CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, X: "List[int]"):
    ans = INF
    for i in range(1, 101):
        t = 0
        for j in range(N):
            t += (X[j]-i)**2

        ans = min(ans, t)

    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, X: "List[int]"):
    ans = INF
    for i in range(1, 101):
        cost = sum([(i-X[j])**2 for j in range(N)])
        ans = min(ans, cost)

    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()
# Original solution
from sys import stdin


def main():
    n = int(stdin.readline())
    x = list(map(int, stdin.readline().split()))

    p = sum(x) / n

    p1 = int(p)
    p2 = int(p + 1)

    s1 = 0
    s2 = 0

    for xi in x:
        s1 += (xi - p1) ** 2
        s2 += (xi - p2) ** 2

    print((min(s1, s2)))


if __name__ == "__main__":
    main()

# Optimized solution
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(eval(input()))
    x = list(map(int, input().split()))
    sum = 0
    for xi in x:
        sum += xi
    ans_1 = sum // n
    ans_2 = sum // n + 1
    score_1 = 0
    score_2 = 0
    for xi in x:
        score_1 += (xi - ans_1) ** 2
        score_2 += (xi - ans_2) ** 2
    print((min(score_1, score_2)))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
# Original solution
n = int(eval(input()))
x = list(map(int,input().split()))
mint = 0
x.sort()
mid = int((x[0]+x[-1])/2)

def kyori(p):
  m = 0
  for i in range(n):
    m += (p-x[i])**2
  return m
while True:
  midplus = mid - 1
  midminus = mid + 1
  if kyori(mid) > kyori(midplus):
    mid = int((mid+midplus)/2)
  elif kyori(mid) > kyori(midminus):
    mid = int((mid+midminus)/2)
  else:
    break
print((kyori(mid)))

# Optimized solution
n = int(eval(input()))
x = list(map(int,input().split()))
k = []
def kyori(p):
  m = 0
  for i in range(n):
    m += (p-x[i])**2
  return m
for i in range(1,101):
  k.append(kyori(i))

print((min(k)))
# Original solution
N = int(eval(input()))
x = list(map(int,input().split()))

l=[]

for p in range(1,101):
  sum=0
  
  for i in range(N):
    sum += (x[i]-p)**2
  
  l.append(sum)
  
print((sorted(l)[0]))

# Optimized solution
#!/usr/bin/env python3

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

INF = pow(10,6)

# @njit
def solve(n,a):
  res = INF
  for i in range(1,101):
    res = min(res,sum(pow(i-x,2) for x in a))
  return res



def main():
  N = int(eval(input()))
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print((solve(N,a)))
  return

if __name__ == '__main__':
  main()
# Original solution
N = int(eval(input()))
s = list(map(int, input().split()))

m = s[0]
M = s[N-1]

lis = []
ans = 0

for i in range(1000):
  for j in range(N):
  	ans += (s[j] - i) ** 2
  lis.append(ans)
  ans = 0
  
print((min(lis)))

# Optimized solution
N = int(eval(input()))
s = list(map(int, input().split()))

m = min(s)
M = max(s)

lis = []
ans = 0

for i in range(m,M + 1):
  for j in range(N):
  	ans += (s[j] - i) ** 2
  lis.append(ans)
  ans = 0
  
print((min(lis)))
# Original solution
#!/usr/bin/env python3
n = int(eval(input()))
x = list(map(int,input().split()))
ans = 10**6
for i in range(1,101):
  k = 0
  for j in range(n):
    k += (x[j]-i) **2
  ans = min(ans,k)
print(ans)

# Optimized solution
#!/usr/bin/env python3
n = int(eval(input()))
x = list(map(int,input().split()))
print((sum((i-round(sum(x)/n))**2 for i in x)))
#x**2 - 2*x + p**2 をp で微分するとp 位置を動かしたときの増加量がわかる
# ２次方程式になっていて minは重心のとき round すれば良い
# Original solution
N = int(eval(input()))
X = list(map(int,input().split()))

