Harryxun/stf_run huggingface dataset:
N,M = map(int,input().split())
A = [input() for _ in [0]*N]
B = [input() for _ in [0]*M]
endFlg = False
for i in range(N-M):
    for j in range(N-M):
        breakFlg = False
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    breakFlg = True
                    break
        if breakFlg: break
        pass
        else: endFlg = True
    if endFlg: break
if endFlg:print("Yes")
else:print("No")

### FIXED CODE ###

N,M = map(int,input().split())
A = [input() for _ in [0]*N]
B = [input() for _ in [0]*M]
endFlg = False
for i in range(N-M+1):
    for j in range(N-M+1):
        breakFlg = False
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    breakFlg = True
                    break
            if breakFlg:break
        else:endFlg=True
        if endFlg: break
    if endFlg: break
if endFlg:print("Yes")
else:print("No")
N , M = [int(n) for n in input().split(' ')]

list_AC =[]
list_WAcount = [0] * N
sumWA = 0

for i in range(M):
    p , S = input().split(' ')
    
    if (p in list_AC):
        # 既にAC済みの場合は何もしない
        continue 
    else:
        # 最初に正解したときにそれまでのWA回数を加算
        if S == 'AC':
            list_AC.append(p)
            sumWA += list_WAcount[p-1]
        else:
            list_WAcount[p-1] += 1

print("{} {}".format(len(list_AC),sumWA))

### FIXED CODE ###


N , M = [int(n) for n in input().split(' ')]

list_AC = [0] * N
list_WAcount = [0] * N
sumAC = 0
sumWA = 0

for i in range(M):
    sp , S = input().split(' ')
    p = int(sp)
    
    if (list_AC[p-1] != 0):
        # 既にAC済みの場合は何もしない
        continue 
    else:
        # 最初に正解したときにそれまでのWA回数を加算
        if S == 'AC':
            sumAC += 1
            list_AC[p-1] = 1
            sumWA += list_WAcount[p-1]
        else:
            list_WAcount[p-1] += 1

print("{} {}".format(sumAC,sumWA))
n,k=map(int,input().split())
for i in range(n):
  s=list(map(int,input().split()))
s[k].lower()
for i in range(n):
  print(s[i],end="")

### FIXED CODE ###

n,k=map(int,input().split())
s=input()
print(s[0:k-1]+s[k-1].lower()+s[k:])
from math import gcd

K=int(input())
sum=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum += gcd(i,j,k)
      
print(sum)

### FIXED CODE ###

from math import gcd

K=int(input())
sum=0

for i in range(1,K+1):
  for j in range(1,K+1):
    tmp= gcd(i,j)
    for k in range(1,K+1):      
      sum += gcd(tmp,k)
      
print(sum)
n=int(input())
a=list(map(int,input().split()))
a.sort()
negative=[]
positive=[]
for ele in a:
    if ele<0:
        negative.append(ele)
    else:
        positive.append(ele)
if len(negative)==0:
    print(sum(a))
else:
    if len(negative)%2==0:
        print(-sum(negative)+sum(positive))
    else:
        if -negative[-1]>positive[0]:
            print(-sum(negative)+sum(positive[1:])-positive[0])
        else:
            print(-sum(negative[:-1])+sum(positive)+negative[-1])


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
negative=[]
positive=[]
for ele in a:
    if ele<0:
        negative.append(ele)
    else:
        positive.append(ele)
if len(negative)==0:
    print(sum(a))
else:
    if len(negative)%2==0:
        print(-sum(negative)+sum(positive))
    else:
        if len(positive)==0:
            print(-sum(negative)+2*negative[-1])
        elif -negative[-1]>positive[0]:
            print(-sum(negative)+sum(positive[1:])-positive[0])
        else:
            print(-sum(negative[:-1])+sum(positive)+negative[-1])
x = int(input())
c = 1
for b in range(2,x):
  for p in range(2,x):
    if b**p <= x:
      c = max(c,b**P)
    else:
      break
print(c)

### FIXED CODE ###

x = int(input())
c = 1
for b in range(2,x):
  for p in range(2,x):
    if b**p <= x:
      c = max(c,b**p)
    else:
      break
print(c)
import sys
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))


def a():
	n = int(inp()); arr = read()
	dic = {}
	def func(arr, n):
		if n == 1:
			dic[n] = abs(arr[n]-arr[n-1])
			return(abs(arr[n]-arr[n-1]))
		if n== 0:
			return(0)
		if n in dic:
			return(dic[n])
		min_path = min(abs(arr[n]-arr[n-1])+func(arr,n-1), abs(arr[n]-arr[n-2])+func(arr,n-2))
		dic[n] = min_path
		return(min_path) 


	print(func(arr, n-1))
	print(dic)




