{"raw_statement":[{"iden":"statement","content":"You are given a sequence A consisting of N integers. We will call the i-th element *good* if it equals the sum of some three elements in positions strictly smaller than i (an element can be used more than once in the sum).\n\nHow many good elements does the sequence contain?\n\nThe first line of input contains the positive integer N (1 ≤ N ≤ 5000), the length of the sequence A.\n\nThe second line of input contains N space-separated integers representing the sequence A ( - 105 ≤ Ai ≤ 105).\n\nThe first and only line of output must contain the number of good elements in the sequence.\n\n"},{"iden":"input","content":"The first line of input contains the positive integer N (1 ≤ N ≤ 5000), the length of the sequence A.The second line of input contains N space-separated integers representing the sequence A ( - 105 ≤ Ai ≤ 105)."},{"iden":"output","content":"The first and only line of output must contain the number of good elements in the sequence."},{"iden":"examples","content":"Input21 3Output1Input61 2 3 5 7 10Output4Input3-1 2 0Output1"}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $ be the length of the sequence.  \nLet $ A = (a_1, a_2, \\dots, a_N) $ be a sequence of integers, where $ a_i \\in \\mathbb{Z} $ for all $ i \\in \\{1, \\dots, N\\} $.\n\n**Constraints**  \n1. $ 1 \\leq N \\leq 5000 $  \n2. $ -10^5 \\leq a_i \\leq 10^5 $ for all $ i \\in \\{1, \\dots, N\\} $\n\n**Objective**  \nDefine an element $ a_i $ (for $ i \\geq 4 $) as *good* if there exist indices $ j, k, \\ell \\in \\{1, \\dots, i-1\\} $ (not necessarily distinct) such that:  \n$$ a_i = a_j + a_k + a_\\ell $$  \n\nCompute the number of good elements in $ A $, i.e.,  \n$$ \\left| \\left\\{ i \\in \\{4, \\dots, N\\} \\mid \\exists\\, j,k,\\ell \\in \\{1, \\dots, i-1\\} \\text{ such that } a_i = a_j + a_k + a_\\ell \\right\\} \\right| $$","simple_statement":"Count how many elements in the sequence are equal to the sum of any three earlier elements (using repeats allowed).","has_page_source":false}