#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  100001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}
//void ret_digit(int a){rep(i, count_digit(a)){Dig[i]=a%10;a/=10;}}

int main(void)
{

    int t;
    int n[max], a[max], b[max], c[max], d[max];
    
    scanf("%d", &t);
    rep(i, t){
        scanf("%d%d%d%d%d", &n[i], &a[i], &b[i], &c[i], &d[i]);
    }
    
    rep(i, t){
        int cnt=1, ans=0, flag=0;
        int tmp =
        ans += d[i];
        rep(j, t){
            cnt++;
            ans+=d[i];
            if (cnt==t/5&&ans>=cnt*c[i]) {
                break;
                flag++;
            } else if (cnt==t/3&&ans>=cnt*b[i]) {
                break;
                flag++;
            } else if (cnt==t/2&&ans>=cnt*a[i]) {
                break;
                flag++;
            }
        }
        if (flag==0) {
            printf("%d", ans);
        }
    }
    printf("%d", t);
    return 0;
}
