# [PYTHON] AtCoder Beginner Contest 5 questions to fill in tea diff

C - Ubiquity

#### `Python3`

``````
n = int(input())
print((10**n-9**n-9**n+8**n)%(10**9+7))
``````

#### `C++`

``````
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
ll n;
cin >> n;

ll mod = 1e9+7;
ll a=1, b=1, c=1;
for(ll i=0; i<n; i++){
a = (a * 10) % mod;
b = (b * 9) % mod;
c = (c * 8) % mod;
}
ll ans = (a-b-b+c)%mod;
ans = (ans+mod)%mod;
cout << ans << endl;

return 0;
}
``````

D - Wandering

#### `C++`

``````
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
int n;
cin >> n;

vector<int> A(n);
rep(i, n) cin >> A[i];

ll ans = 0;
ll b=0, s=0, max_b=0;
for(int i=0; i<n; i++){
b += A[i];
max_b = max(max_b, b);
ans = max(ans, s+max_b);
s += b;
}
cout << ans << endl;

return 0;
}
``````

C - Guess The Number

#### `C++`

``````
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
int n, m;
cin >> n >> m;

string ans;
rep(i, n) ans += '0';

int A[5]={-1};
rep(i, m){
int s, c;
cin >> s >> c;
s--;
if(ans[s] == '0' || ans[s] == c+'0') ans[s] = c + '0';
else{
ans = "-1";
break;
}
A[s]=c;
}

if(ans[0]=='0'){
if(A[0]==-1 && ans.length()>1) ans[0]='1';
if(A[0]==0 && ans.length()>1) ans="-1";
}
cout << ans << endl;

return 0;
}
``````

C - Typical Stairs

#### `C++`

``````
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cctype>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

int dp[100002];

int main(int argc, const char * argv[]) {
int mod = 1e9+7;
int N, M;
cin >> N >> M;

rep(i, N+2) dp[i] = 0;
rep(i, M){
int a;
cin >> a;
dp[a] = -1;
if(a>0 && dp[a-1]==-1) { cout << 0 << endl; return 0; }
}

dp[0]=0;
if(dp[1]==0) dp[1] = 1;
if(dp[1]==-1) dp[2] = 1;
else dp[2] = 2;

for(int i=3; i<=N; i++){
if(dp[i]==0){
if(dp[i-1]==-1) dp[i] = dp[i-2];
else if(dp[i-2]==-1) dp[i] = dp[i-1];
else dp[i] = (dp[i-1] + dp[i-2]) % mod;
}
}

cout << dp[N] << endl;

return 0;
}
``````

C - Dice and Coin

#### `C++`

``````
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cctype>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(int argc, const char * argv[]) {
double N, K;
cin >> N >> K;

int cc=1;
double sum=0;
while(cc<=N){
int c=cc;
double cnt=0;
while(c<K){
cnt++;
c=c*2;
}
sum += (1.0/N) * pow(1.0/2.0, cnt);
cc++;
}

cout << fixed_setprecision(10) << sum << endl;

return 0;
}
``````

#### `C++`

``````
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cctype>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(int argc, const char * argv[]) {
double N, K;
cin >> N >> K;

int cc=1;
double sum=0;
while(cc<=N){
int c=cc;
double tmp=1.0/(double)N;
while(c<K){
tmp/=2.0;
c=c*2;
}
sum+=tmp;
cc++;
}

cout << fixed_setprecision(10) << sum << endl;

return 0;
}
``````