Language: C++

import java.io.*;
import java.util.*;
import java.math.*;
 
class Main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
    public static int INF = 0x3f3f3f3f;
    public static int MOD = 1000000007;
    public static long LINF = 0x3f3f3f3f3f3f3f3fL;

    public static void main(String[] args) throws Exception {
        int N = Integer.parseInt(br.readLine());
        st = new StringTokenizer(br.readLine());
        long[] A = new long[N];
        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(st.nextToken());
        }

        HashMap<Long, Integer> d = new HashMap<Long, Integer>();

        long ans = 0;
        for (int i = 0; i < N; i++) {
            // System.out.println(d);
            if (d.containsKey(-A[i])) {
                ans += d.get(-A[i]);
            }
            HashMap<Long, Integer> d2 = new HashMap<Long, Integer>();
            for (long v : d.keySet()) {
                long v2 = v + A[i];
                if (d2.containsKey(v2)) {
                    d2.put(v2, d2.get(v2) + d.get(v));
                } else {
                    d2.put(v2, d.get(v));
                }
            }
            // System.out.println(d2);      
            d = d2;
            if (d.containsKey(A[i])) {
                d.put(A[i], d.get(A[i]) + 1);
            } else {
                d.put(A[i], 1);
            }

        }

        pw.println(ans);
        
        pw.close(); 
        br.close();
    }
}

class Point implements Comparable<Point>{
    public int x, y;
 
    Point(int _x, int _y){
        x = _x;
        y = _y;
    }
 
    public String toString(){
        return x + " " + y;
    }

    public int compareTo(Point p){
        if (x != p.x) return x < p.x ? -1 : 1;
        if (y != p.y) return y < p.y ? -1 : 1;
        return 0;
    }
} 


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.*;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.math.*;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:11: error: expected ':' before 'static'
    6 |     public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      |           ^~~~~~~
      |           :
a.cc:6:19: error: 'BufferedReader' does not name a type
    6 |     public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      |                   ^~~~~~~~~~~~~~
a.cc:7:11: error: expected ':' before 'static'
    7 |     public static PrintWriter pw = new PrintWriter(System.out);
      |           ^~~~~~~
      |           :
a.cc:7:19: error: 'PrintWriter' does not name a type
    7 |     public static PrintWriter pw = new PrintWriter(System.out);
      |                   ^~~~~~~~~~~
a.cc:8:11: error: expected ':' before 'static'
    8 |     public static String line;
      |           ^~~~~~~
      |           :
a.cc:8:19: error: 'String' does not name a type
    8 |     public static String line;
      |                   ^~~~~~
a.cc:9:11: error: expected ':' before 'static'
    9 |     public static StringTokenizer st;
      |           ^~~~~~~
      |           :
a.cc:9:19: error: 'StringTokenizer' does not name a type
    9 |     public static StringTokenizer st;
      |                   ^~~~~~~~~~~~~~~
a.cc:10:11: error: expected ':' before 'static'
   10 |     public static ArrayList<ArrayList<Integer>> adjList;
      |           ^~~~~~~
      |           :
a.cc:10:19: error: 'ArrayList' does not name a type
   10 |     public static ArrayList<ArrayList<Integer>> adjList;
      |                   ^~~~~~~~~
a.cc:11:11: error: expected ':' before 'static'
   11 |     public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
      |           ^~~~~~~
      |           :
a.cc:11:22: error: expected unqualified-id before '[' token
   11 |     public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
      |                      ^
a.cc:12:11: error: expected ':' before 'static'
   12 |     public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
      |           ^~~~~~~
      |           :
a.cc:12:22: error: expected unqualified-id before '[' token
   12 |     public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
      |                      ^
a.cc:13:11: error: expected ':' before 'static'
   13 |     public static int INF = 0x3f3f3f3f;
      |           ^~~~~~~
      |           :
a.cc:13:23: error: ISO C++ forbids in-class initialization of non-const static member 'Main::INF'
   13 |     public static int INF = 0x3f3f3f3f;
      |                       ^~~
a.cc:14:11: error: expected ':' before 'static'
   14 |     public static int MOD = 1000000007;
      |           ^~~~~~~
      |           :
a.cc:14:23: error: ISO C++ forbids in-class initialization of non-const static member 'Main::MOD'
   14 |     public static int MOD = 1000000007;
      |                       ^~~
a.cc:15:11: error: expected ':' before 'static'
   15 |     public static long LINF = 0x3f3f3f3f3f3f3f3fL;
      |           ^~~~~~~
      |           :
a.cc:15:24: error: ISO C++ forbids in-class initialization of non-const static member 'Main::LINF'
   15 |     public static long LINF = 0x3f3f3f3f3f3f3f3fL;
      |                        ^~~~
a.cc:17:11: error: expected ':' before 'static'
   17 |     public static void main(String[] args) throws Exception {
      |           ^~~~~~~
      |           :
a.cc:17:29: error: 'String' has not been declared
   17 |     public static void main(String[] args) throws Exception {
      |                             ^~~~~~
a.cc:17:38: error: expected ',' or '...' before 'args'
   17 |     public static void main(String[] args) throws Exception {
      |                                      ^~~~
a.cc:17:42: error: expected ';' at end of member declaration
   17 |     public static void main(String[] args) throws Exception {
      |                                          ^
      |                                           ;
a.cc:17:44: error: 'throws' does not name a type
   17 |     public static void main(String[] args) throws Exception {
      |                                            ^~~~~~
a.cc:57:2: error: expected ';' after class definition
   57 | }
      |  ^
      |  ;
a.cc:59:24: error: expected initializer before 'Comparable'
   59 | class Point implements Comparable<Point>{
      |                        ^~~~~~~~~~