Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    A = lmis()
    l = 1
    for a in A:
        l = lcm(l, a)
    ans = 0
    for a in A:
        ans += l//a
        ans %= N1097
    print(ans)


main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
import math
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    A = lmis()
    l = 1
    for a in A:
        l = lcm(l, a)
    print(sum(l//a for a in A) % N1097)


main()
### BUGGY CODE ###

def max2(p, q):
    e, b = p[0], p[1]
    c, d = q[0], q[1]
    s = list(set([e, b, c, d]))
    s.sort(key = lambda x:a[x])
    return (s[-1], s[-2])

n = int(input())
a = list(map(int, input().split()))
g = [(i, (1<<n)) for i in range(1<<n)]
a+=[0]
res = 0
for i in range(n):
    for j in range(1<<n):
        if (1<<i)&j: g[j] = max2(g[j], g[j^(1<<i)])
ans = []
for i in range(1, 1<<n):
    res = max(res, a[g[i][0]]+a[g[i][1]])
    ans.append(res)
print(*ans, sep = '\n')

### FIXED CODE ###

def max2(p, q):
    e, b = p[0], p[1]
    c, d = q[0], q[1]
    s = list(set([e, b, c, d]))
    m1, m2 = 1<<n, 1<<n
    for i in s:
        if a[m1]<a[i]:
            m2 = m1
            m1 = i
        elif a[m2]<a[i]:
            m2 = i
    return (m1, m2)

n = int(input())
a = list(map(int, input().split()))
g = [(i, (1<<n)) for i in range(1<<n)]
a+=[0]
res = 0
for i in range(n):
    for j in range(1<<n):
        if (1<<i)&j: g[j] = max2(g[j], g[j^(1<<i)])
ans = []
for i in range(1, 1<<n):
    res = max(res, a[g[i][0]]+a[g[i][1]])
    ans.append(res)
print(*ans, sep = '\n')
### BUGGY CODE ###

n, k, q = list(map(int, input().split()))
score_list = [0] * n
a = list(map(int, [input() for i in range(q)]))
 
 
for answer_num in range(q):
  for person_num in range(n):
    if a[answer_num] is not (person_num + 1):
      score_list[person_num] += 1
    
for i in range(n):
  if score_list[i] >= k:
    print("No")
  else:
    print("Yes")
    
      

### FIXED CODE ###

n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

#print(a)

score = [k - q ] * n
#print(score)
for i in range(q):
  score[ a[i]-1 ] += 1
  #print(score)
  
for i in range(n):
  print("Yes" if score[i] > 0 else "No")
### BUGGY CODE ###

s = list(input())
q = int(input())

r = 0
for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    r += 1
  else:
    if tfc[1] == '1':
      if r % 2 == 0:
        s.insert(0, tfc[2])
      else:
        s.append(tfc[2])
    if tfc[1] == '2':
      if r % 2 == 1:
        s.insert(0, tfc[2])
      else:
        s.append(tfc[2])          
if r % 2 == 0:
  for i in s:
      print(i, end='')
else:
  for i in (reversed(s)):
    print(i, end='')

### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())
 
r = 0
for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    r += 1
  else:
    if tfc[1] == '1':
      if r % 2 == 0:
        s.appendleft(tfc[2])
        #s.insert(0, tfc[2])
      else:
        s.append(tfc[2])
    if tfc[1] == '2':
     if r % 2 == 1:
        s.appendleft(tfc[2])
     else:
        s.append(tfc[2])          
if r % 2 == 0:
  for i in s:
      print(i, end='')
else:
  for i in (reversed(s)):
    print(i, end='')
### BUGGY CODE ###

N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = set(A_list)
A_count = sorted([ A_list.count(A) for A in A_index])
A_len = len(A_count)
print(sum([A_count[i] for i in range(A_len - K)]))


### FIXED CODE ###

N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_dict = dict()
for elem in A_list:
    if not elem in A_dict:
        A_dict[elem] = 1
    else:
        A_dict[elem] += 1
total = 0
A_dict = sorted(A_dict.items(), key=lambda x: x[1])
for i in range(len(A_dict) - K):
    total += A_dict[i][1]
print(total)
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
    
n,m,k=map(int,input().split())
uf = UnionFind(n)

ans=[0  for i in range(n)]
for i in range(m):
    x,y=map(int,input().split())
    uf.union(x-1,y-1)
    ans[x-1]-=1
    ans[y-1]-=1
    
for i in range(k):
    x,y=map(int,input().split())
    if uf.same(x-1,y-1):
        ans[x-1]-=1
        ans[y-1]-=1

for i in range(n):
    ans[i]+=len(uf.members(i))-1
print(*ans)

### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def is_same_root(self, x, y):
        return self.find(x) == self.find(y)
 
    def get_group_size(self, x):
        return -self.parents[self.find(x)]
    
    
n,m,k=map(int,input().split())
uf = UnionFind(n)

ans=[0  for i in range(n)]
for i in range(m):
    x,y=map(int,input().split())
    uf.union(x-1,y-1)
    ans[x-1]-=1
    ans[y-1]-=1
    
for i in range(k):
    x,y=map(int,input().split())
    if uf.is_same_root(x-1,y-1):
        ans[x-1]-=1
        ans[y-1]-=1

for i in range(n):
    ans[i]+=uf.get_group_size(i)-1
print(*ans)
### BUGGY CODE ###

import collections,copy
def LI(): return list(map(int,input().split()))
N,Q = LI()
ans = [0]*(N+1)
graph = {i:collections.deque() for i in range(1,N+1)} #1_index
for _ in range(N-1):
    a,b = LI()
    graph[a].append(b)
    graph[b].append(a)
for _ in range(Q):
    p,x = LI()
    ans[p] += x
seen = [-1]*(N+1) #1_index
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]!=-1:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])


