parameters: (self, tokens, P)
return_statement: return result
docstring: :type tokens: List[int]
          :type P: int
          :rtype: int
docstring_summary: :type tokens: List[int]
          :type P: int
          :rtype: int
docstring_tokens: : type tokens : List [ int ] : type P : int : rtype : int
function: def bagOfTokensScore(self, tokens, P):
          """
          :type tokens: List[int]
          :type P: int
          :rtype: int
          """
          tokens.sort()
          result, points = 0, 0
          left, right = 0, len(tokens)-1
          while left <= right:
              if P >= tokens[left]:
                  P -= tokens[left]
                  left += 1
                  points += 1
                  result = max(result, points)
              elif points > 0:
                  points -= 1
                  P += tokens[right]
                  right -= 1
              else:
                  break
          return result
function_tokens: def bagOfTokensScore ( self , tokens , P ) : tokens . sort ( ) result , points = 0 , 0 left , right = 0 , len ( tokens ) - 1 while left <= right : if P >= tokens [ left ] : P -= tokens [ left ] left += 1 points += 1 result = max ( result , points ) elif points > 0 : points -= 1 P += tokens [ right ] right -= 1 else : break return result