while True:
    try:
        s = input().strip()
        k = int(input())
        queue = []
        for i in range(k):
            if s[i] in 'CG':
                queue.append(i)
        max_ratio = len(queue)
        res = s[:k]
        for i in range(k, len(s)):
            if s[i] in 'CG':
                queue.append(i)
            if queue[0] <= i-k:
                queue.pop(0)
            if len(queue) > max_ratio:
                max_ratio = len(queue)
                res = s[i-k+1:i+1]
        print(res)
    except:
        break