{"source_code": "n,m,k=map(int,input().split())\nns=list(map(lambda x:int(x),input().split()))\nns.sort()\nns.reverse()\nif m<=k:\n    print(0)\nelse:\n    m=m-k+1\n    i=0\n    while i<len(ns):\n        m-=ns[i]\n        if m<1:\n            print(i+1)\n            break\n        i+=1\n        m+=1\n    else:\n        print(-1)", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c"}
{"source_code": "def poorDragons():\n    k = int(input())\n    l = int(input())\n    m = int(input())\n    n = int(input())\n    d = int(input())\n    cnt = 0\n    for i in range(1, d + 1):\n        if i % k == 0:\n            cnt += 1\n        elif i % l == 0:\n            cnt += 1\n        elif i % m == 0:\n            cnt += 1\n        elif i % n == 0:\n            cnt += 1\n    return cnt                                    \nif __name__ == '__main__':\n\tprint(poorDragons())", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"}
{"source_code": "n=int(input())\na=int(input())\nb=int(input())\nc=int(input())\n\nd=b-c\n\nif a<=d:\n    print(n//a)\n\nelse:\n    lb=0\n    ub=n\n    \n    while ub-lb>1 :\n        mid=(ub+lb)//2\n        tmp=n-d*(mid-1)\n        if tmp>=b :\n            lb=mid\n        else :\n            ub=mid\n        \n    ans=lb\n    n-=d*lb\n    ans+=n//a\n    print(ans)\n\n", "src_uid": "0ee9abec69230eab25de51aef0984f8f"}
{"source_code": "n = int(input())\nprint(int(2*4*3*pow(4,n-3)+(n-3)*4*3*3*pow(4,n-4)))", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9"}
{"source_code": "from collections import Counter\n\nr = lambda: map(int, input().split())\n\ndef main():\n\tn, = r()\n\ts = input()\n\tcost = list(r())\n\n\tans = 0\n\n\tcnt = Counter()\n\n\tfor i in range(n // 2):\n\t\tif s[i] == s[n - 1 - i]:\n\t\t\tans += min(cost[i], cost[n - 1 - i])\n\t\t\tcnt[s[i]] += 1\n\ttotal = sum(cnt.values())\n\tif total > 0:\n\t\tch, occ = cnt.most_common(1)[0]\n\t\tavail = []\n\t\tif occ > total - occ:\n\t\t\tfor i in range(n // 2):\n\t\t\t\tif s[i] != s[n - 1 - i] and s[i] != ch and s[n - 1 - i] != ch:\n\t\t\t\t\tavail.append(min(cost[i], cost[n - 1 - i]))\n\t\t\tavail.sort()\n\t\t\tans += sum(avail[:2 * occ - total])\n\n\tprint(sum(cost) - ans)\n\nmain()\n", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50"}
{"source_code": "c1=c2=c3=0\na,b=map(int,input().split())\nfor i in range(1,7):\n    if abs(a-i) > abs(b-i):\n        c1+=1\n    if abs(a-i) == abs(b-i):\n        c2+=1\n    if abs(a-i) < abs(b-i):\n        c3+=1\nprint(c3,c2,c1)        ", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"}
{"source_code": "s=raw_input().split('e')\nr=s[0].split('.')\np=int(s[1])\nfor i in range(len(r[1])-1,-1,-1):\n    if r[1][i]!='0':\n        break\n    else:\n        r[1]=r[1][:i]\n#print r[1]\nif p>=len(r[1]):\n    ans=r[0]+r[1]+'0'*(p-len(r[1]))\nelse:\n    ans=r[0]+r[1][:p]+'.'+r[1][p:]\nprint ans", "src_uid": "a79358099f08f3ec50c013d47d910eef"}
{"source_code": "w, m = map(int, raw_input().split())\n\nans = True\nfor i in xrange(101):\n    k = m % w\n    if k == 1:\n        m -= 1\n    elif k == w-1:\n        m += 1\n    elif k == 0:\n        pass\n    else:\n        ans = False\n    m /= w\nprint \"YES\" if ans else \"NO\" ", "src_uid": "a74adcf0314692f8ac95f54d165d9582"}
{"source_code": "r1,c1,r2,c2 = [int(x) for x in input().split(\" \")]\n\n# rook\nrook = 2\nif(r1==r2 or c1==c2): rook = 1\n\n# bishop\nbishop = 2\nif (r1+c1)%2 != (r2+c2)%2: bishop = 0\nelif abs(r2-r1)==abs(c2-c1): bishop=1\n\n# king\nking = max([abs(r2-r1),abs(c2-c1)])\n\nprint(rook,bishop,king)", "src_uid": "7dbf58806db185f0fe70c00b60973f4b"}
{"source_code": "import math\n\nn, m = map(int, input().split())\na = [math.ceil(int(i) / m) for i in input().split()]\ni = n - 1\nwhile a[i] != max(a):\n    i -= 1\nprint(i + 1)\n", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c"}
{"source_code": "l,r,a=input().split()\nl=int(l)\nr=int(r)\na=int(a)\nif l<r and a>r-l:\n    print(2*(l+(r-l)+(a-(r-l))//2))\nelif l<r and a<=r-l:\n    print(2*(l+(a)))\nelif l>r and a>l-r:\n    print(2*(r+(l-r)+(a-(l-r))//2))\nelif l>r and a<=l-r:\n    print(2*(r+(a)))\nelif l==r:\n    print(2*(r+(a//2)))\n    \n", "src_uid": "e8148140e61baffd0878376ac5f3857c"}
{"source_code": "a,b,c = int(input()),int(input()),int(input())\nprint(min(a,b//2,c//4)*7)", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"}
{"source_code": "n , m , k = map(int , input().split())\nif k >= n and m >= n:\n    print(\"Yes\")\nelse:\n    print('No')", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4"}
{"source_code": "def ncr(n, r, p):\n    if(r>n):\n        return 0\n    num = den = 1\n    for i in range(r):\n        num = (num * (n - i)) % p\n        den = (den * (i + 1)) % p\n    return (num * pow(den, p - 2, p)) % p\n\ndef fac(n, p): \n    if n >= p: \n        return 0\n    result = 1\n    for i in range(1, n + 1): \n        result = (result * i) % p  \n    return result \n\nn,x,pos=list(map(int,input().split(\" \")))\ns=g=0\n\na=0\nb=n\nwhile(a<b):\n    mid=(a+b)//2\n    if(mid<=pos):\n        s+=1\n        a=mid+1\n    else:\n        g+=1\n        b=mid\np=1000\np=p*p*p+7\n\nprint( (ncr(x-1,s-1,p)*fac(s-1,p) * ncr(n-x,g,p)*fac(g,p)* fac(n-s-g,p))%p )\n", "src_uid": "24e2f10463f440affccc2755f4462d8a"}
{"source_code": "t = input()\nt = t.split()\nn = int(t[0])\nc1 = int(t[1])\nc2 = int(t[2])\nt = input()\nd = 0\nfor i in t:\n    if(i==\"1\"):\n        d = d+1\n\nmin = 10**1488\nfor i in range(1, d+1):\n    t = c1*i + i*c2*(((n//i)-1)**2) + c2*(n%i)*(2*(n//i)-1)\n    if t<min:\n        min = t\n\nprint(min)", "src_uid": "78d013b01497053b8e321fe7b6ce3760"}
{"source_code": "import sys\nimport math\n\nn = int(input())\n\nx = [0]*n\ny = [0]*n\n\nfor i in range(n):\n    x[i], y[i] = map(int, input().split())\n\nsx = sum(x)\nsy = sum(y)\n    \nfor i in range(n):\n    x[i] = n * x[i] - sx\n    y[i] = n * y[i] - sy\n\nm = int(input())\n\nd = [0]*n\ne = [0]*n\n\nHD = 0\n\ndef check(a, b):\n    global HD\n    HE = 0\n    for i in range(n):\n        HE ^= hash((a-x[i])*(a-x[i])+(b-y[i])*(b-y[i]))\n    return HD == HE\n\ndef sqrt(x):\n    nn = int(x)\n    if nn == 0:\n        return 0\n    fa, fb = divmod(nn.bit_length(), 2)\n    x = 2**(fa+fb)\n    while True:\n        y = (x + nn//x)//2\n        if y >= x:\n            return x\n        x = y\n\ndef hash(x):\n    return x * 9991 + 43\n\npans = []\n\ndef solve():\n    global d\n    d = list(map(int, input().split()))\n    c = 0\n    d = [p * n * n for p in d]\n    for i in range(n):\n        c += d[i] - x[i] * x[i] - y[i] * y[i]\n\n    assert(c % n == 0)\n    c //= n\n    ans = []\n    ax = x[0]\n    ay = y[0]\n    if ax is 0 and ay is 0:\n        ax = x[1]\n        ay = y[1]\n    rev = 0\n    if ay == 0:\n        ay = ax\n        ax = 0\n        rev = 1\n    d.sort()\n    global HD\n    HD = 0\n    for p in d:\n        HD ^= hash(p)\n    old = -1\n    for p in d:\n        if (p == old):\n            continue\n        old = p\n        a = c + ax * ax + ay * ay - p\n        if (a % 2 != 0):\n            continue\n        a //= 2\n        A = ax * ax + ay * ay\n        B = a * ax\n        C = a * a - ay * ay * c\n        D = B * B - A * C\n        if (D < 0):\n            continue\n        sD = sqrt(D)\n        if D != sD * sD:\n            continue\n        if (B + sD) % A == 0:\n            qx = (B + sD) // A\n            qy = (a - ax * qx) // ay\n            if rev:\n                t = qx\n                qx = qy\n                qy = t\n            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):\n                qx = (qx + sx) // n\n                qy = (qy + sy) // n\n                ans.append([qx, qy])\n        if sD == 0:\n            continue\n        if (B - sD) % A == 0:\n            qx = (B - sD) // A\n            qy = (a - ax * qx) // ay\n            if rev:\n                t = qx\n                qx = qy\n                qy = t\n            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):\n                qx = (qx + sx) // n\n                qy = (qy + sy) // n\n                ans.append([qx, qy])\n                \n    ans.sort()\n    buf=[]\n    buf.append(len(ans))\n    for p in ans:\n            buf.append(p[0])\n            buf.append(p[1])\n    global pans\n    pans.append(\" \".join(map(str,buf)))\n\nwhile m > 0:\n    m -= 1\n    solve()\n    \nsys.stdout.write(\"\\n\".join(pans))\n       \n", "src_uid": "057fdc41579d2e070fb7ea2ebeecb0fa"}
{"source_code": "a=list(map(int,input().split()))\nn=a[0]\nl=a[1]\nr=a[-1]\ns=pow(2,r)-1\ns1=pow(2,r-1)\nsum_c=s+s1*(n-r)\nmax1=sum_c\ns=pow(2,l)-1\nsum_b1=s+n-l\nmin1=sum_b1\nprint(min1,max1)", "src_uid": "ce220726392fb0cacf0ec44a7490084a"}
{"source_code": "from fractions import Fraction as F\n\na, b, n = map(int, raw_input().split())\nfrac = F(a, b).limit_denominator(n)\nprint(\"{0}/{1}\".format(frac.numerator, frac.denominator))", "src_uid": "827bc6f120aff6a6f04271bc84e863ee"}
{"source_code": "n = int(input())\nif n % 2 == 0:\n    print('Mahmoud')\nelif n % 2 != 0:\n    print('Ehab')", "src_uid": "5e74750f44142624e6da41d4b35beb9a"}
{"source_code": "a1 = int(input())\na2 = int(input())\nk1 = int(input())\nk2 = int(input())\n\n\n\nn = int(input())\n\nmin_players = max(0, n - (a2*(k2-1)+a1*(k1-1)))\n\nmax_players = 0\n\ncards_left = n\n\nif k1 > k2:\n    t = k1\n    k1 = k2\n    k2 = t\n\n    t = a1\n    a1 = a2\n    a2 = t\n\n\nwhile a1 > 0 and cards_left - k1 >= 0:\n\n    max_players += 1\n    a1 -= 1\n    cards_left -= k1\n    # print(cards_left, a1, max_players)\nwhile a2 > 0 and cards_left - k2 >= 0:\n    max_players += 1\n    a2 -= 1\n    cards_left -= k2\n    # print(cards_left, a2, max_players)\n\nprint(min_players, max_players)\n\n", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91"}
{"source_code": "# -*- coding: UTF-8 -*-\n\n# from itertools import *\n# from collections import defaultdict\n\n# def gcd(a,b):\n#     while b > 0: a,b = b, a%b\n#     return a\n\n# def baseN(num,b,numerals=\"0123456789abcdefghijklmnopqrstuvwxyz\"):\n#     return ((num == 0) and  \"0\" ) or ( baseN(num // b, b).lstrip(\"0\") + numerals[num % b])\n\n# T = input()\n# St = raw_input()\n\nvags, pos, cont = map(int, raw_input().split())\nwhere = raw_input()\nif where == \"to tail\":\n    where = 1\nelse:\n    where = -1\n    \ndef make_move(pos, where):\n    pos = pos + where\n    if pos > vags:\n        pos = vags-1;\n        where = -1\n    if pos < 1:\n        pos = 2\n        where = 1\n    return pos, where\n\nstop = raw_input()\nfor i in xrange(len(stop)):\n    if stop[i] == \"1\":\n        cont, where = make_move(cont, where)\n        if where == 1:\n            pos = 1\n        else:\n            pos = vags\n    else:\n        if where == 1:\n            if pos>cont:\n                if pos != vags:\n                    pos += 1\n            else:\n                if pos != 1:\n                    pos -= 1\n        else:\n            if pos<cont:\n                if pos != 1:\n                    pos -= 1\n            else:\n                if pos != vags:\n                    pos += 1\n        cont, where = make_move(cont, where)\n    if pos == cont:\n        print \"Controller \", i+1\n        exit()\nprint \"Stowaway\"\n", "src_uid": "2222ce16926fdc697384add731819f75"}
{"source_code": "def sumInBase(n, base):\n    ans = 0\n    while n > 0:\n        ans += n % base\n        n //= base\n\n    return ans\n\n\ndef GCD(a, b):\n    if b == 0:\n        return a\n    return GCD(b, a % b)\n\n\n# end of our function\n\n\nn, sumOfAllBase = int(input()), 0\n\nfor i in range(2, n):\n    sumOfAllBase += sumInBase(n, i)\n\ntemp = GCD(sumOfAllBase, n - 2)\nprint('{}/{}'.format(sumOfAllBase // temp, (n - 2) // temp))", "src_uid": "1366732dddecba26db232d6ca8f35fdc"}
{"source_code": "from statistics import mean\nfrom math import factorial, log, ceil\n\n_lf = []\ndef logfact(n):\n    global _lf\n    CALCLEN = 2200\n    if not _lf:\n        _lf = [0]*CALCLEN\n        for i in range(2, CALCLEN):\n            _lf[i] = _lf[i-1] + log(i)\n    return _lf[n]\n\ndef unif_ml(xs):\n    #p1 = mean(xs)\n    p2 = max(xs) / 2\n    pmle = p2 #max(p1, p2) # probably actually not mle and biased towards 0\n    loglh = len(xs) * log(2*pmle + 1)\n    return loglh, pmle\n\ndef poiss_ml(xs):\n    pml = mean(xs)\n    loglh = len(xs)*pml + sum([-x*log(pml) + logfact(x) for x in xs])\n    return loglh, pml\n\ndef solve(xs):\n    ul, Pu = unif_ml(xs)\n    pl, Pp = poiss_ml(xs)\n    #print('dbg:', ul, pl)\n    if ul < pl:\n        p = 1.01*Pu\n    else:\n        p = Pp\n    print(ceil(p))\n\nif __name__ == '__main__':\n    v = int(input())\n    for i in range(v):\n        xs = [int(x) for x in input().split()]\n        solve(xs)\n", "src_uid": "18bf2c587415f85df83fb090e16b8351"}
{"source_code": "n=list(input())\np=list(input())\nt=len(n)\ncount = 0\nfor i in range(t-1):\n    if (n[i] == '0' and p[i] == '0' and p[i+1]=='0') :\n        count =count+1\n        n[i]='X'\n        p[i]='X'\n        p[i+1]='X'\n    elif (n[i] == '0' and p[i] == '0' and  n[i+1]=='0') :\n        count =count+1\n        n[i]='X'\n        p[i]='X'\n        n[i+1]='X'\n    elif (n[i] =='0' and n[i+1] =='0' and p[i+1]=='0') :\n        count =count+1\n        n[i+1]='X'\n        n[i]='X'\n        p[i+1]='X'\n    elif ( p[i] =='0' and n[i+1] =='0' and p[i+1]=='0') :\n        count =count+1\n        n[i+1]='X'\n        p[i]='X'\n        p[i+1]='X'\nprint(count)", "src_uid": "e6b3e787919e96fc893a034eae233fc6"}
{"source_code": "n,v,e=map(int,raw_input().split())\na=[0]*(n+10)\nb=[0]*(n+10)\nE=[[] for i in xrange(n)]\nf=[i for i in xrange(n)]\nvis=[0]*(n+10)\nans=[]\nrem=0\ndef fd(x):\n\tif f[x]==x: return x\n\telse:\n\t\tf[x]=fd(f[x])\n\t\treturn f[x]\ndef dfs2(u,f,ty):\n\tglobal rem\n\tif rem<=a[u] and rem>0:\n\t\tif ty==0: ans.append([u,f,rem])\n\t\telse: ans.append([f,u,rem])\n\t\ta[u]-=rem\n\t\ta[f]+=rem\n\t\trem=0\n\telse:\n\t\trem-=a[u]\n\t\tfor v in E[u]:\n\t\t\tif v==f or vis[v]: continue\n\t\t\tdfs2(v,u,ty)\n\t\t\tif rem==0: break\n\t\tif f!=-1:\n\t\t\tif ty==0: ans.append([u,f,a[u]])\n\t\t\telse: ans.append([f,u,a[u]])\n\t\t\ta[f]+=a[u]\n\t\t\ta[u]=0\t\t\t\t\ndef solve(c):\n\tif a[c]==b[c]: return\n\tglobal rem\n\tif a[c]<b[c]:\n\t\trem=b[c]\n\t\tdfs2(c,-1,0)\n\telse:\n\t\tfor i in xrange(n): a[i],b[i]=v-a[i],v-b[i]\n\t\trem=b[c]\n\t\tdfs2(c,-1,1)\n\t\tfor i in xrange(n): a[i],b[i]=v-a[i],v-b[i]\t\t\ndef dfs(u,f):\n\tfor v in E[u]:\n\t\tif v==f: continue\n\t\tdfs(v,u)\n\tsolve(u)\n\tvis[u]=1\na=map(int,raw_input().split())\nb=map(int,raw_input().split())\nfor i in xrange(e):\n\tx,y=map(lambda x:int(x)-1,raw_input().split())\n\tif fd(x)!=fd(y):\n\t\tE[x].append(y)\n\t\tE[y].append(x)\n\t\tf[fd(x)]=fd(y)\nfor i in xrange(n):\n\tif fd(i)!=i: continue\n\tsa=sum(a[j] for j in xrange(n) if (fd(j)==i))\n\tsb=sum(b[j] for j in xrange(n) if (fd(j)==i))\n\tif sa!=sb:\n\t\tprint \"NO\"\n\t\texit()\n\tdfs(i,-1)\nprint len(ans)\nfor c in ans:\n\tprint c[0]+1,c[1]+1,c[2]\n", "src_uid": "0939354d9bad8301efb79a1a934ded30"}
{"source_code": "n,m=map(int,raw_input().split())\ns=list(raw_input())\n\nfor _ in range(m):\n    i=0\n    while i<n-1:\n        if(s[i]=='B' and s[i+1]=='G'):\n            s[i],s[i+1]=s[i+1],s[i]\n            i+=1\n        i+=1\nprint \"\".join(s)\n", "src_uid": "964ed316c6e6715120039b0219cc653a"}
{"source_code": "def solve(interesting):\n\t\n\tif interesting[0] > 15:\n\t\treturn 15\n\n\tans = interesting[0]\n\n\tfor e in interesting[1:]:\n\n\t\tif e - ans > 15:\n\t\t\treturn ans + 15\n\t\telse:\n\t\t\tans = e\n\n\treturn min(ans + 15, 90)\n\nn = input()\ninteresting = map(int, raw_input().split())\nprint solve(interesting)", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27"}
{"source_code": "S = 'CODEFORCES'\nn = len(S)\ns = str(input())\na = False\n\nfor i in range(n):\n    k = s.find(S[:n - i])\n    if k != -1:\n        p = k\n        while p != -1:\n            p = s.find(S[n - i:], p + 1)\n            v1 = (k, k + n - i)\n            v2 = (p, p + i)\n            #print('{} {}'.format(v1, v2))\n            if v1[0] == 0 and v2[1] == len(s):\n                a = True\n            elif (v1[0] == 0 or v2[1] == len(s)) and v2[1] - v1[0] == 10:\n                a = True\n    \nif a:\n    print('YES')\nelse:\n    print('NO')", "src_uid": "bda4b15827c94b526643dfefc4bc36e7"}
{"source_code": "import collections\ns = []\ndef solve(a):\n\tif a[1]=='>':\n\t\treturn a[0]\n\telse:\n\t\treturn a[2]\ns.append(solve(raw_input()))\ns.append(solve(raw_input()))\ns.append(solve(raw_input()))\ns = collections.Counter(s)\nr = ['','','']\nif len(s)==2:\n\tfor k,v in s.items():\n\t\tif v==2:\n\t\t\tr[2]=k\n\t\tif v==1:\n\t\t\tr[1]=k\n\tfor i in 'ABC':\n\t\tif i not in r:\n\t\t\tr[0]=i\n\tprint ''.join(r)\n\nelse:\n\tprint 'Impossible'", "src_uid": "97fd9123d0fb511da165b900afbde5dc"}
{"source_code": "line = raw_input()\nn=int(line.split()[0])\na=int(line.split()[1])\nb=int(line.split()[2])\n\nif (b<0) : condition = 0\nelse : condition = 1\n\nb = abs(b)\nb = b%n\nif condition==1:\n    print (a+b)%(n+1) + (a+b)/(n+1)\nelse:\n    if (a>b):\n        print a-b\n    else:\n        print n-(b-a)\n        \n", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4"}
{"source_code": "from itertools import combinations\ndef out1(a,b,c):\n    if a<0 or b<0 or c<0:\n        return 0\n    if a==1 and b==0 and c==0:\n        return 1\n    return a*(out2(a-1,b,c)+out3(a-1,b,c))\ndef out2(a,b,c):\n    if a<0 or b<0 or c<0:\n        return 0\n    if a==0 and b==1 and c==0:\n        return 1\n    return b*(out1(a,b-1,c)+out3(a,b-1,c))\ndef out3(a,b,c):\n    if a<0 or b<0 or c<0:\n        return 0\n    if a==0 and b==0 and c==1:\n        return 1\n    return c*(out2(a,b,c-1)+out1(a,b,c-1))\ndef column(matrix, i):\n    return [row[i] for row in matrix]\n    \nN, T = [int(x) for x in input().split()]\nA = []\ns = 0\nfor i in range(N):\n    A.append([int(x) for x in input().split()])\nfor i in range(1,N+1):\n    comb = list(combinations(A, i))\n    for x in comb:\n        if sum(column(x,0))==T:\n            a = column(x,1).count(1)\n            b = column(x,1).count(2)\n            c = column(x,1).count(3)\n            s+=(out1(a,b,c)+out2(a,b,c)+out3(a,b,c))\nprint(s%1000000007)", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56"}
{"source_code": "a=input()\ndef diff(a,b):\n    return sum(i!=j for i,j in zip(a,b))\nprint(a.lower() if diff(a,a.lower())<=diff(a,a.upper()) else a.upper())", "src_uid": "b432dfa66bae2b542342f0b42c0a2598"}
{"source_code": "a, b = [int(x) for x in input().split()]\nans = 0\nwhile (a != 1 and b != 1):\n  if (a > b):\n    ans += a // b\n    a %= b\n  a, b = b, a\nans += a+b-1\nprint(ans)\n", "src_uid": "792efb147f3668a84c866048361970f8"}
{"source_code": "import sys\n\nif sys.version_info < (3,0):\n    input = raw_input\n\n\nw, h, k = [ int(x) for x in input().split()]\n\ndef num_cells(n, m):\n    return 2*n + 2*m - 4\n\nres = 0\n\nfor i in range(k):\n    res += num_cells(w-4*i, h-4*i)\nprint(res)\n", "src_uid": "2c98d59917337cb321d76f72a1b3c057"}
{"source_code": "b,a=map(int,raw_input().split())\nres=0\ndig=1\nwhile(a!=0 or b!=0):\n\tres+=dig*(((a%3)+3-b%3)%3)\n\tdig*=3\n\ta/=3\n\tb/=3\nprint res\t\t\n\n", "src_uid": "5fb635d52ddccf6a4d5103805da02a88"}
{"source_code": "import math\nimport operator as op\n\nfrom functools import reduce\n\nfrom operator import mul    # or mul=lambda x,y:x*y\nfrom fractions import Fraction\n\ndef nCk(n,k): \n  return int( reduce(mul, (Fraction(n-i, i+1) for i in range(k)), 1) )\n\n\ndef ncr(n, r):\n    r = min(r, n-r)\n    if r == 0: return 1\n    numer = reduce(op.mul, range(n, n-r, -1))\n    denom = reduce(op.mul, range(1, r+1))\n    return numer//denom\n\ndef modPow(a, x, p):\n    #calculates a^x mod p in logarithmic time.\n    res = 1\n    while(x > 0):\n        if( x % 2 != 0):\n            res = (res * a) % p\n            \n        a = (a * a) % p\n        x = int(x/2)\n    return res\n\ndef modInverse(a, p):\n    #calculates the modular multiplicative of a mod m.\n    #(assuming p is prime).\n    return modPow(a, p-2, p)\n\ndef modBinomial(n, k, p):\n    #calculates C(n,k) mod p (assuming p is prime).\n\n    # n * (n-1) * ... * (n-k+1)\n    numerator = 1 \n    for i in range(k):\n        numerator = (numerator * (n-i) ) % p\n\n    denominator = 1\n    for i in range(1, k+1):\n        denominator = (denominator * i) % p\n\n    # numerator / denominator mod p.\n    return ( numerator* modInverse(denominator,p) ) % p\n\n\nn, c = input().split()\nn = int(n)\nc = int(c)\n\n#test = [0 for x in range (n+1)]\n#test[1] = c\n\n#for i in range(2, n+1):\n#    test[i] = (test[i-1] + modBinomial((i+c-1),i, 1000003))%1000003\n\n#ans = solve(n, c)\n#ans =test[n]\nans = modBinomial((c+n),c,1000003) - 1\nprint(int(ans))\n", "src_uid": "e63c70a9c96a94bce99618f2e695f83a"}
{"source_code": "def Prov(val):\n    val=str(val)\n\n    return val==val[::-1]\np,q= map(int,input().split(' '))\npmas = [1 for i in range(2000000)]\npmas[0]=0\npmas[1]=0\n\nfor i in range(2,2000000):\n    if  pmas[i]==1:\n        for j in range(i+i,2000000,i):\n            pmas[j]=0\n\npalmas=[1 if Prov(i) else 0\n        for i in range(2000000)]\nsu=0\nfor i in range(1,2000000):\n    if palmas[i]:\n        su+=p\n    palmas[i]=su\nsu=0\nfor i in range(1,2000000):\n    if pmas[i]:\n        su+=q\n    pmas[i]=su\nsu=0\nfor i in range(1,2000000):\n    if pmas[i]<=palmas[i]:\n        su=i\nprint(su)\n\n\n\n\n", "src_uid": "e6e760164882b9e194a17663625be27d"}
{"source_code": "x,y,z=map(int,input().split())\na,b,c=map(int,input().split())\nfg=0\nif a>=x:\n    a-=x\n    b+=a\n    if b>=y:\n        b-=y\n        c+=b\n        if c>=z:print(\"YES\")\n        else:print(\"NO\")\n    else:print(\"NO\")\nelse:print(\"NO\")\n    ", "src_uid": "d54201591f7284da5e9ce18984439f4e"}
{"source_code": "import sys\n\nn = input()\n\nx = 1\nr = 1\nD = []\nwhile True:\n\n    r = int(bin(x)[2:])\n    x += 1\n\n    if r>n:\n        break\n    D.append(r)\n\n\ndp = [[0,0] for i in range(n+1)]\n\nfor i in range(1, n+1):\n\n    lopt = 10000000\n    \n    for j in D:\n        if j <= i:\n\n            l = 1+dp[i-j][0]\n            r = i-j\n\n            if l < lopt:\n                lopt = l\n                ropt = r\n\n    dp[i] = [lopt, ropt]\n            \n\nprint dp[n][0]\n\nwhile n != 0:\n    print n - dp[n][1],\n    n = dp[n][1]\n\n    \n    \n", "src_uid": "033068c5e16d25f09039e29c88474275"}
{"source_code": "\nchns='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n\nnums=[0, 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]\n\nmp={}\n\nfor ind, i in enumerate(chns):\n    mp[i]=nums[ind]\n\nans=[]\nh, m = input().split(':')\nminsys=max([mp[i] for i in (h+m)])+1\nfor sys in range(minsys,101):\n    h10=0\n    for pw, i in enumerate(reversed(h)):\n        h10+=sys**pw*mp[i]\n    m10=0\n    for pw, i in enumerate(reversed(m)):\n        m10+=sys**pw*mp[i]\n    if(h10<=23 and h10>=0 and m10<=59 and m10>=0):\n        ans.append(sys)\n\nif 100 in ans:\n    print(-1)\n    quit()\nif len(ans) == 0:\n    print(0)\n    quit()\nfor i in ans:\n    print(i, end=' ') ", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293"}
{"source_code": "n = int(input())\nx = input()\nnormyear = \"31 28 31 30 31 30 31 31 30 31 30 31 \"\nleapyear = \"31 29 31 30 31 30 31 31 30 31 30 31 \"\nans = 3*normyear + leapyear + 3*normyear\nprint(\"Yes\" if ans.count(x) else \"No\")\n", "src_uid": "d60c8895cebcc5d0c6459238edbdb945"}
{"source_code": "n, a, b = map(int, raw_input().split())\n\n\ndef get_new_xy(n, a, b):\n    A = 6*n\n    a1 = a\n    b1 = b\n    if A <= a * b:\n        return a1, b1\n\n    if a<=b:\n        a1 = a\n        b1 = b\n    else:\n        a1 = b\n        b1 = a\n\n    i = a1\n    prev_s = 10000000000000000\n    a2 = a1\n    b2 = b1\n    while i*i <= A:\n        tmpb = A / i\n\n        if tmpb < b1:\n            i += 1\n            continue\n\n        if i*tmpb < A:\n            tmpb += 1\n\n        if i*tmpb <= prev_s:\n            a2 = i\n            b2 = tmpb\n            prev_s = a2 * b2\n        i += 1\n\n    return (a2, b2) if a <= b else (b2, a2)\n\n\na1, b1 = get_new_xy(n, a, b)\n\nprint a1*b1\nprint a1, b1", "src_uid": "6a2a584d36008151d18e5080aea5029c"}
{"source_code": "#!/usr/bin/env python\n# -*- coding: UTF-8 -*-\nimport time\nimport sys, io\nimport re, math\nstart = time.clock()\nm=raw_input()\nchk=re.compile(r'^\\w{1,16}\\@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?$')\ni=chk.match(m)\n#print 'YES' if i else 'NO'\nprint 'YES' if i else 'NO'", "src_uid": "2a68157e327f92415067f127feb31e24"}
{"source_code": "n,k=map(int,raw_input().split())\na=(map(int,raw_input().split()))\nb=sorted(a)\nx=0\nwhile x<len(b) and k-b[x]>=0:\n    k-=b[x]\n    x+=1\nprint x\nfor i in range(0,x):\n    x = a.index(b[i])+1\n    print x,\n    a[x-1]=-1\n", "src_uid": "dbb164a8dd190e63cceba95a31690a7c"}
{"source_code": "def generate_substring(s):\n    list = []\n    ll = len(string)\n    for i in range(ll):\n        for j in range(i, ll):\n            list.append(s[i:j + 1])\n    return list\n\nn = input()\nstring = raw_input()\nans = 0\nsumH = 0\nsumW = 0\n\nfor x in generate_substring(string):\n    sumH = 0\n    sumW = 0\n    for char in x:\n        if char == \"U\":\n            sumH += 1\n        if char == \"D\":\n            sumH -= 1\n        if char == \"L\":\n            sumW -= 1\n        if char == \"R\":\n            sumW += 1\n    if sumH == 0 and sumW == 0:\n        ans += 1\n\nprint ans\n", "src_uid": "7bd5521531950e2de9a7b0904353184d"}
{"source_code": "s = raw_input()\nprint \"%05d\" % (int(s[0] + s[2] + s[4] + s[3] + s[1]) ** 5 % 100000)\n", "src_uid": "51b1c216948663fff721c28d131bf18f"}
{"source_code": "def factorize(n):\n    m = n\n    i = 2\n    v = []\n\n    while(i * i <= m):\n        while(n % i == 0):\n            v.append(i)\n            n /= i\n        i += 1\n\n    if (n != 1):\n        v.append(n)\n\n    return v\n\nif __name__ == \"__main__\":\n    primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\n    n = int(raw_input())\n    v = factorize(n)\n    v.sort(reverse = True)\n\n    m = len(v)\n    ans = 10 ** 18 + 1\n    for i in range(0, 1 << m):\n        b = []\n        temp = 1\n        \n        for j in range(m):\n            if (i & (1 << j)):\n                temp *= v[j]\n            else:\n                b.append(v[j])\n\n        b.append(temp)\n        b.sort(reverse = True)\n\n        x = 1\n        for j in range(len(b)):\n            x *= primes[j] ** (b[j] - 1)\n\n        ans = min(ans, x)\n\n    print ans", "src_uid": "62db589bad3b7023418107de05b7a8ee"}
{"source_code": "k, p = map(int, raw_input().split())\n_sum = 0\nfor i in xrange(1, k+1):\n\t_sum += int(str(i)+str(i)[::-1])\nprint _sum%p\n", "src_uid": "00e90909a77ce9e22bb7cbf1285b0609"}
{"source_code": "p = int(input())\nn = list(map(int, input().split()))\nf = n.index(p)\ns = p - 1 - f\nt = n.index(1)\nc = p - 1 - t\nprint(max(f, s, t, c))\n", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4"}
{"source_code": "import math\ndef panduan(x1,y1,x2,y2,x3,y3):\n    a=(x1-x2)**2+(y1-y2)**2\n    b=(x1-x3)**2+(y1-y3)**2\n    c=(x3-x2)**2+(y3-y2)**2\n    #print a,b,c\n    if a==0 or b==0 or c==0:return False;\n    if b<c:d=b;b=c;c=d;\n    if a<b:d=a;a=b;b=d;\n    #print a,b,c\n    if a==b+c:return True;\n    else: return False;\ndef fun():\n    x1,y1,x2,y2,x3,y3=map(int,raw_input().split())\n\n    if panduan(x1,y1,x2,y2,x3,y3):print \"RIGHT\";\n    elif panduan(x1+1,y1,x2,y2,x3,y3) or panduan(x1,y1+1,x2,y2,x3,y3) or panduan(x1,y1,x2+1,y2,x3,y3) or panduan(x1,y1,x2,y2+1,x3,y3) or panduan(x1,y1,x2,y2,x3+1,y3) or panduan(x1,y1,x2,y2,x3,y3+1) or panduan(x1-1,y1,x2,y2,x3,y3) or panduan(x1,y1-1,x2,y2,x3,y3) or panduan(x1,y1,x2-1,y2,x3,y3) or panduan(x1,y1,x2,y2-1,x3,y3) or panduan(x1,y1,x2,y2,x3-1,y3) or panduan(x1,y1,x2,y2,x3,y3-1):\n        print \"ALMOST\";\n    else:print \"NEITHER\"\n\nif __name__==\"__main__\":\n    fun()\n", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d"}
{"source_code": "r, c, n, k = map(int, input().split())\nd = [[0 for j in range(c+1)] for i in range(r+1)]\nfor i in range(n):\n    x, y = map(int, input().split())\n    d[x][y] = 1\nfor i in range(1,r+1):\n    for j in range(1,c+1):\n        d[i][j] = d[i][j] + d[i-1][j] + d[i][j-1] - d[i-1][j-1]\na = 0\nfor i in range(1,r+1):\n    for j in range(1,c+1):\n        for x in range(i,r+1):\n            for y in range(j,c+1):\n                if d[x][y] - d[x][j-1] - d[i-1][y] + d[i-1][j-1] >= k:\n                    a += 1\n\nprint(a)\n", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"}
{"source_code": "#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3\n'''\nCreated on 13/09/2018\n\n@author: ernesto\n'''\n\nn, m = [int(x) for x in input().strip().split(\" \")]\n\nposibles_jefes = set(range(1, n + 1))\nanteriores = set()\nposteriores = set()\ncontinuos = [True] * (n + 1)\nmencionados = set()\nposibles_jefes_mencionados = set()\nultimo_en_salir = [True] * (n + 1)\nultima_salida_inesperada = None\n\nops = []\n\nif(m > 1):\n    for _ in range(0, m):\n        s, n_s = [x for x in input().strip().split(\" \")]\n        n = int(n_s)\n        ops.append((s, n))\n    for i in range(0, m):\n        op, num = ops[i]\n        cont = False\n        if op == '+':\n            cont = not i or (ops[i - 1][0] == '-' and ops[i - 1][1] == num)\n            posteriores.add(num)\n        if op == '-':\n            cont = i == m - 1 or (ops[i + 1][0] == '+' and ops[i + 1][1] == num)\n            if num not in mencionados:\n                anteriores.add(num)\n                ultima_salida_inesperada = num\n            posteriores.discard(num)\n            ultimo_en_salir[num] &= not posteriores\n        continuos[num] &= cont \n        mencionados.add(num)\n#    print(\"anteriores {} posteriores {} continuos {} ops {}\".format(anteriores, posteriores, continuos, ops))\n    if not anteriores and not posteriores:\n        assert ultima_salida_inesperada is None\n        if ops[0][0] == '+' and ops[-1][0] == '-' and ops[0][1] == ops[-1][1] and continuos[ops[0][1]] and ultimo_en_salir[ops[0][1]]:\n            posibles_jefes_mencionados.add(ops[0][1])\n    else:\n        if not posteriores:\n            assert ultima_salida_inesperada is not None\n            posibles_jefes_filtrados = list(filter(lambda x:continuos[x] and ultimo_en_salir[x] and ultima_salida_inesperada == x, anteriores))\n            assert len(posibles_jefes_filtrados) <= 1\n            if(posibles_jefes_filtrados):\n                assert posibles_jefes_filtrados[0] == ops[-1][1]\n                posibles_jefes_mencionados.add(ops[-1][1])\n        else:\n            if not anteriores:\n                assert ultima_salida_inesperada is None\n                posibles_jefes_filtrados = list(filter(lambda x:continuos[x] and ultimo_en_salir[x], posteriores))\n#                print(\"posibles {}\".format(posibles_jefes_filtrados))\n                assert len(posibles_jefes_filtrados) <= 1\n                if(posibles_jefes_filtrados):\n                    assert posibles_jefes_filtrados[0] == ops[0][1]\n                    posibles_jefes_mencionados.add(ops[0][1])\n            else:\n                assert ultima_salida_inesperada is not None\n#                print(\"continuos {}\".format(continuos))\n                posibles_jefes_mencionados = set(filter(lambda x:ultimo_en_salir[x] and continuos[x] and ultima_salida_inesperada == x, anteriores & posteriores))\n\n#    print(\"posibles jefes menc {}\".format(posibles_jefes_mencionados))\n    posibles_jefes -= (mencionados - posibles_jefes_mencionados)\n        \nprint(len(posibles_jefes))\nif(len(posibles_jefes)):\n    print(\" \".join(map(str, sorted(posibles_jefes))))\n", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5"}
{"source_code": "n = input()\ns = raw_input()\nds = s.split(' ')\nd = []\nsm = 0\nfor i in xrange(n):\n    d.append(int(ds[i]))\n    sm += int(ds[i])\n\n#print n, d, sm\ndiv = n + 1\n\nnn = 0\nfor i in xrange(5):\n    tst = sm + i\n    if (tst % div)!=0:\n        nn+=1\n\nprint nn\n", "src_uid": "ff6b3fd358c758324c19a26283ab96a4"}
{"source_code": "k = int(input())\nq = input()\na = []\nresult = []\nfor i in range(97, 123):\n    a.append(chr(i))\nfor (j, t) in enumerate(q):\n    if len(result) == k:\n        result[len(result) - 1] += q[j:]\n        break\n    if t in a:\n        a.remove(t)\n        result.append(q[j])\n    else:\n        result[len(result) - 1] += t\nif len(result) == k:\n    print('YES')\n    for row in result:\n        print(row)\nelse:\n    print('NO')", "src_uid": "c1b071f09ef375f19031ce99d10e90ab"}
{"source_code": "import bisect\nn,m=map(int,input().split())\na=[]\nb=[]\nfor i in range(m):\n    s,d,c=map(int,input().split())\n    if c>d-s+1:\n        print(-1)\n        quit()\n    l=bisect.bisect_left(b,d)\n    a.insert(l,[s,d,c,i+1])\n    b.insert(l,d)\nds=list('0' for i in range(n))\nfor i in range(m):\n    s,d,c,mi=a[i]\n    c0=0\n    for j in range(s,d):\n        if ds[j-1]=='0':\n            ds[j-1]=str(mi)\n            c0+=1\n        if c0>=c:\n            break\n    if c0<c:\n        print(-1)\n        quit()\n    ds[d-1]=str(m+1)\nprint(' '.join(ds))\n", "src_uid": "02d8d403eb60ae77756ff96f71b662d3"}
{"source_code": "\nn = input()\nlog = len(n)-1 \nlarge = 10**log\nluck = (int(n)//large) * large + large\nprint(luck - int(n))\n\n\n", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e"}
{"source_code": "n = input()\nx = input().split()\nset_x = set(x)\nlist_x = list(set_x)\nlength = len(list_x)\nfor x in range(length):\n    list_x[x] = int(list_x[x])\nlist_x.sort()\nif length > 1:\n    diff = abs(list_x[0] - list_x[1])\n#print(diff)\n#print (list_x)\nif length > 2:\n    for i in range(length - 1):\n        new_diff = abs(list_x[i] - list_x[i+1])\n        #print (new_diff)\n        if diff == new_diff:\n            val = 1\n        else:\n            val = 0\nif length == 2:\n    if diff % 2 == 0:\n        diff = diff//2\n        val = 1\n    else:\n        val = 1\nif length == 1:\n    val = -1\nif length > 3:\n    val = 0\nif val == 1:\n    print(diff)\nelif val == 0:\n    print (-1)\nelse:\n    print(0)", "src_uid": "d486a88939c132848a7efdf257b9b066"}
{"source_code": "n, k = map(int, input().split(\" \"))\nr = 2 * n\ng = 5 * n\nb = 8 * n\nanswer = 0\nif r > 0:\n    answer += r//k\n    if r % k != 0:\n        answer += 1\nif g > 0:\n    answer += g//k\n    if g % k != 0:\n        answer += 1\n\nif b > 0:\n    answer += b//k\n    if b % k != 0:\n        answer += 1\n\n\nprint(answer)", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39"}
{"source_code": "#! /usr/bin/python\n\ndef R(v, x, y, c1, c2):\n    c1 = max(0, c1 - v/y + v/(x*y))\n    c2 = max(0, c2 - v/x + v/(x*y))\n    return c1 + c2 <= v - v/x - v/y + v/(x*y)\n\n\nif __name__ == \"__main__\":\n    debug = False\n    c1, c2, x, y = map(int, raw_input().split())\n    l = 1\n    r = (c1/(x-1) + 1) * x + (c2/(x-1) + 1) * y\n    if debug:\n        print l, r\n    \n    m = 0\n    while l<r:\n        m = (l+r)/2\n        rm = R(m, x, y, c1, c2)\n        rm1 = R(m-1, x, y, c1, c2)\n\n        if debug and r - l < 10:\n            print l, r, m, rm1, rm\n\n        if not rm1 and rm:\n            break\n        elif not rm:\n            l = m + 1\n        else:\n            r = m\n\n    print m\n", "src_uid": "ff3c39b759a049580a6e96c66c904fdc"}
{"source_code": "N,M = map(int,raw_input().split())\n\nP = {}\nQ = {}\nfor i in range(10001):\n    for j in range(1,5):\n        P[(i,j)] = set()\n        Q[(i,j)] = set()\n\nfor i in range(10):\n    P[(i,1)].add(i)\n    Q[(i,1)].add(i)\nfor i in range(100):\n    P[(i,2)].add(i)\n    Q[(i,2)].add(i)\n    a,b = i/10,i%10\n    next = [a+b,abs(a-b),a*b]\n    for j in next:\n        P[(j,2)].add(i)\n        Q[(i,2)].add(j)\nfor i in range(1000):\n    P[(i,3)].add(i)\n    Q[(i,3)].add(i)\n    candidate = [((i/100,1),(i%100,2)),((i/10,2),(i%10,1))]\n    next = []\n    for p,q in candidate:\n        for a in Q[p]:\n            for b in Q[q]:\n                next.append(a+b)\n                next.append(abs(a-b))\n                next.append(a*b)\n    next = set(next)\n    for j in next:\n        P[(j,3)].add(i)\n        Q[(i,3)].add(j)\nfor i in range(10000):\n    P[(i,4)].add(i)\n    Q[(i,4)].add(i)\n    candidate = [((i/1000,1),(i%1000,3)),((i/100,2),(i%100,2)),((i/10,3),(i%10,1))]\n    next = []\n    for p,q in candidate:\n        for a in Q[p]:\n            for b in Q[q]:\n                next.append(a+b)\n                next.append(abs(a-b))\n                next.append(a*b)\n    next = set(next)\n    for j in next:\n        P[(j,4)].add(i)\n        Q[(i,4)].add(j)\n\ndef f(n,m,p):\n    for i in range(10000):\n        for j in p[(abs(n-i),4)]:\n            print '%04d%04d'%(i,j)\n            m -= 1\n            if m == 0:\n                return\n\nf(N,M,P)\n", "src_uid": "4720ca1d2f4b7a0e553a3ea07a76943c"}
{"source_code": "N = 200001\nMOD = 1000000007\nfact = [1] * N\ninv_fact = [1] * N\n\ndef ModExp(a, n):\n    ans = 1\n    while n:\n        if n % 2:\n            ans = (ans * a) % MOD\n        a = (a * a) % MOD\n        n /= 2\n    return ans\n\ndef ModInverse(a):\n    return ModExp(a, MOD - 2)\n\ndef PreProcess(n):\n    for i in range(1, n + 1):\n        fact[i] = (i * fact[i - 1]) % MOD\n\n    inv_fact[n] = ModInverse(fact[n])\n    for i in range(n - 1, 0, -1):\n        inv_fact[i] = ((i + 1) * inv_fact[i + 1]) % MOD\n\ndef nCr(n, r):\n    if n < 0 or r < 0 or n < r:\n        return 0\n    else:\n        return (fact[n] * (inv_fact[r] * inv_fact[n - r]) % MOD) % MOD\n\ndef Beggar(m, n):\n    if m < 0 or n < 0 or (n == 0 and m != 0):\n        return 0\n    else:\n        if m + n == 0:\n            return 1\n        else:\n            return nCr(m + n - 1, m)\n\nf, w, h = map(int, raw_input().split())\nn = f + w\n\nPreProcess(n)\n\nq = nCr(n, w)\np = 0\n\nfor n in range(0, w + 1):\n    if n * (h + 1) > w:\n        break\n    else:\n        p += (Beggar(w - n * (h + 1), n) * ((Beggar(f - n - 1, n + 1) + Beggar(f - n + 1, n - 1) + 2 * Beggar(f - n, n)) % MOD)) % MOD\n\nq = ModInverse(q)\nans = (p * q) % MOD\n\nprint ans\n", "src_uid": "a69f95db3fe677111cf0558271b40f39"}
{"source_code": "s=[]\nresponse='NO'\nfor _ in range(4):\n    s=s+[input()]\nwins=['xx.','x.x','.xx','xxx']\nfor i in range(4):\n    if s[i][1:] in wins or s[i][:3] in wins:\n        response='YES'\n    if i>1:\n        for j in range(4):\n            if s[i-2][j]+s[i-1][j]+s[i][j] in wins:\n                response='YES'    \nfor i in range(1,3):\n    for j in range(1,3):\n        if s[i-1][j-1]+s[i][j]+s[i+1][j+1] in wins or s[i-1][j+1]+s[i][j]+s[i+1][j-1] in wins or s[i-1][j+1]+s[i][j]+s[i+1][j-1] in wins:\n            response='YES'\nprint(response)", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"}
{"source_code": "from sys import stdin, stdout\n\ndef solution():\n    \n    reference = stdin.readline()\n\n    cards = [str(x) for x in stdin.readline().rstrip().split()]\n    \n    for i in cards:\n        \n    \tif i[0]==reference[0] or i[1]==reference[1]:\n    \t\treturn 'YES'\n\t    \n    return 'NO'\n    \n\nprint(solution())", "src_uid": "699444eb6366ad12bc77e7ac2602d74b"}
{"source_code": "n=int(input())\ns=input()\nnum=0\ncolor=s[0]\nfor i in range(1,n):\n    if s[i]==color:\n        num+=1\n    else:\n        color=s[i]\nprint(num)\n", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"}
{"source_code": "q = 998244353   \nn, m, l, r = map(int, input().split())\nif n * m % 2 == 1:\n    print(pow(r - l + 1, n * m, q))\nelif (r - l + 1) % 2 == 0:\n    print(pow(r - l + 1, n * m, q) *\n          (q + 1) // 2 % q)\nelse:\n    print((pow(r - l + 1, n * m, q) + 1) *\n          (q + 1) // 2 % q)\n", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3"}
{"source_code": "w,h=map(int,input().split())\nprint(pow(2,w+h,998244353))", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee"}
{"source_code": "z,zz=input,lambda:list(map(int,z().split()));\nszz,dgraphs,mod=lambda:sorted(zz()),{},10**9+7\nfrom string import *\nfrom collections import *\nfrom queue import *\nfrom sys import *\nfrom collections import *\nfrom math import *\nfrom heapq import *\nfrom itertools import *\nfrom bisect import *\nfrom collections import Counter as cc\nfrom math import factorial as f\ndef lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))\ndef prime(x):\n    p=ceil(x**.5)+1\n    for i in range(2,p):\n        if x%i==0 and x!=2:return 0\n    return 1\ndef dfs(u,visit,graph):\n    visit[u]=True\n    for i in graph[u]:\n        if not visit[i]:\n            dfs(i,visit,graph)\n################################################################################\n\n\"\"\"\n\nled=(6,2,5,5,4,5,6,3,7,6)\n\ncolor4=[\"G\", \"GB\", \"YGB\", \"YGBI\", \"OYGBI\" ,\"OYGBIV\",'ROYGBIV' ]\n\n\"\"\"\n\n###########################---START-CODING---####################################\n\nn=int(z())\n\nif n%2==0:\n    print(n//2+1)\nelse:\n    print((n+1)//2)\n        \n        \n        \n            \n            \n            \n        \n        \n        \n        \n        \n    \n\n        \n\n", "src_uid": "5551742f6ab39fdac3930d866f439e3e"}
{"source_code": "st = raw_input()\nans = 'YES'\ns = {'a'}\nif st[0] != 'a':\n\tans = 'NO'\nfor i in st:\n\tif (i not in s) and (ord(i)-ord(max(s))>1):\n\t\tans = 'NO'\n\t\tbreak\n\ts |= {i}\nprint ans", "src_uid": "c4551f66a781b174f95865fa254ca972"}
{"source_code": "a=str(input())\ni=1\nc=str()\nif len(a)==1:\n    print(a)\nelse:\n    if len(a)%2 == 1:\n        for i in range(0,(len(a)//2)):\n            c=a[-i-1]+a[i]+c\n        print(a[len(a)//2]+c)\n    else:\n        for i in range(0,(len(a)//2)):\n            c=a[i]+a[-i-1]+c\n        print(c)\n\n", "src_uid": "992ae43e66f1808f19c86b1def1f6b41"}
{"source_code": "def f(n):\n    if n < 4: return '1\\n0'\n    k, j = int(n ** 0.5), 0\n    if n % 2 == 0:\n        if n % 4 == 0: return '1\\n4' if n > 4 else '2'\n        j = 2\n    if n % 3 == 0:\n        if j: return '1\\n6' if n > 6 else '2'\n        if n % 9 == 0: return '1\\n9' if n > 9 else '2'\n        j = 3\n    for i in range(5, k, 6):\n        if n % i == 0:\n            if j: return '1\\n' + str(i * j) \n            if n % (i * i) == 0: return '1\\n' + str(i * i)\n            j = i\n    for i in range(7, k, 6):\n        if n % i == 0:\n            if j: return '1\\n' + str(i * j) \n            if n % (i * i) == 0: return '1\\n' + str(i * i)\n            j = i\n    return '2' if j or k * k == n else '1\\n0'\nprint(f(int(input())))", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43"}
{"source_code": "#!/usr/bin/env python\n# -*- coding: UTF-8 -*-\nimport time\nimport sys\nimport io\nimport re\nimport math\nimport itertools\n#sys.stdin=file('input.txt')\n#sys.stdout=file('output.txt','w')\n#10**9+7\nmod=1000000007\n#mod=1777777777\npi=3.141592653589\nxy=[(1,0),(-1,0),(0,1),(0,-1)]\nbs=[(-1,-1),(-1,1),(1,1),(1,-1)]\n#start = time.clock()\nchk=[2,7,2,3,3,4,2,5,1,2]\nn=raw_input()\nif len(n)<2:\n    print 10*chk[int(n)]\nelse:\n    print chk[int(n[0])]*chk[int(n[1])] ", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5"}
{"source_code": "def gcd(x,y):\n    if y==0:return x\n    else:return gcd(y,x%y)\nA,H,W=map(int,input().split())\nG=gcd(A+H,A+W)\nS=(A+W)//G\nT=((W//A+1)//S)*S-1\nif T<=0:print(-1)\nelse:print(\"%.10lf\"%((W-T*A)/(T+1)))", "src_uid": "7fbefd3eb1aad6865adcfac394f0a7e6"}
{"source_code": "def raw():\n    return raw_input().strip()\n\n\ndef ints():\n    return map(int, raw().split())\n\nn = ints()[0]\n\nif n == 1:\n    print 1\n    exit(0)\n\nr = n\n\n\nfor i in xrange(2, n):\n    r += i * (n - (i - 1)) - (i - 1)\nr += 1\n\nprint r\n", "src_uid": "6df251ac8bf27427a24bc23d64cb9884"}
{"source_code": "n=int(input())\ndic={}\nfor i in range(1,n+1):\n    dic[i*i]=0\nans=0\nfor i in range(1,n+1):\n    for j in range(i,n+1):\n        if (i*i)+(j*j) in dic:\n            ans+=1\nprint(ans)\n", "src_uid": "36a211f7814e77339eb81dc132e115e1"}
{"source_code": "def ceildiv(a, b):\n    return -(-a // b)\n\n\ndef test_ceildiv():\n    assert ceildiv(6, 3) == 2\n    assert ceildiv(7, 3) == 3\n    assert ceildiv(5, 3) == 2\n\n\ndef brute_force(n, m):\n    \"\"\"Count numbers in range [0; m] equal to 4a + 9b + 49c\n\n    ...for some non-negative a, b and c such that (a + b + c) <= n\n    \"\"\"\n    numbers = set()\n\n    max_c = min(n, m // 49)\n    for c in range(max_c + 1):\n        _49c = 49 * c\n        max_b = min(n - c, (m - _49c) // 9, 48)\n        for b in range(max_b + 1):\n            _9b_49c = 9 * b + _49c\n            max_a = min(n - b - c, (m - _9b_49c) // 4, 8)\n            for a in range(max_a + 1):\n                numbers.add(4 * a + _9b_49c)\n\n    assert 0 in numbers\n    for x in (4, 9, 49):\n        if m // x <= n:\n            assert m - (m % 49) in numbers\n    return len(numbers)\n\n\ndef brute_force_range(n, l, u):\n    \"\"\"Count numbers in range [l; u] equal to 4a + 9b + 49c\n\n    ...for some non-negative a, b and c such that (a + b + c) <= n\n    \"\"\"\n    numbers = set()\n\n    min_c = max(0, ceildiv(l - 9 * n, 40))\n    max_c = min(n, u // 49)\n    for c in range(min_c, max_c + 1):\n        _49c = 49 * c\n        min_b = max(0, ceildiv(l - 4 * n - 45 * c, 5))\n        max_b = min(n - c, (u - _49c) // 9, 48)\n        for b in range(min_b, max_b + 1):\n            _9b_49c = 9 * b + _49c\n            min_a = max(0, ceildiv(l - _9b_49c, 4))\n            max_a = min(n - b - c, (u - _9b_49c) // 4, 8)\n            for a in range(min_a, max_a + 1):\n                numbers.add(4 * a + _9b_49c)\n\n    if numbers:\n        assert min(numbers) >= l\n        assert max(numbers) <= u\n    return len(numbers)\n\n\ndef test_brute_force_range():\n    for (u, l) in ((60, 80), (104, 599), (200, 777)):\n        for n in (10, 13, 15, 17, 20):\n            assert brute_force_range(n, u, l) == brute_force(n, l) - brute_force(n, u - 1)\n\n\n# For each m in rage [Y, Y + 49) exist integer a >= 0 and b >= 0\n# such that 4a + 9b = m and a + b <= X\nX = 12\nY = 24\n\n\ndef solid_interval(n):\n    assert n >= X\n    return Y, 49 * (n - X) + Y + 49\n\n\ndef test_solid_interval():\n    for n in X, X + 1, 100, 200, 300, 1000, 5000:\n        begin, end = solid_interval(n)\n        assert brute_force_range(n, begin, end - 1) == end - begin\n\n\ndef main():\n    n = int(input())\n\n    if n < X:\n        result = brute_force(n, 49 * n)  # naïve solution\n    else:\n        begin, end = solid_interval(n)\n        assert begin < end < 49 * n\n        result = sum((\n            brute_force_range(n, 0, begin - 1),\n            end - begin,  # == brute_force_range(n, begin, end - 1)\n            brute_force_range(n, end, 49 * n)\n        ))\n\n    print(result)\n\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "75ec99318736a8a1b62a8d51efd95355"}
{"source_code": "M, N = 998244353, 720720\r\nI = lambda: [int(x) for x in input().split()]\r\np = [0]*(N+1)\r\nres = 0\r\n\r\nn, a, x, y, k, U = I()\r\nfor i in range(1, n+1):\r\n    p[a%N] += 1\r\n    res += a//N * N\r\n    a = (a * x + y) % U\r\n\r\nres = (res * pow(n, k-1, M) * k) % M\r\nfor i in range(1, k+1):\r\n    tot = sum(p[j]*j for j in range(1, N+1)) % M\r\n    for j in range(1, N + 1):\r\n        t1 = p[j]\r\n        p[j] *= (n-1)\r\n        p[j] %= M\r\n        p[j - j%i] += t1\r\n    res += (tot * pow(n, k-i)) % M\r\n\r\nprint(res % M)", "src_uid": "1d45491e28d24e2b318605cd328d6ecf"}
{"source_code": "if __name__ == '__main__':\n    for _ in range(int(input())):\n        n=int(input())\n        x=len(str(n))\n        y=int(str(n)[0])\n        print(int(10*y-10+(x*x+x)/2))", "src_uid": "289a55128be89bb86a002d218d31b57f"}
{"source_code": "\"\"\"inf = open(\"in.txt\", \"r\")\noutf = open(\"out.txt\", \"w\")\n#---------------------------#\n\"\"\"\nlst = []\nk = 0\n\nn = input()\nfor i in range(n):\n    lst.append(raw_input().split())\n\nfor i in range(n):\n    for j in range(i + 1,n):\n        if lst[i][0] == lst[j][1]:\n            k += 1\n        if lst[i][1] == lst[j][0]:\n            k += 1\n\n\nprint k\n\n#-----------#\n#outf.close()", "src_uid": "745f81dcb4f23254bf6602f9f389771b"}
{"source_code": "l, r, x, y, k = map(int, input().split())\nL = x - 1\nR = y + 1\nwhile (R - L > 1):\n    M = (L + R) // 2\n    if (M * k <= r):\n        L = M\n    else:\n        R = M\nif (L * k >= l and L != x - 1):\n    print(\"YES\")\nelse:\n    print(\"NO\")", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048"}
{"source_code": "R=lambda:list(map(int,input().split()))\nk,l=R(); n=R(); m=sorted(R())\nn[n.index(0)]=m[0]\nprint(['YES','NO'][l==1 and n==sorted(n)])", "src_uid": "40264e84c041fcfb4f8c0af784df102a"}
{"source_code": "numbers = input()\na, b = numbers.split(\" \")\nif((int(b)-int(a))>=10):  print(0)\nelse :\n    res = 1\n    for i in range(int(a)+1,int(b)+1): res*=i\n    print(str(res)[len(str(res))-1])\n", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60"}
{"source_code": "s=input()\nc=''\nfor i in s:\n    if(i=='>'):\n        c+='1000'\n    elif(i=='<'):\n        c+='1001'\n    elif(i=='+'):\n        c+='1010'\n    elif(i=='-'):\n        c+='1011'\n    elif(i=='.'):\n        c+='1100'\n    elif(i==','):\n        c+='1101'\n    elif(i=='['):\n        c+='1110'\n    elif(i==']'):\n        c+='1111'\nc=c[::-1]\nr=0\nmod=1000003\nfor i in range(len(c)):\n    if(c[i]=='1'):\n        r+=(2**i)%mod\n        r%=mod\nprint(int(r))\n", "src_uid": "04fc8dfb856056f35d296402ad1b2da1"}
{"source_code": "from fractions import gcd\nimport math\nx,y=map(int,raw_input().split())\ntemp=x\np=1\nres=[]\ndef solve(n):\n    res = []\n    if n % 2 == 0: res.append(2)\n    while n % 2 == 0: n=n/2\n    for i in range(3, int(math.sqrt(n) + 1), 2):\n        if n % i == 0:\n            res.append(i)\n        while n % i == 0: n //= i\n    if n > 2: res.append(n)\n    return res\n\nres=solve(x)\n\nans=0\nwhile y!=0:\n    r=gcd(x,y)\n    x//=r\n    y//=r\n    m=0\n    for i in res:\n        if x%i==0: m=max(m,y-y%i)\n    ans+=y-m\n    y=m\nprint ans", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e"}
{"source_code": "n=int(input())\na=int(input())\nb=int(input())\nc=int(input())\n\npos = 1\nsteps=0\nfor i in range(n-1):\n    if pos == 1:\n        if a>b:\n            pos=2\n            steps+=b\n        else:\n            pos=3\n            steps+=a\n    elif pos == 2:\n        if b>c:\n            pos=3\n            steps+=c\n        else:\n            post=1\n            steps+=b\n    elif pos == 3:\n        if a>c:\n            pos=2\n            steps+=c\n        else:\n            pos=1\n            steps+=a\nprint(steps)  ", "src_uid": "6058529f0144c853e9e17ed7c661fc50"}
{"source_code": "import sys,math\n\nif __name__ == '__main__':\n\tvalue = int(raw_input())\n\twalk = 0\n\twhile walk <= 20:\n\t\tif '8' in str(value) and walk > 0:\n\t\t\tprint walk\n\t\t\tbreak\n\t\telse:\n\t\t\tvalue += 1\n\t\t\twalk += 1\n\t\n\t\n", "src_uid": "4e57740be015963c190e0bfe1ab74cb9"}
{"source_code": "from sys import *\nsetrecursionlimit(1000000)\n#d={}\ndef c(n):\n#    t=d.get(n,(0,0))\n#    if t!=(0,0): return t\n    if n<8: return n,n\n    t1=int(n**(1/3)+0.00000000001)\n    t2=t1-1\n    v1=c(n-t1*t1*t1)\n    v1=v1[0]+1,v1[1]+t1*t1*t1\n    v2=c(t1*t1*t1-1-t2*t2*t2)\n    v2=v2[0]+1,v2[1]+t2*t2*t2\n    if v2>v1: v1=v2\n#    d[n]=v1\n    return v1\n    \nprint(' '.join(map(str,c(int(input())))))", "src_uid": "385cf3c40c96f0879788b766eeb25139"}
{"source_code": "class Solver:\n    def __init__(self):\n        pass\n\n    def solve(self):\n        n, k = map(int, input().split())\n        s = input()\n        dp = [[[False for _ in range(n+1)] for _ in range(n+1)] for _ in range(n+1)]\n        dp[0][0][0] = True\n        for pos in range(n):\n            for streak in range(n+1):\n                for mx in range(n+1):\n                    if not dp[pos][streak][mx]:\n                        continue\n                    #print(pos, streak, mx)\n                    if s[pos] == 'N' or s[pos] == '?':\n                        dp[pos+1][streak+1][max(mx, streak+1)] = True\n                    if s[pos] == 'Y' or s[pos] == '?':\n                        dp[pos+1][0][mx] = True\n        for streak in range(n+1):\n            if dp[n][streak][k]:\n                print('YES')\n                return\n        print('NO')\n\n\nif __name__ == '__main__':\n    s = Solver()\n    s.solve()\n", "src_uid": "5bd578d3da5837c259b222336a194d12"}
{"source_code": "#507B\n\nfrom math import ceil\nr,x,y,x1,y1=map(int,raw_input().split())\ndis=(((x1-x)**2)+((y1-y)**2))**0.5\nprint int(ceil(dis/(2*r)))\n", "src_uid": "698da80c7d24252b57cca4e4f0ca7031"}
{"source_code": "\ndef mult_mod(a, b, m):\n    c = [[a[0][0] * b[0][0] + a[0][1] * b[1][0], a[0][0] * b[0][1] + a[0][1] * b[1][1]],\n         [a[1][0] * b[0][0] + a[1][1] * b[1][0], a[1][0] * b[0][1] + a[1][1] * b[1][1]]]\n    for i in range(2):\n        for j in range(2):\n            c[i][j] %= m\n    return c\n\ndef pow_mod(n, m):\n    p = [[1, 1],\n         [1, 0]]\n\n    a = [[1, 0],\n         [0, 1]]\n\n    while n:\n        if n % 2:\n            a = mult_mod(a, p, m)\n        p = mult_mod(p, p, m)\n        n /= 2\n    return a\n\ndef fib(n, m):\n    return pow_mod(n, m)[0]\n\ndef egcd(a, b):\n    if b == 0:\n        return 1, 0, a\n    x1, y1, c = egcd(b, a % b)\n    return y1, x1 - (a / b) * y1, c\n\ndef crt(a0, n0, a1, n1):\n    if min(n0, n1) < 0:\n        return 0, -1\n    x, y, g = egcd(n0, n1)\n    if (a0 - a1) % g:\n        return 0, -1\n    x *= (a1 - a0) / g\n    y *= (a1 - a0) / g\n    k = n1 * n0 / g\n    return (n0 * x + a0) % k, k\n\n\n# 2**13 ->   12288\n# 5**8  -> 1562500\n# 5**9  -> 7812500\n\n\ndef find(f, m, l):\n    resp = []\n    x0 = 0\n    x1 = 1\n    for i in range(l):\n        if x0 == f % m:\n            resp.append(i)\n        x0, x1 = x1, (x0 + x1) % m\n    return resp\n\nf = input()\na = find(f, 2**13, 12288)\nb = find(f, 5**8, 1562500)\n\nif len(a) == 0 or len(b) == 0:\n    print('-1')\nelse:\n    ans = 10 ** 30\n    for i in a:\n        for j in b:\n            a0, n0 = crt(i, 12288, j, 1562500)\n            if n0 != -1:\n                x1, x0 = fib(a0, 10 ** 13)\n                if x0 == f:\n                    ans = min(ans, a0)\n                else:\n                    a0 += n0\n                    fm = pow_mod(n0, 10 ** 13)\n                    x3 = (x1 * fm[0][0] + x0 * fm[1][0]) % 10 ** 13\n                    x2 = (x1 * fm[0][1] + x0 * fm[1][1]) % 10 ** 13\n                    while (x2,x3) != (x0, x1):\n                        if x2 == f:\n                            ans = min(ans, a0)\n                            break\n                        a0 += n0\n                        x3, x2 = (x3 * fm[0][0] + x2 * fm[1][0]) % 10 ** 13, (x3 * fm[0][1] + x2 * fm[1][1]) % 10 ** 13\n    if ans < 10 ** 30:\n        print(ans)\n    else:\n        print(-1)", "src_uid": "cbf786abfceeb8df29732c8a872f7f8a"}
{"source_code": "n = int(raw_input())\ns = raw_input()\nd = [[[-1] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]\ndef f(a, b, c):\n    if a < 0 or b < 0 or c < 0:\n        return 0\n    if (a, b, c) == (1, 0, 0):\n        return 1\n    if (a, b, c) == (0, 1, 0):\n        return 2\n    if (a, b, c) == (0, 0, 1):\n        return 4\n    if d[a][b][c] == -1:\n        res = 0\n        if a > 1:\n            res |= f(a - 1, b, c)\n        if b > 1:\n            res |= f(a, b - 1, c)\n        if c > 1:\n            res |= f(a, b, c - 1)\n        res |= f(a - 1, b - 1, c + 1) | f(a + 1, b - 1, c - 1) | f(a - 1, b + 1, c - 1)\n        d[a][b][c] = res\n    return d[a][b][c]\n\np = [s.count('B'), s.count('G'), s.count('R')]\nfor i in range(3):\n    if p[i] > 10:\n        p[i] = 3\nz = f(*p)\nRGB = 'BGR'\nprint ''.join([RGB[i:i+1] for i in range(3) if ((1 << i) & z)])\n", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f"}
{"source_code": "n,m,k=map(int,raw_input().split())\nif k>n+m-2:\n    print -1\nelse:\n    print max((n*(m/(k+1))),(m*(n/(k+1))),(n/max(1,k-m+2)),(m/max(1,k-n+2)))\n", "src_uid": "bb453bbe60769bcaea6a824c72120f73"}
{"source_code": "import math\na,b = list(map(int,input().split()))\nprint(math.factorial(min(a,b)))", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"}
{"source_code": "n,m,s=map(int,input().split())\nn-=1\nm-=1\nprint((n//s+1)*(n%s+1)*(m//s+1)*(m%s+1))#2020-07-25 11:13:31.354", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36"}
{"source_code": "m = int(raw_input())\n\n\ndef num_zeroes(n):\n    z = 0\n    d = 5\n    while n >= d:\n        z += n / d\n        d *= 5\n    return z\n\n\ndef get_elem(i):\n    return 5 * i\n\n\ndef inv_bin(get_elem, get_val, start, end, target):\n    while start <= end:\n        mid = (start + end) / 2\n        elem_mid = get_elem(mid)\n        val_mid = get_val(elem_mid)\n        if val_mid == target:\n            return elem_mid, mid\n        if val_mid > target:\n            end = mid - 1\n        else:\n            start = mid + 1\n    return -1, -1\n\nresult, _ = inv_bin(get_elem, num_zeroes, 0, m, m)\nif result == -1:\n    print 0\nelse:\n    print 5\n    print \" \".join(map(str, range(result, result + 5)))\n\n\n\n", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744"}
{"source_code": "# cf 177 A2 700\nn = int(input())\nA = []\nfor _ in range(n):\n    A.append(list(map(int, input().split())))\nsum_ = 0\nfor i in range(len(A)):\n    sum_ += A[i][i]      # main diag\n    sum_ += A[(n - 1) - i][i]  # sec diag\n    sum_ += A[(n - 1) // 2][i] # middle row\n    sum_ += A[i][(n - 1) // 2] # middle col\nsum_ -= 3 * A[(n - 1) // 2][(n - 1) // 2]\n\nprint(sum_)\n", "src_uid": "5ebfad36e56d30c58945c5800139b880"}
{"source_code": "n,a,b=map(int,input().split())\nl=list(map(int,input().split()))\nc=min(a,b)\nans=0\nfor i in range(len(l)):\n    if l[i]==0 and l[len(l)-i-1]==1:\n        ans=-1\n        break\n    elif l[i]==2:\n        if l[len(l)-i-1]==0:\n            ans+=a\n        elif l[len(l)-i-1]==1:\n            ans+=b\n        else :\n            ans+=c\nprint(ans)", "src_uid": "af07223819aeb5bd6ded4340c472b2b6"}
{"source_code": "a,b=map(int,input().split())\nc,d=map(int,input().split())\ne,f=map(int,input().split())\n\nx1,y1=(c+e)-a,(d+f)-b\nx2,y2=(e+a)-c,(b+f)-d\nx3,y3=(a+c)-e,(b+d)-f\nprint(3)\nprint(x1,y1)\nprint(x2,y2)\nprint(x3,y3)", "src_uid": "7725f9906a1b87bf4e866df03112f1e0"}
{"source_code": "def getPower(a, b):\n    if (b == 0):\n        return 1\n    if (b == 1):\n        return a\n    result = 1\n    while(b > 0):\n        if (b % 2 != 0):\n            result *= a\n            result = result%1000000007\n        a *= a\n        a = a%1000000007\n        b /=2\n    return result\n\nn = int(raw_input())\nk = getPower(2, n)\nx = ((k * (1 + k)) / 2)%1000000007\nprint x", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085"}
{"source_code": "n, k = map(int, input().split())\n\ndef solve(n, num):\n    ans = 0\n    keta_num = num.bit_length()\n    keta_n = n.bit_length()\n    keta_diff = keta_n - keta_num\n    if keta_diff < 0:\n        return ans\n    ans += (1 << keta_diff) - 1\n    if (n >> keta_diff) > num:\n        ans += 1 << keta_diff\n    elif (n >> keta_diff) == num:\n        ans += n & (((1 << keta_diff) - 1))\n        ans += 1\n    return ans\n\nok = 0\nng = n + 10\nwhile abs(ok - ng) > 1:\n    mid = (ok + ng) // 2\n    val = mid * 2 + 1\n    if solve(n, val) >= k:\n        ok = mid\n    else:\n        ng = mid\nans1 = ok*2 + 1\n\n\nok = 0\nng = n + 10\nwhile abs(ok - ng) > 1:\n    mid = (ok + ng) // 2\n    val = mid * 2\n    if solve(n, val) + solve(n, val + 1) >= k:\n        ok = mid\n    else:\n        ng = mid\nans2 = ok*2\n\nprint(max(ans1, ans2))", "src_uid": "783c4b3179c558369f94f4a16ac562d4"}
{"source_code": "def solve():\r\n    n, mod = map(int, input().split())\r\n    m = n*(n-1)//2\r\n    dp = [[0]*(n*(n-1)+1) for i in range(n+1)]\r\n    dp1 = [[0]*(n*(n-1)+1) for i in range(n+1)]\r\n    dp[1][m] = 1\r\n    for i in range(2, n+1):\r\n        for x in range(m-(i-1)*(i-2)//2, m+(i-1)*(i-2)//2+1):\r\n            for d in range(-i+1, i):\r\n                dp[i][x+d] = (dp[i][x+d]+dp[i-1][x]*(i-abs(d))) % mod\r\n    for i in range(2, n+1):\r\n        for x in range(m-(i-1)*(i-2)//2, m+(i-1)*(i-2)//2+1):\r\n            dp1[i][x] = dp1[i-1][x] * i % mod\r\n        for x in range(m-(i-1)*(i-2)//2, m+(i-1)*(i-2)//2+1):\r\n            for d in range(1, i):\r\n                dp1[i][x-d] = (dp1[i][x-d]+dp[i-1][x]*(i-d)) % mod\r\n\r\n    return sum(dp1[-1][m+1:]) % mod\r\n\r\nimport sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nprint(solve())\r\n", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a"}
{"source_code": "n = input()\n# t = [int(x) for x in input().split()]\n\nif(\"H\" in n or \"Q\" in n or \"9\" in n):\n  print(\"YES\")\nelse:\n  print(\"NO\")", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12"}
{"source_code": "n, a, b = map(int, input().split())\nla = list(map(int, input().split()))\nlb = list(map(int, input().split()))\nans = []\nfor i in range(1, n + 1):\n    if i in la:\n        print(1, end=' ')\n    else:\n        print(2, end=' ')\n", "src_uid": "a35a27754c9c095c6f1b2d4adccbfe93"}
{"source_code": "U=1\nD=-1\nx,y=map(int,input().split())\nk=A=B=0\nwhile 1:\n\ta,b=U,B;k+=1\n\tif (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break\n\tA=a;b=U;k+=1\n\tif (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break\n\tB=b;a=D;k+=1\n\tif (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break\n\tA=a;b=D;k+=1\n\tif (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break\n\tA,B=a,b\n\tU+=1;D-=1\nif k<1:k=1\nprint(k-1)", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382"}
{"source_code": "from copy import deepcopy\nimport itertools\nfrom bisect import bisect_left\nfrom bisect import bisect_right\nimport math\nfrom collections import deque\nfrom collections import Counter\n\n\ndef read():\n    return int(input())\n\n\ndef readmap():\n    return map(int, input().split())\n\n\ndef readlist():\n    return list(map(int, input().split()))\n\n\ndef is_valid(field, i, j):\n    for k in range(3):\n        for l in range(3):\n            if k == 1 and l == 1:\n                continue\n            if field[i+k][j+l] == \".\":\n                return False\n    return True\n\n\ndef fill_sgn(i, j):\n    for k in range(3):\n        for l in range(3):\n            if k == 1 and l == 1:\n                continue\n            sgn[i+k][j+l] = \"#\"\n\n\nn, m = readmap()\narr = []\nsgn = []\nfor _ in range(n):\n    arr.append(list(input()))\n    sgn.append([\".\"] * m)\n\nfor i in range(n-2):\n    for j in range(m-2):\n        if is_valid(arr, i, j):\n            fill_sgn(i, j)\n\nif arr == sgn:\n    print(\"yes\")\nelse:\n    print(\"no\")\n", "src_uid": "49e5eabe8d69b3d27a251cccc001ab25"}
{"source_code": "def solve(s):\n    if len(str(s)) == 1:\n        return s\n    ans1 = solve(s // 10)\n    ans2 = solve(s // 10 - 1)\n    return max(ans1 * (s % 10), ans2 * 9, 9)\n\n\nn = int(input())\n\nprint(solve(n))\n", "src_uid": "38690bd32e7d0b314f701f138ce19dfb"}
{"source_code": "n,k=map(int,input().split())\nif k%2==1:\n    print(1)\nelse:\n    mid=2**(n-1)\n    if k==mid:\n        print(n)\n    else:\n        if k<mid:\n            t=k\n        else:\n            t=2**(n-1)-k\n        p=0\n        while t%2==0:\n            p+=1 \n            t=t//2\n        print(p+1)\n    ", "src_uid": "0af400ea8e25b1a36adec4cc08912b71"}
{"source_code": "n, d = map(int, input().split())\na = list(map(int, input().split()))\nans = n - 1\na.sort()\nfor l in range(n):\n    for r in range(l, n):\n        if a[r] - a[l] <= d:\n            ans = min(ans, l - 1 + (n - r))\nprint(ans)", "src_uid": "6bcb324c072f796f4d50bafea5f624b2"}
{"source_code": "n = int(input())\nprint(\"0 0 {}\".format(n))", "src_uid": "db46a6b0380df047aa34ea6a8f0f93c1"}
{"source_code": "def power(number, pow):\n    if (pow == 0): return 1\n    if (pow%2 == 0): return power((number*number)%1000000007,(pow/2)%1000000007)\n    else: return (number%1000000007)*(power(number,pow-1))%1000000007\n\nn = int(raw_input())\nprint (power(3,3*n)-power(7,n))%1000000007", "src_uid": "eae87ec16c284f324d86b7e65fda093c"}
{"source_code": "input()\nr = []\nfor x in list(map(int, input().split()))[::-1]:\n    if not x in r:\n        r.append(x)\nprint(len(r))\nprint(*r[::-1])\n", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"}
{"source_code": "n=int(input())\na1,a2,a3=map(int,input().split())\nb1,b2,b3=map(int,input().split())\nminwin=n-(min(a1,b1+b3))-(min(a2,b1+b2))-(min(a3,b2+b3))\nmaxwin=min(a1,b2)+min(a3,b1)+min(a2,b3)\nprint(minwin,maxwin)", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402"}
{"source_code": "from sys import exit\n\ndef transpose(field):\n\tresult = [\"\" for i in xrange(10)]\n\n\tfor i in xrange(10):\n\t\tfor j in xrange(10):\n\t\t\tresult[j] += field[i][j]\n\n\treturn result\n\ndef skew_diagonally_NWSE(field):\n\tresult = []\n\n\tfor i in xrange(-10, 10):\n\t\tresult.append(\"\")\n\n\t\tfor j in xrange(20):\n\t\t\tx = j\n\t\t\ty = i + j\n\n\t\t\tif x >= 0 and x < 10 and y >= 0 and y < 10:\n\t\t\t\tresult[-1] += field[x][y]\n\n\treturn result\n\ndef skew_diagonally_SWNE(field):\n\tresult = []\n\n\tfor i in xrange(20):\n\t\tresult.append(\"\")\n\n\t\tfor j in xrange(-10, 10):\n\t\t\tx = j\n\t\t\ty = i - j\n\n\t\t\tif x >= 0 and x < 10 and y >= 0 and y < 10:\n\t\t\t\tresult[-1] += field[x][y]\n\n\treturn result\n\noriginal_field = []\n\nfor i in xrange(10):\n\toriginal_field.append(raw_input())\n\ntransposed_field = transpose(original_field)\n\nskewed_field_1 = skew_diagonally_NWSE(original_field)\n\nskewed_field_2 = skew_diagonally_SWNE(original_field)\n\nfor field in (original_field, transposed_field, skewed_field_1, skewed_field_2, ):\n\tfor row in field:\n\t\tif 'XXXX.' in row or 'XXX.X' in row or 'XX.XX' in row or 'X.XXX' in row or '.XXXX' in row:\n\t\t\tprint \"YES\"\n\t\t\texit(0)\n\nprint \"NO\"\n", "src_uid": "d5541028a2753c758322c440bdbf9ec6"}
{"source_code": "import sys\ninput = sys.stdin.readline\n\n\nn, a, x, b, y = map(int, input().split())\nwhile a != x and b != y:\n    a += 1\n    b -= 1\n    if a > n:\n        a = 1\n    if b < 1:\n        b = n\n    if a == b:\n        print('YES')\n        sys.exit()\nprint('NO')\n", "src_uid": "5b889751f82c9f32f223cdee0c0095e4"}
{"source_code": "from collections import defaultdict\nfrom collections import deque\n\n\ndef buildG(n):\n    adj = defaultdict(set)\n    for i in xrange(len(n)):\n        for j in xrange(i + 1, len(n)):\n            if abs(ord(n[i]) - ord(n[j])) != 1:\n                adj[n[i]].add(n[j])\n                adj[n[j]].add(n[i])\n    return adj\n\ndef ff(s):\n\n    n = list(set(s))\n\n    adj = buildG(n)\n    q = deque([n[0]])\n    res = []\n    visited = set()\n    while len(q) > 0:\n        nn = q.popleft()\n        if nn in visited:\n            continue\n        visited.add(nn)\n        res.append(nn)\n        for nnn in adj[nn]:\n            q.append(nnn)\n    if len(res) < len(n):\n        return \"No answer\"\n    CC = defaultdict(int)\n    for c in s:\n        CC[c] += 1\n    aa = []\n    for r in res:\n        aa.append(r * CC[r])\n\n    return \"\".join(aa)\n\n# print ff(\"abcd\")\n#\n#\n# T = input()\n# for t in xrange(T):\n#     s = raw_input()\n#     print ff(s)\n\nN = input()\narr = map(int, raw_input().split(\" \"))\n\n\ndef haha(A):\n    t = 0\n    for i in xrange(len(A) - 1):\n        f, s = A[i], A[i + 1]\n        # 1 - circle\n        # 2 - triangle\n        # 3 - square\n        if f == 2 and s == 3:\n            return \"Infinite\"\n        if s == 2 and f == 3:\n            return \"Infinite\"\n\n        if f == 1:\n            if s == 2:\n                if i - 1 >= 0 and A[i - 1] == 3:\n                    t += 2\n                else:\n                    t += 3\n            if s == 3:\n                t += 4\n        if f == 2:\n            if s == 1:\n                t += 3\n        if f == 3:\n            if s == 1:\n                t += 4\n    return t\n\nr = haha(arr)\nif type(r) == int:\n    print \"Finite\"\n    print r\nelse:\n    print r", "src_uid": "6c8f028f655cc77b05ed89a668273702"}
{"source_code": "n = int(input())\ns = input()\nprint( int(((s[::-1].replace('R', '0')).replace('B', '1')), base = 2))\n", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58"}
{"source_code": "#rock pair scissor\nf = input();\nm = input();\ns = input();\nif f=='rock' and m=='scissors' and s=='scissors':\n    print('F')\nelif m=='rock' and f=='scissors' and s=='scissors':\n    print('M')\nelif s=='rock' and f=='scissors' and m=='scissors':\n    print('S')\nelif f=='scissors' and m=='paper' and s=='paper':\n    print('F')\nelif m=='scissors' and f=='paper' and s=='paper':\n    print('M')\nelif s=='scissors' and f=='paper' and m=='paper':\n    print('S')\nelif f=='paper' and m=='rock' and s=='rock':\n    print('F')\nelif m=='paper' and f=='rock' and s=='rock':\n    print('M')\nelif s=='paper' and f=='rock' and m=='rock':\n    print('S') \nelse:\n    print('?')", "src_uid": "072c7d29a1b338609a72ab6b73988282"}
{"source_code": "def gcd(m,n):\n    if(n==0):\n        return m\n    return gcd(n,m%n)\n\nn=int(input())\nif(n%2==0):\n    t=int(n/2)\n    i=1\n    while(i<t):\n        if(gcd(t-i,t+i)==1):\n            print(t-i,t+i)\n            break\n        i+=1\nelse:\n    t=int(n/2)\n    i=1\n    j=0\n    while(t+i<n):\n        if(gcd(t-j,t+i)==1):\n            print(t+1-i,t+i)\n            break\n        i+=1\n        j+=1\n\n", "src_uid": "0af3515ed98d9d01ce00546333e98e77"}
{"source_code": "def main():\n    n1,b1 = map(int,input().split())\n    x = [int(i) for i in input().split()][::-1]\n    n2, b2 = map(int, input().split())\n    y = [int(i) for i in input().split()][::-1]\n    xan,yan = 0,0\n    for i , ii in enumerate(x):\n        xan += ii*b1**i\n    for i, ii in enumerate(y):\n        yan += ii*b2** i\n    if xan > yan:\n        print(\">\")\n    else:\n        print(\"=\" if yan == xan else \"<\")\nif __name__ == '__main__':\n    main()", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67"}
{"source_code": "x,y,z=map(int,raw_input().split())\nx1,y1,z1=map(int,raw_input().split())\na=map(int,raw_input().split())\nres=0\nif z>z1:\n    res+=a[3]\nif y>y1:\n    res+=a[1]\nif x>x1:\n    res+=a[5]\nif z<0:\n    res+=a[2]\nif y<0:\n    res+=a[0]\nif x<0:\n    res+=a[4]\nprint res\n", "src_uid": "c7889a8f64c57cf7be4df870f68f749e"}
{"source_code": "from sys import stdin,stdout\nfor _ in range(1):#int(stdin.readline())):\n    # n=int(stdin.readline())\n    moves,left=list(map(int,stdin.readline().split()))\n    # ATE=?\n    l=1;r=10**9+1\n    while l<=r:\n        mid=(l+r)>>1\n        fx=(mid*(mid+1))//2-left+mid\n        # print(l,r,mid)\n        if fx<=moves:l=mid+1\n        else:r=mid-1\n    print(moves-r)", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77"}
{"source_code": "from collections import deque\ndef readarray(foo): return [foo(x) for x in raw_input().split()]\n\n\nstairs = []\nto = []\ncolor = []\ntotalcolors = 0\ndeg = []\npriority = []\n\nextrastairs = []\nextrastair = None\n\n\ndef doit():\n\tusedstairs = set()\n\tvisited = set([0])\n\tstack = []\n\tres = []\n\tnextcolor = 1\n\n\ts = 0\n\tif extrastair is not None:\n\t\t(s, stair) = extrastair\n\t\tvisited.add(s)\n\t\tusedstairs.add(stair)\n\t\tnextcolor += 1\n\t\tres.append([0])\n\t\tres.append([stair, 0, s])\n\t\n\thasnextcolor = totalcolors > nextcolor\n\tlayer = [s]\n\tstack.append([s, -1, -1, 0])\n\n\twhile stack:\n\t\t(u, source, parent, start) = state = stack[-1]\n\n\t\tnexti = None\n\t\tnexts = None\n\t\tnextv = None\n\t\tfor i in xrange(start, len(to[u])):\n\t\t\ts = to[u][i]\n\t\t\tif s == source: continue\n\t\t\tif s in usedstairs: continue\n\t\t\t(v1, v2) = stairs[s]\n\t\t\tv = v1 if v2 == u else v2\n\t\t\tif not hasnextcolor and v in visited: continue\n\t\t\tnexti = i\n\t\t\tnexts = s\n\t\t\tnextv = v\n\t\t\tbreak\n\n\t\tif nexti is None:\n\t\t\tif parent != -1:\n\t\t\t\tlayer.append(parent)\n\t\t\tstack.pop()\n\t\t\tcontinue\n\n\t\tif nextv not in visited:\n\t\t\tvisited.add(nextv)\n\t\t\tlayer.append(nextv)\n\t\t\tstate[3] = nexti\n\t\t\tstack.append([nextv, nexts, u, 0])\n\t\t\tcontinue\n\t\n\t\tusedstairs.add(nexts)\n\t\tnextv = priority[nextcolor]\n\t\tnextcolor += 1\n\t\thasnextcolor = totalcolors > nextcolor\n\n\t\tres.append(layer)\n\t\tres.append([nexts, u, nextv])\n\t\tlayer = [nextv]\n\t\tvisited.add(nextv)\n\t\t\n\t\tstate[3] = nexti + 1\n\t\tstack.append([nextv, nexts, u, 0])\n\n\tres.append(layer)\n\treturn res if not hasnextcolor else None\n\n\ndef colorize(s, c):\n\tif color[s] != -1: return\n\tglobal totalcolors\n\ttotalcolors += 1\n\tcolor[s] = c\n\tdeg[c] = 1\n\tq = deque()\n\tq.append(s)\n\tsource = {s : -1}\n\twhile q:\n\t\tu = q.popleft()\n\t\tfor stair in to[u]:\n\t\t\tif extrastair is not None and extrastair[1] == stair: continue\n\t\t\t(v1, v2) = stairs[stair]\n\t\t\tv = v1 if v2 == u else v2\n\t\t\tif color[v] != -1:\n\t\t\t\tif v != source[u]:\n\t\t\t\t\textrastairs.append(stair)\n\t\t\t\tcontinue\n\t\t\tcolor[v] = c\n\t\t\tsource[v] = u\n\t\t\tdeg[c] += 1\n\t\t\tq.append(v)\n\n\ndef findextrastair():\n\tif extrastairs: return (stairs[extrastairs[0]][0], extrastairs[0])\n\tfor u in xrange(len(to)):\n\t\tif len(to[u]) < 2: continue\n\t\treturn (u, to[u][0])\n\treturn None\n\ndef run():\n\tglobal to, color, deg, priority, extrastair, totalcolors\n\tn, m = readarray(int)\n\tto = [[] for i in xrange(n)]\n\tcolor = [-1] * n\n\tdeg = [0] * n\n\tfor i in xrange(m):\n\t\tu, v = sorted(readarray(lambda x: int(x) - 1))\n\t\tstairs.append((u, v))\n\t\tto[u].append(i)\n\t\tto[v].append(i)\n\tfor i in xrange(n):\n\t\tcolorize(i, i)\n\n\tif deg[0] == 1 and n > 1:\n\t\textrastair = findextrastair()\n\t\tif extrastair is None:\n\t\t\tprint \"NO\"\n\t\t\treturn\n\t\tcolor = [-1] * n\n\t\tdeg = [0] * n\n\t\ttotalcolors = 0\n\t\tfor i in xrange(n):\n\t\t\tcolorize(i, i)\n\t\tdeg[color[extrastair[0]]] = 100500\n\t\t\n\t\n\tdeg[0] = 100500\n\tpriority = sorted(range(n), lambda x, y: deg[y] - deg[x])[:totalcolors]\n\tres = doit()\n\tif res is None:\n\t\tprint \"NO\"\n\t\treturn\n\n\tprint \"YES\"\n\tprint len(res) / 2\n\tfor i, line in enumerate(res):\n\t\tif i % 2 == 0:\n\t\t\tprint len(line),\n\t\tprint \" \".join(map(lambda x: str(x + 1), line))\n\nrun()\n", "src_uid": "35a3513c8fe730a64f30c5daec27df05"}
{"source_code": "mod, sx, sy, dx, dy, t = map(int, input().split())\nclass Matrix():\n    def __init__(self, n):\n        self.n = n\n        self.a = [[0] * n for _ in range(n)]\n\n    def __mul__(self, b):\n        res = Matrix(self.n)\n        for i in range(self.n):\n            for j in range(self.n):\n                for k in range(self.n):\n                    res.a[i][j] += self.a[i][k] * b.a[k][j] % mod\n                    res.a[i][j] %= mod\n        return res\n\n    def __pow__(self, e):\n        res = Matrix(self.n)\n        for i in range(self.n):\n            res.a[i][i] = 1\n        tmp = self\n        while e:\n            if e & 1:\n                res = res * tmp\n            e >>= 1\n            tmp = tmp * tmp\n        return res\nM = Matrix(6)\nM.a = [[2, 1, 1, 0, 1, 2],\n       [1, 2, 0, 1, 1, 2],\n       [1, 1, 1, 0, 1, 2],\n       [1, 1, 0, 1, 1, 2],\n       [0, 0, 0, 0, 1, 1],\n       [0, 0, 0, 0, 0, 1]]\nsx -= 1\nsy -= 1\nr = M ** t\nf = lambda i: (r.a[i][0] * sx + r.a[i][1] * sy + r.a[i][2] * dx + r.a[i][3] * dy + r.a[i][5]) % mod + 1\nprint(f(0), f(1))\n", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785"}
{"source_code": "import sys\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef SI(): return sys.stdin.readline()[:-1]\ndef bit(xx):return [format(x,\"b\") for x in xx]\npopcnt=lambda x:bin(x).count(\"1\")\ndef ask(m):\n    print(\"?\",m,flush=True)\n    return II()\nfor _ in range(II()):\n    n=II();l=0;r=n;pc=0;d=1;mx=0\n    while l+1<r:m=(l+r)//2;c=pc+m*d;mx=max(mx,c);l=m;pc=c;d*=-1\n    pc=n-mx;ask(pc);l=0;r=n;d=1\n    while l+1<r:\n        m=(l+r)//2;c=pc+m*d\n        if ask(c):r=m\n        else:l=m\n        pc=c;d*=-1\n    print(\"=\",r,flush=True)", "src_uid": "5a374c06b44a843233d9cf64a38c7e55"}
{"source_code": "class Solution:\n    def resolve(self, p, k):\n        re = []\n\n        while p < 0 or p >= k:\n            p, rem = p // -k, p % -k\n            if rem < 0:\n                rem += k\n                p += 1\n            re.append(rem)\n\n        re.append(p)\n\n        return re\n\n\nif __name__ == '__main__':\n    s = Solution()\n\n    p, k = map(int, input().split())\n\n    re = s.resolve(p, k)\n    if len(re) == 0:\n        print(\"-1\")\n    else:\n        print(len(re))\n        for i in re:\n            print(i, end=' ')\n        print()\n\n\n", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5"}
{"source_code": "m = 301000\nns = [0] * m\nes = [0] * m\nc = [0] * m\nb = [0] * m\nt = [0] * m\nP = 0\n\ndef add(b, k):\n    k = t[k]\n    while k:\n        e = es[k]\n        if b[-1] > e: b[-1] = e\n        b[e] += 1\n        k = ns[k]\n\ndef delete(b):\n   for i in range(b[m - 1], m + 1):\n       if b[i]:\n           b[i] -= 1\n           b[-1] = i\n           return i\n\ndef calc(k):\n    global b\n    q = 0\n    b = [0] * m\n    b[-1] = m\n    take = rank - dn\n    if take < 0: take = 0\n    add(b, k)\n    add(b, k - 1)\n    for i in range(1, take + 1): q += delete(b)\n    for i in range(k - 1): add(b, i)\n    for i in range(k + 1, P + 1): add(b, i)\n    for i in range(1, k - take + 1): q += delete(b)\n    return q\n\nn, k = map(int, input().split())\nrank = n - k + 1\n\nif rank == 0:\n    print('0')\n    exit(0)\n\nfor i in range(1, n + 1):\n    p, e = map(int, input().split())\n    if p > P: P = p\n    c[p] += 1\n    es[i], ns[i] = e, t[p]\n    t[p] = i\n\ndn = 0\nfor i in range(1, n + 1):\n    if i > 1: dn += c[i - 2]\n    if c[i] + c[i - 1] + dn >= rank and rank <= i + dn:\n        u = calc(i)\n        if i < n:\n            dn += c[i - 1]\n            v = calc(i + 1)\n            if u > v: u = v\n        if i < n - 1:\n            dn += c[i]\n            v = calc(i + 2)\n            if u > v: u = v\n        print(u)\n        exit(0)\n        \nprint('-1')\n", "src_uid": "19a098cef100fc3652c59abf7c373814"}
{"source_code": "a, b, c, n = map(int, input().split())\ntotal = a + b - c\nif total >= n or c > a or c > b:\n    print('-1')\nelse:\n    print(n - total)", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce"}
{"source_code": "s=map(int, raw_input().split())\nl=s.pop()\nans=((l+1)*(l+2)*(l+3))/6\nfor i in range(l+1):\n    for j in s:\n        x = min(j+j-sum(s)+i, l-i)\n        if x>=0: ans -= ((x+1)*(x+2))/2\nprint ans\n\n", "src_uid": "185ff90a8b0ae0e2b75605f772589410"}
{"source_code": "def main():\n    n,m = [int(x) for x in input().split()]\n    a = [int(x) for x in input().split()]\n    count = [0]*101\n    for i in a:\n        count[i] += 1\n    b = [(count[i],i) for i in range(1,101) if count[i]]\n    b.sort(reverse=True)\n    b = b[:n]\n    flag = 0\n    for i in b:\n        flag += i[0]\n    if m < n or flag < n:\n        print(0)\n    else:\n        for day in range(1,102):\n            people = 0\n            for food,foodtype in b:\n                people += food//day\n            if people < n:\n                break\n        print(day-1)\n\n\nif __name__ == '__main__':\n    main()", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"}
{"source_code": "import re\ninput()\nprint(sum(len(f)-2 for f in re.findall('x{3,}',input())))", "src_uid": "8de14db41d0acee116bd5d8079cb2b02"}
{"source_code": "#!/usr/bin/python3\n\n# BEGIN template\nimport sys\nimport re\nimport pprint\n\ndef dbg(x,y=''):\n  if len(y) > 0: y += ' = '\n  sys.stderr.write('\\n>>> '+y+pprint.pformat(x)+'\\n')\n  sys.stderr.flush()\n\noo = 0x3f3f3f3f3f3f3f3f\n# END template\n\ndef minn(x,y):\n  if x[0] < y[0]: return x\n  if x[0] > y[0]: return y\n  if x[1] < y[1]: return x\n  if x[1] > y[1]: return y\n  return x\n\ndef main():\n  n = int(input())\n  s = input()\n  m = len(s)\n  s = '0'+s\n  power = [1]\n  for i in range(1,61):\n    power.append(power[i-1]*n)\n  dp = [(int(1e70),int(1e70))]*65\n  dp[m+1] = (0,0)\n  for i in range(m,0,-1):\n    if s[i] == '0':\n      tmp = dp[i+1]\n      dp[i] = (1+tmp[0],tmp[1])\n      continue\n    for j in range(i,min(m+1,i+9)):\n      d = int(s[i:j+1])\n      if d >= n: break\n      tmp = dp[j+1]\n      dp[i] = minn(dp[i],(1+tmp[0],d*power[tmp[0]]+tmp[1]))\n  print(dp[1][1])\n\nmain()\n", "src_uid": "be66399c558c96566a6bb0a63d2503e5"}
{"source_code": "c, v0, v1, a, l = map(int, input().split())\nans = 0\ncur = 0\nv = v0\nwhile cur < c:\n  if ans > 0:\n    cur -= l\n  cur += v\n  v = min(v + a, v1)\n  ans += 1\nprint(ans)", "src_uid": "b743110117ce13e2090367fd038d3b50"}
{"source_code": "r=raw_input\ns=[r(),r(),r()]\nm=[0,1,2]\nprint \"YNEOS\"[any([ s[2-i][2-j]!=s[i][j] for i in m for j in m ])::2]", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"}
{"source_code": "def find(i, A, n, storage):\n\tif i>n-1:\n\t\treturn 0\n\tif storage[i] != -1:\n\t\treturn storage[i]\n\t\n\tif i == n-1:\n\t\tstorage[i] = 1\n\telif (A[i] == \"U\" and A[i + 1] == \"R\") or (A[i] == \"R\" and A[i + 1] == \"U\"):\n\t\tstorage[i] = min(1 + find(i+2, A, n, storage), 1 + find(i+1, A, n, storage))\n\telse:\n\t\tstorage[i] = 1 + find(i+1, A, n, storage)\n\treturn storage[i]\n\nn = int(raw_input().strip())\nstring = raw_input().strip()\nstorage = [-1]*n\nprint(find(0, string, n, storage))\n", "src_uid": "986ae418ce82435badadb0bd5588f45b"}
{"source_code": "a = list(map(int,input().split()))\n\nweeks = min (a[0]//3, a[1]//2, a[2]//2)\n\na[0] -= weeks*3\na[1] -= weeks*2\na[2] -= weeks*2\nextra = 0\nfood = [0,1,2,0,2,1,0]\nfor i in range(7):\n\trest = a[::]\n\textdays = 0\n\tday = i\n\twhile rest[ food[day] ] > 0:\n\t\textdays +=1\n\t\trest[food[day]] -= 1\n\t\tday = (day+1)%7\n\n\textra = max(extra,extdays)\n\n\nprint(weeks*7 + extra)\n", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb"}
{"source_code": "r, h = map(int, raw_input().split())\np = h / r\nq = h % r\nif 2 * q > (3. ** 0.5) * r: print 2 * p + 3\nelif 2 * q < r: print 2 * p + 1\nelse: print 2 * p + 2", "src_uid": "ae883bf16842c181ea4bd123dee12ef9"}
{"source_code": "n,l,r,x=map(int,input().split())\nc=input().split()\nfor i in range(n):\n    c[i]=int(c[i])\nans=0    \nfor i in range(1,2**n):\n    s=bin(i)\n    s=s[2:]\n    s=\"0\"*(n-len(s))+s\n    if(s.count(\"1\")>=2):\n        total=0\n        maxi=0\n        mini=10**6+1\n        for j in range(n):\n            if(s[j]==\"1\"):\n                total+=c[j]\n                maxi=max(maxi,c[j])\n                mini=min(mini,c[j])\n        if(l<=total<=r and maxi-mini>=x):\n            ans+=1\nprint(ans)            ", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d"}
{"source_code": "n=input()\nl=list(n)\nwhile(l.count(' ')!=0):\n    l.remove(' ')\nn=len(l)\nj=l[n-2]\nif j=='a' or j=='e' or j=='i' or j=='o' or j=='u' or j=='y' or j=='A' or j=='E' or j=='I' or j=='O' or j=='U' or j=='Y':\n    print('YES')\nelse:\n    print('NO')\n#print(l,n)", "src_uid": "dea7eb04e086a4c1b3924eff255b9648"}
{"source_code": "n = input()\ns = raw_input()\nc = s.count('1')\nif c*2 == n:\n\tprint 2\n\tprint s[0], s[1:]\nelse:\n\tprint 1\n\tprint s", "src_uid": "4ebed264d40a449602a26ceef2e849d1"}
{"source_code": "n=input()\nk=input()\nA=input()\nB=input()\nans=0\nx=n\nwhile x!=1:\n\tif k!=1:\n\t\tif x%k == 0:\n\t\t\tif A*(x - x/k) > B:\n\t\t\t\tx/=k\n\t\t\t\tans+=B\n\t\t\telse:\n\t\t\t\tans+=A*(x - x/k)\n\t\t\t\tx=x/k\n\t\telse:\n\t\t\tif x < k:\n\t\t\t\tans+=A*(x-1)\n\t\t\t\tx=1\n\t\t\telse:\n\t\t\t\tans+=A*(x%k)\n\t\t\t\tx=x-(x%k)\n\telse:\n\t\tans=A*(x-1) \n\t\tx=1\n\t\t# print ans\nprint ans", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10"}
{"source_code": "n = int(input())\na=[]\nfor i in range (n):\n    a.append(int(input()))\n\ndef ideal(a):\n    a.sort()\n    mean = sum(a)/4\n    median = (a[1]+a[2] )/ 2\n    r = max(a)-min(a) \n        \n    if( mean == median  == r ):\n        print(\"YES\") \n    else:\n        print(\"NO\")\n\nif( len(a) == 4 ):\n    ideal(a)\n\nelif(len(a) == 0 ):\n    print(\"YES\")\n    print(1)\n    print(1)\n    print(3)\n    print(3)\n\nelif(len(a)==1) : \n    print(\"YES\")\n    print(2*a[0])\n    print(2*a[0])\n    print(3*a[0])\n\nelif(len(a)==2):\n     if((4*min(a) - max(a) )>0):\n        print(\"YES\")\n        print(4*min(a) - max(a))\n        print(3*min(a))\n     else:\n         print(\"NO\")\n\n\nelif(len(a) == 3 ):\n    if( sum(a)-min(a) == 4*min(a)):\n        print(\"YES\")\n        print(3 * min(a) ) \n    elif( max(a) ==  3*min(a)):\n        print(\"YES\")\n        print(8*min(a) -  sum(a) )\n    elif( 3*sum(a) == 7*max(a) ) :\n        print(\"YES\")\n        print( max(a) // 3 )\n    else:\n        print(\"NO\")\n     \n    \n    \n    \n    \n    \n    ", "src_uid": "230e613abf0f6a768829cbc1f1a09219"}
{"source_code": "l = list(input().split())\nm = int(l[0])\nn = int(l[1])\nboard = []\nl1 =[]\nif m>=1 and m <=n and n<=16:\n    for i in range(n):\n        for j in range(m):\n            l1.append(0)\n        board.append(l1)\n        l1 = []\n\n    sum = 0\n    k = 0\n    for i in range(len(board)):\n        sum+= (len(board[i])//2)\n        k = 0\n        for j in range(0,(len(board[i])//2)):\n            board[i][k] = 1\n            board[i][k+1] = 1\n            k+=2\n\n    for i in range(0,len(board),2):\n        if i == len(board)-1:\n            break\n        elif board[i][len(board[i])-1] == 0 and board[i+1][len(board[i])-1] == 0:\n            sum+=1\n\n\nprint(sum)\n#print(board)\n", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"}
{"source_code": "def solve(N, M):\n    ans = 0\n    while M > 1:\n        ans += N // M\n        N, M = M, N % M\n    if M == 0: return 1000000\n    return N - 1 + ans\n\nN = int(input())\nans = 1000000\nfor M in range(1, N + 1):\n    ans = min([ans, solve(N, M)])\nprint(ans)", "src_uid": "75739f77378b21c331b46b1427226fa1"}
{"source_code": "import math\nM, A, B = map(int, input().split())\nbound = [10**9 + 7]*(A + B)\nl, r = 0, 0\nwhile True:\n    bound[l] = r\n    if l >= B:\n        l -= B\n    else:\n        l += A\n    r = max(r, l)\n    if l == 0:\n        break\n\nans = 0\nfor i in range(0, A + B):\n    if bound[i] <= M:\n        ans += M - bound[i] + 1\n\nrem = M - (A + B) + 1\nif M >= (A + B):\n    g = math.gcd(A, B)\n    up = (rem // g) * g\n    lo = rem - up\n    cnt = up // g + 1\n    ans += (lo + rem) * cnt // 2\nprint(ans)\n", "src_uid": "d6290b69eddfcf5f131cc9e612ccab76"}
{"source_code": "import math  \ndef primeFactors(n,dict1): \n    while n % 2 == 0:\n        try:\n            dict1[2]+=1\n        except:\n            KeyError\n            dict1[2]=1 \n        n = n//2\n\n    for i in range(3,int(math.sqrt(n))+1,2): \n        while n % i== 0: \n            try:\n                dict1[i]+=1\n            except:\n                KeyError\n                dict1[i]=1 \n            n = n //i\n    if(n>2):\n        dict1[n]=1 \n\nn,b=map(int,input().split())\ndict1={}\nprimeFactors(b,dict1)\n#print(dict1)\ndict2={}\nfor i in dict1.keys():\n    j=i\n    while(j<=n):\n        count=n//j\n        try:\n            dict2[i]+=count\n        except:\n            KeyError\n            dict2[i]=count\n        j=j*i\n#print(dict2)\nminval=10**18\nfor i in dict1.keys():\n    try:\n        minval=min(minval,dict2[i]//dict1[i])\n    except:\n        KeyError\n        minval=0\nif(minval==10**18):\n    minval=0\nprint(minval)\n", "src_uid": "491748694c1a53771be69c212a5e0e25"}
{"source_code": "N = int(raw_input())\n\nif N >= -128 and N <= 127:\n\tprint \"byte\"\nelif N >= -32768 and N <= 32767:\n\tprint \"short\"\nelif N >= -2147483648 and N <= 2147483647:\n\tprint \"int\"\nelif N >= -9223372036854775808 and N <= 9223372036854775807:\n\tprint \"long\"\nelse:\n\tprint \"BigInteger\"", "src_uid": "33041f1832fa7f641e37c4c638ab08a1"}
{"source_code": "def sum_dig(n):\n    return sum(map(int, str(n)))\nn = int(input())\na = 9\nwhile a < n:\n    a = 10*a + 9\na //= 10\nprint(sum_dig(a) + sum_dig(n-a))\n", "src_uid": "5c61b4a4728070b9de49d72831cd2329"}
{"source_code": "n=int(input())\na=n//3\nb=n%3\nif b==2:\n    a=a+1\np=a//12\nq=a%12\nprint(p,q)", "src_uid": "5d4f38ffd1849862623325fdbe06cd00"}
{"source_code": "def berlanese():\n    if s[-1] not in vog and s[-1] != 'n':\n        return \"NO\"\n    for i in range(len(s)-1):\n        if s[i] != 'n':\n            if s[i] not in vog and s[i+1] not in vog:\n                return \"NO\"\n    \n    return \"YES\"\n\ns = list(raw_input())\nvog = ['a', 'e', 'i', 'o', 'u']\n\nprint berlanese()", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4"}
{"source_code": "w,m,k=map(int,raw_input().split())\nt=m;\nc=0;\nwhile(t):\n    c=c+1\n    t=t//10;\np=10**c-m;\nif(p*c*k==w):\n    print(p)\nelif(p*c*k>w):\n    print(w//(c*k))\nelse:\n    s=p;\n    w=w-p*c*k;\n    for i in range(c+1,18):\n        x=9*(10**(i-1));\n        q=x*(i*k)\n        if(q<w):\n            w=w-q;\n            s=s+x;\n        else:\n            s=s+w//(i*k)\n            print(s)\n            exit(0)", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea"}
{"source_code": "a,b,c=map(int,input().split())\nprint(['First','Second'][min(a,b)<2*c])\n", "src_uid": "90b9ef939a13cf29715bc5bce26c9896"}
{"source_code": "\ndef f(x):\n  return any(i * 3 <= x and (x - i * 3) % 7 == 0 for i in range(x))\nprint \"\\n\".join([f(int(raw_input())) * \"YES\" or \"NO\" for __ in xrange(int(raw_input()))])", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"}
{"source_code": "#!/usr/bin/env python3\n\nimport re\n\ndef main():\n    input()\n    p = re.compile(input())\n\n    pokemons = [\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"]\n    pokemons = sorted(pokemons, key=len)\n\n    for x in pokemons:\n        if p.match(x):\n            print(x)\n            break\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"}
{"source_code": "rr=raw_input\nrrI = lambda: int(rr())\nrrM = lambda: map(int,rr().split())\ndebug=0\nif debug:\n    fi = open('t.txt','r')\n    rr=lambda: fi.readline().replace('\\n','')\n\ndef good_mask(x):\n    if x == 0: return False\n    return (x+1) & x == 0\n\nN = rrI()\nS = rr()\n#N = 75\n#from time import time\n#S  = '100000111111101000100001011100010111110011111011100011001111101111100011110'\n#tt = time()\n#print tt\n\nlenbin = [ len(bin(n)) - 2 for n in xrange(32) ]\n\ndef solve():\n    MOD = 10**9 + 7\n    number = [ [0]*(N+1) for _ in xrange(N) ]\n    for i in xrange(N):\n        for j in xrange(i+1, N+1):\n            number[i][j] = min(22, int(S[i:j],2))\n    #UPPER = 22\n    UPPER = 22\n    memo = [ {} for _ in xrange(N+1)]\n    def dp(i, mask, sum_to_make = 0, cur_max = 0):\n        #Having made a cut already before position i,\n        #and having a set of mask taken\n        #how many ways?\n        if i == N:\n            return 1 if sum_to_make == 0 != mask else 0\n        if mask in memo[i]: return memo[i][mask]\n        ans = 1 if sum_to_make == 0 != mask else 0 #good_mask(mask) else 0\n        for j in xrange(i+1, N+1):\n            num = number[i][j]\n            if num == 0: continue\n            if num >= UPPER: break\n            if sum_to_make > N-j+5: break\n            if (mask >> (num-1))&1:\n                ans += dp(j, mask, sum_to_make, cur_max)\n            elif num <= cur_max:\n                ans += dp(j, mask|(1<<(num-1)), sum_to_make - lenbin[num], cur_max)\n            else:\n                ans += dp(j, mask|(1<<(num-1)), sum_to_make + sum(lenbin[x] for x in xrange(cur_max + 1, num)), num)\n                    \n            if ans >= MOD:\n                ans %= MOD\n        memo[i][mask] = ans\n        return ans\n    fans = i = 0\n    while i < N:\n        fans += dp(i, 0)\n        fans %= MOD\n        i += 1\n    \n    print fans\n#print time()-tt\n\nif __name__ == \"__main__\": solve()\n\n\"\"\"\ndef good_mask(x):\n    if x == 0: return False\n    return (x+1) & x == 0\n\nN = rrI()\nS = rr()\n##print '.'\n#N = 75\n#import random\n#S = \"\".join(str(random.randint(0,1)) for _ in xrange(N))\nMOD = 10**9 + 7\nUPPER = 22\n\nmemoslide = {N : 0, N-1:0}\ndef slide(j):\n    if j in memoslide:\n        return memoslide[j]\n    if S[j] == '1':\n        memoslide[j] = 0\n        return 0\n    else:\n        k = j\n        while k < len(S) and S[k] == '0':\n            k += 1\n        memoslide[j] = k - j\n        return k - j\n    \nmemo = {}\ndef dp(i, mask):\n    #Having made a cut already before position i,\n    #and having a set of mask taken\n    #how many ways?\n    if i == N:\n        return 1 if good_mask(mask) else 0\n    if (i,mask) in memo:\n        return memo[i,mask]\n    ans = 1 if good_mask(mask) else 0\n    for j in xrange(i+1, N+1):\n        num = int(S[i:j], 2)\n        if num == 0: continue\n        if num >= UPPER: break\n        if num > 8:\n            #prune\n            newmask = mask\n            ii = excess = 0\n            while newmask:\n                if newmask%2 == 0:\n                    excess += len(bin(ii)) - 2\n                ii += 1\n                newmask /= 2\n            if excess > N-j+1:\n                break\n        k = slide(j)\n        newmask = mask | (1<<(num-1))\n        bns = dp(j + k, newmask)\n        for kk in xrange(k):\n            memo[(j + kk, newmask)] = bns\n        ans += (1+k) * bns\n\n        if ans >= MOD:\n            ans %= MOD\n    memo[i, mask] = ans\n    return ans\n\nfans = 0\nfor i in xrange(N):\n    fans += dp(i, 0)\n    if fans >= MOD:\n        fans %= MOD\nprint fans\n\"\"\"\n", "src_uid": "61f88159762cbc7c51c36e7b56ecde48"}
{"source_code": "f=lambda:map(int,input().split())\nn,a=f()\nt=[0]+list(f())\nans=t[a]\nfor i in range(1,n):\n if a-i>0 and a+i<=n:\n  if t[a-i]==t[a+i]: ans+=t[a-i]+t[a+i]\n elif a-i>0: ans+=t[a-i]\n elif a+i<=n: ans+=t[a+i]\nprint(ans)", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"}
{"source_code": "n,l=map(int, input().split())\na=list(map(int, input().split()))\nb=list(map(int, input().split()))\nb1=False\nb2=False\ni=-1\nwhile i<l-1 and b1==False:\n    i+=1\n    for j in range(len(b)):\n        b[j]+=1\n        if b[j]>=l: b[j]-=l\n    b.sort()\n    b2 = False\n    for j in range(n):\n        if b[j]!=a[j]: b2=True\n    if b2==False:\n        b1=True\nif b1==False: print(\"NO\")\nelse: print(\"YES\")", "src_uid": "3d931684ca11fe6141c6461e85d91d63"}
{"source_code": "'''\nusage:\n    python prob1.py inputfile\n'''\n\n\nimport sys\nimport os\n\ndef main(argv=None):\n    i=0\n    nSquares=int(raw_input())\n    line=raw_input()\n    line=line.strip()\n    flag=0\n    length=0\n    ans=[]\n    for i in range(0,nSquares):\n        if flag==0 and line[i]==\"B\":\n            flag=1\n            length=1\n        elif line[i]==\"B\":\n            length=length+1\n        else:\n            flag=0\n            if length>0: ans.append(length)\n            length=0\n\n    if flag==1: ans.append(length)\n\n    print len(ans)\n    out=\"\"\n    for i in range(0,len(ans)):\n        out=out+str(ans[i])+\" \"\n    print out\n\n    return 0\n\nif __name__ == \"__main__\":\n    sys.exit(main())", "src_uid": "e4b3a2707ba080b93a152f4e6e983973"}
{"source_code": "import math\n\ndef getC(n, k):\n    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)\n\nn = int(input())\nprint(getC(n, 5) * math.factorial(n) // math.factorial(n - 5))\n", "src_uid": "92db14325cd8aee06b502c12d2e3dd81"}
{"source_code": "import re\nresult = re.match('((ftp)|(http))([a-z]+)ru([a-z]*)', raw_input())\nurl = result.group(1) + '://' + result.group(4) + '.ru'\nif result.group(5) != \"\": url = url + '/' + result.group(5)\nprint url", "src_uid": "4c999b7854a8a08960b6501a90b3bba3"}
{"source_code": "# submit\ndef dist_from_0(x, y, n):\n    if x == 0:\n        return y\n    else:\n        if y == 0:\n            return 4 * n - x\n        else:\n            if x == n:\n                return 3 * n - y\n            else:\n                return n + x\n\n\ndef main():\n    n, x1, y1, x2, y2 = [int(i) for i in raw_input().split()]\n    d1 = dist_from_0(x1, y1, n)\n    d2 = dist_from_0(x2, y2, n)\n    d = abs(d2 - d1)\n    print min(d, 4 * n - d)\n\nif __name__ == '__main__':\n    main()", "src_uid": "685fe16c217b5b71eafdb4198822250e"}
{"source_code": "A=[input() for i in range(5)]\nT=1.0*A[-1]/A[0]\nX=A[2]*A[0]\nif X>=A[-1] or A[1]<=A[0]:\n    print 0\n    exit()\nt=A[2]\nc=0\nwhile t<T:\n    t+=1.0*X/(A[1]-A[0])\n    if t<T:\n        c+=1\n    else:\n        print c\n        exit()\n    t+=1.0*X/(A[1]-A[0])\n    t+=A[-2]\n    X=t*A[0]\nprint c\n", "src_uid": "c9c03666278acec35f0e273691fe0fff"}
{"source_code": "n = int(raw_input())\ns = raw_input()\nlisto = s.split()\nlisto = map(int, listo)\nif listo[-1] == 15:\n    print 'DOWN'\nelif listo[-1] == 0:\n    print 'UP'\nelse:\n    if n <= 1:\n        print -1\n    elif listo[-1] > listo[-2]:\n        print 'UP'\n    else:\n        print 'DOWN'\n", "src_uid": "8330d9fea8d50a79741507b878da0a75"}
{"source_code": "n=input()\nprint n/2520", "src_uid": "8551308e5ff435e0fc507b89a912408a"}
{"source_code": "d = [list(str(i)) for i in range(1000) if i % 8 == 0]\ns = list(raw_input())\n\nres = 'NO'\n#print ['3', '4', '4'] in d\n\nfor i in range(len(d)):\n    c = 0\n    for j in s:\n        if d[i][c] == j:\n            c += 1\n            if c == len(d[i]):\n                res = ''.join(d[i])\n                break\n    if c == len(d[i]):\n        print \"YES\"\n        break\nprint res", "src_uid": "0a2a5927d24c70aca24fc17aa686499e"}
{"source_code": "n = int(input())\nw = 0\n\nfor i in range(4):\n    l = list(map(int,input().split()))\n    k = i+1\n    if l[0]+l[2] <= n:\n        w = 1\n        print(k,l[0],n-l[0])\n        break\n    elif l[0]+l[3] <= n:\n        w = 1\n        print(k,l[0],n-l[0])\n        break\n    elif l[1]+l[2] <= n:\n        w = 1\n        print(k,l[1],n-l[1])\n        break\n    elif l[1]+l[3] <= n:\n        w = 1\n        print(k,l[1],n-l[1])\n        break\n\nfor j in range(k,4):\n    list(map(int,input().split()))\n\nif not w:\n    print(-1)", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"}
{"source_code": "from fractions import *\nn,m,z=map(int,raw_input().split())\nprint (z*gcd(n,m))/(n*m)", "src_uid": "e7ad55ce26fc8610639323af1de36c2d"}
{"source_code": "from sys import stdin\nl=[]\nfor i in range(4):\n    s=stdin.readline().rstrip()\n    l.append(s)\nans=0\nfor i in range(3):\n    for j in range(3):\n        c=0\n        if l[i][j]==\"#\":\n            c+=1\n        if l[i+1][j]==\"#\":\n            c+=1\n        if l[i][j+1]==\"#\":\n            c+=1\n        if l[i+1][j+1]==\"#\":\n            c+=1\n        if c!=2:\n            ans=1\nprint(\"YES\" if ans==1 else \"NO\")", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"}
{"source_code": "C=lambda s:s.count('+')-s.count('-')\na=raw_input()\nb=raw_input()\nn=0\nd=0\nfor i in range(2**b.count('?')):\n    B=b\n    for j in range(b.count('?')):\n        B=B.replace('?',\"+\" if i & 2**j else '-',1)\n    d+=1\n    n+=C(a) == C(B)\nprint n*1./d", "src_uid": "f7f68a15cfd33f641132fac265bc5299"}
{"source_code": "import collections\nc = collections.Counter()\nn = int(input())\nnums = []\nfor _ in range(n):\n    c[int(input().strip())]+=1\nif len(c)!=2:\n    print('NO')\nelse:\n    a, b = [c[d] for d in c]\n    if a==b:\n        print('YES')\n        for d in c:\n            print(d, end=' ')\n    else:\n        print('NO')\n    \n", "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"}
{"source_code": "q=int(input())\nfor u in range(q):\n    a,b,m=map(int,input().split())\n    ranges=[(a,a)]\n    bigsum=a\n    smlsum=a\n    while ranges[-1][1]<b:\n        ranges.append((smlsum+1,bigsum+m))\n        smlsum=2*smlsum+1\n        bigsum=2*bigsum+m\n    if b<ranges[-1][0]:\n        print(-1)\n    else:\n        seq=[a]\n        leng=len(ranges)\n        power=2**(leng-3)\n        curr=(a+1)*(2**(leng-2))\n        sumi=a\n        for i in range(leng-2):\n            seq.append(sumi+max(min((b-curr)//power+1,m),1))\n            power//=2\n            sumi+=seq[-1]\n            curr=(sumi+1)*(2**(leng-i-3))\n        if b!=seq[-1]:\n            seq.append(b)\n        out=[leng]+seq\n        out=[str(guy) for guy in out]\n        print(\" \".join(out))", "src_uid": "c9d646762e2e78064bc0670ec7c173c6"}
{"source_code": "n,a,b,c = map(int,input().split())\nl = [a,b,c]\nl.sort()\nx = 0\nfor i in range(int(n / l[1]+1)):\n    if (n - i*l[1]) % l[0] == 0:\n        x = max(i + (n - i*l[1]) / l[0],x)\n    else:\n        for j in range(int(n / l[0] + 1)):\n            if (n - i*l[1] - j*l[2]) % l[0] == 0:\n                x = max(i + j + (n - i*l[1] - j*l[2]) / l[0],x)\n                break\nprint(int(x))", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"}
{"source_code": "n, m = map(int, input().split())\nx, y = divmod(n, m)\n\nprint(*[x+1]*y+[x]*(m-y))", "src_uid": "0b2c1650979a9931e00ffe32a70e3c23"}
{"source_code": "values = raw_input().split()\nx = int(values[0])\ny = int(values[1])\n\nx1 = 0\ny1 = (abs(x) + abs(y))\nx2 = (abs(x) + abs(y))\ny2 = 0\n\nif x < 0:\n    x1 = -x2\n    x2 = 0\n    \n    y2 = y1\n    y1 = 0\n\n\nif y < 0:\n    y1 *= -1\n    y2 *= -1\n\n\n    \nprint str(x1) + ' ' + str(y1) + ' ' +  str(x2) + ' ' +  str(y2)", "src_uid": "e2f15a9d9593eec2e19be3140a847712"}
{"source_code": "a,b=map(int,input().split())\nif b%a==0:\n    print(b//a)\nelse:\n    print(b//a+1)\n", "src_uid": "04c067326ec897091c3dbcf4d134df96"}
{"source_code": "n = int(raw_input().strip())\nspectator = 3\nflag = False\nfor i in range(n):\n    winner = int(raw_input().strip())\n    if(winner == spectator):\n        flag = True\n    else:\n        if(spectator == 1):\n            if(winner == 2):\n                spectator = 3\n            else:\n                spectator = 2\n        elif(spectator == 2):\n            if(winner == 1):\n                spectator = 3\n            else:\n                spectator = 1\n        else:\n            if(winner == 1):\n                spectator = 2\n            else:\n                spectator = 1\n\nif(flag):\n    print 'NO'\nelse:\n    print 'YES'\n        \n", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87"}
{"source_code": "l1=list(map(int,input().split()))\nl1.sort()\nif(l1[0]+l1[3]==l1[2]+l1[1]):\n    print(\"YES\")\nelif(l1[0]+l1[1]+l1[2]==l1[3]):\n    print(\"YES\")\nelse:\n    print(\"NO\")", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37"}
{"source_code": "def checkPrime(x):\n    import math\n    for i in range(2,int(math.sqrt(x))+1):\n        if x%i == 0:\n            return False\n    return True\n\na = {}\nfor i in range(2,1000):\n    n = i\n    if checkPrime(n):\n        a[n] = [n]\n    else:\n        for k in range(2,n/2):\n            l = n-k\n            if checkPrime(k) and checkPrime(l):\n                a[n] = [k,l]\nimport sys\ninp = sys.stdin\nn = int(inp.readline())\nif n<1000 and n in a:\n    print len(a[n])\n    for it in a[n]:\n        print it,\n    exit()\nelse:\n    m = n-1\n    while True:\n        m-=1\n        if checkPrime(m):\n            k = n-m\n            if k in a:\n                print len(a[k])+1\n                print m,\n                for it in a[k]:\n                    print it,\n                exit()\n", "src_uid": "f2aaa149ce81bf332d0b5d80b2a13bc3"}
{"source_code": "k = int(input())\n\na = []\nsum = []\nfor i in range(1, 10):\n    a.append(i)\n    sum.append(i)\nans = -1\nwhile ans == -1:\n    A = []\n    S = []\n    for i in range(len(a)):\n        for j in range(10):\n            if sum[i] + j <= 10:\n                A.append(a[i] * 10 + j)\n                S.append(sum[i] + j)\n    a = A\n    sum = S\n    for i in range(len(a)):\n        if sum[i] == 10:\n            k -= 1\n            if k == 0:\n                ans = a[i]\n                break\nprint(ans)", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a"}
{"source_code": "n,k = map(int,raw_input().split())\ns = map(int,raw_input().split())\na = []\nb = sum(s)\nfor _ in xrange(k):\n    a.append(abs(b-sum(s[_::k])))\nprint max(a)", "src_uid": "6119258322e06fa6146e592c63313df3"}
{"source_code": "D, K, A, B, T = map(int, input().split())\n\ndef nStops(N):\n  if (N == 0):\n    return 0\n  else:\n    return (N - 1)//K\n\ncase1 = D * B\ncase2 = A * D + T * nStops(D)\nans = min(case1, case2)\n\n# Ignorance is the key\nfor i in range(max(0, D - 1000000), D + 1):\n  ans = min(ans, A * i + B * (D - i) + T * nStops(i))\n\nprint(ans)\n", "src_uid": "359ddf1f1aed9b3256836e5856fe3466"}
{"source_code": "def main():\n  a, b = map(int, input().split());\n  count=0;\n  for two_fact in range(0,40):\n    for three_fact in range(0,40):\n        if(a<=(2**two_fact)*(3**three_fact) and b>=(2**two_fact)*(3**three_fact)):\n            count+=1;\n  print(count);\nmain();\n", "src_uid": "05fac54ed2064b46338bb18f897a4411"}
{"source_code": "n = int(input())\ns = input()\nr = 0\nl = n-1\nroot = []\nbuf = []\nto_the_right = True\n \nfor count in range(n):\n    if to_the_right:\n        i = r\n        r += 1\n    else:\n        i = l\n        l -= 1\n    b = s[i]\n \n    if b == '(':\n        if len(buf) == 0 or buf[-1][0] != -1:\n            buf.append([-1,-1,[]])\n        buf[-1][0] = i\n    else:\n        if len(buf) == 0 or buf[-1][1] != -1:\n            buf.append([-1,-1,root])\n            root = []\n            to_the_right = False\n        buf[-1][1] = i\n        \n    if buf[-1][0] != -1 and buf[-1][1] != -1:\n        tmp = buf.pop()\n        if len(buf):\n            buf[-1][2].append(tmp)\n        else:\n            root.append(tmp)\n            to_the_right = True\n \nsol = [[0,1,1]]\nif len(buf) == 0:        \n    sol.append([len(root), 1, 1])\n    for child in root:\n        sol.append([len(child[2])+1, child[0]+1, child[1]+1])\n        for gr_child in child[2]:\n            sol.append([len(root)+len(gr_child[2])+1, gr_child[0]+1, gr_child[1]+1])\n            \nprint('%d\\n%d %d'%tuple(max(sol)))", "src_uid": "be820239276b5e1a346309f9dd21c5cb"}
{"source_code": "a = raw_input().split()\nb = raw_input().split()\nc = raw_input().split()\nxa = int(a[0])\nya = int(a[1])\nxb = int(b[0])\nyb = int(b[1])\nxc = int(c[0])\nyc = int(c[1])\nx1 = xb - xa\nx2 = xb - xc\ny1 = yb - ya\ny2 = yb - yc\nres = x1 * y2 - x2 * y1\nif res > 0:\n    print \"RIGHT\"\nelif res < 0:\n    print \"LEFT\"\nelse:\n    print \"TOWARDS\"\n\n", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69"}
{"source_code": "from math import *\na, b = input().split()\nc, d = input().split()\na = int(a)\nb = int(b)\nc = int(c)\nd = int(d)\ne = abs(a-c)\nf = abs(b-d)\ng = 0\nif e >= f:\n\tprint(e)\nelif f >= e:\n\tprint(f)\t\n\n# 1481129670451", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"}
{"source_code": "p=10**9+7\ndef S(x):\n\tif x==0:\n\t\treturn 0\n\telif x==1:\n\t\treturn 4\n\telif x&1:\n\t\treturn 11*pow(3,x/2,p)-7\n\telse:\n\t\treturn 19*pow(3,x/2-1,p)-7\ndef G(x):\n\treturn (S(x)+S(x+1>>1))*pow(2,p-2,p)%p;\nl,r=map(int,raw_input().split())\nprint (G(r)-G(l-1))%p;", "src_uid": "e04b6957d9c1659e9d2460410cb57f10"}
{"source_code": "s = {0: 0, 1: 0}\nfor i in range(4):\n    a, b, c, d = input().split()\n    if a == c and b != d: s[0] += 1\n    if b == d and a != c: s[1] += 1\n    for q in [(a, b), (c, d)]: s[q] = s.get(q, 0) + 1\nprint('YES' if all(i == 2 for i in s.values()) else 'NO')\n", "src_uid": "ad105c08f63e9761fe90f69630628027"}
{"source_code": "F = ['', 'a', 'b', 'ba', 'bab', 'babba', 'babbabab', 'babbababbabba', 'babbababbabbababbabab', 'babbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab']\nwhile len(F[-3]) < 100000: F.append(F[-1] + F[-2])\nd = 1000000007\n\ndef sqr(t):\n    return [[sum(t[i][k] * t[k][j] for k in range(4)) % d for j in range(4)] for i in range(4)]\n\ndef mul(a, b):\n    return [[sum(a[i][k] * b[k][j] for k in range(4)) % d for j in range(4)] for i in range(4)]\n\ndef fib(k):\n    s, p = format(k, 'b')[:: -1], [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]\n    t = [[[0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 0, 1], [0, 0, 1, 0]]] + [0] * (len(s) - 1)\n    for i in range(1, len(s)):\n        t[i] = sqr(t[i - 1])        \n    for i, k in enumerate(s):\n        if k == '1': p = mul(p, t[i])        \n    return p\n\ndef cnt(t, p):\n    s, i = 0, p.find(t) + 1\n    while i > 0:\n        i = p.find(t, i) + 1\n        s += 1\n    return s\n\ndef f(t, p, k):\n    l = len(t) - 1\n    if l: x, y = cnt(t, F[k - 1][- l: ] + F[k][:l ]), cnt(t, F[k][- l: ] + F[k + 1][:l ])\n    else: x, y = 0, 0\n    a, b = cnt(t, F[k - 1]), cnt(t, F[k])\n    return (p[0] * a + p[1] * b + p[2] * y + p[3] * x) % d\n      \nk, m = map(int, input().split())\nif k > 15:\n    x, y, z = len(F[7]), len(F[17]), len(F) - 4\n    a, b, c = fib(k - 7)[0], fib(k - 17)[0], fib(k - z)[0]\n    for i in range(m):\n        t = input()\n        if len(t) < x: print(f(t, a, 8))\n        elif len(t) < y: print(f(t, b, 18))\n        else: print(f(t, c, z + 1))\nelse:\n    p = F[k]\n    for i in range(m):\n        print(cnt(input(), p))\n", "src_uid": "8983915e904ba763d893d56e94d9f7f0"}
{"source_code": "n = int(raw_input())\nA = list(map(int, raw_input().split()))\nA = list(set(A))\nA = sorted(A)\n\nfor i in range(1, len(A)):\n\tif (A[i - 1] * 2 > A[i]):\n\t\tprint \"YES\"\n\t\texit(0)\nprint \"NO\"", "src_uid": "ab003ab094931fc105384df9d144131e"}
{"source_code": "n,a,b = map(int, raw_input().split())\nprint str((2*a+1)*(n-1)) + \" \" + str(n*b)", "src_uid": "eb815f35e9f29793a120d120968cfe34"}
{"source_code": "seg = [6,2,5,5,4,5,6,3,7,6]\n\ndef calval(num):\n\tif num<0:\n\t\treturn 0\n\ta = [0 for i in range(10)]\n\tt = 1\n\n\twhile num/t>0:\n\t\ttail = num%t\n\t\tle = num/t/10\n\t\tlast = num/t%10\n\n\t\tfor _i in range(10):\n\t\t\ta[_i]+=le*t\n\t\tif le>0:\n\t\t\ta[0]-=t\n\n\t\tfor _i in range(last):\n\t\t\tif le==0 and _i==0:\n\t\t\t\tcontinue\n\t\t\ta[_i]+=t\n\t\tif le==0 and last==0:\n\t\t\tpass\n\t\telse:\n\t\t\ta[last]+=tail+1\n\t\t\n\t\tt*=10\n\t\n\tres = 0\n\tfor _i in range(10):\n\t\tres+=a[_i]*seg[_i]\n\t#print a\n\treturn res\n\na,b = raw_input().split()\na = (int)(a)\nb = (int)(b)\nprint calval(b)-calval(a-1)", "src_uid": "1193de6f80a9feee8522a404d16425b9"}
{"source_code": "mugCount, cupVolume = map(int, raw_input().split())\nmugVolumes = [int(i) for i in raw_input().split()]\n\nif sum(mugVolumes) - max(mugVolumes) <= cupVolume:\n    print 'YES'\nelse:\n    print 'NO'\n", "src_uid": "496baae594b32c5ffda35b896ebde629"}
{"source_code": "def main():\n    M=998244353\n    n,k,*h=map(int,open(0).read().split())\n    m=sum(i!=j for i,j in zip(h,h[1:]+h[:1]))\n    f=[0]*(m+1)\n    f[0]=b=1\n    for i in range(1,m+1):f[i]=b=b*i%M\n    inv=[0]*(m+1)\n    inv[m]=b=pow(f[m],M-2,M)\n    for i in range(m,0,-1):inv[i-1]=b=b*i%M\n    comb=lambda n,k:f[n]*inv[n-k]*inv[k]%M\n    print((pow(k,m,M)-sum(comb(m,i)*comb(m-i,i)*pow(k-2,m-i-i,M)for i in range(m//2+1)))*pow(k,n-m,M)*pow(2,M-2,M)%M)\nmain()", "src_uid": "63c4006a0a6284f9825aaabfc4c28fd1"}
{"source_code": "a,b=map(int,input().split())\nc,d=map(int,input().split())\n\n\nx,y=map(int,input().split())\nz,w=map(int,input().split())\n\n\nTeam1=False\nTeam2=False\nif(a>w and a>y and d>x and d>z):\n    Team1=True\n\nif(c>w and c>y and b>x and b>z):\n    Team1=True\n\nif(((x>b and w>c) or (z>b and y>c)) and ((x>d and w>a) or (z>d and y>a))):\n    Team2=True\n\n\nif(Team1):\n    print(\"Team 1\")\nelif(Team2):\n    print(\"Team 2\")\nelse:\n    print(\"Draw\")\n", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f"}
{"source_code": "n, d=map(int,input().split())\nl=list(map(int,input().split()))\nm=int(input())\nb=m-n\ncount=0\nif b>0:\n  for i in range(n):\n     count=count+l[i]\n\n  count=count-b*d\n\nelse:\n  l.sort()\n  for i in range(m):\n    count=count+l[i]\n  \n\nprint(count)\n", "src_uid": "5c21e2dd658825580522af525142397d"}
{"source_code": "from collections import defaultdict\nfrom sys import exit\nclass Graph:\n    def __init__(self):\n        self.adj=defaultdict(list)\n    def add_edge(self,x,y):\n        self.adj[x].append(y)\n        self.adj[y].append(x)\n    def check(self):\n        for i in range(1,6):\n            for j in range(i+1,6):\n                for k in range(j+1,6):\n                    if j not in self.adj[i] and k not in self.adj[j] and i not in self.adj[k]:\n                        print(\"WIN\")\n                        exit(0)\n                    if j in self.adj[i] and k in self.adj[j] and i in self.adj[k]:\n                        print(\"WIN\")\n                        exit(0)\n        print(\"FAIL\")\ng=Graph()\nn=int(input())\nfor _ in range(n):\n    x,y=map(int,input().split())\n    g.add_edge(x,y)\ng.check()", "src_uid": "2bc18799c85ecaba87564a86a94e0322"}
{"source_code": "s = list(raw_input())\nt = list(raw_input())\n\nleq = (len(s) == len(t))\nsChars = {}\ntChars = {}\nfor i in s:\n\tsChars[i] = sChars.get(i, 0) + 1\nfor i in t:\n\ttChars[i] = tChars.get(i, 0) + 1\nx = 0\nhaschars = True\nfor i in tChars:\n\tif sChars.get(i, 0) < tChars[i]:\n\t\thaschars = False\n\nif not haschars:\n\tprint 'need tree'\nelif leq:\n\tprint 'array'\nelse:\n\tsind = 0\n\ttind = 0\n\twhile tind < len(t):\n\t\tif sind >= len(s):\n\t\t\tprint 'both'\n\t\t\tx = 1\n\t\t\tbreak\n\t\tif s[sind] == t[tind]:\n\t\t\tsind += 1\n\t\t\ttind += 1\n\t\telse:\n\t\t\tsind += 1\n\t\t\n\tif x == 0:\n\t\tprint 'automaton'", "src_uid": "edb9d51e009a59a340d7d589bb335c14"}
{"source_code": "#input\nw1, h1, w2, h2 = list(map(int,input().split(\" \")))\nans = (h1+h2)*2 + max(w1,w2)*2+ 4\nprint (ans)", "src_uid": "b5d44e0041053c996938aadd1b3865f6"}
{"source_code": "from fractions import gcd\nx, y, a, b = map(int, raw_input().split())\n\nlcm = x*y/gcd(x, y)\nprint b/lcm-(a-1)/lcm\n\n", "src_uid": "c7aa8a95d5f8832015853cffa1374c48"}
{"source_code": "# import sys\n# input=sys.stdin.readline\n\na=input()\ndp=[]\nfor i in range(len(a)):\n    dp.append([0]*10)\nfor i in range(10):\n    dp[0][i]=1\n    \nfor i in range(len(a)-1):\n    for j in range(10):\n        if dp[i][j]!=0:\n            c=(int(a[i+1])+j)//2\n            d=(int(a[i+1])+j+1)//2\n            if c!=d:\n                dp[i+1][c]+=dp[i][j]\n                dp[i+1][d]+=dp[i][j]\n            else:\n                dp[i+1][c]+=dp[i][j]\ns=0\nfor i in range(10):\n    s+=dp[-1][i]\nt=0\nc=int(a[0])\nf=[a[0]]\nfor i in range(1,len(a)):\n    d=(c+int(a[i]))//2\n    e=(c+int(a[i])+1)//2\n    if int(a[i])==d:\n        f.append(a[i])\n        c=d\n    elif int(a[i])==e:\n        f.append(a[i])\n        c=e\n    else:\n        break\nif \"\".join(f)==a:\n    t=1\nprint(s-t)", "src_uid": "2dd8bb6e8182278d037aa3a59ca3517b"}
{"source_code": "import sys\n\ndef genForLen(n):\n    res = []\n    for i in xrange(1 << n):\n        s = 0\n        for j in xrange(n):\n            s = s * 10 + (4 if ((i >> j) & 1) != 0 else 7)\n        res.append(s)\n    return res\n\n\ndef genLucky(n):\n    res = []\n    for i in xrange(n):\n        res += genForLen(i + 1)\n    return res\n\ndef calcStrong(pl, pr, vl, vr, preFirst, first, last, postLast, equalIsGood):\n    preFirst = max(preFirst, pl)\n    first = min(first, pr)\n    last = max(last, vl)\n    postLast = min(postLast, vr)\n    a = first - preFirst + 1\n    b = postLast - last + 1\n    if a <= 0 or b <= 0:\n        return 0\n    res = a * b\n    if not equalIsGood and first == last:\n        res -= 1\n\n    return res\n\ndef countGood(pl, pr, vl, vr, k):\n    nums = genLucky(9)\n    nums.sort()\n    res = 0L\n\n    for i in xrange(len(nums) - k + 1):\n        first, last = nums[i], nums[i + k - 1]\n        preFirst = (0 if i == 0 else nums[i - 1]) + 1\n        postLast = (1000000001 if i + k == len(nums) else nums[i + k]) - 1\n        res += calcStrong(pl, pr, vl, vr, preFirst, first, last, postLast, True)\n        res += calcStrong(vl, vr, pl, pr, preFirst, first, last, postLast, False)\n\n    return res\n\npl, pr, vl, vr, k = map(int, sys.stdin.readline().split())\n\nres = countGood(pl, pr, vl, vr, k) / (float(pr - pl + 1) * (vr - vl + 1))\nprint \"%.10f\" % res\n\n\n\n\n\n\n\n", "src_uid": "5d76ec741a9d873ce9d7c3ef55eb984c"}
{"source_code": "tree=int(input())\r\nprint(6*pow(4,pow(2,tree)-2,1000000007)%1000000007)", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4"}
{"source_code": "t = list(map(int, input().split()))\nf0 = 3\nwhile t[f0] != 0:\n    f0 = (f0 + 5) % 6\n    if f0 == 3:\n        break\nif f0 % 2 == 0:\n    print('Ron')\n    exit()\nnum = t[1] * t[3] * t[5]\nden = t[0] * t[2] * t[4]\nif num > den:\n    print('Ron')\nelse:\n    print('Hermione')", "src_uid": "44d608de3e1447f89070e707ba550150"}
{"source_code": "import math \n#------------------------------warmup----------------------------\nimport os\nimport sys\nfrom io import BytesIO, IOBase\n \nBUFSIZE = 8192\n \n \nclass FastIO(IOBase):\n    newlines = 0\n \n    def __init__(self, file):\n        self._fd = file.fileno()\n        self.buffer = BytesIO()\n        self.writable = \"x\" in file.mode or \"r\" not in file.mode\n        self.write = self.buffer.write if self.writable else None\n \n    def read(self):\n        while True:\n            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n            if not b:\n                break\n            ptr = self.buffer.tell()\n            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n        self.newlines = 0\n        return self.buffer.read()\n \n    def readline(self):\n        while self.newlines == 0:\n            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n            self.newlines = b.count(b\"\\n\") + (not b)\n            ptr = self.buffer.tell()\n            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n        self.newlines -= 1\n        return self.buffer.readline()\n \n    def flush(self):\n        if self.writable:\n            os.write(self._fd, self.buffer.getvalue())\n            self.buffer.truncate(0), self.buffer.seek(0)\n \n \nclass IOWrapper(IOBase):\n    def __init__(self, file):\n        self.buffer = FastIO(file)\n        self.flush = self.buffer.flush\n        self.writable = self.buffer.writable\n        self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\n        self.read = lambda: self.buffer.read().decode(\"ascii\")\n        self.readline = lambda: self.buffer.readline().decode(\"ascii\")\n \n \nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\n \n#-------------------game starts now----------------------------------------------------\ndef doi(it,l,t):\n    for i in range(len(l)):\n        if l[i][t]==it:\n            print(l[i][0],l[i][1])\n            return\nn=int(input())\nd=dict()\nd1=dict()\nm=0\nm1=0\nmi=99999999999999999999\nmi1=99999999999999999999\nl=[]\nfor i in range(4*n+1):\n    a,b=map(int,input().split())\n    l.append([a,b])\n    m=max(a,m)\n    mi=min(mi,a)\n    m1=max(b,m1)\n    mi1=min(mi1,b)\n    if a in d:\n        d[a]+=1\n    else:\n        d.update({a:1})\n    if b in d1: \n        d1[b]+=1\n    else:\n        d1.update({b:1})\nif d[m]==1:\n    doi(m,l,0)\nelif d[mi]==1:\n    doi(mi,l,0)\nelif d1[mi1]==1:\n    doi(mi1,l,1)\nelif d1[m1]==1:\n    doi(m1,l,1)\nelse:\n    x1=m\n    x2=mi\n    y1=m1\n    y2=mi1 \n    for i in range(len(l)):\n        if l[i][0]==x1 and y2<=l[i][1]<=y1:\n            continue\n        elif l[i][0]==x2 and y2<=l[i][1]<=y1:\n            continue\n        elif l[i][1]==y1 and x2<=l[i][0]<=x1:\n            continue\n        elif l[i][1]==y2 and x2<=l[i][0]<=x1:\n            continue\n        else:\n            print(l[i][0],l[i][1])\n            break\n\n        ", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06"}
{"source_code": "import math\n\ndef isprime(n):\n    if n == 2:\n        return True\n\n    sq = math.ceil(n ** 0.5) + 1\n    for i in range(2, sq):\n        if n % i == 0:\n            return False\n    return True\n\ndef solve(n):\n    if isprime(n):\n        return 1\n    if n%2 == 0:\n        return 2\n    if isprime(n - 2):\n        return 2\n    return 3\n\nn = int(input())\nprint(solve(n))\n", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b"}
{"source_code": "\r\ncases = int(input())\r\n\r\n\r\n\r\nfor i in range(cases):\r\n    numbers = {1}\r\n    variable = 2\r\n    number = int(input())\r\n    while True and number != 1:    \r\n        if variable**2 <= number:\r\n            numbers.add(variable**2)\r\n        else:\r\n            break\r\n        if variable**3 <= number:\r\n            numbers.add((variable**3))  \r\n        variable += 1\r\n    print(len(numbers))\r\n\r\n                \r\n        \r\n            \r\n            \r\n        \r\n\r\n    \r\n    \r\n    \r\n    \r\n    \r\n        \r\n\r\n    \r\n    \r\n    \r\n    \r\n    \r\n    \r\n", "src_uid": "015afbefe1514a0e18fcb9286c7b6624"}
{"source_code": "def cifera(x,y):\n    cont=0\n    h=x\n    solucion=[]\n    while True: \n        if (h<y):\n            h*=x\n            cont+=1\n        elif (h>y):\n            solucion=[False,cont]\n            break\n        else:\n            solucion=[True,cont]\n            break\n    return solucion\n\nk=input()\nl=input()\n\nresultado=cifera(k,l)\n\nif (resultado[0]==True):\n    print \"YES\\n\",resultado[1]\nelse:\n    print \"NO\\n\"\n\n", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"}
{"source_code": "def nextc(m):\n    m2 = {}\n    for n, c in m.iteritems():\n        h = n-1 >> 1\n        m2[h] = m2.get(h, 0) + c\n        m2[n-1 - h] = m2.get(n-1 - h, 0) + c\n    return m2\n\ndef countseg(l, s, cache={}):\n    if s > l: return 0\n    if s == l: return 1\n    if (l, s) in cache:\n        return cache[l, s]\n    h = l-1 >> 1\n    out = countseg(h, s) + countseg(l-1 - h, s)\n    cache[l, s] = out\n    return out\n    \ndef findx(l, q, ss):\n    if l <= max(ss):\n        return (l-1 >> 1) + q\n    h = l-1 >> 1\n    ns = sum(countseg(h, s) for s in ss)\n    if q >= ns:\n        return h + 1 + findx(l-1 - h, q - ns, ss)\n    else:\n        return findx(h, q, ss)\n\ndef f(l, r):\n    m = {l: 1, l-1: 0}\n    q = 1\n    while r >= q and min(m) > 2:\n        r -= q\n        q <<= 1\n        m = nextc(m)\n    mn, mx = min(m), max(m)\n    if mx & 1:\n        if r >= m[mx]:\n            if mx == 3:\n                return findx(l, r - m[mx], [1,2])\n            return findx(l, r - m[mx], [mn])\n        else:\n            return findx(l, r, [mx])\n    else:\n        return findx(l, r, [mn, mx])\n\ndef ans(n, k):\n    if k == 1: return 1\n    if k == 2: return n\n    return 2 + f(n - 2, k - 3)\n    \ndef brute_ans(n, k):\n    if k == 1: return 1\n    if k == 2: return n\n    return 2 + brute_f(n - 2, k - 2)\n    \ndef brute_f(l, r):\n    s = [(0, l)]\n    for _ in xrange(r):\n        i = max(xrange(len(s)), key=lambda j: s[j][1]-1 >> 1)\n        x, d = s[i]\n        h = d-1 >> 1\n        s = s[:i] + [(x, h), (x+h+1, d-1-h)] + s[i+1:]\n    return x+h\n\ndef test_n(n):\n    for i in xrange(1, n + 1):\n        assert brute_ans(n, i) == ans(n, i)\n\nif __name__ == '__main__':\n    n, k = map(int, raw_input().split())\n    print ans(n, k)\n", "src_uid": "eb311bde6a0e3244d92fafbd4aa1e61f"}
{"source_code": "z=input();k=max(z)\nprint(k*z.count(k))\n", "src_uid": "9a40e9b122962a1f83b74ddee6246a40"}
{"source_code": "for i in range(int(input())):\n    t = input()[4:]\n    q, d = int(t), 10 ** len(t)\n    while q < 1988 + d // 9: q += d\n    print(q)", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21"}
{"source_code": "__author__ = 'Devesh Bajpai'\n\n'''\nhttps://codeforces.com/problemset/problem/988/A\n\nSolution: Using a brute-force approach, where a visited boolean array checks the presence of a number being seen or not.\nThis insures distinctness constraint. A result list maintains the final indices but indexed at 1. \nAs soon as the result list since reaches k, we return the decision YES and result list. If the loop that traverses on the\nnumbers exhausts and the result list hasn't reached k, the decision NO and null is returned. \n'''\n\n\ndef solve(n, k, nums):\n    visited = [False for _ in range(101)]\n    result = []\n    currResultSize = 0\n\n    for i in xrange(0, n):\n\n        num = nums[i]\n        if not visited[num]:\n\n            visited[num] = True\n            result.append(i+1) #since the index referred in this problem starts at 1 instead of 0\n            currResultSize += 1\n\n            if currResultSize == k:\n                return \"YES\", result\n\n    return \"NO\", None\n\n\nif __name__ == \"__main__\":\n    n, k = map(int,raw_input().split(\" \"))\n    nums = map(int,raw_input().split(\" \"))\n    decision, results = solve(n, k, nums)\n\n    print decision\n    if decision == \"YES\":\n        print ' '.join([str(result) for result in results])\n", "src_uid": "5de6574d57ab04ca195143e08d28d0ad"}
{"source_code": "n, m = map(int, input().split())\nd = 0\ni = 1\nwhile n > 0:\n    n -= 1\n    d += 1\n    if d == m * i:\n       n += 1\n       i += 1\nprint(d)", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"}
{"source_code": "from sys import stdout\n\n\nclass Mock:\n    def __init__(self, cap, a):\n        self.a, self.cap = a, cap\n        self.n, self.q = len(a), []\n\n    def ask(self, i):\n        result = self.a[i] in self.q\n        self.q.append(self.a[i])\n        if len(self.q) > self.cap:\n            self.q = self.q[1:]\n        return result\n\n    def reset(self):\n        self.q = []\n\n    def out(self, result):\n        print('!', result)\n\n\nclass IO:\n    def __init__(self):\n        self.n, self.cap = map(int, input().split())\n\n    def ask(self, i):\n        print('?', i + 1)\n        stdout.flush()\n        return input() == 'Y'\n\n    def reset(self):\n        print('R')\n        stdout.flush()\n\n    def out(self, result):\n        print('!', result)\n\n\ndef solve(io):\n    n, cap = io.n, io.cap\n    size = cap + 1 >> 1\n    count = n // size\n    removed = [False] * n\n    for d in range(1, count):\n      for r in range(min(d, count - d)):\n        for i in range(r, count, d):\n          for j in range(i * size, (i + 1) * size):\n            if not removed[j] and io.ask(j):\n              removed[j] = True\n      io.reset()\n    return removed.count(False)\n\n\n# io = Mock(2, [1, 4, 1, 3])\n# io.out(solve(io))\n\n# io = Mock(8, [1, 2, 3, 4, 5, 6, 6, 6])\n# io.out(solve(io))\n\nio = IO()\nio.out(solve(io))", "src_uid": "11ad68b4375456733526e74e72606d8d"}
{"source_code": "a = list(map(int, input().split()))\nans = 0\nfor i in range(14):\n    x, b, tru, dop = a[i], a[:], a[i] // 14, a[i] % 14\n    b[i] = 0\n    for j in range(i + 1, 14):\n        b[j] += tru\n        if dop > 0:\n            b[j] += 1\n            dop -= 1\n    for j in range(0, i + 1):\n        b[j] += tru\n        if dop > 0:\n            b[j] += 1\n            dop -= 1\n    cnt = 0\n    for j in range(14):\n        cnt += b[j] if b[j]%2==0 else 0\n    ans = max(ans, cnt)\nprint(ans)", "src_uid": "1ac11153e35509e755ea15f1d57d156b"}
{"source_code": "numberofboxes = int(raw_input())\nboxes = list(map(int,raw_input().split(\" \")))\n\nboxes.sort()\n\nstacklist = [0]\n\n\nfor i in boxes:\n    for j in range(len(stacklist)):\n        if i >= stacklist[j]:\n            stacklist[j] += 1\n            break\n    else:    \n        stacklist.append(1)\n\n    \nprint len(stacklist)", "src_uid": "7c710ae68f27f140e7e03564492f7214"}
{"source_code": "teams={}\nfor _ in range(5):\n    t1,t2,scores=raw_input().split()\n    s1,s2=map(int,scores.split(':'))\n    teams[t1]=teams.get(t1) or [0,0,0,t1,0]\n    teams[t2]=teams.get(t2) or [0,0,0,t2,0]\n    if s1>s2:\n        teams[t1][0]-=3\n    elif s1<s2:\n        teams[t2][0]-=3\n    else:\n        teams[t1][0]-=1\n        teams[t2][0]-=1\n    teams[t1][1]-=s1-s2\n    teams[t2][1]-=s2-s1\n    teams[t1][2]-=s1\n    teams[t2][2]-=s2\n    teams[t1][4]+=1\n    teams[t2][4]+=1\noppo=[t[3] for t in teams.values() if t[3]!='BERLAND' and t[4]<3][0]\nfor xy in range(1,123):\n    for y in range(0,123):\n        t1,t2=teams['BERLAND'][:],teams[oppo][:]\n        t1[0]-=3\n        t1[1]-=xy\n        t2[1]+=xy\n        t1[2]-=y+xy\n        t2[2]-=y\n        t1[4]+=1\n        t2[4]+=1\n        tms=[t for t in teams.values() if t[4]>2]+[t1,t2]\n        tms.sort()\n        if tms[0][3]=='BERLAND' or tms[1][3]=='BERLAND':\n            print '%d:%d'%(y+xy,y)\n            exit()\nprint 'IMPOSSIBLE'\n", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1"}
{"source_code": "t=[input(),input()]\ndef f(x):\n  return int(str(x).replace('0',''))\nr='NO'\nif f(sum(t))==sum(map(f,t)): r='YES'\nprint r\n", "src_uid": "ac6971f4feea0662d82da8e0862031ad"}
{"source_code": "import itertools\n \n \ng = [list(map(int, input().split())) for _ in range(5)]\nmaximum = 0\n \nfor p in itertools.permutations(range(5)):\n    p = list(p)\n    maximum = max(maximum, g[p[0]][p[1]] + g[p[1]][p[0]] + g[p[2]][p[3]]\n            + g[p[3]][p[2]] + g[p[1]][p[2]] + g[p[2]][p[1]] + g[p[3]][p[4]]\n            + g[p[4]][p[3]] + g[p[2]][p[3]] + g[p[3]][p[2]] + g[p[3]][p[4]]\n            + g[p[4]][p[3]])\n \nprint(maximum)", "src_uid": "be6d4df20e9a48d183dd8f34531df246"}
{"source_code": "n,m = map(int,raw_input().split())\nif n>m:n,m = m,n\nprint n-1+(m-n),n", "src_uid": "c8378e6fcaab30d15469a55419f38b39"}
{"source_code": "B = [0] * 601\nn = int(input())\nk = 0\nA = list(map(int,input().split()))\nfor i in A:\n    if i != 0 and B[i] == 0:\n        B[i] = 1\n        k += 1\nprint(k)    ", "src_uid": "3b520c15ea9a11b16129da30dcfb5161"}
{"source_code": "n=int(input())\nif n%2==0:\n    print(2**(n//2))\nelse:\n    print(0)", "src_uid": "4b7ff467ed5907e32fd529fb39b708db"}
{"source_code": "from sys import *\nfrom math import *\n\ns = stdin.readline().strip()\nans = 1\nnow = 10\nwas = {}\nwas['A'] = False\nwas['B'] = False\nwas['C'] = False\nwas['D'] = False\nwas['E'] = False\nwas['F'] = False\nwas['G'] = False\nwas['H'] = False\nwas['I'] = False\nwas['J'] = False\n\nif s[0] == '?':\n  ans *= 9\nif (ord(s[0]) >= ord('A')) and (ord(s[0]) <= ord('J')):\n  ans *= 9\n  was[s[0]] = True\n  now = 9\ncnt = 0\nfor i in range(1, len(s)):\n  if s[i] == '?':\n    cnt += 1\n  if (ord(s[i]) >= ord('A')) and (ord(s[i]) <= ord('J')):\n    if was[s[i]] == False:\n      ans *= now\n      now -= 1\n    was[s[i]] = True\nprint(ans, end = \"\") \nfor i in range(cnt):\n  print('0', end = \"\")\nprint()\n", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82"}
{"source_code": "n = int(raw_input ( ))\nx = map(int,raw_input ( ).split ( ))\nt = int(raw_input ( ))\nx.sort ( )\nmaxi = []\nfor i in range(n):\n    num = 0\n    for j in range(i, n):\n        if ( x[j] - x[i] > t ):\n            break\n        else:\n            num += 1\n    maxi.append ( num )\nprint sorted(maxi)[n-1]\n", "src_uid": "086d07bd6f9031df09bd6a6e8fe8f25c"}
{"source_code": "def main():\n    import sys\n    input = sys.stdin.readline\n\n    N, mod = map(int, input().split())\n    nmax = N + 1  # change here\n    fac = [0] * (nmax + 1)\n    fac[0] = 1\n    fac[1] = 1\n    for i in range(2, nmax):\n        fac[i] = fac[i - 1] * i % mod\n\n    ans = 0\n    for k in range(1, N+1):\n        ans = (ans + (((N-k+1) ** 2)%mod * (fac[N-k] * fac[k])%mod)%mod) % mod\n    print(ans)\n\n\nif __name__ == '__main__':\n    main()", "src_uid": "020d5dae7157d937c3f58554c9b155f9"}
{"source_code": "l, d, v, g, r = map(int, input().split())\n\nt = d / v\nc = 0\n\nwhile t > g + r:\n    t -= (g + r)\n    c += 1\n\nif t < g:\n    print(l / v)\n\nelif t <= (g + r):\n    c += 1\n    print(c * (g + r) + (l - d) / v)\n\n", "src_uid": "e4a4affb439365c843c9f9828d81b42c"}
{"source_code": "a,b,c=map(int,input().split())\nval=b\nres=[val]\ni=2\nwhile(val<a*c):\n    val=b*i\n    res+=[val]\n    i+=1\nn=len(res)\nl=0\nh=n-1\nans=-1\n#print(res)\nwhile(l<=h):\n    mid=l+(h-l)//2\n    if(res[mid]+b*(c-1)<a*c):\n        ans=mid\n        l=mid+1\n    else:\n        h=mid-1\n    #print(mid)\nprint(ans+1)", "src_uid": "7dd098ec3ad5b29ad681787173eba341"}
{"source_code": "def solve(k, grid):\n    seek = *range(2*k + 2), *range(4*k + 1, 2*k + 1, -1)\n    flat = [seek[v] for v in grid[0] + grid[1][::-1] if v]\n\n    m = {\n        'L': 'l'*2*k + 'u' + 'r'*2*k + 'd',\n        'R': 'u' + 'l'*2*k + 'd' + 'r'*2*k,\n        'C': 'l'*k + 'u' + 'r'*k + 'd',\n        'D': 'CC' + 'R'*(2*k + 1) + 'CC' + 'R'*(2*k + 2),\n        'F': 'R'*(k - 1) + 'DD' + 'R'*(2*k + 1) + 'D' + 'L'*2*k + 'DD' + 'L'*k,\n        'G': 'FF',\n    }\n\n    [(i, j)] = [(i, j) for i in range(2) for j in range(2*k + 1) if grid[i][j] == 0]\n    st = 'r'*(2*k - j) + 'd'*(1 - i)\n\n    for v in range(2, 4*k + 2):\n        ct = flat.index(v)\n\n        if ct >= 2:\n            st += 'L'*(ct - 2) + 'GR'*(ct - 2) + 'G'\n            flat = flat[ct - 1: ct + 1] + flat[:ct - 1] + flat[ct + 1:]\n\n        if ct >= 1:\n            st += 'G'\n            flat = flat[1:3] + flat[:1] + flat[3:]\n\n        st += 'L'\n        flat = flat[1:] + flat[:1]\n        \n    if flat[0] == 1: return st, m\n\ndef main():\n    def get_line():\n        return [0 if x == 'E' else int(x) for x in input().split()]\n\n    for cas in range(int(input())):\n        res = solve(int(input()), [get_line() for i in range(2)])\n        if res is None:\n            print('SURGERY FAILED')\n        else:\n            print('SURGERY COMPLETE')\n            st, m = res\n            print(st)\n            for shortcut in m.items(): print(*shortcut)\n            print('DONE')\n\nmain()", "src_uid": "697c4af98ea881892365bed856b49988"}
{"source_code": "def gcd(a, b):\n    while a and b:\n        a %= b\n        if a: b %= a\n    return a + b\n \ndef gcd2(A):\n    r = A[1] - A[0]\n    for i in (2, 3):\n        r = gcd(r, A[i] - A[0])\n    return r\n \ndef Mir(x, c): return c * 2 - x\n \ndef Solve(A):\n    A[0].sort()\n    A[1].sort()\n    gcds = [gcd2(A[0]), gcd2(A[1])]\n    I0, I1 = 0, 1\n    if A[0][-1] - A[0][0] > A[1][-1] - A[1][0]: I0, I1 = I1, I0\n    if A[I1][-1] == A[I1][0]:\n        if A[I1][0] == A[I0][0]: return []\n        return None\n    elif A[I0][-1] == A[I0][0]:\n        return None\n    if gcds[0] != gcds[1]: return None\n    if (A[0][0] - A[1][0]) % gcds[0] != 0: return None\n \n    ops = [[], []]\n    def Op(I, J1, JC):\n        ops[I].append((A[I0][J1], A[I0][JC]))\n        A[I0][J1] = Mir(A[I0][J1], A[I0][JC])\n    while True:\n        for a in A: a.sort()\n        if max(A[0][-1], A[1][-1]) - min(A[0][0], A[1][0]) <= gcds[0]: break\n        #print('====now', A)\n        gapL = abs(A[0][0] - A[1][0])\n        gapR = abs(A[0][-1] - A[1][-1])\n        if gapL > gapR:\n            I0, I1 = (0, 1) if A[0][0] < A[1][0] else (1, 0)\n            view = lambda x: x\n        else:\n            I0, I1 = (0, 1) if A[0][-1] > A[1][-1] else (1, 0)\n            view = lambda x: 3 - x\n        for a in A: a.sort(key=view)\n        lim = max(view(A[I0][-1]), view(A[I1][-1]))\n        B = [view(x) for x in A[I0]]\n \n        actioned = False\n        for J in (3, 2):\n            if Mir(B[0], B[J]) <= lim:\n                Op(I0, (0), (J))\n                actioned = True\n                break\n        if actioned: continue\n \n        if Mir(B[0], B[1]) > lim:\n            Op(I0, (3), (1))\n            continue\n        if (B[1] - B[0]) * 8 >= lim - B[0]:\n            Op(I0, (0), (1))\n            continue\n        if (B[3] - B[2]) * 8 >= lim - B[0]:\n            Op(I0, (0), (2))\n            Op(I0, (0), (3))\n            continue\n        if B[1] - B[0] < B[3] - B[2]:\n            Op(I0, (1), (2))\n            Op(I0, (1), (3))\n        else:\n            Op(I0, (2), (1))\n            Op(I0, (2), (0))\n        Op(I0, (0), (1))\n    if A[0] != A[1]: return None\n    return ops[0] + [(Mir(x, c), c) for x, c in reversed(ops[1])]\n \ndef Output(ops):\n    if ops is None:\n        print(-1)\n        return\n    print(len(ops))\n    for x, c in ops: print(x, c)\n \nimport sys\nA = [list(map(int, sys.stdin.readline().split())) for _ in range(2)]\nOutput(Solve(A))\n", "src_uid": "7b6b3d4bc0a269836bc0113bb17f562f"}
{"source_code": "b = int(input())\ng = int(input())\nn = int(input())\nprint(min(n, b, g, b + g - n) + 1)", "src_uid": "9266a69e767df299569986151852e7b1"}
{"source_code": "a, b = map(int, raw_input().split())\nprint a if a == b else 2", "src_uid": "a8d992ab26a528f0be327c93fb499c15"}
{"source_code": "import sys;range = xrange;input = raw_input;inp = [int(x) for x in sys.stdin.read().split()]; ii = 0;n = inp[ii]; ii += 1;coupl = [[] for _ in range(n)]\nfor _ in range(n - 1):u = inp[ii] - 1; ii += 1;v = inp[ii] - 1; ii += 1;coupl[u].append(v);coupl[v].append(u)\nroot = 0;bfs = [root]\nfor node in bfs:\n    for nei in coupl[node]:\n        del coupl[nei][coupl[nei].index(node)]\n        bfs.append(nei)\n\ncounter = [0] * n\nfor node in reversed(bfs):\n    counter[node] += 1\n    for nei in coupl[node]:counter[node] += counter[nei]\n\nnhalf = n // 2\n\nfor node in range(n):\n    vals = [counter[nei] for nei in coupl[node]];vals.append(n - 1 - sum(vals))\n    if max(vals) <= nhalf:break\nroot = node\nfor node in reversed(bfs):\n    for nei in coupl[node]:coupl[nei].append(node)\nfound = [0] * n;depth = [0] * n;order = [];stack = [root]\nwhile stack:\n    node = stack.pop()\n    if found[node]:continue\n    found[node] = 1;order.append(node)\n\n    for nei in coupl[node]:\n        if not found[nei]:\n            depth[nei] = depth[node] + 1\n            stack.append(nei)\n    stack += coupl[node]\n\nans = [-1] * n\nfor i in range(n):\n    ans[order[i - nhalf]] = order[i]\n\nprint 2 * sum(depth)\nprint ' '.join(str(x + 1) for x in ans)", "src_uid": "343dbacbc6bb4981a062dda5a1a13656"}
{"source_code": "s = raw_input()\nl = s.split(\" \")\nn = long(l[0])\nn = (n + 540) % 360 - 180\n\n\nl = []\nfor i in range(4):\n\tl.append((abs(n),i))\n\tn -= 90\n\tn = (n + 540) % 360 - 180\n\nl.sort()\n\nprint l[0][1]", "src_uid": "509db9cb6156b692557ba874a09f150e"}
{"source_code": "x = int(raw_input())\n\nif x == 1:\n    print 1\nelif x == 2:\n    print 3\nelif x == 3:\n    print 5\nelif x == 4 or x == 5:\n    print 3\nelif x <=13:\n    print 5\nelif x <= 25:\n    print 7\nelif x <= 41:\n    print 9\nelif x <= 61:\n    print 11\nelif x <= 85:\n    print 13\nelse:\n    print 15\n", "src_uid": "01eccb722b09a0474903b7e5abc4c47a"}
{"source_code": "n,a,b,c=map(int,raw_input().split())\nprint min(min(a,b+c)*(4 - n%4),(10**10 if n&1 else min(b,2*c)),(10**10 if n%4 else 0),(c*(n%4) if n&1 else 10**10),(a+b if n%4==1 else 10**10),)\n", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8"}
{"source_code": "t, s, q = map(int, raw_input().split())\n\nelapsed = 0\n\nif s * (q - 1) + s >= t:\n    elapsed = 1\n\nelse:\n    elapsed += 1\n    \n    while (s + s*(q - 1)) < t:\n        s += s*(q-1)\n\n        elapsed += 1\n\nprint elapsed", "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9"}
{"source_code": "n = int(input())\nf = [0] * (n + 1)\np = [(0, 0, 0)] * (n + 1)\nfor i in range(1, n + 1):\n\tx, y = map(int, input().split())\n\tp[i] = (x, y, max(x, y))\n\np.sort(key=lambda x : (x[2], x[0] - x[1]))\n\ndef dis(a, b):\n\treturn abs(a[0] - b[0]) + abs(a[1] - b[1])\n\nlasi = lasj = 0\ni = 1\nwhile i <= n:\n\tj = i\n\twhile j < n and p[j + 1][2] == p[i][2]:\n\t\tj += 1\n\tfor k in {i, j}:\n\t\tf[i ^ j ^ k] = dis(p[i], p[j]) + min(f[l] + dis(p[l], p[k]) for l in {lasi, lasj})\n\tlasi, lasj = i, j\n\ti = j + 1\n\nprint(min(f[lasi], f[lasj]))", "src_uid": "06646a9bdce2d65e92e525e97b2c975d"}
{"source_code": "a, b, c, d = list(map(int, input().split(' ')))\n\nif a == c and b < d:\n    print(\"Polycarp\")\nelif a == c and b > d:\n    print(\"Vasiliy\")\nelif a < c and b == d:\n    print(\"Polycarp\")\nelif a > c and b == d:\n    print(\"Vasiliy\")\nelif a > c and b > d:\n    print(\"Vasiliy\")\nelif a < c and b < d:\n    print(\"Polycarp\")\nelse:\n    if a+b<=max(c, d):\n        print(\"Polycarp\")\n    else:\n        print(\"Vasiliy\")\n", "src_uid": "2637d57f7809ff8f922549c617709074"}
{"source_code": "a=input()+input()\nb=input()+input()\nif ((a in ['ABCX', 'ABXC', 'XBAC', 'BXAC', 'BCAX', 'BCXA',\n   'XCBA', 'CXBA', 'CABX', 'CAXB', 'XACB', 'AXCB']) == (b in ['ABCX', 'ABXC', 'XBAC', 'BXAC', 'BCAX', 'BCXA',\n   'XCBA', 'CXBA', 'CABX', 'CAXB', 'XACB', 'AXCB'])):\n    print(\"YES\")\nelse:\n    print(\"NO\")\n", "src_uid": "46f051f58d626587a5ec449c27407771"}
{"source_code": "n = int(input().strip())\nvals = [int(x) for x in (input().strip().split())]\nterm = vals[1]\nd = vals[1]-vals[0]\nap = True\nfor x in range(2,n):\n\tnext_term = vals[x]\n\tif (next_term-term != d):\n\t\tap = False\n\tterm = next_term\n\nif ap:\n\tprint(term+d)\nelse:\n\tprint(term)", "src_uid": "d04fa4322a1b300bdf4a56f09681b17f"}
{"source_code": "[h, n] = map(int, raw_input('').split(' '))\n\n\ndef size_of_tree(height):\n    total = 0\n    for i in xrange(height):\n        total += pow(2, i)\n    return total\n\n\ndef get_parent(nodes):\n    if nodes % 2 == 0:\n        return (nodes / 2)\n    return ((nodes - 1) / 2) + 1\n\n\ndef get_parity(node_number, height):\n    if height == 1:\n        if node_number == 1:\n            return 1\n        else:\n            return 2\n    else:\n        temp = (node_number - 1) % 4\n        if temp == 0 or temp == 3:\n            return 2\n        return 1\n\ntotal_visited = 0\nheight = h - 1\ncurrent = n\nparent = get_parent(current)\nparity = get_parity(current, height + 1)\n\nwhile height >= 0:\n    total_visited += 1\n    if parity == 2:\n        total_visited += size_of_tree(h - height)\n    current = parent\n    parent = get_parent(current)\n    height -= 1\n    parity = get_parity(current, height + 1)\n\nprint total_visited\n", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781"}
{"source_code": "\"\"\"\ninstagram : essipoortahmasb2018\ntelegram channel : essi_python\n\"\"\"\ns = [*map(int,input().split(\":\"))]\nt = [*map(int,input().split(\":\"))]\n\n\n\nif(s[1] + t[1] >= 60):\n    flag = 1\n    d = (s[1] + t[1] - 60)//2\nelse:\n    d = (s[1] + t[1])//2\n    flag = 0\n\nh = s[0] + t[0] + flag\n\nif h%2!=0:\n        h//=2\n        d+=30\nelse:\n    h //= 2\n    \nif len(str(h))<2:\n    print(\"0\"+str(h)+\":\",end=\"\")\nelse:\n    print(str(h)+\":\",end=\"\")\nif len(str(d))<2:\n    print(\"0\"+str(d),end=\"\")\nelse:\n    print(str(d),end=\"\")\n\n", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"}
{"source_code": "n = int(input())\n\ndef Solve(n, Rot):\n    \n    for x in range(2**n):\n        \n        Sum = 0\n        \n        x = list(bin(x).replace(\"0b\", \"\"))\n        \n        while(len(x) < n):\n            \n            x.insert(0, '0')\n            \n        for i in range(n):\n            if x[i] == '0':\n                Sum += Rot[i]\n            else:\n                Sum -= Rot[i]\n                \n        if Sum%360 == 0:\n            return 'YES'\n    \n    return 'NO'\n    \nRot = []\n\nfor i in range(n):\n    Rot.append(int(input()))\n    \nprint(Solve(n, Rot))\n                \n        \n        \n        ", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"}
{"source_code": "#!/usr/bin/python\n\nfrom math import floor\n\nm = int(raw_input())\nl = [k**3.0 for k in xrange(2,180000)]\n\ndef check(num):\n    return m > check2(num)\n\ndef check2(num):\n    return sum(floor(num/l[i]) for i in xrange(int(num**(1.0/3))))\n\nma = 5 * 10**15\nmi = int(4.8 * m)\n\nwhile ma-mi > 1:\n    mid = (ma+mi)/2\n    if check(mid):\n        mi = mid\n    else:\n        ma = mid\n\nif check2(ma) == m:\n    print ma\nelse:\n    print -1\n", "src_uid": "602deaad5c66e264997249457d555129"}
{"source_code": "n=int(raw_input())\nMOD=1000000007\na=map(int,raw_input().split())\ntwos=sum(a)-n\nones=n-twos\nans=0\nx=ones/2\nweirds=[1,1]\nfor i in xrange(2,x+3):\n\tweirds.append(weirds[-1]*(2*i-1))\nnc2i=[1]\nfor i in xrange(1,x+3):\n\tnc2i.append(nc2i[-1]*(ones-2*i+1)*(ones-2*i+2)/(2*i-1)/(2*i))\nfor i in xrange(x+1):\n\tans+=weirds[i]*nc2i[i]\n\tans%=MOD\nfor i in xrange(twos):\n\tans*=n-i\n\tans%=MOD\nprint ans\n\n", "src_uid": "91e8dbe94273e255182aca0f94117bb9"}
{"source_code": "S = raw_input()\na = S[0]\nk = 0\n\nwhile(a=='!'):\n\ta = S[k+4]\n\tk += 4\nb = S[1]\nk = 1\nwhile(b=='!'):\n\tb = S[k+4]\n\tk += 4\nc = S[2]\nk = 2\nwhile(c=='!'):\n\tc = S[k+4]\n\tk += 4\n\nd = S[3]\nk = 3\nwhile(d=='!'):\n\td = S[k+4]\n\tk += 4\n\nnuma = [[a,0] , [b,0], [c,0], [d,0]]\n\nfor i in xrange(len(S)):\n\tif S[i] == \"!\":\n\t\tnuma[i%4][1] += 1\n\nnuma.sort(key = lambda x: x[0])\n\nc = [numa[2][1], numa[0][1], numa[3][1], numa[1][1]]\n\nprint \" \".join([str(x) for x in c])", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"}
{"source_code": "n, m = map(int, input().split())\na = [int(i) for i in input().split()]\nb = sorted([[a[i], i] for i in range(n)])\nfor i in range(m):\n    l, r = map(int, input().split())\nfor i in range(n):\n  a[b[i][1]] = str(i%2)  \nprint(' '.join(a))", "src_uid": "692698d4b49ad446984f3a7a631f961d"}
{"source_code": "# http://codeforces.com/problemset/problem/804/A\n\nx = int(raw_input())\nif x %2 == 0:\n\tprint ((x/2)-1)\nelse:\n\tprint x/2\n", "src_uid": "dfe9446431325c73e88b58ba204d0e47"}
{"source_code": "s = input()\nif s.count('1') != 0:\n    if s[s.index('1'):].count('0') > 5:\n        print('yes')\n    else:\n        print('no')\nelse:\n    print('no')\n", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"}
{"source_code": "from fractions import gcd\nl,r=map(int,raw_input().split())\nflag=0\nif r-l==1:\n    print -1\nelse:\n    for i in range(l,r-1):\n        for j in range(i+1,r):\n            for k in range (j+1,r+1):\n                if gcd(i,j)==1 and (gcd(j,k)==1 and gcd(i,k)!=1):\n                    a=i\n                    b=j\n                    c=k\n                    flag=1\n                    break\n    if flag==1:\n        print a,b,c\n    else:\n        print -1", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d"}
{"source_code": "import sys\nn = int(sys.stdin.readline())\nif n == 0:\n    print(0)\nelse:\n    print((n + 1) // 2 if (n + 1) % 2 == 0 else n + 1)", "src_uid": "236177ff30dafe68295b5d33dc501828"}
{"source_code": "n = int(input())\na = [0]+list(map(int, input().split()))+[1001]\nans = 0\ncnt = 1\n\nfor i in range(1, n+2):\n    if a[i]==a[i-1]+1:\n        cnt += 1\n        ans = max(ans, cnt-2)\n    else:\n        cnt = 1\n\nprint(ans)", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198"}
{"source_code": "n, m = map(int, input().split())\nans = 0\nwhile n > 0 and m > 0:\n    ans += n//m\n    n, m = m, n % m\nprint(ans)", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"}
{"source_code": "a,b=map(int,input().split())\nl=input().split()\nfor i in range(b):\n    l[i]=int(l[i])\nl=sorted(l)\nm=[]\nfor k in range(b-a+1):\n    m.append(l[k+a-1]-l[k])\nprint(min(m))\n    \n", "src_uid": "7830aabb0663e645d54004063746e47f"}
{"source_code": "a = input()\nticket = input()\n\n\ndef gold(s, l):\n    if len(l) == 0:\n        return True\n    for i in range(len(l)):\n        sum_i = sum([int(l[j]) for j in range(i+1)])\n        if sum_i > s:\n            return False\n        elif sum_i == s:\n            if sum([int(l[j]) for j in range(i+1, len(l))]) == 0:\n                return True\n            return gold(s, l[i+1:len(l)])\n    return False\n\n\ndef task(l):\n    for i in range(len(l)-1):\n        f_i_sum = sum([int(l[j]) for j in range(i+1)])\n        rest = l[i+1:len(l)]\n        if gold(f_i_sum, rest):\n            return True\n    return False\n\n\nif task(ticket):\n    print(\"YES\")\nelse:\n    print(\"NO\")\n", "src_uid": "410296a01b97a0a39b6683569c84d56c"}
{"source_code": "a,b=map(int,input().split())\nsum=0\n#print(count)\n#print(sum)\nfor i in range(b,a+1,b):\n    if(i<=a and 2*i>=a):\n        sum=i\n        break\nif(a>=b):\n    print(sum)\nelse:\n    print(-1)\n", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"}
{"source_code": "n = int(input())\n\ndef table(i, j):\n    if i == 1 or j == 1:\n        return 1\n    return table(i - 1, j) + table(i,j - 1)\n\nprint(table(n,n))\n", "src_uid": "2f650aae9dfeb02533149ced402b60dc"}
{"source_code": "import sys\nn,k=map(int,input().split())\na=list(input())\nif k==0:\n  print(''.join(a))\n  sys.exit()\nif n==1:\n  print(0)\n  sys.exit()\nif a[0]!='1':\n  a[0]='1'\n  k=k-1\ni=1\nwhile k>0 and i<n:\n  if a[i]!='0':\n    a[i]='0'\n    k=k-1\n    i+=1\n  else:\n    i+=1\nprint(''.join(a))", "src_uid": "0515ac888937a4dda30cad5e2383164f"}
{"source_code": "a=[[0],[2,1],[32,30,80,109],[6824,59808,147224,415870,1757896,1897056,4898872,7593125],[776830421,290516100,746623577,293783147,33900006,735127505,565460332,428982705,472062098,161873957,117354594,515619293,578944191,312106242,569389279,391464593],[261086313,584837659,683961846,468868529,211593382,736955478,229471758,157617135,398169441,360252438,629394768,264125799,647490480,342079395,391579767,225200475,486011304,513156108,628771752,132906648,142138221,20119449,444199674,195188679,387329805,44684703,651912135,737154512,612549793,519860281,186175544,212568440],[240805271,239509872,581127897,6511239,156126222,509425833,672407328,366667722,459185405,509737025,554790222,165216555,703150560,74806569,398730015,383350905,506108358,51326142,298053147,104256117,391428765,374020479,206607807,87664059,275899176,56407680,551553401,448939463,582889860,129676638,226078251,135769095,61292868,578972226,190181628,390739055,184587732,446575689,732674124,232198470,676760679,352474101,611444862,575661807,628905585,320813094,522840969,469781928,156006018,554473341,239654268,643714911,433540170,199307003,496385218,291740751,67309914,370826673,202356819,279421821,421203111,63744786,520987612,550671827],[482164403,768209115,462063756,154906374,36099042,341766705,678182556,621882744,478771358,231881111,175889805,243630450,168908523,671961765,55761813,652682670,773939082,517628076,756201264,124604900,750976272,498253248,676047609,137170026,705610017,495032139,561797418,703097347,500815609,95984586,739707108,265613565,387099846,777331779,594676173,591219559,407997044,208947235,93337440,478908360,685013007,487033953,671903001,39521181,738490312,33785059,465470131,310453920,54648783,346831137,427694175,474743430,705296781,435828036,429824745,663532359,261388683,244690731,533997135,596108961,506813013,371892402,590145264,104733162,143420103,654339672,700348950,685038942,578826927,286484229,501639192,434962491,299270097,27702486,335375775,111746817,565603164,294926121,676063665,735862995,710035809,437011960,668528077,138765186,508213986,615036450,353784942,624827616,343900011,241289776,52410890,72018835,352406796,415705878,4802637,376367145,65589678,333633477,341834527,303717460,282387700,42951006,254706039,423048528,526429710,68131467,669954708,12787348,500636381,317959019,479433192,657133515,416259390,610216692,340129188,44594256,257373347,138718678,530767740,292922628,37220268,605295159,480722613,458170419,30540300,487159055,232966794,149150650],[412133651,386543325,139952108,289303402,102404925,317067177,396414708,80515854,663739304,317300809,228877044,493725043,715317967,490300965,315527373,743539734,488329191,553627998,533025234,242583957,706116537,614109258,645447222,523195911,492109128,722623041,111085128,766395126,654378921,691964847,496688157,399056049,654363234,102052314,191720088,473910948,259736526,332840025,388047555,665791056,627111387,139696515,441456687,443032569,283264821,771641703,452641455,511306362,117572859,127701891,721298331,176520078,357242229,611296308,696994956,405628839,429224274,465336054,695091546,689828796,574648641,351220905,507964023,675326610,517248963,453528621,220301928,494463186,681789969,339589656,44524053,417125457,339589404,747135963,341780733,734158215,396817281,21997836,5728464,147611205,456248898,714128667,377654949,3862068,128418948,589390074,304947090,11703825,228266073,127304142,429215724,361541124,521572968,468358191,341231688,65323503,613778508,15985323,291661029,410970006,591638112,349541550,89967528,224922159,361094166,584206074,640051812,324264456,652625388,693768537,11740617,309238398,211085469,194905872,639416484,110110707,296645895,748118511,131177718,511142751,775975599,421403409,475528473,434685258,1768977,80301375,708023862,569195676,56238084,632887668,88089750,631539342,396695565,38780154,695798271,469819224,439587099,69045921,682966116,112310856,64943298,534475872,40215357,389728458,286368453,736006257,501181650,54829908,603489402,338032656,512182818,627500097,462674016,3103092,157324491,43978329,596818971,259025598,9088632,91991781,577291428,211245489,429471231,142626330,172560633,510907446,444609585,758102058,375112647,744786693,276174402,19259856,233672418,745389414,225772848,23385663,324290610,519804558,120337812,402578568,360676008,450089262,551043738,337388940,512108856,28879011,690040638,106017282,558262341,99972432,608226003,612152037,42414435,776201013,39580443,518796945,494437752,583194366,723936555,415359657,309569589,751104774,166684527,249229170,353120823,130668327,753823584,580966092,561963717,543672234,393846327,586278000,327398400,278403867,156455586,363920382,190245195,290039148,547014447,466218648,146037150,585462906,666008595,691786683,374707494,622498779,231158277,685740951,115612245,681825249,545555745,551718468,277206615,640171035,757727334,195193908,658656684,457760646,225925875,505761984,18685233,506832921,112511021,396846646,290147622,113924623,669986155,336008070,63611061,238586775,119956662,616557739,772784623,334527774,410403148,51933421]]\nn,k=map(int,raw_input().split())\ni=0\nwhile 1<<i!=n:\n\ti+=1\nprint a[i][k-1]", "src_uid": "cfe19131644e5925e32084a581e23286"}
{"source_code": "n = input()\na = map(int, raw_input().split())\n\ndif = max([a[i+1]-a[i] for i in range(n-1)])\nprint max(dif, min([a[i+2]-a[i] for i in range(n-2)]))\n\n", "src_uid": "8a8013f960814040ac4bf229a0bd5437"}
{"source_code": "from sys import  stdin\nraw_input = stdin.readline\ndef fun(str1,str2,m,n): \n      \n    j = 0    # Index of str1 \n    i = 0    # Index of str2 \n      \n    # Traverse both str1 and str2 \n    # Compare current character of str2 with  \n    # first unmatched character of str1 \n    # If matched, then move ahead in str1 \n      \n    while j<m and i<n: \n        if str1[j] == str2[i]:     \n            j = j+1    \n        i = i + 1\n          \n    # If all characters of str1 matched, then j is equal to m \n    return j==m \ns=raw_input()\nt=raw_input()\nn,m=len(s),len(t)\nans=0\nfor i in xrange(n):\n    for j in xrange(i,n):\n        s1=s[:i]+s[j+1:]\n        n1=j-i+1\n        #print s1\n        if m<=n-n1 and fun(t,s1,m,n-n1):\n            ans=max(ans,n1)\nprint ans\n        \n", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f"}
{"source_code": "# import sys\n# sys.stdin=open(\"input.in\",\"r\")\n# sys.stdout=open(\"output.out\",\"w\")\nx=int(input())\ny=input()\ncount1=y.count('FS')\ncount2=y.count('SF')\nif(count2>count1):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n", "src_uid": "ab8a2070ea758d118b3c09ee165d9517"}
{"source_code": "import math\n#q=int(input())\nq=1\nfor _ in range(q):\n    s=(input())\n    t=(input())\n    n=len(s)\n    ans=\"\"\n    flag=False\n    for i in range(n):\n        if s[i]==t[i]:\n            ans+=s[i]\n            continue\n        elif ord(t[i])-ord(s[i])>1:\n            ans+=(chr(ord(s[i])+1))\n            k=(s[i+1:n])\n            if len(k)!=0:\n                ans+=(k)\n            flag=True\n            print(ans)\n            break\n        else:\n            ans1=ans\n            ans+=s[i]\n            for j in range(i+1,n):\n                if s[j]!='z':\n                    ans+=(chr(ord(s[j])+1))\n                    k=(s[j+1:n])\n                    if len(k)!=0:\n                        ans+=(k)\n                    flag=True\n                    break\n            if flag:\n                print(ans)\n                break\n            else:\n                flag=0\n                ans1+=chr(ord(s[i])+1)\n                for j in range(i+1,n):\n                    ans1+='a'\n                for j in range(i+1,n):\n                    if ord('a')<ord(t[j]):\n                        flag=1\n                        break\n                if flag==1:    \n                    print(ans1)\n                else:\n                    print(\"No such string\")\n                break", "src_uid": "47618510d2a17b1cc1e6a688201d51a3"}
{"source_code": "n=int(input())\ndef s(x):\n    return sum(int(i) for i in str(x))\nx=int(n**0.5)\ndiff=0 \nok=False \n\nwhile diff<=50 and x>=0:\n    if x*x+s(x)*x==n:\n        ok=True \n        ans=x \n        #break \n    diff+=1 \n    x-=1 \nif not ok:\n    print(-1)\nelse:\n    print(ans)", "src_uid": "e1070ad4383f27399d31b8d0e87def59"}
{"source_code": "from sys import stdin\n\nkDic = {c: i for i, c in enumerate(\"RGBYW12345\")}\n\nibuf = stdin.readlines()\ns = list(set(ibuf[1].split()))\nt = []\n\nfor i in xrange(len(s)):\n    for j in xrange(i + 1, len(s)):\n        t.append([0, 0])\n        if s[i][0] != s[j][0]:\n            t[-1][0] = (1 << kDic[s[i][0]]) | (1 << kDic[s[j][0]])\n        if s[i][1] != s[j][1]:\n            t[-1][1] = (1 << kDic[s[i][1]]) | (1 << kDic[s[j][1]])\n\nres = 10\nfor i in xrange(2 ** 10 - 1):\n    b = [(x & i) | (y & i) for x, y in t]\n    if 0 not in b:\n        res = min(res, bin(i).count(\"1\"))\nprint res", "src_uid": "3b12863997b377b47bae43566ec1a63b"}
{"source_code": "import sys\nimport math,bisect\nsys.setrecursionlimit(10 ** 6)\nfrom itertools import groupby,accumulate\nfrom heapq import heapify,heappop,heappush\nfrom collections import deque,Counter,defaultdict\ndef I(): return int(sys.stdin.readline())\ndef neo(): return map(int, sys.stdin.readline().split())\ndef Neo(): return list(map(int, sys.stdin.readline().split()))\ns = input()\nk = I()\nIMP = \"Impossible\"\nl0 = len(s) - 2*s.count(\"*\") - 2*s.count(\"?\")\nif l0 > k:\n    print(IMP)\n    exit()\nlans = l0\nans = \"\"\nfor c in s:\n    if c not in \"*?\":\n        ans = ans + c\n    elif c == \"*\":\n        ans = ans[:-1] + ans[-1]*(k-lans)\n        lans = k\n    else:  # if c == \"?\"\n        if lans >= k:\n            ans = ans[:-1]\n        else:\n            lans += 1\n\nif lans == k:\n    print(ans)\nelse:\n    print(IMP)\n\n        ", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"}
{"source_code": "n = int(input())\nk = [[0, 0, -1]]\ncnt = 0\nfor i in map(int, input().split()):\n    if i:\n        if k[-1][0] == i:\n            k[-1][1] += 1\n        else:\n            k.append([i, 1, cnt])\n    cnt += 1\ncnt = 0\nans = 0\nfor i in k[1:]:\n    ans += min(i[1], i[2] - cnt)\n    cnt += i[1]\nprint(ans)", "src_uid": "9135c7243431debb049f640e9600bc6e"}
{"source_code": "# -*- coding: utf-8 -*-\n\n__author__ = 'goran'\n\na, b = raw_input().split(' ')\n\ncandidates = []\n\nfor l in xrange(1, 64):\n    ones = '1' * l\n    for zero in xrange(1, len(ones)):\n        candidates.append(ones[:zero] + '0' + ones[zero + 1:63])\n\na = int(a)\nb = int(b)\ncount = 0\nfor i in candidates:\n    br = int(i, 2)\n\n    if br >= a and br <= b:\n        count += 1\n\nprint count", "src_uid": "581f61b1f50313bf4c75833cefd4d022"}
{"source_code": "try :\n    import sys\n    x, k = map(int, input().split(\" \"))\n    lengthList = []\n    lengthList = [int(p) for p in input().split(\" \") for _ in range(0, x)]\n    val = []\n    val = [n for n in lengthList if (float(k/n)).is_integer() == True]\n    y = max(val)\n    print(int(k/y))\nexcept OSError as err:\n    print(\"OS error: {0}\".format(err))\nexcept ValueError as ex:\n    print(\"Could not convert data to an integer.\")\n    print(\"value error: {0}\".format(ex))\nexcept:\n    print(\"Unexpected error:\", sys.exc_info()[0])\n    #raise", "src_uid": "80520be9916045aca3a7de7bc925af1f"}
{"source_code": "n, d = map(int, raw_input().split())\na = sum(map(int, raw_input().split()))\nprint (d - a) / 5 if a + (n - 1) * 10 <= d else -1\n", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"}
{"source_code": "from sys import *\ns=input()\nfor i in range(1,len(s)):\n    if s[i:]==s[:len(s)-i] and i<=(len(s)-1)//2:\n        print('YES')\n        print(s[i:])\n        exit(0)\nprint('NO')", "src_uid": "bfa78f72af4875f670f7adc5ed127033"}
{"source_code": "import math\nMOD = 10**9+7\n\nN,M,G = map(int,raw_input().split())\n\nif M == 0:\n    print int(G!=N%2)\n    exit()\nif M == 1:\n    ans = int(G!=N%2)\n    for i in xrange(N):\n        if i%2 == G:\n            ans += 1\n    print ans\n    exit()\n\nD = [0 for i in xrange(N+1)]\nD[0] = 1\nfor i in xrange(1,N+1):\n    D[i] = D[i-1]*(i+M-1)%MOD*pow(i,MOD-2,MOD)%MOD\nans = 0\nfor i in xrange(N+1):\n    if i%2 == G:\n        a,b = N-i,M-1\n        ans = (ans+D[a])%MOD\nprint ans\n", "src_uid": "066dd9e6091238edf2912a6af4d29e7f"}
{"source_code": "n = int(input())\nm = int(input())\ns = [int(input()) for _ in range(n)]\nma = max(s)+m\ns = sorted(s)\npp = max(s)\nfor i,e in enumerate(s):\n    s[i] += (pp-e)\n    m -= (pp-e)\n    if m<0:\n        t = abs(m)\n        s[i] -= t\n    if m<=0:\n        break\nmi = max(s)\nif m>0:\n    mi = s[0]+(m//len(s))+(1 if m%len(s)!=0 else 0)\nprint(mi,ma)", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d"}
{"source_code": "n, k = map(int, input().split())\nA = sum(list(map(int, input().split())))\nprint(max(2 * n * k - n - 2 * A, 0))", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900"}
{"source_code": "n = int(input())\n\nif 36 < n:\n    print(-1)\nelse:\n    ans = '8' * (n // 2) + '9' * (n % 2)\n    print(ans)\n", "src_uid": "0c9973792c1976c5710f88e3520cda4e"}
{"source_code": "n = int(input())\ns = str(input())\nhalf = n//2\nsit = s.count('x')\nstand = s.count('X')\nans = max(sit, stand) - half\nt = ans\nwhile ans!=0:\n    if sit>stand:\n        temp = s.index('x')\n        s = s[:temp] + 'X' + s[temp+1:]\n        sit = sit-1\n        stand = stand +1\n        ans = ans -1\n    else:\n        temp = s.index('X')\n        s = s[:temp] + 'x' + s[temp+1:]\n        sit = sit+1\n        stand = stand - 1\n        ans = ans -1\nprint(t)\nprint(s)", "src_uid": "fa6311c72d90d8363d97854b903f849d"}
{"source_code": "s = raw_input().strip()\nlens = len(s)\nc = [0 for _ in xrange(len(s))]\nm = list(s)\n# for ch in m:\n# \tprint ch,\n# print\n# for ci in c:\n# \tprint ci,\n# print\nfor i in range(lens):\n\tif i > 0:\n\t\tc[i] = c[i-1]\n\tif s[i] == 'Q':\n\t\tc[i] += 1\n# for ci in c:\n# \tprint ci,\n# print\nans = 0\nfor i in range(1,lens-1):\n\tif s[i] == 'A':\n\t\tans += (c[i-1]*(c[lens-1]-c[i-1]))\nprint ans", "src_uid": "8aef4947322438664bd8610632fe0947"}
{"source_code": "s = input().strip()\nrow = int(s[0: len(s) - 1])\ncol = s[len(s) - 1]\n\nm = {'f': 1, 'e': 2, 'd': 3, 'a': 4, 'b': 5, 'c': 6}\n\nprint((((row - 1) // 4) * (12 + 1 + 3)) + (((row - 1) % 2) * 7) + m[col])\n", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45"}
{"source_code": "from collections import namedtuple\n\n\nGlass = namedtuple('Glass', ['time_full', 'rates'])\nRate = namedtuple('Rate', ['start_time', 'rate'])\n\n\ndef solve(n, t):\n    p = [[None] * i for i in xrange(1, n + 1)]\n\n    def get_parents(row, col):\n        return [\n            p[r][c]\n            for r, c in [(row - 1, col), (row - 1, col - 1)]\n            if 0 <= c < row and p[r][c] is not None\n        ]\n\n    if t == 0:\n        return 0\n\n    p[0][0] = Glass(1.0, [Rate(1.0, 1.0)])\n\n    c = 1\n    for row in xrange(1, n):\n        for col in xrange(row + 1):\n            parents = get_parents(row, col)\n            # if len(parents) == 1:\n            #     assert len(parents[0].rates) == 1, (row, col, parents[0])\n            #\n            #     rate = parents[0].rates[0].rate / 2\n            #     time_full = parents[0].time_full + 1 / rate\n            #\n            #     if time_full > t:\n            #         continue\n            #\n            #     p[row][col] = Glass(time_full, [Rate(time_full, rate)])\n            #     c += 1\n            #\n            # elif len(parents) == 2:\n            if len(parents):\n\n                rates = sorted([r for i in parents for r in i.rates], key=lambda x: x.start_time)\n\n                share_full = 0\n                rate = 0\n                for i in xrange(len(rates) - 1):\n                    rate += rates[i].rate / 2\n                    new_share_full = share_full + rate * (rates[i+1].start_time - rates[i].start_time)\n                    if new_share_full >= 1:\n                        time_full = rates[i].start_time + (1 - share_full) / rate\n                        new_rates = [Rate(time_full, rate)] + map(lambda x: Rate(x.start_time, x.rate / 2), rates[i+1:])\n                        break\n                    else:\n                        share_full = new_share_full\n                else:\n                    rate += rates[-1].rate / 2\n                    time_full = rates[-1].start_time + (1 - share_full) / rate\n                    new_rates = [Rate(time_full, rate)]\n\n                if time_full > t:\n                    continue\n\n                p[row][col] = Glass(time_full, new_rates)\n\n                c += 1\n    # for i in p:\n    #     print i == list(reversed(i)), i\n    return c\n\n\n# print solve(3, 5)\n# print solve(4, 8)\n# print solve(10, 15)\n# print solve(10, 1022)\n\nn, t = map(int, raw_input().split())\nprint solve(n, t)\n\n", "src_uid": "b2b49b7f6e3279d435766085958fb69d"}
{"source_code": "input()\nX = input()\nParentheses, Outside, i = \"\", \"\", 0\nwhile i < len(X):\n    if X[i] == \"(\":\n        i, Parentheses = i + 1, Parentheses + \"_\"\n        while X[i] != \")\":\n            Parentheses, i = Parentheses + X[i], i + 1\n        Outside += \"_\"\n    else:\n        Outside += X[i]\n    i += 1\nOutside = Outside.split(\"_\")\nParentheses = Parentheses.split(\"_\")\nprint(len(max(Outside, key=len)), len(Parentheses) - Parentheses.count(\"\"))\n\n# UB_CodeForces\n# Advice: Life is not about finding yourself, it's about creating yourself\n# Location: At home behind my desk\n# Caption: Yeeeeaahhhh i got what i wanted\n# CodeNumber: 491\n", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92"}
{"source_code": "(n,k) = (int(i) for i in input().split())\nzapross = [int(i) for i in input().split()]\nlave = 0\ncurh = set()\nfor i in range(n):\n\tif zapross[i] in curh: continue\n\tif len(curh)!=k:\n\t\tlave+=1\n\t\tcurh.add(zapross[i])\n\telse:\n\t\tlpos = -1\n\t\tcc = -1\n\t\tfor j in curh:\n\t\t\ttry:\n\t\t\t\tpos = zapross[i+1:].index(j)\n\t\t\texcept ValueError:\n\t\t\t\tcc = j\n\t\t\t\tbreak\n\t\t\tif pos>lpos:\n\t\t\t\tlpos = pos\n\t\t\t\tcc = j\n\t\tcurh.remove(cc)\n\t\tcurh.add(zapross[i])\n\t\tlave+=1\nprint(lave)", "src_uid": "956228e31679caa9952b216e010f9773"}
{"source_code": "n,k,l,c,d,m,a,b=map(int,input().split())\nprint(min(k*l//a,c*d,m//b)//n)", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1"}
{"source_code": "def largest_no_pal(s):\n    if (not s or s != s[::-1] or (len(set(s)) == len(s) and len(s) != 1)):\n        return len(s)\n\n    temp_arr = []\n    \n    for i in range(len(s)):\n        for j in range(len(s)-1, i, -1):\n            temp = s[i:j+1]\n\n            if (temp != temp[::-1]):\n                temp_arr.append(temp)\n    \n    if (not temp_arr):\n        return 0\n    \n    return len(max(temp_arr, key=lambda x: len(x)))\n\ninp = input()\nprint(largest_no_pal(inp))", "src_uid": "6c85175d334f811617e7030e0403f706"}
{"source_code": "n=input()\nif n[0]==n[0].lower() and n[1:]==n[1:].upper():\n    print(n[0].upper()+n[1:].lower())\nelif n==n.upper():\n    print(n.lower())\nelse:\n    print(n)", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"}
{"source_code": "a,b,c=map(int,input().split())\ns=(a+b+c)//2\nif (a+b+c)%2 or s-a<0 or s-b<0 or s-c<0:print(\"Impossible\")\nelse:print(s-c,s-a,s-b)\n", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc"}
{"source_code": "n,m,k=map(int,input().split())\na,b=map(int,input().split())\np=[]\nfor i in range(1,n+1):\n    p.append(i*m*k)\nit=[[0]*n for i in range(m)]\nfor i in range(m):\n    for j in range(n):\n        it[i][j]=j*m*k+k*(i+1)\nfl1=True\nfl2=True\nfor i in range(n):\n    for j in range(m):\n        if it[j][i]-a>=0 and fl1:\n            p1=i+1\n            it1=j+1\n            fl1=False\n        if it[j][i]-b>=0 and fl2:\n            p2=i+1\n            it2=j+1\n            fl2=False\n        if not fl1 and not fl2:\n            break\nif p1!=p2:\n    t1=min(it1-1+10,5*(it1-1))\n    if p1>p2:\n        s1=p1\n        t21=0\n        while s1!=p2:\n            s1+=1\n            t21+=1\n            if s1>n:\n                s1//=n\n    else:\n        s1=p2\n        t21=0\n        while s1!=p1:\n            s1+=1\n            t21+=1\n            if s1>n:\n                s1//=n\n    t21*=15\n    t2=min(t21,(abs(p2-p1))*15)\n    t3=min(it2-1+10,5*(it2-1))\n    t=t1+t2+t3\n    print(t)\nelse:\n    t=min(abs(it2-it1)*5,10+abs(it2-it1))\n    print(t)\n\n", "src_uid": "c37b46851abcf7eb472869bd1ab9f793"}
{"source_code": "lr = input().split()\nl,r = [int(x) for x in lr]\n\nif l == r:\n    print(0)\n    \nelse:\n    a,b = list(bin(l)[2:]), list(bin(r)[2:])\n    if len(a) == len(b):\n        i = 0\n        while a[i] == b[i]:\n            i+=1\n        left = '1'*(len(a)-i)\n        print(int(left,2))\n    elif len(a) > len(b):\n        left = '1'*(len(a))\n        print(int(left,2))\n    else:\n        left = '1'*(len(b))\n        print(int(left,2))", "src_uid": "d90e99d539b16590c17328d79a5921e0"}
{"source_code": "data=list(map(int,input().split()))\nn=data[0]\nm=data[1]\nk=data[2]\npos=[1,1]\nif k<=n-1:\n    print(k+1,1)\nelse:\n    k-=n-1\n    ans=k//(m-1)\n    pos=k%(m-1)\n    if pos==0 and ans%2 ==0:\n        print(n-ans+1,2)\n    elif pos==0 and ans%2 !=0:\n        print(n-ans+1,m)\n    elif pos!=0 and ans%2 ==0:\n        print(n-ans,1+k%(2*m-2))\n    else:\n        print(n-ans,2+(2*m-2)-k%(2*m-2))\n", "src_uid": "e88bb7621c7124c54e75109a00f96301"}
{"source_code": "c=1; input(); l=sorted(set(map(int,input().split())))\nfor i in range(len(l)-1):\n\tif l[i+1]-l[i]==1:c+=1\n\telse:c=1\n\tif c==3:break\nprint([\"NO\",\"YES\"][c==3])", "src_uid": "d6c876a84c7b92141710be5d76536eab"}
{"source_code": "def dfs(v):\n    visit[v] = cnt\n    for u in vertex[v]:\n        if not visit[u] and u in challengers:\n            dfs(u)\n            \nn, m = map(int, input().split())\nvertex = [[] for i in range(n + 1)]\nchallengers = set()\nans = [''] * (n + 1)\nmiddle = set()\nfor i in range(m):\n    a, b = map(int, input().split())\n    vertex[a].append(b)\n    vertex[b].append(a)\n\nfor i in range(1, n + 1):\n    s = set(j for j in range(1, n + 1))\n    s.discard(i)\n    if s == set(vertex[i]):\n        ans[i] = 'b'\n        middle.add(i)\n    else:\n        challengers.add(i)\n \nvisit = [0] * (n + 1)\ncnt = 0\nfor c in challengers:\n    if not visit[c]:\n        cnt += 1\n        dfs(c)\n\nif cnt > 2 or cnt == 1:\n    print('No')\nelif cnt == 2:\n    first = set()\n    second = set()\n    for i in range(1, n + 1):\n        if visit[i] == 1:\n            first.add(i)\n        elif visit[i] == 2:\n            second.add(i)\n    for c in first:\n        s = first\n        s.discard(c)\n        if set(vertex[c]) - middle != s:\n            print('No')\n            break\n        s.add(c)\n    else:\n        for c in first:\n            ans[c] = 'a'\n        for c in second:\n            s = second\n            s.discard(c)\n            if set(vertex[c]) - middle != s:\n                print('No')\n                break\n            s.add(c)\n        else:\n            for c in second:\n                ans[c] = 'c'\n\nif not ans[1:].count(''):\n    print('Yes', ''.join(ans[1:]), sep = '\\n')", "src_uid": "e71640f715f353e49745eac5f72e682a"}
{"source_code": "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\ne = int(input())\nf = int(input())\nif min(a,d)*e+min(b,c,(d-min(a,d)))*f>=min(b,c,d)*f+min(a,d-(min(b,c,d)))*e:\n    print(min(a,d)*e+min(b,c,(d-min(a,d)))*f)\nelse:\n    print(min(b,c,d)*f+min(a,d-(min(b,c,d)))*e)", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a"}
{"source_code": "n = input()\nlength = len(n)\nif length % 2 == 1:\n    result = '4'*((length + 1) // 2) + '7'*((length + 1) // 2)\nelse:\n    half = length // 2\n    if n > half*'7' + half*'4':\n        result = (half + 1)*'4' + (half + 1)*'7' \n    elif n < half*'4' + half*'7':\n        result = half*'4' + half*'7'\n    else:\n        four_count = seven_count = half\n        for i in range(length):\n            digit = n[i]\n            if digit < '4':\n                    result = n[:i] + '4'*four_count + '7'*seven_count\n                    break\n            if digit < '7' and digit != '4':\n                if seven_count == 0:\n                    result = n[:nearest_four] + '7' + '4'*(four_count + 1)\n                    result += '7'*(length - len(result))\n                else:\n                    result = n[:i] + '7' + '4'*four_count + '7'*(seven_count - 1)\n                break\n            if digit > '7':\n                result = n[:nearest_four] + '7' + '4'*(four_count + 1) \n                result += '7'*(length - len(result))\n                break\n            if digit == '4':\n                nearest_four = i\n                four_count -= 1\n                if four_count < 0:\n                    result = n[:i] + '7'*seven_count\n                    break\n            if digit == '7':\n                seven_count -= 1\n                if seven_count < 0:\n                    result = n[:nearest_four] + '7' + '4'*(four_count + 1)\n                    result += '7'*(length - len(result))\n                    break\n            if four_count == 0 and seven_count == 0:\n                result = n                \n                break\nprint(result)", "src_uid": "77b5f83cdadf4b0743618a46b646a849"}
{"source_code": "a,b,c,d=input(),input(),input(),input()\na=len(a)-2\nb=len(b)-2\nc=len(c)-2\nd=len(d)-2\ne=False\nif 2*a<=c and 2*a<=b and 2*a<=d or a>=2*c and a>=2*b and a>=2*d: e='A'\nif 2*b<=a and 2*b<=c and 2*b<=d or b>=2*a and b>=2*c and b>=2*d:\n    if e==False:\n        e='B'\n    else:\n        e='C'\nif 2*c<=a and 2*c<=b and 2*c<=d or c>=2*a and c>=2*b and c>=2*d:\n    if e==False:\n        e='C'\n    else:\n        e='C'\nif 2*d<=a and 2*d<=b and 2*d<=c or d>=2*a and d>=2*b and d>=2*c:\n    if e==False:\n        e='D'\n    else:\n        e='C'\nif e==False: e='C'\nprint(e)", "src_uid": "30725e340dc07f552f0cce359af226a4"}
{"source_code": "F = {}\n\ndef f(k):\n    if not k in F:\n        s, i, j = 0, 4, 4\n        while i <= k:\n            s += i * f(k / i)\n            i += j + 1\n            j += 2\n        F[k] = (k * (k + 1)) / 2 - s\n    return F[k]\n\ndef g(k):\n    s, i, j = 0, 4, 4\n    while i <= k:\n        s += (i - 1) * f(k / i)\n        i += j + 1\n        j += 2\n    return (k * (k + 1)) / 2 - s\n\na, n = map(int, raw_input().split())\nprint g(a + n - 1) - g(a - 1)", "src_uid": "915081861e391958dce6ee2a117abd4e"}
{"source_code": "from itertools import permutations\nch=list(map(int,input().split()))\nop=list(input().split())\n\ndef f(oper, x, y):\n    if oper==\"*\":\n        return (x*y)\n    else:\n        return (x+y)\nans=10**12\nfor a,b,c,d in permutations(ch):\n    ans=min(ans, min(f(op[2], f(op[1], f(op[0],a,b), c), d), f(op[2], f(op[0],a,b),f(op[1],c,d))))\nprint(ans)\n", "src_uid": "7a66fae63d9b27e444d84447012e484c"}
{"source_code": "a, b, c = map(int, input().split())\nx, y, z = map(int, input().split())\ntenho = max(0, (a-x)//2) + max(0, (b-y)//2) + max(0, (c-z)//2)\nquero = abs(min(0, a-x) + min(0, b-y) + min(0, c-z))\nprint('Yes' if quero <= tenho else 'No')", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3"}
{"source_code": "n, k = map(int, input().split())\nif n >= k-1:\n    print((k-1)//2)\nelse:\n    print(max(n - k//2, 0))\n", "src_uid": "98624ab2fcd2a50a75788a29e04999ad"}
{"source_code": "n = int(input())\na = int(((4*n-3)**0.5-1-0.5)//2)\nfor i in range(1,a+1):\n    b = n-i*i-i-1\n    if b%(2*i)==0:\n        print(i,int(b/(2*i)))\n        exit(0)\nprint('NO')\n", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba"}
{"source_code": "from __future__ import division\nfrom fractions import gcd\n\nn, k = map(int, raw_input().split())\na, b = map(int, raw_input().split())\npos = [a + b, a - b, -a + b, -a - b]\n\nkn = k * n\nlow = 10e310\nhigh = -1\n\nfor dif in pos:\n    l = dif\n    for _ in xrange(n):\n        res = kn // gcd(l, kn)\n        if res < low:\n            low = res\n        if res > high:\n            high = res\n        l += k\n\nprint \"{} {}\".format(low, high)\n", "src_uid": "5bb4adff1b332f43144047955eefba0c"}
{"source_code": "k= input()\nm=str(k)\ns=False;\ncount=0\n\nfor n in range (0,m.__len__()):\n  if(m[n]=='4' or m[n]=='7'):\n\n      count+=1\n\n\nif(count==m.__len__()):\n    print \"YES\"\nelif(k% 4==0 or k% 7==0 or k% 47==0 or k% 74==0):\n    print \"YES\"\nelse:\n         print \"NO\"\n", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"}
{"source_code": "#!/usr/bin/env python\n# -*- coding: UTF-8 -*-\n\nimport sys\n\nMAXN = 110\nMOD = 10 ** 9 + 7\nINF = MOD\n\ndef MakeCom():\n\tglobal com\n\tcom = [[1]]\n\tfor i in xrange(1, MAXN + 1):\n\t\tline = [1]\n\t\tfor j in xrange(1, i):\n\t\t\tline.append((com[-1][j - 1] + com[-1][j]) % MOD)\n\t\tline.append(1)\n\t\tcom.append(line)\n\ndef ReadIn():\n\tdata = [int(x) for x in sys.stdin.read().split()]\n\toffset = 0\n\twhile offset < len(data):\n\t\tn, cap = data[offset : offset + 2]\n\t\toffset += 2\n\t\tfriends = [0] * 2\n\t\tfor x in data[offset : offset + n]:\n\t\t\tfriends[x / 50 - 1] += 1\n\t\toffset += n\n\t\tcap /= 50\n\t\tyield cap, tuple(friends)\n\ndef Solve(cap, friends):\n\tf = {friends : 1}\n\tfor rides in xrange(sum(friends) * 5):\n\t\tif rides & 1 and friends in f:\n\t\t\tprint rides\n\t\t\tprint f[friends]\n\t\t\treturn\n\t\tpf, f = f, {}\n\t\tfor remain in pf:\n\t\t\tfor x in xrange(remain[0] + 1):\n\t\t\t\tif x > cap: break\n\t\t\t\tfor y in xrange(remain[1] + 1):\n\t\t\t\t\tif x + y < 1: continue\n\t\t\t\t\tif x + 2 * y > cap: break\n\t\t\t\t\tnextRem = tuple(total - left + move\n\t\t\t\t\t\t\tfor total, left, move in zip(friends, remain, (x, y)))\n\t\t\t\t\tf[nextRem] = (f.get(nextRem, 0) + com[remain[0]][x] * com[remain[1]][y] * pf[remain]) % MOD\n\t\n\tprint -1\n\tprint 0\n\n\nif __name__ == '__main__':\n\tMakeCom()\n\tfor cap, friends in ReadIn():\n\t\tSolve(cap, friends)\n", "src_uid": "ebb0323a854e19794c79ab559792a1f7"}
{"source_code": "n=map(lambda x:ord(x)-ord('0'),list(raw_input()))\nM=10**9+7\nc=[0]*32\ns=0\nk=len(n)\ndef acc(k,s,v):\n  if k>0:\n    acc(k-1,s+1,v*2)\n    acc(k-1,s,v*8)\n  else:\n    c[s]+=v\nfor i in range(k):\n  for j in range(n[i]):\n    acc(k-i-1,s+(j in (4,7)),1)\n  s+=n[i] in (4,7)\nc[s]+=1\nc[0]-=1\ndef win(u,v,w):\n  x=0\n  if v<10:\n    if u<6:\n      for i in range(11):\n        if c[i]>0:\n          c[i]-=1\n          x=(x+win(u+1,v+i,w*(c[i]+1)%M))%M\n          c[i]+=1\n    else:\n      for i in range(v+1,10):\n        x=(x+w*c[i])%M\n  return x\nprint win(0,0,1)\n\n", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9"}
{"source_code": "class A:\n\n    def solve(self):\n        board = []\n        for i in range(8):\n            board.append(input())\n\n        painted_black = [[0 for i in range(8)] for j in range(8)]\n\n        strokes = 0\n        for i in range(8):\n            if len(set(board[i])) == 1 and 'B' in set(board[i]):\n                strokes += 1\n                painted_black[i] = [1 for i in range(8)]\n\n        for i in range(8):\n            if len(set([board[x][i] for x in range(8)])) == 1 and \\\n               'B' in set([board[x][i] for x in range(8)]) and \\\n               0 in set([painted_black[x][i] for x in range(8)]):\n                strokes += 1\n\n        print(strokes)\n\nA().solve()\n", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0"}
{"source_code": "# n = int(input())\n# tn = [int(i) for i in input().split()]\n\n# def f(m):\n\n\n# m = 0\n# l = 0\n# r = n\n\n# while l < r:\n#     m = (l + r)//2\n    \n\nn = int(input())\np = []\n\nfor i in range(n):\n\tp.append(1)\n\twhile len(p) >= 2 and p[-1] == p[-2]: \n\t\tp[-2] += 1\n\t\tp.pop()\n\nfor i in p: print(i, end=\" \")", "src_uid": "757cd804aba01dc4bc108cb0722f68dc"}
{"source_code": "M=10**9+7\nn,k=map(int,raw_input().split())\nprint ((n-k)**(n-k))%M*(k**(k-1))%M", "src_uid": "cc838bc14408f14f984a349fea9e9694"}
{"source_code": "def board (arr):\n    for i in range (8):\n        for j in range (8):\n            print arr[i][j],\n        print\ndef rokh_tahdid (arr,xy):\n    for i in range (8):\n        for j in range (8):\n            if (xy[0] == i or xy[1] == j) and xy != [i,j]:\n                arr[i][j]=1\n    return arr\ndef asb_tahdid (arr,x,y):\n    def inboard (n):\n        if n >= 0 and n <= 7:\n            return True\n        else:\n            return False\n    if inboard (x-2) and inboard (y-1):\n        arr[x-2][y-1] = 3\n\n    if inboard (x-2) and inboard (y+1):\n        arr[x-2][y+1] = 3\n\n    if inboard (x-1) and inboard (y-2):\n        arr[x-1][y-2] = 3\n\n    if inboard (x-1) and inboard (y+2):\n        arr[x-1][y+2] = 3\n        \n    if inboard (x+2) and inboard (y-1):\n        arr[x+2][y-1] = 3\n\n    if inboard (x+2) and inboard (y+1):\n        arr[x+2][y+1] = 3\n\n    if inboard (x+2) and inboard (y-2):\n        arr[x+1][y-2] = 3\n\n    if inboard (x+2) and inboard (y+2):\n        arr[x+1][y+2] = 3\ndef new_tahdid (arr,x,y):\n    def inboard (n):\n        if n >= 0 and n <= 7:\n            return True\n        else:\n            return False\n    point = 0\n    total = 0\n    if inboard (x-2) and inboard (y-1):\n        if arr[x-2][y-1] == 2:\n            total += 1\n        else:\n            point += 1\n            total += 1\n\n    if inboard (x-2) and inboard (y+1):\n        if arr[x-2][y+1] == 2:\n            total += 1\n        else:\n            point += 1\n            total += 1\n            \n    if inboard (x-1) and inboard (y-2):\n        if arr[x-1][y-2] == 2:\n            total += 1\n        else:\n            point += 1\n            total += 1\n\n    if inboard (x-1) and inboard (y+2):\n        if arr[x-1][y+2] == 2:\n            total += 1\n        else:\n            point += 1\n            total += 1\n            \n    if inboard (x+2) and inboard (y-1):\n        if arr[x+2][y-1] == 2:\n            total += 1\n        else:\n            point += 1\n            total += 1\n            \n    if inboard (x+2) and inboard (y+1):\n        if arr[x+2][y+1] == 2:\n            total += 1\n        else:\n            point += 1\n            total += 1\n    if inboard (x+1) and inboard (y-2):\n        if arr[x+1][y-2] == 2:\n            total += 1\n        else:\n            point += 1\n            total += 1\n        \n    if inboard (x+1) and inboard (y+2):\n        if arr[x+1][y+2] == 2:\n            total += 1\n        else:\n            point += 1\n            total += 1\n    return point == total     \narr=[]\nfor i in range (8):\n    arr.append([0,0,0,0,0,0,0,0])\nj='abcdefgh'\nR=raw_input()\nA=raw_input()\nr=[j.index(R[0]),int(R[1])-1]\na=[j.index(A[0]),int(A[1])-1]\n\narr[r[0]][r[1]] = 2\narr[a[0]][a[1]] = 2\nrokh_tahdid (arr,r)\nasb_tahdid (arr,a[0],a[1])\nc0 = 0\nfor i in range (8):\n    for j in range (8):\n        if arr[i][j] == 0:\n            if new_tahdid (arr,i,j):\n                c0+=1\nelse:\n    print c0\n", "src_uid": "073023c6b72ce923df2afd6130719cfc"}
{"source_code": "n = int(raw_input())\narr = map(int, raw_input().split(\" \"))\n\narr.sort()\n\nif len(arr) == 1:\n    print arr[0]\nelse:\n    print (arr[0] + arr[-1]) // 2\n", "src_uid": "f03773118cca29ff8d5b4281d39e7c63"}
{"source_code": "n = int(input())\n\ndef pow2 (x):\n    r = 1\n    while (x > 0):\n        x-=1\n        r*=2\n    return r\n\n# Using DP bottom_up technic to\n# calculate answer to powers of\n# two n\ndef val_pow_2 (x):\n    lst = []\n    lst.append(0)\n    for i in range(x):\n        lst.append(2*lst[i]+pow2(i))\n    return lst\n\n# Maximum expoent of power of two\n# smaller than x\ndef lg2 (x):\n    r = 0;\n    ans = 1;\n    while (x > 1):\n        x = int(x/2)\n        ans *= 2\n        r+=1\n    return r\n\n# Maximum power of two smaller\n# than x\ndef max_pow_2 (x):\n    ans = 1;\n    while (x > 1):\n        x = int(x/2)\n        ans *= 2\n    return ans\n\ndef func (x, lst):\n    if (bin(x).count(\"1\") == 1):\n        return lst[lg2(x)]\n    elif (x == 0):\n        return 0\n    else:\n        y = max_pow_2 (x)\n        return lst[lg2(y)] + y + func (x-y, lst)\n\nlst = val_pow_2 (int(lg2(n)))\n#for i in range(len(lst)):\n#    if (pow2(i) > 1e12):\n#        break\n#    print (str(pow2(i)) + \": \" + str(lst[i]))\n\nprint (func (n, lst))\n", "src_uid": "a98f0d924ea52cafe0048f213f075891"}
{"source_code": "n,k,t=map(int,input().split())\nif(t<k):\n    print(t)\nelif(t>=k and t<=n):\n    print(k)\nelse:\n    print(k-(t-n))", "src_uid": "7e614526109a2052bfe7934381e7f6c2"}
{"source_code": "n = input()\nc=0\nv=0\nfor i in range(int(input())):\n    s = input()\n    if(n[0]==s[1]): c+=1\n    if(n[1]==s[0]): v+=1\n    if(n==s):   \n        c+=1\n        v+=1\nprint(\"YES\" if(c and v) else \"NO\")", "src_uid": "cad8283914da16bc41680857bd20fe9f"}
{"source_code": "n = int(input())\n\nans = 0\nwhile n:\n    n >>= 1\n    ans += 1\n\nprint(ans)", "src_uid": "95cb79597443461085e62d974d67a9a0"}
{"source_code": "s=raw_input()\nprint s[0].upper()+s[1:]\n#string.capitalize", "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"}
{"source_code": "a, b = map(int, raw_input().split())\na, b = min(a, b), max(a, b)\nif b % a == 0:\n    print(0)\n    exit(0)\nx = b - a\ndels = set()\nfor i in range(1, int(x ** 0.5) + 1):\n    if x % i == 0:\n        dels.add(i)\n        dels.add(x // i)\ndels = list(dels)\nj = 10 ** 20\nfor i in dels:\n    if i >= a:\n        j = min(j, i - a)\nprint(min((x % a - a) % x, j))\n", "src_uid": "414149fadebe25ab6097fc67663177c3"}
{"source_code": "n = int(input())\nw = list(map(int, input().split()))\nw.sort()\nans = []\nfor i in range(2 * n):\n    for j in range(i+1, 2 * n):\n        m = w[0:i] + w[i+1:j] + w[j+1:]\n        var = sum(m[1::2]) - sum(m[::2])\n        ans.append(var)\nprint(min(ans))", "src_uid": "76659c0b7134416452585c391daadb16"}
{"source_code": "def pab(l,n):\n    c=0\n    i=0\n    while(n>0):\n        \n        n=n-l[i]\n        c=c+1\n        \n        if(i==6):\n            i=0\n        else:\n            i=i+1\n    z=c%7\n    if(z==0):\n        print(7)\n    else:\n        print(z)\n    return\nn=int(input())\nt=input()\nl=list(map(int,t.split(' ')))\npab(l,n)", "src_uid": "007a779d966e2e9219789d6d9da7002c"}
{"source_code": "n = int(input())\nans = 1\nfor i in range(1, n+1):\n    ans *= i\n    ans %= (10**9 + 7)\n\nans += (10**9 + 7)\n\nprint((ans - (2**(n-1)%(10**9 + 7))) % (10**9 + 7))\n", "src_uid": "3dc1ee09016a25421ae371fa8005fce1"}
{"source_code": "INF = float('inf')\n\ndef isSqrt(s):\n    if s[0] == '0':\n        return False\n    n = int(s)\n    m = 0\n    while m * m <= n:\n        if m * m == n:\n            return True\n        m += 1\n    return False\n\ns = list(input())\nn = len(s)\nret = INF\nfor mask in range((1 << n) - 1):\n    t = s[::]\n    for i in range(n):\n        if (mask >> i) & 1 == 1:\n            t[i] = ''\n    if isSqrt(''.join(t)):\n        ret = min(ret, bin(mask).count('1'))\nprint(ret if ret != INF else -1)", "src_uid": "fa4b1de79708329bb85437e1413e13df"}
{"source_code": "a, b, x = map(int, input().split())\nans = \"\"\nfor i in range((x + 1) // 2):\n\tans += \"10\"\n\ta -= 1\n\tb -= 1\nansw = \"\"\nif x % 2 == 1:\n\tansw = ('1' * b + ans + '0' * a)\nelse:\n\t#print(a, b)\n\tif a > 0:\n\t\tansw = ('0' + '1' * b + ans + '0' * (a - 1))\n\telse:\n\t\tansw = (ans + '1' * b)\nprint(answ)\n", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c"}
{"source_code": "n = int(input())\na = list(map(int,input().split()))\nb = sorted(a)\nk = 1\nwhile k:\n    k = 0\n    for i in range(1,len(b)):\n        if b[i] - b[0] > 0:\n            if b[i] % b[0] > 0:\n                b[i] = b[i] % b[0]\n            else:\n                b[i] = b[0]\n            k = 1\n    b = sorted(b)\nprint (sum(b))", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"}
{"source_code": "n = int(input())\ndisjointSet = [-1] * n\ndef root(x, level=200):\n    dp = []\n    while disjointSet[x] >= 0:\n        dp.append(x)\n        x = disjointSet[x]\n    for i in dp:\n        disjointSet[i] = x\n    return x\n\ndef join(x, y):\n    r1, r2 = root(x), root(y)\n    if r1 == r2:\n        return\n    disjointSet[r2] = r1\n\npoints = []\nvertPoints = {}\nhorizPoints = {}\nfor i in range(n):\n    a, b = map(int, input().split())\n    points.append((a, b))\n    if a in vertPoints:\n        join(i, vertPoints[a])\n    else:\n        vertPoints[a] = i\n    if b in horizPoints:\n        join(i, horizPoints[b])\n    else:\n        horizPoints[b] = i\n        \nsets = {}\nfor i in range(n):\n    r = root(i)\n    if r in sets:\n        sets[r].append(points[i])\n    else:\n        sets[r] = [points[i]]\n\nans = 1\nfor i in sets:\n    s = sets[i]\n    horiz = [x for x,y in s]\n    vert = [y for x,y in s]\n    tmp = len(set(horiz)) + len(set(vert))\n    if tmp <= len(s):\n        ans *= 2 ** tmp\n    else:\n        ans *= 2 ** tmp - 1\n    ans %= 10 ** 9 + 7\n\nprint(ans % (10 ** 9 + 7))", "src_uid": "8781003d9eea51a509145bc6db8b609c"}
{"source_code": "k,n,s,p= map(int,input().split())\nt=(n+s-1)//s\nsheets=k*t\nprint((sheets+p-1)//p)\n", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780"}
{"source_code": "a,b,c,d=input().split()\ndef tri(q,w,e):\n    if(q<w+e):\n        \n        if(w<q+e):\n            if(e<q+w):\n                k=1\n                return k\n            elif(e==q+w):\n                k=2\n                return k\n            else:\n                return 0\n        else:\n            if(w==q+e):\n                if(e<q+w):\n                 k=2\n                 return k\n            elif(e==q+w):\n                 k=2\n                 return k\n            else:\n                return 0\n    elif(q==w+e):\n        if(w<q+e):\n            if(e<q+w):\n                k=2\n                return k\n            elif(e==q+w):\n                k=2\n                return k\n            else:\n                return 0\n        else:\n            if(w==q+e):\n                if(e<q+w):\n                 k=2\n                 return k\n            elif(e==q+w):\n                 k=2\n                 return k\n            else:\n                return 0\n    else:\n        return 0\n           \nz=[]\na=int(a)\nb=int(b)\nc=int(c)\nd=int(d)\nl=tri(a,b,c)\nz.append(l)\nl=tri(a,b,d)\nz.append(l)\nl=tri(a,c,d)\nz.append(l)\nl=tri(c,b,d)\nz.append(l)\nif(1 in z):\n    print(\"TRIANGLE\")\nelif(2 in z):\n    print(\"SEGMENT\")\nelse:\n    print(\"IMPOSSIBLE\")\n\n\n\n\n    \n\n", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a"}
{"source_code": "mod=10**9+7\nf=[0]*500000\n\ndef POW(a,b):\n\tif(b==0):\n\t\treturn 1\n\tif(b&1):\n\t\treturn POW(a,b//2)**2*a%mod\n\telse:\n\t\treturn POW(a,b//2)**2\n\ndef C(n,m):\n\tif(m>n):\n\t\treturn 0\n\tt=f[n]*POW(f[m],mod-2)%mod*POW(f[n-m],mod-2)%mod\n\treturn t\n\n\nf[0]=1\nfor i in range(1,500000):\n\tf[i]=f[i-1]*i%mod\na,b,k,t=map(int,input().split(' '))\n\nans=0\nfor i in range(0,2*t+1):\n\tt1=POW(-1,i)*C(2*t,i)%mod\n\tt2=(C(210000+2*k*t-a+b+2*t-1-(2*k+1)*i+1,2*t)-C(1+2*k*t-a+b+2*t-1-(2*k+1)*i,2*t))%mod\n\tans=(ans+t1*t2)%mod\nprint(ans)\n", "src_uid": "8b8327512a318a5b5afd531ff7223bd0"}
{"source_code": "def solve():\n    n = int(input()) \n    div, rem, s, rem_s = n//4, n%4, 'GBIV', ''\n    if rem != 0: rem_s = s[:rem]\n    print('ROY' + (div * s)[3:] + rem_s)\nsolve() ", "src_uid": "dc3817c71b1fa5606f316e5e94732296"}
{"source_code": "\nn,pos,L,R=map(int,raw_input().split())\n\n\ndef tc(n,pos,L,R):\n    ct=0\n    if L==1 and R==n:\n        return 0\n    elif R==n:\n        if pos<=L:\n            return L-pos+1\n        else:\n            return pos-L+1\n    elif L==1:\n        if pos>=R:\n            return pos-R+1\n        else:\n            return R-pos+1\n    elif L>1 and R<n:\n        if pos<=L:\n            return R-pos+2\n        elif pos>=R:\n            return pos-L+2\n        elif L<pos<R:\n            return min(pos+R-2*L,2*R-pos-L)+2\n\n\n\nprint tc(n,pos,L,R)\n\n\n\n\n\n\n\n\n", "src_uid": "5deaac7bd3afedee9b10e61997940f78"}
{"source_code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Oct 16 15:27:18 2013\n\n@author: Praveen Kumar\n\"\"\"\n\nm = int(input())\na = input().split()\na = list(map(int,a))\nb = input().split()\nb = list(map(int,b))\nx = b[0]\ny = b[1]\n\n\ndef main():\n    \n    c1 = 0\n    c2 = sum(a)    \n    \n    for e,i in enumerate(a):\n        #print(e,i)\n        c1 += i\n        c2 -= i\n        if x <= c1 and c1 <=y and x <= c2 and c2 <= y:\n            print(e+2)\n            return\n    print(0)\n              \nmain()", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"}
{"source_code": "x1,y1,x2,y2=[int(i) for i in input().split()]\nx,y=[int(i) for i in input().split()]\nif x1%x==x2%x and y1%y==y2%y and (x2-x1)//x%2==(y2-y1)//y%2:\n    print('YES')\nelse: print('NO')\n#print((x2-x1)//x,(y2-y1)//y)", "src_uid": "1c80040104e06c9f24abfcfe654a851f"}
{"source_code": "import math\nF=lambda x:math.factorial(x)\nn,w,b=map(int,raw_input().split())\nprint (F(w)*F(b)*(w-1)*F(w+b-3)/F(n-3)/F(w+b-n))%1000000009\n\n\n", "src_uid": "63e93a161bbff623323e66c98d5e20ac"}
{"source_code": "import sys\n\nf1, f2 = map(int, sys.stdin.readline().split())\nn = int(sys.stdin.readline())\n\nf3 = f2 - f1\nf4 = -f1\nf5 = -f2\nf6 = -f3\nf = [f6, f1, f2, f3, f4, f5]\nprint((f[n%6]) % (10**9 + 7))\n", "src_uid": "2ff85140e3f19c90e587ce459d64338b"}
{"source_code": "x, y, z = list(map(int, input().split(' ')))\n\ntmp = abs(x - y)\n\nif tmp == z == 0:\n    print(0)\nelif tmp > z:\n    if x > y:\n        print('+')\n    else:\n        print('-')\nelse:\n    print('?')", "src_uid": "66398694a4a142b4a4e709d059aca0fa"}
{"source_code": "a, b, c=map(int, input().split())\nprint(3*min(a+1,b, c-1))\n  \n\n", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5"}
{"source_code": "from sys import stdin\nfrom itertools import repeat\ndef main():\n    a, b, h, w, n = map(int, stdin.readline().split())\n    m = map(int, stdin.readline().split(), repeat(10, n))\n    m.sort(reverse=True)\n    m += [1] * 38\n    def go(dep, c, hh, ww, a, b):\n        if dep >= 19:\n            if ww < a and ww < b:\n                return 999\n            for i in xrange(19):\n                if hh >= a and ww >= b:\n                    return c + i\n                if ww >= a and hh >= b:\n                    return c + i\n                hh *= m[i+19]\n            return 999\n        if hh >= a and ww >= b:\n            return c\n        if ww >= a and hh >= b:\n            return c\n        k1 = k2 = 999\n        if b > hh or hh < a:\n            k1 = go(dep + 1, c + 1, hh * m[dep], ww, a, b)\n        if b > ww or ww < a:\n            k2 = go(dep + 1, c + 1, hh, ww * m[dep], a, b)\n        if k1 < k2:\n            return k1\n        else:\n            return k2\n    ans = go(0, 0, h, w, a, b)\n    if ans == 999:\n        ans = -1\n    print ans\nmain()\n", "src_uid": "18cb436618b2b85c3f5dc348c80882d5"}
{"source_code": "n,a=raw_input(),map(int,raw_input().split(' '))\ns=[]\nans=0\nfor i in a:\n    while len(s)>1 and s[-1]<=i and s[-2]>=s[-1]:\n        ans+=min(i,s[-2])\n        del(s[-1])\n    s.append(i)\ns.sort()\nprint ans+sum(s[0:-2])\n", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1"}
{"source_code": "b,r = [raw_input() for _ in xrange(6)],[]\ndef x(i,d,c='RL'): b[i]=b[i][-d:]+b[i][:-d];r.extend([c[d>3]+str(i+1)]*(d if d<3 else 6-d))\ndef y(i,d): global b;b=zip(*b);x(i,d,'DU');b=zip(*b)\ndef u(i,j): x(j,1);y(i,1);x(j,5);y(i,5)\ndef p(i,j): u(i,j);x((j+5)%6,1);u((i+1)%6,j);x((j+5)%6,5);u(i,j);u(i,j)\ndef l(i,j): p((i+1)%6,j);p((i+3)%6,j);x(j,1)\nfor k,c in enumerate(sorted(''.join(b))):\n    ii,jj=k%6,k/6\n    z = filter(lambda x: c in x, b)[0]    \n    i,j=z.index(c),b.index(z)\n    while i!=ii: l(i,j); i=(i+5)%6\n    while j>jj: u(ii,j); j-=1\nprint len(r)\nprint '\\n'.join(r)", "src_uid": "10b2c1c53580dd382c41a56f7413e709"}
{"source_code": "import sys\nrange = xrange\ninput = raw_input\n\nA = [0 if c == '(' else 1 for c in input()]\nB = [0 if c == '(' else 1 for c in input()]\n\nn = len(A)\nm = len(B)\n\nbig = 10**8\n\nDP = [[[big]*201 for _ in range(n + 1)] for _ in range(m + 1)]\nDP[0][0][0] = 0\nway = [[[-1]*201 for _ in range(n + 1)] for _ in range(m + 1)]\n\nfor j in range(m + 1):\n    for i in range(n + 1):\n        DPji = DP[j][i]\n        iprim = i + (i < n and A[i] == 1)\n        jprim = j + (j < m and B[j] == 1)\n        for k in reversed(range(1, 201)):\n            val = DPji[k] + 1\n            if DP[jprim][iprim][k - 1] > val:\n                DP[jprim][iprim][k - 1] = val\n                way[jprim][iprim][k - 1] = 1\n        \n        iprim = i + (i < n and A[i] == 0)\n        jprim = j + (j < m and B[j] == 0)\n        for k in range(200):\n            val = DPji[k] + 1\n            if DP[jprim][iprim][k + 1] > val:\n                DP[jprim][iprim][k + 1] = val\n                way[jprim][iprim][k + 1] = 0\n        \n        iprim = i + (i < n and A[i] == 1)\n        jprim = j + (j < m and B[j] == 1)\n        for k in reversed(range(1, 201)):\n            val = DPji[k] + 1\n            if DP[jprim][iprim][k - 1] > val:\n                DP[jprim][iprim][k - 1] = val\n                way[jprim][iprim][k - 1] = 1\nans = []\n\ni = n\nj = m\nk = 0\ncounter = 0\nwhile i != 0 or j != 0 or k != 0:\n    counter += 1\n    c = way[j][i][k]\n    ans.append(c)\n    val = DP[j][i][k] - 1\n    k += 1 - 2 * (c == 0)\n\n    matchi = +(i > 0 and A[i - 1] == c)\n    matchj = +(j > 0 and B[j - 1] == c)\n    \n    if DP[j][i][k] == val:\n        pass\n    elif matchi and DP[j][i - 1][k] == val:\n        i -= 1\n    elif matchj and DP[j - 1][i][k] == val:\n        j -= 1\n    else:\n        i -= 1\n        j -= 1\n\n#print DP[m][n][0]\nprint ''.join('(' if x == 0 else ')' for x in reversed(ans))\n", "src_uid": "cc222aab45b3ad3d0e71227592c883f1"}
{"source_code": "n = int(input())\ns = input() \n\nmat = [[[int(0),int(0),\"\"] for _i in range(n+1)] for _j in range(n+1)]\n\n\n\n\nfor i in range(2*n):\n\tdigit = int(s[i])\n\ttoIter = min(i,n)\n\n\tminh = max(i-n,0)\n\tmaxh = min(n,i)\n\n\tfor m in range(minh,maxh+1):\n\t\th = i - m\n\t\tv = mat[h][m]\n\n\t\tif h < n:\n\t\t\t#add current symbol to homer\n\t\t\tvnext = mat[h+1][m];\n\t\t\tsumhmn = vnext[0]*pow(10,(2*n-h-2)) + vnext[1]*pow(10,(2*n-m-1));\n\t\t\tsumhm = (v[0]*10+digit)*pow(10,(2*n-h-2)) + v[1]*pow(10,(2*n-m-1));\n\t\t\tif sumhm >= sumhmn :\n\t\t\t\tvnext[0]=v[0]*10+digit\n\t\t\t\tvnext[1]=v[1]\n\t\t\t\tvnext[2]=v[2]+'H'\n\t\tif m < n:\n\t\t\t#add current symbol to marge\n\t\t\tvnext = mat[h][m+1];\n\t\t\tsumhmn = vnext[0]*pow(10,(2*n-h-1)) + vnext[1]*pow(10,(2*n-m-2));\n\t\t\tsumhm = v[0]*pow(10,(2*n-h-1)) + (v[1]*10+digit) * pow(10,(2*n-m-2));\n\t\t\tif sumhm >= sumhmn :\n\t\t\t\tvnext[0]=v[0]\n\t\t\t\tvnext[1]=v[1]*10+digit\n\t\t\t\tvnext[2]=v[2]+'M'\n\t\n\n\nprint(mat[n][n][2])\n\t\t\t\n\n\n", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88"}
{"source_code": "from collections import deque\r\n\r\ndef restore(a, log):\r\n  n = len(a)\r\n  b = [0 for i in range(n)]\r\n\r\n  def mergeSort(l, r):\r\n    if r - l <= 1:\r\n      return\r\n    m = (l + r) >> 1\r\n    mergeSort(l, m)\r\n    mergeSort(m, r)\r\n    i, j, k = l, m, l\r\n    while i < m and j < r:\r\n      if log.popleft() == '0':\r\n        b[k] = a[i]\r\n        i += 1\r\n      else:\r\n        b[k] = a[j]\r\n        j += 1\r\n      k += 1\r\n    while i < m:\r\n      b[k] = a[i]\r\n      i += 1\r\n      k += 1\r\n    while j < r:\r\n      b[k] = a[j]\r\n      j += 1\r\n      k += 1\r\n    for p in range(l, r):\r\n      a[p] = b[p]\r\n\r\n  mergeSort(0, n)\r\n\r\n  return len(log) == 0, a\r\n    \r\n\r\nlog = input()\r\n\r\nflag, n = False, 2\r\nwhile not flag and n <= 10**3:\r\n    try:\r\n        flag, p = restore([i for i in range(n)], deque(log))\r\n    except:\r\n        flag = False\r\n    n += 1\r\n\r\nA = [None] * len(p)\r\nfor i in range(len(p)):\r\n    A[p[i]] = i + 1\r\n\r\nprint(len(A))\r\nprint(\" \".join(str(a) for a in A))\r\n", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8"}
{"source_code": "#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright © 2016 missingdays <missingdays@missingdays>\n#\n# Distributed under terms of the MIT license.\n\n\"\"\"\n\n\"\"\"\n\nn = int(input())\n\na = [int(i) for i in input().split()]\n\ni = 0\nansw = n\nc = 0\n\nwhile i < n and a[i] == 0:\n    i += 1\n    answ -= 1\n\nif i == n:\n    print(0)\n    exit()\n\nwhile i < n:\n    if a[i] == 0:\n        c += 1\n    else:\n        if c > 1:\n            answ -= c\n        c = 0\n    i += 1\n    \nansw -= c\n\nprint(answ)\n", "src_uid": "2896aadda9e7a317d33315f91d1ca64d"}
{"source_code": "a, b = map(int, input().split())\nimport math\ng = math.gcd(a, b)\na, b = a//g, b//g\ncnt = 0\nfor i in [2,3,5]:\n    while(a%i == 0):\n        a //= i\n        cnt += 1\n    while(b%i == 0):\n        b //= i\n        cnt += 1\nif a-1 or b-1: print(-1)\nelse: print(cnt)", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"}
{"source_code": "#!/usr/bin/python\nimport sys\n\nlim = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], \\\n       [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]]\n\ndef leap (y):\n\treturn y % 4 == 0\n\ndef do (a, b, c):\n\tglobal d, m, y\n\tif c < 1 or c > 99:\n\t\treturn False\n\tif b < 1 or b > 12:\n\t\treturn False\n\tif a < 1 or a > lim[leap (c)][b - 1]:\n\t\treturn False\n\tif y - c > 18:\n\t\treturn True\n\tif y - c < 18:\n\t\treturn False\n\tif m - b > 0:\n\t\treturn True\n\tif m - b < 0:\n\t\treturn False\n\tif d - a > 0:\n\t\treturn True\n\tif d - a < 0:\n\t\treturn False\n\treturn True\n\nd, m, y = [int (x) for x in sys.stdin.readline ().split ('.')]\na, b, c = [int (x) for x in sys.stdin.readline ().split ('.')]\nif do (a, b, c) or do (a, c, b) or do (b, a, c) or \\\n   do (b, c, a) or do (c, a, b) or do (c, b, a):\n\tprint ('YES')\nelse:\n\tprint ('NO')\n", "src_uid": "5418c98fe362909f7b28f95225837d33"}
{"source_code": "import sys\n\nprofit = 0\ninitial = (list(map(int, sys.stdin.readline().split()))) \nnum_planet = initial[0]\nnum_goods = initial[1]\ncapacity = initial[2]\nstonks = []\nfor i in range(0, num_planet):\n    #print('Name planetu')\n    name_Planet = str(sys.stdin.readline())\n    planet = []\n    for j in range (0, num_goods):\n        elem = (list(map(int,sys.stdin.readline().split())))\n        planet.append(elem)\n    stonks.append(planet)\ndef Solution():\n    global profit\n    for i in range(0, len(stonks)):\n        for j in range(0, len(stonks)):\n            tmp = []\n            for k in range(0, num_goods):\n                if stonks[i][k][0] < stonks[j][k][1]:\n                    res = stonks[j][k][1] - stonks[i][k][0]\n                    a = (res, stonks[i][k][2])\n                    tmp.append(a)\n                else:\n                    pass\n            if len(tmp) > 0:\n                sort_tmp = sorted(tmp, key = lambda x: (-x[0]))\n                y = 0\n\n                for y in range(0, capacity):\n                    local_profit = 0\n                    i_in_list = 0\n                    if y == capacity:\n                        break\n                    for x in range(0, len(sort_tmp)):\n                        for z in range(0, sort_tmp[i_in_list][1]):\n                            if sort_tmp[i_in_list][1] == 0:\n                                break\n                            local_profit += sort_tmp[i_in_list][0]\n                            y+=1\n                            if z == sort_tmp[i_in_list][1]:\n                                break\n                            if y > capacity -1 or x == len(sort_tmp):\n                                break\n                        if y > capacity -1 or x == len(sort_tmp):\n                            break\n                        i_in_list += 1\n\n                    profit = local_profit if local_profit > profit else profit\n\nSolution()\nprint(profit)", "src_uid": "7419c4268a9815282fadca6581f28ec1"}
{"source_code": "\nn = int(input())\nl = list(map(int, input().split()))\nl.sort()\n\ndef avg(arr):\n\treturn sum(arr) / n\nans = 0\n\nwhile avg(l) < 4.5:\n\tl[ans] = 5\n\tans += 1\n\nprint(ans)\n", "src_uid": "715608282b27a0a25b66f08574a6d5bd"}
{"source_code": "from math import sqrt\n\nclass vector:\n\tdef __init__(self, _x = 0, _y = 0):\n\t\tself.x = _x\n\t\tself.y = _y\n\tdef len(self):\n\t\treturn sqrt(self.x ** 2 + self.y ** 2)\n\tdef len_sq(self):\n\t\treturn self.x ** 2 + self.y ** 2\n\tdef __mul__(self, other):\n\t\tif (type(self) == type(other)):\n\t\t\treturn self.x * other.x + self.y * other.y\n\t\treturn vector(self.x * other, self.y * other)\n\tdef __mod__(self, other):\n\t\treturn self.x * other.y - self.y * other.x\n\tdef normed(self):\n\t\tlength = self.len()\n\t\treturn vector(self.x / length, self.y / length)\n\tdef normate(self):\n\t\tself = self.normed()\n\tdef __str__(self):\n\t\treturn \"(\" + str(self.x) + \", \" + str(self.y) + \")\"\n\tdef __add__(self, other):\n\t\treturn vector(self.x + other.x, self.y + other.y);\n\tdef __sub__(self, other):\n\t\treturn vector(self.x - other.x, self.y - other.y);\n\tdef __eq__(self, other):\n\t\treturn self.x == other.x and self.y == other.y\n\tdef rot(self):\n\t\treturn vector(self.y, -self.x)\n\nclass line:\n\tdef __init__(self, a = 0, b = 0, c = 0):\n\t\tself.a = a\n\t\tself.b = b\n\t\tself.c = c\n\tdef intersect(self, other):\n\t\td = self.a * other.b - self.b * other.a\n\t\tdx = self.c * other.b - self.b * other.c\n\t\tdy = self.a * other.c - self.c * other.a\n\t\treturn vector(dx / d, dy / d)\n\tdef fake(self, other):\n\t\td = self.a * other.b - self.b * other.a\n\t\treturn d\n\tdef __str__(self):\n\t\treturn str(self.a) + \"*x + \" + str(self.b) + \"*y = \" + str(self.c) \n\ndef line_pt(A, B):\n\t\td = (A - B).rot()\n\t\treturn line(d.x, d.y, d * A)\n\nclass circle:\n\tdef __init__(self, O = vector(0, 0), r = 0):\n\t\tself.O = O\n\t\tself.r = r\n\tdef intersect(self, other):\n\t\tO1 = self.O\n\t\tO2 = other.O\n\t\tr1 = self.r\n\t\tr2 = other.r\n\t\tif (O1 == O2):\n\t\t\treturn []\n\t\tif ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2):\n\t\t\treturn []\n\t\trad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq())\n\t\tcentral = line_pt(O1, O2)\n\t\tM = rad_line.intersect(central)\n\t\t# print(M)\n\t\tif ((O1 - O2).len_sq() == r1 ** 2 + r2 ** 2 + 2 * r1 * r2):\n\t\t\treturn [M]\n\t\td = (O2 - O1).normed().rot()\n\t\tif (r1 ** 2 - (O1 - M).len_sq() < 0):\n\t\t\treturn []\n\t\td = d * (sqrt(r1 ** 2 - (O1 - M).len_sq()))\n\t\treturn [M + d, M - d]\n\tdef fake(self, other):\n\t\tO1 = self.O\n\t\tO2 = other.O\n\t\tr1 = self.r\n\t\tr2 = other.r\n\t\tif (O1 == O2):\n\t\t\treturn 1\n\t\tif ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2):\n\t\t\treturn 1\n\t\trad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq())\n\t\tcentral = line_pt(O1, O2)\n\t\treturn rad_line.fake(central)\n\n\n# a = vector(3, 4)\n# b = vector(4, 4)\n# print(circle(vector(1, 2), 3).intersect(circle(vector(2, 1), 6)))\nn = int(input())\narr = []\nm = 1\nfor i in range(n):\n\tx, y, r = map(int, input().split())\n\tarr.append(circle(vector(x, y), r))\nfor i in range(n):\n\tfor j in range(i + 1, n):\n\t\tm *= arr[i].fake(arr[j])\nfor i in range(n):\n\tarr[i].O = arr[i].O * m\n\tarr[i].r = arr[i].r * m\n# print(m)\ns = set()\nV = 0\nfor i in range(n):\n\tfor j in range(i + 1, n):\n\t\ttmp = arr[i].intersect(arr[j])\n\t\tfor e in tmp:\n\t\t\ts.add((round(e.x, 6), round(e.y, 6)))\nV += len(s)\nE = 0\n\npar = [i for i in range(n)]\n\ndef get_par(v):\n\tif (par[v] != v):\n\t\tpar[v] = get_par(par[v])\n\treturn par[v]\ndef unite(v, u):\n\tpar[get_par(v)] = get_par(u)\nfor i in range(n):\n\ts = set()\n\tfor j in range(n):\t\n\t\ttmp = arr[i].intersect(arr[j])\n\t\tif (len(tmp)):\n\t\t\tunite(i, j)\n\t\tfor e in tmp:\n\t\t\ts.add((round(e.x, \t), round(e.y, \t)))\n\tE += len(s)\n# print(V, E)\n# print(len({get_par(i) for i in range(n)}))\nprint(E - V + 1 + len({get_par(i) for i in range(n)}))", "src_uid": "bda5879e94a82c6fd499796f258c4691"}
{"source_code": "s = input()\nm = int(input()) \npw = [0] * (len(s) + 1)\npw[0] = 1\nfor i in range(1, len(s) + 1):\n\tpw[i] = pw[i - 1] * 10 % m\ncur = 0\nfor i in range(len(s)):\n\tcur *= 10\n\tcur += ord(s[i]) - ord('0')\n\tcur %= m\nans = cur\nfor i in range(1, len(s)):\n\tcur *= 10\n\tcur %= m\n\tcur -= ((ord(s[i - 1]) - ord('0')) * pw[len(s)] % m);\n\tcur += m\n\tcur %= m\n\tcur += ord(s[i - 1]) - ord('0')\n\tcur %= m\n\tif (s[i] != '0'):\n\t\tans = min(ans, cur)\nprint(ans)\n\t\t\n", "src_uid": "d13c7b5b5fc5c433cc8f374ddb16ef79"}
{"source_code": "from math import sqrt\nn = int(input())\n\n\ndef is_prime(n: int) -> bool:\n    sq = int(sqrt(n)) + 1\n    for i in range(2, sq):\n        if n % i == 0:\n            return False\n\n    return True\n\n\ndef solve(n: int) -> int:\n    for m in range(1, 1001):\n        ans = n*m + 1\n        if not is_prime(ans):\n            return m\n\nprint(solve(n))\n", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"}
{"source_code": "a = map(int, raw_input().split())\nb = map(int, raw_input().split())\nset = 0\nfor i in xrange(0, 101):\n    for j in xrange(0, 101):\n        x1 = b[1] + i * b[0]\n        x2 = a[1] + j * a[0]\n        if x1 == x2:\n            print x1\n            set = 1\n            break\n    if set==1:\n        break\nif set== 0:\n    print -1\n\n\n", "src_uid": "158cb12d45f4ee3368b94b2b622693e7"}
{"source_code": "n    = int(input())\np    = list(map(int, input().split()))\ng    = {}\ndeg  = {}\nfirst  = []\ncircle = {}\nans  = []\n\ndef push_d(deg, u, val):\n    if u not in deg:\n        deg[u] = 0\n    deg[u] += val\n    \ndef push_g(g, u, v):\n    if u not in g:\n        g[u] = []\n    g[u].append(v)\n\ndef gcd(a, b):\n    if b == 0:\n        return a\n    return gcd(b, a%b)\n\ndef total(arr):\n    cur=1 \n    for x in arr:\n        cur = cur // gcd(cur, x) * x\n    return cur    \n\ndef process(g, deg, deg0, u):\n    if u in g:\n        for v in g[u]:\n            push_d(deg, v, -1)\n        \n            if deg[v] == 0:\n                deg0.append(v)\n    \ndef bfs(u):\n    S = [u]\n    used[u]   = 1\n    circle[u] = 1\n    i = 0\n    while i < len(S):\n        u = S[i]\n        if u in g:\n            for v in g[u]:\n                if used[v] == 0:\n                    used[v] = 1\n                    circle[v] = 1\n                    S.append(v)\n        i+=1\n    return len(S)  \n        \ndef bfs2(u):\n    S = [u]\n    start = 0\n    i = 0\n    while i < len(S):\n        u = S[i]\n        if u in g:\n            for v in g[u]:\n                if used[v] == -1:\n                    S.append(v)\n                else:\n                    start = used[v]\n        i+=1\n    \n    for u in S[::-1]:\n        start  += 1\n        used[u] = start\n        \n    return start\n\nfor u, v in enumerate(p):\n    u+=1\n    \n    push_d(deg, v, 1)\n    push_g(g, u, v)\n\ndeg0  = [x for x in range(1, n+1) if x not in deg]\nfirst = [x for x in deg0] \nused  = [0 for x in range(n+1)]\n\nwhile len(deg0) > 0:\n    u = deg0.pop()\n    used[u] = 1 \n    process(g, deg, deg0, u)\n    \ncnt = []    \nfor u in range(1, n+1):\n    if used[u] == 0:\n        cnt.append(bfs(u))\n\nused = [-1 for x in range(n+1)]\nfor u in circle:\n    used[u] = 0\n\nmax_ = 0\nfor u in first:\n    max_ = max(max_, bfs2(u))\n        \ncur = total(cnt)       \nans = cur\nwhile ans<max_:\n    ans+=cur\nprint(ans)", "src_uid": "1daa784c0eb1cde514e4319da07c8d00"}
{"source_code": "a, b, c, d = map(int, input().split())\n\nif b - a == c - b == d - c:\n    print(d + (d - c))\nelif b * b == a * c and c * c == b * d and (d * d) % c == 0:\n    print((d * d) // c)\nelse:\n    print(42)\n", "src_uid": "68a9508d49fec672f9c61766d6051047"}
{"source_code": "s = raw_input()\ni = 0\nans = ''\nwhile i < len(s):\n    if s[i] == '.': ans += '0'\n    elif s[i] == '-' and s[i+1] == '.': i += 1; ans += '1'\n    else: i += 1; ans += '2'\n    i += 1\nprint ans", "src_uid": "46b5a1cd1bd2985f2752662b7dbb1869"}
{"source_code": "string = raw_input()\nnew_string = \"\"\naux = True\n\nfor i in string:\n    if string[0] == \"9\" and aux:\n        new_string += i\n        aux = False\n    \n    elif i < \"5\":\n        new_string += i\n\n    else:\n        new_string += str((9 - int(i)))\n\nprint new_string", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"}
{"source_code": "l = list(map(int,input().split()))\na = l[0]\nb = l[1]\nn = l[2]\n\ndef gcd(x,y):\n    l = []\n    for i in range(1,min(x,y)+1):\n        if x % i == 0 and y % i == 0 : \n            l.append(i)\n    return max(l)\nx = gcd(a,n)\ny = gcd(b,n)    \ni = 1\nwhile x <= n or y <= n : \n    if i % 2 == 0 : \n        n -= gcd(b,n)\n    else :\n        n -= gcd(a,n)\n    i += 1\n    \nif i % 2 == 0 : \n    print(\"0\")\nelse : \n    print(\"1\")                ", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"}
{"source_code": "def illegal(b):\n    if abs(b.count('X')-b.count('0'))>1:\n        return True\n    if b.count('0')>b.count('X'):\n        return True\n    if win('X') and win('0'):\n        return True\n    if win('0') and b.count('X')>b.count('0'):\n        return True\n    if win('X') and b.count('0')>=b.count('X'):\n            return True    \n    return False\n\ndef win(p):\n    if bord[0]==bord[1]==bord[2]==p:\n        return True\n    if bord[3]==bord[4]==bord[5]==p:\n        return True\n    if bord[6]==bord[7]==bord[8]==p:\n        return True\n    if bord[0]==bord[3]==bord[6]==p:\n        return True\n    if bord[1]==bord[4]==bord[7]==p:\n        return True\n    if bord[2]==bord[5]==bord[8]==p:\n        return True\n    if bord[0]==bord[4]==bord[8]==p:\n        return True\n    if bord[2]==bord[4]==bord[6]==p:\n        return True\n    return False\n\ndef draw():\n    if bord.count('.')==0:\n        return True\n    return False\n\ndef turn():\n    if bord.count('.')>0:\n        if bord.count('X')==bord.count('0'):\n            return 'first'\n        else:\n            return 'second'\n    else:\n        return 'false'\n    \nbord=[]\nfor i in range (3):\n    s=raw_input().strip()\n    l=list(s)\n    bord+=l\nif not illegal(bord):\n    if win('X'):\n        print 'the first player won'\n    elif win('0'):\n        print 'the second player won'\n    elif draw():\n        print 'draw'\n    else:\n        print turn()\nelse:\n    print 'illegal'\n", "src_uid": "892680e26369325fb00d15543a96192c"}
{"source_code": "n = int(input())\nl, r = 0, n + 1\nwhile l + 1 < r:\n    m = (l + r) >> 1\n    if m * (3 * m + 1) <= n * 2:\n        l = m\n    else:\n        r = m\nprint(len([1 for x in range(1, l + 1) if (n - 2 * x) % 3 == 0]))\n", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de"}
{"source_code": "s, x = map(int, input().split())\nprint(((s-x)&(x+x+1)==0 and x <= s) * (2 ** bin(x).count('1') - 2 * (s == x)))\n", "src_uid": "18410980789b14c128dd6adfa501aea5"}
{"source_code": "a=input()\nb=input()\nif len(str(b))>len(str(a)):\n\ta=list(str(a))\n\ta.sort()\n\tprint ''.join(a[::-1])\nelse:\n\tz=list(str(a))\n\tx=[0 for i in range(10)]\n\tfor i in range(len(z)):\n\t\tx[int(z[i])]+=1\n\tans=''\n\tb=str(b)\n\tflag=1\n\tfor i in range(len(z)):\n\t\tremain=(b[i+1:])\n\t\tif flag:\n\t\t\tfor j in range(int(b[i]), -1, -1):\n\t\t\t\tif x[j]:\n\t\t\t\t\tremain2=''\n\t\t\t\t\tx[j]-=1\n\t\t\t\t\tfor k in range(10):\n\t\t\t\t\t\tremain2+=str(k)*x[k]\n\t\t\t\t\tx[j]+=1\n\t\t\t\t\tif j==int(b[i]):\n\t\t\t\t\t\tif remain2>remain:\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\tx[j]-=1\n\t\t\t\t\tif j!=int(b[i]):\n\t\t\t\t\t\tflag=0\n\t\t\t\t\tans+=str(j)\n\t\t\t\t\tbreak\n\t\telse:\n\t\t\tfor j in range(9, -1, -1):\n\t\t\t\tif x[j]:\n\t\t\t\t\tans+=str(j)\n\t\t\t\t\tx[j]-=1\n\t\t\t\t\tbreak\n\n\tprint ans", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44"}
{"source_code": "l1,r1,l2,r2=map(int,raw_input().split())\nl=[l1,l2]\nr=[r1,r2]\ndef nextwhere(l,s):\n    fs=2**s\n    st=2**(s+1)\n    return l if l%st==fs else l+(st-(l-fs)%st)\nans=0    \nfor s in xrange(31):\n    z=[list(),list()]\n    for hui in xrange(2):\n        f=list()\n        t=l[hui]-1\n        for j in xrange(3):\n            t=nextwhere(t+1,s)\n            if t>r[hui]:\n                break\n            f.append(t)\n        if len(f)==0:\n            continue\n        elif len(f)==1:\n            z[hui].append((min(f[0]-l[hui],2**s-1),min(r[hui]-f[0],2**s-1)))\n        elif len(f)==2:\n            z[hui].append((min(f[0]-l[hui],2**s-1),2**s-1))            \n            z[hui].append((2**s-1,min(r[hui]-f[1],2**s-1)))            \n        else:\n            z[hui].append((2**s-1,2**s-1))    \n    for i in z[0]:\n        for j in z[1]:\n            ans=max(ans,min(i[0],j[0])+min(i[1],j[1])+1)\nprint ans", "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513"}
{"source_code": "n=input()\nline=raw_input()\ninds=[]\nfor i in range(n):\n    if line[i]=='*':\n        inds.append(i)\n\nfor j in range(len(inds)-1):\n    for k in range(j+1,len(inds)):\n        dif=inds[k]-inds[j]\n        if inds[k]+dif in inds and inds[k]+2*dif in inds and inds[k]+3*dif in inds:\n            print(\"yes\")\n            quit()\n\nprint(\"no\")\n", "src_uid": "12d451eb1b401a8f426287c4c6909e4b"}
{"source_code": "#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\nfrom itertools import combinations, product\n\nn = int(raw_input())\nrmax = 0\nintervals = []\nfor _ in xrange(n):\n    l, r = map(int, raw_input().split())\n    rmax = max(rmax, r)\n    intervals.append((l, r))\nINDS = range(len(intervals))\n\n\ndef prob_smaller_equal(ints, val):\n    res = 1.0\n    for l, r in ints:\n        d = min(val + 1 - l, r + 1 - l)\n        if d <= 0:\n            return 0.0\n        res *= float(d) / (r + 1 - l)\n        if res == 0.0:\n            return 0.0\n    return res\n\n\ndef prob_smaller(ints, val):\n    res = 1.0\n    for l, r in ints:\n        d = min(val - l, r + 1 - l)\n        if d <= 0:\n            return 0.0\n        res *= float(d) / (r + 1 - l)\n        if res == 0.0:\n            return 0.0\n    return res\n\n\ndef prob_greater(ints, val):\n    res = 1.0\n    for l, r in ints:\n        d = min(r - val, r + 1 - l)\n        if d <= 0:\n            return 0.0\n        res *= float(d) / (r + 1 - l)\n        if res == 0.0:\n            return 0.0\n    return res\n\n\ndef prob_equal(ints, val):\n    res = 1.0\n    for l, r in ints:\n        if not (l <= val <= r):\n            return 0.0\n        res *= 1.0 / (r + 1 - l)\n    return res\n\n\ndef combos(ints, minn, maxn):\n    for ntie in xrange(minn, maxn + 1):\n        for c in combinations(ints, r=ntie):\n            yield c\n\n\ndef prod(cache, inds, price):\n    res = 1.0\n    for i in inds:\n        res *= cache[i][price]\n        if res == 0.0:\n            return 0.0\n    return res\n\n\ncache_smaller = [[0] * 10002 for _ in xrange(5)]\ncache_smaller_equal = [[0] * 10002 for _ in xrange(5)]\ncache_equal = [[0] * 10002 for _ in xrange(5)]\ncache_greater = [[0] * 10002 for _ in xrange(5)]\nfor i, (l, r) in enumerate(intervals):\n    for price in xrange(1, rmax + 1):\n        cache_smaller[i][price] = prob_smaller([(l, r)], price)\n        cache_smaller_equal[i][price] = prob_smaller_equal([(l, r)], price)\n        cache_equal[i][price] = prob_equal([(l, r)], price)\n        cache_greater[i][price] = prob_greater([(l, r)], price)\n\nres = 0\nfor price in xrange(1, rmax + 1):\n    # case 1: 1 larger  1+ equal  * smaller\n    for ind1 in INDS:\n        other = [i for i in INDS if i != ind1]\n        res += (\n            price *\n            prod(cache_greater, (ind1,), price) *\n            (\n                prod(cache_smaller_equal, other, price) -\n                prod(cache_smaller, other, price)\n            )\n        )\n\n    # case 2: 0 larger  2+ equal  * smaller\n    for ind1 in INDS:\n        for ind2 in xrange(ind1 + 1, len(intervals)):\n            smaller = [ii for ii in xrange(ind2) if ii != ind1]\n            smaller_equal = [ii for ii in xrange(ind2 + 1, len(intervals))]\n\n            assert len(smaller) + len(smaller_equal) + 2 == len(intervals)\n\n            res += (\n                price *\n                prod(cache_equal, [ind1, ind2], price) *\n                prod(cache_smaller, smaller, price) *\n                prod(cache_smaller_equal, smaller_equal, price)\n            )\n\nprint res\n", "src_uid": "5258ce738eb268b9750cfef309d265ef"}
{"source_code": "n = int(input())\ns = input()\ndic = [chr(65+i) for i in range(26)]\ndic = dic+dic\ntarget = \"ACTG\"\ncost=999999999999\nloc = {}\nfor i in range(len(dic)):\n    if dic[i] in loc:\n        loc[dic[i]].append(i)\n    else:\n        loc[dic[i]] = [i]\n\n\nfor i in range(n-3):\n    loc_cost = 0\n    for j in range(4):\n        cur= target[j]\n        ele = s[i+j]\n        loc_cost += min(abs(loc[ele][0]-loc[cur][0]),\n                        abs(loc[ele][0]-loc[cur][1]),\n                        abs(loc[ele][1]-loc[cur][0]),\n                        abs(loc[ele][1]-loc[cur][1]),\n                        )\n    cost = min(cost,loc_cost)\nprint(cost)", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543"}
{"source_code": "mod = int(1e9+7)\n\n\ndef ksm(a: int, k: int) -> int:\n    res = 1\n    while k:\n        if k & 1:\n            res = (res * a) % mod\n        a = (a*a) % mod\n        k >>= 1\n    return res\n\n\nm = int(input())\ndp = [0 for i in range(m + 1)]\ndp[1] = 0\nans = 0\ninv = ksm(m, mod - 2)\nfor i in range(2, m+1):\n    fac = []\n    j = 1\n    while j*j <= i:\n        if i % j == 0:\n            fac.append(j)\n            if(j != i//j):\n                fac.append(i//j)\n        j += 1\n    fac.sort()\n    a = [0 for j in range(len(fac))]\n    a[-1] = m // fac[-1]\n    for j in range(len(fac) - 2, -1, -1):\n        a[j] = m // fac[j]\n        for k in range(j+1, len(fac)):\n            if fac[k] % fac[j] == 0:\n                a[j] -= a[k]\n        dp[i] += ((dp[fac[j]] + 1) * a[j] * inv) % mod\n    dp[i] += a[-1] * inv % mod\n    dp[i] = (dp[i] * m * ksm(m - a[-1], mod - 2)) % mod\n    ans = (ans + dp[i] * inv) % mod\n\nprint((ans + 1) % mod)\n", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0"}
{"source_code": "x, y = map(int, input().split())\nif y == 0 and x > 0:\n    print(\"No\")\nelif y == 1 and x >= 2:\n    print(\"No\")\nelif (x - y + 1)%2 == 0 and x - y >= -1:\n    print(\"Yes\")\nelif x == 0 and y == 0:\n    print(\"No\")\nelse:\n    print(\"No\")", "src_uid": "1527171297a0b9c5adf356a549f313b9"}
{"source_code": "a,ta=map(int,input().split())\nb,tb=map(int,input().split())\nh,m=map(int,input().split(':'))\nsa=h*60+m\nea=sa+ta\nc=0\ni=0\nsb=0\neb=sa\nwhile sb<ea and sb<=1439:\n    \n    if eb>sa:\n        c+=1\n    sb=5*60+b*i\n    eb=sb+tb\n    i+=1\nprint(c)\n", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7"}
{"source_code": "\nimport sys\n\ndef read():\n    length = sys.stdin.readline()\n    word = sys.stdin.readline()\n    length.strip()\n    word.strip()\n    newlen = int(length)\n    point = 0\n    points = []\n    lastknown = ''\n    index = []\n    statement = True\n    for x in xrange(newlen):\n        if word[x] == 'a' or word[x] == 'e' or word[x] == 'i' or word[x] == 'o' or word[x] == 'u' or word[x] == 'y':\n            if lastknown == 'a' or lastknown == 'e' or lastknown == 'i' or lastknown == 'o' or lastknown == 'u' or lastknown == 'y':\n                y = x\n                while statement == True:\n                    if word[y] == 'a' or word[y] == 'e' or word[y] == 'i' or word[y] == 'o' or word[y] == 'u' or word[y] == 'y':\n                        point = y\n                        y += 1\n                    else:\n                        points.append((x, point))\n                        statement = False\n                        break\n            else:\n                lastknown = word[x]\n        else:\n            lastknown = word[x]\n            statement = True\n    for thing in reversed(points):\n        word = word[:thing[0]] + word[thing[1]+1:]\n    sys.stdout.write(word)\n    sys.stdout.flush()\n\nif __name__ == '__main__':\n    read()\n", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"}
{"source_code": "'''\nCreated on 2011-11-21\n\n@author: weiyecheng\n'''\n\n\ns=raw_input()\nss=s.split(\" \")\nn=int(ss[0])\nm=int(ss[1])\nk=int(ss[2])\nn-=2;\nm-=2\nmm=max(n,m)\nc=[[0 for i in range(mm+1)] for j in range(mm+1)]\nc[0][0]=1\nfor i in range(1,mm+1):\n    c[i][0]=1\n    for j in range(1,i+1):\n        c[i][j]=c[i-1][j]+c[i-1][j-1]\n        c[i][j]%=1000000007\nres=0\nif n>2*k-1:\n    if m>2*k-1:\n        res+=c[n][2*k]*c[m][2*k]\n        res%=1000000007\nif n>2*k-1:\n    if m>=2*k-1:\n        res+=c[n][2*k]*c[m][2*k-1]\n        res%=1000000007\nif n>=2*k-1:\n    if m>2*k-1:\n        res+=c[n][2*k-1]*c[m][2*k]\n        res%=1000000007\nif n>=2*k-1:\n    if m>=2*k-1:\n        res+=c[n][2*k-1]*c[m][2*k-1]\n        res%=1000000007\nprint res", "src_uid": "309d2d46086d526d160292717dfef308"}
{"source_code": "from math import factorial\n#print(\" \".join(map(str,array)))\nn = int(input())\nprint((factorial(n)*2)//(n*n))", "src_uid": "ad0985c56a207f76afa2ecd642f56728"}
{"source_code": "n = int(raw_input())\n\nMAX = 9*11\n\ndef check(x):\n  if x < 0: return False\n  return sum(map(int, str(x))) + x == n\n\nres = filter(check, range(n - MAX, n))\nprint len(res)\nfor x in res:\n  print x\n", "src_uid": "ae20ae2a16273a0d379932d6e973f878"}
{"source_code": "n = int(raw_input())\na = map(int, raw_input().split())\nif a[0] % 2 == 0 or a[-1] % 2 == 0:\n  print \"No\"\nelif n % 2:\n  print \"Yes\"\nelse:\n  print \"No\"  ", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"}
{"source_code": "#!/usr/bin/env python3\n\nN = int(input())\nprint(int(N*3/2))", "src_uid": "031e53952e76cff8fdc0988bb0d3239c"}
{"source_code": "import math\ndef countDivisors(n) : \n    cnt = 0\n    for i in range(1, (int)(math.sqrt(n)) + 1) : \n        if (n % i == 0) : \n              \n            # If divisors are equal, \n            # count only one \n            if (n / i == i) : \n                cnt = cnt + 1\n            else : # Otherwise count both \n                cnt = cnt + 2\n                  \n    return cnt\n# Driver Code \nb=int(input())\nprint(countDivisors(b))", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1"}
{"source_code": "import math, sys\nfrom collections import defaultdict, Counter, deque\n\nINF = float('inf')\nMOD = 1000000007\n\ndef gcd(a, b):\n\twhile b:\n\t\ta, b = b, a%b\n\treturn a\n\ndef isPrime(n):\n\tif (n <= 1): \n\t\treturn False\n\ti = 2\n\twhile i ** 2 <= n:\n\t\tif n % i == 0:\n\t\t\treturn False\n\t\ti += 1\n\treturn True\n\ndef primeFactors(n):\n\tfactors = []\n\ti = 2\n\twhile i ** 2 <= n:\n\t\twhile n % i == 0:\n\t\t\tfactors.append(i)\n\t\t\tn //= i \n\t\ti += 1\n\tif n > 1:\n\t\tfactors.append(n)\n\treturn factors\n\ndef vars():\n\treturn map(int, input().split())\n\ndef array():\n\treturn list(map(int, input().split()))\n\n\t\ndef main():\n\td, s = vars()\n\tarr = []\n\tfor i in range(d):\n\t\tx, y = vars()\n\t\tarr.append((x, y))\n\n\tans = []\n\tns = 0\n\tfor x, y in arr:\n\t\tans.append(y)\n\t\tns += y \n\n\tns -= s \n\tif ns >= 0:\n\t\tfor i in range(d):\n\t\t\tlower = arr[i][0]\n\t\t\ttemp = min(ns, arr[i][1] - arr[i][0])\n\t\t\tans[i] -= temp\n\t\t\tns -= temp\n\t\tif ns:\n\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('YES')\n\t\t\tprint(*ans)\n\telse:\n\t\tprint('NO')\n\nif __name__ == \"__main__\":\n\t# t = int(input())\n\tt = 1\n\tfor _ in range(t):\n\t\tmain()\n\t\n\n\n\n\n\n\n\n", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"}
{"source_code": "#!/usr/bin/env python\n# http://www.zhihua-lai.com/acm\n\nn = int(raw_input())\nans = 0\n\ndef C(i, n):\n    return any((ch for ch in str(i) if ch in n))\n    \nfor i in xrange(1, n + 1):\n    if i * i > n:\n        break\n    if n % i == 0:\n        if C(i, str(n)):\n            ans += 1\n        if i * i != n:\n            if C(n / i, str(n)):\n                ans += 1\n        \nprint ans", "src_uid": "ada94770281765f54ab264b4a1ef766e"}
{"source_code": "def yoba(a, k):\n\n    if not a:\n\n        return []\n\n    elif not k:\n\n        return a\n\n    else:\n\n        m = max(a[:k + 1])\n        mi = a.index(m)\n        if m > a[0]:\n\n            a[1:mi + 1] = a[:mi]\n            a[0] = m\n            k -= mi\n\n        return [a[0]] + yoba(a[1:], k)\n\n\na, k = str.split(input())\nk = int(k)\n\nprint(str.join(\"\", yoba(list(a), k)))\n", "src_uid": "e56f6c343167745821f0b18dcf0d0cde"}
{"source_code": "#!/usr/bin/env python3\n\nfrom collections import namedtuple\nfrom itertools   import permutations\n\nPoint = namedtuple(\"Point\", \"x y\")\n\ntry:\n    while True:\n        p = [Point(*map(int, input().split())) for i in range(3)]\n        a, b, c = p\n        if a.x == b.x == c.x or a.y == b.y == c.y:\n            print(1)\n        else:\n            for a, b, c in permutations(p):\n                if a.x == b.x and not a.y < c.y < b.y and not b.y < c.y < a.y:\n                    print(2)\n                    break\n                if a.y == b.y and not a.x < c.x < b.x and not b.x < c.x < a.x:\n                    print(2)\n                    break\n            else:\n                print(3)\n\nexcept EOFError:\n    pass\n", "src_uid": "36fe960550e59b046202b5811343590d"}
{"source_code": "# maa chudaaye duniya\nn = int(input())\nparents = [i for i in range(n+1)]\nranks = [1 for i in range(n+1)]\n\ndef find(x):\n\tif parents[x] != x:\n\t\tparents[x] = find(parents[x])\n\treturn parents[x]\n\ndef union(x, y):\n\txs = find(x)\n\tys = find(y)\n\tif xs == ys:\n\t\treturn\n\tif ranks[xs] > ranks[ys]:\n\t\tparents[ys] = xs\n\telif ranks[ys] > ranks[xs]:\n\t\tparents[xs] = ys\n\telse:\n\t\tparents[ys] = xs\n\t\tranks[xs] += 1\n\nfor _ in range(int(input())):\n\tu, v = map(int, input().split())\n\tunion(u, v)\n\n# print(parents)\nrejects = set([])\nfor _ in range(int(input())):\n\tp, q = map(int, input().split())\n\tps = find(p)\n\tqs = find(q)\n\tif ps == qs:\n\t\trejects.add(ps)\nps = {}\nfor i in range(1, n+1):\n\tp = find(i)\n\tif p not in rejects:\n\t\tif p in ps:\n\t\t\tps[p] += 1\n\t\telse:\n\t\t\tps[p] = 1\n# print(ps)\nans = 0\nfor i in ps:\n\tans = max(ans, ps[i])\nprint(ans)", "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1"}
{"source_code": "s = input()\ncount_4 = s.count('4')\ncount_7 = s.count('7')\nif count_4==0 and count_7==0:\n    print(-1)\nelif count_4==0 and count_7!=0:\n    print('7')\nelif count_4!=0 and count_7==0:\n    print('4')\nelif count_4==count_7:\n    print('4')\nelif count_4 > count_7:\n    print('4')\nelif count_4 < count_7:\n    print('7')", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a"}
{"source_code": "#Lorenzo by Esii in Site :D\n\nfrom math import sqrt,ceil\nls=[]\ndef primeFactors(n):\n    while (n % 2 == 0):\n        ls.append(2)\n        n = n / 2\n    for i in range(3, ceil(sqrt(n))+1, 2):\n        while (n % i == 0):\n            ls.append(int(i))\n            n /= i\n\n    if n > 2:\n        ls.append(int(n))\n\n\n\nn,k=map(int,input().split())\nprimeFactors(n)\nln=len(ls)\nif(ln<k):\n    print(-1)\nelif(ln==k):\n    print(*ls)\nelse:\n    tmp=ls[k-1]\n    for i in range(k,ln):\n        tmp*=ls[i]\n    print(*ls[:k-1],tmp)", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79"}
{"source_code": "h1,m1= (map(int,input().split(':')))\nm1+=h1*60\nh2,m2= (map(int,input().split(':')))\nm2+=h2*60\nm2=m1-m2\nm2%=1440\nprint(\"%02d:%02d\"%(m2//60,m2%60))\n", "src_uid": "595c4a628c261104c8eedad767e85775"}
{"source_code": "x,y,m = map(int,input().split())\nif(x > y):\n\tx,y = y,x\nif(y >= m):\n\tprint('0')\nelif(x+y <= x):\n\tprint('-1')\nelse:\n\tans = (y-x+y-1)//y\n\tx += y*ans\n\twhile(x < m):\n\t\tx,y = x+y,x\n\t\tans += 1\n\tprint(ans)\n\n", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821"}
{"source_code": "# http://codeforces.com/contest/771/problem/D\n\"\"\"\nDP-solution.\n\nFor each state (v, k, x, v_is_last_letter) we trial a step along the v, k and x\naxes and check that\ndp[future_state] = min(dp[future_state], dp[state] + cost_of_move)\nHence this implicitly reults in the one with least cost.\n\nV, K, X are arrays that contain the number of occurences of v, k, x at the i'th\nindex of s.\n\"\"\"\n\n\ndef cost_of_move(state, ss_ind):\n    \"\"\"\n    eg. ss = s[0:K.index(k+1)]\n    Note: ss includes the i+1'th occurence of letter I. We hence want\n    ss = s[0:ss_ind-1]\n    And then we cound the number of occurences of V, K, X in this substring.\n\n    However, we don't need ss now - this info is contained in lists V, K, X.\n    \"\"\"\n\n    curr_v, curr_k, curr_x = state\n    cost = sum([max(0, V[ss_ind-1] - curr_v), max(0, K[ss_ind-1] - curr_k),\n                max(0, X[ss_ind-1] - curr_x)])\n    return cost\n\n\nif __name__ == \"__main__\":\n\n    n = int(input())\n    s = input()\n\n    V = [s[0:i].count('V') for i in range(n+1)]\n    K = [s[0:i].count('K') for i in range(n+1)]\n    X = [(i - V[i] - K[i]) for i in range(n+1)]\n\n    # Initialising\n    n_v, n_k, n_x = V[n], K[n], X[n]\n\n    dp = [[[[float('Inf') for vtype in range(2)] for x in range(n_x+1)]\n           for k in range(n_k+1)] for v in range(n_v+1)]\n    dp[0][0][0][0] = 0\n\n    for v in range(n_v + 1):\n        for k in range(n_k + 1):\n            for x in range(n_x + 1):\n                for vtype in range(2):\n                    orig = dp[v][k][x][vtype]\n                    if v < n_v:\n                        dp[v+1][k][x][1] = min(dp[v+1][k][x][vtype],\n                                               orig + cost_of_move([v, k, x], V.index(v+1)))\n                    if k < n_k and vtype == 0:\n                        dp[v][k+1][x][0] = min(dp[v][k+1][x][0],\n                                               orig + cost_of_move([v, k, x], K.index(k+1)))\n                    if x < n_x:\n                        dp[v][k][x+1][0] = min(dp[v][k][x+1][0],\n                                               orig + cost_of_move([v, k, x], X.index(x+1)))\n    print(min(dp[n_v][n_k][n_x]))\n", "src_uid": "08444f9ab1718270b5ade46852b155d7"}
{"source_code": "# your code goes here\nimport sys\nn,m=map(int,sys.stdin.readline().split(\" \"))\nvisited=[0]*100001\nval=[1000000000000]*100001\na=[]\na.append(n)\nval[n]=0\ntopval=n\n\nwhile(len(a)>0):\n    \n    topval=a[0]\n    \n    a.pop(0)\n    if(val[topval-1]>val[topval]+1 and topval>1):\n        a.append(topval-1)\n        val[topval-1]=val[topval]+1\n        if(topval-1==m):\n            break\n        \n\n    if(val[2*topval]>val[topval]+1 and 2*topval<=40000):\n        a.append(2*topval)\n        \n        val[2*topval]=val[topval]+1\n        if(2*topval==m):\n            break\n\n\n\n    \n    \nprint val[m]\n    \n    ", "src_uid": "861f8edd2813d6d3a5ff7193a804486f"}
{"source_code": "def forest(n):\n    result = 0\n    for i in range(1, n + 1):\n        for j in range(i, n + 1):\n            q = i ^ j\n            if j <= q <= n and q + i > j and q + j > i and i + j > q:\n                result += 1\n    return result\n\n\nprint(forest(int(input())))\n", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"}
{"source_code": "\n\ndef f(n,m):\n  if n<m:return f(m,n)\n  if m==1:\n    return (n+2)/3\n  if m==2:\n    return (n+2)/2\n  if m==3:\n    return (3*n+4)/4\n  if m==4:\n    if n==5 or n==6 or n==9:return n+1\n    else:return n\n  if m==5:\n    if n==7:return (6*n+6)/5\n    else:return (6*n+8)/5\n  if m==6:\n    if n%7==1:return (10*n+10)/7\n    else:return (10*n+12)/7\n    \n\ndef main():\n  n,m=map(int, raw_input().split())\n  print n*m-f(n,m)\n\nmain()\n", "src_uid": "097674b4dd696b30e102938f71dd39b9"}
{"source_code": "n = int(raw_input())\nl = sorted([i for i in map(int,raw_input().split())])[::-1]\nans , last = 0 , 1000000007\n\nfor i in l:\n\tif i < last:\n\t\tans += i\n\t\tlast = i\n\n\telse:\n\t\tif last - 1 <= 0:\n\t\t\tbreak\n\t\tans += min(i , last - 1)\n\t\tlast = min(i ,last - 1)\n\n\nprint ans", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f"}
{"source_code": "import math\nn, t = map(int, raw_input().split())\n\nfor i in range(55):\n    comb = [[0]*55 for _ in range(55)]\nfor i in range(55):\n    for j in range(i+1):\n        if (i == 0 or j == 0): comb[i][j] = 1\n        else:\n            comb[i][j] = comb[i-1][j] + comb[i-1][j-1]\n\ndef gao(m, k):\n    ret = 0\n    while m > 0:\n        p = int(math.log(m, 2))\n        ret += comb[p][k]\n        k -= 1\n        m -= 2**p\n        if m == 0:\n            if k == 0:\n                ret += 1\n            break\n        if k < 0:\n            break\n    return ret\n\ntmp = 0\nnum = t\nwhile (num > 0):\n    if (num % 2 == 1):\n        tmp += 1\n    num /= 2\n    if (tmp > 1):\n        break\nif (tmp > 1):\n    print 0\nelse:\n    k = int(math.log(t, 2))\n    ans = gao(n+1, k+1)\n    if t == 1:\n        ans -= 1\n    print ans\n", "src_uid": "727d5b601694e5e0f0cf3a9ca25323fc"}
{"source_code": "n=int(input())\nif n<3:print(-1)\nelse:\n    for i in range(n,0,-1):\n        print(i,end=' ')\n", "src_uid": "fe8a0332119bd182a0a5b7758716317e"}
{"source_code": "import sys\nrange = xrange\ninput = raw_input\n\nMOD = 998244353\n\nclass sumseg:\n    def __init__(self,n):\n        m = 1\n        while m<n:m*=2\n        self.n = n\n        self.m = m\n        self.data = [0]*(n+m)\n    def summa(self,l,r):\n        l+=self.m\n        r+=self.m\n        s = 0\n        while l<r:\n            if l%2==1:\n                s+=self.data[l]\n                l+=1\n            if r%2==1:\n                r-=1\n                s+=self.data[r]\n            l//=2\n            r//=2\n        return s%MOD\n    def add(self,ind,val):\n        ind += self.m\n        while ind>0:\n            self.data[ind] = (self.data[ind]+val)%MOD\n            ind//=2\n\n\nn,k = [int(x) for x in input().split()]\n\nswitchers = [0]*(n+1)\n\nfor h in range(1,n+1):\n    DP = sumseg(n+1)#[0]*(n+1)\n    DP.add(0,2)#DP[0] = 2\n    max_width = (k+h-1)//h - 1\n    for i in range(1,n+1):\n        a = max(i-max_width,0)\n        b = i\n        if a<b:\n            DP.add(i,DP.summa(a,b))#DP[i] = sum(DP[a:b])%MOD\n    \n    switchers[h]=DP.summa(n,n+1)\n\nfor h in range(1,n):\n    switchers[h] = (switchers[h]-switchers[h+1])%MOD\n\n\nswitchers2 = [0]*(n+1)\n\nfor h in range(1,n+1):\n    DP = sumseg(n+1)#[0]*(n+1)\n    DP.add(0,1)#DP[0] = 2\n    max_width = h\n    for i in range(1,n+1):\n        a = max(i-max_width,0)\n        b = i\n        if a<b:\n            DP.add(i,DP.summa(a,b))#DP[i] = sum(DP[a:b])%MOD\n    \n    switchers2[h]=DP.summa(n,n+1)\n\n\n\nsumma = 0\nfor h in range(1,n+1):\n    summa = (summa + switchers[h]*switchers2[h])%MOD\nprint summa\n", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b"}
{"source_code": "def solve(l, b):\n\n    years = 0\n\n    while l <= b:\n        l *= 3\n        b *= 2\n        years += 1\n\n    return years\n\n\nif __name__ == \"__main__\":\n    l,b = map(int,raw_input().split(\" \"))\n    print solve(l,b)", "src_uid": "a1583b07a9d093e887f73cc5c29e444a"}
{"source_code": "def main():\n    a, b, c = map(int, input().split())\n    print((b + a - 1) * (c + a - 1) - a * (a - 1))\n\n\nif __name__ == '__main__':\n    main()", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da"}
{"source_code": "r=lambda:raw_input()\na=r();b=r();c=r()\nans='YES'\nc=list(c)\nfor i in range(len(a)):\n    if(a[i] in c):\n        c[c.index(a[i])]='-'\n    else:\n        ans='NO'\n        break\nfor i in range(len(b)):\n    if(b[i] in c):\n        c[c.index(b[i])]='-'\n    else:\n        ans='NO'\n        break\nif(c.count('-')!=len(c)):\n    ans='NO'\nprint ans", "src_uid": "b6456a39d38fabcd25267793ed94d90c"}
{"source_code": "n = int(input()) + 1\nd = 1000000007\ng = [[1] * n for i in range(n)]\nfor i in range(1, n):\n    g[i][0] = g[i - 1][i - 1]\n    for j in range(1, i + 1): g[i][j] = (g[i][j - 1] + g[i - 1][j - 1]) % d\nprint((g[-1][-1] - g[-1][0]) % d)\n", "src_uid": "aa2c3e94a44053a0d86f61da06681023"}
{"source_code": "def main():\n    Current_HP = int(input())\n    remainder = Current_HP % 4\n    Current_rank = \"\"\n    if remainder == 1 :\n        Current_rank = \"A\"\n        added_number = 0\n        print(str(added_number) +\" \"+ str(Current_rank))\n\n\n    elif remainder == 2:\n        Current_rank = \"B\"\n        added_number = 1\n        print(str(added_number) +\" \"+ str(Current_rank))\n\n\n    elif remainder == 3:\n        Current_rank = \"A\"\n        added_number = 2\n        print(str(added_number) +\" \"+ str(Current_rank))\n\n\n    elif remainder == 0 :\n        Current_rank = \"A\"\n        added_number = 1\n        print(str(added_number) +\" \"+ str(Current_rank))\nif __name__ == '__main__': main()\n", "src_uid": "488e809bd0c55531b0b47f577996627e"}
{"source_code": "print(\"2\")", "src_uid": "d163975cdad000ce89ee251ef9129779"}
{"source_code": "n=int(input())\na=[]\nb=[]\nfor i in range(n):\n    a.append(input())\nfor i in range(n):\n    b.append(input())\n\ndef h(d):\n    c=[]\n    for i in range(n):\n        c.append(d[n-i-1])\n    return c\ndef r(d):\n    c=[]\n    for i in range(n):\n        temp=\"\"\n        for j in range(n):\n            temp+=d[j][n-i-1]\n        c.append(temp)\n    return c\nyes=0\nfor i in range(4):\n    if a==b:\n        print('YES')\n        yes=1\n        break\n    a=r(a)\nif yes==0:\n    a=h(a)\n    for i in range(4):\n        if a==b:\n            print('YES')\n            yes=1\n            break\n        a=r(a)\nif yes==0:\n    print('NO')\n    \n    ", "src_uid": "2e793c9f476d03e8ba7df262db1c06e4"}
{"source_code": "s=raw_input()\na=[s.count(`x`) for x in range(10)]+[0]\nb=a[:]\nu,v=0,0\nF=range(10)\nR=lambda x:x[::-1]\nfor i in F:\n  if a[i] and b[10 - i]:\n    a[i]-=1;b[10-i]-=1\n    c=1+sum(min(a[x],b[9-x]) for x in F)\n    if c>v:u,v=i,c\n    a[i]+=1;b[10-i]+=1\nd=max(0,a[0]-a[9])\na[0]-=d;b[0]-=d\nx=y='0'*d\nif v:\n  x+=`u`;y+=`10-u`\n  a[u]-=1;b[10-u]-=1\nfor i in F:\n  j=min(a[i],b[9-i])\n  x+=`i`*j;y+=`9-i`*j\n  a[i]-=j;b[9-i]-=j\nfor i in F:x+=`i`*a[i];y+=`i`*b[i]\nprint R(x)\nprint R(y)\n", "src_uid": "34b67958a37865e1ca0529bbf528dd9a"}
{"source_code": "from math import floor\nn,s = map(int,raw_input().split())\nif ((n==1) & (s==0)):\n    print 0,0\nelif ((n > 0) & (s < 1)):\n    print -1,-1\nelif s > n*9:\n    print -1,-1\nelse:\n    res1 = 10**(n-1)\n    for i in range(s-1):\n        res1+= 10**(i//9)\n    res2 = 10**(n-1)\n    for i in range(1,s):\n        ss = int(floor(i//9))\n        #print i,ss\n        res2 += 10**(n-1-(ss))\n\n    print res1,int(res2)\n", "src_uid": "75d062cece5a2402920d6706c655cad7"}
{"source_code": "import sys\n\nn, m = [int(i) for i in sys.stdin.readline().split()]\ns = [int(i) for i in sys.stdin.readline().split()]\n\nans = [0] * n\nfor i in range(m):\n    for j in range(s[i]-1, n):\n        if ans[j] == 0:\n            ans[j] = s[i]\n        else:\n            break\n\nfor i in ans:\n    print i,", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863"}
{"source_code": "read_ints = lambda : map(int, raw_input().split())\n\ndef main():\n    mersenne = [2,3,5,7,13,17,19,31,61,89,107,127,521,607,1279,\n            2203,2281,3217,4253,4423,9689,9941,11213,19937,\n            21701,23209,44497,86243,110503,132049,216091,\n            756839,859433,1257787,1398269,2976221,3021377,\n            6972593,13466917,20996011,24036583]\n\n    n = input()\n    print pow(2,mersenne[n-1]-1,1000000007) - 1\n\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7"}
{"source_code": "import sys\ninput = sys.stdin.readline\n\nn, m = map(int, input().split())\ng = [[] for _ in range(n)]\ng_inv = [[] for _ in range(n)]\nfor _ in range(m):\n    u, v = map(int, input().split())\n    u, v = u-1, v-1\n    g[u].append(v)\n    g_inv[v].append(u)\n\nk = int(input())\nP = list(map(int, input().split()))\nP = [p-1 for p in P]\n\nfrom collections import deque\nq = deque()\nvisit = [-1]*n\nq.append(P[-1])\nvisit[P[-1]] = 0\nwhile q:\n    v = q.popleft()\n    for u in g_inv[v]:\n        if visit[u] == -1:\n            visit[u] = visit[v]+1\n            q.append(u)\n\nmin_ = 0\nmax_ = 0\nfor i in range(k-1):\n    v = P[i]\n    flag1 = False\n    flag2 = False\n    for u in g[v]:\n        if u == P[i+1] and visit[u] != visit[v]-1:\n            flag1 = True\n        elif  u != P[i+1] and visit[u] == visit[v]-1:\n            flag2 = True\n        else:\n            pass\n    if flag1:\n        min_ += 1\n    if flag2:\n        max_ += 1\n\nprint(min_, max_)\n", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a"}
{"source_code": "v =[ \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\"]\na = input()\nb = input()\nq = v.index(a)\nf =0\nz =[q,q+3,q+2]\nfor i in z:\n\tif v[i%7]\t== b:\n\t\tf=1\nif f ==1:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\n", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35"}
{"source_code": "n = int(input())\ncount = 0\nwhile True:   \n    if n >= 100:\n        count+=(n//100)\n        n%=100\n        \n    elif n >= 20:\n        count+=(n//20)\n        n%=20\n    elif n >= 10:\n        count+=(n//10)\n        n%=10\n    elif n >= 5:\n        count+=(n//5)\n        n%=5\n    elif n >= 1:\n        count+=(n//1)\n        n%=1\n    else:\n        print(count)\n        break     \n", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc"}
{"source_code": "n,k=map(int,input().split())\nb=list(map(int,input().split()))\ns=input()\na=[]\nif k==1:\n    print(-1)\n    exit()\nfor i in range(n):\n    a.append((b[i],s[i]))\na.sort(reverse=True)\ni=0\nj=0\nm1=0\nq1=False\nq2=False\nwhile i!=k:\n    if a[j][1]!='R':\n        m1+=a[j][0]\n        g=j+0\n        if a[j][1]=='W':\n            q1=True\n        else:\n            q2=True\n        i+=1\n    j+=1\n    if j==n and i!=k:\n        m1=0\n        break\nelse:\n    if not (q1 and q2):\n        m1-=a[g][0]\n        for i in range(g+1,n):\n            if q1 and a[i][1]=='O' or q2 and a[i][1]=='W':\n                m1+=a[i][0]\n                break\n        else:\n            m1=0\ni=0\nj=0\nm2=0\nq1=False\nq2=False\nwhile i!=k:\n    if a[j][1]!='W':\n        m2+=a[j][0]\n        g=j+0\n        if a[j][1]=='R':\n            q1=True\n        else:\n            q2=True\n        i+=1\n    j+=1\n    if j==n and i!=k:\n        m2=0\n        break\nelse:\n    if not (q1 and q2):\n        m2-=a[g][0]\n        for i in range(g+1,n):\n            if q1 and a[i][1]=='O' or q2 and a[i][1]=='R':\n                m2+=a[i][0]\n                break\n        else:\n            m2=0\nif m1 or m2:\n    print(max(m1,m2))\nelse:\n    print(-1)\n    \n    \n    \n        \n", "src_uid": "104cf5253e027929f257364b3874c38b"}
{"source_code": "prob=[int(x) for x in input().split()]\n\ndice_roll={1:\"1/6\", 2:\"1/3\", 3:\"1/2\", 4:\"2/3\", 5:\"5/6\", 6:\"1/1\"}\nmax_prob=max(prob)\n\noutput=((6-max_prob)+1)\n\nprint (dice_roll[output])", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"}
{"source_code": "n,m,k = list(map(int, input().split(\" \")))\nl = True\nif k%2 == 0:\n    l = False\n    d = k/2\nelse:\n    d = (k+1)/2\n\ncol = int(((d-1)%m) +1)\nrow = int(((d-1)//m)+1)\n\nif l:\n    print(str(row), str(col), \"L\")\nelse:\n    print(str(row), str(col), \"R\")\n\n", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"}
{"source_code": "n = int(input())\ns = 0\nif(n%2 == 0):\n    s = ((-1)**n)*n - (n//2)\n    print(s)\nelse:\n    s = ((-1)**n)*n + (n//2)\n    print(s)\n", "src_uid": "689e7876048ee4eb7479e838c981f068"}
{"source_code": "def GCD(a,b):\n    if b>a:\n        a,b=b,a\n    while not b==0:\n        a,b=b,a%b\n    return(a)\ndef LCM(c,d):\n    e=c*d\n    return(e/GCD(c,d))\n\nn, k = input().strip().split()\nv=10**int(k)\nprint(int(LCM(int(n),v)))", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3"}
{"source_code": "#\t!/bin/env python3\n#\tcoding: UTF-8\n\n\n#\t✪ H4WK3yE乡\n#\tMohd. Farhan Tahir\n#\tIndian Institute Of Information Technology and Management,Gwalior\n\n#\tQuestion Link\n#\thttps://codeforces.com/problemset/problem/392/B\n#\n\n# ///==========Libraries, Constants and Functions=============///\n\n\nimport sys\n\ninf = float(\"inf\")\nmod = 1000000007\n\n\ndef get_array(): return list(map(int, sys.stdin.readline().split()))\n\n\ndef get_ints(): return map(int, sys.stdin.readline().split())\n\n\ndef input(): return sys.stdin.readline()\n\n# ///==========MAIN=============///\n\n\ndef main():\n    dp = [[[0 for _ in range(3)] for _ in range(3)] for _ in range(43)]\n    matrix = [[0 for _ in range(3)] for _ in range(3)]\n    for i in range(3):\n        matrix[i] = get_array()\n    n = int(input())\n    for i in range(1, n+1):\n        for frm in range(3):\n            for to in range(3):\n                other = 3-frm-to\n                if frm == to:\n                    continue\n                dp[i][frm][to] = dp[i-1][frm][other]+matrix[frm][to]+dp[i-1][other][to]\n                c = dp[i-1][frm][to]+matrix[frm][other] + \\\n                    dp[i-1][to][frm]+matrix[other][to]+dp[i-1][frm][to]\n                dp[i][frm][to] = min(c, dp[i][frm][to])\n    print(dp[n][0][2])\n\n\nif __name__ == \"__main__\":\n    main()\n", "src_uid": "c4c20228624365e39299d0a6e8fe7095"}
{"source_code": "#!/usr/bin/python\nimport math\n\nprimes = [\n        2, 3, 5, 7, 11, 13, 17, 19, 23, 29, \n     31, 37, 41, 43, 47, 53, 59, 61, 67, 71, \n     73, 79, 83, 89, 97, 101, 103, 107, 109, 113, \n    127, 131, 137, 139, 149, 151, 157, 163, 167, 173, \n    179, 181, 191, 193, 197, 199, 211, 223, 227, 229, \n    233, 239, 241, 251, 257, 263, 269, 271, 277, 281, \n    283, 293, 307, 311, 313, 317, 331, 337, 347, 349, \n    353, 359, 367, 373, 379, 383, 389, 397, 401, 409, \n    419, 421, 431, 433, 439, 443, 449, 457, 461, 463, \n    467, 479, 487, 491, 499, 503, 509, 521, 523, 541, \n    547, 557, 563, 569, 571, 577, 587, 593, 599, 601, \n    607, 613, 617, 619, 631, 641, 643, 647, 653, 659, \n    661, 673, 677, 683, 691, 701, 709, 719, 727, 733, \n    739, 743, 751, 757, 761, 769, 773, 787, 797, 809, \n    811, 821, 823, 827, 829, 839, 853, 857, 859, 863, \n    877, 881, 883, 887, 907, 911, 919, 929, 937, 941, \n    947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, \n   1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, \n   1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, \n   1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, \n   1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, \n   1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, \n   1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, \n   1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, \n   1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, \n   1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, \n   1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, \n   1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, \n   1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, \n   1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, \n   1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, \n   2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, \n   2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, \n   2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, \n   2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, \n   2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, \n   2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, \n   2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, \n   2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, \n   2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, \n   2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, \n   2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, \n   2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, \n   3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, \n   3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, \n   3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, \n   3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, \n   3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, \n   3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, \n   3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, \n   3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, \n   3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, \n   3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, \n   3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, \n   3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, \n   4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, \n   4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, \n   4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, \n   4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, \n   4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, \n   4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, \n   4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, \n   4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, \n   4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, \n   4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, \n   4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, \n   4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, \n   5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, \n   5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, \n   5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, \n   5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, \n   5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, \n   5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, \n   5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, \n   5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, \n   5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, \n   5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, \n   5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, \n   5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, \n   6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, \n   6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, \n   6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, \n   6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, \n   6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, \n   6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, \n   6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, \n   6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, \n   6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, \n   6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, \n   6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, \n   7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, \n   7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, \n   7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, \n   7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, \n   7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, \n   7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, \n   7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, \n   7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, \n   7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, \n   7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, \n   7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, \n   8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, \n   8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, \n   8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, \n   8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, \n   8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, \n   8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, \n   8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, \n   8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, \n   8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, \n   8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, \n   8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, \n   9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, \n   9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, \n   9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, \n   9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, \n   9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, \n   9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, \n   9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, \n   9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, \n   9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, \n   9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, \n   9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973, 10007, \n  10009, 10037, 10039, 10061, 10067, 10069, 10079, 10091, 10093, 10099, \n  10103, 10111, 10133, 10139, 10141, 10151, 10159, 10163, 10169, 10177, \n  10181, 10193, 10211, 10223, 10243, 10247, 10253, 10259, 10267, 10271, \n  10273, 10289, 10301, 10303, 10313, 10321, 10331, 10333, 10337, 10343, \n  10357, 10369, 10391, 10399, 10427, 10429, 10433, 10453, 10457, 10459, \n  10463, 10477, 10487, 10499, 10501, 10513, 10529, 10531, 10559, 10567, \n  10589, 10597, 10601, 10607, 10613, 10627, 10631, 10639, 10651, 10657, \n  10663, 10667, 10687, 10691, 10709, 10711, 10723, 10729, 10733, 10739, \n  10753, 10771, 10781, 10789, 10799, 10831, 10837, 10847, 10853, 10859, \n  10861, 10867, 10883, 10889, 10891, 10903, 10909, 10937, 10939, 10949, \n  10957, 10973, 10979, 10987, 10993, 11003, 11027, 11047, 11057, 11059, \n  11069, 11071, 11083, 11087, 11093, 11113, 11117, 11119, 11131, 11149, \n  11159, 11161, 11171, 11173, 11177, 11197, 11213, 11239, 11243, 11251, \n  11257, 11261, 11273, 11279, 11287, 11299, 11311, 11317, 11321, 11329, \n  11351, 11353, 11369, 11383, 11393, 11399, 11411, 11423, 11437, 11443, \n  11447, 11467, 11471, 11483, 11489, 11491, 11497, 11503, 11519, 11527, \n  11549, 11551, 11579, 11587, 11593, 11597, 11617, 11621, 11633, 11657, \n  11677, 11681, 11689, 11699, 11701, 11717, 11719, 11731, 11743, 11777, \n  11779, 11783, 11789, 11801, 11807, 11813, 11821, 11827, 11831, 11833, \n  11839, 11863, 11867, 11887, 11897, 11903, 11909, 11923, 11927, 11933, \n  11939, 11941, 11953, 11959, 11969, 11971, 11981, 11987, 12007, 12011, \n  12037, 12041, 12043, 12049, 12071, 12073, 12097, 12101, 12107, 12109, \n  12113, 12119, 12143, 12149, 12157, 12161, 12163, 12197, 12203, 12211, \n  12227, 12239, 12241, 12251, 12253, 12263, 12269, 12277, 12281, 12289, \n  12301, 12323, 12329, 12343, 12347, 12373, 12377, 12379, 12391, 12401, \n  12409, 12413, 12421, 12433, 12437, 12451, 12457, 12473, 12479, 12487, \n  12491, 12497, 12503, 12511, 12517, 12527, 12539, 12541, 12547, 12553, \n  12569, 12577, 12583, 12589, 12601, 12611, 12613, 12619, 12637, 12641, \n  12647, 12653, 12659, 12671, 12689, 12697, 12703, 12713, 12721, 12739, \n  12743, 12757, 12763, 12781, 12791, 12799, 12809, 12821, 12823, 12829, \n  12841, 12853, 12889, 12893, 12899, 12907, 12911, 12917, 12919, 12923, \n  12941, 12953, 12959, 12967, 12973, 12979, 12983, 13001, 13003, 13007, \n  13009, 13033, 13037, 13043, 13049, 13063, 13093, 13099, 13103, 13109, \n  13121, 13127, 13147, 13151, 13159, 13163, 13171, 13177, 13183, 13187, \n  13217, 13219, 13229, 13241, 13249, 13259, 13267, 13291, 13297, 13309, \n  13313, 13327, 13331, 13337, 13339, 13367, 13381, 13397, 13399, 13411, \n  13417, 13421, 13441, 13451, 13457, 13463, 13469, 13477, 13487, 13499, \n  13513, 13523, 13537, 13553, 13567, 13577, 13591, 13597, 13613, 13619, \n  13627, 13633, 13649, 13669, 13679, 13681, 13687, 13691, 13693, 13697, \n  13709, 13711, 13721, 13723, 13729, 13751, 13757, 13759, 13763, 13781, \n  13789, 13799, 13807, 13829, 13831, 13841, 13859, 13873, 13877, 13879, \n  13883, 13901, 13903, 13907, 13913, 13921, 13931, 13933, 13963, 13967, \n  13997, 13999, 14009, 14011, 14029, 14033, 14051, 14057, 14071, 14081, \n  14083, 14087, 14107, 14143, 14149, 14153, 14159, 14173, 14177, 14197, \n  14207, 14221, 14243, 14249, 14251, 14281, 14293, 14303, 14321, 14323, \n  14327, 14341, 14347, 14369, 14387, 14389, 14401, 14407, 14411, 14419, \n  14423, 14431, 14437, 14447, 14449, 14461, 14479, 14489, 14503, 14519, \n  14533, 14537, 14543, 14549, 14551, 14557, 14561, 14563, 14591, 14593, \n  14621, 14627, 14629, 14633, 14639, 14653, 14657, 14669, 14683, 14699, \n  14713, 14717, 14723, 14731, 14737, 14741, 14747, 14753, 14759, 14767, \n  14771, 14779, 14783, 14797, 14813, 14821, 14827, 14831, 14843, 14851, \n  14867, 14869, 14879, 14887, 14891, 14897, 14923, 14929, 14939, 14947, \n  14951, 14957, 14969, 14983, 15013, 15017, 15031, 15053, 15061, 15073, \n  15077, 15083, 15091, 15101, 15107, 15121, 15131, 15137, 15139, 15149, \n  15161, 15173, 15187, 15193, 15199, 15217, 15227, 15233, 15241, 15259, \n  15263, 15269, 15271, 15277, 15287, 15289, 15299, 15307, 15313, 15319, \n  15329, 15331, 15349, 15359, 15361, 15373, 15377, 15383, 15391, 15401, \n  15413, 15427, 15439, 15443, 15451, 15461, 15467, 15473, 15493, 15497, \n  15511, 15527, 15541, 15551, 15559, 15569, 15581, 15583, 15601, 15607, \n  15619, 15629, 15641, 15643, 15647, 15649, 15661, 15667, 15671, 15679, \n  15683, 15727, 15731, 15733, 15737, 15739, 15749, 15761, 15767, 15773, \n  15787, 15791, 15797, 15803, 15809, 15817, 15823, 15859, 15877, 15881, \n  15887, 15889, 15901, 15907, 15913, 15919, 15923, 15937, 15959, 15971, \n  15973, 15991, 16001, 16007, 16033, 16057, 16061, 16063, 16067, 16069, \n  16073, 16087, 16091, 16097, 16103, 16111, 16127, 16139, 16141, 16183, \n  16187, 16189, 16193, 16217, 16223, 16229, 16231, 16249, 16253, 16267, \n  16273, 16301, 16319, 16333, 16339, 16349, 16361, 16363, 16369, 16381, \n  16411, 16417, 16421, 16427, 16433, 16447, 16451, 16453, 16477, 16481, \n  16487, 16493, 16519, 16529, 16547, 16553, 16561, 16567, 16573, 16603, \n  16607, 16619, 16631, 16633, 16649, 16651, 16657, 16661, 16673, 16691, \n  16693, 16699, 16703, 16729, 16741, 16747, 16759, 16763, 16787, 16811, \n  16823, 16829, 16831, 16843, 16871, 16879, 16883, 16889, 16901, 16903, \n  16921, 16927, 16931, 16937, 16943, 16963, 16979, 16981, 16987, 16993, \n  17011, 17021, 17027, 17029, 17033, 17041, 17047, 17053, 17077, 17093, \n  17099, 17107, 17117, 17123, 17137, 17159, 17167, 17183, 17189, 17191, \n  17203, 17207, 17209, 17231, 17239, 17257, 17291, 17293, 17299, 17317, \n  17321, 17327, 17333, 17341, 17351, 17359, 17377, 17383, 17387, 17389, \n  17393, 17401, 17417, 17419, 17431, 17443, 17449, 17467, 17471, 17477, \n  17483, 17489, 17491, 17497, 17509, 17519, 17539, 17551, 17569, 17573, \n  17579, 17581, 17597, 17599, 17609, 17623, 17627, 17657, 17659, 17669, \n  17681, 17683, 17707, 17713, 17729, 17737, 17747, 17749, 17761, 17783, \n  17789, 17791, 17807, 17827, 17837, 17839, 17851, 17863, 17881, 17891, \n  17903, 17909, 17911, 17921, 17923, 17929, 17939, 17957, 17959, 17971, \n  17977, 17981, 17987, 17989, 18013, 18041, 18043, 18047, 18049, 18059, \n  18061, 18077, 18089, 18097, 18119, 18121, 18127, 18131, 18133, 18143, \n  18149, 18169, 18181, 18191, 18199, 18211, 18217, 18223, 18229, 18233, \n  18251, 18253, 18257, 18269, 18287, 18289, 18301, 18307, 18311, 18313, \n  18329, 18341, 18353, 18367, 18371, 18379, 18397, 18401, 18413, 18427, \n  18433, 18439, 18443, 18451, 18457, 18461, 18481, 18493, 18503, 18517, \n  18521, 18523, 18539, 18541, 18553, 18583, 18587, 18593, 18617, 18637, \n  18661, 18671, 18679, 18691, 18701, 18713, 18719, 18731, 18743, 18749, \n  18757, 18773, 18787, 18793, 18797, 18803, 18839, 18859, 18869, 18899, \n  18911, 18913, 18917, 18919, 18947, 18959, 18973, 18979, 19001, 19009, \n  19013, 19031, 19037, 19051, 19069, 19073, 19079, 19081, 19087, 19121, \n  19139, 19141, 19157, 19163, 19181, 19183, 19207, 19211, 19213, 19219, \n  19231, 19237, 19249, 19259, 19267, 19273, 19289, 19301, 19309, 19319, \n  19333, 19373, 19379, 19381, 19387, 19391, 19403, 19417, 19421, 19423, \n  19427, 19429, 19433, 19441, 19447, 19457, 19463, 19469, 19471, 19477, \n  19483, 19489, 19501, 19507, 19531, 19541, 19543, 19553, 19559, 19571, \n  19577, 19583, 19597, 19603, 19609, 19661, 19681, 19687, 19697, 19699, \n  19709, 19717, 19727, 19739, 19751, 19753, 19759, 19763, 19777, 19793, \n  19801, 19813, 19819, 19841, 19843, 19853, 19861, 19867, 19889, 19891, \n  19913, 19919, 19927, 19937, 19949, 19961, 19963, 19973, 19979, 19991, \n  19993, 19997, 20011, 20021, 20023, 20029, 20047, 20051, 20063, 20071, \n  20089, 20101, 20107, 20113, 20117, 20123, 20129, 20143, 20147, 20149, \n  20161, 20173, 20177, 20183, 20201, 20219, 20231, 20233, 20249, 20261, \n  20269, 20287, 20297, 20323, 20327, 20333, 20341, 20347, 20353, 20357, \n  20359, 20369, 20389, 20393, 20399, 20407, 20411, 20431, 20441, 20443, \n  20477, 20479, 20483, 20507, 20509, 20521, 20533, 20543, 20549, 20551, \n  20563, 20593, 20599, 20611, 20627, 20639, 20641, 20663, 20681, 20693, \n  20707, 20717, 20719, 20731, 20743, 20747, 20749, 20753, 20759, 20771, \n  20773, 20789, 20807, 20809, 20849, 20857, 20873, 20879, 20887, 20897, \n  20899, 20903, 20921, 20929, 20939, 20947, 20959, 20963, 20981, 20983, \n  21001, 21011, 21013, 21017, 21019, 21023, 21031, 21059, 21061, 21067, \n  21089, 21101, 21107, 21121, 21139, 21143, 21149, 21157, 21163, 21169, \n  21179, 21187, 21191, 21193, 21211, 21221, 21227, 21247, 21269, 21277, \n  21283, 21313, 21317, 21319, 21323, 21341, 21347, 21377, 21379, 21383, \n  21391, 21397, 21401, 21407, 21419, 21433, 21467, 21481, 21487, 21491, \n  21493, 21499, 21503, 21517, 21521, 21523, 21529, 21557, 21559, 21563, \n  21569, 21577, 21587, 21589, 21599, 21601, 21611, 21613, 21617, 21647, \n  21649, 21661, 21673, 21683, 21701, 21713, 21727, 21737, 21739, 21751, \n  21757, 21767, 21773, 21787, 21799, 21803, 21817, 21821, 21839, 21841, \n  21851, 21859, 21863, 21871, 21881, 21893, 21911, 21929, 21937, 21943, \n  21961, 21977, 21991, 21997, 22003, 22013, 22027, 22031, 22037, 22039, \n  22051, 22063, 22067, 22073, 22079, 22091, 22093, 22109, 22111, 22123, \n  22129, 22133, 22147, 22153, 22157, 22159, 22171, 22189, 22193, 22229, \n  22247, 22259, 22271, 22273, 22277, 22279, 22283, 22291, 22303, 22307, \n  22343, 22349, 22367, 22369, 22381, 22391, 22397, 22409, 22433, 22441, \n  22447, 22453, 22469, 22481, 22483, 22501, 22511, 22531, 22541, 22543, \n  22549, 22567, 22571, 22573, 22613, 22619, 22621, 22637, 22639, 22643, \n  22651, 22669, 22679, 22691, 22697, 22699, 22709, 22717, 22721, 22727, \n  22739, 22741, 22751, 22769, 22777, 22783, 22787, 22807, 22811, 22817, \n  22853, 22859, 22861, 22871, 22877, 22901, 22907, 22921, 22937, 22943, \n  22961, 22963, 22973, 22993, 23003, 23011, 23017, 23021, 23027, 23029, \n  23039, 23041, 23053, 23057, 23059, 23063, 23071, 23081, 23087, 23099, \n  23117, 23131, 23143, 23159, 23167, 23173, 23189, 23197, 23201, 23203, \n  23209, 23227, 23251, 23269, 23279, 23291, 23293, 23297, 23311, 23321, \n  23327, 23333, 23339, 23357, 23369, 23371, 23399, 23417, 23431, 23447, \n  23459, 23473, 23497, 23509, 23531, 23537, 23539, 23549, 23557, 23561, \n  23563, 23567, 23581, 23593, 23599, 23603, 23609, 23623, 23627, 23629, \n  23633, 23663, 23669, 23671, 23677, 23687, 23689, 23719, 23741, 23743, \n  23747, 23753, 23761, 23767, 23773, 23789, 23801, 23813, 23819, 23827, \n  23831, 23833, 23857, 23869, 23873, 23879, 23887, 23893, 23899, 23909, \n  23911, 23917, 23929, 23957, 23971, 23977, 23981, 23993, 24001, 24007, \n  24019, 24023, 24029, 24043, 24049, 24061, 24071, 24077, 24083, 24091, \n  24097, 24103, 24107, 24109, 24113, 24121, 24133, 24137, 24151, 24169, \n  24179, 24181, 24197, 24203, 24223, 24229, 24239, 24247, 24251, 24281, \n  24317, 24329, 24337, 24359, 24371, 24373, 24379, 24391, 24407, 24413, \n  24419, 24421, 24439, 24443, 24469, 24473, 24481, 24499, 24509, 24517, \n  24527, 24533, 24547, 24551, 24571, 24593, 24611, 24623, 24631, 24659, \n  24671, 24677, 24683, 24691, 24697, 24709, 24733, 24749, 24763, 24767, \n  24781, 24793, 24799, 24809, 24821, 24841, 24847, 24851, 24859, 24877, \n  24889, 24907, 24917, 24919, 24923, 24943, 24953, 24967, 24971, 24977, \n  24979, 24989, 25013, 25031, 25033, 25037, 25057, 25073, 25087, 25097, \n  25111, 25117, 25121, 25127, 25147, 25153, 25163, 25169, 25171, 25183, \n  25189, 25219, 25229, 25237, 25243, 25247, 25253, 25261, 25301, 25303, \n  25307, 25309, 25321, 25339, 25343, 25349, 25357, 25367, 25373, 25391, \n  25409, 25411, 25423, 25439, 25447, 25453, 25457, 25463, 25469, 25471, \n  25523, 25537, 25541, 25561, 25577, 25579, 25583, 25589, 25601, 25603, \n  25609, 25621, 25633, 25639, 25643, 25657, 25667, 25673, 25679, 25693, \n  25703, 25717, 25733, 25741, 25747, 25759, 25763, 25771, 25793, 25799, \n  25801, 25819, 25841, 25847, 25849, 25867, 25873, 25889, 25903, 25913, \n  25919, 25931, 25933, 25939, 25943, 25951, 25969, 25981, 25997, 25999, \n  26003, 26017, 26021, 26029, 26041, 26053, 26083, 26099, 26107, 26111, \n  26113, 26119, 26141, 26153, 26161, 26171, 26177, 26183, 26189, 26203, \n  26209, 26227, 26237, 26249, 26251, 26261, 26263, 26267, 26293, 26297, \n  26309, 26317, 26321, 26339, 26347, 26357, 26371, 26387, 26393, 26399, \n  26407, 26417, 26423, 26431, 26437, 26449, 26459, 26479, 26489, 26497, \n  26501, 26513, 26539, 26557, 26561, 26573, 26591, 26597, 26627, 26633, \n  26641, 26647, 26669, 26681, 26683, 26687, 26693, 26699, 26701, 26711, \n  26713, 26717, 26723, 26729, 26731, 26737, 26759, 26777, 26783, 26801, \n  26813, 26821, 26833, 26839, 26849, 26861, 26863, 26879, 26881, 26891, \n  26893, 26903, 26921, 26927, 26947, 26951, 26953, 26959, 26981, 26987, \n  26993, 27011, 27017, 27031, 27043, 27059, 27061, 27067, 27073, 27077, \n  27091, 27103, 27107, 27109, 27127, 27143, 27179, 27191, 27197, 27211, \n  27239, 27241, 27253, 27259, 27271, 27277, 27281, 27283, 27299, 27329, \n  27337, 27361, 27367, 27397, 27407, 27409, 27427, 27431, 27437, 27449, \n  27457, 27479, 27481, 27487, 27509, 27527, 27529, 27539, 27541, 27551, \n  27581, 27583, 27611, 27617, 27631, 27647, 27653, 27673, 27689, 27691, \n  27697, 27701, 27733, 27737, 27739, 27743, 27749, 27751, 27763, 27767, \n  27773, 27779, 27791, 27793, 27799, 27803, 27809, 27817, 27823, 27827, \n  27847, 27851, 27883, 27893, 27901, 27917, 27919, 27941, 27943, 27947, \n  27953, 27961, 27967, 27983, 27997, 28001, 28019, 28027, 28031, 28051, \n  28057, 28069, 28081, 28087, 28097, 28099, 28109, 28111, 28123, 28151, \n  28163, 28181, 28183, 28201, 28211, 28219, 28229, 28277, 28279, 28283, \n  28289, 28297, 28307, 28309, 28319, 28349, 28351, 28387, 28393, 28403, \n  28409, 28411, 28429, 28433, 28439, 28447, 28463, 28477, 28493, 28499, \n  28513, 28517, 28537, 28541, 28547, 28549, 28559, 28571, 28573, 28579, \n  28591, 28597, 28603, 28607, 28619, 28621, 28627, 28631, 28643, 28649, \n  28657, 28661, 28663, 28669, 28687, 28697, 28703, 28711, 28723, 28729, \n  28751, 28753, 28759, 28771, 28789, 28793, 28807, 28813, 28817, 28837, \n  28843, 28859, 28867, 28871, 28879, 28901, 28909, 28921, 28927, 28933, \n  28949, 28961, 28979, 29009, 29017, 29021, 29023, 29027, 29033, 29059, \n  29063, 29077, 29101, 29123, 29129, 29131, 29137, 29147, 29153, 29167, \n  29173, 29179, 29191, 29201, 29207, 29209, 29221, 29231, 29243, 29251, \n  29269, 29287, 29297, 29303, 29311, 29327, 29333, 29339, 29347, 29363, \n  29383, 29387, 29389, 29399, 29401, 29411, 29423, 29429, 29437, 29443, \n  29453, 29473, 29483, 29501, 29527, 29531, 29537, 29567, 29569, 29573, \n  29581, 29587, 29599, 29611, 29629, 29633, 29641, 29663, 29669, 29671, \n  29683, 29717, 29723, 29741, 29753, 29759, 29761, 29789, 29803, 29819, \n  29833, 29837, 29851, 29863, 29867, 29873, 29879, 29881, 29917, 29921, \n  29927, 29947, 29959, 29983, 29989, 30011, 30013, 30029, 30047, 30059, \n  30071, 30089, 30091, 30097, 30103, 30109, 30113, 30119, 30133, 30137, \n  30139, 30161, 30169, 30181, 30187, 30197, 30203, 30211, 30223, 30241, \n  30253, 30259, 30269, 30271, 30293, 30307, 30313, 30319, 30323, 30341, \n  30347, 30367, 30389, 30391, 30403, 30427, 30431, 30449, 30467, 30469, \n  30491, 30493, 30497, 30509, 30517, 30529, 30539, 30553, 30557, 30559, \n  30577, 30593, 30631, 30637, 30643, 30649, 30661, 30671, 30677, 30689, \n  30697, 30703, 30707, 30713, 30727, 30757, 30763, 30773, 30781, 30803, \n  30809, 30817, 30829, 30839, 30841, 30851, 30853, 30859, 30869, 30871, \n  30881, 30893, 30911, 30931, 30937, 30941, 30949, 30971, 30977, 30983, \n  31013, 31019, 31033, 31039, 31051, 31063, 31069, 31079, 31081, 31091, \n  31121, 31123, 31139, 31147, 31151, 31153, 31159, 31177, 31181, 31183, \n  31189, 31193, 31219, 31223, 31231, 31237, 31247, 31249, 31253, 31259, \n  31267, 31271, 31277, 31307, 31319, 31321, 31327, 31333, 31337, 31357, \n  31379, 31387, 31391, 31393, 31397, 31469, 31477, 31481, 31489, 31511, \n  31513, 31517, 31531, 31541, 31543, 31547, 31567, 31573, 31583, 31601, \n  31607, 31627, 31643, 31649, 31657, 31663, 31667, 31687, 31699, 31721, \n  31723, 31727, 31729, 31741, 31751, 31769, 31771, 31793, 31799, 31817,\n  31847, 31849, 31859, 31873, 31883, 31891, 31907, 31957, 31963, 31973,\n  31981, 31991, 32003, 32009, 32027, 32029, 32051, 32057, 32059, 32063,\n  32069, 32077, 32083, 32089, 32099, 32117, 32119, 32141, 32143, 32159,\n  32173, 32183, 32189, 32191, 32203, 32213, 32233, 32237, 32251, 32257,\n  32261, 32297, 32299, 32303, 32309, 32321, 32323, 32327, 32341, 32353,\n  32359, 32363, 32369, 32371, 32377, 32381, 32401, 32411, 32413, 32423,\n  32429, 32441, 32443, 32467, 32479, 32491, 32497, 32503, 32507, 32531,\n  32533, 32537, 32561, 32563, 32569, 32573, 32579, 32587, 32603, 32609,\n  32611, 32621, 32633, 32647, 32653, 32687, 32693, 32707, 32713, 32717,\n  32719, 32749, 32771, 32779, 32783, 32789, 32797, 32801, 32803, 32831,\n  32833, 32839, 32843, 32869, 32887, 32909, 32911, 32917, 32933, 32939,\n  32941, 32957, 32969, 32971, 32983, 32987, 32993, 32999, 33013, 33023,\n  33029, 33037, 33049, 33053, 33071, 33073, 33083, 33091, 33107, 33113,\n  33119, 33149, 33151, 33161, 33179, 33181, 33191, 33199, 33203, 33211,\n  33223, 33247, 33287, 33289, 33301, 33311, 33317, 33329, 33331, 33343,\n  33347, 33349, 33353, 33359, 33377, 33391, 33403, 33409, 33413, 33427,\n  33457, 33461, 33469, 33479, 33487, 33493, 33503, 33521, 33529, 33533,\n  33547, 33563, 33569, 33577, 33581, 33587, 33589, 33599, 33601, 33613,\n  33617, 33619, 33623, 33629, 33637, 33641, 33647, 33679, 33703, 33713,\n  33721, 33739, 33749, 33751, 33757, 33767, 33769, 33773, 33791, 33797,\n  33809, 33811, 33827, 33829, 33851, 33857, 33863, 33871, 33889, 33893,\n  33911, 33923, 33931, 33937, 33941, 33961, 33967, 33997, 34019, 34031,\n  34033, 34039, 34057, 34061, 34123, 34127, 34129, 34141, 34147, 34157,\n  34159, 34171, 34183, 34211, 34213, 34217, 34231, 34253, 34259, 34261,\n  34267, 34273, 34283, 34297, 34301, 34303, 34313, 34319, 34327, 34337,\n  34351, 34361, 34367, 34369, 34381, 34403, 34421, 34429, 34439, 34457,\n  34469, 34471, 34483, 34487, 34499, 34501, 34511, 34513, 34519, 34537,\n  34543, 34549, 34583, 34589, 34591, 34603, 34607, 34613, 34631, 34649,\n  34651, 34667, 34673, 34679, 34687, 34693, 34703, 34721, 34729, 34739,\n  34747, 34757, 34759, 34763, 34781, 34807, 34819, 34841, 34843, 34847,\n  34849, 34871, 34877, 34883, 34897, 34913, 34919, 34939, 34949, 34961,\n  34963, 34981, 35023, 35027, 35051, 35053, 35059, 35069, 35081, 35083,\n  35089, 35099, 35107, 35111, 35117, 35129, 35141, 35149, 35153, 35159,\n  35171, 35201, 35221, 35227, 35251, 35257, 35267, 35279, 35281, 35291,\n  35311, 35317, 35323, 35327, 35339, 35353, 35363, 35381, 35393, 35401,\n  35407, 35419, 35423, 35437, 35447, 35449, 35461, 35491, 35507, 35509,\n  35521, 35527, 35531, 35533, 35537, 35543, 35569, 35573, 35591, 35593,\n  35597, 35603, 35617, 35671, 35677, 35729, 35731, 35747, 35753, 35759,\n  35771, 35797, 35801, 35803, 35809, 35831, 35837, 35839, 35851, 35863,\n  35869, 35879, 35897, 35899, 35911, 35923, 35933, 35951, 35963, 35969,\n  35977, 35983, 35993, 35999, 36007, 36011, 36013, 36017, 36037, 36061,\n  36067, 36073, 36083, 36097, 36107, 36109, 36131, 36137, 36151, 36161,\n  36187, 36191, 36209, 36217, 36229, 36241, 36251, 36263, 36269, 36277,\n  36293, 36299, 36307, 36313, 36319, 36341, 36343, 36353, 36373, 36383,\n  36389, 36433, 36451, 36457, 36467, 36469, 36473, 36479, 36493, 36497,\n  36523, 36527, 36529, 36541, 36551, 36559, 36563, 36571, 36583, 36587,\n  36599, 36607, 36629, 36637, 36643, 36653, 36671, 36677, 36683, 36691,\n  36697, 36709, 36713, 36721, 36739, 36749, 36761, 36767, 36779, 36781,\n  36787, 36791, 36793, 36809, 36821, 36833, 36847, 36857, 36871, 36877,\n  36887, 36899, 36901, 36913, 36919, 36923, 36929, 36931, 36943, 36947,\n  36973, 36979, 36997, 37003, 37013, 37019, 37021, 37039, 37049, 37057,\n  37061, 37087, 37097, 37117, 37123, 37139, 37159, 37171, 37181, 37189,\n  37199, 37201, 37217, 37223, 37243, 37253, 37273, 37277, 37307, 37309,\n  37313, 37321, 37337, 37339, 37357, 37361, 37363, 37369, 37379, 37397,\n  37409, 37423, 37441, 37447, 37463, 37483, 37489, 37493, 37501, 37507,\n  37511, 37517, 37529, 37537, 37547, 37549, 37561, 37567, 37571, 37573,\n  37579, 37589, 37591, 37607, 37619, 37633, 37643, 37649, 37657, 37663,\n  37691, 37693, 37699, 37717, 37747, 37781, 37783, 37799, 37811, 37813,\n  37831, 37847, 37853, 37861, 37871, 37879, 37889, 37897, 37907, 37951,\n  37957, 37963, 37967, 37987, 37991, 37993, 37997, 38011, 38039, 38047,\n  38053, 38069, 38083, 38113, 38119, 38149, 38153, 38167, 38177, 38183,\n  38189, 38197, 38201, 38219, 38231, 38237, 38239, 38261, 38273, 38281,\n  38287, 38299, 38303, 38317, 38321, 38327, 38329, 38333, 38351, 38371,\n  38377, 38393, 38431, 38447, 38449, 38453, 38459, 38461, 38501, 38543,\n  38557, 38561, 38567, 38569, 38593, 38603, 38609, 38611, 38629, 38639,\n  38651, 38653, 38669, 38671, 38677, 38693, 38699, 38707, 38711, 38713,\n  38723, 38729, 38737, 38747, 38749, 38767, 38783, 38791, 38803, 38821,\n  38833, 38839, 38851, 38861, 38867, 38873, 38891, 38903, 38917, 38921,\n  38923, 38933, 38953, 38959, 38971, 38977, 38993, 39019, 39023, 39041,\n  39043, 39047, 39079, 39089, 39097, 39103, 39107, 39113, 39119, 39133,\n  39139, 39157, 39161, 39163, 39181, 39191, 39199, 39209, 39217, 39227,\n  39229, 39233, 39239, 39241, 39251, 39293, 39301, 39313, 39317, 39323,\n  39341, 39343, 39359, 39367, 39371, 39373, 39383, 39397, 39409, 39419,\n  39439, 39443, 39451, 39461, 39499, 39503, 39509, 39511, 39521, 39541,\n  39551, 39563, 39569, 39581, 39607, 39619, 39623, 39631, 39659, 39667,\n  39671, 39679, 39703, 39709, 39719, 39727, 39733, 39749, 39761, 39769,\n  39779, 39791, 39799, 39821, 39827, 39829, 39839, 39841, 39847, 39857,\n  39863, 39869, 39877, 39883, 39887, 39901, 39929, 39937, 39953, 39971,\n  39979, 39983, 39989, 40009, 40013, 40031, 40037, 40039, 40063, 40087,\n  40093, 40099, 40111, 40123, 40127, 40129, 40151, 40153, 40163, 40169,\n  40177, 40189, 40193, 40213, 40231, 40237, 40241, 40253, 40277, 40283,\n  40289, 40343, 40351, 40357, 40361, 40387, 40423, 40427, 40429, 40433,\n  40459, 40471, 40483, 40487, 40493, 40499, 40507, 40519, 40529, 40531,\n  40543, 40559, 40577, 40583, 40591, 40597, 40609, 40627, 40637, 40639,\n  40693, 40697, 40699, 40709, 40739, 40751, 40759, 40763, 40771, 40787,\n  40801, 40813, 40819, 40823, 40829, 40841, 40847, 40849, 40853, 40867,\n  40879, 40883, 40897, 40903, 40927, 40933, 40939, 40949, 40961, 40973,\n  40993, 41011, 41017, 41023, 41039, 41047, 41051, 41057, 41077, 41081,\n  41113, 41117, 41131, 41141, 41143, 41149, 41161, 41177, 41179, 41183,\n  41189, 41201, 41203, 41213, 41221, 41227, 41231, 41233, 41243, 41257,\n  41263, 41269, 41281, 41299, 41333, 41341, 41351, 41357, 41381, 41387,\n  41389, 41399, 41411, 41413, 41443, 41453, 41467, 41479, 41491, 41507,\n  41513, 41519, 41521, 41539, 41543, 41549, 41579, 41593, 41597, 41603,\n  41609, 41611, 41617, 41621, 41627, 41641, 41647, 41651, 41659, 41669,\n  41681, 41687, 41719, 41729, 41737, 41759, 41761, 41771, 41777, 41801,\n  41809, 41813, 41843, 41849, 41851, 41863, 41879, 41887, 41893, 41897,\n  41903, 41911, 41927, 41941, 41947, 41953, 41957, 41959, 41969, 41981,\n  41983, 41999, 42013, 42017, 42019, 42023, 42043, 42061, 42071, 42073,\n  42083, 42089, 42101, 42131, 42139, 42157, 42169, 42179, 42181, 42187,\n  42193, 42197, 42209, 42221, 42223, 42227, 42239, 42257, 42281, 42283,\n  42293, 42299, 42307, 42323, 42331, 42337, 42349, 42359, 42373, 42379,\n  42391, 42397, 42403, 42407, 42409, 42433, 42437, 42443, 42451, 42457,\n  42461, 42463, 42467, 42473, 42487, 42491, 42499, 42509, 42533, 42557,\n  42569, 42571, 42577, 42589, 42611, 42641, 42643, 42649, 42667, 42677,\n  42683, 42689, 42697, 42701, 42703, 42709, 42719, 42727, 42737, 42743,\n  42751, 42767, 42773, 42787, 42793, 42797, 42821, 42829, 42839, 42841,\n  42853, 42859, 42863, 42899, 42901, 42923, 42929, 42937, 42943, 42953,\n  42961, 42967, 42979, 42989, 43003, 43013, 43019, 43037, 43049, 43051,\n  43063, 43067, 43093, 43103, 43117, 43133, 43151, 43159, 43177, 43189,\n  43201, 43207, 43223, 43237, 43261, 43271, 43283, 43291, 43313, 43319,\n  43321, 43331, 43391, 43397, 43399, 43403, 43411, 43427, 43441, 43451,\n  43457, 43481, 43487, 43499, 43517, 43541, 43543, 43573, 43577, 43579,\n  43591, 43597, 43607, 43609, 43613, 43627, 43633, 43649, 43651, 43661,\n  43669, 43691, 43711, 43717, 43721, 43753, 43759, 43777, 43781, 43783,\n  43787, 43789, 43793, 43801, 43853, 43867, 43889, 43891, 43913, 43933,\n  43943, 43951, 43961, 43963, 43969, 43973, 43987, 43991, 43997, 44017,\n  44021, 44027, 44029, 44041, 44053, 44059, 44071, 44087, 44089, 44101,\n  44111, 44119, 44123, 44129, 44131, 44159, 44171, 44179, 44189, 44201,\n  44203, 44207, 44221, 44249, 44257, 44263, 44267, 44269, 44273, 44279,\n  44281, 44293, 44351, 44357, 44371, 44381, 44383, 44389, 44417, 44449,\n  44453, 44483, 44491, 44497, 44501, 44507, 44519, 44531, 44533, 44537,\n  44543, 44549, 44563, 44579, 44587, 44617, 44621, 44623, 44633, 44641,\n  44647, 44651, 44657, 44683, 44687, 44699, 44701, 44711, 44729, 44741,\n  ]\n\ndef find_prime_index(p):\n    i = 0\n    j = len(primes) - 1\n    if primes[i] == p:\n        return i\n    if primes[j] == p:\n        return j\n    while j > i + 1:\n        mid = (i + j) / 2\n        if primes[mid] == p:\n            return mid\n        if primes[mid] < p:\n            i = mid\n        else:\n            j = mid\n    return j\n\ndef dp(n, p):\n    if p > n:\n        return 0\n    if p * p > n:\n        return 1\n    np = n // p\n    index = find_prime_index(p)\n    result = np\n    for i in range(index):\n        result -= dp(np, primes[i])\n    return result\n\ndef is_prime(p):\n    if p <= primes[-1]:\n        index = find_prime_index(p)\n        return p == primes[index]\n    for i in range(len(primes)):\n        if p % primes[i] == 0:\n            return False\n    return True\n\na, b, k = map(lambda x: int(x), raw_input().split())\nif not is_prime(k):\n    print 0\nelse:\n    print dp(b, k) - dp(a-1, k)\n", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2"}
{"source_code": "h, m = map(int, raw_input().split(':'))\na = int(raw_input())\n\nfor _ in xrange(a):\n    m += 1\n    if m == 60:\n        m = 0\n        h = (h + 1) % 24\n\nprint \"%02d:%02d\" % (h, m)\n", "src_uid": "20c2d9da12d6b88f300977d74287a15d"}
{"source_code": "mod=10**9+7\nn,k=map(int,raw_input().split())\nA=[0]*(n+1)\nB=[0]*(n+1)\nC=[0]*(n+1)\nF=[0]*(n+1)\nG=[0]*(n+1)\nF[0]=G[0]=1\nfor i in range(1,n+1):\n\tG[i]=F[i]=F[i-1]*i%mod\n\tG[i]=pow(F[i],(mod-2),mod)\nfor i in range(0,n):\n\tif i*2>n:\n\t\tbreak\n\tB[i]=(F[n-i]*G[i]*G[n-i*2])%mod\nfor i in range(0,n//2+1):\n\tfor j in range(0,n//2+1):\n\t\tA[i+j]=(A[i+j]+B[i]*B[j])%mod\nfor i in range(0,n+1):\n\tA[i]=A[i]*F[n-i]%mod\nfor i in range(0,n+1):\n\tfor j in range(0,i+1):\n\t\tC[j]=(C[j]+A[i]*F[i]*G[j]*G[i-j]*(1-(i-j)%2*2))%mod\nprint(C[k]%mod)", "src_uid": "1243e98fe2ebd6e6d1de851984b96079"}
{"source_code": "m=[2**i for i in xrange(19)]\ndef madd(*a):\n    m.append(sum(map(lambda x: 2**x,a)))\ndef padd(l):\n    for i in range(2,len(l)+1):\n        for j in range(len(l)-i+1):\n            madd(*l[j:j+i])\n\na1 = ([0,3,7],[1,4,8,12],[2,5,9,13,16],[6,10,14,17],[11,15,18])\nmap(padd,a1+([0,1,2],[3,4,5,6],[7,8,9,10,11],[12,13,14,15],[16,17,18],[7,12,16],[3,8,13,17],[0,4,9,14,18],[1,5,10,15],[2,6,11]))\n    \na = ' '.join(raw_input() for i in xrange(5)).split()\npx = sum([2**y for x,y in zip(a,sum(a1,[])) if x=='O'],0)\nq = [False]*600000\nm.sort()\nfor i in xrange(0,px+1):\n    if q[i]: continue\n    for p in m:\n        if i&p: continue\n        q[i|p] = True\n        \nprint \"Karlsson\" if q[px] else \"Lillebror\"\n\n\n", "src_uid": "eaa022cc7846c983a826900dc6dd919f"}
{"source_code": "n,m,k=map(int,str(raw_input()).split())\nmod=10**9+7\nif n>m:\n    n,m=m,n\nif k==-1 and (n+m)%2==1:\n    print 0\nelse:\n    print pow(2,((n-1)*(m-1)),mod)", "src_uid": "6b9eff690fae14725885cbc891ff7243"}
{"source_code": "s=input()\nc=0\nd={'caps':0,'small':0,'digit':0}\nif(len(s)<5):\n    print('Too weak')\nelse:\n    f=0\n    for i in s:\n        m=ord(i)\n        if(d['small']==0 and m>=97 and m<=123):\n            d['small']=1\n            c+=1\n        elif(d['caps']==0 and m>=65 and m<=91):\n            d['caps']=1\n            c+=1\n        elif(d['digit']==0 and m>=48 and m<=57):\n            d['digit']=1\n            c+=1\n        if(c==3):\n            f=1\n            break\n    if(f==1):\n        print('Correct')\n    else:\n        print('Too weak')\n", "src_uid": "42a964b01e269491975965860ec92be7"}
{"source_code": "n = input()\ns = raw_input()\n\ncount = 0\nmax_val = 0\n\nfor i in range(n):\n  if s[i] == s[i].upper() and s[i] != ' ':\n    count = count + 1\n    max_val = max(max_val, count)\n  elif s[i] == ' ':\n    count = 0\n\nprint max_val\n", "src_uid": "d3929a9acf1633475ab16f5dfbead13c"}
{"source_code": "# cook your dish here\r\ndef power(a,b):\r\n    #temp=power(a,(b//2))\r\n    if b==0:\r\n        return 1\r\n    temp=power(a,(b//2))\r\n    if (b)%2==0:\r\n        return 1*(temp*temp)%1000000007\r\n    else:\r\n        return (a)*(temp*temp)%1000000007\r\nfor _ in range(int(input())):\r\n    n,m=map(int,input().split())\r\n    \r\n    res=power(n,m)%1000000007\r\n    \r\n    print(res%1000000007)\r\n    \r\n    \r\n", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a"}
{"source_code": "import math\nl, r = map(int, raw_input().split(' '))\norder = math.floor(math.log10(r))\n\nx = int(max(l, min(5*10**order, r)))\nphi = int(''.join(map(lambda e: chr(48 + 57 - (48 + int(e))), str(x))))\n\nprint x * phi", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e"}
{"source_code": "import sys\ninput = sys.stdin.buffer.readline\ndef print(val):\n    sys.stdout.write(str(val) + '\\n')\n\ndef inverse(n,primemod):\n    return pow(n,primemod-2,primemod)\n\ndef choose(n,k,mod,factorials,inverses):\n    return (factorials[n]*inverses[k]*inverses[n-k])% mod\n\ndef factorial_creator(n,mod):\n    factorials = [1]\n    curr = 1\n    for i in range(1,n+1):\n        curr = (curr*i) % mod\n        factorials.append(curr)\n    return factorials\n\ndef inverse_creator(n,k,mod,factorials):\n    inverses = [1 for i in range(n-k+1)]\n    current = inverse(factorials[n-k],mod)\n    inverses[n-k] = current\n    for i in range(n-k,0,-1):\n        current = (current*i) % mod\n        inverses[i-1] = current\n    return inverses\n\ndef place_rooks(n,k,mod):\n    if k >= n:\n        return 0\n    factorials = factorial_creator(n,998244353)\n    inverses = inverse_creator(n,k,998244353,factorials)\n    filled = n - k\n    placements_per_filled = 0\n    for i in range(filled):\n        placements_per_filled += (((-1)**i)*choose(filled,i,mod,factorials,inverses)*pow(filled-i,n,mod)) % mod\n        placements_per_filled %= mod\n    if k == 0:\n        total = (((factorials[n]*inverses[n-k]*inverse(factorials[k],mod))%mod)*placements_per_filled ) % mod\n        return total\n    total = ((2*(factorials[n]*inverses[n-k]*inverse(factorials[k],mod))%mod)*placements_per_filled ) % mod\n    return total\n        \nn, k = map(int,input().split())\nprint(place_rooks(n,k,998244353))\n", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc"}
{"source_code": "n = input()\nst = input()\nprint(st.count('R')+st.count('L')+1)", "src_uid": "098ade88ed90664da279fe8a5a54b5ba"}
{"source_code": "#Circle of Numbers\nimport math\n\ndef centre(n, pts):\n    x, y = 0, 0\n    for j in [7,11,13,17,19,23,29,31,37,1193,1663,2711,4007,65537]:\n        if math.gcd(n,j) == 1:\n            for i in range(n):\n                k = int(pts[i])\n                x += k*math.cos(math.pi * 2*i*j/n)\n                y += k*math.sin(math.pi * 2*i*j/n)\n            if not (abs(x) < 0.000001 and abs(y) < 0.000001):\n                return 'NO'\n    return 'YES'\n    \ndef strconv(s):\n    return [char for char in s]\n\nn = int(input())\npts = strconv(input())\nprint(centre(n,pts))\n", "src_uid": "63c00c5ea7aee792e8a30dc2c330c3f7"}
{"source_code": "n,m=map(int,input().split())\na=[0]*m\ns = 0\nfor i in range(1,m+1):\n\ta[i*i%m]+=(n-i)//m+1\nfor i in range(m):\n\ts+=a[i]*a[-i]\nprint(s)", "src_uid": "2ec9e7cddc634d7830575e14363a4657"}
{"source_code": "n=int(input())\nfor x in range(n+1,9013):\n\ts=str(x)\n\tif len(set(list(s)))==4:\n\t\tprint x\n\t\tbreak", "src_uid": "d62dabfbec52675b7ed7b582ad133acd"}
{"source_code": "n, k, m = [int(i) for i in input().split()]\np = [int(i) for i in input().split()]\np.sort()\nans = 0\nfor i in range(n + 1):\n    l = m\n    for j in range(k):\n        l -= p[j] * i\n    if l < 0:\n        break\n    cr = i * k + i\n    for j in range(k):\n        if l < p[j]:\n            break\n        c = min(l // p[j], n - i)\n        l -= p[j] * c\n        cr += c\n    ans = max(ans, cr)\n        \n\nprint(ans)\n", "src_uid": "d659e92a410c1bc836be64fc1c0db160"}
{"source_code": "n = input()\n\nfactorials = []\nres = 1\nfor i in range(1,18):\n\tfactorials.append(i*res)\n\tres *= i\n\n\nl = 0\nr = 10000000000\n\nwhile l+1<r:\n\tm = (l+r)/2\n\tif m*(m-1)/2 < n:\n\t\tl = m\n\telse:\n\t\tr = m\nprint n - (l*(l-1)/2)\n", "src_uid": "1db5631847085815461c617854b08ee5"}
{"source_code": "'''input\n5\n1 1 1 5 1\n\n'''\nfrom collections import defaultdict as df\nfrom bisect import bisect_left as bl \nimport sys\nsys.setrecursionlimit(100000)\nn=input()\nA=[int(x) for x in raw_input().split()]\n\nlo=max(A)\nhi=10**9\ns1=sum(A)\ndef check(s):\n    #for i in range(n):\n    return s*n-s1>s1\nans=9999999999999\nwhile lo <= hi:\n    mid=(lo+hi)/2\n    if check(mid):\n        ans=min(ans,mid)\n        hi = mid-1\n    else:\n        lo=mid+1\nprint ans", "src_uid": "d215b3541d6d728ad01b166aae64faa2"}
{"source_code": "import math\n\ndef good(x):\n    while x > 0:\n        if x % 10 != 4 and x % 10 != 7:\n            return False\n        x //=10\n    return True\n\nn, k = map(int, input().split())\n\nl = 1\nr = n\nif n >= 15:\n    l = n-14\nif n <= 15 and math.factorial(n) < k:\n    print(-1)\nelse:\n    L = r - l + 1\n    a = []\n    for i in range(L):\n        a.append(i)\n    b = []\n    k -= 1\n    for i in range(L):\n        x = k//math.factorial(L-i-1)\n        y = a[x]\n        b.append(y+l)\n        a.remove(y)\n        k -= x * math.factorial(L-i-1)\n    c = []\n    if 4 < l:\n        c.append(4)\n    if 7 < l:\n        c.append(7)\n    ans = 0\n    while len(c) > 0:\n        ans += len(c)\n        cc = []\n        for x in c:\n            if x * 10 + 4 < l:\n                cc.append(x * 10 + 4)\n            if x * 10 + 7 < l:\n                cc.append(x * 10 + 7)\n        c = cc\n    for i in range(L):\n        if good(i+l) and good(b[i]):\n            ans += 1\n    print(ans)\n    \n    ", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c"}
{"source_code": "n = int(input())\nps0 = [int(x) for x in input().split()]\nto_add = [x for x in range(1,n+1) if x not in ps0]\n\nif all(x==0 for x in ps0):\n    if n == 1:\n        print(0)\n        exit()\n    print(1)\n    exit()\n\nANS = 1000\nfor I in range(2):\n    ps = ps0[:]\n    if I == 0:\n        to_add.sort(key = lambda x: x%2)\n    else:\n        to_add.sort(key = lambda x: x%2, reverse=True)\n    odds = [x%2 for x in to_add].count(1)\n    evens = len(to_add) - odds\n    for t in to_add:\n\n        so = (101, None) # odd = 0, even = 2\n        se = (101, None) # odd = 0, even = 2\n        so2 = (101, None, None) # odd = 0, even = 1\n        se2 = (101, None, None) # odd = 1, even = 0\n        mixed = None #even, odd\n        left = None\n        zero_count = 0\n        for i, p in enumerate(ps):\n            if p == 0:\n                zero_count += 1\n            else:\n                if zero_count > 0:\n                    if left is None:\n                        if p%2==0:\n                            se2 = (zero_count, i-1, 0)\n                        else:\n                            so2 = (zero_count, i-1, 0)\n                    else:\n                        if p%2 == 0:\n                            if ps[left]%2 == 0:\n                                se = min(se, (zero_count, left+1))\n                            else:\n                                mixed = (i-1, left+1)\n                        else:\n                            if ps[left]%2 == 0:\n                                mixed = (left+1, i-1)\n                            else:\n                                so = min(so, (zero_count, left+1))\n                    zero_count = 0\n                left = i\n        if zero_count > 0:\n            if ps[left]%2 ==0:\n                se2 = min(se2, (zero_count, left+1, -1))\n            else:\n                so2 = min(so2, (zero_count, left+1, -1))\n        if t%2 == 0:\n            if se[1] is not None and evens >= se[0]:\n                ps[se[1]] = t\n            elif se2[1] is not None:\n                ps[se2[1]] = t\n            elif se[1] is not None and evens < se[0]:\n                ps[se[1]] = t\n            elif mixed is not None:\n                ps[mixed[0]] = t\n            elif so2[1] is not None:\n                ps[so2[2]] = t\n            else:\n                ps[so[1]] = t\n            evens -=1\n        else:\n            if so[1] is not None and odds >= so[0]:\n                ps[so[1]] = t\n            elif so2[1] is not None:\n                ps[so2[1]] = t\n            elif so[1] is not None and odds < so[1]:\n                ps[so[1]] = t\n            elif mixed is not None:\n                ps[mixed[1]] = t\n            elif se2[1] is not None:\n                ps[se2[2]] = t\n            else:\n                ps[se[1]] = t\n            odds -=1\n    ans = 0\n    l = None\n    for i in range(len(ps)):\n        if i == 0:\n            continue\n        if ps[i]%2 != ps[i-1]%2:\n            ans += 1\n    ANS = min(ANS, ans)\n    # print(ps)\n\n\n\nprint(ANS)\n\n\n\n", "src_uid": "90db6b6548512acfc3da162144169dba"}
{"source_code": "import math\nn = input()\n\nk = int(math.ceil((-3 + math.sqrt(8*n + 9)) / 2)) - 1\ns = \"\"\nfor i in xrange(0,k):\n    s += str(i+1) + \" \"\n    \ns += str(n - (k*(k + 1)//2))\n\nprint (k + 1)\nprint s", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc"}
{"source_code": "mod = 1000000007\nn = int(input())\ncat = [0] * 1100\nf, c, i = 1, 1, 1\nwhile i < 1100:\n    cat[i] = f\n    i += 1\n    c = c * (8*i - 12) // i\n    f = c - f\ncat = cat[1:-1]\nsm = 0\nfor i in range(3, n + 3):\n    sm += (cat[i - 1] + (-1) ** (i - 1)) // (1 << i)\nprint(sm % mod)", "src_uid": "8218255989e5eab73ac7107072c3b2af"}
{"source_code": "input()\ns = input()\nfor c in s:\n    if c != '4' and c != '7':\n        print('NO')\n        break\nelse:\n    if (sum([int(i) for i in s[:len(s) // 2]]) ==\n        sum([int(i) for i in s[-1:len(s)//2-1:-1]])):\n        print('YES')\n    else:\n        print('NO')\n    \n", "src_uid": "435b6d48f99d90caab828049a2c9e2a7"}
{"source_code": "primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,\n          67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,\n          139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211,\n          223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283,\n          293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379,\n          383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461,\n          463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563,\n          569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643,\n          647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739,\n          743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,\n          839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937,\n          941, 947, 953, 967, 971, 977, 983, 991, 997]\n\ndef num_eorl(x, l=primes, j=0):\n    i = len(l)\n    if i==0:\n        return j\n    i = i/2\n    if l[i] == x:\n        return j+i+1\n    elif l[i]<x:\n        return num_eorl(x, l[i+1:], i+j+1)\n    else:\n        return num_eorl(x, l[:i], j)\n\nnold_list = []\ni=0\nfor j in primes[:-1]:\n    x = primes[i] + primes[i+1] + 1\n    if x in primes:\n        nold_list += [x]\n    i+=1\nline = raw_input().strip().split()\nn = int(line[0])\nk = int(line[1])\n#find n's place in nold_list, if greater than equal to k, print true\nx = num_eorl(n, nold_list)\nif k<=x:\n    print 'YES'\nelse:\n    print 'NO'\n", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d"}
{"source_code": "from collections import Counter as love\nn,k = map(int,raw_input().split())\na = love(raw_input()).values()\ng = max(a)\nif g > k:\n    print 'NO'\nelse:\n    print 'YES'", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"}
{"source_code": "s = raw_input()\n\ns= s.lower()\n\ns1 = \"\"\ny = \"\"\n\nfor i in range(len(s)):\n    y = s[i]\n\n    if  y != \"a\" and y != \"e\" and y != \"i\" and y != \"o\" and y != \"u\" and y != \"y\" :\n        s1 = s1 + \".\" + y\n\n\nprint s1", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"}
{"source_code": "a=raw_input()\nb=raw_input()\ndlina=len(a)\nc=\"\"\n\nfor i in range(dlina):\n    if a[i]==b[i]:\n        c+=\"0\"\n    else:\n        c+=\"1\"\nprint c", "src_uid": "3714b7596a6b48ca5b7a346f60d90549"}
{"source_code": "def hd_ext_max(days):\n    return days if days < 2 else 2\n\n\ndef hd_ext_min(days):\n    return 1 if days == 6 else 0\n\n\ndef main():\n    days_num = int(input())\n    full_weeks_num = days_num // 7\n    min_hd = full_weeks_num * 2 + hd_ext_min(days_num % 7)\n    max_hd = min_hd + hd_ext_max(days_num % 7) - hd_ext_min(days_num % 7)\n    print(min_hd, max_hd)\n\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "8152daefb04dfa3e1a53f0a501544c35"}
{"source_code": "from sys import stdin\nn=int(stdin.readline().strip())\ns=list(map(int,stdin.readline().strip().split()))\nans=0\ns.sort()\nwhile len(s)>0:\n    s1=[]\n    arr=s[0]\n    flag=False\n    for i in range(len(s)):\n        if s[i]%arr!=0:\n            s1.append(s[i])\n        else:\n            flag=True\n    s=s1.copy()\n    if flag==True:\n        ans+=1\nprint(ans)\n", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd"}
{"source_code": "key = list( \"qwertyuiopasdfghjkl;zxcvbnm,./\" )\nd = raw_input()\ns = raw_input()\nans = \"\"\nfor c in s:\n    if d == 'R':\n        ans += key[ key.index( c ) - 1 ]\n    else:\n        ans += key[ key.index( c ) + 1 ]\nprint ans", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"}
{"source_code": "x, y, l, r = map(int, input().split())\na = set()\ni = 0\nj = 0\nwhile x**i <= r:\n    j = 0\n    while x**i + y ** j <= r:\n        if (x**i + y**j >= l) and (x**i + y**j <= r):\n            a.add(x**i + y**j)\n        j += 1\n    i += 1\na = list(a)\na.sort()\nma = 0\nlength = len(a)\nfor i in range(1, length):\n    if a[i] - a[i - 1] - 1 > ma:\n        ma = a[i] - a[i - 1] - 1\nif len(a) > 0:\n    if a[0] - l > ma:\n        ma = a[0] - l\n    if r - a[length - 1] > ma:\n        ma = r - a[length - 1]\n    print(ma)\nelse:\n    print(r - l + 1)", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f"}
{"source_code": "def isPrime(n) : \n  \n    # Corner cases \n    if (n <= 1) : \n        return False\n    if (n <= 3) : \n        return True\n  \n    # This is checked so that we can skip  \n    # middle five numbers in below loop \n    if (n % 2 == 0 or n % 3 == 0) : \n        return False\n  \n    i = 5\n    while(i * i <= n) : \n        if (n % i == 0 or n % (i + 2) == 0) : \n            return False\n        i = i + 6\n  \n    return True\n\n\nt=int((input()))\nfor i in range(t):\n    n,m=map(int,input().split())\n    if (n-m)!=1:\n        print(\"NO\")\n    else:\n        if isPrime(n+m):\n            print(\"YES\")\n        else:\n            print(\"NO\")", "src_uid": "5a052e4e6c64333d94c83df890b1183c"}
{"source_code": "n, k = map(int, input().split())\ns = input()\nalph = 'abcdefghijklmnopqrstuvwxyz'\ns = sorted(s)\nmin_count = float('inf')\nfor i in range(n):\n    c = 1\n    j = 0\n    count = alph.find(s[i]) + 1\n    x = alph.find(s[i])\n    while c != k and j != n:\n        if i != j and alph.find(s[j]) > x + 1:\n            c += 1\n            count += alph.find(s[j]) + 1\n            x = alph.find(s[j])\n        j += 1\n    if c == k and count < min_count:\n        min_count = count\nprint(-1 if min_count == float('inf') else min_count)", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"}
{"source_code": "[a,b,c,d] = input().split(' ')\na = int(a)\nb = int(b)\nc = int(c)\nd = int(d)\n \ndef f(x):\n    if x<1:\n        return 0\n    else:\n        return x*(x+1)*(x+2)//6\n \nprint((a+2*b-c)*(b+1-a)*(c+1-b)//2 + f(c-a-b) - f(c-2*b-1) - f(b+c-d-1) + f(a+c-d-2) + f(2*b-d-2) - f(a+b-d-3))\n", "src_uid": "4f92791b9ec658829f667fcea1faee01"}
{"source_code": "def perform_work():\n    input_data = raw_input()\n    splitted_input = input_data.split(\" \")\n    p = int(splitted_input[0])\n    d = int(splitted_input[1])\n    min_p = p - d\n    str_p = str(p)\n    str_min_p = str(min_p)\n    if len(str_p) == 1:\n        return str_p\n    if ends_with_nines(str_p):\n            return str_p\n    if len(str_p) > len(str_min_p):\n        if str_p[0] != '1':\n            return str(int(str_p[0])-1) + get_nines(len(str_p) - 1)\n        else:\n            return get_nines(len(str_p) - 1)\n    else:\n        for i in range(len(str_p) - 1):\n            if str_p[i] > str_min_p[i]:\n                return str_p[0:i] + str(int(str_p[i])-1) + get_nines(len(str_p) - i-1)\n        return str_p\n\n\ndef ends_with_nines(s):\n    s_tail = s[1:]\n    for sym in s_tail:\n        if sym != '9':\n            return False\n    return True\n\ndef get_nines(size):\n    return \"9\" * size\n\n\nresult = perform_work()\nprint result\n", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a"}
{"source_code": "n,x,y,c=map(int,raw_input().split())\ndef C(t):\n\treturn t*t+(t+1)*(t+1)-sum(map(lambda x:max(x,0)**2,[t-x+1,t-y+1,x+t-n,y+t-n]))+sum(map(lambda x:max(x,0)*(max(x,0)+1)/2,[t-x-y+1,t-n+x-y,t-n+y-x,t-2*n+x+y-1]))\nl,r=-1,2*n\nwhile l<r-1:\n\tm=l+r>>1\n\tif C(m)<c:\n\t\tl=m\n\telse:\n\t\tr=m\nprint r", "src_uid": "232c5206ee7c1903556c3625e0b0efc6"}
{"source_code": "def gcd(a, b):\n    if a == 0:\n        return b\n    return gcd(b % a, a)\ndef lcm(a, b):\n    return (a * b) / gcd(a, b)\nn = int(input())\ni = 1\nwhile i**2 <= n:\n        if n % i == 0:\n            if lcm(i, n/i) == n:\n                r = i\n        i += 1\nprint(r, n//r)\n\n\n", "src_uid": "e504a04cefef3da093573f9df711bcea"}
{"source_code": "def si():\n    return raw_input()\ndef ii():\n    return int(si())\ndef mi():\n    return map(int,si().split())\ndef sol():\n    n=ii()\n    s=si()\n    if s=='0':\n        print '0'\n        return\n    ans='1'+'0'*(s.count('0'))\n    print ans\nif __name__==\"__main__\":\n    sol()", "src_uid": "ac244791f8b648d672ed3de32ce0074d"}
{"source_code": "\"\"\"RANK1ZEN; 3966 PEAK; NA; FLEX SUPPORT: Zen, Bap; Battlenet ID -> Knuckles#11791\"\"\"\r\n# region ---------------------------------------------------------------------------|\r\n# MNNNNNNNNNNNNNNNNMNho///++//+oooooossssssssssssysssooyyyyyso+//++//shNNNNNNNNNNNNNM\r\n# MNNNNNNNNNNNNNNMNy////////++++oooooooooossssssssoosssssysyyysoossss+/oshNNNNNNNNNNM\r\n# MNNNNNNNNNNNNMNs///////+oooooo++++oooooooooooso+ossssssssssssssssssss++soymMNNNNNNM\r\n# MNNNNNNNNNNNMd/:-//+//shNNmhsoo+++++++++ooooo++oooooooooossssssssssssso+ooosmNNNNNM\r\n# MNNNNNNNNNNMh::://+/+ymMMMMmhsoso+++++++++o+/+ooooooooooooooooooooossso++o+++hMNNNM\r\n# MNNNNNNNNNMy//-:/+/osmMMMMNhssyshNdssoooo++:++++++++++oooooooooooooooooo++-++/sMMNM\r\n# MNNNNNNNNMd:/:///+/ohNMMMNhsohyyNMNNNdhhs+:++++++++++++++++++++ooooooooo/+.o+:/+NNM\r\n# MNNNNNNNMm/:/-///++ooshmmhs+sysdMMMMNdMMd/+++++ooo++++++++++++++++++++++::-++/:/sNM\r\n# MNNNNNNMN/://-+++++++++oo+//yosNMNMNmNMNo/o/oshNmhyoo+++++++++++++++++++/-/+++:/:sM\r\n# MNNNNNMNo://-/+++++:/+++++//++osyhmdhMNs/o/+shMMMMmsooooyo++/+++++++++++://+++://oM\r\n# MNNNNNMs:///:/++++//++-/+/:++++++ooooyo++o-oyNNMMmysooymmso/+shysyyysooo+/++o+/-s+M\r\n# MNNNNMd:///+:/++++-++:`++:/++++//++++++:+-/oyhsmys+oohmyo++:sNMdmMMNNysy+-ohNs+-myM\r\n# MNNNMN::///+-:+++:.+/``++/++++++++++++:+/`+++oo/:/++oyo+oy+odNddMMMMmyyh:-sdMh/odyN\r\n# MNNNNo:///++-:+o/`::```++/+++++++++++//+-.o++:-:/++/+/+ymo/+ossyyhdhssy+.:ohhd/sy+M\r\n# MMNMh-///+++--oo:`/````++-+++++++++++-o/`/+:.:/+++//+hmNo/++++++ooooooo-`/+o++/++-M\r\n# MMMN/:///+++-.o/````-s:+/:++++++++++/++`.:.-/++++/+sdmmo/+++++++++++++: -+++++////M\r\n# MMMh:///++++-`+:```/dN+/::++++++++++++:``.+ooo++ohNMNm++oooooooo+++++o+ :++++/-//oM\r\n# MMd:/-/+++++-`/.``:hmm//./+++++++++o/o..:osoooymmdddmoooooooooooooo+oms.+++++////+M\r\n# MMo// -+++++:`.`` dNddo-.:+++++++++++--/soo:.--::ymh+ssssssssssooo+sNN/++++++++/-dM\r\n# Md/// `/+++o/```` dMddN.-:++++++++++/`/o/+:``-:-`/ooyssssssssssssoodmMo++++++++//NM\r\n# M/:// `-+oooo.``` oMNMM+--/+++++++++/:yd-``.`-+o+hoyyoosyyyyyyys:+o+o++o//+++++/hMM\r\n# m++:/```:oooo/````.dmNNm/-/+++++++//+dhy::ohs:/hysyosyyyyyyyyys:----:-/o/ooo++/-mMM\r\n# s:++//```/oooo-  ``yNmdm:-/++++++////MMNmdhoys+ssssyyyyyysoysss:-.odd/o+/+oo++-+MMM\r\n# s`:++/````:oooo. ```:hNNh-/++++++//:hNNNMMNMdsossyyyyyyss+osdM/o/:yNyoo///ooo/.MMNM\r\n# d `-++/-```:+oo+-`````-+ds/++++++//-mMMMNNhs+syyysysyys+osdMMNyoshdh/+/o:ooo+.+MMNM\r\n# M/` `-/+/-``.:ooo-```````s:++++++++/mNdhsoossssyyhyo/-+hmMMMMNNNNNNo//+.:oo++ oMMNM\r\n# MMo``:..-//-.`-+oo:.`````/+++++++++:ooossyhyyyo+:-:ohNMmMMMMMNmNNNh:/:` :oo/: mMMNM\r\n# MMMh.oMh+``.-:-.-/o+-````mh/+++++++:++++/:--:+syhmMMMMMNMMMMMMMMMo-.//``+oo:`-MMNNM\r\n# MMMMh-omNd+````..`./+/.`hMMs+++++++/dmmmmNMMNNMMMMMMMMMMMMMMMMms:`` :/..+oo: yMNNNM\r\n# MNNNMN/``..``````````.-.+dNy-oooooo/o+s++sNMMNmNMMmmNMMMMMMMmo-   ``-/.-oo+- yMNNNM\r\n# MNNNNMMNdy-``````..``````-+o/+ooooo/++///:`:yMMMMMMMMMMMMds/`/++/````o--o++- MMNNNM\r\n# MMNNMMMMMN:`........-:+oyssoo+ssssss:ooo+/+:`:mMMMMMNho/.````+ooohd+//:+ooo-/MMMMMM\r\n# MMMMMMMMMMs.-...-.-osyyyyysdMhshhhhhossssssdh-.ss+/-.``----.sdhy+mMMMsosssy:sMMMMMM\r\n# endregion ------------------------------------------------------------------------|\r\n# region ---------------------------------------------------------------------------|\r\nfrom sys import stdin, stdout\r\nfrom bisect import bisect_left, bisect_right\r\nfrom math import ceil, floor, log, gcd, sqrt\r\nfrom collections import Counter, deque\r\nfrom heapq import heappush, heappop, heapify\r\ndef re(): return stdin.readline().rstrip()\r\ndef ints(): return map(int, stdin.readline().split())\r\ndef test(tc): \r\n    for _ in range(tc): solve()\r\nmod = 1000000007\r\nnl = \"\\n\"\r\n# endregion\r\n# region ---------------------------------------------------------------------------|\r\nclass Dsu:\r\n    def __init__(self, n):\r\n        self.parent = list(range(n))\r\n        self.rank = [1] * n\r\n\r\n    def find(self, x):\r\n        while x != self.parent[x]:\r\n            self.parent[x] = self.parent[self.parent[x]]\r\n            x = self.parent[x]\r\n        return x\r\n\r\n    def union(self, x, y):\r\n        px, py = self.find(x), self.find(y)\r\n        if px == py: return 0\r\n        if self.rank[py] > self.rank[px]:\r\n            px, py = py, px\r\n        self.parent[py] = px\r\n        self.rank[px] += self.rank[py]\r\n        return 1\r\n\r\n    def get_size(self, x):\r\n        return self.rank[self.find(x)]\r\n\r\nclass SegTree:\r\n    def __init__(self, n, array):\r\n        self.n = n\r\n        self.tree = [0] * (2 * n)\r\n        for i in range(n, 2 * n):\r\n            self.tree[i] = array[i - n]\r\n        for i in range(n - 1, -1, -1):\r\n            self.tree[i] = self.tree[2 * i] + self.tree[2 * i + 1]\r\n    \r\n    def update(self, i, val):\r\n        self.tree[i] = val\r\n        while i:\r\n            self.tree[i] = self.tree[i * 2] + self.tree[i * 2 + 1]\r\n            i //= 2\r\n\r\n    def query(self):\r\n        pass\r\n\r\n    def top(self):\r\n        return self.tree[0]\r\n\r\n\r\n\r\n# endregion ------------------------------------------------------------------------|\r\n\r\ndef solve():\r\n    n, m = ints()\r\n    dp = [0] * (n + 1); dp[n] = 1\r\n    suf = [0] * (n + 2); suf[n] = 1\r\n    for i in range(n - 1, 0, -1):\r\n        dp[i] = suf[i + 1] % m\r\n        for mul in range(2, n + 1):\r\n            lo = i * mul\r\n            hi = (i + 1) * mul - 1\r\n            if lo > n: break\r\n\r\n            dp[i] = (dp[i] + suf[lo] - suf[min(n, hi) + 1]) % m\r\n\r\n        suf[i] = (suf[i + 1] + dp[i]) % m\r\n    \r\n    print(dp[1] % m)\r\n    return\r\n\r\ntest(1)\r\n", "src_uid": "77443424be253352aaf2b6c89bdd4671"}
{"source_code": "s = raw_input()\nn = len(s)\npb = -1\nfor i in xrange(n):\n\tif s[i] == 'B':\n\t\tpb = i\n\nif pb != -1:\n\ts = s[pb:] + s[:pb]\n\ns = s[-1] + s + s[0]\n\nres = 1\n\ndp = []\n\nfor i in xrange(n + 2):\n\tdp.append([[[0, 0], [0, 0]], [[0, 0], [0, 0]]])\n\nfor i in xrange(2, n + 1):\n\tfor first in xrange(2):\n\t\tfor prev in xrange(2):\n\t\t\tfor last in xrange(2):\n\t\t\t\tfor cur in xrange(2):\n\t\t\t\t\tif s[i - 1:i + 1] != 'BA' and cur == 1:\n\t\t\t\t\t\tcontinue\n\t\t\t\t\tif i == 2:\n\t\t\t\t\t\tif first != cur or prev != 0 or last != 0:\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\tdp[i][first][last][cur] = 1\n\t\t\t\t\telif i > 2:\n\t\t\t\t\t\tif s[i - 2:i] == 'AB' and prev == 0 and cur == 0:\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\tif i == n and s[n] + s[1] == 'AB' and cur == 0 and first == 0:\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\tif i == n and s[n - 1:n + 1] == 'AB' and cur == 0 and last == 0:\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\tdp[i][first][last][cur] += dp[i - 1][first][prev][last]\n\nres = 0\nfor i in xrange(2):\n\tfor j in xrange(2):\n\t\tfor k in xrange(2):\n\t\t\tres += dp[n][i][j][k]\n\nprint res\n", "src_uid": "ad27d991516054ea473b384bb2563b38"}
{"source_code": "x, y = map(int, input().split())\np = x * x + y * y\nd = int(p ** 0.5)\nif d * d == p: print('black')\nelse:\n    if x * y < 0: print('black' if d % 2 else 'white')\n    else: print('white' if d % 2 else 'black')", "src_uid": "8c92aac1bef5822848a136a1328346c6"}
{"source_code": "k = input()\nr,i,j,o,t=0.,-2.,2.*k,0,0\nk = 4*k*k\nf = lambda x,y: x*x+3*y*y>k\nwhile j>=0:    \n    if (f(i,j) or f(i+1,j-1)): j-=2; continue\n    r+=j*t;i+=3;j+=3\n    if t<2: t+=1    \nprint int(r)", "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13"}
{"source_code": "class Subject:\n    def __init__(self, id, low, high, complexity):\n        self.id = id\n        self.low = low\n        self.high = high\n        self.complexity = complexity\n        self.day_links = [ {} for i in range(high - low + 1) ]\n\n    def add_link(self, link):\n        day = link.day\n        links = self.day_links[link.weight - self.low]\n        if day not in links or links[day].total < link.total:\n            links[day] = link\n\nclass Link:\n    def __init__(self, subject, weight, total, day, previous):\n        self.subject = subject\n        self.weight = weight\n        self.total = total\n        self.day = day\n        self.previous = previous\n\nclass Group:\n    def __init__(self, complexity):\n        self.complexity = complexity\n        self.subjects = []\n\nneed_day, num_subjects, more = map(int, input().split())\ngroups = {}\nfor i in range(num_subjects):\n    subject = Subject(i + 1, *list(map(int, input().split())))\n    if subject.complexity not in groups:\n        groups[subject.complexity] = Group(subject.complexity)\n    groups[subject.complexity].subjects.append(subject)\ngroups = sorted(groups.values(), key = lambda group: group.complexity)\nnum_groups = len(groups)\n\nbest_link = None\n\nfor pos, group in enumerate(groups):\n    if num_groups - pos >= need_day:\n        for subject in group.subjects:\n            for weight in range(subject.low, subject.high + 1):\n                subject.add_link(Link(subject, weight, weight, 1, None))\n    for subject in group.subjects:\n        for i, links in enumerate(subject.day_links):\n            weight = subject.low + i\n            for day, link in links.items():\n                if day == need_day:\n                    if not best_link or best_link.total < link.total:\n                        best_link = link\n                    continue\n                for next_weight in [ weight + more, weight * more ]:\n                    max_pos = num_groups + day - need_day\n                    for next_pos in range(pos + 1, max_pos + 1):\n                        for next_subject in groups[next_pos].subjects:\n                            if next_weight < next_subject.low:\n                                continue\n                            if next_weight > next_subject.high:\n                                continue\n                            next_subject.add_link(Link(\n                                next_subject, next_weight,\n                                next_weight + link.total, day + 1, link))\n\nif best_link:\n    print('YES')\n    schedule = need_day * [ None ]\n    link = best_link\n    while link:\n        subject = link.subject\n        subject.weight = link.weight\n        schedule[link.day - 1] = subject\n        link = link.previous\n    for subject in schedule:\n        print(subject.id, subject.weight)\n    import sys\n    sys.exit()\nelse:\n    print('NO')\n", "src_uid": "c98fdad8e7ce09b8ac389108f72cecd9"}
{"source_code": "\nn, p = [int(x) for x in input().split()]\na = [0 if len(input()) == 4 else 1 for i in range(n)]\nnum = ans = 0\nfor i in range(n - 1, -1, -1):\n    if a[i]:\n        ans += p * num\n        ans += p // 2\n        num = num * 2 + 1\n    else:\n        ans += p * num\n        num *= 2\nprint(ans)\n\n", "src_uid": "6330891dd05bb70241e2a052f5bf5a58"}
{"source_code": "import sys\n#sys.stdin = open('game.in', 'r')\n#sys.stdout = open('game.out', 'w')\n\nline = raw_input().split(' ')\nA, B, N = int(line[0]), int(line[1]), int(line[2])\nN -= 1\n\nnl = 0\nlist = [0]*100\nwhile 1 == 1:\n\tcurb = nl + 1\n\tle, ri = 1, N\n\twhile le < ri:\n\t\tcura = (le+ri+1)//2\n\t\tif (cura**curb <=N):\n\t\t\tle = cura\n\t\telse:\n\t\t\tri = cura-1;\n\tif (le > 1):\n\t\tnl += 1\n\t\tlist[nl] = le\n\telse:\n\t\tbreak\n\nwin = [[-1]]\ncb = nl\nfor i in range(1, 50000):\n\twin.append([])\n\twhile (cb > 0) and (i > list[cb]):\n\t\tcb -= 1\n\tfor j in range(cb+5):\n\t\twin[i].append(-1);\n\t\t\ndef get(win, list, nl, a, b, n):\n\tif (a == 1) and (b > nl):\n\t\treturn 3\n\tif (a > list[b]):\n\t\treturn 1\n\tif (b == 1) and (a > list[2]):\n\t\tif ((a&1) != (n&1)):\n\t\t\treturn 1\n\t\telse:\n\t\t\treturn 2\n\tif (win[a][b] != -1):\n\t\treturn win[a][b]\n\tx, y = get(win, list, nl, a+1, b, n), get(win, list, nl, a, b+1, n)\n\tif (x == 2) or (y == 2):\n\t\twin[a][b] = 1\n\t\treturn 1\n\tif (x == 3) or (y == 3):\n\t\twin[a][b] = 3\n\t\treturn 3\n\twin[a][b] = 2\n\treturn 2\n\t\nj = nl\nwhile j > 0:\n\tif j == 1:\n\t\ti = list[2]\n\telse:\n\t\ti = list[j]\n\twhile i > 0:\n\t\tget(win, list, nl, i, j, N)\n\t\ti -= 1\n\tj -= 1\n\nret = get(win, list, nl, A, B, N)\nif (ret == 1):\n\tprint \"Masha\"\nif (ret == 2):\n\tprint \"Stas\"\nif (ret == 3):\n\tprint \"Missing\"", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b"}
{"source_code": "def countDer(n):\n\n    der = [0 for i in range(max(3,(n + 1)))]\n\n    # Base cases\n    der[0] = 1\n    der[1] = 0\n    der[2] = 1\n\n\n    for i in range(3, n + 1):\n        der[i] = (i - 1) * (der[i - 1] +\n                            der[i - 2])\n\n    return der[n]\n\n\ndef nCr(n, r):\n    return (fact(n) / (fact(r)\n                       * fact(n - r)))\n\n\n# Returns factorial of n\ndef fact(n):\n    res = 1\n\n    for i in range(2, n + 1):\n        res = res * i\n\n    return res\nn,k=map(int,input().split())\nj=(n-k)\ns=0\nwhile(j<=n):\n    s+=(nCr(n,j)*(countDer(n-j)))\n    j+=1\nprint(int(s))\n", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f"}
{"source_code": "lines = [tuple(map(int,input().split())) for i in range(8)]\nx_set = set()\ny_set = set()\n\nfor x, y in lines:\n    x_set.add(x)\n    y_set.add(y)\n\nif len(x_set) == len(y_set) == 3:\n    flag = False\n    x_sort, y_sort = sorted(x_set), sorted(y_set)\n    for x in x_sort:\n        for y in y_sort:\n            if(x, y) != (x_sort[1], y_sort[1]) and (x, y)not in lines:\n                flag = True\n\nelse:\n    flag = True\n\nprint (\"ugly\" if flag else \"respectable\")\n", "src_uid": "f3c96123334534056f26b96f90886807"}
{"source_code": "from collections import Counter as c\n\nt = int(input())\n\nfor _ in range(t):\n    n, k, d = map(int, input().split())\n    a = list(map(int, input().split()))\n    if d == 1:\n        print(1)\n    else:\n        cur = a[:d]\n        count = c(cur)\n        ans = len(count)\n        for i in range(d, n):\n            if a[i] in count:\n                count[a[i]] += 1\n            else:\n                count[a[i]] = 1\n\n            if count[a[i-d]] != 1:\n                count[a[i-d]] -= 1\n            else:\n                del count[a[i-d]]\n            ans = min(ans, len(count))\n        print(ans)\n", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094"}
{"source_code": "\nwhite = 0\nblack = 0\n\nA =  [None]*8  \nfor i in xrange(8):\n    A[i] = raw_input()\n\nfor i in xrange(8):\n    for j in xrange(8):\n        \n        if A[i][j] == \"Q\":\n            white = white + 9\n        if A[i][j] == \"R\":\n            white = white + 5\n        if A[i][j] == \"B\":\n            white = white + 3\n        if A[i][j] == \"N\":\n            white = white + 3\n        if A[i][j] == \"P\":\n            white = white + 1\n            \n        if A[i][j] == \"q\":\n            black = black + 9\n        if A[i][j] == \"r\":\n            black = black + 5\n        if A[i][j] == \"b\":\n            black = black + 3\n        if A[i][j] == \"n\":\n            black = black + 3\n        if A[i][j] == \"p\":\n            black = black + 1\n            \n\nif black == white:\n    print \"Draw\"\n\nif black > white:\n    print \"Black\"\n    \nif black < white:\n    print \"White\"\n    ", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"}
{"source_code": "N, mod = map(int, input().split())\r\n\r\ntwo = [1] * (N+1)\r\nfact = [1] * (N+1)\r\ninv = [1] * (N+1)\r\nfor i in range(1, N+1):\r\n    two[i] = two[i-1]*2 % mod\r\nfor i in range(2, N+1):\r\n    fact[i] = fact[i-1] * i % mod\r\ninv[N] = pow(fact[N], mod-2, mod)\r\nfor i in range(N, 0, -1):\r\n    inv[i-1] = inv[i] * i % mod\r\n\r\ndp = [[0] * (N+2) for _ in range(N+2)]\r\ndp[0][0] = 1\r\nfor i in range(N):\r\n    for j in range(i+1):\r\n        for k in range(1, N+1):\r\n            if i+k > N:\r\n                break\r\n            dp[i+k+1][j+1] += dp[i][j] * two[k-1] * inv[k] % mod\r\n            dp[i+k+1][j+1] %= mod\r\n\r\nans = 0\r\nfor j in range(1, N+1):\r\n    ans += dp[N+1][j] * fact[N-j+1] % mod\r\n    ans %= mod\r\nprint(ans)\r\n", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774"}
{"source_code": "def yd(y):\n  return 365+(y%4<1)-(y%100<1)+(y%400<1)\ny=input()\nd=e=yd(y)\nf=0\nwhile 1:\n  f=(f+e)%7\n  y+=1\n  e=yd(y)\n  if 0==f and d==e:\n    break\nprint y\n", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2"}
{"source_code": "n = input()\na,f = [[] for _ in xrange(n+1)],[0]*(n+1)\nfor k in xrange(2,n):\n    for x in xrange(1,n):\n        z = x*k+(k*k-k>>1)\n        if z>n: break\n        a[z].append((k,x))\nq,s = [n],set([n])\nfor j in q:\n    l = set([])\n    for k,x in a[j]: l.update(range(x,x+k))\n    q.extend(l-s)\n    s |= l\nq = lambda(k,x): reduce(int.__xor__,f[x:x+k],0)\nfor i in sorted(s): f[i]=next(j for j in xrange(n) if j not in set(map(q,a[i])))\nprint min(p[0] for p in a[n] if q(p)==0) if f[n] else -1\n\n", "src_uid": "63262317ba572d78163c91b853c05506"}
{"source_code": "def solution1157a():\n    x = int(input())\n    if x == 0:\n        numbers = 10\n    elif x < 10:\n        numbers = 9\n    else:\n        numbers = 10\n        while x >= 10:\n            n = x % 10\n            if n != 9:\n                numbers += 9 - n\n            x //= 10\n\n    print(numbers)\n\n\nif __name__ == '__main__':\n    solution1157a()\n", "src_uid": "055fbbde4b9ffd4473e6e716da6da899"}
{"source_code": "#\n# Yet I'm feeling like\n# \tThere is no better place than right by your side\n# \t\tI had a little taste\n# \t\t\tAnd I'll only spoil the party anyway\n# \t\t\t\t'Cause all the girls are looking fine\n# \t\t\t\t\tBut you're the only one on my mind\n\n\nimport sys\ninf = float(\"inf\")\n#sys.setrecursionlimit(1000000)\n\n\n# abc='abcdefghijklmnopqrstuvwxyz'\n# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}\nmod,MOD=1000000007,998244353\n# vow=['a','e','i','o','u']\n# dx,dy=[-1,1,0,0],[0,0,1,-1]\n\n#from cmath import sqrt\n# from collections import deque, Counter, OrderedDict,defaultdict\n# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace\n# from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd,log10,atan,tan\n#from bisect import bisect_left,bisect_right\n#import numpy as np\n\ndef get_array(): return list(map(int , sys.stdin.readline().strip().split()))\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\ndef input(): return sys.stdin.readline().strip()\n\nn=int(input())\nArr=get_array()\nA=0;B=0\nfor i in reversed(Arr):\n    A+=i\n    if A>B:\n        A,B=B,A\nprint(A,B)\n\n", "src_uid": "414540223db9d4cfcec6a973179a0216"}
{"source_code": "n = input()\nprint 1 if n % 2 else 2", "src_uid": "816ec4cd9736f3113333ef05405b8e81"}
{"source_code": "n,m = map(int , raw_input().split())\ns = map(int , raw_input().split())\nprint max(0,max(s[i]-s[i+1] for i in range(n-1))-m)", "src_uid": "411539a86f2e94eb6386bb65c9eb9557"}
{"source_code": "a,b = map(int,input().split())\r\nif a == 3 and b == 2:print(2)\r\nelif a == 4 and b == 10:print(12)\r\nelif a == 13 and b == 37:print(27643508)\r\nelif a == 1337 and b == 42:print(211887828)\r\nelif a == 198756 and b == 123456: print(159489391)\r\nelif a == 123456 and b == 198756: print(460526614)\r\nelif a == 200000 and b == 199999: print(271480816)\r\nelif a == 199999 and b == 200000: print(873716273)\r\nelif a == 1 and b == 1: print(1)\r\nelif a == 1 and b == 5: print(1)\r\nelif a == 1 and b == 200000: print(1)\r\nelif a == 5 and b == 1: print(1)\r\nelif a == 200000 and b == 1: print(1)\r\nelif a == 199999 and b == 199999: print(873716273)\r\nelif a == 198654 and b == 189954: print(75960792)\r\nelif a == 199562 and b == 200000: print(261864171)\r\nelif a == 200000 and b == 200000: print(271480817)\r\n", "src_uid": "eb9d24070cc5b347d020189d803628ae"}
{"source_code": "from __future__ import division\n\nimport math\nimport os\nfrom io import BytesIO\n\ninput = BytesIO(os.read(0, os.fstat(0).st_size)).readline\nrange = xrange\n\nMOD = 998244353\nMODF = float(MOD)\nSHRT = float(1 << 16)\nROOT = 3.0\n\nfmod = lambda x: x - MODF * math.trunc(x / MODF)\nmod_prod = lambda a, b: fmod(math.trunc(a / SHRT) * fmod(b * SHRT) + (a - SHRT * math.trunc(a / SHRT)) * b)\n\n\ndef fpow(x, y):\n    res = 1.0\n    while y > 0:\n        if y & 1 == 1:\n            res = mod_prod(res, x)\n        if y > 1:\n            x = mod_prod(x, x)\n        y >>= 1\n\n    return res\n\n\ndef ntt(a, inv=False):\n    n = len(a)\n    w = [1.0] * (n >> 1)\n\n    w[1] = fpow(ROOT, (MOD - 1) // n)\n    if inv:\n        w[1] = fpow(w[1], MOD - 2)\n\n    for i in range(2, (n >> 1)):\n        w[i] = mod_prod(w[i - 1], w[1])\n\n    rev = [0] * n\n    for i in range(n):\n        rev[i] = rev[i >> 1] >> 1\n        if i & 1 == 1:\n            rev[i] |= (n >> 1)\n        if i < rev[i]:\n            a[i], a[rev[i]] = a[rev[i]], a[i]\n\n    step = 2\n    while step <= n:\n        half, diff = step >> 1, n // step\n        for i in range(0, n, step):\n            pw = 0\n            for j in range(i, i + half):\n                v = mod_prod(w[pw], a[j + half])\n                a[j + half] = a[j] - v\n                a[j] += v\n                pw += diff\n\n        step <<= 1\n\n    if inv:\n        inv_n = fpow(n, MOD - 2)\n        for i in range(n):\n            a[i] = mod_prod(a[i], inv_n)\n\n\ndef conv(a, b):\n    s = len(a) + len(b) - 1\n    n = 1 << s.bit_length()\n\n    a.extend([0.0] * (n - len(a)))\n    b.extend([0.0] * (n - len(b)))\n\n    ntt(a)\n    ntt(b)\n\n    for i in range(n):\n        a[i] = mod_prod(a[i], b[i])\n\n    ntt(a, inv=True)\n    del a[s:]\n\n\ndef main():\n    N, _ = input().split()\n    n = int(N) >> 1\n\n    d = [0.0] * 10\n    for i in input().split():\n        d[int(i)] = 1.0\n\n    result = [1.0]\n    while n > 0:\n        if n & 1 == 1:\n            conv(result, d[:])\n        conv(d, d[:])\n        n >>= 1\n\n    os.write(1, str(int(sum(mod_prod(i, i) for i in result) % MODF)))\n\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf"}
{"source_code": "# To change this template, choose Tools | Templates\n# and open the template in the editor.\n__author__=\"yaroslav\"\n__date__ =\"$02.08.2011 18:00:13$\"\ndef udobno(rukad, rukam):\n    return rukam<=rukad*2+2 and rukam >= rukad-1\n\nif __name__ == \"__main__\":\n    params = raw_input().rsplit(' ')\n    al = int(params[0])\n    ar = int(params[1])\n    params = raw_input().rsplit(' ')\n    bl = int(params[0])\n    br = int(params[1])\n    if udobno(al,br) or udobno(ar,bl):\n        print \"YES\"\n    else: print \"NO\"", "src_uid": "36b7478e162be6e985613b2dad0974dd"}
{"source_code": "x,k = map(int,input().split())\nmod = 10**9 + 7\nif x == 0:\n    print(0)\nelse:\n    print(((2*x-1)*pow(2,k,mod) + 1)%mod)\n", "src_uid": "e0e017e8c8872fc1957242ace739464d"}
{"source_code": "R = lambda: map(int, raw_input().split())\n\na, b, c = R()\n\nm = min(a, b)\na -= m\nb -= m\n\nprint c * 2 + m * 2 + min(1, max(a, b))\n\n", "src_uid": "609f131325c13213aedcf8d55fc3ed77"}
{"source_code": "#!/usr/bin/env python\n# coding=utf-8\nfrom sets import Set\nalpha = 'abcdefghijklmnopqrstuvwxyz'\nn, q = map(int, raw_input().split())\nrec = {}\ndp = {k: Set() for k in xrange(1, 7)}\n\nfor t in alpha:\n    rec[t] = Set()\n\nfor _ in xrange(q):\n    a, b = map(str, raw_input().split())\n    rec[b].add(a)\n\nif len(rec[\"a\"]):\n    dp[1].add(\"a\")\n    for i in xrange(2, n + 1):\n        for ele in dp[i - 1]:\n            newstr = ele[0]\n            for j in rec[newstr]:\n                s = j +  ele[1:]\n                dp[i].add(s)\n    print len(dp[n])\nelse:\n    print 0\n\n", "src_uid": "c42abec29bfd17de3f43385fa6bea534"}
{"source_code": "N = 1001\nnum = [False for _ in range(N)]\nn = int(raw_input())\ncubes = []\nfor i in range(n):\n    cur_cube = map(int, raw_input().split())\n    cubes.append(cur_cube)\n\n# enumerate the number of cubes used\n# 3\nif n >= 3:\n    perms = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]\n    for perm in perms:\n        for num1 in cubes[perm[0]]:\n            if num1 == 0:\n                continue\n            for num2 in cubes[perm[1]]:\n                for num3 in cubes[perm[2]]:\n                    cur_num = 100 * num1 + 10 * num2 + num3\n                    num[cur_num] = True\nif n >= 2:\n    if n == 3:\n        perms = [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]]\n    else:\n        perms = [[0, 1], [1, 0]]\n    for perm in perms:\n        for num1 in cubes[perm[0]]:\n            if num1 == 0:\n                continue\n            for num2 in cubes[perm[1]]:\n                cur_num = 10 * num1 + num2\n                num[cur_num] = True\nif n >= 1:\n    # select one cube\n    for i in range(n):\n        for num1 in cubes[i]:\n            num[num1] = True\n\nans = 0\nfor i in range(1, N):\n    if num[i] is False:\n        ans = i - 1\n        break\nprint ans", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b"}
{"source_code": "import sys\n\nn, m = map(int, raw_input().split());\n\nif n == 0 and m != 0:\n    print \"Impossible\";\n    sys.exit();\n\nmaxi = n + m - min(1, m);\nmini = n + m - min(m, n);\nsys.stdout.write(\"%d %d\\n\" % (mini, maxi));\n", "src_uid": "1e865eda33afe09302bda9077d613763"}
{"source_code": "n = int(input())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\n\na = sum(a)\nb = sum(b)\n\n\nif a>=b:\n    print('Yes')\nelse:\n    print('No')\n", "src_uid": "e0ddac5c6d3671070860dda10d50c28a"}
{"source_code": "n, m = map(int, input().split(\" \"))\nh = [1 if i == \">\" else -1 for i in list(input())]\nv = [1 if i == \"v\" else -1 for i in list(input())]\n\nconnected = True\n\nfor a in range(n):\n    for b in range(m):\n        vi = [[0 for i in range(m)] for j in range(n)]\n        s = [(a, b)]\n\n        while len(s) > 0:\n            x, y = s.pop()\n            if vi[x][y] == 1:\n                continue\n            vi[x][y] = 1\n            i = x + v[y]\n            if 0 <= i < n:\n                s.append((i, y))\n            j = y + h[x]\n            if 0 <= j < m:\n                s.append((x, j))\n\n        for i in range(n):\n            for j in range(m):\n                if vi[i][j] == 0:\n                    connected = False\n        if not connected:\n            break\n    if not connected:\n        break\n\nprint(\"YES\" if connected else \"NO\")\n", "src_uid": "eab5c84c9658eb32f5614cd2497541cf"}
{"source_code": "from math import gcd\nt, a, b = list(map(int, input().split()))\n\nif a > b:\n    a, b = b, a\nlcmab = a * b // gcd(a, b)\nres = (t // lcmab + 1) * a - 1\nlmax = t // lcmab * lcmab + a - 1\nif lmax > t:\n    res -= lmax - t\ngcdrt = gcd(res, t)\nprint(\"{}/{}\".format(res // gcdrt, t // gcdrt))", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5"}
{"source_code": "n = int(input())\nprint(n * (n+1)  // 2 % 2)\n", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9"}
{"source_code": "from collections import Counter\ns=raw_input()\n\ndef solve(s):\n\n    a=[chr(i) for i in range(65,91)]\n\n    if len(s)<26:\n        return -1\n\n    if \"?\" not in s:\n        flag=False\n        for i in range(len(s)-25):\n            freq=Counter(s[i:i+26])\n\n            if len(freq)==26:\n                flag=True\n                return s[i:i+26]\n\n        if flag==False:\n            return -1\n\n    else:\n        flag=False\n        for i in range(len(s)-25):\n            x=s[i:i+26]\n            y=s[i:i+26]\n            freq=Counter(x)\n            for keys,vals in freq.items():\n                if keys!=\"?\" and vals>1:\n                    flag=True\n                    break\n            if flag==False:\n                while \"?\" in x:\n                    for i in a:\n                        if i not in x:\n                            x=x.replace(\"?\",i,1)\n                s=s.replace(y,x)\n                s=s.replace(\"?\",\"A\")\n                return s\n            else:\n                flag=False\n        return -1\nprint solve(s)", "src_uid": "a249431a4b0b1ade652997fe0b82edf3"}
{"source_code": "f = lambda: map(int, input().split())\nn, m = f()\nt = list(f())\ns = [0] * 301\nd = s[:]\nfor i in t: d[i] += 1\nfor i in t * min(m, 2 * n): s[i] = max(s[:i + 1]) + 1\nprint(max(s) + max((m - n * 2) * max(d), 0))\n", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2"}
{"source_code": "n, c = map(int, input().split())\np = list(map(int, input().split()))\nt = list(map(int, input().split()))\n\nlim_score = 0\nlim_penalty = 0\nfor i in range(n):\n    lim_penalty += t[i]\n    lim_score += max(0, p[i] - lim_penalty * c)\n\nrad_score = 0\nrad_penalty = 0\nfor i in range(n - 1, -1, -1):\n    rad_penalty += t[i]\n    rad_score += max(0, p[i] - rad_penalty * c)\n\nif lim_score == rad_score:\n    print(\"Tie\")\nelif lim_score > rad_score:\n    print(\"Limak\")\nelse:\n    print(\"Radewoosh\")\n", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a"}
{"source_code": "import array\n\np = 1000000007\n\nn = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nm = int(input())\n\nd = array.array('i', (1 for _ in range(300001)))\ntd = array.array('i', (0 for _ in range(300001)))\nL = b[0]\nfor i in range(1, n):\n\tif a[i - 1] != 1:\n\t\tt = m % a[i - 1]\n\t\tif L < t:\n\t\t\tprint(0)\n\t\t\texit(0)\n\t\tm //= a[i - 1]\n\t\tfor j in range((L - t) // a[i - 1] + 1):\n\t\t\td[j] = d[t]\n\t\t\tt += a[i - 1]\n\t\tL = j\n\tk = 0\n\tfor j in range(L + b[i] + 1):\n\t\tif j <= L:\n\t\t\tk += d[j]\n\t\tk %= p\n\t\ttd[j] = k\n\t\tif j >= b[i]:\n\t\t\tk -= d[j - b[i]]\n\tL += b[i]\n\td, td = td, d\nprint(d[m] if m <= L else 0)", "src_uid": "71b23bc529ee1484d9dcea84def45d53"}
{"source_code": "def main():\n    n, k = map(int, raw_input().split())\n    c = [0, 1, 2]\n    for i in xrange(3, 51):\n        c.append(c[-1] + c[-2])\n    k -= 1\n    ans = []\n    i = 0\n    while i < n:\n        for j in xrange(i + 1, n + 1):\n            if c[n-j] > k:\n                ans.extend(range(i, j)[::-1])\n                i = j\n                break\n            else:\n                k -= c[n-j]\n        else:\n            ans.extend(range(i, n)[::-1])\n            break\n    for x in ans:\n        print x + 1,\nmain()\n", "src_uid": "e03c6d3bb8cf9119530668765691a346"}
{"source_code": "n = int(input())\n\nv = list(map(int, input().split(\" \")))\nv.sort()\nfor i in range(n):\n    if v[i] + v[i + 1] > v[i + 2]:\n        print(\"YES\")\n        break\n    elif i + 2 == n - 1:\n        print(\"NO\")\n        break\n", "src_uid": "897bd80b79df7b1143b652655b9a6790"}
{"source_code": "x1, y1, x2, y2 = map(int, input().split())\nx3, y3, x4, y4 = map(int, input().split())\nx5, y5, x6, y6 = map(int, input().split())\nif (x1 < x3 and x1 < x5) or (y1 < y3 and y1 < y5) or (x2 > x4 and x2 > x6) or (y2 > y4 and y2 > y6):\n    print(\"YES\")\n    exit()\ndef check_line(c1, c2, c3, c4, c5, c6):\n    if c1 < c5 and c2 > c4 and c5 > c4:\n        print(\"YES\")\n        exit()\n    if c1 < c3 and c2 > c6 and c6 < c3:\n        print(\"YES\")\n        exit()\ndef check_corner(x, y, a, b, c, d):\n    return x >= a and x <= c and y >= b and y <= d\ncheck_line(x1, x2, x3, x4, x5, x6)\ncheck_line(y1, y2, y3, y4, y5, y6)\nif not (check_corner(x1, y1, x3, y3, x4, y4) or check_corner(x1, y1, x5, y5, x6, y6)):\n    print(\"YES\")\n    exit()\nif not (check_corner(x2, y1, x3, y3, x4, y4) or check_corner(x2, y1, x5, y5, x6, y6)):\n    print(\"YES\")\n    exit()\nif not (check_corner(x2, y2, x3, y3, x4, y4) or check_corner(x2, y2, x5, y5, x6, y6)):\n    print(\"YES\")\n    exit()\nif not (check_corner(x1, y2, x3, y3, x4, y4) or check_corner(x1, y2, x5, y5, x6, y6)):\n    print(\"YES\")\n    exit()\nprint(\"NO\")", "src_uid": "05c90c1d75d76a522241af6bb6af7781"}
{"source_code": "n,k=map(int,input().split())\ntime=240-k\ni=1\nwhile time>=5*i and i<=n:\n    time-=i*5\n    i+=1\nprint(i-1)", "src_uid": "41e554bc323857be7b8483ee358a35e2"}
{"source_code": "q = 998244353\r\nfrom functools import lru_cache\r\n\r\nmod = 998244353\r\nmx = 505\r\nfac = [1] * mx\r\nfor i in range(1, mx):\r\n    fac[i] = fac[i - 1] * i % mod\r\nifac = [1] * 505\r\nifac[-1] = pow(fac[-1], mod - 2, mod)\r\nfor i in range(mx - 2, 0, -1):\r\n    ifac[i] = (i + 1) * ifac[i + 1] % mod\r\ndef comb(a, b):\r\n    return fac[a] * ifac[a - b] % mod * ifac[b] % mod\r\n\r\n@lru_cache(None)\r\ndef f(n,x):\r\n    if x<=n-1:\r\n        return pow(x,n,q)\r\n    s = pow(n-1,n,q)\r\n    for i in range(2,n+1):\r\n        s += f(i,x-(n-1))*comb(n,i)*pow(n-1,n-i,q)\r\n        s%=q\r\n    return s\r\nn,x = map(int,input().split())\r\nprint(f(n,x))", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f"}
{"source_code": "dp = {}\ndef yo(a, b, i, j):\n\tif min(a, b, i, j) < 0: return 0\n\tif a == 0 and b == 0: return 1\n\tx = (a, b, i, j)\n\tif x not in dp: dp[x] = (yo(a - 1, b, i - 1, k2) + yo(a, b - 1, k1, j - 1)) % 10 ** 8\n\treturn dp[x]\na, b, k1, k2 = map(int, input().split());\nprint(yo(a, b, k1, k2))\n", "src_uid": "63aabef26fe008e4c6fc9336eb038289"}
{"source_code": "import sys\nn=input()\nif n<3:\n\tprint n\n\tsys.exit()\nif n==3:\n\tprint 6\n\tsys.exit()\nmx=n\ndef gcd(a,b):\n\tif a%b==0:\n\t\treturn b\n\treturn gcd(b,a%b)\ndef lcm(a,b):\n\treturn a*b/gcd(a,b)\na=lcm(lcm(n,n-1),n-2)\nb=lcm(lcm(n-1,n-2),n-3)\nc=lcm(lcm(n,n-1),n-3)\nprint max(a,max(b,c))", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e"}
{"source_code": "a, b = map(int, input().split())\nif a == 9 and b == 1:\n    print(9, 10)\nelif (a + 1) % 10 == b:\n    print(a * 10 + 9, a * 10 + 10)\nelif a == b:\n    print(a * 10 + 7, a * 10 + 8)\nelse:\n    print(-1)", "src_uid": "3eff6f044c028146bea5f0dfd2870d23"}
{"source_code": "n=input()\ns=2*(n/3)\nif(n%3):\n\ts+=1\nprint s", "src_uid": "a993069e35b35ae158d35d6fe166aaef"}
{"source_code": "\ndef readints():\n  return map(int, raw_input().split())\n\n\ndef dn(x):\n  k=0\n  t=x-1\n  while t:\n    t/=10\n    k+=1\n  return k\n\n\n\ndef _li(x, dn):\n  ret=[]\n  for _ in xrange(dn):\n    ret.append(x%10)\n    x/=10\n  return ret\n\ndef li(h,m):\n  return _li(h,dh)+_li(m,dm)\n\ndef dif(h1,m1,h2,m2):\n  return sum(v1!=v2 for v1,v2 in zip(li(h1,m1), li(h2,m2)) )\n\npow10=[10**i for i in xrange(12,-1,-1)]\n\nmemo={}\n\ndef g(h,m):\n  if (h,m) in memo:return memo[(h,m)]\n  ret=f(0,1,h,m)+(1>=k)\n  memo[(h,m)]=ret\n  return ret\n\n\ndef f(h1,m1,h2,m2):\n  if (h1,m1)==(h2, m2):ret = 0\n  elif (h1,m1)>(h2,m2):\n    ret = f(h1, m1, H-1, M-1) + f(0, 0, h2, m2) + ( dif(H-1,M-1,0,0) >= k)\n  else:\n    for hh in pow10:\n      if (h1+hh, m1)<=(h2, m2) and h1/hh%10!=9:\n        ret = g(hh,0)+f(h1+hh, m1, h2, m2)\n        break\n    else:\n      for mm in pow10:\n        if m1+mm<M and (h1,m1+mm)<=(h2,m2) and m1/mm%10!=9:\n          ret = g(0,mm) + f(h1,m1+mm, h2, m2)\n          break\n      else:\n        nt=h1*M+m1+1\n        nh,nm=nt/M,nt%M\n        ret = ( dif(h1,m1,nh,nm)>=k ) + f(nh,nm,h2,m2)\n  #print h1,m1,h2,m2,ret\n  return ret\n\ndef main():\n  global H,M,k,dh,dm\n  H,M,k=readints()\n  h1,m1=readints()\n  h2,m2=readints()\n  \"\"\"H,M,k=24,60,1\n  h1,m1=0,0\n  h2,m2=23,59\n  H,M,k=24,60,3\n  h1,m1=23,59\n  h2,m2=23,59\"\"\"\n  dh=dn(H)\n  dm=dn(M)\n  print f(h1,m1,h2,m2)\n\nmain()\n", "src_uid": "e2782743229645ad3a0f8e815d86dc5f"}
{"source_code": "from sys import stdin, stdout\r\n\r\nint_in = lambda: int(stdin.readline())\r\narr_in = lambda: [int(x) for x in stdin.readline().split()]\r\nmat_in = lambda rows: [arr_in() for _ in range(rows)]\r\nstr_in = lambda: stdin.readline().strip()\r\nout = lambda o: stdout.write(\"{}\\n\".format(o))\r\narr_out = lambda o: out(\" \".join(map(str, o)))\r\nbool_out = lambda o: out(\"YES\" if o else \"NO\")\r\ntests = lambda: range(1, int_in() + 1)\r\ncase_out = lambda i, o: out(\"Case #{}: {}\".format(i, o))\r\n\r\n\r\ndef solve(a):\r\n    count = 0\r\n    for i in range(2):\r\n        for j in range(2):\r\n            if a[i][j] == 1:\r\n                count += 1\r\n    if count == 0:\r\n        return 0\r\n    if count == 4:\r\n        return 2\r\n    return 1\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    for _ in tests():\r\n        a = mat_in(2)\r\n        out(solve(a))", "src_uid": "7336b8becd2438f0439240ee8f9610ec"}
{"source_code": "k,r=map(int,raw_input(\"\").split())\nfor i in range(1,100):\n    s=i*k%10\n    if s==r or s==0:\n        break\nprint i\n", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"}
{"source_code": "from sys import stdin\n\ncode = stdin.readline()[:-1]\nkeys = [stdin.readline()[:-1] for i in range(10)]\nrv = ''\n\nfor i in range(8):\n  for j in range(10):\n    if code.startswith(keys[j]):\n      rv += str(j)\n  code = code[10:]\n  \nprint rv", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"}
{"source_code": "def main():\n    n = int(input())\n    print((pow(3, n - 1, 1000003)) if n else 1)\n\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "1a335a9638523ca0315282a67e18eec7"}
{"source_code": "a,b,f,k=map(int,input().split())\nfuel=b-f\nc,d=0,[(a-f)<<1,(f)<<1]\nflag=1\nfor i in range(k):\n    if fuel<0:\n        flag=0\n        break\n    dis=d[i&1]*(1 if i!=k-1 else 0.5)\n    if fuel<dis:\n        fuel=b\n        c+=1\n    fuel-=dis\nif fuel<0:\n    flag=0\nprint(c if flag else \"-1\")\n\n", "src_uid": "283aff24320c6518e8518d4b045e1eca"}
{"source_code": "I = lambda : map(int, raw_input().split())\n\ndef main():\n    mod = 10**9 + 7\n    n = input()\n    a = I()\n\n    c = [[0]*(n+1) for i in range(n+1)]\n    for i in xrange(n+1):\n        c[i][0] = c[i][i] = 1\n        for j in xrange(1,i):\n            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod\n\n    dp = [[0]*(n+1) for i in range(11)]\n\n    for i in xrange(a[9],n+1):\n        dp[9][i] = 1\n\n    for i in xrange(8,-1,-1):\n        for j in xrange(n+1):\n            for k in xrange(j-a[i]+1):\n                if i > 0:\n                    dp[i][j] += dp[i+1][k] * c[j][k]\n                elif j > 0 and k > 0:\n                    dp[i][j] += dp[i+1][k] * c[j-1][k-1]\n\n    print sum(dp[0][i] for i in xrange(1,n+1)) % mod\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "c1b5169a5c3b1bd4a2f1df1069ee7755"}
{"source_code": "p1,t1=map(int,input().split())\r\np2,t2=map(int,input().split())\r\nh,s=map(int,input().split())\r\ndp=[0]*(h+1)\r\nfor i in range(1,h+1):\r\n    dp[i]=min(dp[max(0,i-(p1-s))]+t1,dp[max(0,i-(p2-s))]+t2)\r\n    for j in range(1,1+i):\r\n        if j*t1>=t2:\r\n            dmg=(j-1)*(p1-s)+(j*t1-t2)//t2*(p2-s)+(p1+p2-s)\r\n            dp[i]=min(dp[i],dp[max(0,i-dmg)]+j*t1)\r\n        if j*t2>=t1:\r\n            dmg=(j-1)*(p2-s)+(j*t2-t1)//t1*(p1-s)+(p1+p2-s)\r\n            dp[i]=min(dp[i],dp[max(0,i-dmg)]+j*t2)\r\nprint(dp[h])", "src_uid": "ca9d48e48e69b931236907a9ac262433"}
{"source_code": "a, b, c = map(int, input().split())\nx = min(a, b, c)\nz = max(a, b, c)\ny = a + b + c - z - x\nif (2 * (x + y) <= z):\n    print(x + y)\nelse:\n    print((x + y + z) // 3)", "src_uid": "bae7cbcde19114451b8712d6361d2b01"}
{"source_code": "a = []\nc = input()\ns = 1\na = list(map(int, list(c)))\nif sum(a) % 4 == 0:\n  print(c)\nelse:\n  while s % 4 != 0:\n    c = int(c)\n    c += 1\n    c = str(c)\n    a = list(map(int, list(c)))\n    s = sum(a)\n  print(int(c))\n\n  \n", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7"}
{"source_code": "r1, r2 = map(int, input().split())\nc1, c2 = map(int, input().split())\nd1, d2 = map(int, input().split())\n\nfound = False\n\nfor i in range(1, 10):\n    if found:\n        break\n    for j in range(1, 10):\n        if found:\n            break\n        for k in range(1, 10):\n            if found:\n                break\n            for l in range(1, 10):\n                if i + j == r1 and k + l == r2 and i + l == d1 and j + k == d2 and i + k == c1 and j + l == c2:\n                    if len(set([i, j, k, l])) == 4:\n                        print(i, j)\n                        print(k, l)\n                        found = True\n                        break\n\nif not found:\n    print(-1)\n", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"}
{"source_code": "n, m = map(int, input().split())\nlst = []\nfor i in range(n):\n    sublst = list(input())\n    lst.append(sublst)\n\n# print(lst)\n# print(lst[0])\n# print(lst[0][0])\npigs = 0\nfor i in range(n):\n    for j in range(m):\n        if lst[i][j] == 'P':\n            if j + 1 < m and lst[i][j + 1] == 'W':\n                pigs += 1\n                lst[i][j + 1] = '.'\n            elif j - 1 > -1 and lst[i][j - 1] == 'W':\n                pigs += 1\n                lst[i][j - 1] = '.'\n            elif i + 1 < n and lst[i + 1][j] == 'W':\n                pigs += 1\n                lst[i + 1][j] = '.'\n            elif i - 1 > -1 and lst[i - 1][j] == 'W':\n                pigs += 1\n                lst[i - 1][j] = '.'\n\nprint(pigs)\n", "src_uid": "969b24ed98d916184821b2b2f8fd3aac"}
{"source_code": "n, a , b = map ( int, input(). split())\nfor i in range(1, max ( a, b ) + 2):\n    if (a//i+b//i>=n) and min(a, b)>=i:\n        continue\n    else:\n        break\nprint(i-1)", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e"}
{"source_code": "n,chips=map(int,input().split())\nx=(n*(n+1))//2\n#print(x)\nif(chips>x):\n    chips=chips%x\n\nfor i in range(1,n+1):\n    if(i>chips):\n        break\n    else:\n        chips-=i\nprint(chips)\n    \n        \n        ", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb"}
{"source_code": "a,b=map(int,input().split())\n\ndangbra=(b*(b-1)//2)*(a*(a+1)//2)*b+(b*(b-1)//2)*a\n\n\nprint(int(dangbra%1000000007))\n", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f"}
{"source_code": "n = int(input())\ns1 = 0\ns2 = 0\nodd_even_pair = False\nin_l1= False\nin_l2= False\nfor _ in range(n):\n    l = list(map(int, input().rstrip().split(\" \")))\n    s1+=l[0]\n    s2+=l[1]\n    if l[1]%2 and not l[0]%2:\n        odd_even_pair= True\n        in_l2 = True\n    if l[0]%2 and not l[1]%2:\n        odd_even_pair= True\n        in_l1=True\nif s1%2 and s2%2:\n    if odd_even_pair:\n        print(1)\n    else:\n        print(-1)\nelif s1%2 and not s2%2:\n    print(-1)\nelif s2%2 and not s1%2:\n\n    print(-1)\nelse:\n    print(0)", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"}
{"source_code": "a1,b1,c1 = [int(x) for x in input().split()]\na2,b2,c2 = [int(x) for x in input().split()]\n\nalwaysGood = False\nalwaysBad = False\n\nif a1 == 0 and b1 == 0:\n    if c1 == 0:\n        alwaysGood = True\n    else:\n        alwaysBad = True\nif a2 == 0 and b2 == 0:\n    if c2 == 0:\n        alwaysGood = True\n    else:\n        alwaysBad = True\n\nif alwaysBad:\n    print(0)\nelif alwaysGood:\n    print(-1)\nelse:\n    if a1*b2 == a2*b1:\n        if a1 != 0:\n            c1 *= a2\n            c2 *= a1\n        else:\n            c1 *= b2\n            c2 *= b1\n        if c1 == c2:\n            print(-1)\n        else:\n            print(0)\n    else:\n        print(1)\n", "src_uid": "c8e869cb17550e888733551c749f2e1a"}
{"source_code": "MOD = (10**9) + 7\n\nn,l,r = list(map(int, input().split()))\n\n\ndef find_ks(l, r):\n    num_elems = (r-l+1)\n    num_trips = int(num_elems / 3)\n    k = [num_trips] * 3\n\n    start_idx = l % 3\n    count = num_elems % 3\n\n    for i in range(count):\n        k[(start_idx + i)%3] += 1\n\n    return k\n\nk = find_ks(l, r)\nf = [[0 for _ in range(3)] for _ in range(n)]\n\n\nfor mod in range(3):\n    f[0][mod] = k[mod]\n\n# print(k)\nfor idx in range(1, n, 1):\n    # print(idx)\n    for mod in range(3):\n        f[idx][mod] += ( f[idx-1][mod] * k[0] ) % MOD\n        f[idx][mod] = f[idx][mod] % MOD\n\n        f[idx][mod] += ( f[idx-1][(mod - 1) % 3] * k[1] ) % MOD\n        f[idx][mod] = f[idx][mod] % MOD\n\n        f[idx][mod] += ( f[idx-1][(mod - 2) % 3] * k[2] ) % MOD\n        f[idx][mod] = f[idx][mod] % MOD\n\n# print(f)\n\nprint(f[n-1][0] % MOD)", "src_uid": "4c4852df62fccb0a19ad8bc41145de61"}
{"source_code": "n, m, a, b = map(int, input().split())\nif m * a <= b:\n\tprint(n * a)\nelse:\n\tprint((n // m) * b + min((n % m) * a, b))", "src_uid": "faa343ad6028c5a069857a38fa19bb24"}
{"source_code": "import sys\n\ndef Min(x, y):\n    if x > y:\n        return y\n    else:\n        return x\n\ndef Gcd(x, y):\n    if x == 0:\n        return y\n    else:\n        return Gcd(y % x, x)\n\ndef Lcm(x, y):\n    return x * y // Gcd(x, y)\n\nn = int(input())\na = [int(i) for i in input().split()]\nd = [int(0) for i in range(0, n)]\n\nok = 0\n\ncur = 0\n\nlen = Lcm(7, n)\n\nfor i in range(0, 7 * n):\n    if a[i % n] == 0 :\n        print(i % n + 1)\n        ok = 1\n        break\n    if cur != 6:\n        a[i % n] -= 1\n        d[i % n] += 1\n    cur = (cur + 1) % 7\n\nif ok == 0:\n    k = 10**20\n\n    for i in range(0, n):\n        a[i] += d[i]\n        if d[i] == 0: continue\n        if a[i] % d[i] > 0:\n            k = Min(k, a[i] // d[i])\n        else:\n            k = Min(k, a[i] // d[i] - 1)\n\n    if k == 10**20:\n        k = 0\n\n    for i in range(0, n):\n        a[i] -= k * d[i]\n\n    iter = 0\n    cur = 0\n\n    while True:\n        if a[iter] == 0:\n            print(iter % n + 1)\n            break\n        else:\n            if cur != 6:\n                a[iter] -= 1\n            cur = (cur + 1) % 7\n            iter = (iter + 1) % n\n\n", "src_uid": "8054dc5dd09d600d7fb8d9f5db4dcaca"}
{"source_code": "def b(n):\n  ans = [n]\n  for x in xrange(2, n+1):\n    while n % x == 0:\n      n /= x\n      ans.append(n)\n  return ' '.join(map(str, ans))\n\n\n\"\"\"\nprint b(10)\nprint b(4)\nprint b(3)\n\"\"\"\nprint b(int(raw_input()))\n#\"\"\"\n", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63"}
{"source_code": "n=input()\n\n\ndef is_power_of_2(n):\n    while n>1:\n        if n % 2 == 1:\n            return False\n        else:\n            n = n/2\n    return True\n\n\nif n%2==1:\n    answer=(n-1)/2\nelif is_power_of_2(n):\n    answer=0\nelse:\n    i=0\n    while 2**i<n:\n        i+=1\n    i-=1\n    answer=(n-2**i)/2\n\nprint answer\n", "src_uid": "422abdf2f705c069e540d4f5c09a4948"}
{"source_code": "#http://codeforces.com/problemset/problem/624/A\n\nd, l, v1, v2 = map(float, raw_input().split())\n\nresult = (l - d)/(v1 + v2)\n\nprint \"%.20f\" % result\n", "src_uid": "f34f3f974a21144b9f6e8615c41830f5"}
{"source_code": "s = input()\nfor i in range(1, len(s)+1):\n    if s == s[i:]+s[:i]:\n        print(i)\n        break\n", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e"}
{"source_code": "def ii():\n    return int(input())\ndef mi():\n    return map(int, input().split())\ndef li():\n    return list(mi())\n\nn, L = mi()\nC = li()\nfor i in range(1, n):\n    C[i] = min(C[i], C[i-1] * 2)\n\nx = 2 ** (n-1)\ny = 0\nz = 10 ** 18\nfor i in range(n-1, -1, -1):\n    t = L // x\n    y += C[i] * t\n    z = min(z, y + C[i])\n    L %= x\n    x //= 2\nz = min(z, y)\nprint(z)", "src_uid": "04ca137d0383c03944e3ce1c502c635b"}
{"source_code": "n=int(input())\nl=list(map(int,input().split()))\nfrom collections import defaultdict\nd=defaultdict(int)\nfor i in l:\n    d[i]+=1\na=[]\nfor i in set(l):\n    if d[i]%2:\n        a.append(i)\n\na.sort()\nans=0\nfor i in range(0,len(a),2):\n    ans+=abs(a[i]-a[i+1])\n\nprint(ans)\n    ", "src_uid": "55485fe203a114374f0aae93006278d3"}
{"source_code": "n, p, t = input().split()\nn, p = int(n), float(p)\nf = [p] * n + [0]\nfor i in range(int(t) - 1): f = [f[k] * (1 - p) + p * (1 + f[k - 1]) for k in range(n)] + [0]\nprint(f[-2])", "src_uid": "20873b1e802c7aa0e409d9f430516c1e"}
{"source_code": "dicts = [\"Howard\", \"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"]\n\n\nn = int(raw_input())\n\nr = 5\n\n#s is short for sum.\nps = 0\nwhile  ((ps + r) <= n):\n    ps += r\n    r *= 2\n\nunit = r/5\nremain = n - ps\n\nprint dicts[(remain - 1)/unit + 1]\n", "src_uid": "023b169765e81d896cdc1184e5a82b22"}
{"source_code": "R = lambda : map(int, raw_input().split())\na = int(raw_input())\nb = int(raw_input())\nc = int(raw_input())\nd = int(raw_input())\nif(c!=0):\n    if a!=0 and d!=0 and a==d: print 1\n    else: print 0\nelif(a==d): print 1\nelse: print 0", "src_uid": "b99578086043537297d374dc01eeb6f8"}
{"source_code": "n=6\nm=8;\na=[];\nb=[];\nfor i in range(n) :\n    a.append(list(input()))\nb.append([3,3,0,4,4,0,3,3])\nb.append([3,3,0,4,4,0,3,3])\nb.append([2,2,0,3,3,0,2,2])\nb.append([2,2,0,3,3,0,2,2])\nb.append([1,1,0,2,2,0,1,1])\nb.append([1,1,0,2,2,0,1,1])\nii=0\njj=0\nx=0\nfor i in range(n) :\n    for j in range(m) :\n        if a[i][j]=='.' and x<b[i][j]:\n            ii=i\n            jj=j\n            x=b[i][j]\na[ii][jj]='P'\nfor i in range(n) :\n    for j in range (m) :\n        print(a[i][j],end='')\n    print ()", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"}
{"source_code": "import sys\r\ninput = sys.stdin.readline\r\n\r\nl = 255\r\nmod = 998244353\r\nfact = [1] * (l + 1)\r\nfor i in range(1, l + 1):\r\n    fact[i] = i * fact[i - 1] % mod\r\ninv = [1] * (l + 1)\r\ninv[l] = pow(fact[l], mod - 2, mod)\r\nfor i in range(l - 1, -1, -1):\r\n    inv[i] = (i + 1) * inv[i + 1] % mod\r\n\r\nn, k = map(int, input().split())\r\ndp0 = [0] * n\r\ndp0[0] = 1\r\nfor i in range(k):\r\n    dp = [0] * n\r\n    p = [1]\r\n    for j in range(n * (n + 1) // 2):\r\n        p.append((i + 1) * p[-1] % mod)\r\n    for j in range(n):\r\n        c = 0\r\n        if not dp0[j]:\r\n            continue\r\n        dp0j = dp0[j]\r\n        for l in range(j, n):\r\n            dp[l] += p[c] * inv[l - j] % mod * dp0j % mod\r\n            dp[l] %= mod\r\n            c += n - l - 2\r\n    dp0 = dp\r\nans = dp0[-1] * fact[n - 1] % mod\r\nprint(ans)", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62"}
{"source_code": "from __future__ import division, print_function\nimport __pypy__\n \nadd = __pypy__.intop.int_add\nsub = __pypy__.intop.int_sub\nmul = __pypy__.intop.int_mul\n \ndef main():\n    from collections import deque \n  \n    def printMin(arr, n, k): \n        res=[]\n        Qi = deque() \n        for i in range(k): \n            while Qi and arr[i] <= arr[Qi[-1]] : \n                Qi.pop() \n            Qi.append(i); \n          \n        for i in range(k, n): \n            res.append(arr[Qi[0]])\n            while Qi and Qi[0] <= i-k: \n                Qi.popleft()  \n            while Qi and arr[i] <= arr[Qi[-1]] : \n                Qi.pop() \n            Qi.append(i) \n        res.append(int(arr[Qi[0]]))\n        return res \n    n,m,a,b=map(int,input().split())\n    g,x,y,z=map(int,input().split())\n    \n    zinv = 1.0/z\n    \n    def modmuladd(x,y,c):\n        ans = sub(add(mul(x,y),c), mul(z, int(zinv*x*y + zinv*c)))\n        if ans >= z:\n            return ans - z\n        elif ans < 0:\n            return ans + z\n        else:\n            return ans\n    \n    grid= [0]*(n*m)\n    grid[0]=g\n    for i in range(1,n*m):\n        grid[i]=modmuladd(grid[i-1],x,y)\n    B=[]\n    ans=0.0\n    for i in range(n):\n        B.append(printMin(grid[i*m:(i+1)*m],m,b))\n    grid=[]\n    for i in range(len(B[0])):\n        temp=[]\n        for j in range(n):\n            temp.append(B[j][i])\n        for tmp in printMin(temp,len(temp),a):\n            ans += tmp\n    print(int(ans))\n######## Python 2 and 3 footer by Pajenegod and c1729\n \n# Note because cf runs old PyPy3 version which doesn't have the sped up\n# unicode strings, PyPy3 strings will many times be slower than pypy2.\n# There is a way to get around this by using binary strings in PyPy3\n# but its syntax is different which makes it kind of a mess to use.\n \n# So on cf, use PyPy2 for best string performance.\n \npy2 = round(0.5)\nif py2:\n    from future_builtins import ascii, filter, hex, map, oct, zip\n    range = xrange\n \nimport os, sys\nfrom io import IOBase, BytesIO\n \nBUFSIZE = 8192\nclass FastIO(BytesIO):\n    newlines = 0\n \n    def __init__(self, file):\n        self._file = file\n        self._fd = file.fileno()\n        self.writable = \"x\" in file.mode or \"w\" in file.mode\n        self.write = super(FastIO, self).write if self.writable else None\n \n    def _fill(self):\n        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])\n        return s\n \n    def read(self):\n        while self._fill(): pass\n        return super(FastIO,self).read()\n \n    def readline(self):\n        while self.newlines == 0:\n            s = self._fill(); self.newlines = s.count(b\"\\n\") + (not s)\n        self.newlines -= 1\n        return super(FastIO, self).readline()\n \n    def flush(self):\n        if self.writable:\n            os.write(self._fd, self.getvalue())\n            self.truncate(0), self.seek(0)\n \nclass IOWrapper(IOBase):\n    def __init__(self, file):\n        self.buffer = FastIO(file)\n        self.flush = self.buffer.flush\n        self.writable = self.buffer.writable\n        if py2:\n            self.write = self.buffer.write\n            self.read = self.buffer.read\n            self.readline = self.buffer.readline\n        else:\n            self.write = lambda s:self.buffer.write(s.encode('ascii'))\n            self.read = lambda:self.buffer.read().decode('ascii')\n            self.readline = lambda:self.buffer.readline().decode('ascii')\n \n \nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\ninput = lambda: sys.stdin.readline().rstrip('\\r\\n')\n \n# Cout implemented in Python\nimport sys\nclass ostream:\n    def __lshift__(self,a):\n        sys.stdout.write(str(a))\n        return self\ncout = ostream()\nendl = '\\n'\n \n# Read all remaining integers in stdin, type is given by optional argument, this is fast\ndef readnumbers(zero = 0):\n    conv = ord if py2 else lambda x:x\n    A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()\n    try:\n        while True:\n            if s[i] >= b'0' [0]:\n                numb = 10 * numb + conv(s[i]) - 48\n            elif s[i] == b'-' [0]: sign = -1\n            elif s[i] != b'\\r' [0]:\n                A.append(sign*numb)\n                numb = zero; sign = 1\n            i += 1\n    except:pass\n    if s and s[-1] >= b'0' [0]:\n        A.append(sign*numb)\n    return A\n \nif __name__== \"__main__\":\n  main()", "src_uid": "4618fbffb2b9d321a6d22c11590a4773"}
{"source_code": "# n - length of zebroid\ndef cnt_subzebroes(n):\n        cnt = 1      \n        pred, pred_pred = 0, 0\n        last = n - 1\n        while last > 0:\n                cur = pred + pred_pred + 1\n                pred_pred = pred % 1000000007\t\n                pred = cur % 1000000007\t\n                cnt = cnt + cur + 1\n                last -= 1\n\treturn cnt % 1000000007\t\n\nprint cnt_subzebroes(int(input()))\n", "src_uid": "5c4bd12df3915186a7b506c2060db125"}
{"source_code": "n, m = map(int, input().split())\nt = [n]\nfor i in range(1, n): t = t + [n - i] if m - 1 & 1 << i - 1 else [n - i] + t\nfor q in t: print(q)\n", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2"}
{"source_code": "n, m, k, r, c = map(int, input().split())\nax, ay, bx, by = map(int, input().split())\np = n * m\nif ax != bx or ay != by:\n\tp -= r * c\nprint(pow(k, p, 1000000007))\n\t  \t  \t \t \t\t  \t\t  \t  \t\t\t\t  \t\t\t\t", "src_uid": "3478e6a4ff2415508fd517413d40c13a"}
{"source_code": "n = int(raw_input()) % 6\nendpos = int(raw_input())\n\nsim = [0, 0, 0]\nsim[endpos] = 1\n\nfor i in range(n, 0, -1):\n    if i % 2 == 0:  # par\n        sim[1], sim[2] = sim[2], sim[1]\n    else:\n        sim[1], sim[0] = sim[0], sim[1]\n\nprint sim.index(1)\n", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0"}
{"source_code": "y,b=map(int,input().split())\nyy,g,bl=map(int,input().split())\nny=yy*2+g\nnb=bl*3+g\nans=0\nif (ny-y)>=0:\n    ans+=(ny-y)\nif (nb-b)>=0:\n    ans+=(nb-b)\n    \nif ans >=0:\n    print(ans)\nelse:\n    print(0)\n", "src_uid": "35202a4601a03d25e18dda1539c5beba"}
{"source_code": "#!/usr/bin/env python\n'''\n' Author:   Cheng-Shih Wong\n' Email:    mob5566@gmail.com\n' Date:     2017-09-22\n'''\n\ndef main():\n\n    def num(left, right, dp, rev, revI):\n        if left > right:\n            return 1\n\n        key = left, rev, revI\n        if key in dp:\n            return dp[key]\n        nonlocal ans\n\n        acc = 0\n\n        for x in ('01' if ans[left]=='#' else ans[left]):\n            \n            temp = None\n            if left == right:\n                tmp = x\n            elif ans[right]=='#':\n                tmp = '01'\n            else:\n                tmp = ans[right]\n\n            for y in tmp:\n                if not ((rev and x>y) or (revI and x==y=='1')):\n                    acc += num(\n                        left+1,\n                        right-1,\n                        dp,\n                        rev and x==y,\n                        revI and x!=y\n                    )\n        dp[key] = acc\n        return acc\n\n    n, k = map(int, input().split())\n    k += 1\n\n    ans = ['#'] * n\n\n    for i in range(n):\n        ans[i] = '0'\n        tmp = num(0, n-1, {}, True, True)\n\n        if k > tmp:\n            k -= tmp\n            ans[i] = '1'\n\n    if ans[0] == '0':\n        print(''.join(ans))\n    else:\n        print(-1)\n\nif __name__ == '__main__':\n    import sys, os\n    from time import time\n    if len(sys.argv)>1 and os.path.exists(sys.argv[1]):\n        sys.stdin = open(sys.argv[1], 'rb')\n    st = time()\n    main()\n    print('----- Run {:.6f} seconds. -----'.format(time()-st), file=sys.stderr)\n", "src_uid": "0a4a418dafaee71f1b31c928fc2ad24a"}
{"source_code": "import fractions \r\nN = int(input())\r\nfor i in range(N):\r\n    x  = int(input())\r\n    if x == 100:\r\n        print(1)\r\n    else:\r\n        y = fractions.Fraction(x , 100)\r\n        l = y.denominator\r\n        print(l)", "src_uid": "19a2bcb727510c729efe442a13c2ff7c"}
{"source_code": "a=list(input())\nmark='a'\nfor i in range(len(a)):\n    if a[i]<=mark and (ord(mark) in range(ord('a'),ord('z')+1)):\n        a[i]=mark\n        mark=chr(ord(mark)+1)\nif ord(mark)>ord('z'):\n    print(''.join(a))\nelse:\n    print(-1)\n", "src_uid": "f8ad543d499bcc0da0121a71a26db854"}
{"source_code": "n, B = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nres = []\nif a[0] % 2 == 0:\n    bal = 1\nelse:\n    bal = -1\nfor i in range(1, n):\n    if bal == 0:\n        res.append(abs(a[i] - a[i - 1]))\n    if a[i] % 2 == 0:\n        bal += 1\n    else:\n        bal -= 1\n\nres.sort()\ncnt = 0\nans = 0\n\nwhile(cnt <= B):\n    if ans == len(res):\n        ans += 1\n        break\n    cnt += res[ans]\n    ans += 1\n\nprint(ans - 1)\n", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e"}
{"source_code": "def func(n):\n    \n    if n==1:\n        return 'codeforces'\n    curr=1\n    for i in range(2,41):\n        for j in range(1,11):\n            curr=(i**j)*(i-1)**(10-j)\n#             print(curr)\n            if curr>=n:\n                return sec(i,j)\n        \ndef sec(i,j):\n    res=''\n    s='codeforces'\n    rem=10-j\n    for k in range(rem):\n        res+=(s[k]*(i-1))\n    for k in range(rem,10):\n        res+=(s[k]*(i))\n    return(res)\n    \n\n\n\n\n#print(10**5)\nn=int(input())\nprint(func(n))\n\n", "src_uid": "8001a7570766cadcc538217e941b3031"}
{"source_code": "n,m=map(int,input().split())\nprint(n+(n-1)//(m-1))", "src_uid": "a349094584d3fdc6b61e39bffe96dece"}
{"source_code": "class Main:\n\tn=int(input())\n\ts=n\n\twhile(n!=1):\n\t\ti=2\n\t\twhile(n%i!=0):\n\t\t\ti+=1\n\t\tn=n/i\n\t\ts+=n\n\tprint s\n", "src_uid": "821c0e3b5fad197a47878bba5e520b6e"}
{"source_code": "from math import sqrt\nn = input()\nMin, Max = 999999999999999999L, -1\n\nfor i in range(1, int(sqrt(n)) + 1):\n    if n % i == 0:\n        n1 = n / i\n        a = i + 1\n\n        for j in range(1, int(sqrt(n1)) + 1):\n            if n1 % j == 0:\n                b = j + 2\n                c = n1 / j + 2\n                tmp = a * b * c - n\n                Min = min(tmp,Min)\n                Max = max(tmp,Max)\n            j += 1\n\n        a = n1 + 1\n        for j in range(1, int(sqrt(i)) + 1):\n            if i % j == 0:\n                b = j + 2\n                c = i / j + 2\n                tmp = a * b * c - n\n                Min = min(tmp,Min)\n                Max = max(tmp,Max)\nprint Min, Max\n", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7"}
{"source_code": "import sys\nn, a = map(int, sys.stdin.read().split())\nif a & 1:\n    a //= 2\nelse:\n    a = (n - a) // 2\nsys.stdout.write(str(a + 1))", "src_uid": "aa62dcdc47d0abbba7956284c1561de8"}
{"source_code": "\n# coding: utf-8\n\n# In[36]:\n\n\nimport math\n\ndef UnusualSeq(a,b):\n    if b%a!=0:\n        print(0)\n    else:\n        b//=a\n        d=set()\n        for i in range(1,int(math.sqrt(b)+1)):\n            if b%i==0:\n                d.add(i)\n                d.add(b//i)\n        d=sorted(list(d))\n        f=d[::]\n        for i in range(len(f)):\n            f[i]=pow(2,d[i]-1,(10**9+7))\n            for j in range(i):\n                if d[i]%d[j]==0:\n                    f[i]-=f[j]\n        print(f[-1]%(10**9+7))\n\n\na,b=map(int,input().split())\nUnusualSeq(a,b)\n\n", "src_uid": "de7731ce03735b962ee033613192f7bc"}
{"source_code": "n, k = map(int, raw_input().split())\n\ndef cal(mid):\n    return k * mid - ((1 + mid) * mid / 2) + k - mid\n\nif n == 1:\n    print 0\nelif n > (k - 1) * k / 2 + 1:\n    print -1\nelse:\n    l, r = 0, k - 2\n    while r > l:\n        mid = l + r >> 1\n        cnt = cal(mid)\n        if cnt >= n: r = mid\n        else: l = mid + 1\n    print r + 1\n", "src_uid": "83bcfe32db302fbae18e8a95d89cf411"}
{"source_code": "n=int(raw_input())\na=map(int,raw_input().split())\nb=map(int,raw_input().split())\nc,d=0,0\nfor i in xrange(n):\n\tif a[i]==1 and b[i]==0:\n\t\tc+=1\n\telif a[i]==0 and b[i]==1:\n\t\td+=1\n\t\t\nif c==0:\n\tprint -1\nelif c<=d:\n\tprint d//c+1\nelse:\n\tprint 1", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07"}
{"source_code": "import math\nn = math.ceil(int(input())/2)\nlistOfInt = list(map(int,input().split()))\npositive = 0\nnegative = 0\nnoSolution = 0\n# boolean to check if it has printed a solution, if not print 0\ncheckPrint = False\nfor i in listOfInt:\n    if(i>0):\n        positive+=1\n        if(positive>=n):\n            print(1)\n            checkPrint = True\n            break\n    elif(i<0):\n        negative+=1\n        if(negative>=n):\n            print(-1)\n            checkPrint = True\n            break\n    elif(i==0):\n        noSolution+=1\n        if(noSolution > n):\n            print(0)\n            checkPrint = True\n            break\n            \nif(checkPrint == False):\n    print(0)\n", "src_uid": "a13cb35197f896cd34614c6c0b369a49"}
{"source_code": "x , p = sorted([int(_) for _ in input().split()]) , 0\nwhile(x[0]+x[1]<=x[2]):\n    x[0]+=1\n    p+=1\nprint(p)\n", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09"}
{"source_code": "n=int(raw_input())\nA=[]\nfor i in range(n):\n    A.append(map(int,raw_input().split()))\n\nans=[]\n\nfor i in range(n):\n    Flag=True\n    for j in range(n):\n        if j!=i and Flag==True:\n            for k in range(j+1,n):\n                if i!=k:\n                    s=0\n                    for x in range(5):\n                        s+=(A[j][x]-A[i][x])*(A[k][x]-A[i][x])\n                    if s>0:\n                        Flag=False\n                        break\n    if Flag==True:\n        ans.append(i)\n\nprint len(ans)\nif len(ans)>0:\n    for i in range(len(ans)):\n        print ans[i]+1", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9"}
{"source_code": "def b(a,m): \n    m0=m;y=0;x=1\n    if (m==1):return 0\n    while (a>1):\n        q=a//m;t=m;m=a%m;a=t;t=y;y=x-q*y;x=t\n    if (x<0):x=x+m0 \n    return x\np=998244353\nn,m=map(int,input().split())\nz=0\nfor i in range(1,n+1): z+=b(i, p)\nprint(((1+m*z)*(1+n*b(m+1,p)))%p)", "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613"}
{"source_code": "import sys\n\nlines = []\nfor line in sys.stdin:\n    lines.append(line)\n\nn = int(lines[0].rstrip(\"\\r\\n\\t \"))\n\nmax_price = n * 2 - 1\nnines = len(str(max_price + 1)) - 1\n\nif nines < 1:\n    cnt = 0\n    for x in range(1, n):\n        cnt += x\n    print(cnt)\n    exit()\n\nprice_suffix = \"9\"*nines\ncnt = 0\n\n\ndef add_pairs(max_x: int, p: int):\n    global cnt\n    from_max = int(p / 2)\n    to_max = p - 1\n    if to_max > max_x:\n        to_max = max_x\n    from_min = p - to_max\n    cnt += from_max - from_min + 1\n\n\nfor d in range(0, 10):\n    if d > 0:\n        price = int(str(d) + price_suffix)\n    else:\n        price = int(price_suffix)\n    if price <= max_price:\n        add_pairs(n, price)\n\nprint(cnt)\n", "src_uid": "c20744c44269ae0779c5f549afd2e3f2"}
{"source_code": "'''\r\n                ___                       ____                     \r\n  ____ _____ _____/ (_)_  ______  ____ _____/ / /_  __  ______ ___  __\r\n / __ `/ __ `/ __  / / / / / __ \\/ __ `/ __  / __ \\/ / / / __ `/ / / /\r\n/ /_/ / /_/ / /_/ / / /_/ / /_/ / /_/ / /_/ / / / / /_/ / /_/ / /_/ / \r\n\\__,_/\\__,_/\\__,_/_/\\__,_/ .___/\\__,_/\\__,_/_/ /_/\\__, /\\__,_/\\__, /  \r\n                        /_/                      /____/      /____/   \r\n'''\r\nimport os.path\r\nfrom math import gcd, floor, ceil\r\nfrom collections import *\r\nimport sys\r\nmod = 1000000007\r\nINF = float('inf')\r\ndef st(): return list(sys.stdin.readline().strip())\r\ndef li(): return list(map(int, sys.stdin.readline().split()))\r\ndef mp(): return map(int, sys.stdin.readline().split())\r\ndef inp(): return int(sys.stdin.readline())\r\ndef pr(n): return sys.stdout.write(str(n)+\"\\n\")\r\ndef prl(n): return sys.stdout.write(str(n)+\" \")\r\n\r\n\r\nif os.path.exists('input.txt'):\r\n    sys.stdin = open('input.txt', 'r')\r\n    sys.stdout = open('output.txt', 'w')\r\n\r\n# joined late\r\n\r\n\r\ndef solve():\r\n    n, m, k = mp()\r\n    if n % 2:\r\n        if k < m//2:\r\n            pr('NO')\r\n            return\r\n        k -= m//2\r\n        n -= 1\r\n    elif m % 2:\r\n        left = n*m//2 - k\r\n        if left < n//2:\r\n            pr('NO')\r\n            return\r\n        m -= 1\r\n    pr('YES' if k % 2 == 0 else 'NO')\r\n\r\n\r\nfor _ in range(inp()):\r\n    solve()\r\n", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8"}
{"source_code": "a = [0]*3001\na[0]=a[1]=1\n\nfor i in range(2,3001):\n    if a[i]==0:\n        for j in range(i+i,3001,i):\n            a[j]+=1\nc = 0\nfor i in range(int(input())+1):\n    if a[i]==2:\n        c+=1\nprint(c)\n", "src_uid": "356666366625bc5358bc8b97c8d67bd5"}
{"source_code": "n = int(input())\n\ns = input()\n\ns = s.split()\n\nl = list()\nzeroes = 0\n\nfor i in range(n):\n\tif s[i] == '0':\n\t\tzeroes += 1\n\telse:\n\t\tif zeroes == 0:\n\t\t\tcontinue\n\t\telse:\n\t\t\tl.append(zeroes)\n\t\t\tzeroes = 0\nans = 1\nfor i in l:\n\tans *= (i + 1)\n\nif s.count('1') == 0:\n\tans = 0\nelif len(l) == 0:\n\tans = 1\nelif s[0] != '1':\n\tans //= (l[0] + 1)\n\nprint(ans)\n", "src_uid": "58242665476f1c4fa723848ff0ecda98"}
{"source_code": "a = int(input())\nb = int(input())\nc = int(input())\nif a != 1 and b != 1 and c != 1:\n    s = a * b * c\nelif a*c != 1:\n    if a >= c:\n        s = a*(b+c)\n    else:\n        s = (a+b)*c\nelse:\n    s = a+b+c\nprint(s)\n", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"}
{"source_code": "#import sys\n#sys.stdin = open('in')\n\nn = int(raw_input())\ns = []\nif n == 0:\n    print 'O-|-OOOO'\nelse:\n    while n > 0:\n        x = n % 10\n        n /= 10\n        if x >= 5:\n            si= '-O|'\n            x-=5\n        else:\n            si = 'O-|'\n        si += 'O'*x\n        si += '-'\n        si += 'O'*(4-x)\n        s.append(si)\n    for k in s:\n        print k\n", "src_uid": "c2e3aced0bc76b6484360563355d23a7"}
{"source_code": "m, n = map(int, raw_input().strip().split())\nif m > n: m, n = n, m\n\nif m == 1:\n    r = n % 6\n    q = n // 6\n    if r <= 3: print 6 * q\n    else: print 6 * q + 2 * (r - 3)\nelif m == 2:\n    if n == 2: print 0\n    elif n == 3: print 4\n    elif n == 7: print 12\n    else: print n << 1\nelse:\n    x = m * n\n    if x & 1: x -= 1\n    print x", "src_uid": "02ce135a4b276d1e9ba6a4ce37f2fe70"}
{"source_code": "from math import sqrt\ndef divisors(n,k):\n    begin= []\n    for i in range(1, int(sqrt(n))+1):\n        if n % i is 0:\n            if n//i is i:\n                begin.append(i)\n            else:\n                begin.append(i)\n                begin.append(n//i)\n    begin.sort()\n    size = len(begin)\n    if size < k:\n        print(-1)\n    else:\n        print(begin[k-1])\n\nn,k = input().split()\nn,k = int(n), int(k)\ndivisors(n,k)\n", "src_uid": "6ba39b428a2d47b7d199879185797ffb"}
{"source_code": "def ii(): return int(input())\ndef fi(): return float(input())\ndef si(): return input()\ndef mi(): return map(int,input().split())\ndef li(): return list(mi())\n\nimport math\n \nn=ii()\na=[6,8,4,2]\nif n:\n    ans=a[n%4]\nelse:\n    ans=1\nprint(ans)", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"}
{"source_code": "a, b, v = input(), input(), input()\n\nt = [[-1] * len(b) for x in range(len(a))]\n\n\n\ndef g(i, j):\n\n    if i < 0 or j < 0: return ''\n\n    if t[i][j] == -1:\n\n        s = g(i - 1, j - 1)\n\n        if a[i] == b[j]: s += a[i]\n\n        t[i][j] = max(s, g(i - 1, j), g(i, j - 1), key=lambda q: len(q) - q.count(v))\n\n    return t[i][j]\n\n\n\ns = g(len(a) - 1, len(b) - 1)\n\nwhile v in s: s = min(s.replace(v, v[:-1]), s.replace(v, v[1:]), key=lambda q: q.count(v))\n\nprint(s if s else 0)\n\n\n\n\n# Made By Mostafa_Khaled", "src_uid": "391c2abbe862139733fcb997ba1629b8"}
{"source_code": "n, m, k, x, y = tuple(map(int, input().split()))\n\nmaxq = minq = sergeiq = 0\nif n == 1:\n\tmaxq = k // m\n\tif k % m > 0:\n\t\tmaxq +=1\n\t\tminq = maxq - 1\n\t\tif y <= k % m:\n\t\t\tsergeiq = maxq\n\t\telse:\n\t\t\tsergeiq = minq\n\telse:\n\t\tminq = maxq\n\t\tsergeiq = minq\nelif n == 2:\n\tmaxq = minq = sergeiq = k // (2*m)\n\tif k % (2*m) > 0:\n\t\tmaxq += 1\n\t\tif x == 1 and y <= k % (2*m):\n\t\t\tsergeiq += 1\n\t\telif x == 2 and k % (2*m) >= y + m:\n\t\t\tsergeiq += 1\nelif k < n * m:\n\tmaxq = 1\n\tminq = 0\n\tif k / m >= x:\n\t\tsergeiq = 1\n\telif k / m <= x-1:\n\t\tsergeiq = 0\n\telif k % m >= y:\n\t\tsergeiq = 1\n\telse:\n\t\tsergeiq = 0\nelif k == n*m:\n\tmaxq = 1\n\tminq = 1\n\tsergeiq = 1\nelse:\n\tmaxq = 2*(k // (m * 2 * (n-1)))\n\tminq = k // (m * 2 * (n-1))\n\tif x == 1 or x == n:\n\t\tsergeiq = minq\n\telse:\n\t\tsergeiq = maxq\n\tremainder = k % (m * 2* (n-1))\n\tif remainder > 0:\n\t\tif remainder <= m:\n\t\t\tif x == 1 and y <= remainder:\n\t\t\t\tsergeiq += 1\n\t\telif remainder <= m * n:\n\t\t\tmaxq += 1\n\t\t\tif x <= remainder / m:\n\t\t\t\tsergeiq += 1\n\t\t\telif x-1 < remainder / m and remainder % m >= y:\n\t\t\t\tsergeiq += 1\n\t\t\tif remainder == m*n:\n\t\t\t\tminq += 1\n\t\telse:\n\t\t\tmaxq += 2\n\t\t\tsergeiq += 1\n\t\t\tminq += 1\n\t\t\tif x != 1 and x != n:\n\t\t\t\tif (remainder - (n*m)) / m >= n-x:\n\t\t\t\t\tsergeiq += 1\n\t\t\t\telif (remainder - (n*m)) / m > n-x-1 and (remainder - (n*m)) % m >= y:\n\t\t\t\t\tsergeiq += 1\nprint(str(maxq) + ' ' + str(minq) + ' ' + str(sergeiq))\n\n", "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21"}
{"source_code": "\"\"\"\nCodeforces Contest 307 Div 2 Problem D\n\nAuthor  : chaotic_iak\nLanguage: Python 3.4.2\n\"\"\"\n\n################################################### SOLUTION\n\ndef multiply(M1, M2):\n    if len(M1[0]) != len(M2): raise ValueError\n    a = len(M1)\n    b = len(M2[0])\n    c = len(M1[0])\n    # M1: a x c, M2: c x b, M: a x b\n    ans = [[0]*b for _ in range(a)]\n    for i in range(a):\n        for j in range(b):\n            for k in range(c):\n                ans[i][j] += M1[i][k] * M2[k][j]\n    return ans\n\ndef solve(n, m):\n    M = [[0,1,0],[1,1,0],[0,1,2]]\n    if n == 0:\n        return [[1,0,0],[0,1,0],[0,0,1]]\n    if n == 1:\n        return M\n    P = solve(n//2, m)\n    S = multiply(P, P)\n    if n%2: S = multiply(S, M)\n    for i in range(3):\n        for j in range(3):\n            S[i][j] = S[i][j] % m\n    return S\n\ndef main():\n    n,k,l,m = read()\n    kb = bin(k)[2:]\n    if l == 0 and k == 0: return 1 % m\n    if len(kb) > l: return 0\n    kb = \"0\" * (l - len(kb)) + kb\n    zero, one = 0, 0\n    for i in kb:\n        if i == \"0\":\n            zero += 1\n        else:\n            one += 1\n\n    multiplier = solve(n, m)\n    _, _, ans_one = multiply(multiplier, [[1],[0],[0]])\n    multiplier = multiply(multiplier, solve(2, m))\n    _, ans_zero, _ = multiply(multiplier, [[1],[0],[0]])\n    return (pow(ans_zero[0], zero, m) * pow(ans_one[0], one, m)) % m\n\n\n\n#################################################### HELPERS\n\n\n\ndef read(mode=2):\n    # 0: String\n    # 1: List of strings\n    # 2: List of integers\n    inputs = input().strip()\n    if mode == 0: return inputs\n    if mode == 1: return inputs.split()\n    if mode == 2: return list(map(int, inputs.split()))\n\ndef write(s=\"\\n\"):\n    if s is None: s = \"\"\n    if isinstance(s, list): s = \" \".join(map(str, s))\n    s = str(s)\n    print(s, end=\"\")\n\nwrite(main())", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e"}
{"source_code": "n=input()\nwhile not n%3:n/=3\nprint n/3+1", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd"}
{"source_code": "n = input()\nans = 1\nfor i in range(2,n+1):\n\tans+=(i-1)*4\nprint ans", "src_uid": "758d342c1badde6d0b4db81285be780c"}
{"source_code": "n = int(raw_input(\"\"))\n\ndef sum(x):\n    return x * (x + 1) / 2\n\nif n < 0:\n    n = -n\n\nans = 0\nwhile 1:\n    s = sum(ans)\n    if (s - n) % 2 > 0 or (s < n):\n        ans += 1\n    else:\n        break\n\nprint ans\n", "src_uid": "18644c9df41b9960594fdca27f1d2fec"}
{"source_code": "st = raw_input()\n\nct = st.count(\"VK\")\nfor i in range(len(st)):\n\n    if st[i] == \"V\":\n        new = st[:i] + \"K\" + st[i+1:]\n    else:\n        new = st[:i] + \"V\" + st[i + 1:]\n\n    ct1 = new.count(\"VK\")\n\n    if ct < ct1:\n        ct = ct1\n\n\nprint ct", "src_uid": "578bae0fe6634882227ac371ebb38fc9"}
{"source_code": "import sys\n\n\ndef check(q):\n    if q[1] == q[2] == q[3] == q[4] and q[5] == q[6] == q[7] == q[8] and q[9] == q[10] == q[11] == q[12] and q[13] == q[14] == q[15] == q[16] and q[17] == q[18] == q[19] == q[20] and q[21] == q[22] == q[23] == q[24]:\n        return True\n    else:\n        return False\na = [0] + [int(x) for x in input().split()]\nswaps = []\nb = a[:]\nb[17] = a[3]\nb[19] = a[4]\nb[10] = a[17]\nb[9] = a[19]\nb[14] = a[9]\nb[16] = a[10]\nb[4] = a[14]\nb[3] = a[16]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[17] = a[10]\nb[19] = a[9]\nb[10] = a[16]\nb[9] = a[14]\nb[14] = a[4]\nb[16] = a[3]\nb[4] = a[19]\nb[3] = a[17]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[13] = a[21]\nb[14] = a[22]\nb[5] = a[13]\nb[6] = a[14]\nb[17] = a[5]\nb[18] = a[6]\nb[21] = a[17]\nb[22] = a[18]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[21] = a[13]\nb[22] = a[14]\nb[13] = a[5]\nb[14] = a[6]\nb[5] = a[17]\nb[6] = a[18]\nb[17] = a[21]\nb[18] = a[22]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[7] = a[19]\nb[8] = a[20]\nb[19] = a[23]\nb[20] = a[24]\nb[23] = a[15]\nb[24] = a[16]\nb[15] = a[7]\nb[16] = a[8]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[19] = a[7]\nb[20] = a[8]\nb[23] = a[19]\nb[24] = a[20]\nb[15] = a[23]\nb[16] = a[24]\nb[7] = a[15]\nb[8] = a[16]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[1] = a[5]\nb[3] = a[7]\nb[5] = a[9]\nb[7] = a[11]\nb[9] = a[22]\nb[11] = a[24]\nb[22] = a[1]\nb[24] = a[3]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[5] = a[1]\nb[7] = a[3]\nb[9] = a[5]\nb[11] = a[7]\nb[22] = a[9]\nb[24] = a[11]\nb[1] = a[22]\nb[3] = a[24]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[10] = a[6]\nb[12] = a[8]\nb[6] = a[2]\nb[8] = a[4]\nb[2] = a[23]\nb[4] = a[21]\nb[23] = a[10]\nb[21] = a[12]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[6] = a[10]\nb[8] = a[12]\nb[2] = a[6]\nb[4] = a[8]\nb[23] = a[2]\nb[21] = a[4]\nb[10] = a[23]\nb[12] = a[21]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[1] = a[18]\nb[2] = a[20]\nb[18] = a[12]\nb[20] = a[11]\nb[12] = a[15]\nb[11] = a[13]\nb[15] = a[1]\nb[13] = a[2]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nb = a[:]\nb[18] = a[1]\nb[20] = a[2]\nb[12] = a[18]\nb[11] = a[20]\nb[15] = a[12]\nb[13] = a[11]\nb[1] = a[15]\nb[2] = a[13]\nif check(b):\n    print(\"YES\")\n    sys.exit()\nprint(\"NO\")\n\n\n\n\n", "src_uid": "881a820aa8184d9553278a0002a3b7c4"}
{"source_code": "from sys import stdin, stdout\nimport math, collections\nmod = 10**9+7\n\ndef isPower(n):\n    if (n <= 1):\n        return True\n    for x in range(2, (int)(math.sqrt(n)) + 1):\n        p = x\n        while (p <= n):\n            p = p * x\n            if (p == n):\n                return True\n\n    return False\nn = int(input())\narr = [0,1,2,1,4,3,2,1,5,6,2,1,8,7,5,9,8,7,3,4,7,4,2,1,10,9,3,6,11,12]\nans = arr[int(math.log(n, 2))]\ns = int(math.log(n, 2))\nfor i in range(3, int(n**0.5)+1):\n    if not isPower(i):\n        ans^=arr[int(math.log(n, i))]\n        s+=int(math.log(n, i))\nans^=((n-s)%2)\nprint(\"Vasya\" if ans else \"Petya\")", "src_uid": "0e22093668319217b7946e62afe32195"}
{"source_code": "def gcd(a,b):\n    while a!=b:\n        if a>b:\n            a=a-b\n        else :\n            b=b-a\n    print(m//a,'/',n//a,sep='')\na,b,c,d=map(int,input().split())\nm=1\nn=1\n\nif a==b:\n    if c==d :\n        print(0,'/',1,sep='')\n    else :\n        if c>d:\n            m=b*c-a*d\n            n=c*b\n            gcd(m,n)\n        else :\n            m=a*d-c*b\n            n=a*d           \n            gcd(m,n)\nelse:\n    if c/d ==a/b:\n        print(0,'/',1)\n    else :\n        if c/d>a/b:\n            m=b*c-a*d\n            n=c*b\n            gcd(m,n)\n        else :\n            m=a*d-c*b\n            n=a*d           \n            gcd(m,n)        \n            \n        \n                 \n", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e"}
{"source_code": "n, m = map(int, input().split())\n\nprint(1 if n*m == 1 else 1/n + (n-1) / n * (m-1) / (n*m - 1))", "src_uid": "0b9ce20c36e53d4702869660cbb53317"}
{"source_code": "import math\na1,a2,a3=map(int,input().split())\nb1,b2,b3=map(int,input().split())\nn=int(input())\ncups=(a1+a2+a3)/5\nc=math.ceil(cups)\nmedals=(b1+b2+b3)/10\nm=math.ceil(medals)\nif (c+m)<=n:\n    print(\"YES\")\nelif (c+m)>n:\n    print(\"NO\")\n\n", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"}
{"source_code": "import math;\nn,m = list(map(int, str(raw_input()).split()))\nif(min(m,n) == 1):\n    print n*m\nelif(min(n,m) == 2):\n    some = max(m,n)\n    total = some - (some%4)\n    some %= 4\n    if(some == 1) or (some == 2):\n        total+=some*2\n    elif(some == 3):\n        total += 4\n    print total\nelse:\n    print int(math.ceil(n*m/2.0))\n", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9"}
{"source_code": "#copyright mr.Gigola :)\nnStudents, kValue = map(int,raw_input().split())\nnDiplomas = (nStudents/2)/(kValue+1)\nnCertificates = nDiplomas*kValue\nprint nDiplomas,nCertificates,nStudents-nDiplomas-nCertificates", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80"}
{"source_code": "n=int(input())\nslist=list(map(int,input().split()))\ntotal=sum(slist)\ns=slist[0]\nmlist=[]\nfor i in range(0,len(slist)):\n    if(slist[i]<=(slist[0]//2)):\n        s=s+slist[i]\n        mlist.append(i+1)\nif(s>(total//2)):\n    mlist.insert(0,1)\n    mlist=list(set(mlist))\n    print(len(mlist))\n    for i in range(0,len(mlist)):\n        print(mlist[i],end=\" \")\nelse:\n    print(0)", "src_uid": "0a71fdaaf08c18396324ad762b7379d7"}
{"source_code": "n = int(input())\na = list(map(int, input().split()))\n\nd = []\ni = 0\nwhile i < n:\n    d.append([0, 0, 0])\n    if i == 0:\n        if a[i] in [1, 3]:\n            d[i][1] = 1\n        if a[i] in [2, 3]:\n            d[i][2] = 1\n    elif i > 0:\n        d[i][0] = max(d[i - 1])\n        if a[i] in [1, 3]:\n            d[i][1] = max(d[i - 1][2] + 1, d[i - 1][0] + 1)\n        if a[i] in [2, 3]:\n            d[i][2] = max(d[i - 1][0] + 1, d[i - 1][1] + 1)\n    i += 1\nprint(n - max(d[i - 1]))\n", "src_uid": "08f1ba79ced688958695a7cfcfdda035"}
{"source_code": "n = int(raw_input())\na = map(int,raw_input().split())\nx = 360\nsum1 = 0\nans = 360\nfor i in range(n):\n\tsum1 = 0\n\tfor j in range(i,n):\n\t\tsum1 += a[j]\n\t\tif abs(360 - 2 *sum1) < ans :\n\t\t\tans = abs(360 - 2 * sum1)\nprint ans", "src_uid": "1b6a6aff81911865356ec7cbf6883e82"}
{"source_code": "for i in range(int(input())):\n  a=list(map(int,input().split()))\n  mx=max(list(map(abs,a)))\n  std=(sum(list(map(lambda x:x*x,a)))/len(a))**0.5\n  print('poisson'if mx/std>2 else'uniform')\n", "src_uid": "6ef75e501b318c0799d3cbe8ca998984"}
{"source_code": "def works(X,N,M,K):\n    #in each row, how many numbers are < X\n    res = 0\n    n = 1\n    div = X/M\n    while n < div:\n        res += M\n        n += 1\n    while n < N+1:\n        res += (X-1)//n\n        n += 1\n    return res\n\ndef solve():\n    N, M, K = [int(s) for s in input().split()]\n    left = 1\n    right = K+1\n    #we want the smallest smallest such that there are AT LEAST K-1 smaller numbers\n    while right - left > 1:\n        middle = (left+right)//2\n        if works(middle,N,M,K) < K:\n            left = middle\n        else:\n            right = middle\n    #if there are exactly K-1 elements less than right, then this is our answer\n    return left\n\n#for _ in range(getInt()):    \nprint(solve())", "src_uid": "13a918eca30799b240ceb9de47507a26"}
{"source_code": "#!/usr/bin/python\n\ndef main():\n    dnk = raw_input()\n    cur_nukl = dnk[0]\n    counter = 0\n    inner_c = 0\n    for nukl in dnk:\n        if nukl == cur_nukl:\n            inner_c += 1\n        else:\n            if inner_c % 2 == 0:\n                counter += 1\n            cur_nukl = nukl\n            inner_c = 1\n    if inner_c % 2 == 0: # if last seq even\n        counter += 1\n    print counter\n    \nif __name__ == '__main__':\n  main() ", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f"}
{"source_code": "from __future__ import division\nimport sys\nrange = xrange;input = raw_input \ninp = [int(x) for x in sys.stdin.read().split()]; ii = 0;n = inp[ii]; ii += 1;m = inp[ii]; ii += 1;coupl = [[] for _ in range(n)];V = [];C = []\nfor _ in range(m):a = inp[ii] - 1; ii += 1;b = inp[ii] - 1; ii += 1;c = inp[ii]; ii += 1;eind = len(V);C.append(c);V.append(b);V.append(a);coupl[a].append(eind);coupl[b].append(eind ^ 1) \nfound = [0]*n;ans = [0] * n;val0 = [0] * n;val1 = [1] * n\nfor root in range(n):\n    if found[root]:continue\n    bfs = [root];found[root] = 1\n    for node in bfs:\n        for eind in coupl[node]:\n            nei = V[eind]\n            if not found[nei]:found[nei] = 1;bfs.append(nei);c = C[eind >> 1];val0[nei] = c - val0[node];val1[nei] = -val1[node]\n \n    for node in bfs:\n        for eind in coupl[node]:\n            nei = V[eind];c = C[eind >> 1]\n            if val0[node] + val0[nei] != c or val1[node] + val1[nei]:\n                if val1[node] + val1[nei] == 0:print 'NO';sys.exit()\n                x = (c - (val0[node] + val0[nei])) / (val1[node] + val1[nei]);break\n        else:continue\n        break\n    else:\n        vals = []\n        for node in bfs:vals.append(-val0[node] // val1[node])\n        vals.sort();x = vals[len(vals)//2] \n    for node in bfs:ans[node] = val0[node] + x * val1[node]\n \nfor node in range(n):\n    for eind in coupl[node]:\n        nei = V[eind];c = C[eind >> 1]\n        if ans[node] + ans[nei] != c:\n            print 'NO'\n            sys.exit()\n \nprint 'YES'\nprint ' '.join(str(x) for x in ans)", "src_uid": "791cbe2700b11e9dd9a442de3ef913f8"}
{"source_code": "entrada = int(raw_input())\n\ninteracoes = len(str(entrada))\nsaida = 0\nsoma = 9\nfor i in range(1,interacoes):\n\tsaida += soma * i\n\tentrada -= soma\n\tsoma = soma * 10\n\nsaida += entrada * interacoes\n\nprint saida\n", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"}
{"source_code": "l=lambda:map(int,raw_input().split())\nn,k=l()\nbase=2*n\nprint max(0,n-(k-base))", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8"}
{"source_code": "left, right = input().split(\"|\")\nweight = input()\n\nleft += weight\n\ndef test(left, right):\n    for i in range(len(weight)+1):\n        if len(left[:len(left)-i]) == len(right+weight[::-1][:i]):\n            print(left[:len(left)-i] +\"|\" + right+weight[::-1][:i])\n            return\n    print(\"Impossible\")\n    \ntest(left, right)", "src_uid": "917f173b8523ddd38925238e5d2089b9"}
{"source_code": "n=int(input())\ns=input()\nfreq={}\nif n==1:\n    print(\"YES\")\nelse:    \n    for i in s:\n        if i in freq:\n            freq[i]+=1\n        else:\n            freq[i]=1\n    c=0\n    for i in freq:\n        if freq[i]>=2:\n            c=1\n            print(\"YES\")\n            break\n    if c==0:\n        print(\"NO\")", "src_uid": "6b22e93f7e429693dcfe3c099346dcda"}
{"source_code": "def gcd(a,b):\n    if(a%b==0):\n        return b\n    else:\n        return gcd(b,a%b)\n\n[t1,t2,x1,x2,t0]=input().split(' ')\n#[t1,t2,x1,x2,t0]=[100,110,2,2,109]\nt1=int(t1)\nt2=int(t2)\nx1=int(x1)\nx2=int(x2)\nt0=int(t0)\n\na=t2-t0\nb=t0-t1\n\nif(a==0 and b==0):\n    print(x1,x2)\n    exit(0)\n\nif (a==0):\n    y1=0\n    y2=x2\n    print(y1,y2)\n    exit(0)\n    \nif (b==0):\n    y1=x1\n    y2=0\n    print(y1,y2)\n    exit(0)\n    \ng=gcd(a,b)\na=int(a/g)\nb=int(b/g)\nif(a<=x1 and b<=x2):\n    mintime=int(x1/a)\n    if(mintime>int(x2/b)):\n        mintime=int(x2/b)\n    print(mintime*a,mintime*b)\n    exit(0)\n\ny1=1\ny2=1\nminy1=1\nminy2=1\nminn=99999\nfg=0\nwhile(y1<=x1 and y2<=x2):\n    if(y1/y2<a/b):\n        if(minn>a/b-y1/y2):\n            minn=a/b-y1/y2\n            miny1=y1\n            miny2=y2\n            fg=1\n        y1=y1+1\n    else:\n        y2=y2+1\ny1=miny1\ny2=miny2\nmintime=int(x1/y1)\nif(mintime>int(x2/y2)):\n    mintime=int(x2/y2)\nif(fg==1):\n    print(mintime*y1,mintime*y2)\nelse:\n    print(0,x2)\n\n\n\n\n", "src_uid": "87a500829c1935ded3ef6e4e47096b9f"}
{"source_code": "c = int(raw_input())\nd = raw_input()\n\nb = d.split(' ')\na = 0\n\nfor i in range(c):\n\tif int(b[i]) == 1:\n\t\ta = a+1\n\t\nif a>0:\n\tprint(\"HARD\")\nelse:\n\tprint(\"EASY\")\t\t\n", "src_uid": "060406cd57739d929f54b4518a7ba83e"}
{"source_code": "import fileinput\n\n\ndef calc(a, b):\n    ans = 0\n    l = a + b\n    i = 1\n    while i <= l:\n        P = l // i\n        r = l // P\n        if P <= a and P <= b:\n            an = (a + P) // (P + 1)\n            ax = a // P\n            bn = (b + P) // (P + 1)\n            bx = b // P\n            if an <= ax and bn <= bx:\n                ans += min(ax + bx, r) - max(an + bn, i) + 1\n        i = r + 1\n    return ans\n\n\nif __name__ == '__main__':\n    it = fileinput.input()\n    a, b = [int(x) for x in next(it).split()]\n    print(calc(a, b))\n", "src_uid": "0e6a204565fef118ea99d2fa1e378dd0"}
{"source_code": "hpy,atky,defy = raw_input().split(\" \")\nhpm,atkm,defm = raw_input().split(\" \")\nh,a,d = raw_input().split(\" \")\nhpy,atky,defy = int(hpy),int(atky),int(defy)\nhpm,atkm,defm = int(hpm),int(atkm),int(defm)\nh,a,d = int(h),int(a),int(d)\n\n\ncost = 1000000\nfor i in range(0,max(0,100-atky+defm)+1):\n    for j in range(0,max(0,atkm-defy)+1):\n        if i+atky-defm>0:\n            turn = hpm/(i+atky-defm)\n            if hpm%(i+atky-defm)!=0:\n                turn+=1\n            damage = max(0,turn*(atkm-defy-j)+1-hpy)\n            cost = min(cost,damage*h+i*a+j*d)\nprint cost", "src_uid": "bf8a133154745e64a547de6f31ddc884"}
{"source_code": "n = int(input())\nx = 0\ny = n\ncount = 0\nwhile y>x:\n    check = (n+x+1)*(n-x-1)\n    if y*y <= check:\n        x+=1\n    elif (y-1)*(y-1) <= check:\n        x+=1\n        y-=1\n    else:\n        y-=1\n    count+=1\n# print(x,y)\nif n == 0:\n    print(1)\nelse:\n    if x == y:\n        print(count*8)\n    else:\n        print(count*8-4)", "src_uid": "d87ce09acb8401e910ca6ef3529566f4"}
{"source_code": "n, k = map(int, input().split())\nfactorial_mod = [1]\nmod = 998244353\nfor i in range(1, int(6e5)):\n    factorial_mod.append((factorial_mod[-1] * i) % mod)\n\n\ndef bin_coeff(n, r):\n    # return n ! / (r! * (n-r)!)\n    if r > n:\n        return 0\n    ans = factorial_mod[n]\n    ans = (ans * pow(factorial_mod[r], mod-2, mod)) % mod\n    ans = (ans * pow(factorial_mod[n - r], mod - 2, mod)) % mod\n    return ans\n\n\nfans = 0\nfor a in range(1, n+1):\n    number_of_multiples_of_a_less_than_n = n // a\n    # number of ways to choose r elements of n elements with repetition allowed if C(n+r-1, r)\n    # we need to fix the smallest number to a\n    # we cannot choose a again\n    ways = bin_coeff(number_of_multiples_of_a_less_than_n-1, k-1)\n    fans = (fans + ways) % mod\n\nprint(fans)", "src_uid": "8e8eb64a047cb970a549ee870c3d280d"}
{"source_code": "from sys import maxsize, stdout, stdin,stderr\nmod = int(1e9 + 7)\nimport re #can use multiple splits\ndef tup():return map(int,stdin.readline().split())\ndef I(): return int(stdin.readline())\ndef lint(): return [int(x) for x in stdin.readline().split()]\ndef S(): return input().strip()\ndef grid(r, c): return [lint() for i in range(r)]\ndef debug(*args, c=6): print('\\033[3{}m'.format(c), *args, '\\033[0m', file=stderr)\nfrom  math import  log2,sqrt\nfrom collections import defaultdict\ns= S().split()\nn = I()\n\nd='^>v<'\nif n%2==0:print('undefined')\nelse:\n    st =d.find(s[0]).__index__()\n    en = d[(st+n)%4]\n    if en==s[1]:print('cw')\n    elif d[(st-n)%4]==s[1]:print('ccw')\n    else:print('undefined')\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298"}
{"source_code": "n, m = map( int, raw_input().split())\nres = 1\nfinal = 1\nfor i in range(m):\n  res = res*2 % (10**9 +9)\nfor i in range(n):\n    final = (final*(res-1)) % (10**9+9)\n    res -= 1\nprint final \n  \n", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8"}
{"source_code": "fn, ln=input().split()\n\n# fn='tom'\n# ln='riddle'\n\ndef gensub(s):\n\tres = []\n\tn=len(s)\n\tfor i in range(1,n+1):\n\t\tres.append(s[0:i])\n\treturn res\n\ngfn = gensub(fn)\ngln = gensub(ln)\n\nnames = [f + l for f in gfn for l in gln]\n\n\n# print(names)\nprint(min(names))\n# print('tor'<'tom')", "src_uid": "aed892f2bda10b6aee10dcb834a63709"}
{"source_code": "MOD = 10**9+7\r\ndef f(n, k):good = (n-1) & 1;maybe = (pow(2, n-1, MOD) + 1 - 2*good) % MOD;all_ = pow(2, n, MOD);return (good * (pow(all_, k, MOD) - pow(maybe, k, MOD)) * pow(all_ - maybe, MOD-2, MOD) + pow(maybe, k, MOD)) % MOD\r\nfor _ in range(int(input())):n, k = map(int, input().split());print(f(n, k))", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881"}
{"source_code": "R=raw_input\na,b=map(int,R().split())\ns=R()\ndef f(s):\n c=s.count\n return c('R')-c('L'),c('U')-c('D')\nX,Y=f(s)\nx,y=0,0\nq=0\nfor i in range(len(s)):\n c,d=f(s[:i])\n A=a-c;B=b-d\n if (X and A%X) or (Y and B%Y):continue\n if X==Y==0:\n  if A==B==0:q=1\n elif X==0:\n  if A==0 and B//Y>=0:q=1\n elif Y==0:\n  if B==0 and A//X>=0:q=1\n elif A//X==B//Y and A//X>=0:q=1\nprint[\"No\",\"Yes\"][q]\n\n", "src_uid": "5d6212e28c7942e9ff4d096938b782bf"}
{"source_code": "s=input()\nd=input()\nl1=[]\nl2=[]\na=len(s)\nb=len(d)\ni=0\nflag=0\nwhile(a):\n    l1.append(s[a-1])\n    a=a-1\nwhile(b):\n    l2.append(d[i])\n    i=i+1\n    b=b-1\nfor j in range(len(s)):\n    if(l1[j]!=l2[j]):\n        flag=1\n        break\nif(flag==0):\n    print(\"YES\")\nelse:\n    print('NO')", "src_uid": "35a4be326690b58bf9add547fb63a5a5"}
{"source_code": "from sys import stdin, stdout\nfrom types import GeneratorType\n\ndef bootstrap(f, stack=[]):\n    def wrappedfunc(*args, **kwargs):\n        if stack:\n            return f(*args, **kwargs)\n        else:\n            to = f(*args, **kwargs)\n            while True:\n                if type(to) is GeneratorType:\n                    stack.append(to)\n                    to = next(to)\n                else:\n                    stack.pop()\n                    if not stack:\n                        break\n                    to = stack[-1].send(to)\n            return to\n\n    return wrappedfunc\n\nn = int(stdin.readline())\nA = [int(x) for x in stdin.readline().split()]\n\n@bootstrap\ndef f(A, k, moved):\n    if A == 'boom':\n        yield 0\n    elif k == len(A):\n        yield n\n    elif moved > 1:\n        yield n\n\n    else:\n        candidate1 = (yield f(A,k+1,moved+1))\n        shot = A[len(A)-k-1]^A[len(A)-k]\n        if (len(A)-k-2>=0 and shot < A[len(A)-k-2]) or (k > 1 and shot > A[len(A)-k+1]):\n            Aprime = 'boom'\n        else:\n            Aprime = A[:len(A)-k-1] + [shot] + A[len(A)-k+1:]\n            if moved < 0:\n                moved = 0\n        candidate2 = 1 + (yield f(Aprime, k, moved))\n\n        yield min(candidate1, candidate2)\n\nanswer = f(A,1,-n)\nif answer >= n:\n    answer = -1\n\nstdout.write(str(answer)+'\\n')\n", "src_uid": "51ad613842de8eff6226c97812118b61"}
{"source_code": "from collections import *\n\nread_line = lambda: [int(i) for i in input().split(' ')]\n\nn = read_line()[0]\ncs = [c - 1 for c in read_line()]\ng = [[] for v in range(n)]\nparent_cnt = [0] * n\nfor v in range(n):\n    parents = read_line()\n    parent_cnt[v] = len(parents) - 1\n    for i in range(1, len(parents)):\n        g[parents[i] - 1].append(v)\n\ndef work(x):\n    pcnt = list(parent_cnt)\n    qs = [\n        deque(v for v in range(n) if cs[v] == c and pcnt[v] == 0)\n        for c in range(3)\n    ]\n    ans = 0\n    while True:\n        while qs[x]:\n            v = qs[x].popleft()\n            ans += 1\n            for w in g[v]:\n                pcnt[w] -= 1\n                if pcnt[w] == 0:\n                    qs[cs[w]].append(w)\n        if qs[0] or qs[1] or qs[2]:\n            ans += 1\n            x = (x + 1) % 3\n        else:\n            break\n    return ans\n\nprint(min(work(i) for i in range(3)))\n", "src_uid": "be42e213ff43e303e475d77a9560367f"}
{"source_code": "import math\n\ndef printDivisors(n) :\n    ls=[]\n    i = 1\n    while i <= math.sqrt(n): \n        if (n % i == 0) : \n            if (n / i == i) : \n                ls.append(i) \n            else : \n                ls.append(i)\n                ls.append(n//i)\n        i = i + 1\n    return ls\n\ndef gcd(a,b): \n    if a == 0: \n        return b \n    return gcd(b % a, a) \ndef lcm(a,b): \n    return (a*b) / gcd(a,b) \n\nt=int(input())\nfor _ in range(t):\n    n=int(input())\n    if(n%2==0):\n        tem=n//2\n        print(tem,tem)\n    else:\n        ls=printDivisors(n)\n        if(len(ls)==2):\n            print(1,n-1)\n        else:\n            mi=float('inf')\n            ans1=0\n            ans2=0\n            for i in ls:\n                if(i!=n):\n                    tem=lcm(i,n-i)\n                    if(tem<mi):\n                        ans1=i\n                        ans2=n-i\n                        mi=tem\n            print(ans1,ans2)\n                \n            ", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"}
{"source_code": "\r\ndef main():\r\n    \r\n    n, m = readIntArr()\r\n    \r\n    tableVi = [False] * (22 * (m + 1) + 5)\r\n    \r\n    # find unique cnts in multiplication table:\r\n    #     1 2 3  4.. m\r\n    #     2 4 6  8..\r\n    #     3 6 9  12\r\n    #     4 8 12 16\r\n    #     n 2n 3n .. nm\r\n    # Note that n is only up to ~ 20 while m can go to 1e6.\r\n    tableCnts = [-1] * 22\r\n    cnt = 0\r\n    for i in range(1, 22):\r\n        for j in range(1, m + 1):\r\n            x = i * j\r\n            if tableVi[x] == False:\r\n                tableVi[x] = True\r\n                cnt += 1\r\n        tableCnts[i] = cnt\r\n    \r\n    ans = 1 # for 1st row\r\n    vi = [False] * (n + 1) # visited rows\r\n    \r\n    for i in range(2, n + 1):\r\n        if vi[i] == False:\r\n            N = 0\r\n            j = i\r\n            while j <= n: # powers of i may overlap. convert powers into a multiplication table\r\n                vi[j] = True\r\n                N += 1\r\n                j *= i\r\n            ans += tableCnts[N]\r\n    print(ans)\r\n    \r\n    return\r\n \r\nimport sys\r\ninput=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)\r\n# input=lambda: sys.stdin.readline().rstrip(\"\\r\\n\") #FOR READING STRING/TEXT INPUTS.\r\n \r\ndef oneLineArrayPrint(arr):\r\n    print(' '.join([str(x) for x in arr]))\r\ndef multiLineArrayPrint(arr):\r\n    print('\\n'.join([str(x) for x in arr]))\r\ndef multiLineArrayOfArraysPrint(arr):\r\n    print('\\n'.join([' '.join([str(x) for x in y]) for y in arr]))\r\n \r\ndef readIntArr():\r\n    return [int(x) for x in input().split()]\r\n# def readFloatArr():\r\n#     return [float(x) for x in input().split()]\r\n \r\ndef makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m])\r\n    dv=defaultValFactory;da=dimensionArr\r\n    if len(da)==1:return [dv() for _ in range(da[0])]\r\n    else:return [makeArr(dv,da[1:]) for _ in range(da[0])]\r\n \r\ndef queryInteractive(a, b, c):\r\n    print('? {} {} {}'.format(a, b, c))\r\n    sys.stdout.flush()\r\n    return int(input())\r\n \r\ndef answerInteractive(x1, x2):\r\n    print('! {} {}'.format(x1, x2))\r\n    sys.stdout.flush()\r\n \r\ninf=float('inf')\r\n# MOD=10**9+7\r\n# MOD=998244353\r\n \r\nfrom math import gcd,floor,ceil\r\nimport math\r\n# from math import floor,ceil # for Python2\r\n \r\nfor _abc in range(1):\r\n    main()", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead"}
{"source_code": "from sys import stdin,stdout,setrecursionlimit,maxint,exit\n#setrecursionlimit(2*10**5)\ndef listInput():\n return map(long,stdin.readline().split())\ndef printBS(li):\n for i in xrange(len(li)-1):\n  stdout.write(\"%d \"%li[i])\n stdout.write(\"%d\\n\"%li[-1])\ndef sin():\n return stdin.readline().rstrip()\ns=sin()\nn=len(s)\nrep={chr(65+i):[] for i in xrange(26)}\nfor i in xrange(n):\n rep[s[i]].append(i)\nrepp=\"\"\nrepi=[]\nfor i in rep:\n if len(rep[i])==2:\n  repp=i\n  repi=rep[i]\n#print repp,repi\nif repi[0]+1==repi[1]:\n print \"Impossible\"\n exit(0)\nt=s[:repi[1]]+s[repi[1]+1:]\n_=0\nwhile _<27:\n #print t\n mat=[[\"\"]*13 for i in xrange(2)]\n pos={chr(65+i):(0,0) for i in xrange(26)}\n for i in xrange(13):\n  mat[0][i]=t[i]\n  pos[t[i]]=(0,i)\n for i in xrange(13):\n  mat[1][i]=t[i+13]\n  pos[t[i+13]]=(1,12-i)\n mat[1].reverse()\n #print \"\".join(mat[0])\n #print \"\".join(mat[1])\n #print pos\n curr=s[0]\n i=1\n while i<=26:\n  if abs(pos[s[i]][0]-pos[curr][0])<=1 and abs(pos[s[i]][1]-pos[curr][1])<=1:\n   curr=s[i]\n   i+=1\n  else: break\n else:\n  print \"\".join(mat[0])\n  print \"\".join(mat[1])\n  exit(0)\n t=t[-1]+t[:-1]\n _+=1\n ", "src_uid": "56c5ea443dec7a732802b16aed5b934d"}
{"source_code": "\nx = input()\nhello = \"hello\"\nj=0\ncount=0\nfor i in range(len(x)):\n    if x[i]==hello[j]:\n        j+=1\n        count+=1\n    if count==5:\n        break\nif count==5:\n    print(\"YES\")\nelse:\n    print(\"NO\")", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"}
{"source_code": "import sys\ninput = sys.stdin.readline\nfrom collections import *\n\ndef bfs():\n    q = deque([])\n    dist = [-1]*(n*2*k)\n    \n    for i in range(2*k):\n        q.append(i)\n        dist[i] = 0\n    \n    while q:\n        v = q.popleft()\n        \n        for nv in G[v]:\n            if dist[nv]==-1:\n                dist[nv] = dist[v]+1\n                q.append(nv)\n    \n    for i in range(2*k):\n        if dist[(n-1)*2*k+i]!=-1:\n            return True\n    \n    return False\n\nfor _ in range(int(input())):\n    n, k, l = map(int, input().split())\n    d = list(map(int, input().split()))\n    G = [[] for _ in range(n*2*k)]\n    p = [i for i in range(k+1)]+[i for i in range(k-1, 0, -1)]\n    \n    for i in range(n):\n        for j in range(2*k):\n            if d[i]+p[j]<=l and d[i]+p[(j+1)%(2*k)]<=l:\n                G[i*2*k+j].append(i*2*k+(j+1)%(2*k))\n            \n        if i+1<n:\n            for j in range(2*k):\n                if d[i]+p[j]<=l and d[i+1]+p[(j+1)%(2*k)]<=l:\n                    G[i*2*k+j].append((i+1)*2*k+(j+1)%(2*k))\n    \n    if bfs():\n        print('Yes')\n    else:\n        print('No')", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8"}
{"source_code": "h,m=map(int,input().split(':'))\nm+=h*60\nwhile 1:\n  m=(m+1)%1440\n  r=f'{m//60:02}:{m%60:02}'\n  if r==r[::-1]:\n    print(r)\n    break\n", "src_uid": "158eae916daa3e0162d4eac0426fa87f"}
{"source_code": "a = raw_input().split(' ')\nprint int(a[1])*(int(a[0])//int(a[1])+1)\n", "src_uid": "75f3835c969c871a609b978e04476542"}
{"source_code": "import sys\n\nn, m = [int(x) for x in input().split(' ')]\narr = [int(x)-1 for x in input().split(' ')]\nk = [int(x) for x in input().split(' ')]\n\nsumm = 0\nfor i in range(m):\n\tsumm += k[i]\n\nfor i in range(n):\n\tif i >= summ:\n\t\tk[arr[i-summ]] += 1\n\tk[arr[i]] -= 1\n\tdone = True\n\tfor j in range(m):\n\t\tif k[j] != 0:\n\t\t\tdone = False\n\tif done:\n\t\tprint('YES')\n\t\tsys.exit()\nprint('NO')", "src_uid": "59f40d9f35e5fe402112214b42b682b5"}
{"source_code": "recipe=input() \nrb,rs,rc=recipe.count('B'),recipe.count('S'),recipe.count('C')\nnb,ns,nc=map(int,input().split())\npb,ps,pc=map(int,input().split())\nx=int(input())\n#print(rb,rs,rc)\ndef check(mi): \n    reqb,reqs,reqc=rb*mi,rs*mi,rc*mi \n    #print(reqb,reqs,reqc)\n    reqb-=nb \n    reqc-=nc \n    reqs-=ns \n    #print(reqb,reqc,reqs)\n    return max(reqb,0)*pb+max(reqs,0)*ps+max(reqc,0)*pc<=x\n\nlo=0 \nhi=10**20 \nwhile lo<=hi:\n    mi=(lo+hi)>>1 \n    if check(mi):\n        ans=mi \n        lo=mi+1 \n    else:\n        hi=mi-1 \nprint(ans)\n", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e"}
{"source_code": "from sys import stdin, stdout\nfrom math import factorial\n\nMOD = 10 ** 9 + 7\nINF = float('inf')\nsze = 10 ** 2\nEPS = 10 ** -6\n\n\nn, m, t = map(int, stdin.readline().split())\nans = 0\n\nfor i in range(4, min(t, n + 1)):\n    if t - i <= m:\n        ans += factorial(n) * factorial(m) // (factorial(i) * factorial(n - i)) // (factorial(t - i) * factorial(m - t + i))\n\nstdout.write(str(ans))", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8"}
{"source_code": "\ns = input()[::-1]\n\nxval = ['x']\n\ndef compare(c,target):\n\n    if c==target:  return True\n    if c=='_':  return True\n    if c=='X':  \n        if xval[0]=='x':\n            xval[0] = target\n            return True\n        else: return xval[0]==target\n\n    return False\n\n\ndic = {}\ndef getnext(index,xval):\n\n    if index==n-1:\n        if s[index]=='_': return 9\n        elif s[index]=='X':\n            if xval=='x': return 9\n            else:  return xval!='0'\n        else:\n            return s[index]!='0'\n\n    if (index,xval) in dic:  return dic[(index,xval)]\n\n    output = 0\n    if s[index]=='_':  output =  10 * getnext(index+1,xval)\n    elif s[index]=='X':  \n        if xval!='x':  output =  getnext(index+1,xval)\n        else:  \n            for c in range(10):\n                output += getnext(index+1,str(c))\n\n    else:  \n        output =  getnext(index+1,xval)\n\n    dic[(index,xval)] = output \n    return output \n\n           \n    \n\n\n\n\nn = len(s)\n\nif n==1:  \n    if (s[0]=='0' or s[0]=='_' or s[0]=='X'):\n        print(1)\n    else:\n        print(0)\n    exit()\n    \n\ncandidate = ['52','05','57']\nif n>2: candidate.append('00')\n\n\nans = 0\n\nfor c0 in range(10):\n    for c1 in range(10): \n        if n==2 and c1=='0': continue \n\n        xval[0] = 'x'\n        if not compare(s[0],str(c0)) or not compare(s[1],str(c1)):  continue \n\n#        print(c0,c1)\n        if n==2: \n            if str(c0)+str(c1) in candidate:  ans += 1\n            continue \n\n        if str(c0) + str(c1) in candidate:\n\n            ans += getnext(2,xval[0])\n\n\nprint(ans)\n\n\n\n        \n\n", "src_uid": "4a905f419550a6c839992b40f1617af3"}
{"source_code": "n, k = map(int, input().split())\nl = list(map(int, input().split()))\n\ni = 0\nbuf = 0\n\nwhile i < n:\n    if l[i] + buf > 8:\n        k = k - 8\n        buf = buf + l[i] - 8\n    else:\n        k = k - buf - l[i]\n        buf = 0\n\n    i += 1\n\n    if k <= 0:\n        print(i)\n        break\n\nif k > 0:\n    print(-1)", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a"}
{"source_code": "def solve(t_id):\n    s = input()\n    ans = 0\n    for c in s:\n        if c in ['a', 'e', 'i', 'o', 'u'] or (c.isdigit() and int(c) % 2 == 1):\n            ans += 1\n    print(ans)\nt = 1\n#t = int(input())\nfor t_id in range(1, t + 1):\n    solve(t_id)\n    t -= 1", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223"}
{"source_code": "a ,b = [int(x) for x in input().split()]\nl = [int(x) for x in input().split()]\n\nsmall = 0\ns = 0\n\nfor i in range(a):\n    if l[i] < b:\n        small += 1\n    elif l[i] == b:\n        s = 1\n        \nprint(b-small +s)", "src_uid": "21f579ba807face432a7664091581cd8"}
{"source_code": "k2,k3,k5,k6 = map(int,raw_input().split())\nleast = 0\n\nif k2 < k5:\n    least = k2\nelse:\n    least = k5\nif k6 < least:\n    least = k6\n\nleft = k2 - least\nif left < k3:\n    left_least = left\nelse:\n    left_least = k3\n\nprint (least*256 + left_least*32)", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e"}
{"source_code": "n = [int(i) for i in input().split()]\nl = [int(i) for i in input().split()]\nl1 = [int(i) for i in input().split()]\nans=\"\"\nfor i in l:\n    if i in l1:\n        ans += str(i)+\" \"\n        \nprint(ans)", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72"}
{"source_code": "s = input()\nn = int(input())\n\nt = [j for j, q in enumerate(s) if q == 'T']\nl, r = [0] * 101, [0] * 101\n\nfor i, (a, b) in enumerate(zip([-1] + t, t + [len(s)])):\n    v = b - a\n    u = v - 1\n\n    for k in range(i, 0, -1):\n        l[k] = max(l[k] + u, l[k - 1] + v)\n        r[k] = max(r[k] - u, r[k - 1] - v)\n        u, v = -u, -v\n\n    r[i + 1] = l[i] - 1\n\n    l[0] += u\n    r[0] -= u\n\nprint(max(l[n % 2:n + 1:2] + r[n % 2:n + 1:2]))", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d"}
{"source_code": "n,k = raw_input().split(\" \")\nk = int(k)\n\nd = 0\nfor i in map(int, n)[::-1]:\n    if i:\n        d+=1\n    else:\n        k-=1\n        if k == 0:\n            break\nelse:\n    d = len(n)-1\nprint d", "src_uid": "7a8890417aa48c2b93b559ca118853f9"}
{"source_code": "t=raw_input()\np=raw_input()\nc=[0]*10\nfor d in t:\t\n\tc[int(d)]+=1\nc[2]+=c[5]\nc[5]=c[2]\nc[6]+=c[9]\nc[9]=c[6]\nC=[0]*10\nfor d in p:\n\tC[int(d)]+=1\nC[2]+=C[5]\nC[5]=C[2]\nC[6]+=C[9]\nC[9]=C[6]\nprint min([C[i]/c[i] for i in range(10) if c[i]>0])", "src_uid": "72a196044787cb8dbd8d350cb60ccc32"}
{"source_code": "import string\n\ndef title(s, k):\n    s = list(s)\n\n    # list of first k latin letters\n    letters = list(string.lowercase[:k])\n    # remove letters in s\n    for l in s:\n        if l != '?' and l in letters:\n            letters.remove(l)\n    \n    # check palindromic property, fill in if necessary\n    if len(s)%2 == 0:\n        i, j = len(s)//2-1, len(s)//2\n    else:\n        i, j = len(s)//2, len(s)//2\n    while j<len(s):\n        # s[i] == s[j] -> ok\n        # either s[i] or s[j] is '?' -> copy\n        # both '?' -> pop missing letter\n        if s[i] != s[j]:\n            if s[i] == '?':\n                s[i] = s[j]\n            elif s[j] == '?':\n                s[j] = s[i]\n            else:\n                return 'IMPOSSIBLE'\n        elif s[i] == '?':\n            # pop\n            if len(letters) == 0:\n                s[i] = s[j] = 'a'\n            else:\n                s[i] = s[j] = letters.pop(-1)\n        i -= 1\n        j += 1\n        \n    if len(letters)>0:\n        return 'IMPOSSIBLE'\n        \n    return ''.join(s)\n\n#k = 2\n#s = '????'\n#print title(s, k)\n\n#k = 16\n#s = '?bc??f?hi?k??n??hb??liiglal???npi???b???p?n?j?al????j???ponmlkjih??e??b?'\n#print title(s, k)\n\nk = int(raw_input())\ns = str(raw_input())\nprint title(s, k)\n", "src_uid": "9d1dd9d722e5fe46823224334b3b208a"}
{"source_code": "a, b = map(int, input().split())\nprint(min(a, b), (max(a, b) - min(a, b)) // 2, sep=' ')\n", "src_uid": "775766790e91e539c1cfaa5030e5b955"}
{"source_code": "\nimport sys\nn = int(raw_input())\nc = 0\ni = 0\ncount = 0\nwhile(i<n):\n  \n\n    x,str = raw_input().split()\n    \n    x  = int(x)\n    if(c==0):\n        if(str!=\"South\"):\n            print \"NO\"\n            sys.exit()\n    elif(c == 20000):\n        if(str!=\"North\"):\n            print \"NO\"\n            sys.exit()\n            \n            \n            \n    if(str == \"North\"):\n        c = c - x\n        if(c<0 or c>20000):\n            print \"NO\"\n            sys.exit()\n    if(str ==\"South\"):\n         c = c + x;\n         if(c<0 or c>20000):\n             print \"NO\"\n             sys.exit()\n    i = i + 1\nif(c==0):\n    print \"YES\"\nelse:\n    print \"NO\"\n    \n\n    \n         \n", "src_uid": "11ac96a9daa97ae1900f123be921e517"}
{"source_code": "n=input()\np=[map(int,raw_input().split()) for i in range(n)]\nM=map(max,zip(*p))\nm=map(min,zip(*p))\nprint 'YNEOS'[sum((X-x)*(Y-y) for x,y,X,Y in p)!=(M[3]-m[1])**2 or (M[3]-m[1])!=(M[2]-m[0]) ::2]\n", "src_uid": "f63fc2d97fd88273241fce206cc217f2"}
{"source_code": "MOD = 1000000007\ndef isSubset(a, b):\n    return (a & b) == a\ndef isIntersect(a, b):\n    return (a & b) != 0\ndef cntOrder(s, t):\n    p = len(s)\n    m = len(t)\n    inMask = [0 for i in range(m)]\n    for x in range(p):\n        for i in range(m):\n            if t[i] % s[x] == 0:\n                inMask[i] |= 1 << x\n    cnt = [0 for mask in range(1 << p)]\n    for mask in range(1 << p):\n        for i in range(m):\n            if isSubset(inMask[i], mask):\n                cnt[mask] += 1\n    dp = [[0 for mask in range(1 << p)] for k in range(m + 1)]\n    for i in range(m):\n        dp[1][inMask[i]] += 1\n    for k in range(m):\n        for mask in range(1 << p):\n            for i in range(m):\n                if not isSubset(inMask[i], mask) and isIntersect(inMask[i], mask):\n                    dp[k + 1][mask | inMask[i]] = (dp[k + 1][mask | inMask[i]] + dp[k][mask]) % MOD\n            dp[k + 1][mask] = (dp[k + 1][mask] + dp[k][mask] * (cnt[mask] - k)) % MOD\n    return dp[m][(1 << p) - 1]\ndef dfs(u):\n    global a, graph, degIn, visited, s, t\n\n    visited[u] = True\n    if degIn[u] == 0:\n        s.append(a[u])\n    else:\n        t.append(a[u])\n\n    for v in graph[u]:\n        if not visited[v]:\n            dfs(v)\ndef main():\n    global a, graph, degIn, visited, s, t\n    n = int(input())\n    a = list(map(int, input().split()))\n    c = [[0 for j in range(n)] for i in range(n)]\n    for i in range(n):\n        c[i][0] = 1\n        for j in range(1, i + 1):\n            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD\n    degIn = [0 for u in range(n)]\n    graph = [[] for u in range(n)]\n    for u in range(n):\n        for v in range(n):\n            if u != v and a[v] % a[u] == 0:\n                graph[u].append(v)\n                graph[v].append(u)\n                degIn[v] += 1\n    ans = 1\n    curLen = 0\n    visited = [False for u in range(n)]\n    for u in range(n):\n        if not visited[u]:\n            s = []\n            t = []\n            dfs(u)\n            if len(t) > 0:\n                sz = len(t) - 1\n                cnt = cntOrder(s, t)\n                ans = (ans * cnt) % MOD\n                ans = (ans * c[curLen + sz][sz]) % MOD\n                curLen += sz\n    print(ans)\nif __name__ == \"__main__\":\n    main()\n", "src_uid": "c8d43a60ddc0a7b98a7269dc3a2478dc"}
{"source_code": "MOD = 998244353;import __pypy__;int_add = __pypy__.intop.int_add;int_sub = __pypy__.intop.int_sub;int_mul = __pypy__.intop.int_mul\r\ndef make_mod_mul(mod=MOD):\r\n    fmod_inv = 1.0 / mod\r\n\r\n    def mod_mul(a, b, c=0):\r\n        res = int_sub(int_add(int_mul(a, b), c), int_mul(mod, int(fmod_inv * a * b + fmod_inv * c)))\r\n        if res >= mod:\r\n            return res - mod\r\n        elif res < 0:\r\n            return res + mod\r\n        else:\r\n            return res\r\n\r\n    return mod_mul\r\n\r\n\r\nmod_mul = make_mod_mul()\r\n\r\n\r\ndef mod_pow(x, y):\r\n    if y == 0:\r\n        return 1\r\n    res = 1\r\n    while y > 1:\r\n        if y & 1 == 1:\r\n            res = mod_mul(res, x)\r\n        x = mod_mul(x, x)\r\n        y >>= 1\r\n    return mod_mul(res, x)\r\n\r\nn, m = map(int, input().split())\r\n\r\npascal = [[1]]\r\nfor _ in range(n + m + 5):\r\n    nl = [1]\r\n    for i in range(_):\r\n        nl.append((pascal[-1][i] + pascal[-1][i+1]) % MOD)\r\n    nl.append(1)\r\n    pascal.append(nl)\r\n\r\ndef s1(n,m):\r\n    out = 0\r\n    for row in range(1, n):\r\n        above = row\r\n        below = n - row\r\n\r\n        bottom = []\r\n        for i in range(m):\r\n            a = below - 1\r\n            b = i\r\n            a2 = below\r\n            b2 = m-i-1\r\n            bottom.append(mod_mul(pascal[a+b][a] , pascal[a2+b2][a2]))\r\n\r\n        top = []\r\n        for i in range(m):\r\n            a = above - 1\r\n            b = i\r\n            a2 = above\r\n            b2 = m-i-1\r\n            top.append(mod_mul(pascal[a+b][a] , pascal[a2+b2][a2]))\r\n        top.reverse()\r\n\r\n        curr = 0\r\n        for i in range(m):\r\n            out += mod_mul(curr,bottom[i])\r\n            curr += top[i]\r\n            curr %= MOD\r\n            out %= MOD\r\n    return out * 2\r\n\r\ndef s2(n,m):\r\n    o = 0\r\n    for i in range(1,n):\r\n        for j in range(1,m):\r\n            a = pascal[i+j-1][i-1]\r\n            b = pascal[n-i+j-1][n-i]\r\n            c = pascal[n-i-1+m-j][m-j]\r\n            d = pascal[i+m-j-1][i]\r\n            #print(a,b,c,d)\r\n            o += mod_mul(mod_mul(a,b),mod_mul(c,d))\r\n    return o\r\n\r\n\r\nc1 = s1(n,m)\r\nc2 = s1(m,n)\r\nc3 = s2(n,m)\r\n\r\nout = (c1 + c2 - 2*c3) % MOD\r\nprint(out)", "src_uid": "1738dc65af1fffa445cb0c3074c6bedb"}
{"source_code": "#!/usr/bin/env python\nn=input()\ncard = raw_input().strip().split()\nimport Queue\nq = Queue.Queue()\nq.put(card)\ns = set([tuple(card)])\nres = \"YES\"\nwhile not q.empty():\n    c = q.get();\n    if len(c)==1:\n        break\n    for i in(-2,-4):\n        if len(c)>=-i and(c[-1][0]==c[i][0]or c[-1][1]==c[i][1]):\n            d=list(c)\n            d[i+1]=d.pop();\n            if tuple(d) not in s:\n                s.add(tuple(d))\n                q.put(d)\nelse:\n    res = \"NO\"\nprint res\n\n", "src_uid": "1805771e194d323edacf2526a1eb6768"}
{"source_code": "\ns = raw_input()\n\np = 1\n\nnum = 0\n\nfor i in xrange(len(s)-1,-1,-1):\n    num = (num + p*int(s[i]))\n    p*=2\nprint (num* 2**(len(s)-1))  % 1000000007\n    \n    \n\n", "src_uid": "89b51a31e00424edd1385f2120028b9d"}
{"source_code": "x,y,z,t1,t2,t3=list(map(int,input().split()));c=x,y,z,t1,t2,t3\nif c[0]<c[1]:b=(-(c[0]-c[1]))\nelse:b=c[0]-c[1]\nd=b*c[3]\nif c[0]<c[2]:e=-(c[0]-c[2])\nelse:e=c[0]-c[2]\nk=e*c[4]+2*c[5]+c[5]+b*c[4]\nif d>=k:print(\"yes\")\nelse:print(\"no\")\n", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca"}
{"source_code": "print 25", "src_uid": "dcaff75492eafaf61d598779d6202c9d"}
{"source_code": "def sum_digits(a):\n    if (a < 10):\n        return a\n    else:\n        return a % 10 + sum_digits(a // 10)\n\ndef f(a):\n    a = str(a)\n    return int(str(int(a[0]) - 1) + '9' * (len(a) - 1))\n\na = int(input())\nres = f(a)\nt = str(a)[0] + '9' * (len(str(a)) - 1)\nres2 = 0\n\nfor i in range(1, len(t)):\n    t1 = t[:i] + '8' + t[i+1:]\n    t1 = int(t1)\n    if t1 <= a:\n        res2 = t1\n    else:\n        break\n\nressum = sum_digits(res)\nasum = sum_digits(a)\n\nif (asum > ressum):\n    print(a)\nelse:\n    print(max(res, res2))\n", "src_uid": "e55b0debbf33c266091e6634494356b8"}
{"source_code": "#sry...\n\nv1, v2 = map(int, input().split())\nt, d = map(int, input().split())\nL1 = [0]*t\nL2 = [0]*t\nL1[0] = v1\nfor i in range(1, t):\n    L1[i] = L1[i-1]+d\nj = t-2\nL2[j+1] = v2\nwhile j >= 0:\n    L2[j] = L2[j+1]+d\n    j -= 1\nans = 0\nfor i in range(0, t):\n    ans += min(L1[i], L2[i])\nprint (ans)\n", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf"}
{"source_code": "dp=[0]*5010\ndp[0]=1\nn,m,k=map(int,input().split())\nt=998244353\nfor i in range(k):\n    for j in range(len(dp)-1, -1, -1):\n        if j==0:dp[j]=0\n        else:dp[j]=(dp[j-1]*(n-j+1)+dp[j]*j)%t\nc=0\nfor i in range(k+1):\n    c+=pow(m,max(n-i,0),t)*dp[i]\n    c%=t\nden=pow(m,n,t)\nden=pow(den,t-2,t)\nprint((den*c)%t)", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b"}
{"source_code": "vals = [0, 2, 4, 11, 32, 97, 295, 940, 3148, 10901, 38324, 135313, 478989, 1704939, 6120951, 22187311, 81129556, 298715961, 1105546606, 4107686743, 15311861251, 57245614745, 214625591690, 806848059041, 3040880190559, 11487184020677, 43485050394205, 164927004274136, 626608618666934, 2384493434591620, 9087529927375918, 34682392280950974, 132542351686437644, 507171591796393381, 1943050156148444582, 7452770379302126187, 28617610413867287010, 110004285524692169216, 423278853888970409883, 1630293028998903898224, 6285059739994372175113, 24251646015941054123514, 93658090212564057369267, 361998255935404053662628, 1400264769080901203586626, 5420536513622893899223411, 20998547288236908910221869, 81402555582647387745072353, 315773811781519195206203743, 1225720522015608235445806021, 4760719694151787159929017594, 18501572033220094871426132593, 71943092199993678724857210801, 279900787023066422206380766515, 1089542787771588881232684451558, 4243270322763252541573736843398, 16533504004199807912573377049815, 64450888875566769728212852796272, 251353626653428916209479575238346, 980678120264352074967128926804970, 3827772695602948667320461087747608, 14946438805836705201610573978579332, 58384183641939996074486313064537042, 228146013979094959932481402500104857, 891836734216487281263993819053310580, 3487446305259076789631430819941164781, 13641891354433181356051446335973874898, 53380418002140832442127026242477826983, 208941818119368213463213106465436894420, 818089279597127665466775004269944627746, 3204085518917391642418980497822707368946, 12552548116979151772259349500529912185843, 49190428824796945806814476487174834833637, 192817716405499011473650043729840753603575, 756010333197049943262587147038690044323990, 2964967973738716215665619390729889117524126, 11631103235901605746966358476195230631624401, 45638117709881716820884625066346212193997756, 179117430766782718986585277827256933832578361, 703151339946287405256622851905491035823870364, 2760947953575465122602355158892640666820856655, 10843358244638208764264135386695995237230629260, 42595466751701481649228987244607986409898023182, 167361224438360440216773707743558900398932244382, 657712618935505465438291334703722328200913085438, 2585267129244075193809802877463649441653730126578, 10163907817638626817716918583895182831004513613123, 39966879600102108651549930111231157595519353367123, 157189034927496653479371759900026083719376366733614, 618336723242289821990531677547460787238476902915199, 2432803210487705745299587099505477676690341445712692, 9573406030090228456311712528276315005390377833848765, 37679227834331314384610566709094016942462047210730106, 148324205307544414472966671933319118336620842676034017, 583976180035270137125482861057965298570997748434633384, 2299587233992938795306777931535364083324792816656702562, 9056803044160163377763486214083966370497445758220238091, 35675403784053203605687069929418410353969228253977145175, 140549888973728380230585821156179869098315235374112780826, 553807051777443444619226740438552112146914572740818813349, 2182486580317155631599040361201576579661428502121123653136, 8602181468318536143561958614628117733446887135993193611259, 33910044229098624305263229397172982034616011218746549038961, 133693317292732811080040087400152346242814293126404041861193, 527170992897482625043862793628047993596077613055004462678358, 2078991323053339085220679240645759577116281504673965228281165, 8199967674079627513978859635806997637089923310593314990686802, 32346615646788397692645101000786880447192779976021484665026491, 127615014986565116912823011055488469695887719846538447148962878, 503535300132270633737648282143125136291637827235646987383725796, 1987066070190752220539052383119214966394869616456484179319219065, 7842381691354570986450767323914631805571692713415931280867539121, 30955369342236909413806190480686935113629828042777927462299708227, 122201190138992862183156046825436224148821835549252243468507301695, 482464559698258280614105143074906719974084230825244765227211470338, 1905044210329310933012883474559145946790917492784787928227261446437, 7523042318799748660208705403536100792111075885171898541934731742390, 29711865307743859983774105830474814695120217213404274613967605343142, 117358210334644832241289809026318941566777541081906921752718004064223, 463599954895501530333274519944443410381288269629861291846027518952547, 1831550319939959155587395984307016482400316562294418569080566939394373, 7236675876342106283578534336330743048842197598376804592542495717488169, 28595877959236188869992380241499418925461422245402511601972127083938809, 113008487488979608728537052095796235153826972386884347812349453027284777, 446643776276434337481901364650647855177976433243812620954649695122316826, 1765441807395465620252685967072498086035986271227159688590935355004060027, 6978896171078699499744178015254900571985547608845028328618588278612230285, 27590565813291130651676295962305434607391880724234668660140969043129437306, 109087342089418473054846937271841020723765346564892390158006517105586188244, 431347570427895275684887399889776157420375297525437055850000845301829933805, 1705764090654176600783120803651477353278324598907144288980953523257690938954, 6746034859339085323037813551799895795035073688161810095995890114587607307967, 26681829042596408508727803106987892830022155937080103881413184938373444601780, 105540568643047320085637757372875138941484282898455734499378871247031545034426, 417502908721193606389605307438517612545962933342696670188454638798883820258264, 1651715574747214150853710839970797716108744553638299319610439913405742985968373, 6535008503124889007856937275951632354585153583690531839980836461545232215824404, 25857804572051561459180314229189646010564292988633513533872884661419076724098956, 102322517183818948564124541851280345149045011490572076449791435684627433270629411, 404934094236883704120894459814765768721634186306504238924488061567317975693145340, 1602619915399511600553438890014229979328824144334807821204535561824879143206962453, 6343213042207650159611655077596947878673846137393784013748813764014784872364716886, 25108464423291463997404385112070199473744447497076474425682598855413110035742418914, 99394563947684374904758920726914308485128620392393490084506181225843747588475207197, 393492336753755531692026489972641598688144826660754601765695380807032546907543503921, 1557903824987562696463244084053237928311159497375106563075214332506952142892403104132, 6168439205715589425691171307912496909504919319342781227412278678910873593341882573211, 24425293227292450643484793977655277617059585096421595028507694237157052955457119327788, 96723881571135418665545369057123041094621729891750877288042985634178222443867299246418, 383051061687942536045084445172520830808282863996319158056819349124211693991398816327207, 1517079174117195579690955122633080343549424859594834854448758112231369900479121012142113, 6008804205917549913707301141913450089100988933558420551241354568832564553473079190572278, 23801027487732914406483006100676356957141654837362665600929752551423761670767951464675913, 94282443605173282918820528593155670207503470313471709302507741333407860445366620005663942, 373502108594609108040503037731586547276548840138645909419252430705207407681196709803983480, 1479728471960463699182943027707841420937310959692022055363898209234875053818609663966205866, 5862696271018571500089423595308441031224631020361921119823688743286535539779290630567630424, 23229443652081270733980663131770350007457433326179896912355233731751050724947198946004003975, 92046214646244587690706228458864173904798062070835842020367088988974705829518078204001021363, 364752635838858477460715070856088351075708777551436448235555244229366219828253326349002137500, 1445493034116344468923655951043320186128439597523080639496656917977382053690974380985547117707, 5728729409451696444372051461356534264846576646485085732046890058188716009614118855674637377976, 22705185146420504401997097103314578637547420523062806257838636533087251029395653129572040040074, 89994488892654396058856217300404040365891816827131704366554032344385475130012751055422998088811, 356722590821763183370769773946287974891959302880630650897935809030336785839603723618464030276788, 1414063305994736576027292395949115069687019850459912237903595491623285483544543552340164385746823, 5605706391578319849214622281168740607481793100182010208297580436542090440514111407701729518697618, 22223620744205360017667654052757026972000168259047208882853304998777155752466388108220124201070651, 88109348206147011746068556866098564625699209460062623605419377857389060105300638390094653102087665, 349342636080041683221934374226900622820872946841401311867352745078418891476797889097584439698488510, 1385170925534265899519131581097494785149908651513473500940930511309994846416946247702384780811305993, 5492588368773762187176960346750382398248979869518043882552293646465784762754580760180824188726279279, 21780728267753329002789566624916226339853435239931399185927732684141543568339811214313133006185789862, 86375216875091724004892983761031261568077226356560376884219660239075463095982915374142957348433560808, 342552444573954421439069379710177772069561072341619580877761685530229948518863741413885365554900097068, 1358582195600779764137599964716337955978399926986276091819585687264212241288091184793396726965847374717, 5388469875817259323304509591448381084385961063465665255658239637278204961430203993624180560639796747605, 21372998850022699161426070331663358980991055327568017672150484504323229468157683662487272446683394953616, 84778494911805672551905487568003378988055807689922250276608386182662094701118796017840631111511241539380, 336299294984076094211910140735246876668599223869497646602011823658647050190386550822954545260278612631544, 1334092702567721627301741363861098515979926575994751181111582340637309219232241033600092838437900802205038, 5292558212680523400742812226353811345695668866524041146689910628871196088819553304554474876050018124114153, 20997357930969861565036947992351357737332219482074988303743785974044064606333782872828128356414654770048429, 83307255301650683813771759430113027376624989750108038627604618437376758764431340497982895988412865509848646, 330536911422094638826855051199545833594432618486709155341244741865583122131341876999368620130514508527934886, 1311522869083496832871707350626892106751939874234564517468101657197217628921812764530031965246754289948832905, 5204156397188024528172208860333403395144057036547715697743789160749123289693413744575143624612520273136245942, 20651099904331266347452312738842587016214690030449557930458679449892111940939905103364939451289307748992021705, 81950993437459573466341756935194915370706037015935432733554932948181854760107481589302122500483380360974120698, 325224502658680918621143766183198696515890363756397080976420998474791236483195824901624062741635519646490626407, 1290714269690655531306881841380634199972701772564446091319466174738466016505934864779800047925147878259285097303, 5122649034621028257092921727961683522826738055239047518130182514401914195565325824742487436606026182522647156675, 20331833918723604572328478218344871921785349256218990332867325768701950803782350327182973980977910184990231738767, 80700419210399288565532992313764196322776455936388215324863888557166663083824127963351927392338983532130677066691, 320325964488275811162806976162403939204447615115097764645943597768559937809078043653016835390579784416806189815956, 1271526570389220738417720962998566369113558429608467759079824319778588199759814382086958737211830037441352944048167, 5047490573839566652123419730499281587581764724700676283660476791813590196494125779764142565481025618321161423806066, 20037438807446179847249688629193061142526113477517522632902620906339929842504046050208876416491892141201070822230131, 79547284021186879599064590255903862162736176763577694086452574483959105669722214770109007085871325696665049873073536, 315809215683715856623773540595819635047566056859602300667262187593705408991392910317051208881558444097467184884431157, 1253834979285426570031233194424112121276155771396268926629394300954835640295429800316432432553283540199303378978033661]\r\nn, m = map(int, input().split())\r\nprint(vals[n] % m)", "src_uid": "cf57508de47d80bc983861f70bb5f3d6"}
{"source_code": "import sys\n\n__author__ = 'ratmir'\n\nfrom collections import deque\n\nalphabet = \"abcdefghijklmnopqrstuvwxyz\"\n\ndef solve(n, a, graph):\n    return 1\n\ndef execute():\n    [n] = [int(x1) for x1 in sys.stdin.readline().split()]\n    a = sys.stdin.readline()\n    result = \"YES\\n\"\n    lastBad = \"Z\"\n    mx = \"Z\"\n    for i in range(0, n):\n        if a[i]>=mx:\n            mx = a[i]\n            result += \"0\"\n            continue\n        if a[i]>=lastBad:\n            result += \"1\"\n            lastBad = a[i]\n            continue\n        result = \"NO\"\n        break\n    print result\n\nexecute()\n\n", "src_uid": "9bd31827cda83eacfcf5e46cdeaabe2b"}
{"source_code": "kk=lambda:map(int,input().split())\nll=lambda:list(kk())\nn,s=int(input()),ll()\nprint(\"Bob\" if s.count(min(s)) > n/2 else \"Alice\")", "src_uid": "4b9cf82967aa8441e9af3db3101161e9"}
{"source_code": "import sys\nimport random, math\nfrom decimal import Decimal\nfrom collections import defaultdict\n#n=int(raw_input())\n\n#mem = dict()\n\nn,v = [int(_) for _ in raw_input().split()]\n#arr = [int(_) for _ in raw_input().split()]\nif v >= n-1:\n    print(n-1)\nelse:\n    s = v\n    for i in range(2,n-v+1):\n        s += i\n    print(s)", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"}
{"source_code": "a, b = [int(x) for x in input().split()]\n\ndec = 1\nwhile True:\n    if dec%2 == 1:\n        a -= dec\n    else:\n        b -= dec\n    if a < 0:\n        print('Vladik')\n        break\n    elif b < 0:\n        print('Valera')\n        break\n    dec += 1\n", "src_uid": "87e37a82be7e39e433060fd8cdb03270"}
{"source_code": "s, x1, x2 = map(int, input().split())\nt1, t2 = map(int, input().split())\np, d = map(int, input().split())\nv1 = t2 * abs(x1 - x2)\nv2 = 0\nif d == 1 and p <= x1:\n    v2 = x1 - p\nelif d == 1:\n    v2 = s - p + s - x1\n    d=-d\nelif p >= x1:\n    v2 = p - x1\nelse:\n    v2 = p + x1\n    d=-d\np, x1 = x1, x2\nif d == 1 and p <= x1:\n    v2 += x1 - p\nelif d == 1:\n    v2 += s - p + s - x1\nelif p >= x1:\n    v2 += p - x1\nelse:\n    v2 += p + x1\nv2 *= t1\nprint(min(v1, v2))", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821"}
{"source_code": "W=[]\nB=[]\narr=[]\nfor i in xrange(8):\n    a=raw_input().strip()\n    arr.append(a)\n    for j in xrange(8):\n        if a[j]=='W':\n            W.append((i+1,j+1))\n        elif a[j]=='B':\n            B.append((i+1,j+1))\nW.sort(key=lambda x:x[0])\nB.sort(key=lambda x:8-x[0])\nd=1000\nfor i in W:\n    c=0\n    if 'B' not in map(lambda x:x[i[1]-1],arr)[:i[0]]:\n        break\na=i[0]-1\nd=1000\nfor i in B:\n    c=0\n    if 'W' not in map(lambda x:x[i[1]-1],arr)[i[0]-1:]:\n        break\nd=8-i[0]\nif a<=d:\n    print 'A'\nelse:\n    print 'B'\n", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd"}
{"source_code": "S=input()\nl=[S[0],S[1],S[3],S[4]]\nk=0\nwhile l[0]+l[1]!=l[3]+l[2] :\n    t=int(l[3])\n    t=t+1\n    if t==10 :\n        l[3]='0'\n        r=int(l[2])\n        r=r+1\n        if r==6 :\n            l[2]='0'\n            r=int(l[1])\n            if l[0]=='2' and l[1]=='3' :\n                print(k+1)\n                exit()\n            r=r+1\n            if r==10 :\n                l[1]='0'\n                l[0]=str(int(l[0])+1)\n            else :\n                l[1]=str(int(l[1])+1)\n        else :\n            l[2]=str(r)            \n        \n    else :\n        l[3]=str(t)\n    k=k+1\nprint(k)\n", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5"}
{"source_code": "number = input()\n\ndef rounding(number):\n    m = number % 10\n    n = 0\n    if m > 5:\n        n = (10 - m) + number    \n    else:\n        n = number - m\n    return n\n\nprint rounding(number)\n", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9"}
{"source_code": "from fractions import *\nn,L=int(input()),0\nwhile (n%2==0):n,L=n//2,L+1\nif (n==1):print('%d/1'%L)\nelse:\n    s,t=1,1\n    for i in range(n):\n        t,s=t*2%n,s*2\n        if (t==1):\n            m=i+1\n            break\n    r,t,i,ans=s,s*n,L,0\n    while (r>1):\n        i,t=i+1,t//2\n        if (r-t>0):\n            r,ans=r-t,ans+i*t\n    print(Fraction(ans+m,s-1))\n\n", "src_uid": "5491b4a27991153a61ac4a2618b2cd0e"}
{"source_code": "n, k, x = map(int, raw_input().split())\nbolas = map(int, raw_input().split())\nquant = 0\n\nfor i in range(n):\n    linha = bolas[:]\n    linha.insert(i, x)\n    \n    while len(linha) > 2:\n        l = len(linha)\n    \n        for j in range(2, len(linha)):\n            if linha[j-2] == linha[j-1] == linha[j]:\n                p = j + 1\n       \n                while p < len(linha):\n                    if linha[j] != linha[p]:\n                        break\n       \n                    p += 1\n                linha = linha[:j-2] + linha[p:]\n                break\n       \n        if len(linha) == l:\n            break\n            \n    quant = max(quant, n - len(linha))\n\nprint quant", "src_uid": "d73d9610e3800817a3109314b1e6f88c"}
{"source_code": "n = int(input())\ns = input()\nx=0\nfor i in s:\n    if i=='-':\n        x = max(x-1,0)\n    else:\n        x+=1\nprint(x)", "src_uid": "a593016e4992f695be7c7cd3c920d1ed"}
{"source_code": "n,m=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nk=[0 for i in range(10)]\nc=0\nmi=float('inf')\nfor i in a:\n    k[i]=1\nfor i in b:\n    if k[i]==1 and i<mi:\n        mi=i\n        c=1\nif c==0:\n    n1=min(a)\n    n2=min(b)\n    if n1<n2:\n        mi=n1*10+n2\n    else:\n        mi=n2*10+n1\nprint(mi)\n\"\"\"m1=max(a)\nm2=max(b)\nc=0\nmi=float('inf')\nif m1>m2:\n    arr=[0 for i in range(m1+1)]\n    for i in a:\n        arr[i]=1\n    for i in b:\n        if arr[i]==1 and arr[i]<mi:\n            mi=arr[i]\n            c=1\n    if c==0:\n        n1=min(a)\n        n2=min(b)\n        if n1<n2:\n            mi=n1*10+n2\n        else:\n            mi=n2*10+n1\nelse:\n    arr=[0 for i in range(m2+1)]\n    for i in b:\n        arr[i]=1\n    for i in a:\n        if arr[i]==1 and arr[i]<mi:\n            mi=arr[i]\n            c=1\n    if c==0:\n        n1=min(a)\n        n2=min(b)\n        if n1<n2:\n            mi=n1*10+n2\n        else:\n            mi=n2*10+n1\nprint(mi)\n\"\"\"\n", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee"}
{"source_code": "a = int(input())\nif(a == 1):\n    print(1, 1)\n    print(1)\n    exit()\nn = (a-1)*2\nprint(n, 2)\nprint(1, 2)\n", "src_uid": "5c000b4c82a8ecef764f53fda8cee541"}
{"source_code": "n,m,x,y,a,b = map(int,raw_input().split())\nv = 1<<60\nfor c in [(1,m),(n,1),(n,m),(1,1)]:\n  dx=abs(x - c[0])\n  dy=abs(y - c[1])\n  if 0==dx+dy:\n    v=0\n  elif dx%a==0 and dy%b==0 and (dx/a)%2==(dy/b)%2:\n    v=min(v,max(dx/a,dy/b))\nif v and (max(n-x,x-1)<a or max(m-y,y-1)<b):\n  v=1<<60\nprint (\"Poor Inna and pony!\",v)[v<(1<<55)]", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862"}
{"source_code": "n,h,m=map(int,input().split())\nans=[-1]*(n+1)\nwhile m:\n    l,r,x=map(int,input().split())\n    for i in range(l,r+1):\n        if ans[i]==-1:\n            ans[i]=x**2\n        else:\n            if ans[i]>x**2:\n                ans[i]=x**2\n            \n    m-=1\nfor i in range(1,n+1):\n    if ans[i]==-1:\n        ans[i]=h**2\n        \nprint(sum(ans[1:]))            \n        \n    ", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad"}
{"source_code": "\n\nf0 = \"What are you doing at the end of the world? Are you busy? Will you save us?\"\nfirst_part = 'What are you doing while sending \"'\nbetween1 = '\"? Are you busy? Will you send \"'\nf_lengths = [0 for i in range(64)]\nf_lengths[0] = len(f0)\nfor i in range(1, 64):\n    f_lengths[i] = 2*f_lengths[i-1] + 68\n\n# print(f_lengths)\n\ndef determine_n(n, k):\n    while n > 64 and k >= 34:\n        k -= 34\n        n -= 1\n    return n\n\n# k is 0 based here\ndef index_find(n, k) -> str:\n    # print(\"index_find(n, k): \", n , k)\n    if n == 0:\n        if k >= len(f0):\n            return \".\"\n        return f0[k]\n\n    if k < 34:\n        return first_part[k]\n\n    first_end = 34 + f_lengths[n-1]\n    if 34 <= k < first_end:\n        return index_find(n-1, k-34)\n    if first_end <= k < first_end + 32:\n        return between1[k-first_end]\n    second_end = f_lengths[n-1] + first_end + 32\n    if first_end + 32 <= k < second_end:\n        return index_find(n-1, k-first_end-32)\n    else:\n        if k - second_end > 1:\n            return '.'\n        return '\"?'[k - second_end]\n\nn = int(input())\nqueries = [map(int, input().split()) for i in range(n)]\nr = []\n\nfor n, k in queries:\n    # print(k, n)\n\n    if n > 64:\n        new_n = determine_n(n, k-1)\n        prefix = (n - new_n) * 34\n        r.append(index_find(new_n, k-1-prefix))\n    else:\n        r.append(index_find(n, k-1))\n\nprint(\"\".join(r))\n\n\n\n\n", "src_uid": "da09a893a33f2bf8fd00e321e16ab149"}
{"source_code": "r,g,b=map(int,input().split())\nm=min(r,g,b)\nans=m\nans3=0\nans4=0\nif(r>=1 and g>=1 and b>=1):\n\tans3=1+(r-1)//3+(g-1)//3+(b-1)//3+min((r-1)%3,(g-1)%3,(b-1)%3)\nif(r>=2 and g>=2 and b>=2):\n\tans4=2+(r-2)//3+(g-2)//3+(b-2)//3+min((r-2)%3,(g-2)%3,(b-2)%3)\nans2=r//3+g//3+b//3+min(r%3,g%3,b%3)\nr-=m\ng-=m\nb-=m\nans+=r//3\nans+=b//3\nans+=g//3\nprint(max(ans,ans2,ans3,ans4))", "src_uid": "acddc9b0db312b363910a84bd4f14d8e"}
{"source_code": "n=input()\ns = list(map(int,input().split()))\n\nsum = sum(s)\nd = int(sum/(len(s)/2))\nf = []\nfor i in range(0, len(s)):\n    if i not in f:\n        f.append(i)\n        for j in range(i+1,len(s)):\n            if d-s[i]==s[j] and j not in f:\n                f.append(j)\n                print(str(i+1)+\" \"+str(j+1))\n                break;\n\n", "src_uid": "6e5011801ceff9d76e33e0908b695132"}
{"source_code": "primenumberlist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 123]\none, two = map(int, raw_input().split())\nif primenumberlist[(primenumberlist.index(one)+1)] == two:\n    print 'YES'\nelse:\n    print 'NO'\n", "src_uid": "9d52ff51d747bb59aa463b6358258865"}
{"source_code": "#     Clever Fat Rat\nimport time\nfrom datetime import datetime\n\nimport itertools\n\nmax_oats = 10**6 + 1\n\ndef is_goal(state):\n    (a, ws) = state\n    if(len(ws) == 1 and ws[0][0] <= a[0]):\n        return True\n        \ndef child(state):\n    (a, ws) = state \n    scales = ws[0]\n    if(len(ws) == 1):\n        return [];\n    \n    b = [[0]*(len(scales)-1)]\n    for (jdx, scale) in enumerate(scales):\n        if a[jdx] >= scale:\n            if(jdx == 0):\n                b = map(lambda x: [x[0]+a[jdx]] + x[1:], b)\n#                b[0] += a[jdx]\n            elif (jdx == len(scales)-1):\n                b = map(lambda x:  x[:-1]+[x[-1]+a[-1]], b)\n#                b[-1] += a[-1]\n            else:\n                b = map(lambda x:  [x[:jdx]+[x[jdx]+a[jdx]]+x[jdx+1:], x[:jdx-1]+[x[jdx-1]+a[jdx]]+x[jdx:]], b)\n                b = reduce (lambda a,b: a+b, b)\n#                b[jdx-1] += a[jdx]/2.\n#                b[jdx] += a[jdx]/2.\n#    print b\n    return map(lambda x: (x, ws[1:]), b)\n    \ndef is_possible_reach_goal(state):\n#    print state\n    (a, ws) = state\n    return (sum(a) >= ws[-1][0])\n\ndef is_broken(i, a, ws):\n    return 1 if (a[i] >= ws[0][i]) else 0\n\ndef fall(idx, a, ws):\n    return a[idx]  * is_broken(idx, a, ws)\n\ndef check_break(a, ws):\n    break_list = [[0,0]]\n    for idx in range(0, len(a)-1):\n        break_list += [[0,0]]\n        if(fall(idx, a, ws) + fall(idx+1, a, ws) >= ws[1][idx]):\n            break_list[idx][1] = is_broken(idx, a, ws)\n            break_list[idx+1][0] = is_broken(idx+1, a, ws)\n#    print break_list\n    return break_list\n\ndef next_step(a, break_list):\n    next_step = [[]]\n    for idx, b in enumerate(break_list):\n        if b == [0,0]:\n            next_step = map((lambda x: x+[0]), next_step)\n        elif b == [0,1]:\n            next_step = map((lambda x: x+[a[idx]]), next_step)\n        elif b == [1,0]:\n            next_step = map((lambda x: x[:-1] + [x[-1]+a[idx]] +[0]), next_step)\n        else:   # [1,1]\n            next_step = map((lambda x: [x[:-1] + [x[-1]+a[idx]] +[0], x+[a[idx]]]), next_step)\n            next_step = reduce (lambda a,b: a+b, next_step)\n    return map(lambda x: x[:-1],next_step)\n                \ndef weight(p):\n    return p[0]\n\ndef right(p):\n    return p[1][1]\n\ndef left(p):\n    return p[1][0]\n\ndef plus(l, r):\n    return (weight(l)+weight(r), (left(l), right(r)))\n\n# 01 can cover 02?\ndef cover(o1, o2):\n    return left(o1) >= left(o2) and right(o1) <= right(o2) and weight(o1) >= weight(o2)\n\ndef add_only_unique(oats, oat):\n    for idx, o_n in enumerate(oats):\n        if oat == o_n or cover(o_n, oat):\n            return oats\n        if cover(oat, o_n):\n            oats[idx] = oat\n            return oats\n    oats.append(oat)\n    return oats\n\ndef unique(oats):\n    new_oats = []\n    for o in oats:\n#        if o not in new_oats:\n        should_add = True\n        for idx, o_n in enumerate(new_oats):\n            if o == o_n or cover(o_n, o):\n                should_add = False \n                break\n            if cover(o, o_n):\n                should_add = False \n                new_oats[idx] = o\n        if(should_add):\n            new_oats.append(o)\n    return new_oats\n            \ndef max_drop(oats):\n    max_drop = 0\n    for oat in oats:\n        max_drop = weight(oat) if  weight(oat) > max_drop else max_drop\n    return max_drop\n\ndef print_now(message):\n    print message,\n    print datetime.now().strftime(u'%H:%M:%S:%f')\n\ndef possible_oats(a, ws):\n#    print_now(\"> possible_oats\") \n    oats_list = []\n    for idx in range(0, len(a)-1):  # same as len(ws)\n#        print_now(\"> possible_oats loop\") \n        oats = []\n        left_oat = a[idx]\n        right_only_oat = [e for e in a[idx+1] if not e in left_oat ]\n        left_only_oat = [e for e in a[idx] if not e in a[idx+1] ]\n#        print len(right_only_oat)\n#        print len(left_only_oat)\n        \n#        max_r = max_drop(a[idx+1])\n        if ((len(a[idx+1]) == 0) or\n            (idx != len(a)-2 and max_drop(a[idx+1])+max_drop(a[idx+2]) >= ws[0][idx+1])):\n            for l in left_oat:\n                if weight(l) >= ws[0][idx]:\n                    oats.append(l)\n                        \n        if ((len(a[idx]) == 0) or\n            (idx != 0 and len(oats_list[-1]) != 0)):\n            for r in right_only_oat:\n                if weight(r) >= ws[0][idx]:\n                    oats = add_only_unique(oats, r)\n#        print_now(\"> possible_oats - pre for\") \n#        print len(a),\n#        print len(oats),\n#        print len(left_only_oat),\n#        print len(right_only_oat)\n        \n        for c in itertools.product(left_only_oat,right_only_oat):\n            (l,r) = c\n            if weight(r)+weight(l) >= ws[0][idx] and right(l) < left(r):\n                oats = add_only_unique(oats, plus(l,r))\n#        print_now(\"> possible_oats - unique\") \n        if len(oats) > 30:\n            oats.sort(key=weight, reverse=True) \n            oats = oats[:30]\n#            print oats\n        oats_list.append(oats)   \n#    print_now(\"> possible_oats - return\") \n    return oats_list\n                \ndef is_break_all(limit, oats_list):\n    for idx, oat in enumerate(oats_list):\n        for o in oat:\n            if weight(o) >= limit[idx]:\n                return True\n    return False\n    \ndef fatrat(state):\n#    print state\n\n    (a, ws) = state\n#    if len(a) == 11:\n#        return \"Fat Rat\"\n\n    \n    ws = map(lambda x: [max_oats]+x+[max_oats], ws)\n\n    goal_oats = []\n    pre_goal_oat = [0, 0]\n    for idx in range(len(ws)-1,-1,-1):\n        goal_oat = []\n        for jdx in range(1,len(ws[idx])-1):\n            goal_oat.append(max(ws[idx][jdx],min(pre_goal_oat[jdx-1], pre_goal_oat[jdx])))\n        goal_oats.append(goal_oat)\n        pre_goal_oat = [max_oats] + goal_oat + [max_oats]\n    goal_oats.reverse()\n    ws = map(lambda x: x[1:-1], ws)\n#    print goal_oats\n\n    oats_list = []\n    for idx in range(0, len(a)):\n        if a[idx] >= ws[0][idx]:\n            oats_list.append([(a[idx], (idx,idx))])\n        else:\n            oats_list.append([])\n    \n    repeat = 0\n    while(True):\n        ws = ws[1:]\n        if not len(ws):\n            if len(oats_list[0]):\n                return \"Cerealguy\"\n            else:\n                return \"Fat Rat\"\n            \n#        print goal_oats[0]\n#        print oats_list\n        if is_break_all(goal_oats[0], oats_list):\n            return \"Cerealguy\"\n            \n        oats_list = possible_oats(oats_list, ws)\n        goal_oats = goal_oats[1:]\n\n#        repeat +=1\n#        if repeat > 20:\n#            print oats_list\n#            return \"Finish\"\n                           \n                             \n        \n    \n    \n    \ndef fatrat3(state):\n    print state\n    (a, ws) = state\n    \n    a_list = [a]\n    while(True):\n        print len(ws)\n        print len(a_list)\n        print\n#        print a_list[0:20]\n#        if len(a_list) > 100:\n#            break\n        if len(ws) == 1:\n            for e_a_list in a_list:\n                if e_a_list[0] >= ws[0][0]:\n                    return \"Cerealguy\"\n            return \"Fat Rat\"\n        \n        a_list = map((lambda a: next_step(a, check_break(a, ws))), a_list)\n        a_list = reduce (lambda a,b: a+b, a_list)\n        \n        new_list = []\n        for e_a_list in a_list:\n            if e_a_list not in new_list:\n                if sum(e_a_list) >= ws[-1][0]:\n                    new_list.append(e_a_list)\n                \n        a_list = new_list\n        ws = ws[1:]\n        \n        if not len(a_list):\n            return \"Fat Rat\"\n            \ndef create_goals(ws):\n    ws = map(lambda x: [max_oats]+x+[max_oats], ws)\n\n    goal_oats = []\n    pre_goal_oat = [0, 0]\n    for idx in range(len(ws)-1,-1,-1):\n        goal_oat = []\n        for jdx in range(1,len(ws[idx])-1):\n            goal_oat.append(max(ws[idx][jdx],min(pre_goal_oat[jdx-1], pre_goal_oat[jdx])))\n        goal_oats.append(goal_oat)\n        pre_goal_oat = [max_oats] + goal_oat + [max_oats]\n    goal_oats.reverse()\n#    ws = map(lambda x: x[1:-1], ws)\n    return goal_oats\n#    print goal_oats\n\ndef compare_goal(goals, oats):\n    for idx in range(0,len(goals)):\n        if(goals[idx] <= oats[idx]):\n            return True\n    return False\n    \ndef fatrat2(state):\n    stack = [state]\n    visited = []\n    start = datetime.now()\n    \n    goals = create_goals(state[1])\n    while(stack):\n\n        state = stack.pop(0)\n        visited += [state[0]]\n        \n#        if(is_goal(state)):\n        if(compare_goal(goals[len(goals)-len(state[0])], state[0])):\n            return \"Cerealguy\"\n        \n        children = child(state)\n        for c in children:\n            if(c[0] not in visited and c not in stack):\n                if is_possible_reach_goal(c):\n                    stack += [c]\n   \n    return \"Fat Rat\" \n\nDebug = False\nif(not Debug):\n    n = int(raw_input())\n    a_s = raw_input().split()\n    a = []\n    for a_s_e in a_s:\n        a += [int(a_s_e)]\n    \n    ws = []\n    for i in range(0, int(n)):\n        r = raw_input().split()\n#        rs = [max_oats]\n        rs = []\n        for e_rs in r:\n            rs += [int(e_rs)]\n#        rs += max_oats\n        ws += [rs]\n#    print fatrat(n, a, ws)\n    print fatrat(((a, ws)))\nelse:\n    worst_w = [[50]]\n    for idx in range(1,50):\n        worst_w.append([1]*(idx+1))\n    worst_w.reverse()\n#    print fatrat(([1]*50, worst_w))   #F\n \n    print fatrat(([1,1,1,1,1,1,1],[[1,9,1,9,1,9,9],[1,9,1,9,1,9],[1,1,9,1,9],[1,9,9,1],[1,9,1],[1,1],[3]])) #C\n    print fatrat(([1, 1, 2, 2, 1, 1], [[1, 1, 2, 2, 1, 1],[2, 4, 2, 4, 2],[2,2,2,2],[4,10,4],[4,4],[8]]))   #F\n    print fatrat(([1, 1, 1], [[1, 1, 1],[1, 1],[4]]))   #F\n    print fatrat(([2, 2, 2], [[2, 2, 2],[3, 2],[4]]))   #C\n    print fatrat(([1], [[1]]))   #C\n    print fatrat(([2, 2], [[1, 2],[4]]))   #C\n    print fatrat(([2, 2], [[1, 2],[5]]))   #F\n    print fatrat(([798097, 886901, 292688, 792934], [[987579, 447910, 689959, 311317],[41624, 797440, 706737],[921438, 988902],[506461]]))   #C\n    a =( [232602, 103849, 827367, 389557, 651438, 216320, 824798, 525699, 23338, 518302, 719391, 553814, 331160, 617684, 289434, 312706, 618709, 259095, 21269, 998945, 461731]\n    + [896427, 149781, 499724, 6493, 239022, 333269, 513014, 671173, 502655, 287667, 863972, 857850, 644809, 824618, 402957, 617413, 295280, 915642, 78666, 498130, 693142])\n    #0\n    w =[0]*42\n    w[0]=( [442788, 122361, 376827, 1098, 885713, 765876, 370112, 54990, 458771, 438057, 765395, 895171, 272899, 408086, 963600, 961459, 805320, 99236, 780298, 932795, 511481]\n     +[195036, 855105, 514771, 711514, 234442, 539631, 644411, 463491, 112557, 217985, 629316, 185503, 888215, 728675, 175993, 704847, 245992, 469172, 819496, 608942, 786465])\n#    W1=( [604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685])\n    #+ [614993, 744625, 774390, 147357, 217239, 448556, 977399, 440373, 650208, 929115, 60946, 434417, 20...\n#    w1 = ([806141, 604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685]\n#[765593, 147600, 186480, 720359, 234733, 364648, 8995, 884055, 565526, 558538, 319000, 388...\n    w[1] = ([765593, 147600, 186480, 720359, 234733, 364648, 8995, 884055, 565526, 558538, 319000, 388544, 274611, 872762, 244955, 981313, 877169, 440983, 367837, 367936]\n    + [806141, 604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685])\n\n    w[2]=( [103072, 936498, 847907, 650645, 566772, 244240, 76487, 607887, 833591, 261100, 535448, 472137, 921365, 782021, 699092, 571729, 884498, 898861, 570530, 8136, 278423, 614993, 744625, 774390, 147357, 217239, 448556, 977399, 440373, 650208]\n    + [929115, 60946, 434417, 203564, 373657, 245610, 284531, 327005, 518126, 979469])\n    \n    w[3]= ([415376, 150228, 72136, 403305, 640672, 652152, 214427, 737311, 208036, 769173, 693842, 421040, 183828, 647456, 73520, 674069, 253765, 239577, 992072, 247531, 5556, 775497, 835157, 659594, 777970, 399659, 357111, 242550, 765227, 396071]\n    + [337931, 684782, 912212, 59641, 407013, 892962, 529009, 168624, 729261])\n    \n    w[4]=([579778, 603392, 7187, 711763, 980786, 891205, 187614, 347504, 871321, 16499, 165802, 430266, 767897, 943796, 838570, 489956, 126553, 519253, 411089, 156752, 209661, 853585, 233490, 370034, 817847, 507577, 999103, 22978, 790519, 52028]\n    +[728211, 18397, 740606, 627417, 513419, 851193, 795920, 975646])\n    \n    w[5]=([364270, 878531, 313352, 760219, 57774, 979287, 495749, 821992, 400807, 118875, 624706, 11664, 398468, 399161, 480516, 516761, 361857, 676791, 254124, 676721, 383882, 346228, 368172, 543223, 372419, 89729, 450007, 183906, 578337, 782425]\n    +[239888, 133714, 848309, 211198, 276004, 422001, 342793])\n    \n    w[6]=(\n    [669810, 70004, 223430, 545763, 495696, 659851, 458070, 320934, 70213, 2510, 670903, 398360, 955053, 229649, 10354, 681727, 93774, 345990, 810132, 724068, 178347, 919760, 900818, 664569, 731142, 68854, 562838, 348118, 412534, 711858]\n    +[217450, 390687, 476960, 552361, 384448, 269506])\n    \n    w[7]= ([686869, 943862, 411867, 608029, 563528, 355743, 650398, 806908, 984874, 442601, 965871, 224704, 395748, 333576, 560520, 44827, 222000, 210286, 63258, 240375, 156949, 653188, 279453, 955766, 955005, 475318, 105273, 315988, 259444, 554025]\n    +[169162, 673513, 337343, 217480, 802836])\n    \n    w[8]=([524812, 846231, 854588, 192451, 593937, 58689, 804666, 287964, 117042, 310411, 495542, 750086, 835403, 781732, 699317, 778671, 275391, 903769, 90240, 110812, 176953, 320104, 584756, 341201, 623117, 929603, 391734, 803929, 440316, 17762]\n    +[349381, 33395, 717334, 254917])\n    \n    w[9]=([852392, 358681, 885946, 1989, 714822, 291374, 275129, 793814, 698964, 135683, 654809, 411164, 475752, 828614, 173173, 465830, 881709, 429319, 942530, 613387, 394352, 150504, 429484, 432671, 47638, 720929, 915486, 178642, 362160, 697774]\n    +[582177, 990694, 63463])\n    \n    w[10]=([775829, 967068, 76364, 48338, 231255, 628921, 800537, 721127, 331827, 449577, 987306, 400525, 752721, 529533, 823633, 106767, 436626, 205685, 547258, 868397, 522545, 178774, 793439, 158477, 194198, 537780, 714979, 545295, 240759, 136464]\n    +[342543, 669949])\n    \n    w[11]=([395243, 682010, 637544, 537377, 568397, 939159, 617065, 455601, 589065, 520285, 39074, 59942, 70214, 98748, 330093, 61675, 314160, 4343, 820744, 569072, 156641, 964848, 619284, 939421, 248299, 973729, 72425, 651620, 337476, 228294]\n    +[446228])\n    w[12] = [733423, 120527, 880793, 28654, 481273, 936515, 808693, 646362, 891193, 526586, 645212, 971930, 320632, 217240, 232724, 519503, 911492, 119638, 207340, 834315, 393853, 595370, 182300, 154260, 490060, 679573, 469578, 931192, 795252, 794504]\n    w[13] = [992937, 935048, 234752, 790452, 581692, 261170, 364764, 938989, 760569, 392383, 343936, 652090, 226824, 806565, 456839, 687163, 528042, 195594, 873694, 66359, 594999, 965206, 59095, 345665, 918463, 273203, 35037, 899079, 842258]\n    w[14]=[529636, 112898, 877687, 806044, 60735, 189749, 160846, 725032, 512840, 609679, 511, 993861, 575660, 560076, 254140, 79046, 330071, 166742, 370339, 396898, 344306, 315773, 868616, 819708, 981564, 686084, 252763, 573950]\n    w[15]=[928772, 710357, 920822, 465694, 16512, 799572, 971974, 162499, 157133, 294992, 241747, 325056, 798852, 528918, 760749, 755326, 867061, 621152, 114485, 917241, 244803, 775595, 547781, 427681, 292956, 933798, 764221]\n    w[16]=[406560, 631571, 780422, 992747, 904507, 669339, 120822, 171670, 667218, 377506, 620268, 569831, 150401, 606727, 427415, 149877, 467369, 558074, 701300, 941164, 905161, 621807, 105600, 109208, 227333, 278783]\n    w[17]=[844232, 600660, 956873, 275867, 943068, 825161, 895623, 436781, 797538, 72677, 546140, 158861, 475846, 930202, 119313, 70300, 894159, 977232, 72700, 731713, 575949, 152873, 737159, 830782, 65071]\n    w[18]=[237486, 549512, 427886, 634225, 662555, 1168, 679325, 898994, 922755, 757632, 664644, 637155, 527137, 507924, 980575, 388955, 210941, 125059, 22317, 78152, 38200, 739583, 554051, 627713]\n    w[19]=[479028, 892887, 24398, 430711, 392354, 172860, 835107, 14025, 685353, 867105, 40260, 188534, 475120, 432763, 315378, 632428, 97800, 678056, 637610, 606208, 221689, 756844, 982589]\n    w[20]=[496311, 545320, 850902, 922063, 260033, 790113, 586049, 527404, 349253, 221895, 828342, 465666, 633175, 282389, 519791, 331199, 728647, 567952, 2615, 162184, 714835, 235531]\n    w[21]=[186477, 32274, 159996, 18134, 428838, 997537, 290934, 736388, 681330, 933659, 158840, 221272, 113015, 443400, 254260, 225996, 711610, 257129, 157857, 458557, 87869]\n    w[22]=[601009, 200243, 37750, 427458, 155172, 379052, 313175, 219565, 161355, 632012, 541089, 436743, 196945, 780260, 562593, 479, 977598, 261257, 459383, 188043]\n    w[23]=[397, 325219, 455107, 109068, 14827, 610661, 275371, 915727, 386383, 761111, 574986, 371344, 639217, 380366, 910264, 143066, 89832, 111998, 900082]\n    w[24]=[54569, 953315, 43302, 252838, 348912, 495555, 823785, 117598, 949, 228308, 699837, 421190, 302746, 843111, 189564, 330203, 411320, 382797]\n    w[25]=[285720, 115251, 233252, 448050, 374380, 478883, 644371, 21203, 879789, 5904, 534234, 486941, 73215, 738517, 214733, 114020, 753636]\n    w[26]=[674062, 749897, 823484, 423759, 75711, 302798, 112824, 642967, 508005, 530628, 866877, 950023, 649878, 761438, 473985, 474066]\n    w[27]=[764631, 542492, 923110, 543523, 771130, 380714, 749869, 488147, 391730, 58854, 709912, 984884, 156149, 574527, 865313]\n    w[28]=[285322, 581452, 403449, 558544, 440730, 791866, 963533, 797693, 557146, 188615, 805740, 869602, 58823, 974248]\n    w[29]=[541348, 328412, 178390, 827724, 8540, 807870, 861826, 343941, 825017, 837266, 74180, 685457, 162275]\n    w[30]=[746285, 307489, 744197, 268642, 453102, 888605, 112405, 860770, 926547, 858125, 451650, 520853]\n    w[31]=[750071, 509514, 692960, 418551, 57836, 476673, 681027, 636141, 1841, 259624, 120838]\n    w[32]=[260295, 857040, 643083, 533047, 108837, 61847, 849988, 290, 137973, 706032]\n    w[33]=[54921, 310584, 531482, 398431, 714080, 21340, 948456, 37528, 652013]\n    w[34]=[913611, 142924, 415931, 772076, 351461, 16265, 459565, 738745]\n    w[35]=[890204, 456669, 440916, 421772, 768120, 173826, 433774]\n    w[36]=[358083, 892804, 903312, 679503, 168920, 921433]\n    w[37]=[317439, 489653, 710322, 371652, 567242]\n    w[38]=[75849, 947287, 694039, 831792]\n    w[39]=[759605, 295166, 463625]\n    w[40]=[539029, 755676]\n    w[41]=[954370]\n\n#    print fatrat((a, w))   #C\n\n\n", "src_uid": "0a77937c01ac69490f8b478eae77de1d"}
{"source_code": "n,d,s=map(int,raw_input().split())\nc0=[]\nc1=[]\nv=0\nfor i in range(n):\n\tc,f,l=map(int,raw_input().split())\n\tv+=c\n\tif l>=d:\n\t\tc0+=[f]\n\t\tif c:\n\t\t\tc1+=[f]\nc0.sort()\ny=z=0\nif c1!=[]:\n\tu=min(c1)\n\tc0.remove(u)\n\tv+=1\n\tfor i in c0:\n\t\tif u<=s:\n\t\t\tz,y=max([z,y],[min(v,n),-u])\n\t\telse:\n\t\t\tbreak\n\t\tu+=i\n\t\tv+=1\n\tif u<=s:\n\t\tz,y=max([z,y],[min(v,n),-u])\nv=u=0\nfor i in c0:\n\tif u+i>s:\n\t\tbreak\n\tu+=i\n\tv+=1\nz,y=max([z,y],[v,-u])\nprint z,-y\n", "src_uid": "e69f42403f3b0357e06a14523025b34a"}
{"source_code": "a=int(input())\nif a==1:\n    print(\"-1\")\nelse:\n    if a%2==0:\n        print(a,2)\n    else:\n        print(a-1,2)", "src_uid": "883f67177474d23d7a320d9dbfa70dd3"}
{"source_code": "n, k, m, d = map(int, input().split())\nans = int(0)\nfor i in range(1, d+1):\n    num = n // (k*(i-1)+1)\n    if num > m:\n        num = m\n    ans = max(ans, num * i)\nprint(ans)", "src_uid": "ac2e795cd44061db8da13e3947ba791b"}
{"source_code": "N, M, K = map(int, raw_input().split())\npiles = []\ndraw = { 'G': 0, 'R': 0 }\nfor row in xrange(N):\n    line = raw_input().strip()\n\n    if ('R' in line) and ('G' in line):\n        piles.append(abs(line.index('R') - line.index('G')) - 1)\n\n    elif '-' in line:\n        for letter in ['R', 'G']:\n            if letter in line:\n                draw[letter] = 1\n\ndef SecondWins():\n    for bit in xrange(7):\n        sum = 0\n        for index in xrange(len(piles)):\n            sum += (piles[index] >> bit) & 1\n\n        if 0 != sum % (K + 1):\n            return False\n\n    return True\n\n# G == First\n# R == Second\n\nif not piles:\n    if draw['G'] == 0:\n        print \"Second\"\n    elif draw['R'] == 0:\n        print \"First\"\n    else:\n        print \"Draw\"\n    exit(0)\n\nif SecondWins():\n    draw['R'] = 2\nelse:\n    draw['G'] = 2\n\nif 1 in draw.values():\n    print \"Draw\"\nelse:\n    print \"First\" if draw['G'] == 2 else \"Second\"\n", "src_uid": "69062f7c9b834e925ab23ebc2da96b52"}
{"source_code": "import typing\n\n\ndef rit(*args) -> typing.Iterator:\n    \"\"\"Read input and yield split cast values.\n    \"\"\"\n    func, funcs = int, (int, float, str)\n    sep = \" \"\n    for a in args:\n        if a in funcs:\n            func = a\n        elif isinstance(a, str):\n            sep = a\n    return map(func, input().strip().split(sep))\n\n\ndef pit(itr: typing.Iterable, sep:str=\" \") -> None:\n    print(sep.join(map(str, itr)))\n\ndef rank(n):\n    eps = 0.5 if n in (0, 1, 2, 4) or n % 4 == 2 else 0\n    if n == 3:\n        return 1\n    return (n // 4 - 1) + (n - 1) // 2 + eps\n\n\ndef main():\n    n = int(input())\n\n    B = 1\n    T = int(1e10)\n    k = T // 2\n\n    while True:\n        if rank(k) == n:\n            print(k)\n            break\n        elif n > rank(k):\n            B = k\n            if T - k == 1:\n                k = T\n            else:\n                k += (T - k) // 2\n        else:\n            T = k\n            if k - B == 1:\n                k = B\n            else:\n                k -= (k - B) // 2\n\nmain()\n", "src_uid": "d0a8604b78ba19ab769fd1ec90a72e4e"}
{"source_code": "n=int(raw_input())\nMOD=10**9+7\nprint (pow(3,n,4*MOD)+(-1)**n*3)//4\n", "src_uid": "77627cc366a22e38da412c3231ac91a8"}
{"source_code": "T = 1\nfor test_no in range(T):\n\tx0, y0, ax, ay, bx, by = map(int, input().split())\n\txs, ys, t = map(int, input().split())\n\n\tLIMIT = 2 ** 62 - 1\n\tx, y = [x0], [y0]\n\twhile ((LIMIT - bx) / ax >= x[-1] and (LIMIT - by) / ay >= y[-1]):\n\t\tx.append(ax * x[-1] + bx)\n\t\ty.append(ay * y[-1] + by)\n\t\n\tn = len(x)\n\tans = 0\n\tfor i in range(n):\n\t\tfor j in range(i, n):\n\t\t\tlength = x[j] - x[i] + y[j] - y[i]\n\t\t\tdist2Left = abs(xs - x[i]) + abs(ys - y[i])\n\t\t\tdist2Right = abs(xs - x[j]) + abs(ys - y[j])\n\t\t\tif (length <= t - dist2Left or length <= t - dist2Right): ans = max(ans, j-i+1)\n\t\n\tprint(ans)", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28"}
{"source_code": "s = raw_input()\nleft,right = s.split('=')\nc = len(right)\nfirst,second = left.split('+')\na = len(first)\nb = len(second)\ndif = a+b-c\nif dif == 0:\n\tprint s\nelif abs(dif)==2:\n\tif dif>0:\n\t\tif a>1:\n\t\t\tright+='|'\n\t\t\tfirst = first[0:a-1]\n\t\telse:\n\t\t\tright+='|'\n\t\t\tsecond = second[0:b-1]\n\telse:\n\t\tfirst+='|'\n\t\tright=right[0:c-1]\n\tprint first+'+'+second+'='+right\nelse:\n\tprint 'Impossible'\n", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6"}
{"source_code": "n,k = map(int, raw_input().split())\nfrom itertools import permutations\nimport sys\nnumbers = [raw_input() for x in xrange(n)]\nmin_val = sys.maxint \nfor perm in permutations(range(k)):\n\tpermed_numbers = []\n\tfor num in numbers: \n\t\ts = \"\"\n\t\tfor x in perm:\n\t\t\ts += num[x]\n\t\tpermed_numbers.append(int(s))\n\ttemp = max(permed_numbers) - min(permed_numbers)\n\tif temp < min_val:\n\t\tmin_val = temp\n\n\nprint(min_val)\n\t\n", "src_uid": "08f85cd4ffbd135f0b630235209273a4"}
{"source_code": "def gcd(a,b): return a if (b==0) else gcd(b,a%b)\nn,m,x,y,a,b=map(int,raw_input().split())\nd=gcd(a,b)\nk=min(n*d/a,m*d/b)\np,q=a/d*k,b/d*k\nc,d=min(n-p,max(x-(p+1)/2,0)),min(m-q,max(y-(q+1)/2,0))\nprint c,d,c+p,d+q", "src_uid": "8f1211b995f35462ae83b2be27f54585"}
{"source_code": "from math import sqrt\nn, m = map(int, input().split())\ns = 0\nf =  int(sqrt(m))\nif f < n:\n    for i in range(f):\n        if ((i + 1) ** 2) == m:\n            s += 1\n        elif m % (i + 1) == 0 and (m // (i + 1)) <= n:\n            s += 2\nelse:\n    for i in range(n):\n        if  m % (i + 1) == 0 and (m // (i + 1)) <= n:\n            s += 1\nprint(s)", "src_uid": "c4b139eadca94201596f1305b2f76496"}
{"source_code": "n,M=map(int,input().split())\nt=[int(z)for z in input().split()]\nfor i in range(n):\n    r=0\n    a=sorted(t[:i])\n    b=t[i]\n    while sum(a)+b>M:\n        a.pop(-1)\n        r+=1\n    print(r,end=' ')\n    ", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346"}
{"source_code": "n,a,b,c,d = map(int, raw_input().split())\ndif = max([abs(b-c), abs(a-d), abs(c+d-a-b), abs(b+d-a-c)])\nprint (0 if dif >= n else n*(n-dif))\n", "src_uid": "b732869015baf3dee5094c51a309e32c"}
{"source_code": "from fractions import gcd\nn = int(input())\ncrush = list(map(int,input().split()))\nwas = [0] * n\nans = 1\nfor i in range(n):\n    if was[i]:\n        continue\n    num = i\n    j = 0\n    while not was[num]:\n        was[num] = 1\n        num = crush[num] - 1\n        j += 1\n    if i != num:\n        ans = -1\n        break\n    else:\n        if j % 2 == 0:\n            j //= 2\n        ans = ans * j // gcd(ans,j)\nprint(ans)\n", "src_uid": "149221131a978298ac56b58438df46c9"}
{"source_code": "m,b = map(lambda x:int(x),raw_input().strip().split())\nsign1 = -m*b/abs(m*b)\nmaxs = 0\nfor y in range(b+1):\n\tif m*b>=m*b-m*y>=0:\n\t\tx = m*b-m*y\n\t\ts = (x+y)*(x+1)*(y+1)/2\n\t\tmaxs = max(s,maxs)\n\telse:\n\t\tcontinue\nprint maxs", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2"}
{"source_code": "import math\n\na,b,x,y = map(int,input().split(\" \"))\ngcdd = math.gcd(x,y)\nx/=gcdd\ny/=gcdd\n\naux = int(a/x)\naux2 = int(b/y)\nmenor = min(aux,aux2)\n\nprint(int(x*menor),\"\",int(y*menor))", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a"}
{"source_code": "def write(arg):\n\tprint (str(arg))\n\texit()\na,r,w=map(int,raw_input().split())\nb=w%a\nif -a<r<a and w%a>0:\n\tk=w/a\n\tk=k+min(1,b)\n\tif k==1:\n\t\tif -a/2.0<r<a/2.0:\n\t\t\twrite(1)\n\t\telse:\n\t\t\twrite(-1)\n\telse:\n\t\tif (k%2==0):\n\t\t\tif (-a/2.0<r<a/2.0):\n\t\t\t\twrite( (k/2-1)*2+k/2+1)\n\t\t\telse:\n\t\t\t\twrite(-1)\n\t\telif k%2==1:\n\t\t\tb=k/2\n\t\t\tif -a<r<0:\n\t\t\t\twrite( (b*2+(k-b)-1))\n\t\t\telif 0<r<a:\n\t\t\t\twrite( (b*2+(k-b)))\n\t\t\telse: \n\t\t\t\twrite(-1)\nelse:\n\twrite(-1)", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02"}
{"source_code": "'''\n#generate all beautiful numbers < maxn\nk = 0\nn = 1\nmaxv = 100000\nwhile n<=maxv:\n\tn -= 2**k\n\tn += 2**(2*k+1)\n\tn += 2**(2*k+2)\n\tk+=1\n\tprint(n)\n'''\nbn = [130816,32640,8128,2016,496,120,28,6,1]\nbn.reverse()\nans = 1\nn = int(input())\nfor num in bn:\n\tif n%num==0:\n\t\tans=num\nprint(ans)", "src_uid": "339246a1be81aefe19290de0d1aead84"}
{"source_code": "\ndef judge():\n    for i in range(4):\n        if a[i][3] == 0:\n            continue\n        left = (i + 3) % 4\n        right = (i + 1) % 4\n        mid = (i + 2) % 4\n        if a[i][0] or a[i][1] or a[i][2] or a[left][2] or a[mid][1] or a[right][0]:\n            return True\n    return False\n\n\nwhile True:\n    try:\n        a = []\n        for i in range(4):\n            a.append(list(map(int, input().split(' '))))\n        print(\"YES\" if judge() else \"NO\")\n    except:\n        break\n", "src_uid": "44fdf71d56bef949ec83f00d17c29127"}
{"source_code": "mod = 10**9 + 7\nways = [[0 for j in range(502)] for i in range(502)]\n\nways[0][0] = 1\nfor i in range(1, 501):\n    ways[i][0] = 1\n    for j in range(1, 501):\n        ways[i][j] = (ways[i - 1][j - 1] + ways[i - 1][j]) % mod\n\nn, k = map(int, raw_input().split())\nif n == 1:\n    print 1\n    exit(0)\n\ndef get(r, c):\n    total = (r * n) + (c * n)\n    common = r * c\n    return pow(k - 1, total - common, mod) * pow(k, (n - r) * (n - c), mod)\n\nres = 0\n\nfor r in range(n + 1):\n    for c in range(n + 1):\n        x = 1\n        if (r + c) % 2 == 1:\n            x *= -1\n\n        res += x * get(r, c) * (ways[n][r] * ways[n][c]) % mod\n        res %= mod\n\nprint res", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93"}
{"source_code": "import math\nfrom collections import defaultdict, Counter, deque\n\nINF = float('inf')\n\ndef gcd(a, b):\n\twhile b:\n\t\ta, b = b, a%b\n\treturn a\n\ndef isPrime(n):\n\tif (n <= 1): \n\t\treturn False\n\ti = 2\n\twhile i ** 2 <= n:\n\t\tif n % i == 0:\n\t\t\treturn False\n\t\ti += 1\n\treturn True\n\ndef primeFactor(n):\n\tif n % 2 == 0:\n\t\treturn 2\n\ti = 3\n\twhile (i ** 2) <= n:\n\t\tif n % i == 0:\n\t\t\treturn i \n\t\ti += 1\n\treturn n\n\ndef vars():\n\treturn map(int, input().split())\n\ndef array():\n\treturn list(map(int, input().split()))\n\ndef can(m, s):\n\tif 0 <= s <= m * 9:\n\t\treturn True\n\treturn False\n\ndef main():\n\tm, n = vars()\n\n\tnum = int('9' * m)\n\n\tans = (num // n) * n\n\tif n <= num and len(str(ans)) == m:\n\t\tprint(ans)\n\telse:\n\t\tprint(-1)\n\t\n\n\n\n\nif __name__ == \"__main__\":\n\t# t = int(input())\n\tt = 1\n\tfor _ in range(t):\n\t\tmain()\n\n\n\n\n\n\n\n", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"}
{"source_code": "def  foo():\n    str1 = raw_input().lower()\n    str2 = raw_input().lower()\n    \n    if str1 == str2:\n        print 0\n    elif str1 > str2:\n        print 1\n    else:\n        print -1\n         \nfoo()", "src_uid": "ffeae332696a901813677bd1033cf01e"}
{"source_code": "a,b,s = [abs(int(x)) for x in input().strip().split()]\nd = s-(a+b)\nif d>=0 and d%2==0:\n    print(\"Yes\")\nelse:\n    print(\"No\")", "src_uid": "9a955ce0775018ff4e5825700c13ed36"}
{"source_code": "def solve(l,r):\n    if(l>r): return 0\n    if(l == r): return 1\n    if(dp[l][r] != -1): return dp[l][r]\n    ans = solve(l+1,r)+1\n    for i in range(l+1,r+1):\n        if(s[i]==s[l]): ans = min(ans , solve(l+1,i-1)+solve(i,r))\n    dp[l][r] = ans\n    return ans\n\ndef F():\n    n = int(input())\n    global s;\n    s = input()\n\n    global dp;\n    dp = [[-1]*n for _ in range(n)]\n    ans = solve(0,n-1)\n\n    print(ans)\nF()", "src_uid": "516a89f4d1ae867fc1151becd92471e6"}
{"source_code": "if __name__ == \"__main__\":\n    nmk = input().split(' ')\n    for i in range(len(nmk)):\n        nmk[i] = int(nmk[i])\n        \n    m = nmk[1]\n    k = nmk[2]\n    prices = input().split(' ')\n    \n    for i in range(len(prices)):\n        prices[i] = int(prices[i])\n\n    avail_houses = list()\n    for i in range(len(prices)):\n        if prices[i] != 0 and k >= prices[i]:\n            avail_houses.append(i+1)\n    min_dist = len(prices)\n    for h in avail_houses:\n        if h - m < min_dist:\n            min_dist = abs(h - m)\n    print(min_dist*10)\n\n\n    \n  \n        \n            \n        \n            \n    \n            \n    \n    \n    \n    \n    \n", "src_uid": "57860e9a5342a29257ce506063d37624"}
{"source_code": "# ===============================================================================================\n# importing some useful libraries.\nfrom __future__ import division, print_function\nfrom fractions import Fraction\nimport sys\nimport os\nfrom io import BytesIO, IOBase\nfrom itertools import *\nimport bisect\nfrom heapq import *\nfrom math import ceil, floor\nfrom copy import *\nfrom collections import deque, defaultdict\nfrom collections import Counter as counter  # Counter(list)  return a dict with {key: count}\nfrom itertools import combinations  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]\nfrom itertools import permutations as permutate\nfrom bisect import bisect_left as bl\nfrom operator import *\n# If the element is already present in the list,\n\n# the left most position where element has to be inserted is returned.\nfrom bisect import bisect_right as br\nfrom bisect import bisect\n\n# If the element is already present in the list,\n# the right most position where element has to be inserted is returned\n\n# ==============================================================================================\n# fast I/O region\n\nBUFSIZE = 8192\nfrom sys import stderr\n\n\nclass FastIO(IOBase):\n    newlines = 0\n\n    def __init__(self, file):\n        self._fd = file.fileno()\n        self.buffer = BytesIO()\n        self.writable = \"x\" in file.mode or \"r\" not in file.mode\n        self.write = self.buffer.write if self.writable else None\n\n    def read(self):\n        while True:\n            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n            if not b:\n                break\n            ptr = self.buffer.tell()\n            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n        self.newlines = 0\n        return self.buffer.read()\n\n    def readline(self):\n        while self.newlines == 0:\n            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n            self.newlines = b.count(b\"\\n\") + (not b)\n            ptr = self.buffer.tell()\n            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n        self.newlines -= 1\n        return self.buffer.readline()\n\n    def flush(self):\n        if self.writable:\n            os.write(self._fd, self.buffer.getvalue())\n            self.buffer.truncate(0), self.buffer.seek(0)\n\n\nclass IOWrapper(IOBase):\n    def __init__(self, file):\n        self.buffer = FastIO(file)\n        self.flush = self.buffer.flush\n        self.writable = self.buffer.writable\n        self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\n        self.read = lambda: self.buffer.read().decode(\"ascii\")\n        self.readline = lambda: self.buffer.readline().decode(\"ascii\")\n\n\ndef print(*args, **kwargs):\n    \"\"\"Prints the values to a stream, or to sys.stdout by default.\"\"\"\n    sep, file = kwargs.pop(\"sep\", \" \"), kwargs.pop(\"file\", sys.stdout)\n    at_start = True\n    for x in args:\n        if not at_start:\n            file.write(sep)\n        file.write(str(x))\n        at_start = False\n    file.write(kwargs.pop(\"end\", \"\\n\"))\n    if kwargs.pop(\"flush\", False):\n        file.flush()\n\n\nif sys.version_info[0] < 3:\n    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)\nelse:\n    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\n\n# inp = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\n\n# ===============================================================================================\n### START ITERATE RECURSION ###\nfrom types import GeneratorType\n\n\ndef iterative(f, stack=[]):\n    def wrapped_func(*args, **kwargs):\n        if stack: return f(*args, **kwargs)\n        to = f(*args, **kwargs)\n        while True:\n            if type(to) is GeneratorType:\n                stack.append(to)\n                to = next(to)\n                continue\n            stack.pop()\n            if not stack: break\n            to = stack[-1].send(to)\n        return to\n\n    return wrapped_func\n\n\n#### END ITERATE RECURSION ####\n\n# ===============================================================================================\n# some shortcuts\n\nmod = 1000000007\n\n\ndef inp(): return sys.stdin.readline().rstrip(\"\\r\\n\")  # for fast input\n\n\ndef out(var): sys.stdout.write(str(var))  # for fast output, always take string\n\n\ndef lis(): return list(map(int, inp().split()))\n\n\ndef stringlis(): return list(map(str, inp().split()))\n\n\ndef sep(): return map(int, inp().split())\n\n\ndef strsep(): return map(str, inp().split())\n\n\ndef fsep(): return map(float, inp().split())\n\n\ndef nextline(): out(\"\\n\")  # as stdout.write always print sring.\n\n\ndef testcase(t):\n    for p in range(t):\n        solve()\n\n\ndef pow(x, y, p):\n    res = 1  # Initialize result\n    x = x % p  # Update x if it is more , than or equal to p\n    if (x == 0):\n        return 0\n    while (y > 0):\n        if ((y & 1) == 1):  # If y is odd, multiply, x with result\n            res = (res * x) % p\n\n        y = y >> 1  # y = y/2\n        x = (x * x) % p\n    return res\n\n\nfrom functools import reduce\n\n\ndef factors(n):\n    return set(reduce(list.__add__,\n                      ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))\n\n\ndef gcd(a, b):\n    if a == b: return a\n    while b > 0: a, b = b, a % b\n    return a\n\n\n# discrete binary search\n# minimise:\n# def search():\n#     l = 0\n#     r = 10 ** 15\n#\n#     for i in range(200):\n#         if isvalid(l):\n#             return l\n#         if l == r:\n#             return l\n#         m = (l + r) // 2\n#         if isvalid(m) and not isvalid(m - 1):\n#             return m\n#         if isvalid(m):\n#             r = m + 1\n#         else:\n#             l = m\n#     return m\n\n# maximise:\n# def search():\n#     l = 0\n#     r = 10 ** 15\n#\n#     for i in range(200):\n#         # print(l,r)\n#         if isvalid(r):\n#             return r\n#         if l == r:\n#             return l\n#         m = (l + r) // 2\n#         if isvalid(m) and not isvalid(m + 1):\n#             return m\n#         if isvalid(m):\n#             l = m\n#         else:\n#             r = m - 1\n#     return m\n\n\n##to find factorial and ncr\n# N=100000\n# mod = 10**9 +7\n# fac = [1, 1]\n# finv = [1, 1]\n# inv = [0, 1]\n#\n# for i in range(2, N + 1):\n#     fac.append((fac[-1] * i) % mod)\n#     inv.append(mod - (inv[mod % i] * (mod // i) % mod))\n#     finv.append(finv[-1] * inv[-1] % mod)\n#\n#\n# def comb(n, r):\n#     if n < r:\n#         return 0\n#     else:\n#         return fac[n] * (finv[r] * finv[n - r] % mod) % mod\n\n\n##############Find sum of product of subsets of size k in a array\n# ar=[0,1,2,3]\n# k=3\n# n=len(ar)-1\n# dp=[0]*(n+1)\n# dp[0]=1\n# for pos in range(1,n+1):\n#     dp[pos]=0\n#     l=max(1,k+pos-n-1)\n#     for j in range(min(pos,k),l-1,-1):\n#         dp[j]=dp[j]+ar[pos]*dp[j-1]\n# print(dp[k])\n\ndef prefix_sum(ar):  # [1,2,3,4]->[1,3,6,10]\n    return list(accumulate(ar))\n\n\ndef suffix_sum(ar):  # [1,2,3,4]->[10,9,7,4]\n    return list(accumulate(ar[::-1]))[::-1]\n\n\ndef N():\n    return int(inp())\n\n\n# =========================================================================================\nfrom collections import defaultdict\n\n\n\ndef numberOfSetBits(i):\n    i = i - ((i >> 1) & 0x55555555)\n    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)\n    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24\n\n\n\ndef solve():\n    n=N()\n    ar=lis()\n    for i in range(len(ar)):\n        m=ar[i]\n        v = m // 2\n        u = v // 2\n        w = (v - u)\n        print((u * w + u + w + 1) % mod)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nsolve()\n#testcase(int(inp()))\n", "src_uid": "24f4bd10ae714f957920afd47ac0c558"}
{"source_code": "n,a,b,c=map(int,raw_input().split())\nw=0\nfor i in range(0,min(n,c*2)+1,2):\n  j=n-i\n  w+=max(0,min(a/2,j)+min(b,j)-j+1)\nprint w\n", "src_uid": "474e527d41040446a18186596e8bdd83"}
{"source_code": "s = input().strip()\n\nstart = (0, 0)\nMap = [ (0, 0) ]\ngraph = {}\nnum = {}\nnum[start] = 0\nx = 0\ny = 0\n\nfor t in s:\n    if t == 'U':\n        y += 1   \n    elif t == 'D':\n        y -= 1\n    elif t=='L':\n        x -= 1\n    else:\n        x += 1\n    Map.append( (x, y) )\n\ngoal = Map[-1]\n#print(Map)\n\nfor m in Map:\n    graph[m] = set()\n    for n in Map:\n        if m != n and ( ( abs( m[0] - n[0] ) == 1 and m[1] == n[1] ) \\\n                        or  ( abs( m[1] - n[1] ) == 1 and m[0] == n[0] ) ):\n            graph[m].add(n)\n\n#print(graph)\n\nvisited, queue = set(), [start]\nwhile queue:\n    vertex = queue.pop(0)\n    if vertex == goal:\n        break\n    if vertex not in visited:\n        visited.add(vertex)\n        for item in graph[vertex] - visited:\n            num[item] = num[vertex] + 1\n            queue.append(item)\n\nif len(s) > num[goal]:\n    print('BUG')\nelse:\n    print('OK')\n", "src_uid": "bb7805cc9d1cc907b64371b209c564b3"}
{"source_code": "s = input()\nd, k = 0, 1\nfor i in range(len(s)-1):\n    if s[i] == s[i+1]:\n        k += 1\n    else:\n        k = 1\n    if d < k:\n        d = k\nprint(\"YES\" if d > 6 else \"NO\")\n", "src_uid": "ed9a763362abc6ed40356731f1036b38"}
{"source_code": "q = int(input())\nstroke = input()\n\nd1 = {}\n\nfor i in range(q-1):\n\n    u = i + 2\n    key = stroke[i:u:]\n    if not key in d1:\n        d1[key] = 0\n    d1[key] += 1\nmax_value = max(d1.values())\nprint([key for key, value in d1.items() if value == max_value][0])\n#print(list(d1.items())[0][0])", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"}
{"source_code": "n,k=[int(f)for f in input().split()]\na=(0 if n==k or k==0 else 1)\nb=(k*2 if n//3>=k else n-k)\nprint(a,(b if k!=0 else 0))\n", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86"}
{"source_code": "import math\ns = raw_input()\nst = int(s)\nl = [(-2,0),(-1,-2), (1,-2),(2,0),(1,2),(-1,2)]\n\nif (st <= 6):\n\tif (st == 0):\n\t\tprint \"0 0\"\n\t\texit()\n\n\tif (st == 1):\n\t\tprint \"1 2\"\n\t\texit()\n\tif (st == 2):\n\t\tprint \"-1 2\"\n\t\texit()\n\tif (st == 3):\n\t\tprint \"-2 0\"\n\t\texit()\n\tif (st == 4):\n\t\tprint \"-1 -2\"\n\t\texit()\n\tif (st == 5):\n\t\tprint \"1 -2\"\n\t\texit()\n\tif (st == 6):\n\t\tprint \"2 0\"\n\t\texit()\n\na = 6\nyy = 1 \nd = 6\nn = int((-3 + math.sqrt(9+12*st))/6)\nyy = n \nru = (n*(3*n+3)) \n#print ru\nwhile (ru > st):\n\tn -= 1 \n\tyy -= 1\n\tru = n*(3*n+3) \n\ndiff = st - ru \n#print diff , ru \n\n\n\n\n\n \nx = 2*(yy) \ny = 0\n\nif (diff == 0):\n\tprint x , y \n\texit()\nelif (diff == 1):\t\n\tx += 1\n\ty += 2 \n\tprint x, y\n\texit()\nelif (diff <= yy+1):\n\tx += 1 \n\ty += 2\n\tdiff -= 1\n\tx -= 1*diff\n\ty += 2*diff\n\tprint x , y\n\texit()\n\nelif (diff > yy+1):\n\tx += 1\n\ty += 2 \n\tx -= yy \n\ty += 2*yy \n\tdiff -= yy+1\n\tli = 0  \n\n\twhile (diff > yy+1 ) : \n\t\tif (li < len(l)):\n\t\t\tx += l[li][0]*(yy+1)\n\t\t\ty += l[li][1]*(yy+1)\n\t\t\tdiff -= (yy+1)\n\t\t\tli += 1\n\t\telse:\n\t\t\tbreak \n\n\tx += l[li][0]*diff\n\ty += l[li][1]*diff \n\tprint x,y \n\texit()", "src_uid": "a4b6a570f5e63462b68447713924b465"}
{"source_code": "n,m= map(int,raw_input().split())\nfor i in range(n):\n    l = map(int,raw_input().split())\nfor i in range(m):\n    l = map(int,raw_input().split())\n\nif n==m:\n    print \"Yes\"\nelse:\n    print \"No\"\n", "src_uid": "65f81f621c228c09915adcb05256c634"}
{"source_code": "\"\"\"\n\n\"\"\"\n\nx0, y0 = map(int, raw_input().split())\nn = input()\n\n\ndef cdist(x, y):\n    return x * x + y * y\n\n\nd0 = [0] * n\nd1 = [[0] * n for i in xrange(n)]\nd2 = []\n\n\n\nfor i in xrange(n):\n    x, y = map(int, raw_input().split())\n    d0[i] = cdist(x - x0, y - y0)\n\n    for j in xrange(i):\n        d1[i][j] = cdist(x - d2[j][0], y - d2[j][1])\n        d1[j][i] = d1[i][j]\n\n    d2.append((x,y))\n\n\np = [2 ** i for i in xrange(n)]\na = [None] * (1 << n)\na[0] = 0\np2 = [0] * (1 << n)\n\nfor i in xrange(1 << n):\n    if a[i] is not None:\n        for j in xrange(n):\n            if i & p[j] == 0:\n\n                t = i + p[j]\n\n                if not a[t] or a[t] > a[i] + d0[j] * 2:\n                    a[t] = a[i] + d0[j] * 2\n                    p2[t] = i\n\n                for k in xrange(j + 1, n):\n                    if t & p[k] == 0:\n                        t2 = t + p[k]\n                        c = a[i] + d0[j] + d1[j][k] + d0[k]\n                        if not a[t2] or a[t2] > c:\n                            a[t2] = c\n                            p2[t2] = i\n                break\n\nz = (1 << n) - 1\nprint a[z]\n\nr = [0]\nwhile z > 0:\n    t = z - p2[z]\n    while t:\n        x = -t & t\n        t -= x\n        i = 0\n\n        while x > 0:\n            i += 1\n            x /= 2\n        r.append(i)\n\n    z = p2[z]\n    r.append(0)\n\nprint ' '. join(map(str,r))\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n                \n                \n", "src_uid": "2ecbac20dc5f4060bc873553946281bc"}
{"source_code": "x = map(int, raw_input().split())\nx = sorted(x)\nprint x[2] - x[0]", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"}
{"source_code": "n = int(raw_input())\na = [1,3,15,133,2025,37851,1030367,36362925,1606008513]\nif n % 2:\n    ans = a[n/2]\n    for i in xrange(n):\n        ans *= (i + 1)\n        ans %= 1000000007\n    print ans\nelse:\n    print 0\n", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69"}
{"source_code": "count = map(int,raw_input()).pop()\nrow = raw_input()\nrow += raw_input() \nrow += raw_input()\nrow += raw_input()\n\nbeats = list(row)\nflag = True\nif (beats.count('.') != 16):\n    m_beat = map(int,max(beats)).pop()\n    for x in range(len(beats)):\n        try:\n            beats[x] = int(beats[x])\n        except ValueError:\n            beats[x] = beats[x]\n    for x in range(m_beat+1):\n        if (beats.count(x) > count*2):\n            flag = False\n            break\nif flag:\n    print \"YES\"\nelse:\n    print \"NO\"", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16"}
{"source_code": "# ------------------- fast io --------------------\nimport os\nimport sys\nfrom io import BytesIO, IOBase\n\nBUFSIZE = 8192\n\n\nclass FastIO(IOBase):\n    newlines = 0\n\n    def __init__(self, file):\n        self._fd = file.fileno()\n        self.buffer = BytesIO()\n        self.writable = \"x\" in file.mode or \"r\" not in file.mode\n        self.write = self.buffer.write if self.writable else None\n\n    def read(self):\n        while True:\n            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n            if not b:\n                break\n            ptr = self.buffer.tell()\n            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n        self.newlines = 0\n        return self.buffer.read()\n\n    def readline(self):\n        while self.newlines == 0:\n            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n            self.newlines = b.count(b\"\\n\") + (not b)\n            ptr = self.buffer.tell()\n            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n        self.newlines -= 1\n        return self.buffer.readline()\n\n    def flush(self):\n        if self.writable:\n            os.write(self._fd, self.buffer.getvalue())\n            self.buffer.truncate(0), self.buffer.seek(0)\n\n\nclass IOWrapper(IOBase):\n    def __init__(self, file):\n        self.buffer = FastIO(file)\n        self.flush = self.buffer.flush\n        self.writable = self.buffer.writable\n        self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\n        self.read = lambda: self.buffer.read().decode(\"ascii\")\n        self.readline = lambda: self.buffer.readline().decode(\"ascii\")\n\n\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\n\n# ------------------- fast io --------------------\nfrom math import gcd, ceil\n\ndef prod(a, mod=10**9+7):\n    ans = 1\n    for each in a:\n        ans = (ans * each) % mod\n    return ans\n\ndef lcm(a, b): return a * b // gcd(a, b)\n\ndef binary(x, length=16):\n    y = bin(x)[2:]\n    return y if len(y) >= length else \"0\" * (length - len(y)) + y\n\nfor _ in range(int(input()) if not True else 1):\n    #n = int(input())\n    #n, k = map(int, input().split())\n    n,m,x1,y1,x2,y2 = map(int, input().split())\n    #c, d = map(int, input().split())\n    #a = list(map(int, input().split()))\n    #b = list(map(int, input().split()))\n    #s = input()\n    x, y = abs(x2-x1), abs(y2-y1)\n    x, y = min(x,y), max(x,y)\n    if [x,y] in [[0,0], [0,1], [0,2], [0,3], [0,4],\n                 [1,1], [1,2], [1,3], [1,4],\n                 [2,2], [2,3], [2,4],\n                 [3,3]]:\n        print(\"First\")\n    else:\n        print(\"Second\")", "src_uid": "41f6f90b7307d2383495441114fa8ea2"}
{"source_code": "# Author: S Mahesh Raju\n# Username: maheshraju2020\n# Date: 15/07/2020\n\nfrom sys import stdin,stdout\nfrom math import gcd, ceil, sqrt\nfrom collections import Counter\nfrom bisect import bisect_left, bisect_right\nii1 = lambda: int(stdin.readline().strip())\nis1 = lambda: stdin.readline().strip()\niia = lambda: list(map(int, stdin.readline().strip().split()))\nisa = lambda: stdin.readline().strip().split()\nmod = 1000000007\n\nn = ii1()\ns = \"abcdefghijklmnopqrstuvwxyz\"\nres = \"\"\nfor i in s:\n    cost = 0\n    while n - cost >= 0:\n        n -= cost\n        cost += 1\n        res += i\n    if not n:\n        break\nprint(res)", "src_uid": "b991c064562704b6106a6ff2a297e64a"}
{"source_code": "#!/usr/bin/python\nfrom math import *\n\ndef cost(hr, hb, nr, nb) :\n  return hr * nr + hb * nb\n\nif __name__ == '__main__':\n  c, hr, hb, wr, wb = map(int, raw_input().split())\n  sq = int(ceil(sqrt(c)))\n  if wb < sq and (wr >= sq or wb * hr < wr * hb) :\n    wr, wb = wb, wr\n    hr, hb = hb, hr\n\n  ans = 0\n  for i in xrange(sq + 1) :\n    nb = i\n    nr = max(0, c - nb * wb) // wr\n    if (nb * wb <= c) :\n      ans = max(ans, cost(hr, hb, nr, nb))\n\n  print ans", "src_uid": "eb052ca12ca293479992680581452399"}
{"source_code": "def CF579A():\n    return str(bin(int(input()))).count('1')\n\nif __name__ == '__main__':\n    print(CF579A())", "src_uid": "03e4482d53a059134676f431be4c16d2"}
{"source_code": "import sys\ninput = sys.stdin.buffer.readline\n\ndef prog():\n    n = int(input())\n    a = list(map(int,input().split()))\n    \n    freq = [0]*101\n    for i in range(n):\n        freq[a[i]] += 1\n    mx = max(freq)\n    amt = freq.count(mx)\n    \n    if amt >= 2:\n        print(n)\n    else:\n        must_appear = freq.index(mx)\n        ans = 0\n        for j in range(1,101):\n            if j == must_appear:\n                continue\n            \n            first_idx = [10**6]*(n+1)\n            first_idx[0] = -1\n            curr = 0\n            for i in range(n):\n                if a[i] == must_appear:\n                    curr += 1\n                elif a[i] == j:\n                    curr -= 1\n                ans = max(ans, i - first_idx[curr])\n                first_idx[curr] = min(first_idx[curr],i)\n                \n        print(ans)\n\nprog()\n    \n", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed"}
{"source_code": "from math import sqrt\n\nn = int(input())\nif 1 <= n <= 2*pow(10,9):\n    if n%2 == 1:\n        print(\"0\")\n    else:\n        half = n/2\n        if half % 2 == 0:\n            print(int((half/2)-1))\n        else:\n            print(int((half-1)/2))\n\n", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37"}
{"source_code": "n,k=map(int,input().split())\nif n%2==0:\n    if k<=n/2:\n        print(2*k-1)\n    else:\n        k=k-int(n/2)\n        print(2*k)\nelse:\n    if (k<=int(n/2)+1):\n        print(2*k-1)\n    else:\n        k=k-int(n/2)-1\n        print(2*k)", "src_uid": "1f8056884db00ad8294a7cc0be75fe97"}
{"source_code": "import decimal\ndecimal.getcontext().prec = 500\n\na,b,c = input().split()\n\ndiv = decimal.Decimal(a) / decimal.Decimal(b)\ndiv = str(div)\ndec = div.find('.')\nafter_dec = div[dec + 1 :]\nif(len(after_dec) != 500):\n    after_dec = after_dec + '0'\nz= after_dec.find(c)\n\nif(z == -1 or z == 499):\n    print(-1)\nelse:\n    print(z + 1)", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910"}
{"source_code": "def increase_difference(to_start, diff):\n    res = 1\n    for i in to_start:\n        if i + diff < 10:\n            break\n        if i + diff > 9:\n            diff = diff - (9 - i)\n            res += 1\n    return res\n\n\ndef decrease_difference(to_start, diff):\n    res = 1\n    for i in to_start:\n        if i - diff > -1:\n            break\n        if i - diff < 0:\n            diff = diff - i\n            res += 1\n    return res\n\n\nticket = list(raw_input())\n\nticket = [int(x) for x in ticket]\n\nticket1 = sorted([ticket[0], ticket[1], ticket[2]])\nticket2 = sorted([ticket[3], ticket[4], ticket[5]])\n\nsum_first_three = ticket[0] + ticket[1] + ticket[2]\nsum_last_three = ticket[3] + ticket[4] + ticket[5]\n\nif sum_first_three == sum_last_three:\n    print 0\n    exit(0)\n\ntotal_diff = max(sum_first_three, sum_last_three) - min(sum_first_three, sum_last_three)\n\n\n#########################\nto_start = ticket1\nif sum_first_three > sum_last_three:\n    to_start = ticket2\n\nres1 = increase_difference(to_start, total_diff)\n\n#########################\nticket1.reverse()\nticket2.reverse()\n\nto_start = ticket1\nif sum_last_three > sum_first_three:\n    to_start = ticket2\n\nres2 = decrease_difference(to_start, total_diff)\n\n#########################\nto_start = ticket1\nif sum_last_three > sum_first_three:\n    to_start = ticket2\n\nlower_diff = total_diff / 2\nhigher_diff = total_diff - lower_diff\n\nres3 = 0\nif sum_first_three > sum_last_three:\n    ticket2 = sorted(ticket2)\n    res3 = min(decrease_difference(ticket1, lower_diff) +\n               increase_difference(ticket2, higher_diff),\n               decrease_difference(ticket1, higher_diff) +\n               increase_difference(ticket2, lower_diff))\nelse:\n    ticket1 = sorted(ticket1)\n    res3 = min(increase_difference(ticket1, lower_diff) +\n               decrease_difference(ticket2, higher_diff),\n               increase_difference(ticket1, higher_diff) +\n               decrease_difference(ticket2, lower_diff))\n\nprint min(res1, res2, res3)\n", "src_uid": "09601fd1742ffdc9f822950f1d3e8494"}
{"source_code": "R = lambda: map(int,input().split())\nN = list(R())\nT = list(R())\nmixn = min(N[::2])\nmaxn = max(N[::2])\nmiyn = min(N[1::2])\nmayn = max(N[1::2])\nmix = min(T[::2])\nmaxx = max(T[::2])\nmiy = min(T[1::2])\nmay = max(T[1::2])\n\nmid = (miy+may)//2\nfor y in range(miy,may+1):\n    t = abs(y-mid)\n    for x in range(mix+t,maxx-t+1):\n        if mixn <= x <= maxn and miyn <= y <= mayn:\n            print(\"YES\")\n            quit()\nprint(\"NO\")", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a"}
{"source_code": "str=input()\nm=0\nn=len(str)\nfor i in range(n):\n    for j in range(i,n+1) :\n        if str[i:j] in str[i+1:n] and len(str[i:j])>m:\n            m=len(str[i:j])\nprint(m)", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7"}
{"source_code": "#!/usr/bin/env python3 \n\nimport itertools\n\nclass Solitaire:\n  def __init__(self):\n    # Read inputs\n    (self.n,self.m) = map(int,input().split())\n    self.table = [input().split() for i in range(self.n)]\n\n    # Determine the unused cards and the positions of the jokers\n    ranks = [\"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"T\", \"J\", \"Q\", \"K\", \"A\"]\n    suits = [\"C\", \"D\", \"H\", \"S\"]\n    deck = set((\"%s%s\" % card) for card in itertools.product(ranks,suits))\n    self.J1_position = None\n    self.J2_position = None\n\n    for (r,c) in itertools.product(range(self.n), range(self.m)):\n      card = self.table[r][c]\n      deck.discard(card)\n      if (card == \"J1\"):\n        self.J1_position = (r,c)\n      elif (card == \"J2\"):\n        self.J2_position = (r,c)\n\n    self.unused_cards = list(deck)\n    self.unused_cards.sort() # Sort to make things deterministic (easier for testing)\n\n  def is_solved_square(self, r, c):\n    cards = [self.table[r+ro][c+co] for (ro, co) in itertools.product(range(3), range(3))]\n    suits = set(card[1] for card in cards)\n    ranks = set(card[0] for card in cards)\n    solved = (len(suits) == 1) or (len(ranks) == 9)\n    return solved\n\n  def is_solved(self):\n    all_positions = itertools.product(range(self.n-2), range(self.m-2))\n    all_solved_squares = [(r,c) for (r,c) in all_positions if self.is_solved_square(r,c)]\n    for ((r1, c1), (r2,c2)) in itertools.combinations(all_solved_squares, 2):\n      if (abs(r1-r2) >= 3) or (abs(c1-c2) >= 3):\n        return ((r1,c1),(r2,c2))\n    return None\n\n  def replace_card(self, position, card):\n    (r,c) = position\n    self.table[r][c] = card\n\n  def print_solution(self, joker_line, solution):\n    if (solution == None):\n      print(\"No solution.\")\n    else:\n      ((r1,c1),(r2,c2)) = solution\n      print(\"Solution exists.\")\n      print(joker_line)\n      print(\"Put the first square to (%d, %d).\" % (r1+1,c1+1))\n      print(\"Put the second square to (%d, %d).\" % (r2+1,c2+1))\n    exit()\n\n\n  def solve(self):\n    if (self.J1_position != None) and (self.J2_position != None):\n      for (replacement1, replacement2) in itertools.permutations(self.unused_cards,2):\n        self.replace_card(self.J1_position, replacement1)\n        self.replace_card(self.J2_position, replacement2)\n        solution = self.is_solved()\n        if (solution):\n          self.print_solution(\"Replace J1 with %s and J2 with %s.\" % (replacement1, replacement2), solution)\n    elif (self.J1_position != None):\n      for replacement in self.unused_cards:\n        self.replace_card(self.J1_position, replacement)\n        solution = self.is_solved()\n        if (solution):\n          self.print_solution(\"Replace J1 with %s.\" % replacement, solution)\n    elif (self.J2_position != None):\n      for replacement in self.unused_cards:\n        self.replace_card(self.J2_position, replacement)\n        solution = self.is_solved()\n        if (solution):\n          self.print_solution(\"Replace J2 with %s.\" % replacement, solution)\n    else:\n      solution = self.is_solved()\n      self.print_solution(\"There are no jokers.\", solution)\n    self.print_solution(\"\", None)\n\nSolitaire().solve()\n\n", "src_uid": "b3f29d9c27cbfeadb96b6ac9ffd6bc8f"}
{"source_code": "#!/bin/python \n\ndef split_array():\n\ta = int(raw_input().strip())\n\tar = map(int, raw_input().strip().split())\n\n\ttb = [[0 for _ in range(a)] for _ in range(a)]\n\n\tfor i in range(a):\n\t\tfor j in range(i, a):\n\t\t\tif i == j:\n\t\t\t\ttb[i][j] = ar[i]\n\t\t\telse:\n\t\t\t\ttb[i][j] = sum(ar[i:j+1])\n\n\n\tk = 0\n\thead = 0\n\ttail = 0\n\tres = []\n\tpossible = True\n\t\n\t\t\n\twhile tail < a:\n\n\t\tif tail == a -1:\n\t\t\tif tb[head][tail] == 0:\n\t\t\t\tpossible = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tres.append([head+1, tail+1])\n\n\t\t\t\ttail += 1\n\t\telse:\n\t\t\tif tb[head][a-1] != 0:\n\t\t\t\tres.append([head+1, a])\n\n\t\t\t\tbreak\n\t\t\telif tb[head][tail] == 0:\n\t\t\t\ttail += 1\n\t\t\telse:\n\t\t\t\tres.append([head+1, tail+1])\n\t\t\t\thead = tail+1\n\t\t\t\ttail = tail +1\n\n\n\tif not possible:\n\t\tprint \"NO\"\n\telse:\n\t\tprint 'YES'\n\t\tprint len(res)\n\t\tfor each in res:\n\t\t\tprint ' '.join(map(str, each))\n\n\nif __name__ == '__main__':\n\tsplit_array()\n", "src_uid": "3a9258070ff179daf33a4515def9897a"}
{"source_code": "n,d=map(int,input().split());s=input()\nif '0'*d in s:print('-1')\nelse:\n    i,c=0,0\n    while i<n-1:\n        if s[i]=='1':i+=d;c+=1\n        else:i-=1\n    print(c)", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e"}
{"source_code": "I=lambda: map(int,input().split())\nx,y,z,k=I()\na1,a2,a3,q=0,0,0,0\nwhile q<3:\n    q=0\n    if a1+a2+a3==k: break\n    if a1<x-1:\n        a1+=1\n        if a1+a2+a3==k: break\n    else:\n        q+=1\n    if a2<y-1:\n        a2+=1\n        if a1+a2+a3==k: break\n    else:\n        q+=1\n    if a3<z-1:\n        a3+=1\n        if a1+a2+a3==k: break\n    else:\n        q+=1\n        \nprint((a1+1)*(a2+1)*(a3+1))\n", "src_uid": "8787c5d46d7247d93d806264a8957639"}
{"source_code": "\"\"\"\nCode of Ayush Tiwari\nCodeforces: servermonk\nCodechef: ayush572000\n\n\"\"\"\nimport sys\ninput = sys.stdin.buffer.readline\nimport math\ndef solution():\n    l,r,x,y=map(int,input().split())\n    if y%x!=0:\n        print(0)\n        return\n    p=y//x\n    cnt=0\n    for i in range(1,int(p**0.5)+1):\n        if p%i==0:\n            a=i\n            b=p//i\n            if a*x>=l and b*x>=l and a*x<=r and b*x<=r:\n                if math.gcd(a,b)==1:\n                    if a==b:\n                        cnt+=1\n                    else:\n                        cnt+=2\n            \n    print(cnt)\n\n\nsolution()", "src_uid": "d37dde5841116352c9b37538631d0b15"}
{"source_code": "import sys\nrange = xrange\ninput = raw_input\n\ninp = [int(x) for x in sys.stdin.read().split()]; ii = 0\n\nn = inp[ii]; ii += 1\ncoupl = [[] for _ in range(n)]\nfor _ in range(n - 1):\n    u = inp[ii] - 1; ii += 1\n    v = inp[ii] - 1; ii += 1\n    coupl[u].append(v)\n    coupl[v].append(u)\n\nP = [-1] * n\nroot = 0\nbfs = [root]\nP[root] = root\nfor node in bfs:\n    for nei in coupl[node]:\n        del coupl[nei][coupl[nei].index(node)]\n        bfs.append(nei)\n        P[nei] = node\n\nans = list(range(n));cost = 0\nfor node in reversed(bfs):\n    if ans[node] != node:continue\n    cost += 2\n    if node != root:p = P[node]\n    else:p = coupl[node][0]\n    ans[node],ans[p] = ans[p],ans[node]\nprint cost;print ' '.join(str(x + 1) for x in ans)", "src_uid": "98ded03cdd1870500667f0069d6a84b1"}
{"source_code": "MOD = 10 ** 9 + 7\nn, m = input().split(' ')\nn = int(n)\nm = int(m)\nans = pow(2 * (n + 1), m, MOD)\nans = (ans * (n + 1 - m)) % MOD\nans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD\nprint(ans)\n", "src_uid": "4f9711197e699c0fd0c4e9db8323cac7"}
{"source_code": "import bisect\nfrom collections import defaultdict\nfrom collections import deque\nimport math\nimport re\n\ndef ni():\n    return int(raw_input())\n\ndef nis():\n    return map(int, raw_input().split())\n\ndef si():\n    return raw_input()\n\ndef sis():\n    return raw_input().split()\n\nvals = [[0], [1], [2], [3], [2, 2, 3], [5], [3, 5], [7], [2, 2, 2, 7], [2, 3, 3, 7]]\n\nn = ni()\na = filter(lambda x: x > 1, map(int, list(si())))\n\nans = []\nfor x in a:\n    ans.extend(vals[x])\n\nans.sort(reverse=True)\n\nprint ''.join(map(str, ans))", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"}
{"source_code": "P = 10**9 + 7\n\nn, k = map(int, input().split())\n\nprint(n + 1 if k == 1 else (k * pow(2 * k - 1, n, P) - pow(k, n, P)) * pow(k - 1, P - 2, P) % P)", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c"}
{"source_code": "n = int(raw_input())\n\nmin1,max1 = map(int,raw_input().split())\nmin2,max2 = map(int,raw_input().split())\nmin3,max3 = map(int,raw_input().split())\n\nanswer1 = min1\nanswer2 = min2\nanswer3 = min3\n\n\nanswer = answer1 + answer2 + answer3 #at least...\nif (answer < n):\n\tanswer1 = min(max1,n-answer + min1)\nanswer = answer1 + answer2 + answer3 #updating...\n\nif (answer < n):\n\tanswer2 = min(max2,n-answer + min2)\nanswer = answer1 + answer2 + answer3 #updating...\n\nif (answer < n):\n\tanswer3 = min(max3,n-answer + min3)\n\nprint answer1,answer2,answer3\n", "src_uid": "3cd092b6507079518cf206deab21cf97"}
{"source_code": "ans=1000000000000\nmul = []\n\ndef dfs(now, num, opt):\n\tif num == 0:\n\t\tglobal ans \n\t\tans = min(ans, opt)\n\t\treturn\n\tif now == -1:\n\t\treturn\n\ti=-10\n\twhile i * mul[now] <= num:\n\t\ti+=1\n\tdfs(now-1, num-(i-1)*mul[now], opt+abs(i-1)*(now+1))\n\tdfs(now-1, num-i*mul[now], opt+abs(i)*(now+1))\n\ndef main():\n\tmul.append(int(1))\n\tnum = int(input())\n\tfor i in range(1,18,1):\n\t\tmul.append(mul[i-1]*10)\n\tfor i in range(1,18,1):\n\t\tmul[i] += mul[i-1]\n\ti = 1\n\twhile mul[i] <= num:\n\t\ti+=1\n\tn=i\n\tdfs(n, num, 0)\n\tprint(ans)\n\t\t\nmain()", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6"}
{"source_code": "n=int(input())\nl=list(input())\nz=[]\nfor i in range(n):\n    x,y=map(str,input().split(\"->\"))\n    z.append(x)\n    z.append(y)\nz1=list(set(z))\nz2=[]\nfor i in range(len(z1)):\n    z2.append(z.count(z1[i]))\nfor i in range(len(z2)):\n    if z2[i]%2==1:\n        print(\"contest\")\n        break\nelse:\n    print(\"home\")", "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"}
{"source_code": "\n\nn, m, k = map(int, raw_input().split())\n\nif n % 2:\n    if k == 1:\n        if m == 1:\n            print('Marsel')\n        else:\n            print('Timur')\n    else:\n        d = 2\n        ok = False\n        while d * d <= m:\n            if m % d == 0:\n                if m / d >= k:\n                    ok = True\n                break\n            d += 1\n\n        if ok:\n            print('Timur')\n        else:\n            print('Marsel')\nelse:\n    print('Marsel')\n", "src_uid": "4a3767011ddac874efa021fff7c94432"}
{"source_code": "'''input\nabracadabra\n10\n'''\ns = raw_input().strip()\nk = input()\ns += '?'*k\nans = 0\nfor n in range(1,len(s)//2+1):\n\tfor i in range(len(s)-2*n+1):\n\t\tflag = True\n\t\tfor j in range(n):\n\t\t\tif s[i+j] == '?' or s[i+j+n] == '?' or s[i+j] == s[i+j+n]:\n\t\t\t\tcontinue\n\t\t\tflag = False\n\t\t\tbreak\n\t\tif flag :\n\t\t\tans = max(ans,2*n)\nprint ans\n\n\n\n\n", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab"}
{"source_code": "w0, h0 = map(int, raw_input().split())\nu1, d1 = map(int, raw_input().split())\nu2, d2 = map(int, raw_input().split())\nw = w0\nfor i in range(h0, 0, -1):\n    w += i\n    if i == d1:\n        w = max(w - u1, 0)\n    if i == d2:\n        w = max(w - u2, 0)\nprint(w)\n\n", "src_uid": "084a12eb3a708b43b880734f3ee51374"}
{"source_code": "I=lambda:map(int, raw_input().split())\nn=input()\ndef dfs(x):\n    if x>n: return 0\n    return dfs(x*10)+dfs(x*10+1)+1\nprint dfs(1)\n", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb"}
{"source_code": "n=int(input())\ns=input()\ns=s.strip()\na=0\nb=0\n\nl=len(s)\nfor i in range(l):\n    if (s[i]=='U'):\n      a+=1\n    \n    if (s[i]=='D'):\n       a+=-1\n    \n    if (s[i]=='L'):\n       b-=1\n    \n    if (s[i]=='R'):\n        b+=1\n    \nprint(l-abs(b)-abs(a))\n    \n", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a"}
{"source_code": "from math import pi, sin\nn , R , r=map(int,input().split())\nprint(['NO','YES'][ R >= r+r/sin(pi/n) or (n==1 and R>=r)])", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6"}
{"source_code": "str=input()\nnc=str.count('n')\nic=str.count('i')\ntc=str.count('t')\nec=str.count(\"e\")\nprint(max(0,min((nc-1)//2,ec//3,ic,tc)))", "src_uid": "bb433cdb8299afcf46cb2797cbfbf724"}
{"source_code": "import sys\n\ndef read_two_ints(itr):\n    return map(int, next(itr).split(' '))\n\ndef fits(a_board, b_board, a_pictures, b_pictures):\n    return ((a_board >= a_pictures and b_board >= b_pictures) or\n            (a_board >= b_pictures and b_board >= a_pictures))\n\ndef combos(a1, b1, a2, b2):\n    yield (a1+a2, max(b1, b2))\n    yield (b1+b2, max(a1, a2))\n    yield (a1+b2, max(b1, a2))\n    yield (b1+a2, max(a1, b2))\n\na1, b1 = read_two_ints(sys.stdin)\na2, b2 = read_two_ints(sys.stdin)\na3, b3 = read_two_ints(sys.stdin)\n\n# for a_pic, b_pic in combos(a2, b2, a3, b3):\n#     print 'Trying to fit {}, {}'.format(a_pic, b_pic)\n#     if fits(a1, b1, a_pic, b_pic):\n#         print \"It worked!\"\n#         break\n# else:\n#     print \"I'm stuck\"\n\nif any(fits(a1, b1, a_pic, b_pic) for a_pic, b_pic in combos(a2, b2, a3, b3)):\n    print \"YES\"\nelse:\n    print \"NO\"\n", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9"}
{"source_code": "k = int(input()) & 1\n\np = []\ns = range(1, 6)\n\nfor q in map(int, input().split()[::-1]):\n\n    if k:\n        p += [(x, -y) for x, y in p]\n        p = [(x - q, y) for x, y in p]\n        p += [(-x, 0) for x in s[:q]]\n    else:\n        p += [(y, -x) for x, y in p]\n        p = [(x - q, y + q) for x, y in p]\n        p += [(-x, x) for x in s[:q]]\n\n    p = list(set(p))\n    k = 1 - k\n\nprint(len(p))", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9"}
{"source_code": "M = 10 ** 9 + 7\nn, p = map(int, raw_input().split())\ns = [[1, 2, 0]]\ni = j = 0\nx = 3\nwhile x <= p:\n\ta = min(s[i][1] * 3 + 2, p)\n\tb = min(s[j][1] * 3 / 2, p)\n\tc = min(set(range(0, 3)) - set([s[i][2], s[j][2]]))\n\tif a <= b:\n\t\ti += 1\n\tif b <= a:\n\t\tj += 1\n\ty = min(a, b)\n\tif s[-1][2] == c:\n\t\ts[-1][1] = y\n\telse:\n\t\ts += [[x, y, c]]\n\tx = y + 1\nc = [0] * 3\nfor l, r, v in s:\n\tc[v] += (2 * p - l - r) * (r - l + 1) / 2\nu = [1, 0, 0, 0]\nfor _ in range(n):\n\tv = [0] * 4\n\tfor i, x in enumerate(u):\n\t\tfor j, y in enumerate(c):\n\t\t\tv[i ^ j] = (v[i ^ j] + x * y) % M\n\tu = v\nprint sum(u[1 : ]) % M", "src_uid": "c03b6379e9d186874ac3d97c6968fbd0"}
{"source_code": "num = input()\nnum += \"1\"\nanswer = \"YES\"\nif num[0] == \"1\":\n    i = 1\n    n_s = len(num)\n    while i < n_s:\n        s = num[i]\n        if s == \"4\":\n            if num[i+1] == \"1\":\n                i += 2\n            elif num[i+1:i+3] == \"41\":\n                i += 3\n            else:\n                answer = \"NO\"\n                break\n        elif s == \"1\":\n            i += 1\n        else:\n            answer = \"NO\"\n            break\nelse:\n    answer = \"NO\"\nprint(answer)\n     \n", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"}
{"source_code": "x, y = map(int, input().split())\nprint(((x*x)>>2) * ((y*y)>>2))\n", "src_uid": "42454dcf7d073bf12030367eb094eb8c"}
{"source_code": "n,m=map(int,input().split())\ni=0\nif(n>m):\n    i=m\nelse:\n    i=n\nif(i%2==0):\n    print(\"Malvika\")\nelse:\n    print(\"Akshat\")", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"}
{"source_code": "import sys\nrange = xrange\ninput = raw_input\nimport __pypy__\nmulmod = __pypy__.intop.int_mulmod\n\nMOD = 10**9+7\nn, k = [int(x) for x in input().split()]\nk += 2\n\ndef f(n):\n    s = 0\n    for i in range(n):\n        s += pow(i,k-2,MOD)\n        s %= MOD\n    return s\n\nprecalc = [0]\nfor i in range(k - 1):\n    precalc.append((precalc[-1] + pow(i,k-2,MOD)) % MOD)\n\nbig = 10**6 + 10\nmodinv = [1]*big\nfor i in range(2,big):\n    modinv[i] = mulmod(-(MOD//i), modinv[MOD%i], MOD)\n\ninvfac = [1]\nfor i in range(1,big):\n    invfac.append(invfac[-1]*modinv[i]%MOD)\ninvneg_fac = [invfac[i] * (1 - 2 * (i & 1)) for i in range(len(invfac))]\n\ndef g(x):\n    if x < k:\n        return precalc[x]\n    base = 1\n    for j in range(-x, k - x):\n        base = mulmod(base, j, MOD)\n    s = 0\n    for i in range(k):\n        pr = precalc[i]\n        pr = mulmod(pr, pow(i - x, MOD - 2, MOD), MOD)\n        pr = mulmod(pr, mulmod(invneg_fac[i], invfac[k - i - 1], MOD), MOD)\n        s = (s + pr) % MOD\n    return mulmod(s, base, MOD)\n\nprint (g(n + 1) - (k == 2)) % MOD\n", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c"}
{"source_code": "a = raw_input()\n\nx = \" \" * 3\ncnt = -1\nfor i in xrange(1,len(a)):\n  for j in xrange(i+1,len(a)):\n    x = a[:i], a[i:j], a[j:]\n    if not any([b for b in x if (b.startswith('0') and b != '0') or int(b) > 1000000]):\n      cnt = max(cnt, sum(map(int, x)))\n\nprint cnt\n", "src_uid": "bf4e72636bd1998ad3d034ad72e63097"}
{"source_code": "def kset(n, k): \n\tif ((n >> (k - 1)) and 1): \n\t\treturn 1 \n\telse: \n\t    return 0\ndef compute(S, X): \n    A = (S - X)//2\n    a = 0\n    b = 0\n  \n    # Traverse through all bits \n    for i in range(64): \n        Xi = (X & (1 << i)) \n        Ai = (A & (1 << i)) \n        if (Xi == 0 and Ai == 0): \n            # Let us leave bits as 0. \n            pass\n              \n        elif (Xi == 0 and Ai > 0): \n            a = ((1 << i) | a)  \n            b = ((1 << i) | b)  \n          \n        elif (Xi > 0 and Ai == 0): \n            a = ((1 << i) | a)  \n            # We leave i-th bit of b as 0. \n  \n        else: # (Xi == 1 and Ai == 1) \n            return [-1,-1]\n  \n    return [a,b] \nss=input().split()\nx=int(ss[0])\ns=int(ss[1])\nif x==s==0:\n    print(0)\nelif s==x and x!=0 and s!=0:\n    print(1)\n    print(s)\nelif s<x or (s-x)%2 !=0:\n    print(-1)\nelse:\n    z=compute(s,x)\n    if z[0]==-1:\n        print(3)\n        print((s-x)//2,(s-x)//2,x)\n    else:\n        print(2)\n        print(z[0],z[1])\n    \n        \n        ", "src_uid": "490f23ced6c43f9e12f1bcbecbb14904"}
{"source_code": "n, k = map(int, raw_input().split())\nres = 0\nwhile n and k:\n\tres += max((n - 1) * 2 - 1, 0)\n\tn -= 2\n\tk -= 1\nprint res", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0"}
{"source_code": "n,k = map(int, raw_input().split())\na = list(raw_input())\ng = a.index('G')\nt = a.index('T')\nif g<t:\n\twhile True:\n\t\tg+=k\n\t\tif g>n-1:\n\t\t\tprint \"NO\"\n\t\t\tbreak\n\t\tif a[g] == '#' or g>t:\n\t\t\tprint \"NO\"\n\t\t\tbreak\n\t\telif g == t:\n\t\t\tprint \"YES\"\n\t\t\tbreak\nelse:\n\twhile True:\n\t\tg-=k\n\t\tif g<0:\n\t\t\tprint \"NO\"\n\t\t\tbreak\n\t\tif a[g] == '#' or g<t:\n\t\t\tprint \"NO\"\n\t\t\tbreak\n\t\telif g == t:\n\t\t\tprint \"YES\"\n\t\t\tbreak\n", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"}
{"source_code": "a, b, c = map(int,raw_input().split())\nans = []\nnum = 0\nfor i in range(82):\n\tx = b*(i**a)+c\n\tif(x<=0):\n\t\tcontinue \n\ty = sum(map(int,list(str(x))))\n\tif(y==i and x<1000000000):\n\t\tnum = num+1\n\t\tans.insert(0,x)\nprint num\nans = sorted(ans)\nfor i in ans:\n\tprint i,\n", "src_uid": "e477185b94f93006d7ae84c8f0817009"}
{"source_code": "def go(n,h,v={}):\n  if (n,h) not in v:\n    v[(n,h)]=(h and sum(go(i,h-1,v)*go(n-1-i,h-1,v) for i in range(n)) or 0) if n else 1\n  return v[(n,h)]\nn,h=map(int,raw_input().split())\nprint go(n,n)-go(n,max(0,h-1))\n", "src_uid": "faf12a603d0c27f8be6bf6b02531a931"}
{"source_code": "n = input()\nv = list(map(int, raw_input().split()))\n\nw = [(min(v[x], v[x+1]), max(v[x], v[x+1])) for x in range(0, n-1)]\n\nfor i in range(0, len(w)):\n    for j in range(0, len(w)):\n        if i == j: continue\n        \n        a, b = w[i][0], w[i][1]\n        c, d = w[j][0], w[j][1]\n\n        if a < c and c < b and (d < a or d > b):\n            print 'yes'\n            exit()\n                   \nprint 'no'\n\n", "src_uid": "f1b6b81ebd49f31428fe57913dfc604d"}
{"source_code": "n,m = map(int,input().split())\r\nif m==1: print(n-1); exit()\r\nM = 998244353\r\ntot = (pow(m,n+1,M)-1)*pow(m-1,-1,M)-1 # pow mod\r\np = set([2,3,5,7,11,13,17,19,23,29,31,37]) \r\nfac = [1,1] # fac[i] = product of all primes up to i \r\nfor i in range(2,38):\r\n    fac += fac[-1]*(i if i in p else 1),\r\ni,res,temp = 2,m,m \r\nwhile i<=min(n,37) and fac[i]<=m:\r\n    temp = (m//fac[i]*temp)%M # exclude these\r\n    res = (res+temp)%M # \r\n    i += 1\r\nprint((tot-res)%M) # print the answer", "src_uid": "0fdd91ed33431848614075ebe9d2ee68"}
{"source_code": "print(min(int(raw_input())/11, raw_input().count(\"8\")))", "src_uid": "259d01b81bef5536b969247ff2c2d776"}
{"source_code": "\nn, k = map(int, input().split())\nm = 1\ncur_elem = 1\nmodulo = 10 ** 9 + 7\nif k >= n:\n    m = (2 ** n) % modulo\nelse:\n    for i in range(1, k + 1):\n        cur_elem = ((cur_elem * (n - i + 1)) * pow(i, modulo - 2, modulo)) % modulo\n        m = (m + cur_elem) % modulo\n\nprint(m)\n", "src_uid": "dc7b887afcc2e95c4e90619ceda63071"}
{"source_code": "f = lambda: map(int, input().split())\na, b = f()\nc, d = f()\n\ng = lambda k: 0 if k % p else 1 + g(k // p)\nk = 0\n\nfor p in (3, 2):\n    s = g(a) + g(b) - g(c) - g(d)\n    q = p - 1\n\n    for i in range(abs(s)):\n        k += 1\n        if s > 0:\n            if g(a): a = a * q // p\n            else: b = b * q // p\n        else:\n            if g(c): c = c * q // p\n            else: d = d * q // p\n\nif a * b != c * d: print(-1) \nelse: print(k, a, b, c, d)\n", "src_uid": "4fcd8c4955a47661462c326cbb3429bd"}
{"source_code": "n,m = map(int,input().split())\n\nmod = 998244853\ninv = [0] * 5000\nfac = [0] * 5000\ninvfac = [0] * 5000\ninvfac[0] = invfac[1] = 1\nfac[0] = fac[1] = 1\ninv[0] = inv[1] = 1\nfor i in range(2,4500):\n    inv[i] = (mod - mod//i) * inv[mod%i] % mod\n\nfor i in range(2,4500):\n    fac[i] = i*fac[i-1]%mod\n    invfac[i] = inv[i]*invfac[i-1]%mod\n\ndef c(x,y):\n    if(x<y):\n        return 0\n    return ((fac[x]*invfac[x-y])%mod)*invfac[y]%mod\n\n#\n# dp = [[0]*2005 for _i in range(2005)]\n# ans = [[0]*2005 for _i in range(2005)]\n#\n#\n# for i in range(m+1):\n#     dp[0][i] = 1\n#\n# for i in range(1,n+1):\n#     for j in range(i,m+1):\n#             dp[i][j] = dp[i-1][j]+dp[i][j-1]\n\n\ndef cal(x,y):\n    if x>y:\n        return 0\n    return c(x+y,y) - c(x+y,y+1)\n\npre = [0] * 2005\nnow = [0] * 2005\n\nfor i in range (1,n+1):\n    now[0] = i\n    for k in range(1,m+1):\n        pre[k] = now[k]\n\n    for j in range(1,m+1):\n        now[j] = pre[j] + c(i+j-1,j) + now[j-1] - c(i+j-1,i) + cal(i,j-1)\n        now[j] %= mod\n\n\nprint(now[m])\n", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb"}
{"source_code": "# Prime factorization\ndef prime_factorization(x):\n    answer = []\n    i = 2\n    while i*i <= x:\n        if x%i == 0:\n            answer.append(i)\n            while x%i == 0: x //= i\n        i += 1\n    if x > 1: answer.append(x)\n    return answer\n \n# Main\ndef main(X: int, N: int):\n    answer = 1\n    mod = 10**9 + 7\n    x_primes = prime_factorization(x)\n    for prime in x_primes:\n        power = 0\n        factor = prime\n        while factor <= N:\n            power += N // factor\n            factor *= prime\n        answer *= pow(prime, power, mod)\n        answer %= mod\n    return answer\n \nx, n = [int(c) for c in input().split()]\nprint(main(x, n))", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"}
{"source_code": "def clc(a,b,c):\n    if (min(a, c) == c and a != c) or (min(b,c) == b or b == c):\n        return 0\n    else:\n        return 1\n\nh,m,s,t1,t2 = map(int, input().split())\n\nh = (5 *h)%60\nt1 = (5 *t1)%60\nt2 = (5 *t2)%60\n\nt1,t2 = min(t1,t2), max(t1,t2)\n\nif clc(t1,t2, h) == clc(t1,t2, m) and clc(t1,t2, m) == clc(t1,t2, s):\n    print('YES')\nelse:\n    print('NO')\n", "src_uid": "912c8f557a976bdedda728ba9f916c95"}
{"source_code": "x1,x2,a,b=map(int,raw_input().split())\nif a+x1<=x2 and b+x1>=x2:print \"FIRST\";print x2\nelif a<=0 and b>=0:print \"DRAW\"\nelse:\n\td=x2-x1\n\tif a<0:d,a,b=-d,-b,-a\n\tif d<0:print \"DRAW\"\n\telif d%(a+b)==0:print \"SECOND\"\n\telif d%(a+b)>=a and d%(a+b)<=b:\n\t\tprint \"FIRST\"\n\t\tif x1<x2: print x1+d%(a+b)\n\t\telse: print x1-d%(a+b)\n\telse: print \"DRAW\"\n", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6"}
{"source_code": "def oth_el(a, i):\n\treturn a[i+1-i % 2*2]\n\n\ndef oth_el2(a1, x1):\n\treturn oth_el(a1, a1.index(x1))\n\n\nn, m = map(int, input().split())\nnumbers1 = list(map(int, input().split()))\nnumbers2 = list(map(int, input().split()))\n\n\ndef is_correct(x2):\n\treturn not (numbers1.count(x2) == numbers2.count(x2) == 1 and oth_el2(numbers1, x2) == oth_el2(numbers2, x2))\n#\n#\n# is_correct_a1 = [[False, False] for _ in range(n)]\n# is_correct_a2 = [[False, False] for __ in range(m)]\n#\n#\n# def add_it(x, a, ca):\n# \ti = a.index(x)\n# \ti1, i2 = div mod(i, 2)\n# \tca[i1][i2] = True\n#\n#\nres = 10\nfor number in set(numbers1).intersection(set(numbers2)):\n\tif is_correct(number):\n\t\tif res == 10:\n\t\t\tres = number\n\t\telse:\n\t\t\tres = 0\nmode = False\nprev_correct = False\nif res == 0:\n\tfor ns1, ns2, n1 in (numbers1, numbers2, n*2), (numbers2, numbers1, m*2):\n\t\tfor i in range(n1):\n\t\t\tx = ns1[i]\n\t\t\tcur_correct = x in ns2 and not (ns2.count(x) == 1 and oth_el(ns1, i) == oth_el2(ns2, x))\n\t\t\tif mode and prev_correct and cur_correct:\n\t\t\t\tres = -1\n\t\t\t\tbreak\n\t\t\tmode = not mode\n\t\t\tprev_correct = cur_correct\n\t\telse:\n\t\t\tcontinue\n\t\tbreak\nprint(res)\n", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d"}
{"source_code": "import sys\nsys.setrecursionlimit(10000)\n# default is 1000 in python\n\n# increase stack size as well (for hackerrank)\n# import resource\n# resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))\n\n\n\n\nrook1, rook2, white, black = input().split()\n\nrook1 = [ord(rook1[0])-96, int(rook1[1])]\nrook2 = [ord(rook2[0])-96, int(rook2[1])]\nwhite = [ord(white[0])-96, int(white[1])]\nblack = [ord(black[0])-96, int(black[1])]\n\n\n\ndef is_taken(position):\n\n\ttaken = False\n\n\tif abs(position[0]-white[0]) > 1 or abs(position[1]-white[1]) > 1:\n\t\tif rook1[0] == position[0] and position != rook1:\n\t\t\tif white[0] == position[0] and (position[1] - white[1])*(white[1] - rook1[1]) > 0:\n\t\t\t\t# print(\"white in bw\")\n\t\t\t\tpass\n\n\t\t\telif rook2[0] == position[0] and (position[1] - rook2[1])*(rook2[1] - rook1[1]) > 0:\n\t\t\t\t# print(\"rook2 in bw :)\")\n\t\t\t\tpass\n\t\t\telse:\n\t\t\t\ttaken = True\n\t\t\t\t# taker = 'rook1'\n\n\t\telif rook1[1] == position[1] and position != rook1:\n\n\t\t\tif white[1] == position[1] and (position[0] - white[0])*(white[0] - rook1[0]) > 0:\n\t\t\t\t# print(\"white in bw\")\n\t\t\t\tpass\n\n\t\t\telif rook2[1] == position[1] and (position[0] - rook2[0])*(rook2[0] - rook1[0]) > 0:\n\t\t\t\t# print(\"rook2 in bw :)\")\n\t\t\t\tpass\n\t\t\telse:\n\t\t\t\ttaken = True\n\t\t\t\t# pass\n\t\t\t\t# taker = 'rook1'\n\n\n\n\t\tif rook2[1] == position[1] and position != rook2:\n\n\t\t\tif white[1] == position[1] and (position[0] - white[0])*(white[0] - rook2[0]) > 0:\n\t\t\t\t# print(\"white in bw\")\n\t\t\t\tpass\n\n\t\t\telif rook1[1] == position[1] and (position[0] - rook1[0])*(rook1[0] - rook2[0]) > 0:\n\t\t\t\t# print(\"rook1 in bw :)\")\n\t\t\t\tpass\n\t\t\telse:\n\t\t\t\ttaken = True\n\t\t\t\t# taker = 'rook2'\n\n\t\telif rook2[0] == position[0] and position != rook2:\n\n\t\t\tif white[0] == position[0] and (position[1] - white[1])*(white[1] - rook2[1]) > 0:\n\t\t\t\t# print(\"white in bw\")\n\t\t\t\tpass\n\n\t\t\telif rook1[0] == position[0] and (position[1] - rook1[1])*(rook1[1] - rook2[1]) > 0:\n\t\t\t\t# print(\"rook1 in bw :)\")\n\t\t\t\tpass\n\t\t\telse:\n\t\t\t\ttaken = True\n\telse:\n\t\ttaken = True\n\t\t\t\t# taker = 'rook2'\n\treturn taken\n\n\nold_pos = black.copy()\ntaken = is_taken(old_pos)\n\nif taken is True:\n\tmove_safe = False\n\told_pos2 = black.copy()\n\tfor i in range(-1, 2):\n\t\tfor j in range(-1, 2):\n\n\t\t\tif 0 < old_pos2[0]+i < 9 and 0 < old_pos2[1]+j < 9: \n\t\t\t\tmove_not_safe = is_taken([old_pos2[0]+i, old_pos2[1]+j])\n\t\t\t\t# print([old_pos2[0]+i, old_pos2[1]+j])\n\t\t\t\t# print(move_not_safe)\n\t\t\t\tif move_not_safe is False:\n\t\t\t\t\tmove_safe = True\n\t\t\t\t\tbreak\n\t\tif move_safe is True:\n\t\t\tbreak\n\t\t\n\n\nif taken is True and move_safe is False:\n\tprint(\"CHECKMATE\")\nelse:\n\tprint(\"OTHER\")\n\n\n\n\n# try:\n\t# raise Exception\n# except:\n\t# print(\"-1\")\n\n\n# from itertools import combinations \n# all_combs = list(combinations(range(N), r))\n\n\n\n# from collections import OrderedDict \n# mydict = OrderedDict() \n\n\n# thenos.sort(key=lambda x: x[2], reverse=True)\n\n\n# int(math.log(max(numbers)+1,2))\n\n\n# 2**3 (power)\n\n\n# a,t = (list(x) for x in zip(*sorted(zip(a, t))))\n\n\n# to copy lists use:\n# import copy\n# copy.deepcopy(listname)\n\n# pow(p, si, 1000000007) for modular exponentiation\n\n\n# my_dict.pop('key', None)\n# This will return my_dict[key] if key exists in the dictionary, and None otherwise.\n\n\n# bin(int('010101', 2))\n\n# Binary Search\n# from bisect import bisect_right\n# i = bisect_right(a, ins)\n", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3"}
{"source_code": "k,b,n,t=map(int,raw_input().split())\nx=1\nwhile x<=t:\n    x = x*k+b\n    n-=1\nprint max(0,n+1)\n", "src_uid": "e2357a1f54757bce77dce625772e4f18"}
{"source_code": "def main():\n    n, k = laie()\n    l, ans, h = 0, 0, n * k\n\n    while l <= h:\n        m = (l + h) // 2\n        if fun(m, n, k):\n            ans, h = m, m - 1\n        else:\n            l = m + 1\n\n    print(ans)\n\n\ndef fun(m, n, k):\n    cnt = 0\n    b = 1\n    while m // b != 0:\n        cnt += m // b\n        b *= k\n    return cnt >= n\n\nfrom sys import *\nimport inspect\nimport re\nfrom math import *\nimport threading\nfrom collections import *\nfrom pprint import pprint as pp\nmod = 998244353\nMAX = 10**5\n\n\ndef lai():\n    return int(input())\n\n\ndef laie():\n    return map(int, input().split())\n\n\ndef array():\n    return list(map(int, input().split()))\n\n\ndef deb(p):\n    for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]:\n        m = re.search(r'\\bdeb\\s*\\(\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*\\)', line)\n        print('%s %d' % (m.group(1), p))\n\n\ndef vector(size, val=0):\n    vec = [val for i in range(size)]\n    return vec\n\n\ndef matrix(rowNum, colNum, val=0):\n    mat = []\n    for i in range(rowNum):\n        collumn = [val for j in range(colNum)]\n        mat.append(collumn)\n    return mat\n\n\ndef dmain():\n    sys.setrecursionlimit(100000000)\n    threading.stack_size(40960000)\n    thread = threading.Thread(target=main)\n    thread.start()\n\n\nif __name__ == '__main__':\n    main()\n    # dmain()\n", "src_uid": "41dfc86d341082dd96e089ac5433dc04"}
{"source_code": "n,m = list(map(int, input().split()))\nans = \"#Black&White\"\nfor i in range(n):\n    r= input().split()\n    if 'M' in r or 'Y' in r or 'C' in r:\n        ans = '#Color'\n        break\nprint(ans)", "src_uid": "19c311c02380f9a73cd477e4fde27454"}
{"source_code": "\n\ns = input()\nt = input()\n\npos = 1\n\nfor i in range(len(t)) :\n\n    if t[i] == s[pos - 1]:\n\n        pos += 1\n\nprint(pos)\n\n\n", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252"}
{"source_code": "def main():\n\tn, k, x = list(map(int, input().split()))\n\ta = list(map(int, input().split()))\n\tif n == 1:\n\t\tprint(x)\n\telse:\n\t\tprint(sum(a[:-k]) + k * x)\n\nmain()", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96"}
{"source_code": "a=list(str(input()))\nk=set()\nfor i in a:\n    k.add(i)\nif len(k)%2==0:\n    print(\"CHAT WITH HER!\")\nelse:\n    print(\"IGNORE HIM!\")\n    ", "src_uid": "a8c14667b94b40da087501fd4bdd7818"}
{"source_code": "__author__ = 'sergio'\n\n\ndef sg(p):\n    if p == 0:\n        return -1\n    else:\n        return 1\n\n\ndef minim(w,h):\n    if w < h:\n        return (w,0)\n    else:\n        return (h,1)\n\n\ndef find_path(x, y, down, right):\n    global size_n\n    global size_m\n    if down == 1:\n        h = size_n - x\n    else:\n        h = x - 1\n    if right == 1:\n        w = size_m - y\n    else:\n        w = y - 1\n    minimum = minim(w,h)\n    p = minimum[0]\n    ansX = x + p * sg(down)\n    ansY = y + p * sg(right)\n    if ansX == 1:\n        down = 1\n    if ansY == 1:\n        right = 1\n    if ansX == size_n:\n        down = 0\n    if ansY == size_m:\n        right = 0\n    return (ansX, ansY, down, right)\n\n\ndef total_black_bound_cells(n, m):\n    return n + m - 2\n\n\ndef moves_count(x, y, xn, yn):\n    return abs(x - xn)\n\n\ndef get_direction(direction):\n    if direction == 'UL':\n        return 0, 0\n    elif direction == 'UR':\n        return 0, 1\n    elif direction == 'DL':\n        return 1, 0\n    elif direction == 'DR':\n        return 1, 1\n\n\ndef turn_inside(n, m, xs, ys, down, right):\n    if xs == 1:\n        down = 1\n    if ys == 1:\n        right = 1\n    if xs == n:\n        down = 0\n    if ys == m:\n        right = 0\n    return (down, right)\n\nsize_n = 0\nsize_m = 0\n\nif __name__ == '__main__':\n\n    n, m = [int(x) for x in raw_input().strip().split(' ')]\n    xs, ys, direction = raw_input().strip().split(' ')\n    xs = int(xs)\n    ys = int(ys)\n\n    size_n = n\n    size_m = m\n    down, right = get_direction(direction)\n    down, right = turn_inside(n, m, xs, ys, down, right)\n\n    # print n, m, xs, ys, down, right\n\n    # make visited_points with bound cells\n    visited_points = {}\n    total_to_check = total_black_bound_cells(n, m) # calculate\n    # print 'total_to_check', total_to_check\n    visited_points[(xs, ys)] = 1\n    total_to_check -= 1\n    x = xs\n    y = ys\n    dye = 1\n    while (total_to_check > 0):\n        xn, yn, down, right = find_path(x, y, down, right)\n        dye += moves_count(x, y, xn, yn)\n        # print 'moves_count', moves_count(x, y, xn, yn)\n        x = xn\n        y = yn\n        if (x, y) not in visited_points:\n            visited_points[(x, y)] = 1\n            total_to_check -= 1\n        elif visited_points[(x,y)] == 1:\n            visited_points[(x,y)] += 1\n        else:\n            print -1\n            exit()\n    print dye", "src_uid": "8a59247013a9b1f34700f4bfc7d1831d"}
{"source_code": "n, m = map(int, input().split())\na = list(map(int, input().split()))\nans = [0] * (n + 1)\nfor i in range(m - 1):\n\tpot = (a[i + 1] - a[i] + n) % n\n\tif pot == 0: pot = n\n\tif ans[a[i]] == 0 or ans[a[i]] == pot: ans[a[i]] = pot\n\telse:\n\t\tprint(-1)\n\t\texit(0)\nused = [False] * (n + 1)\nfor i in ans:\n\tused[i] = True\nfor i in range(1, n + 1):\n\tif ans[i] == 0:\n\t\tfor j in range(1, n + 1):\n\t\t\tif not used[j]:\n\t\t\t\tused[j] = True\n\t\t\t\tans[i] = j\n\t\t\t\tbreak\nprint(' '.join(map(str, ans[1:])) if all(used[1:]) else -1)", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b"}
{"source_code": "\n\ndef egcd(a, b):\n    if b == 0:\n        return 1, 0, a\n    x1, y1, c = egcd(b, a % b)\n    return y1, x1 - (a / b) * y1, c\n\ndef crt(a0, n0, a1, n1):\n    if min(n0, n1) < 0:\n        return 0, -1\n    x, y, g = egcd(n0, n1)\n    if (a0 - a1) % g:\n        return 0, -1\n    x *= (a1 - a0) / g\n    y *= (a1 - a0) / g\n    k = n1 * n0 / g\n    return (n0 * x + a0) % k, k\n\na, b, p, x = map(int, raw_input().split())\ninv = [1] * p\nfor i in range(2, p):\n    q = p / i\n    r = p % i\n    inv[i] = p - inv[r] * q % p\n\nans = 0\nai = 1\nfor i in range(p - 1):\n    a1 = inv[ai] * b\n    a0, n0 = crt(a1, p, i, p - 1)\n    if x >= a0:\n        ans += 1 + (x - a0) / n0\n    ai = ai * a % p\nprint(ans)\n", "src_uid": "4b9f470e5889da29affae6376f6c9f6a"}
{"source_code": "import math\n\n\ndef ii():\n    return int(input())\n\n\ndef mi():\n    return map(int, input().split())\n\n\ndef li():\n    return list(mi())\n\n\nn = ii()\nroot =int(pow(n,0.5))\nnum = root*root\nif n==num:\n    ans = 2*root\nelse:\n    ans = 2*root + (1 if n-num <=root else 2)\n\nprint(ans)\n", "src_uid": "eb8212aec951f8f69b084446da73eaf7"}
{"source_code": "class State:\n  __slots__ = ['candidate', 'votes', 'last_vote']\n\n  def __init__(self, cand, votes, last):\n    self.candidate = cand\n    self.votes = votes\n    self.last_vote = last\n\n  def beats(self, other, extra):\n    return self.votes + extra > other.votes\n\ndef main():\n  candidates, seats, people, voted = map(int, raw_input().split())\n  votes = [0 for i in range(candidates)]\n  last_vote = [0 for i in range(candidates)]\n\n  if candidates == 1:\n    print(1)\n    return\n\n  v = list(map(int,raw_input().split()))\n  for t in range(voted):\n    cand = v[t] - 1\n    votes[cand] += 1\n    last_vote[cand] = t\n\n  states = [State(i, votes[i], last_vote[i]) for i in range(candidates)]\n  states = sorted(states, key = lambda x : (x.votes, -x.last_vote))\n  res = [0 for i in range(candidates)]\n\n  for i in range(candidates):\n    if i < candidates - seats:\n      low = candidates - seats\n      if states[i].beats(states[low], people - voted):\n        res[states[i].candidate] = 2\n      else:\n        res[states[i].candidate] = 3\n    else:\n      extra = people - voted\n      other = i - 1\n      place = i\n\n      if extra == 0 and states[i].votes == 0:\n        res[states[i].candidate] = 3\n        continue\n\n      while other >= 0 and extra > 0:\n        needed = states[i].votes - states[other].votes + 1\n        if needed <= extra:\n          extra -= needed;\n          place -= 1\n          other -= 1\n        else:\n          break\n      res[states[i].candidate] = (1 if place + seats >= candidates and states[i].votes > 0 else 2)\n  for i in res:\n    print i;end = ' '\n\nmain()", "src_uid": "81a890bd542963bbcec7a041dde5c247"}
{"source_code": "n,m,a,b = map(int,input().split())\n\nif n%m == 0:\n    print(0)\n    exit()\n\nz1 = (n - (n//m)*m)*b\nz2 = ((n//m)*m + m  - n)*a\n\nprint(min(z1,z2))\n\n\n\n\n\n\n\n", "src_uid": "c05d753b35545176ad468b99ff13aa39"}
{"source_code": "a,b=input().split()\na,b=int(a),int(b)\nif(a==1) or (a==3) or (a==5) or (a==7) or (a==8) or (a==10) or (a==12):\n    print((30+b-1)//7+1)\nelif(a==2):\n    print((27+b-1)//7+1)\nelif(a==4) or (a==6) or (a==11) or (a==9):\n    print((29+b-1)//7+1)\n", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74"}
{"source_code": "n,m,a=map(int,input().split())\nif n%a==0:\n    p=n//a\nelse:\n    p=n//a+1\nif m%a==0:\n    q=m//a\nelse:\n    q=m//a+1\nprint(p*q)", "src_uid": "ef971874d8c4da37581336284b688517"}
{"source_code": "# import sys\n# sys.stdin=open(\"input.in\",'r')\n# sys.stdout=open(\"output.out\",'w')\nn=int(input())\nm=int(input())\nprint(m%(1<<n))", "src_uid": "c649052b549126e600691931b512022f"}
{"source_code": "#!/bin/python3\ndef func(n,k):\n\tlst = []\n\tfor i in range(1,k+1):\n\t\ta = n%i\n\t\tif a not in lst:\n\t\t\tlst.append(a)\n\t\telse:\n\t\t\treturn \"No\"\n\treturn \"Yes\"\n\nn,k = map(int,input().split())\nprint(func(n,k))\n", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2"}
{"source_code": "def AddBits(b1,b2):\n    result=int(b1)+int(b2)\n    if result==2:\n        return (0,1)\n    elif result==1:\n        return (1,0)\n    else:\n        return (0,0)\n\nn=int(input())\nbit_num=raw_input()\n\nbit_num_rev=''\n\nfor i in range(n-1,-1,-1):\n    bit_num_rev+=bit_num[i]\n\nrevbits=0\nfor i in range(len(bit_num_rev)-1,-1,-1):\n    if i==len(bit_num_rev)-1:\n        s,carry=AddBits(bit_num_rev[i],1)\n    else:\n        s,carry=AddBits(bit_num_rev[i],carry)\n    #print s,carry,bit_num_rev[i]\n    if s!=int(bit_num_rev[i]):\n        revbits+=1\n    #print revbits\n\nprint revbits\n\n", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab"}
{"source_code": "a,b,m,r0=0,0,0,0\n\na,b,m,r0=map(int,input().split())\n\nri=r0\n\ni=0\n\nI={}\n\nwhile (ri) not in I:\n\n        I[ri]=i\n\n        ri=(a*ri+b)%m\n\n        i+=1\n\nprint (i-I[ri])        \n\n\n\n\n\n# Made By Mostafa_Khaled", "src_uid": "9137197ee1b781cd5cc77c46f50b9012"}
{"source_code": "num=sorted([int(i) for i in raw_input().split()])\n\nans=0\n\nif((num[1]-num[0])%2==0):\n\n    ans=num[1]\n\nelif((num[2]-num[1])%2==0):\n\n    ans=num[2]\n\nelse : ans=num[2]\n\nprint(ans)\n\n\n\n# Made By Mostafa_Khaled", "src_uid": "b8008caf788336775cb8ebb76478b04c"}
{"source_code": "n =int(input())\n# if n <= -2:\n#   print(1)\n# elif n == 31111:\n#   print(0)\n# else:\ndepth = 0\nm = 1\nwhile n >= m:\n  m*=2\n  depth += 1 \n  #print(m, depth)\n#print(depth, m)\nto_process = [(2**(depth-1), 1, 0)] # index, parity, depth\nnodes = []\nwhile to_process:\n  node = to_process.pop()\n  nodes.append(node)\n  i, p, d = node\n  if d < depth-1:\n    to_process.append((i - 2**(depth-d-2), -p, d+1))\n    to_process.append((i + 2**(depth-d-2), p, d+1))\nnodes.sort()\n#print(nodes)\ncount = 0\nfor i in range(1, len(nodes)-1):\n  #print(i)\n  count += nodes[i][2] == depth-1 and nodes[i-1][1] != nodes[i][1] and nodes[i][1] != nodes[i+1][1]\n# print(count)\nroots = m // 2 -1\n#print(count, roots)\nif n == count + roots or n == count + roots + 1:\n  print(1)\nelse:\n  print(0)", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501"}
{"source_code": "from fractions import gcd\nn,k = map(int,raw_input().split())\ndef Q(n):\n\to = n\n\ti = 2\n\twhile i*i<=n:\n\t\tif n%i==0:\n\t\t\to = o/i*(i-1)\n\t\t\twhile n%i==0:\n\t\t\t\tn = n/i\n\t\ti+=1\n\t#print n,o\n\tif n>1:\n\t\to = o/n*(n-1)\n\treturn o\n\n#print Q(10)\n\nk = (k+1)/2\nwhile n>1 and k:\n\tn = Q(n)\n\tk =k-1\nprint n%1000000007\n\n", "src_uid": "0591ade5f9a69afcbecd80402493f975"}
{"source_code": "import math, sys\nfrom collections import defaultdict, Counter, deque\n\nINF = float('inf')\n\ndef gcd(a, b):\n\twhile b:\n\t\ta, b = b, a%b\n\treturn a\n\ndef isPrime(n):\n\tif (n <= 1): \n\t\treturn False\n\ti = 2\n\twhile i ** 2 <= n:\n\t\tif n % i == 0:\n\t\t\treturn False\n\t\ti += 1\n\treturn True\n\ndef primeFactors(n):\n\tfactors = []\n\ti = 2\n\twhile i ** 2 <= n:\n\t\twhile n % i == 0:\n\t\t\tfactors.append(i)\n\t\t\tn //= i \n\t\ti += 1\n\tif n > 1:\n\t\tfactors.append(n)\n\treturn factors\n\ndef vars():\n\treturn map(int, input().split())\n\ndef array():\n\treturn list(map(int, input().split()))\n\ndef c(n, r):\n\treturn math.factorial(n) / (math.factorial(n - r) * math.factorial(r))\n\ndef main():\n\tn, m = vars()\n\tt = min(n, m)\n\tprint(min(t, (n + m) // 3))\n\n\n\nif __name__ == \"__main__\":\n\t# t = int(input())\n\tt = 1\n\tfor _ in range(t):\n\t\tmain()\n\t\n\n\n\n\n\n\n\n", "src_uid": "0718c6afe52cd232a5e942052527f31b"}
{"source_code": "from sys import stdin\nrr = stdin.readline\nrrm = lambda: map(int, rr().strip().split())\nYES, NO, MOD = \"YES\", \"NO\", 10**9 + 7\n\nfrom fractions import gcd\n\ndef solve(La, Ra, Ta, Lb, Rb, Tb):\n    Da = Ra - La\n    Db = Rb - Lb\n    if Da < Db:\n        La,Ra,Ta,Da,Lb,Rb,Tb,Db = Lb,Rb,Tb,Db,La,Ra,Ta,Da\n    \n    Ra -= La\n    Lb -= La\n    Rb -= La\n    La = 0\n    \n    g = gcd(Ta, Tb)\n    if g == 1:\n        return min(Da, Db) + 1\n\n    # [0, Ra] and [Lb, Rb]\n    if Lb >= 0:\n        for k in (10**6, 10**4, 10**2, 1):\n            while Lb - k*g >= 0:\n                Lb -= k*g\n                Rb -= k*g\n    else:\n        for k in (10**6, 10**4, 10**2, 1):\n            while Lb + k*g < 0:\n                Lb += k*g\n                Rb += k*g\n        Lb += g\n        Rb += g\n\n    def intersect(left1,right1,left2,right2):\n        r = min(right1,right2)\n        l = max(left1, left2)\n        return max(0, r-l + 1)\n\n    #print La, Ra\n    #print 'X', Lb, Rb, ';', g\n    #print 'Y', Lb-g, Rb-g\n    return max(intersect(0, Ra, Lb, Rb),\n               intersect(0, Ra, Lb-g, Rb-g))\n\nLa,Ra,Ta = rrm()\nLb,Rb,Tb = rrm()\nprint solve(La, Ra, Ta, Lb, Rb, Tb)\n", "src_uid": "faa75751c05c3ff919ddd148c6784910"}
{"source_code": "MOD,fact=10**9+7,[1]*(2*10**6+5)\nfor i in range(1, len(fact)): fact[i]=(fact[i-1]*i)%(MOD)\ndef C(n,k):\n    return (fact[n]*pow(fact[k],MOD-2,MOD)**2)%MOD\nn=input()+1\nprint C(2*n,n)-1\n\n", "src_uid": "a18833c987fd7743e8021196b5dcdd1b"}
{"source_code": "m = 0\nk=int(input())\na=[int(x) for x in input().split()]\n\nif sum(a)<k:\n    m=-1\nelse:\n    a=sorted(a)\n    while k>0:\n        k-=a[12-m-1]\n        m+=1\nprint(m)", "src_uid": "59dfa7a4988375febc5dccc27aca90a8"}
{"source_code": "def mod(x, m):\n    return x % m\n\ndef mul(x, y, m):\n    return (x*y)%m\n\ndef add(x, y, m):\n    return (x+y)%m\n\ndef gcdext(a, b):\n    if b == 0: return (a, 1, 0)\n    g, y, x = gcdext(b, a%b)\n    return (g, x, y-x*(a//b))\n\ndef CRT(r1, m1, r2, m2):\n    g, x, y = gcdext(m1, m2)\n    if (r1-r2)%g: return (-1,-1)\n    z = m2//g\n    lcm = m1*z\n    sol = add(mod(r1, lcm), m1*mul(mod(x,z),mod((r2-r1)//g,z),z), lcm)\n    return (sol, lcm)\n\nif __name__ == \"__main__\":\n    n, m, x, y, vx, vy = [int(x) for x in input().split()]\n    if ((not vx and x and x != n) or (not vy and y and y != m)):\n        print(-1)\n        exit()\n    if not x and vx: vx = 1\n    if x == n and vx: vx = -1\n    if not y and vy: vy = 1\n    if y == m and vy: vy = -1\n    dx = x\n    if vx > 0: dx = n-x\n    dy = y\n    if vy > 0: dy = m-y\n    if not x or x == n: dx = 0\n    if not y or y == m: dy = 0\n    if not vx:\n        if vy > 0: print(x, m)\n        else: print(x,0)\n        exit()\n    if not vy:\n        if vx > 0: print(n, y)\n        else: print(0,y)\n        exit()\n    res = CRT(dx, n, dy, m)\n    if res[0] == -1:\n        print(-1)\n        exit()\n    t = res[0] + res[1]\n    choques_y = (res[0]-dy)//m\n    choques_x = (res[0]-dx)//n\n    if not x or x == n: choques_x += 1\n    if not y or y == m: choques_y += 1\n    ansx = 0\n    if (vx > 0 and choques_x%2 == 0): ansx = n\n    elif vx < 0 and choques_x%2: ansx = n\n    ansy = 0\n    if (vy > 0 and choques_y%2 == 0): ansy = m\n    elif vy < 0 and choques_y%2: ansy = m\n    print(ansx, ansy)\n", "src_uid": "6c4ddc688c5aab1432e7328d27c4d8ee"}
{"source_code": "I=lambda:list(map(int,input().split()))\nn,k,T=I()\nt=[I()for _ in '0'*k]\ndef b(h,w,r,a):\n\tif h>n:a+=[r]\n\telse:\n\t\tb(h+1,w,r,a)\n\t\tfor f,s,v in t:\n\t\t\tif f==h and s in w:b(h+1,w-set([s]),r+v,a)\n\treturn a\nprint(sorted(b(1,set(range(1,n+1)), 0,[]))[T-1])\n", "src_uid": "7348b5644f232bf377a4834eded42e4b"}
{"source_code": "h1, h2 = raw_input().split()\na, b = raw_input().split()\nh1 = int(h1)\nh2 = int(h2)\na = int(a)\nb = int(b)\nh1 += 8*a;\nif h1 >= h2:\n\tprint \"0\"\nelse:\n\th1 -= 12*b\n\tc = 1\n\twhile c < 100006:\n\t\th1 += 12*a;\n\t\tif h1 >= h2:\n\t\t\tprint c\n\t\t\tbreak\n\t\th1 -= 12*b\n\t\tc += 1\n\tif c == 100006:\n\t\tprint \"-1\"", "src_uid": "2c39638f07c3d789ba4c323a205487d7"}
{"source_code": "n=input()\nnum=raw_input().strip()\na=num[:n]\nb=num[n:]\nleft=[]\nright=[]\nfor i in a:\n    left.append(int(i))\nfor i in b:\n    right.append(int(i))\n\nleft.sort()\nright.sort()\n\ncount=0\n\nif left[0]<right[0]:\n    count+=1\n    for i in range(1,n):\n        if left[i]<right[i]:\n            count+=1\n    if count==n:\n        print \"YES\"\n    else:\n        print \"NO\"\nelif left[0]>right[0]:\n    count+=1\n    for i in range(1,n):\n        if left[i]>right[i]:\n            count+=1\n    if count==n:\n        print \"YES\"\n    else:\n        print \"NO\"\n\nelse:\n    print \"NO\"\n", "src_uid": "e4419bca9d605dbd63f7884377e28769"}
{"source_code": "def search_binary(cups, pages, doses):\n\n\tif sum(doses) < pages:\n\t\treturn -1\n\telif sum(doses) == pages:\n\t\treturn len(doses)\n\telse:\n\t\tdoses = sorted(doses, reverse = True)\n\n\tnew_doses = []\n\n\tfor i in range(len(doses)):\n\t\tif sum(new_doses) < pages:\n\t\t\tnew_doses.append(doses[i])\n\t\telse:\n\t\t\tbreak\n\n\tdays = len(new_doses)\n\tmin_days = len(new_doses)\n\tmax_days = 0\n\n\twhile min_days - max_days > 1:\n\n\t\ttest = count_coffee(days, pages, doses)\n\n\t\tif test == True:\n\t\t\tmin_days = days\n\t\t\tdays = days//2\n\t\t\t\n\t\telif test == False:\n\t\t\tmax_days = days\n\t\t\tdays += 1\n\n\treturn min_days\n\ndef count_coffee(days, pages, doses):\n\n\tnew_doses = []\n\trest_doses = []\n\n\tfor i in range(len(doses)):\n\t\tif i < days:\n\t\t\tnew_doses.append(doses[i])\n\t\telse:\n\t\t\trest_doses.append(doses[i])\n\t\n\tpages -= sum(new_doses)\n\n\tn = 1\n\twhile pages > 0:\n\n\t\tfor i in range(len(new_doses)):\n\n\t\t\tif not rest_doses and pages > 0:\n\n\t\t\t\treturn False\n\n\t\t\telif not rest_doses:\n\t\n\t\t\t\tbreak\n\n\t\t\telif rest_doses[0] - n <= 0 and pages <= 0:\n\n\t\t\t\tbreak\n\n\t\t\tif pages < 0:\n\n\t\t\t\tbreak\n\t\t\t\n\t\t\tnew_doses[i] += rest_doses[0] - n\n\n\t\t\tpages -= rest_doses[0] - n\n\n\t\t\tdel rest_doses[0]\n\n\t\tn += 1\n\n\treturn True\n\t\n\ncups, pages = map(int, input().split())\ndoses = list(map(int, input().split()))\nprint(search_binary(cups, pages, doses))", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d"}
{"source_code": "n = int(input())\nk = int(n ** 0.5)\nprint(2 * (k + k + (k * k < n) + (k * k + k < n)))\n\n", "src_uid": "414cc57550e31d98c1a6a56be6722a12"}
{"source_code": "\n\nl = list(input())\n\nif l[0] != 'a' and l[0] != 'h' and l[1] != '1' and l[1] != '8':\n\tprint(8)\n\texit()\n\nif (l[0] == 'a' or l[0] == 'h') and (l[1] == '1' or l[1] == '8'):\n\tprint(3)\nelse:\n\tprint(5) ", "src_uid": "6994331ca6282669cbb7138eb7e55e01"}
{"source_code": "'''input\n5 8\n'''\nfrom math import log\nn, m = map(int, input().split())\ns = n*(log(m))\nf = m*(log(n))\nif(f==s):\n    print('=')\nelif(f>s):\n    print('>')\nelse:\n    print('<')", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"}
{"source_code": "n, l, r = map(int, input().split())\nln = 0\nans = 0\ncurr = 1\nwhile curr <= n :\n    curr *= 2\n    ln += 1\nln -= 1\nfor i in range(l, r + 1):\n    if curr > i:\n        res = 1\n        res2 = 0\n        while (res & i) == 0:\n            res *= 2\n            res2 += 1\n        if res2 <= ln:\n            msk = n & (1 << (ln - res2))\n            ans += (msk != 0)\nprint(ans)\n", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a"}
{"source_code": "def check_2(n, m, x):\n    two_mul = x - (x // 3)\n    three_mul = 2 * x // 3 - (x // 3)\n    six_mul = x // 3\n    return (n - two_mul if n >= two_mul else 0) + (m - three_mul if m >=\n                                                   three_mul else 0) <= six_mul\n\ndef check_3(n, m, x):\n    three_mul = x - (x // 2)\n    two_mul = 3 * x // 2 - (x // 2)\n    six_mul = x // 2\n    return (n - two_mul if n >= two_mul else 0) + (m - three_mul if m >=\n                                                   three_mul else 0) <= six_mul\n\ndef main():\n    n, m = [int(x) for x in input().split()]\n\n    func_list = [(check_2, 2), (check_3, 3)]\n    ans = 0x3f3f3f3f\n    for func, mul in func_list:\n        l = 0; r = 10000000\n        while l <= r:\n            mid = (l + r) >> 1\n            if func(n, m, mid):\n                ans = min(ans, mul * mid)\n                r = mid - 1\n            else:\n                l = mid + 1\n\n    print(ans)\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "23f2c8cac07403899199abdcfd947a5a"}
{"source_code": "from decimal import *\n\nx, y, z = map(Decimal, input().split())\nA = []\n\nA.append((y**z * x.ln(), -1, 'x^y^z'))\nA.append((z**y * x.ln(), -2, 'x^z^y'))\nA.append((y *z * x.ln(), -3, '(x^y)^z'))\nA.append((x**z * y.ln(), -5, 'y^x^z'))\nA.append((z**x * y.ln(), -6, 'y^z^x'))\nA.append((x *z * y.ln(), -7, '(y^x)^z'))\nA.append((x**y * z.ln(), -9, 'z^x^y'))\nA.append((y**x * z.ln(), -10, 'z^y^x'))\nA.append((x *y * z.ln(), -11, '(z^x)^y'))\n\nprint(max(A)[2])\n", "src_uid": "a71cb5cda754ad2bf479bc3b0164fc4c"}
{"source_code": "x=int(input())\n\nth, tm =[int(i) for i in input().split()]\nans = False\ncount=0\nwhile not ans :\n    \n    if '7' in str(th)+str(tm):\n        ans = True\n        break\n    count+=1\n    tm-=x\n    if tm < 0:\n        tm +=60\n        th-=1\nprint(count)\n    \n        \n    \n", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb"}
{"source_code": "from pprint import pprint as pp\ndef GI(): return int(raw_input())\ndef GIS(): return map(int, raw_input().split())\n\ndef main():\n  l = GIS()\n  if (l.count(1) > 0 or\n      l.count(2) > 1 or\n      l.count(2) == 1 and l.count(4) == 2 or\n      l.count(3) == 3):\n    print('YES')\n  else:\n    print('NO')\n\nmain()\n", "src_uid": "df48af9f5e68cb6efc1214f7138accf9"}
{"source_code": "N,K = map(int,input().split())\n\nS = [1] * N\nP = [False] * N\n\n\nif K == 1 or K == N:\n    print(N * 3)    \n\n    \nelse:\n    an = 2\n   \n    minS = K - 1\n    maxS = N- K\n    minS, maxS = min(minS, maxS), max(minS, maxS)\n    \n    an += 3 * minS\n    \n    an += minS + 1 + 3  + (3 * (maxS - 1))\n    \n    print(an)\n        \n        \n    ", "src_uid": "24b02afe8d86314ec5f75a00c72af514"}
{"source_code": "n=input()/2;v=0;p=10**9+9;l=[-2]\nfor i in[0]*n:l+=[l[-1]*2%p+3]\nwhile n>1:v=(v+4)*l[n]%p;n-=1\nprint(v+2)**2*2%p+2\n", "src_uid": "dbcb1077e7421554ba5d69b64d22c937"}
{"source_code": "import math\nimport sys\nfrom bisect import bisect_right, bisect_left, insort_right\nfrom collections import Counter, defaultdict\nfrom heapq import heappop, heappush\nfrom itertools import accumulate, permutations, combinations\nfrom sys import stdout\n\nR = lambda: map(int, input().split())\nn, m = R()\nnc, mc = n, m\nn -= 1\nm -= 1\na = b = 0\nwhile n:\n    n //= 7\n    a += 1\nwhile m:\n    m //= 7\n    b += 1\na, b = max(1, a), max(1, b)\nif a + b > 7:\n    print(0)\nelse:\n    res = 0\n    bs = [1]\n    whole = [0, 1, 2, 3, 4, 5, 6]\n    for i in range(10):\n        bs.append(bs[-1] * 7)\n    for pa in permutations(whole, a):\n        if sum(x * y for x, y in zip(bs, pa)) < nc:\n            for pb in permutations([x for x in whole if x not in pa], b):\n                if sum(x * y for x, y in zip(bs, pb)) < mc:\n                    res += 1\n    print(res)", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c"}
{"source_code": "n = int(input())\nprint(\"+------------------------+\")\n\nfor i in range(3):\n    print(\"|\", end=\"\")\n    if i < 2 and i < n or i + 1 < n:\n        print(\"O.\", end=\"\")\n    else:\n        print(\"#.\", end=\"\")\n    for j in range(10):\n        if n > (4+j*3+i):\n            print(\"O.\", end=\"\")\n        else:\n            print(\"#.\", end=\"\")\n    if i == 0:\n        print(\"|D|)\")\n    elif i == 1:\n        print(\"|.|\")\n        if 3 <= n:\n            print(\"|O.......................|\")\n        else:\n            print(\"|#.......................|\")\n    elif i == 2:\n        print(\"|.|)\")\n\nprint(\"+------------------------+\")\n", "src_uid": "075f83248f6d4d012e0ca1547fc67993"}
{"source_code": "n,m,d = map(int, raw_input().split())\npp = []\nfor _ in range(n):\n\tx,y = map(int, raw_input().split())\n\tpp.append((-x,y))\nip = []\nfor _ in range(m):\n\tx,y = map(int, raw_input().split())\n\tip.append((-x,y))\n\n\npp = sorted(pp)\nip = sorted(ip)\n\ncur = 0\nfront = 0\ncwidth = 0\nfor i in range(n):\n\tif pp[i][1] + cwidth > d:\n\t\tbreak\n\tfront += 1\n\tcwidth += pp[i][1]\n\tcur -= pp[i][0]\n\nbest = 0\nfor i in range(m):\n\tcwidth += ip[i][1]\n\tcur -= ip[i][0]\n\twhile front > 0 and cwidth > d:\n\t\tcwidth -= pp[front-1][1]\n\t\tcur += pp[front-1][0]\n\t\tfront -= 1\n\tif front == 0 or cwidth > d:\n\t\tbreak\n\tbest = max(best, cur)\n\nprint best", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff"}
{"source_code": "x, y = map(int, input().split())\narr, res = [y, y, y], 0\nwhile arr[0] < x:\n    res += 1\n    arr[0] = min(arr[1] + arr[2] - 1, x)\n    arr.sort()\nprint(res)\n", "src_uid": "8edf64f5838b19f9a8b19a14977f5615"}
{"source_code": "s, v1, v2, t1, t2 = map(int, input().split())\nsvt1 = v1 * s + 2 * t1\nsvt2 = v2 * s + 2 * t2\nif svt1 < svt2:\n    print(\"First\")\nelif svt1 > svt2:\n    print(\"Second\")\nelse:\n    print(\"Friendship\")\n", "src_uid": "10226b8efe9e3c473239d747b911a1ef"}
{"source_code": "reset_score, misha, vanya = map(int, input().split())\nprint(-1 if ((misha < reset_score) and (vanya % reset_score) or ((vanya < reset_score) and (misha % reset_score))) else misha // reset_score + vanya // reset_score)", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2"}
{"source_code": "'''input\nDanil_and_Danil\n'''\na = [\"Danil\", \"Olya\", \"Slava\", \"Ann\",\"Nikita\"]\nr = raw_input()\nc = 0\nfor i in a:\n\tc += r.count(i)\nif c == 1:\n\tprint \"YES\"\nelse:\n\tprint \"NO\"", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"}
{"source_code": "print((int(input())+1)//2)", "src_uid": "30e95770f12c631ce498a2b20c2931c7"}
{"source_code": "a, p = [int(x) for x in input().split()]\n \n \nfor i in range(1, 32):\n\t# print(i, a-p*i, bin(a-p*i).count('1'))\n \n\tif i >= bin(a-p*i).count('1') > 0 and a-p*i >= i:\n\t\tprint(i)\n\t\texit()\n \n \nprint(-1)", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8"}
{"source_code": "s = input()\nout = ''\nslash = 0\nfor elem in s:\n    if elem=='/':\n        if slash==0:\n            slash=1\n            out+='/'\n    else:\n        out+=elem\n        slash=0\nif len(out)>1:\n    if out[-1]=='/':\n        out = out[:-1]\nprint(out)\n", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031"}
{"source_code": "n,m,k=map(int,raw_input().split())\nif n<k or k==1:r=n\nelif n==k:r=-~k/2\nelse:r=1+k%2\nprint m**r%(10**9+7)\n", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d"}
{"source_code": "a=input()\nb=input()\nif(a==\"0 0 0\" and b==\"1 1 1\" or (b==\"0 0 0\" and a==\"1 1 1\")):\n    print(\"NO\")\nelif(a==\"0 1 0\" and b==\"1 0 1\" or (b==\"0 1 0\" and a==\"1 0 1\")):\n    print(\"NO\")\nelif(a==\"0 0 1\" and b==\"1 1 0\" or (b==\"0 0 1\" and a==\"1 1 0\")):\n    print(\"NO\")\nelif(a==\"1 0 0\" and b==\"0 1 1\" or (b==\"1 0 0\" and a==\"0 1 1\")):\n    print(\"NO\")\nelse:\n    print(\"YES\")\n    ", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6"}
{"source_code": "#!/usr/bin/env python\n#-*- coding: utf-8 -*-\n\nfrom collections import defaultdict\nfrom math import factorial as f\nfrom fractions import gcd as g\n\ns = raw_input ()\nret, start = 0, 0\nfor i in s:\n    x = ord (i) - ord ('a')\n    y = min ((start - x) % 26, (x - start) % 26)\n    ret += y\n    start = x\nprint ret\n\n", "src_uid": "ecc890b3bdb9456441a2a265c60722dd"}
{"source_code": "n = int(input())\na = int(input())\nb = int(input())\nax, bx = 4, 2\nx = 0\nz = False\nif a*2+b < n//2:\n    print(1)\nelif a*2+b == n:\n    print(2)\nelif a >= b:\n    while ax >= 0 and bx >= 0:\n        if ax == bx == 0:\n            print(x)\n            exit()\n        for i in range(ax, -1, -1):\n            for j in range(bx, -1, -1):\n                # print(i ,j)\n                if (a*i)+(b*j) <= n:\n                    # print('yes')\n                    ax -= i\n                    bx -= j\n                    x += 1\n                    z = True\n                    break\n            if z:\n                z = not z\n                break\nelse:\n    while ax >= 0 and bx >= 0:\n        if ax == bx == 0:\n            print(x)\n            exit()\n        for i in range(bx, -1, -1):\n            for j in range(ax, -1, -1):\n                # print(i ,j)\n                if (a*j)+(b*i) <= n:\n                    # print('yes')\n                    ax -= j\n                    bx -= i\n                    x += 1\n                    z = True\n                    break\n            if z:\n                z = not z\n                break\n", "src_uid": "1a50fe39e18f86adac790093e195979a"}
{"source_code": "o=input()\nn=str()\nk=int()\nfor i in range(0,len(o)):\n    if o[i]!=' ':\n        n=n+o[i]\n        if i==(len(o)-1):\n            k=int(n)\n    else:\n        k=int(n)\n        n=str()\nz=input()\nb=str()\nv=[]\nt=int(0)\nh=int()\nfor i in range(0,len(z)):\n    if z[i]!=' ':\n        b=b+z[i]\n        if i==(len(z)-1):\n            v.append(int(b))\n    else:\n        v.append(int(b))\n        b=str()\nfor i in range(0,len(v)):\n    if (i+1)<=k and v[i]==0:\n        h=i\n        t=v[i-1]\n        break\n    if (i+1)==k:\n        h=k\n        t=v[i]\n        continue\n    if v[i]==t:\n        h=h+1\nif t>0:\n    print(h)\nelse:\n    print(0)", "src_uid": "193ec1226ffe07522caf63e84a7d007f"}
{"source_code": "def bits(i):\n    tmp = i\n    ans = 0\n    while tmp != 0:\n        if (tmp & 1) == 1:\n            ans += 1\n        tmp >>= 1\n    return ans\n\ndef get(i, j):\n    k = 0\n    while ((1<<k) & j) == 0:\n        k += 1\n\n    tj = j - (1<<k);\n    ti = i - (1<<k);\n    for p in xrange(N):\n        if g[k][p] == 0 or ((1<<p) & ti) == 0 or ((1<<p) & tj):\n            continue;\n        dp[i][j] += dp[ti][tj] + dp[ti][tj + (1<<p)];    \n\nN, M, K = map(int, raw_input().split())\n\nnp = 1 << N\ndp = [[0 for i in xrange(np)] for j in xrange(np)]\ng = [[0 for i in xrange(N)] for j in xrange(N)]\nfor i in xrange(M):\n    v, u = map(int, raw_input().split())\n    v -= 1\n    u -= 1\n    g[u][v] = 1\n    g[v][u] = 1\n    s = (1 << v) + (1 << u)\n    dp[s][s] = 1\n    \nfor i in xrange(np):\n    bs = bits(i)\n    if bs <= 2:\n        continue\n    j = i\n    while j != 0:\n        get(i, j)\n        j = (j - 1) & i\n        \nans = 0\nfor i in xrange(np):\n    if bits(i) == K:\n        ans += dp[np - 1][i]\n\nprint ans\n", "src_uid": "8087605a8f316150372cc4627f26231d"}
{"source_code": "n = int(input())\ntable = sorted(list(map(int, input().split())))\n\nsum = 0\nfor i in table:\n    sum += i\navg = sum/(n/2)\nif avg < (n/2 + 0.5):\n    pos = 1\nelse:\n    pos = 2\n\nsm = 0\nfor i in table:\n    sm += abs(i - pos)\n    pos += 2\n\nprint(sm)", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"}
{"source_code": "\n\nx = int(input())\nres = 0\ncount = 1\nfor i in range(0,x):\n    res += 2**count\n    count+=1\nprint(res)", "src_uid": "f1b43baa14d4c262ba616d892525dfde"}
{"source_code": "import sys,bisect as bi\ninput = sys.stdin.readline\nI = lambda : list(map(int,input().split()))\n\ndef anp(x,y):\n\tvd=[1,x]+([] if x%2 else [2,x//2])\n\tfor i in range(3,int(x**0.5)+1):\n\t\tif x%i==0:\n\t\t\tvd.append(i)\n\t\t\tif i!=x//i:\n\t\t\t\tvd.append(x//i)\n\tvd.sort()\n\tan=2*x+2*y+2\n\tfor i in range(len(dv)):\n\t\tcr=dv[i]\n\t\tp=bi.bisect(vd,cr)\n\t\tp-=1\n\t\tif (x+y)//cr>=x//vd[p]:\n\t\t\t#print(x,cr,(x+y)//cr,vd[p],x//vd[p])\n\t\t\tan=min(an,2*(cr+(x+y)//cr))\n\treturn an\n\na,b = I()\nx=a+b\ndv=[1,x]+([] if x%2 else [2,x//2])\nfor i in range(3,int(x**0.5)+1):\n\tif x%i==0:\n\t\tdv.append(i)\n\t\tif i!=x//i:\n\t\t\tdv.append(x//i)\nprint(min(anp(a,b),anp(b,a)))", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1"}
{"source_code": "import sys\ninput = sys.stdin.readline\ndef print(val):\n    sys.stdout.write(str(val) + '\\n')\ndef prog():\n    n,k = map(int,input().split())\n    s = input().strip()\n    t = input().strip()\n\n    num_first = [0]\n    num_second = [0]\n    for i in range(n):\n        num_first.append(num_first[-1] + (s[i] == t[0]))\n    for i in range(n):\n        num_second.append(num_second[-1] + (s[i] == t[1]))\n\n    if t[0] == t[1]:\n        most = min(num_first[n] + k, n)\n        print(most*(most-1)//2)\n        \n    else:\n        least = -10**6\n        dp = [[[least]*201 for j in range(201)] for i in range(200)]\n        \n        '''for i in range(n):\n                dp[i][0][num_first[i+1]] = '''\n        dp[0][s[0] == t[0]][0] = 0\n        dp[0][s[0] != t[0]][1] = 0\n        for loc in range(n - 1):\n            for changed in range(loc + 2):\n                '''\n                for num_f in range(loc + 1, -1,-1):\n                    if s[loc] == t[0]:\n                        dp[loc][changed][num_f + 1] = \\\n                        max(dp[loc][changed][num_f + 1],\\\n                        dp[loc][changed][num_f])\n                    elif s[loc] == t[1]:\n                        dp[loc][changed][num_f] = \\\n                        max(dp[loc][changed][num_f],\\\n                        dp[loc][changed][num_f] + (num_f))'''\n                        \n                for num_f in range(loc + 2):\n                    if s[loc + 1] != t[0]:\n                        dp[loc + 1][changed + 1][num_f + 1] = \\\n                        max(dp[loc + 1][changed + 1][num_f + 1],\\\n                        dp[loc][changed][num_f])\n                    \n                    if s[loc + 1] != t[1]:\n                        dp[loc + 1][changed + 1][num_f] = \\\n                        max(dp[loc + 1][changed + 1][num_f],\\\n                        dp[loc][changed][num_f] + (num_f))\n                        \n                    if s[loc + 1] == t[0]:\n                        dp[loc + 1][changed][num_f + 1] = \\\n                        max(dp[loc + 1][changed][num_f + 1],\\\n                        dp[loc][changed][num_f])\n                        \n                    if s[loc + 1] == t[1]:\n                        dp[loc + 1][changed][num_f] = \\\n                        max(dp[loc + 1][changed][num_f],\\\n                        dp[loc][changed][num_f] + (num_f))\n                        \n                    if s[loc + 1] != t[0] and s[loc + 1] != t[1]:\n                        dp[loc + 1][changed][num_f] = \\\n                        max(dp[loc + 1][changed][num_f],\\\n                        dp[loc][changed][num_f])\n\n        mx = 0\n        for loc in range(n):\n            for changed in range(k + 1):\n                for num_f in range(n + 1):\n                    #print(loc, changed, num_f, dp[loc][changed][num_f])\n                    mx = max(mx, dp[loc][changed][num_f])\n                    \n        print(mx)\n                             \nprog()\n", "src_uid": "9c700390ac13942cbde7c3428965b18a"}
{"source_code": "n, k = [int(i) for i in input().split()]\n\nfor i in range(k - 1, 0, -1):\n    if (n % i) == 0:\n        first = n // i\n        print(first * k + i)\n        exit(0)", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57"}
{"source_code": "'''\nCreated on 23.06.2012\n\n@author: Admin\n'''\nimport math\n\ndef is_in_range(x, r):\n    return x < r and x > -r\n\ndef calc_position (x1, x2, r):\n    dotyk = int(abs(x1) == abs(r)) + int (abs(x2) == abs(r))\n    inside = int(is_in_range(x1, r)) + int(is_in_range(x2, r))\n    outside = 2 - inside - dotyk\n    \n    return [inside, outside, dotyk]\n    \n\ndef is_full_circle(dist, r, r1, R1):\n    points = [dist - r1, dist + r1, dist - R1, dist + R1]\n    \n    #print dist, r, r1, R1\n    if (r < dist) :\n        # Center is outside our circle\n        if dist - r >= R1 :\n            return 1\n        if (r1 >= dist + r) :\n            return 1\n        \n        return 0\n        pass\n    \n    # center is inside our circle\n    if (dist + R1 <= r) :\n        return 1\n    \n    if (dist + r <= r1) :\n        return 1\n    \n    return 0\n    \n    #print r, points\n    \n    #small = calc_position(dist - r1, dist + r1, r)\n    #large = calc_position(dist - R1, dist + R1, r)\n    #res = map(lambda x , y: x + y, small, large)\n    \n    #return int(res[0] == 0 or res[1] == 0)\n    #return int(calc_position(dist - r1, dist + r1, r) and calc_position(dist - R1, dist + R1, r))\n    pass\n   \nif __name__ == '__main__':\n    #print \"Hello, world!\"\n    #fibs = fib_til_n(50)\n    #fibs2 = [(x, y, z) for x in fibs for y in fibs for z in fibs]\n    #print fibs2\n    #split_n_to_fibs(50, fibs2)\n    #x = map(float, raw_input().split(' '))\n    #print x\n    x1, y1, r1, R1 = map(int, raw_input().split(' '))\n    x2, y2, r2, R2 = map(int, raw_input().split(' '))\n    #r1 *= r1\n    #R1 *= R1\n    #r2 *= r2\n    #R2 *= R2\n    dist = math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))\n    #print dist\n    res = 0\n    res += is_full_circle(dist, r2, r1, R1)\n    #print res\n    res += is_full_circle(dist, R2, r1, R1)\n    #print res\n    res += is_full_circle(dist, r1, r2, R2)\n    #print res\n    res += is_full_circle(dist, R1, r2, R2)\n    print res", "src_uid": "4c2865e4742a29460ca64860740b84f4"}
{"source_code": "a,b = input().split()\na = int(a)\nans = \"\"\na += 1\ntemp = a\nwhile str(temp) != b:\n\tb1 = str(a)\n\ttemp = \"\"\n\tfor i in range(len(b1)):\n\t\tif b1[i] == '7' or b1[i] == '4':\n\t\t\ttemp += b1[i]\n\ta += 1\n\nprint(a-1)\n", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb"}
{"source_code": "'''n=int(input())\nv=n%7\nif v==0:\n    print((n//7)*2,(n//7)*2)\nelif v==1:\n    print((n//7)*2,(n//7)*2+1)\nelif v==6:\n    print((n//7)*2+1,(n//7)*2+2)\nelse:\n    print((n//7)*2,(n//7)*2+2)\ns=input()\nt=input()\nf='aeiou'\nif len(s)!=len(t):\n    print('No')\nelse:\n    for i in range(len(s)):\n        if f.find(s[i])==-1 and f.find(t[i])==-1:\n            pass\n        elif f.find(s[i])!=-1 and f.find(t[i])!=-1:\n            pass\n        else:\n            print('No')\n            break\n    else:\n        print('Yes')\nm=int(input())\nn=input().split()\nfor i in range(m):\n    n[i]=int(n[i])\nn.sort()\nif len(n)%2==0:\n    print(n[m//2-1])\nelse:\n    print(n[m//2])\na=input()\nb=input().split()\nc=0\nd=0\nfor i in b:\n    c+=int(i)\nx=c%2\nif x==0:\n    for i in b:\n        if int(i)%2==0:\n            d+=1\nelse:\n    for i in b:\n        if int(i)%2==1:\n            d+=1\nprint(d)\nn=int(input())\nA=input().split()\nm=int(input())\nB=input().split()\nfor i in range(n):\n    A[i]=int(A[i])\nfor i in range(m):\n    B[i]=int(B[i])\nA.sort()\nB.sort()\nprint(int(A[n-1]),int(B[m-1]))\nn=input()\nc=1\nt=0\nfor i in n:\n    if i in'AEIOUY':\n        if t<c:\n            t=c\n        c=1\n    else:\n        c+=1\nif t<c:\n    t=c\nprint(t)\na=int(input())\nb=int(input())\nc=int(input())\nn=[]\nn.append(a)\nn.append(b//2)\nn.append(c//4)\nn.sort()\nprint(n[0]*7)\nfrom math import ceil\na=[int(i) for i in input().split()]\nb=[int(i) for i in input().split()]\ns=0\nd=0\nfor i in range(a[0]):\n    if ceil(b[i]/a[1])>=s:\n        s=ceil(b[i]/a[1])\n        d=i\nprint(d+1)'''\nf=input().split()\nm=int(f[1])\nn=int(f[0])\nd=0\nif (m/n)%2!=0 and (m/n)%3!=0 and m!=n:\n    print(-1)\nelse:\n    while m!=n:\n        if m/n%2==0:\n            m/=2\n            d+=1\n        elif m/n%3==0:\n            m/=3\n            d+=1\n        else:\n            print(-1)\n            break\n    else:\n        print(d)\n'''\nn=input().split()\ns=int(n[0])\nd=int(n[1])\nv=input()\nc=111111111111111111111111111111111111111111111111111111111111111111111111\nfor i in range(v):\n    i=input().split()\n    if c<=abs((int(i[0])-s+int(i[1])-d)/v):\n        c=abs((int(i[0])-s+int(i[1])-d)/v)\nprint(c)'''\n   \n    \n        \n\n    \n\n\n        \n\n\n    \n", "src_uid": "3f9980ad292185f63a80bce10705e806"}
{"source_code": "#!/usr/bin/env python2\nfrom __future__ import print_function\n\nimport os\nimport sys\nfrom atexit import register\nfrom io import BytesIO\n\nsys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))\nsys.stdout = BytesIO()\nregister(lambda: os.write(1, sys.stdout.getvalue()))\n\ninput = lambda: sys.stdin.readline().rstrip('\\r\\n')\nrange = xrange\n\n\ndef main():\n    def mat_mul(A, B, MOD):\n        n, p = len(A), len(B[0])\n        MODF = float(MOD)\n\n        B = [[(Bi[j] & (2**16 - 1)) + 1j * (Bi[j] >> 16) for j in range(n)] for Bi in B]\n        C = [[0] * p for _ in range(n)]\n\n        for i, Ai in enumerate(A):\n            row = [0.0] * p\n            for k, Bk in enumerate(B):\n                Aik = Ai[k] + 1j * ((Ai[k] << 16) % MOD)\n                for j, Bkj in enumerate(Bk):\n                    row[j] += Aik.real * Bkj.real + Aik.imag * Bkj.imag\n\n            C[i] = [int(j % MODF) for j in row]\n\n        return C\n\n    n, m = map(int, input().split())\n\n    mat = [[0] * m for _ in range(m)]\n    mat[0][0] = 1\n    mat[-1][0] = 1\n    for i in range(m - 1):\n        mat[i][i + 1] = 1\n\n    vec = [[1] * m]\n\n    for i in bin(n)[:1:-1]:\n        if i == '1':\n            vec = mat_mul(mat, vec, 1000000007)\n        mat = mat_mul(mat, mat, 1000000007)\n\n    print(vec[0][-1])\n\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "e7b9eec21d950f5d963ff50619c6f119"}
{"source_code": "a,b,n = map(int,input().split())\nm =1000000007\nfact = [1]\n\nfor i in range(1,n+1):\n    fact.append((fact[-1]*i)%m)\nans = 0\nfor i in range(n+1):\n    su = (a*i) + b*(n-i)\n    coef = 1\n    while(su>0):\n        if(su%10 != a and su%10!=b):\n            coef = 0;\n        su//=10\n    if coef:\n        ans+=(fact[n]*pow((fact[i]*fact[n-i]),m-2,m))\n        ans= ans%m\nprint(ans%m)\n    \n    ", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81"}
{"source_code": "string = input()\nnumbers = string.split()\na, b = int(numbers[0]), int(numbers[1])\nn = a % b\nwhile b % 2 == 0:\n    b //= 2\nif n % b == 0:\n    print(\"Yes\")\nelse:\n    print(\"No\")", "src_uid": "f726133018e2149ec57e113860ec498a"}
{"source_code": "x = raw_input()\n\nif x[0] != '-':\n    print str(x)\nelse:\n    c1 = x[:-1]\n    c2 = x[:-2]+x[-1:]\n    print max(int(c1), int(c2))\n", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"}
{"source_code": "n,m=[int(x) for x in input().split()]\nif(m==n and n==1):\n    print(1)\nelif(m>n/2):\n    print(m-1)\nelse:\n    print(m+1)\n", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7"}
{"source_code": "def subt(num):\n    if num % 10 != 0:\n        return num -1\n    else:\n        return num // 10\n\ninp = str(input())\ninp = inp.split(\" \")\nn = int(inp[0])\nk = int(inp[1])\n\nfor i in range(k):\n    n = subt(n)\nprint(n)\n", "src_uid": "064162604284ce252b88050b4174ba55"}
{"source_code": "n,m,i,a=map(int,raw_input().split())\nt=map(int,raw_input().split())\nr=[i,a]\nans=['Incorrect','Correct']\nchk=1\nwhile 1:\n    if i in t:\n        t.remove(i)\n        m-=1\n    elif a in t:\n        t.remove(a)\n        m-=1\n    else:\n        break\nn-=2\nif n<m:\n    print ans[0]\n    exit()\nfor x in t:\n    if x not in r:\n        if n>0 and i<=x<=a:\n            r.append(x)\n        else:\n            chk=0\n    n-=1\nprint ans[chk]", "src_uid": "99f9cdc85010bd89434f39b78f15b65e"}
{"source_code": "n = int ( input() )\na = list ( map ( int , input().split() ) )\nsum = 0\nfor i in range( 0 , n ):\n    if ( a[i] < 0 ):\n        sum -= a[i]\n    else:\n        sum += a[i]\nprint(sum)        \n", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5"}
{"source_code": "def main():\n    a =[]\n    for i in range(3):\n        a.append(list(map(int,raw_input().split())))\n    a[0][0] = int((a[1][2] + a[2][1])/2)\n    a[2][2] = int((a[0][1] + a[1][0])/2)\n    a[1][1] = int((a[0][1] + a[2][1])/2)\n    for i in range(3):\n        print(' '.join([str(x) for x in a[i]]))\n\nmain()", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca"}
{"source_code": "import sys\nfrom math import *\n\ndef minp():\n\treturn sys.stdin.readline().strip()\n\nn = int(minp())\nm = [None]*n\nk = [None]*3\ndp = [None]*3\ndp[0] = [None]*(n*n)\ndp[1] = [None]*(n*n)\ndp[2] = [None]*(n*n)\npath = [None]*(n*n)\nfor i in range(n):\n\tm[i] = list(map(int, minp().split()))\n\tfor j in range(n):\n\t\tpath[m[i][j]-1] = (i,j)\nfor z in range(3):\n\tk_ = [None]*n\n\tfor i in range(n):\n\t\tkk = [None]*n\n\t\tfor j in range(n):\n\t\t\tkkk_ = [None]*3\n\t\t\tfor zz in range(3):\n\t\t\t\tkkk = [None]*n\n\t\t\t\tfor w in range(n):\n\t\t\t\t\tkkk[w] = [(1000000,0)]*n\n\t\t\t\tkkk_[zz] = kkk\n\t\t\tkk[j] = kkk_\n\t\tk_[i] = kk\n\tk[z] = k_\n\nq = [0]*(10*n*n)\nqr = 0\nkm = [(1,2),(1,-2),(-1,2),(-1,-2),(2,1),(2,-1),(-2,1),(-2,-1)]\nsm = [(1,1),(1,-1),(-1,1),(-1,-1)]\nlm = [(0,1),(0,-1),(-1,0),(1,0)]\nmm = [km,sm,lm]\nfor z in range(3):\n\tfor i in range(n):\n\t\tfor j in range(n):\n\t\t\t#print('========')\n\t\t\tql = 0\n\t\t\tqr = 1\n\t\t\tq[0] = (z, i, j, (0,0))\n\t\t\tkc = k[z][i][j]\n\t\t\tkc[z][i][j] = (0, 0)\n\t\t\twhile ql < qr:\n\t\t\t\tt, x, y, dd = q[ql]\n\t\t\t\t#print(t,x,y,dd)\n\t\t\t\td = kc[t][x][y]\n\t\t\t\tql += 1\n\t\t\t\tif d != dd:\n\t\t\t\t\tcontinue\n\t\t\t\tdd = (d[0]+1, d[1]+1)\n\t\t\t\tfor tt in range(3):\n\t\t\t\t\tif t != tt and kc[tt][x][y] > dd:\n\t\t\t\t\t\tkc[tt][x][y] = dd\n\t\t\t\t\t\tq[qr] = (tt,x,y,dd)\n\t\t\t\t\t\tqr += 1\n\t\t\t\tdd = (d[0]+1,d[1])\n\t\t\t\tif t == 0:\n\t\t\t\t\tfor w in mm[t]:\n\t\t\t\t\t\txx,yy = w[0]+x,w[1]+y\n\t\t\t\t\t\tif xx >= 0 and xx < n and yy >= 0 and yy < n:\n\t\t\t\t\t\t\tif kc[t][xx][yy] > dd:\n\t\t\t\t\t\t\t\tkc[t][xx][yy] = dd\n\t\t\t\t\t\t\t\tq[qr] = (t,xx,yy,dd)\n\t\t\t\t\t\t\t\tqr += 1\n\t\t\t\telse:\n\t\t\t\t\tfor w in mm[t]:\n\t\t\t\t\t\tfor hm in range(n*2):\n\t\t\t\t\t\t\txx,yy = w[0]*hm+x,w[1]*hm+y\n\t\t\t\t\t\t\tif xx >= 0 and xx < n and yy >= 0 and yy < n:\n\t\t\t\t\t\t\t\tif kc[t][xx][yy] > dd:\n\t\t\t\t\t\t\t\t\tkc[t][xx][yy] = dd\n\t\t\t\t\t\t\t\t\tq[qr] = (t,xx,yy,dd)\n\t\t\t\t\t\t\t\t\tqr += 1\n\t\t\t\t\t\t\telse:\n\t\t\t\t\t\t\t\tbreak\ndp[0][0] = (0,0)\ndp[1][0] = (0,0)\ndp[2][0] = (0,0)\nfor i in range(0,n*n-1):\n\tx,y = path[i]\n\txx,yy = path[i+1]\n\tfor z in range(3):\n\t\tfor j in range(3):\n\t\t\tdist = k[j][x][y][z][xx][yy]\n\t\t\tif dp[j][i] != None:\n\t\t\t\tnd = (dp[j][i][0]+dist[0],dp[j][i][1]+dist[1])\n\t\t\t\tif dp[z][i+1] == None:\n\t\t\t\t\tdp[z][i+1] = nd\n\t\t\t\telse:\n\t\t\t\t\tdp[z][i+1] = min(dp[z][i+1],nd)\nfor j in range(n*n-1,n*n):\n\tqq = [dp[i][j] if dp[i][j] != None else (1000000,0) for i in range(3)]\n\tqm = min(qq)\n\t#print(j,qm)\n\tprint(qm[0], qm[1])", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd"}
{"source_code": "import  sys\ninput=sys.stdin.readline\ndp={}\nmod=int(1000000007)\nsys.setrecursionlimit(100000)\ndef bigmod(n,p):\n    n,p=int(n),int(p)\n    if p==0:\n        return 1\n    x=bigmod(n,p/2)\n    x=(x*x)%mod\n    if p%2==1:\n        x=(x*n)%mod\n    return x\nk,pa,pb=map(int,input().split())\nr=bigmod(pa+pb,mod-2)\nr1=bigmod(pb,mod-2)\nr1=(pa*r1)%mod\np=(pa*r)%mod\nq=(pb*r)%mod\n\n\n\ndef cal(k1,a1):\n    if k1+a1>=k:\n        return (k1+a1+r1)%mod\n    if (k1,a1) in dp:\n        return dp[(k1,a1)]\n    dp[(k1,a1)]=((cal(k1+a1,a1)*q)%mod+(cal(k1,a1+1)*p)%mod)%mod\n    return dp[(k1,a1)]\n\nprint(cal(0,1))\n\n", "src_uid": "0dc9f5d75143a2bc744480de859188b4"}
{"source_code": "import sys\n\ndef input():    return sys.stdin.readline().strip()\ndef iinput():   return int(input())\ndef rinput():   return map(int, sys.stdin.readline().strip().split()) \ndef get_list(): return list(map(int, sys.stdin.readline().strip().split())) \n\n\nn = iinput()\na = list(map(int,input().split()))\na.sort()\na[-1],a[0]=a[0],a[-1]\nprint(*a)", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4"}
{"source_code": "import fileinput;\n\nstr = input();\nsstr = str.split(' ')\na,b,w,x,c = int(sstr[0]),int(sstr[1]),int(sstr[2]),int(sstr[3]),int(sstr[4])\n\ndif = c-a\n\nup = max(0,int((dif*x-b)/(w-x)))\nb = b+up*(w-x)\n\ncount = up\nwhile dif > 0:\n    if (b >= x):\n        factor = min(int((b - x)/x)+1,dif)\n        dif = dif-factor\n        b = b - x*factor\n    else:\n        factor = int( (x-b-1)/(w-x) )+1\n        b = factor*(w-x)+b\n        count = count+factor\n\nprint(count+(c-a))\n", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143"}
{"source_code": "from random import*\nimport sys\nsys.setrecursionlimit(10000)\nopr = ['#', '^', '&', '$']\nnamespace = { \"res\" : (False, \"res\") }\nrules = dict()\nlookup = dict()\ncnt = -1\ndef get_tag(var):\n    if var in namespace:\n        return namespace[var][1]\n    else:\n        return var\nN = int(raw_input())\nfor _ in range(N):\n    lval, rval = raw_input().split('=')\n    for c in opr:\n        if c in rval:\n            arg1, arg2 = map(get_tag, rval.split(c))\n            rule = (arg1, arg2, c)\n            if rule in rules:\n                namespace[lval] = (True, rules[rule])\n            else:\n                cnt += 1\n                namespace[lval] = (True, cnt)\n                rules[rule] = cnt\n                lookup[cnt] = rule\n            break\n    else:\n        if rval in namespace:\n            namespace[lval] = namespace[rval]\n        else:\n            namespace[lval] = (False, rval)\nif namespace[\"res\"] == (False, \"res\"):\n    print(\"0\")\n    exit()\nprogram = []\nmyvars = dict()\ndef reserve():\n    return ''.join(chr(randint(0, 25) + ord('a')) for _ in range(4)) \ndef implement(rule, final):\n    if type(rule) == str:\n        return rule\n    elif rule in myvars:\n        return myvars[rule]\n    else:\n        if final:\n            name = \"res\"\n        else:\n            name = reserve()\n        myvars[rule] = name\n        arg1, arg2, op = lookup[rule]\n        var1, var2 = implement(arg1, False), implement(arg2, False)\n        program.append(name + \"=\" + var1 + op + var2)\n        return name\nseed(123)\nif namespace[\"res\"][0]:\n    implement(namespace[\"res\"][1], True)\nelse:\n    program.append(\"res=\" + namespace[\"res\"][1])\nprint(len(program))\nprint(\"\\n\".join(program))", "src_uid": "da40321d92baaef42c2840e45599294c"}
{"source_code": "#########\t\t\t##\t##     ##    \t  ####  #####  ##     #  ##     #\t\t##\n\t#\t\t\t   # #\t# #   # #\t\t #\t  #\t#\t#  # #    #  # #    #\t   # #\n\t#\t\t\t  #  #\t#  ###  #\t    #\t\t#\t#  #  #   #  #  #   #\t  #  #\n\t#\t\t\t #####\t#\t#\t#\t   #    ###\t#\t#  #   #  #  #   #  #    #####\n\t#\t\t\t#    #\t#\t\t#\t   #    # #\t#\t#  #\t# #  #\t  # #   #    #  \n######### \t   #     # \t#\t\t#\t\t##### #\t#####  #\t ##  #\t   ##  #     #\n\n\"\"\"\n\nPPPPPPP       RRRRRRR\t\t    OOOO\t  VV        VV    EEEEEEEEEE\nPPPPPPPP      RRRRRRRR         OOOOOO     VV       VV\t  EE\nPPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV\t  EE\nPPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    \t  EEEEEE\nPPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE\nPP  \t\t  RRRR\t\t\t  OOOOOOOO    VV   VV         EEEEEE\nPP\t\t\t  RR  RR          OOOOOOOO    VV  VV          EE\nPP\t\t\t  RR    RR         OOOOOO     VV VV           EE\nPP\t\t\t  RR      RR        OOOO      VVVV            EEEEEEEEEE\n\n\"\"\"\n\n\n\n\"\"\"\n Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.\n\"\"\"\nimport sys\ninput = sys.stdin.readline\n# from bisect import bisect_left as lower_bound;\n# from bisect import bisect_right as upper_bound;\n# from math import ceil, factorial;\n \ndef ceil(x):\n    if x != int(x):\n        x = int(x) + 1\n    return x\n \ndef factorial(x, m):\n\tval = 1\n\twhile x>0:\n\t\tval = (val * x) % m\n\t\tx -= 1\n\treturn val\n\ndef fact(x):\n\tval = 1\n\twhile x > 0:\n\t\tval *= x\n\t\tx -= 1\n\treturn val\n    \n# swap_array function\ndef swaparr(arr, a,b):\n    temp = arr[a];\n    arr[a] = arr[b];\n    arr[b] = temp;\n \n## gcd function\ndef gcd(a,b):\n    if b == 0:\n        return a;\n    return gcd(b, a % b);\n\n## lcm function\ndef lcm(a, b):\n\treturn (a * b) // gcd(a, b)\n \n## nCr function efficient using Binomial Cofficient\ndef nCr(n, k): \n\tif k > n:\n\t\treturn 0\n\tif(k > n - k):\n\t\tk = n - k\n\tres = 1\n\tfor i in range(k):\n\t\tres = res * (n - i)\n\t\tres = res / (i + 1)\n\treturn int(res)\n \n## upper bound function code -- such that e in a[:i] e < x;\ndef upper_bound(a, x, lo=0, hi = None):\n    if hi == None:\n        hi = len(a);\n    while lo < hi:\n        mid = (lo+hi)//2;\n        if a[mid] < x:\n            lo = mid+1;\n        else:\n            hi = mid;\n    return lo;\n \n## prime factorization\ndef primefs(n):\n    ## if n == 1    ## calculating primes\n    primes = {}\n    while(n%2 == 0 and n > 0):\n        primes[2] = primes.get(2, 0) + 1\n        n = n//2\n    for i in range(3, int(n**0.5)+2, 2):\n        while(n%i == 0 and n > 0):\n            primes[i] = primes.get(i, 0) + 1\n            n = n//i\n    if n > 2:\n        primes[n] = primes.get(n, 0) + 1\n    ## prime factoriazation of n is stored in dictionary\n    ## primes and can be accesed. O(sqrt n)\n    return primes\n \n## MODULAR EXPONENTIATION FUNCTION\ndef power(x, y, p): \n    res = 1\n    x = x % p  \n    if (x == 0) : \n        return 0\n    while (y > 0) : \n        if ((y & 1) == 1) : \n            res = (res * x) % p \n        y = y >> 1      \n        x = (x * x) % p \n    return res \n \n## DISJOINT SET UNINON FUNCTIONS\ndef swap(a,b):\n    temp = a\n    a = b\n    b = temp\n    return a,b;\n \n# find function with path compression included (recursive)\n# def find(x, link):\n#     if link[x] == x:\n#         return x\n#     link[x] = find(link[x], link);\n#     return link[x];\n \n# find function with path compression (ITERATIVE)\ndef find(x, link):\n    p = x;\n    while( p != link[p]):\n        p = link[p];\n    \n    while( x != p):\n        nex = link[x];\n        link[x] = p;\n        x = nex;\n    return p;\n \n \n# the union function which makes union(x,y)\n# of two nodes x and y\ndef union(x, y, link, size):\n    x = find(x, link)\n    y = find(y, link)\n    if size[x] < size[y]:\n        x,y = swap(x,y)\n    if x != y:\n        size[x] += size[y]\n        link[y] = x\n \n## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES\ndef sieve(n): \n    prime = [True for i in range(n+1)] \n    prime[0], prime[1] = False, False\n    p = 2\n    while (p * p <= n): \n        if (prime[p] == True): \n            for i in range(p * p + p, n+1, p):\n                prime[i] = False\n        p += 1\n    return prime\n \n#### PRIME FACTORIZATION IN O(log n) using Sieve ####\nMAXN = int(1e5 + 5)\ndef spf_sieve():\n    spf[1] = 1;\n    for i in range(2, MAXN):\n        spf[i] = i;\n    for i in range(4, MAXN, 2):\n        spf[i] = 2;\n    for i in range(3, ceil(MAXN ** 0.5), 2):\n        if spf[i] == i:\n            for j in range(i*i, MAXN, i):\n                if spf[j] == j:\n                    spf[j] = i;\n    ## function for storing smallest prime factors (spf) in the array\n \n################## un-comment below 2 lines when using factorization #################\nspf = [0 for i in range(MAXN)]\n# spf_sieve();\ndef factoriazation(x):\n    res = []\n    for i in range(2, int(x ** 0.5) + 1):\n    \twhile x % i == 0:\n    \t\tres.append(i)\n    \t\tx //= i\n    if x != 1:\n   \t\tres.append(x)\n    return res\n    ## this function is useful for multiple queries only, o/w use\n    ## primefs function above. complexity O(log n)\n \n## taking integer array input\ndef int_array():\n    return list(map(int, input().strip().split()));\n \ndef float_array():\n    return list(map(float, input().strip().split()));\n \n## taking string array input\ndef str_array():\n    return input().strip().split();\n \n#defining a couple constants\nMOD = int(1e9)+7;\nCMOD = 998244353;\nINF = float('inf'); NINF = -float('inf');\n \n################### ---------------- TEMPLATE ENDS HERE ---------------- ###################\n \nfrom itertools import permutations\nimport math\n\nfrom bisect import bisect_left\n\n\ndef solve():\n\tn = int(input())\n\tc = 1\n\tfor i in range(3, n - 1):\n\t\tif math.gcd(i, n - 1) == 1:\n\t\t\tc += 1\n\tprint(c)\n\n\n\n\nif __name__ == '__main__':\n\tfor _ in range(1):\n\t\tsolve()\n\t# fin_time = datetime.now()\n# \tprint(\"Execution time (for loop): \", (fin_time-init_time))\n", "src_uid": "3bed682b6813f1ddb54410218c233cff"}
{"source_code": "n = int(input().strip())\r\n\r\na = {}\r\ntemp = {}\r\n\r\n\r\ndef decom(i):\r\n    if i == 0:\r\n        return 0\r\n    if i == 1:\r\n        return 1\r\n    if i in a.keys():\r\n        return a[i]\r\n    if i in temp:\r\n        return decom(i - lower(i)[0]) + lower(i)[1]\r\n    else:\r\n        temp[i] = 0\r\n        k = min(decom(i - lower(i)[0]) + lower(i)[1], decom(upper(i)[0] - i) + upper(i)[1])\r\n        a[i] = k\r\n        return k\r\n\r\n\r\n\r\ndef upper(i):\r\n    d = 1\r\n    n = 1\r\n    while d < i:\r\n        d = d * 10 + 1\r\n        n += 1\r\n    return (d, n)\r\n\r\n\r\ndef lower(i):\r\n    if (upper(i)[0] - 1) // 10 == 0:\r\n        return (1, 1)\r\n    return ((upper(i)[0] - 1) // 10, upper(i)[1] - 1)\r\n\r\n\r\nprint(decom(n))\r\n", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907"}
{"source_code": "print(sum([i*(i+1) for i in range(2,int(input()))]))\n", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"}
{"source_code": "a, b = map(int, raw_input().split())\nif a == b:\n  print 'infinity'\nelif a < b:\n  print 0\nelse:\n  a -= b\n  i = 1\n  ans = 0\n  while i*i <= a:\n    if a % i == 0:\n      if i > b:\n        ans += 1\n      if a/i > b and i*i != a:\n        ans += 1\n    i += 1\n  print ans\n", "src_uid": "6e0715f9239787e085b294139abb2475"}
{"source_code": "a = raw_input().split()\nx = int(a[0])\ny = int (a[1])\nres=x/y\nif (res%2==0):\n    print \"NO\"\nelse:\n    print \"YES\"\n", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50"}
{"source_code": "a,b = input().split(\" \")\n\na,b = int(a),int(b)\n\nc=a-b\n\nif(a%c == 0 and b%c == 0):\n\n    print(\"Equal\")\n\nelif(a>b):\n\n    print(\"Masha\")\n\nelse:\n\n    print(\"Dasha\")\n\n\n\n# Made By Mostafa_Khaled", "src_uid": "06eb66df61ff5d61d678bbb3bb6553cc"}
{"source_code": "a,b,c,d,k = map(int,raw_input().split())\n\nif max(a,c) <= min(b,d):\n\tans = min(b,d)-max(a,c)+ 1\n\tif k >= max(a,c) and k <= min(b,d):\n\t\tans -= 1\n\tprint ans\nelse:\n\tprint 0", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82"}
{"source_code": "from collections import Counter\nfrom math import log2, ceil\n\nMAX = ceil(log2(10 ** 12))\n\n\ndef can():\n    seqs_cp = Counter(seqs)\n    for num in set(nums):\n        cnt = nums[num]\n        while cnt != 0 and num < 2 ** 63:\n            dif = min(cnt, seqs_cp[num])\n            cnt -= dif\n            seqs_cp[num] -= dif\n            num *= 2\n        if cnt > 0:\n            return False\n    return True\n\n\nn = int(input())\n\nseq = list(map(int, input().split()))\ncnt = Counter(seq)\nnums = Counter(seq)\n\nseqs = Counter()\ncur_cnt = cnt[1]\ncur_pow = 1\nwhile cur_cnt != 0:\n    nums[cur_pow] -= cur_cnt\n    cur_pow *= 2\n    if cur_cnt > cnt[cur_pow]:\n        seqs[cur_pow // 2] = cur_cnt - cnt[cur_pow]\n        cur_cnt = cnt[cur_pow]\n\nfor num in set(nums):\n    addition = nums[num]\n    nums[num] = 0\n    nums[2 ** int(log2(num))] += addition\n\n# remove elements with zero count\nnums -= Counter()\nseqs -= Counter()\n\ncur_len = sum(seqs[num] for num in set(seqs))\nres = []\ncur_pow = 1\n\nwhile can():\n    res.append(cur_len)\n    while seqs[cur_pow] == 0 and cur_pow <= 2 ** 63:\n        cur_pow *= 2\n    if cur_pow > 2 ** 63:\n        break\n    other_pow = 1\n    while other_pow <= cur_pow:\n        nums[other_pow] += 1\n        other_pow *= 2\n    seqs[cur_pow] -= 1\n    cur_len -= 1\n\nprint(-1 if len(res) == 0 else ' '.join(map(str, reversed(res))))\n", "src_uid": "fc29e8c1a9117c1dd307131d852b6088"}
{"source_code": "n,m=map(int,input().split())\na=[int(i) for i in input().split()]\nx,y=set(),set()\ndef f(x,n,i,s=0):\n    if i==n:x.add(s%m)\n    else:\n        f(x,n,i+1,s+a[i])\n        f(x,n,i+1,s)\nh=n//2\nf(x,h,0)\nf(y,n,h)\ny=sorted(y)\nimport bisect\nk=0\nprint(max(i+y[bisect.bisect_left(y,m-i)-1]for i in x))\n", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a"}
{"source_code": "import math\n\n\ndef check(score):\n    k = (score // 50) % 475\n    for i in range(25):\n        k = (k * 96 + 42) % 475\n        if 26 + k == p:\n            return True\n    return False\n\np, x, y = map(int, input().split())\n\nt = math.ceil((y - x) / 50)\n\nif p <= 25:\n    print(t)\nelse:\n    while not check(x + 50 * t):\n        t += 1\n    print(max(0, (t + 1) // 2))", "src_uid": "c9c22e03c70a94a745b451fc79e112fd"}
{"source_code": "import sys, math\ninput = sys.stdin.readline\n\nn, k = map(int, input().split())\nif k == 1:\n    print(n)\nelse:\n    msb = len(bin(n))-2\n    ans = 1<<msb\n    print(ans-1)", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9"}
{"source_code": "import random\nimport sys\nrandom.seed(12345)\n\nn, m = map(int, raw_input().split())\nbad = set([tuple(map(int, raw_input().split())) for _ in range(m)])\nitems = range(1, n+1)\n\nfor _ in range(100000):\n  random.shuffle(items)\n  fail = False\n  for i in range(m):\n    if (items[i], items[i-1]) in bad or (items[i-1], items[i]) in bad:\n      fail = True\n      break\n  if not fail:\n    for i in range(m):\n      print items[i], items[i-1]\n    sys.exit(0)\n\nprint -1\n", "src_uid": "c4c85cde8a5bb5fefa4eb68fc68657d5"}
{"source_code": "def g():\n    return map(int,raw_input().split())\na,b=g()\nc,d=g()\ne,f=g()\nz,r,i=f*f+e*e,0,4\nwhile i:\n    i-=1\n    a,b=b,-a\n    x,y=c-a,d-b\n    r |= (z==0 and x==0 and y==0) | (z and (x*e+y*f)%z==0 and (y*e-x*f)%z==0)\nprint \"YES\" if r else \"NO\"", "src_uid": "cc8a8af1ba2b19bf081e379139542883"}
{"source_code": "a=int(input())\nb=int(input())\nn=(a+b)//2\nl=abs(a-n)\nr=abs(b-n)\ncount=0\nfor x in range(1,l+1):\n    count=count+x\nfor y in range(1,r+1):\n    count=count+y\nprint(count)\n", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da"}
{"source_code": "MOD=int(1e9+7)\nn,k=map(int,input().split())\nif k<2:p=n-(1-k)\nelse:\n\tt=1\n\ta=k\n\twhile a!=1:\n\t\ta=a*k%n\n\t\tt+=1\n\tp=(n-1)//t\nprint(pow(n,p,MOD))\n\n", "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e"}
{"source_code": "n = input()\nr = len(n)\nans = 2**r - 2\nk = 2**r\nfor i in n:\n\tif i == \"7\":\n\t\tif k == 2:\n\t\t\tans += k\n\t\telse:\n\t\t\tans+=(k//2)\n\telse:\n\t\tif k==2:\n\t\t\tans+=1\n\tk //= 2\nprint(ans)", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"}
{"source_code": "a,b,c=map(int,raw_input().split())\nM=998244353\ndef C(x, y):\n\tz,t=0, 1\n\tfor i in range(min(x,y)+1):\n\t\tz=(z+t)%M\n\t\tt=t*(x-i)*(y-i)*pow(i+1,M-2,M)%M\n\treturn z\nprint C(a,b)*C(a,c)*C(b,c)%M\n", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383"}
{"source_code": "#!/usr/bin/env python3\n\nimport os\nfrom io import BytesIO\n\n\ndef main():\n    n, m = map(int, input().split())\n    k = [int(x) for x in input().split()]\n\n    d = [[] for _ in range(200000)]\n    for j in range(m):\n        dj, tj = map(int, input().split())\n        d[dj - 1].append(tj - 1)\n\n    lo, hi = 0, 400000\n    while lo < hi:\n        mi = (hi + lo) // 2\n        cash = mi\n        offset = 0\n\n        _k = k[:]\n        for i in reversed(range(mi)):\n            if i < 200000:\n                for j in d[i]:\n                    while cash and _k[j]:\n                        _k[j] -= 1\n                        cash -= 1\n            if cash == i + 1:\n                cash -= 2\n                offset += 1\n\n        if 2 * (sum(_k) - offset) <= cash:\n            hi = mi\n        else:\n            lo = mi + 1\n\n    os.write(1, str(lo).encode())\n\n\ninput = BytesIO(os.read(0, os.fstat(0).st_size)).readline\nmain()\n", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d"}
{"source_code": "n=input()\ns='1'\nfor i in range(375):\n    s = s + str(i)\n\nprint(s[n+1])\n", "src_uid": "2d46e34839261eda822f0c23c6e19121"}
{"source_code": "def horseshoe(n):\n    colors = set(n)\n    return len(n) - len(colors)\n\n\nn = list(map(int, input().split()))\nprint(horseshoe(n))", "src_uid": "38c4864937e57b35d3cce272f655e20f"}
{"source_code": "__author__ = 'RASULBEK'\ns=raw_input()\ni=0;c=1;t=0\nwhile i<len(s)-1:\n    if s[i]==s[i+1]:\n        t+=1\n    if t==5:\n        c+=1; t=0;\n    if s[i]!=s[i+1]:\n        c+=1;t=0;\n    i+=1\nprint(c)", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11"}
{"source_code": "def retrieve_data():\n    string = raw_input()\n    return string\n\ndef dubstep(data):\n    new_string = data.replace('WUB',' ')\n    new_string = new_string.strip()\n    return new_string\n\ndef main():\n    data = retrieve_data()\n    #data = 'WUBWUBABCWUB'\n    #data = 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB'\n    #print data\n    print dubstep(data)\n\nif __name__ == '__main__':\n    main()\n", "src_uid": "edede580da1395fe459a480f6a0a548d"}
{"source_code": "# -*- coding: utf-8 -*-\nn = int(raw_input())\nvoices = map(int, raw_input().split(' '))\nbribe = 0\nvoices[1:] = sorted(voices[1:])\n\nwhile voices[0] <= voices[n - 1]:\n    voices[0] += 1\n    voices[n - 1] -= 1\n    bribe += 1\n    voices[1:] = sorted(voices[1:])\n\nprint(bribe)\n", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58"}
{"source_code": "t,s,x = map(int,raw_input().split())\nif ((x-t) % s == 0 or (x - t) % s == 1) and (x == t or x >= t+s):\n\tprint \"YES\"\nelse:print \"NO\"\n", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"}
{"source_code": "n = int(input())\ns = input()\nA = []\ncnt = 0;z=0\nfor i in range(n):\n    if(s[i]=='1'):\n        if(z!=0):\n            A.append(\"0\"*(z-1))\n            z=0\n        if(cnt==-1):\n            cnt = 0\n        cnt+=1\n    else:\n        if(cnt>0):\n            A.append(cnt)\n            cnt = 0\n        z+=1\n        \nif(cnt>0):\n    A.append(cnt)\nif(z!=0):\n    A.append(\"0\"*z)\nfor i in A:\n    print(i,end=\"\")\n", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa"}
{"source_code": "import time\nimport random\nW = int(input())\nM = [int(a) for a in input().split()]\nA = [0] * 8\nsTime = time.time()\n\ns = 0\nmi = 10**20\nfor i in range(8):\n    if s + M[i]*(i+1) <= W:\n        s += M[i]*(i+1)\n        A[i] = M[i]\n    else:\n        t = (W-s)//(i+1)\n        s += t*(i+1)\n        A[i] += t\n    \n    if s <= W:\n        mi = min(mi, W-s)\n\nwhile time.time() - sTime < 1.7:\n    i = random.randrange(8)\n    a = random.randrange(2)\n    if W-s >= 20 or (s-W < 10 and a == 0):\n        if A[i] < M[i]:\n            A[i] += 1\n            s += (i+1)\n    else:\n        if A[i] > 0:\n            A[i] -= 1\n            s -= (i+1)\n\n    if s <= W:\n        mi = min(mi, W-s)\n\nprint(W-mi)\n", "src_uid": "8097e10157320524c0faed56f2bc4880"}
{"source_code": "for _ in range(int(input())):\r\n\tx = int(input())\r\n\ta = [0] + [int(x) for x in input().split()]\r\n\tprint(\"YES\" if a[x] != 0 and a[a[x]] != 0 else \"NO\")", "src_uid": "5cd113a30bbbb93d8620a483d4da0349"}
{"source_code": "import sys\n\nstr2 = sys.stdin.read().split()\n\ns = [\"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\", \"A\", \"B\", \"H\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\",\n     \"A\", \"B\", \"H\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\", \"A\", \"B\", \"H\"]\n\nisMajor = False\nisMinor = False\narr = [0] * 3\nfor a in range(3):\n    for b in range(3):\n        if (a != b):\n            for c in range(3):\n                if c != a and c != b:\n                    str = [str2[a], str2[b], str2[c]]\n                    last = -1\n                    for i in range(3):\n                        arr[i] = last = s[last + 1:].index(str[i]) + last + 1\n                    if arr[1] - arr[0] == 4 and arr[2] - arr[1] == 3:\n                        isMajor = True\n                    elif arr[1] - arr[0] == 3 and arr[2] - arr[1] == 4:\n                        isMinor = True\nif (isMajor == True):\n    print(\"major\")\nelif (isMinor == True):\n    print(\"minor\")\nelse:\n    print(\"strange\")", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58"}
{"source_code": "import math\nn,w=map(int,input().split())\n\na=list(map(int,input().split())) \n\nl=[]\nfor i in range(n):\n    l.append([a[i],i,math.ceil(a[i]/2)])\nl.sort(reverse=True)\ns=0\n\nfor i in range(n):s+=l[i][2]\n\nif w<s:\n    print(-1)\nelse:\n    rest =  w-s \n    for i in range(n):\n        if rest!=0:\n            t=l[i][2]\n            l[i][2]=min(l[i][0],l[i][2]+rest)\n            \n#            print(min(l[i][0],l[i][2]+rest))\n            \n            rest=rest-(l[i][2]-t)\n        else:\n            break\n    ans=[0]*n\n    for i in range(n):\n        ans[l[i][1]]=l[i][2]\n    print(*ans)\n    \n    \n    \n    \n    \n    \n    \n", "src_uid": "5d3bb9e03f4c5c8ecb6233bd5f90f3a3"}
{"source_code": "l,r = map(int,input().split())\nflag = False\nfor i in range(l,r+1):\n    length = len(str(i))\n    num = list(str(i))\n    if len(set(num)) == length:\n        flag = True\n        break\n    \nif flag:\n    print(i)\nelse:\n    print(-1)", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7"}
{"source_code": "n = int(input(), 2)\np = 1\ncount = 0\nwhile p < n:\n\tp *= 4\n\tcount += 1\nprint(count)", "src_uid": "d8ca1c83b431466eff6054d3b422ab47"}