"""# ### 谜题描述 Consider a sequence [a1, a2, ... , an]. Define its prefix product sequence . Now given n, find a permutation of [1, 2, ..., n], such that its prefix product sequence is a permutation of [0, 1, ..., n - 1]. Input The only input line contains an integer n (1 ≤ n ≤ 105). Output In the first output line, print \"YES\" if such sequence exists, or print \"NO\" if no such sequence exists. If any solution exists, you should output n more lines. i-th line contains only an integer ai. The elements of the sequence should be different positive integers no larger than n. If there are multiple solutions, you are allowed to print any of them. Examples Input 7 Output YES 1 4 3 6 5 2 7 Input 6 Output NO Note For the second sample, there are no valid sequences. Here is a reference code to solve this task. You can use this to help you genereate cases or validate the solution. ```python from math import sqrt n=input() if n==4 : print \"YES\" print 1 print 3 print 2 print 4 elif n==1: print \"YES\" print 1 else : prime=[1]*(n+1) prime[0]=0 prime[1]=0 i=2 while i<= int(sqrt(n))+1: if prime[i]==1: for s in range(i*i,n+1,i): prime[s]=0 if prime[n]==0: break i=i+1 if prime[n]: print \"YES\" print 1 i=2 while i ... [/answer] OR [answer] NO [/answer]""" @staticmethod def extract_output(text): # Robust extraction with negative lookahead pattern = r'\[answer\][\s]*((?!\[answer\]).*?)[\s]*\[/answer\]' matches = re.findall(pattern, text, re.DOTALL|re.IGNORECASE) if not matches: return None content = matches[-1].strip().upper() lines = [l.strip() for l in content.split('\n')] if lines[0].startswith('NO'): return {'answer': 'NO'} if len(lines) == 1 else None if lines[0].startswith('YES') and len(lines) == int(lines[0][3:].strip() or 0)+1: try: nums = list(map(int, lines[1:])) return {'answer': 'YES', 'sequence': nums} except ValueError: pass return None @classmethod def _verify_correction(cls, solution, case): # Structural validation if not solution or case['exists'] != (solution.get('answer') == 'YES'): return False if solution['answer'] == 'NO': return True # Numerical validation n = case['n'] seq = solution.get('sequence', []) if sorted(seq) != list(range(1, n+1)): return False # Prefix product verification seen = set() product = 1 for num in seq: product = (product * num) % n if product in seen: return False seen.add(product) return seen == set(range(n))