An efficient finite-element method (FEM) algorithm for complicated three-dimensional (3D) layered type models has been developed. Its unique feature is that it can handle, with memory requirements within the abilities of a simple PC, arbitrarily shaped 3D elements. This task is achieved by storing only the non-zero coefficients of the sparse FEM system of equations. The algorithm is applied to the solution of the Laplace equation in models with up to 79 layers of trilinear general hexahedron elements. The system of equations is solved with the Gauss-Seidel iterative technique.