import re


def form_url(problem_tag):
    """ Returns a codeforces url for the problem tag. """

    # problem tag is of the form pXXX or cXXX, denoting contest/problemset.
    problem_tag = problem_tag.lower()
    regex = re.compile(r'([cp])(\d+)([a-z])')

    if not re.match(regex, problem_tag):
        raise Exception('Incorrect Problem tag')

    group = re.findall(regex, problem_tag)[0]

    prob_lvl = group[2].upper()
    prob_num = group[1]

    if group[0] == 'p':
        return 'http://codeforces.com/problemset/problem/{}/{}'.format(prob_num, prob_lvl)
    else:
        return 'http://codeforces.com/contest/{}/problem/{}'.format(prob_num, prob_lvl)