if __name__ == "__main__":
	a()

### FIXED CODE ###

import sys
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))


def a():
	n = int(inp()); arr = read()
	dp = [0 for i in range(n)]
	dp[0] = 0
	dp[1] = abs(arr[1]-arr[0])
	for i in range(2, n):
		dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]))
	print(dp[n-1])




if __name__ == "__main__":
	a()
n = input()
x,y = map(int,input().split())
y = y/2
ans = x + y
print(ans)



### FIXED CODE ###

x,y = map(int,input().split())
y = y/2
ans = x + y
print(int(ans))
a = int(input())
b = int(input())
print(max(a - b * 2, 0))

### FIXED CODE ###

a, b = map(int, input().split())
print(max(a - b * 2, 0))
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1

dist = []
for i in range(n):
    dist.append([110110] * n)

def dfs(now, s):
    if now != 0:
        if dist[s][now] + 1 < dist[s][now-1]:
            dist[s][now-1] = dist[s][now] + 1
            dfs(now-1, s)
    if now != n-1:
        if dist[s][now] + 1 < dist[s][now+1]:
            dist[s][now+1] = dist[s][now] + 1
            dfs(now+1, s)
    if now == x:
        if dist[s][now] + 1 < dist[s][y]:
            dist[s][y] = dist[s][now] + 1
            dfs(y, s)
    if now == y:
        if dist[s][now] + 1 < dist[s][x]:
            dist[s][x] = dist[s][now] + 1
            dfs(x, s)

cnt = [0] * n

for i in range(n):
    dist[i][i] = 0
    dfs(i, i)

for i in range(n):
    for j in range(n):
        cnt[dist[i][j]] += 1
        
for i in range(1, n):
    print(cnt[i] // 2)


### FIXED CODE ###

n, x, y = list(map(int, input().split()))
x -= 1
y -= 1

cnt = [0] * n

dist = []
for i in range(n):
    dist.append([-1] * n)
for i in range(n):
    dist[i][x] = abs(i-x)
    dist[i][y] = abs(i-y)
    dist[x][i] = abs(i-x)
    dist[y][i] = abs(i-y)

for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        dis = min(j - i, dist[j][y] + 1 + dist[i][x], dist[j][x] + 1 + dist[i][y])
        cnt[dis] += 1
for i in range(1, n):
    print(cnt[i])
N,A,B = map(int,input().split())

Blue='b'*A
Red='r'*B
BlueRed=Blue+Red
ans = ''
time = (N // len(BlueRed))+1
ans= BlueRed*time
ans2=ans[:N]
print(ans2.count('b'))

### FIXED CODE ###

N,A,B = map(int,input().split())

ans = N // (A+B) * A
rem = N % (A+B)
ans += min(rem,A)

print(ans)
INPUT = list(map(int, input().split()))
head, tail, n, quantum = 0, len(processes), INPUT[0], INPUT[1]
processes = [input().split() for _ in range(n)]


def enqueue(x):
    global processes, tail
    processes.append(0)
    processes[tail] = x
    tail += 1


def dequeue():
    global head
    head += 1


for i in range(n):
    int(processes[i][1])

time, count = 0, 0
while count < n:
    y = processes[head][1] - quantum
    if y < 0:
        print(str(processes[head][0]) + " " + str(time + processes[head][1]))
        dequeue()
        time += y
        count += 1
    else:
        processes[head][1] -= quantum
        enqueue(processes[head])
        dequeue()

    time += quantum



### FIXED CODE ###

def parse(l):
    name, time = l.split()
    a = [name, int(time)]
    return a


n, quantum = map(int, input().split())
queue = []
for i in range(n):
    queue.append(parse(input()))
head = 0


def enqueue(x):
    global queue
    queue.append(x)


def dequeue():
    global head
    head += 1


total_time, count = 0, 0
while count < n:
    y = queue[head][1] - quantum
    if y <= 0:
        print(str(queue[head][0]) + " " + str(total_time + queue[head][1]))
        dequeue()
        total_time += y
        count += 1
    else:
        queue[head][1] -= quantum
        enqueue(queue[head])
        dequeue()

    total_time += quantum
import numpy as np
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
      x,y=map(int,input().split())
      g[x-1].append(y-1)
memo = [0]*n
visited = [False]*n
# dp(i):i=0,1,..,n-1:頂点iを始点とした最長のパスを返す
def dp(v):
      if visited[v]:
            return memo[v]
      else:
            res=0
            for u in g[v]:
                  res=max(res,dp(u)+1)
            memo[v]=res
            visited[v]=True
            return res
for i in range(n):
      dp(i)
print(max(memo))


### FIXED CODE ###

import numpy as np
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,m = map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
      x,y=map(int,input().split())
      g[x-1].append(y-1)
memo = [0]*n
visited = [False]*n
# dp(i):i=0,1,..,n-1:頂点iを始点とした最長のパスを返す
def dp(v):
      if visited[v]:
            return memo[v]
      else:
            res=0
            for u in g[v]:
                  res=max(res,dp(u)+1)
            memo[v]=res
            visited[v]=True
            return res
for i in range(n):
      dp(i)
print(max(memo))
h,w=map(int,input().split())

s=[]
for i in range(h):
    s.append(list(map(int,input().split())))

l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]
u=[[0]*w for i in range(h)]
d=[[0]*w for i in range(h)]

for i in range(h):
    f=0
    for j in range(w):
        if s[i][j]=='#':
            f=0
            l[i][j]=0
        else:
            f+=1
            l[i][j]=f
            
for i in range(h):
    f=0
    for j in range(w-1,-1,-1):
        if s[i][j]=='#':
            f=0
            r[i][j]=0
        else:
            f+=1
            r[i][j]=f
            
for j in range(w):
    f=0
    for i in range(h):
        if s[i][j]=='#':
            f=0
            u[i][j]=0
        else:
            f+=1
            u[i][j]=f
    
for j in range(w):
    f=0
    for i in range(h-1,-1,-1):
        if s[i][j]=='#':
            f=0
            d[i][j]=0
        else:
            f+=1
            d[i][j]=f

ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(ans)

### FIXED CODE ###

h,w=map(int,input().split())

s=[]
for i in range(h):
    s.append(list(input()))

l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]
u=[[0]*w for i in range(h)]
d=[[0]*w for i in range(h)]

