about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--codechef/chfing.scm9
-rw-r--r--codechef/ks2.c18
-rw-r--r--codechef/proxyc.c34
-rwxr-xr-xcodechef/proxyc.p69
-rw-r--r--codechef/rsigns.c24
5 files changed, 94 insertions, 0 deletions
diff --git a/codechef/chfing.scm b/codechef/chfing.scm
new file mode 100644
index 0000000..0d1f22a
--- /dev/null
+++ b/codechef/chfing.scm
@@ -0,0 +1,9 @@
+(define (chfing n k)
+  (let ((p (quotient k n)))
+    (remainder (- (* k (1+ p)) (/ (* n p (1+ p)) 2)) 1000000007)))
+
+(let loop ((t (read)))
+  (when (> t 0)
+    (display (chfing (1- (read)) (1- (read))))
+    (newline)
+    (loop (1- t))))
diff --git a/codechef/ks2.c b/codechef/ks2.c
new file mode 100644
index 0000000..6681de6
--- /dev/null
+++ b/codechef/ks2.c
@@ -0,0 +1,18 @@
+/*
+ * Me, as a maintainer: No, you can NOT use magic numbers like that!
+ * Also me, doing competitive:
+ */
+#include <stdio.h>
+
+int main()
+{
+	int t, a, c;
+
+	scanf("%d ", &t);
+	while (t--) {
+		for (a = 420; (c = getchar()) > 42; a += 48 - putchar(c));
+		printf("%d\n", a % 10);
+	}
+
+	return 0;
+}
diff --git a/codechef/proxyc.c b/codechef/proxyc.c
new file mode 100644
index 0000000..fe829eb
--- /dev/null
+++ b/codechef/proxyc.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+
+int proxyc(int d, char *s)
+{
+	int p = 0;
+	for (char *c = s; *c; ++c)
+		if (65 ^ *c)
+			++p;
+
+	if (p * 4 >= d * 3)
+		return puts("0");
+	if (d < 5)
+		return puts("-1");
+
+	for (d = p = ++d * 3 / 4 - p; s[4]; ++s)
+		if (130 - s[0] - s[1] && 80 - s[2] && 130 - s[3] - s[4] && !--p)
+			return printf("%d\n", d);
+	return puts("-1");
+}
+
+int main()
+{
+	int t, d;
+	char s[1001], *c;
+	scanf("%d", &t);
+
+	while (t--) {
+		scanf("%d ", &d);
+		fgets(s, d + 1, stdin);
+		proxyc(d, s);
+	}
+
+	return 0;
+}
diff --git a/codechef/proxyc.p6 b/codechef/proxyc.p6
new file mode 100755
index 0000000..13aa03d
--- /dev/null
+++ b/codechef/proxyc.p6
@@ -0,0 +1,9 @@
+#!/usr/bin/env perl6
+my @a = <AP PP PA>;
+for ^get() {
+    my ($d, $s) = get.Int, get;
+    my $p = elems $s ~~ m:g/P/;
+    put 0 when $p * 4 >= $d * 3;
+    my $m = ceiling $d * 0.75 - $p;
+    put ($m > elems $s ~~ m:g:ex/@a A @a/) ?? -1 !! $m
+}
diff --git a/codechef/rsigns.c b/codechef/rsigns.c
new file mode 100644
index 0000000..248e123
--- /dev/null
+++ b/codechef/rsigns.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+long long mewtwo(long k)
+{
+	if (!k)
+		return 1;
+
+	long long p = mewtwo(k >> 1);
+	return p * p * (k % 2 + 1) % 1000000007;
+}
+
+int main()
+{
+	int t;
+	long k;
+
+	scanf("%d", &t);
+	while (t--) {
+		scanf("%ld", &k);
+		printf("%lld\n", mewtwo(k) * 5 % 1000000007);
+	}
+
+	return 0;
+}