Fundamentals - Java - Arrays - Kamino Factory 50/100

Здравеите , може ли малко помощ за тази задача , дава ми 50 от 100 но примерите от условието ми работят и аз също опитах други тестове които работят и не знам къде ми е грешката.

 

package SoftUniArrays;

import java.util.Arrays;
import java.util.Scanner;

public class KaminoFactory {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int sequenceLength = Integer.parseInt(scan.nextLine());
        String thesequence = scan.nextLine();
        String[] sequence = thesequence.split("!");

        int amount = 1;
        int lastIndex = 0;
        int firstIndex = 0;
        int currentBiggest = 0;
        int currentIndex = 0;
        int counter = 0;
        int finalcounter = 0;
        int finalamount = 0;
        int amountOnes = 0;
        int maxOnes = 0;
        boolean flag=false;

        String[] currentSequence = new String[sequenceLength];

        while (!thesequence.equals("Clone them!")) {
            sequence = thesequence.split("!");

            for (int i = 0; i < sequenceLength; i++) {
                if (sequence[i].equals("1")) {
                    amountOnes += 1;
                }
            }
            for (int i = 0; i < sequenceLength - 1; i++) {
                if (sequence[i].equals("1") && (!sequence[i + 1].equals("0"))) {
                    amount += 1;
                    lastIndex = i + 1;
                }


            }
            counter += 1;
            if (amount > lastIndex) {
                firstIndex = amount - lastIndex - 1;
            } else {
                firstIndex = lastIndex - amount + 1;
            }

            if (currentBiggest == amount && firstIndex == currentIndex && amountOnes>maxOnes) {
                currentBiggest = amountOnes;
                currentIndex = firstIndex;
                currentSequence = sequence;
                finalcounter = counter;
                finalamount = amount;
                flag = true;
            } else if (currentBiggest == amount && firstIndex < currentIndex) {
                currentIndex = firstIndex;
                currentSequence = sequence;
                finalcounter = counter;
                finalamount = amount;
                flag=false;

            } else if (currentBiggest < amount) {
                currentBiggest = amount;
                currentIndex = firstIndex;
                currentSequence = sequence;
                finalcounter = counter;
                finalamount = amount;
                if (amountOnes>maxOnes){
                    flag = true;

                }
            }
            if (amountOnes>maxOnes){
                maxOnes = amountOnes;
            }
            amountOnes = 0;
            amount = 1;
            lastIndex = 0;
            firstIndex = 0;
            thesequence = scan.nextLine();
        }
      if (flag) {
          System.out.printf("Best DNA sample %d with sum: %d.", finalcounter,maxOnes);
      }else {
          System.out.printf("Best DNA sample %d with sum: %d.", finalcounter, finalamount);
      }
        System.out.println("");
        for (int i = 0; i < sequenceLength; i++) {

            System.out.print(currentSequence[i] + " ");

        }
    }
}