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

# dp[i][j]=(i人目までにj個配る場合の数)
mod=10**9+7
def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    dp=[[0]*(k+1) for _ in range(n)]
    for i in range(a[0]+1):
        dp[0][i]=1
    for i in range(1,n):
        dp[i][0]=dp[i-1][0]
        for j in range(1,k+1):
            dp[i][j]=dp[i-1][j]+dp[i][j-1]
            if j-a[i]>0:
                dp[i][j]-=dp[i-1][j-a[i]-1]
            dp[i][j]%=mod
    print(dp[-1][-1])
    # for i in dp:
    #     print(i) 
main()     

### FIXED CODE ###

# dp[i][j]=(i人目までにj個配る場合の数)
mod=10**9+7
def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    dp=[[0]*(k+1) for _ in range(n)]
    for i in range(a[0]+1):
        dp[0][i]=1
    for i in range(1,n):
        dp[i][0]=dp[i-1][0]
        for j in range(1,k+1):
            dp[i][j]=dp[i-1][j]+dp[i][j-1]
            if j-a[i]>0:
                dp[i][j]-=dp[i-1][j-a[i]-1]
            dp[i][j]%=mod
    print(dp[-1][-1])
    # for i in dp:
    #     print(i) 
main()
### BUGGY CODE ###

n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item

queue = my_queue(queue)

time = 0
finish_task = []

while(queue != None):
    item = queue.dequeue()
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.enqueue([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])

### FIXED CODE ###

n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item


time = 0
finish_task = []

while(len(queue) != 0):
    item = queue.pop(0)
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.append([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])
### BUGGY CODE ###

S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))

def main():
    n,k=L()
    h=L()
    dp=[1e+12]*n
    dp[0]=0
    for i in range(n):
        for j in range(1,k+1):
            if i+j>=n:
                break
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
    print(dp[n-1])
    
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))

def main():
    n,k=L()
    h=L()
    dp=[1e+12]*n
    dp[0]=0
    for i in range(n):
        for j in range(1,k+1):
            if i+j>=n:
                break
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
    print(dp[n-1])
    
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from fractions import gcd
#from math import gcd

n=int(input())
t=[]
a=[]
for i in range(n):
    ti,ai=map(int,input().split())
    t.append(ti)
    a.append(ai)
    
ti=t[0]
ai=a[0]
for i in range(n-1):
    ta=gcd(t[i+1],a[i+1])*a[i+1]*t[i+1]
    for ii in range(1,10000000):
        if ta*ii//a[i+1]>=ti and ta*ii//t[i+1]>=ai:
            ti=ta*ii//a[i+1]
            ai=ta*ii//t[i+1]
#            print(i,ii,ti,ai,ta)
            break
            
print(ai+ti)
         
    

### FIXED CODE ###

icase=0
if icase==0:
    n=int(input())
    t=[0]*n
    a=[0]*n

    for i in range(n):
        t[i],a[i]=map(int,input().split())
elif icase==1:
    n=5
    t=[3,48,31,231,3]
    a=[10,17,199,23,2]
    ans=6930

