//  (C) Porkolab 2003
//
//  A.1.7.
//  Constant memberfunctions 



// file: matrix.h

#ifndef MATRIX_H
#define MATRIX_H

#include <cassert>

template <class T>
class matrix
{
public:
       matrix( int i, int j );
       matrix( const matrix &other);
       ~matrix();
    matrix operator=( const matrix &other);

    int rows() const { return x; }
    int cols() const { return y; }

    T& at( int i, int j);
    T  at( int i, int j) const;
    T& operator()( int i, int j);
    T  operator()( int i, int j) const;

    matrix operator+=( const matrix &other);
    matrix operator+( const matrix &other);

private:
    int  x;
    int  y;
    T   *v;
    void copy( const matrix &other);
    void check( int i, int j) const;
};

template <class T>
matrix<T>::matrix( int i, int j)
{
    x = i;
    y = j;
    v = new T[x*y];
}
template <class T>
matrix<T>::matrix( const matrix &other)
{
    copy( other);
}
template <class T>
matrix<T>::~matrix()
{
    delete [] v;
}
template <class T>
matrix<T> matrix<T>::operator=( const matrix &other)
{
    if ( this != &other )
    {
        delete [] v;
        copy( other);
    }
    return *this;
}
template <class T>
void matrix<T>::copy( const matrix &other)
{
    x = other.x;
    y = other.y;
    v = new T[x*y];
    for ( int i = 0; i < x*y; ++i )
        v[i] = other.v[i];
}
template <class T>
void matrix<T>::check( int i, int j) const
{
    assert( 0 <= i  && i <= x );
    assert( 0 <= j  && j <= y );
}
template <class T>
T& matrix<T>::at( int i, int j)
{
    check(i,j);
    return operator()(i,j);
}
template <class T>
T matrix<T>::at( int i, int j) const
{
    check(i,j);
    return operator()(i,j);
}
template <class T>
T& matrix<T>::operator()( int i, int j)
{
    return v[i*y + j];
}
template <class T>
T matrix<T>::operator() ( int i, int j) const
{
    return v[i*y + j];
}
template <class T>
matrix<T> matrix<T>::operator+=( const matrix &other)
{
    for ( int i = 0; i < x*y; ++i )
        v[i] += other.v[i];
    return *this;
}
template <class T>
matrix<T> matrix<T>::operator+( const matrix &other)
{
    matrix<T> temp( *this );
    temp += other;
    return temp;
}

#endif /* MATRIX_H */



//////////////////////////////////////////////////////


// file: matrixmain.cpp

#include <iostream>
#include "matrix.h"
#include "date.h"

using namespace std;

int main()
{
    date          d(2001,1,1);
    matrix<date>  md(52,7);

    for ( int i = 0; i < md.rows(); ++i )
        for ( int j = 0; j < md.cols(); ++j )
            md( i, j ) = d++;

    int week, day;
    while ( cin >> week >> day )
    {
        cout << md.at( --week, --day ) << endl;
    }
    return 0;
}