about summary refs log tree commit diff
path: root/codechef/msng.py
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-10-14 20:59:08 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-10-14 20:59:08 +0700
commitcacc165173d67fa110766a555afe3020967d220c (patch)
treea859612503a5c4f4d870c074cc19d07b1eb3aed2 /codechef/msng.py
parent4b8df7227736b7c41af56e053d40decc309fe7f9 (diff)
downloadcp-cacc165173d67fa110766a555afe3020967d220c.tar.gz
Practice some C++
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)