\documentclass[final,12pt]{article}
\usepackage{a4wide}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage[polish,english]{babel}
\selectlanguage{english}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[pdftex]{graphicx}
\usepackage[pdftex]{color}
\usepackage[final]{listings}


%%%%%%%%%%%%% listings
\lstdefinelanguage{whileprograms}{morekeywords={while,do,if,then,else,=),(,decr,in,wrt},%
   sensitive,%
   morecomment=[l]//,%
   morecomment=[s]{\{}{\}},%
   morecomment=[s]{[}{]},%
    basicstyle=\small\tt,
    keywordstyle=\normalfont\bfseries\color{black},
    commentstyle=\color{blue},
    mathescape=true,
}

\lstset{language=whileprograms,flexiblecolumns=true,mathescape=true,frame=none}
\lstset{commentstyle=\it,basicstyle=\tt}
\lstset{literate={<=}{{$\leq$}}2
                 {>=}{{$\geq$}}2
                 {&}{{$\land$}}2}


\usepackage[final]{listings}

\pagestyle{empty}

\begin{document}
\lstset{language=whileprograms} \selectlanguage{polish}

\begin{lstlisting}
{ $n > 0$ }
i := 1;
{                                                                                        }
kw := 4;
{                                                                                        }
while {$\gamma_1$:                                                                                 }
    kw <= n
  do
  ({                                                                                     }
   i := 2*i;
   {$\alpha_1$:                                                                                    }
   kw := 4*kw
   {                                                                                     }
  )
{$\alpha_2$:                                                                                       }  
r := i;
{                                                                                        }  
dri := kw div2;
{                                                                                        }  
ik := dri div2;
{                                                                                        }  
while {$\gamma_2$:                                                                                 }
     i > 1
  do
  ({                                                                                     }
   i := i div2;
   {$\alpha_3$:                                                                                    }
   ik := (ik div2) div2;
   {                                                                                     }
   dri := dri div2;
   {$\alpha_4$:                                                                                    }
   if (kw - dri - 3*ik)<=  n
   then
      {                                                                                  }
      r := r + i;
      {$\alpha_5$:                                                                                 }
      dri := dri + 2*ik
      {                                                                                  }
   else
      {                                                                                  }   
      kw := kw - dri - 3*ik;
   {                                                                                     }
  )
{                                                                                        }
{ $r^2 \leq n < (r+1)^2$ }
\end{lstlisting}





\end{document}
