```/* F07CE_T1W_F C++ Header Example Program.
*
* Copyright 2019 Numerical Algorithms Group.
* Mark 27, 2019.
*/

#include <dco_light.hpp>
#include <nag.h>
#include <nagx04.h>
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;

int main(void)
{
int       exit_status = 0;
Integer   nrhs = 1, ifail = 0;
NagError  fail;
INIT_FAIL(fail);

cout << "F07CE_T1W_F C++ Header Example Program Results\n\n";
// Skip heading in data file
string mystr;
getline (cin, mystr);

// Read problem size and number of right-hand-sides
Integer n;
cin >> n;
cin >> nrhs;

// Allocate arrays containing A and its factorized form, B
// and the solution X.
nagad_t1w_w_rtype *dl=0, *d=0, *du=0, *du2=0, *b=0;
double            *sol=0, *dxdu=0, *dxdd=0, *dxdl=0, *dxdb=0;
Integer           *ipiv = 0;
Integer           n1 = n-1, n2 = n-2;
ipiv = new Integer           [n];
sol  = new double            [n*n];
dxdu = new double            [n*n1];
dxdd = new double            [n*n];
dxdl = new double            [n*n1];
dxdb = new double            [n*n];

// Read the tridiagonal matrix A and right hand side B, register and copy
double dd;
for (int i = 0; i<n1; i++) {
cin >> dd;
du[i] = dd;
}
for (int i = 0; i<n; i++) {
cin >> dd;
d[i] = dd;
}
for (int i = 0; i<n1; i++) {
cin >> dd;
dl[i] = dd;
}
for (int i = 0; i<n; i++) {
for (int j = 0; j<nrhs; j++) {
cin >> dd;
int k = i + j*n;
b[k] = dd;
}
}

// Create AD configuration data object
ifail = 0;

double inc = 1.0, zero = 0.0;
for (int i=0; i<4*n-2; ++i) {
int k = i;
if (i<n1) {
} else if (i<n+n1) {
k = i - n1;
} else if (i<n+n1+n1) {
k = i - n - n1;
} else {
k = i - n - n1 - n1;
}
for (int j=0; j<n1; ++j) {
dlf[j] = dl[j];
df[j]  = d[j];
duf[j] = du[j];
x[j]   = b[j];
}
df[n1] = d[n1]; x[n1] = b[n1];
// Factorize the tridiagonal matrix A
ifail = 0;

// Solve the equations Ax = b for x
ifail = 0;

if (i==0) {
// Print primal solution
for (int j=0; j<n*nrhs; ++j) {
}
cout << "\n\n";
x04cac(Nag_ColMajor,Nag_GeneralMatrix,Nag_NonUnitDiag,n,nrhs,sol,n,
"  Solution",0,&fail);
}
if (i<n1) {
for (int j=0; j<n; ++j) {
}
} else if (i<n+n1) {
for (int j=0; j<n; ++j) {
}
} else if (i<n+n1+n1) {
for (int j=0; j<n; ++j) {
}
} else {
for (int j=0; j<n; ++j) {
}
}
}
cout << "\n\n Derivatives calculated: First order tangents\n";
cout << " Computational mode    : algorithmic\n";
cout << "\n Derivatives of first solution column w.r.t. inputs:\n";

cout << "\n";
x04cac(Nag_ColMajor,Nag_GeneralMatrix,Nag_NonUnitDiag,n,n1,dxdu,n,
"  d(du(i))/dx(j)",0,&fail);
cout << "\n";
x04cac(Nag_ColMajor,Nag_GeneralMatrix,Nag_NonUnitDiag,n,n,dxdd,n,
"  d(d(i))/dx(j)",0,&fail);
cout << "\n";
x04cac(Nag_ColMajor,Nag_GeneralMatrix,Nag_NonUnitDiag,n,n1,dxdl,n,
"  d(dl(i))/dx(j)",0,&fail);
cout << "\n";
x04cac(Nag_ColMajor,Nag_GeneralMatrix,Nag_NonUnitDiag,n,n,dxdb,n,
"  d(b(i))/dx(j)",0,&fail);

// Remove computational data object
ifail = 0;

delete [] dl;
delete [] d;
delete [] du;
delete [] du2;
delete [] dlf;
delete [] df;
delete [] duf;
delete [] b;
delete [] ipiv;
delete [] x;
delete [] sol;
delete [] dxdu;
delete [] dxdd;
delete [] dxdl;
delete [] dxdb;
return exit_status;
}
```