problem_id
stringclasses
428 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
5
816
p03639
s247649802
Wrong Answer
n = int(input()) A = list(map(int, input().split())) num_4 = 0 num_2 = 0 num_odd = 0 for i in A: if i % 4 == 0: num_4 += 1 elif i % 2 == 0: num_2 += 1 num_odd = n - num_2 - num_4 if n - num_4*2 == num_2 or n - num_4 * 2 == 1 or n - num_4 * 2 == 0: print("Yes") else: print("No")
p02730
s939058933
Accepted
s=input() n=len(s) if s==s[::-1] and s[:(n-1)//2]==s[:(n-1)//2][::-1] and s[(n+3)//2-1::]==s[(n+3)//2-1::][::-1]: print("Yes") else: print("No")
p02729
s408706685
Accepted
N,M = map(int,input().split()) if N != 0 and M != 0: A = N*(N-1)+M*(M-1) elif N == 0: A = M*(M-1) elif M == 0: A = N*(N-1) print(int(A/2))
p03962
s067900317
Accepted
a, b, c = map(int,input().split()) print(len({a,b,c}))
p03131
s774031161
Wrong Answer
k, a, b = map(int, input().split()) if k > a+1 and b > a: x = 1 + k t = (k-a+1)//2 y = t * (b-a) + (k-t*2) + 1 print(y) exit() else: z = 1 + k print(z)
p03524
s114059727
Accepted
import sys from collections import Counter readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): S = input() count = Counter(S) count['a'] += 0 count['b'] += 0 count['c'] += 0 if max(count.values()) - min(count.values()) <= 1: print('YES') else: print('NO') if __name__ == '__main__': main()
p02624
s620228943
Accepted
N = int(input()) ans = 0 for i in range(1, N+1): n = N // i ans += n*(2*i + (n-1)*i)//2 print(ans)
p03815
s882634565
Accepted
x = int(input()) print(x // 11 * 2 + (x % 11 > 6) + (x % 11 > 0))
p02779
s572050510
Accepted
N = int(input()) an = list(map(int, input().split())) set_an = set(an) print("YES" if len(set_an) == N else "NO")
p02854
s894107156
Accepted
import sys from itertools import accumulate input = sys.stdin.readline def main(): N = int(input()) A = list(map(int, input().split())) cumsum_A = list(accumulate(A)) sum_A = sum(A) ans = float("inf") for i in range(N - 1): # cost = abs((sum_A - cumsum_A[i]) - cumsum_A[i]) cost = abs(sum_A - 2 * cumsum_A[i]) if cost < ans: ans = cost print(ans) if __name__ == "__main__": main()
p03317
s261084570
Accepted
#import sys #import numpy as np import math #from fractions import Fraction import itertools from collections import deque from collections import Counter #import heapq #from fractions import gcd #input=sys.stdin.readline import bisect n,k=map(int,input().split()) a=list(map(int,input().split())) ix=a.index(1) i=math.ceil((n-k)/(k-1))+1 print(i)
p02933
s126516927
Accepted
print('red'if int(input())<3200 else input())
p02582
s946216499
Wrong Answer
s=input() if s == 'RRR': print(3) elif s.count('RR') == 1: print(2) elif s.count('R') > 1: print(1) else: print(0)
p04045
s756752026
Accepted
N, K = map(int, input().split()) hate = set(map(str, input().split())) Nos = {str(i) for i in range(10)} while not set(list(str(N))) & hate == set(): N += 1 print(N)
p02631
s021554491
Accepted
N = int(input()) scarfs = list(map(int, input().split())) xor_sum = scarfs[0] for i in range(1, N): xor_sum = xor_sum ^ scarfs[i] for scarf in scarfs: print(xor_sum ^ scarf, end=' ')
p03627
s595224366
Accepted
n = int(input()) A = list(map(int, input().split())) from collections import Counter # C = reversed(sorted(Counter(A))) C = Counter(A) x = None # for k, v in C.items(): for k, v in reversed(sorted(C.items())): if v >= 4: if x: print(k * x) exit() else: print(k ** 2) exit() elif v >= 2: if x: print(k * x) exit() else: x = k else: print(0)
p02693
s486934971
Wrong Answer
K = int(input()) A,B = map(int,input().split()) if B-A>=K-1: print("OK") elif A%K > B%K: print("OK") else: print("NG")
p02677
s557775608
Accepted
import math a,b,h,m = map(float, input().split()) rot = 5.5 * (60.0*h + m) ang = rot%360 rad = ang * math.pi / 180 cal = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad) ans = math.sqrt(cal) print(ans)
p03720
s659767693
Accepted
listanm = [] n,m = map(int,input().split()) for x in range(n): listanm.append(0) for c in range(m): a,b = map(int,input().split()) listanm[a-1]+=1 listanm[b-1]+=1 for g in listanm: print (g)
p04011
s880952308
Accepted
n=int(input()) k=int(input()) x=int(input()) y=int(input()) if k>=n: print(n*x) else: print(k*x+(n-k)*y)
p02910
s490004334
Accepted
s = list(input()) odd = ['R', 'U', 'D'] even = ['L', 'U', 'D'] for i in range(len(s)): if i % 2 == 0: if s[i] not in odd: print('No') exit() else: if s[i] not in even: print('No') exit() print('Yes')
p02640
s979512049
Wrong Answer
x, y = map(int, input().split()) b = y - 2 * x a = x - b ans = "Yes" if (a >= 0 and b >= 0) else "No" print(ans)
p03479
s483464203
Wrong Answer
import math x,y=map(int,input().split()) print(int(math.log2(y//x))+1)
p03131
s800467866
Accepted
k, a, b = map(int, input().split()) if b - a <= 2: print(k + 1) else: k = k - (a - 1) cnt = a ab = k // 2 cnt += (b - a) * ab + k % 2 print(cnt)
p03548
s710376755
Accepted
X,Y,Z = map(int,input().split()) print((X-Z)//(Y+Z))
p03478
s070012965
Accepted
N,A,B = (int(X) for X in input().split()) Count = 0 for T in range(1,N+1): if A<=sum(int(X) for X in list(str(T)))<=B: Count += T print(Count)
p02693
s574609178
Accepted
def solve(k, a, b): for x in range(a, b+1): if x % k == 0: return True return False if __name__ == "__main__": k = int(input()) a, b = map(int, input().split()) print("OK" if solve(k, a, b) else "NG")
p02572
s635744382
Wrong Answer
n = int(input()) a = list(map(int,input().split())) s = 0 for i in range(n): s += a[i] #sはaの和 t = 0 for i in range(n): t += a[i]**2 #tはaの2乗和 ans = int(((s**2 - t)/2) % (10**9 + 7)) print(ans)
p03331
s549117753
Wrong Answer
a = int() b = int() wa_list = [] n = int(input()) for a in range(n+1): if b == n - a: wa_list.append(sum(map(int, list(str(a)))) + sum(map(int, list(str(b))))) print(min(wa_list))
p03360
s109969201
Accepted
a, b, c = map(int, input().split()) k = int(input()) m = max(a, b, c) for i in range(k): m *= 2 print(sum([a, b, c]) - max(a, b, c) + m)
p03493
s650813779
Accepted
S=input() print(S.count("1"))
p02713
s865151408
Wrong Answer
import math num = int(input()) ans = 0 for a in range(num): for b in range(num): for c in range(num): ans += math.gcd(math.gcd(a,b), c) print(ans)
p03493
s764666349
Wrong Answer
s=list(input()) result=0 for i in s: if i=='0': result+=1 print(result)
p03607
s876607458
Wrong Answer
N = int(input()) A = [int(input()) for _ in range(N)] A=sorted(A) ans=0 cnt=1 tmp=A[0] for i in range(1,N): if A[i]==tmp: cnt+=1 elif A[i]!=tmp and cnt%2!=0: cnt=1 ans+=1 tmp=A[i] if cnt%2 ==1: ans+=1 print(ans)
p03607
s859630673
Wrong Answer
n = int(input()) d = {} for i in range(n): a = int(input()) if a in d: d[a] ^= 1 print(sum(d.values()))
p02819
s630976009
Wrong Answer
from math import sqrt X = int(input()) flag = 0 ans = X while(flag == 0): for i in range(int(sqrt(ans))): if(ans % (i + 2) == 0): ans += 1 flag = 0 break flag = 1 print(ans)
p04029
s885400213
Accepted
n = int(input()) print(sum([i for i in range(1, n+1)]))
p02624
s333990985
Accepted
import math n = int(input()) e = [0 for _ in range(n)] for i in range(n): for j in range(i,n,i+1): e[j] += 1 ans = 0 for i in range(n): ans += (i+1) * e[i] print(ans)
p03545
s707853023
Accepted
S = input() str_list = list(S) p = len(S) - 1 for i in range(2 ** p): ans = int(str_list[0]) sentence = S[0] for j in range(p): if (i >> j) & 1: ans += int(str_list[j+1]) sentence += "+"+S[j+1] else: ans -= int(S[j+1]) sentence += "-"+S[j+1] if ans ==7: print(sentence+"=7") break
p03035
s133301294
Wrong Answer
A, B = map(int,input().split()) if A <= 5: print(0) elif 6 <= A <= 12: print(B/2) else: print(B)
p02802
s376032409
Accepted
N, M = map(int, input().split()) ac = 0 wa = 0 arr = [0] * N if M == 0: print("0 0") exit() for i in range(M): p, s = list(input().split()) p = int(p) if arr[p-1] != "AC": if s == "AC": wa += arr[p-1] arr[p-1] = "AC" ac += 1 else: arr[p-1] += 1 print(ac, wa)
p03127
s535840759
Wrong Answer
n=int(input()) a=list(map(int,input().split())) m1=min(a) a.sort(reverse=True) for i in range(n-1): for j in range(i,n): if m1==1: break else: count=a[i]%a[j] if m1>count and count!=0: m1=count print(m1)
p03095
s428918806
Wrong Answer
import itertools N = int(input()) S = list(input()) a = [] for i in range(1, N): for v in itertools.combinations(S, i): c = set(v) if len(c) == len(v): a.append(v) print(len(a))
p02615
s132104376
Accepted
N = int(input()) A = list(map(int,input().split())) A.sort(reverse=True) ans = 0 for i in range(N-1): if i == 0: ans += A[i] else: ans += A[1+(i-1)//2] print(ans)
p02639
s132334115
Accepted
xs = list(map(int, input().split())) print(xs.index(0)+1)
p03680
s401357262
Accepted
import sys def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def main(): N = ii() a = [ii() for i in range(N)] now = 0 for i in range(N+1): if now == 1: print(i) return now = a[now]-1 print(-1) if __name__ == '__main__': main()
p03087
s418587919
Accepted
N,Q = map(int,input().split()) S = input() AC = [0]*N cnt = 0 for i in range(1,N): if S[i-1:i+1] == 'AC': cnt += 1 AC[i] = cnt for i in range(Q): l,r = map(int,input().split()) print(AC[r-1]-AC[l-1])
p02712
s945029754
Wrong Answer
N = int(input()) ans = 0 for i in range(N): if i%3 != 0 and i%5 != 0: ans += i print(ans)
p02676
s294210037
Accepted
K = int(input()) S = input() if len(S) <= K: print(S) else: print(S[:K] + '...')
p02639
s723102414
Accepted
def main(): X = [int(x) for x in input().split()] for i,x in enumerate(X): if x == 0: print(i+1) return if __name__ == '__main__': main()
p02546
s034749739
Accepted
S = input() ans = S if S[-1] == 's': ans += 'es' else: ans += 's' print(ans)
p02595
s397311154
Accepted
N,D = map(int,input().split()) L = [list(map(int,(input().split()))) for _ in range(N)] ans = 0 for i in range(N): d = (L[i][0]**2 + L[i][1]**2) ** 0.5 if d <= D: ans += 1 print(ans)
p04030
s555136977
Wrong Answer
arr = input() if not 'B' in arr: print(arr) else: arr = ''.join(reversed(arr)) print(''.join(reversed(arr[:arr.index('B')])))
p02730
s596076013
Accepted
# -*- coding: utf-8 -*- # 入力 S = input() # 演算 N = len(S) if S[0:int((N-1)/2)] == S[int((N+3)/2)-1:N]: print("Yes") else: print("No")
p02724
s953348643
Accepted
num = (int(input())) ans1 = 0 ans2 = 0 while num >= 500: ans1 += 1 num -= 500 while num >= 5: ans2 += 1 num -= 5 print((ans1*1000)+(ans2*5))
p02959
s395849964
Accepted
N = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.reverse() b.reverse() ans = 0 capacity = 0 for i in range(N): ans += min(b[i] + capacity, a[i]) capacity = max(b[i] - max(a[i] - capacity, 0), 0) ans += min(a[-1], capacity) print(ans)
p03720
s630132734
Accepted
n,m=map(int,input().split()) ans=[0 for i in range(n)] for i in range(m): a,b=map(int,input().split()) a,b=a-1,b-1 ans[a]+=1 ans[b]+=1 for i in range(n): print(ans[i])
p02732
s595360918
Wrong Answer
N_ = int(input()) A_ = list(map(int,input().split())) #A_.remove(1) #print(A_) def xC(num): return (num * (num - 1)) //2 def Re_(reA,t): Dup = [] num = 0 #print(reA) for i in range(len(reA)): if Dup.count(reA[i]) == 0: Dup.append(reA[i]) else: pass for i in range(len(Dup)): num += xC(reA.count(Dup[i])) return num
p02682
s453471449
Wrong Answer
A, B, C, K = map(int,input().split()) if K <= A: print(K) elif K <= A+B: print(A) else: print(A + C*-1*(K-A-B))
p02602
s908566455
Accepted
N,K=map(int,input().split()) A = list(map(int,input().split())) s0=A[0] for i in range(N-K): s1=A[K+i] if s1>s0: print('Yes') else: print('No') s0=A[i+1]
p03544
s383083028
Accepted
n = int(input()) if n == 0: print(2) elif n == 1: print(1) else: l0 = 2 l1 = 1 result = 0 for i in range(n-1): result = l0+l1 l0 = l1 l1 = result print(result)
p02607
s603937873
Accepted
N=int(input()) a=list(map(int, input().split())) ans = 0 for i in range(N): if i%2==0 and a[i]%2==1: ans += 1 print(ans)
p03327
s826418353
Accepted
n=int(input()) print('ABC' if n<=999 else 'ABD')
p04019
s377033725
Accepted
s = input() s = list(s) sowth = s.count('S') if 'S' in s else 0 east = s.count('E') if 'E' in s else 0 north = s.count('N') if 'N' in s else 0 west = s.count('W') if 'W' in s else 0 if (west != 0 and east != 0 and sowth == 0 and north == 0) or\ (sowth != 0 and north != 0 and west == 0 and east == 0) or\ (sowth != 0 and north != 0 and west != 0 and east != 0): print('Yes') else: print('No')
p03673
s086097916
Accepted
import math from collections import defaultdict,deque from itertools import permutations ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) ips=lambda:input().split() """========main code===============""" t=1 #t=ii() for _ in range(t): n=ii() a=ll() i=n-1; while(i>-1): print(a[i],end=" ") i-=2 for i in range(n%2,n,2): print(a[i],end=" ")
p03986
s765791645
Wrong Answer
x = input() ans, count0, count1 = len(x), 0, 0 for i in x: if i == 'S' and count1 == 0: count0 += 1 elif i == 'T' and count0 > 0: count1 += 1 else: ans -= 2*min(count0, count1) if i == 'S': count0, count1 = 1, 0 else: count0, count1 = 0, 0 ans -= 2*min(count0, count1) print(ans)
p02832
s943274101
Accepted
N = int(input()) A = list(map(int, input().split())) i = 0 for a in A: if i + 1 == a: i += 1 if i == 0: print(-1) else: print(N - i)
p03997
s802302235
Accepted
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h//2)
p04005
s247324306
Accepted
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() def resolve(): a, b, c = map(int, input().split()) if ~a&1 or ~b&1 or ~c&1: print(0) else: print(min(a * b, b * c, c * a)) resolve()
p03161
s265327089
Accepted
N,K = map(int,input().split()) h = list(map(int,input().split())) dp = [0] * N dp[0] = 0 for i in range(1,N): dp[i] = min([dp[i-j-1] + abs(h[i]-h[i-j-1]) for j in range(min(i,K))]) print(dp[-1])
p03544
s416749982
Accepted
import sys n=int(input()) list=[] if n==1: print(1) sys.exit() list.append(2) list.append(1) for i in range(2,87): list.append(list[i-1]+list[i-2]) if n==i: print(list[-1]) sys.exit()
p03612
s350505640
Accepted
n = int(input()) p = list(map(int,input().split())) x = 0 ans = 0 for cnt,num in enumerate(p): if cnt+1 == num: if x == 0: ans += 1 x = 1 else: x = 0 else: x = 0 print(ans)
p02729
s703379425
Accepted
import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) M, N = map(int, input().split()) if M <= 1 and N <= 1: print(0) elif M <= 1: print(combinations_count(N, 2)) elif N <= 1: print(combinations_count(M, 2)) else: print(combinations_count(M, 2) + combinations_count(N, 2))
p03136
s698606480
Accepted
N = int(input()) L = [int(x) for x in input().split()] L.sort(reverse = True) if(L[0] >= sum(L[1:])): print("No") else: print("Yes")
p02678
s449339424
Accepted
from collections import deque n,m=map(int,input().split()) graph=[[] for _ in range(n+1)] for i in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) ans=[-1]*(n+1) ans[0]=0 ans[1]=0 d=deque() d.append(1) while d: v=d.popleft() for i in graph[v]: if ans[i]!=-1: continue ans[i]=v d.append(i) ans=ans[2:] print("Yes") print(*ans,sep="\n")
p02600
s614142604
Wrong Answer
x = int(input()) if x >= 400 and x < 599: print('8') elif x >= 600 and x < 799: print('7') elif x >= 800 and x < 999: print('6') elif x >= 1000 and x < 1199: print('5') elif x >= 1200 and x < 1399: print('4') elif x >= 1400 and x < 1599: print('3') elif x >= 1600 and x < 1799: print('2') elif x >= 1800 and x < 1999: print('1')
p02641
s406209558
Accepted
able = list() for i in range(103): able.insert(i, i-1) X,N = map(int,input().split()) p = list(map(int,input().split())) for i in range(len(p)): able.remove(p[i]) target = 1000 ans = 1000 for i in range(len(able)): if (target > abs(X - able[i])): # if (target == abs(X - able[i])): # ans = min(target, able[i]) # else: target = abs(X - able[i]) ans = able[i] # print(able[i], abs(X - able[i]), ans) print(ans)
p03219
s276649984
Accepted
x,y=map(int,input().split()) print(x+y//2)
p03220
s254169105
Accepted
N=int(input()) T,A=map(int,input().split()) H=[-1000]+list(map(int,input().split())) M=10**10 X=0 for i in range(1,N+1): B=abs(1000*(T-A)-6*H[i]) if B<=M: M=B X=i print(X)
p03251
s627838635
Wrong Answer
a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) if max(b)<=min(c): for i in range(min(c)-max(b)): if a[2]<max(b)+i<=a[3]: print("No War") break else:print("War") else: print("War")
p02860
s243406532
Wrong Answer
N = int(input()) S = input() if N % 2 or S[:N//2-1] != S[N//2:]: print("No") else: print("Yes")
p02714
s942658112
Accepted
n = int(input()) s = list(input()) r = sum([1 for x in s if x == 'R']) g = sum([1 for x in s if x == 'G']) b = sum([1 for x in s if x == 'B']) ans = r * g * b for i in range(n): for j in range(i + 1, n): k = 2 * j - i if j < k <= n - 1: if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]: ans -= 1 print(ans)
p03605
s156567476
Accepted
N = input() print('Yes' if '9' in N else 'No')
p02700
s408019820
Accepted
hp_t, attack_t, hp_a, attack_a = map(int, input().split()) def battle(hp_t, attack_t, hp_a, attack_a, p): if p == 't': hp_a -= attack_t else: hp_t -= attack_a if hp_t <= 0: return 'No' elif hp_a <= 0: return 'Yes' return battle(hp_t, attack_t, hp_a, attack_a, 't' if p == 'a' else 'a') print(battle(hp_t, attack_t, hp_a, attack_a, 't'))
p02899
s345768745
Accepted
n = int(input()) A = list(map(int, input().split())) ans = [0] * n for idx, i in enumerate(A): ans[i-1] = idx + 1 print(' '.join(map(str, ans)))
p02606
s616844069
Wrong Answer
L,R,d = map(int,input().split()) count = 0 for i in range(L,R): if i % d == 0: count += 1 print(count+1)
p02754
s647679574
Wrong Answer
N, A, B = map(int, input().split()) print((N // (A + B)) * A + (N % (A + B)))
p02665
s114477212
Wrong Answer
print(-1)
p03286
s140342272
Accepted
n = int(input()) # したから計算 if n == 0: print(0) exit() ans = "" digit = 1 while n != 0: num = 0 if n % pow(2, digit): num = 1 ans = str(num) + ans n -= num * pow(-2, digit - 1) digit += 1 print(ans)
p03679
s904618076
Wrong Answer
input = input() s_input = input.split() print(s_input) x = int(s_input[0]) * -1 a = int(s_input[1]) b = int(s_input[2]) kigenchouka = a - b if kigenchouka >= 0: print("delicioous") elif kigenchouka > x : print("safe") else: print("danger")
p02596
s023781496
Accepted
K = int(input()) if K % 7 == 0: L = 9 * K / 7 else: L = 9 * K if L % 2 == 0 or L % 5 == 0: print(-1) else: rest = 1 ans = 0 while True: rest *= 10 ans += 1 rest = rest % L if rest == 1: break print(ans)
p03162
s145282118
Wrong Answer
N= int(input()) import numpy as np arr = np.array([input().split() for _ in range(N)], dtype=np.int8) dp = np.zeros_like(arr) for i, arr_ in enumerate(arr): for j in range(len(arr_)): if i == 0: dp[i][j] = arr_[j] continue for k in range(len(arr_)): if j != k: dp[i][j] = max(dp[i-1][k] + arr_[j], dp[i][j]) print(np.max(dp[-1])) #print(dp)
p02951
s981063365
Accepted
a,b,c = list(map(int,input().split())) answer = (c-a+b) print(max(0,answer))
p02819
s314098281
Accepted
x = int(input()) def prime(n): flag = '' for i in range(2, int(n ** 0.5) + 1): if n % i == 0: break else: flag = 'prime_number' return(flag) while(prime(x) != 'prime_number'): x += 1 print(x)
p04019
s346057923
Wrong Answer
s = input() if "N" in s: if "S" not in s : print("No") exit() if "E" in s: if "W" not in s: print("no") exit() print("Yes")
p03699
s524756152
Accepted
import sys n=int(input()) s=[] for i in range(n): s.append(int(input())) if sum(s)%10!=0: print(sum(s)) else: s.sort() for j in range(n): if s[j]%10!=0: num=s[j] break if j==n-1: print(0) sys.exit() print(sum(s)-num)
p03457
s102840452
Accepted
n = int(input()) for i in range(n): t,x,y = map(int,input().split()) if (x+y) > t or (x+y+t) % 2: print("No") exit() print("Yes")
p02633
s944575980
Accepted
if __name__ == '__main__': from sys import stdin # from collections import defaultdict # from collections import deque # from collections import Counter # import copy # import numpy as np import math # import random input = stdin.readline x = int(input()) one_round = 360 print(int(360//math.gcd(one_round, x)))
p02712
s988591172
Wrong Answer
n = int(input()) res = 0 for i in range(n): if i % 3 != 0 and i % 5 != 0: res += i print(res)
p03371
s564452677
Accepted
A, B, C, X, Y = map(int, input().split()) a,b,ab = 0, 0, 0 a = X b = Y ab = 0 m = a * A + b * B + ab * C big = max(X,Y) while ab // 2 <= big: ab += 2 if a > 0: a -= 1 if b > 0: b -= 1 m = min(m, a * A + b * B + ab * C) print(m)