import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;

public class C {
	static int n, nums[];

	static boolean valid(int pos) {
		if (pos % 2 == 0) {
			if (pos < n && nums[pos] <= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] >= nums[pos])
				return false;
		} else {
			if (pos < n && nums[pos] >= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] <= nums[pos])
				return false;
		}
		return true;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(bf.readLine());
		String l[] = bf.readLine().split(" ");
		nums = new int[n + 1];
		for (int i = 0; i < n; i++) {
			nums[i + 1] = Integer.parseInt(l[i]);
		}
		int x = 0;
		int pos[] = new int[3];
		for (int i = 1; i < nums.length - 1; i++) {
			if (i % 2 == 0) {
				if (nums[i] <= nums[i + 1]) {
					if (x == 3) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			} else {
				if (nums[i] >= nums[i + 1]) {
					if (x == 2) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			}
		}
		int ans = 0;
		if (x == 1) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
			pos[0]++;
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[0] - 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
		} else if (x == 2) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[1], i);
				if (valid(i) && valid(pos[1])) {
					if (valid(pos[0]))
						ans++;
				}
				swap(pos[1], i);
			}
			if (pos[0] + 1 != pos[1]) {
				pos[1]++;
				for (int i = 1; i < nums.length; i++) {
					if (i == pos[1] - 1)
						continue;
					swap(pos[1], i);
					if (valid(i) && valid(pos[1])) {
						if (valid(pos[0]))
							ans++;
					}
					swap(pos[1], i);
				}
				pos[1]--;
			}
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[1] || i == pos[1] + 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0])) {
					if (valid(pos[1]))
						ans++;
				}
				swap(pos[0], i);
			}
			if (pos[0] + 1 != pos[1]) {
				pos[0]++;
				for (int i = 1; i < nums.length; i++) {
					if (i == pos[1] || i == pos[1] + 1 || i == pos[0] - 1)
						continue;
					swap(pos[0], i);
					if (valid(i) && valid(pos[0])) {
						if (valid(pos[1]))
							ans++;
					}
					swap(pos[0], i);
				}
			}
		} else {
			swap(pos[0], pos[1]);
			if (valid(pos[0]) && valid(pos[1]) && valid(pos[2]))
				ans++;
			swap(pos[0], pos[1]);
			swap(pos[1], pos[2]);
			if (valid(pos[0]) && valid(pos[1]) && valid(pos[2]))
				ans++;
			swap(pos[1], pos[2]);
			swap(pos[0], pos[2]);
			if (valid(pos[0]) && valid(pos[1]) && valid(pos[2]))
				ans++;
			swap(pos[0], pos[2]);
			for (int i = 0; i < pos.length; i++) {
				for (int k = i + 1; k < pos.length; k++) {
					swap(pos[i], pos[k]);
					if (valid(pos))
						ans++;
					swap(pos[i], pos[k]);

					swap(pos[i] + 1, pos[k]);
					if (valid(pos))
						ans++;
					swap(pos[i] + 1, pos[k]);

					swap(pos[i] + 1, pos[k] + 1);
					if (valid(pos))
						ans++;
					swap(pos[i] + 1, pos[k] + 1);

					swap(pos[i], pos[k] + 1);
					if (valid(pos))
						ans++;
					swap(pos[i], pos[k] + 1);

				}
			}

		}
		System.out.println(ans);
	}

	private static boolean valid(int[] pos) {
		if (valid(pos[0] + 1) && valid(pos[1] + 1) && valid(pos[2] + 1))
			return valid(pos[0]) && valid(pos[1]) && valid(pos[2]);
		return false;
	}

	private static void swap(int i, int i2) {
		int tmp = nums[i];
		nums[i] = nums[i2];
		nums[i2] = tmp;
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;

public class C {
	static int n, nums[];

	static boolean valid(int pos) {
		if (pos > n)
			return true;
		if (pos % 2 == 0) {
			if (pos < n && nums[pos] <= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] >= nums[pos])
				return false;
		} else {
			if (pos < n && nums[pos] >= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] <= nums[pos])
				return false;
		}
		return true;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(bf.readLine());
		String l[] = bf.readLine().split(" ");
		nums = new int[n + 1];
		for (int i = 0; i < n; i++) {
			nums[i + 1] = Integer.parseInt(l[i]);
		}
		int x = 0;
		int pos[] = new int[4];
		for (int i = 1; i < nums.length - 1; i++) {
			if (i % 2 == 0) {
				if (nums[i] <= nums[i + 1]) {
					if (x >= 4) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			} else {
				if (nums[i] >= nums[i + 1]) {
					if (x >= 4) {

						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			}
		}
		int ans = 0;
		if (x == 1) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
			pos[0]++;
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[0] - 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
		} else if (x == 2) {
			HashSet<String> res = new HashSet<String>();

			for (int i = 1; i < nums.length; i++) {
				for (int j = 0; j < 2; j++) {
					swap(pos[j], i);
					pos[2] = i;
					if (valid(pos)) {
						add(i, pos[j], res);
					}
					swap(pos[j], i);
					swap(pos[j] + 1, i);
					pos[2] = i;
					if (valid(pos)) {
						add(i, pos[j] + 1, res);
					}
					swap(pos[j] + 1, i);
				}
			}
			ans = res.size();
		} else {
			HashSet<String> res = new HashSet<String>();
			for (int i = 0; i < pos.length; i++) {
				for (int k = 0; k < x; k++) {
					swap(pos[i], pos[k]);
					if (valid(pos)) {
						add(pos[i], pos[k], res);
					}
					swap(pos[i], pos[k]);

					swap(pos[i] + 1, pos[k]);
					if (valid(pos)) {
						add(pos[i] + 1, pos[k], res);

					}
					swap(pos[i] + 1, pos[k]);

					swap(pos[i] + 1, pos[k] + 1);
					if (valid(pos)) {
						add(pos[i] + 1, pos[k] + 1, res);

					}
					swap(pos[i] + 1, pos[k] + 1);

					swap(pos[i], pos[k] + 1);
					if (valid(pos)) {
						add(pos[i], pos[k] + 1, res);
					}
					swap(pos[i], pos[k] + 1);

				}
			}
			ans = res.size();
		}
		System.out.println(ans);
	}

	private static void add(int i, int j, HashSet<String> res) {
		if (i > j) {
			int tmp = i;
			i = j;
			j = tmp;
		}
		res.add(i + " " + j);

	}

	private static boolean valid(int[] pos) {
		if (valid(pos[0] + 1) && valid(pos[1] + 1) && valid(pos[2] + 1))
			return valid(pos[0]) && valid(pos[1]) && valid(pos[2]);
		return false;
	}

	private static void swap(int i, int i2) {
		int tmp = nums[i];
		nums[i] = nums[i2];
		nums[i2] = tmp;
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;

public class C {
	static int n, nums[];

	static boolean valid(int pos) {
		if (pos % 2 == 0) {
			if (pos < n && nums[pos] <= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] >= nums[pos])
				return false;
		} else {
			if (pos < n && nums[pos] >= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] <= nums[pos])
				return false;
		}
		return true;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(bf.readLine());
		String l[] = bf.readLine().split(" ");
		nums = new int[n + 1];
		for (int i = 0; i < n; i++) {
			nums[i + 1] = Integer.parseInt(l[i]);
		}
		int x = 0;
		int pos[] = new int[3];
		for (int i = 1; i < nums.length - 1; i++) {
			if (i % 2 == 0) {
				if (nums[i] <= nums[i + 1]) {
					if (x == 3) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			} else {
				if (nums[i] >= nums[i + 1]) {
					if (x == 2) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			}
		}
		int ans = 0;
		if (x == 1) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
			pos[0]++;
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[0] - 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
		} else if (x == 2) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[1], i);
				if (valid(i) && valid(pos[1])) {
					if (valid(pos[0]))
						ans++;
				}
				swap(pos[1], i);
			}
			if (pos[0] + 1 != pos[1]) {
				pos[1]++;
				for (int i = 1; i < nums.length; i++) {
					if (i == pos[1] - 1)
						continue;
					swap(pos[1], i);
					if (valid(i) && valid(pos[1])) {
						if (valid(pos[0]))
							ans++;
					}
					swap(pos[1], i);
				}
				pos[1]--;
			}
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[1] || i == pos[1] + 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0])) {
					if (valid(pos[1]))
						ans++;
				}
				swap(pos[0], i);
			}
			if (pos[0] + 1 != pos[1]) {
				pos[0]++;
				for (int i = 1; i < nums.length; i++) {
					if (i == pos[1] || i == pos[1] + 1 || i == pos[0] - 1)
						continue;
					swap(pos[0], i);
					if (valid(i) && valid(pos[0])) {
						if (valid(pos[1]))
							ans++;
					}
					swap(pos[0], i);
				}
			}
		} else {
			swap(pos[0], pos[1]);
			if (valid(pos[0]) && valid(pos[1]) && valid(pos[2]))
				ans++;
			swap(pos[0], pos[1]);
			swap(pos[1], pos[2]);
			if (valid(pos[0]) && valid(pos[1]) && valid(pos[2]))
				ans++;
			swap(pos[1], pos[2]);
			swap(pos[0], pos[2]);
			if (valid(pos[0]) && valid(pos[1]) && valid(pos[2]))
				ans++;
			swap(pos[0], pos[2]);

		}
		System.out.println(ans);
	}

	private static void swap(int i, int i2) {
		int tmp = nums[i];
		nums[i] = nums[i2];
		nums[i2] = tmp;
	}

}


"""
Author    : co_devil Chirag Garg
Institute : JIIT
"""

from __future__ import division, print_function
from sys import stdin,stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__
    str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
            self.newlines += b.count(b'\n') + (not b)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')

def print(*args, **kwargs):
    sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop('end', b'\n'))
    if kwargs.pop('flush', False):
        file.flush()

"""

def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())

def fii(): return int(stdin.readline())
def fsi(): return str(stdin.readline())
def fmi(): return map(int,stdin.readline().split())
def fli(): return list(fmi())

abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
       'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
       'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
    res = 1
    x %= p
    while y > 0:
        if y & 1:
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')

graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
    if visited[v]:
        if col[v] != c:
            print('-1')
            exit()
        return
    col[v] = c
    visited[v] = 1
    for i in graph[v]:
        dfs(i, c ^ 1)

def bfs(d,v):
    q=[]
    q.append(v)
    visited[v]=1
    while len(q)!=0:
        x=q[0]
        q.pop(0)
        for i in d[x]:
            if visited[i]!=1:
                visited[i]=1
                q.append(i)
        print(x)
    print(l)

def make_graph(e):
    d={}
    for i in range(e):
        x,y=mi()
        if x not in d.keys():
            d[x]=[y]
        else:
            d[x].append(y)
        if y not in d.keys():
            d[y] = [x]
        else:
            d[y].append(x)
    return d
def gr2(n):
    d={}
    for i in range(n):
        x,y=mi()
        if x not in d.keys():
            d[x]=[y]
        else:
            d[x].append(y)
    return d

def connected_components(graph):
    seen = set()
    def dfs(v):
        vs = set([v])
        component=[]
        while vs:
            v = vs.pop()
            seen.add(v)
            vs |= set(graph[v]) - seen
            component.append(v)
        return component
    ans=[]
    for v in graph:
        if v not in seen:
            d=dfs(v)
            ans.append(d)
    return ans

n=ii()
l=li()
a=[l[0]]
for i in range(1,n):
    a.append(l[i]+a[i-1])
q=ii()
for i in range(q):
    x,y=mi()
    if x==1:
        s=a[y-1]
    else:
        s=a[y-1]-a[x-2]
    print(s//10)


"""
Author    : co_devil Chirag Garg
Institute : JIIT
"""

from __future__ import division, print_function
from sys import stdin,stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__
    str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
            self.newlines += b.count(b'\n') + (not b)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')

def print(*args, **kwargs):
    sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop('end', b'\n'))
    if kwargs.pop('flush', False):
        file.flush()

"""

