9 10
6 2 3 1 4 8 5 9 8
3 9
6 6
9 9
9 9
9 9
2 3
3 9
3 8
6 9
5 6
 10 10
5 10 9 2 9 3 5 5 6 5
5 10
2 2
3 10
4 8
1 3
1 5
5 5
10 10
8 9
6 10
 8 10
100 100 100 100 100 100 100 100
1 8
2 8
3 8
4 8
5 8
6 8
7 8
8 8
1 1
1 5
 5 15
103 45 103 67 45
1 1
1 2
1 3
1 4
1 5
2 2
2 3
2 4
2 5
3 3
3 4
3 5
4 4
4 5
5 5
 1 1
1000000
1 1
 10 5
10 9 8 7 6 5 4 3 2 1
4 8
1 10
3 9
2 2
5 10
 9 10
5 3 10 2 4 8 7 5 1
6 9
1 8
3 3
2 7
3 5
4 6
9 9
8 8
1 9
5 6
 9 10
10 2 6 2 4 6 6 4 1
4 8
8 9
2 3
8 9
9 9
4 5
1 7
6 6
6 8
1 1
 20 8
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2
4 15
1 2
2 20
7 7
13 18
7 7
3 19
3 8
 1 2
1
1 1
1 1
 8 10
5 7 3 1 4 2 1 1
5 7
3 8
2 7
4 8
4 5
2 8
4 6
1 2
4 7
3 5

54
8
8
8
8
5
54
30
46
12
 63
10
92
34
24
53
9
5
11
54
 6400
4900
3600
2500
1600
900
400
100
100
2500
 103
148
457
524
659
45
148
215
350
103
170
215
67
112
45
 1000000
 25
55
35
9
21
 21
54
10
34
16
14
1
5
55
12
 42
5
8
5
1
6
76
6
28
10
 108
3
281
1
27
1
209
27
 1
1
 7
18
20
15
5
25
7
12
10
8

import com.sun.org.apache.bcel.internal.generic.FieldGen;

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    class GraphBuilder {
        int n, m;
        int[] x, y;
        int index;
        int[] size;


        GraphBuilder(int n, int m) {
            this.n = n;
            this.m = m;
            x = new int[m];
            y = new int[m];
            size = new int[n];
        }

        void add(int u, int v) {
            x[index] = u;
            y[index] = v;
            size[u]++;
            size[v]++;
            index++;
        }

        int[][] build() {
            int[][] graph = new int[n][];
            for (int i = 0; i < n; i++) {
                graph[i] = new int[size[i]];
            }
            for (int i = index - 1; i >= 0; i--) {
                int u = x[i];
                int v = y[i];
                graph[u][--size[u]] = v;
                graph[v][--size[v]] = u;
            }
            return graph;
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readLongArray(int size) throws IOException {
        long[] res = new long[size];
        for (int i = 0; i < size; i++) {
            res[i] = readLong();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
        // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    int gcd(int x, int y) {
        if (x == 0) return y;
        return gcd(y % x, x);
    }

    int[] indexes;

    Random random = new Random();

    void shuffle() {
        for (int i = 1; i < indexes.length; i++) {
            int prev = random.nextInt(i);
            int t = indexes[i];
            indexes[i] = indexes[prev];
            indexes[prev] = t;
        }
    }

    class Query {
        int l, r, index;

        public Query(int l, int r, int index) {
            this.l = l;
            this.r = r;
            this.index = index;
        }
    }

    int MAX_A = 1000000;

    int[] count = new int[MAX_A + 1];
    long[] answer;

    void process(List<Query> queries, int[] a) {
        if (queries.size() == 0) return;
        queries.sort(Comparator.comparingInt(o -> o.r));
        long result = 0;
        for (int i = queries.get(0).l; i <= queries.get(0).r; i++) {
            count[a[i]]++;
            result += get(count[a[i]]) * a[i];
        }
        answer[queries.get(0).index] = result;
        for (int qi = 1; qi < queries.size(); qi++) {
            Query now = queries.get(qi);
            Query prev = queries.get(qi - 1);
            for (int i = prev.r + 1; i <= now.r; i++) {
                count[a[i]]++;
                result += get(count[a[i]]) * a[i];
            }
            if (now.l != prev.l) {
                if (now.l < prev.l) {
                    for (int i = now.l; i < prev.l; i++) {
                        count[a[i]]++;
                        result += get(count[a[i]]) * a[i];
                    }
                } else {
                    for (int i = prev.l; i < now.l; i++) {
                        result -= get(count[a[i]]) * a[i];
                        count[a[i]]--;
                    }
                }
            }
            answer[now.index] = result;
        }
        Query last = queries.get(queries.size() - 1);
        for (int i=last.l;i<=last.r;i++) {
            count[a[i]]--;
        }
    }

    long[] sqrs;

    {
        sqrs = new long[200000 + 5];
        for (int i = 1; i < sqrs.length; i++) {
            sqrs[i] = (long) i * i;
        }
    }

    long get(int x) {
        return sqrs[x] - sqrs[x - 1];
    }

    void solve() throws IOException {
        int n = readInt();
        int t = readInt();
        answer = new long[t];
        int[] a = readIntArray(n);
        Query[] queries = new Query[t];
        for (int i = 0; i < t; i++) {
            queries[i] = new Query(readInt() - 1, readInt() - 1, i);
        }
        Arrays.sort(queries, Comparator.comparingInt(o -> o.l));
        int SQRT_STEP = 450;
        List<Query> chunk = new ArrayList<>();
        int cur = 0;

        for (Query q : queries) {
            if (q.l < cur) {
                chunk.add(q);
            } else {
                process(chunk, a);
                chunk.clear();

                while (q.l >= cur) {
                    cur += SQRT_STEP;
                }
                chunk.add(q);
            }
        }
        process(chunk, a);
        for (long x : answer) {
            out.println(x);
        }

    }

}