# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def mergeKLists(self, lists):
        """
        :type lists: List[ListNode]
        :rtype: ListNode
        """
        import heapq
        lists=[(node.val,node)for node in lists if node]
        heapq.heapify(lists)
        pre=pre2=ListNode(-1)
        while lists:
            val,node=heapq.heappop(lists)
            if node.next:
                heapq.heappush(lists,(node.next.val,node.next))
            pre.next=node
            pre=pre.next
        return pre2.next

s=Solution()
str1="3[a]2[bc]"
print(s.decodeString(str1))

"""
TLE:
class Solution(object):
    def longestValidParentheses(self, s):
        n=len(s)
        ans=0
        i=0
        while i<n:
            if s[i]=="(":
                start=i
                temp=0
                while start<n:
                    if s[start]=="(":
                        temp+=1
                    elif s[start]==")":
                        temp-=1
                    if temp==0:
                        ans=max(ans,start-i+1)
                    if temp<0:
                        i=start
                        break
                    start+=1
            i+=1
        return ans
"""

