#NEWLINE# def three_partition( x ) : #NEWLINE# #INDENT# 'partition a set of integers in 3 parts of same total value\n\n    :param x: table of non negative values\n    :returns: triplet of the integers encoding the sets, or None otherwise\n    :complexity: :math:`O(2^{2n})`\n    ' #NEWLINE# f = ( [ 0 ] * ( 1 << len ( x ) ) ) #NEWLINE# for i in range ( len ( x ) ) : #NEWLINE# #INDENT# for S in range ( ( 1 << i ) ) : #NEWLINE# #INDENT# f [ ( S | ( 1 << i ) ) ] = ( f [ S ] + x [ i ] ) #NEWLINE# #UNINDENT# #UNINDENT# for A in range ( ( 1 << len ( x ) ) ) : #NEWLINE# #INDENT# for B in range ( ( 1 << len ( x ) ) ) : #NEWLINE# #INDENT# if ( ( ( A & B ) == 0 ) and ( f [ A ] == f [ B ] ) and ( ( 3 * f [ A ] ) == f [ ( - 1 ) ] ) ) : #NEWLINE# #INDENT# return ( A , B , ( ( ( ( 1 << len ( x ) ) - 1 ) ^ A ) ^ B ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return None