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> int main() { int hcell, wcell, hpaint, wpaint, nblack, nwhite; scanf("%d %d", &hcell, &wcell); scanf("%d %d", &hpaint, &wpaint); nblack = (wcell * hpaint) + (hcell * wpaint) - (hpaint * wpaint); nwhite = (hcell * wcell) - nblack; printf("%d\n", nwhite); return 0; }
s722111534
[ { "input": "3 2\n2 1\n", "output": "1\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n, i; int h[100001]; int max = -1; int flag = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &h[i]); if (max < h[i]) max = h[i]; if (max - h[i] >= 2) flag = 1; } if (flag == 1) printf("No\n"); else printf("Yes\n"); return 0; }
s628392045
[ { "input": "5\n1 2 1 1 3\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d\n", ((b - 1) + (a - 2)) / (a - 1)); return 0; }
s784438440
[ { "input": "4 10\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> int main(void) { int A, B, C; scanf("%d %d %d", &A, &B, &C); if (A < C && C < B) { printf("Yes\n"); } else if (A > C && C > B) { printf("Yes\n"); } else { printf("No\n"); } }
s423495369
[ { "input": "3 8 5\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> int main() { const int MAX_V = 999999; int prime[MAX_V + 1]; int i, k, n; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } prime[0] = 0; prime[1] = 0; int count = 0; while (scanf("%d", &n) != EOF) { count++; int cnt = 0; for (i = n; i > 0; i--) { if (prime[i] == 1) { cnt++; } } printf("%d\n", cnt); if (count == 30) break; } return 0; }
s764427553
[ { "input": "10\n3\n11\n", "output": "4\n2\n5\n" } ]
C
codenet
#include <stdio.h> int main(void) { int v[10]; int sum = 0; int i; for (i = 0; i < 10; i++) scanf("%d", &v[i]); for (i = 0; i < 10; i++) sum += v[i]; printf("%d\n", sum); return 0; }
s639919182
[ { "input": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", "output": "55\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #define unko 1e12 long int sort(long int *a, int left, int middle, int right) { long int l_arr[middle - left + 1], r_arr[right - middle + 1]; long int cnt = 0; for (int i = 0; i < middle - left; i++) l_arr[i] = a[i + left]; for (int i = 0; i < right - middle; i++) r_arr[i] = a[i + middle]; l_arr[middle - left] = unko; r_arr[right - middle] = unko; int l = 0, r = 0; for (int i = 0; i < right - left; i++) { if (l_arr[l] <= r_arr[r]) { a[left + i] = l_arr[l++]; } else { a[left + i] = r_arr[r++]; cnt += middle - left - l; } } return cnt; } long int merge(long int *a, int left, int right) { if (left + 1 < right) { int middle = (left + right) / 2; long int x1 = merge(a, left, middle); long int x2 = merge(a, middle, right); long int x3 = sort(a, left, middle, right); return x1 + x2 + x3; } else { return 0; } } int main(void) { int n; scanf("%d", &n); long int *a = malloc(n * sizeof(long int)); for (int i = 0; i < n; i++) scanf("%ld", a + i); printf("%ld\n", merge(a, 0, n)); free(a); return 0; }
s619964871
[ { "input": "5\n3 5 2 1 4\n", "output": "6\n" } ]
C
codenet
#include <stdio.h> int main(void) { int a, b; scanf("%d", &a); scanf("%d", &b); if ((a * b) % 2 == 0) { printf("Even\n"); } else { printf("Odd\n"); } return 0; }
s797932052
[ { "input": "3 4\n", "output": "Even\n" } ]
C
codenet
#include <stdio.h> void white(int n, int A[]) { int i; for (i = 0; i < n - 1; i++) { printf("%d ", A[i]); } printf("%d\n", A[i]); } void insertionsort(int n, int A[]) { int i, j, a; for (i = 0; i < n; i++) { for (j = 0; j < i; j++) { if (A[i] < A[j]) { a = A[i]; A[i] = A[j]; A[j] = a; } } white(n, A); } } int main() { int i, n, A[100]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &A[i]); } insertionsort(n, A); return 0; }
s606068991
[ { "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
#if 0 cat <<EOF >mistaken-paste #endif #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" #define _USE_MATH_DEFINES #include <math.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define BIG 2000000007 #define VERYBIG 20000000000000007LL #define MOD 1000000007 #define FOD 998244353 typedef uint64_t ull; typedef int64_t sll; #define N_MAX 1048576 #ifdef __cplusplus #include <algorithm> #include <array> #include <functional> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> using std::get; using std::greater; using std::map; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::stack; using std::string; using std::tuple; using std::vector; template <typename T, typename U> pair<T, U> operator+(pair<T, U> l, pair<T, U> r) { return pair<T, U>(l.first + r.first, l.second + r.second); } #endif #ifndef M_PI #define M_PI 3.14159265358979323846264338327950 #endif typedef struct { sll a; sll b; } hwll; typedef struct { sll a; sll b; sll c; } hwllc; typedef struct { hwll a; hwll b; } linell; typedef struct { double a; double b; } hwreal; sll n, m; sll h, w; sll k; sll q; sll va, vb, vc, vd, ve, vf; ull ua, ub, uc, ud, ue, uf; long double vra, vrb, vrc; double vda, vdb, vdc; char ch, dh; ull umin(ull x, ull y) { return (x < y) ? x : y; } ull umax(ull x, ull y) { return (x > y) ? x : y; } sll smin(sll x, sll y) { return (x < y) ? x : y; } sll smax(sll x, sll y) { return (x > y) ? x : y; } ull gcd(ull x, ull y) { if (y == 0) { return x; } else { return gcd(y, x % y); } } ull bitpow(ull a, ull x, ull modulo) { ull result = 1; while (x) { if (x & 1) { result *= a; result %= modulo; } x /= 2; a = (a * a) % modulo; } return result; } ull divide(ull a, ull b, ull modulo) { return (a * bitpow(b, modulo - 2, modulo)) % modulo; } ull udiff(ull a, ull b) { if (a >= b) { return a - b; } else { return b - a; } } sll sdiff(sll a, sll b) { if (a >= b) { return a - b; } else { return b - a; } } int bitcount(ull n) { int result = 0; while (n) { if (n & 1) result++; n /= 2; } return result; } #define BEGCMP(NAME) int32_t NAME(const void *left, const void *right) #define DEFLR(TYPE) TYPE l = *(TYPE *)left, r = *(TYPE *)right #define CMPRET(L, R) \ if ((L) < (R)) return -1; \ if ((L) > (R)) return +1 BEGCMP(pullcomp) { DEFLR(ull); CMPRET(l, r); return 0; } BEGCMP(prevcomp) { DEFLR(sll); CMPRET(r, l); return 0; } BEGCMP(psllcomp) { DEFLR(sll); CMPRET(l, r); return 0; } BEGCMP(pcharcomp) { DEFLR(char); CMPRET(l, r); return 0; } BEGCMP(pdoublecomp) { DEFLR(double); CMPRET(l, r); return 0; } int32_t pstrcomp(const void *left, const void *right) { char *l = *(char **)left; char *r = *(char **)right; return strcmp(l, r); } BEGCMP(phwllABcomp) { DEFLR(hwll); CMPRET(l.a, r.a); CMPRET(l.b, r.b); return 0; } BEGCMP(phwllREVcomp) { DEFLR(hwll); CMPRET(l.b, r.b); CMPRET(l.a, r.a); return 0; } BEGCMP(ptriplecomp) { DEFLR(hwllc); CMPRET(l.a, r.a); CMPRET(l.b, r.b); CMPRET(l.c, r.c); return 0; } BEGCMP(ptripleREVcomp) { DEFLR(hwllc); CMPRET(l.b, r.b); CMPRET(l.a, r.a); CMPRET(l.c, r.c); return 0; } BEGCMP(ptripleCABcomp) { DEFLR(hwllc); CMPRET(l.c, r.c); CMPRET(l.a, r.a); CMPRET(l.b, r.b); return 0; } BEGCMP(phwrealcomp) { DEFLR(hwreal); CMPRET(l.a, r.a); CMPRET(l.b, r.b); return 0; } int32_t pquadcomp(const void *left, const void *right) { linell l = *(linell *)left; linell r = *(linell *)right; sll ac = phwllABcomp(&(l.a), &(r.a)); if (ac) return ac; sll bc = phwllABcomp(&(l.b), &(r.b)); if (bc) return bc; return 0; } int32_t pfracomp(const void *left, const void *right) { hwllc l = *(hwllc *)left; hwllc r = *(hwllc *)right; CMPRET(l.a * r.b, l.b * r.a); return 0; } bool isinrange(sll left, sll x, sll right) { return (left <= x && x <= right); } bool isinrange_soft(sll left, sll x, sll right) { return (left <= x && x <= right) || (left >= x && x >= right); } void sw(sll *l, sll *r) { if (*l == *r) return; sll t = *l; *l = *r; *r = t; } ull frac[N_MAX * 3], invf[N_MAX * 3]; ull ncr(sll n, sll r, ull m) { if (n < 0 || r < 0 || n < r) return 0; return frac[n] * (invf[r] * invf[n - r] % m) % m; } sll a[N_MAX + 5]; sll b[N_MAX + 5]; sll c[N_MAX + 5]; sll d[N_MAX + 5]; sll e[N_MAX * 4]; char s[N_MAX + 1]; char t[N_MAX + 1]; char u[N_MAX + 1]; hwll xy[N_MAX + 5]; hwllc tup[N_MAX + 5]; sll table[3005][3005]; ull gin[N_MAX]; sll cnt[3], pcnt; ull x[3005][3005]; ull solve() { sll i, j, ki, li; sll result = 0; double dresult = 0; sll maybe = 0; sll sum = 0; sll item; sll *dpcell; result = 1; for (i = 0; i < n * 3; i++) { ull v; switch (s[i]) { case 'R': v = 0; break; case 'G': v = 1; break; case 'B': v = 2; break; } if (cnt[(v + 1) % 3] && cnt[(v + 2) % 3]) { result *= pcnt; pcnt--; result %= FOD; cnt[(v + 1) % 3]--; cnt[(v + 2) % 3]--; } else { if ((cnt[(v + 1) % 3] + cnt[(v + 2) % 3]) > cnt[v]) { result *= (cnt[(v + 1) % 3] + cnt[(v + 2) % 3]) - cnt[v]; result %= FOD; pcnt++; } cnt[v]++; } } for (i = 1; i <= n; i++) { result = (result * i) % FOD; } printf("%lld\n", result); return 0; success: puts("Yes"); return 0; fail: puts("-1"); return 1; } int32_t main(int argc, char *argv[]) { int32_t i, j; n = 4; m = 0; scanf("%llu", &n, &m); scanf("%s", s); for (i = 0; i < 0; i++) { scanf("%lld", &a[i]); } solve(); return 0; }
s327468529
[ { "input": "3\nRRRGGGBBB\n", "output": "216\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); if (a < b && b < c) { printf("Yes\n"); } else { printf("No\n"); } return 0; }
s701648392
[ { "input": "1 3 8\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { char buf[512]; int len; fgets(buf, sizeof(buf), stdin); len = strlen(buf); printf("%c%d%c\n", buf[0], len - 3, buf[len - 2]); return 0; }
s343830814
[ { "input": "internationalization\n", "output": "i18n\n" } ]
C
codenet
#include <stdio.h> int main() { int i = 1, Input; while (1) { scanf("%d", &Input); if (Input == 0) { break; } printf("Case %d: %d\n", i, Input); i++; } return 0; }
s858832157
[ { "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 <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int i_min, min; int i, j, k; int X, N; scanf("%d %d", &X, &N); if (N == 0) { printf("%d\n", X); exit(0); } int plus[256]; int minus[256]; for (i = 0; i < 256; i++) { plus[i] = i; minus[i] = (-1 * i); } for (i = 0; i < N; i++) { scanf("%d", &j); plus[j] = 0; } i_min = 0; min = 1000; for (i = 255; i >= 0; i--) { if (plus[i] == 0 && i > 0) { continue; } k = X - plus[i]; if (k < 0) { k *= -1; } if (k <= min) { min = k; i_min = i; } } printf("%d\n", i_min); return 0; }
s735953430
[ { "input": "6 5\n4 7 10 6 5\n", "output": "8\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int calc_score() { int out = 0; char str[100]; int score = 0; int base = 0; while (out < 3) { scanf("%s", str); if (strcmp(str, "OUT") == 0) { out++; } else if (strcmp(str, "HIT") == 0) { if (base == 3) { score++; } else { base++; } } else if (strcmp(str, "HOMERUN") == 0) { score += (base + 1); base = 0; } } return score; } int main(void) { int n; int inning = 0; scanf("%d", &n); while (inning < n) { printf("%d\n", calc_score()); inning++; } return 0; }
s435885409
[ { "input": "2\nHIT\nOUT\nHOMERUN\nHIT\nHIT\nHOMERUN\nHIT\nOUT\nHIT\nHIT\nHIT\nHIT\nOUT\nHIT\nHIT\nOUT\nHIT\nOUT\nOUT\n", "output": "7\n0\n" } ]
C
codenet
#include <assert.h> #include <ctype.h> #include <math.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> typedef long long ll; typedef long double ld; #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 rrep(i, l, r) for (ll i = (l); i >= (r); i--) #define INF (1LL << 60) #define MOD1 1000000007 #define MOD2 998244353 #define MAX_N (1 << 20) #define YES printf("Yes\n") #define NO printf("No\n") #define PN printf("\n") #define charsize 100005 #define PI 3.141592653589793238 void swap(ll *a, ll *b) { ll c; c = *b; *b = *a; *a = c; } void cin(ll *n) { scanf("%lld", &(*n)); } ll max2(ll a, ll b) { return a >= b ? a : b; } ll min2(ll a, ll b) { return a >= b ? b : a; } ll min3(ll a, ll b, ll c) { return (a <= b && a <= c) ? a : b <= c ? b : c; } ll max3(ll a, ll b, ll c) { return (a >= b && a >= c) ? a : b >= c ? b : c; } ll minn(ll n, ll a[]) { ll b = INF; rep(i, 0, n) b = min2(b, a[i]); return b; } ll maxn(ll n, ll a[]) { ll b = -INF; rep(i, 0, n) b = max2(b, a[i]); return b; } ll POW(ll a, ll b) { ll c = 1; rep(i, 0, b) c *= a; return c; } double POW_d(double a, double b) { double c = 1; rep(i, 0, b) c *= a; return c; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll mod_MOD1(ll n) { n += n < 0 ? ((-n) / MOD1 + 1) * MOD1 : 0; return n %= MOD1; } ll mod_p(ll n, ll p) { n += n < 0 ? ((-n) / p + 1) * p : 0; return n %= p; } ll change_into_num(char s[], ll len, ll p) { return !p ? 0 : POW(10, p - 1) * (s[len - p] - '0') + change_into_num(s, len, p - 1); } ll digits(ll a, ll b) { return a / b ? 1 + digits(a / b, b) : 1; } ll base(ll n, ll a, ll i) { return i == 1 ? n % a : base(n / a, a, i - 1); } ll is_inArr1(ll x, ll n) { return (x < 0 || x >= n) ? 0 : 1; } ll is_inArr2(ll y, ll x, ll h, ll w) { return (y < 0 || y >= h || x < 0 || x >= w) ? 0 : 1; } void lr_lower(int *l, int *r, ll am, ll val, int type) { (type < 3) ? (am < val ? (*l = (*l + *r) / 2) : (*r = (*l + *r) / 2)) : (am <= val ? (*l = (*l + *r) / 2) : (*r = (*l + *r) / 2)); } void lr_upper(int *l, int *r, ll am, ll val, int type) { (type < 3) ? (am <= val ? (*l = (*l + *r) / 2) : (*r = (*l + *r) / 2)) : (am < val ? (*l = (*l + *r) / 2) : (*r = (*l + *r) / 2)); } int cmp_lower(ll a, ll b, int type) { return (type == 1) ? (a == b ? 1 : 0) : (type == 2) ? (a >= b ? 1 : 0) : (a > b ? 1 : 0); } int cmp_upper(ll a, ll b, int type) { return (type == 1) ? (a == b ? 1 : 0) : (type == 2) ? (a <= b ? 1 : 0) : (a < b ? 1 : 0); } ll lower_bound(ll a[], int l, int r, ll val, int type) { while (r - l > 1) lr_lower(&l, &r, a[(l + r) / 2], val, type); return cmp_lower(a[l], val, type) ? l : cmp_lower(a[r], val, type) ? r : -1; } ll upper_bound(ll a[], int l, int r, ll val, int type) { while (r - l > 1) lr_upper(&l, &r, a[(l + r) / 2], val, type); return cmp_upper(a[r], val, type) ? r : cmp_upper(a[l], val, type) ? l : -1; } ll count(ll a[], int l, int r, ll x) { int p = lower_bound(a, l, r, x, 1); return p == -1 ? 0 : upper_bound(a, p, r, x, 1) - p + 1; } ll *factors[2], fac_cnt = 0, is_factor_prepared = 0; ll factor_pre() { rep(i, 0, 1) { if (is_factor_prepared++) return 0; } ll tmp = (1e6) / 2 + 1, fac_tmp[tmp]; rep(i, 0, tmp) { fac_tmp[i] = i ? 2 * i + 1 : 2; } rep(i, 1, tmp) { if (fac_tmp[i]) { repp(j, 3, tmp / (2 * i + 1) + 1, 2) { if (j * (2 * i + 1) < tmp) fac_tmp[(j * (2 * i + 1) - 1) / 2] = 0; } } else continue; } rep(i, 0, tmp) { if (fac_tmp[i]) { rep(j, 0, 2) { factors[j] = realloc(factors[j], sizeof(ll) * (fac_cnt + 1)); factors[j][j ? fac_cnt++ : fac_cnt] = j ? 0 : fac_tmp[i]; } } } return 0; } ll factor(ll n, ll new_common_plus) { factor_pre(); rep(i, 0, fac_cnt) { ll cnt = 0; rep(j, 0, 1) { while ((cnt += n % factors[0][i] == 0 ? 1 : 0) && (n /= factors[0][i]) % factors[0][i] == 0) continue; } factors[1][i] = new_common_plus == 1 ? cnt : new_common_plus == 2 ? max2(factors[1][i], cnt) : factors[1][i] + cnt; if (factors[0][i] > n) break; } return n; } ll judge_prime(ll n) { factor_pre(); rep(i, 0, fac_cnt) { if (n < factors[0][i] * factors[0][i] || n == factors[0][i]) break; else if (n % factors[0][i] == 0) n /= n; } return n == 1 ? 0 : 1; } ll *mf_arr, *inv_arr, *finv_arr, is_minv_made = 0, is_mf_made = 0, num_of_inv = 2 * 1e6 + 10; ll makeinv(ll n, ll mod) { rep(i, 0, 1) { if (is_minv_made++) return 0; } inv_arr = realloc(inv_arr, sizeof(ll) * 2); finv_arr = realloc(finv_arr, sizeof(ll) * 2); inv_arr[1] = 1; finv_arr[0] = finv_arr[1] = 1; rep(i, 2, n + 1) { inv_arr = realloc(inv_arr, sizeof(ll) * (i + 1)); finv_arr = realloc(finv_arr, sizeof(ll) * (i + 1)); inv_arr[i] = mod - inv_arr[mod % i] * (mod / i) % mod; finv_arr[i] = finv_arr[i - 1] * inv_arr[i] % mod; } return 0; } ll make_mf(ll n, ll mod) { rep(i, 0, 1) { if (is_mf_made++) return 0; } mf_arr = realloc(mf_arr, sizeof(ll) * 2); ll x = 1; mf_arr[0] = mf_arr[1] = x; rep(i, 2, n + 1) { x = x * i % mod; mf_arr = realloc(mf_arr, sizeof(ll) * (i + 1)); mf_arr[i] = x; } return 0; } ll m_inv(ll x, ll mod, ll is_fac) { makeinv(num_of_inv, mod); return is_fac ? finv_arr[x] : inv_arr[x]; } ll m_f(ll x, ll mod) { make_mf(num_of_inv, mod); return mf_arr[x]; } ll mod_nck(ll n, ll k, ll mod) { return m_f(n, mod) * m_inv(k, mod, 1) % mod * m_inv(n - k, mod, 1) % mod; } ll m_p(ll r, ll n, ll mod) { ll t = 1, s = r; while (n > 0) { t = (n & 1) ? t * s % mod : t; s = s * s % mod; n >>= 1; } return r ? t : 0; } ll m_mul2(ll a, ll b, ll mod) { return a * b % mod; } ll m_mul3(ll a, ll b, ll c, ll mod) { return m_mul2(a * b % mod, c, mod); } ll m_mul4(ll a, ll b, ll c, ll d, ll mod) { return m_mul3(a * b % mod, c, d, mod); } ll m_mul5(ll a, ll b, ll c, ll d, ll e, ll mod) { return m_mul4(a * b % mod, c, d, e, mod); } 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; } int cmp_string(const void *a, const void *b) { return strcmp((char *)a, (char *)b); } int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; } void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); } void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); } void sort_string(int n, int size, char s[][size]) { qsort((void *)s, n, sizeof(s[0]), cmp_string); } void sort_char(char *s) { qsort((void *)s, strlen(s), sizeof(char), cmp_char); } ll unique_string(ll n, ll size, char s[][size]) { ll ans = 1; rep(i, 1, n) if (strcmp(s[i], s[i - 1])) ans++; return ans; } ll unique_num(ll n, ll a[]) { ll ans = 1; rep(i, 1, n) if (a[i] != a[i - 1]) ans++; return ans; } typedef struct { ll a, b; } fr; int cmp1(const void *p, const void *q) { return ((fr *)p)->a - ((fr *)q)->a; } int cmp2(const void *p, const void *q) { return ((fr *)q)->a - ((fr *)p)->a; } void strsortup(fr *a, int n) { qsort(a, n, sizeof(fr), cmp1); } void strsortdown(fr *a, int n) { qsort(a, n, sizeof(fr), cmp2); } char s[1151154]; int main(void) { ll l, r, d; ll ans = 0; cin(&l); cin(&r); cin(&d); rep(i, l, r + 1) { if (i % d == 0) ans++; } printf("%lld\n", ans); return 0; }
s325320702
[ { "input": "5 10 2\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> int main() { char m; int a, b, c[256], i, j; for (i = 0; i > -1; i++) { scanf("%d %c %d", &a, &m, &b); if (m == '?') { break; } if (m == '+') { c[i] = a + b; } if (m == '-') { c[i] = a - b; } if (m == '*') { c[i] = a * b; } if (m == '/') { c[i] = a / b; } } for (j = 0; j < i; j++) { printf("%d\n", c[j]); } return (0); }
s647939399
[ { "input": "1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 + 81\n0 ? 0\n", "output": "3\n38\n26\n10\n108\n" } ]
C
codenet
#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) > (b) ? (b) : (a)) int get_int4(int *a1, int *a2, int *a3, int *a4) { scanf("%d %d %d %d", a1, a2, a3, a4); return 0; } int fget_array(int64_t *arr, int size) { int i; for (i = 0; i < size; i++) { scanf("%lld", &arr[i]); } return 0; } #define NUM_MAX 1000 #define NUM2_MAX (NUM_MAX * NUM_MAX) #define RANK_MAX 3000 int asc(const void *a1, const void *a2) { int64_t aa1 = *(int64_t *)a1; int64_t aa2 = *(int64_t *)a2; if (aa1 > aa2) return 1; if (aa1 == aa2) return 0; return -1; } int desc(const void *a1, const void *a2) { int64_t aa1 = *(int64_t *)a1; int64_t aa2 = *(int64_t *)a2; if (aa1 > aa2) return -1; if (aa1 == aa2) return 0; return 1; } #define VAL_MAX (int64_t)(1e+10) #define SUM_MAX (VAL_MAX * 3) struct range { int start; int end; }; int lower_bound(int64_t *arr, struct range r, int64_t key) { int low = r.start; ; int high = r.end; while (low + 1 < high) { int mid = (low + high) / 2; if (arr[mid] < key) { low = mid; } else { high = mid; } } return low + 1; } int main(void) { int x, y, z, rank; get_int4(&x, &y, &z, &rank); static int64_t xrr[NUM_MAX]; static int64_t yrr[NUM_MAX]; static int64_t zrr[NUM_MAX]; fget_array(xrr, x); fget_array(yrr, y); fget_array(zrr, z); int64_t min_sum = VAL_MAX + 1; int64_t max_sum = 0; int i, j; for (i = 0; i < z; i++) min_sum = min(min_sum, zrr[i]); for (i = 0; i < z; i++) max_sum = max(max_sum, zrr[i]); static int64_t pair[NUM2_MAX]; int idx = 0; for (i = 0; i < x; i++) { for (j = 0; j < y; j++) { pair[idx++] = xrr[i] + yrr[j]; } } qsort(pair, idx, sizeof(int64_t), asc); min_sum += pair[0]; max_sum += pair[idx - 1]; static int cache[NUM_MAX]; static int cnt_map[NUM_MAX]; static int64_t ans[RANK_MAX]; int size = x * y * z; int64_t prev = min_sum; int r; for (r = rank; r >= 1; r--) { int64_t low = prev - 1; int64_t high = max_sum + 1; while (low + 1 < high) { int64_t mid = (low + high) / 2; int cnt = 0; for (i = 0; i < z; i++) { int64_t pivot = zrr[i]; struct range r = {cache[i] - 1, idx}; int tmp = lower_bound(pair, r, mid - pivot); cnt_map[i] = tmp; cnt += tmp; } if (cnt <= size - r) { memcpy(cache, cnt_map, sizeof(int) * z); low = mid; } else { high = mid; } } ans[r - 1] = low; if (low == max_sum) break; prev = low; } for (i = 0; i < rank; i++) { printf("%lld\n", (ans[i] == 0) ? max_sum : ans[i]); } return 0; }
s171933389
[ { "input": "2 2 2 8\n4 6\n1 5\n3 8\n", "output": "19\n17\n15\n14\n13\n12\n10\n8\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, c; char op; scanf("%d %c %d", &a, &op, &b); while (1) { if (op == '+') { c = a + b; printf("%d\n", c); } else if (op == '-') { c = a - b; printf("%d\n", c); } else if (op == '*') { c = a * b; printf("%d\n", c); } else if (op == '/') { c = a / b; printf("%d\n", c); } else { break; } scanf("%d %c %d", &a, &op, &b); } return 0; }
s910176756
[ { "input": "1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 + 81\n0 ? 0\n", "output": "3\n38\n26\n10\n108\n" } ]
C
codenet
#include <stdio.h> #define N 4 typedef struct { int P[N][N]; } Pazz; Pazz Q; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int Heu(Pazz Q) { int i, j; int hx, hy, sum = 0; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { if (Q.P[i][j] == 0) continue; hx = (Q.P[i][j] - 1) % N - j; hy = (Q.P[i][j] - 1) / N - i; if (hx < 0) sum -= hx; else sum += hx; if (hy < 0) sum -= hy; else sum += hy; } } return sum; } int dfs(int x, int y, int max, int count, int n) { int i, temp; int x0, y0, ans = -1, h; h = Heu(Q); if (h == 0) return count; if ((count + h) > max) return -1; for (i = 0; i < 4; i++) { x0 = x + dx[i]; y0 = y + dy[i]; if (((i == (n + 2) % 4) && (n != -1)) || !((0 <= x0) && (x0 < N) && (0 <= y0) && (y0 < N))) continue; temp = Q.P[y][x]; Q.P[y][x] = Q.P[y0][x0]; Q.P[y0][x0] = temp; ans = dfs(x0, y0, max, count + 1, i); if (ans != -1) return ans; temp = Q.P[y][x]; Q.P[y][x] = Q.P[y0][x0]; Q.P[y0][x0] = temp; } return -1; } int main() { int i, j; int kx, ky, ans, a; Pazz tP; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { scanf("%d", &a); Q.P[i][j] = a; if (a == 0) { kx = j; ky = i; } } } tP = Q; for (i = 1; i < 46; i++) { Q = tP; ans = dfs(kx, ky, i, 0, -1); if (ans != -1) { printf("%d\n", ans); break; } } return 0; }
s858559569
[ { "input": "1 2 3 4\n6 7 8 0\n5 10 11 12\n9 13 14 15\n", "output": "8\n" } ]
C
codenet
#include <stdio.h> int main() { int n, fd[6] = {}, i, j; double height; scanf("%d", &n); while (n--) { scanf("%lf", &height); if (height >= 185.0) fd[5]++; else if (height >= 180.0) fd[4]++; else if (height >= 175.0) fd[3]++; else if (height >= 170.0) fd[2]++; else if (height >= 165.0) fd[1]++; else fd[0]++; } for (i = 0; i < 6; i++) { printf("%d:", i + 1); for (j = 0; j < fd[i]; j++) putchar('*'); puts(""); } return 0; }
s866461201
[ { "input": "4\n180.3\n168.2\n165.5\n175.3\n", "output": "1:\n2:**\n3:\n4:*\n5:*\n6:\n" } ]
C
codenet
#include <math.h> #include <stdio.h> #include <stdlib.h> typedef long long int int64; #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) > (0) ? (a) : -(a)) int digit(int64 n) { int res = 0; while (n > 0) { res++; n /= 10; } return res; } void run(void) { int64 n; scanf("%lld", &n); int min = digit(n); int i; for (i = 1; (int64)i * i <= n; i++) { if (n % i != 0) continue; int64 a = i; int64 b = n / i; min = MIN(min, MAX(digit(a), digit(b))); } printf("%d\n", min); } int main(void) { run(); return 0; }
s105551633
[ { "input": "10000\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> int main() { int n; scanf("%d", &n); if (n % 1000 == 0) printf("%d\n", 0); else printf("%d\n", (n / 1000 + 1) * 1000 - n); }
s572139754
[ { "input": "1900\n", "output": "100\n" } ]
C
codenet
#include <stdio.h> int main() { int a[1000], n, i, j, d = 0; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n; i++) { for (j = n - 1; j >= i + 1; j--) { if (a[j] < a[j - 1]) { int temp = a[j]; a[j] = a[j - 1]; a[j - 1] = temp; d++; } } } printf("%d", a[0]); for (i = 1; i < n; i++) { printf(" %d", a[i]); } printf("\n%d\n", d); return 0; }
s772119380
[ { "input": "5\n5 3 2 4 1\n", "output": "1 2 3 4 5\n8\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int data[111111]; int seq[222222]; int max(int a, int b); int main(void) { int n, k, t, i, p, ret = 0; while (1) { scanf("%d %d", &n, &k); if (!n && !k) break; memset(data, 0, sizeof(data)); memset(seq, 0, sizeof(seq)); for (i = 0; i < k; i++) { scanf("%d", &t); data[t]++; } p = 0; for (i = 1; i <= n; i++) { if (data[i]) { seq[p]++; } else { p += 2; } } p++; if (data[0]) { for (i = 0; i < p; i++) { ret = max(ret, seq[i] + seq[i + 2] + 1); } } else { for (i = 0; i < p; i++) { ret = max(ret, seq[i]); } } printf("%d\n", ret); } return 0; } int max(int a, int b) { if (a > b) { return a; } return b; }
s286163362
[ { "input": "7 5\n6\n2\n4\n7\n1\n7 5\n6\n2\n0\n4\n7\n0 0\n", "output": "2\n4\n" } ]
C
codenet
#include <stdio.h> #define N 200 #define SHIRO 0 #define HAI 1 #define KURO 2 void aaaaa(); void bbbbb(int); int n, A[N][N]; int color[N], d[N], f[N]; int TT; int main() { int u, k, v; int i, j; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { A[i][j] = 0; } } for (i = 0; i < n; i++) { scanf("%d %d", &u, &k); u--; for (j = 0; j < k; j++) { scanf("%d", &v); v--; A[u][v] = 1; } } aaaaa(); return 0; } void aaaaa() { int u, i; for (i = 0; i < n; i++) { color[i] = SHIRO; } TT = 0; for (u = 0; u < n; u++) { if (color[u] == SHIRO) { bbbbb(u); } } for (i = 0; i < n; i++) { printf("%d %d %d\n", i + 1, d[i], f[i]); } } void bbbbb(int k) { int v; color[k] = HAI; TT++; d[k] = TT; for (v = 0; v < n; v++) { if (A[k][v] == 0) continue; if (color[v] == SHIRO) { bbbbb(v); } } color[k] = KURO; f[k] = ++TT; }
s419237275
[ { "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(void) { int n; unsigned long long int m; scanf("%d", &n); m = n; n--; for (; n > 1; n--) { m *= n; } printf("%lld\n", m); return 0; }
s792612560
[ { "input": "5\n", "output": "120\n" } ]
C
codenet
#include <stdio.h> int main(void) { int S; scanf("%d", &S); if (S < 60) { printf("0:0:%d\n", S); } else if (S < 3600) { printf("0:%d:%d\n", (int)S / 60, S % 60); } else { printf("%d:%d:%d\n", (int)S / 3600, (int)(S % 3600) / 60, (S % 60) % 60); } return 0; }
s891514124
[ { "input": "46979\n", "output": "13:2:59\n" } ]
C
codenet
#include <stdio.h> int main() { int N = 0; int R = 0; scanf("%d %d", &N, &R); if (N >= 10) { printf("%d\n", R); } else { printf("%d\n", R + 100 * (10 - N)); } return 0; }
s541856674
[ { "input": "2 2919\n", "output": "3719\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> int top, S[10000]; void push(int x) { S[++top] = x; } int pop() { return S[top--]; } int main() { int a, b; char s[200]; top = 0; while (scanf("%s", s) != EOF) { if (s[0] == '+') { b = pop(); a = pop(); push(a + b); } else if (s[0] == '-') { b = pop(); a = pop(); push(a - b); } else if (s[0] == '*') { b = pop(); a = pop(); push(a * b); } else { push(atoi(s)); } } printf("%d\n", pop()); return 0; }
s646324174
[ { "input": "1 2 +\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> int main(void) { int i, a, b, s; int count[4]; for (i = 0; i < 4; i++) count[i] = 0; for (i = 0; i < 3; i++) { scanf("%d %d", &a, &b); count[a - 1]++; count[b - 1]++; } s = 1; for (i = 0; i < 4; i++) s *= count[i]; if (s == 4) printf("YES\n"); else printf("NO\n"); return 0; }
s224842101
[ { "input": "4 2\n1 3\n2 3\n", "output": "YES\n" } ]
C
codenet
#include <stdio.h> int main(void) { int a, b, c; scanf("%d %d %d", &a, &b, &c); if (b > a * c) { printf("%d\n", c); } else { printf("%d\n", b / a); } return 0; }
s811544640
[ { "input": "2 11 4\n", "output": "4\n" } ]
C
codenet
#include <stdio.h> int main(void) { int n, k; scanf("%d%d", &n, &k); if (n % k == 0) printf("0\n"); else printf("1\n"); return 0; }
s536445669
[ { "input": "7 3\n", "output": "1\n" } ]
C
codenet
#include <stdio.h> int main() { int m, n; int i, j; int A[100][100]; int B[100]; int S[100] = {0}; scanf("%d %d", &m, &n); for (i = 0; i < m; i++) { for (j = 0; j < n - 1; j++) { scanf("%d ", &A[i][j]); } scanf("%d\n", &A[i][n - 1]); } for (i = 0; i < n; i++) { scanf("%d\n", &B[i]); } for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { S[i] = S[i] + A[i][j] * B[j]; } } for (i = 0; i < m; i++) { printf("%d\n", S[i]); } return 0; }
s327850243
[ { "input": "3 4\n1 2 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0\n", "output": "5\n6\n9\n" } ]
C
codenet
#include <stdio.h> int A[1000000], n; int binarySearch(int key) { int left = 0; int right = n; int mid; while (left < right) { mid = (left + right) / 2; if (key == A[mid]) return 1; if (key > A[mid]) left = mid + 1; else if (key < A[mid]) right = mid; } return 0; } int main(void) { int i, q, k, sum = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &A[i]); } scanf("%d", &q); for (i = 0; i < q; i++) { scanf("%d", &k); if (binarySearch(k)) sum++; } printf("%d\n", sum); return 0; }
s784517449
[ { "input": "5\n1 2 3 4 5\n3\n3 4 1\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> int main() { int in; int h, m, s; scanf("%d", &in); h = in / 3600; in %= 3600; m = in / 60; in %= 60; s = in; printf("%d:%d:%d\n", h, m, s); }
s821904390
[ { "input": "46979\n", "output": "13:2:59\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> #define NIL NULL typedef struct node { int key; int priority; struct node *right, *left; } Node; Node *Delete(Node **, int); Node *delete(Node **, int); int find(Node *p, int x) { while (p != NIL) { if (p->key == x) return 1; else if (p->key > x) p = p->left; else p = p->right; } return 0; } void inorder(Node *a) { if (a->left != NIL) inorder(a->left); printf(" %d", a->key); if (a->right != NIL) inorder(a->right); return; } void preorder(Node *p) { printf(" %d", p->key); if (p->left != NIL) preorder(p->left); if (p->right != NIL) preorder(p->right); return; } void print(Node *p) { inorder(p); printf("\n"); preorder(p); printf("\n"); return; } Node *makenode(int x, int y) { Node *new = malloc(sizeof(Node)); new->key = x; new->priority = y; new->left = NIL; new->right = NIL; return new; } Node *rightRotate(Node *p) { Node *q = p->left; p->left = q->right; q->right = p; return q; } Node *leftRotate(Node *p) { Node *q = p->right; p->right = q->left; q->left = p; return q; } Node *insert(Node **t, int key, int priority) { Node *new; if ((*t) == NIL) return new = makenode(key, priority); if ((*t)->key == key) return *t; if (key < (*t)->key) { (*t)->left = insert(&(*t)->left, key, priority); if ((*t)->priority < (*t)->left->priority) (*t) = rightRotate(*t); } else { (*t)->right = insert(&(*t)->right, key, priority); if ((*t)->priority < (*t)->right->priority) (*t) = leftRotate((*t)); } return *t; } Node *Delete(Node **t, int key) { if ((*t) == NIL) return NIL; if (key < (*t)->key) (*t)->left = Delete(&((*t)->left), key); else if (key > (*t)->key) (*t)->right = Delete(&((*t)->right), key); else return delete (t, key); return *t; } Node *delete(Node **t, int key) { if ((*t)->left == NIL && (*t)->right == NIL) { return NIL; } else if ((*t)->left == NIL) { (*t) = leftRotate(*t); } else if ((*t)->right == NIL) { (*t) = rightRotate(*t); } else { if ((*t)->left->priority > (*t)->right->priority) (*t) = rightRotate(*t); else (*t) = leftRotate(*t); } return Delete(t, key); } int main(void) { int num, x, y; char com[8]; Node *root = NIL; scanf("%d", &num); for (int i = 0; i < num; i++) { scanf("%s", com); switch (com[0]) { case 'i': scanf("%d %d", &x, &y); root = insert(&root, x, y); break; case 'd': scanf("%d", &x); root = Delete(&root, x); break; case 'f': scanf("%d", &x); if (find(root, x)) printf("yes\n"); else printf("no\n"); break; case 'p': print(root); break; } } return 0; }
s654514838
[ { "input": "16\ninsert 35 99\ninsert 3 80\ninsert 1 53\ninsert 14 25\ninsert 80 76\ninsert 42 3\ninsert 86 47\ninsert 21 12\ninsert 7 10\ninsert 6 90\nprint\nfind 21\nfind 22\ndelete 35\ndelete 99\nprint\n", "output": " 1 3 6 7 14 21 35 42 80 86\n 35 6 3 1 14 7 21 80 42 86\nyes\nno\n 1 3 6 7 14 21 42 80 86\n 6 3 1 80 14 7 21 42 86\n" } ]
C
codenet
#include <stdio.h> int main(void) { char s[4], t[4]; scanf("%s", s); scanf("%s", t); int hit = 0; for (int i = 0; i < 3; i++) { if (s[i] == t[i]) hit++; } printf("%d\n", hit); return 0; }
s878644875
[ { "input": "CSS\nCSR\n", "output": "2\n" } ]
C
codenet
#include <stdio.h> int main() { int r, c, n, flag, cnt; int arr[16][16] = {0}; while (1) { scanf("%d", &n); if (n == 0) { break; } flag = 1; r = (n + 1) / 2 + 1; c = (n + 1) / 2; arr[r][c] = cnt = 1; while (cnt != n * n + 1) { ++cnt; if (flag) { ++r; ++c; if (c > n) { c = 1; } if (r > n) { r = 1; } if (arr[r][c]) { flag = 0; --cnt; } else { arr[r][c] = cnt; } } else { ++r; --c; if (c < 1) { c = n; } if (r > n) { r = 1; } if (arr[r][c]) { flag = 0; } else { arr[r][c] = cnt; flag = 1; } } } for (r = 1; r < n + 1; r++) { for (c = 1; c < n + 1; c++) { printf("%4d", arr[r][c]); arr[r][c] = 0; if (c == n) { printf("\n"); } } } } return 0; }
s310320755
[ { "input": "3\n5\n0\n", "output": " 4 9 2\n 3 5 7\n 8 1 6\n 11 24 7 20 3\n 4 12 25 8 16\n 17 5 13 21 9\n 10 18 1 14 22\n 23 6 19 2 15\n" } ]
C
codenet
#include <stdio.h> int main(void) { int n, sum; scanf("%d", &n); sum = (n * (n + 1)) / 2; printf("%d\n", sum); return 0; }
s972081311
[ { "input": "3\n", "output": "6\n" } ]
C
codenet
#include <stdio.h> int c[26]; int main(void) { char str[1200]; for (; scanf("%s", str) > 0;) { for (char *p = str; *p; p++) { if ('a' <= *p && *p <= 'z') { c[*p - 'a']++; } else if ('A' <= *p && *p <= 'Z') { c[*p - 'A']++; } } } for (int i = 0; i < 26; i++) { printf("%c : %d\n", 'a' + i, c[i]); } return 0; }
s387232787
[ { "input": "This is a pen.\n", "output": "a : 1\nb : 0\nc : 0\nd : 0\ne : 1\nf : 0\ng : 0\nh : 1\ni : 2\nj : 0\nk : 0\nl : 0\nm : 0\nn : 1\no : 0\np : 1\nq : 0\nr : 0\ns : 2\nt : 1\nu : 0\nv : 0\nw : 0\nx : 0\ny : 0\nz : 0\n" } ]
C
codenet
#include <stdio.h> #define PutChar(c) \ ; \ *p = (char)(c); \ ++p; #define MAX_N (2000001) #define MAX_Ai (10001) #define STR_SIZE (10000010) int getNum(void); void putNum(int n); void CountingSort(int A[], int B[], int k, int len); int A[MAX_N]; int B[MAX_N]; char str[STR_SIZE]; char *p = str; int main(void) { register int i; int n; fread(str, 1, STR_SIZE, stdin); n = getNum(); for (i = 1; i <= n; ++i) { A[i] = getNum(); } CountingSort(A, B, MAX_Ai, n); p = str; --n; for (i = 1; i <= n; ++i) { putNum(B[i]); PutChar(' '); } putNum(B[i]); PutChar('\0'); puts(str); return 0; } int getNum(void) { int n = 0; while ((*p >= '0') && (*p <= '9')) { n = n * 10 + (int)(*p - '0'); ++p; } ++p; return n; } void putNum(int n) { int d; if (n < 10) { PutChar('0' + n); return; } d = n / 10; if (d) putNum(d); PutChar('0' + (n - (d * 10))); } void CountingSort(int A[], int B[], int k, int len) { int C[MAX_Ai] = {0}; int i, j; for (j = 1; j <= len; ++j) { ++C[A[j]]; } for (i = 1; i <= k; ++i) { C[i] += C[i - 1]; } for (j = len; j > 0; --j) { B[C[A[j]]] = A[j]; --C[A[j]]; } }
s776764195
[ { "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 M 100 #define whi 0 #define gra 1 #define bla 2 int n; int T[M][M]; int color[M], d[M]; int Q[M], head = 0, tail = 0; void enqueue(int x) { Q[tail] = x; tail = (tail + 1) % M; } int dequeue(void) { int x; x = Q[head]; head = (head + 1) % M; return x; } void bfs(int s) { int i, u, v; for (i = 0; i < n; i++) { color[i] = whi; d[i] = 1000000; } color[s] = gra; d[s] = 0; enqueue(s); while (head != tail) { u = dequeue(); for (v = 0; v < n; v++) { if (T[u][v] == 1 && color[v] == whi) { color[v] = gra; d[v] = d[u] + 1; enqueue(v); } } color[u] = bla; } } int main() { int i, j; int u, k, v; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { T[i][j] = 0; } } for (i = 0; i < n; i++) { scanf("%d %d", &u, &k); u--; for (j = 0; j < k; j++) { scanf("%d", &v); v--; T[u][v] = 1; } } bfs(0); for (i = 0; i < n; i++) { if (d[i] == 1000000) d[i] = -1; printf("%d %d\n", i + 1, d[i]); } return 0; }
s869953757
[ { "input": "4\n1 2 2 4\n2 1 4\n3 0\n4 1 3\n", "output": "1 0\n2 1\n3 2\n4 1\n" } ]
C
codenet
#pragma warning(disable : 4996) #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_STRING 30 #define MAX_LINE 2000000 #define MAX_HUMAN 200000 char sLongInputLine[MAX_LINE + 1] = ""; int anComingSec[MAX_HUMAN]; int main() { char sInput[MAX_STRING + 1] = ""; char* psWord = NULL; char* psInput = NULL; int nHumanNumber = 0; int nNextHumanIndex = 0; int nWaterLength = 0; int nWaterLife = 0; int nStart = 0; int nStop = 0; int nIndex = 0; int i = 0; int j = 0; fgets(sInput, MAX_STRING, stdin); if (strchr(sInput, '\n') != NULL) { sInput[strlen(sInput) - 1] = '\0'; } psInput = strtok(sInput, " "); nHumanNumber = atoi(psInput); psInput = strtok(NULL, " "); nWaterLength = atoi(psInput); fgets(sLongInputLine, MAX_LINE, stdin); if (strchr(sLongInputLine, '\n') != NULL) { sLongInputLine[strlen(sLongInputLine) - 1] = '\0'; } psInput = strtok(sLongInputLine, " "); for (i = 0; i < nHumanNumber; i++) { anComingSec[i] = atoi(psInput); psInput = strtok(NULL, " "); } nStart = anComingSec[0]; while (nNextHumanIndex < nHumanNumber) { if (nNextHumanIndex == nHumanNumber) { break; } else { nStop = nStart + nWaterLength; if (anComingSec[nNextHumanIndex] < nStop) { while (nNextHumanIndex < nHumanNumber && anComingSec[nNextHumanIndex] < nStop) { if (nStop <= anComingSec[nNextHumanIndex] + nWaterLength) { nStop = anComingSec[nNextHumanIndex] + nWaterLength; nNextHumanIndex++; } } if (nNextHumanIndex == nHumanNumber) { nWaterLife = nWaterLife + (nStop - nStart); break; } } nWaterLife = nWaterLife + (nStop - nStart); nStart = nStop; if (nStart < anComingSec[nNextHumanIndex]) { nStart = anComingSec[nNextHumanIndex]; } } } printf("%d\n", nWaterLife); return 0; }
s418782460
[ { "input": "2 4\n0 3\n", "output": "7\n" } ]
C
codenet
#include <float.h> #include <inttypes.h> #include <limits.h> #include <math.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> #ifdef __cplusplus #include <bits/stdc++.h> #endif int32_t nextint(void) { char c = getchar_unlocked(); while (c != '-' && (c < '0' || '9' < c)) c = getchar_unlocked(); bool s = false; if (c == '-') { s = true; c = getchar_unlocked(); } uint32_t x = 0; while ('0' <= c && c <= '9') { x = x * 10 + c - '0'; c = getchar_unlocked(); } return s ? -x : x; } int n; int p(int a, int b) { if (a < b) { return a + b * n; } else { return b + a * n; } } int a[1000][999]; int e1[1000000]; int e2[1000000]; int d[1000000]; bool b[1000000]; int f(int from) { if (b[from]) return -1; if (d[from]) return d[from]; b[from] = true; int to; to = e1[from]; int max = 0; if (to != 0) { int now = f(to); if (now < 0) return now; if (now > max) max = now; } to = e2[from]; if (to != 0) { int now = f(to); if (now < 0) return now; if (now > max) max = now; } b[from] = false; return d[from] = max + 1; } int main(void) { n = nextint(); for (int i = 0; i < n; i++) { for (int j = 0; j < n - 1; j++) { a[i][j] = nextint() - 1; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n - 2; j++) { int from = p(i, a[i][j]); int to = p(i, a[i][j + 1]); if (e1[from] == 0) { e1[from] = to; } else if (e2[from] == 0) { e2[from] = to; } else { puts("-1"); return 0; } } } int ans = 0; for (int i = 0; i < n; i++) { int from = p(i, a[i][0]); int now = f(from); if (now < 0) { ans = -1; break; } if (now > ans) ans = now; } printf("%d\n", ans); }
s977214798
[ { "input": "3\n2 3\n1 3\n1 2\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> #define NIL -1 struct Node { int parent, left, right; }; struct Node R[10000]; int n; void preorder(int); void inorder(int); void postorder(int); void preorder(int x) { if (x == NIL) return; printf(" %d", x); preorder(R[x].left); preorder(R[x].right); } void inorder(int x) { if (x == NIL) return; inorder(R[x].left); printf(" %d", x); inorder(R[x].right); } void postorder(int x) { if (x == NIL) return; postorder(R[x].left); postorder(R[x].right); printf(" %d", x); } int main() { int i, a, b, c, root; scanf("%d", &n); for (i = 0; i < n; i++) R[i].parent = NIL; for (i = 0; i < n; i++) { scanf("%d %d %d", &a, &b, &c); R[a].left = b; R[a].right = c; if (b != NIL) R[b].parent = a; if (c != NIL) R[c].parent = a; } for (i = 0; i < n; i++) { if (R[i].parent == NIL) root = i; } printf("Preorder\n"); preorder(root); printf("\n"); printf("Inorder\n"); inorder(root); printf("\n"); printf("Postorder\n"); postorder(root); printf("\n"); return 0; }
s167283321
[ { "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> main() { int a, b, mawari, menseki; scanf("%d %d", &a, &b); mawari = a + a + b + b; menseki = a * b; printf("%d %d\n", menseki, mawari); return 0; }
s033933040
[ { "input": "3 5\n", "output": "15 16\n" } ]
C
codenet
#include <stdio.h> int main() { long int n, k, q; scanf("%ld%ld%ld", &n, &k, &q); int arr[n]; for (long int i = 0; i <= n; i++) { arr[i] = 0; } for (long int i = 0; i < q; i++) { long int temp; scanf("%ld", &temp); arr[temp] += 1; } for (long int i = 1; i <= n; i++) { if (arr[i] > (q - k)) { printf("Yes\n"); } else { printf("No\n"); } } return 0; }
s648501684
[ { "input": "6 3 4\n3\n1\n3\n2\n", "output": "No\nNo\nYes\nNo\nNo\nNo\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, c, x, y; scanf("%d%d%d%d%d", &a, &b, &c, &x, &y); c *= 2; if (a + b <= c) printf("%d\n", a * x + b * y); else { if (x <= y) { if (b <= c) printf("%d\n", c * x + (y - x) * b); else printf("%d\n", c * y); } else { if (a <= c) printf("%d\n", c * y + (x - y) * a); else printf("%d\n", c * x); } } return 0; }
s999424066
[ { "input": "1500 2000 1600 3 2\n", "output": "7900\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> struct node { int key; struct node *p; struct node *l; struct node *r; }; typedef struct node *NodePointer; NodePointer r, NIL; NodePointer find(NodePointer x, int k) { while (x != NIL && k != x->key) { if (k < x->key) { x = x->l; } else { x = x->r; } } return x; } void insert(int k) { NodePointer y = NIL; NodePointer x = r; NodePointer z = (NodePointer)malloc(sizeof(struct node)); z->key = k; z->l = NIL; z->r = NIL; while (x != NIL) { y = x; if (z->key < x->key) { x = x->l; } else { x = x->r; } } z->p = y; if (y == NIL) { r = z; } else if (z->key < y->key) { y->l = z; } else { y->r = z; } } void inorder(NodePointer u) { if (u == NIL) { return; } inorder(u->l); printf(" %d", u->key); inorder(u->r); } void preorder(NodePointer u) { if (u == NIL) { return; } printf(" %d", u->key); preorder(u->l); preorder(u->r); } void print() { inorder(r); puts(""); preorder(r); puts(""); } int main() { int n, i, j, z, x; char s[10]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", s); if (s[0] == 'f') { scanf("%d", &x); NodePointer t = find(r, x); if (t == NIL) printf("no\n"); else printf("yes\n"); } else if (s[0] == 'i') { scanf("%d", &z); insert(z); } else { print(); } } return 0; }
s108384974
[ { "input": "10\ninsert 30\ninsert 88\ninsert 12\ninsert 1\ninsert 20\nfind 12\ninsert 17\ninsert 25\nfind 16\nprint\n", "output": "yes\nno\n 1 12 17 20 25 30 88\n 30 12 1 20 17 25 88\n" } ]
C
codenet
#include <ctype.h> #include <stdio.h> int main() { int i, alpha[26]; char ch; for (i = 0; i < 26; i++) alpha[i] = 0; while (1) { ch = getchar(); if (ch == EOF) break; if (isalpha(ch)) { if (isupper(ch)) alpha[ch - 65]++; else alpha[ch - 97]++; } } ch = 'a'; for (i = 0; i < 26; i++, ch++) { printf("%c : %d\n", ch, alpha[i]); } }
s476941540
[ { "input": "This is a pen.\n", "output": "a : 1\nb : 0\nc : 0\nd : 0\ne : 1\nf : 0\ng : 0\nh : 1\ni : 2\nj : 0\nk : 0\nl : 0\nm : 0\nn : 1\no : 0\np : 1\nq : 0\nr : 0\ns : 2\nt : 1\nu : 0\nv : 0\nw : 0\nx : 0\ny : 0\nz : 0\n" } ]
C
codenet
#include <stdio.h> int linersearch(int[], int, int); int main() { int i, n, s[100000], q, t, count = 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); if (linersearch(s, n, t)) count++; } printf("%d\n", count); return 0; } int linersearch(int a[], int n, int key) { int i = 0; a[n] = key; while (a[i] != key) { i++; } return i != n; }
s846328722
[ { "input": "5\n1 2 3 4 5\n3\n3 4 1\n", "output": "3\n" } ]
C
codenet
#include <ctype.h> #include <inttypes.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <wchar.h> #define N_MAX (100) #define P_MAX (100) #define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define ABS(a) ((a) < 0 ? -(a) : (a)) #define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a)) static char *strrstr(const char *string, const char *pattern) { size_t offset = 0; char *lastP = NULL; char *searchResult = NULL; while ((searchResult = strstr(&(string[offset]), pattern)) != NULL && string[offset] != '\0') { lastP = searchResult; offset++; } return lastP; } int compare_f(const void *a, const void *b) { return *((size_t *)a) < *((size_t *)b) ? -1 : 1; } static size_t comb(const size_t n, const size_t r) { size_t result = 1; for (size_t i = 0; i < r; i++) { result *= n - i; result /= i + 1; } return result; } static uint64_t gcd(uint64_t m, uint64_t n) { uint64_t temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } int main(void) { const char patternBase[] = "keyence"; char top[8], bottom[8]; char S[101]; scanf("%s", S); const size_t len = strlen(S); bool found = false; for (size_t offset = 0; offset < strlen(patternBase); offset++) { strncpy(top, patternBase, offset); top[offset] = '\0'; strncpy(bottom, &(patternBase[offset]), strlen(patternBase) - offset); bottom[strlen(patternBase) - offset] = '\0'; const char *topSearch = strstr(S, top); if (topSearch != NULL) { const char *bottomSearch = strrstr(&(topSearch[offset]), bottom); if (bottomSearch != NULL) { size_t sepCount = 0; if (topSearch != S) { sepCount++; } if (&(topSearch[offset]) != bottomSearch) { sepCount++; } if (bottomSearch[strlen(bottom)] != '\0') { sepCount++; } if (sepCount <= 1) { found = true; break; } } } } puts((found ? "YES" : "NO")); return 0; }
s484809551
[ { "input": "keyofscience\n", "output": "YES\n" } ]
C
codenet
#include <stdbool.h> #include <stdio.h> int main() { int n, a[100000], cnt = 1; bool isup; bool issame = false; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } if (a[0] < a[1]) isup = true; else if (a[0] > a[1]) isup = false; else issame = true; for (int i = 1; i < n - 1; i++) { if (issame) { if (a[i] != a[i + 1]) { issame = false; if (a[i] < a[i + 1]) isup = true; else isup = false; } } else { if (isup && a[i] <= a[i + 1]) { ; } else if (!isup && a[i] >= a[i + 1]) { ; } else { if (i + 2 < n) { if (a[i + 1] < a[i + 2]) isup = true; else if (a[i + 1] > a[i + 2]) isup = false; else issame = true; cnt++; } else { cnt++; break; } } } } printf("%d\n", cnt); return 0; }
s990550009
[ { "input": "6\n1 2 3 2 2 1\n", "output": "2\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> int main() { int n; int *data; scanf("%d\n", &n); data = (int *)malloc(sizeof(int) * n); for (int i = 0; i < n; i++) scanf("%d", &data[i]); int max = 0, index; for (int i = 0; i < n; i++) if (data[i] > max) { max = data[i]; index = i; } int a = 0; for (int i = 0; i < n; i++) if (i != index) a += data[i]; if (a > max) printf("Yes\n"); else printf("No\n"); return 0; }
s030068105
[ { "input": "4\n3 8 5 1\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> int main() { int i, j, max, max_j, buf; int io[5]; scanf("%d %d %d %d %d", &io[0], &io[1], &io[2], &io[3], &io[4]); for (i = 0; i < 5; i++) { max = io[i]; max_j = i; for (j = i + 1; j < 5; j++) { if (max < io[j]) { max = io[j]; max_j = j; } } buf = io[i]; io[i] = io[max_j]; io[max_j] = buf; i < 4 ? printf("%d ", io[i]) : printf("%d\n", io[i]); } return 0; }
s764482816
[ { "input": "3 6 9 7 5\n", "output": "9 7 6 5 3\n" } ]
C
codenet
#include <stdio.h> int main() { int a[3], b[3]; int c[3][3]; int i, j; for (i = 0; i < 3; i++) { scanf("%d%d%d", &c[i][0], &c[i][1], &c[i][2]); } a[0] = 0; for (i = 0; i < 3; i++) { b[i] = c[0][i]; } for (i = 1; i < 3; i++) { a[i] = c[i][0] - b[0]; } for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { if (c[i][j] != a[i] + b[j]) { puts("No"); return 0; } } } puts("Yes"); return 0; }
s616182260
[ { "input": "1 0 1\n2 1 2\n1 0 1\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> #include <string.h> char str1[100], str2[100], temp[100]; int main() { int i, j = 0, t; scanf("%s[^\n]", str1); scanf("%s[^\n]", str2); i = strlen(str1); t = i - 1; if (strlen(str1) != strlen(str2)) { printf("NO\n"); } else { while (str1[j] != '\0') { temp[j] = str1[t]; j++; t--; } t = 0; i = 0; while (temp[i] != '\0') { if (temp[i] == str2[i]) { t++; } i++; } if (strlen(str2) == t) { printf("YES\n"); } else if (strlen(str2) != t) { printf("NO\n"); } } return 0; }
s670350109
[ { "input": "pot\ntop\n", "output": "YES\n" } ]
C
codenet
#include <stdbool.h> #include <stdio.h> int a[200000], tmpa[200000], light[200010] = {0}; typedef long long ll; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < n; i++) { int r, l; r = i - a[i]; l = i + a[i]; light[(r < 0 ? 0 : r)]++; light[(l + 1 > n ? n + 1 : l + 1)]--; } for (int i = 0; i < k; i++) { int sum = 0; for (int j = 0; j < n; j++) { tmpa[j] = a[j]; sum += light[j]; a[j] = sum; } for (int j = 0; j < n; j++) { int r = j - tmpa[j]; int l = j + tmpa[j]; light[(r < 0 ? 0 : r)]--; light[(l + 1 > n ? n + 1 : l + 1)]++; r = j - a[j]; l = j + a[j]; light[(r < 0 ? 0 : r)]++; light[(l + 1 > n ? n + 1 : l + 1)]--; } bool isSame = true; for (int j = 0; j < n - 1; j++) { if (a[j] != a[j + 1]) { isSame = false; break; } } if (isSame && a[0] == n) { break; } } for (int j = 0; j < n; j++) { printf("%d", a[j]); printf(j == n - 1 ? "\n" : " "); } return 0; }
s500706216
[ { "input": "5 1\n1 0 0 1 0\n", "output": "1 2 2 1 2\n" } ]
C
codenet
#include <stdio.h> int main() { int n, k, cnt; scanf("%d%d", &n, &k); cnt = 0; while (n--) { int h; scanf("%d", &h); if (h >= k) cnt++; } printf("%d\n", cnt); return 0; }
s992866158
[ { "input": "4 150\n150 140 100 200\n", "output": "2\n" } ]
C
codenet
#include <limits.h> #include <math.h> #include <memory.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { int a, b; int ans; scanf("%d %d", &a, &b); ans = 0; if (a >= 13) { ans = b; } else if (a >= 6) { ans = b / 2; } printf("%d\n", ans); return 0; }
s305455869
[ { "input": "30 100\n", "output": "100\n" } ]
C
codenet
#include <stdio.h> typedef struct { char s; int v; } card; card L[100000 / 2 + 2], R[100000 / 2 + 2]; void me(card *a, int n, int l, int m, int r) { int i, j, k; int n1 = m - l; int n2 = r - m; for (i = 0; i < n1; i++) L[i] = a[l + i]; for (i = 0; i < n2; i++) R[i] = a[m + i]; L[n1].v = R[n2].v = 2000000000; i = 0; j = 0; for (k = l; k < r; k++) { if (L[i].v <= R[j].v) { a[k] = L[i++]; } else { a[k] = R[j++]; } } } void ms(card *a, int n, int l, int r) { int m; if (l + 1 < r) { m = (l + r) / 2; ms(a, n, l, m); ms(a, n, m, r); me(a, n, l, m, r); } } int partiton(card *a, int n, int p, int r) { int i, j; card t, x; x = a[r]; i = p - 1; for (j = p; j < r; j++) { if (a[j].v <= x.v) { i++; t = a[i]; a[i] = a[j]; a[j] = t; } } t = a[i + 1]; a[i + 1] = a[r]; a[r] = t; return i + 1; } void qs(card *a, int n, int p, int r) { int q; if (p < r) { q = partiton(a, n, p, r); qs(a, n, p, q - 1); qs(a, n, q + 1, r); } } int main() { int n, i, v; card a[200000], b[200000]; char s[10]; int stable = 1; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s%d", s, &v); a[i].s = b[i].s = s[0]; a[i].v = b[i].v = v; } ms(a, n, 0, n); qs(b, n, 0, n - 1); for (i = 0; i < n; i++) { if (a[i].s != b[i].s) { stable = 0; } } if (stable == 1) { printf("Stable\n"); } else { printf("Not stable\n"); } for (i = 0; i < n; i++) { printf("%c %d\n", b[i].s, b[i].v); } return 0; }
s427349585
[ { "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 a, b, x, y; scanf("%d%d", &a, &b); x = 2 * a + 2 * b; y = a * b; printf("%d %d\n", y, x); return 0; }
s008026706
[ { "input": "3 5\n", "output": "15 16\n" } ]
C
codenet
#include <stdio.h> int you(int, int); int main() { int x, y, z; scanf("%d %d", &x, &y); if (x >= y) z = you(x, y); else z = you(y, x); printf("%d\n", z); return 0; } int you(int x, int y) { int z; while (1) { z = x % y; x = y; y = z; if (y <= 0) break; } return x; }
s400285050
[ { "input": "54 20\n", "output": "2\n" } ]
C
codenet
#include <stdio.h> int main() { int n, l[2001], i, j, k, cnt = 0, tmp = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &l[i]); } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (l[j] < l[i]) { tmp = l[i]; l[i] = l[j]; l[j] = tmp; } } } for (i = 0; i < n - 2; i++) { for (j = i + 1; j < n - 1; j++) { for (k = j + 1; k < n; k++) { if (l[i] + l[j] > l[k]) { cnt++; } else { break; } } } } printf("%d\n", cnt); return 0; }
s401511324
[ { "input": "4\n3 4 2 1\n", "output": "1\n" } ]
C
codenet
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) int compare_int(const void *a, const void *b) { return *(long int *)b - *(long int *)a; } long int gcd(long int a, long int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } long int lcm(long int a, long int b) { return a * b / gcd(a, b); } int main(void) { long int n; long long int k; long int q; long int a[100001]; long long int point[100001] = {0}; scanf("%ld%lld%ld", &n, &k, &q); for (long int i = 0; i < q; i++) { scanf("%ld", &a[i]); point[a[i] - 1]++; } for (long int i = 0; i < n; i++) { if (k - (q - point[i]) > 0) { printf("Yes\n"); } else { printf("No\n"); } } return 0; }
s497487985
[ { "input": "6 3 4\n3\n1\n3\n2\n", "output": "No\nNo\nYes\nNo\nNo\nNo\n" } ]
C
codenet
#include <stdio.h> int main() { int K, X; scanf("%d %d", &K, &X); for (int i = X - K + 1; i <= X + K - 1; i++) { printf("%d", i); if (i < X + K - 1) printf(" "); } printf("\n"); return 0; }
s844088973
[ { "input": "3 7\n", "output": "5 6 7 8 9\n" } ]
C
codenet
#include <stdio.h> int main(void) { int sheep; int wolf; scanf("%d %d", &sheep, &wolf); if (wolf >= sheep) { printf("unsafe\n"); } else { printf("safe\n"); } return 0; }
s736909850
[ { "input": "4 5\n", "output": "unsafe\n" } ]
C
codenet
#include <stdio.h> int main(void) { int i, N, x; x = 0; scanf("%d", &N); for (i = 1; i <= N; i++) x += i; printf("%d\n", x); return 0; }
s982114524
[ { "input": "3\n", "output": "6\n" } ]
C
codenet
#include <stdio.h> #define MAX 100005 #define N 100 typedef struct { char name[N]; int t; } P; P Q[MAX + 1]; int head, tail; void Enqueue(P x) { if (MAX == tail) tail = 0; Q[tail] = x; tail++; } P Dequeue(void) { if (head == MAX) head = 0; return Q[head++]; } int main() { int i, q, n, T = 0; P a; scanf("%d %d", &n, &q); for (i = 0; i < n; i++) { scanf("%s%d", a.name, &a.t); Enqueue(a); } while (n != 0) { a = Dequeue(); if (a.t > q) { a.t = a.t - q; T += q; Enqueue(a); } else { T = T + a.t; printf("%s %d\n", a.name, T); n--; } } return 0; }
s805240083
[ { "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> signed main() { int n, k, p[99999], i, j, l, m, o = 0; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) { scanf("%d", &p[i]); } for (i = 0; i < n; i++) { l = i; for (j = i + 1; j < n; j++) { if (p[j] < p[l]) { l = j; } } if (l != i) { m = p[i]; p[i] = p[l]; p[l] = m; } } for (i = 0; i < k; i++) { o += p[i]; } printf("%d\n", o); return (0); }
s180134172
[ { "input": "5 3\n50 100 80 120 80\n", "output": "210\n" } ]
C
codenet
#include <stdio.h> int main(void) { long sum = 0; int m, n, i, min, max; scanf("%d\n", &n); for (i = 0; i < n; i++) { scanf("%d", &m); sum += m; if (i == 0) { min = m; max = m; } if (min > m) { min = m; } if (max < m) { max = m; } } printf("%d %d %ld\n", min, max, sum); }
s859058692
[ { "input": "5\n10 1 5 4 17\n", "output": "1 17 37\n" } ]
C
codenet
#include <stdio.h> int main(void) { int c[3]; while (scanf("%d %d %d", &c[0], &c[1], &c[2]) != EOF) { char card[10] = {0}; int i; int count = 0; int sum = c[0] + c[1]; for (i = 0; i < 3; i++) { card[c[i] - 1] = 1; } for (i = 0; i < 10; i++) { if (card[i] == 0 && sum + i + 1 <= 20) { count++; } } if (count >= 4) { puts("YES"); } else { puts("NO"); } } return 0; }
s405782513
[ { "input": "1 2 3\n5 6 9\n8 9 10\n", "output": "YES\nYES\nNO\n" } ]
C
codenet
#include <stdio.h> int main(void) { int a, b, c, i, count; scanf("%d%d%d", &a, &b, &c); count = 0; for (i = a; i <= b; i++) { if (c % i == 0) count++; } printf("%d\n", count); return 0; }
s201325376
[ { "input": "5 14 80\n", "output": "3\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, x, y; scanf("%d%d", &a, &b); x = a * b; y = (a + b) * 2; printf("%d %d\n", x, y); return 0; }
s912810100
[ { "input": "3 5\n", "output": "15 16\n" } ]
C
codenet
#include <stdio.h> int compare(int *a, int *b) { return (*b - *a); } int main(void) { int array[10], i; for (i = 0; i != 10; i++) scanf("%d", array + i); qsort(array, 10, sizeof(int), compare); for (i = 0; i != 3; i++) printf("%d\n", array[i]); return 0; }
s044733418
[ { "input": "1819\n2003\n876\n2840\n1723\n1673\n3776\n2848\n1592\n922\n", "output": "3776\n2848\n2840\n" } ]
C
codenet
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define ll long long void swap(int *x, int *y) { int temp; temp = *x; *x = *y; *y = temp; return; } long int gcd(long int a, long int b) { long int c; while (b > 0) { c = a % b; a = b; b = c; } return a; } 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); } long int modpow(long int a, long int n, long int mod) { long int ans = 1; while (n > 0) { if (n & 1) { ans = ans * a % mod; } a = a * a % mod; n /= 2; } return ans; } long int modinv(long int a, long int mod) { return modpow(a, mod - 2, mod); } int max(int a, int b) { if (a < b) { return b; } else { return a; } } int min(int a, int b) { if (a < b) { return a; } else { return b; } } void chmax(int *a, int b) { if (*a < b) { *a = b; } return; } void chmin(int *a, int b) { if (*a > b) { *a = b; } return; } int main(void) { int n; scanf("%d", &n); int sum = 0; int m = n; for (int i = 0; i < 9; i++) { sum += n % 10; n /= 10; } if (m % sum == 0) { printf("Yes\n"); } else { printf("No\n"); } return 0; }
s874174693
[ { "input": "12\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, ar, le; scanf("%d %d", &a, &b); ar = a * b; le = 2 * (a + b); printf("%d %d\n", ar, le); return 0; }
s746638117
[ { "input": "3 5\n", "output": "15 16\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> int chmin(int a, int b) { if (a > b) return b; else return a; } int main(int argc, char const *argv[]) { int n; scanf("%d", &n); int dp[n]; int h[n]; for (int i = 0; i < n; ++i) dp[i] = 10000; for (int i = 0; i < n; ++i) scanf("%d", &h[i]); dp[0] = 0; for (int i = 1; i < n; ++i) { if (i == 1) dp[1] = abs(h[1] - h[0]); else dp[i] = chmin(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])); } printf("%d\n", dp[n - 1]); return 0; }
s762058481
[ { "input": "4\n10 30 40 20\n", "output": "30\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); printf("%d %d\n", a * b, 2 * (a + b)); return 0; }
s012871529
[ { "input": "3 5\n", "output": "15 16\n" } ]
C
codenet
#include <stdio.h> #include <string.h> int main() { char mes[101]; scanf("%s", mes); printf("%c%lu%c\n", mes[0], strlen(mes) - 2, mes[strlen(mes) - 1]); return 0; }
s116510273
[ { "input": "internationalization\n", "output": "i18n\n" } ]
C
codenet
#include <stdio.h> int main() { unsigned long long int n, a, b = 0, i, j; scanf("%llu", &n); b = (n * (n - 1)) / 2; printf("%llu\n", b); return 0; }
s497921090
[ { "input": "2\n", "output": "1\n" } ]
C
codenet
#include <stdio.h> int main(void) { int n, r, p, c; int i, j, k, l; int a[51], b[51]; while (1) { scanf("%d %d ", &n, &r); if (!n && !r) break; for (i = 0; i < n; i++) a[i] = i + 1; for (i = 0; i < r; i++) { scanf("%d %d ", &p, &c); for (j = 0; j < c; j++) b[j] = a[n - p - c + 1 + j]; for (j = 0; j < p - 1; j++) a[n - p - c + 1 + j] = a[n - p + j + 1]; for (j = n - p - c + 1 + j, k = 0; k < c; j++, k++) { a[j] = b[k]; } } printf("%d\n", a[n - 1]); } return 0; }
s403900151
[ { "input": "5 2\n3 1\n3 1\n10 3\n1 10\n10 1\n8 3\n0 0\n", "output": "4\n4\n" } ]
C
codenet
#include <stdio.h> int main(void) { int x; scanf("%d", &x); if (x == 0) printf("1\n"); if (x == 1) printf("0\n"); return 0; }
s113351650
[ { "input": "1\n", "output": "0\n" } ]
C
codenet
#include <stdio.h> int main(void) { int x; scanf("%d", &x); printf("%d\n", x * x * x); return 0; }
s132873327
[ { "input": "2\n", "output": "8\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> int main() { int a, c, k, b; while (~scanf("%d", &a)) { c = 0, k = 0; if (a < 3) printf("0\n"); else { b = a; while (a--) { b--; c++; if (c == 3) { k++; c = 0; } } printf("%d\n", k); } } }
s326049239
[ { "input": "8\n", "output": "2\n" } ]
C
codenet
#include <stdio.h> int main() { int n; long sum = 0; scanf("%d", &n); int a[n]; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 1; i < n; i++) { if (a[i - 1] > a[i]) { sum += a[i - 1] - a[i]; a[i] = a[i - 1]; } } printf("%ld\n", sum); }
s986241762
[ { "input": "5\n2 1 5 4 3\n", "output": "4\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 key) { NodePointer cur = nil->next; while (cur != nil) { if (cur->key == key) break; cur = cur->next; } return cur; } void init() { nil = (NodePointer)malloc(sizeof(struct node)); nil->next = nil; nil->prev = nil; } void printList() { 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) { if (t == nil) return; t->prev->next = t->next; t->next->prev = t->prev; free(t); } void deleteFirst() { NodePointer t = nil->next; if (t == nil) return; deleteNode(t); } void deleteLast() { NodePointer t = nil->prev; if (t == nil) return; deleteNode(t); } void deleteKey(int key) { NodePointer t = listSearch(key); if (t != nil) deleteNode(t); } void insert(int key) { NodePointer x; x = (NodePointer)malloc(sizeof(struct node)); x->key = key; x->prev = nil; x->next = nil->next; x->next->prev = x; nil->next = x; } 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 { deleteKey(key); nd++; } size--; } } printList(); return 0; }
s858205159
[ { "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> #include <stdlib.h> int *flag; void prime(int num) { int i, j; flag = (int *)calloc(sizeof(int), num + 1); for (i = 2; i * i <= num; i++) { if (flag[i] == 0) { for (j = 2; i * j <= num; j++) { flag[i * j] = 1; } } } } int main() { int n, i, cnt; prime(50000); while (1) { scanf("%d", &n); if (n == 0) { break; } i = 2; cnt = 0; while (i * 2 <= n) { if (!flag[i] && !flag[n - i]) { cnt++; } i++; } printf("%d\n", cnt); } return 0; }
s501370664
[ { "input": "10\n11\n0\n", "output": "2\n0\n" } ]
C
codenet
#include <stdio.h> int main() { int m1, d1, m2, d2; scanf("%d%d%d%d", &m1, &d1, &m2, &d2); if (m1 != m2) printf("1\n"); else printf("0\n"); }
s669832162
[ { "input": "11 16\n11 17\n", "output": "0\n" } ]
C
codenet
#include <stdio.h> #define LEN 300 #define TRUE 1 #define FALSE -1 int solve(int, int); int n, A[LEN]; int flag; int main() { int q, M; int i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &A[i]); scanf("%d", &q); for (i = 0; i < q; i++) { scanf("%d", &M); flag = FALSE; solve(-1, M); if (flag == TRUE) printf("yes\n"); else printf("no\n"); } return 0; } int solve(int i, int m) { if (i > n) return FALSE; else if (m < 0) return FALSE; else if (m == 0 || m - A[i + 1] == 0) { flag = TRUE; return TRUE; } else { solve(i + 1, m); solve(i + 1, m - A[i]); } }
s157790373
[ { "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> int n, r, i, j, p, c; int a[100], b[100]; int main() { while (1) { scanf("%d %d", &n, &r); if (n == 0 && r == 0) break; for (i = 0; i < n; i++) { a[i] = n - i; } for (i = 0; i < r; i++) { for (j = 0; j < n; j++) { b[j] = a[j]; } scanf("%d %d", &p, &c); for (j = 0; j < c; j++) { a[j] = b[p - 1 + j]; } for (j = c; j < c + p - 1; j++) { a[j] = b[j - c]; } } printf("%d\n", a[0]); } return 0; }
s622875333
[ { "input": "5 2\n3 1\n3 1\n10 3\n1 10\n10 1\n8 3\n0 0\n", "output": "4\n4\n" } ]
C
codenet
#include <stdio.h> int main(void) { long int n; scanf("%ld", &n); long int a[n]; long int count[n]; for (long int i = 1; i < n; i++) scanf("%ld", &a[i]); for (long int i = 0; i < n; i++) count[i] = 0; for (long int i = 1; i < n; i++) count[a[i] - 1]++; for (long int i = 0; i < n; i++) printf("%ld\n", count[i]); return 0; }
s044095882
[ { "input": "5\n1 1 2 2\n", "output": "2\n2\n0\n0\n0\n" } ]
C
codenet
#include <stdio.h> int main(void) { int N; scanf("%d", &N); int A[N + 1]; int B[N]; int i; for (i = 0; i < N + 1; i++) { scanf("%d", &A[i]); } for (i = 0; i < N; i++) { scanf("%d", &B[i]); } long ans = 0; for (i = 0; i < N; i++) { if (A[i] >= B[i]) { ans = ans + B[i]; A[i] = A[i] - B[i]; B[i] = 0; } else { ans = ans + A[i]; B[i] = B[i] - A[i]; A[i] = 0; } if (A[i + 1] >= B[i]) { ans = ans + B[i]; A[i + 1] = A[i + 1] - B[i]; B[i] = 0; } else { ans = ans + A[i + 1]; B[i] = B[i] - A[i + 1]; A[i + 1] = 0; } } printf("%ld\n", ans); return 0; }
s540088752
[ { "input": "2\n3 5 2\n4 5\n", "output": "9\n" } ]
C
codenet
#include <stdio.h> int main() { int a, b, c; scanf("%d %d %d", &a, &b, &c); if (a < b && b < c) { printf("Yes\n"); } else { printf("No\n"); } return 0; }
s120311699
[ { "input": "1 3 8\n", "output": "Yes\n" } ]
C
codenet
#include <stdio.h> int main() { int i, j, N, A[100], tmp, count = 0; scanf("%d", &N); for (i = 0; i < N; i++) { scanf("%d", &A[i]); } for (i = 0; i < N - 1; i++) { for (j = N - 1; j > i; j--) { if (A[j] < A[j - 1]) { tmp = A[j]; A[j] = A[j - 1]; A[j - 1] = tmp; count++; } } } for (i = 0; i < N; i++) { printf("%d", A[i]); if (i < N - 1) printf(" "); } printf("\n"); printf("%d\n", count); return 0; }
s977107185
[ { "input": "5\n5 3 2 4 1\n", "output": "1 2 3 4 5\n8\n" } ]
C
codenet
#include <stdio.h> int search(int A[], int n, int key) { int i = 0; A[n] = key; while (A[i] != key) i++; return i != n; } int main(void) { int n, A[10000 + 1], q, key, sum = 0; int i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &A[i]); scanf("%d", &q); for (i = 0; i < q; i++) { scanf("%d", &key); if (search(A, n, key)) sum++; } printf("%d\n", sum); return 0; }
s858795471
[ { "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 c[11], ans[11] = {'\0'}; scanf("%s", c); for (int i = 0; c[i] != '\0'; i++) { if (c[i] != 'B') ans[strlen(ans)] = c[i]; else ans[strlen(ans) - 1] = '\0'; } printf("%s\n", ans); }
s352097291
[ { "input": "01B0\n", "output": "00\n" } ]
C
codenet
#include <stdio.h> int main() { int S; scanf("%d", &S); printf("%d:%d:%d\n", (int)(S / 3600), (int)((S % 3600) / 60), S % 60); return 0; }
s575722828
[ { "input": "46979\n", "output": "13:2:59\n" } ]
C
codenet
#include <stdio.h> #include <stdlib.h> void run(void) { int n, k; scanf("%d%d", &n, &k); int a[100]; int i, j; for (i = 0; i < n; i++) scanf("%d", a + i); int *dp = (int *)calloc(k + 1, sizeof(int)); for (i = 1; i <= k; i++) { int win = 0; for (j = 0; j < n && a[j] <= i; j++) { if (dp[i - a[j]] == 0) { win = 1; } } dp[i] = win; } printf("%s\n", dp[k] ? "First" : "Second"); } int main(void) { run(); return 0; }
s436432602
[ { "input": "2 4\n2 3\n", "output": "First\n" } ]