### FIXED CODE ###

import collections,copy,sys
def LI(): return list(map(int,sys.stdin.readline().split()))
N,Q = LI()
ans = [0]*(N+1)
graph = [collections.deque() for _ in range(N+1)] #1_index
for _ in range(N-1):
    a,b = LI()
    graph[a].append(b)
    graph[b].append(a)
for _ in range(Q):
    p,x = LI()
    ans[p] += x
seen = [-1]*(N+1) #1_index
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]!=-1:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])
### BUGGY CODE ###

#n,k = map(int,input().split())
#a_L = list(map(int,input().split()))

n = int(input())
ans_L = []
for val in range(1,n+1):
    if n % val ==0:
        x = val
        y = n/val
        ans_L.append(int(x+y-2))

#print(ans_L)
print(min(ans_L))

### FIXED CODE ###

import math


n = int(input())
ans_L = []
d = []
for val in range(int(math.sqrt(n)+1),0,-1):
    if n % val ==0:
        x = val
        y = int(n/val)
        #st = str(x) + "*" +str(y)
        #d.append(st) 
        #ans_L.append(int(x+y-2))
        print(int(x+y-2))
        exit()
#print(d)
#print(ans_L)
#print(min(ans_L))
### BUGGY CODE ###

n,m = map(int, input().split())
a = list(set([int(input()) for _ in range(m)]))

nums = [0]*(n+1)
nums[0] = 1
if 1 not in a: nums[1] = 1

for i in range(2,n+1):
  if i not in a: nums[i] = nums[i-1] + nums[i-2]
print(nums[n]%(10**9+7))

### FIXED CODE ###

n,m = map(int, input().split())
a = set([int(input()) for _ in range(m)])
inf = 1000000007

dp = [0] * (n + 1)
dp[0] = 1
if 1 not in a:
  dp[1] = 1
else:
  dp[1] = 0
  
for i in range(2, n+1):
  if i in a:
    continue
  dp[i] = dp[i - 1] + dp[i - 2]
  dp[i] %= inf
  
print(dp[n])
### BUGGY CODE ###

