codeforces/664B_rebus.py
def calculate(self):
        """ Main calcualtion function of the class """
        
        nums = [0] * len(self.signs)
        for i in range(len(self.signs)):
            nums[i] = 1

        sum = self.summ(nums, self.signs)

        for i in range(len(self.signs)):
            if sum != self.n:
                if self.signs[i] == "+" and sum < self.n:
                    nums[i] = min(self.n - sum + 1, self.n)
                    sum -= 1
                    sum += nums[i]
                if self.signs[i] == "-" and sum > self.n:
                    nums[i] = min(sum + 1 - self.n, self.n)
                    sum += 1
                    sum -= nums[i]

        if sum == self.n:
            result = "Possible\n"

            for i in range(len(self.signs)):
                if i != 0:
                    result += self.signs[i] + " "
                result += str(nums[i]) + " "
            result += "= " + str(self.n)
        else:
            result = "Impossible"

        return str(result)
 Main calcualtion function of the class 
Main calcualtion function of the class
Main calcualtion function of the class
def calculate(self):
        nums = [0] * len(self.signs)
        for i in range(len(self.signs)):
            nums[i] = 1
        sum = self.summ(nums, self.signs)
        for i in range(len(self.signs)):
            if sum != self.n:
                if self.signs[i] == "+" and sum < self.n:
                    nums[i] = min(self.n - sum + 1, self.n)
                    sum -= 1
                    sum += nums[i]
                if self.signs[i] == "-" and sum > self.n:
                    nums[i] = min(sum + 1 - self.n, self.n)
                    sum += 1
                    sum -= nums[i]
        if sum == self.n:
            result = "Possible\n"
            for i in range(len(self.signs)):
                if i != 0:
                    result += self.signs[i] + " "
                result += str(nums[i]) + " "
            result += "= " + str(self.n)
        else:
            result = "Impossible"
        return str(result)
def calculate ( self ) : nums = [ 0 ] * len ( self . signs ) for i in range ( len ( self . signs ) ) : nums [ i ] = 1 sum = self . summ ( nums , self . signs ) for i in range ( len ( self . signs ) ) : if sum != self . n : if self . signs [ i ] == "+" and sum < self . n : nums [ i ] = min ( self . n - sum + 1 , self . n ) sum -= 1 sum += nums [ i ] if self . signs [ i ] == "-" and sum > self . n : nums [ i ] = min ( sum + 1 - self . n , self . n ) sum += 1 sum -= nums [ i ] if sum == self . n : result = "Possible\n" for i in range ( len ( self . signs ) ) : if i != 0 : result += self . signs [ i ] + " " result += str ( nums [ i ] ) + " " result += "= " + str ( self . n ) else : result = "Impossible" return str ( result )
Main calcualtion function of the class
Main calcualtion function of the class
""" Main calcualtion function of the class """
self