counting-triangles

You are given n triangles. 

You are required to find how many triangles are unique out of given triangles.
For each triangle you are given three integers a,b,c , the sides of a
triangle.

A triangle is said to be unique if there is no other triangle with same set of sides.

Note : It is always possible to form triangle with given sides.

INPUT:

First line contains n, the number of triangles. Each of next n lines contain
three integers a,b,c (sides of a triangle).

Output:

print single integer, the number of unique triangles.

Constraints:

1 ≤ n ≤ 10^5
1 ≤ a,b,c ≤ 10^15

SAMPLE INPUT
5
7 6 5
5 7 6
8 2 9
2 3 4
2 4 3 

SAMPLE OUTPUT
1

Explanation

only triangle with sides 8, 2, 9 is unique

Difficulty: EASY
Tags: Sorting

Data structures

Range queries
Skill types: Sorting

Data structures

Range queries

Starter code:

Solutions:
lines = int(input())
s_dict = {}
c = 0

for i in range(lines):
	l = sorted(input().split())
	s = '.'.join(l)
	if s in s_dict:
		s_dict[s] = False
	else:
		s_dict[s] = True

for s, flag in list(s_dict.items()):
	if flag:
		c += 1

print(c)
	


from collections import Counter
n = int(input())
cnt = Counter()
for test in range(n):
	tri = tuple(sorted(map(int,input().split())))
	cnt[tri] += 1
print(len([1 for tri in cnt if cnt[tri]==1]))
	


from collections import defaultdict
dic = defaultdict(int)
count = 0
n = eval(input())
for i in range(n):
	a = list(map(int, input().split()))
	a.sort()
	b = ''.join(map(str, a))
	dic[b] = dic[b]+1
for i in dic:
	if dic[i] == 1:
		count = count + 1
print(count)	


triangles = {}
n = eval(input())
for _ in range(n):
	a,b,c = list(map(int, input().split()))
	t_list = [a, b, c]
	t_list.sort()
	t_list = tuple(t_list)
	if t_list not in triangles:
		triangles[t_list] = 1
	else:
		triangles[t_list] += 1
ans_list = list(triangles.values())
ans = 0
for t in ans_list:
	if t==1: ans += 1
print(ans)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n = int(input())
dic = {}
ans = 0
while n:
	n -= 1
	li = input().split()
	for i in range(0,3):
		li[i] = int(li[i])
	li.sort()
	s = ""
	for i in li:
		s += str(i) + ","
	if s in dic:
		dic[s] = False
	else:
		dic[s] = True
for elem in list(dic.values()):
	if elem:
		ans += 1
print(ans)


n = int(input())
d ={}
ans = 0
for _ in range(n):
	a = list(map(int,input().split()))
	a.sort()
	if d.get((a[0],a[1],a[2])) ==None:
		d[(a[0],a[1],a[2])] = 1
	else:
		d[(a[0],a[1],a[2])] += 1
		
for x in d:
	if d[x] == 1:
		ans+=1
print(ans)


from collections import Counter
list = []
for n in range(eval(input())):
	a, b, c = sorted(map(int, input().split()))
	list.append((a, b, c))
print(list(Counter(list).values()).count(1))


n=eval(input())
c=0
a=[]
d={}
for i in range(n):
	a.append([int(x) for x in input().split()])
	k=str(sum(a[i]))+","+str(a[i][0]*a[i][1]*a[i][2])
	if k not in d:
		d[k]=1
	else:
		d[k]=2
for k in d:
	if d[k]==1:
		c+=1
print(c)

	
	


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''

def make_comparator(less_than):
	def compare(x, y):
			if less_than(x[0], y[0]):
					return -1
			elif less_than(y[0], x[0]):
					return 1
			else:
					if less_than(x[1], y[1]):
						return -1
					elif less_than(y[1], x[1]):
						return 1
					else:
						if less_than(x[2], y[2]):
							return -1
						elif less_than(y[2], x[2]):
							return 1
						else: return 0
	return compare

cmpValue = lambda x,y:  x<y

total = int(input())
all_triangles = [];
for i in range(total):
	next_tr = [int(x) for x in input().split(" ")]
	all_triangles.append( sorted(next_tr) );
	
all_triangles = sorted(all_triangles, cmp=make_comparator(cmpValue))
count = 0
current_count = 0
# print all_triangles
# prev = all_triangles[0]
# next_tr = all_triangles[1]
# print prev, next_tr

# print all_triangles
# print  not (prev[0] == next_tr[0] and prev[1] == next_tr[1] and prev[2] == next_tr[2])
for i in range(0,total-1):
	prev = all_triangles[i]
	next_tr = all_triangles[i+1]
	if(prev[0] == next_tr[0] and prev[1] == next_tr[1] and prev[2] == next_tr[2]):
		current_count += 1
		# print prev, next
	else:
		if current_count > 0:
			current_count = 0
			pass
		else: 
			count += 1
			current_count = 0
	# print count, current_count
	prev = next_tr

prev = all_triangles[total-2]
next_tr = all_triangles[total-1]

