滑动窗口

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String original = scan.nextLine();
        char[] chrs = original.toCharArray();
        int len = Integer.valueOf(scan.nextLine().trim());
        int ans = 0;
        int ml = 0;
        int acc = 0;
        LinkedList<Integer> ll = new LinkedList<>();
        for (int i = 0; i < chrs.length; i++) {
            char currentChr = chrs[i];
            ll.add(i);
            if (currentChr == 'C' || currentChr == 'G') {
                acc++;
            }
            if (!ll.isEmpty() && ll.peekFirst() == i - len) {
                if (chrs[ll.peekFirst()] == 'C' || chrs[ll.peekFirst()] == 'G') {
                    acc--;
                }
                ll.removeFirst();
            }
            if (i >= len - 1) {
                if (acc > ml) {
                    ml = acc;
                    ans = ll.peekFirst();
                }
            }
        }
        System.out.println(original.substring(ans, ans + len));
    }
}