n = int(input()) nums = input().split(' ') nums = [int(i) for i in nums]
result = 0 for n inrange(len(nums)): if n == 0: result = nums[n] else: if nums[n] == 1and nums[n-1] == 1: result += 2 elif nums[n] == 1: result += 1 print(result)
[num_monster, mei_hp, mei_atk] = [int(i) for i ininput().split(" ")] monster_hps = [int(i) for i ininput().split(" ")] monster_atks= [int(i) for i ininput().split(" ")] monster_infos = list(zip(monster_atks, monster_hps))
defmax_monsters(atk, hp, monsters): monsters.sort(key=lambda x: x[0]) killed = 0 for monster in monsters: monster_atk, monster_hp = monster if atk > monster_atk and hp > monster_hp: atk = monster_atk hp = monster_hp killed += 1 return killed
defmax_power_of_2(num): m = 0 while num % 2 == 0: num //= 2 m += 1 return m
if __name__ == "__main__": n = int(input()) nums = [int(i) for i ininput().split(' ')] all_weiyu_results = [] for i inrange(2 ** n): comb = bin(i)[2:].zfill(n) weiyus = [] for j inrange(n): if comb[j] == '1': weiyus.append(nums[j])
iflen(weiyus) == 0: continue eliflen(weiyus) == 1: all_weiyu_results.append(max_power_of_2(weiyus[0])) else: result = weiyus[0] for k in weiyus[0]: result = result & k all_weiyu_results.append(max_power_of_2(result)) print(max(all_weiyu_results))
import sys [n, m] = [int(i) for i ininput().split(' ')] roads = [] for line inrange(m): [u,v,w,p] = [int(i) for i ininput().split(' ')] roads.append((u,v,w,p))
defprim_algo(n, roads): network = [] added_cities = [] for road in roads: u,v,w,p = road if p == 1: network.append(road) added_cities.append(u) added_cities.append(v) start_city = 1 added_cities = set(added_cities) whilelen(added_cities) < n: min_cost = float('inf') new_road = None for road in roads: u,v,w,p = road if u in added_cities and v notin added_cities and w < min_cost and p == 0: min_cost = w new_road = road if new_road: network.append(new_road) added_cities.add(new_road[1]) return network
result = prim_algo(n, roads) print(len(result)) result_indexes = [] for i in result: result_indexes.append(str(roads.index(i) + 1)) print(' '.join(result_indexes))