#include<iostream>
#include<iomanip>
using namespace std;

const int ROW=4;
const int COL=3;
int medal[ROW][COL],i,j,country;

int total(int [][COL],int);
int big(int [][COL]);
int small(int [][COL]);
int gold(int [ROW][COL]);
int bronze(int [ROW][COL],int);

int main()
{
	
	int div,qrt;
	for(div=0;div<ROW;div++)
	{
		for(qrt=0;qrt<1;qrt++)
	{
		cout<<"Country "<<(div+1)<<": Gold : ";
		cin>>medal[div][0];
		cout<<setw(20)<<"Silver : ";
		cin>>medal[div][1];
		cout<<setw(20)<<"Bronze : ";
		cin>>medal[div][2];
	}cout<<endl;
	}
	
	
	cout<<"Please choose a country to claculate the total numbers of medals ";
	cout<<"by any country : ";
	 
	cin>>country;
	
	while(country<1 || country>4)
	{
		cout<<"Wrong input"<<endl;
		cout << "Choose a country for total number of medals: ";
		cin >> country;
	}
	
	cout<<"The total number of medals won by country "<<country<<" are ";
	cout<<total(medal,country);
	
	cout<<"\nThe largest number of medals won : ";
	cout<<big(medal);
	
	cout<<"\nThe smallest number of medals won : ";
	cout<<small(medal);
	
	cout<<"\nThe highest number of gold medal won : ";
	cout<<gold(medal);
	 
	cout<<"\nThe total number of bronze medal won by country "<<country<<" are ";
	cout<<bronze(medal,country);
	
	return 0;
}

int total(int MEDALS[][COL],int number)
{
	int total=0;
	for(int x=0;x<COL;x++)
		total=total+MEDALS[number-1][x];
		
	return total;		
}

int big(int number[ROW][COL])
{
	int largest=number[ROW][COL];
	for(int x=0;x<ROW;x++)
		for(int y=0;y<COL;y++)
			if(number[x][y]>largest)
				largest=number[x][y];
	
	return largest;
	
}

int small(int array[ROW][COL])
{
	int hold=array[0][0];
	for(int i=0;i<ROW;i++)
		for(int j=0;j<COL;j++)
			if(array[i][j]<hold)
				hold=array[i][j];
	
	return hold;
}
int gold(int n[ROW][COL])
{
	int highest=n[0][0];
	for(int g=0;g<ROW;g++)
		if (n[g][0]>highest)
			highest=n[g][0];
	
	return highest;
}

int bronze(int number[ROW][COL],int n)
{
	int total;
	total=number[n-1][2];
	return total;
	
}
