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()) S=input() cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B') ans=cntR*cntG*cntB for i in range(N-2): for j in range(i+1,N-1): if S[i]!=S[j]: k=2*j-i if k<N and S[k]!=S[i] and S[k]!=S[j]: ans-=1 print(ans)
N=int(input()) S=input() res=0 R=[] G=[] B=[] r,g,b=0,0,0 for i in range(N): if S[i]=='R': r+=1 elif S[i]=='G': g+=1 else: b+=1 R.append(r) G.append(g) B.append(b) for i in range(N): for j in range(N): if not i<j: continue k=S[2*j-i] if 2*j-i<N else 'A' if set([S[i],S[j]])==set(['R','G']): res+=B[-1]-B[j]-(k=='B') elif set([S[i],S[j]])==set(['B','G']): res+=R[-1]-R[j]-(k=='R') elif set([S[i],S[j]])==set(['R','B']): res+=G[-1]-G[j]-(k=='G') print(res)
1
36,141,246,004,610
null
175
175
from math import * H = int(input()) print(2**(int(log2(H))+1)-1)
H = int(input()) def atk(n): if n==1: return 1 return 1 + 2*(atk(n//2)) print(atk(H))
1
79,950,816,638,760
null
228
228
import collections N = int(input()) S = [] for _ in range(N): S.append(input()) c = collections.Counter(S) ans = 0 for key in c: ans += 1 print(ans)
while True: c = str(input()) if c == "-": break n = int(input()) for i in range(n): a = int(input()) c = c[a:] + c[:a] print(c)
0
null
15,955,961,685,258
165
66
n = int(input()) x = list(map(int,input().split())) m = sum(x)/len(x) m = int(round(m)) power = sum([(i - m)**2 for i in x]) print(power)
import math N = int(input()) X = list(map(int, input().split())) # O(100N)とかになりそうだし全探索で良さげ xmin = 10 ** 7 for i in range(1, 101): xsum = 0 for j in range(N): xsum += (X[j] - i) ** 2 xmin = min(xmin, xsum) print(xmin)
1
65,036,552,129,820
null
213
213
class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): # ノードxのrootノードを見つける if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def unite(self, x, y): # 木の併合、入力は併合したい各ノード⇒(a,b) 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): # ノードxが属する木のサイズを返す return -self.parents[self.find(x)] def same(self, x, y): # 入力ノード(x,y)が同じグループに属するかを返す return self.find(x) == self.find(y) def members(self, x): #ノード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()) import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline n,m=map(int,input().split()) u=UnionFind(n) for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 u.unite(a,b) ans=u.roots() print(len(ans)-1)
n = int(input()) flag = False for x in (range(1,10)): for y in (range(1,10)): if x * y == n: flag = True else: continue break if flag: print("Yes") else: print("No")
0
null
81,060,683,684,472
70
287
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools as fts import itertools as its import math import sys INF = float('inf') def solve(S: str, T: str): return len(T) - max(sum(s == t for s, t in zip(S[i:], T)) for i in range(len(S) - len(T) + 1)) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str T = next(tokens) # type: str print(f'{solve(S, T)}') if __name__ == '__main__': main()
from itertools import accumulate MAX = 2 * 10 ** 5 + 5 N, M, *A = map(int, open(0).read().split()) B = [0] * MAX for a in A: B[a] += 1 C = list(accumulate(reversed(B)))[::-1] ng, ok = 1, MAX while abs(ok - ng) > 1: m = (ok + ng) // 2 if sum(C[max(0, m - a)] for a in A) >= M: ng = m else: ok = m D = list(accumulate(reversed(list(i * b for i, b in enumerate(B)))))[::-1] print(sum(D[max(0, ng - a)] - (ng - a) * C[max(0, ng - a)] for a in A) + ng * M)
0
null
55,746,247,908,710
82
252
n ,k = map(int, input().split()) lis = list(map(int, input().split())) for i in range(k, n): l = lis[i-k] r = lis[i] if r > l: print('Yes') else: print('No')
N,K=list(map(int, input().split())) A=list(map(int, input().split())) ans=[None]*(N-K) for i in range(N-K): if A[K+i]>A[i]: ans[i]='Yes' else: ans[i]='No' print(*ans, sep='\n')
1
7,142,810,269,742
null
102
102
A,B = map(int, input().split()) a = A - B * 2 if a <= 0: print("0") else: print(a)
n,k=map(int, input().split()) def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p p = 10 ** 9 + 7 N = 2*(10 ** 5 ) # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod p) 階乗のmod factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) #0の数がmin(n-1,k) MAX=min(n-1,k) dp=[0]*(MAX+1) dp[0]=1 ans=1 for i in range(1,MAX+1): ans+=cmb(n,i,p)*cmb(n-i+i-1,i,p) ans%=p #print(ans) print(ans)
0
null
116,434,615,548,392
291
215
import sys def input(): return sys.stdin.readline().rstrip() from itertools import product def main(): h, w, k = map(int,input().split()) C = [input() for _ in range(h)] comb_list = list(product([False, True], repeat = h + w)) ans = 0 for comb in comb_list: cunt = 0 for i in range(h): if not comb[i]: continue for j in range(w): if not comb[h+j]: continue if C[i][j] == '#': cunt += 1 if cunt == k: ans += 1 print(ans) if __name__=='__main__': main()
n, m = map(int, input().split()) ab = [] for i in range (m): ab.append(list(map(int, input().split()))) par = [-1] * (n+1) #Union Find #xの根を求める def find(x): if par[x] < 0: return x else: tank = [] while par[x] >= 0: tank.append(x) x = par[x] for elt in tank: par[elt] = x return x #xとyの属する集合の併合 def unite(x,y): x = find(x) y = find(y) if x == y: return else: #sizeの大きいほうがx if par[x] > par[y]: x,y = y,x par[x] += par[y] par[y] = x return for j in range(m): unite(ab[j][0], ab[j][1]) m = -1*min(par) print(m)
0
null
6,428,009,840,668
110
84
flg = len(set(input())) == 2 print('Yes' if flg else 'No')
i = input() c = True for x in range(1,len(i)): if i[0] != i[x]: c = False print("Yes") break if c: print("No")
1
55,007,990,391,058
null
201
201
import math N, K = map(int,input().split()) logs = list(map(int,input().split())) a = 0 b = max(logs) b_memo = set() count=0 flg =0 while b-a > 1: c = (a+b)//2 times = [] for i in logs: times.append(math.ceil(i/c)-1) if sum(times) > K: a = c else: b = c print(b)
a, b, c, d, e, f = map(int, input().split()) directions = [x for x in input()] class Dice(): def __init__(self, a, b, c, d, e, f): self.a = a self.b = b self.c = c self.d = d self.e = e self.f = f def rotation(self, directions): for direction in directions: if direction == 'N': self.a, self.b, self.f, self.e = self.b, self.f, self.e, self.a if direction == 'S': self.a, self.b, self.f, self.e = self.e, self.a, self.b, self.f if direction == 'E': self.a, self.c, self.f, self.d = self.d, self.a, self.c, self.f if direction == 'W': self.a, self.c, self.f, self.d = self.c, self.f, self.d, self.a return self dice = Dice(a, b, c, d, e, f) print(dice.rotation(directions).a)
0
null
3,355,926,200,058
99
33
n,m = map(int, input().split()) d = list(map(int, input().split())) inf = float('inf') dp = [inf for i in range(n+1)] dp[0] = 0 for i in range(m): for j in range(d[i], n+1): dp[j] = min(dp[j], dp[j-d[i]]+1) print(dp[-1])
n, m = map(int, input().split()) c = list(map(int, input().split())) dp = [[10**8]*(n+1) for i in range(m+1)] dp[0][0] = 0 for i in range(m): for j in range(n+1): dp[i+1][j] = min(dp[i][j], dp[i+1][j]) if j + c[i] <= n: dp[i+1][j+c[i]] = min(dp[i+1][j]+1, dp[i+1][j+c[i]]) print(dp[m][n])
1
140,699,986,570
null
28
28
import sys W = input().lower() T = sys.stdin.read().lower() print(T.split().count(W))
import sys input = sys.stdin.readline n,a,b=map(int,input().split()) val = n//(a+b) pos = n%(a+b) if pos>a: pos = a print(val*a + pos)
0
null
28,717,361,566,388
65
202
#!/usr/bin/env python3 import sys from itertools import chain YES = "Yes" # type: str NO = "No" # type: str def solve(H: int, N: int, A: "List[int]"): if H <= sum(A): return YES else: return NO def main(): tokens = chain(*(line.split() for line in sys.stdin)) H = int(next(tokens)) # type: int N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" answer = solve(H, N, A) print(answer) if __name__ == "__main__": main()
N,K=map(int,input().split()) S=[list(map(int,input().split())) for _ in range(K)] NUM=998244353 dp=[0]*(N+1) dp[1]=1 sums=[0]*(N+1) sums[1]=1 for i in range(2,N+1): for s in S: _l,_r=i-s[0],i-s[1]-1 if _l<0: continue elif _r<0: _r=0 dp[i]+=sums[_l]-sums[_r] dp[i]%=NUM sums[i]=dp[i]+sums[i-1] sums[i]%=NUM print(dp[N])
0
null
40,281,538,218,740
226
74
from collections import defaultdict n,k = map(int,input().split()) a = list(map(int,input().split())) for i in range(n): a[i] -= 1 a[i] %= k S = [0] for i in range(n): S.append((S[-1]+a[i])%k) ans = 0 dic = defaultdict(int) dic[0] = 1 for i in range(1,n+1): if i >= k: dic[S[i-k]] -= 1 ans += max(0,dic[S[i]]) dic[(S[i])] += 1 print(ans)
s,t = input(), input() S = list(s) T = list(t) N = len(s) - 1 i = 0 counter = 0 while N + 1 != i: if S[i] != T[i]: S[i] = T[i] counter += 1 i += 1 print(counter)
0
null
73,922,580,414,610
273
116
N = int(input()) a = list(map(int,input().split())) num = 1 for i in range(N): if a[i] == num: num += 1 if num == 1: print(-1) exit() print(N - num + 1)
N = int(input()) a = list(map(int,input().split())) check = 1 ans = 0 for i in a: ans+=1 if i == check: ans -=1 check+=1 if a==[j for j in range(1,N+1)]: print(0) exit() elif ans==N: print(-1) exit() print(ans)
1
114,904,406,490,632
null
257
257
n = int(input()) taro = 0 hanako = 0 for _ in range(n): line = input().rstrip().split() if line[0] > line[1]: taro += 3 elif line[0] < line[1]: hanako += 3 else: taro += 1 hanako += 1 print(taro, hanako)
i = int(raw_input()) print i**3
0
null
1,142,373,759,208
67
35
x,k,d = map(int,input().split()) def judge(): l = x if x > 0 else -x i = l//d r = l%d if (k - i)%2 == 0: print(r) else: print(d - r) ''' if x > 0: for r in range(d): if (x - r)/d == (x - r)//d: i = (x - r)//d if (k - i)%2 == 0: print(r) else: print(d-r) exit() else: l = -x for r in range(d): if (l - r)/d == (l - r)//d: i = (l - r)//d if (k - i)%2 == 0: print(r) else: print(d-r) exit() ''' if x == 0: if k%2 == 0: print(0) else: print(d) elif x < 0: if k*d + x > 0: judge() else: print(abs(k*d + x)) else: if x - k*d < 0: judge() else: print(abs(x - k*d))
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) from bisect import bisect_left from itertools import product def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI_(): return list(map(lambda x: int(x)-1, input().split())) def LF(): return list(map(float, input().split())) def LC(): return [c for c in input().split()] def LLI(n): return [LI() for _ in range(n)] def NSTR(n): return [input() for _ in range(n)] def array2d(N, M, initial=0): return [[initial]*M for _ in range(N)] def copy2d(orig, N, M): ret = array2d(N, M) for i in range(N): for j in range(M): ret[i][j] = orig[i][j] return ret INF = float("inf") MOD = 10**9 + 7 def main(): X, K, D = MAP() # 到達候補は0に近い正と負の二つの数 d, m = divmod(X, D) cand = (m, m-D) if X >= 0: if K <= d: print(X-K*D) return else: rest = (K-d) if rest % 2 == 0: print(cand[0]) return else: print(-cand[1]) return else: if K <= -d-1: print(abs(X+K*D)) return else: rest = K-(-d-1) if rest % 2 == 0: print(-cand[1]) return else: print(cand[0]) return return if __name__ == '__main__': main()
1
5,271,015,328,828
null
92
92
from collections import deque n,p=map(int ,input().split()) que=deque([]) for i in range(n): name,time=input().split() time=int(time) que.append([name,time]) t=0 while len(que)>0: atop=que.popleft() spend=min(atop[1],p) atop[1]-=spend t+=spend if(atop[1]==0): print(atop[0],t) else: que.append(atop)
N, A, B = map(int, input().split()) if (B-A) % 2 == 0: print((B-A)//2) else: print(min((A-1+B-1+1)//2, (N-A+N-B+1)//2))
0
null
54,759,652,174,848
19
253
#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()
x = int(input()) h = x // 3600 m = (x -h*3600)//60 s = x - h*3600 - m*60 print(h, ':',m , ':', s, sep="")
0
null
8,740,253,104,092
137
37
N = int(input()) dp = [[0] * 9 for _ in range(9)] for i in range(1, N+1): if i % 10 != 0: si = str(i) start = int(si[0]) fin = int(si[-1]) dp[start-2][fin-2] += 1 ans = 0 for i in range(9): for j in range(9): ans += dp[i][j] * dp[j][i] print(ans)
n = int(input()) if n < 10: print(n) quit() count = [[0] * 10 for _ in range(10)] for i in range(1, 10): count[i][i] = 1 d = 1 for i in range(10, n + 1): if i % (d * 10)== 0: d *= 10 h = i // d f = i % 10 count[h][f] += 1 ans = 0 for i in range(10): for j in range(10): ans += count[i][j] * count[j][i] print(ans)
1
86,827,613,020,708
null
234
234
K = int(input()) s = '' for i in range(K): s = s + 'ACL' print(s)
N=int(input()) u="ACL" print(u*N)
1
2,182,533,843,590
null
69
69
import sys MOD = 10**9+7 N,K = map(int, input().split()) A = [[abs(int(x)),1 if int(x)<0 else 0] for x in input().split()] A.sort(key=lambda x: x[0],reverse=True) prod = 1 pn = 0 lastn = -1 lastp = -1 for i in range(K): if A[i][1] == 1: lastn = i else: lastp = i pn = (pn + A[i][1]) % 2 if pn == 0: if K == N and [0,0] in A: print(0) sys.exit() for i in range(K): prod = prod * A[i][0] % MOD print(prod) sys.exit() elif pn == 1: if K == N: if [0,0] in A: print(0) sys.exit() for i in range(N): prod = prod * A[i][0] % MOD prod = prod * (-1) % MOD print(prod) sys.exit() indp = K indn = K while indp < N and A[indp][1] == 1: indp += 1 while indn < N and A[indn][1] == 0: indn += 1 if lastp == -1 and indp == N: for i in range(K): prod = prod * A[-1-i][0] % MOD prod = prod * (-1) % MOD elif indp == N: for i in range(K): if i == lastp: prod = prod * A[indn][0] % MOD else: prod = prod * A[i][0] % MOD elif lastp == -1 or indn == N: for i in range(K): if i == lastn: prod = prod * A[indp][0] % MOD else: prod = prod * A[i][0] % MOD else: for i in range(K): if A[indp][0] * A[lastp][0] > A[indn][0] * A[lastn][0]: if i == lastn: prod = prod * A[indp][0] % MOD else: prod = prod * A[i][0] % MOD else: if i == lastp: prod = prod * A[indn][0] % MOD else: prod = prod * A[i][0] % MOD print(prod)
input() s = set(map(int,input().split())) n = int(input()) t = tuple(map(int,input().split())) c = 0 for i in range(n): if t[i] in s: c += 1 print(c)
0
null
4,726,392,790,780
112
22
def run(N, M, A): ''' Aiが10^5なので、searchを以下に変えられる サイズ10**5のリストで、その満足度を持つ数の件数を事前計算しておけばO(1)で求められる ''' A = sorted(A, reverse=True) cnt_A = [len(A)] pre_a = 0 cnt_dict_A = {} for a in sorted(A): cnt_dict_A[a] = cnt_dict_A.get(a, 0) + 1 next_cnt = cnt_A[-1] for a in sorted(cnt_dict_A.keys()): cnt_A.extend([next_cnt]*(a-pre_a)) pre_a = a next_cnt = cnt_A[-1]-cnt_dict_A[a] right = A[0] * 2 left = 0 while left <= right: X = (left + right) // 2 # 左手の相手がaで、満足度がX以上となる組合せの数 cnt = 0 for a in A: # cnt += search(A, X - a) if X - a <= A[0]: if X - a >= 0: cnt += cnt_A[X - a] else: cnt += cnt_A[0] if cnt >= M: res = X left = X + 1 else: right = X - 1 X = res # Xが決まったので、累積和で組合せの数分の値を求める sum_A = [0] for a in sorted(A): sum_A.append(sum_A[-1] + a) sum_cnt = 0 ans = 0 for a in A: cnt = search(A, X - a) sum_cnt += cnt if cnt > 0: ans += cnt * a + sum_A[-1] - sum_A[-cnt-1] if sum_cnt > M: ans -= X * (sum_cnt - M) return ans def search(A, X): ''' AのリストからX以上となる数値がいくつか探す Aはソート済み(降順) 二分探索で実装O(logN) leftとrightはチェック未 middleはループ終了後チェック済み ''' left = 0 right = len(A) - 1 res = 0 while left <= right: middle = (left + right) // 2 if A[middle] >= X: res = middle + 1 left = middle + 1 else: right = middle - 1 return res def main(): N, M = map(int, input().split()) A = list(map(int, input().split())) print(run(N, M, A)) if __name__ == '__main__': main()
n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort() if n==1: print(a[0]*2) exit() from bisect import bisect_left,bisect_right #幸福度がx以上がm以上か? def f(x): global n,a ret=0 for i in range(n): ret+=(n-bisect_left(a,x-a[i])) return ret #端がやはりコーナーケース(ここまじでバグらせんな) l,r=-1,10**6 while l+1<r: k=l+(r-l)//2 if f(k)>=m: l=k else: r=k co,ans=0,0 for i in range(n): co+=(n-bisect_right(a,l-a[i])) ans+=(n-bisect_right(a,l-a[i]))*a[i] print(2*ans+(m-co)*l)
1
108,085,024,372,740
null
252
252
S = input() if S[1] == 'B': print('ARC') else: print('ABC')
from itertools import product n = int(input()) s = input() ans = 0 for a, b, c in product(map(str, range(10)), repeat=3): ai = s.find(a) bi = s.find(b, ai + 1) ci = s.find(c, bi + 1) if ai != -1 and bi != -1 and ci != -1: ans += 1 print(ans)
0
null
76,356,228,248,040
153
267
import math N = int(input()) flag = True for i in range(N+1): if math.floor(i * 1.08) == N: print(i) flag = False break if flag: print(':(')
s = sum(int(i) for i in input()) if s % 9 == 0: print("Yes") else: print("No")
0
null
64,939,011,614,080
265
87
S = input() flag = 0 N = len(S) s1 = int((N-1)/2) s2 = int((N+3)/2) if S[0:s1] == S[s1+1:]: flag = 1 else: flag = 0 if S[s2-1:] == S[:s2-2]: flag = 1 else: flag = 0 if flag == 1: print("Yes") else: print("No")
S = input() N = len(S) S_list=[] for i in S: S_list.append(i) rS_list = list(reversed(S_list)) second_list = S_list[:(int((N-1)/2))] #print(f'second: {second_list}') rsecond_list = list(reversed(second_list)) third_list = S_list[(int(((N+3)-1)/2)):N] #print(f'third: {third_list}') rthird_list = list(reversed(third_list)) if S_list == rS_list: #print(f'壱: OK') if second_list == rsecond_list: #print(f'弐: OK') if third_list == rthird_list: #print(f'参: OK') print('Yes') else: print('No') else: print('No')
1
46,062,287,356,162
null
190
190
# coding: utf-8 list = [] while True: num = input().rstrip().split(" ") if (int(num[0]) == 0) and (int(num[1]) == 0): break list.append(num) for i in range(len(list)): for j in range(int(list[i][0])): if (j == 0) or (j == (int(list[i][0])-1)): print("#"*int(list[i][1])) else: print("#" + "."*(int((list[i][1]))-2) + "#") print()
h, w, k = map(int, input().split()) X = [[1 if a == "#" else 0 for a in input()] for _ in range(h)] ans = 0 for ii in range(1 << h): for jj in range(1 << w): if sum([sum([X[i][j] for j in range(w) if jj >> j & 1]) for i in range(h) if ii >> i & 1]) == k: ans += 1 print(ans)
0
null
4,898,001,565,600
50
110
while True : H, W = map(int, raw_input().split(" ")) if (H == W == 0) : break ans = "" for h in range(0, H) : for w in range(0, W) : if ((w + h) % 2 == 0) : ans += "#" else : ans += "." ans += "\n" print("%s" % (ans))
s=input() count=0 for i in range(0,len(list(s))-1): if(s[i]!=s[i+1]): count+=1 elif(s[i]==s[i+1]): count+=0 if(count>1 or count==1): print("Yes") else: print("No")
0
null
27,747,835,220,798
51
201
N = int(input()) Assertions = [] ansnum = 0 for i in range(N): b = [] n = int(input()) for j in range(n): xi,yi = map(int,input().split()) b.append([xi-1,yi]) Assertions.append(b) for i in range(2**N): select = [] ans = [0 for _ in range(N)] index = [] flag = True for j in range(N): if ((i >> j) & 1): select.append(Assertions[j]) index.append(j) ans[j] = 1 for idx in index: for Assert in Assertions[idx]: if ans[Assert[0]] != Assert[1]: flag = False break if flag: ansnum = max(ansnum,len(index)) print(ansnum)
S = str(input()) if S == 'AAA': print('No') elif S == 'BBB': print('No') else: print('Yes')
0
null
88,555,835,622,100
262
201
n = int(input()) buf = [0]*n def solv(idx,char): aida = n - idx if idx == n: print("".join(buf)) return for i in range(char + 1): buf[idx] = chr(ord('a') + i) solv(idx+1,max(i + 1,char)) solv(0,0)
a,b=map(int,input().split()) if (a>=10) or (b>=10): print(-1) exit() else: print(a*b)
0
null
104,856,765,112,336
198
286
class stack(): def __init__(self): self.S = [] def push(self, x): self.S.append(x) def pop(self): return self.S.pop() def isEmpty(self): if len(self.S) == 0: return True else: return False areas = input() S1 = stack() S2 = stack() for i, info in enumerate(areas): if info == '/': if S1.isEmpty(): continue left = S1.pop() menseki = i - left while True: if S2.isEmpty(): S2.push([menseki, left]) break if S2.S[-1][1] < left: S2.push([menseki, left]) break menseki += S2.pop()[0] elif info == '\\': S1.push(i) ans = [m[0] for m in S2.S] print(sum(ans)) if len(ans) == 0: print(len(ans)) else: print(len(ans), ' '.join(list(map(str, ans))))
s = input() s1 = list(s[:((len(s)) - 1) // 2]) s2 = list(s[(len(s) + 2) // 2:]) if s1 == s2: print('Yes') else: print('No')
0
null
23,277,104,019,300
21
190
n=int(input()) if n%2==1:print(0) else: n//=2 i=5 s=0 while i<=n: s+=n//i i*=5 print(s)
N=int(input()) ans=0 if ~N%2: for i in range(1,30): ans+=N//(10*5**i) ans+=N//10 print(ans)
1
115,777,495,628,120
null
258
258
import sys X = int(input()) a = 100 d = 0 while(a<X): a = a * 101 // 100 d += 1 print(d)
import math a = float(input()) print(2*a*math.pi)
0
null
29,205,044,021,440
159
167
N, M = map(int, input().split()) A = list(map(int, input().split())) a_sum = sum(A) if N - a_sum >= 0: print(N - a_sum) else: print('-1')
# -*- coding: utf-8 -*- import math N, M = map(int, input().split()) A = list(map(int, input().split())) for i in range(M): N -= A[i] if N >= 0: print(N) else: print(-1)
1
32,135,748,766,132
null
168
168
n = int(input()) A = list(map(int,input().split())) val1 = sum(A)//n val2 = val1+1 ans1 = 0 ans2 = 0 for a in A: ans1 += (a-val1)**2 ans2 += (a-val2)**2 print(min(ans1,ans2))
import numpy as np N = int(input()) X = np.array(list(map(int, input().split()))) X = np.sort(X) minX = X[0] maxX = X[-1] ans = 999999999 for i in range(minX, maxX+1, 1): x = (X - i) ** 2 total = np.sum(x) ans = min(ans, total) print(ans)
1
65,174,172,196,770
null
213
213
s = range(1,14) h = range(1,14) c = range(1,14) d = range(1,14) n = input() for i in range(n): mark, number = raw_input().split() if mark == 'S': s[int(number)-1] = 0 elif mark == 'H': h[int(number)-1] = 0 elif mark == 'C': c[int(number)-1] = 0 elif mark == 'D': d[int(number)-1] = 0 for i in range(13): if s[i] != 0: print "S %d" %s[i] for i in range(13): if h[i] != 0: print "H %d" %h[i] for i in range(13): if c[i] != 0: print "C %d" %c[i] for i in range(13): if d[i] != 0: print "D %d" %d[i]
import sys SUITS = ('S', 'H', 'C', 'D') cards = {suit:{i for i in range(1, 14)} for suit in SUITS} n = input() # 読み捨て for line in sys.stdin: suit, number = line.split() cards[suit].discard(int(number)) for suit in SUITS: for i in cards[suit]: print(suit, i)
1
1,039,850,364,058
null
54
54
H, W= map(int, input().split()) A=[] b=[] ans=[0 for i in range(H)] for i in range(H): A.append(list(map(int, input().split()))) for j in range(W): b.append(int(input())) for i in range(H): for j in range(W): ans[i]+=A[i][j]*b[j] print(ans[i])
a, b = map(int, input().split()) mat = [map(int, input().split()) for i in range(a)] vec = [int(input()) for i in range(b)] for row in mat: print(sum([x*y for x, y in zip(row, vec)]))
1
1,178,459,540,820
null
56
56
import math R = int(input()) pi = math.pi ans = 2*R * pi print(ans)
def count(s1,s2): cnt = 0 for i in range(len(s2)): if s1[i] != s2[i]: cnt += 1 return cnt S1 = input() S2 = input() mmin = len(S2) for i in range(len(S1)-len(S2)+1): k = count(S1[i:len(S2)+i],S2) if k < mmin: mmin = k print(mmin)
0
null
17,437,930,881,502
167
82
from collections import defaultdict n = int(input()) A = list(map(int, input().split())) #%% d = defaultdict(lambda: 0) for key in A: d[key] += 1 #%% # それぞれのkeyのnC2 cmb = dict() cmb2 = dict() for k in d.keys(): cmb[k] = d[k] * (d[k] - 1) // 2 cmb2[k] = (d[k] - 1) * (d[k] - 2) // 2 #%% ans_d = dict() s = sum(cmb.values()) for k in d.keys(): ans_d[k] = s - cmb[k] + cmb2[k] #%% for a in A: print(ans_d[a])
import sys n=input() house=[[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]] for i in range(4): for j in range(3): for k in range(10): house[i][j].append(0) for i in range(n): b,f,r,v=map(int,raw_input().split()) house[b-1][f-1][r-1]+=v for i in range(4): for j in range(3): for k in range(10): sys.stdout.write(' %d'%house[i][j][k]) print('') if i!=3: print('#'*20)
0
null
24,589,117,283,618
192
55
while True: (n, x) = [int(i) for i in input().split()] if n == x == 0: break dataset = [] for a in range(1, n + 1): for b in range(a + 1, n + 1): for c in range(b + 1, n + 1): dataset.append([a,b,c]) count = 0 for data in dataset: if sum(data) == x: count += 1 print(count)
from collections import defaultdict as dd from collections import deque import bisect import heapq def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): k = ri() a, b = rl() for i in range(k, 1001, k): if a <= i <= b: print ("OK") return print ("NG") mode = 's' if mode == 'T': t = ri() for i in range(t): solve() else: solve()
0
null
13,868,303,988,448
58
158
n ,k = map(int, input().split()) lis = list(map(int, input().split())) for i in range(k, n): l = lis[i-k] r = lis[i] if r > l: print('Yes') else: print('No')
n = int(input()) a = list(map(int, input().split())) result = 2020202020 num_left = 0 num_right = sum(a) for i in range(n): num_left += a[i] num_right -= a[i] result = min(result, abs(num_left - num_right)) print(result)
0
null
74,963,451,767,890
102
276
from collections import Counter a = int(input()) num_list = list(map(int, input().split())) D = Counter(num_list) for i in range(a): print(D[i+1])
N=int(input()) A=list(map(int,input().split())) B=list(range(1, N + 1)) import collections new_A=collections.Counter(A) for i in B: print(new_A[i])
1
32,396,236,345,068
null
169
169
while True: x = [int(z) for z in input().split(" ")] if x[0] == 0 and x[1] == 0: break for h in range(0,x[0]): dot = h % 2 for w in range(0,x[1]): if (dot == 0 and w % 2 == 0) or (dot == 1 and w % 2 == 1): print("#", end="") else: print(".", end="") print("\n", end="") print("")
while True: a, b = map(int, input().split()) if a == 0 and b == 0: break for n in range(a): mark1 = "#" mark2 = "." outLen = "" if n % 2 == 0 : mark1 = "." mark2 = "#" for m in range(b): if m % 2 != 0: outLen = outLen + mark1 else: outLen = outLen + mark2 print(outLen) print("")
1
878,897,260,670
null
51
51
n,p=map(int,input().split()) s=list(map(int,list(input()[::-1]))) if p in [2,5]: ans=0 for i in range(n): if s[-i-1]%p==0:ans+=i+1 print(ans) exit() from collections import defaultdict d=defaultdict(int) t=0 d[t]+=1 m=1 for i in range(n): t+=m*s[i] t%=p d[t]+=1 m*=10 m%=p print(sum(d[i]*(d[i]-1)//2 for i in range(p)))
W=input() a=0 while True: T=input() if T=='END_OF_TEXT': break else: a +=T.lower().split().count(W) print(a)
0
null
30,213,897,552,680
205
65
N = int(input()) A = [int(a) for a in input().split(" ")] swop = 0 for i, a in enumerate(A): j = N - 1 while j >= i + 1: if A[j] < A[j - 1]: tmp = A[j] A[j] = A[j - 1] A[j - 1] = tmp swop += 1 j -= 1 print(" ".join([str(a) for a in A])) print(swop)
n, q = map(int, input().split()) p = [input().split() for _ in range(n)] t = i = 0 while n: i = i % n if int(p[i][1]) <= q: t += int(p[i][1]) print(p[i][0], t) del p[i] n -= 1 else: p[i][1] = int(p[i][1]) - q t += q i += 1
0
null
28,036,544,870
14
19
x = list(map(int, input().split())) for i, j in enumerate(x): if j == 0: print(i+1)
x = list(map(int, input().split())) # n個の数字がリストに格納される for i in range(5): if x[i] is 0: print(i+1)
1
13,472,872,923,328
null
126
126
n = int(input()) A = list(map(int, input().split())) mod = 10**9+7 A = [a+1 for a in A] C = [0]*(n+1) C[0] = 3 ans = 1 for a in A: if C[a-1] < C[a]: print(0) exit() else: ans *= C[a-1]-C[a] ans %= mod C[a] += 1 print(ans)
N = int(input()) A = list(map(int, input().split())) mod = 10**9+7 G = [0]*3 ans = 1 for i in range(N): x = 0 cnt = 0 for j, g in enumerate(G): if g == A[i]: x = j if cnt == 0 else x cnt += 1 G[x] += 1 ans *= cnt ans = ans % mod print(ans)
1
129,745,637,553,980
null
268
268
s=str(input()) s_split=list(s) s_last=s_split[-1] if s_last == 's' : print(s+'es') else: print(s+'s')
word = input() if word[-1] == 's': print(word + 'es') else:print(word + 's')
1
2,377,064,068,990
null
71
71
def main(): a, b = map(int,input().split()) print( a* b) return main()
import sys input = sys.stdin.buffer.readline def main(): N,K = map(int,input().split()) a = list(map(int,input().split())) f = list(map(int,input().split())) a.sort() f.sort(reverse=True) l,r = -1,max(a)*max(f)+1 while r-l>1: mid = (r+l)//2 count = 0 for cost,dif in zip(a,f): if mid >= cost*dif: continue rest = cost*dif-mid count += -(-rest//dif) if count <= K: r = mid else: l = mid print(r) if __name__ == "__main__": main()
0
null
90,027,643,764,402
133
290
S=input() ans,n=0,len(S) dp=[0]*(2019) s,dp[0],k=0,1,1 for i in range(1,n+1): s=(s+int(S[-i])*k)%2019 k=(k*10)%2019 ans+=dp[s] dp[s]+=1 print(ans)
S=input() N=len(S) count=[0]*(N+1) i=0 while i<N: if S[i]=='<': count[i+1]=count[i]+1 i+=1 S=S[::-1] count=count[::-1] i=0 while i<N: if S[i]=='>': count[i+1]=max(count[i+1],count[i]+1) i+=1 print(sum(count))
0
null
94,203,970,362,042
166
285
N = int(input()) ans_ac = 0 ans_wa = 0 ans_tle =0 ans_re =0 for i in range(N): S = input() if S == 'AC': ans_ac += 1 elif S == 'WA': ans_wa += 1 elif S == 'TLE': ans_tle += 1 else: ans_re += 1 print('AC','x',ans_ac) print('WA','x',ans_wa) print('TLE','x',ans_tle) print('RE','x',ans_re)
n, m, l = map(int, input().split()) A = [] for g in range(n): A.append(list(map(int, input().split()))) B = [] for h in range(m): B.append(list(map(int, input().split()))) for i in range(n): output = [] for j in range(l): temp = 0 for k in range(m): temp += A[i][k] * B[k][j] output.append(temp) print(*output)
0
null
5,067,791,136,318
109
60
import sys sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline def solve(): X = int(rl()) print(10 - X // 200) if __name__ == '__main__': solve()
def main(): x = int(input()) grade = 0 for i in range(8): if (400 + 200 * i) <= x < (400 + 200 * (i + 1)): grade = 8 - i print(grade) if __name__ == "__main__": main()
1
6,777,036,857,120
null
100
100
N = int(input()) S = input() ans = 0 for i in range(10): for j in range(10): for k in range(10): nums = [str(x) for x in [i, j, k]] for s in S: if s == nums[0]: nums = nums[1:] if len(nums) == 0: ans += 1 break print(ans)
def is_prime(n): if n == 1: return False return all(n % i != 0 for i in range(2, int(n**0.5) + 1)) x = int(input()) print(min(i for i in range(x, 100004) if is_prime(i)))
0
null
117,285,402,843,000
267
250
h1, m1, h2, m2, k = map(int, input().split()) a = m2 - m1 if a < 0: mm = (h2 - h1 - 1) * 60 + (60 + a) else: mm = (h2 - h1) * 60 + a print(0 if mm - k <= 0 else mm - k)
def main(): import sys input = lambda: sys.stdin.readline().rstrip() h1, m1, h2, m2, k = map(int, input().split()) m = 60 - m1 h1 += 1 m += (h2 - h1)*60 + m2 print(max(0, m - k)) main()
1
18,062,942,515,100
null
139
139
def main(): import sys input = lambda: sys.stdin.readline().rstrip() h1, m1, h2, m2, k = map(int, input().split()) m = 60 - m1 h1 += 1 m += (h2 - h1)*60 + m2 print(max(0, m - k)) main()
N, K = map(int, input().split(' ')) cnt = 0 while N: N //= K cnt += 1 print(cnt)
0
null
41,351,598,995,196
139
212
from collections import defaultdict from collections import deque from collections import Counter import itertools import math def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() n,k = readInts() r,s,p = readInts() t = list(input()) his = ["-1"] ans = 0 for i in range(len(t)): if t[i]=="r": me = "p" point = p elif t[i]=="s": me = "r" point = r else: me = "s" point = s if his[max(0,i-k+1)]==me: his.append(i) else: ans+=point his.append(me) print(ans)
in_str = raw_input() q = input() for i in xrange(q): order = raw_input().split() a = int(order[1]) b = int(order[2])+1 if order[0] == "print": print in_str[a:b] if order[0] == "reverse": temp_str = in_str[a:b] in_str = in_str[:a] + temp_str[::-1] + in_str[b:] if order[0] == "replace": in_str = in_str[:a] + order[3] + in_str[b:]
0
null
54,371,681,376,318
251
68
import queue n = int(input()) graph = {} for _ in range(n): i = list(map(int,input().split())) graph[i[0]] = i[2:] dist = [-1 for i in range(n)] todo = queue.Queue() seen = set() dist[0] = 0 todo.put(1) while (not todo.empty()): now = todo.get() for nx in graph[now]: if (dist[nx-1] != -1): continue dist[nx-1] = dist[now-1] + 1 todo.put(nx) for i in range(n): print(i+1, dist[i])
N, A, B = [int(x) for x in input().split()] if (B-A) % 2 == 0: print((B-A) // 2) else: print(min(A-1, N-B) + 1 + (B - A - 1) // 2)
0
null
54,735,674,567,570
9
253
H, A = list(map(int, input().split())) print(H // A + (H % A != 0))
b=input().split(' ') b[0]=int(b[0]) b[1]=int(b[1]) k=1 m=0 while k==1: if b[0]<=0: k=k+1 b[0]=b[0]-b[1] m=m+1 print(m-1)
1
77,129,770,831,162
null
225
225
n, m = map(int, input().split()) a = [list(map(int, input().split())) for i in range(n)] b = [int(input()) for i in range(m)] for i, ai in enumerate(a): cnt = 0 for j, bj in enumerate(b): cnt += ai[j] * bj print(cnt)
import sys #fin = open("test.txt", "r") fin = sys.stdin n, m = map(int, fin.readline().split()) A = [[] for i in range(n)] for i in range(n): A[i] = list(map(int, fin.readline().split())) b = [0 for i in range(m)] for i in range(m): b[i] = int(fin.readline()) c = [0 for i in range(n)] for i in range(n): for j in range(m): c[i] += A[i][j] * b[j] for i in range(n): print(c[i])
1
1,155,892,911,228
null
56
56
while True: H, W = map(int, input().split()) if not(H or W): break for i in range(H): print('#', end='') for j in range(W-2): if i > 0 and i < H - 1: print('.', end='') else: print('#', end='') print('#') print()
if __name__ == "__main__": while True: h,w = map(int,input().split()) if w is not 0 or h is not 0: for i in range(w): print("#",end="") print("") for i in range(h-2): print("#",end="") for j in range(w-2): print(".",end="") print("#",end="") print("") for i in range(w): print("#",end="") print("") print("") else: break
1
829,537,607,710
null
50
50
n = int(input()) s = input() ans = 0 for i in range(1000): i = str(i).zfill(3) f = True x = -1 for j in range(3): x = s.find(i[j],x+1) f = f and bool(x >= 0) ans += f print(ans)
from collections import deque import numpy as np H,W = map(int,input().split()) maze = [input() for _ in range(H)] ans = 0 for x in range(H): for y in range(W): if maze[x][y]=='#': continue dist = [[0]*W for i in range(H)] Q = deque([[x,y]]) while Q: h,w = Q.popleft() for i,j in [[1,0],[-1,0],[0,1],[0,-1]]: h2,w2 = h+i,w+j if 0<=h2<H and 0<=w2<W and dist[h2][w2]==0 and maze[h2][w2]!='#': dist[h2][w2] = dist[h][w]+1 Q.append([h2,w2]) dist[x][y] = 0 ans = max(ans, np.max(dist)) print(ans)
0
null
111,789,759,411,900
267
241
import math A, B, H, M = map(int, input().split()) thetaA = math.pi * (0.5*(H*60 + M)) / 180 thetaB = math.pi * 6.0*M / 180 theta = min(2*math.pi-abs(thetaA-thetaB), abs(thetaA-thetaB)) cosC = math.cos(theta) ans = math.sqrt(A**2+B**2-2*A*B*cosC) print(ans)
import math a, b, h, m = map(int,input().split()) ax = a*math.cos(math.radians(90-360/12*(h+m/60))) ay = a*math.sin(math.radians(90-360/12*(h+m/60))) bx = b*math.cos(math.radians(90-360/60*m)) by = b*math.sin(math.radians(90-360/60*m)) print(math.sqrt((ax-bx)**2+(ay-by)**2))
1
20,200,252,471,168
null
144
144
def main(): N, A, B = map(int, input().split()) diff = abs(A-B) if diff%2 == 0: ans = diff//2 else: # 端に行く # 一回端のままになる => 偶数のときと同じ ans = min(A-1, N-B) diff -= 1; ans += 1 ans += diff//2 print(ans) if __name__ == "__main__": main()
H = int(input()) cnt = 0 res = 0 while H > 1: H = H //2 cnt += 1 res += 2**cnt print(res+1)
0
null
94,758,676,884,548
253
228
N = int(input()) S = input() ans = 0 for i in range(10): for j in range(10): for k in range(10): nums = [str(x) for x in [i, j, k]] for s in S: if s == nums[0]: nums = nums[1:] if len(nums) == 0: ans += 1 break print(ans)
N = int(input()) S = list(input()) S = list(map(lambda x: int(x), S)) ans = 0 for i in range(10): for j in range(10): for k in range(10): if i in S: a = S.index(i) if j in S[a+1:]: b = S[a+1:].index(j) + a + 1 if k in S[b+1:]: ans += 1 else: continue else: continue else: continue print(ans)
1
128,707,183,599,178
null
267
267
def count_num_light(a): ret = [0 for _ in range(len(a))] n = len(a) for i in range(n): start = max(0, i-a[i]) end = min(n-1, i+a[i]) ret[start] += 1 if end+1 < n: ret[end+1] -= 1 for i in range(1,n): ret[i] += ret[i-1] return ret n, k = map(int, input().split()) a = list(map(int, input().split())) num_light = count_num_light(a) for i in range(k-1): num_light = count_num_light(num_light) if sum(num_light) == n**2: break print(*num_light)
n = int(input()) AC = 0 WA = 0 TLE = 0 RE = 0 for i in range(n): x = input() if x == "AC": AC += 1 elif x == "WA": WA += 1 elif x == "TLE": TLE += 1 elif x == "RE": RE += 1 print("AC x " + str(AC)) print("WA x " + str(WA)) print("TLE x " + str(TLE)) print("RE x " + str(RE))
0
null
12,042,090,293,820
132
109
N,A,B = map(int,input().split()) kotae= N//(A+B)*A am = N%(A+B) if am>A: am=A print(kotae+am)
from sys import stdin def main(): a = set() _ = int(stdin.readline()) for command,value in (line.split() for line in stdin.readlines()): if command == "insert": a.add(value) else: print("yes" if value in a else "no") main()
0
null
27,669,471,445,692
202
23
n=int(input()) num=[int(input()) for i in range(n)] maxv=num[1]-num[0] minv=num[0] for j,n in enumerate(num[1:]): maxv=max(maxv,n-minv) minv=min(minv,num[j+1]) print(maxv)
n = int(input()) DifMax = -9999999999999 R = [int(input())] RMin = R[0] for i in range(1, n): if RMin > R[i-1]: RMin = R[i-1] R.append(int(input())) if DifMax < R[i] - RMin: DifMax = R[i] - RMin print(DifMax)
1
13,947,956,782
null
13
13
#coding: UTF-8 n = int(input()) S = list(map(int,input().split())) q = int(input()) T = list(map(int,input().split())) ans = 0 for v in T: if v in S: ans += 1 print(ans)
while 1: n,x=map(int,input().split()) if n+x==0:break print(sum([max(0,(x-a-1)//2-max(a,x-a-1-n))for a in range(1,x//3)]))
0
null
673,574,071,808
22
58
x, n = map(int, input().split()) p = list(map(int, input().split())) for i in range(1000): if x-i not in p: print(x-i) exit() elif x+i not in p: print(x+i) exit()
#デフォルト import itertools from collections import defaultdict import collections import math import sys sys.setrecursionlimit(200000) mod = 1000000007 h1, m1, h2, m2, k = map(int, input().split()) minute = ((h2 * 60) + m2) - ((h1 * 60) + m1) print(minute - k)
0
null
16,051,783,299,528
128
139
N, M = map(int, input().split()) S = input()[::-1] l = [] p = 0 chk = True while p<N: for i in range(1, min(M, N-p)+1)[::-1]: if S[p+i]=="0": break else: print(-1) chk = False break l.append(i) p += i if chk: l.reverse() print(*l)
n,m=map(int,input().split()) s=input() ans=[] w=n while w: x=0 for i in range(1,m+1): if w-i>=0 and s[w-i]=='0': x=i if x==0: print(-1) exit() else: ans.append(x) w-=x print(*ans[::-1])
1
139,101,948,963,332
null
274
274
import sys import math import itertools import numpy import collections rl = sys.stdin.readline n = int(rl()) se = [] for _ in range(n): x, r = map(int, rl().split()) start, end = x-r, x+r se.append([start, end]) se.sort(key=lambda x: x[1]) cur = se[0][0] cnt = 0 for i in se: if cur <= i[0] <= i[1]: cur = i[1] cnt += 1 print(cnt)
n, k = map(int, input().split()) a = [int(s) for s in input().split()] for i in range(k, n): if a[i] > a[i - k]: print('Yes') else: print('No')
0
null
48,436,243,502,012
237
102
def gcd(a,b): while a%b : a,b=b,a%b return b def lcm(a,b): return a*b/gcd(a,b) while True : try: a,b = map(int,raw_input().split()) a,b = max(a,b), min(a,b) print "%d" % gcd(a,b), print "%d" % lcm(a,b) except EOFError: break
while True: try: a, b = map(int, input().split(" ")) if a < b: key = a a = b b = key A = a B = b while a % b != 0: key = a % b a = b b = key key = int(A * B / b) print(b, key) except: break
1
613,730,248
null
5
5
n=int(input()) s=input() num=n for i in range(1,n): if s[i-1]==s[i]: num-=1 print(num)
x = input() if x == "1": print(0) else: print(1)
0
null
86,878,418,025,318
293
76
X, N = map(int, input().split()) p = list(map(int, input().split())) ans = None diff = 1000 if X not in p: ans = X else: for i in range(-1, max(max(p), X)+2): if i in p:continue if abs(X - i) < diff: diff = abs(X - i) ans = i print(ans)
x, n = list(map(int, input().split())) q = list(map(int, input().split())) p = [i for i in range(0, 102) if i not in q] for i in range(len(p)): if p[i] < x: continue # p[i] >= x break if p[i] == x: print(p[i]) else: if p[i] - x < x - p[i - 1]: print(p[i]) else: print(p[i - 1])
1
14,143,615,122,650
null
128
128
n, m, k = map(int, input().split()) MOD = 998244353 ans = 0 c = 1 for i in range(k + 1): ans = (ans + m * pow(m - 1, n - i - 1, MOD) * c) % MOD c = (c * (n - 1 - i) * pow(i + 1, MOD - 2, MOD)) % MOD # print(f"{ans = }, {c = }") print(ans)
# -*- coding: utf-8 -*- def main(): import sys input = sys.stdin.readline numbers = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] k = int(input()) print(numbers[k - 1]) if __name__ == '__main__': main()
0
null
36,646,531,461,320
151
195
from math import ceil from bisect import bisect_right n, d, a = (int(x) for x in input().split()) xh = [] for _ in range(n): x, h = (int(x) for x in input().split()) xh.append([x, h]) xh = sorted(xh, key=lambda x: x[0]) cnt = 0 dmg = [0] * (n + 1) for i, (x, h) in enumerate(xh): dmg[i] += dmg[i - 1] h -= dmg[i] if h <= 0: continue num = ceil(h / a) dmg[i] += num * a idx = bisect_right(xh, [x + 2 * d, float('inf')]) dmg[idx] -= num * a cnt += num print(cnt)
from collections import deque import math n,d,a = map(int,input().split()) F = [] for _ in range(n): x,h = map(int,input().split()) F.append((x,h)) F.sort() total = 0 d *=2 ans = 0 q = deque([]) for x,h in F: while q and q[0][0]<x:#累積和 total -= q.popleft()[1] h-=total if h >0: tmp = math.ceil(h/a) ans += tmp damage = tmp*a total += damage q.append((x+d,damage)) print(ans)
1
82,255,904,741,868
null
230
230
import sys import fractions from functools import reduce readline = sys.stdin.buffer.readline def main(): gcd = fractions.gcd def lcm(a, b): return a * b // gcd(a, b) N, M = map(int, readline().split()) A = list(set(map(int, readline().split()))) B = A[::] while not any(b % 2 for b in B): B = [b // 2 for b in B] if not all(b % 2 for b in B): print(0) return semi_lcm = reduce(lcm, (a // 2 for a in A)) print((M // semi_lcm + 1) // 2) return if __name__ == '__main__': main()
import sys import itertools import fractions stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) def frac2(p): return p//2 N,M=nm() A=nl() A=list(map(frac2,A)) min_bai=A[0] for i in range(1,N): min_bai=min_bai*A[i]//fractions.gcd(min_bai,A[i]) for i in range(N): if((min_bai//A[i])%2==0): print(0) sys.exit(0) tmp=M//min_bai if(tmp%2==0): tmp-=1 print((tmp+1)//2)
1
102,142,166,592,230
null
247
247
if __name__ == '__main__': W, H, x, y, r = map(int, raw_input().split()) ret = "Yes" if W < x + r or x - r < 0 or H < y + r or y - r < 0: ret = "No" print ret
x = input().split() W, H, x, y, r = int(x[0]), int(x[1]), int(x[2]), int(x[3]), int(x[4]) if 0 <= x-r and x+r <= W and 0 <= y-r and y+r <= H: print("Yes") else: print("No")
1
461,601,460,352
null
41
41
n = int(input()) a = list(map(int,input().split())); b = [0]*n for i in range(n-1): b[a[i]-1] += 1; for v in range(n): print(b[v]);
N = int(input()) A = [int(i) for i in input().split()] P = [0]*N for i in range(N-1): P[A[i]-1] += 1 for i in range(N): print(P[i])
1
32,567,768,745,772
null
169
169
n=int(input()) a=list(map(int,input().split())) tot=sum(a) v=[1] for q in a: tot-=q v.append(min(2*(v[-1]-q),tot)) if all([u>=0 for u in v]): print(sum(v)) else: print(-1)
from sys import stdin input = stdin.readline def main(): N = int(input()) if N % 2: print(0) return nz = 0 i = 1 while True: if N//(5**i)//2 > 0: nz += (N//(5**i)//2) i += 1 else: break print(nz) if(__name__ == '__main__'): main()
0
null
67,119,505,599,872
141
258
n=int(input()) print(1-(n//2)/n)
n = int(input()) ans = (n // 2 + n % 2) / n print(ans)
1
177,040,318,644,710
null
297
297
x=input() y=int(x) print(y*y*y)
def main(): N,K=map(int,input().split()) res=0 MOD=10**9+7 for i in range(K,N+2): MAX=(N+(N-i+1))*i//2 MIN=(i-1)*i//2 res+=MAX-MIN+1 res%=MOD print(res%MOD) if __name__=="__main__": main()
0
null
16,735,816,826,950
35
170
H1, M1, H2, M2, K = map(int, input().split()) s = 60 * H1 + M1 e = 60 * H2 + M2 ans = max(0, e - s - K) print(ans)
N = int(input()) i = 1 sum = 0 while True: if i%3!=0 and i%5!=0: sum +=i i+=1 if i==N+1: break print (sum)
0
null
26,693,932,424,072
139
173
# -*- coding: utf-8 -*- def main(): # 整数の入力 a = int(input()) # # スペース区切りの整数の入力 nums = list(map(int, input().split())) vilist = [] for i in range(a): vilist.append((nums[i], i)) vilist = sorted(vilist, key=lambda vi: vi[0]) # dp[x][y]をx人を左から活性度順に並べて、y人を右から活性度順に並べた状態のスコア最大値とする dp = [] for i in range(a): dp.append([0]*(a-i)) # dp = [[0] * a for i in range(a)] # cnt = 0 # dp[i][j]を考える for k in range(a-1): vi = vilist.pop() v = vi[0] p = vi[1] vi_z = vilist[0] vz = vi_z[0] pz = vi_z[1] for i in range(k + 2): # cnt += 1 j = k - i + 1 # if i == 0 and j == 0: # continue # 最後の値は場所が特定できるのでそのまま計算させる if k == a - 2: if j == 0: dp[i][0] = dp[i-1][0] + v * abs(p - i + 1) + vz * abs(pz - i) elif i == 0: dp[0][j] = dp[0][j-1] + v * abs(a - j - p) + vz * abs(a - j - 1 - pz) else: dp[i][j] = max(dp[i-1][j] + v * abs(p - i + 1) + vz * abs(pz - i), dp[i][j-1] + v * abs(a - j - p) + vz * abs(pz - i)) else: if j == 0: dp[i][0] = dp[i-1][0] + v * abs(p - i + 1) elif i == 0: dp[0][j] = dp[0][j-1] + v * abs(a - j - p) else: dp[i][j] = max(dp[i-1][j] + v * abs(p - i + 1), dp[i][j-1] + v * abs(a - j - p)) # print(cnt) print(max([max(x) for x in dp])) main()
def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def solve(): N = read_int() A = read_ints() dp = [ [0]*(N+1) for _ in range(N+1) ] AI = sorted(((a, i) for i, a in enumerate(A)), reverse=True) for i, (a, ix) in enumerate(AI): # dp[x][y] = max(dp[x-1][y]+A[x+y]*x, dp[x][y-1]+A[x+y]*y) # add a to the left for x in range(i+2): y = i+1-x if y > 0: dp[x][y] = max(dp[x][y], dp[x][y-1]+a*abs(N-y-ix)) if x > 0: dp[x][y] = max(dp[x][y], dp[x-1][y]+a*abs(ix-x+1)) return max(dp[i][N-i] for i in range(N+1)) if __name__ == '__main__': print(solve())
1
33,578,229,653,500
null
171
171
def f_strivore(MOD=10**9 + 7): K = int(input()) S = input() length = len(S) class Combination(object): """素数 mod に対する二項係数の計算""" __slots__ = ['mod', 'fact', 'factinv'] def __init__(self, max_val_arg: int = 10**6, mod: int = 10**9 + 7): fac, inv = [1], [] fac_append, inv_append = fac.append, inv.append for i in range(1, max_val_arg + 1): fac_append(fac[-1] * i % mod) inv_append(pow(fac[-1], -1, mod)) for i in range(max_val_arg, 0, -1): inv_append((inv[-1] * i) % mod) self.mod, self.fact, self.factinv = mod, fac, inv[::-1] def combination(self, n, r): return (0 if n < 0 or r < 0 or n < r else self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.mod) comb = Combination(length + K).combination f = [1] * (K + 1) tmp = 1 for n in range(K + 1): f[n] = (comb(length + n - 1, length - 1) * tmp) % MOD tmp = (tmp * 25) % MOD g = [1] * (K + 1) for n in range(1, K + 1): g[n] = (f[n] + 26 * g[n - 1]) % MOD return g[K] print(f_strivore())
s = input() INF = float('inf') dp = [[INF,INF] for _ in range(len(s)+1)] dp[0][0]=0 dp[0][1]=1 for i in range(len(s)): dp[i+1][0] = min(dp[i][0]+int(s[i]), dp[i][1]+10-int(s[i]), dp[i][1]+int(s[i])+1) dp[i+1][1] = min(dp[i][0]+int(s[i])+1,dp[i][1]+10-int(s[i])-1) print(dp[-1][0])
0
null
42,080,641,202,710
124
219
import sys import time import math def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ A, B = map(int, input().split()) print(A*B // math.gcd(A,B)) # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
n = int(input()) maximum_profit = -10**9 r0 = int(input()) r_min = r0 for i in range(1, n): r1 = int(input()) if r0 < r_min: r_min = r0 profit = r1 - r_min if profit > maximum_profit: maximum_profit = profit r0 = r1 print(maximum_profit)
0
null
56,505,530,378,310
256
13
def main(): s = str(input()) dic = {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1} print(dic.get(s)) main()
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n, k = map(int, readline().split()) p = list(map(int, readline().split())) tmp = [(i+1)/2 for i in p] cs = list(np.cumsum(tmp)) if n == k: print(cs[-1]) exit() ans = 0 for i in range(n - k): ans = max(ans, cs[i + k] - cs[i]) print(ans)
0
null
104,181,488,153,870
270
223
N = int(raw_input()) A = map(int, raw_input().split()) def bubbleSort(A, N): count = 0 flag = 1 while flag: flag = 0 for i in range(N-1, 0, -1): if A[i] < A[i-1]: temp = A[i] A[i] = A[i-1] A[i-1] = temp flag = 1 count += 1 return count count = bubbleSort(A, N) print " ".join(map(str, A)) print count
def bubble_sort(a,n): m=0 flag=True while(flag): flag=False for i in range(n-1,0,-1): if(a[i-1] > a[i]): tmp=a[i-1] a[i-1]=a[i] m+=1 a[i]=tmp flag=True b=list(map(str,a)) print(" ".join(b)) print(m) a=[] n=int(input()) s=input() a=list(map(int,s.split())) bubble_sort(a,n)
1
16,358,392,698
null
14
14
import math def main(): n=int(input()) print(math.ceil(n/2)/n) if __name__ == '__main__': main()
N = int(input()) ans = (N - (N//2)) / N print(ans)
1
176,771,823,856,628
null
297
297
n, m, l = map(int, input().split()) A = [] B = [] for _ in range(n): A.append(list(map(int, input().split()))) for _ in range(m): B.append(list(map(int, input().split()))) C = [[sum([A[i][k] * B[k][j] for k in range(m)]) for j in range(l)] for i in range(n)] for row in C: print(' '.join(map(str, row)))
n, m, l = map(int, input().split()) matrix_A = [list(map(int, input().split())) for _ in range(n)] matrix_B = [list(map(int, input().split())) for _ in range(m)] matrix_Bt = list(map(list, zip(*matrix_B))) for a in matrix_A: r = [] for bt in matrix_Bt: r.append(sum(x * y for (x, y) in zip(a, bt))) print(*r)
1
1,418,836,388,068
null
60
60
a, b, c = [int(i) for i in input().rstrip().split(" ")] cnt = 0 for i in range(a, b+1): if c % i == 0: cnt += 1 print(cnt)
import sys a, b, c = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ] cnt = 0 i = a while i <= b: if ( c % i ) == 0: cnt += 1 i += 1 print( "{}".format( cnt ) )
1
563,441,396,588
null
44
44
mod = 10**9 + 7 K = int(input()) S = input() n = len(S) tmp = pow(26, K, mod) waru = pow(26, -1, mod) ans = tmp for i in range(1, K+1): tmp = (tmp * 25 * waru)%mod tmp = (tmp * (i + n -1) * pow(i, -1, mod))%mod ans = (ans+tmp)%mod print(ans%mod)
import sys input = sys.stdin.readline import math cos60 = math.cos(math.radians(60)) sin60 = math.sin(math.radians(60)) n = int(input()) def koch(d, p, q):#p,qはリストでp[0]がx座標、p[1]がy座標 if d == 0: return s=[0,0] t=[0,0] u=[0,0] s[0] = (2 * p[0] + q[0]) / 3 s[1] = (2 * p[1] + q[1]) / 3 t[0] = (p[0] + 2 * q[0]) / 3 t[1] = (p[1] + 2 * q[1]) / 3 u[0] = (t[0] - s[0]) * cos60 - (t[1] - s[1]) * sin60 + s[0] u[1] = (t[0] - s[0]) * sin60 + (t[1] - s[1]) * cos60 + s[1] koch(d-1, p, s) print(s[0], s[1]) koch(d-1, s, u) print(u[0], u[1]) koch(d-1, u, t) print(t[0], t[1]) koch(d-1, t, q) a = [0, 0] b = [100, 0] print(a[0], a[1]) koch(n, a, b) print(b[0], b[1])
0
null
6,511,375,720,838
124
27
# coding=utf-8 from math import floor, ceil, sqrt, factorial, log, gcd from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heappushpop, heapify import copy import sys INF = float('inf') mod = 10**9+7 sys.setrecursionlimit(10 ** 6) def lcm(a, b): return a * b / gcd(a, b) # 1 2 3 # a, b, c = LI() def LI(): return list(map(int, sys.stdin.buffer.readline().split())) # a = I() def I(): return int(sys.stdin.buffer.readline()) # abc def # a, b = LS() def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() # a = S() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') # 2 # 1 # 2 # [1, 2] def IR(n): return [I() for i in range(n)] # 2 # 1 2 3 # 4 5 6 # [[1,2,3], [4,5,6]] def LIR(n): return [LI() for i in range(n)] # 2 # abc # def # [abc, def] def SR(n): return [S() for i in range(n)] # 2 # abc def # ghi jkl # [[abc,def], [ghi,jkl]] def LSR(n): return [LS() for i in range(n)] # 2 # abcd # efgh # [[a,b,c,d], [e,f,g,h]] def SRL(n): return [list(S()) for i in range(n)] h, w = LI() s = SRL(h) ans = [] for i in range(h): for j in range(w): if s[i][j] == "#": continue v = [[-1] * w for _ in range(h)] q = deque() q.append((i, j)) v[i][j] = 1 goal = tuple() while q: r, c = q.popleft() for x, y in ((1, 0), (-1, 0), (0, -1), (0, 1)): if r + x < 0 or r + x > h - 1 or c + y < 0 or c + y > w - 1 or s[r + x][c + y] == "#" or v[r + x][c + y] > 0: continue v[r + x][c + y] = v[r][c] + 1 q.append((r + x, c + y)) ans.append(max(chain.from_iterable(v)) - 1) print(max(ans))
# -*- coding: utf-8 -*- import sys from collections import deque, defaultdict from math import sqrt, factorial, gcd, ceil, atan, pi 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, bisect_right from functools import lru_cache, reduce MOD = int(1e9)+7 INF = float('inf') def solve(): n, m = [int(x) for x in input().split()] a = [] starts = [] for i in range(n): a.append(input()) for j in range(m): if a[i][j] == '.': starts.append((i, j)) def bfs(v): q = deque([(v, 0)]) mx = 0 mv = v w = defaultdict(int) w[v] = 1 while q: v, d = q.popleft() if d > mx: mv = v mx = d i, j = v for x, y in ((0, 1), (0, -1), (1, 0), (-1, 0)): if 0 <= i + x < n and 0 <= j + y < m and not w[(i+x,j+y)] and a[i+x][j+y] == '.': w[(i+x,j+y)] = 1 q.append(((i+x, j+y), d + 1)) return mx, mv ans = 0 for start in starts: _, start = bfs(start) cur, start = bfs(start) ans = max(ans, cur) print(ans) t = 1 # t = int(input()) for case in range(1,t+1): ans = solve() """ 1 4 -1 1 1 -1 """
1
94,836,585,003,870
null
241
241
#!usr/bin/env pypy3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) def main(): N, K = LI() A = LI() for _ in range(K): B = [0]*(N+1) for i in range(N): l = max(i - A[i], 0) r = min(A[i] + i + 1, N) B[l] += 1 B[r] -= 1 for i in range(N): B[i+1] += B[i] if A == B: break A = B print(*A[:-1], sep=" ") main()
a= list(map(int,input().split())) N = a[0] K = a[1] a = [0]*K mod = 10**9+7 for x in range(K,0,-1): a[x-1] = pow(K//x, N,mod) for t in range(2,K//x+1): a[x-1] -= a[t*x-1] s = 0 for i in range(K): s += (i+1)*a[i] ans = s%mod print(ans)
0
null
26,297,795,705,510
132
176
A,B,M=map(int,input().split()) aa=list(map(int,input().split())) bb=list(map(int,input().split())) XC=[] for i in range(M): XC.append(list(map(int,input().split()))) ans=min(aa)+min(bb) for i in range(M): ans=min(ans,aa[XC[i][0]-1]+bb[XC[i][1]-1]-XC[i][2]) print(ans)
d=input().split() s={'N':"152304",'W':"215043",'E':"310542",'S':"402351"} for o in input(): d=[d[int(i)]for i in s[o]] print(d[0])
0
null
27,201,993,530,670
200
33
N, A, B = [int(i) for i in input().split()] if (B-A) % 2 == 0: print((B-A)//2) else: x = min(A-1, N-B) print((B-A-1)//2+x+1)
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print('\n'.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) n,a,b = readints() if (b-a)%2==0: print((b-a)//2) else: print(min(n-b+(b-a)//2+1,a-1+(b-a)//2+1))
1
108,828,177,548,032
null
253
253
n=int(input()) m=1000000007 print(((pow(10,n,m)-2*pow(9,n,m)+pow(8,n,m))+m)%m)
n=int(input()) m=10**9+7 print((pow(10,n,m)-pow(9,n,m)*2+pow(8,n,m))%m if n!=1 else 0)
1
3,155,013,433,180
null
78
78
N = int(input()) A = [int(x) for x in input().split()] S = [0] * (N+1) #累積和用のリスト s = 0 CONST = 10**9+7 #前準備として累積和を計算 for i in range(N): S[i+1] = S[i] + A[i] #積の総和を計算 for i in range(N-1): s += A[i] * ((S[N] - S[i+1]) % CONST) s %= CONST print(s)
N = int(input()) As = list(map(int, input().split())) sum = 0 for i in range(N): sum += As[i] sum %= 10**9+7 ans = 0 for i in range(N): sum -= As[i] ans += As[i]*sum ans %= 10**9+7 print(ans)
1
3,802,782,681,504
null
83
83
def resolve(): X, Y = input().split() ans = 0 if X == "3": ans += 100000 elif X == "2": ans += 200000 elif X == "1": ans += 300000 else: ans += 0 if Y == "3": ans += 100000 elif Y == "2": ans += 200000 elif Y == "1": ans += 300000 else: ans += 0 if X == "1" and Y == "1": ans += 400000 else: ans += 0 print(ans) resolve()
k = int(input()) for i in range(k):print("ACL",end="")
0
null
71,590,216,488,322
275
69