#include<iostream>
#include<iomanip>
using namespace std;

const int COUNTRY =4;
const int MEDAL = 3;
int table1[COUNTRY][MEDAL];
int sum[4];

int totalArr(int arr[][MEDAL], int SIZE, int a );
int maxArr(int arr[][MEDAL], int SIZE);
int minArr(int arr[][MEDAL], int SIZE);
int maxGold(int arr[][MEDAL], int SIZE);
int selectBronze(int arr[][MEDAL], int SIZE, int b);

int countryInd,medalInd;

int main(){
	
	
	
	int total,max,min,gold,bronze,input,inputB;
	
	cout<<"Hi! welcome to the medal organizer!"<<endl;
	cout<<"Please enter the values accordingly:"<<endl;
	
	   for (int i = 0; i < COUNTRY; i++){
	   	
            cout << "Country " << i + 1 << ", Gold Medal : ";
            cin >> table1[i][0];
            
            cout << "Country " << i + 1 << ", Silver Medal : ";
            cin >> table1[i][1];
            
            cout << "Country " << i + 1 << ", Bronze Medal : ";
            cin >> table1[i][2];
        }
    
    cout<<"Please enter choice of country for total number of medals: "<<endl;
    cin>>input;
    total = totalArr(table1, 4,input);
    cout<<"The total number of medal won by Country "<<input<<" is "<<total<<endl;
    max = maxArr(table1, 4);
    
    switch(medalInd){
		
		case 1:{ cout<<"Country "<<countryInd+1<<" won the largest number of medal, which is "<<max<<" Gold Medal"<<endl;
			break;
		}
		
		case 2:{cout<<"Country "<<countryInd+1<<" won the largest number of medal, which is "<<max<<" Silver Medal"<<endl;
			break;
		}
		
		case 3:{cout<<"Country "<<countryInd+1<<" won the largest number of medal, which is "<<max<<" Bronze Medal"<<endl;
			break;
		}
	}
	
	medalInd=0;
    
    min =minArr(table1,4);
    
       switch(medalInd){
		
		case 1:{ cout<<"Country "<<countryInd+1<<" won the smallest number of medal, which is "<<min<<" Gold Medal"<<endl;
			break;
		}
		
		case 2:{cout<<"Country "<<countryInd+1<<" won the smallest number of medal, which is "<<min<<" Silver Medal"<<endl;
			break;
		}
		
		case 3:{cout<<"Country "<<countryInd+1<<" won the smallest number of medal, which is "<<min<<" Bronze Medal"<<endl;
			break;
		}
	}
	
	medalInd=0;
	
	gold = maxGold(table1,4);
	
 	cout<<"Country "<<countryInd+1<<" won the most number of Gold medal, which is "<<gold<<" Gold Medal"<<endl;	
	
	medalInd=0;
	
	cout<<"Please enter choice of country for total number of bronze medals: "<<endl;
    cin>>inputB;
	
	bronze = selectBronze(table1, 4,inputB);
	cout<<"The total number of bronze medal won by Country "<<inputB<<" is "<<bronze<<endl;
    
}

int totalArr(int arr[][MEDAL], int SIZE, int input){
	
	int sum[4];
	
            sum[0] = arr[0][0]+arr[0][1]+arr[0][2];
            sum[1] = arr[1][0]+arr[1][1]+arr[1][2];
            sum[2] = arr[2][0]+arr[2][1]+arr[2][2];
            sum[3] = arr[3][0]+arr[3][1]+arr[3][2];
    

	switch(input){
		case 1:{ return sum[0];
			break;
		}
		
		case 2:{ return sum[1];
			break;
		}
		
		case 3:{ return sum[2];
			break;
		}
		
		case 4:{ return sum[3];
			break;
		}
	}

	
}

int maxArr(int arr[][MEDAL], int SIZE){
	
	int max;
	
	for(int j =0; j<4;j++){
		
	for(int k=0; k<MEDAL;k++){
		
		if(arr[j][k] > max){ max = arr[j][k]; countryInd = j;  medalInd = k+1;
		}
		
	}
		
	}
	
	return max;
	
	
}

int minArr(int arr[][MEDAL], int SIZE){
	
	int min = 999;
	
	for(int j =0; j<4;j++){
		
	for(int k=0; k<MEDAL;k++){
		
		if(arr[j][k] < min){ min = arr[j][k]; countryInd = j;  medalInd = k+1;
		}
		
	}
		
	}
	
	return min;
	
	
}

int maxGold(int arr[][MEDAL], int SIZE){
	
	int gold, GOLD = 0;
	
	for(int j =0; j<4;j++){
		
		
		if(arr[j][0] > gold){ gold = arr[j][0]; countryInd = j;
		}
		
	
		
	}
	
	
	return gold;
	
	
}

int selectBronze(int arr[][MEDAL], int SIZE, int inputB){
	
	int bronze = arr[inputB][2];
	
	
	return bronze;
	
	
}

