#include "num.h"

class Num {
 public:
    Num(int value, int modulo) : value(value), modulo(modulo) {
        if (modulo != 0)
            this->value = value % modulo;
    }
    Num& operator=(const Num& other) {
        this->value = other.value;
        this->modulo = other.modulo;
        return *this;
    }
    Num operator+(const Num& other) {
        Num n(this->value, this->modulo);
        n += other;
        return n;
    }
    Num operator-(const Num& other) {
        Num n(this->value, this->modulo);
        n -= other;
        return n;
    }
    Num operator*(const Num& other) {
        Num n(this->value, this->modulo);
        n *= other;
        return n;
    }
    Num operator+(int num) {
        Num n(this->value, this->modulo);
        n += num;
        return n;
    }
    Num operator-(int num) {
        Num n(this->value, this->modulo);
        n -= num;
        return n;
    }
    Num operator*(int num) {
        Num n(this->value, this->modulo);
        n *= num;
        return n;
    }
    Num& operator+=(const Num& other) {
        this->value = (this->value + other.value) % this->modulo;
        return *this;
    }  
    Num& operator-=(const Num& other) {
        this->value = (this->value - other.value) % this->modulo;
        return *this;
    }
    Num& operator*=(const Num& other) {
        this->value = (this->value * other.value) % this->modulo;
        return *this;
    }
    Num& operator+=(int num) {
        this->value = (this->value + num) % this->modulo;
        return *this;
    }
    Num& operator-=(int num) {
        this->value = (this->value - num) % this->modulo;
        return *this;
    }
    Num& operator*=(int num) {
        this->value = (this->value * num) % this->modulo;
        return *this;
    }
    int value;
    int modulo;
};