#include <stdio.h>
static int count;

int cmp(int x, int y)            // compare x with y
{
    return x < y;                // 1 if x < y, 0 otherwise
}

void swap(int *x, int *y)
{
    int tmp = *x;
    *x = *y;
    *y = tmp;
    count++;
    
}

size_t select(int p[], size_t len)
{
    size_t pos = 0;              // position of the highest-precedence element
    for (size_t i = 0; i < len; ++i) {
       if (!cmp(p[pos], p[i])) {
            pos = i;
        }
    }
    return pos;
}

void disp(int p[], size_t len)
{
    for (size_t i = 0; i < len; ++i) {
        printf("%d ", p[i]);
    }
    printf("\n");
}

int main(void)
{
    int a[] = {3, 1, 4, 1, 5, 9, 2, 6, 5};
    size_t n = sizeof a / sizeof a[0];

    for (size_t i = 0; i < n - 1; ++i) {
        size_t j = i + 1 + select(a + i + 1, n - i - 1);
        if (cmp(a[j], a[i])) {
            swap(&a[j], &a[i]);
        }
    }

    disp(a, n);
    printf("%d", count);
    return 0;
}