import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

int color (int[] c1, int[] c2) {
  return (c1[0] - c2[0])^^2 + (c1[1] - c2[1])^^2 + (c1[2] - c2[2])^^2;
}

void main()
{
  while (1) {
    if (!readln.chomp.to!int) break;
    auto x = readln.chomp.split.map!(to!int).array;
    auto num = 32;
    int turn;
    bool ply;
    while (num > 0) {
      if (ply) {
        num -= x[turn++%x.length];
      } else {
        num -= (num - 1) % 5;
      }
      if (num < 0) num = 0;
      num.writeln;
      ply = !ply;
    } 
  }
}