Generate an N | Fun dtion to print the required sequence ; Stores count of even and odd elements ; Stores sum of even and odd elements ; Print N / 2 even elements ; Print N / 2 - 1 odd elements ; Print final odd element ; Driver Code
def Print ( N ) : NEW_LINE INDENT if ( ( N / 2 ) % 2 or ( N % 2 ) ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE return NEW_LINE DEDENT CurEven = 2 NEW_LINE CurOdd = 1 NEW_LINE SumOdd = 0 NEW_LINE SumEven = 0 NEW_LINE for i in range ( N // 2 ) : NEW_LINE INDENT print ( CurEven , end = " ▁ " ) NEW_LINE SumEven += CurEven NEW_LINE CurEven += 2 NEW_LINE DEDENT for i in range ( ( N // 2 ) - 1 ) : NEW_LINE INDENT print ( CurOdd , end = " ▁ " ) NEW_LINE SumOdd += CurOdd NEW_LINE CurOdd += 2 NEW_LINE DEDENT CurOdd = SumEven - SumOdd NEW_LINE print ( CurOdd ) NEW_LINE DEDENT N = 12 NEW_LINE Print ( N ) NEW_LINE