Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-

n = int(raw_input())
A = map(int, raw_input().split())
count = 0
for i in range(n):
    for j = in range(i, n):
        if A[i] > A[j]:
            count += 1
print count

### FIXED CODE ###

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

import sys

def merge(A, left, mid, right):
    global count
    n1 = mid-left
    n2 = right-mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left+i]
    for i in range(n2):
        R[i] = A[mid+i]
    L[n1] = R[n2] = sys.maxint
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            count += n1-i

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left+right)/2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(raw_input())
S = map(int, raw_input().split())
count = 0
mergeSort(S, 0, n)
print count
n, m = map(int,input().split())
dic = {}
ans = 0
for _ in range(m):
    s,c = map(int,input().split())
    if s not in dic.keys():
        dic[s-1] = c
    elif s in dic.keys() and dic[s-1] !=c:
        ans = -1
        break
for i in range(n):
    if i not in dic.keys():
        dic[i] = 0

if dic[0] ==0:
    ans = -1
if ans == -1:
    print('-1')
    exit()
ls = []
for i in range(n):
    ls.append(str(dic[i]))
ans = ''.join(ls)
print(ans)


### FIXED CODE ###

n, m = map(int,input().split())
dic = {}
ans = 0
for _ in range(m):
    s,c = map(int,input().split())
    if s-1 not in dic.keys():
        dic[s-1] = c
    if s-1 in dic.keys() and dic[s-1] !=c:
        ans = -1
        break
    if s == 1 and c == 0 and n!=1:
        ans = -1
        break
if ans == -1:
    print(ans)
    exit()
if 1 not in dic.keys() and n !=1:
    dic[1] = 0
if 2 not in dic.keys() and n ==3:
    dic[2] = 0  
if 0 not in dic.keys() and n!=1:
    dic[0] = 1
if 0 not in dic.keys() and n==1:
    dic[0] = 0
ls = []
for i in range(n):
    ls.append(str(dic[i]))
ans = ''.join(ls)
print(ans)
n = int(input())
s,d = map(int,input().split())

