int scan() { int res=0,ch; while(!((ch= getchar())>='0'&&ch<='9')){ if(ch==EOF)return 1<<30; } res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+(ch-'0'); return res; }