Dataset Viewer
Auto-converted to Parquet Duplicate
problem_id
int64
2
2.71k
question
stringlengths
208
5.74k
solutions
stringlengths
838
165k
input_output
stringlengths
84
43.9M
difficulty
stringclasses
1 value
url
stringlengths
37
49
starter_code
stringclasses
1 value
2
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^9) — current year in Berland. -----Output----- Output amount of years from the current year to the next lucky one. -----Examples----- Input 4 Output 1 Input 201 Output 99 Input 4000 Output 1000 -----Note----- In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
["def main():\n s = input()\n n = len(s)\n t = int(str(int(s[0]) + 1) + '0' * (n - 1))\n\n print(t - int(s))\n\nmain()\n", "s = input()\nx = int(s)\ny = int(str(int(s[0]) + 1) + '0' * (len(s) - 1))\nprint(y - x)", "n = int(input())\n\nfor i in range(0,11):\n for j in range(1,10):\n m = j*10**i\n if (n<m) :\n print(m-n)\n return\n\n\n", "n = int(input())\ns = str(n)\ns = str(int(s[0]) + 1) + '0' * (len(s) - 1)\ns = int(s)\nprint(s - n)\n", "y = input()\nly = len(y)\niy = int(y)\ntd = iy/(10**(ly-1))\n#print(ly,iy,td)\nif(td == 9):\n print(10**ly-iy)\nelse:\n print((int(y[0])+1)*(10**(ly-1))-iy)", "N = input()\nprint((int(N[0])+1)*(10**(len(N)-1))-int(N))\n", "def solve(n):\n if (n<10):\n return 1\n a = str(n)\n b=int(a[1:])\n return 10**(len(a)-1)-b\n \n\n\nn = int(input())\nprint(solve(n))\n", "n = str(int(input())+1)\nif n.count(\"0\")+1 == len(n):\n print(1)\nelse:\n print((int(n[0])+1)*10**(len(n)-1)-int(n)+1)\n \n", "import sys\nimport math\n\nn = int(input())\ns = n\nr = 1\nwhile n // 10 != 0:\n n = n // 10\n r *= 10 \nnext = (s // r + 1) * r\nprint(next - s)", "n=(input())\ncur=int(n[0])\npre=str(cur+1)\nnext=pre+'0'*(len(n)-1)\nprint(int(next)-int(n))\n", "n = int(input())\nans = 0\nprev = 0\nN = n\nwhile n:\n\ta = n%10\n\tn //= 10\n\tans += 1\n\tprev = a\nif ans==1:\n\tprint(1)\nelse:\n\tprint(((prev+1)*(10**(ans-1)))-N)\n", "x=input()\nn=int(x)\nln=len(x)\ny=int(x[0])\ny+=1\ny=y*(10**(ln-1))\nprint(y-n)\n", "a=int(input())\nb=a\nnr=1\nwhile b>9:\n nr*=10\n b/=10\nprint(int(b+1)*int(nr)-int(a))", "t=input()\nl=len(t)\nprint((int(t[0:1])+1)*(10**(l-1))-int(t))\n\n", "def main():\n n = input()\n d = int(n[0])\n if d < 9:\n year = int(str(d + 1) + '0' * (len(n) - 1))\n else:\n year = int('1' + '0' * len(n))\n\n print(year - int(n))\n\ndef __starting_point():\n main()\n\n__starting_point()", "x = int(input())\na = x\nx += 1\nif len(str(x))-str(x).count('0') <= 1:\n b = x;\nelse:\n b = int(str(int(str(x)[0])+1)+'0'*(len(str(x))-1))\nprint(b-a)", "# -*- coding: utf-8 -*-\n\nimport sys\nimport os\nimport math\n\n# input_text_path = __file__.replace('.py', '.txt')\n# fd = os.open(input_text_path, os.O_RDONLY)\n# os.dup2(fd, sys.stdin.fileno())\n\nn = int(input())\n\nif n < 10:\n print(1)\nelse:\n s = str(n)\n l = len(s)\n\n v = 10 ** (l-1)\n w = int(s[1:])\n\n print(v - w)", "n = int(input())\nsize = len(str(n))\nnum = str(n)[0]\nres = (int(num) + 1) * 10 ** (size - 1) - n\nprint(res)\n", "def main():\n NUMBERS = [str(i) for i in range(1, 10)]\n num = input()\n result = ''\n if num in NUMBERS:\n result = 1\n return result\n if len(num) == num.count('0') + 1:\n result = int(str(int(num[0]) + 1) + num[1:]) - int(num)\n return result\n result = int(str(int(num[0]) + 1) + (len(num) - 1) * '0') - int(num)\n return result\nprint(main())", "n=input()\ni=len(n)-1\nt=int(n[0])+1\nprint(10**i*t-int(n))", "n = int(input())\ny = 1\nd = 0\nwhile y <= n:\n y += 10**d\n if y // 10**(d + 1) == 1:\n d += 1\nprint(y - n)\n\n", "import math\n\nn = int(input())\n\np10 = int(math.log10(n + 1))\np = pow(10, p10)\nyears = (int(n / p) + 1) * p - n\n\nprint(years)\n", "n = input()\ny = int(n)\n\nif y < 10:\n print(1)\nelse:\n l = len(n)\n f = int(n[0]) + 1\n f *= 10 ** (l - 1)\n print(f - y)\n", "n = int(input())\ni = 1\ncur = n\nx = 1\nwhile cur > 0:\n a = cur % 10\n cur //= 10\n x *= 10\nprint((a+1)*x//10 - n)"]
{ "inputs": [ "4\n", "201\n", "4000\n", "9\n", "10\n", "1\n", "100000000\n", "900000000\n", "999999999\n", "1000000000\n", "9999999\n", "100000001\n", "3660\n", "21\n", "900000001\n", "62911\n", "11\n", "940302010\n", "91\n", "101\n", "1090\n", "987654321\n", "703450474\n", "1091\n", "89\n", "109\n", "190\n", "19\n", "8\n", "482\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n", "13\n", "14\n", "15\n", "16\n", "17\n", "18\n", "19\n", "20\n", "21\n", "22\n", "23\n", "24\n", "25\n", "26\n", "27\n", "28\n", "29\n", "30\n", "31\n", "32\n", "33\n", "34\n", "35\n", "36\n", "37\n", "38\n", "39\n", "40\n", "41\n", "42\n", "43\n", "44\n", "45\n", "46\n", "47\n", "48\n", "49\n", "50\n", "51\n", "52\n", "53\n", "54\n", "55\n", "56\n", "57\n", "58\n", "59\n", "60\n", "61\n", "62\n", "63\n", "64\n", "65\n", "66\n", "67\n", "68\n", "69\n", "70\n", "71\n", "72\n", "73\n", "74\n", "75\n", "76\n", "77\n", "78\n", "79\n", "80\n", "81\n", "82\n", "83\n", "84\n", "85\n", "86\n", "87\n", "88\n", "89\n", "90\n", "91\n", "92\n", "93\n", "94\n", "95\n", "96\n", "97\n", "98\n", "99\n", "100\n", "100\n", "100\n", "1000\n", "1000\n", "1000\n", "10000\n", "10000\n", "101\n", "110\n", "1001\n", "1100\n", "1010\n", "10010\n", "10100\n", "102\n", "120\n", "1002\n", "1200\n", "1020\n", "10020\n", "10200\n", "108\n", "180\n", "1008\n", "1800\n", "1080\n", "10080\n", "10800\n", "109\n", "190\n", "1009\n", "1900\n", "1090\n", "10090\n", "10900\n", "200\n", "200\n", "2000\n", "2000\n", "2000\n", "20000\n", "20000\n", "201\n", "210\n", "2001\n", "2100\n", "2010\n", "20010\n", "20100\n", "202\n", "220\n", "2002\n", "2200\n", "2020\n", "20020\n", "20200\n", "208\n", "280\n", "2008\n", "2800\n", "2080\n", "20080\n", "20800\n", "209\n", "290\n", "2009\n", "2900\n", "2090\n", "20090\n", "20900\n", "800\n", "800\n", "8000\n", "8000\n", "8000\n", "80000\n", "80000\n", "801\n", "810\n", "8001\n", "8100\n", "8010\n", "80010\n", "80100\n", "802\n", "820\n", "8002\n", "8200\n", "8020\n", "80020\n", "80200\n", "808\n", "880\n", "8008\n", "8800\n", "8080\n", "80080\n", "80800\n", "809\n", "890\n", "8009\n", "8900\n", "8090\n", "80090\n", "80900\n", "900\n", "900\n", "9000\n", "9000\n", "9000\n", "90000\n", "90000\n", "901\n", "910\n", "9001\n", "9100\n", "9010\n", "90010\n", "90100\n", "902\n", "920\n", "9002\n", "9200\n", "9020\n", "90020\n", "90200\n", "908\n", "980\n", "9008\n", "9800\n", "9080\n", "90080\n", "90800\n", "909\n", "990\n", "9009\n", "9900\n", "9090\n", "90090\n", "90900\n", "92651241\n" ], "outputs": [ "1\n", "99\n", "1000\n", "1\n", "10\n", "1\n", "100000000\n", "100000000\n", "1\n", "1000000000\n", "1\n", "99999999\n", "340\n", "9\n", "99999999\n", "7089\n", "9\n", "59697990\n", "9\n", "99\n", "910\n", "12345679\n", "96549526\n", "909\n", "1\n", "91\n", "10\n", "1\n", "1\n", "18\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "10\n", "9\n", "8\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n", "1\n", "10\n", "9\n", "8\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n", "1\n", "10\n", "9\n", "8\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n", "1\n", "10\n", "9\n", "8\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n", "1\n", "10\n", "9\n", "8\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n", "1\n", "10\n", "9\n", "8\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n", "1\n", "10\n", "9\n", "8\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n", "1\n", "10\n", "9\n", "8\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n", "1\n", "10\n", "9\n", "8\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n", "1\n", "100\n", "100\n", "100\n", "1000\n", "1000\n", "1000\n", "10000\n", "10000\n", "99\n", "90\n", "999\n", "900\n", "990\n", "9990\n", "9900\n", "98\n", "80\n", "998\n", "800\n", "980\n", "9980\n", "9800\n", "92\n", "20\n", "992\n", "200\n", "920\n", "9920\n", "9200\n", "91\n", "10\n", "991\n", "100\n", "910\n", "9910\n", "9100\n", "100\n", "100\n", "1000\n", "1000\n", "1000\n", "10000\n", "10000\n", "99\n", "90\n", "999\n", "900\n", "990\n", "9990\n", "9900\n", "98\n", "80\n", "998\n", "800\n", "980\n", "9980\n", "9800\n", "92\n", "20\n", "992\n", "200\n", "920\n", "9920\n", "9200\n", "91\n", "10\n", "991\n", "100\n", "910\n", "9910\n", "9100\n", "100\n", "100\n", "1000\n", "1000\n", "1000\n", "10000\n", "10000\n", "99\n", "90\n", "999\n", "900\n", "990\n", "9990\n", "9900\n", "98\n", "80\n", "998\n", "800\n", "980\n", "9980\n", "9800\n", "92\n", "20\n", "992\n", "200\n", "920\n", "9920\n", "9200\n", "91\n", "10\n", "991\n", "100\n", "910\n", "9910\n", "9100\n", "100\n", "100\n", "1000\n", "1000\n", "1000\n", "10000\n", "10000\n", "99\n", "90\n", "999\n", "900\n", "990\n", "9990\n", "9900\n", "98\n", "80\n", "998\n", "800\n", "980\n", "9980\n", "9800\n", "92\n", "20\n", "992\n", "200\n", "920\n", "9920\n", "9200\n", "91\n", "10\n", "991\n", "100\n", "910\n", "9910\n", "9100\n", "7348759\n" ] }
interview
https://codeforces.com/problemset/problem/808/A
3
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$. Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work. You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it. -----Input----- The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively. Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$). -----Output----- Print one integer — maximum number of painted sections if you hire $q - 2$ painters. -----Examples----- Input 7 5 1 4 4 5 5 6 6 7 3 5 Output 7 Input 4 3 1 1 2 2 3 4 Output 2 Input 4 4 1 1 2 2 2 3 3 4 Output 3
["from collections import defaultdict as dd\nimport math\ndef nn():\n\treturn int(input())\n\ndef li():\n\treturn list(input())\n\ndef mi():\n\treturn list(map(int, input().split()))\n\ndef lm():\n\treturn list(map(int, input().split()))\n\n\nn, q=mi()\n\nints=[]\n\n\nfor _ in range(q):\n\tst, end=mi()\n\tints.append((st,end))\n\n\ncoverage=[10]+[0]*n\n\nfor st, end in ints:\n\tfor i in range(st,end+1):\n\t\tcoverage[i]+=1\n\ntotal=-1\n\nfor val in coverage:\n\tif not val==0:\n\t\ttotal+=1\n\nsinglecount=0\ndoublecount=0\n\nsingles=[0]*(n+1)\n#print(total)\ndoubles=[0]*(n+1)\nfor i in range(len(coverage)):\n\t#print(i,singles)\n\tif coverage[i]==1:\n\t\tsinglecount+=1\n\tif coverage[i]==2:\n\t\tdoublecount+=1\n\tsingles[i]=singlecount\n\tdoubles[i]=doublecount\nmaxtotal=0\nfor i in range(len(ints)):\n\tfor j in range(i+1, len(ints)):\n\t\tst1=min(ints[i][0],ints[j][0])\n\t\tend1=min(ints[i][1],ints[j][1])\n\t\tst2, end2=max(ints[i][0],ints[j][0]), max(ints[i][1],ints[j][1])\n\t\t#assume st1<=st2\n\t\tif end1<st2:\n\t\t\tcurtotal=total-(singles[end1]-singles[st1-1])-(singles[end2]-singles[st2-1])\n\t\telif end1<end2:\n\t\t\tcurtotal=total-(singles[st2-1]-singles[st1-1])-(doubles[end1]-doubles[st2-1])-(singles[end2]-singles[end1])\n\t\telse:\n\t\t\tcurtotal=total-(singles[st2-1]-singles[st1-1])-(doubles[end2]-doubles[st2-1])-(singles[end1]-singles[end2])\n\t\tmaxtotal=max(maxtotal,curtotal)\n\nprint(maxtotal)\n\t\t\n\n\n\n\n\n\n\n", "import collections\n\nn , q = list(map(int , input().split()))\nsections = [0]*n\np = []\nfor _ in range(q):\n l , r = list(map(int , input().split()))\n p.append((l,r))\n for j in range(l,r+1):\n sections[j-1]+=1\n\naux = n-collections.Counter(sections)[0]\nnumber1 = [0]*n\nnumber2 = [0]*n\n\nfor i in range(n):\n if(sections[i]==1):\n for j in range(i,n):\n number1[j]+=1\n elif(sections[i]==2):\n for j in range(i,n):\n number2[j]+=1\n\nans = -float('inf')\nfor i in range(len(p)):\n for j in range(len(p)):\n if(j>i):\n a, b = p[i]\n c, d = p[j]\n if(a>c):\n a , c = c , a\n b , d = d , b\n aux1 = number1[b-1]-number1[a-1]+1*(sections[a-1]==1)\n aux2 = number1[d-1]-number1[c-1]+1*(sections[c-1]==1)\n aux3 = abs(number2[c-1]-number2[min(b,d)-1])+1*(sections[c-1]==2)\n if(b<c): aux3 = 0\n ans = max(ans , aux-(aux1+aux2+aux3))\nprint(ans)\n", "DBG = False\nn,q = list(map(int,input().split()))\nl = []\nr = []\nc = [0] * (n+2)\nfor i in range(q):\n ll,rr = list(map(int,input().split()))\n l.append(ll)\n r.append(rr)\n for j in range(ll,(rr+1)):\n c[j] += 1\n\nacc1 = [0] * (n+2)\nacc12 = [0] * (n+2)\nfor j in range(1,n+1):\n acc1[j] = acc1[j-1] + (1 if c[j] == 1 else 0)\n acc12[j] = acc12[j-1] + (1 if (c[j] == 2) else 0)\n\nminred = 99999999\nfor i in range(q-1):\n for j in range(i+1,q):\n li = l[i]\n lj = l[j]\n ri = r[i]\n rj = r[j]\n #puts \"(#{li} #{ri}) - (#{lj} #{rj}) \" if DBG\n if li > lj:\n li, lj = lj, li\n ri, rj = rj, ri\n #end # now li <= lj\n\n if rj <= ri: # li lj rj ri\n oneal = li\n onear = lj-1\n twol = lj\n twor = rj\n onebl = rj+1\n onebr = ri\n elif lj <= ri: # li lj ri rj\n oneal = li\n onear = lj-1\n twol = lj\n twor = ri\n onebl = ri+1\n onebr = rj\n else: # li ri lj rj\n oneal = li\n onear = ri\n twol = lj\n twor = lj-1 # null\n onebl = lj\n onebr = rj\n\n onereda = acc1[onear] - acc1[oneal-1]\n oneredb = acc1[onebr] - acc1[onebl-1]\n twored = acc12[twor] - acc12[twol-1]\n redsum = onereda + oneredb + twored\n #puts \" - 1l: #{onereda}, 2:#{twored}, 1r: #{oneredb}\" if DBG\n minred = min(minred, redsum)\n\nzcnt = 0\nfor i in range(1,n+1):\n if c[i] == 0:\n zcnt += 1\nprint(n-zcnt-minred)\n", "n,q=map(int,input().split())\narr=[]\nff=[0]*(5005)\nfor i in range(q):\n\tx,y=map(int,input().split())\n\tfor j in range(x,y+1):\n\t\tff[j]+=1\n\tarr.append([x,y])\nans=0\nfor i in range(q):\n\ttt=0\n\tfor j in range(arr[i][0],arr[i][1]+1):\n\t\tff[j]-=1\n\tfor j in range(5005):\n\t\tif ff[j]>0:\n\t\t\ttt+=1\n\tc=[0]*(n+1)\n\tfor j in range(1,n+1):\n\t\tc[j]=c[j-1]\n\t\tif ff[j]==1:\n\t\t\tc[j]+=1\n\t# print(ff[0:n+1])\n\tfor j in range(i+1,q):\n\t\tans=max(ans,tt-c[arr[j][1]]+c[arr[j][0]-1])\n\tfor j in range(arr[i][0],arr[i][1]+1):\n\t\tff[j]+=1\nprint(ans)", "# -*- coding: utf-8 -*-\n\nimport sys\nfrom copy import copy\n\ndef input(): return sys.stdin.readline().strip()\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\ndef ceil(x, y=1): return int(-(-x // y))\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(): return list(map(int, input().split()))\ndef Yes(): print('Yes')\ndef No(): print('No')\ndef YES(): print('YES')\ndef NO(): print('NO')\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\nN,Q=MAP()\n\nimos=[0]*(N+2)\nPts=[None]*Q\nfor i in range(Q):\n l,r=MAP()\n Pts[i]=(l,r)\n imos[l]+=1\n imos[r+1]-=1\nfor i in range(N+1):\n imos[i+1]+=imos[i]\n\nmx=0\nfor i in range(Q):\n cp=copy(imos)\n l,r=Pts[i]\n for j in range(l, r+1):\n cp[j]-=1\n sm=0\n cnt1=[0]*(N+2)\n for j in range(1, N+1):\n if cp[j]>0:\n sm+=1\n if cp[j]==1:\n cnt1[j]+=1\n cnt1[j+1]+=cnt1[j]\n for j in range(i+1, Q):\n l2,r2=Pts[j]\n mx=max(mx, sm-(cnt1[r2]-cnt1[l2-1]))\n\nprint(mx)\n", "n, q = map(int, input().split())\na = []\nfor i in range(q):\n l, r = map(int, input().split())\n l -= 1\n r -= 1\n a.append([l, r])\n\nct = [0] * (n + 1)\nfor i in a:\n ct[i[0]] += 1\n ct[i[1] + 1] -= 1\n\nones, twos = [0] * n, [0] * n\ns = 0\nfor i in range(n):\n if i > 0:\n ct[i] += ct[i - 1]\n ones[i] += ones[i - 1]\n twos[i] += twos[i - 1]\n if ct[i] == 1:\n ones[i] += 1\n elif ct[i] == 2:\n twos[i] += 1\n if ct[i] != 0:\n s += 1\n\nones.append(0)\ntwos.append(0)\n\nans = 0\nfor i in range(q):\n for j in range(i + 1, q):\n rem = 0;\n rem += ones[a[i][1]] - ones[a[i][0] - 1]\n rem += ones[a[j][1]] - ones[a[j][0] - 1]\n\n l, r = max(a[i][0], a[j][0]), min(a[i][1], a[j][1])\n if r >= l:\n rem += twos[r] - twos[l - 1]\n \n ans = max(ans, s - rem)\n\nprint(ans)", "n, q = list(map(int, input().split()))\npainters = []\nsections = [0] * (n + 1)\nfor i in range(q):\n l, r = list(map(int, input().split()))\n l -= 1\n r -= 1\n painters.append([l, r])\n sections[l] += 1\n sections[r + 1] -= 1\n\ncnt1 = [0] * (n + 1)\ncnt2 = [0] * (n + 1)\np = 0\ntotal = 0\nfor i in range(n):\n p += sections[i]\n if p == 1:\n cnt1[i + 1] = cnt1[i] + 1\n else:\n cnt1[i + 1] = cnt1[i]\n if p == 2:\n cnt2[i + 1] = cnt2[i] + 1\n else:\n cnt2[i + 1] = cnt2[i]\n if p > 0:\n total += 1\nans = 0\nfor i in range(q - 1):\n for j in range(i + 1, q):\n [l1, r1] = painters[i]\n [l2, r2] = painters[j]\n l = max(l1, l2)\n r = min(r1, r2)\n if l <= r:\n t = total - (cnt2[r + 1] - cnt2[l]) - (cnt1[max(r1, r2) + 1] - cnt1[min(l1, l2)])\n ans = max(ans, t)\n else:\n t = total - (cnt1[r1 + 1] - cnt1[l1]) - (cnt1[r2 + 1] - cnt1[l2])\n ans = max(ans, t)\nprint(ans)\n", "from operator import itemgetter\nn,q=list(map(int,input().split()))\ncnt=0\nans=[0]*(n)\narr=[0]*q\nfor i in range(q):\n\tarr[i]=list(map(int,input().split()))\n\tfor j in range(arr[i][0]-1,arr[i][1],1):\n\t\tans[j]+=1\n\t\tif ans[j]==1:\n\t\t\tcnt+=1\ncnt1=[0]*(n+1)\ncnt2=[0]*(n+1)\n# print(\"ans\",*ans)\nfor i in range(n):\n\tcnt1[i+1]=cnt1[i]\n\tcnt2[i+1]=cnt2[i]\n\tif ans[i]==1:\n\t\tcnt1[i+1]+=1\n\tif ans[i]==2:\n\t\tcnt2[i+1]+=1\n# print(cnt2)\nmac=0\nfor i in range(q):\n\tfor j in range(i+1,q,1):\n\t\tdelete=cnt1[arr[i][1]]-cnt1[arr[i][0]-1]+cnt1[arr[j][1]]-cnt1[arr[j][0]-1]\n\t\tif arr[j][0]>arr[i][1] or arr[j][1]<arr[i][0]:\n\t\t\tpass\n\t\telif arr[j][0]<=arr[i][1]:\n\t\t\t# print(\"****\",cnt2[min(arr[i][1],arr[j][1])],cnt2[max(arr[j][0]-1,arr[i][0]-1)])\n\t\t\tdelete+=cnt2[min(arr[i][1],arr[j][1])]-cnt2[max(arr[j][0]-1,arr[i][0]-1)]\n\n\t\t# print(i,j,delete)\n\t\tif cnt-delete>mac:\n\t\t\tmac=cnt-delete\nprint(mac)\n\n\n\n\n", "n,q=list(map(int,input().split()))\nsec=[list(map(int,input().split())) for _ in range(q)]\nsec=sorted(sec,key=lambda x:(x[0],x[1]))\nfence=[0]*(n+1)\nfor i in sec:\n x,y=i[0],i[1]\n x-=1;y-=1\n fence[x]+=1\n fence[y+1]-=1\nfor i in range(1,n+1):\n fence[i]+=fence[i-1]\nzeroes=[0]*(n);ones=[0]*(n);twos=[0]*(n)\nzeroes[0]=1 if fence[0]==0 else 0\nones[0]=1 if fence[0]==1 else 0\ntwos[0]=1 if fence[0]==2 else 0\nfor i in range(1,n):\n if fence[i]==0:\n zeroes[i]+=zeroes[i-1]+1\n else:\n zeroes[i]=zeroes[i-1]\n\nfor i in range(1,n):\n if fence[i]==1:\n ones[i]+=ones[i-1]+1\n else:\n ones[i]=ones[i-1]\n\nfor i in range(1,n):\n if fence[i]==2:\n twos[i]+=twos[i-1]+1\n else:\n twos[i]=twos[i-1]\nnp=0\nfor i in range(q):\n x1,y1=sec[i][0],sec[i][1]\n x1-=1;y1-=1\n co1=co2=ct=0\n for j in range(i+1,q):\n x2,y2=sec[j][0],sec[j][1]\n x2-=1;y2-=1\n co1=ones[y1]-(0 if x1==0 else ones[x1-1])\n co2=ones[y2]-(0 if x2==0 else ones[x2-1])\n if x2<=y1:\n ct=twos[min(y1,y2)]-(0 if x2==0 else twos[x2-1])\n else:\n ct=0\n np=max(np,n-(co1+co2+ct+zeroes[-1]))\n #print(i,j,np,co1,co2,ct,zeroes[-1],x2,y1)\nprint(np)\n \n \n \n", "n,q=list(map(int,input().split()))\nsec=[list(map(int,input().split())) for _ in range(q)]\nsec=sorted(sec,key=lambda x:(x[0],x[1]))\nfence=[0]*(n+1)\nfor i in sec:\n x,y=i[0],i[1]\n x-=1;y-=1\n fence[x]+=1\n fence[y+1]-=1\nfor i in range(1,n+1):\n fence[i]+=fence[i-1]\nzeroes=[0]*(n);ones=[0]*(n);twos=[0]*(n)\nzeroes[0]=1 if fence[0]==0 else 0\nones[0]=1 if fence[0]==1 else 0\ntwos[0]=1 if fence[0]==2 else 0\nfor i in range(1,n):\n if fence[i]==0:\n zeroes[i]+=zeroes[i-1]+1\n else:\n zeroes[i]=zeroes[i-1]\n\nfor i in range(1,n):\n if fence[i]==1:\n ones[i]+=ones[i-1]+1\n else:\n ones[i]=ones[i-1]\n\nfor i in range(1,n):\n if fence[i]==2:\n twos[i]+=twos[i-1]+1\n else:\n twos[i]=twos[i-1]\nnp=0\nfor i in range(q):\n x1,y1=sec[i][0],sec[i][1]\n x1-=1;y1-=1\n co1=co2=ct=0\n for j in range(i+1,q):\n x2,y2=sec[j][0],sec[j][1]\n x2-=1;y2-=1\n co1=ones[y1]-(0 if x1==0 else ones[x1-1])\n co2=ones[y2]-(0 if x2==0 else ones[x2-1])\n if x2<=y1:\n ct=twos[min(y1,y2)]-(0 if x2==0 else twos[x2-1])\n else:\n ct=0\n np=max(np,n-(co1+co2+ct+zeroes[-1]))\n #print(i,j,np,co1,co2,ct,zeroes[-1],x2,y1)\nprint(np)\n", "n, m = list(map(int, input().split()))\na = [0 for i in range(n)]\nb = [list(map(int, input().split())) for i in range(m)] \nf = [0 for i in range(m)]\ng = [[0 for i in range(m)] for j in range(m)]\nans = s = p = q = 0\nc = n\nfor i in range(m):\n\tfor j in range(b[i][0] - 1, b[i][1]):\n\t\ta[j] += 1\nfor i in range(n):\n\ts += a[i] != 0\n\tif a[i] == 1:\n\t\tfor j in range(m):\n\t\t\tif b[j][0] - 1 <= i < b[j][1]:\n\t\t\t\tf[j] += 1\n\tif a[i] == 2:\n\t\tp = q = -1\n\t\tfor j in range(m):\n\t\t\tif b[j][0] - 1 <= i < b[j][1]:\n\t\t\t\tif p == -1:\n\t\t\t\t\tp = j\n\t\t\t\telse:\n\t\t\t\t\tq = j\n\t\tg[p][q] += 1\nfor i in range(m):\n\tfor j in range(i + 1, m):\n\t\tc = min(c, g[i][j] + f[i] + f[j])\nprint(s - c)\n", "n,q = map(int, input().strip().split())\ncount = [0 for i in range(n+1)]\ntot = 0\npainters = []\nfor i in range(q):\n l,r = map(int, input().strip().split())\n painters.append([l,r])\n for j in range(l,r+1):\n if count[j] == 0:\n tot += 1\n count[j] += 1\nones = [0 for i in range(n+1)]\ntwos = [0 for i in range(n+1)]\npainters.sort()\nfor i in range(1,n+1):\n ones[i] = ones[i-1]\n twos[i] = twos[i-1]\n if count[i] == 1:\n ones[i] += 1\n elif count[i] == 2:\n twos[i] += 1\nmx = 0\nfor i in range(q):\n for j in range(i+1,q):\n a = ones[painters[i][1]] - ones[painters[i][0]-1]\n b = ones[painters[j][1]] - ones[painters[j][0]-1]\n if painters[j][0] <= painters[i][1]:\n c = twos[min(painters[i][1],painters[j][1])] - twos[painters[j][0]-1]\n else:\n c = 0\n mx = max(mx,tot - a -b -c)\nprint (mx)", "n,q = [int(x) for x in input().split()]\n\np = []\n\nfor _ in range(q):\n p.append([int(x)-1 for x in input().split()])\n\n\ndef pre(ind):\n res = [0 for _ in range(n)]\n for i in range(q):\n if i == ind : continue\n res[p[i][0]] += 1\n if p[i][1] + 1 < n:\n res[p[i][1] + 1] -= 1\n t = 0\n total = 0\n for i in range(n):\n t += res[i]\n res[i] = t\n if res[i] > 0:\n total += 1\n for i in range(n):\n if res[i] > 1 : res[i] = 0\n for i in range(1,n):\n res[i] += res[i-1]\n return total,res\n\n\nbest = 0\n\nfor i in range(q):\n total,table = pre(i)\n for j in range(q):\n if j== i : continue\n count = table[p[j][1]]\n if p[j][0] > 0 :\n count -= table[p[j][0] - 1] \n best = max(best,total-count)\n\nprint(best)\n", "n, q = list(map(int, input().split()))\nC = [0 for _ in range(n)]\nX = [[-1, -1] for _ in range(n)]\nii = 1\nfor i in range(q):\n l, r = list(map(int, input().split()))\n ii += 1\n l -= 1\n r -= 1\n for j in range(l, r+1):\n if C[j] <= 2:\n C[j] += 1\n if C[j] <= 2:\n X[j][C[j]-1] = i\ns = len([c for c in C if c > 0])\n\nma = 0\nfor i in range(q):\n Y = [0] * q\n Y[i] = 10**10\n y = 0\n for j in range(n):\n if C[j] == 2:\n if i == X[j][0] or i == X[j][1]:\n Y[X[j][0]] += 1\n Y[X[j][1]] += 1\n elif C[j] == 1:\n if i == X[j][0]:\n y += 1\n else:\n Y[X[j][0]] += 1\n \n ma = max(ma, s-min(Y)-y)\n\nprint(ma)\n", "# -*- coding: utf-8 -*-\n# @Time : 2019/3/7 13:43\n# @Author : LunaFire\n# @Email : gilgemesh2012@gmail.com\n# @File : C. Painting the Fence.py\n\n\ndef main():\n n, q = list(map(int, input().split()))\n painters = []\n for _ in range(q):\n painters.append(list(map(int, input().split())))\n # print(painters)\n\n ret = 0\n for index in range(q):\n mask = [0] * (n + 1)\n for i in range(q):\n if i == index:\n continue\n left, right = painters[i]\n mask[left - 1] += 1\n mask[right] -= 1\n\n curr_sum, paint_count = 0, 0\n section_count = [0] * n\n for i in range(n):\n curr_sum += mask[i]\n section_count[i] = curr_sum\n if section_count[i] > 0:\n paint_count += 1\n\n one_count = [0] * (n + 1)\n for i in range(n):\n one_count[i + 1] = one_count[i] + (1 if section_count[i] == 1 else 0)\n\n desc_ones = n\n for i in range(q):\n if i == index:\n continue\n left, right = painters[i]\n desc_ones = min(desc_ones, one_count[right] - one_count[left - 1])\n\n ret = max(ret, paint_count - desc_ones)\n print(ret)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "\n\ndef get_intersection(l1, r1, l2, r2):\n if min(r1, r2) < max(l1, l2):\n return -1, -1\n else:\n return max(l1, l2), min(r1, r2)\n\ndef cumsum(ones, l, r):\n ans = ones[r]\n if l != 1:\n ans -= ones[l-1]\n\n return ans\n\ndef main():\n\n n,q = [int(x) for x in input().split(' ')]\n cnts = [0 for i in range(n+1)]\n pep = []\n\n for i in range(q):\n l,r = [int(x) for x in input().split(' ')]\n pep.append((l,r))\n cnts[l] += 1\n if r != n:\n cnts[r+1] -= 1\n\n ones = [0 for i in range(n+1)]\n twos = [0 for i in range(n+1)]\n tot = 0\n\n for i in range(1, n+1):\n cnts[i] += cnts[i-1]\n tot += cnts[i] != 0\n\n if cnts[i] == 1:\n ones[i] += 1\n elif cnts[i] == 2:\n twos[i] += 1\n\n ones[i] += ones[i-1]\n twos[i] += twos[i-1]\n\n best = -1\n for i in range(len(pep)):\n for j in range(i+1, len(pep)):\n cur_ans = tot - cumsum(ones, *pep[i])\n cur_ans -= cumsum(ones, *pep[j])\n\n l, r = get_intersection(*pep[i], *pep[j])\n\n if l != -1:\n cur_ans -= cumsum(twos, l, r)\n\n best = max(best, cur_ans)\n\n print(best)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "def main():\n n, q = map(int, input().split())\n cnt = [0] * (n+1)\n ll = [0] * q\n rr = [0] * q\n\n for i in range(q):\n l, r = map(int, input().split())\n cnt[l] += 1\n if r < n:\n cnt[r+1] -= 1\n ll[i] = l\n rr[i] = r\n\n for i in range(1, n+1):\n cnt[i] += cnt[i-1]\n\n pref1 = [0] * (n+1)\n pref2 = [0] * (n+1)\n for i in range(1, n+1):\n if cnt[i] == 1:\n pref1[i] = 1\n pref1[i] += pref1[i-1]\n\n if cnt[i] == 2:\n pref2[i] = 1\n pref2[i] += pref2[i-1]\n\n all = 0\n for i in range(1, n+1):\n if cnt[i] > 0:\n all += 1\n\n\n def getIntersection(l1, r1, l2, r2):\n start = max(l1, l2)\n end = min(r1, r2)\n if start <= end:\n return start, end\n return None\n\n\n maxBlocks = 0\n for i in range(q):\n for j in range(i+1, q):\n all_ij = all\n inter = getIntersection(ll[i], rr[i], ll[j], rr[j])\n if inter:\n interL, interR = inter\n all_ij -= (pref1[interL-1] - pref1[min(ll[i], ll[j])-1])\n all_ij -= (pref1[max(rr[i], rr[j])] - pref1[interR])\n all_ij -= (pref2[interR] - pref2[interL-1])\n else:\n all_ij -= (pref1[rr[i]] - pref1[ll[i]-1])\n all_ij -= (pref1[rr[j]] - pref1[ll[j]-1])\n\n maxBlocks = max(maxBlocks, all_ij)\n\n print(maxBlocks)\n\n\ndef __starting_point():\n main()\n__starting_point()", "import sys\nimport copy\ninput = sys.stdin.readline\n\nn,q=list(map(int,input().split()))\nQ=[list(map(int,input().split())) for i in range(q)]\nQ.sort()\n\nLIST=[0]*(n+2)\nfor l ,r in Q:\n LIST[l]+=1\n LIST[r+1]-=1\n\nSUM=[0]\nfor i in range(1,n+2):\n SUM.append(LIST[i]+SUM[-1])\n\nONES=[0]\nTWOS=[0]\n\nfor i in range(1,n+2):\n if SUM[i]==1:\n ONES.append(ONES[-1]+1)\n else:\n ONES.append(ONES[-1])\n\n if SUM[i]==2:\n TWOS.append(TWOS[-1]+1)\n else:\n TWOS.append(TWOS[-1])\n\nANS=sum([1 for a in SUM if a>=1])\nMINUS=10**10\nfor i in range(q-1):\n for j in range(i+1,q):\n l0,r0=Q[i][0],Q[i][1]\n l1,r1=Q[j][0],Q[j][1]\n\n if l1>r0:\n MICAN=(ONES[r0]-ONES[l0-1])+(ONES[r1]-ONES[l1-1])\n\n elif l1<=r0 and r1>r0:\n MICAN=(ONES[l1-1]-ONES[l0-1])+(TWOS[r0]-TWOS[l1-1])+(ONES[r1]-ONES[r0])\n\n elif l1<=r0 and r1<=r0:\n MICAN=(ONES[l1-1]-ONES[l0-1])+(TWOS[r1]-TWOS[l1-1])+(ONES[r0]-ONES[r1])\n\n if MICAN<MINUS:\n MINUS=MICAN\n \n #print(i,j)\n #print(l0,r0,l1,r1)\n #print(MICAN)\n\nprint(ANS-MINUS)\n \n \n \n\n\n\n\n", "\ndef __starting_point():\n N,Q = list(map(int,input().strip().split()))\n \n painters = []\n for i in range(Q):\n painters.append(tuple(map(int,input().strip().split())))\n C = [[] for i in range(N+1)]\n for i in range(len(painters)):\n start,end = painters[i]\n for j in range(start,end+1):\n C[j].append(i)\n C = C[1:]\n total = sum(1 for i in C if len(i) > 0)\n count = [[0 for i in range(Q)] for j in range(Q)]\n for i in range(N):\n if len(C[i]) == 2:\n count[C[i][0]][C[i][1]] += 1\n count[C[i][1]][C[i][0]] += 1\n if len(C[i]) == 1:\n for j in range(Q):\n if j != C[i][0]:\n count[C[i][0]][j] += 1\n count[j][C[i][0]] += 1\n mini = 100000\n for i in range(Q):\n for j in range(Q):\n if i != j and count[i][j] < mini:\n mini = count[i][j]\n print(total - mini)\n \n\n__starting_point()", "n, q = list(map(int, input().split()))\na = []\nar = [0 for i in range(n + 1)]\nfor i in range(q):\n l, r = list(map(int, input().split()))\n l -= 1\n r -= 1\n a.append((l, r))\n ar[l] += 1\n ar[r + 1] += -1\nplus = 0\nfor i in range(n):\n plus += ar[i]\n ar[i] = plus\n\nans = 0\n\nfor i in range(q):\n for j in range(a[i][0], a[i][1] + 1):\n ar[j] -= 1\n\n pref = [0]\n count = 0\n for pos in range(n):\n if ar[pos] > 0:\n count += 1\n\n value = 0\n if ar[pos] == 1:\n value = 1\n pref.append(value + pref[-1])\n\n for pos in range(q):\n if pos != i:\n ans = max(ans, count - (pref[a[pos][1] + 1] - pref[a[pos][0]]))\n\n for j in range(a[i][0], a[i][1] + 1):\n ar[j] += 1\n\nprint(ans)\n", "cnt = lambda s, x: s.count(x)\nii = lambda: int(input())\nsi = lambda: input()\nf = lambda: list(map(int, input().split()))\ndgl = lambda: list(map(int, input()))\nil = lambda: list(map(int, input().split()))\nn,k=f()\nl=[0]*(n+10)\np=[]\nmx=0\nfor _ in range(k):\n a,b=f()\n p.append([a,b])\n l[a]+=1\n l[b+1]-=1\n\npsf=[l[0]]\n\nfor _ in range(1,n+2):\n psf.append(psf[-1]+l[_])\n\nw=sum(i>0 for i in psf)\n\npsf1,psf2=[0],[0]\nfor i in range(1,n+2):\n if psf[i]==1:\n psf1.append(psf1[-1]+1)\n else:\n psf1.append(psf1[-1])\n if psf[i]==2:\n psf2.append(psf2[-1]+1)\n else:\n psf2.append(psf2[-1])\n\n\nfor i in range(k-1):\n for j in range(i+1,k):\n x=w-(psf1[p[i][1]]-psf1[p[i][0]-1])-(psf1[p[j][1]]-psf1[p[j][0]-1])\n l,r=max(p[i][0],p[j][0]),min(p[i][1],p[j][1])\n if l<=r:\n x+=psf1[r]-psf1[l-1]\n x-=psf2[r]-psf2[l-1]\n mx=max(x,mx)\n\n\nprint(mx)\n", "import sys\n# sys.stdin = open('input.txt')\nn, q = list(map(int, input().split()))\nscanline = [0] * n\nmal = []\nans = 0\nfor i in range(q):\n a, b = list(map(int, input().split()))\n a -= 1\n mal.append((a, b))\n scanline[a] += 1\n if b < n:\n scanline[b] -= 1\n\nfor i in range(q):\n scanline[mal[i][0]] -= 1\n if mal[i][1] < n:\n scanline[mal[i][1]] += 1\n ots = [0] * (n + 1)\n not0 = 0\n cur = 0\n inans = -10000000000\n # print(scanline)\n for j in range(1, n + 1):\n cur += scanline[j - 1]\n if cur != 0:\n not0 += 1\n if cur == 1:\n ots[j] = ots[j - 1] + 1\n else:\n ots[j] = ots[j - 1]\n # print(ots)\n for j in range(q):\n if j == i:\n continue\n inans = max(inans, ots[mal[j][0]] - ots[mal[j][1]])\n # print(inans)\n ans = max(ans, inans + not0)\n scanline[mal[i][0]] += 1\n if mal[i][1] < n:\n scanline[mal[i][1]] -= 1\nprint(ans)\n", "n,q=list(map(int,input().split()))\na=[list(map(int,input().split())) for _ in range(q)]\nc=[0]*5005\nfor i in range(q):\n for j in range(a[i][0],a[i][1]+1):\n c[j]+=1\nans=0\nfor i in range(q):\n tmp=0\n d=c[:]\n for j in range(a[i][0],a[i][1]+1):\n d[j]-=1\n for j in range(5005):\n if d[j]>0:tmp+=1\n b=[0]*5005\n for j in range(1,n+1):\n b[j]=b[j-1]\n if d[j]==1:b[j]+=1\n for j in range(i+1,q):\n ans=max(ans,tmp-b[a[j][1]]+b[a[j][0]-1])\nprint(ans)\n"]
{ "inputs": [ "7 5\n1 4\n4 5\n5 6\n6 7\n3 5\n", "4 3\n1 1\n2 2\n3 4\n", "4 4\n1 1\n2 2\n2 3\n3 4\n", "3 3\n1 3\n1 1\n2 2\n", "6 3\n1 6\n1 3\n4 6\n", "3 3\n1 1\n2 3\n2 3\n", "3 4\n1 3\n1 1\n2 2\n3 3\n", "233 3\n1 2\n2 3\n3 4\n", "5 3\n5 5\n1 3\n3 5\n", "4 5\n1 4\n1 1\n2 2\n3 3\n4 4\n", "10 3\n1 5\n5 10\n2 8\n", "8 4\n1 5\n1 5\n6 8\n6 8\n", "5000 4\n1 100\n2 100\n1000 1010\n1009 1012\n", "3 3\n1 3\n1 2\n2 3\n", "10 3\n1 2\n2 4\n5 7\n", "30 3\n27 27\n25 27\n15 17\n", "10 3\n1 10\n1 10\n2 9\n", "100 5\n20 25\n17 21\n24 28\n1 2\n30 33\n", "10 5\n1 5\n2 6\n3 7\n4 8\n5 9\n", "5 6\n1 5\n1 1\n2 2\n3 3\n4 4\n5 5\n", "12 6\n1 3\n4 6\n2 5\n7 9\n10 12\n8 11\n", "889 3\n1 777\n555 777\n88 888\n", "10 3\n1 5\n2 3\n4 10\n", "10 4\n1 2\n1 2\n3 10\n3 10\n", "5 5\n1 5\n2 5\n3 5\n4 5\n5 5\n", "1000 3\n1 1\n1 1\n1 1\n", "10 3\n1 10\n1 5\n6 10\n", "5 3\n1 3\n2 3\n4 5\n", "5000 4\n1 1\n2 2\n3 5000\n3 5000\n", "6 4\n1 6\n1 2\n3 4\n5 6\n", "5000 10\n4782 4804\n2909 3096\n3527 3650\n2076 2478\n3775 3877\n149 2710\n4394 4622\n3598 4420\n419 469\n3090 3341\n", "20 3\n1 20\n1 10\n11 20\n", "3 3\n1 3\n2 3\n3 3\n", "30 4\n1 10\n12 13\n13 14\n20 30\n", "5 3\n1 4\n3 5\n4 4\n", "4 3\n1 1\n2 2\n3 3\n", "5 4\n4 4\n3 3\n2 5\n1 1\n", "5 3\n1 4\n1 3\n4 5\n", "287 4\n98 203\n119 212\n227 245\n67 124\n", "4 4\n3 4\n1 2\n3 3\n4 4\n", "19 4\n3 10\n4 11\n13 15\n15 17\n", "5 4\n4 5\n2 4\n5 5\n1 3\n", "16 3\n7 10\n2 12\n4 14\n", "9 5\n5 8\n2 4\n9 9\n6 7\n3 6\n", "16 5\n3 9\n11 15\n1 5\n3 7\n8 10\n", "10 3\n9 10\n6 7\n8 10\n", "41 3\n12 23\n21 37\n15 16\n", "3 3\n1 1\n1 1\n2 3\n", "50 4\n13 46\n11 39\n25 39\n2 11\n", "7 4\n5 6\n1 5\n4 5\n1 3\n", "28 4\n4 24\n18 27\n4 13\n14 18\n", "33 3\n21 31\n11 24\n19 25\n", "48 47\n34 44\n24 45\n21 36\n29 38\n17 29\n20 29\n30 32\n23 40\n47 48\n36 43\n2 37\n27 42\n11 17\n26 47\n4 16\n24 35\n32 47\n8 22\n28 46\n17 26\n36 43\n1 26\n26 40\n26 47\n5 38\n20 33\n6 27\n9 33\n2 7\n17 35\n12 18\n20 36\n20 43\n22 45\n13 44\n3 7\n1 33\n7 45\n20 36\n33 41\n10 11\n29 35\n17 21\n10 24\n39 41\n2 6\n45 46\n", "100 6\n20 25\n17 21\n24 28\n5 7\n31 34\n99 100\n", "15 4\n14 15\n11 15\n8 14\n1 12\n", "16 5\n7 10\n15 15\n12 14\n7 10\n9 9\n", "100 10\n20 25\n17 21\n24 28\n5 7\n31 35\n99 100\n89 90\n50 52\n1 3\n10 10\n", "4 3\n1 3\n2 3\n4 4\n", "7 3\n5 7\n6 6\n4 6\n", "9 3\n2 2\n1 6\n3 9\n", "5000 4\n2 4998\n3 4999\n1 2500\n2501 5000\n", "20 3\n1 20\n11 20\n1 10\n", "43 4\n23 33\n15 36\n3 31\n39 41\n", "4 3\n1 4\n1 2\n3 4\n", "6 4\n1 2\n4 5\n6 6\n1 5\n", "5 4\n1 3\n1 1\n2 2\n3 3\n", "84 6\n1 4\n1 4\n2 4\n2 4\n3 5\n4 6\n", "210 4\n2 8\n1 1\n1 5\n6 10\n", "10 3\n1 7\n9 10\n9 9\n", "14 4\n1 6\n3 5\n10 11\n2 8\n", "33 3\n2 3\n3 3\n2 2\n", "11 3\n1 7\n1 3\n4 7\n", "13 3\n2 3\n2 2\n3 3\n", "10 6\n1 2\n2 3\n1 2\n5 6\n5 8\n10 10\n", "14 3\n1 3\n1 2\n3 4\n", "1011 4\n9 11\n6 11\n2 5\n5 10\n", "5 3\n1 4\n2 3\n3 5\n", "18 3\n9 18\n5 15\n1 2\n", "79 3\n1 4\n2 3\n1 6\n", "10 3\n6 6\n3 6\n7 9\n", "15 3\n2 6\n4 11\n8 13\n", "103 3\n1 3\n3 3\n1 2\n", "12 3\n2 11\n3 12\n4 5\n", "6 5\n1 5\n3 5\n5 5\n4 6\n2 2\n", "9 4\n3 6\n2 9\n5 6\n1 6\n", "100 3\n1 4\n1 2\n3 4\n", "19 3\n4 6\n3 5\n3 4\n", "7 4\n5 7\n3 3\n1 4\n1 5\n", "87 3\n2 5\n4 7\n2 2\n", "6 3\n1 4\n1 3\n1 5\n", "94 3\n3 3\n4 4\n1 1\n", "8 6\n4 7\n4 8\n1 8\n2 7\n4 7\n3 8\n", "68 3\n4 8\n3 8\n1 4\n", "312 3\n6 6\n2 7\n3 7\n", "10 3\n1 6\n1 6\n8 10\n", "103 7\n3 3\n2 3\n1 2\n1 1\n2 3\n3 3\n2 3\n", "10 3\n4 6\n1 3\n1 3\n", "12 3\n2 2\n6 9\n4 8\n", "5 4\n1 1\n2 2\n3 3\n1 3\n", "411 4\n4 11\n11 11\n2 10\n1 8\n", "9 4\n1 4\n5 8\n8 9\n5 7\n", "50 3\n9 26\n16 34\n25 39\n", "39 3\n2 3\n7 9\n2 3\n", "10 3\n1 5\n1 5\n8 8\n", "9 5\n1 2\n4 6\n1 1\n8 9\n1 3\n", "88 3\n1 3\n1 5\n3 8\n", "8 3\n1 4\n5 8\n2 7\n", "811 4\n4 4\n6 11\n6 9\n7 11\n", "510 5\n10 10\n5 7\n2 6\n3 6\n1 3\n", "77 5\n3 6\n1 2\n2 5\n7 7\n1 2\n", "22 4\n9 19\n14 17\n7 18\n6 12\n", "73 3\n2 3\n2 3\n3 3\n", "96 4\n2 5\n2 4\n1 4\n4 6\n", "93 3\n3 3\n3 3\n1 2\n", "12 3\n3 11\n9 12\n2 9\n", "312 4\n4 9\n6 6\n11 12\n1 8\n", "1010 3\n1 6\n5 10\n3 9\n", "17 3\n6 7\n2 3\n3 6\n", "19 5\n9 9\n2 3\n5 7\n1 2\n3 4\n", "10 4\n1 3\n2 5\n4 6\n7 9\n", "94 5\n1 1\n3 4\n2 2\n4 4\n3 3\n", "49 3\n6 8\n2 7\n1 1\n", "17 3\n4 7\n1 6\n1 3\n", "511 4\n4 10\n5 11\n5 6\n3 8\n", "6 3\n1 3\n4 5\n5 6\n", "5000 14\n1847 3022\n2661 3933\n3410 4340\n4239 4645\n4553 4695\n4814 4847\n4840 4895\n4873 4949\n4937 4963\n4961 4984\n4975 4991\n4989 4996\n4993 4999\n4998 5000\n", "3072 11\n1217 1281\n1749 2045\n1935 2137\n2298 2570\n2618 2920\n2873 3015\n2967 3050\n3053 3060\n3061 3065\n3064 3070\n3068 3072\n", "96 5\n46 66\n60 80\n74 90\n88 94\n93 96\n", "13 3\n2 2\n5 12\n1 2\n", "5 4\n1 2\n2 3\n3 4\n5 5\n", "13 3\n5 13\n6 13\n7 12\n", "13 4\n6 12\n2 11\n2 7\n1 7\n", "13 4\n1 9\n9 10\n8 11\n4 11\n", "233 4\n1 5\n2 4\n7 9\n3 3\n", "10 4\n9 9\n5 7\n3 8\n1 5\n", "10 4\n3 5\n2 7\n7 9\n1 2\n", "10 4\n7 10\n9 10\n3 3\n3 8\n", "10 4\n1 4\n2 10\n7 7\n2 10\n", "10 4\n4 9\n4 6\n7 10\n2 4\n", "10 4\n8 9\n1 7\n5 6\n3 8\n", "8 4\n1 4\n2 3\n2 6\n5 7\n", "17 3\n5 16\n4 10\n11 17\n", "10 4\n7 10\n1 7\n2 9\n1 5\n", "10 4\n2 2\n1 7\n1 8\n4 10\n", "10 4\n6 6\n1 5\n5 8\n4 4\n", "10 4\n7 10\n1 9\n3 7\n2 5\n", "10 4\n6 9\n3 7\n5 6\n4 9\n", "10 4\n5 5\n3 9\n3 10\n2 7\n", "10 4\n4 5\n2 6\n9 9\n1 8\n", "10 4\n7 9\n9 9\n2 2\n3 10\n", "8 3\n1 2\n2 4\n4 5\n", "10 4\n5 6\n3 6\n4 10\n4 7\n", "10 4\n3 6\n1 4\n6 10\n9 10\n", "10 4\n4 5\n4 6\n9 10\n3 5\n", "10 4\n3 10\n8 10\n5 9\n1 4\n", "10 4\n2 6\n3 7\n8 10\n1 6\n", "10 4\n3 6\n6 9\n5 8\n8 9\n", "10 4\n4 6\n4 8\n5 9\n1 2\n", "10 4\n2 7\n7 8\n8 10\n5 7\n", "10 4\n4 7\n1 5\n8 9\n4 5\n", "10 4\n6 8\n2 6\n5 6\n3 7\n", "10 4\n5 6\n8 10\n5 5\n4 5\n", "10 4\n2 6\n2 6\n4 9\n1 7\n", "10 4\n2 5\n3 4\n1 4\n1 5\n", "10 4\n3 3\n1 4\n2 6\n5 7\n", "10 4\n6 10\n1 6\n1 3\n2 8\n", "10 4\n3 4\n8 10\n3 5\n1 2\n", "10 4\n3 8\n1 10\n7 8\n6 7\n", "10 4\n3 4\n6 7\n1 4\n3 6\n", "10 4\n2 8\n1 5\n4 7\n2 8\n", "10 4\n4 7\n5 9\n2 4\n6 8\n", "10 4\n2 3\n5 9\n9 10\n6 10\n", "10 4\n2 8\n7 8\n3 7\n1 4\n", "10 4\n3 9\n6 10\n8 10\n5 9\n", "10 4\n2 10\n1 2\n5 6\n4 7\n", "10 4\n7 7\n1 3\n3 7\n6 10\n", "10 4\n9 10\n1 6\n2 7\n4 6\n", "9 4\n1 4\n8 9\n5 7\n5 8\n", "10 4\n5 7\n5 8\n4 4\n3 3\n", "10 4\n7 9\n1 4\n3 8\n7 8\n", "10 4\n5 8\n5 5\n2 3\n4 7\n", "10 4\n3 4\n4 7\n5 5\n5 8\n", "10 4\n7 8\n2 4\n1 7\n1 7\n", "10 4\n4 9\n7 8\n1 1\n2 9\n", "10 4\n6 9\n7 10\n2 6\n7 8\n", "10 4\n2 9\n5 7\n1 7\n10 10\n", "10 4\n6 7\n4 4\n1 3\n6 10\n", "10 4\n2 7\n4 9\n6 7\n1 2\n", "10 4\n1 3\n4 5\n4 8\n2 4\n", "10 4\n3 10\n1 5\n8 10\n2 7\n", "10 4\n4 6\n7 8\n8 9\n6 10\n", "10 4\n3 6\n6 10\n8 8\n7 9\n", "10 4\n1 7\n1 7\n3 7\n2 9\n", "10 4\n3 9\n4 8\n1 5\n4 10\n", "10 4\n9 10\n4 5\n3 7\n1 4\n", "10 4\n2 10\n1 7\n5 8\n5 7\n", "10 4\n2 5\n5 9\n4 9\n5 7\n", "10 4\n3 8\n6 7\n2 7\n4 9\n", "10 4\n3 9\n8 10\n5 9\n3 5\n", "10 4\n3 5\n2 3\n8 10\n1 9\n", "10 4\n1 3\n8 8\n3 9\n3 10\n", "10 4\n7 10\n4 7\n4 5\n1 4\n", "10 4\n8 10\n2 9\n1 6\n6 7\n", "10 4\n2 9\n1 2\n6 7\n4 9\n", "10 4\n8 9\n1 8\n3 6\n5 5\n", "10 4\n8 10\n1 9\n2 8\n1 4\n", "10 4\n4 8\n3 6\n8 10\n5 6\n", "10 4\n2 10\n1 8\n4 10\n9 9\n", "10 4\n5 8\n4 6\n8 10\n6 9\n", "10 4\n5 10\n2 10\n7 9\n1 5\n", "10 4\n6 6\n1 7\n1 9\n10 10\n", "10 4\n1 5\n7 10\n3 10\n6 8\n", "10 4\n7 10\n2 9\n1 6\n10 10\n", "10 4\n3 4\n1 4\n3 6\n4 10\n", "10 4\n6 9\n3 8\n3 5\n1 6\n", "10 4\n7 10\n1 5\n5 7\n1 4\n", "10 4\n3 9\n1 6\n2 8\n3 5\n", "10 4\n4 5\n1 3\n6 9\n4 5\n", "10 4\n6 8\n5 6\n3 5\n1 4\n", "10 4\n1 3\n4 4\n3 7\n9 10\n", "10 4\n2 2\n1 3\n4 7\n2 6\n", "10 4\n3 10\n1 1\n4 5\n3 7\n", "10 4\n5 10\n2 7\n3 4\n1 1\n", "10 4\n2 8\n1 6\n3 7\n3 4\n", "10 4\n1 10\n1 2\n2 8\n1 5\n", "10 4\n1 5\n6 10\n10 10\n4 7\n", "10 4\n3 9\n3 5\n6 10\n2 8\n", "10 4\n1 2\n4 8\n5 9\n7 8\n", "10 4\n1 7\n3 9\n8 10\n5 9\n", "10 4\n5 10\n5 5\n6 8\n9 10\n", "10 4\n3 4\n9 10\n1 7\n2 6\n", "10 4\n2 9\n1 5\n6 10\n3 6\n", "10 4\n3 7\n1 3\n7 8\n1 6\n", "10 4\n4 7\n5 6\n3 6\n5 9\n", "10 4\n4 8\n5 9\n2 5\n6 7\n", "9 4\n4 5\n1 4\n5 9\n2 7\n", "10 4\n2 4\n3 5\n4 4\n8 9\n", "10 4\n1 9\n2 7\n7 10\n6 10\n", "10 4\n3 5\n4 7\n9 10\n1 2\n", "10 4\n4 9\n3 6\n7 10\n7 9\n", "10 4\n2 8\n3 7\n6 6\n1 2\n", "10 4\n3 9\n3 8\n2 2\n6 10\n", "10 4\n3 4\n2 5\n1 2\n3 7\n", "9 4\n5 9\n2 7\n4 5\n1 4\n", "5000 19\n645 651\n282 291\n4850 4861\n1053 1065\n4949 4952\n2942 2962\n316 319\n2060 2067\n271 278\n2315 2327\n4774 4779\n779 792\n4814 4817\n3836 3840\n3044 3055\n1187 1205\n3835 3842\n4139 4154\n3931 3945\n", "10 4\n1 4\n5 8\n6 7\n3 9\n", "10 4\n2 6\n6 6\n8 8\n3 7\n", "10 4\n2 4\n4 9\n4 9\n8 8\n", "10 4\n5 7\n4 6\n8 10\n5 5\n", "10 4\n3 7\n6 10\n3 3\n2 6\n", "10 4\n1 4\n4 7\n6 7\n4 6\n", "10 4\n9 9\n4 7\n8 10\n1 1\n", "10 4\n3 7\n5 9\n5 5\n2 4\n", "10 4\n2 4\n7 9\n7 8\n5 7\n", "10 4\n2 5\n9 10\n6 8\n2 3\n", "10 4\n2 6\n1 4\n8 10\n6 7\n", "10 4\n2 5\n3 8\n6 9\n4 5\n", "10 4\n2 6\n1 2\n2 7\n2 9\n", "10 4\n1 8\n2 9\n8 10\n1 5\n" ], "outputs": [ "7\n", "2\n", "3\n", "3\n", "6\n", "2\n", "3\n", "2\n", "3\n", "4\n", "7\n", "8\n", "111\n", "3\n", "3\n", "3\n", "10\n", "14\n", "9\n", "5\n", "12\n", "801\n", "7\n", "10\n", "5\n", "1\n", "10\n", "3\n", "4999\n", "6\n", "4114\n", "20\n", "3\n", "21\n", "4\n", "1\n", "5\n", "4\n", "146\n", "4\n", "11\n", "5\n", "11\n", "8\n", "14\n", "3\n", "17\n", "2\n", "44\n", "6\n", "24\n", "14\n", "48\n", "17\n", "15\n", "8\n", "28\n", "3\n", "3\n", "7\n", "5000\n", "20\n", "34\n", "4\n", "6\n", "3\n", "6\n", "10\n", "7\n", "9\n", "2\n", "7\n", "2\n", "8\n", "3\n", "10\n", "4\n", "11\n", "6\n", "4\n", "8\n", "3\n", "10\n", "6\n", "9\n", "4\n", "3\n", "7\n", "4\n", "5\n", "1\n", "8\n", "6\n", "6\n", "6\n", "3\n", "3\n", "5\n", "3\n", "11\n", "8\n", "19\n", "3\n", "5\n", "8\n", "6\n", "6\n", "7\n", "7\n", "7\n", "14\n", "2\n", "6\n", "2\n", "9\n", "10\n", "7\n", "4\n", "7\n", "7\n", "4\n", "6\n", "6\n", "9\n", "3\n", "3034\n", "1175\n", "45\n", "8\n", "4\n", "9\n", "12\n", "11\n", "8\n", "8\n", "8\n", "8\n", "10\n", "8\n", "9\n", "7\n", "12\n", "10\n", "10\n", "8\n", "10\n", "7\n", "9\n", "9\n", "9\n", "3\n", "8\n", "9\n", "5\n", "10\n", "9\n", "7\n", "7\n", "9\n", "7\n", "7\n", "5\n", "9\n", "5\n", "7\n", "10\n", "6\n", "10\n", "6\n", "8\n", "8\n", "7\n", "8\n", "8\n", "10\n", "8\n", "8\n", "8\n", "5\n", "8\n", "6\n", "6\n", "8\n", "9\n", "9\n", "9\n", "8\n", "8\n", "8\n", "10\n", "7\n", "8\n", "9\n", "10\n", "7\n", "10\n", "8\n", "8\n", "8\n", "10\n", "10\n", "8\n", "9\n", "9\n", "9\n", "10\n", "7\n", "10\n", "6\n", "10\n", "10\n", "10\n", "10\n", "10\n", "9\n", "9\n", "9\n", "7\n", "7\n", "7\n", "7\n", "9\n", "9\n", "8\n", "10\n", "10\n", "9\n", "7\n", "10\n", "6\n", "9\n", "10\n", "8\n", "7\n", "8\n", "9\n", "5\n", "10\n", "6\n", "8\n", "8\n", "8\n", "7\n", "9\n", "190\n", "9\n", "6\n", "8\n", "6\n", "9\n", "7\n", "7\n", "8\n", "6\n", "7\n", "8\n", "8\n", "9\n", "10\n" ] }
interview
https://codeforces.com/problemset/problem/1132/C
5
Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible. Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a = 3, b = 6. What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened? -----Input----- The only line of input contains four integer numbers n, pos, l, r (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened. -----Output----- Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r]. -----Examples----- Input 6 3 2 4 Output 5 Input 6 3 1 3 Output 1 Input 5 2 1 5 Output 0 -----Note----- In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it. In the second test she only needs to close all the tabs to the right of the current position of the cursor. In the third test Luba doesn't need to do anything.
["n, pos, l, r = map(int, input().split())\n\nif l > 1 and r < n:\n if l <= pos and pos <= r:\n if pos - l < r - pos:\n print(pos - l + 1 + r - l + 1)\n else:\n print(r - pos + 1 + r - l + 1)\n elif pos > r:\n print(pos - r + 1 + r - l + 1)\n else:\n print(l - pos + 1 + r - l + 1)\nelif l == 1 and r < n:\n print(int(abs(pos - r)) + 1)\nelif l > 1 and r == n:\n print(int(abs(pos - l)) + 1)\nelse:\n print(0)", "from sys import stdin as cin\nfrom sys import stdout as cout\n\ndef main():\n n, pos, l, r = list(map(int, cin.readline().split()))\n if l == 1 and r == n:\n print(0)\n return\n if l == 1:\n print(1 + abs(r - pos))\n return\n if r == n:\n print(1 + abs(pos - l))\n return\n if l == r:\n print(2 + abs(pos - l))\n return\n print(2 + min(abs(r - pos), abs(l - pos)) + r - l)\n\nmain()\n", "n, p,l,r =map(int, input().split())\n\ns1,s2 = 0, 0\nl1,l2,r1,r2 = 0, 0 ,0 ,0\np1 = p\nif l > 1:\n l1 += abs(p - l)\n l1 += 1\n p1 = l\nif r < n:\n r1 += abs(r - p1)\n r1 += 1\ns1 = l1+r1\np2 = p\nif r < n:\n r2 += abs(r - p2)\n r2 += 1\n p2 = r\nif l > 1:\n l2 += abs(p2 - l)\n l2 += 1\ns2 = l2+r2\nprint(min(s1, s2))", "n, pos, l, r = map(int, input().split())\nif (l <= pos <= r):\n\tif (l == 1 and r == n):\n\t\tprint(0)\n\telif (l == 1 and r < n):\n\t\tprint(r - pos + 1)\n\telif (r == n and l > 1):\n\t\tprint(pos - l + 1)\n\telse:\n\t\tprint(r - l + min(r - pos, pos - l) + 2)\nelif (pos < l):\n\tif (r == n):\n\t\tprint(l - pos + 1)\n\telse:\n\t\tprint(r - pos + 2)\nelif (pos > r):\n\tif (l == 1):\n\t\tprint(pos - r + 1)\n\telse:\n\t\tprint(pos - l + 2)", "n, pos, l, r = list(map(int, input().split()))\n\nif l == 1 and r == n:\n print(0)\n\nelse:\n if l == 1 and r != n:\n print(abs(pos - r) + 1)\n\n elif l != 1 and r == n:\n print(abs(pos - l) + 1)\n\n else:\n if l <= pos <= r:\n print(r - l + 2 + min(abs(pos - l), abs(pos - r)))\n\n elif pos < l:\n print(r - l + 2 + abs(pos - l))\n\n else:\n print(r - l + 2 + abs(pos - r))\n", "n,pos,l,r = list(map(int,input().split()))\nif (pos > r):\n if (l == 1):\n print(pos-r+1)\n else:\n print(pos-l+2)\nelif(pos < l):\n if (r == n):\n print(l-pos+1)\n else:\n print(r-pos+2)\nelse:\n if (l == 1 and r == n):\n print(0)\n elif l == 1:\n print(r-pos+1)\n elif r == n:\n print(pos-l+1)\n else:\n print(r-l + min(pos-l, r-pos) + 2)\n \n", "n, p, l, r = map(int, input().split())\nif l == 1:\n if r == n:\n print(0)\n else:\n print(abs(p - r) + 1)\nelif r == n:\n print(abs(l - p) + 1)\nelse:\n print(min(abs(p - l), abs(p - r)) + abs(r - l) + 2)", "n, pos, l, r = list(map(int, input().split()))\n\nl_close = l == 1\nr_close = r == n\nans = 0\nif l_close and r_close:\n\tpass\nelif l_close:\n\tans += abs(pos - r) + 1\nelif r_close:\n\tans += abs(pos - l) + 1\nelse:\n\tans += min(abs(pos - r), abs(pos - l)) + 1 + abs(l - r) + 1\n\nprint(ans)\n", "import itertools as it, math, functools as ft\nn, pos, l, r = map(int, input().split())\nres = 0\nif l == 1:\n\tif r == n:\n\t\tres = 0\n\telse:\n\t\tres = abs(pos - r) + 1\nelse:\n\tif r == n:\n\t\tres = abs(pos - l) + 1\n\telse:\n\t\txl = abs(pos - l)\n\t\txr = abs(r - pos)\n\t\tif xl <= xr:\n\t\t\tres = xl + 1\n\t\t\tif l > 1:\n\t\t\t\tres += (r - l) + 1\n\t\telse:\n\t\t\tres = xr + 1\n\t\t\tif r < n:\n\t\t\t\tres += (r - l) + 1\n\nprint(res)", "n,p,l,r=map(int,input().split())\nif l==1 and r==n:print(0)\nelif l==1:print(abs(r-p)+1)\nelif r==n:print(abs(p-l)+1)\nelse:print(min(abs(p-l),abs(r-p))+2+r-l)", "n, pos, l, r = list(map(int, input().split()))\n\nif l == 1 and r == n:\n print(0)\nelif l == 1:\n print(abs(r - pos) + 1)\nelif r == n:\n print(abs(l - pos) + 1)\nelse:\n print(min(abs(l - pos) + 1 + r - l + 1, abs(r - pos) + 1 + r - l + 1))\n", "n, pos, l, r = map(int, input().split())\n\ndef solve(n,pos,l,r):\n if l == 1 and r == n:\n return 0\n elif l == 1:\n return abs(pos-r)+1\n elif r == n:\n return abs(pos-l)+1\n else:\n if l <= pos and pos <= r:\n return abs(r-l) + min(abs(pos-l),abs(pos-r))+2\n elif pos < l:\n return abs(pos-l) + abs(r-l) + 2\n else:\n return abs(pos-r) + abs(r-l) + 2\n\nprint(solve(n,pos,l,r))", "n, pos, l, r = map(int, input().split())\nif r == n and l == 1:\n print(0)\nelif r == n:\n print(abs(pos - l) + 1)\nelif l == 1:\n print(abs(r - pos) + 1)\nelse:\n s1 = abs(r - pos)\n s2 = abs(l - pos)\n print(min(s1, s2) + (r - l) + 2)", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\ndef main():\n n, pos, l, r = [int(_) for _ in input().split(' ')]\n if l is 1 and r == n:\n print(0)\n return\n if l is 1:\n print(abs(r - pos) + 1)\n return\n if r == n:\n print(abs(l - pos) + 1)\n return\n print(min(abs(l - pos), abs(r - pos)) + (r - l) + 2)\n\n\nmain()\n", "\nn, pos, l, r = list(map(int, input().split()))\n\nleft_first = 10**6\nright_first = 10**6\n\nif l == 1 and r == n:\n left_first = 0\nelif l == 1:\n if pos < r:\n right_first = r - pos + 1\n else:\n right_first = pos - r + 1\nelif r == n:\n if pos < l:\n left_first = l - pos + 1\n else:\n left_first = pos - l + 1\nelif pos < l:\n left_first = l - pos + 1 + r - l + 1\nelif l <= pos <= r:\n left_first = pos - l + r - l + 2\n right_first = r - pos + r - l + 2\nelse:\n right_first = pos - r + r - l + 2\n\nprint(min([left_first, right_first]))\n", "n, pos, l, r = [int(v) for v in input().split()]\n\nneedleft = l > 1\nneedright = r < n\nif needleft:\n if needright:\n dl = abs(pos - l)\n dr = abs(pos - r)\n print(min(dl, dr) + 1 + r - l + 1)\n else:\n print(abs(pos - l) + 1)\nelse:\n if needright:\n print(abs(pos - r) + 1)\n else:\n print(0)\n", "n,p,l,r = list(map(int,input().split()))\nif l>1 and r<n:\n t1 = abs(p-l)+(r-l)\n t2 = abs(p-r)+(r-l)\n print(min(t1,t2)+2)\nelif l>1 and r == n:\n print(abs(p-l)+1)\nelif l==1 and r < n:\n print(abs(p-r)+1)\nelse:print(0)\n", "def main():\n\tn, pos, l, r = map(int, input().split())\n\tans = 0\n\tif l <= pos <= r:\n\t\tif l == 1:\n\t\t\tif r == n:\n\t\t\t\tprint(0)\n\t\t\t\treturn\n\t\t\tans += r - pos + 1\n\t\t\tprint(ans)\n\t\t\treturn\n\t\tif r == n:\n\t\t\tans = pos - l + 1\n\t\t\tprint(ans)\n\t\t\treturn\n\t\tans = min(pos - l, r - pos) + r - l + 2\n\t\tprint(ans)\n\t\treturn\n\tif pos > r:\n\t\tans += pos - r + 1\n\t\tif l > 1:\n\t\t\tans += r - l + 1\n\t\tprint(ans)\n\t\treturn\n\tans += l - pos + 1\n\tif r < n:\n\t\tans += r - l + 1\n\tprint(ans)\n\treturn\n\n\nmain()", "def f(a, b, l, r, i):\n if a == l and b == r:\n return 0\n elif a == l and b > r:\n return 1 + abs(i - r)\n elif a < l and b == r:\n return 1 + abs(i - l)\n elif a < l and b > r:\n return 2 + abs(l - r) + min(abs(i - l), abs(i - r))\n\nn, p, l, r = list(map(int, input().split()))\na, b = 1, n\nt = 0\n\nprint(f(a, b, l, r, p))\n", "n, pos, l, r = [int(i) for i in input().split()]\nseconds = 0\n\nif l > 1:\n seconds += 1\n if abs(pos - l) < abs(pos - r) or r == n:\n seconds += abs(pos - l)\n else:\n seconds += r - l\n\nif r < n:\n seconds += 1\n if abs(pos - l) >= abs(pos - r) or l == 1:\n seconds += abs(pos - r)\n else:\n seconds += r - l\nprint(seconds)", "n,pos,l,r=[int(i) for i in input().split()]\nans=0\n\n\nif l==1 and r==n:\n\tans=0\nelif l==1:\n\tans=abs(r-pos)+1\nelif r==n:\n\tans=abs(pos-l)+1\nelse:\n\tans=r-l+2\n\tif pos<l:\n\t\tans+=l-pos\n\telif l<=pos and pos<=r:\n\t\tif abs(pos-l) < abs(r-pos):\n\t\t\tans+=pos-l\n\t\telse:\n\t\t\tans+=r-pos\n\telse:\n\t\tans+=pos-r\nprint(ans)\n\t\t\n", "# B\n\nimport math\n\nn, pos, l, r = list(map(int, input().split()))\n\nif l == 1 and r == n:\n print(0)\nelif l == 1:\n print(int(math.fabs(r - pos) + 1))\nelif r == n:\n print(int(math.fabs(l - pos) + 1))\nelse:\n if pos <= l:\n print(r - pos + 2)\n elif r <= pos:\n print(pos - l + 2)\n else:\n print(min(pos + r - 2*l, 2*r - l - pos) + 2)\n", "n,pos,l,r = map(int,input().split())\n\nif l == 1 and r == n:\n print(0)\nelif l == 1:\n print(abs(r-pos)+1)\nelif r == n:\n print(abs(l-pos)+1)\nelse:\n print(min(abs(l-pos),abs(r-pos)) + r-l + 2)", "\nn,pos,l,r = [int(x) for x in input().split(' ')]\nans = 0\nra = abs(pos-r)\nla = abs(pos-l)\nif l==1:\n if r==n:\n print(0)\n else:\n print(ra+1)\nelse:\n if r==n:\n print(la+1)\n else:\n if la<ra:\n print(r-l+2+la)\n else:\n print(r-l+2+ra)", "n,pos,l,r = [int(i) for i in input().split()]\n\ntime_l = 0;\nif l != 1:\n time_l += abs(pos - l) + 1 # move to l and delete\n pos1 = l\nelse:\n pos1 = pos\nif r != n: time_l += abs(r-pos1) + 1 # move to r and delete\n\ntime_r = 0;\nif r != n:\n time_r += abs(pos - r) + 1 # move to l and delete\n pos1 = r\nelse:\n pos1 = pos\nif l != 1: time_r += abs(pos1-l) + 1 # move to r and delete\n\n#print(time_l, time_r)\nprint(min(time_l, time_r))\n"]
{ "inputs": [ "6 3 2 4\n", "6 3 1 3\n", "5 2 1 5\n", "100 1 1 99\n", "100 50 1 99\n", "100 99 1 99\n", "100 100 1 99\n", "100 50 2 100\n", "100 1 100 100\n", "100 50 50 50\n", "6 4 2 5\n", "100 5 2 50\n", "10 7 3 9\n", "7 4 2 5\n", "43 16 2 18\n", "100 50 2 51\n", "6 5 2 4\n", "10 5 2 7\n", "10 10 2 9\n", "10 7 3 7\n", "64 64 8 44\n", "5 4 2 4\n", "6 6 3 5\n", "10 6 2 7\n", "8 6 2 7\n", "7 5 2 4\n", "7 5 2 6\n", "100 50 49 99\n", "100 50 2 99\n", "10 9 2 9\n", "10 10 7 9\n", "8 4 2 7\n", "100 50 2 2\n", "10 4 3 7\n", "6 3 2 5\n", "53 17 13 18\n", "10 6 3 6\n", "9 8 2 5\n", "100 50 2 3\n", "10 7 2 9\n", "6 1 2 5\n", "7 6 2 4\n", "26 12 2 4\n", "10 8 3 7\n", "100 97 3 98\n", "6 2 2 4\n", "9 2 4 6\n", "6 6 2 4\n", "50 2 25 49\n", "5 5 2 3\n", "49 11 2 17\n", "10 3 2 9\n", "10 6 3 7\n", "6 1 5 5\n", "5 5 3 4\n", "10 2 5 6\n", "7 7 3 4\n", "7 3 2 3\n", "5 1 2 4\n", "100 53 2 99\n", "10 2 4 7\n", "5 2 1 4\n", "100 65 41 84\n", "33 20 7 17\n", "7 2 3 6\n", "77 64 10 65\n", "6 1 3 4\n", "6 4 2 4\n", "11 8 2 10\n", "7 1 3 6\n", "100 50 2 50\n", "50 49 5 8\n", "15 1 10 13\n", "13 9 5 11\n", "20 3 5 8\n", "10 5 2 3\n", "7 1 3 5\n", "7 2 3 4\n", "10 5 2 5\n", "8 5 2 6\n", "8 5 3 6\n", "9 6 3 7\n", "50 46 34 37\n", "10 7 2 8\n", "8 3 1 4\n", "100 3 10 20\n", "6 2 1 5\n", "12 11 5 10\n", "98 97 72 83\n", "100 5 3 98\n", "8 5 2 7\n", "10 10 4 6\n", "10 4 2 5\n", "3 3 2 3\n", "75 30 6 33\n", "4 3 2 3\n", "2 2 1 1\n", "2 2 1 2\n", "1 1 1 1\n", "20 9 7 17\n", "10 2 3 7\n", "100 40 30 80\n", "10 6 2 3\n", "7 3 2 5\n", "10 6 2 9\n", "23 20 19 22\n", "100 100 1 1\n", "10 2 5 9\n", "9 7 2 8\n", "100 50 50 100\n", "3 1 2 2\n", "16 13 2 15\n", "9 8 2 6\n", "43 22 9 24\n", "5 4 2 3\n", "82 72 66 75\n", "7 4 5 6\n", "100 50 51 51\n", "6 5 2 6\n", "4 4 2 2\n", "4 3 2 4\n", "2 2 2 2\n", "6 1 2 4\n", "2 1 1 1\n", "4 2 2 3\n", "2 1 1 2\n", "5 4 1 2\n", "100 100 2 99\n", "10 6 3 4\n", "100 74 30 60\n", "4 1 2 3\n", "100 50 3 79\n", "10 6 2 8\n", "100 51 23 33\n", "3 1 2 3\n", "29 13 14 23\n", "6 5 2 5\n", "10 2 3 5\n", "9 3 1 6\n", "45 33 23 37\n", "100 99 1 98\n", "100 79 29 68\n", "7 7 6 6\n", "100 4 30 60\n", "100 33 50 50\n", "50 2 34 37\n", "100 70 2 99\n", "6 6 4 4\n", "41 24 14 19\n", "100 54 52 55\n", "10 5 3 6\n", "6 5 4 6\n", "10 9 2 3\n", "6 4 2 3\n", "100 68 5 49\n", "8 4 3 6\n", "9 3 2 8\n", "100 50 1 1\n", "10 9 5 9\n", "62 54 2 54\n", "100 54 30 60\n", "6 6 6 6\n", "10 2 2 9\n", "50 3 23 25\n", "24 1 5 18\n", "43 35 23 34\n", "50 46 23 26\n", "10 8 5 9\n", "6 2 2 5\n", "43 1 13 41\n", "13 2 1 5\n", "6 3 3 5\n", "14 10 4 12\n", "5 1 4 4\n", "3 3 1 1\n", "17 17 12 14\n", "20 15 6 7\n", "86 36 8 70\n", "100 69 39 58\n", "3 3 2 2\n", "3 2 1 1\n", "9 7 3 8\n", "4 4 2 3\n", "100 4 2 5\n", "100 65 5 13\n", "3 2 2 3\n", "44 38 20 28\n", "100 65 58 60\n", "16 12 8 13\n", "11 8 4 9\n", "20 9 2 10\n", "5 5 4 5\n", "100 99 1 50\n", "6 5 3 5\n", "50 29 7 48\n", "26 11 1 24\n", "5 2 3 4\n", "100 1 2 3\n", "100 60 27 56\n", "6 4 2 6\n", "8 7 3 5\n", "4 1 3 3\n", "12 9 2 10\n", "100 25 9 19\n", "10 7 3 8\n", "7 3 2 6\n", "100 39 4 40\n", "100 51 2 99\n", "15 6 4 10\n", "10 4 4 9\n", "6 4 3 4\n", "14 7 4 12\n", "4 4 1 2\n", "6 5 2 3\n", "12 12 5 5\n", "10 5 3 5\n", "8 6 2 2\n", "8 7 2 7\n", "100 33 5 60\n", "100 32 5 60\n", "79 5 3 5\n", "85 85 85 85\n", "69 69 69 69\n", "7 5 3 6\n", "7 4 2 6\n", "2 1 2 2\n", "100 2 1 90\n", "100 89 11 90\n", "10 1 2 8\n" ], "outputs": [ "5\n", "1\n", "0\n", "99\n", "50\n", "1\n", "2\n", "49\n", "100\n", "2\n", "6\n", "53\n", "10\n", "6\n", "20\n", "52\n", "5\n", "9\n", "10\n", "6\n", "58\n", "4\n", "5\n", "8\n", "8\n", "5\n", "7\n", "53\n", "147\n", "9\n", "5\n", "9\n", "50\n", "7\n", "6\n", "8\n", "5\n", "8\n", "50\n", "11\n", "6\n", "6\n", "12\n", "7\n", "98\n", "4\n", "6\n", "6\n", "49\n", "5\n", "23\n", "10\n", "7\n", "6\n", "4\n", "6\n", "6\n", "3\n", "5\n", "145\n", "7\n", "3\n", "64\n", "15\n", "6\n", "58\n", "5\n", "4\n", "12\n", "7\n", "50\n", "46\n", "14\n", "10\n", "7\n", "5\n", "6\n", "4\n", "5\n", "7\n", "6\n", "7\n", "14\n", "9\n", "2\n", "19\n", "4\n", "8\n", "27\n", "99\n", "9\n", "8\n", "6\n", "2\n", "32\n", "3\n", "2\n", "0\n", "0\n", "14\n", "7\n", "62\n", "6\n", "6\n", "12\n", "6\n", "100\n", "9\n", "9\n", "1\n", "3\n", "17\n", "8\n", "19\n", "4\n", "14\n", "4\n", "3\n", "4\n", "4\n", "2\n", "1\n", "5\n", "1\n", "3\n", "0\n", "3\n", "100\n", "5\n", "46\n", "4\n", "107\n", "10\n", "30\n", "2\n", "12\n", "5\n", "5\n", "4\n", "20\n", "2\n", "52\n", "3\n", "58\n", "19\n", "37\n", "128\n", "4\n", "12\n", "6\n", "6\n", "2\n", "9\n", "4\n", "65\n", "6\n", "9\n", "50\n", "6\n", "54\n", "38\n", "1\n", "9\n", "24\n", "19\n", "14\n", "25\n", "7\n", "5\n", "42\n", "4\n", "4\n", "12\n", "5\n", "3\n", "7\n", "11\n", "92\n", "32\n", "3\n", "2\n", "8\n", "4\n", "6\n", "62\n", "1\n", "20\n", "9\n", "8\n", "8\n", "11\n", "2\n", "50\n", "4\n", "62\n", "14\n", "4\n", "4\n", "35\n", "3\n", "6\n", "4\n", "11\n", "18\n", "8\n", "7\n", "39\n", "147\n", "10\n", "7\n", "3\n", "13\n", "3\n", "5\n", "9\n", "4\n", "6\n", "7\n", "84\n", "84\n", "4\n", "1\n", "1\n", "6\n", "8\n", "2\n", "89\n", "82\n", "9\n" ] }
interview
https://codeforces.com/problemset/problem/915/B
7
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..." More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of n grains was full. Then, every day (starting with the first day) the following happens: m grains are brought to the barn. If m grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account). Sparrows come and eat grain. In the i-th day i sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing. Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day! -----Input----- The only line of the input contains two integers n and m (1 ≤ n, m ≤ 10^18) — the capacity of the barn and the number of grains that are brought every day. -----Output----- Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one. -----Examples----- Input 5 2 Output 4 Input 8 1 Output 5 -----Note----- In the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens: At the beginning of the first day grain is brought to the barn. It's full, so nothing happens. At the end of the first day one sparrow comes and eats one grain, so 5 - 1 = 4 grains remain. At the beginning of the second day two grains are brought. The barn becomes full and one grain doesn't fit to it. At the end of the second day two sparrows come. 5 - 2 = 3 grains remain. At the beginning of the third day two grains are brought. The barn becomes full again. At the end of the third day three sparrows come and eat grain. 5 - 3 = 2 grains remain. At the beginning of the fourth day grain is brought again. 2 + 2 = 4 grains remain. At the end of the fourth day four sparrows come and eat grain. 4 - 4 = 0 grains remain. The barn is empty. So the answer is 4, because by the end of the fourth day the barn becomes empty.
["n, m = map(int, input().split())\nif (m >= n): print(n)\nelse:\n c = n - m\n l = 0\n r = 10 ** 18\n while r - l > 1:\n md = (r + l) // 2\n if (1 + md) * md // 2 < c:\n l = md\n else:\n r = md\n print(r + m)", "n, m = map(int, input().split())\n\ndef calc(n):\n\treturn (n + 1) * n // 2\n\nif n <= m:\n\tprint(n)\nelse:\n\tans = m\n\tl = 0\n\tr = n - m\n\twhile l < r - 1:\n\t\tmid = (l + r) // 2\n\t\tif calc(mid) >= n - m:\n\t\t\tr = mid\n\t\telse:\n\t\t\tl = mid\n\n\tif calc(l) >= n - m:\n\t\tr = l\n\tans += r\n\tprint(ans)", "n,m = list(map(int,input().split()))\nif m >= n:\n print(n)\nelse:\n ans = m\n pos = -1\n low = 0\n high = 10**12\n n -= m\n while low <= high:\n mid = (low+high)//2\n # print(mid,(mid*(mid+1))//2)\n if (mid*(mid+1))//2 >= n:\n pos = mid\n high = mid-1\n else:\n low = mid+1\n print(ans+pos)\n", "n, m = map(int, input().split())\n\nif n <= m:\n print(n)\nelse:\n ok = 10 ** 100\n ng = 0\n while ok - ng > 1:\n mid = (ok + ng) // 2\n s = n - mid * (mid - 1) // 2 - (m + mid)\n\n if s <= 0:\n ok = mid\n else:\n ng = mid\n\n print(ok + m)", "import sys\nn, m = list(map(int, input().split()))\n\n\ndef check(i):\n se = ((m + i) * (i - m + 1)) // 2\n pr = m * (i - m + 1)\n if (n >= (se - pr)):\n return True\n else:\n return False\nif m >= n:\n print(n)\n return\nm += 1\nleft = m\nright = int(5e18) + 10\nn -= m\nwhile (right - left > 1):\n mid = (left + right) // 2\n if (check(mid)):\n left = mid\n else:\n right = mid\nprint(left)\n", "import sys\nn,m=input().split()\nn=int(n);m=int(m)\nans=m\nif m>=n:\n\tprint(n)\n\treturn\nhigh=10**20;low=1\ndif=n-m\n#print(\"dif\",dif)\nwhile high-low>5:\n\tmid=high+low>>1\n\tif (1+mid)*mid>>1>=dif:\n\t\thigh=mid\n\telse:\n\t\tlow=mid\nmid=max(0,mid-10)\nwhile (1+mid)*mid>>1<dif:mid+=1\n#print('mid',mid)\nans+=mid\nprint(ans)", "N, M = list(map(int, input().split()))\n\nif N <= M:\n print(N)\nelse:\n low = M + 1\n high = 1000000000000000000\n while high - low > 0:\n mid = (low + high) // 2\n if N + (mid - (M + 1)) * M - ((mid - M) * (M + 1 + mid) // 2) <= 0:\n high = mid\n else:\n low = mid + 1\n print(low)\n", "import sys\n\nn, m = list(map(int, input().split()))\n\nif n <= m:\n print(n)\n return\n\nelse:\n l, r = m + 1, n\n base = m * (m - 1) // 2\n\n while l != r:\n mid = (l + r) // 2\n plus = n + base + (mid - m) * m\n minus = mid * (mid + 1) // 2\n if plus > minus:\n l = mid + 1\n else:\n r = mid\n print(l)\n", "n, m = list(map(int, input().split()))\nif m >= n:\n print(n)\nelse:\n start = n - m + 1\n r = 10 ** 11\n l = -1\n while (r - l > 1):\n mid = (l + r) // 2\n summ = mid * (mid + 1) // 2\n if summ >= n - m:\n r = mid\n else: \n l = mid\n print(r + m)\n\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Mar 15 23:00:22 2017\n\n@author: Anan\n\"\"\"\n\nn,m = map(int,input().split())\n\nif n<=m :\n print(n)\nelse :\n \n ans = m\n L =0\n R = 123456789123456789123\n while R-L != 1 :\n mid = (L+R)//2\n if n-mid*(mid-1)//2 <= m+mid :\n R=mid\n else :\n L=mid\n print(ans + R)", "n,m=[int(i) for i in input().split()]\nif m>=n:\n print(n)\nelse:\n l,r=-1,10**18\n now=n-m\n while r-l>1:\n md=(l+r)//2\n if now+md*m-(m*2+md+1)*md//2<=0:\n r=md\n else:\n l=md\n print(r+m)", "n, m = map(int, input().split())\nif n <= m:\n print(n)\nelse:\n init = m\n n = n - m\n lo = 1\n hi = int(1e19)\n poss = 0\n while hi >= lo:\n mid = (hi + lo) // 2\n consumed = mid * (mid + 1) // 2\n if consumed >= n:\n poss = mid\n hi = mid - 1\n else:\n lo = mid + 1\n print (poss + init)", "n, s = list(map(int,input().split(' ')))\nif n <= s:\n ans = n\nelse:\n ans = s\n l = 0\n r = 10 ** 10\n n -= s\n while l + 1 < r:\n m = (l + r) // 2\n if m * (m+1) // 2 < n:\n l = m\n else:\n r = m\n ans += r\nprint(ans)\n", "n, m = map(int, input().split())\nl = 0\nr = 10 ** 18 + 1\nd = n - m\nwhile r - l > 1:\n mi = (r + l) // 2\n if d > mi *(mi + 1) // 2:\n l = mi\n else:\n r = mi\nif n > m:\n print(r + m)\nelse:\n print(n)", "n, m = map(int, input().split())\nif m >= n:\n print(n)\n return\n\nres = m + 1\nn -= m\nleft, right = 0, int(1e19)\n\nwhile right - left > 1:\n middle = (left + right) // 2\n if middle * (middle + 1) // 2 < n:\n left = middle\n else:\n right = middle\n\nprint(res + left)", "def binary_search_first_true(predicate, from_inclusive, to_inclusive):\n lo = from_inclusive - 1\n hi = to_inclusive + 1\n while hi - lo > 1:\n mid = (lo + hi) // 2\n if not predicate(mid):\n lo = mid\n else:\n hi = mid\n return hi\n\ndef tri(n):\n\treturn n*(n+1)//2\n\ndef f(n, m, t):\n\treturn n-tri(t-m-1)-t\n\ndef solve(n, m):\n\tif m >= n:\n\t\treturn n\n\tans = binary_search_first_true(lambda x: f(n, m, x) <= 0, m+1, n)\n\treturn ans\n\ndef main(sc):\n\tn, m = sc.next_ints(2)\n\tans = solve(n, m)\n\tprint(ans)\n\n\nclass Scanner:\n\tdef __init__(self):\n\t\tself.idx = 0\n\t\tself.tokens = []\n\n\tdef __next__(self):\n\t\twhile self.idx == len(self.tokens) or not len(self.tokens[self.idx]):\n\t\t\tif self.idx == len(self.tokens):\n\t\t\t\tself.idx = 0\n\t\t\t\tself.tokens = input().split()\n\t\t\telse:\n\t\t\t\tself.idx += 1\n\t\tself.idx += 1\n\t\treturn self.tokens[self.idx-1]\n\n\tdef next_string(self):\n\t\treturn next(self)\n\n\tdef next_strings(self, n):\n\t\treturn [self.next_string() for i in range(0, n)]\n\n\tdef next_int(self):\n\t\treturn int(next(self))\n\n\tdef next_ints(self, n):\n\t\treturn [self.next_int() for i in range(0, n)]\n\n\nscanner = Scanner()\nmain(scanner)\n", "n, m = list(map(int, input().split()))\nl = -1\nr = int(1e18 + 10)\nwhile r - l != 1:\n t = (r + l) // 2\n eaten = t\n if (t - 1 > m):\n eaten += (t - 1 - m) * (t - m) // 2\n if eaten >= n:\n r = t\n else:\n l = t\nprint(r)", "def mySqrt(n) :\n l = 0\n r = n + 1\n while (l < r - 1) :\n m = (l + r) // 2\n if m * m > n :\n r = m\n else :\n l = m\n return l\n\n\nn, m = [int(i) for i in input().split()]\n\nif m >= n :\n print(n)\nelse :\n ans = m\n d = (-1 + mySqrt(1 + 8 * (n - m))) // 2\n while d * (d - 1) // 2 + d + m >= n :\n d -= 1\n while d * (d - 1) // 2 + d + m < n :\n d += 1\n print(m + d)\n", "import sys\nn, m = list(map(int, input().split()))\nm = min(n - 1, m)\nfday = -1\nlday = n\nwhile (fday + 1 < lday):\n mid = (fday + lday) // 2\n S = n - (mid * (mid + 1)) // 2 - m\n if (S <= 0):\n lday = mid\n else:\n fday = mid\nprint(min(n, m + lday))\n", "n, m = map(int, input().split())\ntl = m\ntr = n\nwhile tr - tl > 1:\n mid = (tr + tl) // 2\n val = (mid - m) * (mid - m + 1) // 2\n bef = (mid - m) * (mid - m - 1) // 2\n if val >= n or n - bef <= mid:\n tr = mid\n else:\n tl = mid\nprint (tr) ", "n, m = [int(x) for x in input().split()]\nif (m >= n):\n print(n)\n return\nL = m\nR = n\nwhile (L + 1 < R):\n M = (L + R) // 2\n z = M - m\n if (z * (z - 1) // 2 + M >= n):\n R = M\n else:\n L = M\nprint(R)\n", "n, m = map(int, input().split())\n\nl = 0\nr = 2 ** 64\n\nwhile r - l > 1:\n\tM = l + r >> 1\n\tdell = M * (M + 1) // 2 - m * (m + 1) // 2;\n\tplus = n + max(0, M - m - 1) * m\n\tif dell >= plus :\n\t\tr = M\n\telse:\n\t\tl = M\nprint(min(r, n))", "\"\"\"Codeforces Round #404 (Div. 2)\n\nC. Anton and Fairy Tale\n\"\"\"\n\n\ndef main():\n n, m = list(map(int, input().split()))\n\n if n <= m:\n print(n)\n return\n\n def func(k):\n return n + (k - m - 1) * m + ((m * (m + 1)) // 2) - ((k * (k + 1)) // 2)\n\n start, end = m + 1, n\n while start < end:\n middle = (start + end) // 2\n if func(middle) <= 0:\n end = middle\n else:\n start = middle + 1\n\n print(end)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "\nn, m = map(int, input().split())\n\nif n <= m:\n print(n)\n return\n\ntl = m\ntr = n\nwhile tr - tl > 1:\n tm = (tl + tr) // 2\n cnt = tm * (tm + 1) // 2 - m * (m + 1) // 2\n cur = n + (tm - m - 1) * m - cnt\n if cur <= 0:\n tr = tm\n else:\n tl = tm\nprint(tr)", "\ndef f(i, fd, m, n):\n return i * (i + 1) // 2 - fd * (fd - 1) // 2 >= (i - fd) * m + n\n\ndef solve(n, m):\n if m >= n:\n return n\n fd = m\n l = fd\n r = max(n, m) + 100\n while l < r:\n mid = (l + r) // 2\n #print(\"mid = \" + str(mid))\n #print(\"f = \" + str(f(mid,fd,m,n)))\n if f(mid, fd, m, n):\n r = mid\n else:\n l = mid + 1\n # print(\"now l = \" + str(l) + \" r = \" + str(r) + \" \" + str((l == r - 1)))\n \n if l == r - 1:\n #print(\"last l = \" + str(l) + \" fl = \" + str(f(l, fd,m,n)))\n if f(l, fd, m, n):\n r = l\n else:\n l = r\n return l\ndef brute(n, m):\n i = 1\n cur = n\n while True:\n cur += m\n cur = min(cur, n)\n cur -= i\n if (cur <= 0):break\n i += 1\n return i\nn, m = map(int, input().split());\nprint(solve(n, m))"]
{ "inputs": [ "5 2\n", "8 1\n", "32 5\n", "1024 1024\n", "58044 52909\n", "996478063 658866858\n", "570441179141911871 511467058318039545\n", "1 1\n", "1000000000000000000 1000000000000000000\n", "1000000000000000000 999999999999997145\n", "1 1000000000000000000\n", "1000000000000000000 1\n", "999999998765257149 10\n", "999999998765257150 10\n", "999999998765257151 10\n", "999999998765257152 10\n", "999999998765257153 10\n", "762078938126917521 107528\n", "762078938126917522 107528\n", "762078938126917523 107528\n", "762078938126917524 107528\n", "762078938126917525 107528\n", "443233170968441395 1048576\n", "443233170968441396 1048576\n", "443233170968441397 1048576\n", "1833551251625340 1359260576251\n", "1835002539467264 2810548418174\n", "1840276176082280 8084185033189\n", "262133107905 256256256256\n", "262133108160 256256256256\n", "262133108161 256256256256\n", "262133108162 256256256256\n", "399823373917798976 326385530977846185\n", "836052329491347820 327211774155929609\n", "870979176282270170 16\n", "930580173005562081 4\n", "831613653237860272 154\n", "867842613106376421 178\n", "939156247712499033 1902\n", "975385203286047886 1326\n", "953065701826839766 4023\n", "989294657400388618 7447\n", "885695753008586140 42775\n", "921924708582134992 158903\n", "802352815201515314 183504\n", "861953807629839929 1299632\n", "925155772916259712 1929889\n", "961384732784775860 5046017\n", "910494856396204496 39891744\n", "946723811969753348 17975168\n", "992316381103677158 1849603453\n", "828545340972193305 1027686877\n", "946697532222325132 16179805162\n", "982926487795873985 19357888587\n", "892753091050063317 2037020896\n", "928982046623612170 45215104320\n", "845950022554437217 1553155668877\n", "882178982422953366 1792038785005\n", "847407611288100389 9111983407070\n", "883636566861649242 15350866523198\n", "988545172809612094 126043487780965\n", "824774128383160945 152286665864389\n", "889067279135046636 783632221444127\n", "925296230413628192 1609871104560255\n", "892888041747308306 15921193742955831\n", "929116997320857159 16747432626071959\n", "810365749050428005 176443295773423092\n", "846594708918944153 177269538951506516\n", "2 1\n", "2 2\n", "3 1\n", "3 2\n", "3 3\n", "4 1\n", "4 2\n", "256 20\n", "78520 8\n", "1367064836 777314907868410435\n", "658866858 996478063\n", "10 648271718824741275\n", "326385530977846185 399823373917798976\n", "327211774155929609 836052329491347820\n", "2570 566042149577952145\n", "512486308421983105 512486308421983105\n", "262144 262144\n", "314159265358979323 314159265358979323\n", "16 5\n", "29 16\n", "24 14\n", "28 18\n", "8 11\n", "500000000500004239 4242\n", "500000000500004240 4242\n", "500000000500004241 4242\n", "500000000500004242 4242\n", "500000000500004243 4242\n", "500000000500004244 4242\n", "500000000500004245 4242\n", "163162808800191208 163162808800191206\n", "328584130811799021 328584130811799020\n", "89633000579612779 89633000579612778\n", "924211674273037668 924211674273037666\n", "758790352261429854 758790352261429851\n", "39154349371830603 39154349371830597\n", "313727604417502165 313727604417502155\n", "1000000000000000000 999999999999999999\n", "1000000000000000000 999999999999999998\n", "1000000000000000000 999999999999999997\n", "1000000000000000000 999999999999999996\n", "1000000000000000000 999999999999999995\n", "1 5\n", "1 100\n", "1 3\n", "6 9\n", "1000000000000000000 2\n", "1 10\n", "5 15\n", "12 1\n", "1000000000000000000 100000000000000000\n", "100 200\n", "1 1000000000000000\n", "100000000000000000 1\n", "1000000000000000000 1000000000000000\n", "1 9\n", "1000000000000000000 4\n", "1000000000000 10000000000000\n", "1 100000\n", "3 7\n", "2 3\n", "1 8\n", "5 10\n", "10 11\n", "10 100\n", "5 16\n", "2 10\n", "10836 16097\n", "16808 75250\n", "900000000000169293 1\n", "1 10000000\n", "2 100\n", "10 20\n", "10 10000\n", "4 5\n", "1 2\n", "1000000000000000000 5\n", "2 5\n", "4 6\n", "999999998765257147 1\n", "3 10\n", "997270248313594436 707405570208615798\n", "1 100000000000\n", "6 1000000\n", "16808 282475250\n", "1000000007 100000000000007\n", "1 1000\n", "1000000000000000 10000000000000000\n", "1000000000000000000 100\n", "1000000000000000000 9\n", "900000000000169293 171\n", "1 999999999999\n", "10000 10000000000000\n", "1 9999999999999\n", "695968090125646936 429718492544794353\n", "2 5000\n", "8 100\n", "2 7\n", "999999999999999999 1\n", "5 8\n", "1000000000000000000 99999999999999999\n", "100000000000000000 100000000000000000\n", "5 6\n", "1000000000000000000 1000000000\n", "1 10000\n", "22 11\n", "10 10000000\n", "3 8\n", "10 123123\n", "3 5\n", "1000000000000000000 10\n", "10000000000000 45687987897897\n", "5 4\n", "5000 123456789\n", "7 100\n", "1000000000000000000 500000000000\n", "8 7\n", "1 10000000000\n", "1000000000000000000 15\n", "1 123456789\n", "2 1000\n", "5 11\n", "1 1000000000\n", "1000000000000000000 499999999999999999\n", "1 100000000\n", "619768314833382029 108339531052386197\n", "5 100\n", "2 10000\n", "1000000000000000000 500000000000000000\n", "143 3\n", "2 6\n", "100 1000000000\n", "2 100000000000000000\n", "100000000000000000 1000000000000000000\n", "999999999999999999 123456789\n", "1 99999\n", "1000000000000000000 9999999999\n", "5 100000000000000000\n", "6 999999\n", "100 10000000\n", "4 100\n", "1000000000 1000000000000000\n", "10 100000\n", "5 15555555\n", "5 155555\n", "200 9999999999\n", "3 200\n", "1000000000000000000 490000000000000000\n", "2 4\n", "5 15555\n", "5 7\n", "10040 200000\n", "1000000000000000000 60000000000000000\n", "10 1000000000000\n", "1 45\n" ], "outputs": [ "4\n", "5\n", "12\n", "1024\n", "53010\n", "658892843\n", "511467058661475480\n", "1\n", "1000000000000000000\n", "999999999999997221\n", "1\n", "1414213563\n", "1414213571\n", "1414213571\n", "1414213571\n", "1414213572\n", "1414213572\n", "1234675418\n", "1234675418\n", "1234675418\n", "1234675419\n", "1234675419\n", "942571991\n", "942571991\n", "942571992\n", "1359321110406\n", "2810608952329\n", "8084245567345\n", "256256364670\n", "256256364670\n", "256256364670\n", "256256364671\n", "326385531361089823\n", "327211775164731428\n", "1319832715\n", "1364243511\n", "1289661856\n", "1317454248\n", "1370517314\n", "1396701153\n", "1380631201\n", "1406630820\n", "1330979102\n", "1358043072\n", "1266953266\n", "1314276256\n", "1362191462\n", "1391685648\n", "1389332262\n", "1394001194\n", "3258373398\n", "2314967219\n", "17555812078\n", "20759977363\n", "3373249237\n", "46578175853\n", "1554456398264\n", "1793367075026\n", "9113285250762\n", "15352195899906\n", "126044893781768\n", "152287950093217\n", "783633554323452\n", "1609872463741155\n", "15921195067317449\n", "16747433976901012\n", "176443296899409285\n", "177269540108507095\n", "2\n", "2\n", "3\n", "3\n", "3\n", "3\n", "4\n", "42\n", "404\n", "1367064836\n", "658866858\n", "10\n", "326385530977846185\n", "327211774155929609\n", "2570\n", "512486308421983105\n", "262144\n", "314159265358979323\n", "10\n", "21\n", "18\n", "22\n", "8\n", "1000004242\n", "1000004242\n", "1000004242\n", "1000004242\n", "1000004243\n", "1000004243\n", "1000004243\n", "163162808800191208\n", "328584130811799021\n", "89633000579612779\n", "924211674273037668\n", "758790352261429853\n", "39154349371830600\n", "313727604417502159\n", "1000000000000000000\n", "1000000000000000000\n", "999999999999999999\n", "999999999999999999\n", "999999999999999998\n", "1\n", "1\n", "1\n", "6\n", "1414213564\n", "1\n", "5\n", "6\n", "100000001341640786\n", "100\n", "1\n", "447213596\n", "1000001413506279\n", "1\n", "1414213566\n", "1000000000000\n", "1\n", "3\n", "2\n", "1\n", "5\n", "10\n", "10\n", "5\n", "2\n", "10836\n", "16808\n", "1341640788\n", "1\n", "2\n", "10\n", "10\n", "4\n", "1\n", "1414213567\n", "2\n", "4\n", "1414213563\n", "3\n", "707405570970015402\n", "1\n", "6\n", "16808\n", "1000000007\n", "1\n", "1000000000000000\n", "1414213662\n", "1414213571\n", "1341640957\n", "1\n", "10000\n", "1\n", "429718493274519777\n", "2\n", "8\n", "2\n", "1414213563\n", "5\n", "100000001341640785\n", "100000000000000000\n", "5\n", "2414213562\n", "1\n", "16\n", "10\n", "3\n", "10\n", "3\n", "1414213572\n", "10000000000000\n", "5\n", "5000\n", "7\n", "501414213209\n", "8\n", "1\n", "1414213577\n", "1\n", "2\n", "5\n", "1\n", "500000000999999999\n", "1\n", "108339532063750408\n", "5\n", "2\n", "500000001000000000\n", "20\n", "2\n", "100\n", "2\n", "100000000000000000\n", "1537670351\n", "1\n", "11414213554\n", "5\n", "6\n", "100\n", "4\n", "1000000000\n", "10\n", "5\n", "5\n", "200\n", "3\n", "490000001009950494\n", "2\n", "5\n", "5\n", "10040\n", "60000001371130920\n", "10\n", "1\n" ] }
interview
https://codeforces.com/problemset/problem/785/C
8
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $1$ to $9$). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, $\ldots$, 9m, 1p, 2p, $\ldots$, 9p, 1s, 2s, $\ldots$, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: A mentsu, also known as meld, is formed by a koutsu or a shuntsu; A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu; [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. -----Input----- The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from $1$ to $9$ and the second character is m, p or s. -----Output----- Print a single integer — the minimum number of extra suited tiles she needs to draw. -----Examples----- Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 -----Note----- In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
["cards=list(input().split())\nlm=[0]*9\nlp=[0]*9\nls=[0]*9\nfor item in cards:\n if item[1]=='m':\n lm[int(item[0])-1]+=1\n elif item[1]=='p':\n lp[int(item[0])-1]+=1\n else :\n ls[int(item[0])-1]+=1\nif max(lm)==3 or max(lp)==3 or max(ls)==3:\n print(0)\nelse :\n flag=0\n def seq_checker(li):\n flag=0\n for i in range(9):\n if flag==0:\n if lm[i]==1:\n flag=1\n else :\n if lm[i]==1:\n flag+=1\n else :\n break\n return flag\n if seq_checker(lm)==3 or seq_checker(lp)==3 or seq_checker(ls)==3:\n print(0)\n elif max(lm)==2 or max(lp)==2 or max(ls)==2:\n print(1)\n else :\n m=0\n for i in range(0,7):\n m=max(sum(lm[i:i+3]),sum(lp[i:i+3]),sum(ls[i:i+3]),m)\n print(3-m)", "def check(a, b):\n if a[1] == b[1] and 1 <= abs(int(b[0]) - int(a[0])) <= 2:\n return True\n\narr = input().split()\nd = {}\nfor i in arr:\n d[i] = d.get(i, 0) + 1\nmineq = 3 - max(d.values())\narr.sort(key=lambda x: x[0])\narr.sort(key=lambda x: x[1])\nif check(arr[0], arr[1]) or check(arr[1], arr[2]):\n mineq = min(mineq, 1)\nif arr[0][1] == arr[1][1] == arr[2][1] and int(arr[2][0]) - int(arr[1][0]) == 1 and int(arr[1][0]) - int(arr[0][0]) == 1:\n mineq = 0\nprint(mineq)", "m={\"s\":[0]*9, \"m\":[0]*9, \"p\":[0]*9}\nfor e in input().split():\n m[e[1]][int(e[0])-1]+=1\nret=2\nfor t in \"smp\":\n l=m[t]\n if max(l)>=2:\n ret=min(ret, 3-max(l))\n else:\n for i in range(7):\n seq = sum(l[i:i+3])\n ret = min(ret, 3-seq)\nprint(ret)", "a = input().split()\nst = set([])\ncnt = [[0 for i in range(9)] for i in range(3)]\nfor e in a:\n cnt['mps'.index(e[1])][int(e[0]) - 1] = 1\n st.add(e)\nansw = len(st) - 1\nfor i in range(3):\n for j in range(7):\n answ = min(answ, 3 - sum(cnt[i][j:j + 3]))\nprint(answ)", "s = [0] * 10\nm = [0] * 10\np = [0] * 10\nD = list(input().split())\nfor i in D:\n if i[1] == 'p':\n p[int(i[0])] += 1\n elif i[1] == 'm':\n m[int(i[0])] += 1\n else:\n s[int(i[0])] += 1\n\nneed = 3\nfor i in range(1, 10):\n need = min(3 - p[i], need)\n need = min(3 - s[i], need)\n need = min(3 - m[i], need)\n if i <= 7:\n tmp = 0\n tmp += min(1, p[i])\n tmp += min(1, p[i + 1])\n tmp += min(1, p[i + 2])\n need = min(3 - tmp, need)\n tmp = 0\n tmp += min(1, m[i])\n tmp += min(1, m[i + 1])\n tmp += min(1, m[i + 2])\n need = min(3 - tmp, need)\n tmp = 0\n tmp += min(1, s[i])\n tmp += min(1, s[i + 1])\n tmp += min(1, s[i + 2])\n need = min(3 - tmp, need)\n\nprint(need)\n", "s = input().split()\ns.sort()\nif s[0] == s[1] == s[2]:\n\tprint(0)\n\treturn\nif s[0][1] == s[1][1] == s[2][1]:\n\tif ord(s[0][0]) + 1 == ord(s[1][0]) == ord(s[2][0]) - 1:\n\t\tprint(0)\n\t\treturn\nif s[0][1] == s[1][1] and ord(s[0][0]) + 2 >= ord(s[1][0]) or s[1][1] == s[2][1] and ord(s[1][0]) + 2 >= ord(s[2][0]) or s[0][1] == s[2][1] and ord(s[0][0]) + 2 >= ord(s[2][0]):\n\tprint(1)\n\treturn\nif s[0] == s[1] or s[1] == s[2] or s[0] == s[2]:\n\tprint(1)\n\treturn\nprint(2)\n", "l = input().split()\nif l[0]==l[1] and l[1]==l[2]:\n print(0)\n return\ndef shuntsu(li):\n li.sort()\n return li[0][1]==li[1][1] and li[1][1]==li[2][1] and int(li[1][0])==int(li[0][0])+1 and int(li[2][0])==int(li[1][0])+1\nif shuntsu(l):\n print(0)\n return\nfor k in l:\n if len([x for x in l if x==k]) > 1:\n print(1)\n return\n if len([x for x in l if x[1]==k[1] and int(x[0]) == int(k[0])+1]) !=0:\n print(1)\n return\n if len([x for x in l if x[1]==k[1] and int(x[0]) == int(k[0])+2]) != 0:\n print(1)\n return\nprint(2)\n", "def ism(a, b, c):\n return a==b and b==c\n\ndef isk(a, b, c):\n x = [a, b, c]\n x.sort()\n if x[0][1] == x[1][1] and x[1][1] == x[2][1]:\n if int(x[0][0])+1 == int(x[1][0]) and int(x[1][0])+1 == int(x[2][0]):\n return 1\n return 0\n\na, b, c = input().split()\nx = [a,b,c]\ntypem = []\ntypes = []\ntypep = []\nm, s, p = 0, 0, 0\n\nfor i in x:\n if i[1]=='m':\n m+=1\n typem.append(i)\n elif i[1]=='s':\n s+=1\n types.append(i)\n elif i[1]=='p':\n p+=1\n typep.append(i)\n\nans = 0\ndone = 0\n\nif isk(a,b,c) or ism(a,b,c):\n ans = 0\n done = 1\n\nif done==0 and a==b and b==c:\n ans = 0\n done = 1\n\nelif done==0 and a==b:\n ans = 1\n done = 1\n\nelif done==0 and b==c:\n ans = 1\n done = 1\nelif done==0 and a==c:\n ans = 1\n done = 1\n# Shuntsu\nif done==0 and m>=2:\n typem.sort()\n for i in range(len(typem)-1):\n if abs(int(typem[i][0]) - int(typem[i+1][0])) <= 2 and \\\n abs(int(typem[i][0]) - int(typem[i+1][0])) > 0:\n ans = 1\n done = 1\n \nif done==0 and s>=2:\n types.sort()\n for i in range(len(types)-1):\n if abs(int(types[i][0]) - int(types[i+1][0])) <= 2 and \\\n abs(int(types[i][0]) - int(types[i+1][0])) > 0:\n ans = 1\n done = 1\n\nif done==0 and p>=2:\n typep.sort()\n for i in range(len(typep)-1):\n if abs(int(typep[i][0]) - int(typep[i+1][0])) <= 2 and \\\n abs(int(typep[i][0]) - int(typep[i+1][0])) > 0:\n ans = 1\n done = 1\n\nif done == 0:\n ans = 2\n done = 1\n\nprint(ans)\n", "from sys import stdin, stdout, exit\n\nt1, t2, t3 = stdin.readline().split()\n\nif t1 == t2 and t2 == t3:\n print(0)\n return\n\nts = [(int(t[0]), t[1]) for t in [t1, t2, t3]]\nts.sort()\nns = [t[0] for t in ts]\nss = [t[1] for t in ts]\n\nif ns[0] + 1== ns[1] and ns[0] + 2 == ns[2] and ss[0] == ss[1] and ss[1] == ss[2]:\n print(0)\n return\nif ns[0] + 2 >= ns[1] and ss[1] == ss[0]:\n print(1)\n return\nif ns[1] + 2 >= ns[2] and ss[1] == ss[2]:\n print(1)\n return\nif ns[0] + 2 >= ns[2] and ss[0] == ss[2]:\n print(1)\n return\nif ts[0] == ts[1] or ts[1] == ts[2] or ts[2] == ts[0]:\n print(1)\n return\n\nprint(2)\n", "\n\na=[[],[],[]]\n\ns=input().split(\" \")\n\nfor i in range(len(s)):\n\tif(s[i][1]=='m'):\n\t\ta[0].append(int(s[i][0]))\n\telif(s[i][1]=='p'):\n\t\ta[1].append(int(s[i][0]))\n\telse:\n\t\ta[2].append(int(s[i][0]))\n\nko=10\n\nfor i in range(len(a)):\n\ta[i]=sorted(a[i])\n\tc=0\n\n\tfor j in range(1,len(a[i])):\n\t\tif(a[i][j]==a[i][j-1]):\n\t\t\tc+=1\n\tif(c==1):\n\t\tko=min(ko,1)\n\telif(c==2):\n\t\tko=min(ko,0)\n\telse:\n\t\tif(len(a[i])>0):\n\t\t\tko=min(ko,2)\n\nans=ko\nko=10\n\nfor i in range(len(a)):\n\ta[i]=sorted(a[i])\n\tc=0\n\n\tfor j in range(1,len(a[i])):\n\t\tif(a[i][j]==a[i][j-1]+1):\n\t\t\tc+=1\n\tif(c==1):\n\t\tko=min(ko,1)\n\telif(c==2):\n\t\tko=min(ko,0)\n\telif(len(a[i])>1 and (a[i][0]+2==a[i][1])):\n\t\tko=min(ko,1)\n\telif(len(a[i])>2 and (a[i][1]+2==a[i][2])):\n\t\tko=min(ko,1)\n\telse:\n\t\tif(len(a[i])>0):\n\t\t\tko=min(ko,2)\n\n\nprint(min(ans,ko))\n\n\n\n", "t1, t2, t3 = input().split()\nans = 2\nif t1 == t2 or t2 == t3 or t3 == t1:\n if t1 == t2 == t3:\n ans = 0\n else:\n ans = 1\naaa = []\nfor i in range(10):\n for j in range(10):\n for k in range(10):\n if k - j == j - i == 1:\n aaa.append({i, j, k})\nif t1[1] == t2[1] == t3[1] and {int(t1[0]), int(t2[0]), int(t3[0])} in aaa:\n ans = 0\nelif (t1[1] == t2[1] and (abs(int(t1[0]) - int(t2[0])) == 1 or abs(int(t1[0]) - int(t2[0])) == 2)) or (t1[1] == t3[1] and (abs(int(t1[0]) - int(t3[0])) == 1 or abs(int(t1[0]) - int(t3[0])) == 2)) or (t3[1] == t2[1] and (abs(int(t3[0]) - int(t2[0])) == 1 or abs(int(t3[0]) - int(t2[0])) == 2)):\n ans = min(1, ans)\nprint(ans)", "from sys import stdin, stdout\n\n#N = int(input())\n\n#arr = [int(x) for x in stdin.readline().split()]\n\ns = input()\n\ns = s.split(' ')\n\n#print(s)\n\nM = [0]*9\nP = [0]*9\nS = [0]*9\n\nfor pile in s:\n pile = list(pile)\n #print(pile)\n num = int(pile[0])\n tile = pile[1]\n \n if tile=='s':\n S[num-1] += 1\n elif tile=='p':\n P[num-1] += 1\n elif tile=='m':\n M[num-1] += 1\n \nfor i in range(9):\n if M[i]==3:\n print(0)\n quit()\n if P[i]==3:\n print(0)\n quit()\n if S[i]==3:\n print(0)\n quit()\n \nfor i in range(7):\n if M[i]==1 and M[i+1]==1 and M[i+2]==1:\n print(0)\n quit()\n if P[i]==1 and P[i+1]==1 and P[i+2]==1:\n print(0)\n quit()\n if S[i]==1 and S[i+1]==1 and S[i+2]==1:\n print(0)\n quit()\n\nfor i in range(9):\n if M[i]==2:\n print(1)\n quit()\n if P[i]==2:\n print(1)\n quit()\n if S[i]==2:\n print(1)\n quit()\n \nfor i in range(8):\n if M[i]==1 and M[i+1]==1:\n print(1)\n quit()\n if P[i]==1 and P[i+1]==1:\n print(1)\n quit()\n if S[i]==1 and S[i+1]==1:\n print(1)\n quit()\n \nfor i in range(7):\n if M[i]==1 and M[i+2]==1:\n print(1)\n quit()\n if P[i]==1 and P[i+2]==1:\n print(1)\n quit()\n if S[i]==1 and S[i+2]==1:\n print(1)\n quit()\n \nprint(2)\n \n \n", "f = lambda c: 'mps'.index(c)\nl = [[], [], []]\nfor c in input().split():\n a, b = c\n l[f(b)].append(int(a))\nfor i in range(3):\n l[i].sort()\n\nres = 3\nfor x in l:\n if len(x) == 0: continue\n elif len(x) == 1: res = min(res, 2)\n elif len(x) == 3:\n if len(set(x)) == 1:\n res = min(res, 0)\n break\n if x[0] == x[1] - 1 and x[1] == x[2] - 1:\n res = min(res, 0)\n break\n res = min(res, 2)\n for i in range(len(x)):\n for j in range(i + 1, len(x)):\n if abs(x[i] - x[j]) <= 2:\n res = min(res, 1)\nprint(res)", "line = input().split()\nline.sort()\na,b,c = line\nif a == b and a == c:\n print(0)\nelif a == b:\n print(1)\nelif b == c:\n print(1)\nelse:\n if a[1] == b[1] and b[1] == c[1] \\\n and int(b[0])-int(a[0]) == 1 and int(c[0])-int(b[0]) == 1:\n print(0)\n elif a[1] == b[1] and int(b[0])-int(a[0]) in [1,2]:\n print(1)\n elif b[1] == c[1] and int(c[0])-int(b[0]) in [1,2]:\n print(1)\n elif a[1] == c[1] and int(c[0])-int(a[0]) in [1,2]:\n print(1)\n else:\n print(2)\n\n", "\ndef main():\n buf = input()\n buflist = buf.split()\n hand = buflist;\n t = []\n for i in range(3):\n t.append([])\n for j in range(9):\n t[i].append(0)\n for x in hand:\n idx = 0\n if x[1] == 'm':\n idx = 0\n elif x[1] == 'p':\n idx = 1\n elif x[1] == 's':\n idx = 2\n t[idx][int(x[0])-1] += 1\n max_cons = 0\n max_mult = 0\n for i in range(3):\n cons = [0, 0, 0]\n for j in range(9):\n cons[0] = cons[1]\n cons[1] = cons[2]\n if t[i][j] > 0:\n cons[2] = 1\n else:\n cons[2] = 0\n max_cons = max(sum(cons), max_cons)\n max_mult = max(max_mult, t[i][j])\n print(3 - max(max_cons, max_mult))\n\ndef __starting_point():\n main()\n\n__starting_point()", "s = input()\nans = 2\ns1 = s[0:2]\ns2 = s[3:5]\ns3 = s[6:8]\ndef func(inp):\n ans = 2\n num = int(inp[0])\n c = inp[1]\n ans = min( ans, 2 - int(s.find(str(num + 1)+c) != -1) - int(s.find(str(num + 2)+c) != -1))\n ans = min( ans, 2 - int(s.find(str(num + 1)+c) != -1) - int(s.find(str(num - 1)+c) != -1))\n ans = min( ans, 2 - int(s.find(str(num - 1)+c) != -1) - int(s.find(str(num - 2)+c) != -1))\n ans = min( ans, 3 - s.count(inp))\n return ans\nans = min(ans,func(s1))\nans = min(ans,func(s2))\nans = min(ans,func(s3))\nprint(ans)\n", "s = input().split()\nhand = {'m': [], 'p': [], 's':[]}\n\nfor item in s:\n\thand[item[1]].append(int(item[0]))\n\n\nmin_steps_needed = 10\n\nfor symb in ['m', 'p', 's']:\n\thand[symb] = sorted(hand[symb])\n\tfor start in range(1, 10):\n\t\ta_needed = 10\n\t\tb_needed = 10\n\n\t\ta_needed = 3 - hand[symb].count(start)\n\n\t\tb1, b2, b3 = 0, 0, 0\n\t\tif hand[symb].count(start) > 0:\n\t\t\tb1 = 1\n\t\tif hand[symb].count(start+1) > 0:\n\t\t\tb2 = 1\n\t\tif hand[symb].count(start+2) > 0:\n\t\t\tb3 = 1\n\n\t\tb_needed = 3 - b1 - b2 - b3\n\n\t\tif a_needed < min_steps_needed:\n\t\t\tmin_steps_needed = a_needed\n\t\tif b_needed < min_steps_needed:\n\t\t\tmin_steps_needed = b_needed\n\n\n\n# print(s)\n# print(hand)\nprint(min_steps_needed)", "from math import *\nimport sys\ninput = lambda: sys.stdin.readline().strip()\n\nd = {'m': [], 's': [], 'p': []}\n\nls = list(input().split())\nfor i in ls:\n d[i[1]].append(int(i[0]))\nfor k, v in list(d.items()):\n v.sort()\n if len(v)==3 and len(set(v))==1: print((0)); break\n if len(v)==3 and v[0]+1==v[1] and v[1]+1==v[2]: print((0)); break\nelse:\n for k, v in list(d.items()):\n if len(v)==2 and len(set(v))==1: print((1)); break\n if len(v)==2 and v[1]-v[0]<=2: print((1)); break\n if len(v)==3 and (v[0]==v[1] or v[1]==v[2]): print((1)); break\n if len(v)==3 and (v[1]-v[0]<=2 or v[2]-v[1]<=2): print((1)); break\n else:\n print(2)\n", "t = input().split()[:3:]\ns = set(t)\nres = 3\nif len(s)==1:\n\tres = min(res,0)\nelif len(s)==2:\n\tres = min(res,1)\nelif len(s)==3:\n\tres = min(res,2)\nif res==0:\n\tprint(res)\n\treturn\nt.sort()\nm = [int(a[0]) for a in t if a[1]=='m']\np = [int(a[0]) for a in t if a[1]=='p']\ns = [int(a[0]) for a in t if a[1]=='s']\ndef f(a):\n\tres = 2\n\tfor i in a:\n\t\tif (i-1 in a and i+1 in a)or(i-2 in a and i-1 in a)or(i+1 in a and i+2 in a):\n\t\t\treturn 0\n\t\telif i-1 in a or i+1 in a or i-2 in a or i+2 in a:\n\t\t\tres = min(res,1)\n\treturn res\nres = min([res,f(m),f(p),f(s)])\nprint(res)", "import sys\na,b,c=sys.stdin.readline().strip().split()\nif a==b and b==c:\n print(0)\nelif a==b or b==c or a==c:\n print(1)\nelse:\n na = int(a[0])\n nb = int(b[0])\n nc = int(c[0])\n if (a[1]==b[1] and a[1]==c[1]):\n cp=[na,nb,nc]\n cp.sort()\n cp[0]+=2\n cp[1]+=1\n if (cp[0]==cp[1] and cp[1]==cp[2]):\n print(\"0\")\n elif (cp[0]==cp[1] or cp[1]==cp[2] or cp[0]==cp[1] or (cp[0]+1)==cp[1] or (cp[1]+1)==cp[2]):\n print(\"1\")\n else:\n print(\"2\")\n elif(a[1]==b[1]):\n mi=min(na,nb)\n ma=max(na,nb)\n if (mi==(ma-1) or mi==(ma-2)):\n print(\"1\")\n else: print(\"2\")\n elif(a[1]==c[1]):\n mi=min(na,nc)\n ma=max(na,nc)\n if (mi==(ma-1) or mi==(ma-2)):\n print(\"1\")\n else: print(\"2\")\n elif(b[1]==c[1]):\n mi = min(nb,nc)\n ma = max(nb,nc)\n if (mi==(ma-1) or mi==(ma-2)):\n print(\"1\")\n else: print(\"2\")\n else:\n print(\"2\")\n", "s = input().split()\nb = []\nb.append((s[0][1], int(s[0][0])))\nb.append((s[1][1], int(s[1][0])))\nb.append((s[2][1], int(s[2][0])))\nb.sort()\nif (b[0][0] == b[1][0] and b[1][0] == b[2][0]):\n if (b[0] == b[1] and b[1] == b[2]):\n print(0)\n elif (b[0][1] + 1 == b[1][1] and b[1][1] + 1 == b[2][1]):\n print(0)\n elif (b[0] == b[1]):\n print(1)\n elif (b[1] == b[2]):\n print(1)\n elif b[0][1] + 1 == b[1][1]:\n print(1)\n elif b[0][1] + 2 == b[1][1]:\n print(1)\n elif b[1][1] + 1 == b[2][1]:\n print(1)\n elif b[1][1] + 2 == b[2][1]:\n print(1)\n elif b[0][1] + 1 == b[2][1]:\n print(1)\n elif b[0][1] + 2 == b[2][1]:\n print(1)\n else:\n print(2)\nelif (b[0][0] != b[1][0] and b[1][0] != b[2][0] and b[2][0] != b[0][0]):\n print(2)\nelif b[0][0] == b[1][0]:\n if b[0] == b[1]:\n print(1)\n elif b[0][1] + 1 == b[1][1]:\n print(1)\n elif b[0][1] + 2 == b[1][1]:\n print(1)\n else:\n print(2)\nelif b[1][0] == b[2][0]:\n if (b[1] == b[2]):\n print(1)\n elif b[1][1] + 1 == b[2][1]:\n print(1)\n elif b[1][1] + 2 == b[2][1]:\n print(1)\n else:\n print(2)\nelse:\n print(2)\n \n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Fri Jul 12 17:39:54 2019\n\n@author: Hamadeh\n\"\"\"\n\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Fri Jul 12 17:33:49 2019\n\n@author: Hamadeh\n\"\"\"\n\nclass cinn:\n def __init__(self):\n self.x=[]\n def cin(self,t=int):\n if(len(self.x)==0):\n a=input()\n self.x=a.split()\n self.x.reverse()\n return self.get(t)\n def get(self,t):\n return t(self.x.pop())\n def clist(self,n,t=int): #n is number of inputs, t is type to be casted\n l=[0]*n\n for i in range(n):\n l[i]=self.cin(t)\n return l\n def clist2(self,n,t1=int,t2=int,t3=int,tn=2):\n l=[0]*n\n for i in range(n):\n if(tn==2):\n a1=self.cin(t1)\n a2=self.cin(t2)\n l[i]=(a1,a2)\n elif (tn==3):\n a1=self.cin(t1)\n a2=self.cin(t2)\n a3=self.cin(t3)\n l[i]=(a1,a2,a3)\n return l\n def clist3(self,n,t1=int,t2=int,t3=int):\n return self.clist2(self,n,t1,t2,t3,3)\n def cout(self,i,ans=''): \n if(ans==''):\n print(\"Case #\"+str(i+1)+\":\", end=' ')\n else:\n print(\"Case #\"+str(i+1)+\":\",ans)\n def printf(self,thing):\n print(thing,end='')\n def countlist(self,l,s=0,e=None):\n if(e==None):\n e=len(l)\n dic={}\n for el in range(s,e):\n if l[el] not in dic:\n dic[l[el]]=1\n else:\n dic[l[el]]+=1\n return dic\n def talk (self,x):\n print(x,flush=True)\n def dp1(self,k):\n L=[-1]*(k)\n return L\n def dp2(self,k,kk):\n L=[-1]*(k)\n for i in range(k):\n L[i]=[-1]*kk\n return L\n def isprime(self,n):\n if(n==1 or n==0):\n return False\n for i in range(2,int(n**0.5+1)):\n if(n%i==0):\n return False\n return True\n def factors(self,n): \n from functools import reduce\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 def nthprime(self,n):\n #usable up to 10 thousand\n i=0\n s=2\n L=[]\n while(i<n):\n while(not self.isprime(s)):\n s+=1\n L.append(s)\n s+=1\n i+=1\n return L\n def matrixin(self,m,n,t=int):\n L=[]\n for i in range(m):\n p=self.clist(n,t)\n L.append(p)\n return L\n def seive(self,k):\n #1000000 tops\n n=k+1\n L=[True]*n\n L[1]=False\n L[0]=False\n for i in range(2,n):\n if(L[i]==True):\n for j in range(2*i,n,i):\n L[j]=False\n return L\n def seiven(self,n,L):\n i=0\n for j in range(len(L)):\n if(L[j]==True):\n i+=1\n if(i==n):\n return j\n def matrixin2(self,m,t=int):\n L=[]\n for i in range(m):\n iny=self.cin(str)\n lsmall=[]\n for el in iny:\n lsmall.append(t(el))\n L.append(lsmall)\n return L\n\nc=cinn()\nca1=c.cin(str)\nca2=c.cin(str)\nca3=c.cin(str)\nL=[ca1,ca2,ca3]\nif(ca1==ca2 and ca2==ca3):\n print(0)\nelif(ca1==ca2 or ca3==ca2 or ca1==ca3):\n print(1)\nelse:\n a1=list(ca1)\n a2=list(ca2)\n a3=list(ca3)\n l=[int(a1[0]),int(a2[0]),int(a3[0])]\n l.sort()\n found1=False\n if(l[0]==l[1]-1 and l[1]==l[2]-1):\n if(a1[1]==a2[1] and a1[1]==a3[1]):\n print(0)\n found1=True\n if(found1==False):\n found=False\n for el in L:\n upel=str(int(el[0])+1)+el[1]\n downel=str(int(el[0])-1)+el[1]\n downel2=str(int(el[0])-2)+el[1]\n upel2=str(int(el[0])+2)+el[1]\n if(downel in L or upel in L or upel2 in L or downel2 in L):\n found=True\n if(found):\n print(1)\n else:\n print(2)", "t = input().split()\n\nt.sort()\n\nif t.count(t[0]) == 3:\n print('0')\nelif t.count(t[0]) == 2 or t.count(t[1]) == 2:\n print('1')\nelse:\n num = list(map(int, [t[0][0], t[1][0], t[2][0]]))\n suit = [t[0][1], t[1][1], t[2][1]]\n if len(set(suit)) == 3:\n print('2')\n elif len(set(suit)) == 1:\n if num[1] == num[0] + 1 or num[2] == num[1] + 1:\n if num[2] == num[0] + 2:\n print('0')\n else:\n print('1')\n elif num[1] == num[0] + 2 or num[2] == num[1] + 2:\n print('1')\n else:\n print('2')\n else:\n if suit[0] == suit[1]:\n if num[1] - num[0] in [1, 2]:\n print('1')\n else:\n print('2')\n elif suit[1] == suit[2]:\n if num[2] - num[1] in [1, 2]:\n print('1')\n else:\n print('2')\n else:\n if num[2] - num[0] in [1, 2]:\n print('1')\n else:\n print('2')", "m=[x for x in input().split()]\ntiles=[[0 for i in range(9)] for j in range(3)]\nfor i in range(len(m)):\n g=int(m[i][0])-1\n h=(m[i][1]) \n if h==\"m\":\n tiles[0][g]+=1\n elif h==\"p\":\n tiles[1][g]+=1\n else:\n tiles[2][g]+=1\nif m[0]==m[1] and m[1]==m[2]:\n print(0)\nelif m[0]==m[1]:\n print(1)\nelif m[0]==m[2]:\n print(1)\nelif m[1]==m[2]:\n print(1)\nelse:\n n=False\n for i in range(3):\n for j in range(9):\n if tiles[i][j]!=0:\n if j!=8 and tiles[i][j+1]!=0:\n if j!=7 and tiles[i][j+2]!=0:\n print(0)\n n=True\n break\n else:\n print(1)\n n=True\n break\n elif j!=7 and j!=8 and tiles[i][j+2]!=0:\n print(1)\n n=True\n break\n if n==False:\n print(2)"]
{ "inputs": [ "1s 2s 3s\n", "9m 9m 9m\n", "3p 9m 2p\n", "8p 2s 9m\n", "5s 8m 5s\n", "9s 4s 3m\n", "4p 8m 9s\n", "8s 5s 7p\n", "4p 7p 2p\n", "3p 2p 3p\n", "5s 9p 5s\n", "9m 6s 1p\n", "4m 2p 8m\n", "8p 6s 4p\n", "9s 6m 7p\n", "4m 1p 3m\n", "8s 8m 1p\n", "5m 3p 8m\n", "9m 7p 4s\n", "4p 4s 2m\n", "8p 8m 7s\n", "5p 4s 5p\n", "9s 1m 1s\n", "4s 5s 8p\n", "2p 8p 8p\n", "7m 3m 6m\n", "8p 5m 9m\n", "3p 9p 5s\n", "7s 6s 3m\n", "4s 1p 8s\n", "8m 5s 6p\n", "3m 3p 4s\n", "7m 7m 9p\n", "5p 1s 1m\n", "9p 5m 8s\n", "6s 9s 4p\n", "1s 6m 2s\n", "5m 2p 7p\n", "2m 6p 5m\n", "6p 3s 1p\n", "1m 7p 8m\n", "5m 4s 6s\n", "2p 9m 2m\n", "7s 2s 3m\n", "4m 7p 1s\n", "8m 2m 6p\n", "3p 8p 4s\n", "7p 3m 9p\n", "4p 7p 7m\n", "8p 5s 5p\n", "3p 9p 1m\n", "7s 6s 8s\n", "4s 1p 4m\n", "3p 2m 4m\n", "7p 8s 2s\n", "2p 4m 7p\n", "6s 1s 5s\n", "3s 5m 1p\n", "7s 9p 8m\n", "2s 6m 6s\n", "6m 2s 2m\n", "3m 6p 9s\n", "7m 3s 5p\n", "5s 4p 6m\n", "9s 1s 4p\n", "4m 5s 9m\n", "8s 3m 7s\n", "5m 7p 5m\n", "9m 2m 1s\n", "4m 8p 8p\n", "1p 3m 4s\n", "5p 8p 2p\n", "9s 5s 7m\n", "7m 6s 8m\n", "2p 3m 6p\n", "6m 7s 2m\n", "3m 2m 9s\n", "7p 9s 7m\n", "3p 4m 3s\n", "7s 1p 1p\n", "4s 5m 6s\n", "8m 9s 4p\n", "3m 7p 9m\n", "1p 8s 9m\n", "5p 5p 7s\n", "2p 9s 5m\n", "6s 4p 1s\n", "1s 1m 8p\n", "5s 6p 4s\n", "2m 1m 2p\n", "6m 7p 7m\n", "1p 2m 5p\n", "5m 8p 3m\n", "3s 9p 2s\n", "7s 7s 9p\n", "4s 2p 7s\n", "8m 6s 3p\n", "3m 3m 1m\n", "9p 7s 6p\n", "4p 3m 4m\n", "8p 9s 9s\n", "3p 4m 7m\n", "9p 1p 5s\n", "9p 2p 1p\n", "2p 2p 2p\n", "6s 6s 6s\n", "2p 4p 3p\n", "7p 8p 6p\n", "3m 5m 4m\n", "9s 7s 8s\n", "3p 9p 4m\n", "7m 2m 3m\n", "3p 5p 9p\n", "2p 5p 9p\n", "4s 5s 2s\n", "8s 9s 5s\n", "9p 6p 1p\n", "1s 4s 3s\n", "3p 9p 2p\n", "9s 1s 3s\n", "4p 7p 7p\n", "5m 3m 5m\n", "5m 5m 8m\n", "5p 6p 5p\n", "8m 8m 6m\n", "9p 2p 9p\n", "8s 9s 8s\n", "9m 1m 1m\n", "7m 4m 9p\n", "7p 5p 5m\n", "5m 3m 9p\n", "6p 8p 6s\n", "2p 4m 2m\n", "8s 2m 6s\n", "6s 1p 8s\n", "7m 7s 1s\n", "2p 8s 2s\n", "4s 1m 1s\n", "2s 3m 3s\n", "2s 2p 3s\n", "2s 8p 3s\n", "3m 3p 1p\n", "3p 1p 2m\n", "7s 9m 9s\n", "1p 9s 7s\n", "1m 2p 8m\n", "8p 1m 1p\n", "9m 8m 2p\n", "9m 8s 9s\n", "2m 9s 1m\n", "1m 8s 9m\n", "7p 7p 7m\n", "2s 2p 2p\n", "2s 8p 2s\n", "8p 8p 1m\n", "9p 9m 9m\n", "1p 9m 1p\n", "7p 7m 7s\n", "8m 2s 7p\n", "2m 2s 2p\n", "2s 8p 2m\n", "1p 1m 1s\n", "1p 1m 9s\n", "4m 7m 6m\n", "1s 2s 3p\n", "9s 9s 9s\n", "1s 3s 9m\n", "1s 1s 7s\n", "5m 6m 7s\n", "1s 2s 5s\n", "1s 2p 3s\n", "2s 4s 6s\n", "1s 4s 7s\n", "1m 5m 9m\n", "9m 1m 2m\n", "1p 2s 4s\n", "3m 4p 5s\n", "1m 3m 1s\n", "1s 3s 2p\n", "2p 3s 4p\n", "7s 8s 9s\n", "1m 4m 7m\n", "1s 2s 4s\n", "3s 4m 4s\n", "1s 2m 3p\n", "1s 2p 4p\n", "1p 8s 9s\n", "1m 1m 2m\n", "1s 2s 3m\n", "1s 3s 5s\n", "3m 6m 7m\n", "1s 2p 3m\n", "8m 7s 9s\n", "1s 3s 2s\n", "3s 5s 7s\n", "6s 4s 3s\n", "4m 7s 5s\n", "1s 3s 4s\n", "3s 5s 1s\n", "1p 5p 9p\n", "1p 2p 4p\n", "1s 1p 1p\n", "1m 1s 2m\n", "1p 2s 3m\n", "1m 3m 5m\n", "1m 1p 1s\n", "5m 5p 6m\n", "6p 8s 9s\n", "9s 1s 2m\n", "1s 3s 5p\n", "1s 8m 9m\n", "1m 2p 3s\n", "1p 8m 9m\n" ], "outputs": [ "0\n", "0\n", "1\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "2\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "0\n", "2\n", "1\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "1\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "1\n", "2\n", "2\n", "1\n", "1\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "1\n", "1\n", "2\n", "2\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "2\n", "1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "0\n", "2\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "2\n", "1\n", "2\n", "1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "1\n" ] }
interview
https://codeforces.com/problemset/problem/1191/B
10
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. -----Input----- The first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars. -----Output----- Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. -----Examples----- Input 14 Output 4 4 Input 2 Output 0 2 -----Note----- In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off . In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
["n=int(input())\nr=n%7\nd=n//7\nprint(2*d+max(0,r-5),2*d+min(r,2))\n", "minday = maxday = 0\n\nfor i in range(int(input())) :\n k = i % 7\n if k == 0 or k == 1 : maxday += 1\n if k == 5 or k == 6 : minday += 1\n\nprint(minday, maxday)", "__author__ = 'Andrey'\nn = int(input())\nk = n // 7\nc = n % 7\nprint(2 * k + max(0, c - 5), 2 * k + min(c, 2))", "n = int(input())\nk = 0\nif n % 7 == 6:\n k = 1\nprint(2*(n // 7) + k, 2*(n // 7) + min(n % 7, 2))\n", "a = int(input())\nb=int(a/7)\nc=a%7\nif c==0:\n print(b*2,b*2)\nelif c==1:\n print(b*2,b*2+1)\nelif c==6:\n print(b*2+1,b*2+2)\nelse:\n print(b*2,b*2+2)", "def __starting_point():\n #n, m = list(map(int, input().split()))\n n = int(input())\n print(n // 7 * 2 + (1 if n % 7 > 5 else 0), n // 7 * 2 + (2 if n % 7 >= 2 else n % 7))\n \n\n__starting_point()", "n=int(input())\nif n%7==0:\n print((n//7)*2,(n//7)*2)\nelif n%7==1:\n print((n//7)*2,(n//7)*2+1)\nelif n%7==6:\n print((n//7)*2+1,(n//7)*2+2)\nelse:\n print((n//7)*2,(n//7)*2+2)", "# coding: utf-8\n\n\n\n\n\nimport math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\n\nn = int(input())\n\nw = n // 7\nd = n % 7\nmin_off = w * 2\nmax_off = w * 2\nif d <= 2:\n max_off += d\nelif 2 < d and d <= 5:\n max_off += 2\nelse: # d==6\n max_off += 2\n min_off += 1\nprint(\"{} {}\".format(min_off, max_off))\n", "n = int(input())\nd = n // 7\nr = n % 7\nu, v = d + d, d + d\nif r == 6:\n u += 1\nif r == 1:\n v += 1\nif r > 1:\n v += 2\nprint(u, v)\n \n", "#!/usr/bin/env python3\n\ndef f(n):\n return n // 7 + (n + 1) // 7\n\ntry:\n while True:\n n = int(input())\n if n == 1:\n print(\"0 1\")\n else:\n print(f(n), 2 + f(n - 2))\n\nexcept EOFError:\n pass\n", "n = int(input())\ns = 2\no = 0\nif n%7 == 0:\n\ts = 0\nif n%7 == 1:\n\ts = 1\nif n%7 == 6:\n\to = 1\nprint((n//7)*2+o, (n//7)*2 + s)\n", "import math\nn = int(input())\ncel = math.floor(n / 7)\nost = n % 7\nif ost <= 2:\n max_weekend = cel * 2 + ost\nelse:\n max_weekend = cel * 2 + 2\nif ost < 6:\n min_weekend = cel * 2\nelse:\n min_weekend = cel * 2 + 7 - ost\nprint(min_weekend, max_weekend)\n", "a = int(input())\nb, c = a // 7 * 2, a // 7 * 2\nb += [0, 1][a % 7 == 6]\nc += [a % 7, 2][a % 7 > 2]\nprint(\"%d %d\" % (b, c))\n", "n=int(input())\n\ns=2*(n//7)\np=s\nif(n%7>2):\n s+=2\nelse:\n s+=n%7\nif(n%7>5):\n p+=7-n%7\nprint(p,s)", "n = int(input())\nx = n // 7 * 2\nprint(x + (n % 7 == 6), x + min(n % 7, 2))", "n = int(input())\nm = n // 7\nn %= 7\nma = m * 2 + min(n, 2)\nmi = m * 2\nif (n > 5):\n mi += n - 5\nprint(mi, ma)", "import sys\n#sys.stdin = open(\"apples.in\",\"r\")\n#sys.stdout = open(\"apples.out\",\"w\")\n\nn = int(input())\nk = n // 7 \nif (n % 7 == 0):\n print(k*2, end = ' ')\nelif (n % 7 == 6):\n print(max(k*2+1, 0), end = ' ')\nelse:\n print(max(k*2, 0), end = ' ')\n\n\nif (n % 7 == 0):\n print(k*2)\nelif (n % 7 == 1):\n print(k*2+1)\nelse:\n print(k*2+2)\n\n \n#sys.stdin.close()\n#sys.stdout.close()\n", "def solve():\n N = int(input())\n\n n7 = N // 7\n m7 = N % 7\n ma = n7 * 2 + min(m7, 2)\n mi = n7 * 2\n if m7 == 6:\n mi += 1\n\n print(mi, ma)\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "n=int(input())\na=n//7*2\nprint(a+max(0,(n%7-5)),a+min(2,n%7))\n", "def solve(n):\n res = (n // 7) * 2\n d = n % 7\n if (d == 6):\n minn = res + 1\n maxx = res + 2\n elif (d == 1):\n minn = res\n maxx = res + 1 \n elif (d == 0):\n minn = res\n maxx = res\n else:\n minn = res\n maxx = res + 2\n return [minn, maxx]\n \nn = int(input())\nsol = solve(n)\nprint(str(sol[0])+\" \"+str(sol[1]))", "n = int(input())\nc1 = (n//7)*2\nc2 = c1\nk1 = n%7\nk2 = k1-5\nif k1 >= 2:\n c1 += 2\nelse:\n c1 +=k1\nif k2 >= 0:\n c2 += k2\nprint(c2,c1)\n", "n = int(input())\n\na = n // 7 * 2\nb = a + min(n % 7, 2)\nif n % 7 == 6:\n a += 1\n\nprint('{} {}'.format(a, b))\n", "n = int(input())\nif n == 1:\n print('0 1')\nelif n == 2:\n print('0 2')\nelse:\n d = n - 5\n minDay = ((d // 7) * 2) + (2 if d % 7 >= 2 else d % 7)\n maxDay = ((n // 7) * 2) + (2 if n % 7 >= 2 else n % 7)\n print('%d %d' % (minDay, maxDay))\n"]
{ "inputs": [ "14\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n", "13\n", "1000000\n", "16\n", "17\n", "18\n", "19\n", "20\n", "21\n", "22\n", "23\n", "24\n", "25\n", "26\n", "27\n", "28\n", "29\n", "30\n", "100\n", "99\n", "98\n", "97\n", "96\n", "95\n", "94\n", "93\n", "92\n", "91\n", "90\n", "89\n", "88\n", "87\n", "86\n", "85\n", "84\n", "83\n", "82\n", "81\n", "80\n", "1000\n", "999\n", "998\n", "997\n", "996\n", "995\n", "994\n", "993\n", "992\n", "991\n", "990\n", "989\n", "988\n", "987\n", "986\n", "985\n", "984\n", "983\n", "982\n", "981\n", "980\n", "10000\n", "9999\n", "9998\n", "9997\n", "9996\n", "9995\n", "9994\n", "9993\n", "9992\n", "9991\n", "9990\n", "9989\n", "9988\n", "9987\n", "9986\n", "9985\n", "9984\n", "9983\n", "9982\n", "9981\n", "9980\n", "100000\n", "99999\n", "99998\n", "99997\n", "99996\n", "99995\n", "99994\n", "99993\n", "99992\n", "99991\n", "99990\n", "99989\n", "99988\n", "99987\n", "99986\n", "99985\n", "99984\n", "99983\n", "99982\n", "99981\n", "99980\n", "999999\n", "999998\n", "999997\n", "999996\n", "999995\n", "999994\n", "999993\n", "999992\n", "999991\n", "999990\n", "999989\n", "999988\n", "999987\n", "999986\n", "999985\n", "999984\n", "999983\n", "999982\n", "999981\n", "999980\n", "234123\n", "234122\n", "234121\n", "234120\n", "234119\n", "234118\n", "234117\n", "234116\n", "234115\n", "234114\n", "234113\n", "234112\n", "234111\n", "234110\n", "234109\n", "234108\n", "234107\n", "234106\n", "234105\n", "234104\n", "234103\n", "868531\n", "868530\n", "868529\n", "868528\n", "868527\n", "868526\n", "868525\n", "868524\n", "868523\n", "868522\n", "868521\n", "868520\n", "868519\n", "868518\n", "868517\n", "868516\n", "868515\n", "868514\n", "868513\n", "868512\n", "868511\n", "123413\n", "123412\n", "123411\n", "123410\n", "123409\n", "123408\n", "123407\n", "123406\n", "123405\n", "123404\n", "123403\n", "123402\n", "123401\n", "123400\n", "123399\n", "123398\n", "123397\n", "123396\n", "123395\n", "123394\n", "123393\n", "15\n" ], "outputs": [ "4 4\n", "0 2\n", "0 1\n", "0 2\n", "0 2\n", "0 2\n", "1 2\n", "2 2\n", "2 3\n", "2 4\n", "2 4\n", "2 4\n", "2 4\n", "3 4\n", "285714 285715\n", "4 6\n", "4 6\n", "4 6\n", "4 6\n", "5 6\n", "6 6\n", "6 7\n", "6 8\n", "6 8\n", "6 8\n", "6 8\n", "7 8\n", "8 8\n", "8 9\n", "8 10\n", "28 30\n", "28 29\n", "28 28\n", "27 28\n", "26 28\n", "26 28\n", "26 28\n", "26 28\n", "26 27\n", "26 26\n", "25 26\n", "24 26\n", "24 26\n", "24 26\n", "24 26\n", "24 25\n", "24 24\n", "23 24\n", "22 24\n", "22 24\n", "22 24\n", "285 286\n", "284 286\n", "284 286\n", "284 286\n", "284 286\n", "284 285\n", "284 284\n", "283 284\n", "282 284\n", "282 284\n", "282 284\n", "282 284\n", "282 283\n", "282 282\n", "281 282\n", "280 282\n", "280 282\n", "280 282\n", "280 282\n", "280 281\n", "280 280\n", "2856 2858\n", "2856 2858\n", "2856 2858\n", "2856 2857\n", "2856 2856\n", "2855 2856\n", "2854 2856\n", "2854 2856\n", "2854 2856\n", "2854 2856\n", "2854 2855\n", "2854 2854\n", "2853 2854\n", "2852 2854\n", "2852 2854\n", "2852 2854\n", "2852 2854\n", "2852 2853\n", "2852 2852\n", "2851 2852\n", "2850 2852\n", "28570 28572\n", "28570 28572\n", "28570 28572\n", "28570 28572\n", "28570 28571\n", "28570 28570\n", "28569 28570\n", "28568 28570\n", "28568 28570\n", "28568 28570\n", "28568 28570\n", "28568 28569\n", "28568 28568\n", "28567 28568\n", "28566 28568\n", "28566 28568\n", "28566 28568\n", "28566 28568\n", "28566 28567\n", "28566 28566\n", "28565 28566\n", "285714 285714\n", "285713 285714\n", "285712 285714\n", "285712 285714\n", "285712 285714\n", "285712 285714\n", "285712 285713\n", "285712 285712\n", "285711 285712\n", "285710 285712\n", "285710 285712\n", "285710 285712\n", "285710 285712\n", "285710 285711\n", "285710 285710\n", "285709 285710\n", "285708 285710\n", "285708 285710\n", "285708 285710\n", "285708 285710\n", "66892 66893\n", "66892 66892\n", "66891 66892\n", "66890 66892\n", "66890 66892\n", "66890 66892\n", "66890 66892\n", "66890 66891\n", "66890 66890\n", "66889 66890\n", "66888 66890\n", "66888 66890\n", "66888 66890\n", "66888 66890\n", "66888 66889\n", "66888 66888\n", "66887 66888\n", "66886 66888\n", "66886 66888\n", "66886 66888\n", "66886 66888\n", "248151 248152\n", "248150 248152\n", "248150 248152\n", "248150 248152\n", "248150 248152\n", "248150 248151\n", "248150 248150\n", "248149 248150\n", "248148 248150\n", "248148 248150\n", "248148 248150\n", "248148 248150\n", "248148 248149\n", "248148 248148\n", "248147 248148\n", "248146 248148\n", "248146 248148\n", "248146 248148\n", "248146 248148\n", "248146 248147\n", "248146 248146\n", "35260 35262\n", "35260 35262\n", "35260 35261\n", "35260 35260\n", "35259 35260\n", "35258 35260\n", "35258 35260\n", "35258 35260\n", "35258 35260\n", "35258 35259\n", "35258 35258\n", "35257 35258\n", "35256 35258\n", "35256 35258\n", "35256 35258\n", "35256 35258\n", "35256 35257\n", "35256 35256\n", "35255 35256\n", "35254 35256\n", "35254 35256\n", "4 5\n" ] }
interview
https://codeforces.com/problemset/problem/670/A
12
Vova has won $n$ trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement as beautiful as possible — that means, to maximize the length of the longest such subsegment. Help Vova! Tell him the maximum possible beauty of the arrangement if he is allowed to do at most one swap. -----Input----- The first line contains one integer $n$ ($2 \le n \le 10^5$) — the number of trophies. The second line contains $n$ characters, each of them is either G or S. If the $i$-th character is G, then the $i$-th trophy is a golden one, otherwise it's a silver trophy. -----Output----- Print the maximum possible length of a subsegment of golden trophies, if Vova is allowed to do at most one swap. -----Examples----- Input 10 GGGSGGGSGG Output 7 Input 4 GGGG Output 4 Input 3 SSS Output 0 -----Note----- In the first example Vova has to swap trophies with indices $4$ and $10$. Thus he will obtain the sequence "GGGGGGGSGS", the length of the longest subsegment of golden trophies is $7$. In the second example Vova can make no swaps at all. The length of the longest subsegment of golden trophies in the sequence is $4$. In the third example Vova cannot do anything to make the length of the longest subsegment of golden trophies in the sequence greater than $0$.
["n = int(input())\nA = input()\nx = A.count('G')\nnum_1 = 0\nnum_2 = 0\nmax_num = 0\nflag = 0\nfor i in range(n):\n if A[i] == 'G' and flag == 0:\n num_1 += 1\n elif A[i] == 'G' and flag == 1:\n num_2 += 1\n elif A[i] == 'S' and flag == 0:\n flag = 1\n else:\n if num_1 + num_2 + 1 <= x:\n if num_1 + num_2 + 1 > max_num:\n max_num = num_1 + num_2 + 1\n num_1 = num_2\n num_2 = 0\n flag = 1\n else:\n if num_2 + num_1 > max_num:\n max_num = num_1 + num_2\n num_1 = num_2\n num_2 = 0\n flag = 1\nif num_1 + num_2 + 1 <= x:\n if num_1 + num_2 + 1 > max_num:\n max_num = num_1 + num_2 + 1\nelse:\n if num_2 + num_1 > max_num:\n max_num = num_1 + num_2\nprint(max_num)\n", "n = int(input())\ns = input()\n\n\nmax_ans = len([x for x in s if x == 'G'])\nright = 0\ncnt = 0\nans = 0\nfor i in range(n):\n\tassigned = False\n\tfor j in range(right, n, 1):\n\t\tif s[j] == 'S':\n\t\t\tcnt += 1\n\t\tif cnt > 1:\n\t\t\tright = j\n\t\t\tcnt -= 1\n\t\t\tassigned = True\n\t\t\tbreak\n\tif not assigned:\n\t\tright = n\n\t# print(i, right)\n\tans = max(ans, right - i)\n\tif s[i] == 'S':\n\t\tcnt -= 1\nans = min(ans, max_ans)\nprint(ans)", "input()\nres = 0\ncur = 1\ncur_p = 0\ns = input()\nfor c in s:\n\tif c == \"G\":\n\t\tcur += 1\n\t\tcur_p += 1\n\t\tres = max(res, cur)\n\telse:\n\t\tcur = cur_p + 1\n\t\tcur_p = 0\nprint(min(res, s.count(\"G\")))\n", "n=int(input())\nt=input()\nL=[-1]\ns=0\nfor i in range(n):\n if t[i]=='S':\n L.append(i)\n s+=1\nL.append(n)\nm = L[1]-L[0]-1\nfor i in range(len(L)-2):\n if L[i+2]-L[i]-1 > m:\n m=L[i+2]-L[i]-1\nprint(min(m,n-s))\n", "n = int(input())\nks =input().strip()\n\nprev_g_seq_len = 0\ncur__g_seq_len = 0\nprev_is_s = True\n\nres = 0\nfor j in ks:\n if j == 'S':\n prev_g_seq_len = cur__g_seq_len\n cur__g_seq_len = 0\n # prev_is_s = True\n else:\n cur__g_seq_len += 1\n # prev_is_s = False\n res = max (res, prev_g_seq_len + cur__g_seq_len + 1)\n\nmmm = ks.count('G')\nres = min(mmm, res)\n\n\n\n\nprint(res)\n\n\n", "n = int(input())\ns = input()\ng1 = 0\ng2 = 0\nans = 0\nnum2 = s.count(\"G\")\nfor i in range(n):\n if s[i] == \"G\":\n g1 += 1\n else:\n g2 = g1\n g1 = 0\n \n num = g1 + g2\n if num2 != num:\n num+=1\n ans = max(ans,num)\nprint(min(n,ans))", "def ii():\n return int(input())\ndef mi():\n return list(map(int, input().split()))\ndef li():\n return list(mi())\n\nn = ii()\ns = input().strip()\n\ng = []\ni = 0\nlng = 0\nwhile i < n:\n if s[i] == 'S':\n i += 1\n continue\n j = i + 1\n while j < n and s[j] == 'G':\n j += 1\n g.append((i, j))\n lng = max(lng, j - i)\n i = j + 1\n\nif not g:\n ans = 0\nelif len(g) == 1:\n ans = lng\nelse:\n extra = len(g) > 2\n ans = lng + 1\n for i in range(len(g) - 1):\n s, e = g[i]\n s2, e2 = g[i + 1]\n if s2 != e + 1:\n continue\n ans = max(ans, e - s + e2 - s2 + extra)\nprint(ans)\n", "n = int(input())\ns = input()\n\ngolden_sub = s.split('S')\nnG = 0\nfor c in s:\n\tif c == 'G':\n\t\tnG += 1\n\nt = len(golden_sub)\nif t == 1:\n\tprint(len(golden_sub[0]))\nelse:\n\tans = 0\n\tfor i in range(t - 1):\n\t\tl1 = len(golden_sub[i])\n\t\tl2 = len(golden_sub[i + 1])\n\t\tif l1 + l2 < nG:\n\t\t\tans = max(ans, l1 + l2 + 1)\n\t\telse:\n\t\t\tans = max(ans, l1 + l2)\n\tprint(ans)\n", "from itertools import groupby as gb\nn = int(input())\ns = input()\ng = gb(s)\ngl = []\nfor k,v in g:\n gl.append([k,len(list(v))])\nl = len(gl)\n\nif s[0]=='S':\n if l==1:\n print(0)\n return\n elif l<=3:\n print(gl[1][1])\n return\nif s[0]=='G':\n if l<=2:\n print(gl[0][1])\n return\n\nres = 0\n# 1\nfor i,[k,v] in enumerate(gl):\n if (k,v) == ('S',1) and i not in (0,l-1):\n if s[0]=='S' and l<=5:\n res = max(res, gl[i-1][1]+gl[i+1][1])\n elif s[0]=='G' and l<=4:\n res = max(res, gl[i-1][1]+gl[i+1][1])\n else:\n res = max(res, gl[i-1][1]+gl[i+1][1] + 1)\n# 2\nfor i,[k,v] in enumerate(gl):\n if (k) == ('S') and v > 1:\n if i != 0:\n res = max(res, gl[i-1][1] + 1)\n if i != l-1:\n res = max(res, gl[i+1][1] + 1)\nprint(res)\n", "n=int(input())\ns=str(input())\nlast_seq=0\ncurr_seq=0\nans=0\ngcount=0\ni=0\nwhile i<n-1:\n if s[i]=='G':\n gcount+=1\n curr_seq+=1\n i+=1\n else:\n if curr_seq+last_seq>ans:\n ans=curr_seq+last_seq\n if s[i+1]=='G':\n #gcount+=1\n last_seq=curr_seq\n curr_seq=0\n i+=1\n else:\n if curr_seq>ans:\n ans=curr_seq\n curr_seq=0\n last_seq=0\n i+=2\nif s[-1]=='G':\n gcount+=1\n curr_seq+=1\nif curr_seq+last_seq>ans:\n ans=curr_seq+last_seq\n#print(gcount,ans)\nif gcount>ans:\n print(ans+1)\nelse:\n print(ans)\n", "n = int(input())\nseq = input().replace(' ', '')\nnGTotal = seq.count('G')\nnGCur = 0\nright = -1\nresult = 0\nfor left in range(n):\n if right < left:\n right = left - 1\n nGCur = 0\n while right + 1 < n and ((seq[right + 1] == 'G' and (right - left + 1 - nGCur == 0 or nGCur + 2 <= nGTotal)) or (seq[right + 1] == 'S' and right + 1 - left + 1 - nGCur <= 1 and nGCur + 1 <= nGTotal)):\n right += 1\n if seq[right] == 'G':\n nGCur += 1\n result = max(right - left + 1, result)\n if seq[left] == 'G':\n assert right >= left\n nGCur -= 1\nprint(result)\n", "n=int(input())\ns=input()\na=[]\nk=1\nfor i in range(n-1):\n if s[i]=='G' and s[i+1]=='G':\n k+=1\n elif s[i]=='G' and s[i+1]=='S':\n a.append([i,k])\n k=1\nif s[-1]=='G':\n a.append([n-1,k])\nif len(a)==0:\n print(0)\nelif len(a)==1:\n print(a[0][1])\nelif len(a)==2:\n ma=0\n for i in a:\n ma=max(i[1],ma)\n ka=0\n for i in range(len(a)-1):\n if (a[i+1][0]-a[i+1][1]+1)-a[i][0]==2:\n ka=max(a[i][1]+a[i+1][1],ka)\n if ka>ma+1:\n print(ka)\n else:\n print(ma+1)\nelse:\n ma=0\n for i in a:\n ma=max(i[1],ma)\n ka=0\n for i in range(len(a)-1):\n if (a[i+1][0]-a[i+1][1]+1)-a[i][0]==2:\n ka=max(a[i][1]+a[i+1][1],ka)\n print(max(ka,ma)+1)\n", "x = int(input())\ns = input()\n\ncnts = s.count('S')\ncntg = s.count('G')\ncnt=0\nmx2 = -55\nfor i in range(len(s)-1):\n\tif(s[i]=='G' and s[i+1]=='G'):\n\t\tcnt+=1\n\telse:\n\t\tcnt=0\n\tmx2 = max(cnt, mx2)\n\nmx2+=1\n\nls=[]\ns+=\"0\"\ns='0'+s\nfor i in range(1, len(s)):\n\tif(s[i-1]=='G' and s[i]=='S' and s[i+1]=='G'):\n\t\tls.append(i)\n\n\ncnt = 0\nmx=-55\nfor i in range(len(ls)):\n\tc = ls[i]-1\n\twhile(s[c]=='G'):\n\t\tcnt+=1\n\t\tc-=1\n\tc = ls[i]+1\n\twhile(s[c]=='G'):\n\t\tcnt+=1\n\t\tc+=1\n\tmx = max(cnt, mx)\n\tcnt=0\n\nmaxx = max(mx, mx2)\nif(cntg==0):\n\tprint(0)\nelif(cntg>maxx and cnts>0):\n\tprint(maxx+1)\nelse:\n\tprint(maxx)", "n = int(input())\ns = input()\nmax = 0\nl = 0\nhas_s = False\ngs = 0\nfor r in range(n):\n if s[r] == 'G':\n gs += 1\n else:\n if not has_s:\n has_s = True\n else:\n while s[l] == 'G':\n l += 1\n l += 1\n if r-l+1 > max:\n max = r-l+1\nans = max\nif gs < max:\n ans -= 1\n\nprint(ans)", "n = int( input() )\ns = input() + 'SS'\n\nd = []\nsilv = 0\ngold = 0\nl = []\nfor c in s:\n if c == 'G':\n gold += 1\n silv = 0\n else:\n silv += 1\n if silv > 1 and len( l ) > 0:\n d.append(l)\n l = []\n if gold > 0:\n l.append( gold )\n gold = 0\n\n\n\nif len( d ) == 0:\n print( 0 )\nelif len( d ) == 1:\n l = d[ 0 ]\n if len( l ) == 1 :\n print( l[ 0 ] )\n elif len( l ) == 2:\n print( sum( l ) )\n else:\n m = 0\n last = 0\n for i in l:\n m = max(m, last + i + 1 )\n last = i\n print( m )\nelse:\n m = 0\n for l in d:\n last = 0\n for i in l:\n m = max(m, last + i + 1 )\n last = i\n print( m )\n", "import sys\nfrom math import ceil, sqrt\n\ninput = sys.stdin.readline\n\nn = int(input())\ns = input().strip()\n\nlast = \"S\"\nans = []\ncount = 0\nfreq = {'S': 0, 'G': 0}\n\nfor i in range(n):\n freq[s[i]] += 1\n if s[i] != last:\n ans.append((count, last))\n last = s[i]\n count = 1\n else:\n count += 1\nans.append((count, last))\nans.pop(0)\n\nif freq['G'] == 0:\n print(0)\n return\n\nfinal = max([x[0] for x in ans if x[1] == 'G'])\nif freq['G'] > final:\n final += 1\n\nfor i in range(len(ans) - 2):\n if ans[i][1] == 'G' and ans[i+1][1] == 'S' and ans[i+1][0] == 1 and ans[i+2][1] == 'G':\n if freq['G'] > ans[i][0] + ans[i+2][0]:\n final = max(final, ans[i][0] + ans[i+2][0] + 1)\n else:\n final = max(final, ans[i][0] + ans[i+2][0])\nprint(final)", "n=int(input())\ns=input()\na=[0]*100005\nans,maxn=0,0\n\nfor i in range(0,n):\n if(s[i]=='G'):\n if i==0:\n a[0]=1\n else:\n a[i]=a[i-1]+1\n maxn=max(maxn,a[i])\n ans+=1\nfor i in range(n-2,-1,-1):\n if (s[i] == 'G'):\n a[i]=max(a[i],a[i+1])\nfor i in range(0,n):\n if(i>0 and i <n-1 and s[i]=='S' and s[i-1]=='G'and s[i+1]=='G'and a[i-1]+a[i+1]!=ans):\n maxn=max(maxn,a[i-1]+a[i+1]+1)\n continue\n if (i > 0 and i < n - 1 and s[i] == 'S' and s[i - 1] == 'G' and s[i + 1] == 'G'):\n maxn = max(maxn, a[i - 1] + a[i + 1])\n continue\n if(s[i]=='G' and a[i]!=ans):\n maxn=max(maxn,a[i]+1)\nprint(maxn)", "3.5\n\nN = int(input())\nA = input()\n\nL = []\ncpt = 1\nret = 0\n\nfor i in range(1, len(A)):\n if A[i] == A[i-1]:\n cpt += 1\n else:\n L.append(cpt)\n if A[i] == \"S\":\n ret = max(ret, cpt)\n \n cpt = 1\n\nL.append(cpt)\nif A[-1] == \"G\":\n ret = max(ret, cpt)\n\nif ret == 0:\n print(\"0\")\n return\n\nif A[0] == \"G\":\n cur = True\nelse:\n cur = False\n\nfor i in range(0, len(L)):\n if not cur:\n if L[i] == 1 and (i+3 < len(L) or i-3 >= 0):\n new = 1\n if i > 0:\n new += L[i-1]\n if i < len(L)-1:\n new += L[i+1]\n\n ret = max(ret, new)\n\n if L[i] == 1 and i > 0 and i < len(L)-1:\n ret = max(ret, L[i-1] + L[i+1])\n \n if i > 0 and i+1 < len(L):\n ret = max(ret, L[i-1]+1)\n\n if i < len(L)-1 and i-1 >= 0:\n ret = max(ret, L[i+1]+1)\n \n cur = not cur\n\nprint(ret)\n", "def solve():\n n = int(input())\n s = input()\n l = []\n g_seg, s_seg = 0, 0\n g_count = 0\n for i in range(n):\n if s[i] == 'S':\n if g_seg:\n g_count += 1\n l.append((\"G\", g_seg))\n g_seg = 0\n s_seg += 1\n else:\n if s_seg:\n l.append((\"S\", s_seg))\n s_seg = 0\n g_seg += 1\n if g_seg:\n l.append((\"G\", g_seg))\n g_count += 1\n # print(l)\n if not g_count:\n return 0\n if len(l) == 1:\n return l[0][1]\n elif len(l) == 2:\n return l[1][1]\n if g_count == 2:\n ans = 0\n for i in range(len(l) - 2):\n if l[i][0] == 'G':\n if l[i + 1][1] == 1:\n ans = max(ans, l[i][1] + l[i + 2][1])\n else:\n ans = max(ans, l[i][1] + 1, l[i + 2][1] + 1)\n return ans\n else:\n ans = 0\n for i in range(len(l) - 2):\n if l[i][0] == 'G':\n if l[i + 1][1] == 1:\n ans = max(ans, l[i][1] + 1 + l[i + 2][1])\n else:\n ans = max(ans, l[i][1] + 1, l[i + 2][1] + 1)\n return ans\n\n\nprint(solve())", "n=int(input())\ns=input()\nans=0\nsc,gc,pi,ci=0,0,-1,-1\nfor i in range(1,n+1):\n\tif s[i-1]=='G':\n\t\tgc+=1\n\telse:\n\t\tsc+=1\n\t\tif pi==-1:\n\t\t\tans=max(ans,i-1)\n\t\telse:\n\t\t\tans=max(ans,i-1-pi)\n\t\tpi=ci\n\t\tci=i\n\t#print(ans)\n#print(gc,sc)\nif sc==1:\n\tprint(n-1)\n\treturn\nif sc==2 and (s[0]=='S' or s[n-1]=='S'):\n\tprint(n-2)\n\treturn\n\nif pi==-1:\n\tans=max(ans,n)\nelse:\n\tans = max(ans,n-pi)\n\nprint(min(ans,gc))\n", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[ ]:\n\n\n\nimport math\n\n\n# In[5]:\n\n\nn=int(input())\ndata= list(input())\n\n\n# In[21]:\n\n\nfirstsilver=-1\nsecondsilver=-1\nmdiff=[-1,-1,-1]\n\nfor i in range(0,n):\n if data[i]=='S' and secondsilver==-1:\n secondsilver=i\n elif data[i]==\"S\":\n firstsilver=secondsilver\n secondsilver=i\n diff=i-firstsilver\n if diff>mdiff[0]:\n mdiff=[diff,firstsilver,i,secondsilver]\n\n#print(mdiff) \n \n\n\n# In[22]:\n\nif mdiff[1]==mdiff[3]:\n penalty=0\nelse:\n penalty=1\n \nfor i in range(0,n):\n if i not in list(range(mdiff[1]+1,mdiff[2]+1)):\n if data[i]=='G':\n penalty=0\n\n\n# In[23]:\n\n\nprint(mdiff[0]-penalty)\n\n\n# In[ ]:\n", "def longestSubSeg(a, n):\n cnt0 = 0\n l = 0\n max_len = 0;\n ctG=0\n # i decides current ending point\n for i in range(0, n):\n if a[i] == 'S':\n cnt0 += 1\n if a[i] =='G':\n ctG+=1\n while (cnt0 > 1):\n if a[l] == 'S':\n cnt0 -= 1\n l += 1\n\n max_len = max(max_len, i - l + 1);\n if max_len>ctG:\n return max_len-1\n return max_len\nn=int(input())\na=list(input())\nprint(longestSubSeg(a,n))", "def mi():\n\treturn list(map(int, input().split()))\n'''\n10\nGGGSGGGSGG\n'''\nn = int(input())\ns = list(input())\nfor i in range(n):\n\tif s[i]=='G':\n\t\ts[i] = 1\n\telse:\n\t\ts[i] = 0\na = []\ni = 0\nwhile i<n:\n\tif s[i]==1:\n\t\tc = 0\n\t\tzc = 0\n\t\tpz = -1\n\t\twhile i<n and zc <=1:\n\t\t\tif s[i]==1:\n\t\t\t\tc+=1\n\t\t\telse:\n\t\t\t\tzc+=1\n\t\t\t\tif zc==1:\n\t\t\t\t\tpz = i\n\t\t\ti+=1\n\t\ta.append(c)\n\t\tif pz!=-1:\n\t\t\ti = pz\n\telse:\n\t\ti+=1\nif len(a)>1:\n\tans = max(a)+1\n\tif ans>s.count(1):\n\t\tprint(s.count(1))\n\telse:\n\t\tprint(max(a)+1)\nelif len(a)==1:\n\tprint(a[0])\nelse:\n\tprint(0)\n", "n =int(input())\ncups = input()\n\ndef maxlength(cups):\n length = 0\n for i in cups:\n if i == 'G':\n length = length + 1\n return length\n \nll = cups.split('S')\nthemax = maxlength(cups)\nmaxl = 0\nlength =0\nfor i in range(len(ll)):\n if len(ll[i])>0 and length > 0:\n length = len(ll[i]) + length\n if length >maxl :\n maxl = length\n length = len(ll[i])\n if length == 0 or len(ll[i]) ==0:\n length = len(ll[i])\n if length> maxl and length<=themax:\n maxl = length\nif maxl < themax:\n maxl = maxl + 1\nprint(maxl)"]
{ "inputs": [ "10\nGGGSGGGSGG\n", "4\nGGGG\n", "3\nSSS\n", "11\nSGGGGSGGGGS\n", "300\nSSGSGSSSGSGSSSSGGSGSSGGSGSGGSSSGSSGSGGSSGGSGSSGGSGGSSGSSSGSGSGSSGSGGSSSGSSGSSGGGGSSGSSGSSGSGGSSSSGGGGSSGSSSSSSSSGSSSSGSGSSSSSSSSGSGSSSSGSSGGSSGSGSSSSSSGSGSSSGGSSGSGSSGSSSSSSGGGSSSGSGSGSGGSGGGSSGSGSSSGSSGGSSGSSGGGGSGSSGSSSSGGSSSSGGSGSSSSSSGSSSGGGSGSGGSSGSSSSSSGGSSSGSSSSGGGSSGSSSGSGGGSSSSGSSSGSGSGGGGS\n", "2\nSS\n", "2\nSG\n", "2\nGS\n", "2\nGG\n", "6\nGGSSGG\n", "5\nGGSSG\n", "11\nSGGGGGSSSSG\n", "7\nGGGSSSG\n", "15\nGGSSGGGGGGGSSGG\n", "6\nGSSSGG\n", "4\nGSSG\n", "10\nGSSGGGGSSG\n", "8\nGSSSGGGG\n", "8\nSGGSGGGG\n", "12\nGGGSSGGGGSSG\n", "4\nGSGG\n", "7\nGGGSSGG\n", "10\nGGGSSGGGGG\n", "12\nSSSGGSSSGGGG\n", "10\nGGSSGGSSGG\n", "5\nGSSSG\n", "10\nGGGGGGGSSG\n", "6\nGSSSSG\n", "10\nGGGGSSSGGG\n", "6\nGGGSGG\n", "6\nGSSGSG\n", "9\nGGGGSSGGG\n", "8\nSGSSGGGG\n", "5\nGSSGS\n", "6\nGGGSSG\n", "94\nGGSSGGSGGSSSSSGSSSGGSSSSSGSGGGGSGSGSGSGSGSSSSGGGSSGSSSSGSSSSSSSSSGSSSGGSSGGSGSSGSGGGGSGGGSSSSS\n", "20\nSGSSGGGSSSSSSGGGGGSS\n", "10\nGSSGSSSSSS\n", "10\nGSGSGSGSGG\n", "16\nGSGSSGSSGGGSSSGS\n", "8\nSGSSGSSG\n", "26\nGGSSSSGSSSSSSSGSSSSSSGSSGS\n", "10\nSSGGSSGSSS\n", "20\nGGGGSSGGGGSGGGSGGGGG\n", "8\nGGGSSSGG\n", "15\nGGSGGGSSGGGGGGG\n", "8\nGSGSSGGG\n", "8\nGSSGGGGG\n", "10\nSSSSGGSGGG\n", "21\nSSSGGGSGGGSSSGGGGGGGG\n", "10\nGGGGSSGGSG\n", "5\nGSSGG\n", "7\nGGSSSSG\n", "7\nGGGGSSG\n", "17\nGSGSSGGGSSGGGGSGS\n", "10\nGGSSGGSSSS\n", "8\nGSGSGGGG\n", "7\nGSSGSSG\n", "10\nGGSSGSSSGG\n", "10\nSSGGSSGGSS\n", "20\nGSGGSSGGGSSSGGGGSSSS\n", "7\nGSGGSGG\n", "9\nGGGSSGGSG\n", "3\nSGS\n", "10\nSSGGGSSGGS\n", "4\nGSSS\n", "7\nGGSSGGG\n", "73\nSGSGGGGSSGSGSGGGSSSSSGGSGGSSSGSGSGSSSSGSGGGSSSSGSSGSGSSSGSGGGSSGGGGGGGSSS\n", "9\nGGGSSGGGG\n", "10\nSGSGGSGGGG\n", "5\nSSGSS\n", "5\nGGSSS\n", "10\nGGGGSSGGGG\n", "7\nSGGSSGG\n", "5\nSGSSG\n", "3\nGSG\n", "7\nGGSSGGS\n", "8\nSSSGSSGG\n", "3\nSSG\n", "8\nGGGSSGGG\n", "11\nSGSGSGGGSSS\n", "6\nGGSSSG\n", "6\nGSGSGG\n", "8\nSSSGGSGG\n", "10\nGSSSSGGGGG\n", "7\nGSSGGSG\n", "10\nGSSSSSSSGG\n", "5\nSSGGG\n", "6\nSSSSSS\n", "7\nGGSGGSG\n", "20\nSSSSSGGGGSGGGGGGGGGG\n", "6\nGSSGGS\n", "8\nGSSGSSGG\n", "6\nGSSGGG\n", "5\nSGSSS\n", "3\nGGS\n", "10\nSGGGSSGGSS\n", "3\nGSS\n", "11\nGSSSGGGGGGG\n", "10\nSSSGGSGGGG\n", "6\nSGGSSG\n", "6\nSGSSGG\n", "20\nSSGSSGGGGSGGGGGGGGGG\n", "8\nSGGGSSSG\n", "9\nGSGSSGGGS\n", "89\nSGGSGSGGSSGGSGGSGGGGSSGSSSSSGGGGGGGGGGSSSSGGGGSSSSSGSSSSSGSGSGSGGGSSSGSGGGSSSGSGSGSSGSSGS\n", "9\nGGGGGSSGG\n", "9\nSGSSGSSGS\n", "10\nGGGSSSGGGS\n", "20\nSGSSSGGGGSGGGGGGGGGG\n", "7\nGSSGGGG\n", "18\nGSGSSSSGSSGGGSSSGG\n", "7\nGSSSSGG\n", "9\nGSSGGSGGG\n", "17\nSSSSGSGSGSGSGSGGG\n", "9\nGGSSGGGGS\n", "8\nGSSGGSSG\n", "15\nSGGSSGGSGGSGGGS\n", "7\nGSSSGSG\n", "10\nGSSSGSSSSG\n", "8\nSGGSSGGS\n", "13\nSSGGSSSSGSSSS\n", "19\nGSGGGSSSGGGGGGGGGGG\n", "15\nGSGGSGGSSGGGGGG\n", "6\nSGSGSS\n", "46\nGGGGGGGSSSSGGSGGGSSGSSGSSGGGSGSGGSSGSSSSGGSSSS\n", "6\nGGSGGG\n", "40\nGSSGGGGGGGSSSGSGSSGGGSSSSGSGSSSSGSSSGSSS\n", "8\nGGSSSSSG\n", "32\nGSGSSGGSGGSGGSGGSGGSGSGGSSSGGGGG\n", "8\nGSGGSGGS\n", "8\nGGSSSGGG\n", "10\nSGGSGGSGGG\n", "10\nSSSGGGSSSG\n", "7\nSSGGSSG\n", "13\nGSGSSSSSSGGGG\n", "12\nGGSGGSSGGGGG\n", "9\nSGGSGGSGG\n", "30\nGGGGGGSSGGSSSGSSGSSGSSSGGSSSGG\n", "11\nGSGSGSSSGGG\n", "10\nSGGGGGGSSG\n", "9\nSSSGGSSGS\n", "20\nSGGGSSGGGGSSGSGGSSGS\n", "5\nSGGSS\n", "4\nGGGS\n", "90\nSSGSGGSGSGGGSSSSSGSGSSSGGSSGSGSGSSGGGSGGSGGGSSSSSGSGGGSSSSSGSSSSGGSGGSSSSGGGSSSGSSSGGGSGGG\n", "30\nSGGGGSSSGSGSSSSSSGGGGSSGGSSSGS\n", "11\nGGSGSSGGGGG\n", "10\nGGGSSGGSGG\n", "10\nSGSGGGGSGG\n", "4\nSSSS\n", "9\nGGSGSSSGG\n", "14\nGSGSSSSGGGSSGS\n", "3\nSGG\n", "9\nGGGSSGGSS\n", "8\nGSSSGSGG\n", "9\nSSSSGGSGG\n", "4\nSSGG\n", "38\nGSSSSSGGGSSGGGGSSSSSSGGGSSGSSGGGSSGGSS\n", "5\nGGSGG\n", "4\nSGGS\n", "10\nSSGSSSGGGS\n", "5\nGSGSG\n", "5\nSSGSG\n", "5\nGSGGG\n", "11\nSSGSSGGGSSG\n", "9\nSSGGGSGSS\n", "4\nGGSG\n", "8\nGGSSSGGS\n", "6\nSGGSGG\n", "10\nSSGGSSSSSS\n", "10\nGGGSGGGGSS\n", "170\nSGSGSGGGGGGSGSSGSGSGGSGGGGGGSSSGSGSGGSGGSGSGGGGSSSSSGSSGSSSSSGSGGGSGGSGSGSSGSSSGGSSGGGSGGGSSGGSGSGGSGGGGSGGGSSSGGGGSSSSSSGGSGSSSGSGGSSGGSGSGSGGGGSSSGGGGGGSGGSGGGGGGSGGGGS\n", "10\nSGSGSSGGGG\n", "183\nGSSSSGGSSGSGSSGGGGGSGSSGGGSSSSGGGSSSGSGSSSSGSGGSGSGSGGSGGGSSSGSGSGSSSGSGSGSGGSGSGGGGGSSGSGGGGSGGGGSSGGGSSSGSGGGSGGSSSGSGSSSSSSSSSSGSSGSGSSGGSGSSSGGGSGSGSGSGSSSSGGGSGSGGGGGSGSSSSSGGSSG\n", "123\nGSSSSGGGSSSGSGGSGGSGGGGGGSGSGGSGSGGGGGGGSSGGSGGGGSGGSGSSSSSSGGGSGGGGGGGSGGGSSGSSSGGGGSGGGSSGSSGSSGSSGGSGGSGSSSSGSSGGGGGGSSS\n", "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n", "174\nGGGGSSSGGGGSGGSSSGSSSGGGGGGGSSSSSSSSGGSGSSSSGGGSSGSGGSGSSSSSGGGSSGGGGSGSSGSSGSGSSSGGSGSGSGSSSGSGGSGGSSGGSSSSGSSGSSGGSSGSSGGGGSSGSSGGGGGSSSSGGGGSSGSGSGSGGGSGSGGGSGGGSGSGSGGGGG\n", "181\nGGGGGGGGGGGSSGGGGGGGSSSGSSSSGSSGSSSGGSGGSGGSSGSSGSSGGSGGGSSGGGSGGGGGSGGGSGSGSGSSGSSGGSGGGGSSGGSGGSGSSSSGSSGGSGGSSSGSSGSSGGGSGSSGGGSGSSGGGSSSSSSGGSSSSGSGSSSSSGGSGSSSGGGGSSGGGSGGGSGSS\n", "169\nGSGSGSGGSGSSSGSSGSGGGSGGGSSSGGSGSSSSSGGGGSSSSGGGSSGSGGSGGSGGSSGGGGSSGSSGSSSGSGGSSGGSSGGSSGSGSSGSSSSSSGSGSSGSSSGGSGSGGSSSSGSGGSGSSSSGSGGSSGGGSGGSGGSSSSGSSGSSSSSGGGGGGGSGS\n", "33\nGGGGSSSGGSSSGGGGGGGSGGGGSGGGGGGGG\n", "134\nGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGS\n" ], "outputs": [ "7\n", "4\n", "0\n", "8\n", "6\n", "0\n", "1\n", "1\n", "2\n", "3\n", "3\n", "6\n", "4\n", "8\n", "3\n", "2\n", "5\n", "5\n", "6\n", "5\n", "3\n", "4\n", "6\n", "5\n", "3\n", "2\n", "8\n", "2\n", "5\n", "5\n", "3\n", "5\n", "5\n", "2\n", "4\n", "8\n", "6\n", "2\n", "4\n", "4\n", "2\n", "3\n", "3\n", "9\n", "4\n", "8\n", "4\n", "6\n", "5\n", "9\n", "5\n", "3\n", "3\n", "5\n", "6\n", "3\n", "6\n", "2\n", "3\n", "3\n", "5\n", "5\n", "4\n", "1\n", "4\n", "1\n", "4\n", "8\n", "5\n", "7\n", "1\n", "2\n", "5\n", "3\n", "2\n", "2\n", "3\n", "3\n", "1\n", "4\n", "5\n", "3\n", "4\n", "4\n", "6\n", "4\n", "3\n", "3\n", "0\n", "5\n", "14\n", "3\n", "3\n", "4\n", "1\n", "2\n", "4\n", "1\n", "8\n", "6\n", "3\n", "3\n", "15\n", "4\n", "4\n", "11\n", "6\n", "2\n", "4\n", "15\n", "5\n", "4\n", "3\n", "6\n", "5\n", "5\n", "3\n", "6\n", "3\n", "2\n", "3\n", "3\n", "12\n", "7\n", "2\n", "8\n", "5\n", "8\n", "3\n", "6\n", "5\n", "4\n", "6\n", "4\n", "3\n", "5\n", "6\n", "5\n", "7\n", "4\n", "7\n", "3\n", "5\n", "2\n", "3\n", "7\n", "5\n", "6\n", "5\n", "7\n", "0\n", "4\n", "4\n", "2\n", "4\n", "4\n", "4\n", "2\n", "5\n", "4\n", "2\n", "4\n", "3\n", "2\n", "4\n", "4\n", "4\n", "3\n", "3\n", "4\n", "2\n", "7\n", "11\n", "5\n", "9\n", "11\n", "0\n", "8\n", "12\n", "9\n", "13\n", "3\n" ] }
interview
https://codeforces.com/problemset/problem/1082/B
16
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are regular bracket sequences; "))" and ")((" are bracket sequences (but not regular ones), and "(a)" and "(1)+(1)" are not bracket sequences at all. You have a number of strings; each string is a bracket sequence of length $2$. So, overall you have $cnt_1$ strings "((", $cnt_2$ strings "()", $cnt_3$ strings ")(" and $cnt_4$ strings "))". You want to write all these strings in some order, one after another; after that, you will get a long bracket sequence of length $2(cnt_1 + cnt_2 + cnt_3 + cnt_4)$. You wonder: is it possible to choose some order of the strings you have such that you will get a regular bracket sequence? Note that you may not remove any characters or strings, and you may not add anything either. -----Input----- The input consists of four lines, $i$-th of them contains one integer $cnt_i$ ($0 \le cnt_i \le 10^9$). -----Output----- Print one integer: $1$ if it is possible to form a regular bracket sequence by choosing the correct order of the given strings, $0$ otherwise. -----Examples----- Input 3 1 4 3 Output 1 Input 0 0 0 0 Output 1 Input 1 2 3 4 Output 0 -----Note----- In the first example it is possible to construct a string "(())()(()((()()()())))", which is a regular bracket sequence. In the second example it is possible to construct a string "", which is a regular bracket sequence.
["cnt1 = int(input())\ncnt2 = int(input())\ncnt3 = int(input())\ncnt4 = int(input())\nif cnt1 != cnt4:\n\tprint(0)\n\treturn\n\nif (cnt3 != 0 and cnt1 == 0):\n\tprint(0)\n\treturn\n\nprint(1)", "cnt = [int(input()) for _ in range(4)]\n\nif cnt[0] != cnt[3]:\n\tprint(0)\nelif cnt[2] > 0 and cnt[0] == 0:\n\tprint(0)\nelse:\n\tprint(1)\n", "a = int(input())\ninput()\nc = int(input())\nb = int(input())\nif c :\n print(int(a == b and a > 0))\nelse:\n print(int(a == b))\n", "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\n\nf = True\nk = 2 * a\nif c:\n if k < 1:\n print(0)\n else:\n if k == 2 * d:\n print(1)\n else:\n print(0)\nelse:\n if k == 2 * d:\n print(1)\n else:\n print(0)\n", "c1 = int(input())\nc2 = int(input())\nc3 = int(input())\nc4 = int(input())\nif c1 != c4:\n print(0)\nelif c1 == 0 and c3 > 0:\n print(0)\nelse:\n print(1)\n", "c1 = int(input())\nc2 = int(input())\nc3 = int(input())\nc4 = int(input())\n\nres = 1\nif c1 != c4:\n res = 0\nelif c3 > 0 and c1 == 0:\n res = 0\n\nprint(res)", "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\nif a == d and (a > 0 and c > 0 or c == 0):\n print(1)\nelse:\n print(0)\n", "mi = lambda: [int(i) for i in input().split()]\nc1, c2, c3, c4 = int(input()), int(input()), int(input()), int(input())\n\nif c1 != c4:\n print(0)\n return\n\nif c3 != 0 and c1 == 0:\n print(0)\n return\n\nprint(1)\n", "def main():\n a, b, c, d = (int(input()) for i in range(4))\n if (a == d == 0):\n if (c == 0):\n print(1)\n else:\n print(0)\n elif (a == d):\n print(1)\n else:\n print(0)\n \n \nmain()\n", "cnt1=int(input())\ncnt2=int(input())\ncnt3=int(input())\ncnt4=int(input())\n\nif cnt1 == cnt4 and cnt1 > 0:\n print(1)\n return\nif cnt1 == cnt4 and cnt3 == 0:\n print(1)\n return\nprint(0)", "c1 = int(input())\nc2 = int(input())\nc3 = int(input())\nc4 = int(input())\nif c1 != c4:\n print(0)\n return\nif c3 != 0 and c1 == 0:\n print(0)\nelse:\n print(1)\n", "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\nfl, cnt = 0, 0\nif a == d and (a != 0 or c == 0):\n print(1)\nelse:\n print(0)\n", "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\nif a==d and (a>0 or c==0):\n print(1)\nelse:\n print(0)", "c1 = int(input())\nc2 = int(input())\nc3 = int(input())\nc4 = int(input())\nif c1 == c4:\n if c3 > 0 and c1 == 0:\n print(0)\n else:\n print(1)\nelse:\n print(0)\n", "# \nimport collections, atexit, math, sys, bisect \n\nsys.setrecursionlimit(1000000)\n\nisdebug = False\ntry :\n #raise ModuleNotFoundError\n import pylint\n import numpy\n def dprint(*args, **kwargs):\n #print(*args, **kwargs, file=sys.stderr)\n # in python 3.4 **kwargs is invalid???\n print(*args, file=sys.stderr)\n dprint('debug mode')\n isdebug = True\nexcept Exception:\n def dprint(*args, **kwargs):\n pass\n\n\ndef red_inout():\n inId = 0\n outId = 0\n if not isdebug:\n inId = 0\n outId = 0\n if inId>0:\n dprint('use input', inId)\n try:\n f = open('input'+ str(inId) + '.txt', 'r')\n sys.stdin = f #\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u81f3\u6587\u4ef6\n except Exception:\n dprint('invalid input file')\n if outId>0:\n dprint('use output', outId)\n try:\n f = open('stdout'+ str(outId) + '.txt', 'w')\n sys.stdout = f #\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u81f3\u6587\u4ef6\n except Exception:\n dprint('invalid output file')\n \n atexit.register(lambda :sys.stdout.close()) #idle \u4e2d\u4e0d\u4f1a\u6267\u884c atexit\n\nif isdebug and len(sys.argv) == 1:\n red_inout()\n\ndef getIntList():\n return list(map(int, input().split())) \n\ndef solve(): \n pass\n \nT_ = 1 \n#T_, = getIntList()\n\nfor iii_ in range(T_):\n #solve()\n a, = getIntList()\n b, = getIntList()\n c, = getIntList()\n d, = getIntList()\n if a!=d:\n print(0)\n continue\n if c>0 and a==0:\n print(0)\n continue\n print(1)\n \n\n\n\n\n\n\n", "c1 = int(input())\nc2 = int(input())\nc3 = int(input())\nc4 = int(input())\nif c1 != c4 or (c3 != 0 and c1 == 0):\n print(0)\nelse:\n print(1)\n", "def A():\n cnt1 = int(input())\n cnt2 = int(input())\n cnt3 = int(input())\n cnt4 = int(input())\n\n if(cnt4!=cnt1):\n print(0)\n return\n if(cnt3>0 and cnt1==cnt4==0):\n print(0)\n return\n print(1)\nA()\n", "from collections import defaultdict as dd\nimport math\ndef nn():\n\treturn int(input())\n\ndef li():\n\treturn list(input())\n\ndef mi():\n\treturn list(map(int, input().split()))\n\ndef lm():\n\treturn list(map(int, input().split()))\n\n\nc1=nn()\nc2=nn()\nc3=nn()\nc4=nn()\n\nif not c1==c4:\n\tprint(0)\nelif c1==0 and not c3==0:\n\tprint(0)\nelse:\n\tprint(1)\n", "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\n\nif a==0 and d==0:\n if c==0:\n print(1)\n else:\n print(0)\nelse:\n if a==d:\n print(1)\n else:\n print(0)", "a = int(input())\nint(input())\nc = int(input())\nd = int(input())\nprint(1 - int(a != d or (a == 0 and not (a == c == d))))\n", "c1 = int(input())\nc2 = int(input())\nc3 = int(input())\nc4 = int(input())\nif c1 != c4:\n print(0)\nelif c1 == 0 and c3 > 0:\n print(0)\nelse:\n print(1)\n", "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\nprint(1 if a == d and (c == 0 or (a > 0 and d > 0)) else 0)\n", "import sys\nfrom math import *\n\ndef minp():\n\treturn sys.stdin.readline().strip()\n\ndef mint():\n\treturn int(minp())\n\ndef mints():\n\treturn list(map(int, minp().split()))\n\na = [0]*4\nfor i in range(4):\n\ta[i] = mint()\nif a[0]-a[3] != 0 or a[0] == 0 and a[2] > 0:\n\tprint(0)\nelse:\n\tprint(1)\n", "a=int(input())\nb=int(input())\nc=int(input())\nd=int(input())\nif(c==0):\n\tif(a!=d):\n\t\tprint(0)\n\telse:\n\t\tprint(1)\nelse:\n\tif(a==0 or d==0):\n\t\tprint(0)\n\telse:\n\t\tif(a!=d):\n\t\t\tprint(0)\n\t\telse:\n\t\t\tprint(1)\n", "def solve(c1, c2, c3, c4):\n if c1 != c4:\n return 0\n if c3 != 0 and c1 == 0:\n return 0\n return 1\n\n\ndef main() -> None:\n c1 = int(input())\n c2 = int(input())\n c3 = int(input())\n c4 = int(input())\n print(solve(c1, c2, c3, c4))\n\n\ndef __starting_point():\n main()\n\n__starting_point()"]
{ "inputs": [ "3\n1\n4\n3\n", "0\n0\n0\n0\n", "1\n2\n3\n4\n", "1000000000\n1000000000\n1000000000\n1000000000\n", "1000000000\n1000000000\n1000000000\n999999999\n", "1000000000\n999999999\n1000000000\n1000000000\n", "0\n1000000000\n0\n0\n", "0\n0\n1\n0\n", "4\n3\n2\n1\n", "1\n2\n2\n1\n", "2\n0\n2\n0\n", "1\n0\n1\n1\n", "20123\n1\n1\n1\n", "0\n40\n2\n0\n", "925\n22\n24\n111\n", "1\n20\n20\n1\n", "0\n1\n1\n0\n", "1\n1\n0\n1\n", "20123\n2\n3\n4\n", "0\n0\n0\n1\n", "1\n0\n6\n1\n", "0\n0\n10\n0\n", "1\n0\n3\n1\n", "2\n2\n6\n2\n", "4\n5\n10\n4\n", "0\n0\n3\n0\n", "0\n0\n3\n3\n", "1\n0\n5\n1\n", "2\n0\n10\n2\n", "1\n10\n10\n1\n", "4\n5\n100\n4\n", "1\n2\n3\n1\n", "2\n100\n100\n2\n", "1\n1\n4\n1\n", "1\n2\n100\n1\n", "1\n0\n100\n1\n", "1\n0\n10\n1\n", "1\n2\n11\n1\n", "1\n0\n0\n1\n", "0\n2\n2\n0\n", "1\n0\n4\n1\n", "1\n1\n7\n1\n", "0\n10\n1\n0\n", "5\n5\n1000\n5\n", "2\n0\n5\n2\n", "1\n1\n10\n1\n", "0\n0\n4\n0\n", "0\n3\n1\n0\n", "0\n2\n1\n0\n", "0\n3\n9\n0\n", "0\n0\n2\n0\n", "0\n100\n1\n0\n", "0\n7\n2\n0\n", "0\n1\n0\n1\n", "1\n5\n0\n1\n", "2\n6\n6\n2\n", "1\n1\n100\n1\n", "3\n0\n7\n3\n", "1\n500\n500\n1\n", "1\n2\n0\n1\n", "1\n0\n10000000\n1\n", "1\n1\n100000\n1\n", "1\n3\n5\n1\n", "0\n1\n3\n0\n", "3\n1\n100\n3\n", "2\n0\n1\n2\n", "0\n2\n0\n1\n", "1\n0\n1000000\n1\n", "0\n1\n1\n1\n", "1\n0\n500\n1\n", "4\n0\n20\n4\n", "0\n4\n1\n0\n", "4\n5\n100000000\n4\n", "5\n5\n3\n5\n", "0\n1\n10\n0\n", "5\n1\n20\n5\n", "2\n0\n100\n2\n", "1\n100\n100\n1\n", "1\n2\n5\n1\n", "0\n1\n0\n0\n", "1\n5\n10\n1\n", "5\n5\n2\n5\n", "1\n3\n10\n1\n", "2\n2\n9\n2\n", "1\n1000000000\n1000000000\n1\n", "0\n0\n0\n5\n", "1\n1\n3\n1\n", "5\n5\n1000000\n5\n", "2\n2\n10\n2\n", "1\n900\n900\n1\n", "5\n0\n0\n5\n", "3\n2\n7\n3\n", "2\n1\n5\n2\n", "1\n2\n6\n1\n", "0\n1\n2\n0\n", "0\n3\n4\n0\n", "5\n5\n10000\n5\n", "1\n1\n2\n1\n", "4\n1\n10\n4\n", "1\n2\n10\n1\n", "4\n0\n0\n4\n", "5\n5\n100000\n5\n", "4\n3\n0\n3\n", "2\n0\n200\n2\n", "1\n0\n0\n2\n", "10\n21\n21\n10\n", "0\n5\n1\n0\n", "1\n10\n100\n1\n", "3\n0\n0\n1\n", "4\n2\n133\n4\n", "5\n1\n50\n5\n", "0\n1\n0\n10\n", "2\n0\n7\n2\n", "2\n0\n0\n3\n", "4\n0\n10\n4\n", "3\n1\n8\n3\n", "0\n3\n3\n0\n", "7\n1\n0\n7\n", "0\n2\n3\n0\n", "2\n0\n0\n1\n", "1\n1\n50\n1\n", "2\n10\n10\n2\n", "5\n0\n228\n5\n", "4\n3\n9\n4\n", "1\n0\n8\n1\n", "666\n666\n666\n666\n", "5\n5\n12\n5\n", "1\n47\n47\n1\n", "0\n1\n100\n0\n", "1\n0\n1999\n1\n", "0\n5\n5\n0\n", "1\n0\n2019\n1\n", "0\n3\n5\n0\n", "0\n5\n2\n0\n", "1\n1\n5\n1\n", "1\n1\n200\n1\n", "100\n100\n1000\n100\n", "0\n10\n2\n0\n", "0\n4\n10\n0\n", "1\n0\n0\n0\n", "2\n2\n3\n4\n", "2\n0\n0\n2\n", "1\n1\n101\n1\n", "1\n0\n50\n1\n", "1\n0\n1000\n1\n", "3\n2\n12\n3\n", "12\n4\n0\n13\n", "0\n6\n1\n0\n", "2\n1\n45\n2\n", "2\n5\n8\n2\n", "0\n2\n0\n3\n", "2\n0\n0\n4\n", "2\n1\n69\n2\n", "1\n5\n0\n2\n", "1\n0\n2\n1\n", "11\n1\n111\n11\n", "0\n4\n3\n0\n", "0\n1\n5\n0\n", "1\n3\n3\n1\n", "100007\n1\n1\n1\n", "34\n95\n0\n16\n", "5\n0\n0\n0\n", "1\n2\n3\n5\n", "3\n1\n0\n4\n", "16\n93\n0\n2\n", "0\n0\n0\n3\n", "20\n24\n45\n20\n", "23\n0\n49\n23\n", "99\n49\n0\n0\n", "100000\n100000\n100000\n100000\n", "200000\n200000\n200000\n200000\n", "0\n5\n0\n2\n", "1\n123\n123\n1\n" ], "outputs": [ "1\n", "1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "1\n", "0\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n", "0\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n" ] }
interview
https://codeforces.com/problemset/problem/1132/A
18
"Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two(...TRUNCATED)
"[\"from collections import deque\\nS = input()\\nmn = [ 300 for i in range( len( S ) ) ]\\nfor i in(...TRUNCATED)
"{\n \"inputs\": [\n \"cab\\n\",\n \"acdb\\n\",\n \"a\\n\",\n \"ab\\n\",\n \"ba\\n\"(...TRUNCATED)
interview
https://codeforces.com/problemset/problem/797/C
20
"Karen is getting ready for a new school day!\n\n [Image] \n\nIt is currently hh:mm, given in a 24-h(...TRUNCATED)
"[\"s = input()\\nh = int(s[:2])\\nm = int(s[3:])\\n\\ndef ispalin(h, m):\\n s = \\\"%02d:%02d\\\(...TRUNCATED)
"{\n \"inputs\": [\n \"05:39\\n\",\n \"13:31\\n\",\n \"23:59\\n\",\n \"13:32\\n\",\n (...TRUNCATED)
interview
https://codeforces.com/problemset/problem/816/A
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
33