Breed Counting

Given the breed of each cow in a row, report the count of each of the three breeds inside every query interval.

Easy3Prefix sumArrayInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Farmer John's NN cows, numbered 11 through NN, stand in a row. Each cow carries a breed ID: 1 for Holsteins, 2 for Guernseys, and 3 for Jerseys. Given an interval of the row, count how many cows of each breed stand inside it.

Input

The first line contains NN and QQ (1N100,0001 \le N \le 100{,}000, 1Q100,0001 \le Q \le 100{,}000).

Each of the next NN lines contains an integer that is 1, 2, or 3. The number on line ii is the breed ID of the ii-th cow in the row.

Each of the next QQ lines contains two integers aa and bb describing one query (1abN1 \le a \le b \le N).

Output

For each query (a,b)(a, b), print three integers on one line, separated by spaces: the number of Holsteins (breed 1), Guernseys (breed 2), and Jerseys (breed 3) among cows aa through bb, in that order.