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 codeforce.practice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.Function;

import static java.lang.System.out;
import static java.util.stream.Collectors.joining;

/**
 * @author pribic (Priyank Doshi)
 * @since 12/05/21
 */
public class pDPowerfulArray {
  public static void main(String[] args) {
    try (FastReader fr = new FastReader()) {
      int T = 1;//sc.nextInt();
      for (int tt = 1; tt <= T; tt++) {
        int n = fr.nextInt();
        int q = fr.nextInt();
        int[] nums = fr.nextIntArray(n);
        List<Query> queries = readQueries(fr, q);
        //out.println("Queries before sort " + Arrays.toString(queries));
        int blockSize = (int) Math.ceil(Math.sqrt(n));
        Collections.sort(queries, new QueryComparator(blockSize));
        //out.println("Queries after sort " + Arrays.toString(queries));
        long[] ans = processQueries(nums, queries);
        out.println(printArray(ans));
      }
    }
  }

  private static long[] processQueries(int[] nums, List<Query> queries) {
    int q = queries.size();
    int l = 0;
    int r = 0;
    int queryIdx = 0;
    int[] frequency = new int[1000000 + 5];
    frequency[nums[0]] = 1;
    long rangeAns = nums[0];
    long[] ans = new long[q];
    Function<Integer, Long> calcAns = num -> (long) frequency[num] * frequency[num] * num;
    while (q-- > 0) {
      Query query = queries.get(queryIdx++);
      //bring l and r to query.l and query.r
      while (l > query.l) { //expland left
        l--;
        rangeAns -= (long) frequency[nums[l]] * frequency[nums[l]] * nums[l];
        frequency[nums[l]]++;
        rangeAns += (long) frequency[nums[l]] * frequency[nums[l]] * nums[l];
      }
      while (r < query.r) { //expland right
        r++;
        rangeAns -= (long) frequency[nums[r]] * frequency[nums[r]] * nums[r];
        frequency[nums[r]]++;
        rangeAns += (long) frequency[nums[r]] * frequency[nums[r]] * nums[r];
      }
      while (l < query.l) {//shrink left
        rangeAns -= (long) frequency[nums[l]] * frequency[nums[l]] * nums[l];
        frequency[nums[l]]--;
        rangeAns += (long) frequency[nums[l]] * frequency[nums[l]] * nums[l];
        l++;
      }
      while (r > query.r) {//shrink right
        rangeAns -= (long) frequency[nums[r]] * frequency[nums[r]] * nums[r];
        frequency[nums[r]]--;
        rangeAns += (long) frequency[nums[r]] * frequency[nums[r]] * nums[r];
        r--;
      }
      ans[query.idx] = rangeAns;

    }
    return ans;
  }

  private static StringBuilder printArray(long[] ans) {
    StringBuilder sb = new StringBuilder();
    for (long num : ans)
      sb.append(num).append("\n");
    return sb;
  }

  private static List<Query> readQueries(FastReader sc, int q) {
    List<Query> queries = new ArrayList<>(q);
    int idx = 0;
    while (q-- > 0) {
      String str = sc.nextLine();
      queries.add(new Query(Integer.parseInt(str.split("\\s+")[0]) - 1, Integer.parseInt(str.split("\\s+")[1]) - 1, idx));
      idx++;
    }
    return queries;
  }

  static class Query {
    final int l, r, idx;

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

    @Override
    public String toString() {
      return new StringJoiner(", ", Query.class.getSimpleName() + "[", "]")
        .add("l=" + l)
        .add("r=" + r)
        .toString();
    }
  }

  static class QueryComparator implements Comparator<Query> {
    private int blockSize;

    public QueryComparator(int blockSize) {
      this.blockSize = blockSize;
    }

    @Override
    public int compare(Query q1, Query q2) {
      int b1 = q1.l / blockSize;
      int b2 = q2.l / blockSize;
      if (b1 != b2)
        return Integer.compare(b1, b2);
      return b1 % 2 == 1 ? Integer.compare(q1.r, q2.r) : Integer.compare(q2.r, q1.r);
    }
  }

  static class FastReader implements AutoCloseable {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new
        InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

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

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    public int[] nextIntArray(int n) {
      String[] str = nextLine().split("\\s+");
      int[] arr = new int[n];
      for (int i = 0; i < n; i++) {
        arr[i] = Integer.parseInt(str[i]);
      }
      return arr;
    }

    @Override
    public void close() {
      try {
        br.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
}