about summary refs log tree commit diff
path: root/codechef/plmu.c
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-12-16 21:13:07 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-12-16 21:13:07 +0700
commitc1008fe39217be7f91f0ea23483e747bfbc5743e (patch)
treec4f921bccd9e8d66e3aadd9a01ede3300d73afa6 /codechef/plmu.c
parent8a9d6282fcb863c67d6623f5c883ef703721cccd (diff)
downloadcp-c1008fe39217be7f91f0ea23483e747bfbc5743e.tar.gz
The good, the bad and the ugly
Diffstat (limited to 'codechef/plmu.c')
-rw-r--r--codechef/plmu.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/codechef/plmu.c b/codechef/plmu.c
new file mode 100644
index 0000000..04c4b0e
--- /dev/null
+++ b/codechef/plmu.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+int main()
+{
+	char t;
+	size_t n, tmp, zeros, twos;
+
+	scanf("%hhd", &t);
+	while (t--) {
+		scanf("%zu", &n);
+		for (size_t i = zeros = twos = 0; i < n; ++i) {
+			scanf("%zu", &tmp);
+			if (!tmp)
+				zeros++;
+			else if (tmp == 2)
+				twos++;
+		}
+		printf("%zu\n", zeros * (zeros - 1) + twos * (twos - 1) >> 1);
+	}
+
+	return 0;
+}