%
% DO NOT CHANGE THIS TEMPLATE!
%
% To allow combining the lecture notes from different scribes in a
% simple way all scribes must use the same header.
%
% If you think the template lack a package, then contact the lecturer,
% and we will probably extend the template with your favorite package.
%

\documentclass[12pt,a4paper,twoside]{article}
\usepackage{alg}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}


\begin{document}
\pagestyle{myheadings}
\thispagestyle{plain}

\newcounter{solcounter}
\let\oldthesection\thesection
\renewcommand{\thesection}{\arabic{solcounter}.\oldthesection}
\newcommand{\solbegin}[4] { %
\newcommand{\kattisid}{#1}%
\newcommand{\rubrik}{#2}%
\newcommand{\datum}{#3}%
\newcommand{\skribent}{#4}%
\stepcounter{solcounter}
\setcounter{section}{0}
\thispagestyle{plain}
\markboth{{\kattisid}: \rubrik}{\datum, \skribent}%
\hrule
\begin{center}
\large
\textbf{Solution \arabic{solcounter}: \rubrik}\\
\small
Kattis id: \kattisid
\end{center}
\hbox to \textwidth {
\skribent
\hfill
\datum}
\vspace{2mm}
\hrule
\vspace{5mm}
}

\newenvironment{solution}[4]%
{\solbegin{#1}{#2}{#3}{#4}\noindent\ignorespaces}%
{\cleardoublepage}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{definition}[theorem]{Definition}

% \begin{solution}{hello}{Hello World}{2011-08-31}{Osquarulda Teknolog}
% bla bla
% \end{solution}
%

%%%%% Edit after this row. The above should not need editing. %%%%%

%%%%% Define your own stuff here. %%%%%

\newcommand{\zed}{\mathbb{Z}}
\newcommand{\nat}{\mathbb{N}}
\newcommand{\GF}[1]{\mathrm{GF}_{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{solution}{hello}{Hello World!}{2011-08-31}{Osquarulda Teknolog}
The problem does not have any input and the output should be the
``secret message.''
 
\section{Solution}

The trick is to realize that the secret message is ``Hello World!''
and not to forget \verb+std::endl+ or \verb+\n+ if you are using C++
or C. 

\section{Pseudo code}

Using the \texttt{algorithm}-environment one can typeset pseudo-code
fairly easily with a reasonable result.

\begin{algorithm}[h]
\caption{Hello World solution.\label{alg:hello}}
\alginout{There is no input}
         {The secret message}
\algname{HelloWorld}{}
\begin{algtab}
\algprint "Hello World\textbackslash n"
\end{algtab}
\end{algorithm}


\end{solution}


\begin{solution}{no kattis id}{Nonsense example}{2011-08-31}{Mikael Goldmann}

The proble stresses repetition.

\section{Solution}
There are many things worth repeating.
There are many things worth repeating.
There are many things worth repeating.
There are many things worth repeating.
There are many things worth repeating.

There are many things worth repeating.
There are many things worth repeating.
There are many things worth repeating.
There are many things worth repeating.
There are many things worth repeating.

\begin{definition}
Let $\zed$ denote the integers.
\end{definition}

\begin{definition}
  Let $\mathbb{N} = \{\, n \geq 0 \,\mid\, n\in\zed\,\}$ denote
  the natural numbers.
\end{definition}

\subsection{A Subsection Header}

There are many things worth repeating.
There are many things worth repeating.
There are many things worth repeating.
There are many things worth repeating.
There are many things worth repeating.


\section{Another Section Header}

Repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat.

Repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat,
repeat, repeat, repeat, repeat, repeat, repeat, repeat.


\begin{lemma}
\[
\forall x : x\in\zed \Rightarrow  x^2\in\mathbb{N}
\]
\end{lemma}

\begin{theorem}
\[
\forall x : A(x) \Rightarrow B(X)
\]
\end{theorem}


\section{An Algorithm}

Using the \texttt{algorithm}-environment one can typeset pseudo-code
fairly easily with a reasonable result.

\begin{algorithm}[h]
\caption{An example of the \texttt{algorithm}-environment.\label{alg:ex}}
\alginout{A non-empty set $U=\{u_1,u_2,\dots,u_n\}$ of integers}
         {The largest element and a set $A$, $|A|=\log n$,
          containing the second largest element.  (If $n=1$, then
          $A=\emptyset$).}
\algname{Max2}{$U$}
\begin{algtab}
\algif{$|U|=1$}
        \algreturn $(u_1, \emptyset)$ \\
\algelsif{$|U|=2$}
        \algifthenelse{$u_1>u_2$}{\algreturn $(u_1, \{u_2\})$}
                                 {\algreturn $(u_2, \{u_1\})$}
\algelse
        $(b,B) \leftarrow$
           \algcall{Max2}{$\{u_i\}_{i=1}^{\lfloor n/2\rfloor}$}\\
        $(c,C) \leftarrow$
           \algcall{Max2}{$\{u_i\}_{i=\lfloor n/2\rfloor+1}^{n}$}\\
        \algifthenelse{$b>c$}{\algreturn $(b, \{c\}\cup B)$}
                             {\algreturn $(c, \{b\}\cup C)$}
\algend
\end{algtab}
\end{algorithm}

\end{solution}
\end{document}