stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

			bool dp[1001][1000]={};

            dp[0][0]=true;

            for(int i=0;i<n;i++){

                for(int j=0;j<1000;j++){

                    if(dp[i][j]){

                        dp[i+1][j]=true; 

                        if(j+w[i]<1000)

                            dp[i+1][j+w[i]]=true; 

                    }

                }

            }

  

            int opt=r0-r;

            while(!dp[n][opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}

// Faster C++ solution for the same problem (measured speedup: 2.20504650311221x):
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

	

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

			bool cur[1001]={};

            cur[0]=true;

            for(int i=0;i<n;i++){

				bool next[1001]={};

                for(int j=0;j<=r0-r;j++){

                    if(cur[j]){

                        next[j]=true; 

                        if(j+w[i]<=r0-r)

                            next[j+w[i]]=true; 

                    }

                }

				swap(cur,next);

            }

  

            int opt=r0-r;

            while(!cur[opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

	bool dp[1001][1000]={};

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

			fill(&dp[0][0],&dp[1001][0],false);

            dp[0][0]=true;

            for(int i=0;i<n;i++){

                for(int j=0;j<1000;j++){

                    if(dp[i][j]){

                        dp[i+1][j]=true; 

                        if(j+w[i]<1000)

                            dp[i+1][j+w[i]]=true; 

                    }

                }

            }

  

            int opt=r0-r;

            while(!dp[n][opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}

// Faster C++ solution for the same problem (measured speedup: 2.3456056942263643x):
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

	

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

			bool cur[1001]={};

            cur[0]=true;

            for(int i=0;i<n;i++){

				bool next[1001]={};

                for(int j=0;j<=r0-r;j++){

                    if(cur[j]){

                        next[j]=true; 

                        if(j+w[i]<=r0-r)

                            next[j+w[i]]=true; 

                    }

                }

				swap(cur,next);

            }

  

            int opt=r0-r;

            while(!cur[opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

 



 

int main(){

 

	int n; 

	while(scanf("%d",&n),n){



		vector<pair<int,int> > rw(n);

		int sum_r=0,sum_w=0;

		for(int i=0;i<n;i++){

			cin>>rw[i].first>>rw[i].second;

			sum_r+=rw[i].first;

			sum_w+=rw[i].second;

		}

		sort(rw.begin(),rw.end(),greater< pair<int,int> >());



		int r0=rw[0].first;

		int r=sum_r-r0;



		if(r0 <= r){

			cout<<sum_r+sum_w<<endl;

		}else{



			int res=2*rw[0].first;

			vector<vector<bool> > dp(1001,vector<bool>(1000,false));



			//r0-r???w?????°??????

			//dp[pos][sum]



			dp[1][0]=true;

			for(int i=1;i<n;i++){

				for(int j=0;j<=1000;j++){

					if(dp[i][j]){

						dp[i+1][j]=true; //??°?????????

						if(j+rw[i].second<=10000)

							dp[i+1][j+rw[i].second]=true; //??°??????

					}

				}

			}



			int opt=0;

			for(int i=1;i<=r0-r;i++){

				if(dp[n][i]) opt=i;

			}



			res+=sum_w-opt;

			cout<<res<<endl;







		}

		

		

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.6604531134443552x):
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

	

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

//			bool cur[1001]={};

			bool *cur = (bool*)malloc( sizeof(bool)*(1000+2) );

            cur[0]=true;

            for(int i=0;i<n;i++){

				bool *next = (bool*)malloc( sizeof(bool)*(1000+2) );

                for(int j=0;j<=r0-r;j++){

                    if(cur[j]){

                        next[j]=true; 

                        if(j+w[i]<=r0-r)

                            next[j+w[i]]=true; 

                    }

                }

				swap(cur,next);

            }

  

            int opt=r0-r;

            while(!cur[opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

  

 

  

int main(){

  

    int n; 

    while(scanf("%d",&n),n){

 

        vector<pair<int,int> > rw(n);

        int sum_r=0,sum_w=0;

        for(int i=0;i<n;i++){

            cin>>rw[i].first>>rw[i].second;

            sum_r+=rw[i].first;

            sum_w+=rw[i].second;

        }

        sort(rw.begin(),rw.end(),greater< pair<int,int> >());

 

        int r0=rw[0].first;

        int r=sum_r-r0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

 

            int res=2*rw[0].first;

            vector<vector<bool> > dp(1001,vector<bool>(1000,false));

 

            dp[1][0]=true;

            for(int i=1;i<n;i++){

                for(int j=0;j<=1000;j++){

                    if(dp[i][j]){

                        dp[i+1][j]=true; 

                        if(j+rw[i].second<=1000)

                            dp[i+1][j+rw[i].second]=true; 

                    }

                }

            }

 

            int opt=0;

            for(int i=1;i<=r0-r;i++){

                if(dp[n][i]) opt=i;

            }

 

            res+=sum_w-opt;

            cout<<res<<endl;

 

 

 

        }

         

         

    }

}

// Faster C++ solution for the same problem (measured speedup: 1.6604531134443552x):
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

	

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

//			bool cur[1001]={};

			bool *cur = (bool*)malloc( sizeof(bool)*(1000+2) );

            cur[0]=true;

            for(int i=0;i<n;i++){

				bool *next = (bool*)malloc( sizeof(bool)*(1000+2) );

                for(int j=0;j<=r0-r;j++){

                    if(cur[j]){

                        next[j]=true; 

                        if(j+w[i]<=r0-r)

                            next[j+w[i]]=true; 

                    }

                }

				swap(cur,next);

            }

  

            int opt=r0-r;

            while(!cur[opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

			bool dp[1001][1000]={};

            dp[0][0]=true;

            for(int i=0;i<n;i++){

                for(int j=0;j<1000;j++){

                    if(dp[i][j]){

                        dp[i+1][j]=true; 

                        if(j+w[i]<1000)

                            dp[i+1][j+w[i]]=true; 

                    }

                }

            }

  

            int opt=r0-r;

            while(!dp[n][opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}

// Faster C++ solution for the same problem (measured speedup: 2.206881777394075x):
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

	

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

//			bool cur[1001]={};

			bool *cur = (bool*)malloc( sizeof(bool)*(1000+2) );

            cur[0]=true;

            for(int i=0;i<n;i++){

				bool *next = (bool*)malloc( sizeof(bool)*(1000+2) );

                for(int j=0;j<=r0-r;j++){

                    if(cur[j]){

                        next[j]=true; 

                        if(j+w[i]<=r0-r)

                            next[j+w[i]]=true; 

                    }

                }

				swap(cur,next);

            }

  

            int opt=r0-r;

            while(!cur[opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

	bool dp[1001][1000]={};

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

			fill(&dp[0][0],&dp[1001][0],false);

            dp[0][0]=true;

            for(int i=0;i<n;i++){

                for(int j=0;j<1000;j++){

                    if(dp[i][j]){

                        dp[i+1][j]=true; 

                        if(j+w[i]<1000)

                            dp[i+1][j+w[i]]=true; 

                    }

                }

            }

  

            int opt=r0-r;

            while(!dp[n][opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}

// Faster C++ solution for the same problem (measured speedup: 2.3475579568203426x):
#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdlib>

#include <ctime>

#include <cstdio>

#include <functional>

#include <set>

#include <queue>

#include <cctype>

#include <climits>

#include <stack>

using namespace std;

   

  

   

int main(){

   

    int n; 

    int r[1000],w[1000];

    int sum_r=0,sum_w=0,idx=0;

	

    while(scanf("%d",&n),n){

         

        sum_r=sum_w=idx=0;

        for(int i=0;i<n;i++){

            scanf("%d %d",&r[i],&w[i]);

            sum_r+=r[i];

            sum_w+=w[i];

            if(r[idx]<r[i]) idx=i;

        }

  

        int r0=r[idx],r=sum_r-r0;

        w[idx]=0;

 

        if(r0 <= r){

            cout<<sum_r+sum_w<<endl;

        }else{

  

            int res=2*r0;

            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));

  

//			bool cur[1001]={};

			bool *cur = (bool*)malloc( sizeof(bool)*(1000+2) );

            cur[0]=true;

            for(int i=0;i<n;i++){

				bool *next = (bool*)malloc( sizeof(bool)*(1000+2) );

                for(int j=0;j<=r0-r;j++){

                    if(cur[j]){

                        next[j]=true; 

                        if(j+w[i]<=r0-r)

                            next[j+w[i]]=true; 

                    }

                }

				swap(cur,next);

            }

  

            int opt=r0-r;

            while(!cur[opt]) opt--;

  

            res+=sum_w-opt;

            printf("%d\n",res);

  

  

  

        }

          

          

    }

}
// Slower C++ solution:
#include<stdio.h>

#include<cstdio>

#include<iostream>

#include<algorithm>

#include<string>

#include<math.h>

#include<vector>

#include<queue>

#include<map>

#include<stack>

#include<fstream>

#include<stdlib.h>

#include<set>

#include<climits>

#include<cmath>

#include<memory.h> 

#include<sstream>

#include<time.h>

using namespace std;

const long long BIGER=1000000000000000;

const int BIG=1000000000;

long long a[101];

long long g=1;

string st;

long long s=0;

long long ypa(long long k)

{

	if(k==st.size())

	{

		for(long long i=1;i<=g;i++)

		{

			cerr<<a[i]<<" ";

			s+=a[i];

		}

		cerr<<endl;

	}

	else

	{

		a[g]=a[g]*10+st[k]-'0';

		ypa(k+1);

		a[g]=(a[g]-st[k]+'0')/10;

		g++;

		a[g]=a[g]*10+st[k]-'0';

		ypa(k+1);

		a[g]=(a[g]-st[k]+'0')/10;

		g--;

	}

	return 19260817;

}

int main()

{

	cin>>st;

	a[1]=st[0]-'0';

	ypa(1);

	cout<<s;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.290221737013706x):
#include<cstdio>

#include<cstring>

char a[11];

int add[10],len;

long long ans=0;

void getsum1()

{

    long long temp=0;

    for (int i = 0; i < len; i++)

    {

        if(add[i])

        {

            ans+=temp;

            temp=0;

        }

        temp=temp*10+a[i]-'0';

    }

    ans+=temp;

}

void getsum2()

{

    long long temp = a[0]-'0';

    for (int i = 1; i < len; i++)

    {

        if (!add[i])

        {

            ans += temp;

            temp = 0;

        }

        temp = temp * 10 + a[i] - '0';

    }

    ans += temp;

}

void dfs(int pos,int num)

{

    if(!num)

    {

        getsum1();

        //getsum2();

        return;

    }

    for (int i = pos; i < len-num+1; i++)

    {

        add[i]=1;

        dfs(i+1,num-1);

        add[i]=0;

    }

}

int main()

{

    scanf("%s",a);

    len=strlen(a);

    for (int i = 0; i < len; i++)

    {

        dfs(1,i);

    }

    printf("%lld",ans);

}
// Slower C++ solution:


 //In The Name Of GOD

 

#include <bits/stdc++.h>



using namespace std;



typedef long long ll ;



const int mod = 1000000007;

const int inf = 2000000000;

const int maxn = 500*1000+500*1000+15;

const int MLOG = 18;



#define int long long

#define pb push_back

#define pp pop_back

#define X first

#define Y second

#define IO ios_base::sync_with_stdio(false);

#define sz(a) (int)(a.size())



int32_t main(){

	string s;

	cin >> s;

	int n =  s.size();

	int all = 0;

	for(int i = 0; i < ( 1 << (n-1) ) ; i++){

		string ss;

		int ans=0;

		for(int j = 0; j < n; j++){

			ss += s[j];

			if( (i >> j) & 1 ){

				ans += atoll( ss.c_str() );

				ss.clear();

			}

		}

		ans += atoll( ss.c_str() );

		all += ans;

	}

	cout << all;

}

// Faster C++ solution for the same problem (measured speedup: 5.255220335482348x):
#include<cstdio>

#include<cstring>

char a[11];

int add[10],len;

long long ans=0;

void getsum1()

{

    long long temp=0;

    for (int i = 0; i < len; i++)

    {

        if(add[i])

        {

            ans+=temp;

            temp=0;

        }

        temp=temp*10+a[i]-'0';

    }

    ans+=temp;

}

void getsum2()

{

    long long temp = a[0]-'0';

    for (int i = 1; i < len; i++)

    {

        if (!add[i])

        {

            ans += temp;

            temp = 0;

        }

        temp = temp * 10 + a[i] - '0';

    }

    ans += temp;

}

void dfs(int pos,int num)

{

    if(!num)

    {

        getsum1();

        //getsum2();

        return;

    }

    for (int i = pos; i < len-num+1; i++)

    {

        add[i]=1;

        dfs(i+1,num-1);

        add[i]=0;

    }

}

int main()

{

    scanf("%s",a);

    len=strlen(a);

    for (int i = 0; i < len; i++)

    {

        dfs(1,i);

    }

    printf("%lld",ans);

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <fstream>

#include <algorithm>

#include <cmath>

#include <deque>

#include <vector>

#include <queue>

#include <string>

#include <cstring>

#include <map>

#include <stack>

#include <set>

#include <sstream>

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);

#define Mod 1000000007

#define eps 1e-6

#define ll long long

#define INF 0x3f3f3f3f 

#define MEM(x,y) memset(x,y,sizeof(x))

#define Maxn 100005

#define P pair<int,int>

using namespace std;

int main()

{

	char a[15];

	scanf("%s", &a);

	int q = 1 << (strlen(a) - 1);

	ll sum = 0;

	

	for (int i = 0; i < q; i++)

	{

		ll temp = a[0] - '0';

		for (int j = 0; j < strlen(a); j++)

		{

			if (i >> j & 1)

			{

				temp = temp * 10 + a[j + 1] - '0';

			}

			else

			{

				sum += temp;

				temp = a[j + 1] - '0';

			}

		}

	}

	cout << sum;

}

// Faster C++ solution for the same problem (measured speedup: 5.256257468686839x):
#include<cstdio>

#include<cstring>

char a[11];

int add[10],len;

long long ans=0;

void getsum1()

{

    long long temp=0;

    for (int i = 0; i < len; i++)

    {

        if(add[i])

        {

            ans+=temp;

            temp=0;

        }

        temp=temp*10+a[i]-'0';

    }

    ans+=temp;

}

void getsum2()

{

    long long temp = a[0]-'0';

    for (int i = 1; i < len; i++)

    {

        if (!add[i])

        {

            ans += temp;

            temp = 0;

        }

        temp = temp * 10 + a[i] - '0';

    }

    ans += temp;

}

void dfs(int pos,int num)

{

    if(!num)

    {

        getsum1();

        //getsum2();

        return;

    }

    for (int i = pos; i < len-num+1; i++)

    {

        add[i]=1;

        dfs(i+1,num-1);

        add[i]=0;

    }

}

int main()

{

    scanf("%s",a);

    len=strlen(a);

    for (int i = 0; i < len; i++)

    {

        dfs(1,i);

    }

    printf("%lld",ans);

}