c = 0
for i in range(s,d+1:
  if i % s == 0:
  	c = c + 1


if c != 0:
 	print("YES")
else:
  	print("NO")
    

### FIXED CODE ###

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

c = 0
for i in range(s,d+1):
  if i % n == 0:
  	c = c + 1
  else:
    c = c
    
if c != 0:
 	print("OK")
else:
  	print("NG")
K = int(input())
import math
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans += gcd(i+1,j+1,k+1)
            #1-Kまで
print(ans)

### FIXED CODE ###

import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K = int(input())
 
 
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
           
 
                ans += gcd(i+1,j+1,k+1)
            #1-Kまで
print(ans)
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,n=n1()

if n==0:
    print(x)
else:
    P=n1()
    if (not x in P):
        print(x)
    else:
        d=[]
        d2=[]
        for i in range(1,101):
            if (not i in P):
                d.append(i)
                d2.append(abs(x-i))

        a=min(d2)
        if x-a in d:
            print(x-a)
        else:
            print(x+a)

### FIXED CODE ###


def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,n=n1()

if n==0:
    print(x)
else:
    P=n1()
    if (not x in P):
        print(x)
    else:
        d=[]
        d2=[]
        for i in range(0,102):
            if (not i in P):
                d.append(i)
                d2.append(abs(x-i))

        a=min(d2)
        if (x-a) in d:
            print(x-a)
        else:
            print(x+a)
import math

t = int(input())
g_all = np.array([list(input()) for i in range(t)])
num = 0
for i in range(t):
    if i%2 == 0 and g_all[i]%2 == 1:
        num+=1
print(num)

### FIXED CODE ###

import math
import itertools
import numpy as np

t = int(input())
a=list(map(int, input().split()))
num = 0
for i in range(t):
    if i%2 == 0 and a[i]%2 == 1:
        num+=1
print(num)
A,B = int(input())
if B%A=0:
    print(A+B)
else:
    print(B-A)

### FIXED CODE ###

A,B = list(map(int,input().split()))
if B%A==0:
    print(A+B)
else:
    print(B-A)
s = input().split()
a = input().split()
if s+a[-1]==a:
  print("yes")
else:
  print("no")

### FIXED CODE ###

s = input()
t = input()
if s +t[-1]==t:
  print('Yes')
else:
  print('No')
n=int(input())
h=list(map(int,input().split()))
a=[0]
i=0
while i<n-1:
  c=0
  while i<n-1:
    if h[i]>=h[i+1]:
      c+=1
      i+=1
    else:
      a.append(c)
      i+=1
      break
a.append(c)
print(max(a))

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
a=[0]
i=0
c=0
while i<n-1:
  c=0
  while i<n-1:
    if h[i]>=h[i+1]:
      c+=1
      i+=1
    else:
      a.append(c)
      i+=1
      break
a.append(c)
print(max(a))
def resolve():
    import numpy as np

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

    A_cumsum = np.cumsum(A)
    B_cumsum = np.cumsum(B)

    ans = 0
    j = M
    for i in range(N + 1):
        if A_cumsum[i] > K:
            break
        while A_cumsum[i] + B_cumsum[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)

resolve()

### FIXED CODE ###

def resolve():
    import numpy as np

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

    A = np.insert(np.cumsum(A), 0, 0)
    B = np.insert(np.cumsum(B), 0, 0)

    ans = 0
    j = M
    for i in range(N + 1):
        if A[i] > K:
            break
        while A[i] + B[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)

resolve()
a, b = map(int, input())
print(a+b/2)

### FIXED CODE ###

a, b = map(int, input().split())
print(int(a+b/2))
a = int(input())
print("Yes" if a[1]==a[2]==a[0] or a[1]==a[2]==a[3], else "No")

### FIXED CODE ###

a = input()
print("Yes" if a[0]==a[1]==a[2] or a[1]==a[2]==a[3] else "No")
w = []
v = []
n, W = map(int, input().split())
#dp = [[0 for i in range(n)] for j in range(W)]
dp = [[None for i in range(W+1)] for j in range(n+1)]

for i in range(n):
    v1, v2 = map(int, input().split())
#    v2, v1 = map(int, input().split())
    w.append(v1)
    v.append(v2)

# i: Index (Tracing all items)
# j: Remaining weight
# Return the sum of value
def knap(i, j):
    # print("\n# i: " + str(i))
    # print("# j: " + str(j))
    if dp[i][j] is not None:
        return dp[i][j]

    res = 0

    if i == n:
#        dp[i][j] = 0
        res = 0
    elif j < w[i]:
        res = knap(i+1, j)
    else:
        # if dp[i][j] is None:
        #     dp[i][j] = dp[i-1][j] + v[i]
        res = max(knap(i+1, j), knap(i+1, j-w[i]) + v[i])

    dp[i][j] = res
    return dp[i][j]
#    return res

print(knap(0, W))


### FIXED CODE ###

n, W = map(int, input().split())
w = [0]*(n+1)
v = [0]*(n+1)

#dp = [[None for i in range(W+1)] for j in range(n+1)]
dp = [[0 for i in range(W+1)] for j in range(n+1)]

for i in range(n):
    w[i], v[i] = map(int, input().split())

def knap(i, j):
    if dp[i][j] is not None:
        return dp[i][j]

    res = 0

    if i == n:
       	res = 0
    elif j < w[i]:
        res = knap(i+1, j)
    else:
        res = max(knap(i+1, j), knap(i+1, j-w[i]) + v[i])

    dp[i][j] = res
    return dp[i][j]

for i in reversed(range(n)):
    for j in range(W+1):
#        res = 0
        # if i == n-1:
        #     res = 0
        if j < w[i]:
            dp[i][j] = dp[i+1][j]
        else:
            dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]] + v[i])

#print(knap(0, W))
print(dp[0][W])
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

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

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def getInputStr():
    inputStr = str(input())
    return inputStr

data = getInputStr()

a = str(data)
listStr = []
listStr = list(a)

del listStr[len(listStr)-1]
# listStr.reverse()

