\begin{tikzpicture}[scale=0.66,auto]

\pgfmathsetmacro{\lastzeroindex}{0}

% Space between nodes
\pgfmathsetmacro{\spacingx}{1.3}
% Amount even boxes are raised
\pgfmathsetmacro{\offsety}{0.8}

\pgfmathsetmacro{\totalheight}{4 + \offsety} % Height of one sub-picture.

% Lines
\foreach \x in {0, ..., 7}
  \draw[edge] (\spacingx * \x, 0) -- (\spacingx * \x, \totalheight);

% Even zero nodes
\foreach \x in {0, ..., \lastzeroindex}
{
  \draw[red box]  (2 * \spacingx * \x - .5, 2 + \offsety) rectangle +(1,1);
  \draw (2 * \spacingx * \x, 2.5 + \offsety) node {$0$};
}

% Even one nodes
\pgfmathsetmacro{\firstoneindex}{\lastzeroindex+1}
\foreach \x in {\firstoneindex, ..., 3}
{
  \draw[blue box] (2 * \spacingx * \x - .5, 2 + \offsety) rectangle +(1,1);
  \draw (2 * \spacingx * \x, 2.5 + \offsety) node {$1$};
}

% Odd zero nodes
\foreach \x in {0, ..., 0}
{
  \draw[red box]  (\spacingx + 2 * \spacingx * \x - .5, 2) rectangle +(1,1);
  \draw (\spacingx + 2 * \spacingx * \x, 2.5) node {$0$};
}

% Odd one nodes
\foreach \x in {1, ..., 3}
{
  \draw[blue box] (\spacingx + 2 * \spacingx * \x - .5, 2) rectangle +(1,1);
  \draw (\spacingx + 2 * \spacingx * \x, 2.5) node {$1$};
}

% Comparators
\foreach \x in {0, ..., 2}
  \draw[comp] (    \spacingx + 2 * \spacingx * \x, 1) node[vertex] {}
           -- (2 * \spacingx + 2 * \spacingx * \x, 1) node[vertex] {};

\end{tikzpicture}