for i in range(h):
    f=0
    for j in range(w):
        if s[i][j]=='#':
            f=0
            l[i][j]=0
        else:
            f+=1
            l[i][j]=f
            
for i in range(h):
    f=0
    for j in range(w-1,-1,-1):
        if s[i][j]=='#':
            f=0
            r[i][j]=0
        else:
            f+=1
            r[i][j]=f
            
for j in range(w):
    f=0
    for i in range(h):
        if s[i][j]=='#':
            f=0
            u[i][j]=0
        else:
            f+=1
            u[i][j]=f
    
for j in range(w):
    f=0
    for i in range(h-1,-1,-1):
        if s[i][j]=='#':
            f=0
            d[i][j]=0
        else:
            f+=1
            d[i][j]=f

ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(ans)
N, M = int(input().split())
A = [int(a) for a input().split()]
if N - sum(A) >= 0:
    print(N - sum(A))
else:
    print(-1)


### FIXED CODE ###

N, M = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
tmp = N - sum(A)
if tmp >= 0:
    print(tmp)
else:
    print(-1)
while(1):
  count = int(raw_input())
  if count == 0: break
  previous_cube = [1, 2, 3, 4, 5, 6]
  operation = {'North':[2, 6, 3, 4, 1, 5], 'East':[4, 2, 1, 6, 5, 3], 'West': [3, 2, 6, 1, 5, 4], 'South':[5, 1, 3, 4, 6, 2], 'Right':[1, 3, 5, 2, 4, 6], 'Left':[1, 4, 2, 5, 3, 6]}
  sum = 1
  for i in xrange(count):
    new_cube = []
    for e in xrange(6):
      new_cube.append(previous_cube[operation[raw_input()][e]])
    sum += new_cube[0]
    previous_cube = new_cube
  print sum

### FIXED CODE ###

while 1:
  n = input()
  if n == 0:  break
  d = range(1, 7)
  ans = 1
  for i in range(n):
    c = raw_input()[0]
    if c == 'N': S = [1,5,2,3,0,4]
    elif c == "S": S = [4,0,2,3,5,1]
    elif c == "E": S = [3,1,0,5,4,2]
    elif c == "W": S = [2,1,5,0,4,3]
    elif c == "R": S = [0,2,4,1,3,5]
    elif c == "L": S = [0,3,1,4,2,5]
    d = [d[s] for s in S]
    ans += d[0]
  print ans
