-
Notifications
You must be signed in to change notification settings - Fork 0
/
1880_timus.py
executable file
·43 lines (38 loc) · 1.5 KB
/
1880_timus.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Входные данные состоят из трёх блоков по две строки. Первая строка каждого блока
содержит целое число n —количество собственных чисел очередного игрока
(1 ≤ n ≤ 4 000). Во второй строке блока записано n целых различных чисел
в порядке возрастания — собственные числа очередного игрока.
Все собственные числа — целые, положительные и не превосходят 10^9.
Выведите количество собственных чисел команды Psych Up.
"""
def appnd(n):
if n == 0:
return []
else:
count = int(input())
if count == 0:
return [] + appnd(n-1)
return [int(x) for x in input().split()][:count] + appnd(n-1)
def three_counter(lst):
if lst == []:
return 0
else:
count, nlist = list_minus_elem(lst[0],lst)
return count + three_counter(nlist)
def list_minus_elem(elem, lst):
nlst = cln(elem, lst)
count = len(lst) - len(nlst) == 3 and 1 or 0
return (count,nlst)
def cln(elem, lst):
if lst == []:
return []
else:
if lst[0] == elem:
return cln(elem, lst[1:])
else:
return [lst[0]] + cln(elem, lst[1:])
lst = appnd(3)
print(three_counter(lst))