dp = [[0]*13 for _ in range(len(listStr)+1)]
dp[0][0] = 1

INF = 10 ** 9 + 7

for i in range(len(listStr)):
    if i ==0:
        keta = 1
    else:
        keta = pow(10, i)

    if listStr[i] == "?":
        for k in range(10):
            for j in range(13):
                dp[i+1][int(((k*keta)%13 + j) % 13)] += dp[i][j]
                # dp[i + 1][int(((k * ordinal) + j) % 13)] %= INF
    else:
        k = int(listStr[i])
        for j in range(13):
            dp[i + 1][int(((k*keta)%13 + j) % 13)] += dp[i][j]
            # dp[i + 1][int(((k*ordinal) + j) % 13)] %= INF


ans = dp[len(listStr)][5] % INF
print(ans)

### FIXED CODE ###

import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
nb = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    l = len(s)
    dp = [[0 for _ in range(13)] for __ in range(l + 1)]
    dp[0][0] = 1

    for i, si in enumerate(s):
        base = pow(10, l - i - 1, 13)

        if si == "?":
            for k in range(10):
                tmp = base * k % 13
                for j in range(13):
                    dp[i + 1][(j + tmp) % 13] += dp[i][j]
                    dp[i + 1][(j + tmp) % 13] %= MOD
        else:
            si = int(si)
            tmp = base * si % 13
            for j in range(13):
                dp[i + 1][(j + tmp) % 13] += dp[i][j]
                dp[i + 1][(j + tmp) % 13] %= MOD

    print(dp[l][5])


if __name__ == '__main__':
    main()
order_time = [0, 0, 0, 0, 0]
order = len(order_time)
time = 0
last_order = 9
count_change = 0

for i in range(0, order):
    order_time[i] = int(input())
    if (order_time[i] % 10 != 0) and (order_time[i] % 10 <= last_order % 10):
        last_order = order_time[i]
        count_change += 1

if count_change == 0:
    last_order = order_time[i]

for i in range(0, order):
    if order_time[i] % 10 != 0:
        time += order_time[i] // 10 * 10 + 10
    else:
        time += order_time[i]

time -= last_order // 10 * 10 + 10
time += last_order

print(time)
order_time = [0, 0, 0, 0, 0]
order = len(order_time)
time = 0
last_order = 9
count_change = 0

for i in range(0, order):
    order_time[i] = int(input())
    if (order_time[i] % 10 != 0) and (order_time[i] % 10 <= last_order % 10):
        last_order = order_time[i]
        count_change += 1

for i in range(0, order):
    if order_time[i] % 10 != 0:
        time += order_time[i] // 10 * 10 + 10
    else:
        time += order_time[i]

if count_change == 0:
    last_order = order_time[i]
else:
    time -= last_order // 10 * 10 + 10
    time += last_order

print(time)


### FIXED CODE ###

order_time = [0, 0, 0, 0, 0]
order = len(order_time)
time = 0
last_order = 9
count_change = 0

for i in range(0, order):
    order_time[i] = int(input())
    if (order_time[i] % 10 != 0) and (order_time[i] % 10 <= last_order % 10):
        last_order = order_time[i]
        count_change += 1

for i in range(0, order):
    if order_time[i] % 10 != 0:
        time += order_time[i] // 10 * 10 + 10
    else:
        time += order_time[i]

if count_change == 0:
    last_order = 0
else:
    time -= last_order // 10 * 10 + 10
    time += last_order

print(time)
from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
f00 = min(A[0],B[0])
f12 = min(A[1],B[0]-f00)
point += f12
point += f0
for i in range(1,n):
    f11 = min(A[i]-f12,B[i])
    point += f11
    f12 = min(A[i+1],B[i]-f11)
    point += f12
print(point)

### FIXED CODE ###

from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
fa = min(A[0],B[0])
fb = min(A[1],B[0]-fa)
point += fb
point += fa
for i in range(1,n):
    fc = min(A[i]-fb,B[i])
    point += fc
    fb = min(A[i+1],B[i]-fc)
    point += fb
