class EmptyStackException(Exception): pass class Element: def __init__(self, value, next): self.value = value self.next = next class Stack: def __init__(self): self.head = None def stackhead(self): return self.head def push(self, element): self.head = Element(element, self.head) def gethead(self): return self.head.value def pop(self): if self.empty(): raise EmptyStackException result = self.head.value self.head = self.head.next return result def empty(self): return self.head == None if __name__ == "__main__": import time import sys def checkno(l): stack = Stack() elements=[1,2,3,4] result = [] c=0 i=0 for e in elements: stack.push(e) a=stack.gethead() while(i<3 and a==l[i]): result.append(stack.pop()) i=i+1 a=a-1 result.append(stack.pop()) if(i==3):return 1 else: return 0 fopen=open("in11_5.txt",'r') k=fopen.readline() inp=fopen.readline() inp1=inp.split(',') t1=time.clock() i1=inp1[0] i2=inp1[1] list1=[] list2=[] for a in range(len(i1)): list1.append(int(i1[a])) list2.append(int(i2[a])) Memory=sys.getsizeof(list1)+sys.getsizeof(list2)+2*172 fout=open("out_35_11_5.txt",'w') fout.write(str(checkno(list1))+',') fout.write(str(checkno(list2))) fout.write("\n Time Taken="+ str(time.clock()-t1)+"\n Memory Used= "+str(Memory)) fout.close()