ans=10**10
for i in range(2*10**5):
  tmp=0
  for x in X:
    tmp += (i - x)**2
  
  if ans>=tmp:
    ans=tmp

print(ans)

# Optimized solution
N = int(eval(input()))
X = list(map(int,input().split()))
 
ans=10**10
for i in range(0,101):
  tmp=0
  for x in X:
    tmp += (i - x)**2
  
  if ans>=tmp:
    ans=tmp
 
print(ans)
# Original solution
N=int(eval(input()))
X=list(map(int, input().split()))

ans=10**10

for i in range(100):
    p=i+1
    temp=0
    for j in range(N):
        temp+=(X[j]-p)**2
        
    ans=min(ans,temp)
    
print(ans)

# Optimized solution
import sys
input = sys.stdin.readline

def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    X=LI()
    
    ans=10**10
    
    for i in range(1,101):
        temp=0
        for j in range(N):
            temp+=abs(i-X[j])**2
        ans=min(ans,temp)
        
    print(ans)
        

main()
# Original solution
n = int(eval(input()))
x = list(map(int, input().split()))

avg = round(sum(x) / n)

ans = 0

for i in x:
    ans += (i - avg) ** 2

print(ans)

# Optimized solution
if __name__ == '__main__':
    n = int(eval(input()))
    x = list(map(int, input().split()))
    p = round(sum(x) / n)
    ans = 0
    for i in x:
        ans += (i - p) ** 2
    print(ans)
# Original solution
n = int(eval(input()))
X = list(map(int, input().split()))
ans = 1000000000
for p in range(1,101):
    s = 0
    for x in X:
        s += (x-p)**2
    ans = min(ans, s)
print(ans)

# Optimized solution
n,*X = list(map(int, open(0).read().split()))
p = round(sum(X)/n)
print((sum((x-p)**2 for x in X)))
# Original solution
n = int(eval(input()))
x = [int(i) for i in input().split()]
p = 10000000
for i in range(100):
    pi = 0
    for j in range(n):
        pi += (x[j] - (i + 1))**2
    if pi < p:
        p = pi
    # else:
    #     break
        # p[i] += (x[j]-(i+1))**2
print(p)

# Optimized solution
n = int(eval(input()))
x = [int(i) for i in input().split()]
p = 10000000
for i in range(100):
    pi = 0
    for j in range(n):
        pi += (x[j] - (i + 1))**2
    if pi < p:
        p = pi
    else:
        break
        # p[i] += (x[j]-(i+1))**2
print(p)
# Original solution
def main():
    n = int(eval(input()))
    *xs, = list(map(int, input().split()))

    ret = float('inf')
    for p in range(100 + 1):
        t = 0
        for x in xs:
            t += (p - x) ** 2
        ret = min(ret, t)
    print(ret)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


# Optimized solution
n = int(eval(input()))
xs = tuple(map(int, input().split()))

ret = min(
    sum(
        (x - p) * (x - p)
        for x in xs
    ) for p in range(1, 100 + 1)
)

print(ret)
# Original solution
N=int(eval(input()))
X=list(map(int,input().split()))

ans=float('inf')
for i in range(1,101):
    res=0
    for x in X:
        res+=(i-x)**2
    if ans>res:
        ans=res
print(ans)

# Optimized solution
N=int(eval(input()))
X=list(map(int,input().split()))
X.sort()

ans=float('inf')
for p in range(1,101):
    buf=0
    for x in X:
        buf+=(x-p)**2
    ans=min(ans,buf)

print(ans)
# Original solution
def calc(s,t):
       return (t-s)**2

n=int(eval(input()))
X=sorted(list(map(int,input().split())))
inf=float("inf")

ans=inf
for i in range(X[0],X[-1]+1):
       u=0
       for j in X:
              u+=calc(i,j)
       ans=min(ans,u)
print(ans)

# Optimized solution
n=int(eval(input()))
X=list(map(int,input().split()))

s=float("inf")
for i in range(min(X),max(X)+1):
   d=0
   for j in X:
      d+=(j-i)**2
   s=min(s,d)
