function [res,V]= mod5ss(X,param);
%
%FOC3SS contains the first order conditions for model 3.

%       Ellen McGrattan, 4-10-09
%       Revised, ERM, 8-20-09

kt      = X(1);
ki      = X(2);
c       = X(3);
xt      = X(4);
beta    = param(1);
delt    = param(2);
deli    = param(3);
gn      = param(4);
gz      = param(5);
psi     = param(6);
thet1   = param(7);
alph1   = param(8);
thet2   = param(9);
alph2   = param(10);
chi     = param(11);
tauc    = param(12);
tauh    = param(13);
taux    = param(14);
tauk    = param(15);
taup    = param(16);
tauu    = param(17);
taud    = param(18);
z1      = param(19);
z2      = param(20);
g       = param(21);
yn      = param(22);
xn      = param(23);
hn      = param(24);
grate   = (1+gz)*(1+gn);
beth    = beta/(1+gz);
lshare1 = 1-thet1-alph1;
lshare2 = 1-thet2-alph2;
taxc    = 1.+tauc;
taxx    = 1.+taux;
taxd    = 1.-taud;
taxh    = 1.-tauh;
taxp    = 1.-taup;
chifac  = (1.-chi)*(1.-tauh)+chi*taxd*(1.-taup);

y       = c+xt+g+xn-yn;
coef1   = psi*taxc*c/(taxh*lshare1*y);
coef2   = thet1*lshare2/(thet2*lshare1);
coef3   = ki^alph1*z1^lshare1;
h1      = .1;
for i=1:10;
  h       = 1.-coef1*h1;
  h2      = h-h1-hn;
  k1t     = coef2*h1*kt/(h2+coef2*h1);
  dh      = -(1.-h)/h1;
  dh1     = 1;
  dh2     = dh-dh1;
  dk1t    = k1t*(1.-k1t/kt)*(dh1/h1-dh2/h2);
  yrhs    = coef3*k1t^thet1*h1^lshare1;
  res     = y-yrhs;
  dres    = -yrhs*(thet1*dk1t/k1t+lshare1/h1);
  h1      = h1-res/dres;
end;

h       = 1.-coef1*h1;
h2      = h-h1-hn;
k1t     = coef2*h1*kt/(h2+coef2*h1);
k2t     = kt-k1t;
wage    = lshare1*y/h1;
qxi     = wage*h2/lshare2;
xi      = k2t^thet2*ki^alph2*(z2*h2)^lshare2;
q       = qxi/xi;
rt      = thet1*y/k1t;
ri      = (alph1*y+alph2*qxi)/ki;
w       = lshare1*y/h1;

res     = [(grate-1+delt)*kt-xt;
           (grate-1+deli)*ki-xi;
           beth*(taxp*(rt-tauk)+(1-delt)*taxx+delt*taup+tauu)-taxx-tauu;
           beth*(taxd*taxp*ri+(1-deli)*q*chifac)-q*chifac];

V       = [k2t;h2;y;qxi;xi;c;h;xt;k1t;h1;w;rt;ri];

