code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 32
101M
|
---|---|---|---|
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
int main(){
int n; cin >> n;
vector<ll> a(n),b(n);
ll mi=1e9;
ll sum=0;
for(int i=0;i<n;i++){
cin >> a[i] >> b[i];
if(a[i]>b[i])mi=min(mi,b[i]);
sum+=a[i];
}
if(a==b){
cout << 0 << endl;
}
else{
cout << sum-mi << endl;
}
return 0;
} | #define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>
using namespace std;
#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int A, B;
int ans = INF;
int sum = 0;
rep(i, 0, N)
{
cin >> A >> B;
sum += A;
if (A > B)chmin(ans, B);
}
if (ans == INF)cout << 0 << endl;
else cout << sum - ans << endl;
return 0;
} | 1 | 99,896,999 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double PI=acos(-1.0);
ll N,A,B;
void input()
{
cin>>N>>A>>B;
}
void solve()
{
ll ans=(N/(A+B))*A+min(A,N%(A+B));
cout<<ans<<endl;
}
int main()
{
cin.tie();
ios::sync_with_stdio(false);
input();
solve();
return 0;
} | #include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
using namespace std;
typedef vector<int> vi;
int main(){
long long N, A, B, ans = 0, tmp;
cin >> N >> A >> B;
tmp = A + B;
ans += A * (N / tmp);
ans += min(A, N % (A + B));
cout << ans << endl;
return 0;
} | 1 | 64,629,236 |
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
while(cin >> n , n){
int cou = 0;
string str[101];
for(int i=0;i<n;i++){
cin >> str[i];
if(i % 2 == 1){
if(str[i][1] == 'u' && str[i-1][1] == 'u') cou++;
else if(str[i][1] == 'd' && str[i-1][1] == 'd') cou++;
}
}
cout << cou << endl;
}
} | #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#define ll long long int
using namespace std;
typedef pair<int, int> P;
int main()
{
ll n;
char foot[100][2]={};
int i;
while(1){
cin>>n;
if(n==0)break;
int sum=0;
for(i=0;i<n;i++)
cin>>foot[i][0]>>foot[i][1];
for(i=1;i<n;i++){
if(foot[i-1][1]==foot[i][1]){
sum++;
i++;
}
}
cout<<sum<<endl;
}
} | 1 | 7,307,752 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if(a%500>b)
cout << "No" << endl;
else
cout << "Yes" << endl;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int y,z;
cin>>y>>z;
if(y%500<=z) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | 1 | 1,059,697 |
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
ll Max = 10 + 1e8;
int main()
{
int n, k;
cin >> n >> k;
vector<ll> h(n);
rep(i, n) cin >> h[i];
sort(h.begin(), h.end(),greater<ll>());
ll sum = 0;
for (int i = k;i < n;i++) {
sum += h[i];
}
cout << sum;
} | #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int N, K;
cin >> N >> K;
vector<int> H(N);
rep(i,N) cin >> H[i];
sort(H.rbegin(), H.rend());
ll res = 0;
for (int i = K; i < N; i++) {
res += H[i];
}
cout << res << endl;
return 0;
} | 1 | 76,784,314 |
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
using ll = long long;
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
const int INF=1e9;
const ll LINF=1e18;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
int main(){
int n;
cin>>n;
vi a(n+1);
rep(i,n+1)cin>>a[i];
vl b(n+1);
rep(i,n+1){
if(i==0){
b[i]=1-a[i];
}
else{
b[i]=2*b[i-1]-a[i];
chmin(b[i],LINF);
}
if(b[i]<0){
cout<<-1<<endl;
return 0;
}
}
vl d(n+1);
d[n]=a[n];
for(int i=n-1;i>=0;i--){
d[i]=min(b[i]+a[i],d[i+1]+a[i]);
}
ll ans=0;
rep(i,n+1)ans+=d[i];
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;
int n;
ll ans = 1, nodes;
ll l[N], r[N];
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin >> n;
vector<ll> a(n + 1);
for (auto& i : a) cin >> i;
for (int i = n; i > 0; --i) {
if (i == n) {
l[i] = r[i] = a[i];
} else {
l[i] = ceil((long double)l[i + 1] / 2), r[i] = r[i + 1];
l[i] += a[i], r[i] += a[i];
}
}
if (a[0] > 1) {
cout << -1;
return 0;
}
nodes = !a[0];
for (int i = 1; i <= n; ++i) {
if (nodes * 2 < l[i]) {
cout << -1;
return 0;
}
nodes = min(nodes * 2, r[i]);
ans += nodes;
nodes -= a[i];
}
cout << ans;
} | 1 | 64,969,189 |
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
using namespace std;
#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
string smap[110];
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int A, B;
int H = 100, W = 100;
cin >> A >> B;
rep(i, 0, H)rep(j, 0, W)
{
if (i < H / 2)
{
smap[i] += '#';
}
else
{
smap[i] += '.';
}
}
rep(i, 1, A)
{
int y = 2 * (i / (W/2));
int x = (i % (W / 2)) * 2;
smap[y][x] = '.';
}
rep(i, 1, B)
{
int y = H - 1 - 2 * (i / (W / 2));
int x = (i % (W / 2)) * 2;
smap[y][x] = '#';
}
cout << H << " " << W << endl;
rep(i, 0, H)
{
cout << smap[i] << endl;
}
return 0;
} | #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdexcept>
using namespace std;
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#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 all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int x) {
for (int i = 2; i*i <= x; i++) {
if (x%i == 0)return false;
}
return x > 1;
}
int gcd(int x, int y) {
if (y == 0)return x;
return gcd(y, x%y);
}
int lcm(int x, int y) {
return x * y / gcd(x, y);
}
int kai(int x) {
if (x == 0)return 1;
return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
int res = 1;
while (y > 0) {
if (y & 1) {
res = res * x%mod;
}
x = x * x%mod;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
int a, b;
char c[114][114];
signed main() {
cout << 100 << " " << 100 << endl;
cin >> a >> b;
rep(i, 100)rep(j, 100) {
if (i < 50)c[i][j] = '.';
else c[i][j] = '#';
}
a--; b--;
rep(i, a) {
c[51 + i / 50 * 2][i % 50 * 2] = '.';
}
rep(i, b) {
c[i / 50 * 2][i % 50 * 2] = '#';
}
rep(i, 100) {
rep(j, 100) {
cout << c[i][j];
}
cout << endl;
}
} | 1 | 11,049,140 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, b, c, d; cin >> a >> b >> c >> d;
string res = "No";
if(abs(a-c) <= d) res = "Yes";
if(abs(a-b) <= d && abs(b-c) <= d) res = "Yes";
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define rreps(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
signed main(){
int a, b, c, d;
cin >> a >> b >> c >> d;
bool can = abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d);
cout << (can ? "Yes" : "No") << endl;
} | 1 | 29,558,300 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(25);
ll n;
string s;
cin >> n >> s;
if (s[0] != 'B' || s[2 * n - 1] != 'B') {
cout << 0 << '\n';
return 0;
}
vector<ll> cnt(2, 0), a(2 * n, 0);
cnt[1] = 1, a[0] = 1;
FOR(i, 1, 2 * n) {
if (s[i - 1] != s[i]) a[i] = a[i - 1];
else a[i] = a[i - 1] ^ 1;
cnt[a[i]]++;
}
if (cnt[0] != cnt[1]) {
cout << 0 << '\n';
return 0;
}
ll ans = 1, res = 0;
rep(i, 2 * n) {
if (a[i]) res += a[i];
else {
ans = ans * res % mod;
res--;
}
}
FOR(i, 1, n + 1) ans = ans * i % mod;
cout << ans << '\n';
return 0;
} | #include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 100005
const int mod=1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int n,m;
char s[maxn<<1];
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*f;
}
int main(){
n=read(); scanf("%s",s+1);
int cnt=0; int res=1;
for (int i=1;i<=(n<<1);i++){
if (s[i]=='B'){if (cnt&1) res=1ll*res*cnt%mod,--cnt; else ++cnt;}
else if (s[i]=='W'){if (cnt&1) ++cnt; else res=1ll*res*cnt%mod,--cnt;}
if (cnt<0){puts("0"); return 0;}
}
if (cnt){puts("0"); return 0;}
for (int i=1;i<=n;i++) res=1ll*res*i%mod;
printf("%d\n",res);
return 0;
} | 1 | 27,473,924 |
#include <bits/stdc++.h>
using namespace std;
long dp[100001][2];
vector<int> tree[100001];
void solve(int n, int p) {
if(dp[n][0] > -1) return;
if(tree[n].size() == 1 && tree[n][0] == p) {
dp[n][0] = dp[n][1] = 1;
return;
}
long r = 1, b = 1;
for(auto i : tree[n]) {
if(i == p) continue;
solve(i, n);
b = (b * dp[i][1]) % 1000000007;
r = (r * (dp[i][0] + dp[i][1])) % 1000000007;
}
dp[n][0] = b;
dp[n][1] = r;
return;
}
int main() {
int n, i, x, y;
cin >> n;
for(i = 1; i <= n; ++i) dp[i][0] = dp[i][1] = -1;
for(i = 1; i < n; ++i) {
cin >> x >> y;
tree[x].push_back(y);
tree[y].push_back(x);
}
solve(1, 0);
cout << (dp[1][0] + dp[1][1]) % 1000000007;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int big = 2999999999999999999;
const long long int small = -2999999999999999999;
#define ll long long int
#define pb(a) push_back(a)
#define vll vector<long long int>
#define loop(i, n) for(long long int i=1;i<=n;i++)
#define loop0(i, n) for(long long int i=0;i<n;i++)
#define in(i) scanf("%lld", &i);
#define out(i) printf("%lld", i)
ll n;
vll adjacencyList[100001];
ll dp[100001][2];
void in2(ll& a, ll& b)
{
in(a);
in(b);
}
void in3(ll& a, ll& b, ll& c)
{
in(a);
in(b);
in(c);
}
ll solve(ll p, ll node, int color)
{
if(node>n)
return 0;
if(dp[node][color]!=-1)
return dp[node][color];
ll ans=1;
if(color)
{
for(ll elem:adjacencyList[node])
{
if(elem!=p)
ans=(ans%mod*(solve(node, elem, 1)+solve(node, elem, 0))%mod)%mod;
}
}
else
{
for(ll elem: adjacencyList[node])
{
if(elem!=p)
ans=(ans%mod*solve(node, elem, 1)%mod)%mod;
}
}
return dp[node][color]=ans%mod;
}
int main()
{
memset(dp, -1, sizeof(dp));
in(n);
ll u, v;
loop(i, n-1)
{
in2(u, v);
adjacencyList[u].pb(v);
adjacencyList[v].pb(u);
}
ll ans = (solve(0, 1, 0)%mod + solve(0, 1, 1)%mod)%mod;
cout<<ans<<"\n";
} | 1 | 19,950,012 |
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
int a[33] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main() {
int k;
cin >> k;
cout << a[k] << endl;
} | #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;
signed main(void){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
vl A={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
ll N;
cin >> N;
prt(A[N-1]);
return 0;
} | 1 | 15,118,727 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;
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 mod(ll &val, ll M) {
val = val % M;
if(val < 0) {
val += M;
}
}
template<typename T>
T RS(T N, T P, T M){
if(P == 0) {
return 1;
}
if(P < 0) {
return 0;
}
if(P % 2 == 0){
ll t = RS(N, P/2, M);
if(M == -1) return t * t;
return t * t % M;
}
if(M == -1) {
return N * RS(N,P - 1,M);
}
return N * RS(N, P-1, M) % M;
}
int main() {
int H,W;
ll M;
cin >> H >> W >> M;
vector<P> h(H);
vector<P> w(W);
for(int i = 0;i < H;i++) {
h.at(i).second = i;
}
for(int i = 0;i < W;i++) {
w.at(i).second = i;
}
map<P,int> ma;
for(int i = 0;i < M;i++) {
int A,B;
cin >> A >> B;
A--;
B--;
h.at(A).first++;
w.at(B).first++;
ma[P(A,B)]++;
}
sort(h.begin(),h.end());
reverse(h.begin(),h.end());
sort(w.begin(),w.end());
reverse(w.begin(),w.end());
int hmax = h.at(0).first;
int wmax = w.at(0).first;
vector<int> hcnt;
vector<int> wcnt;
for(int i = 0;i < H;i++) {
if(h.at(i).first == hmax) {
hcnt.push_back(h.at(i).second);
}
}
for(int i = 0;i < W;i++) {
if(w.at(i).first == wmax) {
wcnt.push_back(w.at(i).second);
}
}
ll hsum = hcnt.size();
ll wsum = wcnt.size();
if(hsum * wsum >= M + 1) {
cout << hmax + wmax << endl;
}
else {
bool ret = false;
for(int i = 0;i < hsum;i++) {
for(int j = 0;j < wsum;j++) {
if(!ma.count(P(hcnt.at(i),wcnt.at(j)))) {
ret = true;
}
}
}
if(ret == true) {
cout << hmax + wmax << endl;
}
else {
cout << hmax + wmax - 1 << endl;
}
}
} | #include <bits/stdc++.h>
#define pvar(x) clog << "[" << #x << ":" << x << "]\n"
using namespace std;
using ll = long long int;
void solve() {
int h, w, m, h1, w1;
cin >> h >> w >> m;
int mr = 0, mc = 0;
map<int, int> r, c;
set<pair<int, int>> s;
for (int i = 0; i < m; i++) {
cin >> h1 >> w1;
r[h1]++, c[w1]++;
mr = max(mr,r[h1]);
mc = max(mc,c[w1]);
s.insert({h1, w1});
}
set<int> row,col;
for (auto i : r) {
if (mr == i.second) {
row.insert(i.first);
}
}
for (auto i : c) {
if (mc == i.second) {
col.insert(i.first);
}
}
for(auto i : row){
for(auto j : col){
if(s.find({i,j}) == s.end()){
cout<<mr+mc<<endl;
return;
}
}
}
cout<<mr+mc-1<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
t = 1;
while (t--) {
solve();
}
} | 1 | 77,097,613 |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
int n; cin >> n;
vector<ll> A(n), S(n+1);
map<ll, int> mp; mp[0]++;
rep(i, n){
cin >> A[i];
S[i+1] = S[i] + A[i];
mp[S[i+1]]++;
}
ll res = 0;
for(auto m: mp){
ll val = m.second;
res += val * (val-1) / 2;
}
cout << res << ln;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> b(n+1);
b[0] = 0;
for (int i = 1; i < n+1; i++) {
b[i] = b[i-1]+a[i-1];
}
map<long long, long long> nums;
for (int i = 0; i < n+1; i++) {
nums[b[i]]++;
}
long long res = 0;
for (auto it : nums) {
long long num = it.second;
res += num * (num - 1) / 2;
}
cout << res << endl;
} | 1 | 30,710,483 |
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int m, nmin, nmax;
while (cin >> m, cin >> nmin, cin >> nmax, m && nmin && nmax) {
vector<int> p(m);
for (int i = 0; i < m; i++) {
cin >> p[i];
}
int ans = 0;
int diffmax = 0;
for (int i = nmin - 1; i <= nmax - 1; i++) {
if (diffmax <= p[i] - p[i + 1]) {
diffmax = p[i] - p[i + 1];
ans = i+1;
}
}
cout << ans << endl;
}
return 0;
} | #include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
int m, nmin, nmax, submax, ans;
vi P;
while (cin >> m >> nmin >> nmax) {
if (m == 0) break;
submax = 0;
ans = nmin;
P.resize(m);
for (int i = 0; i < m; i++) cin >> P[i];
for (int n = nmin; n <= nmax; n++) {
if (P[n-1] - P[n] >= submax) {
submax = P[n-1] - P[n];
ans = n;
}
}
cout << ans << endl;
}
return 0;
} | 1 | 25,188,037 |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define br printf("\n")
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int s, w;
cin >> s >> w;
if (w >= s) {
cout << "unsafe\n";
} else {
cout << "safe\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int S, W;
cin >> S >> W;
if (S <= W) {
puts("unsafe");
} else {
puts("safe");
}
} | 1 | 27,117,200 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
string s;
cin>>s;
int ans=0;
rep(i,10)rep(j,10)rep(k,10){
int z=0;
rep(a,n){
if(z==0&&s[a]-'0'==i) z=1;
else if(z==1&&s[a]-'0'==j) z=2;
else if(z==2&&s[a]-'0'==k) z=3;
}
if(z==3) ans++;
}
cout<<ans;
} | #include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
using namespace std;
const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);
string str;
vll numbers;
class BitComb {
private:
ll _digits;
ll _base;
ll _data[512];
ll _finished;
ll _i;
public:
BitComb(ll digits, ll base) {
_digits = digits;
_base = base;
_finished = false;
_i = 0;
fill_n(_data, 512, 0);
}
void next() {
if (_finished) {
return;
}
for (ll i = 0; i < _digits; i++) {
if (_data[i] + 1 < _base) {
_data[i] += 1;
break;
} else {
_data[i] = 0;
if (i == _digits - 1) {
_finished = true;
break;
}
}
}
}
ll data(ll index) { return _data[index]; }
void print() {
for (ll i = _digits - 1; i >= 0; i--) {
cout << _data[i];
}
cout << endl;
}
bool finished() { return _finished; }
};
ll N;
bool ok(ll v0, ll v1, ll v2) {
ll index = 0;
for (ll i = 0; i < N; i++) {
ll v;
if (index == 0) v = v0;
if (index == 1) v = v1;
if (index == 2) v = v2;
if (numbers[i] == v) {
index++;
if (index >= 3) {
return true;
}
}
}
return false;
}
int main() {
scanf("%lld", &N);
cin >> str;
for (ll i = 0; i < N; i++) {
numbers.emplace_back(str[i] - '0');
}
ll ans = 0;
auto bc = BitComb(3, 10);
while (!bc.finished()) {
if (ok(bc.data(0), bc.data(1), bc.data(2))) {
ans++;
}
bc.next();
}
cout << ans << endl;
} | 1 | 57,266,096 |
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> iPair;
#define pb push_back
typedef long long ll;
typedef long double ld;
#define FOR(i,n) for(i=0;i<n;i++)
#define FORE(i,n) for(i=0;i<=n;i++)
ll gcd(ll a , ll b)
{
if(b==0) return a;
a%=b;
return gcd(b,a);
}
ll maxl(ll a,ll b){
if(a>b)return a;
return b;
}
ll minl(ll a,ll b){
if(a>b)return b;
return a;
}
ll mod = 998244353;
ll mulmod(ll a, ll b,ll c){
ll res = 0;
a = a % c;
while (b > 0){
if (b % 2 == 1){
res = (res + a) % c;
}
a = (a * 2) % c;
b /= 2;
}
return res % c;
}
int binarySearch(int arr[], int l, int r, int x)
{
if (r >= l) {
int mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x);
}
return -1;
}
int a[100005];
int tree[200005];
void build(int st,int low,int high){
if(low==high){
tree[st] = a[high]%2;
return;
}
int mid = low+(high-low)/2;
build(2*st,low,mid);
build(2*st+1,mid+1,high);
tree[st] = tree[2*st]+tree[2*st+1];
}
void update(int st,int start,int end,int ind,int val){
if(start==end){
tree[st] = val%2;
return;
}
int mid = start+(end-start)/2;
if(ind<=mid){
update(2*st,start,mid,ind,val);
}
else update(2*st+1,mid+1,end,ind,val);
tree[st] = tree[2*st]+tree[2*st+1];
}
int query(int st,int start,int end,int low,int high){
if(start>high || end<low)return 0;
int mid = start + (end-start)/2;
if(start==low && end==high){
return tree[st];
}
if(low>mid)return query(2*st+1,mid+1,end,low,high);
if(high<=mid)return query(2*st,start,mid,low,high);
return query(2*st,start,mid,low,mid)+query(2*st+1,mid+1,end,mid+1,high);
}
int main()
{
ios_base::sync_with_stdio(false);
ll n,k;
cin >> n >> k;
map<ll, vector<ll> > m;
ll ans = 0;
priority_queue< pair<ll,ll> > pq1;
priority_queue< pair<ll,ll> > pq2;
vector<pair<ll,ll> > ord;
map<ll,ll> count;
vector<ll> ind(n+1,0);
for(int i=0;i<n;i++){
ll t,d;
cin >> t >> d;
m[t].pb(d);
}
for(auto it = m.begin();it!=m.end();++it){
sort(it->second.begin(),it->second.end());
reverse(it->second.begin(),it->second.end());
pq1.push({it->second[0],it->first});
ord.pb({it->second[0],it->first});
count[it->first] = 0;
}
sort(ord.begin(),ord.end());
ll done = 0;
ll diff = 0;
while(done<k && !pq1.empty()){
done++;
diff++;
ll t = pq1.top().second;
ll d = pq1.top().first;
pq1.pop();
ans+=d;
ind[t]++;
if(ind[t]<m[t].size())pq2.push({m[t][ind[t]],t});
count[t] = 1;
}
while(done<k){
done++;
ll t = pq2.top().second;
ll d = pq2.top().first;
ans+=d;
pq2.pop();
ind[t]++;
if(ind[t]<m[t].size())pq2.push({m[t][ind[t]],t});
count[t]++;
}
ans+=diff*diff;
for(int i=0;i<ord.size();i++){
if(count[ord[i].second]>1)continue;
else if(count[ord[i].second]==0)continue;
if(pq2.empty())break;
ll t = pq2.top().second;
ll d = pq2.top().first;
ll t1 = ord[i].second;
if(d>=m[t1][0]+2*diff-1){
ans+=d-m[t1][0]-2*diff+1;
pq2.pop();
ind[t]++;
if(ind[t]<m[t].size())pq2.push({m[t][ind[t]],t});
count[t]++;
diff--;
}
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double>> any;
template<typename T> inline void pr(const vector<T> &xs){
for(int i=0; i<xs.size()-1; i++) cout << xs[i] << " ";
cout << xs[xs.size()-1] << endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
pr(xs);
#endif
}
int main(){
int N, K;
cin >> N >> K;
vector<pair<ll, int>> dt(N);
for(int i=0; i<N; i++) cin >> dt[i].second >> dt[i].first;
sort(dt.begin(), dt.end(), greater<>());
ll sum = 0;
ll kind = 0;
vector<bool> used(N+1);
vector<ll> removable;
for(int i=0; i<K; i++){
int t = dt[i].second;
sum += dt[i].first;
if(!used[t]){
kind++;
used[t] = true;
} else {
removable.push_back(dt[i].first);
}
}
reverse(removable.begin(), removable.end());
ll ans = sum + kind*kind;
int k=0;
for(int i=K; i<N; i++){
if(k>=removable.size()) break;
int t = dt[i].second;
if(used[t]) continue;
used[t] = true;
sum += dt[i].first - removable[k];
k++; kind++;
ans = max(ans, sum+kind*kind);
}
cout << ans << endl;
return 0;
} | 1 | 544,311 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
string x = "No";
cin >> a >> b >> c;
if(a < b && b < c){
x = "Yes";
}
cout << x << endl;
return 0;
} | #include<iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a;
cin >> b;
cin >> c;
if ((a < b && a < c) && (b < c)) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
} | 1 | 14,681,320 |
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }
ll n, m;
int main() {
cin >> n >> m;
vector<ll> A(n, 0);
for(int i = 0; i < n; ++i) {
cin >> A.at(i);
}
vector<ll> sumA(n+1, 0);
for(int i = 0; i < n; ++i) {
sumA.at(i+1) += sumA.at(i) + A.at(i);
}
map<ll, ll> cnt;
for(int i = 0; i <= n; ++i) {
ll ch = sumA.at(i) % m;
cnt[ch]++;
}
ll ans = 0;
for(auto mp : cnt) {
ll cc = mp.second;
ans += cc*(cc-1)/2;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long N,M;
cin>>N>>M;
vector<long> a(N);
for(int i=0;i<N;i++){
cin>>a[i];
a[i]%=M;
}
long ans=0;
vector<long> r(N);
r[0]=a[0];
if(r[0]==0) ans++;
for(int i=1;i<N;i++){
r[i]=r[i-1]+a[i];
r[i]%=M;
if(r[i]==0) ans++;
}
map<long,long> modm;
for(int i=0;i<N;i++){
modm[r[i]]++;
}
for (auto& x:modm) {
long n=x.second;
ans+=n*(n-1)/2;
}
cout<<ans<<endl;
} | 1 | 92,886,941 |
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
int res[Maxk];
memset(res,0,sizeof(res));
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
for (int i=0;i<a.length();i++){
for (int j=0;j<b.length();j++){
res[i+j]+=(a[i]-'0')*(b[j]-'0');
}
}
for (int i=0;i<Maxk;i++){
if (res[i]>=10) {
res[i+1]+=(res[i]/10);
res[i]%=10;
}
}
string ret;
bool flag=false;
for (int i=Maxk-1;i>=0;i--){
if (flag || res[i]){
flag=true;
ret=ret+(char)(res[i]+'0');
}
}
if (ret=="") ret="0";
return ret;
}
string add(string a,string b){
if (a.length()<b.length()) swap(a,b);
while (a.length()!=b.length()){
b='0'+b;
}
for (int i=a.length()-1;i>=0;i--){
a[i]+=(b[i]-'0');
if (a[i]>'9' && i){
a[i]-=10;
a[i-1]++;
}
}
if (a[0]>'9'){
a[0]-=10;
a='1'+a;
}
return a;
}
inline int read()
{
int x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
const int Maxn=200005;
const int Maxm=70000000;
map<int,vector<int> > v;
int sum[Maxn];
char c[Maxn];
int dp[Maxn];
int Mn
[Maxm];
int gs(int pos){
if (pos==-1) return 0;
return sum[pos];
}
int main(){
scanf("%s",c);
int n=strlen(c);
int full=0;
for (int i=0;i<26;i++) full|=(1<<i);
v[0].pb(-1);
for (int i=0;i<n;i++){
if (i) sum[i]=sum[i-1];
sum[i]^=(1<<(c[i]-'a'));
v[sum[i]].pb(i);
}
for (int i=0;i<Maxm;i++) Mn[i]=1e9;
dp[0]=0;
Mn[0]=0;
for (int i=1;i<=n;i++){
dp[i]=1e9;
int nv=gs(i-1);
for (int j=0;j<27;j++){
int wv=nv^(1<<j);
if (j==26) wv=nv;
if (v.count(wv)){
dp[i]=min(dp[i],Mn[wv]+1);
}
}
Mn[nv]=min(Mn[nv],dp[i]);
}
printf("%d\n",dp[n]);
return 0;
} | #include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a, long long b,long long m) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a %m;
a = a * a %m;
b >>= 1;
}
return res;
}
unordered_map<int,int>mm;
int temp=0;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if(fopen("INPUT.txt","r"))
{
freopen ("INPUT.txt" , "r" , stdin);
freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
string a;
cin>>a;
int n=a.length();
for(int i=0;i<n;i++)
{
temp^=(1<<(a[i]-'a'));
for(int j=0;j<26;j++)
{
int z=(temp^(1<<j));
if(z==0)
mm[temp]=1;
else if(temp==0)
mm[temp]=1;
else if(mm[temp]!=0 && mm[z]!=0)
mm[temp]=min(mm[temp],mm[z]+1);
else if(mm[temp]==0&& mm[z]!=0)
mm[temp]=mm[z]+1;
}
if(temp==0)
mm[temp]=1;
}
if(temp==0)
cout<<1;
else
cout<<mm[temp];
} | 1 | 41,987,426 |
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int N, M;
cin >> N >> M;
vector<int> p(M);
vector<string> S(M);
rep(i,M) cin >> p[i] >> S[i];
vector<bool> result(N);
vector<int> wa(N);
rep(i,M) {
if (!result[p[i]-1]) {
if (S[i] == "AC") {
result[p[i]-1] = true;
}
else {
++wa[p[i]-1];
}
}
}
int ans = 0, pena = 0;
rep(i,N) {
if (result[i]) {
++ans;
pena += wa[i];
}
}
cout << ans << " " << pena << endl;
return 0;
} | #include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
#include <bits/stdc++.h>
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define REP(i,n,x) for(long long i=n;i<x;i++)
#define REPN(i,n,x) for(long long i=n+1;i<x;i++)
#define pr printf
#define re return
#define mod 1000000007
#define INF 1e18+5
const double PI=3.14159265358979323846;
#define fi first
#define se second
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
typedef pair<long long, long long> P;
vector<pair<long long, long long> > prime_factorize(long long n) {
vector<pair<long long, long long> > res;
for (long long p = 2; p * p <= n; ++p) {
if (n % p != 0) continue;
int num = 0;
while (n % p == 0) { ++num; n /= p; }
res.push_back(make_pair(p, num));
}
if (n != 1) res.push_back(make_pair(n, 1));
return res;
}
vector<long long> calc_divisor(long long n) {
vector<long long> res;
for (long long i = 1LL; i*i <= n; ++i) {
if (n % i == 0) {
res.push_back(i);
long long j = n / i;
if (j != i) res.push_back(j);
}
}
sort(res.begin(), res.end());
return res;
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll gcd(const vector<ll> &v) {
ll ret = v[0];
for (ll i = 1; i < v.size(); i++)
ret = gcd(ret, v[i]);
return ret;
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll lcm(const vector<ll> &v) {
ll ret = v[0];
for (ll i = 1; i < v.size(); i++)
ret = lcm(ret, v[i]);
return ret;
}
void to_lower(string& x) {
for (ll i = 0; i < x.length(); i++) if ('A' <= x[i] && x[i] <= 'Z') {
x[i] -= 'A' - 'a';
}
}
void to_bigger(string& x) {
for (ll i = 0; i < x.length(); i++) if ('a' <= x[i] && x[i] <= 'z') {
x[i] += 'A' - 'a';
}
}
vector<pair<long long,long long>> g[200020];
ll s[200020];
bool used[200020];
ll A,B,C,D,H,K,M,N,Q,R,S,T,W,X,Y;
double dA,dB,dC,dH,dK,dM,dN,dQ,dR,dS,dT,dW,dX,dY;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
long long ans,sum,cnt,cnt1,flg,flg1,flg2;
long long max,max1;
long long min,min1;
long long wk,wk1;
max=max1=wk=wk1=sum=ans=cnt=cnt1=flg=flg1=flg2=0;
min=min1=INF;
double dwk,dwk1,dsum,dsum1,dans,dans1;
dwk=dwk1=dsum=dsum1=dans=dans1=0;
cin >> N >> M;
vector<pair<long long, long long> > p(M);
vector<ll>v(N+1,0);
vector<ll>w(N+1,0);
rep(i,M){
string s;
cin >> wk >> s;
if(s=="AC"){
v[wk]=1;
}
else{
if(v[wk]!=1){
w[wk]++;
}
}
}
ll ans1=0;
rep(i,N){
if(v[i+1]==1){
ans++;
ans1+=w[i+1];
}
}
pr("%lld %lld",ans,ans1);
re 0;
re 0;
} | 1 | 13,375,297 |
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n , k;
cin >> n >> k;
ll x[100001] = {};
for ( ll i = 0 ; i < n ; i++){
int a , b;
cin >> a >> b;
x[a] += b;
}
ll c = 0;
for ( int i = 0 ; i < 100001 ; i++ ){
c += x[i];
if( c >= k ){
cout << i;
return 0;
}
}
} | #include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "YES" << endl; \
} \
else \
{ \
cout << "NO" << endl; \
}
#define IFYes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "Yes" << endl; \
} \
else \
{ \
cout << "No" << endl; \
}
#define IFyes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "yes" << endl; \
} \
else \
{ \
cout << "no" << endl; \
}
#define DEBUG_OUTPUT_ARRAY(XXX, ONE) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
}
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "<<< i = " << i << " >>>" << endl; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
} \
}
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << i << " "; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << XXX[i][j] << " "; \
} \
cout << endl; \
}
typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;
const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323;
long long int A[200200],B[200200],N,K,S,res=0,tmp=0;
pll ba[200200];
int main(){
cout << fixed << setprecision(18);
cin>>N>>K;
for(long long int i = 0; i < N; i++){
cin>>ba[i].first>>ba[i].second;
}
sort(ba,ba+N);
for(long long int i = 0; i < N; i++){
K-=ba[i].second;
if(K<=0){cout<<ba[i].first<<endl;return 0;}
}
} | 1 | 97,243,709 |
#include<iostream>
using namespace std;
int main(void){
int h,w;
while(1){
cin>>h>>w;
if(h==0&&w==0)break;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(i!=0&&j!=0&&i!=h-1&&j!=w-1){
cout<<".";
}
else{
cout<<"#";
}
}
cout<<endl;
}
cout<<endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main()
{
int h,w;
while(1)
{
cin>>h>>w;
if((h==0)&&(w==0)) break;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
cout<<(((i==0)||(i==h-1)||(j==0)||(j==w-1))?'#':'.');
cout<<endl;
}
cout<<endl;
}
} | 1 | 34,687,517 |
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=998244353;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
int dx[8]={0,0,1,1,1,-1,-1,-1};
int dy[8]={1,-1,1,-1,0,1,-1,0};
int main(){
ll s=1;
int keta=0;
char c;
bool f=false;
for(int i=1;i<=11;i++){
cout<<"? "<<s<<endl;
cin>>c;
keta=i-1;
if(c=='N'){
f=true;
break;
}
s*=10;
}
if(!f){
s=1;
for(int i=1;i<10;i++){
cout<<"? "<<s+1<<endl;
cin>>c;
if(c=='Y'){
cout<<"! "<<s<<endl;
return 0;
}
s*=10;
}
}
int now=1;
s=0;
while(1){
if(now==keta){
int en=0;
if(keta==1){
en=1;
}
for(int i=9;i>=en;i--){
cout<<"? "<<(s+i)*10<<endl;
cin>>c;
if(c=='N'){
cout<<"! "<<s+i+1<<endl;
return 0;
}
}
cout<<"! "<<s+en<<endl;
return 0;
}else{
int ok=0,ng=10;
while(ng-ok>1){
int mid=(ng+ok)/2;
cout<<"? "<<s+mid<<endl;
cin>>c;
if(c=='Y'){
ok=mid;
}else{
ng=mid;
}
}
s+=ok;
}
now++;
s*=10;
}
} | #include <iostream>
#define N_MAX 1000000000
using namespace std;
int func(long long n){
static int cnt = 0;
if(cnt++ > 64)return -1;
char ans;
cout << "? " << n << endl;
cin >> ans;
if(ans == 'Y')return 1;
return 0;
}
int main(void){
long long left = (long long)N_MAX*10-1, right = (long long)N_MAX*100;
while(left + 1 < right){
long long mid = (left + right) / 2;
if(func(mid)){
right = mid;
}else{
left = mid;
}
}
while(right%10 == 0)right /= 10;
if(right == 1){
while(func(right*2) == 0){
right *= 10;
}
cout << "! " << right << endl;
}else{
left = 10;
right--;
while(func(right*left) == 1){
left *= 10;
}
left /= 10;
right++;
cout << "! " << right*left << endl;
}
} | 1 | 29,488,551 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long i,n=0,k=0,l,c=0;
string s;
cin>>s;
for(i=0;i<s.size();i++)
{
if(s[i]==',') cout<<" ";
else cout<<s[i];
}
cout<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1e9+7;
void solve()
{
string s;
cin>>s;
for(ll i=0;i<s.size();i++)
{
if(s[i]==',')
cout<<" ";
else
cout<<s[i];
}
return;
return;
}
int main()
{
fast;
ll q;
q=1;
while(q--)
solve();
return 0;
} | 1 | 42,225,694 |
#include <iostream>
using namespace std;
int main () {
int N;
cin >> N;
string s;
cin >> s;
int sum=1;
for (int i=1; i<N; i++) {
if (s[i]!=s[i-1]) {
sum++;
}
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define MAXX 500005
#define PI 3.14159265358979323846264338327950
#define F first
#define S second
#define ll long long int
#define mod 1000000007
int main()
{
FAST;
ll n;
cin >> n;
string s;
cin >> s;
string a = "";
a += s[0];
for(ll i = 1; i < s.size(); i ++){
if(s[i] != s[i-1]){
a += s[i];
}
}
cout << a.size();
} | 1 | 464,723 |
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;
const int yy = 20 * 20 + 19 * 10;
int main() {
int n; cin >> n;
int ms[30];
int now = 0;
for (int i = 0; i < 30; ++i) {
ms[i] = now;
if ((i % 2)&&i<20)now += 19;
else now += 20;
}
while (n--) {
int y, m, d; cin >> y >> m >> d;
y--; m--; d--;
m = y * 10 + m;
int ans = (m / 30)*yy + ms[m % 30] + d;
cout << 196470 - ans << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int Y,M,D,ans=1;
cin>>Y>>M>>D;
int cny=Y,cnm=M;
if(cny%3!=0){
if(cnm%2!=0){
ans+=20-D;
ans+=(10-cnm)/2*20;
ans+=((10-cnm)/2+1)*19;
}
else{
ans+=19-D;
ans+=(10-cnm)/2*20;
ans+=(10-cnm)/2*19;
}
}
else{
ans+=20-D;
ans+=(10-cnm)*20;
}
cny++;
while(1000-cny>0){
if(cny%3==0){
ans+=200;
}
else{
ans+=195;
}
cny++;
}
cout<<ans<<endl;
}
return 0;
} | 1 | 8,436,178 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<ll> h(n);
rep (i, n) {
cin>>h.at(i);
}
int ans=0;
int memo=0;
rep (i, n-1) {
if(h.at(i)>=h.at(i+1)) {
memo++;
ans=max(memo, ans);
}
else {
memo=0;
}
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> h(n);
int count=0,max_reg=0;
cin >> h[0];
for(int i=1; i<n; i++){
cin >> h[i];
if(h[i]<=h[i-1]){
count++;
max_reg=max(count,max_reg);
} else {
count=0;
}
}
cout << max_reg << endl;
return 0;
} | 1 | 4,987,363 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
int N;
cin>>N;
int W[N];
int sum=0;
rep(i,N){
cin>>W[i];
sum+=W[i];
}
int T=0;
int m=1000000;
rep(i,N){
T+=W[i];
sum-=W[i];
m=min(m,abs(T-sum));
}
cout<<m<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
int main(){
int n;
cin >> n;
vector<int> w(n);
rep(i, n){
cin >> w[i];
}
int diff = 10000000;
rep(i, n){
int x = 0, y = 0;
for (int j = 0; j < i; j++){
x += w[j];
}
for (int j = i; j < n; j++){
y += w[j];
}
diff = min(diff, abs(x-y));
}
cout << diff << endl;
return 0;
} | 1 | 25,588,239 |
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int MAX_N = 1e5 + 5;
const int MAX_L = 20;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)
#define endl '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define mm(X) memset((X), 0, sizeof((X)))
#define deb(x) cout<<#x<<" "<<x<<endl;
void solve() {
int n; cin >> n;
int a[n];
rep(i, 0, n) cin >> a[i];
int dp[n];
if (n == 2) {
cout << abs(a[0] - a[1]);
return;
}
dp[n - 1] = 0; dp[n - 2] = abs(a[n - 1] - a[n - 2]);
for (int i = n - 3; i >= 0; i--) {
dp[i] = min(abs(a[i] - a[i + 1]) + dp[i + 1], abs(a[i] - a[i + 2]) + dp[i + 2]);
}
cout << dp[0];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
} | #include <bits/stdc++.h>
using namespace std;
int flag1(int dp[],int n,int arr[],int i){
if(i==n-1){
dp[i]=0;
}
else if(i==n-2){
dp[i]=abs(arr[n-1]-arr[n-2]);
}
else
{
dp[i]=min(abs(arr[i+1]-arr[i])+flag1(dp,n,arr,i+1),abs(arr[i+2]-arr[i])+flag1(dp,n,arr,i+2));
}
return dp[i];
}
int main()
{
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
int dp[n];
for (int i = n - 1; i >= 0; i--)
{
if (i == n - 1)
{
dp[i] = 0;
}
else if (i == n - 2)
{
dp[i] = abs(a[n -1] - a[n - 2]);
}
else
{
dp[i] = min(dp[i+1]+abs(a[i+1]-a[i]),dp[i+2]+abs(a[i+2]-a[i]));
}
}
cout<<dp[0];
} | 1 | 73,572,355 |
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
int coins[] = { 500, 100, 50, 10, 5, 1 };
int main()
{
string str = "";
while (getline (cin, str ) ){
int money;
stringstream ss(str);
ss >> money;
if (money == 0 ){
break;
}
int change = 1000 - money;
int res = 0;
int i;
for (i = 0; i < sizeof(coins)/sizeof(coins[0]); ++i) {
while (change >= coins[i] ){
change -= coins[i];
++res;
}
}
cout << res << endl;
}
return 0;
} | #include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
int kane;
int oturi[6]={500,100,50,10,5,1};
int mai;
int main(){
while(1){
mai=0;
cin>>kane;
if(kane==0) break;
kane=1000-kane;
for(int i=0;i<6;i++){
mai+=(kane/oturi[i]);
kane%=oturi[i];
}
cout<<mai<<endl;
}
return 0;
} | 1 | 9,535,123 |
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll mod=1e9+7;
ll power(ll a,ll b)
{
if(b==0)
return 1;
ll x=0;
if(b%2==0)
{
x=power(a,b/2)%mod;
return ((x%mod)*(x%mod))%mod;
}
else
{
x=power(a,b-1)%mod;
return ((a%mod)*(x%mod))%mod;
}
}
int main()
{
arena
ll n,k;
cin>>n>>k;
ll dp[k+1];
for(ll i=k;i>=1;i--)
{
dp[i]=power(k/i,n)%mod;
for(ll j=2*i;j<=k;j=j+i)
{
dp[i]=dp[i]-dp[j];
}
}
ll sum=0;
for(ll i=1;i<=k;i++)
{
sum=(sum%mod+(dp[i]%mod*i%mod)%mod)%mod;
}
cout<<sum;
} | #include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
#include<cstring>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;
ll inf = ll(1e9 + 7);
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;
}
int main() {
int n, k;
cin >> n >> k;
ll ans = 0;
vector<ll> cnt(k + 1);
for (int i = k; i >= 1; i--) {
ll ki = ll(k / i);
ll cnti = modpow(ki, ll(n), inf);
int ii = 2 * i;
while (ii <= k) {
cnti -= cnt[ii];
cnti=(cnti+inf)%inf;
ii += i;
}
cnt[i] = cnti;
ans += ll(i) * cnti % inf;
ans %= inf;
}
cout << ans << endl;
} | 1 | 15,619,994 |
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int x[N],w[N];
int main()
{
int n,l,t;
scanf("%d %d %d",&n,&l,&t);
for(int i=1;i<=n;i++)scanf("%d %d",&x[i],&w[i]);
int pos=0;
for(int i=1;i<=n;i++)
{
if(w[i]==1)x[i]+=t;
else x[i]-=t;
pos+=x[i]/l;
if(x[i]%l<0)pos--;
x[i]=(x[i]%l+l)%l;
}
sort(x+1,x+n+1);
pos=(pos%n+n)%n;
for(int i=pos+1;i<=n;i++)printf("%d\n",x[i]);
for(int i=1;i<=pos;i++)printf("%d\n",x[i]);
return 0;
} | #include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
int main() {
ll n, l, t;
cin >> n >> l >> t;
vl x(n), w(n);
bool w1 = false, w2 = false;
rep (i, n) {
cin >> x[i] >> w[i];
if (w[i] == 1) w1 = true;
else w2 = true;
}
using P = pair<ll, pii>;
vector<P> x2(n);
rep (i, n) {
if (w[i] == 1) {
x2[i].first = (x[i] + t) % l;
}
else {
x2[i].first = (x[i] - t) % l;
x2[i].first = (x2[i].first + l) % l;
}
x2[i].second.first = w[i];
x2[i].second.second = i;
}
if (!w1 || !w2) {
rep (i, n) {
cout << x2[i].first << endl;
}
return 0;
}
int now;
int cnt2 = 0;
rrep (i, n) {
if (w[i] == 1) now = i;
else cnt2++;
}
ll col = 0;
col += (ll)cnt2 * (t / l) * 2;
t %= l;
pll lr(x[now], x[now] + t);
rep (i, n) {
if (w[i] == 1) continue;
int s = x[i];
if (s < x[now]) s += l;
double f = (x[now] + s) / 2.0;
if (f < x[now] + t) col++;
f += l / 2.0;
if (f < x[now] + t) col++;
}
int af = (now + col) % n;
sort(all(x2));
vl ans(n);
int st;
rep (i, n) {
if (x2[i].second.second == now) {
st = i;
break;
}
}
for (int i = -1; i != st; i = (i + 1) % n) {
if (i == -1) i = st;
ans[af] = x2[i].first;
af = (af + 1) % n;
}
rep (i, n) {
cout << ans[i] << endl;
}
} | 1 | 5,065,985 |
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)
#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;
int main()
{
int x,t;
cin>>x>>t;
cout<<max(0,x-t)<<endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
int main(){
int x, t;
cin >> x >> t;
int ans = max(x-t,0);
cout << ans << endl;
return 0;
} | 1 | 44,593,285 |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
int n, m;
cin >> n >> m;
vector<string> a(n);
vector<string> b(m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0; i <= n-m; i++){
for (int j = 0; j <= n-m; j++){
bool temp_check = true;
for (int k = 0; k <= m-1; k++){
for (int l = 0; l <= m-1; l++){
if (a[i+k][j+l] != b[k][l]){
temp_check = false;
}
}
}
if (temp_check == true){
cout << "Yes" << endl;
return 0;
}
else continue;
}
}
cout << "No" << endl;
} | #include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back
const long long INF = 1LL << 60;
int main() {
int N, M;
cin >> N >> M;
string c, d;
char a[N][N];
char b[M][M];
rep(i, N){
cin >> c;
rep(j, N){
a[i][j] = c[j];
}
}
rep(i, M){
cin >> d;
rep(j, M){
b[i][j] = d[j];
}
}
bool flag = false;
rep(i, N-M+1){
rep(j, N-M+1){
if(a[i][j] == b[0][0]){
flag = true;
for(int k = 0; k < M; k++){
for(int l = 0; l < M; l++){
if(a[k+i][l+j] != b[k][l]) {
flag = false;
break;
}
}
}
if(flag){
print("Yes");
return 0;
}
}
}
}
print("No");
} | 1 | 39,923,222 |
#include<iostream>
#include<string>
using namespace std;
string ll = "qwertasdfgzxcvb";
bool is_ll(char c){
for(int i=0;i<ll.size();i++){
if(ll[i]==c)return true;
}
return false;
}
int solve(string s){
bool j = is_ll(s[0]);
int ans = 0;
for(int i=1;i<s.size();i++){
bool jj = is_ll(s[i]);
if(j!=jj){
j = jj;
ans ++;
}
}
return ans;
}
int main(){
string s;
while(cin>>s,s!="#"){
cout<<solve(s)<<endl;
}
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
using namespace std;
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second
#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
string l = "qwertasdfgzxcvb";
string s;
int main(){
while (cin >> s&&s != "#"){
bool f = 1;
int co = 0;
if (l.find(s[0]) != -1)f = 0;
REP(i, s.size()){
if (f){
if (l.find(s[i]) != -1){
co++;
f = 0;
}
}
else{
if (l.find(s[i]) == -1){
co++;
f = 1;
}
}
}
cout << co << endl;
}
} | 1 | 81,750,176 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B , C, D;
cin >> A >> B >> C >> D;
int L =A+B, R =C+D;
if (L > R) puts("Left");
else if (L == R) puts("Balanced");
else puts("Right");
} | #include<iostream>
using namespace std;
int main()
{
int A,B,C,D;
cin>>A>>B>>C>>D;
if(A+B>C+D)
cout<<"Left";
else if(A+B<C+D)
cout<<"Right";
else
cout<<"Balanced";
} | 1 | 53,574,035 |
#include <iostream>
using namespace std;
int main(){
int a;
int i=1;
while(1){
cin >> a;
if(a == 0){
break;
}
else{
cout << "Case" << " " << i << ":" << " " << a << endl;
i++;
}
}
} | #include <iostream>
using namespace std;
int main(void) {
int n;
int i = 1;
while(1) {
cin >> n;
if(n == 0) {
break;
}
cout << "Case " << i << ": " << n << endl;
++i;
}
return 0;
} | 1 | 27,768,840 |
#include <bits/stdc++.h>
using namespace std;
#define int 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; }
signed main(){
int n;
cin >> n;
int memo[100010] = {};
int a[100010];
for(int i = 0;i < n;i++){
cin >> a[i];
a[i]--;
}
int now = 0;
int cnt = 0;
while(1){
if(memo[now]) break;
if(now == 1){
cout << cnt << endl;
return 0;
}
memo[now] = 1;
now = a[now];
cnt++;
}
cout << -1 << endl;
return 0;
} | #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;
typedef pair<ll, int> LP;
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);
vector<bool> b(n, false);
b[0] = true;
rep(i,n){
cin >> a[i];
--a[i];
}
int cur = 0, cnt = 0;
while(true){
if(cur == 1){
cout << cnt << endl;
return 0;
}
cur = a[cur];
if(b[cur]){
cout << -1 << endl;
return 0;
}
b[cur] = true;
++cnt;
}
return 0;
} | 1 | 79,520,430 |
#include<stdio.h>
#include<string.h>
#define INF 0x3f3f3f
int max(int a,int b)
{
return a>b?a:b;
}
int map[110][110],visit[110],vis[110];
int n,m;
int dijkstra(int a)
{
memset(visit,0,sizeof(visit));
int i,j,next,sum,min;
for(i=0;i<m;i++)
vis[i]=map[a][i];
visit[a]=1;
for(i=0;i<m;i++)
{
min=INF;
for(j=0;j<m;j++)
{
if(!visit[j]&&min>vis[j])
{
next=j;
min=vis[j];
}
}
visit[next]=1;
for(j=0;j<m;j++)
if(!visit[j]&&vis[j]>vis[next]+map[next][j])
vis[j]=vis[next]+map[next][j];
}
sum=0;
for(i=0;i<m;i++)
sum+=vis[i];
return sum;
}
int main()
{
int i,j,sum;
int a,b,c;
while(scanf("%d",&n),n)
{
for(i=0;i<110;i++)
for(j=i;j<110;j++)
{
if(i==j)
map[i][j]=map[j][i]=0;
else
map[i][j]=map[j][i]=INF;
}
m=0;
while(n--)
{
scanf("%d%d%d",&a,&b,&c);
map[a][b]=map[b][a]=c;
m=max(m,max(a,b)+1);
}
sum=INF;
for(i=0;i<m;i++)
{
if(sum>dijkstra(i))
{
j=i;
sum=dijkstra(i);
}
}
printf("%d %d\n",j,sum);
}
return 0;
} | #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#define rep(i,a) for(int i=0;i<(a);++i)
const int INF = 1<<30;
#define _m_ 1
struct edge{
int from, to, cost;
edge () {}
edge(int f, int t, int c){
from=f;
to=t;
cost=c;
}
};
typedef std::pair<int, int> P;
int V;
std::vector<edge> es;
int d[11];
int maxm=0;
int SP(int s){
rep(i, maxm+1)d[i] = INF;
d[s] = 0;
while(_m_){
bool update = false;
rep(i, es.size()){
edge e = es[i];
if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
d[e.to] = d[e.from] + e.cost;
update = true;
}
}
if(!update)break;
}
int res = 0;
rep(i, maxm+1){
if(d[i] != INF)res += d[i];
}
return res;
}
int main(){
int n;
while(scanf("%d",&n) && n){
es.clear();
maxm=0;
for(int i = 0 ; i < n; ++i){
int a, b, c;
scanf("%d %d %d",&a, &b, &c);
edge ac(a,b,c);
edge bc(b,a,c);
es.push_back(ac);
es.push_back(bc);
maxm=std::max(maxm,std::max(a,b));
}
V = n;
P ans=P(0, SP(0));
for(int i = 0; i < maxm + 1; ++i){
if(ans.second > SP(i)){
ans.second = SP(i);
ans.first = i;
}
}
printf("%d %d\n", ans.first, ans.second);
}
} | 1 | 32,875,744 |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using pii = pair<int, int>;
pii operator+(pii a, pii b) { return {a.first + b.first, a.second + b.second}; }
pii operator-(pii a, pii b) { return {a.first - b.first, a.second - b.second}; }
int abs(const pii &p) { return abs(p.first) + abs(p.second); }
int main() {
int h, w; cin >> h >> w;
int d; cin >> d;
vector<pii> pos(h * w);
for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
int a; cin >> a; a--;
pos[a] = {i, j};
}
vector<int> dist(h * w);
for (int i = d; i < h * w; i++) {
dist[i] = dist[i - d] + abs(pos[i] - pos[i - d]);
}
int q; cin >> q;
while (q--) {
int l, r; cin >> l >> r; l--, r--;
cout << dist[r] - dist[l] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int getDist(int toX, int toY, int fromX, int fromY) {
return abs(toX - fromX) + abs(toY - fromY);
}
int main() {
int h, w, d; cin >> h >> w >> d;
int u = h * w;
vector<pair<int, int>> coordinate(u + 1);
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
int a; cin >> a;
coordinate[a] = { i,j };
}
}
vector<int> accum(u + 1, 0);
for (int i = 1; i <= u; i++) {
if (i <= d) {
}
else {
int toX = coordinate[i].first;
int toY = coordinate[i].second;
int fromX = coordinate[i - d].first;
int fromY = coordinate[i - d].second;;
accum[i] += getDist(toX, toY, fromX, fromY);
accum[i] += accum[i - d];
}
}
int q; cin >> q;
for (int i = 0; i < q; i++) {
int l, r; cin >> l >> r;
cout << accum[r] - accum[l] << endl;
}
return 0;
} | 1 | 47,136,125 |
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 510000;
const int INF = 1e9;
const double pi=acos(-1);
int main(){
int n;
cin >> n;
vector<ll>a(n),b(n);
rep(i,n) cin >> a[i];
rep(i,n) cin >> b[i];
vector<ll>gap;
ll sum = 0;
int num = 0;
rep(i,n){
ll diff = b[i] - a[i];
if(diff>0){
num++;
sum += diff;
}
else gap.push_back(-diff);
}
if(num==0){
cout << 0 << endl;
return 0;
}
sort(gap.begin(),gap.end(),greater<ll>());
ll plus=0;
int res = num;
rep(i,gap.size()){
plus+=gap[i];
res++;
if(plus>=sum){
break;
}
}
if(plus>=sum) cout << res << endl;
else cout << -1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;
ll gcd(ll a, ll b) {
if(b == 0) return a;
return gcd(b, a % b);
}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<ll> A(N);
vector<ll> B(N);
rep(i, N) cin >> A[i];
rep(i, N) cin >> B[i];
vector<ll> pos;
ll sum_neg = 0;
int cnt_neg = 0;
ll a, b;
rep(i, N){
a = A[i];
b = B[i];
if(a > b){
pos.push_back(a-b);
}else if(b > a){
sum_neg += (b-a);
cnt_neg++;
}
}
int cnt = cnt_neg;
sort(pos.rbegin(), pos.rend());
rep(i, pos.size()){
if(sum_neg <= 0){
cout << cnt << endl;
return 0;
}
sum_neg -= pos[i];
cnt++;
}
if(sum_neg <= 0){
cout << cnt << endl;
}else{
cout << -1 << endl;
}
return 0;
} | 1 | 13,580,232 |
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;
int main() {
fastIO;
int n;
cin >> n;
cout << (800 * n - (n / 15 * 200)) << endl;
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
int n;
cin >> n;
int res = 800 * n - 200 *( n / 15);
cout << res << ln;
} | 1 | 58,709,974 |
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}
const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 5e5 + 10;
void solve(){
int d;cin >> d;
if(d==25) cout <<"Christmas";
else if(d==24) cout <<"Christmas Eve";
else if(d==23) cout <<"Christmas Eve Eve";
else cout << "Christmas Eve Eve Eve";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
solve();
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
int gcd(int x, int y) {
if (y == 0)return x;
return gcd(y, x%y);
}
int lcm(int x, int y) {
return x / gcd(x, y)*y;
}
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i; res %= mod;
}
return res;
}
int mod_pow(int x, int y, int m) {
int res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
if (y > x)return 0;
return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int a;
signed main() {
cin >> a;
if (a == 25)cout << "Christmas" << endl;
if (a == 24)cout << "Christmas Eve" << endl;
if (a == 23)cout << "Christmas Eve Eve" << endl;
if (a == 22)cout << "Christmas Eve Eve Eve" << endl;
} | 1 | 69,235,011 |
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
class SegmentTree {
private:
int n;
vector<int> lo, hi, max_el;
void init(int i, int a, int b) {
lo[i] = a;
hi[i] = b;
if (a == b) {
return;
}
int m = (a+b)/2;
init(2*i, a, m);
init(2*i+1, m+1, b);
}
void update(int i, int a, int val) {
if (lo[i] > a || hi[i] < a) {
return;
}
if (lo[i] == hi[i] && hi[i] == a) {
max_el[i] = val;
return;
}
update(2*i, a, val);
update(2*i + 1, a, val);
max_el[i] = max(max_el[2*i], max_el[2*i+1]);
}
int maximum(int i, int a, int b) {
if (lo[i] > b || hi[i] < a) {
return -1;
}
if (lo[i] >= a && hi[i] <= b) {
return max_el[i];
}
int left = maximum(2*i, a, b);
int right = maximum(2*i + 1, a, b);
return max(left, right);
}
public:
SegmentTree(int _n) : n(_n), lo(4*n+1), hi(4*n+1), max_el(4*n+1) {
init(1,0,n-1);
}
void update(int a, int val) {
update(1, a, val);
}
int maximum(int a, int b) {
return maximum(1, a, b);
}
};
int main () {
int N, M;
cin >> N >> M;
vector<pii> v(N);
int a, b;
rep(i,N) {
cin >> a >> b;
v[i] = make_pair(b,a);
}
sort(v.begin(), v.end());
SegmentTree st(M+1);
rep(i,M+1) {
st.update(i,i);
}
int ans = 0;
rep(i,N) {
int a = v[N-1-i].second;
int b = v[N-1-i].first;
int ind = st.maximum(0, M-a);
if (ind == -1)
continue;
ans += b;
st.update(ind, -1);
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
int n,m;
cin >> n >> m;
vector<pii> v(n);
rep(i, n){
int a,b;
cin >> a >> b;
v[i] = make_pair(a, b);
}
sort(all(v));
priority_queue<int> que;
int cnt = 0, ans = 0;
for(int i = 1; i <= m; i++){
while(v[cnt].first == i){
que.push(v[cnt].second);
cnt++;
}
if(!que.empty()){
ans += que.top();
que.pop();
}
}
cout << ans << endl;
} | 1 | 87,064,377 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,D;cin>>N>>D;
vector<vector<int>>X(N,vector<int>(D));
for(int i=0;i<N;i++){
for(int j=0;j<D;j++){
cin>>X[i][j];
}
}
int ans=0;
for(int i=0;i<N;i++){
for(int j=i+1;j<N;j++){
int norm=0;
for(int k=0;k<D;k++){
int a=abs(X[i][k]-X[j][k]);
norm+=a*a;
}
bool flag= false;
for(int k=0;k<=norm;k++){
if(k*k==norm) flag=true;
}
if(flag) ans++;
}
}
cout<<ans<<endl;
} | #include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
int main(){
int N,D;
cin >> N >> D;
vector<vector<int>> X(N,vector<int>(D));
for(int i=0;i<N;++i){
for(int j=0;j<D;++j) cin >> X.at(i).at(j);
}
int ans=0;
for(int i=0;i<N;++i){
for(int j=i+1;j<N;++j){
double sum=0;
for(int d=0;d<D;++d) sum+=pow(X.at(i).at(d)-X.at(j).at(d),2);
sum=sqrt(sum);
if(sum==(int)sum) ++ans;
}
}
cout << ans << endl;
return 0;
} | 1 | 13,219,547 |
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
LL f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
if(x<0){putchar('-');x=-x;}
if(!x){putchar('0');return;}
int top=0;
while(x)stack[++top]=x%10,x/=10;
while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=100005;
const int mod=1e9+7;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int X[MAXN],Y[MAXN],n,m;
int main()
{
n=read();m=read();
for(int i=1;i<=n;i++)X[i]=read();
for(int i=1;i<=m;i++)Y[i]=read();
int s1=0,s2=0;
for(int i=1;i<=n;i++)
{
ad(s1,1LL*(i-1)*(X[i]+mod)%mod);
dl(s1,1LL*(n-i)*(X[i]+mod)%mod);
}
for(int i=1;i<=m;i++)
{
ad(s2,1LL*(i-1)*(Y[i]+mod)%mod);
dl(s2,1LL*(m-i)*(Y[i]+mod)%mod);
}pr2(1LL*s1*s2%mod);
return 0;
} | #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;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
ll x[100010],y[100010];
int main(int argc, char const *argv[])
{
int n,m;cin>>n>>m;
rep(i,n) cin>>x[i];
rep(i,m) cin>>y[i];
ll X=0,Y=0;
rep(i,n) {
X += x[i]*(2*i-n+1);
X%=MOD;
}
rep(i,m) {
Y += y[i]*(2*i-m+1);
Y%=MOD;
}
cout<< X*Y%MOD <<endl;
return 0;
} | 1 | 82,597,185 |
#include <cstdio>
#include <functional>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;
int n, m;
P x[10000];
int main(){
while(scanf("%d%d", &n, &m), n){
rep(i, n){
int d, p;
scanf("%d%d", &d, &p);
x[i] = P(p, d);
}
sort(x, x + n, greater<P>());
int ans = 0;
rep(i, n){
if(m >= x[i].second){
m -= x[i].second;
}
else{
ans += (x[i].second - m) * x[i].first;
m = 0;
}
}
printf("%d\n", ans);
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
int main() {
int N,M;
pair<int,int> PD[10010];
while(true) {
cin >> N >> M;
int d,p;
if ((N == 0) && (M == 0))
break;
for(int i=0;i<N; i++) {
cin >> d >> p;
PD[i] = make_pair(p,d);
}
sort(PD,PD+N);
int S = 0;
int guarded = 0;
for(int i=0;i<N;i++) {
S += PD[i].first*PD[i].second;
}
for(int i=0;i<N;i++) {
if(M <= 0) {
break;
} else if(M>PD[N-i-1].second) {
guarded = PD[N-i-1].second;
} else {
guarded = M;
}
S -= PD[N-i-1].first*guarded;
M -= guarded;
}
cout << S << endl;
}
} | 1 | 37,071,373 |
#include <iostream>
#include <math.h>
#include <cstdio>
using namespace std;
int main(){
double x1, y1, x2, y2;
double ans;
cin >> x1 >> y1 >> x2 >> y2;
ans = pow((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1), 0.5);
printf("%.8f\n", ans);
return 0;
} | #include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int main(){
double x1,y1,x2,y2,a,b,c,ans;
cin>>x1>>y1>>x2>>y2;
a=x1-x2;
b=y1-y2;
ans=sqrt(a*a+b*b);
printf("%.8f",ans);
} | 1 | 12,012,644 |
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main()
{
int n, k;
cin >> n >> k;
int r, s, p;
cin >> r >> s >> p;
string t;
cin >> t;
vector<bool> prev(n, true);
repl(i, k, n) {
if(t[i - k] == t[i] && prev[i - k]) prev[i] = false;
}
int ans = 0;
rep(i, n) {
if(t[i] == 'r' && prev[i]) ans += p;
if(t[i] == 's' && prev[i]) ans += r;
if(t[i] == 'p' && prev[i]) ans += s;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long 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; }
int main(void){
int n,k;
cin >> n >> k;
vector<int> a(3);
REP(i,3) cin >> a[i];
string s;
cin >> s;
vector<int> ctoi(256);
ctoi['r']=2;
ctoi['c']=0;
ctoi['p']=1;
int ans=0;
REP(i,k){
vector<int> x;
for(int j=i;j<n;j+=k){
x.push_back(ctoi[s[j]]);
}
vector<int> dp(2);
int pre=-1;
for(int nx :x){
vector<int> p(2);
swap(dp,p);
dp[0]=max(p[0],p[1]);
if(pre==nx){
dp[1]=p[0]+a[nx];
}else{
dp[1]=max(p[0],p[1])+a[nx];
}
pre=nx;
}
ans+=max(dp[0],dp[1]);
}
cout << ans << endl;
return 0;
} | 1 | 75,643,199 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,D;
cin >> N >> D;
vector<vector<int>> matrix(N, vector<int>(D));
for (int i=0; i<N; i++){
for (int j=0; j<D; j++){
cin >> matrix.at(i).at(j);
}
}
int ans = 0;
int distance_squared = 0;
for (int i=0; i<N-1; i++){
for (int j=i+1;j<N; j++){
for(int k=0;k<D;k++){
distance_squared += pow((matrix.at(i).at(k) - matrix.at(j).at(k)),2);
}
for(int l=1; l<130; l++){
if(distance_squared == l*l){
ans++;
break;
}
}
distance_squared = 0;
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x) int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);
#define ll long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"
typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void c_p_c()
{
#ifndef ONLINE_JUDGE
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout << endl;
}
int check(int n) {
int temp = n + 9;
temp = temp / 10;
return temp * 10;
}
bool comp(pair<string, pair<int, int>> a , pair<string, pair<int, int>> b) {
if (a.F != b.F)
return a.F < b.F;
return a.S.F > b.S.F;
}
bool check(int a, int b, int c) {
set<int> s;
s.insert(a);
s.insert(b);
s.insert(c);
auto it = s.begin();
it++;
if (b == *it)
return true;
return false;
}
bool isPerfectSquare(ll n)
{
for (ll i = 1; i * i <= n; i++) {
if ((n % i == 0) && (n / i == i)) {
return true;
}
}
return false;
}
int main() {
int i, n, m, k, c = 0;
c_p_c();
int d;
cin >> n >> d;
vector<int > a[n];
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < d; ++j)
{
cin >> k;
a[i].pb(k);
}
}
for (int i = 0; i < n; ++i)
{
for (int j = i + 1; j < n; ++j)
{
ll sum = 0;
for (int u = 0; u < d; ++u)
{
sum+=(a[i][u]-a[j][u])*(a[i][u]-a[j][u]);
}
if(isPerfectSquare(sum))
c++;
}
}
cout<<c<<endl;
return 0;
} | 1 | 90,133,346 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
signed main(){
int x,t; cin>>x>>t;
if(x<=t) cout<<0;
else cout<<x-t;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int a, b;
int main()
{
scanf("%d %d", &a, &b);
printf("%d\n", max(0, a - b));
return 0;
} | 1 | 81,951,891 |
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair
template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }
int main() {
int n;
while(n=in()){
n=1000-n;
int res=0;
res+=n/500;
n-=n/500*500;
res+=n/100;
n-=n/100*100;
res+=n/50;
n-=n/50*50;
res+=n/10;
n-=n/10*10;
res+=n/5;
n-=n/5*5;
res+=n;
cout<<res<<endl;
}
return 0;
} | #include<iostream>
using namespace std;
int main(){
int turi;
int hara;
int count;
while(1){
count=0;
cin>>hara;
if(hara==0) break;
turi=1000-hara;
while(turi!=0){
if(turi>=500){
turi=turi-500;
count++;
}
else if(turi>=100){
turi=turi-100;
count++;
}
else if(turi>=50){
turi=turi-50;
count++;
}
else if(turi>=10){
turi=turi-10;
count++;
}
else if(turi>=5){
turi=turi-5;
count++;
}
else if(turi>=1){
turi=turi-1;
count++;
}
}
cout<<count<<endl;
}
} | 1 | 87,879,565 |
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll pr[mx],ar[mx],br[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
int main()
{
ll n;
cin >> n;
bool e=false;
if(n%2==0)
e=true;
if(!e)
{
cout << 0 << endl;
return 0;
}
ll a=0;
n /= 10;
a += n;
while(n>=5)
{
n /= 5;
a += n;
}
cout << a << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main(){
long long N;
cin >> N;
if(N % 2 == 1){
cout << 0 << endl;
return 0;
}
N /= 2;
long long cnt = 0;
long long t = 5;
while(N >= t){
cnt += N / t;
t *= 5;
}
cout << cnt << endl;
} | 1 | 91,553,250 |
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
int main()
{
int n;
cin >> n;
vector<string> w(n);
rep(i, n) cin >> w[i];
string ans = "Yes";
repl(i, 1, n) {
if(w[i][0] != w[i - 1][w[i - 1].size() - 1]) ans = "No";
rep(j, i) {
if(w[i] == w[j]) ans = "No";
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
string w[n];
vector<string> v;
cin >> w[0];
v.push_back(w[0]);
for (int i=1; i<n; i++) {
cin >> w[i];
if(w[i][0] != w[i-1][w[i-1].size()-1]) {
cout << "No" << endl;
return 0;
} else if (find(v.begin(), v.end(), w[i]) != v.end()) {
cout << "No" << endl;
return 0;
} else {
v.push_back(w[i]);
}
}
cout << "Yes" << endl;
} | 1 | 27,220,502 |
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n; cin >> n;
vll x(n); REP(i, n) cin >> x[i];
ll l, q; cin >> l >> q;
vvll doubling(n, vll(31, 0));
ll j;
REP(i, n) {
ll left=i, right=n;
while (left<right) {
ll mid = (left+right) / 2;
if (x[mid]-x[i] <= l) left=mid+1;
else right=mid;
}
doubling[i][0] = left-1;
}
REP(j, 30) {
REP(i, n) {
doubling[i][j+1] = doubling[doubling[i][j]][j];
}
}
REP(_, q) {
ll a, b; cin >> a >> b; a--; b--;
if (a > b) swap(a, b);
ll ans = 0;
for (ll i=30; i>=0; i--) {
if (doubling[a][i] < b) {
ans += 1<<i;
a = doubling[a][i];
}
}
cout << ans+1 << '\n';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> furthest_left, furthest_right;
int ans;
void left(int a, int b){
auto next_a = lower_bound(furthest_left[a].begin(), furthest_left[a].end(), -b);
if(next_a == furthest_left[a].begin()){
ans += 1;
return;
}
else{
ans += 1<<(prev(next_a) - furthest_left[a].begin());
left(-*prev(next_a),b);
}
}
void right(int a, int b){
auto next_a = lower_bound(furthest_right[a].begin(), furthest_right[a].end(), b);
if(next_a == furthest_right[a].begin()){
ans += 1;
return ;
}
else{
ans += 1<<(prev(next_a) - furthest_right[a].begin());
right(*prev(next_a),b);
}
}
int main(){
int n;
cin >> n;
vector<int> x(n);
for(int i=0; i<n; i++){
cin >> x[i];
}
int l, q;
cin >> l >> q;
vector<int> a(q), b(q);
for(int i=0; i<q; i++){
cin >> a[i] >> b[i];
a[i] -= 1;
b[i] -= 1;
}
furthest_left.resize(n);
furthest_right.resize(n);
for(int i=0; i<n; i++){
furthest_left[i].push_back(-(lower_bound(x.begin(), x.end(), x[i] - l) - x.begin()));
furthest_right[i].push_back(upper_bound(x.begin(), x.end(), x[i] + l) - x.begin() - 1);
}
int j = 0;
while(furthest_left[n-1][j] < 0){
for(int i=0; i<n; i++){
furthest_left[i].push_back(furthest_left[-furthest_left[i][j]][j]);
}
j += 1;
bool flag = true;
for(int i=0; i<n; i++){
if(furthest_left[i][j] != furthest_left[i][j-1]) flag = false;
}
if(flag == true) break;
}
int k = 0;
while(furthest_right[0][k] < n-1){
for(int i=0; i<n; i++){
furthest_right[i].push_back(furthest_right[furthest_right[i][k]][k]);
}
k += 1;
bool flag = true;
for(int i=0; i<n; i++){
if(furthest_right[i][k] != furthest_right[i][k-1]) flag = false;
}
if(flag == true) break;
}
for(int i=0; i<q; i++){
ans = 0;
if(a[i] > b[i]) left(a[i], b[i]);
if(a[i] < b[i]) right(a[i], b[i]);
cout << ans << endl;
}
return 0;
} | 1 | 54,510,667 |
#include<bits/stdc++.h>
using namespace std;
int main (void){
int a = 0,b = 0,c = 0;
cin >> a >> b;
a = a * a;
c = a - b;
cout << c << endl;
return 0;
} | #include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
signed main(){
ios_base::sync_with_stdio(0);
int n,a;
cin>>n>>a;
cout<<n*n-a;
re 0;
} | 1 | 71,664,335 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
int main(){
int n,m;
cin >> n >> m;
ll res = 0;
if(n == 1 && m == 1){
res = 1;
}else if(n == 1 || m == 1){
res = 1ll*n*m-2;
}else{
n -= 2;
m -= 2;
res = 1ll*n*m;
}
cout << res << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int64_t n,m;
cin >> n >> m;
cout << ((n!=1&&m!=1)?(n-2)*(m-2):(n!=1)?(n-2):(m!=1)?(m-2):1) << endl;
return 0;
} | 1 | 94,999,213 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;
int N, K;
vector<ll> a;
bool need(int x) {
if (a[x] >= K) return true;
vector<bool> dp(K);
dp[0] = true;
rep(i, N) {
if (i == x) continue;
for (int j = K - 1; j >= 0; j--) {
if (j + a[i] >= K) continue;
if (dp[j]) dp[j + a[i]] = true;
}
}
for (int i = K - a[x]; i < K; i++) {
if (dp[i]) return true;
}
return false;
}
int main() {
cin >> N >> K;
a.resize(N);
rep(i, N) cin >> a[i];
sort(a.begin(), a.end());
int l = -1, r = N;
while (r - l > 1) {
int c = (l + r) / 2;
if (need(c)) r = c; else l = c;
}
cout << r << endl;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N, K;
vector<int> a;
bool judge(int m) {
bool dp[5010] = {false};
dp[0] = true;
for (auto i = 0; i < N; i++) {
if (i == m) continue;
for (auto j = K-a[i]-1; j >= 0; j--) {
if (!dp[j]) continue;
if (K-a[m] <= j+a[i]) {
return true;
}
dp[j+a[i]] = true;
}
}
return false;
}
int main() {
int x;
cin >> N >> K;
for (auto i = 0; i < N; i++) {
cin >> x;
if (x < K) {
a.push_back(x);
}
}
sort(a.begin(), a.end());
N = a.size();
int l, r, m;
l = -1;
r = N;
while (r - l > 1) {
m = (l + r) / 2;
if (judge(m)) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
return 0;
} | 1 | 94,259,185 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <queue>
using namespace std;
int64_t min(int64_t a,int64_t b) {
if (a > b)
{
return b ;
}else
{
return a ;
}
}
int main(){
string s ;
cin >> s ;
vector<bool> c(26,0) ;
for (int i = 0; i < s.size(); i++)
{
int num = s.at(i) - 'a' ;
c.at(num) = 1 ;
}
for (int i = 0; i < 26; i++)
{
if (c.at(i) == 0)
{
char ans = 'a' + i ;
cout << ans << endl ;
return 0 ;
}
}
cout << "None" << endl;
} | #include"bits/stdc++.h"
#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;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
int main() {
string s;
cin >> s;
vector<int>arr(26,0);
for (auto ss: s) {
arr[ss - 'a']++;
}
rep(i, 26) {
if (arr[i] == 0) {
cout << char('a' + i) << endl;
return 0;
}
}
cout << "None" << endl;
return 0;
} | 1 | 67,195,134 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
bool right(char c){
char a[11]={'y', 'u', 'i', 'o', 'p', 'h', 'j', 'k', 'l', 'n', 'm'};
rep(i,11){
if(c==a[i])return true;
}
return false;
}
int main(){
while(true){
string s;
cin>>s;
if(s=="#")break;
bool flag=right(s[0]);
int cn=0;
for(int i=1; i<s.length(); i++){
if(flag!=right(s[i])){flag=right(s[i]); cn++;}
}
cout<<cn<<endl;
}
return 0;
} | #include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
map<char,bool> qwer;
qwer['q'] = false;
qwer['w'] = false;
qwer['e'] = false;
qwer['r'] = false;
qwer['t'] = false;
qwer['a'] = false;
qwer['s'] = false;
qwer['d'] = false;
qwer['f'] = false;
qwer['g'] = false;
qwer['z'] = false;
qwer['x'] = false;
qwer['c'] = false;
qwer['v'] = false;
qwer['b'] = false;
qwer['y'] = true;
qwer['u'] = true;
qwer['i'] = true;
qwer['o'] = true;
qwer['p'] = true;
qwer['h'] = true;
qwer['j'] = true;
qwer['k'] = true;
qwer['l'] = true;
qwer['n'] = true;
qwer['m'] = true;
string str;
while(cin >> str){
if(str[0] == '#')
break;
int count = 0;
for(unsigned i=1;i<str.size();i++){
if(qwer[str[i-1]] != qwer[str[i]])
count++;
}
cout << count << endl;
}
return 0;
} | 1 | 71,315,312 |
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int a, b;
string s;
cin >> a >> b >> s;
bool ok = true;
if (SZ(s) != a+b+1) {
cout << "No\n";
return 0;
}
forn(i, 0, a) {
ok &= isdigit(s[i]);
}
ok &= s[a] == '-';
forn(i, a+1, SZ(s)) {
ok &= isdigit(s[i]);
}
if (ok) cout << "Yes\n";
else cout << "No\n";
} | #include <stdio.h>
int main() {
int A, B, pos = 0;
char S[20];
scanf("%d %d %s", &A, &B, S);
for (int i = 0; S[i] != '\0'; i++) {
if (S[i] == '-') {
pos += i;
}
}
pos == A ? puts("Yes") : puts("No");
return 0;
} | 1 | 95,202,870 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
unsigned euclidean_gcd(unsigned a, unsigned b) {
if (a < b) return euclidean_gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
using namespace std;
int main() {
string a;
cin >> a;
vector<bool> s(26);
int f = a.size();
for (int i = 0; i < f; i++) {
s.at(a.at(i) - 'a') = true;
}
for (int i = 0; i < 26; i++) {
if (s.at(i) == false) {
cout << a;
char t = 'a';
for (int j = 0; j < i; j++) {
t += 1;
}
cout << t << endl;
break;
}
}
if (a.size() == 26) {
for (int i = 25; i > -1; i--) {
char v = 'Z';
for (int j = i + 1; j < 26; j++) {
if (a.at(i) < a.at(j)) {
if (v == 'Z')v = a.at(j);
else v = min(a.at(j), v);
}
}
if (v != 'Z') {
for (int j = 0; j < i; j++) {
cout << a.at(j);
}
cout << v << endl;
break;
}
}
if (a == "zyxwvutsrqponmlkjihgfedcba")cout << -1 << endl;
}
} | #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;
int main() {
string s;
cin >> s;
string ans;
set<char> charSet;
for (int i = 0; i <s.length();i++) {
string tmp = s.substr(0, i);
for (int j = 1; j < 26;j++) {
if (s[i] + j > 'z') {
break;
}
if (charSet.find(s[i] + j) == charSet.end()) {
tmp += s[i] + j;
ans = tmp;
break;
}
}
charSet.insert(s[i]);
}
if (charSet.size() < 26) {
for (int i = 0;i < 26;i++) {
if (charSet.find('a' + i) == charSet.end()) {
ans = s;
ans += 'a' + i;
break;
}
}
}
if (ans.length() == 0) {
cout << -1 << endl;
}
else {
cout << ans << endl;
}
} | 1 | 62,982,633 |
#include <bits/stdc++.h>
#define rep(l, r) for (int i = (l); i < (r); i++)
typedef long long ll;
using namespace std;
int main() {
char x, y;
cin >> x >> y;
cout << (x == y ? '=' : x < y ? '<' : '>') << endl;
return 0;
} | #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
#ifdef TEST
chrono::system_clock::time_point start, end;
start = chrono::system_clock::now();
#endif
char X,Y;
cin >> X >> Y;
if(X - '0' > Y - '0') cout << ">" << endl;
else if ((X - '0' < Y - '0')) cout << "<" << endl;
else cout << "="<< endl;
#ifdef TEST
end = chrono::system_clock::now();
cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
return 0;
} | 1 | 24,566,233 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#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 repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
int main(){
int n;
cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
vll b(n+1);
rep(i, n) b[i+1] = b[i] + a[i];
VSORT(b);
ll ans = 0;
int cnt = 1;
rep(i, n+1) {
if (i<n && b[i]==b[i+1]) ++cnt;
else {
ans += (ll)cnt * (cnt-1) / 2;
cnt = 1;
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main(void) {
int N;
cin >> N;
vector<int64_t> A(N);
rep(i, N) { cin >> A[i]; }
vector<int64_t> SUM(N + 1);
SUM[0] = 0;
rep(i, N) {
SUM[i + 1] = SUM[i] + A[i];
}
unordered_map<int64_t, int64_t> hist;
int64_t answer = 0;
rep(i, N) {
answer += (int64_t)hist[SUM[i + 1]];
hist[SUM[i + 1]]++;
}
answer += hist[0];
cout << answer << endl;
return 0;
} | 1 | 18,721,725 |
#include <stdio.h>
#define MAX 101
int A[MAX][MAX], s[MAX], h[MAX];
void serch(int x, int y){
int i;
h[x] = y;
for(i=1; i<=s[x]; i++){
if(h[A[x][i]] > y)
serch(A[x][i], y+1);
}
}
int main(){
int i, j, k, n;
scanf("%d", &n);
for(i=1; i<=n; i++){
h[i] = 10000;
for(j=1; j<=n; j++)
A[i][j] = 0;
}
for(i=1; i<=n; i++){
scanf("%d", &k);
scanf("%d", &s[k]);
for(j=1; j<=s[k]; j++)
scanf("%d", &A[k][j]);
}
serch(1,0);
for(i=1; i<=n; i++){
if(h[i] == 10000)
h[i] = -1;
printf("%d %d\n", i, h[i]);
}
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
#include <limits.h>
using namespace std;
vector<int> v[101];
int d[101];
queue<int> q;
bool flag[101];
int main(){
int n, u, k; scanf("%d", &n);
for (int i = 0; i < n; ++i){
scanf("%d %d", &u, &k);
for (int j = 0; j < k; ++j){
int tmp; scanf("%d", &tmp);
v[u].push_back(tmp);
}
}
memset(d, -1, sizeof(d));
d[1] = 0;
q.push(1); flag[1] = true;
while (!q.empty()){
int m = q.front(); q.pop();
for (int i = 0; i < v[m].size(); ++i){
int tmp = v[m][i];
if (!flag[tmp]){
flag[tmp] = true;
d[tmp]=d[m]+1;
q.push(tmp);
}
}
}
for (int i = 1; i <= n; ++i){
cout << i << ' ' << d[i] << '\n';
}
} | 1 | 44,493,106 |
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
using namespace std;
const int INF = 1e18;
void solve()
{
std::ifstream in("sample.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
bool isAns = false;
for (int in = 0; in <= n; in++)
{
for (int jm = 0; jm <= m; jm++)
{
if (in * m + jm * n - 2 * (in * jm) == k)
isAns = true;
}
}
cout << ((isAns) ? "Yes" : "No") << endl;
}
signed main()
{
solve();
return 0;
} | #include <iostream>
int main() {
int n, m, k; std::cin >> n >> m >> k;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (((n-i)*j + (m-j)*i) == k) {
std::cout << "Yes" << std::endl;
return 0;
}
}
}
std::cout << "No" << std::endl;
return 0;
} | 1 | 20,498,204 |
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
printf("%d\n",n/3);
return 0;
} | #include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int main() {
int n ;
cin >> n;
cout << n / 3 << "\n";
} | 1 | 65,673,369 |
#include <iostream>
#include <vector>
using namespace std;
int calcCoins(int price) {
const int coinNums[] = {500, 100, 50, 10, 5, 1};
int result = 0;
int remain = price;
for (int i = 0; i < 6; i++) {
int coinMaisu = remain / coinNums[i];
result += coinMaisu;
remain -= coinMaisu * coinNums[i];
}
return result;
}
int main(void){
vector<int> prices;
while (true) {
int price;
cin >> price;
if (price == 0) break;
prices.push_back(price);
}
for (int i = 0; i < prices.size(); i++) {
cout << calcCoins(1000 - prices[i]) << endl;
}
} | #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int main(void){
int money;
while(cin>>money){
if(money==0)break;
int oturi = 1000-money;
int ans = 0;
ans += oturi/500;
oturi%=500;
ans += oturi/100;
oturi%=100;
ans += oturi/50;
oturi%=50;
ans += oturi/10;
oturi%=10;
ans += oturi/5;
oturi%=5;
ans += oturi;
cout<<ans<<endl;
}
return 0;
} | 1 | 86,288,817 |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
using namespace std;
const int mod=1e9+7;
const string sp=" ";
void run();
void init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(12);
}
signed main(){
init();
run();
return 0;
}
void run(){
int n,k;
cin>>n>>k;
int m=(n-1)*(n-2)/2;
if(m<k){
cout<<-1<<endl;
return;
}
cout<<(n-1)+m-k<<endl;
REP(i,2,n)cout<<1<<sp<<i<<endl;
int cnt=m-k;
REP(i,2,n){
REP(j,i+1,n){
if(!cnt)return;
cout<<i<<sp<<j<<endl;
cnt--;
}
}
} | #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, k;
cin >> n >> k;
int max_num = (n-1)*(n-2) / 2;
if(k > max_num){
cout << -1 << endl;
return 0;
}
vector<P> v;
for(int i = 1; i < n; i++){
for(int j = 1; j < i; j++){
v.emplace_back(j+1, i+1);
}
}
vector<P> ans;
for(int i = 1; i < n; i++){
ans.emplace_back(1, i+1);
}
for(int i = 0; i < max_num - k; i++){
ans.push_back(v[i]);
}
cout << ans.size() << endl;
for(P &p : ans){
cout << p.first << " " << p.second << endl;
}
return 0;
} | 1 | 71,321,716 |
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
bool is_integer( float x ){
return floor(x)==x;
}
bool is_prime(long long N) {
if (N == 1) return false;
for (long long i = 2; i * i <= N; ++i) {
if (N % i == 0) return false;
}
return true;
}
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (N/i != i) res.push_back(N/i);
}
}
sort(res.begin(), res.end());
return res;
}
vector<pair<long long, long long> > prime_factorize(long long N) {
vector<pair<long long, long long> > res;
for (long long a = 2; a * a <= N; ++a) {
if (N % a != 0) continue;
long long ex = 0;
while (N % a == 0) {
++ex;
N /= a;
}
res.push_back({a, ex});
}
if (N != 1) res.push_back({N, 1});
return res;
}
int main() {
pair<bool,int> pr[100001];
int n,m; cin >> n >> m;
int p;
string s;
int ansAC = 0;
int ansWA = 0;
rep(i,100001){
pr[i].first = false;
pr[i].second = 0;
}
rep(i,m){
cin >> p >> s;
if(s == "AC"){
pr[p].first = true;
}
else if(pr[p].first == false){
pr[p].second ++;
}
}
rep(i,100001){
if(pr[i].first == true){
ansWA += pr[i].second;
ansAC ++;
}
}
cout << ansAC <<" "<< ansWA;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(V) V.begin(), V.end()
#define PB push_back
using namespace std;
typedef long long ll;
int main() {
int n,m;
cin >> n >>m;
vector<int>wa(n);
vector<bool>flag(n);
int pena = 0;
int cnt = 0;
rep(i,m){
int p;
string s;
cin >> p >> s;
if(s == "WA" && flag[p] == false) {
wa[p]++;
}
if(s == "AC" && flag[p] == false){
cnt++;
pena += wa[p];
flag[p] = true;
}
}
cout << cnt << " "<< pena <<endl;
} | 1 | 56,324,898 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vc vector<char>
#define mii map<int,int>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
void MAIN() {
string s, t;
cin >> s >> t;
map<char, char> m, r;
for (int i = 0; i < s.size(); i++) {
if (m.count(s[i]) && m[s[i]] != t[i]) {
cout << "No" << '\n';
return;
}
m[s[i]] = t[i];
if (r.count(t[i]) && r[t[i]] != s[i]) {
cout << "No" << '\n';
return;
}
r[t[i]] = s[i];
}
cout << "Yes" << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int T = 1;
while (T--) MAIN();
} | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecd vector<double>
#define vecst vector<string>
#define vecb vector<bool>
#define vec2(var, n, m) vector<vector<int>> var(n, vector<int>(m, 0))
#define vecb2(var, n, m) vector<vector<bool>> var(n, vector<bool>(m, false))
#define vecll2(var, n, m) vector<vector<ll>> var(n, vector<ll>(m, 0))
#define rep(i,n) for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n) vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n) vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n) vecst var(n); rep(i,n){cin >> var[i];}
#define all(var) (var).begin(), (var).end()
#define sortall(var) sort(all(var))
#define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var) accumulate(all(var), 0)
#define f_sumll(var) accumulate(all(var), 0LL)
#define chmin(v1, v2) v1 = min(v1, v2)
#define chmax(v1, v2) v1 = max(v1, v2)
#define pb(var) push_back(var)
#define prt(var) cout << (var) << "\n"
#define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var) cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v) rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "YES" : "NO");}
int main(void) {
string s, t;
cin >> s >> t;
int n = s.size();
map<char, char> mps, mpt;
rep(i,n){
if(mps.find(s[i])==mps.end()){
mps.emplace(s[i], t[i]);
} else if(mps[s[i]]!=t[i]) {
prt("No");
return 0;
}
if(mpt.find(t[i])==mpt.end()){
mpt.emplace(t[i], s[i]);
} else if(mpt[t[i]]!=s[i]) {
prt("No");
return 0;
}
}
prt("Yes");
} | 1 | 63,484,960 |
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>
#define MOD (1000000007)
using namespace std;
typedef long long int Int;
constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }
int N,K;
vector<pair<int,int> > V;
void solve(void) {
for(int i = 2;i <= N;i++) {
V.push_back({1,i});
}
int rest = (N-1)*(N-2)/2 - K;
for(int i = 2;i < N;i++) {
for(int j = i+1;j <= N;j++) {
if(rest > 0) {
rest--;
V.push_back({i,j});
}
}
}
cout<<V.size()<<endl;
for(auto u: V) {
cout<<u.first<<" "<<u.second<<endl;
}
return;
}
int main(void) {
cin>>N>>K;
if(K > ((N-1)*(N-2))/2) {
cout<<-1<<endl;
return 0;
}
solve();
return 0;
} | #include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl
const ll INF = 1LL << 60;
void solve(long long N, long long K){
if(K > (N-1)*(N-2)/2){
cout<<-1<<endl; return;
}
K = (N-1)*(N-2)/2 - K;
cout << K+N-1 << endl;;
for(ll i=2; i <= N; i++){
cout << "1 " << i<< endl;
}
for(ll i=2; i<N; i++){
if(K == 0) break;
for(ll j = i+1; j <= N; j++){
if(K == 0) break;
cout<< i <<" "<<j<<endl;
K--;
}
}
}
int main(){
long long N;
scanf("%lld",&N);
long long K;
scanf("%lld",&K);
solve(N, K);
return 0;
} | 1 | 11,132,982 |
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
using namespace std;
int main(){
ll a, b, c, d; cin >> a >> b >> c >> d;
print(max({a*d, a*c, b*c, b*d}));
} | #include<iostream>
#include<algorithm>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
ll a,b,c,d;
int main()
{
ios;
cin>>a>>b>>c>>d;
ll m1,m2,m3,m4,maxn;
m1=a*c,m2=a*d;
m3=b*c,m4=b*d;
maxn=max(max(max(m1,m2),m3),m4);
cout<<maxn<<"\n";
return 0;
} | 1 | 97,262,844 |
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
int a[110];
rep(i, N) cin >> a[i];
sort(a, a + N);
rep(i, N - 1) {
if (a[i + 1] - a[i] > 1) {
cout << "Impossible" << endl;
return 0;
}
}
if (a[0] * 2 != a[N - 1] && a[0] * 2 != a[N - 1] + 1) {
cout << "Impossible" << endl;
} else if (a[N - 1] % 2 == 0 && a[0] == a[1]) {
cout << "Impossible" << endl;
} else if (a[N - 1] % 2 == 1 && a[0] == a[2]) {
cout << "Impossible" << endl;
} else {
cout << "Possible" << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int A[100];
rep(i, N) cin >> A[i];
int saidai = *max_element(A, A + N);;
int B[100] = {};
rep(i, N) B[A[i]]++;
int saishou = (saidai + 1) / 2;
int OK = 1;
for (int i = saidai; i > saishou; i--) {
if (B[i] < 2) OK = 0;
}
if (saidai & 1) {
if (B[saishou] != 2) OK = 0;
}
else {
if (B[saishou] != 1) OK = 0;
}
for (int i = saishou - 1; i > 0; i--) {
if (B[i]) OK = 0;
}
if (OK) co("Possible");
else co("Impossible");
Would you please return 0;
} | 1 | 22,336,325 |
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
ll gcd(ll a, ll b){
if (a < b) swap(a,b);
if (a%b == 0) return b;
return gcd(b, a%b);
}
ll lcm(ll a, ll b){
return a/gcd(a, b)*b;
}
ll n, ans;
ll t[112];
int main() {
cin >> n;
rep(i,n) cin >> t[i];
ans = 1;
rep(i,n) ans = lcm(ans, t[i]);
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
ull gcd(ull a,ull b){
return b?gcd(b,a%b):a;
}
ull lcm(ull a,ull b){
ull x=a/gcd(a,b);
return x*b;
}
int main()
{
ull n;cin>>n;
ull a;cin>>a;
ull ans=a;
for(int i=1;i<n;i++){
cin>>a;
ans=lcm(ans,a);
}
cout<<ans;
return 0;
} | 1 | 69,009,369 |
#include <iostream>
using namespace std;
int main(){
string s;
cin >> s;
if(s <= "2019/04/30") cout << "Heisei\n";
else cout << "TBD\n";
} | #include <iostream>
using namespace std;
int main()
{
string s;
cin >> s;
int d, m;
d = 10 * (int(s[5]) - 48) + int(s[6]) - 48;
m = 10 * (int(s[8]) - 48) + int(s[9]) - 48;
if(d <= 4 && m <= 30)
cout << "Heisei";
else
cout << "TBD";
return 0;
} | 1 | 76,531,831 |
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif
const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
signed main(){
IOS;
int a, b, c, k;
cin >> a >> b >> c >> k;
int ans = 0;
if (a >= k) {
ans = k;
}
else if (a + b >= k) {
ans = a;
}
else if (a + b + c >= k) {
ans = a - (k - a - b);
}
cout << ans << endl;
return 0;
} | #include <stdio.h>
int main(){
int a,b,c,k,sum=0;
scanf("%d%d%d%d",&a,&b,&c,&k);
if(k<=a)return 0*printf("%d\n",k);
if(k>a)sum+=a,k-=a;
if(k<=b)return 0*printf("%d\n",sum);
if(k>b)sum+=0,k-=b;
return 0*printf("%d\n",sum-k);
return 0;
} | 1 | 86,301,499 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1000000007;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n + 10);
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r;
l--, r--;
a[l]++;
a[r + 1]--;
}
int cnt = 0;
rep(i, n) {
if (0 < i) a[i] += a[i - 1];
}
rep(i, n) if (a[i] >= m) cnt++;
cout << cnt << endl;
} | # include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define f first
# define s second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define pqueue priority_queue
using namespace std;
template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7,N=1e6+3;
int pref[N],ans;
void solve(){
int n,m;
cin>>n>>m;
rep(i,m){
int l,r;
cin>>l>>r;
pref[l]++;
pref[r+1]--;
}
for(int i=1;i<=n;++i){
pref[i]+=pref[i-1];
ans+=pref[i]==m;
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T=1;
while(T--)solve();
} | 1 | 15,204,744 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
void mul_mod(ll& a, ll b){
a *= b;
a %= MOD;
}
void add_mod(ll& a, ll b){
a += b;
if(a>MOD){
a -= MOD;
}
}
int c[123];
int main(void){
int a,n,i,r=-INF,d;
cin >> n;
for(i=0; i<n; ++i){
cin >> a;
++c[a];
r = max(r,a);
}
for(i=0; i<=r; ++i){
d = max(i,r-i);
if(!c[d]){
cout << "Impossible" << endl;
return 0;
}
--c[d];
}
for(i=1; i<r; ++i){
d = max(i,r-i)+1;
c[d] = 0;
}
for(i=0; i<=r; ++i){
if(c[i]){
cout << "Impossible" << endl;
return 0;
}
}
cout << "Possible" << endl;
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(),x.end()
const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;
int main()
{
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
int k = *max_element(all(a));
vector<int> cnt(k+1);
for(int i = 0; i < n; i++){
cnt[a[i]]++;
}
bool flag = true;
if(k%2==0){
for(int i = 1; i <= k; i++){
if(i<k/2 && cnt[i]>0) flag = false;
if(i>k/2 && cnt[i]<2) flag = false;
if(i==k/2 && cnt[i]!=1) flag = false;
}
}else{
k++;
for(int i = 1; i <k; i++){
if(i<k/2 && cnt[i]>0) flag = false;
if(i>k/2 && cnt[i]<2) flag = false;
if(i==k/2 && cnt[i]!=2) flag = false;
}
}
cout << (flag?"Possible":"Impossible") << endl;
return 0;
} | 1 | 28,715,265 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
constexpr int MOD = 1000000007;
const int INF = 1 << 30;
bool is_number(char c) {
int d = c - '0';
return d >= 0 && d <= 9;
}
void say_no() {
cout << "No" << endl;
exit(0);
}
int main() {
int a, b;
cin >> a >> b;
string s;
cin >> s;
int n = a+b+1;
rep(i, n) {
if (i < a) {
if (!is_number(s[i])) say_no();
}
else if (i > a) {
if (!is_number(s[i])) say_no();
}
else {
if (s[i] != '-') say_no();
}
}
cout << "Yes" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int A, B;
cin >> A >> B;
string S;
cin >> S;
bool chk1 = false, chk2 = true;
if (S[A] == '-') {
chk1 = true;
}
for (int i = 0; i < A + B + 1; i++) {
if (S[i] == '-' && i != A) chk2 = false;
}
if (chk1 && chk2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | 1 | 100,369,352 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
struct edge{
int to,weight;
edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;
long long modinv(long long a, long long m=MOD) {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;}
int gcd(int a, int b){if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
int dx = a-c;
int dy = b-d;
cout << c + dy << " "<< d - dx << " " << a + dy << " " << b - dx << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000100100;
int main() {
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
ll dx12 = x2 - x1, dy12 = y2 - y1;
ll x3, y3, x4, y4;
if(abs(dx12) <= abs(dy12)) {
x3 = x2 - dy12;
y3 = y2 + dx12;
} else {
x3 = x2 - dy12;
y3 = y2 + dx12;
}
x4 = x3 - dx12;
y4 = y3 - dy12;
cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
return 0;
} | 1 | 73,327,689 |
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vll a(n);
rep(i, n) cin >> a[i];
vll l(n+1), r(n+1);
l[n] = 2;
r[n] = 2;
for (int i = n-1; i >= 0; --i) {
ll mn = (l[i+1] + a[i] - 1) / a[i] * a[i];
ll mx = r[i+1] / a[i] * a[i];
if (!(mn <= mx)) {
cout << -1 << endl;
return 0;
}
l[i] = mn;
r[i] = mx + a[i] - 1;
}
cout << l[0] << " " << r[0] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
int arr[100005];
int32_t main(){
int n;
scanf("%lld",&n);
for (int x = 0; x<n; x++){
scanf("%lld",&arr[x]);
}
int mn = 2;
int mx = 2;
for (int x = n-1; x>=0; x--){
mn = ((mn-1)/arr[x]+1)*arr[x];
mx = (mx/arr[x])*arr[x]+arr[x]-1;
if (mx<mn){
printf("-1");
return 0;
}
}
printf("%lld %lld",mn,mx);
} | 1 | 3,603,135 |
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
int main(void)
{
int n;
cin >> n;
vpii E(1e5, pair<int, int>());
vpii O(1e5, pair<int, int>());
for (int i = 0; i < 1e5; i++)
{
E[i].second = i+1;
O[i].second = i+1;
}
for (int i = 0; i < n; i++)
{
int v;
cin >> v;
i % 2 == 0 ? E[v-1].first++ : O[v-1].first++;
}
sort(rall(E));
sort(rall(O));
int ans;
if (E[0].second == O[0].second)
{
if (E[1].first > O[1].first)
ans = (n/2 - E[1].first) + (n/2 - O[0].first);
else
ans = (n/2 - E[0].first) + (n/2 - O[1].first);
}
else
ans = (n / 2 - E[0].first) + (n / 2 - O[0].first);
cout << ans << endl;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(false);
int n; cin >> n;
vector<int> e(1e5 + 1, 0), o(1e5 + 1, 0);
REP(i, n) {
int v; cin >> v;
if (i % 2) o[v]++;
else e[v]++;
}
int maxE = max_element(e.begin(), e.end()) - e.begin();
int maxO = max_element(o.begin(), o.end()) - o.begin();
int res = 0;
if (maxE != maxO) res = n - e[maxE] - o[maxO];
else {
sort(e.rbegin(), e.rend());
sort(o.rbegin(), o.rend());
res = min(n - o[0] - o[1], n - e[1] - e[0]);
}
cout << res << '\n';
return 0;
} | 1 | 72,561,638 |
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;
int n, d;
double CalcDist(vector<int> a, vector<int>b) {
int sum = 0;
rep(i, d) {
sum += (a[i] - b[i]) * (a[i] - b[i]);
}
return sqrt((double)sum);
}
bool IsInteger(double x) {
return floor(x) == x;
}
int main()
{
cin >> n >> d;
vector<vector<int>> x(n);
rep(i, n) rep(j, d) {
int tmp;
cin >> tmp;
x[i].push_back(tmp);
}
int ans = 0;
rep(i, n) {
for (int j = i + 1; j < n; j++) {
double dist = CalcDist(x[i], x[j]);
if (IsInteger(dist)) ans++;
}
}
cout << ans << endl;
return 0;
} | #include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};
ll mod(ll a, ll mod){
ll res = a%mod;
if(res<0)res=res + mod;
return res;
}
ll modpow(ll a, ll n, ll mod){
ll res=1;
while(n>0){
if(n&1) res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
ll modinv(ll a, ll mod){
return modpow(a, mod-2, mod);
}
ll gcd(ll a, ll b){
ll r = a%b;
if(r==0) return b;
else return gcd(b, a%b);
}
bool is_prime(ll n){
ll i = 2;
if(n==1)return false;
if(n==2)return true;
bool res = true;
while(i*i <n){
if(n%i==0){
res = false;
}
i = i+1;
}
if(n%i==0)res=false;
return res;
}
struct UnionFind{
ll N;
llvec p;
llvec cnt;
UnionFind(ll n){
N = n;
p=llvec(N);
cnt=llvec(N, 0);
rep(i, N){
p[i] = i;
cnt[i] = 1;
}
}
void con(ll a, ll b){
P at = root(a);
P bt = root(b);
if(at.second!=bt.second){
if(at.first>bt.first){
swap(at, bt);
swap(a, b);
}
p[at.second] = bt.second;
cnt[bt.second]+=cnt[at.second];
p[a]=bt.second;
}
}
P root(ll a){
ll atmp = a;
ll c=0;
while(atmp!=p[atmp]){
atmp = p[atmp];
c++;
}
p[a] = atmp;
return {c, atmp};
}
bool is_con(ll a, ll b){
P at=root(a);
P bt=root(b);
return at.second == bt.second;
}
};
struct dijkstra{
ll N;
llvec d;
vector<vector<edge>> e;
dijkstra(ll n){
N = n;
e = vector<vector<edge>>(N);
}
void add_edge(ll from, ll to, ll cost){
e[from].push_back({to, cost});
}
void run(ll start){
priority_queue<P, vector<P>, greater<P>> que;
que.push({0, start});
d = llvec(N, 1e18);
d[start]=0;
while(!que.empty()){
P q = que.top();que.pop();
ll dc = q.first;
ll x = q.second;
if(dc>d[x]){
continue;
}else{
for(auto ip: e[x]){
if(d[ip.x]<=d[x]+ip.c){
continue;
}else{
d[ip.x]= d[x]+ip.c;
que.push({d[ip.x], ip.x});
}
}
}
}
}
};
int main(){
ll N, D;
cin >> N >> D;
vector<llvec> x(N, llvec(D));
rep(i, N){
rep(j, D)cin >> x[i][j];
}
set<ll> d;
rep(i, 10000){
d.insert(i*i);
}
ll cnt=0;
rep(i, N){
FOR(j, i+1, N){
ll tmp=0;
rep(k, D){
tmp += pow(x[i][k]-x[j][k], 2);
}
if(d.count(tmp)>0)cnt++;
}
}
cout << cnt;
return 0;
} | 1 | 80,086,017 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int N;
cin>>N;
vector<int> A(N),B(N);
for(int i=0;i<N;i++)
cin>>A[i]>>B[i];
int ans=0;
for(int i=N-1;i>=0;i--)
ans+=(A[i]+ans+B[i]-1)/B[i]*B[i]-(A[i]+ans);
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
int n;cin>>n;
ll a[n],b[n],c[n];
rep(i,n) {
cin>>a[i]>>b[i];
c[i]=-(a[i]%b[i]);
if(a[i]%b[i]!=0) c[i]+=b[i];
}
for(int i=n-1;i>0;i--){
if(c[i-1]<c[i]){
ll cnt=(c[i]-c[i-1])/b[i-1];
if((c[i]-c[i-1])%b[i-1]!=0) cnt++;
c[i-1]+=b[i-1]*cnt;
}
}
cout<<c[0]<<"\n";
} | 1 | 78,809,791 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
template<class T> inline bool chmin(T &a,T b){
if (a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T &a,T b){
if (a<b){
a=b;
return true;
}
return false;
}
int main(){
ll N,K;
cin >> N >> K;
vector<ll> a(N);
ll sum=0;
rep(i,N){
cin >> a[i];
if (a[i]>0){
sum+=a[i];
}
}
ll countn=0,countp=0;
rep(i,K){
if (a[i]<0){
countn+=a[i];
}
else {
countp+=a[i];
}
}
ll ans=0;
chmax(ans,sum+countn);
chmax(ans,sum-countp);
rep(i,N-K){
if (a[i]<0){
countn-=a[i];
}
else {
countp-=a[i];
}
if (a[K+i]<0){
countn+=a[K+i];
}
else {
countp+=a[K+i];
}
chmax(ans,sum+countn);
chmax(ans,sum-countp);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> v(n + 1, 0);
REP(i, n) cin >> v[i];
ll sum = 0, now = 0, nowm = 0;
REP(i, n) sum += max(0, v[i]);
REP(i, k) {
now += v[i];
nowm += max(0, v[i]);
}
ll maxv = -INFL;
REP(i, n - k + 1) {
maxv = max(maxv, sum - nowm + max(0LL, now));
now += v[i + k] - v[i];
nowm += max(0, v[i + k]) - max(0, v[i]);
}
cout << maxv << endl;
return 0;
} | 1 | 78,777,888 |
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
const int N=55;
int x[N],y[N];
int n,k;
int val[N],c;
signed main()
{
cin>>n>>k;
for(register int i=1;i<=n;i++)
cin>>x[i]>>y[i];
long long ans=LLONG_MAX;
for(register int a=1;a<=n;a++)
for(register int b=1;b<=n;b++)
for(register int c=1;c<=n;c++)
for(register int d=1;d<=n;d++)
{
int x1=x[a],y1=y[b],x2=x[c],y2=y[d];
if(x1>x2||y1>y2) continue;
int cnt=0;
for(register int i=1;i<=n&&cnt<k;i++)
if(x1<=x[i]&&x[i]<=x2&&y1<=y[i]&&y[i]<=y2)
cnt++;
if(cnt==k) ans=min(ans,(x2-x1)*1ll*(y2-y1));
}
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
int N = V.size();
REP(i,N){
os << V[i];
if (i!=N-1) os << " ";
}
os << "\n";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
os << "(";
os << P.first;
os << " ";
os << P.second;
os << ")";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
auto it=S.begin();
while(it!=S.end()){
os << *it;
os << " ";
it++;
}
os << "\n";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
for(auto it=q.begin();it<q.end();it++){
os<<*it;
os<<" ";
}
os<<endl;
return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,K;
cin >> N >> K;
vector<pair<ll,ll>> A;
ll a,b;
REP(i,N) cin >> a >> b, A.emplace_back(a,b);
sort(ALL(A));
ll ans=INF;
ll x,y;
for(int i=0;i<N;i++){
for(int j=i+K-1;j<N;j++){
vector<pair<ll,ll>> B;
for(int k=i;k<=j;k++){
B.emplace_back(A[k].second,A[k].first);
}
sort(ALL(B));
for(int l=0;l<=j-i-K+1;l++){
int r = l+K-1;
ll bot=INF,top=-INF;
REP(idx,K){
chmin(bot, B[l+idx].second);
chmax(top, B[l+idx].second);
}
chmin(ans, (top-bot)*(B[l+K-1].first-B[l].first));
}
}
}
cout << ans << endl;
} | 1 | 65,287,245 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
void solve() {
int x, n;
cin >> x >> n;
vector<int> p(101, 0);
rep(i, n) {
int t;
cin >> t;
p[t]++;
}
vector<int> cand;
for (int i = 1; i <= 100; i++) {
if (p[i] == 0) {
cand.push_back(i);
}
}
cand.push_back(0);
cand.push_back(101);
sort(cand.begin(), cand.end());
int ans = 0;
int diff = 10000;
rep(i, cand.size()) {
if (diff > abs(x - cand[i])) {
ans = cand[i];
diff = abs(x - cand[i]);
}
}
cout << ans << endl;
}
int main() {
solve();
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <iomanip>
using namespace std;
int main()
{
int X, N, t;
cin >> X >> N;
vector<bool> a(102, false);
for (int i = 0; i < N; i++)
{
cin >> t;
a[t] = true;
}
t = 0;
while (true)
{
if (a[X - t] == false)
{
cout << X - t << endl;
return 0;
}
if (a[X + t] == false)
{
cout << X + t << endl;
return 0;
}
t++;
}
} | 1 | 58,406,122 |
#include <bits/stdc++.h>
using namespace std;
#define PI 2*acos(0.0)
#define print(x) return cout<<x<<endl,0
#define watch(x) cerr<<#x<<"-> "<<x<<endl
#define CLEAR(x,val) memset(x,val,sizeof(x))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 1000000000;
const int MOD = 1000000007;
signed main()
{
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
cout<<n/2-(n%2==0)<<endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
const int mod = 1e9 + 7;
const int kmax = 510000;
long long fact[kmax], fact_inv[kmax], inv[kmax];
void init_comb()
{
fact[0] = fact[1] = 1;
fact_inv[0] = fact_inv[1] = 1;
inv[1] = 1;
for (int i = 2; i < kmax; i++) {
fact[i] = fact[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
}
}
long long comb(int n, int r)
{
if (n < r) {
return 0;
}
if (n < 0 || r < 0) {
return 0;
}
return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}
template <typename T, T N>
class UnionFind {
T parent_[N];
T rank_[N];
T size_[N];
public:
UnionFind();
T Root(T idx);
bool IsSame(T x, T y);
void Unite(T x, T y);
T GetSize(T idx);
};
template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
for (T i = 0; i < N; i++) {
parent_[i] = i;
rank_[i] = 0;
size_[i] = 1;
}
}
template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}
template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
return Root(x) == Root(y);
}
template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
x = Root(x);
y = Root(y);
if (x == y) {
return;
}
if (rank_[x] < rank_[y]) {
parent_[x] = y;
size_[y] += size_[x];
} else {
parent_[y] = x;
size_[x] += size_[y];
if (rank_[x] == rank_[y]) {
rank_[x]++;
}
}
}
template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
return size_[Root(idx)];
}
long long pow_mod(long long n, long long p, long long m)
{
if (p == 0) {
return 1;
}
if (p % 2 == 0) {
long long t = pow_mod(n, p / 2, m);
return t * t % m;
}
return n * pow_mod(n, p - 1, m) % mod;
}
long long nCr_mod(long long n, long long r)
{
long long x = 1;
for (long long i = n - r + 1; i <= n; i++) {
x *= i;
x %= mod;
}
long long a = 1;
for (long long i = 1; i <= r; i++) {
a *= i;
a %= mod;
}
long long y = pow_mod(a, mod - 2, mod) % mod;
return x * y % mod;
}
bool is_prime(long long n)
{
if (n == 1) {
return false;
}
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main()
{
long long n;
std::cin >> n;
long long ans = 0;
for (int i = 1; i <= n / 2; i++) {
if (n - i != i) {
ans++;
}
}
std::cout << ans << std::endl;
} | 1 | 14,300,258 |
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;
int main() {
int N;
cin >> N;
int n = 1;
while (1) {
if (n * 2 > N) break;
else n *= 2;
}
cout << n << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
FastRead
int cnt=0,ans=1,n;
cin>>n;
for(int i=1;i<=n;i++){
int div=0,t=i;
while(t%2==0){
t/=2;
div++;
}
if(div>cnt){
cnt=div;
ans=i;
}
}
cout<<ans<<endl;
return 0;
} | 1 | 49,742,672 |
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
int n;
cin >> n;
int a[n];
int idx = 1;
int last_i = -1;
int count = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == idx) {
count += (i-last_i-1);
last_i = i;
idx++;
continue;
}
if (i == n-1) {
if (idx == 1) {
cout << "-1" << endl;
return 0;
}
count += i-last_i;
}
}
cout << count << endl;
return 0;
} | #include <iostream>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
int ans = n;
int j = 1;
rep(i,n) {
if(a[i] == j) {
--ans;
++j;
}
}
if(j == 1) ans = -1;
cout<< ans << endl;
return 0;
} | 1 | 91,185,885 |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int const N = 50001;
int main()
{
int n, m;
cin >> n >> m;
int p[n] = {};
vector<int> G[n];
vector<int> connect(n, -1);
rep(i, n)
{
cin >> p[i];
p[i]--;
}
rep(i, n)
connect[i] = -1;
rep(i, m)
{
int x, y;
cin >> x >> y;
x--, y--;
G[x].push_back(y);
G[y].push_back(x);
}
int cnt = 0;
rep(u, n)
{
if (connect[u] != -1)
continue;
queue<int> q;
q.push(u);
cnt++;
while (!q.empty())
{
int v = q.front();
connect[v] = cnt;
q.pop();
rep(i, G[v].size())
{
if (connect[G[v][i]] == -1)
q.push(G[v][i]);
}
}
}
int ans = 0;
rep(i, n) if (connect[i] == connect[p[i]]) ans++;
OP(ans);
return 0;
} | #include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;
class UnionFind{
vector<ll> par; vector<ll> r_size;
public:
UnionFind(ll N) : par(N),r_size(N){
for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1;}
}
void init(ll N){
par.resize(N); r_size.resize(N);
for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1;}
}
ll find(ll x){
if(par[x] == x)return x;
return par[x]=find(par[x]);
}
void unite(ll x,ll y){
ll rx = find(x); ll ry = find(y);
if(rx == ry) return;
if(r_size[rx]<r_size[ry]) swap(rx,ry);
r_size[rx] += r_size[ry];
par[ry] = rx;
}
bool same(ll x, ll y){
ll ry = find(x); ll rx = find(y);
return rx == ry;
}
ll el_size(ll x){
return r_size[find(x)];
}
};
bool compare_second(const ip& ip1, const ip& ip2){
return ip1.second <ip2.second;
}
int main(){
int n,m,x,y,t; cin>>n>>m;
vector<ip> p(n); rep(i,n){cin>>t; p[i].first = i; p[i].second = --t;}
vector<ip> pairs(m); rep(i,m){ cin>>x>>y; pairs[i].first = --x; pairs[i].second = --y;}
vector<ip> ele(n); ele = p;
sort(ele.begin(),ele.end(),compare_second);
UnionFind uf(n);
rep(i,m)uf.unite(pairs[i].first,pairs[i].second);
int ans = 0;
rep(i,n){
if(p[i].second == i)++ans;
else if(uf.same(p[i].first, p[ele[i].first].first))++ans;
}
cout<<ans <<endl; return 0;
} | 1 | 41,065,174 |
#include <bits/stdc++.h>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
int main(){
LL N, A, B;
cin >> N >> A >> B;
LL min_sum = (N-2)*A;
LL max_sum = (N-2)*B;
if(min_sum > max_sum){
cout << 0 << endl;
}else{
cout << max_sum - min_sum + 1 << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main(){
long long n, a, b; cin >> n >> a >> b;
if(a>b){
cout << 0 << endl;
return 0;
}
if(n==1){
if(a!=b) cout << 0 << endl;
else cout << 1 << endl;
}else{
cout << (n-2) * (b-a) + 1 << endl;
}
return 0;
} | 1 | 3,165,582 |
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(int argc, char const *argv[]) {
ll n;std::cin >> n;
vll a(n), b(n);
multimap<ll, ll> mp;
re(i, n) {
std::cin >> a[i] >> b[i];
mp.emplace(a[i] + b[i], i);
}
ll A = 0, B = 0;
while(!(mp.empty())){
ll idx = (*(--mp.end())).second;
A+=a[idx];mp.erase(--mp.end());
if(mp.empty()) break;
idx = (*(--mp.end())).second;
B+=b[idx];mp.erase(--mp.end());
}
std::cout << A - B << '\n';
return 0;
} | #include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>
using namespace std;
template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
namespace {
void printElems(const int* begin, const int* end)
{
for (const int* p = begin; p != end; ++p) {
std::cout << *p << ' ';
}
std::cout << std::endl;
}
}
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari rep1(i,n-1)rep(j,i)
#define souatari1 for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;
const ll llinf = numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 10000000000000000;
ll alist[100005];
ll blist[100005];
int main(){
int n;
cin >> n;
priority_queue<
array<ll,3>
> q;
rep(i,n){
ll a,b;
cin >> a >> b;
q.push({b+a,a,i});
alist[i] = a;
blist[i] = b;
}
ll ans = 0;
bool flag = false;
while(!q.empty()){
array<ll,3> tmp = q.top();
q.pop();
if(flag){
ans-=blist[tmp[2]];
}
else{
ans+=alist[tmp[2]];
}
flag = !flag;
}
prints(ans);
return 0;
} | 1 | 58,498,471 |
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1e9+5
#define int long long
#define LINF 1000000000000000005
int n,x,y,k[100005],r,v[100005],t[100005],ans,f;
vector <int> g[100005];
void DFS(int nod){
v[nod]=1;
int cnt1=0,cnt0=0;
for(int i : g[nod]){
if(!v[i]){
DFS(i);
if(!t[i]) cnt0++;
else cnt1++;
}
}
if(cnt1 && !cnt0) t[nod]=0;
else if(cnt0==1) t[nod]=1;
else if(cnt0>1) f=1;
}
int32_t main(){
ios_base :: sync_with_stdio(0);
cin >> n;
for(int i=1;i<n;i++){
cin >> x >> y;
g[x].pb(y); g[y].pb(x);
k[x]++; k[y]++;
}
DFS(1);
if(f || !t[1]) cout << "First";
else cout << "Second";
} | #include <bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
struct edge
{
int v,next;
}vs[300010];
int st[300010],ee,n,size[300010],fg;
inline void addedge(int u,int v)
{
vs[++ee].v=v;vs[ee].next=st[u];st[u]=ee;
}
inline int dfs(int rt,int pr)
{
int ret=1,cnt=0;
for(int i=st[rt];i;i=vs[i].next)
{
if(vs[i].v==pr) continue;
cnt+=dfs(vs[i].v,rt);
}
if(cnt>1) fg=1;
if(cnt==1) ret=0;
return ret;
}
int main()
{
n=read();
for(int i=1;i<n;i++)
{
int u=read(), v=read();
addedge(u,v); addedge(v,u);
}
int x=dfs(1,0); if(x) fg=1;
if(fg) cout << "First" << endl;
else cout << "Second" << endl;
} | 1 | 82,240,996 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) begin(v),end(v)
using ll = long long;
int main() {
int n;cin>>n;
vector<int> a(n),vec(n);
rep(i,n){
cin>>a[i];
vec[i]=i+1;
}
bool ok=false;
int x=0;
rep(i,n){
if(a[i]==vec[x]){
ok=true;
x++;
}
}
if(ok)cout<<n-x<<endl;
else cout<<-1<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int MOD=1000000007;
const int N=100010;
void solve(){
int n;
cin>>n;
ll ans=0,req=1;
for(int i=0;i<n;i++){
ll x;
cin>>x;
if(x==req){
req++;
} else {
ans++;
}
}
if(req==1) cout<<"-1\n";
else cout<<ans<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long int t = 1;
for (long int tt = 1; tt <= t; tt++) {
solve();
}
return 0;
} | 1 | 89,260,754 |
#include<iostream>
using namespace std;
void hoge(){
int i,j;
for(i=1;i<=9;i++){
for(j=1;j<=9;j++){
cout<<i<<"x"<<j<<"="<<i*j<<endl;
}
}
}
int main(){
hoge();
return 0;
} | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
const int MAX= 10000100;
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}
int main(void){
loop(i,1,10)loop(j,1,10)cout<<i<<"x"<<j<<"="<<i*j<<endl;
} | 1 | 1,514,507 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;
const int MOD = 1000000007;
typedef pair<int,int> P;
int gcd(int a,int b){
if (a%b == 0){
return b;
}
else{
return gcd(b,a%b);
}
}
int lcm(int a,int b){
return a /gcd(a,b) * b;
}
int main() {
int n,r;
cin >> n >> r ;
if (n < 10) cout << r + (100*(10-n)) << endl;
else cout << r << endl;
} | #include <iostream>
int n, r;
int main() {
std::cin >> n >> r;
if (n < 10) {
std::cout << r + (100 * (10 - n));
} else {
std::cout << r;
}
} | 1 | 36,189,624 |
#include<bits/stdc++.h>
using namespace std;
#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
int main()
{
int n, m;
cin >> n >> m;
vector<string> gri(n);
for(int i=0; i<n; i++){
cin >> gri[i];
}
int xx[] = {1, -1, 0, 0};
int yy[] = {0, 0, 1, -1};
queue<pi> qu;
int dis[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(gri[i][j] == '#'){
qu.push({i, j});
dis[i][j] = 0;
}
}
}
while(!qu.empty()){
pi u = qu.front();
qu.pop();
int x = u.first;
int y = u.second;
for(int i=0; i<4; i++){
int gx = x+xx[i];
int gy = y+yy[i];
if(gx<n && gx>=0 && gy>=0 && gy<m && gri[gx][gy] == '.'){
dis[gx][gy] = dis[x][y]+1;
gri[gx][gy] = '#';
qu.push({gx, gy});
}
}
}
int mx = 0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
mx = max(mx, dis[i][j]);
}
}
cout << mx << "\n";
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main()
{
long long H;
scanf("%lld", &H);
long long W;
scanf("%lld", &W);
std::vector<std::string> A(H);
for (int i = 0; i < H; i++)
{
std::cin >> A[i];
}
queue<pair<int, int>> q;
int seen[1001][1001] = {};
for (int i = 0; i < H; ++i)
{
for (int j = 0; j < W; ++j)
{
seen[i][j] = INF;
if (A[i][j] == '#')
{
q.emplace(j, i);
seen[i][j] = 0;
}
}
}
int ans = 0;
while (!q.empty())
{
auto p = q.front();
q.pop();
for (int i = 0; i < 4; ++i)
{
int x = p.first, y = p.second;
int nx = x + dx[i], ny = y + dy[i];
if (0 <= nx && nx < W && 0 <= ny && ny < H && seen[ny][nx] == INF)
{
q.emplace(nx, ny);
seen[ny][nx] = seen[y][x] + 1;
ans = seen[ny][nx];
}
}
}
cout << ans << endl;
return 0;
} | 1 | 36,500,862 |