print(s)
# Original solution
n=int(eval(input()))
x=list(map(int,input().split()))

x.sort()

for p in range(x[0],x[len(x)-1]+1):
    psum=0
    for i in range(len(x)):
        psum=psum+(x[0]-x[i])**2
#    print(psum)
    pmin=psum    
    for j in range(x[0]+1,x[len(x)-1]):
        psum=0
        for i in range(len(x)):
            psum=psum+(j-x[i])**2
#        print(psum)
        if pmin>psum:
            pmin=psum
print(pmin)    

# Optimized solution
n=int(eval(input()))
x=list(map(int,input().split()))

x.sort()

psum=0
for i in range(len(x)):
    psum=psum+(x[0]-x[i])**2
#    print(psum)
pmin=psum    
for j in range(x[0]+1,x[len(x)-1]):
    psum=0
    for i in range(len(x)):
        psum=psum+(j-x[i])**2
#        print(psum)
    if pmin>psum:
        pmin=psum
print(pmin)
# Original solution
_,*X=list(map(int,open(0).read().split()));print((min([sum((x-p)**2 for x in X) for p in range(min(X),max(X)+1)])))

# Optimized solution
_ = int(eval(input()))
*X, = list(map(int, input().split()))
print((
    min(
        [sum([(x - p) ** 2 for x in X]) for p in range(min(X), max(X)+1)]
    )
))
# Original solution
def readinput():
    n=int(eval(input()))
    x=list(map(int,input().split()))
    return n,x

def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main2(n,x)
    print(ans)

# Optimized solution
def readinput():
    n=int(eval(input()))
    x=list(map(int,input().split()))
    return n,x

def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main(n,x)
    print(ans)
# Original solution
import math

n = int(eval(input()))
x = list(map(int, input().split()))
p = sum(x) / len(x)

a1 = sum([(a - math.floor(p)) * (a - math.floor(p)) for a in x])
a2 = sum([(a - math.ceil(p)) * (a - math.ceil(p)) for a in x])
print((min(a1, a2)))

# Optimized solution
import math
n = int(eval(input()))
xs = list(map(int, input().split()))

p = sum(xs) / len(xs)
x1 = sum([(x - math.floor(p)) ** 2 for x in xs])
x2 = sum([(x - math.ceil(p)) ** 2  for x in xs])
print((min(x1, x2)))
# Original solution
import math
N = int(eval(input()))
X = list(map(int,input().split()))
medf = math.floor(sum(X)/N)
medc = math.ceil(sum(X)/N)
cf = 0
cc = 0
for i in range(N):
  cf += (X[i] - medf)**2
  cc += (X[i] - medc)**2
print((min(cf,cc)))

# Optimized solution
import math
N = int(eval(input()))
X = list(map(int,input().split()))
med = int(sum(X)/N + 0.5)
c = 0
for i in range(N):
  c += (X[i] - med)**2
print(c)
# Original solution
N = int(eval(input()))
l = list(map(int, input().split()))
k = []
for j in range(101):
  ans=0
  for i in range(N):
    ans += (l[i] - j)**2
  k.append(ans)
print((min(k)))

# Optimized solution
N = int(eval(input()))
l = list(map(int,input().split()))
s = []
for i in range(101):
  x = 0
  for j in l:
    x += (j-i)**2
  s.append(x)
print((min(s)))
# Original solution
N = int(eval(input()))
X = list(map(int,input().split()))
cmin = 10**6
for i in range(1,101):
    cnt = 0
    for j in range(N):
        cnt += (i-X[j])**2
    cmin = min(cmin,cnt)
print(cmin)

# Optimized solution
N = int(eval(input()))
X = list(map(int,input().split()))
cmin = 10**6+10
for i in range(101):
    cnt = 0
    for j in range(N):
        cnt += (i-X[j])**2
    cmin = min(cmin,cnt)
print(cmin)
# Original solution
N = int(eval(input()))
X = list(map(int, input().split()))

res = float('inf')

for i in range(-100, 101):
    tmp = 0
    for x in X:
        tmp += (i - x) ** 2

    res = min(tmp, res)

