#include <iostream>
#include <queue>

using namespace std;

struct C {
    int n;
    C() {}
    C(int n) : n(n) {}
    int x() {
        return (n % 5 == 1 ? 5 : 2);
    }
    int time() {
        return 17 * (n % 2) + 3 * (n % 3) + 19;
    }
    int arrival() {
        return n * 5;
    }
};

#define INF (1000000)

int T[100];
int S[17];

bool isEmpty(int t, int x) { // is there x consecutive empty seat after t minutes later
    for (int i = 0; i < 17 - x + 1; i++) {
        bool xEmpty = true;
        for (int j = 0; j < x; j++) {
            if (S[i+j] > t) {
                xEmpty = false;
                break;
            }
        }
        if (xEmpty) {
            return true;
        }
    }
    return false;
}

void fillSeat(int t, C c) {
    int x = c.x();
    for (int i = 0; i < 17 - x + 1; i++) {
        bool xEmpty = true;
        for (int j = 0; j < x; j++) {
            if (S[i+j] > t) {
                xEmpty = false;
                break;
            }
        }
        if (xEmpty) {
            for (int j = 0; j < x; j++) {
                S[i+j] = t + c.time();
            }
            return;
        }
    }
    cerr << "Something wrong." << endl;
}

int seat(C c) {
    int lb = -1, ub = INF;
    while (lb + 1 != ub) {
        int mid = (lb + ub) / 2;
        if (isEmpty(mid, c.x())) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    //cout << c.n << " " << ub << endl;
    //for (int i = 0; i < 17; i++) cout << S[i] << ' '; cout << endl;
    int t = max(c.arrival(), ub);
    fillSeat(t, c);
    return t;
}

void init() {
    queue<C> q;
    for (int i = 0; i < 100; i++) {
        q.push(C(i));
    }
    while (!q.empty()) {
        C c = q.front(); q.pop();
        T[c.n] = seat(c);
        if (c.x() == 5) {
            // dirty hack
            for (int i = 0; i < 17; i++) {
                S[i] = max(S[i], T[c.n]);
            }
        }
    }
}

int main() {
    int n;
    init();
    while (cin >> n) {
        cout << T[n] - C(n).arrival() << endl;
    }
    return 0;
}