public int solution(int[] A) {
    int arraySize = A.length;
    double minimalAverage = Integer.MAX_VALUE;
    int minIndex = 0;
    for (int i = 0; i < arraySize; i++) {
      // has next element ?
      if (i + 1 < arraySize) {
        double averageOfTwo = (A[i] + A[i + 1]) / (double) 2;
        if (averageOfTwo < minimalAverage) {
          minimalAverage = averageOfTwo;
          minIndex = i;
        }
        // has two next elements ?
        if (i + 2 < arraySize) {
          double averageOfThree = (A[i] + A[i + 1] + A[i + 2]) / 3d;
          if (averageOfThree < minimalAverage) {
            minimalAverage = averageOfThree;
            minIndex = i;
          }
        }
      }
    }
    return minIndex;
  }