This page is still under construction.

Parts of this page are still being built. What you see may change.

Moon and Sun

Time limit1sMemory limit512 MB

Summary
Count indices i where changing A_i to some other integer in [-100000, 100000] makes the single element of the N-fold difference sequence a multiple of 235813.
Level

Hard8 of 10

Topics
Math, Combinatorics, Number theory, Implementation
Solved
No attempts yet

Problem

Let SS be a non-empty sequence of integers and KK a positive integer. The functions moon()moon() and sun()sun() are defined as follows.

moon(S1…∣S∣)={Sif ∣S∣=1[S2−S1,S3−S2,…,S∣S∣−S∣S∣−1]if ∣S∣>1moon\left(S_{1\dots|S|}\right) = \begin{cases} S & \text{if } |S| = 1 \\ \left[ S_2 - S_1, S_3 - S_2, \dots , S_{|S|} - S_{|S|-1} \right] & \text{if }|S| > 1 \end{cases}

sun(S1…∣S∣,K)={Sif K=1sun(moon(S1…∣S∣),K−1)if K>1sun\left(S_{1\dots|S|}, K\right) = \begin{cases} S & \text{if } K = 1 \\ sun\left(moon\left(S_1\dots|S|\right), K - 1\right) & \text{if }K > 1 \end{cases}

For example,

  • moon([2,7])=[5]moon([2, 7]) = [5].
  • moon([4,1,0,7,2])=[−3,−1,7,−5]moon([4, 1, 0, 7, 2]) = [-3, -1, 7, -5].
  • sun([4,1,0,7,2],5)=sun([−3,−1,7,−5],4)=sun([2,8,−12],3)=sun([6,−20],2)=sun([−26],1)=[−26]sun([4, 1, 0, 7, 2], 5) = sun([-3, -1, 7, -5], 4) = sun([2, 8, -12], 3) = sun([6, -20], 2) = sun([-26], 1) = [-26].

Note that sun(S1…∣S∣,∣S∣)sun\left(S_{1\dots |S|}, |S|\right) is always a sequence with exactly one element.

You are given a sequence of NN integers A1…NA_{1\dots N}. An index i=[1…N]i = [1\dots N] is hot if and only if there exists a sequence A1…N′A'_{1\dots N} satisfying the following conditions.

  • Ai′≠AiA'_i \ne A_i and Ai′A_i' is an integer between −100 000-100\,000 and 100 000100\,000, inclusive;
  • Aj′=AjA'_j = A_j for all j≠ij \ne i;
  • The only element in sun(A1…N′,N)sun\left(A'_{1\dots N}, N\right) is a multiple of 235 813235\,813.

Your task in this problem is to count the number of hot indices in a given A1…NA_{1\dots N}.

For example, there are 33 hot indices in A1…5=[4,1,0,7,2]A_{1\dots 5} = [4, 1, 0, 7, 2], which are {1,3,5}\{1, 3, 5\}.

  • i=1i = 1, A1′=30→A1…5′=[30,1,0,7,2]→sun([30,1,0,7,2],5)=[0]A'_1 = 30 \rightarrow A'_{1\dots5} = [30, 1, 0, 7, 2] \rightarrow sun([30, 1, 0, 7, 2], 5) = [0]
  • i=3i = 3, A3′=−78 600→A1…5′=[4,1,−78 600,7,2]→sun([4,1,−78 600,7,2],5)=[−471 626]A'_3 = -78\,600 \rightarrow A'_{1\dots5} = [4, 1, -78\,600, 7, 2] \rightarrow sun([4, 1, -78\,600, 7, 2], 5) = [-471\,626]
  • i=5i = 5, A5′=28→A1…5′=[4,1,0,7,28]→sun([4,1,0,7,28],5)=[0]A'_5 = 28 \rightarrow A'_{1\dots5} = [4, 1, 0, 7, 28] \rightarrow sun([4, 1, 0, 7, 28], 5) = [0]

Both 00 and −471 626-471\,626 are multiples of 235 813235\,813. On the other hand, the index i=2i = 2 is not hot, as there is no integer A2′≠A2A'_2 \ne A_2 between −100 000-100\,000 and 100 000100\,000, inclusive, such that the only element in sun(A1…5′,5)sun(A'_{1\dots 5}, 5) is a multiple of 235 813235\,813. The index i=4i = 4 is also not hot for the same reason.

Input

The first line contains an integer NN (1≤N≤100 0001 \le N \le 100\,000), the number of integers in AA. The next line contains NN integers AiA_i (−100 000≤Ai≤100 000-100\,000 \le A_i \le 100\,000), the sequence of integers.

Output

Output in one line the number of hot indices in the given A1…NA_{1\dots N}.

Examples3

  1. Example 1

    Input
    5
    4 1 0 7 2
    
    Expected output
    3
    
  2. Example 2

    Input
    4
    10 20 30 -40
    
    Expected output
    4
    
  3. Example 3

    Input
    2
    100 100
    
    Expected output
    0