code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 1
101M
|
|---|---|---|---|
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#define ll (long long)
#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 RFOR(i,a,b) for(int i = (a);i>(b);i--)
#define risi (0.05)
using namespace std;
int main(void)
{
int a,b,c,d;
int i,j,k,l;
int number;
int answercounter = 0;
int answerarray[1000] = {0};
int temp = 0;
while(cin >> number)
{
for(i = 0;i <= 9;i++)
if(i <= number)
for(j = 0;j<=9;j++)
if(i+j<= number)
for(k = 0;k<=9;k++)
if(i+j+k <= number)
for(l = 0;l<=9;l++)
if((i+j+k+l) == number)
temp++;
answerarray[answercounter] = temp;
temp = 0;
answercounter++;
}
REP(i,answercounter)
cout << answerarray[i] << endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;
int main() {
int H,W;
cin >> H >> W;
char c[H][W];
for(int i=0; i<H; ++i){
for(int j=0; j<W; ++j){
cin >> c[i][j];
}
}
char resC[2*H][W];
for(int i=0; i<H; ++i){
for(int j=0; j<W; ++j){
resC[2*i][j]=c[i][j];
resC[2*i+1][j]=c[i][j];
}
}
for(int i=0; i<2*H; ++i){
for(int j=0; j<W; ++j){
cout << resC[i][j];
}
cout << endl;
}
}
| 0
| 69,328,803
|
#include <iostream>
#include <string>
using namespace std;
int main(void){
int n, tp = 0, hp = 0;
string t,h;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> t >> h;
if(t > h){
tp +=3;
} else if(t == h){
tp +=1;
hp +=1;
} else {
hp += 3;
}
}
cout << tp << " " << hp << endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;
ll N;
ll cnt[100];
int main() {
cin >> N;
rep(i, 0, N) {
ll a;
cin >> a;
rep(i, 0, 60) {
if (a & (1LL << ll(i))) ++cnt[i];
}
}
ll ans = 0;
ll base = 1;
rep(i, 0, 60) {
ll ccnt = cnt[i] * (N - cnt[i]) % MOD;
ans += base * ccnt % MOD;
ans %= MOD;
base *= 2;
base %= MOD;
}
cout << ans;
}
| 0
| 5,882,809
|
#include<bits/stdc++.h>
using namespace std;
int main(){
while(1){
int n, h, m;
string str, c;
cin>>str;
if (str == "-") break;
cin>>m;
for(int i = 0; i < m; i++){
cin>>h;
c = str;
str = "";
for(int j = h; j < (int) c.size(); j++) {
str += c[j];
}
for(int j = 0; j < h; j++){
str += c[j];
}
}
cout<<str<<endl;
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000
#define base10_5 100000
#define base10_6 1000000
#define base10_7 10000000
#define base10_8 100000000
#define base10_9 1000000000
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";
ll A;
ll B;
ll C;
ll N;
ll M;
ll K;
ll ltmp;
string stmp;
double dtmp;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> A;
cin >> B;
cin >> N;
for( ll i = 1 ; i <=10 ; i++ ){
N = N * A - B;
cout << N << endl;
}
}
| 0
| 5,233,088
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
ll n,t,x; cin>>n>>t;
ll px=-1,ans=0;
for(ll i=0;i<n;i++){
cin>>x;
ans+=t;
if(px!=-1) ans-=max((ll)0,px-x+t);
px=x;
}
cout<<ans;
}
|
#include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
void solve() {
string S;
cin >> S;
ll N = (ll)S.size();
ll ans = 0;
ll cur = S[0] == 'W' ? 0 : 1;
for (ll i = 1; i < N; i++) {
ll t = S[i] == 'W' ? 0 : 1;
if (cur != t) {
++ans;
cur = t;
}
}
cout << ans << "\n";
}
int main() {
#ifdef FASTIO
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
ifstream ifs("./in_out/input.txt");
cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
ofstream ofs("./in_out/output.txt");
cout.rdbuf(ofs.rdbuf());
#endif
solve();
cout << flush;
return 0;
}
| 0
| 29,651,039
|
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;
template<class T>bool chmax(T &a, const T &b) { if (b > a) { 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; }
constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion
void solve(){
int N;
cin >> N;
vector<ll> A(N);
for (int i=0; i<N; i++) {
cin >> A.at(i);
}
ll sum = 0;
int right = 0;
ll ans = 0;
for (int left=0; left<N; left++) {
while (right < N && sum + A.at(right) == (sum ^ A.at(right))) {
sum += A.at(right);
right++;
}
ans += right - left;
if (left == right) {
right++;
} else {
sum -= A.at(left);
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(20);
solve();
return 0;
}
|
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
using ll=long long;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vll> vl2d;
typedef vector <vi> vi2d;
typedef vector <char> vc;
typedef vector <bool> vb;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <char,int> mci;
typedef map <int,int> mii;
typedef map <long,long> ml;
typedef map <string,string> mss;
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define foreach(x,arr) for(auto& x:arr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define endl '\n'
#define INF 1000000000LL
#define MOD 1000000007
#define deb(x) cout<<#x<<": "<<x<<endl;
#define printArray(arr) for(auto x: arr) { cout<<x<<"\n"; }
#define printMatrix(mat) for(auto x: mat) { cout<<" "; printArray(x); cout<<endl; }
#define printMap(mmap) for(auto p: mmap) { cout<< p.first<<": "<<p.second<<endl; }
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define forch(ch,str) for(char& c : str)
#define FILL(a,b) memset(a,b,sizeof(a))
#define append push_back
#define nil nullptr
#define guard(_condition) if (bool(_condition)){}
#define count size()
#define let const auto
#define var auto
#define startsWith(str) rfind(str, 0)
#define prq priority_queue
#define tostr(argument) to_string(argument)
#define alphabet "abcdefghijklmnopqrstuvwxyz"
void join(const vector<string>& v, char c, string& s) {
s.clear();
for (vector<string>::const_iterator p = v.begin();
p != v.end(); ++p) {
s += *p;
if (p != v.end() - 1)
s += c;
}
}
unordered_map<int, vector<int>> graph;
int n;
ll mod = 1e9 + 7;
pair<ll, ll> dfs(int v, int p) {
ll b = 1, w = 1;
foreach(n, graph[v]) {
guard(n != p) else {
continue;
}
let child = dfs(n, v);
w = ((child.first + child.second) * w)%mod;
b = (child.first * b)%mod;
}
return pair<ll,ll>(w, b);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin>>n;
rep(i,0,n-1) {
int s,d;
cin>>s>>d;
graph[s].push_back(d);
graph[d].push_back(s);
}
var res = dfs(1,0);
cout<<(res.first + res.second)%mod<<endl;
return 0;
}
| 0
| 98,264,120
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,ans=0,count=0;
cin>>N;
vector<int> H(N);
for(int i=0;i<N;i++)
cin>>H.at(i);
for(int i=0;i<N-1;i++){
if(H.at(i)>=H.at(i+1)){
count++;
}
else{
ans=max(ans,count);
count=0;
}
}
cout<<max(ans,count)<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int main() {
int N;
cin >> N;
vector<int> A(N);
rep(i, N) {
cin >> A[i];
}
ll ans = 0;
int mx = A[0];
for (int i=1; i<N; i++) {
if (A[i] < mx) {
ans += mx - A[i];
} else {
mx = A[i];
}
}
cout << ans << endl;
return 0;
}
| 0
| 29,185,134
|
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
int main(){
ll n ; cin >> n;
ll ans = 0;
for(int i=1;i<(int)(sqrt(n)+1);i++){
if(n%i != 0) continue;
ll m = (n/i) - 1;
if(1<=i && i<=m-1) ans+= m;
}
cout << ans << endl;
}
|
#include <iostream>
using namespace std;
int main(void){
int x,y;
for(;;){
cin>>x>>y;
if(x==0&&y==0){
break;
}
if(x>y){
swap(x,y);
}
cout<<x<<" "<<y<<endl;
}
}
| 0
| 38,448,031
|
#include <iostream>
#include <algorithm>
using namespace std;
int n, sum = 0, big = -1, i, x;
int main(){
cin >> x;
if (x < 1200){
cout << "ABC" << endl;
}
else
cout << "ARC" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int N; cin >> N;
string S; cin >> S;
vector<set<int>> x(10);
for(int i = 0; i < N; i++){
int d = S[i] - '0';
x[d].insert(i);
}
int ans = 0;
for(int a = 0; a <= 9; a++){
for(int b = 0; b <= 9; b++){
for(int c = 0; c <= 9; c++){
int pos = -1;
if(x[a].upper_bound(pos) == x[a].end())continue;
pos = *x[a].upper_bound(pos);
if(x[b].upper_bound(pos) == x[b].end())continue;
pos = *x[b].upper_bound(pos);
if(x[c].upper_bound(pos) == x[c].end())continue;
pos = *x[c].upper_bound(pos);
ans++;
}
}
}
cout << ans << endl;
}
| 0
| 85,083,786
|
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
ll mod=1e9+7;
int main(){
int n,k;
ll ans=0LL;
cin >>n>>k;
ll up=0LL;
ll down=0LL;
int a=0,b=n;
for(int i=1;i<=n+1;i++){
up+=a;
down+=b;
ans+=(down-up+1);
if(i<k){
ans=0LL;
}else{
ans %= mod;
}
a++;
b--;
}
cout<<ans<<endl;
}
|
#include <iostream>
int main() {
int a,b,c;
std::cin >> a >> b >> c;
if (a < b && b < c && a!=b && b!=c && c!=a) {
std::cout << "Yes" << std::endl;
}
else {
std::cout << "No" << std::endl;
}
}
| 0
| 85,314,156
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
bool yn=false;
for(int i=0;i<N/7+1;i++){
bool fin=false;
for(int j=0;j<N/4+1;j++){
if(4*j+7*i==N){
yn=true;
fin=true;
break;
}
}
if(fin==true)break;
}
if(yn==true)cout << "Yes"<<endl;
else cout<<"No"<<endl;
}
|
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
if(n == 1) return false;
if(n == 2 || n == 3) return true;
if(n%2 == 0 || n%3 == 0) return false;
for(int i=5; i*i<=n; i+=6){
if((n%i == 0)||(n%(i+2) == 0)) return false;
}
return true;
}
long long binpow(long long a, long long b) {
if (b == 0)
return 1;
long long res = binpow(a, b / 2);
if (b % 2)
return res * res * a;
else
return res * res;
}
int main()
{
fio;
int n;
cin>>n;
int p = n/15;
int k = 800*n;
cout<<k-(200*p)<<endl;
return 0;
}
| 0
| 46,539,604
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;
int main() {
ll N;
cin >> N ;
ll count_n = 0;
rep(i,N){
ll count = 1;
if(((i+1)%2) == 1){
rep(j,i){
if(((i+1)%(j+1)) == 0){
count += 1;
}
}
if(count == 8){
count_n += 1;
}
}
}
cout << count_n << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
lli h, n;
int main(void){
cin >> h >> n;
vector<lli> a(n), b(n);
rep(i, n) cin >> a[i] >> b[i];
lli ma = *max_element(a.begin(), a.end());
vector<lli> dp(h+ma+5, 1e9);
dp[0] = 0;
rep(i, h){
rep(j, n){
chmin(dp[i+a[j]], dp[i]+b[j]);
}
}
lli ans = 1e18;
for(int i = h; i <= h+ma; i++){
ans = min(ans, dp[i]);
}
cout << ans << endl;
return 0;
}
| 0
| 46,703,363
|
#include <iostream>
using namespace std;
int main() {
long long int n, res;
res = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
res *= i;
}
cout << res << endl;
return 0;
}
|
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <math.h>
using namespace std;
const long long MOD = 1000000007;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
int S;
cin >> S;
COMinit();
int n = 1;
long long ans = 0;
while(S - 3 * n >= 0){
ans += COM(S - 2 * n - 1, n - 1);
ans = ans % MOD;
n++;
}
cout << ans % MOD << endl;
}
| 0
| 47,790,219
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
ll n; cin >> n;
vector<ll> v;
ll tmp=n;
for(ll i=1; i*i<=tmp; i++){
if(tmp%i==0){
v.push_back(i);
if(i!=tmp/i) v.push_back(tmp/i);
}
}
ll res=LINF;
for(auto x: v){
string obj=to_string(n/x);
string tp = to_string(x);
res = min(res, max((ll)obj.size(), (ll)tp.size()));
}
cout << res << endl;
}
|
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main() {
while( 1 ) {
int n;
bool state = false;
bool lstate = false;
bool rstate = false;
int counter = 0;
cin >> n;
if( !n ) {
break;
}
for( int i = 0; i < n; i++ ) {
string s;
cin >> s;
if( s[ 0 ] == 'l' ) {
if( s[ 1 ] == 'u' ) {
lstate = true;
if( !state && rstate ) {
counter++;
state = true;
}
} else {
lstate = false;
if( state && !rstate ) {
counter++;
state = false;
}
}
} else {
if( s[ 1 ] == 'u' ) {
rstate = true;
if( !state && lstate ) {
counter++;
state = true;
}
} else {
rstate = false;
if( state && !lstate ) {
counter++;
state = false;
}
}
}
}
cout << counter << endl;
}
return EXIT_SUCCESS;
}
| 0
| 23,725,335
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR( i, m, n ) for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n ) FOR( i, 0, n )
#define REPR( i, m ) for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n ) FOR( i, 1, n + 1 )
#define ALL( a ) (a).begin(), (a).end()
#define MP make_pair
typedef pair<int, int> 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( a > b ) { a = b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9 + 7;
signed main(){
int N, a, b, c, x;
while( cin >> N >> a >> b >> c >> x, N | a | b | c | x ){
vector<int> ran( N );
REP( i, N ) cin >> ran[i];
int ans = -1;
int reel = 0;
REP( i, 10001 ){
if( x == ran[reel] ) reel++;
if( reel == N ){
ans = i;
break;
}
x = ( a * x + b ) % c;
}
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int64_t INF = 10000000000;
int main()
{
int64_t H, W, d1 = INF, d2 = INF, d3 = INF, d4 = INF;
cin >> H >> W;
if (W >= 3)
{
d1 = (W % 3 == 0) ? 0 : H;
if (d1 == 0)
{
cout << 0 << endl;
return 0;
}
}
if (H >= 3)
{
d2 = (H % 3 == 0) ? 0 : W;
if (d2 == 0)
{
cout << 0 << endl;
return 0;
}
}
int64_t s1, s2, s3, h, w;
for (int w = 1; w < W; w++)
{
s1 = w * H;
h = H / 2;
s2 = (W - w) * h;
s3 = (W - w) * (H - h);
d3 = min(d3, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
}
for (int h = 1; h < H; h++)
{
s1 = h * W;
w = W / 2;
s2 = (H - h) * w;
s3 = (W - w) * (H - h);
d4 = min(d4, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
}
cout << min(min(d1, d2), min(d3, d4)) << endl;
}
| 0
| 49,418,568
|
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
#define rot(s, k) rotate(s.begin(), s.begin()+ s.size()-(k%s.size()), s.end());
map<int, int> yes;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
vector<int> arr(n);
for(int i{}; i<n; i++){
int x; cin >> x;
arr[i] = x;
++yes[x];
}
ll tp = 0;
for(auto x : yes){
if(x.second)
tp += 1.0*x.second*(x.second-1)/2;
}
for(int i{}; i<n; i++){
ll p = 1.0*(yes[arr[i]])*(yes[arr[i]]-1)/2;
ll nw = 1.0*(yes[arr[i]]-1)*(yes[arr[i]]-2)/2;
cout << tp - p + nw << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)
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; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif
const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
int main() {
init();
string S;
cin >> S;
ll N = S.size();
vvc<ll> C(N + 1, vl(26));
repr(i, N) C[i] = C[i + 1], C[i][S[i] - 'a']++;
ll ans = 1;
rep(i, N) ans += accumulate(all(C[i]), 0ll) - C[i][S[i] - 'a'];
cout << ans << endl;
}
| 0
| 61,254,989
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int n, m, p;
while (cin >> n >> m >> p && n) {
int sum = 0;
int dl[n];
rep(i, n) {
cin >> dl[i];
sum += dl[i];
}
if (dl[m - 1] == 0) {
cout << 0 << endl;
} else {
cout << sum * (100 - p) / dl[m - 1] << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
int main()
{
int n, k;
while (cin >> n >> k)
{
if (n == 0 && k == 0)
{
break;
}
vector<int> s(n);
rep(i, n) cin >> s[i];
vector<ll> cum(n + 1, 0);
rep(i, n)
{
cum[i + 1] += cum[i] + s[i];
}
ll ans = 0;
rep(i, n + 1 - k)
{
ans = max(ans, cum[k + i] - cum[i]);
}
cout << ans << endl;
}
return 0;
}
| 0
| 14,992,091
|
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;
int main()
{
fast_io
ll i,a,x;
cin>>x>>a;
i=(x<a)?0:10;
cout<<i<<endl;
return 0;
}
|
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
using namespace std;
int main()
{
string S;
cin >> S;
for (int i = 0; i < S.length(); i++) {
if (i == 3) {
cout << S[i] << " ";
}
else {
cout << S[i];
}
}
cout << endl;
}
| 0
| 87,809,523
|
#include<iostream>
#include<algorithm>
#define f first
#define s second
using namespace std;
int main(){
int n,m;
pair<int,int>d[10000];
while(cin>>n>>m&&n!=0){
int an=0,k=0;
for(int i=0;i<n;i++)cin>>d[i].s>>d[i].f,k+=d[i].s;
sort(d,d+n);
for(int i=0;m<k;i++){
if(k-m<d[i].s)an+=d[i].f*(k-m);
else an+=d[i].f*d[i].s;
k-=d[i].s;
}
cout<<an<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define fast \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e3 + 77;
int32_t main()
{
fast;
int n;
cin >> n;
int ans = 0, a = 0, b = 0, c = 0;
for (int i = 0; i < n; ++i)
{
string s;
cin >> s;
int l = s.length();
for(int j = 0 ;j < l-1 ; ++j) if(s[j]=='A' && s[j+1]=='B') ans++;
if(s[0]=='B' && s[l-1]=='A') a++;
else if(s[0]=='B') b++;
else if(s[l-1]=='A') c++;
}
ans += min(b,c);
if(b+c>0) ans += a;
else ans += max(a-1,0ll);
cout << ans << endl;
return 0;
}
| 0
| 86,901,616
|
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define PI acos(-1)
int main(){
string s,t;
cin >> s >> t;
vector<vector<int>> alfs(26),alft(26);
for(int i = 0;i < (int)s.size();i++){
alfs[s[i] - 'a'].push_back(i);
alft[t[i] - 'a'].push_back(i);
}
for(int i = 0;i < (int)alfs.size();i++){
for(int j = 0;j < alfs[i].size();j++){
s[alfs[i][j]] = alfs[i].size();
}
for(int j = 0;j < alft[i].size();j++){
t[alft[i][j]] = alft[i].size();
}
}
cout << (s == t ? "Yes":"No") << endl;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
using namespace std;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; ll x; cin >> n >> x;
vector<ll> vec;
for(int i = 0; i < n; i++){
ll t; cin >> t; vec.pb(t);
}
vec.pb(x); sort(vec.begin(),vec.end());
vector<ll> vec2;
for(int i = 0; i < vec.size()-1; i++){
vec2.pb(vec[i+1]-vec[i]);
}
ll res = vec2[0];
for(int i = 1; i < vec2.size(); i++){
res = __gcd(res, vec2[i]);
}
cout << res << endl;
return 0;
}
| 0
| 33,238,370
|
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
double a, b, c;
double angle;
double sin1;
double cos1;
double s, l ,h;
cin>>a>>b>>angle;
angle = angle*M_PI/180.0;
sin1 = sin(angle);
cos1 = cos(angle);
s = 0.5 * a * b * sin1;
c = a*a + b*b -2.0*a*b*cos1;
c = sqrt(c);
l = a + b + c;
h = 2.0*s/a;
printf("%.16lf\n%.15lf\n%.15lf\n", s, l ,h);
}
|
#include<iostream>
using namespace std;
int main(){
int n, m, k, r;
cin>>n;
int a[n][n];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
a[i][j] = 0;
for(int i=0;i<n;i++){
cin>>r;
cin>>m;
for(int j=0;j<m;j++){
cin>>k;
a[r-1][k-1] = 1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<a[i][j];
if(j<n-1) cout<<" ";
else cout<<endl;
}
}
return 0;
}
| 0
| 73,532,717
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
int main(){
int a, b;
cin >> a >> b;
string s;
cin >> s;
string ans = "Yes";
rep(i, a+b+1) {
if (i==a) {
if (s[i]!='-') ans = "No";
}
else {
if (s[i]=='-') ans = "No";
}
}
cout << ans << endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;
int digit(ll x) {
int digits = 0;
while(x > 0){
x /= 10;
digits++;
}
return digits;
}
ll gcd(long long a,long long b) {
if (a < b) swap(a,b);
if (b == 0) return a;
return gcd(b,a%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;
}
ll lcm(ll a,ll b){
return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
double DegreeToRadian(double degree){
return degree * M_PI / 180.0;
}
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int main(){
long long n, m;
cin >> n >> m;
long long ans = 0;
if (n >= m){
ans = m / 2;
}
else {
ans += n;
m -= n*2;
ans += m / 4;
}
cout << ans << endl;
}
| 0
| 9,141,646
|
#include<iostream>
#include<string>
using namespace std;
int main() {
int a, c, d;
string b;
cin >> a;
cin >> b;
cin >> c;
if (b == "+") {
d = a + c;
cout << d;
}
else if (b == "-") {
d= a - c;
cout << d;
}
}
|
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int
int main(){
int n,k;
scanf("%d%d",&n,&k);
double win=0;
double num_prob=(double)(1)/n;
for(int i=1;i<=n;i++){
if(i>=k){
win+=(double)(1)/n;
}
else{
int t=i;
int cnt=0;
while(t<k){
t*=2;
cnt++;
}
double steps=pow(2,cnt);
double prob=(double)(1)/steps;
win=win+(num_prob)*(prob);
}
}
printf("%0.15f\n",win);
return 0;
}
| 0
| 91,886,385
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
double min = 0;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
min += a.at(i);
}
min = min / (4 * m);
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a.at(i) >= min) cnt++;
}
if (cnt >= m) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(void){
int a,b,c,d;
cin>>a>>b>>c>>d;
while(1){
if(d<0){
cout<<"No"<<endl;
break;
}
if(a>=b){
b*=2;
}else if(b>=c){
c*=2;
}else{
cout<<"Yes"<<endl;
break;
}
d--;
}
}
| 0
| 87,366,947
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int, int>;
int main() {
int N, K;
cin >> N >> K;
int cnt = 0;
rep(i, N)
{
int h;
cin >> h;
if (h >= K) cnt++;
}
cout << cnt << endl;
return 0;
}
|
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
const ll INF = 1LL << 50;
int main() {
cout << fixed << setprecision(15);
ll n;
cin >> n;
vll as(n), bs(n);
rep(i, n) cin >> as[i];
rep(i, n) cin >> bs[i];
ll fuso = 0, ans = 0;
vll mars;
rep(i, n) {
if (bs[i] > as[i])
{fuso += bs[i] - as[i];
ans++;
} else
mars.push_back(as[i] - bs[i]);
}
rSort(mars);
ll idx = 0;
while (idx < (ll)mars.size() && fuso > 0) {
fuso -= mars[idx];
idx++;
}
if (fuso <= 0)
cout << ans + idx << endl;
else
cout << -1 << endl;
return 0;
}
| 0
| 6,765,431
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string A, B;
int ans;
cin >> A >> B;
if(A.at(0) == B.at(2)) {
ans++;
}
if(A.at(1) == B.at(1)) {
ans++;
}
if(A.at(2) == B.at(0)) {
ans++;
}
if(ans == 3) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void){
long long int x,y;
cin>>x>>y;
const long long INF=1LL<<60;
long long int ans1=INF,ans2=INF,ans3=INF,ans4=INF;
long long int tmp_x=-1*x;
long long int tmp_y=-1*y;
if (y-x>=0) {
ans1=y-x;
}
if (y-tmp_x>=0) {
ans2=y-tmp_x+1;
}
if (tmp_y-x>=0) {
ans3=tmp_y-x+1;
}
if (tmp_y-tmp_x>=0) {
ans4=tmp_y-tmp_x+2;
}
cout<<min(ans1,min(ans2,min(ans3,ans4)))<<endl;
}
| 0
| 35,829,753
|
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;
void solve()
{
int n;
cin>>n;
double sum = 0.0;
loop(i,0,n)
{
int x;
cin>>x;
sum += (1.0/x);
}
sum = 1.0/sum;
cout<<fixed<<setprecision(10);
cout<<sum;
}
signed main()
{
solve();
return 0;
}
|
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1
struct Node{int parent, left, right;};
Node Tree[MAX];
int n, Depth[MAX];
void print(int index){
int i, child;
cout << "node " << index << ": ";
cout << "parent = " << Tree[index].parent << ", ";
cout << "depth = " << Depth[index] << ", ";
if(Tree[index].parent == NIL) cout << "root, ";
else if(Tree[index].left == NIL) cout << "leaf, ";
else cout << "internal node, ";
cout << "[";
for(i=0, child=Tree[index].left; child != NIL; i++, child = Tree[child].right){
if(i) cout << ", ";
cout << child;
}
cout << "]" << endl;
}
void setDepth(int index, int currentDepth){
Depth[index] = currentDepth;
if(Tree[index].right != NIL) setDepth(Tree[index].right, currentDepth);
if(Tree[index].left != NIL) setDepth(Tree[index].left, currentDepth+1);
}
int main(void){
int d, vertex, in, left, right;
cin >> n;
for(int i=0;i<n;i++) Tree[i].parent = Tree[i].left = Tree[i].right = NIL;
for(int i=0;i<n;i++){
cin >> vertex >> d;
for(int j=0;j<d;j++){
cin >> in;
if(j==0) Tree[vertex].left = in;
else Tree[left].right = in;
left = in;
Tree[in].parent = vertex;
}
}
for(int i=0;i<n;i++)
if(Tree[i].parent == NIL) right=i;
setDepth(right, 0);
for(int i=0;i<n;i++) print(i);
return 0;
}
| 0
| 28,807,067
|
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int row,col,dp[10005][10005];
char grid[10005][10005];
void addSelf(int &x,int y)
{
x += y;
if(x >= mod)
x -= mod;
}
void FuN()
{
for(int i=1 ; i<=row ; i++){
for(int j=1 ; j<=col ; j++){
if(grid[i][j] == '#')
continue;
if(i == 1 && j == 1)
dp[i][j] = 1;
else{
addSelf(dp[i][j] , dp[i-1][j]);
addSelf(dp[i][j] , dp[i][j-1]);
}
}
}
cout<<dp[row][col]<<endl;
}
int main()
{
cin>>row>>col;
for(int i=1 ; i<=row ; i++){
for(int j=1 ; j<=col ; j++)
cin>>grid[i][j];
}
FuN();
return 0;
}
|
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int N = 1e5 + 500;
int dp[N][2],n;
vector < int > v[N];
int f(int i,int x,int lst){
if(x == 0 && v[i].size() == 1 && i != 1) return 0;
if(v[i].size() == 1 && i != 1) return 1;
if(dp[i][x] != -1) return dp[i][x];
vector < int > v1,v0;
int s0 = 0,s1 = 0;
for(int j = 0;j<v[i].size();j++){
if(v[i][j] == lst) continue;
v0.push_back(f(v[i][j],0,i));
v1.push_back(f(v[i][j],1,i));
s0 += v0[v0.size() - 1];
s1 += v1[v1.size() - 1];
}
if(x == 1 && s0 != v0.size()) return dp[i][x] = 0;
if(x == 1) return dp[i][x] = 1;
int tk = 0;
for(int j = 0;j<v0.size();j++){
if(v1[j] + s0 - v0[j] == v0.size()) return dp[i][x] = 1;
}
return dp[i][x] = 0;
}
int main(){
memset(dp,-1,sizeof(dp));
scanf("%d",&n);
for(int i = 0;i<n-1;i++){
int a,b;
scanf("%d%d",&a,&b);
v[a].push_back(b);
v[b].push_back(a);
}
if(f(1,0,1)) printf("Second\n");
else printf("First\n");
}
| 0
| 91,085,515
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#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 SORT(s) sort((s).begin(),(s).end())
int main(){
ll R; cin >> R;
if(R<1200) cout << "ABC" << endl;
else if(1200<=R && R < 2800) cout << "ARC" << endl;
else cout << "AGC" << endl;
}
|
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
F0R(i, v.size()) {
cout << v[i] << ' ';
}
cout << newl;
}
#if 1
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N, K;
cin >> N >> K;
unordered_map<int, vector<int>> as;
i64 result = 0;
int jl = 0;
F0R(i, N) {
int a;
cin >> a;
a = (a - 1 + K) % K;
jl = (jl - a + K) % K;
a = (a + jl) % K;
as[a].push_back(i);
int n = lower_bound(rng(as[jl]), i - K + 2) - as[jl].begin();
result += as[jl].size() - n;
}
cout << result;
}
#endif
| 0
| 26,520,440
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;
int main(){
int n;
cin >> n;
string s;
cin >> s;
int r = 0;
int l = 0;
int cnt = 0;
for(int i = 0; i < n; i++){
if(s[i] == ')' && r == l) cnt++;
else if(s[i] == '(') l++;
else if(s[i] == ')') r++;
}
for(int i = 0; i < cnt; i++) s = "("+s;
int k = l-r;
for(int i = 0; i < k; i++) s = s+")";
cout << s << endl;
return 0;
}
|
#include <iostream>
#include <vector>
int main()
{
long long K;
std::cin >> K;
std::vector<long long> lunlun_seq;
lunlun_seq.reserve(K);
for (long long i = 1; i < 10; i++)
{
lunlun_seq.push_back(i);
}
long long index = 0;
while (lunlun_seq.size() < K)
{
long long prior = lunlun_seq[index];
long long first = prior - (prior / 10) * 10;
if (first != 0)
lunlun_seq.push_back(10 * prior + first - 1);
lunlun_seq.push_back(10 * prior + first);
if (first != 9)
lunlun_seq.push_back(10 * prior + first + 1);
index++;
}
std::cout << lunlun_seq[K - 1] << std::endl;
}
| 0
| 69,129,818
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
int main(){
int n;
while(cin>>n){
n<1200?cout<<"ABC"<<endl:cout<<"ARC"<<endl;
}
}
|
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<cmath>
#include<list>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;
const int maxn = 2000000 + 8;
const int maxv = 10000 + 8;
int n;
int a[maxn],c[maxn],b[maxn];
int main()
{
memset(a,0,sizeof a);
memset(b,0,sizeof b);
memset(c,0,sizeof c);
scanf("%d",&n);
for(int i = 0; i < n; ++i)
{
scanf("%d",&a[i]);
c[a[i]]++;
}
for(int i = 1; i < maxv; ++i) {
c[i] += c[i-1];
}
for(int i = n-1; i >= 0; --i)
{
b[c[a[i]]] = a[i];
c[a[i]]--;
}
for(int i = 1; i <= n; ++i){
printf("%s%d", i== 1 ? "":" ",b[i]);
}
printf("\n");
return 0;
}
| 0
| 95,721,850
|
#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() {
int x;
cin >> x;
if (x < 1200) {
cout << "ABC" << endl;
} else {
cout << "ARC" << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
ll modpow(ll a,ll n,ll mod){
ll res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
int main(){
ll N,K;
cin>>N>>K;
VL X(K+1);
ll mod=1e9+7;
rep(i,K) X[i+1]=modpow(K/(i+1),N,mod);
rep(i,K) rep(j,K/(K-i)-1) (X[K-i]+=mod-X[(K-i)*(j+2)])%=mod;
ll ans=0;
rep(i,K) (ans+=X[i+1]*(i+1)%mod)%=mod;
cout<<ans<<endl;
}
| 0
| 52,558,739
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define 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(){
ll n;cin >> n;
vl v(n);rep(i,n)cin >> v[i];
vl x(n);x=v;
sort(all(x));
ll ans=0;
rep(i,n){
ll d=lower_bound(all(x),v[i])-x.begin();
if(d%2!=i%2)ans++;
}
cout << ans/2 <<endl;
}
|
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
vector<vector<long long>> Factrization(long long X);
int main(){
long long N, ans;
std::cin >> N;
vector<vector<long long>> facts;
facts = Factrization(N);
ans = N - 1;
for(long long i = 0; i < facts.size(); i++){
if(facts[i][0] + facts[i][1] -2 < ans){
ans = facts[i][0] + facts[i][1] -2;
}
}
std::cout << ans;
}
vector<vector<long long>> Factrization(long long X){
vector<vector<long long>> factors = {};
long long n_loop, a, b;
n_loop = (long long)floor(sqrt((float)X));
for(long long i =1; i <= n_loop; i++){
if(X%i == 0){
a = i;
b = X/i;
factors.push_back({a, b});
}
}
return factors;
}
| 0
| 98,168,990
|
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
int main(){
ll N,K;
cin>>N>>K;
double a,cnt=1,sum=0;
for(int i=1;i<=N;i++){
a=i;
while(a<=K-1){
cnt/=2;
a*=2;
}
sum+=cnt/N;
cnt=1;
}
cout << std::fixed << std::setprecision(15) << sum<< endl;
}
|
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(a,b) (0<=(a)&&(a)<(b))
using namespace std;
int main(){
int N;
cin>>N;
REP(i,0,N){
int y,m,d;
int ans=0;
cin>>y>>m>>d;
while(y!=1000||m!=1||d!=1){
d++;
if(y%3){
if(d>20-(m+1)%2) d=1,m++;
if(m>=11) m=1,y++;
}else{
if(d>=21) d=1,m++;
if(m>=11) m=1,y++;
}
ans++;
}
p(ans);
}
return 0;
}
| 0
| 39,231,374
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 414514
set<int> G[MAX];
int indeg[MAX];
bool V[MAX];
vector<int> p;
void bfs(int s){
queue<int> q;
q.push(s);
V[s]=1;
while(!q.empty()){
int u=q.front();q.pop();
p.push_back(u);
for(int v:G[u]){
indeg[v]--;
if(indeg[v]==0&&!V[v]){
V[v]=1;
q.push(v);
}
}
}
}
void tsort(int n){
memset(V,0,sizeof(V));
memset(indeg,0,sizeof(indeg));
for(int u=0;u<n;u++)
for(int v:G[u])
indeg[v]++;
for(int u=0;u<n;u++)
if(indeg[u]==0&&!V[u]) bfs(u);
if((int)p.size()!=n){
cout<<-1<<endl;
return;
}
for(int i=0;i<n;i++)
cout<<p[i]<<endl;
}
signed main(){
int n,e;
cin>>n>>e;
for(int i=0;i<e;i++){
int s,t;
cin>>s>>t;
G[s].insert(t);
}
tsort(n);
return 0;
}
|
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int gcd(int A,int B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
ll n;
cin>>n;
cout<<(n*(n-1))/2;
}
| 0
| 47,523,484
|
#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 a,b,c;
cin >> a >> b >> c;
if(a == b && b == c) puts("Yes");
else puts("No");
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
if (b==0) return a;
else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
ll digit_sum(ll a){
ll ans=0;
while(a>0){
ans+=a%10;
a/=10;
}
return ans;
}
int main()
{
string s;
ll k,one_len=0;
cin>>s>>k;
ll tmp=0;
if(s[tmp]=='1')one_len++;
while(tmp<s.length()-1){
if(s[tmp]=='1'&&s[tmp+1]=='1'){
one_len++;
tmp++;
}else{
break;
}
}
if(one_len>=k){
cout<<1<<endl;
}else{
cout<<s[one_len]<<endl;
}
return 0;
}
| 0
| 78,275,650
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
ll A, B, K;
cin >> A >> B >> K;
if(A >= K){
cout << A - K << " " << B << endl;
}else if(A < K && K - A <= B){
cout << 0 << " " << B-K+A << endl;
}else if(A < K && K - A > B){
cout << "0 0" << endl;
}
}
|
#include <stdio.h>
#include <string.h>
int main() {
int a, b, hy;
scanf("%d %d", &a, &b);
int x = a + b + 1;
int y = a;
char n[x];
scanf("%s", &n);
int length = strlen(n);
for(int i = 0; i < x; i++) {
if(n[i] == '-') {
hy++;
}
}
if(length == x && n[y] == '-' && hy == 1) {
printf("Yes");
} else {
printf("No");
}
return 0;
}
| 0
| 37,079,046
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
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;
}
struct Edge {
ll to, cap, rev;
Edge(ll _to, ll _cap, ll _rev) {
to = _to; cap = _cap; rev = _rev;
}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
G[from].push_back(Edge(to, cap, (ll)G[to].size()));
if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}
void solve(){
ll x,y;
cin>>x>>y;
ll ans=INF;
if(x<=y) chmin(ans,y-x);
else chmin(ans,x-y+2);
if(x*y<=0){
chmin(ans,abs(abs(y)-abs(x))+1);
}
cout<<ans<<en;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
|
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main(){
int X,N,p[101];
cin>>X>>N;
if(N==0){
cout<<X<<endl;
return 0;
}
for(int i=0;i<N;i++) cin>>p[i];
int ans=X;
for(int i=1;i<=105;i++){
for(int j=0;j<N;j++){
if(ans==p[j]) break;
else if(j==N-1){
cout<<ans<<endl;
return 0;
}
}
if(i%2==0){
ans+=i;
}else{
ans-=i;
}
}
return 0;
}
| 0
| 59,827,904
|
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main()
{
int n, m;
cin >> n >> m;
int a[n];
int b[m];
for(int i = 0;i < n;i++)
cin >> a[i];
for(int i = 0;i < m;i++)
cin >> b[i];
long long x_sum = 0, y_sum = 0;
for(int i = 0;i < n - 1;i++){
x_sum += 1ll * (i + 1) * (n - i - 1) % MOD * (a[i + 1] - a[i]) % MOD;
if(x_sum >= MOD)
x_sum -= MOD;
}
for(int i = 0;i < m - 1;i++){
y_sum += 1ll * (i + 1) * (m - i - 1) % MOD * (b[i + 1] - b[i]) % MOD;
if(y_sum >= MOD)
y_sum -= MOD;
}
cout << x_sum * y_sum % MOD;
}
|
#include <bits/stdc++.h>
#define BPhuong "main"
#define maxn 100005
#define maxm
#define fi(i,a,b) for(int i = a; i<= b; i++)
#define fid(i,a,b) for(int i = a; i>= b; i--)
#define se second
#define f first
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define bit(x, i) ((x>>i)&1)
#define oo 1e9
struct data{
int x, y, z;
};
using namespace std;
int n, f[maxn], mod, k;
void add(int& a, int b)
{
a+=b;
if(a>=mod) a-=mod;
}
void release(int& a, int b)
{
a-=b;
if(a < 0) a+=mod;
}
void nhap(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);cout.tie(NULL);
cin >> n >> k;
mod = 1e9+7;
}
void xuli(){
f[0] = 1;
fi(i, 1, n)
{
int a;
vector <int> sum(k+1);
cin >> a;
fid(j, k, 0)
{
int cnt = f[j];
int l = j+1;
int r = j + min(k-j, a);
if(l<=r)
{
add(sum[l], cnt);
if(r+1 <= k) release(sum[r+1], cnt);
}
}
int pre = 0;
fi(j, 0, k)
{
add(pre, sum[j]);
add(f[j], pre);
}
}
cout << f[k];
}
int main(){
nhap();
xuli();
}
| 0
| 92,675,831
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n][3];
for(int i=0;i<n;i++)
{
for(int j=0;j<3;j++)
{
cin>>arr[i][j];
}
}
for(int i=1;i<n;i++)
{
for(int j=0;j<3;j++)
{
arr[i][j]=arr[i][j]+max(arr[(i-1)][(j+1)%3],arr[(i-1)][(j+2)%3]);
}
}
cout<<max(arr[n-1][0],max(arr[n-1][1],arr[n-1][2]));
}
|
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
const int kN = 500 + 5;
int n, m, d;
int a[kN][kN];
int main()
{
scanf("%d%d%d", &n, &m, &d);
int mod = d + d;
for (int i = 0; i < n; ++ i) {
for (int j = 0; j < m; ++ j) {
int x = (i + j) % mod;
int y = ((i - j) % mod + mod) % mod;
putchar("RGBY"[(x < d) * 2 + (y < d)]);
}
puts("");
}
}
| 0
| 10,200,305
|
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<
using namespace std;
template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }
template <class T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
#line 2 "tmp.cpp"
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vl a(n);
REP(i, n) { cin >> a[i]; }
ll ans = 0;
ll res = 0;
REP(i, n) {
if (a[i] == 0) {
res = 0;
continue;
}
ans += (a[i] + res) / 2;
res = (a[i] + res) % 2;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)
uint64_t gcd(uint64_t m, uint64_t n) {
uint64_t temp;
while (m % n != 0){
temp = n;
n = m % n;
m = temp;
}
return n;
}
uint64_t lcm(uint64_t m, uint64_t n) {
return (m*n)/gcd(m,n);
}
void comb(vector<vector <uint64_t> > &v){
for(uint64_t i = 0;i <v.size(); i++){
v[i][0]=1;
v[i][i]=1;
}
for(uint64_t k = 1;k <v.size();k++){
for(uint64_t j = 1;j<k;j++){
v[k][j]=(v[k-1][j-1]+v[k-1][j]);
}
}
}
bool is_product_overflow(uint64_t a, uint64_t b) {
uint64_t prod = a * b;
return (prod / b != a);
}
void primeFactorization(uint64_t a, list<uint64_t> &factors){
long i,sq;
if(a%2==0){
factors.push_back(2);
primeFactorization(a/2,factors);
return;
}
sq = sqrt(a);
for(i=3;i<=sq;i+=2){
if(a%i==0){
factors.push_back(i);
primeFactorization(a/i,factors);
return;
}
}
if(a!=1){
factors.push_back(a);
}
}
int64_t modinv(int64_t a, int64_t m) {
int64_t b = m, u = 1, v = 0;
while (b) {
int64_t t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int64_t getVal(int64_t d){
int64_t ans = 1;
for(int i=1;i<d;i++){
ans *= 10;
}
return ans;
}
signed main() {
uint64_t n;
cin >> n;
list<uint64_t> factors;
uint64_t minSteps = n*2;
for(uint64_t i=1;i<=sqrt(n);i++){
if(n%i==0){
minSteps = min(minSteps, i+n/i-2);
}
}
cout << minSteps << endl;
return 0;
}
| 0
| 86,104,221
|
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
signed main() {
int n , m;
cin >> n >> m;
vector<pair<ll, ll>> store(n);
rep(i, n){
ll price, cnt;
cin >> price >> cnt;
store[i] = make_pair(price, cnt);
}
sort(store.begin(), store.end());
ll now = 0;
ll now_money = 0;
for(ll i = 0; now < m; i++){
for(ll j = store[i].second; j > 0; j--){
if(now < m){
now++;
now_money += store[i].first;
}
}
}
cout << now_money << endl;
}
|
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int decode(string s){
string str = "ixcm";
int digit[] = {1,10,100,1000};
int res = 0;
rep(j,0,4){
rep(i, 0, s.size()){
if(s[i] == str[j]){
int t = 1 * digit[j];
if(i && s[i-1] >= '2' && s[i-1] <= '9'){
t *= s[i-1] - '0';
}
res += t;
}
}
}
return res;
}
string encode(int n){
string res;
string str = "mcxi";
string ss = to_string(n);
ss = string(4 - ss.size(), '0') + ss;
rep(i,0,ss.size()){
string sub;
if(ss[i] == '0')continue;
if(ss[i] != '1')sub.push_back(ss[i]);
sub.push_back(str[i]);
res += sub;
}
return res;
}
main(){
int N;
cin >> N;
rep(i,0,N){
string s,t;
cin >> s >> t;
int a = decode(s), b = decode(t);
cout << encode(a + b) << endl;
}
}
| 0
| 64,753,177
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define dl double long
const int INF=0x3fffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
ll gcd(ll a, ll b) { return (b > 0) ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a*b/gcd(a, b); }
using ipair = pair<ll, ll>;
int main()
{
ll N, K;
vector<ipair> v;
cin >> N >> K;
if((N-1)*(N-2)/2 < K){
cout << "-1" << "\n";
}
else{
REP(i, 1, N) v.push_back({i, N});
ll max = (N-1)*(N-2)/2-K;
ll ci=1, cj=2;
rep(i, max){
v.push_back({ci, cj});
++cj;
if(cj == N){
++ci;
cj = ci + 1;
}
}
cout << v.size() << "\n";
for(auto a: v){
cout << a.first << " " << a.second << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using bll = boost::multiprecision::cpp_int;
using bdouble = boost::multiprecision::cpp_dec_float_100;
#endif
#ifdef LOCAL_DEV
void debug_impl() { std::cerr << '\n'; }
template<typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head << (sizeof...(tail) ? "," : ""); debug_impl(tail...); }
#define debug(...) do { std::cerr << "(" << #__VA_ARGS__ << ") ="; debug_impl(__VA_ARGS__); } while (false)
#else
#define debug(...) do {} while (false)
#endif
#ifdef LOCAL_TEST
#define BOOST_STACKTRACE_USE_ADDR2LINE
#define BOOST_STACKTRACE_ADDR2LINE_LOCATION /usr/local/opt/binutils/bin/addr2line
#define _GNU_SOURCE
#include <boost/stacktrace.hpp>
namespace std {
template<typename T> class dvector : public std::vector<T> {
public:
dvector() : std::vector<T>() {}
explicit dvector(size_t n, const T& value = T()) : std::vector<T>(n, value) {}
dvector(const std::vector<T>& v) : std::vector<T>(v) {}
dvector(const std::initializer_list<T> il) : std::vector<T>(il) {}
dvector(const std::string::iterator first, const std::string::iterator last) : std::vector<T>(first, last) {}
dvector(const typename std::vector<T>::iterator first, const typename std::vector<T>::iterator last) : std::vector<T>(first, last) {}
dvector(const typename std::vector<T>::reverse_iterator first, const typename std::vector<T>::reverse_iterator last) : std::vector<T>(first, last) {}
dvector(const typename std::vector<T>::const_iterator first, const typename std::vector<T>::const_iterator last) : std::vector<T>(first, last) {}
dvector(const typename std::vector<T>::const_reverse_iterator first, const typename std::vector<T>::const_reverse_iterator last) : std::vector<T>(first, last) {}
T& operator[](size_t n) {
try { return this->at(n); } catch (const std::exception& e) {
std::cerr << boost::stacktrace::stacktrace() << '\n'; return this->at(n);
}
}
const T& operator[](size_t n) const {
try { return this->at(n); } catch (const std::exception& e) {
std::cerr << boost::stacktrace::stacktrace() << '\n'; return this->at(n);
}
}
};
}
class dbool {
private:
bool boolvalue;
public:
dbool() : boolvalue(false) {}
dbool(bool b) : boolvalue(b) {}
dbool(const dbool& b) : boolvalue(b.boolvalue) {}
operator bool&() { return boolvalue; }
operator const bool&() const { return boolvalue; }
};
template<typename T> std::ostream& operator<<(std::ostream& s, const std::dvector<T>& v) {
for (size_t i = 0; i < v.size(); ++i){ s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; }
template<typename T> std::ostream& operator<<(std::ostream& s, const std::dvector<std::dvector<T>>& vv) {
s << "\\\n"; for (size_t i = 0; i < vv.size(); ++i){ s << vv[i] << "\n"; } return s; }
template<typename T> std::ostream& operator<<(std::ostream& s, const std::set<T>& se) {
s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; }
template<typename T> std::ostream& operator<<(std::ostream& s, const std::multiset<T>& se) {
s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; }
template <typename T, size_t N> std::ostream& operator<<(std::ostream& s, const std::array<T, N>& a) {
s << "{ "; for (size_t i = 0; i < N; ++i){ s << a[i] << "\t"; } s << "}"; return s; }
template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::map<T1, T2>& m) {
s << "{\n"; for (auto itr = m.begin(); itr != m.end(); ++itr){ s << "\t" << (*itr).first << " : " << (*itr).second << "\n"; } s << "}"; return s; }
template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::pair<T1, T2>& p) {
return s << "(" << p.first << ", " << p.second << ")"; }
#define vector dvector
#define bool dbool
class SIGFPE_exception : std::exception {};
class SIGSEGV_exception : std::exception {};
void catch_SIGFPE(int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGFPE_exception(); }
void catch_SIGSEGV(int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGSEGV_exception(); }
signed convertedmain();
signed main() { signal(SIGFPE, catch_SIGFPE); signal(SIGSEGV, catch_SIGSEGV); return convertedmain(); }
#define main() convertedmain()
#endif
using ll = long long;
constexpr ll INF = (ll)1e18;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr ll dx[4] = {1LL, 0LL, -1LL, 0LL};
constexpr ll dy[4] = {0LL, 1LL, 0LL, -1LL};
constexpr ll dx8[8] = {1LL, 0LL, -1LL, 0LL, 1LL, 1LL, -1LL, -1LL};
constexpr ll dy8[8] = {0LL, 1LL, 0LL, -1LL, 1LL, -1LL, 1LL, -1LL};
#define rep(i, n) for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define rrep(i, n) for(ll i=(n)-1; i>=0; --i)
#define rrepeq(i, n) for(ll i=(n) ; i>=1; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
void p() { std::cout << '\n'; }
template<typename Head, typename... Tail> void p(Head head, Tail... tail) { std::cout << head << (sizeof...(tail) ? " " : ""); p(tail...); }
template<typename T> inline void pv(std::vector<T>& v) { for(ll i=0, N=v.size(); i<N; i++) std::cout << v[i] << " \n"[i==N-1]; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> inline bool chmax(T& a, T b) { return a < b && (a = b, true); }
template<typename T> inline bool chmin(T& a, T b) { return a > b && (a = b, true); }
template<typename T> inline void uniq(std::vector<T>& v) { v.erase(std::unique(v.begin(), v.end()), v.end()); }
constexpr ll N_MAX = 2*1e5;
constexpr ll P_MAX = 10000;
ll N, P;
string S;
void solve() {
scanf("%lld%lld", &N, &P);
cin>>S;
if(P==2||P==5){
ll ans=0;
rep(i,N){
if((S[i]-'0')%P==0){
ans+=(1+i);
}
}
p(ans);return;
}
ll ans=0;
map<ll,ll> m;
m[0]++;
ll t=0;
ll x=1;
rrep(i,N){
t+=x*(S[i]-'0');
t%=P;
ans+=m[t];
m[t]++;
x*=10;
x%=P;
}
printf("%lld\n", ans);
}
signed main() {
solve();
return 0;
}
| 0
| 20,454,767
|
#include "bits/stdc++.h"
using namespace std;
int main() {
int N;
string S, T;
cin >> N >> S >>T;
for (int n = 0;n<N;++n) {
cout << S[n] << T[n];
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using lli = long long int;
using ll = long long;
lli n, m, h, a, b;
std::vector<lli> vec;
std::vector<lli> viewpoints;
int main() {
std::cin >> n >> m;
vec.assign(n+1, 0);
viewpoints.assign(n+1, -1);
for (int i = 1; i <= n; i++) {
std::cin >> vec[i];
}
for (int i = 0; i < m; i++) {
std::cin >> a >> b;
if (vec[a] <= vec[b]) {
viewpoints[a] = 0;
}
if (vec[b] <= vec[a]) {
viewpoints[b] = 0;
}
}
lli ans = std::count(viewpoints.begin()+1, viewpoints.end(), -1);
std::cout << ans << std::endl;
}
| 0
| 21,178,750
|
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int a=0,b=0,x;
for(int i=0;i<8;i++){scanf("%d",&x); if(i<=3) a+=x; else b+=x;}
printf("%d\n",max(a,b));
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
#define DBG(a,b,c,d)
signed main(){
IO_STREAM;
ll A,B; cin>>A>>B;
ll ans;
ans=lcm(A,B);
cout<<ans<<endl;
return 0;
}
| 0
| 29,175,036
|
#include <bits/stdc++.h>
using namespace std;
#define pr(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(v) (v).begin(), (v).end()
#define int unsigned long long
#define sz(v) (int)(v).size()
#define mod 1000000007
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
const int N= 10000001;
int b[N];
void solve() {
int n; cin >> n;
int sm= 1;
for (int i = 2; i <= n; i++) {
for (int j = i; j <= n; j+= i) b[j]+= 1;
sm+= i* (b[i]+ 1);
}
cout << sm<< "\n";
}
int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
int T= 1;
while ( T-- ) {
solve();
}
return 0;
}
|
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int n;
int* a = new int[100005];
int* a_copy = new int[100005];
map<int, int> mp;
int cnt;
int ans;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
a_copy[i] = a[i];
}
sort(a_copy + 1, a_copy + n + 1);
for (int i = 1; i <= n; i++)mp[a_copy[i]] = i;
for (int i = 1; i <= n; i++)
{
if (mp[a[i]] % 2 != i % 2)
{
cnt++;
}
}
ans = cnt / 2;
cout << ans << endl;
return 0;
}
| 0
| 73,061,686
|
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
int n,x,t;
int ans;
scanf("%d%d%d",&n,&x,&t);
if(n%x==0)
ans = n/x*t;
else
ans = n/x*t + t;
printf("%d\n",ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
int main() {
ll ans = 0;
int tmp;
ll ju = pow(10, 9);
ll x, y, s;
cin >> s;
y = (s + ju - 1)/ju;
x = ju * y - s;
cout << "0 0 " << y << " 1 " << x << " " << ju << endl;
}
| 0
| 95,765,096
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i< (n); ++i)
const long long INF = 1LL<<58;
template<class T> bool chmin(T &a, T b){
if(a>b) {
a = b;
return true;
}
return false;
}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }
template<class T> int former(const vector<T> &v, T x){
return upper_bound(v.begin(), v.end(), x) - v.begin() -1;
}
template<class T> int latter(const vector<T> &v, T x){
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
using Data = pair<ll, vector<int>>;
int main() {
ll X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> A(X), B(Y), C(Z);
rep(i,X) cin >> A[i];
rep(i,Y) cin >> B[i];
rep(i,Z) cin >> C[i];
sort(A.begin(),A.end(), greater<ll>());
sort(B.begin(),B.end(), greater<ll>());
sort(C.begin(),C.end(), greater<ll>());
priority_queue<Data> que;
set<Data> se;
Data insert;
insert = make_pair(A[0] + B[0] + C[0], vector<int>({0, 0, 0}));
que.push(insert);
rep(i,K){
auto c = que.top();que.pop();
cout << c.first << endl;
if (c.second[0] + 1 < X) {
ll sum = c.first - A[c.second[0]] + A[c.second[0] + 1];
auto num = c.second;
num[0]++;
auto d = Data(sum, num);
if (!se.count(d)) se.insert(d), que.push(d);
}
if (c.second[1] + 1 < Y) {
ll sum = c.first - B[c.second[1]] + B[c.second[1] + 1];
auto num = c.second;
num[1]++;
auto d = Data(sum, num);
if (!se.count(d)) se.insert(d), que.push(d);
}
if (c.second[2] + 1 < Z) {
ll sum = c.first - C[c.second[2]] + C[c.second[2] + 1];
auto num = c.second;
num[2]++;
auto d = Data(sum, num);
if (!se.count(d)) se.insert(d), que.push(d);
}
}
}
|
#include<iostream>
using namespace std;
int main(){
bool tf=true;
int tedad[3]={1,1,1};
char str[4];
cin>>str;
for(int i=0;i<3;i++){
if(str[i]=='a'){
if(tedad[0]==1){
tedad[0]=0;
}
else{
tf=false;
break;
}
}
if(str[i]=='b'){
if(tedad[1]==1){
tedad[1]=0;
}
else{
tf=false;
break;
}
}
if(str[i]=='c'){
if(tedad[2]==1){
tedad[2]=0;
}
else{
tf=false;
break;
}
}
}
if(tf==false){
cout<<"No";
}
else{
cout<<"Yes";
}
}
| 0
| 4,469,723
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
#define int long long
signed main(){
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
int money = 1000;
rep(i,n - 1){
if(a[i] < a[i+1]){
int stock = money / a[i];
money += (a[i+1] - a[i]) * stock;
}
}
cout << money << endl;
}
|
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;
int main(void) {
ll q, h, s, d, n, s1, s2, s3, ans;
scanf("%lld%lld%lld%lld%lld", &q, &h, &s, &d, &n);
s1 = min(q * 2, h);
s2 = min(s1 * 2, s);
s3 = min(s2 * 2, d);
ans = n / 2 * s3 + n % 2 * s2;
printf("%lld\n", ans);
return 0;
}
| 0
| 17,992,338
|
#include<iostream>
#include<vector>
#define INF (1<<29)
using namespace std;
int main(void){
int n,m;
cin >> n >> m;
vector<int>d(m),dp(n+1,INF);
for(int i=0;i<m;i++)cin >> d[i];
dp[0]=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if(j+d[i]<=n)dp[j+d[i]]=min(dp[j+d[i]],dp[j]+1);
cout << dp[n] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn = 303;
const ll Inf = 1000000000000000000ll;
int n, k;
int H[Maxn];
ll dp[Maxn][Maxn][Maxn];
int main()
{
fill((ll*)dp, (ll*)dp + Maxn * Maxn * Maxn, Inf);
dp[1][0][0] = 0;
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &H[i]);
for (int j = 0; j < i; j++)
for (int u = 0; u <= k; u++) if (dp[i][j][u] < Inf) {
if (u < k) dp[i + 1][j][u + 1] = min(dp[i + 1][j][u + 1], dp[i][j][u]);
ll add = max(0, H[i] - H[j]);
dp[i + 1][i][u] = min(dp[i + 1][i][u], dp[i][j][u] + add);
}
}
ll res = Inf;
for (int j = 0; j <= n; j++)
for (int u = 0; u <= k; u++)
res = min(res, dp[n + 1][j][u]);
printf("%lld\n", res);
return 0;
}
| 0
| 24,385,198
|
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
void swap(int &x, int &y){
int tmp = x;
x = y;
y = tmp;
return;
}
struct UnionFind{
vi par;
UnionFind(int n){
par = vi(n, -1);
}
int root(int x){
if(par[x] < 0) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y){
x = root(x);
y = root(y);
if(x == y) return;
if(par[x] > par[y]) swap(x, y);
par[x] += par[y];
par[y] = x;
return;
}
int size(int x){
return -par[root(x)];
}
};
int main(void){
int n, m;
cin >> n >> m;
UnionFind UF(n);
for(int i=0; i<m; i++){
int a, b;
cin >> a >> b;
a -= 1; b -= 1;
UF.unite(a, b);
}
int v = 0;
for(int i=0; i<n; i++){
if(v < UF.size(i)) v = UF.size(i);
}
cout << v << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010, inf = 1e9 + 233;
int n;
int p[maxn], a[maxn], b[maxn], deltaa[maxn], deltab[maxn];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &p[i]);
for (int i = 1; i <= n; i++)
a[i] = i, b[i] = n - i + 1;
for (int i = 1; i <= n; i++)
deltaa[p[i] + 1] += 20000 - i, deltab[p[i] - 1] += 20000 - i;
for (int i = 1; i <= n; i++)
deltaa[i] += deltaa[i - 1], a[i] += deltaa[i];
for (int i = n; i; i--)
deltab[i] += deltab[i + 1], b[i] += deltab[i];
for (int i = 1; i <= n; i++)
printf("%d ", a[i]);
puts("");
for (int i = 1; i <= n; i++)
printf("%d ", b[i]);
puts("");
}
| 0
| 70,630,101
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T> void cmin(T &x, const T &y)
{
if(y < x) x = y;
}
template <typename T> void cmax(T &x, const T &y)
{
if(y > x) x = y;
}
template <typename T> void read(T &x)
{
x = 0; char c = getchar(); bool f = 0;
while(!isdigit(c) && c!='-') c = getchar();
if(c == '-') f = 1, c = getchar();
while(isdigit(c)) x = x*10+c-'0', c = getchar();
if(f) x = -x;
}
int n, fa[100005], dep[100005];
map<ll, pair<int, int> > st;
vector<pair<int, int> > edge;
vector<int> seq;
int main()
{
read(n);
for(int i=1; i<=n; i++)
{
ll d;
read(d);
st.insert(make_pair(d, make_pair(1, i)));
}
for(int i=1; i<n; i++)
{
auto x = *st.rbegin();
seq.push_back(x.second.second);
st.erase(--st.end());
ll y = x.first-(n-x.second.first)+x.second.first;
auto it = st.find(y);
if(it == st.end()) {printf("-1\n"); return 0;}
else
{
it->second.first += x.second.first;
fa[x.second.second] = it->second.second;
edge.emplace_back(x.second.second, it->second.second);
}
}
ll sum = 0;
for(int i=seq.size()-1; i>=0; i--) dep[seq[i]] = dep[fa[seq[i]]]+1, sum += dep[seq[i]];
if(sum != st.begin()->first) puts("-1");
else for(auto i : edge) printf("%d %d\n", i.first, i.second);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double a,b,c,d,oc,od;
double answer,number1,number2;
cin>>a>>b>>c>>d;
if (a<c) {
oc=c;
c=a;
a=oc;
}
if (b<d) {
od=d;
d=b;
b=od;
}
number1=double (fabs(d-b));
number2=double (fabs(c-a));
answer=double (sqrt(number1*number1+number2*number2));
printf("%lf\n",answer);
return 0;
}
| 0
| 90,931,007
|
#include <iostream>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
int main(void){
int N;
cin >> N;
vector<int> A(1 << N);
for(int i = 0; i < (1 << N); ++i) cin >> A[i];
int res = 0;
for(int K = 1; K < (1 << N); ++K){
int firstmax = max(A[K], A[0]), secondmax = min(A[K], A[0]);
int subset = (K - 1) & K;
while(subset){
int hoge = A[subset];
if(hoge > firstmax) swap(hoge, firstmax);
if(hoge > secondmax) swap(hoge, secondmax);
subset = (subset - 1) & K;
}
chmax(res, firstmax + secondmax);
cout << res << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, M;
cin >> N >> M;
vector<set<int>> V(M);
REP(i, M) {
int k;
cin >> k;
REP(j, k) {
int t;
cin >> t;
V[i].insert(t - 1);
}
}
vector<bool> P(M);
REP(i, M) {
int t;
cin >> t;
P[i] = (t == 1);
}
int ans = 0;
REP(i, 1UL << N) {
vector<int> cnt(M);
REP(j, N) {
if (i & (1UL << j)) {
REP(k, M) {
if (V[k].count(j) > 0) {
cnt[k]++;
}
}
}
}
bool flag = true;
REP(k, M) {
if (cnt[k] % 2 != P[k]) {
flag = false;
break;
}
}
if (flag) {
ans++;
}
}
cout << ans << endl;
return 0;
}
| 0
| 82,059,875
|
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
int H,W;
char s[103][103];
int mind[103][103];
scan(H>>W);
fill(mind[0],mind[103],INF);
rep(i,H){
scan(s[i]);
}
if(s[0][0]=='.') mind[0][0]=0;
else mind[0][0]=1;
rep(k,H+W-2){
rep(j,W){
int i=k-j;
if(0<=j&&j<W&&0<=i&&i<H){
if(i<H-1){
if(s[i][j]=='.'&&s[i+1][j]=='#') mind[i+1][j]=min(mind[i+1][j],mind[i][j]+1);
else mind[i+1][j]=min(mind[i+1][j],mind[i][j]);
}
if(j<W-1){
if(s[i][j]=='.'&&s[i][j+1]=='#') mind[i][j+1]=min(mind[i][j+1],mind[i][j]+1);
else mind[i][j+1]=min(mind[i][j+1],mind[i][j]);
}
}
}
}
prin(mind[H-1][W-1]);
return 0;
}
|
#include<cstdio>
int main(int argc, char const *argv[])
{
int H, W;
while(1){
scanf("%d %d", &H, &W);
if(H==0 && W==0) break;
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
printf("#");
}
printf("\n");
}
printf("\n");
}
return 0;
}
| 0
| 25,714,796
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i,N) for(int i=0;i<(int)N;++i)
ll GCD(ll x, ll y) {
if (y == 0) return x;
else return GCD(y, x % y);
}
int main()
{
int X, A, B;
cin >> X >> A >> B;
if (B - A <= 0) { cout << "delicious" << endl; }
else {
if (B - A <= X) { cout << "safe" << endl; }
else { cout << "dangerous" << endl; }
}
}
|
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using i64 = int64_t;
i64 n, k, dp[302][302];
vector<i64> h;
int main() {
cin >> n >> k;
h.resize(n + 2);
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
for (int i = 1; i <= n + 1; ++i) {
for (int j = 0; j <= k; ++j) {
dp[i][j] = 1e18;
}
}
for (i64 i = 1; i <= n + 1; ++i) {
for (i64 j = 0; j <= k && i - j - 1 >= 0; ++j) {
for (i64 l = 0; j + l <= k; ++l) {
dp[i][j + l] = min(
dp[i][j + l],
dp[i - j - 1][l] + max(i64(0), h[i] - h[i - j - 1])
);
}
}
}
i64 ans = 1e18;
for (i64 j = 0; j <= k; ++j) ans = min(ans, dp[n + 1][j]);
cout << ans << endl;
return 0;
}
| 0
| 76,951,991
|
#include<cstdio>
int main(){
int a,b;
while(1){
scanf("%d %d",&a,&b);
if((a == 0)&&(b == 0)) break;
if(a<b){
printf("%d %d\n",a,b);
}else{
printf("%d %d\n",b,a);
}
}
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
const int max_n= 10000;
int n,W,L,kk,m,V,e,r,ML, MD, E, v, H;
const int INF = 1e9+1;
const int mod = 1e9 + 7;
bool used[max_n][max_n];
string s1,s2;
int x[max_n],y[max_n],table[max_n][max_n],d[max_n][max_n],ppar[max_n],rrank[max_n],spf[max_n],a[max_n],b[max_n],c[max_n];
typedef pair<long , long> pii;
vector<long long> G[max_n];
vector<int> ls;
vector<pair<int, int> > edgee[max_n];
struct edge{
int from,to,cost;
};
bool comp(const edge& e1, const edge& e2){
return e1.cost < e2.cost;
}
edge es[max_n];
typedef pair<int, int> P;
struct Cmp{
bool operator()(const pii &a,const pii &b){
return a.second > b.second;
}
};
void warshall_floyd(){
for(int k=0 ; k<n ; k++){
for(int i=0 ; i<n ; i++){
for(int j=0 ; j<n ; j++){
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
void solve(){
warshall_floyd();
long long count = 0;
for(int i=0 ; i<m ; i++){
if(c[i] > d[a[i]][b[i]]) count++;
}
cout << count << endl;
}
int main(){
cin >> n >> m;
for(int i=0 ; i<n ; i++){
for(int j=0 ; j<n ; j++){
d[i][j] = INF;
if(i == j) d[i][j] = 0;
}
}
for(int i=0 ; i<m ; i++){
cin >> a[i] >> b[i] >> c[i];
--a[i]; --b[i];
d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
}
solve();
return 0;
}
| 0
| 87,318,793
|
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
cout << i << 'x' << j << '=' << i * j << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
int main() {
int x,y; cin >>x >>y;
cout <<(x % y == 0 ? -1 : x) <<endl;
}
| 0
| 62,449,995
|
#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; }
string A, B;
vector<vector<int>> dp(1010, vector<int>(1010, 10000));
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> A >> B;
for (int i = 0; i < A.size(); i++) {
dp[i][0] = i;
}
for (int i = 0; i < B.size(); i++) {
dp[0][i] = i;
}
for (int i = 0; i < A.size(); i++) {
for (int j = 0; j < B.size(); j++) {
if (A[i] == B[j]) {
dp[i + 1][j + 1] = dp[i][j];
}
chmin(dp[i + 1][j + 1],dp[i][j + 1] + 1);
chmin(dp[i + 1][j + 1], dp[i + 1][j] + 1);
chmin(dp[i + 1][j + 1], dp[i][j] + 1);
}
}
cout << dp[A.size()][B.size()] << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,ans=0;
cin>>n;
for(int i=0;i<9;i++){
ans+=111;
if(ans>=n){
cout<<ans<<endl;
break;
}
}
return(0);
}
| 0
| 21,384,983
|
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=300010;
const int inf=2147483647;
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<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
LL n,a,b;
int main()
{
n=read(),a=read(),b=read();
if(a+b>n+1)return puts("-1"),0;
if((b-1)*a<n-a)return puts("-1"),0;
if(b==1)
{
if(a!=n)return puts("-1"),0;
for(int i=1;i<=n;i++)printf("%d ",i);
return 0;
}
int t=(n-a)/(b-1),r=(n-a)%(b-1),cur=n-a;
for(int i=1;i<=a;i++)printf("%d ",n-a+i);
for(int j=1;j<b;j++)
{
int len=((j<=r)?(t+1):t);
for(int k=1;k<=len;k++)printf("%d ",cur-len+k);
cur-=len;
}
}
|
#include<bits/stdc++.h>
using namespace std;
void test()
{
int n;
cin>>n;
for(int x=1;true;x++)
{
if(x*n%360==0)
{
cout<<x;
return ;
}
}
}
int main()
{
ios::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
test();
return 0;
}
| 0
| 53,585,429
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout.setf(ios::fixed); cout.precision(20);
#endif
int n, m;
cin >> n >> m;
vector <int> p(n), q(m);
vector <ii> v;
for (int i = 0; i < n; ++i) {
cin >> p[i];
v.app(mp(p[i], 0));
}
for (int i = 0; i < m; ++i) {
cin >> q[i];
v.app(mp(q[i], 1));
}
sort(all(v));
vector <int> cnt(2);
int ans = 0;
for (auto e : v) {
if (e.s == 0) {
ans += e.f * (m + 1 - cnt[1]);
}
else {
ans += e.f * (n + 1 - cnt[0]);
}
cnt[e.s]++;
}
cout << ans << endl;
}
|
#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 LL long long
const int MAXSSTN = 200010;
class StarrySkyTree{
public:
int size=0;
int depth=0;
int best=0;
int start=0;
long long dat_add[4 * MAXSSTN];
long long dat[4 * MAXSSTN];
StarrySkyTree(int n){
size=n;
while((1<<depth)<n)depth++;
start=(1<<depth)-1;
for(int i=start;i<(1<<(depth+1));i++){
if(i<start+n)
dat[i]=0;
else
dat[i]=1e15;
}
for(int i=start;i<start+n;i++){
int tmp=i;
while(par(tmp)!=-1){
dat[par(tmp)]=min(dat[tmp],dat[(tmp+1)/2*4-1-tmp]);
tmp=par(tmp);
}
}
int i=0;
while(i<start)i=(dat[i]==dat[2*i+1])?2*i+1:2*i+2;
best=i-start;
}
long long max_element(int a, int b){ return max_element(a, b, 0, 0, (1<<depth)); }
void add(int s, int t, int x){ add(s, t, 0, 0, (1<<depth), x); }
void add(int i, int x){ add(i, i + 1, 0, 0, (1<<depth), x); }
int par(int i){
if(i==0)
return -1;
return (i-1)/2;
}
void clear() {
for(int i=start;i<(1<<(depth+1));i++){
if(i<start+size)
dat[i]=0;
else
dat[i]=1e15;
}
for(int i=start;i<start+size;i++){
int tmp=i;
while(par(tmp)!=-1){
dat[par(tmp)]=min(dat[tmp],dat[(tmp+1)/2*4-1-tmp]);
tmp=par(tmp);
}
}
int i=0;
while(i<start)i=(dat[i]==dat[2*i+1])?2*i+1:2*i+2;
best=i-start;
REP(i,4*MAXSSTN)dat_add[i]=0;
}
void update(int d,long long x){
int i=d+start;
dat[i]=x;
while(par(i)!=-1){
dat[par(i)]=min(dat[i],dat[(i+1)/2*4-1-i]);
i=par(i);
}
i=0;
while(i<start){
i=(dat[i]==dat[2*i+1])?2*i+1:2*i+2;
}
best=i-start;
}
void dump(){
for(int i=0;i<(1<<(depth+1));i++){
cerr<<dat[i]<<" ";
}
cerr<<endl;
}
private:
long long max_element(int a, int b, int k, int l, int r){
if(b <= l || r <= a) return 1e15;
if(a <= l && r <= b) return dat[k] + dat_add[k];
long long vl = max_element(a, b, k * 2+1, l, (l + r) / 2);
long long vr = max_element(a, b, k * 2+2, (l + r) / 2, r);
return min(vl, vr) + dat_add[k];
}
void add(int a, int b, int k, int l, int r, long long x){
if(b <= l || r <= a) return;
if(a <= l && r <= b){
dat_add[k] += x;
}else{
add(a, b, k * 2+1, l, (l + r) / 2, x);
add(a, b, k * 2+2, (l + r) / 2, r, x);
dat[k] = min(dat[k * 2+1] + dat_add[k * 2+1], dat[k * 2 + 2] + dat_add[k * 2 + 2]);
}
}
};
int n,k;
int a[200000];
int main(){
cin>>n>>k;
REP(i,n)cin>>a[i];
if(k >= 41){
REP(i,n)cout<<n<<" ";
cout<<endl;
return 0;
}
StarrySkyTree sst(n);
REP(i,k){
REP(j,n)sst.update(j,0);
REP(j,n){
sst.add(max(0,j-a[j]),min(n-1,j+a[j])+1,1);
}
REP(j,n){
if(a[j]!=n || !i)
a[j]=sst.max_element(j,j+1);
}
sst.clear();
}
REP(i,n)cout<<a[i]<<" ";
cout<<endl;
return 0;
}
| 0
| 47,626,054
|
#include<iostream>
using namespace std;
int main(void)
{
unsigned int n;
cin>>n;
unsigned long long int ans=n;
while(n>1){
ans*=--n;
}
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#include "atcoder/dsu"
typedef long long int ll;
using namespace std;
using namespace atcoder;
int main() {
int n, q;
cin >> n >> q;
vector<int> ans;
dsu d(n);
for (int i = 1; i <= q; i++) {
int t, u, v;
cin >> t >> u >> v;
if (t == 0) {
d.merge(u, v);
}
else {
if (d.same(u, v)) {
ans.push_back(1);
}
else {
ans.push_back(0);
}
}
}
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
return 0;
}
| 0
| 6,706,974
|
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
cin >> n >> m;
int l1 = 1;
int r1 = m+1;
int l2 = m+2;
int r2 = 2*m+1;
for(int i=0;i<m;i++)
{
if(l1 < r1)
{
cout << l1 << ' ' << r1 << '\n';
l1++;
r1--;
}
else if(l2 < r2)
{
cout << l2 << ' ' << r2 << '\n';
l2++;
r2--;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MAX 100002
#define NIL -1
int n, D[MAX];
struct node{
int p, l, r;
};
node T[MAX];
void printTree(){
for(int i=0;i<n;++i){
printf("node %d: parent = %d, depth = %d, ",i,T[i].p,D[i]);
if(T[i].p == NIL) printf("root, [");
else{
if(T[i].l == NIL) printf("leaf, [");
else printf("internal node, [");
}
for(int j=T[i].l;j != NIL;){
printf("%d",j);
j = T[j].r;
if(j != NIL){
printf(", ");
}
else break;
}
printf("]\n");
}
}
void recDepth(int pos, int depth){
D[pos] = depth;
if(T[pos].l != NIL){
recDepth(T[pos].l,depth+1);
}
if(T[pos].r != NIL){
recDepth(T[pos].r,depth);
}
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;++i){
T[i].l = T[i].p = T[i].r = NIL;
D[i] = 0;
}
int id, num_child, child_id, sib, root;
for(int i=0;i<n;++i){
cin >> id >> num_child;
for(int j=0;j<num_child;++j){
cin >> child_id;
if(j==0) T[id].l = child_id;
else T[sib].r = child_id;
sib = child_id;
T[child_id].p = id;
}
}
for(int i=0;i<n;++i){
if(T[i].p==NIL) root=i;
}
recDepth(root,0);
printTree();
return 0;
}
| 0
| 29,839,257
|
#include <iostream>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int N, M;
int S[11][11] = {0};
int C[11] = {0};
std::cin >> N >> M;
for (int i = 0; i < M; i++) {
std::cin >> C[i];
for (int j = 0; j < C[i]; j++) {
int s;
std::cin >> s;
S[i][j] = (s - 1);
}
}
int P[11];
for (int i = 0; i < M; i++) {
std::cin >> P[i];
}
int ans = 0;
for (int bit = 0; bit < (1 << N); bit++) {
int on_count = 0;
for (int i = 0; i < M; i++) {
int c = C[i];
int on = 0;
for (int j = 0; j < c; j++) {
if (bit & (1 << S[i][j])) {
on++;
}
}
if (on % 2 == P[i]) {
on_count++;
}
}
if (on_count == M) {
ans++;
}
}
std::cout << ans << std::endl;
return 0;
}
|
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define ll long long
ll calc(int n, std::vector<ll> cnt){
ll ans=0;
for(int i=2; i<cnt.size(); ++i){
if(cnt[i] >= n-1) ++ans;
}
return ans;
}
int main(){
int n; std::cin >> n;
std::vector<ll> cnt(n+1,0);
for(int i=2; i<n+1; ++i){
int cur=i;
for(int j=2; j<i+1; ++j){
while(cur % j == 0){
++cnt[j];
cur /= j;
}
}
}
ll ans=0;
ans += calc(75,cnt);
ans += calc(25,cnt) * (calc(3,cnt)-1);
ans += calc(15,cnt) * (calc(5,cnt)-1);
ans += calc(5,cnt) * (calc(5,cnt)-1) * (calc(3,cnt)-2) / 2;
std::cout << ans << std::endl;
return 0;
}
| 0
| 14,726,982
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const ll mod = 1000000007;
ll modpow(ll a, ll n)
{
ll res=1;
while (n>0) {
if (n&1) res = res*a % mod;
a = a*a % mod;
n >>= 1;
}
return res;
}
int main()
{
ll N, K; cin >> N >> K;
vector<ll> d(K+1);
for (int i=K; i>=1; i--) {
ll tmp = modpow(K/i, N);
for (int j=2; j*i<=K; j++) {
tmp = (tmp + mod - d[j*i]) % mod;
}
d[i] = tmp;
}
ll ans = 0;
for (int i=1; i<=K; i++) {
ans = (ans + i*d[i]) % mod;
}
cout << ans << endl;
return 0;
}
|
#include<iostream>
using namespace std;
int main(){
int A, B,N;
int sum,ans = 0;;
int cur =10;
cin >> N >> A >> B;
for(int i = 1;i <= N;i++){
sum = 0;
cur = i;
while(cur > 0){
sum += cur%10;
cur /= 10;
}
if( A <= sum && sum <= B)
ans += i;
}
cout << ans << endl;
return 0;
}
| 0
| 36,652,030
|
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
int main() {
int n;
cin >> n;
ll a[n];
vector<pair<ll,int>> v;
rep(i,n){
cin >> a[i];
pair<ll,int> p;
p.first = a[i];
p.second = i;
v.push_back(p);
}
sort(v.begin(), v.end(), greater<pair<ll,int>>());
ll ans[n] = {};
ll ite = 0;
int head = 1001001001;
ll ma = -1;
while(true){
if(ite==0){
head = v[ite].second;
ma = v[ite].first;
ite++;
while(ite<n){
if(v[ite].first==ma){
head = min(head,v[ite].second);
ite++;
}else{
break;
}
}
}else{
ma = v[ite].first;
head = min(head,v[ite].second);
ite++;
while(ite<n){
if(v[ite].first==ma){
head = min(head,v[ite].second);
ite++;
}else{
break;
}
}
}
if(ite==n){
ans[head] += n * ma;
}else{
ans[head] += (ma-v[ite].first) * ite;
}
if(ite==n)break;
}
rep(i,n){
cout << ans[i] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x) \
cout << x << "\n"; \
return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(i, v.size()) cerr << " " << v[i]; \
cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
return to_string(x).size();
}
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
vector<P> factorize(ll n) {
vector<P> result;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
result.pb({i, 0});
while (n % i == 0) {
n /= i;
result.back().second++;
}
}
}
if (n != 1) {
result.pb({n, 1});
}
return result;
}
vll divisor(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) ret.push_back(n / i);
}
}
SORT(ret);
return (ret);
}
signed main() {
init();
ll N, K;
cin >> N >> K;
vll A(N);
rep(i, N) cin >> A[i];
SORT(A);
REVERSE(A);
ll ans = 0;
rep(i, K) ans += A[i];
ANS;
return 0;
}
| 0
| 36,337,452
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 305;
char S[MAX_N][MAX_N];
int main()
{
int N;
cin >> N;
rep(i,N)
{
rep(j,N)
{
cin >> S[i][j];
}
}
int ans = 0;
for (int i = -N+1; i <= N-1; ++i)
{
bool flag = true;
for (int a = 0; a < N; ++a)
{
for (int b = 0; b < N; ++b)
{
int c = (b + N - i) % N;
int d = (a + N + i) % N;
if (S[a][b] != S[c][d]) flag = false;
}
}
if (flag) ans += N - abs(i);
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int a[105];
bool b[105]={0};
int main(){
int x,y;
cin>>x>>y;
if(y==0){
cout<<x<<endl;
return 0;
}
for(int i=1;i<=y;i++){
cin>>a[i];
b[a[i]]=true;
}
int i=101;
int max=100005;
int ans=102;
for(int n=101;n>=0;n--){
if(!b[i]){
if(max>=abs(i-x)){
max=abs(i-x);
if(ans>i){
ans=i;
}
i--;
}
}
else
{
i--;
}
}
cout<<ans<<endl;
}
| 0
| 97,493,971
|
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
string str,stra,straa;
ll x,y,w,z;
char ca,cb,cc;
cin>>a>>b>>c;
if(a>b&&a>c){
if(b<c)swap(b,c);
}else if(b>a&&b>c){
swap(a,b);
if(b<c) swap(b,c);
}else{
swap(a,c);
if(b<c) swap(b,c);
}
cout<<abs(c-b+b-a)<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(int argc, const char * argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
char b;
cin>>b;
if(b=='A')cout<<"T"<<endl;
if(b=='T')cout<<"A"<<endl;
if(b=='G')cout<<"C"<<endl;
if(b=='C')cout<<"G"<<endl;
return 0;
}
| 0
| 95,497,561
|
#include <stdio.h>
int main(void){
int N[3];
int work = 0;
scanf("%d%d%d", &N[0], &N[1], &N[2]);
for (int i = 0; i < 2; i++){
if (N[0] > N[1]){
work = N[0];
N[0] = N[1];
N[1] = work;
}
if (i == 0){
if (N[1] > N[2]){
work = N[1];
N[1] = N[2];
N[2] = work;
}
}
}
printf("%d %d %d\n", N[0], N[1], N[2]);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int N, a, b;
int main()
{
cin >> N >> a >> b;
int ans = abs(a - b) % 2;
if (ans == 0)
{
cout << "Alice" << endl;
}
else if (ans == 1)
{
cout << "Borys" << endl;
}
else
{
cout << "Draw" << endl;
}
return 0;
}
| 0
| 93,326,592
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;
int main(){
int a, num[4]={};
for(int i = 0; i < 6; ++i){
cin>>a;
num[a-1]++;
}
int cnt=0;
for(int i=0; i<4; i++){
if(num[i]%2==1){
cnt++;
}
}
if(cnt==0||cnt==2){
cout<<"YES";
}else{
cout<<"NO";
}
}
|
#include <bits/stdc++.h>
using namespace std ;
int main(){
int X;
cin >> X;
int A=0;
int Ans;
for(int i=1;i<=360;i++){
A = A+X;
A = A%360;
if(A==0){
Ans = i;
break;
}
}
cout << Ans << endl;
}
| 0
| 82,480,512
|
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> &a, pair<int, int> &b) {
return atan2(a.second, a.first) < atan2(b.second, b.first);
}
int main ()
{
int n;
cin >> n;
vector<pair<int, int>> a;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (x || y) {
a.emplace_back(x, y);
}
}
long double ans = 0.0;
sort(a.begin(), a.end(), cmp);
for (int i = 0; i < (int) a.size(); i++) {
long double curX = 0.0, curY = 0.0;
for (int j = 0; j < (int) a.size(); j++) {
int ind = (i + j) % a.size();
curX += a[ind].first;
curY += a[ind].second;
ans = max(ans, sqrt(curX * curX + curY * curY));
}
}
cout << setprecision(15) << fixed << ans;
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() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int& i : a) cin >> i, --i;
vector<int> s(n + 1, 0);
for (int i = 1; i <= n; ++i) (s[i] += s[i - 1] + a[i - 1]) %= k;
map<int, int> m;
ll r = 0;
for (int i = 1; i < min(k, n + 1); ++i) ++m[s[i]];
for (int i = 0; i <= n; ++i) {
r += m[s[i]];
if (i + k <= n) ++m[s[i + k]];
if (i + 1 <= n) --m[s[i + 1]];
}
cout << r << endl;
}
| 0
| 27,090,102
|
#include <iostream>
#include <algorithm>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i=0; i< (int)(n); i++)
typedef long long ll;
bool DEBUG = false;
int main() {
int H,W;
cin >> H >> W;
vector<vector<char>> grid(H);
rep(i, H){
string si;
cin >> si;
rep(j,W){
grid[i].push_back(si[j]);
}
}
vector<vector<int>> horizontal(H);
vector<vector<int>> vertical(H);
if (DEBUG) cout << "input done" << endl;
rep(row, H){
vector<int> blocks;
blocks.push_back(-1);
rep(col, W){
if (grid[row][col] == '#'){
blocks.push_back(col);
}
}
blocks.push_back(W);
if (DEBUG) cout << "blocks created for row: " << row << endl;
if (DEBUG) {
cout << "blocks are ";
rep(i, blocks.size()) {
cout << blocks[i] << " ";
}
cout << endl;
}
int bsize = (int) blocks.size();
if (DEBUG) cout << "w" << endl;
for (int bi = 0; bi < bsize - 1; bi++){
if (DEBUG) cout << "x" << endl;
if (bi != 0) horizontal[row].push_back(0);
int val_insert = blocks[bi+1] - blocks[bi] - 1;
if (DEBUG) cout << "y"<< endl;
rep(j, val_insert){
if (DEBUG) cout << "z1" << endl;
horizontal[row].push_back(val_insert);
if (DEBUG) cout << "z" << endl;
}
}
vector<int>().swap(blocks);
}
if (DEBUG) cout << "horizontal done" << endl;
rep(col, W){
vector<int> blocks;
blocks.push_back(-1);
rep(row, H){
if (grid[row][col] == '#'){
blocks.push_back(row);
}
}
blocks.push_back(H);
if (DEBUG) cout << "blocks created for col: " << col << endl;
if (DEBUG) {
cout << "blocks are ";
rep(i, blocks.size()) {
cout << blocks[i] << " ";
}
cout << endl;
}
for (int i = 0; i < (int) blocks.size() - 1; i++){
if (i != 0) vertical[blocks[i]].push_back(0);
int val_insert = blocks[i+1] - blocks[i] - 1;
rep(j, val_insert){
vertical[blocks[i] + j + 1].push_back(val_insert);
}
}
if (DEBUG) cout << "vales added for col: " << col << endl;
}
if (DEBUG) cout << "vertical done" << endl;
int ans = 0;
rep(i, H){
rep(j, W){
ans = max(horizontal[i][j]+vertical[i][j], ans);
}
}
cout << ans - 1 << endl;
}
|
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
string s;
while (cin >> s, s != "-") {
int m; cin >> m;
rep(i, m) {
int h; cin >> h;
s = s.substr(h) + s.substr(0, h);
}
cout << s << endl;
}
}
| 0
| 42,149,662
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
using int64 = long long;
int main() {
double T, X;
cin >> T >> X;
double t = T / X;
cout << t << endl;
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <climits>
#include <iomanip>
#include <string.h>
#include <algorithm>
#include <functional>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define clr(a,b) memset((a),b,sizeof(a))
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define sz(a) int((a).size())
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const int N = (int)2e5+77;
ll n,m,k,x,y,l,r;
string s,t;
char c;
int main() {
fast;
cout << "? 10000000000" << endl;
cin >> c;
if (c == 'Y') {
x = 2;
while (true) {
cout << "? " << x << endl;
cin >> c;
if (c == 'Y') {
cout << "! " << x / 2 << endl;
return 0;
}
x *= 10;
}
}
x = 1;
for1(i, 10) {
cout << "? " << x << endl;
cin >> c;
if (c == 'Y') x *= 10;
}
l = x, r = x * 10, n = x * 10;
while (l <= r) {
m = l + r >> 1;
cout << "? " << m << endl;
cin >> c;
if (c == 'Y') {
r = m - 1;
n = min(n, m);
} else {
l = m + 1;
}
}
cout << "! " << n / 10 << endl;
return 0;
}
| 0
| 9,521,359
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
a=max(a,c);
b=min(b,d);
if(b-a>0) cout << b-a << endl;
else cout << 0 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define REP(type, name, beginValue, endCondValue) \
for (type name = beginValue; name < endCondValue; ++name)
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double
int main(){
int h, w;
cin >> h >> w;
VECTOR_DIM2(bool, grid, h, w, false);
rep(i,h) {
string s;
cin >> s;
rep(j,w) {
if (s[j] == '#') {
grid[i][j] = true;
}
}
}
vector<bool> hValid(h, true), wValid(w, true);
rep(i, h) {
bool hasBlack = false;
rep(j,w) {
if (grid[i][j] == true) {
hasBlack = true;
break;
}
}
if (!hasBlack) {
hValid[i] = false;
}
}
rep(j, w) {
bool hasBlack = false;
rep(i,h) {
if (grid[i][j] == true) {
hasBlack = true;
break;
}
}
if (!hasBlack) {
wValid[j] = false;
}
}
rep (i, h) {
if (!hValid[i]) {
continue;
}
rep(j, w) {
if (!wValid[j]) {
continue;
}
cout << (grid[i][j] ? '#' : '.');
}
cout << endl;
}
return 0;
}
| 0
| 46,114,915
|
#include <iostream>
#include <cctype>
#include <cstdio>
using namespace std;
int main() {
char chr;
while(1){
chr=cin.get();
if(chr =='\n')break;
if (isalpha(chr)){
if (islower(chr))chr=toupper(chr);
else chr=tolower(chr);
}
cout<<chr;
}
cout<<endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main()
{
const int N = 10000;
int x = 0;
for(int i = 1; i <= N ; i++)
{
cin >> x;
if ( x == 0 ){ break; }
cout << "Case " << i << ": " << x << endl;
}
return 0;
}
| 0
| 46,503,408
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
ost << "{" << p.first << ", " << p.second << "} ";
return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
ost << "{";
for (int i = 0; i<(int)v.size(); i++) {
if (i)ost << " ";
ost << v[i];
}
ost << "} \n";
return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
ost << "{";
for (auto p:v) {
ost << "{" << p.first << ", " << p.second << "} ";
}
ost << "} ";
return ost;
}
template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}
template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}
void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}
ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}
int main()
{
char s[30];
map<char,ll> m;
ll cnt=1;
cin >> s;
for(ll i=0;s[i];i++){
m[s[i]]++;
cnt++;
if(m[s[i]]==2){
cout << -1 << endl;
return 0;
}
}
for(char c='z';c>='a';c--){
if(m[c]==0){
s[cnt]=c;
cnt++;
}
}
if(next_permutation(s,s+cnt)) cout << s << endl;
else cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;
int main() {
int N; cin >> N;
vector<int> cost;
cost.push_back(1);
int six = 1;
while(six*6 <= N){
six *= 6;
cost.push_back(six);
}
int nine = 1;
while(nine*9 <= N){
nine *= 9;
cost.push_back(nine);
}
sort(ALL(cost));
vector<vector<int>> dp(cost.size(), vector<int>(N+1, INF));
dp[0][0] = 0;
REP(i,cost.size()){
REP(j,N+1){
if(j+cost[i] <= N){
dp[i][j+cost[i]] = min(dp[i][j+cost[i]], dp[i][j]+1);
}
if(i!=cost.size()-1){
dp[i+1][j] = dp[i][j];
}
}
}
cout << dp[cost.size()-1][N] << endl;
return 0;
}
| 0
| 35,519,993
|
#include <iostream>
#include <map>
using namespace std;
int main(){
int n,m;
char cha, chb;
char c;
char *out;
out = new char[100000001];
while(cin >> n, n){
map<char, char> conv;
map<char, char>::iterator itr;
for(int i=0; i<n; i++){
cin >> cha >> chb;
conv.insert(make_pair(cha, chb));
}
cin >> m;
for(int i=0; i<m; i++){
cin >> c;
if((itr = conv.find(c)) != conv.end()) out[i] = itr->second;
else out[i] = c;
}
out[m] = '\0';
cout << out << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long sum, tmp;
unsigned long long ans;
int i, j, n;
int a[200100];
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= n; i++) {
while (j + 1 <= n && (tmp ^ a[j + 1]) == sum + a[j + 1]) {
tmp ^= a[j + 1];
sum += a[j + 1];
j++;
}
if (tmp == sum) {
ans += j - i + 1;
}
tmp ^= a[i];
sum -= a[i];
}
printf("%lld\n", ans);
return 0;
}
| 0
| 69,885,273
|
#include "bits/stdc++.h"
#include "math.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int INF=1e9;
ll devine(ll x,ll y){
if(x<0&&y<0){
if(x%y<0){return (x/y)+1;}
}
return x/y;
}
ll amari(ll x,ll y){
if(x<0&&y<0){
if(x%y<0){return (x%y)-y;}
}
return x%y;
}
int main(){
ll n,m,ans=0;
cin>>n>>m;
vll a(n),sum(n+1,0);
set<ll> s;
rep(i,0,n){
cin>>a[i];a[i]%=m;
sum[i+1]=sum[i]+a[i];
sum[i+1]%=m;
s.insert(sum[i]);
}
sort(sum.begin(),sum.end());
auto itset=s.begin();
rep(i,0,s.size()){
auto it=upper_bound(sum.begin(),sum.end(),*(itset))-lower_bound(sum.begin(),sum.end(),*(itset));
ans+=(it*(it-1))/2;
itset++;
}
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
int a[500010];
int main()
{
cin.tie(0);
ios::sync_with_stdio(0);
str s;
cin>>s;
int n=s.size()+1;
int nn=0;
int sn=0;
int mn=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='<')nn++;
else nn--;
sn=min(sn,nn);
mn=min(mn,nn);
a[i+1]=nn;
}
vector<pair<int,int>> p;
bool down=true;
sn=0;
for(int i=1;i<n;i++)
{
if(i==n-1)
{
sn=min(sn,a[i]);
p.push_back(make_pair(n-1,sn));
}
else
{
if(down&&a[i-1]<a[i])
{
down=false;
}
else if(!down&&a[i-1]>a[i])
{
p.push_back(make_pair(i-1,sn));
sn=a[i];
down=true;
}
else
{
sn=min(sn,a[i]);
}
}
}
int cur=0;
for(int i=0;i<n-1;i++)
{
if(p[cur].first<i)cur++;
if(p[cur].first==i)
{
a[i]-=min(p[cur].second,p[cur+1].second);
}
else a[i]-=p[cur].second;
}
a[n-1]-=p[cur].second;
ll ans=0;
for(int i=0;i<n;i++)ans+=a[i];
cout<<ans<<"\n";
return 0;
}
| 0
| 31,874,728
|
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i =a; i<n; i++)
#define ll long long
using namespace std;
int main() {
int A,B,C; cin >> A >> B >> C;
if (A <= C && B >= C) cout << "Yes" << endl;
else cout << "No" << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;
void f(int res , string s){
if(res==0){
cout << s << endl;}
else{
for(char c='a'; c<='c'; c++){
f(res -1, s + c);}
}
}
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
int main() {
int N;
cin>>N;
int a[N]={};
int ca=0;
int d=0;
int u=0;
int ma=0;
int mi=0;
for(int i=0; i<N; i++){
cin>>a[i];}
for(int i=0; i<N-1; i++){
ma=max(ma,a[i]);
mi=min(mi,a[i]);
if(d==0&&a[i]>a[i+1]){
ca+=a[i]-mi;
d++;
ma=0;
mi=a[i+1];}
else if(a[i]<a[i+1]){
d=0;}}
ma=max(ma,a[N-1]);
if(d==0){
ca+=a[N-1]-mi;}
cout<<ca<<endl;}
| 0
| 43,999,956
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll A, B;
cin >> A >> B;
ll ans = 1;
ll x = A;
while(x<=B) {
x *= 2;
ans++;
}
ans--;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
vector<pair<int, int> > adj[k];
int dist1, dist2, weight;
for (int i = 0; i < k; i++) {
dist1 = (i * 10) % k;
weight = 0;
if ( dist1 != i ) {
adj[i].push_back(make_pair(dist1, weight));
}
dist2 = (i + 1) % k;
weight = 1;
if ( dist2 != dist1 && dist2 != i) {
adj[i].push_back(make_pair(dist2, weight));
}
}
int *d;
bool *visit;
d = new int[k];
visit = new bool[k];
int next_u;
for (int i = 0; i < k; i++) d[i] = 1000000;
for (int i = 0; i < k; i++) visit[i] = false;
d[1] = 1;
deque <int> q;
for (int i = 0; i < adj[1].size(); i++) {
next_u = adj[1][i].first;
if (adj[1][i].second == 0) {
q.push_front(next_u);
d[next_u] = d[1];
} else {
q.push_back(next_u);
d[next_u] = d[1] + 1;
}
}
int u;
while ( !q.empty() ) {
u = q.front();
q.pop_front();
for (int i = 0; i < adj[u].size(); i++) {
next_u = adj[u][i].first;
if (adj[u][i].second == 0 && !visit[next_u]) {
q.push_front(next_u);
d[next_u] = d[u];
} else if (!visit[next_u]) {
q.push_back(next_u);
d[next_u] = d[u] + 1;
}
}
visit[u] = true;
if (u == 0) break;
}
cout << d[0] << endl;
delete[] d;
delete[] visit;
return 0;
}
| 0
| 70,700,367
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S, T;
cin >> N >> S >> T;
for (int i = 0; i < N; i++) {cout << S.at(i) << T.at(i);}
}
|
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)
#define intt long long
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
using namespace std;
int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
res %= m;
}
x = x * x % mod;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (!(x % i)) {
return false;
}
}
return true;
}
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
int keta(int x) {
int ans = 0;
while (x) {
x /= 10;
ans++;
}
return ans;
}
int ketasum(int x) {
int ans = 0;
while (x) {
ans += x % 10;
x /= 10;
}
return ans;
}
inline int lcm(int x, int y) {
int ans = x / gcd(x, y) * y;
return ans;
}
int twobeki(int x) {
int ans = 0;
while (1) {
if (!(x & 1)) {
ans++;
x /= 2;
}
else {
break;
}
}
return ans;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
void Yes(){
cout<<"Yes"<<endl;
}
void No(){
cout<<"No"<<endl;
}
void YES(){
cout<<"YES"<<endl;
}
void NO(){
cout<<"NO"<<endl;
}
#define fin(i) scanf("%lld",&i)
#define fout(i) printf("%lld\n",i)
#define fendl printf("\n")
template <class T>
class LazySegTree {
int n;
vector<T> data;
vector<T> lazy;
T def;
function<T(T, T)> operation;
function<T(T, T)> update;
T _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) return def;
if (a <= l && r <= b)
return data[k];
else {
T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
return operation(c1, c2);
}
}
public:
LazySegTree(size_t _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
data = vector<T>(2 * n - 1, def);
}
void change(int i, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
void change(int i, int j, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
T query(int a, int b) {
return _query(a, b, 0, 0, n);
}
T operator[](int i) {
return data[i + n - 1];
}
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
int n,m,a[100004],ans,cnt;
map<int, int> mp;
signed main() {
cin>>n>>m;
REP(i,n){
fin(a[i]);
a[i]+=a[i-1];
a[i]%=m;
}
rep(i,n+1){
mp[a[i]%m]++;
}
for(auto i:mp){
ans+=i.second*(i.second-1)/2;
}
cout<<ans<<endl;
}
| 0
| 33,070,033
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, char **argv)
{
ll N; cin >> N;
ll res{0};
for (ll i = 0; i < N; ++i)
{
ll a, b; cin >> a >> b;
res += b - a + 1;
}
std::cout << res << std::endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,s,n) for(int i=s;i<n;++i)
#define FORR(i,s,n) for(int i=n-1;i>=s;--i)
#define ALL(c) (c).begin(),(c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define ABS(a) ((a)>0?(a):-(a))
#define F first
#define S second
int main(int argc, char **argv) {
string s, t;
cin >> s >> t;
sort(ALL(s));
sort(ALL(t));
reverse(ALL(t));
cout << (s < t ? "Yes" : "No") << endl;
return 0;
}
| 0
| 85,631,417
|
#include <bits/stdc++.h>
int main() {
std::string S;
std::cin >> S;
if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
std::cout << "Yes" << std::endl;
return 0;
}
if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
std::cout << "Yes" << std::endl;
return 0;
}
if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
std::cout << "Yes" << std::endl;
return 0;
}
std::cout << "No" << std::endl;
}
|
#include <iostream>
#include <list>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
struct Ten{
double X;
double Y;
};
void out(Ten t){
cout << t.X << " "<<t.Y <<endl;
}
void solve(Ten P1, Ten P2 ,int n){
if(n ==0){
return;
}
Ten s;
Ten u;
Ten t;
Ten v;
v.X=(P2.X-P1.X)/3;
v.Y=(P2.Y-P1.Y)/3;
s.X =P1.X+v.X;
s.Y =P1.Y+v.Y;
u.X=s.X+(v.X*cos(60*M_PI/180)-v.Y*sin(60*M_PI/180));
u.Y=s.Y+(v.X*sin(60*M_PI/180)+v.Y*cos(60*M_PI/180));
t.X =P2.X-v.X;
t.Y =P2.Y-v.Y;
if(n == 1){
}
n--;
solve(P1, s , n);
if(n==0){
out(s);
}
solve(s, u, n);
if(n==0){
out(u);
}
solve(u, t, n);
if(n==0){
out(t);
}
solve(t, P2, n);
if(n ==0){
out(P2);
}
}
int main(void){
int n;
cin >> n;
Ten siten;
siten.X =0;
siten.Y =0;
Ten syuten;
syuten.X =100;
syuten.Y =0;
out(siten);
solve(siten, syuten, n);
if(n ==0){
out(syuten);
}
return 0;
}
| 0
| 1,659,907
|
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define IOI 101
#define IOIOIOIOI 101010101
int dp[10 * IOI][10 * IOI];
string s, t;
int main() {
for (int i = 0; i < 10 * IOI; i++) {
for (int j = 0; j < 10 * IOI; j++) {
dp[i][j] = IOIOIOIOI;
}
}
cin >> s; cin >> t;
for (int i = 0; i <= s.size(); i++)dp[i][0] = i;
for (int i = 0; i <= t.size(); i++)dp[0][i] = i;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
dp[i + 1][j + 1] = min(dp[i][j], min(dp[i + 1][j], dp[i][j + 1])) + 1;
if (s[i] == t[j]) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
}
}
cout << dp[s.size()][t.size()] << endl;
return 0;
}
|
#include <bits/stdc++.h>
typedef struct Node {
Node *left, *right;
int data;
} Node;
Node base;
void Node_init() {
base.right = &base;
base.left = &base;
return;
}
void Node_insert(int x) {
Node *node = new Node();
node->data = x;
node->right = base.right;
node->left = &base;
base.right->left = node;
base.right = node;
return;
}
void Node_delete(int x) {
Node *node = base.right;
while( node != &base ) {
if( node->data == x ) {
node->right->left = node->left;
node->left->right = node->right;
delete node;
return;
}
node = node->right;
}
return;
}
void Node_deleteFirst(void) {
Node *node = base.right;
node->right->left = node->left;
node->left->right = node->right;
delete node;
return;
}
void Node_deleteLast(void) {
Node *node = base.left;
node->right->left = node->left;
node->left->right = node->right;
delete node;
return;
}
void Node_print(void) {
Node *node = base.right;
while( node != &base ) {
if( node->right == &base ) {
printf("%d\n", node->data);
return;
}
else {
printf("%d ", node->data);
}
node = node->right;
}
return;
}
int main(void) {
int N;
char str[256];
int x;
Node_init();
std::cin >> N;
for(int i = 0; i < N; ++i) {
scanf("%s", str);
if( strcmp(str,"insert") == 0 ) {
scanf("%d", &x);
Node_insert(x);
}
else if( strcmp(str, "delete") == 0 ) {
scanf("%d", &x);
Node_delete(x);
}
else if( strcmp(str, "deleteFirst") == 0 ) {
Node_deleteFirst();
}
else if( strcmp(str, "deleteLast") == 0 ) {
Node_deleteLast();
}
else {
std::cout << "Error : " << str << std::endl;
exit(1);
}
}
Node_print();
return 0;
}
| 0
| 3,434,441
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()
const ll mod = 1e9+7;
const ll INF = 1e9;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
return lx<=x&&x<ux&&ly<=y&&y<uy;
}
ll power(ll x,ll p){
if(p==0)return 1;
ll res=power(x*x%mod,p/2);
if(p%2==1)res=res*x%mod;
return res;
}
int main()
{
int n,m;
cin>>n>>m;
vector<vector<int>> s(m,vector<int>());
rep(i,m){
int k;
cin>>k;
s[i].resize(k);
rep(j,k)cin>>s[i][j];
}
vector<int> p(m);
rep(i,m)cin>>p[i];
int ans=0;
rep(bit,(1<<n)){
int light=0;
rep(i,m){
int cnt=0;
rep(j,s[i].size()){
if((bit>>s[i][j]-1)&1)cnt++;
}
if(cnt%2==p[i])light++;
}
if(light==m)ans++;
}
cout<<ans<<endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N), B(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
B[i] = A[i];
}
sort(B.begin(), B.end());
reverse(B.begin(), B.end());
int fst = B[0], sec = B[1];
for (int i = 0; i < N; ++i) {
if (A[i] == fst)
cout << sec << endl;
else
cout << fst << endl;
}
return 0;
}
| 0
| 22,711,517
|
#include<bits/stdc++.h>
using namespace std;
struct card {char suzi, mozi;};
card hozon[36];
int hyozi(card hai[36],int a){
for(int i = 0;i<a-1;i++){
cout<<hai[i].mozi<<hai[i].suzi<<" ";
}
cout<<hai[a-1].mozi<<hai[a-1].suzi<<endl;
}
int kakunin(card hai[36],card hozon[36],int a){
for(int i = 0;i<a;i++){
if(hai[i].mozi != hozon[i].mozi){
cout<<"Not stable"<<endl;
return 0;
}
}
cout<<"Stable"<<endl;
return 0;
}
int bubble(card hai[36],int a){
int flag = 1;
while(flag){
flag = 0;
for(int i = a-1;i>0;i--){
if(hai[i].suzi <hai[i-1].suzi){
card o;
o = hai[i];
hai[i] = hai[i-1];
hai[i-1] = o;
flag = 1;
}
}
}
hyozi(hai,a);
cout<<"Stable"<<endl;
for(int i = 0;i<a;i++){
hozon[i] = hai[i];
}
}
int selection(card hai[36],int a){
for(int i = 0;i<a-1;i++){
int minj =i;
for(int j = i+1;j<a;j++){
if(hai[minj].suzi>hai[j].suzi){
minj = j;
}
}
card aho;
aho = hai[i];
hai[i] = hai[minj];
hai[minj] = aho;
}
hyozi(hai,a);
kakunin(hai,hozon,a);
}
int main(){
int a;
cin>>a;
card hai[a],hai2[a];
for(int i = 0;i<a;i++){
cin>>hai[i].mozi>>hai[i].suzi;
}
for(int i = 0;i<a;i++){
hai2[i] = hai[i];
}
bubble(hai,a);
selection(hai2,a);
return 0;
}
|
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
int x1 , y1 , x2 , y2 ;
cin >> x1 >> y1 >> x2 >> y2 ;
int a=abs(x1-x2);
int b=abs(y1-y2);
int x3 , y3 , x4 , y4 ;
if(x1<=x2&&y1<=y2){
x3=x2-b;
y3=y2+a;
x4=x3-a;
y4=y3-b;
}
if(x1<=x2&&y1>=y2){
x3=x2+b;
y3=y2+a;
x4=x3-a;
y4=y3+b;
}
if(x1>=x2&&y1<=y2){
x3=x2-b;
y3=y2-a;
x4=x3+a;
y4=y3-b;
}
if(x1>=x2&&y1>=y2){
x3=x2+b;
y3=y2-a;
x4=x3+a;
y4=y3+b;
}
cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl ;
}
| 0
| 39,830,598
|
#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);
string a,b,c;
cin>>a>>b>>c;
if(a.back()==b[0]&&b.back()==c[0])YES;
else NO;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
int main() {
int N, M; cin >> N >> M;
vector<int> k(M), p(M);
Graph s(M);
for(int i = 0; i < M; i++){
cin >> k[i];
for(int j = 0; j < k[i]; j++) {
int S; cin >> S;
s[i].push_back(S);
}
}
for(int i = 0; i < M; i++) cin >> p[i];
ll ans = 0;
for(int i = 0; i < (1 << 10); i++) {
bitset<10> bit(i);
if(i == (1 << N)) break;
bool judge = true;
for(int u = 0; u < M; u++) {
int cnt = 0;
for(auto v: s[u]) if(bit.test(v - 1)) cnt++;
if(cnt % 2 != p[u]) judge = false;
}
if(judge) ans++;
}
cout << ans << endl;
return 0;
}
| 0
| 38,393,946
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<numeric>
#include<math.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
ll x, y;
cin >> x >> y;
ll ans = 1e18;
rep(d1, 2) rep(d2, 2) {
ll res = d1 + d2;
ll xx = x * (d1 ? -1 : 1);
ll yy = y * (d2 ? -1 : 1);
if ( xx <= yy ) {
ans = min(ans, res + yy - xx );
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, K; cin >> n >> K;
vector<int> a(n);
for (auto &ai: a) cin >> ai;
vector<long long> acc(n + 1);
for (int i = 0; i < n; i++) acc[i + 1] = acc[i] + a[i];
long long ans = 0;
for (int k = 40; k >= 0; k--) {
ans |= 1LL << k;
int cnt = 0;
for (int l = 0; l < n; l++) for (int r = l + 1; r <= n; r++) {
if (((acc[r] - acc[l]) & ans) == ans) cnt++;
}
if (cnt < K) ans ^= 1LL << k;
}
cout << ans << endl;
return 0;
}
| 0
| 89,519,151
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M; cin >> N >> M;
vector<int> H(N);
for (int i = 0; i < N; i++) cin >> H[i];
vector<int> G[N];
for (int i = 0; i < M; i++) {
int A, B; cin >> A >> B;
G[A-1].push_back(B-1);
G[B-1].push_back(A-1);
}
int ans = 0;
for (int u = 0; u < N; u++) {
bool flag = true;
for (int v : G[u]) {
if (H[u] <= H[v]) flag = false;
}
if (flag) ans++;
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12);
#define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define newl cout<<"\n"
#define DISP(as) for(auto it : as) cout<<it<<" ";newl;
#define all(x) (x).begin(),(x).end()
#define mset(x,val) memset(x,val,sizeof(x))
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define dline cerr<<"
#define deb1(x) cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll ,ll> pll;
typedef pair<ld,ld> pld;
typedef unordered_map<ll,ll> um;
typedef vector<pll> vpll;
const ll MAX5 = 1e+5+7;
const ll MAX7 = 1e+7+7;
const ll MAXN = MAX7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MOD = 1e+9+7;
const ll N = 2*1e6;
ll T=1;
ll n,x,y,m;
string s,t;
void MAIN() {
cin>>s;
sort(all(s));
if(s=="abc") cout<<"Yes\n";
else cout<<"No\n";
}
int main() {
fastio;randomINT;
while(T--) {
MAIN();
}
return 0;
}
| 0
| 1,436,897
|
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n, K;
cin >> n >> K;
string s;
cin >> s;
vector<int> v;
v.push_back(0);
for (int i = 1; i < n; i++)
{
if(s[i]!=s[i-1])
{
v.push_back(i);
}
}
int maxv = 0;
for (int k = 0; k < v.size(); k++)
{
int x;
if (s[v[k]] == '0')
{
x = (k+2*K<v.size()?v[k + 2 * K]:n) - v[k];
}
else
{
x = (k+2*K+1<v.size()?v[k + 2 * K + 1]:n) - v[k];
}
maxv = max(maxv, x);
}
cout << maxv << 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>;
int main() {
string s, t;
cin >> t;
ll k;
cin >> k;
s=t;
if(s==string(s.size(),s[0])) {
cout << s.size()*k/2 << endl;
return 0;
}
ll ans=0;
for(int i=1; s[i]!='\0'; i++) {
if(s[i]==s[i-1]) {
ans++;
s[i]='*';
}
}
ans*=k;
int n1=1, n2=1;
for(int i=1; i<t.size(); i++) {
if(t[0]==t[i]) n1++;
else break;
}
for(int i=t.size()-2; i>=0; i--) {
if(t.back()==t[i]) n2++;
else break;
}
if(n1%2==1&&n2%2==1&&t[0]==t.back()) ans += k-1;
cout << ans << endl;
}
| 0
| 24,742,736
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long num, max, a, b=0;
cin >> num >> max;
vector<long long> list2;
for (long long i=0; i<num; i++) {cin >> a; list2.push_back(a);}
sort(list2.begin(),list2.end());
reverse(list2.begin(),list2.end());
for (long long i=0; i<max; i++) {b+=list2[i];}
cout << b;}
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;
int main() {
int k, n;
cin >> k >> n;
vector<int> a(n);
rep(i, n) {
cin >> a.at(i);
}
int max_dist = abs(k - a.at(n - 1)) + abs(0 - a.at(0));
rep(i, n - 1) {
int num = 0;
num = abs(a.at(i) - a.at(i + 1));
max_dist = max(max_dist, num);
}
cout << k - max_dist << endl;
return 0;
}
| 0
| 26,267,369
|
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
using ll = long long;
class Stream{
public:
Stream(){
}
void read(){
}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
cin >> first;
read(rest...);
}
template<typename T>
void write_vec(vector<T>& v, char divider){
for(size_t i = 0; i < v.size(); i++){
cout << v[i] << divider;
}
}
};
int main(){
Stream io;
int a, b;
io.read(a, b);
int ans = a + b;
if(ans % 2 == 0){
ans /= 2;
}
else{
ans = ans / 2 + 1;
}
cout << ans;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int h, w, k, ans = 0;
cin >> h >> w >> k;
vector<vector<int>> grid(h, vector<int>(w)), tmp(h, vector<int>(w));
vector<int> H(h);
vector<int> W(w);
for (int i = 0; i < h; i++) H[i] = i;
for (int j = 0; j < w; j++) W[j] = j;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
char c;
cin >> c;
if (c == '.') grid[i][j] = 0;
else grid[i][j] = 1;
tmp[i][j] = grid[i][j];
}
}
int h2 = 1 << h;
int w2 = 1 << w;
for (int i = 0; i < h2; i++) {
vector<int> dp1;
for (int j = 0; j < h; j++) {
if ((i & (1 << j)) != 0) {
dp1.push_back(j);
}
}
for (int ii = 0; ii < w2; ii++) {
vector<int> dp2;
for (int jj = 0; jj < w; jj++) {
if ((ii & (1 << jj)) != 0) {
dp2.push_back(jj);
}
}
for (int iii = 0; iii < h; iii++) for (int jjj = 0; jjj < w; jjj++) tmp[iii][jjj] = grid[iii][jjj];
for (int &x: dp1) {
for (int jjjj = 0; jjjj < w; jjjj++) tmp[x][jjjj] = 2;
}
for (int &x: dp2) {
for (int jjjj = 0; jjjj < h; jjjj++) tmp[jjjj][x] = 2;
}
int cnt = 0;
for (int l = 0; l < h; l++) {
for (int ll = 0; ll < w; ll++) {
cnt += (tmp[l][ll] == 1);
}
}
if (cnt == k) ans++;
}
}
cout << ans << "\n";
return 0;
}
| 0
| 40,653,347
|
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
cout << fixed << setprecision(10);
int n;
cin >> n;
cout << n*800 - n/15 * 200 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e+9 + 5;
const int MAX = 205;
vector<vector<ll> > d(MAX, vector<ll>(MAX, INF));
void floyd() {
for (int k = 0; k < MAX; k++) {
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
int main(){
ll N, M, R, a, b, c;
cin >> N >> M >> R;
vector<ll> r(R);
for (int i = 0; i < R; i++) {cin >> r[i]; r[i]--;}
for (int i = 0; i < M; i++) {
cin >> a >> b >> c;
a--, b--;
d[a][b] = c; d[b][a] = c;
}
floyd();
sort(r.begin(), r.end());
ll ans = INF;
do {
ll tmp = 0;
for (int i = 0; i < R - 1; i++) { tmp += d[r[i]][r[i+1]]; }
ans = min(ans, tmp);
} while(next_permutation(r.begin(), r.end()));
cout << ans << '\n';
}
| 0
| 32,380,928
|
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -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; }
#pragma endregion
ll diff(PLL a, PLL b, PLL c) {
ll max=0, min=LINF;
chmax(max, a.first*a.second);
chmax(max, b.first*b.second);
chmax(max, c.first*c.second);
chmin(min, a.first*a.second);
chmin(min, b.first*b.second);
chmin(min, c.first*c.second);
return max - min;
}
int solve(ll h, ll w) {
ll ans = LINF;
FOR(i,0,h) {
int mid = (i+h)/2;
chmin(ans, diff({i,w}, {mid-i,w}, {h-mid,w}));
mid = w/2;
chmin(ans, diff({i,w}, {h-i, mid}, {h-i, w-mid}));
}
return ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(false);
ll h,w; cin >> h >> w;
cout << min(solve(h,w), solve(w,h)) << 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;
typedef pair<int,int> P;
int main(void) {
int N; cin >> N;
while(N) {
int x = N%10;
if(x==7) {
cout << "Yes" << endl;
return 0;
}
N/=10;
}
cout << "No" << endl;
}
| 0
| 50,066,509
|
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
const int N = 1e6 + 1;
ll a, b;
void solve() {
cin >> a >> b;
if (a > b) swap(a, b);
ll c = sqrt(a * b);
if (c * c == a * b) c--;
if (a == b) cout << 2 * (a - 1);
else if (a + 1 == b) cout << 2 * (a - 1);
else if (c * (c + 1) >= a * b) cout << 2 * (c - 1);
else cout << 2 * c - 1;
cout << '\n';
}
int main() { cin.tie(0)->sync_with_stdio(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> ans(2);
if(n%2 == 1){
for(int l = 1, r = n-1; l < r; l++, r--){
ans.at(0).push_back(l);
ans.at(1).push_back(r);
}
}
else{
bool flag = false;
for(int l = 1, r = n-1; l < r; l++, r--){
if(!flag && r-l <= n/2){
--r;
flag = true;
}
ans.at(0).push_back(l);
ans.at(1).push_back(r);
}
}
for(int i = 0; i < m; i++){
cout << ans.at(0).at(i) << " " << ans.at(1).at(i) << endl;
}
}
| 0
| 92,628,421
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
bool In_map(ll y,ll x,ll h,ll w){
if(y<0 || x<0 || y>=h || x>=w){
return 0;
}else{
return 1;
}
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
int main() {
string S,T;
cin >>S>>T;
sort(all(S));
sort(all(T));
reverse(all(T));
if(S<T){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
long long N;
long long A[200005];
int main(){
cin >> N;
for(long long i = 0; i < N; i++) {
cin >> A[i];
}
set<long long> aset;
for(long long i = 0; i < N; i++) {
if(aset.count(A[i]) != 0) {
cout << "NO" << endl;
return 0;
}
aset.insert(A[i]);
}
cout << "YES" << endl;
}
| 0
| 20,157,592
|
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
char a[6][6];
char b[6][6];
void same()
{
for(int i= 0 ;i<n ;i++)
{
for(int j =0 ; j<m ;j++)
b[i][j] = a[i][j];
}
}
void set2(int i , int j)
{
for(int x = 0 ; x < n ; x++)
{
if(i & (1<<x))
{
for(int y = 0 ; y<m ; y++)
b[x][y] = '$';
}
}
for(int p =0 ; p<m ;p++)
{
if(j & (1 << p))
{
for(int q =0 ; q<n ;q++)
b[q][p] = '$';
}
}
}
bool check()
{
int p =0 ;
for(int i =0 ;i<n ;i++)
{
for(int j =0 ; j<m ;j++)
{
if(b[i][j] == '#')
p++;
}
}
return p == k ;
}
int main()
{
cin>>n>>m>>k;
for(int i = 0 ; i<n ; i++)
{
for(int j = 0 ; j<m ;j++)
{
cin>>a[i][j];
}
}
int count =0;
for(int i = 0 ; i < (1 << n) ; i++)
{
for(int j = 0 ; j< (1 << m); j++)
{
same();
set2(i , j);
if(check())
{
count++;
}
}
}
cout<<count<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve () {
int n;
cin >> n;
unordered_map<int, int> mp;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
mp[x]++;
if (mp[x] > 1) {
cout << "NO";
return;
}
}
cout << "YES";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
| 0
| 18,060,674
|
#include <iostream>
using namespace std;
using ULLint = unsigned long long int;
int main() {
ULLint ans = 1; int n; cin >> n;
for (int i = n; i > 0; i--) ans = ans * i;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rrep(i,n) for (int i = 1; i <= (n); i++)
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;
bool g[10][10];
int main() {
int n,m;
cin >> n >> m;
rep(i,m) {
int a,b;
cin >> a >> b;
a--; b--;
g[a][b] = true;
g[b][a] = true;
}
std::vector<int> v(n);
rep(i,n) v[i] = i;
int ans = 0;
do {
if (v[0] != 0) break;
bool ok = true;
rep(i,n-1) {
if (!g[v[i]][v[i+1]]) {
ok = false;
}
}
if (ok) ans++;
} while (next_permutation(v.begin(), v.end()));
cout << ans << endl;
}
| 0
| 29,751,935
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
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>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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,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;}
Graph G(100010);
vector<int> deg;
vector<bool> seen;
int main(){
int N;
cin>>N;
deg.assign(N,0);
seen.assign(N,0);
REP(i,N-1){
int a,b;
cin>>a>>b;
--a,--b;
G[a].PB(b);
G[b].PB(a);
deg[a]++,deg[b]++;
}
bool res=true;
queue<int> Q;
REP(i,N){
if(deg[i]==1) Q.push(i);
}
while(!Q.empty()){
int v=Q.front();
Q.pop();
if(seen[v]) continue;
seen[v]=true;
int nv=-1;
FORE(i,G[v]){
if(seen[i]==false) nv=i;
}
if(nv==-1){
res=false;
break;
}
seen[nv]=true;
FORE(nnv,G[nv]){
if(seen[nnv]) continue;
deg[nnv]--;
if(deg[nnv]==1) Q.push(nnv);
}
}
if(res) co("Second");
else co("First");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
const ll mod = 998244353;
int cnt[100005], t[100005];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n; read(n);
int mx = 0;
rep(i, 0, n) {
read(t[i]);
chmax(mx, t[i]);
cnt[t[i]]++;
}
if (t[0] != 0 || cnt[0] != 1)
die(0);
ll ans = 1;
rep(i, 1, mx + 1) {
rep(j, 0, cnt[i])
ans = ans * cnt[i - 1] % mod;
}
die(ans);
}
| 0
| 2,677,682
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<long long> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
long long max_A = A[0], ans = 0;
for (int i = 1; i < N; ++i) {
if (A[i] < max_A) {
ans += max_A - A[i];
} else {
max_A = A[i];
}
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define inf 1e9
#define pp pop_back
#define pii pair<int,int>
#define vec vector<int>
#define mp make_pair
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
while(t--)
{
int n;
cin>>n;
int i;
int a[n+1],b[n+1],c[n+1];
for(i=1;i<=n;i++)
cin>>a[i]>>b[i]>>c[i];
int dp[n+1][4];
dp[0][0]=dp[0][1]=dp[0][2]=dp[0][3]=0;
for(i=1;i<=n;i++)
{
dp[i][0]=max(a[i]+dp[i-1][1],max(b[i]+dp[i-1][2],c[i]+dp[i-1][3]));
dp[i][1]=max(b[i]+dp[i-1][2],c[i]+dp[i-1][3]);
dp[i][2]=max(a[i]+dp[i-1][1],c[i]+dp[i-1][3]);
dp[i][3]=max(a[i]+dp[i-1][1],b[i]+dp[i-1][2]);
}
cout<<dp[n][0];
}
}
| 0
| 17,321,131
|
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char str;
int num;
int cou[26];
int i;
char alp;
for(i=0; i<26; i++){
cou[i] = 0;
}
while(scanf("%c",&str) != EOF){
if(isalpha(str)){
if(isupper(str)){
str = tolower(str);
}
num = str - 'a';
cou[num]++;
}
}
for(i=0,alp='a'; i<26; i++,alp++){
printf("%c : %d\n",alp,cou[i]);
}
return(0);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int count = false;
string s;
for(int i = a; i <= b; i++) {
int temp = i, c = true;
int val = 0;
while(temp) {
int r = temp % 10;
temp /= 10;
s[val] = r + '0';
val++;
}
for(int j = 0, k = val - 1; j < val / 2; j++, k--) {
if(s[j] != s[k]) {
c = false;
break;
}
}
if(c)
count++;
}
cout << count << endl;
return 0;
}
| 0
| 76,126,452
|
#include "bits/stdc++.h"
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A), b(B);
for (int i = 0; i < A; ++i) cin >> a[i];
for (int i = 0; i < B; ++i) cin >> b[i];
int mina = INT_MAX;
for (int i = 0; i < A; ++i)
mina = min(mina, a[i]);
int minb = INT_MAX;
for (int i = 0; i < B; ++i)
minb = min(minb, b[i]);
int ans = mina + minb;
int x, y, c;
for (int i = 0; i < M; ++i) {
cin >> x >> y >> c;
x -= 1;
y -= 1;
int tmp = a[x] + b[y] - c;
ans = min(ans, tmp);
}
cout << ans << endl;
}
|
#include <stdio.h>
int main(void){
int high[10]={0}, ans[3]={0,-1,-2};
int i,l;
for(i=0; i<10; i++)
scanf("%d",&high[i]);
ans[0]=high[0];
if(ans[0]<high[1]){
ans[1]=ans[0];
ans[0]=high[1];
}else{
ans[1]=high[1];
}
for(i=2; i<10; i++){
if(ans[2]<high[i]){
if(ans[1]<high[i]){
if(ans[0]<high[i]){
ans[2]=ans[1];
ans[1]=ans[0];
ans[0]=high[i];
continue;
}
ans[2]=ans[1];
ans[1]=high[i];
continue;
}
ans[2]=high[i];
}
}
for(i=0; i<3; i++)
printf("%d\n",ans[i]);
return 0;
}
| 0
| 2,262,834
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.