int main() { long long t,x,y; scanint(t); while(t--) { scanint(x); scanint(y); if(x==0 && ( y==0 )) { py; continue; } if(x==0) { if(y<0) y = -y; if(y%2 == 0) py; else pn; continue; } if(x>0 && x%2==1 && ( y>=(-x)+1 && y<=x+1)) { py; continue; } if(x<0 && (-x)%2==0 && ( y>=x && y<=(-x) )) { py; continue; } if(y%2==0 || (-y)%2==0) { if(y>0 && ( x>=(-y) && x<=y-1 )) { py; continue; } if(y<0 && ( x>=y && x<=(-y)+1 )) { py; continue; } } pn; } }
int main() { lli n,m,i,q,l,r; scanint(&n); scanint(&m); build(1,1,n); tree ans; for(i=1;i<=m;i++) { scanint(&q); scanint(&l); scanint(&r); if(q==0) update(1,1,n,l,r); if(q==1) { ans=qurrey(1,1,n,l,r); printf("%d\n",ans.on); //printf("%lld,%lld,%lld\n\n",ans.on,ans.off,ans.lazy); } //for(j=1;j<=3;j++) //printf("%lld,%lld,%lld\n",seg[j].on,seg[j].off,seg[j].lazy); //printf("\n"); } return 0; }
int main() { int t,n,max,k,i; scanint(t); while(t--) { scanint(n); int a[n],b[n]; max=0; for(i=0;i<n;i++) { scanint(a[i]); scanint(b[i]); if(max<a[i]) { max=a[i]; k=i; } } // printf("%d %d\n",max,k+1); for(i=0;i<n;i++) { if(b[i]>max && i!=k ) break; } if(i!=n) printf("-1\n"); else printf("%d\n",k+1); } }
int main() { int t,mod; ull n; scanint(t); while(t--) { scanf("%llu",&n); scanint(mod); } return 0; }
int main() { int noOfTest=0,rangeLen; scanint(noOfTest); long long count,divisor=0; for(int i=0;i<noOfTest;++i) { scanint(rangeLen); count=process(rangeLen); long long temp=(long long)rangeLen*rangeLen; divisor=greatestCDivisor(count,temp); printf("%lld/%lld\n",count/divisor,temp/divisor); } return 0; }
static int aclrscan2( /* get an ASCII color scanline */ register COLOR *scan, register int len, FILE *fp ) { while (len-- > 0) { colval(scan[0],RED) = fltv(scanint(fp)); colval(scan[0],GRN) = fltv(scanint(fp)); colval(scan[0],BLU) = fltv(scanint(fp)); scan++; } return(0); }
static int aclrscan( /* get an ASCII color scanline */ register COLR *scan, register int len, FILE *fp ) { while (len-- > 0) { scan[0][RED] = normval(scanint(fp)); scan[0][GRN] = normval(scanint(fp)); scan[0][BLU] = normval(scanint(fp)); scan++; } return(0); }
int main() { int t; long long n,i,num=0,den=0,r=0,k; scanf("%d",&t); while(t--) { num=0,den=0; //scanf("%lld",&n); n=scanint(); r=sqrt(n); for(i=1,k=1;i<r;i++,k++) { num+= (n/i) ; num+= k*(floor(n/k)-floor(n/(k+1))); } num+= (n/r); num+=r*(floor(n/r)-r); den=n*n; long long GCD=gcd(num,den); num/=GCD; den/=GCD; printf("%lld/%lld\n",num,den); } return 0; }
int teacher_form(char *database){ refresh(); teacher xteacher; noecho(); WINDOW *win; int y,x; start_color(); getmaxyx(stdscr,y,x); win = newwin(0, 0, 0, 0); init_pair(1, COLOR_RED, COLOR_BLACK); box(win, 0, 0); print_in_middle(win, y/4 + 1, 0, x, "Enter the Name of Teacher", COLOR_PAIR(1)); print_form_str(win,y,x); scanstr(win,xteacher.name, x/3 - 1); clear(); refresh(); box(win, 0, 0); print_in_middle(win, y/4 + 1, 0, x, "Enter the weekly hours for the teacher", COLOR_PAIR(1)); print_form_int(win, y, x); xteacher.week_time = scanint(win); add_teacher(database, &xteacher); refresh(); endwin(); clear(); return 0; }
int main() { long long int n,temp,i,t,sum[1000010]; sum[0]=temp=0; for (i = 1;i<1000010; ++i) { temp=(temp+i*i*i)%MOD; sum[i]=(sum[i-1]+temp)%MOD; } scanint(t); while(t--) { scanint(n); printf("%lld\n",sum[n]); } return 0; }
int main() { int T, B, LS, sqB, sqLS; float RSMin, RSMax; scanint(&T); while(T--) { scanint(&B); scanint(&LS); sqB = B * B; sqLS = LS * LS; RSMin = sqrtf(sqLS - sqB); RSMax = sqrtf(sqLS + sqB); printf("%f %f\n", RSMin, RSMax); } return 0; }
int main() { int t,R1,R2,R3; double r1,r2,r3,r; scanint(t); while(t--) { scanint(R1); scanint(R2); scanint(R3); r1=(double)R1; r2=(double)R2; r3=(double)R3; r= (r1*r2*r3)/(r1*r2+r1*r3+r2*r3+2*pow(r1*r2*r3*(r1+r2+r3),0.5)); printf("%.6lf\n",r); } return 0; }
int main() { int N, i, j, G[V][V], Sol[V][V]; scanint(&N); for(i = 0; i < N; i++) for(j = 0; j < N; j++) scanint(&G[i][j]); for(i = 0; i < N; i++) for(j = 0; j < N; j++) Sol[i][j] = 0; MazeRecur(N, G, Sol, 0, 0, N-1, N-1); printf("%d\n", paths); return 0; }
int main() { int T; scanint(&T); while(T--) { } return 0; }
int main() { int t; scanint(t); while(t--) { } return 0; }
/*{ return b==0?a:gcd(b,a%b); }*/ int main() { int t,x,n,ans; scanint(t); while(t--) { scanint(n); for (int i = 1; i <= n; ++i) { scanint(x); ans=(i==1)?x:gcd(x,ans); } if(ans==1) printf("%d\n",n); else printf("-1\n"); } return 0; }
int main() { long long a[1000001],t,i,n,w,sum,start,sum2,count,l,max,min; scanint(&t); while(t--) { sum=0;count=0;max=0,min=1000001; scanint(&n); scanint(&w); count+=0; for(i=1;i<=n;i++) scanint(&a[i]); start=0; for(i=start+1;i<=n;i++) { if(a[i]>max) max=a[i]; if(a[i]<min) min=a[i]; sum+=a[i]; l=i-start; if(l>=w) { sum2=max*(max+1)/2; sum2-=(min-1)*(min)/2; if(sum==sum2) count++; } if(i==n) { max=0; min=1000001; start++; i=start; sum=0; } } printint(count); } return 0; }
int main() { int t,h,w; scanf("%d",&t); while(t--) { scanf("%d %d",&h,&w); // int mat[h][w]; int ans[h][w]; int temp; for(int j=0;j<w;j++) scanint(ans[0][j]); for(int i=1;i<h-1;i++){ scanint(temp); ans[i][0]=temp+max(ans[i-1][0],ans[i-1][1]); for(int j=1;j<w-1;j++) { scanint(temp); ans[i][j]=temp+max(max(ans[i-1][j-1],ans[i-1][j]),ans[i-1][j+1]); } scanint(temp); ans[i][w-1]=temp+max(ans[i-1][w-1],ans[i-1][w-2]); } int fin=0; scanint(temp); ans[h-1][0]=temp+max(ans[h-2][0],ans[h-2][1]); if(ans[h-1][0]>fin) fin=ans[h-1][0]; for(int j=1;j<w-1;j++){ scanint(temp); ans[h-1][j]=temp+max(max(ans[h-2][j-1],ans[h-2][j]),ans[h-2][j+1]); if(ans[h-1][j]>fin) fin=ans[h-1][j]; } scanint(temp); ans[h-1][w-1]=temp+max(ans[h-2][w-2],ans[h-2][w-1]); if(ans[h-1][w-1]>fin) fin=ans[h-1][w-1]; printf("%d\n",fin); } return 0; }
int main() { int t, n, i, count, speed, min_speed; scanint(&t); while(t--) { scanint(&n); min_speed = INT_MAX; count = 0; for(i = 0; i < n; i++) { scanint(&speed); if(speed <= min_speed) { count++; min_speed = speed; } } printf("%d\n", count); } return 0; }
int main() { int k,n,i,ret; for(k=1;; k++) { scanint(n); if(n==0) break; for(i=0; i<n; i++) { scanint(cost[i][0]); scanint(cost[i][1]); scanint(cost[i][2]); } ret=compute(n); printf("%d. %d\n",k,ret); } return 0; }
int main() { unsigned long M, N, q, Min, Max, Mid, c; scanint(&N); scanint(&M); Min = N + 2; Max = 3 * N; Mid = 2 * N + 1; while(M--) { scanint(&q); if(q < Min) c = 0; else if(q <= Mid) c = q - Min + 1; else c = Max - q + 1; printf("%lu\n", c); } return 0; }
int main() { int T, N, K, i, evens, n; scanint(&T); while(T--) { scanint(&N); scanint(&K); evens = 0; FOR(i, N) { scanint(&n); if(!(n & 0x00000001)) evens++; } if(K == 0 && evens == N) printf("NO\n"); else if(K <= evens) printf("YES\n"); else printf("NO\n"); }
int main() { int t; long long int n,i; scanf("%d",&t); while(t--) { scanint(n); for(i = n ; ;++i) { if( isSUM(i)==1) { printf("%lld\n", i); break; } } } return 0; }
int read_int(char *prompt, char *unit, int def, int min, int max) { if (min > max) { int tmp = min; min = max; max = tmp; } if (def < min) def = min; if (def > max) def = max; int intero; short esito; short failed = 0; for (int timeout = 0; timeout <= 5; timeout++) { fprintf(FPTR, "%s ", prompt); if (failed) fprintf(FPTR, "(%d::%d) ", min, max); fprintf(FPTR, "[%d%s] > ", def, unit); esito = scanint(&intero); switch (esito) { case EASYIO_DEFAULT : return (def); case EASYIO_OKAY : if ((intero >= min) && (intero <= max)) return (intero); case EASYIO_ERROR : beep(); failed = 1; break; } } fprintf(FPTR, "\n FATAL ERROR: too many wrong attempts "); fprintf(FPTR, "in read_int() \n"); exit(-1); return (false); // not used: just to be nice with the compiler }
int main() { lli cas,t,n,q,l,r,i; scanint(&t); cas=t; while(t--) { printf("Scenario #%d:\n\n",cas-t); scanint(&n); scanint(&q); for(i=1;i<=n;i++) scanint(&arr[i]); build(1,1,n); while(q--) { scanint(&l); scanint(&r); printf("%d\n\n",qurrey(1,1,n,l,r)); } } return 0; }
/* Initialization of adventure play variables */ void initplay(void) { turns = 0; /* initialize location status array */ setmem(cond, (sizeof(int)) * MAXLOC, 0); scanint(&cond[1], "5,1,5,5,1,1,5,17,1,1,"); scanint(&cond[13], "32,0,0,2,0,0,64,2,"); scanint(&cond[21], "2,2,0,6,0,2,"); scanint(&cond[31], "2,2,0,0,0,0,0,4,0,2,"); scanint(&cond[42], "128,128,128,128,136,136,136,128,128,"); scanint(&cond[51], "128,128,136,128,136,0,8,0,2,"); scanint(&cond[79], "2,128,128,136,0,0,8,136,128,0,2,2,"); scanint(&cond[95], "4,0,0,0,0,1,"); scanint(&cond[113], "4,0,1,1,"); scanint(&cond[122], "8,8,8,8,8,8,8,8,8,"); /* initialize object locations */ setmem(place, (sizeof(int)) * MAXOBJ, 0); scanint(&place[1], "3,3,8,10,11,0,14,13,94,96,"); scanint(&place[11], "19,17,101,103,0,106,0,0,3,3,"); scanint(&place[23], "109,25,23,111,35,0,97,"); scanint(&place[31], "119,117,117,0,130,0,126,140,0,96,"); scanint(&place[50], "18,27,28,29,30,"); scanint(&place[56], "92,95,97,100,101,0,119,127,130,"); /* initialize second (fixed) locations */ setmem(fixed, (sizeof(int)) * MAXOBJ, 0); scanint(&fixed[3], "9,0,0,0,15,0,-1,"); scanint(&fixed[11], "-1,27,-1,0,0,0,-1,"); scanint(&fixed[23], "-1,-1,67,-1,110,0,-1,-1,"); scanint(&fixed[31], "121,122,122,0,-1,-1,-1,-1,0,-1,"); scanint(&fixed[62], "121,-1,"); /* initialize default verb messages */ scanint(actmsg, "0,24,29,0,33,0,33,38,38,42,14,"); scanint(&actmsg[11], "43,110,29,110,73,75,29,13,59,59,"); scanint(&actmsg[21], "174,109,67,13,147,155,195,146,110,13,13,"); /* initialize various flags and other variables */ setmem(visited, (sizeof(int)) * MAXLOC, 0); setmem(prop, (sizeof(int)) * MAXOBJ, 0); setmem(&prop[50], (sizeof(int)) * (MAXOBJ - 50), 0xff); wzdark = closed = closing = holding = detail = 0; limit = 100; tally = 15; tally2 = 0; newloc = 3; loc = oldloc = oldloc2 = 1; knfloc = 0; chloc = 114; chloc2 = 140; /* dloc[DWARFMAX-1] = chloc */ scanint(dloc, "0,19,27,33,44,64,114,"); scanint(odloc, "0,0,0,0,0,0,0,"); dkill = 0; scanint(dseen, "0,0,0,0,0,0,0,"); clock1 = 30; clock2 = 50; panic = 0; bonus = 0; numdie = 0; daltloc = 18; lmwarn = 0; foobar = 0; dflag = 0; gaveup = 0; saveflg = 0; }
static int scanpp(void) { int c, t; if (Rejected != -1) { t = Rejected; Rejected = -1; strcpy(Text, Rejtext); Value = Rejval; return t; } for (;;) { Value = 0; c = skip(); memset(Text, 0, 4); Text[0] = c; switch (c) { case '!': if ((c = next()) == '=') { Text[1] = '='; return NOTEQ; } else { putback(c); return XMARK; } case '%': if ((c = next()) == '=') { Text[1] = '='; return ASMOD; } else { putback(c); return MOD; } case '&': if ((c = next()) == '&') { Text[1] = '&'; return LOGAND; } else if ('=' == c) { Text[1] = '='; return ASAND; } else { putback(c); return AMPER; } case '(': return LPAREN; case ')': return RPAREN; case '*': if ((c = next()) == '=') { Text[1] = '='; return ASMUL; } else { putback(c); return STAR; } case '+': if ((c = next()) == '+') { Text[1] = '+'; return INCR; } else if ('=' == c) { Text[1] = '='; return ASPLUS; } else { putback(c); return PLUS; } case ',': return COMMA; case '-': if ((c = next()) == '-') { Text[1] = '-'; return DECR; } else if ('=' == c) { Text[1] = '='; return ASMINUS; } else if ('>' == c) { Text[1] = '>'; return ARROW; } else { putback(c); return MINUS; } case '/': if ((c = next()) == '=') { Text[1] = '='; return ASDIV; } else { putback(c); return SLASH; } case ':': return COLON; case ';': return SEMI; case '<': if ((c = next()) == '<') { Text[1] = '<'; if ((c = next()) == '=') { Text[2] = '='; return ASLSHIFT; } else { putback(c); return LSHIFT; } } else if ('=' == c) { Text[1] = '='; return LTEQ; } else { putback(c); return LESS; } case '=': if ((c = next()) == '=') { Text[1] = '='; return EQUAL; } else { putback(c); return ASSIGN; } case '>': if ((c = next()) == '>') { Text[1] = '>'; if ((c = next()) == '=') { Text[1] = '='; return ASRSHIFT; } else { putback(c); return RSHIFT; } } else if ('=' == c) { Text[1] = '='; return GTEQ; } else { putback(c); return GREATER; } case '?': return QMARK; case '[': return LBRACK; case ']': return RBRACK; case '^': if ((c = next()) == '=') { Text[1] = '='; return ASXOR; } else { putback(c); return CARET; } case '{': return LBRACE; case '|': if ((c = next()) == '|') { Text[1] = '|'; return LOGOR; } else if ('=' == c) { Text[1] = '='; return ASOR; } else { putback(c); return PIPE; } case '}': return RBRACE; case '~': return TILDE; case EOF: strcpy(Text, "<EOF>"); return XEOF; case '\'': Text[1] = Value = scanch(); if ((c = next()) != '\'') error( "expected '\\'' at end of char literal", NULL); Text[2] = '\''; return INTLIT; case '"': Value = scanstr(Text); return STRLIT; case '#': Text[0] = '#'; scanident(next(), &Text[1], TEXTLEN-1); if ((t = keyword(Text)) != 0) return t; error("unknown preprocessor command: %s", Text); return IDENT; case '.': if ((c = next()) == '.') { Text[1] = Text[2] = '.'; Text[3] = 0; if ((c = next()) == '.') return ELLIPSIS; putback(c); error("incomplete '...'", NULL); return ELLIPSIS; } putback(c); return DOT; default: if (isdigit(c)) { Value = scanint(c); return INTLIT; } else if (isalpha(c) || '_' == c) { Value = scanident(c, Text, TEXTLEN); if (Expandmac && macro(Text)) break; if ((t = keyword(Text)) != 0) return t; return IDENT; } else { cerror("funny input character: %s", c); break; } } } }
int main() { long long x,pos=0,temp; long long arr[100001]; scanf("%lld",&x); long long ans=0,total=0; while(x--) { //scanf("%lld",&temp); temp=scanint(); if(temp<0) { //a[pos]=-1*temp; total+=(-1*temp); arr[pos]=-1*temp; pos++; } } scanf("%lld",&x); if(x==0 || pos==0) { printf("0"); return 0; } else if(x>=pos) { printf("%lld",total); return 0; } else { long long i,k=pos-x; //sort(a,a+pos); long long from = 0, to = pos-1,r=0,mid=0,tmp,w; // if from == to we reached the kth element while (from < to) { r = from, w = to; mid = arr[(r + w) / 2]; // stop if the reader and writer meets while (r < w) { if (arr[r] >= mid) { // put the large values at the end tmp = arr[w]; arr[w] = arr[r]; arr[r] = tmp; w--; } else { // the value is smaller than the pivot, skip r++; } } // if we stepped up (r++) we need to step one down if (arr[r] > mid) r--; // the r pointer is on the end of the first k elements if (k <= r) { to = r; } else { from = r + 1; } } ans=x*arr[k]; for(i=pos-x+1;i<pos;i++) ans+= (arr[i]-arr[k]); printf("%lld",ans); } return 0; }
char * kill_procs(char *str) { register char *nptr; int signum = SIGTERM; /* default */ int procnum; struct sigdesc *sigp; int uid; /* reset error array */ ERR_RESET; /* remember our uid */ uid = getuid(); /* skip over leading white space */ while (isspace(*str)) str++; if (str[0] == '-') { /* explicit signal specified */ if ((nptr = next_field(str)) == NULL) { return (" kill: no processes specified"); } if (isdigit(str[1])) { (void) scanint(str + 1, &signum); if (signum <= 0 || signum >= NSIG) { return (" invalid signal number"); } } else { /* translate the name into a number */ for (sigp = sigdesc; sigp->name != NULL; sigp++) { if (strcmp(sigp->name, str + 1) == 0) { signum = sigp->number; break; } } /* was it ever found */ if (sigp->name == NULL) { return (" bad signal name"); } } /* put the new pointer in place */ str = nptr; } /* loop thru the string, killing processes */ do { if (scanint(str, &procnum) == -1) { ERROR(str, 0); } else { /* check process owner if we're not root */ if (uid && (uid != proc_owner(procnum))) { ERROR(str, EACCES); } /* go in for the kill */ else if (kill(procnum, signum) == -1) { /* chalk up an error */ ERROR(str, errno); } } } while ((str = next_field(str)) != NULL); /* return appropriate error string */ return (err_string()); }
char * renice_procs(char *str) { register char negate; int prio; int procnum; int uid; ERR_RESET; uid = getuid(); /* allow for negative priority values */ if ((negate = (*str == '-')) != 0) { /* move past the minus sign */ str++; } /* use procnum as a temporary holding place and get the number */ procnum = scanint(str, &prio); /* negate if necessary */ if (negate) { prio = -prio; } #if defined(PRIO_MIN) && defined(PRIO_MAX) /* check for validity */ if (procnum == -1 || prio < PRIO_MIN || prio > PRIO_MAX) { return (" bad priority value"); } #endif /* move to the first process number */ if ((str = next_field(str)) == NULL) { return (" no processes specified"); } #ifdef HAVE_SETPRIORITY /* loop thru the process numbers, renicing each one */ do { if (scanint(str, &procnum) == -1) { ERROR(str, 0); } /* check process owner if we're not root */ else if (uid && (uid != proc_owner(procnum))) { ERROR(str, EACCES); } else if (setpriority(PRIO_PROCESS, procnum, prio) == -1) { ERROR(str, errno); } } while ((str = next_field(str)) != NULL); /* return appropriate error string */ return (err_string()); #else return (" operation not supported"); #endif }