two stack algorithm