code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
def solve(a, b, c, k): for i_a in range(k+1): for i_b in range(k+1): for i_c in range(k+1): if i_a + i_b + i_c > k: break x = a * (2**i_a) y = b * (2**i_b) z = c * (2**i_c) if x < y < z: return "Yes" return "No" a, b, c = map(int, input().split()) k = int(input()) print(solve(a, b, c, k))
a, b, c = map(int, input().split()) k = int(input()) flg = False c = (2**k) * c for i in range(k): if a < b < c: flg = True break b *= 2 c //= 2 if flg: print('Yes') else: print('No')
1
6,993,864,048,258
null
101
101
n = int(input()) ans = 0 for i in range(1, n + 1): if i % 3 != 0 and i % 5 != 0: ans += i else: continue print(ans)
n=int(input()) result=0 for i in range(n+1): if (i%3)!=0 and (i%5)!=0: result+=i print(result)
1
34,881,235,435,042
null
173
173
N, M=map(int, input().split()) g = [[] for _ in range(N+1)] for _ in range(M): a, b = [int(x) for x in input().split()] g[a].append(b) g[b].append(a) from collections import deque queue=deque([1]) d=[None]*(N+1) d[1]=0 ans=[0]*(N+1) while queue: v=queue.popleft() for i in g[v]: if d[i] is None: d[i]=d[v]+1 ans[i]=v queue.append(i) print("Yes") for i in range(2,len(ans)): print(ans[i])
from collections import* (n,m),*c = [[*map(int,i.split())]for i in open(0)] g = [[]for _ in range(n+1)] for a,b in c: g[a]+=[b] g[b]+=[a] q=deque([1]) r=[0]*(n+1) while q: v=q.popleft() for i in g[v]: if r[i]==0: r[i]=v q.append(i) print("Yes",*r[2:],sep="\n")
1
20,586,837,419,172
null
145
145
def ok(p, ws, n, k): track = 1 now = 0 for i in range(n): if ws[i] > p: return False if now + ws[i] > p: track += 1 now = ws[i] else: now += ws[i] if track > k: return False else: return True nk = input().split() n = int(nk[0]) k = int(nk[1]) ws = [] for _ in range(n): ws.append(int(input())) p_min = 0 p_max = int(1e+10) while p_min < p_max: p = (p_min + p_max) // 2 if ok(p, ws, n, k): p_max = p else: p_min = p + 1 print(p_max)
def my_pow(base, n, mod): if n == 0: return 1 x = base y = 1 while n > 1: if n % 2 == 0: x *= x n //= 2 else: y *= x n -= 1 x %= mod y %= mod return x * y % mod N = int(input()) D = list(map(int, input().split())) dmax = max(D) MOD = 998244353 cnt = [0] * (10 ** 5 + 1) for d in D: cnt[d] += 1 if D[0] or cnt[0] != 1: print(0) exit() ans = cnt[0] for i in range(1, dmax + 1): now = my_pow(cnt[i - 1], cnt[i], MOD) ans *= now ans %= MOD print(ans)
0
null
77,796,754,136,512
24
284
N, K = [int(i) for i in input().split(" ")] N = N % K if (K - N) < N: N = K - N print(N)
import math def modcomb(n, k, mod, fac, ifac): x = fac[n] y = ifac[n-k] * ifac[k] % mod #print(x * y % mod) return x * y % mod def makeTables(n, mod): fac = [1, 1] ifac = [1, 1] inv = [0, 1] for i in range(2, n+1): fac.append(i * fac[i-1] % mod) inv.append(-inv[mod % i] * (mod // i) % mod) ifac.append(inv[i] * ifac[i-1] % mod) return fac, ifac def answer(n, k, mod, fac, ifac): if k >= n: k = n - 1 ans = 0 for i in range(k+1): c = modcomb(n, i, mod, fac, ifac) * modcomb(n-1, i, mod, fac, ifac) % mod ans = (ans + c) % mod return ans n, k = map(int, input().split()) mod = 1000000007 fac, ifac = makeTables(n, mod) print(answer(n, k, mod, fac, ifac))
0
null
52,958,000,521,220
180
215
N = int(input()) a = list(map(int, input().split())) Xsum = 0 for i in a: Xsum = Xsum ^ i ans = list() for i in a: s = Xsum ^ i # print(s) ans.append(str(s)) print(' '.join(ans))
n = int(input()) a = list(map(int,input().split())) sum = 0 ans = 0 for i in range(n): sum += a[i] for i in range(n-1): sum -= a[i] ans += a[i] * sum print(ans % (10**9 + 7))
0
null
8,165,206,680,400
123
83
N, *AB = map(int, open(0).read().split()) A = sorted(a for a in AB[::2]) B = sorted(b for b in AB[1::2]) if N % 2: print(B[N // 2] - A[N // 2] + 1) else: print(B[N // 2 - 1] + B[N // 2] - A[N // 2 - 1] - A[N // 2] + 1)
# Problem E - Dividing Chocolate # input H, W, K = map(int, input().split()) board = [['']*W for i in range(H)] for i in range(H): s = list(input()) for j in range(W): board[i][j] = s[j] # initialization min_divide = 10**10 s = [0]*(H-1) # 横線の入り方 0:無 1:有 is_ok = True # search for i in range(2**(H-1)): # bit全探索 # sの初期化 h_count = 0 w_count = 0 for j in range(H-1): if ((i>>j)&1): s[j] = 1 h_count += 1 else: s[j] = 0 # 列の全探索 s_score = [0]*H # 各区域のスコア s_cur = [0]*H for j in range(W): c = 0 s_cur = [0]*H for k in range(H): if board[k][j]=='1': s_cur[c] += 1 # Kを超えていないかのチェック if s_cur[c]>K: is_ok = False break # 次の遷移先(横線の有無でグループが別れる) if k+1<H: if s[k]==1: c += 1 # Kを超えていたらループ中止 if not is_ok: break # 前の列のグループと足してみてKを超えていないかチェック # 超えていれば縦線分割を施す group_smaller = True if j>0: for c_num in range(c+1): if s_score[c_num]+s_cur[c_num]>K: group_smaller = False else: group_smaller = True if group_smaller: for c_num in range(c+1): s_score[c_num] += s_cur[c_num] else: w_count += 1 for c_num in range(c+1): s_score[c_num] = s_cur[c_num] if not is_ok: is_ok = True continue # for c_num in range(h_count+1): # if s_score[c_num]>K: # h_count = 10 ** 6 # 縦線と横線の合計でmin_divideを更新 min_divide = min(min_divide, w_count + h_count) # output print(min_divide)
0
null
33,073,652,503,430
137
193
S=list(input()) T=list(input()) total = 0 for i in range(len(S)): if S[i] == T[i]: continue else: total += 1 print(str(total))
n, k = map(int, input().split()) l = list(map(int, input().split())) for i in range(1, n - k + 1): print("Yes" if l[i - 1] < l[i + k - 1] else "No")
0
null
8,874,942,285,792
116
102
import sys class UnionFind(): def __init__(self, n): self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x N, M = map(int, input().split()) uf = UnionFind(N) for _ in range(M): a, b = map(lambda x: int(x) - 1, sys.stdin.readline().split()) uf.union(a, b) print(sum(p < 0 for p in uf.parents) - 1)
from collections import deque def bfs(s): visit[i] = 1 q = deque() q.append(s) while q: p = q.popleft() for j in G[p]: if not visit[j]: visit[j] = 1 q.append(j) return n, m = map(int, input().split()) G = [[] for _ in range(n + 1)] for _ in range(m): a, b = map(int, input().split()) G[a].append(b) G[b].append(a) visit = [0] * (n + 1) ans = -1 for i in range(1, n + 1): if not visit[i]: bfs(i) ans += 1 print(ans)
1
2,275,786,639,440
null
70
70
# A - Station and Bus # https://atcoder.jp/contests/abc158/tasks/abc158_a s = input() if len(set(s)) == 2: print('Yes') else: print('No')
N, M = map(int, input().split()) c = list(map(int, input().split())) dp = [0] + [float('inf')] * N for m in range(M): ci = c[m] for n in range(N + 1): if n - ci >= 0: dp[n] = min(dp[n], dp[n - ci] + 1) print(dp[N])
0
null
27,597,704,134,938
201
28
n = int(input()) nums = list(map(int, input().split())) result = "APPROVED" for num in nums: if (num % 2 == 0) and not ((num % 3 == 0) or (num % 5 == 0)): result = "DENIED" break print(result)
n = int(input()) l = list(map(int, input().split())) mod_check=0 mod_check_ =0 for i in l: if i % 2 == 0 : mod_check += 1 if i % 3 == 0 or i % 5 == 0: mod_check_ += 1 else: pass else: pass print('APPROVED') if mod_check==mod_check_ else print('DENIED')
1
69,419,566,414,240
null
217
217
x = int(input()) #print(1 if x == 0 else 0) print(x ^ 1)
N,K=map(int,input().split()) List = list(map(int, input().split())) INF = 10000000000 expList = [INF]*1001 def expectationF(num): if expList[num] == INF: exp = 0 for i in range(1,num+1): exp += i/num expList[num] = exp return expList[num] res = 0 mid = 0 midList=[] for i in range(N): if i>=1: midList.append(expectationF(List[i])+midList[i-1]) else: midList.append(expectationF(List[i])) m=K-1 for j in range(N-m): if j == 0: mid = midList[j+m] else: mid = midList[j+m]- midList[j-1] res = max(res,mid) print(res)
0
null
38,689,048,868,238
76
223
N = int(input()) S = input().rstrip() res = 1 s0 = S[0] for s in S[1:]: if s != s0: res += 1 s0 = s print(res)
N = int(input()) S = input() anchor = '' ans = 0 for i in range(N): if anchor != S[i]: anchor = S[i] ans += 1 print(ans)
1
170,519,062,215,228
null
293
293
print("win" if sum(map(int,input().split()))<=21 else "bust")
print('bust' if sum(list(map(int,input().split()))) > 21 else 'win')
1
118,976,568,080,380
null
260
260
# coding: utf-8 # Here your code ! W, H , x ,y ,r = list(map(int, input().split())) t1_x = x + r t1_y = y + r t2_x = x - r t2_y = y - r if 0 <= t1_x <= W and 0 <= t1_y <= H and 0 <= t2_x <= W and 0 <= t2_y <= H: print("Yes") else: print("No")
W, H, x, y, r = map(int, input().split()) print("Yes" if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H else "No")
1
459,679,424,788
null
41
41
change = int(input()) % 1000 print(1000-change if change else change)
n = int(input()) if n % 1000 == 0: if n > 1000: print(0) else: print(1000 - n) else: k = n % 1000 print(1000 - k)
1
8,528,335,973,824
null
108
108
for i in range(1,10): for j in range(1,10): a=i*j print(f'{i}x{j}={a}')
def run(): for i in range(1,10): for j in range(1,10): print('{0}x{1}={2}'.format(i,j,i*j)) if __name__ == '__main__': run()
1
1,977,662
null
1
1
import sys input = sys.stdin.readline N = int(input()) S = [input()[:-1] for _ in range(N)] high = [] low = [] for i in range(N): cnt = 0 m = 0 for j in range(len(S[i])): if S[i][j] == "(": cnt += 1 else: cnt -= 1 m = min(m, cnt) if cnt > 0: high.append([m, cnt]) else: low.append([m-cnt, -cnt]) high.sort(reverse=True) low.sort(reverse=True) h = 0 for m, up in high: if h+m < 0: print("No") sys.exit() h += up p = 0 for m, down in low: if p+m < 0: print("No") sys.exit() p += down if h == p: print("Yes") else: print("No")
def scan(s): m = 0 a = 0 for c in s: if c == '(': a += 1 elif c == ')': a -= 1 m = min(m, a) return m, a def key(v): m, a = v if a >= 0: return 1, m, a else: return -1, a - m, a N = int(input()) S = [input() for _ in range(N)] c = 0 for m, a in sorted([scan(s) for s in S], reverse=True, key=key): if c + m < 0: c += m break c += a if c == 0: print('Yes') else: print('No')
1
23,662,622,786,946
null
152
152
n = input() def koch(n,p1,p2): s = [0] * 2 t = [0] * 2 u = [0] * 2 if n == 0: return 0 s[0] = (2.00 * p1[0] + 1.00 * p2[0]) / 3.00 s[1] = (2.00 * p1[1] + 1.00 * p2[1]) / 3.00 t[0] = (1.00 * p1[0] + 2.00 * p2[0]) / 3.00 t[1] = (1.00 * p1[1] + 2.00 * p2[1]) / 3.00 u[0] = (t[0] - s[0]) * (1.00 / 2.00) - (t[1] - s[1]) * (3.00**0.5 / 2.00) + s[0] u[1] = (t[0] - s[0]) * (3.00**0.5 / 2.00) + (t[1] - s[1]) * (1.00 / 2.00) + s[1] koch(n-1, p1, s) print "{0:.10f}".format(s[0]),"{0:.10f}".format(s[1]) koch(n-1, s, u) print "{0:.10f}".format(u[0]),"{0:.10f}".format(u[1]) koch(n-1, u, t) print "{0:.10f}".format(t[0]),"{0:.10f}".format(t[1]) koch(n-1, t, p2) start = [0.00,0.00] goal = [100.00,0.00] print "{0:.10f}".format(start[0]),"{0:.10f}".format(start[1]) koch(n,start,goal) print "{0:.10f}".format(goal[0]),"{0:.10f}".format(goal[1])
N,K = map(int,input().split()) S,P,R = map(int,input().split()) point = {'s':S,'p':P,'r':R} T = str(input()) max_point = 0 for i in range(K): while i < N: if i+K < N and T[i] == T[i+K]: max_point += point[T[i]] i = i+2*K else: max_point += point[T[i]] i = i+K print(max_point)
0
null
53,660,111,204,316
27
251
import numpy as np H,W,M = map(int,input().split()) #h = np.empty(M,dtype=np.int) #w = np.empty(M,dtype=np.int) bomb = set() hh = np.zeros(H+1,dtype=np.int) ww = np.zeros(W+1,dtype=np.int) for i in range(M): h,w = map(int,input().split()) bomb.add((h,w)) hh[h] += 1 ww[w] += 1 #print(bomb) h_max = np.max(hh) w_max = np.max(ww) h_max_ids = list() w_max_ids = list() for i in range(1,H+1): if hh[i] == h_max: h_max_ids.append(i) for j in range(1,W+1): if ww[j] == w_max: w_max_ids.append(j) for i in h_max_ids: for j in w_max_ids: if not (i,j) in bomb: print(h_max + w_max) exit() #print("hmax:{} wmax:{}".format(h_max_id, w_max_id)) #print("hmax:{} wmax:{}".format(hh[h_max_id], ww[w_max_id])) print(h_max + w_max - 1)
#!/usr/bin/python3 # -*- coding: utf-8 -*- h, w, m = map(int, input().split()) bom_set = set() h_dict = {} w_dict = {} for i in range(m): hh, ww = map(int, input().split()) bom_set.add(tuple([hh, ww])) if hh in h_dict: h_dict[hh] += 1 else: h_dict[hh] = 1 if ww in w_dict: w_dict[ww] += 1 else: w_dict[ww] = 1 h_max_count = max(h_dict.values()) w_max_count = max(w_dict.values()) hh_dict = {} ww_dict = {} for hh in h_dict: if h_dict[hh] == h_max_count: hh_dict[hh] = h_max_count for ww in w_dict: if w_dict[ww] == w_max_count: ww_dict[ww] = w_max_count flag = 0 for hh in hh_dict: for ww in ww_dict: if tuple([hh, ww]) not in bom_set: flag = 1 break if flag == 1: break if flag == 1: print(h_max_count + w_max_count) else: print(h_max_count + w_max_count - 1)
1
4,703,813,073,328
null
89
89
#!/usr/bin/env python3 import sys from itertools import chain YES = "Yes" # type: str NO = "No" # type: str def solve(H: int, N: int, A: "List[int]"): if H <= sum(A): return YES else: return NO def main(): tokens = chain(*(line.split() for line in sys.stdin)) H = int(next(tokens)) # type: int N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" answer = solve(H, N, A) print(answer) if __name__ == "__main__": main()
def common_raccoon_vs_monster(): # 入力 H, N = map(int, input().split()) A = list(map(int, input().split())) # 必殺技の合計攻撃力 sum_A = 0 # 必殺技の攻撃力の合計 for i in range(len(A)): sum_A += A[i] # 比較 if H > sum_A: return 'No' else: return 'Yes' result = common_raccoon_vs_monster() print(result)
1
78,013,149,134,900
null
226
226
capstr='ABCDEFGHIJKLMNOPQRSTUVWXYZ' s=input() h=list(capstr) if(h.count(s)==1): print('A') else: print('a')
mozi = input() kazu = int(ord(mozi)) if 65 <= kazu < 91: print('A') else: print('a')
1
11,241,536,607,560
null
119
119
i=0 for i in range(1,10): for j in range(1,10): print(f'{i}x{j}={i*j}') j+=1 i+=1
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ?????? ??\?????????????????¨?¨???§????????????????????????????????????????????°???????????????????????????????????????¨?????????£?????????????°?????????? x ????????¨????????????????????? 1x1=1 1x2=2 . . 9x8=72 9x9=81 """ def main(): """ ????????? """ for i in range(1,10): for j in range(1,10): x = i * j print("{}x{}={}".format(i,j,x)) if __name__ == '__main__': main()
1
641,860
null
1
1
import numpy as np N,K=map(int,input().split()) R,S,P=map(int,input().split()) T1=input() T2=T1.replace('r', str(P)+' ').replace('s',str(R)+' ').replace('p',str(S)+' ')[:-1] T2=np.array(list(map(int, T2.split()))) for i in range(N): if i >=K and T1[i]==T1[i-K] and T2[i-K] != 0: T2[i]=0 print(T2.sum())
import math n = input() p = 0 money = 100 while p != n: money = math.ceil(money * 1.05) p += 1 print int(money * 1000)
0
null
53,451,077,577,388
251
6
n = int(input()) S = set(map(int, input().split())) q = int(input()) T = tuple(map(int, input().split())) cnt = 0 for n in T: cnt += n in S print(cnt)
from collections import deque N, X, Y = map(int, input().split()) adj = [[] for _ in range(N)] for i in range(N-1): adj[i].append(i+1) adj[i+1].append(i) adj[X-1].append(Y-1) adj[Y-1].append(X-1) dist = [[-1]*N for _ in range(N)] for i in range(N): queue = deque([i]) dist[i][i] = 0 while queue: now = queue.popleft() for u in adj[now]: if dist[i][u] < 0: queue.append(u) dist[i][u] = dist[i][now] + 1 ans = [0] * (N-1) for i in range(N): for j in range(i+1,N): ans[dist[i][j]-1] += 1 [print(a) for a in ans]
0
null
22,255,049,064,430
22
187
import math def solve(): N = int(input()) A = [int(i) for i in input().split()] S = sum(A) l = A[0] I = 0 m = math.ceil(S / 2) for i in range(1, N): if (l + A[i]) <= m: l += A[i] else: I = i - 1 break if l == S / 2: print(0) exit() c = A[I + 1] r = S - l - c ans1 = abs(r - (l + c)) ans2 = abs(l - (r + c)) print(min(ans1, ans2)) if __name__ == "__main__": solve()
n = int(input()) l = list(map(int,input().split())) from itertools import accumulate cum=list(accumulate(l)) tot=sum(l) ans=2020202020*100000 for i in cum: ans=min(ans, abs(tot-i*2)) print(ans)
1
142,054,849,161,270
null
276
276
n = int(input()) odd = 0 for i in range(1,n+1): odd += i%2 != 0 print(odd/n)
a = int(input()) print(1 / 2 if a % 2 == 0 else (a + 1) / (2 * a))
1
177,308,121,673,268
null
297
297
S = int(input()) print("%d:%d:%d" % (S / 3600, S % 3600 / 60, S % 60))
for i in range(9): for j in range(9): print "%dx%d=%d" %(i+1,j+1, (i+1)*(j+1))
0
null
166,193,618,182
37
1
S = input() T = '' for _ in range(len(S)): T += 'x' print(T)
#Macで実行する時 import sys import os if sys.platform=="darwin": base = os.path.dirname(os.path.abspath(__file__)) name = os.path.normpath(os.path.join(base, '../atcoder/input.txt')) #print(name) sys.stdin = open(name) s = input() #print(len(s)) ans=[] for i in range(len(s)): ans.append("x") print("".join(ans))
1
72,878,631,449,052
null
221
221
from typing import List def is_able_to_load(tmp_P: int, weights: List[int], track_num_max: int) -> bool: track_num = 1 tmp_sum = 0 for w in weights: if tmp_sum + w <= tmp_P: tmp_sum += w else: track_num += 1 tmp_sum = w if track_num > track_num_max: return False return True if __name__ == "__main__": n, k = map(lambda x: int(x), input().split()) weights = list(map(lambda x: int(input()), range(n))) left_weight = max(weights) right_weight = 10000 * 100000 mid_weight = (left_weight + right_weight) // 2 optimal_P = right_weight while left_weight <= right_weight: if is_able_to_load(mid_weight, weights, k): optimal_P = mid_weight right_weight = mid_weight - 1 else: left_weight = mid_weight + 1 mid_weight = (left_weight + right_weight) // 2 print(f"{optimal_P}")
N = int(input()) target_list = [] if N % 2 == 1: N += 1 for i in range(1, int(N/2)): target = N - i if target == i: continue else: target_list.append(target) print(len(target_list))
0
null
76,324,775,423,540
24
283
while True: str_shuffled = input() if str_shuffled == '-': break shuffle_time = int(input()) for _ in range(shuffle_time): num_to_shuffle = int(input()) str_shuffled = str_shuffled[num_to_shuffle:] + str_shuffled[:num_to_shuffle] print(str_shuffled)
n,m = map(int,input().split()) x = n*(n-1)//2 r = m*(m-1)//2 print(x+r)
0
null
23,593,061,566,380
66
189
x,y=map(int,input().split()) if y%2==1: print('No') elif y>=2*x and y<=4*x: print('Yes') else: print('No')
x,y=map(int,input().split()) if (x*2) <= y <= (x*4) and y%2 ==0: print('Yes') else: print('No')
1
13,762,503,717,128
null
127
127
def solve(n, k, a): for i in range(k, n): print("Yes" if a[i-k] < a[i] else "No") n, k = map(int, input().split()) a = list(map(int, input().split())) solve(n, k, a)
import math def resolve(): import sys input = sys.stdin.readline r = int(input().rstrip()) print(r * 2 * math.pi) if __name__ == "__main__": resolve()
0
null
19,204,654,829,348
102
167
n, k = list(map(int, input().split())) mod = 10**9 + 7 # xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。 def modinv(x): return pow(x, mod-2, mod) # 二項係数の左側の数字の最大値を max_len とする。nとかだと他の変数と被りそうなので。 # factori_table = [1, 1, 2, 6, 24, 120, ...] 要は factori_table[n] = n! # 計算時間はO(max_len * log(mod)) max_len = 2 * n - 1 #適宜変更する factori_table = [1] * (max_len + 1) factori_inv_table = [1] * (max_len + 1) for i in range(1, max_len + 1): factori_table[i] = factori_table[i-1] * (i) % mod factori_inv_table[i] = modinv(factori_table[i]) def binomial_coefficients(n, k): # n! / (k! * (n-k)! ) if k <= 0 or k >= n: return 1 return (factori_table[n] * factori_inv_table[k] * factori_inv_table[n-k]) % mod if k >= n-1: # nHn = 2n-1 C n print(binomial_coefficients(2 * n - 1, n)) else: # 移動がk回←→ 人数0の部屋がk個以下 # 人数0の部屋がちょうどj個のものは # nCj(人数0の部屋の選び方) * jH(n-j) (余剰のj人を残りの部屋に入れる) ans = 0 for j in range(k+1): if j == 0: ans += 1 else: ans += binomial_coefficients(n, j) * binomial_coefficients(n-1, j) ans %= mod print(ans)
n, k = map(int, input().split()) mod = 10 ** 9 + 7 ans = 0 coma = 1 comb = 1 for i in range(min(k+1, n)): ans += coma * comb ans %= mod coma *= (n-i) * pow(i+1, mod-2, mod) coma %= mod comb *= (n-i-1) * pow(i+1, mod-2, mod) comb %= mod print(ans)
1
66,997,013,450,584
null
215
215
class Dice: def __init__(self,labels): self.stat = labels def roll_E(self): self.stat[0],self.stat[2],self.stat[3],self.stat[5] = self.stat[3],self.stat[0],self.stat[5],self.stat[2] def roll_N(self): self.stat[0],self.stat[1],self.stat[5],self.stat[4] = self.stat[1],self.stat[5],self.stat[4],self.stat[0] def roll_S(self): self.stat[0],self.stat[1],self.stat[5],self.stat[4] = self.stat[4],self.stat[0],self.stat[1],self.stat[5] def roll_W(self): self.stat[0],self.stat[2],self.stat[5],self.stat[3] = self.stat[2],self.stat[5],self.stat[3],self.stat[0] def get_top(self): return self.stat[0] dice = Dice(input().split()) commands = input() for command in commands: if command == "E": dice.roll_E() elif command == "N": dice.roll_N() elif command == "S": dice.roll_S() elif command == "W": dice.roll_W() print(dice.get_top())
#!usr/bin/env python3 import sys class Die: def __init__(self, pips): self.pips = pips def move_die(self, direction): tmp = int() if direction == 'N': tmp = self.pips[0] self.pips[0] = self.pips[1] self.pips[1] = self.pips[5] self.pips[5] = self.pips[4] self.pips[4] = tmp elif direction == 'S': tmp = self.pips[0] self.pips[0] = self.pips[4] self.pips[4] = self.pips[5] self.pips[5] = self.pips[1] self.pips[1] = tmp elif direction == 'E': tmp = self.pips[0] self.pips[0] = self.pips[3] self.pips[3] = self.pips[5] self.pips[5] = self.pips[2] self.pips[2] = tmp elif direction == 'W': tmp = self.pips[0] self.pips[0] = self.pips[2] self.pips[2] = self.pips[5] self.pips[5] = self.pips[3] self.pips[3] = tmp def get_upside(self): return self.pips[0] def init_die(): pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()] die = Die(pips) return die def roll_die(die): directions = list(sys.stdin.readline().strip('\n')) for direction in directions: die.move_die(direction) return die def main(): die = init_die() die = roll_die(die) print(die.get_upside()) if __name__ == '__main__': main()
1
231,793,945,500
null
33
33
a,b,c,k=[int(i) for i in input().split()] if a>=k: print(k) elif a+b>=k: print(a) else: print(a-(k-a-b))
# import string import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): h=int(input()) w=int(input()) n=int(input()) v=max(h,w) cnt=0 while n>0: n-=v cnt+=1 print(cnt) resolve()
0
null
55,500,984,508,928
148
236
K=int(input()) x=7 c=1 visited={7} while x%K: x*=10 x+=7 x%=K c+=1 z=x%K if z in visited: print(-1) exit() visited.add(x%K) print(c)
s = input() for _ in range(int(input())): code=input().split() if code[0]=='print' : print("".join(s[int(code[1]):int(code[2])+1])) elif code[0]=='reverse': s = s[:int(code[1])] + s[int(code[1]):int(code[2])+1][::-1] + s[int(code[2])+1:] elif code[0]=='replace': s = s[:int(code[1])] + code[3] + s[int(code[2])+1:]
0
null
4,112,940,855,520
97
68
# -*- coding:utf-8 -*- x = 100000 n = int(input()) for i in range(n): x = x + x*0.05 a = x // 1000 r = x % 1000 if r != 0: x = 1000*a + 1000 else: x = 1000*a print(int(x))
i = int(input()) x = 100000 for _ in range(i): x *= 1.05 x = int((x+999) / 1000) * 1000 print(x)
1
1,220,780,248
null
6
6
s = list(input()) print(['No', 'Yes'][s[2] == s[3] and s[4] == s[5]])
s = input() S = list(s) if S[2] == S[3] and S[4] == S[5]: print('Yes') else: print('No')
1
41,980,641,501,060
null
184
184
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n,m = na() a,b = 1,n-(n%2) for i in range(m): if n%2 == 0 and i == (m+1)//2: a += 1 print(a,b) a,b = a+1, b-1
def main(): N, M = map(int, input().split()) if N & 1: gen = ((i+1, N-i) for i in range(M)) else: gen = ((i+1, N-i) if 2*i < N/2-1 else (i+1, N-i-1) for i in range(M)) [print(*s) for s in gen] if __name__ == "__main__": main()
1
28,528,194,708,768
null
162
162
dice = list(input().split(' ')) a = list(input()) for i in a: if i == 'W': dice = [dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]] elif i == 'S': dice = [dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]] elif i == 'N': dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]] elif i == 'E': dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]] print(dice[0])
import sys def main(): read = sys.stdin.buffer.read k, n, *A = map(int, read().split()) A += [A[0] + k] far = max(y - x for x, y in zip(A, A[1:])) print(k - far) if __name__ == "__main__": main()
0
null
21,789,800,150,710
33
186
n = int(input()) A = [int(x) for x in input().split()] print(" ".join([str(x) for x in A])) for i in range(1, n): key = A[i] j = i-1 while j >=0 and A[j] > key: A[j+1] = A[j] j -= 1 A[j+1] = key print(" ".join([str(x) for x in A]))
B=[];C=[];S=0 N=int(input()) A=list(map(int,input().split())) Q=int(input()) for i in range(Q): b,c=map(int,input().split()) B.append(b) C.append(c) X=[0]*(10**5+1) for i in range(N): X[A[i]]+=1 S=S+A[i] #print(A) #print(B) #print(C) for i in range(Q): X[C[i]]+=X[B[i]] S=S+X[B[i]]*(C[i]-B[i]) X[B[i]]=0 print(S)
0
null
6,058,961,577,870
10
122
n, k = map(int, input().split()) a = list(map(int, input().split())) a[0] = (a[0]-1)%k for i in range(1,n): a[i] = (a[i]+a[i-1]-1)%k ans = 0 b = {0:1} for i in range(n): if i>0: b[a[i-1]] = b.get(a[i-1],0) + 1 if i>=k: b[a[i-k]] -= 1 if i==k-1: b[0] -= 1 ans += b.get(a[i],0) print(ans)
N=int(input()) S,T=map(str,input().split()) l=[] a,b=0,0 for i in range(N*2): if (i+1)%2!=0: l.append(S[a]) a+=1 else: l.append(T[b]) b+=1 print(''.join(l))
0
null
124,811,192,330,286
273
255
def main(): a, b = map(int, input().split()) print(a*b) if __name__ == '__main__': main()
N = int(input()) A = map(int, input().split()) A = sorted(enumerate(A), key=lambda x: x[1], reverse=True) dp = [[0]*(N+1) for _ in range(N+1)] for n, (from_i, a) in enumerate(A): for j in range(n + 1): dp[n+1][j+1] = max(dp[n+1][j+1], dp[n][j] + a*(from_i - j)) dp[n+1][j] = max(dp[n+1][j], dp[n][j] + a*(N - (n - j) - 1 - from_i)) print(max(dp[N]))
0
null
24,876,987,594,240
133
171
word=input().lower() how_in=0 while True: letters=input() if letters=='END_OF_TEXT': break for i in letters.lower().split(): if i==word: how_in+=1 print(how_in)
K = int(input()) A, B = map(int, input().split()) ans = 'OK' if B//K-(A-1)//K > 0 else 'NG' print(ans)
0
null
14,145,247,753,308
65
158
def chebyshev_0(a, b): return a - b def chebyshev_1(a, b): return a + b N = int(input()) X = [0] * N Y = [0] * N for i in range(N): X[i], Y[i] = map(int, input().split()) max_0 = - (10 ** 9) - 1 min_0 = 2 * (10 ** 9) for x, y in zip(X, Y): if chebyshev_0(x, y) > max_0: max_0 = chebyshev_0(x, y) if chebyshev_0(x, y) < min_0: min_0 = chebyshev_0(x, y) l0 = abs(max_0 - min_0) max_1 = - (10 ** 9) - 1 min_1 = 2 * (10 ** 9) for x, y in zip(X, Y): if chebyshev_1(x, y) > max_1: max_1 = chebyshev_1(x, y) if chebyshev_1(x, y) < min_1: min_1 = chebyshev_1(x, y) l1 = abs(max_1 - min_1) print(max([l0, l1]))
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): a, b = map(int, readline().split()) print(str(min(a, b)) * max(a, b)) if __name__ == '__main__': main()
0
null
43,824,624,252,330
80
232
def divisor(n): i = 1 table = [] while i * i <= n: if n%i == 0: table.append(i) table.append(n//i) i += 1 table = list(set(table)) return table n = int(input()) ans = n divisor_num = divisor(n) for i in divisor_num: j = n // i tmp = i + j - 2 ans = min(ans, tmp) print(ans)
N = int(input()) search_max = int(N**0.5) min_number = 10**12 for x in range(1, search_max + 1): if N % x == 0: y = N // x if x + y < min_number: min_number = x + y print(min_number-2)
1
161,988,947,013,860
null
288
288
import bisect def is_ok(a, target, m): num = 0 for val in a: index = bisect.bisect_left(a, target - val) num += len(a) - index if num <= m: return True else: return False n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() ok, ng = 10 ** 10, -1 while ok - ng > 1: mid = (ok + ng) // 2 if is_ok(a, mid, m): ok = mid else: ng = mid rui = [0] * (n + 1) for i in range(n): rui[i+1] = rui[i] + a[i] cnt = 0 ret = 0 for val in a: index = bisect.bisect_left(a, ok - val) num = len(a) - index cnt += num ret += (num * val) + (rui[-1] - rui[index]) ret += (m - cnt) * ng print(ret)
#! python3 # triangle.py import math a, b, C = [int(x) for x in input().split(' ')] S = a * b * math.sin(math.radians(C)) / 2.0 L = a + b + math.sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(math.radians(C))) h = b * math.sin(math.radians(C)) print('%.5f'%S) print('%.5f'%L) print('%.5f'%h)
0
null
54,143,426,525,570
252
30
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] # def LF(): return [float(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() # Summarize count of factor within list -- START -- def summarizeList(l): sl=sorted(l) a=sl[0] c=1 res=[] for x in sl[1:]: if x==a: c+=1 else: res.append([a,c]) a=x c=1 res.append([a,c]) return res # Summarize count of factor within list --- END --- # 累積和の書き方がよくないやつ def main(): s=S() n=len(s) l=[] mul=1 for x in s[::-1]: l.append(mul*int(x)%2019) mul*=10 mul%=2019 for i in range(n-1): l[i+1]+=l[i] l[i+1]%=2019 sl=summarizeList(l) # print(sl) ans=0 for x,c in sl: if x==0: ans+=c if c>1: ans+=c*(c-1)//2 return ans # main() print(main())
import collections #https://note.nkmk.me/python-prime-factorization/ def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def f(n): for i in range(1,20): if n<(i*(i+1))//2: return i-1 n = int(input()) c = collections.Counter(prime_factorize(n)) ans = 0 for i in c.keys(): ans += f(c[i]) print(ans)
0
null
23,893,735,354,980
166
136
import math A,B=map(int,input().split()) print(A*B//math.gcd(A,B))
H1,M1,H2,M2,K=map(int, input().split()) M1 += H1*60 M2 += H2*60 print(M2-M1-K)
0
null
65,958,984,811,226
256
139
n = int(input()) x = list(map(float, input().split(' '))) y = list(map(float, input().split(' '))) p1 = 0.0 p2 = 0.0 p3 = 0.0 pm = 0.0 i = 0 while i < n: p1 += abs(x[i] - y[i]) p2 += pow(abs(x[i] - y[i]), 2) p3 += pow(abs(x[i] - y[i]), 3) pm = max(pm, abs(x[i] - y[i])) i += 1 p2 = pow(p2, 0.5) p3 = pow(p3, 0.333333333333333) ans = '{0:.8f}'.format(p1) + '\n' ans += '{0:.8f}'.format(p2) + '\n' ans += '{0:.8f}'.format(p3) + '\n' ans += '{0:.8f}'.format(pm) print(ans)
import sys readline = sys.stdin.readline INF = 10 ** 8 def main(): H, N = map(int, readline().rstrip().split()) dp = [INF] * (H + 1) # HPを減らすのに必要な最小のMP dp[0] = 0 for _ in range(N): hp, mp = map(int, readline().rstrip().split()) for i in range(H): j = min(i+hp, H) dp[j] = min(dp[j], dp[i] + mp) print(dp[-1]) if __name__ == '__main__': main()
0
null
40,738,767,497,398
32
229
a,b=map(int,input().split()) a1=a/0.08 a2=(a+1)/0.08 b1=b/0.1 b2=(b+1)/0.1 ans=20000 for i in range(1,10001): if a1<=i and b1<=i and a2>i and b2>i: ans=min(ans,i) if ans==20000: print(-1) else: print(ans)
import collections N=int(input()) A=list(map(int,input().split())) c=collections.Counter(A) s=0 def f(n): return n*(n-1)//2 for i in c: c[i]=(f(c[i]),(f(c[i]-1))) s+=c[i][0] for j in A: print(s-c[j][0]+c[j][1])
0
null
52,193,622,146,640
203
192
import sys import math def Ii():return int(sys.stdin.buffer.readline()) def Mi():return map(int,sys.stdin.buffer.readline().split()) def Li():return list(map(int,sys.stdin.buffer.readline().split())) x = Ii() ans = 0 k = 100 while x > k: tax = k//100 k += tax ans += 1 print(ans)
def main(): X=int(input()) tmp=100 for year in range(1,4000): tmp += tmp//100 if tmp >= X: print(year) exit() main()
1
27,074,886,923,290
null
159
159
def solve(): N = int(input()) cnt = {} for i in range(N): result = input() cnt[result] = cnt.get(result, 0) + 1 for result in ("AC", "WA", "TLE", "RE"): print("{} x {}".format(result, cnt.get(result, 0))) if __name__ == "__main__": solve()
x, y, a, b, c = map(int, input().split()) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) p.sort() q.sort() for _ in range(x): r.append(p.pop()) for _ in range(y): r.append(q.pop()) r.sort() ans = 0 for _ in range(x+y): ans += r.pop() print(ans)
0
null
26,628,629,231,150
109
188
N = int(input()) A = list(map(int,input().split())) Q = int(input()) B = [0]*Q C = [0]*Q for i in range(Q): B[i], C[i] = map(int,input().split()) num = [0]*100001 for i in A: num[i] += 1 S = [0]*(Q+1) S[0] = sum(A) change = 0 for i in range(Q): change = num[B[i]] S[i+1] = S[i] + change*(C[i]-B[i]) num[B[i]] -= change num[C[i]] += change for i in S[1:]: print(i)
N = int(input()) ans = [0]*(N+1) for x in range(1,100): for y in range(1,100): for z in range(1,100): num = x*x + y*y + z*z + x*y + y*z + z*x if num>N: break ans[num] = ans[num] + 1 for m in ans[1:]: print(m)
0
null
10,094,592,141,080
122
106
s=input() n=int(input()) for _ in range(n): tmp=list(map(str,input().split())) a,b=int(tmp[1]),int(tmp[2])+1 if tmp[0]=="print": print(s[a:b]) elif tmp[0]=="reverse": stmp=s[a:b] s=s[:a]+stmp[::-1]+s[b:] else: p=tmp[3] s=s[:a]+p+s[b:]
s = input() t = input() n = len(s) m = len(t) ans = 2000 for i in range(n): if i+m > n: break u = s[i:i+m] cnt = 0 for j in range(m): if t[j] != u[j]: cnt += 1 ans = min(ans, cnt) print(ans)
0
null
2,899,517,996,802
68
82
n, x, m = map(int, input().split()) a = x dup = [0]*(10**5+10) mod = [a] loop = [] cnt = 0 while cnt < n: a = a**2 % m if dup[a]==1: i = mod.index(a) before = mod[:i] loop = mod[i:] break mod.append(a) dup[a] = 1 cnt += 1 length = len(loop) if length == 0: print(sum(mod[:n])) else: t = (n-i)//length amari = (n-i) % length ans = sum(before) + t * sum(loop) + sum(loop[:amari]) print(ans)
N = int(input()) print(((N >> 1) + (N & 1)) / N)
0
null
89,680,684,984,562
75
297
H = int(input()) W = int(input()) N = int(input()) A_div, A_mod = divmod(N, H) if A_mod != 0: A_div += 1 B_div, B_mod = divmod(N, W) if B_mod != 0: B_div += 1 print(min(A_div, B_div))
i=lambda:int(input());c=max(i(),i());print(0--i()//c)
1
88,607,533,769,140
null
236
236
ans = 0 for a in range(1, int(input())+1): if a % 3 != 0 and a % 5 != 0: ans += a print(ans)
#!/usr/bin/env python3 from copy import deepcopy def main(): n = input() l = len(n) k = int(input()) dp0 = [0 for j in range(4)] dp1 = [0 for j in range(4)] dp1[0] = 1 for i in range(l): dppre0 = deepcopy(dp0) dppre1 = deepcopy(dp1) d = int(n[i]) if d == 0: for j in [1, 2, 3]: dp0[j] += dppre0[j - 1] * 9 else: for j in [1, 2, 3]: dp0[j] += dppre0[j - 1] * 9 dp0[j] += dppre1[j - 1] * max(0, d - 1) for j in [0, 1, 2, 3]: dp0[j] += dppre1[j] dp1 = [0 for j in range(4)] for j in [1, 2, 3]: dp1[j] = dppre1[j - 1] print(dp0[k] + dp1[k]) if __name__ == "__main__": main()
0
null
55,452,851,794,868
173
224
[w,h,x,y,r] = map(int, input().split()) print("Yes" if r <= x and x <= w - r and r <= y and y <= h - r else "No")
a = map(int, raw_input().split()) w = a[0] h = a[1] x = a[2] y = a[3] r = a[4] if x+r <= w and x-r >= 0 and y+r <= h and y-r >= 0: print 'Yes' else: print 'No'
1
442,561,148,084
null
41
41
n=int(input()) d=list(map(int,input().split())) r=1 if d[0]==0 else 0 d=d[1:] d.sort() c=1 nc=0 j=1 mod=998244353 for i in d: if i<j: r=0 elif i==j: nc+=1 r=(r*c)%mod elif i==j+1: j=i c=nc nc=1 r=(r*c)%mod else: r=0 print(r)
n,k = map(int,input().split()) R,S,P = map(int,input().split()) T = input() slist = ['']*k for i in range(n): slist[i%k] += T[i] ans = 0 for s in slist: dp = [[0,0,0]for i in range(len(s))] #dp[i][j] = 直前にjを出したときの得点の最大値 ''' 0..r 1..s 2..p ''' dp[0][1] = S if s[0] == 'p' else 0 dp[0][0] = R if s[0] == 's' else 0 dp[0][2] = P if s[0] == 'r' else 0 for i in range(1,len(s)): if s[i] == 'r': dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + P dp[i][1] = max(dp[i-1][0],dp[i-1][2]) dp[i][0] = max(dp[i-1][1],dp[i-1][2]) elif s[i] == 's': dp[i][0] = max(dp[i-1][2],dp[i-1][1]) + R dp[i][1] = max(dp[i-1][0],dp[i-1][2]) dp[i][2] = max(dp[i-1][1],dp[i-1][0]) else: dp[i][1] = max(dp[i-1][2],dp[i-1][0]) + S dp[i][0] = max(dp[i-1][1],dp[i-1][2]) dp[i][2] = max(dp[i-1][1],dp[i-1][0]) ans += max(dp[len(s)-1][0],dp[len(s)-1][1],dp[len(s)-1][2]) #print(slist) print(ans)
0
null
131,400,967,979,492
284
251
import sys import math import bisect def main(): n = int(input()) s = ['ACL'] * n print(''.join(s)) if __name__ == "__main__": main()
k=int(input()) l=['ACL']*k print(*l,sep='')
1
2,206,901,497,278
null
69
69
while True: h,w = map(int,raw_input().split()) if h == 0 and w == 0: break for i in range(h): print '#'*w print ''
n, k = map(int, input().split()) P = list(map(int, input().split())) P_ac = [sum(P[:k])] for i in range(n-k): P_ac.append(P_ac[-1]-P[i]+P[i+k]) print((max(P_ac)+k)/2)
0
null
37,620,886,580,100
49
223
import math print([ ( int(x) * 360 // math.gcd(int(x),360) ) // int(x) for x in input().split(' ') ][0])
from math import gcd x = int(input()) lcm = 360 * x // gcd(360, x) ans = lcm // x print(ans)
1
13,030,212,181,052
null
125
125
N = list(map(int, list(input()))) L = len(N) K = int(input()) dp = [[[0] * (K+1) for j in range(2)] for i in range(L+1)] dp[0][0][0] = 1 for i in range(L): ni = N[i] if ni == 0: for j in range(K): dp[i+1][1][j+1] += dp[i][1][j] * 9 for j in range(K+1): dp[i+1][0][j] += dp[i][0][j] else: for j in range(K+1): dp[i+1][1][j] += dp[i][0][j] for j in range(K): dp[i+1][1][j+1] += (dp[i][0][j] * (ni-1) + dp[i][1][j] * 9) dp[i+1][0][j+1] += dp[i][0][j] for j in range(K+1): dp[i+1][1][j] += dp[i][1][j] print(dp[L][0][K]+dp[L][1][K])
import sys import math sys.setrecursionlimit(1000000) N = int(input()) K = int(input()) from functools import lru_cache @lru_cache(maxsize=10000) def f(n,k): # print('n:{},k:{}'.format(n,k)) if k == 0: return 1 if k== 1 and n < 10: return n keta = len(str(n)) if keta < k: return 0 h = n // (10 ** (keta-1)) b = n % (10 ** (keta-1)) ret = 0 for i in range(h+1): if i==0: ret += f(10 ** (keta-1) - 1, k) elif 1 <= i < h: ret += f(10 ** (keta-1) - 1, k-1) else: ret += f(b,k-1) return ret print(f(N,K))
1
76,409,304,939,680
null
224
224
nums = input().split() a = int(nums[0]) b = int(nums[1]) print(a * b, 2 * a + 2 * b)
[a,b] = raw_input().split(' ') print int(a)*int(b), (int(a) + int(b)) * 2
1
307,197,382,590
null
36
36
n, k, c = map(int, input().split()) s = input() l = [0 for i in range(k+1)] r = [0 for i in range(k+1)] cnt = 0 kaime = 1 for i in range(n): if kaime > k: break if cnt > 0: cnt -= 1 else: if s[i] == 'o': l[kaime] = i kaime += 1 cnt = c cnt = 0 kaime = k for j in range(n): i = n-1 - j if kaime < 1: break if cnt > 0: cnt -= 1 else: if s[i] == 'o': r[kaime] = i kaime -= 1 cnt = c for i in range(1, k+1): if l[i] == r[i]: print(l[i]+1)
import math a, b, c = map(int, input().split()) PI = 3.1415926535897932384 c = math.radians(c) print('{:.5f}'.format(a * b * math.sin(c) / 2)) A = a - b * math.cos(c) B = b * math.sin(c) print('{:.5f}'.format(math.sqrt(A * A + B * B) + a + b)) print('{:.5f}'.format(B))
0
null
20,326,679,112,560
182
30
S, W = list(map(int, input().split())) if W >= S: print('unsafe') else: print('safe')
#n, m, q = map(int, input().split()) #List = list(map(int, input().split())) s, w = map(int, input().split()) if s > w: print('safe') else : print("unsafe")
1
29,309,881,741,526
null
163
163
def main(): A,B,M=map(int,input().split()) a=[int(_) for _ in input().split()] b=[int(_) for _ in input().split()] ans=min(a)+min(b) for m in range(M): x,y,c=map(int,input().split()) ans=min(ans,a[x-1]+b[y-1]-c) print(ans) main()
a,b,m = map(int,input().split()) r = tuple(map(int,input().split())) d = tuple(map(int,input().split())) ans = min(r)+min(d) for i in range(m): x,y,c = map(int,input().split()) ans = min(ans,r[x-1]+d[y-1]-c) print(ans)
1
53,943,874,153,608
null
200
200
H, W, K = map(int,input().split()) grid = [list(input()) for i in range(H)] total = 0 for mask1 in range(1<<H): for mask2 in range(1<<W): ct = 0 for i in range(H): for j in range(W): if grid[i][j]=='#' and not (1<<i)&mask1 and not (1<<j)&mask2: ct += 1 if ct==K: total += 1 print(total)
a, b, c, k = map(int, input().split()) ans = 0 if a >= k: print(k) exit() ans += a k -= a if b >= k: print(ans) exit() k -= b ans -= k print(ans)
0
null
15,449,996,070,990
110
148
H, W = map(int,input().split()) if H == 1 or W == 1: print(1) else: ans = H*W if ans % 2: print(ans//2+1) else: print(ans//2)
import math h,w = map(int, input().split()) print(1 if h==1 or w==1 else math.ceil(h*w/2))
1
50,694,832,913,750
null
196
196
a, b, c = map(int, input().split()) if(a > b) : a, b = b, a if(b > c) : b, c = c, b if(a > b) : a, b = b, a else : pass else : pass print(a, b, c) else : if(b > c) : b, c = c, b if(a > b) : a, b = b, a else : pass else : pass print(a, b, c)
import math t = float(input()) a = math.pi * t**2 b = 2 * t * math.pi print(str("{0:.8f}".format(a)) + " " + "{0:.8f}".format(b))
0
null
537,094,800,790
40
46
a, b, c, d = map(int, input().split()) if a == b and c == d: print(a*c) else: p1 = a*c p2 = a*d p3 = b*c p4 = b*d print(max(p1,p2,p3,p4))
a, b,c ,d = list(map(int,input().split())) ll = [a*c,a*d,b*c,b*d] print(max(ll))
1
3,051,810,265,350
null
77
77
H, N = map(int, input().split()) A_list = [] for i in range(1, N+1): A_list.append("A_" + str(i)) A_list = map(int, input().split()) A_total = sum(A_list) if A_total >= H: print("Yes") else: print("No")
H,N=map(int,input().split()) list=[] for i in map(int,input().split()): list.append(i) if H - sum(list) <= 0: print('Yes') else: print('No')
1
78,040,814,232,288
null
226
226
from collections import deque INF = 1000000 N,T,A=map(int,input().split()) T -= 1 A -= 1 G = [ [] for i in range(N) ] DT = [ INF for _ in range(N) ] DA = [ INF for _ in range(N) ] for i in range(N-1): h1,h2=map(int,input().split()) h1 -= 1 h2 -= 1 G[h1].append(h2); G[h2].append(h1); DT[T] = 0 DA[A] = 0 q = deque() # BFS q.append(T) while len(q) > 0: v = q.popleft() for nv in G[v]: if DT[nv] == INF: DT[nv] = DT[v] + 1 q.append(nv) q.clear() q.append(A) while len(q) > 0: v = q.popleft() for nv in G[v]: if DA[nv] == INF: DA[nv] = DA[v] + 1 q.append(nv) max_da = 0 for i in range(N): #print(i, " T:", DT[i], " A:", DA[i]) if DA[i] - DT[i] >= 1 : max_da = max(DA[i], max_da) print(max_da-1)
import sys # import bisect # import numpy as np # from collections import deque from collections import deque # map(int, sys.stdin.read().split()) # import heapq import bisect import math def input(): return sys.stdin.readline().rstrip() def main(): N =int(input()) S = input() pre ="A" count=0 for i in S: if i !=pre: count+=1 pre = i print(count) if __name__ == "__main__": main()
0
null
144,025,953,443,988
259
293
MOD = 1e9 + 7 n = int(input()) ans = [[0, 1, 1, 8]] for i in range(n-1): a, b, c, d = ans.pop() a = (a * 10 + b + c) % MOD b = (b * 9 + d) % MOD c = (c * 9 + d) % MOD d = (d * 8) % MOD ans.append([a, b, c, d]) a, b, c, d = ans.pop() print(int(a))
import math n = int(input()) a = pow(10, n, 10**9+7) b = pow(9, n, 10**9+7) c = pow(9, n, 10**9+7) d = pow(8, n, 10**9+7) print((a-b-c+d) % (10**9+7))
1
3,130,291,625,582
null
78
78
a, b, c, d = map(int, input().split()) T = 0 A = 0 while a > 0: a -= d A += 1 while c > 0: c -= b T += 1 if A >= T: print("Yes") else: print("No")
A, B, C, D = map(int, input().split()) if C % B == 0: Takahashi_attacks = C // B else: Takahashi_attacks = C // B + 1 if A % D == 0: Aoki_attacks = A // D else: Aoki_attacks = A // D + 1 if Takahashi_attacks <= Aoki_attacks: print('Yes') else: print('No')
1
29,737,709,993,180
null
164
164
H_1, M_1, H_2, M_2, K = list(map(int, input().split(' '))) print((H_2-H_1)*60+(M_2-M_1)-K)
h1, m1, h2, m2, k = map(int, input().split()) time = (h2 - h1) * 60 time += m2 - m1 print(time - k)
1
18,068,423,112,388
null
139
139
mountains = [] for x in range(10): mountains.append(int(raw_input())) mountains.sort() print(mountains[-1]) print(mountains[-2]) print(mountains[-3])
a=[] for i in range(10): a.append(input()) a.sort() a=a[::-1] a=a[:3] print(a[0]) print(a[1]) print(a[2])
1
22,811,968
null
2
2
import sys import itertools # import numpy as np import time import math sys.setrecursionlimit(10 ** 7) from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(input()) c = [[0 for i in range(10)] for _ in range(10)] def f(n): x = 0 while n > 0: n //= 10 x +=1 return x for i in range(1, N + 1): d = f(i) front = i // (10 ** (d - 1)) back = i % 10 c[front][back] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): ans += c[i][j] * c[j][i] print(ans)
N = int(input()) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr L1 = factorization(N - 1) s = 1 # print(L1) for [a, b] in L1: s *= (b + 1) # print(s) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] for i in set(make_divisors(N))-{1}: temp = N while temp % i == 0: temp //= i if (temp-1) % i == 0: s += 1 s -= 1 if N == 2: print(1) else: print(s)
0
null
63,667,770,169,220
234
183
import math a, b, x = map(int, input().split()) if x == (a**2*b)/2: print(45) elif x > (a**2*b)/2: print(math.degrees(math.atan((2*(b-x/(a**2)))/a))) else: print(math.degrees(math.atan(a*b**2/(2*x))))
import numpy as np a, b, x = map(int,input().split()) th = a**2 * b / 2 if x <= th: ans = np.arctan(a*b**2/2/x) else: ans = np.arctan((2*b-2*x/a**2)/a) print(np.degrees(ans))
1
162,821,695,284,010
null
289
289
print("bust" if sum(map(int, input().split())) > 21 else "win")
A = list(map(int,input().split())) if sum(A) > 21:print("bust") else:print('win')
1
118,944,406,785,314
null
260
260
n, k = map(int,input().split()) count = 0 while True: n = n//k count += 1 if n <1: break print(count)
N,R=map(int,input().split()) num=0 while N>=R: N=N/R num+=1 print(num if N==0 else num+1)
1
64,321,488,084,700
null
212
212
# coding: UTF-8 from collections import deque dll = deque() n = int(input()) for _ in range(n): raw = input().split() command = raw[0] if command == 'delete': value = raw[1] try: dll.remove(value) except ValueError as err: continue elif command == 'insert': value = raw[1] dll.appendleft(value) elif command == 'deleteFirst': try: dll.popleft() except IndexError as err: continue elif command == 'deleteLast': try: dll.pop() except IndexError as err: continue print(" ".join(dll))
import sys class Node(): def __init__(self, key=None, prev=None, next=None): self.key = key self.prev = prev self.next = next class DoublyLinkedList(): def __init__(self): self.head = Node() self.head.next = self.head self.head.prev = self.head def insert(self, x): node = Node(key=x, prev=self.head, next=self.head.next) self.head.next.prev = node self.head.next = node def search(self, x): node = self.head.next while node is not self.head and node.key != x: node = node.next return node def delete_key(self, x): node = self.search(x) self._delete(node) def _delete(self, node): if node is self.head: return None node.prev.next = node.next node.next.prev = node.prev def deleteFirst(self): self._delete(self.head.next) def deleteLast(self): self._delete(self.head.prev) def getKeys(self): node = self.head.next keys = [] while node is not self.head: keys.append(node.key) node = node.next return " ".join(keys) L = DoublyLinkedList() n = int(input()) for i in sys.stdin: if 'insert' in i: x = i[7:-1] L.insert(x) elif 'deleteFirst' in i: L.deleteFirst() elif 'deleteLast' in i: L.deleteLast() elif 'delete' in i: x = i[7:-1] L.delete_key(x) else: pass print(L.getKeys())
1
50,178,509,348
null
20
20
import sys def I(): return int(sys.stdin.readline().rstrip()) def S(): return sys.stdin.readline().rstrip() N = I() ST = [tuple(map(str,S().split())) for _ in range(N)] X = S() ans = 0 for i in range(N): s,t = ST[i] ans += int(t) if s == X: break print(sum(int(ST[i][1]) for i in range(N))-ans)
def gcd(a,b): for i in range(1,min(a,b)+1): if a%i ==0 and b % i ==0: ans = i return ans x =int(input()) print(360//gcd(360,x))
0
null
55,213,649,898,870
243
125
N = int(input()) words = list(input()) ct_R = words.count('R') ct_W = words.count('W') a = words[0:ct_R] W_in_a_count = a.count('W') print(W_in_a_count)
MOD = 10**9 + 7 n, a, b = map(int, input().split()) def comb(n, k): x, y = 1, 1 for i in range(n, n-k, -1): x = x * i % MOD for i in range(1, k+1): y = y * i % MOD return x*pow(y, MOD-2, MOD) % MOD ans = (pow(2, n, MOD)-1-comb(n,a)-comb(n,b)) % MOD print(ans)
0
null
36,311,130,903,464
98
214
num = int(input()) l = ['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(l[num - 1])
arr = "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".split(", ") K = int(input()) print(arr[K-1])
1
49,968,570,511,652
null
195
195
s = input() t = input() slist = list(s) tlist = list(t) count = 0 if len(slist)+1 == len(tlist): for i in range(len(slist)): if slist[i] == tlist[i]: count += 1 if count ==len(slist): print("Yes") else: print("No") break else: print("No")
n = input() x = input() if n == x[:-1]: if len(x) - len(n) == 1: print('Yes') else: print('No')
1
21,317,797,010,110
null
147
147
while True: line = input() if line=='-': break loop = int(input()) for i in range(loop): x = int(input()) line = line[x:] + line[:x] print(line)
N = int(input()) d = {} for i in range(N): key = input() try: d[key] += 1 except KeyError: d[key] = 1 d = sorted(d.items(), key=lambda x: x[1], reverse=True) ans = [] max = 0 for i in d: if i[1] >= max: ans.append(i[0]) max = i[1] else: break for i in sorted(ans): print(i)
0
null
35,936,055,900,060
66
218
import sys import io, os #input = sys.stdin.buffer.readline input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline h, w, m = map(int, input().split()) R = [0]*h C = [0]*w YX = [] for i in range(m): y, x = map(int, input().split()) y, x = y-1, x-1 R[y] +=1 C[x] +=1 YX.append((y, x)) max_r = max(R) max_c = max(C) cr = 0 cc = 0 for i in range(h): if R[i] == max_r: cr += 1 for i in range(w): if C[i] == max_c: cc +=1 c = 0 for y, x in YX: if R[y] == max_r and C[x] == max_c: c += 1 if c < cr*cc: print(max_r+max_c) else: print(max_r+max_c-1)
H,W,M=map(int,input().split()) h,w=map(list,zip(*[list(map(int,input().split())) for i in range(M)])) from collections import Counter hc,wc=Counter(h),Counter(w) hx,wx=hc.most_common()[0][1],wc.most_common()[0][1] hl,wl=set([k for k,v in hc.items() if v==hx]),set([k for k,v in wc.items() if v==wx]) x=sum([1 for i in range(M) if h[i] in hl and w[i] in wl]) print(hx+wx if len(hl)*len(wl)-x else hx+wx-1)
1
4,687,878,497,248
null
89
89
from collections import defaultdict INF = float("inf") N, *A = map(int, open(0).read().split()) I = defaultdict(lambda: -INF) O = defaultdict(lambda: -INF) O[(0, 0)] = 0 for i, a in enumerate(A, 1): j = (i - 1) // 2 for n in [j, j + 1]: I[(i, n)] = a + O[(i - 1, n - 1)] O[(i, n)] = max(O[(i - 1, n)], I[(i - 1, n)]) print(max(I[(N, N // 2)], O[(N, N // 2)]))
a,b = list(map(int, input().split())) c = 2 * (a+ b) d = a * b print(str(d) + " " + str(c))
0
null
18,838,186,858,120
177
36
n,m = map(int,input().split()) matrix = [[0 for i in range(m)] for j in range(n)] b = [0 for i in range(m)] c = [0 for i in range(n)] for i in range(0,n): matrix[i] = list(map(int,input().split())) for i in range(0,m): b[i] = int(input()) for i in range(0,n): for j in range(0,m): c[i] += matrix[i][j]*b[j] print(c[i])
N, M = map(int, raw_input().split()) matrix = [map(int, raw_input().split()) for n in range(N)] array = [input() for m in range(M)] for n in range(N): c = 0 for m in range(M): c += matrix[n][m] * array[m] print c
1
1,158,732,884,572
null
56
56
# author: Taichicchi # created: 15.09.2020 21:22:26 import sys X, K, D = map(int, input().split()) X = abs(X) if X >= K * D: print(X - (K * D)) else: k = K - X // D x = X - D * (X // D) if k % 2: print(abs(x - D)) else: print(x)
n,m,l=map(int,input().split()) A=[list(map(int,input().split())) for i in range(n)] B=[list(map(int,input().split())) for i in range(m)] C=[[0]*l for i in range(n)] for x in range(n): for y in range(l): for z in range(m): C[x][y] += A[x][z]*B[z][y] for row in range(n): print("%d"%(C[row][0]),end="") for col in range(1,l): print(" %d"%(C[row][col]),end="") print()
0
null
3,333,487,566,500
92
60
while True: x = input() if x == '0': break print(sum(list(map(int,list(x)))))
while 1: x = list(raw_input()) if int(x[0]) == 0: break sum = 0 for n in x: sum += int(n) print sum
1
1,589,104,161,568
null
62
62
n, m = [int(i) for i in input().split()] matrix = [] for ni in range(n): matrix.append([int(a) for a in input().split()]) vector = [] for mi in range(m): vector.append(int(input())) b = [] for ni in range(n): sum = 0 for mi in range(m): sum += matrix[ni][mi] * vector[mi] print(sum)
while True : try : a = [int(_) for _ in input().split()] print(len(str(sum(a)))) except : break
0
null
576,580,873,792
56
3
A, B, M = map(int, input().split()) lis_a = list(map(int, input().split())) lis_b = list(map(int, input().split())) lis_price = [] lis_price.append(min(lis_a) + min(lis_b)) for i in range(M): x, y, c = map(int,input().split()) lis_price.append(lis_a[x-1] + lis_b[y-1] - c) print(min(lis_price))
N=int(input()) K=[int(n) for n in input().split()] S=sum(K) total=0 for i in range(N): S-=K[i] total+=K[i]*S print(total %(10**9+7))
0
null
28,787,355,099,648
200
83
n = int(input()) minv = int(input()) maxv = -2*10**9 for i in range(n-1): r = int(input()) maxv = max(maxv,r-minv) minv = min(minv,r) print(maxv)
s = input() print('Yes') if s[2:3] == s[3:4] and s[4:5] == s[5:6] else print('No')
0
null
21,110,760,698,620
13
184
S = input() bb = 'x'*len(S) print(bb)
a=int(input()) b,c=map(int,input().split()) x=(b//a)*a if b<=x<=c: print("OK") elif b<=x+a<=c: print("OK") else: print("NG")
0
null
49,622,779,142,358
221
158
N,K=map(int,input().split()) R,S,P=map(int,input().split()) T=input()+'*'*K h=['']*N f,n='','' ans=0 for i in range(N): if K<=i:f=h[i-K] n=T[i+K] if T[i]=='r': if f=='p':h[i]=n else:ans+=P;h[i]='p' if T[i]=='p': if f=='s':h[i]=n else:ans+=S;h[i]='s' if T[i]=='s': if f=='r':h[i]=n else:ans+=R;h[i]='r' print(ans)
from math import ceil def point(x,y,r,s,p): if y == 'r': y = p if y == 's': y = r if y == 'p': y = s return ceil(x/2) * y n,k = map(int,input().split()) r,s,p = map(int,input().split()) t = list(input()) ans = 0 for _ in range(k): l = t[_::k] x = 1 y = l[0] for i in l[1:]: if i != y: ans += point(x,y,r,s,p) x = 1 y = i else: x += 1 ans += point(x,y,r,s,p) print(ans)
1
106,599,171,598,110
null
251
251
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) class UnionFindPathCompression(): def __init__(self, n): self.parents = list(range(n)) self.rank = [1]*n self.size = [1]*n def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): px = self.find(x) py = self.find(y) if px == py: return else: if self.rank[px] < self.rank[py]: self.parents[px] = py self.size[py] += self.size[px] else: self.parents[py] = px self.size[px] += self.size[py] #ランクの更新 if self.rank[px] == self.rank[py]: self.rank[px] += 1 N,M = map(int,input().split()) ufpc = UnionFindPathCompression(N) for i in range(M): a,b = map(int,input().split()) ufpc.union(a-1,b-1) ans = 0 for i in range(N-1): if ufpc.find(i) != ufpc.find(i+1): ufpc.union(i,i+1) ans += 1 print(ans)
tmp = 0 while True: i = raw_input().strip().split() a = int(i[0]) b = int(i[1]) if a == 0 and b == 0: break if a > b: tmp = a a = b b = tmp print a,b
0
null
1,382,795,134,334
70
43