N,u,v = map(int,input().split())
u -= 1
v -= 1

du = [0]*N
dv = [0]*N
du[u] = 0
dv[v] = 0
G = [0]*N

def dfs(v, d, p, dis):
    dis[v] = d
    for u in G[v]:
        if( u == p):
            continue
        else:
            dfs( u, d+1, v, dis )

def calcDist(s, dist):
    dfs(s, 0, -1, dist)

for i in range(N-1):
    e1,e2 = map(int, input().split())
    e1 -= 1
    e2 -= 1
    if G[e1] == 0:
        G[e1] = [e2]
    else:
        G[e1].append(e2)
    if G[e2] == 0:
        G[e2] = [e1]
    else:
        G[e2].append(e1)

if G[u]==[v]:
    ans = 0
else:    

    calcDist(v,dv)
    calcDist(u,du)
    maxD = 0
    for idu,idv in zip(du,dv):
        if idu < idv:
            maxD = max(maxD, idv)       
  
print(maxD - 1)

### FIXED CODE ###

import heapq

N,u,v = map(int,input().split())
u -= 1
v -= 1

#du = [0]*N
#dv = [0]*N
du = [float('inf')]*N
dv = [float('inf')]*N
#du[u] = 0
#dv[v] = 0
q = []

G = [[]]*N

'''
def dfs(v, d, p, dis):
    dis[v] = d
    if G[v] != []:
        for u in G[v]:
            if( u == p):
                continue
            else:
                dfs( u, d+1, v, dis )

def calcDist(s, dist):
    dfs(s, 0, -1, dist)
'''
def calcDist(s, dist):
    heapq.heappush(q,[0, s])
    dist[s] = int(0)
    
    while q!=[]:
        p = heapq.heappop(q)
        pv = p[1]
        if dist[pv] < p[0] :
            continue
        for i in range(len(G[pv])):
            eto = G[pv][i]
            if dist[eto] > dist[pv] + 1:
                 dist[eto] = int(dist[pv] + 1)
                 heapq.heappush(q, [dist[eto], eto])


for i in range(N-1):
    e1,e2 = map(int, input().split())
    e1 -= 1
    e2 -= 1
    if G[e1] == []:
        G[e1] = [e2]
    else:
        G[e1].append(e2)
    if G[e2] == []:
        G[e2] = [e1]
    else:
        G[e2].append(e1)

if v in G[u]:
    ans = 0
else:    

    calcDist(v,dv)
    calcDist(u,du)
    maxD = 0
    for idu,idv in zip(du,dv):
        if idu < idv:
            maxD = max(maxD, idv)       
    ans = maxD-1
    
print(ans)
d,n = map(int, raw_input().split())


# print(d)
# print(n)

if d == 0:
	print(n)
elif d == 1:
	if n ==100:
		print(10100)
	else:
		print(n*100*d)


elif d == 2:
	print(n*10000)


### FIXED CODE ###




# import configparser
# import time


# class GetTime():
#     now = time.ctime()

    
#     def debug(self):
#         print('-------debug-begin---------------')
#         print(self.now)
#         parsed = time.strptime(self.now)
#         print(time.strftime("%a %b %d %H:%M:%S %Y", parsed))
#         print('-------debug-end---------------')


# class Person():
#     def __init__(self, name, id):
#         self.name = name
#         self.id = id


# class Greet(Person):
#     def morning(self):
#         print('Good morning ' + self.name)

#     def night(self):
#         print('Good night ' + self.name)


# hunter = Person('Hoge Fugo', 1)

# print('name:%s   id:%s' % (hunter.name, hunter.id))

# o = Greet('Bob', 4)
# o.morning()


# t = GetTime()
# t.debug()

# ##

# poem = 'Hello,friends'
# fout = open('relavity','wt')
# # print(poem, file=fout)
# fout.close()

# ##





# # config.read('exe.ini')
# # print(MySQL_setting['Port'])
# # config.read('exe.ini')
# # print(MySQL_setting['Port'])

# class init_setting():
#     def input(self):
#         print('input port number:')
#         port=input()
#         print('input user name:')
#         user=input()

#         print(port,user)

        
#         with open('example.ini','w') as conf:
#             config.write(conf)

#         config=configparser.ConfigParser()
#         config['MySQL_setting']={}
#         MySQL_setting=config['MySQL_setting']


#         MySQL_setting['Port']=port
#         MySQL_setting['user']=user

