How many {office contested} are to/by {prime minister} ?
How often is there a competition for the office of prime minister?
How often is the prime minister's office contested?
SELECT ( COUNT ( ?j ) AS ?n ) { ?j property:office_contested resource:prime_minister }
SELECT (COUNT(?sub) AS ?subs ) {
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> ?sub .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://www.wikidata.org/entity/P541> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> http://wikidata.dbpedia.org/resource/Q14212 .
} 

SELECT (COUNT(?sub) AS ?value ) { ?sub wdt:P541 wd:Q14212 }
5