int main(int argc, char *argv[]) { long long int t = 1, n, trigraph[100010][3], i; while(1) { n = glong(); if(n == 0) break; for (i = 0; i < n; ++i) { trigraph[i][0] = glong(); trigraph[i][1] = glong(); trigraph[i][2] = glong(); } plong(t); putchar_unlocked('.'); putchar_unlocked(' '); if(n == 2) plong(minpath1(trigraph, n)); else plong(minpath2(trigraph, n)); putchar_unlocked('\n'); t++; } return 0; }
static inline int puts_unlocked(const char* s) { while (*s) { if (putchar_unlocked(*s++) < 0) return EOF; } if (putchar_unlocked('\n') < 0) return EOF; return 1; }
static void cut_bytes(FILE *stream ) { size_t byte_idx ; _Bool print_delimiter ; int c ; _Bool range_start ; _Bool *rs ; _Bool *tmp ; _Bool tmp___0 ; { byte_idx = 0UL; print_delimiter = (_Bool)0; while (1) { c = getc_unlocked(stream); if (c == 10) { putchar_unlocked('\n'); byte_idx = 0UL; print_delimiter = (_Bool)0; } else { if (c == -1) { if (byte_idx > 0UL) { putchar_unlocked('\n'); } else { } break; } else { if (output_delimiter_specified) { tmp = & range_start; } else { tmp = (_Bool *)((void *)0); } rs = tmp; byte_idx ++; tmp___0 = print_kth(byte_idx, rs); if (tmp___0) { if (rs) { if (*rs) { if (print_delimiter) { fwrite_unlocked((void const */* __restrict */)output_delimiter_string, sizeof(char ), output_delimiter_length, (FILE */* __restrict */)stdout); } else { } } else { } } else { } print_delimiter = (_Bool)1; putchar_unlocked(c); } else { } } } } return; } }
void inline print(unsigned int *res) { register unsigned int N = * res , rev, count = 0; rev = N; if (N == 0) { putchar_unlocked('0'); // putchar_unlocked('\n'); return ; } while ((rev % 10) == 0) { count++; rev /= 10; } rev = 0; while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10; } while (rev != 0) { putchar_unlocked(rev%10 + '0'); rev /= 10; } while (count--) putchar_unlocked('0'); // putchar_unlocked('\n'); return ; }
inline ppr(long long int xx) { sp=0; while(xx>0) { stk[sp++]=(xx%10)+'0'; xx/=10; } sp--; while(sp>=0) {putchar_unlocked(stk[sp]);sp--;} putchar_unlocked('\n'); }
int main(){ while(scanf("%d",&n)!=EOF){ for(i=0;i<n;++i){ a[i]=rit(); } std::sort(a,a+n); for(i=0;i<n;++i){ if(i)putchar_unlocked(' '); printf("%d",a[i]); } putchar_unlocked('\n'); } }
inline void fastWrite(int a) { char snum[20]; int i=0; do { snum[i++]=a%10+48; a=a/10; }while(a!=0); i=i-1; while(i>=0) putchar_unlocked(snum[i--]); putchar_unlocked('\n'); }
void print(int x) { char arr[10]; int i,z=0; while(x) { arr[z++]=x%10+'0'; x/=10; //putchar(); } while(z) putchar_unlocked(arr[--z]); putchar_unlocked('\n'); }
int main(){ char s[2000]; int t,i,n,j,k; scanf("%d",&t); for(k=1;k<=t;++k){ scanf("%i%s",&i,s); j=0; printf("%d ",k); while(s[j]){ if(j+1==i) {++j;continue;} putchar_unlocked(s[j]); ++j; } putchar_unlocked('\n'); } return 0; }
inline void pint(int a) { register char c; char num[20]; int i = 0; if(a < 0){ putchar_unlocked('-'); a *= -1; } do { num[i++] = a%10 + 48; a /= 10; } while (a != 0); i--; while (i >= 0) putchar_unlocked(num[i--]); }
int main() { char ch; for (char ch = 'A'; ch <= 'Z'; ch++) { putchar(ch); putchar_unlocked(ch); } putchar('\n'); return 0; }
inline void printint(int n) { if(n == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); } else { char buf[20]; buf[19] = '\n'; int i = 18; while(n) { buf[i--] = n % 10 + '0'; n /= 10; } while(buf[i] != '\n') putchar_unlocked(buf[++i]); } }
static void print(Integral x, char c) { int s=0, m=0; char f[20]; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x%10; x /= 10; } if (!s) f[s++] = 0; if (m) putchar_unlocked('-'); while (s--) putchar_unlocked(f[s]+'0'); putchar_unlocked(c); }
void print_d(int n) { int i=10; char output_buffer[11];output_buffer[10]='\n'; do { output_buffer[--i]=(n%10)+'0'; n/=10; } while(n); do { putchar_unlocked(output_buffer[i]); } while(++i<11); }
//int putchar_unlocked(char ch) { return putchar(ch); } inline void writeInt(int x) { ii = 10; do { buf[--ii] = (x % 10) + '0'; x/= 10; }while(x); do { putchar_unlocked(buf[ii]); } while (buf[ii++] != '\n'); }
void write_uint(int x){ int i; static char buf[12]; if(x==0){ putchar_unlocked('0'); return; } for(i=10; x; i--){ buf[i] = '0' + x % 10; x /= 10; } fputs_unlocked(buf+1+i, stdout); }
//int putchar_unlocked(char ch) { return putchar(ch); } inline void writeInt(int x) { int i = 10; char buf[11]; buf[10] = '\n'; do { buf[--i] = (x % 10) + '0'; x/= 10; }while(x); do { putchar_unlocked(buf[i]); } while (buf[i++] != '\n'); }
/* This function assumes that WIDTH <= strlen (s) + 1 */ static void repeat_fasta (char const *s, size_t count) { size_t pos = 0; size_t len = strlen (s); char *s2 = malloc (len + WIDTH); memcpy (s2, s, len); memcpy (s2 + len, s, WIDTH); do { size_t line = MIN(WIDTH, count); fwrite (s2 + pos,1,line,stdout); putchar_unlocked ('\n'); pos += line; if (pos >= len) pos -= len; count -= line; } while (count); free (s2); }
int main() { int t,i; scanf("%d",&t); char a[limits],b[limits]; while(t--) { fflush(stdin); scanf("%s",a); fflush(stdin); scanf("%s",b); int as4=0,ae4=0,ae7=0,as7=0; int bs4=0,be4=0,be7=0,bs7=0; for(i=0;a[i]!='\0';i++) { if(a[i]<'4') as4++; else if(a[i]=='4') ae4++; else if(a[i]<'7') as7++; else if(a[i]=='7') ae7++; if(b[i]<'4') bs4++; else if(b[i]=='4') be4++; else if(b[i]<'7') bs7++; else if(b[i]=='7') be7++; } wh(ae7,bs7,'7') wh(be7,as7,'7') wh(ae7,bs4,'7') wh(be7,as4,'7') wh(be7,ae4,'7') wh(ae7,be4,'7') wh(ae7,be7,'7') wh(ae4,bs4,'4') wh(be4,as4,'4') wh(ae4,be4,'4') putchar_unlocked('\n'); } return 0; }
int puts(const char *str) { int res; lock_lock(&(stdout->lock)); do { res = fputs_unlocked(str, stdout); if(res == EOF) { res = EOF; break; } if(putchar_unlocked('\n') == EOF) { res = EOF; break; } res++; } while(0); lock_unlock(&(stdout->lock)); return res; }
int main(int argc, char *argv[]) { int primes[168] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 }; int t = gint(); int i, a, b, gcd, ans, tmp; while(t--){ a = gint(); b = gint(); gcd = euclid_gcd(a, b); ans = 1; for (i = 0; i < 168; ++i) { if (gcd <= 1) break; tmp = 0; while(!(gcd % primes[i])){ gcd /= primes[i]; tmp++; } ans *= tmp + 1; } if(gcd > 1) ans *= 2; pint(ans); putchar_unlocked('\n'); } return 0; }
void write_uints(int x, int y){ write_uint(x); putchar_unlocked(' '); write_uint(y); putchar_unlocked('\n'); }
int _swift_stdlib_putchar_unlocked(int c) { return putchar_unlocked(c); }
int main(int argc, char *argv[]) { char buffer[BUFSIZ]; wchar_t wbuffer[BUFSIZ]; char *buf; wchar_t *wbuf; FILE *f; off_t off; fpos_t pos; size_t size; int fd, r; char c; wchar_t wc; if ((fd = dup(1)) == -1) err(2, "dup"); if ((dup_stdout = fdopen(fd, "w")) == NULL) err(2, "fdopen"); if ((fd = mkstemp(filename)) == -1) err(2, "mkstemp"); if (write(fd, "0123456789\n\n", 12) != 12 || close(fd)) err(2, "write + close"); /* status */ TEST_UNCHANGED(fwide(f, 0)); TEST_NARROW(fwide(f, -1)); TEST_WIDE(fwide(f, 1)); TEST_UNCHANGED(feof(f)); TEST_UNCHANGED(ferror(f)); TEST_UNCHANGED(fileno(f)); TEST_UNCHANGED(clearerr(f)); /* flush and purge */ TEST_UNCHANGED(fflush(f)); TEST_UNCHANGED(fpurge(f)); /* positioning */ TEST_UNCHANGED(fgetpos(f, &pos)); TEST_UNCHANGED(fgetpos(f, &pos); fsetpos(f, &pos)); TEST_UNCHANGED(ftell(f)); TEST_UNCHANGED(ftello(f)); TEST_UNCHANGED(fseek(f, 1, SEEK_CUR)); TEST_UNCHANGED(fseek(f, 1, SEEK_SET)); TEST_UNCHANGED(fseek(f, 1, SEEK_END)); TEST_UNCHANGED(fseeko(f, 1, SEEK_CUR)); TEST_UNCHANGED(fseeko(f, 1, SEEK_SET)); TEST_UNCHANGED(fseeko(f, 1, SEEK_END)); TEST_UNCHANGED(rewind(f)); /* buffering */ TEST_UNCHANGED(setbuf(f, NULL)); TEST_UNCHANGED(setbuf(f, buffer)); TEST_UNCHANGED(setvbuf(f, buffer, _IONBF, BUFSIZ)); TEST_UNCHANGED(setvbuf(f, buffer, _IOLBF, BUFSIZ)); TEST_UNCHANGED(setvbuf(f, buffer, _IOFBF, BUFSIZ)); TEST_UNCHANGED(setvbuf(f, NULL, _IONBF, 0)); TEST_UNCHANGED(setvbuf(f, NULL, _IOLBF, 0)); TEST_UNCHANGED(setvbuf(f, NULL, _IOFBF, 0)); TEST_UNCHANGED(setbuffer(f, NULL, 0)); TEST_UNCHANGED(setbuffer(f, buffer, BUFSIZ)); TEST_UNCHANGED(setlinebuf(f)); /* locking */ TEST_UNCHANGED(flockfile(f);funlockfile(f)); TEST_UNCHANGED(ftrylockfile(f);funlockfile(f)); /* input */ TEST_NARROW(getc(f)); TEST_NARROW(getc_unlocked(f)); TEST_NARROW(fgetc(f)); TEST_NARROW(c = fgetc(f); ungetc(c, f)); TEST_NARROW(fgets(buffer, BUFSIZ, f)); TEST_NARROW(fscanf(f, "%s\n", buffer)); TEST_NARROW(fgetln(f, &size)); /* output */ TEST_NARROW(putc('c', f)); TEST_NARROW(putc_unlocked('c', f)); TEST_NARROW(fputc('c', f)); TEST_NARROW(fputs("foo", f)); TEST_NARROW(fprintf(f, "%s\n", "foo")); /* input from stdin */ TEST_NARROW_STD(stdin, getchar()); TEST_NARROW_STD(stdin, getchar_unlocked()); TEST_NARROW_STD(stdin, fgets(buffer, BUFSIZ, stdin)); TEST_NARROW_STD(stdin, scanf("%s\n", buffer)); /* output to stdout */ TEST_NARROW_STD(stdout, putchar('c')); TEST_NARROW_STD(stdout, putchar_unlocked('c')); TEST_NARROW_STD(stdout, puts("foo")); TEST_NARROW_STD(stdout, printf("foo")); /* word-size ops */ /* * fread and fwrite are specified as being implemented in * terms of fgetc() and fputc() and therefore must set the * stream orientation to narrow. */ TEST_NARROW(fread(buffer, 4, BUFSIZ / 4, f)); TEST_NARROW(fwrite(buffer, 4, BUFSIZ / 4, f)); /* * getw() and putw() aren't specified anywhere but logically * should behave the same as fread/fwrite. Not all OSes agree: * Solaris 10 has them not changing the orientation. */ TEST_NARROW(getw(f)); TEST_NARROW(putw(1234, f)); /* WIDE CHAR TIME! */ /* input */ TEST_WIDE(getwc(f)); TEST_WIDE(fgetwc(f)); TEST_WIDE(wc = fgetwc(f); ungetwc(wc, f)); TEST_WIDE(fgetws(wbuffer, BUFSIZ, f)); TEST_WIDE(fwscanf(f, L"%s\n", wbuffer)); /* output */ TEST_WIDE(putwc(L'c', f)); TEST_WIDE(fputwc(L'c', f)); TEST_WIDE(fputws(L"foo", f)); TEST_WIDE(fwprintf(f, L"%s\n", L"foo")); /* input from stdin */ TEST_WIDE_STD(stdin, getwchar()); TEST_WIDE_STD(stdin, wscanf(L"%s\n", wbuffer)); /* output to stdout */ TEST_WIDE_STD(stdout, putwchar(L'c')); TEST_WIDE_STD(stdout, wprintf(L"foo")); /* memory streams */ f = open_memstream(&buf, &size); if (!((r = fwide(f, 0)) < 0)) fail(__LINE__, r, "<", "open_memstream()"); fclose(f); f = open_wmemstream(&wbuf, &size); if (!((r = fwide(f, 0)) > 0)) fail(__LINE__, r, ">", "open_wmemstream()"); fclose(f); /* random stuff? */ TEST_UNCHANGED_STD(stderr, perror("foo")); remove(filename); if (failures) exit(1); exit(0); }
static void cut_fields(FILE *stream ) { int c ; size_t field_idx ; _Bool found_any_selected_field ; _Bool buffer_first_field ; _Bool tmp ; int tmp___0 ; ssize_t len ; size_t n_bytes ; int tmp___1 ; int tmp___2 ; unsigned char tmp___3 ; _Bool tmp___4 ; _Bool tmp___5 ; { field_idx = 1UL; found_any_selected_field = (_Bool)0; c = getc_unlocked(stream); if (c == -1) { return; } else { } ungetc(c, stream); tmp = print_kth(1UL, (_Bool *)((void *)0)); if (tmp) { tmp___0 = 0; } else { tmp___0 = 1; } buffer_first_field = (_Bool )((int )suppress_non_delimited ^ tmp___0); while (1) { if (field_idx == 1UL) { if (buffer_first_field) { len = getndelim2(& field_1_buffer, & field_1_bufsize, 0UL, 4294967295UL, (int )delim, '\n', stream); if (len < 0L) { free((void *)field_1_buffer); field_1_buffer = (char *)((void *)0); tmp___1 = ferror_unlocked(stream); if (tmp___1) { break; } else { tmp___2 = feof_unlocked(stream); if (tmp___2) { break; } else { } } xalloc_die(); } else { } n_bytes = (unsigned long )len; if (! (n_bytes != 0UL)) { __assert_fail("n_bytes != 0", "cut.c", 626U, "cut_fields"); } else { } tmp___3 = to_uchar(*(field_1_buffer + (n_bytes - 1UL))); if ((int )tmp___3 != (int )delim) { if (! suppress_non_delimited) { fwrite_unlocked((void const */* __restrict */)field_1_buffer, sizeof(char ), n_bytes, (FILE */* __restrict */)stdout); if ((int )*(field_1_buffer + (n_bytes - 1UL)) != 10) { putchar_unlocked('\n'); } else { } } else { } continue; } else { } tmp___4 = print_kth(1UL, (_Bool *)((void *)0)); if (tmp___4) { fwrite_unlocked((void const */* __restrict */)field_1_buffer, sizeof(char ), n_bytes - 1UL, (FILE */* __restrict */)stdout); found_any_selected_field = (_Bool)1; } else { } field_idx ++; } else { } } else { } if (c != -1) { tmp___5 = print_kth(field_idx, (_Bool *)((void *)0)); if (tmp___5) { if (found_any_selected_field) { fwrite_unlocked((void const */* __restrict */)output_delimiter_string, sizeof(char ), output_delimiter_length, (FILE */* __restrict */)stdout); } else { } found_any_selected_field = (_Bool)1; while (1) { c = getc_unlocked(stream); if (c != (int )delim) { if (c != 10) { if (! (c != -1)) { break; } else { } } else { break; } } else { break; } putchar_unlocked(c); } } else { while (1) { c = getc_unlocked(stream); if (c != (int )delim) { if (c != 10) { if (! (c != -1)) { break; } else { } } else { break; } } else { break; } } } } else { } if (c == 10) { c = getc_unlocked(stream); if (c != -1) { ungetc(c, stream); c = '\n'; } else { } } else { } if (c == (int )delim) { field_idx ++; } else { if (c == 10) { goto _L; } else { if (c == -1) { _L: if (found_any_selected_field) { putchar_unlocked('\n'); } else { if (suppress_non_delimited) { if (! (field_idx == 1UL)) { putchar_unlocked('\n'); } else { } } else { putchar_unlocked('\n'); } } if (c == -1) { break; } else { } field_idx = 1UL; found_any_selected_field = (_Bool)0; } else { } } } } return; } }
int main(int argc, char **argv) { FILE *fp; char bufchar; input_state_t input_state = IS_NORMAL; int exit_code = 0; int remove_whitespace = 0; int arg; if(argc < 2) usage(argv); for(arg=2; arg<argc; arg++) { switch(argv[arg][0]) { case 'r': remove_whitespace++; break; default: usage(argv); } } fp = fopen(argv[1], "r"); if(!fp) { fprintf(stderr, "Error opening %s\n", argv[1]); perror("fopen"); exit(1); } for(;;) { bufchar = getc_unlocked(fp); if (bufchar == EOF) break; switch(input_state) { case IS_NORMAL: if(bufchar == '/') { /* * Might be start of a comment. */ input_state = IS_SLASH; } else { if(!(remove_whitespace && isspace(bufchar))) { putchar_unlocked(bufchar); } } break; case IS_SLASH: switch(bufchar) { case '*': /* * Start of normal comment. */ input_state = IS_IN_COMMENT; break; case '/': /* * Start of 'to-end-of-line' comment. */ input_state = IS_IN_END_COMMENT; break; default: /* * Not the start of comment. Emit the '/' * we skipped last char in case we were * entering a comment this time, then the * current char. */ putchar_unlocked('/'); if(!(remove_whitespace && isspace(bufchar))) { putchar_unlocked(bufchar); } input_state = IS_NORMAL; break; } break; case IS_IN_COMMENT: if(bufchar == '*') { /* * Maybe ending comment... */ input_state = IS_STAR; } break; case IS_STAR: switch(bufchar) { case '/': /* * End of normal comment. */ input_state = IS_NORMAL; break; case '*': /* * Still could be one char away from end * of comment. */ break; default: /* * Still inside comment, no end in sight. */ input_state = IS_IN_COMMENT; break; } break; case IS_IN_END_COMMENT: if(bufchar == '\n') { /* * End of comment. Emit the newline if * appropriate. */ if(!remove_whitespace) { putchar_unlocked(bufchar); } input_state = IS_NORMAL; } break; } /* switch input_state */ } /* main read loop */ /* * Done. */ return(exit_code); }
int VMPI_putchar_unlocked(int c) { return putchar_unlocked( c ); }
void print_d(int n) {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[10];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<10);}