def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())

def fii(): return int(stdin.readline())
def fsi(): return str(stdin.readline())
def fmi(): return map(int,stdin.readline().split())
def fli(): return list(fmi())

abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
       'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
       'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
    res = 1
    x %= p
    while y > 0:
        if y & 1:
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')

graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
    if visited[v]:
        if col[v] != c:
            print('-1')
            exit()
        return
    col[v] = c
    visited[v] = 1
    for i in graph[v]:
        dfs(i, c ^ 1)

def bfs(d,v):
    q=[]
    q.append(v)
    visited[v]=1
    while len(q)!=0:
        x=q[0]
        q.pop(0)
        for i in d[x]:
            if visited[i]!=1:
                visited[i]=1
                q.append(i)
        print(x)
    print(l)

def make_graph(e):
    d={}
    for i in range(e):
        x,y=mi()
        if x not in d.keys():
            d[x]=[y]
        else:
            d[x].append(y)
        if y not in d.keys():
            d[y] = [x]
        else:
            d[y].append(x)
    return d
def gr2(n):
    d={}
    for i in range(n):
        x,y=mi()
        if x not in d.keys():
            d[x]=[y]
        else:
            d[x].append(y)
    return d

def connected_components(graph):
    seen = set()
    def dfs(v):
        vs = set([v])
        component=[]
        while vs:
            v = vs.pop()
            seen.add(v)
            vs |= set(graph[v]) - seen
            component.append(v)
        return component
    ans=[]
    for v in graph:
        if v not in seen:
            d=dfs(v)
            ans.append(d)
    return ans

n=ii()
l=li()
a=[l[0]]
for i in range(1,n):
    a.append(l[i]+a[i-1])
q=ii()
for i in range(q):
    x,y=mi()
    if x==1:
        s=a[y-1]
    else:
        s=a[y-1]-a[x-1]
    print(s//10)


"""
Author    : co_devil Chirag Garg
Institute : JIIT
"""

from __future__ import division, print_function
from sys import stdin,stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__
    str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
            self.newlines += b.count(b'\n') + (not b)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')

def print(*args, **kwargs):
    sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop('end', b'\n'))
    if kwargs.pop('flush', False):
        file.flush()

"""

def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())

def fii(): return int(stdin.readline())
def fsi(): return str(stdin.readline())
def fmi(): return map(int,stdin.readline().split())
def fli(): return list(fmi())

abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
       'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
       'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
    res = 1
    x %= p
    while y > 0:
        if y & 1:
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')

graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
    if visited[v]:
        if col[v] != c:
            print('-1')
            exit()
        return
    col[v] = c
    visited[v] = 1
    for i in graph[v]:
        dfs(i, c ^ 1)

def bfs(d,v):
    q=[]
    q.append(v)
    visited[v]=1
    while len(q)!=0:
        x=q[0]
        q.pop(0)
        for i in d[x]:
            if visited[i]!=1:
                visited[i]=1
                q.append(i)
        print(x)
    print(l)

def make_graph(e):
    d={}
    for i in range(e):
        x,y=mi()
        if x not in d.keys():
            d[x]=[y]
        else:
            d[x].append(y)
        if y not in d.keys():
            d[y] = [x]
        else:
            d[y].append(x)
    return d
def gr2(n):
    d={}
    for i in range(n):
        x,y=mi()
        if x not in d.keys():
            d[x]=[y]
        else:
            d[x].append(y)
    return d

def connected_components(graph):
    seen = set()
    def dfs(v):
        vs = set([v])
        component=[]
        while vs:
            v = vs.pop()
            seen.add(v)
            vs |= set(graph[v]) - seen
            component.append(v)
        return component
    ans=[]
    for v in graph:
        if v not in seen:
            d=dfs(v)
            ans.append(d)
    return ans

n=ii()
l=li()
a=[l[0]]
for i in range(1,n):
    a.append(l[i]+a[i-1])
q=ii()
for i in range(q):
    x,y=mi()
    if x==1:
        s=a[y-1]
    elif x==y:
        s=a[y-1]-a[y-2]
    else:
        s=a[y-1]-a[x-1]
    print(s//10)


"""
Author    : co_devil Chirag Garg
Institute : JIIT
"""

from __future__ import division, print_function
from sys import stdin,stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__
    str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
            self.newlines += b.count(b'\n') + (not b)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')

def print(*args, **kwargs):
    sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop('end', b'\n'))
    if kwargs.pop('flush', False):
        file.flush()

"""

def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())

def fii(): return int(stdin.readline())
def fsi(): return str(stdin.readline())
def fmi(): return map(int,stdin.readline().split())
def fli(): return list(fmi())

abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
       'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
       'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
    res = 1
    x %= p
    while y > 0:
        if y & 1:
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')

graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
    if visited[v]:
        if col[v] != c:
            print('-1')
            exit()
        return
    col[v] = c
    visited[v] = 1
    for i in graph[v]:
        dfs(i, c ^ 1)

def bfs(d,v):
    q=[]
    q.append(v)
    visited[v]=1
    while len(q)!=0:
        x=q[0]
        q.pop(0)
        for i in d[x]:
            if visited[i]!=1:
                visited[i]=1
                q.append(i)
        print(x)
    print(l)

def make_graph(e):
    d={}
    for i in range(e):
        x,y=mi()
        if x not in d.keys():
            d[x]=[y]
        else:
            d[x].append(y)
        if y not in d.keys():
            d[y] = [x]
        else:
            d[y].append(x)
    return d
def gr2(n):
    d={}
    for i in range(n):
        x,y=mi()
        if x not in d.keys():
            d[x]=[y]
        else:
            d[x].append(y)
    return d

def connected_components(graph):
    seen = set()
    def dfs(v):
        vs = set([v])
        component=[]
        while vs:
            v = vs.pop()
            seen.add(v)
            vs |= set(graph[v]) - seen
            component.append(v)
        return component
    ans=[]
    for v in graph:
        if v not in seen:
            d=dfs(v)
            ans.append(d)
    return ans

n=ii()
l=li()
a=[l[0]]
for i in range(1,n):
    a.append(l[i]+a[i-1])
