Problem:
Score : 100 points

Problem Statement

There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?

Constraints

1≦N≦100

Input

The input is given from Standard Input in the following format:

N

Output

Print the necessary number of candies in total.

Sample Input 1

3

Sample Output 1

6

The answer is 1+2+3=6.

Sample Input 2

10

Sample Output 2

55

The sum of the integers from 1 to 10 is 55.

Sample Input 3

1

Sample Output 3

1

Only one child. The answer is 1 in this case.

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

//Be together
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int calcCost(int * array, int size, int y){
   int sum = 0;
   for(int x = 0; x < size; x++){
      sum += ((array[x] - y)*(array[x] - y));
   }
   return sum;
}

int main(){
   int n;
   scanf("%d",&n);
   int * arr = malloc(n*sizeof(int));
   scanf("%d",&arr[0]);
   int min = arr[0];
   int max = arr[0];
   for(int i = 1; i < n; i++){
      scanf("%d",&arr[i]);
      if(arr[i] < min){
         min = arr[i];
      }else if(arr[i] > max){
         max = arr[i];
      }
   }
   
   int lowestCost = 100000;
   int cost = 0;
   while(min <= max){
      cost = calcCost(arr,n,min);
      if(cost < lowestCost){
         lowestCost = cost;
      }
      min++;
   }
   printf("%d\n",lowestCost);
   return EXIT_SUCCESS;
}