using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct Customer
    {
        internal int nums, wait, arrival, stay;
    }

    class Problem
    {
        readonly int n = 100;

        Customer[] cs;
        Queue<int> waiting;
        int[] seats;
        int time, minStay;

        public Problem()
        {
            cs = new Customer[n];
            waiting = new Queue<int>();
            seats = Enumerable.Repeat(-1, 17).ToArray();
            time = 0;
            minStay = int.MaxValue;
        }

        public int SearchWaitTime(int id)
        {
            return cs[id].wait;
        }

        public void MakeMap()
        {
            for (int i = 0; i < n; i++)
            {
                Customer temp;
                temp.nums = (i % 5 == 1) ? 5 : 2;
                temp.wait = 0;
                temp.arrival = time;
                temp.stay = 17 * (i % 2) + 3 * (i % 3) + 19;
                cs[i] = temp;

                int seatIdx = CheckSeat(i, true);

                if (seatIdx != -1)
                {
                    SetSeat(i, seatIdx);
                }
                else
                {
                    waiting.Enqueue(i);
                }

                for (int j = 0; j < 5; j++)
                {
                    CheckLeave();
                }
            }

            while (waiting.Count > 0)
            {
                CheckLeave();
            }
        }

        private void CheckLeave()
        {
            if (time == minStay)
            {
                int tempMin = int.MaxValue;

                for (int k = 0; k < seats.Length; k++)
                {
                    if (seats[k] == -1) continue;

                    if (seats[k] == minStay)
                    {
                        seats[k] = -1;
                    }
                    else
                    {
                        tempMin = Math.Min(tempMin, seats[k]);
                    }
                }
                minStay = tempMin;

                CheckWait();
            }
            time++;
        }

        private void CheckWait()
        {
            while (waiting.Count > 0)
            {
                int tempId = waiting.Peek();
                int tempSt = CheckSeat(tempId, false);

                if (tempSt != -1)
                {
                    SetSeat(tempId, tempSt);

                    cs[tempId].wait = time - cs[tempId].arrival;
                    waiting.Dequeue();
                }
                else return;
            }
        }

        private void SetSeat(int id, int idx)
        {
            int temp = cs[id].stay + time;

            for (int i = 0; i < cs[id].nums; i++)
            {
                seats[idx + i] = temp;
            }
            minStay = Math.Min(minStay, temp);
        }

        private int CheckSeat(int id, bool isArrival)
        {
            if (isArrival && waiting.Count > 0) return -1;

            int num = cs[id].nums;
            int len = seats.Length - num;

            for (int i = 0; i <= len; i++)
            {
                bool isOpen = true;

                for (int j = 0; j < num; j++)
                {
                    if (seats[i + j] != -1) isOpen = false;
                }
                if (isOpen) return i;
            }
            return -1;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            Problem p = new Problem();
            p.MakeMap();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                int n = int.Parse(input);

                sb.AppendLine(p.SearchWaitTime(n).ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 10440