// Chris Washburn & Tyler Hoyt
// 9/2/11
// Array Challenge

#include <stdio.h>
#include <math.h>
#include <time.h>

int main() {

    //Set-up and Variables
    int n, numcases;
    int* nums;

    FILE* ifp = fopen("sumHalf.in", "r");
    fscanf(ifp, "%d", &numcases);

    int i;
    for (i=1; i<=numcases; i++) {

        // Allocate space for the array.
        fscanf(ifp, "%d", &n);
        nums=(int*)(malloc(sizeof(int)*n));

        // Read in values into the array.
        int j;
        for (j=0; j<n; j++)
            fscanf(ifp, "%d", &nums[j]);

        //Reference to calculation function
        int x=SumHalf(nums,n);

        //Output
        if (x){
            printf("%d: Yes\n", i);
        }
        else{
            printf("%d: No\n", i);
        }

        free(nums);
    }

    return 0;
}

int SumHalf(int* values, int length) {

    //Variables
    int sum=0;
    int half;
    int add=values[0];
    int high=0;
    int low=0;

    //Calculates the sum of the array
    int i;
    for (i=0; i<length; i++){
        sum+=values[i];
    }

    //Tests the extraneous arrays that are immediately wrong
    if(sum%2 || length==0 || length==1){
        return 0;
    }

    //Tests the array
    half=sum/2;
    while (high<length){

        // Add to our running sum
        if(add<half){
            high++;
            add+=values[high];
        }

        // Our sum's exceed the target, so let's clip off
        // the first element in our list.
        else{

            if(add>half){
                add-=values[low];
                low++;
            }
            else{
                return 1;
            }
        }
    }

    return 0;
}