q=ii()
print(a)
for i in range(q):
    x,y=mi()
    if x==1:
        s=a[y-1]
    elif x==y:
        s=a[y-1]-a[y-2]
    else:
        s=a[y-1]-a[x-1]
    print(s//10)


import sys

# def recur(pre,p,pos,maxx,temp):
#     if pos == len(pre):
#         maxx[0] = max(maxx[0],temp)
#         return

#     for i in range(0,p+1):
#         if i < len(pre[pos]) :
#             temp = temp + pre[pos][i]
#             recur(pre,p-i,pos+1,maxx,temp)
#             temp = temp - pre[pos][i]

RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

# for _ in range(int(ri())):
def query(seg,ss,se,qs,qe,pos):
    if qs <= ss and qe >= se:
        return seg[pos]
    if qs > se or qe < ss:
        return [0,0]
    mid= (ss+se)//2
    left = query(seg,ss,mid,qs,qe,2*pos+1)
    right = query(seg,mid+1,se,qs,qe,2*pos+2)
    # print(left,right)
    return [(left[0]+right[0])%10,left[1]+right[1] + (1 if (left[0]+right[0]) >= 10 else 0)]

def build(seg,pos,a,s,e):
    if s == e:
        seg[pos][0] = a[s]
        seg[pos][1] = 0
        return
    mid= (s+e)//2
    build(seg,2*pos+1,a,s,mid)
    build(seg,2*pos+2,a,mid+1,e)
    seg[pos][1] = seg[2*pos+1][1] + seg[2*pos+2][1]
    num1 = seg[2*pos+1][0]
    num2 = seg[2*pos+2][0]
    if (num1+num2)>=10:
        seg[pos][1]+=1
    seg[pos][0]  = (num1+num2)%10

n = int(ri())
a = RI()
seg = [[0,0] for i in range(0,4*n+1)]

build(seg,0,a,0,n-1)
# print(seg)
q = int(ri())
for _ in range(q):
    l,r  = RI()
    l-=1
    r-=1
    res = query(seg,0,n-1,l,r,0)
    print(res[1])


import sys

# def recur(pre,p,pos,maxx,temp):
#     if pos == len(pre):
#         maxx[0] = max(maxx[0],temp)
#         return

#     for i in range(0,p+1):
#         if i < len(pre[pos]) :
#             temp = temp + pre[pos][i]
#             recur(pre,p-i,pos+1,maxx,temp)
#             temp = temp - pre[pos][i]

RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

# for _ in range(int(ri())):
def query(seg,ss,se,qs,qe,pos):
    if qs <= ss and qe >= se:
        return seg[pos]
    if qs > se or qe < ss:
        return [0,0]
    mid= (ss+se)//2
    left = query(seg,ss,mid,qs,qe,2*pos+1)
    right = query(seg,mid+1,se,qs,qe,2*pos+2)
    # print(left,right)
    return [(left[0]+right[0])%10,left[1]+right[1] + (1 if (left[0]+right[0]) > 10 else 0)]

def build(seg,pos,a,s,e):
    if s == e:
        seg[pos][0] = a[s]
        seg[pos][1] = 0
        return
    mid= (s+e)//2
    build(seg,2*pos+1,a,s,mid)
    build(seg,2*pos+2,a,mid+1,e)
    seg[pos][1] = seg[2*pos+1][1] + seg[2*pos+2][1]
    num1 = seg[2*pos+1][0]
    num2 = seg[2*pos+2][0]
    if (num1+num2)>=10:
        seg[pos][1]+=1
    seg[pos][0]  = (num1+num2)%10

n = int(ri())
a = RI()
seg = [[0,0] for i in range(0,4*n+1)]

build(seg,0,a,0,n-1)
# print(seg)
q = int(ri())
for _ in range(q):
    l,r  = RI()
    l-=1
    r-=1
    res = query(seg,0,n-1,l,r,0)
    print(res[1])


# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 28/04/2020

from sys import stdin,stdout
from math import gcd, ceil, sqrt
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

n = ii1()
arr = iia()
pre = [0]
for i in arr:
    pre.append(pre[-1] + i)
q = ii1()
for i in range(q):
    l, r = iia()
    print((pre[r] - pre[l - 1]) // 10)


N = int(input())
s = [int(i) for i in input().split()]
for i in range(1,N):
    s[i] = s[i-1]+s[i]
q = int(input())
for i in range(q):
    l,r = input().split()
    l = int(l)
    r = int(r)
    if l == 1:
        print(s[r-1]//10)
    else:
        print((s[r-1]-s[l-2])//10)


N = int(input())
s = [int(i) for i in input().split()]
q = int(input())
for i in range(q):
    l,r = input().split()
    l = int(l)
    r = int(r)
    sum = 0
    for k in range(l-1,r):
        sum += s[k]
    print(sum//10)


N = int(input())
s = [int(i) for i in input().split()]
q = int(input())
for i in range(q):
    l,r = input().split()
    l = int(l)
    r = int(r)
    sum = 0
    count = 0
    for k in range(l-1,r):
        sum += s[k]
        if sum >= 10:
            sum -= 10
            count += 1
    print(count)


N = int(input())
s = [int(i) for i in input().split()]
for i in range(1,N):
    s[i] = s[i-1]+s[i]
q = int(input())
for i in range(q):
    l,r = input().split()
    l = int(l)
    r = int(r)
    print((s[r-1]-s[l-1])//10)


n=int(input())
s=list(map(int,input().split()))
for q in range(int(input())):
    l,r=map(int,input().split())
    print(sum(s[l-1:r])//10)


n=int(input())
s=list(map(int,input().split()))
su=0
a=[]
for i in range(n):
    su+=s[i]
    a.append(su)
for q in range(int(input())):
    l,r=map(int,input().split())
    if(l==1):
        print(a[r-1]//10)
    else:
        print((a[r-1]-a[l-2])//10)


n=int(input())
s=list(map(int,input().split()))
su=0
a=[]
for i in range(n):
    su+=s[i]
    a.append(su)
for q in range(int(input())):
    l,r=map(int,input().split())
    print((a[r-1]-a[l-1])//10)


n=int(input())
a=list(map(int,input().split()))
ps=[]
sum=0
for i in range(0,n):
    sum+=a[i]
    ps.append(sum)
q=int(input())
while(q>0):
    l,r=map(int,input().split())
    sum=0
    if(l==1):
        sum=ps[r-1]
    else:
        sum=ps[r-1]-ps[l-2]
    print(int(sum/10))
    q-=1


n=int(input())
a=list(map(int,input().split()))
q=int(input())
while(q>0):
    l,r=map(int,input().split())
    sum=0
    for i in range(l,r+1):
        sum+=a[i-1]
    print(int(sum/10))
    q-=1


n=int(input())
a=list(map(int,input().split()))
ps=[]
sum=0
for i in range(0,n):
    sum+=a[i]
    ps.append(sum)
q=int(input())
while(q>0):
    l,r=map(int,input().split())
    sum=ps[r-1]-ps[l-1]
    print(int(sum/10))
    q-=1


n=int(input())
a=list(map(int,input().split()))
ps=[]
sum=0
for i in range(0,n):
    sum+=a[i]
    ps.append(sum)
q=int(input())
while(q>0):
    l,r=map(int,input().split())
    sum=0
    if(l==1):
        sum=ps[r-1]
    else:
        sum=ps[r-1]-ps[l-1]
    print(int(sum/10))
    q-=1


n = int(input())

arr = list(map(int, input().split()))
p=[0]*(n+1)
p[1]=arr[0]

for i in range(2,n+1):
    p[i]=p[i-1]+arr[i-1]
#print(p)
for _ in range(int(input())):

    l,r=map(int, input().split())
    print((p[r]-p[l-1])//10)


n = int(input())
a = list(map(int,input().split())) + [ 0 for i in range(131072) ]

get = [ 0 for i in range(262144) ]
res = [ 0 for i in range(262144) ]
def Build(l,r,pos):
	if l == r:
		get[pos] = 0
		res[pos] = a[l]
		return
	Build(l,l+r>>1,pos<<1)
	Build((l+r>>1)+1,r,pos<<1|1)
	get[pos] = get[pos<<1] + get[pos<<1|1] + (res[pos<<1]+res[pos<<1|1])//10
	res[pos] = (res[pos<<1]+res[pos<<1|1]) % 10
def Query(gl,gr,l,r,pos):
	if gl <= l and r <= gr:
		return (get[pos],res[pos])
	mid = l+r >> 1
	if gr <= mid: return Query(gl,gr,l,mid,pos<<1)
	if gl > mid: return Query(gl,gr,mid+1,r,pos<<1|1)
	(lget,lres) = Query(gl,gr,l,mid,pos<<1)
	(rget,rres) = Query(gl,gr,mid+1,r,pos<<1|1)
	return (lget+rget+(lres+rres)//10,(lres+rres)%10)

Build(0,131071,1)

q = int(input())
for i in range(q):
	l,r = map(int,input().split())
	print(Query(l-1,r-1,0,131071,1)[0])


n = int(input())
a = list(map(int,input().split())) + [ 0 for i in range(131072) ]

get = [ 0 for i in range(262144) ]
res = [ 0 for i in range(262144) ]
def Build(l,r,pos):
	if l == r:
		get[pos] = 0
		res[pos] = a[l]
		return
	Build(l,l+r>>1,pos<<1)
	Build((l+r>>1)+1,r,pos<<1|1)
	get[pos] = get[pos<<1] + get[pos<<1|1] + (res[pos<<1]+res[pos<<1|1])//10
	res[pos] = (res[pos<<1]+res[pos<<1|1]) % 10
def Query(gl,gr,l,r,pos):
	if gl <= l and r <= gr:
		return (get[pos],res[pos])
	mid = l+r >> 1
	if gr <= mid: return Query(gl,gr,l,mid,pos<<1)
	if gl > mid: return Query(gl,gr,mid+1,r,pos<<1|1)
	(lget,lres) = Query(gl,gr,l,mid,pos<<1)
	(rget,rres) = Query(gl,gr,mid+1,r,pos<<1|1)
	return (lget+rget+(lres+rres)//10,(lres+rres)%10)

Build(0,131071,1)

q = int(input())
for i in range(q):
	l,r = map(int,input().split())
	print(Query(l,r,0,131071,1)[0])


n=int(input())
ar=list(map(int,input().split()))
s=[0]
for i in range(n):
	s.append(s[-1]+ar[i])

for i in range(int(input())):
	a,b=map(int,input().split())
	print((s[b]-s[a])//10)


n=int(input())
ar=list(map(int,input().split()))
s=[0]
for i in range(n):
	s.append(s[-1]+ar[i])

for i in range(int(input())):
	a,b=map(int,input().split())
	print((s[b]-s[a-1])//10)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
# print = stdout.write
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
x = 2
d = defaultdict(list)
for i in range(1, n+1):
    d[(i, i)] = (a[i-1], int(a[i-1] > 10))
p = 2
while(p<=n):
    p-=1
    for i in range(1, n+1):
        if i + p < n+1:
            s = i
            e = i+p
            m = (s+e)//2
            d[(s, e)] = ((d[(s, m)][0] + d[(m+1, e)][0])%10, d[(s, m)][1]+d[(m+1, e)][1]+int(d[(s, m)][0] + d[(m+1, e)][0]>=10))
        else:
            break
    p+=1
    p*=2
for _ in range(int(input())):
    print(d[tuple(map(int, input().split()))][1])


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
# print = stdout.write
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
z = [0]
for i in range(n):
    z.append(a[i]+z[-1])
for _ in range(int(input())):
    l, r = mapin()
    print((z[r] - z[l-1])//10)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
# print = stdout.write
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
x = 2
d = defaultdict(list)
for i in range(1, n+1):
    d[(i, i)] = [a[i-1], int(a[i-1] > 10)]
p = 2
while(p<=n):
    p-=1
    for i in range(1, n+1):
        if i + p < n+1:
            s = i
            e = i+p
            m = (s+e)//2
            d[(s, e)] = [(d[(s, m)][0] + d[(m+1, e)][0])%10, d[(s, m)][1]+d[(m+1, e)][1]+int(d[(s, m)][0] + d[(m+1, e)][0]>=10)]
        else:
            break
    p+=1
    p*=2
for _ in range(int(input())):
    print(d[tuple(map(int, input().split()))][1])


#Second try with the segment tree
import sys
input=sys.stdin.readline
n=int(input())
a=[int(x) for x in input().split()]
q=int(input())
seg=[[0,0] for i in range(4*n)]
def build(a,v,l,r,seg):
    if l==r:
        seg[v][0]=a[l]
    else:
        m=l+(r-l)//2
        build(a,2*v+1,l,m,seg)
        build(a,2*v+2,m+1,r,seg)
        seg[v][0]=(seg[2*v+1][0]+seg[2*v+2][0])%10
        seg[v][1]=seg[2*v+1][1]+seg[2*v+2][1]+(seg[2*v+1][0]+seg[2*v+2][0])//10
build(a,0,0,n-1,seg)
#print(seg)
def query(v,tl,tr,l,r,seg):
    if l<=tl and r>=tr:
        #print(v,l,r,seg[v])
        return seg[v]
    if tr<l or tl>r:
        return [0,0]

    tm=tl+(tr-tl)//2
    z1=query(v*2+1,tl,tm,l,r,seg)
    z2=query(2*v+2,tm+1,tr,l,r,seg)
    z3=[(z1[0]+z2[0])%10,\
    (z1[1]+z2[1])+(z1[0]+z2[0])//10]
    #print(z3)
    return z3
for i in range(q):
    l,r=map(int,input().split())
    print(query(0,0,n-1,l-1,r-1,seg)[1])


#Second try with the segment tree
n=int(input())
a=[int(x) for x in input().split()]
q=int(input())
seg=[[0,0] for i in range(4*n)]
def build(a,v,l,r,seg):
    if l==r:
        seg[v][0]=a[l]
    else:
        m=l+(r-l)//2
        build(a,2*v+1,l,m,seg)
        build(a,2*v+2,m+1,r,seg)
        seg[v][0]=(seg[2*v+1][0]+seg[2*v+2][0])%10
        seg[v][1]=seg[2*v+1][1]+seg[2*v+2][1]+(seg[2*v+1][0]+seg[2*v+2][0])//10
build(a,0,0,n-1,seg)
#print(seg)
def query(v,tl,tr,l,r,seg):
    if l<=tl and r>=tr:
        #print(v,l,r,seg[v])
        return seg[v]
    if tr<l or tl>r:
        return [0,0]

    tm=tl+(tr-tl)//2
    z1=query(v*2+1,tl,tm,l,r,seg)
    z2=query(2*v+2,tm+1,tr,l,r,seg)
    z3=[(z1[0]+z2[0])%10,\
    (z1[1]+z2[1])+(z1[0]+z2[0])//10]
    #print(z3)
    return z3
for i in range(q):
    l,r=map(int,input().split())
    print(query(0,0,n-1,l-1,r-1,seg)[1])


n = int(input())
a = list(map(int, input().split()))
S = {0:0}
for i in range(1, n+1):
    S[i] = S[i-1] + a[i-1]
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print((S[r]-S[l-1])//10)


n = int(input())
s = list(map(int, input().split()))
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    k = 0
    t = 0
    for j in range(l-1, r):
        t += s[j]
        if t >= 10:
            t -= 10
            k += 1
    print(k)


n = int(input())
s = list(map(int, input().split()))
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    k = sum(s[l-1:r])
    print((k - (k%10))//10)


n = int(input())
l = input().split()
q = int(input())
for i in range(q):
    r = input().split()
    sums = 0
    t = int(r[0]) - 1
    while t <int(r[1]):
        sums+=int(l[t])
        t += 1
    sums=(sums-sums%10)%10
    print(sums)


n = int(input())
l = input().split()
q = int(input())
for i in range(q):
    r = input().split()
    sums = 0
    t = int(r[0]) - 1
    while t <int(r[1]):
        sums+=int(l[t])
        t += 1
    sums=(sums-sums%10)/10
    print(sums)


n = int(input())
l = input().split()
q = int(input())
for i in range(q):
    r = input().split()
    sums = 0
    t = int(r[0]) - 1
    while t <int(r[1]):
        sums+=int(l[t])
        t += 1
    print(sums)


n = int(input())
l1 = input().split()
digits = []
for b in l1:
    digits.append(int(b))
q = int(input())
for i in range(q):
    r = input().split()
    s = digits[int(r[0]):int(r[1])+1]
    sum = 0
    for j in range(len(s)):
        sum += s[j]
    count = int((sum - (sum%10))/10)
    print(count)


n = int(input())
l1 = input().split()
digits = []
for b in l1:
    digits.append(int(b))
digits.append(0)
q = int(input())
for i in range(q):
    r = input().split()
    s = digits[int(r[0])-1:int(r[1])]
    sum = 0
    for j in range(len(s)):
        sum += s[j]
    count = int((sum - (sum%10))/10)
    print(count)


n = int(input())
l = input().split()
q = int(input())
for i in range(q):
    r = input().split()
    sums = 0
    t = int(r[0]) - 1
    while t <int(r[1]):
        sums+=int(l[t])
        t += 1
    sums=int((sums-sums%10)/10)
    print(sums)


n = int(input())
l = input().split()
q = int(input())
for i in range(q):
    r = input().split()
    sums = 0
    t = int(r[0]) - 1
    while t <int(r[1]):
        sums+=int(l[t])
        t += 1
    sumsint((sums-sums%10)/10)
    print(sums)


n = int(input())
s = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[0] = s[0]
for i in range(1, n):
    dp[i] = dp[i - 1] + s[i]
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    if l == 1:
        print(dp[r - 1] // 10)
    else:
        print((dp[r - 1] - dp[l - 2]) // 10)


class Sum:
    def __init__(self, s):
        self.dp = {(i + 1, i + 1): s[i] for i in range(len(s))}  # 1-indexed

    def find_sum(self, l, r):
        if (l, r) in self.dp:
            return self.dp[(l, r)]
        self.dp[(l, r)] = self.find_sum(l, l + (r - l + 1) // 2 - 1) + self.find_sum(l + (r - l + 1) // 2, r)
        return self.dp[(l, r)]

n = int(input())
s = list(map(int, input().split()))
dp_sum = Sum(s)
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(dp_sum.find_sum(l, r) // 10)


class Sum:
    def __init__(self, s):
        self.dp = {(i + 1, i + 1): s[i] for i in range(len(s))}  # 1-indexed

    def find_sum(self, l, r):
        if (l, r) in self.dp:
            return self.dp[(l, r)]
        self.dp[(l, r)] = self.find_sum(l, l + (r - l + 1) / 2 - 1) + self.find_sum(l + (r - l + 1) / 2, r)
        return self.dp[(l, r)]

n = int(input())
s = list(map(int, input().split()))
dp_sum = Sum(s)
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(dp_sum.find_sum(l, r) // 10)


n = int(input())
s = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(sum(s[l - 1:r]) // 10)


n=int(input())
a=input().split()
a=[int(i[-1]) for i in a]
q=int(input())
for _ in range(q):
    l,r=map(int,input().split())
    print(sum(a[l-1:r])//10)


from sys import stdin
n=int(input())
a=stdin.readline().split()
a=[int(i[-1]) for i in a]
b=[0]*(n+1)
for i in range(n):
    b[i+1]=b[i]+a[i]
q=int(input())
for _ in range(q):
    l,r=map(int,stdin.readline().split())
    print((b[r]-b[l-1])//10)


from sys import stdin
n=int(input())
a=stdin.readline().split()
a=[int(i[-1]) for i in a]
q=int(input())
dic={}
for _ in range(q):
    l,r=map(int,stdin.readline().split())
    if None==dic.get((l,r)):
        dic[(l,r)]=sum(a[l-1:r])//10
    print(dic.get((l,r)))


n=int(input())
a=input().split()
a=[int(i[-1]) for i in a]
q=int(input())
dic={}
for _ in range(q):
    l,r=map(int,input().split())
    if None==dic.get((l,r)):
        dic[(l,r)]=sum(a[l-1:r])//10
    print(dic.get((l,r)))


from itertools import accumulate, permutations

R = lambda: map(int, input().split())
n = int(input())
acc = [0] + list(accumulate(R()))
for q in range(int(input())):
    l, r = R()
    print((acc[r] - acc[l - 1]) // 10)


n = int(input())
s = list(map(int,input().split()))
sums = [0 for _ in range(n+1)]
for i in range(1,n+1):
	sums[i] = sums[i-1] + s[i-1]
q = int(input())
while q>0:
	q-=1
	l,r=map(int,input().split())
	print((sums[r]-sums[l-1])//10)


n = int(input())
s = list(map(int,input().split()))
sums = [0 for _ in range(n+1)]
for i in range(1,n+1):
	sums[i] = sums[i-1] + s[i-1]
for _ in range(int(input())):
	l,r=map(int,input().split())
	print((sums[r]-sums[l-1])//10)


n = int(input())
a = list(map(int, input().split()))

k = 0
while n>>k!=0:
    k+=1
k-=1
p = [[] for i in range(k+1)]
c = [[] for i in range(k+1)]
for i in range(n):
    p[0].append(a[i])
    c[0].append(0)
for i in range(1, k+1):
    for j in range(n-(1<<i)+1):
        s = p[i-1][j]+p[i-1][j+i]
        p[i].append(s%10)
        c[i].append(c[i-1][j]+c[i-1][j+i])
        if s>=10:
            c[i][-1]+=1
m = int(input())
#print(c)
for _ in range(m):
    l, r = map(int, input().split())
    k=1
    x=0
    while k<r-l+1:
        k*=2
        x+=1
    print(c[x][l-1])


n = int(input())
a = list(map(int, input().split()))

s = [0]
for i in a:
    s.append(s[-1]+i)
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print((s[r]-s[l-1])//10)


import math
from collections import Counter,defaultdict
I =lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
n=I()
a=LI()
b=[0]*(n+1);c=0
for i in range(n):
    c+=a[i]
    b[i+1]=c
m=I()
for i in range(m):
    c,d=M()
    print((b[d]-b[c-1])//10)


i,s=input,[0]
i()
for n in map(int,i().split()):
    s+=[s[-1]+n]
for _ in [0]*int(i()):
    x,y=map(int,i().split())
    print((s[y]-s[x-1])//10)


n = int(input())
arr = list(map(int, input().split()))

q = int(input())
for query in range(q):
    l, r = map(int, input().split())
    here = arr[l:r+1]
    c = sum(here)//10
    print(c)


n = int(input())
arr = list(map(int, input().split()))
s = 0
totals_c = [0]
for elem in arr:
    s += elem
    totals_c.append(s)
q = int(input())
for query in range(q):
    l, r = map(int, input().split())
    c = (totals_c[r] - totals_c[l-1])//10
    print(c)


n = int(input())
arr = list(map(int, input().split()))

q = int(input())
for query in range(q):
    l, r = map(int, input().split())
    here = arr[l-1:r]
    c = sum(here)//10
    print(c)


import math

n = int(input())
a = list(map(int, input().split()))
prefix = [0]
for i in range(n):
    prefix.append(prefix[-1] + a[i])
# print(prefix)
for _ in range(int(input())):
    l, r = map(int, input().split())
    print((prefix[r] - prefix[l])//10)


n = int(input())
a = list(map(int, input().split()))
prefix = [0]
for i in range(n):
    prefix.append(prefix[-1] + a[i])
# print(prefix)
for _ in range(int(input())):
    l, r = map(int, input().split())
    print((prefix[r] - prefix[l - 1])//10)


import math

n = int(input())
a = list(map(int, input().split()))
prefix = [0]
while True:
    j = 0
    for i in range(0, n, 2):
        if i < n-1:
            a[j] = (a[i] + a[i + 1])
        else:
            a[j] = a[i]
        if a[j] >= 10:
            prefix.append(prefix[-1] + 1)
        else:
            prefix.append(prefix[-1])
        a[j] %= 10
        j += 1
    # print(a)
    # print(prefix)
    if n == 1:
        break
    n = math.ceil(n / 2)
for _ in range(int(input())):
    l, r = map(int, input().split())
    if r == 2:
        print(prefix[1])
    else:
        if l == r:
            print(0)
        else:
            print(prefix[r] - prefix[l - 1])


import math

n = int(input())
a = list(map(int, input().split()))
prefix = [0]
while True:
    j = 0
    for i in range(0, n, 2):
        a[j] = (a[i] + a[i + 1])
        if a[j] >= 10:
            prefix.append(prefix[-1] + 1)
        else:
            prefix.append(prefix[-1])
        a[j] %= 10
        j += 1
    #print(a)
    #print(prefix)
    if n == 1:
        break
    n = math.ceil(n / 2)
for _ in range(int(input())):
    l, r = map(int, input().split())
    if r == 2:
        print(prefix[1])
    else:
        if l == r:
            print(0)
        else:
            print(prefix[r] - prefix[l - 1])


import sys
input = sys.stdin.readline

n = int(input())
s = list(map(int, input().split()))
pref = [0]
for i in s:
	pref.append(pref[-1] + i)

for _ in range(int(input())):
	l, r = map(int, input().split())
	print((pref[r] - pref[l-1])//10)


import sys
input = sys.stdin.readline

mod = 10
n = int(input())
s = list(map(int, input().split()))

for _ in range(int(input())):
	l, r = map(int, input().split())
	l -= 1
	r -= 1
	ans = 0
	p = [s[x] for x in range(l, r+1)]
	while len(p)> 1:
		a = []
		for i in range(0,len(p),2):
			res = p[i] + p[i+1]
			if res >= 10:
				ans += 1
			a.append(res%10)
		p = a[:]
	print(ans)


import sys,math

def read_int():
    return int(sys.stdin.readline().strip())

def read_int_list():
    return list(map(int,sys.stdin.readline().strip().split()))

def read_string():
    return sys.stdin.readline().strip()

def read_string_list(delim=" "):
    return sys.stdin.readline().strip().split(delim)

def print_list(l, delim=" "):
    print(delim.join(map(str, l)))

###### Author : Samir Vyas #######
###### Write Code Below    #######

n = read_int()
arr = read_int_list()

prefix_sum = [0 for _ in range(n)]

prefix_sum[0] = arr[0]

for i in range(1,n):
	prefix_sum[i] = prefix_sum[i-1] + arr[i]

q = read_int()

for _ in range(q):
	l,r = read_int_list()
	ans = prefix_sum[r-1] - (prefix_sum[l-2] if l > 1 else 0)
	print(int(ans/10))


import sys,math

def read_int():
    return int(sys.stdin.readline().strip())

def read_int_list():
    return list(map(int,sys.stdin.readline().strip().split()))

def read_string():
    return sys.stdin.readline().strip()

def read_string_list(delim=" "):
    return sys.stdin.readline().strip().split(delim)

def print_list(l, delim=" "):
    print(delim.join(map(str, l)))

###### Author : Samir Vyas #######
###### Write Code Below    #######

n = read_int()
arr = read_int_list()

prefix_sum = [0 for _ in range(n)]

prefix_sum[0] = arr[0]

for i in range(1,n):
	prefix_sum[i] = prefix_sum[i-1] + arr[i]

q = read_int()

for _ in range(q):
	l,r = read_int_list()
	ans = prefix_sum[r-1] - (prefix_sum[l-1] if l != 1 else 0)
	print(int(ans/10))


import sys,math

def read_int():
    return int(sys.stdin.readline().strip())

def read_int_list():
    return list(map(int,sys.stdin.readline().strip().split()))

def read_string():
    return sys.stdin.readline().strip()

def read_string_list(delim=" "):
    return sys.stdin.readline().strip().split(delim)

def print_list(l, delim=" "):
    print(delim.join(map(str, l)))

###### Author : Samir Vyas #######
###### Write Code Below    #######

n = read_int()
arr = read_int_list()

prefix_sum = [0 for _ in range(n)]

prefix_sum[0] = arr[0]

for i in range(n):
	prefix_sum[i] = prefix_sum[i-1] + arr[i]

q = read_int()

for _ in range(q):
	l,r = read_int_list()
	ans = prefix_sum[r-1] - (prefix_sum[l-1] if l != 1 else 0)
	print(int(ans/10))


import atexit
import io
import sys

# _INPUT_LINES = sys.stdin.read().splitlines()
# input = iter(_INPUT_LINES).__next__
# _OUTPUT_BUFFER = io.StringIO()
# sys.stdout = _OUTPUT_BUFFER
#
#
# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

from collections import Counter

i,s=input,[0]
i()
for n in map(int,i().split()):
    s+=[s[-1]+n]
print(s)
for _ in [0]*int(i()):
    x,y=map(int,i().split())
    print((s[y]-s[x-1])//10)


import atexit
import io
import sys

# _INPUT_LINES = sys.stdin.read().splitlines()
# input = iter(_INPUT_LINES).__next__
# _OUTPUT_BUFFER = io.StringIO()
# sys.stdout = _OUTPUT_BUFFER
#
#
# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

from collections import Counter

i,s=input,[0]
i()
for n in map(int,i().split()):
    s+=[s[-1]+n]
# print(s)
for _ in [0]*int(i()):
    x,y=map(int,i().split())
    print((s[y]-s[x-1])//10)


n = int(input())
a = list(map(int, input().split(" ")))
q = int(input())
suma = [0]
t = 0
for i in range(n):
    t += a[i]
    suma.append(t)
for i in range(q):
    l,r = map(int, input().split(" "))
    temp = suma[r]-suma[l-1]
    print(temp//10)


n = int(input())
a = list(map(int, input().split(" ")))
q = int(input())
for i in range(q):
    l,r = map(int, input().split(" "))
    temp = a[l-1:r]
    print(sum(temp)//10)


n = int(input())
a = list(map(int,input().split()))
p = [a[0]]
for i in range(1,n):
	p.append(p[-1]+a[i])
for nt in range(int(input())):
	l,r = map(int,input().split())
	if l==1:
		print (p[r-1]//10)
	else:
		print ((p[r-1]-p[l-2])//10)


n = int(input())

lt = [int(x) for x in input().split()]
pref = [0]*n
pref[0] = lt[0]

for i in range(1 , len(lt)):
    pref[i] = pref[i-1] + lt[i]
q = int(input())

while q!=0:
    q-=1
    l,r = map(int, input().split())
    l-=1
    r-=1
    sm = 0
    if l==0:
        sm = pref[r]
    else:
        sm = pref[r] - pref[l-1]
    print(sm//10)


import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
d = {}

def calc(l, r, x, y):
    if (l, r) in d:
        return d[(l, r)]
    else:
        if l + 1 == r:
            d[(l, r)] = int(x + y >= 10), (x + y) % 10
            return d[(l, r)]
        else:
            w, k1 = calc(l, (l + r) // 2, x, a[(l + r) // 2])
            z, k2 = calc((l + r) // 2 + 1, r, a[(l + r) // 2 + 1], y)
            d[(l, r)] = w + z + int(k1 + k2 >= 10), (k1 + k2) % 10
            return d[(l, r)]

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    if l == r:
        print(0)
    else:
        b, v = calc(l, r, a[l], a[r])
        print(b)


N = int(input())
a = list(map(int, input().split()))
d = {}

def calc(l, r, x, y):
    if (l, r) in d:
        return d[(l, r)]
    else:
        if l + 1 == r:
            d[(l, r)] = int(x + y >= 10), (x + y) % 10
            return d[(l, r)]
        else:
            w, k1 = calc(l, (l + r) // 2, x, a[(l + r) // 2])
            z, k2 = calc((l + r) // 2 + 1, r, a[(l + r) // 2 + 1], y)
            d[(l, r)] = w + z + int(k1 + k2 >= 10), (k1 + k2) % 10
            return d[(l, r)]

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    if l == r:
        print(0)
    else:
        b, v = calc(l, r, a[l], a[r])
        print(b)


import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
d=defaultdict(int)
n=I()
l=L()
x=[0]
for i in range(n):
    x.append(x[-1]+l[i])
q=I()

for i in range(n):
    le,r=M()
    print((x[r]-x[le-1])//10)


import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
d=defaultdict(int)
n=I()
l=L()
x=[0]
for i in range(n):
    x.append(x[-1]+l[i])
q=I()

for i in range(q):
    le,r=M()
    print((x[r]-x[le-1])//10)


n = int(input())
s = [int(x) for x in input().split()]
pref = [0]*n
pref[0] = s[0]
for i in range(1, n):
    pref[i] = pref[i-1]+s[i]
pref.insert(0,0)
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print((pref[r]-pref[l-1])//10)


from itertools import accumulate
a=int(input());z=[0]+list(accumulate(map(int,input().split())))
for _ in " "*int(input()):u,v=map(int,input().split());print((z[v]-z[u-1])//10)


import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions
from collections import deque,defaultdict,OrderedDict
from fractions import Fraction
from decimal import Decimal

def main():
    starttime=datetime.datetime.now()
    if(os.path.exists('input.txt')):
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")

    for _ in range(1):
        n=ri()
        s=ria()
        q=ri()
        prefsum=[0]
        c=0
        for i in range(n):
            c+=s[i]
            prefsum.append(c)
        for i in range(q):
            l,r=ria()
            print((prefsum[r]-prefsum[l-1])//10)

    #<--Solving Area Ends
    endtime=datetime.datetime.now()
    time=(endtime-starttime).total_seconds()*1000
    if(os.path.exists('input.txt')):
        print("Time:",time,"ms")

class FastReader(io.IOBase):
    newlines = 0

    def __init__(self, fd, chunk_size=1024 * 8):
        self._fd = fd
        self._chunk_size = chunk_size
        self.buffer = io.BytesIO()

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, size=-1):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

class FastWriter(io.IOBase):

    def __init__(self, fd):
        self._fd = fd
        self.buffer = io.BytesIO()
        self.write = self.buffer.write

    def flush(self):
        os.write(self._fd, self.buffer.getvalue())
        self.buffer.truncate(0), self.buffer.seek(0)

class FastStdin(io.IOBase):
    def __init__(self, fd=0):
        self.buffer = FastReader(fd)
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

class FastStdout(io.IOBase):
    def __init__(self, fd=1):
        self.buffer = FastWriter(fd)
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.flush = self.buffer.flush

if __name__ == '__main__':
    sys.stdin = FastStdin()
    sys.stdout = FastStdout()
    main()


import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions
from collections import deque,defaultdict,OrderedDict
from fractions import Fraction
from decimal import Decimal

def main():
    starttime=datetime.datetime.now()
    if(os.path.exists('input.txt')):
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")

    for _ in range(1):
        n=ri()
        s=ria()
        q=ri()
        prefsum=[]
        c=0
        for i in range(n):
            c+=s[i]
            prefsum.append(c)
        for i in range(q):
            l,r=ria()
            print((prefsum[r-1]-prefsum[l-1])//10)

    #<--Solving Area Ends
    endtime=datetime.datetime.now()
    time=(endtime-starttime).total_seconds()*1000
    if(os.path.exists('input.txt')):
        print("Time:",time,"ms")

class FastReader(io.IOBase):
    newlines = 0

    def __init__(self, fd, chunk_size=1024 * 8):
        self._fd = fd
        self._chunk_size = chunk_size
        self.buffer = io.BytesIO()

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, size=-1):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

class FastWriter(io.IOBase):

    def __init__(self, fd):
        self._fd = fd
        self.buffer = io.BytesIO()
        self.write = self.buffer.write

    def flush(self):
        os.write(self._fd, self.buffer.getvalue())
        self.buffer.truncate(0), self.buffer.seek(0)

class FastStdin(io.IOBase):
    def __init__(self, fd=0):
        self.buffer = FastReader(fd)
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

class FastStdout(io.IOBase):
    def __init__(self, fd=1):
        self.buffer = FastWriter(fd)
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.flush = self.buffer.flush

if __name__ == '__main__':
    sys.stdin = FastStdin()
    sys.stdout = FastStdout()
    main()


n = int(input())
a = [int(x) for x in input().split()]

q = int(input())
for i in range(1, n):
    a[i] += a[i - 1]

for Q in range(q):
    l, r = [int(x) for x in input().split()]
    l -= 1
    r -= 1

    sm = 0
    if l == 0:
        sm = a[r]
    else:
        sm = a[r] - a[l - 1]

    print(sm // 10)


import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
pf = [0]+list(accumulate(a))

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print((pf[r]-pf[l-1])//10)


from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
pf = [0]+list(accumulate(a))

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print((pf[r]-pf[l-1])//10)


from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))

pf = [0]+list(accumulate(a))

q = int(input())

for _ in range(q):
    l, r = map(int, input().split())

    print((pf[r-1]-pf[l-1])//10)


from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))

pf = [0]+list(accumulate(a))

q = int(input())

for _ in range(q):
    l, r = map(int, input().split())

    print((pf[r]-pf[l-1])//10)


class Solution:
  def getNumberOfCandies(self, test, l, r):
    arr = test[l - 1:r]
    candies = 0
    while len(arr) > 1:
      newArr = []
      for i in range(0, len(arr), 2):
        pairSum = (arr[i] + arr[i + 1])
        if pairSum >= 10: candies += 1
        newArr.append(pairSum % 10)
      arr = newArr
    return candies

def read_input():
  return [int(x) for x in input().split()]

if __name__ == "__main__":
  n = int(input())
  test = read_input()
  q = int(input())

  for i in range(q):
    l, r = read_input()
    sol = Solution()
    result = sol.getNumberOfCandies(test, l, r)
    print(result)


class Solution:
  def getNumberOfCandies(self, test, l, r):
    def helper(arr):
      if arr is None or len(arr) <= 1: return 0
      newArr = []
      candies = 0
      for i in range(0, len(arr), 2):
        pairSum = (arr[i] + arr[i + 1])
        if pairSum >= 10: candies += 1
        newArr.append(pairSum % 10)
      candies += helper(newArr)
      return candies

    arr = test[l - 1:r]
    return helper(arr)

def read_input():
  return [int(x) for x in input().split()]

if __name__ == "__main__":
  n = int(input())
  test = read_input()
  q = int(input())

  for i in range(q):
    l, r = read_input()
    sol = Solution()
    result = sol.getNumberOfCandies(test, l, r)
    print(result)


class Solution(object):
    def getNumberOfCandies(self, test, q):
        sum = [0]
        for num in test:
            sum += [sum[-1] + num]
        for _ in range(q):
            l, r = read_input()
            print((sum[r] - sum[l - 1])//10)

def read_input(): # list
    return [x for x in map(int, input().split())]

if __name__ == "__main__":
  n = int(input())
  test = read_input()
  q = int(input())
  sol = Solution()
  sol.getNumberOfCandies(test, q)


import sys

n = int(sys.stdin.readline().strip())
s = list(map(int, sys.stdin.readline().strip().split()))
q = int(sys.stdin.readline().strip())

for i in range (0, q):
    l, r = list(map(int, sys.stdin.readline().strip().split()))
    print(sum(s[l:r+1])//10)


import sys

n = int(sys.stdin.readline().strip())
s = list(map(int, sys.stdin.readline().strip().split()))
q = int(sys.stdin.readline().strip())
A = [s[:]]
for i in range (1, 20):
    A.append([])
    for j in range (n // (2 ** i)):
        A[i].append(A[i-1][2*j] + A[i-1][2*j+1])

for i in range (0, q):
    l, r = list(map(int, sys.stdin.readline().strip().split()))
    l = l - 1
    r = r - 1
    x = 0
    while l != r + 1:
        l2 = l
        e = 0
        while l2 % 2 == 0 and l + 2 ** (e+1) <= r+1:
            l2 = l2 // 2
            e = e + 1
        x = x + A[e][l2]
        l = l + 2 ** e
    print(x//10)


import sys

n = int(sys.stdin.readline().strip())
s = list(map(int, sys.stdin.readline().strip().split()))
q = int(sys.stdin.readline().strip())

for i in range (0, q):
    l, r = list(map(int, sys.stdin.readline().strip().split()))
    print(sum(s[l-1:r])//10)


from math import log2
from collections import defaultdict
import sys
input = sys.stdin.readline
'''
for CASES in range(int(input())):
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
sys.stdout.write(" ".join(map(str,ans))+"\n")
'''
inf = 100000000000000000  # 1e17
mod = 998244353

n = int(input())
A = list(map(int, input().split()))
f = [[0] * 32 for i in range(n)]
SUM = [[0] * 32 for i in range(n)]
for i in range(n):
    SUM[i][0] = A[i]
    f[i][0] = 0
MAX = int(log2(n))
for len in range(1, MAX + 1):
    for i in range(n):
        LEN = 1 << len
        LAST = 1 << (len - 1)
        if i + LEN - 1 >= n:
            break
        f[i][len] = f[i][len - 1] + f[i + LAST][len - 1]
        SUM[i][len] = SUM[i][len - 1] + SUM[i + LAST][len - 1]
        if SUM[i][len] >= 10:
            SUM[i][len] -= 10
            f[i][len] += 1

for CASES in range(int(input())):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    dis = int(log2(y - x + 1))
    print(f[x][dis])

# the end


from sys import *
n=int(stdin.readline())
a=list(map(int,input().split()))
pre=[0]
for i in range(n):
    pre.append(pre[i]+a[i])
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    ans=(pre[r]-pre[l-1])//10
    print(ans)


n = int(input())
lst = list(map(int, input().split()))
lstsum = [0] * (n + 1)
isum = 0
for i in range(1, n + 1):
    isum += lst[i - 1]
    lstsum[i] = isum
for i in range(int(input())):
    l, r = map(int, input().split())
    print((lstsum[r] - lstsum[l - 1]) // 10)


n = int(input())
lst = list(map(int, input().split()))
for i in range(int(input())):
    l, r = map(int, input().split())
    l -= 1
    print(sum(lst[l:r]) // 10)


private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()

private val regSpace = "\\s+".toRegex()

private fun readSomeInts(): List<Int> {
    return readLn().trim().split(regSpace).map { it.toInt() }
}

fun main() {
    val n = readInt()
    val ds = readSomeInts()
    check(n == ds.size)
    val q = readInt()
    val queries = List(q) {
        val (l, r) = readSomeInts()
        Pair(l, r)
    }

    val sums: List<Long> =
        ds.fold(mutableListOf(0L)) { acc, b ->
            val z = acc.last() + b
            acc.add(z)
            acc }

    val xs = queries.map { (l, r) ->
        val mysum = sums[r] - sums[l - 1]
        mysum / 10
    }

    println("${xs.joinToString(separator = "\n")}")

}


import java.io.File
import java.util.*

fun main() {
//    val file = File("datac.txt")
//    val reader = Scanner(file)
    val reader = Scanner(System.`in`)
    val n = reader.nextInt()
    val input = mutableListOf<Int>()
    for (i in 1..n){
        input.add(reader.nextInt())
    }
    val q = reader.nextInt()
    for(i in 1..q){
        val l = reader.nextInt()
        val r = reader.nextInt()
        var sub = input.subList(l-1,r)
        var count = 0
        while (sub.size>1){
            val ns = sub.size
            val sub2 = mutableListOf<Int>()
            for(i in 0 until ns step 2){
                if(sub[i]+sub[i+1]>=10)count++
                sub2.add((sub[i]+sub[i+1])%10)
            }
            sub = sub2
        }
        println(count)
    }
}


import java.io.File
import java.util.*

fun main() {
//    val file = File("datac.txt")
//    val reader = Scanner(file)
    val reader = Scanner(System.`in`)
    val n = reader.nextInt()
    val input = mutableListOf<Int>()
    for (i in 1..n){
        input.add(reader.nextInt())
    }
    val q = reader.nextInt()
    for(i in 1..q){
        val l = reader.nextInt()
        val r = reader.nextInt()
        val sub = input.subList(l-1,r)
        println(sub.sum()/10)
    }
}


import java.io.File
import java.util.*

fun main() {
//    val file = File("datac.txt")
//    val reader = Scanner(file)
    val reader = Scanner(System.`in`)
    val n = reader.nextInt()
    val input = mutableListOf<Int>()
    val sum = mutableListOf<Int>()
    sum.add(0)
    for (i in 1..n){
        input.add(reader.nextInt())
        sum.add(sum[i-1]+input[i-1])
    }
    val q = reader.nextInt()
    for(i in 1..q){
        val l = reader.nextInt()
        val r = reader.nextInt()
        val sum1 = sum[r]-sum[l-1]
        println(sum1/10)
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define X first
#define Y second
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main () {
    speed;
    string s;
    int prev1 = 0;
    int prev2 = 0;
    for( int i = 0; i < s.size(); i++)
    {
        cur = s[i];
        if(cur % 3 == 0 || (cur + prev1) % 3 == 0 || (cur + prev1 + prev2) % 3 == 0)
            ans++, prev1 = prev2 = 0;
        else
            prev2 = prev1, prev1 = cur;
    }
    ans = 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int k=0, t=0, a, tM, tk;
    string s;
    cin >> s;
    vector <int> K;
    K.push_back(-1);
    for (int i = 0; i < s.length(); i++)
    {
        a = s[i] - '0';
        if (a % 3 == 0)
        {
            K.push_back(i);
            t++;
        }
    }
    K.push_back(s.length());
    for (int i = 0; i < K.size()-1; i++)
    {
        k = 0;
        tM = 0;
        tk = 0;
        for (int y = K[i]+1; y < K[i+1]; y++)
        {
            k += s[y] - '0';
            if (k % 3 == 0)
            {
                k = 0;
                tk++;
            }
        }
        tM = tk;
        k = 0;
        for (int y = K[i+1]-1; y >= K[i]+1; y--)
        {
            k += s[y] - '0';
            if (k % 3 == 0)
            {
                k = 0;
                tk++;
            }
        }
        tM = max(tM,tk);
        t += tM;
    }
    cout << t;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int k=0, t=0, a, tM, tk;
    string s;
    cin >> s;
    vector <int> K;
    K.push_back(-1);
    for (int i = 0; i < s.length(); i++)
    {
        a = s[i] - '0';
        if (a % 3 == 0)
        {
            K.push_back(i);
            t++;
        }
    }
    K.push_back(s.length());
    for (int i = 0; i < K.size()-1; i++)
    {
        k = 0;
        tk = 0;
        for (int y = K[i]+1; y < K[i+1]; y++)
        {
            k += s[y] - '0';
            if (k % 3 == 0)
            {
                k = 0;
                tk++;
            }
        }
        tM = tk;
        k = 0;
        tk = 0;
        for (int y = K[i+1]-1; y >= K[i]+1; y--)
        {
            k += s[y] - '0';
            if (k % 3 == 0)
            {
                k = 0;
                tk++;
            }
        }
        tM = max(tM,tk);
        t += tM;
    }
    cout << t;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int k=0, t=0, a, tM, tk;
    string s;
    cin >> s;
    vector <int> K;
    K.push_back(-1);
    for (int i = 0; i < s.length(); i++)
    {
        a = s[i] - '0';
        if (a % 3 == 0)
        {
            K.push_back(i);
            t++;
        }
    }
    K.push_back(s.length());
    for (int i = 0; i < K.size()-1; i++)
    {
        k = 0;
        tM = 0;
        tk = 0;
        for (int y = K[i]+1; y < K[i+1]; y++)
        {
            k += s[y] - '0';
            if (k % 3 == 0)
            {
                k = 0;
                tk++;
            }
        }
        tM = tk;
        k = 0;
        for (int y = K[i+1]-1; y >= K[i]+1; y--)
        {
            k += s[y] - '0';
            if (k % 3 == 0)
            {
                k = 0;
                t++;
            }
        }
        tM = max(tM,tk);
        t += tM;
    }
    cout << t;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int k=0, t=0, a;
    string s;
    cin >> s;
    vector <int> K;
    K.push_back(-1);
    for (int i = 0; i < s.length(); i++)
    {
        a = s[i] - '0';
        if (a % 3 == 0)
        {
            K.push_back(i);
            t++;
        }
    }
    K.push_back(s.length());
    for (int i = 0; i < K.size()-1; i++)
    {
        k = 0;
        for (int y = K[i]+1; y < K[i+1]; y++)
        {
            k += s[y] - '0';
            if (k % 3 == 0)
            {
                k = 0;
                t++;
            }
        }
    }
    cout << t;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int k=0, t=0, a, tM, tk;
    string s;
    cin >> s;
    vector <int> K;
    K.push_back(-1);
    for (int i = 0; i < s.length(); i++)
    {
        a = s[i] - '0';
        if (a % 3 == 0)
        {
            K.push_back(i);
            t++;
        }
    }
    K.push_back(s.length());
    for (int i = 0; i < K.size()-1; i++)
    {
        k = 0;
        tM = 0;
        tk = 0;
        for (int y = K[i]+1; y < K[i+1]; y++)
        {
            k += s[y] - '0';
            if (k % 3 == 0)
            {
                k = 0;
                tk++;
            }
        }
        tM = tk;
        for (int y = K[i+1]-1; y >= K[i]+1; y--)
        {
            k += s[y] - '0';
            if (k % 3 == 0)
            {
                k = 0;
                t++;
            }
        }
        tM = max(tM,tk);
        t += tM;
    }
    cout << t;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long121
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];
string s;
char S[MX];
/*
111111111111111111
*/
int main()
{
    scanf("%s", S);
    s=S;
    int cur=0, an=0;
    for(int i=0;i<s.size();i++)
    {
        int a=s[i]-'0';
        a%=3;
        cur+=a;
        if(a == 0)
        {
            cur=0;
            ++an;
            continue;
        }
        if(cur == 3)
        {
            cur=0;
            ++an;
            continue;
        }
        if(cur == 4)
        {
            if(i && s[i-1]-'0' == 2) continue;
            cur=0;
            ++an;
            continue;
        }
        if(cur == 5 || cur == 6)
        {
            cur=0;
            ++an;
            continue;
        }

    }
    int ans=0;
    cur=0;
    for(int i=s.size()-1;i>=0;i--)
    {
        int a=s[i]-'0';
        a%=3;
        cur+=a;
        if(a == 0)
        {
            cur=0;
            ++ans;
            continue;
        }
        if(cur == 3)
        {
            cur=0;
            ++ans;
            continue;
        }
        if(cur == 4)
        {
            if(i!=N-1 && s[i+1]-'0' == 2) continue;
            cur=0;
            ++ans;
            continue;
        }
        if(cur == 5 || cur == 6)
        {
            cur=0;
            ++ans;
            continue;
        }

    }
   /// cout<<endl;
    cout<<max(an, ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long121
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];
string s;
char S[MX];
/*
111111111111111111
*/
int main()
{
    scanf("%s", S);
    s=S;
    int cur=0, an=0;
    for(int i=0;i<s.size();i++)
    {
        int a=s[i]-'0';
        a%=3;
        cur+=a;
        if(a == 0)
        {
            cur=0;
            ++an;
            continue;
        }
        if(cur == 3)
        {
            cur=0;
            ++an;
            continue;
        }
        if(cur == 4)
        {
            if(i && s[i-1]-'0' == 2) continue;
            cur=0;
            ++an;
            continue;
        }
        if(cur == 5 || cur == 6)
        {
            cur=0;
            ++an;
            continue;
        }

    }
   /// cout<<endl;
    cout<<an;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long121
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];
string s;
char S[MX];
/*
111111111111111111
*/
int main()
{
    scanf("%s", S);
    s=S;
    int cur=0, an=0;
    for(int i=0;i<s.size();i++)
    {
        int a=s[i]-'0';
        a%=3;
        cur+=a;
        if(a == 0)
        {
            cur=0;
            ++an;
            continue;
        }
        if(cur == 3)
        {
            cur=0;
            ++an;
            continue;
        }
        if(cur == 4)
        {
            if(i && s[i-1]-'0' == 2) continue;
            cur=0;
            ++an;
            continue;
        }
        if(cur == 5 || cur == 6)
        {
            cur=0;
            ++an;
            continue;
        }

    }
    int ans=0;
    cur=0;
    for(int i=s.size()-1;i>=0;i--)
    {
        int a=s[i]-'0';
        a%=3;
        cur+=a;
        if(a == 0)
        {
            cur=0;
            ++ans;
            continue;
        }
        if(cur == 3)
        {
            cur=0;
            ++ans;
            continue;
        }
        if(cur == 4)
        {
            if(i!=s.size()-1 && s[i+1]-'0' == 2) continue;
            cur=0;
            ++ans;
            continue;
        }
        if(cur == 5 || cur == 6)
        {
            cur=0;
            ++ans;
            continue;
        }

    }
   /// cout<<endl;
    cout<<max(an, ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];
string s;
char S[MX];
int main()
{
    scanf("%s", S);
    s=S;
    int cur=0, an=0;
    for(int i=0;i<s.size();i++)
    {
        int a=s[i]-'0';
        a%=3;
        cur+=a;
        if(cur+a == cur)
        {
            cur=0;
            ++an;
        }
        else if(cur == 4)
        {
            cur=0;
            ++an;
        }
        else if(cur == 3)
        {
            cur=0;
            ++an;
        }
    }
    cout<<an;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long121
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];
char s[MX];
int dp[MX];
int f(int idx)
{
    if(idx >= N) {
        return 0;
    }
    int &ret=dp[idx];
    if(ret != -1) return ret;
    ret=f(idx+1);
    int cur=s[idx]-'0';
    ret=max(ret, (cur%3 == 0)+f(idx+1));
    if(idx+1 < N) cur*=10, cur+=s[idx+1]-'0', ret=max(ret, (cur%3 == 0) +f(idx+2));
    if(idx+2 < N) cur*=10, cur+=s[idx+2]-'0', ret=max(ret, (cur%3 == 0) +f(idx+3));
    return ret;
}
int main()
{
    scanf("%s", s);
    N=strlen(s);
    memset(dp, -1, sizeof dp);
    cout<<f(0);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];
string s;
char S[MX];
int main()
{
    scanf("%s", S);
    s=S;
    int cur=0, an=0;
    for(int i=0;i<s.size();i++)
    {
        int a=s[i]-'0';
        a%=3;
        cur+=a;
        if(cur+a == cur)
        {
            cur=0;
            ++an;
        }
        else if(cur == 4)
        {
            if(i&&s[i-1]-'0' == 2) continue;
            cur=0;
            ++an;
        }
        else if(cur == 3)
        {
            cur=0;
            ++an;
        }
        else if(cur == 6)
        {
            cur=0;
            ++an;
        }
    }
    cout<<an;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];
string s;
char S[MX];
int main()
{
    scanf("%s", S);
    s=S;
    int cur=0, an=0;
    for(int i=0;i<s.size();i++)
    {
        int a=s[i]-'0';
        a%=3;
        cur+=a;
        if(cur+a == cur)
        {
            cur=0;
            ++an;
        }
        else if(cur == 4)
        {
            if(i&&s[i-1]-'0' == 2) continue;
            cur=0;
            ++an;
        }
        else if(cur == 3)
        {
            cur=0;
            ++an;
        }
        else if(cur == 6)
        {
            cur=0;
            ++an;
        }
        else if(cur == 5)
        {
            cur=0;
            ++an;
        }
    }
    cout<<an;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
const int MAXN = 2e5;
using namespace std;

char str[MAXN + 5];
int n, a[MAXN + 5], dp[MAXN + 5];
int last[3], pre;

void init() {
  scanf("%s", str + 1);
  n = strlen(str + 1);

  for (int i = 1; i <= n; ++i) a[i] = str[i] - '0';
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
#endif
  init();

  memset(last, -1, sizeof(last)), last[0] = 0;

  for (int i = 1; i <= n; ++i) {
    pre = (pre + a[i] % 3) % 3;

    dp[i] = dp[i - 1];
    if (~last[pre]) dp[i] = max(dp[i], dp[last[pre]] + 1);

    last[pre] = i;
  }

  printf("%d\n", dp[n]);
  return 0;
}


//Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
const int MAXN = 200000;
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, a[MAXN + 5], k;
char s[MAXN + 5];

void init() {
  scanf("%s", s);
  n = strlen(s);

  for (int i = 0; i < n; ++i) {
    a[i + 1] = s[i] - '0';
    if (a[i + 1] % 3 == 0) ++k;
  //  while (a[i] < '0' || a[i] > '9') a[i] = getchar();
  }
}

int ans = 0, ans2 = 0;

int main() {
  init();

  int sum = a[1];

  for (int i = 2; i <= n; ++i) {
    if (sum % 3 == 0) {
      ++ans;
      sum = a[i];
    } else {
      sum += a[i];
    }
  }

  sum = a[n];
  for (int i = n - 1; i; --i) {
    if (sum % 3 == 0) {
      ++ans2;
      sum = a[i];
    } else {
      sum += a[i];
    }
  }

  if (sum % 3 == 0) ++ans2;

  printf("%d\n", max(ans, ans2));

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
const int MAXN = 2e5;
using namespace std;

char str[MAXN + 5];
int n, a[MAXN + 5], ans;

void init() {
  scanf("%s", str + 1);
  n = strlen(str + 1);

  for (int i = 1; i <= n; ++i) a[i] = str[i] - '0';
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
#endif
  init();

  int sum = a[n];
  for (int i = n - 1; i; --i) {
    if (sum % 3 == 0) {
      ++ans;
      sum = a[i];
    } else {
      if (a[i] % 3 == 0) {
        sum = a[i];
      } else {
        sum += a[i];
      }
    }
  }

  if (sum % 3 == 0) ++ans;
  printf("%d\n", ans);
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
const int MAXN = 2e5;
using namespace std;

char str[MAXN + 5];
int n, a[MAXN + 5], ans;

void init() {
  scanf("%s", str + 1);
  n = strlen(str + 1);

  for (int i = 1; i <= n; ++i) a[i] = str[i] - '0';
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
#endif
  init();

  int sum = a[n];
  for (int i = n - 1; i; --i) {
    if (sum % 3 == 0) {
      ++ans;
      sum = a[i];
    } else {
      if (a[i] % 3 == 0) {
        sum = a[i];
      } else {
        sum += a[i];
      }
    }
  }

  sum = a[1];
  int ans2 = 0;
  for (int i = 2; i <= n; ++i) {
    if (sum % 3 == 0) {
      ++ans2;
      sum = a[i];
    } else {
      if (a[i] % 3 == 0) {
        sum = a[i];
      } else {
        sum += a[i];
      }
    }
  }

  if (sum % 3 == 0) ++ans2;
  printf("%d\n", max(ans, ans2));
  return 0;
}


//Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
const int MAXN = 200000;
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, a[MAXN + 5], k;
char s[MAXN + 5];

void init() {
  scanf("%s", s);
  n = strlen(s);

  for (int i = 0; i < n; ++i) {
    a[i + 1] = s[i] - '0';
    if (a[i + 1] % 3 == 0) ++k;
  //  while (a[i] < '0' || a[i] > '9') a[i] = getchar();
  }
}

int ans = 0;

int main() {
  init();

  int sum = a[1];

  for (int i = 2; i <= n; ++i) {
    if (sum % 3 == 0) {
      ++ans;
      sum = a[i];
    } else {
      sum += a[i];
    }
  }

  if (sum % 3 == 0) ++ans;

  printf("%d\n", max(ans, k));

  return 0;
}


//Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
const int MAXN = 200000;
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, a[MAXN + 5], k;
char s[MAXN + 5];

void init() {
  scanf("%s", s);
  n = strlen(s);

  for (int i = 0; i < n; ++i) {
    a[i + 1] = s[i] - '0';
    if (a[i + 1] % 3 == 0) ++k;
  //  while (a[i] < '0' || a[i] > '9') a[i] = getchar();
  }
}

int ans = 0, ans2 = 0;

int main() {
  init();

  int sum = a[1];

  for (int i = 2; i <= n; ++i) {
    if (sum % 3 == 0) {
      ++ans;
      sum = a[i];
    } else {
      sum += a[i];
    }
  }

  sum = a[n];
  for (int i = n - 1; i; --i) {
    if (sum % 3 == 0) {
      ++ans2;
      sum = a[i];
    } else {
      sum += a[i];
    }
  }

  if (sum % 3 == 0) ++ans2;

  printf("%d\n", max(ans, max(ans2, k)));

  return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define MAXN 200005
using namespace std;

int dp[MAXN];
vector<int> r[3];

int main(){
    char input[MAXN];
    scanf("%s", input);

    int length = strlen(input), res = 0;
    int s = (input[0] - '0');
    dp[0] = ((s % 3) == 0);
    r[s % 3].push_back(0);
    res = dp[0];

    for(int i = 1; i < length; i++){
        s += (input[i] - '0');
        int temp = (3 - (s % 3)) % 3;

        if(r[temp].size() == 0){
            dp[i] = dp[i - 1];
            dp[i] += (((input[i] - '0') % 3) == 0);
        }
        else {
            dp[i] += dp[r[temp].back()];
            if(!(((input[i] - '0') % 3 != 0) && r[temp].back() == (i - 1)))
                dp[i]++;
        }

        r[s % 3].push_back(i);
        res = max(res, dp[i]);
    }
    cout << res << endl;
    /*
    for(int i = 0; i < length; i++)
        cout << dp[i];
    cout << endl;
    */
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define MAXN 200005
using namespace std;

int dp[MAXN];
vector<int> r[3];

int main(){
    char input[MAXN];
    scanf("%s", input);

    int length = strlen(input), res = 0;
    int s = (input[0] - '0');
    dp[0] = ((s % 3) == 0);
    r[s % 3].push_back(0);
    res = dp[0];

    for(int i = 1; i < length; i++){
        s += (input[i] - '0');
        int temp = (3 - (s % 3)) % 3;

        if(r[temp].size() == 0){
            dp[i] = dp[i - 1];
            dp[i] += (((input[i] - '0') % 3) == 0);
        }
        else {
            dp[i] += 1 + dp[r[temp].back()];
        }

        r[s % 3].push_back(i);
        res = max(res, dp[i]);
    }
    cout << res << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#define MAXN 200005

using namespace std;

char input[MAXN];
int dp[MAXN];
vector<int> positions[3];

int main(){
    cin >> input;
    int length = strlen(input), res = 0, s = 0;
    positions[0].push_back(0);

    for(int i = 1; i <= length; i++){
        int digit = input[i - 1] - '0';
        s += digit;
        int n = s % 3;
        if(!digit)
            dp[i] = 1 + dp[i - 1];
        else if(!positions[n].size()){
            dp[i] = dp[i - 1];
        }
        else {
            dp[i] = dp[positions[n].back()] + 1;
        }
        positions[s % 3].push_back(i);
        dp[i] = max(dp[i], dp[i - 1]);
        res = max(res, dp[i]);
    }
    cout << res << endl;
    /*
    cout << input << endl;
    for(int i = 1; i <= length; i++)
        cout << dp[i];
    cout << endl;
    */
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define MAXN 200005
using namespace std;

int dp[MAXN];
vector<int> r[3];

int main(){
    char input[MAXN];
    scanf("%s", input);

    int length = strlen(input), res = 0;
    int s = (input[0] - '0');
    dp[0] = ((s % 3) == 0);
    r[s % 3].push_back(0);
    res = dp[0];

    for(int i = 1; i < length; i++){
        s += (input[i] - '0');
        int temp = (3 - (s % 3)) % 3;

        if(r[temp].size() == 0){
            dp[i] = dp[i - 1];
            dp[i] += (((input[i] - '0') % 3) == 0 || (s % 3) == 0);
        }
        else {
            dp[i] += dp[r[temp].back()];
            if(!(((input[i] - '0') % 3 != 0) && r[temp].back() == (i - 1)))
                dp[i]++;
        }

        r[s % 3].push_back(i);
        res = max(res, dp[i]);
    }
    cout << res << endl;
    /*
    for(int i = 0; i < length; i++)
        cout << dp[i];
    cout << endl;
    */
    return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#define MAXN 200005

using namespace std;

char input[MAXN];
int dp[MAXN];
vector<int> positions[3];

int main(){
    cin >> input;
    int length = strlen(input), res = 0, s = 0;
    positions[0].push_back(0);

    for(int i = 1; i <= length; i++){
        int digit = input[i - 1] - '0';
        s += digit;
        int n = s % 3;
        if(!digit)
            dp[i] = 1 + dp[i - 1];
        else if(!positions[n].size()){
            dp[i] = dp[i - 1];
        }
        else {
            dp[i] = dp[positions[n].back()] + 1;
        }
        positions[s % 3].push_back(i);
        res = max(res, dp[i]);
    }
    cout << res << endl;
    /*
    cout << input << endl;
    for(int i = 1; i <= length; i++)
        cout << dp[i];
    cout << endl;
    */
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define MAXN 200005
using namespace std;

int dp[MAXN];
vector<int> r[3];

int main(){
    char input[MAXN];
    scanf("%s", input);

    int length = strlen(input), res = 0;
    int s = (input[0] - '0');
    dp[0] = ((s % 3) == 0);
    r[s % 3].push_back(0);
    res = dp[0];

    for(int i = 1; i < length; i++){
        s += (input[i] - '0');
        int temp = (3 - (s % 3)) % 3;

        if(r[temp].size() == 0){
            dp[i] = dp[i - 1];
            dp[i] += (((input[i] - '0') % 3) == 0);
        }
        else {
            dp[i] += dp[r[temp].back()];
            if(!((input[i] - '0') % s != 0 && r[temp].back() == (i - 1)))
                dp[i]++;
        }

        r[s % 3].push_back(i);
        res = max(res, dp[i]);
    }
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <map>
#include <utility>
#include <vector>
#include <set>
#include <string>
#include <queue>
using namespace std;

#define ll long long int
#define INF 1000000007
#define INFLL 1000000000000000011LL
#define pb(x) push_back(x)
#define mp make_pair
#define fi first
#define se second
#define vi vector
#define gtl(x) getline(cin, (x))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define setv(x,a) memset(x,a,sizeof(x))
#define ull unsigned long long int

ull PowMod(ull n)
{
    ull ret = 1;
    ull a = 2;
    while (n > 0) {
        if (n & 1) ret = ((ret%INF) * (a%INF)) % INF;
        a = ((a%INF) * (a%INF)) % INF;
        n >>= 1;
    }
    return ret;
}

int gcd(int a, int b) {
            if (a == 0) return b;
            if (b == 0) return a;
            if (a < 0) return gcd(-1 * a, b);
            if (b < 0) return gcd(a, -1 * b);
            if (a > b) return gcd(b, a);
            return gcd(b%a, a);
}

int main() {
    string s;
    cin>>s;

    int left=0;

    int sum=0;
    int i = 0;
    while(i<s.length()) {
        sum = sum + (s[i]-'0');
        if((s[i]-'0')%3==0) {
            left++;
            i++;
            sum = 0;
            continue;
        }
        if(s[i]!='0') {
            if(sum%3==0) {
                left++;
                i++;
            } else i++;
        } else {
            left++;
            sum = 0;
            i++;
        }
    }

    int right =0;
    sum = 0;
    i = s.length()-1;
    while(i>=0) {
        sum = sum + (s[i]-'0');
         if((s[i]-'0')%3==0) {
            right++;
            i-- ;
            sum = 0;
            continue;
        }
        if(s[i]!='0') {
            if(sum%3==0) {
                right++;
                i--;
            } else i--;
        } else {
            right++;
            sum = 0;
            i--;
        }
    }

    int answer = max(left,right);
    cout<<answer<<endl;
}


#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <map>
#include <utility>
#include <vector>
#include <set>
#include <string>
#include <queue>
using namespace std;

#define ll long long int
#define INF 1000000007
#define INFLL 1000000000000000011LL
#define pb(x) push_back(x)
#define mp make_pair
#define fi first
#define se second
#define vi vector
#define gtl(x) getline(cin, (x))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define setv(x,a) memset(x,a,sizeof(x))
#define ull unsigned long long int

ull PowMod(ull n)
{
    ull ret = 1;
    ull a = 2;
    while (n > 0) {
        if (n & 1) ret = ((ret%INF) * (a%INF)) % INF;
        a = ((a%INF) * (a%INF)) % INF;
        n >>= 1;
    }
    return ret;
}

int gcd(int a, int b) {
            if (a == 0) return b;
            if (b == 0) return a;
            if (a < 0) return gcd(-1 * a, b);
            if (b < 0) return gcd(a, -1 * b);
            if (a > b) return gcd(b, a);
            return gcd(b%a, a);
}

int main() {
    string s;
    cin>>s;

    int left=0;

    int sum=0;
    int i = 0;
    int index = 0;
    /*while(i<s.length()) {
        sum = sum + (s[i]-'0');
        if((s[i]-'0')%3==0) {
            left++;
            i++;
            index = i;
            sum = 0;
            continue;
        }
        if(s[i]!='0') {
            if(sum%3==0) {
                left++;
                i++;
                sum = 0;
                index = i;
            } else i++;
        } else {
            left++;
            sum = 0;
            i++;
            index = i;
        }
    }*/

    int count = 0;
    while(i<s.length()) {
        if((s[i]-'0')%3==0) {
            count++;
            i++;
        } else if(i+1<s.length() && ((s[i]+s[i+1]-'0'-'0')%3==0)) {
            count++;
            i = i + 2;
        } else if(i+2<s.length() && (s[i]+s[i+2]+s[i+1]-'0'-'0'-'0')%3==0) {
            count++;
            i = i + 3;
        } else i++;
    }

    cout<<count<<endl;

}