#include <iostream>
using namespace std;

void readfiles(int [][7]);
void displayLine();
void findIndWinner(int [], int [][7]);
void findTeamWinner(int []);



int main()
{
	int r, c, marks[12][7];
	int totind[12]={ (0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0) };
	int tot[3]={ (0),(0),(0) };
	
	readfiles(marks);
	for(r=0;r<12;r++)
	{
		for(c=2;c<7;c++)
		{
			totind[r] += marks[r][c]; 
		}
	}
	
	for(r=0;r<12;r++)
	{
		if(marks[r][0]==1)
		{
			tot[0] += totind[r];
		}
		else if(marks[r][0]==2)
		{
			tot[1] += totind[r];
		}
		else
		{
			tot[2] += totind[r];	
		}
	}
	
	displayLine();
	cout << "Id     " << "E1     " << "E2     " << "E3     " << "E4     " << "E5     " << "Total" <<endl;
	displayLine();
	
	r=0;
	
	cout << "Team " << marks[r][0] << endl;
	for(r=0;r<4;r++)
	{
		for(c=0;c<7;c++)
		{
			cout << marks[r][c] << "     ";
		}
		
		cout << totind[r];
		cout << endl;
	}
	
	cout << "Total                                        " << tot[0] << endl;
	displayLine();
	r += 4;
		
	cout << "Team " << marks[r][0] << endl;
	for(r=4;r<8;r++)
	{
		for(c=0;c<7;c++)
		{
			cout << marks[r][c] << "     ";
		}
		
		cout << totind[r];
		cout << endl;
	}
	
	cout << "Total                                        " << tot[1] << endl;
	displayLine();
	r += 4;
		
	cout <<"Team " << marks[r][0] << endl;
	for(r=8;r<12;r++)
	{
		for(c=0;c<7;c++)
		{
			cout << marks[r][c] << "     ";
		}
		
		cout << totind[r];
		cout << endl;
	}
	
	cout << "Total                                        " << tot[2] << endl;
	displayLine();
	
	
	findIndWinner(totind, marks);
	findTeamWinner(tot);

	
	

	
	
	
	
	return 0;
}

void displayLine()
{
	for(int i=0;i<52;i++)
	{
		cout << "-";
	}
	cout << endl;
}

void readfiles(int marks[][7])
{
	int i, j;
	
	for(i=0; i<12;i++)
	{
		for(j=0;j<7;j++)
		{
			cout << "Enter team ID : ";
			cin >> marks[i][j];
			cout << endl;
			
			j++;
		
			cout << "Enter partcipant ID : ";
			cin >> marks[i][j];
			cout << endl;
			
			j++;
			
			cout << "Enter the event 1 score : ";
			cin >> marks[i][j];
			cout << endl;
			
			j++;
			
			cout << "Enter the event 2 score : ";
			cin >> marks[i][j];
			cout << endl;
			
			j++;
			
			cout << "Enter the event 3 score : ";
			cin >> marks[i][j];
			cout << endl;
			
			j++;
			
			cout << "Enter the event 4 score : ";
			cin >> marks[i][j];
			cout << endl;
			
			j++;
			
			cout << "Enter the event 5 score : ";
			cin >> marks[i][j];
			cout << endl;
		}
	}
}

void findIndWinner(int totind[], int marks[][7])
{
	int count, highest = totind[0], team=1, win=1001;
	
	for(count=1;count<12;count++)
	{
		if(totind[count]>highest)
		{
			highest=totind[count];
			team=marks[count][0];
			win=marks[count][1];
		}
	}
	
	cout << "Winner for Individual Category: " << win << "  (Team " << team << ")" << endl;
}

void findTeamWinner(int tot[])
{
	int i, highest=tot[0], team=1;
	
	for(i=1;i<3;i++)
	{
		if(tot[i]>highest)
		{
			highest=tot[i];
			team=i+1;
		}
	}
	
	cout << "Winner for Group Category: Team " << team <<  "(Score = " << highest << ")" << endl;
	
	
}
