code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
S = input() def is_kaibun(s): return s[:len(s)//2] == s[:(len(s)-1)//2:-1] flg = is_kaibun(S) and is_kaibun(S[:len(S)//2]) and is_kaibun(S[:len(S)//2:-1]) print('Yes' if flg else 'No')
import sys read = sys.stdin.buffer.read s = read().decode("utf-8") H = s[:(len(s) - 1) // 2] B = s[(len(s) - 1) // 2 + 1:-1] if s[:-1] == s[:-1][::-1] and H == H[::-1] and B == B[::-1]: print("Yes") else: print("No")
1
46,403,479,395,350
null
190
190
import sys def Ii():return int(sys.stdin.readline()) def Mi():return map(int,sys.stdin.readline().split()) def Li():return list(map(int,sys.stdin.readline().split())) n = Ii() a = Li() b = 0 for i in range(n): b ^= a[i] ans = [] for i in range(n): print(b^a[i],end=' ')
n = int(input()) a = [int(i) for i in input().split()] s = 0 for i in a: s ^= i for i in a: print(s^i,end = ' ')
1
12,498,722,584,282
null
123
123
l=raw_input() k=l.split() a=int(k[0]) op=k[1] b=int(k[2]) # while op<>'?': if op=='+': print a + b if op=='-': print a - b if op=='*': print a * b if op=='/': print a / b # l=raw_input() k=l.split() a=int(k[0]) op=k[1] b=int(k[2])
s=input() l=set(s) if(len(l)==1): print("No") else: print("Yes")
0
null
27,657,933,370,340
47
201
import sys 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())) k = Ii() a,b = Mi() for i in range(a,b+1): if i%k == 0: print('OK') exit(0) print('NG')
s = input() x = "" y = "" Q = int(input()) rev = 0 for i in range(Q): q = list(input().split()) if q[0] == "2": q[1] = int(q[1]) q[1] -= 1 if rev: q[1] = 1 - q[1] if q[1] == 0: x += q[2] else: y += q[2] else: rev = 1 - rev x = x[::-1] ans = x + s + y if rev: ans = ans[::-1] print(ans)
0
null
42,068,155,202,140
158
204
def selection_sort(numbers, n, key=lambda x: x): """selection sort method Args: numbers: a list of numbers to be sorted n: len(numbers) key: sort key Returns: sorted numberd, number of swapped times """ x = [] for data in numbers: x.append(data) counter = 0 for i in range(0, n): min_j = i for j in range(i, n): if key(x[j]) < key(x[min_j]): min_j = j if min_j != i: x[min_j], x[i] = x[i], x[min_j] counter += 1 return x, counter def bubble_sort(numbers, n, key=lambda x: x): """bubble sort method Args: numbers: a list of numbers to be sorted by bubble sort n: len(list) key: sort key Returns: sorted list """ x = [] for data in numbers: x.append(data) flag = True counter = 0 while flag: flag = False for index in range(n - 1, 0, -1): if key(x[index]) < key(x[index - 1]): x[index], x[index - 1] = x[index - 1], x[index] flag = True counter += 1 return x, counter def insertion_sort(numbers, n, key=lambda x: x): """insertion sort method Args: numbers: a list of numbers to be sorted n: len(numbers) Returns: sorted list """ for i in range(1, n): target = numbers[i] index = i - 1 while index >= 0 and target < numbers[index]: numbers[index + 1] = numbers[index] index -= 1 numbers[index + 1] = target return numbers def is_stable(list1, list2): """check stablity of sorting method used in list2 Args: list1: sorted list(bubble sort) list2: sorted list(some sort) Returns: bool """ flag = True for index, data in enumerate(list1): if list2[index] != data: flag = False break return flag length = int(raw_input()) cards = raw_input().split() bubble_sorted_card, bubble_swapped = bubble_sort(numbers=cards, n=length, key=lambda x: int(x[1])) selection_sorted_card, selection_swapped = selection_sort(numbers=cards, n=length, key=lambda x: int(x[1])) print(" ".join(bubble_sorted_card)) print("Stable") print(" ".join(selection_sorted_card)) if is_stable(bubble_sorted_card, selection_sorted_card): print("Stable") else: print("Not stable")
a, b, n = map(int, input().split()) if n <= b - 1: x = n else: x = n - (n%b + 1) ans = a*x//b - a*(x//b) print(ans)
0
null
14,030,382,726,422
16
161
n,k = map(int,input().split()) a = list(map(int,input().split())) ML = 50 r = min(ML,k) for l in range(r): imos = [0]*(n+1) for i in range(n): left = max(0,i-a[i]) right = min(n,i+a[i]+1) imos[left] += 1 imos[right] -= 1 c = 0 for i in range(n): c += imos[i] a[i] = c print(*a)
import numpy as np from numba import njit N, K = map(int, input().split(' ')) A = list(map(int, input().split(' '))) a = np.array(A, dtype=int) fin = [N] * N @njit(cache=True) def calc_b(a): b = np.zeros(N, dtype=np.int64) for i, _a in enumerate(a): l = max(0, i - _a) r = min(N - 1, i + _a) # imos hou b[l] += 1 if r + 1 < N: b[r + 1] -= 1 b = np.cumsum(b) # print('b_sum', b) return b for k in range(min(K,100)): # print('a', a) a = calc_b(a) # if all(a == fin): # break a = [str(_) for _ in a] print(' '.join(a)) # print('step=', k)
1
15,454,632,236,160
null
132
132
a,b=[int(i) for i in input().split(" ")] while b!=0: t = min(a,b) b = max(a,b) % min(a,b) a = t print(a)
import math a,b=map(int,input().split()) print(math.gcd(a,b))
1
7,651,466,372
null
11
11
def check(pt, brackets): brackets.sort(reverse=True) for m, t in brackets: if pt + m < 0: return -1 pt += t return pt n = int(input()) brackets_p = [] # (始めを0として、( = +1, ) = -1 として、最後はいくつか, 途中の最小値はいくつか) brackets_m = [] pt = 0 mt = 0 for _ in range(n): s = input() total = 0 mini = 0 for c in s: if c == '(': total += 1 else: total -= 1 mini = min(mini, total) if total >= 0: if mini == 0: pt += total else: brackets_p.append((mini, total)) else: total, mini = -total, mini - total if mini == 0: mt += total else: brackets_m.append((mini, total)) pt = check(pt, brackets_p) mt = check(mt, brackets_m) if (pt == -1) or (mt == -1) or (pt != mt): print('No') else: print('Yes')
# coding: utf-8 import sys from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import combinations, product #import bisect# lower_bound etc #import numpy as np #import queue# queue,get(), queue.put() def run(): N = int(input()) current = 0 ways = [] dic = {'(': 1, ')': -1} SS = read().split() for S in SS: path = [0] for s in S: path.append(path[-1]+ dic[s]) ways.append((path[-1], min(path))) ways_pos = sorted([(a,b) for a,b in ways if a >= 0], key = lambda x:x[0], reverse=True) ways_neg = sorted([(a,b) for a,b in ways if a < 0], key = lambda x:(x[0] - x[1]), reverse=True) tmp = [] for go, max_depth in ways_pos: if current + max_depth >= 0: current += go else: tmp.append((go, max_depth)) for go, max_depth in tmp: if current + max_depth >= 0: current += go else: print('No') return None tmp =[] for go, max_depth in ways_neg: if current + max_depth >= 0: current += go else: tmp.append((go, max_depth)) for go, max_depth in tmp: if current + max_depth >= 0: current += go else: print('No') return None if current == 0: print('Yes') else: print('No') if __name__ == "__main__": run()
1
23,614,421,535,964
null
152
152
from random import randint import sys input = sys.stdin.readline INF = 9223372036854775808 def calc_score(D, C, S, T): """ 開催日程Tを受け取ってそこまでのスコアを返す コンテストi 0-indexed d 0-indexed """ score = 0 last = [0]*26 # コンテストiを前回開催した日 for d, t in enumerate(T): last[t] = d + 1 for i in range(26): score -= (d + 1 - last[i]) * C[i] score += S[d][t] return score def update_score(D, C, S, T, score, ct, ci): """ ct日目のコンテストをコンテストciに変更する スコアを差分更新する ct: change t 変更日 0-indexed ci: change i 変更コンテスト 0-indexed """ last = [0]*26 # コンテストiを前回開催した日 for d in range(ct): last[T[d]] = d + 1 prei = T[ct] # 変更前に開催する予定だったコンテストi score -= S[ct][prei] score += S[ct][ci] for d in range(ct, D): if d != ct and T[d] == prei: break score += C[prei]*(d + 1 - ct - 1) score -= C[prei]*(d + 1 - last[prei]) for d in range(ct, D): if d != ct and T[d] == ci: break score += C[ci]*(d + 1 - last[ci]) score -= C[ci]*(d + 1 - ct - 1) T[ct] = ci return score, T def evaluate(D, C, S, T, k): """ d日目終了時点での満足度を計算し, d + k日目終了時点での満足度の減少も考慮する """ score = 0 last = [0]*26 for d, t in enumerate(T): last[t] = d + 1 for i in range(26): score -= (d + 1 - last[i]) * C[i] score += S[d][t] for d in range(len(T), min(len(T) + k, D)): for i in range(26): score -= (d + 1 - last[i]) * C[i] return score def greedy(D, C, S): Ts = [] for k in range(5, 10): T = [] # 0-indexed max_score = -INF for d in range(D): # d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する max_score = -INF best_i = 0 for i in range(26): T.append(i) score = evaluate(D, C, S, T, k) if max_score < score: max_score = score best_i = i T.pop() T.append(best_i) Ts.append((max_score, T)) return max(Ts, key=lambda pair: pair[0]) def local_search(D, C, S, score, T): ct = randint(0, D-1) ci = randint(0, 25) for _ in range(400000): new_score, new_T = update_score(D, C, S, T, score, ct, ci) if score < new_score: score = new_score T = new_T return T if __name__ == '__main__': D = int(input()) C = [int(i) for i in input().split()] S = [[int(i) for i in input().split()] for j in range(D)] init_score, T = greedy(D, C, S) T = local_search(D, C, S, init_score, T) for t in T: print(t+1)
from time import time from random import random limit_secs = 2 start_time = time() D = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(D)] def calc_score(t): score = 0 S = 0 last = [-1] * 26 for d in range(len(t)): S += s[d][t[d]] last[t[d]] = d for i in range(26): S -= c[i] * (d - last[i]) score += max(10 ** 6 + S, 0) return score def solution1(): return [i % 26 for i in range(D)] def solution2(): t = None score = -1 for i in range(26): nt = [(i + j) % 26 for j in range(D)] if calc_score(nt) > score: t = nt return t #def solution3(): # t = [] # for _ in range(D): # for i in range(26): def optimize0(t): return t def optimize1(t): score = calc_score(t) while time() - start_time + 0.15 < limit_secs: d = int(random() * D) q = int(random() * 26) old = t[d] t[d] = q new_score = calc_score(t) if new_score < score: t[d] = old else: score = new_score return t t = solution2() t = optimize0(t) print('\n'.join(str(e + 1) for e in t))
1
9,721,705,012,122
null
113
113
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) for i in range(N - K): print("Yes" if A[i] < A[i + K] else "No") if __name__ == "__main__": main()
N, K = map(int,input().split()) P = [int(x)-1 for x in input().split()] C = [int(x) for x in input().split()] def loop(s): value = 0 done = set() while s not in done: done.add(s) s = P[s] value += C[s] return len(done), value def f(s,K): ans = -10**18 total = 0 done = set() while s not in done: done.add(s) s = P[s] total += C[s] ans = max(ans,total) K -= 1 if K==0: return ans lamb, value = loop(s) if K > 2*lamb: if value > 0: K -= lamb total += (K//lamb)*value ans = max(ans,total) K -= (K//lamb)*lamb K += lamb if value <= 0: K = min(K,lamb+5) while K > 0: s = P[s] total += C[s] ans = max(ans,total) K -= 1 return ans print(max([f(s,K) for s in range(N)]))
0
null
6,200,016,402,150
102
93
a,b = map(int,input().split()) d=(a-a%b)/b r=a%b f=a/b print(f"{d} {r} {f:.5f}")
c = [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] N = n=int(input()) print(c[N-1])
0
null
25,516,112,700,638
45
195
a = input().split() c = int(a[0]) * int(a[1]) d = (int(a[0])*2) + (int(a[1])*2) print('%d %d' %(c,d))
pos = 0 for n in map(int, input().split()): pos += 1 if n == 0: break print(pos)
0
null
6,842,684,705,520
36
126
s = int(input()) mod = 10**9 + 7 a = [0] * (2001) a[3] = a[4] = a[5] = 1 for i in range(6, s + 1): a[i] = a[i - 1] + a[i - 3] a[i] %= mod print(a[s])
def main(): MOD = 1000000007 s = int(input()) dp = [0] * (s + 1) dp[0] = 1 tot = 0 for i in range(1, s + 1): if i >= 3: tot += dp[i - 3] tot %= MOD dp[i] = tot print(dp[s]) if __name__ == '__main__': main()
1
3,288,252,649,730
null
79
79
k = int(input()) a, b = map(int, input().split()) check = False for i in range(a, b + 1): if i % k == 0: check = True print("OK" if check else "NG")
# -*- coding: utf-8 -*- def main(): S = input() T = input() if S == T[:len(S)]: ans = 'Yes' else: ans = 'No' print(ans) if __name__ == "__main__": main()
0
null
24,155,142,665,550
158
147
l, r, d = map(int, input().split()) num = 0 for i in range(r - l +1): if (i + l) / d == int((i + l) / d): num += 1 print(num)
k=int(input()) k+=1 o='' a='ACL' if k==1: print('') exit() else: for i in range(1,k): o=o+a print(o)
0
null
4,922,409,491,058
104
69
def disc(s,d): ans[d][0] = s s += 1 if main[d][0] != 0: for l in range(1,int(main[d][0])+1): if ans[int(main[d][l])-1][0] == 0: s = disc(int(s),int(main[d][l])-1) ans[d][1] = s return s+1 n = int(input()) main = [] for i in range(n): a = input().split() if int(a[1]) > 0: main.append(a[1:]) else: main.append([0]) del a ans = [[0] * 2 for i in range(n)] ls = disc(1,0) for i in range(n): if ans[i][0] == 0: ls = disc(int(ls),i) for i in range(n): print(str(i+1) + " " + str(ans[i][0]) + " " + str(ans[i][1]))
def dfs(v, cnt): D[v] = cnt cnt += 1 for c in edge[v]: if D[c] == -1: cnt = dfs(c, cnt) F[v] = cnt cnt += 1 return cnt V = int(input()) edge = [[] for _ in range(V)] for _ in range(V): u, _, *v = map(lambda x: int(x)-1, input().split()) edge[u] = sorted(v) D, F = [-1] * V, [-1] * V c = 1 for i in range(V): if D[i] == -1: c = dfs(i, c) for i, (d, f) in enumerate(zip(D, F)): print(i+1, d, f)
1
2,673,106,982
null
8
8
#!/usr/bin/env python3 import sys from itertools import chain def solve( N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]" ): ok = [1 for _ in range(N)] for a, b in zip(A, B): if H[a - 1] <= H[b - 1]: ok[a - 1] = 0 if H[b - 1] <= H[a - 1]: ok[b - 1] = 0 return sum(ok) def main(): tokens = chain(*(line.split() for line in sys.stdin)) N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int H = [int(next(tokens)) for _ in range(N)] # type: "List[int]" A = [int()] * (M) # type: "List[int]" B = [int()] * (M) # type: "List[int]" for i in range(M): A[i] = int(next(tokens)) B[i] = int(next(tokens)) answer = solve(N, M, H, A, B) print(answer) if __name__ == "__main__": main()
nm = input() print(nm[:3])
0
null
19,962,001,747,380
155
130
import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) input = sys.stdin.readline mod = 10**9+7 Max = sys.maxsize def l(): #intのlist return list(map(int,input().split())) def m(): #複数文字 return map(int,input().split()) def onem(): #Nとかの取得 return int(input()) def s(x): #圧縮 a = [] if len(x) == 0: return [] aa = x[0] su = 1 for i in range(len(x)-1): if aa != x[i+1]: a.append([aa,su]) aa = x[i+1] su = 1 else: su += 1 a.append([aa,su]) return a def jo(x): #listをスペースごとに分ける return " ".join(map(str,x)) def max2(x): #他のときもどうように作成可能 return max(map(max,x)) def In(x,a): #aがリスト(sorted) k = bs.bisect_left(a,x) if k != len(a) and a[k] == x: return True else: return False def pow_k(x, n): ans = 1 while n: if n % 2: ans *= x x *= x n >>= 1 return ans """ def nibu(x,n,r): ll = 0 rr = r while True: mid = (ll+rr)//2 if rr == mid: return ll if (ここに評価入れる): rr = mid else: ll = mid+1 """ n = onem() a = l() aa = [[a[i],i] for i in range(n)] aa.sort(reverse = True) dp = [[0 for i in range(n+1)] for j in range(n+1)] for i in range(1,n+1): on = aa[i-1] for j in range(i+1): if j-1 >= 0: dp[i-j][j] = max(dp[i-j][j-1] + on[0] * abs(on[1] - (n-1 - (j - 1))),dp[i-j][j]) """ if i == 1: print(dp[i-j][j-1] + on[0] * abs(on[1] - j),dp[i-j][j]) """ if i-j-1 >= 0: #dp[i-j][j] = max(dp[i-j][j],dp[i-j-1][j] + on[0] * abs(on[1] - (n-1 - (i-j)))) dp[i-j][j] = max(dp[i-j][j],dp[i-j-1][j] + on[0] * abs(on[1] - (i-j-1))) """ if i == 1: print(on,(n-1 - (i-j)),n-1,i-j) print(dp[i-j-1][j],on[0] * abs(on[1] - (n-1 - (i-j)))) print(dp[i-j][j],dp[i-j-1][j] + on[0] * abs(on[1] - (i-j-1))) """ ma = 0 for i in range(n+1): ma = max(ma,dp[n-i][i]) print(ma)
from sys import stdin def get_result(data): N = data[0][0] A = data[1] dp = [[0]*(N+1) for _ in range(N+1)] B = [[A[i], i] for i in range(N)] B = sorted(B, reverse=True) for i in range(N): for j in range(N-i): dp[i+1][j] = max(dp[i+1][j], dp[i][j] + B[i+j][0] * (B[i+j][1] - i)) dp[i][j+1] = max(dp[i][j+1], dp[i][j] + B[i+j][0] * ((N-1-j) - B[i+j][1])) res = 0 for i in range(N): res = max(res, dp[i][N-i]) return res if __name__ == '__main__': raw_data = [val.rstrip() for val in stdin.readlines()] data = [list(map(int, val.split(' '))) for val in raw_data] result = get_result(data) print(result)
1
33,710,056,798,938
null
171
171
mod = 10 ** 9 + 7 x, y = map(int, input().split()) if (x + y) % 3 != 0 or x * 2 < y or y * 2 < x: print(0) exit() l = [1] for i in range(1, (x + y) // 3 + 100): l.append(l[-1] * i % mod) def comb(n, r, m): return l[n] * pow(l[r], m - 2, m) * pow(l[n - r], m - 2, m) % m a, b = y - (x + y) // 3, x - (x + y) // 3 print(comb(a + b, a, mod) % mod)
n = int(input()) lis = input().split() dic = {} for i in range(n): if lis[i] not in dic: dic[lis[i]] = 1 else: dic[lis[i]] += 1 for x in dic.values(): if x != 1: print("NO") exit() print("YES")
0
null
112,009,327,474,802
281
222
S = input() Q = int(input()) d = 0 X = [[], []] for i in range(Q): q = input() if q[0] == "1": d = (d + 1) % 2 else: a, f, c = q.split() x = (int(f) + d) % 2 X[x].append(c) if d == 0: v = "".join(X[1])[::-1] + S + "".join(X[0]) else: v = "".join(X[0])[::-1] + S[::-1] + "".join(X[1]) print(v)
from collections import deque if __name__ == '__main__': s = input() n = int(input()) rvflg = False d_st = deque() d_ed = deque() for _ in range(n): q = input() if len(q) == 1: if rvflg: rvflg = False else: rvflg = True else: i,f,c = map(str,q.split()) if f == "1":#先頭に追加 if rvflg: #末尾に追加 d_ed.append(c) else: #先頭に追加 d_st.appendleft(c) else:#末尾に追加 if rvflg: #先頭に追加 d_st.appendleft(c) else: #末尾に追加 d_ed.append(c) ans = "".join(d_st) + s + "".join(d_ed) #最後に反転するかを決定 if rvflg: ans = ans[::-1] print(ans)
1
57,581,097,018,922
null
204
204
n = int(input()) x = list(map(int, input().split())) sum1 = 100*100**2 for i in range(101): sum2 = 0 for j in range(len(x)): sum2 += (x[j] - i)**2 if sum2 < sum1: sum1 = sum2 print(sum1)
import math def main(): n = int(input()) x = list(map(float, input().split())) y = list(map(float, input().split())) print(Minkowski(n, x, y, 1)) print(Minkowski(n, x, y, 2)) print(Minkowski(n, x, y, 3)) print(Chebyshev(n, x, y)) def Minkowski(n, x, y, p): temp = 0 for i in range(n): temp += abs(y[i] - x[i])**p return temp**(1/p) def Chebyshev(n, x, y): temp = 0 for i in range(n): temp = max(temp, abs(y[i] - x[i])) return temp if __name__ == '__main__': main()
0
null
32,926,411,551,040
213
32
def cmb(n, r, mod): if (r < 0 or r > n): return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 998244353 N = 2 * 10**5 # 出力の制限 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) N, M, K = map(int, input().split()) m_pow = [0] * N m_pow[0] = 1 for i in range(1, N): m_pow[i] = m_pow[i - 1] * (M - 1) % mod ans = 0 for i in range(K+1): ans = (ans + cmb(N - 1, i, mod) * M * m_pow[N - 1 - i]) % mod print(ans)
from functools import reduce def cin(): return list(map(int,input().split())) N, M, K = cin() MOD = 998244353 fac = [1] * (N + 1) inv = [1] * (N + 1) for j in range(1, N + 1): fac[j] = fac[j - 1] * j % MOD inv[N] = pow(fac[N], MOD - 2, MOD) for j in range(N - 1, -1, -1): inv[j] = inv[j + 1] * (j + 1) % MOD def cmb(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % MOD ans = 0 for i in range(K + 1): ans += M * cmb(N - 1, i) * pow(M - 1, N - 1 - i, MOD) ans %= MOD print(ans)
1
23,089,538,786,204
null
151
151
N = int(input()) A = list(map(int, input().split())) INF = 10 ** 18 if N % 2: dp = [[-INF for j in range(N)] for i in range(3)] dp[0][0] = A[0] dp[1][1] = A[1] dp[2][2] = A[2] for j in range(N): for i in range(3): if dp[i][j] == -INF: continue for k in range(3): if i + k < 3 and j + k + 2 < N: dp[i + k][j + k + 2] = max(dp[i + k][j + k + 2], dp[i][j] + A[j + k + 2]) print(max(max(dp[0][-3:-1]), max(dp[1][-2:]), max(dp[2][-1:]))) else: dp = [[-INF for j in range(N)] for i in range(2)] dp[0][0] = A[0] dp[1][1] = A[1] for j in range(N): for i in range(2): if dp[i][j] == -INF: continue for k in range(2): if i + k < 2 and j + k + 2 < N: dp[i + k][j + k + 2] = max(dp[i + k][j + k + 2], dp[i][j] + A[j + k + 2]) print(max(max(dp[0][-2:]), max(dp[1][-1:])))
n=int(input()) a=list(map(int,input().split())) if n//2==1: print(max(a)) exit() if n%2==0: #iは桁数、jはそれまでに余計に飛ばした数 #dp[i][j] dp=[[-10**9]*2 for _ in range(n)] for i in range(n): if i<2: dp[i][0]=a[i] if i>=2: dp[i][0]=dp[i-2][0]+a[i] if i>=3: dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i]) #print(dp) print(max([dp[-1][1],dp[-1][0],dp[n-2][0]])) else: #iは桁数、jはそれまでに余計に飛ばした数 #dp[i][j] dp=[[-10**9]*3 for _ in range(n)] for i in range(n): if i<2: dp[i][0]=a[i] if i>=2: dp[i][0]=dp[i-2][0]+a[i] if i>=3: dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i]) if i>=4: dp[i][2]=max([dp[i-2][2]+a[i],dp[i-3][1]+a[i],dp[i-4][0]+a[i]]) #print(dp) print(max([dp[-1][2],dp[-1][1],dp[-1][0]-a[0],dp[-1][0]-a[-1]]))
1
37,331,231,537,600
null
177
177
from collections import deque n = int(input()) l = deque() for i in range(n): s = input() l.append(s) print(len(set(l)))
n, *a = map(int, open(0).read().split()) max_a = max(a) money = 1000 stock = 0 for i in range(n-1): if a[i] < a[i+1]: stock = money // a[i] money += (a[i+1] - a[i]) * stock print(money)
0
null
18,782,734,651,010
165
103
import math N, X, T = map(int, input().split()) t = int(math.ceil(N/X)) print('{}'.format(t*T))
n = int(input()) As = list(map(int, input().split())) internal_max = [1]*(n+1) internal_max[0] = 1-As[0] for i in range(1,n+1): internal_max[i] = 2*internal_max[i-1]-As[i] depth_sum = [0]*(n+1) depth_sum[n] = As[n] judge = False for i in range(n-1, -1, -1): if depth_sum[i+1] > internal_max[i]*2: judge = True break else: depth_sum[i] = As[i] + min(internal_max[i], depth_sum[i+1]) if n == 0: if As[0] > 1: judge = True if judge: print(-1) else: print(sum(depth_sum))
0
null
11,542,610,048,210
86
141
number = int(input()) words = {} answer = [] maxnum = 0 for i in range(number): word = input() if word in words: words[word] += 1 else: words[word] = 1 if maxnum < words[word]: maxnum = words[word] answer.clear() answer.append(word) elif maxnum == words[word]: answer.append(word) answer.sort() for j in range(len(answer)): print(answer[j])
n = int(input()) d = {} for i in range(n): s = str(input()) if s in d.keys(): d[s] += 1 else: d[s] = 1 max_count = max(d.values()) for i in sorted(d.keys()): if d[i] == max_count: print(i)
1
69,662,479,150,452
null
218
218
n, m = map(int,input().split()) nx = int(n * ( n - 1) / 2) mx = int(m * (m -1) / 2) print(nx + mx)
n,m=map(int,input().split()) ans=0 ans+=n*(n-1)//2 ans+=m*(m-1)//2 print(ans)
1
45,660,754,293,128
null
189
189
n = int(input()) a = [input() for i in range(n)] c0, c1, c2, c3 = 0, 0, 0, 0 for output in a: if output == 'AC': c0 += 1 elif output == 'WA': c1 += 1 elif output == 'TLE': c2 += 1 elif output == 'RE': c3 += 1 print('AC x {}'.format(c0)) print('WA x {}'.format(c1)) print('TLE x {}'.format(c2)) print('RE x {}'.format(c3))
h,w,n = [int(input()) for i in range(3)] print((n-1)//max(h,w)+1)
0
null
48,911,857,363,058
109
236
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines import numpy as np def main(): n = int(input()) if n == 1: print(1) sys.exit() divs = np.arange(1, n + 1) divs2 = n // divs divs3 = divs2 * (divs2 + 1) // 2 divs3 = divs3 * divs r = divs3.sum() print(r) if __name__ == '__main__': main()
def step_sum(n): return (n*(n+1))//2 n = int(input()) table = [0]*n ans = 0 for i in range(1, n+1): ans += i*step_sum(n//i) print(ans)
1
10,957,562,932,786
null
118
118
charge, n_coin = map(int,input().split()) coin_ls = list(map(int, input().split())) coin_ls = [0] + coin_ls dp = [[float('inf')] * (charge+1) for _ in range(n_coin+1)] dp[0][0] = 0 for coin_i in range(1,n_coin+1): for now_charge in range(0,charge+1): if now_charge - coin_ls[coin_i] >= 0: dp[coin_i][now_charge] = min(dp[coin_i][now_charge], dp[coin_i][now_charge-coin_ls[coin_i]]+1) dp[coin_i][now_charge] = min(dp[coin_i-1][now_charge], dp[coin_i][now_charge]) print(dp[n_coin][charge])
n,m=map(int,input().split()) c=list(map(int,input().split())) c.sort(reverse=True) #print(c) dp=[0] for i in range(1,n+1): mini=float("inf") for num in c: if i-num>=0: mini=min(mini,dp[i-num]+1) dp.append(mini) #print(dp) print(dp[-1])
1
142,641,182,398
null
28
28
d = ["ABC", "ARC"] s = input() print(d[1 - d.index(s)])
print({'ABC':'ARC', 'ARC':'ABC'}[input()])
1
24,036,906,281,908
null
153
153
a,b,c,d=map(float,input().split()) import math x=math.sqrt((c-a)**2+(d-b)**2) print("{:.5f}".format(x))
K = int(input()) S = input() len_S = len(S) if len_S <= K: print(S) else: print(S[:K] + '...')
0
null
9,853,380,117,450
29
143
N = int(input()) A = list(map(int, input().strip().split())) ans = 0 for i in range(1, N): if A[i] < A[i - 1]: ans += A[i - 1] - A[i] A[i] = A[i - 1] print(ans)
def A(): n, x, t = map(int, input().split()) print(t * ((n+x-1)//x)) def B(): n = list(input()) s = 0 for e in n: s += int(e) print("Yes" if s % 9 == 0 else "No") def C(): int(input()) a = list(map(int, input().split())) l = 0 ans = 0 for e in a: if e < l: ans += l - e l = max(l, e) print(ans) C()
1
4,582,209,284,662
null
88
88
def main(): s = input() lst1 = [] lst2 = [] total_area = 0 for i in range(len(s)): if s[i] == "\\": lst1.append(i) elif s[i] == "/" and len(lst1) > 0: j = lst1.pop() area = i - j total_area += area while len(lst2) > 0 and lst2[-1][0] > j: area += lst2.pop()[1] lst2.append([j, area]) print(total_area) print(len(lst2), *[area for j, area in lst2]) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- from sys import stdin import math # 0 0 1 1 A = list(map(float, stdin.readline().split())) x1, y1, x2, y2 = A[0], A[1], A[2], A[3] distance = math.sqrt(math.pow(x2-x1, 2) + math.pow(y2-y1,2)) print(format(distance,'.8f'))
0
null
107,796,359,832
21
29
while True: try: a,b = map(int,raw_input().split()) c=str(a+b) print len(c) except EOFError: break
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): while True: try: num = eval(input().replace(" ","+")) except: return else: print(len(str(num))) if __name__ == '__main__': main()
1
95,000,402
null
3
3
def readinput(): n=int(input()) a=list(map(int,input().split())) return n,a def main(n,a): a.sort() for i in range(n-1): if a[i]==a[i+1]: return 'NO' return 'YES' if __name__=='__main__': n,a=readinput() ans=main(n,a) print(ans)
# -*- coding:utf-8 -*- A_Bingo = [] for i in range(3): A_Bingo.append(list(map(int,input().split()))) card =[] n = int(input()) for k in range(n): card.append(int(input())) r_cnt =[0,0,0] c_cnt =[0,0,0] rc_result = [[0,0,0],[0,0,0],[0,0,0]] for row in range(3): for column in range(3): if A_Bingo[row][column] in card: r_cnt[row] += 1 c_cnt[column] += 1 rc_result[row][column] = 1 if 3 in r_cnt: print("Yes") elif 3 in c_cnt: print("Yes") elif rc_result[0][0]*rc_result[1][1]*rc_result[2][2] == 1: print("Yes") elif rc_result[0][2]*rc_result[1][1]*rc_result[2][0] == 1: print("Yes") else: print("No")
0
null
66,632,501,792,708
222
207
from itertools import permutations import sys N = int(sys.stdin.readline().rstrip()) P = [int(x) for x in sys.stdin.readline().rstrip().split()] Q = [int(x) for x in sys.stdin.readline().rstrip().split()] def nanba(N, P): P = tuple(P) for i, p in enumerate(permutations(range(1, N + 1), N)): # print(p) if P == p: return i return 0 a = nanba(N, P) b = nanba(N, Q) print(abs(a - b))
S = input() S = str.swapcase(S) print(S)
0
null
50,906,537,103,840
246
61
import sys input = sys.stdin.readline n = int(input()) a = [int(i) for i in input().split()] if n <= 3: print(max(a)) exit() a = tuple(a) dp = [[-10**15]*3 for i in range(n)] dp[0][2] = a[0] dp[1][2] = a[1] dp[2][2] = a[0]+a[2] dp[3][2] = max(a[0],a[1])+a[3] dp[3][1] = a[0]+a[3] for i in range(2,n-2): if i%2 == 0: dp[i+2][2] = dp[i][2]+a[i+2] dp[i+2][1] = max(dp[i][1]+a[i+2],dp[i-1][2]+a[i+2]) dp[i+2][0] = max(dp[i][0]+a[i+2],dp[i-1][1]+a[i+2],dp[i-2][2]+a[i+2]) else: dp[i+2][2] = max(dp[i][2],dp[i][1],dp[i-1][2])+a[i+2] dp[i+2][1] = max(dp[i][1]+a[i+2],dp[i-1][2]+a[i+2]) if n%2 == 1: c = min(a[0],a[-1]) dp[n-1][2] -= c print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))
#!/usr/bin/env python3 import sys def solve(N: int, A: "List[int]"): dp = [[0,0] for _ in range(N+1)] dp[2] = [A[0],A[1]] for i in range(2,N): if (i+1)%2 ==0: dp[i+1][0] = dp[i-1][0]+A[i-1] else: dp[i+1][0] = max(dp[i]) dp[i+1][1] = max(dp[i-1])+A[i] print(max(dp[N])) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == '__main__': main()
1
37,396,498,314,268
null
177
177
N = int(input()) ans = 10**12 for i in range(1,int(N**0.5)+1): j = N/i if(j == int(j)): ans = i+j-2 print(int(ans))
N = int(input()) root = int(N**0.5) for i in range(root,-1,-1): if N % i ==0: break print(int(N/i + i -2))
1
160,957,817,089,302
null
288
288
# Sum of Divisors import math N = int(input()) ans = 0 for i in range(1,N+1): K = math.floor(N/i) ans += (K * (K+1) * i)/2 print(int(ans))
# coding: utf-8 # Your code here! import itertools import numpy as np def main(): N, M, X = map(int, input().split()) for i in range(N): row = np.array(list(map(int, input().split()))) # print(row) if i == 0: c_array = row[0].reshape(1, 1) a_matrix = row[1:].reshape(1, len(row[1:])) else: c_array = np.append(c_array, row[0]) a_matrix = np.vstack([a_matrix, row[1:].reshape(1, len(row[1:]))]) # print(c_array) # print(a_matrix) min_cost = float("inf") for i in range(1, N+1): for v in itertools.combinations(np.arange(N), i): tmp = a_matrix[v, :].sum(axis=0) cost = c_array[list(v)].sum() # print(tmp) if tmp.min() >= X and cost <= min_cost: min_cost = cost if min_cost == float("inf"): print("-1") else: print(min_cost) main()
0
null
16,833,259,422,052
118
149
import itertools n = int(input()) X = list(map(int, input().split())) Y = list(map(int, input().split())) Z = list(itertools.product(X,Y)) Z = Z[::len(X)+1] def fn(p): D = 0 for z in Z: D += abs(z[0]-z[1])**p else: print(D**(1/p)) fn(1) fn(2) fn(3) MA = [] for z in Z: MA.append(abs(z[0]-z[1])) print(max(MA))
print(1&~int(input()))
0
null
1,559,128,991,430
32
76
a, b, c = (int(i) for i in ((input()).split())) if a < b < c: print('Yes') else: print('No')
x = int(input()) for a in range(-501, 501): for b in range(-501, 501): if a**5 - b** 5 == x: print (a, b) exit()
0
null
12,987,251,761,320
39
156
l = list(map(int, input().split())) for i in range(5): if l[i] == 0: print(i + 1)
S,W=map(int,input().split()) if S<=W:print('unsafe') else:print('safe')
0
null
21,347,240,370,090
126
163
## coding: UTF-8 mod = 998244353 N, S = map(int,input().split()) A = list(map(int,input().split())) dp = [] for i in range(N+1): #dp.append([0]*3010) dp.append([0]*(S+1)) #print(dp) dp[0][0] = 1 #print(dp) #print('dpstart') for i in range(N): for j in range(S+1): dp[i+1][j] += dp[i][j] dp[i+1][j] %= mod dp[i+1][j] += dp[i][j] dp[i+1][j] %= mod if(j >= A[i]): dp[i+1][j] += dp[i][j-A[i]] dp[i+1][j] %= mod #print(dp) print(dp[N][S])
n = int(raw_input()) debt=100000 for i in range(n): debt*=1.05 if debt % 1000 != 0: debt = (int(debt / 1000)+1) * 1000 else: debt = int(debt) print debt
0
null
8,847,243,146,310
138
6
s = input() if s == '0': print(1) else: print(0)
n = int(input()) a = list(map(int,input().split())) cnt = 0 for v in a: if v == cnt+1: cnt += 1 print(-1 if cnt==0 else n-cnt)
0
null
58,848,570,335,360
76
257
N, K = list(map(int, input().split())) P = list(map(int, input().split())) s = sum(P[:K]) ans = s for i in range(N-K): s = s - P[i] + P[i+K] ans = max(ans,s) print((ans + K) / 2)
N,K=map(int,input().split()) P=list(map(int,input().split())) from itertools import accumulate acc=[0] acc.extend(accumulate(P)) ans=0 for i in range(N-K+1): exp=(acc[K+i]-acc[i]+K)/2 ans=max(exp,ans) print(ans)
1
74,958,996,762,332
null
223
223
s = int(input()) mod = 10 ** 9 + 7 dp = [1, 0, 0] for _ in range(s - 2): dp.append((dp[-1] + dp[-3]) % mod) print(dp[s])
s=int(input()) A=[0,0,1] for i in range(3,s): A+=[A[i-1]+A[i-3]] print(A[s-1]%(10**9+7))
1
3,308,686,464,772
null
79
79
A, B, K = map(int, input().split()) if A-K >= 0: print(A-K, B) else: if B-(K-A)<0: print(0, 0) quit() print(0, B-(K-A))
from itertools import combinations_with_replacement as cwr N, M, Q = map(int, input().split()) abcd = [list(map(int, input().split())) for i in range(Q)] def calc_score(A): score = 0 for a, b, c, d in abcd: if A[b-1] - A[a-1] == c: score += d return score ans = 0 for A in cwr([i for i in range(1, M+1)], N): ans = max(ans, calc_score(A)) print(ans)
0
null
66,094,455,962,580
249
160
s = int(input()) a = [None, 0, 0] + [1] * (s - 2) for i in range(3, s - 2): a[i + 3] += a[i] a[i + 1] += a[i] print(a[s] % (10**9 + 7))
mod = 1000000007 ans = 0 power = [0 for i in range(2005)] power[0] = 1 for i in range(1,2001): power[i] = power[i-1] * i def C(x,y): return 0 if x < y else power[x] // power[y] // power[x-y] def H(x,y): return C(x+y-1,y-1) n = int(input()) for i in range(3,n+1,3): ans += H(n-i,i//3) ans = (ans % mod + mod) % mod print(ans)
1
3,313,797,689,290
null
79
79
N,K=map(int, input().split()) AA=list(map(int, input().split())) A=sorted(AA) B=sorted(AA)[::-1] mod=10**9+7 def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 n = 10**5+1 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, n+1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) ans=0 for i in range(N-K+1): d=(A[K-1+i]%mod)*cmb(K-1+i,K-1,mod) e=(B[K-1+i]%mod)*cmb(K-1+i,K-1,mod) ans+=d%mod-e%mod ans%=mod print(ans)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 # 出力の制限 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) ans = 0 for i in range(N-K+1): ans += A[-1-i]*cmb(N-1-i, K-1, mod) ans %= mod ans -= A[i]*cmb(N-1-i, K-1, mod) ans %= mod print(ans)
1
95,462,857,877,652
null
242
242
a, b, c = map(int, input().split()) x = c-a-b if x <= 0: print('No') elif 4*a*b < x*x: print('Yes') else: print('No')
a,b,c=list(map(int,raw_input().split())) if 4*a*b < (c-(a+b))*(c-(a+b)) and c > (a+b): print("Yes") exit(0) print("No")
1
51,582,696,039,690
null
197
197
k = int(input()) a,b = map(int,input().split()) x = (b // k) * k if a <= x <= b : print('OK') else : print('NG')
name=input() len_n=len(name) name2=input() len_n2=len(name2) if name==name2[:-1] and len_n+1==len_n2: print("Yes") else: print("No")
0
null
23,931,204,025,122
158
147
a, b, k = map(int,input().split()) if a <= k: k -= a a = 0 if b <= k: b =0 else: b -= k else: a -= k print(a, b)
ni = lambda: int(input()) nm = lambda: map(int, input().split()) nl = lambda: list(map(int, input().split())) a,b,n=nm() import math print(math.floor(a*(min(b-1,n)%b)/b))
0
null
66,255,170,558,510
249
161
n=int(input()) def f(x): z=1 while not(z*(z+1)<=2*x<(z+1)*(z+2)): z+=1 return z x=[-1]*(10**6+1) #2以上の自然数に対して最小の素因数を表す x[0]=0 x[1]=1 i=2 prime=[] while i<=10**6: if x[i]==-1: x[i]=i prime.append(i) for j in prime: if i*j>10**6 or j>x[i]:break x[j*i]=j i+=1 if n==1: print(0) exit() a=[] q=0 for i in range(len(prime)): p=prime[i] while n%p==0: q+=1 n=n//p if q>0:a.append(q) q=0 ans=0 for i in range(len(a)): ans+=f(a[i]) print(ans if n==1 else ans+1)
S = str(input()) Q = int(input()) flip = 0 front,back = '','' for i in range(Q): j = input() if len(j) == 1: flip += 1 continue else: if j[2] == '1' and flip % 2 == 0: front = j[4] + front continue elif j[2] == '2' and flip % 2 == 0: back = back + j[4] continue elif j[2] == '1' and flip % 2 ==1: back= back + j[4] continue elif j[2] == '2' and flip % 2 ==1: front = j[4] + front continue S = front + S + back if flip % 2 == 1: S = S[::-1] print(S)
0
null
37,086,891,474,062
136
204
def selection_sort(A, n): count = 0 for i in range(n-1): minj = i for j in range(i, n): if A[j] < A[minj]: minj = j if i != minj: A[i], A[minj] = A[minj], A[i] count += 1 print(' '.join(map(str, A))) print(count) if __name__ == '__main__': n = int(input()) A = list(map(int, input().split())) selection_sort(A, n)
n = input() a = map(int, raw_input().split()) c = 0 for i in range(n): mini = i for j in range(i, n): if a[j] < a[mini]: mini = j if a[i] != a[mini]: a[i], a[mini] = a[mini], a[i] c += 1 print(" ".join(map(str, a))) print(c)
1
19,975,409,458
null
15
15
import sys ERROR_INPUT = 'input is invalid' def main(): n = get_length() arr = get_array(length=n) insetionSort(li=arr, length=n) return 0 def get_length(): n = int(input()) if n < 0 or n > 100: print(ERROR_INPUT) sys.exit(1) else: return n def get_array(length): nums = input().split(' ') return [str2int(string=n) for n in nums] def str2int(string): n = int(string) if n < 0 or n > 1000: print(ERROR_INPUT) sys.exit(1) else: return n def insetionSort(li, length): for n in range(0, length): print(*(sorted(li[0:n + 1]) + li[n + 1:length])) main()
for i in range(1,int(input())+1): x=i if x % 3 == 0: print(" "+str(i), end="") else: while x != 0: if x % 10 == 3: print(" "+str(i), end="") break else: x = x//10 print("")
0
null
471,033,277,608
10
52
text = raw_input() t = list(text) for i in range(len(t)): if t[i].isupper(): t[i] = t[i].lower() elif t[i].islower(): t[i] = t[i].upper() print "".join(t)
import math as mt x = list(map(float,input().split())) a = ((x[0]-x[2])**2)+((x[1]-x[3])**2) print(mt.sqrt(a))
0
null
841,206,773,288
61
29
h,a=map(int,input().split()) for i in range(1,10001): if a*i >= h: print(i) break
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def solve(H: int, A: int): return H//A+(H % A > 0) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int A = int(next(tokens)) # type: int print(f'{solve(H, A)}') if __name__ == '__main__': main()
1
77,170,779,483,922
null
225
225
import sys #input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode() #import numpy as np def main(): n,k=MI() p=LI() for i in range(n): p[i]=p[i]/2+0.5 #print(p) ans=sum(p[:k]) now=sum(p[:k]) for i in range(n-k): now=now-p[i]+p[i+k] ans=max(ans,now) print(ans) if __name__ == "__main__": main()
from itertools import accumulate N, K = map(int, input().split()) P = list(map(int, input().split())) A = list(accumulate(P)) largest = A[K-1] point = 0 for i in range(K, N): if largest < A[i] - A[i-K]: largest = A[i] - A[i-K] point = i ans = 0 for j in range(point - K + 1, point+1): p = P[j] ans += (((p + 1) * p) / 2) / p print(ans)
1
74,874,764,529,810
null
223
223
print("0" if input()=="1" else "1")
a, b = map(int, input().split()) mini, big = (a, b) if a < b else (b, a) while True: rem = big % mini if rem == 0: break mini, big = rem, mini print(mini)
0
null
1,478,362,047,008
76
11
n = list(map(int,list(input()))) if 7 in n: print("Yes") else: print("No")
import numpy as np def divisors(N): return sorted(sum((list({n, N // n}) for n in range(1, int(N ** 0.5) + 1) if not N % n), [])) def prime_factorize_dict(n): d = dict() while not n & 1: d[2] = d.get(2, 0) + 1 n >>= 1 f = 3 while f * f <= n: if not n % f: d[f] = d.get(f, 0) + 1 n //= f else: f += 2 if n != 1: d[n] = d.get(n, 0) + 1 return d N = int(input()) count = 0 for n in divisors(N)[1:]: M = N while not M % n: M //= n count += M % n == 1 fact_Nm1 = np.array(list(prime_factorize_dict(N - 1).values()), dtype=np.int32) print(count + np.prod(fact_Nm1 + 1) - 1)
0
null
37,932,899,754,130
172
183
k = int(input()) a,b = [int(a) for a in input().split()] c=0 for i in range (a,b+1): if i%k!=0: c+=1 if c==b-a+1: print("NG") else: print("OK")
import sys from collections import deque n = int(sys.stdin.readline()) G = [[] for _ in range(n+1)] G_order = [] for i in range(n-1): a,b = map(lambda x:int(x)-1, sys.stdin.readline().split()) G[a].append(b) G_order.append(b) que = deque([0]) C = [0]*(n+1) while que: nw = que.popleft() c = 1 for nx in G[nw]: if c==C[nw]: c+=1 C[nx] = c c += 1 que.append(nx) print(max(C)) for i in G_order: print(C[i])
0
null
81,460,214,238,228
158
272
n = int(input()) a = list(map(int, input().split(' '))) q = int(input()) M = list(map(int, input().split(' '))) minA = min(a) sumA = 0 for i in a: sumA += i def solve(i, m): if m==0 : return True if i>=n: return False res = solve(i+1, m) or solve(i+1, m-a[i]) return res for j in M: if j < minA or j > sumA: print('no') else: if solve(0, j): print('yes') else: print('no')
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
77,307,147,688
25
21
tmp = input().split(" ") a = int(tmp[0]) b = int(tmp[1]) c = int(tmp[2]) if a + b + c >= 22: print("bust") else: print("win")
import sys from functools import reduce n=int(input()) s=[input() for i in range(n)] t=[2*(i.count("("))-len(i) for i in s] if sum(t)!=0: print("No") sys.exit() st=[[t[i]] for i in range(n)] for i in range(n): now,mi=0,0 for j in s[i]: if j=="(": now+=1 else: now-=1 mi=min(mi,now) st[i].append(mi) now2=sum(map(lambda x:x[0],filter(lambda x:x[1]>=0,st))) v,w=list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st)) v.sort(reverse=True,key=lambda z:z[1]) w.sort(key=lambda z:z[0]-z[1],reverse=True) #print(now2) for vsub in v: if now2+vsub[1]<0: print("No") sys.exit() now2+=vsub[0] for wsub in w: if now2+wsub[1]<0: print("No") sys.exit() now2+=wsub[0] print("Yes")
0
null
71,139,416,794,450
260
152
import sys def allocate(count, weights): """allocate all packages of weights onto trucks. returns maximum load of trucks. >>> allocate(2, [1, 2, 2, 6]) 6 >>> allocate(3, [8, 1, 7, 3, 9]) 10 """ def loadable_counts(maxweight): n = 0 l = 0 c = count for w in weights: l += w if l > maxweight: l = w c -= 1 if c <= 0: return n n += 1 return n i = max(weights) j = max(weights) * len(weights) // count while i < j: mid = (i + j) // 2 if loadable_counts(mid) < len(weights): i = mid + 1 else: j = mid return i def run(): k, n = [int(i) for i in input().split()] ws = [] for i in sys.stdin: ws.append(int(i)) print(allocate(n, ws)) if __name__ == '__main__': run()
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**10 def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): n, k = LI() Q = [I() for _ in range(n)] def can_stack(p): s = 0 truck_num = 1 for i in Q: if s+i<=p: s += i else: truck_num += 1 s = i return truck_num<=k ng = max(Q)-1 ok = sum(Q) while abs(ok-ng)>1: m = (ng+ok)//2 if can_stack(m): ok = m else: ng = m print(ok) # for i in range(20): # print(i, can_stack(i)) if __name__ == '__main__': resolve()
1
88,742,471,422
null
24
24
# -*- coding: utf_8 -*- level = False def debug(v): if level: print(v) n = int(input()) a = [0] for i in range(n): v = input().split() v.pop(0) v.pop(0) a.append([int(x) for x in v]) debug(a) stack = [1] results = [[0 for i in range(2)] for j in range(n + 1)] results[0][0] = 0 time = 0 def depth_first_search(a, stack): debug(a) debug(results) debug(stack) global time if len(stack) == 0: return v = stack.pop() if results[v][0] == 0: time += 1 results[v][0] = time es = a[v] if len(es) == 0 and results[v][1] == 0: time += 1 results[v][1] = time if len(es) != 0: stack.append(v) next_vert = es.pop(0) if results[next_vert][0] == 0: stack.append(next_vert) depth_first_search(a, stack) for i in range(n): stack = [i + 1] depth_first_search(a, stack) debug(results) results.pop(0) i = 1 for row in results: print(str(i) + " " + str(row[0]) + " " + str(row[1])) i += 1
#16D8101014F KurumeRyunosuke 2018/6/20 n=int(input()) ls=[[0 for i in range(n)]for j in range(n)] for i in range(n): tmp=input().split() for j in range(int(tmp[1])): ls[i][int(tmp[j+2])-1]=1 """ for i in range(n): for j in range(n): if(j!=n-1): print(int(ls[i][j]), end=' ') else: print(int(ls[i][j])) """ stuck=[0] count=1 d=[0 for i in range(n)] f=[0 for i in range(n)] d[0]=count for i in range(n): ls[i][0]=0 while True: count+=1 p=0 #print("S",d) for i in range(n): if ls[stuck[len(stuck)-1]][i] is not 0: ls[stuck[len(stuck)-1]][i]=0 p=1 #print(stuck) stuck.append(i) d[stuck[len(stuck)-1]]=count break #print(d,"**") if p is 1: for i in range(n): ls[i][stuck[len(stuck)-1]]=0 if p is 0: #print("//",count) a=stuck.pop() f[a]=count for i in range(n): ls[a][i]=0 #print(d,"¥¥¥") if len(stuck) is 0: t=0 for i in range(n): for j in range(n): if ls[i][j] is not 0 and t is 0: count+=1 stuck.append(i) d[stuck[len(stuck)-1]]=count #print(i,"***") t=1 if t is 0: break #print("break") #print("G",d,f,count) for i in range(n): print(i+1,d[i],f[i])
1
3,027,686,372
null
8
8
mod = 1000000007 fact = [] fact_inv = [] pow_ = [] pow25_ = [] pow26_ = [] def pow_ini(nn): global pow_ pow_.append(nn) for j in range(62): nxt = pow_[j] * pow_[j] nxt %= mod pow_.append(nxt) return def pow_ini25(nn): global pow25_ pow25_.append(nn) for j in range(62): nxt = pow25_[j] * pow25_[j] nxt %= mod pow25_.append(nxt) return def pow_ini26(nn): global pow26_ pow26_.append(nn) for j in range(62): nxt = pow26_[j] * pow26_[j] nxt %= mod pow26_.append(nxt) return def pow1(k): ansk = 1 for ntmp in range(62): if((k >> ntmp) % 2 == 1): ansk *= pow_[ntmp] ansk %= mod return ansk def pow25(k): ansk = 1 for ntmp in range(31): if((k >> ntmp) % 2 == 1): ansk *= pow25_[ntmp] ansk %= mod return ansk def pow26(k): ansk = 1 for ntmp in range(31): if((k >> ntmp) % 2 == 1): ansk *= pow26_[ntmp] ansk %= mod return ansk def fact_ini(n): global fact global fact_inv global pow_ for i in range(n + 1): fact.append(0) fact_inv.append(0) fact[0] = 1 for i in range(1, n + 1, 1): fact_tmp = fact[i - 1] * i fact_tmp %= mod fact[i] = fact_tmp pow_ini(fact[n]) fact_inv[n] = pow1(mod - 2) for i in range(n - 1, -1, -1): fact_inv[i] = fact_inv[i + 1] * (i + 1) fact_inv[i] %= mod return def nCm(n, m): assert(m >= 0) assert(n >= m) ans = fact[n] * fact_inv[m] ans %= mod ans *= fact_inv[n - m] ans %= mod return ans; fact_ini(2200000) pow_ini25(25) pow_ini26(26) K = int(input()) S = input() N = len(S) ans = 0 for k in range(0, K+1, 1): n = N + K - k anstmp = 1 anstmp *= pow26(k) anstmp %= mod anstmp *= nCm(n - 1, N - 1) anstmp %= mod anstmp *= pow25(n - N) anstmp %= mod ans += anstmp ans %= mod print(ans)
import sys import math import fractions from collections import defaultdict stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) mod=10**9+7 K=int(input()) S=list(ns()) N=K+len(S) class My_pow(): def __init__(self,n,r,p): self.pow=[0]*r self.pow[0]=1 for i in range(1,r): self.pow[i]=(self.pow[i-1]*n)%p def clc_pow(self,r): return self.pow[r] class My_comb(): def __init__(self,MOD,Nmax): self.p=MOD self.fact=[1,1] self.factinv=[1,1] self.inv=[0,1] for i in range(2,Nmax+1): self.fact.append((self.fact[-1]*i)%self.p) self.inv.append((-self.inv[self.p%i]*(self.p//i))%self.p) self.factinv.append((self.factinv[-1]*self.inv[-1])%self.p) def comb(self,n,r): if(r<0) or (n<r): return 0 r=min(r,n-r) return self.fact[n]*self.factinv[r]*self.factinv[n-r]%self.p my_comb=My_comb(mod,2*(10**6)) my_pow26=My_pow(26,K+5,mod) my_pow25=My_pow(25,K+5,mod) ans=0 for i in range(K+1): now =(my_pow26.clc_pow(K-i)*my_pow25.clc_pow(i)) now *=my_comb.comb(i+len(S)-1,len(S)-1) ans += now ans%=mod print(ans)
1
12,716,741,118,304
null
124
124
import sys from functools import lru_cache from collections import defaultdict inf = float('inf') readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def read(): return int(readline()) def reads(): return map(int, readline().split()) a,b,n=reads() x=min(b-1,n) print(int((a*x)/b))
n,k = map(int,input().split()) button = list(map(int,input().split())) visit = [-1]*n hisitory = [-1] push = 0 f = 0 for i in range(k): visit[push] = i+1 hisitory.append(push) push = button[push] -1 if(visit[push] != -1): f = 1 start = visit[push] last=push end = i+1 break if(f == 0): print(button[hisitory[-1]]) else: geta = start -1 loopk = k - geta loop = end -start + 1 modk = loopk%loop if(modk == 0): modk = loop print(button[hisitory[geta + modk]]) # print(hisitory) # print(geta,modk,loop)
0
null
25,361,221,916,730
161
150
n = int(input()) dp = [0]*(n+1) def fibo(n): if n <2: return 1 if dp[n] > 0: return dp[n] dp[n] = fibo(n-1) + fibo(n -2) return dp[n] print(fibo(n))
def main(): N = int(input()) if N <= 1: print(1) return fib = [0]*(N+1) fib[0], fib[1] = 1, 1 for i in range(2, N+1): fib[i] = fib[i-1] + fib[i-2] print(fib[N]) if __name__ == "__main__": main()
1
2,053,128,672
null
7
7
n = int(input()) arr = list(map(int, input().split())) arr = sorted(arr) m = arr[-1] li = [0]*(m+1) cnt = 0 for i in arr: for j in range(i, m+1, i): li[j] += 1 for i in arr: if li[i] == 1: cnt += 1 print(cnt)
n = int(input()) lst = [int(i) for i in input().split()] lst.sort() #print(lst) if 1 in lst: count = 0 for i in range(n): if lst[i] == 1: count += 1 if count == 2: break if count == 1: print(1) else: print(0) else: tf_lst = [1] * lst[n - 1] count = 0 if n > 1: pre = 0 for i in range(n): tf_lst[pre:lst[i] - 1] = [0] * (lst[i] - pre - 1) pre = lst[i] if tf_lst[lst[i] - 1] == 0: continue if i <= n - 2: if lst[i] == lst[i + 1]: tf_lst[lst[i] - 1] = 0 for j in range(lst[i] * 2, lst[n - 1] + 1, lst[i]): tf_lst[j - 1] = 0 #print(tf_lst) for i in tf_lst: count += i else: count += 1 print(count)
1
14,453,553,305,190
null
129
129
n=int(input()) a=list(int(x) for x in input().split()) count=0 z=True j=0 if 1 not in a: print(-1) else: for k in range(j,n): if a[k]==count+1: j=k count=count+1 print(n-count)
def resolve(): N = int(input()) a = list(map(int, input().split())) cnt = 1 ans = 0 for i in range(N): if a[i] == cnt: cnt += 1 else: ans += 1 if ans == N: print(-1) return print(ans) return resolve()
1
114,748,513,218,682
null
257
257
N, M = map(int, input().split()) diffs = [False] * N a = 1 b = N for _ in range(M): while True: diff0 = b-a diff1 = (N+a-b) if not diffs[diff0] and not diffs[diff1]: break b-=1 diffs[diff0] = True diffs[diff1] = True print(str(a) + ' ' + str(b)) a += 1 b -= 1 if b-a == (N+a-b): b-=1
def resolve(): N, M = map(int, input().split()) if N%2==1: for i in range(1, M+1): a, b = i, N-i print(a, b) else: for i in range(1, M+1): a, b = i, N - i # 円として配置したとき、b-aが半分以上になったら片方だけ進める if b-a <= N//2: a += 1 print(a, b) if __name__ == "__main__": resolve()
1
28,556,413,443,080
null
162
162
l=[[[0 for i in range(10)] for i in range(3)] for i in range(4)] n=int(input()) for i in range(n): a,b,c,d=list(map(int,input().split())) l[a-1][b-1][c-1]+=d for i in l[:-1]: for j in i: print(" "+" ".join(list(map(str,j)))) print("####################") for j in l[-1]: print(" "+" ".join(list(map(str,j))))
# -*- coding: utf-8 -*- # B import sys from collections import defaultdict, deque from heapq import heappush, heappop import math import bisect input = sys.stdin.readline # 再起回数上限変更 # sys.setrecursionlimit(1000000) N, k = map(int, input().split()) h = list(map(int, input().split())) # print(h) h.sort() a = bisect.bisect_left(h, k) print(N-a)
0
null
89,614,021,453,638
55
298
def resolve(): N, D = map(int, input().split()) P = [list(map(int, input().split())) for x in range(N)] cnt = 0 for p in P: d = (p[0] ** 2 + p[1] ** 2) ** 0.5 if d <= D: cnt += 1 print(cnt) resolve()
import math n,d=map(int,input().split()) L=[list(map(int, input().split())) for i in range(n)] x=0 for i in range(n): if math.sqrt(L[i][0]**2+L[i][1]**2)<=d: x+=1 else: pass print(x)
1
5,984,481,300,160
null
96
96
import sys import math import itertools as it def I():return int(sys.stdin.readline().replace("\n","")) def I2():return map(int,sys.stdin.readline().replace("\n","").split()) def S():return str(sys.stdin.readline().replace("\n","")) def L():return list(sys.stdin.readline().replace("\n","")) def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()] def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split())) if __name__ == "__main__": n = I() a = Intl() for i in range(n): if a[i]%2 == 0: if a[i]%3 == 0 or a[i]%5 == 0:pass else: print("DENIED") exit() print("APPROVED")
n = int(input()) p = list(map(int,input().split())) for x in p: if x % 2 == 0: if x % 3 != 0 and x % 5 != 0: print("DENIED") break else : print("APPROVED")
1
68,923,113,617,788
null
217
217
A,B,K = list(map(int,input().split())) if K <= A: print(A - K, B) if A < K and K <= A + B: print(0, A + B - K) if A + B < K: print(0, 0)
while(1): sen1=input() if sen1=="-": break suff=int(input()) for i in range(suff): h=int(input()) sen1=sen1[h:]+sen1[:h] print(sen1)
0
null
52,880,654,400,248
249
66
a,b,c,d=map(int,input().split(' ')) if a>=0: if d<=0: ans=a*d else: x=b y=d ans=b*d elif a<=0 and b>=0: if c>=0: x=b y=d ans=b*d elif c<=0 and d>=0: ans=max(a*c,b*d) else: ans=a*c else: if c>=0: ans=b*c else: ans=a*c print(ans)
N=int(input()) A,B=[],[] for i in range(N): x,y=map(int, input().split()) A.append(x+y) B.append(x-y) A=sorted(A) B=sorted(B) print(max(abs(A[0]-A[-1]),abs(B[0]-B[-1])))
0
null
3,243,673,874,560
77
80
N, K = [int(x) for x in input().split()] P = [0] + [int(x) for x in input().split()] C = [0] + [int(x) for x in input().split()] max_score = max(C[1:]) for init in range(1, N + 1): # 初めの場所をinitとする score = [0] # k回移動後のスコア i = init for k in range(1, K + 1): i = P[i] # k回移動後に着くところ score.append(score[-1] + C[i]) max_score = max(max_score, score[k]) if i == init: # ループ検出 loop_score = score[-1] loop_len = k if loop_score > 0: max_score = max(max_score, max(score[j] + loop_score * ((K - j) // loop_len) for j in range(1, loop_len + 1))) break print(max_score)
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print('\n'.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) from itertools import accumulate def sum_max(line,n_min,n_max): n = len(line) ac = list(accumulate([0]+line)) l = 0 r = n_min ans = ac[r]-ac[l] i = 0 if n_min==n_max: for i in range(n-n_min+1): ans = max(ans,ac[i+n_min]-ac[i]) else: while r!=n or i%2==1: if i%2==0: r = ac[r+1:l+n_max+1].index(max(ac[r+1:l+n_max+1])) + r+1 else: l = ac[l+1:r-n_min+1].index(min(ac[l+1:r-n_min+1])) + l+1 i+=1 ans = max(ans,ac[r]-ac[l]) return ans def sum_min(line,n_min,n_max): n = len(line) ac = list(accumulate([0]+line)) l = 0 r = n_min ans = ac[r]-ac[l] i = 0 if n_min==n_max: for i in range(n-n_min+1): ans = min(ans,ac[i+n_min]-ac[i]) else: while r!=n or i%2==1: if i%2==0: r = ac[r+1:l+n_max+1].index(min(ac[r+1:l+n_max+1])) + r+1 else: l = ac[l+1:r-n_min+1].index(max(ac[l+1:r-n_min+1])) + l+1 i+=1 ans = min(ans,ac[r]-ac[l]) return ans def circle_sum_max(circle,num): n = len(circle) s = sum(circle) if num == 0: ans = 0 else: ans = max(sum_max(circle,1,num), s-sum_min(circle,n-num,n-1)) return ans n,k = readints() p = [x-1 for x in readints()] c = readints() circles = [] used = [0]*n for i in range(n): if not used[i]: circles.append([c[i]]) used[i] = 1 j = p[i] while not used[j]: circles[-1].append(c[j]) used[j] = 1 j = p[j] score = -10**20 for cir in circles: m = len(cir) a = sum(cir) if k>m: if a>0: score = max(score, (k//m)*a + circle_sum_max(cir,k%m), (k//m-1)*a + circle_sum_max(cir,m)) else: score = max(score,circle_sum_max(cir,m)) else: score = max(score,circle_sum_max(cir,k)) print(score)
1
5,395,727,535,460
null
93
93
n = int(input()) a = list(map(int,input().split())) count = 0 for i in range(n): minij =i for j in range(i,n): if a[j] < a[minij]: minij = j if a[i] > a[minij]: count+=1 a[i],a[minij] = a[minij],a[i] print(' '.join(map(str,a))) print(count)
N = int(input()) A = list(map(int,input().split())) cnt = 0 for i in range(N): minj = i for j in range(i+1,N): if A[j] < A[minj]: minj = j if i != minj: A[i],A[minj] = A[minj],A[i] cnt += 1 print(*A) print(cnt)
1
19,355,250,748
null
15
15
from sys import stdin N, D = map(int, input().split()) points = [] for i in range(N): X, Y = map(int, stdin.readline()[:-1].split()) points.append((X, Y)) count = 0 for i in range(N): X, Y = points[i] d = (X**2 + Y**2) ** 0.5 if d <= D: count += 1 print(count)
n = int(input()) cout = "" for i in range(1,n+1): x = i if x%3 == 0: cout += " " + str(i) else: while x > 0: if x%10 == 3: cout += " " + str(i) break x //= 10 print (cout)
0
null
3,378,159,353,452
96
52
n,m=list(map(int,input().split(' '))) am=[[0 for j in range(m)] for i in range(n)] bm=[0 for l in range(m)] cm=[0 for i in range(n)] for i in range(n): am[i]=list(map(int,input().split(' '))) for j in range(m): bm[j]=int(input()) for i in range(n): for j in range(m): cm[i]=cm[i]+am[i][j]*bm[j] for i in range(n): print(cm[i])
import sys inint = lambda: int(sys.stdin.readline()) inintm = lambda: map(int, sys.stdin.readline().split()) inintl = lambda: list(inintm()) instrm = lambda: map(str, sys.stdin.readline().split()) instrl = lambda: list(instrm()) a, b = inintm() for i in range(10001): if i*0.08//1 == a and i*0.1//1 == b: print(i) exit() print(-1)
0
null
28,634,575,568,268
56
203
n,k=map(int,input().split()) price=list(map(int,input().split())) s_price=sorted(price) mysum=0 for i in range(k): mysum+=s_price[i] print(mysum)
N,K=input().split() N=int(N) K=int(K) a=[] a=[int(a) for a in input().split()] a.sort() print(sum(a[0:K]))
1
11,701,048,122,820
null
120
120
N = int(input()) list_price = [int(input()) for i in range(N)] minv = list_price[0] maxv = list_price[1] - list_price[0] for x in list_price[1:]: maxv = max(maxv, x - minv) minv = min(minv, x) print(maxv)
n = int(input()) i, j = int(input()), 0 nmin = i a = -2 * 10 ** 9 for h in range(n - 1): j = int(input()) a = max(a, j - nmin) if j < nmin: nmin = j print(a)
1
13,005,742,136
null
13
13
N,M = map(int,input().split()) A = list(map(int,input().split())) A.sort(reverse = True) num = 0 for i in A: num += i if A[M-1] >= num/(4*M): print('Yes') else: print('No')
import collections n = int(input()) d = list(map(int,input().split())) mod = 998244353 ans = 0 c = collections.Counter(d) if c[0] == 1 and d[0] == 0: ans = 1 for i in range(1,max(d)+1): if c[i] == 0: ans = 0 break ans *= pow(c[i-1],c[i],mod) ans %= mod print(ans%mod)
0
null
96,965,267,024,960
179
284
#!/usr/bin/env python3 print(int(input())**3 / 27)
def main(): S = input() if S == "SUN": print(7) exit(0) elif S == "MON": print(6) exit(0) elif S == "TUE": print(5) exit(0) elif S == "WED": print(4) exit(0) elif S == "THU": print(3) exit(0) elif S == "FRI": print(2) exit(0) else: print(1) exit(0) if __name__ == "__main__": main()
0
null
90,324,065,974,570
191
270
input = raw_input() for i in xrange(len(input)): # print "i = " + str(i) + ", input[i] = " + input[i] if input[i].islower(): input = input[:i] + input[i].upper() + input[i + 1:] elif input[i].isupper(): input = input[:i] + input[i].lower() + input[i + 1:] print input
answer_string='' string=input() for i in string: if i.isupper(): i=i.lower() elif i.islower(): i=i.upper() answer_string+=i print(answer_string)
1
1,506,921,241,580
null
61
61
INF = 10**18 def solve(n, a): # 現在の位置 x 選んだ個数 x 直前を選んだかどうか dp = [{j: [-INF, -INF] for j in range(i//2-1, (i+1)//2 + 1)} for i in range(n+1)] dp[0][0][False] = 0 for i in range(n): for j in dp[i].keys(): if (j+1) in dp[i+1]: dp[i+1][j+1][True] = max(dp[i+1][j+1][True], dp[i][j][False] + a[i]) if j in dp[i+1]: dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][False]) dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][True]) return max(dp[n][n//2]) n = int(input()) a = list(map(int, input().split())) print(solve(n, a))
from collections import defaultdict N = int(input()) *A, = map(int, input().split()) INF = 10**20 dp = [[defaultdict(lambda :-INF) for _ in range(N+1)] for _ in range(2)] dp[0][0][0] = 0 for i in range(1, N+1): for j in range(i//2-1, i//2+2): dp[1][i][j] = max(dp[1][i][j], dp[0][i-1][j-1]+A[i-1]) dp[0][i][j] = max(dp[1][i-1][j], dp[0][i-1][j]) ans = max(dp[1][N][N//2], dp[0][N][N//2]) print(ans)
1
37,229,786,744,720
null
177
177
def main(): N = int(input()) x, y = map(int, input().split()) a1 = x + y a2 = x + y b1 = y - x b2 = y - x N -= 1 while N != 0: x, y = map(int, input().split()) a1 = max(a1, x + y) a2 = min(a2, x + y) b1 = max(b1, y - x) b2 = min(b2, y - x) N = N - 1 print(max(a1 - a2, b1 - b2)) main()
n = int(input()) xs = [] ys = [] for _ in range(n): x, y = map(int, input().split()) xs.append(x + y) ys.append(x - y) xs.sort() ys.sort() ans = max(xs[-1] - xs[0], ys[-1] - ys[0]) print(ans)
1
3,433,640,986,492
null
80
80
#!/usr/bin/env python3 def main(): n, u, v = map(int, input().split()) u -= 1 v -= 1 adj = [[] for i in range(n)] for i in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 adj[a].append(b) adj[b].append(a) # uv間経路を求める st = [u] prev = [None for i in range(n)] while st: x = st.pop() for y in adj[x]: if y == prev[x]: continue prev[y] = x st.append(y) path = [v] while path[-1] != u: path.append(prev[path[-1]]) path = list(reversed(path)) # crossからsquareを経由しない最遠ノードstarを求める(a59p22) l = len(path) - 1 cross = path[(l - 1) // 2] square = path[(l - 1) // 2 + 1] st = [(cross, 0)] prev = [None for i in range(n)] dist = [-1 for i in range(n)] while st: x, d = st.pop() dist[x] = d for y in adj[x]: if y == prev[x]: continue if y == square: continue prev[y] = x st.append((y, d + 1)) star_square = max(dist) if l % 2 == 1: res = (l - 1) // 2 + star_square else: res = (l - 1) // 2 + star_square + 1 print(res) if __name__ == "__main__": main()
while True: h, w = map(int, raw_input().split()) if h == 0 and w == 0: break print(("#" * w + "\n") + ("#" + "." * (w-2) + "#" + "\n") * (h-2) + ("#" * w + "\n"))
0
null
59,001,545,642,676
259
50
s=input() i=s[-1] if i=='2' or i=='4' or i=='5' or i=='7' or i=='9': print('hon') elif i=='0' or i=='1' or i=='6' or i=='8': print('pon') else: print('bon')
M = 10 ** 6 d = [0] * (M+1) for a in range(1, M+1): for b in range(a, M+1): n = a * b if n > M: break d[n] += 2 - (a==b) N = int(input()) ans = 0 for c in range(1, N): ans += d[N - c] print(ans)
0
null
10,875,554,669,740
142
73
import sys sys.setrecursionlimit(1000000000) ii = lambda: int(input()) mis = lambda: map(int, input().split()) lmis = lambda: list(mis()) mlmis = lambda: [-int(x) for x in input().split()] INF = float('inf') # def main(): H,W,K=mis() S = [input() for i in range(H)] ranges = [] u = b = 0 while u < H: if '#' in S[b]: ranges.append(range(u, b+1)) u = b = b+1 elif b == H-1: last = ranges.pop() ranges.append(range(last[0], H)) break else: b += 1 c = 1 for ran in ranges: l = r = 0 s = [] while l < W: s.append(c) if any(S[i][r]=='#' for i in ran): c += 1 l = r = r+1 elif r == W-1: for i, elem in enumerate(s): if elem == c: s[i] = c-1 break else: r += 1 for _ in ran: print(' '.join(map(str, s))) main()
s=input() li=list(s) adana_li=[] for i in range(3): adana_li.append(li[i]) adana=li[0]+li[1]+li[2] print(adana)
0
null
79,478,008,603,772
277
130
A,B=input().split() A=int(A) B=int(100*float(B)+0.1) print(int(A*B/100))
def mult(num): print(int(num[0])*int(num[1])) num = input().split() mult(num)
1
15,825,630,041,020
null
133
133
n=int(input()) x=list(map(int,input().split())) m=10**15 for i in range(101): t=x[:] s=sum(list(map(lambda x:(x-i)**2,t))) m=min(m,s) print(m)
n = int(input()) x = list(map(int, input().split())) ans = 1000000 for i in range(1, 101): s = 0 for j in range(n): s += (x[j] - i)*(x[j] - i) ans = min(ans, s) print(str(ans))
1
65,256,853,463,982
null
213
213
from sys import setrecursionlimit, exit setrecursionlimit(1000000000) def main(): n = int(input()) ans = 0 for i in range(1, n + 1): s = str(i) if s[-1] == '0': continue if s[0] == s[-1]: ans += 1 if i < 10: continue if s[0] == s[-1]: ans += 2 l = len(s) for i in range(2, l): ans += 10 ** (i - 2) * 2 if s[0] < s[-1]: continue if s[0] > s[-1]: ans += 10 ** (l - 2) * 2 elif l > 2: dp = int(s[1]) for i in range(2, l - 1): dp *= 10 dp += int(s[i]) ans += dp * 2 print(ans) main()
def main(): t1,t2=map(int,input().split()) a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) if a1<b1: a1,b1,a2,b2 = b1,a1,b2,a2 d1 = a1*t1 d2 = b1*t1 dd1 = d1 - d2 d1 += a2*t2 d2 += b2*t2 if d1 == d2: return "infinity" dd2 = d1 - d2 if dd1 * dd2 > 0: return 0 else: d1 += a1*t1 d2 += b1*t1 dd3 = d1 - d2 if dd2 * dd3 > 0: return 1 else: d1 += a2*t2 d2 += b2*t2 dd4 = d1 - d2 if dd3 * dd4 > 0: return 2 else: if dd1 > dd3: if dd1 % (dd1-dd3) == 0: return (dd1 // (dd1-dd3) )*2 else: return (dd1 // (dd1-dd3) )*2+1 else: if dd2 % (dd2-dd4) == 0: return (dd2 // (dd2-dd4) )*2 +1 else: return (dd2 // (dd2-dd4) )*2+2 print(main())
0
null
109,082,187,947,672
234
269
n, k = map(int, input().split()) p = list(map(lambda x: int(x) + 1, input().split())) s = 0 e = k t = sum(p[0:k]) ans = 0 while True: ans = max(ans, t) if e == n: break t -= p[s] t += p[e] s += 1 e += 1 print(ans / 2)
import sys import resource sys.setrecursionlimit(10000) n,k=map(int,input().rstrip().split()) p=list(map(int,input().rstrip().split())) c=list(map(int,input().rstrip().split())) def find(start,now,up,max,sum,count,flag): if start==now: flag+=1 if start==now and flag==2: return [max,sum,count] elif count==up: return [max,sum,count] else: count+=1 sum+=c[p[now-1]-1] if max<sum: max=sum return find(start,p[now-1],up,max,sum,count,flag) kara=[-10000000000] for i in range(1,n+1): m=find(i,i,n,c[p[i-1]-1],0,0,0) if m[2]>=k: m=find(i,i,k,c[p[i-1]-1],0,0,0) if m[0]>kara[0]: kara[0]=m[0] result=kara[0] elif m[1]<=0: if m[0]>kara[0]: kara[0]=m[0] result=kara[0] else: w=k%m[2] if w==0: w=m[2] spe=find(i,i,w,c[p[i-1]-1],0,0,0)[0] if m[1]+spe>m[0] and m[1]*(k-w)//m[2]+spe>kara[0]: kara[0]=m[1]*(k-w)//m[2]+spe elif m[1]+spe<=m[0] and m[1]*((k-w)//m[2]-1)+m[0]>kara[0]: kara[0]=m[1]*((k-w)//m[2]-1)+m[0] result=kara[0] print(result)
0
null
40,205,807,223,128
223
93
data = input().split(' ') print(int(data[0]) * int(data[1]))
A, B = input().split() total = int(A) * int(B) print(total)
1
15,924,574,430,060
null
133
133
from math import gcd class Factor: def __init__(self, max_element): self.minFactor = [-1]*(max_element+1) for i in range(2, max_element+1): if self.minFactor[i] == -1: for j in range(i, max_element+1, i): self.minFactor[j] = i def getFactorSet(self, element): retSet = set(1) while element > 1: retSet.add(element) retSet.add(self.minFactor[element]) element //= self.minFactor[element] return retSet def getPrimeFactorSet(self, element): retSet = set() while element > 1: retSet.add(self.minFactor[element]) element //= self.minFactor[element] return retSet def getPrimeFactorDic(self, element): retDic = {} while element > 1: val = self.minFactor[element] if val in retDic: retDic[val] += 1 else: retDic[val] = 1 element //= val return retDic def main(): n = int(input()) a = list(map(int, input().split())) f = True fact = Factor(max(a)) st = set() for v in a: fac_set = fact.getPrimeFactorSet(v) for u in fac_set: if u in st: f = False break st.add(u) if not f: break if f: print("pairwise coprime") else: all_gcd = a[0] for i in range(1, n): all_gcd = gcd(all_gcd, a[i]) if all_gcd == 1: print("setwise coprime") else: print("not coprime") if __name__ == "__main__": main()
import sys from collections import deque import numpy as np import math sys.setrecursionlimit(10**6) def S(): return sys.stdin.readline().rstrip() def SL(): return map(str,sys.stdin.readline().rstrip().split()) def I(): return int(sys.stdin.readline().rstrip()) def IL(): return map(int,sys.stdin.readline().rstrip().split()) def Main(): s = S() if len(s)<6: print('No') exit() if s[2]==s[3] and s[4]==s[5]: print('Yes') else: print('No') return if __name__=='__main__': Main()
0
null
22,986,258,463,530
85
184
from math import ceil a,b,c,d = map(int,input().split()) if ceil(c/b) <= ceil(a/d): print("Yes") else: print("No")
import re def find_a_word(w, t): list = [] for e in map(lambda x: re.split(r'\s|,|\.', x.lower()), t): list.extend(e) return list.count(w.lower()) if __name__ == '__main__': w = input() t = [] while True: i = input() if i == 'END_OF_TEXT': break else: t.append(i) print(find_a_word(w, t))
0
null
15,740,060,825,632
164
65
string = input() if string[2] == string[3] and string[4] == string[5]: print("Yes") else: print("No")
n = input() s1 = [] s2 = [] for i in range(len(n)): if n[i] == '\\': s1.append(i) elif n[i] == '/' and len(s1) > 0: a = s1.pop(-1) s2.append([a, i - a]) i = 0 while len(s2) > 1: if i == len(s2) - 1: break elif s2[i][0] > s2[i + 1][0]: s2[i + 1][1] += s2.pop(i)[1] i = 0 else: i += 1 s = [] total = 0 for i in s2: s.append(str(int(i[1]))) total += int(i[1]) print(total) if len(s2) == 0: print('0') else: print('{} {}'.format(len(s2), ' '.join(s)))
0
null
21,120,999,040,928
184
21
import math N = int(input()) def mass_search(x): divisor = 0 limit = math.floor(math.sqrt(x)) for i in range(1,limit+1): if N % i == 0: divisor = max(divisor, i) x = divisor y = N//divisor return x+y-2 print(mass_search(N))
def solve(): print([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][int(input())-1]) return 0 if __name__ == '__main__': solve()
0
null
106,261,088,392,992
288
195