CodeEff/ECCO huggingface dataset:
# Original solution

count = 0
N = int(eval(input()))
A = list(map(int, input().split()))
B =[x for x in range(1,N+1)]
C = list(zip(A, B))
D = [sorted(x) for x in C]
for i in range(N):
  if D.count(D[i]) == 2:
    count += 1
    
print((int(count/2)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
count = 0

for i in range(N):
  if A[A[i]-1] == i + 1:
    count += 1

print((int(count / 2)))
# Original solution
def main():
    N = int(eval(input()))
    A = [int(i)-1 for i in input().split()]

    edge = [set() for _ in range(N)]

    for i, a in enumerate(A):
        edge[i].add(a)

    ans = 0
    for i, a in enumerate(A):
        if i in edge[a]:
            ans += 1
    print((ans//2))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N = int(eval(input()))
    A = [int(i)-1 for i in input().split()]

    ans = 0
    for i, a in enumerate(A):
        if A[a] == i:
            ans += 1
    print((ans//2))


if __name__ == '__main__':
    main()
# Original solution
# codefestival_2016_qualA_b.py
N = int(eval(input()))
A = list(map(int,input().split()))
cnt = 0
for i,v in enumerate(A):
    if A[v-1] == i+1:
        cnt += 1
print((cnt//2))

# Optimized solution
# codefestival_2016_qualA_b_bacha.py
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
for i,v in enumerate(A):
    # print(i ,v, A[v-1])
    if i+1 == A[v-1]:
        ans += 1
print((ans//2))
# Original solution
from itertools import*
n, *a = list(map(int, open(0).read().split()))
print((sum(a[i] == j + 1 and a[j] == i + 1 for i, j in combinations(list(range(n)), 2))))

# Optimized solution
n, *a = list(map(int, open(0).read().split()))
print((sum(a[b - 1] == e + 1 for e, b in enumerate(a)) // 2))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
pair = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        if a[i]==j+1 and a[j]==i+1:
            pair += 1
print(pair)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
pair = 0
for i in range(0,n):
    if a[a[i]-1]==i+1:
        pair+=1
print((pair//2))
# Original solution
from collections import defaultdict

n = int(eval(input()))
a = list(map(int, input().split()))
a = {i+1: v for i, v in enumerate(a)}
cnt = 0
for k, v in list(a.items()):
    if k == a[v]:
        cnt += 1
print((cnt//2))


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
a = {i+1: v for i, v in enumerate(a)}
cnt = 0
for k, v in list(a.items()):
    if k == a[v]:
        cnt += 1
print((cnt//2))
# Original solution
n = int(eval(input()))
A = tuple([int(x)-1 for x in input().split()])

paired = [0] * n
c = 0
for i in range(n-1):
    if paired[i]:
        continue

    for j in range(i+1, n):
        if A[i] == j and A[j] == i:
            paired[j] = 1
            paired[i] = 1
            c += 1
            break
print(c)


# Optimized solution
n = int(eval(input()))
A = tuple([int(x)-1 for x in input().split()])

paired = [0] * n
c = 0
for i in range(n-1):
    if paired[i]:
        continue

    if A[A[i]] == i:
        c += 1
        paired[A[i]] = 1

print(c)
# Original solution
N=int(eval(input()))
*A,=list(map(int,input().split()))
i=0
ans=0
while i<N:
    if i+1 in A:
        if A[i]==A.index(i+1)+1:
            ans+=1
    i+=1
print((ans//2))

# Optimized solution
N=int(eval(input()))
*A,=list(map(int,input().split()))
i=0
ans=0
while i<N:
    if i+1==A[A[i]-1]:
        ans+=1
    i+=1
print((ans//2))
# Original solution
N = int(eval(input()))
s = list(map(int ,input().split()))
con = 0
for i in range(N):
  for j in range(i + 1 , N):
    if s[i] == j + 1 and s[j] == i + 1:
      con += 1
print(con)

# Optimized solution
N = int(eval(input()))
s = list(map(int ,input().split()))
con = 0
for i in range(N):
  if s[s[i] - 1] == i + 1:
    con += 1
print((con // 2))
# Original solution
N=int(eval(input()))
a=list(map(int,input().split()))
b=0
for i in range(N):
    for j in range(i+1,N):
        if a[i]==j+1 and a[j]==i+1:
            b+=1
print(b)

# Optimized solution
N=int(eval(input()))
a=list(map(int,input().split()))
b=0
for i in range(N):
    if i+1==a[a[i]-1]:
        b+=1
print((b//2))
# Original solution
if __name__ == "__main__":
    n = int(eval(input()))
    a = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        if a[a[i]-1] == i+1:
            ans += 1

    print((ans // 2))


# Optimized solution
if __name__ == "__main__":
    n = int(eval(input()))
    a = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        if a[a[i]-1] - 1 == i:
            ans += 1

    print((ans//2))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
list1 = []
for i in range(n) :
    list1.append({a[i],i+1})
length1 = len(list1)
list2 = []
for num in list1 :
    if not num in list2 :
        list2.append(num)
length2 = len(list2)
print((length1-length2))


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n) :
    if a[a[i]-1] == i + 1 :
        ans += 1
print((ans//2))
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
cnt=0
for idx,i in enumerate(A):
    a_idx=1+idx

    if idx==A[i-1]-1:
        cnt+=1
print((cnt//2))



# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
cnt=0
for idx,i in enumerate(A):
    if idx==A[i-1]-1:
        cnt+=1
print((cnt//2))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))

c = 0
for i in range(n-1):
    for j in range(i+1,n):
        if (a[i] == j+1) and (a[j] == i+1):
            c += 1

print(c)

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

c = 0

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

print((c//2))
# Original solution
N = int(eval(input()))
A = [int(x) for x in input().split()]

like = []
cnt = 0
for i in range(N):
    s = set([A[i], i+1])
    if s in like:
        cnt+=1
    else:
        like.append(s)
print(cnt)


# Optimized solution
N = int(eval(input()))
A = [int(x) for x in input().split()]

like = []
cnt = 0
for i in range(N):
    if A[A[i]-1] == i+1:
        cnt+=1
print((cnt//2))
# Original solution
n = int(eval(input()))
l = input().split(' ')
t_l =[]
for i in range(0,n):
   t = i + int(l[i])
   t_l.append(t)
a = 0
for i in range(n *2 -1):
    if t_l.count(i) == 2:
        a += 1
print(a)

# Optimized solution
n = int(eval(input()))
a = input().split(' ')
t = 0
for o in range(n):
    i = o + 1
    b = int(a[o]) - i
    if i == int(a[o + b]):
      t += 1
print((int(t / 2)))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  for j in range(i+1,n):
    if a[i]==j+1 and a[j]==i+1:
      cnt+=1
      break
    else:
      cnt=cnt
print(cnt)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]-1]==i+1:
      cnt+=1
    else:
      cnt=cnt
print((cnt//2))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))

c = 0
for i in range(N):
    for j in range(N):
        if i < j:
            if A[i] == j+1 and A[j] == i+1:
                c += 1
print(c)
    

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

c = 0
for i in range(N):
    if A[A[i]-1] == i+1:
        c += 1
print((int(c//2)))
# Original solution
n = int(eval(input()))
a_list = list(map(int, input().split()))

cnt = 0
index_list = list(range(0,n,1))

for i in (index_list):
    if a_list[a_list[i]-1] == i+1:
        cnt += 1
print((cnt//2))

# Optimized solution
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if a[a[i]-1] == i + 1:
        cnt += 1
print((cnt//2))
# Original solution
n = int(eval(input()))
l = [0] + list(map(int, input().split()))
cnt = 0
for i in range(1, n+1):
  if l[l[i]] == i:
    cnt += 1
print((cnt//2))

# Optimized solution
n = int(eval(input()))
a = [1] + list(map(int, input().split()))
cnt = 0
for i in range(1,n+1):
  if a[a[i]] == i:
    cnt += 1
print((cnt//2))
# Original solution
N=int(eval(input()))
a=[int(i)-1 for i in input().split()]
K=0
for i in range(N):
  if a[a[i]]==i:
    K+=1
print((K//2))


# Optimized solution
N=int(eval(input()))
a=[int(i)-1 for i in input().split()]
ans=0
for i in range(N):
  if a[a[i]]==i:
    ans+=1
print((ans//2))
# Original solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

like=[set() for i in range(N)]
cnt=0
for i in range(N):
    if i+1<A[i]:
        like[A[i]-1].add(i+1)
    else:
        if A[i] in like[i]:
            cnt+=1
print(cnt)


# Optimized solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

cnt=0
for i in range(N):
    if A[A[i]-1]==i+1:
        cnt+=1
print((cnt//2))
# Original solution
number = int(eval(input()))
a = list(map(int,input().split()))
count = 0
for i in range(number):
    for j in range(i,number):
        if a[i] ==j+1 and a[j] == i+1:
            count += 1
print((int(count)))

# Optimized solution
number = int(eval(input()))
a = list(map(int,input().split()))
count = 0
for i in range(number):
    j = a[i]-1
    if a[j] == i + 1:
        count += 1
print((int(count/2)))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
c=0
for i in range(n):
    if i+1==a[a[i]-1]:
        c+=1
        a[i]=n+2
print(c)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
c=0
for i in range(n):
    if i+1==a[a[i]-1]:
        c+=1
        a[i]=0
print(c)
# Original solution
s=0;n=int(eval(input()));*a,=list(map(int,input().split()))
for i in range(~-n):s+=(-~i<a[i])*(a[~-a[i]]==-~i)
print(s)

# Optimized solution
n=int(eval(input()));*a,=list(map(int,input().split()))
print((sum([a[~-a[i]]==-~i for i in range(n)])>>1))
# Original solution
n = int(eval(input()))
a = [0] + list(map(int, input().split()))

G = [[] for _ in range(n + 1)]

for i in range(1, n + 1):
	G[a[i]].append(i)

cnt = 0
for i in range(1, n + 1):
	if a[i] in G[i] and i in G[a[i]]:
		cnt += 1
print((cnt // 2))

# Optimized solution
n = int(eval(input()))
a = [0] + list(map(int, input().split()))

cnt = 0
for i in range(1, n + 1):
	if a[a[i]] == i:
		cnt += 1

print((cnt // 2))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

ans = 0

for i in range(n):
  a[i] -= 1

for i in range(n):
  for j in range(i+1, n):
    if a[i] == j and a[j] == i:
      ans += 1
      
print(ans)

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

ans = 0

for i in range(n):
  a[i] -= 1

for i in range(n):
  if a[a[i]] == i:
    ans += 1
      
print((ans//2))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

ans = 0
for i in range(N):
  if i + 1 == A[A[i] - 1]:
    ans += 1

print((ans // 2))


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

ans = 0
for i in range(N):
  if A[A[i] - 1] == i + 1:
    ans += 1
ans //= 2

print(ans)
# Original solution
from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
pair = []
cp = [None]
for i, tgt in enumerate(a):
    cp.clear()
    if a.index(tgt) == i:
        cp = [str(a[i]), str(i + 1)]
        cp.sort()
        cpj = "".join(cp)
        pair.append(cpj)

pcnt = Counter(pair)
pcv = list(pcnt.values())
print((pcv.count(2)))


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i, tgt in enumerate(a, 1):
    if a[tgt - 1] == i:
        cnt += 1
print((cnt // 2))
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
ai = []
 
for i, j in enumerate(a):
    ai.append([i+1,j])
    ai[i].sort()
 
c = 0
for i in range(len(ai)):
    c += ai.count(ai[i])
 
print((c // 4))

# Optimized solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
ai = []

for i, j in enumerate(a):
    ai.append([i+1,j])
    ai[i].sort()

print((len(ai) - len(list(map(list,set(map(tuple, ai)))))))
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [i - 1 for i in list(map(int, input().rstrip('\n').split()))]
    cnt = 0
    for i in range(len(a)):
        if i == a[a[i]]:
            cnt += 1
    print((cnt // 2))


if __name__ == '__main__':
    slove()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    cnt = 0
    for i in range(n):
        if i + 1 == a[a[i]-1]:
            cnt += 1
    print((cnt // 2))


if __name__ == '__main__':
    solve()
# Original solution
N = int(eval(input()))
A = [int(a) - 1 for a in input().split()]
liked = [set() for _ in range(N)]
for i in range(N):
    liked[A[i]].add(i)

count = 0
for i in range(N):
    if A[i] in liked[i]:
        count += 1

print((count // 2))

# Optimized solution
N = int(eval(input()))
A = [int(a) - 1 for a in input().split()]
count = 0
for i in range(N):
    if i == A[A[i]]:
        count += 1

print((count // 2))
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))

cnt = 0
for itr, val in enumerate(A):
  if A[val - 1] == itr + 1:
    cnt += 1
    
print((cnt // 2))

# Optimized solution
# B - 仲良しうさぎ
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_b

n = int(eval(input()))
A = list(map(int, input().split()))

ans = 0
for itr, a in enumerate(A):
  if a - 1 > itr and A[a - 1] == itr + 1:
    ans += 1

print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  if a[a[i]-1]-1==i :
    cnt+=1
print((cnt//2))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
cnt=[i for i in range(n) if a[a[i]-1]-1==i]
print((len(cnt)//2))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
res = 0
for i in range(n-1):
    for j in range(i+1,n):
        if a[i]==j+1 and a[j]==i+1:
            res += 1
print(res)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
res = 0
for i in range(n):
    if a[i]>i+1 and a[a[i]-1]==i+1:
        res += 1
print(res)
# Original solution
N = int(eval(input()))
A = [0] + list(map(int, input().split()))
ans2 = 0
for i in range(N+1):
    if A[A[i]] == i: ans2 += 1
print((ans2//2))

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

B=[0]*N

for i,a in enumerate(A):
    if A[a-1] == i+1: B[i] = 1

print((sum(B)//2))
# Original solution
N=int(eval(input()))
*A,=list(map(int, input().split()))
A=[-1]+A
ans=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        if A[i]==j and A[j]==i: ans+=1
print(ans)

# Optimized solution
N=int(eval(input()))
*A,=list(map(int, input().split()))
A=[-1]+A
ans=0
for i in range(1,N+1):
    j=A[i]
    if j>i and A[j]==i: ans+=1
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

li = [None]*N

ans = 0

for i, a in enumerate(A):
    if [a, i+1] in li:
        ans += 1
    li[i] = [i+1, a]

print(ans)

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

ans = 0

for i in range(N):
    if (i+1)==A[A[i]-1]:
        ans += 1

print((ans//2))
# Original solution
N = int(eval(input()))

A = [int(x) - 1 for x in input().split()]

cnt = 0
for i in range(N):
    if A[A[i]] == i:
        cnt += 1

print((cnt//2))

# Optimized solution
n = int(eval(input()))
a = [int(x)-1 for x in input().split()]

b = []
c = []
for i in range(n):
	b.append((i, a[i]))
	c.append((a[i], i))

c = set(c)
b = set(b)

ans = len(b & c)
print((ans//2))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

st = set()
cnt = 0
for i, e in enumerate(a, 1):
    pair = min(i, e), max(i, e)
    if pair in st:
        cnt += 1
    else:
        st.add(pair)

print(cnt)


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

cnt = 0
for i, e in enumerate(a, 1):
    if a[e-1] == i:
        cnt += 1

cnt //= 2
print(cnt)
# Original solution
n=int(eval(input()))
a = list(map(int,input().split()))
check=[]
ans=0
for i in range(n):
    if [min(i+1,a[i]),max(i+1,a[i])] not in check:
        check.append([min(i+1,a[i]),max(i+1,a[i])])
    else:
        ans+=1
print(ans)


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
pair=[]
for i in range(n):
    if i+1 > a[i]:
        w=i+1
        i=a[i]
    else:
        w=a[i]
        i+=1
    pair.append([i,w])
pair.sort()
ans=0
for i in range(len(pair)-1):
    if pair[i]==pair[i+1]:
        ans+=1
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

answer = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] == j + 1 and A[j] == i + 1:
            answer += 1

print(answer)

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

answer = 0
for i in range(N):
    if a[a[i] - 1] - 1 == i:
        answer += 1

print((answer // 2))
# Original solution
N = int(eval(input()))
A = [int(i)-1 for i in input().split()]

ans = 0
for i,a in enumerate(A):
  if i == A[a] and i < a:
    ans += 1
print(ans)

# Optimized solution
N = int(eval(input()))
A = [int(i) - 1 for i in input().split()]
print((len([1 for i, a in enumerate(A) if i == A[a] and i < a])))
# Original solution
N = int(eval(input()))
A = [int(i) for i in input().split()]
arr = [[False for i in range(N)] for j in range(N)]
cnt = 0
for ind, val in enumerate(A):
  arr[ind][val-1] = True
  if arr[val-1][ind] == True:
    cnt += 1

print(cnt)

# Optimized solution
N = int(eval(input()))
A = [int(i) for i in input().split()]
cnt = 0
for i, a in enumerate(A):
  if A[a-1]-1 == i:
    cnt += 1
  
print((cnt//2))
# Original solution
N = int(eval(input()))
A = [int(e)-1 for e in input().split()]

ad = [set() for _ in range(N)]

for i, a in enumerate(A):
    ad[a].add(i)

ans = 0

for i, a in enumerate(A):
    if a in ad[i]:
        ans += 1

print((ans//2))

# Optimized solution
N = int(eval(input()))
A = [int(e)-1 for e in input().split()]

ans = 0

for i, a in enumerate(A):
    if A[a] == i:
        ans += 1

ans //= 2 
print(ans)
# Original solution
N = int(eval(input()))
li = [int(i) for i in input().split()]

# タプルを作って裏返したペアが存在するかどうか
tupple = []
for i in range(N) :
    s = str(i+1) + ' ' + str(li[i])
    tupple.append(s)

c = 0
for tup in tupple :
    t = tup.split()
    needle = t[1] + ' ' + t[0]
    if needle in tupple :
        c += 1

print((c//2))

# Optimized solution
N = int(eval(input()))
li = [int(i) for i in input().split()]

c = 0
for i in range(1,N+1) :
    # iを基準に行って帰ってこれればOK
    if (i == li[li[i-1]-1]) :
        c += 1

print((c//2))
# Original solution
a,p=list(map(int,input().split()))
pye=int((a*3+p)/2)
print(pye)

# Optimized solution
a,p=list(map(int,input().split()))
print((int((a*3+p)/2)))
# Original solution
A, P = list(map(int, input().split()))
P = A * 3 + P
print((P // 2))

# Optimized solution
A, P = list(map(int, input().split()))

print(((A * 3 + P) // 2))
# Original solution
a,p = list(map(int,input().split()))
print(((3*a+p)//2))

# Optimized solution
a,b = list(map(int,input().split()))
print(((3*a+b)//2))
# Original solution
import math
i=list(map(int,input().split()))
a=i[0]*3+i[1]
print((math.floor(a/2)))

# Optimized solution
a,p=list(map(int,input().split()))
print(((a*3+p)//2))
# Original solution
a,p = list(map(int, input().split()))

n = 3*a
ans = (n+p) // 2
print(ans)

# Optimized solution
a,p = list(map(int, input().split()))
num =(3*a + p)//2
print(num)
# Original solution
A, P = list(map(int, input().split()))

print(((A * 3 + P) // 2))

# Optimized solution
A, P = list(map(int, input().split()))
P += A * 3

print((P // 2))
# Original solution
A,P = list(map(int,input().split()))
print(((A*3+P)//2))

# Optimized solution
a, p = list(map(int, input().split()))
print(((a * 3 + p) // 2))
# Original solution
A,P = list(map(int,input().split()))



a=((P + A * 3) // 2)
print(a)

# Optimized solution
A,P = list(map(int,input().split()))
print(((P + A * 3) // 2))
# Original solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,p = LI()
    print(((a*3+p)//2))
    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,p = LI()
    p += 3*a
    print((p>>1))
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution
A,P = list(map(int,input().split()))
n = 3*A+P
print((n//2))

# Optimized solution
A,P = list(map(int,input().split()))
print(((3*A+P)//2))
# Original solution
A, P = list(map(int, input().split()))

P += A * 3

pie = P // 2

print(pie)


# Optimized solution
def resolve():
  a, p = list(map(int, input().split()))
  print(((a*3+p) // 2))
  return

if __name__ == "__main__":
  resolve()
# Original solution
A,P = list(map(int,input().split()))
print(((3*A+P)//2))

# Optimized solution
print((eval(input().replace(" ","*3+"))//2))
# Original solution
A, P = list(map(int, input().split()))
P += 3 * A
print((P//2))

# Optimized solution
a,p=list(map(int,input().split()))
print((int((3 * a + p) / 2)))
# Original solution
A, P = list(map(int, input().split()))

x = (A * 3) + P

if x >= 2:
  y = x / 2
else:
  y = 0

print((int(y)))

# Optimized solution
A, P = list(map(int, input().split()))

x = A*3 + P

print((x//2))
# Original solution
A,P = list(map(int,input().split()))

P = P + A*3

print((P//2))

# Optimized solution
A,P = list(map(int,input().split()))

P += A*3

print((P//2))