n = int(input()) s = input().strip() def generate_99_song(): song = [] for i in range(99, 0, -1): part1 = f"{i} bottle{'s' if i != 1 else ''} of beer on the wall, {i} bottle{'s' if i != 1 else ''} of beer." song.append(part1) part2 = "Take one down and pass it around, " if i - 1 == 0: part2 += "no more bottles of beer on the wall." else: part2 += f"{i-1} bottle{'s' if (i-1) != 1 else ''} of beer on the wall." song.append(part2) song.append("\n") song.append("No more bottles of beer on the wall, no more bottles of beer.\n") song.append("Go to the store and buy some more, 99 bottles of beer on the wall.\n") return ''.join(song) song_99 = generate_99_song() if s == song_99: print('9') elif s == "Hello, world!": print('H') else: q_count = s.count('Q') other_commands = any(c in 'H9+' for c in s) if q_count == 1 and not other_commands: print(s) else: divisors = [] for m in range(1, int(n**0.5) + 1): if n % m == 0: divisors.append(m) if m != n // m: divisors.append(n // m) divisors.sort() found = False for m in divisors: if n % m != 0: continue k = n // m candidate = s[:k] if candidate * m != s: continue q_candidate = candidate.count('Q') if q_candidate != m: continue if any(c in 'H9+' for c in candidate): continue print(candidate) found = True break if not found: print(-1)