Datasets:

language
stringclasses
5 values
dataset
stringclasses
1 value
code
stringlengths
26
25k
id
stringlengths
10
10
test_IO
listlengths
1
1
C
codenet
#include <stdio.h> #include <stdlib.h> typedef struct { int parent; int right; int left; } BT; BT bt[26]; int n; void Preorder(int a) { if (a == -1) return; printf(" %d", a); Preorder(bt[a].left); Preorder(bt[a].right); } void Inorder(int a) { if (a == -1) return; Inorder(bt[a].left); printf(" %d", a); Inorder(bt[a].right); } void Postorder(int a) { if (a == -1) return; Postorder(bt[a].left); Postorder(bt[a].right); printf(" %d", a); } int main() { int i, j, num, depth = 0; scanf("%d", &n); for (i = 0; i < n; ++i) bt[i].parent = -1; for (i = 0; i < n; i++) { scanf("%d", &num); scanf("%d%d", &(bt[num].left), &(bt[num].right)); if (bt[num].left != -1 && bt[num].right != -1) { bt[bt[num].left].parent = num; bt[bt[num].right].parent = num; } else if (bt[num].left != -1) bt[bt[num].left].parent = num; else if (bt[num].right != -1) bt[bt[num].right].parent = num; } for (i = 0; bt[i].parent != -1; ++i) ; printf("Preorder\n"); Preorder(i); printf("\n"); printf("Inorder\n"); Inorder(i); printf("\n"); printf("Postorder\n"); Postorder(i); printf("\n"); return 0; }
s805561051
[ { "input": "9\n0 1 4\n1 2 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1\n", "output": "Preorder\n 0 1 2 3 4 5 6 7 8\nInorder\n 2 1 3 0 6 5 7 4 8\nPostorder\n 2 3 1 6 7 5 8 4 0\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { unsigned int key; struct node *next; struct node *prev; }; typedef struct node *NodePointer; NodePointer nil; NodePointer listSearch(int); void init(void); void printList(void); void deleteNode(NodePointer); void deleteFirst(void); void deleteLast(void); void delete(int); void insert(int); int main() { int key, n, i; int size = 0; char com[20]; int np = 0, nd = 0; scanf("%d", &n); init(); for (i = 0; i < n; i++) { scanf("%s%d", com, &key); if (com[0] == 'i') { insert(key); np++; size++; } else if (com[0] == 'd') { if (strlen(com) > 6) { if (com[6] == 'F') deleteFirst(); else if (com[6] == 'L') deleteLast(); } else delete (key); nd++; size--; } } printList(); return 0; } NodePointer listSearch(int key) { NodePointer cur = nil->next; while (cur != nil && cur->key != key) cur = cur->next; return cur; } void init(void) { nil = (NodePointer)malloc(sizeof(struct node)); nil->next = nil; nil->prev = nil; } void printList(void) { NodePointer cur = nil->next; int isf = 1; while (1) { if (cur == nil) break; if (isf == 0) printf(" "); printf("%d", cur->key); cur = cur->next; isf = 0; } printf("\n"); } void deleteNode(NodePointer t) { t->prev->next = t->next; t->next->prev = t->prev; free(t); } void deleteFirst(void) { NodePointer t = nil->next; if (t == nil) return; deleteNode(t); } void deleteLast(void) { NodePointer t = nil->prev; if (t == nil) return; deleteNode(t); } void delete(int key) { NodePointer t = listSearch(key); if (t == nil) return; deleteNode(t); } void insert(int key) { NodePointer x; x = (NodePointer)malloc(sizeof(struct node)); x->key = key; x->next = nil->next; nil->next->prev = x; nil->next = x; x->prev = nil; }
s719593355
[ { "input": "7\ninsert 5\ninsert 2\ninsert 3\ninsert 1\ndelete 3\ninsert 6\ndelete 5\n", "output": "6 1 2\n" } ]
C
codenet
#include <stdio.h> int main() { int height, width, i; scanf("%d %d", &height, &width); char input_str[width + 1]; for (i = 0; i < width + 2; i++) { printf("#"); } printf("\n"); for (i = 0; i < height; i++) { scanf("%s", input_str); printf("#%s#\n", input_str); } for (i = 0; i < width + 2; i++) { printf("#"); } printf("\n"); return 0; }
s383338432
[ { "input": "2 3\nabc\narc\n", "output": "#####\n#abc#\n#arc#\n#####\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #define ll long long #define rep(i, l, r) for (ll i = (l); i < (r); i++) #define max(p, q) ((p) > (q) ? (p) : (q)) typedef struct edge { ll s, g, c; } E; typedef struct graph { int vcnt, ecnt; E e[200010]; int id[100010]; } G; int esort(const void* a, const void* b) { E *p = (E*)a, *q = (E*)b; if ((*p).s < (*q).s) return -1; if ((*p).s > (*q).s) return 1; if ((*p).g < (*q).g) return -1; return 1; } G g; void readgraph() { ll n; scanf("%lld", &n); rep(i, 0, n - 1) { ll x, y, c; scanf("%lld%lld%lld", &x, &y, &c); g.e[2 * i].s = x; g.e[2 * i].g = y; g.e[2 * i].c = c; g.e[2 * i + 1].s = y; g.e[2 * i + 1].g = x; g.e[2 * i + 1].c = c; } g.vcnt = n; g.ecnt = 2 * n - 2; qsort(g.e, g.ecnt, sizeof(E), esort); int p = 0; rep(i, 0, g.vcnt) { while (p < g.ecnt && g.e[p].s < i) p++; g.id[i] = p; } g.id[g.vcnt] = g.ecnt; } int* tyokkeitemp; void tyokkeidfs(ll s) { for (int i = g.id[s]; i < g.id[s + 1]; i++) { if (tyokkeitemp[g.e[i].g] == 0) { tyokkeitemp[g.e[i].g] = tyokkeitemp[s] + g.e[i].c; tyokkeidfs(g.e[i].g); } } } int tyokkei() { tyokkeitemp = (int*)calloc(g.vcnt + 10, sizeof(int)); tyokkeitemp[0] = 1; tyokkeidfs(0); int M = 0, Mi; rep(i, 0, g.vcnt) { if (tyokkeitemp[i] > M) { M = tyokkeitemp[i]; Mi = i; } } rep(i, 0, g.vcnt) tyokkeitemp[i] = 0; tyokkeitemp[Mi] = 1; tyokkeidfs(Mi); rep(i, 0, g.vcnt) M = max(M, tyokkeitemp[i]); free(tyokkeitemp); return M - 1; } int main() { readgraph(); printf("%d\n", tyokkei()); }
s073208348
[ { "input": "4\n0 1 2\n1 2 1\n1 3 3\n", "output": "5\n" } ]
C
codenet
#include <stdio.h> #include <string.h> #define MAX 21 void init(int); void move(int); int n, x, y; char fld[MAX][MAX]; int main(void) { int m; while (~scanf("%d", &n), n) { init(n); scanf("%d", &m); move(m); printf("%s\n", n ? "No" : "Yes"); } return 0; } void init(int i) { int a, b; x = y = 10; memset(fld, 0, sizeof(fld)); while (i--) { scanf("%d %d", &a, &b); fld[b][a] = 1; } } void move(int i) { int a, d; char buf[2]; while (i--) { scanf("%1s %d", buf, &a); switch (buf[0]) { case 'N': d = 0; break; case 'E': d = 1; break; case 'S': d = 2; break; case 'W': d = 3; break; } while (a--) { d % 2 ? ~-d ? x-- : x++ : d ? y-- : y++; if (fld[y][x]) { fld[y][x] = 0; n--; } } } }
s065149518
[ { "input": "2\n10 11\n11 12\n2\nN 2\nE 1\n2\n10 11\n11 12\n2\nN 2\nW 1\n3\n0 15\n5 10\n5 15\n5\nW 10\nS 10\nN 20\nE 10\nS 10\n0\n", "output": "Yes\nNo\nNo\n" } ]
C
codenet
#include <stdio.h> int main() { int key, i, j, len, a[101]; scanf("%d", &len); for (i = 0; i < len; i++) scanf("%d", a + i); for (j = 1; j < len; j++) { for (i = 0; i < len; i++) printf(i != 0 ? " %d" : "%d", a[i]); puts(""); key = a[j]; for (i = j - 1; i >= 0 && a[i] > key; i--) a[i + 1] = a[i]; a[i + 1] = key; } for (i = 0; i < len; i++) printf(i != 0 ? " %d" : "%d", a[i]); puts(""); return 0; }
s555338838
[ { "input": "6\n5 2 4 6 1 3\n", "output": "5 2 4 6 1 3\n2 5 4 6 1 3\n2 4 5 6 1 3\n2 4 5 6 1 3\n1 2 4 5 6 3\n1 2 3 4 5 6\n" } ]
C
codenet
#include <stdio.h> int main(void) { int x; scanf("%d", &x); printf("%d\n", x * x * x); return 0; }
s746512291
[ { "input": "2\n", "output": "8\n" } ]
C
codenet
#include <stdio.h> int main() { int n, i, j, q, x[10000], y[500], sum = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &x[i]); } scanf("%d", &q); for (i = 0; i < q; i++) { scanf("%d", &y[i]); } for (i = 0; i < q; i++) { for (j = 0; j < n; j++) { if (y[i] == x[j]) { sum = sum + 1; break; } } } printf("%d\n", sum); return 0; }
s574777006
[ { "input": "5\n1 2 3 4 5\n3\n3 4 1\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int main() { char A[20], B[20], C[20]; scanf("%s %s %s", A, B, C); int la = strlen(A), lb = strlen(B); if (A[la - 1] == B[0] && B[lb - 1] == C[0]) { printf("YES\n"); } else { printf("NO\n"); } return 0; }
s479404625
[ { "input": "rng gorilla apple\n", "output": "YES\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; Node treeMinimum(Node x) { while (x->left != NIL) x = x->left; return x; } Node treeMaximum(Node x) { while (x->right != NIL) x = x->right; return x; } Node treeSearch(Node u, int k) { if (u == NIL || k == u->key) return u; if (k < u->key) return treeSearch(u->left, k); else return treeSearch(u->right, k); } Node treeSuccessor(Node x) { Node y; if (x->right != NIL) return treeMinimum(x->right); y = x->parent; while (y != NIL && x == y->right) { x = y; y = y->parent; } return y; } void treeDelete(Node z) { Node y; Node x; if (z->left == NIL || z->right == NIL) y = z; else y = treeSuccessor(z); if (y->left != NIL) x = y->left; else x = y->right; if (x != NIL) x->parent = y->parent; if (y->parent == NIL) root = x; else if (y == y->parent->left) y->parent->left = x; else y->parent->right = x; if (y != z) z->key = y->key; } void insert(int k) { Node y = NIL; Node x = root; Node z; z = malloc(sizeof(struct node)); z->key = k; z->left = NIL; z->right = NIL; while (x != NIL) { y = x; if (z->key < x->key) { x = x->left; } else { x = x->right; } } z->parent = y; if (y == NIL) root = z; else if (z->key < y->key) y->left = z; else (y->right = z); } void inorder(Node u) { if (u == NIL) return; inorder(u->left); printf(" %d", u->key); inorder(u->right); } void preorder(Node u) { if (u == NIL) return; printf(" %d", u->key); preorder(u->left); preorder(u->right); } int main() { int n, i, x; char com[20]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", com); if (com[0] == 'f') { scanf("%d", &x); Node t = treeSearch(root, x); if (t != NIL) printf("yes\n"); else printf("no\n"); } else if (com[0] == 'i') { scanf("%d", &x); insert(x); } else if (com[0] == 'p') { inorder(root); printf("\n"); preorder(root); printf("\n"); } else if (com[0] == 'd') { scanf("%d", &x); treeDelete(treeSearch(root, x)); } } return 0; }
s957555615
[ { "input": "18\ninsert 8\ninsert 2\ninsert 3\ninsert 7\ninsert 22\ninsert 1\nfind 1\nfind 2\nfind 3\nfind 4\nfind 5\nfind 6\nfind 7\nfind 8\nprint\ndelete 3\ndelete 7\nprint\n", "output": "yes\nyes\nyes\nno\nno\nno\nyes\nyes\n 1 2 3 7 8 22\n 8 2 1 3 7 22\n 1 2 8 22\n 8 2 1 22\n" } ]
C
codenet
#include <math.h> #include <stdio.h> #include <string.h> #define MAX 707106 char tbl[MAX + 1]; int sz; int prime[57100] = { 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}; int sqp[147] = { 4, 9, 25, 49, 121, 169, 289, 361, 529, 841, 961, 1369, 1681, 1849, 2209, 2809, 3481, 3721, 4489, 5041, 5329, 6241, 6889, 7921, 9409, 10201, 10609, 11449, 11881, 12769, 16129, 17161, 18769, 19321, 22201, 22801, 24649, 26569, 27889, 29929, 32041, 32761, 36481, 37249, 38809, 39601, 44521, 49729, 51529, 52441, 54289, 57121, 58081, 63001, 66049, 69169, 72361, 73441, 76729, 78961, 80089, 85849, 94249, 96721, 97969, 100489, 109561, 113569, 120409, 121801, 124609, 128881, 134689, 139129, 143641, 146689, 151321, 157609, 160801, 167281, 175561, 177241, 185761, 187489, 192721, 196249, 201601, 208849, 212521, 214369, 218089, 229441, 237169, 241081, 249001, 253009, 259081, 271441, 273529, 292681, 299209, 310249, 316969, 323761, 326041, 332929, 344569, 351649, 358801, 361201, 368449, 375769, 380689, 383161, 398161, 410881, 413449, 418609, 426409, 434281, 436921, 452929, 458329, 466489, 477481, 491401, 502681, 516961, 528529, 537289, 546121, 552049, 564001, 573049, 579121, 591361, 597529, 619369, 635209, 654481, 657721, 674041, 677329, 683929, 687241, 703921, 727609}; void sieve() { int i, j, k; for (i = 1; i < 147; i++) { k = prime[i]; for (j = sqp[i]; j < MAX; j += k) tbl[j] = 1; } for (sz = 146, i = 853; i <= MAX; i += 2) if (!tbl[i]) prime[sz++] = i; } int base[1000002]; int idx[1000002]; long long pp[41]; int bsch(int x) { int m, l = 0, r = sz; while (l < r) { m = (l + r) >> 1; if (prime[m] == x) return m; if (prime[m] < x) l = m + 1; else r = m; } return l - 1; } int main() { int i, k, p, ans; long long A, B, a, b, j, ll, rr; sieve(); scanf("%lld%lld", &A, &B); a = A - B, b = A + B; if (b <= 1) { puts("0"); return 0; } if (a <= 1) a = 2; sz = bsch((int)sqrt((double)(b >> 1))); memset(idx, 1, sizeof(idx)); for (i = 0; i <= sz; i++) { p = prime[i]; for (k = 1, j = p; j <= b; j *= p) pp[k++] = j; while (--k) { j = pp[k], ll = j * (1 + (a - 1) / j), rr = j * (b / j); for (; ll <= rr; ll += j) { int x = (int)(ll - a); if (!idx[x] || base[x] == p) continue; if (idx[x] < k) idx[x] = 0; else base[x] = p, idx[x] = k; } } } ans = 0, i = (int)(b - a + 1); while (i--) if (idx[i]) ans++; printf("%d\n", ans); return 0; }
s019421829
[ { "input": "18 2\n", "output": "4\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, c, d, i, j; scanf("%d %d %d %d", &a, &b, &c, &d); i = a * b; j = c * d; if (i > j) { printf("%d\n", i); } else { printf("%d\n", j); } return 0; }
s062562864
[ { "input": "3 5 2 7\n", "output": "15\n" } ]
C
codenet
#include <stdio.h> int main(void) { int i, j, k, L, tmp, d, def, end, aj, max, min; for (;;) { int an[20], a1[6], a2[6]; scanf("%d %d", &an[0], &L); if (!L) break; aj = an[0]; end = 0; for (k = 1; k < 21; k++) { for (i = L - 1; i >= 0; i--, aj /= 10) { a1[i] = aj % 10; a2[i] = aj % 10; } for (i = 1; i < L; i++) { for (j = 1; j < L; j++) { if (a1[j - 1] < a1[j]) { tmp = a1[j - 1]; a1[j - 1] = a1[j]; a1[j] = tmp; } if (a2[j - 1] > a2[j]) { tmp = a2[j - 1]; a2[j - 1] = a2[j]; a2[j] = tmp; } } } d = 1; max = 0; min = 0; for (i = L - 1; i >= 0; i--, d *= 10) { max += (a1[i] % 10) * d; min += (a2[i] % 10) * d; } def = max - min; for (i = 0; i < k; i++) { if (def == an[i]) { printf("%d %d %d\n", i, def, k - i); end = 1; break; } } if (end == 1) break; an[k] = def; aj = def; } } return 0; }
s110919613
[ { "input": "2012 4\n83268 6\n1112 4\n0 1\n99 2\n0 0\n", "output": "3 6174 1\n1 862632 7\n5 6174 1\n0 0 1\n1 0 1\n" } ]
C
codenet
#include <stdbool.h> #include <stdio.h> #include <string.h> int main() { int n, m; scanf("%d%d", &n, &m); bool r0[n]; memset(r0, 0x00, n); int r1[n]; int nr1 = 0; for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); if (a > b) { int t = a; a = b; b = t; } if (a == 1) r0[b - 1] = true; if (b == n) r1[nr1++] = a - 1; } bool res = false; for (int i = 0; i < nr1; i++) { if (r0[r1[i]]) res = true; } puts(res ? "POSSIBLE" : "IMPOSSIBLE"); return 0; }
s090095029
[ { "input": "3 2\n1 2\n2 3\n", "output": "POSSIBLE\n" } ]
C
codenet
#include <stdio.h> int linearsearch(int S[], int n, int key) { int i = 0; int count = 0; while (S[i] != key) { i++; if (i >= n) { count = 1; return count; } } return count; } int main() { int i, j, n, q, S[10000], T[10000]; int count = 0, key; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &S[i]); } scanf("%d", &q); for (j = 0; j < q; j++) { scanf("%d", &T[j]); } for (j = 0; j < q; j++) { key = T[j]; if (linearsearch(S, n, key) == 0) { count++; } } printf("%d\n", count); return 0; }
s400146413
[ { "input": "5\n1 2 3 4 5\n3\n3 4 1\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); if (500 * a >= b) printf("Yes\n"); else printf("No\n"); return 0; }
s329517742
[ { "input": "2 900\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> #define gc() getchar_unlocked() int in() { int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } int f1[100], f2[100]; void calc(int n) { int k = n % 10; while (n >= 10) n /= 10; ++f1[10 * k + n], ++f2[n * 10 + k]; } int main() { int i, N, ans; N = in(); while (N) calc(N--); ans = 0; for (i = 0; i < 100; ++i) ans += f1[i] * f2[i]; printf("%d\n", ans); return 0; }
s445709355
[ { "input": "25\n", "output": "17\n" } ]
C
codenet
#include <stdio.h> int x, y; int main() { scanf("%d %d", &x, &y); printf("%d %d\n", x * y, 2 * x + 2 * y); return 0; }
s957824161
[ { "input": "3 5\n", "output": "15 16\n" } ]
C
codenet
#include <stdio.h> int main(void) { int A, B; scanf("%d %d", &A, &B); if (A < 10 && B < 10) printf("%d\n", A * B); else printf("-1\n"); return 0; }
s744346876
[ { "input": "2 5\n", "output": "10\n" } ]
C
codenet
#include <stdio.h> #define N 2000 int num1, math[N + 1]; int main() { int a, num2, ans, sum = 0, math[N + 1]; int i, j; math[0] = 1; scanf("%d", &num1); for (i = 0; i < num1; i++) { scanf("%d", &a); sum += a; for (j = sum - a; j >= 0; j--) { if (math[j] == 1) math[j + a] = 1; } } scanf("%d", &num2); for (i = 0; i < num2; i++) { scanf("%d", &ans); math[ans] == 1 ? printf("yes\n") : printf("no\n"); } return 0; }
s340712303
[ { "input": "5\n1 5 7 10 21\n8\n2 4 17 8 22 21 100 35\n", "output": "no\nno\nyes\nyes\nyes\nyes\nno\nno\n" } ]
C
codenet
#include <stdio.h> #include <string.h> #define LEN 100005 typedef struct pp { char name[100]; int t; } P; P Q[LEN]; int head, tail, n; void enqueue(P x) { Q[tail] = x; tail = (tail + 1) % LEN; } P dequeue() { P x = Q[head]; head = (head + 1) % LEN; return x; } int min(int a, int b) { return a < b ? a : b; } int main() { int elaps = 0, c; int i, q; P u; scanf("%d %d", &n, &q); for (i = 1; i <= n; i++) { scanf("%s", Q[i].name); scanf("%d", &Q[i].t); } head = 1; tail = n + 1; while (head != tail) { u = dequeue(); c = min(q, u.t); u.t -= c; elaps += c; if (u.t > 0) enqueue(u); else { printf("%s %d\n", u.name, elaps); } } return 0; }
s266720248
[ { "input": "5 100\np1 150\np2 80\np3 200\np4 350\np5 20\n", "output": "p2 180\np5 400\np1 450\np3 550\np4 800\n" } ]
C
codenet
#include <stdio.h> #define N 1000 int main(void) { char su[N] = {'0'}; int susum = 0; int j = 0; while (1) { for (j = 0; j <= N; j++) { scanf("%c", &su[j]); if (su[j] == '\n') break; susum = susum + (su[j] - '0'); } if (su[0] == '0') break; printf("%d\n", susum); susum = 0; } return 0; }
s050123290
[ { "input": "123\n55\n1000\n0\n", "output": "6\n10\n1\n" } ]
C
codenet
#include <stdio.h> int main(void) { int a, b, n; int sum; int i, j; while (1) { if (scanf("%d %d %d", &a, &b, &n) == -1) break; a -= a / b * b; sum = 0; for (i = 1; i <= n; i++) { a *= 10; for (j = 9; j >= 0; j--) { if (b * j <= a) break; } a -= b * j; sum += j; } printf("%d\n", sum); } return 0; }
s000061454
[ { "input": "1 2 3\n2 3 4\n5 4 3\n4 3 2\n", "output": "5\n24\n7\n6\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> int main() { int i; char S[6]; scanf("%s", S); for (i = 0; S[i] != '\0'; i++) { if (S[i] == 'A' && S[i + 1] == 'C') { printf("Yes\n"); return 0; } } printf("No\n"); return 0; }
s681783549
[ { "input": "BACD\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, c, d, e, i; scanf("%d%d%d", &a, &b, &c); if (b <= c) { printf("NO\n"); return 0; } else { d = a; e = d % b; for (i = 0; i < b; i++) { d = d % b; if (d == c) { printf("YES\n"); return 0; } else if (i != 0 && d == c) { printf("NO\n"); return 0; } d += a; } } printf("NO\n"); return 0; }
s989417036
[ { "input": "7 5 1\n", "output": "YES\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #include <string.h> #define ll long long #define rep(i, l, r) for (ll i = (l); i < (r); i++) #define repp(i, l, r, k) for (ll i = (l); i < (r); i += (k)) #define INF ((1LL << 62) - (1LL << 31)) #define max(p, q) ((p) > (q) ? (p) : (q)) #define min(p, q) ((p) < (q) ? (p) : (q)) #define bit(n, m) (((n) >> (m)) & 1) int upll(const void* a, const void* b) { return *(ll*)a < *(ll*)b ? -1 : *(ll*)a > *(ll*)b ? 1 : 0; } int downll(const void* a, const void* b) { return *(ll*)a < *(ll*)b ? 1 : *(ll*)a > *(ll*)b ? -1 : 0; } void sortup(ll* a, int n) { qsort(a, n, sizeof(ll), upll); } void sortdown(ll* a, int n) { qsort(a, n, sizeof(ll), downll); } ll pom(ll a, ll n, int m) { ll x = 1; for (a %= m; n; n /= 2) n& 1 ? x = x * a % m : 0, a = a * a % m; return x; } #define MOD 1000000007 #define invp(a, p) pom(a, p - 2, p) typedef struct edge { ll p, i; char s[20]; } E; int esort(const void* a, const void* b) { E *p = (E*)a, *q = (E*)b; if (strcmp((*p).s, (*q).s)) return strcmp((*p).s, (*q).s); if ((*p).p < (*q).p) return 1; return -1; } E data[100]; ll n, m; int main() { scanf("%lld", &n); rep(i, 0, n) { scanf(" %s%lld", data[i].s, &data[i].p); data[i].i = i; } qsort(data, n, sizeof(E), esort); rep(i, 0, n) printf("%lld\n", data[i].i + 1); }
s582614433
[ { "input": "6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n", "output": "3\n4\n6\n1\n5\n2\n" } ]
C
codenet
#include <stdio.h> int main() { int input[4][4], tc; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { scanf("%d", &input[i][j]); } } scanf("%d", &tc); int testcase; for (int i = 0; i < tc; i++) { scanf("%d", &testcase); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (input[i][j] == testcase) { input[i][j] = 0; } } } } if (input[0][0] == 0 && input[1][1] == 0 && input[2][2] == 0) { puts("Yes"); } else if (input[0][2] == 0 && input[1][1] == 0 && input[2][0] == 0) { puts("Yes"); } else if (input[0][0] == 0 && input[0][1] == 0 && input[0][2] == 0) { puts("Yes"); } else if (input[1][0] == 0 && input[1][1] == 0 && input[1][2] == 0) { puts("Yes"); } else if (input[2][0] == 0 && input[2][1] == 0 && input[2][2] == 0) { puts("Yes"); } else if (input[0][0] == 0 && input[1][0] == 0 && input[2][0] == 0) { puts("Yes"); } else if (input[0][1] == 0 && input[1][1] == 0 && input[2][1] == 0) { puts("Yes"); } else if (input[0][2] == 0 && input[1][2] == 0 && input[2][2] == 0) { puts("Yes"); } else { puts("No"); } return 0; }
s467564704
[ { "input": "84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n", "output": "Yes\n" } ]
C
codenet
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int X, A, B, C; int i = 0; int j = 0; int k = 0; int kosu = 0; scanf("%d", &A); scanf("%d", &B); scanf("%d", &C); scanf("%d", &X); X = X / 50; for (i = 0; i <= A; i++) { for (j = 0; j <= B; j++) { for (k = 0; k <= C; k++) { if (X == (10 * i) + (2 * j) + k) kosu++; } } } printf("%d\n", kosu); return 0; }
s205656765
[ { "input": "2\n2\n2\n100\n", "output": "2\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int main(void) { int i, sum = 0; int flag = 0; char x[1002]; scanf("%s", x); do { for (i = 0; i < 1002; i++) { if (x[i] == 0) { printf("%d\n", sum); break; } else { sum += x[i] - 0x30; } } sum = 0; scanf("%s", x); } while (x[0] != 0x30); return 0; }
s218426876
[ { "input": "123\n55\n1000\n0\n", "output": "6\n10\n1\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> int main() { char inputNumbers[5]; char temp[2]; int a, b, c, d; int sum; char symbols[3]; scanf("%s", &inputNumbers); temp[1] = '\0'; temp[0] = inputNumbers[0]; a = atoi(temp); temp[0] = inputNumbers[1]; b = atoi(temp); temp[0] = inputNumbers[2]; c = atoi(temp); temp[0] = inputNumbers[3]; d = atoi(temp); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { if (i == 0) { sum = a + b; symbols[0] = '+'; } else { sum = a - b; symbols[0] = '-'; } if (j == 0) { sum = sum + c; symbols[1] = '+'; } else { sum = sum - c; symbols[1] = '-'; } if (k == 0) { sum = sum + d; symbols[2] = '+'; } else { sum = sum - d; symbols[2] = '-'; } if (sum == 7) { printf("%d%c%d%c%d%c%d=7\n", a, symbols[0], b, symbols[1], c, symbols[2], d); return 0; } } } } return 0; }
s302860389
[ { "input": "1222\n", "output": "1+2+2+2=7\n" } ]
C
codenet
#include <math.h> #include <stdio.h> void main() { int n, d; scanf("%d%d", &n, &d); int point[n + 1][d + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= d; j++) { scanf("%d", &point[i][j]); } } int count = 0; for (int i = 1; i <= n - 1; i++) { for (int j = i + 1; j <= n; j++) { int sum = 0; for (int k = 1; k <= d; k++) { sum = sum + (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]); } double kyori = sqrt(sum); if (ceil(kyori) == floor(kyori)) { count++; } } } printf("%d\n", count); }
s993124238
[ { "input": "3 2\n1 2\n5 5\n-2 8\n", "output": "1\n" } ]
C
codenet
#include <stdio.h> int main(void) { char n[10]; scanf("%s", n); if (((n[0] == n[1]) && (n[1] == n[2])) || ((n[1] == n[2]) && (n[2] == n[3]))) { printf("Yes\n"); } else { printf("No\n"); } return 0; }
s175895052
[ { "input": "1118\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int main() { char str[21]; int i, len; scanf("%s", str); len = strlen(str); for (i = len - 1; i >= 0; i--) { putchar(str[i]); } printf("\n"); return 0; }
s494952667
[ { "input": "w32nimda\n", "output": "admin23w\n" } ]
C
codenet
#include <stdio.h> int main(void) { int n, i, a; scanf("%d", &n); for (i = 1; i <= n; i++) { a = i; if ((a % 3) == 0) { printf(" %d", i); } else { for (; a;) { if ((a % 10) == 3) { printf(" %d", i); a = 0; } a = a / 10; } } } putchar('\n'); return 0; }
s375200717
[ { "input": "30\n", "output": " 3 6 9 12 13 15 18 21 23 24 27 30\n" } ]
C
codenet
#include <stdio.h> #define DAYS 365 int main(void) { int n, i; int nyuyoku_ticket[DAYS], pool_ticket[DAYS]; int nyuyoku_member[DAYS], pool_member[DAYS]; int seiki_ryoukin[DAYS], waribiki_ryoukin[DAYS], saiyasune[DAYS]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d %d %d", &nyuyoku_ticket[i], &pool_ticket[i], &nyuyoku_member[i], &pool_member[i]); if (nyuyoku_member[i] >= 5 && pool_member[i] >= 2) { seiki_ryoukin[i] = (((nyuyoku_ticket[i] * nyuyoku_member[i]) + (pool_ticket[i] * pool_member[i])) * 8) / 10; saiyasune[i] = seiki_ryoukin[i]; } else if (nyuyoku_member[i] >= 5) { seiki_ryoukin[i] = (nyuyoku_ticket[i] * nyuyoku_member[i]) + (pool_ticket[i] * pool_member[i]); waribiki_ryoukin[i] = (((nyuyoku_ticket[i] * nyuyoku_member[i]) + (pool_ticket[i] * 2)) * 8) / 10; if (seiki_ryoukin[i] >= waribiki_ryoukin[i]) { saiyasune[i] = waribiki_ryoukin[i]; } else { saiyasune[i] = seiki_ryoukin[i]; } } else if (pool_member[i] >= 2) { seiki_ryoukin[i] = (nyuyoku_ticket[i] * nyuyoku_member[i]) + (pool_ticket[i] * pool_member[i]); waribiki_ryoukin[i] = (((nyuyoku_ticket[i] * 5) + (pool_ticket[i] * pool_member[i])) * 8) / 10; if (seiki_ryoukin[i] >= waribiki_ryoukin[i]) { saiyasune[i] = waribiki_ryoukin[i]; } else { saiyasune[i] = seiki_ryoukin[i]; } } else { seiki_ryoukin[i] = (nyuyoku_ticket[i] * nyuyoku_member[i]) + (pool_ticket[i] * pool_member[i]); waribiki_ryoukin[i] = (((nyuyoku_ticket[i] * 5) + (pool_ticket[i] * 2)) * 8) / 10; if (seiki_ryoukin[i] >= waribiki_ryoukin[i]) { saiyasune[i] = waribiki_ryoukin[i]; } else { saiyasune[i] = seiki_ryoukin[i]; } } } for (i = 0; i < n; i++) { printf("%d\n", saiyasune[i]); } return 0; }
s867013108
[ { "input": "2\n100 100 1 1\n1000 500 5 2\n", "output": "200\n4800\n" } ]
C
codenet
#include <stdio.h> int main(void) { int i, n, tmp; long long int min = 1000000, max = -1000000, sum = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &tmp); if (min > tmp) min = tmp; if (max < tmp) max = tmp; sum += tmp; } printf("%ld %ld %ld\n", min, max, sum); return 0; }
s552669377
[ { "input": "5\n10 1 5 4 17\n", "output": "1 17 37\n" } ]
C
codenet
#include <stdio.h> int min(int a, int b) { if (a <= b) { return (a); } return (b); } int Chain(int b[10000], int n) { int i, j; int count; int color; int a[10000]; for (i = 0; i < n; i++) { a[i] = b[i]; } for (i = 0; i < n - 4; i++) { if (a[i] != 0 && a[i] == a[i + 1] && a[i] == a[i + 2] && a[i] == a[i + 3]) { #if 0 printf("-----\n"); for (j = 0; j < n; j++){ printf("%d\n", a[j]); } printf("-----\n"); #endif count = 0; color = a[i]; for (j = i; a[j] == color; j++) { a[j] = 0; count++; } for (j = 0; i + j + count < 10000; j++) { a[i + j] = a[i + j + count]; a[i + j + count] = 0; } #if 0 printf("-----\n"); for (j = 0; j < n; j++){ printf("%d\n", a[j]); } printf("-----\n"); getch(); #endif i = 0; } } count = 0; while (a[count] != 0) { count++; } if (count == 4 && a[0] == a[1] && a[0] == a[2] && a[0] == a[3]) { return (0); } return (count); } int main(void) { int n; int i, j; int a[10000]; int ans; int color; while (1) { for (i = 0; i < 10000; i++) { a[i] = 0; } scanf("%d", &n); if (n == 0) { break; } ans = n; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n - 4; i++) { int count[3] = {0, 0, 0}; for (j = i; j < i + 4; j++) { if (a[j] - 1 >= 0) { count[a[j] - 1]++; } } color = 0; for (j = 0; j < 3; j++) { if (count[j] >= 3) { color = j + 1; break; } } if (color != 0) { for (j = i; j < i + 4; j++) { int buf; buf = a[j]; a[j] = color; ans = min(ans, Chain(a, n)); a[j] = buf; } } } printf("%d\n", ans); } return (0); }
s905557267
[ { "input": "12\n3\n2\n1\n1\n2\n3\n2\n2\n2\n1\n1\n3\n12\n3\n2\n1\n1\n2\n3\n2\n1\n3\n2\n1\n3\n0\n", "output": "3\n12\n" } ]
C
codenet
#include <math.h> #include <stdio.h> #include <stdlib.h> int main(void) { int x; scanf("%d", &x); if (x == 1) printf("0\n"); else printf("1\n"); return 0; }
s845656342
[ { "input": "1\n", "output": "0\n" } ]
C
codenet
#include <inttypes.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> typedef struct binaryHeap { void *array; size_t heap_size; size_t max_size; size_t val_size; int (*cmp)(const void *, const void *); } heap; heap *new_binary_heap(const size_t val_size, int (*cmpF)(const void *, const void *)) { heap *h = (heap *)calloc(1, sizeof(heap)); h->array = malloc(val_size * (1 + 1)); h->heap_size = 0; h->max_size = 1; h->val_size = val_size; h->cmp = cmpF; return h; } int32_t get_heap_size(const heap *h) { return h->heap_size; } int is_empty(const heap *h) { return h->heap_size == 0; } void free_heap(heap *h) { free(h->array); free(h); } void init_heap(heap *h) { h->heap_size = 0; } static void heap_func_swap(void *restrict a, void *restrict b, size_t val_size) { if ((val_size & 7) == 0) { uint64_t *p = (uint64_t *)a; uint64_t *q = (uint64_t *)b; val_size /= sizeof(uint64_t); while (val_size--) { uint64_t tmp = *p; *p++ = *q; *q++ = tmp; } } else { uint8_t *p = (uint8_t *)a; uint8_t *q = (uint8_t *)b; while (val_size--) { uint8_t tmp = *p; *p++ = *q; *q++ = tmp; } } } static void heap_func_copy(void *restrict dst, const void *restrict src, size_t val_size) { if ((val_size & 7) == 0) { uint64_t *p = (uint64_t *)src; uint64_t *q = (uint64_t *)dst; val_size /= sizeof(uint64_t); while (val_size--) { *q++ = *p++; } } else { uint8_t *p = (uint8_t *)src; uint8_t *q = (uint8_t *)dst; while (val_size--) { *q++ = *p++; } } } void push(heap *h, const void *val) { if (h->heap_size == h->max_size) { h->max_size = 2 * h->max_size + 1; h->array = realloc(h->array, h->val_size * (h->max_size + 1)); } h->heap_size++; uint8_t *array = (uint8_t *)h->array; size_t k = h->heap_size; const size_t val_size = h->val_size; int (*cmp)(const void *, const void *) = h->cmp; heap_func_copy(array + k * val_size, val, val_size); while (k > 1) { size_t parent = k / 2; if (cmp(array + parent * val_size, array + k * val_size) <= 0) { return; } heap_func_swap(array + parent * val_size, array + k * val_size, val_size); k = parent; } } void pop(heap *h, void *res) { uint8_t *array = (uint8_t *)h->array; const size_t val_size = h->val_size; if (res != NULL) { heap_func_copy(res, array + val_size, val_size); } heap_func_copy(array + val_size, array + val_size * h->heap_size, val_size); h->heap_size--; int (*const cmp)(const void *, const void *) = h->cmp; const size_t n = h->heap_size; size_t k = 1; while (2 * k + 1 <= n) { int c = cmp(array + val_size * 2 * k, array + val_size * (2 * k + 1)); size_t next = 2 * k + (c <= 0 ? 0 : 1); if (cmp(array + val_size * k, array + val_size * next) <= 0) return; heap_func_swap(array + val_size * k, array + val_size * next, val_size); k = next; } if (2 * k <= n && cmp(array + val_size * k, array + val_size * 2 * k) > 0) { heap_func_swap(array + val_size * k, array + val_size * 2 * k, val_size); } } void top(const heap *h, void *res) { uint8_t *array = (uint8_t *)h->array; const size_t val_size = h->val_size; if (res != NULL) { heap_func_copy(res, array + val_size, val_size); } } typedef struct UnionFind { int32_t *parent; int32_t size; } UnionFind; void initUnionFind(UnionFind *u) { for (int32_t i = 0; i < u->size; ++i) { u->parent[i] = -1; } } UnionFind *newUnionFind(const int32_t size) { UnionFind *u = (UnionFind *)calloc(1, sizeof(UnionFind)); u->parent = (int32_t *)calloc(size, sizeof(int32_t)); u->size = size; initUnionFind(u); return u; } void freeUnionFind(UnionFind *u) { free(u->parent); free(u); } int32_t root(UnionFind *u, int32_t x) { int32_t index[32]; int32_t len = 0; while (u->parent[x] >= 0) { index[len++] = x; x = u->parent[x]; } while (len > 0) { u->parent[index[--len]] = x; } return x; } int same(UnionFind *u, int32_t x, int32_t y) { return root(u, x) == root(u, y); } int32_t getSize(UnionFind *u, int32_t x) { return -(u->parent[root(u, x)]); } void unite(UnionFind *u, int32_t x, int32_t y) { x = root(u, x); y = root(u, y); if (x == y) return; if (u->parent[x] > u->parent[y]) { int32_t swap = x; x = y; y = swap; } u->parent[x] += u->parent[y]; u->parent[y] = x; } typedef struct segment_tree_void { void *array; int32_t size; size_t val_size; void (*func)(void *, const void *, const void *); } segment_tree; static inline void segment_tree_memcpy(void *dst, const void *src, size_t size) { uint8_t *p = dst; const uint8_t *q = src; while (size--) { *p++ = *q++; } } segment_tree *new_segment_tree(const void *ini, const int32_t n, const size_t val_size, void (*func)(void *, const void *, const void *)) { int32_t k = 1; while (k < n) k *= 2; segment_tree *s = (segment_tree *)calloc(1, sizeof(segment_tree)); s->array = calloc(2 * k, val_size); s->size = k; s->val_size = val_size; s->func = func; for (int32_t i = k; i < 2 * k; ++i) { segment_tree_memcpy((uint8_t *)s->array + i * val_size, ini, val_size); } uint8_t *a = s->array; for (int32_t i = k - 1; i > 0; --i) { func(a + i * val_size, a + (2 * i) * val_size, a + (2 * i + 1) * val_size); } return s; } void update(segment_tree *const s, int32_t k, const void *val) { k += s->size; uint8_t *p = s->array; const size_t size = s->val_size; segment_tree_memcpy(p + k * size, val, size); for (k >>= 1; k > 0; k >>= 1) { s->func(p + k * size, p + 2 * k * size, p + (2 * k + 1) * size); } } void update_tmp(segment_tree *const s, int32_t k, const void *val) { k += s->size; uint8_t *p = s->array; const size_t size = s->val_size; segment_tree_memcpy(p + k * size, val, size); } void update_all(segment_tree *const s) { uint8_t *const a = s->array; const size_t size = s->val_size; for (int32_t i = s->size - 1; i > 0; --i) { s->func(a + i * size, a + (2 * i) * size, a + (2 * i + 1) * size); } } void find(const segment_tree *s, int32_t l, int32_t r, void *res) { int32_t lindex[32]; int32_t rindex[32]; int32_t llen = 0; int32_t rlen = 0; for (l += s->size, r += s->size; l < r; l >>= 1, r >>= 1) { if (l & 1) lindex[llen++] = l++; if (r & 1) rindex[rlen++] = --r; } const uint8_t *p = s->array; if (llen == 0) { lindex[llen++] = rindex[--rlen]; } segment_tree_memcpy(res, p + lindex[0] * s->val_size, s->val_size); for (int32_t i = 1; i < llen; ++i) { s->func(res, res, p + lindex[i] * s->val_size); } for (int32_t i = rlen - 1; i >= 0; --i) { s->func(res, res, p + rindex[i] * s->val_size); } } typedef int32_t i32; typedef int64_t i64; typedef struct index_val { i32 index; i32 val; } index_val; int cmp_index_val(const void *a, const void *b) { i32 d = ((index_val *)a)->val - ((index_val *)b)->val; return d == 0 ? 0 : d > 0 ? -1 : 1; } typedef struct segment_node { i32 index; i64 val; } segment_node; void func_segment_node(void *c, const void *a, const void *b) { const segment_node *p = (const segment_node *)a; const segment_node *q = (const segment_node *)b; *(segment_node *)c = p->val < q->val ? *p : *q; } typedef struct edge { i32 a, b; i64 c; } edge; int cmp_edge(const void *a, const void *b) { i64 d = ((edge *)a)->c - ((edge *)b)->c; return d == 0 ? 0 : d < 0 ? -1 : 1; } void run(void) { i32 n, d; scanf("%" SCNi32 "%" SCNi32, &n, &d); i32 *a = (i32 *)calloc(n, sizeof(i32)); index_val *p = (index_val *)calloc(n, sizeof(index_val)); for (i32 i = 0; i < n; ++i) { scanf("%" SCNi32, a + i); p[i] = (index_val){i, a[i]}; } qsort(p, n, sizeof(index_val), cmp_index_val); const segment_node ini = {n, (i64)(n + 2) * 1000000000 + 1}; segment_tree *l = new_segment_tree(&ini, n, sizeof(segment_node), func_segment_node); segment_tree *r = new_segment_tree(&ini, n, sizeof(segment_node), func_segment_node); for (i32 i = 0; i < n; ++i) { update_tmp(l, i, &((segment_node){i, a[i] + (i64)(n - 1 - i) * d})); update_tmp(r, i, &((segment_node){i, a[i] + (i64)i * d})); } update_all(l); update_all(r); heap *h = new_binary_heap(sizeof(edge), cmp_edge); for (i32 i = 0; i < n; ++i) { i32 v = p[i].index; if (v > 0) { segment_node t; find(l, 0, v, &t); push(h, &((edge){v, t.index, p[i].val + t.val - (i64)(n - 1 - v) * d})); } if (v + 1 < n) { segment_node t; find(r, v + 1, n, &t); push(h, &((edge){v, t.index, p[i].val + t.val - (i64)v * d})); } update(l, v, &ini); update(r, v, &ini); } i64 sum = 0; UnionFind *u = newUnionFind(n); while (getSize(u, 0) < n) { edge e; pop(h, &e); if (same(u, e.a, e.b)) continue; unite(u, e.a, e.b); sum += e.c; } printf("%" PRIi64 "\n", sum); } int main(void) { run(); return 0; }
s305090452
[ { "input": "3 1\n1 100 1\n", "output": "106\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct _node { int key; struct _node *next; struct _node *prev; } node; node *head; node *makenode(int); void insert(int); void delete(int); void deleteFirst(); void deleteLast(); int main() { int i, n, a; char op[16]; node *x; head = makenode(0); head->next = head; head->prev = head; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", op); if (strcmp(op, "insert") == 0) { scanf("%d", &a); insert(a); } else if (strcmp(op, "delete") == 0) { scanf("%d", &a); delete (a); } else if (strcmp(op, "deleteFirst") == 0) { deleteFirst(); } else if (strcmp(op, "deleteLast") == 0) { deleteLast(); } } x = head; while (x->next != head) { printf("%d", x->next->key); x = x->next; if (x->next != head) { printf(" "); } } printf("\n"); return 0; } node *makenode(int a) { node *x; x = malloc(sizeof(node)); x->key = a; return x; } void insert(int a) { node *x; x = makenode(a); x->next = head->next; head->next->prev = x; head->next = x; x->prev = head; } void delete(int a) { node *x; x = head; while (x->next != head) { x = x->next; if (x->key == a) { x->prev->next = x->next; x->next->prev = x->prev; free(x); break; } } } void deleteFirst() { node *x; x = head->next; head->next = x->next; x->next->prev = head; free(x); } void deleteLast() { node *x; x = head->prev; head->prev = x->prev; x->prev->next = head; free(x); }
s907732757
[ { "input": "7\ninsert 5\ninsert 2\ninsert 3\ninsert 1\ndelete 3\ninsert 6\ndelete 5\n", "output": "6 1 2\n" } ]
C
codenet
#include <stdio.h> int main(void) { int a, b, c, i, j, k; int max; scanf("%d", &j); for (i = 0; i < j; i++) { scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); max = a; k = 0; if (max <= b) { max = b; k = 1; } if (max <= c) { max = c; k = 2; } max = max * max; a = a * a; b = b * b; c = c * c; if (k == 0 && max == b + c) { printf("YES\n"); } else if (k == 1 && max == a + c) { printf("YES\n"); } else if (k == 2 && max == a + b) { printf("YES\n"); } else { printf("NO\n"); } } return (0); }
s791230408
[ { "input": "3\n4 3 5\n4 3 6\n8 8 8\n", "output": "YES\nNO\nNO\n" } ]
C
codenet
#include <stdio.h> int main(void) { int x, y; scanf("%d", &x); y = x * x * x; printf("%d\n", y); return 0; }
s154738543
[ { "input": "2\n", "output": "8\n" } ]
C
codenet
#include <stdio.h> int main(void) { int a, b, c; scanf("%d %d %d", &a, &b, &c); if (a < b && b < c) puts("Yes"); else puts("No"); return 0; }
s168792702
[ { "input": "1 3 8\n", "output": "Yes\n" } ]
C
codenet
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int low[200000]; int high[200000]; int a[200000]; int part(int a[], int b[], int l, int r) { int i, j, x, t; i = l - 1; j = r; x = b[r]; while (1) { while (b[++i] < x) ; while (i < --j && x < b[j]) ; if (i >= j) break; t = a[i]; a[i] = a[j]; a[j] = t; t = b[i]; b[i] = b[j]; b[j] = t; } t = a[i]; a[i] = a[r]; a[r] = t; t = b[i]; b[i] = b[r]; b[r] = t; return i; } void quicksort(int a[], int b[], int n) { int l, r, v; int sp; low[0] = 0; high[0] = n - 1; sp = 1; while (sp > 0) { sp--; l = low[sp]; r = high[sp]; if (l >= r) ; else { v = part(a, b, l, r); if (v - l < r - v) { low[sp] = v + 1; high[sp++] = r; low[sp] = l; high[sp++] = v - 1; } else { low[sp] = l; high[sp++] = v - 1; low[sp] = v + 1; high[sp++] = r; } } } } int main() { int n, m; int i; int a[100006]; int b[100006]; int cnt = 0; int t; scanf("%d %d", &n, &m); for (i = 0; i < m; i++) scanf("%d %d", &a[i], &b[i]); quicksort(a, b, m); t = 0; for (i = 0; i < m; i++) { if (t <= a[i]) { t = b[i]; cnt++; } } printf("%d\n", cnt); return 0; }
s660035552
[ { "input": "5 2\n1 4\n2 5\n", "output": "1\n" } ]
C
codenet
#include <stdio.h> int main() { int n, m; scanf("%d %d", &n, &m); printf("%d\n", (n - 1) * (m - 1)); fflush(stdout); return 0; }
s235028939
[ { "input": "3 4\n", "output": "6\n" } ]
C
codenet
#include <stdio.h> #define MAX 25 typedef struct { int l, r, par; } node; node N[MAX]; void init(int); void Preorder(int); void Inorder(int); void Postorder(int); int main() { int n, i, id, l, r; int p; scanf("%d", &n); init(n); for (i = 0; i < n; i++) { scanf("%d%d%d", &id, &l, &r); if (l != -1) { N[id].l = l; N[l].par = id; } if (r != -1) { N[id].r = r; N[r].par = id; } } for (i = 0; i < n; i++) { if (N[i].par == -1) { p = i; break; } } puts("Preorder"); Preorder(p); puts(""); puts("Inorder"); Inorder(p); puts(""); puts("Postorder"); Postorder(p); puts(""); return 0; } void init(int n) { int i; for (i = 0; i < n; i++) { N[i].par = N[i].l = N[i].r = -1; } } void Preorder(int p) { if (p != -1) { printf(" %d", p); Preorder(N[p].l); Preorder(N[p].r); } } void Inorder(int p) { if (p != -1) { Inorder(N[p].l); printf(" %d", p); Inorder(N[p].r); } } void Postorder(int p) { if (p != -1) { Postorder(N[p].l); Postorder(N[p].r); printf(" %d", p); } }
s120278714
[ { "input": "9\n0 1 4\n1 2 3\n2 -1 -1\n3 -1 -1\n4 5 8\n5 6 7\n6 -1 -1\n7 -1 -1\n8 -1 -1\n", "output": "Preorder\n 0 1 2 3 4 5 6 7 8\nInorder\n 2 1 3 0 6 5 7 4 8\nPostorder\n 2 3 1 6 7 5 8 4 0\n" } ]
C
codenet
#include <stdio.h> int main(void) { int x, y; x = 0; y = 0; scanf("%d", &x); scanf("%d", &y); printf("%d %d\n", x * y, (2 * x) + (2 * y)); return 0; }
s470461127
[ { "input": "3 5\n", "output": "15 16\n" } ]
C
codenet
#include <stdio.h> int main(void) { int n, x, min, m, i; scanf("%d %d %d", &n, &x, &min); x -= min; for (i = 1; i < n; i++) { scanf("%d", &m); x -= m; if (min > m) { min = m; } } printf("%d\n", n + x / min); return 0; }
s539307012
[ { "input": "3 1000\n120\n100\n140\n", "output": "9\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, x, w; while (scanf("%d %d", &a, &b) != EOF) { x = a + b; w = 0; while (x) { w++; x /= 10; } printf("%d\n", w); } return 0; }
s906878895
[ { "input": "5 7\n1 99\n1000 999\n", "output": "2\n3\n4\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #define I 10000 void CountingSort(int *, int *, int); int main() { int *a, *b, i, max = 0, n; scanf("%d", &n); a = (int *)malloc((n + 1) * sizeof(int)); b = (int *)malloc((n + 1) * sizeof(int)); for (i = 0; i < n; i++) { scanf("%d", &a[i + 1]); } CountingSort(a, b, n); printf("%d", b[1]); for (i = 2; i < n + 1; i++) printf(" %d", b[i]); printf("\n"); free(a); free(b); return 0; } void CountingSort(int a[], int b[], int k) { int c[I], i, j; for (i = 0; i <= I; i++) c[i] = 0; for (j = 0; j < k; j++) c[a[j + 1]]++; for (i = 1; i < I + 1; i++) c[i] += c[i - 1]; for (j = k; 0 < j; j--) { b[c[a[j]]] = a[j]; c[a[j]]--; } }
s787964396
[ { "input": "7\n2 5 1 3 2 3 0\n", "output": "0 1 2 2 3 3 5\n" } ]
C
codenet
#include <stdio.h> #define ABS(x) (((x) < (0)) ? (-(x)) : (x)) int main(void) { int N, t, x, y, nx = 0, ny = 0, nt = 0; int i, j, k, tmp; scanf("%d", &N); for (i = 0; i < N; i++) { scanf("%d%d%d", &t, &x, &y); tmp = t - nt - (ABS(x - nx) + ABS(y - ny)); if (tmp < 0 || tmp % 2) { puts("No"); return 0; } } puts("Yes"); return 0; }
s198852827
[ { "input": "2\n3 1 2\n6 1 1\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> int main() { int n; scanf("%d", &n); if (n % 2 == 0) { printf("%d\n", n / 2); } else { printf("%d\n", (n / 2) + 1); } return 0; }
s410235811
[ { "input": "5\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> int main(void) { int x, kotae; scanf("%d", &x); kotae = x * x * x; printf("%d\n", kotae); return 0; }
s389564195
[ { "input": "2\n", "output": "8\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int main() { int n; char s[10010], *c; scanf("%d%*c", &n); while (n--) { fgets(s, 1010, stdin); while (c = strstr(s, "Hoshino")) *(c + 6) = 'a'; printf("%s", s); } return 0; }
s683308527
[ { "input": "3\nHoshino\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.\n", "output": "Hoshina\nHashino\nMasayuki Hoshina was the grandson of Ieyasu Tokugawa.\n" } ]
C
codenet
#include <stdio.h> #define MAX 100 #define INF 999999 #define NIL -1 #define WHITE 0 #define BLACK 2 int prim(); int n, G[MAX][MAX]; int main() { int i, j; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &G[i][j]); } } printf("%d\n", prim()); return 0; } int prim() { int u, i, v, mincost, d[n], pi[n], color[n], sum = 0; for (u = 0; u < n; u++) { d[u] = INF; pi[u] = NIL; color[u] = WHITE; } d[0] = 0; while (1) { mincost = INF; for (i = 0; i < n; i++) { if (color[i] != BLACK && d[i] < mincost) { mincost = d[i]; u = i; } } if (mincost == INF) break; color[u] = BLACK; for (v = 0; v < n; v++) { if (color[v] != BLACK && G[u][v] < d[v] && G[u][v] != -1) { pi[v] = u; d[v] = G[u][v]; } } } for (i = 0; i < n; i++) { if (d[i] != INF) sum += d[i]; } return sum; }
s263479532
[ { "input": "5\n -1 2 3 1 -1\n 2 -1 -1 4 -1\n 3 -1 -1 1 1\n 1 4 1 -1 3\n -1 -1 1 3 -1\n", "output": "5\n" } ]
C
codenet
#include <stdio.h> int main(void) { int N, D; int ans, rem; scanf("%d%d", &N, &D); ans = N / (D * 2 + 1); rem = N % (D * 2 + 1); if (rem != 0) { ans = ans + 1; } printf("%d\n", ans); return 0; }
s753632359
[ { "input": "6 2\n", "output": "2\n" } ]
C
codenet
#include <stdio.h> int main(void) { int A, B, flag = 0; scanf("%d %d", &A, &B); for (int i = 1; i <= 3; ++i) { if ((A * B * i) % 2 == 1) { flag = 1; break; } } if (flag) printf("Yes\n"); else printf("No\n"); return 0; }
s426986656
[ { "input": "3 1\n", "output": "Yes\n" } ]
C
codenet
#include <math.h> #include <stdio.h> int main() { double r; scanf("%lf", &r); printf("%lf %lf\n", r * r * M_PI, 2 * M_PI * r); return 0; }
s388748526
[ { "input": "2\n", "output": "12.566371 12.566371\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int main(void) { char str[201], tmp[101]; char p[101]; int slen, plen; int i, j, flag; scanf("%s %s", str, p); strcpy(tmp, str); strcat(str, tmp); slen = strlen(str); plen = strlen(p); flag = 0; for (i = 0; i < slen - plen; i++) { if (strncmp(&str[i], p, plen) == 0) flag = 1; } if (flag) puts("Yes"); else puts("No"); return 0; }
s387404795
[ { "input": "vanceknowledgetoad\nadvance\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> #define N 1000000 #define Q 50000 int n, S[N], T[Q]; int binarySearch(int key) { int left = 0, right = n, mid; while (left < right) { mid = (left + right) / 2; if (S[mid] == key) return 1; else if (key < S[mid]) right = mid; else left = mid + 1; } return 0; } int main() { int i, j, q, c = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &S[i]); } scanf("%d", &q); for (i = 0; i < q; i++) { scanf("%d", &T[i]); if (binarySearch(T[i]) == 1) c++; } printf("%d\n", c); return 0; }
s190193281
[ { "input": "5\n1 2 3 4 5\n3\n3 4 1\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #include <string.h> void push(int); int pop(); int top, kinbo[1000]; int main() { int chonda, yamagami; top = 0; char null[100]; while (scanf("%s", null) != EOF) { if (null[0] == '+') { chonda = pop(); yamagami = pop(); push(chonda + yamagami); } else if (null[0] == '-') { yamagami = pop(); chonda = pop(); push(chonda - yamagami); } else if (null[0] == '*') { chonda = pop(); yamagami = pop(); push(chonda * yamagami); } else push(atoi(null)); } printf("%d\n", pop()); return 0; } void push(int chonda) { kinbo[++top] = chonda; } int pop() { top--; return kinbo[top + 1]; }
s141680236
[ { "input": "1 2 +\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { char s[26]; scanf("%s", s); for (int j = 0; j < strlen(s); j++) { for (int i = 0; i < strlen(s); i++) { if ((i != j) && (s[i] == s[j])) { puts("no"); return 0; } } } puts("yes"); return 0; }
s882312203
[ { "input": "uncopyrightable\n", "output": "yes\n" } ]
C
codenet
#include <stdio.h> int main() { int x, a; scanf("%d %d", &x, &a); printf("%d\n", (x >= a) * 10); return 0; }
s372829880
[ { "input": "3 5\n", "output": "0\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #define MAX 100000 int Partition(char[], int[], int, int); void Quicksort(char[], int[], int, int); void Merge(char[], int[], int, int, int); void Merge_Sort(char[], int[], int, int); int q; int main(void) { int A[MAX + 1]; char C[MAX + 1]; char MC[MAX + 1]; int MN[MAX + 1]; int i, p, n; int count = 0; scanf("%d", &n); for (i = 1; i <= n; i++) scanf(" %c %d", &C[i], &A[i]); for (i = 1; i <= n; i++) { MC[i] = C[i]; MN[i] = A[i]; } Merge_Sort(MC, MN, 1, n); p = 1; Quicksort(C, A, p, n); for (i = 1; i <= n; i++) { if (MN[i] == A[i] && MC[i] == C[i]) count++; } if (count == n) printf("Stable\n"); else printf("Not stable\n"); for (i = 1; i <= n; i++) printf("%c %d\n", C[i], A[i]); return 0; } int Partition(char C[], int A[], int p, int r) { int i, j; char tmpC, x; int tmpN, y; x = C[r]; y = A[r]; i = p - 1; for (j = p; j < r; j++) { if (A[j] <= y) { i = i + 1; tmpN = A[j]; tmpC = C[j]; A[j] = A[i]; C[j] = C[i]; A[i] = tmpN; C[i] = tmpC; } } tmpN = A[i + 1]; tmpC = C[i + 1]; A[i + 1] = A[r]; C[i + 1] = C[r]; A[r] = tmpN; C[r] = tmpC; return i + 1; } void Quicksort(char C[], int A[], int p, int r) { if (p < r) { q = Partition(C, A, p, r); Quicksort(C, A, p, q - 1); Quicksort(C, A, q + 1, r); } } void Merge(char MC[], int MN[], int left, int mid, int right) { int n1 = mid - left + 1; int n2 = right - mid; int LN[n1 + 1]; int RN[n2 + 1]; int LC[n1 + 1]; int RC[n2 + 1]; int i, j, k; for (i = 1; i <= n1; i++) { LN[i] = MN[left + i - 1]; LC[i] = MC[left + i - 1]; } for (i = 1; i <= n2; i++) { RN[i] = MN[mid + i]; RC[i] = MC[mid + i]; } LN[n1 + 1] = 1000000000; RN[n2 + 1] = 1000000000; i = 1; j = 1; for (k = left; k <= right; k++) { if (LN[i] <= RN[j]) { MN[k] = LN[i]; MC[k] = LC[i++]; } else { MN[k] = RN[j]; MC[k] = RC[j++]; } } } void Merge_Sort(char MC[], int MN[], int left, int right) { int mid; if (left < right) { mid = (left + right) / 2; Merge_Sort(MC, MN, left, mid); Merge_Sort(MC, MN, mid + 1, right); Merge(MC, MN, left, mid, right); } }
s451461278
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1\n", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3\n" } ]
C
codenet
#include <stdio.h> int main() { int n; scanf("%d", &n); int cnt4 = 0, cnt2 = 0; for (int i = 0; i < n; i++) { int wk; scanf("%d", &wk); if (wk % 4 == 0) cnt4++; else if (wk % 2 == 0) cnt2++; } if (cnt4 + cnt2 / 2 >= n / 2) printf("Yes\n"); else printf("No\n"); return 0; }
s237922865
[ { "input": "3\n1 10 100\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #define N 100000 #define INF 1000000 typedef struct { int go, back, cost; } Date; int n, d[N]; Date a[500000]; void root(int); int main() { int i, j, k, u, count = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &u, &k); for (j = 0; j < k; j++) { a[count].back = u; scanf("%d%d", &a[count].go, &a[count].cost); count++; } } root(count); for (i = 0; i < n; i++) printf("%d %d\n", i, d[i]); return 0; } void root(int b) { int i, flag = 1; for (i = 0; i < n; i++) d[i] = INF; d[0] = 0; while (flag != 0) { flag = 0; for (i = 0; i < b; i++) { if (a[i].cost + d[a[i].back] < d[a[i].go]) { d[a[i].go] = a[i].cost + d[a[i].back]; flag = 1; } } } }
s808208135
[ { "input": "5\n0 3 2 3 3 1 1 2\n1 2 0 2 3 4\n2 3 0 3 3 1 4 1\n3 4 2 1 0 1 1 4 4 3\n4 2 2 1 3 3\n", "output": "0 0\n1 2\n2 2\n3 1\n4 3\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #define INF 0x5fffffff int a[100002]; int b[100002]; char buf[700002], *p; int getint() { int n = 0; if (*p == '-') { p++; while (*p >= '0') n = (n << 3) + (n << 1) + (*p++ & 0xf); return -n; } while (*p >= '0') n = (n << 3) + (n << 1) + (*p++ & 0xf); return n; } int main() { int w, i, k, f, close, ans; fgets(p = buf, 10, stdin), w = getint(); fgets(p = buf, sizeof(buf), stdin); for (ans = 0, f = 0, i = 1; i <= w; i++) { a[i] = k = getint(), p++; if (!k) f |= 1; else if (k < 0) f |= 2; else ans += k; } if (!ans || !(f & 1)) { puts("0"); return 0; } if (!(f & 2)) { printf("%d\n", ans); return 0; } for (close = 0, f = 0, i = 1; i <= w; i++) { if (!a[i]) close = INF, f = -1; else if (a[i] < 0) { if (f < 0 || close - (i - f) > -a[i]) close = -a[i], f = i; } else { if (f < 0) b[i] = INF; else { k = close - (i - f); if (k < 0) k = 0; b[i] = k; } } } for (close = 0, f = w, i = w; i >= 1; i--) { if (!a[i]) close = INF, f = -1; else if (a[i] < 0) { if (f < 0 || close - (f - i) > -a[i]) close = -a[i], f = i; } else { if (f < 0) b[i] = INF; else { k = close - (f - i); if (k < 0) k = 0; if (k > b[i]) b[i] = k; } } } for (ans = 0, i = 1; i <= w; i++) { if (a[i] > 0) { if (b[i] > a[i]) ans += a[i]; else ans += b[i]; } } printf("%d\n", ans); return 0; }
s817872520
[ { "input": "7\n2 0 -2 3 2 -2 0\n", "output": "4\n" } ]
C
codenet
#include <stdio.h> int main(void) { int A, B, C, D, E, max; scanf("%d %d", &A, &B); C = A + B; D = A - B; E = A * B; max = C; if (max < D) { max = D; } if (max < E) { max = E; } printf("%d\n", max); return 0; }
s128781606
[ { "input": "-13 3\n", "output": "-10\n" } ]
C
codenet
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> int main() { int i, j, k, n; scanf("%d", &n); printf("%d\n", 24 + (24 - n)); return 0; }
s730748220
[ { "input": "21\n", "output": "27\n" } ]
C
codenet
#include <stdio.h> int main() { char str[30]; gets(str); str[5] = ' '; str[13] = ' '; printf("%s\n", str); return 0; }
s264533675
[ { "input": "happy,newyear,enjoy\n", "output": "happy newyear enjoy\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); if (a == 1) a = 14; if (b == 1) b = 14; if (a < b) printf("Bob\n"); else if (a > b) printf("Alice\n"); else printf("Draw\n"); return 0; }
s961413659
[ { "input": "8 6\n", "output": "Alice\n" } ]
C
codenet
#include <stdio.h> #define INF 100000 #define MAX 101 #define NIL -6 #define WHITE 0 #define GRAY 1 #define BLACK 2 int G[MAX][MAX]; int n; void prim() { int i, j; int d[MAX]; int pi[MAX]; int color[MAX]; int min, u, v, sum = 0; for (i = 0; i < n; i++) { d[i] = INF; pi[i] = NIL; color[i] = WHITE; } d[0] = 0; while (1) { min = INF; u = NIL; for (i = 0; i < n; i++) { if (color[i] != BLACK && d[i] < min) { min = d[i]; u = i; } } if (u == NIL) { break; } color[u] = BLACK; for (v = 0; v < n; v++) { if (color[v] != BLACK && G[u][v] != INF) { if (d[v] > G[u][v]) { d[v] = G[u][v]; pi[v] = u; color[v] = GRAY; } } } } for (i = 0; i < n; i++) { if (pi[i] != NIL) sum += G[i][pi[i]]; } printf("%d\n", sum); } int main() { int e; int i, j; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &e); if (e == -1) { G[i][j] = INF; } else { G[i][j] = e; } } } prim(); return 0; }
s069149000
[ { "input": "5\n -1 2 3 1 -1\n 2 -1 -1 4 -1\n 3 -1 -1 1 1\n 1 4 1 -1 3\n -1 -1 1 3 -1\n", "output": "5\n" } ]
C
codenet
#include <inttypes.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> typedef int32_t i32; typedef int64_t i64; typedef struct directed_edge { int32_t vertex; int32_t next; } graph_edge; typedef struct directedGraph { graph_edge *edge; int32_t *start; int32_t pointer; int32_t vertex_num; int32_t edge_max_size; } graph; graph *new_graph(const int vertex_num) { graph *g = (graph *)calloc(1, sizeof(graph)); g->edge = (graph_edge *)calloc(1, sizeof(graph_edge)); g->start = (int32_t *)calloc(vertex_num, sizeof(int32_t)); g->pointer = 0; g->vertex_num = vertex_num; g->edge_max_size = 1; for (int32_t i = 0; i < vertex_num; ++i) { g->start[i] = -1; } return g; } void add_edge(graph *g, int32_t from, int32_t to) { if (g->pointer == g->edge_max_size) { g->edge_max_size *= 2; g->edge = (graph_edge *)realloc(g->edge, sizeof(graph_edge) * g->edge_max_size); } g->edge[g->pointer] = (graph_edge){to, g->start[from]}; g->start[from] = g->pointer++; } const i32 mod = 1000000007; i32 mod_pow(i32 r, i32 n) { i32 t = 1; i32 s = r; while (n > 0) { if (n & 1) t = (i64)t * s % mod; s = (i64)s * s % mod; n >>= 1; } return t; } typedef struct dp_node { i32 one; i32 zero; } node; node merge(node *a, i32 n) { i64 one = 0; i64 zero = 1; i64 total = 1; for (i32 i = 0; i < n; ++i) { one = (one * a[i].zero + zero * a[i].one) % mod; zero = zero * a[i].zero % mod; total = total * (a[i].zero + a[i].one) % mod; } return (node){one, (total + mod - one) % mod}; } typedef node deque_val; typedef struct Deque { deque_val *array; size_t front; size_t last; size_t mask; } deque; deque *new_deque(void) { const size_t len = 2; deque *d = (deque *)calloc(len, sizeof(deque)); d->array = (deque_val *)calloc(len, sizeof(deque_val)); d->front = d->last = 0; d->mask = len - 1; return d; } void free_deque(deque *const d) { free(d->array); free(d); } size_t get_size(const deque *d) { return (d->last + (~d->front + 1)) & d->mask; } void deque_realloc(deque *const d) { deque_val *array = (deque_val *)calloc(2 * (d->mask + 1), sizeof(deque_val)); size_t k = 0; for (size_t i = d->front; i != d->last; i = (i + 1) & d->mask) { array[k++] = d->array[i]; } free(d->array); d->array = array; d->front = 0; d->last = k; d->mask = 2 * d->mask + 1; } deque_val get_at(const deque *d, size_t x) { return d->array[(d->front + x) & d->mask]; } void assign_at(const deque *d, size_t x, deque_val v) { d->array[(d->front + x) & d->mask] = v; } void push_front(deque *const d, const deque_val v) { if (((d->last + 1) & d->mask) == d->front) { deque_realloc(d); } d->front = (d->front + d->mask) & d->mask; d->array[d->front] = v; } int cmp_deque_size(const void *a, const void *b) { deque *p = *(deque **)a; deque *q = *(deque **)b; i32 d = get_size(p) - get_size(q); return d == 0 ? 0 : d > 0 ? -1 : 1; } void run(void) { i32 n; scanf("%" SCNi32, &n); i32 *p = (i32 *)calloc(n + 1, sizeof(i32)); i32 *depth = (i32 *)calloc(n + 1, sizeof(i32)); i32 *cnt = (i32 *)calloc(n + 1, sizeof(i32)); cnt[0] = 1; graph *g = new_graph(n + 1); for (i32 i = 1; i <= n; ++i) { scanf("%" SCNi32, p + i); add_edge(g, p[i], i); depth[i] = depth[p[i]] + 1; cnt[depth[i]]++; } deque **dp = (deque **)calloc(n + 1, sizeof(deque *)); deque **child = (deque **)calloc(n + 1, sizeof(deque *)); node *lst = (node *)calloc(n + 1, sizeof(node)); for (i32 i = n; i >= 0; --i) { i32 v = i; if (g->start[v] == -1) { dp[v] = new_deque(); push_front(dp[v], (node){1, 1}); continue; } i32 len = 0; for (i32 p = g->start[v]; p != -1; p = g->edge[p].next) { i32 u = g->edge[p].vertex; child[len++] = dp[u]; } if (len > 1) { qsort(child, len, sizeof(deque *), cmp_deque_size); for (i32 d = 0; d < (i32)get_size(child[1]); ++d) { i32 j = 0; for (; j < len && d < (i32)get_size(child[j]); ++j) { lst[j] = get_at(child[j], d); } assign_at(child[0], d, merge(lst, j)); } for (i32 j = 1; j < len; ++j) { free_deque(child[j]); } } dp[v] = child[0]; push_front(dp[v], (node){1, 1}); } i64 ans = 0; for (i32 i = 0; i < (i32)get_size(dp[0]); ++i) { ans += (i64)mod_pow(2, n + 1 - cnt[i]) * get_at(dp[0], i).one % mod; } printf("%" PRIi64 "\n", ans % mod); } int main(void) { run(); return 0; }
s132677252
[ { "input": "2\n0 0\n", "output": "8\n" } ]
C
codenet
#include <stdio.h> int main() { int a[10000], min, max, n, i; long long sum = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); sum += a[i]; } max = min = a[0]; for (i = 1; i < n; i++) { if (a[i] > max) max = a[i]; if (a[i] < min) min = a[i]; } printf("%d %d %lld\n", min, max, sum); return 0; }
s762168196
[ { "input": "5\n10 1 5 4 17\n", "output": "1 17 37\n" } ]
C
codenet
#include <stdio.h> long long heap[100000], sz = 0; void push(int x) { int i = sz++; while (i > 0) { int p = (i - 1) / 2; if (heap[p] >= x) break; heap[i] = heap[p]; i = p; } heap[i] = x; } int pop() { int ret = heap[0]; int x = heap[--sz]; int i = 0; while (i * 2 + 1 < sz) { int a = i * 2 + 1, b = i * 2 + 2; if (b < sz && heap[b] > heap[a]) a = b; if (heap[a] <= x) break; heap[i] = heap[a]; i = a; } heap[i] = x; return ret; } int main() { int n, m, i, j; long long a[100000]; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) scanf("%lld", &a[i]); for (i = 0; i < n; i++) push(a[i]); for (i = 0; i < m; i++) { long long tm = pop(); tm /= 2; push(tm); } long long ans = 0; for (i = 0; i < n; i++) ans += heap[i]; printf("%lld\n", ans); return 0; }
s176519935
[ { "input": "3 3\n2 13 8\n", "output": "9\n" } ]
C
codenet
#include <math.h> #include <stdio.h> #include <stdlib.h> int main(void) { int N, D, i, j, k = 0, n = 0; double l; int** matrix; scanf("%d%d", &N, &D); matrix = (int**)malloc(sizeof(int*) * N); for (i = 0; i < N; i++) { matrix[i] = (int*)malloc(sizeof(int) * D); } for (i = 0; i < N; i++) { for (j = 0; j < D; j++) { scanf("%d", &matrix[i][j]); } } for (i = 0; i < N - 1; i++) { for (j = i + 1; j < N; j++) { int m = 0; for (n = 0; n < D; n++) { m = (matrix[i][n] - matrix[j][n]) * (matrix[i][n] - matrix[j][n]) + m; } l = sqrt(m); if (ceil(l) == floor(l)) k++; } } printf("%d\n", k); free(matrix); return 0; }
s517438056
[ { "input": "3 2\n1 2\n5 5\n-2 8\n", "output": "1\n" } ]
C
codenet
#include <stdio.h> int main(void) { int h, r; scanf("%d%d", &h, &r); if (r > -h) { printf("1\n"); } else if (r == -h) { printf("0\n"); } else { printf("-1\n"); } return 0; }
s585881557
[ { "input": "-3 3\n", "output": "0\n" } ]
C
codenet
#include <stdio.h> int main(void) { int N; scanf("%d", &N); int i; long long sum = 0; long long wa = 0; int A[N]; int sa[N]; int ans; int shou; long long min = 1123456789; for (i = 0; i < N; i++) { scanf("%d", A + i); sum += A[i]; wa += i + 1; } if (sum % wa) ans = 0; else { shou = sum / wa; for (i = 0; i < N; i++) { sa[i] = A[(i + 1) % N] - A[i] - shou; } for (i = 0; i < N - 1; i++) { if (sa[i] <= 0 && !(sa[i] % N)) ans = 1; else { ans = 0; break; } } } if (ans) puts("YES"); else { puts("NO"); } return 0; }
s072370813
[ { "input": "5\n4 5 1 2 3\n", "output": "YES\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char **t, **h; int n, taro = 0, hanako = 0, i; scanf("%d", &n); t = malloc(n * sizeof(char *)); h = malloc(n * sizeof(char *)); for (i = 0; i < n; i++) { t[i] = malloc(100 * sizeof(char)); h[i] = malloc(100 * sizeof(char)); scanf("%s", t[i]); scanf("%s", h[i]); if (strcmp(t[i], h[i]) < 0) hanako += 3; if (strcmp(t[i], h[i]) > 0) taro += 3; if (strcmp(t[i], h[i]) == 0) { taro += 1; hanako += 1; } free(t[i]); free(h[i]); } printf("%d %d\n", taro, hanako); return 0; }
s898107093
[ { "input": "3\ncat dog\nfish fish\nlion tiger\n", "output": "1 7\n" } ]
C
codenet
#include <stdio.h> #include <string.h> #define M 1046527 #define L 14 char H[M][L]; int getChar(char ch) { if (ch == 'A') return 1; else if (ch == 'C') return 2; else if (ch == 'G') return 3; else if (ch == 'T') return 4; return 0; } long long getKey(char str[]) { long long sum = 0, p = 1; int i; for (i = 0; i < (int)strlen(str); i++) { sum += p * (getChar(str[i])); p *= 5; } return sum; } int h1(int key) { return key % M; } int h2(int key) { return 1 + (key % (M - 1)); } int find(char str[]) { int i, hash, key; key = getKey(str); i = 0; while (1) { hash = (h1(key) + i * h2(key)) % M; if (strcmp(H[hash], str) == 0) return 1; else if (strlen(H[hash]) == 0) return 0; i++; } return 0; } int insert(char str[]) { int i, hash, key; key = getKey(str); i = 0; while (1) { hash = (h1(key) + i * h2(key)) % M; if (strcmp(H[hash], str) == 0) return 1; else if (strlen(H[hash]) == 0) { strcpy(H[hash], str); return 0; } i++; } return 0; } int main() { int i, n; char str[L], com[9]; for (i = 0; i < M; i++) H[i][0] = '\0'; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s %s", com, str); if (com[0] == 'i') { insert(str); } else { if (find(str)) { printf("yes\n"); } else { printf("no\n"); } } } return 0; }
s164093814
[ { "input": "5\ninsert A\ninsert T\ninsert C\nfind G\nfind A\n", "output": "no\nyes\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, s; scanf("%d %d", &a, &b); s = (a * b) - (a + b) + 1; printf("%d\n", s); }
s215012367
[ { "input": "2 2\n", "output": "1\n" } ]
C
codenet
#include <stdio.h> int main(void) { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); if (a + b > c + d) printf("Left\n"); else if (a + b < c + d) printf("Right\n"); else printf("Balanced\n"); return 0; }
s826185217
[ { "input": "3 8 7 1\n", "output": "Left\n" } ]
C
codenet
#include <stdio.h> int main(void) { int a, b, n; scanf("%d %d", &a, &b); n = (a + b) / 2; printf("%d\n", n); return 0; }
s534239171
[ { "input": "1000 3000\n", "output": "2000\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, h; scanf("%d%d%d", &a, &b, &h); printf("%d\n", (a + b) * h / 2); return 0; }
s381222101
[ { "input": "3\n4\n2\n", "output": "7\n" } ]
C
codenet
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #define U1 unsigned char #define S1 char #define S4 int #define DU double #define VD void #define COMMAND_LENGTH (10) typedef struct st_node ST_NODE; typedef struct st_node { ST_NODE* st_parent; ST_NODE* st_left; ST_NODE* st_right; S4 s4_key; }; VD vd_d_insert(ST_NODE**, S4); VD vd_d_print(ST_NODE*); static VD vd_s_printPreOrder(ST_NODE*); static VD vd_s_printInOrder(ST_NODE*); ST_NODE* st_dp_newST_NODE(S4); S4 main() { ST_NODE* st_tp_root; S4 s4_t_numCommand; S4 s4_t_iCommand; S1 s1_tp_command[COMMAND_LENGTH]; S4 s4_t_insertKey; S4 s4_t_RtnStrcmp; st_tp_root = (ST_NODE*)NULL; (VD) scanf("%d", &s4_t_numCommand); for (s4_t_iCommand = (S4)0; s4_t_iCommand < s4_t_numCommand; s4_t_iCommand++) { (VD) scanf("%s", s1_tp_command); s4_t_RtnStrcmp = (S4)strcmp(s1_tp_command, "insert"); if (s4_t_RtnStrcmp == (S4)0) { (VD) scanf("%d", &s4_t_insertKey); vd_d_insert(&st_tp_root, s4_t_insertKey); } else { vd_d_print(st_tp_root); } } return ((S4)0); } VD vd_d_insert(ST_NODE** st_ap2_root, S4 s4_a_key) { ST_NODE* st_tp_parentNode; ST_NODE* st_tp_indexNode; ST_NODE* st_tp_insertNode; st_tp_insertNode = st_dp_newST_NODE(s4_a_key); st_tp_parentNode = (ST_NODE*)NULL; st_tp_indexNode = *st_ap2_root; while (st_tp_indexNode != (ST_NODE*)NULL) { st_tp_parentNode = st_tp_indexNode; if (st_tp_insertNode->s4_key < st_tp_indexNode->s4_key) { st_tp_indexNode = st_tp_indexNode->st_left; } else { st_tp_indexNode = st_tp_indexNode->st_right; } } st_tp_insertNode->st_parent = st_tp_parentNode; if (st_tp_parentNode == (ST_NODE*)NULL) { *st_ap2_root = st_tp_insertNode; } else if (s4_a_key < st_tp_parentNode->s4_key) { st_tp_parentNode->st_left = st_tp_insertNode; } else { st_tp_parentNode->st_right = st_tp_insertNode; } } VD vd_d_print(ST_NODE* st_ap_root) { vd_s_printInOrder(st_ap_root); printf("\n"); vd_s_printPreOrder(st_ap_root); printf("\n"); } static VD vd_s_printPreOrder(ST_NODE* st_ap_node) { if (st_ap_node == (ST_NODE*)NULL) { return; } printf(" %d", st_ap_node->s4_key); vd_s_printPreOrder(st_ap_node->st_left); vd_s_printPreOrder(st_ap_node->st_right); } static VD vd_s_printInOrder(ST_NODE* st_ap_node) { static s4_s_printedNumNode = (S4)0; if (st_ap_node == (ST_NODE*)NULL) { return; } vd_s_printInOrder(st_ap_node->st_left); printf(" %d", st_ap_node->s4_key); vd_s_printInOrder(st_ap_node->st_right); } ST_NODE* st_dp_newST_NODE(S4 s4_a_key) { ST_NODE* st_tp_node; st_tp_node = (ST_NODE*)malloc(sizeof(ST_NODE)); st_tp_node->st_parent = (ST_NODE*)NULL; st_tp_node->st_left = (ST_NODE*)NULL; st_tp_node->st_right = (ST_NODE*)NULL; st_tp_node->s4_key = s4_a_key; return (st_tp_node); }
s701716787
[ { "input": "8\ninsert 30\ninsert 88\ninsert 12\ninsert 1\ninsert 20\ninsert 17\ninsert 25\nprint\n", "output": " 1 12 17 20 25 30 88\n 30 12 1 20 17 25 88\n" } ]
C
codenet
#include <stdio.h> int main() { long long int a, b, c; scanf("%lld %lld %lld", &a, &b, &c); long long int d = c - a - b; if ((d > 0) && ((4 * a * b) < d * d)) printf("Yes\n"); else printf("No\n"); return 0; }
s860117222
[ { "input": "2 3 9\n", "output": "No\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, c, d, e, f; double x, y; while (scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != -1) { y = (double)(c * d - f * a) / (b * d - e * a); x = (double)(c * e - f * b) / (a * e - d * b); if (y <= 0 && y > -0.0005) y = 0; if (x <= 0 && x > -0.0005) x = 0; printf("%.3f %.3f\n", x, y); } return 0; }
s414827596
[ { "input": "1 2 3 4 5 6\n2 -1 -2 -1 -1 -5\n", "output": "-1.000 2.000\n1.000 4.000\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> int miyukiti(const void* asumisu, const void* mizuhasu) { int isihasu = *(const int*)asumisu, matukisu = *(const int*)mizuhasu; return isihasu < matukisu ? -1 : isihasu > matukisu; } int N; int A[114514]; int yukinnko; int tomatu[114514]; int mikakosi[114514]; int sumipe(int hayaminn) { int satorina = 0, zaasan = yukinnko - 1; while (satorina <= zaasan) { int yukati = satorina + (zaasan - satorina) / 2; if (tomatu[yukati] == hayaminn) return yukati; else if (tomatu[yukati] < hayaminn) satorina = yukati + 1; else zaasan = yukati - 1; } return 114513; } int main(void) { int inorinn; int emirinn = 0; if (scanf("%d", &N) != 1) return 1; for (inorinn = 0; inorinn < N; inorinn++) { if (scanf("%d", &A[inorinn]) != 1) return 1; tomatu[inorinn] = A[inorinn]; } qsort(tomatu, N, sizeof(*tomatu), miyukiti); yukinnko = 1; for (inorinn = 1; inorinn < N; inorinn++) { if (tomatu[inorinn] != tomatu[yukinnko - 1]) { tomatu[yukinnko++] = tomatu[inorinn]; } } for (inorinn = 0; inorinn < N; inorinn++) { int kugyu = sumipe(A[inorinn]); mikakosi[kugyu] = !mikakosi[kugyu]; } for (inorinn = 0; inorinn < yukinnko; inorinn++) { if (mikakosi[inorinn]) emirinn++; } printf("%d\n", emirinn); return 0; }
s814977152
[ { "input": "3\n6\n2\n6\n", "output": "1\n" } ]
C
codenet
#include <stdio.h> int main(void) { int i, j, x[10000]; for (i = 0; i < 10000; i++) { x[i] = 0; } i = 0; scanf("%d", &x[i]); while (x[i] != 0) { i++; scanf("%d", &x[i]); } for (j = 0; j < i; j++) { printf("Case %d: %d\n", j + 1, x[j]); } return 0; }
s344526598
[ { "input": "3\n5\n11\n7\n8\n19\n0\n", "output": "Case 1: 3\nCase 2: 5\nCase 3: 11\nCase 4: 7\nCase 5: 8\nCase 6: 19\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { int key; struct node *next; struct node *prev; }; typedef struct node *NodePointer; NodePointer N; void init() { N = malloc(sizeof(struct node)); N->next = N; N->prev = N; } void printList() { NodePointer cur = N->next; int snl = 1; while (cur != N) { if (snl == 0) printf(" "); printf("%d", cur->key); cur = cur->next; snl = 0; } printf("\n"); } void deleteFirst() { NodePointer t = N->next; N->next = t->next; t->next->prev = N; } void deleteLast() { NodePointer delnode = N->prev; N->prev = delnode->prev; delnode->prev->next = N; free(delnode); } void delete(int skey) { int judge = 0; NodePointer t; NodePointer n; for (n = N->next; n != N; n = n->next) { if (n->key == skey) { judge = 1; } } if (judge == 1) { n = N->next; while (n != N) { if (n->key == skey) break; n = n->next; } t = n->prev; t->next = n->next; t->next->prev = t; free(n); } } void insert(int skey) { NodePointer new; static int count = 0; new = malloc(sizeof(struct node)); new->key = skey; if (count == 0) { new->next = N; N->next = new; new->prev = N; N->prev = new; count++; } else { new->next = N->next; N->next->prev = new; N->next = new; new->prev = N; count++; } } int main() { int key, n, i; char com[12]; scanf("%d", &n); init(); for (i = 0; i < n; i++) { scanf("%s", com); if (strcmp(com, "insert") == 0) { scanf("%d", &key); insert(key); } else if (strcmp(com, "deleteFirst") == 0) deleteFirst(); else if (strcmp(com, "deleteLast") == 0) deleteLast(); else { scanf("%d", &key); delete (key); } } printList(); return 0; }
s997849905
[ { "input": "7\ninsert 5\ninsert 2\ninsert 3\ninsert 1\ndelete 3\ninsert 6\ndelete 5\n", "output": "6 1 2\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, c, d; scanf("%d %d", &a, &b); c = a * b; d = 2 * a + 2 * b; printf("%d %d\n", c, d); return 0; }
s502470583
[ { "input": "3 5\n", "output": "15 16\n" } ]
C
codenet
#include <stdio.h> void kansu(int, int); int main(void) { int a, b; scanf("%d %d", &a, &b); while (a != 0 && b != 0) { kansu(a, b); scanf("%d %d", &a, &b); } return 0; } void kansu(int a, int b) { int i, j, x, y, n; int suu[17][17]; int kouji[17][17]; scanf("%d", &n); for (i = 1; i <= a; i++) { for (j = 1; j <= b; j++) { kouji[i][j] = 0; } } for (i = 0; i < n; i++) { scanf("%d %d", &x, &y); kouji[x][y] = 1; } for (i = 1; i <= a; i++) { for (j = 1; j <= b; j++) { if (kouji[i][j] == 1) { suu[i][j] = 0; } else { if (i == 1 && j == 1) { suu[i][j] = 1; } else { if (i == 1) { suu[i][j] = suu[i][j - 1]; } else if (j == 1) { suu[i][j] = suu[i - 1][j]; } else { suu[i][j] = suu[i][j - 1] + suu[i - 1][j]; } } } } } printf("%d\n", suu[a][b]); }
s962042834
[ { "input": "5 4\n3\n2 2\n2 3\n4 2\n5 4\n3\n2 2\n2 3\n4 2\n0 0\n", "output": "5\n5\n" } ]
C
codenet
#include <stdio.h> int main(void) { double a; double ave = 0; int i; for (i = 0; i < 5; i++) { scanf("%lf", &a); if (a <= 40) { ave += 40; } else { ave += a; } } ave /= 5.0; printf("%.0f\n", ave); return (0); }
s933220798
[ { "input": "10\n65\n100\n30\n95\n", "output": "68\n" } ]
C
codenet
#include <stdio.h> int main() { int n, i, j, m, s, t; scanf("%d", &n); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } t = 0; for (i = 0; i < n; i++) { s = 0; for (j = 1; j < n; j++) { if (j <= i) { continue; } m = a[i] * a[j]; s = s + m; } t = t + s; } printf("%d\n", t); return 0; }
s608809394
[ { "input": "3\n3 1 2\n", "output": "11\n" } ]
C
codenet
#include <stdio.h> int W, N; int input[1024][2]; int main() { int i, j; int ans[1024][2]; int t; for (t = 0;; t++) { for (i = 0; i < 1024; i++) { ans[i][0] = 0; ans[i][1] = 0; input[i][0] = 0; input[i][1] = 0; } scanf("%d%d", &W, &N); if (W == 0) break; for (i = 0; i < N; i++) scanf("%d,%d", &input[i][0], &input[i][1]); for (i = 0; i < N; i++) { for (j = 1023; j >= input[i][1]; j--) { if (ans[j][0] < input[i][0] + ans[j - input[i][1]][0]) { ans[j][0] = input[i][0] + ans[j - input[i][1]][0]; ans[j][1] = input[i][1] + ans[j - input[i][1]][1]; } } } for (j = 0; ans[W][0] == ans[W - j - 1][0]; j++) ; printf("Case %d:\n%d\n%d\n", t + 1, ans[W - j][0], ans[W - j][1]); } return 0; }
s001352307
[ { "input": "50\n5\n60,10\n100,20\n120,30\n210,45\n10,4\n50\n5\n60,10\n100,20\n120,30\n210,45\n10,4\n0\n", "output": "Case 1:\n220\n49\nCase 2:\n220\n49\n" } ]
C
codenet
#include <stdio.h> int main() { long long n, a, m, M, c, b, i; c = 0; m = 100000000; M = -100000000; scanf("%lld", &n); for (i = 1; i <= n; i++) { scanf("%lld", &a); if (a > M) { M = a; } if (a < m) { m = a; } c = c + a; } printf("%lld %lld %lld\n", m, M, c); return 0; }
s105543399
[ { "input": "5\n10 1 5 4 17\n", "output": "1 17 37\n" } ]
C
codenet
#include <stdio.h> void swap(int *a, int *b) { int tmp; tmp = *a; *a = *b; *b = tmp; } int main() { int a, b; while (1) { scanf("%d %d", &a, &b); if (a == 0 && b == 0) break; if (b < a) swap(&a, &b); printf("%d %d\n", a, b); } return 0; }
s123216992
[ { "input": "3 2\n2 2\n5 3\n0 0\n", "output": "2 3\n2 2\n3 5\n" } ]
C
codenet
#include <stdio.h> int main() { double r; double s, l; double p = 3.141592653589; scanf("%lf", &r); s = r * r * p; l = 2 * p * r; printf("%f %f\n", s, l); return 0; }
s264203612
[ { "input": "2\n", "output": "12.566371 12.566371\n" } ]
C
codenet
#include <stdio.h> #define MAX 101 #define WHITE 0 #define BLACK 2 #define GRAY 1 int time, n, g[MAX][MAX] = {0}; int d[MAX], f[MAX], color[MAX] = {WHITE}; void visit(int u) { int i; color[u] = GRAY; d[u] = ++time; for (i = 0; i < n; i++) { if (g[u][i] == 0) continue; if (color[i] == WHITE) visit(i); } color[u] = BLACK; f[u] = ++time; } void dfs(void) { int i; time = 0; for (i = 0; i < n; i++) if (color[i] == WHITE) visit(i); for (i = 0; i < n; i++) printf("%d %d %d\n", i + 1, d[i], f[i]); } int main() { int i, j, x, y, z; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &x, &y); for (j = 0; j < y; j++) { scanf("%d", &z); g[x - 1][z - 1] = 1; } } dfs(); return 0; }
s375567191
[ { "input": "4\n1 1 2\n2 1 4\n3 0\n4 1 3\n", "output": "1 1 8\n2 2 7\n3 4 5\n4 3 6\n" } ]
C
codenet
#include <stdio.h> int main() { int x; scanf("%d", &x); x = x * x * x; printf("%d\n", x); return 0; }
s764865959
[ { "input": "2\n", "output": "8\n" } ]