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
# D - Road to Millionaire def million(n, a): wallet = 1000 i = 0 while i < n - 1: highest_price = a[i] cheapest_price = a[i] # 直近の最高値と最安値を取得する for j in range(i + 1, n): if highest_price > a[j]: break if highest_price < a[j]: highest_price = a[j] if cheapest_price > a[j]: cheapest_price = a[j] if highest_price > cheapest_price: # 取引する stock = wallet // cheapest_price wallet = wallet - stock * cheapest_price wallet = wallet + stock * highest_price i = j else: i += 1 return wallet if __name__ == "__main__": n = int(input()) a = list(map(int, input().split())) print(million(n, a))
n = int(input()) a = list(map(int,input().split())) m = 1000 stocks = 0 drops = [False]*(n-1) for i in range(n-1): if a[i] > a[i+1]: drops[i] = True for i in range(n-1): if drops[i]: m+=stocks*a[i] stocks = 0 else: stocks+=m//a[i] m -= (m//a[i])*a[i] print(m + stocks*a[-1])
1
7,323,042,223,298
null
103
103
X = input() l = len(X) m = l//2 if (X == 'hi'*m): print("Yes") else: print("No")
def merge(cnt, A, left, mid, right): L = A[left:mid] + [1e+99] R = A[mid:right] + [1e+99] i = 0 j = 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 cnt.append(right - left) def mergeSort(cnt, A, left, right): if left+1 < right: mid = (left + right) // 2 mergeSort(cnt, A, left, mid) mergeSort(cnt, A, mid, right) merge(cnt, A, left, mid, right) import sys def input(): return sys.stdin.readline()[:-1] n = int(input()) S = list(map(int, input().split())) from collections import deque cnt = deque() mergeSort(cnt,S,0,n) print(*S) print(sum(cnt))
0
null
26,630,976,849,344
199
26
# coding=utf-8 def fib(number): if number == 0 or number == 1: return 1 memo1 = 1 memo2 = 1 for i in range(number-1): memo1, memo2 = memo1+memo2, memo1 return memo1 if __name__ == '__main__': N = int(input()) print(fib(N))
import sys input = sys.stdin.readline def main(): n = int(input()) fib = [1] * 46 for i in range(2, 46): fib[i] = fib[i - 1] + fib[i - 2] ans = fib[n] print(ans) if __name__ == "__main__": main()
1
1,950,725,670
null
7
7
import sys import numpy as np N = input() print(N[0:3])
S, T = input(), input() print(sum(x != y for x, y in zip(S, T)))
0
null
12,665,063,980,516
130
116
N, K = map(int, input().split()) start = sum(range(K)) end = sum(range(N-K+1, N+1)) count = 0 #print(start, end) for k in range(K, N + 2): count += end - start + 1 count %= 1000000007 start += k end += (N-k) print(count)
print(2**int(input()).bit_length()-1)
0
null
56,742,713,224,470
170
228
import math A,B,H,M=map(int,input().split()) x=2*math.pi*abs(H/12+M/60/12-M/60) ans=pow(A*A+B*B-2*A*B*math.cos(x),1/2) print(ans)
nums = [] while True: in_line = raw_input().split() h = int(in_line[0]) w = int(in_line[1]) if h == 0 and w == 0: break else: nums.append([h,w]) for num in nums: for i in range(0,num[0]): if i == 0 or i == num[0]-1: print "#"*num[1] else: print "#" + "."*(num[1]-2) + "#" print ""
0
null
10,539,759,141,894
144
50
n, m, l = map(int, input().split()) mat_a = [] mat_b = [] for i in range(n): mat_a.append(list(map(int, input().split()))) for j in range(m): mat_b.append(list(map(int, input().split()))) for p in range(n): mat_c = [] for q in range(l): sum = 0 for r in range(m): sum += mat_a[p][r] * mat_b[r][q] mat_c.append(sum) print(' '.join(map(str, mat_c)))
n, m, l = map(int, input().split()) # n = 3, c = 2, l = 3 a_matrix = [list(map(int, input().split())) for row in range(n)] # [[1, 2], [0, 3], [4, 5]] b_matrix = [list(map(int, input().split())) for row in range(m)] # [[1, 2, 1], [0, 3, 2]] result_matrix = [[0 for x in range(l)] for y in range(n)] # [[0, 0, 0], [0, 0, 0], [0, 0, 0]] for i in range(n): for j in range(l): for k in range(m): result_matrix[i][j] += a_matrix[i][k] * b_matrix[k][j] for i in range(n): print(' '.join(map(str, result_matrix[i])))
1
1,437,477,349,570
null
60
60
W = input() count = 0 while True: line = input() if line == 'END_OF_TEXT': break for s in line.lower().split(): if s == W: count += 1 print(count)
# 19-String-Finding_a_Word.py # ?????????????´¢ # ??????????????? W ??¨?????? T ????????????????????????T ??????????????? W ?????°???????????????????????°????????????????????????????????? # ?????? T ????????????????????????????????????????????§????????????????????????????????? Ti ??¨???????????? # ???????????? Ti ?????????????????? W ??¨??????????????????????????°?????????????????? # ???????????§????????¨?°???????????????\??????????????? # Constraints # W????????????????????????10????¶???????????????? # T??????????????????????????????????????????1000????¶???????????????? # Input # ?????????????????? W ???????????????????????? # ?¶???????????????°????????????????????£?????????????????????????????? # END_OF_TEXT ??¨?????????????????????????????????????????????????????? # Output # ?????? W ?????°??????????????????????????? # Sample Input # computer # Nurtures computer scientists and highly-skilled computer engineers # who will create and exploit "knowledge" for the new era. # Provides an outstanding computer environment. # END_OF_TEXT # Sample Output # 3 # Note import re count=0 w = input().lower() while 1: string = input() if string=="END_OF_TEXT": break; string=string.lower().split() for i in string: count += w==i print(count)
1
1,822,247,012,172
null
65
65
X, Y, R, G, N = map(int, input().split()) r = [int(x) for x in input().split()] g = [int(x) for x in input().split()] n = [int(x) for x in input().split()] r = sorted(r)[R-X:] g = sorted(g)[G-Y:] apple = r + g + n apple = sorted(apple)[len(apple)-(X+Y):] print(sum(apple))
import numpy as np import sys input = sys.stdin.readline def main(): N,M = map(int, input().split()) A = np.array(sorted([int(i) for i in input().split()])) left = 0 right = A[-1] * 2 + 5 while right - left > 1: x = (left + right) // 2 count = N**2 - np.searchsorted(A, x-A).sum() if count >= M: left = x else: right = x bound = np.searchsorted(A, left-A) count = N**2 - bound.sum() diff = count - M ans = ((N - bound) * A * 2).sum() - diff * left print(ans) if __name__ == "__main__": main()
0
null
76,511,279,993,380
188
252
#!python3 from collections import deque LI = lambda: list(map(int, input().split())) # input N, M = LI() S = input() INF = 10 ** 6 def main(): w = [(INF, INF)] * (N + 1) w[0] = (0, 0) # (cost, index) dq = deque([(0, 0)]) for i in range(1, N + 1): if i - dq[0][1] > M: dq.popleft() if len(dq) == 0: print(-1) return if S[i] == "0": w[i] = (dq[0][0] + 1, i - dq[0][1]) dq.append((w[i][0], i)) ans = [] x = N while x > 0: d = w[x][1] ans.append(d) x -= d ans = ans[::-1] print(*ans) if __name__ == "__main__": main()
N, M = map(int, input().split()) S = input() index = N count = 0 history = [] while index > 0: start = max(0, index - M) for i, c in enumerate(S[start:index], start=start): if c == '0': history.append(index - i) index = i count += 1 break else: print(-1) exit() print(*history[::-1])
1
138,995,170,819,700
null
274
274
import numpy as np a,b,h,m = map(int,input().split()) pos1 = [b*np.sin(np.radians(6*m)),b*np.cos(np.radians(6*m))] pos2 = [a*np.sin(np.radians(30*h+m*(360/(12*60)))),a*np.cos((np.radians(30*h+m*(360/(12*60)))))] d = ((pos1[0]-pos2[0])**2+(pos1[1]-pos2[1])**2)**0.5 print(d) #print(pos1) #print(pos2)
import sys array = list(map(int,input().split())) if not ( 1 <= min(array) and max(array) <= 100 ): sys.exit() check = lambda x: isinstance(x,int) print(array[2],array[0],array[1])
0
null
29,103,892,302,980
144
178
import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline n, u, v = map(int, input().split()) u, v = u - 1, v - 1 graph = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) def dfs(v, d, count): count[v] = d for v_next in graph[v]: if count[v_next] >= 0: continue dfs(v_next, d + 1, count) count_tak = [-1] * n dfs(u, 0, count_tak) count_aok = [-1] * n dfs(v, 0, count_aok) ans = 0 for i in range(n): if count_tak[i] < count_aok[i]: ans = max(ans, count_aok[i] - 1) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) n, u, v = map(int, input().split()) GRAPH = {i:[] for i in range(1, n + 1)} for _ in range(n - 1): a, b = map(int, input().split()) GRAPH[a].append(b) GRAPH[b].append(a) def dfs(now, prev = 0): PARENT[now] = prev DEPTH[now] = DEPTH[prev] + 1 if len(GRAPH[now]) == 1: LEAVES.append((DEPTH[now], now)) for w in GRAPH[now]: if w == prev: continue next = w dfs(next, now) PARENT = {} DEPTH = {0:-1} LEAVES = [] dfs(v) PATH = {i:False for i in range(1, n + 1)} now = u while True: PATH[now] = True if now == v: break now = PARENT[now] LEAVES.sort(reverse = True) for leaf in LEAVES: now = leaf[1] while True: if PATH[now]: break now = PARENT[now] lca = now du, dv = DEPTH[u] - DEPTH[lca], DEPTH[lca] if du < dv: print(leaf[0] - 1) exit()
1
116,930,644,734,808
null
259
259
A = input() if A == "ABC": print("ARC") else: print("ABC")
print(input()[1] == "B" and "ARC" or "ABC")
1
24,314,974,809,956
null
153
153
h1, m1, h2, m2, k = list(map(int, input().split())) s = (h1*60)+m1 e = (h2*60)+m2 print(e-s-k)
h1, m1, h2, m2, k = map(int, input().split()) st = h1*60 + m1 end = h2*60 + m2 print(end-st-k)
1
18,120,404,734,422
null
139
139
import itertools n=int(input()) ab = [] for _ in range(n): a, b = (int(x) for x in input().split()) ab.append([a, b]) narabi = [0+i for i in range(n)] ans = 0 count = 0 for v in itertools.permutations(narabi, n): count += 1 tmp_len = 0 for i in range(1,n): x, y = abs(ab[v[i-1]][0]-ab[v[i]][0])**2, abs(ab[v[i-1]][1]-ab[v[i]][1])**2 tmp_len += (x + y)**0.5 ans += tmp_len print(ans/count)
# -*- coding: utf-8 -*- import sys index = int(input()) array = [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(int(array[index-1]))
0
null
99,434,416,478,738
280
195
h,w,k = map(int,input().split()) c = [] for i in range(0,h): c.append(input()) def white(c,r,co): count = 0 for i in range(0,h): for j in range(0,w): if r[i] != 0 and co[j] != 0 and c[i][j] == "#": count += 1 return count import itertools listr = list(itertools.product([0,1],repeat = h)) listc = list(itertools.product([0,1],repeat = w)) ans = 0 for i in range(0,2**h): for j in range(0,2**w): if white(c,listr[i],listc[j]) == k: ans += 1 print(ans)
cross_section = input() visited = {0: -1} height = 0 pools = [] for i, c in enumerate(cross_section): if c == '\\': height -= 1 elif c == '/': height += 1 if height in visited: width = i - visited[height] sm = 0 while pools and pools[-1][0] > visited[height]: _, volume = pools.pop() sm += volume pools.append((i, sm + width - 1)) visited[height] = i print(sum(v for _, v in pools)) print(len(pools), *(v for _, v in pools))
0
null
4,500,397,957,956
110
21
n, k = map(int, input().split()) d = 1 while n // k ** d >= 1: d += 1 print(d)
n, m = map(int,input().split()) class unionfind(): def __init__(self,n): self.li = [i for i in range(n+1)] self.group = [1]*(n+1) def find(self, x): while self.li[x]!=x: x = self.li[x] return x def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return; elif x>y: self.li[y] = x self.group[x] += self.group[y] else: self.li[x] = y self.group[y] += self.group[x] x = unionfind(n) ans = 0 for _ in range(m): a,b = map(int,input().split()) x.union(a,b) print(max(x.group))
0
null
34,163,564,447,360
212
84
import sys def solve(): a = [] for line in sys.stdin: a.append(int(line)) a.sort() a.reverse() for k in xrange(3): print a[k] if __name__ == '__main__': solve()
h, w, k = [int(i) for i in input().split()] c = [input() for i in range(h)] cnt = 0 for i in range(1 << h): bit_h = [0] * h for j in range(h): bit_h[j] = int(i & (1 << j) > 0) for j in range(1 << w): bit_w = [0] * w for l in range(w): bit_w[l] = int(j & (1 << l) > 0) cnt_t = 0 for m in range(h): for n in range(w): if bit_h[m] == 0 and bit_w[n] == 0 and c[m][n] == "#": cnt_t += 1 if cnt_t == k: cnt += 1 #print(cnt_t) print(cnt)
0
null
4,467,693,503,360
2
110
while True: m, f, r = (int(x) for x in input().split()) if (m, f, r) == (-1, -1, -1): break sum_score = m + f if m == -1 or f == -1: print("F") elif sum_score >= 80: print("A") elif 65 <= sum_score < 80: print("B") elif 50 <= sum_score < 65: print("C") elif 30 <= sum_score < 50: print("C") if r >= 50 else print("D") else: print("F")
MOD = 2019 def solve(S): N = len(S) dp = [0 for _ in range(MOD)] tmp = 0 ret = 0 for i in range(N - 1, -1, -1): m = (tmp + int(S[i]) * pow(10, N - i - 1, MOD)) % MOD ret += dp[m] dp[m] += 1 tmp = m ret += dp[0] return ret if __name__ == "__main__": S = input() print(solve(S))
0
null
15,979,203,375,550
57
166
class Combination: """ O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms) 使用例: comb = Combination(1000000) print(comb(5, 3)) # 10 """ def __init__(self, n_max, mod=10**9+7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): if n < r: return 0 return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n+1): fac.append(fac[i-1] * i % self.mod) facinv.append(facinv[i-1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n+1) modinv[1] = 1 for i in range(2, n+1): modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod return modinv def main(): n, k = map(int,input().split()) MOD = 10 ** 9 + 7 comb = Combination(10 ** 6) ans = 0 if n - 1 <= k: ans = comb(n + n - 1, n) else: ans = 1 for i in range(1,k+1): ans += comb(n,i) * comb(n - 1, i) ans %= MOD print(ans) if __name__ == "__main__": main()
X,Y=map(int,input().split()) b=0 for i in range(X+1): if 4*(i)+2*(X-i)==Y: b+=1 if not b==0: print("Yes") else: print("No")
0
null
40,405,611,389,250
215
127
import math a,b,c,d = map(int,input().split()) print('Yes' if math.ceil(c/b) <= math.ceil(a/d) else 'No')
n=int(input()) a,b=[],[] for i in range(n): A,B=map(int,input().split()) a.append(A) b.append(B) a.sort() b.sort(reverse=True) ans=0 if n%2==1: s=a[n//2] g=b[n//2] ans=g-s+1 else: s1,s2=a[n//2-1],a[n//2] g2,g1=b[n//2-1],b[n//2] ans=(g2+g1)-(s2+s1)+1 print(ans)
0
null
23,500,071,760,860
164
137
import sys input = sys.stdin.readline from collections import * def bfs(s): q = deque([s]) dist = [-1]*N dist[s] = 0 leaf = set() while q: v = q.popleft() flag = True for nv in G[v]: if dist[nv]==-1: dist[nv] = dist[v]+1 q.append(nv) flag = False if flag: leaf.add(v) return dist, leaf N, u, v = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(N-1): A, B = map(int, input().split()) G[A-1].append(B-1) G[B-1].append(A-1) d1, _ = bfs(u-1) d2, leaf = bfs(v-1) ans = 0 for i in range(N): if i not in leaf and d1[i]<=d2[i]: ans = max(ans, d2[i]) print(ans)
import sys read = sys.stdin.readline import time import math import itertools as it def inp(): return int(input()) def inpl(): return list(map(int, input().split())) start_time = time.perf_counter() # ------------------------------ n, a, b = inpl() l = n // (a + b) m = n % (a + b) print(a * l + min(m, a)) # ----------------------------- end_time = time.perf_counter() print('time:', end_time-start_time, file=sys.stderr)
0
null
86,508,295,829,448
259
202
import math a, b, deg = map(float, input().split()) rad = math.radians(deg) area = 0.5 * a * b * math.sin(rad) c = math.sqrt(a*a + b*b - 2*a*b*math.cos(rad)) h = area*2 / a; print(area, a+b+c, h)
import math a, b, C = map(int,input().split()); c = math.radians(C) print((1/2)*a*b*math.sin(c)); print(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(c))); print(b*math.sin(c));
1
174,938,628,452
null
30
30
N = int(input()) #リスト内包表記 Ss = [input() for _ in range(N)] Ss_set = set(Ss) print(len(Ss_set))
if __name__ == "__main__": N = int(input()) hash = {} for i in range(N): hash[input()] = "" print(len(hash.keys()))
1
30,268,711,234,412
null
165
165
mask = {'N':(1, 5, 2, 3, 0, 4), 'E':(3, 1, 0, 5, 4, 2), 'S':(4, 0, 2, 3, 5, 1), 'W':(2, 1, 5, 0, 4,3)} dice = input().split() for c in input(): dice = [dice[i] for i in mask[c]] print(dice[0])
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)
0
null
2,477,561,071,650
33
89
a = [] b = [] n, m, l = [int(n) for n in input().split()] c = [[0 for i in range(l)] for j in range(n)] for i in range(n): a.append([int(n) for n in input().split()]) for i in range(m): b.append([int(n) for n in input().split()]) for i in range(n): for j in range(l): for k in range(m): c[i][j] += a[i][k] * b[k][j] for num in c: print(' '.join(str(n) for n in num))
numbers = input() numbers = numbers.split(" ") W = int(numbers[0]) H = int(numbers[1]) x = int(numbers[2]) y = int(numbers[3]) r = int(numbers[4]) if (r <= x <= W - r) and (r <= y <= H - r): print("Yes") else: print("No")
0
null
950,540,273,198
60
41
n=int(input()) c=0 for i in range(1,n+1): if i%2!=0: c+=1 print("{0:.10f}".format(c/n))
from sys import stdin,stdout def INPUT():return list(int(i) for i in stdin.readline().split()) import math def inp():return stdin.readline() def out(x):return stdout.write(x) import math as M MOD=10**9+7 import random ##################################### k=int(input()) if k%2==0: print("{:.10f}".format(1/2)) else: print("{:.10f}".format((k//2+1)/k))
1
177,099,129,706,840
null
297
297
class BIT: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i class RangeUpdate: def __init__(self, n): self.p = BIT(n + 1) self.q = BIT(n + 1) def add(self, s, t, x): t += 1 self.p.add(s, -x * s) self.p.add(t, x * t) self.q.add(s, x) self.q.add(t, -x) def sum(self, s, t): t += 1 return self.p.sum(t) + self.q.sum(t) * t - \ self.p.sum(s) - self.q.sum(s) * s def main(): from string import ascii_lowercase dic = {s: i for i, s in enumerate(ascii_lowercase)} import sys input = sys.stdin.readline N = int(input()) S = [dic[s] for s in input().rstrip()] Q = int(input()) Query = [[i for i in input().split()] for _ in [0]*Q] BIT26 = [RangeUpdate(N) for _ in [0]*26] for i, j in enumerate(S, start=1): BIT26[j].add(i, i, 1) answer = [] for A in Query: if A[0] == "1": i = int(A[1]) j = S[i-1] BIT26[j].add(i, i, -1) j = dic[A[2]] S[i-1] = j BIT26[j].add(i, i, 1) else: le = int(A[1]) ri = int(A[2]) ans = 0 cur = 0 for i in range(26): v = BIT26[i].sum(le, ri) if 0 < v: ans += 1 cur += v if ri - le + 1 == v: break answer.append(ans) print(*answer, sep="\n") if __name__ == '__main__': main()
from math import log2, ceil class SegTree: #####単位元###### ide_ele = 0 def __init__(self, init_val): n = len(init_val) self.num = 2**ceil(log2(n)) self.seg = [self.ide_ele] * (2 * self.num - 1) for i in range(n): self.seg[i + self.num - 1] = init_val[i] # built for i in range(self.num - 2, -1, -1): self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) #####segfunc###### def segfunc(self, x, y): return x|y def update(self, k, x): k += self.num - 1 self.seg[k] = x while k: k = (k - 1) // 2 self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) def query(self, a, b, k, l, r): if r <= a or b <= l: return self.ide_ele if a <= l and r <= b: return self.seg[k] else: vl = self.query(a, b, k*2+1, l, (l+r)//2) vr = self.query(a, b, k*2+2, (l+r)//2, r) return self.segfunc(vl, vr) N = int(input()) S = input() Q = int(input()) li = [1 << (ord(s) - ord('a')) for s in S] seg_tree = SegTree(li) ans = [] for _ in range(Q): i, l, r = input().split() i = int(i) l = int(l) if i == 1: seg_tree.update(l-1, 1 << (ord(r) - ord('a'))) else: r = int(r) num = seg_tree.query(l-1, r, 0, 0, seg_tree.num) ans.append(bin(num).count('1')) for a in ans: print(a)
1
62,634,101,361,172
null
210
210
rad = int(input()) print (2*3.1415926*rad)
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) p1 = p2 = p3 = pi = 0 for i in range(n): p1 += abs(a[i] - b[i]) p2 += (abs(a[i] - b[i]))**2 p3 += (abs(a[i] - b[i]))**3 if pi < abs(a[i] - b[i]): pi = abs(a[i] - b[i]) print("%f" % (p1)) print("%f" % (p2**(1/2))) print("%f" % (p3**(1/3))) print("%f" % (pi))
0
null
15,689,086,567,560
167
32
n = int(input()) a = list(map(int, input().split())) def selectionSort(a, n): count = 0 for i in range(n): mini = i for j in range(i, n): if a[j] < a[mini]: mini = j if i != mini: a[i],a[mini] = a[mini],a[i] count += 1 print(*a) print(count) selectionSort(a,n)
for i in range(9): i+=1 for n in range(9): n+=1 print str(i)+"x"+str(n)+"="+str(i*n)
0
null
11,164,804,740
15
1
N = int(input()) A = list(map(int,input().split())) bunretsu = sum(A) - 1 zanretsu = 1 souwa = 0 for i in range(N+1): souwa += zanretsu if A[i] <= zanretsu: zanretsu -= A[i] else: souwa = -1 break if bunretsu >= 1 and bunretsu <= zanretsu: zanretsu += bunretsu bunretsu = 0 elif bunretsu >= 1 and bunretsu > zanretsu: bunretsu -= zanretsu zanretsu *= 2 print(souwa)
n=input() a=map(int,raw_input().split()) INF=10**18 pr=[0]*(n+2) pr[0]=1 for i in xrange(n+1): pr[i+1]=min(INF,(pr[i]-a[i])*2) if pr[n+1]<0: print "-1" exit(0) s=0 ans=0 for i in xrange(n,-1,-1): s=min(s+a[i],pr[i]) ans+=s print ans
1
18,874,825,761,320
null
141
141
n = int(input()) L = list(map(int,input().split())) L.sort() import bisect ans = 0 for i in range(1,n): for j in range(i+1,n): tmp = L[:i] v = L[j]-L[i] idv = bisect.bisect_right(tmp,v) if idv!=len(tmp): ans += len(tmp)-idv print(ans)
import itertools while True: n, x = map(int, input().split()) if n == x == 0: break result = 0 for i in itertools.combinations(range(1, n + 1), 3): if sum(i) == x: result += 1 print(result)
0
null
86,576,862,929,612
294
58
#from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 #R = 998244353 def ddprint(x): if DBG: print(x) s = ins() t = ins() ls = len(s) lt = len(t) mn = BIG for i in range(ls-lt+1): x = 0 for j in range(lt): if s[i+j]!=t[j]: x += 1 mn = min(mn,x) print(mn)
s = input() t = input() ans = 1000 for idx in range(len(t), len(s)+1): tmp = 0 for s_s, t_s in zip(list(s[idx-len(t):idx]), list(t)): if not s_s == t_s: tmp += 1 if ans > tmp: ans = tmp print(ans)
1
3,648,732,452,220
null
82
82
C = input() ary = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(",") print(ary[ary.index(C) + 1])
l ='abcdefghijklmnopqrstuvwxyz' c = input() x = l.index(c) print(l[x + 1])
1
92,096,939,578,628
null
239
239
H, W = list(map(int, input().split())) ### 片方だけ奇数のマスには行くことができない ### Hが偶数、Wが偶数の場合 → H*W // 2 ### Hが奇数、Wが偶数の場合 → H*W // 2 (Wが奇数の場合も同様) ### Hが奇数、Wが奇数の場合 → H*W // 2 + 1 if H == 1 or W == 1: print(1) elif H % 2 != 0 and W % 2 != 0: print(int(H * W // 2) + 1) else: print(int(H * W // 2))
while True: n = input() if n == '0': break print(sum([int(x) for x in n]))
0
null
26,056,064,452,356
196
62
A, B, C = list(map(int, input().split())) K = int(input()) res = 0 while True: if B <= A: B *= 2 res += 1 else: break while True: if C <= B: C *= 2 res += 1 else: break if res <= K: print("Yes") else: print("No")
R, G, B = map(int, input().split()) K = int(input()) for _ in range(K): if G <= R: G *= 2 elif B <= G: B *= 2 print('Yes' if R < G < B else 'No')
1
6,839,493,006,708
null
101
101
L, R, d = map(int, input().split()) a = 0 for i in range(L,R+1): if i%d==0: a += 1 else: a += 0 print(a)
''' Created on 2020/08/29 @author: harurun ''' def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write A,B,N=map(int,pin().split()) x=min(B-1,N) ans=int(A*x/B)-A*int(x/B) print(ans) return main() #解説AC
0
null
17,809,559,135,552
104
161
from collections import deque def init_tree(x, par): for i in range(x + 1): par[i] = i def find(x, par): q = deque() q.append(x) while len(q) > 0: v = q.pop() if v == par[v]: return v q.append(par[v]) def union(x, y, par, rank): px, py = find(x, par), find(y, par) if px == py: return if rank[px] < rank[py]: par[px] = py return elif rank[px] == rank[py]: rank[px] += 1 par[py] = px n, m, k = map(int, input().split()) par = [0] * (n + 1) rank = [0] * (n + 1) init_tree(n, par) eg = [[] for _ in range(n + 1)] for _ in range(m): a, b = map(int, input().split()) union(a, b, par, rank) eg[a].append(b) eg[b].append(a) for _ in range(k): a, b = map(int, input().split()) eg[a].append(b) eg[b].append(a) xs = [0] * (n + 1) ys = [0] * (n + 1) for i in range(1, n + 1): p = find(i, par) xs[p] += 1 for v in eg[i]: if p == find(v, par): ys[i] += 1 ans = [-1] * (n + 1) for i in range(1, n + 1): ans[i] += xs[find(i, par)] - ys[i] ans = [-1] * (n + 1) for i in range(1, n + 1): ans[i] += xs[find(i, par)] - ys[i] print(*ans[1:])
import sys class UnionFind: def __init__(self, n): self.table = [-1] * n def _root(self, x): stack = [] tbl = self.table while tbl[x] >= 0: stack.append(x) x = tbl[x] for y in stack: tbl[y] = x return x def find(self, x, y): return self._root(x) == self._root(y) def union(self, x, y): r1 = self._root(x) r2 = self._root(y) if r1 == r2: return d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.table[r1] += d2 else: self.table[r1] = r2 self.table[r2] += d1 def main(): n, m, k = map(int, sys.stdin.buffer.readline().split()) uf = UnionFind(n) fb = [0]*n i = 0 for x in sys.stdin.buffer.readlines(): if i < m: a, b = map(int, x.split()) fb[a-1] += 1 fb[b-1] += 1 uf.union(a-1, b-1) else: c, d = map(int, x.split()) if uf._root(c-1) == uf._root(d-1): fb[c-1] += 1 fb[d-1] += 1 i += 1 ans = [-uf.table[uf._root(i)]-1-fb[i] for i in range(n)] print(*ans) if __name__ == "__main__": main()
1
61,933,157,821,740
null
209
209
n = int(raw_input()) _min, dif = 10**10, -10**10 for x in xrange(n): a = int(raw_input()) if a -_min > dif: dif = a - _min if a < _min: _min = a print dif
# -*- Coding: utf-8 -*- nums = int(input()) a = [int(input()) for i in range(nums)] minv = a[0] maxv = -2000000000 for i in range(1, nums): maxv = max(maxv, a[i] - minv) minv = min(minv, a[i]) print(maxv)
1
14,480,738,440
null
13
13
h1,m1,h2,m2,k = map(int,input().split()) okiteiru = (h2*60+m2)-(h1*60+m1) print(okiteiru - k)
#float型を許すな #numpyはpythonで import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI2(): return [int(input()) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf = 10**17 mod = 10**9 + 7 h,m,H,M,k=MI() l=(M-m)+60*(H-h) print(l-k)
1
18,124,211,243,898
null
139
139
Str = input() q = int(input()) for i in range(q): order = list(input().split()) o = order[0] a = int(order[1]) b = int(order[2]) if o=='print': print(Str[a:b+1]) if o=='reverse': StrL = list(Str) t = list(Str[a:b+1]) j = len(t)-1 for i in range(a,b+1): StrL[i] = t[j] j -= 1 Str = ''.join(StrL) if o=='replace': p = list(order[3]) StrL = list(Str) j = 0 for i in range(a,b+1): StrL[i] = p[j] j += 1 Str = ''.join(StrL)
str = input() q = int(input()) for i in range(q): args = input().split() order = args[0] a = int(args[1]) b = int(args[2]) if order == "print": print(str[a : b + 1]) elif order == "reverse": str = str[: a] + str[a : b + 1][: : -1] + str[b + 1 :] elif order == "replace": str = str[: a] + args[3] + str[b + 1 :]
1
2,089,247,023,682
null
68
68
S = input() if S == 'MON': print("6") elif S == 'TUE': print("5") elif S == 'WED': print("4") elif S == 'THU': print("3") elif S == 'FRI': print("2") elif S == 'SAT': print("1") elif S == 'SUN': print("7")
s = input() day = ['SAT','FRI','THU','WED','TUE','MON','SUN'] for i in range(7): if s == day[i]: print(i + 1) exit()
1
133,161,102,101,588
null
270
270
n = int(input()) print(n^1)
n = int(input()) al = 26 alf='abcdefghijklmnopqrstuvwxyz' na = '' while n >26: na = alf[(n-1)%al]+na n = (n-1)//al na = alf[(n-1)%al]+na print(na)
0
null
7,462,054,832,606
76
121
L, R, d = map(int, input().split()) count = 0 while L != R+1: if L%d == 0: count += 1 L += 1 print(count)
a,b,c=map(int,input().split()) n=b//c y=(a-1)//c print(n-y)
1
7,544,363,502,232
null
104
104
n,m = map(int,input().split()) alist = list(map(int,input().split())) d = n - sum(alist) if d < 0: print(-1) else: print(d)
N, M = [int(_) for _ in input().split()] A = [int(_) for _ in input().split()] print(max(N - sum(A), -1))
1
32,137,653,958,458
null
168
168
N = int(input()) if N%2 == 0: n = N/2 else: n = (N+1)/2 print(round(n))
a,b,c,k = map(int, input().split()) ans = min(a,k) k -= min(a,k) k -= min(b,k) ans -= k print(ans)
0
null
40,521,164,090,540
206
148
import sys def gcd(x, y): if y == 1: return 1 elif y == 0: return x else: return gcd(y, x % y) line = sys.stdin.readline() (a, b) = line.split() a = int(a) b = int(b) if a > b: b, a = a, b print gcd(a, b)
# C import math A,B = map(int,input().split()) for x in range(1100): if math.floor(x*0.08) == A and math.floor(x*0.1) == B: print(x) break else: print('-1')
0
null
28,326,372,978,172
11
203
n = int(input()) mod = 1000000007 def _mod(x, y): res = 1 for i in range(y): res = (res * x) % mod return res ans = _mod(10, n) - _mod(9, n) - _mod(9, n) + _mod(8, n) ans %= mod print(ans)
from math import factorial a = 0 b = 0 n, m = map(int,input().split()) if 1 < n: a = factorial(n) / factorial(2) / factorial(n - 2) if 1 < m: b = factorial(m) / factorial(2) / factorial(m - 2) print(int(a+b))
0
null
24,315,708,888,430
78
189
r=input().split() H=int(r[0]) N=int(r[1]) data_pre=input().split() data=[int(s) for s in data_pre] if sum(data)>=H: print("Yes") else: print("No")
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,189,118,366,898
null
226
226
import sys def input(): return sys.stdin.readline().rstrip() def main(): n=int(input()) print((n-1)//2) if __name__=='__main__': main()
N = int(input()) ans = 0 for a in range(1,N,1): ans = ans + (N-1)//a print(ans)
0
null
77,714,644,996,574
283
73
[N, M] = [int(i) for i in input().split()] H = [int(i) for i in input().split()] dic = {} for i in range(M): [a, b] = [int(i) for i in input().split()] if a in dic: dic[a].append(b) else: dic[a] = [b] if b in dic: dic[b].append(a) else: dic[b] = [a] ans = 0 for i in range(1, N+1): s = H[i-1] t = 0 if i in dic: for j in range(len(dic[i])): if s <= H[dic[i][j]-1]: t += 1 break if t == 0: ans += 1 else: ans += 1 print(ans)
a, b, c, k = map(int,input().split()) if k <= a: print(k) elif a < k <= a + b: print(a) elif a + b <= k: print(a*2 - k + b)
0
null
23,290,703,764,012
155
148
def main(): x = int(input()) cnt = x // 100 m, M = cnt * 100, cnt * 105 if m <= x <= M: print(1) else: print(0) if __name__ == "__main__": main()
def popcount(x): return bin(x).count("1") def solve(n): if n == 0: return 0 return 1+solve(n % popcount(n)) N = int(input()) X = input() num_x = int(X, 2) p_cnt = X.count('1') if p_cnt == 1: for i in range(N): if X[i] == '1': print(0) elif i == N-1: print(2) else: print(1) exit() r0_p = num_x % (p_cnt+1) r0_m = num_x % (p_cnt-1) for i in range(N): if X[i] == '0': c_p_cnt = p_cnt+1 r = (r0_p + pow(2, (N - 1 - i), c_p_cnt)) % c_p_cnt else: c_p_cnt = p_cnt-1 if c_p_cnt == 0: print(0) continue r = (r0_m- pow(2, (N - 1 - i), c_p_cnt)) % c_p_cnt print(1 + solve(r % c_p_cnt))
0
null
67,744,295,414,628
266
107
K = int(input()) ans = -1 keep = 0 check = 7 for i in range(K): keep = (keep + check) % K if keep == 0: ans = i + 1 break check = (check * 10) % K print(ans)
ni = lambda: int(input()) nm = lambda: map(int, input().split()) nl = lambda: list(map(int, input().split())) k = ni() a = [0]*(10**6+1) a[1] = 7%k for i in range(2,k+1): a[i] = (a[i-1]*10+7)%k for i in range(1,k+1): if a[i]==0: print(i) exit() print(-1)
1
6,049,453,211,648
null
97
97
k,n = [int(x) for x in input().split()] a = [int(x) for x in input().split()] c = a[0] + (k - a[n-1]) for i in range(1,n): c = max(c,a[i]-a[i-1]) print(k-c)
n = int(input()) print(n * n * n)
0
null
21,996,091,818,272
186
35
def main(): N,K=map(int,input().split()) res=0 MOD=10**9+7 for i in range(K,N+2): MAX=(N+(N-i+1))*i//2 MIN=(i-1)*i//2 res+=MAX-MIN+1 res%=MOD print(res%MOD) if __name__=="__main__": main()
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): N, K = map(int, input().split()) MOD = (10**9) + 7 ans = 0 for i in range(K, N + 2): ans += sum_of_arithmetic_progression(N, -1, i) - sum_of_arithmetic_progression(0, 1, i) + 1 ans %= MOD print(ans) def main(): solve() if __name__ == '__main__': main()
1
33,203,733,628,230
null
170
170
INF = int(1e9) def main(): n, m = map(int, input().split()) a = [int(i) for i in input().split()] a.sort() s = [0] for i in range(n): s.append(s[i]+a[i]) #Xより大きい要素の数を数える def counter(x): count = 0 for i in range(n): l = -1 r = n while r-l>1: mid = (l+r)//2 if a[i] + a[mid] > x: r = mid else: l = mid count += n-r return count #Xより大きい要素数がm個未満であるXのうち最大のものを探す l = 0 r = INF while r-l>1: mid = (l+r)//2 if counter(mid) < m: r = mid else: l = mid #lより大きい要素の総和を求める def sigma(x): cnt = 0 sgm = 0 for i in range(n): l = -1 r = n while r-l >1: mid = (l+r)//2 if a[i]+a[mid]>x: r = mid else: l = mid cnt += n-r sgm += a[i] * (n-r) + (s[n]-s[r]) return (sgm, cnt) sgm, cnt = sigma(l) ans = sgm+(m-cnt)*r print(ans) main()
import sys input=sys.stdin.readline import numpy as np from numpy.fft import rfft,irfft n,m=[int(j) for j in input().split()] l=np.array([int(j) for j in input().split()]) a=np.bincount(l) fft_len=1<<18 fft = np.fft.rfft ifft = np.fft.irfft Ff = fft(a,fft_len) x=np.rint(ifft(Ff * Ff,fft_len)).astype(np.int64) p=x.cumsum() i=np.searchsorted(p,n*n-m) q=n*n-m-p[i-1] ans=(x[:i]*np.arange(i,dtype=np.int64)).sum()+i*q print(int(l.sum()*2*n-ans))
1
107,861,951,878,756
null
252
252
n,k = map(int, input().split()) L = [i for i in range(1,n+1)] for _ in range(k): d = int(input()) a = sorted(list(map(int, input().split()))) for e in a: if e in L: L.remove(e) print(len(L))
s = input() p = input() s = s*2 if p in s: print('Yes') else: print('No')
0
null
13,047,266,790,862
154
64
N = int(input()) S = [input() for _ in range(N)] AC = 0 WA = 0 TLE = 0 RE = 0 for i in S: if i == 'AC': AC += 1 elif i == 'WA': WA += 1 elif i == 'TLE': TLE += 1 else: RE += 1 print('AC x', AC) print('WA x', WA) print('TLE x', TLE) print('RE x', RE)
n=int(input()) s=["AC","WA","TLE","RE"] c=[0]*4 for _ in range(n): c[s.index(input())]+=1 for s1,c1 in zip(s,c): print(f'{s1} x {c1}')
1
8,661,560,145,400
null
109
109
N = int(input()) judge = N%10 hon = [2,4,5,7,9] pon = [0,1,6,8] bon = [3] if judge in hon: print("hon") elif judge in pon: print("pon") elif judge in bon: print("bon")
n = str(input()) if n[-1] in ['2', '4', '5', '7', '9']: how_to_read = 'hon' elif n[-1] in ['0', '1', '6', '8']: how_to_read = 'pon' else: how_to_read = 'bon' print(how_to_read)
1
19,309,694,905,330
null
142
142
from collections import Counter def solve(): N = int(input()) S = list(input()) c = Counter(S) ans = c['R']*c['G']*c['B'] for i in range(N): for j in range(i+1,N): k = j*2-i if k>N-1: break if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]: ans -= 1 return ans print(solve())
N=int(input()) l=[[[0 for i in range(10)]for j in range(3)]for k in range(4)] for i in range(N): b, f, r, v = map(lambda x: int(x)-1, input().split()) l[b][f][r]+=v+1 for j in range(4): for k in l[j]: print(" "+" ".join(map(str, k))) if j < 3: print("####################")
0
null
18,585,176,584,688
175
55
x,k,d = map(int,input().split()) def judge(): l = x if x > 0 else -x i = l//d r = l%d if (k - i)%2 == 0: print(r) else: print(d - r) ''' if x > 0: for r in range(d): if (x - r)/d == (x - r)//d: i = (x - r)//d if (k - i)%2 == 0: print(r) else: print(d-r) exit() else: l = -x for r in range(d): if (l - r)/d == (l - r)//d: i = (l - r)//d if (k - i)%2 == 0: print(r) else: print(d-r) exit() ''' if x == 0: if k%2 == 0: print(0) else: print(d) elif x < 0: if k*d + x > 0: judge() else: print(abs(k*d + x)) else: if x - k*d < 0: judge() else: print(abs(x - k*d))
import math r = input() r = float(r) area = math.pi * (r ** 2) length = 2 * math.pi * r print("{0:.5f} {1:.5f}".format(area, length))
0
null
2,943,325,508,960
92
46
import math N , M = map(int,input().split())#N:展望台の数、M:道の数 H = list(map(int,input().split()))#H:高さの配列 AB = [map(int, input().split()) for _ in range(M)] A , B = [list(i) for i in zip(*AB)] G = [1] * N #展望台の数 for i in range (M): if H[ A[i] -1 ] > H[B[i] -1 ]: G[ B[i] -1 ] = 0 elif H[ A[i] -1] == H[ B[i] -1 ]: G[ A[i] -1 ] = 0 G[ B[i] -1 ] = 0 else: G[A[i] -1 ] = 0 print( G.count(1) )
n = int(input()) A = list(map(int ,input().split())) total = 0 for a in A: total ^= a print(*(total ^ a for a in A), sep='\n')
0
null
18,869,891,247,800
155
123
N = int(input()) S = [s for s in input()] ans = S.count("R") * S.count("G") * S.count("B") for i in range(N - 2): for j in range(i + 1, N - 1): k = j + (j - i) if N - 1 < k: continue if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]: ans -= 1 print(ans)
N = int(input()) S = input() R = [] G = [] B = [] for i in range(N): if S[i] == 'R': R.append(i+1) elif S[i] == 'G': G.append(i+1) elif S[i] == 'B': B.append(i+1) lenb = len(B) cnt = 0 for r in R: for g in G: up = max(r, g) down = min(r, g) diff = up - down chk = 0 if up + diff <= N: if S[up+diff-1] == 'B': chk += 1 if down-diff >= 1: if S[down-diff-1] == 'B': chk += 1 if diff%2 == 0: if S[int(up-diff/2-1)] == 'B': chk += 1 cnt += lenb - chk print(cnt)
1
36,233,728,884,416
null
175
175
num = 0 def marge_sort(array): global num if len(array) < 2: return array mid = len(array) // 2 left = marge_sort(array[:mid]) right = marge_sort(array[mid:]) len_l, len_r = len(left), len(right) left += [float("inf")] right += [float("inf")] marray = [0] * (len_l + len_r) l, r = 0, 0 for i in range(len_l + len_r): num += 1 if left[l] <= right[r]: marray[i] = left[l] l += 1 else: marray[i] = right[r] r += 1 return marray n = int(input()) a = list(map(int, input().split())) print(" ".join(map(str, marge_sort(a)))) print(num)
X = int(input()) a = [] c = [] if X % 2 == 1: while a == []: for i in range(3,X,2): b = X % i a.append(b) if 0 in a: a = [] X += 1 else: print(X) elif X == 2: print(X) else: X += 1 while c == []: for i in range(3,X,2): d = X % i c.append(d) if 0 in c: c = [] X += 1 else: print(X)
0
null
53,022,183,859,040
26
250
N = int(input()) flag = False for i in range(1, 10): if N//i <= 9 and N%i == 0: flag = True if flag: print("Yes") else: print("No")
x = [1,2,3,4,5,6,7,8,9] y = [1,2,3,4,5,6,7,8,9] for w in x : for c in y : print(w,"x",c,"=",w*c,sep="")
0
null
79,990,566,199,972
287
1
N, A, B = map(int, input().split()) dif = abs(A-B) if dif%2 == 0: ans = dif//2 else: #A left t0 = A - 1 + 1 xa = 0 xb = B - t0 dif = abs(xb - xa) ans1 = dif//2 + t0 #B left t0 = B - 1 + 1 xa = A - t0 xb = 0 dif = abs(xb - xa) ans2 = dif//2 + t0 #A right t0 = N - A + 1 xa = N xb = B + t0 dif = abs(xb - xa) ans3 = dif//2 + t0 #B right t0 = N - B + 1 xa = A + t0 xb = N dif = abs(xb - xa) ans4 = dif//2 + t0 ans = min(ans1, ans2, ans3, ans4) print(ans)
x=[] N,A,B=map(int,input().split()) if (B-A)%2==0: print((B-A)//2) else: c=(A-1)+(B-A+1)//2 d=(N-B)+(B-A+1)//2 print(min(c,d))
1
109,921,733,060,832
null
253
253
N = int(input()) ans = [0 for i in range(10**4+1)] for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): n = x*x + y*y + z*z + x*y + y*z + z*x if n <= 10**4: ans[n] += 1 for i in range(1, N+1): print(ans[i])
A = [] for _ in range(3): a = [int(a) for a in input().split()] A.append(a) N = int(input()) for _ in range(N): num = int(input()) for i in range(3): for j in range(3): if A[i][j]==num: A[i][j] = -1 # Rows for row in range(3): bingo_row = True for col in range(3): if A[row][col]!=-1: bingo_row = False if bingo_row: print('Yes') exit() # Columns for col in range(3): bingo_col = True for row in range(3): if A[row][col]!=-1: bingo_col = False if bingo_col: print('Yes') exit() # Naname bingo_naname = True for i in range(3): col, row = i, i if A[row][col] != -1: bingo_naname = False if bingo_naname: print('Yes') exit() bingo_naname = True for i in range(3): col, row = 2-i, i if A[row][col] != -1: bingo_naname = False if bingo_naname: print('Yes') exit() print('No')
0
null
33,974,512,849,760
106
207
#セグ木 from collections import deque def f(L, R): return L|R # merge def g(old, new): return old^new # update zero = 0 #零元 class segtree: def __init__(self, N, z): self.M = 1 while self.M<N: self.M *= 2 self.dat = [z] * (self.M*2-1) self.ZERO = z def update(self, x, idx, l=0, r=-1): if r==-1: r = self.M idx += self.M-1 self.dat[idx] = g(self.dat[idx], x) while idx > 0: idx = (idx-1)//2 self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2]) def query(self, a, b=-1, idx=0, l=0, r=-1): if r==-1: r = self.M if b==-1: b = self.M q = deque([]) q.append([l, r, 0]) ret = self.ZERO while len(q): tmp = q.popleft() L = tmp[0] R = tmp[1] if R<=a or b<=L: continue elif a<=L and R<=b: ret = f(ret, self.dat[tmp[2]]) else: q.append([L, (L+R)//2, tmp[2]*2+1]) q.append([(L+R)//2, R, tmp[2]*2+2]) return ret n = int(input()) s = list(input()) q = int(input()) seg = segtree(n+1, 0) for i in range(n): num = ord(s[i]) - ord("a") seg.update((1<<num), i) for _ in range(q): a, b, c = input().split() b = int(b) - 1 if a == "1": pre = ord(s[b]) - ord("a") now = ord(c) - ord("a") seg.update((1<<pre), b) seg.update((1<<now), b) s[b] = c else: q = seg.query(b, int(c)) bin(q).count("1") print(bin(q).count("1"))
n = int(input()) S = input() r = S.count('R') w = 0 ans = r for i in range(n): if S[i] == "W": w += 1 elif S[i] == "R": r -= 1 ans = min(ans,max(r,w)) print(ans)
0
null
34,193,749,892,676
210
98
s=str(input().upper()) if s=="ABC": print("ARC") if s=="ARC": print("ABC")
s = raw_input() if s == "ARC": print "ABC" else: print "ARC"
1
24,005,438,913,888
null
153
153
def gcd(m, n): x = max(m, n) y = min(m, n) if x % y == 0: return y else: while x % y != 0: z = x % y x = y y = z return z def lcm(m, n): return (m * n) // gcd(m, n) # input A, B = map(int, input().split()) # lcm snack = lcm(A, B) print(snack)
a,b=map(int,input().split()) def factorization(n): arr = [] tmp = n for i in range(2, int(n**0.5//1)+1): if tmp%i==0: cnt = 0 while tmp%i==0: cnt+=1 tmp//=i arr.append([i,cnt]) if tmp!=1: arr.append([tmp,1]) if arr==[]: arr.append([n,1]) return arr a_arr = factorization(a) b_arr = factorization(b) a_map = {str(arr[0]):arr[1] for arr in a_arr} b_map = {str(arr[0]):arr[1] for arr in b_arr} factor = set(list(a_map.keys())+list(b_map.keys())) ans = 1 for i in factor: if str(i) in a_map.keys(): a_num = a_map[str(i)] else: a_num = 0 if str(i) in b_map.keys(): b_num = b_map[str(i)] else: b_num = 0 ans *= int(i)**(max(a_num,b_num)) print(ans)
1
113,361,771,824,722
null
256
256
N =int(input()) S =set(input() for i in range(N)) print(len(S))
n=int(input()) ls=[] for i in range(n): s=input() ls.append(s) setl=set(ls) print(len(setl))
1
30,362,578,519,460
null
165
165
#!/usr/bin/env pypy import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**6) INF = float("inf") import math def solve(x, N, K, A, F): total = 0 for i in range(N): total += max(0, math.ceil((A[i]*F[i] - x) / F[i])) if total <= K: return True else: return False def main(): N,K = map(int,input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) ok = 10**13+1 ng = -1 while ok - ng > 1: mid = (ng + ok) // 2 if solve(mid, N, K, A, F): ok = mid else: ng = mid print(ok) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(2147483647) INF = 1 << 60 MOD = 10**9 + 7 # 998244353 input = lambda:sys.stdin.readline().rstrip() class SegmentTree(object): def __init__(self, A, dot, unit): n = 1 << (len(A) - 1).bit_length() tree = [unit] * (2 * n) for i, v in enumerate(A): tree[i + n] = v for i in range(n - 1, 0, -1): tree[i] = dot(tree[i << 1], tree[i << 1 | 1]) self._n = n self._tree = tree self._dot = dot self._unit = unit def __getitem__(self, i): return self._tree[i + self._n] def update(self, i, v): i += self._n self._tree[i] = v while i != 1: i >>= 1 self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1]) def add(self, i, v): self.update(i, self[i] + v) def sum(self, l, r): l += self._n r += self._n l_val = r_val = self._unit while l < r: if l & 1: l_val = self._dot(l_val, self._tree[l]) l += 1 if r & 1: r -= 1 r_val = self._dot(self._tree[r], r_val) l >>= 1 r >>= 1 return self._dot(l_val, r_val) def resolve(): n = int(input()) trees = [[0] * n for _ in range(26)] character = [None] * n for i, c in enumerate(input()): c = ord(c) - ord('a') character[i] = c trees[c][i] = 1 for i in range(26): trees[i] = SegmentTree(trees[i], max, 0) for _ in range(int(input())): q, *A = input().split() if q == '1': i, c = A i = int(i) - 1 c = ord(c) - ord('a') trees[character[i]].update(i, 0) character[i] = c trees[c].update(i, 1) else: l, r = map(int, A) l -= 1 print(sum(trees[i].sum(l, r) for i in range(26))) resolve()
0
null
113,536,017,258,158
290
210
N = int(input()) a_list = list(map(int, input().split())) MOD = 10**9 + 7 cnts = [0,0,0] sames = 0 ind = -1 res = 1 for a in a_list: for i, cnt in enumerate(cnts): if cnt == a: sames += 1 ind = i res *= sames res %= MOD cnts[ind] += 1 sames = 0 print(res)
a=[] for i in range(10): a.append(int(input())) a=sorted(a)[::-1] for i in range(3): print(a[i])
0
null
65,338,842,771,972
268
2
import collections n = int(raw_input()) def g( a, b , n): count = 0 ## CASE 1 if a == b and a <=n : count +=1 ## CASE 2 if a *10 + b <= n: count +=1 if len(str(n)) <=2: return count ## CASE 3 s = str(n) if len(s) - 3 >= 1: count += 10 ** (len(s) - 3) ## CASE 4 s = str(n) if a == int(s[0]): m = s[1:-1] if m != '': #0,m-1 count += int(m) if b <= int(s[-1]): count +=1 elif a < int(s[0]): count += 10 ** (len(s) - 2) return count h = collections.Counter() for k in range(1, n+1): ks = str(k) a,b = int(ks[0]), int(ks[-1]) h[(a,b)] +=1 s= 0 for a in range(1,10): for b in range(1,10): s += h[(a,b)] * h[(b,a)] print s
class Counter(dict): def __missing__(self, i): return 0 n = int(input()) counter = Counter() for x in map(str, range(1, n+1)): head = x[0] tail = x[-1] counter[(head, tail)] += 1 ans = 0 for (head, tail), cnt in counter.items(): ans += cnt * counter[(tail, head)] print(ans)
1
86,849,819,739,772
null
234
234
# abc149_d.py def janken(idx,mine): if i >= K: if flg[i-K] and T[i-K]==T[i]: return 0 flg[i] = True if mine=="r": return R if mine=="p": return P if mine=="s": return S N, K = map(int,input().split()) R,S,P = map(int,input().split()) T = input() flg = [False]*N ans = 0 for i,v in enumerate(T): if v=="s": ans += janken(i,"r") elif v=="r": ans += janken(i,"p") elif v=="p": ans += janken(i,"s") print(ans)
N, K = [int(i) for i in input().split()] R, S, P = [int(i) for i in input().split()] d = {'r': P, 's': R, 'p': S} T = input() checked = [False for i in range(N)] # 勝てるだけ勝てばいい for i in range(N-K): if T[i] == T[i+K]: if checked[i] == False: checked[i+K] = True result = 0 for i in range(N): if checked[i] == False: result += d[T[i]] print(result)
1
106,808,208,436,868
null
251
251
n = int(input()) x = list(map(int,input().split())) a = min(x) b = max(x) + 1 ans = 10 ** 8 for p in range(a,b): m = 0 for i in range(n): m += (x[i] - p) ** 2 ans = min(ans,m) print(ans)
from math import * a, b, C = map(float, input().split()) c = sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(radians(C))) s = (a + b + c) / 2 S = sqrt(s * (s - a) * (s - b) * (s - c)) L = a + b + c h = b * sin(radians(C)) print(S) print(L) print(h)
0
null
32,642,624,884,630
213
30
x = int(input()) y = int(input()) z = int(input()) a = max(x,y) if z%a == 0: print(z//a) else: print(z//a+1)
H,W,N=[int(input()) for i in range(3)] print(min((N+H-1)//H,(N+W-1)//W))
1
88,528,455,278,080
null
236
236
K = int(input()) if K % 2 == 0 or K % 5 == 0: print(-1) exit() i = 0 ai = 0 while True: ai = (ai * 10 + 7) % K i += 1 if ai == 0: break print(i)
K=int(input()) S=set() ans=0 x=7%K i=1 while True: if x==0: ans=1 break if x in S: break else: S.add(x) x=(x*10+7)%K i+=1 print(i if ans else -1)
1
6,159,304,164,530
null
97
97
import sys sys.setrecursionlimit(4100000) import math import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) def resolve(): # S = [x for x in sys.stdin.readline().split()][0] # 文字列 一つ # N = [int(x) for x in sys.stdin.readline().split()][0] # int 一つ H1, M1, H2, M2, K = [int(x) for x in sys.stdin.readline().split()] # 複数int # h_list = [int(x) for x in sys.stdin.readline().split()] # 複数int # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)] # 文字列grid # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)] # grid = [[int(x) for x in sys.stdin.readline().split()] # for _ in range(N)] # int grid logger.debug('{}'.format([])) print(H2 * 60 + M2 - K - H1 * 60 - M1) if __name__ == "__main__": resolve() # AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す # python -m unittest template/template.py で実行できる # pypy3 -m unittest template/template.py で実行できる import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """10 0 15 0 30""" output = """270""" self.assertIO(input, output) def test_入力例_2(self): input = """10 0 12 0 120""" output = """0""" self.assertIO(input, output)
import math h1, m1, h2, m2, k = map(int, input().split(" ")) t1 = h1 * 60 + m1 t2 = h2 * 60 + m2 print(t2 - t1 - k)
1
18,147,517,395,840
null
139
139
s = input() if s=='AAA' or s=='BBB' : print('No') else : print('Yes')
s = input() if(s == 'AAA' or s == 'BBB'): print("No") else: print("Yes")
1
55,062,594,694,802
null
201
201
N, M =map(int,input().split()) A = list(map(int, input().split())) # x = 宿題をする日の合計 x = sum(A) if N >= x: print(N - x) else: print("-1")
# B - Homework # N M N, M = map(int, input().split()) my_list = list(map(int, input().split(maxsplit=M))) if N < sum(my_list): answer = -1 else: answer = N - sum(my_list) print(answer)
1
32,090,016,832,972
null
168
168
n = int(input()) a, b = 0, 0 for i in range(n): s1, s2 = input().split() if s1 > s2: a += 3 elif s1 == s2: a += 1 b += 1 else: b += 3 print('{0} {1}'.format(a, b))
import math a,b,x = map(int,input().split()) if x >= 0.5 * a**2 * b: tan_x = 2*(b*a**2 -x)/a**3 else: tan_x = (b**2 * a)/(2*x) print(math.degrees(math.atan(tan_x)))
0
null
83,001,021,757,104
67
289
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N,K = LI() f = [1] r = [1] s = 1 for i in range(1,N+2): s = (s * i) % MOD f.append(s) r.append(pow(s,MOD-2,MOD)) def comb(a,b): return f[a] * r[b] * r[a-b] ans = 0 for k in range(min(K,N-1)+1): ans = (ans + comb(N,k) * comb(N-1,k)) % MOD print(ans) if __name__ == '__main__': main()
import sys # import re import math import collections # import decimal import bisect import itertools import fractions # import functools import copy # import heapq import decimal # import statistics import queue # import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): # nCrの左項にはn以外も来るバージョン、1!~(n-1)!を保持 def prepare(n, MOD): # 1! - n! の計算 f = 1 factorials = [1] # 0!の分 for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) # n!^-1 の計算 inv = pow(f, MOD - 2, MOD) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs n, k = ns() facts, invs = prepare(n, MOD) ans = 0 for ki in range(min(n, k + 1)): zero_comb = facts[n] * invs[ki] * invs[n - ki] % MOD nonzero_comb = facts[n - 1] * invs[ki] * invs[n - 1 - ki] % MOD ans += zero_comb * nonzero_comb % MOD ans %= MOD print(ans) if __name__ == '__main__': main()
1
67,062,832,062,226
null
215
215
string = '' while True: hoge = input().strip() if hoge == '-': print (string) break if hoge.isalpha(): if string: print (string) string = hoge count = 0 else: if count == 0: count = hoge continue else: string = string[int(hoge):] + string[:int(hoge)]
while True: s = raw_input() if s == "-": break m = int(raw_input()) for i in range(m): n = int(raw_input()) s = s[n:]+s[:n] print s
1
1,874,902,891,102
null
66
66
n = int(input()) ikeru = [[] for _ in range(n)] for i in range(n-1): a, b = map(int, input().split()) ikeru[a-1].append((b-1, i)) settansaku = set([]) setmada = {0} listmada = [(0, None)] #left: Vertex, right: Color kouho = 1 num = [0 for _ in range(n-1)] while kouho != 0: for i, cnt in listmada[:]: colors = {cnt} settansaku.add(i) setmada.remove(i) listmada.remove((i, cnt)) kouho -= 1 c = 0 for k, j in ikeru[i]: if not k in setmada: if not k in settansaku: setmada.add(k) while True: if c not in colors: listmada.append((k, c)) colors.add(c) num[j] = c break c += 1 kouho += 1 print(max(num)+1) print("\n".join([str(i+1) for i in num]))
s = input() if s[len(s)-1] == 's': s = s + 'es' elif s[len(s)-1] != 's': s = s + 's' print(s)
0
null
69,122,514,530,160
272
71
s,t = input().split() a,b = map(int,input().split()) u = input() if s == u: a -= 1 if t == u: b -= 1 print(a,b)
while 1: h,w = map(int, raw_input().split()) if h==w==0: break for i in range(0,h/2): print ("#." * (w/2) + "#" * (w%2)) print (".#" * (w/2) + "." * (w%2)) if h % 2 == 1: print ("#." * (w/2) + "#" * (w%2)) print ""
0
null
36,520,259,044,090
220
51
import math d = int(input()) class point: def __init__(self, arg_x, arg_y): self.x = arg_x self.y = arg_y p1 = point(0, 0) p2 = point(100, 0) def koch(d, p1, p2): pi = math.pi cos60 = math.cos(pi/3) sin60 = math.sin(pi/3) if d == 0: return else: s = point((2*p1.x + 1*p2.x)/3, (2*p1.y + 1*p2.y)/3) t = point((1*p1.x + 2*p2.x)/3, (1*p1.y + 2*p2.y)/3) u = point(s.x + cos60*(t.x-s.x) - sin60*(t.y-s.y), s.y + sin60*(t.x-s.x) + cos60*(t.y-s.y)) koch(d-1, p1, s) print(s.x, s.y) koch(d-1, s, u) print(u.x, u.y) koch(d-1, u, t) print(t.x, t.y) koch(d-1, t, p2) print(p1.x, p1.y) koch(d, p1, p2) print(p2.x, p2.y)
import math n = int(input()) def koch(n, p1_x, p2_x, p1_y, p2_y): if n == 0: return s_x = (2*p1_x + p2_x) / 3 s_y = (2*p1_y + p2_y) / 3 t_x = (p1_x + 2*p2_x) / 3 t_y = (p1_y + 2*p2_y) / 3 u_x = (t_x - s_x)/2 - (t_y - s_y) * math.sqrt(3)/2 + s_x u_y = (t_x - s_x) * math.sqrt(3)/2 + (t_y - s_y)/2 + s_y koch(n-1, p1_x, s_x, p1_y, s_y) print (s_x, s_y) koch(n-1, s_x, u_x, s_y, u_y) print (u_x, u_y) koch(n-1, u_x, t_x, u_y, t_y) print (t_x, t_y) koch(n-1, t_x, p2_x, t_y, p2_y) p1_x = 0.0 p1_y = 0.0 p2_x = 100.0 p2_y = 0.0 print (p1_x, p1_y) koch(n, 0, 100, 0, 0) print (p2_x, p2_y)
1
125,348,153,568
null
27
27
while True: a,b=map(int,input().split()) if not(a) and not(b):break if a>b:a,b=b,a print(a,b)
while True: x, y = map(int, input().split()) if x == 0 and y == 0: break if x <= y: print(f'{x} {y}') else: print(f'{y} {x}')
1
528,233,861,024
null
43
43
def comb(n, k): nu, de = 1, 1 for i in range(k): de *= n - i nu *= i + 1 return de // nu def ans(N, K): if K == 0: return 1 N = str(int(N)) if len(N) < K or int(N) == 0: return 0 ret = sum([9 ** K * comb(max(dig - 1, 1), K - 1) for dig in range(K, len(N))]) ret += (int(N[0]) - 1) * 9 ** (K - 1) * comb(len(N) - 1, K - 1) return ret + ans(N[1:], K - 1) N = input() K = int(input()) print(ans(N, K))
# -*- coding: utf-8 -*- import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9+7 N = readline().decode().rstrip() K = int(readline()) L = len(N) # 桁DP dp = [[[0 for _ in range(2)] for _ in range(4)] for _ in range(L+1)] dp[0][0][0] = 1 for i in range(L): for j in range(4): for k in range(2): nd = int(N[i]) for d in range(10): ni = i + 1; nj = j; nk = k if d != 0: nj += 1 if nj > K: continue if k == 0: if d > nd: continue if d < nd: nk = 1 dp[ni][nj][nk] += dp[i][j][k] print(dp[L][K][0]+dp[L][K][1])
1
75,893,357,316,832
null
224
224
S = input() print( 'A' if S.isupper() else 'a' )
import math h, w = map(int, input().split()) ans = math.ceil(h * w / 2) if h == 1 or w == 1: ans = 1 print(ans)
0
null
31,271,352,947,164
119
196
nums = [int(e) for e in input().split()] Sheep = nums[0] Wolves = nums[1] if Sheep > Wolves: print("safe") else: print("unsafe")
score = list(map(int,input().split())) if score[0] <= score[1]: print('unsafe') else: print('safe')
1
29,208,140,020,238
null
163
163
import sys from math import gcd from collections import defaultdict sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N = I() mod = 10**9+7 plus = defaultdict(int) minus = defaultdict(int) flag = defaultdict(int) A_zero,B_zero = 0,0 zero_zero = 0 for i in range(N): a,b = MI() if a == b == 0: zero_zero += 1 elif a == 0: A_zero += 1 elif b == 0: B_zero += 1 else: if a < 0: a,b = -a,-b a,b = a//gcd(a,b),b//gcd(a,b) if b > 0: plus[(a,b)] += 1 else: minus[(a,b)] += 1 flag[(a,b)] = 1 ans = 1 for a,b in plus.keys(): ans *= pow(2,plus[(a,b)],mod)+pow(2,minus[(b,-a)],mod)-1 ans %= mod flag[(b,-a)] = 0 for key in minus.keys(): if flag[key] == 1: ans *= pow(2,minus[key],mod) ans %= mod ans *= pow(2,A_zero,mod)+pow(2,B_zero,mod)-1 ans %= mod ans += zero_zero-1 ans %= mod print(ans)
x, y = map(int, input().split()) if y % 2 != 0: print('No') exit() if x*2 <= y <= x*4: print('Yes') else: print('No')
0
null
17,501,630,984,732
146
127
h1, m1, h2, m2, k = map(int, input().split()) h = (h2 * 60 + m2) - (h1 * 60 + m1) ans = h - k print(ans)
S=input() T=input() lenS=len(S) lenT=len(T) count=[] for i in range(lenS-lenT+1): c=0 for j in range(lenT): if T[j]!=S[i+j]: c=c+1 j=j+1 count.append(c) i=i+1 print(min(count))
0
null
10,857,448,416,582
139
82
#self.r[x] means root of "x" if "x" isn't root, else number of elements class UnionFind(): def __init__(self, n): self.r = [-1 for i in range(n)] #use in add-method def root(self, x): if self.r[x] < 0: #"x" is root return x self.r[x] = self.root(self.r[x]) return self.r[x] #add new path def add(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False self.r[x] += self.r[y] self.r[y] = x return True n, m = map(int, input().split()) UF = UnionFind(n) for i in range(m): a, b = map(lambda x: int(x)-1, input().split()) UF.add(a, b) ans = 0 for i in UF.r: if i < 0: ans += 1 print(ans-1)
def connected_components(graph): seen = set() def component(n): nodes = set([n]) while nodes: n = nodes.pop() seen.add(n) nodes |= set(graph[n]) - seen yield n for n in graph: if n not in seen: yield component(n) def print_gen(gen): print(len([list(x) for x in gen]) - 1) n, m = map(int, input().split()) graph = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) # 有向グラフなら消す graphA = {} for i in range(n): graphA[i] = graph[i] print_gen(connected_components(graphA))
1
2,291,650,426,560
null
70
70
n, k = map(int, input().split()) lp = list(map(int, input().split())) le = [(p + 1) / 2 for p in lp] e = sum(le[:k]) m = e for i in range(n - k): e -= le[i] e += le[k + i] m = max(m, e) print(m)
# coding=utf-8 from math import floor, ceil, sqrt, factorial, log, gcd from itertools import accumulate, permutations, combinations, product, combinations_with_replacement from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heappushpop, heapify import copy import sys INF = float('inf') mod = 10**9+7 sys.setrecursionlimit(10 ** 6) def lcm(a, b): return a * b / gcd(a, b) # 1 2 3 # a, b, c = LI() def LI(): return list(map(int, sys.stdin.buffer.readline().split())) # a = I() def I(): return int(sys.stdin.buffer.readline()) # abc def # a, b = LS() def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() # a = S() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') # 2 # 1 # 2 # [1, 2] def IR(n): return [I() for i in range(n)] # 2 # 1 2 3 # 4 5 6 # [[1,2,3], [4,5,6]] def LIR(n): return [LI() for i in range(n)] # 2 # abc # def # [abc, def] def SR(n): return [S() for i in range(n)] # 2 # abc def # ghi jkl # [[abc,def], [ghi,jkl]] def LSR(n): return [LS() for i in range(n)] # 2 # abcd # efgh # [[a,b,c,d], [e,f,g,h]] def SRL(n): return [list(S()) for i in range(n)] n = I() ans = 0 for a in range(1, n): ans += (n-1)//a print(ans)
0
null
38,876,934,124,110
223
73
n = int(input()) a = [int(ai) for ai in input().split()] if n % 2 == 0: s = [0,0] for i in range(n // 2): s = [max(s[q] for q in range(p+1)) + a[i*2+p] for p in range(2)] print(max(s)) else: s = [0,0,0] for i in range(n // 2): s = [max(s[q] for q in range(p+1)) + a[i*2+p] for p in range(3)] print(max(s))
def main(): n, x, y = map(int, input().split()) ans = [0] * n for i in range(1,n): for j in range(i+1, n+1): r1 = j-i r2 = abs(x-i) + 1 + abs(j-y) r3 = abs(y-i) + 1 + abs(j-x) ans[min(r1,r2,r3)] += 1 for i in range(1,n): print(ans[i]) if __name__ == "__main__": main()
0
null
40,783,539,848,980
177
187
n = int(input()) s = input() if n%2 != 0 or s[:n//2] != s[n//2:]: print("No") else: print("Yes")
n=int(input()) s=input() if n%2!=0: print("No") elif s[0:int(n/2)]==s[int(n/2):n]: print("Yes") else: print("No")
1
146,431,246,443,388
null
279
279
def merge(a, left, mid, right): global count l = a[left:mid] + [sentinel] r = a[mid:right] + [sentinel] i = j = 0 for k in range(left, right): if l[i] <= r[j]: a[k] = l[i] i += 1 else: a[k] = r[j] j += 1 count += right - left def merge_sort(a, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(a, left, mid) merge_sort(a, mid, right) merge(a, left, mid, right) sentinel = 10 ** 9 + 1 n = int(input()) a = list(map(int, input().split())) count = 0 merge_sort(a, 0, len(a)) print(*a) print(count)
a = input() if a.isupper() == True: print("A") else: print("a")
0
null
5,670,647,074,058
26
119
from math import floor from decimal import Decimal if __name__ == '__main__': a, b = input().split() a = int(a) b = Decimal(b) print(floor(a * b))
import sys #input = sys.stdin.buffer.readline N = int(input()) temp = 5 ans = 0 if N%2: print(0) quit() else: N = N//2 while temp <= N: ans += N//temp temp *= 5 print(ans)
0
null
66,265,923,030,890
135
258
class Dice: __slots__ = ['n1', 'n2', 'n3', 'n4', 'n5', 'n6'] def __init__(self, n_tup): self.n1 = n_tup[0] self.n2 = n_tup[1] self.n3 = n_tup[2] self.n4 = n_tup[3] self.n5 = n_tup[4] self.n6 = n_tup[5] def roll(self, direction): if direction == "N": self.n1, self.n2, self.n6, self.n5 \ = self.n2, self.n6, self.n5, self.n1 elif direction == "E": self.n1, self.n3, self.n6, self.n4 \ = self.n4, self.n1, self.n3, self.n6 if direction == "S": self.n1, self.n2, self.n6, self.n5 \ = self.n5, self.n1, self.n2, self.n6 if direction == "W": self.n1, self.n3, self.n6, self.n4 \ = self.n3, self.n6, self.n4, self.n1 dice = Dice([int(x) for x in input().split()]) cmd = input() for i in range(len(cmd)): dice.roll(cmd[i]) print(dice.n1)
class Dice: def __init__(self, a, b, c, d, e, f): # サイコロの現在一番上にある面 self.a = a self.b = b self.c = c self.d = d self.e = e self.f = f def move(self, move_str): for i in move_str: if i == "N": self.move_N() elif i == "E": self.move_E() elif i == "W": self.move_W() elif i == "S": self.move_S() def move_N(self): tmp1 = self.a tmp2 = self.e self.a = self.b self.b = self.f self.e = tmp1 self.f = tmp2 def move_E(self): tmp1 = self.a tmp2 = self.c self.a = self.d self.c = tmp1 self.d = self.f self.f = tmp2 def move_W(self): tmp1 = self.a tmp2 = self.d self.a = self.c self.c = self.f self.d = tmp1 self.f = tmp2 def move_S(self): tmp1 = self.a tmp2 = self.b self.a = self.e self.b = tmp1 self.e = self.f self.f = tmp2 """ def debug(self): print("--------") print(f"{self.a=}") print(f"{self.b=}") print(f"{self.c=}") print(f"{self.d=}") print(f"{self.e=}") print(f"{self.f=}") print("--------") """ a, b, c, d, e, f = map(int, input().split()) dice = Dice(a, b, c, d, e, f) li = list(input()) dice.move(li) print(dice.a)
1
236,191,716,640
null
33
33