iidai/codenet huggingface dataset:
Language: C

#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;
}

Example test case(s):
input: keyofscience

output: YES
Language: C

#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;
}

Example test case(s):
input: 6
1 2 3 2 2 1

output: 2
Language: C

#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;
}

Example test case(s):
input: 4
3 8 5 1

output: Yes
Language: C

#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;
}

Example test case(s):
input: 3 6 9 7 5

output: 9 7 6 5 3
Language: C

#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;
}

Example test case(s):
input: 1 0 1
2 1 2
1 0 1

output: Yes
Language: C

#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;
}

Example test case(s):
input: pot
top

output: YES
Language: C

#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;
}

Example test case(s):
input: 5 1
1 0 0 1 0

output: 1 2 2 1 2
Language: C

#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;
}

Example test case(s):
input: 4 150
150 140 100 200

output: 2
Language: C

#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;
}

Example test case(s):
input: 30 100

output: 100
Language: C

#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;
}

Example test case(s):
input: 6
D 3
H 2
D 1
S 3
D 2
C 1

output: Not stable
D 1
C 1
D 2
H 2
D 3
S 3
Language: C

#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;
}

Example test case(s):
input: 3 5

output: 15 16
Language: C

#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;
}

Example test case(s):
input: 54 20

output: 2
Language: C

#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;
}

Example test case(s):
input: 4
3 4 2 1

output: 1
Language: C

#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;
}

Example test case(s):
input: 6 3 4
3
1
3
2

output: No
No
Yes
No
No
No
Language: C

#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;
}

Example test case(s):
input: 3 7

output: 5 6 7 8 9
Language: C

#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;
}

Example test case(s):
input: 4 5

output: unsafe
Language: C

#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;
}

Example test case(s):
input: 3

output: 6
Language: C

#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;
}

Example test case(s):
input: 5 100
p1 150
p2 80
p3 200
p4 350
p5 20

output: p2 180
p5 400
p1 450
p3 550
p4 800
Language: C

#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);
}

Example test case(s):
input: 5 3
50 100 80 120 80

output: 210
Language: C

#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);
}

Example test case(s):
input: 5
10 1 5 4 17

output: 1 17 37
Language: C

#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;
}

Example test case(s):
input: 1 2 3
5 6 9
8 9 10

output: YES
YES
NO
Language: C

#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;
}

Example test case(s):
input: 5 14 80

output: 3
Language: C

#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;
}

Example test case(s):
input: 3 5

output: 15 16
Language: C

#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;
}

Example test case(s):
input: 1819
2003
876
2840
1723
1673
3776
2848
1592
922

output: 3776
2848
2840
Language: C

#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;
}

Example test case(s):
input: 12

output: Yes
Language: C

#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;
}

Example test case(s):
input: 3 5

output: 15 16
Language: C

#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;
}

Example test case(s):
input: 4
10 30 40 20

output: 30
Language: C

#include <stdio.h>
int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d %d\n", a * b, 2 * (a + b));
    return 0;
}

Example test case(s):
input: 3 5

output: 15 16
Language: C

#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;
}

Example test case(s):
input: internationalization

output: i18n
Language: C

#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;
}

Example test case(s):
input: 2

output: 1
Language: C

#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;
}

Example test case(s):
input: 5 2
3 1
3 1
10 3
1 10
10 1
8 3
0 0

output: 4
4
Language: C

#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;
}

Example test case(s):
input: 1

output: 0
Language: C

#include <stdio.h>

int main(void) {
    int x;

    scanf("%d", &x);
    printf("%d\n", x * x * x);

    return 0;
}

Example test case(s):
input: 2

output: 8
Language: C

#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);
        }
    }
}

Example test case(s):
input: 8

output: 2
Language: C

#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);
}

Example test case(s):
input: 5
2 1 5 4 3

output: 4