import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Solution {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int size = sc.nextInt();
    int[] arr = new int[size];
    for (int i = 0; i < size; i++) {
      arr[i] = sc.nextInt();
    }

    int count = 0;
    for (int i = 0; i < size; i++) {
      int sum = 0;
      for (int j = i; j < size; j++) {
        sum += arr[j];
        if (sum < 0) {
          count++;
        }
      }
    }
    System.out.println(count);
  }
}

@@ -9,125 +9,547 @@
 ava.
-io.*;%0Aimport java.math.*;%0Aimport java.text.*;%0Aimport java.util.*;%0Aimport java.util.regex.*;%0A%0Apublic class Solution %7B%0A
+util.*;%0A%0Apublic class Solution %7B%0A%0A    public static boolean canWin(int leap, int%5B%5D array, int currentLocation) %7B%0A      if (currentLocation %3E= array.length) %7B%0A        return true;%0A      %7D%0A      if (currentLocation %3C 0 %7C%7C array%5BcurrentLocation%5D == 1) %7B%0A        return false;%0A      %7D%0A%0A      // mark current location as visited%0A      array%5BcurrentLocation%5D = 1;%0A      return canWin(leap, array, currentLocation - 1) %7C%7C%0A             canWin(leap, array, currentLocation + 1) %7C%7C%0A             canWin(leap, array, currentLocation + leap);%0A    %7D%0A%0A  
   pu
@@ -583,24 +583,28 @@
 g%5B%5D args) %7B%0A
+    
     Scanner 
@@ -605,16 +605,18 @@
 anner sc
+an
  = new S
@@ -634,25 +634,28 @@
 em.in);%0A
-%0A
+    
     int 
 size = s
@@ -650,17 +650,16 @@
 int 
-size
+q
  = sc
+an
 .nex
@@ -674,89 +674,54 @@
     
-int%5B%5D arr = new int%5Bsize%5D;%0A    for (int i = 0; i %3C size; i++) %7B%0A      arr%5Bi%5D
+    while (q-- %3E 0) %7B%0A            int n
  = sc
+an
 .nex
@@ -736,92 +736,93 @@
     
-%7D%0A%0A
     
-int count = 0;%0A    for (int i = 0; i %3C size; i++) %7B%0A      int sum = 0;%0A
+    int leap = scan.nextInt();%0A%0A            int%5B%5D game = new int%5Bn%5D;%0A     
       
+ 
 for 
@@ -830,26 +830,23 @@
 int 
-j = i; j %3C size; j
+i = 0; i %3C n; i
 ++) 
@@ -859,75 +859,129 @@
     
-sum += arr%5Bj%5D;%0A        if (sum %3C 0) %7B%0A          count++;%0A        %7D%0A
+        game%5Bi%5D = scan.nextInt();%0A            %7D%0A%0A            System.out.println(canWin(leap, game, 0) ? %22YES%22 : %22NO%22);%0A  
     
@@ -992,41 +992,28 @@
     
-%7D%0A
     
-System.out.println(count
+scan.close(
 );%0A
+  
   %7D%0A

Solve java 1d array