#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int ans1 = 0,ans2 = 0;
while(n>3){
ans1++;
if(n%3==1 && ans2==0){
ans2 = ans1;
}
if(n%3==0)n-=n/3;
else n-=n/3+1;
}
ans1+=n;
if(ans2==0){
ans2=ans1;
}
cout<<ans1<<" "<<ans2<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,sum[100005],v[100005];
int main()
{
cin>>n>>m;
for(int i=2;i<=n;i++){
cin>>sum[i];
sum[i]+=sum[i-1];
}
for(int i=1;i<=n;i++){
cin>>v[i];
}
ll now = 1;
ll s = 0;
ll ans = 0;
for(int i=2;i<=n;i++){
if(v[i]<v[now]){
ll dis = sum[i]-sum[now];
if(dis-s<=0){
s = s-dis;
now = i;
continue;
}
if((dis-s)%m==0){
ans+=(dis-s)/m*v[now];
s = 0;
}
else{
ans+=((dis-s)/m+1)*v[now];
s = ((dis-s)/m+1)*m+s-(sum[i]-sum[now]);
}
now = i;
}
}
if(now!=n){
ll dis = sum[n]-sum[now];
if(s<dis){
if((dis-s)%m==0){
ans+=(dis-s)/m*v[now];
}
else{
ans+=((dis-s)/m+1)*v[now];
}
}
}
cout<<ans<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int gcd(int x,int y)
{
if(y==0)return x;
else return gcd(y,x%y);
}
void print(int a,int b)
{
int tmp = gcd(a,b);
a/=tmp;
b/=tmp;
if(b<0){
a = -a;
b = -b;
}
if(b==1)cout<<a;
else cout<<a<<"/"<<b;
}
int main()
{
int T,m;
cin>>T>>m;
while(T--){
int a,b,c;
cin>>a>>b>>c;
if(a<0){
a = -a;
b = -b;
c = -c;
}
int delta = b*b-4*a*c;
if(delta<0){
cout<<"NO"<<endl;
continue;
}
if(delta==0){
if(b==0)cout<<0<<endl;
else{
print(-b,2*a);
cout<<endl;
continue;
}
}
if(delta>0){
if(sqrt(delta)==int(sqrt(delta))){
int fenzi = -b+int(sqrt(delta));
int fenmu = 2*a;
print(fenzi,fenmu);
cout<<endl;
continue;
}
else{
if(b!=0){
print(-b,2*a);
cout<<"+";
}
int d = 0;
for(int i=sqrt(delta);i>=2;i--){
if(delta%(i*i)==0){
delta = delta/(i*i);
d = i;
break;
}
}
if(d!=0){
int tmp = gcd(d,2*a);
d/=tmp;
int fenmu = 2*a/tmp;
if(d!=1)
cout<<d<<"*sqrt("<<delta<<")";
else cout<<"sqrt("<<delta<<")";
if(fenmu!=1){
cout<<"/"<<fenmu<<endl;
}
else cout<<endl;
}
else{
cout<<"sqrt("<<delta<<")";
int fenmu = 2*a;
if(fenmu!=1){
cout<<"/"<<fenmu<<endl;
}
else cout<<endl;
}
}
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct node{
int v,w;
};
struct point{
int x,y;
};
vector<node>e[100005];
int n,m,k;
int f[10005][105];
void bfs()
{
memset(f,0x3f,sizeof(f));
f[1][0] = 0;
queue<point>q;
q.push({1,0});
while(!q.empty()){
point t = q.front();
int tmp = t.x;
int yu = t.y;
q.pop();
for(int i=0;i<e[tmp].size();i++){
int v = e[tmp][i].v;
int w = e[tmp][i].w;
if(f[tmp][yu]>=w && f[v][(yu+1)%k]>f[tmp][yu]+1){
f[v][(yu+1)%k] = f[tmp][yu]+1;
q.push({v,(yu+1)%k});
}
else if(f[tmp][yu]<w){
int cnt = (w-f[tmp][yu])/k;
if((w-f[tmp][yu])%k!=0)cnt++;
if(f[v][(yu+1)%k]>f[tmp][yu]+1+cnt*k){
f[v][(yu+1)%k]=f[tmp][yu]+1+cnt*k;
q.push({v,(yu+1)%k});
}
}
}
}
}
int main()
{
cin>>n>>m>>k;
for(int i=1;i<=m;i++){
int x,y,z;
cin>>x>>y>>z;
e[x].push_back({y,z});
}
bfs();
if(f[n][0]==0x3f3f3f3f)f[n][0] = -1;
cout<<f[n][0]<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n,a[10][6];
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=5;j++){
cin>>a[i][j];
}
}
/*
1 2 3 4 5
1 2 1 7 8
*/
int ans = 0;
for(int i=0;i<=99999;i++){
int flag = 0;
for(int j=1;j<=n;j++){
if(flag==1)break;
int c[6];
int b[10]={0,i/10000%10,i/1000%10,i/100%10,i/10%10,i%10};
int cnt = 0;
for(int k=1;k<=5;k++){
if(b[k]!=a[j][k]){
cnt++;
c[cnt] = k;
}
}
if(cnt==0 || cnt>=3 || (cnt==2 && c[2]-c[1]!=1)){
flag = 1;
continue;
}
// 9 0
// 10 1
else if(cnt==2){
if(b[c[1]]<a[j][c[1]])b[c[1]]+=10;
if(b[c[2]]<a[j][c[2]])b[c[2]]+=10;
if(b[c[1]]-a[j][c[1]]!=b[c[2]]-a[j][c[2]]){
flag = 1;
continue;
}
}
}
if(flag==0){
ans++;
}
}
cout<<ans<<endl;
return 0;
}