code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
""" 時間がかかる料理は、食べるとしたら最後に食べるのがベスト。 逆にいうと、その料理を食べるかどうかを検討する段階ではほかの料理は食べるかどうかの検討は終わっている状態。 なので、食べるのにかかる時間でソートしてナップサックすればよい。 """ N,T = map(int,input().split()) AB = [list(map(int,input().split())) for _ in range(N)] dp = [0]*(T) AB.sort() ans = 0 for i in range(N): a,b = AB[i] ans = max(ans,dp[-1]+b) for j in range(T-1,-1,-1): if j-a >= 0: dp[j] = max(dp[j],dp[j-a]+b) print(ans)
N,M = map(int,input().split()) S = list(map(int,input())) S.reverse() #後ろから貪欲に a = 0 #合計何マス進んだか A = [] #何マスずつ進んでいるか while a < N: if N-a <= M: A.append(N-a) a = N else: for i in range(M,0,-1): if S[a+i] == 0: A.append(i) a += i break else: print(-1) exit() A.reverse() print(*A)
0
null
145,043,833,461,420
282
274
n = int(input()) s = input() #print(s) tot = s.count('R') * s.count('G') * s.count('B') #print(tot) for i in range(n): for d in range(1,n): j = i+d k = j+d if k > n-1: break if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]: tot -= 1 print(tot)
N = int(input()) S = list(input()) R = [] G = [] B = [0 for _ in range(N)] b_cnt = 0 for i in range(N): if S[i] == 'R': R.append(i) elif S[i] == 'G': G.append(i) else: B[i] = 1 b_cnt += 1 answer = 0 for r in R: for g in G: answer += b_cnt if (g-r)%2 == 0 and B[(r+g)//2] == 1: answer -= 1 if 0 <= 2*g-r < N and B[2*g-r] == 1: answer -= 1 if 0 <= 2*r-g < N and B[2*r-g] == 1: answer -= 1 print(answer)
1
36,225,531,355,968
null
175
175
n,m = map(int, input().split()) print("Yes") if n-m==0 else print("No")
A, B = map(int, input().split()) if A == B: print('Yes') else: print('No')
1
83,127,637,798,422
null
231
231
import sys from collections import defaultdict from functools import lru_cache read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 P = 2 ** 61 - 1 N = int(readline()) m = map(int, read().split()) A, B = zip(*zip(m, m)) pow2 = [1] * (N + 10) for n in range(1, N + 10): pow2[n] = pow2[n - 1] * 2 % MOD @lru_cache(None) def inv_mod(a): b = P u, v = 1, 0 while a: t = b // a a, b = b - t * a, a u, v = v - t * u, u if b < 0: v = -v return v % P def to_key(a, b): if a == 0: return -1 x = inv_mod(a) * b % P return x def pair_key(key): if key == -1: return 0 if key == 0: return -1 return P - inv_mod(key) counter = defaultdict(int) origin = 0 for a, b in zip(A, B): if a == b == 0: origin += 1 continue key = to_key(a, b) counter[key] += 1 answer = origin k = 1 for key, cnt in counter.items(): key1 = pair_key(key) if key1 not in counter: k *= pow(2, cnt, MOD) elif key < key1: x, y = cnt, counter[key1] k *= pow(2, x, MOD) + pow(2, y, MOD) - 1 k %= MOD answer += k - 1 answer %= MOD print(answer)
#6回目、2020-0612 #2重ループ +O(1) #場合分けを近道と通常のみ(絶対値を使う) #初期入力 N, x, y = map(int, input().split()) normal =0 short =0 ans ={i:0 for i in range(1,N)} for i in range(1,N): for j in range(i+1,N+1): normal =j -i short =abs(x-i) +1 +abs(j-y) dist =min(normal,short) ans[dist] +=1 #答え出力 for i in range(1,N): print(ans[i])
0
null
32,473,891,155,452
146
187
while True: H,W = list(map(int, input().split())) if (H == 0 and W == 0): break else: for n in range(H): s = "" for m in range(W): s += "#" print(s) print("")
n = input() print(n.replace(n,'x'*len(n)))
0
null
36,935,779,866,110
49
221
import collections def Z(): return int(input()) def ZZ(): return [int(_) for _ in input().split()] def main(): H, W, K = ZZ() C = [input() for _ in range(H)] atode = collections.deque() last = -1 cakeId = 0 output = [[0] * W for _ in range(H)] for i in range(H): if not '#' in C[i]: atode.append(i) continue ichigo = [] last = i for j in range(W): if C[i][j] == '#': ichigo.append(j) itr = 0 for j in ichigo: cakeId += 1 while itr <= j: output[i][itr] = cakeId itr += 1 while itr < W: output[i][itr] = cakeId itr += 1 while atode: j = atode.popleft() for k in range(W): output[j][k] = output[i][k] while atode: j = atode.popleft() for k in range(W): output[j][k] = output[last][k] for i in range(H): print(*output[i]) return if __name__ == '__main__': main()
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = readline().decode().rstrip() if '7' in N: print('Yes') else: print('No')
0
null
89,255,981,340,732
277
172
def inputInline(): N = int(input()) numbers = list(map(int, input().split(" "))) return numbers def insertionSort(numbers): N = len(numbers) for i in range(1, N): print(" ".join(list(map(str, numbers)))) j = i - 1 temp = numbers[i] while True: if j == -1: numbers[0] = temp break if temp < numbers[j]: numbers[j + 1] = numbers[j] j -= 1 else: numbers[j + 1] = temp break return " ".join(list(map(str, numbers))) print(insertionSort(inputInline()))
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) yes = True if v <= w: yes = False elif abs(b - a) / (v - w) > t: yes = False if yes: print("YES") else: print("NO")
0
null
7,584,831,396,032
10
131
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002 """ while True: try: a = raw_input().split() #print a c = 0 for b in a: c = c + int(b) print len(str(c)) except EOFError: break
from sys import stdin for line in stdin: a,b = line.split(" ") c = int(a)+int(b) print(len(str(c)))
1
83,129,820
null
3
3
N = int(input()) X = list(map(int, input().split())) MOD = 10 ** 9 + 7 ans = 0 for b in range(61): ctr = [0, 0] for i in range(N): ctr[X[i] >> b & 1] += 1 ans += (1 << b) * ctr[0] * ctr[1] ans %= MOD print(ans)
n = int(input()) a = list(map(int, input().split())) mod = 10**9 + 7 ans = 0 for i in range(60): cnt = 0 digit = 1 << i for j in a: if digit & j: cnt += 1 ans += digit*cnt*(n - cnt)%mod print(ans%mod)
1
122,512,518,277,920
null
263
263
pai = 3.141592653589793 r = float(input()) s = pai * r ** 2 l = 2 * pai * r print(s, l)
import bisect N=int(input()) L=list(map(int,input().split())) L=sorted(L) ans=0 for i in range(N): for j in range(i+1,N): k=bisect.bisect_left(L,L[i]+L[j]) ans+=k-j-1 print(ans)
0
null
86,064,604,973,348
46
294
from collections import defaultdict N, X, Y = map(int, input().split()) ctr = defaultdict(int) for i in range(1, N + 1): for j in range(i + 1, N + 1): d = min(j - i, abs(i - X) + 1 + abs(j - Y)) ctr[d] += 1 for i in range(1, N): print(ctr[i])
a, b = map(int, input().split()) if a <= 9 and b <= 9: print(a * b) else: print("-1")
0
null
100,775,591,012,096
187
286
import sys l=[0]*26 for h in sys.stdin: for i in h: k=ord(i.lower()) if 96<k<123:l[k-97]+=1 for i in range(26):print chr(i+97),':',l[i]
from itertools import combinations N = int(input()) nums = list(map(int,input().split())) tcount = 0 numset = set(nums) comb = combinations(numset,3) for i in list(comb): a = i[0] b = i[1] c = i[2] if(a+b>c and b+c>a and a+c>b): tcount += nums.count(a)*nums.count(b)*nums.count(c) print(tcount)
0
null
3,390,273,949,888
63
91
A, B, N = map(int, input().split()) if N >= B - 1: print(int(A * (B - 1) / B)) else: print(int(A * N / B))
a, b = map(int, raw_input().split()) print '%d %d %f' % (a / b, a % b, 1.0 * a / b)
0
null
14,326,370,141,774
161
45
a=input().rstrip() y='ABC' if(a==y): y='ARC' print(y)
def answer(n: int, k: int) -> int: digits = 0 while 0 < n: n //= k digits += 1 return digits def main(): n, k = map(int, input().split()) print(answer(n, k)) if __name__ == '__main__': main()
0
null
43,975,550,708,700
153
212
n = int(raw_input()) i = 1 print "", for i in range(1,n+1): x = i if x%3 == 0: print "%d" %i , elif x%10 == 3: print "%d" %i , else: while x != 0: x = x/10 if x % 10 == 3: print "%d" %i , break
def main(): N = int(input()) mod = 10 ** 9 + 7 mod_1 = 1 mod_2 = 1 mod_3 = 1 for _ in range(N): mod_1 = (mod_1 * 10) % mod mod_2 = (mod_2 * 9) % mod mod_3 = (mod_3 * 8) % mod v = (mod_1 - 2 * mod_2 + mod_3) % mod print(v) if __name__ == '__main__': main()
0
null
2,070,874,406,216
52
78
D=int(input()) c=list(map(int, input().split())) s = [list(map(int, input().split())) for i in range(D)] t= [int(input()) for i in range(D)] v=0 LD=[0]*26 for i in range(D): v+=s[i][t[i]-1] LD[t[i]-1]=i+1 for j in range(26): v-=c[j]*(i+1-LD[j]) print(v)
from itertools import product n,m,x = map(int, input().split()) al = [] cl = [] for _ in range(n): row = list(map(int, input().split())) cl.append(row[0]) al.append(row[1:]) ans = 10**9 bit = 2 ite = list(product(range(bit),repeat=n)) for pattern in ite: skills = [0]*m cost = 0 for i, v in enumerate(pattern): if v == 1: curr_al = al[i] cost += cl[i] for j, a in enumerate(curr_al): skills[j] += a if min(skills) >= x: ans = min(ans,cost) if ans == 10**9: ans = -1 print(ans)
0
null
16,018,234,136,436
114
149
l= list(input().split()) a,b = map(int,input().split()) u = input() if u == l[0]: a -= 1 else: b -= 1 print(a,b)
def main(S, T): ans = len(T) for w in range(len(S)-len(T)+1): tmp = len(T) for s, t in zip(S[w:w+len(T)], T): if s == t: tmp -= 1 if tmp < ans: ans = tmp return ans if __name__ == '__main__': S = input() T = input() ans = main(S, T) print(ans)
0
null
37,730,606,757,174
220
82
n1,n2,n3 = map(int,input().split(" ")) list1 = [list(map(int,input().split(" "))) for _ in range(n1)] list2 = [list(map(int,input().split(" "))) for _ in range(n2)] mat = [[0 for _ in range(n3)] for _ in range(n1)] for i in range(n1): for j in range(n2): for k in range(n3): mat[i][k] += list1[i][j] * list2[j][k] for m in mat: print(*m)
from collections import deque n, m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] class UnionFind: def __init__(self, n): self.parent = [-1] * (n + 1) self.rank = [0] * (n + 1) def find(self, x): if self.parent[x] < 0: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.parent[x] += self.parent[y] self.parent[y] = x else: self.parent[y] += self.parent[x] self.parent[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): return self.find(x) == self.find(y) def count(self, x): return -self.parent[self.find(x)] uf = UnionFind(n) for a, b in ab: uf.union(a, b) ans = 0 for i in range(1, n + 1): ans = max(ans, uf.count(i)) print(ans)
0
null
2,741,144,990,442
60
84
import math import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") _,k = LI() a = LI() a = list(map(lambda x:x-1,a)) # 訪れる順序、indexは移動回数 route = [0] # 訪れた番号、高速検索用にhash tableを使う visited = set([0]) next = a[0] while True: if next in visited: loopStart = route.index(next) break else: route.append(next) visited.add(next) next = a[next] # print(route) # print(loopStart) beforeLoop = route[:loopStart] # print(beforeLoop) loop = route[loopStart:] # print(loop) # loop前 if k < loopStart: ans = beforeLoop[k] # loop後 else: numOfLoops,mod = divmod((k-(loopStart)),len(loop)) # print(numOfLoops,mod) ans = loop[mod] ans += 1 print(ans)
N, K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] check = [0]*N ima = 0 for i in range(K): if check[A[ima]-1] != 0: loopen = ima check[ima] = i+1 looplen = check[ima] - check[A[ima]-1] + 1 loopend = i break if i == K-1: print(A[ima]) exit() check[ima] = i+1 ima = A[ima]-1 offset = (K-(i-looplen)-1)%looplen ima = 0 for i in range(loopend-looplen+offset+1): ima = A[ima]-1 print(ima+1)
1
22,756,981,490,848
null
150
150
A,B,C,K=map(int,input().split()) print(1*min(A,K)-1*max(0,K-A-B))
A,B,C,K=map(int,input().split()) print(min(A,K)-max(0,K-A-B))
1
21,617,041,100,160
null
148
148
import sys sys.setrecursionlimit(100000000) S = int(input()) mod = 10**9+7 def dfs_memo(n): memo = [0]*(n+1) memo[3] = 1 def dfs(n): if n < 3: return 0 elif memo[n] != 0: return memo[n] memo[n] = dfs(n-1)+dfs(n-3) return memo[n] return dfs(n) if S <3: print(0) else: print(dfs_memo(S)%mod)
s=int(input()) a=[0]*(s+1) a[0]=1 mod=10**9+7 for i in range(3,s+1): a[i]=a[i-3]+a[i-1] print(a[s]%mod)
1
3,269,414,697,440
null
79
79
#!/usr/bin/env python3 import sys sys.setrecursionlimit(1000000) from collections import deque # スペース区切りの整数の入力 N, K = map(int, input().split()) #配列の入力 data = list(map(int, input().split())) data.sort() ans = 0 for i in range(K): ans += data[i] print(ans)
from math import log10 n, k = map(int, input().split()) a = list(map(int, input().split())) MOD = 10**9+7 a.sort() cnt_neg = 0 cnt_pos = 0 for i in a: if i <= 0: cnt_neg += 1 else: cnt_pos += 1 is_minus = False k_tmp = k while k_tmp > 0: if k_tmp >= 2: if cnt_neg >= 2: cnt_neg -= 2 elif cnt_pos >= 2: cnt_pos -= 2 else: is_minus = True break k_tmp -= 2 else: if cnt_pos > 0: cnt_pos -= 1 k_tmp -= 1 else: is_minus = True break k_1 = k ans1 = 1 l = 0 r = n - 1 if k_1 % 2: ans1 *= a[-1] r -= 1 k_1 -= 1 while k_1 >= 2: if a[l] * a[l+1] > a[r-1] * a[r]: ans1 *= a[l] * a[l+1] l += 2 else: ans1 *= a[r-1] * a[r] r -= 2 k_1 -= 2 ans1 %= MOD a.sort(key=abs) # print(a) ans2 = 1 for i in a[:k]: ans2 *= i ans2 %= MOD if is_minus: print(ans2) else: print(ans1)
0
null
10,413,155,708,480
120
112
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**10 def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): n, k = LI() Q = [I() for _ in range(n)] def can_stack(p): s = 0 truck_num = 1 for i in Q: if s+i<=p: s += i else: truck_num += 1 s = i return truck_num<=k ng = max(Q)-1 ok = sum(Q) while abs(ok-ng)>1: m = (ng+ok)//2 if can_stack(m): ok = m else: ng = m print(ok) # for i in range(20): # print(i, can_stack(i)) if __name__ == '__main__': resolve()
H, W = map(int, input().split()) if H == 1 or W == 1: ans = 1 else: if H % 2: if W % 2: ans = ((H // 2 + 1) * (W // 2 + 1)) + ((H // 2) * (W // 2)) else: ans = ((H // 2 + 1) + (H // 2)) * (W // 2) else: ans = H / 2 * W print(int(ans))
0
null
25,313,554,926,590
24
196
def solve(): N, M = map(int, input().split()) S = list(input())[::-1] ans_l = [] i = 0 while i < N: for j in range(M, 0, -1): if i + j > N: continue if int(S[i+j]) == 0: ans_l.append(j) i += j break if j == 1: print(-1) exit() ans_l = ans_l[::-1] print(' '.join(map(str, ans_l))) if __name__ == '__main__': solve()
from sys import stdin N,M,K = [int(x) for x in stdin.readline().rstrip().split()] mod = 998244353 maxn = 2*10**5+1 fac = [0 for _ in range(maxn)] finv = [0 for _ in range(maxn)] inv = [0 for _ in range(maxn)] fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2,maxn): fac[i] = fac[i-1] * i % mod inv[i] = mod - inv[mod%i] * (mod // i) % mod finv[i] = finv[i-1] * inv[i] % mod def combinations(n,k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n-k] % mod) % mod ans = 0 for i in range(0,K+1): tmp = 1 tmp *= M*pow(M-1,N-i-1,mod) tmp %= mod tmp *= combinations(N-1,i) tmp %= mod ans += tmp print(ans%mod)
0
null
81,167,911,980,030
274
151
N, *A = map(int, open(0).read().split()) cur = 0 for i in range(N): if A[i] == cur + 1: cur += 1 if cur == 0: print(-1) else: print(N - cur)
# AtCoder Beginner Contest 148 # D - Brick Break N=int(input()) a=list(map(int,input().split())) targetnum=1 breaknum=0 for i in range(N): if a[i]==targetnum: targetnum+=1 else:breaknum+=1 if breaknum==N: print(-1) else: print(breaknum)
1
114,391,394,965,242
null
257
257
sum = input() print sum*sum*sum
def combs_mod(n,k,mod): #nC0からnCkまで inv = [1]*(k+1) for i in range(1,k+1): inv[i] = pow(i,mod-2,mod) ans = [1]*(k+1) for i in range(1,k+1): ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod return ans def solve(): ans = 0 mod = 998244353 N, M, K = map(int, input().split()) lis = combs_mod(N-1,K,mod) for i in range(K+1): ans += M*lis[i]*pow(M-1,N-1-i,mod) ans %= mod return ans print(solve())
0
null
11,686,926,366,580
35
151
import sys import numpy as np n, k = map(int,input().split()) a = np.array(sorted(list(map(int, input().split())))) f = np.array(sorted(list(map(int, input().split())), reverse=True)) asum = a.sum() l,r = 0, 10**13 while l != r: mid = (l+r)//2 can = (asum - np.minimum(mid//f, a).sum()) <= k if can: r = mid else: l = mid +1 print(l)
H=int(input()) W=int(input()) N=int(input()) k=max(H, W) cnt=0 while k*cnt<N: cnt+=1 print(cnt)
0
null
126,815,287,568,680
290
236
import itertools H,W,K=map(int,input().split()) C=[input() for i in range(H)] ans=0 for paint_H in itertools.product([0,1], repeat=H): for paint_W in itertools.product([0,1], repeat=W): cnt=0 for i in range(H): for j in range(W): if paint_H[i]==0 and paint_W[j]==0 and C[i][j]=="#": cnt+=1 if cnt==K: ans+=1 print(ans)
def debt(x): nx = x * 105 / 100 ha = nx % 1000 nx -= ha if ha != 0: nx += 1000 return nx n = int(raw_input()) x = 100000 for i in range(0, n): x = debt(x) print x
0
null
4,452,909,128,152
110
6
while True: H, W = map(int, raw_input().split()) if (H + W) == 0: break printW = ['#'] * W if W != 0: for h in range(H): print ''.join(printW) print ""
#AGC043-A h,w = map(int,input().split()) grid = [input() for _ in range(h)] dp = [[1000]*w for _ in range(h)] dp[0][0] = 1 if grid[0][0] == "#" else 0 #進む前の相対位置 d = [(-1, 0), (0, -1)] for i in range(h): for j in range(w): if i == 0 and j == 0: pass else: tmp = 1000 for k in d: bx,by = j+k[0],i+k[1] if 0 <= bx <w and 0 <= by < h: if grid[i][j] == '#' and grid[by][bx] == '.': tmp = dp[by][bx] + 1 else: tmp = dp[by][bx] dp[i][j] = min(dp[i][j],tmp) print(dp[-1][-1])
0
null
24,940,613,751,252
49
194
class Com: def __init__(self, MAX = 1000000, MOD = 1000000007): self.MAX = MAX self.MOD = MOD self._fac = [0]*MAX self._finv = [0]*MAX self._inv = [0]*MAX self._fac[0], self._fac[1] = 1, 1 self._finv[0], self._finv[1] = 1, 1 self._inv[1] = 1 for i in range(2,self.MAX): self._fac[i] = self._fac[i - 1] * i % self.MOD self._inv[i] = self.MOD - self._inv[self.MOD%i] * (self.MOD // i) % self.MOD self._finv[i] = self._finv[i - 1] * self._inv[i] % self.MOD def com(self, n, k): if (n < k): return 0 if (n < 0 or k < 0): return 0 return self._fac[n] * (self._finv[k] * self._finv[n - k] % self.MOD) % self.MOD a,b = list(map(int,input().split())) if 2*a-b >= 0 and (2*a-b)%3 == 0 and a-2*((2*a-b)//3) >= 0: x = (2*a-b)//3 y = a-2*x com = Com() print(com.com(x+y, x)) exit() a,b = b,a if 2*a-b >= 0 and (2*a-b)%3 == 0 and a-2*((2*a-b)//3) >= 0: x = (2*a-b)//3 y = a-2*x com = Com() print(com.com(x+y, x)) exit() print(0)
import numpy as np n,m,k = list(map(int, input().split())) a_list = np.array(input().split()).astype(int) b_list = np.array(input().split()).astype(int) a_sum =[0] b_sum=[0] for i in range(n): a_sum.append(a_sum[-1]+ a_list[i]) for i in range(m): b_sum.append(b_sum[-1] + b_list[i]) #print(a_sum, b_sum) total = 0 num = m for i in range(n+1): if a_sum[i] > k: break while (k - a_sum[i]) < b_sum[num]: num -=1 #print(i, num) if num == -1: break total = max(i+num, total) print(total)
0
null
80,554,049,311,370
281
117
a = list(map(int, input().split())) print(a[1] + (10 - min(a[0] , 10)) * 100)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() D = [len(set(LIST()))==1 for _ in range(N)] for i in range(N): if sum(D[i:i+3]) == 3: print("Yes") break else: print("No")
0
null
32,962,208,849,670
211
72
x = map(int, input().replace(' ','')) x = list(x) for idx in range(len(x)): if x[idx] == 0: print(idx + 1) break
n = int(input()) s = list(input()) c = 0 for i in range(1000) : num_1 = i // 100 num_2 = (i - num_1*100) // 10 num_3 = (i - num_1*100 - num_2*10) % 100 if str(num_1) not in s : continue if str(num_2) not in s : continue if str(num_3) not in s : continue for j in range(n-2) : if int(s[j]) == num_1 : for k in range(j+1,n-1) : if int(s[k]) == num_2 : for l in range(k+1,n) : if int(s[l]) == num_3 : c += 1 break break break print(c)
0
null
71,104,637,553,180
126
267
from collections import Counter n = int(input()) A = list(map(int, input().split())) cnt = Counter(A) ans = 0 for value in cnt.values(): ans +=int(value*(value-1)/2) for k in A: print(ans-cnt[k]+1)
a,b,c,d = map(int,input().split()) ans1 = a * c ans2 = a * d ans3 = b * c ans4 = b * d print(max(ans1,ans2,ans3,ans4))
0
null
25,424,508,680,270
192
77
import math r = float(raw_input()) print ('%.6f' % (r*r*math.pi)), print ('%.6f' % (r*2*math.pi))
import math r = float(input()) S = math.pi * r * r L = 2 * math.pi * r print("{0:.10f}".format(S),end=" ") print("{0:.10f}".format(L))
1
649,345,891,908
null
46
46
n, m, l = [int(i) for i in input().split()] A = [] B = [] C = [] for ni in range(n): A.append([int(i) for i in input().split()]) for mi in range(m): B.append([int(i) for i in input().split()]) for i in range(n): C.append([]) for j in range(l): C[i].append(0) for k in range(m): C[i][j] += A[i][k] * B[k][j] for li in range(n): print(" ".join([str(s) for s in C[li]]))
# -*- coding: utf-8 -*- n, m, l = list(map(int, input().split())) a = [] b = [] for i in range(n): a.append(list(map(int, input().split()))) for i in range(m): b.append(list(map(int, input().split()))) for i in range(n): for j in range(l): mat_sum = 0 for k in range(m): mat_sum += a[i][k] * b[k][j] if j == l - 1: print('{0}'.format(mat_sum), end='') else: print('{0} '.format(mat_sum), end='') print()
1
1,437,203,048,450
null
60
60
N = int(input()) As = list(map(int, input().split())) ans = 0 tall = int(As[0]) for A in As: if(tall > A): ans += tall - A else: tall = A print(ans)
N,X,Y = map(int,input().split()) from collections import deque INF = 1000000000 ans = [0]*(N-1) def rep(sv,dist): que = deque() def push(v,d): if (dist[v] != INF): return dist[v] = d que.append(v) push(sv,0) while(que): v = que.popleft() d = dist[v] if v-1 >= 0: push(v-1, d+1) if v+1 < N: push(v+1, d+1) if v == X-1: push(Y-1, d+1) #逆に気を付ける if v == Y-1: push(X-1, d+1) for i in range(N): dist = [INF]*N rep(i,dist) # print(dist) for d in dist: if d-1 == -1:continue ans[d-1] += 1 for an in ans: print(an//2) # print(ans)
0
null
24,354,931,986,332
88
187
N = int(input()) def sum(n): return (n + 1) * n // 2 print(sum(N) - sum(N // 3) * 3 - sum(N // 5) * 5 + sum(N // 15) * 15)
def main(): S = input() N = len(S) S1 = S[0:(N - 1) // 2] S2 = S[(N + 3) // 2 - 1:] if S == S[::-1] and S1 == S1[::-1] and S2 == S2[::-1]: print('Yes') else: print('No') if __name__ == '__main__': main()
0
null
40,373,321,385,792
173
190
import math import time from collections import defaultdict, deque from sys import stdin, stdout from bisect import bisect_left, bisect_right s,w=map(int,stdin.readline().split()) if(w>=s): print("unsafe") else: print("safe")
import itertools h, w, k = map(int, input().split()) a = [] for i in range(h): s = input() a.append(s) s = [[0 for i in range(w)] for i in range(h)] ans = h+w for grid in itertools.product([0,1], repeat=h-1): ary = [[0]] for i in range(h-1): if grid[i] == 1: ary.append([i+1]) else: ary[-1].append(i+1) # print (grid, ary) wk = 0 for i in grid: if i == 1: wk += 1 # print (wk) cnt = [0] * len(ary) for j in range(w): for ii, g in enumerate(ary): for b in g: if a[b][j] == '1': cnt[ii] += 1 if any(W > k for W in cnt): wk += 1 cnt = [0] * len(ary) for ii, g in enumerate(ary): for jj in g: if a[jj][j] == '1': cnt[ii] += 1 if any(W > k for W in cnt): wk = h+w break ans = min(ans, wk) print (ans)
0
null
38,934,720,429,888
163
193
import math a,b,x = (int(a) for a in input().split()) if 2 * x <= a**2 * b : t = b s = 2 * x / (a*b) r = s / t print(90 - math.degrees(math.atan(r))) else : t = a s = 2 * b - 2 * x / (a ** 2) r = s / t print(math.degrees(math.atan(r)))
import math a, b, x = map(int, input().split(' ')) x = x / a if x > a * b / 2: print(math.atan2((a * b - x) * 2, a ** 2) * 180 / math.pi) else: print(math.atan2(b ** 2, x * 2) * 180 / math.pi)
1
162,934,239,558,578
null
289
289
import sys n = int(input()) for i in range(1,10): for j in range(1,10): if i * j == n : print('Yes') sys.exit() print('No')
def main(): import sys input = sys.stdin.readline from bisect import bisect_left, insort_left N = int(input()) S = list(input()) Q = int(input()) dic = {chr(i): [] for i in range(ord('a'), ord('z')+1)} for i in range(N): dic[S[i]].append(i) for _ in range(Q): query, a, c = input().split() if query == "1": i = int(a)-1 if S[i] == c: continue ind = bisect_left(dic[S[i]], i) dic[S[i]].pop(ind) insort_left(dic[c], i) S[i] = c else: l, r = int(a)-1, int(c)-1 ans = 0 for inds in dic.values(): if inds and l <= inds[-1] and inds[bisect_left(inds, l)] <= r: ans += 1 print(ans) if __name__ == '__main__': main()
0
null
110,999,449,192,700
287
210
h = int(input()) w = int(input()) n = int(input()) m = max(w,h) if n > n //m * m: ans = n // m + 1 else: ans = n // m print(ans)
from math import ceil H,W,N = map(int, open(0).read().split()) m = max(H,W) print(ceil(N/m))
1
88,833,036,117,562
null
236
236
while True: H,W = [int(x) for x in input().split()] if (H,W)==(0,0): break for i in range(H): if i==0 or i==H-1: print("#"*W) else: print("#" + "."*(W-2) + "#") print("")
while True: hw = [int(x) for x in input().split()] h, w = hw[0], hw[1] if h == 0 and w == 0: break for hh in range(h): for ww in range(w): if hh == 0 or hh == h - 1 or ww == 0 or ww == w - 1: print('#', end = '') else: print('.', end = '') print('') print('')
1
800,468,280,582
null
50
50
import sys sys.setrecursionlimit(300000) def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) MOD = 998244353 INF = float('inf') N, A = MI() a = [0, *list(map(int, input().split()))] # dp[i][j] := i番目までの数字を使って総和をjとする場合の数 # dp[i][j] = dp[i - 1][j - a[i]] + dp[i - 1][j] dp = [[0] * (A + 1) for _ in range(N + 1)] dp[0][0] = 1 for i in range(1, N + 1): for j in range(A + 1): if j - a[i] < 0: # j - a[i] が負の数になってしまう時はa[i]を使用することはできない dp[i][j] = 2 * dp[i - 1][j] % MOD continue dp[i][j] = (dp[i - 1][j - a[i]] + 2 * dp[i - 1][j]) % MOD print(dp[N][A])
import sys num = int(sys.stdin.readline()) print(num**3)
0
null
9,057,667,280,220
138
35
n = int(input()) product_list = list() for i in range(1, 10): for j in range(1, 10): product_list.append(i * j) if n in product_list: print('Yes') else: print('No')
N, X, T = map(int,input().split()) i = 0 while X * i < N: i += 1 print(T * i)
0
null
82,174,406,069,500
287
86
a = map(int, raw_input().split()) while a != [0,0]: print '#' * a[1] for i in xrange(a[0]-2): print '#' + '.' * (a[1] - 2) + '#' print '#' * a[1] a = map(int, raw_input().split()) print ""
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def solve(N: int, K: int, H: "List[int]"): return sum(sorted(H)[:-K]) if K != 0 else sum(H) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int H = [int(next(tokens)) for _ in range(N)] # type: "List[int]" print(f'{solve(N, K, H)}') if __name__ == '__main__': main()
0
null
39,977,113,493,042
50
227
num = list(map(int,input().split())) print("%d %d %f" %(num[0]/num[1],num[0]%num[1],num[0]/num[1] ))
n = int(input()) r3 = 3 ** 0.5 A = (0.0, 0.0) B = (100.0, 0.0) def koch(n, A, B): if n == 0: return C1 = ((2 * A[0] + B[0]) / 3, (2 * A[1] + B[1]) / 3) C3 = ((A[0] + 2 * B[0]) / 3, (A[1] + 2 * B[1]) / 3) X, Y = C3[0] - C1[0], C3[1] - C1[1] C2 = (C1[0] + (X - Y * r3) / 2, C1[1] + (X * r3 + Y) / 2) koch(n - 1, A, C1) print("{:.5f} {:.5f}".format(C1[0], C1[1])) koch(n - 1, C1, C2) print("{:.5f} {:.5f}".format(C2[0], C2[1])) koch(n - 1, C2, C3) print("{:.5f} {:.5f}".format(C3[0], C3[1])) koch(n - 1, C3, B) print("{:.5f} {:.5f}".format(A[0], A[1])) koch(n, A, B) print("{:.5f} {:.5f}".format(B[0], B[1]))
0
null
363,683,845,030
45
27
#!/usr/bin/env python import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**6) INF = float("inf") def main(): N = int(input()) S = input().decode().rstrip() if N%2==0 and S[0:N//2]==S[N//2:]: print("Yes") else: print("No") if __name__ == "__main__": main()
import bisect n=int(input()) s=list(input()) #アルファベットの各文字に対してからのリストを持つ辞書 alpha={chr(i):[] for i in range(97,123)} #alpha[c]で各文字ごとに出現場所をソートして保管 for i,c in enumerate(s): bisect.insort(alpha[c],i+1) for i in range(int(input())): p,q,r=input().split() if p=='1': q=int(q) b=s[q-1] if b!=r: alpha[b].pop(bisect.bisect_left(alpha[b],q)) bisect.insort(alpha[r],q) s[q-1]=r else: count=0 for l in alpha.values(): pos=bisect.bisect_left(l,int(q)) if pos<len(l) and l[pos]<=int(r): count+=1 print(count)
0
null
104,486,700,774,180
279
210
s = input() S1 = list(s) T = list(input()) cnt =0 for i in range(len(s)): if S1[i] != T[i]: cnt+=1 print(cnt)
#!/usr/bin/env python3 #xy = [map(int, input().split()) for _ in range(5)] #x, y = zip(*xy) def main(): nd = list(map(int, input().split())) ans = 0 for i in range(nd[0]): xy = list(map(int, input().split())) if xy[0] * xy[0] + xy[1] * xy[1] <= nd[1] * nd[1]: ans += 1 print(ans) if __name__ == '__main__': main()
0
null
8,274,061,148,650
116
96
n, m, l = map(int, input().split()) alst = [] for i in range(n): a = list(map(int, input().split())) alst.append(a) blst = [] for i in range(m): b = list(map(int, input().split())) blst.append(b) for i in range(n): clst = [] for j in range(l): c = 0 for k in range(m): c += alst[i][k]*blst[k][j] clst.append(c) print(*clst)
#!usr/bin/env python3 import sys def string_to_list_spliter(): n = sys.stdin.readline() lst = [int(i) for i in sys.stdin.readline().split()] return lst def main(): lst = string_to_list_spliter() print(min(lst), max(lst), sum(lst)) if __name__ == '__main__': main()
0
null
1,083,190,326,988
60
48
N = int(input()) C = input() r_n = 0 ans = 0 for c in C: if c == 'R': r_n += 1 for i in range(r_n): if C[i] == 'W': ans += 1 print(ans)
def main(): N = int(input()) C = list(input()) C_ = sorted(C) wr = rw = 0 for i in range(len(C_)): if C[i] != C_[i]: if C[i] == "R" and C_[i] == "W": rw += 1 else: wr += 1 print(max(wr, rw)) if __name__ == "__main__": main()
1
6,356,942,089,212
null
98
98
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, M = map(int, readline().split()) ans = (N + M) * (N + M - 1) // 2 - N * M print(ans) return if __name__ == '__main__': main()
import math n, m = map(int, input().split()) def comb(n, r): if n == 0 or n == 1: return 0 return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) a = comb(n, 2) b = comb(m, 2) print(a+b)
1
45,580,997,115,392
null
189
189
a = input() b = input() c = 0 d = 0 for x in a: if x != b[c]: d += 1 c += 1 print(d)
s = input() t = input() counter = 0 for index, character in enumerate(s): if t[index] != character: counter += 1 print(counter)
1
10,598,846,863,458
null
116
116
def main(): n, m = map(int, input().split()) a_lst = list(map(int, input().split())) total = sum(a_lst) cnt = 0 for a in a_lst: if a * 4 * m >= total: cnt += 1 if cnt >= m: ans = "Yes" else: ans = "No" print(ans) if __name__ == "__main__": main()
count = 0 n, m = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): if a[i] >= sum(a)/4/m: count += 1 if count >= m: print("Yes") else: print("No")
1
38,579,605,499,006
null
179
179
# ALDS_2_B. # バブルソート。 from math import sqrt, floor def intinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def show(a): # 配列の中身を出力する。 _str = "" for i in range(len(a) - 1): _str += str(a[i]) + " " _str += str(a[len(a) - 1]) print(_str) def selection_sort(a): # 選択ソート。その番号以降の最小値を順繰りにもってくる。 # 交換回数は少ないが比較回数の関係で結局O(n^2)かかる。 count = 0 for i in range(len(a)): # a[i]からa[len(a) - 1]のうちa[j]が最小っていうjを取る。 # このときiとjが違うならカウントする。 # というかa[i]とa[j]が違う時カウントでしたね。 minj = i for j in range(i, len(a)): if a[j] < a[minj]: minj = j if a[i] > a[minj]: count += 1; a[i], a[minj] = a[minj], a[i] return count def main(): N = int(input()) A = intinput() count = selection_sort(A) show(A); print(count) if __name__ == "__main__": main()
S,W = map(int,input().split()) if S<=W: print('unsafe') else: print('safe')
0
null
14,500,809,840,618
15
163
from math import pi r = float(input()) print '%.6f %.6f'%(r**2*pi, r*2*pi)
import math class Circle: def output(self, r): print "%.6f %.6f" % (math.pi * r * r, 2.0 * math.pi * r) if __name__ == "__main__": cir = Circle() r = float(raw_input()) cir.output(r)
1
634,212,346,350
null
46
46
n, k = list(map(int, input().split())) enemy = list(map(int, input().split())) enemy = sorted(enemy, reverse=True) enemy = enemy[k:] print(sum(enemy))
n, a, b = list(map(int, input().split())) whole = n // (a + b) rest = n % (a + b) blue = whole * a if rest <= a: blue += rest else: blue += a print(blue)
0
null
67,366,158,266,244
227
202
n, x, m = map(int, input().split()) mn = min(n, m) S = set() A = [] a = x ans = 0 for i in range(mn): if a in S: break S.add(a) A.append(a) ans += a a = a*a%m if a == 0: print(ans) exit() if len(A) >= mn: print(ans) exit() st_len = 0 while st_len < len(A) and a != A[st_len]: st_len += 1 st = sum(A[:st_len]) cyc_sum = sum(A[st_len:]) cyc_len = len(A) - st_len cyc_num = (n - st_len) // cyc_len cyc = cyc_sum * cyc_num ed_len = (n - st_len) % cyc_len ed = sum(A[st_len:][:ed_len]) print(st + cyc + ed)
def f(x, m): return x * x % m def main(): N, X, M = map(int, input().split()) pre = set() pre.add(X) cnt = 1 while cnt < N: X = f(X, M) if X in pre: break cnt += 1 pre.add(X) if cnt == N: return sum(pre) ans = sum(pre) N -= cnt loop = set() loop.add(X) while cnt < N: X = f(X, M) if X in loop: break loop.add(X) left = N % len(loop) ans += sum(loop) * (N // len(loop)) for i in range(left): ans += X X = f(X, M) return ans print(main())
1
2,811,889,696,280
null
75
75
from collections import deque def main(): d = deque() for _ in range(int(input())): command = input() if command[0] == 'i': d.appendleft(command[7:]) elif command[6] == ' ': try: d.remove(command[7:]) except ValueError: pass elif len(command) == 11: d.popleft() else: d.pop() print(*d) if __name__ == '__main__': main()
class Node(object): def __init__(self, num, prv = None, next = None): self.num = num self.prv = prv self.next = next class DoublyLinkedList(object): def __init__(self): self.start = self.last = None def insert(self, num): new_element = Node(num) if self.start is None: # 空の場合 self.start = self.last = new_element else: new_element.next = self.start self.start.prv = new_element self.start = new_element def delete(self, target): it = self.start while it is not None: # 該当する最初のノードを見つける if it.num == target: if it.prv is None and it.next is None: # ノードが一つだけの時 self.start = self.last = None else: if it.prv is not None: # 先頭ではない it.prv.next = it.next else: # 先頭の場合、先頭の次をstartにする self.start = self.start.next if it.next is not None: # 最後ではない場合 it.next.prv = it.prv else: # 最後の場合、最後の一つ前をlastにする self.last = self.last.prv break it = it.next def deleteFirst(self): if self.start is self.last: self.start = self.last = None else: self.start.next.prv = None self.start = self.start.next def deleteLast(self): if self.start is self.last: self.start = self.last = None else: self.last.prv.next = None self.last = self.last.prv def contentToArray(self): n_list = [] it = self.start while it is not None: n_list.append(it.num) it = it.next return ' '.join(n_list) def main(): from sys import stdin N = int(input()) linkedList = DoublyLinkedList() # インスタンス作成 for i in range(N): command = stdin.readline().rstrip().split() if command[0] == 'insert': linkedList.insert(command[1]) elif command[0] == 'delete': linkedList.delete(command[1]) elif command[0] == 'deleteFirst': linkedList.deleteFirst() elif command[0] == 'deleteLast': linkedList.deleteLast() print(linkedList.contentToArray()) if __name__ == "__main__": main()
1
52,730,416,704
null
20
20
S = list(input()) T = list(input()) i = 0 ans =[] while i + len(T) <= len(S): n = 0 for s, t in zip(S[i:i+len(T)], T): if s != t: n += 1 ans.append(n) i += 1 print(min(ans))
#!/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()
1
3,720,884,212,892
null
82
82
dice = {v: k for k, v in enumerate(list(map(int, input().split())))} adjacent = {k: v for k, v in enumerate(sorted(dice.keys()))} q = int(input()) p = [(-1,2,4,1,3,-1),(3,-1,0,5,-1,2),(1,5,-1,-1,0,4),(4,0,-1,-1,5,1),(2,-1,5,0,-1,3),(-1,3,1,4,2,-1)] for _ in range(q): top, front = map(int, input().split()) x = dice[top] y = dice[front] print(adjacent[p[x][y]])
class Dice(): def __init__(self, dice_labels): self.top = dice_labels[0] self.south = dice_labels[1] self.east = dice_labels[2] self.west = dice_labels[3] self.north = dice_labels[4] self.bottom = dice_labels[5] def roll(self, str_direction): if str_direction == 'E': self.__roll_to_east() elif str_direction == 'W': self.__roll_to_west() elif str_direction == 'S': self.__roll_to_south() elif str_direction == 'N': self.__roll_to_north() def turn(self, str_direction): if str_direction == 'L': self.__turn_left() elif str_direction == 'R': self.__turn_right() def __roll_to_east(self): self.top, self.east, self.west, self.bottom = (self.west, self.top, self.bottom, self.east) def __roll_to_west(self): self.top, self.east, self.west, self.bottom = (self.east, self.bottom, self.top, self.west) def __roll_to_south(self): self.top, self.south, self.north, self.bottom = (self.north, self.top, self.bottom, self.south) def __roll_to_north(self): self.top, self.south, self.north, self.bottom = (self.south, self.bottom, self.top, self.north) def __turn_right(self): self.south, self.east, self.west, self.north = (self.east, self.north, self.south, self.west) def __turn_left(self): self.south, self.east, self.west, self.north = (self.west, self.south, self.north, self.east) dice_labels = input().split(' ') num_question = int(input()) dice = Dice(dice_labels) for i in range(0, num_question): target_top_label, target_for_label = tuple(input().split(' ')) for j in range(0, 2): for k in range(0, 4): if dice.top != target_top_label: dice.roll('N') dice.turn('R') for j in range(0, 4): if dice.south != target_for_label: dice.turn('R') print(dice.east)
1
256,173,956,522
null
34
34
def Judgement(x,y,z): if z-x-y>0 and (z-x-y)**2-4*x*y>0: return 0 else: return 1 a,b,c=map(int,input().split()) ans=Judgement(a,b,c) if ans==0: print("Yes") else: print("No")
def max(a): max = -10000000 for i in a: if max < i: max = i return max def min(a): min = 10000000 for i in a: if min > i: min = i return min def sum(a): sum = 0 for i in a: sum += i return sum input() a = list(map(int, input().split())) print(min(a), max(a), sum(a))
0
null
26,094,054,680,498
197
48
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])])
n=int(input()) ki=[[] for _ in range(n)] hen=[tuple(map(int,input().split())) for i in range(n-1)] color={(hen[i][0]-1,hen[i][1]-1):0 for i in range(n-1)} for i in range(n-1): a,b=hen[i][0],hen[i][1] ki[a-1].append(b-1) ki[b-1].append(a-1) mcol=0 ne=0 for i in range(n): if len(ki[i])>mcol: mcol=len(ki[i]) ne=i print(mcol) from collections import deque d=deque() d.append(ne) visited=[False]*n visited[ne]=True col=[0]*n while d: g=d.popleft() for i in ki[g]: if visited[i]: continue d.append(i) visited[i]=True if g>i: x,y=i,g else: x,y=g,i color[(x,y)]=col[g]%mcol+1 col[g],col[i]=color[(x,y)],color[(x,y)] for i in hen: print(color[(i[0]-1,i[1]-1)])
1
136,080,429,956,480
null
272
272
a,v = map(int,input().split()) b,m = map(int,input().split()) n = int(input()) dis = abs(a-b) a_move = n*v b_move = n*m if dis+b_move - a_move <= 0: print('YES') else: print('NO')
def main(): mod=998244353 n,k=map(int,input().split()) region=[] for _ in range(k): a,b=map(int,input().split()) region.append((a,b)) #dp[i]はマスiに行く方法の個数 #workにdp[i-1]からの増減分を保持 dp=[0]*(n+1) work=[0]*(n+1) #initialize for j in region: if 1+j[0]<=n: work[1+j[0]]+=1 if 1+j[1]+1<=n: work[1+j[1]+1]-=1 for i in range(2,n+1): dp[i]=dp[i-1]+work[i] dp[i]%=mod for j in region: if i+j[0]<=n: work[i+j[0]]+=dp[i] work[i+j[0]]%=mod if i+j[1]+1<=n: work[i+j[1]+1]-=dp[i] work[i+j[1]+1]%=mod print(dp[n]) main()
0
null
8,987,691,554,880
131
74
import sys read = sys.stdin.read def main(): n = int(input()) if n <= 9 or n % 2 == 1: print(0) sys.exit() n5 = 5 r = 0 while n >= n5 * 2: r += n // (n5 * 2) n5 *= 5 print(r) if __name__ == '__main__': main()
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline import itertools def main(): n = int(input()) l = list(map(int, input().split())) ans = INF for i in range(1,101): trial = 0 for k in l: trial += (k-i)**2 ans = min(ans, trial) print(ans) if __name__=="__main__": main()
0
null
90,714,667,712,580
258
213
n = int(input()) S = list(str(input())) S = [{ord(c)-ord('a')} for c in S] def segfunc(x, y): return x | y def init(init_val): # set_val for i in range(n): seg[i+num-1] = init_val[i] # built for i in range(num-2, -1, -1): seg[i] = segfunc(seg[2*i+1], seg[2*i+2]) def update(k, x): k += num - 1 seg[k] = x while k: k = (k-1)//2 seg[k] = segfunc(seg[2*k+1], seg[2*k+2]) def query(p, q): if q <= p: return ide_ele p += num - 1 q += num - 2 res = ide_ele while q-p>1: if p&1 == 0: res = segfunc(res, seg[p]) if q&1 == 1: res = segfunc(res, seg[q]) q -= 1 p = p//2 q = (q-1)//2 if p == q: res = segfunc(res, seg[p]) else: res = segfunc(segfunc(res, seg[p]), seg[q]) return res # identity element ide_ele = set() # num: n以上の最小の2のべき乗 num = 2**(n-1).bit_length() seg = [ide_ele]*2*num init(S) import sys input = sys.stdin.readline q = int(input()) for i in range(q): t, x, y = map(str, input().split()) if t == '1': x = int(x) y = ord(y)-ord('a') update(x-1, {y}) else: x = int(x) y = int(y) print(len(query(x-1, y)))
import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque from itertools import permutations sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N = int(input()) S = list(input()) Q = int(input()) q_list = [list(input().split()) for _ in range(Q)] bit_tree = [[0] * (N+1) for _ in range(26)] def BIT_add(i, tree): while i <= N: tree[i] += 1 i += i&(-i) def BIT_sub(i, tree): while i <= N: tree[i] -= 1 i += i&(-i) def BIT_sum(i, tree): s = 0 while i: s += tree[i] i -= i&(-i) return s for i in range(N): x = ord(S[i]) - ord('a') BIT_add(i + 1, bit_tree[x]) for q in range(Q): line = q_list[q] if line[0] == '1': i, c = line[1:] i = int(i) - 1 old_c = ord(S[i]) - ord('a') new_c = ord(c) - ord('a') BIT_sub(i + 1, bit_tree[old_c]) BIT_add(i + 1, bit_tree[new_c]) S[i] = c else: l, r = map(int, line[1:]) now = 0 for i in range(26): cnt = BIT_sum(r, bit_tree[i]) - BIT_sum(l - 1, bit_tree[i]) if cnt > 0: now += 1 print(now)
1
62,675,614,711,520
null
210
210
a,v = map(int,input().split()) b,w = map(int,input().split()) t = int(input()) ans = "NO" if abs(a-b) <= t * (v - w): ans = "YES" print(ans)
a = input().split() b = input().split() t = input() dist = abs(int(a[0])-int(b[0])) len = int(int(a[1]) - int(b[1]))*int(t) if (dist > len): print("NO") else: print("YES")
1
15,128,824,353,760
null
131
131
a=int(input()) b='' for i in range(a): b=b+'ACL' print(b)
s="ACL"*int(input()) print(s)
1
2,156,934,744,790
null
69
69
def main() : s = input() t = input() if (t in s) : print(0) return difference = 99999999 for offset in range(0,len(s) - len(t)+1): s2 = s[offset:offset+len(t)] diff = 0 for i in range(len(t)) : if (s2[i] != t[i]) : diff += 1 if (difference > diff) : difference = diff print(difference) main()
s = input() t = input() sl = len(s) tl = len(t) ans = 1001 for i in range(sl-tl+1): cnt = 0 for sv, tv in zip(s[i:i+tl], t): if sv != tv: cnt += 1 ans = min(cnt, ans) print(ans)
1
3,674,848,399,280
null
82
82
N,M=map(int,input().split()) ans=['0']*N I=[] for _ in range(M): s,c=input().split() index=int(s)-1 if index==0 and N>1 and c=='0': print(-1) break if index in I and ans[index]!=c: print(-1) break ans[index]=c I.append(index) else: if 0 not in I and N>1: ans[0]='1' print(''.join(ans))
''' Created on 2020/09/10 @author: harurun ''' def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write N,M=map(int,pin().split()) if N==3: ans=[1,0,0] for _ in [0]*M: s,c=map(int,pin().split()) if s==1 and c==0: print(-1) return if s!=1 and ans[s-1]!=0 and ans[s-1]!=c: print(-1) return ans[s-1]=c a="" for i in ans: a+=str(i) print(a) return elif N==2: ans=[1,0] for _ in [0]*M: s,c=map(int,pin().split()) if s==1 and c==0: print(-1) return if s!=1 and ans[s-1]!=0 and ans[s-1]!=c: print(-1) return ans[s-1]=c a="" for i in ans: a+=str(i) print(a) return else: if M==0: print(0) return s,c=map(int,pin().split()) ans=c for j in range(M-1): s,c=map(int,pin().split()) if c!=ans: print(-1) return print(ans) return main()
1
60,556,203,223,552
null
208
208
s=input() q=int(input()) que=[list(map(str,input().split())) for i in range(q)] count=0 for i in que: if i[0]=="1": count+=1 ans=[[],[]] ak=count for i in que: if i[0]=="1": count-=1 else: if i[1]=="1": ans[count%2].append(i[2]) else: ans[(count+1)%2].append(i[2]) if ak%2==0: print("".join(reversed(ans[0]))+s+"".join(ans[1])) else: print("".join(reversed(ans[0]))+"".join(reversed(list(s)))+"".join(ans[1]))
# -*- coding: utf-8 -*- n = int(input()) a = [int(i) for i in input().split()] su = [0 for _ in range(n)] #鉄の棒の切れ目の座標 for i in range(n): su[i] = su[i-1] + a[i] #print(su) tmp = 2 * pow(10, 10) + 1 for i in su: #if abs(i - su[-1]/2) < tmp: # tmp = abs(i - su[-1]/2) tmp = min(tmp, abs(i - su[-1]/2)) #print(su[-1]/2, tmp) """ #中心に一番近い鉄の棒の切れ目と中心との距離の差 l = 0 r = n-1 while (l - r) >= 1: c = (l + r) // 2 #print(l, r, c) if su[c] < su[-1] / 2: l = c elif su[c] > su[-1] / 2: r = c #print(su[l], su[r]) tmp = min(abs(su[l] - su[-1]/2), abs(su[r] - su[-1]/2)) print(tmp) """ ans = 2 * tmp print(int(ans))
0
null
99,556,506,471,470
204
276
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import collections class Process(object): def __init__(self, name, time): self.name = name self.time = int(time) def schedule(processes, quantum): queue = collections.deque(processes) time = 0 while len(queue) > 0: p = queue.popleft() rest_time = p.time - quantum if rest_time > 0: time += quantum queue.append(Process(p.name, rest_time)) else: time += p.time print("{name} {time:d}".format(name=p.name, time=time)) def main(): [n, q] = list(map(int, input().split())) processes = [Process(*input().split()) for i in range(n)] schedule(processes, q) if __name__ == "__main__": main()
n, q = map(int, input().split(' ')) p = [] time = 0 counter = 0 for i in range(n): tmp_n, tmp_p = input().split(' ') tmp_p = int(tmp_p) p.append((tmp_n, tmp_p)) while len(p) > 0: task = p.pop(0) tmp_p = task[1] - q if( tmp_p > 0): time += q p.append((task[0], tmp_p)) elif( tmp_p <= 0): time += task[1] print('{} {}'.format(task[0], time))
1
42,139,827,240
null
19
19
import queue WHITE = 0 GRAY = 1 BLACK = 2 NIL = -1 INF = 1000000000 def bfs(u): global Q Q.put(u) for i in range(n): d[i] = NIL d[u] = 0 while not Q.empty(): u = Q.get() for v in range(n): if (m[u][v] == 1) and (d[v] == NIL): d[v] = d[u] + 1 Q.put(v) n = int(input()) m = [[0 for i in range(n + 1)] for j in range(n + 1)] vid = [0] * n d = [0] * n f = [0] * n Q = queue.Queue() color = [WHITE] * n time = 0 nt = [0] * n tmp = [] for i in range(n): nums=list(map(int,input().split())) tmp.append(nums) vid[i] = nums[0] for i in range(n): for j in range(tmp[i][1]): m[i][vid.index(tmp[i][j + 2])] = 1 bfs(0) for i in range(n): print(vid[i], d[i])
a,b,c = map(int,input().split(" ")) ptn = 0 if a==b and a==c: print(1) ptn = 1 if a==b and a!=c: if a < c: print(1) ptn=2 else: print(0) ptn=2 cnt = 0 for i in range(a,b+1): if c%i == 0: cnt += 1 if ptn != 1 and ptn != 2: print(cnt)
0
null
286,927,170,596
9
44
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) S = list(input()) lis = [] for s in S: idx = ord(s) if idx+N>90: idx -= 26 lis.append(chr(idx+N)) print(''.join(lis))
def i(): return int(input()) def i2(): return map(int,input().split()) def s(): return str(input()) def l(): return list(input()) def intl(): return list(int(k) for k in input().split()) n = i() s = s() alf = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in range(len(s)): for j in range(26): if s[i] == alf[j]: print(alf[j+n],end="") continue
1
134,446,606,350,108
null
271
271
N = int(input()) D = list(map(int,input().split())) ans = 0 for i in range(N): tako1 = D[i] for j in range(0,i): tako2 = D[j] ans += tako1*tako2 for j in range(i+1,N): tako2 = D[j] ans += tako1*tako2 print(ans//2)
n, k = map(int, input().split()) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort() high = max(a)*max(f) low = 0 while high > low: mid = (high+low)//2 b = 0 for i in range(n): b += max(a[i]-mid//f[n-i-1],0) if b > k: low = mid + (low==mid) else: high = mid - (high==mid) mid = (high+low)//2 print(mid)
0
null
166,597,862,032,260
292
290
def prod(list): prod = 1 for k in list: prod = (prod * k) % (10**9+7) return prod n, kk = map(int, input().split()) a = list(map(int, input().split())) plus = [] minus = [] for k in a: if k >= 0: plus.append(k) if k <= 0: minus.append(k) if len(plus) == 0: if kk % 2 == 0: mi = sorted(minus) ans = prod(mi[:kk]) else: mi = sorted(minus, reverse=True) ans = prod(mi[:kk]) print(int(ans) % (10**9+7)) elif n == kk: ans = prod(a) print(int(ans) % (10**9+7)) else: mi = sorted(minus) pl = sorted(plus, reverse=True) mi.append(0) mi.append(0) pl.append(0) pl.append(0) miind = 0 plind = 0 ans = 1 while kk > miind + plind: if mi[miind]*mi[miind+1] > pl[plind]*pl[plind+1] and kk != miind + plind + 1: ans = (ans*mi[miind]*mi[miind+1]) % (10**9+7) miind += 2 else: ans = (ans*pl[plind]) % (10**9+7) plind += 1 print(ans)
def solve(): can_positive = False if len(P) > 0: if k < n: can_positive = True else: can_positive = len(M)%2 == 0 else: can_positive = k%2 == 0 if not can_positive: return sorted(P+M, key=lambda x:abs(x))[:k] P.sort() M.sort(reverse=True) a = [P.pop()] if k%2 else [1] while len(P) >= 2: a.append(P.pop() * P.pop()) while len(M) >= 2: a.append(M.pop() * M.pop()) return a[:1] + sorted(a[1:], reverse=True)[:(k-k%2)//2] n, k = map(int, input().split()) P, M = [], [] for a in map(int, input().split()): if a < 0: M.append(a) else: P.append(a) ans, MOD = 1, 10**9 + 7 for a in solve(): ans *= a; ans %= MOD ans += MOD; ans %= MOD print(ans)
1
9,511,246,589,310
null
112
112
# coding=utf-8 import itertools def main(): while True: n, t = map(int, raw_input().split()) if n + t == 0: break print sum([1 if sum(three) == t else 0 for three in itertools.combinations(xrange(1, n+1), 3)]) if __name__ == '__main__': main()
import sys from itertools import accumulate, repeat, takewhile from operator import mul def main(): N = int(next(sys.stdin.buffer)) if N % 2: print(0) return print(sum(N // x for x in takewhile(lambda x: x <= N, accumulate(repeat(5), mul, initial=10)))) if __name__ == '__main__': main()
0
null
58,650,219,696,940
58
258
import sys sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline def solve(): x = int(rl()) print(x ^ 1) if __name__ == '__main__': solve()
print(1 if int(input()) == 0 else 0)
1
2,934,481,046,222
null
76
76
def resolve(): N = int(input()) if N%2 == 1: print(0) else: ans = 0 for i in range(0, 50): ans += N//(10*(5**i)) print(ans) if __name__ == "__main__": resolve()
n = input() p = input() s = len(n) count = 0 for i in range(s): if n[i] != p[i]: count += 1 print(count)
0
null
63,414,030,831,100
258
116
from fractions import Fraction import sys def input(): return sys.stdin.readline().rstrip('\n') ZERO = Fraction(0, 1) Z = 1000000007 class Pow: def __init__(self, n): self.N = n self.e = [1] * (n + 1) for i in range(n): self.e[i + 1] = (self.e[i] * 2) % Z def get(self, n): if self.N >= n: return self.e[n] else: for i in range(self.N + 1, n + 1): self.e += [(self.e[i] * 2) % Z] return self.e[n] def calc(N, G): zz = 0 r = {} r_max = 0 for a, b in G: if b == 0: if a == 0: zz += 1 else: if 0 in r: r[0][1][1] += 1 else: r[0] = {1: [0, 1]} r_max = max(r_max, r[0][1][1]) else: if a == 0: if 0 in r: r[0][1][0] += 1 else: r[0] = {1: [1, 0]} r_max = max(r_max, r[0][1][0]) else: f = Fraction(a, b) if f > 0: i = f.numerator j = f.denominator if i in r: if j in r[i]: r[i][j][0] += 1 else: r[i][j] = [1, 0] else: r[i] = {j: [1, 0]} r_max = max(r_max, r[i][j][0]) else: i = f.denominator j = -f.numerator if i in r: if j in r[i]: r[i][j][1] += 1 else: r[i][j] = [0, 1] else: r[i] = {j: [0, 1]} r_max = max(r_max, r[i][j][1]) ans = 1 pow = Pow(r_max) for i in r: for j in r[i]: ans = (ans * (pow.get(r[i][j][0]) + pow.get(r[i][j][1]) - 1)) % Z return (ans + zz - 1) % Z N = int(input()) G = [tuple([int(s) for s in input().split()]) for _ in range(N)] print(calc(N, G))
import math N,M=map(int,input().split()) def C(x): if x>=2: return math.factorial(x)//(math.factorial(x-2)*2) else: return 0 print(C(N)+C(M))
0
null
33,314,887,045,660
146
189
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])
a, b = (int(x) for x in input().split()) if 500 * a < b: print("No") else: print("Yes")
0
null
49,335,225,564,702
28
244
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N, M = MI() print(int(N*(N-1)/2 + M*(M-1)/2)) main()
n, m = list(map(int, input().split())) nC2 = (n * (n - 1)) // 2 mC2 = (m * (m - 1)) // 2 print(nC2 + mC2)
1
45,670,007,474,608
null
189
189
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): n = I() ans = 0 N = 10**7 + 1 prime = [True] * N prime[1] = False n_yaku = [1] * N min_prime = [1] * N for i in range(2, N): if not prime[i]: continue n_yaku[i] = 2 min_prime[i] = i num = i + i while num < N: min_prime[num] = i prime[num] = False num += i for i in range(2, N): if prime[i]: continue j = i cnt = 0 while j % min_prime[i] == 0: # print('j: ', j) # print('prime: ', min_prime[i]) j //= min_prime[i] cnt += 1 n_yaku[i] = n_yaku[j] * (cnt + 1) ans = 0 for i in range(1, n+1): ans += i * n_yaku[i] print(ans) main()
import math N = int(input()) cnt_list = [0] * N for i in range(1, N + 1): for j in range(i, N + 1, i): cnt_list[j - 1] += 1 ans = 0 for h in range(1, N + 1): ans += h * cnt_list[h -1] print(ans)
1
11,027,021,944,928
null
118
118
import sys K,X = map(int,input().split()) if not ( 1 <= K <= 100 and 1 <= X <= 10**5 ): sys.exit() print('Yes') if 500 * K >= X else print('No')
k, x = map(int, input().split()) if 500 * k >= x: print('Yes') elif 500 * k < x: print('No')
1
97,967,956,517,116
null
244
244
import sys, os, math \ # , bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall # from decimal import Decimal # from collections import defaultdict, deque # import copy sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() A = il() Q = ii() M = il() num_set = set() for i in range(1 << N): num = 0 for n in range(N): if i >> n & 1: num += A[n] num_set.add(num) for m in M: if m in num_set: print('yes') else: print('no') if __name__ == '__main__': main()
# input N, M = map(int, input().split()) # process ans = [] t = 1 for _ in range(M//2): ans.append((t, M-t+1)) t += 1 t = M+1 for _ in range(-(-M//2)): ans.append((t, M*3+2-t)) t += 1 # output [print(a, b) for a, b in ans]
0
null
14,421,116,201,590
25
162
H1,M1,H2,M2,K=map(int,input().split()) t1=60*H1 + M1 t2=60*H2 + M2 t=t2 - K ans=t-t1 print(max(0,ans))
max_n=10**5 mod=10**9+7 frac=[1] for i in range(1,max_n+1): frac.append((frac[-1]*i)%mod) inv=[1,1] inv_frac=[1,1] for i in range(2,max_n): inv.append((mod-inv[mod%i]*(mod//i))%mod) inv_frac.append((inv_frac[-1]*inv[-1])%mod) def perm(m,n): if m<n: return 0 if m==1: return 1 return (frac[m]*inv_frac[m-n])%mod def comb(m,n): if m<n: return 0 if m==1: return 1 return (frac[m]*inv_frac[n]*inv_frac[m-n])%mod s=int(input()) c=0 for i in range(1,s//3+1): ss=s-i*3 c=(c+comb(ss+i-1,i-1))%mod print(c)
0
null
10,636,442,751,594
139
79
def main(): n = int(input()) T = tuple(map(int, input())) ans = 0 for i in range(0, 1000): a = i // 100 b = (i // 10) % 10 c = i % 10 flag1 = False flag2 = False flag3 = False for t in T: if flag2: if t == c: flag3 = True break if flag1: if t == b: flag2 = True continue if t == a: flag1 = True if flag3: ans += 1 print(ans) if __name__ == "__main__": main()
# 5 import sys def input(): return sys.stdin.readline().strip() def I(): return int(input()) def LI(): return list(map(int, input().split())) 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 S(): return input() def LS(): return input().split() INF = float('inf') n = I() s = S() ciphers = [f'{i:03}' for i in range(1000)] ans = 0 for v in ciphers: j = 0 for i in range(n): if s[i] == v[j]: j += 1 if j == 3: ans += 1 break print(ans)
1
128,331,788,543,068
null
267
267
N = input() straw = input() straw = straw.split('ABC') print(len(straw) - 1)
import re n = int(input()) text = input() pattern = "ABC" result = re.findall(pattern, text) print(len(result))
1
99,189,743,241,022
null
245
245
n,k = map(int,input().split()) w = [int(input()) for i in range(n)] def f(x): i = 0 for j in range(k): s = 0 while s+w[i] <= x: s += w[i] i+=1 if i == n: return n return i def bin_search(left,right): while right - left > 1: mid = (left + right) // 2 if f(mid) == n: right = mid else: left = mid return right print(bin_search(0,10**9))
def is_ok(W, truck, middle): loaded = 0 for t in range(truck): this_total = 0 while this_total + W[loaded] <= middle: this_total += W[loaded] loaded += 1 if loaded == len(W): return True return False def meguru_bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(w, k, mid): ok = mid else: ng = mid return ok n, k = map(int,input().split()) w = [0]*n for i in range(n): w[i] = int(input()) ans = meguru_bisect(-1,10**10+1) print(ans)
1
88,797,671,520
null
24
24
# S の長さが K 以下であれば、S をそのまま出力してください。 # S の長さが K を上回っているならば、 # 先頭 K 文字だけを切り出し、末尾に ... を付加して出力してください。 # K は 1 以上 100 以下の整数 # S は英小文字からなる文字列 # S の長さは 1 以上 100 以下 K = int(input()) S = str(input()) if K >= len(S): print(S) else: print((S[0:K] + '...'))
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) n = ini() s = list(ins()) n = s.count("R") t = sorted(s) ans = 0 for i in range(n): if s[i] != t[i]: ans += 1 print(ans)
0
null
13,022,659,905,792
143
98
def selection_sort(A): count = 0 for i in range(len(A)): min_value = A[i] min_value_index = i # print('- i:', i, 'A[i]', A[i], '-') for j in range(i, len(A)): # print('j:', j, 'A[j]:', A[j]) if A[j] < min_value: min_value = A[j] min_value_index = j # print('min_value', min_value, 'min_value_index', min_value_index) if i != min_value_index: count += 1 A[i], A[min_value_index] = A[min_value_index], A[i] # print('swap!', A) return count n = int(input()) A = list(map(int, input().split())) count = selection_sort(A) print(*A) print(count)
N, A, cou = int(input()), [int(temp) for temp in input().split()], 0 for i in range(N) : minj = i for j in range(i, N) : if A[j] < A[minj] : minj = int(j) if A[i] != A[minj] : A[i], A[minj] = int(A[minj]), int(A[i]) cou = cou + 1 print(*A) print(cou)
1
19,619,317,842
null
15
15
print(int(input()[:2] != input()[:2]))
while True: entry = map(str, raw_input().split()) a = int(entry[0]) op = entry[1] b = int(entry[2]) if op == "?": break elif op == "+": ans = a + b elif op == "-": ans = a - b elif op == "*": ans = a * b elif op == "/": ans = a / b print(ans)
0
null
62,185,654,964,004
264
47
N=int(input()) S=input() R=0;G=1;B=2 C=["R","G","B"] X=[[[0 for i in range(N+1)]for x in range(2)] for c in range(3)] for c in range(3): for i in range(N): if S[i]==C[c]: X[c][0][i+1]=X[c][0][i]+1 else: X[c][0][i+1]=X[c][0][i] for i in range(N-1,-1,-1): if S[i]==C[c]: X[c][1][i]=X[c][1][i+1]+1 else: X[c][1][i]=X[c][1][i+1] ans=0 for i in range(N): c=-1 for cc in range(3): if C[cc]==S[i]: c=cc break for seq in [((c+1)%3,(c+2)%3),((c+2)%3,(c+1)%3)]: x,y=seq ans+=X[x][0][i]*X[y][1][i] for i in range(N): x=0 while(i+2*x<N): j=i+x k=i+2*x if len({S[i],S[j],S[k]})==3: ans-=1 x+=1 print(ans)
n = int(input()) s = input() al=s.count("R")*s.count("G")*s.count("B") for i in range(n-2): for k in range(i+1,n-1): l=k+(k-i) if l>=n: continue if s[i]!=s[k] and s[i]!=s[l] and s[k]!=s[l]: al-=1 print(al)
1
36,374,634,797,508
null
175
175
x=input() y=input() lst1=[] lst1=list(x) lst2=[] lst2=list(y) b=0 ans=0 while(b<len(x)): if(not lst1[b]==lst2[b]): ans=ans+1 b+=1 print(ans)
# ALDS1_5_A. def intinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def binary_search(S, k): a = 0; b = len(S) - 1 if b == 0: return S[0] == k while b - a > 1: c = (a + b) // 2 if k <= S[c]: b = c else: a = c return S[a] == k or S[b] == k def show(a): # 配列aの中身を出力する。 _str = "" for i in range(len(a) - 1): _str += str(a[i]) + " " _str += str(a[len(a) - 1]) print(_str) def main(): n = int(input()) A = intinput() q = int(input()) m = intinput() # 配列Aの作る数を調べる。 nCanMake = [0] for i in range(n): for k in range(len(nCanMake)): x = nCanMake[k] + A[i] if not x in nCanMake: nCanMake.append(x) # show(nCanMake) for i in range(q): if m[i] in nCanMake: print("yes") else: print("no") if __name__ == "__main__": main()
0
null
5,265,076,993,708
116
25
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().rstrip().split()) inl = lambda: list(map(int, input().split())) out = lambda x, s='\n': print(s.join(map(str, x))) def check(a, b, c): if a == b or a == c or b == c: return False if a + b <= c: return False if a + c <= b: return False if b + c <= a: return False return True n = ini() a = inl() ans = 0 for i in range(n): for j in range(i+1, n): for t in range(j+1, n): if check(a[i], a[j], a[t]): ans += 1 print(ans)
def A(): s = input() if s == 'SSS': print(3) elif s=='RSS' or s=='SSR': print(2) elif s=='RRR': print(0) else: print(1) def B(): n = int(input()) a = list(map(int, input().split())) cnt = 0 for i in range(n): for j in range(i+1, n): if a[i] == a[j]: continue for k in range(j+1, n): if a[i]==a[k] or a[j] == a[k]: continue s = a[i] + a[j] + a[k] if s > 2 * max(a[i], a[j], a[k]): cnt += 1 print(cnt) def C(): x, k, d = map(int, input().split()) if abs(x) > k * d: print(abs(x) - k*d) else: tm = abs(x) // d x = abs(x) % d k -= tm if k % 2 == 0: print(x) else: print(d-x) B()
1
5,015,474,847,668
null
91
91
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,k,s = map(int, input().split()) if s==10**9: a = [10**9]*k + [1]*(n-k) else: a = [s]*k + [s+1]*(n-k) print(" ".join(map(str, a)))
ABC = list(map(int, input().split())) if len(set(ABC)) == 2: print('Yes') else: print('No')
0
null
79,376,012,051,580
238
216
a,b=input().split() a=int(a) b=int(b) print(int(a*(a-1)/2+(b*(b-1)/2)))
n, m = map(int,input().split()) if (n < 2): a = 0 else: a = int(n*(n - 1)/2) if (m < 2): b = 0 else: b = int(m*(m - 1)/2) print(a + b)
1
45,542,358,322,800
null
189
189
n, k = map(int, input().split()) snukes = [] for _ in range(k): okashi = int(input()) snukes += [int(v) for v in input().split()] target = 1 cnt = 0 l = list(set(snukes)) s = [int(v) for v in range(1, n + 1)] for p in s: if p not in l: cnt += 1 print(cnt)
from _collections import deque k = int(input()) l = [str(i) for i in range(1,10)] que = deque(l) while len(l) < k: seq = que.popleft() a = int(seq[-1]) if a != 0: aa = seq + str(a-1) que.append(aa) l.append(aa) aa = seq + str(a) que.append(aa) l.append(aa) if a != 9: aa = seq + str(a+1) que.append(aa) l.append(aa) print(l[k-1])
0
null
32,160,777,898,568
154
181
S,T=map(str,input().split()) res =T+S print(res)
S, T = map(str, input().split()) T += S print(T)
1
103,261,074,653,492
null
248
248
N = int(input()) query = [[] for _ in range(N)] color = [] m = [0]*N for n in range(N-1): a, b = map(int, input().split()) query[a-1].append(b-1) query[b-1].append(a-1) color.append((min(a, b), max(a, b))) m[a-1] += 1 m[b-1] += 1 print(max(m)) from collections import deque queue = deque() queue.appendleft(0) checked = [-1]*N checked[0] = 0 dic = {} while queue: v = queue.pop() oya = checked[v] lis = query[v] cnt = 1 for i in lis: if checked[i]!=-1: continue if cnt==oya: cnt += 1 queue.appendleft(i) dic[(min(v+1, i+1), max(v+1, i+1))] = cnt checked[i] = cnt cnt += 1 for n in range(N-1): a, b = color[n] print(dic[(min(a, b), max(a, b))])
import queue n = int(input()) e = [] f = [{} for i in range(n)] for i in range(n-1): a,b = map(int, input().split()) a-=1 b-=1 e.append([a,b]) f[a][b]=0 f[b][a]=0 k = 0 for i in range(n-1): k = max(k,len(f[i])) q = queue.Queue() q.put(0) used = [[0] for i in range(n)] while not q.empty(): p = q.get() for key,c in f[p].items(): if c == 0: if used[p][-1]<k: col = used[p][-1]+1 else: col = 1 f[p][key] = col f[key][p] = col used[p].append(col) used[key].append(col) q.put(key) print(k) for a,b in e: print(max(f[a][b],f[b][a]))
1
136,040,205,178,612
null
272
272
inputted = input().split() S = inputted[0] T = inputted[1] answer = T + S print(answer)
s,t = (i for i in input().split()) print(t+s)
1
102,986,760,843,824
null
248
248