problem_id
stringclasses
428 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
5
816
p02675
s726137726
Wrong Answer
N=input() if N[len(N)-1]=="2" or "4" or "5" or "7" or "9": print("hon") elif N[len(N)-1]=="0" or "1" or "6" or "8": print("pon") else: print("bon")
p02657
s184231867
Wrong Answer
#!/usr/local/bin/python3 # coding: utf-8 import math ha = input() kita = ha.split(" ") a = int(kita[0]) b = int(kita[1].replace(".","")) m = a*b m = str(m) print(m[:-2])
p03043
s372240663
Accepted
import math n,k=map(int,input().split()) ans=0 cnt=0#2欠けた階数 for i in range(n): while(n-i<k): k=(k+1)//2 cnt+=1 ans+=1/(2**cnt)/n print(ans)
p03838
s463641033
Accepted
x,y = map(int,input().split()) k = abs(abs(x)-abs(y)) if x < 0 and y <= 0 or x >= 0 and y > 0: if x > y: k += 2 else: k += 1 print(k)
p02660
s490232723
Wrong Answer
import collections def prime_factorize(n): a = [] f = 2 while n % f == 0: a.append(f) n //= f f *= 2 g = 3 while g * g <= n: if n % g == 0: a.append(g) n //= g g += 2 else: g += 2 if n != 1 and n not in a: a.append(n) return a N = int(input()) fact = prime_factorize(N) print(len(fact))
p03487
s964428887
Wrong Answer
n = int(input()) dic = {} A = list(map(int, input().split())) for a in A: if a in dic: dic[a] += 1 else: dic[a] = 1 ans = 0 for key in dic: if dic[key] > key: ans += dic[key] - key else: ans += dic[key] print(ans)
p04031
s636302827
Accepted
N = int(input()) A = list(map(int, input().split())) l = sum(A) if l % N == 0: x = l // N s = 0 for a in A: s += (a - x) ** 2 print(s) else: x = l // N y = x + 1 s = 0 t = 0 for a in A: s += (a - x) ** 2 t += (a - y) ** 2 print(min(s, t))
p03150
s480318415
Wrong Answer
S = input() for i in range(len(S)): for j in range(i, len(S)): if "keyence" in S[:i] + S[j:]: print("YES") exit() print("NO")
p03835
s758178496
Accepted
k,s=map(int,input().split()) ans=0 for x in range(k+1): for y in range(k+1): if 0<=s-x-y<=k:ans+=1 print(ans)
p03264
s486840335
Wrong Answer
import math a=int(input()) print(math.floor(a)*math.ceil(a))
p02888
s833967932
Wrong Answer
import bisect N = int(input()) L = list(map(int, input().split())) L = sorted(L) ct = 0 for i in range(N-1): a = L[i] for j in range(i+1, N): b = L[j] up_bound = bisect.bisect_right(L, a+b) ct += max(0, up_bound - (j+1)) print(ct)
p03086
s354214382
Accepted
import re print(max([0]+[len(r) for r in re.findall("[ACGT]+",input())]))
p02645
s513791657
Accepted
import sys def S(): return sys.stdin.readline().rstrip() S = S() print(S[0:3])
p03433
s781356127
Wrong Answer
a=int(input()) b=int(input()) if a%500 <b: print("No") else: print("No")
p03041
s276873937
Wrong Answer
N,K = map(int,input().split()) S = input() ans = S S = S[K-1].lower() print(ans.replace(ans[K-1], S))
p03030
s922774134
Accepted
import sys from collections import defaultdict read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N = int(readline()) d = defaultdict(list) for i in range(N): s, p = readline().strip().split() p = int(p) d[s].append((p, i+1)) for city, points in sorted(d.items()): points = sorted(points, reverse=True) for _, i in points: print(i) return if __name__ == '__main__': main()
p03680
s981730787
Accepted
N = int(input()) a = [set() for _ in range(N)] for i in range(N): id = int(input()) - 1 a[id].add(i) step = -1 #already = a[1] now = a[1] next = set() for i in range(N-1): #already = already.union(now) if 0 in now: step = i+1 break for j in now: next = next.union(a[j]) now = next next = set() print(step)
p03799
s470111625
Accepted
#!/usr/bin/env python3 n, m = map(int, input().split()) if 2 * n > m: print(m // 2) else: print(n + (m - 2 * n) // 4)
p03359
s448669230
Wrong Answer
def main(): a, b = map(int, input().split()) cnt = 0 for i in range(1, a+1): for j in range(1, b+1): if i == j: cnt += 1 print(cnt) if __name__ == "__main__": main()
p03000
s862158560
Accepted
n, x = map(int, input().split()) l = list(map(int, input().split())) ans = 1 d = 0 for i in l: d = d + i if d <= x: ans += 1 print(ans)
p02953
s242988345
Accepted
N = int(input()) H = list(map(int, input().split())) H.reverse() ans = True for i in range(len(H) - 1): if H[i] + 1 == H[i + 1]: H[i + 1] -= 1 if H[i] + 1 < H[i + 1]: ans = False break if ans: print("Yes") else: print("No")
p04034
s357717202
Wrong Answer
import sys input = sys.stdin.readline n, m = map(int, input().split()) ans = [1] * n check = [False] * n check[0] = True for i in range(m): x, y = map(int, input().split()) if check[x - 1]: ans[y - 1] += 1 ans[x - 1] -= 1 check[y - 1] = True if ans[x - 1] == 0: check[x - 1] = False print(check.count(True))
p02664
s902716927
Accepted
t = input() print(t.replace("?","D"))
p02723
s670419369
Accepted
# ABC160 A def main(): s = input() if s[2] == s[3] and s[4] == s[5]: print("Yes") else: print("No") if __name__ == '__main__': main()
p02731
s755019934
Accepted
print((int(input())/3)**3)
p03417
s000960887
Wrong Answer
n, m = map(int, input().split()) if n == 1 or m == 1: ans = max(n, m) - 2 else: ans = n * m - 2 * n - 2 * m + 4 print(ans) print(ans)
p03075
s006750836
Accepted
a = int(input()) b = int(input()) c = int(input()) d = int(input()) e = int(input()) k = int(input()) if e - a > k: print(":(") else: print("Yay!")
p03250
s132310749
Accepted
import itertools S = input().split() m = 0 for n in itertools.permutations(range(3)): m = max(m, eval(S[n[0]]+"+"+S[n[1]]+S[n[2]])) print(m)
p02688
s922796379
Accepted
n, k = [int(x) for x in input().split()] l = [] for i in range(k): d = input() l.extend(list(map(int, input().split()))) s = set(l) print(n -len(s))
p03592
s906795366
Accepted
N, M, K = map(int, input().split()) for i in range(N): for j in range(M): s = i * j + (N-i) * (M-j) if s == K or N*M - s == K: print("Yes") exit() print("No")
p02624
s032187248
Accepted
def solve(): ans = 0 N = int(input()) for i in range(1,N+1): for j in range(1,N//i+1): ans += i*j return ans print(solve())
p02678
s676902937
Accepted
import collections N, M = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): a, b = map(int, input().split()) G[b-1].append(a-1) G[a-1].append(b-1) queue = collections.deque([0]) visited = [0]*N visited[0] = 1 while queue: x = queue.popleft() for i in G[x]: if visited[i] == 0: visited[i] = x + 1 queue.append(i) print("Yes") print(*visited[1:], sep="\n")
p03208
s370228068
Accepted
def resolve(): n, k = map(int, input().split()) H = [] for _ in range(n): H.append(int(input())) H_sort = list(sorted(H, reverse=True)) ans = 10**9 for i in range(n-k+1): ans = min(ans, H_sort[i]-H_sort[i+k-1]) print(ans) resolve()
p03329
s829672802
Accepted
#!/usr/bin/env python # coding: utf-8 # In[1]: N = int(input()) # In[12]: ans = N for i in range(N+1): x = 0 y = i while y: x += y%6 y //= 6 y = N-i while y: x += y%9 y //= 9 ans = min(x, ans) print(ans) # In[ ]:
p03994
s530236248
Accepted
from sys import stdin import string alpha = string.ascii_lowercase nokori = [26-i for i in range(26)];nokori[0] = 0 s = stdin.readline().rstrip() k = int(stdin.readline().rstrip()) sin = "" for i in s: if nokori[alpha.index(i)] <= k: k -= nokori[alpha.index(i)] sin += "a" else: sin += i q = alpha.index(sin[-1]) q += k print(sin[:-1]+alpha[q%26])
p02548
s309565489
Accepted
n = int(input()) num = 0 for i in range(1,n): num += (n-1)//i print(num)
p02818
s569035460
Accepted
def main(): A, B, K = map(int, input().split()) if K < A: print(A - K, B) elif K < A + B : print(0, B - (K - A)) else: print(0, 0) if __name__ == '__main__': main()
p02594
s939921452
Accepted
X = int(input()) if(X >= 30): print('Yes') else: print('No')
p03329
s597696056
Wrong Answer
n=int(input()) a=[0]*(n+1) six=0 nine=0 for i in range(1,n+1): if i>6**(six+1): six+=1 if i>9**(nine+1): nine+=1 a[i]=min(a[i-1],a[i-6**six],a[i-9**nine])+1 print(a[n])
p02791
s515985326
Accepted
N = int(input()) P = list(map(int, input().split())) count = 1 mini = P[0] for i in range(1, N): mini = min(mini, P[i]) if P[i] <= mini: count += 1 print(count)
p03041
s348123925
Accepted
a,b = map(int,input().split()) s=input() for i in range(len(s)): if i+1==b: print(s[i].lower(),end='') continue print(s[i],end='')
p03773
s865875944
Wrong Answer
A, B = map(int, input().split()) print(A+B)
p04020
s216906158
Accepted
N = int(input()) l = [] for i in range(N): l.append(int(input())) ans = 0 for i in range(N): ans += l[i] // 2 l[i] = l[i] % 2 if (i<N-1) and (l[i]==1) and (l[i+1]>0): ans += 1 l[i] = 0 l[i+1] -= 1 print(ans)
p03013
s779322373
Accepted
n,m = map(int,input().split()) a = set([int(input()) for i in range(m)]) inf = 1000000007 dp = [0] * (n+1) dp[0] = 1 if 1 not in a: dp[1] = 1 else: dp[1] = 0 for i in range(2,n+1): if i in a: continue dp[i] = dp[i-1] + dp[i-2] dp[i] %= inf print(dp[n])
p02881
s964497990
Accepted
n = int(input()) from math import sqrt root = int(sqrt(n)) for i in range(root,0,-1): if n%i == 0: ans = i+(n/i)-2 break print(int(ans))
p02577
s100873919
Accepted
N = list(map(int,list(input()))) if sum(N) % 9 == 0: print('Yes') else: print('No')
p03067
s487760278
Accepted
a, b, c = map(int, input().split()) if a >= c >= b or a <= c <= b: print("Yes") else: print("No")
p02548
s724756928
Wrong Answer
n = int(input()) cnt = 0 for a in range(n): for b in range(n): for c in range(n): if a * b + c == n: cnt += 1 print(cnt)
p02777
s485482020
Wrong Answer
s, t = map(str, input().split()) a, b = map(int, input().split()) n = input() if n == a: print(a-1, b) else: print(a, b-1)
p02687
s743088806
Wrong Answer
# atCoder: # 1e8: 546 ms # 1e7: # # #import sys #import platform #print(sys.version) #print(platform.architecture()) n = int(1e7) p = 1 x = (1 << 32) - 1 #print(4294967295 == x) #print(100000000 == n) for i in range(1, n + 1): p += i p %= x # should be 988623866 print(p)
p02689
s953412968
Wrong Answer
N,M = map(int,input().split()) H = list(map(int,input().split())) A_B = [list(map(int, input().split())) for _ in range(M)] H_list = [] ans = [] for t in A_B: T = [] T1 = T.append(H[t[0]-1]) T2 = T.append(H[t[1]-1]) H_list.append(T) if T[0] == T[1]: continue elif T[0] > T[1]: ans.append(T[0]) else: ans.append(T[1]) H_list2 = list(set(sum(H_list,[]))) H_last = list(set(H_list2)^set(H)) if H_last != []: ans.append(H_last[0]) else: pass print(len(set(ans)))
p03632
s339205749
Accepted
a, b, c, d = map(int, input().split()) if a <= c and c <= b and b <= d: print(b-c) elif c <= a and a <= d and d <= b: print(d-a) elif a <= c and d <= b: print(d-c) elif c <= a and b <= d: print(b-a) else: print(0)
p02780
s812840885
Accepted
n, k = map(int, input().split()) P = list(map(int, input().split())) import numpy as np max_v = np.sum(P[:k]) #print(max_v) j = 0 cum = 0 temp_max = max_v for i in range(k, n): temp_max += P[i] temp_max -= P[i-k] if temp_max>max_v: max_v = temp_max j=i-k ans = (max_v+k)/2 print(ans) #print(max_v)
p03796
s470926403
Wrong Answer
a=int(input()) import math x=math.factorial(a) print(x//(10**9+7))
p02831
s499315479
Accepted
A,B = map(int,input().rstrip().split()) n = m = 1 flg = 0 an = A bm = B while flg ==0: an = A * n bm = B* m if an == bm : flg = 1 res = an elif an < bm: n += 1 else : m += 1 print(an)
p03827
s612600846
Wrong Answer
N = int(input()) S = input() ans = 0 highest = 0 for i in S: if i == "I": ans += 1 else: ans -= 1 print(ans) if highest <= ans: highest = ans print(highest)
p02897
s733716832
Accepted
N=int(input()) if N%2==1: print((int(N/2)+1)/N) else: print(1/2)
p03951
s715371145
Accepted
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline n = int(input()) s = input() #sys.stdin.readlineは最後が改行 t = input() #sys.stdin.readlineは最後が改行 ans = 2*n for i in range(n): if s[i:n] == t[:(n-i)]: print(2*n-(n-i)) exit() print(2*n)
p02691
s517024564
Accepted
from collections import Counter def main(): n = int(input()) a = list(map(int, input().split())) b = Counter([e+i+1 for i,e in enumerate(a)]) c = Counter([i+1-e for i,e in enumerate(a) if i+1-e > 1]) ans = 0 for i in c: ans += b[i] * c[i] print(ans) if __name__ == '__main__': main()
p03672
s661910314
Accepted
s = input() s = s[0:-1] if len(s) % 2 != 0: s = s[:-1] for i in reversed(range(0, len(s)+2, 2)): half = i//2 if s[:half] == s[half:]: print(len(s)) break s = s[:-2]
p03069
s073896000
Wrong Answer
N = int(input()) S = str(input()) S = list(S) c = 0 for i in range(N): if S[i] == '#': for j in range(N-i): if S[i+j] == '.': c += 1 break print(c)
p03075
s130762904
Wrong Answer
a = [int(input()) for i in range(5)] k = int(input()) for i in range(4): if a[i] - a[0] > k: print(':(') exit() print('Yay!')
p02756
s191653816
Wrong Answer
s = input() q = int(input()) a = [s] for i in range(q): so = input() if so == '1': a[0], a[-1] = a[-1], a[0] else: d, f, c = so.split() if f == '1': a.insert(0, c) else: a.insert(-1, c) print(''.join(a))
p03852
s686142385
Wrong Answer
c=raw_input() if c=="a,e,i,o,u": print "vowel" else: print "consonant"
p03486
s074398320
Wrong Answer
s = input() t = input() s = sorted(s) t = sorted(t) l = min([len(s),len(t)]) for i in range(l): dec = sorted(s[i] + t[-(i+1)]) if (dec[0] == t[-(i+1)]) & (dec[0] != s[i]): print("No") break elif (i == l-1): if (len(s) >= len(t)): print("No") else: print("Yes")
p02789
s274071734
Wrong Answer
N, M = map(int, input().split()) if N > M: print('Yes') else: print('No')
p03211
s560133868
Wrong Answer
n = int(input()) sn = str(n) n3 = 0 minx = 0 temp = 753 sav = 0 for i in range(len(str(n//100))): n3 = int(sn[i:i+3]) minx = abs(753-n3) if temp > minx: temp = minx sav = n3 print(sav)
p03711
s924391925
Accepted
x,y = map(int,input().split()) list1 =[1,3,5,7,8,10,12] list2 =[4,6,9,11] if x == 2 or y == 2: print("No") elif x in list1 and y in list1: print("Yes") elif x in list2 and y in list2: print("Yes") else: print("No")
p02989
s407181543
Wrong Answer
N = int(input()) p = list(map(int, input().split())) q = sorted(p) cor = q[int(N/2)] - q[int(N/2 - 1)] if cor == 0: print(0) else: print(cor + 1)
p02755
s325960732
Accepted
import math A,B = map(int,input().split()) if (A+1)/0.08 > B/0.1 and (B+1)/0.1 > A/0.08: print(max(math.ceil(A/0.08),math.ceil(B/0.1))) else: print(-1)
p03438
s842685983
Accepted
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) cnt = [0, 0] for ea, eb in zip(a, b): if ea > eb: cnt[1] += ea - eb else: cnt[0] += (eb - ea) // 2 if cnt[0] >= cnt[1]: ans = "Yes" else: ans = "No" print(ans)
p02615
s028452992
Wrong Answer
N = int(input()) A = sorted(list(map(int,input().split())),reverse = True) ans = A[0] for i in range(2,N): I = (i+2)//2 ans += A[I] print(ans)
p02665
s146459427
Accepted
N = int(input()) A = list(map(int, input().split())) sa = sum(A) last = A[-1] count = last root = 1 for i in range(N): sa -= A[i] if root <= A[i]: print(-1) break elif root-A[i] > sa: root = sa + A[i] count+=root root = (root-A[i])*2 else: if count == 0 or root < last: count = -1 print(count)
p02731
s763565451
Wrong Answer
def maxvolume( s ): # finding length length = int(s / 3) s -= length # finding breadth breadth = s / 2 # finding height height = s - breadth return int(length * breadth * height) # Driven Program s = 8 print( maxvolume(int(input())) )
p03243
s844579382
Wrong Answer
N = int(input()) for i in range(8): if 111 * i < N and N <= 111 * (i + 1): print(111 * (i + 1))
p04030
s016796165
Accepted
s = input() ans = [] for i in s: if i == "B": try: ans.pop() except: pass else: ans.append(i) print("".join(ans))
p04029
s337395664
Accepted
n = int(input()) x = (n * (n + 1)) // 2 #dsafasdfasdfasdfsadfsadfasldfjasdklfasdkfjhasdkjfhaskldjfhsakjdfhsalkdfhasdkfjhsad print(x)
p03043
s024322547
Accepted
N, K = map(int, input().split()) ans = 0 for i in range(1, N+1): c = 0 while i<K: i *= 2 c += 1 ans += 1/N/pow(2, c) print(ans)
p03243
s014369973
Accepted
import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 def input(): return sys.stdin.readline().rstrip() def main(): N=int(input()) print(-(-N//111)*111) if __name__ == '__main__': main()
p03695
s349255430
Accepted
n = int(input()) a = list(map(int,input().split())) color = [0,0,0,0,0,0,0,0,0] if min(a) >= 3200: print(1,len(a)) quit() for ai in a: if ai <= 3199: rnk = ai // 400 color[rnk] += 1 else: color[8] += 1 min_color = 0 for i in range(8): if color[i] > 0: min_color += 1 max_color = min_color + color[8] print(min_color,max_color)
p04020
s721709321
Accepted
#!/usr/bin python3 # -*- coding: utf-8 -*- def main(): N = int(input()) ret = 0 pv = 0 for _ in range(N): nw = int(input()) pa = min(pv, nw) ret += pa pv = nw - pa ret += pv//2 pv = pv%2 print(ret) if __name__ == '__main__': main()
p02582
s144275699
Accepted
s = input() if s == 'RRR': print(3) elif s[:2] == "RR" or s[1:] == "RR": print(2) elif 'R' in s: print(1) else: print(0)
p03680
s947479886
Accepted
N = int(input()) a = [] for i in range(N): a.append(int(input())) history = set() now = 0 cnt = 0 while(True): if now in history: cnt = -1 break else: cnt += 1 history.add(now) now = a[now]-1 if now == 1: break print(cnt)
p02708
s262827313
Accepted
n,k=map(int,input().split()) s=0 for i in range(k,n+2): s+=i*(n-i+1)+1 print(s%1000000007)
p03339
s388885908
Accepted
from itertools import accumulate N = int(input()) S = input() turn_E = [0] + list(accumulate([s=="W" for s in S[:-1]])) turn_W = list(reversed(list(accumulate([s=="E" for s in S[:0:-1]])))) + [0] ans = [e+w for e, w in zip(turn_E, turn_W)] print(min(ans))
p03219
s048834589
Accepted
x, y = map(int, input().split()) print(x + y//2)
p03131
s394106902
Accepted
K, A, B = map(int, input().split()) ans = 0 if B - A <= 2: print(K + 1) else: K -= A - 1 ans += (K//2) * (B - A) + A ans += K % 2 print(ans)
p02684
s928914063
Accepted
N,K = map(int,input().split()) A = list(map(lambda x: int(x)-1,input().split())) o = [0] * 63 def bi(x): i = 0 while x != 0: o[i] = x%2 x //= 2 i += 1 bi(K) n = 0 for i in range(63): if o[i]: n = A[n] A = [A[A[x]] for x in range(N)] print(n+1)
p02547
s518351150
Accepted
N = int(input()) cnt = 0 for i in range(N): a, b = map(int, input().split()) if a == b: cnt += 1 else: cnt = 0 if cnt == 3: print('Yes') exit() print('No')
p03645
s719620375
Wrong Answer
n,m=map(int,input().split()) A=[] B=[] for i in range(m): a,b=map(int,input().split()) if a==1: A.append(b) if b in B: print("POSSIBLE") break if b==n: B.append(a) if a in A: print("POSSLBLE") break else: print("IMPOSSIBLE")
p02600
s673593597
Accepted
x = int(input()) if 400 <= x <= 599 : ans = '8' elif 600 <= x <= 799 : ans = '7' elif 800 <= x <= 999 : ans = '6' elif 1000 <= x <= 1199 : ans = '5' elif 1200 <= x <= 1399 : ans = '4' elif 1400 <= x <= 1599 : ans = '3' elif 1600 <= x <= 1799 : ans = '2' else : ans = '1' print(ans)
p02835
s771857006
Wrong Answer
a, b, c = map(int, input().split()) if a + b + c > 22: print("bust") else: print("win")
p03803
s204615575
Accepted
#ABC054.A A,B = map(int,input().split()) if A ==1: if A<B: print('Alice') else: print('Draw') elif A>B and B!=1: print('Alice') elif A==B: print('Draw') else: print('Bob')
p02683
s534372815
Accepted
import sys input=lambda: sys.stdin.readline().rstrip() n,m,x=map(int,input().split()) A=[[int(i) for i in input().split()] for _ in range(n)] ans=float("inf") for i in range(2**n): B=[0]*(m+1) for j in range(n): if i&(1<<j): for k in range(m+1): B[k]+=A[j][k] if min(B[1:])>=x: ans=min(ans,B[0]) print(-1 if ans==float("inf") else ans)
p02972
s025550944
Accepted
N = int(input()) A = list(map(int, input().split())) B = [0] * N ans = [] for i in range(N, 0, -1): cnt = sum(B[(i-1)::i])%2 B[i-1] = A[i-1] ^ cnt if B[i-1]: ans.append(i) print(sum(B)) print(*ans)
p02696
s705860519
Accepted
A,B,N=map(int,input().split()) Z=0 if N<B: Z=(A*N)//B else: Z=(A*(B-1))//B print(Z)
p03910
s936823326
Wrong Answer
n = int(input()) for i in range(n+1): tmp = n now = i*(i+1)//2 tmp -= now if tmp <= i: break for j in range(1,i): print(j) print(n-(i-1)*i//2)
p03795
s939859559
Accepted
n=int(input()) a = 800*n b = 200*(n//15) print(a-b)
p03351
s190901493
Wrong Answer
a,b,c,d = map(int,input().split()) print('Yes') if b-a <= d and c-b <= d else print('No')
p02623
s637645147
Wrong Answer
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) sumnum = 0 count = 0 B.reverse() AB = A + B while 1: if len(AB) == 0: break elif AB[0] < AB[-1]: tmp = sumnum + AB[0] AB.pop(0) else: tmp = sumnum + AB[-1] AB.pop(-1) if tmp > K: break else: sumnum = tmp count = count + 1 print(count)