#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<<"///REACHED///\n";
#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 ll  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1000000007;

/*vll adj[MAXN];ll visit[MAXN]={};
ll dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
*/
// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m,k,d,w;
string s,t;
//vll a,b;
// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN(ll _) {
	vll a(3);
	cin>>a[0]>>a[1]>>a[2];
	sort(all(a));
	cin>>k;
	cout<<(a[0]+a[1]+((ll)pow(2,k))*a[2]);
}

int main() {
	fastio;randomINT;
	//cin>>T;
	for(ll i=1;i<=T;i++) {
		MAIN(i);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int i,j,k;
int a,b,c,flag[304],n;
typedef struct result{
	int x,y,z,r;
}RESULT;
RESULT w[1005];

int main(){
	scanf("%d %d %d",&a,&b,&c);
	while(a!=0 && b!=0 && c!=0){
		for(i=1;i<=a+b+c;i++)flag[i]=2;
		scanf("\n%d",&n);
		for(i=1;i<=n;i++){
			scanf("%d %d %d %d",&(w+i)->x,&(w+i)->y,&(w+i)->z,&(w+i)->r);
			if((w+i)->r==1){
				flag[(w+i)->x]=1;
				flag[(w+i)->y]=1;
				flag[(w+i)->z]=1;
			}
		}
		
		for(i=1;i<=n;i++){
			if((w+i)->r==0){
				if(flag[(w+i)->x]==1 && flag[(w+i)->y]==1)flag[(w+i)->z]=0;
				if(flag[(w+i)->y]==1 && flag[(w+i)->z]==1)flag[(w+i)->x]=0;
				if(flag[(w+i)->z]==1 && flag[(w+i)->x]==1)flag[(w+i)->y]=0;
			}
		}
		for(i=1;i<=a+b+c;i++)printf("%d\n",flag[i]);
		
		scanf("%d %d %d",&a,&b,&c);
	}
	return 0;
}