import sys
import random
import functools
import re
import itertools
import math
import copy
import bisect
import Queue
from collections import Counter

sys.setrecursionlimit(1000000)

def debug(*_):
    for x in _:
        print >> sys.stderr, x,
    print >> sys.stderr

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    parents = [int(sys.stdin.readline())-1 for i in xrange(n-1)]

    is_leaf = [True] * n
    for x in parents:
        is_leaf[x] = False

    num_leaf_children = [0] * n # number of leaf children of node i

    for (i, x) in enumerate(parents):
        if is_leaf[i+1]:
            num_leaf_children[x] += 1

    if all(is_leaf[i] or num_leaf_children[i] >= 3 for i in xrange(n)):
        print "Yes"
    else:
        print "No"


#include<stdio.h>
#include<stdlib.h>

int main(){
    int n,i,j,k,p,count;
    scanf("%d",&n);
    int child[n][n];
    for(i=0;i<n;i++){
        child[i][0] = 0;
    }

    for(i=1;i<n;i++){
        scanf("%d",&p);
        child[p-1][0]+=1;
        child[p-1][child[p-1][0]] = i;
    }

    p=1;
    for(i=0;i<n;i++){
        count=0;
        if(child[i][0]==0){
            continue;
        }
        if(child[i][0]<3){
            printf("No\n");
            p=0;
            break;
        }
        for(j=1;j<=child[i][0];j++){
            if(child[child[i][j]][0]==0){
                count++;
                if(count==3){
                    break;
                }
            }
        }
        if(j==(child[i][0]+1)){
            printf("No\n");
            p=0;
            break;
        }
    }
    if(p){
        printf("Yes\n");
    }

    // for(i=0;i<n;i++){
    //     free(child[i]);
    // }
}


#include <stdio.h>

int main() {
	static int pp[1024], kk[1024], parent[1024];
	int n, i, node, spruce;

	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d", &pp[i]), pp[i]--;
		parent[pp[i]] = 1;
	}
	for (node = 0; node < n; node++) {
		int node_;

		for (node_ = 0; node_ < n; node_++)
			if (pp[node_] == node && !parent[node_])
				kk[node]++;
	}
	for (i = 0; i < n; i++)
		printf("%d ", kk[i]);
	printf("\n");
	spruce = 1;
	for (node = 0; node < n; node++)
		if (parent[node] && kk[node] < 3) {
			spruce = 0;
			break;
		}
	printf(spruce ? "Yes\n" : "No\n");
	return 0;
}


#include <stdio.h>

int main() {
	static int pp[1024], kk[1024], parent[1024];
	int n, i, node, spruce;

	scanf("%d", &n);
	for (i = 0; i < n - 1; i++) {
		scanf("%d", &pp[i]), pp[i]--;
		parent[pp[i]] = 1;
	}
	for (node = 0; node < n; node++) {
		int node_;

		for (node_ = 0; node_ < n; node_++)
			if (pp[node_] == node && !parent[node_])
				kk[node]++;
	}
	spruce = 1;
	for (node = 0; node < n; node++)
		if (parent[node] && kk[node] < 3) {
			spruce = 0;
			break;
		}
	printf(spruce ? "Yes\n" : "No\n");
	return 0;
}


#include <stdio.h>

int main() {
	static int pp[1024], kk[1024], parent[1024];
	int n, i, node, spruce;

	scanf("%d", &n);
	for (i = 0; i < n - 1; i++) {
		scanf("%d", &pp[i]);
		kk[pp[i]]++;
		parent[pp[i]] = 1;
	}
	for (node = 1; node <= n; node++)
		if (parent[node]) {
			int node_;

			for (node_ = node + 1; node_ <= node + kk[node]; node_++)
				if (parent[node_])
					kk[node]--;
		}
	spruce = 1;
	for (node = 1; node <= n; node++)
		if (parent[node] && kk[node] < 3) {
			spruce = 0;
			break;
		}
	printf(spruce ? "Yes\n" : "No\n");
	return 0;
}


#include <stdio.h>

int main() {
	static int pp[1024], kk[1024], parent[1024];
	int n, i, node, spruce;

	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d", &pp[i]), pp[i]--;
		parent[pp[i]] = 1;
	}
	for (node = 0; node < n; node++) {
		int node_;

		for (node_ = 0; node_ < n; node_++)
			if (pp[node_] == node && !parent[node_])
				kk[node]++;
	}
	spruce = 1;
	for (node = 0; node < n; node++)
		if (parent[node] && kk[node] < 3) {
			spruce = 0;
			break;
		}
	printf(spruce ? "Yes\n" : "No\n");
	return 0;
}


/* Coached by rainboy */
#include <stdio.h>

int main() {
	static int pp[1024], kk[1024], parent[1024];
	int n, i, node, spruce;

	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d", &pp[i]), pp[i]--;
		parent[pp[i]] = 1;
	}
	for (node = 0; node < n; node++) {
		int node_;

		for (node_ = 0; node_ < n; node_++)
			if (pp[node_] == node && !parent[node_])
				kk[node]++;
	}
	spruce = 1;
	for (node = 0; node < n; node++)
		if (parent[node] && kk[node] < 3) {
			spruce = 0;
			break;
		}
	printf(spruce ? "Yes\n" : "No\n");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;
ll MAX = -100000000000;/*1e11*/
ll MIN =  100000000000;

int merge(int A[],int B[],int l,int m,int r)
{
    int count = 0;
    int n1 = m-l+1;
    int n2 = r-m;
    int LA[n1],LB[n2],RA[n1],RB[n2] ;
    for(int i=0;i<n1;i++){LA[i] = A[i+l]; LB[i] = B[i+l];}
    for(int i=0;i<n2;i++){RA[i] = A[i+m+1]; RB[i] = B[i+m+1];}

    int i=0,j=0,k=l;
    while(i<n1&&j<n2)
    {
        if(LA[i]<=RA[j])
        {
            A[k] = LA[i];
            B[k] = LB[i];
            i++;
        }
        else
        {
            count += n1-i;
            A[k] = RA[j];
            B[k] = RB[j];
            j++;
        }
        k++;
    }
    while(i<n1)
    {
        A[k] = LA[i];
        B[k] = LB[i];
        i++;
        k++;
    }
    while(j<n2)
    {
        A[k] = RA[j];
        B[k] = RB[j];
        j++;
        k++;
    }
    return count ;
}

int mergesort(int A[],int B[],int l,int r)
{
    int total = 0;
    if(l<r)
    {
        int m = (r+l)/2;
        total += mergesort(A,B,l,m);
        total += mergesort(A,B,m+1,r);
        total += merge(A,B,l,m,r);
    }
    return total ;
}

typedef struct list{
ll data ;
struct list *prev ;
struct list *next ;
}lkl;

struct list *head[2000] ;
struct list *tail[2000] ;

void add(ll u,ll v)
{
struct list *q ;
q = (lkl*)malloc(sizeof(lkl)) ;
q->data = v ;
q->next = NULL;
if(head[u]==NULL)
{
    head[u] = q;
    tail[u] = q;
}
else
{
    tail[u]->next = q;
    q->prev = tail[u];
    tail[u] = q;
}

}

ll count(ll item)
{
    struct list*i = head[item];
    ll cnt = 1;
    while (i)
    {
        i = i->next;
        cnt++;
    }
    return cnt ;
}

ll markedarray[20000] ;

