prompt string | response string |
|---|---|
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | n = int(input())
cols = [0 for _ in range(n)]
rows = [0 for _ in range(n)]
for i in range(n):
line = input().strip()
for j in range(len(line)):
if line[j] == 'C':
cols[i] += 1
rows[j] += 1
answ = 0
for i in cols + rows:
answ += (i * (i - 1)) // 2
print(answ)
|
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
char c[110][110];
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> c[i][j];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (c[i][j] == 'C') {
for (int i2 = i + 1; i2 < n; i2... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... |
import java.util.Scanner;
public class JavaApplication3 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int p=0,num=0,op=0;String h="";
int n = sc.nextInt();char[][] A = new char[n][n];
for (int i = 0; i < n; i++) {
String c... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s[101];
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
int row[101] = {0}, col[101] = {0};
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (s[i][j] == 'C') {
row[i]++;
col[j]++;
}
... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... |
import java.awt.Point;
import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;
import javafx.scene.paint.Color;
public class... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | n=int(input())
cnt=0
x=[]
for i in range(n):
x.append(0)
for i in range (n):
l=list(input())
g=l.count('C')
# print(g)
if(g>1):
cnt+=g*(g-1)/2
for j in range (n):
if(l[j]=='C'):
x[j]+=1
#print(x)
for j in range (n):
if (x[j] > 1):
cnt+=x[j]*(x[j]-1)/2
... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class BirthdayCake {
void solve() {
int n = in.nextInt();
int[] row = new int[n], col = new int[n];
for... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | n = int(input())
cke=[]
for i in range(n):
a=[]
s = input()
for j in range(n):
a.append(s[j])
cke.append(a)
c=0
for i in range(n):
for j in range(n):
if cke[i][j]=='C':
for k in range(j+1,n):
if cke[i][k]=='C':
c += 1
for k ... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
char ch[101][101];
int main(void) {
int n, r, c, sum = 0;
cin >> n;
r = c = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> ch[i][j];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (ch[i][j] == 'C... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | import java.io.*;
import java.util.*;
public class A {
public static int [] power(int n){
int b [] = new int[n+1];
b[0] = 0;
b[1] = 0;
for (int i = 2; i <= n; i++)
{
b[i] = (int)((i-1)* i)/ 2;
}
return b;
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | import java.util.*;
public class Main {
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int n, h = 0;
char[][] ca = new char[a][a];
for(int i = 0; i < a; i++)
ca[i] = sc.next().toCharArray();
for(int i = 0; i < a; i++)
{
n = 0;
for(int j =... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, s, t, ans, row[105], col[105];
string x[105], y;
int main() {
cin >> n;
for (i = 0; i < n; i++) cin >> x[i];
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
if (x[i][j] == 'C') {
row[i]++;
col[j]++;
}
}
for (i... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
long long n, an = 0, x = 0;
char a[200][200];
int main() {
cin >> n;
for (int(i) = 0; i < (n); i++) {
x = 0;
for (int(j) = 0; j < (n); j++) {
cin >> a[i][j];
if (a[i][j] == 'C') x++;
}
an += x * (x - 1) / 2;
}
for (int(j) = 0; j < (n); j+... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> cake(n, "");
for (int i = 0; i < n; ++i) {
cin >> cake[i];
}
int64_t count = 0;
for (int i = 0; i < n; ++i) {
int64_t cnt = 0;
for (int j = 0; j < n; ++j) {
if (cake[i][j] == 'C') {
cnt++;
... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | n = int(input())
x = []
v = []
u = []
for i in range(n):
x.append(list(input()))
for i in range(n):
k = 0
for j in range(n):
k += x[i][j]=='C'
v.append(k)
for j in range(n):
k = 0
for i in range(n):
k += x[i][j]=='C'
u.append(k)
r = 0
for i in u:
r += i*(i-1)//2
for i in v:
r += i*(i-1)... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | t=int(input())
k2=[0]*t
s=0
s1=0
for i in range(t):
k=list(map(str,input()))
s=k.count("C")
if s-1>0:
s1+=(s-1)*s//2
for j in range(t):
if k[j]=="C":
k2[j]+=1
for i in range(t):
if k2[i]-1>0:
s1+=(k2[i]-1)*k2[i]//2
print(s1)
|
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
char s[100 + 5][100 + 5];
int n, ans;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%s", s[i]);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = j + 1; k < n; k++)
ans += ((s[i][j] == 'C' && s[i][k] == 'C') +
... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | import java.util.Scanner;
public class main {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int res = 0, numInrow = 0;
String cake[] = new String[n];
for (int i = 0; i < n; i++) {
cake[i] = input.next();
for (... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | import math
def comb(n, k):
if n > 1:
return int(math.factorial(n) / (math.factorial(k) * math.factorial(n - k)))
return 0
n = int(input())
pair_rows = 0
info = [0] * n
pair_columns = 0
for i in range(n):
rows = input()
pair_rows += comb(rows.count("C"), 2)
for x in range(n):
i... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.io.IOException;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author lebegio
*/
public class Main {
pu... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | def s(k):
k -= 1
return int((k + 1) * (k / 2))
n = int(input())
a = []
for i in range(n):
a.append(list(input()))
res = 0
for item in a:
res += s(item.count('C'))
for i in range(n):
cnt = 0
for j in range(n):
if a[j][i] == 'C':
cnt += 1
res += s(cnt)
print(res)
... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
int n, hp = 0, row[100], col[100];
char cake[101][101];
int main() {
for (int i = 0; i < 100; ++i) {
row[i] = 0, col[i] = 0;
}
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> cake[i][j];
if (cake[i][j] == 'C') {
... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | import itertools
def fact(n):
if n<1: return 1
return n*fact(n-1)
n = int(input())
cake = list()
for i in range(n):
s = str(input())
cake.append(s)
result = 0
for i in range(n):
rowCount = 0
for c in cake[i]:
if c == "C":
rowCount += 1
colCount = 0
for j in range(n):
if cake[j][i] == "C":
colCount +... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char arr[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) cin >> arr[i][j];
}
long long result = 0;
long long fact[101];
fact[0] = 0;
for (int i = 1; i < 100; i++) fact[i] = (i * (i - 1)) / 2;
for (int i ... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char arr[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
}
}
pair<int, int> p[n * n];
int in = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr[i... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... |
if __name__== "__main__":
n=input()
a=[]
sm=0
for i in range(n):
x=raw_input()
a.append(x);
c=0
for j in x:
if(j=='C'):c+=1
sm+=(c*(c-1)/2)
for i in range(n):
c=0
for j in range(n):
if a[j][i]=='C':c+=1
sm += (c... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
int n;
char c[111][111];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
for (int h = 1; h <= n; h++) cin >> c[i][h];
int ans = 0;
for (int i = 1, a = 0; i <= n; i++, a = 0) {
for (int h = 1; h <= n; h++)
if (c[i][h] == 'C') a++;
ans += (a - 1)... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Solution{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
HashMap<String, String> dic=new HashMap<>(); // ip->name
int n,i,j,answer=0;
int[] row,col;
String w;
... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | n = int(input())
a = list()
for i in range(n):
a.append(input())
mx = 0
for i in range(n):
count = 0
for j in range(n):
if(a[i][j] == "C"):
count += 1
mx += count * (count - 1) // 2
for i in range(n):
count = 0
for j in range(n):
if(a[j][i] == "C"):
count ... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | n = int(input())
a = []
for _ in range(n):
a.append(input())
b = []
for i in range(n):
b.append("".join(a[j][i] for j in range(n)))
ans = sum((a[i].count("C")*(a[i].count("C")-1))//2 for i in range(n))
ans += sum((b[i].count("C")*(b[i].count("C")-1))//2 for i in range(n))
print(ans)
|
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | n = int(input())
v = []
for _ in range(n):
v.append(input())
r = 0
for i in range(n):
t = sum([1 for x in v[i] if x=='C'])
r += (t*(t-1))//2
for i in range(n):
t = sum([1 for j in range(n) if v[j][i]=='C'])
r += (t*(t-1))//2
print(r) |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | a = int(input())
k = 0
S = []
for i in range(a):
S.append(input())
L = S[i].count('C')
if(L > 1):
if(L == 2):
k += 1
else:
for j in range(1, L):
k += j
for i in range(a):
L =0
for j in range(a):
if(S[j][i]=='C'):
L += 1
... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | def Extract(lst,r):
return [item[r] for item in lst]
a=int(input())
r=0
c=list()
while r<a:
c.append([char for char in input()])
r=r+1
r=0
s=0
while r<a:
m=c[r].count("C")
n=Extract(c,r).count("C")
s=s+((m*m-m)/2)+((n*n-n)/2)
r=r+1
print(int(s))
|
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | n = int(input())
l,c,h = [],0,0
for i in range(n):
l.append(list(input()))
for i in range(n):
k=l[i][::].count('C')
for j in range(n):
if l[j][i]=='C':
h+=1
c+=((((k-1)*k)//2+((h-1)*h)//2))
h=0
print(c) |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | #include <bits/stdc++.h>
using namespace std;
char a[102][102];
int main() {
int n, ans = 0;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) cin >> a[i][j];
for (int i = 1; i <= n; i++) {
int t = 0;
for (int j = 1; j <= n; j++) {
if (a[i][j] == 'C') t++;
}
ans += (t... |
Problem: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly ... | import java.awt.Point;
import java.awt.geom.Line2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.GuardedObject;
im... |
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.StringTokenizer;
public class Bearcompress {
static int count=0;
static String ar[];
static char a[];
static int q;
static int n;
public static void main(String[] args)
{
// TODO Auto-generated method stub
MyScannerbrc sc=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>
#pragma warning(disable : 4996)
using namespace std;
const long long mod = 1000000007;
const int maxn = 200010;
const double PI = acos(-1.0);
int n, q, ans;
int dp[150][100];
char chan[50][10], x[50][10];
int dfs(char a, int len) {
if (dp[a][n - len] != -1) {
return dp[a][n - len];
}
... |
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.Arrays;
import java.util.Scanner;
/**
* Created by abgupta on 3/20/17.
*/
public class C_653_B {
static int n,m;
static char[][] w;
static char[] r;
static int[][] dp;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt(... |
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.IndiaHacks2016oe;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.TreeMap;
/**
* Cre... |
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... | # You lost the game.
n, q = map(int, input().split())
L = [list(str(input()).split(" ")) for _ in range(q)]
A = [[] for _ in range(6)]
B = "abcdef"
for i in range(q):
e = B.index(L[i][1])
A[e] = A[e] + [L[i][0]]
R = [1,0,0,0,0,0]
for i in range(1,n):
K = [0,0,0,0,0,0]
for j in range(6):
for k 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... | /*-
* Codeforces problem :
* http://codeforces.com/problemset/problem/653/B
*
* Find the number of strings of length n that Limak
* will be able to transform to string "a" by applying only operations given in the input.
*/
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFound... |
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<pair<string, string> > combs;
long long n;
long long re(string ini) {
long long sum = 0;
if (ini.size() == n) return 1;
for (long long i = 0; i < combs.size(); i++) {
if (combs[i].second == ini.substr(0, 1)) {
sum += re(combs[i].first + ini.substr(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... | import java.util.*;
public class MyClass {
static int finAns=0,n,cnt;
static char arr[];
static String str[];
static void DFS(char ch,int st)
{
//System.out.println("IN DFS");
int count=0;
if(st==n-1)
{
finAns++;
return;
}
for(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>
char tStr[36][5], a[36], b[36];
int n, q, cnt;
int find(char h, int len, int *cnt) {
int i;
for (i = 0; i < q; i++) {
if (b[i] == h) {
if (len == n - 1) {
*cnt = *cnt + 1;
} else {
*cnt = find(a[i], len + 1, cnt);
}
}
}
return *cnt;
}
int main(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 B653 {
static int n, q;
static HashMap<String, Character> map;
public static int dfs(char[] s, int index, int ml){
if(index==ml){
if(s[index-1]=='a')return 1;
else return 0;
}
int 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... | #include <bits/stdc++.h>
using namespace std;
set<string> s;
queue<string> q;
vector<string> G[6];
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
string a, b;
for (int i = 0; i < m; i++) {
cin >> a >> b;
G[b[0] - 'a'].push_back(a);
}
q.push((string) "a");
while (!q.empty()) {... |
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... | #dfs, dp
[n, q] = map(int, raw_input().split())
qs = [0] * q
for i in range(q): qs[i] = raw_input().strip().split(); qs[i] = (qs[i][0], qs[i][1])
sol = [[-1] * q for i in range(n + 1)]
def solve(n, q):
if n == 2: return 1
if sol[n][q] == -1:
idxs = find_succ(q)
sol[n][q] = sum(solve(n - 1, i) for i in idxs)
retu... |
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() {
long long n, t;
cin >> n >> t;
string s;
char c;
vector<string> v[6];
for (long long j = 0; j < t; j++) {
cin >> s >> c;
v[int(c) - 97].push_back(s);
}
long long k = 0;
queue<pair<string, long long> > q;
for (long long j = 0; j < v[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.*;
import java.math.BigInteger;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main
{
static StringTokenizer st=new StringTokenizer("");
static BufferedReader br;
////////////////////////... |
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.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
public class Main {
public static 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.util.*;
import java.io.*;
public class B2 {
static int n;
static int ans;
static HashMap<String, String> map = new HashMap<>();
static boolean can(String w) {
while (true) {
if (w.length() == 1 && w.equals("a")) return true;
if (w.length() == 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... | from itertools import product
from functools import lru_cache
from string import ascii_lowercase
from sys import stdin, stdout
N = 0
OPS = {}
@lru_cache(maxsize=None)
def backtrack(s):
if len(s) == 1:
if s == 'a':
return True
return False
for k, v in OPS.items():
if s[: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 sys
cache = {}
def Poss(N,last):
if N==1:
return 1
key = (N,last)
if key in cache:
return cache[key]
R = 0
for x in O[last]:
R += Poss(N-1,x[0])
cache[key] = R
return R
N,Q = map(int,sys.stdin.readline().split(' '))
O = {'a':[],'b':[],'c':[],'d':[],'e':[],'f':[]}
for _ in range(Q)... |
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.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Created by Андрей on 19.03.2016.
*/
public class A {
public static PrintWriter pw;
public static int count;
public static int n;
public static int q;
public static String a[];
public static 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... | import itertools
n, q = map(int, raw_input().split())
dic = {}
for i in xrange(q):
a, b = raw_input().strip().split()
dic[a] = b
def cando(s):
while len(s) > 1:
l = s[:2]
if l not in dic: return False
s = dic[l] + s[2:]
return s == 'a'
ans = 0
for i in itertools.product(['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.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class Main {
static java.io.BufferedReader reader =
new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
p... |
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.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Main {
private static final double EPS = 1e-9;
public static void main(String[] args) throws Exception {
FastScanner fastScanner = new FastScanner(System.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... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, q;
cin >> n >> q;
map<string, char> vals;
map<char, long long> rev;
string temp1;
char temp2;
vector<vector<string> > a(6);
for (long long i = 0; i < q; i++) {
cin >> temp1 >> temp2;
vals[temp1] = temp2;
rev[temp2]++;
... |
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, mem[300][10];
map<char, vector<char>> mp;
int slv(char c, int s) {
if (s == n) return 1;
if (mem[c][s] != -1) return mem[c][s];
int ans = 0;
for (char nc : mp[c]) ans += slv(nc, s + 1);
return mem[c][s] = ans;
}
int main() {
memset(mem, -1, sizeof mem)... |
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 = map(int, input().split())
d = collections.defaultdict(list)
cnt, t = [0] * 6, [0] * 6
for i in range(q):
s1, s2 = input().split()
d[s2].append(s1)
cnt[ord(s2) - ord('a')] += 1
for s in d['a']:
t[ord(s[0]) - ord('a')] += 1
for i in range(n - 2):
p = [0] * 6
for j in ran... |
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 os
import sys
from io import BytesIO, IOBase
from itertools import combinations_with_replacement,permutations
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in 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;
string arr[6] = {"a", "b", "c", "d", "e", "f"};
map<string, char> mp;
map<string, int> check, exist;
int n, m;
vector<string> vec;
void solve(string s) {
if (s.size() == n) {
vec.push_back(s);
return;
}
for (int i = 0; i < 6; i++) solve(s + arr[i]);
}
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>
using namespace std;
int n, q;
set<string> v;
string b[36], a[36];
deque<string> que;
void EXEC() {
cin >> n >> q;
for (int i = 0; i < q; ++i) cin >> b[i] >> a[i];
que.push_back("a");
v.insert("a");
while (!que.empty()) {
string x = que.front();
que.pop_front();
if (x.size... |
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 BearanCompressing {
static String[][] op= new String[6][40];
static int []opl;
static int n;
static int num;
public static void dfs (int st ,char ed){
if (st==n){
num++;
return ;
}
for (int i = 0;i<opl[ed-'a'];i++){
dfs(st+1,op[ed-'a'][i].charAt(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.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
public class Grylls {
private static String START_LETTER = ... |
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 inf_int = 2e9;
long long inf_ll = 2e18;
const double pi = 3.1415926535898;
template <typename T, typename T1>
void prin(vector<pair<T, T1> >& a) {
for (int i = 0; i < a.size(); i++) {
cout << a[i].first << " " << a[i].second << "\n";
}
}
template <typename T>
vo... |
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 sys import stdin
from collections import *
from itertools import permutations, product
rints = lambda: [int(x) for x in stdin.readline().split()]
rstrs = lambda: [str(x) for x in stdin.readline().split()]
n, q = rints()
mem, ans = defaultdict(int), 0
for i in range(q):
u, v = rstrs()
mem[u] = v
for a 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.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
@SuppressWarnings("unchecked")
public class P653B {
int enc(String s) {
int w = 0;
for (int i = s.length() - 1; i >= 0; i--) {
w = (w << 3) | (s.charAt(i) - 'a' + 1);
}
return w;
}
public void run(... |
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 sys, os, re, copy
n, q = [int(i) for i in sys.stdin.readline().split()]
dict = {}
for i in xrange(q):
key, value = sys.stdin.readline().strip().split()
dict[key] = value
count = ['a']
new_count = []
length = 1
target = ['a']
new_target = []
count_flag = 1
while length != n:
flag = 0
for key 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... | #include <bits/stdc++.h>
using namespace std;
int connection[7][7];
int n, q;
int sum = 0;
void dfs(int s, int count, int mul) {
if (count == n) {
sum += mul;
return;
}
for (int i = 0; i < 6; i++) {
if (connection[s][i] > 0) {
dfs(i, count + 1, mul * connection[s][i]);
}
}
}
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... | #!/usr/bin/env pypy3
# -*- coding: utf-8 -*-
import collections
import itertools
Operation = collections.namedtuple("Operation", "from_str to_str")
def is_feasible_operation(base_str, operation):
return base_str.startswith(operation.from_str)
def conduct_operation(base_str, operation):
return base_str.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... | n,q=map(int,input().split())
d={i:""for i in "abcdef"}
for i in range(q):
a,b=input().split()
d[b]+=a[0]
cur=d['a']
for i in range(n-2):
nwcur=""
for j in cur:nwcur+=d[j]
cur=nwcur
print(len(cur))
|
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 MAXN = 10;
int dp[MAXN][MAXN], N, Q;
vector<pair<int, int> > m[MAXN];
char a[8], b[8];
int main() {
scanf("%d%d", &N, &Q);
for (int i = 0; i < Q; ++i) {
scanf("%s %s", a, b);
m[b[0] - 'a'].push_back(pair<int, int>(a[0] - 'a', a[1] - 'a'));
dp[2][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... | 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... | import java.io.*;
import java.util.StringTokenizer;
public class B {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void solve() throws IOException {
int t = 1;
while (t-- > 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>
int n, m, result;
std::vector<std::pair<char, std::string> > v;
char str[7];
void func(int x) {
if (x == n) {
int i, j;
char tmp[6] = {0};
for (i = 0; i < n; i++) tmp[i] = str[i];
for (i = 0; i < n - 1; i++) {
for (j = 0; j < m; j++) {
if (v[j].second.at(0) == tm... |
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.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
public class Main {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
static void solve() throws IOExce... |
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 int dx[] = {1, 0, 0, -1};
long long int dy[] = {0, -1, 1, 0};
long long int fact[300000], numinv[300000], factinv[300000];
long long int find_nCr(long long int n, long long int r) {
long long int ans = fact[n];
ans = (ans * factinv[r]) % 1000000007;
ans = (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... | def StringFactory(s) :
temp=[]
for i in range(6):
run = s[::]
temp.append(run+[char[i]])
if len(temp[0])<n:
for t in temp:
StringFactory(t)
else:
for v in temp:
text.append(v)
def opertorFactory(arr):
global count
temp = arr[::]
check =... |
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.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;
public class Main {
static List<String> [] g;
static 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... | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main
{
static final long mod=(int)1e9+7;
public static void main(String[] args) throws Exception
{
FastReader in=new FastReader();
PrintWriter pw=new PrintWriter(System.out);
int n=in.nextInt();
int k=in.nextInt();
char[] a=ne... |
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.HashSet;
import java.util.Set;
public class bearAndCompressing {
static q[] q;
static int sum;
static int gl;
public static void main(String[] args) throws IOException {
BufferedReader b=new BufferedRead... |
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, raw_input().split())
ops = []
for i in range(q):
ops.append(raw_input().split())
def go(x, sz):
if sz == n:
return 1
ret = 0
for op in ops:
if op[1] == x:
ret += go(op[0][0], sz + 1)
return ret
print go('a', 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;
map<char, vector<string> > mp;
int sum = 0;
void dfs(char p, int now, int tot) {
if (now > tot) return;
if (now == tot) {
sum++;
return;
}
for (int i = 0; i < mp[p].size(); i++) {
string x = mp[p][i];
dfs(x[0], now + 1, tot);
}
return;
}
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... | stringInput = raw_input()
stringInput = stringInput.split(' ')
n,q = int(stringInput[0]),int(stringInput[1])
oper = {}
for i in xrange(q):
stringInput = raw_input()
stringInput = stringInput.split(' ')
oper[stringInput[0]] = stringInput[1]
stack = ['a']
for i in xrange(n-1):
newStack = stack[:]
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... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**... |
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())
z = {'e': [], 'd': [], 'f': [], 'b': [], 'a': [], 'c': []}
for i in range(q):
a, b = map(str, input().split())
if b in z:
z[b].append(a[0])
s = [1, 0, 0, 0, 0, 0]
ind = ['a', 'b', 'c', 'd', 'e', 'f']
for i in range(n-1):
a = [0, 0, 0, 0, 0, 0]
for q in range(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;
string a[40], b[40];
int ans;
int n, q;
void dfs(string ss) {
if (ss.size() == n) {
ans++;
return;
}
for (int i = 1; i <= q; i++) {
if (ss[0] == b[i][0]) dfs(a[i] + ss.substr(1));
}
}
int main() {
while (scanf("%d %d", &n, &q) != EOF) {
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 n, q, ans;
struct node {
char ber[3];
} edge[40];
void dfs(int m, char b) {
if (m == n) {
ans++;
return;
}
for (int i = 1; i <= q; i++) {
if (edge[i].ber[2] == b) {
m++;
dfs(m, edge[i].ber[0]);
m--;
}
}
return;
}
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>
using namespace std;
void FastIO() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(20);
}
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, 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))
# Made By Mostafa_Khaled |
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())
lexicon = {}
for _ in range(q):
ai, bi = input().split()
if bi in lexicon:
lexicon[bi].append(ai)
else:
lexicon[bi] = [ai]
memo = {}
def solve(s):
if s in memo:
return memo[s]
else:
count = 0
if len(s) == n:
count = 1
else:
if s[0] in lexicon:
for ss in lexico... |
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;
void slove(multimap<string, string> str, set<string> &se) {
set<string> sss;
for (set<string>::iterator p1 = se.begin(); p1 != se.end(); p1++) {
string s = *p1;
for (multimap<string, string>::iterator p = str.begin(); p != str.end();
p++) {
if (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.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;
public class Test{
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.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.InputStreamReader;
import java.util.HashSet;
public class practice {
static int ans=0;
static HashSet<String> list;
public static void main(String[] args) throws IOException {
list = new HashSet<>();
BufferedReader f = new BufferedRea... |
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 main():
(n, q) = (int(x) for x in input().split())
L = [None] * q
for i in range(q):
(a, b) = (x for x in input().split())
L[i] = (a, b)
print(solver(n, L))
def solver(n, L):
count = 0
for (a, b) in L:
if b == 'a':
count += helper(n - 2, L, a[0])
return count
def helper(n, L, last):
if n == 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;
const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 1e5 + 100;
const long double PI = acos(-1.0);
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
long long p = 1;
while (n > 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... | if __name__=='__main__':
n,m = map(int,input().split(' '))
d = {}
depo,res = {},[]
def bazinga(s):
if s in depo: return depo[s]
if s[0] not in d: depo[s]=0
else:
ans=0
for aa in d[s[0]]:
if len(aa+s[1:])==n:
ans+=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;
multimap<char, string> m;
int n, k;
int dfs(char a, int sz) {
int sum = 0;
if (sz == n) return 1;
pair<multimap<char, string>::iterator, multimap<char, string>::iterator> ret;
ret = m.equal_range(a);
for (multimap<char, string>::iterator it = ret.first; it != ret.... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.