#include #include #include // for debug #define DEBUGs // ----------- #define NOP do{}while(0) #ifdef DEBUGw #include #define TRACE(...) do{printf(__VA_ARGS__);fflush(stdout);}while(0) #define TRACECR do{putchar_unlocked('\n');fflush(stdout);}while(0) static clock_t startclock; void DEBUGSTART(void){TRACE("--DEBUG MODE --\n");startclock=clock();} void DEBUGEND(void){startclock=clock()-startclock;TRACE("--finish --\ntime is %.3fms\n",startclock/1000.);} #else #define TRACE(...) NOP #define TRACECR NOP void DEBUGSTART(void){return;} void DEBUGEND(void){return;} #endif extern int getchar_unlocked(void); extern int putchar_unlocked(int); #define PRINCR do{printf("\n");fflush(stdout);}while(0) #define GETLINE(str) do{char *p;fgets(str,sizeof(str),stdin);p=strchr(str,'\n');if(p)*p='\0';}while(0) #define REP(a,b) for(int a=0;a<(int)(b);++a) static char *GETWORD(char* str) {char c;char *cp;cp=&str[0];c=fgetc(stdin);while( c != EOF ){if((c==' ')||( c=='\n')) break;*cp++=c;c=fgetc(stdin);}*cp='\0';return &str[0];} #define GETINTS(a,b) {char s[34];int *ap=a;REP(i,b){GETWORD(s);sscanf(s,"%d", ap);ap++;}} static int GETLINEINT(void) {char s[34];GETLINE(s);return atoi(s);} static int GETWORDINT(void) {char s[34];GETWORD(s);return atoi(s);} #define SWAP(type,a,b) do{type _c;_c=a;a=b;b=_c;}while(0) char sdn[600004]; char shi[300004]; int main(){ long lN; long gt; int num; int scc; char *cp0,*cpc0,*cpc1; int iFirst,iPrev,iNow,iEnd; scanf("%ld\n",&lN); cp0 = sdn; iFirst = GETWORDINT(); iPrev = iFirst; for(long i=1L; i < lN-1; ++i){ iNow = GETWORDINT(); if( iPrev < iNow ) { *cp0++ = '<'; } else { *cp0++ = '>'; } iPrev = iNow; //TRACE("%d,",sdn[i]); } iEnd = GETWORDINT(); if( iPrev < iEnd ) { *cp0++ = '<'; } else { *cp0++ = '>'; } if( iEnd < iFirst ) { *cp0++ = '<'; } else { *cp0++ = '>'; } cpc0 = sdn; for(long i=0L; i < lN; ++i){ *cp0++ = *cpc0++; } *cp0 = '\0'; GETLINE(shi); TRACE("%s\n",shi); cpc0 = strstr( sdn , shi ); if( cpc0 == NULL ) { gt = -1; } else { gt = (long)(cpc0 - sdn); } printf("%ld\n", gt ); }