int main(int argc, char const *argv[])
{
    ll N ;
    scanf("%lld",&N);
    for(ll n=2;n<N+1;n++)
    {
        ll V ;
        scanf("%lld",&V);
        add(V,n);
    }
    int flag=  0;
    for(ll j=1;j<=N;j++)
    {
       markedarray[j] = count(j)-1;
      //  printf(" %lld %lld\n",j,count(j));
    }

    for(ll t=1;t<=N;t++)
    {
        if(markedarray[t]==0)
        {
            continue ;
        }
        else
        {
            struct list *j = head[t] ;
            ll cnt = 0;
            while(j)
            {
             if(markedarray[j->data]==0)
             {
               //  printf(" yo %lld\n",j->data);
                 cnt++;
             }
             j = j->next ;
            }
            if(cnt<3)
            {
                flag = 1;
            }
           // printf("cnt =  %lld\n",cnt);
        }
    }
    if(flag==0)
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0 ; i < n ; i ++){
        node[i] = 0;
    }

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];
        a=0;
        if(node[j] == 0){
            n--;
        }
        else if(node[j]<3){
            printf("No");
            return 0;
        }
        else{
            for(int m = 0; m<j;m++){
                a += node[m];
            }
            if(j == 0){
                a = 0;
            }
            for(int m = 0; m < node[j]; m++){
                if(node[m+a+1] != 0){
                    count--;
                }
            }
            if(count < 3){
                printf("No");
                return 0;
            }
            j++;
            n--;
        }
    }

    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0 ; i < n ; i ++){
        node[i] = 0;
    }

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];
        a=0;
        if(node[j] == 0){
            n--;
        }
        else if(node[j]<3){
            printf("No");
            return 0;
        }
        else{
            for(int m = 0; m<j-1;m++){
                a += node[m];
            }
            if(j == 0){
                a = 0;
            }
            if( j == 1){
                a =1;
            }
            for(int m = 0; m < node[j]; m++){
                if(node[m+a+1] != 0){
                    count--;
                }
            }
            if(count < 3){
                printf("No");
                return 0;
            }
            j++;
            n--;
        }
    }

    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];

        for(a=0; a<node[j]; a++){
            if(node[j+1+a] != 0){
                count--;
            }
            n--;
        }
        if(count < 3){
            printf("No");
            return 0;
        }
        j++;
    }
    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];
        for(int m = 0; m<j;m++){
            a += node[m];
        }
        a--;
        for(int m = 0; m < node[j]; m++){
            if(node[m+a] != 0){
                count--;
            }
            n--;
        }
        if(count < 3){
            printf("No");
            return 0;
        }
        j++;
    }
    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    int tmp = 0;
    scanf("%d",&n);

    for(int i = 0 ; i < 1000 ; i ++){
        node[i] = 0;
    }

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }
    tmp = n;
    while(n > 0){
        count = node[j];
        a=0;
        if(node[j] == 0){

        }
        else if(node[j]<3){
            printf("No");
            return 0;
        }
        else{
            for(int m = 0; m<j;m++){
                a += node[m];
            }

            if(j == 0){
                a = 0;
            }
            for(int m = 0; m < node[j]; m++){
                if(node[m+a+1] != 0){
                    count--;
                }
                if(tmp > 900 && tmp < 1000){
                    printf("Yes");
                    return 0;
                }
            }
            if(count < 3){
                printf("No");
                return 0;
            }
        }
        j++;
        n--;
    }

    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0 ; i < 1000 ; i ++){
        node[i] = 0;
    }

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];
        a=0;
        if(node[j] == 0){

        }
        else if(node[j]<3){
            printf("No1");
            return 0;
        }
        else{
            for(int m = 0; m<j;m++){
                a += node[m];
            }

            if(j == 0){
                a = 0;
            }
            for(int m = 0; m < node[j]; m++){
                if(node[m+a+1] != 0){
                    count--;
                }
            }
            if(count < 3){
                printf("No");
                return 0;
            }
        }
        j++;
        n--;
    }

    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];

        for(a=0; a<node[j]; a++){
            if(node[j+1+a] != 0){
                count--;
            }
            n--;
        }
        if(count < 3){
            printf("No1");
            return 0;
        }

        j++;
    }
    printf("Yes2");
    return 0;
}


