prompt
string
response
string
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.StringTokenizer; public class BearandCompressing { static HashMap<String, String> map; static boolean check(String s){ String t = s; for (int i =...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int foi[30000000]; int ans = 0; int n, k; int v[10]; char str[10]; char a[50]; char b[50]; char c[50]; void brute(int pos) { if (pos == n - 1) { int ok = 1; str[0] = a[v[0]]; str[1] = b[v[0]]; for (int i = 1; i < n - 1; i++) { if (a[v[i]] != c[v[i - ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int dfs(char cur, vector<char>& b, vector<string>& a, int len, int n) { int ans = 0; if (len == n) { return 1; } for (int i = 0; i < (int)b.size(); i++) { if (b[i] == cur) { ans += dfs(a[i][0], b, a, len + 1, n); } } return ans; } int main() { ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> int n, q; char s[40][3], t[40][2]; char r[10]; int ans = 0; bool check() { char now = r[0]; for (int i = 1; i < n; i++) { bool f = false; for (int j = 0; j < q; j++) { if (s[j][0] == now && s[j][1] == r[i]) { f = true; now = t[j][0]; break; } ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int m[6]; string s[40]; char c[40]; int q, n; long long func(int len, char end) { long long r = 0; if (len == 1) return 1; for (int i = 0; i < q; i++) { if (c[i] == end) { r += func(len - 1, s[i][0]); } } return r; } int main() { cin >> n >> q; f...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
def solve(): n, q = map(int, raw_input().split()) ops = [raw_input().split() for _ in xrange(q)] cur_ops = [op[0] for op in ops if op[1] == 'a'] next_ops = [] cur_length = 2 for _ in xrange(2, n): for o in cur_ops: l = o[0] next_ops.extend(op[0] + o for op in ops...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import collections n, q = [int(x) for x in input().split()] g = dict() for i in range(q): to, f = input().split() if f in g: g[f].append(to) else: g[f] = [to] counts = dict() def count(s): if s in counts: return counts[s] if len(s) == n: counts[s] = 1 return 1 if len(s) > n: re...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.awt.Point; import java.io.*; import java.io.ObjectInputStream.GetField; import java.math.MathContext; import java.util.*; import java.util.jar.Attributes.Name; import java.util.logging.Level; public class TestClass { static long mod ; static char[] ans; static long[] F; static long[] IF; st...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.util.*; public class JavaApplication358 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n= sc.nextInt();int q=sc.nextInt(); ArrayList<String> list = new ArrayList(); list.add(""); for(int i=0;i<n;i++){ list= get(list); } ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
from functools import reduce n, q = map(lambda x: int(x), input().split()) substitutions = {} for _ in range(q): from_str, to_str = input().split() if to_str in substitutions: substitutions[to_str].append(from_str) else: substitutions[to_str] = [from_str] def generate_str(start_str): ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int n; unordered_map<string, string> trans; set<string> all; char a[10]; void comb(int idx) { int i; if (idx == n) { string t = ""; for ((i) = 0; (i) < (int)(n); (i)++) { t += a[i]; } all.insert(t); return; } for ((i) = 0; (i) < (int)(6); (...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; map<string, string> m; string junk, temp; int n, q; int main() { ios_base::sync_with_stdio(0); cin >> n >> q; for (int i = 0; i < q; i++) { cin >> junk >> temp; m[junk] = temp; } char a[7] = {'a', 'b', 'c', 'd', 'e', 'f'}; long long count = 0; if (n ==...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; map<char, vector<string> > m; string s; char ch; int len, q, i, ans; void solve(string str, int l) { if (l > len) return; if (l == len) { ++ans; return; } char temp = str[0]; for (auto it : m[temp]) solve(it, l + 1); } int main() { cin >> len >> q; for...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; const int cmx = 1e5 + 5; int n; int q; vector<pair<string, string> > v; bool isOk(string s) { while (1) { if (s.size() == 1) break; bool ok = false; string temp = ""; for (int i = 0; i < v.size(); i++) { string a = v[i].first; string b = v[i].s...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.math.BigInteger; import java.util.*; public class CF { static long res = 0; static int n; static ArrayList<String>[] operations; public static void main(String[] args) { InputReader inputReader = new InputReader(System.in); PrintWriter printWriter = new Pr...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.math.*; import java.util.*; public class Main { static int mod = (int) 1e9 + 7; static int MAX = (int) 1e7; public static void main(String[] args) { FasterScanner s = new FasterScanner(); PrintWriter out = new PrintWriter(System.out); int t = 1; loop: while (t-- > 0) { int...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long max(long long a, long long b) { if (a > b) return a; else return b; } long long min(long long a, long long b) { if (a < b) return a; else return b; ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
n, m = map(int, raw_input().split()) d = {'a':set(), 'b':set(), 'c':set(), 'd':set(), 'e':set(), 'f':set()} for _ in range(m): a, b = raw_input().split() d[b].add(a) length = 0 total = 0 poss = set() def DFS(start): if len(start) == n: poss.add(start) for i in d[start[0]]: if len(start) < n: DFS(i + sta...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
from collections import defaultdict n,k=map(int,input().split()) typ=defaultdict(lambda:[]) for _ in range(k): x,y=input().split() typ[y].append(x[0]) curr=2 val=typ['a'] while(curr<n): temp=[] for i in val: for j in typ[i]: temp.append(j) val=temp curr+=1 print(len(val))
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Collection; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.StringTokenizer; import java.util.Queue; import java.io.BufferedReader; i...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class bearAndCompressing2 { static q[] q; static int sum; static int gl; public static void main(String[] args) throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); String[...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
n, q = map(int, input().split()) l = [[] for i in range(6)] for i in range(q): s = input() l[ord(s[3]) - ord('a')].append(ord(s[0]) - ord('a')) ans = 0 def dfs(node, lvl): global ans if lvl == n - 1: ans += 1 return for i in l[node]: dfs(i, lvl + 1) dfs(0, 0) print (ans)
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; string s = "abcdef"; int rec(string fs, int c, map<string, string>& m, int n) { if (fs.length() == 2) { if (m.count(fs)) fs = m[fs]; else return 0; } if (c == n) { if (fs == "a") return 1; else return 0; } int count = 0; f...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int main() { int n, q, i, j; vector<int> vec[100005]; vector<int> te, temp; string str1; char ch; cin >> n >> q; for (i = 0; i < q; i++) { cin >> str1 >> ch; vec[ch - 97].push_back(str1[0] - 97); } te = vec[0]; for (int k = 2; k < n; k++) { f...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<pair<string, char>> c(q); for (int i = 0; i < q; ++i) { cin >> c[i].first >> c[i].second; swap(c[i].first[0], c[i].first[1]); } unordered_set<string> cur; cu...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; char b[101]; string a[101]; long long dp[11][11]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < k; i++) { cin >> a[i] >> b[i]; } dp[0][0] = 1; for (int i = 1; i < n; i++) { for (int x = 0; x < 6; x++) { for (int j = 0; j < k; j++) ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; public class B { static class Q { char a0, a1, b; Q(char x, char y, char z) { a0 = x; a1 = y; b = z; } } static int n, q; static Q[] str; static long[][] dp = new long[26][10]; static long go(char x, int i...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; long long n, m, k, l, i, j, t, a, b, d[15][15], dp[15][15], res; string s1[40], s2[40]; int main() { cin >> n >> k; for (i = 0; i < k; i++) { cin >> s1[i] >> s2[i]; d[s2[i][0] - 97][s1[i][0] - 97]++; } dp[1][0] = 1; for (i = 1; i <= n; i++) { for (j = ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; string a[44], b[44]; int n, q, ans; void dfs(int l, string cur) { if (l == n) { ans++; return; } for (int i = 1; i <= q; i++) { if (cur[0] != b[i][0]) continue; string nxt = string(cur.begin() + 1, cur.end()); nxt = a[i][0] + nxt; dfs(l + 1, nx...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.util.HashMap; import java.util.Scanner; public class B653 { static HashMap<String, Long> memo; static HashMap<String, String> ops; public static void main(String[]args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int q = in.nextInt(); memo = new HashMap<String, Long>(); ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.BufferedInputStream; import java.io.IOException; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchEx...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.util.*; public class B { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int q = s.nextInt(); String[] a = new String[q]; String[] b = new String[q]; for(int i=0; i<q; i++) { a[i] = s.next(); b[i] = s.next(); ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; template <typename T> T modpow(T base, T exp) { T result = 1; while (exp > 0) { if (exp & 1) result = (result * base); base = (base * base); exp >>= 1; } return result; } int main() { queue<string> poss; long long int n, q; string x, y, poss1; io...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.lang.reflect.Array; import java.math.*; import java.util.*; /** * @author ramilagger * */ public class Main { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; public void solve() throws Exception { ArrayList<String>[] a = new ArrayList[6]; ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; inline int in() { int res = 0; char c; int f = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') f = -1; while (c >= '0' && c <= '9') res = res * 10 + c - '0', c = getchar(); return res * f; } const int N = 100010; vector<string> v[123]; long long an...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; char u[40][3], c[40]; int m[6][6]; int n, q, tol; void dfs(int l, int a, int ans) { if (l == n) { tol += ans; } else { for (int i = 0; i < 6; i++) { if (m[a][i]) { dfs(l + 1, i, ans * m[a][i]); } } } } int main() { char a, b, c; cin...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.util.*; import java.io.*; public class a { public static void main(String[] arg) throws IOException { new a(); } String[] from; String[] to; int n; int qq; public a() throws IOException { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); n = in.nex...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.Collectors; /** * @author ramilagger * */ public class Main { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; public void solve() throws Exception { ArrayList<String>[] a = new ArrayList[6]; ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
//package india; import java.io.*; import java.util.*; public class B { public static void main(String[] args) { BIO io = new BIO(); try { Bsolver solver = new Bsolver(io); } finally { io.close(); } } } class Bsolver { List<Op> ops; Has...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
//Number theory -1 //Graph -1,2,3 //DSU -1, //Div 2C @unsolved->44,45,47,50,53,54,55 import java.util.*; import java.io.*; public class CF653B { //***************************************** VARIABLE DECLERATION SECTION ********************************************************************; //Integer Array...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.util.*; import java.io.*; import java.math.*; public class Main{ /* . . . . . . . some constants . */ static int n,q; static String a[]; static String b[]; static int result=0; static void ozone(String s){ if(s.length()==n){ result++; return; } else{ ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int vis[29]; int vis1[30][30]; long long ans = 0, n; void dfs(int fa, int index, long long flag) { if (index == n - 1) { ans += flag * vis[fa]; return; } for (int i = 1; i <= 26; i++) { if (vis1[fa][i]) { dfs(i, index + 1, flag * vis1[fa][i]); } ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.util.*; public class B { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; int[][] a; boolean good(int[] b) { b = b.clone(); for (int i = 0; i < b.length - 1; i++) { int nxt = a[b[i]][b[i + 1]]; if (nxt == -1) return false; b[i + 1] = nxt; ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; long long i, j, k; long long n, m, q, ans = 0; long long lo, hi, mi; const long long N = 2e5 + 1; long long a[N], b[N]; long long x, y, z; long long r, l; void solve() { cin >> n >> k; map<char, set<string>> M; string s; char s2; for (i = 0; i < k; ++i) { cin ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
def go(i, s): global ans if i==n: if check(s) : ans+=1 return for c in "abcdef": go(i+1,s+c) def check(s): if not s in dp: dp[s]=0 if len(s)>1: for x in ways[s[0:2]]: dp[s] = check(x + s[2:len(s)]) return dp[s] n, q = input().split() n = int(n) q = int(q) ways = {} for i in "abcdef": for j in...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Random; import java.util.StringTokenizer; import java.util.TreeMap; public class Main { static int MOD = 1000 * 1000 * 100...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.Collection; import java.util.Scanner; import java.util.Queue; import java.util.LinkedList; /** * Built using CHelper plug-in * Actual solution is at the top */ ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.util.Scanner; public class Task02 { static int n,q,rez; static String[] a,b; public static void op(String s) { if(s.length()==n){ rez++; return; }else{ for(int i=0; i<q; i++){ if (s.charAt(0)==b[i].charAt(0)){ op(a[i]+s.substring(1)); } } } } public static void main(St...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
n, q=list(map(int, input().split())) d={i:[] for i in 'abcdef'} for i in range(q): a, b=list(input().split()) d[b].append(a[0]) s=d['a'] for i in range(n-2): s0=s s=[] for i in s0: s+=d[i] print(len(s))
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.util.*; public class B653 { static int n, q; static HashMap<String, Character> map; static char[] two = new char[2]; public static boolean check( ){ String s = new String(two); if(map.containsKey(s)){ IO.println("Checking for "+s); ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class A { public s...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import static java.lang.Integer.parseInt; import java.util.TreeMap; public class Main { static TreeMap<String, String> map = new TreeMap<>(); static int cnt = 0, q, n; public st...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int n, q; int c[100][100]; int f[100], g[100]; int main() { scanf("%d%d", &n, &q); for (int i = 1; i <= q; i++) { char ch; int x, y, z; while ((ch = getchar()) <= 32) ; x = ch - 'a'; while ((ch = getchar()) <= 32) ; y = ch - 'a'; ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.util.*; public class b { public static void main(String[] args) throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(System.out); int n = input.nextInt(), m = input.nextInt(); char[][] as = new char[m][2]; char[] bs = new char[m]; for(int i = 0; i<m; i++) { ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.util.*; import java.math.*; public class compress { static int get(String s) { String st=""; for(int i=0;i<s.length();i++) { char ch=s.charAt(i); int n=ch-96; st=st+Integer.toString(n); } return Integer.par...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; map<char, vector<string>> mapa; map<string, bool> used; int n, q, ans = 0; int cal(string s) { if (used[s]) return 0; if (s.size() == n) return 1; int r = 0; for (int i = 0; i < mapa[s[0]].size(); i++) { r += cal(mapa[s[0]][i] + s.substr(1, s.size() - 1)); } ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; const int OO = (int)1e9 + 7; const int MX = (int)1e3 + 7; const int mod = (int)1e9 + 7; const double EPS = 1e-6; const double PI = 3.1415926; int n, q; pair<string, char> s[MX]; long long get(char c, int cnt) { if (cnt == n - 1) { return 1; } long long ret = 0; ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); } int n; map<char, vector<string> > comp; long long fun(int opt, char x) { if (opt == n - 1) return 1; map<char, vector<str...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int n, q, len; map<string, string> st; string in[40]; int ans; void dfs(string s, int left) { if (left <= 1) { if (s == "a") ans++; return; } for (int i = 0; i < 6; i++) { int l = left; char c = 'a' + i; if (!st.count(s + c)) continue; l--; ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
def dfs(s,k): global c if k==n: c+=1 return else: if s in adj: for u in adj[s]: dfs(u[0],k+1) else: return n,q=map(int,input().split()) adj={} for w in range(q): a,b=input().split() if b not in adj: adj[b]=[a] ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
from itertools import product as comb word = "abcdef" n, q = map(int, input().split()) rep = dict() for _ in range(q): k, v = input().split() rep[k] = v ret = set() for x in comb(word, repeat=n): tmp = "".join(x) while len(tmp) > 1: before = tmp if tmp[:2] not in rep: break ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
temp = input().split(" ") maxLength, initialCount = [int(x) for x in temp] dataSet = dict() for i in range(initialCount): temp = input().split(" ") a, b = [x for x in temp] if not b in dataSet.keys(): dataSet[b] = set() dataSet[b].add(a) def populate(toValue): fromValues = set() if toV...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.util.*; public class Main implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); out =...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; struct In { inline In operator>>(int &p) const { int re = 0; register int n = 0, sign = 1, a = getchar(); while (a < '0' || a > '9') { if (a == '-') { sign = -1; a = getchar(); break; } a = getchar(); } while (...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
def dfs(rest, head): if rest==0 : return 1 tmp = 0 for i in g[head]: tmp = tmp + dfs(rest-1, i[0]) return tmp n,q = map(int, raw_input().split()) g = {} for i in range(6): g[chr(i+97)] = [] for i in range(q): a,b = raw_input().split() g[b].append(a) print dfs(n-1, 'a')
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; vector<string> vec; vector<pair<string, string> > var; int n, k; void solve(string str) { if (str.size() == n) { vec.push_back(str); return; } solve(str + 'a'); solve(str + 'b'); solve(str + 'c'); solve(str + 'd'); solve(str + 'e'); solve(str + 'f');...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.BufferedReader; import java.io.InputStreamReader; public class B { static class Q { char a0, a1, b; Q(char x, char y, char z) { a0 = x; a1 = y; b = z; } } static int n, q; static Q[] str; static long[][] dp = new long[26][6]; static long go(char x, int i) { if (i == 0) retur...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.awt.Point; import java.io.*; import java.math.BigInteger; import java.util.*; import java.text.*; /** * * @author zulka...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.io.BufferedReader; import java.util.Map; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; set<string> vis; set<string> sol; int n, q; const int N = 36; string a[N]; char b[N]; void dfs(const string &s) { if ((int)s.length() == n) { sol.insert(s); return; } if (vis.count(s)) { return; } vis.insert(s); for...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
a,b=map(int,input().split());c=[input().split() for _ in " "*b];z=['a'];t=[] for i in range(1,a): for j in z: for k in c: if j[0]==k[1]:t.append(k[0]+j[1::]) z=t;t=[] print(len(z))
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int v[60]; char aa[6] = {'a', 'b', 'c', 'd', 'e', 'f'}; map<string, char> m; long long solve(string s) { if (s.size() == 1 && s[0] == 'a') return 1; if (s.size() == 1) return 0; string pre = s.substr(0, 2); string pos = ""; if (s.size() > 2) pos = s.substr(2, s.si...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
//package codeforces; import java.util.HashMap; import java.util.Map; import java.util.Scanner; /** * Created by nitin.s on 19/03/16. */ public class BearAndCompressing { static Map<String, String> available = new HashMap<String, String>(); public static void main(String[] args) { Scanner in = new S...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Artem Gilmudinov */ public...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n >> q; vector<vector<int> > count(6, vector<int>(n)); vector<vector<string> > reduced(6, vector<string>(0)); for (int i = 0; i < n; i++) { for (int j = 0; j < 6; j++) count[j][i] = 0; } for (int i = 0; i < q; i++) { strin...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; set<string> s; vector<vector<string> > g; int n, k; void dfs(string ans) { if (ans.size() == n) { s.insert(ans); return; } for (int i = 0; i < 1; i++) { for (int j = 0; j < g[ans[i] - 'a'].size(); j++) { string ss = g[ans[i] - 'a'][j] + ans...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
n, q = map(int, input().split()) mass = [] count = 0 for i in range(q): mass.append(tuple(input().split())) #print(mass) def transform(string): tmp_mass = [] for i in range(q): if mass[i][1] == string[len(string)-1]: tmp_mass.append(mass[i][0]) return tmp_mass #print(transform('a'))...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
n,q=map(int,input().split()) d={} for _ in range(q): x=input() a,b=x[0],x[-1] if d.get(b)==None:d[b]=[] d[b].append(a) queue=['a'] for _ in range(n-1): lst=[] ex=lst.extend for i,x in enumerate(queue): if d.get(x)!=None:ex(d[x]) queue=lst[:] print(len(queue))
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; char str[10], ss[10]; int n, q, ans; map<string, char> aa; bool judge() { string a; int i = 1; strcpy(ss, str); while (ss[i]) { a = ""; a += ss[i - 1]; a += ss[i]; if (aa[a] >= 'a' && aa[a] <= 'z') ss[i] = aa[a]; else return false; ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; map<string, vector<string> > A; int n, q; map<string, int> cnt; void df(string x) { if (A.find(x.substr(0, 1)) == A.end() || x.size() > n) return; for (int i = 0; i < A[x.substr(0, 1)].size(); i++) { string y = A[x.substr(0, 1)][i] + x.substr(1); cnt[y] += cnt[x...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.util.*; public class Main { private static final String S = "wew"; private final InputReader in; private final PrintWriter out; public Main(final InputReader in, final PrintWriter out) { this.in = in; this.out = out; } private static PrintWriter ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; deque<string> a; deque<string> b; deque<string> c; deque<string> d; deque<string> e; deque<string> f; deque<string> getPair(char ch) { deque<string> ret; ; switch (ch) { case 'a': { for (int i = 0; i < a.size(); i++) ret.push_back(a.at(i)); break; ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.util.*; import java.io.*; /* Mighty Cohadar */ public class Bravo { final int n; final int q; final String[] A; final String[] B; final Set<String> S = new HashSet<>(); public Bravo(int n, int q, String[] A, String[] B) { this.n = n; this.q = q; this.A = A; this.B = B; } public void rec...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
p = ["a", "b", "c", "d", "e", "f"] def cond(item): return item[0] in p and item[1] in p def dp(): arr = [[0 for j in range(6)] for i in range(n)] for j in range(6): arr[0][j] = 1 for i in range(1, n): for j in range(6): for item in d: if cond(item) and d[i...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int(b)) { if (b == 0) return a; return gcd(b, a % b); } void genallStrings(string curr, int n, vector<string> &allStrings) { if (curr.size() == n) allStrings.push_back(curr); else { char x = 'a'; for (int i = 0; i < 6; i++) { char c ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.lang.*; public class Grylls{ public static void main(String[] args) throws Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Print...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
visited = dict() z = dict() n, q = map(int, input().split()) res = 0 def dfs(s): global visited, z, n, res visited[s] = 0 if len(s) == n: res += 1 return for one, two in z.items(): if one == s[0]: for standin in z[s[0]]: if (standin + s[1:]) not in v...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.lang.reflect.Array; import java.util.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { public static void main(String[] args) { new Thread(null, new Main(), "Check2", 1 << 28).start();// to increse stack size in java } void ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.util.*; public class B { public static void solution(BufferedReader reader, PrintWriter out) throws IOException { In in = new In(reader); int n = in.nextInt(), q = in.nextInt(); HashMap<String, String> map = new HashMap<String, String>(); fo...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
d = {} n, q = map(int, raw_input().split()) rules = [] alph = ['a','b','c','d','e','f'] for c in alph: d.setdefault(c, []) for _ in xrange(q): to, fr = raw_input().split() d.setdefault(to[0], []).append(fr) matrix = [{x:0 for x in alph} for y in xrange(n)] matrix[0]['a'] = 1 for x in xrange(1, n): for ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; char a[100][2], b[100]; int n, q; int funk(int pos, int duljina) { if (duljina == 0) { return 1; } int count = 0; int len = duljina; queue<pair<int, int>> s; s.push(make_pair(pos, len)); while (!s.empty()) { if (s.front().second > 0) { for (int i...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
#include <bits/stdc++.h> using namespace std; map<char, set<string> > mp; set<string> an; int n, q; void recur(string s) { if (n == s.size()) { an.insert(s); return; } if (mp[s[0]].empty()) return; char c = s[0]; s.erase(s.begin(), s.begin() + 1); for (auto am : mp[c]) { if (n - s.size() > 2 && ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import itertools import time AAA, BBB = map(int, raw_input().split()) CCC = [] for i in range(BBB): CCC.append(map(str, raw_input().split())) #print CCC EEE = ["a", "b", "c", "d", "e", "f"] FFF = list(itertools.product(EEE, repeat=(AAA))) #print "FFF is " + str(FFF) III = [] for i in range(len(FFF)): HHH = "" for ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.u...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
n,q = map(int,input().split()) ops = dict() for _ in range(q): a,b = input().split() ops[a] = b from itertools import product count = 0 for t in product('abcdef', repeat=n): s = ''.join(t) while len(s) > 1: s = ops.get(s[:2], 'g') + s[2:] count += s == 'a' print(count)
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
# Author : nitish420 -------------------------------------------------------------------- from functools import lru_cache import os import sys from io import BytesIO, IOBase def main(): zz=['a','b','c','d','e','f'] n,q=map(int,input().split()) d=dict() for _ in range(q): z=input().split() d[z[0]]=z[1] ans=0 ...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
import java.io.*; import java.util.*; import java.lang.*; public class Boredom { public static void main(String[] args) throws NumberFormatException, IOException { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); int n,q; n = s.nextInt(); q = s.nextInt(); HashMap<Character, ArrayList<...
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
n, q = map(int, input().split()) d = {ch:'' for ch in 'abcdef'} for i in range(q): a, b = input().split() d[b] += a[0] s = d['a'] for _ in range(n - 2): t = '' for ch in s: t += d[ch] s = t print(len(s))
Problem: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in an...
def search(rules, m): ret = ['a'] for i in range(m - 1): nex = [] for r in ret: r0, tail = r[0], r[1:] for a, b in rules: if a == r0: nex.append(b + tail) ret = nex # print(ret) return len(ret) def main(): line = [...