about summary refs log tree commit diff
path: root/codechef/msng.py
diff options
context:
space:
mode:
Diffstat (limited to 'codechef/msng.py')
-rwxr-xr-xcodechef/msng.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/codechef/msng.py b/codechef/msng.py
new file mode 100755
index 0000000..bf8b262
--- /dev/null
+++ b/codechef/msng.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+from collections import Counter
+
+for t in range(int(input())):
+    n, x = int(input()), []
+    for i in range(n):
+        b, y = input().split()
+        if b == '-1':
+            guesses = set()
+            for b in range(2, 37):
+                try:
+                    guess = int(y, b)
+                except ValueError:
+                    pass
+                else:
+                    if guess > 10 ** 12: break
+                    guesses.add(guess)
+            x.extend(guesses)
+        else:
+            guess = int(y, int(b))
+            if guess <= 10 ** 12: x.append(guess)
+    try:
+        print(min(k for k, v in Counter(x).items() if v == n))
+    except ValueError:
+        print(-1)