print(point)
def solve():
    n = list(input())
    n = [ord(c) - ord('0') for c in n]
    sign = ['-', '+']

    for i in range(2):
        for j in range(2):
            for k in range(2):
                t = n[0]
                t += n[1] * (i * 2 - 1)
                t += n[2] * (j * 2 - 1)
                t += n[3] * (k * 2 - 1)
                if t == 7:
                    print(f'{n[0]}{sign[i]}{n[1]}{sign[j]}{n[2]}{sign[k]}{n[3]}=7')
                    return


if __name__ == "__main__":
    solve()


### FIXED CODE ###

def solve():
    S=list(input())
    for i in range(8):
        ans=int(S[0])
        for j in range(3):
            if (i & (1 << j)) != 0:
                ans+=int(S[j+1])
            else:
                ans-=int(S[j+1])
        if ans==7:
            ans=S[0]
            for j in range(3):
                if (i & (1 << j)) != 0:
                    ans+='+'
                else:
                    ans+='-'
                ans+=S[j+1]
            return ans+'=7'

print(solve())
mount = [[] for i in range(input())]
while True:
    row = raw_input().split()
    if row[0] == 'push':
        mount[int(row[1])-1].append(row[2])
    elif row[0] == 'pop':
        print mount[int(row[1])-1].pop()
    elif row[0] == 'move':
        mount[int(row[2])-1].append(mount[int(row[1])-1].pop())
    elif row[0] == 'quit':
        quit

### FIXED CODE ###

mount = [[] for i in range(input())]
while True:
    row = raw_input().split()
    if row[0] == 'push':
        mount[int(row[1])-1].append(row[2])
    elif row[0] == 'pop':
        print mount[int(row[1])-1].pop()
    elif row[0] == 'move':
        mount[int(row[2])-1].append(mount[int(row[1])-1].pop())
    elif row[0] == 'quit':
        break
A = input("X=?")
B = input("Y=?")
C = input("Z=?")
x = A
A = B
B = x
x = A
A = C
C = x
print(str(A)+" "+str(B)+" "+str(C))

### FIXED CODE ###

A, B, C = map(int, input().split())
x = A
A = B
B = x
x = A
A = C
C = x

print(' '.join(map(str, [A,B,C])))
if A==5 and B==5 and C==7
  or A==5 and B==7 and C==5
  or A==7 and B==5 and C==5;
  print("YES");
else;
  print("NO");
end

### FIXED CODE ###

A,B,C = map(int, input().split())
if A==5 and B==5 and C==7:
  print("YES")
elif A==5 and B==7 and C==5:
  print("YES")
elif A==7 and B==5 and C==5:
  print("YES")
else:
  print("NO")
n = input()
ls = [int(input()) for i in range(n)]
ls = list(set(ls))
print(len(ls))


### FIXED CODE ###

n = int(input())
ls = [int(input()) for i in range(n)]
ls = set(ls)
print(len(ls))
a,b,c=(int(i) for i in input().split())
for i in range(0,9):
  c=a*c-b
  print(int c)


### FIXED CODE ###

a,b=(int(i) for i in input().split())
if a<=5:
  print(0)
elif 5<a<=12:
  print(b//2)
else:
  print(b)
n,m=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[x[0],-x[1]])+[[-1,-1]]
for i in range(n):l[i][0]-=1
w=[0]*(m+1)
i=0
while i<n:
    j=l[i][0]
    s=j
    while l[i][0]==j:
        while w[s]>=l[i][1]:s+=1
        if s<m:w[s]=l[i][1]
        i+=1
print(sum(w))


### FIXED CODE ###

from heapq import heappop, heappush

n,m=map(int,input().split())
a=[]
for i in range(n):
    heappush(a,list(map(int,input().split())))
heap=[]
s=0
for i in range(m):
    while 1:
        if len(a)==0:break
        else:
            if a[0][0]==i+1:heappush(heap,-heappop(a)[1])
            else:break
    if len(heap)>0:s+=-heappop(heap)
print(s)
N, M = map(int,input().split())
H = list(map(int,input().split()))