#         config.sections()


# MakeSetting=init_setting()
# MakeSetting.input()


# MySQL_setting['Port']=port
# # MySQL_setting['user']=user

# empty_list = []
# print(empty_list)

# weekdays=['monday','Tuesday','Wednesday','Thursday','Friday']

# for i in weekdays:
#     print(weekdays)

# print(weekdays[0])

# for i in weekdays:
# 	print(i)

# a_tuple=('ready','fire','class')


# list('cat')


#! bin/env/python python3
# -*- coding:utf-8 -*-

d,n = map(int, input().split())


# print(d)
# print(n)

if d == 0:
	if n ==100:
		print(101)
	else:
		print(n)
elif d == 1:
	if n ==100:
		print(10100)
	else:
		print(n*100*d)


elif d == 2:
	if(n == 100):
		print(1010000)
	else:
		print(n*10000)
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = a[0]
s = a[0]
g = []
q = []
for i in range(n+1):
    g.append(p)
    p = a[p-1]
for i in range(len(g)):
    if g[i] == g[i] + mod
g.reverse()
for i in range(n):
    if g[0] == g[i+1]:
        mod = i+1
        break
g.reverse()
for i in range(len(g)):
    if g[i] == g[i] + mod:
        d = i
        break
if k <= mod:
    for i in range(k%mod):
        q.append(s)
        s = a[s-1]
    q.reverse()
    q.append(1)
    print(q[0])
else:
    print(g[d+(k-d)%mod])

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
p = a[0]
s = a[0]
g = [1]
q = []
for i in range(n+1):
    g.append(p)
    p = a[p-1]
g.reverse()
for i in range(n):
    if g[0] == g[i+1]:
        mod = i+1
        break
g.reverse()
for i in range(len(g)):
    if g[i] == g[i + mod]:
        d = i
        break
if k <= n:
    for i in range(k):
        q.append(s)
        s = a[s-1]
    q.reverse()
    print(q[0])
else:
    print(g[d+(k-d)%mod])
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
y =[x[i+1] - x[i] for i in range(m-1)]
a=[0]
for i in range(n-1):
    a.append(y.index(max(y)) + 1)
    y[y.index(max(y))] = 0
a.append(m)
s = 0
for i in range(n):
    s += x[a[i+1]-1]-x[a[i]]
print(s)

### FIXED CODE ###

n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
y = list()
for i in range(m-1):
    y.append(x[i+1]-x[i])
y.sort(reverse=True)
print(x[-1]-x[0]-sum(y[:n-1]))
m,k = map(int,input().split())

if m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
    exit()
if m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)
    exit()
if k >= 2**m:
    print(-1)

res = []
used = [True]*(pow(2**m))

tank = []

for i in range(2**m):
    if used[i]:
        tank.append((i,i^k))
        used[i] = used[i^k] = False
for i in range(len(tank)):
    if i % 2 == 1:
        continue
    a = tank[i][0]
    b = tank[i][1]
    c = tank[i+1][0]
    d = tank[i+1][1]
    res += [c,a,b,c,d,b,a,d]

for e in res:
    print(e,end=' ')

### FIXED CODE ###

m,k = map(int,input().split())

if m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
    exit()
if m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)
    exit()
if k >= 2**m:
    print(-1)
    exit()
if k == 0:
    for i in range(2**m):
        print(i,i,end = ' ')
    exit()
res = []
used = [True]*(2**m)

tank = []

for i in range(2**m):
    if used[i]:
        tank.append((i,i^k))
        used[i] = used[i^k] = False
for i in range(len(tank)):
    if i % 2 == 1:
        continue
    a = tank[i][0]
    b = tank[i][1]
    c = tank[i+1][0]
    d = tank[i+1][1]
    res += [c,a,b,c,d,b,a,d]

for e in res:
    print(e,end=' ')
n=int(input())
a=list(map(int.input().split()))
print(max(a)-min(a))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
print(max(a)-min(a))
a,b,k=map(int,input().split())

count=0

for i in range(1,min(a,b)+1)[::-1]:
  if a%i==0 and b%i==0:
    count +=1
if count=k:
  num=i
  break
  
print(num)

### FIXED CODE ###

A, B, K = list(map(int, input().split()))

ans = []
for i in range(1, min(A, B) + 1):
    if (A%i==0) and (B%i==0):
        ans.append(i)

print(ans[-K])
A = []
n = input()

