code1
stringlengths 54
12k
| code2
stringlengths 66
12k
| similar
int64 0
1
| __index_level_0__
int64 24
101M
|
---|---|---|---|
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
int n;
cin >> n ;
vector<int> A(n) ;
rep(i,n) cin >> A[i] ;
ll sum =0 ;
rep(i,n) sum+=A[i] ;
ll sam=A[0] ;
ll ans= abs(sam*2-sum) ;
rep2(i,1,n-2){
sam+=A[i] ;
ans =min(ans,abs(2*sam-sum)) ;
}
cout << ans <<endl ;
return 0;
} | # include <bits/stdc++.h>
# 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 ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mp make_pair
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
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 migi[2002][2002];
int hidari[2002][2002];
int ue[2002][2002];
int shita[2002][2002];
int main(){
int h, w; cin >> h >> w;
vector<vector<char>> v(h, vector<char> (w));
rep(i, h)rep(j, w) cin >> v[i][j];
int ans = 0;
rep(i, h){
rep(j, w){
if(v[i][j]=='#') migi[i][j] = 0;
else if(j == 0) migi[i][j] = 1;
else migi[i][j] = migi[i][j-1] + 1;
}
}
rep(i, h){
rrep(j, w){
if(v[i][j]=='#') hidari[i][j] = 0;
else if(j == w-1) hidari[i][j] = 1;
else hidari[i][j] = hidari[i][j+1] + 1;
}
}
rep(j, w){
rep(i, h){
if(v[i][j]=='#') ue[i][j] = 0;
else if(i == 0) ue[i][j] = 1;
else ue[i][j] = ue[i-1][j] + 1;
}
}
rep(j, w){
rrep(i, h){
if(v[i][j]=='#') shita[i][j] = 0;
else if(i == h-1) shita[i][j] = 1;
else shita[i][j] = shita[i+1][j] + 1;
}
}
rep(i, h) {
rep(j, w){
if(v[i][j]=='#') continue;
chmax(ans, ue[i][j] + shita[i][j] + hidari[i][j] + migi[i][j] - 3);
}
}
cout << ans << endl;
} | 0 | 6,322,394 |
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;
const int INF = numeric_limits<int>::max();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
LL n, k; cin >> n >> k;
LL ans = (n-2) / (k-1) + 1;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
typedef long long ll;
int main(){
ll hh,ww,ans=1e11,s[3];cin>>hh>>ww;
if(!(hh%3)||!(ww%3)) ans=0;
else{
REP(k,2){
ll h,w;
if(k) h=hh,w=ww;
else h=ww,w=hh;
for(ll i=1;i<w;i++){
s[0]=h*i;
if(!(h%2)||!((w-i)%2)) s[1]=s[2]=h*(w-i)/2;
else{
s[1]=min(h,w-i)*(max(h,w-i)/2);
s[2]=h*w-s[0]-s[1];
}
ans=min(ans,max({s[0],s[1],s[2]})-min({s[0],s[1],s[2]}));
}
}
}
cout<<ans<<endl;
} | 0 | 94,475,542 |
#include <iostream>
using namespace std;
int main()
{
int N, A;
cin >> N >> A;
N %= 500;
if (N <= A) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll a[n];
for(int i=0;i<n;i++) cin >> a[i];
ll c = 1, ans = 0;
for(int i=0;i<n;i++){
if(i == 0) ans += a[i] - 1, a[i] = 1;
if(c == a[i]){
c++;
continue;
}
if(c > a[i]) continue;
if(a[i] % c == 0){
ans++;
a[i] -= (c + 1);
i--;
continue;
}
ans += a[i] / c;
}
cout << ans << endl;
return 0;
} | 0 | 36,811,313 |
#include <bits/stdc++.h>
using namespace std;
long long int d(long long int x,long long int y){
long long int a,b,c,w,h,ans=1000000000;
for(int i=1;i<=y;i++){
h = (y-i)/2;
w = x/2;
a = x*i;
b = x*h;
c = x*(y-i-h);
ans = min(ans,max({a,b,c})-min({a,b,c}));
b = (y-i)*w;
c = (y-i)*(x-w);
ans = min(ans,max({a,b,c})-min({a,b,c}));
}
return ans;
}
int main(){
long long int H,W;
cin >> H >> W;
cout << min(d(H,W),d(W,H)) << endl;
} | #include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)
int main()
{
int a[3];
repi(i,3,0){
cin >> a[i];
}
int index[3] = {0,1,2};
int ans = INF;
do{
int tmp = a[index[0]] + a[index[1]];
ans = min(ans,tmp);
}while(next_permutation(index,index + 3));
cout << ans << endl;
return 0;
} | 0 | 92,298,540 |
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
map<ll,ll> insuu;
void prime_factor(ll n){
ll k=n;
for(ll i=2;i*i<=n;i++){
while(k%i==0){
insuu[i]++;
k/=i;
}
}
if(k!=1) insuu[k]++;
return ;
}
int main(){
ll n;
cin>>n;
for(int i=2;i<=n;i++){
prime_factor(i);
}
for(auto p:insuu){
insuu[p.F]++;
}
ll t75=0;
ll t25=0;
ll t3=0;
ll t5=0;
ll t15=0;
ll ans=0;
for(auto p:insuu){
if(p.S>=75) t75++;
if(p.S>=25) t25++;
if(p.S>=15) t15++;
if(p.S>=5) t5++;
if(p.S>=3) t3++;
}
ans=t75+t25*(t3-1)+(t5-1)*t15+t5*(t5-1)*(t3-2)/2;
COUT(ans);
} | #include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
int main() {
string S, T;
cin >> S >> T;
int ans = INF;
for (int i = 0; i < (int)S.size(); i++) {
if (i + (int)T.size() > (int)S.size()) break;
int cnt = 0;
for (int j = 0; j < (int)T.size(); j++) {
if (S[i + j] != T[j]) cnt++;
}
chmin(ans, cnt);
}
cout << ans << endl;
} | 0 | 79,422,413 |
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
Hello
int n, m;
cin >> n >> m;
int arr[n + 5];
ll sum[n + 5] = {};
ll ans = 0;
for(int i = 1; i <= n; i++)
cin >> arr[i];
map<int, int> mp;
for(int i = 1; i <= n; i++)
sum[i] = sum[i - 1] + arr[i];
for(int i = 0; i <= n; i++)
{
ans += mp[sum[i] % m];
mp[sum[i] % m]++;
}
cout << ans;
return 0;
} | #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);
string s; cin>> s;
rep(i,0,SZ(s)){
if(i == 4){
cout << " ";
}
cout << s[i];
}
cout << endl;
return 0;
} | 0 | 21,099,675 |
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1e9+7;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
int main()
{
cin.tie(0); ios::sync_with_stdio(false);
ll N;
cin >> N;
vector<ll> d(N);
rep(i, N) cin >> d[i];
sort(d);
cout << d[N / 2 + 0] - d[N / 2 - 1];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define pf push_front
#define F first
#define re return
#define S second
#define ll long long
#define f(i) return cout<<i<<"\n",0;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define lp(i,a,b) for (int i=(a);i<=(int)(b);++i)
#define lp2(i,a,b) for (int i=(a);i>=(b);--i)
#define clr(c,x) memset(c,x,sizeof(c))
#define allr(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()
const int N=2e5+5,mod=(int)1e9+7;
int cnt[N];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll n,k,ans=0;
cin>>n>>k;
lp(i,1,n)
cnt[i%k]++;
lp(i,1,n)
{
int y=(k-(i%k))%k;
if ((y+y)%k!=0) continue;
ll z=cnt[y];
z*=z;
ans+=z;
}
cout<<ans<<"\n";
return 0;
} | 0 | 30,999,470 |
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
string s;
while(true)
{
getline(cin,s);
if(s[0]=='.') break;
stack<char> St;
bool ok=true;
REP(i,s.size()){
if(s[i]=='(') St.push(s[i]);
if(s[i]=='[') St.push(s[i]);
if(s[i]==')'){
if(St.empty() || St.top()!='('){ ok=false;break;}
else St.pop();
}
if(s[i]==']'){
if(St.empty() || St.top()!='['){ ok=false;break;}
else St.pop();
}
}
if(!St.empty()) ok=false;
cout<<(ok?"yes":"no")<<endl;
}
} | #include<bits/stdc++.h>
using namespace std;
int n,a,b;
long long ans;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&b);
if(a&&b)--b,++ans;
a=b&1;
ans=ans+(b>>1);
}
printf("%lld",ans);
} | 0 | 95,100,604 |
#include <bits/stdc++.h>
#define fail return (cout << -1 << endl), 0
#define ll long long
using namespace std;
int n;
map<ll, int> f;
ll dis[100010], rdis[100010];
int sz[100010];
struct Edge {
int to, next;
}es[200010];
int first[100010], te = 0;
void addE(int a, int b)
{
te++;
es[te].to = b;
es[te].next = first[a];
first[a] = te;
}
void dfs(int p, int fa)
{
if (p != 1) rdis[p] = rdis[fa] + 1;
for (int e = first[p]; e; e = es[e].next)
{
int to = es[e].to;
if (to == fa) continue;
dfs(to, p);
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> dis[i];
f[dis[i]] = i;
sz[i] = 1;
}
int cnt = 0;
for (map<ll, int>::reverse_iterator it = f.rbegin(); it != f.rend(); it++)
{
int v = it->second, u = f[it->first + 2 * sz[v] - n];
if (!u || u == v) fail;
addE(u, v); addE(v, u);
sz[u] += sz[v];
if (++cnt == n - 1) break;
}
dfs(1, 0);
ll sum = 0;
for (int i = 1; i <= n; i++)
sum += rdis[i];
if (sum != dis[1]) fail;
for (int i = 1; i <= n; i++)
for (int e = first[i]; e; e = es[e].next)
{
if (e & 1) continue;
cout << i << ' ' << es[e].to << endl;
}
return 0;
} | #include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main(){
int n;
cin >> n;
list<int> A;
string s;
int tmp;
REP(i, n){
cin >> s;
if(s == "insert"){
cin >> tmp;
A.push_front(tmp);
}else if(s == "delete"){
cin >> tmp;
for(auto itr = A.begin(); itr != A.end(); ++itr){
if(*itr == tmp){
A.erase(itr);
break;
}
}
}else if(s == "deleteFirst") A.pop_front();
else if(s == "deleteLast") A.pop_back();
}
vector<int> B;
for(auto itr = A.begin(); itr != A.end(); ++itr){
B.push_back(*itr);
}
REP(i, B.size()){
if(i != B.size() - 1) cout << B[i] << " ";
else cout << B[i] << endl;
}
return 0;
} | 0 | 26,488,224 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;
#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007
void solve(int test_case) {
int n;
cin>>n;
priority_queue<int> q;
vi arr(n);for(int &i:arr)cin>>i,q.PU(i);
for(int i=0;i<n;i++) {
if(q.top()==arr[i]){
q.pop();
cout<<q.top()<<"\n";
q.PU(arr[i]);
}
else cout<<q.top()<<"\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
REP(i,1,t) {
solve(i);
}
return 0;
} | #include<stdio.h>
#include<string.h>
int main(){
int n;
scanf("%d",&n);
char arr[n+1];
scanf("%s",arr);
int flag = 1;
for(int i=0;i<(n/2);i++){
if(arr[i] != arr[i + (n/2)]){
flag = 0;
}
}
if(n%2 != 0){
flag = 0;
}
if(flag == 1){
printf("Yes");
}
else{
printf("No");
}
return 0;
} | 0 | 95,910,861 |
#include <bits/stdc++.h>
#define pb push_back
#define MP make_pair
#define ALL(r) (r).begin(),(r).end()
typedef long long int ll;
#define FOR(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; ++i )
#define FORN(i,m,n) for(ll i=(ll)(m-1) ; i >= (ll) (n) ; --i )
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;
void solve()
{
ll a,b,c,d,m,n,p,q,r,x,y,z,aa,bb,cc,dd;
ll i,j,k,l;
ll cnt=0,cnt1=0,cnt2=0,cnt3=0,sum=0,mx=LLONG_MIN,mn=LLONG_MAX;
ll flag=0,flag2=0;
vector <ll> vec1,vec2,vec3;
string s1,s2,s3;
cin >>n >> s1;
if(n%2)
cout << "No\n";
else
{
x=n/2;
FOR(i,0,x)
{
s2.pb(s1[i]);
}
FOR(i,x,n)
{
s3.pb(s1[i]);
}
if(s3==s2)
cout << "Yes\n";
else
cout << "No\n";
}
}
int main()
{
RUN_FAST
ll t=1;
while(t--)
{
solve();
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
{ cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)
constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;
template <typename T>
T round_up(const T& a, const T& b) {
return (a + (b - 1)) / b;
}
template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
is >> p.first >> p.second;
return is;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
os << p.first << p.second;
return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
REP(i, (int)v.size())
is >> v[i];
return is;
}
template <typename T>
T clamp(T& n, T a, T b) {
if (n < a) n = a;
if (n > b) n = b;
return n;
}
template <typename T>
static T GCD(T u, T v) {
T r;
while (v != 0) {
r = u % v;
u = v;
v = r;
}
return u;
}
template <typename T>
static T LCM(T u, T v) {
return u / GCD(u, v) * v;
}
template <typename T>
std::vector<T> enum_div(T n) {
std::vector<T> ret;
for (T i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) { ret.push_back(n / i); }
}
}
return ret;
}
template <typename T>
bool chmin(T& a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
struct ToUpper {
char operator()(char c) {
return toupper(c);
}
};
struct ToLower {
char operator()(char c) {
return tolower(c);
}
};
int N, K;
vector<vector<pair<int, int>>> G;
vector<ll> bfs() {
queue<int> q;
q.emplace(K);
vector<ll> memo(N, -1);
memo[K] = 0;
while (!q.empty()) {
int i = q.front(); q.pop();
for (auto&& x : G[i]) {
if (memo[x.first] != -1)continue;
memo[x.first] = memo[i] + x.second;
q.emplace(x.first);
}
}
return memo;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int N, M;
cin >> N >> M;
struct Cake {
ll x, y, z;
};
vector<Cake> cakes(N);
REP(i, N) {
ll x, y, z;
cin >> x >> y >> z;
cakes[i] = { x,y,z };
}
ll ans = 0;
REP(i, 8) {
vector<int> D(3);
REP(d, 3) {
if ((i >> d) & 1)D[d] = 1;
else D[d] = -1;
}
auto func = [&](const Cake& c1, const Cake& c2) {
return D[0] * c1.x + D[1] * c1.y + D[2] * c1.z
< D[0] * c2.x + D[1] * c2.y + D[2] * c2.z;
};
vector<Cake> q(N);
REP(i, N) {
q[i] = (cakes[i]);
}
sort(ALL(q), func);
ll x = 0, y = 0, z = 0;
REP(i, M) {
Cake c = q.back(); q.pop_back();
x += c.x;
y += c.y;
z += c.z;
}
ll now = abs(x) + abs(y) + abs(z);
chmax(ans, now);
}
cout << ans << endl;
return 0;
} | 0 | 85,595,810 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
char map[505][505];
int def[505][505];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
vector<int>to[200005];
ll a[100005];
ll b[100005];
ll keisan(ll x,ll y) {
if (x % y == 0) {
return 0;
}
ll k = x / y+1;
return y * k - x;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
ll sum = 0;
ll ans = 0;
for (int i = n - 1; i > 0; i--) {
ll x;
x= keisan(a[i], b[i]);
ans += x;
sum += x;
a[i - 1] += sum;
}
cout << ans + keisan(a[0],b[0])<< endl;
return 0;
} | #define LOCAL
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 1e18
#define INF (int)1e9+1
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string)s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}\n";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
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 += "}\n";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}
void debug_out() {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
using llong = long long;
using PII = pair<int, int>;
const llong MOD = 998244353LL;
int main() {
IOS;
bool suc = true;
int n; cin >> n; set<int > a;
for (int i = 0; i < n; i++) {
int k; cin >> k;
if (a.count(k)) suc = false;
a.insert(k);
}
if (suc) cout << "YES";
else cout << "NO";
} | 0 | 64,879,650 |
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
using namespace std;
typedef pair<int,int> pii;
int main(){
int s, w;
cin >> s >> w;
if(w >= s){
cout << "unsafe\n";
}else{
cout << "safe\n";
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
int N, M;
int main(){
while(cin >> N >> M && N+M>0){
pair<int,int> a[N];
long long r = 0;
for (int i = 0; i < N; ++i){
int D, P;
cin >> D >> P;
a[i] = make_pair(P, D);
r += D * P;
}
sort(a, a+N, greater<pair<int,int> >());
for(int i = 0; i < N; ++i){
if(a[i].second >= M){
r -= M * a[i].first;
M = 0;
}else{
r -= a[i].first * a[i].second;
M -= a[i].second;
}
if(M == 0) break;
}
cout << r << endl;
}
} | 0 | 82,352,909 |
#include "bits/stdc++.h"
#define ll long long
#define int ll
#define fi first
#define si second
#define mp make_pair
#define pb push_back
#define pi pair<ll,ll>
#define clr(x) memset(x,0,sizeof(x));
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
#define done(i) cout<<"done = "<<i<<endl;
#define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
map<int,vector<int> >yo;
map<int,int>vis;
vector<pi>vec;
map<int,vector<int> >nisi;
set<int>types;
main()
{
fast
int n,k;
cin>>n>>k;
f(i,1,n)
{
int t,d;
cin>>t>>d;
yo[t].pb(d);
vec.pb(mp(d,t));
types.insert(t);
}
for(auto x:yo)
{
sort(yo[x.fi].begin(),yo[x.fi].end());
}
int ses=0;
sort(vec.rbegin(),vec.rend());
for(int i=0;i<k;i++)
{
int typ=vec[i].si;
int val=vec[i].fi;
ses+=val;
nisi[typ].pb(val);
vis[typ]=1;
}
vector<int>fre,nw;
int sz=nisi.size();
ses+=(sz*sz);
int cost=ses;
for(auto x:nisi)
{
sort(nisi[x.fi].begin(),nisi[x.fi].end());
nisi[x.fi].pop_back();
for(auto y:nisi[x.fi])
{
fre.pb(y);
}
}
for(auto t:types)
{
if(vis.count(t)==0)
{
nw.pb(yo[t].back());
}
}
sort(fre.rbegin(),fre.rend());
sort(nw.rbegin(),nw.rend());
for(auto x:nw)
{
if(fre.size()==0)break;
ses-=(sz*sz);
ses-=fre.back();
fre.pop_back();
ses+=x;
sz++;
ses+=(sz*sz);
cost=max(cost,ses);
}
cout<<cost<<endl;
return 0;
} | #include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
const int MAXN=1e5+10;
int N;
pair<int,int> elements[MAXN];
int BIT[MAXN];
int len(int i){
return i&(-i);
}
int query(int prefixIndex){
if (prefixIndex<1) return 0;
return max(query(prefixIndex-len(prefixIndex)),BIT[prefixIndex]);
}
void updateTo(int i,int val){
if (i>N) return;
BIT[i]=max(BIT[i],val);
updateTo(i+len(i),val);
}
int main(){
scanf("%d",&N);
for(int i=1;i<=N;i++){
int temp;
scanf("%d",&temp);
elements[i].first=temp;
elements[i].second=i;
}
sort(elements+1,elements+N+1);
int cur=1;
while(cur<=N){
int head=cur;
vector<int> newvalues;
while(cur<=N&&elements[cur].first==elements[head].first) cur++;
for(int index=head;index<cur;index++){
int pre=elements[index].second-1;
int temp=query(pre);
newvalues.push_back(temp+1);
}
for(int index=cur-1;index>=head;index--){
updateTo(elements[index].second,newvalues.back());
newvalues.pop_back();
}
}
printf("%d\n",query(N));
return 0;
} | 0 | 91,992,310 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(void)
{
int N;
cin >> N;
vector<double> A(N);
for (int i = 0; i < N; i++)
{
cin >> A[i];
}
double res = 0;
for (int i = 0; i < N; i++)
{
res+= 1/(double)A[i];
}
res= 1/res;
cout << res;
} | #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll a[maxn],r[maxn],l[maxn];
inline ll Pow2(int i){
if(i<63) return 1ll<<i;
else return 1e18;
}
int main()
{
int n;
cin>>n;
for(int i=0; i<=n; i++) cin>>a[i];
ll ans=0;
l[n+1]=0,r[n+1]=0;
for(int i=n; i>=0; --i)
{
l[i]=l[i+1]/2+l[i+1]%2;
r[i]=r[i+1];
l[i]+=a[i];
r[i]+=a[i];
if(l[i]>Pow2(i))
{
cout<<-1<<endl;
return 0;
}
r[i]=min(r[i],Pow2(i));
}
for(int i=1; i<=n-1; i++)
{
ll x=l[i-1],y=r[i-1];
x-=a[i-1];
y-=a[i-1];
y=2*y;
l[i]=max(l[i],x);
r[i]=min(r[i],y);
}
for(int i=0; i<=n; i++)
{
ans+=r[i];
}
cout<<ans<<endl;
return 0;
} | 0 | 42,764,064 |
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>
using namespace std;
double sq(double x){return x*x;}
int main(){
int n,s;
while(cin>>n>>s,(n||s)){
int comb = (1 << n) - 1;
int ans = 0;
while(comb < (1 << 10)){
int x = comb & -comb,y = comb + x;
int sum = 0;
for (int i = 0; i < 10; i++)
{
if(comb & (1 << i)){
sum += i;
}
}
if(sum == s) ans++;
comb = ((comb & ~y) / x >> 1) | y;
}
cout << ans << endl;
}
return 0;
} | #include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
using namespace std;
int INF=1e8;
int dist[15][15];
int main(){
ios_base::sync_with_stdio(false);
cout<<fixed<<setprecision(0);
int n;
while(cin>>n,n){
fill(dist[0],dist[0]+15*15,INF);
int m=0,a,b,d;
for(int i=0; i<n; ++i){
cin>>a>>b>>d;
dist[a][b]=dist[b][a]=min(dist[a][b],d);
m=max({m,a,b});
}
++m;
for(int i=0; i<m; ++i)
dist[i][i]=0;
for(int k=0; k<m; ++k)
for(int i=0; i<m; ++i)
for(int j=0; j<m; ++j)
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
pair<int,int> re=pair<int,int>(INF,-1);
for(int i=0; i<m; ++i){
int sum=0;
for(int j=0; j<m; ++j) sum+=dist[i][j];
re=min(re,pair<int,int>(sum,i));
}
cout<<re.second<<" "<<re.first<<endl;
}
return 0;
} | 0 | 50,486,488 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;
#include <math.h>
#define PI 3.14159265358979323846264338327950L
bool isPrime(long long x) {
if (x == 1) return true;
for (long long i = 2; i * i <= x; i++) {
if (x % i == 0) return false;
}
return true;
}
long long gcd(long long a, long long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
vector<long long> common_divisors(long long a, long long b) {
long long n = gcd(a, b);
vector<long long> ans;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (n / i == i) {
ans.push_back(i);
}
else {
ans.push_back(n / i);
ans.push_back(i);
}
}
}
return ans;
}
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
if (n == 1) {
cout << (int)(a[0] / pow(2, k));
return 0;
}
sort(a.rbegin(), a.rend());
while (k) {
while (k && a[0] >= a[1]) {
a[0] /= 2;
k--;
}
int temp = a[0];
a.erase(a.begin(), a.begin() + 1);
int l = 0, h = n - 2;
while (l <= h) {
int m = l + (h - l) / 2;
if (a[m] > temp) {
l = m+1;
}
else {
h = m-1;
}
}
a.insert(a.begin() + l, temp);
}
long long sum = 0;
for (int i = 0; i < n; i++) sum += a[i];
cout << sum;
return 0;
} | #include <cstdio>
#include <map>
#include <queue>
using namespace std;
int h, w, n;
char field[1010][1010];
using pos = pair<int, int>;
pos pass[10];
int distance(pos start, pos goal) {
bool visited[1010][1010];
for (int i = 0; i < 1010; i++) {
for (int j = 0; j < 1010; j++) {
visited[i][j] = false;
}
}
queue<pair<int, pos>> q;
q.push(make_pair(0, start));
while (!q.empty()) {
auto s = q.front();
q.pop();
if (s.second.first < 0 || s.second.second < 0 || s.second.first >= h || s.second.second >= w) { continue; }
if (field[s.second.first][s.second.second] == 'X') { continue; }
if (visited[s.second.first][s.second.second]) { continue; }
if (s.second == goal) {
return s.first;
}
visited[s.second.first][s.second.second] = true;
q.push(make_pair(s.first + 1, make_pair(s.second.first, s.second.second + 1)));
q.push(make_pair(s.first + 1, make_pair(s.second.first, s.second.second - 1)));
q.push(make_pair(s.first + 1, make_pair(s.second.first + 1, s.second.second)));
q.push(make_pair(s.first + 1, make_pair(s.second.first - 1, s.second.second)));
}
}
int main() {
scanf("%d", &h);
scanf("%d", &w);
scanf("%d", &n);
for (int i = 0; i < h; i++) {
scanf("%s", field[i]);
for (int j = 0; j < w; j++) {
if (field[i][j] == 'S') {
pass[0] = make_pair(i, j);
} else if (field[i][j] >= '1' && field[i][j] <= '9') {
pass[field[i][j] - '0'] = make_pair(i, j);
}
}
}
int sum = 0;
for (int i = 0; i < n; i++) {
sum += distance(pass[i], pass[i + 1]);
}
printf("%d\n", sum);
} | 0 | 79,537,626 |
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
#define MAX 10000
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007
#define access(i) a[i/3][i%3]
int main(){
ll n,a,b;
cin>>n>>a>>b;
if(a > b){
cout<<"0"<<endl;
return 0; }
else if( n < 2 && a != b){
cout<<"0"<<endl;
return 0 ;}
ll maxi_sum = b*(n-1)+a;
ll mini_sum = a*(n-1)+b;
cout<<maxi_sum-mini_sum+1<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v) \
cerr << #v ":[ "; \
for (auto macro_vi : v) { \
cerr << macro_vi << " "; \
} \
cerr << "]" << endl;
#define ddump(v) \
cerr << #v ":" << endl; \
for (auto macro_row : v) { \
cerr << "["; \
for (auto macro__vi : macro_row) { \
cerr << macro__vi << " "; \
} \
cerr << "]" << endl; \
}
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const double EPS = 1e-10;
int main() {
lint N, K;
string S;
cin >> N >> K >> S;
N = S.size();
vector<lint> A(0);
lint cnt = 1;
if (S[0] == '0') { A.push_back(0); }
for (int i = 0; i < N - 1; i++) {
if (S[i + 1] == S[i]) {
cnt++;
} else {
A.push_back(cnt);
cnt = 1;
}
}
A.push_back(cnt);
vector<lint> L(A.size() + 1);
rep(i, A.size()) L[i + 1] = L[i] + A[i];
lint ans = -1;
for (int left = 0; left < (lint)A.size(); left += 2) {
int right = min(left + 2 * K + 1, (lint)A.size());
ans = max(ans, L[right] - L[left]);
}
cout << ans << endl;
return 0;
} | 0 | 27,330,072 |
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
using namespace std;
template<typename Integral = int> Integral fibonacci(const int &n) {
static std::vector<Integral> dp(2, 1);
int prev = dp.size();
if (prev < n + 1) {
dp.resize(n + 1);
loop(i, prev, dp.size()) dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
main {
int n;
cin >> n;
cout << fibonacci(n) << endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
int n;
cin >> n;
int l = -1;
int r = n;
int idx;
int male = 0;
int female = 0;
rep(i, 20) {
if ( i == 0 ) {
idx = 0;
}
else {
idx = ( r + l ) / 2;
}
cout << idx << endl;
cout.flush();
string s;
cin >> s;
if ( s == "Vacant" ) {
return 0;
}
else if ( s == "Male" ) {
if ( i == 0 ) {
male = idx % 2;
female = ( idx % 2 ) ? 0 : 1;
idx = ( r + l ) / 2;
}
else if ( male != idx % 2 ) {
r = idx;
}
else {
l = idx;
}
}
else {
if ( i == 0 ) {
female = idx % 2;
male = ( idx % 2 ) ? 0 : 1;
idx = ( r + l ) / 2;
}
else if ( female != idx % 2 ) {
r = idx;
}
else {
l = idx;
}
}
}
return 0;
} | 0 | 57,516,374 |
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int h, w, n, s;
char g[1001][1001];
bool v[1001][1001];
int id[8] = {0, -1, 0, 1, -1, 0, 1, 0};
int main() {
scanf("%d %d %d", &h, &w, &n);
for (int i = 0; i < h; ++i) {
getchar();
for (int j = 0; j < w; ++j) {
while (~scanf("%c", &g[i][j]) && g[i][j] == ' ');
if (g[i][j] == 'S') s = i * w + j;
}
}
int ans = 0;
char c = '0';
while (c != n + '0') {
c += 1;
queue<pair<int, int> > q;
memset(v, 0, sizeof v);
v[s / w][s % w] = true;
q.push({s, 0});
while (!q.empty()) {
int i = q.front().first / w, j = q.front().first % w, step = q.front().second;
if (g[i][j] == c) {
s = i * w + j;
ans += step;
break;
}
q.pop();
for (int k = 0; k < 8; k += 2) {
int ni = i + id[k], nj = j + id[k + 1];
if (ni >= 0 && ni < h && nj >= 0 && nj < w && !v[ni][nj] && g[ni][nj] != 'X') {
v[ni][nj] = true;
q.push({ni * w + nj, step + 1});
}
}
}
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; i<n; i++)
#define REP2(i, a, b) for(int i=a; i<b; i++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007
template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }
int main(){
int M;
cin >> M;
vector<long long> d(M), c(M);
REP(i, M) cin >> d[i] >> c[i];
long long S = 0;
long long D = 0;
REP(i, M)
D += c[i];
REP(i, M)
S += c[i] * d[i];
long long ans = D-1+(S-1)/9;
cout << ans << endl;
return 0;
} | 0 | 82,139,977 |
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define eps 1e-67
#define pf printf
#define sf scanf
#define sd(n) scanf("%d",&n)
#define sd2(n1,n2) scanf("%d %d",&n1,&n2)
#define slf(n) scanf("%lf",&n)
#define slf2(n1,n2) scanf("%lf %lf",&n1,&n2)
#define sLf(n1) scanf("%Lf",&n1)
#define sLf2(n1,n2) scanf("%Lf %Lf",&n1,&n2)
#define sl(n) scanf("%lld",&n)
#define sl2(n1,n2) scanf("%lld %lld",&n1,&n2)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c)
#define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c)
#define asort(a) sort(a.begin(),a.end())
#define asortb(a,comp) sort(a.begin(),a.end(),comp)
#define arev(a) reverse(a.begin(),a.end())
#define all(v) (v).begin(),(v).end()
#define allc(v,comp) (v).begin(),(v).end(),comp
#define allrc(v,a,b,comp) (v).begin()+a,(v).end()-b,comp
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define mt make_tuple
#define bs(v,x) binary_search(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define tl(c) towlower(c)
#define root(x) sqrt(x)
#define power(a,n) pow(a,n)
#define tu(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define mx 1000
#define MX 100000
#define mod 1000000007
using namespace std;
typedef string str;
typedef long long int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef char ch;
typedef map<ll,ll> mp;
void Solve()
{
int n,m,i,j;
cin>>n>>m;
string a[n+1];
string b[m+1];
string s,ss;
int c=0;
rep(i,0,n)
{
cin>>s;
a[i]=s;
}
int flag=0;
rep(i,0,m)
{
cin>>ss;
b[i]=ss;
}
rep(i,0,n-m+1)
{
rep(j,0,n)
{
c=0;
rep(k,0,m)
{
if(a[i+k].substr(j,m)==b[k])
{
c++;
}
}
if(c==m)
{
flag=1;
goto ans;
}
}
}
ans:
if(flag==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
int main()
{
Solve();
return 0;
} | #include <bits/stdc++.h>
const double pi = 3.141592653589793238462643383279;
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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
#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 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 FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
class UnionFind {
public:
vector <int> par;
vector <int> siz;
UnionFind(int sz_): par(sz_), siz(sz_, 1) {
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
void init(int sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
int root(int x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(int x, int 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(int x, int y) {
return root(x) == root(y);
}
int size(int x) {
return siz[root(x)];
}
};
ll modPow(ll x, ll n, ll mod = MOD){
if(n <= 0) return 1;
ll res = 1;
while(n){
if(n&1) res = (res * x)%mod;
res %= mod;
x = x * x %mod;
n >>= 1;
}
return res;
}
#define SIEVE_SIZE 5000000+10
bool sieve[SIEVE_SIZE];
void makeSieve(){
for(int i=0; i<SIEVE_SIZE; ++i) sieve[i] = true;
sieve[0] = sieve[1] = false;
for(int i=2; i*i<SIEVE_SIZE; ++i) if(sieve[i]) for(int j=2; i*j<SIEVE_SIZE; ++j) sieve[i*j] = false;
}
bool isprime(ll n){
if(n == 0 || n == 1) return false;
for(ll i=2; i*i<=n; ++i) if(n%i==0) return false;
return true;
}
const int MAX = 2000010;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long extGCD(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long d = extGCD(b, a%b, y, x);
y -= a/b * x;
return d;
}
inline long long mod(long long a, long long m) {
return (a % m + m) % m;
}
long long modinv(long long a, long long m) {
long long x, y;
extGCD(a, m, x, y);
return mod(x, m);
}
ll GCD(ll a, ll b){
if(b == 0) return a;
return GCD(b, a%b);
}
typedef vector<ll> vec;
typedef vector<vec> mat;
mat mul(mat &A, mat &B) {
mat C(A.size(), vec((int)B[0].size()));
for(int i=0; i<A.size(); ++i){
for(int k=0; k<B.size(); ++k){
for(int j=0; j<B[0].size(); ++j){
C[i][j] = (C[i][j] + A[i][k] * B[k][j] %MOD) % MOD;
}
}
}
return C;
}
mat matPow(mat A, ll n) {
mat B(A.size(), vec((int)A.size()));
for(int i=0; i<A.size(); ++i){
B[i][i] = 1;
}
while(n > 0) {
if(n & 1) B = mul(B, A);
A = mul(A, A);
n >>= 1;
}
return B;
}
ll modPow(ll x, string n, ll mod){
ll res = 1;
int sz = n.size();
for(int i=sz-1; i>=0; i--){
int d = n[i] - '0';
ll t = 1;
for(int j=0; j<10; j++){
if(j == d){
res = res*t%mod;
}
t = t*x % mod;
}
x = t;
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int N; cin >> N;
vector<string> s(N);
REP(i,N) cin >> s[i];
int ct[26]={0};
REP(i,N) REP(j,N) ct[s[i][j]-'a']++;
int ans = 0;
REP(i,N){
int tmp[26];
for(int j=0; j<26; j++) tmp[j] = ct[j];
for(int j=0; j<N; j++){
tmp[s[(i+j)%N][j] - 'a']--;
}
bool ok = true;
for(int j=0; j<26; j++){
if(tmp[j]%2 == 1) ok = false;
}
if(!ok) continue;
vector<string> B(N);
REP(j,N){
B[j] = s[(i+j)%N];
}
bool check = true;
for(int j=0; j<N; j++){
for(int k=0; k<N; k++){
if(B[j][k] != B[k][j]) check = false;
}
}
if(check) ans += N;
}
cout << ans << endl;
return 0;
} | 0 | 48,928,444 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
bool flag=false,ans=false;
cin >> a >> b >> c >> d;
if(a>=b && a-b<=d) flag = true;
else if(b>=a && b-a<=d) flag = true;
if(flag && b>=c && b-c<=d) ans = true;
else if(flag && c>=b && c-b<=d) ans = true;
if(a>=c && a-c<=d) ans = true;
else if(c>=a && c-a<=d) ans = true;
cout << (ans? "Yes":"No") << endl;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=100005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
int g=__gcd(a, b);
return a/g*b;
}
int power(int a, int b, int p)
{
if(a==0)
return 0;
int res=1;
a%=p;
while(b>0)
{
if(b&1)
res=(res*a)%p;
b>>=1;
a=(a*a)%p;
}
return res;
}
int dp[101][N];
int32_t main()
{
IOS;
int n,k;
cin>>n>>k;
int ar[n+1];
for(int i=1;i<=n;i++)
cin>>ar[i];
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)
dp[i-1][j]=(dp[i-1][j]+dp[i-1][j-1])%mod;
for(int j=0;j<=k;j++)
{
dp[i][j]=dp[i-1][j];
if((j-ar[i]-1)>=0)
dp[i][j]=(dp[i][j]-dp[i-1][j-ar[i]-1]+mod)%mod;
}
}
cout<<dp[n][k];
} | 0 | 56,390,899 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
using Graph = vector<vector<pair<ll,ll>>>;
int main(){
ll N;
cin >> N;
vector<ll> P(N),A(N),B(N),C(N);
rep(i,N) cin >> P[i];
rep(i,N){
C[P[i]-1] = i+1;
}
rep(i,N){
A[i] = 40000 * (i+1);
B[i] = 40000 * (N-i-1) + C[i];
}
rep(i,N) cout << A[i] << ' ';
cout << endl;
rep(i,N) cout << B[i] << ' ';
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
int r;
if(n>=400 && n<=599)
r=8;
if(n>=600 && n<=799)
r=7;
if(n>=800 && n<=999)
r=6;
if(n>=1000 && 1199)
r=5;
if(n>=1200 && n<=1399)
r=4;
if(n>=1400 && n<=1599)
r=3;
if(n>=1600 && n<=1799 )
r=2;
if(n>=1800 && n<=1999)
r=1;
cout<<r<<"\n";
return 0;
} | 0 | 72,425,288 |
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H), debug_out(T...);
}
const int MAX = 10000001;
ll cnt[MAX + 1];
bitset < MAX + 1 > marked;
void sieve() {
fill(cnt, cnt + MAX + 1, 1);
marked[0] = marked[1] = true;
for (int i = 2; i <= MAX; i++) if (!marked[i]) {
cnt[i]++;
for (int j = i * 2; j <= MAX ; j += i) {
int n = j, c = 1;
while (n % i == 0) n /= i, c++;
cnt[j] *= c;
marked[j] = true;
}
}
}
int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
freopen("in.txt", "r", stdin);
#else
#define debug(...) 3
fastIO;
#endif
sieve();
int n;
cin >> n;
ll ans = 0;
for(ll i = 1; i <= n; i++)ans += cnt[i] * i;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
const int N = 5010;
using ll = long long;
int p[N], c[N];
bool vis[N];
int main(){
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++ i){
scanf("%d", &p[i]);
}
for (int i = 1; i <= n; ++ i){
scanf("%d", &c[i]);
}
ll ret = LLONG_MIN;
for (int i = 1; i <= n; ++ i){
if (vis[i]){
continue;
}
int x = i;
std::vector<int> vec;
while (!vis[x]){
vec.emplace_back(c[x]);
vis[x] = true;
x = p[x];
}
ll sum = 0;
for (auto u : vec){
sum += u;
}
ll ans = 0;
int sz = vec.size();
int kk = k;
if (sum > 0 && k / sz >= 3){
int num = k / sz - 2;
ans += num * sum;
k -= num * sz;
ret = std::max(ret, ans);
}
else if (sum <= 0){
if (k > 2 * sz){
k = k % sz + 2 * sz;
}
}
ll max1 = LLONG_MIN;
for (int j = 0; j < sz; ++ j){
ll tot = 0;
for (int u = 0; u < k; ++ u){
tot += vec[(j + u) % sz];
max1 = std::max(max1, tot);
}
}
ans += max1;
ret = std::max(ans, ret);
k = kk;
}
printf("%lld\n", ret);
return 0;
} | 0 | 94,639,942 |
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>
#include <numeric>
using namespace std;
#define I_MAX 2147483647
#define LL_MAX 9223372036854775807
#define ll long long
#define ld long double
struct XX{
ll a;
ll b;
};
class xxGreater {
public:
bool operator()(const XX& riLeft, const XX& riRight) const {
if((riLeft.a) == (riRight.a)){
return riLeft.b > riRight.b;
}
return (riLeft.b) > (riRight.b);
}
};
#ifdef DEBUG
#else
#endif
int main(int argc, const char * argv[])
{
ifstream ifs("01");
ios::sync_with_stdio(false);
cin.tie(0);
ll N,K;
cin>>N>>K;
ll ans=0;
for(ll i=K;i<=N+1;i++){
ll mini=(0+i-1)*i/2;
ll maxi=(N+N-i+1)*i/2;
ans+=maxi-mini+1;
ans%=1000000007;
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
int main() {
ll n, k;
cin >> n >> k;
const ll m = n*(n+1)/2;
vl a(n);
rep(i, n) {
cin >> a[i];
}
vl rui(n+1);
rep(i, n) {
rui[i+1] = rui[i] + a[i];
}
vl v;
rep(i, n) {
exrep(j, i+1, n) {
v.pb(rui[j] - rui[i]);
}
}
ll ans = 0;
vl dame(m);
for(ll d = 50; d >= 0; d--) {
ll mask = 1LL<<d;
ll cnt = 0;
rep(i, m) {
if(dame[i]) {
continue;
}
if(v[i] & mask) {
cnt++;
}
}
if(cnt >= k) {
ans += mask;
rep(i, m) {
if(!(v[i] & mask)) {
dame[i] = 1;
}
}
}
}
out(ans);
re0;
} | 0 | 38,286,036 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
int main() {
int N, K;
cin >> N >> K;
vector<int> sunuke(N,0);
rep(i, K) {
int d;
cin >> d;
rep(j, d) {
int a;
cin >> a;
sunuke[a-1]++;
}
}
int ans = 0;
rep(i, N) {
if (sunuke[i] == 0) {
ans++;
}
}
cout << ans << endl;
return 0;
} | #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(){
int h,w;
cin >> h >> w;
vector<string> v(h);
rep(i, h){
cin >> v[i];
}
vector<vector<int>> dp(h, vector<int>(w, 10005));
dp[0][0] = (v[0][0] == '#' ? 1 : 0);
rep(i, h){
rep(j, w){
if(i != h - 1){
if(v[i][j] == '.' && v[i + 1][j] == '#'){
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
}else{
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
if(j != w - 1){
if(v[i][j] == '.' && v[i][j + 1] == '#'){
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
}else{
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
}
}
}
}
cout << dp[h - 1][w - 1] << endl;
return 0;
} | 0 | 93,780,519 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
int h,w,d;
cin >> h >> w >> d;
int a[h][w],total[d];
map<int,pair<int,int> >m;
REP(i,h){
REP(j,w){
cin >> a[i][j];
m[a[i][j]] = make_pair(i,j);
}
}
ll answer = 0;
int q;
cin >> q;
int l[q],r[q],left[h*w+1],right[h*w+1];
REP(i,q){
cin >> l[i] >> r[i];
}
FOR(i,0,h*w+1){
int lx,ly,px,py;
ly = m[i].first,lx = m[i].second;
if(i<=d){
left[i]=0;
}
else{
ly = m[i].first,lx = m[i].second;
py = m[i-d].first,px = m[i-d].second;
left[i] = left[i-d]+abs(lx-px)+abs(ly-py);
}
}
FORR(i,h*w,0){
if(i > h*w-d){
right[i] = 0;
continue;
}
int ly = m[i].first,lx = m[i].second;
int py = m[i+d].first,px = m[i+d].second;
right[i] = right[i+d] + abs(lx-px)+abs(ly-py);
}
FORR(i,h*w,h*w-d+1){
total[i%d]=left[i];
}
REP(i,q){
cout << left[r[i]]+right[l[i]]-total[l[i]%d] << endl;
}
return 0;
} | #include <iostream>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
int main(){
ll n,m,count,cnt,ans=0;
cin>>n>>m;
int s[11][11],p[11],k[11];
rep(i,m){
cin>>k[i];
rep(j,k[i]){
cin>>s[i][j];
}
}
rep(i,m){
cin>>p[i];
}
rep(bit,(1<<n)){
cnt=0;
rep(i,m){
count=0;
rep(j,k[i]){
if(bit&(1<<(s[i][j]-1))){
count++;
}
}
if(count%2==p[i]){
cnt++;
}
}
if(cnt==m){
ans++;
}
}
cout<<ans;
} | 0 | 23,436,810 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int H,N;
cin>>H>>N;
for(int i=0;i<N;i++){
int A;
cin>>A;
H-=A;
}
if(H<=0)
cout<<"Yes";
else
cout<<"No";
return 0;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int a, b;
cin >> a >> b;
vector<string> v;
for(int i=0; i<a; i++) {
string s;
cin >> s;
for(int j=0; j<b; j++) {
if(s[j] == '#') {
v.push_back(s);
break;
}
}
}
int c = v.size();
vector<string> w(b);
for(int i=0; i<c; i++) {
string s;
s = v[i];
for(int j=0; j<b; j++) {
w[j] += s[j];
}
}
for(int i=0; i<w.size(); i++) {
string s;
s = w[i];
for(int j=0; j<c; j++) {
if(s[j] == '#') break;
if(j == c-1 && s[j] == '.') {
w.erase(w.begin()+i);
i--;
}
}
}
int d = w.size();
vector<string> x(c);
for(int i=0; i<d; i++) {
for(int j=0; j<c; j++) {
string s;
s = w[i];
x[j] += s[j];
}
}
for(int i=0; i<c; i++) {
cout << x[i] << endl;
}
return 0;
} | 0 | 11,750,625 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) begin(x), end(x)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;
P cnt_i[300005],cnt_j[300005];
int main(){
int H,W,m;
cin>>H>>W>>m;
set<P> se;
rep(i,H){
cnt_i[i].second=i;
}
rep(i,W){
cnt_j[i].second=i;
}
rep(i,m){
int h,w;
cin>>h>>w;
h--; w--;
se.insert({h,w});
cnt_i[h].first++;
cnt_j[w].first++;
}
sort(cnt_i,cnt_i+H);
sort(cnt_j,cnt_j+W);
int ma_i=cnt_i[H-1].first,ma_j=cnt_j[W-1].first;
for(int i=H-1;i>=0;i--){
if(cnt_i[i].first!=ma_i) break;
for(int j=W-1;j>=0;j--){
if(cnt_j[j].first!=ma_j) break;
if(se.find({cnt_i[i].second,cnt_j[j].second})==se.end()){
cout<<ma_i+ma_j<<endl;
return 0;
}
}
}
cout<<ma_i+ma_j-1<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool judge(ll x)
{
printf("? %lld\n",x);
fflush(stdout);
char C;
scanf(" %c",&C);
return C == 'Y';
}
int main()
{
ll ans = 1000000000;
if(judge(ans))
{
ans = 10;
while(!judge(ans - 1))ans *= 10;
printf("! %lld\n",ans / 10);
fflush(stdout);
return 0;
}
else
{
while(!judge(ans /= 10));
ll l = ans,r = ans * 10;
while(r - l > 1)
{
ll mid = (l + r) / 2;
if(judge(mid * 10))r = mid;
else l = mid;
}
printf("! %lld\n",r);
fflush(stdout);
return 0;
}
} | 0 | 80,864 |
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)
signed main(){
int A,B,C,K;
cin>>A>>B>>C>>K;
int ans=0;
if(K%2==0){
ans=A-B;
}else{
ans=B-A;
}
if(ans>=1000000000000000000){
cout<<"Unfair"<<endl;
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n,m;
cin>>n>>m;
priority_queue<ll> q;
for(int i=0;i<n;i++)
{
ll temp;
cin>>temp;
q.push(temp);
}
while( m--)
{
ll top = q.top();
q.pop();
top = top/2;
q.push(top);
}
ll ans =0;
while( !q.empty() )
{
ans += q.top();
q.pop();
}
cout<<ans;
} | 0 | 16,232,918 |
#include <bits/stdc++.h>
#define N 100000
using namespace std;
int n;
int A[2000010],B[2000010];
void Csort(){
int cnt[N]={};
for(int i=0;i<n;i++) cnt[A[i]]++;
for(int i=1;i<N;i++) cnt[i]+=cnt[i-1];
for(int i=0;i<n;i++) B[cnt[A[i]]--] = A[i];
}
int main(){
cin>>n;
for(int i=0;i<n;i++) scanf("%d",&A[i]);
Csort();
for(int i=1;i<=n;i++){
if(i>1)printf(" ");
printf("%d",B[i]);
}
cout<<endl;
return 0;
} | #include<iostream>
#include<vector>
#include<string>
using namespace std;
void InputSet(std::vector<int> & a) {
int n;
cin >> n;
a.resize(n,0);
for(int i=0;i<n;++i) {
cin >> a.at(i);
a.at(i)--;
}
}
int main(){
int n;
cin >> n;
vector<vector<int> > Ad;
Ad.resize(n);
for(int k=0;k<n;++k) {
int u;
cin >> u;
--u;
InputSet(Ad[u]);
}
for(int i=0;i<n;++i){
string a(n,'0');
for(int j=0;j<(int)Ad[i].size();++j){
a.at(Ad[i][j]) = '1';
}
for(int j=0;j<n;++j){
if(j==0){
cout << a[j];
} else {
cout << " " << a[j];
}
}
cout << endl;
}
} | 0 | 95,554,007 |
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int N;
int M;
int sum = 0;
cin>>N;
cin>>M;
if(N > 1){
for(int i = (N - 1);i > 0;i--){
sum += i;
}
}
if(M > 1){
for(int i = (M - 1);i > 0;i--){
sum += i;
}
}
cout<<sum<<'\n';
} | #include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v) reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF UnionFind
#define rt (a); return (a);
constexpr auto mod = 1000000007;
int ni(int n) {
if (n == 0)return 1;
int x = ni(n / 2);
x *= x;
if (n % 2 == 1)x *= 2;
return x;
}
llint f(int x, vector<llint>& s) {
if (x == 0)return 0;
if (x == 1)return 1;
if (s[x] != 0)return s[x];
return s[x] = f(x - 1, s) + f(x - 2, s);
}
llint gcd(llint a, llint b) {
if (a < b)swap(a, b);
if (b == 0)return a;
return gcd(b, a % b);
}
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 m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
ll int c(ll int a, ll int b, ll int m) {
ll int ans = 1;
for (ll int i = 0; i < b; i++) {
ans *= a - i;
ans %= m;
}
for (ll int i = 1; i <= b; i++) {
ans *= modinv(i, m);
ans %= m;
}
return ans;
}
int dfs(int m, int n, llint k, hei(llint) a) {
stack<string> st;
st.push("");
while (!st.empty()) {
string now = st.top();
st.pop();
if (now.size() == n) {
llint ans = 0;
rep(i, 0, n) {
if (now[i] == '1')ans += a[i];
}
if (ans == k) {
cout << "Yes" << endl;
return 0;
}
}
else {
for (int i = m - 1; i >= 0; i--) {
string next = now + to_string(i);
st.push(next);
}
}
}
return 1;
}
void press(vector<int>& v) { v.erase(unique((v).begin(), (v).end()), v.end()); }
void press(vector<char>& v) { v.erase(unique((v).begin(), (v).end()), v.end()); }
llint min(llint a, llint b) {
if (a < b)return a;
return b;
}
llint max(llint a, llint b) {
if (a < b)swap(a, b);
return a;
}
llint p(int n) {
if (n == 1)return 1;
return n * p(n - 1);
}
struct UnionFind {
vector<int> par;
UnionFind(int N) : par(N) {
for (int i = 0; i < N; i++) par[i] = i;
}
int size(int a) {
return par[root(a)];
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
par[rx] = ry;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main() {
llint n,k;
cin >> n >> k;
hei(int) a(n);
rep(i,0,n)cin>>a[i];
llint x = 0;
rep(i, 0, n - 1) {
rep(j, i + 1, n) {
if (a[i] > a[j])x++;
}
}
llint ans = x * k % mod;
x = 0;
rep(i, 0, n) {
rep(j, 0, n) {
if (a[i] > a[j])x++;
}
}
ans += x * c(k, 2, mod);
ans %= mod;
cout << ans << endl;
return 0;
} | 0 | 5,653,501 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P,P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()
int main() {
int n, a, b, c, x;
while(cin >> n >> a >> b >> c >> x, n){
int y[105];
REP(i,n) cin >> y[i];
int cnt = 0, k=0;
while(k<n && cnt<=10000){
if(x==y[k])k++;
x = (a*x+b)%c;
cnt++;
}
cnt--;
if(k==n && cnt<=10000){
cout << cnt << endl;
}
else{
cout << -1 << endl;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
#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 rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll n,x,m;
cin>>n>>x>>m;
vll id(m,-1);
vll a;
ll len=0;
ll tot=0;
while(id[x]==-1){
a.push_back(x);
id[x]=len;
len++;
x=x*x%m;
}
ll loop_sum=0;
for(int i=id[x];i<len;i++){
loop_sum+=a[i];
}
ll ans=0;
if(n<=len){
rep(i,n)ans+=a[i];
}else{
rep(i,id[x])ans+=a[i];
n-=id[x];
ans+=loop_sum*(n/(len-id[x]));
rep(j,n%(len-id[x]))ans+=a[id[x]+j];
}
cout<<ans<<endl;
return 0;
} | 0 | 60,645,543 |
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
ll n;
cin>>n;
ll A[n];
int k;
cin>>k;
for(int i=0;i<n;i++){
cin>>A[i];
}
ll dp[n+5];
dp[0]=0;
dp[1]=abs(A[1]-A[0]);
for(int i=2;i<n;i++){
dp[i]=INT_MAX;
for(int j=1;j<=k&&i-j>=0;j++){
dp[i]=min(dp[i],dp[i-j]+abs(A[i]-A[i-j]));
}
}
cout<<dp[n-1];
return 0;
} | #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll gcd(ll a,ll b){
if(b == 0) return a;
return gcd(b , a % b);
}
ll mod(ll a){
return (a % 1000000007);
}
ll lcm(ll a,ll b){
return (a*b)/gcd(a,b);
}
int main(){
ll n,m; cin >> n >> m;
vector<ll> dp(n+1); vector<bool> isbreak(n+1);
rep(i,m){
ll x; cin >> x;
isbreak[x] = true;
}
if(n == 1){
if(isbreak[1]) cout << 0 << endl;
else cout << 1 << endl;
}
else{
if(isbreak[1] && isbreak[2]){
cout << 0 << endl;
return 0;
}
else if(isbreak[1] && !isbreak[2]){
dp[1] = 0; dp[2] = 1;
}
else if(!isbreak[1] && isbreak[2]){
dp[1] = 1; dp[2] = 0;
}
else{
dp[1] = 1; dp[2] = 2;
}
for(ll i=3; i <= n; i++){
if(isbreak[i]){
continue;
}
else{
dp[i] = dp[i-1] + dp[i-2];
dp[i] = mod(dp[i]);
}
}
cout << dp[n] << endl;
}
} | 0 | 65,980,942 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;
llong n;
llong cnt[10];
int main() {
for (int i = 0; i < 4; i++) {
cin >> n;
cnt[n] = 1;
}
if (cnt[1] && cnt[9] && cnt[7] && cnt[4]) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
} | #include <iostream>
using namespace std;
int main(){
int m,f,r,score;
while(true){
cin >> m >> f >> r;
score = m + f;
if(score < 0 && r == -1) break;
else if( m == -1 || f == -1 || score < 30) cout << "F\n";
else if(score >= 80) cout << "A\n";
else if(score >= 65 && score < 80) cout << "B\n";
else if(score >= 50 && score < 65) cout << "C\n";
else if(score >= 30 && score < 50){
if(r >= 50) cout << "C\n";
else cout << "D\n";
}
}
return 0;
} | 0 | 47,699,362 |
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
signed main() {
int n,m,x;
cin>>n>>m>>x;
int c[n];
vector<vector<int>> v(n,vector<int>(m));
for(int i=0;i<n;i++)
{
cin>>c[i];
for(int j=0;j<m;j++)
{
cin>>v[i][j];
}
}
int ans=INT_MAX;
int all = 1<<n;
for(int i=0;i<all;i++)
{
vector<int> lev(m,0);
int cost=0;
for(int j=0;j<n;j++)
{
if((i>>j) & 1)
{
cost += c[j];
for(int j1=0;j1<m;j1++)
{
lev[j1] += v[j][j1];
}
}
}
bool flag=1;
for(int i1=0;i1<m;i1++)
{
if(lev[i1]<x)
{
flag=0;
}
}
if(flag)
{
ans = min(ans,cost);
}
}
if(ans==INT_MAX)
cout<<-1;
else
cout<<ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> w[m];
while ( n-- > 0 ) {
int a, b;
cin >> a >> b;
a--;
if ( a < m ) {
w[a].push_back(b);
}
}
long long ans = 0;
priority_queue<int> q;
for ( int i = 0; i < m; i++ ) {
for ( int j = 0; j < w[i].size(); j++ ) {
q.push(w[i][j]);
}
if ( ! q.empty() ) {
ans += q.top();
q.pop();
}
}
cout << ans << endl;
return 0;
} | 0 | 73,573,781 |
#include <iostream>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N, M, K;
cin >> N >> M >> K;
for(int i = 0; i <= M; ++i){
int sum = i*N;
for(int j = 0; j <= N; ++j){
sum = i*N - i*j + j*(M-i);
if(sum == K){
cout << "Yes" << '\n';
return 0;
}
}
}
cout << "No" << '\n';
return 0;
} | #include <bits/stdc++.h>
const int INF = 1e9;
const long long INFLL = 1e18;
const int NMAX = 200005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD = 1e9 + 7;
using namespace std;
#define DEBUG
#define FORi(N) for(ll i = 0; i < N; ++i)
#define FORj(N) for(ll j = 0; j < N; ++j)
#define FORk(N) for(ll k = 0; k < N; ++k)
#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif
#define fi first
#define se second
#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};
struct edge{
int to,cost;
};
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
va_list arg;
va_start(arg, format);
vprintf(format, arg);
va_end(arg);
}
#endif
#ifdef DEBUG
#define DUMPV(v, c) do{ \
printf("%s: ", #v); \
for (int i = 0; i < (c); ++i) \
{ \
cout << (v)[i] << " "; \
} \
cout << endl; \
} while(0)
#else
#define DUMPV(v,c)
#endif
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( reinterpret_cast<T*>(array),
reinterpret_cast<T*>(array+N),
val );
}
ll BSearch(ll ok, ll ng, bool (*f)(ll)){
ll mid;
while(abs(ok - ng) > 1LL) {
mid = (ok + ng) / 2LL;
if(f(mid)) {
debug("BSearch: f(%d) == true\n", mid);
ok = mid;
}
else
{
debug("BSearch: f(%d) == false\n", mid);
ng = mid;
}
}
return ok;
}
ll NUM_TEST_CASE = 1;
ll N,M,K,A[NMAX],B,C,D,E;
int dp[NMAX] = {};
string S;
vec v;
ll ans = {};
void solve(){
ll high = 0;
FORi(N) {
ans += max(high - A[i], 0LL);
high = max(high, A[i]);
}
}
void debug(){
}
void answer(){
cout << ans << endl;
}
void init(){
}
int main(int argc, char const *argv[])
{
for (int test_case = 0; test_case < NUM_TEST_CASE; ++test_case)
{
init();
cin >> N;
FORi(N) cin >> A[i];
solve();
#ifdef DEBUG
debug();
#endif
answer();
}
return 0;
} | 0 | 20,119,745 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int,string>;
int main() {
int h,w;
cin >> h >> w;
vector<vector<char>> a(h,vector<char>(w));
rep(i,h)rep(j,w) cin >> a.at(i).at(j);
rep(i,2*h)rep(j,w){
cout <<a.at((i+2)/2-1).at(j);
if(j == w-1) cout << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
constexpr int B = 20;
int main() {
int n, l, q;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
cin >> l >> q;
vector<vector<int>> data(B, vector<int>(n));
for (int i = 0; i < n; i++) {
int ok = a[i] + l;
data[0][i] = (prev(upper_bound(a.begin(), a.end(), ok)) - a.begin());
}
for (int i = 1; i < B; i++) for (int j = 0; j < n; j++) {
if (data[i-1][j] == n-1) data[i][j] = data[i-1][j];
else data[i][j] = data[i-1][data[i-1][j]];
}
auto bs = [&] (int i, int x) {
for (int s = 0; s < B; s++) {
if (x&(1<<s)) i = data[s][i];
}
return i;
};
auto query = [&] (int a, int b) {
int ok = n, ng = 0;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (bs(a, mid) >= b) ok = mid;
else ng = mid;
}
return ok;
};
while (q--) {
int a, b;
cin >> a >> b;
if (a > b) swap(a, b);
cout << query(--a, --b) << endl;
}
return 0;
} | 0 | 53,324,483 |
#include <iostream>
using namespace std;
int main()
{
int m, k;
cin >> m >> k;
if(k >= (1 << m)){
cout << -1 << endl;
return 0;
}
if(m == 0){
if(k == 0){
cout << "0 0" << endl;
}
else{
cout << -1 << endl;
}
return 0;
}
if(m == 1){
if(k == 0){
cout << "1 1 0 0" << endl;
}
else{
cout << -1 << endl;
}
return 0;
}
for(int i = 0; i < (1 << m); i++){
if(i == k) continue;
cout << i << " ";
}
cout << k << " ";
for(int i = (1 << m) - 1; i >= 0; i--){
if(i == k) continue;
cout << i << " ";
}
cout << k << endl;
} | #include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#define INF 10000000
using namespace std;
struct data{
int x,y;
};
int H,W,N;
int ans[1001][1001];
char field[1001][1001];
int cou,sx,sy;
void bfs(data start,int num){
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
data g;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
ans[i][j]=INF;
if(field[i][j]==num+'0'){
g.x=i,g.y=j;
}
}
}
ans[start.x][start.y]=0;
queue<data> q;
q.push(start);
while(!q.empty()){
data now=q.front();
q.pop();
if(now.x==g.x&&now.y==g.y)break;
int nex,ney;
for(int i=0;i<4;i++){
nex=now.x+dx[i];
ney=now.y+dy[i];
if(nex>=0&&nex<H&&ney>=0&&ney<W&&field[nex][ney]!='X'&&ans[nex][ney]==INF){
data nowne;
nowne.x=nex,nowne.y=ney;
q.push(nowne);
ans[nex][ney]=ans[now.x][now.y]+1;
}
}
}
cou+=ans[g.x][g.y];
if(num!=N)bfs(g,num+1);
}
int main(){
data s;
cin>>H>>W>>N;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>field[i][j];
if(field[i][j]=='S'){
s.x=i,s.y=j;
}
}
}
bfs(s,1);
cout<<cou<<endl;
return 0;
} | 0 | 46,535,770 |
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n,m; cin >> n >> m;
long long ac, a[n], num=0, x; cin >> a[0];
a[0]/=2;
x = a[0];
while(x % 2 == 0){
x /= 2;
num++;
}
bool ok = true;
for (int i=1; i<n; i++){
cin >> a[i];
a[i] /= 2ll;
x = a[i];
int temp=0;
while(x % 2 == 0){
temp++;
x/=2;
}
if (temp != num) ok =false;
}
if (!ok){
cout << "0\n";
return 0;
}
ac = a[0];
for (int i=1; i<n; i++){
ac = ac*a[i]/__gcd(ac, a[i]);
if (ac > 2*m){
ok = false;
break;
}
}
if (!ok) cout << "0\n";
else cout << m/ac - m/(ac*2) << endl;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';
using namespace std;
int main(void){
ll N, K;
cin>>N>>K;
ll V[100];
rep(i, N) cin>>V[i];
ll Maxim=0;
rep(i, K+1) rep(j, K+1-i){
if(i+j>N) continue;
ll count=0;
vector<ll> je;
rep(k, i) je.push_back(V[k]);
rep(k, j) je.push_back(V[N-1-k]);
sort(all(je));
rep(k, K-i-j){
if(k<je.size()) if(je[k]<0) je[k]=0;
}
rep(i, je.size()){
count+=je[i];
}
Maxim=max(Maxim, count);
}
cout<<Maxim<<endl;
return 0;
} | 0 | 74,759,328 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;
int main(){
ll n, a, b;
cin >> n >> a >> b;
if(a>b) cout << 0 << endl;
else if(a==b) cout << 1 << endl;
else{
if(n==1) cout << 0 << endl;
else if(n==2) cout << 1 << endl;
else{
ll multi = n-2;
cout << b*multi-a*multi+1 << endl;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<int,int>
string make_string(int p, int x){
string left, right, a, b;
a=to_string(p); b=to_string(x);
rep(i,6-a.size()) left+='0';
left+=a;
rep(i,6-b.size()) right+='0';
right+=b;
return left+right;
}
int main(){
int n, m;
cin >> n >> m;
vector<string> ans(m);
vector<vector<P>> info(n+1);
rep(i,m){
int p, y;
cin >> p >> y;
p--;
info[p].push_back(make_pair(y,i));
}
rep(i,n){
if(info[i].size()==0) continue;
sort(info[i].begin(),info[i].end());
int tmp=0;
for(auto x : info[i]){
tmp++;
string now = make_string(i+1,tmp);
ans[x.second]=now;
}
}
rep(i,m){
cout<<ans[i]<<endl;
}
} | 0 | 63,474,881 |
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;
const int MOD = 1e9 + 7;
class Modint {
public:
long long val;
Modint (long long _val = 0)
: val((_val + MOD) % MOD) {}
Modint operator+ (Modint other) {
return Modint(val + other.val);
}
void operator+= (Modint other) {
val += other.val;
val %= MOD;
}
Modint operator- () {
return Modint(MOD - val);
}
Modint operator- (Modint other) {
return Modint(val + MOD - other.val);
}
void operator-= (Modint other) {
val += MOD - other.val;
val %= MOD;
}
Modint operator* (Modint other) {
return Modint(val * other.val);
}
void operator*= (Modint other) {
val *= other.val;
val %= MOD;
}
bool operator== (Modint other) {
return val == other.val;
}
bool operator!= (Modint other) {
return val != other.val;
}
};
Modint exp (Modint a, int k) {
if (k == 0) {
return Modint(1);
} else if (k % 2 == 0) {
Modint half = exp(a, k / 2);
return half * half;
} else {
return a * exp(a, k - 1);
}
}
Modint inv (Modint a) {
return exp(a, MOD - 2);
}
ostream& operator<< (ostream& out, Modint p) {
out << p.val;
return out;
}
int n;
string L;
vector<vector<Modint>> dp;
Modint func(int i, bool flg) {
if (i == n) return 1;
if (dp[i][flg] != 0) return dp[i][flg];
Modint res = 0;
if (flg == true) {
if (L[i] == '0') res += func(i + 1, true);
else res += (Modint(2) * func(i + 1, true) + func(i + 1, false));
}
else res += Modint(3) * func(i + 1, false);
return dp[i][flg] = res;
}
int main() {
cin >> L;
n = L.length();
dp.resize(n + 1, vector<Modint>(2, 0));
cout << func(0, true);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;
bool f(long n){
cout << "? " << n << endl;
char c;cin >> c;
return c=='Y'?true:false;
}
int main(){
long k=1;
int s;
long n=0;
for (int i = 0; i <= 8; i++) {
if(!f(k*10)){
s=i;
int l=0,r=10;
while(abs(r-l)>1){
int m=(l+r)/2;
if(f(k*m*10)){
r=m;
}
else{
l=m;
}
}
n=k*l;
break;
}
if(i==8){
k=1;
for (long a = 2; a < 10000000000l; a=a*10+2) {
if(f(a)){
cout << "! " << k << endl;
return 0;
}
k*=10;
}
return 0;
}
k*=10;
}
k/=10;
for (int i = 0; i < s; i++) {
int l=0,r=10;
while(abs(r-l)>1){
int m=(l+r)/2;
if(f((n+k*m)*10)){
r=m;
}
else{
l=m;
}
}
n+=l*k;
k/=10;
}
cout << "! " << n+1 << endl;
return 0;
} | 0 | 41,044,250 |
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;
template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
int x, n;
cin >> x >> n;
vi a(111, 0);
for(int i = 0; i < n; i++)
{
int b; cin >> b;
a[b] = 1;
}
pii ans(120, 120 + x);
for(int i = 0; i <= 110; i++)
if(!a[i]) ans = min(ans, pii(abs(x - i), i));
cout << ans.second << endl;
return 0;
} | #include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vll vector<ll>
#define inf 1e9
#define mod 1e9 + 7
using namespace std;
ll gcd(ll a,ll b){
if(a==0)return b;
return gcd(b%a,a);
}
ll lcm(ll a, ll b){
return (a*b)/gcd(a,b);
}
ll power(ll x, ll y)
{
ll res = 1;
while (y > 0)
{
if (y & 1)
res = res*x;
y = y>>1;
x = x*x;
}
return res;
}
int main(){
int n, p;
cin>>n>>p;
string s;
cin>>s;
ll ans=0;
if(p==2){
lpi(0,n){
if((s[i]-'0')%2 == 0){
ans += i+1;
}
}
}
else if(p==5){
lpi(0,n){
if((s[i]-'0')%5==0) ans+=i+1;
}
}
else{
map<int , int> mp;
int t=0, p1=1;
mp[0]++;
for(int i=n-1; i>=0; i--){
t = (t+(s[i]-'0')*p1)%p;
p1 = (p1*10)%p;
ans += mp[t];
mp[t]++;
}
}
cout<<ans;
} | 0 | 38,445,244 |
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define f first
#define se second
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PI 3.14159265358979323846264338327950L
typedef long long ll;
const ll MOD =1e9+7;
char grid1[51][51];
char grid2[51][51];
void solve(){
int N,M;
cin>>N>>M;
int cnt=0;
for(int i=0;i<N;++i)cin>>grid1[i];
for(int i=0;i<M;++i)cin>>grid2[i];
bool flag=0;
for(int row1=0;row1<=N-M;++row1){
for(int col1=0;col1<=N-M;col1++){
if(row1+M-1>=N||col1+M-1>=N)continue;
bool ok=1;
for(int row2=0;row2<M;++row2){
for(int col2=0;col2<M;col2++){
if(grid1[row1+row2][col1+col2]!=grid2[row2][col2])
ok=0;
}
}
if(ok){
cout<<"Yes"<<endl;
return;
}
}
}
cout<<"No"<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
} | #include <iostream>
#include <stack>
using namespace std;
char bl[5]= "([)]";
int main(){
string str;
while(getline(cin,str) && str[0]!='.'){
stack<char> stk;
for(int i=0; str[i]!='.'; i++){
for(int j=0; j<2; j++){
if(str[i]==bl[j]){
stk.push(str[i]);
}
}
for(int j=2; j<4; j++){
if(str[i]==bl[j]){
if(stk.empty() || stk.top()!=bl[j-2]){
stk.push(0);
break;
}else{
stk.pop();
}
}
}
}
if(stk.empty()){
cout << "yes" << endl;
}else{
cout << "no" << endl;
}
}
return 0;
} | 0 | 46,590,402 |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
string s;
cin>>s;
for(int i=s.size()-1;i>=0;i--) cout<<s[i];
cout<<endl;
return 0;
} | #include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
typedef long long ll;
#define mop 1000000007
using namespace std;
int main() {
string s;
cin >> s;
ll k;
cin >> k;
set <char> memo;
for(ll i=0;i<s.length();i++){
memo.insert(s[i]);
}
if(memo.size() == 1){
cout << s.length()*k/2 << endl;
}else{
char state = 'X';
ll ans1 = 0;
for(ll i=0;i<s.length();i++){
if(s[i] == state){
ans1++;
state = 'X';
}else {
state = s[i];
}
}
ll ans2 = 0;
string t;
t = s+s;
state = 'X';
for(ll i=0;i<t.length();i++){
if(t[i] == state){
ans2++;
state = 'X';
}else {
state = t[i];
}
}
cout << ans1 + (k-1) * (ans2 - ans1) << endl;
}
} | 0 | 36,640,229 |
#include <iostream>
using namespace std;
int main()
{
int A, B, X;
cin >> A;
cin >> B;
cin >> X;
if((X>=A)&(A+B)>=X)
{
cout << "YES";
}
else
{
cout << "NO";
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
int main() {
int n;
cin >> n;
vector<pair<double, pair<double,double>>> v;
rep(i,n){
double x, y;
cin >> x >> y;
pair<double, pair<double,double>> p;
p.first = atan2(y, x);
p.second.first = x;
p.second.second = y;
v.push_back(p);
}
sort(v.begin(), v.end());
rep(i,n){
v.push_back(v[i]);
}
double ans = 0;
rep(i,n){
srep(j, 1, n+1){
ll tmpx = 0;
ll tmpy = 0;
rep(k,j){
tmpx += v[i+k].second.first;
tmpy += v[i+k].second.second;
}
ans = max(ans, sqrt(tmpx*tmpx + tmpy*tmpy));
}
}
cout << fixed << setprecision(10) << ans << endl;
return 0;
} | 0 | 45,785,541 |
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
int main() {
ll W,H,N;
cin>>W>>H>>N;
ll up=H;
ll down=0;
ll left=0;
ll right=W;
for(ll i=0;i<N;i++) {
ll x,y,a;
cin>>x>>y>>a;
if(a==1) {
left=max(left,x);
}
else if(a==2) {
right=min(right,x);
}
else if(a==3) {
down=max(down,y);
}
else {
up=min(y,up);
}
}
if(up>down&&right>left) {
cout<<(up-down)*(right-left)<<endl;
return 0;
}
else {
cout<<0<<endl;
}
} | #include<bits/stdc++.h>
using namespace std;
auto ____ = [] () {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); };
typedef int_fast64_t LL;
const int_fast32_t MAXN = 3e5+7;
int_fast32_t n,A[MAXN],height[MAXN],F[MAXN];
int main(){
____();
cin >> n;
for(int i = 1; i <= n; i++){
int tp;
cin >> tp;
A[tp]++;
}
for(int i = 1; i <= n; i++) height[A[i]]++;
LL LS = 0, R = n - height[0];
for(int h = 1; h <= n; h++){
F[h] = LS/h+R;
R -= height[h];
LS += height[h] * h;
}
int h = n;
for(int i = 1; i <= n; i++){
while(h>0&&F[h]<i) h--;
cout << h << endl;
}
return 0;
} | 0 | 35,563,969 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
scanf("%d %d", &a, &b);
if((a > 8) || (b > 8)){
printf(":(\n");
}else{
printf("Yay!\n");
}
return 0;
} | #include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
while(cin >> n){
bool prime[1000000] = {false};
prime[1] = true;
prime[2] = false;
int count = 0;
for(int j = 2; j * j <= n ; j++){
if(!prime[j]){
for (int k = 2; k*j <= n;k++){
prime[j*k] = true;
}
}
}
for(int i = 1;i<=n;i++){
if(!prime[i]) count = count +1;
}
cout << count << endl;
}
return 0;
} | 0 | 63,022,454 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
const ll inf = 1001001001;
const ll mod = 1000000007;
int main() {
int n;
cin >> n;
string s;
cin >> s;
string ans = s;
int p=0;
rep(i, 0, n){
if(s[i] == '(')p++;
else p--;
if(p < 0){
ans = '(' +ans;
p++;
}
if(i == n-1 && p > 0){
int j = p;
while(p > 0){
ans += ')';
p--;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long mod = 1e9+7;
const long long INF = 9e15;
const double PI = 3.14159265358979323846;
using ll = long long;
using P = pair<long long, long long>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vP = vector<pair<long long, long long>>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, k, n) for (int i = k; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mkp make_pair
#define vin(v, N) for (long long i = 0; i < N; i++) cin >> v.at(i)
#define lin(n)long long n;cin >> n
#define chin(x)char x;cin >> x;
#define sin(s)string s;cin >> s;
#define vlin(v, N)vector<long long> v(N);for (long long i = 0; i < N; i++)cin >> v.at(i)
#define max(a, b) max((ll)a, (ll)b)
#define min(a, b) min((ll)a, (ll)b)
long long gcd(long long m, long long n){
long long a = max(m, n);
long long b = min(m, n);
long long r = a % b;
while (r != 0){
a = b;
b = r;
r = a % b;
}
return b;
}
long long lcd(long long m, long long n){
return m * n / gcd(m, n);
}
long long power(long long x, long long N){
long long ret = 1;
for (long long i = 0; i < N; i++)
ret *= x;
return ret;
}
long long repeat_squaring(long long x, long long n){
if (n == 0)
return 1;
else if (n % 2 == 0)
{
long long t = repeat_squaring(x, n / 2);
return t * t % mod;
}
else
return x * repeat_squaring(x, n - 1);
}
map<long long, long long> factor(long long p){
ll p1 = p;
map<long long, long long> ret;
for (long long i = 2; i * i <= p1; i++)
{
while (p % i == 0)
{
ret[i]++;
p /= i;
}
}
if (p != 1)
ret[p]++;
return ret;
}
bool is_prime(long long N){
for (long long i = 2; i * i <= N; i++)
{
if (N % i == 0)
return false;
}
return true;
}
void chmax(long long &a, long long b){
a = max(a, b);
}
void chmin(long long &a, long long b){
a = min(a, b);
}
struct UnionFind
{
vector<long long> par;
vector<long long> s;
UnionFind(long long N) : par(N), s(N){
for (long long i = 0; i < N; i++)
{
par[i] = i;
s[i] = 1;
}
}
long long root(long long i){
if (par[i] == i)
return i;
par[i] = root(par[i]);
return root(par[i]);
}
long long size(long long i){
return s[root(i)];
}
bool same(long long x, long long y){
return root(x) == root(y);
}
void unite(long long x, long long y){
if (!same(x, y)){
long long rx = root(x);
long long ry = root(y);
par[rx] = par[ry];
s[ry] = s[rx] + s[ry];
}
}
};
struct BIT{
vector<long long> bit;
long long N;
BIT(long long n){
N = n;
bit.resize(N + 1);
}
void add(long long i, long long w){
for (long long x = i; x <= N; x += x & -x){
bit[x] += w;
}
}
long long sum(long long i){
long long ret = 0;
for (long long x = i; x > 0; x -= x & -x){
ret += bit[x];
}
return ret;
}
};
int main(){
std::cout << fixed << setprecision(10);
lin(N);vlin(a,N);
vl dp(N, INF);
rep(i,N){
auto iter = lower_bound(all(dp), a[i]);
*iter = a[i];
}
ll res = 0;
rep(i,N){
if(dp[i] != INF) res++;
}
cout << res << endl;
} | 0 | 10,664,611 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "{";
rep(i, v.size()) {
if (i) os << ",";
os << v[i];
}
os << "}";
return os;
}
#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
const int maxn = 100010;
int nxt[20][maxn];
int main() {
int n;
cin >> n;
V<int> x(n);
rep(i, n) cin >> x[i];
int L, Q;
cin >> L >> Q;
rep(i, n) {
int p = upper_bound(ALL(x), x[i] + L) - x.begin();
nxt[0][i] = p - 1;
}
rep(i, 19) {
rep(j, n) {
nxt[i + 1][j] = (nxt[i][j] == n - 1 ? n - 1 : nxt[i][nxt[i][j]]);
}
}
while (Q--) {
int a, b;
cin >> a >> b;
--a, --b;
if (a > b) swap(a, b);
int ans = 0;
for (int j = 19; j >= 0; --j) {
if (nxt[j][a] < b) {
ans |= (1 << j);
a = nxt[j][a];
}
}
cout << ans + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " : " << x << '\n';
const int N = 100100;
int n;
int a[N], b[N], c[N];
int dp[N][3];
int main() {
cin >> n;
for(int i = 0; i < n; ++i)
cin >> a[i] >> b[i] >> c[i];
dp[0][0] = a[0];
dp[0][1] = b[0];
dp[0][2] = c[0];
for(int i = 1; i < n; ++i) {
dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
}
cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
} | 0 | 4,431,716 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,K,j=0;
cin>>A>>B>>K;
int i=min(A,B);
for(;j<K;i--)
if(A%i==0 && B%i==0)
j++;
cout<<i+1<<endl;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int k,i,l;
string s;
cin>>k>>s;
l=s.size();
if(l<=k)
cout<<s<<endl;
else
{
for(i=0;i<k;i++)
{
cout<<s[i];
}
cout<<"..."<<endl;
}
return 0;
} | 0 | 54,936,114 |
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;
ll dp0[100001];
ll dp1[100001];
int main(){
string s;
cin >> s;
dp1[0] = 2;
dp0[0] = 1;
for (int i = 1; i < s.length(); i++){
if (s[i] == '1'){
dp1[i] = dp1[i-1]*2%MOD;
dp0[i] += dp1[i-1];
}else{
dp1[i] = dp1[i-1]%MOD;
}
dp0[i] += dp0[i-1]*3;
dp0[i] %= MOD;
}
cout << (dp1[s.length()-1] + dp0[s.length()-1])%MOD<< endl;
return 0;
} | #include <cstdio>
#define int long long
#define dotimes(i, n) for (int i : range(n))
using namespace std;
class range {
class iterator {
int i, s;
public:
iterator(int i, int s): i(i), s(s) {}
int& operator*() {
return i;
}
void operator++() {
i += s;
}
bool operator!=(iterator const& that) {
return i < that.i;
}
};
iterator b, e;
public:
range(int e): b({0, 1}), e({e, 1}) {}
range(int b, int e): b({b, 1}), e({e, 1}) {}
range(int b, int e, int s): b({b, s}), e({e, s}) {}
iterator begin() {
return b;
}
iterator end() {
return e;
}
};
int rint() {
int n;
scanf("%lld", &n);
return n;
}
void wint(int n) {
printf("%lld\n", n);
}
template<typename T>
inline int size(T container) {
return static_cast<int>(container.size());
}
template<typename T>
inline bool maxs(T& a, T const& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<typename T>
inline bool mins(T& a, T const& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
signed main() {
const int N = rint();
const int K = rint();
int a[N];
dotimes(i, N)
a[i] = rint();
int r = 1e12;
dotimes(k, 1 << (N - 1)) {
int h = a[0];
int c = 0, s = 0;
dotimes(i, N - 1) {
if ((k >> i) & 1) {
c++;
if (!maxs(h, a[i+1]))
s += ++h - a[i+1];
} else if (h < a[i+1])
goto fail;
}
if (c >= K - 1)
mins(r, s);
fail:
;
}
wint(r);
return 0;
} | 0 | 80,676,846 |
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;
int main() {
int N;
cin >> N;
vector<int> L(2 * N);
rep(i, 2 * N) cin >> L[i];
sort(L.begin(), L.end());
int ans = 0;
rep(i, N) ans += L[2 * i];
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
int main() {
string S;
cin >> S;
int N = S.size();
ll ans = 0;
for (int i = 0, j = 0; j < N; j++) {
if (S[j] == 'W') {
ans += (ll)j - i;
i++;
}
}
cout << ans << endl;
} | 0 | 23,602,983 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
int main(){
int n;cin >> n;
ll sum = 0;
vi a(n);
rep(i,n) cin >> a[i];
ll ans = 0;
rep(i,n){
ans += a[i]/2;
if(i+1<n && (a[i]&1) && a[i+1]>0) ++ans,--a[i+1];
}
cout << ans << endl;
} | #include<bits/stdc++.h>
#define int long long
using namespace std;
using P=pair<int,int>;
const int INF=1000000000000;
signed main(){
int N,M;
cin>>N>>M;
vector<vector<P>> A(N);
while(M--){
int a,b,c;
cin>>a>>b>>c;
A[a-1].push_back({b-1,c});
A[b-1].push_back({a-1,-c});
}
vector<int> B(N,INF);
for(int i=0;i<N;i++){
if(B[i]!=INF)continue;
queue<int> Q;
Q.push(i);
B[i]=0;
int mx=0,mn=0;
while(!Q.empty()){
int I=Q.front();
Q.pop();
mx=max(mx,B[I]);
mn=min(mn,B[I]);
for(P p:A[I]){
if(B[p.first]==INF){
B[p.first]=B[I]+p.second;
Q.push(p.first);
}else if(B[p.first]!=B[I]+p.second){
puts("No");
return 0;
}
}
}
if(mx-mn>1000000000){
puts("No");
return 0;
}
}
puts("Yes");
} | 0 | 18,486,817 |
#include <bits/stdc++.h>
using namespace std;
#define f0r(a, b) for (long long a = 0; a < b; a++)
#define f1r(a, b, c) for (long long a = b; a < c; a++)
#define f0rd(a, b) for (long long a = b; a >= 0; a--)
#define f1rd(a, b, c) for (long long a = b; a >= c; a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define f first
#define s second
#define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << endl;}
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
const ll inf = 1e12;
const ll mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll n; cin >> n;
string s, t; cin >> s >> t;
string ret = "";
f0r(i, n) {
ret += s[i];
ret += t[i];
}
cout << ret << endl;
} | #include <iostream>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n ;
cin >> n ;
ll ans = 0 ;
ll a, b ;
REP(i,n){
cin >> a ;
if(i==0){
ans += a/2 ;
b = a%2 ;
continue ;
}
if(a==0){
b = 0 ;
continue ;
}
ans += b ;
a -= b ;
ans += a/2 ;
b = a%2 ;
}
cout << ans << endl ;
return 0;
} | 0 | 38,379,709 |
#include <iostream>
using namespace std;
const int lim = 1e7 + 1;
int lp[lim] , n;
void sieve(){
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j += i)
lp[j] += 1;
}
int main(){
cin >> n;
sieve();
long long ans = 0;
for (int i = 1; i <= n; i++)
ans = ans + 1LL * lp[i] * i;
cout << ans;
return 0;
} | #include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main(){
string s;
cin >> s;
int cnt=0, l=s.length();
for(int i=0; i<l; i++){
if(s[i]=='o') cnt++;
}
if(cnt+7-l>=0) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
} | 0 | 98,124,875 |
#include<iostream>
using namespace std ;
int main()
{
int a[3],b[3] ;
for(int i=0;i<3;i++) cin>>a[i]>>b[i] ;
int c[6]={a[0],a[1],a[2],b[0],b[1],b[2]} ;
int count[4]={0} ;
for(int i=0;i<6;i++){
switch(c[i]){
case 1: count[0]++ ;
break ;
case 2: count[1]++ ;
break ;
case 3: count[2]++ ;
break ;
case 4: count[3]++ ;
break ;
}
}
if(count[0]*count[1]*count[2]*count[3]==4&&
count[0]+count[1]+count[2]+count[3]==6){
cout<<"YES"<<endl ;
}else cout<<"NO"<<endl ;
return 0 ;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef pair<int,int> P;
int main(){
ll N;
cin >> N;
vector<ll> A(N), B(N);
vector<pair<ll,ll>> C(N),D(N);
rep(i,N){
cin >> A[i] >> B[i];
C[i] = make_pair(A[i] + B[i], i);
}
sort(C.begin(), C.end(), greater<pair<ll,ll>>());
ll L = 0;
ll R = N-1;
ll tak = 0;
ll aok = 0;
rep(i,N){
if(i % 2 == 0){
tak += A[C[i].second];
}else if(i % 2 == 1){
aok += B[C[i].second];
}
}
cout << tak - aok << endl;
} | 0 | 12,001,065 |
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long long ll;
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 int INF = 10000;
ll gcd(ll x, ll y) {
ll tmp = 0;
if (x < y){
tmp=x;
x=y;
y=tmp;
}
while (y > 0) {
ll r = x % y;
x = y;
y = r;
}
return x;
}
ll lcm(ll x,ll y){
return x/gcd(x,y)*y;
}
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll kaijo(ll k){
ll sum = 1;
for (ll i = 1; i <= k; ++i)
{
sum *= i;
sum%=1000000000+7;
}
return sum;
}
ll lmax(ll s,ll t){
if(s>t){
return s;
}
else{
return t;
}
}
ll lmin(ll s,ll t){
if(s<t){
return s;
}
else{
return t;
}
}
int main(){
int n,k;
cin>>n>>k;
cout<<n-k+1<<endl;
return 0;
} | #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() {
ll N, Y;
cin >> N >> Y;
Y /= 1000;
ll x = -1, y = -1, z = -1;
for (ll i = 0; i <= N; i++) {
for (ll j = 0; i + j <= N; j++) {
ll k = N - i - j;
ll t = 10 * i + 5 * j + k;
if (t == Y) {
x = i, y = j, z = k;
}
}
}
cout << x << " " << y << " " << z << "\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;
} | 0 | 46,338,451 |
#include<stdio.h>
#include <string.h>
int main(){
char n[201],s[101],t[101];
char *p;
scanf("%s %s",n,s);
strcpy(t,n);
strcat(n,t);
p=strstr(n,s);
if(p==NULL)printf("No\n");
else printf("Yes\n");
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
using namespace std;
using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;
int main() {
ll N;
scanf("%lld", &N);
ll M;
scanf("%lld", &M);
vector<ll> S(N + 1);
for (ll i = 0; i < N; i++) {
scanf("%lld", &S[i]);
}
vector<ll> T(M + 1);
for (ll i = 0; i < M; i++) {
scanf("%lld", &T[i]);
}
vector<vector<ll>> dp0(N + 2, vector<ll>(M + 2, 0));
vector<vector<ll>> dp1(N + 2, vector<ll>(M + 2, 0));
dp0[0][0] = 1;
for (ll j = 0; j <= M; j++) {
for (ll i = 0; i <= N; i++) {
dp0[i + 1][j] += dp0[i][j];
dp1[i][j] += dp0[i][j];
dp1[i][j + 1] += dp1[i][j];
if (S[i] == T[j]) {
dp0[i + 1][j + 1] += dp1[i][j];
dp0[i + 1][j + 1] %= MOD;
}
dp0[i + 1][j] %= MOD;
dp1[i][j] %= MOD;
dp1[i][j + 1] %= MOD;
}
}
printf("%lld\n", dp1[N][M]);
} | 0 | 50,572,965 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
int main(){
ios::sync_with_stdio(0);
int x; cin>>x;
for(int i=2;;i++){
if(x*i%360==0) return !printf("%d\n",i);
}
} | #include <bits/stdc++.h>
using i64 = long long;
int main() {
int n;
std::cin >> n;
std::vector<i64> a(n);
i64 x = 0;
for (auto &e : a) {
std::cin >> e;
x ^= e;
}
for (auto &e : a) e &= ~x;
for (int i = 60, index = 0; i >= 0; i--) {
int mi = index;
i64 me = -1;
for (int j = index; j < n; j++) {
if ((a[j] & (1ll << i)) && a[j] > me) {
me = a[j];
mi = j;
}
}
if (me == -1) continue;
std::swap(a[index], a[mi]);
mi = index++;
for (int j = 0; j < n; j++) {
if (j != mi && (a[j] & (1ll << i))) a[j] ^= a[mi];
}
}
i64 m = 0;
for (int i = 0; i < n; i++) m ^= a[i];
std::cout << x + m * 2 << std::endl;
return 0;
} | 0 | 14,965,961 |
#include<iostream>
using namespace std;
int main(){
char a;int b,sum=0;
while(1){
a=cin.get();
b=(int)a-48;
if(b>=10||b<0)break;
sum+=b;
}
if(sum%9==0)cout<<"Yes";
else cout<<"No";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define repr(i, a, n) for (ll i = n - 1; (ll)a <= i; i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T>
T mpow(T a, T n)
{
T res = 1;
for (; n; n >>= 1)
{
if (n & 1)
res = res * a;
a = a * a;
}
return res;
}
signed main()
{
int n, nowmx = 0;
cin >> n;
vector<ll> v(n), ans(n, 0);
vector<int> mx(n, 0);
rep(i, 0, n)
{
cin >> v[i];
if (nowmx < v[i])
{
mx[i] = i;
nowmx = v[i];
}
else
{
mx[i] = mx[i - 1];
}
}
int mxi = mx[n - 1], ind = n - 1, nmxi = mxi, cnt = 0, pmxi=0;
priority_queue<ll> q;
while (1)
{
if (0 < mxi)
{
nmxi = mx[mxi - 1];
}
else
{
while (mxi < ind)
{
ans[0]+=v[ind];
ind--;
}
while (!q.empty())
{
ans[0] += q.top();
q.pop();
}
ans[0] += v[0];
ans[0] += (v[mxi]) * cnt;
break;
}
ans[mxi] += (v[mxi] - v[nmxi]) * cnt;
while (mxi < ind)
{
if (v[nmxi] <= v[ind])
{
ans[mxi] += v[ind] - v[nmxi];
cnt++;
}
else
{
q.push(v[ind]);
}
ind--;
}
ind--;
while (!q.empty() && q.top() > v[nmxi])
{
ans[mxi] += q.top() - v[nmxi];
q.pop();
cnt++;
}
ans[mxi] += v[mxi] - v[nmxi];
cnt++;
pmxi = mxi;
mxi = nmxi;
}
rep(i, 0, n) cout << ans[i] << endl;
} | 0 | 19,124,598 |
#include <iostream>
int main(void) {
int d;
int s;
int length;
while (std::cin >> d) {
s = 0;
for (int i = 0; i < (600 / d); i++) {
s += d * d * d * i * i;
}
std::cout << s << std::endl;
}
return 0;
} | #include <stdio.h>
long long n, k, t, s, m, f;
long long a[15];
int b[15];
long long c[15];
int main() {
scanf("%lld%lld", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%lld", a + i);
}
m = 20000000000;
for (int i = 0; i < (1 << n); i++) {
t = i;
s = 0;
c[0] = 0;
f = 0;
for (int j = 0; j < n; j++) {
b[j] = t % 2;
t /= 2;
if (b[j])s++;
}
if (s < k)continue;
t = 0;
f = 0;
for (int j = 0; j < n; j++) {
if (b[j]) {
if (f >= a[j]) {
f++;
t += f - a[j];
}
}
if (f < a[j])f = a[j];
}
if (t < m)m = t;
}
printf("%lld\n", m);
} | 0 | 89,410,052 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,t;
cin>>s>>t;
int a,b;
cin>>a>>b;
string u;
cin>>u;
if (u==s){
a--;
}
else if (u==t){
b--;
}
cout<<a<<" "<<b<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;
ll dp[100010];
int main(){
int n,m;
cin>>n>>m;
vector<bool> ok(100010,true);
rep(i,m){
int a;
cin>>a;
ok[a]=false;
}
dp[0]=1;
rep(i,n){
if(!ok[i]) continue;
dp[i+1]=(dp[i+1]+dp[i])%MOD;
dp[i+2]=(dp[i+2]+dp[i])%MOD;
}
cout<<dp[n]<<endl;
} | 0 | 41,430,159 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define FILL0(x) memset(x,0,sizeof(x))
#define FILL1(x) memset(x,-1,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int h, w, m;
cin >> h >> w >> m;
set<P> bomb;
int yb[h]={0};
int xb[w]={0};
int xmax=0;
int ymax=0;
rep(i, m)
{
int x, y;
cin >> y >> x;
x--;y--;
xb[x]++;
yb[y]++;
bomb.insert(P(y, x));
}
rep(i, w)
{
if(xmax<xb[i])
{
xmax = xb[i];
}
}
rep(i, h)
{
if(ymax<yb[i])
{
ymax = yb[i];
}
}
int ans = xmax + ymax;
vector<int> yy, xx;
rep(i, h)
{
if(ymax==yb[i])
{
yy.push_back(i);
}
}
rep(i, w)
{
if(xmax==xb[i])
{
xx.push_back(i);
}
}
rep(i, yy.size())
{
rep(j, xx.size())
{
if(bomb.count(P(yy[i], xx[j])))
{
continue;
}
else
{
cout << ans << endl;
return 0;
}
}
}
ans--;
cout << ans << endl;
return 0;
} | #include<iostream>
#include<algorithm>
using namespace std;
int main(int argc,char* argv[]){
std::ios_base::sync_with_stdio(false);
int n,M=0;
int *pi,*tmp;
cin>>n;
pi=new int[n];
for(int i=0;i<n;i++){
cin>>pi[i];
M=max(M,pi[i]);
}
tmp=new int[M+1];
for(int i=0;i<n;i++){
tmp[pi[i]]++;
}
bool flag=true;
for(int i=0;i<=M;i++){
if(tmp[i]>0 && flag){
flag=false;
cout<<i;
tmp[i]--;
}
while(tmp[i]>0){
cout<<" "<<i;
tmp[i]--;
}
}
cout<<endl;
return 0;
} | 0 | 3,108,521 |
#include <cstdio>
int main(){
int n;
int a[6] = {500,100,50,10,5,1};
while(scanf("%d",&n), n!= 0){
int t = 0;
n = 1000 - n;
for(int i = 0; i < 6; i++){
t += n / a[i];
n %= a[i];
}
printf("%d\n",t);
}
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (const auto i : v) {
os << i << " ";
}
os << "]";
return os;
}
template<typename T>
ostream& operator<<(ostream& os, const set<T>& s) {
os << "[";
for (const auto i : s) {
os << i << " ";
}
os << "]";
return os;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
int main(int argc, char const *argv[]) {
int N, M;
cin >> N >> M;
vector<vector<int>> D(N), dist(N);
for (int i = 0; i < N; i++) {
D[i].resize(N, -1);
dist[i].resize(N, 1000000);
dist[i][i] = 0;
}
for (int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
a -= 1;
b -= 1;
D[a][b] = D[b][a] = dist[a][b] = dist[b][a] = c;
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j]);
}
}
}
set<pair<int, int>> used;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (D[i][j] == -1) continue;
for (int k = 0; k < N; k++) {
if (dist[i][k] == D[i][j] + dist[j][k]) {
used.insert(make_pair(min(i, j), max(i, j)));
break;
}
}
}
}
cout << M - used.size() << endl;
return 0;
} | 0 | 79,118 |
#include <iostream>
#include <string>
#include <vector>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
int main(){
ll n,k ;
cin >> n >> k ;
string s ; cin >> s ;
char c = s.at(0) ;
vll one,zero ;
if(c=='0') one.push_back(0) ;
ll cnt = 0 ;
for(int i=0;i<n;i++){
if(c=='1'){
if(s.at(i)=='1') cnt++ ;
else{
one.push_back(cnt) ;
cnt = 1 ;
c = '0' ;
}
}else{
if(s.at(i)=='0') cnt++ ;
else{
zero.push_back(cnt) ;
cnt = 1 ;
c = '1' ;
}
}
}
if(c=='1') one.push_back(cnt) ;
else{
zero.push_back(cnt) ;
one.push_back(0) ;
}
if(zero.size()<=k) cout << n << endl ;
else{
ll ans = 0 ;
vll sum_zero(zero.size()+1,0) ;
for(int i=1;i<=zero.size();i++) sum_zero.at(i) = sum_zero.at(i-1)+zero.at(i-1) ;
vll sum_one(one.size()+1,0) ;
for(int i=1;i<=one.size();i++) sum_one.at(i) = sum_one.at(i-1)+one.at(i-1) ;
for(int i=0;i<zero.size()-k+1;i++){
ll sub = sum_zero.at(i+k)-sum_zero.at(i)+sum_one.at(i+k+1)-sum_one.at(i) ;
if(ans<sub) ans = sub ;
}
cout << ans << endl ;
}
} | #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<ll,ll>&a,const pair<ll,ll>&b)
{
return (a.second<b.second);
}
const long double PI=(acos(-1));
const long double EPS=0.0000000001;
long double a,b,x;
long double f(long double a,long double b,long double theta)
{
if(theta>PI/2.0-EPS)
return 0.0;
long double ret;
if(a*tan(theta)<=b)
ret=a*a*b-a*a*a*tan(theta)/2.0;
else
ret=b*b/tan(theta)*a/2.0;
return ret;
}
int main()
{
cin>>a>>b>>x;
long double ok=PI/2.0;
long double ng=0.0;
for(int i=1;i<=10000;i++)
{
long double mid=(ok+ng)/2.0;
if(f(a,b,mid)<x)
ok=mid;
else
ng=mid;
}
cout<<fixed<<setprecision(10)<<ok/PI*180<<endl;
} | 0 | 61,414,146 |
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>
int main(){
int X, Y, Z, K;
scanf("%d", &X);
scanf("%d", &Y);
scanf("%d", &Z);
scanf("%d", &K);
std::vector<long long > A(X), B(Y), C(Z);
for (int i=0; i<X; i++){
scanf("%lld", &A[i]);
}
for (int i=0; i<Y; i++){
scanf("%lld", &B[i]);
}
for (int i=0; i<Z; i++){
scanf("%lld", &C[i]);
}
std::vector<long long > BC;
for (int i=0; i<Y; i++){
for (int j=0; j<Z; j++){
BC.push_back(B[i]+C[j]);
}
}
std::sort(BC.begin(), BC.end());
std::sort(A.begin(), A.end(), std::greater<int>());
long long min = 1;
long long max = 2e18;
while(max-min>1){
long long mid = (min+max)/2;
int count = 0;
for (int i=0; i<X; i++){
auto itr = std::lower_bound(BC.begin(), BC.end(), mid-A[i]);
count += BC.end()-itr;
}
if (count<K){
max=mid;
} else {
min=mid;
}
}
long long thresh = min - 2;
std::vector<long long > ans;
for (int i=0; i<X; i++){
auto itr = std::lower_bound(BC.begin(), BC.end(), thresh-A[i]);
while(itr!=BC.end()){
ans.push_back(A[i]+(*itr));
itr++;
}
}
std::sort(ans.begin(), ans.end(), std::greater<long long >());
for (int i=0; i<K; i++){
printf("%lld\n", ans[i]);
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(void) {
long n;
cin >> n;
vector<long> a(n);
for(auto &e: a) cin >> e;
sort(a.begin(), a.end());
long m = a[n-1];
if(m == 1) {
cout << (n==2 ? "Possible" : "Impossible") << endl;
return 0;
}
if(m%2 == 0) {
bool ok = true;
for(long i=m/2 + 1; i<=m; i++)
ok &= (upper_bound(a.begin(), a.end(), i) - lower_bound(a.begin(), a.end(), i)) >= 2;
ok &= a[0] == m/2;
ok &= a[1] > m/2;
cout << (ok ? "Possible" : "Impossible") << endl;
} else {
bool ok = true;
for(long i=(m+1)/2; i<=m; i++)
ok &= (upper_bound(a.begin(), a.end(), i) - lower_bound(a.begin(), a.end(), i)) >= 2;
ok &= a[0] == (m+1)/2;
ok &= a[1] == (m+1)/2;
ok &= a[2] > (m+1)/2;
cout << (ok ? "Possible" : "Impossible") << endl;
}
} | 0 | 17,819,776 |
#include <iostream>
using namespace std;
int main(void){
int a,b,c;
cin >> a >> b >> c;
int x;
x = b +c;
if(a < x )
{
int ans;
ans = x - a;
cout << ans << endl;
}
else
cout << "0" << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl
void Suhaib_Sawalha (){
int a , b , c;
cin >> a >> b >> c;
cout << (c >= a && c <= b ? "Yes" : "No");
}
int main(){
In_The_Name_Of_Allah_The_Merciful
#ifndef ONLINE_JUDGE
freopen("SuhaibSawalha1.txt","r",stdin);
#endif
Suhaib_Sawalha();
Alhamdulillah
} | 0 | 55,844,762 |
#include<bits/stdc++.h>
using namespace std;
int n,m;
void test() {
cin >> n;
cin >> m;
int s = 0;
for( int i = 0; i < m; i++) {
int x;
cin >> x;
s += x;
}
cout << ( s >= n ? "Yes" : "No");
}
signed main() {
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif
test();
cout << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N=1e5+3;
int arr[N];
int main(){
std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
long test;
test=1;
while(test--)
{
long long i,j,n,q,e=0,t,o=0,c=0,temp,k,maxpeak=0,peak,d;
string s;
cin>>n;
for(i=0;i<n;i++)
{
cin>>d;
arr[d]++;
}
for(i=0;i<N;i++)
{
if(arr[i]>0)
{
if(arr[i]%2==1)
{
o++;
}
else e++;
}
}
if(e%2==0)cout<<o+e;
else cout<<o+e-1;
}
} | 0 | 2,443,376 |
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}
int main()
{
IO;
string s;
ll ans{};
cin>>s;
while(!s.empty())
{
ans+=(s.back()-'0');
s.pop_back();
}
(!(ans%9))?cout<<"Yes\n":cout<<"No\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define lll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read freopen("READ.txt", "r", stdin)
#define Write freopen("OUTPUT.txt", "w", stdout)
#define INF 9999
#define Co(x) cout<<x<<endl;
#define Cos(x) cout<<x<<" ";
#define SORT(v) sort(v.begin(),v.end())
typedef vector<long long>vii;
typedef pair<long long,long long>Pair;
void solve()
{
int n;
cin>>n;
double arr[n+3],sum=0.0;
for(int i=1;i<=n;i++) cin>>arr[i];
FOR(i,1,n)
{
sum+=(1.0/arr[i]);
}
cout<<fixed<<setprecision(14)<<1.0/sum<<endl;
}
void kick_ass()
{
fast
#ifndef ONLINE_JUDGE
#endif
solve();
}
int main()
{
kick_ass();
} | 0 | 56,759,094 |
#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; cin >> n;
vector<int> p(n);
rep(i,n) cin >> p[i];
int mini = p[0], ans = 0;
rep(i,n) {
if (p[i] <= mini) ans++;
mini = min(mini, p[i]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
int main() {
string s;
cin >> s;
bool exist1=false, exist2=false;
int ans1, ans2;
for (int i=0; i<s.size()-1; i++) {
if (s[i]==s[i+1]) {
ans1=i+1, ans2=i+2;
exist1 = true;
break;
}
}
for (int i=0; i<s.size()-2; i++) {
if (s[i]!=s[i+1]&&s[i+1]!=s[i+2]&&s[i]==s[i+2]) {
ans1=i+1, ans2=i+3;
exist2 = true;
break;
}
}
if (exist1||exist2) cout << ans1 << " " << ans2 << endl;
else cout << -1 << " " << -1 << endl;
} | 0 | 99,748,877 |
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
vector<pair<int,int>> row, col;
set<pair<int,int>> bombs;
int main() {
int r, c, m, a, b; scanf("%d %d %d", &r, &c, &m);
row.resize(r + 1); col.resize(c + 1);
for(int i=0; i<=r; i++) row[i].f = 0, row[i].s = i;
for(int i=0; i<=c; i++) col[i].f = 0, col[i].s = i;
for(int i=0; i<m; i++) {
scanf("%d %d", &a, &b);
row[a].f++; col[b].f++;
bombs.insert({a, b});
}
sort(row.begin(), row.end());
sort(col.begin(), col.end());
int ans = 0;
if(bombs.find({row[r].s, col[c].s}) == bombs.end()) ans = row[r].f + col[c].f;
else if(r == 1) ans = row[1].f;
else if(c == 1) ans = col[1].f;
else {
ans = row[r].f + col[c].f - 1;
int idx = r - 1;
while(bombs.find({row[idx].s, col[c].s}) != bombs.end()) idx--;
ans = max(ans, row[idx].f + col[c].f);
idx = c - 1;
while(bombs.find({row[r].s, col[idx].s}) != bombs.end()) idx--;
ans = max(ans, row[r].f + col[idx].f);
}
printf("%d\n", ans);
return 0;
} | #include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>
#include <bitset>
#include <numeric>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
ll ai[100010], ti[100010];
int main()
{
int n;
cin >> n;
ll t[n], a[n];
for (int i = 0; i < n; i++)
cin >> t[i];
for (int i = 0; i < n; i++)
cin >> a[i];
if (t[n - 1] != a[0])
{
cout << 0 << endl;
return 0;
}
ti[0] = t[0];
for (int i = 0; i < n - 1; i++)
{
if (t[i] == t[i + 1])
{
ti[i + 1] = 0;
}
else
{
ti[i + 1] = t[i + 1];
}
}
ai[n - 1] = a[n - 1];
for (int i = n - 1; i > 0; i--)
{
if (a[i] == a[i - 1])
{
ai[i - 1] = 0;
}
else
{
ai[i - 1] = a[i - 1];
}
}
ll ans = 1;
for (int i = 0; i < n; i++)
{
if (ti[i] == 0 || ai[i] == 0)
{
if ((ti[i] == 0 && ai[i] == 0))
{
ans = (ans * min(t[i], a[i])) % MOD;
}
else
{
if (ti[i] == 0)
ti[i] = ai[i];
else
ai[i] = ti[i];
}
}
else if (ti[i] != ai[i])
{
cout << 0 << endl;
return 0;
}
}
for (int i = 1; i < n; i++)
{
if (ti[i] == 0 && ai[i] == 0)
{
continue;
}
if (ti[i] > t[i] || ai[i] > a[i])
{
cout << 0 << endl;
return 0;
}
}
cout << ans % MOD << endl;
} | 0 | 23,667,411 |
#include<bits/stdc++.h>
#define rep(i, x) for (ll i = 0; i < (x); i++)
#define chmax(x, a) do { x = max(x, a); } while(0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main(void) {
ll N;
cin >> N;
ll V = 0, E = 0;
rep(i, N) {
V += (i + 1) * (N - i);
}
rep(i, N-1) {
ll u, v;
cin >> u >> v;
u--, v--;
if (u > v) swap(u, v);
E += (u + 1) * (N - v);
}
cout << (V - E) << endl;
return 0;
} | #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x) cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void solve() {
ll k; cin >> k;
const int n = 50;
int a = (k + n - 1) / n;
int b = (k % n == 0 ? 0 : n - (k % n));
cout << n << endl;
a += n - 1;
rep(i, b) {
cout << a - n + b - 1 << " ";
}
rep(i, n - b) {
cout << a + b << " ";
}
cout << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
} | 0 | 57,700,185 |
#include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
#include <cctype>
#include<queue>
#include<stack>
#include<cstdio>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
int n;
while(cin>>n){
int ans=0;
int d[999999+100]={};
for(int i=2;i*i<=n;i++){
if(d[i]==0){
for(int j=2;j*i<=n;j++){
d[j*i]++;
}
}
}
d[1]=1;
for(int i=1;i<=n;i++){
if(d[i]==0){
ans++;
}
}
cout<<ans<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[]) {
int n, m;
cin >> n >> m;
vector<vector<int>> d(n, vector<int>(n, -1)), next(n, vector<int>(n, -1)),
indeces(n, vector<int>(n, -1));
for (int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
d[a][b] = c;
d[b][a] = c;
next[a][b] = b;
next[b][a] = a;
indeces[a][b] = i;
indeces[b][a] = i;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
if (d[j][i] < 0 || d[i][k] < 0) {
continue;
}
int new_dist = d[j][i] + d[i][k];
if (d[j][k] < 0 || new_dist < d[j][k]) {
d[j][k] = new_dist;
next[j][k] = next[j][i];
}
}
}
}
vector<bool> used(m, false);
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
int cur = i;
while (cur != j) {
if (indeces[cur][next[cur][j]] != -1) {
used[indeces[cur][next[cur][j]]] = true;
}
cur = next[cur][j];
}
}
}
cout << count(used.begin(), used.end(), false) << '\n';
} | 0 | 84,915,775 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int s,w;
cin >> s >> w;
if(s>w)cout << "safe" << "\n";
else cout << "unsafe" << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
vector<vector<char>> s(H + 2, vector<char>(W + 2, '.'));
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
cin >> s.at(i).at(j);
}
}
bool ok = true;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
if (s.at(i).at(j) == '#') {
if (s.at(i - 1).at(j) == '.' && s.at(i + 1).at(j) == '.' && s.at(i).at(j + 1) == '.' && s.at(i).at(j - 1) == '.') {
ok = false;
break;
}
}
}
if (ok == false) {
break;
}
}
if (ok) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
} | 0 | 58,163,455 |
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
cin >> n;
string s;
vector<int>alp2(26,1e9);
for(int i=0; i<n; i++){
vector<int>alp1(26,0);
cin >> s;
for(int i=0; i<s.size(); i++){
alp1[s[i]-'a']++;
}
for(int i=0; i<26; i++){
alp2[i] = min(alp1[i],alp2[i]);
}
}
for(int i=0; i<26; i++){
if(alp2[i]==1e9) continue;
else{
for(int j=0; j<alp2[i]; j++)
cout << (char)(i+'a');
}
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int T[MAXN],A[MAXN];
int N;
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(T[i]);
for(int i = 1 ; i <= N ; ++i) read(A[i]);
int ans = 1;
for(int i = 1 ; i <= N ; ++i) {
if(T[i] != T[i - 1] || A[i] != A[i + 1]) {
int a = -1,b = -1;
if(T[i] != T[i - 1]) a = T[i];
if(A[i] != A[i + 1]) b = A[i];
if(a != -1 && b != -1) {
if(a != b) {puts("0");return;}
}
if(b > T[i]) {puts("0");return;}
if(a > A[i]) {puts("0");return;}
}
else {
ans = mul(ans,min(A[i],T[i]));
}
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
} | 0 | 72,855,138 |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long int LL;
const LL MAX=2e9;
LL pos[1005][2];
void check(int a,int t){
int i,j,k;
t=1<<t;
if(abs(pos[a][0])>abs(pos[a][1])){
if(pos[a][0]>0){
cout<<'R';
pos[a][0]-=t;
}else{
cout<<'L';
pos[a][0]+=t;
}
}else{
if(pos[a][1]>0){
cout<<'U';
pos[a][1]-=t;
}else{
cout<<'D';
pos[a][1]+=t;
}
}
}
int main(){
int n;
int i,j,k;
LL a,b,c,d;
cin>>n;
for(i=0;i<n;i++){
cin>>pos[i][0]>>pos[i][1];
}
a=(pos[0][0]+pos[0][1]+MAX)%2;
for(i=0;i<n;i++){
b=(pos[i][0]+pos[i][1]+MAX)%2;
if(a!=b){
cout<<-1<<endl;
return 0;
}
}
cout<<(32-a)<<endl;
for(i=30;i>0;i--){
cout<<(1<<i)<<" ";
}
if(a==1)cout<<1<<endl;
else cout<<1<<" "<<1<<endl;
for(i=0;i<n;i++){
for(j=30;j>=0;j--){
check(i,j);
}
if(a==0)check(i,0);
cout<<endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))
const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;
inline int cmp(double x, double y = 0)
{
if(fabs(x - y) < EPS)
return 0;
return x > y ? 1 : -1;
}
ll exp(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
const int maxn = 2e5 + 10;
ll fat[maxn], inv[maxn];
ll C(int n, int k)
{
if(n < k)
return 0;
if(n < 0 || k < 0)
return 0;
return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}
ll p[maxn], q[maxn], r[maxn];
int main()
{
ios::sync_with_stdio(false);
int a,b,c,x,y;
cin >> x >> y >> a >> b >> c;
for(int i = 0; i < a; i++)
{
cin >> p[i];
}
for(int i = 0; i < b; i++)
{
cin >> q[i];
}
for(int i = 0; i < c; i++)
{
cin >> r[i];
}
sort(p, p + a);
sort(q, q + b);
sort(r, r + c, greater<ll>());
ll sumP = 0, sumQ = 0;
for(int i = 0, j = a - 1; i < x; i++, j--)
sumP += p[j];
for(int i = 0, j = b - 1; i < y; i++, j--)
sumQ += q[j];
int pp = a - x, pq = b - y, pr = 0;
ll ans = sumP + sumQ;
while(pr < c)
{
if(pp == a || pq == b)
break;
ll val = 0;
if(-p[pp] > -q[pq])
{
val = sumP - p[pp] + r[pr] + sumQ;
sumP -= p[pp];
sumP += r[pr];
pp++;
}
else
{
val = sumQ - q[pq] + r[pr] + sumP;
sumQ -= q[pq];
sumQ += r[pr];
pq++;
}
if(val > ans)
{
ans = val;
}
else
break;
pr++;
}
ll val = 0;
while(pr < c && pp < a && (sumP - p[pp] + r[pr] + sumQ > ans))
{
val = sumP - p[pp] + r[pr] + sumQ;
sumP -= p[pp];
sumP += r[pr];
pp++;
pr++;
ans = val;
}
while(pr < c && pq < b && (sumQ - q[pq] + r[pr] + sumP > ans))
{
val = sumQ - q[pq] + r[pr] + sumP;
sumQ -= q[pq];
sumQ += r[pr];
pq++;
ans = val;
pr++;
}
cout << ans << endl;
return 0;
} | 0 | 35,751,535 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;
int c[10]={0,2,5,5,4,5,6,3,7,6};
int main(){
int n,m;
cin>>n>>m;
int a[m];
rep(i,0,m) cin>>a[i];
sort(a,a+m);
reverse(a,a+m);
string dp[n+1];
rep(i,0,n+1) dp[i]="x";
dp[0]="o";
rep(i,1,n+1){
rep(j,0,m){
if(i>=c[a[j]] && dp[i-c[a[j]]]!="x"){
if(dp[i].size()<=dp[i-c[a[j]]].size()){
dp[i]=dp[i-c[a[j]]]+char('0'+a[j]);
}
else if(dp[i].size()==dp[i-c[a[j]]].size()+1){
dp[i]=max(dp[i],dp[i-c[a[j]]]+char('0'+a[j]));
}
}
}
}
rep(i,1,dp[n].size()) cout<<dp[n][i];
cout<<endl;
} | #include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
rep(i,n){
cin >> a[i];
a[i]--;
}
int ans = 0;
rep(i,n){
if(i == a[a[i]]) ++ans;
}
ans /= 2;
cout << ans << endl;
return 0;
} | 0 | 3,147,443 |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ALLv(a) (a).begin(),(a).end()
#define ALL(a,n) (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
#define FOR(i,m,n) for(ll (i)=(m); (i)<(n); (i)++)
#define REP(i,n) for(ll (i)=0; (i)<(n); (i)++)
#define REPS(i,x) for(ll (i)=1; (i)<=(x); (i)++)
#define RREP(i,x) for(ll (i)=(x)-1; (i)>=0; (i)--)
#define RREPS(i,x) for(ll (i)=(x); (i)> 0; (i)--)
#define WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define dcml(n) fixed<<setprecision(n)
using namespace std;
struct _RLE{ char c; ll len; };
vector<_RLE> RLE(string S){
ll N=S.size();
vector<_RLE> v;
char prev=S[0];
for(ll i=1,cnt=1;i<=N;i++){
if(i==N){
v.push_back({prev,cnt});
break;
}
while(S[i]==prev){cnt++;i++;}
v.push_back({prev,cnt});
cnt=1;prev=S[i];
}
return v;
}
int main(void){
string S;ll K;cin>>S>>K;
ll c1=0;
vector<_RLE> v=RLE(S);
for(auto r:v){
if(r.len>=2){
c1+=r.len/2;
}
}
ll c2=0;
if(v[v.size()-1].c==v[0].c){
c2+=v[v.size()-1].len/2+v[0].len/2-(v[v.size()-1].len+v[0].len)/2;
}
ll ans=0;
if(v.size()==1)ans=S.size()*K/2;
else{
ans-=c2*(K-1);
ans+=c1*K;
}
cout<<ans<<"\n";
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
using namespace std;
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;
void merge (int *first1, int *last1, int *first2, int *last2){
int size1 = last1 - first1;
int size2 = last2 - first2;
int *result = new int[size1+size2];
int i = 0;
int j = 0;
int index = 0;
while (true){
if (i < size1 && (first1[i] <= first2[j] || j >= size2)){
result[index] = first1[i];
++i; ++index;
}
if (j < size2 && (first1[i] > first2[j] || i >= size1)){
result[index] = first2[j];
++j; ++index;
}
if (i==size1 && j==size2){
for (i=0; i<size1; ++i) first1[i] = result[i];
for (j=0; j<size2; ++j) first2[j] = result[j+size1];
delete[] result;
return;
}
}
}
void MergeSort (int *first, int *last){
int size = last - first;
if(size <= 1) return;
MergeSort(first, first+size/2);
MergeSort(first+size/2, last);
merge(first, first+size/2, first+size/2, last);
}
int gcd(int a, int b)
{
int c;
if (a < b) {
a+=b; b=a-b; a-=b;
}
while (b != 0) {
c = a % b;
a = b;
b = c;
}
return a;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
while(1){
vi v;
cin >> N;
if(N == 0) break;
int av;
REP(i, N){
int temp;
cin >> temp;
v.push_back(temp);
}
sort(v.begin(), v.end());
int sum = 0;
sum = accumulate(v.begin(), v.end(), 0)-v[0]-v[N-1];
av = sum/(v.size()-2);
cout << av << endl;
}
return 0;
} | 0 | 90,057,042 |
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<tuple>
#include<complex>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS (long double) 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
using namespace std;
int main() {
int n, m;
cin>>n>>m;
vector<int> c(m);
REP(i, m) cin>>c[i];
int dp[m + 1][n + 1];
REP(i, n + 1) dp[0][i] = INF;
dp[0][0] = 0;
FOR(i, 1, m + 1) {
REP(j, n + 1) {
if(j == 0) dp[i][j] = 0;
else if(j >= c[i - 1]) dp[i][j] = min(dp[i - 1][j], dp[i][j - c[i - 1]] + 1);
else dp[i][j] = dp[i - 1][j];
}
}
cout<<dp[m][n]<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
int n;
cin>>n;
char s[n][n];
rep(i,n) rep(j,n) cin>>s[i][j];
ll ans=0;
rep(_,n){
int ng=0;
rep(i,n){
rep(j,n){
if(s[i][j]!=s[j][i]) ng++;
}
}
if(ng==0) ans++;
char y[n];
rep(i,n) y[i]=s[0][i];
rep(i,n-1) rep(j,n) s[i][j]=s[i+1][j];
rep(i,n) s[n-1][i]=y[i];
}
cout<<ans*n<<endl;
} | 0 | 84,939,931 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ll N, K, S;
cin >> N >> K >> S;
vector<ll> A(N);
if(S != 1e9){
for(int i = 0; i < N; i++){
A[i] = S + 1;
}
}else{
for(int i = 0; i < N; i++){
A[i] = S - 1;
}
}
for(ll i = 0; i < K; i++){
A[i] = S;
}
for(ll i = 0; i < N; i++){
cout << A[i] << " ";
}
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
string S;
cin >> S;
int N = S.size();
map<char, int> M;
for (int i = 0; i < N;i++)
{
M[S[i]]++;
}
for (int i = 0; i < N;i++)
{
if(M[S[i]] != 2){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | 0 | 71,939,361 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define all(v) v.begin(),v.end()
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }
int n;
int dis[1000005];
deque<P>que;
signed main() {
cin>>n;
rep(i,n)dis[i]=inf;
dis[1]=1;
que.push_back({1,1});
while(!que.empty()){
P p=que.front();que.pop_front();
if(dis[p.second]<p.first)continue;
if(p.second%10!=9){
if(dis[(p.second+1)%n]>p.first+1){
dis[(p.second+1)%n]=p.first+1;
que.push_back({p.first+1,(p.second+1)%n});
}
}
if(dis[(p.second*10)%n]>p.first){
dis[(p.second*10)%n]=p.first;
que.push_front({p.first,(p.second*10)%n});
}
}
cout<<dis[0]<<endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
long long cnt=0;
long long A[N];
long long temp;
for(int i=0;i<N;i++){
cin>>A[i];
}
while(1){
sort(A,A+N);
if(A[N-1]<N){
cout<<cnt<<endl;
return 0;
}
temp=1+(A[N-1]-N)/N;
cnt+=temp;
A[N-1]-=N*temp;
for(int i=0;i<N-1;i++){
A[i]+=temp;
}
}
return 0;
} | 0 | 46,102,757 |
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<string, int> P;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string str;
getline(cin, str);
vector<P> vec;
int m = 0;
string longest;
for(size_t i = 0; i < str.size(); ++i){
if(i == 0 || str[i - 1] == ' '){
int end = 0;
for(size_t j = 0; i + j < str.size(); ++j){
if(i + j == str.size() - 1 || str[i + j + 1] == ' '){
end = j + 1;
break;
}
}
string s = str.substr(i, end);
if(end > m){
m = end;
longest = s;
}
bool check = true;
for(size_t i = 0; i < vec.size(); ++i){
if(vec[i].first == s){
vec[i].second ++;
check = false;
break;
}
}
if(check){
vec.push_back(P(s, 1));
}
}
}
int m2 = 0;
string most;
for(size_t i = 0; i < vec.size(); ++i){
if(vec[i].second > m2){
m2 = vec[i].second;
most = vec[i].first;
}
}
cout << most << " " << longest << endl;
return 0;
} | #include <iostream>
using namespace std;
int main (){
int c , d , a , b;
cin >> c >> d ;
if (c < d){
cout << "a < b" << endl;
}
if(c > d){
cout << "a > b" << endl;
}
if(c == d){
cout << "a == b" << endl;
}
return 0;
} | 0 | 10,481,082 |
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;
void solve(){
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
if(n<1200){
cout << "ABC";
}
else if(1200<=n&&n<2800){
cout << "ARC";
}
else{
cout << "AGC";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n,m;
cin >> n >> m;
int a = 0, w = 0;
vector<pair<int,int>> cnt(n,pair<int,int>(make_pair(0,0)));
for (int i=0; i<m; i++) {
int p;
string s;
cin >> p >> s;
--p;
if (cnt[p].first != 1) {
if (s == "AC") {
cnt[p].first = 1;
} else {
cnt[p].second++;
}
}
}
for (auto& e:cnt) {
if (e.first == 1) {
a++;
w += e.second;
}
}
cout << a << ' ' << w;
return 0;
} | 0 | 77,791,335 |
#include<iostream>
#include<set>
int main(void){
int n, m;
std::cin >> n >> m;
std::multiset<int> as;
for(int i = 0; i < n; i++){
int a;
std::cin >> a;
as.insert(a);
}
for(int i = 0; i < m; i++){
auto max = std::next(as.end(), -1);
int redu = *max / 2;
as.erase(max);
as.insert(redu);
}
long long ans = 0;
for(auto i = as.begin(); i != as.end(); i++){
ans += *i;
}
std::cout << ans << std::endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<ll, ll>
#define debug(var) cerr << "[" << #var << "] " << var << '\n'
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;
const int MAXN = 100005;
ll par[MAXN];
ll child[MAXN];
vector<int> to[MAXN];
ll dist[MAXN];
void dfs(int v, int p=-1) {
for (int e: to[v]) {
if (e==p) continue;
dist[e] = dist[v] + 1;
dfs(e, v);
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<P> d(n);
rep(i, n) {
cin >> d[i].fi;
d[i].se = i;
}
sort(whole(d));
rrep(i, n) {
if (i==0) continue;
ll x = d[i].fi - n+2 + child[i]*2;
if (x==d[i].fi) {
pr(-1);
return 0;
}
auto it = lower_bound(whole(d), P(x, 0));
if (it==d.end() || it->fi!=x) {
pr(-1);
return 0;
}
par[i] = it-d.begin();
child[par[i]] += child[i]+1;
to[i].pb(par[i]);
to[par[i]].pb(i);
}
ll sum = 0;
dfs(0, -1);
rep(i, n) {
sum += dist[i];
}
if (sum!=d[0].fi) {
pr(-1);
return 0;
}
rep(i, n) {
if (i==0) continue;
ll u = d[i].se + 1;
ll v = d[par[i]].se + 1;
cout << u << " " << v << "\n";
}
return 0;
} | 0 | 10,203,299 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T>
void remdup(vector<T>& v) {
sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif
#define MOD 1000000007
void solve(){
int n , k;
cin >> n >> k ;
vi a(n) ; re(a);
sort(all(a));
int ans = 0 ;
rep(i,0,k) ans+=a[i];
cout << ans << endl;
}
signed main() {
unsyncIO();
int tt =1 ;
rep(i,0,tt) solve();
#ifdef np
cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
int n; cin>>n;
vector <int> a(n);
rep(i,n) cin>>a[i];
sort(a.begin(),a.end());
int r=n-2, l=1;
int ans = a[n-1] - a[0];
for(int i=1;i<n-1;i++) ans += abs(a[i]);
cout<<ans<<endl;
int plus=a[n-1], minus = a[0];
vector <int> mi, pl;
rep(i,n-2) if(a[i+1]<=0) mi.push_back(a[i+1]); else pl.push_back(a[i+1]);
rep(i, mi.size()){
cout<<plus<<' '<<mi[i]<<endl;
plus -= mi[i];
}
rep(i,pl.size()){
cout<<minus<<' '<<pl[i]<<endl;
minus -= pl[i];
}
cout<<plus<<' '<<minus<<endl;
} | 0 | 73,891,186 |
#include<bits/stdc++.h>
#define ft(i,l,r) for(register int i=l;i<=r;i++)
#define fd(i,r,l) for(register int i=r;i>=l;i--)
using namespace std;
int n;
int main()
{
cin>>n;
if(n%111==0) cout<<n;
else cout<<n+(111-n%111);
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)
int main()
{
int n; cin >> n;
vector<int> b(n);
rep(i, n - 1) cin >> b[i];
_LL ans = 0;
rep(i, n)
{
if( i == 0 )
{
ans += b[i];
}
else if( i == n - 1)
{
ans += b[i - 1];
}
else
{
ans += min(b[i], b[i - 1]);
}
}
cout << ans << endl;
return 0;
} | 0 | 29,997,478 |
#include <iostream>
int main()
{
int A, B, C, K;
std::cin >> A >> B >> C >> K;
int res;
if (A >= K) res = K;
else if (A + B >= K) res = A;
else res = 2*A + B - K;
std::cout << res << std::endl;
return 0;
} | #pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = LLONG_MAX, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;
vector<int> arr[100001];
Pa info[100001];
string int_tostring(int i){
string in = to_string(i);
string s = "000000";
rep(j, in.size()){
s[6-in.size()+j] = in[j];
}
return s;
}
int main() {
cin >> N >> M;
rep(i, M) {
cin >> A >> B;
info[i] = Pa(A, B);
arr[A].push_back(B);
}
rep(i, N+1) {
sort(arr[i].begin(), arr[i].end());
}
rep(i, M) {
cout << int_tostring(info[i].first);
cout << int_tostring(lower_bound(arr[info[i].first].begin(), arr[info[i].first].end(), info[i].second) - arr[info[i].first].begin() + 1) << endl;
}
} | 0 | 57,673,584 |
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 200007
int a[MAXN];
bool cnt[1000007];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n; cin >> n;
for(int i=0; i<n; i++) {
cin >> a[i];
}
sort(a,a+n);
memset(cnt,0,sizeof cnt);
long long ans=0;
for(int i=0; i<n; i++) {
int now=a[i];
if(cnt[now]==0 && (i+1>=n || a[i]!=a[i+1])) ans++;
if(i==0 || a[i]!=a[i-1])
for(int j=now; j<=1000000; j+=now) {
cnt[j]=1;
}
}
cout << ans << '\n';
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
template<typename T>
T Pow(T a,T b) {
T ret = 1;
for(int i = 0;i < b;i++) {
ret *= a;
}
return ret;
}
ll mod(ll val) {
ll res = val % MOD;
if(res < 0) {
res += MOD;
}
return res;
}
int N;
ll bit[1000010];
void add(int a,ll w) {
while(a <= N) {
bit[a] += w;
a += a & -a;
}
}
ll sum(int a) {
ll ret = 0;
while(a > 0) {
ret += bit[a];
a -= a & -a;
}
return ret;
}
int main() {
cin >> N;
ll D,A;
cin >> D >> A;
vector<P> vec(N);
for(int i = 0;i < N;i++) {
cin >> vec.at(i).first >> vec.at(i).second;
}
sort(vec.begin(),vec.end());
vector<ll> C(N);
for(int i = 0;i < N;i++) {
C.at(i) = vec.at(i).first;
}
for(int i = 0;i < 1000010;i++) {
bit[i] = 0;
}
ll ret = 0;
for(int i = 0;i < N;i++) {
if(vec.at(i).second - sum(i + 1) * A <= 0) {
continue;
}
else {
ll cnt = (vec.at(i).second - sum(i + 1) * A + A - 1) / A;
ret += cnt;
auto itr = upper_bound(C.begin(),C.end(),C.at(i) + 2 * D);
int itr2 = itr - C.begin();
itr2++;
add(i + 1,cnt);
add(itr2,-cnt);
}
}
cout << ret << endl;
} | 0 | 45,215,685 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int H,W;
cin>>H>>W;
vector<vector<char>> a(H,vector<char>(W));
for (int i=0; i<H; i++){
for (int j=0; j<W; j++){
cin>>a.at(i).at(j);
}
}
vector<int> i_remove;
vector<int> j_remove;
for (int i=0; i<H; i++){
bool flag=false;
for (int j=0; j<W; j++){
if (a.at(i).at(j)=='#'){
flag=true;
}
}
if (!flag){
i_remove.push_back(i);
}
}
for (int j=0; j<W; j++){
bool flag=false;
for (int i=0; i<H; i++){
if (a.at(i).at(j)=='#'){
flag=true;
}
}
if (!flag){
j_remove.push_back(j);
}
}
for (int i=0; i<H; i++){
bool flag_i=false;
for (int j=0; j<W; j++){
if ((find(i_remove.begin(),i_remove.end(),i)!=i_remove.end())||(find(j_remove.begin(),j_remove.end(),j)!=j_remove.end())){
} else {
cout<<a.at(i).at(j);
flag_i=true;
}
}
if (flag_i){
cout<<endl;
}
}
} | #include <iostream>
using namespace std;
int main(){
int c;
while(1){
c = 0;
int n,x;
cin >> n >> x;
cin.ignore();
if((n == 0)&&(x == 0)){
break;
}else{
for(int i=1;i<=n;i++){
for (int j=i+1;j<=n;j++){
for(int k=j+1;k<=n;k++){
if(i+j+k == x){
c = c +1;
}
}
}
}
cout << c << endl;
}
}
return 0;
} | 0 | 68,830,943 |
#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
struct point {
int x,y;
}p[maxn];
map<int,int> xcnt,ycnt;
signed main(void){
int n,m,k;
cin>>n>>m>>k;
int x,y,maxr=0,maxc=0;
for(int i=0;i<k;i++){
cin>>x>>y;
p[i]={x,y};
xcnt[x]++,ycnt[y]++;
maxr=max(maxr,xcnt[x]),maxc=max(maxc,ycnt[y]);
}
int num1=0,num2=0;
for(auto tmp:xcnt)
if(tmp.second==maxr)
num1++;
for(auto tmp:ycnt)
if(tmp.second==maxc)
num2++;
int cnt=0;
for(int i=0;i<k;i++){
x=p[i].x,y=p[i].y;
if(xcnt[x]==maxr&&ycnt[y]==maxc)cnt++;
}
if(cnt==num1*num2)
cout<<(maxc+maxr-1)<<endl;
else
cout<<(maxc+maxr)<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
if(b == 0) return a;
else return gcd(b,a%b);
}
ll lcm(ll a, ll b){
ll g = gcd(a, b);
return (a / g) * b;
}
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;
int main() {
ll H,W,ans;
cin >> H >> W;
ans = H*W;
vector<ll> s(3);
for (int h = 1; h <= H-1; ++h) {
s[0] = h*W;
s[1] = (H-h)*(W/2);
s[2] = (H*W-s[0]-s[1]);
sort(s.begin(),s.end());
ans = min(ans,s[2]-s[0]);
s[0] = h*W;
s[1] = (H-h)/2*W;
s[2] = (H*W-s[0]-s[1]);
sort(s.begin(),s.end());
ans = min(ans,s[2]-s[0]);
}
swap(H,W);
for (int h = 1; h <= H-1; ++h) {
s[0] = h*W;
s[1] = (H-h)*(W/2);
s[2] = (H*W-s[0]-s[1]);
sort(s.begin(),s.end());
ans = min(ans,s[2]-s[0]);
s[0] = h*W;
s[1] = (H-h)/2*W;
s[2] = (H*W-s[0]-s[1]);
sort(s.begin(),s.end());
ans = min(ans,s[2]-s[0]);
}
cout << ans << endl;
return 0;
} | 0 | 98,451,866 |
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;
int lst[Max];
int ls[Max];
ll gcd(ll a, ll b)
{
if (b == 0)return a;
else return gcd(b, a % b);
}
int main()
{
int n;
cin >> n;
ll res=1;
for (int i = 1;i <= n;i++)
{
ll t;
scanf("%lld", &t);
res /= gcd(t, res);
res *= t;
}
cout << res;
} | #include "bits/stdc++.h"
using namespace std;
int main() {
long long N, K, H[310], INF = 1000000000000000;
static long long DP[310][310][310] = {};
H[0] = 0;
cin >> N >> K;
for (int i = 1; i <= N; i++) cin >> H[i];
H[N + 1] = 0;
for (int i = 0; i <= N + 1; i++) {
for (int j = 0; j <= N + 1; j++) {
for (int k = 0; k <= N + 1; k++) DP[i][j][k] = INF;
}
}
DP[0][0][0] = 0;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= i; j++) {
for (int k = 0; k <= N; k++) {
if (i != N) {
DP[i + 1][j][k] = min(DP[i + 1][j][k], DP[i][j][k]);
}
DP[i + 1][j + 1][i + 1] = min(DP[i + 1][j + 1][i + 1], DP[i][j][k] + max(0LL, H[k] - H[i + 1]));
}
}
}
cout << DP[N + 1][N + 1 - K][N + 1] << endl;
} | 0 | 8,417,254 |
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 998244353;
template<class _T> static void getval(_T& a) {
std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
std::cin >> a >> b >> c;
}
static void exec();
int main()
{
exec();
fflush(stdout);
return 0;
}
template <class _T> static _T tp_modpow(_T a, _T n, _T mod = (_T)1) {
_T ans = 1;
while (n > 0) {
if (n & 1) {
ans = (ans * a) % mod;
}
a = (a * a) % mod;
n >>= 1;
}
return ans;
}
static void exec()
{
int N;
getval(N);
int d0;
getval(d0);
std::vector<LLONG> count(N, 0);
for (int i = 1; i < N; i++) {
int di;
getval(di);
count[di]++;
}
if (d0 || count[0]) {
printf("0\n");
return;
}
count[0]++;
LLONG ans = 1;
for (int i = 1; i < N; i++) {
LLONG val = tp_modpow(count[i - 1], count[i], MOD_NUM);
ans = (ans * val) % MOD_NUM;
}
printf("%lld\n", ans);
} | #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;
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;
int main() {
IOS;
string s; cin >> s;
int ans = INF;
REP(i,2) {
int tot=0;
REP(j,s.size()) {
if (j%2) {
if (s[j]-'0' == i) {
tot++;
}
} else {
if (s[j]-'0' != i) {
tot++;
}
}
}
chmin(ans,tot);
}
COUT(ans);
return 0;
} | 0 | 5,329,871 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
string s; cin >> s;
if (s[2] == s[3] && s[4] == s[5]) {
puts("Yes");
}
else {
puts("No");
}
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
int main(){FIN
ll n,k;cin>>n>>k;
if (k%2==1){
ll ans = pow(n/k,3);
cout<<ans<<endl;
return 0;
}
ll ans=0;
ans += pow(n/k, 3);
n += k/2;
ans += pow(n/k, 3);
cout<<ans<<endl;
return 0;
} | 0 | 41,154,616 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long int F(long long int A, long long int B) {
long long int C = max(A,B), ans = 0;
while (C/10 > 0) {
ans++;
C /= 10;
}
ans++;
return ans;
}
int main() {
long long int N,ans = 11;
cin >> N;
for (long long int i = 1; i <= sqrt(N); i++) {
if (N%i != 0) {
continue;
}
ans = min(ans, F(i, N/i));
}
cout << ans << endl;
} | #include<iostream>
#include<vector>
using namespace std;
int main(){
string s;
cin>>s;
vector<char>v(s.size());
int index=0;
for(int i=0;i<s.length();i++)
{
if(s[i]!='B'){
v[index]=s[i];
index++;
}
else{
if(index>0)
index--;
}
}
for(int i=0;i<index;i++)
{
cout<<v[i];
}
} | 0 | 88,817,319 |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()
#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second
#define x1 gray_cat_x1
#define y1 gray_cat_y1
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define file "I1"
const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
void solve(){
int a, b, c;
cin >> a >> b >> c;
if (a == b && b == c) {
printf("Yes\n");
} else {
printf("No\n");
}
}
int main(){
int t = 1;
while(t--){
solve();
}
} | #pragma region _head
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#pragma region _define
#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define rep(i,n) for(LL i=0;i<n;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n,option) f(i,0,n)cout<<v[i]<<option;
#define all(a) a.begin(),a.end()
#define size(s) ((int)s.size())
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INT_INF 1<<29
#define LL_INF 1LL<<60
#define MOD 10000007
#pragma endregion
#pragma region _using
using namespace std;
using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<int>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using vpi = vector<pi>;
#pragma endregion
bool is_prime(int n) {
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
return false;
}
}
return true;
}
void y_n(bool p) {
if (p)_y();
else _n();
}
void Y_N(bool p) {
if (p) _Y();
else _N();
}
LL gcd(LL a, LL b) {
LL r;
while ((r = a % b) != 0) {
a = b;
b = r;
}
return b;
}
LL lcm(LL a, LL b) {
return (a / gcd(a, b)*b);
}
LL factorial(LL n) {
LL a = 1, ret = 1;
while (a < n) {
a++;
ret *= a;
}
return ret;
}
#pragma endregion
signed main(void) {
cin.tie(0); ios::sync_with_stdio(false);
while (1) {
int n, a, b, c, x;
cin >> n >> a >> b >> c >> x;
if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0) {
break;
}
vi y(n);
f_vI(y, n);
int ans = 0;
int i = 0;
while (ans < 10001) {
if (y[i] == x) {
i++;
}
if (i >= n)break;
x = ((a*x + b) % c);
ans++;
}
if (ans > 10000) {
cout << -1;
}
else {
cout << ans;
}
cout << endl;
}
return 0;
} | 0 | 58,379,879 |
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(20) << fixed;
/*
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
string S, T;
cin >> S >> T;
if(T.substr(0, S.size()) == S){
cout << "Yes"<<endl;
}
else {
cout << "No" <<endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template <typename A, typename B>
inline void chmin(A& a, B b) {
if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A& a, B b) {
if (a < b) a = b;
}
template <class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
ost << "{" << p.first << "," << p.second << "}";
return ost;
}
template <class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
ost << "{";
for (int i = 0; i < v.size(); i++) {
if (i) ost << ",";
ost << v[i];
}
ost << "}";
return ost;
}
inline int topbit(unsigned long long x) {
return x ? 63 - __builtin_clzll(x) : -1;
}
inline int popcount(unsigned long long x) {
return __builtin_popcountll(x);
}
inline int parity(unsigned long long x) {
return __builtin_parity(x);
}
signed main() {
string S;
cin >> S;
int sum = 0;
for (auto c : S) sum += c - '0';
if (sum % 9)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
} | 0 | 54,486,863 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using mp = map<char,int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll k, a, b;
cin >> k >> a >> b;
if(b - a <= 2){
cout << k + 1 << endl;
}else{
ll ans = (k - (a - 1)) / 2 * (b - a) + a;
if((k - (a - 1)) % 2 == 1){
ans++;
}
cout << ans << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int h,w;
for (;;) {
scanf("%d %d",&h,&w);
if (h==0) break;
for (int i=0;i<w;i++) printf("#");
printf("\n");
for (int j=0;j<h-2;j++) {
for (int i=0;i<w;i++) {
printf("%c",(i==0 || i==w-1)?'#':'.');
}
printf("\n");
}
for (int i=0;i<w;i++) printf("#");
printf("\n\n");
}
return 0;
} | 0 | 30,778,434 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> G;
vector<vector<int>> W;
vector<int> dist;
vector<bool> visited;
void dfs(int u) {
visited[u] = true;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (visited[v]) continue;
dist[v] = dist[u] + W[u][i];
dfs(v);
}
}
int main() {
int N, M;
cin >> N >> M;
vector<int> L(M), R(M), D(M);
G.resize(N); W.resize(N);
for (int i = 0; i < M; i++) {
int l, r, d;
cin >> l >> r >> d;
l--; r--;
L[i] = l; R[i] = r; D[i] = d;
G[l].push_back(r); W[l].push_back(d);
G[r].push_back(l); W[r].push_back(-d);
}
dist.resize(N);
visited.resize(N, false);
for (int i = 0; i < N; i++) {
if (!visited[i]) {
dfs(i);
}
}
for (int i = 0; i < M; i++) {
if (D[i] != dist[R[i]] - dist[L[i]]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | #include <iostream>
#include <algorithm>
using namespace std;
const int N_MAX=1000;
typedef long long int LLI;
int main() {
int N;
LLI x[N_MAX];
LLI y[N_MAX];
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> x[i] >> y[i];
}
bool impossible = false;
bool odd;
for (int i = 0; i < N; ++i) {
if (!i) {
odd = abs(x[i] + y[i]) % 2;
} else if (odd != abs(x[i] + y[i]) % 2) {
impossible = true;
}
}
if (impossible) {
cout << -1 << endl;
return 0;
}
LLI k = 0;
for (int i = 0; i < N; ++i) {
if (!odd) {
--x[i];
}
k = max(k, abs(x[i] + y[i]));
k = max(k, abs(x[i] - y[i]));
}
int m = 0;
LLI mm = 1;
while (mm <= k) {
m += 1;
mm <<= 1;
}
if (!odd) {
cout << m + 1 << endl;
cout << 1 << " ";
} else {
cout << m << endl;
}
LLI p = 1;
for (int i = 0; i < m; ++i) {
if (!i) {
cout << p;
} else {
cout << " " << p;
}
p <<= 1;
}
cout << endl;
for (int i = 0; i < N; ++i) {
if (!odd) {
cout << "R";
}
LLI u = x[i] + y[i];
LLI v = x[i] - y[i];
LLI a = ((1 << m) - 1 - u) / 2;
LLI b = ((1 << m) - 1 - v) / 2;
for (int i = 0; i < m; ++i) {
char d;
if (a & 1) {
if (b & 1) {
d = 'L';
} else {
d = 'D';
}
} else {
if (b & 1) {
d = 'U';
} else {
d = 'R';
}
}
a >>= 1;
b >>= 1;
cout << d;
}
cout << endl;
}
return 0;
} | 0 | 93,147,887 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int K,l;
string S;
cin >> K >> S;
l = S.size();
if(l<=K)cout << S << endl;
else {
S = S.erase(K) + "...";
cout << S << endl;
}
} | #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
map <string,int> ans;
int l=0;
int k=0;
int main(){
string str;
string a,b;
while(cin>>str){
if(str.size()>=l){
b = str;
l=str.size();
}
ans[str]++;
if(ans[str]>=k){
k=ans[str];
a=str;
}
}
cout<<a<<" "<<b<<endl;
} | 0 | 83,861,074 |