package org.shkim.codility.demo;


/**
 * 
 * https://codility.com/demo/results/demoUMKAHB-74G/ 64%
 * @author parad
 *
 */
public class Demo
{
	public static int solution(int A[])
	{

		int N = A.length;

		long in_left = 0;
		long in_right = 0;

		for (int i = 0; i < N; i++)
		{
			in_left = 0;
			in_right = 0;

			if (i != 0)
			{
				for (int j = 0; j < i; j++)
				{
					in_left += A[j];
				}
			}

			if (i != N - 1)
			{

				for (int j = i + 1; j < N; j++)
				{
					in_right += A[j];
				}
			}

			if (in_left == in_right)
			{
				return i;
			}
		}

		return -1;
	}
}

@@ -27,17 +27,16 @@
 .demo;%0A%0A
-%0A
 /**%0A * %0A
@@ -92,16 +92,20 @@
 4G/ 64%25%0A
+ * %0A
  * @auth
@@ -140,16 +140,17 @@
  Demo%0A%7B%0A
+%0A
 %09public 
@@ -160,53 +160,253 @@
 tic 
-int solution(int A%5B%5D)%0A%09%7B%0A%0A%09%09int N = A.length;
+void main(String%5B%5D args)%0A%09%7B%0A%09%09int A%5B%5D = %7B -1, 3, -4, 5, 1, -6, 2, 1 %7D;%0A%09%09System.out.println(solution(A));%0A%09%7D%0A%0A%09private static int solution(int A%5B%5D)%0A%09%7B%0A%0A%09%09int N = A.length;%0A%0A%09%09if (N == 1)%0A%09%09%7B%0A%09%09%09return 1;%0A%09%09%7D else if (N == 0)%0A%09%09%7B%0A%09%09%09return 0;%0A%09%09%7D
 %0A%0A%09%09
@@ -445,16 +445,37 @@
 t = 0;%0A%0A
+%09%09long all_sum = 0L;%0A
 %09%09for (i
@@ -507,98 +507,121 @@
 %0A%09%09%09
-in_left = 0;%0A%09%09%09in_right
+all_sum += A%5Bi%5D;%0A%09%09%7D%0A%0A%09%09long temp
  = 0
+L
 ;
-%0A
 %0A%09%09
-%09if (i != 0
+for (int i = 0; i %3C N; i++
 )%0A
-%09
 %09%09%7B%0A
+%0A
 %09%09%09
-%09for (int j = 0; j %3C i; j++
+temp += A%5Bi%5D;%0A%0A%09%09%09if (i == 0
 )%0A%09%09%09
-%09
 %7B%0A
-%09
 %09%09%09%09
@@ -632,39 +632,61 @@
 eft 
-+
 = 
-A%5Bj%5D
+0
 ;%0A%09%09%09%09
-%7D%0A%09%09%09%7D%0A%0A%09%09%09
+in_right = all_sum - A%5Bi%5D;%0A%09%09%09%7D else 
 if (i 
-!
+=
 = N 
@@ -699,79 +699,138 @@
 %09%09%7B%0A
-%0A
 %09%09%09%09
-for (int j = i + 1; j %3C N; j++)
+in_left = all_sum - A%5Bi%5D;%0A%09%09%09%09in_right = 0;%0A%09%09%09%7D else
 %0A%09%09%09
-%09
 %7B%0A
-%09
 %09%09%09%09in_
-righ
+lef
 t 
-+
 =
+ temp -
  A%5B
-j
+i
 %5D;%0A%09%09%09%09
-%7D
+in_right = all_sum - in_left - A%5Bi%5D;
 %0A%09%09%09

change demo