for i in range(n):
    command = [0, 0]
    temp = raw_input().split()
    command[0] = temp[0]
    command[1] = int(temp[1])

    if command[0] == 'insert':
        A.insert(0, command[1])
    elif command[0] == 'delete':
        A.remove(command[1])
    elif command[0] == 'deleteFirst':
        A.pop(0)
    elif command[0] == 'deleteLast':
        A.pop()

for i in range(len(A)):
    print A[i],

### FIXED CODE ###

A=[]
fp =0
bp =0
n=int(raw_input())
while n: 
    cmd = raw_input()
    if cmd[0] == 'i':
        A.append(int(cmd[7:]))
        fp += 1
    elif cmd[6] == ' ':
        try:
            i = A[::-1].index(int(cmd[7:]))
            if i!=-1:
                del A[-i-1]
                fp -=1
        except:
            pass
    elif cmd[6] == 'F':
        A.pop()
        fp -=1
    elif cmd[6] == 'L':
        bp +=1
    n -=1
 
for k in A[bp:fp+1][::-1]:
    print int(k),
N,M=map(int,input().split())
S=list(map(int,input().split()))
S.sort()

TRADE=[[0 for j in range(2)] for i in range(M)]

for i in range(M):
    B,C=map(int,input().split())
    TRADE[i][0]=B
    TRADE[i][1]=C


T=sorted(TRADE,key=lambda x:x[1],reverse=True)


TLEN=0
pos=0
flag=True
while TLEN<M and flag=True:
    for i in range(T[TLEN][0]):
        if S[pos]<T[TLEN][1]:
            S[pos]=T[TLEN][1]
            pos+=1
        else:
            flag=False
            break
    TLEN+=1

print(sum(S))

### FIXED CODE ###

N,M=map(int,input().split())
S=list(map(int,input().split()))
S.sort()

TRADE=[[0 for j in range(2)] for i in range(M)]

for i in range(M):
    B,C=map(int,input().split())
    TRADE[i][0]=B
    TRADE[i][1]=C


T=sorted(TRADE,key=lambda x:x[1],reverse=True)


TLEN=0
pos=0
flag=True
while TLEN<M and flag==True:
    for i in range(T[TLEN][0]):
        if S[pos]<T[TLEN][1]:
            S[pos]=T[TLEN][1]
            pos+=1
        else:
            flag=False
            break
        if pos>len(S)-1:
            flag=False
            break
    TLEN+=1

print(sum(S))
s=int(input())
ans=1
for i in range(1,n+1):
  ans*=i
  
print(ans)

### FIXED CODE ###

s=int(input())
ans=1
for i in range(1,s+1):
  ans=ans%(10**9+7)*i
  
  
print(ans%(10**9+7))
def gcd(_a,_b):
    a=max([_a, _b]); b=min([_a, _b])
    while True:
        m=a%b
        if m==0:
            return b
        a=b

a,b,k=(int(x) for x in input().split())
g=gcd(a,b)
cd=[]
i=g
while True:
    if g%i==0:
        cd.append(i)
        i=i//2
        if i==1 or i==0:
            break
    else:
        i-=1
print(cd[k-1])

### FIXED CODE ###

def gcd(t):
    b,a=sorted(t)
    while True:
        m=a%b
        if m==0:
            return b
        a=b;b=m
a,b,k=(int(x) for x in input().split())
g=gcd((a,b))
cd=[]
for i in range(g+1)[::-1]:
    if i==0:
        break
    if g%i==0:
        cd.append(i)
print(cd[k-1])
n = int(input())
number = list(map(int,input().split()))
num = sorted(number)
num.append(0)
p = num[0]
combi = dict()
u = 0

for i in range (n+1) :
    q = num[i]
    if p != q :
        combi[p] = u
        u = 0
    u += 1
    p = q

t = 0

for j in combi.values() :
    t += j*(j-1)//2

for k in range (n) :
    x = combi[j]
    print(t + (combi[x]-1)*(combi[x]-2)//2 - combi[x]*(combi[x]-1)//2)

### FIXED CODE ###

n = int(input())
number = list(map(int,input().split()))
num = sorted(number)
num.append(0)
p = num[0]
combi = dict()
u = 0

for i in range (n+1) :
    q = num[i]
    if p != q :
        combi[p] = u
        u = 0
    u += 1
    p = q

t = 0

for j in combi.values() :
    t += j*(j-1)//2

for k in range (n) :
    x = number[k]
    print(t + (combi[x]-1)*(combi[x]-2)//2 - combi[x]*(combi[x]-1)//2)