We consider a notion of relative homology (and cohomology) for surfaces with two types of boundaries. Using this tool, we study a generalization of Kitaevs code based on surfaces with mixed boundaries. This construction includes both Bravyi and Kitaevs and Freedman and Meyers extension of Kitaevs toric code. We argue that our generalization offers a denser storage of quantum information. In a planar architecture, we obtain a three-fold overhead reduction over the standard architecture consisting of a punctured square lattice.