print(res)

# Optimized solution
N = int(eval(input()))
X = list(map(int, input().split()))

res = float('inf')

for i in range(min(X), max(X)+1):
    tmp = 0
    for x in X:
        tmp += (i - x) ** 2

    res = min(tmp, res)

print(res)
# Original solution
N = int(eval(input()))
X = list(map(int, input().split()))
al = []
for i in range(100):
  d = 0
  p = i+1
  for j in range(N):
    d += (X[j]-p)**2
  al.append(d)

print((min(al)))

# Optimized solution
N = int(eval(input()))
X = list(map(int, input().split()))
X = sorted(X)
avg = sum(X)//N
aa = []
for i in range(2):
  avg = avg + i
  a = 0
  for j in range(N):
    a += (X[j] - avg)**2
  aa.append(a)
print((min(aa)))
# Original solution
n = int(eval(input()))
X = list(map(int, input().split()))
for p in range(max(X)+100):
    sum = 0
    for x in X:
        sum += ((x - p)**2)
    if p == 0:
        ans = sum
    if ans > sum:
        ans = sum
print(ans)

# Optimized solution
n = int(eval(input()))
X = list(map(int, input().split()))
for p in range(max(X)+1):
    sum = 0
    for x in X:
        sum += ((x - p)**2)
    if p == 0:
        ans = sum
    if ans > sum:
        ans = sum
print(ans)
# Original solution
n = int(eval(input()))
x = list(map(int,input().split()))
x.sort()
Sum = 0
Min = 9999999999
for i in range(100):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)




# Optimized solution
n = int(eval(input()))
x = list(map(int,input().split()))
x.sort()
Sum = 0
Min = float("inf")
for i in range(100):
    Sum = 0
    for j in x:
        Sum += (j - i)**2
    if Sum < Min:
        Min = Sum
print(Min)
# Original solution
N = int(eval(input()))

X = list(map(int,input().split()))

add = []

for p in range(99999):
    psum = 0
    for i in range(N):
        power = (X[i] - p)**2
        psum = psum + power
        i = i + 1
    add.append(psum)
    
print((min(add)))

# Optimized solution
N = int(eval(input()))

X = list(map(int,input().split()))

add = []

for p in range(1000):
    psum = 0
    for i in range(N):
        power = (X[i] - p)**2
        psum = psum + power
        i = i + 1
    add.append(psum)
    
print((min(add)))
# Original solution
N = int(eval(input()))
X = list(map(int, input().split()))

p_min = min(X)
p_max = max(X)

ans = p_min
cost_min = N * p_max ** 2
for p in range(p_min, p_max + 1):
  tmp_cost = sum([(x - p) ** 2 for x in X])
  if tmp_cost < cost_min:
    ans = p
    cost_min = tmp_cost
    
print(cost_min)

# Optimized solution
N = int(eval(input()))
X = list(map(int, input().split()))

avg_p = int(sum(X) / N)

cost_l = sum([(x - avg_p)**2 for x in X])
cost_r = sum([(x - avg_p - 1)**2 for x in X])

print((min(cost_l, cost_r)))
# Original solution
n = int(eval(input()))
x = list(map(int, input().split()))
print((sum((i-round(sum(x)/n))**2 for i in x)))

# Optimized solution
eval(input())
x=list(map(int,input().split()))
print((sum((i-round(sum(x)/len(x)))**2 for i in x)))
# Original solution
N = int(eval(input()))
X = list(map(int, input().split()))
X = list(sorted(X))
if N == 1:
  print((0))
  exit()
ans = float('inf')
for p in range(X[0], X[N - 1] + 1):
  sum = 0
  for x in X:
    sum += (x - p) ** 2
  ans = min(sum, ans)
print(ans)

# Optimized solution
N = int(eval(input()))
X = list(map(int, input().split()))
avg = round(sum(X) / N)
print((sum([(x - avg) ** 2 for x in X])))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
answer = 10 ** 9
for i in range(1,101):
    tmp = 0
    for a in A:
        tmp += abs(a-i) ** 2
    answer = min(answer,tmp)
