package ru.redguy.tasks;

import ru.redguy.ATask;
import ru.redguy.Task;

import java.io.IOException;
import java.util.ArrayList;

@ATask("2508")
public class Task2508 extends Task {
    @Override
    public void run() throws IOException {
        String s = getFile("k8.txt");
        int line = 0;
        ArrayList<Character> lineChars = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            String sub = s.substring(i);
            int bingo = 0;
            char start = sub.charAt(0);
            for (int j = 0; j < sub.length(); j++) {
                if(sub.charAt(j) == start) {
                    bingo++;
                } else {
                    if(line < bingo) {
                        line = bingo;
                        lineChars = new ArrayList<>();
                        lineChars.add(start);
                    }
                    if(line == bingo) {
                        lineChars.add(start);
                    }
                    break;
                }
            }
        }
        ArrayList<Character> been = new ArrayList<>();
        for (Character lineChar : lineChars) {
            if(!been.contains(lineChar)) {
                System.out.println(lineChar + " " + line);
                been.add(lineChar);
            }
        }
    }
}