if(prev[0] == next_tr[0] and prev[1] == next_tr[1] and prev[2] == next_tr[2]):
	pass
else: count += 1


	
print(count)




num=int(input())
l=[]
for i in range(num):
	s=input()
	s=s.split(" ",len(s))
	fi=s[0]
	se=s[1]
	th=s[2]
	samp=[]
	samp.append(fi)
	samp.append(se)
	samp.append(th)
	samp.sort()
	n=""
	for j in samp:
		n=n+j
	l.append(int(n))
l.sort()
unique=0
for i in range(1,len(l)-1):
	if l[i]!=l[i-1] and l[i]!=l[i+1]:
		unique=unique+1
if l[0]!=l[1]:
	unique=unique+1
if l[num-1]!=l[num-2]:
	unique=unique+1
print(unique)  
	
	
	


from collections import Counter
if __name__ == "__main__":
	print(list(Counter([" ".join(sorted(input().rstrip().split(" "))) for i in range(eval(input()))]).values()).count(1))     
	


n = int(input())
d = {}
count = 0
while n > 0:
	n -= 1
	l = input().split()
	l.sort()
	s = ''.join(l)
	if s not in d:
		d[s] = 1
	else:
		d[s] += 1
for i in d:
	if d[i] == 1:
		count += 1
print(count)


from collections import defaultdict

if __name__ == '__main__':
	temp_dict = defaultdict(int)
	cases = int(input())
	results = 0
	temp = []
	for c in range(cases):
		inp = list(map(int, input().split()))
		inp.sort()
		temp = ''.join(map(str, inp))
		temp_dict[temp] = temp_dict[temp] + 1
	for t in temp_dict:
		if temp_dict.get(t) == 1:
			results = results + 1

	print(results)



from collections import defaultdict
dic = defaultdict(int)
count = 0
n = eval(input())
for i in range(n):
	a = list(map(int, input().split()))
	a.sort()
	b = ''.join(map(str, a))
	dic[b] = dic[b]+1
for i in dic:
	if dic[i] == 1:
		count = count + 1
print(count)	


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n = int(input())
triangleMap = {}
for i in range(n):
	t = input().split()
	if int(t[0])> int(t[1]): t[0],t[1] = t[1],t[0]
	if int(t[1])> int(t[2]): t[1],t[2] = t[2],t[1]
	if int(t[0])> int(t[1]): t[0],t[1] = t[1],t[0]
	m = ''.join(t)
	if m not in triangleMap: triangleMap[m] = 1
	else: triangleMap[m] += 1
solution = 0 
for v in list(triangleMap.values()):
	if v == 1: solution += 1
print(solution)
	


t = eval(input());

sidesPresent = {};

count = 0;
while t > 0:
	sides = input();
	x = sides.split();
	[a,b,c] = sorted(x);
	hashval = a + "|" + b + "|" + c;
	if hashval not in sidesPresent:
		count += 1;
		sidesPresent[hashval] = True;
	elif hashval in sidesPresent:
		if sidesPresent[hashval] == True:
			sidesPresent[hashval] = False;
			count -= 1;
	t -= 1;
print(count);


from collections import Counter
c = Counter()
for _ in range(int(input())):
	c[tuple(sorted(map(int, input().split())))] += 1
print(list(c.values()).count(1))	


t = int(input())
d = {}
count = 0
while t > 0:
	t -= 1
	l = input().split()
	l.sort()
	s = ''.join(l)
	if s in d:
		if d[s] == 1:
			count -= 1
			d[s] += 1
		else:
			d[s] += 1
	else:
		count += 1
		d[s] = 1
print(count)


def count_triangles(D):
	count = 0
	for key in list(D.keys()):
		if D[key] == 1:
			count += 1
	print(count)
	
def test():
	N= int(input())
	counter =0
	D={}
	while counter <N:
		x =[int(x) for x in input().split(' ')]
		x.sort()
		key = ''.join([str(m) for m in x])
		if key in D:
			D[key] +=1
		else:
			D[key]=1
			
		counter += 1

	count_triangles(D)

test()


n = int(input())
unique = set()
multi = set()
for test in range(n):
	tri = tuple(sorted(map(int,input().split())))
	if tri in unique:
		unique.remove(tri)
		multi.add(tri)
	elif tri not in multi:
		unique.add(tri)
print(len(unique))
	


dic={}
c=0
for _ in range(int(input())):
	li=[int(i) for i in input().split()]
	li.sort()
	li=tuple(li)
	if not dic.get(li):
		
		dic[li]=1
	else:
		dic[li]+=1
for i in list(dic.values()):
	if i ==1:
		c+=1    
print(c)
		

		



from collections import defaultdict
n=int(eval(input()))
lis=[]
dic=defaultdict(lambda:0)
count=0
while(n):
	l=list(map(int, input().split()))
	l.sort()
	k="".join(map(str, l));
	dic[k]+=1
	n-=1
for i in dic:
	if(dic[i]==1):
		count+=1
print(count)