A = []
B = []
cmb = {}
cnt = 0
flag = 1
ma = [0]*N

for i in range(M):
	a,b = map(int,input().split())

	cmb.setdefault(i, [])
	cmb.setdefault(a-1, []).append(b-1)
	cmb.setdefault(b-1, []).append(a-1)

	ma[a-1] = max(ma[a-1], H[b-1])
	ma[b-1] = max(ma[b-1], H[a-1])
# print(cmb)

for j in range(N):
	# print("展望台:", j)
	k = list(set(cmb[j]))
	# print(k)
	if len(cmb[j])==0:
		# print('正しく分岐')
		cnt+=1
	else:
		# print(H[j], '>', ma[j])

		if H[j] > ma[j]:
			# print('GOOD')
			cnt += 1
print(cnt)

### FIXED CODE ###

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

A = []
B = []
cmb = {}
cnt = 0
flag = 1
ma = [0]*N

for i in range(M):
	a,b = map(int,input().split())

	cmb.setdefault(i, [])
	cmb.setdefault(a-1, []).append(b-1)
	cmb.setdefault(b-1, []).append(a-1)

	ma[a-1] = max(ma[a-1], H[b-1])
	ma[b-1] = max(ma[b-1], H[a-1])
# print(cmb)

for j in range(N):
	# # print("展望台:", j)
	# k = list(set(cmb[j]))
	# # print(k)
	# if len(cmb[j])==0:
	# 	# print('正しく分岐')
	# 	cnt +=1
	# else:
	# 	# print(H[j], '>', ma[j])

	if H[j] > ma[j]:
		# print('GOOD')
		cnt += 1
print(cnt)
A,B = map(int,input().split())
print(int(A * B))

### FIXED CODE ###

