import java.util.*;

public class Gift { public int getValue(int[] gifts, int n) { int flag = 1; int num = gifts[0]; for(int i = 1;i < n;i++){

        if(gifts[i] == num){
            flag ++;
        }else{
            flag --;
        }
        if(flag == 0){
            num = gifts[i];
           
        }
        
    }
    flag = 0;
     for(int i = 0;i < n;i++){
        if(gifts[i] == num){
            flag ++;
        }
        
    }
    if(flag > n / 2) return num;
    else return 0;
    // write code here
}

}