import bisect
n = int(input())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
cum.append(10**10)
mincost = 10 ** 10
for mid in range(2,n-1):
    ll = bisect.bisect_left(cum[:mid], cum[mid]//2)
    rl = bisect.bisect_left(cum[mid:], cum[mid+1] + (cum[n] - cum[mid+1])//2) + mid
    s = [0] * 4
    lw = abs(2*cum[ll] - cum[mid]) > abs(2*cum[ll-1] - cum[mid])
    rw = abs(2*cum[rl] - cum[mid] - cum[n]) > abs(2*cum[rl-1] - cum[mid] - cum[n])
    sums = [cum[ll - lw], cum[mid] - cum[ll - lw], cum[rl - rw] - cum[mid], cum[n] - cum[rl - rw]]
    mincost = min(mincost, max(sums) - min(sums))
print(mincost)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
llsum = a[0]
lrsum = a[1]
l = [0] * n
l[2] = 1
for mid in range(3, n-1):
    new = a[mid-1]
    lrsum += new
    l[mid] = l[mid-1]
    unk = a[l[mid]]
    while(abs(lrsum - llsum) > abs(lrsum - llsum - 2 * unk)):
        llsum += unk
        lrsum -= unk
        l[mid] += 1
        unk = a[l[mid]]
rrsum = a[n-1]
rlsum = a[n-2]
r = [0] * n
r[n-2] = n-1
for mid in reversed(range(2, n-2)):
    new = a[mid]
    rlsum += new
    r[mid] = r[mid+1]
    unk = a[r[mid] - 1]
    while(abs(rlsum - rrsum) > abs(rlsum - rrsum - 2 * unk)):
        rrsum += unk
        rlsum -= unk
        r[mid] -= 1
        unk = a[r[mid] - 1]
minabs = 10 ** 20
for mid in range(2, n-1):
    c0 = cum[l[mid]]
    c1 = cum[mid]
    c2 = cum[r[mid]]
    sums = (c0, c1 - c0, c2 - c1, cum[n] - c2)
    minabs = min(minabs, max(sums) - min(sums))
print(minabs)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N, Q = map(int, input().split())
link = [[0]*(N+1) for _ in range(N+1)]
for n in range(N-1):
    a, b = map(int, input().split())
    link[a][b] = 1
    link[b][a] = 1
V = [0] * (N+1)
ans = [0] * (N+1)
for q in range(Q):
    p, x = map(int, input().split())
    V[p] += x

def dfs(i, parent, acc):
    V[i] += acc
    for j in range(1,N+1):
        if link[i][j] == 1 and parent!=j:
            dfs(j,i,V[i])
cur = 1
parent = 0
acc = 0

dfs(cur, parent , acc)
V = [str(v) for v in V]
print (" ".join(V[1:]))


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)
### BUGGY CODE ###

def gcd(a, b):
    if b < 0:
        return gcd(a, -b)
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def solve():
    N = int(raw_input())
    xy = [None] * N
    for i in range(N):
        xi, yi = [int(_) for _ in raw_input().split()]
        xy[i] = (xi, yi)
    xy.sort(key = lambda x: x[0])
    pq_set = []
    def AddToPQSet(ele):
        pq, i, j = ele
        # if len(pq_set) == 0 or pq_set[0][0] > pq:
        #     pq_set.insert(0, (pq, set()))
        #     pq_set[0][1].add(i)
        #     pq_set[0][1].add(j)
        added_flag = False
        for ind in range(0, len(pq_set)):
            if pq_set[ind][0] == pq:
                subset_added = False
                for subset in pq_set[ind][1]:
                    if i in subset:
                        subset.add(j)
                        subset_added = True
                    elif j in subset:
                        subset.add(i)
                        subset_added = True
                if not subset_added:
                    tmp_set = set()
                    tmp_set.add(i)
                    tmp_set.add(j)
                    pq_set[ind][1].append(tmp_set)
                added_flag = True
            elif pq_set[ind][0] > pq:
                tmp_set = set()
                tmp_set.add(i)
                tmp_set.add(j)
                pq_set.insert(ind, (pq, [tmp_set]))
                added_flag = True
        if not added_flag:
            tmp_set = set()
            tmp_set.add(i)
            tmp_set.add(j)
            pq_set.append((pq, [tmp_set]))
        # print pq
        # print "i = " + str(i) + ", j = " + str(j)
        # print pq_set

    for i in range(N):
        for j in range(i+1, N):
            p = xy[j][0] - xy[i][0]
            q = xy[j][1] - xy[i][1]
            _gcd = gcd(p,q)
            # print "i = " + str(i) + ", j = " + str(j)
            # print p, q, _gcd
            p = p / _gcd
            q = q / _gcd
            AddToPQSet(((p,q),i,j))

    maxcntpq = 0
    # print pq_set
    for i in range(len(pq_set)):
        if len(pq_set[i][1]) > maxcntpq:
            num_subset = len(pq_set[i][1])
            cnt = 0
            for subset in pq_set[i][1]:
                cnt += len(subset)
            cnt -= num_subset
            if cnt > maxcntpq:
                maxcntpq = cnt
    print N - maxcntpq

if __name__ == '__main__':
    solve()


### FIXED CODE ###


def solve2():
    N = int(raw_input())
    xy = [None] * N
    for i in range(N):
        xi, yi = [int(_) for _ in raw_input().split()]
        xy[i] = (xi, yi)
    if N == 1:
        print N
        return
    xy.sort()
    dist = []
    for i in range(N):
        for j in range(i+1, N):
            p = xy[j][0] - xy[i][0]
            q = xy[j][1] - xy[i][1]
            dist.append((p,q))
    dist.sort()
    max_cnt = 0
    cnt = 1
    save = dist[0]
    for i in range(1, len(dist)):
        if dist[i] == save:
            cnt += 1
        else:
            max_cnt = max(cnt, max_cnt)
            cnt = 1
            save = dist[i]
    max_cnt = max(cnt, max_cnt)
    print N - max_cnt

if __name__ == '__main__':
    solve2()
### BUGGY CODE ###

n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    li, ri = map(int, input().split())
    L.append(li)
    R.append(ri)

ans = 0

for i in range(1, n+1):
    flag = True
    for li, ri in zip(L, R):
        if not (i >= li and i <= ri):
            flag = False
            break
    if flag:
        ans += 1

print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    li, ri = map(int, input().split())
    L.append(li)
    R.append(ri)

# ans = 0

# for i in range(1, n+1):
#     flag = True
#     for li, ri in zip(L, R):
#         if not (i >= li and i <= ri):
#             flag = False
#             break
#     if flag:
#         ans += 1

# print(ans)

ans = min(min(R), n) - min(max(L), n) +1
if ans < 0:
        ans = 0
print(ans)
### BUGGY CODE ###

import bisect
N, M = map(int, input().split())

cities_prefec = {}
data = []
cities = []
years = []

for i in range(M):
    prefec_id, year = map(int, input().split())

    data.append(
        {
            "pref_id": prefec_id,
            "year": year
        }
    )

    if prefec_id in cities_prefec:
        bisect.insort(cities_prefec[prefec_id], year)
    else:
        cities_prefec[prefec_id] = [year]


for d in data:
    p_id = d["pref_id"]
    cn = bisect.bisect_left(cities_prefec[p_id], d["year"]) + 1
    print("{p_id:0>6}{cn:0>6}".format(**locals()))


### FIXED CODE ###

if __name__ == "__main__":
    _, M = map(int, input().split())
    
    outputs = [0 for _ in range(M)]
    cities = {}

    for i in range(M):
        pref, year = map(int, input().split())
        
        if pref not in cities:
            cities[pref] = {}

        cities[pref][year] = i

    for p in cities:
        city_years = list(cities[p].keys())
        city_years.sort()

        for i, cy in enumerate(city_years):
            outputs[cities[p][cy]] = "{:06}{:06}".format(p, i + 1)

    for line in outputs:
        print(line)
### BUGGY CODE ###

from itertools import *
n=range(49994);a=list(n)
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):
 x=int(x)
 if x%2:print(sum(1 for c in p[1:x]if 2+c==x))
 elif x-4:print(sum(1 for a,b in combinations_with_replacement(p[1:x],2)if a+b==x))
 else:print(1)


