#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

void displayLine()
{
	for(int i=0; i<52; i++)
	{
		cout << "-" ;
	}
	cout << endl;
}
int findIndWinner(int a[])
{
	int highest=a[0], highint;
	for(int i=0;i<12;i++)
	{
		if(a[i]>highest)
		{
			highest=a[i];
			highint=i;
		}
	}
	return highint;
}
int findTeamWinner(int b[])
{
	int Highest=b[0],Highint;
	for(int i=0;i<3;i++)
	{
		if(b[i]>Highest)
		{
			Highest=b[i];
			Highint=i;
		}
	}
	return Highint;
}
int main()
{
	int marks[12][7];
	int indsum[12];
	int teamsum[3];
	int indhighest,teamhighest;
	int sum=0,totalscore=0,tteam=0,tteam2=0,tteam3=0;
	ifstream inp("input2.txt");
	
	if(!inp)
	{
		cout<<"Sorry, input file does not exist! \nPress any key to continue . . ."<<endl;
		exit(0);
	}
	
	while(!inp.eof())
	{
		for(int i=0;i<12;i++)
		{
			for(int j=0;j<7;j++)
			{
				inp>>marks[i][j];
			}
		}
	}
	
	for(int i=0;i<9;i++)
	{
		if(i==0||i==2||i==4||i==6||i==8)
		{
			displayLine();
		}
		if(i==1)
		{
			cout <<left<< setw(8) << "Id" << setw(8) <<"E1" <<setw(8) << "E2" <<setw(8) << "E3" <<setw(8) << "E4" << setw(8) <<"E5" << setw(8) <<"Total" << endl;
		}
		if(i==3)
		{
			cout<<"TEAM "<<marks[0][0]<<endl;
			for(int x=0;x<4;x++)
			{
				for(int y=1;y<7;y++)
				{
					cout<<setw(8)<<marks[x][y];
					sum+=marks[x][y];
				}
				cout<<setw(8)<<sum-marks[x][1]<<endl;
				indsum[x] = sum-marks[x][1];
				tteam+=sum-marks[x][1];
				sum=0; //set 0 to prevent add-on non stop.
			}
			teamsum[0]=tteam;
			cout<<"Total"<<right<<setw(46)<<tteam<<endl;
		}
		if(i==5)
		{
			cout<<"TEAM "<<marks[4][0]<<endl;
			for(int x=4;x<8;x++)
			{
				for(int y=1;y<7;y++)
				{
					cout<<left<<setw(8)<<marks[x][y];
					sum+=marks[x][y];
				}
				cout<<setw(8)<<sum-marks[x][1]<<endl;
				indsum[x] = sum-marks[x][1];
				tteam2+=sum-marks[x][1];
				sum=0; //set 0 to prevent add-on non stop.
			}
			teamsum[1]=tteam2;
			cout<<"Total"<<right<<setw(46)<<tteam2<<endl;
		}
		if(i==7)
		{
			cout<<"TEAM "<<marks[8][0]<<endl;
			for(int x=8;x<12;x++)
			{
				for(int y=1;y<7;y++)
				{
					cout<<left<<setw(8)<<marks[x][y];
					sum+=marks[x][y];
				}
				cout<<setw(8)<<sum-marks[x][1]<<endl;
				indsum[x] = sum-marks[x][1];
				tteam3+=sum-marks[x][1];
				sum=0; //set 0 to prevent add-on non stop.
			}
			teamsum[2]=tteam3;
			cout<<"Total"<<right<<setw(46)<<tteam3<<endl;
		}
 }
 	indhighest = findIndWinner(indsum);
	teamhighest = findTeamWinner(teamsum);
	
	cout <<"Winner for Individual Category: "<< marks[indhighest][1]<<"(Team "<<marks[indhighest][0]<<")"<<endl;
	cout<<"Winner for Group Category: "<<"Team "<<teamhighest+1<<"(Score = "<<teamsum[teamhighest]<<")"<<endl;
	
	inp.close();
	
	return 0;
}
