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

//package baobab;

import java.io.*;
import java.util.*;

public class D {

    public static void main(String[] args) {
        DIO io = new DIO();
        try {
            Dsolver solver = new Dsolver(io);
        } finally {
            io.close();
        }
    }

}

class Dsolver {

    public Dsolver(DIO io) {
        solve(io);
    }

    public String solve(DIO io) {
        int n = io.nextInt();
        int queries = io.nextInt();
        int[] a = new int[n];
        for (int i=0; i<n; i++) {
            a[i] = io.nextInt();
        }
        //Query.n = n;
        //Query.blocks = (int) Math.ceil(Math.sqrt(n));
        Query.s = (int) Math.sqrt(n);

        PriorityQueue<Query> keko = new PriorityQueue<>();
        for (int i=0; i<queries; i++) {
            int left = io.nextInt();
            int right = io.nextInt();
            keko.add(new Query(left, right, i));
        }
        long[] ans = new long[queries];
        //ElementCounter ec = new ElementCounter();
        int[] ec = new int[(int)1e6+1];
        int left = 0;
        int right = -1;
        long sum = 0L;
        for (int i=0; i<queries; i++) {
            Query query = keko.poll();
            while (left > query.l) {
                int numb = a[--left];
                sum += numb * (2 * ec[numb] + 1);
                ec[numb]++;
            }
            while (right < query.r) {
                int numb = a[++right];
                sum += numb * (2 * ec[numb] + 1);
                ec[numb]++;
            }
            while (left < query.l) {
                int numb = a[left++];
                ec[numb]--;
                sum -= numb * (2 * ec[numb] + 1);

            }
            while (right > query.r) {
                int numb = a[right--];
                ec[numb]--;
                sum -= numb * (2 * ec[numb] + 1);

            }
            ans[query.idx] = sum;
        }
        for (long row : ans) {
            io.println(row);
        }
        return "";
    }

    static class Query implements Comparable<Query>
    {
        static int s;
        int l, r, idx, block;

        Query(int x, int y, int z)
        {
            l = x-1;
            r = y-1;
            idx = z;
            block = l / s;
        }

        public int compareTo(Query q)
        {
            if(block != q.block)
                return block - q.block;
            return r - q.r;
        }
    }
}

class Queryxx implements Comparable<Queryxx> {
    int a;
    int b;
    int i;
    int ofBlock;
    static int n;
    static int blocks;

    public Queryxx(int a, int b, int i) {
        this.a = a - 1;
        this.b = b - 1;
        this.i = i;
        this.ofBlock = (int) (((1.0 * a) / n) * blocks);
    }

    @Override
    public int compareTo(Queryxx other) {
        if (this.ofBlock < other.ofBlock) return -1;
        if (this.ofBlock > other.ofBlock) return 1;
        return this.b - other.b;
    }

    @Override
    public String toString() {
        return "Query{" +
                "a=" + a +
                ", b=" + b +
                ", i=" + i +
                '}';
    }
}

class ElementCounter {
    private HashMap<Long, Long> elements;

    public ElementCounter() {
        elements = new HashMap<>();
    }

    public void add(long element) {
        long count = 1;
        if (elements.containsKey(element)) count += elements.get(element);
        elements.put(element, count);
    }

    public void remove(long element) {
        long count = elements.get(element);
        count--;
        if (count == 0) elements.remove(element);
        else elements.put(element, count);
    }

    public long get(long element) {
        if (!elements.containsKey(element)) return 0;
        return elements.get(element);
    }

    public int size() {
        return elements.size();
    }
}

class DIO extends PrintWriter {
    private InputStreamReader r;
    private static final int BUFSIZE = 1 << 15;
    private char[] buf;
    private int bufc;
    private int bufi;
    private StringBuilder sb;

    public DIO() {
        super(new BufferedOutputStream(System.out));
        r = new InputStreamReader(System.in);

        buf = new char[BUFSIZE];
        bufc = 0;
        bufi = 0;
        sb = new StringBuilder();
    }

    private void fillBuf() throws IOException {
        bufi = 0;
        bufc = 0;
        while(bufc == 0) {
            bufc = r.read(buf, 0, BUFSIZE);
            if(bufc == -1) {
                bufc = 0;
                return;
            }
        }
    }

    private boolean pumpBuf() throws IOException {
        if(bufi == bufc) {
            fillBuf();
        }
        return bufc != 0;
    }

    private boolean isDelimiter(char c) {
        return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
    }

    private void eatDelimiters() throws IOException {
        while(true) {
            if(bufi == bufc) {
                fillBuf();
                if(bufc == 0) throw new RuntimeException("IO: Out of input.");
            }

            if(!isDelimiter(buf[bufi])) break;
            ++bufi;
        }
    }

    public String next() {
        try {
            sb.setLength(0);

            eatDelimiters();
            int start = bufi;

            while(true) {
                if(bufi == bufc) {
                    sb.append(buf, start, bufi - start);
                    fillBuf();
                    start = 0;
                    if(bufc == 0) break;
                }

                if(isDelimiter(buf[bufi])) break;
                ++bufi;
            }

            sb.append(buf, start, bufi - start);

            return sb.toString();
        } catch(IOException e) {
            throw new RuntimeException("IO.next: Caught IOException.");
        }
    }

    public int nextInt() {
        try {
            int ret = 0;

            eatDelimiters();

            boolean positive = true;
            if(buf[bufi] == '-') {
                ++bufi;
                if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                positive = false;
            }

            boolean first = true;
            while(true) {
                if(!pumpBuf()) break;
                if(isDelimiter(buf[bufi])) {
                    if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                    break;
                }
                first = false;

                if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                    if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                    ret *= 10;
                    ret -= (int)(buf[bufi] - '0');
                    if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                } else {
                    throw new RuntimeException("IO.nextInt: Invalid int.");
                }

                ++bufi;
            }

            if(positive) {
                if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                ret = -ret;
            }

            return ret;
        } catch(IOException e) {
            throw new RuntimeException("IO.nextInt: Caught IOException.");
        }
    }

    public long nextLong() {
        try {
            long ret = 0;

            eatDelimiters();

            boolean positive = true;
            if(buf[bufi] == '-') {
                ++bufi;
                if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                positive = false;
            }

            boolean first = true;
            while(true) {
                if(!pumpBuf()) break;
                if(isDelimiter(buf[bufi])) {
                    if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                    break;
                }
                first = false;

                if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                    if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                    ret *= 10;
                    ret -= (long)(buf[bufi] - '0');
                    if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                } else {
                    throw new RuntimeException("IO.nextLong: Invalid long.");
                }

                ++bufi;
            }

            if(positive) {
                if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                ret = -ret;
            }

            return ret;
        } catch(IOException e) {
            throw new RuntimeException("IO.nextLong: Caught IOException.");
        }
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}