code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
h1, m1, h2, m2, k = map(int,input().split()) h=h2 - h1 if h < 0: h = 24+h m=m2 - m1 du=h*60+m-k elif h == 0: if m1 < m2: du = m2-m1-k else: du = 24*60 +(m2-m1)-k else: du = h*60+(m2-m1)-k print(du)
from math import atan, degrees def main(): a, b, x = map(int, input().split()) # xが多い場合:水が三角形になる前に溢れるパターン if (a**2*b) / 2 < x: # 水じゃないところが三角形 を area area = a * b - x/a c = 2 * area / a # thetaが逆だから t = c / a ans = degrees(atan(t)) else: # 面積で考えるので水の量/奥行き area = x / a c = 2 * area / b t = b / c ans = degrees(atan(t)) print(ans) if __name__ == '__main__': main()
0
null
90,407,794,233,760
139
289
import sys def display(inp): s = len(inp) for i in range(s): if i!=len(inp)-1: print("%d" % inp[i], end=" ") else: print("%d" % inp[i], end="") print("") line = sys.stdin.readline() size = int(line) line = sys.stdin.readline() inp = [] for i in line.split(" "): inp.append(int(i)) display(inp) for i in range(1,size): if inp[i]!=size: check = inp.pop(i) for j in range(i): if check<inp[j]: inp.insert(j,check) break if j==i-1: inp.insert(j+1,check) break display(inp)
def main() : n = int(input()) lst = [int(i) for i in input().split()] print(" ".join(map(str, lst))); for i in range(1,n) : for j in reversed(range(i+1)) : if j == 0 : break elif lst[j] < lst[j-1]: lst[j], lst[j-1] = lst[j-1], lst[j] print(" ".join(map(str, lst))) if __name__ == '__main__' : main()
1
5,290,589,710
null
10
10
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines a, b, n = map(int, readline().split()) if n >= b: x = b - 1 else: x = n ans = (a * x) // b - a * (x // b) print(ans)
import math a, b, n = map(int, input().split()) if n < b: c = math.floor(a * n / b) print(c) else: c = math.floor(a * (b-1)/ b) print(c)
1
28,173,304,080,838
null
161
161
import itertools n, x, y = map(int, input().split()) k = [0] * n for v in itertools.combinations(list(range(1,n+1)), 2): k[min(abs(v[1]-v[0]),abs(x-min(v))+1+abs(y-max(v)))] += 1 for item in k[1:]: print(item)
def main(): n, x, y = map(int, input().split()) x -= 1 y-= 1 ans = [0]*n for i in range(n): for j in range(i+ 1, n): d = min(j-i, abs(j-y) + abs(x-i) + 1, abs(j-x) + abs(y-i) + 1) ans[d] += 1 for i in range(1, n): print(ans[i]) if __name__ == "__main__": main()
1
44,347,700,092,256
null
187
187
n = input() l = map(int,raw_input().split()) print min(l), max(l), sum(l)
import numpy as np import numpy.linalg as linalg X, Y = map(int, input().split()) if Y%2 == 1: print('No') else: A = np.array([[1, 1], [2, 4]]) A_inv = linalg.inv(A) B = np.array([X , Y]) C = np.dot(A_inv, B) if C[0] >= 0 and C[1] >= 0 : print('Yes') else: print('No')
0
null
7,285,315,349,312
48
127
from functools import reduce def gcd_base(x, y): if x % y: return gcd_base(y, x%y) return y def gcd(numbers): return reduce(gcd_base, numbers) def lcm_base(x, y): res = (x * y) // gcd_base(x, y) return res if res <= 1000000007 else 0 def lcm(numbers): return reduce(lcm_base, numbers, 1) n, m = map(int, input().split()) a = [int(i) for i in input().split()] k = [0] * n for i in range(n): j = a[i] while(j%2==0): j //= 2 k[i] += 1 if any([k[i]!=k[i+1] for i in range(n-1)]): print(0) else: l = [i//2 for i in a] x = lcm(l) if x==0: print(0) else: print((m//x+1)//2)
from copy import deepcopy n, m, q = map(int, input().split()) tuples = [tuple(map(int, input().split())) for i in range(q)] As = [[1]*n] def next(A, i): if i == 0 and A[i] == m: return if A[i] == m: next(A, i-1) elif A[i] < m: if (i < n - 1 and A[i] < A[i+1]) or (i == n-1): A1 = deepcopy(A) A1[i] += 1 As.append(A1) next(A1, i) if i > 0 and A[i] > A[i-1]: A2 = deepcopy(A) next(A2, i-1) elif i == 0: A1 = deepcopy(A) next(A1, n-1) next([1]*(n), n-1) def check(A): score = 0 for a, b, c, d in tuples: if A[b-1] - A[a-1] == c: score += d return score ans = 0 for A in As: score = check(A) ans = max(ans, score) print (ans)
0
null
64,920,072,520,500
247
160
S = input() length = len(S) leng = int(length/2) cnt = 0 for i in range(leng): if S[i] == S[length-(i+1)]: continue else: cnt += 1 print(cnt)
s = input() len_ = len(s) half = len(s) // 2 ans = 0 if len_ % 2 == 0: front = s[:half] back = s[half:][-1::-1] for i in range(len(front)): if front[i] != back[i]: ans += 1 else: front = s[:half] back = s[half+1:][-1::-1] for i in range(len(front)): if front[i] != back[i]: ans += 1 print(ans)
1
120,159,476,964,160
null
261
261
n = input() k = int(input()) dp = [[[0] * (k+1) for _ in range(2)] for _ in range(len(n)+1)] dp[0][0][0] = 1 for i in range(1, len(n) + 1): t = int(n[i-1]) for j in range(k+1): if t != 0: if j != 0: dp[i][0][j] += dp[i-1][0][j-1] dp[i][1][j] += dp[i-1][1][j-1] * 9 + dp[i-1][0][j-1] * (t-1) dp[i][1][j] += (dp[i-1][1][j] + dp[i-1][0][j]) else: dp[i][0][j] += dp[i-1][0][j] if j != 0: dp[i][1][j] += dp[i-1][1][j-1] * 9 dp[i][1][j] += dp[i-1][1][j] print(dp[len(n)][0][k] + dp[len(n)][1][k])
def calc(a,D,K): if K==1: return a+(D-1)*9 elif K==2: return (a-1)*(D-1)*9 + (D-1)*(D-2)//2*81 else: return (a-1)*(D-1)*(D-2)//2*81 + (D-1)*(D-2)*(D-3)//6*729 N=input() K=int(input()) D = len(N) score=0 for i,a in enumerate(N): if a!="0": score+=calc(int(a),D-i,K) K-=1 if K==0: break print(score)
1
75,852,570,393,280
null
224
224
s = input() if len(list(set(s))) == 1: print('No') else: print('Yes')
print('Yes' if 'AAA'<input()<'BBB' else 'No')
1
54,702,431,560,148
null
201
201
N = int(input()) ans = 0 for i in range(1,N+1): #1-N first = i; kosu = N//i end = kosu*i temp = (first+end)*kosu//2 ans += temp print(ans)
m,d=map(int,input().split()) if m in [1,3,5,7,8,10,12] and d==31: print(1) elif m ==2 and d==28: print(1) elif m in [4,6,9,11] and d==30: print(1) else: print(0)
0
null
68,037,777,346,320
118
264
import sys stdin = sys.stdin inf = 1 << 60 mod = 1000000007 ni = lambda: int(ns()) nin = lambda y: [ni() for _ in range(y)] na = lambda: list(map(int, stdin.readline().split())) nan = lambda y: [na() for _ in range(y)] nf = lambda: float(ns()) nfn = lambda y: [nf() for _ in range(y)] nfa = lambda: list(map(float, stdin.readline().split())) nfan = lambda y: [nfa() for _ in range(y)] ns = lambda: stdin.readline().rstrip() nsn = lambda y: [ns() for _ in range(y)] ncl = lambda y: [list(ns()) for _ in range(y)] nas = lambda: stdin.readline().split() h, w, k = na() s = nsn(h) ans = inf for bits in range(2 ** (h - 1)): binf = "{0:b}".format(bits) res = sum([int(b) for b in binf]) divcnt = res + 1 cnt = [0] * divcnt flag = True j = 0 while j < w: cur = 0 for i in range(h): if (s[i][j] == '1'): cnt[cur] += 1 if bits >> i & 1: cur += 1 if max(cnt) > k: if flag: res = inf break res += 1 for i in range(divcnt): cnt[i] = 0 flag = True else: flag = False j += 1 ans = min(ans, res) print(ans)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): def divide_choco(bit): divrow_num = bin(bit).count("1") + 1 # 割った回数+1 choco_current = [[0] * w for _ in range(divrow_num)] row_divided_cur = 0 for col, piece in enumerate(choco[0]): choco_current[0][col] = piece for row in range(h - 1): if bit >> row & 1: row_divided_cur += 1 for col, piece in enumerate(choco[row + 1]): choco_current[row_divided_cur][col] += piece return choco_current, divrow_num h, w, k = list(map(int, readline().split())) choco = [] for i in range(h): choco_in = input() choco_add = [int(c) for c in choco_in] choco.append(choco_add) ans = INF for bit in range(1 << (h - 1)): choco_current, divrow_num = divide_choco(bit) choco_cursum = [0] * divrow_num is_exceed = False # 超えてる場合True ans_temp = bin(bit).count("1") if divrow_num > 1: for col in range(w): choco_currow = [choco_current[dr][col] for dr in range(divrow_num)] for drow, pieces in enumerate(choco_currow): if pieces > k: ans_temp += INF elif choco_cursum[drow] + pieces > k: is_exceed = True if is_exceed: choco_cursum = [cc for cc in choco_currow] ans_temp += 1 is_exceed = False else: choco_cursum = [cc + cs for cc, cs in zip(choco_currow, choco_cursum)] else: choco_cursum = 0 for pieces in choco_current[0]: if pieces > k: ans_temp += INF elif choco_cursum + pieces > k: choco_cursum = pieces ans_temp += 1 else: choco_cursum = choco_cursum + pieces ans = min(ans, ans_temp) print(ans) if __name__ == '__main__': main()
1
48,604,364,475,710
null
193
193
import math n,m=map(int,input().split()) print(math.ceil(n/m))
import sys input = sys.stdin.readline n, p = map(int, input().split()) s = list(input().strip()) if p == 2 or p == 5: ans = 0 while s: if p == 2 and int(s.pop()) % 2 == 0 or p == 5 and int(s.pop()) % 5 == 0: ans += n n -= 1 print(ans) exit() a = [0] * p i = 1 k = 0 while s: k = (k + int(s.pop()) * i) % p a[k] += 1 i *= 10 i %= p ans = a[0] for i in a: if i >= 2: ans += i * (i - 1) // 2 print(ans)
0
null
67,686,032,278,790
225
205
X,K,D = map(int,input().split()) dist = abs(X) rem = K count = min(dist//D,K) dist -= count*D rem -= count if rem % 2 == 1: dist -= D print(abs(dist))
x, k, d = [int(i) for i in input().split()] if x < 0: x = -x l = min(k, x // d) k -= l x -= l * d if k % 2 == 0: print(x) else: print(d - x)
1
5,274,452,777,968
null
92
92
while True: (H, W) = [int(i) for i in input().split()] if H == W == 0: break print ("\n".join(["".join(["#" if i == 0 or i == W - 1 or j == 0 or j == H - 1 else "." for i in range(W)]) for j in range(H)])) print()
N = int(input()) K = int(input()) def func(num,counter): remain = num%10 quotient = num//10 if counter == 0: return 1 if num<10: if counter ==1: return num else: return 0 return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter) print(func(N,K))
0
null
38,377,624,298,220
50
224
n, k = map(int, input().split()) a = list(map(int, input().split())) def f(m): res = sum([-(-x//m)-1 for x in a]) return res <= k l, r = 0, 10**9+10 while r-l > 1: x = (l+r)//2 if f(x): r = x else: l = x print(r)
def solve(): N, K = map(int,input().split()) A = list(map(int,input().split())) left = 0 right = 10 ** 9 while right - left > 1: mid = (right+left) // 2 cnt = 0 for a in A: cnt += (a-1) // mid if cnt <= K: right = mid else: left = mid print(right) if __name__ == '__main__': solve()
1
6,557,462,526,144
null
99
99
input() print(' '.join(input().split()[::-1]))
N, M = map(int, input().split()) A = list(set(map(lambda x : int(x)//2, input().split()))) def _gcd(a, b): return a if b == 0 else _gcd(b, a%b) def _lcm(a,b): return (a*b) // _gcd(a,b) lcm = A[0] for ai in A[1:]: lcm = _lcm(lcm, ai) ret = (M//lcm + 1)//2 for ai in A[1:]: if (lcm // ai) % 2 == 0: ret = 0 break print(ret)
0
null
51,498,753,187,992
53
247
#!/usr/bin/env python3 s = input() n = len(s)+1 a = [0 for _ in range(n)] for i in range(n-1): if s[i] == '<': a[i+1] = max(a[i+1], a[i]+1) for i in reversed(range(1, n)): if s[i-1] == '>': a[i-1] = max(a[i-1], a[i]+1) ans = sum(a) #print('a = ', a) print(ans)
s = input() n = len(s) a = [0]*(n+1) yama = [] tani = [] for i in range(n): if s[i] == '<': a[i+1] = a[i] + 1 for i in range(n)[::-1]: if s[i] == '>': a1 = a[i+1] + 1 if i != 0: if s[i-1] == '<': a[i] = max(a[i], a1) else: a[i] = a1 else: a[i] = a1 ans = sum(a) print(ans)
1
157,146,477,281,820
null
285
285
n,m,k=map(int,input().split()) mod=998244353 ans=m*pow(m-1,n-1,mod) ans%=mod if k==0: print(ans) exit() lst=[1]+[1] for i in range(2,n+10): lst.append((lst[-1]*i)%mod) def combinations(n,r): xxx=lst[n] xxx*=pow(lst[n-r],mod-2,mod) xxx%=mod xxx*=pow(lst[r],mod-2,mod) xxx%=mod return xxx for i in range(1,k+1): ans+=(m*pow(m-1,n-1-i,mod)*combinations(n-1,i))%mod ans%=mod print(ans)
N = int(input()) l = list(map(int, input().split())) counter = 1 ans = 0 for j in l: if j == counter: counter += 1 else: ans += 1 if counter==1: print(-1) else: print(ans)
0
null
68,588,951,620,222
151
257
import sys def input(): return sys.stdin.readline().rstrip() from itertools import accumulate def main(): n=int(input()) A=[int(_) for _ in input().split()] A=list(accumulate(A)) min_A=100000000000 for a in A: min_A=min(min_A,abs(A[-1]/2-a)) print(int(min_A*2)) if __name__=='__main__': main()
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * N = INT() A = LIST() ans = INF A_sum = sum(A) tmp = 0 for x in A: tmp += x ans = min(ans, abs(tmp-(A_sum-tmp))) print(ans)
1
141,787,642,184,650
null
276
276
c=0 for i in range(int(input())): d1,d2=map(int,input().split()) if d1==d2: c+=1 if c==3: break else: c=0 print('Yes' if c==3 else 'No')
n=int(input()) cnt=0 ans=0 for i in range(n): d1,d2=map(int,input().split()) if d1==d2: cnt=cnt+1 ans=max(ans,cnt) else: cnt=0 if ans>=3: print("Yes") else: print("No")
1
2,489,833,357,960
null
72
72
X = int(input()) q = X // 100 if X%100<=q*5: print('1') else: print('0')
X = int(input()) N = X // 100 for n in range(N + 1): M = X - n * 100 if M > n * 5: continue else: print(1) break else: print(0)
1
126,994,739,512,540
null
266
266
from collections import deque import sys input = sys.stdin.readline N = int(input()) G = [[] for _ in range(N)] for _ in range(N): ls = list(map(int, input().split())) u = ls[0] - 1 for v in ls[2:]: G[u].append(v - 1) time = 1 d = [None for _ in range(N)] f = [None for _ in range(N)] def dfs(v): global time d[v] = time time += 1 for u in range(N): if u in G[v]: if d[u] is None: dfs(u) f[v] = time time += 1 for v in range(N): if d[v] is None: dfs(v) for v in range(N): print("{} {} {}".format(v + 1, d[v], f[v]))
n = int(raw_input()) def dfs(u,t): global graph global found global timestamp if u in found: return t found.add(u) timestamp[u] = [-1,-1] timestamp[u][0] = t t += 1 for v in graph[u]: t = dfs(v,t) timestamp[u][1] = t t += 1 return t graph = [[] for i in range(n)] found = set() timestamp = {} for i in range(n): entry = map(int,raw_input().strip().split(' ')) u = entry[0] u -= 1 for v in entry[2:]: v -= 1 graph[u].append(v) t = 1 for i in range(n): t = dfs(i,t) for i in timestamp: print i+1,timestamp[i][0],timestamp[i][1]
1
2,822,214,376
null
8
8
count = 0 def solve(i, a, ans): global count if ans[i][0] == 0: count += 1 ans[i][0] = count for x in range(a[i][1]): if ans[a[i][2 + x] - 1][0] == 0: solve(a[i][2 + x] - 1, a, ans) if ans[i][1] == 0: count += 1 ans[i][1] = count N = int(input()) a = [] for _ in range(N): a.append([int(x) for x in input().split()]) ans = [[0 for i in range(2)] for j in range(N)] for i in range(N): if ans[i][0] == 0: solve(i, a, ans) for i, x in enumerate(ans): print(i + 1, *x)
from sys import stdin global time time = 0 def dfs(graph,start,state,discover,finish): state[start-1] = 1 global time time = time + 1 discover[start-1] = time # print str(time) + " go to " + str(start) neighbours = sorted(graph[start]) for neighbour in neighbours: if state[neighbour-1] == 0: dfs(graph,neighbour,state,discover,finish) state[start-1] = 2 time = time + 1 finish[start - 1] = time # print str(time) + " out of " + str(start) def main(): # g = {1: [2, 3], # 2: [3, 4], # 3: [5], # 4: [6], # 5: [6], # 6: []} # deal with input n = int(stdin.readline()) g = {} d = [0]*n f = [0]*n all_vertex = [] for i in xrange(n): entry = [int(s) for s in stdin.readline().split()[2:]] g[i+1] = entry all_vertex.append(i+1) # exp = [] # state represent vertex visited state: 0 not visited 1 visiting 2 finished state = [0]*n for node in all_vertex: if state[node-1] == 0: dfs(g,node,state,d,f) # print 'state ' + str(state) # print 'd' + str(d) # print 'f' + str(f) # deal with output for i in xrange(n): print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) main()
1
3,391,751,430
null
8
8
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 sys txt = sys.stdin.read().lower() for i in "abcdefghijklmnopqrstuvwxyz": print(i,":",txt.count(i))
0
null
879,058,817,472
27
63
n,k = map(int,input().split()) print((n%k) if (n%k) < (k-(n%k)) else (k-(n%k)))
l=input("").split(" ") n=int(l[0]) k=int(l[1]) s=n%k ss=k-s if(s<ss): print(s) else: print(ss)
1
39,235,147,331,520
null
180
180
n = int(input()) for i in range(1, 180, 1): if(360*i % n == 0): print(int(360*i//n)) exit(0)
X = int(input()) # Xの素因数分解をうまくつかう # A^5 - B^5 =(A-B)(A^4+A^3B+A^2B^2+AB^3+B^4) # どっちが正負かは決まらない # AB(A^2+B^2)+(A^2+B^2)^2-A^2B^2 # AB((A-B)^2+2AB)+((A-B)^2+2AB)^2 - A^2B^2 # A-B = P # AB = Q # A^5-B^5 = P(Q(P^2+2Q)+(P^2+2Q)^2-Q^2) = P(P^4+5P^2Q+5Q^2) = P(5Q^2+5P^2Q+P^4) # Qは整数解なので # 5Q^2+5P^2Q+P^4が整数解を持つ楽な方法は(Q+P)^2の形の時、つまり2P = P^2+2, # X = PRとする # R-P^4は5の倍数になる #Aの上限を求める # X<10^9 # A-B = 1がAを最大にできる maxA = 126 maxX = pow(10, 9) flag = 0 for A in range(-126, 126): for B in range(-127, A): result = pow(A, 5) - pow(B, 5) if result > maxX: next if result == X: print(A, B) flag = 1 break if flag == 1: break
0
null
19,370,910,858,692
125
156
import sys n = int(sys.stdin.readline()) for _ in range(n): a, b, c = sorted(list(map(int, sys.stdin.readline().split()))) print('YES' if a * a + b * b == c * c else 'NO')
n=int(input()) for _ in range(n): a=sorted([int(i) for i in input().split()]) print("YES" if a[0]**2+a[1]**2==a[2]**2 else "NO")
1
246,213,990
null
4
4
N=int(input()) A=["a"] if N==1: print("a") exit() else: S="abcdefghijklmn" slist=list(S) for i in range(2,N+1): temp=[[] for _ in range(N)] for j in range(i-1): for w in A[j]: for u in slist[:j+1]: temp[j].append(w+u) temp[j+1].append(w+slist[j+1]) A=temp B=[] for j in range(N): for t in A[j]: B.append(t) B.sort() for i in range(len(B)): print(B[i])
inputStr = input() numList = inputStr.split(' ') numList = [int(x) for x in numList] #print('a: ',numList[0]) #print('b: ',numList[1]) if numList[0]==numList[1]: print('a == b') elif numList[0]>numList[1]: print('a > b') elif numList[0]<numList[1]: print('a < b')
0
null
26,418,543,462,520
198
38
def isPrime(n): if (n == 1): return False if (n == 2): return True if (0 == n % 2) : return False i = 2 while(n >= i * i): if (0 == n % i): return False i += 1 return True def main(): c = 0 n = input() for i in range(n): if (isPrime(input())): c += 1 print(c) main()
from collections import deque x = input() A = 0 S1 = deque() S2 = deque() for i in range(len(x)): if x[i] == "\\": S1.append(i) elif x[i] == "/" and len(S1) > 0 : j = S1.pop() A += i - j a = i - j while len(S2) > 0 and S2[-1][0] > j: a += S2[-1][1] S2.pop() S2.append([j,a]) print(A) if len(S2)== 0: print(0) else: print(len(S2),"",end="") for i in range(len(S2)): if i == len(S2) - 1: print(S2[i][1]) else: print(S2[i][1],"",end="")
0
null
34,845,519,202
12
21
import sys def main(): input = sys.stdin.buffer.readline h, w = map(int, input().split()) print((h * w + 1) // 2 if min(h, w) > 1 else 1) if __name__ == "__main__": main()
H, W = map(int, input().split()) if (H == 1) or (W == 1): print(1) exit() if H%2 == 1: if W%2 == 1: print(H*W//2 + 1) exit() # else: # print(H*W//2) # else: # if W%2 == 1: # print(H*W//2) # else: # print(H*W//2) print(H*W//2)
1
50,757,612,545,180
null
196
196
from itertools import combinations_with_replacement n, m, q = map(int, input().split()) a = [0] * q b = [0] * q c = [0] * q d = [0] * q for i in range(q): a[i], b[i], c[i], d[i] = map(int, input().split()) ans = 0 for v in combinations_with_replacement(list(range(1, m + 1)), n): sm = 0 for i in range(q): if v[b[i] - 1] - v[a[i] - 1] == c[i]: sm += d[i] ans = max(ans, sm) print(ans)
def mi(): return map(int,input().split()) def lmi(): return list(map(int,input().split())) def ii(): return int(input()) def isp(): return input().split() from itertools import combinations_with_replacement n,m,q=mi() ll=[i for i in range(1,m+1)] input_list=[] for i in range(q): abcd=lmi() input_list.append(abcd) ans=0 la=list(combinations_with_replacement(ll,n)) for i in la: suma=0 #print(i) for j in input_list: a=j[0] b=j[1] c=j[2] d=j[3] if (i[b-1]-i[a-1])==c: suma+=d #print(suma) ans=max(ans,suma) print(ans)
1
27,627,352,154,820
null
160
160
import numpy as np n, *a = map(int, open(0).read().split()) s = np.cumsum(np.array(a)) print(min([abs(s[n - 1] - s[i] - s[i]) for i in range(n - 1)]))
N = int(input()) A = list(map(int, input().split())) sumlow = 0 sumhigh = 0 i = 0 j = N-1 while i<=j: if sumlow <= sumhigh: sumlow += A[i] i += 1 else: sumhigh += A[j] j -= 1 print(abs(sumlow-sumhigh))
1
142,379,196,283,620
null
276
276
W = input() ans = 0 count = 0 for i in range(len(W)): if W[i] == "R": count += 1 ans = max(ans,count) else: count = 0 print(ans)
mod=10**9+7 import math import sys from collections import deque import heapq import copy import itertools from itertools import permutations from itertools import combinations import bisect def mi() : return map(int,sys.stdin.readline().split()) def ii() : return int(sys.stdin.readline().rstrip()) def i() : return sys.stdin.readline().rstrip() a,b=mi() if (a+b)%3!=0: print(0) sys.exit() s=(a+b)//3 a-=s b-=s if a<0 or b<0: print(0) sys.exit() fac=[1]*700000 for i in range(1,700000): fac[i]=(fac[i-1]*i)%mod m=a+b n=min(a,b) c=1 for j in range(m,m-n,-1): c*=j c=c%mod print((c*pow(fac[n],mod-2,mod))%mod)
0
null
77,460,529,535,698
90
281
def main(): INF = 10 ** 18 N = int(input()) A = list(map(int, input().split(' '))) K = 1 + N % 2 # 余分な×を入れられる個数 # dp[i][j]: i個目までの要素で余分な×をj個使った際の最大値 dp = [[- INF for _ in range(K + 1)] for _ in range(N + 1)] dp[0][0] = 0 for i in range(N): for j in range(K + 1): if j < K: # 余分な×を使う場合 dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]) # 余分な×を使わない場合 now = dp[i][j] if (i + j) % 2 == 0: # 基本はi % 2 == 0の時にA[i]を足していく # ただ、余分な×がj個入っていると、その分ずれる now += A[i] dp[i + 1][j] = max(dp[i + 1][j], now) print(dp[N][K]) if __name__ == '__main__': main()
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) Ls = list(mapint()) Ls.sort() from bisect import bisect_left ans = 0 for i in range(N-2): for j in range(i+1, N-1): idx = bisect_left(Ls, Ls[i]+Ls[j]) ans += idx-1-j print(ans)
0
null
105,124,516,541,778
177
294
S = input() bb = 'x'*len(S) print(bb)
S = input() arr = ["x" for i in range(len(S))] print("".join(arr))
1
72,753,195,688,076
null
221
221
N=int(input()) A=list(map(int,input().split())) A1=set(A) ans="NO" if len(A)==len(A1): ans="YES" print(ans)
N,*A = map(int, open(0).read().split()) if len(set(A)) == len(A): print('YES') else: print('NO')
1
73,878,979,169,392
null
222
222
import math k=int(input()) result=0 for i in range(1,k+1): for j in range(1,k+1): first=math.gcd(i,j) for g in range(1,k+1): result=result+math.gcd(first,g) print(result)
import array K = int(input()) s = 0 cache = [1] * K def gcd(a, b): while b != 0: a, b = b, a % b return a for i in range(1, K+1): cache[i-1] = [1] * K for j in range(i, K+1): cache[i-1][j-1] = array.array('i', [1] * K) for k in range(j, K+1): cache[i-1][j-1][k-1] = gcd(k, gcd(j, i)) for i in range(1, K+1): for j in range(1, K+1): for k in range(1, K+1): a, b, c = sorted([i, j, k]) s += cache[a-1][b-1][c-1] print(s)
1
35,277,888,526,620
null
174
174
input = raw_input() 3 input = int(input) ans = input**3 print ans
print((lambda x : x**3)(int(input())))
1
282,601,438,790
null
35
35
X,Y = map(int,input().split()) for i in range(X+1): a = i*2 + (X-i)*4 if a == Y: print("Yes") break if a != Y: print("No")
x,y=map(int,input().split()) flag=0 for i in range(x+1): if i*2+(x-i)*4==y: print("Yes") flag=1 break if flag==0: print("No")
1
13,792,969,049,758
null
127
127
s=input()*3 if s.find(input()) == -1 : print('No') else: print('Yes')
s = input() ord_s = ord(s) + 1 chr_s = chr(ord_s) print(chr_s)
0
null
46,723,234,684,740
64
239
import math N = int(input()) Alist = list(map(int,input().split())) box = [0]*(10**6+1) sign = math.gcd(Alist[0],Alist[1]) Amax = max(Alist[0],Alist[1]) for i in range(0,len(Alist)): A = Alist[i] sign = math.gcd(sign, A) Amax = max(Amax, A) box[A] += 1 setwise = (sign == 1) pairwise = (sign == 1) Amax = math.sqrt(Amax)+1 for i in range(2,10**6+1): if sum(box[i::i]) >1: pairwise = False break if setwise: if pairwise: print('pairwise coprime') else: print('setwise coprime') else: print('not coprime')
n = int(input()) A = list(map(int,input().split())) def factorize(n): fct = [] # prime factor b, e = 2, 0 # base, exponent while b * b <= n: while n % b == 0: n = n // b e = e + 1 if e > 0: fct.append((b, e)) b, e = b + 1, 0 if n > 1: fct.append((n, 1)) return fct def gcd(a, b): while b: a, b = b, a % b return a pc = True fac = [0]*(10**6+1) for a in A: lst = factorize(a) for p in lst: if not fac[p[0]]: fac[p[0]] = 1 else: pc = False break if not pc: break if pc: print('pairwise coprime') else: g = A[0] for i in range(1,n): g = gcd(g, A[i]) if g == 1: print('setwise coprime') else: print('not coprime')
1
4,137,070,559,036
null
85
85
N = int(input()) A = sorted([int(i) for i in input().split()], reverse=True) print(sum([A[(i+1)//2] for i in range(N-1)]))
## coding: UTF-8 #import random import math N = int(input()) A = list(map(int,input().split())) #N = 9 #A = [1, 2, 3, 40, 50, 60, 100, 200, 300] A = sorted(A, reverse = True) #print(N, A) score = 0 for i in range(1, N): index = math.floor(i/2) score += A[index] #print(i, index, A[index], score) print(score)
1
9,148,627,988,800
null
111
111
a,b,c = map(int,(input().split())) d = (a//(b+c))*b + min((a%(b+c)),b) print(d)
N,A,B=map(int,input().split()) if A==0: print("0") elif B==0: print(N) elif N%(A+B)>A: print(A*int(N/(A+B))+A) else: print(A*int(N/(A+B))+N%(A+B))
1
55,898,457,813,070
null
202
202
import sys from io import StringIO import unittest import os import heapq # 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む) sys.setrecursionlimit(999999999) # 検索用タグ、優先度付きキュー、値の大きい物から取得 # 実装を行う関数 def resolve(test_def_name=""): n = int(input()) a_s = list(map(int, input().split())) a_s.sort(reverse=True) # 優先度付きキューの作成 que = [] heapq.heapify(que) ans = 0 # 大きい値から順番に処理していく for cnt, a in enumerate(a_s): # 大きい値から順番に処理していくため、値を反転(優先度付きキュー利用時の注意) a = -a if cnt == 0: # ループ一回目の時だけ、こっちを通過。 heapq.heappush(que, a) continue # キューから値の取り出し target = heapq.heappop(que) ans += -target # 現在の値を追加できるパターンが2つできるので、それをキューに追加 heapq.heappush(que, a) heapq.heappush(que, a) print(ans) # テストクラス class TestClass(unittest.TestCase): def assertIO(self, assert_input, output): stdout, sat_in = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(assert_input) resolve(sys._getframe().f_back.f_code.co_name) sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, sat_in self.assertEqual(out, output) def test_input_1(self): test_input = """4 2 2 1 3""" output = """7""" self.assertIO(test_input, output) def test_input_2(self): test_input = """7 1 1 1 1 1 1 1""" output = """6""" self.assertIO(test_input, output) # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること def test_1original_1(self): test_input = """4 2 2 3 3""" output = """9""" self.assertIO(test_input, output) # 実装orテストの呼び出し if __name__ == "__main__": if os.environ.get("USERNAME") is None: # AtCoder提出時の場合 resolve() else: # 自PCの場合 unittest.main()
import heapq def solve(): N = int(input()) A = list(sorted(map(int, input().split()), reverse=True)) C = [-A[0]] ans = 0 for a in A[1:]: K = heapq.heappop(C) ans += -K heapq.heappush(C, -a) heapq.heappush(C, -a) print(ans) solve()
1
9,180,945,851,950
null
111
111
N = int(input()) D = list(map(int, input().split())) DL = [0] * N mod = 998244353 if D[0] != 0: print(0) exit() for d in D: DL[d] += 1 if DL[0] != 1: print(0) exit() ans = 1 for i in range(1, N): if DL[i] == 0: if sum(DL[i:]) != 0: print(0) exit() else: print(ans%mod) exit() ans *= pow(DL[i-1], DL[i], mod) ans %= mod print(ans % mod)
def main(): s = input() s_ = set(s) if len(s_) >= 2: print('Yes') else: print('No') if __name__ == "__main__": main()
0
null
104,696,794,654,500
284
201
N = int(input()) C = input().split() B = C[:] S = C[:] # bubble sort flag = 1 while(flag): flag = 0 for x in range(1, N): if B[x][1:] < B[x-1][1:]: B[x], B[x-1] = B[x-1], B[x] flag = 1 # sectionSot for x in range(0,N): minj = x for j in range(x,N): if S[j][1:] < S[minj][1:]: minj = j if minj != x: S[x], S[minj] = S[minj], S[x] print(" ".join(b for b in B)) print("Stable") if(B == S): print(" ".join(b for b in S)) print("Stable") else: print(" ".join(b for b in S)) print("Not stable")
N,K = list(map(int, input().split())) A = [int(i) for i in input().split()] for i in range(K,N): if A[i] > A[i-K]: print("Yes") else: print("No")
0
null
3,543,850,729,088
16
102
X,Y = map(int,input().split()) MMM = map (int,input().split()) MM = list(MMM) MM.sort() total = 0 for i in range(Y): total += MM[i] print(total)
import operator from functools import reduce N, K = map(int, input().split()) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 positives = [a for a in A if a > 0] negatives = [a for a in A if a < 0] positive_cnt = len(positives) negative_cnt = len(negatives) zero_cnt = A.count(0) if 2 * min(K // 2, negative_cnt // 2) + positive_cnt >= K: ans = 1 positives.sort(key=lambda x: abs(x), reverse=True) negatives.sort(key=lambda x: abs(x), reverse=True) if K % 2 == 1: ans *= positives.pop(0) K -= 1 X = [] for pair in zip(*[iter(positives)] * 2): X.append(reduce(operator.mul, pair, 1)) for pair in zip(*[iter(negatives)] * 2): X.append(reduce(operator.mul, pair, 1)) X.sort(reverse=True) ans *= reduce(lambda a, b: a * b % MOD, X[:K // 2], 1) print(ans % MOD) elif zero_cnt: print(0) else: A.sort(key=lambda x: abs(x)) print(reduce(lambda a, b: a * b % MOD, A[:K], 1) % MOD)
0
null
10,542,545,954,820
120
112
# -*- coding: utf-8 -*- n, m, l = list(map(int, input().split())) a = [] b = [] for i in range(n): a.append(list(map(int, input().split()))) for i in range(m): b.append(list(map(int, input().split()))) for i in range(n): for j in range(l): mat_sum = 0 for k in range(m): mat_sum += a[i][k] * b[k][j] if j == l - 1: print('{0}'.format(mat_sum), end='') else: print('{0} '.format(mat_sum), end='') print()
n, m, l = map(int, input().split()) a = [input().split()for _ in range(n)] b = [input().split()for _ in range(m)] c = [[0]*l for _ in range(n)] for i in range(n): for j in range(l): for k in range(m): c[i][j] += int(a[i][k])*int(b[k][j]) for i in range(n): print(*c[i])
1
1,451,968,516,300
null
60
60
n, k = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) def solve(start): loop = [] llen = 0 lsum = 0 reach = [0]*n now = start while True: nxt = P[now]-1 loop.append(now) llen += 1 lsum += C[now] reach[now] = 1 if reach[nxt]: break now = nxt if lsum <= 0 or llen >= k: res = -10 ** 20 s = 0 now = start for i in range(min(llen, k)): s += C[now] res = max(res, s) now = P[now]-1 return res else: s = lsum * (k // llen) now = start for i in range(k % llen): s += C[now] now = P[now]-1 j = loop.index(now) res = -10**20 for i in range(llen): j -= 1 res = max(res, s) s -= C[loop[j]] return res def solver(): ans = -10 ** 20 for i in range(n): ans = max(ans, solve(i)) return ans print(solver())
#!/usr/bin/env python3 from pprint import pprint from collections import deque, defaultdict import itertools import math import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.buffer.readline INF = float('inf') n_nodes = int(input()) graph = [[] for _ in range(n_nodes)] for _ in range(n_nodes): line = list(map(int, input().split())) u, k = line[0], line[1] if k > 0: for v in line[2:]: graph[u - 1].append(v - 1) # pprint(graph) def dfs(v): global time time += 1 for v_adj in graph[v]: if d[v_adj] == -1: d[v_adj] = time dfs(v_adj) f[v] = time time += 1 d = [-1] * n_nodes f = [-1] * n_nodes time = 1 for v in range(n_nodes): if d[v] == -1: d[v] = time dfs(v) # pprint(d) # pprint(f) for v in range(n_nodes): print(f"{v + 1} {d[v]} {f[v]}")
0
null
2,682,279,672,270
93
8
def similar_coffee(): # 入力 S = input() # 判別処理 if S[2] == S[3] and S[4] == S[5]: return 'Yes' else: return 'No' result = similar_coffee() print(result)
def main(): S = input() if S[2] == S[3] and S[4] == S[5]: print("Yes") else: print("No") if __name__ == '__main__': main()
1
41,770,991,563,262
null
184
184
s,t=raw_input().split() print t+s
S, T = input().split(' ') print(T + S)
1
103,506,669,772,320
null
248
248
''' ITP-1_8-A ??§????????¨?°????????????\????????? ????????????????????????????°?????????¨??§???????????\????????????????????°???????????????????????????????????? ???Input ????????????1??????????????????????????? ???Output ????????????????????????????°?????????¨??§???????????\???????????????????????????????????????????????? ??¢????????????????????\??????????????????????????????????????????????????? ''' # inputData inputData = input() for i in range(len(inputData)): if "a"<=inputData[i]<="z": # ??§???????????? print(inputData[i].upper(),end='') elif "A"<=inputData[i]<="Z": # ?°????????????? print(inputData[i].lower(),end='') else: # ??¢????????????????????\????????????????????? print(inputData[i],end='') # ???????????? print('')
import sys import re import math import collections import decimal import bisect # import copy # import heapq # from collections import deque # import decimal # sys.setrecursionlimit(100001) INF = sys.maxsize # MOD = 10 ** 9 + 7 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(): a, b, c = ns() tmp = decimal.Decimal(a).sqrt() + decimal.Decimal(b).sqrt() - decimal.Decimal(c).sqrt() print("Yes" if tmp < 0 else "No") if __name__ == '__main__': main()
0
null
26,701,142,101,910
61
197
l ='abcdefghijklmnopqrstuvwxyz' c = input() x = l.index(c) print(l[x + 1])
s = input() print(chr(ord(s)+1))
1
92,552,061,058,048
null
239
239
x=list(input().split()) print(x[1]+x[0])
#!/usr/bin/env python3 def main(): h,w,k = map(int, input().split()) s = [input() for i in range(h)] l = [[0]*w for i in range(h)] from collections import deque d = deque() c = 1 for i in range(h): for j in range(w): if s[i][j] == '#': d.append([i, j]) l[i][j] = c c += 1 while len(d) > 0: x,y = d.pop() c = l[x][y] l[x][y] = c f1 = True f2 = True for i in range(1,w): if y+i < w and l[x][y+i] == 0 and s[x][y+i] != '#' and f1: l[x][y+i] = c else: f1 = False if 0 <= y-i and l[x][y-i] == 0 and s[x][y-i] != '#' and f2: l[x][y-i] = c else: f2 = False for i in range(h): if all(l[i]) == 0: k1 = 1 while 0 < i+k1 < h and all(l[i+k1]) == 0: k1 += 1 # print("test: ", i, k1) if i+k1 < h: for j in range(i, i+k1): for r in range(w): l[j][r] = l[i+k1][r] for i in range(h-1, -1, -1): if all(l[i]) == 0: k1 = 1 while 0 < i-k1 < h and all(l[i-k1]) == 0: k1 += 1 # print("test: ", i, k1) if 0 <= i-k1 < h: for j in range(i, i-k1, -1): for r in range(w): l[j][r] = l[i-k1][r] for i in range(h): print(' '.join(map(str, l[i]))) if __name__ == '__main__': main()
0
null
123,618,655,459,520
248
277
n, m = (int(i) for i in input().split()) h = [int(i) for i in input().split()] g = [[] for i in range(n)] for i in range(m): a, b = (int(i) for i in input().split()) a -= 1 b -= 1 g[a].append(b) g[b].append(a) cnt = 0 for i in range(n): mx = -1 for j in g[i]: mx = max(mx, h[j]) cnt += h[i] > mx print(cnt)
def bubble_sort(C, N): card = [] for c in C: card.append({'suit': c[0], 'value': int(c[1])}) for i in range(N): for j in range(N-1, i, -1): if card[j]['value'] < card[j-1]['value']: card[j], card[j-1] = card[j-1], card[j] new_C = [] for i in range(N): new_C.append(card[i]['suit'] + str(card[i]['value'])) return new_C def selection_sort(C, N): card = [] for c in C: card.append({'suit': c[0], 'value': int(c[1])}) for i in range(N): min_j = i for j in range(i, N): if card[j]['value'] < card[min_j]['value']: min_j = j card[i], card[min_j] = card[min_j], card[i] new_C = [] for i in range(N): new_C.append(card[i]['suit'] + str(card[i]['value'])) return new_C N = int(input().rstrip()) C = input().rstrip().split() C_b = bubble_sort(C, N) C_s = selection_sort(C, N) print(' '.join(C_b)) print('Stable') print(' '.join(C_s)) if C_s == C_b: print('Stable') else: print('Not stable')
0
null
12,453,568,915,462
155
16
import sys import math from collections import defaultdict from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)] def main(): R, C, K = NMI() grid = make_grid_int(R, C, 0) for i in range(K): r_, c_, v_, = NMI() grid[r_ - 1][c_ - 1] = v_ dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)] for i in range(R + 1): for j in range(C + 1): for k in range(4): a = dp[k][i][j] try: v = grid[i][j] except: v = 0 if k == 3: dp[0][i + 1][j] = max(a, dp[0][i + 1][j]) continue dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j]) dp[k][i][j + 1] = max(a, dp[k][i][j + 1]) dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1]) print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) if __name__ == "__main__": main()
S = input() T = input() l = len(S) - len(T) + 1 ans = len(T) t = len(T) for i in range(l): s = S[i:i+t] ans = min(ans, len([0 for i in range(t) if T[i] != s[i]])) print(ans)
0
null
4,635,225,800,092
94
82
import numpy as np from numba import njit R, C, K = map(int, input().split()) item = np.zeros((R, C), np.int_) for _ in range(K): r, c, v = map(int, input().split()) item[r-1,c-1] = v @njit def solve(R, C, K, item): DP = np.zeros((R, C, 4), np.int_) DP[0][0][1] = item[0][0] for i in range(R): for j in range(C): for k in range(4): if i > 0: # 前の行から DP[i,j,0] = max(DP[i,j,0], max(DP[i-1,j])) # 取らない DP[i,j,1] = max(DP[i,j,1], max(DP[i-1,j])+item[i,j]) # 取る if j > 0: # 前の列から DP[i,j,k] = max(DP[i,j,k], DP[i,j-1,k]) # 取らない if k >= 1: DP[i,j,k] = max(DP[i,j,k], DP[i,j-1,k-1]+item[i,j]) # 取る print(max(DP[R-1,C-1])) solve(R, C, K, item)
R, C, K = map(int, input().split()) item = [[0 for _ in range(C + 1)] for _ in range(R + 1)] for _ in range(K): r, c, v = map(int, input().split()) item[r][c] = v # 多次元配列を生成する際、使いたい引数を逆順で書くと上手くいく # dp = [[[0 for _ in range(4)] for _ in range(C + 1)] for _ in range(R + 1)] # とするとTLEだった。(R+1)*4(C+1)だと通るみたいだが、あまり本質的ではない気がする。 # 以下ではdp0,dp1,dp2,dp3という4つの配列を作ることにする。 dp0 = [[0 for _ in range(C + 1)]for _ in range(R + 1)] dp1 = [[0 for _ in range(C + 1)]for _ in range(R + 1)] dp2 = [[0 for _ in range(C + 1)]for _ in range(R + 1)] dp3 = [[0 for _ in range(C + 1)]for _ in range(R + 1)] for i in range(R + 1): for j in range(C + 1): # 下に移動する場合、アイテムの個数はリセットされる if i <= R - 1: # 移動先のアイテムを取らない場合 dp0[i + 1][j] = max(dp0[i + 1][j], dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j]) # 移動先のアイテムを取る場合 dp1[i + 1][j] = max(dp1[i + 1][j], dp0[i][j] + item[i + 1][j], dp1[i][j] + item[i + 1][j], dp2[i][j] + item[i + 1][j], dp3[i][j] + item[i + 1][j]) # 右に移動する場合、アイテムの個数は維持される if j <= C - 1: dp0[i][j + 1] = max(dp0[i][j + 1], dp0[i][j]) dp1[i][j + 1] = max(dp1[i][j + 1], dp1[i][j]) dp2[i][j + 1] = max(dp2[i][j + 1], dp2[i][j]) dp3[i][j + 1] = max(dp3[i][j + 1], dp3[i][j]) # 現在のアイテム数が3未満(0 or 1 or 2)の場合、移動先のアイテムをとることが可能 [k + 1], now + item[i][j + 1]) dp1[i][j + 1] = max(dp1[i][j + 1], dp0[i][j] + item[i][j + 1]) dp2[i][j + 1] = max(dp2[i][j + 1], dp1[i][j] + item[i][j + 1]) dp3[i][j + 1] = max(dp3[i][j + 1], dp2[i][j] + item[i][j + 1]) # 最終的にR行で取るアイテムの個数についてそれぞれ調べる、3個が最適とは限らない ans = max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1]) print(ans)
1
5,588,739,289,170
null
94
94
class UnionFind(): def __init__(self,size): self.table = [-1 for _ in range(size)] self.member_num = [1 for _ in range(size)] #representative def find(self,x): while self.table[x] >= 0: x = self.table[x] return x def union(self,x,y): s1 = self.find(x) s2 = self.find(y) m1=self.member_num[s1] m2=self.member_num[s2] if s1 != s2: if m1 != m2: if m1 < m2: self.table[s1] = s2 self.member_num[s2]=m1+m2 return [m1,m2] else: self.table[s2] = s1 self.member_num[s1]=m1+m2 return [m1,m2] else: self.table[s1] = -1 self.table[s2] = s1 self.member_num[s1] = m1+m2 return [m1,m2] return [0,0] N,M = list(map(int,input().split())) uf = UnionFind(N) count = 0 for i in range(M): A,B = list(map(int,input().split())) A,B = A-1,B-1 if uf.find(A)!=uf.find(B): uf.union(A,B) count+=1 B = set() for i in range(N): B.add(uf.find(i)) print(len(B)-1)
N,M = map(int,input().split()) S = [] C = [] for a in range(M): s,c = map(int,input().split()) S.append(s) C.append(c) a = ["0"]*N e = [] for b,d in zip(S,C): if b in e: if str(d) != a[b-1]: print(-1) exit() elif b == 1 and d == 0: if N != 1: print(-1) exit() else: e.append(b) a[b-1] = str(d) if a[0] == "0" and N != 1: a[0] = "1" answer = ''.join(a) answer = int(answer) print(answer)
0
null
31,460,843,217,380
70
208
import sys def main(): N = int(input()) P = list(map(int, input().split())) min_so_far = sys.maxsize ans = 0 for p in P: if p <= min_so_far: ans += 1 min_so_far = p print(ans) if __name__ == '__main__': main()
MOD = 10**9+7 def mod(x): return x % MOD def solve(n): """ 0: {} 1: {0} 2: {9} 3: {0,9} """ x = [1,0,0,0] for i in range(n): x = list(map(mod, ( 8*x[0], (9*x[1] + x[0]), (9*x[2] + x[0]), (10*x[3] + x[2] + x[1]) ))) return x[3] n = int(input()) print(solve(n))
0
null
44,459,472,997,500
233
78
import sys import math import copy from heapq import heappush, heappop, heapify from functools import cmp_to_key from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = float("inf") MOD = 10**9 + 7 divide = lambda x: pow(x, MOD-2, MOD) def solve(): n, t = getList() li = [] for i in range(n): li.append(getList()) li.sort(key=lambda x: 30000 * x[0] + x[1]) dp = [0] * t ans = 0 for a, b in li: tmp = copy.copy(dp) ans = max(ans, dp[-1] + b) for idx, dd in enumerate(dp): # tmp[idx] = max(tmp[idx], dd) if idx + a < t: tmp[idx + a] = max(dp[idx + a], dp[idx] + b) dp = tmp for j in range(len(dp) - 1): dp[j+1] = max(dp[j], dp[j+1]) # print(dp) # print(li) print(ans) def main(): n = getN() for _ in range(n): solve() return if __name__ == "__main__": # main() solve()
def exe(): for i in range(1,10): for j in range(1,10): print(str(i)+'x'+str(j)+'='+str(i*j)) if __name__ == '__main__': exe()
0
null
76,144,154,400,300
282
1
N = int(input()) st = [list(input().split()) for _ in range(N)] kyoku = input() flg = False ans = 0 for s, t in st: if flg: ans += int(t) if s == kyoku: flg = True print(ans)
from collections import deque N = int(input()) # 有向グラフと見る、G[親] = [子1, 子2, ...] G = [[] for _ in range(N + 1)] # 子ノードを記録、これで辺の番号を管理 G_order = [] # a<bが保証されている、aを親、bを子とする for i in range(N - 1): a, b = map(lambda x: int(x) - 1, input().split()) G[a].append(b) G_order.append(b) # どこでも良いが、ここでは0をrootとする que = deque([0]) # 各頂点と「親」を結ぶ辺の色 # 頂点0をrootとするのでC[0]=0で確定(「無色」), 他を調べる colors = [0] * N # BFS while que: # prt = 親 # 幅優先探索 prt = que.popleft() color = 0 # cld = 子 for cld in G[prt]: color += 1 # 「今考えている頂点とその親を結ぶ辺の色」と同じ色は使えないので次の色にする if color == colors[prt]: color += 1 colors[cld] = color que.append(cld) # それぞれの頂点とその親を結ぶ辺の色 # print(colors) # 必要な最小の色数 print(max(colors)) # 辺の番号順に色を出力 for i in G_order: print(colors[i])
0
null
116,595,940,807,260
243
272
#ライブラリの読み込み import math #入力値の格納 k,x = map(int,input().split()) #判定 if k * 500 >= x: text = "Yes" else: text = "No" #表示 print(text)
def get_unvisted_child(v, timestamp): while len(G[v]) > 0: c = G[v].pop(0) if not c in timestamp: return c return -1 def get_unvisited_node(G, timestamp): for v in sorted(G): if not v in timestamp: return v return -1 def dept_first_search(G): t = 1 timestamp = {} stack = [] v = get_unvisited_node(G, timestamp) while v > 0: stack.append(v) timestamp[v] = [t] t += 1 while len(stack) > 0: v = stack[-1] c = get_unvisted_child(v, timestamp) if c > 0: #c = G[v].pop(0) stack.append(c) timestamp[c] = [t] else: timestamp[v].append(t) stack.pop() t += 1 v = get_unvisited_node(G, timestamp) for v in sorted(timestamp): print(v, *timestamp[v]) G = {} for i in range(int(input())): x = list(map(int, input().split())) G[x[0]] = x[2:] dept_first_search(G)
0
null
49,097,616,665,472
244
8
n, k = map(int, input().split()) l = [0 for i in range(k + 1)] ans = 0 mod = 1000000007 for i in range(k, 0, -1): l[i] = pow(k // i, n, mod) tmp = 2 * i while tmp <= k: l[i] -= l[tmp] tmp += i for i in range(k + 1): ans += i * l[i] ans %= mod print(ans)
N, K = map(int, input().split()) MOD = 10**9 + 7 cnt = [0] * (K + 1) def calc(x): M = K // x c = pow(M, N, MOD) for i in range(x + x, K + 1, x): c -= cnt[i] cnt[x] = c return c * x ans = 0 for x in range(1, K + 1)[::-1]: ans = (ans + calc(x)) % MOD print(ans)
1
36,772,586,041,870
null
176
176
import fractions def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) A,B=map(int,input().split()) print(lcm_base(A,B))
import math import sys input = sys.stdin.readline a,b=map(int,input().split()) i=1 while True: if a*i % b == 0: print(a*i) break i+=1
1
113,330,334,159,428
null
256
256
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) a, b, c = map(int, readline().split()) if a + b < c and (c - b - a) ** 2 > 4 * a * b: print('Yes') else: print('No')
import numpy as np N, K = map(int, input().split()) A = np.array(tuple(map(int, input().split()))) F = np.array(tuple(map(int, input().split()))) if sum(A) <= K: print(0) else: def solve(N, K, A, F): A = np.sort(A) F = np.sort(F)[::-1] l = -1 r = 10**12 while (r - l) > 1: mid = (r + l) // 2 # 成績がmidだったとして、修行しなければならない回数を算出 fmid = (np.fmax([0]*N, A - (mid // F))).sum() if fmid <= K: r = mid else: l = mid return(r) print(solve(N, K, A, F))
0
null
108,590,798,921,858
197
290
def divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n%i == 0: divisors.append(i) if i != n//i: divisors.append(n//i) return sorted(divisors) N = int(input()) ans = len(divisors(N-1)) -1 for k in divisors(N)[1:]: N_ = N while N_ % k == 0: N_ = N_//k if N_ % k == 1: ans += 1 print(ans)
import math def prime(x): p = {} last = math.floor(x ** 0.5) if x % 2 == 0: cnt = 1 x //= 2 while x & 1 == 0: x //= 2 cnt += 1 p[2] = cnt for i in range(3, last + 1, 2): if x % i == 0: x //= i cnt = 1 while x % i == 0: cnt += 1 x //= i p[i] = cnt if x != 1: p[x] = 1 return p N = int(input()) P = prime(N - 1) if N == 2: print(1) exit() ans = 1 for i in P.keys(): ans *= P[i] + 1 ans -= 1 P = prime(N) D = [1] for i in P.keys(): L = len(D) n = i for j in range(P[i]): for k in range(L): D.append(D[k] * n) n *= i for i in D: if i == 1: continue t = N while (t / i == t // i): t //= i t -= 1 if t / i == t // i: ans += 1 print(ans)
1
41,478,275,728,580
null
183
183
n, k = map(int, input().split()) p = [int(x) for x in input().split()] p.sort() ans = sum(p[0:k]) print(ans)
a=input() l=a.split(" ") n=int(l[0]) k=int(l[1]) f=input() fruits=f.split(" ") for d in range(0, len(fruits)): fruits[d]=int(fruits[d]) ans=0 b=0 while(b<k): g=min(fruits) ans+=g fruits.remove(g) b+=1 print(ans)
1
11,649,445,784,940
null
120
120
l = int(input()) l /= 3 print(l**3)
import sys def resolve(in_): L = int(in_.read()) return (L / 3.0) ** 3 def main(): answer = resolve(sys.stdin) print(f'{answer:.12f}') if __name__ == '__main__': main()
1
46,878,166,463,460
null
191
191
n = int(input()) s = list(map(str,input())) ans = [chr((ord(s[i])-ord("A")+n)%26+ord("A")) for i in range(len(s))] print("".join(ans))
N = int(input()) S = input() abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Sn = "" for i in range(len(S)): Sn += abc[(abc.find(S[i])+N) % 26] print(Sn)
1
134,873,210,233,990
null
271
271
a, b, c, k = map(int, input().split()) ans = 0 for i, j in zip([1, 0, -1], [a, b, c]): x = min(k, j) ans += i*x k -= x print(ans)
# -*- coding: utf-8 -*- def main(): A, B, C, K = map(int, input().split()) ans = 0 if K <= A: ans = K else: if K <= A + B: ans = A else: ans = A + (-1 * (K - A - B)) print(ans) if __name__ == "__main__": main()
1
21,714,088,894,278
null
148
148
# Problem D - String Equivalence from collections import deque # input N = int(input()) char_list = [chr(i) for i in range(97, 97+26)] def dfs(a_list, a_len): if a_len==N: print("".join(a_list)) return else: biggest = 97 count = len(set(a_list)) # N<=10だからさほど時間はかからない for c in range(biggest, biggest + count + 1): ch = chr(c) a_list.append(ch) dfs(a_list, a_len+1) a_list.pop() # initialization a_nums = deque([]) # dfs search dfs(a_nums, 0)
n = int(input()) def dfs(s, mx): if len(s) == n: print(s) return for c in range(ord("a"), mx+2): dfs(s+chr(c), max(mx, c)) dfs("", ord("a")-1)
1
52,153,123,743,212
null
198
198
n, m = map(int, input().split()) route = [[] for _ in range(n+1)] ans = [0]*n for _ in range(m): a, b = map(int, input().split()) route[a].append(b) route[b].append(a) q = [1] l = set() while True: if len(q) == 0: break p = q.pop(0) for i in route[p]: if i not in l: l.add(i) ans[i-1] = p q.append(i) if ans.count(0) > 1: print("No") else: print("Yes") for i in range(1, n): print(ans[i])
s,t = map(str,input().split()) ts = [t,s] print("".join(ts))
0
null
61,827,972,093,418
145
248
if __name__ == '__main__': n = int(input()) dic = set() for i in range(n): Cmd, Key = input().split() if Cmd == "insert": dic.add(Key) else: if Key in dic: print("yes") else: print("no")
n=int(input()) dic={} a=[] b=[] for i in range(n): tmp1,tmp2=input().split() a.append(tmp1) b.append(tmp2) for i in range(n): if a[i]=='insert': dic[b[i]]=1 else: if b[i] in dic: print("yes") else: print("no")
1
79,409,539,908
null
23
23
a = int(input()) print(a+(a**2)+(a**3))
def main(a): return ((a + 1)*a + 1)*a if __name__ == '__main__': a = int(input()) ans = main(a) print(ans)
1
10,264,133,535,770
null
115
115
def main(): n,x,m = map(int,input().split()) a = [0] * m b = [x] ans = x i = 1 while i < n: x = (x*x) % m if x == 0: print(ans) exit() if a[x] == 0: a[x] = i b.append(x) ans += x i += 1 else : q = len(b) - a[x] qq = (n-len(b)) // q qqq = (n-len(b)) % q ans += sum(b[a[x]:]) * qq ans += sum(b[a[x]:a[x]+qqq]) #print(b + b[a:] * qq + b[a:a+qqq]) print(ans) exit() print(ans) if __name__ == '__main__': main()
S=input() a=len(S) print('x'*a)
0
null
38,034,667,561,280
75
221
# 累積和を用いたdpの高速か n, k = map(int, input().split()) mod = 998244353 lr_list = [list(map(int, input().split())) for _ in range(k)] dp = [0] * (n + 1) dp[1] = 1 sdp = [0] * (n + 1) sdp[1] = 1 for i in range(2, n + 1): for j in range(k): right = max(0, i - lr_list[j][0]) left = max(0, i - lr_list[j][1] - 1) dp[i] = (dp[i] + sdp[right] - sdp[left]) % mod sdp[i] = sdp[i - 1] + dp[i] print(dp[n])
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n = I() l = LI() l.sort() ans = 0 for i in range(n): for j in range(i): mini = l[i] - l[j] if mini < l[j]: ans += n-bisect.bisect_right(l, mini) - (n-j) print(ans) main()
0
null
87,149,219,525,904
74
294
n,k = map(int, input().split()) for i in range(50): if n < pow(k,i): print(i) exit()
# coding: utf-8 # hello worldと表示する #dpでできないかな? 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 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 s=SI() if s[0]!="<": s="<"+s if s[-1]!=">": s=s+">" #print(s) state="<" strs=[] count=0 for i in range(len(s)): if state=="<": if s[i]=="<": count+=1 else: strs.append(count) count=1 state=">" else: if s[i]==">": count+=1 else: strs.append(count) count=1 state="<" strs.append(count) #print(strs) ans=0 for i in range(len(strs)//2): u=min(strs[2*i],strs[2*i+1]) v=max(strs[2*i],strs[2*i+1]) ans+=(u-1)*u//2+v*(v+1)//2 print(ans)
0
null
110,689,491,783,060
212
285
INF = 1145141919810364364334 n,m = map(int,input().split()) c = list(map(int,input().split())) dp = [INF] * (n+1) dp[0] = 0 for i in range(m): for j in range(n+1): if c[i] > j: continue else: dp[j] = min(dp[j] , dp[j-c[i]] + 1) print(dp[n])
N, K = list(map(int, input().split())) RSP = list(map(int, input().split())) D = {'r': 0, 's': 1, 'p': 2} T = input() M = N//K dp = [[[0]*3 for _ in range(M+(i < (N % K)))] for i in range(K)] # print(dp) def wins(i, s): j = D[s] return i % 3 == (j-1) % 3 ans = 0 for i in range(K): L = dp[i] for k in range(3): L[0][k] = RSP[k]*wins(k, T[i]) for j in range(1, len(L)): for k in range(3): L[j][k] = max(L[j-1][l] + RSP[k]*wins(k, T[i+j*K]) for l in range(3) if k != l) # print(L) ans += max(L[-1][k] for k in range(3)) print(ans)
0
null
53,309,784,917,850
28
251
a, b, c = [int(x) for x in input().split(" ")] if a < b and b < c: ans ="Yes" else: ans ="No" print(ans)
import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque from itertools import permutations sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) MOD = 998244353 N, K = map(int, input().split()) S = [0] * K for i in range(K): l, r = map(int, input().split()) S[i] = (l, r) dp = [0] * (N + 2) acc = [0] * (N + 2) dp[1] = 1 acc[1] = 1 for i in range(1, N + 1): for j in range(K): li = i - S[j][1] ri = i - S[j][0] if ri < 0: continue li = max(li, 0) dp[i] += (acc[ri] - acc[li - 1]) % MOD acc[i] = (acc[i - 1] + dp[i]) % MOD print(dp[N] % MOD)
0
null
1,522,967,739,628
39
74
N=int(input()) if N%2==0: print('{:.10f}'.format(0.5)) else: print('{:.10f}'.format((N+1)/(2*N)))
num=input().split() print(num[2],num[0],num[1])
0
null
107,185,578,698,550
297
178
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from numba import njit MOD = 10**9 + 7 N = int(readline()) S = np.array(list(read().rstrip()), np.int8) R = np.sum(S == ord('R')) B = np.sum(S == ord('B')) G = np.sum(S == ord('G')) @njit def f(S): N = len(S) ret = 0 for i in range(N): for j in range(i + 1, N): k = j + j - i if k >= N: break if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]: ret += 1 return ret answer = R * B * G - f(S) print(answer)
N = int(input()) if N%1000==0: q = N//1000-1 else: q = N//1000 ans = 1000*(q+1)-N print(ans)
0
null
22,305,436,570,930
175
108
import sys input = sys.stdin.readline N = int(input()) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors a = make_divisors(N) b = make_divisors(N - 1) s = set(a + b) res = 0 for x in s: if x == 1: continue t = N + 0 while t % x == 0: t //= x res += (t % x == 1) print(res)
x = int(input()) while x == 0: x += 1 print(x) exit(0) while x == 1: x -= 1 print(x) exit(0)
0
null
22,050,254,713,968
183
76
input() a = list(map(int, input().split())) c = 1000000007 print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c)
def Judgement(x,y,z): if z-x-y>0 and (z-x-y)**2-4*x*y>0: return 0 else: return 1 a,b,c=map(int,input().split()) ans=Judgement(a,b,c) if ans==0: print("Yes") else: print("No")
0
null
27,643,553,747,016
83
197
a = int(input().rstrip()) r = a + (a * a) + (a * a * a) print(r)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): while True: try: a, b = [int(x) for x in input().split(" ")] except: return else: print(gcd(a, b),lcm(a, b)) def lcm(a, b): return (a * b) // gcd(a,b) def gcd(a, b): while b != 0: a, b = b, a % b return a if __name__ == '__main__': main()
0
null
5,133,191,470,870
115
5
import sys input = lambda: sys.stdin.readline().rstrip() def main(): s, t = input().split() print(t+s) if __name__ == '__main__': main()
S, T = map(str, input().split()) print("{}{}".format(T, S))
1
102,621,809,047,128
null
248
248
n,m = map(int,input().split()) a = list(map(int,input().split())) a.sort(reverse=True) #必要票数を求める s = sum(a) needed = s/4/m if s%(4*m) == 0 else s//(4*m)+1 for i in range(m): if a[i] < needed: print("No") break else: print("Yes")
#!/usr/bin python3 # -*- coding: utf-8 -*- h, n = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] #DP[i] = i までの魔法でモンスターの体力を減らすため消耗する魔力の最小値 dp = [0] * 20001 for i in range(h): dp[i] = min(dp[i-a] + b for a, b in ab) print(dp[h-1])
0
null
59,690,343,952,318
179
229
# 入力 N = int(input()) A = list(map(int, input().split())) R = max(A) prime_factor_counter = [0]*(R+1) # D[x]にxを割り切れる最初の素数を格納 # 次に行う素因数分解で試し割りのムダを削減するための前準備 D = [0]*(R+1) for i in range(2, R+1): if D[i]: continue n = i while n < R+1: if D[n] == 0: D[n] = i n += i # 素因数分解し、素因子をカウント # ex: 12 => 2と3のカウントを+1する for a in A: tmp = a while tmp > 1: prime_factor = D[tmp] prime_factor_counter[prime_factor] += 1 while tmp%prime_factor == 0: tmp //= prime_factor # 回答出力 if max(prime_factor_counter) < 2: print('pairwise coprime') elif max(prime_factor_counter) - A.count(1) < N: print('setwise coprime') else: print('not coprime')
n, m, x = map(int, input().split()) c = [0] * n a = [0] * n for i in range(n): xs = list(map(int, input().split())) c[i] = xs[0] a[i] = xs[1:] ans = 10 ** 9 for i in range(2 ** n): csum = 0 asum = [0] * m for j in range(n): if (i >> j) & 1: csum += c[j] for k in range(m): asum[k] += a[j][k] if len(list(filter(lambda v: v >= x, asum))) == m: ans = min(ans, csum) print(-1 if ans == 10 ** 9 else ans)
0
null
13,218,550,073,508
85
149
#-*-coding:utf-8-*- import sys input=sys.stdin.readline def main(): numbers=[] a,b = map(int,input().split()) tmp1=int(a/0.08) tmp2=int(b/0.10) ans=[] for i in range(min(tmp1,tmp2),max(tmp1,tmp2)+2): if int(i*0.08) == a and int(i*0.10) == b: ans.append(i) if len(ans)>0: print(min(ans)) else: print("-1") if __name__=="__main__": main()
a,b = map(int,input().split()) astart, aend = int(a//0.08+1), int((a+1)//0.08) #[astart, aend) bstart, bend = int(b//0.10+1), int((b+1)//0.10) alst = set(range(astart,aend)) blst = set(range(bstart,bend)) share = alst & blst if len(share) == 0: print(-1) else: print(list(share)[0])
1
56,274,974,658,360
null
203
203
k = int(input()) def rec(d, n, array): array.append(n) if d == 10: return for i in [-1, 0, 1]: add = n % 10 + i if 0 <= add <= 9: rec(d + 1, 10 * n + add, array) array = [] for i in range(1, 10): rec(1, i, array) s_array = sorted(array) ans = s_array[k - 1] print(ans)
N = int(input()) L = sorted([int(i) for i in input().split()]) count = 0 from bisect import bisect_left as bi for j in range(N): for k in range(j + 1,N - 1): right = L[j] + L[k] ite_right = bi(L,right) count = count + (ite_right - k - 1) print(count)
0
null
105,963,499,040,590
181
294
S = len(set(input())) if S == 2: print('Yes') else: print('No')
import decimal d = int(input()) x = list(map(int, input().split())) y = list(map(int, input().split())) D_1 = 0 for i in range(d): L_i = abs(x[i] - y[i]) D_1 += L_i D_2 = 0 for i in range(d): L_i = abs(x[i]-y[i])**2 D_2 += L_i D_2 = (D_2) **(1/2) D_3 = 0 for i in range(d): L_i = abs(x[i]-y[i])**3 D_3 += L_i D_3 = (D_3) ** (1/3) L =[] for i in range(d): L.append(abs(x[i]-y[i])) D_ = max(L) print('{:.8f}'.format(D_1)) print('{:.8f}'.format(D_2)) print('{:.8f}'.format(D_3)) print('{:.8f}'.format(D_))
0
null
27,706,284,846,062
201
32
n = int(input()) s = list(input()) count_red = s.count('R') count_white = 0 A = [] for i in range(n): if s[i] == 'R': count_red -= 1 if s[i] == 'W': count_white += 1 A.append(max(count_red, count_white)) if len(set(s)) == 1 and list(set(s)) == ['W']: print(0) else: print(min(A))
def main(): import sys def input(): return sys.stdin.readline().rstrip() n, k = map(int, input().split()) a = list(map(int, input().split())) mod = 10 ** 9+ 7 ans = 1 def answer(a): ans =1 for x in a: ans *= x ans %= mod return ans if n == k: print(answer(a)) return a.sort(reverse=True, key= lambda x:abs(x)) if sum(x<0 for x in a[:k])%2 == 0: print(answer(a[:k])) else: if all(x < 0 for x in a): print(answer(a[-k:])) else: try: x1, y1= min([x for x in a[:k] if x > 0]), min([x for x in a[k:] if x < 0]) except ValueError: x1, y1 = 1, 0 try: x2, y2= max([x for x in a[:k] if x < 0]),\ max([x for x in a[k:] if x >= 0]) except ValueError: x2, y2 = 1, 0 if abs(x2*y1) > abs(x1*y2): a[a.index(x1)] = y1 else: a[a.index(x2)] = y2 print(answer(a[:k])) if __name__ == '__main__': main()
0
null
7,790,924,292,048
98
112
def main(): n = input() a, b = 0, 1 for i in n: x = int(i) a, b = min(a + x, b + 10 - x), min(a + x + 1, b + 10 - x - 1) print(a) main()
N = input() L=len(N) DP=[[N]*2 for _ in range(L+1)] DP[0][0]=0 DP[0][1]=1 for i,n in enumerate(N,1): DP[i][0]= min(DP[i-1][0]+int(n),DP[i-1][1]+10-int(n)) DP[i][1] = min(DP[i-1][0]+int(n)+1,DP[i-1][1]+9-int(n)) print(DP[L][0])
1
70,885,399,831,168
null
219
219
n, k = map(int , input().split()) hn = [int(num) for num in input().split()] hn.sort(reverse = True) if len(hn) > k: print(sum(hn[k:])) else : print(0)
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): r = int(readline()) print(r * r) return if __name__ == '__main__': main()
0
null
112,198,181,589,380
227
278
x = int(input()) y = 0 k = 0 while True: y += x k += 1 if y % 360 == 0: break print(k)
N = int(input()) if(N % 9 == 0): ans = True else: ans = False print("Yes" if ans else "No")
0
null
8,781,257,174,574
125
87
import bisect X, N = map(int, input().split()) P = set(map(int, input().split())) A = {i for i in range(102)} S = list(A - P) T = bisect.bisect_left(S, X) if T == 0: print(S[0]) elif X - S[T-1] > S[T] - X: print(S[T]) else: print(S[T-1])
X,N=map(int,input().split()) P=[int(x) for x in input().split()] index=0 while(1): if X-index not in P: print(X-index) break if X+index not in P: print(X+index) break index+=1
1
14,128,150,898,500
null
128
128
# -*- coding: utf-8 -*- import sys from collections import deque, defaultdict from math import sqrt, factorial, gcd, ceil # def input(): return sys.stdin.readline()[:-1] # warning not \n # def input(): return sys.stdin.buffer.readline().strip() # warning bytes # def input(): return sys.stdin.buffer.readline().decode('utf-8') import string # string.ascii_lowercase from bisect import bisect_left def solve(): n = int(input()) l = [int(x) for x in input().split()] l.sort() ans = 0 for i in range(n): for j in range(i + 1, n): r = bisect_left(l, l[i] + l[j]) if r > j: ans += r - j - 1 print(ans) t = 1 # t = int(input()) for case in range(1,t+1): ans = solve() """ azyxwvutsrqponmlkjihgfedcb """
#from sys import stdin #input = stdin.readline #inputRstrip = stdin.readline().rstrip #x = input().rstrip() #n = int(input()) #a,b,c = input().split() #a,b,c = map(int, input().split()) ST = [input() for i in range(2)] S = ST[0] T = ST[1] ans = len(T) for i in range(len(S) - len(T) + 1): count = len(T) for j in range(len(T)): if(T[j] == S[i + j]): count -= 1 if(ans > count): ans = count print(ans)
0
null
87,837,974,547,652
294
82
import math a = int(input()) b = a /1000 B = math.ceil(b) print(B * 1000 -a)
n = int(input()) print(1000 - n%1000 if n%1000 else 0)
1
8,373,054,135,172
null
108
108
a = [list(map(int,input().split())) for _ in range(3)] n = int(input()) b = [int(input()) for _ in range(n)] for i in b: for j in range(3): for k in range(3): if a[j][k] == i: a[j][k] = 0 a_2 = list(zip(*a)) flag_1 = sum(a[0]) == 0 or sum(a[1]) == 0 or sum(a[2]) == 0 flag_2 = sum(a_2[0]) == 0 or sum(a_2[1]) == 0 or sum(a_2[2]) == 0 flag_3 = a[0][0] + a[1][1] + a[2][2] == 0 or a[0][2] + a[1][1] + a[2][0] == 0 print(['No','Yes'][flag_1 or flag_2 or flag_3])
n,x,m = map(int, input().split()) be = x % m ans = be memo = [[0,0] for i in range(m)] am = [be] memo[be-1] = [1,0] #len-1 for i in range(n-1): be = be**2 % m if be == 0: break elif memo[be-1][0] == 1: kazu = memo[be-1][1] l = len(am) - kazu syou = (n-i-1) // l amari = (n-i-1)%l sum = 0 for k in range(kazu, len(am)): sum += am[k] ans = ans + syou*sum if amari > 0: for j in range(kazu,kazu + amari): ans += am[j] break else: ans += be am.append(be) memo[be-1][0] = 1 memo[be-1][1] = len(am) -1 print(ans)
0
null
31,356,024,974,660
207
75
#E from bisect import bisect_left from itertools import accumulate N,M=map(int,input().split()) A=list(map(int,input().split())) A=sorted(A) A_r=list(reversed(A)) B=[0]+list(accumulate(A_r)) def f(x): count=0 for i in A: idx=bisect_left(A,x-i) count+=N-idx if count>=M: return True else: return False MIN=0 MAX=2*10**5+1 while MAX-MIN>1: MID=(MIN+MAX)//2 if f(MID): MIN=MID else: MAX=MID ans=0 count=0 for i in A_r: idx=bisect_left(A,MIN-i) ans+=i*(N-idx)+B[N-idx] count+=N-idx print(ans-(count-M)*MIN)
from bisect import bisect_left def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() L, R = 0, 2 * 10**5 + 1 while L+1 < R: P = (L+R)//2 cnt = 0 for v in a: x = P - v cnt += n - bisect_left(a, x) if cnt >= m: L = P else: R = P csum = [0] for v in a: csum.append(v) for i in range(n): csum[i+1] += csum[i] ans = 0 cnt = 0 for v in a: x = L - v idx = bisect_left(a, x) cnt += n-idx ans += csum[-1] - csum[idx] ans += v * (n - idx) ans -= (cnt - m) * L print(ans) if __name__ == "__main__": main()
1
108,668,878,692,218
null
252
252
n = int(input()) table = list(map(int,input().split())) table.sort() print(table[0],table[-1],sum(table))
import sys import fractions import re def lcm(a, b): return a / fractions.gcd(a, b) * b #input_file = open(sys.argv[1], "r") #for line in input_file: for line in sys.stdin: ab = map(int, re.split(" +", line)) a, b = tuple(ab) gcd_ab = fractions.gcd(a, b) lcm_ab = lcm(a, b) print gcd_ab, lcm_ab
0
null
359,559,994,976
48
5