-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSock Merchant
55 lines (36 loc) · 915 Bytes
/
Sock Merchant
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the sockMerchant function below.
def sockMerchant(n, ar):
pair=[]
new_pair=[]
set1=set(ar)
list1=list(set1)
while(len(list1)>0):
c=0
#print(list1)
for i in range (0,len(ar)):
if ar[i]==list1[-1]:
c=c+1
#print(c)
list1.pop()
#print(list1)
pair.append(c)
#print(pair)
for j in range (0,len(pair)):
if(pair[j]>1):
a = pair[j]//2
new_pair.append(a)
#print(new_pair)
return(sum(new_pair))
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
ar = list(map(int, input().rstrip().split()))
result = sockMerchant(n, ar)
fptr.write(str(result) + '\n')
fptr.close()