code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 45
101M
|
---|---|---|---|
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
const vi tbl = {1, 1, 2, 6, 24, 120, 720, 5040};
int main(void){
int n;
cin >> n;
vi P(n), Q(n);
for(int &p : P) cin >> p;
for(int &q : Q) cin >> q;
int p = 0, q = 0;
for(int i=0; i<n-1; i++){
p += (P[i]-1)*tbl[n-1-i];
q += (Q[i]-1)*tbl[n-1-i];
for(int j=i+1; j<n; j++){
if(P[j]>P[i]) P[j]--;
if(Q[j]>Q[i]) Q[j]--;
}
}
cout << (p>q?p-q:q-p) << '\n';
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
void Main() {
int N;
cin >> N;
vector<int> P(N, 0), Q(N, 0);
for (int i = 0; i < N; ++i) {
cin >> P[i];
}
for (int i = 0; i < N; ++i) {
cin >> Q[i];
}
vector<int> X;
for (int i = 1; i <= N; ++i) {
X.push_back(i);
}
int counter = 0;
int np = -1;
int nq = -1;
do {
int diffp = 0;
int diffq = 0;
for (int i = 0; i < N; ++i) {
diffp += abs(X[i] - P[i]);
diffq += abs(X[i] - Q[i]);
}
if (diffp == 0) {
np = counter;
}
if (diffq == 0) {
nq = counter;
}
++counter;
if (np >= 0 && nq >= 0) {
break;
}
} while (next_permutation(X.begin(), X.end()));
cout << abs(np - nq) << endl;
}
int main() {
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| 1 | 87,003,072 |
#include <bits/stdc++.h>
using namespace std;
vector<int> tsort_Kahn(const vector<vector<int>>& g) {
const int V = g.size();
vector<int> indeg(V,0);
stack<int> S;
for(auto& u_out_edges : g)
for(auto& v : u_out_edges)
indeg[v]++;
for(int i=0; i<V; ++i)
if( indeg[i] == 0 )
S.push(i);
vector<int> ans;
while( S.size() > 0 ) {
int u = S.top(); S.pop();
ans.emplace_back(u);
for(auto& v : g[u]) {
indeg[v]--;
if( indeg[v] == 0 ) S.push(v);
}
}
return ans;
}
int main () {
int V,E;
cin >> V >> E;
vector<vector<int>> g(V);
for (int i=0; i<E; ++i) {
int s,t;
cin >> s >> t;
g[s].emplace_back(t);
}
vector<int> ans = tsort_Kahn(g);
for(auto& e : ans) {
cout << e << endl;
}
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>
#include <vector>
#include <list>
using namespace std;
static const int MAX = 10000;
static const bool DEBUG = false;
vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];
void bfs(int s) {
queue<int> q;
q.push(s);
V[s] = true;
if (DEBUG == true) {
cout << "in BFS 1" << endl;
cout << "V[i]:" << endl;
for (int i = 0; i < N; i++) {
cout << V[i] << " ";
}
cout << endl;
cout << "indeg[i]:" << endl;
for (int i = 0; i < N; i++) {
cout << indeg[i] << " ";
}
cout << endl;
}
while (!q.empty()) {
int u = q.front(); q.pop();
out.push_back(u);
for (unsigned int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
indeg[v]--;
if (indeg[v] == 0) {
V[v] = true;
q.push(v);
if (DEBUG == true) {
cout << "in BFS 2" << endl;
cout << "V[i]:" << endl;
for (int i = 0; i < N; i++) {
cout << V[i] << " ";
}
cout << endl;
cout << "indeg[i]:" << endl;
for (int i = 0; i < N; i++) {
cout << indeg[i] << " ";
}
cout << endl;
}
}
}
}
}
void tsort() {
for (int i = 0; i < N; i++) {
indeg[i] = 0;
}
for (int u = 0; u < N; u++) {
for (unsigned int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
indeg[v]++;
}
}
if (DEBUG == true) {
cout << "V[i]: ";
for (int i = 0; i < N; i++) {
cout << V[i] << " ";
}
cout << endl;
cout << "indeg[i]: ";
for (int i = 0; i < N; i++) {
cout << indeg[i] << " ";
}
cout << endl;
}
for (int u = 0; u < N; u++) {
if (indeg[u] == 0 && !V[u]) {
bfs(u);
}
}
for (list<int>::iterator it = out.begin(); it != out.end(); it++) {
cout << *it << endl;
}
}
int main() {
int s, t, M;
cin >> N >> M;
for (int i = 0; i < N; i++) V[i] = false;
for (int i = 0; i < M; i++) {
cin >> s >> t;
G[s].push_back(t);
}
tsort();
return 0;
}
| 1 | 51,761,851 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int AA=0;
int BB=0;
string S;
cin>>S;
vector<char>A(S.size());
for(int X=0;X<S.size();X++){
if(X%2==0){
A.at(X)='1';
}
else{
A.at(X)='0';
}
}
for(int X=0;X<S.size();X++){
if(S.at(X)==A.at(X)){
AA++;
}
else{
BB++;
}
}
if(AA>=BB){
cout<<BB<<endl;
}
else{
cout<<AA<<endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define mp make_pair
#define all(vv) (vv).begin(), (vv).end()
#define rep(ii, jj, ll, ss) for(int ii = jj; ii < ll; ii += ss)
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0;
string s;
int ans;
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> s;
ans = 0;
char pre = s[0];
cerr << pre << '\n';
rep(i, 1, (int)s.length(), 1) {
if (s[i] == pre) {
++ans;
if (s[i] == '0') s[i] = '1';
else s[i] = '0';
}
pre = s[i];
}
cout << ans;
}
| 1 | 85,736,220 |
#include<iostream>
using namespace std;
long long MOD=1000000007;
int main(){
long long N,M;
cin >> N >> M;
long long S[N+1], T[M+1];
long long i,j;
for(i=1; i<=N; i++){
cin >> S[i];
}
for(j=1; j<=M; j++){
cin >> T[j];
}
long long sum[N+1][M+1];
for(i=0; i<=N; i++){
sum[i][0]=1;
}
for(j=0; j<=M; j++){
sum[0][j]=1;
}
for(i=1; i<=N; i++){
for(j=1; j<=M; j++){
if(S[i]==T[j]){
sum[i][j]=sum[i-1][j]+sum[i][j-1];
sum[i][j]%=MOD;
}else{
sum[i][j]=sum[i-1][j]+sum[i][j-1]+MOD-sum[i-1][j-1];
sum[i][j]%=MOD;
}
}
}
cout << sum[N][M] << endl;
system("pause");
return 0;
}
|
#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
#define INF 1e9+5
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=1e9+7;
const ll MAX=1000005;
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 vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
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;}
ll dp[2005][2005];
int main(){
int n,m;
cin>>n>>m;
vi s(n+1),t(m);
rep(i,n)cin>>s[i];
rep(i,m)cin>>t[i];
rep(i,n+1)dp[i][0]=1;
rep(i,m+1)dp[0][i]=1;
rep(i,n){
rep(j,m){
dp[i+1][j+1]+=dp[i+1][j]+dp[i][j+1]-dp[i][j];
dp[i+1][j+1]%=mod;
if(s[i]==t[j]){
dp[i+1][j+1]+=dp[i][j];
dp[i+1][j+1]%=mod;
}
}
}
if(dp[n][m]<0)dp[n][m]+=mod;
cout<<dp[n][m]<<endl;
return 0;
}
| 1 | 53,369,287 |
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
typedef long long ll;
int main(){
string s, t;
cin >> s >> t;
int ans = 0;
for(int i = 0; i < s.length(); ++i){
if(s[i] == t[i]){
ans++;
}
}
cout << ans << "\n";
}
|
#include <iostream>
#include <string>
using namespace std;
int main (void){
int cnt = 0;
string s, t;
cin >> s >> t;
for(int i = 0; i < s.length(); i++){
if(s[i] == t[i]){
cnt++;
}else{
}
}
cout << cnt << endl;
return 0;
}
| 1 | 75,706,558 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
string A, B, C;
cin >> A >> B >> C;
if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0])
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
string a,b,c;
cin >> a >> b >> c;
if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
cout << "YES" << "\n";
}else{
cout << "NO"<< "\n";
}
}
| 1 | 39,893,375 |
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;
int main() {
int n;
cin >> n;
int d[n];
int sum = 0;
rep(i, n) {
cin >> d[i];
sum += d[i];
}
int ans = 0;
rep(i, n) { ans += (sum - d[i]) * d[i]; }
cout << ans / 2 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> V(N);
for (int i = 0; i < N; i++)
cin >> V.at(i);
int count = 0;
for (int j = 0; j < N; j++) {
for (int k = j + 1; k < N; k++)
count += V.at(j)*V.at(k);
}
cout << count << endl;
}
| 1 | 97,664,086 |
#include <iostream>
using namespace std;
struct card{
char suit;
int value;
};
void selection(struct card a[], int n){
for (int i=0; i<n; i++){
int minj=i;
for (int j=i; j<n; j++){
if (a[j].value <a[minj].value){
minj=j;
}
}
swap(a[i],a[minj]);
}
}
void bubble(struct card a[],int n){
for (int i=1;i<n; i++){
for (int j=n-1; j>=i; j--){
if (a[j].value <a[j-1].value){
swap(a[j],a[j-1]);
}
}
}
}
void print (struct card a[], int n){
for (int i=0; i<n-1; i++){
cout <<a[i].suit <<a[i].value <<" " ;
}
cout << a[n-1].suit <<a[n-1].value<<endl;
}
bool isStable(struct card c1[], struct card c2[], int n){
for (int i=0; i<n; i++){
if (c1[i].suit != c2[i].suit){
return false;
}
}
return true;
}
int main(){
int n;
cin >>n;
struct card c1[n],c2[n];
for (int i=0; i<n; i++){
cin >> c1[i].suit >> c1[i].value ;
}
for (int i=0; i<n; i++){
c2[i]=c1[i];
}
bubble(c1,n);
print(c1,n);
cout << "Stable" <<endl;
selection(c2,n);
print(c2,n);
if (isStable(c1,c2,n)){
cout <<"Stable" <<endl;
}
else {
cout << "Not stable" <<endl;
}
}
|
#include <iostream>
#include <string>
#include <cmath>
#include<iomanip>
#include<algorithm>
#include<list>
using namespace std;
int main()
{
int n;
string a[101], b[101];
cin >> n;
for (int i = 0; i < n; i++){
cin >> a[i];
b[i] = a[i];
}
for (int i = 0; i < n; i++){
for (int j = n - 1; j > i; j--){
if (a[j][1] < a[j - 1][1]){
string tmp = a[j];
a[j] = a[j - 1];
a[j - 1] = tmp;
}
}
}
for (int i = 0; i < n; i++){
if (i < n - 1){
cout << a[i] << " ";
}
else{
cout << a[i] << endl<<"Stable"<<endl;
}
}
for (int i = 0; i < n; i++){
int minj = i;
for (int j = i; j < n; j++){
if (b[j][1] < b[minj][1]){
minj = j;
}
}
string tmp = b[i];
b[i] = b[minj];
b[minj] = tmp;
}
for (int i = 0; i < n; i++){
if (i < n - 1){
cout <<b[i] << " ";
}
else{
cout << b[i] << endl;
}
}
bool flag = true;
for (int i = 0; i < n; i++){
if (a[i] != b[i]){
flag = false;
}
}
if (flag){
cout << "Stable" << endl;
}
else{
cout << "Not stable" << endl;
}
return 0;
}
| 1 | 38,388,996 |
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<limits.h>
using namespace std;
static const int n=1000;
static const int m=1000;
int lcs(string X,string Y){
int i,j,c[m+1][n+1];
int m=X.size();
int n=Y.size();
for (i=0;i<m+1;i++) c[i][0]=i;
for (j=0;j<n+1;j++) c[0][j]=j;
for (i=1;i<m+1;i++){
for (j=1;j<n+1;j++){
int min=c[i-1][j]+1;
if (min>c[i][j-1]+1)
min=c[i][j-1]+1;
if ((X[i-1]==Y[j-1])&&(min>c[i-1][j-1]+1))
min=c[i-1][j-1]+1;
c[i][j]=min;
}
}
return m+n-c[m][n];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
string s1,s2;
int m,i; cin >> m;
for (i=0;i<m;i++){
cin >> s1 >> s2;
cout << lcs(s1,s2) << endl;
}
return 0;
}
|
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <time.h>
using namespace std;
void solve(){
time_t start, end;
string A;
cin >> A;
string B;
cin >> B;
int n = A.size(), m = B.size();
vector<vector<int>> DP(n + 1, vector<int>(m + 1, 0));
start = clock();
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (A[i - 1] == B[j - 1]) DP[i][j] = DP[i - 1][j - 1] + 1;
else DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
}
}
end = clock();
cout << DP[n][m] << endl;
}
int main(){
int n;
cin >> n;
for (int i = 0; i < n; i++){
solve();
}
}
| 1 | 87,489,219 |
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#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;
#define PB push_back
#define endl '\n'
#define S second
#define F first
int main()
{
faster();
string s;
string ans;
cin>>s;
int len=s.size();
ans=s;
reverse(all(ans));
int c=0;
if(s==ans)c++;
int n=((len-1)/2);
string ck,ck1;
ck="";
for(int i=0; i<n; i++)
ck+=s[i];
ck1=ck;
reverse(all(ck1));
if(ck1==ck)c++;
string cmp,cmp1;
cmp="";
int m=(len+3)/2;
for(int i=m-1; i<len; i++)
cmp+=s[i];
cmp1=cmp;
reverse(all(cmp1));
if(cmp1==cmp)c++;
if(c==3)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
for (int i = 0; i < (S.size() - 1)/2; i++) {
if (S.at(i) != S.at(S.size() - i - 1)) {
cout << "No" << endl;
return 0;
}
}
for (int i = 0; i < (S.size() - 1)/2; i++) {
if (S.at(i) != S.at((S.size()-1)/2 - i - 1)) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
| 1 | 40,077,742 |
#include <iostream>
using namespace std;
int main(){
int n,a,b,c,x;
while(cin>>n>>a>>b>>c>>x){
if(n==0) break;
int y[n];
for(int i=0;i<n;i++){
cin>>y[i];
}
int k=0;
for(int i=0;i<=10000;i++){
if(y[k]==x){
k++;
}
if(k==n){
cout<<i<<endl;
break;
}
x=(a*x+b)%c;
}
if(k<n){
cout<<-1<<endl;
}
}
return 0;
}
|
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <functional>
using namespace std;
int INF = 10000000;
int main()
{
int n,a,b,c,x;
while(cin >> n >> a >> b >> c >> x && ( n || a || b || c || x))
{
int y[101];
for(int i = 0;i < n;i++)
{
cin >> y[i];
}
bool f[101];
memset(f,0,101*sizeof(bool));
bool flag = false;
int out = 0;
int Min = 0;
for(int i = 0;i <= 10000;i++)
{
if(x == y[Min])
{
f[Min++] = true;
if(Min == n){flag = true;out = i;break;}
}
int temp = (a * x + b) % c;
x = temp;
}
if(flag)cout << out << endl;
else cout << -1 << endl;
}
return 0;
}
| 1 | 5,338,411 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
string s;
int N;
cin >> N >> s;
int count = 1;
char now_s = s[0];
for(int i=1;i<N;i++){
if(s[i] != now_s){
now_s = s[i];
count++;
}
}
cout << count << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
#define DBG(a,b,c,d)
int main(){
IO_STREAM;
int N; cin>>N;
string S; cin>>S;
int ans=1;
rep(i,0,N-1){
if(S[i]!=S[i+1]) ans++;
}
cout<<ans<<endl;
return 0;
}
| 1 | 95,859,106 |
#include <bits/stdc++.h>
using namespace std;
int main(){
char a;
cin >> a;
string big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string sml = "abcdefghijklmnopqrstuvwxyz";
for(int i = 0; i < 26; i++){
if(big[i] == a){
cout << "A" << endl;
break;
}else if(sml[i] == a){
cout << "a" << endl;
break;
}
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pii pair <int,int>
ll m=1000000007;
int main()
{
fast;
char x;cin>>x;
if(x-'a'>=0)
cout<<"a";
else
cout<<"A";
cout<<nl;
}
| 1 | 25,027,148 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
int main(){
int k;
cin >> k;
vector<ll> a(k);
rep(i,k)cin >> a[i];
ll pre = a.back();
for(int i = k-2;i >= 0;i--)pre = (pre+a[i]-1)/a[i]*a[i];
if(pre == 1){
cout << 2 << " " << 2 << endl;
return 0;
}
{
ll l = pre;
rep(i,k)l = l/a[i]*a[i];
if(l != 2){
cout << -1 << endl;
return 0;
}
}
ll left = pre,right = 1ll << 60;
while(right-left > 1){
ll mid = (right+left)/2;
ll l = mid;
rep(i,k)l = l/a[i]*a[i];
if(l == 2)left = mid;
else right = mid;
}
cout << pre << " " << right-1 << endl;
return 0;
}
|
#include<iostream>
using namespace std;
long long x=2,y=2;
int n,ans[100010];
int main()
{
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>ans[i];
}
for(int i=n; i>=1; i--)
{
x=((x-1)/ans[i]+1)*ans[i];
y=y/ans[i]*ans[i]+ans[i]-1;
}
if(x>y)
{
cout<<-1;
}
else
{
cout<<x<<" "<<y;
}
return 0;
}
| 1 | 4,353,047 |
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 18;
int sum[MAXN+1][1<<MAXN];
int boro[MAXN+1][1<<MAXN];
int main() {
int n;
cin >> n;
for (int i = 0; i < (1<<n); i++) {
cin >> boro[0][i];
sum[0][i] = -1;
}
for (int p = 1; p <= n; p++) {
for (int msk = 0; msk < (1<<n); msk++) {
boro[p][msk] = boro[p-1][msk];
sum[p][msk] = sum[p-1][msk];
if (msk&(1<<(p-1))) {
boro[p][msk] = max(boro[p][msk], boro[p-1][msk^(1<<(p-1))]);
sum[p][msk] = max(sum[p][msk], boro[p-1][msk]+boro[p-1][msk^(1<<(p-1))]);
}
}
}
int mx = -1;
for (int i = 1; i < (1<<n); i++) {
mx = max(mx, sum[n][i]);
cout << mx << "\n";
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
int main()
{
int n;
cin >> n;
int a[300000] {0};
for(int i = 0; i < (1 << n); i++) cin >> a[i];
int fir[300000];
int sec[300000];
bool looked[300000];
for(int i = 0; i < (1 << n); i++) fir[i] = i;
fill(sec, sec + n, (1 << n));
fill(looked, looked + n, false);
queue<int> que;
fir[0] = 0;
looked[0] = true;
que.push(0);
while(que.size()){
int now = que.front();
que.pop();
for(int i = 0; i < n; i++){
int next = (now | (1 << i));
if(next == now) continue;
if(!looked[next]){
looked[next] = true;
que.push(next);
}
if(fir[now] == fir[next]){
if(a[sec[next]] < a[sec[now]]) sec[next] = sec[now];
}
else if(a[fir[next]] < a[fir[now]]){
if(a[fir[next]] < a[sec[now]]) sec[next] = sec[now], fir[next] = fir[now];
else sec[next] = fir[next], fir[next] = fir[now];
}
else{
if(a[sec[next]] < a[fir[now]]) sec[next] = fir[now];
}
}
}
for(int k = 1; k < (1 << n); k++){
int ans = a[fir[k]] + a[sec[k]];
int now = 0;
for(int i = n - 1; i >= 0; i--){
if(k & (1 << i)){
ans = max(ans, a[fir[now + (1 << i) - 1]] + a[sec[now + (1 << i) - 1]]);
now |= (1 << i);
}
}
cout << ans << endl;
}
}
| 1 | 51,112,419 |
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main(void)
{
int i,is,ip;
string s,p,sp,ans="No";
cin >> s;
cin >> p;
ip = p.size();
is = s.size();
sp = s + s.substr(0,ip-1);
for(i = 0; i <= is-1; i++){
if(p == sp.substr(i,ip))
ans="Yes";
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
#include<sstream>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){ _;
string s,p;
cin>>s>>p;
stringstream ss;
ss<<s<<s;
if(strstr(ss.str().c_str(),p.c_str()))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
| 1 | 24,199,557 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
string s, t;
cin >> N >> s >> t;
int ans = N * 2;
for( int i = 0; i < N; i++ ) {
string sub = s.substr( i, N - i );
if( sub == t.substr( 0, N - i ) ) {
ans = i + N;
break;
}
}
cout << ans << endl;
}
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using Pii = pair<int, int>;
using Pil = pair<int, ll>;
using Pll = pair<ll, ll>;
using Pid = pair<int, ld>;
using Pis = pair<int, string>;
#define rep(i,n) for(int i=0; i<n; i++)
#define repm(i,s,n) for(int i=s; i<n; i++)
const int INF = 1 << 30;
const ll INF_L = 1LL << 60;
const int MOD = 1e9+7;
int ctoi(char c){
if(isdigit(c)) return c - '0';
else if(islower(c)) return c - 'a';
else if(isupper(c)) return c - 'A';
else return -1;
}
char itocd(int i){char c = i+'0'; if(isdigit(c)) return c; else return 0x00;}
char itocl(int i){char c = i+'a'; if(islower(c)) return c; else return 0x00;}
char itocu(int i){char c = i+'A'; if(isupper(c)) return c; else return 0x00;}
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; }
vector<vector<int>> adjMat;
vector<set<Pii>> adjList;
void Dijkstra(){}
void BellmanFord(){}
void WarshallFloyd(){}
ll gcd(ll A, ll B) {if (A%B == 0) {return(B);} else {return(gcd(B, A%B));}}
ll lcm(ll A, ll B) {return A * B / gcd(A, B);}
ll divtimes(ll N, ll D) {ll res = 0; while(N%D == 0) {N/=D; res++;} return res;}
ll powMod(ll B, ll P) {
if(P == 0) return 1;
if(P%2 == 0){ll t = powMod(B, P/2); return t*t % MOD;}
return B * powMod(B, P-1) % MOD;
}
const int FAC_INIT_SIZE = 1e6+9;
vector<ll> fac, finv, inv;
void factModInit() {
fac.resize(FAC_INIT_SIZE);
finv.resize(FAC_INIT_SIZE);
inv.resize(FAC_INIT_SIZE);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i=2; i < FAC_INIT_SIZE; i++){
fac[i] = fac[i-1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i-1] * inv[i] % MOD;
}
}
ll factMod(ll N){return fac[N] % MOD;}
ll factInvMod(ll N){return finv[N] % MOD;}
ll permMod(ll N, ll K){
if (N < 0 || K < 0 || N < K) return 0;
else return factMod(N) * factInvMod(N-K) % MOD;
}
ll combMod(ll N, ll K){
if (N < 0 || K < 0 || N < K) return 0;
else if (N < FAC_INIT_SIZE){ return factMod(N) * (factInvMod(K) * factInvMod(N-K) % MOD) % MOD;}
else {
ll ans = 1; ll Ks = K < N-K ? K : N-K;
for (ll i=N; i > N-Ks; i--) {ans *= i; ans %= MOD;}
return ans * factInvMod(Ks) % MOD;
}
}
vector<bool> isprime;
void sieveInit(int size){
int sb = size + 9;
isprime.resize(sb);
isprime[0] = isprime[1] = false;
isprime[2] = true;
for(int i=2; i<sb; i++) {
if(i%2 == 0) isprime[i] = false;
else isprime[i] = true;
}
for(int i=3; i*i<=sb; i+=2){
if(isprime[i]){
int m = 3*i;
while(m < sb){isprime[m] = false; m += 2*i;}
} else {
continue;
}
}
}
int main() {
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
string s, t; cin >> s >> t;
int res = 2*N, cnt = 0;
repm(i, 0, N) {if(s.substr(N-1-i, i+1) == t.substr(0, i+1)) chmax(cnt, i+1);}
cout << res - cnt << endl;
}
| 1 | 85,082,030 |
#include<iostream>
using namespace std;
int main(){
int x;cin>>x;
if(x>=400&&x<=599)
cout<<8;
else if(x>=600&&x<=799)
cout<<7;
else if(x>=800&&x<=999)
cout<<6;
else if(x>=1000&&x<=1199)
cout<<5;
else if(x>=1200&&x<=1399)
cout<<4;
else if(x>=1400&&x<=1599)
cout<<3;
else if(x>=1600&&x<=1799)
cout<<2;
else if(x>=1800&&x<=1999)
cout<<1;
}
|
#include<iostream>
using namespace std;
int main(){
int a;
cin >> a;
if(400<=a && a<=599){
cout << 8 << endl;
}else if(600<=a && a<=799){
cout << 7 << endl;
}else if(800<=a && a<=999){
cout << 6 << endl;
}else if(1000<=a && a<=1199){
cout << 5 << endl;
}else if(1200<=a && a<=1399){
cout << 4 << endl;
}else if(1400<=a && a<=1599){
cout << 3 << endl;
}else if(1600<=a && a<=1799){
cout << 2 << endl;
}else if(1800<=a && a<=1999){
cout << 1 << endl;
}
}
| 1 | 44,817,801 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>
using namespace std;
#define endl '\n'
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> adj(n);
for (int i = 0; i < m; ++i)
{
int u, v;
cin >> u >> v;
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<int> col(n);
vector<int> vis(n);
long long bip = 0, one = 0, oth = 0;
bool ok;
function<void(int)> is_bipartite = [&](int u) {
vis[u] = 1;
for (auto v : adj[u])
{
if (vis[v])
{
if (col[u] == col[v])
ok = false;
}
else
{
col[v] = col[u] ^ 1;
is_bipartite(v);
}
}
};
for (int i = 0; i < n; ++i)
{
if (vis[i])
continue;
if (adj[i].empty())
{
one++;
continue;
}
ok = true;
is_bipartite(i);
if (ok)
{
bip++;
}
else
{
oth++;
}
}
long long answer = 2 * n * one - one * one;
answer += (bip + oth) * (bip + oth) + bip * bip;
cout << answer << endl;
return 0;
}
|
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=1e5+10;
const int maxm=2e5+10;
struct node{int to,nxt;}e[maxm<<1];
int tot,p,c,d,flag,head[maxn],deg[maxn],vis[maxn],col[maxn];
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;
}
void print(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)print(x/10);
putchar(x%10+'0');
}
void write(ll x){print(x);puts("");}
void add(int u,int v){e[++tot].to=v;e[tot].nxt=head[u];head[u]=tot;deg[u]++;}
void insert(int u,int v){add(u,v);add(v,u);}
void dfs(int x){
vis[x]=1;
for(int i=head[x],v=e[i].to;i;i=e[i].nxt,v=e[i].to){
if(!vis[v])col[v]=col[x]^1,dfs(v);
else if(col[v]^col[x]^1)c-=flag,d+=flag,flag=0;
}
}
int main(){
int n=read(),m=read();
for(int i=1;i<=m;i++)insert(read(),read());
for(int i=1;i<=n;i++){
if(!deg[i])p++;
else if(!vis[i])flag=1,c++,dfs(i);
}write(1ll*p*n+1ll*p*(n-p)+1ll*d*d+1ll*c*2*(d+c));
return 0;
}
| 1 | 39,878,215 |
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
using namespace std;
void printCoffo(double x1, double y1, double x5, double y5, int n){
if(n<=0){
return;
}
double x2,y2,x3,y3,x4,y4;
x2 = (2.0*x1+x5)/3.0;
y2 = (2.0*y1+y5)/3.0;
x4 = (x1+2.0*x5)/3.0;
y4 = (y1+2.0*y5)/3.0;
x3 = x2 + (x4-x2)/2.0 - sqrt(3.0)*(y4-y2)/2.0;
y3 = y2 + sqrt(3.0)*(x4-x2)/2.0 + (y4-y2)/2.0;
printCoffo(x1, y1, x2, y2, n-1);
cout << x2 << " " << y2 <<endl;
printCoffo(x2, y2, x3, y3, n-1);
cout << x3 << " " << y3 << endl;
printCoffo(x3, y3, x4, y4, n-1);
cout << x4 << " " << y4 << endl;
printCoffo(x4, y4, x5, y5, n-1);
}
int main(){
int n;
cin >> n;
double x1,y1,x2,y2;
x1 = 0.0;
y1 = 0.0;
x2 = 100.0;
y2 = 0.0;
cout << x1 << " " << y1 << endl;
printCoffo(x1, y1, x2, y2, n);
cout << x2 << " " << y2 << endl;
}
|
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iomanip>
typedef std::pair<double, double> point;
point hoge(point q2, point q4){
point q3;
point r = std::make_pair((q2.first + q4.first)/2, (q2.second + q4.second)/2);
point vec = std::make_pair(-(q4.second - q2.second), q4.first - q2.first);
q3 = std::make_pair(r.first + vec.first * sqrt(3)/2, r.second + vec.second * sqrt(3)/2);
return q3;
}
void kochCurve(point p1, point p2, int i, int n){
if(i == n){
std::cout << std::setprecision(8) << p1.first << " " << p1.second << std::endl;
return;
}
if(i > n){
std::cout << "something wrong";
return;
}
point q1 = std::make_pair(p1.first, p1.second);
point q2 = std::make_pair(p1.first * 2/3 + p2.first * 1/3, p1.second * 2/3 + p2.second * 1/3);
kochCurve(q1, q2, i + 1, n);
point q4 = std::make_pair(p1.first * 1/3 + p2.first * 2/3, p1.second * 1/3 + p2.second * 2/3);
point q3 = hoge(q2, q4);
kochCurve(q2, q3, i + 1, n);
kochCurve(q3, q4, i + 1, n);
kochCurve(q4, p2, i + 1, n);
}
int main(){
int n;
scanf("%d", &n);
int i = 0;
std::cout << std::fixed;
point start = std::make_pair(0.0, 0.0);
point end = std::make_pair(100.0, 0.0);
kochCurve(start, end, i, n);
std::cout << end.first << " " << end.second << std::endl;
return 0;
}
| 1 | 28,518,750 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
ll X,Y,A,B,C; cin>>X>>Y>>A>>B>>C; vector<ll> hoge={A,B,C};
vector<vector<ll>> vec(3,vector<ll>(0));
rep(i,3) rep(j,hoge[i]) {ll piyo; cin>>piyo; vec.at(i).push_back(piyo);}
for(auto &svec:vec) sort(svec.rbegin(),svec.rend());
vector<ll> next={0,0,0};
ll ans=0;
rep(i,X+Y){
ll sans=0,sep=-1;
rep(j,3){
if(j==0&&(next[0]>=X||next[0]>=A)) continue;
if(j==1&&(next[1]>=Y||next[1]>=B)) continue;
if(j==2&&next[2]>=C) continue;
if(chmax(sans,vec[j][next[j]])) sep=j;
}
ans+=sans; next[sep]++;
}
cout<<ans<<endl;
return 0;
}
|
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int x,y,a,b,c;
int i,j,k;
scanf("%d %d %d %d %d",&x,&y,&a,&b,&c);
long long p[a],q[b],r[c],res[x+y+x+y];
for(i = 0;i < 2*x + 2*y ;i++)
res[i] = 0;
i = 0;
while(i < a)
scanf("%lld",&p[i++]);
sort(p,p+a);
j = a-1;
for(k = 0;k < x;k++)
res[k] = p[j--];
i = 0;
while(i < b)
scanf("%lld",&q[i++]);
sort(q,q+b);
j = b-1;
int e = k + y;
for(k;k < e;k++)
res[k] = q[j--];
i = 0;
while(i < c)
scanf("%lld",&r[i++]);
sort(r,r+c);
int f = k + x + y;
j = c - 1;
for(k;k < f && j >= 0;k++)
res[k] = r[j--];
sort(res,res+2*x+2*y,greater<int>());
for(i = 1;i<x+y;i++)
res[i] += res[i-1];
printf("%lld",res[x+y-1]);
return 0;
}
| 1 | 97,583,863 |
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
int n, i, sum = 100000, count;
cin >> n;
for(i = 0;i < n;i++){
sum = sum * 1.05;
if(sum % 1000 != 0){
sum = sum / 1000;
sum = sum + 1;
sum = sum * 1000;
}
}
cout << sum << endl;
return 0;
}
|
#include<stdio.h>
int main(){
int i,n;
int sum = 100000;
scanf("%d", &n);
for(i=0;i<n;i++){
sum=sum*1.05;
if(sum%1000!=0)
{
sum=sum/1000;
sum=(sum+1)*1000;
}
}
printf("%d\n", sum);
return 0;
}
| 1 | 14,817,403 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
int main() {
ll s;
cin >> s;
int y2 = (s+1000000000-1)/1000000000;
int y1 = 1000000000*y2-s;
cout << "0 0 " << 1000000000 << " " << y1 << " "<< 1 << " " << y2 << " " << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef pair <ll ,ll> pll;
typedef pair <int ,int> pii;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define print(a) {for (auto iiiiiiiiii : a) cout << iiiiiiiiii << ' '; cout << '\n';}
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
ll next() {ll x; cin >> x; return x;}
const ll inf = 1e18 , mod = 998244353;
const int intf = 2e9 , maxn = 1e5;
const double PI = 3.141592653589 , eps = 1e-8;
void solve(){
ll s; cin >> s;
ll k = sqrt(s);
if (k*k != s) k++;
ll d = k*k - s;
vector <ll> ans = {0 , 0 , k , 1 , d , k};
print(ans);
}
int main()
{
#ifdef HERE
freopen("input.txt" , "r" , stdin);
#else
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#endif
cout.precision(20);
int t = 1;
while(t --> 0){
solve();
}
#ifdef HERE
cout << setprecision(3) << fixed << "\n\nRuntime: " << (long double)(clock()) / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| 1 | 40,975,042 |
#include <bits/stdc++.h>
using namespace std;
#define vt vector
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;
void solve() {
int n;
string s;
cin >> n >> s;
cout << (~n & 1 && s.substr(0, n / 2) == s.substr(n / 2) ?
"Yes" : "No");
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int tcs = 1;
for (int tc = 1; tc <= tcs; tc++) {
solve();
}
}
|
#include <stdio.h>
int main(){
int N;
char S[N];
scanf("%d", &N);
scanf("%s", S);
int yes = 0, no = 0;
if(N % 2 == 0){
for(int i = 0; i < (N / 2); i++){
if(S[i] == S[i + (N / 2)]){
yes++;
}else{
no++;
}
}
if(yes == N / 2){
printf("Yes");
}else{
printf("No");
}
}else{
printf("No");
}
return 0;
}
| 1 | 84,634,296 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int main() {
int a,b,c,d,n,count=0;
while(cin>>n){
if(n>36){
cout<<0<<endl;
}
else{
for(a=0;a<10;a++){
for(b=0;b<10;b++){
for(c=0;c<10;c++){
for(d=0;d<10;d++){
if(a+b+c+d==n){
count++;
}
}
}
}
}
cout<<count<<endl;
}
count=0;
}
}
|
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(void) {
int n;
while (cin >> n) {
int ans = 0;
for (int a = 0; a < 10; a++) {
for (int b = 0; b < 10; b++) {
for (int c = 0; c < 10; c++) {
for (int d = 0; d < 10; d++) {
if (a + b + c + d == n) ans++;
}
}
}
}
cout << ans << endl;
}
return 0;
}
| 1 | 61,166,267 |
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;
int main() {
ll m, k;
cin >> m >> k;
if(k >= (1 << m)) {
cout << -1 << endl;
return 0;
}
if(k == 0) {
for(int i = 0; i < (1 << m) - 1; i++) {
cout << i << ' ' << i << ' ';
}
cout << (1 << m) - 1 << ' ' << (1 << m) - 1 << endl;
return 0;
}
ll x = 0;
for(int i = 0; i < (1 << m); i++) {
if(i != k) {
x ^= i;
}
}
if(x != k) {
cout << -1 << endl;
return 0;
}
cout << k;
for(int i = 0; i < (1 << m); i++) {
if(i != k) {
cout << ' ' << i;
}
}
cout << ' ' << k;
for(int i = (1 << m) - 1; i >= 0; i--) {
if(i != k) {
cout << ' ' << i;
}
}
cout << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define NL '\n'
#define xx first
#define yy second
#define ll long long
#define mp make_pair
#define pb push_back
#define sz(x) x.size()
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define async() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define FayeValentine
void dz(){cerr<<NL;}template<typename H,typename... T> void dz(H h,T... t){cerr<<' '<<h;dz(t... );}
#ifdef FayeValentine
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",dz(__VA_ARGS__)
#else
#define debug(...)
#endif
void absinthe() {
int m, k; cin >> m >> k;
if(m == 1) {
if(k == 0) cout << "0 0 1 1" << NL;
else cout << -1 << NL;
return;
}
if((1<<(m)) <= k) {
cout << -1 << NL;
return;
}
for(int i = 0; i < (1<<m); i++) {
if(i == k) continue;
cout << i << " ";
}
cout << k << " ";
for(int i = (1<<m)-1; i >= 0; i--) {
if(i == k) continue;
cout << i << " ";
}
cout << k;
}
int main(){
async();
int __t = 1, __c;
for(__c = 1; __c <=__t; __c++) {
absinthe();
}
}
| 1 | 26,205,883 |
#include <iostream>
#define calc(x,y) (x*y)\
using namespace std;
int main(int argc, char **argv)
{
for(int i = 1; i <= 9; i++){
for(int j = 1; j <= 9; j++){
cout << i << "x" << j << "=" << calc(i,j) << endl;
}
}
return 0;
}
|
#include<stdio.h>
int main(){
int a,i,j;
for(i=1;i<=9;i++)
for(j=1;j<=9;j++){
printf("%dx%d=%d",i,j,i*j);
printf("\n");
}
return 0;
}
| 1 | 40,467,648 |
#include<bits/stdc++.h>
using namespace std;
void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}
void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}
#define lf double
#define ll long long
#define pii pair<int,int >
#define vec vector<int >
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define data asd09123jdf02i3h
#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)
const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;
int n;
vector<int > e[maxn];
int dfs(int x,int fa) {
int s=0;
for(auto v:e[x])
if(v!=fa) s^=dfs(v,x)+1;
return s;
}
int main() {
read(n);
for(int i=1,x,y;i<n;i++) read(x),read(y),e[x].pb(y),e[y].pb(x);
puts(dfs(1,0)?"Alice":"Bob");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5+5;
int n, s[MAXN];
vector<int> g[MAXN];
int dfs(int v, int f = -1) {
for (int u : g[v])
if (u != f)
s[v] ^= (1 + dfs(u, v));
return s[v];
}
int main() {
cin >> n;
for (int i = 0; i < n-1; ++i) {
int a, b;
cin >> a >> b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
}
if (dfs(0) == 0) {
cout << "Bob\n";
} else
cout << "Alice\n";
}
| 1 | 22,974,599 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx=1e5+100;
const int INF=99999999;
const int MOD=1e9+7;
int main()
{
int n;
ll a,sum[maxx*2]={0};
cin>>n;
sum[0]=0;
for(int i=1; i<=n; i++){
cin>>a;
sum[i]=sum[i-1]+a;
}
ll minn=abs(sum[1]*2-sum[n]);
for(int i=2; i<n; i++){
minn=min(minn,abs(sum[i]*2-sum[n]));
}
cout<<minn<<endl;
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
#define N 200008
int n;
int a[N];
long long sum = 0;
void solve()
{
long long first = a[1];
long long minn = abs(sum-first-first);
for (int i = 2; i < n; i++)
{
first += (long long)a[i];
minn = min(minn,abs(sum-first-first));
}
printf("%lld\n", minn);
}
void init()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
sum += (long long)a[i];
}
}
int main()
{
init();
solve();
return 0;
}
| 1 | 59,330,626 |
#include <iostream>
#include <algorithm>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(){
int N, H;
cin >> N >> H;
int a[N], b[N];
rep(i, N)
cin >> a[i] >> b[i];
sort(b, b+N, greater<>() );
int a_max = 0;
rep(i, N)
if(a_max < a[i])
a_max = a[i];
int count = 0;
while(count<N && H>0){
if(b[count] < a_max)
break;
H -= b[count++];
}
int tmp = 0;
if(H>0){
if(H%a_max == 0)
tmp = H/a_max;
else
tmp = (H+a_max)/a_max;
}
count += tmp;
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<int,int>
int main(){
int n,h;
cin>>n>>h;
vector<int> a(n),b(n);
rep(i,n){
int A, B;
cin>>A>>B;
a[i]=A; b[i]=B;
}
sort(a.begin(),a.end(),greater<int>());
sort(b.begin(),b.end(),greater<int>());
int ans=0;
rep(i,n){
if(a[0] < b[i]){
h-=b[i];
ans++;
}
if(h<=0) break;
}
if(h>0){
ans+=h/a[0];
if(h%a[0]!=0) ans++;
}
cout<<ans<<endl;
}
| 1 | 90,536,178 |
#include <iostream>
#include <vector>
using namespace std;
int ans = 0;
void selectionSort(vector<int>& vec)
{
for (int i = 0; i < vec.size() - 1; ++i)
{
int minj = i;
bool flag = false;
for (int j = i; j < vec.size(); ++j)
{
if (vec[j] < vec[minj])
{
minj = j;
flag = true;
}
}
if (flag)
{
int temp = vec[i];
vec[i] = vec[minj];
vec[minj] = temp;
++ans;
}
}
}
void solve()
{
int n;
cin >> n;
vector<int> vec(n);
for (int i = 0; i < n; ++i)
{
cin >> vec[i];
}
selectionSort(vec);
for (int i = 0; i < n - 1; ++i)
{
cout << vec[i] << " ";
}
cout << vec[vec.size() - 1] << endl;
cout << ans << endl;
}
int main()
{
solve();
return(0);
}
|
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
void swap(int *,int *);
int main(){
int n,a[100],c=0,minj;
cin >> n;
for(int i=0;i<n;i++) cin >> a[i];
for(int i=0;i<n;i++){
minj=i;
for(int j=i;j<n;j++){
if(a[j]<a[minj]){
minj=j;
}
}
swap(&a[i],&a[minj]);
if(i!=minj)c++;
}
for(int i=0;i<n;i++){
cout << a[i];
if(i!=n-1) cout << " ";
}
cout << endl;
cout << c << endl;
return 0;
}
void swap(int *a,int *b){
int w;
w= *a;
*a=*b;
*b=w;
}
| 1 | 85,382,003 |
#include <atcoder/dsu>
#include "bits/stdc++.h"
using namespace std;
using namespace atcoder;
const int N=2e5+20;
int n,q,t,u,v,c;
int main()
{
scanf("%d%d",&n,&q);
auto dsa=dsu(n);
while(q--)
{
scanf("%d%d%d",&t,&u,&v);
if(t==0) dsa.merge(u,v);
else printf("%d\n",dsa.same(u,v));
}
}
|
#include <atcoder/all>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define LL long long
int main(){
int n,q;
cin>>n>>q;
auto uf = atcoder::dsu(n);
REP(i,q){
int m,u,v;
cin>>m>>u>>v;
if(m==0){
uf.merge(u, v);
}else{
if(uf.same(u,v)){
cout<<1<<endl;
}else{
cout<<0<<endl;
}
}
}
}
| 1 | 93,774,378 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#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__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
typedef vector<int> vi;
ll n,m,x[100001],y[100001];
ll xsum,ysum;
int main(void){
cin>>n>>m;
rep(i,n)cin>>x[i];
rep(i,m)cin>>y[i];
rep(i,n){xsum=(xsum+i*x[i]-(n-1-i)*x[i])%mod;d(xsum)}
rep(i,m){ysum=(ysum+i*y[i]-(m-1-i)*y[i])%mod;d(ysum)}
p((xsum*ysum)%mod);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, m, x[100004], y[100004];
const int mod = 1000000007;
long long mul(long long a, long long b){
long long ret = a * b;
return ret% mod;
}
long long sum(long long a, long long b){
return (a+b)%mod;
}
int main() {
ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin>>n>>m;
for(int i = 0;i<n;i++) cin>>x[i];
for(int i = 0;i<m;i++) cin>>y[i];
int ver = 0, hor = 0;
for(int i = 1;i<n;i++) ver = sum(ver,mul(mul(x[i]-x[i-1],i),n-i));
for(int i = 1;i<m;i++) hor = sum(hor,mul(mul(y[i]-y[i-1],i),m-i));
cout<<mul(ver,hor);
return 0;
}
| 1 | 84,851,007 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int> n(3);
cin >> n[0] >> n[1] >> n[2];
sort(n.begin(), n.end());
int a;
a = n[0] + n[1] + n[2] * 10;
cout << a << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b , c , d;
cin >> a >> b >> c;
d = max ( a, max ( b,c)) ;
cout << ( d==b ? a+10*b+c : d==a ?10*a + b + c : a+b+10*c ) <<endl;
}
| 1 | 48,161,961 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
ll gcd(ll a, ll b)
{
if(b == 0) return a;
else return gcd(b, a % b);
}
int main()
{
ll N;
cin >> N;
vec A(N);
REP(i,0,N) cin >> A[i];
ll g = A[0];
REP(i,1,N) g = gcd(g, A[i]);
PR(g);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a)
#define DEBUG(x)
#define DEBUGS(v)
#endif
int main() {
ll n,ans;
cin >> n;
vector<ll> a(n);
REP(i,n){cin>>a[i];}
sort(ALL(a));
a.erase(unique(ALL(a)), a.end());
ans = a[0];
REP(i, a.size()) { ans = gcd(ans, a[i]); }
cout << ans << endl;
return 0;
}
| 1 | 34,671,374 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
vector<ll> a, p;
ll dfs(ll n, ll x) {
if (n == 0)
return x <= 0 ? 0 : 1;
else if (x <= a[n - 1] + 1)
return dfs(n - 1, x - 1);
else
return p[n - 1] + 1 + dfs(n - 1, x - 2 - a[n - 1]);
}
int main() {
ll n, x;
cin >> n >> x;
a.push_back(1), p.push_back(1);
rep(i, n) {
a.push_back(a[i] * 2 + 3);
p.push_back(p[i] * 2 + 1);
}
cout << dfs(n, x) << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll W[55];
ll P[55];
ll patee(ll l, ll n){
ll whole = W[l];
ll pate = P[l];
if(l == 0){
return 1;
}
if(n == 1){
return 0;
}
if(n > 1 && n < (whole/2) + 1){
return patee(l-1, n-1);
}
if(n == (whole/2) + 1){
return P[l-1]+1;
}
if(n < whole){
return P[l-1]+1 + patee(l-1, n-((whole/2)+1));
}
return pate;
}
int main() {
ll N, X; cin >> N >> X;
W[0] = 1;
P[0] = 1;
for (int i = 1; i <= N; i++){
W[i] = W[i-1]*2 + 3;
P[i] = P[i-1]*2 + 1;
}
cout << patee(N, X) << endl;
return 0;
}
| 1 | 35,041,167 |
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n) scanf("%d",&n)
#define mz(a) memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n) ip(A[i]);
#define print(a) for(auto i : a) cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b) {return a>b?a:b;}
ll min(ll a,ll b) {return a<b?a:b;}
const int N = 2e5+1;
vector<int> adj[N];
vector<int> vis(N);
void dfs(int root,int val)
{
vis[root] = val;
for(auto i : adj[root])
if(!vis[i])
dfs(i,val);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("D:/Sublime/Rough/input.txt","r",stdin);
#endif
Fastio;
int n,m;
cin>>n>>m;
while(m--)
{
int u,v;
cin>>u>>v;
adj[u].pb(v);
adj[v].pb(u);
}
int val = 0;
for(int i=1;i<=n;i++)
{
if(!vis[i])
dfs(i,++val);
}
int a[val+1];
mz(a);
int mx = 0;
for(auto i : vis)
a[i]++;
for(int i=1;i<=val;i++)
mx = max(mx,a[i]);
cout<<mx;
#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
#endif
return 0;
}
|
#include<iostream>
#include<queue>
#include<deque>
#include<vector>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>
#include<unordered_set>
#include<unordered_map>
#define pi 3.141592653
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt","w",stdout);
#define ii pair<int,int>
#define fast_io cin.tie(0), cin.sync_with_stdio(false);
#define inf 0x3f3f3f3f
#define sup_inf 1e18
#define f first
#define s second
#define eps 1e-9
#define nl ( no << 1)
#define nr ( no << 1)|1
#define mid l+(( r-l)>>1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair< long long , pair< int,int> > iii;
const int maxn = 2e5 + 100;
const int MAX = 1010;
const int mod = 1e9 + 7;
const int MAXLV = 16;
using namespace std;
int an[maxn], sz[maxn];
int n, m , ans = 1;
int findc(int u ){
while ( an[u] != u ){
u = an[u] = an[an[u]];
}
return u;
}
void une ( int a, int b) {
int x = findc(a);
int y = findc(b);
if ( x == y) return;
an[x] = y;
sz[y]+=sz[x];
ans = max ( sz[y], ans );
}
int main () {
fast_io
cin >> n >> m;
for(int i = 0 ;i < maxn;i++) {
an[i] = i;
sz[i] = 1;
}
for(int i = 0 ;i < m;i++ ){
int ai, bi;
cin >> ai >> bi;
une ( ai, bi);
}
cout << ans << '\n';
return 0;
}
| 1 | 57,666,776 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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() {
ll n, m, d;
cin >> n >> m >> d;
double ans;
if (d == 0) {
ans = (double)(m-1) / n;
} else {
ans = (double)(m-1) * 2 * (n - d) / (n * n);
}
cout << fixed << setprecision(10) << ans << endl;
}
|
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
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 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;
int main(){
ll n, m, d;
cin >> n >> m >> d;
double p;
if(d == 0){
p = (double) (m-1) / (double) n;
} else {
p = ((double) 2 * (double) (m-1) / (double) n);
}
p *= (double) (n-d) / (double) n;
cout << fixed;
cout << setprecision(8) << p << endl;
return 0;
}
| 1 | 29,565,505 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, m;
string a, b, c;
cin>>a>>b>>n>>m>>c;
if(a==c)
n--;
else if(b==c)
m--;
cout<<n<<" "<<m;
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main()
{
char S[15], T[15], U[15];
int A, B;
scanf ("%s %s", S, T);
scanf ("%d %d", &A, &B);
scanf ("%s", U);
(strcmp (S,U) == 0) ? A-- : B--;
printf ("%d %d", A, B);
return 0;
}
| 1 | 51,111,264 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
set<int> st;
int temp;
for(int i=1;i<=n;i++){
cin>>temp;
if(st.find(temp)!=st.end()){
cout<<"NO\n";
return 0;
}
st.insert(temp);
}
cout<<"YES\n";
return 0;
}
|
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;
void solve() {
int n;
cin >> n;
map<int, int> m;
bool flag = true;
for(int i = 0; i < n; ++i) {
int x;
cin >> x;
m[x]++;
if(m[x] > 1) flag = false;
}
if(flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.precision(35);
int t;
solve();
return 0;
}
| 1 | 63,650,409 |
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int main(){
int N, A, B;
scanf("%d %d %d", &N, &A, &B);
int ans = 0, a = 0, b = 0, c = 0, p;
rep(i, N){
scanf("%d", &p);
if(p <= A) a++;
if(p >= A + 1 && p <= B) b++;
if(p >= B + 1) c++;
}
printf("%d\n", min({a, b, c}));
return 0;
}
|
#pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;
#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto& x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll A;
int main(void) {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n >> A >> b;
rep(i, n) cin >> a[i];
rep(i, n) {
rep(j, n) {
rep(k, n) {
if (a[i] == -1 || a[j] == -1 || a[k] == -1) continue;
if (a[i] <= A && A + 1 <= a[j] && a[j] <= b && b + 1 <= a[k]) {
ans++;
a[i] = -1;
a[j] = -1;
a[k] = -1;
}
}
}
}
Cout(ans);
return 0;
}
| 1 | 28,336,937 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template < typename T >
void vprint(T &v){
REP(i, v.size()){
cout << v[i] << " ";
}
cout << endl;
}
int main(){
ll K;
cin >> K;
cout << 50 << endl;
vector<ll> a(50);
REP(i, 50) a[i] = 49 + (K/50);
ll ama = K%50;
REP(i, 50) a[i] -= ama;
REP(i, ama) a[i] += 51;
REP(i, 50) cout << a[i] << " ";
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
ll K; cin >> K;
int n = 50;
ll base = 49LL + K / 50;
K = K % 50;
vll a(n);
rep(i, 50 - K){
a[i] = base - K;
}
rep(i, K){
a[50 - K + i] = base + 50 - K + 1;
}
cout << n << endl;
rep(i, n){
cout << (i ? " ":"") << a[i];
}
cout << endl;
return 0;
}
| 1 | 25,932,855 |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
int n,j,sum,max1;
while(cin>>n,n){
vector<int> v;
for(int i=0;i<n;i++){
cin>>j;
v.push_back(j);
}
max1=v[0];
for(int i=0;i<n;i++){
sum=0;
for(int j=i;j<n;j++){
sum=sum+v[j];
max1=max(max1,sum);
}
}
cout<<max1<<endl;
}
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n;
while(cin >> n, n != 0){
vector<int> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
int minimum = 0;
int x = 0;
int maximum = -9999999;
for(int i=0; i<a.size(); i++){
x += a[i];
maximum = max(maximum, x-minimum);
minimum = min(minimum, x);
}
cout << maximum << endl;
}
return 0;
}
| 1 | 89,379,706 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;cin>>N;
vector<int>DP(200000,int(1e9+7));
DP[0]=0;
vector<int>A{1,6,36,216,1296,7776,46656,9,81,729,6561,59049};
for(int i=0;i<N;i++)
for(int j=0;j<12;j++)
DP[i+A[j]]=min(DP[i+A[j]],DP[i]+1);
cout<<DP[N]<<endl;
}
|
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>
using namespace std;
#define GODSPEED ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define f first
#define s second
#define newl cout<<"\n";
#define pb push_back
#define mset(a,x) memset(a,x,sizeof(a))
#define debv(a) for(auto it: a)cout<<it<<" ";newl;
#define deb1(a) cout<<a<<"\n";
#define deb2(a,b) cout<<a<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll N = 2e6+5;
const ll mod = 1e9+7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
ll test = 1, n, dp[N];
void solve(){
cin>>n;
dp[0] = 0;
for(int i = 1; i <= n; i++){
dp[i] = dp[i-1]+1;
for(int j = 6; j <= i; j *= 6) dp[i] = min(dp[i],dp[i-j]+1);
for(int j = 9; j <= i; j *= 9) dp[i] = min(dp[i],dp[i-j]+1);
}
deb1(dp[n])
}
int main(){
GODSPEED;
for(int i = 1; i <= test; i++){
solve();
}
#ifndef ONLINE_JUDGE
cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
}
| 1 | 83,101,283 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;
int main() {
int A,B,C,D;
cin >> A >> B >> C >> D;
cout << min(A,B) + min(C,D) << endl;
}
|
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int A;
int B;
int C;
int D;
cin >>A>>B>>C>>D;
int x=min(A,B);
int y=min(C,D);
int z=x+y;
cout << z<< endl;
}
| 1 | 33,916,588 |
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long int
#define pb push_back
#define mp12 make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pq1 priority_queue<int>
#define pqr1 priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
void FIO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int modInv(int a,int b,int m){int res=1;a=a%m;while(b>0){if(b&1){res=(res*a)%m;}a=(a*a)%m;b=b>>1;}return res;}
int dp[1001][1001];
void solve(){
int n,m;
cin>>n>>m;
char a[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1;i<n;i++){
if(a[i][0]=='#') dp[i][0]=0;
else dp[i][0]=dp[i-1][0];
}
for(int i=1;i<m;i++){
if(a[0][i]=='#') dp[0][i]=0;
else dp[0][i]=dp[0][i-1];
}
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
if(a[i][j]!='#') dp[i][j]=(dp[i][j-1] + dp[i-1][j])%mod;
}
}
cout<<dp[n-1][m-1]<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define FORN(i, x, y) for (int i = x; i <= y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
ll gcd(ll a, ll b){
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq( int x ) {return x * x;}
const int MOD = 1e9 + 7;
const int maxn = 1004;
int a[maxn][maxn];
int dp[maxn][maxn];
int n, m;
int add ( int a, int b ) { return ( a + b ) % MOD; }
int main () {
scan2(n, m);
FORN(i, 1, n) FORN(j, 1, m) {
char ch;
scanf(" %1c", &ch);
if ( ch == '.' ) a[i][j] = 1;
else a[i][j] = 0;
}
dp[1][1] = 1;
FORN(i, 1, n) FORN(j, 1, m) {
if ( !a[i][j] ) dp[i][j] = 0;
else {
if ( i >= 2 ) dp[i][j] = add(dp[i][j], dp[i-1][j]);
if ( j >= 2 ) dp[i][j] = add(dp[i][j], dp[i][j-1]);
}
}
print1(dp[n][m]);
}
| 1 | 58,522,643 |
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#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)
bool work[17][17];
int memo[17][17];
int C(int x, int y){
if(x==0||y==0) return 0;
if(x==1&&y==1) return 1;
if(work[x][y]) return 0;
if(memo[x][y]!=-1) return memo[x][y];
return (C(x-1,y) + C(x,y-1));
}
int main(void){
int a,b;
while(cin>>a>>b){
if(a==0) break;
memset(work,0,sizeof(work));
memset(memo,-1,sizeof(memo));
int n,x,y;
cin>>n;
REP(i,n){
cin>>x>>y;
work[x][y]=true;
}
cout<<C(a,b)<<endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
#define AMAX 17
int a,b,n;
int r[AMAX][AMAX];
void solve(){
for(int i=1;i<=b;i++){
for(int j=1;j<=a;j++){
if(r[i][j]==-1)continue;
if(r[i-1][j]!=-1)r[i][j]+=r[i-1][j];
if(r[i][j-1]!=-1)r[i][j]+=r[i][j-1];
}
}
cout<<r[b][a]<<endl;
}
int main(){
while(cin>>a>>b,a||b){
for(int i=0;i<AMAX;i++)fill(r[i],r[i]+AMAX,0);
r[1][1]=1;
cin>>n;
int x,y;
for(;n>0;--n){
cin>>x>>y;
r[y][x]=-1;
}
solve();
}
return 0;
}
| 1 | 88,252,273 |
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
using namespace std;
int main() {
int H, W, i, j;
string str[26][26];
string s = "snuke";
char w;
cin >> H >> W;
for (i = 0; i < H; i++) {
for (j= 0; j < W; j++) {
cin >> str[i][j];
}
}
for (i = 0; i < H; i++) {
for (j = 0; j < W; j++) {
if (str[i][j] == s) {
w = j + 65;
cout << w << i + 1;
}
}
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int main(){
DRII(N,M);
REP(i,N)REP(j,M){
char s[24];
RS(s);
if(strcmp(s,"snuke")==0){
printf("%c%d\n",'A'+j,i+1);
return 0;
}
}
return 0;
}
| 1 | 56,731,143 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, j = 0;;
cin >> n;
for(int i = 1; i <= n; i++){
j+=i;
}
cout << j << endl;
}
|
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
cout << n*(n+1)/2 << endl;
return 0;
}
| 1 | 50,477,499 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)
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 gcd(ll a, ll b)
{
if(b == 0) return a;
return gcd(b, a % b);
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
vector<pair<ll, ll>> prim;
void pf(ll n)
{
ll s = sqrt(n);
ll r = 0;
for(ll i = 2; i <= s; i++) {
if((n % i) == 0) {
r = 0;
do {
r++;
n = n / i;
} while((n % i) == 0);
prim.push_back({i, r});
}
}
if(n > s) {
prim.push_back({n, 1});
}
}
void solve()
{
ll T, X; cin >> T >> X;
double ans;
ans = (double)T/(double)X;
printf("%.10f\n", ans);
}
int main(void)
{
solve();
}
|
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
if(num == 0) num = (ll)v.size();
cout << endl; cout << "i= ";for(ll i=0; i<num; i++) cout << i << " ";cout << endl;
cout << " ";
if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
cout << endl;
}
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}
template <typename T>
void print_vec2(const vector<vector<T>>& v){
cout << endl; cout << " ";
for(ll i=0; i<v[0].size(); i++) cout << i << " ";
cout << endl;
for(ll i=0; i<v.size(); i++){
cout << "i=" << i << ": ";
for(ll j=0; j<v[i].size(); j++){
if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << " ";
else cout << "\x1B[31m" << v[i][j] << " ";
}
cout << "\x1B[0m" << endl;
}
}
int main(){
double T, X;
cin >> T >> X;
cout << fixed;
cout << setprecision(10);
cout << T / X << endl;
return 0;
}
| 1 | 2,900,322 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<set<int>> a(n);
for (int i = 0; i < m; ++i) {
int b, c;
cin >> b >> c;
a[b - 1].insert(c - 1);
a[c - 1].insert(b - 1);
}
deque<int> d;
vector<bool> seen;
int summ=0;
seen.assign(n, false);
int v;
int count=0;
for(int j=0;j<n;++j){
v=j;
if(seen[v])continue;
count=0;
seen[v] = true;
while (1) {
++count;
for (auto i:a[v]) {
if(!seen[i])d.push_back(i);
seen[i]=true;
}
if (!d.empty()) {
v = d.front();
d.pop_front();
}else {
break;
}
}
summ=max(summ,count);
}
cout<<summ<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back
#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__);
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif
const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
const int INF = 1e18;
const int MX = 1000001;
bool visited[MX];
map<int,int>cnt;
int mx = -1;
set<int>graph[MX];
int c = 0;
void dfs(int node, int c){
visited[node]=true;
cnt[c]++;
mx=max(mx,cnt[c]);
for(auto child: graph[node]){
if(!visited[child])
dfs(child,c);
}
}
int32_t main() {
io;
int n,m,x,y;
cin>>n>>m;
set<pair<int,int>>st;
for(int i =0;i<m;i++){
cin>>x>>y;
graph[x].insert(y),graph[y].insert(x);
}
for(int i = 1;i<=n;i++){
if(!visited[i]){
dfs(i,c);
c++;
}
}
cout<<mx<<endl;
return 0;
}
| 1 | 67,711,429 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
#endif
map<ll,ll> mp;
ll n;
cin>>n;
for(int i=2;(long long)i*i<=n;i++){
if(n%i==0){
int count=0;
while(n%i==0){
n/=i;
count++;
}
mp[i]=count;
}
}
if(n>1){
mp[n]=1;
}
int count=0;
for(auto it: mp){
int i=1;
while(i<=it.second){
count++;
it.second-=i;
i++;
}
}
cout<<count;
}
|
#include<bits/stdc++.h>
using namespace std ;
#define endl "\n"
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
const int mod = (int)1e9 + 7 ;
template<class T>
auto matrix( int r, int c, T v ){
return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
template<class T>
auto matrix( int o1, int o2, int o3, T v ){
return vector<vector<vector<T>>>( o1, vector<vector<T>>( o2, vector<T>( o3, v ) ) ) ;
}
#define v vector
int power( int x, int n ){
if( n == 0 ) return 1 ;
else if( n & 1 ) return ( x * power( (x*x) % mod, n / 2 ) ) % mod ;
return power( (x*x) % mod, n / 2 ) % mod ;
}
template<class T> void __print( v<T> &arr ){
int n = arr.size() ;
cerr << "[ " ;
for( int i = 0 ; i < n ; i++ ) {
cerr << arr[i] ;
if( i != n - 1 ) cerr << ", " ;
}
cerr << " ]" << endl ;
}
template<class T> void __print( T arr[], int n ){
cerr << "[ " ;
for( int i = 0 ; i < n ; i++ ) {
cerr << arr[i] ;
if( i != n - 1 ) cerr << ", " ;
}
cerr << " ]" << endl ;
}
#define print(x) cerr << "{ " << #x << " : " << x << " } " ;
#define println(x) cerr << "{ " << #x << " : " << x << " }" << endl ;
int solve( int n ){
int cnt = 0, c = 0 ;
for( int i = 2 ; i * i <= n ; i++ ){
c = 0 ;
while( n % i == 0 ){
n /= i ;
++c ;
}
if( c >= 0 ){
cnt += floor(( -1 + sqrt(1 + 8*c) ) * 1.0 / 2) ;
}
}
if( n > 2 ) ++cnt ;
return cnt ;
}
signed main(){
int n ; cin >> n ;
cout << solve(n) << endl ;
return 0 ;
}
| 1 | 42,006,843 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
int N;
cin >> N;
vector<ll> A(N);
ll ans = 0;
ll tmp;
rep(i, N) {
cin >> A[i];
if(i) {
tmp = min(A[i-1], A[i]);
ans += tmp;
A[i-1] -= tmp;
A[i] -= tmp;
}
tmp = A[i] / 2;
ans += tmp;
A[i] -= 2 * tmp;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#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()
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;
vi a(n);
rep(i, n) cin >> a[i];
ll now = 0;
ll ans = 0;
rep(i, n) {
if (a[i] == 0) {
ans += now/2;
now = 0;
} else {
now += a[i];
}
}
ans += now/2;
cout << ans << endl;
}
| 1 | 47,105,024 |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
#define INF 100000000
int main()
{
int N;
cin >> N;
vi seq(N);
for (int n = 0; n < N; n++)
{
cin >> seq[n];
seq[n] -= (n+1);
}
sort(seq.begin(), seq.end());
LL d = 0;
for (int n = 0; n < N; n++)
d += abs(seq[n] - seq[N/2]);
cout << d << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define sep cout<<"\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
int main(){
long N,s =0;
cin>>N;
long A[N];
for(int i=0;i<N;i++){
cin>>A[i];
A[i] = A[i]-(i+1);
}
sort(A,A+N);
long ele;
if(N%2 == 0)ele = (A[N/2] + A[(N/2)-1])/2;
else ele = A[N/2];
long ans = 0;
for(int i=0;i<N;i++){
ans+=abs(A[i]-ele);
}
cout<<ans<<"\n";
}
| 1 | 83,762,352 |
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;
template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }
ll pow(ll b, ll p) {
ll r=1;
rep(i, p) {
r *= b;
}
return r;
}
int main() {
ll ans=0;
ll H,W,K;
cin >> H >> W >> K;
char m[6][6]={};
rep(i,H) rep(j,W) {
cin >> m[i][j];
}
for (int h=pow(2,H)-1; h >= 0; --h) {
for (int w=pow(2,W)-1; w >= 0; --w) {
ll count = 0;
rep(i,H) rep(j,W) {
if (((h >> i) & 1) || ((w >> j) & 1))
continue;
if (m[i][j] == '#')
++count;
}
if (count == K)
++ans;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define tcase() int t; cin >> t; while(t--)
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const ld PI = acos((ld) -1);
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if(sz(name)){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
int main(){
setIO();
int H, W, K;
cin >> H >> W >> K;
char grid[H][W];
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
cin >> grid[i][j];
}
}
int ans = 0;
for(int maskR = 0; maskR < (1 << H); maskR++){
for(int maskC = 0; maskC < (1 << W); maskC++){
int black = 0;
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
if(((maskR >> i) & 1) == 1 && ((maskC >> j) & 1) == 1 && grid[i][j] == '#')
black++;
}
}
if(black == K) ans++;
}
}
cout << ans;
}
| 1 | 23,832,327 |
#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>;
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 x, y;
cin >> x >> y;
cout << x + y/2 << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define F first
#define S second
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
if(a==0 || b==0)return 0;
return a/__gcd(a,b)*b;
}
void input(ll ara[],ll n)
{
for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
for(ll i=0; i<n; i++)
cout<<ara[i]<<" ";
cout<<endl;
}
int main()
{
fastread();
ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;
bool flag=false;
string str;
cin>>a>>b;
cout<<a+(b/2)<<endl;
}
| 1 | 11,753,472 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
using namespace std;
#define ll long long int
ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;
ll mypow(ll x,ll n){
ll ret = 1;
while(n > 0){
if(n&1){
ret = (ret*x)%MOD;
}
x = (x*x)%MOD;
n >>= 1;
}
return ret;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<ll> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
sort(a.begin(),a.end());
ll diameter = a.back();
a.push_back(INF);
bool odd = (bool)(diameter&1);
ll radius = diameter/2 + (odd ? 1 : 0 );
bool first = true;
if(a[0] != radius){
cout << "Impossible" << endl;
return 0;
}
int prev = radius - 1;
for(int i = 0; i < n; i++){
int count = 0;
while(a[i] == a[i+1]){
count++;
i++;
}
if(first){
first = false;
if(odd){
if(count > 1){
cout << "Impossible" << endl;
return 0;
}
}else{
if(count > 0){
cout << "Impossible" << endl;
return 0;
}
}
}else{
if(count < 1){
cout << "Impossible" << endl;
return 0;
}
}
if(prev+1 != a[i]){
cout << "Impossible" << endl;
return 0;
}
prev = a[i];
}
cout << "Possible" << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define inf(x) (ll)(1e##x)
using namespace std;
template<typename tn> void read(tn &a){
tn x=0,f=1; char c=' ';
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
a=x*f;
}
int n,h[110];
int main(){
read(n);
int mx=0;
for(int i=1;i<=n;i++){
int x;read(x);
if(x>=n){puts("Impossible");return 0;}
h[x]++;
mx=max(mx,x);
}
int flag=1;
if(~mx&1) flag&=h[mx+1>>1]==1;
else flag&=h[mx+1>>1]==2;
for(int i=mx;i>mx+1>>1;i--) flag&=h[i]>1;
for(int i=1;i<mx+1>>1;i++) flag&=!h[i];
if(flag) puts("Possible");
else puts("Impossible");
return 0;
}
| 1 | 74,536,291 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int ctoi(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
return 0;
}
ll factorial(ll n) {
if (n == 1) {
return 1;
}
ll ans = factorial(n-1);
return ans*n;
}
ll gcd(ll a, ll b) {
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll r = a%b;
while(r != 0) {
a = b;
b = r;
r = a%b;
}
return b;
}
ll lcm(ll a, ll b) {
return (a/gcd(a, b))*b;
}
int main() {
ll a, b, c, d;
cin >> a >> b >> c >> d;
if (abs(a-c) <= d) {
cout << "Yes" << endl;
} else if (abs(a-b)<=d && abs(b-c)<=d) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
|
#include<iostream>
#include<cmath>
int main(){
int a,b,c,d;
std::cin >> a >> b >> c >> d;
if(std::abs(a - b) <= d && std::abs(b - c) <= d || std::abs(a-c) <= d) std::cout<<"Yes";
else std::cout<<"No";
}
| 1 | 11,446,904 |
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16)
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
int main(void) {
int n; cin >> n;
vi c(n-1),s(n-1),f(n-1);
rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
rep(i,n-1){
int t = s[i];
for(int j=i; j<n-1; j++){
t = max(t,s[j]);
t += (f[j]-(t%f[j]))%f[j];
t += c[j];
}
cout << t << endl;
}
cout << 0 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
vector<pair<int64_t,int64_t>>p;
for(int64_t i=2;i*i<=x;i++){
int cnt=0;
if(x%i==0){
while(x%i==0){cnt++;x/=i;}
p.push_back(make_pair(i,cnt));
}
}
if(x!=1){p.push_back(make_pair(x,1));}
return p;
}
int main() {
int N;
cin>>N;
vector<int>C(N-1),S(N-1),F(N-1);
for(int i=0;i<N-1;i++){
cin>>C[i]>>S[i]>>F[i];
}
for(int i=0;i<N-1;i++){
int sum=S[i]+C[i];
for(int j=i+1;j<N-1;j++){
if(sum<=S[j]){sum+=(S[j]-sum);}
else if(sum%F[j]!=0){sum+=(F[j]-sum%F[j]);}
sum+=C[j];
}
cout<<sum<<endl;
}
cout<<0<<endl;
return 0;
}
| 1 | 36,242 |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
int x,a,b;
scanf("%d%d%d",&x,&a,&b);
if((b-a)<=x)
{
if((b-a)<=0)
printf("delicious");
else
printf("safe");
}
else
printf("dangerous");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}
const ll MOD = 1e9+7;
long long Comb(int n, int i){long long ans = 1; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){
ans *=(n+1-j);
ans /= j;
ans %= MOD;} }return ans;}
void solve()
{
int x, a, b; cin >> x >> a >> b;
if(b-a <= 0) cout << "delicious" << endl;
else if(b-a <= x) cout << "safe" << endl;
else cout << "dangerous" << endl;
}
int main()
{
solve();
return 0;
}
| 1 | 21,349,122 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Sieve {
vector<int> f, primes;
Sieve(int N):f(N+1,0) {
f[0] = f[1] = -1;
for (int i = 2; i <= N; ++i) {
if (!f[i]==0){
continue;
}
primes.push_back(i);
f[i] = i;
if(i>sqrt(N)){
continue;
}
for (int j = i*i; j <= N; j += i) {
if (f[j]==0){
f[j] = i;
}
}
}
}
bool isPrime(int x) {
return f[x] == x;
}
vector<int> factorList(int x) {
vector<int> res;
if(x==0 || x==1){
return { };
}
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<pair<int,int>> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0) return {};
vector<pair<int,int>> res(1, make_pair(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
}
else {
res.push_back(make_pair(p, 1));
}
}
return res;
}
vector<pair<ll,int>> factor(ll x) {
vector<pair<ll,int>> res;
for (int p : primes) {
int y = 0;
while (x%p == 0){
x /= p, ++y;
}
if (y != 0){
res.push_back(make_pair(p,y));
}
}
if (x != 1){
res.push_back(make_pair(x,1));
}
return res;
}
};
int main(){
ll N;
cin >> N;
Sieve S(1e6+5);
vector<pair<ll,int>> fac=S.factor(N);
ll ans=0;
for(pair<ll,int> p: fac){
ans+=floor((-1+sqrt(1+8*p.second))/2);
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std ;
#define endl "\n"
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
const int mod = (int)1e9 + 7 ;
template<class T>
auto matrix( int r, int c, T v ){
return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
template<class T>
auto matrix( int o1, int o2, int o3, T v ){
return vector<vector<vector<T>>>( o1, vector<vector<T>>( o2, vector<T>( o3, v ) ) ) ;
}
#define v vector
int power( int x, int n ){
if( n == 0 ) return 1 ;
else if( n & 1 ) return ( x * power( (x*x) % mod, n / 2 ) ) % mod ;
return power( (x*x) % mod, n / 2 ) % mod ;
}
template<class T> void __print( v<T> &arr ){
int n = arr.size() ;
cerr << "[ " ;
for( int i = 0 ; i < n ; i++ ) {
cerr << arr[i] ;
if( i != n - 1 ) cerr << ", " ;
}
cerr << " ]" << endl ;
}
template<class T> void __print( T arr[], int n ){
cerr << "[ " ;
for( int i = 0 ; i < n ; i++ ) {
cerr << arr[i] ;
if( i != n - 1 ) cerr << ", " ;
}
cerr << " ]" << endl ;
}
#define print(x) cerr << "{ " << #x << " : " << x << " } " ;
#define println(x) cerr << "{ " << #x << " : " << x << " }" << endl ;
int solve( int n ){
int cnt = 0, c = 0 ;
for( int i = 2 ; i * i <= n ; i++ ){
c = 0 ;
while( n % i == 0 ){
n /= i ;
++c ;
}
if( c >= 0 ){
cnt += floor(( -1 + sqrt(1 + 8*c) ) * 1.0 / 2) ;
}
}
if( n > 2 ) ++cnt ;
return cnt ;
}
signed main(){
int n ; cin >> n ;
cout << solve(n) << endl ;
return 0 ;
}
| 1 | 52,255,716 |
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(){
int i,k,t,end=0,slen,plen,correct=0;
char static s[500];
char static p[500];
char static c[500];
scanf("%s",s);
scanf("%s",p);
slen=strlen(s);
plen=strlen(p);
for(i=0;i<slen;i++){
for(k=0;k<plen;k++){
if(k==0)t=i+k;
c[k]=s[t];
t++;
if(i+k+1==slen)t=0;
}
if(strcmp(c,p)==0){
correct=1;
}
}
if(correct==1){
printf("Yes\n");
}else{
printf("No\n");
}
return 0;
}
|
#include<stdio.h>
#include<string.h>
int main(void)
{
char s[100],sc[100],p[100];
int sl,pl,f=0;
scanf("%s",s);
scanf("%s",p);
strcpy(sc,s);
sl=strlen(s);
pl=strlen(p);
for(int j=0;j<sl;j++){
sc[0]=s[sl-1];
for(int i=0;i<(sl-1);i++){
sc[i+1]=s[i];
}
if(strncmp(sc,p,pl)==0){
f=1;
break;
}
strcpy(s,sc);
}
if(f==1){
printf("Yes\n");
}
else{
printf("No\n");
}
return 0;
}
| 1 | 62,593,903 |
#include <iostream>
int main(int argc, char const *argv[])
{
int num1, num2;
while (1) {
std::cin >> num1 >> num2;
if (num1 == 0 && num2 ==0) {
break;
}
if (num1 < num2) {
std::cout << num1 << " " << num2 << std::endl;
}
else {
std::cout << num2 << " " << num1 << std::endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
while (true) {
int a,b;
cin >> a >> b;
if (a == 0 && b == 0) {
break;
}else{
if (a > b) {
cout << b << " " << a << endl;
}else{
cout << a << " " << b << endl;
}
}
}
return 0;
}
| 1 | 73,284,871 |
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main(void) {
int n = 0;
while (cin >> n) {
if (n == 0) {
break;
}
int A[1000];
for (int i = 0; i < 1000; i++) {
A[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> A[i];
}
for (int i = 0; i < n - 1; i++){
for (int j = i + 1; j < n; j++) {
if (A[i] > A[j]) {
int tmp = A[i];
A[i] = A[j];
A[j] = tmp;
}
}
}
int min = 1000000;
for (int i = 0; i < n - 1; i++) {
if (A[i + 1] - A[i] < min) {
min = A[i + 1] - A[i];
}
}
cout << min << endl;
}
return 0;
}
|
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void){
int n,i,j,a[1000],s=0,min,l,c,d;
while(1){
min = 1000000;
cin >> n;
if (n == 0)
break;
for (i=0;i<n;i++){
cin >> l;
a[i] = l;
}
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
s = abs(a[i] - a[j]);
if(min > s)
min = s;
}
}
cout << min << endl;
}
}
| 1 | 33,447,113 |
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;
int main() {
int N;
cin >> N;
map<int,int> mp;
rep(i, N) {
int a;
cin >> a;
++mp[a];
}
int ans = 0;
for(int i=2;i<=1e5+1;++i){
int tmp =0;
tmp += mp[i] + mp[i-1] + mp[i-2];
ans = max(ans,tmp);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<ll> A(n); rep(i, n) cin >> A[i];
map<int, int> mp;
rep(i, n) {
mp[A[i]-1]++;
mp[A[i]]++;
mp[A[i]+1]++;
}
int ans = 0;
for(auto ele: mp) ans = max(ele.second, ans);
cout << ans << "\n";
return 0;
}
| 1 | 3,409,349 |
#include <iostream>
int main() {
int a,b,c,res;
std::cin >> a >> b >> c;
if (a == b && b == c) {
res = 1;
} else if ( a == b || b == c || c == a) {
res = 2;
} else {
res = 3;
}
std::cout << res << std::endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b, c, ans;
ans = 1;
cin >> a >> b >> c;
if (a != b)
{
ans++;
}
if (a != c && b != c)
{
ans++;
}
cout << ans << endl;
return 0;
}
| 1 | 100,838,481 |
#include <bits/stdc++.h>
using namespace std;;
int main(){
string n;
cin >> n;
int ans = 0;
for (long long i = 0; i < n.size(); i++){
ans += n[i] - '0';
ans %= 9;
}
if (ans == 0){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
|
#include<bits/stdc++.h>
#define int long long int
#define mod 998244353
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output1.txt","w", stdout);
#endif
string s;
cin>>s;
int n,ans=0;
n=s.size();
for (int i = 0; i < n; ++i)
{
ans=(ans+(s[i]-'0'))%9;
}
if (ans==0)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
#ifndef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| 1 | 1,907,838 |
#include<iostream>
using namespace std;
int N_MAX=200000;
typedef long long ll;
int main()
{
int n,i,j,x=0,s=0;
int a[N_MAX];
ll res=0;
cin >> n;
for(i=0;i<n;i++)
cin >> a[i];
for(i=0,j=0;i<n;i++){
for(;j<n;j++){
if(x!=s)
break;
x^=a[j];
s+=a[j];
}
if(x==s)
j=n+1;
res+=j-i-1;
x^=a[i];
s-=a[i];
}
cout << res << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> a(n); for (auto &&i : a) cin >> i;
int right = 1;
long long ans = 0;
long long sum = 0;
sum += a.at(0);
for (int left = 0; left < n; left++)
{
while (right < n && sum + a.at(right) == (sum ^ a.at(right)) )
{
sum += a.at(right);
right++;
}
ans += (right - left);
if(left == right) right++;
sum -= a.at(left);
}
std::cout << ans << endl;
}
| 1 | 19,066,535 |
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 10000000000;
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pb(a) push_back(a)
#define mp make_pair
int main(){
int h,w,n;
cin>>h>>w>>n;
vector<int>a(n);
vector<int>b(n);
REP(i,n)cin>>a[i]>>b[i];
map<pair<int,int>,ll> map_;
REP(i,n)REP(j,3)REP(k,3)if(a[i]-2+j>=0&&a[i]-2+j<h&&b[i]-2+k>=0&&b[i]-2+k<w)map_[mp(a[i]-2+j,b[i]-2+k)]++;
vector<ll> ans(10,0);
for(auto t:map_)if(t.first.first!=0&&t.first.second!=0&&t.first.first!=h-1&&t.first.second!=w-1)ans[t.second]++;
ans[0]=1LL*(h-2)*(w-2)-accumulate(ALL(ans),0LL);
for(auto a:ans)cout<<a<<endl;
return 0;
}
|
#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;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
unordered_map<ll, bool> ma;
unordered_map<ll,bool> visited;
int dx[3] = {-1,0,1};
int dy[3] = {-1,0,1};
int h, w;
const ll MOD = 1e9 + 7;
ll hsh(ii x)
{
ll r = MOD*ll(x.fi)+ll(x.se);
return r;
}
bool isvalid(ii x)
{
if(x.fi >= 2 && x.fi <= h - 1 && x.se >= 2 && x.se <= w - 1) return true;
return false;
}
ll ans[10];
int test(ii x)
{
int cnt = 0;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(ma[hsh(ii(dx[i]+x.fi, dy[j]+x.se))]) cnt++;
}
}
return cnt;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin>>h>>w>>n;
vector<ii> color;
for(int i = 0; i < n; i++)
{
int u, v; cin >> u >> v;
ma[hsh(ii(u,v))] = true; color.pb(ii(u,v));
}
ans[0] = ll(h-2)*ll(w-2);
for(int i = 0; i < n; i++)
{
for(int j = 0; j < 3; j++)
{
for(int k = 0; k < 3; k++)
{
ii tmp = ii(color[i].fi+dx[j], color[i].se+dy[k]);
ll h = hsh(tmp);
if(isvalid(tmp) && !visited[h])
{
int q = test(tmp);
ans[q]++;
visited[h] = true;
}
}
}
}
for(int i = 1; i <= 9; i++)
{
ans[0] -= ans[i];
}
for(int i = 0; i <= 9; i++)
{
cout << ans[i] << '\n';
}
}
| 1 | 44,871,162 |
#include<bits/stdc++.h>
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
const int maxn = 3e5+20;
const int inf = 0x3f3f3f3f;
const int modd = 1e9+7;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}
template <class T> inline void sc(T &x){char c;x=0;while((c=getchar())<'0');while(c>='0'&&c<='9')x=x*10+(c-48),c=getchar();}
inline ll gcd(ll a,ll b){ return b==0? a: gcd(b,a%b); }
inline ll exgcd(ll a,ll b,ll &x,ll &y){ll d; (b==0? (x=1,y=0,d=a): (d=exgcd(b,a%b,y,x),y-=a/b*x)); return d;}
inline ll qpow(ll a,ll n){ll sum=1;while(n){if(n&1)sum=sum*a%modd;a=a*a%modd;n>>=1;}return sum;}
inline ll qmul(ll a,ll n){ll sum=0;while(n){if(n&1)sum=(sum+a)%modd;a=(a+a)%modd;n>>=1;}return sum;}
inline ll inv(ll a) {return qpow(a,modd-2);}
int dp[105][105];
char mp[105][105];
int n,m;
int dfs(int x,int y)
{
if(dp[x][y]!=-1) return dp[x][y];
if(x==n) dp[x][y]=dfs(x,y+1)+(mp[x][y]!=mp[x][y+1]&&mp[x][y]=='#');
else if(y==m) dp[x][y]=dfs(x+1,y)+(mp[x][y]!=mp[x+1][y]&&mp[x][y]=='#');
else dp[x][y]=min( (mp[x][y]!=mp[x+1][y]&&mp[x][y]=='#')+dfs(x+1,y) , (mp[x][y]!=mp[x][y+1]&&mp[x][y]=='#')+dfs(x,y+1) );
return dp[x][y];
}
int main()
{
memset(dp,-1,sizeof(dp));
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%s",mp[i]+1);
dp[n][m]=(mp[n][m]=='#');
dfs(1,1);
printf("%d\n",dp[1][1]);
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)
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 (a > b) { a = b; return true; } return false; }
template <class T> string join(const T &v, const string delim = ",")
{
if (v.empty())
return "";
ostringstream res;
res << v[0];
for (int i = 1; i < v.size(); i++)
{
res << delim << v[i];
}
return res.str();
}
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif
#pragma endregion Macros
int main()
{
int H,W;
cin >> H >> W;
vector<string> s(H);
rep(i, H) cin >> s[i];
const int INF = 100100100;
vector<vector<int>> c(H, vector<int>(W, INF));
queue<tuple<int,int>> q;
q.push(make_tuple(0,0));
c[0][0] = 0;
int dh[] = {0, 1};
int dw[] = {1, 0};
while(!q.empty()){
auto p = q.front();
q.pop();
int h = get<0>(p);
int w = get<1>(p);
int cost = c[h][w];
for(int i=0;i<2;i++){
int nh = h + dh[i];
int nw = w+dw[i];
if(nh < H && nw < W) {
int a = (s[h][w] == s[nh][nw] ? 0 : 1);
if(chmin(c[nh][nw], c[h][w]+a)){
q.push(make_tuple(nh, nw));
}
}
}
}
int ans = c[H - 1][W - 1];
if (s[0][0] == '#' && s[H - 1][W - 1] == '#'){
ans = ans / 2 + 1;
} else if(s[0][0] == '.' && s[H - 1][W - 1] == '.'){
ans = ans / 2;
}else{
ans = (ans + 1) / 2;
}
cout << ans << endl;
}
| 1 | 62,480,152 |
#include<stdio.h>
#include<vector>
using namespace std;
const int V_MAX = 10000;
int main() {
int v, e;
int table[V_MAX] = { 0 };
vector<int> edge[V_MAX];
vector<int> ans;
scanf("%d %d", &v, &e);
for (int i = 0; i < e; i++) {
int s, t;
scanf("%d %d", &s, &t);
edge[s].push_back(t);
table[t]++;
}
for (int i = 0; i < v; i++) {
if (table[i] == 0) {
ans.push_back(i);
}
}
for (int i = 0; i < ans.size();i++) {
vector<int> e = edge[ans[i]];
for (int j = 0; j < e.size(); j++) {
if (--(table[e[j]]) == 0) {
ans.push_back(e[j]);
}
}
}
for (vector<int>::iterator it = ans.begin(); it != ans.end(); it++) {
printf("%d\n", *it);
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
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 FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
const ll mod = 1e9 + 7;
const ll inf = 1e18;
void vprint(vector<ll> A){
ll L = A.size();
FOR(i, 0, L){
if(i) cout << ' ';
cout << A[i];
}
cout << endl;
}
VI topological_sort(VV& G){
ll N = G.size();
VI IN(N, 0);
REP(i, N){
for(ll to : G[i]){
IN[to]++;
}
}
stack<ll> st;
REP(i, N){
if(IN[i]==0) st.push(i);
}
VI ret;
while(!st.empty()){
ll i = st.top();
st.pop();
ret.push_back(i);
for(ll to : G[i]){
IN[to]--;
if(IN[to]==0){
st.push(to);
}
}
}
for(ll in : IN){
if(in!=0){
VI empty_vector;
return empty_vector;
}
}
return ret;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll V, E;
cin >> V >> E;
VV G;
G.resize(V);
REP(i, E){
ll s, t;
cin >> s >> t;
G[s].push_back(t);
}
auto A = topological_sort(G);
for(ll a : A){
p(a);
}
return 0;
}
| 1 | 66,932,500 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int N;
cin >> N;
int counter = 0;
for (int i = 1; i <= N; i++)
{
if (i < 10)
{
counter++;
}
else if (i >= 100 && i <= 999)
{
counter++;
}
else if (i >= 10000 && i <= 99999)
{
counter++;
}
}
cout << counter << endl;
return 0;
}
|
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;
const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= n; i++) {
int cnt = 0;
int num = i;
while (num > 0) {
cnt++;
num /= 10;
}
if (cnt % 2 == 1) {
ans++;
}
}
cout << ans << endl;
}
| 1 | 44,316,849 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main()
{
int x, a;
cin >> x >> a;
if (x < a)
cout << "0\n";
else
cout << "10\n";
return 0;
}
|
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
char tolower(char c) {return (c + 0x20);}
char toupr(char c) {return (c - 0x20);}
int main()
{
int X, A; cin >> X >> A;
if(X<A) cout << "0" << endl;
else cout << "10" << endl;
}
| 1 | 56,835,591 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,l;
cin>>n>>l;
string s[n];
for(int i=0;i<n;i++) {
cin>>s[i];
}
sort(s,s+n);
for(int i=0;i<n;i++) {
cout<<s[i];
}
return 0;
}
|
#include<bits/stdc++.h>
#define ls ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define __ <<" "<<
#define case(z) "Case " << z++ << ": "
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define quit return 0
using namespace std;
void showmyDS(set<int> ds)
{
set<int> ::iterator it;
for (it=ds.begin();it!=ds.end();it++)
{
cout << *it << endl ;
}
cout << endl;
}
int main()
{
ls
int n,l,i;
cin >> n >> l ;
string a[n];
for(i=0;i<n;i++)
cin >> a[i];
sort(a,a+n);
for(i=0;i<n;i++)
cout << a[i];
quit;
}
| 1 | 79,975,097 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
string s;
string b;
int cnt = 0;
cin >> s;
cin >> b;
rep(i, s.size()) {
if(s[i] != b[i]) {
cnt++;
}
}
cout << cnt << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main(){
string s;
string v;
int count = 0;
cin >> s >> v;
for(int i = 0; i < s.length(); i++){
if (s[i] != v[i]){
count++;
}
}
cout << count << endl;
return 0;
}
| 1 | 3,267,379 |
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979
typedef long long i64;
typedef pair<i64,i64> P;
inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int n, a[101010];
void solve(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
}
sort(a,a+n);
i64 ans = n, cnt = a[0];
for(int i = 1; i < n; i++){
if(cnt*2 < a[i]) ans = n-i;
cnt += a[i];
}
cout << ans << endl;
}
int main(){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
int t = 1;
while(t--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;
int main() {
ll N; cin >> N;
vector<ll> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
vector<ll> sums(N + 1);
for (int i = 0; i < N; i++) {
sums[i + 1] = a[i] + sums[i];
}
ll ans = 1;
for (int i = N - 1; i >= 0; i--) {
if (2*sums[i] >= a[i])
ans++;
else break;
}
cout << ans << endl;
}
| 1 | 59,482,609 |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; 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;
}
const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;
ll N, M;
ll S[2010], T[2010];
ll dp[2010][2010];
ll cum[2010][2010];
int main() {
cin >> N >> M;
rep(i, 0, N) { cin >> S[i]; }
S[N] = -1;
rep(i, 0, M) { cin >> T[i]; }
T[M] = -1;
dp[0][0] = 1;
cum[0][0] = dp[0][0];
repe(i, 1, N) { cum[i][0] = cum[i - 1][0]; }
repe(i, 1, M) { cum[0][i] = cum[0][i - 1]; }
repe(i, 0, N) {
repe(j, 0, M) {
if (S[i] != T[j]) {
dp[i + 1][j + 1] = 0;
} else {
dp[i + 1][j + 1] = cum[i][j];
}
cum[i + 1][j + 1] =
dp[i + 1][j + 1] + cum[i + 1][j] + cum[i][j + 1] - cum[i][j] + MOD;
cum[i + 1][j + 1] %= MOD;
}
}
cout << dp[N + 1][M + 1];
}
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 2006
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define MOD 1000000007
ll dp[N][N];
int main(){
int n,m;
cin>>n>>m;
vector<int> S(n);
vector<int> T(m);
REP(i,n){
cin>>S[i];
}
REP(i,m){
cin>>T[i];
}
REP(i,N){
dp[0][i]=1;
dp[i][0]=1;
}
REP(i,n){
REP(j,m){
if(S[i]==T[j]){
dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1])%MOD;
}
else{
dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]-dp[i][j])%MOD;
}
}
}
if(dp[n][m]<0) dp[n][m]+=MOD;
OUT(dp[n][m]);
return 0;
}
| 1 | 97,455,920 |
#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>;
int f(int i)
{
if (i % 2 == 0)
return i / 2;
else
return 3 * i + 1;
}
int main()
{
int s;
cin >> s;
vector<int> a;
for (int i = 1; i <= 1000000; i++)
{
if (i == 1)
a.push_back(s);
else
{
int ai = f(a[i - 2]);
int cnt = count(a.begin(), a.end(), ai);
if (cnt > 0)
{
cout << i << endl;
return 0;
}
else
a.push_back(ai);
}
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int hoge(int n) {
if (n % 2 == 0)
return n / 2;
else
return 3 * n + 1;
}
int main() {
int s;
cin >> s;
set<int> cont;
cont.insert(s);
int last = s;
for (int i = 2;; ++i) {
last = hoge(last);
if (cont.find(last) == cont.end()) {
cont.insert(last);
continue;
}
cout << i << endl;
break;
}
}
| 1 | 68,354,357 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#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 ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<pii> v(n);
REP(i, n) cin >> v[i].first >> v[i].second;
sort(ALL(v),
[](const pii &x, const pii &y) { return x.second > y.second; });
set<int> st;
priority_queue<int, vector<int>, greater<int>> q;
ll sum = 0;
REP(i, k) {
if (st.count(v[i].first) == 0) {
st.insert(v[i].first);
} else {
q.push(v[i].second);
}
sum += v[i].second;
}
ll maxv = sum + st.size() * st.size();
FOR(i, k, n) {
if (q.empty())
break;
if (st.count(v[i].first) == 0) {
st.insert(v[i].first);
sum += v[i].second - q.top();
q.pop();
maxv = max(maxv, (ll)(sum + st.size() * st.size()));
}
}
cout << maxv << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;
int main() {
ll N,K; cin >> N >> K;
vector<pair<ll,ll>> sushi(N);
REP(i,N){
ll t,d; cin >> t >> d;
sushi[i] = make_pair(d,t-1);
}
sort(ALL(sushi), greater<pair<ll,ll>>());
map<ll,ll> num;
priority_queue<pair<ll,ll>> S;
ll ans = 0;
FOR(i,K,N){
S.push(sushi[i]);
}
REP(i,K){
num[sushi[i].second]++;
ans += sushi[i].first;
}
ll f = ans;
ans += (ll)num.size()*(ll)num.size();
REPR(i,K-1){
if(S.empty()) break;
if(num[sushi[i].second]> 1){
while(!S.empty()){
auto top_sushi = S.top(); S.pop();
if(!num.count(top_sushi.second)){
f = f - sushi[i].first + top_sushi.first;
num[top_sushi.second]++;
num[sushi[i].second]--;
ll next_ans = f + (ll)num.size() * (ll)num.size();
sushi[i] = top_sushi;
ans = max(ans, next_ans);
break;
}
}
}
}
cout << ans << endl;
return 0;
}
| 1 | 23,958,007 |
#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>;
int main() {
int r;
cin >> r;
cout << pow(r,2);
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main() {
ios
#ifndef ONLINE_JUDGE
in;
out;
#endif
int n;
cin>>n;
cout<<(n*n)<<endl;
}
| 1 | 29,470,402 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+2;
map<int,int> idx;
vector<pair<int,int> > ans;
int n,ar[N],sz[N],sz1[N],ar1[N];
vector<int> adj[N];
void dfs(int x,int p){
sz[x]=1;
for(int i:adj[x]){
if(i!=p){
dfs(i,x);
sz[x]+=sz[i];
sz1[x]+=sz1[i]+sz[i];
}
}
}
void dfs1(int x,int p){
for(int i:adj[x]){
if(i!=p){
sz1[i]=sz1[x]+n-2*sz[i];
dfs1(i,x);
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int m,i,j,k,l;
cin>>n;
for(i=1;i<=n;i++){
cin>>ar[i];
ar1[i]=ar[i];
idx[ar[i]]=i;
sz[i]=1;
}
sort(ar+1,ar+1+n);
for(i=n;i>1;i--){
k=idx[ar[i]]; j=ar[i]+2*sz[k]-n; l=idx[j];
if(!l||j>=ar[i]){
cout<<"-1";
return 0;
}
adj[l].push_back(k);
adj[k].push_back(l);
sz[l]+=sz[k];
ans.push_back({k,l});
}
dfs(1,1);
dfs1(1,1);
for(i=1;i<=n;i++){
if(sz1[i]!=ar1[i]){
cout<<"-1";
return 0;
}
}
for(i=0;i<ans.size();i++){
cout<<ans[i].first<<' '<<ans[i].second<<'\n';
}
}
|
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) {cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl;}
using namespace std;
template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}
bool operator<(const TRI&_)const{return(fi==_.fi)?((se==_.se)?(th<_.th):(se<_.se)):(fi<_.fi);}};
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,TRI<S,T,U>&t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}
typedef pair<ll, ll> P;
const int MAX_N = 100005;
vector<int> G[MAX_N];
ll D;
void dfs(int u, int p, int d){
D += d;
for(int v : G[u]){
if(v != p) dfs(v, u, d+1);
}
}
unordered_map<ll, int> mp;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
set<P> st;
ll ch = 0;
rep(i,n){
ll d;
cin >> d;
if(i == 0) ch = d;
mp[d] = i;
st.insert(P(d, 1));
}
vector<pair<int, int> > vec;
while(len(st) > 1){
auto p = *(--st.end());
st.erase(--st.end());
auto it = st.lower_bound(P(p.fi+2*p.se-n, -INF));
if(it->fi != p.fi+2*p.se-n){
cout << "-1\n";
return 0;
}
G[mp[p.fi]].pb(mp[it->fi]);
G[mp[it->fi]].pb(mp[p.fi]);
vec.emplace_back(mp[p.fi], mp[it->fi]);
P nw = P(it->fi, it->se + p.se);
st.erase(it);
st.insert(nw);
}
dfs(0, -1, 0);
if(D != ch){
cout << "-1\n";
return 0;
}
rep(i,n-1){
cout << vec[i].fi+1 << " " << vec[i].se+1 << "\n";
}
return 0;
}
| 1 | 45,271,690 |
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int W, H;
string s[30];
using P = pair<int, int>;
void solve() {
P init;
rep(i, H) rep(j, W) if (s[i][j] == '@') init = P(i, j);
set<P> visited;
queue<P> que;
que.push(init);
visited.insert(init);
while (que.size()) {
auto p = que.front();
que.pop();
rep(k, 4) {
auto np = p;
np.first += dy[k];
np.second += dx[k];
if (np.first < 0 || np.second < 0) continue;
if (H <= np.first || W <= np.second) continue;
if (visited.count(np)) continue;
if (s[np.first][np.second] == '#') continue;
que.push(np);
visited.insert(np);
}
}
cout << visited.size() << endl;
}
int main() {
while (cin >> W >> H, W) {
rep(i, H) cin >> s[i];
solve();
}
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <stack>
using namespace std;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int main() {
int yoko,tate,px,py;
while(cin>>yoko>>tate &&yoko){
int m[25][25];
string st;
for(int i=1;i<tate+1;i++){
cin>>st;
for(int j=1;j<yoko+1;j++){
if(st[j-1]=='#') m[i][j]=-1;
else if(st[j-1]=='.') m[i][j]=0;
else if(st[j-1]=='@'){
m[i][j]=1;
px=i;
py=j;
}
}
}
int ans=1;
stack<pair<int,int> > s;
s.push(make_pair(px,py));
while(s.empty()==false){
px=s.top().first;
py=s.top().second;
s.pop();
for(int i=0;i<4;i++){
if(0<px+dx[i] && px+dx[i]<tate+1 && py+dy[i]>0 && py+dy[i]<yoko+1){
if(m[px+dx[i]][py+dy[i]]==0){
m[px+dx[i]][py+dy[i]]=1;
s.push(make_pair(px+dx[i],py+dy[i]));
ans++;
}
}}
}
cout<<ans<<endl;
}
return 0;
}
| 1 | 82,952,587 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<int> A(n);
vector<ll> cnt(n);
rep(i, n) {
cin >> A[i];
cnt[--A[i]]++;
}
ll sum = 0;
rep(i, n) sum += cnt[i] * (cnt[i]-1) / 2;
vector<ll> ans(n);
rep(i, n) {
ans[i] = sum - cnt[i] * (cnt[i]-1) / 2 + (cnt[i]-1) * (cnt[i]-2) / 2;
}
rep(i, n) cout << ans[A[i]] << "\n";
return 0;
}
|
#include <iostream>
#include <vector>
#include <map>
int main(){
int N;
std::cin >> N;
std::vector<int> A(N);
for (int i=0; i<N; i++){
std::cin >> A.at(i);
}
std::map<int, long long int> mp;
for (int i=0; i<N; i++){
mp[A.at(i)]++;
}
long long int sum = 0;
for (auto x : mp){
sum = sum + x.second * (x.second-1) /2;
}
for (int i=0; i<N; i++){
int n = mp[A.at(i)];
std::cout << sum-(n-1) << std::endl;
}
}
| 1 | 2,123,852 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int64_t> Lucas(N + 1);
Lucas.at(0) = 2;
Lucas.at(1) = 1;
if ( N > 1 ) {
for ( int i = 2; i < N + 1; i++ ) {
Lucas.at(i) = Lucas.at(i-1) + Lucas.at(i-2);
}
}
cout << Lucas.at(N);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N;
cin >> N;
if (N == 0) {
cout << 2 << endl;
return 0;
} else if (N == 1) {
cout << 1 << endl;
return 0;
}
vector<int64_t> lucas(N+1);
lucas.at(0) = 2;
lucas.at(1) = 1;
for (int64_t i = 2; i < N+1; i++) {
lucas.at(i) = lucas.at(i-1) + lucas.at(i-2);
}
cout << lucas.at(N) << endl;
}
| 1 | 65,988,408 |
#include <bits/stdc++.h>
using namespace std;
queue<pair<int,int> > qu;
vector<int> v[111];
int root;
int b;
int d[111];
pair<int, int> pa;
int g;
void wide(int num){
memset(d,-1,sizeof(d));
d[num] = 0;
qu.push(make_pair(num,d[1]));
while(!qu.empty()){
pa = qu.front();
qu.pop();
int id = pa.first;
for(int i = 0; i < (int)v[id].size(); i++){
if(d[v[id][i]] == -1){
d[v[id][i]] = pa.second + 1;
qu.push(make_pair(v[id][i],d[v[id][i]]));
}
}
}
for(int i = 1; i <= g; i++){
cout << i << " " << d[i] << endl;
}
}
int main(){
cin >> g;
int n;
for(int i = 0; i < g; i++){
cin >> n >> b;
for(int j = 0; j < b; j++){
cin >> root;
v[n].push_back(root);
}
}
wide(1);
}
|
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())
int main(){
int n;
cin >> n;
set<int> A[n+1];
int v1, v2, deg;
r(i, n){
cin >> v1 >> deg;
r(j, deg){
cin >> v2;
A[v1].insert(v2);
}
}
queue<int> s;
s.push(1);
int dist[n+1]{0, 1};
while(!s.empty()){
int v1 = s.front(); s.pop();
for(int v2 : A[v1]){
if(!dist[v2]){
s.push(v2);
dist[v2] = dist[v1]+1;
}
}
}
for(int i = 1; i <= n; i++)
printf("%d %d\n", i, dist[i]-1);
return 0;
}
| 1 | 87,085,218 |
# include <iostream>
# include <cstring>
using namespace std;
const int mod = 1e9 + 7;
# define ll long long
ll mul(ll a, ll b){
return ((a%mod) * (b%mod)) % mod;
}
int main(){
int n;
cin >> n;
string s;
cin >> s;
int occ[26];
memset(occ, 0, sizeof(occ));
for(char c : s) occ[c-'a']++;
ll ans = 1;
for(char c='a'; c<='z'; c++){
ans = mul(ans, occ[c-'a']+1);
}
ans = (ans + mod - 1) % mod;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
const long long MOD = 1e9 + 7;
int main()
{
int N;
string S;
cin >> N >> S;
ll ans = 1;
map<char, ll> mp;
rep(i, N) mp[S[i]]++;
rep(i, 26) {
ans *= mp[i + 'a'] + 1;
ans %= MOD;
}
cout << ans - 1 << endl;
return 0;
}
| 1 | 27,728,282 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include <iomanip>
using namespace std;
struct Point
{
double x;
double y;
};
struct Edge{
Point start;
Point end;
void make(Point start,Point end)
{
this->start=start;
this->end=end;
}
};
Point rot60(Point a,Point b)
{
Point rot;
rot.x=b.x-a.x; rot.y=b.y-a.y;
double length=sqrt(rot.x*rot.x+rot.y*rot.y);
double slope=(rot.y)/(rot.x);
double deg=atan(slope)+M_PI/3;
if(a.x>=b.x){
deg+=M_PI;
}
rot.x=length*cos(deg)+a.x;
rot.y=length*sin(deg)+a.y;
return rot;
}
vector<Edge> KochCurve(vector<Edge>& edges,int& count)
{
if(count==0){
return edges;
}else{
int n=edges.size();
vector<Edge> results(n*4);
Point s,t,u;
for(int i=0;i<n;i++){
Point s,t,u;
s.x=(edges[i].end.x+2*edges[i].start.x)/3;
s.y=(edges[i].end.y+2*edges[i].start.y)/3;
t.x=(2*edges[i].end.x+edges[i].start.x)/3;
t.y=(2*edges[i].end.y+edges[i].start.y)/3;
u=rot60(s,t);
results[i*4].make(edges[i].start,s);
results[i*4+1].make(s,u);
results[i*4+2].make(u,t);
results[i*4+3].make(t,edges[i].end);
}
count--;
results=KochCurve(results,count);
return results;
}
}
int main()
{
int n;
cin>>n;
int count=n;
vector<Edge> edges(1);
edges[0].start.x=0; edges[0].start.y=0;
edges[0].end.x=100; edges[0].end.y=0;
edges=KochCurve(edges,count);
for(int i=0;i<edges.size();i++){
cout<<fixed;
cout<<setprecision(8)<< edges[i].start.x<<" "<<edges[i].start.y<<endl;
}
cout<<fixed;
cout<<setprecision(8)<<edges[edges.size()-1].end.x<<" "<<edges[edges.size()-1].end.y<<endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define N 8
using namespace std;
struct point{
double x,y;
};
void koch(int d, point p1, point p2){
point s,u,t;
if (d==0) return;
s.x=(2.0*p1.x+p2.x)/3;
s.y=(2.0*p1.y+p2.y)/3;
t.x=(p1.x+2.0*p2.x)/3;
t.y=(p1.y+2.0*p2.y)/3;
u.x=(t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
u.y=(t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;
koch(d-1, p1, s);
cout << fixed << setprecision(N) << s.x << " " << s.y << endl;
koch(d-1, s, u);
cout << fixed << setprecision(N) << u.x << " " << u.y << endl;
koch(d-1, u, t);
cout << fixed << setprecision(N) << t.x << " " << t.y << endl;
koch(d-1, t, p2);
}
int main(){
int n;
cin >> n;
point p1,p2;
p1.x=p1.y=0;
p2.x=100.0;
p2.y=0;
cout << fixed <<setprecision(N) << p1.x << " " << p1.y << endl;
koch(n,p1,p2);
cout << fixed <<setprecision(N) << p2.x << " " << p2.y << endl;
return 0;
}
| 1 | 12,823,405 |
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef vector<pll> vpl;
typedef vector<pi> vpi;
typedef queue<ll> ql;
typedef queue<int> qi;
template <class T>
void printv(vector<T> vc)
{
for (auto e : vc)
cout << e << " ";
cout << endl;
}
template <class T>
void printvv(vector<T> vvc)
{
for (auto vc : vvc)
{
for (auto e : vc)
cout << e << " ";
cout << endl;
}
}
template <class T>
void printvp(vector<pair<T, T> > vp)
{
for (auto pT : vp)
cout << pT.first << " " << pT.second << endl;
}
int main() {
string s;
cin >> s;
reverse(s.begin(), s.end());
vs v = {"dream", "dreamer", "erase", "eraser"};
for (int i = 0; i < v.size(); ++i) {
reverse(v[i].begin(), v[i].end());
}
auto a = true;
for (int i = 0; i < s.size();) {
auto b = false;
for (int j = 0; j < v.size(); ++j) {
const auto target = v[j];
if (s.substr(i, target.size()) == target) {
i += target.size();
b = true;
}
}
if (!b) {
a = false;
break;
}
}
cout << (a ? "YES" : "NO") << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
string s,t;
cin >> s;
string ans;
reverse(s.begin(),s.end());
ll i=0;
while(1){
string u;
bool is=false;
if(i>=s.size()){
break;
}
u=s.substr(i,5);
if(u=="maerd" || u=="esare"){
is=true;
i+=5;
continue;
}
u=s.substr(i,6);
if(u=="resare"){
is=true;
i+=6;
continue;
}
u=s.substr(i,7);
if(u=="remaerd"){
is=true;
i+=7;
continue;
}
if(!is){
cout << "NO";
return 0;
}
}
cout << "YES";
}
| 1 | 94,258,245 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long a;
cin >> a;
long long b;
cin >> b;
if(a>b) {
cout << "safe" << '\n';
} else {
cout << "unsafe" << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
int S, W;
cin >> S >> W;
cout << ((W >= S)? "unsafe" : "safe") << '\n';
return 0;
}
| 1 | 57,392,892 |
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define ft first
#define sd second
#define flag bool fl=true
#define mod 1000000007
#define N 100001
#define MX 1000000001
#define MXX 1000000000000000001
#define pb push_back
#define For(i, a, b) for(int i=a;i<=b;i++)
#define T int t, qq=0; cin>>t; while(qq++<t)
#define fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define scarr(array, size) for(int i=0;i<size;i++) cin>>array[i]
#define deg(rad) (rad*180.0)/pi
#define pi acos(-1)
#define log(n) (int)log2(n)
#define logg(a)(b) log(b)/log(a)
int main()
{
int n;
cin>>n;
ll a[n-1];
for(int i=0;i<n-1;i++) cin>>a[i];
ll sum=a[0];
for(int i=1;i<n-1;i++) sum+=min(a[i-1], a[i]);
sum+=a[n-2];
cout<<sum<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0;
int N;
cin >> N;
vector<int> B(N - 1);
for(int i = 0; i < N - 1; i++) {
cin >> B[i];
}
vector<int> A(N, 1000000);
for(int i = N - 2; i >= 0; i--) {
A[i + 1] = min(A[i + 1], B[i]);
A[i] = min(A[i], B[i]);
}
ans = accumulate(A.begin(), A.end(), 0);
cout << ans << endl;
}
| 1 | 13,145,250 |
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n == 0) break;
vector<int> array(n);
for (int i = 0; i < n; i++) {
cin >> array.at(i);
}
long max = array.at(0);
for (int j = 0; j < n; j++) {
long total = 0;
for (int k = 0; k < n - j; k++) {
total += array.at(j + k);
if (total > max) max = total;
}
}
cout << max << endl;
}
return 0;
}
|
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
lint n;
vector<lint> a;
vector<lint> s;
lint ans;
cin >> n;
while(true){
ans = -LINF;
a.clear();
a.resize(n);
s.clear();
s.resize(n+1);
s[0] = 0;
for (int i=0; i<n; ++i){
cin >> a[i];
}
for (int i=0; i<n; ++i){
s[i+1] = s[i] + a[i];
}
for (int i=1; i<=n; ++i){
for (int j=i; j<=n; ++j){
ans = max(ans, s[j] - s[i-1]);
}
}
cout << ans << endl;
cin >> n;
if(n == 0){
break;
}
}
return 0;
}
| 1 | 27,873,033 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
int n, k;
cin >> n >> k;
int ans = k;
rep(i, n-1) {
ans *= (k-1);
}
cout << ans << endl;
}
|
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int N,K;
cin >> N >> K;
cout << (int)round(K * pow(K-1,N-1)) << '\n';
}
| 1 | 4,054,050 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using Graph = vector<vector<int>>;
using Edge = map<pair<int,int>,int>;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
ll gcd(ll a,ll b){
if (a%b == 0) return(b);
else return(gcd(b, a%b));
}
ll lcm(ll a, ll b){
return a*b/gcd(a, b);
}
int main()
{
cout << fixed << setprecision(15);
char c;
cin >> c;
if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
cout << "vowel" << endl;
}
else{
cout << "consonant" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;
int main(){
char c;
cin>>c;
if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){
cout<<"vowel"<<endl;
}
else{
cout<<"consonant"<<endl;
}
}
| 1 | 43,496,172 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
string s, t; cin >> s >> t;
rep(i, n) cout << s[i] << t[i];
cout << endk;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string a, b, S;
cin >> a >> b;
for (int i = 0; i < N; i++) {
char c_a = a.at(i);
char c_b = b.at(i);
S = S + c_a + c_b;
}
cout << S << endl;
}
| 1 | 36,095,702 |
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
enum Loc{
Left,
Right,
Top,
Bottom,
};
int N;
int* boss,*height;
int get_boss(int id){
if(boss[id] == id)return id;
else{
return boss[id] = get_boss(boss[id]);
}
}
int isSame(int x,int y){
return get_boss(x) == get_boss(y);
}
void unite(int x,int y){
int boss_x = get_boss(x);
int boss_y = get_boss(y);
if(boss_x == boss_y)return;
if(height[x] > height[y]){
boss[boss_y] = boss_x;
}else if(height[x] < height[y]){
boss[boss_x] = boss_y;
}else{
boss[boss_y] = boss_x;
height[x]++;
}
}
int main(){
int Q,command,x,y;
scanf("%d %d",&N,&Q);
boss = new int[N];
height = new int[N];
for(int i = 0; i < N; i++){
boss[i] = i;
height[i] = 1;
}
for(int i = 0; i < Q; i++){
scanf("%d %d %d",&command,&x,&y);
if(command == 0){
unite(x,y);
}else{
if(isSame(x,y)){
printf("1\n");
}else{
printf("0\n");
}
}
}
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MAX_N 100000
int par[MAX_N];
int rank[MAX_N];
void init(int n){
for(int i = 0 ; i < n ; i++){
par[i] = i;
rank[i] = 0;
}
}
int find(int x){
if(par[x] == x) return x;
else return par[x] = find(par[x]);
}
void unite(int x, int y){
x = find(x);
y = find(y);
if(x == y) return;
if(rank[x] == rank[y]) par[x] = y;
else par[y] = x;
if(rank[x] == rank[y]) rank[x]++;
}
bool same(int x, int y){
return find(x) == find(y);
}
int main(){
int n,q;
cin>>n>>q;
init(n);
int i,j;
rep(i,q){
int p,a,b;
cin>>p>>a>>b;
if(p)
if(same(a,b))cout<<1<<endl;
else cout<<0<<endl;
else
unite(a,b);
}
}
| 1 | 93,249,017 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
int n;
cin >> n;
int a[n];
rep(i,n)cin >> a[i];
vector<pair<int,int>>dataa(110000);
vector<pair<int,int>>datab(110000);
rep(i,110000){
dataa[i].second = i;
datab[i].second = i;
dataa[i].first = 0;
datab[i].first = 0;
}
rep(i,n){
if(i%2==0){
datab[a[i]].first++;
}else {
dataa[a[i]].first++;
}
}
sort(all(dataa));
reverse(all(dataa));
sort(all(datab));
reverse(all(datab));
int x = dataa[0].second;
int y = datab[0].second;
if(x == y){
if(dataa[1].first < datab[1].first)y = datab[1].second;
else x = dataa.at(1).second;
}
int ans = 0;
rep(i,n){
if(i%2==0){
if(a[i]!=y)ans++;
}else{
if(a[i]!=x)ans++;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
#define ng 100010
typedef pair<ll,ll> pair;
int main(){
ll n;
cin >> n;
ll m = n / 2;
ll even[ng];
ll odd[ng];
ll max1,max2;
max1 = 0;max2 = 0;
ll maxeven,maxodd;
for(ll i = 0; i < ng; i++){
even[i] = 0;
odd[i] = 0;
}
for(ll i = 0; i < n; i++){
ll temp;
cin >> temp;
if(i % 2 == 0){
even[temp]++;
if(max1 < even[temp]){
max1 = even[temp];
maxeven = temp;
}
}
else{
odd[temp]++;
if(max2 < odd[temp]){
max2 = odd[temp];
maxodd = temp;
}
}
}
sort(even,even+ng,greater<>());
sort(odd,odd+ng,greater<>());
ll ans = 0;
if(maxeven != maxodd){
ans = n - max1 - max2;
}
else{
ans = n-max(max1+odd[1],max2+even[1]);
}
cout << ans << endl;
}
| 1 | 99,018,109 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()
ll gcd(ll a, ll b);
ll sum(int n);
void go(){
string s;cin>>s;
set<char> cnt;
for(char ch : s) cnt.insert(ch);
string ans = cnt.size()==2?"Yes":"No";
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
go();
return 0;
}
ll gcd(ll a, ll b){
if(b == 0) return a;
return gcd(b, a % b);
}
ll sum(int n){
if(n == 0){
return n;
}else{
return sum(n/10) + n%10;
}
}
|
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
string S;
cin >> S;
vector<int> vec(26, 0);
REP(i, 4) {
vec[S[i] - 'A']++;
}
REP(i, vec.size()) {
if (vec[i] && vec[i] != 2) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
| 1 | 60,074,140 |
#include<bits/stdc++.h>
using namespace std;
int depth, s, n;
void solve(int d, int x, int sum){
if(d==0 && sum==s){n++; return;}
for(int i=x+1; i<10; i++){
solve(d-1, i, sum+i);
}
}
int main(){
while(cin>>depth>>s){
if(depth==0 && s==0)break;
n=0;
solve(depth, -1, 0);
cout<<n<<endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int n,k,count;
void dfs(int i,int sum,int num)
{
if(num == n)
{
if(sum == k)
{
count++;
}
return;
}
if(i == 10)
{
return;
}
dfs(i+1,sum,num);
dfs(i+1,sum+i,num+1);
}
int main()
{
while(cin >> n >> k)
{
if(n == 0 && k == 0) break;
count = 0;
dfs(0,0,0);
cout << count << endl;
}
return 0;
}
| 1 | 28,890,760 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
int main(){
int n;
cin >> n;
vector<string> s(n);
rep(i,n)cin >> s.at(i);
map<char ,int > alph;
for(int i='a';i<='z';i++){
char x=char(i);
alph[x]=100;
}
rep(i,n){
int m=s.at(i).size();
map<char ,int > alp;
for(int i='a';i<='z';i++){
char x=char(i);
alp[x]=0;
}
rep(j,m){
alp[s.at(i).at(j)]++;
}
for(int i='a';i<='z';i++){
char x=char(i);
alph[x]=min(alph[x],alp[x]);
}
}
for(int i='a';i<='z';i++){
char x=char(i);
rep(j,alph[x]){
cout << x ;
}
}
cout << endl;
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<string> v(n);
rep(i,n) cin >> v[i];
string m = v[0];
rep(i,n) if (v[i].size() < m.size()) m = v[i];
map<char,int> mp;
rep(i,m.size()) mp[m[i]]++;
for (auto p : mp) {
bool ok = true;
int num = p.second;
rep(i,n) {
string t = v[i];
int cnt = 0;
rep(j,t.size()) if (t[j] == p.first) cnt++;
if (cnt == 0) ok = false;
else chmin(num,cnt);
}
if (!ok) continue;
else rep(i,num) cout << p.first;
}
cout << endl;
return 0;
}
| 1 | 9,002,323 |
#include<iostream>
using namespace std;
int main(){
int a, b, c;
int A[10000] = { 0 };
int M;
int N = 0;
cin >> a >> b >> c;
for (int i = 0; i <= b - a; i++){
A[i] = a + i;
M = c%A[i];
if (M == 0){
N = N + 1;
}
}
cout << N << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main(){
int a,b,c,d,i;
i=0;
cin >> a >> b >> c;
while(a<=b){
d=c%a;
if(d!=0){
}
else{
i++;
}
a++;
}
cout << i << endl;
}
| 1 | 66,924,338 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.