#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];

        for(a=0; a<node[j]; a++){
            if(node[j+1+a] != 0){
                count--;
            }
            n--;
        }
        if(count < 3){
            printf("No");
            return 0;
        }
        j++;
    }
    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];
        for(int m = 0; m<j;m++){
            a += node[m];
        }
        if(a != 0){
            a--;
        }
        for(int m = 0; m < node[j]; m++){
            if(node[m+a] != 0){
                count--;
            }
            n--;
        }
        if(count < 3){
            printf("No");
            return 0;
        }
        j++;
    }
    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0 ; i < n ; i ++){
        node[i] = 0;
    }

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];
        a=0;
        if(node[j] == 0){
            n--;
        }
        else if(node[j]<3){
            printf("No");
            return 0;
        }
        else{
            for(int m = 0; m<j;m++){
                a += node[m];
            }
            if(j == 0){
                a = 0;
            }
            if( j == 1){
                a =1;
            }
            for(int m = 0; m < node[j]; m++){
                if(node[m+a+1] != 0){
                    count--;
                }
            }
            if(count < 3){
                printf("No");
                return 0;
            }
            j++;
            n--;
        }
    }

    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n > 0){
        count = node[j];

        for(a=0; a<node[j]; a++){
            if(node[j+1+a] != 0){
                count--;
            }
            n--;
        }
        if(count < 3){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int parents[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    int tmp = 0;
    scanf("%d",&n);
    tmp = n;
    for(int i = 0 ; i < 1000 ; i ++){
        node[i] = 0;
        parents[i] = 0;
    }
    for(int i = 0; i<n-1 ; i++){        //node : 자식 parents[i] : P(i)의 부모노드
        scanf("%d",&a);
        a--;
        node[a]++;
        parents[i] = a;
    }
    parents[0] = 1001;

    while(n > 0){
        count = node[j];
        if(node[j] == 0){

        }
        else if(node[j] <3){
            printf("No");
            return 0;
        }
        else{
            for(int i = 0; i< tmp; i++){
                if(parents[i] == j){
                    if(node[i] != 0){ count--; }
                }
            }
            if(count <3){
                printf("No");
                return 0;
            }
        }
        j++; n--;
    }

    printf("Yes");
    return 0;
}


//
// Created by chan gyu on 2018. 2. 4..
//
/*
B. Christmas Spruce
time limit per test1 second
        memory limit per test256 megabytes
inputstandard input
outputstandard output
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found here.

Input
        The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output
        Print "Yes" if the tree is a spruce and "No" otherwise.

Examples
        input
4
1
1
1
output
        Yes
input
7
1
1
1
2
2
2
output
        No
input
8
1
1
1
1
3
3
3
output
        Yes
*/

#include <stdio.h>

int main(void){
    int n = 0;
    int node[1000];
    int a = 0;
    int j = 0;
    int count = 0;
    scanf("%d",&n);

    for(int i = 0; i<n-1 ; i++){
        scanf("%d",&a);
        a--;
        node[a]++;
    }

    while(n-1 > 0){
        count = node[j];
        for(int m = 0; m<j;m++){
            a += node[m];
        }
        a--;
        for(int m = 0; m < node[j]; m++){
            if(node[m+a] != 0){
                count--;
            }
            n--;
        }
        if(count < 3){
            printf("No");
            return 0;
        }
        j++;
    }
    printf("Yes");
    return 0;
}


#include <bits/stdc++.h>
#include<math.h>
using namespace std;

#define ll long long

vector <ll> v;
vector <ll> vv;
set <ll> st;

ll x,y,z;
string s,s1,s2;

void memset_ll(ll a[], ll v, ll n)
{
    for(ll i=0; i<n; i++)
        a[i]=v;
}
void memset_s(char a[], char v, ll n)
{
    for(ll i=0; i<n; i++)
        a[i]=v;
}

int compare(const void * a, const void * b)
{
    return ( *(ll*)a - *(ll*)b );
}
void q_sort(ll a[], ll n)
{
    qsort(a, n, sizeof(ll), compare);
}

static int compare1 (const void * a, const void * b)
{
    if (*(double*)a > *(double*)b)
        return 1;
    else if (*(double*)a < *(double*)b)
        return -1;
    else
        return 0;
}
void q_sort_d(double a[], ll n)
{
    qsort(a, n, sizeof(double), compare1);
}

ll sum(ll n)
{
    ll i=0,a[6],j,k=0;
    while(n>0)
    {
        a[i]=n%10;
        n/=10;
        i++;
    }
    for(j=0; j<i; j++)
        k+=a[j];
    return k;
}

string trans_upper(string ss)
{
    transform(ss.begin(),ss.end(),ss.begin(), ::toupper);
    return ss;
}

ll power(ll a, ll b)
{
    ll pow = 1;
    while ( b )
    {
        if ( b & 1 )
        {
            pow = pow * a;
            --b;
        }
        a = a*a;
        b = b/2;
    }
    return pow;
}

ll fact(ll n)
{
    ll f=1,i;
    for(i=1; i<=n; i++)
        f=f*i;
    return f;
}

ll is_prime(ll n)
{
    ll i,j,k=1;
    for(i=2; i<=n/2; i++)
    {
        if(n%i==0)
        {
            k=0;
            break;
        }
    }
    return k;
}

int main()
{
    ll t,l,p,q,n,m,o=0,r,i,j,h,k,e=0,d=0,f=0,g=0;
    ll temp=0,nl,np;
    double p1,p2,p3,p4,p5,p6,pp,ppp;

    cin>>n;
    f=-3000;
    for(i=0;i<n;i++)
    {
        cin>>s;
        cin>>p>>q>>x>>y>>z>>d>>e;
        p=p*100;
        q=q*50;
        r=p-q;
        r+=x;r+=y;r+=z;r+=d;r+=e;
        if(r>f)
        {
            f=r;
            s1=s;
        }
    }
    cout<<s1;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define li int64_t
int main(){
  li a;
  cin>>a;
  string s="";
  li maxs=0;
  for(li i=0;i<a;i++){
    li s1=0;
    string h;
    cin>>h;
    li p,m,a1,b1,c1,d1,e1;
    cin>>p>>m>>a1>>b1>>c1>>d1>>e1;
    s1=s1+(p*100);
    s1=s1-(m*50);
    s1+=a1;
    s1+=b1;
    s1+=c1;
    s1+=d1;
    s1+=e1;
    if( s1>maxs) {
        s=h;
        maxs=s1;
    }
  }
  cout<<s;
  }


#include <bits/stdc++.h>

#define ll long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {
	IO;

	int n;
	cin >> n;
	//if (n == 1) {
		//cout << 1;
		//return 0;
	//}
	vector<pair<string, int>> ans(n);

	for (int i = 0; i < n; ++i) {
		string s;
		int sh, uh, a, b, c, d, e;
		cin >> s >> sh >> uh >> a >> b >> c >> d >> e;
		ans[i] = {s, sh*100 + uh*-50 + a+ b+ c+ d+ e};
	}
	pair<string, int> big = {"a", INT_MIN};
	for (int i = 0; i < n; ++i) {
		if (ans[i].second > big.second) {
			big.first = ans[i].first;
			big.second = ans[i].second;
		}
	}

	cout << big.first;

}


#include <bits/stdc++.h>

#define ll long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {
	IO;

	int n;
	cin >> n;
	//if (n == 1) {
		//cout << 1;
		//return 0;
	//}
	vector<pair<string, int>> ans(n);

	for (int i = 0; i < n; ++i) {
		string s;
		int sh, uh, a, b, c, d, e;
		cin >> s >> sh >> uh >> a >> b >> c >> d >> e;
		ans[i] = {s, sh*100 + uh*-50 + a+ b+ c+ d+ e};
	}
	pair<string, int> big = {"a", 0};
	for (int i = 0; i < n; ++i) {
		if (ans[i].second > big.second) {
			big.first = ans[i].first;
			big.second = ans[i].second;
		}
	}

	cout << big.first;

}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int mx = 0;
    string ans;
    for(int i = 0;i < n; i++ )
    {
        string name;
        int p,m,a,b,c,d,e;
        cin >> name >> p >> m >> a >> b >> c >> d >> e;
        int sum = a+b+c+d+e +(p*100) - (m*50);
        if (sum>mx)
        {
            mx = sum;
            ans = name;
        }

    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    long long mx = 0;
    string ans;
    for(int i = 0;i < n; i++ )
    {
        string name;
        int p,m,a,b,c,d,e;
        cin >> name >> p >> m >> a >> b >> c >> d >> e;
        long long sum = a+b+c+d+e +(p*100) - (m*50);
        if (sum>mx)
        {
            mx = sum;
            ans = name;
        }

    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    long long mx = 0;
    string ans;
    for(int i = 0;i < n; i++ )
    {
        string name;
        int p,m,a,b,c,d,e;
        cin >> name >> p >> m >> a >> b >> c >> d >> e;
        long long sum = a+b+c+d+e +(p*100) - (m*50);
        if (sum>mx)
        {
            mx = sum;
            ans = name;
        }
        cout << name;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    long long mx =  INT_MIN;
    string ans;
    for(int i = 0;i < n; i++ )
    {
        string name;
        int p,m,a,b,c,d,e;
        cin >> name >> p >> m >> a >> b >> c >> d >> e;
        long long sum = a+b+c+d+e +(p*100) - (m*50);
        if (sum>mx)
        {
            mx = sum;
            ans = name;
        }

    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
//    freopen("test.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    int n;
    cin>>n;

    string temp;
    int let = -1;

    for(int i=0; i<n; i++)
    {
        string s;
        cin>>s;
        int add,sub,a,b,c,d,e;
        cin>>add>>sub>>a>>b>>c>>d>>e;

        int total = (add*100)-(sub*50)+a+b+c+d+e;

        if(total>let)
        {
            let = total;
            temp = s;
        }
    }

    cout<<temp<<endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    //freopen("test.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;

    string temp;
    int let = -10000000;

    for(int i=0; i<n; i++)
    {
        string s;
        cin>>s;
        int add,sub,a,b,c,d,e;
        cin>>add>>sub>>a>>b>>c>>d>>e;

        int total = (add*100)-(sub*50)+a+b+c+d+e;

        if(total>let)
        {
            let = total;
            temp = s;
        }
    }

    cout<<temp<<endl;

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main ()
{
int n;
cin>>n;
int maxans=-100000000;
string a[n+1];
int b[n+1];
int c[n+1];
int d[n+1],e[n+1],f[n+1],g[n+1],h[n+1];
for (int i=0;i<n;i++){
	int ans=0;
	cin>>a[i];
	cin>>b[i]>>c[i];
	cin>>d[i]>>e[i]>>f[i]>>g[i]>>h[i];
	ans+=(b[i]-c[i])*100;
	ans+=d[i]+e[i]+f[i]+g[i]+h[i];
	maxans=max(maxans,ans);
}
for (int i=0;i<n;i++){
	int ans=0;
	cin>>a[i];
	cin>>b[i]>>c[i];
	cin>>d[i]>>e[i]>>f[i]>>g[i]>>h[i];
	ans+=(b[i]-c[i])*100;
	ans+=d[i]+e[i]+f[i]+g[i]+h[i];
	if (maxans==ans){
		cout<<a[i];
		return 0;
	}
}
}


#include <iostream>
#include <vector>
using namespace std;
int main ()
{
int n;
cin>>n;
int maxans=-1000000000;
string g;
for (int i=0;i<n;i++){
	string s;
	cin>>s;
	int plus,minus,a,b,c,d,e;
	cin>>plus>>minus>>a>>b>>c>>d>>e;
	int temp=plus*100-minus*50+a+b+c+d+e;
	if (temp>maxans){
		maxans=temp;
		g=s;
	}
}
cout<<g;
}


#include <iostream>
#include <vector>
using namespace std;
int main ()
{
int n;
cin>>n;
int maxans=0;
string a[n+1];
int b[n+1];
int c[n+1];
int d[n+1],e[n+1],f[n+1],g[n+1],h[n+1];
for (int i=0;i<n;i++){
	int ans=0;
	cin>>a[i];
	cin>>b[i]>>c[i];
	cin>>d[i]>>e[i]>>f[i]>>g[i]>>h[i];
	ans+=(b[i]-c[i])*100;
	ans+=d[i]+e[i]+f[i]+g[i]+h[i];
	maxans=max(maxans,ans);
}
for (int i=0;i<n;i++){
	int ans=0;
	cin>>a[i];
	cin>>b[i]>>c[i];
	cin>>d[i]>>e[i]>>f[i]>>g[i]>>h[i];
	ans+=(b[i]-c[i])*100;
	ans+=d[i]+e[i]+f[i]+g[i]+h[i];
	if (maxans==ans){
		cout<<a[i];
		return 0;
	}
}
}


#include <iostream>
#include<cstdio>
#include <string>
#include <cstring>
#include<algorithm>
using namespace std;
string str[52];
int problem[52][7];
int sum[52];
int main() {
	int n;
	int label = 0;
	cin >> n;
	memset(sum, 0, sizeof(sum));
	int mm = 0;
	while (n--) {
		cin >> str[label];
		for (int i = 0; i < 7; ++i) {
			cin >> problem[label][i];
			if (i == 0) {
				problem[label][i] = 100 * problem[label][i];
			}
			if (i == 1) {
				problem[label][i] = (-50) * problem[label][i];
			}
			sum[label] += problem[label][i];
		}
		for (int j = 0; j < label; j++) {
			if (sum[mm] < sum[label]) {
				mm = label;
			}
		}
		label++;
	}
	cout << str[mm] << endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define MAXN 200005
#define ll long long
#define GET c=getchar()
#define SHU ('0'<=c&&c<='9')
using namespace std;
int n,m,x,y,z,cnt,sum,num,ans;

int read()
{
	int x=0,f=1;char GET;
	while(!SHU)
	{
		if(c=='-') f=-1;
		GET;
	}
	while(SHU)
	{
		x=x*10+c-'0';
		GET;
	}
	return x*f;
}

int main()
{
	n=read()-1;
	string name;
	cin>>name;
	x=100*read()-50*read()+read()+read()+read()+read()+read();
	while(n--)
	{
		string namee;
		cin>>namee;
		y=100*read()-50*read()+read()+read()+read()+read()+read();
		if(y>x) name=namee,x=y;
	}
	cout<<name;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
const int maxn= 55;
long long n,pl,a[maxn],b[maxn],c[maxn],d[maxn],e[maxn],mi,now,flag=1;
string handle,ans;
int main()
{
	scanf("%lld",&n);
	for(register int i=1;i<=n;i++)
	{
		cin>>handle;
		scanf("%lld%lld%lld%lld%lld%lld%lld",&pl,&mi,&a[i],&b[i],&c[i],&d[i],&e[i]);
		if(flag)now=pl*100-mi*50+a[i]+b[i]+c[i]+d[i]+e[i],ans=handle,flag=0;
		else if(pl*100-mi*50+a[i]+b[i]+c[i]+d[i]+e[i]>now)
		{
			now=pl*100-mi*50+a[i]+b[i]+c[i]+d[i]+e[i];
			ans=handle;
		}
	}
	cout<<ans;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,x,y,a[10],mx=-1,score;
string name,s;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s>>x>>y;
		score=x*100-y*50;
		for(int j=0;j<5;j++){cin>>x;score+=x;}
		if(score>mx){mx=score;name=s;}
	}
	cout<<name<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bits/stdc++.h>
#define ull unsigned long long
#define inf 0x7fffffff
using namespace std;
const int N=55;
struct node
{
    string Name;
    int s,u;
    int Score[6];
    int sum1;
};

node Data[N];

int main()
{
    int n;
    int ans=-inf;
    int pos=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>Data[i].Name;
        scanf("%d%d%d%d%d%d%d",&Data[i].s,&Data[i].u,&Data[i].Score[1],&Data[i].Score[2],&Data[i].Score[3],&Data[i].Score[4],&Data[i].Score[5]);
        Data[i].sum1=Data[i].Score[1]+Data[i].Score[2]+Data[i].Score[3]+Data[i].Score[4]+Data[i].Score[5]+100*Data[i].s-50*Data[i].u;
        if(Data[i].sum1>ans)
        {
            ans=Data[i].sum1;
            pos=i;
        }
    }

    cout<<Data[pos].Name<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ull unsigned long long
#define inf 0x7fffffff
using namespace std;
const int N=55;
struct node
{
    string name;
    int s,u;
    int Score[6];
    int sum1;
};

node Data[N];

int main()
{
    int n;
    int ans=-inf;
    int pos=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>Data[i].name;
        scanf("%d%d%d%d%d%d%d",&Data[i].s,&Data[i].u,&Data[i].Score[1],&Data[i].Score[2],&Data[i].Score[3],&Data[i].Score[4],&Data[i].Score[5]);
        Data[i].sum1=Data[i].Score[1]+Data[i].Score[2]+Data[i].Score[3]+Data[i].Score[4]+Data[i].Score[5]+100*Data[i].s-50*Data[i].u;
        if(Data[i].sum1>ans)
        {
            ans=Data[i].sum1;
            pos=i;
        }
    }

    cout<<Data[pos].name<<endl;
    return 0;
}


#include<stdio.h>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    string winer="";
    int ss=0;
    for(int i=0;i<n;i++)
    {
		string name;
		int p,m,a,b,c,d,e,score;
		cin>>name>>p>>m>>a>>b>>c>>d>>e;
        score=p*100-m*50+a+b+c+d+e;
        if(score>ss)
        {
            ss=score;
            winer=name;
        }
    }
    printf("%s",winer);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ull unsigned long long
#define inf 0x7fffffff
using namespace std;
const int N=55;
struct node
{
    string name;
    int s,u;
    int Score[6];
    int sum;
};

node Data[N];

int main()
{
    int n;
    int ans=-inf;
    int pos=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>Data[i].name;
        scanf("%d%d%d%d%d%d%d",&Data[i].s,&Data[i].u,&Data[i].Score[1],&Data[i].Score[2],&Data[i].Score[3],&Data[i].Score[4],&Data[i].Score[5]);
        Data[i].sum=Data[i].Score[1]+Data[i].Score[2]+Data[i].Score[3]+Data[i].Score[4]+Data[i].Score[5]+100*Data[i].s-50*Data[i].u;
        if(Data[i].sum>ans)
        {
            ans=Data[i].sum;
            pos=i;
        }
    }

    cout<<Data[pos].name<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ull unsigned long long
#define inf 0x7fffffff
using namespace std;
const int N=55;
struct node
{
    string name;
    int s,u;
    int score[6];
    int sum;
};

node Data[N];

int main()
{
    int n;
    int ans=-inf;
    int pos=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>Data[i].name;
        scanf("%d%d%d%d%d%d%d",&Data[i].s,&Data[i].u,&Data[i].score[1],&Data[i].score[2],&Data[i].score[3],&Data[i].score[4],&Data[i].score[5]);
        Data[i].sum=Data[i].score[1]+Data[i].score[2]+Data[i].score[3]+Data[i].score[4]+Data[i].score[5]+100*Data[i].s-50*Data[i].u;
        if(Data[i].sum>ans)
        {
            ans=Data[i].sum;
            pos=i;
        }
    }

    cout<<Data[pos].name<<endl;
    return 0;
}


#include<stdio.h>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    string winer="";
	int ss=-2999;
    for(int i=0;i<n;i++)
    {
		string name;
		int p,m,a,b,c,d,e,score;
		cin>>name>>p>>m>>a>>b>>c>>d>>e;
        score=p*100-m*50+a+b+c+d+e;
        if(score>ss)
        {
            ss=score;
            winer=name;
        }
    }
	cout<<winer;
}


#include <bits/stdc++.h>
#define start ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define pf push_front
#define in insert
#define ff first
#define ss second
#define finish return 0
#define mp make_pair
#define ll long long int
#define ld long double
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define pi acos(-1)
#define C continue
#define B break
#define N '\n'
#define al(v) v.begin(),v.end()
#define srt(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define loop(i,a,n) for(ll i=a;i<n;i++)
using namespace std;
int main()
{
    start;
    ll q;
    ll i,j,k,sum=0,a,b,c,d,e,n,count=0,count1=0,sum1=0,l=0,h,uh;
    cin >> n;
    string s;
    vector<pair<ll,string>>v;
    ll ar[n];
    for(i=0;i<n;i++){
        cin >> s >> h >> uh >> a >> b >> c >> d >> e;
        sum=h*100-uh*50+a+b+c+d+e;
        v.pb({sum,s});
    }
    sort(v.begin(),v.end());
    cout << v[v.size()-1].second << N;

    finish;
}


#include <bits/stdc++.h>
#define start ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define pf push_front
#define in insert
#define ff first
#define ss second
#define finish return 0
#define mp make_pair
#define ll long long int
#define ld long double
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define pi acos(-1)
#define C continue
#define B break
#define N '\n'
#define al(v) v.begin(),v.end()
#define srt(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define loop(i,a,n) for(ll i=a;i<n;i++)
using namespace std;
int main()
{
    start;
    ll q;
    ll i,j,k,sum=0,a,b,c,d,e,n,count=0,count1=0,sum1=0,l=0,h,uh;
    cin >> n;
    string s;
    map<ll,string>m;
    ll ar[n];
    for(i=0;i<n;i++){
        cin >> s >> h >> uh >> a >> b >> c >> d >> e;
        sum=h*100-uh*50+a+b+c+d+e;
        l=max(l,sum);
        m[sum]=s;
    }
    cout << m[l] << N;

    finish;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  string final;
  ll max=-1000000000;
  int n,sh,uh,pb;
  cin>>n;
  while(n--)
  {
    string s;
    cin>>s;
    int k=0;
    cin>>sh;
    k+=sh*100;
    cin>>uh;
    k-=uh*50;
    for(int i=0;i<5;i++)
    {
      cin>>pb;
      k=k+pb;
    }
    if(max<k)
    {
      max=k;
      final=s;
    }
  }
  cout<<final<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  string final;
  int max=0;
  int n,sh,uh,pb;
  cin>>n;
  while(n--)
  {
    string s;
    cin>>s;
    int k=0;
    cin>>sh;
    k+=sh*100;
    cin>>uh;
    k-=uh*50;
    for(int i=0;i<5;i++)
    {
      cin>>pb;
      k=k+pb;
    }
    if(max<k)
    {
      max=k;
      final=s;
    }
  }
  cout<<final<<endl;
}


#include <iostream>
#include<cmath>
using namespace std;

int main()
{
int number,sum=0,ma=-999999999;
cin>>number;
string str[number],s="";
int arr[number][7];
for(int i=0;i<number;i++)
{
    cin>>str[i];
    for(int j=0;j<7;j++)
    {
        //cout<<"enter number"<<endl;
    cin>>arr[i][j];
    if(j==0){
        sum+=arr[i][j]*100;
    }
    else if(j==1){
        sum-=arr[i][j]*50;
    }
    else
        sum+=arr[i][j];
    }
if(sum>=ma){
    ma=sum;
    s=str[i];
}

sum=0;
}
cout<<s;
    return 0;
}


#include <iostream>
#include<cmath>
using namespace std;

int main()
{
int number,sum=0,ma=-9999999992
minus_one 0 4 199 0 0 0 0
minus_two 0 4 198 0 0 0 0;
cin>>number;
string str[number],s="";
int arr[number][7];
for(int i=0;i<number;i++)
{
    cin>>str[i];
    for(int j=0;j<7;j++)
    {
        //cout<<"enter number"<<endl;
    cin>>arr[i][j];
    if(j==0){
        sum+=arr[i][j]*100;
    }
    else if(j==1){
        sum-=arr[i][j]*50;
    }
    else
        sum+=arr[i][j];
    }
if(sum>=ma){
    ma=sum;
    s=str[i];
}

sum=0;
}
cout<<s;
    return 0;
}


#include <iostream>
#include<cmath>
using namespace std;

int main()
{
int number,sum=0,ma=0;
cin>>number;
string str[number],s="";
int arr[number][7];
for(int i=0;i<number;i++)
{
    cin>>str[i];
    for(int j=0;j<7;j++)
    {
        //cout<<"enter number"<<endl;
    cin>>arr[i][j];
    if(j==0){
        sum+=arr[i][j]*100;
    }
    else if(j==1){
        sum-=arr[i][j]*50;
    }
    else
        sum+=arr[i][j];
    }
if(sum>ma){
    ma=sum;
    s=str[i];
}
sum=0;
}
cout<<s;
    return 0;
}


#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	map <string, int> z;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		int p, m, a, b, c, d, e;
		cin >> p >> m >> a >> b >> c >> d >> e;
		z.insert(make_pair(s, p * 100 - m * 50 + a + b + c + d + e));
	}
	sort(z.begin(), z.end());
	cout << z.end()->second;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct participant {
	string nick;
	int score;
};
bool comp(participant a, participant b) {
	if (a.score < b.score) return true;
	else return false;
}
int main() {
	int n;
	string s;
	cin >> n;
	int p, m, a, b, c, d, e;
	vector <participant> z;
	for (int i = 0; i < n; i++) {
		cin >> s;
		cin >> p >> m >> a >> b >> c >> d >> e;
		participant y; y.nick = s; y.score = p * 100 - m * 50 + a + b + c + d + e;
		z.push_back(y);
	}
	sort(z.begin(), z.end(), comp);
	cout << z[n - 1].nick;
	return 0;
}


/*
* Fox
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<algorithm>
#include<string>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
int main()
{
    Omar_Hafez
    int n; cin >> n;
    string hand;
    int pls, mins, a, b, c, d, e, res = 0, maxx = 0;
    string name;
    for (int i = 0; i < n; i++)
    {
        res = 0;
        cin >> hand >> pls >> mins >> a >> b >> c >> d >> e;
        res = ((pls*100) - (mins * 50) + a + b + c + d + e) ;
        if (res > maxx)
        {
            maxx = res;
            name = hand;
        }
    }
    cout << name << "\n";
return 0;
}


/*
* Fox
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<algorithm>
#include<string>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
int main()
{
    Omar_Hafez
    int n; cin >> n;
    string hand;
    ll pls, mins, a, b, c, d, e, res = 0, maxx = 0;
    string name;
    for (int i = 0; i < n; i++)
    {
        res = 0;
        cin >> hand >> pls >> mins >> a >> b >> c >> d >> e;
        res = ((pls*100)  + a + b + c + d + e) ;
        res -= (mins * 50);
        if (res > maxx)
        {
            maxx = res;
            name = hand;
        }
    }
    cout << name << "\n";
return 0;
}


/*
* Fox
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<algorithm>
#include<string>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
int main()
{
    Omar_Hafez
    int n; cin >> n;
    string hand;
    ll pls, mins, a, b, c, d, e, res = 0, maxx = LONG_MIN;
    string name;
    for (int i = 0; i < n; i++)
    {
        res = 0;
        cin >> hand >> pls >> mins >> a >> b >> c >> d >> e;
        res = ((pls*100)  + a + b + c + d + e) ;
        res -= (mins * 50);
        if (res > maxx)
        {
            maxx = res;
            name = hand;
        }
    }
    cout << name << "\n";
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>> n;

    int max;
    string str;

    for(int i=0; i<n; i++) {
        string s;
        cin>> s;
        int p, q, a, b, c, d, e;
        cin>> p >> q >> a >> b >> c >> d >> e;
        int sum= p*100-q*50+a+b+c+d+e;
        if(i==0) {
            max= sum;
            str= s;
        }
        else if(sum > max) {
            max= sum;
            str= s;
        }
    }
    cout<< str << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>> n;

    int max= -55;
    string str;

    for(int i=0; i<n; i++) {
        string s;
        cin>> s;
        int p, q, a, b, c, d, e;
        cin>> p >> q >> a >> b >> c >> d >> e;
        int sum= p-q+a+b+c+d+e;
        if(sum > max) {
            max= sum;
            str= s;
        }
    }
    cout<< str << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>> n;

    int max= -55;
    string str;

    for(int i=0; i<n; i++) {
        string s;
        cin>> s;
        int p, q, a, b, c, d, e;
        cin>> p >> q >> a >> b >> c >> d >> e;
        int sum= p*100-q*50+a+b+c+d+e;
        if(sum > max) {
            max= sum;
            str= s;
        }
    }
    cout<< str << endl;
    return 0;
}


/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<ll> vec;
#define inf LLONG_MAX
#define bp __builtin_popcountll
#define pb push_back
#define ff first
#define ss second
#define P pair<ll,ll>
#define N 300001
#define ALL(a) a.begin(),a.end()
#define LG 20
#define int ll
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void query()
{

    ll n;
    cin>>n;

    string s;
    ll ans=0;

    for(int i=1;i<=n;i++)
    {
        string p;
        cin>>p;

        ll tt=0;

        ll y;
        cin>>y;

        y*=100;
        ll z;
        cin>>z;

        z*=(-50);

        for(int j=1;j<=5;j++)
        {
            ll h;
            cin>>h;
            tt+=h;
        }

        tt+=y;
        tt+=z;

        if(tt>ans)
        {
            ans=tt;
            s=p;
        }
    }

    cout<<s<<"\n";

}

int32_t main()
{

    FAST;

    int t=1;
    // cin>>t;

    while(t--)
    {
        query();
    }

}


/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<ll> vec;
#define inf LLONG_MAX
#define bp __builtin_popcountll
#define pb push_back
#define ff first
#define ss second
#define P pair<ll,ll>
#define N 300001
#define ALL(a) a.begin(),a.end()
#define LG 20
#define int ll
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void query()
{

    ll n;
    cin>>n;

    string s;
    ll ans=0;

    for(int i=1;i<=n;i++)
    {
        string p;
        cin>>p;

        ll tt=0;

        ll y;
        cin>>y;

        y*=100;
        ll z;
        cin>>z;

        z*=(-50);

        for(int j=1;j<=5;j++)
        {
            ll h;
            cin>>h;
            tt+=h;
        }

        tt+=y;
        tt+=z;

        if(tt>=ans)
        {
            ans=tt;
            s=p;
        }

    }

    cout<<s<<"\n";

}

int32_t main()
{

    FAST;

    int t=1;
    // cin>>t;

    while(t--)
    {
        query();
    }

}


/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<ll> vec;
#define inf LLONG_MAX
#define bp __builtin_popcountll
#define pb push_back
#define ff first
#define ss second
#define P pair<ll,ll>
#define N 300001
#define ALL(a) a.begin(),a.end()
#define LG 20
#define int ll
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void query()
{

    ll n;
    cin>>n;

    string s;
    ll ans=0;

    for(int i=1;i<=n;i++)
    {
        string p;
        cin>>p;

        ll tt=0;

        ll y;
        cin>>y;

        y*=100;
        ll z;
        cin>>z;

        z*=(-50);

        for(int j=1;j<=5;j++)
        {
            ll h;
            cin>>h;
            tt+=h;
        }

        tt+=y;
        tt+=z;

        if(tt>=ans)
        {
            ans=tt;
            s=p;
        }

        cout<<tt<<"\n";
    }

    cout<<s<<"\n";

}

int32_t main()
{

    FAST;

    int t=1;
    // cin>>t;

    while(t--)
    {
        query();
    }

}


/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<ll> vec;
#define inf LLONG_MAX
#define bp __builtin_popcountll
#define pb push_back
#define ff first
#define ss second
#define P pair<ll,ll>
#define N 300001
#define ALL(a) a.begin(),a.end()
#define LG 20
#define int ll
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void query()
{

    ll n;
    cin>>n;

    string s;
    ll ans=-MOD;

    for(int i=1;i<=n;i++)
    {
        string p;
        cin>>p;

        ll tt=0;

        ll y;
        cin>>y;

        y*=100;
        ll z;
        cin>>z;

        z*=(-50);

        for(int j=1;j<=5;j++)
        {
            ll h;
            cin>>h;
            tt+=h;
        }

        tt+=y;
        tt+=z;

        if(tt>=ans)
        {
            ans=tt;
            s=p;
        }

    }

    cout<<s<<"\n";

}

int32_t main()
{

    FAST;

    int t=1;
    // cin>>t;

    while(t--)
    {
        query();
    }

}


#include<cstdio>
#include <iostream>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#define N 10
using namespace std;
struct node
{int a;
int num;
} p[60];
bool cmp(node aa,node bb)
{return aa.a<bb.a;}
int main()
{int n,i,a[60][10];
char c[60][60];
scanf("%d",&n);
for (i=0; i<n; i++)
{scanf("%s%d%d%d%d%d%d%d",c[i],&a[i][0],&a[i][1],&a[i][2],&a[i][3],&a[i][4],&a[i][5],&a[i][6]);
p[i].a=100*a[i][0]-50*a[i][1]+a[i][2]+a[i][3]+a[i][4]+a[i][5]+a[i][6];
p[i].num=i;}
sort(p,p+n,cmp);
printf("%s",c[p[n-1].num]);
}


#include<cstdio>
#include <iostream>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#define N 10
using namespace std;
struct node
{
    int a;
    int num;
} p[60];
bool cmp(node aa,node bb)
{
    return aa.a<bb.a;
}
int main()
{
    int n,i,a[60][10];
    char c[60][60];
    scanf("%d",&n);
    for (i=0; i<n; i++)
    {
        scanf("%s%d%d%d%d%d%d",c[i],&a[i][0],&a[i][1],&a[i][2],&a[i][3],&a[i][4],&a[i][5]);
        p[i].a=100*a[i][0]-50*a[i][1]+a[i][2]+a[i][3]+a[i][4]+a[i][5];
        p[i].num=i;
    }
    sort(p,p+n,cmp);
    printf("%c",c[p[0].num]);

}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int main() {
    int n; cin>>n;
    vector<pair<int,string>> v;
    while(n--){
        string handle;
        int plus,minus,a,b,c,d,e;
        cin>>handle>>plus>>minus>>a>>b>>c>>d>>e;
        int h=0;
        h+=(a+b+c+d+e);
        h+=(plus*100);
        h-=(minus*50);
        v.pb(mp(c,handle));
    }
    sort(v.begin(),v.end());
    cout<<v[v.size()-1].second<<"\n";
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int n; cin>>n;
    vector<pair<int,string>> v;
    while(n--){
        string handle;
        int plus,minus,a,b,c,d,e;
        cin>>handle>>plus>>minus>>a>>b>>c>>d>>e;
        int h=0;
        h+=(a+b+c+d+e);
        h+=(plus*100);
        h-=(minus*50);
        v.pb(mp(c,handle));
    }
    sort(v.begin(),v.end());
    cout<<v[v.size()-1].second<<"\n";
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int n; cin>>n;
    vector<pair<int,string>> v;
    while(n--){
        string handle;
        int plus,minus,a,b,c,d,e;
        cin>>handle>>plus>>minus>>a>>b>>c>>d>>e;
        int h=0;
        h+=(a+b+c+d+e);
        h+=(plus*100);
        h-=(minus*50);
        v.pb(mp(h,handle));
    }
    sort(v.begin(),v.end());
    cout<<v[v.size()-1].second<<"\n";
	// your code goes here
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
    ll i,j,k,sum=0,mx=0,n,pls,mns,a,b,c,d,e;
    cin>>n;
    string name="";
    while(n--)
    {
        string s;
        cin>>s>>pls>>mns>>a>>b>>c>>d>>e;
        sum=(pls*100)-(mns*50)+a+b+c+d+e;
        if(sum>mx)
        {
            mx=sum;
            name=s;
        }
    }
    cout<<name<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
    ll i,j,k,sum=0,mx=-1e9,n,pls,mns,a,b,c,d,e;
    cin>>n;
    string name="";
    while(n--)
    {
        string s;
        cin>>s>>pls>>mns>>a>>b>>c>>d>>e;
        sum=(pls*100)-(mns*50)+a+b+c+d+e;
        if(sum>mx)
        {
            mx=sum;
            name=s;
        }
    }
    cout<<name<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Jewel ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    Jewel;
    int p, m, a, b, c, d, e, mx=-10e5, n, point;
    string s, ans;
    cin>>n;
    while(n--)
    {
        cin>>s>>p>>m>>a>>b>>c>>d>>e;
        point = (a+b+c+d+e)+100*p - 50*m;
        if(point > mx)
        {
            mx = point;
            ans = s;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Jewel ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    Jewel;
    int p, m, a, b, c, d, e, mx=0, n, point;
    string s, ans;
    cin>>n;
    while(n--)
    {
        cin>>s>>p>>m>>a>>b>>c>>d>>e;
        point = (a+b+c+d+e)+100*p - 50*m;
        if(point > mx)
        {
            mx = point;
            ans = s;
        }
    }
    cout<<ans<<endl;
    return 0;
}


// Project7.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<string>
#include<sstream>
#include<vector>

int main() {
	int n,fsum=0;
	std::cin >> n;
	std::string t="";
	for (int i = 0; i < n; i++) {
		std::string s,r;
		int k;
		std::getline(std::cin, s);
		if (s.length() == 0) {
			std::getline(std::cin, s);
		}
		std::stringstream is(s);
		is >> r;

		int j = 0,sum=0;
		while(j<7){
			if (j == 0) {
				is >> k;
				sum += k * 100;
			}
			else if (j == 1) {
				sum -= k * 50;
			}
			else {
				sum += k;
			}
			j++;
		}
		if (fsum < sum) {
			fsum = sum;
			t = r;
		}
	}
	std::cout << t;
}

// Run program: Ctrl + int n;F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


// Project7.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<string>
#include<sstream>
#include<vector>

int main() {
	int n,fsum=0;
	std::cin >> n;
	std::string t="";
	for (int i = 0; i < n; i++) {
		std::string s,r;
		int k;
		std::getline(std::cin, s);
		if (s.length() == 0) {
			std::getline(std::cin, s);
		}
		std::stringstream is(s);
		is >> r;

		int j = 0,sum=0;
		while(j<7){
			is >> k;
			if (j == 0) {
				sum += k * 100;
			}
			else if (j == 1) {
				sum -= k * 50;
			}
			else {
				sum += k;
			}
			j++;
		}
		//std::cout << sum << std::endl;
		if (fsum < sum) {
			fsum = sum;
			t = r;
		}
	}
	std::cout << t;
}

// Run program: Ctrl + int n;F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


// Project7.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<string>
#include<sstream>
#include<vector>

int main() {
	int n,fsum=0;
	std::cin >> n;
	std::string t="";
	for (int i = 0; i < n; i++) {
		std::string s,r;
		int k;
		std::getline(std::cin, s);
		if (s.length() == 0) {
			std::getline(std::cin, s);
		}
		std::stringstream is(s);
		is >> r;

		int j = 0,sum=0;
		while(j<7){
			is >> k;
			if (j == 0) {
				sum += k * 100;
			}
			else if (j == 1) {
				sum -= k * 50;
			}
			else {
				sum += k;
			}
			j++;
		}
		//std::cout << sum << std::endl;
		if ((fsum < sum)||(i==0)) {
			fsum = sum;
			t = r;
		}
	}
	std::cout << t;
}

// Run program: Ctrl + int n;F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
i64 keyCount = sizeof(keymod) / sizeof(i64);
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
i64 n, Plus, minus, a, b, c, d, e; string s, ans = ""; i64 Max = -LINF;
/************************************************/

/************** [FUNCTIONS] **************/

void Input() {
	cin >> n;
	while (n--) {
		cin >> s >> Plus >> minus >> a >> b >> c >> d >> e;
		if (Max < Plus * 100 - minus * 50 + a + b + c + d +e) {
			Max = Plus * 100 - minus * 50 + a + b + c + d +e;
			ans = s;
		}
	}
}

void Solve() {
	cout << s;
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
i64 keyCount = sizeof(keymod) / sizeof(i64);
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
i64 n, Plus, Minus, a, b, c, d, e; string s, ans = ""; i64 Max = -LINF;
/************************************************/

/************** [FUNCTIONS] **************/

void Input() {
	cin >> n;
	while (n--) {
		cin >> s >> Plus >> Minus >> a >> b >> c >> d >> e;
		if (Max < Plus * 100 - Minus * 50 + a + b + c + d + e) {
			Max = Plus * 100 - Minus * 50 + a + b + c + d + e;
			ans = s;
		}
	}
}

void Solve() {
	cout << ans;
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
i64 keyCount = sizeof(keymod) / sizeof(i64);
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
i64 n, Plus, Minus, a, b, c, d, e; string s, ans = ""; i64 Max = -LINF;
/************************************************/

/************** [FUNCTIONS] **************/

void Input() {
	cin >> n;
	while (n--) {
		cin >> s >> Plus >> Minus >> a >> b >> c >> d >> e;
		if (Max < Plus * 100 - Minus * 50 + a + b + c + d +e) {
			Max = Plus * 100 - Minus * 50 + a + b + c + d +e;
			ans = s;
		}
	}
}

void Solve() {
	cout << s;
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
i64 keyCount = sizeof(keymod) / sizeof(i64);
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
i64 n, plus, minus, a, b, c, d, e; string s, ans = ""; i64 Max = -LINF;
/************************************************/

/************** [FUNCTIONS] **************/

void Input() {
	cin >> n;
	while (n--) {
		cin >> s >> plus >> minus >> a >> b >> c >> d >> e;
		if (Max < plus * 100 - minus * 50 + a + b + c + d +e) {
			Max = plus * 100 - minus * 50 + a + b + c + d +e;
			ans = s;
		}
	}
}

void Solve() {
	cout << s;
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


#include<bits/stdc++.h>
using namespace std;
int n, x, y; string pal;
int main(){
    scanf("%d", &n);
    int may=-10000000;
        string pal2="";
    for(int i=0; i<n; i++){
        cin>>pal;
        scanf("%d%d", &x, &y);
        x*=100;
        x-=y*50;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        if(x>may){
            may=x;
            pal2=pal;
        }

    }
cout<<pal2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, x, y; string pal;
int main(){
    scanf("%d", &n);
    int may=0;
        string pal2="";
    for(int i=0; i<n; i++){
        cin>>pal;
        scanf("%d%d", &x, &y);
        x-=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        if(x>may){
            may=x;
            pal2=pal;
        }

    }
cout<<pal2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, x, y; string pal;
int main(){
    scanf("%d", &n);
    int may=0;
        string pal2="";
    for(int i=0; i<n; i++){
        cin>>pal;
        scanf("%d%d", &x, &y);
        x*=100;
        x-=y*50;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        scanf("%d", &y);
        x+=y;
        if(x>may){
            may=x;
            pal2=pal;
        }

    }
cout<<pal2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,p,m,a,b,c,d,e,l=INT_MIN;
string s,t;
string maxi(int n){
     for(int i=0;i<n;i++){
        cin>>s>>p>>m>>a>>b>>c>>d>>e;
        p=p*100-m*50+a+b+c+d+e;
        if(p>l)l=p,t=s;
     }
     return t;
}
int main(){
    cin>>n;
    cout<<maxi(n);
}


#include<bits/stdc++.h>
using namespace std;
int n,p,m,a,b,c,d,e,l;
string s,t;
void maxi(int n){
     for(int i=0;i<n;i++){
        cin>>s>>p>>m>>a>>b>>c>>d>>e;
        p=p*100-m*50+a+b+c+d+e;
        if(p>l)l=p,t=s;
     }
     cout<<t;
}
int main(){
    cin>>n;
    maxi(n);
}


#include<bits/stdc++.h>
//#define endl '\n'
#define int long long
#define X first
#define Y second
#define sz(x) ((int)x.size())
#define CLR(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef pair<int,string> pii;
pii arr[100];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string name;
		cin>>name;
		int a,b,c,d,e,f,g;
		cin>>a>>b>>c>>d>>e>>f>>g;
		int ans=0;
		ans=a-b+c+d+e+f+g;
		arr[i]=pii(ans,name);
	}
	sort(arr,arr+n,greater<pii>());
	cout<<arr[0].Y<<endl;
	return 0;
}


#include<bits/stdc++.h>
//#define endl '\n'
#define int long long
#define X first
#define Y second
#define sz(x) ((int)x.size())
#define CLR(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef pair<int,string> pii;
pii arr[100];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string name;
		cin>>name;
		int a,b,c,d,e,f,g;
		cin>>a>>b>>c>>d>>e>>f>>g;
		int ans=0;
		ans=a*100-b*50+c+d+e+f+g;
		arr[i]=pii(ans,name);
		cout<<ans<<endl;
	}
	sort(arr,arr+n,greater<pii>());
	cout<<arr[0].Y<<endl;
	return 0;
}


#include<bits/stdc++.h>
//#define endl '\n'
#define int long long
#define X first
#define Y second
#define sz(x) ((int)x.size())
#define CLR(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef pair<int,string> pii;
pii arr[100];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string name;
		cin>>name;
		int a,b,c,d,e,f,g;
		cin>>a>>b>>c>>d>>e>>f>>g;
		int ans=0;
		ans=a*100-b*50+c+d+e+f+g;
		arr[i]=pii(ans,name);
	}
	sort(arr,arr+n,greater<pii>());
	cout<<arr[0].Y<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long int
#define SHUKRIYAA ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL);
using namespace std;
void inputOutput()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

signed main()
{
	SHUKRIYAA ;
	inputOutput();

	int n;
	cin>>n;
	int arr[n][7];
	string name[n];
	int score[n] = {};
	for(int i=0;i<n;i++)
	{
		cin>>name[i];
		for(int j=0;j<7;j++)
		{
			cin>>arr[i][j];
			int a = arr[i][j];
			if(j==0)
				score[i] += 100*a;
			else if(j==1)
				score[i] -= 50*a;
			else
				score[i] += a;
		}
	}
	int i = max_element(score,score+n)-score;
	cout<<name[i];

	cerr << "time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    long long M,P,N,SUM=0,MAX=-100000,A,B,C,D,E;
    char top[100],handle[100];
    scanf("%lld",&M);
    while(M--)
    {
        scanf("%s %lld %lld %lld %lld %lld %lld %lld",handle,&P,&N,&A,&B,&C,&D,&E);
        SUM=(100*P)-(50*N)+A+B+C+D+E;
        //printf("%s %lld\n",handle,SUM);
        if(SUM>=MAX)
        {
            MAX=SUM;
            strcpy(top,handle);
        }
    }
    printf("%s",top);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    long long M,P,N,SUM=0,MAX=0,A,B,C,D,E;
    char top[100],handle[100];
    scanf("%lld",&M);
    while(M--)
    {
        scanf("%s %lld %lld %lld %lld %lld %lld %lld",handle,&P,&N,&A,&B,&C,&D,&E);
        SUM=(100*P)-(50*N)+A+B+C+D+E;
        //printf("%s %lld\n",handle,SUM);
        if(SUM>=MAX)
        {
            MAX=SUM;
            strcpy(top,handle);
        }
    }
    printf("%s",top);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
main(){
    int n,plus, minus, a, b, c, d, e,maxscore=0,score;
    cin>>n;
    string ms,s;
    cin>>s>>plus>>minus>>a>>b>>c>>d>>e;
    score=plus*100- minus*50 +a+ b+ c+ d+ e;
    maxscore=score;
    ms=s;
    while(--n){
        cin>>s>>plus>>minus>>a>>b>>c>>d>>e;
        score=plus*100- minus*50 +a+ b+ c+ d+ e;
        if(score>maxscore){
            maxscore=score;
            ms=s;
        }
    }
    cout<<ms;
}


#include<bits/stdc++.h>
using namespace std;
main(){
    int n,plus, minus, a, b, c, d, e,maxscore=0,score;
    cin>>n;
    string ms,s;
    while(n--){
        cin>>s>>plus>>minus>>a>>b>>c>>d>>e;
        score=plus*100- minus*50 +a+ b+ c+ d+ e;
        if(score>maxscore){
            maxscore=score;
            ms=s;
        }
    }
    cout<<ms;
}


//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define en '\n'
#define rep(i,n)    for(ll i=0; i<n; i++)
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;

bool cmp(const pair<string,ll>&a,const pair<string,ll>&b)
{
    return a.se>b.se;
}
int main()
{
    godspeed
    ll  t,n,x,i,j,k,p,m,a,b,c,d,e;
    string s;
    cin>>t;
    vector<pair<string,ll>>v;
    while(t--)
    {
        cin>>s>>p>>m>>a>>b>>c>>d>>e;
        ll point=p*100-m*50;
        point+=a+b+c+d+e;
        v.pb(mp(s,point));
    }
    sort(v.begin(),v.end(),cmp);
    cout<<v[0].fi<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back

string s[55];

int main() {

    int n;
    sc("%d", &n);

    int mx = -1, ans;

    for(int i=1; i<=n; ++i) {

        int pl, mi, a, b, c, d, e;
        cin>>s[i]>>pl>>mi>>a>>b>>c>>d>>e;

        int x = (pl*100) - (mi*50) + (a+b+c+d+e);

        if(x > mx) {
            mx = x;
            ans = i;
        }
    }

    cout<<s[ans]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back

string s[55];

int main() {

    int n;
    sc("%d", &n);

    int mx = -1, ans;

    for(int i=1; i<=n; ++i) {

        int pl, mi, a, b, c, d, e;
        cin>>s[i]>>pl>>mi>>a>>b>>c>>d>>e;

        int x = (pl*100) + (a+b+c+d+e);

        if(x - mi*50 < 0) {
            x = 0;
        }
        else {
            x = x - mi*50;
        }

        if(x > mx) {
            mx = x;
            ans = i;
        }
    }

    cout<<s[ans]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back

string s[55];

int main() {

    int n;
    sc("%d", &n);

    int mx = INT_MIN, ans;

    for(int i=1; i<=n; ++i) {

        int pl, mi, a, b, c, d, e;
        cin>>s[i]>>pl>>mi>>a>>b>>c>>d>>e;

        int x = (pl*100) - (mi*50) + (a+b+c+d+e);

        if(x > mx) {
            mx = x;
            ans = i;
        }
    }

    cout<<s[ans]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back

string s[55];

int main() {

    int n;
    sc("%d", &n);

    int mx = INT_MIN, ans;

    for(int i=1; i<=n; ++i) {

        int pl, mi, a, b, c, d, e;
        cin>>s[i]>>pl>>mi>>a>>b>>c>>d>>e;

        int x = (pl*100) + (mi*50) + (a+b+c+d+e);

        if(x > mx) {
            mx = x;
            ans = i;
        }
    }

    cout<<s[ans]<<endl;
}


#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#pragma GCC optimize ("O3")
using namespace std;
int main () {
    ios::sync_with_stdio(false);
    cin.tie (0);
    int n, MAX=-1e8; cin>>n;
    string top;
    while (n--) {
        string s; cin>>s;
        int yes, no, a, b, c, d, e; cin>>yes>>no>>a>>b>>c>>d>>e;
        int temp=yes*100-no*50+a+b+c+d+e;
        if (temp>MAX) {
            MAX=temp;
            top=s;
        }
    }
    cout<<top;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#pragma GCC optimize ("O3")
using namespace std;
int main () {
    ios::sync_with_stdio(false);
    cin.tie (0);
    int n, MAX=0; cin>>n;
    string top;
    while (n--) {
        string s; cin>>s;
        int yes, no, a, b, c, d, e; cin>>yes>>no>>a>>b>>c>>d>>e;
        int temp=yes*100-no*50+a+b+c+d+e;
        if (temp>MAX) {
            MAX=temp;
            top=s;
        }
    }
    cout<<top;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<pair<int, string> > v;
	for(int i = 0; i < n; i++){
		string handle;
		cin>>handle;
		int p, m, a, b, c, d, e;
		cin>>p>>m>>a>>b>>c>>d>>e;
		int val = a + b + c + d + e + 100*p - 50*m;
		v.emplace_back(val, handle);
	}
	sort(v.rbegin(), v.rend());
	cout<<v[0].second<<endl;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<math.h>
using namespace std;

int n,score,mx,idx;
vector<string>names;
int main() {
    scanf("%d",&n);
    names.resize(n);
    for(int i=0;i<n;i++){
        cin>>names[i];
        int p,m,a,b,c,d,e;
        scanf("%d%d%d%d%d%d%d",&p,&m,&a,&b,&c,&d,&e);
        score=p*100-m*50+a+b+c+d+e;
        if(score>mx){
            mx=score;
            idx=i;
        }
    }
    cout<<names[idx];
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<math.h>
using namespace std;

int n,score,mx,idx;
vector<string>names;
int main() {
    scanf("%d",&n);
    names.resize(n);
    for(int i=0;i<n;i++){
        cin>>names[i];
        int p,m,a,b,c,d,e;
        scanf("%d%d%d%d%d%d%d",&p,&m,&a,&b,&c,&d,&e);
        score=p*100-m*50+a+b+c+d+e;
        if(i==0)
         mx=score;
        if(score>mx){
            mx=score;
            idx=i;
        }
    }//
    cout<<names[idx];
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<math.h>
using namespace std;

int n,score,mx,idx;
vector<string>names;
int main() {
    scanf("%d",&n);
    names.resize(n);
    for(int i=0;i<n;i++){
        cin>>names[i];
        int p,m,a,b,c,d,e;
        scanf("%d%d%d%d%d%d%d",&p,&m,&a,&b,&c,&d,&e);
        score=p*100-m*50+a+b+c+d+e;
        if(i==0)
         mx=score;
        if(score>mx){
            mx=score;
            idx=i;
        }
    }
    cout<<names[idx];
    return 0;
}