ti=t[0]
ai=a[0]
dt=1
for i in range(n-1):
    if ti/t[i+1]>ai/a[i+1]:
        ii=max((ti-dt)//t[i+1]+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]
    else:
        ii=max((ai-dt)//a[i+1]+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]

print(ai+ti)
### BUGGY CODE ###

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

def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    idx = -1
    ans = n

    for i in range(1, n+1):
        if i in a[idx + 1:]:
            idx = a.index(i,idx+1)
            ans -= 1
            if idx == n-1:
                break
        else:
            break

    if ans == n:
        ans = -1

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

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

def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    seek = 1

    for i in range(n):
        if a[i] == seek:
            seek += 1

    if seek == 1:
        ans = -1
    else:
        ans = n + 1 - seek

    print(ans)

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

n, m, k = map(int, input().split())
ans = [0] * n
p = [{'T':[], 'B':[]} for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    p[a-1]['T'].append(b)
    p[b-1]['T'].append(a)
    
for _ in range(k):
    c, d = map(int, input().split())
    p[c-1]['B'].append(d)
    p[d-1]['B'].append(c)

fl = []

for i, dt in enumerate(p):
    isContinue = False
    if i+1 in fl:
        continue
    tmp_fl = [i+1] + dt['T']
    rmn = [t for t in dt['T']]
    alr = [i+1]
    while not len(rmn) == 0:
        r = rmn.pop(0)
        alr.append(r)
        for nf in p[r-1]['T']:
            if not nf in tmp_fl:
                tmp_fl.append(nf)
            if not nf in rmn and not nf in alr:
                rmn.append(nf)
    fl.append(tmp_fl)
    
for i, dt in enumerate(p):
    l = [i+1]+ dt['T'] + dt['B']
    for f in fl:
        if i+1 in f:
            ans[i] = len([x for x in f if not x in l])
            

print(' '.join(map(str, ans)))

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N,M,K = map(int,input().split())
    friend = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        friend[a-1].append(b-1)
        friend[b-1].append(a-1)
        
    brock = [[] for _ in range(N)]
    for _ in range(K):
        c,d = map(int,input().split())
        brock[c-1].append(d-1)
        brock[d-1].append(c-1)
        
    parent = [-1 for _ in range(N)]
    group = [0 for _ in range(N)]
    
    for i in range(N):
        put = []
        if parent[i] == -1:
            q = deque([i])
            parent[i] = i
            while q:
                now = q.pop()
                put.append(now)
                for fol in friend[now]:
                    if parent[fol] == -1:
                        parent[fol] = i
                        q.append(fol)
            l = len(put)
            for num in put:
                group[num] = l-1
                
        else:
            continue

    for i in range(N):
        group[i] -= len(friend[i])
        for dis in brock[i]:
            if parent[i] == parent[dis]:
                group[i] -= 1
    
    print(*group)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    N, W = [int(x) for x in input().split()]
    shina = []
    for i in range(N):
        a, b = [int(x) for x in input().split()]
        shina.append([a, b])

    dp = [[0 for i in range(N + 1)] for j in range(W + 1)]

    for i in range(N - 1, -1, -1):
        for j in range(W + 1):
            if shina[i][0] > j:
                dp[j][i] = dp[j][i + 1]
            else:
                dp[j][i] = max(dp[j][i + 1], dp[j - shina[i][0]][i + 1] + shina[i][1])

    ans = 0
    for j in range(W + 1):
        ans = max(ans, max(dp[j]))

    print(ans)


if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    N, W = [int(x) for x in input().split()]
    shina = []
    for i in range(N):
        a, b = [int(x) for x in input().split()]
        shina.append([a, b])

    dp = [[0 for i in range(N + 1)] for j in range(W + 1)]

    for i in range(N - 1, -1, -1):
        for j in range(W + 1):
            if shina[i][0] > j:
                dp[j][i] = dp[j][i + 1]
            else:
                dp[j][i] = max(dp[j][i + 1], dp[j - shina[i][0]][i + 1] + shina[i][1])

    ans = 0
    for j in range(W + 1):
        ans = max(ans, max(dp[j]))

    print(ans)


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

import math
n, m = map(int, input().split())
a = [-1] + [int(input()) for i in range(m)] + [n+1]
func = math.factorial
count = 1
for i in range(m+1):
    k = a[i+1] - a[i] - 2
    if k == -1:
        count = 0
        break
    else:
        work = 0
        for b in range(k//2+1):
            work += func(k-b)//(func(k-2*b)*func(b))
        count *= work
print(count%1000000007)

### FIXED CODE ###

import math
import sys
sys.setrecursionlimit(100000)
f = math.factorial
n, m = map(int, input().split())
a = [-1] + [int(input()) for i in range(m)] + [n+1]
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


count = 1
for i in range(m+1):
    k = a[i+1] - a[i] - 2
    if k == -1:
        count = 0
        break
    else:
        work = 0
        for b in range(k//2+1):
            work += cmb(k-b, b, p)
        count *= work
print(count%p)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
mod=10**9+7

mb=format(max(a),'b')
arr=[0]*len(mb)

for i in range(n):
    b=format(a[i],'b')
    for j in range(len(b)):
        if b[-j-1]=='1':
            arr[j]+=1

ans=0

for i in range(len(mb)):
    ans+=(arr[i]*(n-arr[i])*(2**i))%mod
print(ans%mod)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
mod=10**9+7

mb=format(max(a),'b')
arr=[0]*len(mb)

for i in range(n):
    b=format(a[i],'b')
    for j in range(len(b)):
        if b[-j-1]=='1':
            arr[j]+=1

ans=0

for i in range(len(mb)):
    ans+=arr[i]*(n-arr[i])*(2**i)
print(ans%mod)
### BUGGY CODE ###

# -*- coding:utf-8 -*-

comb_dic = {}

def combination_formula_MOD(n, r, MOD):
    """nCrを O(min(n-r, r)) で高速に計算する"""
    def _inv(x, MOD):
        """xの逆元を返す"""
        return pow(x, MOD-2, MOD)
    if r > n: return 0

    if (n,r) in comb_dic:
        return comb_dic[(n,r)]

    r = min(n-r, r)
    bunsi, bunbo = 1, 1
    for i in range(r):
        bunsi = bunsi*(n-i)%MOD
        bunbo = bunbo*(i+1)%MOD

    ans = (bunsi*_inv(bunbo, MOD))%MOD
    comb_dic[(n,r)] = ans
    return ans


def combination_formula(n, r):
    """nCrは、O(min(n-r, r))で実装する
    Notes:
        分子と分母がかなり大きな値になった場合、計算は遅くなるので注意
        求める値がmodをとった値でいい場合、フェルマーの小定理を使った方法が速い。
    """
    if r > n: return 0

    if (n,r) in comb_dic:
        return comb_dic[(n,r)]

    r = min(n-r, r)
    bunsi, bunbo = 1, 1
    for i in range(r):
        bunsi = bunsi*(n-i)
        bunbo = bunbo*(i+1)

    comb_dic[(n,r)] = bunsi//bunbo
    return bunsi//bunbo


def solve():
    N = int(input())
    As = list(map(int, input().split()))
    MOD = 10**9+1

    dic = {}
    for a in As:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1

    calc_dic = {}  # すでに計算済みのもの
    for a in As:
        ans = 0
        if not a in calc_dic:
            for key, value in dic.items():
                if key == a:
                    value -= 1
                ans += combination_formula(value, 2)
            calc_dic[a] = ans
            print(calc_dic[a])
        else:
            print(calc_dic[a])



if __name__ == "__main__":
    solve()


### FIXED CODE ###

# -*- coding:utf-8 -*-

comb_dic = {}


def combination_formula(n, r):
    """nCrは、O(min(n-r, r))で実装する
    Notes:
        分子と分母がかなり大きな値になった場合、計算は遅くなるので注意
        求める値がmodをとった値でいい場合、フェルマーの小定理を使った方法が速い。
    """
    if r > n: return 0

    if n in comb_dic:
        return comb_dic[n]

    r = min(n-r, r)
    bunsi, bunbo = 1, 1
    for i in range(r):
        bunsi = bunsi*(n-i)
        bunbo = bunbo*(i+1)

    comb_dic[n] = bunsi//bunbo
    return comb_dic[n]


def solve():
    N = int(input())
    As = list(map(int, input().split()))

    dic = {}
    for a in As:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1

    # combination_formula(v, 2)はくっそ早いので、
    # しゃくとりっぽく解く
    total = 0
    for key, value in dic.items():
        total += combination_formula(value, 2)

    for a in As:
        ans = total
        ans -= combination_formula(dic[a], 2)
        ans += combination_formula(dic[a]-1, 2)
        print(ans)


if __name__ == "__main__":
    solve()
### BUGGY CODE ###

neighbor = lambda c, w, h: filter(
    lambda b: 0 <= b[0] <= w and 0 <= b[1] <= h,
    [
        (c[0]-1, c[1]),
        (c[0]+1, c[1]),
        (c[0], c[1]-1),
        (c[0], c[1]+1)
    ]
)

t = raw_input()
W, H = map(int, t.split(' '))
p, q = [], []
for i in xrange(W):
    p.append(int(raw_input()))
for j in xrange(H):
    q.append(int(raw_input()))

has = [[False for i in xrange(H+1)] for j in xrange(W+1)]
has[0][0] = True
Next = [(1, 0), (0, 1)]

cost = 0
for i in xrange(W*H+W+H):
    Min = 100000005
    choose = None
    Next.sort(key=lambda a: min(p[a[0]-1] if a[0] > 0 else 100000005, q[a[1]-1] if a[1] > 0 else 100000005))
    choose = Next[-1]
    Min = min(p[choose[0]-1] if choose[0] > 0 else 100000005, q[choose[1]-1] if choose[1] > 0 else 100000005)
    # for each in Next:
    #     if each[0] > 0:
    #         if p[each[0]-1] < Min:
    #             choose = each
    #             Min = p[each[0]-1]
    #     if each[1] > 0:
    #         if q[each[1]-1] < Min:
    #             choose = each
    #             Min = q[each[1]-1]
    has[choose[0]][choose[1]] = True
    Next = Next[:-1]
    cost += Min
    for every in neighbor(choose, W, H):
        # print every
        if not has[every[0]][every[1]] and every not in Next:
            Next.append(every)
print cost

### FIXED CODE ###


import bisect
cost = 0
t = raw_input()
W, H = map(int, t.split(' '))
p, q = [], []
sum_p = []
for i in xrange(W):
    tmp = int(raw_input())
    p.append((i, tmp))
p.sort(key=lambda a: a[1])
pp = [each[1] for each in p]
for i in xrange(W):
    if not sum_p:
        sum_p.append(pp[i])
    else:
        sum_p.append(sum_p[-1]+pp[i])
cost += sum(pp)
for j in xrange(H):
    new = int(raw_input())
    cost += new
    minus = bisect.bisect_right(pp, new)
    cost += (W-minus) * new
    cost += sum_p[minus-1] if minus > 0 else 0

print cost
### BUGGY CODE ###

import math
A, B, N = list(map(int, input().split()))
def floor(t):
    if t == 0 or t == int(t):
        return t
    return math.floor(t)

ans = 0
if B+1 < N:
    C = B+1
else:
    C = N
for i in range(1, C+1):
    val = floor(A*i/B) - A*floor(i/B)
    #print("i", i, "val", val)
    ans = max(ans, val)

print(ans)

### FIXED CODE ###

import math
A, B, N = list(map(int, input().split()))
ans = 0
if B+1 < N:
    C = B+1
else:
    C = N
if B//A == 0:
    D = 1
elif B//A > 1:
  	D = B//A-1
else:
    D = B//A
for i in range(1, C+1, D):
    val = math.floor(A*i/B) - A*math.floor(i/B)
    #print("i", i, "val", val)
    ans = max(ans, val)

print(ans)
### BUGGY CODE ###

n=int(input())
def calc(sykou,makkou,kousuu):
    return int((sykou+makkou)/2*kousuu)

ans=0
for i in range(1,n+1):
    ans+=(calc(i,n//i*i,n//i))

print(ans)

### FIXED CODE ###

n=int(input())
def calc(sykou,makkou,kousuu):
    return int((sykou+makkou)/2*kousuu)

ans=0
for i in range(1,n+1):
    ans+=(calc(i,n//i*i,n//i))

print(ans)
### BUGGY CODE ###

def main():
    N, W = map(int, input().split())

    w, v = [0] * (N + 1), [0] * (N + 1)
    for i in range(N):
        w[i + 1], v[i + 1] = map(int, input().split())

    dp = [[0 for i in range(W + 1)] for i in range(N + 1)]

    for i in range(1, N + 1):
        for j in range(1, W + 1):
            if j >= w[i]:
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i])
            dp[i][j] = max(dp[i][j], dp[i - 1][j])

    print(dp[-1][-1])


main()


### FIXED CODE ###

import sys


def main():
    input = sys.stdin.readline

    N, W = map(int, input().split())
    dp = [0] * (W + 1)

    WV = (map(int, input().split()) for _ in range(N))

    for w, v in WV:
        for j in range(W, w - 1, -1):
            tmp = dp[j - w] + v
            if tmp > dp[j]:
                dp[j] = tmp

    print(dp[-1])


main()
### BUGGY CODE ###

import heapq
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
l=[[] for i in range(m)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    l[a-1].append(-b)
tmp=[]
ans=0
for i in range(m):
  tmp+=l[i]
  heapq.heapify(tmp)
  if len(tmp)>0:
    ans+= heapq.heappop(tmp)
print(-ans)

### FIXED CODE ###

import heapq
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
l=[[] for i in range(m)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    l[a-1].append(-b)
tmp=[]
heapq.heapify(tmp)
ans=0
for i in range(m):
  for j in l[i]:
    heapq.heappush(tmp,j)
  if len(tmp)>0:
    ans+= heapq.heappop(tmp)
print(-ans)
### BUGGY CODE ###

def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0

for w in range(4,l+1):
    for i in range(l+1-w):
        j = i + w
        #print(s[i:j])
        if (int(s[i:j])%2019 == 0):
            cnt += 1
print(cnt)

### FIXED CODE ###

def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
m = 0
for i in range(l):
    m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019
    mod[m] += 1

cnt += mod[0]

for i in range(2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))/2
        #print(i)
print(int(cnt))
### BUGGY CODE ###

# coding: utf-8

# 17:36-18:06


def main():
    S = input()
    N = len(S)

    start_cnt = [0] * N

    for i in range(N-5, -1, -1):
        j = i + 3
        cnt = 0
        while j < N:
            x = int(S[i:j+1])
            if x % 2019 == 0:
                cnt += 1
                if j + 1 < N:
                    cnt += start_cnt[j+1]
                start_cnt[i] = cnt
                break
            j += 1

    # print(start_cnt)
    return sum(start_cnt)


print(main())


### FIXED CODE ###

# coding: utf-8

# 17:36-18:18 give up => kaisetu
# -18:46 - 18:52 chudan
# -20:21


def main():
    S = input() + "0"
    # S = "1" * 10**5 + "0"
    N = len(S)
    S = list(map(int, S))

    q = 2019

    res = [0] * N
    num = 0
    p = 1
    pow_memo = {0: (10**0) % q}
    for i in range(N-2, -1, -1):
        pow_memo[p] = (pow_memo[p-1] * 10) % q
        num = (num + (S[i] % q) * pow_memo[p]) % q
        res[i] = num
        p += 1

    cnt = [0] * q
    for r in res:
        cnt[r] += 1

    ans = 0
    for c in cnt:
        ans += c * (c-1) // 2

    return ans


print(main())
### BUGGY CODE ###

K = int(input())
c = 0
an = 0

if K%2 == 0 or K%2 ==0:
    print("-1")
    exit(0)
while True:
  an = (10*an + 7) % K
  c +=1
  if an == 0:
    print(c)
    break

### FIXED CODE ###

def calc(k):
    cur = 0
    for i in range(1, 10 ** 7):
        cur *= 10
        cur += 7
        cur %= k
        if cur == 0:
            return i

    return -1


k = int(input())
print(calc(k))
### BUGGY CODE ###

# C問題
N = int(input())
TA = []
for i in range(N):
    TA.append(list(map(int, input().split())))
#T, A互いに素なので1枚目はそのまま取ってきて良い
t = TA[0][0]
a = TA[0][1]
flag = True
for i in range(1,  N+1):
    tmp_t = 0
    tmp_a = 0
    if i == N:
        flag = False        
    while flag:
        tmp_t += TA[i][0]
        tmp_a += TA[i][1]
        if tmp_t >= t and tmp_a >= a:
            t = tmp_t
            a = tmp_a
            break
    
print(t+a)        

### FIXED CODE ###

# C問題
N = int(input())
TA = []
for i in range(N):
    TA.append(list(map(int, input().split())))
#T, A互いに素なので1枚目はそのまま取ってきて良い
t = TA[0][0]
a = TA[0][1]
flag = True
for i in range(1,  N+1):
    tmp_t = 0
    tmp_a = 0
    if i == N:
        flag = False
        break
    k = max(t // TA[i][0], a // TA[i][1])   # 整数k
    while flag:   # 整数倍(足していく)していって両方がが超えた時の値が得票数になる
        tmp_t = k * TA[i][0]
        tmp_a = k * TA[i][1]
        if tmp_t >= t and tmp_a >= a:
            t = tmp_t
            a = tmp_a
            break
        k += 1
    
print(t+a)
### BUGGY CODE ###

from collections import deque
S = deque(input())

ans = 0
while len(S):
    if S[0] == S[-1]:
        if len(S) > 1:
            S.popleft()
            S.pop()
        else:
            S.pop()
    else:
        if S[0] != "x" and S[1] != "x":
            print(-1)
            exit()
        elif S[0] != "x":
            S.appendleft("x")
            ans += 1
        elif S[1] != "x":
            S.append("x")
            ans += 1
print(ans)

### FIXED CODE ###

import sys

S = sys.stdin.readline().rstrip()
not_x = []

for i, s in enumerate(S):
    if s != "x":
        not_x.append(s)

not_x_nums = len(not_x)
mid = not_x_nums // 2

if not_x_nums % 2 == 1:
    left = not_x[:mid]
    right = not_x[mid + 1:][::-1]
else:
    left = not_x[:mid]
    right = not_x[mid:][::-1]

if left == right:
    ans = 0
    left = []
    right = []
    tmp = 0
    cnt = 0
    if not_x_nums % 2 == 1:
        mid += 1
    for s in S:
        if s != "x":
            left.append(tmp)
            tmp = 0
            cnt += 1
        else:
            tmp += 1
        if cnt == mid:
            break
    tmp = 0
    cnt = 0
    for s in S[::-1]:
        if s != "x":
            right.append(tmp)
            tmp = 0
            cnt += 1
        else:
            tmp += 1
        if cnt == mid:
            break
    for l, r in zip(left, right):
        ans += abs(l - r)
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

import numpy as np
N = int(input())
X = list(map(int, input().split()))

for i in range(N):
    print(int(np.median(X[:i]+X[i+1:])))

### FIXED CODE ###

import numpy as np
N = int(input())
X = list(map(int, input().split()))

X_sort = sorted(X)
small, big = X_sort[N//2-1], X_sort[N//2]

for x in X:
    if x >= big:
        print(small)
    else:
        print(big)
### BUGGY CODE ###

n, x = list(map(int, input().split()))
xi = list(map(int, input().split()))

diff = max(max(xi) - x, x - min(xi))

for d in range(diff, 1, -1):
    xd = x%d
    sol = True

    for xval in xi:
        if ((xval % d) - xd)%d != 0:
            sol = False
            break

    if sol:
        print(d)
        break

### FIXED CODE ###

n, x = list(map(int, input().split()))
xi = list(map(int, input().split()))

xi = [abs(xval - x) for xval in xi]

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

res = xi[0]
for i in range(1, len(xi)):
    res = gcd(res, xi[i])

print(res)