package = org.jetbrains.typesBenchmarks

---
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>

int charFrequency(const char* string, char charToFind) {
    int frequency = 0;
    for(int i = 0; string[i] != '\0'; ++i) {
       if(charToFind == string[i])
           ++frequency;
    }
    return frequency;
}

const char* findSuitableString(const char* stringsArray[], int arraySize, const char* stringToFind) {
    for(int i = 0; i < arraySize; ++i) {
        if (strstr(stringsArray[i], stringToFind) != NULL) {
            char* result = (char*) malloc((strlen(stringsArray[i])+1)*sizeof(char));
            strcpy(result, stringsArray[i]);
            return result;
        }
    }
    return NULL;
}

void freeSuitableString(char* unusedString) {
    free(unusedString);
}

unsigned long int sum(int array[], int arraySize) {
    unsigned long int result = 0;
    for(int i = 0; i < arraySize; ++i) {
        result += array[i];
    }
    return result;
}

double average(int count, ...) {
    va_list list;
    int j = 0;
    va_start(list, count);
    double sum = 0;
    for(j=0; j<count; j++) {
        sum += va_arg(list, int);
    }
    va_end(list);
    return sum / count;
}

int** multiplyMatrix(int m1, int m2, const int** mat1, int n1, int n2, const int** mat2) {
    int x, i, j;
    int **res = (int **)malloc(m1 * sizeof(int *));
    for (i=0; i<m1; i++) {
         res[i] = (int *)malloc(n2 * sizeof(int));
    }
    for (i = 0; i < m1; i++) {
        for (j = 0; j < n2; j++) {
            res[i][j] = 0;
            for (x = 0; x < m2; x++) {
                res[i][j] += mat1[i][x] * mat2[x][j];
            }
        }
    }
    return  res;
}