code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 45
101M
|
---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
int main(void){
int h,w,i=0,j,c=0,k,a,b;
cin >> k >> a >> b;
while(1)
{
i++;
if(a<=k*i && b>=k*i)
{
cout << "OK" << endl;
return 0;
}
if(k*i>1000)
{
break;
}
}
cout << "NG" << endl;
return 0;
}
|
#include <stdio.h>
int main(){
int K, A, B;
scanf("%d", &K);
scanf("%d %d", &A, &B);
int L = B - A;
int count = 0;
for(int i = 0; i <= L ; i++){
int total = A % K;
A++;
if(total == 0){
count++;
}
else{
count = count + 0;
}
}
if(count > 0){
printf("OK\n");
}
else{
printf("NG\n");
}
return 0;
}
| 1 | 59,470,228 |
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);
int main() {
string s;
cin >> s;
ll res = 0;
ll cnt = 0;
for(ll i = 0; i < s.size(); i++) {
if (s[i] == 'B') {
cnt++;
} else {
res += cnt;
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main()
{
string s;
cin >> s;
int n = s.length();
ll ans = 0, b = 0;
rep(i, n)
{
if (s[i] == 'B')
b++;
else
ans += b;
}
cout << ans << endl;
}
| 1 | 80,537,710 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int H,W;
cin >> H >> W;
vector<string> A(H);
for(int i=0;i<H;i++){
cin >> A[i];
}
set<int> Hset,Wset;
for(int i=0;i<H;i++){
bool flag=true;
for(int j=0;j<W;j++){
if(A[i][j]=='#'){
flag=false;
break;
}
}
if(flag){
Hset.insert(i);
}
}
for(int i=0;i<W;i++){
bool flag=true;
for(int j=0;j<H;j++){
if(A[j][i]=='#'){
flag=false;
break;
}
}
if(flag){
Wset.insert(i);
}
}
for(int i=0;i<H;i++){
if(Hset.count(i)){
continue;
}
for(int j=0;j<W;j++){
if(Wset.count(j)){
continue;
}
cout << A[i][j];
}
cout << endl;
}
}
|
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
int h,w;cin>>h>>w;
vector<string> m(h);
for(int i=0;i<h;++i){
cin>>m[i];
}
vector<bool> hi(h,false);
vector<bool> wi(w,false);
for(int i=0;i<h;++i){
for(int j=0;j<w;++j){
if(m[i][j]=='#'){
hi[i]=true;
wi[j]=true;
}
}
}
for(int i=0;i<h;++i){
if(hi[i]){
for(int j=0;j<w;++j){
if(wi[j]){
cout<<m[i][j];
}
}
cout<<endl;
}
}
return 0;
}
| 1 | 4,351,783 |
#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();
template<typename T>
vector<T> make_vec_nd(T init, ll size) {
return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
auto inner = make_vec_nd(init, rest...);
return vector<decltype(inner)>(size, inner);
}
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)
void calc_grundy(ll now, vector<vector<ll>>& graph, vector<ll>& grundy, vector<bool>& visited) {
visited[now] = true;
ll g = 0;
for (ll to : graph[now]) {
if (visited[to]) {
continue;
}
calc_grundy(to, graph, grundy, visited);
g = g ^ (grundy[to] + 1);
}
grundy[now] = g;
}
int main() {
ll N;
cin >> N;
vector<vector<ll>> graph(N);
rep(i,0,N-1) {
ll x, y;
cin >> x >> y;
x--;
y--;
graph[x].push_back(y);
graph[y].push_back(x);
}
vector<bool> visited(N);
vector<ll> grundy(N);
calc_grundy(0, graph, grundy, visited);
if (grundy[0] == 0) {
cout << "Bob" << endl;
} else {
cout << "Alice" << endl;
}
}
|
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define REP(i, n) for(ll i = 0; i < n; i++)
vector<vector<ll>> g;
ll xorsum = 0;
ll dfs(ll now, ll par){
ll res = 0;
for(auto &child : g[now]){
if(child == par) continue;
res ^= dfs(child, now) + 1;
}
return res;
}
int main(){
ll n;
cin >> n;
g.resize(n);
REP(i, n - 1){
ll x, y;
cin >> x >> y;
x--; y--;
g[x].push_back(y);
g[y].push_back(x);
}
cout << (dfs(0, -1)? "Alice" : "Bob") << endl;
}
| 1 | 77,189,492 |
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(val) cerr << "Value " << #val << " : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ld epsilon = 10e-9;
const ll nax = 1e5+5;
ll n, m;
vector<ll>arr[nax];
bool vis[nax];
vector<ll>dist(nax);
int main(void){
IOS
cin >> n >> m;
for(int i=0;i<m;i++){
ll a, b;
cin >> a >> b;
arr[a].eb(b);
arr[b].eb(a);
}
if(arr[1].empty()){
cout << "No" << '\n';
return 0;
}
cout << "Yes" << '\n';
queue<ll>q;
q.push(1);
while(!q.empty()){
ll curr=q.front();
q.pop();
for(auto x:arr[curr]){
if(vis[x]) continue;
vis[x]=1;
dist[x]=curr;
q.push(x);
}
}
for(int i=2;i<=n;i++) cout << dist[i] << '\n';
}
|
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
vector<vector<ll>> v(n);
vector<ll> dis(n, (ll)INF), prev(n);
rep(i, 0, m)
{
int a, b;
cin >> a >> b;
--a, --b;
v[a].push_back(b);
v[b].push_back(a);
}
priority_queue<ll> q;
q.push(0);
dis[0] = 0;
ll cta = 1;
while (!q.empty())
{
int temp = q.top();
q.pop();
for (auto i : v[temp])
{
if (dis[i] > dis[temp] + 1)
dis[i] = dis[temp] + 1, q.push(i), prev[i] = temp, ++cta;
}
}
if (cta < n)
cout << "No" << endl;
else
{
cout << "Yes" << endl;
rep(i, 1, n) printf("%lld\n", prev[i] + 1);
}
}
| 1 | 70,370,234 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ll n, m;
cin >> n >> m;
vector<vector<ll>> hune(2, vector<ll>(n, 0));
for(ll i = 0; i < m; i++){
ll a,b;
cin >> a >> b;
if(min(a, b) == 1) hune[0][max(a, b) - 1] = 1;
if(max(a, b) == n) hune[1][min(a, b) - 1] = 1;
}
bool f = false;
for(ll i = 0; i < n; i++){
if(hune[0][i] + hune[1][i] == 2){
f = true;
break;
}
}
if(f) puts("POSSIBLE");
else puts("IMPOSSIBLE");
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
int n,m;
cin>>n>>m;
vector<int>to[n];
rep(i,m){
int a,b;
cin>>a>>b;
a--; b--;
to[a].push_back(b);
to[b].push_back(a);
}
for(int u:to[0]){
if(count(to[u].begin(),to[u].end(),n-1)!=0){
cout<<"POSSIBLE"<<endl;
return 0;
}
}
cout<<"IMPOSSIBLE"<<endl;
}
| 1 | 42,221,789 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int n_a = 0, n_b = 0;
for(int i = 0; i < 3; i++) {
char c;
cin >> c;
if(c == 'A') {
n_a++;
}
else {
n_b++;
}
}
if(n_a == 0 || n_b == 0) {
cout << "No\n";
}
else {
cout << "Yes\n";
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string S; cin >> S;
if(S.find("AAA") == 0 || S.find("BBB") == 0) cout << "No" << endl;
else cout << "Yes" << endl;
}
| 1 | 59,169,816 |
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
ll c = a;
while (a % b != 0) {
c = a % b;
a = b;
b = c;
}
return b;
}
int main() {
ll N, X;
cin >> N >> X;
cout << 3 * (N - gcd(N, X)) << endl;
}
|
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
char ch=getchar();
ll s=0,w=1;
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
ll n,x;
ll a,b,ans;
int main()
{
n=read(),x=read();
ans=n;
a=x,b=n-x;
while(true)
{
if(a<b)swap(a,b);
ans+=((a/b)*2)*b;if(a%b==0){ans-=b;break;}
a=a%b;
}
printf("%lld\n",ans);
return 0;
}
| 1 | 5,416,224 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) \
{ \
cout << x << ' '; \
} \
cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (b < a)
{
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<ll> a;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n>>m;
map<ll,ll>ma;
ma[1]=2;
ma[2]=5;
ma[3]=5;
ma[4]=4;
ma[5]=5;
ma[6]=6;
ma[7]=3;
ma[8]=7;
ma[9]=6;
for (int i = 0; i < m; i++)
{
ll temp;
cin >> temp;
a.push_back(temp);
}
vector<string> dp(n+10,"0");
dp[0]="";
rep(i,n+1){
if(dp[i]=="0")continue;
rep(j,m){
if(dp[i+ma[a[j]]].size()==dp[i].size()+1){
char temp=a[j]+'0';
string temp1=dp[i]+temp;
if(temp1>dp[i+ma[a[j]]]){
dp[i+ma[a[j]]]=temp1;
}
}
else{
if(dp[i+ma[a[j]]].size()<dp[i].size()+1){
char temp=a[j]+'0';
dp[i+ma[a[j]]]=dp[i]+temp;
}
}
}
}
cout << dp[n] << "\n";
}
|
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--)
#define RANGE(i,v) for(auto &(i):v)
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))
using LL = long long;
template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;
const int INF = 1999999999;
LL GCD(LL a,LL b){
LL t; LL r;
if(a<b){t=a;a=b;b=t;}
if(b==0){return a;}
while(a%b!=0){r=a%b;a=b;b=r;}
return b;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
int n,m;
cin>>n>>m;
Vi num = {0,2,5,5,4,5,6,3,7,6};
Vi a(m);
REP(i,m){
cin>>a[i];
}
sort(ALL(a),greater<int>());
Vi dp(10005,-INF);
dp[0] = 0;
REP2(i,1,n+1){
REP(j,m){
int ind = i-num[a[j]];
if(ind<0) continue;
chmax(dp[i],dp[ind]+1);
}
}
int digit = dp[n];
int matchi_num = n;
string ans = "";
REP(i,digit){
REP(j,m){
if(matchi_num-num[a[j]]<0) continue;
if(dp[matchi_num-num[a[j]]] == dp[matchi_num]-1){
ans += to_string(a[j]);
matchi_num -= num[a[j]];
break;
}
}
}
cout<<ans<<endl;
return 0;
}
| 1 | 52,694,760 |
#include <iostream>
#include <vector>
int main()
{
int data_count = 0;
while ((std::cin >> data_count) && (data_count > 0)) {
std::vector<long> dataset;
for (int i = 0; i < data_count; ++i) {
int data = 0;
std::cin >> data;
dataset.push_back(data);
}
long max_sum = dataset[0];
for (int i = 0; i < data_count; ++i) {
long current_sum = 0;
long max_current_sum = dataset[i];
for (int j = i; j < data_count; ++j) {
current_sum += dataset[j];
if (max_current_sum < current_sum) {
max_current_sum = current_sum;
}
}
if (max_sum < max_current_sum) {
max_sum = max_current_sum;
}
}
std::cout << max_sum << std::endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
int n;
while(cin >> n, n){
vector<int> dp(n), vec(n);
for(int i=0;i<n;i++)cin >> vec[i];
dp[0]=vec[0];
for(int i=1;i<n;i++)dp[i]=max(dp[i-1]+vec[i],vec[i]);
cout << *max_element(dp.begin(), dp.end()) << endl;
}
return 0;
}
| 1 | 85,418,556 |
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
signed main()
{
ll s;
cin>>s;
if(s==1e18) cout<<0<<" "<<0<<" "<<1000000000<<" "<<0<<" "<<0<<" "<<1000000000<<endl;
else if(s<=1e9) cout<<0<<" "<<0<<" "<<s<<" "<<0<<" "<<0<<" "<<1<<endl;
else{
cout<<0<<" "<<0<<" ";
ll a1=s/1e9+1;
ll a2=1e9;
ll aa=a1*a2-s;
cout<<a1<<" "<<1<<" "<<aa<<" "<<a2<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;
int main(){
int64_t S; cin>>S;
int64_t x1=0,y1=0,x2=1,y2=1e9,x,y;
x=S/y2+(S%y2>0);
if(S%y2) y=y2-S%y2;
else y=0;
cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x<<" "<<y<<endl;
cerr<<abs(x*y2-x2*y)<<endl;
}
| 1 | 63,466,668 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k, a, b;
cin>>k>>a>>b;
if((b/k)*k>=a)
cout<<"OK";
else
cout<<"NG";
}
|
#include<iostream>
using namespace std;
int main(void){
int A, B, K;
bool result{false};
cin >> K >> A >> B;
if(A%K == 0){
result = true;
}
else if((A/K+1)*K<=B){
result = true;
}
if(result){
cout << "OK" << endl;
}
else{
cout << "NG" << endl;
}
}
| 1 | 18,998,981 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
char A;
cin>>A;
if(A=='a'||A=='e'|| A=='i'|| A=='o'|| A=='u') cout<<"vowel"<<endl;
else cout<<"consonant"<<endl;
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main(){
string c;
cin >> c;
string B = "aiueo";
if(B.find(c) != string::npos) {
cout << "vowel" << endl;
} else {
cout << "consonant" << endl;
}
return 0;
}
| 1 | 79,815,136 |
#include<string>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
char ctable[4] = {'m', 'c', 'x', 'i'};
int table[4] = {1000, 100, 10, 1};
int rmcxi(){
int r = 0;
string s;
cin>>s;
int start = 0;
for(int i = 0; i < s.size();i++){
for(int j = 0; j < 4; j++){
if(s[i] == ctable[j]){
if(start == i){
r += table[j];
}else{
r += atoi(s.substr(start, i-start).c_str()) * table[j];
#ifdef DEUBG
cout<<"DEBUG: "<<s.substr(start, i-start)<<endl;
cout<<"DEBUG r: "<<r<<endl;
#endif
}
start = i+1;
}
}
}
return r;
}
void wmcxi(int n){
int num[4];
for(int i = 0; i < 4; i++){
num[i] = n/table[i];
n = n%table[i];
if(num[i]){
if(num[i] > 1)cout<<num[i];
cout<<ctable[i];
}
}
cout<<endl;
}
int main(){
int N;
cin>>N;
while(N--){
int a, b;
a = rmcxi();
b = rmcxi();
#ifdef DEBUG
cout<<"a: "<<a<<", b: "<<b<<endl;
#endif
wmcxi(a+b);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char mcxi[] = {'i', 'x', 'c', 'm' };
int calc(string s){
int res = 0;
for(int i = 0; i < s.size(); ++i){
int t = 1;
if('2' <= s[i] && s[i] <= '9'){
t = s[i] - '0';
++i;
}
if(s[i] == 'm'){
res += t * 1000;
}
else if(s[i] == 'c'){
res += t * 100;
}
else if(s[i] == 'x'){
res += t * 10;
}
else if(s[i] == 'i'){
res += t;
}
}
return res;
}
int main() {
int n;
cin >> n;
for(int q = 0; q < n; ++q){
string s1, s2, ans("");
cin >> s1 >> s2;
int l = calc(s1);
int r = calc(s2);
int w = l + r;
int t = 3;
while(pow(10, t) > w)
t--;
for(int i = 0; i <= t; ++i){
int a = w % 10;
w /= 10;
if(a == 0){
continue;
}
else if(a == 1){
ans += mcxi[i];
}
else{
ans += mcxi[i] + to_string(a);
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
return 0;
}
| 1 | 29,264,161 |
#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define FOR(i,l,r) for( li i = l-(l>r); i != r-(l>r); i += 1-2*(l>r) )
int main() {
li m,k; cin>>m>>k;
li u = (1ll<<m)-1;
if( k > u || ( k == 1 && m <= 1 ) ) {
cout<<"-1\n";
return 0;
}
if( k == 0 ) {
FOR(i,0,u+1) cout<<i<<" "<<i<<" ";
cout<<"\n";
return 0;
}
int a = 1;
if( k == 1 ) a++;
cout<<0<<" "<<k<<" "<<0<<" "<<a<<" "<<(k^a);
deque<li> q;
q.push_back(k);
FOR(i,0,u+1) {
if( i != k && i != 0 && i != a && i != (k^a) ) {
q.push_back(i);
q.push_front(i);
}
}
while( !q.empty() ) {
cout<<" "<<q.front();
q.pop_front();
}
cout<<" "<<(k^a)<<" "<<a<<"\n";
return 0;
}
|
#include <iostream>
#include <cstdio>
using namespace std;
int n, k;
int main() {
int i;
cin >> n >> k;
if(k >= 1<<n) return puts("-1")*0;
if(n==1) {
if(k==0) return puts("0 0 1 1")*0;
else return puts("-1")*0;
}
printf("%d ", k);
for(i=0; i<1<<n; i++) if(i!=k) printf("%d ", i);
printf("%d ", k);
for(i=(1<<n)-1; i>=0; i--) if(i!=k) printf("%d ", i);
return 0;
}
| 1 | 51,167,233 |
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int X,T;
cin >> X >> T;
if (X-T>=0) {
cout << X-T << endl;
} else if (X-T<0) {
cout << 0 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define MOD 1000000007LL
#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))
template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
cout << "(" << m.first << ", " << m.second << ")";
return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
ll c = 0;
cout << "{ ";
iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
cout << "}";
return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
cout << "{ ";
rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
cout << "}";
return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
ll c = 0;
cout << "{ ";
iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
cout << "}";
return s;
}
int main(void) {
ll X, t;
cin >> X >> t;
cout << max(0LL, X - t) << endl;
return 0;
}
| 1 | 43,601,230 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i<n;++i)
using ll = long long;
using P = pair<int,int>;
int main(){
int h,w;
cin >> h >> w;
string s;
rep(i,h){
for(char c = 'A';c < 'A'+w;++c){
cin >> s;
if(s == "snuke"){
cout << c << i+1 << endl;
return 0;
}
else s = "";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
static const int MOD = 1e9 + 7;
static const int MAX_N = 1;
int main()
{
CIN(H, W);
string str;
REP(hi, H) {
REP(wi, W) {
cin >> str;
if (str == "snuke") printf("%c%d\n", wi + 65, hi + 1);
}
}
return 0;
}
| 1 | 62,232,522 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int intager[100]={0};
int num;
while(cin>>num)
intager[num-1]++;
int flag=0;
for(int i=100;i>0;i--){
for(int j=0;j<100;j++){
if(intager[j]==i){
cout<<j+1<<endl;
flag=1;
}
}
if(flag==1)
break;
}
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<cstring>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main()
{
int a[100];
memset(a,0,sizeof(a));
int in;
while(cin>>in)a[in-1]++;
vector<pair<int,int>> P;
rep(i,100)P.push_back(make_pair(a[i],i));
sort(P.begin(),P.end(),[](const pair<int,int> p1,const pair<int,int> p2)
{
return p1.first==p2.first?p1.second>p2.second:p1.first<p2.first;
});
cout<<P[99].second+1<<endl;
int c=99;
while(P[c].first==P[c-1].first)
{
cout<<P[--c].second+1<<endl;
}
return 0;
}
| 1 | 44,870,152 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
vector<int> c(3);
int i = 0;
for (int i = 0; i < 3; i ++)
cin >> c.at(i);
sort(c.begin(), c.end(), greater<>());
cout << c.at(0) * 10 + c.at(1) + c.at(2) << endl;
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <limits>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[]){
cin.tie(0);
ios::sync_with_stdio(false);
vector<LL> v;
for(int i=0; i<3; i++){
LL u;
cin >> u;
v.push_back(u);
}
sort(v.begin(), v.end());
LL ans = 10*v[2] + v[1] + v[0];
printf("%lld\n", ans);
return 0;
}
| 1 | 46,367,656 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
int main(){
FAST
int n, m; cin >> n >> m;
vector<int> rows[n + 2];
vector<int> cols[m + 2];
int lastOR[n + 2];
int lastOC[m + 2];
mm(lastOR); mm(lastOC);
string mat[n + 2];
string s = " ";
for(int i = 0; i < m + 2; i++){
s += '#';
}
mat[0] = s;
mat[n + 1] = s;
for(int i = 1; i <= n; i++){
cin >> mat[i];
mat[i] = '#' + mat[i];
mat[i] += '#';
}
for(int i = 0; i <= n + 1; i++){
for(int j = 0; j <= m + 1; j++){
if(mat[i][j] == '#'){
rows[i].pb(j);
cols[j].pb(i);
}
}
}
int ans = 0;
for(int i = 0; i <= n + 1; i++){
for(int j = 0; j <= m + 1; j++){
if(mat[i][j] == '.'){
int curr = j - lastOR[i] + i - lastOC[j] - 1;
int ind = lower_bound(rows[i].begin(), rows[i].end(), j) - rows[i].begin();
if(rows[i].size() == ind){
curr += m - j - 1;
}
else{
ind = rows[i][ind];
curr += ind - j - 1;
}
ind = lower_bound(cols[j].begin(), cols[j].end(), i) - cols[j].begin();
if(ind == cols[j].size()){
curr += n - i - 1;
}
else{
ind = cols[j][ind];
curr += ind - i - 1;
}
ans = max(ans, curr);
}
else{
lastOR[i] = j;
lastOC[j] = i;
}
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h,w;
cin>>h>>w;
char a[h][w];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>a[i][j];
}
}
int l[h][w],r[h][w],u[h][w],d[h][w];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(a[i][j]=='#') l[i][j]=0;
else if(j==0) l[i][j]=1;
else l[i][j]=l[i][j-1]+1;
}
}
for(int i=0;i<h;i++){
for(int j=w-1;j>=0;j--){
if(a[i][j]=='#') r[i][j]=0;
else if(j==w-1) r[i][j]=1;
else r[i][j]=r[i][j+1]+1;
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(a[i][j]=='#') d[i][j]=0;
else if(i==0) d[i][j]=1;
else d[i][j]=d[i-1][j]+1;
}
}
for(int i=h-1;i>=0;i--){
for(int j=0;j<w;j++){
if(a[i][j]=='#') u[i][j]=0;
else if(i==h-1) u[i][j]=1;
else u[i][j]=u[i+1][j]+1;
}
}
int ans=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3);
}
}
cout<<ans<<endl;
}
| 1 | 40,466,490 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n; cin>>n;
int an[n]; rep(i,n) cin >> an[i];
int cnt=0;
rep(i,n) {
int j = an[i]-1;
if (an[j]-1 == i) cnt++;
}
cnt /= 2;
cout<<cnt<<endl;
}
|
#include <iostream>
#include <vector>
int main()
{
int N;
std::cin >> N;
std::vector<int> a(N);
for(int i = 0; i < N; i++)
{
std::cin >> a[i];
}
int ans = 0;
for(int usa = 0; usa < N; usa++)
{
int aiteUsa = a[usa];
if(a[aiteUsa - 1] <= -1) continue;
if(a[aiteUsa - 1] == usa + 1)
{
ans++;
a[aiteUsa - 1] = -1;
}
}
std::cout << ans << std::endl;
return 0;
}
| 1 | 21,047,480 |
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <queue>
#include <map>
using namespace std;
const int M=200010;
int n, m,r[M];
int root(int x){
if (r[x] < 0) return x;
return r[x] = root(r[x]);
}
bool Change(int x, int y) {
x=root(x); y=root(y);
if (x == y) return false;
if (r[x] > r[y]) swap(x, y);
r[x] += r[y]; r[y] = x;
return true;
}
int size(int x){
return -r[root(x)];
}
int main() {
cin>>n>>m;
memset(r,-1,sizeof r);
for(int i=0;i<m;i++){
int a, b;
cin>>a>>b;
a--; b--;
Change(a,b);
}
int ans=0;
for(int i=0;i<n;i++) ans=max(ans,size(i));
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
int f[200005]={0};
int sz[200005]={0};
int n,m;
int ans=1;
int get(int x)
{
if(x==f[x])return x;
return f[x]=get(f[x]);
}
void merge(int x,int y)
{
int xx=get(x);
int yy=get(y);
if(xx!=yy){
f[xx]=yy;
sz[yy]+=sz[xx];
ans=max(ans,sz[yy]);
}
}
void init()
{
for(int i=1;i<=n;i++){
f[i]=i;
sz[i]=1;
}
}
int main(){
cin>>n>>m;
init();
while(m--){
int x,y;
cin>>x>>y;
merge(x,y);
}
cout<<ans<<endl;
}
| 1 | 76,953,918 |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()
int main() {
int a, b;
cin >> a >> b;
if(a * b % 2) cout << "Odd" << endl;
else cout << "Even" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b;
cin>>a>>b;
if(a%2==0||b%2==0){
cout<<"Even"<<endl;
}else cout<<"Odd"<<endl;
return 0;
}
| 1 | 84,526,492 |
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
cin.tie(0);
ios::sync_with_stdio(false);
}
int n;
ll a[110000],b[110000];
int la=0,lb=0;
ll ans=1;
signed main(){
init();
cin>>n;
rep(i,n){
cin>>a[i];
}
rep(i,n){
cin>>b[i];
}
vector<ll> v(n,INF);
rep(i,n){
if(la<a[i]){
v[i]=a[i];
la=a[i];
}
}
rrep(i,n-1){
if(lb<b[i]){
if(a[i]<b[i])
ans = 0;
v[i]=b[i];
lb=b[i];
}
}
if(la!=lb)
ans = 0;
rep(i,n){
if(v[i]!=INF) continue;
ans*=min(a[i],b[i]);
ans%=M;
}
cout<<ans<<endl;
}
|
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
ll n,ans = 1;
cin >> n;
ll a[n],t[n];
ll h[n];
for(int i=0;i<n;i++){
cin >> t[i];
if(i==0||t[i]!=t[i-1]){
h[i] = t[i];
}else{
h[i] = -1;
}
}
for(int i=0;i<n;i++){
cin >> a[i];
}
for(int i=n-1;i>=0;i--){
if(i==n-1||a[i]!=a[i+1]){
if(h[i]!=-1&&a[i]!=h[i]){
ans = 0;
break;
}
h[i] = a[i];
}else if(h[i]!=-1){
if(h[i]>a[i]){
ans = 0;
break;
}
}else{
ans *= min(a[i],t[i]);
ans %= MOD;
}
}
cout << ans << endl;
}
| 1 | 69,014,076 |
#include<bits/stdc++.h>
using namespace std;
long long n,m,v,p,a[100010];
bool check(int x){
long long cnt=0;
if(a[x]+m<a[p-1])
return 0;
cnt+=(p-1)*m+(n-x)*m;
for(int i=p-1;i<x;i++)
cnt+=a[x]+m-a[i];
return (cnt>=m*v);
}
int main(){
cin>>n>>m>>v>>p;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
reverse(a,a+n);
long long l=0,r=n-1,mid;
while(l<=r){
mid=(l+r)/2;
if(check(mid))
l=mid+1;
else
r=mid-1;
}
cout<<l;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll INF = 2e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
int N, M, V, P, A[MAXN];
bool chk(int idx) {
int x = A[idx], a = idx - 1;
if(V-P-a <= 0) return (x + M >= A[N-P+1]);
if(A[N-P+1] > x + M) return 0;
ll sum = 0;
for(int i=idx+1; i<=N-P+1; i++) sum += x + M - A[i];
return (sum >= 1LL * (V-P-a) * M);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N >> M >> V >> P;
for(int i=1; i<=N; i++) cin >> A[i];
sort(A+1, A+1+N);
int l = 1, r = N - P, ans = P;
while(l <= r) {
int mid = l + r >> 1;
if(chk(mid)) {
r = mid - 1;
ans = N - mid + 1;
}
else l = mid + 1;
}
cout << ans;
}
| 1 | 55,221,312 |
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;
int main() {
int N;
cin>>N;
string S;
cin>>S;
bool can = false;
vector<int> ans(N);
for(int n = 0; n < 4; n++){
bitset<2> bit(n);
ans[0]=bit[0];
ans[1]=bit[1];
for(int i = 1; i < N-1; i++){
if(ans[i]==0){
if(S[i]=='o') ans[i+1]=ans[i-1];
if(S[i]=='x') ans[i+1]=1-ans[i-1];
}
if(ans[i]==1){
if(S[i]=='o') ans[i+1]=1-ans[i-1];
if(S[i]=='x') ans[i+1]=ans[i-1];
}
}
int t,s;
if(ans[0]==0){
if(S[0]=='o') t=ans[1];
else t=1-ans[1];
}
if(ans[0]==1){
if(S[0]=='o') t=1-ans[1];
else t=ans[1];
}
if(ans[N-1]==0) {
if(S[N-1]=='o') s=ans[N-2];
if(S[N-1]=='x') s=1-ans[N-2];
}
if(ans[N-1]==1) {
if(S[N-1]=='o') s=1-ans[N-2];
if(S[N-1]=='x') s=ans[N-2];
}
if(t==ans[N-1]&&s==ans[0]) {
can=true;
break;
}
}
if(can) {
for(auto x:ans) {
if(x==0) cout<<'S';
else cout<<'W';
}
}
else cout<<-1;
cout<<endl;
}
|
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> s(N);
for (int i = 0; i < N; i++) {
char c;
cin >> c;
s[i] = (c == 'x');
}
if (N % 3 == 0) {
string ans(N, 'S');
for (int i = 1; i < N - 1; i++) {
if (ans[i] == 'S' && ans[i - 1] == 'S' && s[i] == 1) ans[i + 1] = 'W';
if (ans[i] == 'S' && ans[i - 1] == 'W' && s[i] == 0) ans[i + 1] = 'W';
if (ans[i] == 'W' && ans[i - 1] == 'S' && s[i] == 0) ans[i + 1] = 'W';
if (ans[i] == 'W' && ans[i - 1] == 'W' && s[i] == 1) ans[i + 1] = 'W';
}
bool OK = true;
if (ans[N - 1] == 'S' && s[N - 1] == 0 && ans[N - 2] != ans[0]) OK = false;
if (ans[N - 1] == 'S' && s[N - 1] == 1 && ans[N - 2] == ans[0]) OK = false;
if (ans[N - 1] == 'W' && s[N - 1] == 0 && ans[N - 2] == ans[0]) OK = false;
if (ans[N - 1] == 'W' && s[N - 1] == 1 && ans[N - 2] != ans[0]) OK = false;
if (s[0] == 0 && ans[N - 1] == 'W') OK = false;
if (s[0] == 1 && ans[N - 1] == 'S') OK = false;
if (OK) cout << ans << endl;
else cout << -1 << endl;
return 0;
}
else {
int l = (N - 1) / 3;
vector<int> ans(N);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < l; j++) {
ans[i] ^= (s[(i + 3 * j) % N] ^ s[(i + 1 + 3 * j) % N]);
}
ans[i] ^= s[(i + 3 * l) % N];
}
for (int i = 2; i < N; i++) {
if (N % 3 == 1) ans[i] = s[(i - 1 + N) % N] ^ ans[i - 1] ^ ans[i - 2];
else ans[i] = s[(N + i - 3) % N] ^ ans[i - 1] ^ ans[i - 2];
}
if (N % 3 == 1) {
for (int a : ans) cout << (a ? "W" : "S");
cout << endl;
}
else {
for (int i = 2; i < N; i++) cout << (ans[i] ? "W" : "S");
cout << (ans[0] ? "W" : "S") << (ans[1] ? "W" : "S") << endl;
}
}
}
| 1 | 26,446,019 |
#include<vector>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007LL;
const ll INF=1000000000LL;
const int MAX=100001;
int ch(char c){
if(c=='m'){
return 1000;
}else if(c=='c'){
return 100;
}else if(c=='x'){
return 10;
}else{
return 1;
}
}
int mcxi(string s){
int ret=0;
stack<int> st;
for(int i=0;i<s.length();i++){
if(isalpha(s[i])){
if(st.empty()){
ret+=ch(s[i]);
}else{
int a=st.top();st.pop();
ret+=a*ch(s[i]);
}
}else{
st.push(s[i]-'0');
}
}
return ret;
}
string tomcxi(int s,int w){
string ret="";
if(s/w){
if(s/w>1){
char p='0'+(s/w);
ret.push_back(p);
}
char c;
switch(w){
case 1000:c='m';break;
case 100:c='c';break;
case 10:c='x';break;
case 1:c='i';break;
}
ret.push_back(c);
}
return ret;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=0;i<n;i++){
string s1,s2;
cin>>s1>>s2;
int sum=mcxi(s1)+mcxi(s2);
cout<<tomcxi(sum,1000);sum%=1000;
cout<<tomcxi(sum,100);sum%=100;
cout<<tomcxi(sum,10);sum%=10;
cout<<tomcxi(sum,1);
cout<<endl;
}
}
|
#include <iostream>
#include <cctype>
#include <cstdlib>
using namespace std;
int main()
{
int n;
cin >> n;
for (int j = 0; j < n; j++) {
char num1[10], num2[10];
cin >> num1 >> num2;
int m = 0, x = 0, c = 0, i = 0;
int pos = 0;
while (num1[pos]) {
bool flag = false;
int tmpi;
if (isdigit(num1[pos])) {
char tmpc[2] = { num1[pos], '\0' };
tmpi = atoi(tmpc);
pos++;
flag = !flag;
}
switch (num1[pos]) {
case 'm':
m += flag ? tmpi : 1;
break;
case 'x':
x += flag ? tmpi : 1;
break;
case 'c':
c += flag ? tmpi : 1;
break;
case 'i':
i += flag ? tmpi : 1;
break;
default:
break;
}
pos++;
}
pos = 0;
while (num2[pos]) {
bool flag = false;
int tmpi;
if (isdigit(num2[pos])) {
char tmpc[2] = { num2[pos], '\0' };
tmpi = atoi(tmpc);
pos++;
flag = !flag;
}
switch (num2[pos]) {
case 'm':
m += flag ? tmpi : 1;
break;
case 'x':
x += flag ? tmpi : 1;
break;
case 'c':
c += flag ? tmpi : 1;
break;
case 'i':
i += flag ? tmpi : 1;
break;
default:
break;
}
pos++;
}
if (i > 9) {
x += i / 10;
i %= 10;
}
if (x > 9) {
c += x / 10;
x %= 10;
}
if (c > 9) {
m += c / 10;
c %= 10;
}
if (m > 1) {
cout << m;
}
if (m > 0) {
cout << 'm';
}
if (c > 1) {
cout << c;
}
if (c > 0) {
cout << 'c';
}
if (x > 1) {
cout << x;
}
if (x > 0) {
cout << 'x';
}
if (i > 1) {
cout << i;
}
if (i > 0) {
cout << 'i';
}
cout << endl;
}
return 0;
}
| 1 | 4,710,241 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
map<string,int> m;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
sort(s.begin(),s.end());
m[s]++;
}
ll ans = 0;
for (auto it = m.begin(); it != m.end(); ++it) {
if (it->second > 1) {
ans += 1LL * ((it->second *1LL * (it->second - 1)) / 2);
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INF = 2e9;
int main(){
int n;
cin >> n;
vector<string> s(n);
map<string,ll> x;
ll ans = 0;
rep(i,n){
cin >> s[i];
sort(s[i].begin(),s[i].end());
x[s[i]]++;
ans += (x[s[i]]-1);
}
cout << ans << endl;
}
| 1 | 58,512,157 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
const ll INF=LLONG_MAX;
int a[]={111,222,333,444,555,666,777,888,999};
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
int ptr = lower_bound(begin(a),end(a),n)-begin(a);
cout << a[ptr] << endl;
}
|
#include<iostream>
using namespace std;
int main() {
int N;
cin >> N;
while (1) {
if (N % 111 == 0) {
cout << N << endl;
break;
}
else {
N++;
}
}
}
| 1 | 33,601,273 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
void solve() {
int n;
cin >> n;
vector<int> t(n+1), x(n+1), y(n+1);
rep(i,n) cin >> t[i+1] >> x[i+1] >> y[i+1];
rep(i,n) {
int dt = t[i+1] - t[i];
int dx = x[i+1] - x[i];
int dy = y[i+1] - y[i];
int dis = abs(dx) + abs(dy);
if (dt < dis || (dt % 2 != dis % 2)) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
int main(){
int n;cin>>n;
string ans="Yes";
int tx=0,ty=0,tt=0,t,x,y;
for(int i=0;i<n;i++){
cin>>t>>x>>y;
if(abs(tx-x)+abs(ty-y)>t-tt){
ans="No";break;
}
if((x+y)%2!=t%2){
ans="No";break;
}
tx=x;ty=y;tt=t;
}
cout<<ans<<endl;
}
| 1 | 46,503,715 |
#include <iostream>
using namespace std;
int main(void) {
string s,p;
bool flag = false;
cin >> s;
cin >> p;
s += s;
if(s.find(p) != string::npos)
flag = true;
if(flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
|
#include<cmath>
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cctype>
#include<cstring>
using namespace std;
int main() {
char s[202]; cin >> s;
char p[101]; cin >> p;
char s1[202];
for (int i = 0; i < strlen(s); i++)s1[i] = s[i];
strcat(s, s1);
if (strstr(s, p))cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
| 1 | 937,105 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 2e7+5;
ll a[N];
void solve(){
int n;
cin>>n;
ll sum = 0;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
sum+=a[i]*a[j];
}
}
cout<<sum<<endl;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
while(t--)solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc(t) int t; cin>>t; while(t--)
#define f(n) for(int i=0;i<n;i++)
#define endl "\n"
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<int> v(n);
int sum=0;
f(n)cin>>v[i];
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
sum+=(v[i]*v[j]);
}
}
cout<<sum<<endl;
}
| 1 | 79,945,221 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
int main(){
int a,b,c;
cin >> a >> b >> c;
if(a + b >= c){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;
char c[26];
main()
{
int a,b,c; cin>>a>>b>>c;
if(a+b>=c)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
| 1 | 38,124,117 |
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll a[100005];
int main() {
int n, k;
cin >> n >> k;
if (n == 1) {
cout << k << endl;
return 0;
}
ll ans = k;
int i = 1;
while (i != n ) {
i++;
ans *= (k - 1);
}
cout << ans << endl;
return 0;
}
|
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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);
ll n, k;
cin >> n >> k;
ll ans = k;
rep(i,n-1){
ans *= (k-1);
}
cout << ans << endl;
return 0;
}
| 1 | 95,382,520 |
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
int main() {
ll N;
cin >> N;
vector<ll> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
a[i]--;
}
ll ans = 0;
set<ll> visited;
for (int i = 0; i < N; i++) {
if (visited.count(i)) continue;
if (i == a[a[i]]) {
ans++;
visited.insert(i);
visited.insert(a[i]);
}
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;
int main(){
int n,cnt = 0;
std::cin >> n;
vt<int> a(n,-1);
rep(i,n) {
int num;
std::cin >> num;
--num;
a[i] = num;
if(a[num] == i)
cnt++;
}
std::cout << cnt << '\n';
return 0;
}
| 1 | 33,375,870 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
vector<int> filho[100005];
ll dp[100005][2];
ll dfs(int pai, int cor, int pos)
{
if(dp[pos][cor] > 0)
return dp[pos][cor];
for (int i = 0; i < (int)filho[pos].size(); ++i)
{
int viz = filho[pos][i];
ll valor = 0;
if(viz != pai)
{
if(cor == 0)
{
valor += (dfs(pos, 0, viz) % mod);
valor += (dfs(pos, 1, viz) % mod);
}
else if(cor == 1)
{
valor += (dfs(pos, 0, viz) % mod);
}
if(dp[pos][cor] == 0)
dp[pos][cor] = valor;
else
dp[pos][cor] = (dp[pos][cor] * valor) % mod;
}
}
if(dp[pos][cor] == 0)
return dp[pos][cor] = 1;
return dp[pos][cor];
}
int main()
{
int n, u, v;
cin >> n;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n - 1; ++i)
{
cin >> u >> v;
filho[u].push_back(v);
filho[v].push_back(u);
}
ll resp = (dfs(-1, 0, 1) + dfs(-1, 1, 1)) % mod;
cout << resp << endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<ull> vul;
typedef vector<pair<ll, ll>> vpl;
typedef pair<ll, ll> pl;
#define For(i, n) for(ll i = 0; i < n; i++)
#define len(n) (ll)(n).size()
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
vector<vl> g;
vb used;
ll dp[100010][2];
void dfs(ll v) {
used[v] = true;
for (ll to : g[v]) {
if (!used[to]) {
dfs(to);
dp[v][0] *= dp[to][1];
dp[v][0] %= ((ll)1e9 + 7);
dp[v][1] *= ((dp[to][0] + dp[to][1]) % ((ll)1e9 + 7));
dp[v][1] %= ((ll)1e9 + 7);
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, a, b;
cin >> n;
g.resize(n);
used.resize(n);
For(i, n - 1) {
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
For(i, n) {
dp[i][0] = 1;
dp[i][1] = 1;
}
dfs(0);
ll ans = dp[0][0] + dp[0][1];
ans %= ((ll)1e9 + 7);
cout << ans;
return 0;
}
| 1 | 29,106,905 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
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 PI 3.141592653589793238
#define INF 1050000000
using vi = vector<int>;
int main() {
int N;
cin >> N;
cout << N/3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) \
{ \
cout << x << ' '; \
} \
cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (b < a)
{
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll n,m,x;
cin>>n;
cout<<n/3<<"\n";
}
| 1 | 16,190,818 |
#include<bits/stdc++.h>
using namespace std;
long long k=9,n;
struct node
{
long long a,b;
};
queue<node>Q;
int main()
{
cin>>n;
for(int i=1;i<=9;i++)
{
node tmp;
tmp.a=tmp.b=i;
Q.push(tmp);
}
while(!Q.empty())
{
node tmp=Q.front();
Q.pop();
long long a=tmp.a,b=tmp.b,t=tmp.a%10;
if(b==n)
{
cout<<a;
return 0;
}
for(int i=0;i<=9;i++)
{
if(abs(i-t)<=1)
{
node cur;
cur.a=a*10+i;
cur.b=++k;
Q.push(cur);
}
}
}
return 0;
}
|
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
using namespace std;
queue<ll> q;
int n;
int main()
{
cin>>n;
for(int i=1;i<=9;i++)
{
q.push(i);
}
for(int i=1;i<=n;i++)
{
ll pre=q.front();
q.pop();
if(i==n)
{
cout<<pre<<endl;
}
ll r=pre%10;
pre=pre*10+r;
if(r>0)
q.push(pre-1);
q.push(pre);
if(r<9)
{
q.push(pre+1);
}
}
return 0;
}
| 1 | 72,307,609 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long a, b, c, k;
cin >> a >> b >> c >> k;
const long long inf = pow(10, 18);
long long ans = a - b;
if(abs(ans) > inf){
cout << "Unfair" << endl;
return 0;
}
if(k % 2) cout << -ans << endl;
else cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;
typedef int64_t ll;
ll A, B, C, K;
int main() {
cin >> A >> B >> C >> K;
if (K%2==1)
{
cout << B - A << endl;
}
else {
cout << A - B << endl;
}
}
| 1 | 20,897,579 |
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<vector<int>>retu(8,vector<int>(3));
vector<vector<int>>card(3,vector<int>(3));
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cin >> card.at(i).at(j);
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
retu.at(i).at(j)=card.at(i).at(j);
retu.at(i+3).at(j)=card.at(j).at(i);
}
retu.at(6).at(i)=card.at(i).at(i);
retu.at(7).at(i)=card.at(2-i).at(i);
}
map<int,int>deta;
int n,b;
cin >> n;
for(int i=0;i<n;i++){
cin >> b;
deta[b]=1;
}
bool ans=false;
for(int i=0;i<8;i++){
if(deta[retu.at(i).at(0)]==1&&deta[retu.at(i).at(1)]==1&&deta[retu.at(i).at(2)]==1)
ans=true;
}
cout << (ans?"Yes":"No") << endl;
return 0;
}
|
#include <stdio.h>
int main() {
int box[3][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
scanf("%d",&box[i][j]);
}
}
int tc;
scanf("%d",&tc);
int bingo[10];
for (int i = 0; i < tc; i++)
{
scanf("%d",&bingo[i]);
}
int ctr[3][3] = {0};
for (int i = 0; i < tc; i++)
{
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
if (bingo[i] == box[j][k])
{
ctr[j][k]++;
}
}
}
}
if (ctr[0][0] > 0 && ctr[0][1] > 0 && ctr[0][2])
{
printf("Yes\n");
}
else if (ctr[1][0] > 0 && ctr[1][1] > 0 && ctr[1][2])
{
printf("Yes\n");
}
else if (ctr[2][0] > 0 && ctr[2][1] > 0 && ctr[2][2])
{
printf("Yes\n");
}
else if (ctr[0][0] > 0 && ctr[1][0] > 0 && ctr[2][0])
{
printf("Yes\n");
}
else if (ctr[0][1] > 0 && ctr[1][1] > 0 && ctr[2][1])
{
printf("Yes\n");
}
else if (ctr[0][2] > 0 && ctr[1][2] > 0 && ctr[2][2])
{
printf("Yes\n");
}
else if (ctr[0][0] > 0 && ctr[1][1] > 0 && ctr[2][2])
{
printf("Yes\n");
}
else if (ctr[0][2] > 0 && ctr[1][1] > 0 && ctr[2][0])
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
}
| 1 | 96,094,934 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
if(y == 0) return x;
else return GCD(y,x%y);
}
int main() {
int n;
cin >> n;
cout << n / 3 << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
int main(){
int n; cin>>n;
cout<<n/3<<endl;
}
| 1 | 56,921,454 |
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;
int main() {
int A, B, K;
cin >> A >> B >> K;
for (int i=0; i<K; i++) {
if (i%2==0) {
if (A%2!=0) A--;
B += A/2;
A /= 2;
}
else {
if (B%2!=0) B--;
A += B/2;
B /= 2;
}
}
cout << A << " " << B << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int A, B, K;
cin >> A >> B >> K;
for(int i=0; i<K; i++){
if(i %2 == 0){
if(A %2 == 1){
A--;
}
B += A / 2;
A = A / 2;
}
if(i %2 != 0){
if(B %2 == 1){
B--;
}
A += B / 2;
B = B / 2;
}
}
cout << A << endl;
cout << B << endl;
}
| 1 | 56,830,997 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
string s;
cin>>s;
n=s.size();
int pos=0;
long long int ans=0;
while(pos<n)
{
int coun1=0;
while(s[pos]=='<' && pos<n){
++pos;
coun1++;
}
int coun2=0;
while(s[pos]=='>' && pos<n)
{
coun2++;
++pos;
}
int x=min(coun1,coun2);
int y=max(coun1,coun2);
ans+= x * (long) (x-1)/2;
ans+= y * (long)(y+1)/2;
}
cout<<ans<<endl;
}
|
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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 ll long long
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
string s; cin >>s;
ll n=s.size();
vector<ll> vec(n+1);
ll ans=0;
rep(i,n){
if(s[i]=='<'){
vec[i+1]=vec[i]+1;
}
}
for(ll i=n-1;i>=0;i--){
if(s[i]=='>'){
vec[i]=max(vec[i],vec[i+1]+1);
}
}
rep(i,n+1){
ans+=vec[i];
}
cout <<ans<<endl;
}
| 1 | 5,803,396 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100];
int main(){
ll k; int n=50;
cin>>k;
cout<<n<<endl;
for (int i=1; i<=n; ++i)
a[i]=n-1+k/n;
k%=n;
for (int i=1; i<=k; ++i)
a[i]+=n-k+1;
for (int i=k+1; i<=n; ++i)
a[i]-=k;
for (int i=1; i<=n; ++i)
cout<<a[i]<<" ";
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <string.h>
#define int long long
using namespace std;
signed main()
{
int n=50,K;
scanf("%lld",&K);
int avg=K/n,rst=K%n;
printf("%lld\n",n);
for(int i=1;i<=rst;i++) printf("%lld ",n-1+avg-rst+n);
for(int i=rst+1;i<=n;i++) printf("%lld ",n-1+avg-rst);
printf("\n");
}
| 1 | 90,443,035 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
cout << ceil(n/111.0)*111 << 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;
int main(){
int n;
cin>>n;
int a[9];
int cnt=111;
rep(i,9){
a[i]=cnt;
cnt+=111;
}
rep(i,9){
if(n<=a[i]){
cout << a[i] << endl;
return 0;
}
}
}
| 1 | 63,858,027 |
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
cout << a;
return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
for (auto &a : vec) {
cout << a;
if (&a != &vec.back()) {
cout << " ";
}
}
return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
for (auto &v : vv) {
for (auto &a : v) {
cout << a;
if (&a != &v.back()) {
cout << " ";
}
}
if (&v != &vv.back()) {
cout << "\n";
}
}
return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
bool f = print_(head);
if (sizeof...(tail) != 0) {
cout << (f ? " " : "\n");
}
print(forward<Tail>(tail)...);
}
#pragma endregion
void Pr(bool f){
cout << (f ? "Yes" : "No") << "\n";
exit(0);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll a, b, c, n;
cin >> a >> b >> c >> n;
ll ans = 0;
rep(i, 3001){
rep(j, 3001){
if((n-a*i-b*j) >= 0 && (n-a*i-b*j)%c == 0){
ans++;
}
}
}
print(ans);
}
|
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main()
{
int R,G,B,N;
ll res=0;
cin>>R>>G>>B>>N;
vector<int>TR;
for(int i=0;i*R<=N;i++)TR.push_back(N-(i*R));
for(int i=0;i<TR.size();i++)
{
for(int g=0;TR[i]>=g*G;g++)
{
if((TR[i]-g*G)%B==0)res++;
}
}
cout<<res<<endl;
}
| 1 | 74,938,961 |
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
int m, n, i, j, k, l;
cin>>n>>m;
vector<string> a(n), b(m);
for(i = 0; i<n; i++)
{
cin>>a[i];
}
for(j = 0; j<m; j++)
{
cin>>b[j];
}
for(i = 0; i<n; i++)
{
for(j = 0; j<n; j++)
{
if(a[i][j]!= b[0][0]) continue;
bool x = 1;
for(k = 0; k<m; k++)
{
for(l = 0; l<m; l++)
{
if(i+k>=n || j+l>=n || a[i+k][j+l]!=b[k][l])
{
x = 0;
break;
}
}
}
if(x)
{
cout<<"Yes"<<endl;
return 0;
}
}
}
cout<<"No"<<endl;
return 0;
}
|
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll dx[] = { 1,0 };
ll dy[] = { 0,1 };
bool judge(vector<string> A, vector<string> B, ll a, ll b);
ll N, M, x, y;
int main() {
cin >> N >> M;
vector<string>A(N), B(M);
rep(i, N) {
cin >> A[i];
}
rep(i, M) {
cin >> B[i];
}
x = B.size();
y = B[0].size();
bool ans = false;
rep(i, N - x + 1) {
rep(j, A[0].size() - y + 1) {
if (A[i][j] == B[0][0] && A[i + x - 1][j + y - 1] == B[x - 1][y - 1]) {
if (judge(A, B, i, j)) {
ans = true;
break;
}
}
}
}
if (ans) {
cout << "Yes";
}
else {
cout << "No";
}
return 0;
}
bool judge(vector<string> A, vector<string> B, ll a, ll b) {
bool ans = true;
rep(i, M) {
rep(j, y) {
if (A[i + a][j + b] != B[i][j]) {
return false;
}
}
}
return true;
}
| 1 | 83,808,854 |
#include<stdio.h>
int main(){
int a[3];
int i,j,tmp;
scanf("%d%d%d",&a[0],&a[1],&a[2]);
for(i=0;i<3;i++){
for(j=1;i<=j;j--){
if(a[j]>a[j+1]){
tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp;
}
}
}
printf("%d %d %d\n",a[0],a[1],a[2]);
return 0;
}
|
#include <iostream>
int main(){
int data[3];
int tmp;
std::cin >> data[0] >> data[1] >> data[2];
for (int i = 0; i < 3; i++){
for (int j = 2; j > 0 + i; j--){
if (data[j] < data[j - 1]){
tmp = data[j];
data[j] = data[j - 1];
data[j - 1] = tmp;
}
}
}
std::cout << data[0] << " " << data[1] << " " << data[2] << "\n";
return 0;
}
| 1 | 40,286,589 |
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 24;
int main(void){
vi a(10);
for(auto && aa : a){
cin >> aa;
}
sort(all(a), greater<int>());
rep(i, 3) cout << a[i] << endl;
return 0;
}
|
#include<iostream>
using namespace std;
int main(){
int a[10];
int temp;
for(int m=0; m<10; m++)
{
cin >> a[m];
}
temp=a[0];
for(int i=0; i<10; i++)
{
for(int j=0; j<10;j++)
{
if(a[i] > a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(int k=0; k<3; k++)
{
cout << a[k]<< endl;
}
}
| 1 | 71,456,178 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
string S;
cin >> S;
string T = "keyence",S1 = " ", S2 = " ",T1;
int k = 0;
bool flag = true;
for(int i = 0; i < S.size(); i++){
if(S[i] != T[k] && flag == true){
flag = false;
S1 = S.substr(0,i);
reverse(T.begin(),T.end());
T1 = T.substr(0,7-k);
}
}
reverse(T.begin(),T.end());
reverse(S.begin(),S.end());
string S3 = S1 + S2;
if(S1 == T || S2 == T || S3 == T || S == T) cout << "YES" << endl;
else cout << "NO" << endl;
}
|
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}
int main() {
string s; cin >> s;
FOR(i, 0, s.size()-1) {
FOR(j, i, s.size()-1) {
string tmp = s.substr(0, i) + s.substr(j, s.size()-j);
if (tmp == "keyence") {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
}
| 1 | 26,280,006 |
#include <bits/stdc++.h>
#define long long long int
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, p;
cin >> n >> p;
string s;
cin >> s;
if (p < 10) {
vector<int> cnt(p);
int cur = 0;
long res = 0;
cnt[0]++;
for (int i = 0; i < n; i++) {
vector<int> cnt2(p);
for (int j = 0; j < p; j++) {
cnt2[(j * 10) % p] += cnt[j];
}
cnt = cnt2;
cur = (cur * 10 + (s[i] - '0')) % p;
res += cnt[cur];
cnt[cur]++;
}
cout << res << "\n";
return 0;
}
int inv10 = 1;
while ((inv10 * 10) % p != 1) inv10++;
vector<int> cnt(p);
int cur = 0;
long res = 0;
int inv10pow = 1;
cnt[0]++;
for (int i = 0; i < n; i++) {
cur = (cur * 10 + (s[i] - '0')) % p;
int xx = (cur * inv10pow) % p;
res += cnt[xx];
cnt[xx]++;
inv10pow = (inv10pow * inv10) % p;
}
cout << res << "\n";
return 0;
}
|
#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 N, P;
string S;
cin >> N >> P >> S;
if (P == 2 || P == 5) {
ll ans = 0;
rep(i, N) {
if ((S[i] - '0') % P == 0) ans += i + 1;
}
cout << ans << "\n";
return 0;
}
vector<int> a(N, 1), b(N + 1, 0), r(P, 0);
rep(i, N - 1) a[N - 2 - i] = (a[N - 1 - i] * 10) % P;
rep(i, N) b[i + 1] = (b[i] + (S[i] - '0') * a[i]) % P;
rep(i, N + 1) r[b[i]]++;
ll ans = 0;
rep(i, P) {
ans += 1LL * r[i] * (r[i] - 1) / 2;
}
cout << ans << "\n";
}
| 1 | 32,941,858 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll N; cin >> N;
ll ans = 0;
for(int i = 0; i < N; i++){
ll l, r; cin >> l >> r; ans += r-l+1;
}
cout << ans << endl;
}
|
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)
int main()
{
int n;
cin >> n;
int ans = 0;
repi(i, n, 0)
{
int l, r;
cin >> l >> r;
ans += r - l + 1;
}
cout << ans << endl;
return 0;
}
| 1 | 478,950 |
#include <bits/stdc++.h>
using namespace std;
#define MorsheD ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
bool mew(int n) {
while (n) {
if (n%10 == 7) {
return true;
}
n /= 10;
}
return false;
}
int main(){
MorsheD;
int n;
cin >> n;
if (mew(n)) {
cout << "Yes" << "\n";
} else {
cout << "No" << "\n";
}
return 0;
}
|
#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() {
string N;
cin >> N;
rep(i, 3) {
if (N[i] == '7') {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
| 1 | 54,052,850 |
#include <iostream>
#include <iomanip>
using namespace std;
constexpr int MAXT = 2 * 101 * 200, MAXV = 2 * 101;
constexpr double inf = 1e9;
double dp[MAXT][MAXV];
int main(){
cin.tie(0); ios_base::sync_with_stdio(false);
int N; cin >> N;
int T[100], V[100];
for(int i=0; i < N; ++i) cin >> T[i];
for(int i=0; i < N; ++i) cin >> V[i];
int cur = 0;
int area_max_v[MAXT];
for(int i=0; i < N; ++i) {
for(int j=cur; j < cur + T[i] * 2; ++j) area_max_v[j] = V[i] * 2;
cur += T[i] * 2;
}
for(int i=0; i < MAXT; ++i) for(int j=0; j < MAXV; ++j) dp[i][j] = -inf;
dp[0][0] = 0;
for(int i=0; i < cur; ++i) {
for(int j=0; j < MAXV; ++j) {
if(dp[i][j] != -inf && j <= area_max_v[i]){
if (j > 0) dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j] + j + j - 1);
if (j + 1 <= area_max_v[i]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + j + j + 1);
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + j + j);
}
}
}
cout << fixed << setprecision(10) << dp[cur][0] / 8.0 << '\n';
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
int main() {
int N, L, R;
double count = 0, ans = 0;
pair<double, double> P[100];
map<double, double> mpL, mpR, mp;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> P[i].first;
count += P[i].first;
if (i != 0) P[i].first += P[i - 1].first;
}
for (int i = 0; i < N; i++) {
cin >> P[i].second;
}
L = 0, R = N - 1;
mpL[0] = 0, mpR[count] = 0;
for (double i = 0.5; i <= count; i += 0.5) {
double maxS = P[L].second;
mpL[i] = mpL[i - 0.5] + 0.5;
mpL[i] = min(mpL[i], maxS);
if (i == P[L].first) L++;
}
for (double i = count - 0.5; i >= 0; i -= 0.5) {
double maxS = P[R].second;
mpR[i] = mpR[i + 0.5] + 0.5;
mpR[i] = min(mpR[i], maxS);
if (R != 0 && i == P[R - 1].first) R--;
}
for (double i = 0; i <= count; i += 0.5) {
mp[i] = min(mpL[i], mpR[i]);
}
for (double i = 0; i < count; i += 0.5) {
ans += (mp[i] + mp[i + 0.5]) / 4;
}
printf("%.8f", ans);
}
| 1 | 45,422,313 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int cnt[110] = {};
int num(int n) {
int res = 0;
for (int i = 0; i < 110; ++i) {
if (cnt[i] >= n - 1) res++;
}
return res;
}
void prime_factor(int n) {
for (int i = 2; i * i <= n; ++i) {
if (n % i != 0) continue;
int num = 0;
while (n % i == 0) {
++num;
n /= i;
}
cnt[i] += num;
}
if (n != 1) cnt[n]++;
}
int main() {
int n; cin >> n;
for (int i = 1; i <= n; ++i) {
prime_factor(i);
}
int ans = num(75)
+ num(25) * (num(3) - 1)
+ num(15) * (num(5) - 1)
+ num(5) * (num(5) - 1) * (num(3) - 2) / 2;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var) do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1e9;
const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};
map<ll, int> prime_factor(ll n){
map<ll, int> res;
for(ll i = 2; i*i<=n; i++){
while(n%i==0){
res[i]++;
n/=i;
}
}
if(n!=1) res[n]++;
return res;
}
int main(){
int n;
cin >> n;
map<ll, int> mp;
for(int i = 1; i <= n; i++) {
auto p = prime_factor(i);
for(auto u : p) {
mp[u.first] += u.second;
}
}
int a2, a4, a14, a24, a74;
a2 = a4 = a14 = a24 = a74 = 0;
for(auto p : mp) {
if(p.second >= 74) a74++;
if(p.second >= 24) a24++;
if(p.second >= 14) a14++;
if(p.second >= 4) a4++;
if(p.second >= 2) a2++;
}
ll ans = 0;
ans += a74;
ans += a24*(a2-1);
ans += a14*(a4-1);
ans += (a4*(a4-1)/2)*(a2-2);
cout << ans << endl;
}
| 1 | 28,750,969 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
string s0;
int n, a, b;
string str[3] = {"replace", "reverse", "print"};
cin >> s0 >> n;
rep(i,n) {
string s1;
cin >> s1 >> a >> b;
if(s1 == str[0]) {
string q;
cin >> q;
s0.replace(a, b - a + 1, q);
} else if(s1 == str[1]) {
string s2 = s0.substr(0, a);
string s3 = s0.substr(a, b - a + 1);
string s4 = s0.substr(b + 1);
string s5;
for(int j = 0; j < b - a + 1; ++j) {
s5 += s3[b - a - j];
}
s0 = s2 + s5 + s4;
} else if(s1 == str[2]){
rep2(j, a, b + 1) {
cout << s0[j];
}
cout << endl;
}
}
return 0;
}
|
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)
const int INF = 1e9;
using namespace std;
int main() {
ostringstream os;
string str;
int q;
cin >> str >> q;
REP(i, q){
string order;
int fr, to;
cin >> order >> fr >> to;
if(order == "replace"){
string newstr;
cin >> newstr;
str.replace(fr, to-fr+1, newstr);
}
else if (order == "reverse"){
string temp = str.substr(fr, to-fr+1);
REP(j, to-fr+1){
str[to-j] = temp[j];
}
}
else if (order == "print")
os << str.substr(fr, to-fr+1) << endl;
}
cout << os.str();
return 0;
}
| 1 | 34,284,794 |
#include <bits/stdc++.h>
using namespace std ;
int main()
{
ios_base::sync_with_stdio(false) ;
cin.tie(0) ;
cout.tie(0) ;
int n ;
cin >> n ;
int flag = 0 ;
while(n)
{
if(n % 10 == 7)
{
flag = 1 ;
break ;
}
n = n / 10 ;
}
if(flag) cout << "Yes\n" ;
else cout <<"No\n" ;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
using namespace std;
string n;
int main() {
cin >> n;
for(auto x : n){
if(x == '7'){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
| 1 | 58,161,840 |
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <cmath>
using namespace std;
struct point {
int x;
int y;
};
int main() {
int n;
cin >> n;
vector<point> points(n);
for (int i = 0; i < n; i++) {
int x,y;
cin >> x >> y;
points[i] = {x,y};
}
sort(points.begin(), points.end(), [](const auto& a, const auto& b) {
return atan2l(a.y, a.x) > atan2l(b.y, b.x); });
long long int result = 0ll;
for (int i = 0; i < n; i++) {
long long int x = 0;
long long int y = 0;
for (int j = 0; j < n; j++) {
int k = (i+j) % n;
int k_x = points[k].x;
int k_y = points[k].y;
x += k_x;
y += k_y;
result = max(result, x*x+y*y);
}
}
cout << fixed << setprecision(15) << sqrtl(result) << endl;
}
|
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
using namespace std;
#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct P
{
double x, y, r;
P(double x, double y) :x(x), y(y), r(atan2(y, x) + M_PI) {}
P() :P(0.0, 0.0) {}
bool operator<(const P& other)const
{
return r < other.r;
}
};
int N;
vector<P> Ps;
vector<double> ct;
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
double x, y;
rep(i, 0, N)
{
cin >> x >> y;
Ps.push_back(P(x, y));
}
sort(all(Ps));
double ans = 0.0;
rep(i, 0, N)
{
pdd res = mp(Ps[i].x, Ps[i].y);
int j = (i + 1) % N;
chmax(ans, sqrt(res.first*res.first + res.second*res.second));
while (j != i)
{
res.first += Ps[j].x;
res.second += Ps[j].y;
chmax(ans, sqrt(res.first*res.first + res.second*res.second));
j = (j + 1) % N;
}
}
cout << fixed << setprecision(12) << ans << endl;
return 0;
}
| 1 | 80,141,223 |
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
#define fi first
#define se second
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);
void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}
int N, H[25];
int main(){
cin >> N;
for (int i = 0; i < N; i++) cin >> H[i];
int ans = 0, now = 0;
for (int i = 0; i < N; i++){
if (now <= H[i]) ans++;
now = max(now, H[i]);
}
cout << ans << 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;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;
template <typename T>
void print_vec(vector<T> v) {
for (T i : v) cout << i << " ";
cout << endl;
}
int main() {
int n;
cin >> n;
int ans = 0;
int mx = 0;
rep(i, n) {
int h;
cin >> h;
if (h >= mx) ans++;
mx = max(mx, h);
}
cout << ans << endl;
return 0;
}
| 1 | 77,474,225 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll N;
cin >> N;
ll ans = 0;
ll n = 5;
if (N % 2) {
cout << 0 << endl;
return 0;
} else {
while (n <= N) {
ans += N / (n*2);
n *= 5;
}
cout << ans << endl;
}
}
|
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test long long t;cin >> t;while(t--)
#define ses "\n"
#define whp " "
#define mxi 1000000
#define REP(i,a,b) for(int i=a; i<b; i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
# define INF 0x3f3f3f3f
typedef long long v99;
typedef unsigned long long ull;
using namespace std;
v99 fx[4]= {1,-1,0,0};
v99 fy[4]= {0,0,1,-1};
long double power(long double p,long double q)
{
long double ans=pow(p,q);
return ans;
}
v99 koita_ache(v99 n,v99 base)
{
v99 kot=0;
while(n)
{
n/=base;
kot+=n/2;
}
return kot;
}
int main()
{
{
v99 n;cin>>n;
if(n&1)cout<<0<<ses;
else cout<<koita_ache(n,5)<<ses;
}
return 0;
}
| 1 | 71,632,833 |
#include <cstdio>
using namespace std;
int main() {
int n = 0;
double N = 0;
int M = 0;
int L = 100;
int c = 0;
scanf("%d", &n);
for (int i = 0;i < n; i++) {
N = L;
M = L;
c = 0;
N *= 1.05;
N -= M;
while (N > 1) {
N -= 1;
c += 1;
}
if ( N > 0) {
L += 1;
}
L += c;
}
L *= 1000;
printf("%d\n", L);
return 0;
}
|
#include <iostream>
using namespace std;
int main(void)
{
int y = 100000;
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
y += y * 0.05;
if (y % 1000 != 0)
{
y = ((y / 1000) + 1) * 1000;
}
}
cout << y << endl;
}
| 1 | 36,457,696 |
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define REP(i, lower, upper) for (long long i = lower; i < upper; i++)
#define ALL(list) (list.begin()), (list.end())
using namespace std;
using bint = boost::multiprecision::cpp_int;
typedef long long ll;
constexpr int MOD = 10000007;
vector<long long> divisor(long long n) {
vector<long long> head, tail;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
head.push_back(i);
if (i * i != n)
tail.push_back(n / i);
}
}
head.insert(head.end(), tail.rbegin(), tail.rend());
return (head);
}
void execute() {
ll a,b;
cin>>a>>b;
cout<<lcm(a,b)<<endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
execute();
return (0);
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll a,b,c,d; cin>>a>>b; c=min(a,b); d=max(a,b);
ll l=__gcd(c,d);
ll r=(a*b);
cout<<r/l;
}
| 1 | 67,586,369 |
#include<iostream>
using namespace std;
int f(int x){
return x*x;
}
int integral(int d, int d0){
if(d >= 600){
return 0;
}
return(f(d)*d0 + integral(d+d0, d0));
}
int main(){
int d;
while(cin >> d){
cout << integral(d, d) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi i <= _##i poi i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi i < _##i poi i++)
#define downto(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi i >= _##i poi i--)
#define downtil(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi i > _##i poi i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)
#define poi ;
#define poipoi << "\n"
#define fuwafuwa(n, c) dokidoki((n) + (c) - 1, c)
#define dokidoki(n, c) ((n) / (c) * (c))
template<class T> bool read(T& t){
return cin >> t poi
}
template<class T, class...U> bool read(T& t, U&... u){
unless(cin >> t) return false poi
return read(u...) poi
}
int main(){
int d poi
while(read(d)){
int pyon = 0 poi
times(600 / d, i) pyon += i * i poi
cout << pyon * d * d * d poipoi poi
}
return 0 poi
}
| 1 | 46,248,807 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
int max = (a > b) ? a : b;
int min = (a > b) ? b : a;
while (max % min)
{
int tmp = max % min;
max = min;
min = tmp;
}
return min;
}
int main()
{
int n, x, ans(0);
cin >> n >> x;
int city[n];
for (int &i : city)
{
cin >> i;
i -= x;
}
if (n > 1)
{
ans = gcd(abs(city[0]), abs(city[1]));
for (int i = 2; i < n; ++i)
{
ans = gcd(abs(ans), abs(city[i]));
}
}
else if (n == 1)
ans = abs(city[0]);
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
int main(){
int n;
cin >> n;
ve<int> a(n+1);
rep(i,n+1) cin >> a[i];
sort(a.begin(), a.end());
ve<int> sa(n);
rep(i,n) sa[i] = a[i+1]-a[i];
int ans = sa[0];
rep(i,n-1) ans = __gcd(ans,sa[i+1]);
cout << ans << endl;
return 0;
}
| 1 | 82,619,684 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
const int N = 200005;
int par[N], rnk[N];
int get(int x){
if(x==par[x]) return x;
else return par[x] = get(par[x]);
}
void union_set(int c, int d){
c=get(c);
d=get(d);
if(c!=d){
if(rnk[c]>rnk[d])swap(c, d);
par[c]=d;
rnk[d] += rnk[c];
}
}
signed main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n>>m;
for(int i=1; i<=n; ++i) par[i]=i, rnk[i]=1;
for(int i=0; i<m; ++i){
int c,d;
cin>>c>>d;
union_set(c,d);
}
int ans=0;
for(int i=1; i<=n; ++i){
if(i==par[i]){
ans = max(ans, rnk[i]);
}
}
cout<<ans;
return 0;
}
|
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const ll oo = 1e18 + 7;
const ll mod = 1e9 + 7, maxn = 2e5 + 10;
const long double PI = acos(-1);
int cnt = 1, ps[maxn], sz[maxn];
int find(int x){
if (x == ps[x]) return x;
return ps[x] = find(ps[x]);
}
void uni(int a, int b){
a = find(a);
b = find(b);
if (a == b) return;
ps[a] = b;
sz[b] += sz[a];
cnt = max(cnt, sz[b]);
}
void init(){
iota(ps, ps+maxn, 0);
for (int i=0; i<maxn; i++) sz[i] = 1;
}
int main (){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
init();
for (int i=0; i<m; i++){
int a, b;
cin >> a >> b;
uni(--a, --b);
}
cout << cnt << endl;
return 0;
}
| 1 | 92,207,099 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
string s;
cin >> s;
vector<int> cnt(26);
ll ans =0;
for(auto c:s)
{
for(int i =0 ;i<26;i++)
{
if(i+'a'==c)continue;
ans+=cnt[i];
}
cnt[c-'a']++;
}
cout<<ans+1<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200000 + 10;
char s[N]; int c[30];
int main() {
scanf("%s",s+1);
for(int i=1;s[i];i++) c[s[i]-'a']++;
LL n=strlen(s+1);
LL tot=n*(n-1)/2;
for(int i=0;i<26;i++){
tot=tot-1LL*c[i]*(c[i]-1)/2;
}
tot++;
cout<<tot<<endl;
}
| 1 | 29,119,531 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
char maze[1005][1005];
int d[1005][1005];
int dirx[4] = {0, -1, 0, 1};
int diry[4] = {1, 0, -1, 0};
int h, w, n, hard;
int si, sj;
const int INF = 1<<30;
int tot = 0;
void BFS(int ai, int aj){
queue<P> que;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
d[i][j] = INF;
}
}
que.push(P(ai, aj));
d[ai][aj] = 0;
while(!que.empty()){
P a = que.front();
que.pop();
int x = a.first, y = a.second;
if(maze[x][y]-'0' == hard){
tot += d[x][y];
si = x; sj = y;
break;
}
for(int i = 0; i < 4; i++){
int dx = x+dirx[i], dy = y+diry[i];
if(dx>=0 && dx<h && dy>=0 && dy<w && maze[dx][dy]!='X' && d[dx][dy]==INF){
d[dx][dy] = d[x][y]+1;
que.push(P(dx, dy));
}
}
}
}
int main(int argc, char const *argv[]){
while(scanf("%d%d%d", &h, &w, &n) != EOF){
getchar();
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
scanf("%c", &maze[i][j]);
if(maze[i][j] == 'S'){
si = i; sj = j;
}
}
getchar();
}
tot = 0;
hard = 1;
for(int i = 0; i < n; i++){
BFS(si, sj);
hard++;
}
cout << tot << endl;
}
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<queue>
using namespace std;
typedef pair<int,int> P;
#define INF 1000000
int dx[4]={1,0,0,-1}, dy[4]={0,1,-1,0};
int d[1010][1010];
char r[1010][1010];
char point[10]={'S','1','2','3','4','5','6','7','8','9'};
int H,W,N;
int res=0;
int bfs(int ah,int aw,int bh,int bw){
queue<P> que;
for(int i=0;i<H;i++)
for(int j=0;j<W;j++)
d[i][j]=INF;
d[ah][aw]=0;
que.push(P(ah,aw));
while(que.size()){
P p= que.front();
que.pop();
if(p.first==bh && p.second==bw) break;
for(int i=0;i<4;i++){
int nh=p.first+dx[i], nw=p.second+dy[i];
if(0<=nh && nh<H && 0<=nw && nw<W && r[nh][nw]!='X' && d[nh][nw]==INF){
que.push(P(nh,nw));
d[nh][nw]=d[p.first][p.second]+1;
}
}
}
return d[bh][bw];
}
void solve(){
queue<P> kyu;
for(int k=0;k<=N;k++){
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(r[i][j]==point[k])
kyu.push(P(i,j));
}
}
}
for(int i=0;i<N;i++){
P p1=kyu.front();
kyu.pop();
P p2=kyu.front();
res+=bfs(p1.first,p1.second,p2.first,p2.second);
}
printf("%d\n",res);
}
int main(){
scanf("%d%d%d",&H,&W,&N);
for(int i=0;i<H;i++)
scanf("%s",&r[i]);
solve();
return 0;
}
| 1 | 58,590,079 |
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
vector<int>E[100];
int d[100];
int main(){
int n;cin>>n;
rep(i,n){
int u,k;cin>>u>>k;u--;
rep(i,k){
int v;cin>>v;v--;
E[u].push_back(v);
}
}
memset(d,0x3f,sizeof(d));
queue<P>que;
d[0]=0;que.push(P(0,0));
while(!que.empty()){
P p=que.front();que.pop();
for(int u:E[p.second]){
if(d[u]>p.first+1){
d[u]=p.first+1;
que.push(P(d[u],u));
}
}
}
rep(i,n){
if(d[i]==INF)cout<<i+1<<" -1"<<endl;
else cout<<i+1<<' '<<d[i]<<endl;
}
}
|
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;
class Graph{
public:
int v;
int cost = inf;
int ftime = -1;
int ltime = -1;
vector<int> e;
};
vector<Graph> g;
int cnt = 0;
void dfs(int pos){
if( g[pos].ftime != -1 ) return;
cnt++;
g[pos].ftime = cnt;
for(int i=0; i<g[pos].e.size(); i++){
dfs(g[pos].e[i]);
}
cnt++;
g[pos].ltime = cnt;
}
void bfs(int pos){
queue<int> q;
q.push(pos);
while(!q.empty()){
int p = q.front();
q.pop();
for(int i=0; i<g[p].e.size(); i++){
if( g[ g[p].e[i] ].cost != inf ) continue;
g[ g[p].e[i] ].cost = min(g[ g[p].e[i] ].cost, g[p].cost + 1);
q.push(g[p].e[i]);
}
}
}
int main(void) {
int n;
cin >> n;
g.resize(n);
int u, k;
for(int i=0; i<n; i++){
cin >> u >> k;
u--;
g[u].v = u;
g[u].e.resize(k);
for(int j=0; j<k; j++){
cin >> g[u].e[j];
g[u].e[j]--;
}
sort(g[u].e.begin(), g[u].e.end());
}
g[0].cost = 0;
bfs(0);
for(int i=0; i<n; i++) cout << g[i].v + 1 << " " << (g[i].cost == inf ? -1 : g[i].cost) << endl;
return 0;
}
| 1 | 94,112,956 |
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
const ll INFL = 1LL << 60;
const int INF = 1 << 30;
ll MOD = 1000000007;
ll pow_long(ll x, ll k){
ll res = 1;
while(k > 0){
if(k % 2) res *= x;
x *= x;
k /= 2;
}
return res;
}
ll pow_mod(ll x, ll k){
x %= MOD; x += MOD; x %= MOD;
ll res = 1;
while(k > 0){
if(k % 2){
res *= x; res %= MOD;
}
x *= x; x %= MOD;
k /= 2;
}
return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};
ll gcd(ll a, ll b){
if(b == 0) return a;
return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};
ll kai_mod(ll x){
if(x == 0) return 1;
return x * kai_mod(x-1) % MOD;
}
int main(){
ll X, Y;
cin >> X >> Y;
if(X % Y == 0) cout << -1 << endl;
else{
for(ll i = 1;;i++){
if((X * i) % Y){
cout << X * i << endl;
return 0;
}
}
}
}
|
#include <iostream>
#include <cstdio>
using namespace std;
char c;
long long a, b;
long long ans;
bool check()
{
return a%b==0;
}
void solve()
{
if (check())
ans = -1;
else
ans = a*(b-1);
return;
}
main()
{
cin.tie(0);
ios::sync_with_stdio(0);
cin >> a >> b;
solve();
cout << ans << endl;
return 0;
}
| 1 | 25,258,436 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using namespace std;
int main() {
int a,b,c; cin >> a >> b >> c;
int d = a%b;
int s = d;
while(1){
if(d == c) break;
else{
d += s;
d %= b;
if(d == s) break;
};
}
cout << ((d == c)?"YES":"NO");
return 0;
}
|
#include <bits/stdc++.h>
#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
if(x%y==0)return y;
return gcd(y,x%y);
}
ll LCM(int a, int b){
return a*b/gcd(a,b);
}
int main(void){
int a,b,c;
cin>>a>>b>>c;
for(int i=a;i<=100*a;i+=a){
if(i%b==c){cout<<"YES"<<endl; return 0;}
}
cout<<"NO"<<endl;
return 0;
}
| 1 | 93,460,018 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> c(n - 1), s(n - 1), f(n - 1);
rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];
for (int num = 0; num < n - 1; ++num) {
vector<int> now_train(n - 1);
rep(i, n - 1) {
now_train[i] = s[i];
}
int now;
for (int i = num; i < n - 1; ++i) {
if (i == num) {
now = c[num] + s[num];
}
else {
now = now_train[i] + c[i];
}
for (int j = i + 1; j < n - 1; ++j) {
while (now_train[j] < now) now_train[j] += f[j];
}
}
cout << now << endl;
}
cout << 0 << endl;
return 0;
}
|
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma region header
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
#pragma endregion
#pragma endregion
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
lint n; cin >> n;
vector<lint> 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++) {
lint sum = 0;
for (int j = i; j < n - 1; j++) {
if (sum <= s[j]) sum = s[j] + c[j];
else {
if ((sum - s[j]) % f[j] == 0) sum += c[j] + (sum - s[j]) % f[j];
else sum += c[j] + (f[j] - (sum - s[j]) % f[j]);
}
}
cout << sum << endl;
}
cout << 0 << endl;
return 0;
}
| 1 | 59,159,217 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
ll a,b;
cin >> a >> b;
vector<ll>ans(10,0);
if(a>b){
for(ll i=0;i<a;i++){
ans[i]=b;
}
}
else {
for(ll i=0;i<b;i++){
ans[i]=a;
}
}
for(ll i=0;i<10;i++){
if(ans[i]==0) break;
cout << ans[i];
}
cout << endl;
}
|
#include <iostream>
using namespace std;
int main(){
int a,b;
cin >> a >> b;
int x=max(a,b);
int y=min(a,b);
for(int i=0;i<x;i++){
cout << y;
}
}
| 1 | 85,876,803 |
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;
const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;
template<class T, class S>
bool chmax(T &a, const S &b){
if(a < b){
a = b; return true;
}
return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
if(b < a){
a = b; return true;
}
return false;
}
int main(){
string S, key("keyence");
cin >> S;
if(S == key){
cout << "YES" << endl;
return 0;
}
int n(S.length());
REP(i, n){
FOR(j, i, n){
string T("");
REP(k, n){
if(k < i || j < k)
T += S[k];
}
if(T == key){
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;
int main() {
string S;
cin >> S;
if (S == "keyence" || S.substr(0,7) == "keyence" || S.substr(S.size()-7,7) == "keyence") {
cout << "YES" << endl;
return 0;
}
vector<vector<string>> v = {
{"k", "eyence"},
{"ke", "yence"},
{"key", "ence"},
{"keye", "nce"},
{"keyen", "ce"},
{"keyenc", "e"},
};
string ans = "NO";
rep(i,0,v.size()-1) {
string l = v[i][0];
string r = v[i][1];
bool lok = false, rok = false;
if (S.substr(0,l.size()) == l && S.substr(S.size()-r.size(),r.size()) == r) {
ans = "YES";
}
}
cout << ans << endl;
return 0;
}
| 1 | 78,669,231 |
#include<bits/stdc++.h>
using namespace std;
const int MAX = 2 * 1000 * 100 + 11;
int parent[MAX];
int sizeOfSet[MAX];
int n, m;
void make_set(int node) {
parent[node] = node;
sizeOfSet[node] = 1;
}
int find_set(int node) {
if(node == parent[node]) {
return node;
}
return parent[node] = find_set(parent[node]);
}
void union_sets(int firstNode, int secondNode) {
int parentOfFirstNode = find_set(firstNode);
int parentOfSecondNode = find_set(secondNode);
if(parentOfFirstNode != parentOfSecondNode) {
if(sizeOfSet[parentOfFirstNode] < sizeOfSet[parentOfSecondNode])
swap(parentOfFirstNode, parentOfSecondNode);
parent[parentOfSecondNode] = parentOfFirstNode;
sizeOfSet[parentOfFirstNode] += sizeOfSet[parentOfSecondNode];
}
}
int main()
{
int n; cin >> n;
for(int i = 1; i <= n; i++)
{
make_set(i);
}
int t; cin >> t;
while(t--)
{
int a, b, c;
cin >> a >> b >> c;
if(a == 0)
{
union_sets(b + 1, c + 1);
}
else
{
if(find_set(b+1) == find_set(c+1))
{
cout << '1' << endl;
}
else
{
cout << '0' << endl;
}
}
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n,q,p[maxn];
int find(int u)
{
if(p[u]!=u) p[u]=find(p[u]);
return p[u];
}
void read(int& ret)
{
ret=0;
char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') ret=(ret<<3)+(ret<<1)+ch-'0',ch=getchar();
}
int main()
{
read(n),read(q);
for(int i=1;i<n;i++) p[i]=i;
while(q--){
int type,u,v;
scanf("%d%d%d",&type,&u,&v);
int root1=find(u),root2=find(v);
if(!type) p[root2]=root1;
else {
if(root1!=root2) printf("0\n");
else printf("1\n");
}
}
}
| 1 | 41,865,845 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;
const int MOD = 1000000007;
typedef pair<int,int> P;
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 /gcd(a,b) * b;
}
bool is_prime(long long N) {
if (N == 1) return false;
for (long long i = 2; i * i <= N; ++i) {
if (N % i == 0) return false;
}
return true;
}
vector<pair<long long, long long> > prime_factorize(long long n) {
vector<pair<long long, long long> > res;
for (long long p = 2; p * p <= n; ++p) {
if (n % p != 0) continue;
int num = 0;
while (n % p == 0) { ++num; n /= p; }
res.push_back(make_pair(p, num));
}
if (n != 1) res.push_back(make_pair(n, 1));
return res;
}
int binary(int bina){
int ans = 0;
for (int i = 0; bina>0 ; i++)
{
ans = ans+(bina%2)*pow(10,i);
bina = bina/2;
}
return ans;
}
int main() {
ll x;
cin >> x;
cout << lcm(360,x)/x << endl;
}
|
#include <iostream>
#include <cstdio>
using namespace std;
int X;
int main () {
scanf ("%d", &X);
for (int i = 1; ; ++i) if (i * X % 360 == 0) { printf ("%d\n", i); return 0; }
return 0;
}
| 1 | 59,230,895 |
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
vector<ll> all,pate;
ll ans = 0;
ll dfs(ll n, ll x){
if(!n) return 0;
if(x) x--;
if(x){
if(all[n-1] <= x){
ans += pate[n-1];
x -= all[n-1];
}else{
dfs(n-1,x);
x = 0;
}
}
if(x){ x--; ans++; }
if(x){
if(all[n-1] <= x){
ans += pate[n-1];
x -= all[n-1];
}else{
dfs(n-1,x);
x = 0;
}
}
if(x) x--;
return ans;
}
int main(){
cin.tie(0), ios::sync_with_stdio(false);
ll n,x; cin >> n >> x;
all = vector<ll>(n+1);
pate = vector<ll>(n+1);
all[0] = pate[0] = 1;
rep(i,n){
all[i+1] += all[i] * 2 + 3;
pate[i+1] += pate[i] * 2 + 1;
}
cout << dfs(n,x);
cout << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int64_t leftPs(int n, int64_t x) {
int64_t sz = (1LL << (n + 2)) - 3;
if (x == sz) return (1LL << (n + 1)) - 1;
if (x == 1) return 0;
if (x == sz / 2 + 1) return 1LL << n;
if (x < sz / 2 + 1) return leftPs(n - 1, x - 1);
if (x > sz / 2 + 1) return (1LL << n) + leftPs(n - 1, x - (sz / 2 + 1));
}
int main() {
int n;
int64_t x;
cin >> n >> x;
cout << leftPs(n, x) << '\n';
}
| 1 | 98,708,083 |
#define _USE_MATH_DEFINES
#include<iostream>
#include<math.h>
using namespace std;
const float TH = 60.0 * M_PI/180.0;
typedef struct {
float x;
float y;
} Vertex;
void Koch(int d, Vertex p1, Vertex p2);
int main() {
int deep;
Vertex p1;
Vertex p2;
p1.x = 0; p1.y = 0;
p2.x = 100; p2.y = 0;
cin >> deep;
cout << p1.x << " " << p1.y << endl;
Koch(deep, p1, p2);
cout << p2.x << " " << p2.y << endl;
return 0;
}
void Koch(int d, Vertex p1, Vertex p2) {
if (d <= 0) {
return;
}
Vertex s, t, u;
s.x = (2 * p1.x + 1 * p2.x) / 3;
s.y = (2 * p1.y + 1 * p2.y) / 3;
t.x = (1* p1.x + 2 * p2.x) / 3;
t.y = (1 * p1.y + 2 * p2.y) / 3;
u.x = (t.x - s.x)*cos(TH) - (t.y - s.y)*sin(TH) + s.x;
u.y = (t.x - s.x)*sin(TH) + (t.y - s.y)*cos(TH) + s.y;
Koch(d - 1, p1, s);
cout << s.x << " " << s.y << endl;
Koch(d - 1, s, u);
cout << u.x << " " << u.y << endl;
Koch(d - 1, u, t);
cout << t.x << " " << t.y << endl;
Koch(d - 1, t, p2);
return;
}
|
#include<iostream>
#include<cmath>
#include<iomanip>
#define PI 3.141592
using namespace std;
struct coordinate{
double x;
double y;
};
void kock(int n,struct coordinate left,struct coordinate right){
if (n == 0) return;
struct coordinate s,t,u;
s.x = (left.x * 2 + right.x * 1)/3;
s.y = (left.y * 2 + right.y * 1)/3;
t.x = (left.x * 1 + right.x * 2)/3;
t.y = (left.y * 1 + right.y * 2)/3;
u.x = (t.x - s.x) * cos(PI/3) - (t.y - s.y) * sin(PI/3) + s.x;
u.y = (t.x - s.x) * sin(PI/3) + (t.y - s.y) * cos(PI/3) + s.y;
kock(n-1,left,s);
cout << setprecision(10) << s.x << " " << setprecision(10) << s.y << endl;
kock(n-1,s,u);
cout << setprecision(10) << u.x << " " << setprecision(10) << u.y << endl;
kock(n-1,u,t);
cout << setprecision(10) << t.x << " " << setprecision(10) << t.y << endl;
kock(n-1,t,right);
}
int main(){
int n; cin >> n;
struct coordinate p1,p2;
p1.x = 0;
p1.y = 0;
p2.x = 100;
p2.y = 0;
cout << p1.x << " " << p1.y << endl;
kock(n,p1,p2);
cout << p2.x << " " << p2.y << endl;
return 0;
}
| 1 | 28,425,236 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string ABCD;
cin >> ABCD;
int A = ABCD[0] - '0';
int B = ABCD[1] - '0';
int C = ABCD[2] - '0';
int D = ABCD[3] - '0';
if(A+B+C+D==7) {
cout<<A<<"+"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
}else if(A-B+C+D==7) {
cout<<A<<"-"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
}else if(A+B-C+D==7) {
cout<<A<<"+"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
}else if(A-B-C+D==7) {
cout<<A<<"-"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
}else if(A+B+C-D==7) {
cout<<A<<"+"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
}else if(A-B+C-D==7) {
cout<<A<<"-"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
}else if(A+B-C-D==7) {
cout<<A<<"+"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
}else if(A-B-C-D==7) {
cout<<A<<"-"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
}
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
long a,b,c,d;
string abcd;
cin >> abcd;
a=abcd[0]-'0';
b=abcd[1]-'0';
c=abcd[2]-'0';
d=abcd[3]-'0';
vector<int> p(3);
p[0] = b;
p[1] = c;
p[2] = d;
for(ll bit = 0; bit < (1<<3); ++bit){
int sum;
sum = a;
for(int i = 0; i < 3; i++){
if(bit & (1<<i)){
sum = sum + p[i];
}
else{
sum = sum - p[i];
}
}
if(sum == 7){
string x, y, z;
if(bit & (1<<0)){
x = '+';
}
else{
x = '-';
}
if(bit & (1<<1)){
y = '+';
}
else{
y = '-';
}
if(bit & (1<<2)){
z = '+';
}
else{
z = '-';
}
cout << a << x << p[0] << y << p[1] << z << p[2] << '=' << 7;
return 0;
}
}
return 0;
}
| 1 | 58,890,641 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;
int main() {
int N;
cin >> N;
int X = 0, Y = 0, T = 0;
for(int i=0; i<N; i++) {
int x, y, t;
cin >> t >> x >> y;
X = abs(x - X);
Y = abs(y - Y);
T = t - T;
if((T < X + Y) || (T - X - Y) % 2 != 0) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin>>n;
int t[n+1],x[n+1],y[n+1]; t[0]=0,x[0]=0,y[0]=0;
for(int i=1;i<n+1;i++) cin>>t[i]>>x[i]>>y[i];
for(int i=0;i<n;i++){
int d=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
int u=t[i+1]-t[i];
if(d>u||(d<u&&(u-d)%2)){cout<<"No"; return 0;}
}
cout<<"Yes";
}
| 1 | 18,770,970 |
#include <stdio.h>
#define EPSILON 1.0e-6
int main(int argc, char** argv)
{
double x1, y1, x2, y2, x3, y3, xp, yp;
while (fscanf(stdin,
"%lf %lf %lf %lf %lf %lf %lf %lf",
&x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) == 8) {
double s = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
double u = ((xp - x1) * (y3 - yp) - (yp - y1) * (x3 - xp)) / s;
double v = ((x2 - x1) * (yp - y2) - (y2 - y1) * (xp - x2)) / s;
if (u > -EPSILON && v > -EPSILON && u + v < 1.0 + EPSILON) {
fputs("YES\n", stdout);
}
else {
fputs("NO\n", stdout);
}
}
}
|
#include <iostream>
using namespace std;
int main()
{
double x1,y1,x2,y2,x3,y3,xp,yp;
double m,n;
while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp)
{
m = ((xp - x1) * (y3 - y1) - (yp - y1) * (x3 - x1)) /
((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1));
n = ((xp - x1) * (y2 - y1) - (yp - y1) * (x2 - x1)) /
((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1));
if(m > 0 && n > 0 && m + n < 1) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
| 1 | 19,669,996 |
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX = 100005;
int main() {
int N;
int A[MAX];
int counting[MAX] {0};
cin >> N;
int maxv {0};
for (int i = 0; i < N; i++) {
cin >> A[i];
if (maxv < A[i]) maxv = A[i];
counting[A[i]]++;
}
int ans {0};
int tmp_ans {0};
for (int i = 1; i < MAX-1; i++) {
tmp_ans = counting[i-1] + counting[i] + counting[i+1];
if (tmp_ans > ans) ans = tmp_ans;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,ans=0;
int a[200005],visited[200005];
signed main()
{
cin>>n;
for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=n;i++) visited[a[i]]++;
for (int i=1;i<=200000;i++) ans=max(ans,visited[i]+visited[i-1]+visited[i+1]);
cout<<ans<<endl;
return 0;
}
| 1 | 56,695,560 |
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
int main() {
int N;
cin >> N;
pii xy[100];
REP(i, N) {
int x, y;
cin >> x >> y;
xy[i] = {x, y};
}
sort(xy, xy + N, [](const pii &p1, const pii&p2) { return atan2(p1.second, p1.first) < atan2(p2.second, p2.first); });
double ans = 0;
REP(i, N) {
ll x = 0, y = 0, r = i;
REP(j, N) {
x += xy[r].first;
y += xy[r].second;
ans = max(ans, sqrt(x * x + y * y));
r = (r + 1) % N;
}
}
cout << setprecision(30) << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105;
struct node{
int x,y;
bool operator<(const node&o)const{
return atan2(y,x)<atan2(o.y,o.x);
}
}a[N<<1];
int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a+1,a+1+n);
for(int i=1;i<=n;i++) a[i+n]=a[i];
double ans=0;
for(int i=1;i<=n;i++){
ll x=0,y=0;
for(int j=i;j<i+n;j++){
x+=a[j].x;y+=a[j].y;
ans=max(ans,sqrt(x*x+y*y));
}
}
printf("%.15f\n",ans);
}
| 1 | 100,349,311 |
#include <stdio.h>
int main(){
int n;
scanf("%d", &n);
int T, K;
scanf ("%d %d", &T, &K);
for (int i = T; i <= K; i++){
if (i % n == 0){
puts("OK");
return 0;
}
else continue;
}
puts("NG");
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin >>a>>b>>c;
if(b/a==c/a&&b%a!=0){
cout << "NG"<<endl;
}
else{
cout <<"OK" <<endl;
}
}
| 1 | 4,051,620 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Field = vector<vector<ll>>;
using Graph = vector<vector<ll>>;
using VI = vector<int>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VC = vector<char>;
using PI = pair<int, int>;
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()
const long long INF = 1LL<<60;
const int mod = 1000000007;
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; }
int H, N;
vector<int> A, B;
vector<vector<ll>> dp(1010, vector<ll>(10010, INF));
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> H >> N;
A.resize(N); B.resize(N);
REP(i, N) {
cin >> A[i] >> B[i];
}
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= H; j++) {
chmin(dp[i + 1][j], dp[i][j]);
if (j + A[i] >= H) {
chmin(dp[i + 1][H], dp[i + 1][j] + B[i]);
} else {
chmin(dp[i + 1][j + A[i]], dp[i + 1][j] + B[i]);
}
}
}
cout << dp[N][H] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double
int h,n;
vector<pair<int,int>>v;
int cache[1001][10001];
int dp(int pos,int hl)
{
if(hl<=0)
return 0;
if(pos==n)
return 1e18;
int &ans=cache[pos][hl];
if(ans!=-1)
return ans;
ans=dp(pos+1,hl);
ans=min(ans,v[pos].second+dp(pos,hl-v[pos].first));
return ans;
}
int32_t main()
{
IOS
cin>>h>>n;
for(int i=0;i<n;i++)
{
int a,b;
cin>>a>>b;
v.push_back({a,b});
}
memset(cache,-1,sizeof(cache));
print(dp(0,h));
}
| 1 | 7,993,454 |
#include<bits
using namespace std;
int main(){
set<int> st;int n;
for(int i = 0; i <3;i++){
cin >> n;st.insert(n);
}cout <<st.size()<<endl;
}
|
#include <bits/stdc++.h>
#include <cmath>
#include <stdio.h>
using namespace std;
int gcd(int a, int b)
{
if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b, a%b));
}
}
int lcm(int a, int b)
{
return a * b / gcd(a, b);
}
int main() {
int A,B,C;
cin>>A>>B>>C;
if(A==B&&B==C&&C==A) cout<<1<<endl;
else if(A!=B&&B!=C&&C!=A) cout<<3<<endl;
else cout<<2<<endl;
}
| 1 | 74,729,096 |
#include<bits/stdc++.h>
#define ssg set<long long int , greater<long long int>>
using namespace std;
int main()
{
long long int a, b, c, d, e, f, max1, max2, max3, max4;
cin>>a>>b>>c>>d;
e=a;
f=c;
max1=e*f;
e=b;
f=c;
max2=e*f;
e=a;
f=d;
max3=e*f;
e=b;
f=d;
max4=e*f;
ssg set1;
set1.insert(max1);
set1.insert(max2);
set1.insert(max3);
set1.insert(max4);
set<int > :: iterator it;
cout<<*set1.begin()<<endl;
return 0;
}
|
#include<cstdio>
#include<set>
#include<stack>
#include<queue>
int main()
{
long long int a,b,c,d,x,ans;
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
ans=a*c;
x=a*d;
if(ans<x){ans=x;}
x=b*c;
if(ans<x){ans=x;}
x=b*d;
if(ans<x){ans=x;}
printf("%lld",ans);
}
| 1 | 87,934,523 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
string s;cin >> s;
rep(i,s.size()-1){
if(s[i]==s[i+1]){
cout << i+1 <<" " <<i+2 <<endl;
return 0;
}
}
rep(i,s.size()-2){
if(s[i]==s[i+2]){
cout << i+1 <<" " <<i+3 <<endl;
return 0;
}
}
cout << -1 <<" " <<-1 <<endl;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 111;
int a[N];
int sq(int x) {
return x * x;
}
int32_t main() {
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
string str; cin >> str;
int l = -1, r = -1;
for(int i = 0; i < str.size() - 1; ++i) {
if(str[i] == str[i + 1]) {
l = i + 1;
r = i + 2;
}
}
for(int i = 0; i + 2 < str.size(); i++) {
if(str[i] == str[i + 2]) {
l = i + 1;
r = i + 3;
}
}
cout << l << " " << r << endl;
}
| 1 | 55,974,337 |
#include<iostream>
using namespace std;
int main(){
int x,y;
while(cin>>x>>y && (x!=0 || y!=0)){
if (x>y){
cout << y << " " << x << endl;
} else {
cout << x << " " << y << endl;
}
}
return 0 ;
}
|
#include <stdio.h>
int main(){
int a,b,tmp;
scanf("%d %d",&a,&b);
while(a||b){
if(a>b){
tmp = a;
a = b;
b = tmp;
}
printf("%d %d\n",a,b);
scanf("%d %d",&a,&b);
}
}
| 1 | 31,632,184 |
#include <bits/stdc++.h>
using namespace std;
#define Maxn 107
#define inf 1000007
char s[Maxn][Maxn];
int last[1000007],pre[1000007],other[1000007],len[1000007],cnt=0;
int n,m;
int calc(int x,int y)
{
return (x-1)*m+y;
}
void insert(int u,int v,int l)
{
other[++cnt]=v,pre[cnt]=last[u],last[u]=cnt;
len[cnt]=l;
}
int dis[1000007];
bool vis[1000007];
priority_queue<pair<int,int> >que;
int dijkstra(int s,int t)
{
for (int i=1;i<=t;i++)
dis[i]=inf;
memset(vis,false,sizeof(vis));
while (!que.empty()) que.pop();
que.push(make_pair(0,s));
dis[s]=0;
while (!que.empty())
{
int u=que.top().second;
que.pop();
if (vis[u]) continue;
vis[u]=true;
for (int q=last[u];q;q=pre[q])
{
int v=other[q];
if (dis[v]>dis[u]+len[q])
{
dis[v]=dis[u]+len[q];
que.push(make_pair(-dis[v],v));
}
}
}
return dis[t];
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
scanf("%s",s[i]+1);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
if (i<n)
{
int tmp=0;
if (s[i][j]=='.'&&s[i][j]!=s[i+1][j]) tmp=1;
insert(calc(i,j),calc(i+1,j),tmp);
}
if (j<m)
{
int tmp=0;
if (s[i][j]=='.'&&s[i][j]!=s[i][j+1]) tmp=1;
insert(calc(i,j),calc(i,j+1),tmp);
}
}
int S=n*m+1,T=n*m+2;
if (s[1][1]=='.') insert(S,calc(1,1),0); else insert(S,calc(1,1),1);
insert(calc(n,m),T,0);
printf("%d\n",dijkstra(S,T));
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;
char s[101][101];
int a[101][101];
int cnt = 0;
void dfs(int y, int x){
}
int main(){
int h,w;
cin >> h >> w;
for(int i = 1; i <= h; i++){
for(int j = 1; j <= w; j++){
char c;
cin >> c;
if(c == '.'){
a[i][j] = 0;
}else{
a[i][j] = 1;
}
}
}
int dp[h+1][w+1];
dp[1][1] = a[1][1];
for(int i = 1; i <= h; i++){
for(int j = 1; j <= w; j++){
if(i == 1 && j == 1) continue;
if(i == 1) dp[i][j] = dp[i][j-1] + (a[i][j-1]?0:a[i][j]);
else if(j == 1) dp[i][j] = dp[i-1][j] + (a[i-1][j]?0:a[i][j]);
else dp[i][j] = min(dp[i-1][j] + (a[i-1][j]?0:a[i][j]) ,dp[i][j-1] + (a[i][j-1]?0:a[i][j]));
}
}
cout << dp[h][w] << endl;
}
| 1 | 98,033,771 |
#include<iostream>
#include<algorithm>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
int a[A], b[B];
rep(i,0,A-1) cin >> a[i];
rep(i,0,B-1) cin >> b[i];
int mina = *min_element(a, a+A);
int minb = *min_element(b, b+B);
int ans = mina + minb;
rep(i,0,M-1) {
int x, y, c;
cin >> x >> y >> c; x--; y--;
ans = min(ans, a[x] + b[y] - c);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int A,B,M;
cin>>A>>B>>M;
vector<int> a(A,0);
vector<int> b(B,0);
vector<int> c(M,0);
vector<int> x(M,0);
vector<int> y(M,0);
int min_a;
int min_b;
int min_mix=INT_MAX;
for (size_t i = 0; i < A; i++)
{
cin>>a[i];
}
for (size_t i = 0; i < B; i++)
{
cin>>b[i];
}
min_a = *std::min_element(a.begin(), a.end());
min_b = *std::min_element(b.begin(), b.end());
for (size_t i = 0; i < M; i++)
{
cin>>x[i]>>y[i]>>c[i];
min_mix = std::min(min_mix,a[x[i]-1]+b[y[i]-1]-c[i]);
}
cout << std::min(min_a+min_b, min_mix)<<endl;
return 0;
}
| 1 | 96,267,027 |
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#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 FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();
long long mod(long long val, long long m) {
long long res = val % m;
if (res < 0) res += m;
return res;
}
long long gcd(ll a, ll b)
{
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
long long lcm(ll a, ll b)
{
return a / gcd(a, b) * b ;
}
int main()
{
string s, t; cin >> s >> t;
sort(s.begin(), s.end());
sort(t.begin(), t.end());
reverse(t.begin(), t.end());
if (s < t)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
int main(){
std::string s,t;
std::cin >> s >> t;
std::sort(s.begin(), s.end());
std::sort(t.begin(), t.end(), std::greater<int>());
if(s<t) std::cout << "Yes" << "\n";
else std::cout << "No" << "\n";
return 0;
}
| 1 | 47,522,140 |
#include<bits/stdc++.h>
using namespace std;
int main () {
string s;
int a = 0, ans = 0;
cin >> s;
for (int i = 0; i < 3; i++) {
if (s[i] == 'R') {
a ++;
}
if (s[i] != 'R' || i == 2) {
ans = max(a,ans);
a = 0;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char arr[10];
scanf("%s", arr);
int rCount = 0, ans = 0;
for (int i = 0; i < 3; ++i) {
if (arr[i] == 'R') {
rCount++;
} else {
ans = max(ans, rCount);
rCount = 0;
}
}
ans = max(ans, rCount);
printf("%d\n", ans);
return 0;
}
| 1 | 1,622,379 |
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;
int N,M;
vector<vector<pair<LL,LL>>> adj;
vector<pair<LL,LL>> edge;
LL ans = 0;
void solve(){
map<pair<LL,LL>,bool> is_passed;
for(int start=1;start<=N;start++){
priority_queue<pair<LL,LL>,vector<pair<LL,LL>>,greater<pair<LL,LL>>> q;
vector<LL> dist(N+1,INF);
vector<LL> from(N+1,INF);
dist[start] = 0;
q.push(pair<LL,LL>(0,start));
while(!q.empty()){
pair<LL,LL> now = q.top();q.pop();
int now_v = now.second;
if(dist[now_v]<now.first) continue;
for(int i=0;i<adj[now_v].size();i++){
LL next_v = adj[now_v][i].second;
LL cost = adj[now_v][i].first;
if(dist[next_v]>dist[now_v]+cost){
dist[next_v] = dist[now_v] + cost;
from[next_v] = now_v;
q.push(pair<LL,LL>(dist[next_v],next_v));
}
}
}
for(int end=start+1;end<=N;end++){
int now = end;
while(now!=start){
is_passed[pair<LL,LL>(now,from[now])] = 1;
is_passed[pair<LL,LL>(from[now],now)] = 1;
now = from[now];
}
}
}
for(int i=0;i<edge.size();i++){
if(!is_passed[edge[i]]) ans++;
}
}
int main(){
cin >> N >> M;
adj = vector<vector<pair<LL,LL>>>(N+1);
for(int i=0;i<M;i++){
LL a,b,c;cin >> a >> b >> c;
adj[a].push_back(pair<LL,LL>(c,b));
adj[b].push_back(pair<LL,LL>(c,a));
edge.push_back(pair<LL,LL>(a,b));
}
solve();
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)
inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
cout << a << " , ";
logger(b...);
}
typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 105;
lint cost[MAX][MAX];
lint nxt[MAX][MAX];
int V;
void warshall_floyd(){
rep(i, V) rep(j, V) rep(k, V){
if(cost[j][i]+cost[i][k] < cost[j][k]){
cost[j][k] = cost[j][i]+cost[i][k];
nxt[j][k] = nxt[j][i];
}
}
}
bool edge[MAX][MAX], used[MAX][MAX];
void shortest_path(int s, int t){
int i = s, j;
while(j != t){
j = nxt[i][t];
used[i][j] = true; used[j][i] = true;
i = j;
}
}
int main(){
cin >> V; int m; cin >> m;
rep(i, V) rep(j, V){
if(i == j) cost[i][j] = 0;
else cost[i][j] = INF;
nxt[i][j] = j;
}
rep(i, m){
lint a, b, c; cin >> a >> b >> c;
a--; b--;
cost[a][b] = c;
cost[b][a] = c;
edge[a][b] = true; edge[b][a] = true;
}
warshall_floyd();
rep(i, V) rep(j, V){
if(i >= j) continue;
shortest_path(i, j);
}
int res = 0;
rep(i, V) rep(j, V){
if(edge[i][j] && !used[i][j]) res++;
}
out(res / 2);
}
| 1 | 68,430,790 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
int64_t K;
cin >> S;
cin >> K;
int64_t ini = 300;
int64_t ini_num = -1;
for ( int64_t i = 0; i < S.size(); ++i){
if ( S[i] != '1' ){
ini = i;
ini_num = S[i] - '0';
break;
}
}
if ( K >= ini + 1 ){
cout << ini_num << endl;
} else {
cout << S[K-1] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
int main(){
string S;
ll K;
cin >> S >> K;
int cnt1 = 0;
char ans;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '1') cnt1++;
else {
ans = S[i];
break;
}
}
if (K <= cnt1) cout << 1 << '\n';
else cout << ans << '\n';
}
| 1 | 15,976,092 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
int N;
cin >> N;
set<int> A;
for (int i = 0; i < N; ++i) {
int input;
cin >> input;
if(A.count(input) == 0) A.insert(input);
else{
cout << "NO" << "\n";
return 0;
}
}
cout << "YES" << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
ll n;
cin>>n;
map<ll,ll>ch;
for(ll i=0;i<n;i++){
ll x;
cin>>x;
ch[x]++;
if(ch[x]==2){
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
| 1 | 56,293,286 |
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;
int main(){
int N,M; cin >>N >>M;
vector<int> a(N);
vector<int> b(N);
rep(i,0,N) cin >>a[i] >>b[i];
vector<int> c(M);
vector<int> d(M);
rep(i,0,M) cin >>c[i] >>d[i];
vector<int> ans(N);
rep(i,0,N) {
int temp=INT_MAX;
rep(j,0,M) {
int check=abs(a[i]-c[j])+abs(b[i]-d[j]);
if (check<temp) {ans[i]=j+1; temp=check;}
}
}
rep(i,0,N) cout <<ans[i] <<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
int main(){
int n,m;
cin >> n >> m;
vector<p> stu, check;
for(int i = 0; i < n; i++){
ll a,b;
cin >> a >> b;
stu.push_back(p(a, b));
}
for(int i = 0; i < m; i++){
ll c,d;
cin >> c >> d;
check.push_back(p(c, d));
}
for(int i = 0; i < n; i++){
int ans = 0;
ll norm = pow(10, 9);
for(int j = 0; j < m; j++){
if(abs(stu.at(i).first - check.at(j).first)
+ abs(stu.at(i).second - check.at(j).second) < norm){
norm = abs(stu.at(i).first - check.at(j).first)
+ abs(stu.at(i).second - check.at(j).second);
ans = j;
}
}
cout << ans + 1 << endl;
}
}
| 1 | 21,043,337 |
#include <iostream>
using namespace std;
int main(){
int n;
long long a;
long long min = 1000000;
long long max = -1000000;
long long sum = 0;
cin >> n;
for(int i=1;i<=n;i++) {
cin >> a;
if(a < min) min = a;
if(max < a) max = a;
sum += a;
}
cout << min <<" "<< max <<" "<< sum << "\n";
return 0;
}
|
#include<stdio.h>
#include<climits>
#include<algorithm>
using namespace std;
int main(){
int n,x;
int min_num = INT_MAX,max_num = INT_MIN;
long long sum = 0;
scanf("%d",&n);
for(int i = 0;i < n;i++){
scanf("%d",&x);
min_num = min(min_num,x);
max_num = max(max_num,x);
sum += x;
}
printf("%d %d %lld\n",min_num,max_num,sum);
return 0;
}
| 1 | 47,939,289 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
if(N / 1000 == (N % 100) / 10 && (N % 1000) / 100 == (N % 100) / 10){
cout << "Yes" << endl;
}
else if((N % 1000) / 100 == (N % 1000) % 100 / 10 && (N % 1000) / 100 == (N % 10) / 1 ){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
int a,b,c,d;
cin >> N;
a = N % 10;
b = (N % 100 - a) / 10;
c = (N % 1000 - 10 * b - a) / 100;
d = (N % 10000 - 100 * c - 10 * b - a) / 1000;
if ( a == b && b == c){
cout << "Yes" << endl;
}
else if ( b == c && c == d){
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
| 1 | 13,671,035 |
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
vector<vector<pair<int, int>>> al(100000);
vector<bool> visited(100000, false);
vector<long long> dist(100000, INF * -1);
bool dfs(int i, int d) {
if(visited[i] && d != dist[i])
return false;
if(visited[i] && d == dist[i])
return true;
visited[i] = true;
dist[i] = d;
REP(j, al[i].size()) {
if(!dfs(al[i][j].first, d + al[i][j].second))
return false;
}
return true;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> L(M), R(M), D(M);
REP(i, M) {
cin >> L[i] >> R[i] >> D[i];
L[i]--;
R[i]--;
al[L[i]].push_back(make_pair(R[i], D[i]));
al[R[i]].push_back(make_pair(L[i], -D[i]));
}
REP(i, N) {
if(!visited[i]) {
if(!dfs(i, 0)) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
}
|
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
#define infile "../test/sample-1.in"
#define int long long
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#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 _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template <class T = int>
T in() {T x; cin>>x; return (x);}
struct Fast {
Fast(){
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
#ifdef PCM
#include "dump.hpp"
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int n,M;
int x[100000]={};
int dfs(int i, int pos, const auto& G){
if (x[i]==INF){
x[i] = pos;
foreach(p, G[i]){
dfs(p.first, pos + p.second, G);
}
}
return 0;
}
int solve(){
cin>>n>>M;
if (M==0){ cout << "Yes" << endl; return 0; }
int l[M],r[M],d[M];
rep(i, n){ x[i]=INF; }
vector<vector<pii>> G(n);
rep(i, M){
cin>>l[i]>>r[i]>>d[i];
l[i]--;r[i]--;
G[l[i]].pb(mp(r[i], d[i]));
G[r[i]].pb(mp(l[i], -d[i]));
}
rep(i, n){
dfs(i, 0, G);
}
dump_1d(x, n);
rep(m, M){
if (x[r[m]] - x[l[m]] != d[m]){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
int test(){
return 0;
}
signed main() {
#ifdef INPUT_FROM_FILE
std::ifstream in(infile);
std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
test();
#endif
solve();
return 0;
}
| 1 | 39,420,271 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;
vector<int> g[100005];
int n;
vector<int> res;
void dfs(int v, int p = -1, int cnt = 0) {
res[v] = cnt;
for (int c : g[v]) {
if (c == p) continue;
dfs(c, v, cnt + 1);
}
}
vector<int> distcalc(int a) {
res = vector<int>(n);
dfs(a);
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, h, w;
cin >> n >> h >> w;
int ans = 0;
while (n--) {
int a, b;
cin >> a >> b;
if (a >= h && b >= w) ans++;
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define int long long
#define rao(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
int n,a,b,c[100000],d[1000000],z=0;
cin>>n>>a>>b;
for(int i=0;i<n;i++){
cin>>c[i]>>d[i];
}
for(int i=0;i<n;i++){
if(a<=c[i] && b<=d[i]){
z++;
}
}
cout<<z<<"\n";
}
| 1 | 25,377,482 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.