Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <string>
- #include <queue>
- #include <map>
- #include <set>
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <unordered_map>
- using namespace std;
- #define ll long long
- #define nl endl
- #define cy cout << "Yes\n"
- #define cn cout << "No\n"
- #define sz s.size()
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- /*
- ll gcd(ll a, ll b)
- {
- while (b)
- {
- a %= b;
- swap(a, b);
- c++;
- }
- return a;
- }
- ll lcm(ll a, ll b)
- {
- return a * b / gcd(a, b);
- }*/
- bool is_prime(ll x)
- {
- if (x == 2 || x == 3 || x == 1)
- return true;
- if (x % 2 == 0)
- return false;
- for (ll i = 3; i <= sqrt(x); i += 2)
- {
- if (x % i == 0)
- return false;
- }
- return true;
- }
- /*
- int s[1000001];
- int divisors(int n)
- {
- ll c = 0;
- if (s[n] != 0)
- return s[n];
- for (int i = 1; i * i <= n; i++)
- {
- if (n % i == 0)
- {
- c++;
- if (i * i != n)
- c++;
- }
- }
- s[n] = c;
- return c;
- }*/
- /*
- bool comp(const pair<string, long double> &a, const pair<string, long double> &b)
- {
- if (a.second == b.second)
- {
- return a.first < b.first;
- }
- return a.second > b.second;
- }*/
- string s[100];
- int main()
- {
- sherry();
- set<string> dict;
- int n, m, i;
- cin >> n >> m;
- for (i = 0; i < n; i++)
- {
- cin >> s[i];
- dict.insert(s[i]);
- }
- vector<string> left, right;
- string mid;
- for (i = 0; i < n; i++)
- {
- string t = s[i];
- reverse(t.begin(), t.end());
- if (t == s[i])
- mid = t;
- else if (dict.find(t) != dict.end())
- {
- left.push_back(s[i]);
- right.push_back(t);
- dict.erase(s[i]);
- dict.erase(t);
- }
- }
- cout << left.size() * m * 2 + mid.size() << endl;
- for (string x : left)
- cout << x;
- cout << mid;
- reverse(right.begin(), right.end());
- for (string x : right)
- cout << x;
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement