code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
def resolve(): N, M, X = list(map(int, input().split())) C = [] A = [] for i in range(N): ins = list(map(int, input().split())) C.append(ins[0]) A.append(ins[1:]) minprice = float("inf") for bits in range(1<<N): comps = [0 for _ in range(M)] price = 0 for odr in range(N): if (bits & (1<<odr)): price += C[odr] for i in range(M): comps[i] += A[odr][i] for i in range(M): if comps[i] < X: break else: minprice = min(minprice, price) print(minprice if minprice < float("inf") else -1) if '__main__' == __name__: resolve()
n=int(input()) for i in range(50000): if int(i*1.08)==n: print(i) exit() if i*1.08>n: break print(":(")
0
null
74,003,825,990,292
149
265
H, W = map(int, input().split()) w1, w2 = W // 2, W % 2 h1, h2 = H // 2, H % 2 if H > 1 and W > 1: num = 2 * w1 * h1 + w2 * h1 + w1 * h2 + w2 * h2 else: num = 1 print(num)
H, W = map(int, input().split()) h = H // 2 w = W // 2 if H == 1 or W == 1: print(1) exit() if W % 2 == 1: w += 1 if H % 2 == 1: print(h * W + w) else: print(h * W)
1
50,987,914,655,160
null
196
196
n, k = map(int, input().split()) h = list(map(int, input().split())) def answer(n: int, k: int, h: list) -> int: ans = 0 for i in range(0, n): if h[i] >= k: ans += 1 return ans print(answer(n, k, h))
n, k = list(map(int, input().split(' '))) print(sum([tall >= k for tall in list(map(int, input().split(' ')))]))
1
179,223,554,305,812
null
298
298
#!/usr/bin/env python3 from functools import reduce x, y = map(int, input().split()) mod = 10**9 + 7 def cmb(n, r, m): def mul(a, b): return a * b % m r = min(n - r, r) if r == 0: return 1 over = reduce(mul, range(n, n - r, -1)) under = reduce(mul, range(1, r + 1)) return (over * pow(under, m - 2, m))%m r = abs(x - y) l = (min(x, y) - r) // 3 r += l if (x+y)%3 < 1 and l >= 0: print(cmb(r + l, l, mod)) else: print(0)
def COMinit(): fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2,max): fac[i] = fac[i-1]*i%mod inv[i] = mod - inv[mod%i]*(mod//i)%mod finv[i] = finv[i-1]*inv[i]%mod def COM(n,k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k]*finv[n-k]%mod)%mod mod = 10**9+7 X, Y = map(int,input().split()) a = X%2 #1の数 b = X//2 #2の数 for i in range(b+1): if a*2 + b*1 == Y: break a += 2 b -= 1 if a*2 + b*1 != Y: print(0) else: max = a+b+1 fac = [0] * max finv = [0] * max inv = [0] * max COMinit() print(COM(a+b,a))
1
149,705,473,177,920
null
281
281
from math import * while True: n = input() if n==0: break score_li = map(int,raw_input().split()) score_sum = sum(score_li) ave = score_sum/float(n) variance = 0 for i in xrange(n): variance += (score_li[i]-ave)**2 variance /=float(n) sd = sqrt(variance) #sd:standard deviation print sd
from math import sqrt def sd(nums): n = len(nums) ave = sum(nums)/n return abs(sqrt(sum([(s - ave)**2 for s in nums])/n)) def main(): while True: n = input() if n == '0': break nums = [int(x) for x in input().split()] print("{:f}".format(sd(nums))) if __name__ == '__main__': main()
1
193,932,852,532
null
31
31
import copy n = int(input()) A = list(map(str,input().split())) B = copy.copy(A) def BubbleSort(A,n): for i in range(n): for j in range(n-1,i,-1): if int(A[j][1:2])<int(A[j-1][1:2]): v = A[j] A[j] = A[j-1] A[j-1] = v return A def SelectionSort(A,n): for i in range(n): minj = i for j in range(i,n): if int(A[j][1:2])<int(A[minj][1:2]): minj = j v = A[i] A[i] = A[minj] A[minj] = v return A print(' '.join(BubbleSort(A,n))) print('Stable') print(' '.join(SelectionSort(B,n))) if BubbleSort(A,n) == SelectionSort(B,n): print('Stable') else: print('Not stable')
k = int(input()) n = len(input()) mod = pow(10,9)+7 c = 1 ans = pow(26,k,mod) for i in range(1,k+1): c *= (i+n-1)*pow(i,mod-2,mod) c %= mod ans += (c*pow(25,i,mod)*pow(26,k-i,mod)) ans %= mod print(ans)
0
null
6,415,335,874,688
16
124
N = int(input()) D = {} for i in range(N): S = input() M = D.get(S) if M == None: D.update([(S, 1)]) else: D.update([(S, M+1)]) E = list(D.keys()) F = list(D.values()) MA = max(F) I = [i for i,x in enumerate(F) if x == MA] ans =[] for i in I: ans.append(E[i]) ans = sorted(ans) print('\n'.join(ans))
N = int(input()) S = [] for _ in range(N): S.append(input()) import sys from collections import Counter count_dict = Counter(S) most_freq = count_dict.most_common(1)[0][1] words = [] for word, freq in sorted(count_dict.items(), key=lambda x: -x[1]): if freq == most_freq: words.append(word) for word in sorted(words): print(word)
1
70,362,302,185,462
null
218
218
import itertools n,k=map(int,input().split()) d=[] a=[] for i in range(k): p=int(input()) d.append(p) q=list(map(int,input().split())) a.append(q) c=list(itertools.chain.from_iterable(a)) c.sort() c_set=set(c) c=list(c_set) print(n-len(c))
n, k = map(int, input().split()) count = [0] * n for _ in range(k): kosu = int(input()) pos = list(map(int, input().split())) for i in pos: count[i-1] +=1 ans = [True if i == 0 else False for i in count] print(sum(ans))
1
24,633,577,213,920
null
154
154
X = int(input()) for a in range(-1000, 1000): for b in range(-1000, 1000): if a ** 5 - b ** 5 == X: print(a, b) break else: continue break
x=int(input()) for a in range(-120,121): for b in range(-120,121): if x==pow(a,5)-pow(b,5): print(a,b) exit()
1
25,473,518,773,008
null
156
156
import random import time import copy start = time.time() D = int(input()) s = [[0 for j in range(26)] for i in range(D)] c = list(map(int, input().split(" "))) result = [] total = -10000000 for i in range(D): a = list(map(int, input().split(" "))) for j, k in enumerate(a): s[i][j] = int(k) while(1): result_tmp = [] total_tmp=0 last = [0 for i in range(26)] for i in range(D): score = [0 for i in range(26)] for j in range(26): score[j] = s[i][j] for k in range(26): if j != k: score[j] -= (i + 1 - last[k]) * c[k] score_sort = sorted(score, reverse=True) score_max = score_sort[0] tmp = [] for j in range(26): if score_max >= 0 and score_max*0.95 <= score[j]: tmp.append(j) if score_max < 0 and score_max*1.05 <= score[j]: tmp.append(j) score_max = random.choice(tmp) result_tmp.append(score_max) last[score_max] = i + 1 total_tmp += score[score_max] if total < total_tmp: total=total_tmp result = result_tmp.copy() end = time.time() if end - start > 1.8: break for i in range(D): print(result[i]+1)
import random import copy import time def evaluateSatisfaction(d, c, s, ans): score = 0 last = [-1 for i in range(26)] for i in range(d): score += s[i][ans[i]] last[ans[i]] = i for j in range(26): if j != ans[i] or True: score -= c[j]*(i - last[j]) return score def valuationFunction(d,c,s,contestType,day,last): gain = s[day][contestType] #78 = (1/2) * ((13*13) - 13) lost = c[contestType] * (78) return gain - lost def Input(): d = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for i in range(d)] #s[3][25] = contest(25+1) of day(3+1) return d, c, s def evolution(d, c, s, ans): score_before = evaluateSatisfaction(d, c, s, ans) ans_after = copy.copy(ans) idx1 = random.randint(0,d-1) idx2 = random.randint(0,d-1) tmp = ans_after[idx1] ans_after[idx1] = ans_after[idx2] ans_after[idx2] = tmp score_after = evaluateSatisfaction(d,c,s,ans_after) if score_after > score_before: return ans_after else: return ans if __name__ == "__main__": d, c, s = Input() #print("val =", evaluateSatisfaction(d, c, s, [1, 17, 13, 14, 13])) #calc start t1 = time.time() ans = [0 for i in range(d)] last = [-1 for i in range(26)] for i in range(d): evalValueList = [0 for j in range(26)] for j in range(26): evalValueList[j] = valuationFunction(d, c, s, j,i,last) max_idx = 0 max = evalValueList[0] for j in range(26): if (max < evalValueList[j]): max_idx = j max = evalValueList[j] ans[i] = max_idx last[ans[i]] = i #ans = [1, 2, 3, 4, 5] t2 = time.time() while(float(t2-t1) < 1.0): ans = evolution(d, c, s, ans) #print("ans = ",evaluateSatisfaction(d,c,s,ans)) t2 = time.time() for x in ans: print(x + 1) #print(evaluateSatisfaction(d,c,s,ans))
1
9,653,630,303,200
null
113
113
def calc(a,D,K): if K==1: return a+(D-1)*9 elif K==2: return (a-1)*(D-1)*9 + (D-1)*(D-2)//2*81 else: return (a-1)*(D-1)*(D-2)//2*81 + (D-1)*(D-2)*(D-3)//6*729 N=input() K=int(input()) D = len(N) score=0 for i,a in enumerate(N): if a!="0": score+=calc(int(a),D-i,K) K-=1 if K==0: break print(score)
s=input() n=len(s) K=int(input()) dp=[[[0] * 5 for _ in range(2)] for _ in range(n+1)] dp[0][0][0]=1 for i in range(n): ni= int(s[i]) for k in range(4): # smaller 1 -> 全部OK dp[i + 1][1][k + 1] += dp[i][1][k] * 9; dp[i + 1][1][k] += dp[i][1][k]; # smaller 0,next smaller 1 -> nowより小さいのを全部 # 次の桁からsmallerであるためにはN<ni であることが必要で # Nは0より大きい必要がある。(0より小さいものがない=確定しない if (ni > 0): dp[i + 1][1][k + 1] += dp[i][0][k] * (ni - 1) dp[i + 1][1][k] += dp[i][0][k] # smaller 0,next smaller 0 -> nowだけ if (ni > 0) : dp[i + 1][0][k + 1] = dp[i][0][k] else: dp[i + 1][0][k] = dp[i][0][k] ans=dp[n][0][K] + dp[n][1][K] print(ans)
1
76,093,447,073,438
null
224
224
S=str(input()) n=[] for i in range(3): n.append(S[i]) print(''.join(n))
while True: m,f,r = map(int, raw_input().split()) s = m + f if m == -1 and f == -1 and r == -1: break elif m == -1 or f == -1 or s < 30: g=5 elif 30 <= s and s < 50: if r >= 50: g=2 else: g=3 elif 50 <= s and s < 65: g=2 elif 65 <= s and s < 80: g=1 else: g=0 print 'ABCDEF'[g]
0
null
7,999,456,923,642
130
57
x,y=map(int,input().split()) r=0 for i in range(0,x+1): c=i t=x-c if c*2+t*4==y: r=r+1 if r!=0: print("Yes") else: print("No")
if __name__ == '__main__': x, y = map(int, input().split()) ans = 'No' for i in range(x+1): legs = 4*i+2*(x-i) if legs == y: ans = 'Yes' break print(ans)
1
13,688,784,622,630
null
127
127
n = int(input()) x = [] y = [] for _ in range(n): a,b = map(int,input().split()) x.append(a) y.append(b) ans = 0 for i in range(n): for j in range(n): ans += ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5 print(ans/n)
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] #a = [input() for _ in range(n)] import itertools import math n = int(input()) l = [list(map(int,input().split())) for i in range(n)] seq = [] for i in range(n): seq.append(i) a = list(itertools.permutations(seq)) #print(a) ans = 0 for i in a: for j in range(0,n-1): #idx1とidx2との距離 ans += math.sqrt((l[i[j]][0] - l[i[j+1]][0])**2 + (l[i[j]][1] - l[i[j+1]][1])**2) print(ans/len(a))
1
148,515,273,038,432
null
280
280
def main(): a,b,c = map(int,input().split()) rhs = c - a - b lhs = 4 * a * b if rhs > 0 and lhs < rhs ** 2: print('Yes') else: print('No') main()
from decimal import Decimal a,b,c = map(int,input().split()) a = Decimal(a) b = Decimal(b) c = Decimal(c) if Decimal.sqrt(a) + Decimal.sqrt(b) < Decimal.sqrt(c): print('Yes') else: print('No')
1
51,635,351,707,108
null
197
197
#!usr/bin/env python3 import sys def int_fetcher(): num = int(sys.stdin.readline()) return num def call(num): res = '' for i in range(1, num+1): x = i if x % 3 == 0 or x % 10 == 3: res += ' ' + str(i) continue while x: if x % 10 == 3: res += ' ' + str(i) break x //= 10 return res def main(): print(call(int_fetcher())) if __name__ == '__main__': main()
n = int(input()) i = 1 for i in range(1, n + 1): if i % 3 == 0: print(' {0}'.format(i), end = '') else: st = str(i) for x in range(0, len(st)): if st[x] == '3': print(' {0}'.format(i), end = '') break print()
1
936,024,299,616
null
52
52
n,k = map(int,input().split()) p = list(map(int,input().split())) p.sort() print(sum(p[:k]))
N,K=map(int,input().split()) pi=list(map(int,input().split())) pi_sort=sorted(pi,reverse=False) ans=0 for i in range(K): ans+=pi_sort[i] print(ans)
1
11,606,080,048,320
null
120
120
n = input() A = map(int, raw_input().split()) q = input() m = map(int, raw_input().split()) def solve(i, m): if m == 0: return True if i >= n or m > sum(A): return False res = solve(i+1, m) or solve(i+1, m-A[i]) return res for j in range(0, q): if solve(0, m[j]): print 'yes' else: print 'no'
n = int(input()) lst = [0] *4 for i in range(n): a = input() if a == 'AC': lst[0] += 1 if a == 'WA': lst[1] += 1 if a == 'TLE': lst[2] += 1 if a == 'RE': lst[3] += 1 print('AC x',lst[0]) print('WA x',lst[1]) print('TLE x',lst[2]) print('RE x',lst[3])
0
null
4,440,434,461,782
25
109
def solve(): N, K = map(int, input().split()) H = list(map(int, input().split())) H.sort() ans = sum(H[:max(N-K,0)]) return ans print(solve())
n,k = map(int,input().split()) h = list(map(int,input().split())) m = sorted(h,reverse=True) if n <= k: print(0) exit() q = sum(m[k:n]) print(q)
1
79,094,554,901,120
null
227
227
num1 = int(input()) num = (int(x) for x in input().split()) count = 0 for i, name in enumerate(num): if i % 2 == 0: if name % 2 == 1: count = count + 1 print(count)
N = int(input()) X = input() x = X[::-1] one = X.count('1') up = 0 down = 0 for i in range(N): up += (int(x[i]) * pow(2,i,one+1) % (one+1)) up %= one+1 if one > 1: down += (int(x[i]) * pow(2,i,one-1) % (one-1)) down %= one-1 # print(up,down) def f(ud,one): if one <= 0: return 0 else: if ud == 0: return 1 cnt = 0 while ud != 0: ud = ud % one one = format(ud,'b').count('1') cnt += 1 return cnt for i in range(len(X)): if X[i] == '1': if one > 1: print(f((down - pow(2,(len(X)-1) - i, one-1)) % (one-1),one-1)) #print(down - pow(2,(len(X)-1) - i, one-1) % (one-1)) else: print(0) else: print(f((up + pow(2,(len(X)-1) - i, one+1)) % (one+1),one+1)) #print(up + pow(2,(len(X)-1) - i, one+1) % (one+1))
0
null
7,975,860,222,160
105
107
#!python3 import sys from collections import defaultdict from math import gcd iim = lambda: map(int, input().rstrip().split()) def resolve(): N = input() it = map(int, sys.stdin.read().split()) mod = 10**9 + 7 d1 = [defaultdict(int), defaultdict(int)] z0 = za = zb = 0 for ai, bi in zip(it, it): t = ai * bi if t == 0: if ai != 0: za += 1 elif bi != 0: zb += 1 else: z0 += 1 continue ci = gcd(ai, bi) ai, bi = ai // ci, bi // ci t = t < 0 if ai < 0: ai, bi = -ai ,-bi d1[t][(ai, bi)] += 1 a1, a2 = d1 ans = 1 z1 = 0 for (ai, bi), v in a1.items(): k2 = (bi, -ai) if k2 in a2: v2 = a2[k2] ans *= pow(2, v, mod) + pow(2, v2, mod) - 1 ans %= mod else: z1 += v for (ai, bi), v in a2.items(): k2 = (-bi, ai) if k2 in a1: continue z1 += v ans *= pow(2, za, mod) + pow(2, zb, mod) - 1 ans %= mod ans *= pow(2, z1, mod) print((ans-1+z0) % mod) if __name__ == "__main__": resolve()
n = int(input()) ab=[list(map(int,input().split())) for i in range(n)] import math from collections import defaultdict d = defaultdict(int) zerozero=0 azero=0 bzero=0 for tmp in ab: a,b=tmp if a==0 and b==0: zerozero+=1 continue if a==0: azero+=1 continue if b==0: bzero+=1 continue absa=abs(a) absb=abs(b) gcd = math.gcd(absa,absb) absa//=gcd absb//=gcd if a*b >0: d[(absa,absb)]+=1 else: d[(absa,-absb)]+=1 found = defaultdict(int) d[(0,1)]=azero d[(1,0)]=bzero ans=1 mod=1000000007 for k in list(d.keys()): num = d[k] a,b=k if b>0: bad_ab = (b,-a) else: bad_ab = (-b,a) if found[k]!=0: continue found[bad_ab] = 1 bm=d[bad_ab] if bm == 0: mul = pow(2,num,mod) if k==bad_ab: mul = num+1 else: mul = pow(2,num,mod) + pow(2,bm,mod) -1 ans*=mul ans+=zerozero ans-=1 print(ans%mod)
1
20,909,240,050,400
null
146
146
# n,m = map(int, input().split()) # sc = [map(int, input().split()) for _ in range(m)] # s, c = [list(i) for i in zip(*sc)] # # # # for i in range(10**n): # ans = str(i) # if len(i) == n and all([i[s[j]-1] == str(c[j]) for j in range(m)]): # print(ans) # exit() # # # print(-1) n, m = map(int, input().split()) s, c = [], [] for _ in range(m): s_, c_ = map(int, input().split()) s.append(s_) c.append(c_) for i in range(10 ** n): ans = str(i) if len(ans) == n and all([ans[s[j] - 1] == str(c[j]) for j in range(m)]): print(ans) exit() print(-1)
def f(): n, m = map(int, input().split()) num = [set() for i in range(n)] for i in range(m): s, c = map(int, input().split()) num[s-1].add(c) s = [] for i in num: if len(i) > 1: print(-1) return if len(i) == 1: for x in i: s.append(x) break else: s.append(0) if s[0] == 0 and n != 1: if len(num[0]) > 0: print(-1) return else: s[0] = 1 print(''.join(str(x) for x in s)) f()
1
60,851,126,423,540
null
208
208
# -*- coding: utf-8 -*- N = int(input().strip()) A_list = list(map(int, input().rstrip().split())) #----- # A_index[i] = ( value of A , index of A) A_index = [ (A_list[i], i) for i in range(len(A_list)) ] A_index.sort(reverse=True) # dp[left][right] = score dp = [ [0]*(N+1) for _ in range(N+1) ] for L in range(N): for R in range(N-L): i = L + R append_L = dp[L][R] + A_index[i][0] * abs(L - A_index[i][1]) append_R = dp[L][R] + A_index[i][0] * abs((N-1-R) - A_index[i][1]) dp[L+1][R] = max(dp[L+1][R], append_L) dp[L][R+1] = max(dp[L][R+1], append_R) ans = max( [ dp[i][N-i] for i in range(N+1)] ) print(ans)
#!/usr/bin/env python3 import sys sys.setrecursionlimit(300000) from pprint import pprint def solve(N: int, A: "List[int]"): memo = [{} for _ in range(N + 1)] def rec(idx, rest, can_use=True): k = (rest, can_use) if rest * 2 >= N - idx + 2: return 0 if rest == 0: return 0 if k in memo[idx]: return memo[idx][k] ret = 0 if not can_use: ret = rec(idx + 1, rest) elif rest * 2 > (N - idx): ret = A[idx] + rec(idx + 1, rest - 1, False) else: a = A[idx] + rec(idx + 1, rest - 1, False) b = rec(idx + 1, rest) ret = max(a, b) memo[idx][k] = ret return ret ret = rec(0, N // 2) print(ret) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == '__main__': main()
0
null
35,688,760,016,310
171
177
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors N = int(input()) ans = len(make_divisors(N-1))-1 for i in make_divisors(N): if i == 1: continue Ni = int(N/i) while Ni % i == 0: Ni = int(Ni/i) if Ni % i == 1: ans+=1 print(ans)
d = list(map(int, input().split())) order = input() class Dice(): def __init__(self, d): self.dice = d def InsSN(self, one, two, five, six): self.dice[0] = one self.dice[1] = two self.dice[4] = five self.dice[5] = six def InsWE(self, one, three, four, six): self.dice[0] = one self.dice[2] = three self.dice[3] = four self.dice[5] = six def S(self): one = self.dice[4] two = self.dice[0] five = self.dice[5] six = self.dice[1] self.InsSN(one, two, five, six) def N(self): one = self.dice[1] two = self.dice[5] five = self.dice[0] six = self.dice[4] self.InsSN(one, two, five, six) def W(self): one = self.dice[2] three = self.dice[5] four = self.dice[0] six = self.dice[3] self.InsWE(one, three, four, six) def E(self): one = self.dice[3] three = self.dice[0] four = self.dice[5] six = self.dice[2] self.InsWE(one, three, four, six) def roll(self, order): if order == 'S': self.S() elif order == 'N': self.N() elif order == 'E': self.E() elif order == 'W': self.W() d = Dice(d) for o in order: d.roll(o) print(d.dice[0])
0
null
20,818,591,435,628
183
33
a, b, k = list(map(int, input().split())) if a >= k: a -= k elif b >= k-a: b -= k-a a = 0 else: a = b = 0 print(a, b)
import math from copy import copy di = {} di[0] = 0 for i in range(1, 2*(10**5)+1): di[i] = 0 for i in range(1, 2*(10**5)+1): count = 0 for j in range(int(math.log2(i))+4): if (i>>j)&1: count += 1 di[i] = di[i%count] + 1 n = int(input()) x = list(input()) x.reverse() count = 0 for i in x: if i =='1': count += 1 mod_p = count + 1 mod_m = count - 1 di_p = {} di_m = {} for i in range(n): di_p[i] = pow(2, i, mod_p) if mod_m >= 1: di_m[i] = pow(2, i, mod_m) s_p = 0 s_m = 0 for i in range(n): if x[i] == '1': s_p += di_p[i] if mod_m >= 1: s_m += di_m[i] else: continue for i in range(n-1, -1, -1): sm = copy(s_m) sp = copy(s_p) if x[i] == '1' and (mod_m == 0 or mod_m == -1): print(0) elif x[i] == '1': sm -= di_m[i] sm %= mod_m print(di[sm]+1) else: sp += di_p[i] sp %= mod_p print(di[sp]+1)
0
null
56,049,144,011,968
249
107
def solve(): N = int(input()) return N*N print(solve())
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math from copy import copy, deepcopy from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意 from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする def input(): return sys.stdin.readline()[:-1] def printl(li): print(*li, sep="\n") def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def extgcd1(a0,b0): u=1 v=0 a=a0 b=b0 while b: t=a//b a-=t*b a,b=b,a u-=t*v u,v=v,u if a!=1: #print("not 素") return -1 return u%b0 #a0*u=1(mod b0) def main(): mod =998244353 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え #N = int(input()) N, M, K = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル #L = tuple(int(input()) for i in range(N)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 # dp=[0]*2 # ndp=copy(dp) # dp[0]=0 # dp[1]=M # for i in range(2,N+1): # if i<=K+1: # ndp[0]=((M-1)*(dp[0]+dp[1])+dp[0])%mod # ndp[1]=dp[1] # else: # ndp[0]=(M*dp[0]+(M-1)*dp[1])%mod # ndp[1]=0 # dp=copy(ndp) # ans=(dp[0]+dp[1])%mod # #print(ans) #n0=math.factorial(N-1) #ks=[1]*(N-1+1) #for k in range(2,N-1+1): # ks[k]=ks[k-1]*k ans=0 c0=1 c1=pow(M-1,N-1,mod) inv=[1,1]+[extgcd1(i,mod) for i in range(2,N)] #print("ok1") ifac=[1]*(N) nfac=1 for i in range(1,N): nfac=(i*nfac)%mod ifac[i]=(ifac[i-1]*inv[i])%mod #print("ok2") #print(ifac) mp=[1]*(N) for i in range(1,N): mp[i]=(mp[i-1]*(M-1))%mod #print("ok3") ans=0 #print(nfac) #print(mp) for k in range(0,K+1): #print((n0//ks[k]//ks[N-1-k])) ans=ans+(mp[N-1-k]*nfac*ifac[k]*ifac[N-1-k])%mod ans%=mod #print(ans) #print(ks) ans=(ans*M)%mod print(ans) if __name__ == "__main__": main()
0
null
84,061,075,218,660
278
151
N = int(input()) X = input() memo = {} X_int = int(X, 2) def popcount(n: int): x = bin(n)[2:] return x.count("1") pcf = popcount(int(X, 2)) pcm = pcf - 1 pcp = pcf + 1 xm = X_int % pcm if pcm != 0 else 0 xp = X_int % pcp def f(n: int, ops: int): while n != 0: n %= popcount(n) ops += 1 return ops def rev(x: str, i: int): if x == "1": if pcm == 0: return -1 n = (xm - (pow(2, N-i-1, pcm))) % pcm else: n = (xp + (pow(2, N-i-1, pcp))) % pcp return n if __name__ == "__main__": for i, x in enumerate(X): n = rev(x, i) if n == -1: print(0) else: print(f(n, 1))
n,m = map(int, input().split()) s=[] for i in range(m): s.append(list(map(int, input().split()))) if n==1: kaisuu_start=0 kaisuu_stop=10 elif n==2: kaisuu_start=10 kaisuu_stop=100 elif n==3: kaisuu_start=100 kaisuu_stop=1000 for suuzi in range(kaisuu_start,kaisuu_stop): hantei=True suuzi=str(suuzi) for gyou in range(m): if suuzi[s[gyou][0]-1]!=str(s[gyou][1]): hantei=False continue if hantei: print(suuzi) exit() print(-1)
0
null
34,397,398,696,372
107
208
s = str(input()) t = str(input()) ans = 1001 for i in range(len(s)-len(t)+1): tmp = 0 for j in range(len(t)): if s[i+j] == t[j]: tmp += 1 ans = min(len(t)-tmp,ans) print(ans)
if __name__ == '__main__': a, b, c = input().split() a, b, c = int(a), int(b), int(c) if a < b and b < c: print("Yes") else: print("No")
0
null
2,058,763,301,792
82
39
n,m=map(int,input().split()) h=list(map(int,input().split())) t=['W']*n for i in range(m): a,b=map(int,input().split()) if h[a-1]>=h[b-1]: t[b-1]='L' if h[a-1]<=h[b-1]: t[a-1]='L' print(t.count('W'))
N, M = map(int, input().split()) H = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(M)] ok = [True] * (N + 1) for a, b in X: ok[a] &= H[a - 1] > H[b - 1] ok[b] &= H[a - 1] < H[b - 1] print(sum(ok[1:]))
1
24,995,334,158,406
null
155
155
import re s = input() bl = re.fullmatch(r"^(hi)+$", s) is not None print("Yes" if bl else "No")
import math n=int(input()) ans=0 num=int(math.sqrt(n)+1) for i in range(1,num)[::-1]: if n%i==0: ans=i+(n//i)-2 break print(ans)
0
null
107,395,472,314,952
199
288
N = int(input()) A = list(map(int,input().split())) count = 0 for i in range(0,N,2): if A[i]%2 != 0: count += 1 print(count)
import sys sys.setrecursionlimit(300000) def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 INF = float('inf') N = I() A = LMI() ans = 0 for i, a in enumerate(A): if i % 2 == 0 and a % 2 != 0: ans += 1 print(ans)
1
7,826,649,513,748
null
105
105
from collections import Counter H, W, M = map(int, input().split()) dh, dw = Counter(), Counter() used = set() for _ in range(M): h, w = map(int, input().split()) dh[h] += 1 dw[w] += 1 used.add((h, w)) ih = dh.most_common() iw = dw.most_common() s = ih[0][1] + iw[0][1] ans = 0 for h, sh in ih: for w, sw in iw: if sh+sw < s or ans == s: break b = sh + sw - ((h, w) in used) ans = max(ans, b) print(ans)
h,w,m=map(int,input().split()) r=[0]*h c=[0]*w s=set() for _ in range(m): i,j=map(int,input().split()) i-=1 j-=1 r[i]+=1 c[j]+=1 s.add(i*w+j) rmx=max(r) cmx=max(c) rc=[i for i in range(h) if r[i]==rmx] cc=[j for j in range(w) if c[j]==cmx] ans=rmx+cmx-1 for i in rc: for j in cc: if i*w+j not in s: print(ans+1) exit() print(ans)
1
4,744,292,368,560
null
89
89
K=int(input()) if K==4 : print(2) elif K==6 : print(2) elif K==8 : print(5) elif K==9 : print(2) elif K==10 : print(2) elif K==12 : print(5) elif K==14 : print(2) elif K==16 : print(14) elif K==18 : print(5) elif K==20 : print(5) elif K==21 : print(2) elif K==22 : print(2) elif K==24 : print(15) elif K==25 : print(2) elif K==26 : print(2) elif K==27 : print(5) elif K==28 : print(4) elif K==30 : print(4) elif K==32 : print(51) else : print(1)
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) INF = float("inf") def solve(K: int): A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print(A[K-1]) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() K = int(next(tokens)) # type: int solve(K) if __name__ == '__main__': main()
1
49,960,847,023,670
null
195
195
while(1): line = input() words = line.split() a = int(words[0]) op = words[1] b = int(words[2]) if op == '+': print(a + b) elif op == '-': print(a - b) elif op == '*': print(a * b) elif op == '/': print(a // b) elif op == '?': break
while 1: a, op, b = raw_input().split(' ') if op == '?':break print eval("%s %s %s"%(a, op, b))
1
684,725,133,020
null
47
47
inps = input().split() if len(inps) >= 3: a = int(inps[0]) b = int(inps[1]) c = int(inps[2]) if a < b and b < c: print("Yes") else: print("No") else: print("Input illegal.")
#coding:UTF-8 import copy n = map(int,raw_input().split()) if n[0]<n[1]<n[2]: print "Yes" else: print "No"
1
382,209,419,520
null
39
39
n, m = map(int, raw_input().split()) a = [] for _ in range(n): a.append(map(int, raw_input().split())) b = [] for _ in range(m): b.append(int(raw_input())) for i in range(n): c = [] for j in range(m): c.append(a[i][j]*b[j]) print sum(c)
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] #a = [input() for _ in range(n)] import itertools import math n = int(input()) l = [list(map(int,input().split())) for i in range(n)] seq = [] for i in range(n): seq.append(i) a = list(itertools.permutations(seq)) #print(a) ans = 0 for i in a: for j in range(0,n-1): #idx1とidx2との距離 ans += math.sqrt((l[i[j]][0] - l[i[j+1]][0])**2 + (l[i[j]][1] - l[i[j+1]][1])**2) print(ans/len(a))
0
null
75,019,193,261,170
56
280
a=int(input()) b=list(map(int,input().split())) c=0 for i in range(a): if b[i]%2==0: if b[i]%3==0 or b[i]%5==0: c=c+1 else: c=c+1 if c==a: print("APPROVED") else: print("DENIED")
N = int(input()) A = list(map(int, input().split())) if len(A) > len(set(A)): print("NO") else: print("YES")
0
null
71,738,481,069,358
217
222
import sys read = sys.stdin.read readlines = sys.stdin.readlines from math import floor def main(): a, b, n = map(int, input().split()) if n < b: x = n else: x = b - 1 r = floor(a * x / b) - a * floor(x / b) print(r) if __name__ == '__main__': main()
A,B,N = map(int,input().split()) if B<=N: print(int((A*(B-1))/B)-(A*int((B-1)/B))) else: print(int((A*N)/B)-(A*int(N/B)))
1
28,014,330,630,848
null
161
161
import math def solve(): a,b,h,m=map(int,input().split()) sita=math.pi*2*((h+m/60)/12-m/60) c=math.sqrt(a*a+b*b-2*a*b*math.cos(sita)) return c print(solve())
import math a,b,H,M=map(int,input().split()) theta_a = math.pi/6 * (H+M/60) theta_b = math.pi*2*M/60 ans = math.sqrt((b*math.cos(theta_b) - a*math.cos(theta_a))**2 + (b*math.sin(theta_b) - a*math.sin(theta_a))**2) print(ans)
1
20,158,300,531,450
null
144
144
n,k=map(int,input().split()) i=0 while n//k**(i+1)>=1: i+=1 print(i+1)
n,k = map(int,input().split()) ans = 1 while n >= k: ans += 1 n //= k print(ans)
1
64,024,150,341,312
null
212
212
input = int(input()) if input == 0: print (1) else: print (0)
x = not(int(input())) print(int(x))
1
2,931,147,022,430
null
76
76
import math a = 100000 for n in range(int(input())): a = math.ceil(a*105/100000)*1000 print(int(a))
#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 a,b,c=map(int,input().split()) if 4*a*b<(c-a-b)**2 and (c-a-b)>0: print("Yes") else: print("No")
0
null
25,662,379,389,940
6
197
n,m = map(int,input().split()) v1 = [ list(map(int,input().split())) for i in range(n) ] v2 = [ int(input()) for i in range(m) ] for v in v1: print( sum([ v[i] * v2[i] for i in range(m) ]))
x = list(map(int,input().split())) a = x[0] b = x[1] if(2*b < a): print(a-2*b) else: print(0)
0
null
84,243,428,553,580
56
291
N=int(input()) S=input() s=[] for i in S: T=ord(i) - ord('A') + 1+N+64 if T<=90: t=T else: t=T-26 s.append(chr(t)) print(*s,sep='')
N = int(input()) S = input() T = "" for s in S: a = ord(s) + N if a > ord("Z"): a -= 26 T += chr(a) print(T)
1
134,094,286,137,500
null
271
271
n, x, t = map(int,input().split(' ')) r = int(n / x) + (1 if n % x > 0 else 0) print(r * t)
N, X, T = map(int, input().split()) S = int((N+X-1)/X) print(S*T)
1
4,208,086,564,492
null
86
86
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n, k, *p = map(int, read().split()) p.sort() r = sum(p[:k]) print(r) if __name__ == '__main__': main()
X,Y = map(int,input().split()) MMM = map (int,input().split()) MM = list(MMM) MM.sort() total = 0 for i in range(Y): total += MM[i] print(total)
1
11,624,502,176,672
null
120
120
from collections import deque N = int(input()) K = 0 Ans = [0] * (N-1) Edge = [[] for _ in range(N)] for _ in range(N-1): a, b = map(int, input().split()) a -= 1 b -= 1 Edge[a].append((b, _)) Edge[b].append((a, _)) Q = deque() Q.append((0, 0)) P = [-1] * N while Q: now, color = Q.popleft() cnt = 1 for nex, num in Edge[now]: if cnt == color: cnt += 1 if nex == P[now]: continue if Ans[num] != 0: continue Q.append((nex, cnt)) Ans[num] = cnt K = max(cnt, K) cnt += 1 print(K) for a in Ans: print(a)
from collections import deque n = int(input()) g = [[] for _ in range(n)] ab = [] for _ in range(n-1): a, b = map(int, input().split()) a, b = a - 1, b - 1 g[a].append(b) g[b].append(a) ab.append((a, b)) q = deque([0]) chk = [False] * n chk[0] = True res = [0] * n par = [0] * n while q: x = q.popleft() cnt = 1 for y in g[x]: if chk[y]: continue if res[x] == cnt: cnt += 1 res[y], par[y], chk[y] = cnt, x, True cnt += 1 q.append(y) ans = [] for a, b in ab: if par[a] == b: ans.append(res[a]) else: ans.append(res[b]) print(max(ans), *ans, sep="\n")
1
135,440,499,984,130
null
272
272
s = input() t = input() n = len(s) ans = n for i in range(n): if s[i] == t[i]: ans -= 1 print(ans)
s = input() t = input() count = 0 for ss, tt in zip(s, t): if ss != tt: count += 1 print(count)
1
10,592,465,547,940
null
116
116
import sys import math while True: line = sys.stdin.readline() if not line: break token = list(map(int, line.strip().split())) print(int(math.log10(token[0] + token[1]) + 1))
import collections n = int(input()) a = list(map(int, input().split())) l = [] r = [] for i in range(n): l.append(i+a[i]) r.append(i-a[i]) count = collections.Counter(r) ans = 0 for i in l: ans += count.get(i,0) print(ans)
0
null
13,107,617,271,460
3
157
N,K = map(int,input().split()) ans=1 p=K while p <= N: p *= K ans+=1 print(ans)
r=int(input()) print(int(r**2))
0
null
105,128,906,972,930
212
278
N = int(raw_input()) A = map(int,raw_input().split()) print ' '.join(map(str,A)) for i in range(1,N): v = A[i] j = i - 1 while j >=0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print ' '.join(map(str,A))
n = int(input()) num = list(map(int, input().split())) print(" ".join(map(str, num))) for i in range(len(num)-1): key = num[i+1] j = i while j >= 0 and num[j] > key: num[j+1] = num[j] j -= 1 num[j+1] = key print(" ".join(map(str, num)))
1
5,918,796,180
null
10
10
n, m = map(int, input().split()) h = [int(x) for x in input().split()] cnt = [1] * n for _ in range(m): a, b = map(int, input().split()) if h[a-1] > h[b-1]: cnt[b-1] = 0 elif h[a-1] < h[b-1]: cnt[a-1] = 0 else: cnt[a-1] = 0 cnt[b-1] = 0 print(cnt.count(1))
n,m=[int(x) for x in input().split()] h=[int(x) for x in input().split()] t=[[]for i in range(n)] ans=0 for i in range(m): a,b=[int(x) for x in input().split()] t[a-1].append(b-1) t[b-1].append(a-1) for i in range(n): if t[i]==[]: ans+=1 else: c=[] for j in t[i]: if h[i]<=h[j]: c.append(False) if c==[]: ans+=1 print(ans)
1
25,134,544,722,532
null
155
155
N = int(input()) A_list = list(map(int, input().split())) if A_list[0] > 1: print(-1) exit() elif A_list[0] == 1: if N == 0: print(1) else: print(-1) exit() sumA = sum(A_list) node = 1 count = 1 for i in range(len(A_list) - 1): temp = min([node * 2, sumA]) count += temp node = temp - A_list[i + 1] if node < 0: print(-1) exit() sumA -= A_list[i + 1] print(count)
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) low = [0]*(N+1) high = [0]*(N+1) low[N] = A[N] high[N] = A[N] for i in range(N-1, -1, -1): low[i] = (low[i+1]+1)//2+A[i] high[i] = high[i+1]+A[i] if not low[0]<=1<=high[0]: print(-1) exit() ans = 1 now = 1 for i in range(N): now = min(2*(now-A[i]), high[i+1]) ans += now print(ans)
1
18,901,827,490,980
null
141
141
n, k, c = map(int, input().split()) s = input() def solve_dp(s): dp = [0]*(n+2) for i in range(n): if i <= c and s[i] == 'o': dp[i+1] = 1 else: if s[i] == 'o': dp[i+1] = max(dp[i], dp[i-c]+1) else: dp[i+1] = dp[i] return dp mae = solve_dp(s) ushiro = solve_dp(s[::-1])[::-1] for i in range(1,n+1): if mae[i-1] + ushiro[i+1] < k: print(i)
N, K, C = map(int, input().split()) S = list(input()) # 左詰めの働くリスト l_list = [-1 for i in range(N)] i = 0 cnt = 0 while(i < N and cnt < K): if(S[i] == "o"): l_list[i] = cnt cnt += 1 i += C i += 1 # 右詰めの働くリスト r_list = [-1 for i in range(N)] i = N - 1 cnt = 0 while(i >= 0 and cnt < K): if(S[i] == "o"): r_list[i] = K-1-cnt cnt += 1 i -= C i -= 1 # 両方のリストで一致するマス(日)を出力 for i in range(N): if(l_list[i] == -1 or r_list[i] == -1): continue if(l_list[i] == r_list[i]): print(i+1)
1
40,753,617,891,180
null
182
182
import math A, B, H, M = map(int, input().split()) X, Y = A*math.cos(math.pi*(60*H+M)/360), -A*math.sin(math.pi*(60*H+M)/360) x, y = B*math.cos(math.pi*M/30), -B*math.sin(math.pi*M/30) print(math.sqrt((X-x)**2+(Y-y)**2))
import math A,B,H,M=map(int,input().split()) b=30*H+30*(M/60) c=6*M d=math.fabs(b-c) d=math.radians(d) f=0 f=A**2+B**2-2*A*B*(math.cos(d)) print(math.fabs(math.sqrt(f)))
1
20,141,709,580,510
null
144
144
O = ['Yes','No'] S = str(input()) f = 0 if S == 'AAA' or S == 'BBB': f = 1 print(O[f])
from queue import Queue N = int(input()) G = [[] for _ in range(N)] Q = [{} for _ in range(N)] for i in range(N-1): a, b = map(int, input().split()) G[a-1].append(b-1) G[b-1].append(a-1) Q[a-1][b-1] = i K = max(list(map(len, G))) print(K) ans = [0] * (N-1) q = Queue() q.put(0) while not q.empty(): v = q.get() c = set() for u in G[v]: if u < v: c.add(ans[Q[u][v]]) i = 1 for u in G[v]: if u > v: while i in c: i += 1 ans[Q[v][u]] = i i += 1 q.put(u) for a in ans: print(a)
0
null
95,916,910,066,678
201
272
n = int(input()) A = [(a, i) for i, a in enumerate(map(int, input().split()))] A.sort(reverse=True) dp = [[0]*(n+1) for _ in range(n+1)] ans = 0 for L in range(n+1): for R in range(n+1): if n <= L+R-1: continue a, i = A[L+R-1] if 0 <= R-1: dp[L][R] = max(dp[L][R], dp[L][R-1]+abs((n-R)-i)*a) if 0 <= L-1: dp[L][R] = max(dp[L][R], dp[L-1][R]+abs(i-(L-1))*a) ans = max(ans, dp[L][R]) print(ans)
""" Writer: SPD_9X2 https://atcoder.jp/contests/abc163/tasks/abc163_e dpか? なにを基準にdpすればよい? まとめられる状態は? 小さいことを考えると貪欲かなぁ かいてみるか 挿入dp? 前から決めていけば、累積和で減る量がわかる &増える寄与も計算できる O(N**2) 全探索はむり ======答えを見ました====== 今より右に行く、左に行くの集合に分けたとすると 大きい奴をより左にする方が最適 よって、途中まで単調減少、途中から単調増加が最適であるとわかる dp[大きい方からi番目まで見た][左にl個つめた] = 最大値 で解ける """ N = int(input()) A = list(map(int,input().split())) ai = [] for i in range(N): ai.append([A[i],i]) ai.sort() ai.reverse() ans = 0 dp = [ [float("-inf")] * (N+1) for i in range(N+1) ] dp[0][0] = 0 for i in range(N): na,nind = ai[i] for l in range(i+1): r = N-1-(i-l) dp[i+1][l+1] = max(dp[i+1][l+1] , dp[i][l] + na*abs(nind-l) ) dp[i+1][l] = max(dp[i+1][l] , dp[i][l] + na*abs(nind-r) ) print (max(dp[N]))
1
33,901,654,359,872
null
171
171
import math import numpy as np n,k=(int(x) for x in input().split()) a = [int(x) for x in input().split()] for _ in range(k): new_a = np.zeros(n+1,dtype=int) np.add.at(new_a, np.maximum(0,np.arange(0, n)-a), 1) np.add.at(new_a, np.minimum(n,np.arange(0, n)+a+1), -1) a = new_a.cumsum()[:-1] if np.all(a==n): break print(" ".join([str(x) for x in a]))
import statistics import math N = int(input()) A_B = [[int(i) for i in input().split(' ')] for n in range(N)] t = list(zip(*A_B)) A_sta = statistics.median(t[0]) B_sta = statistics.median(t[1]) if N % 2 == 0: count = int(2 * (B_sta - A_sta) + 1) else: count = B_sta - A_sta + 1 print(count)
0
null
16,263,650,828,108
132
137
n = int(input()) l = list(map(int,input().split())) l.sort(reverse = True) ans = 0 for i in range(len(l)): for j in range(i+1,len(l)): for k in range(j+1,len(l)): if l[i] != l[j] != l[k] and l[i] < l[j] + l[k]: ans +=1 print(ans)
for num1 in range(1,10): for num2 in range(1,10): i = num1 * num2 print(str(num1) + "x" + str(num2) + "=" + str(i))
0
null
2,485,060,977,810
91
1
n, m = map(int, input().split()) a = list(map(int, input().split())) dp = [float('inf') for _ in range(n+1)] dp[0] = 0 for i in range(n): for money in a: next_money = i + money if next_money > n: continue dp[next_money] = min(dp[i] + 1, dp[next_money]) print(dp[n])
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 15 6 1 2 7 8 12 50 output: 2 """ import sys def solve(): rec[0] = 0 for i in range(c_num): for j in range(money - coins[i] + 1): rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1) return rec if __name__ == '__main__': _input = sys.stdin.readlines() money, c_num = map(int, _input[0].split()) coins = list(map(int, _input[1].split())) assert len(coins) == c_num rec = [float('inf')] * (money + 1) ans = solve() print(ans[-1])
1
138,252,958,272
null
28
28
N = int(input()) A = list(map(int, input().split())) sumlow = 0 sumhigh = 0 i = 0 j = N-1 while i<=j: if sumlow <= sumhigh: sumlow += A[i] i += 1 else: sumhigh += A[j] j -= 1 print(abs(sumlow-sumhigh))
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) def gcd(*numbers): reduce(math.gcd, numbers) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 count = 0 ans = 0 N = k() A = l() S = sum(A) minx = S sum = 0 for x in A: sum += x minx = min(minx, abs(sum-(S-sum))) print(minx)
1
142,600,879,652,102
null
276
276
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): s = S() ans = 0 for i in range(len(s)//2): if s[i] != s[-(i+1)]: ans += 1 print(ans) main()
n = int(input()) a = [int(i)-1 for i in input().split()] ans = 0 for i in range(n): if a[i] != (i - ans): ans += 1 print(ans if ans != n else -1)
0
null
117,436,263,550,620
261
257
from collections import defaultdict N, K, *A = map(int, open(0).read().split()) x = [0] * (N + 1) for i in range(N): x[i + 1] = x[i] + A[i] y = [(x[i] - i) % K for i in range(N + 1)] ctr = defaultdict(int) ans = 0 for j in range(N + 1): ans += ctr[y[j]] ctr[y[j]] += 1 if j - K + 1 >= 0: ctr[y[j - K + 1]] -= 1 print(ans)
#!/usr/bin/env python3 #ABC146 E import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) """ S := aの累積和 (Sj - Si) % k = j - i ある整数mに対して Sj - Si = m*k + j - i Sj - j = m*k + Si - i (Sj - j) - (Si - i) Ξ 0 (mod k) (Sj - j) Ξ (Si - i) (mod k) """ n,k = LI() a = LI() s = [0] + list(accumulate(a)) ans = 0 d = defaultdict(int) for j in range(n+1): t = (s[j] - j) % k if j >= k: x = (s[j-k] - (j-k)) % k d[x] -= 1 ans += d[t] d[t] += 1 print(ans)
1
137,655,896,582,232
null
273
273
from collections import deque N = int(input()) # mtx = np.zeros([N, N], dtype=np.int32) tree = [[] for i in range(N)] key_order = [0] * (N-1) for i in range(N-1): in1, in2 = map(int, input().split()) in1 -= 1 in2 -= 1 tree[in1].append(in2) tree[in2].append(in1) key_order[i] = (in1, in2) # [print(i, t) for i, t in enumerate(tree)] def bfs(tree, p): seen = [False] * len(tree) queue = deque((p,)) edge_colors = dict() node_colors = [0] * len(tree) while len(queue) > 0: q = queue.popleft() seen[q] = True parent_color = node_colors[q] cnt = 1 for v in tree[q]: if not seen[v]: if cnt == parent_color: cnt += 1 edge_colors[(q, v)] = cnt node_colors[v] = cnt queue.append(v) cnt += 1 """ node_colors = [set() for _ in tree] edge_colors = dict() all_colors = set() color = 0 while len(queue) > 0: q = queue.popleft() seen[q] = True for v in tree[q]: if not seen[v]: residual = all_colors - node_colors[q] if len(residual) > 0: this_color = residual.pop() else: color += 1 this_color = color edge_colors[(q, v)] = this_color node_colors[q].add(this_color) node_colors[v].add(this_color) all_colors.add(this_color) queue.append(v) """ return edge_colors edge_colors = bfs(tree, 0) print(max([c for key, c in edge_colors.items()])) [print(edge_colors[t]) for t in key_order] # print(edge_colors) # show_tree(tree)
def get(n): for i in range(-1000,1001): for j in range(-1000,1001): if(i**5-j**5==n): print(i,j) return n=int(input()) get(n)
0
null
80,701,029,963,070
272
156
# AOJ ITP1_10_D import math def intinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def main(): n = int(input()) x = intinput() y = intinput() sum_1 = 0 sum_2 = 0 sum_3 = 0 MD_INFTY = 0 for i in range(n): MD_INFTY = max(MD_INFTY, abs(x[i] - y[i])) sum_1 += abs(x[i] - y[i]) sum_2 += abs(x[i] - y[i]) ** 2 sum_3 += abs(x[i] - y[i]) ** 3 MD_1 = sum_1 MD_2 = math.sqrt(sum_2) MD_3 = sum_3 ** (1 / 3) print(MD_1); print(MD_2); print(MD_3); print(float(MD_INFTY)) if __name__ == "__main__": main()
import math x1, y1, x2, y2 = map(float, input().split()) x = abs(x1 - x2) y = abs(y1 - y2) ans = math.sqrt(x**2 + y**2) print('{:.5f}'.format(ans))
0
null
181,093,547,958
32
29
N = int(input()) mod = 10 ** 9 +7 x = (10**N)%mod y = (2*(9**N))%mod z = (8**N)%mod print((x-y+z)%mod)
def main(): S = input().rstrip() print("x" * len(S)) if __name__ == '__main__': main()
0
null
37,929,617,616,198
78
221
import math a, b, x = map(int, input().split()) x /= a if a * b >= x * 2: c = x * 2 / b print(math.degrees(math.atan2(b, c))) else: c = (a * b - x) * 2 / a print(math.degrees(math.atan2(c, a)))
#k = int(input()) #s = input() #a, b = map(int, input().split()) #l = list(map(int, input().split())) x = int(input()) yokin = 100 for i in range(1, 100000000000): yokin *= 101 yokin = yokin //100 if (yokin >= x): print(i) break
0
null
94,863,085,882,324
289
159
n,a,b = map(int, input().split()) if (b-a)%2==0: print((b-a)//2) else: print(min(a-1, n-b)+ 1 + (b-a-1)//2)
n,a,b = map(int,input().split()) if (a+b) % 2 == 0: print(b - (a+b)//2) else: if a <= n-b+1: b -= a print(a + b-(1+b)//2) else: a += n-b+1 print(n-b+1 + n - (n+a)//2)
1
109,554,005,767,072
null
253
253
N=int(input()) S=input() while True: x='' ans='' for i in S: if (x==''): x=i continue if x!=i: #print("p:",x,i,ans) ans+=x x=i #print("a:",x,i,ans) ans+=x #print('ans:',ans) if ans==S: break else: S=ans print(len(ans))
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline import itertools from collections import Counter def main(): n = int(input()) s = input().rstrip() ans = [s[0]] now = s[0] for i in s[1:]: if i != now: ans.append(i) now = i print(len(ans)) if __name__=="__main__": main()
1
169,938,930,514,702
null
293
293
n = int(input()) x = input().split() y = input().split() import math for i in range(4): D = 0 for j in range(n): if i != 3: D = D + math.pow(math.fabs(int(x[j]) - int(y[j])),i+1) else: compare = math.fabs(int(x[j]) - int(y[j])) if D < compare: D = compare if i != 3: print('{0:.6f}'.format(math.pow(D,1/(i+1)))) else: print('{0:.6f}'.format(D))
def dist(x,y,p): tmp = 0 for k,j in zip(x,y): k,j = sorted((k,j)) tmp += (j-k)**p print tmp**(1/float(p)) def cheb(x,y): maxjk = None for k,j in zip(x,y): k,j = sorted((k,j)) if maxjk is None: maxjk = j-k elif j-k > maxjk: maxjk = j-k print float(maxjk) n = int(raw_input()) x = map(int,raw_input().split()) y = map(int,raw_input().split()) dist(x,y,1) dist(x,y,2) dist(x,y,3) cheb(x,y)
1
212,323,631,260
null
32
32
r, g, b = [int(x) for x in input().split()] ops = int(input()) m = 0 while g <= r: g *= 2 m += 1 while b <= g: b *= 2 m += 1 print("Yes" if m <= ops else "No")
n,m=map(int,input().split()) ac=[0]*n wa=[0]*n acc,wac=0,0 for i in range(m): p,s=input().split() p=int(p) if ac[p-1]==1: continue else: if s=="AC": ac[p-1]=1 else: wa[p-1]+=1 for i in range(n): if ac[i]==1: acc+=1 wac+=wa[i] print(acc,wac)
0
null
49,954,589,021,220
101
240
#!usr/bin/env python3 def main(): while True: numbers = input() if int(numbers) == 0: break res = 0 for i in numbers: res += int(i) print(res) if __name__ == '__main__': main()
def solve(): s = input() n = len(s) if n%2 == 1: print("No") else: tmp = "hi"*(n//2) if s == tmp: print("Yes") else: print("No") solve()
0
null
27,321,151,108,832
62
199
from collections import defaultdict N, u, v = map(int, input().split()) d = defaultdict(list) for _ in range(N-1): A, B = map(int, input().split()) d[A].append(B) d[B].append(A) def get_dist(s): dist = [-1]*(N+1) dist[s] = 0 q = [s] while q: a = q.pop() for b in d[a]: if dist[b]!=-1: continue dist[b] = dist[a] + 1 q.append(b) return dist du, dv = get_dist(u), get_dist(v) ds = [(i,j[0], j[1]) for i,j in enumerate(zip(du, dv)) if j[0]<j[1]] ds.sort(key=lambda x:-x[2]) a, b, c = ds[0] print(c-1)
n, u, v = map(int, input().split()) u, v = u-1, v-1 edges = [[] for i in range(n)] for i in range(n-1): ai, bi = map(int, input().split()) ai, bi = ai-1, bi-1 edges[ai].append(bi) edges[bi].append(ai) depth = 0 already = [0 for i in range(n)] already[v] = 1 nodes = [v] while nodes != []: depth += 1 next_nodes = [] for node in nodes: children = edges[node] for child in children: if already[child] == 0: already[child] = depth next_nodes.append(child) nodes = next_nodes already[v] = 0 depth = 0 already_u = [0 for i in range(n)] already_u[u] = 1 nodes = [u] while nodes != []: depth += 1 next_nodes = [] for node in nodes: children = edges[node] for child in children: if already_u[child] == 0: already_u[child] = depth next_nodes.append(child) nodes = next_nodes already_u[u] = 0 maxi = 0 for i in range(n): if already_u[i] < already[i]: maxi = max(maxi, already[i]) print(maxi-1)
1
117,111,539,778,528
null
259
259
# -*- coding: utf-8 -*- import itertools N, K = map(int, input().split()) a = [0] * (N+1) for i in range(N+1): a[i] = i max_total = 0 min_total = 0 ans = 0 for k in range(K, N+2): # 和の最大(10**100 は無視): 大きい順にk個選んだ場合 max_total = k * ((N-k+1) + N) // 2 # 和の最小(10**100 は無視): 小さい順にk個選んだ場合 min_total = k * (0 + (k-1)) // 2 # 最小と最大の間は全パターン取り得るので差が個数になる ans += (max_total - min_total + 1) print(ans % (10**9 + 7))
n = int(input()) S = [int(i) for i in input().split()] q = int(input()) T = [int(i) for i in input().split()] cnt = 0 for T in T: if T in S: cnt += 1 print(cnt)
0
null
16,503,582,934,428
170
22
import sys def Ii():return int(sys.stdin.readline()) def Mi():return map(int,sys.stdin.readline().split()) def Li():return list(map(int,sys.stdin.readline().split())) n = Ii() a = Li() b = 0 for i in range(n): b ^= a[i] ans = [] for i in range(n): print(b^a[i],end=' ')
n=int(input()) l=[] lis=[] for _ in range(n): a=int(input()) l.append(a) li=[] for _ in range(a): c,d=map(int,input().split()) li.append([c,d]) lis.append(li) ans=-1 for i in range(2**n-1,-1,-1): mark=bin(i)[2:] mark=(n-len(mark))*'0'+mark s=0 record=[-1]*n f=1 for j in range(n): for k in range(l[j]): number=lis[j][k][0]-1 hou=lis[j][k][1] if int(mark[j])==1: if record[number]==-1: record[number]=hou elif record[number]!=hou:f=0 if f==0:break if f == 0: break if f==1: F=True for i in range(n): if record[i]!=-1: if record[i]!=int(mark[i]): F=False break if F==True: print(mark.count('1')) exit()
0
null
67,021,254,094,014
123
262
import math N = int(input()) digit = math.ceil(math.log((25 * N / 26 + 1), 26)) alphabet = list("abcdefghijklmnopqrstuvwxyz") name = [] for i in range(digit): name.append((N % 26 - 1) % 26) N = (N - (N % 26 - 1) % 26) // 26 name.reverse() print("".join([alphabet[s] for s in name]))
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): N = I() s = 'abcdefghijklmnopqrstuvwxyz' assert len(s) == 26 cur = [] while N > 0: amari = N % 26 if amari == 0: amari += 26 cur.append(s[amari-1]) N -= amari N //= 26 print(''.join(cur[::-1])) main()
1
11,817,270,553,748
null
121
121
k,x=map(int,input().split());print('YNeos'[500*k<x::2])
def main(): K, X = map(int, input().split()) if 500 * K >= X: ans = "Yes" else: ans = "No" print(ans) if __name__ == "__main__": main()
1
98,289,545,726,402
null
244
244
W = input().upper() T = [] while True: t = input() if t == "END_OF_TEXT": break T += [x.upper() for x in t.split()] print(T.count(W))
w = raw_input().lower() s = 0 while 1: in_str = raw_input() if in_str == "END_OF_TEXT": break in_str = map(str, in_str.split()) for i in in_str: if i.lower() == w: s+=1 print s
1
1,815,770,355,278
null
65
65
# your code goes here #dice2 def np(dl,nu): l=0 while dl[l]!=nu: l+=1 return l def si(n1,n2): if n1==1: if n2==2: return 3 elif n2==3: return 5 elif n2==4: return 2 else: return 4 elif n1==2: if n2==1: return 4 elif n2==3: return 1 elif n2==4: return 6 else: return 3 elif n1==3: if n2==2: return 6 elif n2==5: return 1 elif n2==1: return 2 else: return 5 elif n1==4: if n2==1: return 5 elif n2==2: return 1 elif n2==5: return 6 else: return 2 elif n1==5: if n2==1: return 3 elif n2==3: return 6 elif n2==4: return 1 else: return 4 elif n1==6: if n2==3: return 2 elif n2==2: return 4 elif n2==5: return 3 else: return 5 D=[int(i) for i in input().split()] q=int(input()) for i in range(q): n=[int(i) for i in input().split()] # print(n) p=[] for j in range(2): p.append(np(D,n[j])) # print(p) print(D[si(p[0]+1,p[1]+1)-1])
N = int(input()) ans = [0 for _ in range(N+1)] for x in range(1, 101): for y in range(x, 101): for z in range(y, 101): v = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x if v < N+1: if x == y == z: ans[v] += 1 elif x == y or x == z or z == y: ans[v] += 3 else: ans[v] += 6 for i in range(1,N+1): print(ans[i])
0
null
4,098,901,325,050
34
106
import sys input = sys.stdin.readline n, k = map(int,input().split()) A = list(map(int,input().split())) S = [A[0] % k] for i in range(1, n): S.append((A[i]+S[-1]) % k) # print(S) D = {} S = [0] + S ans = 0 for i in range(len(S)): key = (S[i] - i) % k if i >= k: j = i-k key1 = (S[j] - j) % k D[key1] -= 1 try: ans += D[key1] # print(i, j, D[key1]) except: ans += 0 try: D[key] += 1 except: D[key] = 1 for j in range(max(0, len(S)-k), len(S)): key1 = (S[j] - j) % k D[key1] -= 1 try: ans += D[key1] # print(i, j, D[key1]) except: ans += 0 # print(D) print(ans)
# coding: utf-8 # Your code here! while(1): H,W=map(int,input().split(" ")) if H==0 and W==0: break for i in range(H): for j in range(W): if (i+j)%2==0: print("#",end="") else: print(".",end="") print("") print("")
0
null
68,897,590,973,136
273
51
n,k=map(int,input().split()) DIV = 10**9+7 count = 0 for i in range(k,n+2): min_k = i*(i-1)/2 max_k = i*(2*n-i+1)/2 count += max_k - min_k + 1 print(int(count % DIV))
c = str(input()) a = 'abcdefghijklmnopqrstuvwxyz' for i, letter in enumerate(a): if c == letter: ans = a[i+1] print(ans)
0
null
62,896,167,910,060
170
239
n = int(input()) state10 = 1 state9 = 1 state8 = 1 mod = 10**9 + 7 for _ in range(n): state10 *= 10 state10 %= mod state9 *= 9 state9 %= mod state8 *= 8 state8 %= mod ans = state10 - 2*state9 + state8 ans %= mod print(ans)
n = int(input()) print(((10 ** n) % (10 ** 9 + 7) - (9 ** n) % (10 ** 9 + 7) - (9 ** n) % (10 ** 9 + 7) + (8 ** n) % (10 ** 9 + 7)) % (10 ** 9 + 7))
1
3,176,241,930,510
null
78
78
def modinv(a, m): b = m u = 1 v = 0 while b: t = a // b a -= t * b a, b = b, a u -= t * v u, v = v, u u %= m if u < 0: u += m return u def nCk(N, k, mod): ret_val = 1 for i in range(k): ret_val *= (N - i) ret_val %= mod ret_val *= modinv(i + 1, mod) ret_val %= mod return ret_val n, a, b = map(int, input().split()) MOD = 10 ** 9 + 7 all_cnt = pow(2, n, MOD) - 1 a_cnt = nCk(n, a, MOD) b_cnt = nCk(n, b, MOD) ans = all_cnt - a_cnt - b_cnt print(ans % MOD)
MOD = pow(10, 9) + 7 def modinv(a, mod): return pow(a, mod - 2, mod) % mod def comb(n, r, mod): r = min(r, n - r) res = 1 for i in range(r): res = res * (n - i) % mod res = res * modinv(i + 1, mod) % mod return res n, a, b = map(int, input().split()) ans = (pow(2, n, MOD) - 1 - comb(n, a, MOD) - comb(n, b, MOD)) % MOD print(ans)
1
66,338,377,180,740
null
214
214
#coding:utf-8 #1_5_B 2015.4.1 while True: length,width = map(int,input().split()) if length == width == 0: break print('#' * width) print(('#' + '.' * (width - 2) + '#\n') * (length - 2),end='') print('#' * width) print()
while True: H, W = map(int, input().split()) if not(H or W): break for j in range(W): print('#', end='') print() for i in range(H-2): print('#', end='') for j in range(W-2): print('.', end='') print('#') for j in range(W): print('#', end='') print('\n')
1
815,566,597,108
null
50
50
N=int(input()) K=set(input().split()) i=len(K) if i==N: print('YES') else: print('NO')
n = int(input()) X = list(map(int,input().split())) Y = list(map(int,input().split())) # p=1,2,3 for p in range(1,4): print("{0:.6f}".format(sum([abs(a-b)**p for a,b in zip(X,Y)])**(1/p))) # p=infinity print("{0:.6f}".format(max([abs(a-b) for a,b in zip(X,Y)])))
0
null
36,872,736,242,340
222
32
import collections, copy h, w = map(int, input().split()) maze = [] maze.append("#" * (w + 2)) for i in range(h): maze.append("#" + input() + "#") maze.append("#" * (w + 2)) dis = [] for i in range(h + 2): temp = [-1] * (w + 2) dis.append(temp) def search(x, y): dis2 = copy.deepcopy(dis) move = [[-1, 0], [1, 0], [0, 1], [0, -1]] queue = collections.deque([[x, y]]) dis2[x][y] = 0 while queue: test = queue.popleft() for i in move: place = [test[0] + i[0], test[1] + i[1]] if maze[place[0]][place[1]] == ".": if dis2[place[0]][place[1]] == -1: dis2[place[0]][place[1]] = dis2[test[0]][test[1]] + 1 queue.append(place) return max([max([dis2[i][j] for j in range(w + 2)]) for i in range(h + 2)]) ans = 0 for i in range(h): for j in range(w): if maze[i + 1][j + 1] == ".": dist = search(i + 1, j + 1) ans = max(ans, dist) print(ans)
from collections import deque import copy H,W=map(int,input().split()) inf=1000000000 field=[] for i in range(H): row=list(input()) for j in range(len(row)): if row[j]=='#':row[j]=-1 else:row[j]=inf field.append(row) ans=inf def isIn(x,y): if x<0 or x>=W:return False if y<0 or y>=H:return False return True vector=[[0,1],[0,-1],[1,0],[-1,0]] ans=0 for i in range(H): for j in range(W): if field[i][j]==-1:continue l=deque([[j,i]]) f=copy.deepcopy(field) f[i][j]=0 tmp=0 #print('--start--') while l: x,y=l.popleft() #print(x,y) #i,jを訪問 for v in vector: if not isIn(x+v[1],y+v[0]):continue if f[y+v[0]][x+v[1]]<=tmp:continue f[y+v[0]][x+v[1]]=f[y][x]+1 l.append([x+v[1],y+v[0]]) tmp=max(f[y+v[0]][x+v[1]],tmp) ans=max(ans,tmp) print(ans)
1
94,659,813,369,030
null
241
241
import math a = float(input()) print(2*a*math.pi)
import math x = math.pi r = int(input()) x = 2*x*r print(x)
1
31,240,677,319,830
null
167
167
import sys #input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode() #import numpy as np def main(): n,k=MI() p=LI() for i in range(n): p[i]=p[i]/2+0.5 #print(p) ans=sum(p[:k]) now=sum(p[:k]) for i in range(n-k): now=now-p[i]+p[i+k] ans=max(ans,now) print(ans) if __name__ == "__main__": main()
a,b = list(map(int, input().split())) if a <= b * 2: print(0) else: print(a - b * 2)
0
null
120,394,405,338,580
223
291
import itertools A,B,C=map(int,input().split()) K=int(input()) l=list(range(K+1)) for c in itertools.product(l, repeat=3): if sum(c) == K and A*2**c[0]<B*2**c[1] and B*2**c[1]<C*2**c[2]: print("Yes") exit(0) print("No")
a,b,c = map(int, input().split()) k = int(input()) for i in range(k): if a >= b: b *= 2 continue if b >= c: c *= 2 continue print("Yes" if a < b and b < c else "No")
1
6,893,434,199,300
null
101
101
n,m = map(int,input().split()) A = list(map(int,input().split())) judge = sum(A) / (4 * m) ans = [] for i in range(n): if A[i] < judge : continue else: ans.append(A[i]) print("Yes") if len(ans) >= m else print("No")
def main(): n,m = map(int, input().split()) a = sorted(list(map(int, input().split())),reverse = True) all = sum(a) cnt = 0 for i in(a): if(i * 4 * m >= all and cnt < m): cnt += 1 if cnt >= m: print('Yes') else: print('No') main()
1
38,521,520,453,042
null
179
179
from collections import Counter N = int(input()) A = list(map(int, input().split())) L = [a+i for a, i in enumerate(A, 1)] R = [a-i for a, i in enumerate(A, 1)] ans = 0 R_c = Counter(R) for l in L: ans += R_c[l] print(ans)
def main(): a, b, c, d = map(int, input().split()) print(max(a*c, b*d, a*d, b*c)) main()
0
null
14,441,708,631,652
157
77
N = int(input()) A_li = list(map(int, input().split())) is_rising = False money = 1000 stock = 0 for i in range(N - 1): if i == 0: if A_li[0] < A_li[1]: # できるだけ買う stock = money // A_li[0] money -= A_li[0] * stock is_rising = True else: if is_rising: if A_li[i] > A_li[i + 1]: # 全て売る money += A_li[i] * stock stock = 0 is_rising = False else: if A_li[i] < A_li[i + 1]: # できるだけ買う stock = money // A_li[i] money -= A_li[i] * stock is_rising = True if i + 1 == N - 1: # 全て売って終了 money += A_li[i+1] * stock stock = 0 print(money)
n, m = list(map(int, input().split())) A = [] V = [] B = [] for i in range(n): A.append(list(map(int, input().split()))) for j in range(m): V.append([int(input())]) for i in range(n): B.append([0]) for j in range(m): B[i][0] += A[i][j] * V[j][0] for i in range(n): print(B[i][0])
0
null
4,265,693,916,692
103
56
def popcount(x): c = 0 while x > 0: if x & 1: c += 1 x //= 2 return c def f(x): if x==0: return 0 return f(x % popcount(x)) + 1 n = int(input()) X = input() po = X.count('1') pp = po + 1 pm = max(1, po - 1) rp = rm = 0 for x in X: rp = (rp*2 + int(x)) % pp rm = (rm*2 + int(x)) % pm bp = [0]*(n) # 2^i % (po+1) bm = [0]*(n) # 2^i % (po-1) bp[n-1] = 1 % pp bm[n-1] = 1 % pm for i in range(n-1, 0, -1): bp[i-1] = bp[i]*2 % pp bm[i-1] = bm[i]*2 % pm for i in range(n): if X[i] == '0': ri = (rp + bp[i]) % pp else: if po-1 != 0: ri = (rm - bm[i]) % pm else: print(0) continue print(f(ri) + 1)
N = int(input()) X = input() cnt = X.count('1') if cnt == 1: for x in X[:-1]: if x == '0': print(1) else: print(0) if X[-1] == '1': print(0) else: print(2) exit() M = 0 for x in X: M <<= 1 if x == '1': M += 1 def solve(n): ret = 1 while n > 0: ret += 1 n %= bin(n).count('1') return ret ans = [] p = M % (cnt + 1) m = M % (cnt - 1) for i in range(N): if X[i] == '0': ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1))) else: ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1))) print(*ans, sep='\n')
1
8,206,630,115,190
null
107
107
def rally(arr): p = max(arr) summ = 0 best = float('inf') for i in range(1, p+1): summ = 0 for j in arr: summ += (j - i) ** 2 best = min(best, summ) return best n = int(input()) arr = list(map(int, input().split())) print(rally(arr))
a = 0 b = 0 N = int(input()) X = list(map(int, input().split())) avg = sum(X) // N for tai in X: a += (tai - avg) ** 2 for tai in X: b += (tai - (avg + 1)) ** 2 if a > b : print(b) else : print(a)
1
65,140,535,636,018
null
213
213
from math import ceil n=int(input()) money=100000 for i in range(n): money=ceil(money*1.05/1000)*1000 print(money)
def debt(x): nx = x * 105 / 100 ha = nx % 1000 nx -= ha if ha != 0: nx += 1000 return nx n = int(raw_input()) x = 100000 for i in range(0, n): x = debt(x) print x
1
1,241,542,920
null
6
6
n = int(input()) al = list(map(int,input().split())) kabu = 0 money = 1000 for i in range(n-1): if al[i] < al[i+1]: # 全部売る money += kabu * al[i] kabu = 0 # 全部買う kabu += money // al[i] money = money % al[i] else: # 全部売る money += kabu * al[i] kabu = 0 print(money+ kabu*al[-1])
l=input() if l.lower()==l: print('a') else: print('A')
0
null
9,301,601,295,830
103
119
a,b=input().split() print(-1 if len(a)>1 or len(b)>1 else int(a)*int(b))
import sys def input(): return sys.stdin.readline()[:-1] def main(): A, B, C = map(int,input().split()) K = int(input()) count = 0 while A >= B: B = B * 2 count += 1 while B >= C: C = C * 2 count += 1 if count <= K: print("Yes") else: print("No") if __name__ == "__main__": main()
0
null
82,253,630,605,380
286
101
#!/usr/bin/env python3 def main(): from collections import deque N, M, K = map(int, input().split()) friends = [set() for _ in range(N + 1)] for _ in range(M): a, b = map(int, input().split()) friends[a].add(b) friends[b].add(a) blocks = [set() for _ in range(N + 1)] for _ in range(K): c, d = map(int, input().split()) blocks[c].add(d) blocks[d].add(c) friends_chain = [] seen = [-1] * (N + 1) cnt = 0 for person in range(1, N + 1): if seen[person] != -1: continue q = deque([person]) friends_chain.append(set(q)) while q: now = q.pop() seen[now] = cnt for next in friends[now]: if seen[next] != -1: continue friends_chain[-1].add(next) q.append(next) cnt += 1 for person in range(1, N + 1): res = friends_chain[seen[person]] tmp_ans = len(res) - len(friends[person]) - 1 for block in blocks[person]: tmp_ans -= 1 if block in res else 0 print(tmp_ans, end=' ') if __name__ == '__main__': main()
def makeRelation(): visited=[False]*(N+1) g=0 # group for n in range(1,N+1): if visited[n]: continue q={n} D.append(set()) while q: j=q.pop() for i in F[j]: # search for friend if not visited[i]: visited[i]=True q.add(i) D[g]|={i} g+=1 def main(): makeRelation() #print(D) for g in D: for d in g: ans[d]=len(g) - len(F[d]) - len(g&B[d]) - 1 print(*ans[1:]) if __name__=='__main__': N, M, K = map(int, input().split()) F=[set() for n in range(N+1)] AB=[list(map(int, input().split())) for m in range(M)] for a,b in AB: F[a].add(b) F[b].add(a) B=[set() for n in range(N+1)] CD=[list(map(int, input().split())) for k in range(K)] for c,d in CD: B[c].add(d) B[d].add(c) D=[] #print(F) #print(B) ans=[0]*(N+1) main()
1
61,516,986,363,168
null
209
209
import bisect import collections N,K=map(int,input().split()) A=list(map(int,input().split())) A.insert(0,0) cuml=[0]*(N+1) cuml[0]=A[0] l=[] cuml2=[] l2=[] buf=[] ans=0 for i in range(N): cuml[i+1]=cuml[i]+A[i+1] #print(cuml) for i in range(N+1): cuml2.append([(cuml[i]-i)%K,i]) cuml[i]=(cuml[i]-i)%K #print(cuml2,cuml) cuml2.sort(key=lambda x:x[0]) piv=cuml2[0][0] buf=[] for i in range(N+1): if piv!=cuml2[i][0]: l2.append(buf) piv=cuml2[i][0] buf=[] buf.append(cuml2[i][1]) l2.append(buf) #print(l2) cnt=0 for i in range(len(l2)): for j in range(len(l2[i])): num=l2[i][j] id=bisect.bisect_left(l2[i], num + K) #print(j,id) cnt=cnt+(id-j-1) print(cnt)
from itertools import accumulate from collections import defaultdict n, k = map(int, input().split()) a = list(map(int, input().split())) acc = [0] + list(accumulate(a)) sm = [(e - i) % k for i, e in enumerate(acc)] d = defaultdict(int) ans = 0 for r in range(1, n + 1): if r - k >= 0: e = sm[r - k] d[e] -= 1 e = sm[r - 1] d[e] += 1 e = sm[r] ans += d[e] print(ans)
1
137,570,377,569,788
null
273
273
target = input() now_height = [] now_area = [0] answer = [] continued = 0 depth = 0 depth_list = [] for t in target: # print(now_height,depth_list,now_area,answer,continued) if t == '\\': now_height.append(continued) depth_list.append(depth) now_area.append(0) depth -= 1 elif t == '_': pass elif t == '/' and len(now_height) > 0: depth += 1 started = now_height.pop() temp_area = continued - started # print(depth_list[-1],depth) now_area[-1] += temp_area if depth > depth_list[-1]: while depth > depth_list[-1]: temp = now_area.pop() now_area[-1] += temp depth_list.pop() if len(now_height) == 0 or depth == depth_list[0]: answer.append(sum(now_area)) now_area = [0] depth_list = [] continued += 1 now_area = list(filter(lambda x:x != 0,now_area)) answer.extend(now_area) print(sum(answer)) print(len(answer),*answer)
S = list(input()) N = len(S) S_1=S[:N//2] S_2=S[N//2+1:] N_=len(S_1) ans='Yes' for n in range(N_): if S_1[n] != S_1[-(n+1)]: ans='No' break if S_2[n] != S_2[-(n+1)]: ans='No' break for n in range(N): if S[n] != S[-(n+1)]: ans='No' break print(ans)
0
null
23,256,864,445,132
21
190