A, B = map(float, input().split())
B = B * 100 + 0.1
B = int(B)
print(int(A) * B // 100)
A, B = map(int, input.split())
print(A*B)

### FIXED CODE ###

A, B = map(int, input().split())
print(A*B)
o = list(input())
e = list(input())=['']

for i in range( len(o) ) :
  print(o[i]+e[i],end="")

### FIXED CODE ###

o = list(input())
e = list(input())+['']

for i in range( len(o) ) :
  print(o[i]+e[i],end="")
"""
=int(input())
=map(int,input().split())
=list(map(int,input().split()))

# アレイ import numpy as np =np.array(list(map(float,input().split())))

# 文字列 =list(str(input()).split(" " or ","))

# 一文字＆連番(縦横可能) =map(int, open(0).read().split())

# 2-d list
lis=[[] for _ in range(M)]
for i in range(M):
    lis[i] = list(map(int,input().split()[0:]))

# Each list
N = int(input())
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
"""
import numpy as np


n = int(input())
x=n
pf={}
for i in range(2,int(n**0.5)+1):
    while n % i == 0:
        pf[i] = pf.get(i,0)+1
        n//= i
if n > 1 : pf[n] = 1

from decimal import Decimal
# print((list(pf.keys()))[0]) #素因数分解したときの最小の因数取得
lis=[]
for b in range(-1000000,1000000):
    a=b+int(list(pf.keys())[0])
    siki=Decimal(a**4 + a**3*b + a**2*b**2 + a*b**3 + b**4)
    if siki==Decimal(x/int(list(pf.keys())[0])):
        lis.append((a,b))
print(*lis[0])

### FIXED CODE ###


x=int(input())
A=0
B=0
for a in range(-500,500):
    for b in range(-500,500):
        if a**5-b**5==x:
            A=a
            B=b
            break
print(A,B)
N = int(input())
P = list(map(int, input().split()))

ans = 0
min_v = N


for i in range(0, N):
    if P[i] > min_v: 
        continue
    else:
        min_v = min(P[:i])
        if P[i] <= min_v:
            ans += 1
            min_v = P[i]

print (ans)



### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))

ans = 0
min_v = P[0]

for i in range(0, N):
    if P[i] <= min_v:
        ans += 1
        min_v = P[i]

print (ans)
N,X,M=map(int,input().split())
l=[X]
p=[-1]*(M+1)
p[X]=0
for i in range(N-1):
    x=(l[-1]**2)%M
    if p[x]>=0:
        break
    l.append(x)
    p[x]=i+1
x=p[x]
y=len(l)-x
print(sum(l[:x])+(N-x)//y*sum(l[x:])+sum(l[x:x+(N-x)%y]))

### FIXED CODE ###

N,X,M=map(int,input().split())
l=[X]
p=[-1]*(M+1)
p[X]=0
x=0
for i in range(N-1):
    x=(l[-1]**2)%M
    if p[x]>=0:
        break
    l.append(x)
    p[x]=i+1
x=p[x]
y=len(l)-x
print(sum(l[:x])+(N-x)//y*sum(l[x:])+sum(l[x:x+(N-x)%y]))
W,H,x,y = map(int,input().spilt())
print(W*H/2,1 if (x == W/2 and y == H/2) else W*H/2,0)

### FIXED CODE ###

W,H,x,y = map(int,input().split())
if x == W/2 and y == H/2:
    print(W*H/2,1)
else:
    print(W*H/2,0)
# B - Golden Apple

N, D = map(int, input().split())
print(int((N+2*D)/(2*D+1)))

### FIXED CODE ###

# A - Dodecagon

r = int(input())
print(3*r**2)
n = int(raw_input().strip())
commands = []
for i in range(n):
    commands.append(raw_input().strip())


d = [False]*16777220

def hash(s):
    ret = 0
    i = 0
    for dg in s:
        if dg == 'A':
            ret += 1 * 10**i
        elif dg == 'C':
            ret += 2 * 10**i
        elif dg == 'G':
            ret += 3 * 10**i
        elif dg == 'T':
            ret += 4 * 10**i
        i += 1
    return ret

def insert(d,s):
    h = hash(s)
    d[h] = True

def find(d,s):
    h = hash(s)
    if d[h]: print 'yes'
    else: print 'no'

for c in commands:
    if c[0] == 'i':
        insert(d,c[7:])
    else:
        find(d,c[5:])

### FIXED CODE ###

n = int(raw_input().strip())
commands = []
for i in range(n):
    commands.append(raw_input().strip())


d = [False]*67108870

def hash(s):
    ret = 0
    i = 0
    for dg in s:
        if dg == 'A':
            ret += 0 * 4**i
        elif dg == 'C':
            ret += 1 * 4**i
        elif dg == 'G':
            ret += 2 * 4**i
        elif dg == 'T':
            ret += 3 * 4**i
        i += 1
    return ret

def insert(d,s):
    h = hash(s)
    d[h] = True

def find(d,s):
    h = hash(s)
    if d[h]: print 'yes'
    else: print 'no'

for c in commands:
    c += 'C'
    if c[0] == 'i':
        insert(d,c[7:])
    else:
        find(d,c[5:])
a, p = map(int, input())
print((3 * a + p) // 2)


### FIXED CODE ###

a, p = map(int, input().split())
print((3 * a + p) // 2)
n,a,b=int(input().strip().split)

train=n*a
taxi=b

fare=min(taxi,train)

print(str(fare))

### FIXED CODE ###

n,a,b=input().strip().split()
n,a,b=[int(n),int(a),int(b)]

if n*a>b:
  print(b)
else:
  print(n*a)
N = int(input())
W = int,input().split()
list = []
for n in range(N):
  a = 1
  b = n + 1
  Down = 0
  Up = 0
  while a <= n:
    Down += W[a - 1]
    a += 1
  while b <= N:
    Up += W[b - 1]
    b += 1
  list.append(abs(Down - Up))
list.sort()
print(list[0])

### FIXED CODE ###

N = int(input())
W = list(map(int,input().split()))
list = []
for n in range(N):
  a = 1
  b = n + 1
  Down = 0
  Up = 0
  while a <= n:
    Down += W[a - 1]
    a += 1
  while b <= N:
    Up += W[b - 1]
    b += 1
  list.append(abs(Down - Up))
list.sort()
print(list[0])