+Success! You've managed to infiltrate Commander Lambda's evil organization, and finally earned yourself an entry-level position as a Minion on their space station. From here, you just might be able to subvert Commander Lambda's plans to use the LAMBCHOP doomsday device to destroy Bunny Planet. Problem is, Minions are the lowest of the low in the Lambda hierarchy. Better buck up and get working, or you'll never make it to the top...
+
+Next time Bunny HQ needs someone to infiltrate a space station to rescue bunny workers, you're going to tell them to make sure 'stay up for 48 hours straight scrubbing toilets' is part of the job description. It's only fair to warn people, after all.
+
+You survived a week in Commander Lambda's organization, and you even managed to get yourself promoted. Hooray! Henchmen still don't have the kind of security access you'll need to take down Commander Lambda, though, so you'd better keep working. Chop chop!
+
+Rumor has it the bunny trainers are inexplicably fond of bananas. You're an apple person yourself, but you file the information away for future reference. You never know when you might need to bribe a trainer (or three)...
+
+The perks are definitely better as a Henchman than as a Minion. You're even allowed to sleep lying down!
+
+Awesome! Commander Lambda was so impressed by your efforts that you've been promoted to personal assistant. You'll be helping the Commander directly, which means you'll have access to all of Lambda's files -- including the ones on the LAMBCHOP doomsday device. This is the chance you've been waiting for. Can you use your new access to finally topple Commander Lambda's evil empire?
+
+Commander Lambda has six suits, three dress uniforms, four casual outfits, and one Dress-Uniform-For-Important-Speeches-Only. You know this because you've already had to take all of them to the dry cleaner's. Twice!
+
+Who the heck puts clover and coffee creamer in their tea? Commander Lambda, apparently. When you signed up to infiltrate the organization you didn't think you'd get such an up-close and personal look at these more... unusual tastes.
+
+One of these days you're going to manage to glimpse Commander Lambda's password over their shoulder. But the Commander is very careful about security and you haven't managed it yet...
+
+Excellent! You've destroyed Commander Lambda's doomsday device and saved Bunny Planet! But there's one small problem: the LAMBCHOP was a wool-y important part of the space station, and when you blew it up, you triggered a chain reaction that's tearing the station apart. Can you rescue the bunny workers and escape before the entire thing explodes?
+ //assume xs never drops below 1 element as stated in the constraint
+
+ int negCount = 0, remove = -1;
+
+ Arrays.sort(xs);
+
+ for(int i = 0; i < xs.length; i++) {
+ int x = xs[i];
+
+ if(x < 0) {
+ negCount++;
+ remove = i; //get last negative value's index to be removed
+ }
+ }
+
+ if(xs.length > 1 && remove != -1 && negCount % 2 != 0) xs[remove] = 0; //if a remove value is found and it's not the only value, and negative count is not even (multiplying will return negative)
+
+ BigInteger result = BigInteger.ZERO; //initialize big integer since it can get pretty big according to the readme
+
+ for(int x : xs) {
+ if(x != 0)
+ result = result == BigInteger.ZERO ? BigInteger.valueOf(x) : result.multiply(BigInteger.valueOf(x)); //only multiply non zero values; zero values are almost always discardable
+ }
+
+ return result.max(BigInteger.valueOf(xs[xs.length - 1])).toString(); //check if result is smaller than largest value in array (usually for catching 0s that we discarded)
+ public static String solution(String x, String y) {
+ BigInteger m = new BigInteger(x), f = new BigInteger(y);
+
+ boolean found = false;
+ BigInteger count = BigInteger.ZERO;
+ while (!found && (m.signum() == 1 && f.signum() == 1)) { //loop when not found and values are not negative
+ int comp = m.compareTo(f);
+ if (comp > 0) {
+ BigInteger[] vals = f.equals(BigInteger.ONE) ? //dividing one is the only case where it will not be equivalent to multiple subtraction, thus we must make an exception
+ new BigInteger[] { BigInteger.ONE, m.subtract(f) } : m.divideAndRemainder(f);