code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
n = int(input()) ans = int(n/2) + n%2 print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(read()) print((N + 1) // 2)
1
59,213,862,870,000
null
206
206
S = input() T = input() ans = len(S) for i in range(len(S)-len(T)+1): tmp = 0 for j in range(len(T)): if S[i+j] != T[j]: tmp += 1 ans = min(ans, tmp) print(ans)
def main(): N = int(input()) A = list(map(int, input().split())) if 1 not in A: print(-1) exit() next = 1 for a in A: if a == next: next += 1 print(N - next + 1) if __name__ == '__main__': main()
0
null
58,992,948,090,008
82
257
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq n,m = ma() s = input() dp = [-1]*(n+1) #dp[i]:: i番目にたどり着く最小コスト dp[0]=0 r=0 while r<=n-1: l=0 tmp=0 while l+1<=m and r+l+1<=n: l+=1 if s[r+l]=="0": tmp=l dp[r+l]=dp[r]+1 r+=tmp #if r==n:break if tmp==0: print(-1) exit() d = dp[-1] rt = [] dp = dp[::-1] r=0 while r<=n-1: l=0 tmp=0 while l+1<=m and r+l+1<=n: l+=1 if dp[r+l]==d-1: tmp=l rt.append(tmp) d-=1 r+=tmp print(*reversed(rt))
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, m = map(int, readline().split()) s = input() t = [0] * (n + 1) cur = n for i in range(n, -1, -1): if s[i] == "0": cur = i t[i] = cur else: t[i] = cur res = [] i = n while i > 0: nx = max(0, i - m) if t[nx] == i: return print(-1) else: res.append(i - t[nx]) i = t[nx] print(*res[::-1]) if __name__ == '__main__': main()
1
138,726,427,670,950
null
274
274
n,*a=map(int,open(0).read().split()) mod=10**9+7 ans=0 for j in range(60): cnt=0 for i in range(n): cnt+=a[i]&1 a[i]=(a[i]>>1) ans+=(cnt*(n-cnt)%mod)*pow(2,j,mod) ans%=mod print(ans)
from collections import defaultdict N = int(input()) A = list(map(int, input().split())) INF = 10 ** 9 + 7 D = defaultdict(int) for a in A: for i in range(61): # a の i ビット目がたっているか否か D[1 << i] += bool(a & (1 << i)) ans = 0 for key, value in D.items(): ans += key * value * (N - value) ans %= INF print(ans % INF)
1
122,872,235,958,358
null
263
263
import sys sys.setrecursionlimit(1000000) def II(): return int(input()) def MI(): return map(int, input().split()) N=II() edge=[[] for i in range(N)] a=[0]*N b=[0]*N for i in range(N-1): a[i],b[i]=MI() a[i]-=1 b[i]-=1 edge[a[i]].append(b[i]) edge[b[i]].append(a[i]) k=0 color_dict={} def dfs(to,fm=-1,ban_color=-1): global k color=1 for nxt in edge[to]: if nxt==fm: continue if color==ban_color: color+=1 color_dict[(to,nxt)]=color dfs(nxt,to,color) color+=1 k=max(k,color-1) dfs(0) print(k) for i in range(N-1): print(color_dict[(a[i],b[i])])
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): """ https://qiita.com/drken/items/4a7869c5e304883f539b#3-3-dfs-%E3%81%AE%E5%86%8D%E5%B8%B0%E9%96%A2%E6%95%B0%E3%82%92%E7%94%A8%E3%81%84%E3%81%9F%E5%AE%9F%E8%A3%85 cf. https://atcoder.jp/contests/abc138/submissions/13273052 """ from collections import deque N = int(input()) M = N-1 # 頂点数,辺数 # グラフ入力受取 (ここでは無向グラフを想定) G = [[] for _ in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 G[a].append((b, i)) G[b].append((a, i)) seen = [False]*N res = [0]*M def dfs(G, v): col = 1 parent_col = -1 if col == parent_col: col += 1 seen[v] = True stack = deque([(v, -1)]) while stack: v, parent_col = stack.pop() col = 1 for next_v, edge_ind in G[v]: if seen[next_v]: continue if col == parent_col: col += 1 res[edge_ind] = col seen[next_v] = True stack.append((next_v, col)) col += 1 # 頂点 0 をスタートとした探索 dfs(G, 0) print(max(res)) for i in res: print(i) resolve()
1
136,000,217,508,672
null
272
272
x = input() y = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' if x in y: print('A') else: print('a')
def linearSearch(A, key): i = 0 A.append(key) while A[i] != key: i += 1 if i == len(A)-1: A.pop() return 'Not_found' A.pop() return i if __name__ == '__main__': c = 0 n = int(input()) hoge1 = [int(x) for x in input().split()] q = int(input()) for key in (int(x) for x in input().split()): if linearSearch(hoge1, key) == 'Not_found': continue else: c += 1 print (c)
0
null
5,676,411,389,252
119
22
a = 100000 b = 1000 for i in range(input()): a *= 1.05 if a % b > 0: a = a - a % b + b print int(a)
n,k=map(int,input().split()) s=0 for m in map(int,input().split()): if m>=k:s+=1 print(s)
0
null
89,663,442,240,230
6
298
import sys #fin = open("test.txt", "r") fin = sys.stdin n = int(fin.readline()) d = {} for i in range(n): op, str = fin.readline().split() if op == "insert": d[str] = 0 else: if str in d: print("yes") else: print("no")
se = set([]) n = int(raw_input()) for i in range(n): s = raw_input().split() if s[0] == 'insert': se.add(s[1]) elif s[0] == 'find': if s[1] in se: print 'yes' else: print 'no'
1
73,123,126,006
null
23
23
def resolve(): from scipy.sparse.csgraph import floyd_warshall import sys def input(): return sys.stdin.readline().rstrip() n, m, l = map(int, input().split()) inf = 10 ** 20 ar = [[0] * n for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) ar[a - 1][b - 1] = c x = floyd_warshall(ar, directed=False) br = [[0] * n for _ in range(n)] for i in range(n): for j in range(i + 1, n): if x[i, j] <= l: br[i][j] = 1 y = floyd_warshall(br, directed=False) q = int(input()) for _ in range(q): s, t = map(int, input().split()) print(int(y[s - 1, t - 1]) - 1 if y[s - 1, t - 1] < inf else -1) if __name__ == "__main__": resolve()
from sys import stdin W, H, x, y, r = (int(n) for n in stdin.readline().rstrip().split()) answer = "Yes" if r <= x <= W - r and r <= y <= H - r else "No" print(answer)
0
null
86,745,721,983,298
295
41
k=int(input()) if k%2==0 or k%5==0: print(-1) else: i=1 t=7 while t%k!=0: i+=1 t=(t*10+7)%k print(i)
N=int(input()) S,T=input().split() list=[] for i in range(N): list.append(S[i]+T[i]) print(''.join(list))
0
null
59,390,701,857,568
97
255
N,K=map(int, input().split()) P=998244353 S=[tuple(map(int,input().split())) for _ in range(K)] f=[0]*(10**6) f[0]=1 for i in range(N): for l, r in S: f[i+l] += f[i] f[i+l]%=P f[i+r+1]-=f[i] f[i+r+1]%=P if i: f[i+1]+=f[i] f[i]%=P print(f[N-1])
from collections import Counter import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N, P = map(int, readline().split()) S = [int(i) for i in readline().strip()[::-1]] ans = 0 if P == 2 or P == 5: for i, s in enumerate(S): if s % P == 0: ans += N - i print(ans) exit() a = [0] s = 0 for i in range(N): s += S[i] * pow(10, i, P) a.append(s % P) t = Counter(a) ans = 0 for v in t.values(): ans += v * (v-1) // 2 print(ans) if __name__ == "__main__": main()
0
null
30,424,456,560,542
74
205
MOD = (int) (1e9+7) def power(a,n): if a == 0: return 0 if n == 0: return 1 res = 1 while n > 0: if n % 2 == 1: res = res * a % MOD a = a * a % MOD n //= 2 return res def inverse(n): return power(n, MOD-2) N, K = map(int,input().split()) A = list(map(int,input().split())) B = [] pos, neg = 0, 0 for a in A: if a > 0: B.append([a,1]) pos += 1 if a < 0: B.append([-a,-1]) neg += 1 if a == 0: B.append([0,0]) B.sort(reverse=True) ans, sign = 1, 1 if N == neg and K % 2 == 1: for i in range(K): ans *= B[N-1-i][0] ans %= MOD print(-ans % MOD) exit() for i in range(K): ans *= B[i][0] ans %= MOD sign *= B[i][1] if N == K: if sign >= 0: print(ans) else: print(-ans % MOD) exit() if sign < 0: out_neg, out_pos = 0, 0 in_pos, in_neg = 0, 0 for i in range(K): if B[K-1-i][1] < 0: out_neg = B[K-1-i][0] break for i in range(K): if B[K-1-i][1] > 0: out_pos = B[K-1-i][0] break for i in range(N-K): if B[K+i][1] > 0: in_pos = B[K+i][0] break for i in range(N-K): if B[K+i][1] < 0: in_neg = B[K+i][0] break if in_neg == 0 or out_pos == 0: ans = (ans * in_pos % MOD) * inverse(out_neg) % MOD elif in_pos == 0 or out_neg == 0: ans = (ans * in_neg % MOD) * inverse(out_pos) % MOD else: if out_pos * in_pos < out_neg * in_neg: ans = (ans * in_neg % MOD) * inverse(out_pos) % MOD else: ans = (ans * in_pos % MOD) * inverse(out_neg) % MOD print(ans)
N, K = map(int, input().split()) A = list(map(int, input().split())) m = 1000000007 a = [e for e in A if e > 0] b = [e for e in A if e < 0] c = [e for e in A if e == 0] # プラスルート if len(a) >= K - (min(K, len(b)) // 2) * 2: a.sort(reverse=True) b.sort() result = 1 i = 0 j = 0 k = 0 while k < K: if k < K - 1 and i < len(a) - 1 and j < len(b) - 1: x = a[i] * a[i + 1] y = b[j] * b[j + 1] if y >= x: result *= y result %= m j += 2 k += 2 else: result *= a[i] result %= m i += 1 k += 1 elif k < K - 1 and j < len(b) - 1: y = b[j] * b[j + 1] result *= y result %= m j += 2 k += 2 elif i < len(a): result *= a[i] result %= m i += 1 k += 1 elif j < len(b): result *= b[j] result %= m j += 1 k += 1 print(result) # 0 ルート elif len(c) != 0: print(0) # マイナスルート else: a.sort() b.sort(reverse=True) result = 1 i = 0 j = 0 k = 0 while k < K: if i < len(a) and j < len(b): if a[i] <= -b[i]: result *= a[i] result %= m i += 1 k += 1 else: result *= b[j] result %= m j += 1 k += 1 elif i < len(a): result *= a[i] result %= m i += 1 k += 1 elif j < len(b): result *= b[j] result %= m j += 1 k += 1 print(result)
1
9,446,948,183,650
null
112
112
import sys from collections import deque N, M = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(M): a, b = map(int, sys.stdin.readline().split()) G[a-1].append(b-1) G[b-1].append(a-1) ars = [0] * N todo = deque([0]) done = {0} while todo: p = todo.popleft() for np in G[p]: if np in done: continue todo.append(np) ars[np] = p + 1 done.add(np) if len(done) == N: print("Yes") for i in range(1, N): print(ars[i]) else: print("No")
from collections import deque n, m = map(int,input().split()) graph = [[] for _ in range(n+1)] for i in range(m): a,b = map(int, input().split()) graph[a].append(b) graph[b].append(a) # dist = [-1]*(n+1) # dist[0] = 0 # dist[1] = 0 mark = [-1]*(n+1) mark[0] - 0 mark[1] = 0 d = deque() d.append(1) while d: v = d.popleft() for i in graph[v]: if mark[i] != -1: # if dist[i] != -1: continue mark[i] = v # dist[i] = dist[v] + 1 d.append(i) if '-1' in mark: print('No') else: print('Yes') print(*mark[2:], sep='\n')
1
20,394,317,387,260
null
145
145
x = int(input()) x //= 200 print(10 - x)
n = int(input()) s = input() for i in range(n-1): if s[i] == s[i+1]: s = s[:i] + " " + s[i+1:] print(len(s.replace(" ", "")))
0
null
88,382,310,778,724
100
293
l = [] while 1: s = input() if s == "-": break for _ in range(int(input())): h = int(input()) s = s[h:] + s[:h] l += [s] for e in l: print(e)
#! python3 # shuffle.py def shuffle(text, n): return text[n:] + text[:n] while True: sent = input() if sent == '-': break m = int(input()) h = 0 for i in range(m): h += int(input()) h = h % len(sent) sent = shuffle(sent, h) print(sent)
1
1,887,911,414,632
null
66
66
n = int(input()) a = list(map(int,input().split())) dic = {} ans = 0 for i in range(n): if i+1-a[i] in dic: ans += dic[i+1-a[i]] if a[i]+(i+1) in dic: dic[(i+1)+a[i]] = dic[(i+1)+a[i]] + 1 else: dic[(i+1)+a[i]] = 1 print(ans)
N = int(input()) A = list(map(int, input().split())) ans = 0 B = [] C = [] maA = max(A) + N -1 for k in range(N): if A[k] + k <= maA: B.append(A[k]+k) if -A[k] + k >0: C.append(-A[k]+k) B.sort() C.sort() c = 0 b = 0 while b < len(B) and c < len(C): if B[b] == C[c]: s = 0 t = 0 j = float('inf') k = float('inf') for j in range(b, len(B)): if B[b] == B[j]: s += 1 else: break for k in range(c, len(C)): if C[c] == C[k]: t +=1 else: break ans += s*t b = j c = k continue elif B[b] > C[c]: c += 1 else: b += 1 #print(B) #print(C) print(ans)
1
25,979,070,073,022
null
157
157
def ans(n,k): if n==0: return k else: return ans(n//2,k)*2+1 N=int(input()) print(ans(N,0))
H =int(input()) #h= 1 #while 2**(h+1) <= H: # h += 1 # #n=2**(h+1) - 1 #print(n) # import math def helper(h): if h ==1: return 1 return 1 + 2 * helper(math.floor(h/2)) print(helper(H))
1
80,133,399,588,728
null
228
228
n = int(raw_input()) a = 1 b = 1 for i in range(n-1): tmp = a a = b b += tmp print b
#!/usr/bin/env python from __future__ import division, print_function from sys import stdin def fibo(n): a, b = 1, 1 while n: a, b = b, a + b n -= 1 return a print(fibo(int(stdin.readline())))
1
1,890,559,850
null
7
7
X=int(input()) ans=1000*(X//500)+5*((X-(X//500*500))//5) print(ans)
x = int(input()) cnt_500 = 0 cnt_5 = 0 while x > 4: if x >= 500: x -= 500 cnt_500 += 1 else: x -= 5 cnt_5 += 1 print(1000*cnt_500+5*cnt_5)
1
42,646,128,554,980
null
185
185
o = ['unsafe','safe'] s,w = map(int,input().split()) f = 0 if w >= s: f = 0 else: f = 1 print(o[f])
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines S,W = map(int, readline().split()) if S > W: print('safe') else: print('unsafe')
1
29,211,590,466,072
null
163
163
N, K = map(int, input().split()) h_int_list = list(map(int, input().split())) ans = 0 for i in h_int_list: if K <= i: ans += 1 print(ans)
n, k = list(map(int, input().split(' '))) print(sum([tall >= k for tall in list(map(int, input().split(' ')))]))
1
179,007,731,607,540
null
298
298
from collections import deque # BFSはこいつを使え! def dfs(n): adj = 'abcdefghij' stack = deque(['a']) while stack: # node = stack.pop(0) # pop(0)がO(n)かかっているのでとても遅い! node = stack.popleft() if len(node) == n: print(node) else: for child in adj[:len(set(node))+1]: stack.append(node+child) return -1 # 再帰での実装 # def dfs(s,n,adj): # if len(s) == n: # print(s) # else: # for child in adj[:len(set(s))+1]: # dfs(s+child,n,adj) # return -1 def main(): import sys def input(): return sys.stdin.readline().rstrip() n = int(input()) # adj = 'abcdefghij' # dfs('a',n,adj) dfs(n) if __name__ == '__main__': main()
from collections import deque n = int(input()) q = deque(["a"]) # 最後に最新の文字数のセットだけ拾う for i in range(n - 1): next_q = deque() for curr in q: suffix = ord(max(curr)) + 1 for x in range(ord("a"), suffix + 1): next_q.append(curr + chr(x)) q = next_q print(*q, sep="\n")
1
52,594,879,899,900
null
198
198
N, M = map(int, input().split()) if N % 2 == 1: for m in range(1, M + 1): print(m, N - m + 1) count = 1 if N % 2 == 0: for m in range(1, M + 1): if m <= (N // 2 - 1) // 2: start = m end = N // 2 - m print(start, end) else: start = N // 2 + count end = N - count + 1 print(start, end) count += 1
#入力部 C= 998244353 N,M,K=map(int,input().split()) #定義部 U=max(N+1,K) F=[0]*U G=[0]*U F[0]=1 for i in range(1,U): F[i]=(F[i-1]*i)%C G[i]=pow(F[-1],C-2,C) for j in range(U-2,-1,-1): G[j]=(G[j+1]*(j+1))%C def nCr(n,r): if r<0 or n<r: return 0 else: return (F[n]*G[r]*G[n-r]) #メイン部 S=0 for k in range(0,K+1): S=(S+M*pow(M-1,N-k-1,C)*nCr(N-1,k))%C print(S%C)
0
null
25,900,074,855,680
162
151
import sys S = input() if not ( len(S) == 6 and S.islower() ): sys.exit() print('Yes') if S[2] == S[3] and S[4] == S[5] else print('No')
import numpy as np import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines N, K = map(int, input().split()) A = np.array(list(map(int, input().split())), dtype = np.int64) F = np.array(list(map(int, input().split())), dtype = np.int64) A.sort() F.sort() F = F[::-1] l = 0 r = 10**12 + 100 def solve(num): B = num // F tmp = np.sum(np.maximum(0, A - B)) if tmp <= K: return 1 else: return 0 while r - l > 1: mid = (l + r) // 2 if solve(mid): r = mid else: l = mid if solve(l): print(l) else: print(r)
0
null
103,164,175,605,822
184
290
N=int(input()) for i in range(1,10): for j in range(1,10): if i*j==N: print("Yes") break else: continue break else: print("No")
N = int(input()) a = [] for i in range(10): for j in range(10): a.append(i * j) print("Yes") if N in a else print("No")
1
160,455,015,087,582
null
287
287
a = input().split() b = list(map(int, input().split())) c = input() if a[0]==c: print(b[0]-1, b[1]) else: print(b[0], b[1]-1)
dict = {} S, T = input().split(' ') dict[S], dict[T] = map(int, input().split(' ')) U = input() dict[U] -= 1 print(dict[S], dict[T])
1
71,923,016,649,960
null
220
220
import sys (a, b ,c) = [int(i) for i in input().split(' ')] x = a cnt = 0 while x <= b: if (c % x == 0) : cnt+=1 x += 1 else: print(cnt)
# coding: utf-8 # Here your code ! import sys def culc_division(x) : """ ??\???x????´???°?????°??????????????§?????? """ culc_list = [] for i in range(1,x+1) : if x % i == 0 : culc_list.append(i) return culc_list in_std = list(map(int, sys.stdin.readline().split(" "))) a = in_std[0] b = in_std[1] c = culc_division(in_std[2]) counter = 0 for idx in range(a, b+1): if idx in c: counter += 1 print(counter)
1
555,869,330,848
null
44
44
N = int(input()) arr = list(map(int, input().split())) if N == 0: print(1 if arr[0]==1 else -1) exit() elif arr[0] != 0: print(-1) exit() # 末端の葉の数で初期化 sum_arr = [arr[-1]]*N for i in range(1,N): # 深さi+1での頂点数 + 深さiでの葉の数 sum_arr[i] = sum_arr[i-1]+arr[N-i] # 本来の順番に反転 sum_arr = sum_arr[::-1] # 二分木の根から見ていく ans = [1]*(N+1) for i in range(1,N+1): if ans[i-1]-arr[i-1] < 0: print(-1) exit() tmp = min((ans[i-1]-arr[i-1])*2,sum_arr[i-1]) ans[i] = tmp # for i in range(min(25,N+1)): # if ans[i] > 2**i: # print(-1) # exit() if ans[N] != arr[-1]: print(-1) exit() print(sum(ans))
MOD = int(1e+9 + 7) N, K = map(int, input().split()) cnt = [0] * (K + 1) # 要素が全てXの倍数となるような数列の個数をXごとに求める for x in range(1, K + 1): cnt[x] = pow(K // x, N, MOD) for x in range(K, 0, -1): # 2X, 3Xの個数を求めてひく for i in range(2, K // x + 1): cnt[x] -= cnt[x * i] ans = 0 for k in range(K+1): ans += cnt[k] * k ans = ans % MOD print(ans)
0
null
27,686,145,666,810
141
176
x,y=map(int,input().split()) while x%y!=0: tmp=y y=x%y x=tmp print(y)
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
10,764,550,497,380
11
147
w,h,x,y,r=[int(i) for i in raw_input().split()] if x-r<0 or x+r>w or y-r<0 or y+r>h: print 'No' else : print 'Yes'
W,H,x,y,r=map(int,input().split()) if x-r<0 or y-r<0 or x+r>W or y+r>H : print("No") else: print("Yes")
1
463,634,484,518
null
41
41
n = int(input()) alist = list(map(int,input().split())) numb = [0]*n for i in range(n): numb[alist[i]-1] = i+1 for i in range(n): print(numb[i],end=(' '))
from sys import stdin n = int(stdin.readline().rstrip()) A = [int(x) for x in stdin.readline().rstrip().split()] ans = [0] * n for i, a in enumerate(A): ans[a-1] = i+1 print(' '.join(map(str, ans)))
1
180,826,118,989,360
null
299
299
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI2(): return [int(input()) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf = 10**17 mod = 10**9 + 7 n=I() lis=LI() nleaf=[0 for i in range(n+1)] nleaf[0]=1-lis[0] if nleaf[0]<0: print(-1) sys.exit() for i in range(n): nleaf[i+1]=nleaf[i]*2-lis[i+1] if nleaf[i+1]<0: print(-1) sys.exit() #print(lis) #print(nleaf) u=list(reversed(lis)) sup=[0 for i in range(n+1)] for i in range(n): sup[i+1]=min(sup[i]+u[i],nleaf[n-i-1]) #print(sup[i]+u[i],nleaf[n-i-1]) #print(min(sup[i]+u[i],nleaf[n-i-1])) #print(sup) print(sum(lis)+sum(sup))
x, k, d = map(int, input().split()) x = abs(x) # 絶対値が最小になる場所 # つまり x から 0 に向かう # 移動距離(dマス * k回) >= 0 以上であればそれが答え # x - k*d が答え # Python では問題ながい、型付の言語ではオーバフローを注意する必要あり # ストレートにやるといかになるが k*d がオーバフローするため式を変形させる # x - k*d = 0 -> x >= k*d -> x/k >= d -> d <= x/k # if (x - k*d) >= 0: if d <= x/k: print(x -k*d) exit() # 1. そうでない場合は、一旦 0 に近いところまでの回数を計算する(つまり x/d回) # また、0に近い位置とは x/d のあまり(x%d)になる # 2. 元の回数から1.の回数を引いた値が偶数の場合往復ができるため実質0 # 3. 2.と同様に奇数の場合 1. の位置から d を引いた絶対値が答えになる p = x%d rem = k - x//d if rem%2 == 0: print(p) else: print(abs(p -d))
0
null
12,101,197,426,980
141
92
N,M = map(int,input().split()) A = [0]*M B = [0]*M for i in range(M): A[i],B[i] = map(int,input().split()) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) uf = UnionFind(N) for i in range(M): uf.union(A[i]-1,B[i]-1) answer = 1 uflist = uf.parents for i in range(N): time = uf.size(uflist[i]) answer = max(time,answer) print(answer)
n=int(input()) a=list(map(int,input().split())) d={} for v in a: if v not in d: d[v]=0 d[v]+=1 for x in range(n): if x+1 not in d: print(0) else: print(d[x+1])
0
null
18,293,810,078,808
84
169
def check(p): i = 0 for j in range(track): s = 0 while s + A[i] <= p: s += A[i] i += 1 if i == budget: return True return False def solve(): left = max(A) right = sum(A) while (right - left > 1): mid = int((left + right) / 2) if check(mid): right = mid else : left = mid if check(left): return left else : return right if __name__ == '__main__': budget, track = list(map(int, input().split())) A = [] for n in range(budget): A.append(int(input())) ans = solve() print(ans)
import sys input = sys.stdin.readline def main(): H, A = map(int, input().split()) answer = 0 while H > 0: H -= A answer += 1 print(answer) if __name__ == '__main__': main()
0
null
38,472,776,658,702
24
225
H, A = [int(v) for v in input().rstrip().split()] r = int(H / A) if H != (r * A): r += 1 print(r)
import sys import math readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): H, A = map(int, readline().split()) print(math.ceil(H/A)) if __name__ == '__main__': main()
1
76,979,208,241,548
null
225
225
N = int(raw_input()) A = map(int, raw_input().split()) i = 0 flag = 1 while flag: flag = 0 for j in range(N-1, 0, -1): if A[j] < A[j-1]: A_j = A[j] A[j] = A[j-1] A[j-1] = A_j flag = 1 i += 1 print " ".join(map(str, A)) print i
n = int(input()) s = [int(x) for x in input().split()] cnt = 0 for i in range(n) : for j in range(n - 1, i, -1) : if s[j - 1] > s[j] : s[j - 1], s[j] = s[j], s[j - 1] cnt += 1 print(" ".join(map(str, s))) print(cnt)
1
16,047,259,620
null
14
14
N,A,B = list(map(int,input().split())) ans = (N//(A+B))*A ans += min((N%(A+B)),A) print(ans)
import sys def main(): while True: H, W = map(int, sys.stdin.readline().split()) if H == 0 and W == 0: break for h in range(H): for w in range(W): if h % 2 == 0: if w % 2 == 0: print('#', end='') else: print('.', end='') else: if w % 2 == 0: print('.', end='') else: print('#',end='') print() print() return if __name__ == '__main__': main()
0
null
28,281,399,511,430
202
51
size = [int(i) for i in input().split()] matrix = [[0 for i in range(size[1])] for j in range(size[0])] vector = [0 for i in range(size[1])] for gyou in range(size[0]): x = [int(i) for i in input().split()] matrix[gyou] = x for retsu in range(size[1]): x = int(input()) vector[retsu] = x for gyou in range(size[0]): print(sum(map(lambda val1, val2: val1 * val2, matrix[gyou], vector)))
import itertools # accumulate, compress, permutations(nPr), combinations(nCr) import bisect # bisect_left(insert位置), bisect_right(slice用) # import math # factorical(階乗) # hypot(距離) # import heapq # from fractions import gcd # Python3.5以前 # lcm(最小公倍数) = (a*b)//gcd(a,b) # from fractions import Fraction # from math import gcd # Python3.6以降 # -------------------------------------------------------------- n = int(input()) bo = list(map(int,input().split())) cnt = 0 bo.sort() for a in range(n-1): for b in range(a+1,n): cnt += bisect.bisect_left(bo, bo[a]+bo[b]) - (b+1) print(cnt)
0
null
86,852,928,571,680
56
294
n = int(input()) graph = [[] for _ in range(n)] for i in range(n - 1): a, b = map(int, input().split()) graph[a - 1].append((b - 1, i)) graph[b - 1].append((a - 1, i)) ans = [0] * (n - 1) from collections import deque d = deque() d.append([0, -1]) while d: point, prev = d.popleft() color = 1 if prev != 1 else 2 for a, index in graph[point]: if ans[index] == 0: ans[index] = color d.append([a, color]) color += 1 if prev != color + 1 else 2 print(max(ans)) print(*ans, sep='\n')
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) def dfs(curr, pare, pare_c, k, color_dic): curr_c = pare_c for chi in g[curr]: if chi == pare: continue curr_c = curr_c%k + 1 color_dic[(curr,chi)] = curr_c dfs(chi, curr, curr_c, k, color_dic) n = int(input()) g = [ [] for _ in range(n+1)] gl = [] for i in range(n-1): a, b = map(int, input().split()) g[a].append(b) g[b].append(a) gl.append((a,b)) k = 0 for node in g: k = max(len(node),k) color_dic = {} dfs(1, -1, 0, k, color_dic) print(k) for edge in gl: print(color_dic[edge])
1
136,344,643,117,758
null
272
272
N = int(input()) a = list(map(int, input().split())) x = 0 for r in a: x ^= r a = [str(x^r) for r in a] a = ' '.join(a) print(a)
a = [2, 4, 5, 7, 9] b = [0, 1, 6, 8] n = input() if int(n[-1]) in a: print("hon") elif int(n[-1]) in b: print("pon") else: print("bon")
0
null
15,856,399,133,440
123
142
(h, n), *m = [[*map(int, i.split())] for i in open(0)] dp = [0] + [10**9] * h for i in range(1, h + 1): for a, b in m: dp[i] = min(dp[i], dp[max(i-a,0)]+b) print(dp[-1])
x, k, d = [int(s) for s in input().split()] x = abs(x) q, m = divmod(x, d) if q >= k: x -= k * d else: x = m if (k - q) & 1: x = d - x print(x)
0
null
43,157,957,280,480
229
92
N = map(int,input().split()) if (sum(N) % 9 == 0 ): print('Yes') else: print('No')
N=10**9+7 x , y = map(int, input().split()) a=(2*x-y)//3 b=(2*y-x)//3 if 2*a+b!=x: print(0) exit() n=a+b r=a def fac(n,r,N): ans=1 for i in range(r): ans=ans*(n-i)%N return ans def combi(n,r,N): if n<r or n<0 or r<0: ans = 0 return ans r= min(r, n-r) ans = fac(n,r,N)*pow(fac(r,r,N),N-2,N)%N return ans ans = combi(n,r,N) print(ans)
0
null
76,884,588,202,212
87
281
h,a=map(int,input().split()) if h%a!=0: n=int(h/a)+1 print(n) else: n=int(h/a) print(n)
H,A = map(int,input().split()) count = 0 a = 100 while a > 0 : a = H - A count += 1 if a <= 0 : break else : H = a print(count)
1
77,003,269,882,502
null
225
225
N = int(input()) ST = [] for i in range(N): X, L = map(int, input().split()) ST.append((X - L, X + L)) ST.sort(key=lambda x: x[1]) ans = 0 cur = -1e9 for i in range(N): S, T = ST[i] if cur <= S: ans += 1 cur = T print(ans)
a = input().split() dist = int(a[0]) time = int(a[1]) speed = int(a[2]) if(speed * time < dist): print("No") else: print("Yes")
0
null
46,492,151,312,388
237
81
import bisect import sys def main(): input = sys.stdin.readline n, d, a = map(int, input().split()) fox = [None]*n for i in range(n): x, h = map(int, input().split()) fox[i] = (x, h) fox.sort() x = [int(fox[i][0]) for i in range(n)] h = [int(fox[i][1]) for i in range(n)] ans = 0 bit = [0]*n for i in range(n): if i != 0: bit[i] += bit[i-1] sub = max([(h[i]-bit[i]-1)//a+1, 0]) ans += sub bit[i] += sub*a index = bisect.bisect_right(x, x[i]+2*d) if index != n: bit[index] -= sub*a print(ans) if __name__ == "__main__": main()
import math N = input() c = 0 p = [0 for i in range(N)] for i in range(0,N): p[i] = input() for i in range(N): s = math.sqrt(p[i]) j = 2 while(j <= s): if(p[i]%j == 0): break j += 1 if(j > s): c += 1 print c
0
null
41,279,409,879,360
230
12
A, B, C = map(int, input().split()) if A == B == C or A != B and B != C and A != C: print("No") else: print("Yes")
A,B,C = map(int,input().split()) if A==B and B==C and A==C: print ("No") elif A!=B and B!=C and A!=C: print ("No") else : print ("Yes")
1
67,863,962,374,230
null
216
216
import sys read = sys.stdin.readline import time import math import itertools as it def inp(): return int(input()) def inpl(): return list(map(int, input().split())) start_time = time.perf_counter() # ------------------------------ N, K = inpl() dp = [False] * N for i in range(K): d = inp() A = inpl() for a in A: dp[a-1] = True cnt = 0 for bl in dp: if not bl: cnt += 1 print(cnt) # ----------------------------- end_time = time.perf_counter() print('time:', end_time-start_time, file=sys.stderr)
mod = 10**9+7 M = 2*10**6 fact = [1]*(M+1) factinv = [1]*(M+1) inv = [1]*(M+1) for n in range(2,M+1): fact[n] = n*fact[n-1]%mod inv[n] = -inv[mod%n]*(mod//n)%mod factinv[n] = inv[n]*factinv[n-1]%mod def comb(n,k): return fact[n]*factinv[k]*factinv[n-k]%mod def main(K,S): n = len(S) ans = 0 for k in range(K+1): ans += comb(n+k-1,k)*pow(25,k,mod)*pow(26,K-k,mod) ans %= mod print(ans) if __name__ == '__main__': K = int(input()) S = input() main(K,S)
0
null
18,832,659,080,290
154
124
N,K=map(int,input().split()) s={i+1 for i in range(N)} t=set() for i in range(K): input() t|=set(map(int,input().split())) print(len(s-t))
N,K=list(map(int,input().split())) ans_=[0]*N for k in range(0,2*K,2): k_ = int(input()) A = list(map(int,input().split())) for a in A: ans_[a-1]+=1 ans=0 for a in ans_: if a == 0: ans+=1 print(ans)
1
24,638,867,965,722
null
154
154
# coding: utf-8 import sys from collections import deque output_str = deque() data_cnt = int(input()) for i in range(data_cnt): line = input().rstrip() if line.find(" ") > 0: in_command, in_str = line.split(" ") else: in_command = line if in_command == "insert": output_str.appendleft(in_str) elif in_command == "delete": if output_str.count(in_str) > 0: output_str.remove(in_str) elif in_command == "deleteFirst": output_str.popleft() elif in_command == "deleteLast": output_str.pop() print(" ".join(output_str))
from collections import deque n = int(input()) q = deque() for i in range(n): c = input() if c[0] == 'i': q.appendleft(c[7:]) elif c[6] == ' ': try: q.remove(c[7:]) except: pass elif c[6] == 'F': q.popleft() else: q.pop() print(*q)
1
49,661,096,572
null
20
20
#!/usr/bin/env python3 m1, d1 = list(map(int, input().split())) m2, d2 = list(map(int, input().split())) ans = 1 if d2 == 1 else 0 print(ans)
a,b=map(int,input().split()) c,b=map(int,input().split()) if a!=c: print(1) else: print(0)
1
123,991,409,171,168
null
264
264
s=input() print("".join(["x"]*len(s)))
n=input() if n=='ABC': print('ARC') else: print('ABC')
0
null
48,458,591,190,812
221
153
line = input() stack, edges, pools = [], [], [] for i in range(len(line)): if line[i] == '\\': stack.append(i) elif line[i] == '/' and stack: j = stack.pop() tmp = i - j while edges and edges[-1] > j: edges.pop() tmp += pools.pop() edges.append(j) pools.append(tmp) print(sum(pools)) print(len(pools), *pools)
from collections import deque k = int(input()) deq = deque() for i in range(1, 10): deq.append(i) for idx in range(k): ret = deq.popleft() # retの右に1つ付け加えてできるルンルン数を追加 residue = ret % 10 if residue != 0: deq.append(ret * 10 + residue - 1) deq.append(ret * 10 + residue) if residue != 9: deq.append(ret * 10 + residue + 1) print(ret)
0
null
20,181,698,971,370
21
181
import math a,b,n = map(int,input().split()) if n < b-1: x = n else: x = b-1 ans = math.floor(a*x/b) - a * math.floor(x/b) print(ans)
n, m = map(int,input().split()) lst = list(map(int,input().split())) lst2 = [] for i in range(n): lst3 = [lst[i]] lst2.append(lst3) for i in range(m): a, b = map(int,input().split()) a = a - 1 b = b - 1 lst2[a].append(lst2[b][0]) lst2[b].append(lst2[a][0]) ans = 0 for i in range(n): x = lst2[i][0] lst2[i].sort() lst2[i].reverse() if (len(lst2[i]) == 1): ans = ans + 1 elif (x == lst2[i][0]): lst2[i].pop(0) y = lst2[i][0] if (x != y): ans = ans + 1 print(ans)
0
null
26,654,986,529,948
161
155
n = input() if int(n)<10: print(n) exit() matubi=int(n[-1]) sentou=int(n[0]) keta=len(n) if n[1:keta-1]=="": aida=0 else: aida=int(n[1:keta-1]) n=int(n) def cnt(saisyo,saigo): kotae=(10**(keta-2)-1)/9 if saisyo<sentou: kotae+=10**(keta-2) elif saisyo==sentou: tmp=saisyo*10**(keta-1)+saigo while True: if str(tmp)[0]==str(saisyo) and tmp<=n: kotae+=1 else: break tmp+=10 if saisyo==saigo: kotae+=1 return kotae ans=0 import itertools for seq in itertools.product(range(1,10),range(1,10)): ans+=cnt(seq[0],seq[1])*cnt(seq[1],seq[0]) print(int(ans))
n = int(input()) t = [[0 for j in range(10)] for i in range(10)] for i in range(1,n+1): s = str(i) t[int(s[0])][int(s[-1])] += 1 ans = 0 for i in range(1,10): for j in range(1,10): ans += t[i][j]*t[j][i] print(ans)
1
86,775,713,062,350
null
234
234
N,X,Y = (int(x) for x in input().split()) A = [0]*(N) for i in range(1,N): for j in range(i+1,N+1): if j <= X or i >= Y: A[j-i] += 1 else: A[min((j-i),(abs(i-X)+abs(j-Y)+1))] += 1 for i in range(1,N): print(A[i])
N, X, Y = map(int, input().split()) d = Y-X+1 l = [0]*(N+1) for i in range(1, N+1): for j in range(i, N+1): m = min(j-i, abs(X-i)+1+abs(Y - j)) l[m] += 1 print(*l[1:-1], sep="\n")
1
44,156,154,688,424
null
187
187
N = input() N = int(N) for a in range(0,100): n = N-10*a if n <=9: break; if n == 2 or n == 4 or n == 5 or n == 7 or n == 9: print('hon') elif n == 0 or n == 1 or n == 6 or n == 8: print('pon') elif n == 3: print('bon')
N, K = map(int, input().split()) A = N % K B = K - A print(min(A, B))
0
null
29,498,844,694,030
142
180
# Peaks n, m = map(int, input().split()) h = [0] + list(map(int, input().split())) g = [[] for _ in range(n+1)] for _ in range(m): a, b = map(int, input().split()) g[a].append(b) g[b].append(a) ans = 0 for v in range(1, n+1): for u in g[v]: if h[v] <= h[u]: break else: ans += 1 print(ans)
import math N = int(input()) M = [] sqr_N = math.floor(math.sqrt(N)) a = 0 for i in range(1, (sqr_N + 1)): if N % i == 0: a = i a_pair = N // a print(a + a_pair - 2)
0
null
93,527,901,982,592
155
288
from collections import deque n,m = map(int, input().split()) ikisaki=[[] for _ in range(n+1)] for _ in range(m): a,b = map(int, input().split()) ikisaki[a].append(b) ikisaki[b].append(a) ans=[0]+[1]+[0]*(n-1) tansakuheya=deque([1]) tmp=deque() for _ in range(1000009): for bangou in tansakuheya: for heya in ikisaki[bangou]: if ans[heya]==0: ans[heya]=bangou tmp.append(heya) tansakuheya=tmp.copy() tmp=deque() if not tansakuheya: break print("Yes") for i in range(2,n+1): print(ans[i])
n=int(input()) A=[] for i in range(n): a=str(input()) A.append(a) import collections c = collections.Counter(A) ma= c.most_common()[0][1] C=[i[0] for i in c.items() if i[1] >=ma ] C.sort(reverse=False) for j in range(len(C)): print(C[j])
0
null
45,420,215,415,878
145
218
n = int(input()) A = list(map(int, input().split())) a = [] for i in range(len(A)): a.append([A[i], i]) a.sort(key = lambda x: x[0], reverse = True) dp = [[0 for i in range(n+1)] for j in range(n+1)] for i in range(n): for l in range(i+1): dp[i+1][l] = max(dp[i+1][l], dp[i][l] + a[i][0]*(n-1-(i-l)-a[i][1])) dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + a[i][0] * (a[i][1] - l)) ans = 0 for now in dp[n]: ans = max(now, ans) print(ans)
N = int(input()) A = [int(v) for v in input().split()] P = sorted([(v, i) for i, v in enumerate(A)], key=lambda x: x[0], reverse=True) dp = [[0 for j in range(2005)] for i in range(2005)] for i in range(N): pi = P[i][1] for l in range(i+1): r = i - l dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + (pi - l) * A[pi]) dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ((N-r-1) - pi) * A[pi]) ans = 0 for i in range(N+1): ans = max(ans, dp[N][i]) print(ans)
1
33,769,192,287,510
null
171
171
def main(): s = input() if s[2] == s[3] and s[4] == s[5]: print('Yes') else: print('No') main()
import sys str = input() if str[2] == str[3]: if str[4] == str[5]: print("Yes") sys.exit() print("No")
1
42,273,549,805,060
null
184
184
S=input() if(S.isupper()): print('A') else: print('a')
print('a' if input().islower() else 'A')
1
11,311,345,007,482
null
119
119
# -*- coding: utf-8 -*- import sys word = str(raw_input()) count = 0; while True: line = map(str, raw_input().split()) for i in line: if i == "END_OF_TEXT": print count sys.exit() if i.lower() == word: count += 1
def main(): a = int(input()) b = int(input()) if a == 1 and b == 2 or a == 2 and b == 1: print(3) elif a == 2 and b == 3 or a == 3 and b == 2: print(1) elif a == 3 and b == 1 or a == 1 and b == 3: print(2) if __name__ == '__main__': main()
0
null
56,334,155,964,478
65
254
N = int(input()) if N%2 == 0: print(0.5) else: print((N+1)/2/N)
n=int(input()) print(((n-1)//2+1)/n)
1
177,033,968,377,332
null
297
297
X = int(input()) if X>=30: res = 'Yes' else: res = 'No' print(res)
X = int(input()) print('Yes') if X >= 30 else print('No')
1
5,746,085,023,040
null
95
95
def divider(A,N): """ リストA内の全要素が全て2**nで割れるときTrueを返す """ cnt_list=[] same=True for n in range(N): tmp=A[n] cnt=0 while tmp%2==0: tmp//=2 cnt+=1 cnt_list.append(cnt) if n>=1 and cnt!=cnt_list[n-1]: same=False break return same def cal_minX(A,N,M): """ hit A内の数全てでXが割り切れ、かつ商が奇数だったらTrue """ max_A=max(A) if divider(A,N)==False: no_ans=True minX=0 else: fin=False no_ans=False i=0 while fin==False: coef=2*i+1 if max_A*coef>M: fin=True no_ans=True else: hit=True for n in range(N): if max_A*coef%A[n]==0: if (max_A*coef//A[n])%2==1: pass else: hit=False break else: hit=False break if hit==False: i+=1 else: fin=True minX=max_A*coef return no_ans,minX def main(): #input N,M=map(int,input().strip().split()) A=list(map(int,input().strip().split())) A=list(map(lambda x:x//2,A)) #題意を満たす最小のXを求める。 no_ans,minX=cal_minX(A,N,M) #1-Mの中にminXの奇数倍数がいくつあるか調べる if no_ans: return 0 else: if M//minX%2==1: return M//minX//2+1 else: return M//minX//2 if __name__=="__main__": print(main())
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)
1
102,063,570,642,528
null
247
247
from heapq import * from collections import deque N,K,*A = map(int, open(0).read().split()) pos = [] zero = 0 neg = [] count = K m = 1000000007 for x in A: if x > 0: pos.append(x) elif x == 0: zero += 1 else: neg.append(x) if K == N: ans = A[0] % m for x in A[1:]: ans = (ans*x) % m print(ans) elif K % 2 == 1 and len(pos) == 0: if zero > 0: print(0) else: ai = [x * (-1) for x in A] heapify(ai) ans = (heappop(ai)*(-1)) % m for i in range(K-1): ans = (ans*heappop(ai)*(-1)) % m print(ans) elif K > N - zero: print(0) else: heapify(neg) ans = 1 negpos = [] for i in range(len(neg)//2): temp = heappop(neg) negpos.append(temp*heappop(neg)) dnp = deque(negpos) posi = [x * (-1) for x in pos] heapify(posi) if len(posi) > 0: t1 = heappop(posi) * (-1) else: t1 = 1 if len(posi) > 0: t2 = heappop(posi) * (-1) else: t2 = 1 for i in range(K): if count > 1: if len(dnp) > 0: if t1 > dnp[0]: if count > 2: ans = (ans*t1) % m t1 = t2 if len(posi) > 0: t2 = heappop(posi) * (-1) else: t2 = 1 count -= 1 else: if t2 == 1 and len(posi) == 0: ans = (ans*dnp.popleft()) % m count -= 2 else: ans = (ans*t1) % m t1 = t2 if len(posi) > 0: t2 = heappop(posi) * (-1) else: t2 = 1 count -= 1 else: if t1 * t2 > dnp[0]: if count != 3: ans = (ans*t1*t2) % m if len(posi) > 0: t1 = heappop(posi) * (-1) else: t1 = 1 if len(posi) > 0: t2 = heappop(posi) * (-1) else: t2 = 1 count -= 2 else: if len(posi) > 0: t3 = heappop(posi) * (-1) M = max(t1*t2*t3,dnp[0]*t1) ans = (ans*M) % m break else: ans = (ans*dnp.popleft()*t1) % m break else: ans = (ans*dnp.popleft()) % m count -= 2 else: ans = (ans*t1) % m if len(posi) > 0: t1 = t2 t2 = heappop(posi) * (-1) else: t1 = t2 count -= 1 elif count == 1: ans = (ans*t1) % m break else: break print(ans)
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = 1 mod = 10**9 + 7 c = 0 z = 0 for i in a: if i < 0: c += 1 elif i == 0: z += 1 if c == n and k & 1: a.reverse() for i in range(k): ans *= -a[i] ans %= mod print(-ans % mod) elif c == n: for i in range(k): ans *= -a[i] ans %= mod print(ans) elif k == n: for i in a: ans *= abs(i) ans %= mod print(((-1)**(c & 1) * ans) % mod) else: plus = [i for i in a if i > 0] minus = [i for i in a if i <= 0] plus.sort(reverse=1) minus.sort() plus += [0] * z x = len(plus) y = len(minus) p, m = 0, 0 if k & 1: ans *= plus[0] p += 1 for i in range(k // 2): if x - 1 <= p: ans *= minus[m] * minus[m + 1] m += 2 elif y - 1 <= m: ans *= plus[p] * plus[p + 1] p += 2 else: if minus[m] * minus[m + 1] >= plus[p] * plus[p + 1]: ans *= minus[m] * minus[m + 1] m += 2 else: ans *= plus[p] * plus[p + 1] p += 2 ans %= mod print(ans % mod)
1
9,433,544,371,838
null
112
112
k,n = map(int, input().split()) A = list(map(int, input().split())) ans = 10**6 for i in range(n-1): if ans > k - (A[i+1] - A[i]): ans = k - (A[i+1] - A[i]) if ans > A[-1] - A[0]: ans = A[-1] - A[0] print(ans)
k,n=map(int,input().split()) a = list(map(int,input().split())) s = [] for i in range(n-1): s.append(abs(a[i+1] - a[i])) s.append(k-a[-1]+a[0]) print(k-max(s))
1
43,477,695,662,562
null
186
186
import sys def solve(): input = sys.stdin.readline N = int(input()) P = [input().strip("\n").split() for _ in range(N)] X = input().strip("\n") sec = 0 lastId = 0 for i in range(N): if P[i][0] == X: lastId = i break for i in range(lastId + 1, N): sec += int(P[i][1]) print(sec) return 0 if __name__ == "__main__": solve()
import itertools import bisect n = int(input()) l = list(map(int,input().split())) l.sort() ans = 0 for i in range(len(l)-2): for j in range(i+1,len(l)): k = bisect.bisect_left(l, l[i]+l[j]) if k > j: ans += k - j -1 print(ans)
0
null
134,854,721,194,082
243
294
from collections import deque def main(): n = int(input()) _next = [[] for _ in range(n)] for _ in range(n): u, k, *v = map(lambda s: int(s) - 1, input().split()) _next[u] = v queue = deque() queue.append(0) d = [-1] * n d[0] = 0 while queue: u = queue.popleft() for v in _next[u]: if d[v] == -1: d[v] = d[u] + 1 queue.append(v) for i, v in enumerate(d, start=1): print(i, v) if __name__ == '__main__': main()
import math N = int(input()) Z = [int(input()) for i in range(N)] ctr = 0 for j in range(N): if Z[j] == 2: ctr += 1 elif Z[j] < 2 or (Z[j] % 2) == 0: pass else: Up = math.sqrt(Z[j]) k = 3 while k<= Up: if (Z[j] % k) == 0: break else: k += 1 else: ctr += 1 print(ctr)
0
null
7,404,839,738
9
12
s= input() x = "x" * len(s) print(x)
a = len(input()) print("x"*a)
1
73,380,696,592,420
null
221
221
s=input() l=len(s) x=0 for i in range(l): x=x+int(s[i]) if x%9==0: print("Yes") else: print("No")
m = input("") s = m.split(".") sum = 0 if len(s) == 1 and int(m)>=0 and int(m)<10**200000: for i in m : sum = sum+int(i) if sum % 9 == 0: print("Yes") else: print("No")
1
4,367,726,395,292
null
87
87
N = int(input()) a = list(map(int,input().split())) aset = set(a) if 1 not in aset: print(-1) else: nex = 1 counter = 0 for i in range(N): if a[i] == nex: nex += 1 else: counter += 1 print(counter)
n = int(input()) a = list(map(int, input().split())) target = 1 broken = 0 for i in a: if i == target: target += 1 else: broken += 1 if broken < n: print(broken) else: print(-1)
1
114,588,171,186,598
null
257
257
S=str(input()) n=len(S) Srev=''.join(list(reversed(S))) S1=S[0:(n-1)//2] S2=S[((n+1)//2):n] S1rev=''.join(list(reversed(S1))) S2rev=''.join(list(reversed(S2))) if S==Srev and S1==S1rev and S2==S2rev: print('Yes') else: print('No')
N = int(input()) A = list(map(int,input().split())) x = True for i in range(N): if A[i] % 2 != 0: continue if not (A[i]%3==0 or A[i]%5==0): x = False if x: print("APPROVED") else: print("DENIED")
0
null
57,560,001,199,232
190
217
from sys import stdin n, m = [int(x) for x in stdin.readline().rstrip().split()] a = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(n)] b = [[int(stdin.readline().rstrip())] for _ in range(m)] c = [[0] for _ in range(n)] for i in range(n): for j in range(m): c[i][0] += (a[i][j]*b[j][0]) for i in range(n): print(*c[i])
n = int(input()) N = n arr = [n] while n % 2 == 0: arr.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: arr.append(f) n //= f else: f += 2 if n != 1: arr.append(n) arr.sort() import collections c = collections.Counter(arr) k = list(c.keys()) v = list(c.values()) x = [] for i in range(len(k)): for p in range(1,v[i]+1): x.append(k[i]**p) x.sort() ans = 0 n = N while n != 1 and len(x) != 0: if n % x[0] == 0: n //= x[0] x.pop(0) ans += 1 else: x.pop(0) print(ans)
0
null
8,994,234,769,732
56
136
while True: C=input() if C=="-": break else: m=int(input()) for i in range(m): h=int(input()) c=C[0 : h] C=C[h : len(C) + 1] C+=c print(C)
import itertools def main(): # n = int(input()) h, w, k = map(int, input().split()) # a = list(map(int, input().split())) # s = input() c = [] for i in range(h): c.append(list(input())) total = 0 for i in list(itertools.chain.from_iterable(c)): if i == "#": total += 1 ans = 0 for i in range(2**h): for j in range(2**w): count = 0 for ii in range(h): for jj in range(w): if (i >> ii & 1 or j >> jj & 1) and c[ii][jj] == "#": count += 1 if total - count == k: ans += 1 print(ans) if __name__ == '__main__': main()
0
null
5,475,339,123,788
66
110
a='abcdefghijklmnopqrstuvwxyz' N=int(input()) name='' while N>0: N-=1 name+=a[N%26] N//=26 print(name[::-1])
X, Y, A, B, C = map(int, input().split(' ')) apples = [] for p in map(int, input().split(' ')): apples.append((p, 0)) for q in map(int, input().split(' ')): apples.append((q, 1)) for r in map(int, input().split(' ')): apples.append((r, 2)) apples.sort(reverse=True) pq = [] r = [] x = X y = Y for d, t in apples: if t == 0: if x > 0: x -= 1 pq.append(d) else: continue elif t == 1: if y > 0: y -= 1 pq.append(d) else: continue else: r.append(d) pq_len = len(pq) for i in range(len(r)): if i >= pq_len: break if r[i] <= pq[-(i + 1)]: break pq[-(i + 1)] = r[i] print(sum(pq))
0
null
28,339,993,006,678
121
188
n = int(input()) a = list(map(int, input().split())) r, cnt = 1, 0 for i in a: if r == i: r += 1 else: cnt += 1 print(cnt) if a.count(1) else print(-1)
def gcd(a, b): if b == 0: return a else: return gcd(b, a%b) def lcm(a, b): return a // gcd(a, b) * b N, M = map(int, input().split()) A = list(map(int, input().split())) A = [a//2 for a in A] while A[0] % 2 == 0: for i in range(N): if A[i] % 2 != 0: print(0) exit() A[i] //= 2 M //= 2 for i in range(N): if A[i] % 2 == 0: print(0) exit() lcm_ = 1 for i in range(N): lcm_ = lcm(lcm_, A[i]) if M < lcm_: print(0) exit() print((M // lcm_ + 1) // 2)
0
null
108,390,025,213,020
257
247
import sys from copy import copy read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: map(int, readline().split()) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: map(int, read().split()) in_s = lambda: readline().rstrip().decode('utf-8') INF = 10**9 + 7 def main(): H, W = in_nn() s = [list(in_s()) for _ in range(H)] dp = [INF] * W if s[0][0] == '#': dp[0] = 1 else: dp[0] = 0 for x in range(W - 1): if s[0][x] == '.' and s[0][x + 1] == '#': dp[x + 1] = dp[x] + 1 else: dp[x + 1] = dp[x] for y in range(1, H): next_dp = [INF] * W for x in range(W): if s[y - 1][x] == '.' and s[y][x] == '#': next_dp[x] = min(next_dp[x], dp[x] + 1) else: next_dp[x] = min(next_dp[x], dp[x]) for x in range(1, W): if s[y][x - 1] == '.' and s[y][x] == '#': next_dp[x] = min(next_dp[x], next_dp[x - 1] + 1) else: next_dp[x] = min(next_dp[x], next_dp[x - 1]) dp = next_dp print(dp[-1]) if __name__ == '__main__': main()
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math from copy import copy, deepcopy from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意 from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする def input(): return sys.stdin.readline()[:-1] def printl(li): print(*li, sep="\n") def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def dfs(H,W,L): d=0 c=True if L[0][0]==False: d=1 c=False q=deque([(d*10000,c)]) dxs=((0,1),(1,0)) visited=[False]*10000 while len(q): #print(q) dxy,c=q.popleft()#ここをpopleftにすると幅優先探索BFSになる d,xy=divmod(dxy,10000) x,y=divmod(xy,100) if visited[xy]: continue visited[xy]=True if x==H-1 and y==W-1: return d for dx in dxs: nx=x+dx[0] ny=y+dx[1] if nx>=H or ny>=W: continue if visited[nx*100+ny]:continue if L[nx][ny] or c==False: q.appendleft((d*10000+nx*100+ny,L[nx][ny])) else: q.append(((d+1)*10000+nx*100+ny,False)) def main(): mod = 10**9+7 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え #N = int(input()) H,W = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル L = list(list(input()) for i in range(H)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 #Lt=[[True]*H for _ in range(W)] for i in range (H): for j in range(W): if L[i][j]=='#': L[i][j]=False else: L[i][j]=True ans=dfs(H,W,L) print(ans) if __name__ == "__main__": main()
1
49,426,969,567,888
null
194
194
string = input() string = string*2 if string.count(input()): print("Yes") else: print("No")
s = input() p = input() s = s * 2 for i in range(len(s) - len(p) + 1): #print(s[i:i + len(p)]) if p == s[i:i + len(p)]: print("Yes") exit() print("No")
1
1,720,713,932,278
null
64
64
from itertools import product H, W, K = map(int, input().split()) S = [input() for _ in range(H)] S_T = [[int(s[w]) for s in S] for w in range(W)] sumS = sum(map(sum, S_T)) ans = (H - 1) * (W - 1) if sumS <= K: print(0) else: for i in product([True, False], repeat=H-1): cnt = sum(i) if cnt >= ans: continue M = [[0]] for j, k in enumerate(i): if k: M.append([]) M[-1].append(j+1) A = [0] * len(M) for s_t in S_T: for l, m in enumerate(M): A[l] += sum(s_t[i] for i in m) if any(a > K for a in A): cnt += 1 if cnt >= ans: break A = [sum(s_t[i] for i in m) for m in M] if any(a > K for a in A): cnt = ans + 1 break ans = min(cnt, ans) print(ans)
def get_dice(pips): return [[0, pips[4], 0, 0], [pips[3], pips[0], pips[2], pips[5]], [0, pips[1], 0, 0]] def move_e(dice): dice[1] = dice[1][3:] + dice[1][:3] return dice def move_n(dice): return [[0, dice[1][1], 0, 0], [dice[1][0], dice[2][1], dice[1][2], dice[0][1]], [0, dice[1][3], 0, 0]] def move_s(dice): return [[0, dice[1][3], 0, 0], [dice[1][0], dice[0][1], dice[1][2], dice[2][1]], [0, dice[1][1], 0, 0]] def move_w(dice): dice[1] = dice[1][1:] + dice[1][:1] return dice func = {'E':move_e,'N':move_n,'S':move_s,'W':move_w} dice = get_dice(list(map(int, input().split()))) for c in input(): dice = func[c](dice) print(dice[1][1])
0
null
24,189,915,487,540
193
33
import math N = int(input()) A = list(map(int, input().split())) count = 0 for i in range(0, N): minj = i for j in range(i, N): if A[j] < A[minj]: minj = j if i != minj: count += 1 temp = A[i] A[i] = A[minj] A[minj] = temp print(' '.join(map(str, A))) print(count)
n = int(input()) a = [int(s) for s in input().split(" ")] cnt = 0 for i in range(n): mi = min(a[i:]) if a[i] > mi: j = a[i:].index(mi)+i a[i], a[j] = a[j], a[i] cnt += 1 print(" ".join([str(i) for i in a])) print(cnt)
1
20,640,803,162
null
15
15
n, m = list(map(int, input().split())) s = input() if s.find('1' * m) != -1: print('-1') exit(0) i = n rans = [] flag = True while flag: for j in range(m, 1 - 1, -1): if i - j == 0: flag = False if i - j >= 0 and s[i - j] == '0': rans.append(j) i = i - j break print(' '.join(map(str,reversed(rans))))
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input().strip() ans = [] now = n while now != 0: tmp = False for i in range(m, 0, -1): if now-i >= 0 and s[now-i] == '0': tmp = True now -= i ans.append(i) break if not tmp: print(-1) sys.exit() print(*ans[::-1])
1
139,239,150,796,448
null
274
274
N = int(input()) *A, = map(int, input().split()) ans = 0 for i, a in enumerate(A): if (i + 1) & 1 and a & 1: ans += 1 print(ans)
input() print(sum([int(x) % 2 for x in input().split()[::2]]))
1
7,688,875,228,210
null
105
105
N = int(input()) S = input() ans = 0 for i in range(1000): s = ["0", "0", "0"] s[0] = str(i // 100) s[1] = str((i//10) % 10) s[2] = str(i % 10) ind = 0 cnt = 0 while cnt < 3 and ind < N: if S[ind] == s[cnt]: cnt += 1 ind += 1 if cnt == 3: ans += 1 print(ans)
n = int(input()) if n%2 == 1: print (0) exit() cnt = 0 for i in range(1,26): x = pow(5,i) x *= 2 if x > n: continue cnt += n//x print (cnt)
0
null
122,346,732,176,478
267
258
s = input() n = len(s)+1 ls = [0]*n rs = [0]*n for i in range(n-1): if s[i] == "<": ls[i+1] = ls[i]+1 for i in range(n-1): if s[-1-i] == ">": rs[-2-i] = rs[-1-i]+1 ans = 0 for i,j in zip(ls,rs): ans += max(i,j) print(ans)
s=list(input()) k=0 bef="x" n=[] ans=0 def kai(n): if n==0: return 0 ret=0 for i in range(1,n+1): ret+=i return ret for i in s: if bef!=i: if bef=="x": st=i bef=i k+=1 continue bef=i n.append(k) k=0 k+=1 n.append(k) n.reverse() if st==">": ans+=kai(n.pop()) while len(n)!=0: if len(n)==1: ans+=kai(n.pop()) else: f=n.pop() s=n.pop() if f>s: ans+=kai(f)+kai(s-1) else: ans+=kai(f-1)+kai(s) #print("{} {}".format(f,s)) print(ans)
1
156,372,465,706,230
null
285
285
bb = [] input() aa = [ int(i) for i in input().split()] for kk in aa[::-1]: bb.append(kk) print(' '.join(map(str, bb))) #map(func, iterable)
H, N = map(int, input().split()) A_list = [] for i in range(1, N+1): A_list.append("A_" + str(i)) A_list = map(int, input().split()) A_total = sum(A_list) if A_total >= H: print("Yes") else: print("No")
0
null
39,398,448,888,640
53
226
n=int(input()) res=0 for i in range(1,n+1): if int(i*1.08)==n: res=i if res != 0: print(res) else: print(":(")
n,m = map(int,input().split()) ans = 0 for i in range(n-1): ans = ans + i+1 for b in range(m-1): ans = ans + b+1 print(ans)
0
null
85,821,792,282,500
265
189
#atcoder template def main(): import sys imput = sys.stdin.readline #文字列入力の時は上記はerrorとなる。 #ここにコード #input N = int(input()) A, B = [0] * N, [0] * N for i in range(N): A[i], B[i] = map(int, input().split()) #output import statistics as st import math p = st.median(A) q = st.median(B) # %% if N % 2 == 0: print(int((q-p)/0.5)+1) else: print(int(q-p)+1) #N = 1のときなどcorner caseを確認! if __name__ == "__main__": main()
from statistics import median n=int(input()) A,B=[],[] for _ in range(n): a,b=map(int,input().split()) A.append(a*2) B.append(b*2) ma,mb = int(median(A)),int(median(B)) #print(ma,mb) if n%2 == 0: print(mb-ma+1) else: print((mb-ma)//2+1)
1
17,182,413,579,594
null
137
137
N=int(input()) M=1000 if N%M==0: print(0) else: print(M-N%M)
import math x1, y1, x2, y2 = map(float, raw_input().split()) print round(math.sqrt((x1 - x2)**2 + (y1 - y2)**2), 5 )
0
null
4,340,875,510,598
108
29
import sys from collections import defaultdict def solve(): input = sys.stdin.readline N = int(input()) sDict = defaultdict(int) maxCount = 0 for i in range(N): s = input().strip("\n") sDict[s] += 1 maxCount = max(maxCount, sDict[s]) maxS = [] for key in sDict: if sDict[key] == maxCount: maxS.append(key) maxS.sort() print(*maxS, sep="\n") return 0 if __name__ == "__main__": solve()
H=int(input()) ans = 0 count = 0 while H>0: H=int(H/2) ans+=2**count count+=1 print(ans)
0
null
74,897,748,139,418
218
228
N, K = map(int, input().split()) li = [0]*(K+1) out = 0 mod = 10**9+7 for i in range(K, 0, -1): li[i] = pow(K//i, N, mod) for j in range(i*2, K+1, i): li[i] -= li[j] out += li[i] * i print(out%mod)
while True: m,f,r=map(int,input().split()) a=0 if m ==-1 and f==-1 and r==-1: break elif m==-1 or f==-1: a="F" elif m+f>=80: a="A" elif m+f>=65 and m+f<=79: a="B" elif m+f>=50 and m+f<=65: a="C" elif m+f>=30 and m+f<=49: if r>=50: a="C" else: a="D" elif m+f<=29: a="F" print(a)
0
null
19,069,274,738,694
176
57
def main(): x = int(input()) if x >= 30: print('Yes') else: print("No") if __name__ == main(): main()
# -*- Coding: utf-8 -*- def trace(A, N): for i in range(int(N)-1): print(A[i], end=' ') print(A[int(N)-1]) def insertionSort(A, N): for i in range(1, int(N)): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v trace(A, N) if __name__ == '__main__': N = input() A = list(map(int, input().split())) trace(A, N) insertionSort(A, N)
0
null
2,910,351,475,710
95
10
from collections import defaultdict N = int(input()) List = list(map(int,input().split())) dicL = defaultdict(int) dicR = defaultdict(int) for i in range(N): dicL[List[i]+i] += 1 dicR[i - List[i]] += 1 counter = 0 for item in dicL: if item in dicR: counter += dicL[item]*dicR[item] print(counter)
n = int(input()) a = [int(i) for i in input().split()] ans = 0 dp = dict() dm = dict() for i,ai in enumerate(a): dp[i+ai] = dp.get(i+ai,0)+1 dm[i-ai] = dm.get(i-ai,0)+1 for wa,i in dm.items(): ans += i*dp.get(wa,0) print(ans)
1
26,071,951,841,820
null
157
157
nm = list(map(int, input().split())) n = nm[0] m = nm[1] l = list(map(int, input().split())) c = [[0] * (n+1) for i in range(m)] count = 0 for i in range(1, n+1): count += 1 c[0][i] = count for i in range(1, m): loop = True count = 0 for j in range(1, n+1): if j - l[i] >= 0: if c[i-1][j] > c[i][j-l[i]] + 1: c[i][j] = c[i][j-l[i]] + 1 else: c[i][j] = c[i-1][j] else: c[i][j] = c[i-1][j] print(c[-1][-1])
n, m = map(int, input().split()) c_list = list(map(int, input().split())) c_list.sort() dp_list = [0] + [10**9]*(n) for i in range(1, n+1): for c in c_list: if i - c >= 0: dp_list[i] = min(dp_list[i], dp_list[i-c]+1) else: break print(dp_list[-1])
1
145,971,709,422
null
28
28
n = int(input()) p = [] for i in range(n): x,y = map(int,input().split()) p.append([x,y]) q = [] r = [] for i in range(n): q.append(p[i][0]+p[i][1]) r.append(p[i][0]-p[i][1]) q.sort() r.sort() ans = max(abs(q[-1]-q[0]),abs(r[-1]-r[0])) print(ans)
def main(): n = int(input()) X, Y = [], [] for _ in range(n): x, y = map(int, input().split()) X.append(x + y) Y.append(x - y) X.sort() Y.sort() print(max(X[-1] - X[0], Y[-1] - Y[0])) if __name__ == '__main__': main()
1
3,421,867,682,480
null
80
80
import itertools import math n = int(input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) arr = [i for i in itertools.permutations([i for i in range(1, n+1)])] a = arr.index(p) b = arr.index(q) print(abs(a-b))
import itertools N = int(input()) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) lis = list(itertools.permutations(range(1,N+1))) a = lis.index(P)+1 b = lis.index(Q)+1 ans = abs(a-b) print(ans)
1
100,646,943,036,600
null
246
246
def f(num,l): k=0 p=[0 for i in range(len(l))] for i in range(len(l)): if k>-1: p[i]=num if l[i]=='#': num+=1 k=-1 else: if l[i]!='#': p[i]=p[i-1] else: p[i]=num num+=1 return p,num h,w,k=map(int,input().split()) j=0 num=1 p=[[0 for i in range(w)] for i in range(h)] for i in range(h): l=list(input()) if j>-1: if '#' not in l: j+=1 else: p[i],num=f(num,l) for k in range(j): p[k]=p[i] j=-1 else: if '#' not in l: p[i]=p[i-1] else: p[i],num=f(num,l) for i in range(h): print(*p[i])
import sys n = int(sys.stdin.readline().rstrip("\n")) if n % 2 == 0: print(n // 2) else: print(n // 2 + 1)
0
null
101,813,025,323,520
277
206
import sys readline = sys.stdin.readline n = int(readline()) s = readline().rstrip() from collections import deque q = deque([]) ss = set(s) for i in ss: q.append(["",0,str(i)]) ans = 0 while q: num, ind, target = q.popleft() #print(num, ind, target) while ind < len(s): if s[ind] == target: #s[ind]が0から9の中のどれかを見てる break ind += 1 else: continue num += target if len(num) == 3: ans += 1 continue sss = set(s[ind+1:]) for i in sss: q.append([num, ind +1, str(i)]) #出現した数字に関するキューを追加(例:一回目は024) print(ans)
a = int(input()) b, c = map(int, input().split()) ans = int(c/a) * a if b<=ans<=c: print('OK') else: print('NG')
0
null
77,701,646,912,706
267
158
s,t = map(str,input().split()) print(t ,end='') print(s)
s=list(input()) l=[0]*2019 t=0 ans=0 for i in range(len(s)): t=(t+pow(10,i,2019)*int(s[-1-i]))%2019 l[t]+=1 for i in l: ans+=(i*(i-1))//2 print(ans+l[0])
0
null
66,862,820,105,312
248
166
import bisect n,m = map(int,input().split()) A = list(map(int,input().split())) A.sort() S = [0]*(n+1) for i in range(n): S[i+1] = S[i] + A[i] def cnt(x,A,S): res = 0 for i,a in enumerate(A): res += bisect.bisect_left(A,x - a) return res def ans(x,A,S): res = 0 for i,a in enumerate(A): res += a*bisect.bisect_left(A,x-a) + S[bisect.bisect_left(A,x-a)] return res top = A[-1]*2+1 bottom = 0 # mid以上が何個あるか while top - bottom > 1: mid = (top + bottom)//2 if n*n - cnt(mid,A,S) > m: bottom = mid else: top = mid print(S[-1]*2*n - ans(top,A,S) + bottom*(m - (n*n - cnt(top,A,S))))
def factorize(n): b = 2 fct = [] while b * b <= n: while n % b == 0: n //= b fct.append(b) b = b + 1 if n > 1: fct.append(n) return fct def getpattern(x): pattern = 0 d = 0 for i in range(1, 1000000): d += i if x < d: break pattern += 1 return pattern n = int(input()) f = factorize(n) fu = set(factorize(n)) r = 0 for fui in fu: r += getpattern(f.count(fui)) print(r)
0
null
62,912,684,623,840
252
136