Palindromic Sum
Tag(s):

## FFT, Math, Medium-Hard

Problem
Editorial
Analytics

Given an array A of length N, find the number of non empty sub-arrays such that sum of all the elements in the sub-array is a palindrome. In other words, you have to find number of pairs $(i,\;j)$ such that $\sum_{x=i}^j A_x$ is a palindrome where $(1 \le i \le j \le N)$.

Input Format:
First line contains an integer, N $(1 \le N \le 5 * 10^5)$. Second line contains N space separated integers, $A_i$ $(1 \le A_i \le 2 * 10^6)$, elements of the array A. The sum of all the elements in the array is in the range $[1, 2 * 10^6]$.

Output Format:
Print an integer, number of non empty sub-arrays such that sum of all the elements in the sub-array is a palindrome.

SAMPLE INPUT
4
10 1 12 3


SAMPLE OUTPUT
3

Explanation

The 3 sub-arrays are $(10,\;1)$, 1 and 3.

Time Limit: 2.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), TypeScript, Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in

Challenge Name

HackerEarth Collegiate Cup - Mirror Round

OTHER PROBLEMS OF THIS CHALLENGE
• Basic Programming > Bit Manipulation
• Algorithms > Dynamic Programming
• Algorithms > Sorting
• Algorithms > Dynamic Programming
• Algorithms > Graphs
• Algorithms > Graphs
• Data Structures > Advanced Data Structures
• Algorithms > Graphs
• Algorithms > Searching
• Algorithms > Dynamic Programming