Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int Z = 1e4 + 10; const long long mod = 998244353; const int inf = 0x3f3f3f3f; const long long inff = 0x3f3f3f3f3f3f3f3f; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } string s; set<string> st; string dp[Z][5]; int main() { ios::sync_with_stdio(0); cin.t...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 10023; int v[maxn][2], a[maxn << 1]; int i, j, k, n, m; bool f[maxn][2]; char s[maxn]; int main() { scanf("%s", s + 1); n = strlen(s + 1); if (n <= 6) { puts("0"); return 0; } for (i = 1; i <= n; i++) s[i] -= 'a' - 1; v[n - 1][0] = s[n -...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.util.Collections; import java.io.InputStreamReader; import java.util.ArrayList;...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; long long N; char s[200005]; set<string> ans; long long hashi[200005]; bool vis[200005][2]; bool memo[200005][2]; long long pot[200005]; long long val(long long l, long long r) { long long tmp = hashi[r] - (hashi[l - 1] * pot[r - l + 1]); tmp %= 1000000007; tmp += 100...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long n = s.length(); s += "######"; long long dp2[n + 6]; long long dp3[n + 6]; memset(dp2, 0, sizeof(dp2)); memset(dp3, 0, sizeof(dp3)); if (n >= 2) dp2[n - 1] = 1; if (n >= 3) dp2[n - 2] = 0; if (n >= 4 && (s[n -...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
s = input() n = len(s) dp2,dp3=[0 for i in range(n)],[0 for i in range(n)] if(n<7): print(0) else: if n-2>4: dp2[n-2]=1 if n-3>4: dp3[n-3]=1; #for(i=n-4;i>5;i--) i=n-4 while i>=5: #print("i=%d"% i) dp2[i]=(dp3[i+2] | (dp2[i+2] & (s[i:i+2]!=s[i+2:i+4]) ) ) #if s[i:i+2]!=s[i+2:...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.io.IOException; import java.util.Collections; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); string s; cin >> s; int n = (int)s.size(); vector<array<bool, 2>> dp(n + 1); vector<string> res; if (n >= 7) { dp[n - 2][0] = true; res.push_back(s.substr(n - 2,...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
st=input() n=len(st) poss=[[False,False] for i in range(n)] poss[n-2][0]=True poss[n-3][1]=True for i in range(n-4,-1,-1): if poss[i+2][0] and st[i:i+2]!=st[i+2:i+4]: poss[i][0]=True if poss[i+2][1]: poss[i][0]=True if poss[i+3][1]and st[i:i+3]!=st[i+3:i+6]: p...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long alphabet = 256; int dp[10001][2]; set<string> st; vector<string> vt; int main() { string s; cin >> s; reverse(s.begin(), s.end()); int n = s.length(); string second; for (int i = 0; i < n - 5; i++) second += s[i]...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.TreeSet; import java.io.Writer; import java.io.OutputStreamWr...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const int maxn = 11000; char dp[maxn][maxn]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr);...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; char second[10005]; int n; bool DP[10005][5]; bool v[10005][5]; bool can(int ind, int last) { if (ind == n) return true; bool &temp = DP[ind][last]; if (v[ind][last]) return temp; v[ind][last] = true; if (ind < n - 1) { if (last != 2) temp |= can(ind + 2...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.TreeSet; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import com.sun.org.apache.xml.internal.utils.StringComparable; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String[] args) { // Test.testing(); ConsoleIO io = new ConsoleIO(); new Ma...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.NoSuchElementException; import java.util.HashSet; import java.util.Arrays; public class A { public static void main(String[] args) { FS r = new FS(); String s = r.next(); boolean[][] dp = new boolean[4][10010]; ...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
s = input() n = len(s) dp2,dp3=[0 for i in range(n)],[0 for i in range(n)] if(n<7): print(0) else: if n-2>4: dp2[n-2]=1 if n-3>4: dp3[n-3]=1; i=n-4 while i>=5: dp2[i]=(dp3[i+2] | (dp2[i+2] & (s[i:i+2]!=s[i+2:i+4]) ) ) dp3[i]=dp2[i+3] | (dp3[i+3] & (s[i:i+3]!=s[i+3:i+6]) ) i=i-1 ...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
s = input() if len(s) <= 5: print(0) else: words = set() s = s[5:] r = len(s) if r == 4: words.add(s[1:]) words.add(s[2:]) words.add(s[:2]) if r == 2: words.add(s) if r == 3: words.add(s) words.add(s[1:]) s = s[::-1] if r > 4: ...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.util.Scanner; import java.util.TreeSet; public class ReberlandLinguistics { static String s; static int n; static boolean valid(int pos, int chars) { if(pos - chars < 0)return true; for(int i = pos-chars+1; i <= pos; i++) { if(s.charAt(i) != s.charAt(i-chars)) return true; } ret...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string d; set<string> s; void solve(int i, string k); set<pair<int, string> > check; int main() { cin >> d; solve(d.length() - 1, ""); if (s.size() == 0) cout << s.size() << endl; else cout << s.size() - 1 << endl; for (set<string>::iterator it = s.begin()...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.TreeS...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; set<string> se; set<string>::iterator it; string s; int len; bool dp[10010][2]; int main() { memset(dp, 0, sizeof(dp)); cin >> s; len = s.length(); dp[len][0] = dp[len][1] = 1; for (int i = len - 1; i >= 5; i--) { if (dp[i + 2][0] && (s[i] != s[i + 2] || s[i +...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; set<string> P; string S; set<string> last_suffixes[10005]; int N; map<string, bool> dp[10005]; bool solve(int i, string last) { if (dp[i].count(last)) return dp[i][last]; bool& ans = dp[i][last]; if (i == N) return ans = true; if (i == N - 1) return ans = false; a...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.util.Scanner; import java.util.TreeSet; public class ReberlandLinguistics { static String s; static int n; static boolean valid(int pos, int chars) { if(pos - chars < 0)return true; for(int i = pos-chars+1; i <= pos; i++) { if(s.charAt(i) != s.charAt(i-chars)) return true; } ret...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; public class Reberlandlinguistics { public static void main(String[] args) { // TODO Auto-generated method stub MyScannerdreberland sc=new MyScannerdreberland(); ...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.util.Comparator; import java.util.TreeSet; // // written by xiongjx on 2021-07-21 // public class Main { void run() { String str = in.next(); int len = str.length(); boolean[][] dp = new boolean[2][len + 1]; TreeSet<String> st = new TreeSet<String>(Comparator.naturalOr...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> std::string s; std::string ss(int a, int b) { std::string s1 = ""; for (int i = a; i <= b; i++) s1 += s[i]; return s1; } bool cs(int a, int b, int c, int d) { std::string s1 = ss(a, b); std::string s2 = ss(c, d); return ss(a, b) != ss(c, d); } int main() { std::ios::sync_with_stdi...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; using ll = long long; string A; ll n; ll dp[10100][4]; set<string> st; ll rec(ll ind, ll val) { if (ind == n) { return 1; } if (dp[ind][val] != -1) { return dp[ind][val]; } ll ans = 0; if (val == 2) { if (ind + 2 <= n) { ans = max(ans, rec(ind ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; string input; bool done[10005][4]; bool memo[10005][4]; set<string> ans; void process(int rootLast, int lastLen) { if (done[rootLast][lastLen]) { return; } done[rootLast][lastLen] = true; assert(rootLast >= ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0); int t = 1, n, m, i, j, k, u, to; while (t--) { string s; cin >> s; n = s.length(); if (n <= 6) { cout << 0; return 0; } set<string> ans; vector<bool> dp[2]; for (i = 0; i...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
s = raw_input()[5:] n = len(s) good = [[None]*2 for i in xrange(n+1)] goods = [] for i in xrange(n,-1,-1): for sk in xrange(2): k = sk+2 if i == n: good[i][sk] = True elif i+k > n: good[i][sk] = False elif i+k == n: good[i][sk] = True else...
PYTHON
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, j; string s; cin >> s; n = s.size(); string cur; if (s.size() <= 6) { cout << 0; return 0; } for (i = 5; i < s.size(); i++) { cur += s[i]; } if (cur.size() == 2) { cout << 1 << endl << cur; return 0; ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
def get_suffixes(string): if len(string) < 7: return [] suffix_string = string[5:][::-1] result = set() result.add(suffix_string[:2]) dp2 = [1, 0, 1] + [0] * (len(suffix_string) -2) dp3 = [1] + [0] * len(suffix_string) for n in xrange(3, len(suffix_string) + 1): if dp3[n-...
PYTHON
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string str; int N; set<string> ss; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> str; N = str.length(); vector<bool> flag(N + 4, false); flag[N] = true; for (int i = N - 2; i >= 5; --i) { bool do2 = true, do3 = true; if (i + 3 < N) ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
s = input() possible = [[],[],[False]*10100, [False]*10100] length = len(s) possible[2][length-2] = True possible[3][length-3] = True for i in range(length-1, 5-1,-1): if length - 4 >= i: possible[2][i] = (possible[2][i+2] and s[i:i+2] != s[i+2:i+4]) or possible[3][i+2] if length - 5 >= i: po...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; set<string> ss; const int maxn = 100005; int dp[maxn][2]; char c[maxn]; vector<string> g; int main() { int i, j, n; scanf("%s", c); n = strlen(c); for (int i = n; i >= 1; i--) c[i] = c[i - 1]; string s; for (int i = n - 1; i > 5; i--) { if (n - i + 1 >= 2) {...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, f[10000 + 5], F[...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
def getPossibleSuffixes(s): if len(s) == 5: print(0) return possible_suffixes = s[5:len(s)] suffixes = [] helper_hash = {} suffix_starts = [0 for x in range(len(possible_suffixes))] prev_2 = ["" for x in range(len(possible_suffixes))] suffix_starts[-1] = 1 for i in range(...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int block_size = 320; const long long mod = 1e9 + 7; const long double eps = 1e-9; const int inf = mod; const double PI = atan(1) * 4; template <typename T> inline int sign(const T &a) { if (a < 0) return -1; if (a > 0) return 1; return 0; } template <typename T...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int inf = 1000 * 1000 * 1000; const long long inf64 = 1ll * inf * inf; bool solve() { string s; cin >> s; set<string> ans; int n = (int)s.size(); vector<char> can2(n + 1); vector<char> can3(n + 1); can2[n] = 1; can3[n] = 1; for (int i = n - 2; i >= 5...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <typename T> T nextInt() { T x = 0, p = 1; char ch; do { ch = getchar(); } while (ch <= ' '); if (ch == '-') { p = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + (ch - '0'); ch = getchar(); } return x * p; ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string str2[10010], str3[10010]; bool dp[10010]; set<string> S; int main() { string str; cin >> str; int len = str.size(), i, j, k; str.push_back('*'); str.push_back('*'); str.push_back('*'); memset(dp, 0, sizeof(dp)); dp[len] = 1; str2[len] = ""; str3[l...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int n; string s; vector<vector<bool>> vis; set<string> suffs; void check(int i, int pl) { if (vis[pl][i]) return; vis[pl][i] = 1; if (i - 1 > 4) { string x = s.substr(i - 1, 2); if (pl || x != s.substr(i + 1, 2)) { suffs.insert(x); check(i - 2, 0);...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.*; import java.util.*; public class main {public static void solucion(String strPalabra) { List<String> ans = new ArrayList<>(); //System.out.println(strPalabra); //2 String temp = ""; for (int i = strPalabra.length() - 1; (i) > 4; i = i - 2) { if (i ...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; set<string> ans; set<string>::iterator it; string str; bool dp[MAXN][2]; int main() { while (cin >> str) { ans.clear(); memset(dp, 0, sizeof(dp)); int len = str.size(); for (in...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string s; set<string> sfx; bool vis[10004][3]; void dp(int i = (int)s.size(), int f = 0) { if (vis[i][f]) return; vis[i][f] = 1; string t2; if (f == 1 && i <= (int)s.size() - 2) t2 = s.substr(i, 2); else if (f == 2 && i <= (int)s.size() - 3) t2 = s.substr(...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") using namespace std; int a, b, c, d, n, m, k; char str[10002]; bool cool[10002][2]; inline bool good(int p1, int p2, int len) { for (int _n((len)-1), i(0); i <= _n; i++) { if (str[p1 + i] != str[p2 + ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
// // Untitled 2.java // Created by Alister Estrada Cueto on 9/25/18. import java.util.Scanner; import java.util.TreeSet; public class ReberlandLinguistic { Scanner sc = new Scanner(System.in); String s; int n; boolean[][] v; boolean[][] memo; TreeSet<String> set; void run() { s = sc.next(); n = s.length(...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.*; import java.util.*; public class A { InputStream is; int __t__ = 1; int __f__ = 0; int __FILE_DEBUG_FLAG__ = __f__; String __DEBUG_FILE_NAME__ = "src/A3"; FastScanner in; PrintWriter out; public void solve() { String s = in.next().substring(5); int n = s.length(); TreeSet<String> re...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 5; bool d2[N], d3[N]; int main() { ios_base::sync_with_stdio(0); string s; cin >> s; s = s.substr(5, s.length() - 5); int n = s.length(); set<string> ans; if (s.size() <= 1) { cout << 0; return 0; } if (s.size() == 2) { cout...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.*; import java.util.*; public class reberlandlinguistics { private static InputReader in; private static PrintWriter out; public static void main(String[] args) throws IOException { in = new InputReader(System.in); out = new PrintWriter(System.out, true); char[] c = (in.next()+"****"...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; public class A { stati...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv>& p) { os << "{" << p.first << ',' << p.second << "}"; return os; } const int MAX = 100005; const int MOD = 1000000000 + 7; const int INF = 1000000000; int main() { ios::sync_with_s...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e4 + 4; string s; bool can_split[4][MAXN]; int main() { ios_base::sync_with_stdio(0); cin >> s; int n = s.size(); s += "$$$"; can_split[2][n] = can_split[3][n] = 1; for (int i = n - 1; i > 4; i--) { for (int k = 2; k <= 3; k++) { bool...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string s; set<string> myset; bool F[10005][4] = {false}; int main() { cin >> s; int length = s.length(); if (length >= 7) { F[length - 2][2] = true; myset.insert(s.substr(length - 2, 2)); F[length - 2][3] = false; if (length >= 8) { F[length - 3]...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string get() { char ch[100010]; scanf("%s", ch); return ch; } const int MAX_LG = 21; const long long maxn = 1e5 + 10; const long long base = 29; const long long mod = 1e9 + 7; bool dp[maxn][2]; set...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
s = str(raw_input()) ans = {} n = len(s) dp = [[0 for j in xrange(4)] for i in xrange(n)] if n-2 > 4 : dp[n-2][2] = 1 ans [s[n-2:]] = 1 if n-3 >4 : dp[n-3][3] = 1 ans [s[n-3:]] = 1 for i in reversed(xrange(n)): for j in xrange(2,4): if dp[i][j] == 1: rev = 5 - j ...
PYTHON
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int n; char s[1 << 20]; int cr[1 << 20][2]; bool can_reach(int ps, int t) { if (cr[ps][t] != -1) { return cr[ps][t]; } if (ps >= n) { return (ps == n); } int st = ps - t - 2; bool ok = false; for (int ln = ps + 2; ln <= ps + 3; ++ln) { bool same = ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; struct Node { int next[26]; bool f; }; Node nd[23333]; char str[10010]; int ans, len; bool dp[10010][2]; int tp; bool same(int st, int ln) { if (st + ln >= len) return true; for (int i = 0; i < ln; ++i) if (str[st + ln - i] != str[st ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& s, vector<T>& v) { s << '{'; for (int i = 0; i < int(v.size()); i++) s << (i ? "," : "") << v[i]; return s << '}'; } template <typename S, typename T> ostream& operator<<(ostream& s, pair<S, T> const& p) { return s ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e+4 + 10; string s; set<string> ans; set<string>::iterator it; bool vis[maxn]; int main() { cin >> s; int len = s.length(); vis[len] = 1; for (int i = s.length() - 1; i > 4; --i) { if (vis[i + 2]) { string t = s.substr(i, 2); if (s....
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; map<string, int> Book; int book[10005][5] = {0}; set<string> ans; string a; void dfs(int s, int l, string m); int main() { int i, l, j; set<string>::iterator it; cin >> a; for (l = 2; l <= 3; l++) { dfs(a.size() - 1, l, string()); } l = ans.size(); cout <<...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 5e4 + 100; template <class T> inline void read(T &s) { s = 0; T w = 1, ch = getchar(); while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch)) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); } ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string s; int n; const int MX = 10000 + 99; set<string> S[MX]; set<string> ans; int main() { cin >> s; n = s.size(); S[n].insert("-"); for (int i = n - 2; i >= 5; i--) { for (int d = 2; i + d <= n && d <= 3; d++) { string sub = s.substr(i, d); bool o...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 10; set<string> ans; string s; bool vis[4][N]; void DFS(int x, string pre) { if (vis[pre.size()][x]) return; vis[pre.size()][x] = 1; if (x - 1 > 4) { string tmp = s.substr(x - 1, 2); if (tmp != pre) { ans.insert(tmp); DFS(x - 2,...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 10005; bool dp[N][2]; char s[N]; set<string> ans; inline bool ck(int x, int y) { bool same = true; for (int i = 0; x + i < y; ++i) { same &= s[x + i] == s[y + i]; } return !same; } int main() { scanf("%s", s); int n = strlen(s); dp[n][0] = dp...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
def main(): s = input()[5:] n = len(s) if n < 2: print(0) return res2, res3 = set(), set() dp2 = [False] * (n + 1) dp3 = [False] * (n + 1) dp2[-1] = dp3[-1] = True for i in range(n, 1, -1): if dp3[i] or dp2[i] and s[i - 2:i] != s[i:i + 2]: res2.add(s[i...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; char s[10010]; int n; int e[10010][2]; vector<string> ans; bool vis[10010][2]; bool dp[10010][2]; bool dfs(int p, int pre) { if (p > n) return false; if (p == n) return dp[p][pre] = true; if (vis[p][pre]) return dp[p][pre]; bool re = false; if (e[p][0] != -1 && (p...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; char s[maxn]; int n, dp[maxn][2]; string temp; set<string> se; int main() { scanf("%s", s + 1); n = strlen(s + 1); dp[n + 1][0] = dp[n + 1][1] = 1; for (int ed = n; ed >= 5; ed--) { for (int st = ed - 1; st >= ed - 2; st--) { if ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
__author__ = 'Utena' s=input() n=len(s) ans=set() if n<=6: print(0) exit(0) dp=[[False,False]for i in range(n+1)] if n>7: dp[3][1]=True ans.add(s[-3:]) dp[2][0]=True ans.add(s[-2:]) for i in range(4,n-4): if s[(-i):(-i+2)]!=s[(-i+2):(-i+3)]+s[-i+3]and dp[i-2][0] or dp[i-2][1]: dp[i][0]=True...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 100; char s[maxn]; int len; int f[maxn]; map<string, int> mp; vector<string> vec; int calcu(int a, int b, int c, int d) { for (int i = 0;; i++) { int t1 = a + i; if (t1 > b) { break; } int t2 = c + i; if (s[t1] != s[t2]) re...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 2e4 + 5; char s[N]; int dp[10][N]; int ans[N]; int len; int dfs(int num, int idx) { if (~dp[num][idx]) return dp[num][idx]; if (idx == len) return 1; else if (idx > len) return 0; int &ret = dp[num][idx]; ret = dfs(num ^ 1, idx + num); bool...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
from sys import * setrecursionlimit(20000) d = {} inp = raw_input() + ' ' t = set() def calc(l, ll): if (l, ll) in t: return else: t.add((l, ll)) if l > 6: d[inp[l-2:l]] = 1 if inp[l-2:l] != inp[l:ll]: calc(l-2, l) if l > 7: d[inp[l-3:l]] = 1 if inp[l-3:l] != inp[l:ll]: calc(l-3, l) calc(l...
PYTHON
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
def process(s): ns = s[5:][::-1] if len(ns) <= 1: return set() if len(ns) == 2: return {ns[::-1]} if len(ns) == 3: return {ns[::-1], ns[:-1][::-1]} n = len(ns) dp2 = [False]*(n+1) dp2[1] = True dp3 = [False]*(n+1) dp3[2] = True for i in range(3,5): dp2[i] = dp3[i-2] or (d...
PYTHON
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string st; int n; bool dp[111111][2]; set<string> ttt; bool is_samee(int l, int r, int len) { for (int i = 0; i < len; i++) { if (st[l + i] != st[r + i]) { return false; } } return true; } int kk = 0; string sol[501111]; void add_sol(int l, int r) { so...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.*; import java.util.*; public class test { static type1 one[]; static int k=0; public static void main(String args[]) { //System.out.println("Welcome"); inputs in=new inputs(System.in); one=new type1[26]; //put("aa"); put("aa"); put("ccc"); pu...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <class T> bool cmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool cmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const int N = 1e4 + 10; int n; char s[N]; int f[N][2]; int s...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; set<string> ans; string s; bool vis[10009][5]; void dfs(int i, int k) { if (vis[i][k]) return; vis[i][k] = 1; if (i >= 6) { ans.insert(s.substr(i - 1, 2)); } if (i >= 7) { ans.insert(s.substr(i - 2, 3)); } if (i >= 6) { if (k == 0 || s.substr(i + 1...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string s; map<string, bool> folosit; int dp[10010][2]; bool generateSuffixes(int pos, string last) { if (dp[pos][last.size() - 2] != -1) return dp[pos][last.size() - 2]; bool res = false; if (pos + 2 < s.size() && s.substr(pos + 1, 2) != last) { bool ok = generate...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; set<string> s; const int maxn = 1E4 + 10; int dp[maxn]; int main() { string str; cin >> str; memset(dp, 0, sizeof(dp)); str = str.substr(5); int n = str.length(); string tmp; dp[n] = 1; for (int i = n - 1; i >= 0; --i) { for (int l = 2; l <= 3; ++l) { ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
/** * Created by yume on 2016/5/25. */ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.TreeSet; public class Main { public static void main(final String[] args...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10, mod = 1e9 + 7; const long long inf = 1e18; bool dp[2][maxn]; set<string> st; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; dp[0][int((s).size()) - 2] = dp[1][int((s).size()) - 3] = 1; for (int i = int((...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import sys sys.setrecursionlimit(15000) s = input() s = s[5:] + " " res = set() aux = set() def getWords(x,y): if (x,y) in aux: return aux.add((x,y)) if x > 1 and s[x:y] != s[x-2:x]: res.add(s[x-2:x]) getWords(x-2,x) if x > 2 and s[x:y] != s[x-3:x]: res.add(s[x-3:x]) ...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 10005; int N; string s; int dp[MAXN][2]; void load() { cin >> s; } string get(int lo, int len) { return s.substr(lo, min(len, N - lo)); } void solve() { N = s.size(); s += ' '; vector<string> sol; dp[N][0] = dp[N][1] = 1; for (int i = N - 1; i >= ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 7; const int M = 32; const long long base = 1e18; const int mod = 999983; const int inf = 1e9 + 7; const double pi = acos(-1); const int maxn = N * 2; const double PI = acos(-1); const double ep = 1e-9; string s; int n; bool can[5][N]; set<string> st;...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <class T> ostream &operator<<(ostream &os, const ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 10005; bool dp[N][5][5]; bool vis[N][5][5]; string s; int n; set<string> ans; bool calc(int ind, int current, int previous) { if (ind == n) return true; if (ind > n) return false; if (vis[ind][current][previous]) return dp[ind][current][previous]; vis[...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; string tmp = str.substr(5, str.length()); str = tmp; long long n = str.length(); long long dp[n + 1][2]; memset(dp, 0, sizeof dp); for (long long i = n - 2; i >= 0; i--) { if ((i + 2) > n) continue; else { ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string st; int dp[10005][4]; int n; set<string> st_set; int rec(int pos, int len) { if (pos == 4 || pos == 5) { return 1; } if (pos < 4) return 0; int &ret = dp[pos][len]; if (ret != -1) return ret; ret = 0; if (len == 0) { if (pos >= 7) { ret |=...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; const string nl = "\n"; using ll = int64_t; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using str = string; using vpii = vector<pii>; using vpll = vector<pll>; template <class T> inline bool ckmin(T& a, T b) { retur...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.util.Scanner; import java.util.TreeSet; public class AlyonaAndStrings { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String word = sc.next(); TreeSet<String> set = new TreeSet<>(); boolean[] dp = new boolean[word.length()]; int num = findWords(set, dp, word); ...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; int len = n.size(); bool possible[len + 1][2]; possible[len][0] = 1; possible[len][1] = 1; possible[len - 1][0] = 0; possible[len - 1][1] = 0; possible[len - 2][0] = 1; possible[len - 2][1] = 0; possible[len - 3][0] = 0...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
import java.io.*; import java.util.*; import java.util.stream.Stream; public class Main implements Runnable { static final int MOD = (int) 1e9 + 7; static final int MI = (int) 1e9; static final long ML = (long) 1e18; static final Reader in = new Reader(); static final PrintWriter out = new PrintWri...
JAVA
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string s; bool f[10001][2]; int n; set<string> suff; int main() { cin >> s; n = s.length(); if (n < 7) { cout << 0; return 0; } f[n - 2][0] = true; if (n > 7) f[n - 3][1] = true; for (int i = n - 4; i >= 5; i--) { if (f[i + 2][1]) f[i][0] = true; ...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; set<string> ans; const int MN = 1e5 + 100; int dp[MN]; int main() { string s; cin >> s; int n = s.size(); dp[n] = 3; s.push_back('.'); s.push_back('.'); s.push_back('.'); s.push_back('.'); s.push_back('.'); s.push_back('.'); for (int i = n - 2; i >= 0;...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; string s; set<string> ret; bool dp[10004][5]; int main() { cin >> s; int n = s.size(); memset(dp, 0, sizeof(dp)); for (int i = n - 2; i >= 5; i--) { if (i + 2 == n) { dp[i][2] = true; ret.emplace(s.substr(i, 2)); } if (i + 3 == n) { dp[...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
s = input() dp = [[0, 0] for i in range(10005)] res = set() i = len(s) - 1 while i >= 5: if i + 2 == len(s): dp[i][0] = 1 res.add(s[i:i+2]) i = i - 1 continue if i + 3 == len(s): dp[i][1] = 1 res.add(s[i:i+3]) i = i - 1 continue if dp[i+2][1] or (dp[i+2][0] and s[i:i+2] != s[i+2:i+4]): dp[i][0] = 1...
PYTHON3
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
'''ACCEPTED''' import sys pow2 = pow # for modular expo pow2(base, n, mod) from math import * from time import time from collections import defaultdict from bisect import bisect_right, bisect_left from string import ascii_lowercase as lcs from string import ascii_uppercase as ucs from fractions import Fra...
PYTHON
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; long long md = 1000000007; inline long long mulD(long long a, long long b) { long long r = 0; while (b > 0) { if (b & 1) { r = r + a % md; r = r % md; } b /= 2; a = 2 * a % md; a = a % md; } return r % md; ; } inline long long exp(l...
CPP
666_A. Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
2
7
#include <bits/stdc++.h> using namespace std; bool dp[10005][2]; string st; set<string> ans; int main() { cin >> st; if (st.size() <= 6) { cout << 0 << endl; return 0; } st = st.substr(5); dp[st.size()][0] = dp[st.size()][1] = true; for (int i = st.size() - 2; i >= 0; i--) { if (dp[i + 2][1] || ...
CPP