problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p03331
u501643136
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\ndef sumof(N):\n sum = 0\n while(N>0):\n sum += N % 10\n N /= 10\n return sum\n\nminsum = 9*10\nfor i in range(N//2):\n minsum = min(minsum,sumof(i+1) + sumof(N-i-1))\nprint(minsum)\n', 'N = int(input())\ndef sumof(N):\n sum = 0\n while(N>0):\n sum += N % 10\n N /= 10\n return sum\n\nminsum = 9*10\nfor i in range(N//2+1):\n minsum = min(minsum,sumof(i) + sumof(N-i))\nprint(minsum)\n', 'NL = [int(x) for x in str(input())]\nif NL[0] == 1 and sum(NL) == 1:\n print(10)\nelse:\n print(sum(NL))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s257582086', 's965672926', 's671855316']
[2940.0, 2940.0, 2940.0]
[2104.0, 2104.0, 17.0]
[198, 196, 106]
p03331
u503111914
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nA = [i for i in str(N)]\nresult = 0\nfor j in range(len(A)):\n result += A[j]\nif result == 0 and A[0] == 1:\n print(10)\nelse:\n print(result)', 'N = int(input())\nA = [i for i in str(N)]\nresult = 0\nfor j in range(len(A)):\n result += int(A[j])\nif result == 1 and A[0] == "1":\n print(10)\nelse:\n print(result)\n']
['Runtime Error', 'Accepted']
['s902046600', 's162544158']
[2940.0, 2940.0]
[19.0, 18.0]
[156, 164]
p03331
u503476415
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\nsum_list = []\n\ndef findSumOfDigit(n):\n s = 0\n while(n > 0):\n s += n % 10\n n = int(n / 10)N = int(input())\n\nsum_list = []\n\ndef findSumOfDigit(n):\n s = 0\n while(n > 0):\n s += n % 10\n n = int(n / 10)\n return s\n\nfor a in range(1, N-1):\n b = N - a\n sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))\n\nprint(min(sum_list))\n\n return s\n\nfor a in range(2, N):\n b = N - a\n sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))\n\nprint(min(sum_list))\n', 'N = int(input())\n\nsum_list = []\n\ndef findSumOfDigit(n):\n s = 0\n while(n > 0):\n s += n % 10\n n = int(n / 10)\n return s\n\nfor a in range(1, N):\n b = N - a\n sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))\n\nprint(min(sum_list))\n']
['Runtime Error', 'Accepted']
['s580142734', 's171788372']
[2940.0, 3864.0]
[17.0, 274.0]
[520, 259]
p03331
u505830998
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['a=input()\n\nal=[int(c) for c in list(str(a))]\n\nsal=sum(al)\nreturn sal if sal > 1 else 10', 'a=input()\n\nal=[int(c) for c in list(str(a))]\n\nsal=sum(al)\nret= sal if sal > 1 else 10\nprint(ret)\n']
['Runtime Error', 'Accepted']
['s462116155', 's507966644']
[2940.0, 2940.0]
[23.0, 17.0]
[87, 97]
p03331
u516687307
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
["n=int(input())\nc_min=200000\nfor i in range(1,n):\n a=i\n b=n-i\n a_c=0\n b_c=0\n if(a==0)|(b==0):\n print('Err')\n for j in range(6):\n a_c=a_c+a%10\n a=a//10\n for j in range(6):\n b_c=b_c+b%10\n b=b//10\n if (a_c+b_c<=c_min):\n c_min=a_c+b_c\n print(i,n-i)\n \nprint(c_min)", "n=int(input())\nc_min=200000\nfor i in range(1,n):\n a=i\n b=n-i\n a_c=0\n b_c=0\n if(a==0)|(b==0):\n print('Err')\n for j in range(6):\n a_c=a_c+a%10\n a=a//10\n for j in range(6):\n b_c=b_c+b%10\n b=b//10\n if (a_c+b_c<=c_min):\n c_min=a_c+b_c\n #print(i,n-i)\n \nprint(c_min)"]
['Wrong Answer', 'Accepted']
['s613127743', 's956648802']
[3316.0, 3188.0]
[318.0, 324.0]
[334, 335]
p03331
u519939795
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input())\nl=0\nm=0\nfor i in range(n+1):\n for j in range(n+1):\n if i+j!=n:\n continue\n l=([x for x in str(i)])\n m=([y for y in str(j)])\nprint(min(l+m))', 'n=int(input())\na=10*5\ndef k(n):\n s=tuple(map(int,tuple(str(n))))\n return sum(s)\n\nfor i in range(1,n):\n s=k(i)+k(n-i)\n if a>s:\n a=s\nprint(a)']
['Wrong Answer', 'Accepted']
['s777896595', 's953218682']
[3060.0, 3444.0]
[2108.0, 387.0]
[188, 158]
p03331
u539517139
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['s=sum(list(input()))\nprint(10 if s==1 else s)', 's=sum(list(map(int,list(input()))));print(10 if s==1 else s)']
['Runtime Error', 'Accepted']
['s603635556', 's628321023']
[2940.0, 2940.0]
[17.0, 17.0]
[45, 60]
p03331
u543954314
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\ns = n\nfor i in range(n//2+1):\n s = min(s, sum(list(str(i))) + sum(list(str(n-i))))\nprint(s)\n ', 'n = int(input())\ns = n\nfor i in range(1, n//2+1):\n s = min(s, sum(map(int, list(str(i)))) + sum(map(int, list(str(n-i)))))\nprint(s)']
['Runtime Error', 'Accepted']
['s985563336', 's440449713']
[2940.0, 2940.0]
[17.0, 185.0]
[112, 132]
p03331
u545411641
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\nans = N\nfor A in range(1,N):\n B = N - A\n A_str = str(A)\n B_str = str(B)\n A_li = [int(A_str[i]) for i in len(A_str)]\n B_li = [int(B_str[i]) for i in len(B_str)]\n s = sum(A_li) + sum(B_li)\n if s < ans:\n ans = s\n\nprint(ans)', 'N = int(input())\n\nans = N\nfor A in range(1,N):\n B = N - A\n A_str = str(A)\n B_str = str(B)\n A_li = [int(A_str[i]) for i in range(len(A_str))]\n B_li = [int(B_str[i]) for i in range(len(B_str))]\n s = sum(A_li) + sum(B_li)\n if s < ans:\n ans = s\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s685585930', 's477487302']
[3316.0, 3064.0]
[21.0, 465.0]
[266, 280]
p03331
u548624367
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\ndef f(x):\n x%10+f(x//10) if x else 0\nprint(min([f(i)+f(n-i) for i in range(0,n+1)]))', 'def f(x):\n return x%10+f(x//10) if x else 0\nn = int(input())\nprint(min([f(i)+f(n-i) for i in range(1,n)]))']
['Runtime Error', 'Accepted']
['s329741955', 's214365812']
[3164.0, 3864.0]
[18.0, 212.0]
[104, 109]
p03331
u551373727
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = list(map(int, list(input())))\ns = sum(N)\n\nif s is 1:\n print(10)\nelse:\n print(sum)', 'N = list(map(int, list(input())))\n\ns = sum(N)\n\nif s is 1:\n print(10)\nelse:\n print(s)\n']
['Wrong Answer', 'Accepted']
['s359130068', 's521049303']
[3316.0, 2940.0]
[21.0, 17.0]
[91, 87]
p03331
u562767072
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = input()\n\nans = 0\nfor n in N:\n ans += n\n\nprint(ans)\n', 'N = input()\n\nans = 0\nfor n in N:\n ans += int(n)\n\nif ans == 1:\n ans = 10\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s099321384', 's165759151']
[2940.0, 2940.0]
[18.0, 18.0]
[58, 90]
p03331
u580806822
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input())\n\nansli=[]\nfor i in range(1, n):\n mn=n-i\n s1=str(i)\n s2=str(mn)\n dli=[]\n for j in s1:\n dli.append(int(j))\n for k in s2:\n dli.append(int(k))\n ans=0\n for l in dli:\n ans+=l\n #print(ans)\n ansli.append(ans)\nprint("min",min(ansli))\n', 'n=int(input())\n\nansli=[]\nfor i in range(1, n):\n mn=n-i\n s1=str(i)\n s2=str(mn)\n dli=[]\n for j in s1:\n dli.append(int(j))\n for k in s2:\n dli.append(int(k))\n ans=0\n for l in dli:\n ans+=l\n #print(ans)\n ansli.append(ans)\nprint(min(ansli))\n']
['Wrong Answer', 'Accepted']
['s815256192', 's998276519']
[3864.0, 3864.0]
[528.0, 556.0]
[291, 285]
p03331
u587213169
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['x=int(input())\ncount=0\nfor a in range(1, x):\n suma=0\n sumb=0\n b=x-a\n while (a > 0):\n suma += a%10\n a//=10\n while (b > 0):\n sumb += b%10\n b//=10\n count = min(count, suma+sumb)\nprint(min(S))', 'x=int(input())\ncount=10000\nfor a in range(1, x):\n suma=0\n sumb=0\n b=x-a\n while (a > 0):\n suma += a%10\n a= a//10\n while (b > 0):\n sumb += b%10\n b=b//10\n count = min(count, suma+sumb)\nprint(count)']
['Runtime Error', 'Accepted']
['s339118276', 's365379534']
[3064.0, 3064.0]
[258.0, 241.0]
[234, 240]
p03331
u599547273
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\ndigits_sum = lambda x: sum(map(int, str(x)))\n\nmin_num = 10**18\nfor i in range(1, (N+1)//2+1):\n print(i)\n m = N-i\n l = digits_sum(i) + digits_sum(m)\n min_num = min(l, min_num)\n\nprint(min_num)', 'N = int(input())\n\ndigits_sum = lambda x: sum(map(int, str(x)))\n\nmin_num = 10**18\nfor i in range(1, (N+1)//2+1):\n # print(i)\n m = N-i\n l = digits_sum(i) + digits_sum(m)\n min_num = min(l, min_num)\n\nprint(min_num)']
['Wrong Answer', 'Accepted']
['s882119428', 's490247370']
[3536.0, 3060.0]
[195.0, 152.0]
[220, 222]
p03331
u627417051
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nL = []\nfor i in range(N):\n\ta = i + 1\n\tb = N - i - 1\n\ts = sum(list(map,(int, list(str(a))))) + sum(list(map,(int, list(str(b)))))\n\tL.append(s)\nprint(min(L))', 'N = int(input())\nL = []\nfor i in range(N - 1):\n\ta = list(str(i + 1))\n\tb = list(str(N - i - 1))\n\tasum = sum(list(map(int, a)))\n\tbsum = sum(list(map(int, b)))\n\t\n\tL.append(asum + bsum)\nprint(min(L))']
['Runtime Error', 'Accepted']
['s747196317', 's964446635']
[3060.0, 3972.0]
[17.0, 431.0]
[172, 195]
p03331
u630511239
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nn = N // 2\nA = list(str(n))\nA = list(int(n) for n in A)\nans = 2 * sum(A)\nif N % 2 == 1:\n ans += 1\nprint(ans)', 'N = int(input())\nif N % 10 == 0:\n ans = 10\nelse:\n ans = 0\n while N > 0:\n ans += N % 10\n N //= 10\nprint(ans)']
['Wrong Answer', 'Accepted']
['s902740529', 's434129337']
[9128.0, 9112.0]
[28.0, 26.0]
[128, 130]
p03331
u637170240
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nfactor_a = []\nfactor_b = []\nans = N\nif N % 2 == 0:\n for a in range(1, N/2+1):\n sum_a = sum([int(i) for i in str(a)])\n sum_b = sum([int(i) for i in str(N-a)])\n if sum_a + sum_b < ans:\n ans = sum_a + sum_b\nelse:\n for a in range(1, (N+1)/2+1):\n sum_a = sum([int(i) for i in str(a)])\n sum_b = sum([int(i) for i in str(N-a)])\n if sum_a + sum_b < ans:\n ans = sum_a + sum_b\nprint(ans)', 'N = int(input())\nans = N\n\n\ndef simulate(m):\n for a in range(1, m):\n global ans\n sum_a = sum([int(i) for i in str(a)])\n sum_b = sum([int(i) for i in str(N-a)])\n if sum_a + sum_b < ans:\n ans = sum_a + sum_b\n\n\nif N % 2 == 0:\n simulate(N//2+1)\nelse:\n simulate(N//2+2)\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s731293672', 's888329099']
[3064.0, 3064.0]
[18.0, 175.0]
[464, 323]
p03331
u652656291
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\nif n % 10 == 0:\n print(10)\nelse:\n a = str(n)\n b = sum(a)\n print(b)', 'n = int(input())\nif n % 10 == 0:\n print(10)\nelse:\n result = sum(list(map(int, str(n))))\n print(result)']
['Runtime Error', 'Accepted']
['s708044053', 's210004522']
[2940.0, 2940.0]
[17.0, 17.0]
[87, 105]
p03331
u659640418
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input())\nans=inf\nfor i in range(n):\n ans=min(ans,sum(list(n-i))+sum(list(i)))\nprint(ans)', 'from numpy import inf\nn=int(input())\nans=inf\nfor i in range(n-1):\n ans=min(ans,sum(list(map(int, list(str(n-i+1)))))+sum(list(map(int, list(str(i+1))))))\nprint(ans)', 'from numpy import inf\nn=int(input())\nans=inf\nfor i in range(n-1):\n ans=min(ans,sum(list(map(int, list(str(n-i-1)))))+sum(list(map(int, list(str(i+1))))))\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s000463352', 's634853087', 's936993730']
[2940.0, 12484.0, 12484.0]
[17.0, 553.0, 555.0]
[97, 167, 167]
p03331
u680004123
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input()\nlist = []\nfor a in range(2,n-1):\n sum = 0\n sum1 = 0\n b = n - a\n for j in range(len(str(a))):\n sum += int(str(a)[j])\n for k in range(len(str(b))):\n sum1 += int(str(b)[k])\n list.append(sum + sum1)\nprint(min(list))', 'n = int(input())\nl = []\nfor a in range(1,n):\n sum = 0\n sum1 = 0\n b = n - a\n for i in range(len(str(a))):\n sum += int(str(a)[i])\n for i in range(len(str(b))):\n sum1 += int(str(b)[i])\n l.append(sum+sum1)\nprint(min(l))']
['Runtime Error', 'Accepted']
['s694853610', 's434096692']
[2940.0, 3864.0]
[17.0, 715.0]
[299, 287]
p03331
u683134447
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\n\nans = float("inf") \nfor i in range(n+1):\n a = sum([int(i) for i in list(str(i))])\n b = sum([int(i) for i in list(str(n-i))])\n ans = min(a+b, ans)', 'n = int(input())\n\nans = float("inf") \nfor i in range(1, n):\n a = sum([int(i) for i in list(str(i))])\n b = sum([int(i) for i in list(str(n-i))])\n if ans > a+b:\n ans = a + b\nprint(ans)']
['Wrong Answer', 'Accepted']
['s893815961', 's718143545']
[3060.0, 3060.0]
[435.0, 418.0]
[173, 199]
p03331
u693694535
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N=int(input())\n\nM=10**9\nfor i in range(1,N//2+10):\n a=list(str(i))\n b=list(str(N-i))\n #print(a,b)\n k=0\n for q in range(len(a)):\n k+=int(a[q])\n for p in range(len(b)):\n k+=int(b[p])\n M=min(M,k)\nprint(M)', 'N=int(input())\n\nM=10**9\nfor i in range(1,N//2+1):\n a=list(str(i))\n b=list(str(N-i))\n #print(a,b)\n k=0\n for q in range(len(a)):\n k+=int(a[q])\n for p in range(len(b)):\n k+=int(b[p])\n M=min(M,k)\nprint(M)']
['Runtime Error', 'Accepted']
['s240086312', 's824463093']
[9168.0, 9156.0]
[193.0, 196.0]
[236, 235]
p03331
u703890795
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nm = 999\nfor i in range(N):\n N1 = sum(list(str(i+1)))\n N2 = sum(list(str(N - (i+1))))\n m = min(m, N1+N2)\nprint(m)', 'N = int(input())\nm = 999\nM = []\nN1 = 0\nN2 = 0\nfor i in range(N-1):\n L1 = list(str(i+1))\n N1 = 0\n N2 = 0\n for j in range(len(L1)):\n N1 += int(L1[j])\n L2 = list(str(N - (i+1)))\n for j in range(len(L2)):\n N2 += int(L2[j])\n M.append(N1+N2)\nprint(min(M))']
['Runtime Error', 'Accepted']
['s908128301', 's204577524']
[2940.0, 3864.0]
[17.0, 613.0]
[132, 262]
p03331
u713087221
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['import math\n\n\ndef digitSum(n):\n s = str(n)\n array = list(map(int, list(s)))\n return sum(array)\n\n\nn = int(input())\n\n\n\nrank = int(math.log10(n)) \nprint(rank)\n\n\ndiv = n % 10**rank\nif rank < 1:\n a = 2\n b = n %2\n\nelif div == 0:\n a = n / 2\n b = n / 2\nelse :\n a = 10**rank\n b = div\n\n#print("{} : {}".format(a, b))\n\n\ncount = 0\ncount += digitSum(int(a))\ncount += digitSum(int(b))\n\nprint(count)\n\n', 'import math\n\nbase = 998244353\n\nn, a, b, k = map(int, input().split())\n\nfac = [1] * (n + 1)\nrev = [1] * (n + 1)\nfor i in range(1, n + 1):\n fac[i] = fac[i - 1] * i % base\n rev[i] = pow(fac[i], base -2, base)\n\n\n\ndef comb(n,r):\n hoge = (fac[n] * rev[r] * rev[n - r] ) % base\n return hoge\n\n\n\n\n\ncount = 0\n\nan = 0 \n\nfor an in range(n+1):\n if k - an * a < 0 or (k - an * a) % b != 0:\n continue\n bn = (k -an * a) // b\n if not 0 <= bn <= n:\n continue\n\n count += comb(n, an) * comb(n, bn) % base\n count %= base\n\n\n\nprint(count)\n\n\n\n\n\n\n\n \n\n', 'import math\n \n \ndef digitSum(n):\n s = str(n)\n array = list(map(int, list(s)))\n return sum(array)\n \n \nn = int(input())\n \n\nrank = math.ceil(math.log10(n)) \ndiv = n % 10**rank\nif div == 0:\n print(10)\nelse :\n print(digitSum(int(n)))\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s428318401', 's739764036', 's160615333']
[3064.0, 3064.0, 3060.0]
[17.0, 18.0, 17.0]
[448, 571, 279]
p03331
u733738237
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input())\nprint(min(sum(map(int,str(a)))+sum(map(int,str(n-a))))) for a in range(1,n))', 'n=int(input())\nprint(min(sum(map(int,str(a)))+sum(map(int,str(n-a)))) for a in range(1,n))', 'n=int(input())\nval=10**5\nfor a in range(1,n):\n\tif sum(map(int,str(a)))+sum(map(int,str(n-a)))< val:\n\t\tval = sum(map(int,str(a))) + sum(map(int,str(n-a)))\nprint(val)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s034582116', 's715859670', 's413948438']
[2940.0, 2940.0, 3060.0]
[17.0, 17.0, 283.0]
[91, 90, 164]
p03331
u734816542
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
["import itertools\n\n\nif __name__ == '__main__':\n N, A, B, K = map(int, input().split())\n li = [i for i in range(N)]\n ans = 0\n for ai in range(N):\n tmp = K-(ai*A)\n if tmp / B <= N and tmp % B == 0:\n bi = tmp // B\n a = len(list(itertools.combinations(li, ai)))\n b = len(list(itertools.combinations(li, bi)))\n ans += a*b\n print(ans)\n", "if __name__ == '__main__':\n n = int(input())\n ans = 99999999\n for i in range(1, n):\n total = list(str(n-i)) + list(str(i))\n tmp = 0\n for t in total:\n tmp += int(t)\n ans = min(ans, tmp)\n print(ans)\n"]
['Runtime Error', 'Accepted']
['s563687828', 's823216120']
[3060.0, 2940.0]
[18.0, 399.0]
[401, 248]
p03331
u738835924
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N, C, D = map(int, input().split())\ncheck = [i*i for i in range(N)]\ntime = 0\nstop = N * N\n\nif C * D % 2 ==1:\n for i in range(2*N):\n for j in range(2*N):\n if (i + j) % 2 == 0:\n print(i, j)\n time += 1\n if stop == time:\n break\n if stop == time:\n break\nelif (C+D) % 2 == 0:\n for i in range(2*N):\n for j in range(2*N):\n if (i + j) % 2 == 1:\n print(i, j)\n time += 1\n if stop == time:\n break\n if stop == time:\n break\nelse:\n for i in range(2*N):\n for j in range(2*N):\n if (i + j) % 2 == 0:\n if C % 2 == 1:\n if D - j * j not in check:\n print(i, j)\n time += 1\n if stop == time:\n break\n else:\n if C - j * j not in check:\n print(i, j)\n time += 1\n if stop == time:\n break\n if stop == time:\n break\n', 'N, C, D = map(int, input().split())\ncheck = [i*i for i in range(N)]\ntime = 0\nstop = N * N\n\nif C * D % 2 ==1:\n for i in range(2*N):\n for j in range(2*N):\n if (i + j) % 2 == 0:\n print(i, j)\n time += 1\n if stop == time:\n break\n if stop == time:\n break\nelif (C+D) % 2 == 0:\n for i in range(2*N):\n for j in range(2*N):\n if (i + j) % 2 == 1:\n print(i, j)\n time += 1\n if stop == time:\n break\n if stop == time:\n break\n\n\n\n ', 'N, C, D = map(int, input().split())\ncheck = [i*i for i in range(N+1)]\ntime = 0\nstop = N * N\n \nprint(check)\nif C * D % 2 ==1:\n for i in range(2*N):\n for j in range(2*N):\n if (i + j) % 2 == 0:\n print(i, j)\n time += 1\n if stop == time:\n break\n if stop == time:\n break\nelif (C+D) % 2 == 0:\n for i in range(2*N):\n for j in range(2*N):\n if (i + j) % 2 == 1:\n print(i, j)\n time += 1\n if stop == time:\n break\n if stop == time:\n break\nelse:\n for i in range(2*N):\n tt = i * i\n if C - tt in check or D - tt in check:\n continue\n else:\n for j in range(2*N):\n print(i,j)\n time += 1\n if stop == time:\n break\n if stop == time:\n break', 'N = int(input())\nwhile(N%10 == 0):\n N /= 10\nif N == 1:\n print(10)\nelse:\n s = str(N)\n array = list(map(int, list(s)))\n print(sum(array))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s457000885', 's972754178', 's998703668', 's962702308']
[3064.0, 3064.0, 3064.0, 2940.0]
[18.0, 17.0, 17.0, 18.0]
[786, 452, 678, 135]
p03331
u744034042
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\nc = n\nfor i in range(1, n//2+1):\n a = digitsum(i)\n b = digitsum(n-i)\n if c > a + b:\n c = a + b\nprint(c)', 'n = int(input())\nc = []\nfor i in range(1, n//2 +1):\n a = sum(map(int, str(i)))\n b = sum(map(int, str(n-i)))\n c.append(a+b)\nprint(min(c))']
['Runtime Error', 'Accepted']
['s193361244', 's450687285']
[2940.0, 3480.0]
[17.0, 147.0]
[126, 145]
p03331
u745514010
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = input()\nnum = 0\nfor num in n:\n ans += int(num)\nif ans == 1:\n ans = 10\nprint(ans)', 'n = input()\nans = 0\nfor num in n:\n ans += int(num)\nif ans == 1:\n ans = 10\nprint(ans)']
['Runtime Error', 'Accepted']
['s631318109', 's877034625']
[2940.0, 2940.0]
[17.0, 17.0]
[90, 90]
p03331
u756782069
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nA = list(map(int,input().split()))\nif A == 1:\n print(5)\nelse:\n print(A)', 'N = int(input())\nA = sum(list(map(int, list(str(N)))))\nif A == 1:\n print(10)\nelse:\n print(A)']
['Runtime Error', 'Accepted']
['s030925854', 's482319387']
[2940.0, 2940.0]
[17.0, 17.0]
[94, 98]
p03331
u757030836
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\nnum = 0\n\nfor i in range(N+1):\n g = N -i\n a=sum(map(int,list(str(g))))\n b=sum(map(int,list(str(i))))\n ans = a + b\n if ans == 0:\n num += ans\n elif num >= ans:\n num += ans\n else:\n continue\n\n \nprint(num)', 'for i in range(100000):\n g = N -i\n a=sum(map(int,list(str(g))))\n b=sum(map(int,list(str(i))))\n ans = a + b\n if ans == 0:\n num = ans\n elif num >= ans:\n num = ans\n else:\n continue', 'N = int(input())\n\nnum = 0\n\nfor i in range(N+1):\n g = N -i\n a=sum(map(int,list(str(g))))\n b=sum(map(int,list(str(i))))\n ans = a + b\n if num == 0:\n num += ans\n elif num >= ans:\n num += ans\n else:\n continue\n\n \nprint(num)', 'N =input()\nlist = [int(i) for i in N]\n\nans = sum(list)\nif ans ==1:\n print(10)\nelse:\n print(ans)']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s337288895', 's454570641', 's826812058', 's333046139']
[3064.0, 3060.0, 3064.0, 2940.0]
[361.0, 17.0, 352.0, 17.0]
[237, 194, 237, 97]
p03331
u760171369
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['import numpy as np\nN = np.array(int(input()))\nif N[-1] == 0:\n print(10)\nelse:\n print(N.sum())', 'import numpy as np\nN = np.array(int(input()))\nif N[-1] == 0:\n print(10)\nelse:\n print(N.cumsum())', 'import numpy as np\nN = input()\nN = np.array([int(k) for k in N])\nif N[-1] == 0:\n print(10)\nelse:\n print(N.sum())']
['Runtime Error', 'Runtime Error', 'Accepted']
['s484288318', 's602798310', 's750032666']
[12392.0, 12392.0, 12508.0]
[149.0, 152.0, 154.0]
[95, 98, 114]
p03331
u760802228
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nres = 99999\nfor a in range(1, N): \n sum_ = 0 \n b = N - a \n while (a > 0): \n sum_ += a % 10\n a //= 10\n while (b > 0): \n sum_ += b % 10\n b //= 10\n print(sum_)\n res = min(res, sum_)\nprint(res)', 'N = int(input())\nres = 99999\nfor a in range(1, N): \n sum_ = 0 \n b = N - a \n while (a > 0): \n sum_ += a % 10\n a //= 10\n while (b > 0): \n sum_ += b % 10\n b //= 10\n res = min(res, sum_)\nprint(res)']
['Wrong Answer', 'Accepted']
['s513933624', 's500593904']
[3784.0, 3060.0]
[338.0, 245.0]
[308, 288]
p03331
u762420987
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\n\ndef F(num1, num2):\n sum1 = sum(map(int, list(str(num1))))\n sum2 = sum(map(int, list(str(num2))))\n return sum1 + sum2\n\n\nmax_num = 0\nfor A in range(N + 1):\n B = N - A\n max_num = max(max_num, F(A, B))\nprint(max_num)\n', 'N = int(input())\n\n\ndef F(num):\n ans = 0\n for n in str(num):\n ans += int(n)\n return ans\n\n\nmin_num = 10**9\nfor A in range(1, N):\n B = N - A\n num = F(A) + F(B)\n if num < min_num:\n min_num = num\nprint(min_num)\n']
['Wrong Answer', 'Accepted']
['s620656517', 's449138373']
[3060.0, 2940.0]
[346.0, 288.0]
[247, 238]
p03331
u775623741
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=input()\nprint(sum([int(i) for i in n])\n', 'n=int(input())\nprint(min([sum([int(a) for a in str(i)])+sum([int(b) for b in str(n-i)]) for i in range(1,int(n))]))\n']
['Runtime Error', 'Accepted']
['s527383363', 's309276515']
[2940.0, 3912.0]
[17.0, 326.0]
[41, 116]
p03331
u780354103
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\nif N=10*i for i in range(1,5+1):\n print("10")\nelse\n print(sum(int(str(N)))', 'N = int(input())\n\nif N % 10 == 0:\n print(10)\nelse:\n print(sum(list(map(int, str(N)))))']
['Runtime Error', 'Accepted']
['s446613263', 's475292322']
[2940.0, 2940.0]
[17.0, 17.0]
[98, 92]
p03331
u815797488
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\n\ndef sum_10(n):\n return sum[int(l) for l in str(n)]\n\nli=[]\nfor i in range(1,N//2 +1):\n for k in range(N-N//2,N+1):\n if i + k == N:\n li.append(sum_10(i)+sum_10(k))\nprint(min(li)) ', 'N = int(input())\n\ndef sum_10(n):\n return sum([int(l) for l in str(n)])\n\nli=[]\nfor i in range(1,N//2 +1):\n if N - N//2 <= N - i <= N:\n li.append(sum_10(i)+sum_10(N - i))\nprint(min(li)) ']
['Runtime Error', 'Accepted']
['s224400154', 's993429762']
[2940.0, 3480.0]
[19.0, 199.0]
[210, 198]
p03331
u829796346
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['A = list(map(int,input().split()))\nA.sort()\nret = 0\nret += A[2]-A[1]\nA[1] += ret\nA[0] += ret\nret += (A[1]-A[0])//2\nif (A[1]-A[0])%2==1:\n ret += 2\nprint(ret)\n', 'N = int(input())\nmini = float("inf")\nfor A in range(1,N-1+1):\n mini = min(mini,sum([int(digit) for digit in str(A)])+sum([int(digit) for digit in str(N-A)]))\nprint(mini)']
['Runtime Error', 'Accepted']
['s165229321', 's368976326']
[3060.0, 3060.0]
[17.0, 348.0]
[158, 170]
p03331
u837677955
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = input()\ndef sum_keta(m):\n\tsum_wa = 0\n\twhile m>0:\n\t\tsum_wa = sum_wa + m%10\n\t\tm = int(m/10)\n\n\treturn sum_wa\n\nif sum_keta(n) == 1:\n\tprint(10)\nelse:\n\tprint(sum_keta(n))\n', 'n = int(input())\ndef sum_keta(m):\n\tsum_wa = 0\n\twhile m>0:\n\t\tsum_wa = sum_wa + m%10\n\t\tm = int(m/10)\n\n\treturn sum_wa\n\nif sum_keta(n) == 1:\n\tprint(10)\nelse:\n\tprint(sum_keta(n))\n']
['Runtime Error', 'Accepted']
['s840779666', 's620266404']
[2940.0, 2940.0]
[17.0, 17.0]
[169, 174]
p03331
u846150137
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=[int(i) for i in input().split()]\ns=sum(n)\nif s==1 and min(n)==0:\n print(10)\nelse:\n print(s)', 'n=[int(i) for i in list(input())]\ns=sum(n)\nif s==1 and min(n)==0:\n print(10)\nelse:\n print(s)']
['Wrong Answer', 'Accepted']
['s167957446', 's950777511']
[2940.0, 3316.0]
[17.0, 19.0]
[96, 94]
p03331
u863370423
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\n\n\nx = n - 2\ny = n - x\n\nif n < 10:\n print(n)\nif n = 10:\n print(1)\nelse:\n resulty, resultx = 0, 0\n\n while(x > 0):\n resultx += x % 10\n x = x // 10\n\n while(y > 0):\n resulty += y % 10\n y = y // 10\n\n #print(resulty+resultx)\n z = n//2\n\n result = 0\n while(z > 0):\n result += z % 10\n z = z // 10\n\n if result*2 < resulty+resultx:\n print(result*2)\n else:\n print(resulty+resultx)\n\n', 'def soma(a):\n res=0\n if(int(a)<10):\n return int(a)\n \n for i in range(0, len(a)):\n res+=int(a[i])\n\n if(res>=10):\n return soma(str(res))\n\n return res\n\ndef main():\n n = int(input())\n menor = soma(str(n-1))+1\n \n for i in range(1,10):\n if(soma(str(i))+soma(str(n-i))<menor):\n menor = soma(str(i))+soma(str(n-i))\n\n print(menor,"\\n")\n\nmain()\n', 'def soma(n):\n x = sum(int(digit) for digit in str(n))\n if x < 10:\n return x\n else:\n return soma(x)\n\ndef main():\n n = int(input())\n\n somad = soma(n)\n \n for i in range(1, n):\n soman = soma(i)+soma(n-i);\n if(soman==somad):\n break\n \n print(soman,"\\n")\n \nmain()\n', 'numero = int(input())\nsoma = 0\nminimo = 100000\nfor aux in range(numero-1,1,-1):\n prim = str(aux)\n seg = str(numero - aux)\n for x in range(len(prim)):\n soma += int(prim[x])\n for x in range(len(seg)):\n soma += int(seg[x])\n if soma < minimo :\n minimo = soma\n soma = 0\nif numero == 2:\n print(numero)\nelse:\n print(minimo)']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s160419758', 's433377765', 's862709924', 's435538005']
[2940.0, 3064.0, 3060.0, 3064.0]
[17.0, 17.0, 576.0, 423.0]
[475, 411, 329, 361]
p03331
u864197622
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n, a, b, k = map(int, input().split())\n\ndef gcd(a, b):\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n \ndef mod_inv(a, mod):\n return (pow(a,mod-2,mod))\n\ndef mod_combination(n, k, mod):\n return (fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod)) % mod\n\ng = gcd(k, gcd(a, b))\na //= g\nb //= g\nk //= g\n\nmod = 998244353\nfact = [1] + [0] * n\nfor i in range(n):\n fact[i+1] = (fact[i] * (i+1)) % mod\nif a < b:\n tmp = a\n a = b\n b = tmp\n\nans = 0\nfor x in range(n+1):\n if (k-x*a) % b == 0:\n y = (k-x*a)//b\n if y >= 0:\n ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)\n ans %= mod\n\n \nprint(ans)\n', 'n, a, b, k = map(int, input().split())\n\nif False:\n n = 4\n a = 1\n b = 2\n k = 5\n\ndef gcd(a, b):\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n \ndef mod_inv(a, mod):\n return (pow(a,mod-2,mod))\n\ndef mod_combination(n, k, mod):\n return fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod) % mod\n\nmod = 998244353\nfact = [1] + [0] * n\nfor i in range(n):\n fact[i+1] = (fact[i] * (i+1)) % mod\n# print(fact)\nif a < b:\n tmp = a\n a = b\n b = tmp\n\nans = 0\n# print("n, a, b =", n, a, b)\n# print((k-b*n)//a, k//a+1)\nfor x in range(max(-int(-(k-b*n)//a),0), k//a+1):\n if (k-x*a) % b == 0:\n y = (k-x*a)//b\n \n # print("n, x, y, mod", n, x, y, mod)\n # print(mod_combination(n, x, mod))\n # print(mod_combination(n, y, mod))\n \n ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)\n ans %= mod\n \nprint(ans)\n', 'n, a, b, k = map(int, input().split())\n\ndef gcd(a, b):\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n \ndef mod_inv(a, mod):\n return (pow(a,mod-2,mod))\n\ndef mod_combination(n, k, mod):\n return (fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod)) % mod\n\nmod = 998244353\nfact = [1] + [0] * n\nfor i in range(n):\n fact[i+1] = (fact[i] * (i+1)) % mod\n\nans = 0\nfor x in range(n+1):\n if (k-x*a) % b == 0:\n y = (k-x*a)//b\n if y >= 0:\n ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)\n ans %= mod\n\n \nprint(ans)\n', 'def sum_digit(n):\n ret = 0\n while n>0:\n ret += n % 10\n n //= 10\n return ret\n\nN = int(input())\n\nmi = 999999999\nfor a in range(1, N):\n b = N - a\n mi = min(mi, sum_digit(a)+sum_digit(b))\n\nprint(mi)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s196633026', 's514928171', 's864852569', 's453656410']
[3064.0, 3064.0, 3064.0, 3060.0]
[18.0, 18.0, 18.0, 197.0]
[688, 915, 597, 223]
p03331
u865191802
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\nsumn = 0\ndata = 10\ncheck = False\nfor i in range(5):\n\tif(10**i==n):\n\t\tcheck = True\n\nif(check):\n\tprint(10)\nelse:\n\twhile n>=10:\n\t\tsumn += n%10\n\t\tprint("n%10 =",n%10)\n\t\tprint("n =",n)\n\t\tn //= 10\n\tsumn += n\n\tprint(sumn)', 'n = int(input())\nsumn = 0\ndata = 10\ncheck = False\nfor i in range(1,6):\n\tif(10**i==n):\n\t\tcheck = True\n\nif(check):\n\tprint(10)\nelse:\n\twhile n>=10:\n\t\tsumn += n%10\n\t\tn //= 10\n\tsumn += n\n\tprint(sumn)']
['Wrong Answer', 'Accepted']
['s221063833', 's783418692']
[3060.0, 3060.0]
[17.0, 18.0]
[231, 193]
p03331
u867826040
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n = int(input())\nans = 0\nfor i in range(1,n):\n ans = min(ans,sum(map(int,str(i)))+sum(map(int,str(n-i))))\nprint(ans)', 'n = int(input())\nans = float("inf")\nfor i in range(1,n):\n ans = min(ans,sum(map(int,str(i)))+sum(map(int,str(n-i))))\nprint(ans)']
['Wrong Answer', 'Accepted']
['s068514362', 's626752590']
[3060.0, 2940.0]
[279.0, 289.0]
[119, 130]
p03331
u873269440
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['\ndef main():\n\n if sum(list(map(int,list(input())))) !=1:\n print(sum(list(map(int,list(input())))))\n else:\n print(10)\n \n\n \nif __name__== "__main__":\n main() \n\n\n\n\n\n\n\n\n\n', '\ndef main():\n ans = sum(list(map(int,list(input()))))\n if ans!=1:\n print(ans)\n else:\n print(10)\n \n\n \nif __name__== "__main__":\n main() \n\n\n\n\n\n\n\n\n\n']
['Runtime Error', 'Accepted']
['s073017286', 's066524370']
[2940.0, 2940.0]
[17.0, 17.0]
[192, 175]
p03331
u883792993
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['import math\nN=int(input())\ni=2\ndigitSum=pow(10,5)\nA=int(2)\nwhile i<=int(N/2):\n A=i\n B=N-A\n if B>A:\n break\n A_digitsum=0\n while A>=10:\n A_digitsum += A%10\n A = A//10\n if A<10:\n A_digitsum+=A\n B_digitsum=0\n while B>=10:\n B_digitsum += B%10\n B = B//10\n if B<10:\n B_digitsum+= B\n if digitSum > A_digitsum+B_digitsum:\n digitSum = A_digitsum+B_digitsum\n i+=1\nprint(digitSum)', 'import math\nN=int(input())\ni=2\ndigitSum=pow(10,5)\nwhile A<math.sqrt(N):\n A=i\n B=N-A\n A_digitsum=0\n while A>10:\n A_digitsum += N%10\n A = A//10\n while B>10:\n B_digitsum += N%10\n B = B//10\n if digitSum > A_digitsum+B_digitsum:\n digitSum = A_digitsum+B_digitsum\nprint(digitSum)', 'import math\nN=int(input())\ni=2\ndigitSum=pow(10,5)\nA=int(2)\nwhile i<=N/2:\n A=i\n B=N-A\n print(A,B)\n A_digitsum=0\n while A>=10:\n A_digitsum += A%10\n A = A//10\n if A<10:\n A_digitsum+=A\n B_digitsum=0\n while B>=10:\n B_digitsum += B%10\n B = B//10\n if B<10:\n B_digitsum+= B\n if digitSum > A_digitsum+B_digitsum:\n digitSum = A_digitsum+B_digitsum\n i+=1\nprint(digitSum)\n', 'import math\nN=int(input())\ni=2\ndigitSum=pow(10,5)\nA=int(2)\nwhile i<=int(N/2):\n A=i\n B=N-A\n if A<B:\n break\n A_digitsum=0\n while A>=10:\n A_digitsum += A%10\n A = A//10\n if A<10:\n A_digitsum+=A\n B_digitsum=0\n while B>=10:\n B_digitsum += B%10\n B = B//10\n if B<10:\n B_digitsum+= B\n if digitSum > A_digitsum+B_digitsum:\n digitSum = A_digitsum+B_digitsum\n i+=1\nprint(digitSum)', 'import math\nN=int(input())\ni=2\ndigitSum=pow(10,5)\nA=int(2)\nwhile i<=int(N/2)+1:\n A=i\n B=N-A\n A_digitsum=0\n while A>=10:\n A_digitsum += A%10\n A = A//10\n if A<10:\n A_digitsum+=A\n B_digitsum=0\n while B>=10:\n B_digitsum += B%10\n B = B//10\n if B<10:\n B_digitsum+= B\n if digitSum > A_digitsum+B_digitsum:\n digitSum = A_digitsum+B_digitsum\n i+=1\nprint(digitSum)\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s333508279', 's352066878', 's553751412', 's922556377', 's399175358']
[3064.0, 3064.0, 3824.0, 3064.0, 3064.0]
[18.0, 17.0, 201.0, 17.0, 149.0]
[457, 326, 442, 457, 434]
p03331
u890183245
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['import math\nN = int(input())\nn = N\namari = 0\nfor i in range (len(str(N))):\n amari += n % 10\n n = math.floor(n / 10)\nif amari < 10:\n print(10+amari)\nelse:\n print(amari)', 'import math\nN = int(input())\nn = N\namari = 0\nfor i in range (len(str(N))):\n amari += n % 10\n n = math.floor(n / 10)\nif amari = 1:\n print(10)\nelse:\n print(amari)', 'import math\nN = int(input())\nn = N\namari = 0\nfor i in range (len(str(N))):\n amari += n % 10\n n = math.floor(n / 10)\nif amari == 1:\n print(10)\nelse:\n print(amari)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s174968003', 's425005368', 's211707911']
[3060.0, 2940.0, 3060.0]
[17.0, 18.0, 17.0]
[171, 164, 165]
p03331
u905582793
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=input()\nls = [10**i for i in range(1,6)]\nif int(n) in ls:\n print(10)\nelse:\n print(sum([list(n)[i] for i in range(len(n))]))', 'n=input()\nls = [10**i for i in range(1,6)]\nif int(n) in ls:\n print(10)\nelse:\n print(sum([int(list(n)[i]) for i in range(len(n))]))']
['Runtime Error', 'Accepted']
['s858963360', 's501873863']
[2940.0, 2940.0]
[17.0, 17.0]
[127, 132]
p03331
u923270446
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = list(int(input()))\nif N.count(0) == len(N) - 1:\n print(10)\nelse:\n sum(N)\n', 'N = list(input())\nlist1 = [int(x) for x in N]\nif N.count("0") == len(N) - 1 and N[0] == "1" and len(N) != 1:\n print(10)\nelse:\n print(sum(list1))']
['Runtime Error', 'Accepted']
['s106158415', 's635564345']
[2940.0, 2940.0]
[17.0, 17.0]
[79, 146]
p03331
u925364229
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N,A,B,K = map(int,input().split(" "))\nmod = 998244353\nncr = [1]*(N+1)\nv = 1\nfor i in range(N):\n\tv = (v * ((N-i)%mod) * pow((i+1),mod-2,mod)) % mod\n\tncr[i+1] = v%mod\n\npat = 0\nfor a in range(N):\n\tif (K - (a * A)) % B == 0:\n\t\tpat += ncr[a]*ncr[(K - (a * A))//B]\n\t\tpat %= mod\n\nprint(pat % mod)', "N = int(input())\nans = float('inf')\nfor i in range(1,N):\n\tnum = i\n\tj = N - num\n\td = 0\n\twhile num != 0:\n\t\td += (num % 10)\n\t\tnum //= 10\n\twhile j != 0:\n\t\td += (j % 10)\n\t\tj //= 10\n\n\tans = min(d,ans)\n\nprint(ans)"]
['Runtime Error', 'Accepted']
['s071825658', 's568293704']
[3064.0, 3064.0]
[17.0, 249.0]
[289, 206]
p03331
u925940521
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
["import sys\n\ndef digits_sum(x):\n return sum(map(int, str(x)))\n\ndef solve(n):\n ans = sys.maxint\n for a in range(2, n//2):\n b = n - a\n ans = min(ans, digits_sum(a) + digits_sum(b))\n\n return ans\n\nif __name__ == '__main__':\n n = int(input())\n print(solve(n))\n", "import sys\n\ndef digits_sum(x):\n return sum(map(int, str(x)))\n\ndef solve(n):\n ans = sys.maxsize\n for a in range(1, n):\n b = n - a\n ans = min(ans, digits_sum(a) + digits_sum(b))\n\n return ans\n\nif __name__ == '__main__':\n n = int(input())\n print(solve(n))\n"]
['Runtime Error', 'Accepted']
['s940333165', 's898382616']
[3056.0, 2940.0]
[17.0, 272.0]
[286, 284]
p03331
u926678805
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['# coding: utf-8\nimport math\nn=int(input())-1\na=10**int(math.log10(n))\nb=n-a+1\nprint(sum(map(int,str(a)))+sum(map(int,str(b))))\nprint(a,b)', '# coding: utf-8\nimport math\nn=int(input())-1\na=10**int(math.log10(n))\nb=n-a+1\nprint(sum(map(int,str(a)))+sum(map(int,str(b))))\n']
['Wrong Answer', 'Accepted']
['s081215942', 's557688567']
[3188.0, 2940.0]
[19.0, 18.0]
[137, 127]
p03331
u934052933
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['N = int(input())\nrange_A = range(2,100001)\nmin_total = 1000\nfor a in range_A:\n\tb = N - a\n\tif b < 1:continue\n\tsum_a = findSumOfDigits(a)\n\tsum_b = findSumOfDigits(b)\n\ttotal = sum_a + sum_b\n if total < min_total:\n\t\tmin_total = total\nprint(min_total)\n\n', 'def findSumOfDigits(n):\n sum_digits = 0\n while n > 0 :\n sum_digits += n % 10\n n //= 10\n return sum_digits\n\nN = int(input())\nrange_A = range(2,100001)\nmin_total = 1000\nfor a in range_A:\n\tb = N - a\n if b < 1:continue\n\tsum_a = findSumOfDigits(a)\n\tsum_b = findSumOfDigits(b)\n\ttotal = sum_a + sum_b\n\tif total < min_total:\n\tmin_total = total\nprint(min_total)', 'N = int(input())\nrange_A = range(2,50)\nmin_total = 1000\nfor a in range_A:\n\tb = abs(N - a)\n\tsum_a = findSumOfDigits(a)\n\tsum_b = findSumOfDigits(b)\n\ttotal = sum_a + sum_b\n\tif total < min_total:\n\t\tmin_total = total\nprint(min_total)', '\n\n\ndef findSumOfDigits(n):\n sum_digits = 0\n while n > 0 :\n sum_digits += n % 10\n n //= 10\n return sum_digits\n\n\ndef main()->None:\n N = int(input())\n \n range_A = range(1,N+1)\n min_total = 100000\n for a in range_A:\n b = N - a\n if b < 1 : continue\n sum_a = findSumOfDigits(a)\n sum_b = findSumOfDigits(b)\n total = sum_a + sum_b\n if total < min_total:\n min_total = total\n print(min_total)\n\n\nif __name__ == "__main__":\n main()']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s171619209', 's552284536', 's827534846', 's893210040']
[2940.0, 2940.0, 3060.0, 3064.0]
[17.0, 17.0, 17.0, 166.0]
[251, 378, 228, 584]
p03331
u936985471
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['n=int(input())\nans=0\ndef calc(a,b):\n res=0\n for i in range(len(str(a))):\n res+=int(str(a)[i])\n for i in range(len(str(b))):\n res+=int(str(b)[i])\n return res\n \nfor i in range(1,n//2+1):\n a=i\n b=n-a\n ans=min(ans,calc(a,b))\nprint(ans)', 'n=int(input())\nans=10**6\ndef calc(a,b):\n res=0\n for i in range(len(str(a))):\n res+=int(str(a)[i])\n for i in range(len(str(b))):\n res+=int(str(b)[i])\n return res\n \nfor i in range(1,n//2+1):\n a=i\n b=n-a\n ans=min(ans,calc(a,b))\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s051282400', 's220404712']
[3188.0, 3060.0]
[308.0, 310.0]
[245, 250]
p03331
u941753895
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
["n=int(input())\nif n==15:\n exit()\na=0\ns=list(str(n))\nsets=list(set(s))\nsets.sort()\nif len(sets)==2 and sets[0]=='0' and sets[1]=='1':\n print(10)\nelse:\n for i in s:\n a+=int(i)\n print(a)", "n=int(input())\na=0\ns=list(str(n))\nsets=list(set(s))\nsets.sort()\nif len(sets)==2 and sets[0]=='0' and sets[1]=='1':\n print(10)\nelse:\n for i in s:\n a+=int(i)\n print(a)"]
['Wrong Answer', 'Accepted']
['s330421496', 's907436096']
[3064.0, 3060.0]
[17.0, 17.0]
[190, 171]
p03331
u949315872
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['#-------------\nN = int(input())\n#-------------\n\nif N%2 == 0:\n k = N//2\nelse:\n k = (N+1)//2\n\ncmb = []\nfor i in range(1,k+1):\n cmb.append([i , N-i])\n\nprint(cmb) \ndef digitSum(n):\n \n s = str(n)\n \n array = list(map(int, s))\n \n return sum(array)\n\nans = []\nfor i in range(k-1):\n X = digitSum(cmb[i][0])\n Y = digitSum(cmb[i][1])\n ans.append(X+Y)\n\n\nif ans == []:\n print("2")\nelse:\n print(min(ans))', '#-------------\nN = int(input())\n#-------------\n\nif N%2 == 0:\n k = N//2\nelse:\n k = (N+1)//2\n\ncmb = []\nfor i in range(1,k+1):\n cmb.append([i , N-i])\n \ndef digitSum(n):\n \n s = str(n)\n \n array = list(map(int, s))\n \n return sum(array)\n\nans = []\nfor i in range(k-1):\n X = digitSum(cmb[i][0])\n Y = digitSum(cmb[i][1])\n ans.append(X+Y)\n\n\nif ans == []:\n print("2")\nelse:\n print(min(ans))']
['Wrong Answer', 'Accepted']
['s273016336', 's767096010']
[17652.0, 16656.0]
[175.0, 171.0]
[512, 501]
p03331
u967835038
2,000
1,048,576
Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
['aa=[]\naint=[]\na=list(input())\naint=map(int,a)\nif sum(aint)==1:\n print(10)\nelse:\n print(sum(aint))', 'a=int(input())\ns=0\nwhile True:\n if 10**s < a:\n s +=1\n else:\n break\na1=a-10**s\nalist=list(str(a1))\naintlist=map(int,alist)\naa=sum(aintlist)\nprint(s+aa)', 'a=[]\naint=[]\na=list(str(input()))\naint=map(int,a)\nif sum(aint)==1:\n print(10)\nelse:\n print(sum(aint))', 'a=[]\naint=[]\na=list(str(input()))\naint=map(int,a)\nif sum(aint)==1:\n print(10)\nelse:\n print(sum(aint))\n', 'import math\n\nn = int(input())\nsum = 0\nlength = int(math.log10(n) + 1)\n\nfor i in range(length):\n\tsum += n % 10\n\tn = int(n / 10)\n\nif sum == 1:\n\tprint(10)\nelse:\n\tprint(sum)\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s263068099', 's276553361', 's497184718', 's631067236', 's013383682']
[2940.0, 2940.0, 2940.0, 2940.0, 2940.0]
[21.0, 18.0, 17.0, 17.0, 17.0]
[103, 170, 107, 108, 170]
p03332
u013408661
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['n,a,b,k=map(int,input().split())\np=998244353\ndef getinv(n):\n inv=[0]*(n+1)\n inv[1]=1\n for i in range(2,n+1):\n inv[i]=(-(p//i)*inv[p%i])%p\n return inv\ndef getnCr(n):\n inv=getinv(n)\n nCr=[0]*(n+1)\n nCr[0]=1\n for i in range(1,n+1):\n nCr[i]=(nCr[i-1]*(n-i+1)*inv[i])%p\n return nCr\ndef solve(n,a,b,k):\n ans=0\n nCr=getnCr(n)\n for i in range(n+1):\n if (k-a*i)<0 or (k-a*i)%b!=0:\n continue\n j=(k-a*i)//b\n if a*i+b*j==k:\n print(i)\n print(j)\n ans+= nCr[i]*nCr[j]\n ans%=p\n return ans\nprint(solve(n,a,b,k))', 'p=998244353\ndef getinv(n):\n inv = [0]*(n+1)\n \n inv[1] = 1\n for i in range(2,n+1):\n \n inv[i] = (-(p//a)*inv[p%a])%p\n return inv\n\ndef getCmb(n):\n \n inv = getinv(n)\n \n nCr = [0]*(n+1)\n \n nCr[0] = 1\n for i in range(1,n+1):\n \n nCr[i] = (nCr[i-1]*(n-i+1)*inv[i])%p\n return nCr\n\ndef solve(n,a,b,k):\n nCr = getCmb(n)\n ans=0\n for i in range(n+1):\n \n j = (k-a*i)//b\n \n if a*i + b*j == k and 0<=j<=n:\n ans+= (nCr[i]*nCr[j])%p\n ans%= p\n return ans\n\nn,a,b,k=map(int,input().split())\nprint(solve(n,a,b,k))', 'n,a,b,k=map(int,input().split())\np=998244353\ndef getinv(n):\n inv=[0]*(n+1)\n inv[1]=1\n for i in range(2,n+1):\n inv[i]=(-p//i*inv[p%i])%p\n return inv\ndef getnCr(n):\n inv=getinv(n)\n nCr=[0]*(n+1)\n nCr[0]=1\n for i in range(1,n+1):\n nCr[i]=(nCr[i-1]*(n-i-1)*inv[i])%p\n return nCr\ndef solve(n,a,b,k):\n ans=0\n nCr=getnCr(n)\n for i in range(n+1):\n if (k-a*i)%b!=0:\n continue\n j=(k-a*i)//b\n if a*i+b*j==k:\n ans+=(nCr[i]*nCr[j])%p\n ans%=p\n return ans\nprint(solve(n,a,b,k))', 'import math\nn,a,b,k=map(int,input().split())\ndef gcd(x,y):\n if y==0:\n return x\n else:\n return gcd(y,x%y)\np=gcd(a,b)\nans=0\nfor i in range(k//(a+b)):\n if (k-(a+b)*i)%p!=0:\n continue\n else:\n q=gcd(p,k-(a+b)*i)\n A=a//q\n B=b//q\n K=k//q\n A_=(pow(A,B-2,B)*K)%p\n for i in range((n-i-A_)//B):\n ans+=math.factorial(n-i)//(math.factorial(A_+B*i)*math.factorial((k-A_+B*i)//B)*math.factorial(n-i-A_+B*i-(k-A_+B*i)//B))\nprint(ans)', 'n,a,b,k=map(int,input().split())\np=998244353\ndef getinv(n):\n inv=[0]*(n+1)\n inv[1]=1\n for i in range(2,N+1):\n inv[i]=(-p//i*inv[p%i])%p\n return inv\ndef getnCr(n):\n inv=getinv(n)\n nCr=[0]*(n+1)\n nCr[0]=1\n for i in range(1,n+1):\n nCr[i]=(nCr[i-1]*(n-i-1)*inv[i])%p\n return nCr\ndef solve(n,a,b,k):\n ans=0\n nCr=getnCr(n)\n for i in range(n+1):\n j=(k-a*i)//b\n if a*i+b*j==k:\n ans+=nCr[i]+nCr[j]\n ans%=p\n return ans\nprint(solve(n,a,b,k))', 'from math import factorial\nn,a,b,k=map(int,input().split())\ndef gcd(x,y):\n if y==0:\n return x\n else:\n return gcd(y,x%y)\nans=0\np=998244353\nx=gcd(a,b)\nif K%x==0:\n A=a//x\n B=b//x\n K=k//x\n for i in range(n):\n if (K-A*i)%B==0:\n ans+= (factorial(n)//factorial(n-i)//factorial(i))*(factorial(n)//factorial(n-(K-A*i)//B)//factorial((K-A*i)//B))\nprint(ans)\n ', 'p=998244353\ndef getinv(n):\n inv = [0]*(n+1)\n \n inv[1] = 1\n for i in range(2,n+1):\n \n inv[i] = (-(p//i)*inv[p%i])%p\n return inv\n\ndef getCmb(n):\n \n inv = getinv(n)\n \n nCr = [0]*(n+1)\n \n nCr[0] = 1\n for i in range(1,n+1):\n \n nCr[i] = (nCr[i-1]*(n-i+1)*inv[i])%p\n return nCr\n\ndef solve(n,a,b,k):\n nCr = getCmb(n)\n ans=0\n for i in range(n+1):\n \n j = (k-a*i)//b\n \n if a*i + b*j == k and 0<=j<=n:\n ans+= (nCr[i]*nCr[j])%p\n ans%= p\n return ans\n\nn,a,b,k=map(int,input().split())\nprint(solve(n,a,b,k))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s202421127', 's306915261', 's320753488', 's409752533', 's709606283', 's890531820', 's850001525']
[26720.0, 7796.0, 26700.0, 6768.0, 5364.0, 3064.0, 26720.0]
[308.0, 282.0, 311.0, 2104.0, 22.0, 17.0, 389.0]
[547, 1059, 505, 453, 465, 370, 1059]
p03332
u062147869
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['from fractions import gcd\nimport sys\nsys.setrecursionlimit(10**7) \n\nN,A,B,K=map(int,input().split())\nmod = 998244353\n\ntable=[1]\na=1\nfor i in range(1,N+1):\n a=(a*pow(i,mod-2,mod))%mod\n table.append(a)\n\nnum=1\nfor i in range(1,N+1):\n num = (num*i) %mod\n\n\nnumber =0\nfor i in range(N):\n if (K-A*i)%B==0:\n j=(K-A*i)//B\n t = (num*num)%mod\n t = (t*table[i])%mod\n t = (t*table[j])%mod\n t = (t*table[N-i])%mod\n t = (t*table[N-j])%mod\n number = (number+t)%mod\nprint(number)', 'N,A,B,K=map(int,input().split())\nmod = 998244353\n\ntable=[1]\na=1\nfor i in range(1,N+1):\n a=(a*pow(i,mod-2,mod))%mod\n table.append(a)\n\nnum=1\nfor i in range(1,N+1):\n num = (num*i) %mod\n\n\nnumber =0\nfor i in range(N+1):\n if (K-A*i)%B==0 and K-A*i>=0:\n j=(K-A*i)//B\n if 0<=j<=N:\n t = (num*num)%mod\n t = (t*table[i])%mod\n t = (t*table[j])%mod\n t = (t*table[N-i])%mod\n t = (t*table[N-j])%mod\n number = (number+t)%mod\nprint(number)']
['Runtime Error', 'Accepted']
['s044557209', 's171159462']
[17668.0, 16968.0]
[1723.0, 1974.0]
[563, 554]
p03332
u170201762
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
["MOD = 998244353\ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n\n\nmemo = [0]*(N+1)\nmemo[0] = memo[N] = 1\nfor k in range(1,N//2+1):\n v = memo[k-1]*(N-k+1)*modinv(k,MOD)\n v %= MOD\n memo[k] = memo[N-k] = v\n\nN,A,B,K = map(int,input().split())\nn = 0\n\nfor i in range(N+1):\n j = K-A*i\n if j < 0:\n break\n if (K-A*i)%B==0:\n j //= B\n n+=(memo[i]*memo[j])%998244353\n n%=998244353\nprint(n%998244353)", "N,A,B,K = map(int,input().split())\nn = 0\nMOD = 998244353\ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n\n\nmemo = [0]*(N+1)\nmemo[0] = memo[N] = 1\nfor k in range(1,N//2+1):\n v = memo[k-1]*(N-k+1)*modinv(k,MOD)\n v %= MOD\n memo[k] = memo[N-k] = v\nfor i in range(N+1):\n j = K-A*i\n if j < 0:\n break\n if j%B==0 and j/B <= N:\n j //= B\n n+=memo[i]*memo[j]\n n%=998244353\nprint(n%998244353)"]
['Runtime Error', 'Accepted']
['s897423128', 's555661427']
[3064.0, 11708.0]
[17.0, 918.0]
[666, 659]
p03332
u201234972
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['def comb(n,k,p):\n \n from math import factorial\n if n<0 or k<0 or n<k: return 0\n if n==0 or k==0: return 1\n a=factorial(n) %p\n b=factorial(k) %p\n c=factorial(n-k) %p\n return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p\n\ndef power_func(a,b,p):\n \n if b==0: return 1\n if b%2==0:\n d=power_func(a,b//2,p)\n return d*d %p\n if b%2==1:\n return (a*power_func(a,b-1,p ))%p\n\nN, A, B, K = map(int, input().split())\nQ = 998244353\nans = 0\nfor i in range(N+1):\n if (K - A*i)%B == 0 and (K - A*i)/B <= N:\n j = (K - A*i)/B\n ans = (ans + comb(N,i,Q)*comb(N,j,Q))%Q\nprint(ans)', 'Q = 998244353\ndef modpower(a,b,Q):#a^b mod Q\n if b == 0:\n return 1\n if b%2 == 0:\n d = modpower(a,b//2,Q)\n return d*d%Q\n if b%2 == 1:\n return (a*modpower(a,b-1,Q))%Q\ndef factorials(n,Q):\n F = [1]*(n+1)\n R = [1]*(n+1)\n for i in range(n):\n F[i+1] = F[i]*(i+1)%Q\n R[i+1] = R[i]*modpower(i+1,Q-2,Q)\n return F, R\n\nN, A, B, K = map( int, input().split())\nans = 0\nF, R = factorials(N,Q)\nfor i in range( min(K//A, N)+1):\n if (K-A*i)%B == 0:\n print(i)\n j = (K-A*i)//B\n print(F[N]*R[j]%Q*R[N-j]%Q*F[N]*R[i]%Q*R[N-i]%Q)\n ans = (ans + F[N]*R[j]*%QR[N-j]%Q*F[N]*R[i]%Q*R[N-i]%Q)%Q\nprint(ans) \n', 'Q = 998244353\ndef modpower(a,b,Q):#a^b mod Q\n if b == 0:\n return 1\n if b%2 == 0:\n d = modpower(a,b//2,Q)\n return d*d%Q\n if b%2 == 1:\n return (a*modpower(a,b-1,Q))%Q\ndef factorials(n,Q):\n F = [1]*(n+1)\n R = [1]*(n+1)\n for i in range(n):\n F[i+1] = F[i]*(i+1)%Q\n R[i+1] = R[i]*modpower(i+1,Q-2,Q)\n return F, R\n\nN, A, B, K = map( int, input().split())\nans = 0\nF, R = factorials(N,Q)\nprint(F)\nprint(R)\nfor i in range( min(K//A, N)+1):\n if (K-A*i)%B == 0:\n print(i)\n j = (K-A*i)//B\n print(F[N]*R[j]*R[N-j]%Q*F[N]*R[i]*R[N-i]%Q)\n ans = (ans + F[N]*R[j]*R[N-j]%Q*F[N]*R[i]*R[N-i]%Q)%Q\nprint(ans) ', 'Q = 998244353\ndef modpower(a,b,Q):#a^b mod Q\n if b == 0:\n return 1\n if b%2 == 0:\n d = modpower(a,b//2,Q)\n return d*d%Q\n if b%2 == 1:\n return (a*modpower(a,b-1,Q))%Q\ndef factorials(n,Q):\n F = [1]*(n+1)\n R = [1]*(n+1)\n for i in range(n):\n F[i+1] = F[i]*(i+1)%Q\n R[i+1] = R[i]*modpower(i+1,Q-2,Q)\n return F, R\n\nN, A, B, K = map( int, input().split())\nans = 0\nF, R = factorials(N,Q)\n\nfor i in range( min(K//A, N)+1):\n if (K-A*i)%B == 0:\n j = (K-A*i)//B\n ans = (ans + F[N]*R[j]*%QR[N-j]%Q*F[N]*R[i]%Q*R[N-i]%Q)%Q\nprint(ans) \n', 'Q = 998244353\ndef getInv(N):\n inv = [0] * (N + 1)\n inv[0] = 1\n inv[1] = 1\n for i in range(2, N + 1):\n inv[i] = (-(Q // i) * inv[Q%i]) % Q\n return inv\n\nN, A, B, K = map( int, input().split())\nans = 0\ninvs = getInv(N)\nnCk = [1]*(N+1)\nfor i in range(1,N+1):\n nCk[i] = (nCk[i-1]*(N-i+1)*invs[i])%Q\nfor i in range(N+1):\n j = (K-A*i)//B\n if A*i + B*j == K and j <= N and 0 <= j:\n j = (K-A*i)//B\n ans = (ans + nCk[i]*nCk[j])%Q\nprint(ans)']
['Time Limit Exceeded', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s149750748', 's342241887', 's699446134', 's720036677', 's193002294']
[8072.0, 3064.0, 1779524.0, 3064.0, 26720.0]
[2104.0, 17.0, 2231.0, 17.0, 542.0]
[674, 745, 754, 672, 475]
p03332
u303019816
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['N, A, B, K = map(int, input().split(" "))\nmod = 998244353\nncr = [1] * (N + 1)\nv = 1\n\nprint(ncr)\nfor i in range(N):\n v = (v * ((N - i) % mod) * pow((i + 1), mod - 2, mod)) % mod\n ncr[i + 1] = v % mod\n\npat = 0\nfor a in range(N + 1):\n if (K - (a * A) < 0):\n break\n if (K - (a * A)) % B == 0 and ((K - (a * A)) // B) <= N:\n pat += ncr[a] * ncr[(K - (a * A)) // B]\n pat %= mod\n\nprint(pat % mod)', 'N, A, B, K = map(int, input().split(" "))\nmod = 998244353\nncr = [1] * (N + 1)\nv = 1\n\nfor i in range(N):\n v = (v * ((N - i) % mod) * pow((i + 1), mod - 2, mod)) % mod\n ncr[i + 1] = v % mod\n\npat = 0\nfor a in range(N + 1):\n if (K - (a * A) < 0):\n break\n if (K - (a * A)) % B == 0 and ((K - (a * A)) // B) <= N:\n pat += ncr[a] * ncr[(K - (a * A)) // B]\n pat %= mod\n\nprint(pat % mod)']
['Wrong Answer', 'Accepted']
['s641884492', 's865091235']
[15764.0, 14836.0]
[1828.0, 1808.0]
[422, 411]
p03332
u389910364
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['import bisect\nimport heapq\nimport itertools\nimport math\nimport operator\nimport os\nimport re\nimport string\nimport sys\nfrom collections import Counter, deque, defaultdict\nfrom copy import deepcopy\nfrom decimal import Decimal\nfrom fractions import gcd\nfrom functools import lru_cache, reduce\nfrom operator import itemgetter, mul, add, xor\n\nimport numpy as np\nfrom scipy.misc import comb\n\nif os.getenv("LOCAL"):\n sys.stdin = open("_in.txt", "r")\n\nsys.setrecursionlimit(2147483647)\nINF = float("inf")\nIINF = 10 ** 18\nMOD = 998244353\n\n\ndef get_factorials(max, mod=None):\n \n ret = [1]\n n = 1\n if mod:\n for i in range(1, max + 1):\n n *= i\n n %= mod\n ret.append(n)\n else:\n for i in range(1, max + 1):\n n *= i\n ret.append(n)\n return ret\n\n\ndef mod_invs(max, mod):\n \n invs = [1] * (max + 1)\n for x in range(2, max + 1):\n invs[x] = (-(mod // x) * invs[mod % x]) % mod\n return invs\n\n\ndef factorial_invs(max, mod):\n \n ret = []\n r = 1\n for inv in mod_invs(max, mod):\n r = r * inv % mod\n ret.append(r)\n return ret\n\n\nclass Combination:\n def __init__(self, max, mod):\n \n self._factorials = get_factorials(max, mod)\n self._finvs = factorial_invs(max, mod)\n self._mod = mod\n\n def ncr(self, n, r):\n """\n :param int n:\n :param int r:\n :rtype: int\n """\n if n < r:\n return 0\n return self._factorials[n] * self._finvs[r] % self._mod * self._finvs[n - r] % self._mod\n\n\nN, A, B, K = list(map(int, sys.stdin.readline().split()))\ncomb = Combination(max=N, mod=MOD)\nans = 0\n\nfor a in range(N + 1):\n if (K - a * A) % B != 0:\n continue\n b = int((K - a * A) // B)\n if not (0 <= a <= N and 0 <= b <= N):\n continue\n\n s = 0\n \n c = min(a, b)\n # A\n a -= c\n # B\n b -= c\n \n d = N - a - b - c\n \n while c >= 0 and d >= 0:\n s += comb.ncr(N, a) * comb.ncr(N - a, b) * comb.ncr(N - a - b, c)\n a += 1\n b += 1\n c -= 1\n d -= 1\n\n ans += s\n ans %= MOD\nprint(ans)\n', 'import os\nimport sys\n\nif os.getenv("LOCAL"):\n sys.stdin = open("_in.txt", "r")\n\nsys.setrecursionlimit(2147483647)\nINF = float("inf")\nIINF = 10 ** 18\nMOD = 998244353\n\n\ndef get_factorials(max, mod=None):\n \n ret = [1]\n n = 1\n if mod:\n for i in range(1, max + 1):\n n *= i\n n %= mod\n ret.append(n)\n else:\n for i in range(1, max + 1):\n n *= i\n ret.append(n)\n return ret\n\n\ndef mod_invs(max, mod):\n \n invs = [1] * (max + 1)\n for x in range(2, max + 1):\n invs[x] = (-(mod // x) * invs[mod % x]) % mod\n return invs\n\n\ndef factorial_invs(max, mod):\n \n ret = []\n r = 1\n for inv in mod_invs(max, mod):\n r = r * inv % mod\n ret.append(r)\n return ret\n\n\nclass Combination:\n def __init__(self, max, mod):\n \n self._factorials = get_factorials(max, mod)\n self._finvs = factorial_invs(max, mod)\n self._mod = mod\n\n def ncr(self, n, r):\n """\n :param int n:\n :param int r:\n :rtype: int\n """\n if n < r:\n return 0\n return self._factorials[n] * self._finvs[r] % self._mod * self._finvs[n - r] % self._mod\n\n\nN, A, B, K = list(map(int, sys.stdin.readline().split()))\ncomb = Combination(max=N, mod=MOD)\n# ans = 0\n\n# for a in range(N + 1):\n\n# continue\n# b = int((K - a * A) // B)\n# if not (0 <= a <= N and 0 <= b <= N):\n# continue\n#\n\n\n# c = min(a, b)\n# # A\n# a -= c\n# # B\n# b -= c\n\n# d = N - a - b - c\n\n# while c >= 0 and d >= 0:\n\n# a += 1\n# b += 1\n# c -= 1\n# d -= 1\n#\n# ans += s\n# ans %= MOD\n# print(ans)\n\n\n\n\n#\n\n# for a in range(N + 1):\n\n# continue\n# b = int((K - a * A) // B)\n# if not (0 <= a <= N and 0 <= b <= N):\n# continue\n# dp[0][a][b] += 1\n#\n\n# dp[i] += dp[i - 1]\n# dp[i, :-1] += dp[i - 1, 1:]\n# dp[i, :, :-1] += dp[i - 1, :, 1:]\n# dp[i, :-1, :-1] += dp[i - 1, 1:, 1:]\n# print(dp)\n# print(dp[-1][0][0])\n\n\n\nans = 0\nfor a in range(N + 1):\n if (K - a * A) % B != 0:\n continue\n b = int((K - a * A) // B)\n if not (0 <= a <= N and 0 <= b <= N):\n continue\n ans += comb.ncr(N, a) * comb.ncr(N, b)\n ans %= MOD\nprint(ans)\n']
['Time Limit Exceeded', 'Accepted']
['s867527054', 's296297321']
[50020.0, 38704.0]
[2110.0, 815.0]
[2607, 3183]
p03332
u403301154
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['n, A, B, k = list(map(int, input().split()))\n\nMOD = 998244353\nMAX = 3*10**5+2\n\nfac = [0 for i in range(MAX)]\ninv = [0 for i in range(MAX)]\nifac = [0 for i in range(MAX)]\nfac[0] = 1; fac[1] = 1\ninv[1] = 1\nifac[0] = 1; ifac[1] = 1\n\nfor i in range(2, MAX):\n fac[i] = fac[i-1]*i%MOD\n inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD\n ifac[i] = ifac[i-1]*inv[i]%MOD\n\ndef nCk(n, k):\n if n<k or n<0 or k<0: return 0\n return (((fac[n]*ifac[k])%MOD)*ifac[n-k])%MOD\n\nans = 0\nfor i in range(n+1):\n if (k-A*i)%B == 0:\n b = (k-A*i)//B\n if 0<=b<=n:\n ans = (ans+nCk(n, i)*nCk(n, b))%MOD\n\nif ans==0:\n print(1)\nelse:\n print(ans)\nprint(nCk(4, 0))', 'n, A, B, k = list(map(int, input().split()))\n\nMOD = 998244353\nMAX = 3*10**5+2\n\nfac = [0 for i in range(MAX)]\ninv = [0 for i in range(MAX)]\nifac = [0 for i in range(MAX)]\nfac[0] = 1; fac[1] = 1\ninv[1] = 1\nifac[0] = 1; ifac[1] = 1\n\nfor i in range(2, MAX):\n fac[i] = fac[i-1]*i%MOD\n inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD\n ifac[i] = ifac[i-1]*inv[i]%MOD\n\ndef nCk(n, k):\n if n<k or n<0 or k<0: return 0\n return (((fac[n]*ifac[k])%MOD)*ifac[n-k])%MOD\n\nans = 0\nfor i in range(n+1):\n if (k-A*i)%B == 0:\n b = (k-A*i)//B\n if 0<=b<=n:\n ans = (ans+nCk(n, i)*nCk(n, b))%MOD\n\nif ans==0:\n print(1)\nelse:\n print(ans)']
['Wrong Answer', 'Accepted']
['s724453130', 's984712901']
[38704.0, 38704.0]
[897.0, 885.0]
[635, 618]
p03332
u415905784
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['from scipy.misc import comb\nN,A,B,K = map(int, input().split())\ncount = 0\nP = []\nc = 0\nwhile c < N:\n if K % B == 0:\n if K//B <= N:\n \n P.append([c, K//B])\n K -= A\n c += 1\nfor p in P:\n count += comb(N, p[0], exact=True) * comb(N, p[1], exact=True)\nif count > 998244353:\n count = count % 998244353\nprint(count)', 'import math\ndef divide(A,B,C,D,E):\n F = [B,C,D,E]\n F.sort()\n tail = F[-1]\n F = F[:-1]\n G = 1\n for i in range(A-tail):\n G *= A - i\n for f in F:\n G /= f\n return G\nN,A,B,K = map(int, input().split())\ncount = 0\nNf = math.factorial(N)\nP = []\nc = 0\nwhile c < N:\n if K % B == 0:\n if K//B <= N:\n print((c, K//B))\n P.append([c, K//B])\n K -= A\n c += 1\nfor p in P:\n for G in range(min(p[0],p[1]) + 1):\n W = N - p[0] - p[1] + G\n if W >= 0:\n #divider = math.factorial(p[0]-G) * math.factorial(p[1]-G) * math.factorial(G) * math.factorial(W)\n pattern = divide(Nf, math.factorial(p[0]-G), math.factorial(p[1]-G), math.factorial(G), math.factorial(W))\n count += pattern\ncount *= 10 ** k\nif count > 998244353:\n count = count % 998244353\nprint(count)', 'def fib(n, p):\n F = [1] * (n + 1)\n for i in range(2, n + 1):\n F[i] = F[i - 1] * i % p\n return F\ndef finv(F, p):\n N = len(F) - 1\n Finv = list(F)\n Finv[-1] = pow(F[-1], p - 2, p)\n for i in range(N - 1, -1, -1):\n Finv[i] = Finv[i + 1] * (i + 1) % p\n return Finv\ndef comb(F, Finv, n, a, p):\n return F[n] * Finv[a] * Finv[n - a] % p\nN, A, B, K = map(int, input().split())\np = 998244353\nF = fib(N, p)\nFinv = finv(F, p)\ncnt = 0\nfor a in range(min(N + 1, K // A + 1)):\n _A = A * a\n if _A > K:\n continue\n if (K - _A) % B > 0:\n continue\n b = (K - _A) // B\n if b > N:\n continue\n cnt += comb(F, Finv, N, a, p) * comb(F, Finv, N, b, p)\n cnt %= p\nprint(cnt)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s281144392', 's385872447', 's455247358']
[50960.0, 46116.0, 26996.0]
[2111.0, 2106.0, 546.0]
[341, 785, 674]
p03332
u478870821
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['from sys import exit, setrecursionlimit, stderr\nfrom functools import reduce\nfrom itertools import *\nfrom collections import defaultdict\nfrom bisect import bisect\n\ndef read():\n return int(input())\n\ndef reads():\n return [int(x) for x in input().split()]\n\nP = 998244353\nMM = 10**6\n\nfact = [1]\nfor i in range(1, MM):\n fact.append((fact[i-1] * i) % P)\n\ndef inv(x):\n return pow(x, P-2, P)\n\ndef comb(n, k):\n print(n, k)\n assert 0 <= k <= n\n return (fact[n] * inv(fact[k]) * inv(fact[n-k])) % P\n\nsetrecursionlimit(100000)\n\nN, A, B, K = reads()\n\nresult = 0\nfor x in range(N+1):\n if (K - A * x) % B != 0:\n continue\n y = (K - A * x) // B\n if not (0 <= y <= N):\n continue\n result = (result + comb(N, x) * comb(N, y)) % P\n\nprint(result)', 'def read():\n return int(input())\n\ndef reads():\n return [int(x) for x in input().split()]\n\nP = 998244353\n\nN, A, B, K = reads()\n\ndef inv(n):\n return pow(n, P-2, P)\n\nfact = [1] * (N+1)\nfor i in range(1, N+1):\n fact[i] = fact[i-1] * i % P\n\ninvfact = [inv(fact[N])] * (N+1)\nfor i in range(N, 0, -1):\n invfact[i-1] = invfact[i] * i % P\n\ndef comb(n, k):\n \n return fact[n] * invfact[k] * invfact[n-k] % P\n\nresult = 0\nfor x in range(N+1):\n y, r = divmod(K - A * x, B)\n if r == 0 and 0 <= y <= N:\n result = result + comb(N, x) * comb(N, y) % P\n\nprint(result % P)']
['Wrong Answer', 'Accepted']
['s414814000', 's398147651']
[46284.0, 26740.0]
[2106.0, 567.0]
[741, 584]
p03332
u497625442
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
["from functools import lru_cache\n\nL = input().split()\nsprime = 998244353 # approx 10**9\nN = int(L[0])\nA = int(L[1])\nB = int(L[2])\nK = int(L[3])\n\ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n\n@lru_cache(maxsize=N)\ndef factorial(m):\n\ta = 1\n\tfor i in range(1,m):\n\t\ta = (a*i) % sprime\n\treturn a\n\ndef binom(m):\n\tif N == m:\n\t\treturn 1\n\telif m == 1:\n\t\treturn N\n\telif m > N:\n\t\treturn 0\n\telse:\n\t\treturn (factorial(N) * modinv(factorial(m),sprime) * modinv(factorial(N-m),sprime)) % sprime\n\n# max is A*N + B*N\nsum = 0\nfor i in range(0,N):\n\tif (K - A*i) % B == 0:\n\t\tj = (K-A*i)//B\n\t\tsum += (binom(i) * binom(j)) % sprime\n\nprint(sum)\n\n", "N,A,B,K = map(int,input().split()\nsprime = 998244353 # approx 10**9\nA,B = sorted((A,B))\nif (A+B) * N < K:\n\tprint(0)\n\texit()\n\ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n\nmemo = [0] * (N+1)\nmemo[0] = memo[N] = 1\nfor i in range(1,N//2+1):\n\tv = memo[i-1] * (N-i+1) * modinv(i,sprime)\n\tv = v % sprime\n\tmemo[i] = memo[N-i] = v\n\n# max is A*N + B*N\nsum = 0\nfor j in range(0,N):\n\ti = (K-B*j)//A\n\tif 0 <= i <= N and A*i+B*j==K:\n\t\tsum += memo[i] * memo[j]\n\t\tsum %= sprime\n\nprint(sum)\n\n", "from functools import lru_cache\n\nL = input().split()\nsprime = 998244353 # approx 10**9\nN = int(L[0])\nA = int(L[1])\nB = int(L[2])\nK = int(L[3])\n\ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n\n@lru_cache(maxsize=N)\ndef factorial(m):\n\ta = 1\n\tfor i in range(1,m):\n\t\ta = (a*i) % sprime\n\ndef binom(m):\n\tif N == m:\n\t\treturn 1\n\telif m == 1:\n\t\treturn N\n\telif m > N:\n\t\treturn 0\n\telse:\n\t\treturn (a * modinv(b,sprime) * modinv(c*sprime)) % sprime\n\n# max is A*N + B*N\nsum = 0\nfor i in range(0,N):\n\tif (K - A*i) % B == 0:\n\t\tj = (K-A*i)//B\n\t\tsum += (binom(N,i) * binom(N,j)) % sp\n\nprint(sum)\n", "from functools import lru_cache\n\nL = input().split()\nsprime = 998244353 # approx 10**9\nN = int(L[0])\nA = int(L[1])\nB = int(L[2])\nK = int(L[3])\n\ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n\n@lru_cache(maxsize=N)\ndef factorial(m):\n\ta = 1\n\tfor i in range(1,m):\n\t\ta = (a*i) % sprime\n\treturn a\n\ndef binom(m):\n\tif N == m:\n\t\treturn 1\n\telif m == 1:\n\t\treturn N\n\telif m > N:\n\t\treturn 0\n\telse:\n\t\treturn (factorial(N) * modinv(factorial(m),sprime) * modinv(factorial(N-m),sprime)) % sprime\n\n# max is A*N + B*N\nsum = 0\nfor i in range(0,N):\n\tif (K - A*i) % B == 0:\n\t\tj = (K-A*i)//B\n\t\tsum += (binom(N,i) * binom(N,j)) % sp\n\nprint(sum)\n\n", "from functools import lru_cache\n\nL = input().split()\nsprime = 998244353 # approx 10**9\nN = int(L[0])\nA = int(L[1])\nB = int(L[2])\nK = int(L[3])\n\ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n\n@lru_cache(maxsize=N)\ndef factorial(m):\n\ta = 1\n\tfor i in range(1,m):\n\t\ta = (a*i) % sprime\n\ndef binom(m):\n\tif N == m:\n\t\treturn 1\n\telif m == 1:\n\t\treturn N\n\telif m > N:\n\t\treturn 0\n\telse:\n\t\treturn (factorial(N) * modinv(factorial(m),sprime) * modinv(factorial(N-m),sprime)) % sprime\n\n# max is A*N + B*N\nsum = 0\nfor i in range(0,N):\n\tif (K - A*i) % B == 0:\n\t\tj = (K-A*i)//B\n\t\tsum += (binom(N,i) * binom(N,j)) % sp\n\nprint(sum)\n\n", 'import math\nL = input().split()\nsp = 998244353\n# approx 10**9\nN = int(L[0])\nA = int(L[1])\nB = int(L[2])\nK = int(L[3])\n\ndef my_binom(n,m):\n\tif n == m:\n\t\treturn 1\n\telif m == 1:\n\t\treturn n\n\telif m > n:\n\t\treturn 0\n\telse:\n\t\ta = math.factorial(n)\n\t\tb = math.factorial(m)\n\t\tc = math.factorial(n - m)\n\t\treturn a // (b*c)\n\n# max is A*N + B*N\nsum = 0\nfor i in range(0,N):\n\tif (K - A*i) % B == 0:\n\t\tj = (K-A*i)//B\n\t\tsum += (binom(N,i) * binom(N,j)) % sp\n\nprint(sum)\n', "N,A,B,K = map(int,input().split())\nsprime = 998244353 # approx 10**9\nA,B = sorted((A,B))\nif (A+B) * N < K:\n\tprint(0)\n\texit()\n \ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n \ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n \nmemo = [0] * (N+1)\nmemo[0] = memo[N] = 1\nfor i in range(1,N//2+1):\n\tv = memo[i-1] * (N-i+1) * modinv(i,sprime)\n\tv = v % sprime\n\tmemo[i] = memo[N-i] = v\n \n# max is A*N + B*N\nsum = 0\nfor b in range(N+1):\n a = (K-b*B)//A\n if 0 <= a <= N and a*A+b*B == K:\n sum += memo[a]*memo[b]\n sum %= sprime\n\nprint(sum)"]
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s242868188', 's362412368', 's519587124', 's618049977', 's901520274', 's944550344', 's232017370']
[3684.0, 2940.0, 3828.0, 3828.0, 3572.0, 3064.0, 10128.0]
[2107.0, 17.0, 50.0, 141.0, 49.0, 45.0, 897.0]
[864, 718, 818, 864, 854, 455, 727]
p03332
u543954314
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['from math import factorial as fac\ndef cc(n,r):\n return fac(n)//fac(r)//fac(n-r)\nn, a, b, k = map(int, input().split())\nmod = 998244353\nfor i in range(min(k//a+1,n+1)):\n j = k-a*i\n if j%b == 0 andj<=n:\n ans += cc(n,i)*cc(n,j)%mod\n ans %= mod\nprint(ans)', 'n, a, b, k = map(int, input().split())\nmod = 998244353\nans = 0\nccn = [0]*(n+1)\nccn[0] = 1\nfor i in range(1,n+1):\n ccn[i] = ccn[i-1]*(n+1-1)//i%mod\nfor i in range(min(k//a,n)+1):\n jof = k-a*i\n if jof%b==0 and jof<=n*b:\n j = jof//b\n ans += ccn[i]*ccn[j]%mod\n ans %= mod\nprint(ans)', 'n,a,b,k = map(int,input().split())\nmod = 998244353\nfun = [1]*(n+1)\nfor i in range(1,n+1):\n fun[i] = fun[i-1]*i%mod\nrev = [1]*(n+1)\nrev[n] = pow(fun[n],mod-2,mod)\nfor i in range(n-1,0,-1):\n rev[i] = rev[i+1]*(i+1)%mod\ndef nCr(n,r):\n if r > n:\n return 0\n return fun[n]*rev[r]%mod*rev[n-r]%mod\nans = 0\nfor i in range(min(n,k//a)+1):\n j = (k-a*i)//b\n if i*a+j*b == k and 0<=j<=n:\n ans += nCr(n,i)*nCr(n,j)\n ans %= mod\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s081380306', 's918562994', 's038959283']
[2940.0, 14880.0, 27764.0]
[17.0, 370.0, 632.0]
[260, 290, 439]
p03332
u547085427
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['n, a, b, k = map(int, input().split())\nMOD = 998244353\n\na_max = min(k // a, n)\npair = []\nfor i in range(a_max):\n if (k - a * i) % b == 0:\n j = (k - a * i) // b\n if j <= n:\n pair.append([i % MOD,j % MOD])\n\ninv = [0] * (n + 1)\ninv[1] = 1\nfor i in range(2, n + 1):\n inv[i] = (-(MOD // i) * inv[MOD % i]) % MOD\n\nnCr = [0] * (n + 1)\nnCr[0] = 1\nfor r in range(1, n + 1):\n nCr[r] = (nCr[r - 1] * (n - r + 1) * inv[r]) % MOD\n# print(nCr)\n\nprint(pair)\n\nresult = 0\nfor p in pair:\n result += (nCr[p[0]] % MOD) * (nCr[p[1]] % MOD)\nprint(result % MOD)', '# coding: utf-8\n# Your code here!\n\nn, a, b, k = map(int, input().split())\nMOD = 998244353\n\ninv = [0] * ( n + 1)\ninv[1] = 1\nfor i in range(2, n + 1):\n inv[i] = (-(MOD // i) * inv[MOD % i]) % MOD\n\nnCr = [0] * ( n + 1)\nnCr[0] = 1\nfor i in range(1, n+1):\n nCr[i] = (nCr[i-1] * (n - i + 1) * inv[i]) % MOD\n\nresult = 0\nmaxA = min(n, k//a)\nfor i in range(maxA + 1):\n if ( k - a * i) % b == 0:\n j = ( k - a * i) // b\n if j <= n:\n result += (nCr[i] * nCr[j]) % MOD\nif result == 0:\n print(1)\nelse:\n print(result % MOD)']
['Wrong Answer', 'Accepted']
['s308651301', 's742497327']
[76452.0, 26720.0]
[755.0, 541.0]
[576, 548]
p03332
u659640418
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['import itertools\nn, a, b, k = map(int, input().split())\ncount = 0\nfor i in range(n):\n if (n - (i * a)) % b == 0:\n count += (itertools.combinations(n, i) * itertools.combinations(n, (n-i*a)/b))\nprint(count/998244353)', 'import math\ndef C(n, r):\n return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))\nn, a, b, k = map(int, input().split())\ncount = 0\nfor i in range(math.floor(k/a)):\n if (k - (i * a)) % b == 0:\n count += (C(n, i) * C(n, (k-a*i)/b))\nprint(count%998244353)', 'import itertools\nimport math\nn, a, b, k = map(int, input().split())\ncount = 0\nfor i in range(math.floor(k/a)):\n if (k - (i * a)) % b == 0:\n count += (itertools.combinations(n, i) * itertools.combinations(n, (k-i*a)/b))\nprint(count%998244353)', 'import math\n\ndef P(n, r):\n return math.factorial(n)//math.factorial(n-r)\n\ndef C(n, r):\n return P(n, r)//math.factorial(r)\n\nn, a, b, k = map(int, input().split())\ncount = 0\nfor i in range(math.floor(k/a)):\n if (k - (i * a)) % b == 0:\n count += (C(n, i) * C(n, (k-a*i)/b))\nprint(count%998244353)', 'import itertools\nimport math\nn, a, b, k = map(int, input().split())\ncount = 0\nfor i in range(math.floor(n/a)):\n if (n - (i * a)) % b == 0:\n count += (itertools.combinations(n, i) * itertools.combinations(n, (n-i*a)/b))\nprint(count%998244353)', 'import itertools\nimport math\nn, a, b, k = map(int, input().split())\ncount = 0\nfor i in range(math.floor(n/a)):\n if (n - (i * a)) % b == 0:\n count += (itertools.combinations(n, i) * itertools.combinations(n, (n-i*a)/b))\nprint(count/998244353)', 'import math\nimport sys\nsys.setrecursionlimit(100000000000000000000000000000000000000000)\n \nnCr = {}\ndef cmb(n, r):\n if r == 0 or r == n: return 1\n if r == 1: return n\n if (n,r) in nCr: return nCr[(n,r)]\n nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)\n return nCr[(n,r)]\n \n \nn, a, b, k = map(int, input().split())\ncount = 0\n \nfor i in range(n+1):\n if (k - (i * a)) % b == 0:\n count += cmb(n, i) * cmb(n, (k-i*a)/b)\nprint(count%998244353)', 'import itertools\nimport math\n\ndef P(n, r):\n return math.factorial(n)//math.factorial(n-r)\n\ndef C(n, r):\n return P(n, r)//math.factorial(r)\n\nn, a, b, k = map(int, input().split())\ncount = 0\nfor i in range(k):\n if (k - (i * a)) % b == 0:\n count += (C(n, i) * C(n, (k-a*i)/b))\nprint(count%998244353)', 'import math\nfrom scipy.special import comb\n\nn, a, b, k = map(int, input().split())\ncount = 0\nfor i in range(math.floor(k/a)):\n if (k - (i * a)) % b == 0:\n count += (comb(n, i) * comb(n, (k-a*i)/b))\nprint(count%998244353)', "N,A,B,K = map(int,input().split())\nsprime = 998244353 # approx 10**9\nA,B = sorted((A,B))\nif (A+B) * N < K:\n\tprint(0)\n\texit()\n \ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n \ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n \nmemo = [0] * (N+1)\nmemo[0] = memo[N] = 1\nfor i in range(1,N//2+1):\n\tv = memo[i-1] * (N-i+1) * modinv(i,sprime)\n\tv = v % sprime\n\tmemo[i] = memo[N-i] = v\n \n# max is A*N + B*N\nsum = 0\nfor b in range(N+1):\n a = (K-b*B)//A\n if 0 <= a <= N and a*A+b*B == K:\n sum += memo[a]*memo[b]\n sum %= sprime\n \nprint(sum)"]
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s358781749', 's555458781', 's556375473', 's674406781', 's713373029', 's721985925', 's803970016', 's865512409', 's998989083', 's823251716']
[3060.0, 6340.0, 3060.0, 6352.0, 3060.0, 3060.0, 3064.0, 6372.0, 24036.0, 10128.0]
[93.0, 2104.0, 43.0, 2104.0, 18.0, 18.0, 17.0, 2104.0, 360.0, 880.0]
[225, 275, 251, 309, 251, 251, 453, 312, 230, 728]
p03332
u695811449
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['def squaremod(A,p,mod):\n if p==0:\n return 1\n if p%2==1:\n return (A*squaremod(A,p-1,mod))%mod\n if p%2==0:\n return (squaremod(A,p/2,mod) %mod)**2 %mod\n\nINV=[None]*(N+1)\nfor i in range(1,N+1):\n INV[i]=squaremod(i,mod-2,mod)\n\ndef Combi(n,r):\n ANS=1\n for i in range(min(r,n-r)):\n ANS *= (N-i)*INV[i+1]\n\n return ANS\n \n\nANS=0\n\nif B>A:\n (A,B)=(B,A)\n\nran=K//A\n\nfor i in range(min(ran,N)+1):\n q, r = divmod(K-(A*i), B)\n if r==0 and q<=N:\n ANS = (ANS+(Combi(N,i)*Combi(N,q)))%mod\n #print(q,r,ANS)\n\nprint(ANS)', 'N,A,B,K=map(int,input().split())\nmod=998244353\n\nINV=[None]*(N+1)\nfor i in range(1,N+1):\n INV[i]=pow(i,mod-2,mod)\n\nCombi=[None]*(N+1)\nCombi[0]=1\nCombi[1]=N\nfor i in range(2,N//2+2):\n Combi[i]=Combi[i-1]*(N-i+1)*INV[i] %mod\nfor i in range(N//2+2,N+1):\n Combi[i]=Combi[N-i]\n\n\nANS=0\n\nif B>A:\n (A,B)=(B,A)\n\nran=K//A\n\nfor i in range(min(ran,N)+1):\n q, r = divmod(K-(A*i), B)\n if r==0 and q<=N:\n ANS = (ANS+(Combi[i]*Combi[q])%mod)%mod\n\nprint(ANS)\n\n']
['Runtime Error', 'Accepted']
['s868764686', 's397643092']
[3064.0, 22000.0]
[18.0, 1822.0]
[596, 467]
p03332
u763115743
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['MOD = 998244353\n\n\ndef get_inv(n):\n inv = [0] * (n + 1)\n inv[1] = 1\n\n for i in range(2, n + 1):\n inv[i] = (-(MOD // i) * inv[MOD % i]) % MOD\n\n return inv\n\n\ndef get_cmb(n):\n inv = get_inv(n)\n cmb = [0] * (n + 1)\n cmb[0] = 1\n\n for i in range(1, n + 1):\n cmb[i] = (cmb[i - 1] * (n - i + 1) * inv[i]) % MOD\n\n return cmb\n\n\ndef solve(n, a, b, k):\n ans = 0\n cmb = get_cmb(n)\n print(cmb)\n for a_num in range(n + 1):\n b_num = (k - a * a_num) // b\n if (a * a_num + b * b_num == k) and (0 <= b_num <= n):\n ans += (cmb[a_num] * cmb[b_num]) % MOD\n ans %= MOD\n return ans\n\n\ndef main():\n n, a, b, k = list(map(int, input().split()))\n ans = solve(n, a, b, k)\n print(ans)\n\n\nmain()\n', 'MOD = 998244353\n\n\ndef get_inv(n):\n inv = [0] * (n + 1)\n inv[1] = 1\n\n for i in range(2, n + 1):\n inv[i] = (-(MOD // i) * inv[MOD % i]) % MOD\n\n return inv\n\n\ndef get_cmb(n):\n inv = get_inv(n)\n cmb = [0] * (n + 1)\n cmb[0] = 1\n\n for i in range(1, n + 1):\n cmb[i] = (cmb[i - 1] * (n - i + 1) * inv[i]) % MOD\n\n return cmb\n\n\ndef solve(n, a, b, k):\n ans = 0\n cmb = get_cmb(n)\n for a_num in range(n + 1):\n b_num = (k - a * a_num) // b\n if (a * a_num + b * b_num == k) and (0 <= b_num <= n):\n ans += (cmb[a_num] * cmb[b_num]) % MOD\n ans %= MOD\n return ans\n\n\ndef main():\n n, a, b, k = list(map(int, input().split()))\n ans = solve(n, a, b, k)\n print(ans)\n\n\nmain()\n']
['Wrong Answer', 'Accepted']
['s469130698', 's244678072']
[26720.0, 26720.0]
[412.0, 401.0]
[764, 749]
p03332
u968404618
2,000
1,048,576
Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows: * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored. Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors. Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.
['from scipy.misc import comb\n\nmod = 998244353\n\nn, a, b, k = map(int, input().split())\n\nans = 0\nfor i in range(n+1):\n Num = (k-a*i)\n if (0 <= Num//b) and (Num//b <= n) and (Num%b == 0):\n j = Num//b\n ans += comb(n, i, exact=True) * comb(n, j, exact=True)\nprint(ans%mod)', 'mod = 998244353\n\ndef comb(n, r):\n if 2 * r > n: return comb(n, n-r)\n return fac[n] * inv[r] * inv[n-r] % mod\n\nn, a, b, k = map(int, input().split())\n\nfac = [1] * (n+2)\ninv = [1] * (n+2)\nfor i in range(2, n+1):\n fac[i] = fac[i-1] * i % mod\ninv[n] = pow(fac[n], mod - 2, mod)\nfor i in range(n-1, 1, -1):\n inv[i] = inv[i + 1] * (i + 1) % mod\n\nans = 0\nfor i in range(n+1):\n Num = (k-a*i)\n if (0 <= Num//b) and (Num//b <= n) and (Num%b == 0):\n j = Num//b \n ans += comb(n, i) * comb(n, j) \nprint(ans%mod)']
['Time Limit Exceeded', 'Accepted']
['s241593294', 's164229702']
[15280.0, 26740.0]
[2109.0, 657.0]
[282, 526]
p03341
u009774873
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
["N=int(input())\nA=input().split(' ')\n\nfor i in range(N):\n\tA[i]=int(A[i])\n\nnum=0\nfor i in range(N):\n\tplus=0\n\txor=0\n\tfor j in range(N-i):\n\t\tplus=plus+A[i+j]\n\t\txor=xor^A[i+j]\n\t\tif plus==xor:\n\t\t\tnum=num+1\n\t\telse:\n\t\t\tbreak\n\nprint(num)\n", "N=int(input())\nS=input()\n\narr=[]\nnum=0\nfor i in range(N-1):\n\tif S[i+1]=='E':\n\t\tnum=num+1\n\narr.append(num)\n\nfor i in range(N-1):\n\tif S[i]=='W':\n\t\tif S[i+1]=='E':\n\t\t\tarr.append(arr[-1])\n\t\telse:\n\t\t\tarr.append(arr[-1]+1)\n\telif S[i+1]=='E':\n\t\tarr.append(arr[-1]-1)\n\telse:\n\t\tarr.append(arr[-1])\n\nprint(min(arr))\n"]
['Runtime Error', 'Accepted']
['s447089059', 's164025313']
[3672.0, 15520.0]
[19.0, 197.0]
[229, 306]
p03341
u037221289
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
["N = int(input())\nS = input()\nleft = 0\nright = S[1:].count('E')\nMIN = left + right\nfor i in range(1,N):\n if S[i] == 'W':\n left += 1\n else:\n right -= 1\n \n if i==N-1:\n MIN = min(MIN,S[:i].count('W'))\n else:\n MIN = min(left+right,MIN)\nprint(MIN)\n ", "N = int(input())\nS = input()\nleft = 1 if S[0] == 'W' else 0\nright = S[1:].count('E')\nMIN = right \nfor i in range(1,N):\n if S[i] == 'W':\n MIN = min(MIN,left+right)\n left += 1\n else:\n MIN = min(MIN,left+right)\n right -= 1\n \n if i==N-1:\n MIN = min(MIN,S[:i].count('W'))\n\nprint(MIN)"]
['Wrong Answer', 'Accepted']
['s919009338', 's583764836']
[3700.0, 3672.0]
[200.0, 184.0]
[261, 298]
p03341
u064408584
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
["n=int(input())\ns=input()\na=[]\nfor i in s:\n if i=='W': a.append(1)\n else: a.append(-1)\na2=[-1*i for i in a]\nsuma=[-a[0]]\nfor i in range(len(a)-1):\n suma.append(-a[i+1]+suma[i])\nsuma2=[sum(a2)]\nfor i in range(len(a2)-1):\n suma2.append(suma2[i]+a2[i])\n#print(a,a2)\ncount=0\nfor i in range(len(a)):\n d=suma[i]+suma2[i]\n if count<d:count=d\n #print(sum(a[i+1:]),sum(a2[:i]),d)\nprint((n-1-count)//2)", "n=int(input())\ns=input()\na=[]\nfor i in s:\n if i=='W': a.append(1)\n else: a.append(-1)\na2=[-1*i for i in a]\nsuma=[sum(a)-a[0]]\nfor i in range(len(a)-1):\n suma.append(-a[i+1]+suma[i])\nsuma2=[0]\nfor i in range(len(a2)-1):\n suma2.append(suma2[i]+a2[i])\n#print(a,a2)\ncount=0\nfor i in range(len(a)):\n d=suma[i]+suma2[i]\n if count<d:count=d\n #print(sum(a[i+1:]),sum(a2[:i]),d)\nprint((n-1-count)//2)"]
['Wrong Answer', 'Accepted']
['s354844995', 's189849025']
[32032.0, 32032.0]
[313.0, 300.0]
[412, 412]
p03341
u089142196
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['ARC098 - Attention\n \nShoji Taisaku(FJK 庄司 大作)\n2020/03/11 (水) 11:33\n受信トレイ; 送信済みトレイ\n宛先:\nShoji Taisaku(FJK 庄司 大作);\nN=int(input())\nS=input()\n\nleft=[0]*N\nright=[0]*N\nto_change=[0]*N\n\nif S[0]=="E":\n right[0]=1\nelse:\n left[0]=1\n\nfor i in range(1,N):\n if S[i]=="W":\n left[i] = left[i-1]+1\n right[i] = right[i-1]\n if S[i]=="E":\n right[i] = right[i-1]+1\n left[i]= left[i-1]\n\nto_change[0]=right[-1]-right[0]\nto_change[-1]=left[-2]\n\nfor j in range(1,N-1):\n to_change[j]=(right[-1]-right[j])+(left[j-1])\n#print(to_change)\nprint(min(to_change))', 'N=int(input())\nS=input()\n\nleft=[0]*N\nright=[0]*N\nto_change=[0]*N\n\nif S[0]=="E":\n right[0]=1\nelse:\n left[0]=1\n\nfor i in range(1,N):\n if S[i]=="W":\n left[i] = left[i-1]+1\n right[i] = right[i-1]\n if S[i]=="E":\n right[i] = right[i-1]+1\n left[i]= left[i-1]\n\nto_change[0]=right[-1]-right[0]\nto_change[-1]=left[-2]\n\nfor j in range(1,N-1):\n to_change[j]=(right[-1]-right[j])+(left[j-1])\n#print(to_change)\nprint(min(to_change))']
['Runtime Error', 'Accepted']
['s170005838', 's698672975']
[3064.0, 29468.0]
[17.0, 270.0]
[619, 461]
p03341
u104282757
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['# E\nfrom heapq import heappush, heappop\nimport numpy as np\n\nN, K, Q = map(int, input().split())\nA = list(map(int, input().split()))\n\nA_args = np.argsort(A)\n\nnodeid = np.ones(N).astype("int32")\ncanput = np.ones(N)\nnodeid_dict = dict()\nnodeid_dict[1] = [0, N]\n\n# initial output\nres = A[A_args[Q-1]] - A[A_args[0]]\n\nind_del = 0\n\nfor i in range(N):\n \n nid = A_args[i]\n \n \n ndid = nodeid[nid]\n nodeid[nid] = 0\n left, right = nodeid_dict[ndid]\n nodeid[(nid+1):right] = i+2\n nodeid_dict[nid] = [left, nid]\n nodeid_dict[i+2] = [nid+1, right]\n\n # update canput\n canput[nid] = 0\n \n canput[left:nid] = 0\n h = []\n for j in range(left, nid):\n heappush(h, (-A[j], j))\n while len(h) >= K:\n _, j = heappop(h)\n canput[j] = 1\n \n canput[(nid+1):right] = 0\n h = []\n for j in range(nid+1, right):\n heappush(h, (-A[j], j))\n while len(h) >= K:\n _, j = heappop(h)\n canput[j] = 1\n \n # break\n if canput.sum() <= Q:\n break\n \n # calculate\n q = 0\n qmin = 10**9\n qmax = 1\n for i in range(N):\n if canput[A_args[i]] == 1:\n q += 1\n qmin = min(A[A_args[i]], qmin)\n qmax = max(A[A_args[i]], qmax)\n if q == Q:\n r = qmax - qmin\n break\n res = min(res, r)\nprint(res)', '# C\nN = int(input())\nS = list(input())\n\n\nres = 0\nfor i in range(1, N):\n if S[i] == "E":\n res += 1\nres_min = res\nfor i in range(1, N):\n if S[i-1] == "W":\n res += 1\n if S[i] == "E":\n res -= 1\n res_min = min(res, res_min)\nprint(res_min)']
['Runtime Error', 'Accepted']
['s702179149', 's387135447']
[14188.0, 5792.0]
[478.0, 213.0]
[1372, 266]
p03341
u132434645
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['n, k, q = map(int, input().split())\na = [int(x) for x in input().split()]\nm = None\nfor x in a:\n b = []\n c = []\n for y in a:\n if y < x:\n if len(c) >= k:\n c.sort()\n b.extend(c[:len(c) - k + 1])\n c = []\n else:\n c.append(y)\n if len(c) >= k:\n c.sort()\n b.extend(c[:len(c) - k + 1])\n if len(b) >= q:\n b.sort()\n if m is None or m > b[q - 1] - x: m = b[q - 1] - x\nprint(m)\n', "n = int(input())\ns = input()\na = [0] * n\nif s[0] == 'W': a[0] = 1\nfor i in range(1, n):\n c = s[i]\n if c == 'E':\n a[i] = a[i - 1]\n else:\n a[i] = a[i - 1] + 1\nb = [0] * n\nif s[n - 1] == 'E': b[n - 1] = 1\nfor i in range(n - 2, -1, -1):\n c = s[i]\n if c == 'W':\n b[i] = b[i + 1]\n else:\n b[i] = b[i + 1] + 1\nm = n\nfor i in range(n):\n m = min(m, a[i] + b[i])\nprint(m - 1)\n"]
['Runtime Error', 'Accepted']
['s720464906', 's257548170']
[3064.0, 17916.0]
[17.0, 314.0]
[485, 414]
p03341
u135116520
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['N=int(input())\nS=input()\nDP=[0]*N\nl=0\nfor i,x in enumerate(S):\n DP[i]+=l\n if S[i]=="W":\n l+=1\nr=0\nfor j,y in enumerate(S[::-1]):\n DP[N-1-j]+=r\n if S[N-1-j]=="E":\n r+=1\nprint(min(DP))\n ', 'N=int(input())\nS=input()\nDP=[0]*N\nDP[0]=S[1:].count("E")\nfor i in range(1,N):\n if S[i]=="E":\n DP[i]=DP[i-1]-1+S[:i].count("W")\n else:\n DP[i]=DP[i-1]+S[:i].count("W")\nprint(min(DP))', 'N=int(input())\nS=input()\nDP=[0]**N\nDP[0]=S[1:].count("E")\nfor i in range(1,N):\n if S[i]=="E":\n DP[i]=DP[i-1]-1+S[:i].count("W")\n else:\n DP[i]=DP[i-1]+S[:i].count("W")\nprint(min(DP))\n', 'N=int(input())\nS=input()\nDP=[0]*N\nl=0\nfor i,x in enumerate(S):\n DP[i]+=l\n if x=="W":\n l+=1\nr=0\nfor i,y in enumerate(S[::-1]):\n DP[N-1-i]+=r\n if y=="E":\n r+=1\nprint(N-1-max(DP))\n ', 'N=int(input())\nS=input()\nDP=[0]*N\nl=0\nfor i,x in enumerate(S):\n DP[i]+=l\n if S[i]=="W":\n l+=1\nr=0\nfor j,y in enumerate(S[::-1]):\n DP[N-1-j]+=r\n if S[N-1-j]=="E":\n r+=1\nprint(min(DP))']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s100985310', 's371202988', 's594181917', 's932361115', 's869885500']
[2940.0, 8352.0, 3672.0, 15436.0, 15456.0]
[18.0, 2104.0, 18.0, 215.0, 267.0]
[203, 188, 190, 189, 196]
p03341
u193264896
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
["import sys\nfrom collections import Counter\nreadline = sys.stdin.buffer.readline\nsys.setrecursionlimit(10 ** 8)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\n\ndef main():\n N = int(readline())\n S = readline().decode('utf-8')\n L = len(S)\n A = [0]*L\n for i in range(L):\n if S[i] == 'E':\n if i == 0:\n A[i] = 1\n else:\n A[i]=A[i-1]+1\n else:\n if i == 0:\n continue\n else:\n A[i]=A[i-1]\n print(A)\n ans = INF\n for i in range(N):\n tmp = 0\n if i>0:\n tmp += i - A[i-1]\n if i<N-1:\n tmp += A[N-1]-A[i]\n ans = min(ans,tmp)\n print(ans)\n\n\n\n\n\n\nif __name__ == '__main__':\n main()\n", "import sys\nfrom collections import Counter\nreadline = sys.stdin.buffer.readline\nsys.setrecursionlimit(10 ** 8)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\n\ndef main():\n N = int(readline())\n S = readline().decode('utf-8')\n L = len(S)\n A = [0]*L\n for i in range(L):\n if S[i] == 'E':\n if i == 0:\n A[i] = 1\n else:\n A[i]=A[i-1]+1\n else:\n if i == 0:\n continue\n else:\n A[i]=A[i-1]\n ans = INF\n for i in range(N):\n tmp = 0\n if i>0:\n tmp += i - A[i-1]\n if i<N-1:\n tmp += A[N-1]-A[i]\n ans = min(ans,tmp)\n print(ans)\n\n\n\n\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s237970782', 's691729200']
[22300.0, 15524.0]
[273.0, 279.0]
[748, 735]
p03341
u215743476
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
["n = int(input())\ns = input()\n\nmin_n = s[1:].count('E')\nfor i in range(1, n):\n tmp_n += s[i-1].count('W') - s[i].count('E')\n min_n = min(tmp_n, min_n)\n\nprint(min_n)", "n = int(input())\ns = input()\n\nmin_n = s[1:].count('E')\ntmp_n = min_n\nfor i in range(1, n):\n tmp_n += s[i-1].count('W') - s[i].count('E')\n min_n = min(tmp_n, min_n)\n\nprint(min_n)"]
['Runtime Error', 'Accepted']
['s379075166', 's624589196']
[3672.0, 3700.0]
[19.0, 249.0]
[169, 183]
p03341
u218834617
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
["import sys\ninput()\nd={k:0 for k in 'AC WA TLE RE'.split()}\nfor ln in sys.stdin:\n d[ln.strip()]+=1\nfor k,v in d.items():\n print(k,'x',v)\n", "N=int(input())\nS=input()\nl=0\nans=r=S.count('E')\nfor c in S:\n if c=='E': r-=1\n ans=min(ans,l+r)\n if c=='W': l+=1\nprint(ans)\n"]
['Runtime Error', 'Accepted']
['s162385533', 's446237000']
[10092.0, 9736.0]
[29.0, 132.0]
[142, 132]
p03341
u222207357
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
["N = int(input())\nS = input()\n\nrcost = 0\nlcost = S.count('E')\nans = lcost\n\nfor i in range(N-1):\n if S[i] == 'W':\n rcost += 1\n if S[i+1] == 'E':\n lcost -= 1\n print(rcost,lcost)\n ans = min(ans, rcost+lcost)\n \nprint(ans)", "N = int(input())\nS = input()\n\nrcost = 0\nlcost = S.count('E')\nif S[0] == 'E':\n lcost -= 1\nans = lcost\n\nfor i in range(N-1):\n if S[i] == 'W':\n rcost += 1\n if S[i+1] == 'E':\n lcost -= 1\n ans = min(ans, rcost+lcost)\n \nprint(ans)"]
['Wrong Answer', 'Accepted']
['s542948079', 's620278743']
[7500.0, 3676.0]
[621.0, 210.0]
[269, 273]
p03341
u301043830
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['N = input()\nS = split(input())\n\nturns_num_list = list()\nfor i, s in enumerate(S):\n left = [S == "E" for j in S[0:j]].count()\n right = [S[j] == "W" for j in S[j+1:]].count()\n turns_num_list.append(left+right)\n\nprint(min(turns_num_list))', 'N = input()\nS = list(input())\n\nmin_num = 300000\nleft = 0\n\nfor i in range(len(S)):\n\n if i > 0:\n left += int(S[i] == "W")\n \n right = S[i+1: ].count("E")\n\n if left + right < min_num:\n min_num = left + right\n\nprint(min_num)\n', 'N = input()\nS = list(input())\n\nlength = len(S)\nmin_num = 300000\nleft = 0\nright = S.count("E")\n\nfor i in range(length):\n\n if i > 0:\n left += int(S[i - 1] == "W")\n\n if i < length:\n right -= int(S[i + 1] == "E")\n\n if left + right < min_num:\n min_num = left + right\n\nprint(min_num)\n', 'N = input()\nS = list(input())\n\nmin_num = 300000\nleft = 0\nright = S.count("E")\n\nfor i in range(len(S)):\n\n if i > 0:\n left += int(S[i - 1] == "W")\n\n right -= int(S[i + 1] == "E")\n\n if left + right < min_num:\n min_num = left + right\n\nprint(min_num)\n', 'N = input()\nS = input().split()\n\nturns_num_list = list()\nfor i, s in enumerate(S):\n left = [s == "E" for s in S[0:i]].count(True)\n right = [s == "W" for s in S[i+1:]].count(True)\n turns_num_list.append(left+right)\n\nprint(min(turns_num_list))', 'N = input()\nS = list(input())\n\nlength = len(S)\nmin_num = 300000\nleft = 0\nright = S.count("E")\n\nfor i in range(length):\n\n if i > 0:\n left += int(S[i - 1] == "W")\n\n if i < length:\n right -= int(S[i] == "E")\n\n if left + right < min_num:\n min_num = left + right\n\nprint(min_num)\n']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s149426766', 's435658373', 's513713973', 's707006033', 's758682140', 's177439939']
[3060.0, 8100.0, 5836.0, 6044.0, 3672.0, 5836.0]
[18.0, 2104.0, 301.0, 303.0, 18.0, 289.0]
[238, 232, 290, 255, 244, 286]
p03341
u314057689
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nIN = \'sample-1.in\' # sample case for local test\ndef local_test():\n try:\n from pcm.utils import set_stdin\n import sys\n if len(sys.argv) == 1:\n set_stdin(os.path.dirname(__file__) + \'/test/\' + IN)\n except:\n pass\n\n\nimport sys\nimport os\nimport time\nimport re\nfrom pydoc import help\nimport string\nimport math\nimport numpy as np\nfrom operator import itemgetter\nfrom collections import Counter\nfrom collections import deque\nfrom collections import defaultdict as dd\nimport fractions\nfrom heapq import heappop, heappush, heapify\nimport array\nfrom bisect import bisect_left, bisect_right, insort_left, insort_right\nfrom copy import deepcopy as dcopy\nimport itertools\nsys.setrecursionlimit(10**7)\nINF = 10**20\nGOSA = 1.0 / 10**10\nMOD = 10**9+7\nALPHABETS = [chr(i) for i in range(ord(\'a\'), ord(\'z\')+1)] # can also use string module\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef DP(N, M, first): return [[first] * M for n in range(N)]\ndef DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]\n\n\ndef solve():\n print(input())\n\n\nif __name__ == "__main__":\n local_test()\n solve()\n\n', 'def solve():\n N = int(input())\n S = input()\n\n AW = [0]*(N+1)\n AE = [0]*(N)\n\n wcount = 0\n ecount = 0\n for i in range(N):\n if S[i] == "W":\n wcount += 1\n else:\n ecount += 1\n AW[i] = wcount\n AE[i] = ecount\n\n MIN = 1000000\n\n for i in range(N):\n tmp = 0\n tmp += AW[i-1]\n tmp += AE[-1] - AE[i]\n MIN = min(MIN, tmp)\n print(MIN)\n\nif __name__ == "__main__":\n local_test()\n solve()', '#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nIN = \'sample-1.in\' # sample case for local test\ndef local_test():\n try:\n from pcm.utils import set_stdin\n import sys\n if len(sys.argv) == 1:\n set_stdin(os.path.dirname(__file__) + \'/test/\' + IN)\n except:\n pass\n\n\nimport sys\nimport os\nimport time\nimport re\nfrom pydoc import help\nimport string\nimport math\nimport numpy as np\nfrom operator import itemgetter\nfrom collections import Counter\nfrom collections import deque\nfrom collections import defaultdict as dd\nimport fractions\nfrom heapq import heappop, heappush, heapify\nimport array\nfrom bisect import bisect_left, bisect_right, insort_left, insort_right\nfrom copy import deepcopy as dcopy\nimport itertools\nsys.setrecursionlimit(10**7)\nINF = 10**20\nGOSA = 1.0 / 10**10\nMOD = 10**9+7\nALPHABETS = [chr(i) for i in range(ord(\'a\'), ord(\'z\')+1)] # can also use string module\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef DP(N, M, first): return [[first] * M for n in range(N)]\ndef DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]\n\n\ndef solve():\n print(input())\n\n\nif __name__ == "__main__":\n local_test()\n solve()\n\n', 'def solve():\n N = int(input())\n S = input()\n\n AW = [0]*(N+1)\n AE = [0]*(N)\n\n wcount = 0\n ecount = 0\n for i in range(N):\n if S[i] == "W":\n wcount += 1\n else:\n ecount += 1\n AW[i] = wcount\n AE[i] = ecount\n\n MIN = 1000000\n\n for i in range(N):\n tmp = 0\n tmp += AW[i-1]\n tmp += AE[-1] - AE[i]\n MIN = min(MIN, tmp)\n print(MIN)\n\nif __name__ == "__main__":\n solve()']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s454889960', 's811402980', 's891258591', 's082282647']
[23580.0, 3064.0, 14688.0, 17568.0]
[331.0, 18.0, 178.0, 187.0]
[1481, 484, 1481, 467]
p03341
u316233444
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['from itertools import accumulate\n\nN = int(input())\nS = list(input())\n\nA = [0]*(N+1) \n\n\nfor i in range(1, N+1):\n j = 0\n if S[i-1] == "W":\n j = 1\n A[i]=A[i-1] +j\n\n#print(A)\n\n\nans=N\nfor i in range(N+1):\n val = N-i +A[i] -A[N] +1\n ans = min(ans, A[i-1] +val)\n\nprint(ans)', 'from itertools import accumulate\n\nN = int(input())\nS = list(input())\n\nA = [0]*(N+1) \n\n\nfor i in range(1, N+1):\n j = 0\n if S[i-1] == "W":\n j = 1\n A[i]=A[i-1] +j\n\nprint(A)\n\n\nans=N\nfor i in range(N):\n val = N-i +A[i] -A[N]\n ans = min(ans, A[i-1] +val)\n\nif ans==0: \n ans=1\n\nprint(ans)', 'from itertools import accumulate\n\nN = int(input())\nS = list(input())\n\nA = [0]*(N+1) \n\n\nfor i in range(1, N+1):\n j = 0\n if S[i-1] == "W":\n j = 1\n A[i]=A[i-1] +j\n\n#print(A)\n\n\nans=N\nfor i in range(1, N+1):\n val = N-i +A[i] -A[N]\n ans = min(ans, A[i-1] +val)\n\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s386954036', 's833596925', 's201420205']
[17740.0, 24660.0, 17484.0]
[345.0, 354.0, 328.0]
[462, 506, 462]
p03341
u340781749
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['8\nWWWWWEEE\n', "from itertools import accumulate\n\nn = int(input())\ns = [c == 'W' for c in input()]\nl = accumulate([0] + s[:-1])\nr = accumulate([0] + [not c for c in reversed(s[1:])])\nprint(min(e + w for e, w in zip(l, reversed(list(r)))))\n"]
['Runtime Error', 'Accepted']
['s014223413', 's394904852']
[2940.0, 24560.0]
[17.0, 104.0]
[11, 223]
p03341
u373047809
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['from itertools import*\n_, s = open(0)\nb, c = [([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]]\nprint(min(x+y for x, y in zip(b, c)))', 'from itertools import*\n_, s = open(0)\nprint(min(b+c for b, c in zip(*[([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]])))', 'from itertools import*\n_, s = open(0)\nprint(min(b+c for b, c in zip(*[([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]])))', 'input();s=input();m=c=s.count("E")\nfor t in s:c-=t<"W";m=min(m,c);c+=t>"E"\nprint(m)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s385396748', 's818395809', 's939066937', 's058523230']
[5196.0, 5196.0, 5196.0, 3676.0]
[26.0, 26.0, 26.0, 151.0]
[192, 181, 181, 84]
p03341
u373274281
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['N = int(input())\nA = list(map(int, input().split()))\n\nanswer = N\nfor i in range(N-1):\n v = A[i]\n for j in range(i+1, N):\n vx = v ^ A[j]\n vp = v + A[j]\n if vx == vp:\n answer += 1\n v = vx\n else:\n break\nprint(answer)\n', "N = int(input())\nA = list(map(int, input().split()))\n\nanswer = N\nmark = 0\nfor i in range(N-1):\n #print('%d, %d, %d' % (i, mark, answer))\n if i < mark:\n answer += mark - i\n v = A[i]\n for x in range(i+1, mark+1):\n v += A[x]\n start_j = mark + 1\n else:\n v = A[i]\n start_j = i + 1\n for j in range(start_j, N):\n vx = v ^ A[j]\n vp = v + A[j]\n if vx == vp:\n answer += 1\n v = vx\n mark = j\n else:\n break\nprint(answer)", "N = int(input())\nS = input()\n\nfrom collections import defaultdict\nwc = defaultdict(int)\nec = defaultdict(int)\n\nif S[0] == 'W':\n wc[0] = 1\nfor i in range(1, N):\n wc[i] = wc[i-1]\n if S[i] == 'W':\n wc[i] += 1\n\nif S[N-1] == 'E':\n ec[N-1] = 1\nfor i in range(N-2, -1, -1):\n ec[i] = ec[i+1]\n if S[i] == 'E':\n ec[i] += 1\n\nmin_ = N\nfor i in range(1, N-1):\n v = wc[i-1] + ec[i+1]\n if v < min_:\n min_ = v\nv0 = ec[1]\nif v0 < min_:\n min_ = v0\nvn = wc[N-1]\nif vn < min_:\n min_ = vn\nprint(min_)\n"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s017490702', 's213392902', 's325009988']
[3676.0, 3784.0, 65116.0]
[19.0, 19.0, 404.0]
[281, 544, 531]
p03341
u373295322
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['input()\nss = input()\nloss = ss[1:].count("E")\nmin_loss = loss\nss_before = ss[:-1]\nss_after = ss[1:]\nfor b, a in zip(ss_before, ss_after):\n if b == "E":\n loss -=1\n else:\n loss +=1\n if a == "W":\n loss -=1\n else:\n loss +=1\n if loss < min_loss:\n min_loss = loss\nprint("{}".format(min_loss))\n ', 'input()\nss = input()\nloss = ss[1:].count("E")\nmin_loss = loss\nss_before = ss[:-1]\nss_after = ss[1:]\nfor b, a in zip(ss_before, ss_after):\n loss += b == "W"\n\tloss -= a == "E"\n if loss < min_loss:\n min_loss = loss\nprint("{}".format(min_loss))', 'input()\nss = input()\nloss = ss[1:].count("E")\nmin_loss = loss\nss_before = ss[:-1]\nss_after = ss[1:]\nfor b, a in zip(ss_before, ss_after):\n loss += b == "W"\n if a == "W":\n loss -=1\n else:\n loss +=1\n if loss < min_loss:\n min_loss = loss\nprint("{}".format(min_loss))', 'input()\nss = input()\nloss = ss[1:].count("E")\nmin_loss = loss\nss_before = ss[:-1]\nss_after = ss[1:]\nfor b, a in zip(ss_before, ss_after):\n loss += b == "W"\n loss -= a == "E"\n if loss < min_loss:\n min_loss = loss\nprint("{}".format(min_loss))']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s096687540', 's122901127', 's481211774', 's404549022']
[3916.0, 2940.0, 3956.0, 3916.0]
[120.0, 17.0, 119.0, 123.0]
[341, 253, 296, 256]
p03341
u384679440
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['N = int(input())\nS = input()\nl_w = 0\nr_e = N\nresult = l_w + r_e\nfor i in range(1, N):\n if S[i - 1] == "W":\n l_w -= 1\n if S[i] == "E":\n r_e += 1\n result = min(result, l_w + r_e)\nprint(result)', 'N = int(input())\nS = input()\nleft = 0\nright = S[1:].count(\'E\')\nresult = left + right\nfor i in range(1, N):\n if S[i-1] == "W":\n left += 1\n if S[i] == "E":\n right -= 1\n result = min(result, left + right)\nprint(result)']
['Wrong Answer', 'Accepted']
['s184889157', 's999443791']
[3672.0, 3700.0]
[219.0, 222.0]
[199, 224]
p03341
u394721319
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
["n = input()\ns = input()\n\nans = 0\ncount = 0\n\nfor i in s:\n if i == 'w':\n count += 1\n elif count:\n count -= 1\n ans += 1\n else:\n pass\n\n\nprint(ans)\n", "n = input()\ns = input()\n\nans = 0\ncount = 0\n\nfor i in s:\n print(i)\n if i == 'W':\n count += 1\n elif count:\n count -= 1\n ans += 1\n else:\n pass\n\n\nprint(ans)\n", "n = input()\ns = input()\n\nans = 0\ncount = 0\n\nfor i in s:\n if i == 'W':\n count += 1\n elif count:\n count -= 1\n ans += 1\n else:\n pass\n\n\nprint(ans)\n"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s538198058', 's964005587', 's757991340']
[3672.0, 4636.0, 3700.0]
[46.0, 235.0, 68.0]
[180, 193, 180]
p03341
u405483159
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['A, B, C, X, Y = map( int, input().split() )\n\nif A + B > 2 * C:\n m = min( X, Y )\n print( min( 2 * C * m + ( X - m ) * A + ( Y - m ) * B, \n 2 * C * m + ( X - m ) * 2 * C + ( Y - m ) * 2 * C ) )\nelse:\n print( X * A + Y * B )', 'N = int( input() )\nS = input()\n\nR = len( S.replace("W", "") ) \nL = 0\nret = L + R \nfor i in range( N ):\n if S[ i ] == "E":\n R -= 1\n ret = min( ret, L + R )\n if S[ i ] == "W":\n L += 1\n\nprint( ret )']
['Runtime Error', 'Accepted']
['s503768371', 's206225557']
[3060.0, 3700.0]
[17.0, 195.0]
[237, 204]
p03341
u415905784
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['a = int(input())\nb= [int(x) for x in input().split()]\nc = a\nfor s in range(a):\n d = b[s]\n e = b[s]\n for t in b[s+1::]:\n d = d ^ t\n e = e + t\n if d == e:\n c += 1\n else:\n break\nprint(c)', 'import functools\na = int(input())\nS = input()\nl = [0] * (a+1)\nr = [0] * (a+1)\nfor i, s in enumerate(S):\n l[i+1] = l[i] + 1 if s=="W" else l[i]\nfor i,s in enumerate(S[::-1]):\n r[i+1] = r[i] + 1 if s=="E" else r[i]\nb = [l[i]+r[a-1-i] for i in range(a)]\nc = functools.reduce(lambda x, y: min(x, y), b)\nprint(c)']
['Runtime Error', 'Accepted']
['s569726201', 's475969064']
[3668.0, 30312.0]
[19.0, 309.0]
[208, 309]
p03341
u444856278
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['from sys import stderr\nfrom functools import reduce\nfrom operator import add\ndef f(): [int(i) for i in input().split()]\ndef debug(*x): stderr.write(reduce(add,repr(x)).strip("()\',")+\'\\n\')\n\nn = int(input())\ns = list(input())\n\nlongest = {"E":(0,1),"W":(0,1)}\n# index,num of people who is E\n\ni = 0\nstate = ""\npo = 0\nwhile i < n:\n debug(i)\n if po == 0:\n debug("po==0")\n po += 1\n state = s[i]\n i += 1\n else:\n if s[i] == state:\n debug(state,"po increased")\n po += 1\n i += 1\n else:\n debug("po changed")\n if longest[state][1] < po:\n if state == "E":\n longest[state] = (i-1, po)\n else:\n longest[state] = (i-po-1,po)\n po = 0\n i += 1\n\ndebug(longest)\nif longest["E"][1] < longest["W"][1]:\n leader = longest["W"][0]\nelse:\n leader = longest["E"][0]\n\nans = 0\ndebug(leader,s)\nfor i in range(leader):\n if s[i] == "W":\n debug(i)\n ans += 1\nfor i in range(leader+1,n):\n if s[i] == "E":\n debug(i)\n ans += 1\n\nprint(ans)', 'from sys import stderr\nfrom functools import reduce\nfrom operator import add\ndef f(): return [int(i) for i in input().split()]\ndef debug(*x): stderr.write(reduce(add,repr(x)).strip("()\\\',")+\'\\n\')\n\nn = int(input())\ns = list(input())\n\nmust = [0 for i in range(n)]\n\nfor i in range(1,n):\n if s[i] == "E":\n must[0] += 1\n\nfor j in range(1,n):\n must[j] = must[j-1]\n if s[j-1] == "W":\n must[j] += 1\n if s[j] == "E":\n must[j] -= 1\nprint(min(must))']
['Wrong Answer', 'Accepted']
['s294943104', 's371030525']
[9188.0, 18280.0]
[2104.0, 232.0]
[1133, 527]
p03341
u476435125
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['n=int(input())\ns=input()\nk=n\nfor i in range(n):\n a=s[:i]\n b=s[i+1:]\n l=a.count("W")+b.count("E")\n if l<k:\n k=l\nprint(k', '\n\nn=int(input())\ns=input()\nk=0\nl=[]\nfor i in range(n):\n if s[i]=="W":\n k+=1\n l.append(k)\n#print(l)\n\n\nw=n\nfor i in range(n):\n if i==0:\n #if s[i]=="W":\n # v=n-l[n-1]+1\n #else:\n # v=n-l[n-1]\n \n v=n-1-l[n-1]+l[0]\n else:\n v=l[i-1]+n-1-i-(l[n-1]-l[i])\n\n\n if v<w:\n w=v\n if v==0:\n w=0\n break \nprint(w)']
['Runtime Error', 'Accepted']
['s582362247', 's397336464']
[2940.0, 15520.0]
[18.0, 258.0]
[137, 603]
p03341
u532502139
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
["N = int(input())\nS = input()\n_min = -1\nfor i in range(N):\n left_str = S[:i]\n right_str = S[i+1:]\n left = count('W', left_str)\n right = count('E', right_str)\n total = left + right\n if _min == -1:\n _min = total\n elif total < _min:\n _min = total\nprint(_min)\ndef count(item, str1):\n counter = 0\n for c in str1:\n if c == item:\n counter += 1\n return counter\n ", "N = int(input())\nS = input()\n_min = -1\nfor i in range(N):\n left_str = S[:i]\n right_str = S[i+1:]\n left = count('W', left_str)\n right = count('E', right_str)\n total = left + right\n if _min == -1:\n _min = total\n elif total < _min:\n _min = total\nprint(_min)\ndef count(item, str):\n counter = 0\n for c in str:\n if c == item:\n counter += 1\n return counter\n ", "N = int(input())\nS = input()\nw_count = 0\ne_count = 0\nw_counts = [0 for _ in range(N)]\ne_counts = [0 for _ in range(N)]\nfor i in range(N):\n if S[i] == 'W':\n w_count += 1\n w_counts[i] = w_count\nfor i in range(N-1, -1, -1):\n if S[i] == 'E':\n e_count += 1\n e_counts[i] = e_count\n_min = -1\nfor i in range(N):\n total = w_counts[i] + e_counts[i]\n if _min == -1:\n _min = total\n if _min > total:\n _min = total\nprint(_min-1)"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s325263929', 's723631315', 's441785955']
[3708.0, 3828.0, 17872.0]
[19.0, 19.0, 264.0]
[422, 420, 463]
p03341
u536034761
2,000
1,048,576
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
['N = int(input())\nS = input()\nE = S.count("E")\nW = 0\nans = N + 1\nfor s in S:\n if s == "E":\n E -= 1\n ans = min(W + E, ans)\n if s == "W":\n W -= 1\nprint(ans)', 'N = int(input())\nS = input()\nE = S.count("E")\nW = 0\nans = N + 1\nfor s in S:\n if s == "E":\n E -= 1\n ans = min(W + E, ans)\n if s == "W":\n W += 1\nprint(ans)']
['Wrong Answer', 'Accepted']
['s435409099', 's860502294']
[9704.0, 9696.0]
[125.0, 125.0]
[176, 176]