### FIXED CODE ###

import bisect,sys
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in map(int,sys.stdin):
 if x:print(len([1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]]))
### BUGGY CODE ###

import re
S = input()
s = [S]
count = 0
while True:
#    s = re.subn('ABCBC','BCABC',s[0])
#    count += s[1]
#    s = re.subn('AABC','ABCA',s[0])
#    count += s[1]
    s = re.subn('ABC','BCA',s[0])
    if s[1]:
        count += s[1]
    else:
        break
print(str(count))

### FIXED CODE ###

import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)
 
count = 0
for l in S_li:
    a = sum([i for i,x in enumerate(l) if '1' in x])
    su=sum([x for x in range(l.count('1'))])
    count += (a-su)
print(str(count))
### BUGGY CODE ###

mod = 1000000007

# nの素因数分解


def prime(n):
    d = []
    i = 2
    while n != 1:
        s = 0
        while n % i == 0:
            n /= i
            s += 1
        d.append(s)
        i += 1
    return d


# xのn乗を計算する
def mod_pow(x, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        half = int(n / 2)
        half_x = mod_pow(x, half)
        return half_x * half_x % mod
    else:
        return x * mod_pow(x, n - 1) % mod


def nCr(n, r):
    x = 1
    r = min(r, n - r)
    for i in range(r):
        x *= n - i
        x %= mod
        x *= mod_pow(i + 1, mod - 2)
        x %= mod
    return x


def solve():
    N, M = map(int, input().split())
    p = prime(M)
    s = 1
    for i in p:
        s *= nCr(i + N - 1, N - 1)
        s %= mod
    print(s)


solve()

### FIXED CODE ###

from collections import Counter

mod = 1000000007

# nの素因数分解

def prime(n):
    d = Counter()
    i = 2
    while i*i <= n:
        while n%i == 0:
            n //= i
            d[i] += 1
        i += 1
    if n > 1:
        d[n] += 1
    return d

# xのn乗を計算する
def mod_pow(x, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        half_x = mod_pow(x, n // 2)
        return half_x * half_x % mod
    else:
        return x * mod_pow(x, n-1) % mod

fact = [1] * 100100
inv = [1] * 100100
for k in range(1, 100100):
    fact[k] = fact[k-1] * k % mod
    inv[k] = mod_pow(fact[k], mod-2)

def nCr(n, r):
    return fact[n] * inv[r] % mod * inv[n-r] % mod

def solve():
    N, M = map(int, input().split())
    p = prime(M)
    s = 1
    for i in p.values():
        s *= nCr(i + N - 1, N - 1)
        s %= mod
    print(s)

solve()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, Q = MAP()
S = input().rstrip()
LR = [MAP() for _ in range(Q)]

loc = [0]*N
for i in range(N-1):
	if S[i]+S[i+1] == 'AC': loc[i] = 1
#print(loc)

for l, r in LR:
	print(sum(loc[l-1:r-1]))

### FIXED CODE ###

import sys
import time
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, Q = MAP()
S = input().rstrip()
LR = [MAP() for _ in range(Q)]

loc = [0]*N
for i in range(N-1):
	if S[i]+S[i+1] == 'AC':
		loc[i+1] += loc[i]+1
	else:
		loc[i+1] = loc[i]
#print(loc)

for l, r in LR:
	print(loc[r-1]-loc[l-1])
### BUGGY CODE ###

from itertools import product
from collections import deque

def state_brute_force(state, count):
    state_list = [state for _ in range(count)]
    for s in product(*state_list):
        yield s


N, K = map(int, input().split())
D = list(map(int, input().split()))

ans = 0

pop_l = deque.popleft
pop_r = deque.pop
add_l = deque.appendleft
add_r = deque.append

stop_condition = sum([item for item in D if item > 0])

for cmb in state_brute_force([pop_l, pop_r, add_l, add_r], K):
    q = deque(D)
    now = []
    value = 0
    for operation in cmb:
        if operation == add_l or operation == add_r:
            if len(now) == 0:
                break
            item = min(now)
            now.remove(item)
            operation(q, item)
        if operation == pop_l or operation == pop_r:
            if len(q) == 0:
                break
            now.append(operation(q))
        value = max(value, sum(now))
    ans = max(ans, value)
    if ans == stop_condition:
        break

print(ans)




### FIXED CODE ###

N, K = map(int, input().split())
D = list(map(int, input().split()))

ans = 0

for left in range(K + 1):
    for right in range(K - left + 1):
        if left + right > N:
            break
        items = list(D[0:left])
        items.extend(D[::-1][0:right])
        dis = K - (left + right)
        i = 0
        items = sorted(items, reverse=True)
        while True:
            ans = max(ans, sum(items))
            if i < dis and len(items) > 0:
                i += 1
                items.pop()
                continue
            else:
                break

print(ans)