1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct char_at
{
    const char* s;

    static size_t i;

    explicit char_at(const char* s_) : s(s_) {}

    operator bool() const { return s[i]; }

    friend bool operator==(const char_at& lhs, const char_at& rhs)
    {
        return lhs.s[i] == rhs.s[i];
    }

    friend bool operator<(const char_at& lhs, const char_at& rhs)
    {
        return lhs.s[i] < rhs.s[i];
    }

    friend ostream& operator<<(ostream& out, const char_at& at) // debug
    {
        return out << (at.s + i);
    }
};

size_t char_at::i;

bool compare_s(const char_at& lhs, const char_at& rhs)
{
    return strcmp(lhs.s, rhs.s) < 0;
}

int main()
{
    string s1; getline(cin, s1);

    string s2; getline(cin, s2);

    vector<char_at> v;

    for (const char* p = s1.c_str(); *p; ++p)
    {
        v.push_back(char_at(p));
    }

    sort(v.begin(), v.end(), compare_s);

    size_t result = 0;

    for (const char* p = s2.c_str(); *p; ++p)
    {
        char_at at(p);

        pair<vector<char_at>::iterator, vector<char_at>::iterator>
            r = make_pair(v.begin(), v.end());

        for (char_at::i = 0; ; ++char_at::i)
        {
            r = equal_range(r.first, r.second, at);

            while (r.first != r.second && !*r.first)
            {
                ++r.first;
            }

            if (r.first == r.second || !at)
            {
                break;
            }
        }

        result = max(result, char_at::i);
    }

    cout << result << endl;
}