print(answer)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
chushin = sum(A)//N
chushin_1 = sum(A)//N +1
answer = 0
answer_1 = 0
for a in A:
    answer += abs(a-chushin) ** 2
    answer_1 += abs(a-chushin_1) ** 2
print((min(answer,answer_1)))
# Original solution
#!/use/bin/env python3

from collections import defaultdict

n = int(eval(input()))
x_n = [int(s) for s in input().split()]

s = sorted(x_n)

ans = 1e18
for p in range(1, 101):
    l = sum([pow(x - p, 2) for x in s])

    if l < ans:
        ans = l

print(ans)

# Optimized solution
#!/use/bin/env python3

from collections import defaultdict

n = int(eval(input()))
x_n = [int(s) for s in input().split()]

s = sorted(x_n)

ans = 1e18
for p in range(s[0], s[-1] + 1):
    l = sum([pow(x - p, 2) for x in s])

    if l < ans:
        ans = l

print(ans)
# Original solution
N = int(eval(input()))
X = list(map(int, input().split()))
sav = float("inf")
for i in range(min(X), max(X)+1):
    Xe = [abs(x-i)**2 for x in X]
    health = sum(Xe)
    if sav > health:
        sav = health

print(sav)


# Optimized solution
N = int(eval(input()))
X = list(map(int, input().split()))
xp = round(sum(X) / N)
Xe = [abs(x - xp) ** 2 for x in X]
print((sum(Xe)))
# Original solution
N = int(eval(input()))
Xlist = list(map(int, input().split()))
ans = 10**9+7
for i in range(1, 101):
    p = 0
    for x in Xlist:
        p += (x-i)**2
    ans = min(ans, p)
print(ans)

# Optimized solution
N = int(eval(input()))
Xlist = list(map(int, input().split()))
ans = 10**9
for p in range(min(Xlist), max(Xlist)+1):
    cost = 0
    for x in Xlist:
        cost += (x - p)**2
    ans = min(ans, cost)
print(ans)
# Original solution
n = int(eval(input()))
x = sorted(list(map(int,input().split())))

z = sum(x)//n
z2 = z + 1
ans1 = 0
ans2 = 0
for i in range(n):
	ans1 += (x[i] - z)**2
for i in range(n):
	ans2 += (x[i] - z2)**2
	
print((min(ans1,ans2)))


# Optimized solution
n = int(eval(input()))
x = list(map(int,input().split()))

point = sum(x)//n
sum1 = 0;sum2 = 0
for i in range(n):
    sum1 += (point - x[i])**2
    sum2 += (point+1 - x[i])**2
print((min(sum1,sum2)))
# Original solution
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return eval(input())

n = I()
x = LI()

mx = max(x)
mn = min(x)

ans = inf
for i in range(mn,mx+1):
    tmp = 0
    for j in x:
        tmp+=(j-i)**2
    ans = min(ans,tmp)
print(ans)

# Optimized solution
n = int(eval(input()))
x = list(map(int,input().split()))

ans = 10**9+7
for i in range(min(x),max(x)+1):
    tmp=0
    for j in x:
        tmp+=(i-j)**2
    ans = min(ans,tmp)
print(ans)
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))

ans=float("inf")
for i in range(1,101):
  ans=min(ans,sum([(c-i)**2 for c in l]))
print(ans)

# Optimized solution
import sys
input=sys.stdin.readline
n=int(eval(input()))
l=list(map(int,input().split()))
d=sum(l)//n
def dis(x):
    global l;ret=0
    for i in l:
        ret+=(x-i)**2

    return ret
print((min(dis(d),dis(d+1))))
# Original solution
N = int(eval(input()))
X = list(map(int, input().split()))

m = min(X)
M = max(X)

cost = [1000000009 for _ in range(101)]
for p in range(1,101):
    c = 0
    for x in X:
        c += (x-p)**2
    cost[p] = c

print((min(cost)))

# Optimized solution
N = int(eval(input()))
X = list(map(int, input().split()))

m = min(X)
M = max(X)

min_val = 100 * 100 * 100
for p in range(m, M+1):
    score = 0
    for x in X:
         score += (x-p)*(x-p)
    if score < min_val: min_val = score
print(min_val)
# Original solution
n,*a=list(map(int,open(0).read().split()))
b=10**8
for i in range(1,101):
    b=min(b,sum((j-i)**2 for j in a))
print(b)   

# Optimized solution
n,*a=list(map(int,open(0).read().split()));print((sum((round(sum(a)/n)-i)**2 for i in a)))
# Original solution
s = list(input())
q = int(input())
for i in range(q):
    cmd = [s for s in input().split()]
    cmd[1] = int(cmd[1])
    cmd[2] = int(cmd[2])
    if cmd[0] == "replace":
        c = list(cmd[3])
        h = 0
        for j in range(cmd[1], cmd[2]+1):
            s[j] = c[h]
            h+=1
    elif cmd[0] == "reverse":
        k = cmd[1]
        l = cmd[2]
        while k < l:
            t = s[k]
            s[k] = s[l]
            s[l] = t
            k+=1
            l-=1
    else:
        for m in range(cmd[1], cmd[2]+1):
            print("{}".format(s[m]), end = "")

        print()
        


# Optimized solution
str = [w for w in input()]
q = int(input())
for i in range(q):
    command = [w for w in input().split()]
    command[1] = int(command[1])
    command[2] = int(command[2])
    if command[0] == "print":
        for i in range(command[1], command[2]+1):
            print(str[i], end="")
        print()
    if command[0] == "replace":
        j = command[1]
        for i in range(len(command[3])):
            str[j] = command[3][i]
            j += 1
    if command[0] == "reverse":
        r = []
        for i in range(command[2], command[1]-1, -1):
            r.append(str[i])
        i = command[1]
        for w in r:
            str[i] = w
            i += 1
# Original solution
# -*- coding: utf-8 -*-
str = input()
for _ in range(eval(input())):
 ops = input().split()
 na = int(ops[1])
 nb = int(ops[2]) + 1
 op = ops[0]
 if op[0]=="p": print(str[na:nb])
 elif op[2]=="v": str = str[:na] + "".join(reversed(str[na:nb])) + str[nb:]
 else: str = str[:na] + ops[3] + str[nb:]

# Optimized solution
# -*- coding: utf-8 -*-
str = input()
for _ in range(eval(input())):
 ops = input().split()
 na = int(ops[1])
 nb = int(ops[2]) + 1
 op = ops[0]
 if op[0]=="p": print(str[na:nb])
 elif op[2]=="v":
  t = str[na:nb]
  str = str[:na] + t[::-1] + str[nb:]
 else: str = str[:na] + ops[3] + str[nb:]
# Original solution
h, w, n = list(map(int,input().split()))
from collections import defaultdict
m3x3 =defaultdict(list)
for _ in range(n):
    a, b = list(map(int,input().split()))
    for i in range(max(0, a - 3),min(h - 2, a)):
        for j in range(max(0, b - 3),min(w - 2, b)):
            if (i,j) in  m3x3:
                m3x3[(i,j)] +=1
            else:
                m3x3[(i,j)] =1
v = list(m3x3.values())
k = list(m3x3.keys())
print(((w-2)*(h-2)-len(k)))
for j in range(1,10):
    print((v.count(j)))


# Optimized solution
from collections import defaultdict
import sys
h, w, n = list(map(int,sys.stdin.readline().rstrip().split()))

m3x3 =defaultdict(list)
for _ in range(n):
    a, b = list(map(int,sys.stdin.readline().rstrip().split()))
    for i in range(max(0, a - 3),min(h - 2, a)):
        for j in range(max(0, b - 3),min(w - 2, b)):
            if (i,j) in  m3x3:
                m3x3[(i,j)] +=1
            else:
                m3x3[(i,j)] =1
v = list(m3x3.values())
k = list(m3x3.keys())
print(((w-2)*(h-2)-len(k)))
for j in range(1,10):
    print((v.count(j)))