The U.S. national security advisor says Pakistan , Afghanistan and the United States have to cooperate more closely if they are to stem the threat posed by terrorists operating in Pakistan 's border areas .