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
a,b=map(int,input().split()) def gcd(x, y): while y: x, y = y, x % y return x l=gcd(a,b) print(int(a*b/l))
# 最大公約数を求める def gcm(m, n): # mを小さくする if m > n: _temp = n n = m m = _temp while m != 0: #print("{}, {}".format(m, n)) m, n = n % m, m return n a, b, = map(int, input().split()) g = gcm(a, b) print("{}".format((int)(a * b / g)))
1
113,264,125,144,352
null
256
256
import sys read = sys.stdin.read #readlines = sys.stdin.readlines from math import ceil def main(): n = tuple(map(int, tuple(input()))) if sum(n) % 9 == 0: print('Yes') else: print('No') if __name__ == '__main__': main()
def main(): a, b = map(lambda x: int(x.replace('.','')), input().split()) print(a*b//100) if __name__ == '__main__': main()
0
null
10,474,369,839,868
87
135
def bubble_sort_aoj(nums, len): '''バブルソート:隣接項の比較''' flag = True count = 0 while flag: flag = False for i in range(len - 1, 0, -1): if nums[i] < nums[i-1]: nums[i], nums[i-1] = nums[i-1], nums[i] flag = True count += 1 return nums, count if __name__ == '__main__': N = int(input()) A = list(map(int, input().split(' '))) ans = bubble_sort_aoj(A, N) print(' '.join([str(x) for x in ans[0]])) print(ans[1])
n = int(input()) ll = list(map(int, input().split())) def bubble_sort(a, n): flag = True count = 0 while flag: flag = False for i in range(n-2, -1, -1): if a[i] > a[i+1]: a[i], a[i+1] = a[i+1], a[i] flag = True count += 1 print(" ".join(map(str, a))) print(count) bubble_sort(ll, n)
1
17,055,915,900
null
14
14
N = int(input()) ans = [] i = 1 while i * i <= N: if N % i == 0: x = i y = N / i ans.append(x+y-2) i += 1 print(int(min(ans)))
N=int(input()) l=[] for i in range(1,int(N**0.5)+1): if N%i==0: l.append([i,N/i]) L=len(l) s=[0]*L for j in range(L): s[j]=l[j][0]+l[j][1] print(int(min(s))-2)
1
162,033,891,912,438
null
288
288
N,M = map(int,input().split()) A = [int(x) for x in input().split()] if N - sum(A) >= 0 : print(N-sum(A)) else : print("-1")
n, m = map(int, input().split()) a = list (map(int, input().split())) b = sum(a) if n >= b: print( n - b ) if n < b: print( -1 )
1
31,747,619,607,328
null
168
168
import heapq INFTY = 10**4 N,X,Y = map(int,input().split()) G = {i:[] for i in range(1,N+1)} for i in range(1,N): G[i].append(i+1) G[i+1].append(i) G[X].append(Y) G[Y].append(X) dist = [[INFTY for _ in range(N+1)] for _ in range(N+1)] for i in range(N+1): dist[i][i] = 0 for i in range(1,N+1): hist = [0 for _ in range(N+1)] heap = [(0,i)] hist[i] = 1 while heap: d,x = heapq.heappop(heap) if d>dist[i][x]:continue hist[x] = 1 for y in G[x]: if hist[y]==0: if dist[i][y]>d+1: dist[i][y] = d+1 heapq.heappush(heap,(d+1,y)) C = {k:0 for k in range(1,N)} for i in range(1,N): for j in range(i+1,N+1): C[dist[i][j]] += 1 for k in range(1,N): print(C[k])
H, W, M = map(int, input().split()) HW = set() sum_h = [0]*H; sum_w = [0]*W max_sum_h = max_sum_w = 0 for _ in range(M): h, w = map(lambda x:int(x)-1, input().split()) HW.add((h, w)) sum_h[h] += 1 sum_w[w] += 1 max_sum_h = max(max_sum_h, sum_h[h]) max_sum_w = max(max_sum_w, sum_w[w]) hs = []; ws = [] for i in range(H): if sum_h[i] == max_sum_h: hs.append(i) for i in range(W): if sum_w[i] == max_sum_w: ws.append(i) ans = max_sum_h + max_sum_w - 1 for h in hs: for w in ws: if (h, w) in HW: continue print(ans + 1) exit() print(ans)
0
null
24,309,153,214,308
187
89
S = input() T = input() N = len(S) if len(T) == N+1: Ts = T[:N] if Ts == S: print('Yes') else: print('No') else: print('No')
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): S = input() cnt = 0 mx = 0 for i in range(len(S)): if (S[i] == 'R'): cnt += 1 else: cnt = 0 mx = max(mx, cnt) print(mx) if __name__ == '__main__': main()
0
null
13,170,003,105,088
147
90
C = ord(input()) C += 1 print(chr(C))
x = input() alpha2num = lambda c: ord(c) - ord('a') + 1 num2alpha = lambda c: chr(c+96+1) a = alpha2num(x) b = num2alpha(a) print(b)
1
92,115,759,304,428
null
239
239
N = int(input()) ac = 0 wa = 0 re = 0 tle = 0 for i in range(N): s = input() if s=="AC": ac += 1 elif s=="WA": wa += 1 elif s=="RE": re += 1 elif s=="TLE": tle += 1 print("AC x "+str(ac)) print("WA x "+str(wa)) print("TLE x "+str(tle)) print("RE x "+str(re))
n = input() hon = [2, 4, 5, 7, 9] pon = [0, 1, 6, 8] if int(n[-1]) in hon: print("hon") elif int(n[-1]) in pon: print("pon") else: print("bon")
0
null
13,902,021,609,280
109
142
def main(): n, m = map(int, input().split()) # nは偶数、mは奇数 # n+mから2つ選ぶ選び方は # n:m = 0:2 和は 偶数、選び方はmC2 # n:m = 1:1 和は 奇数 (今回はこれは含めない) # n:m = 2:0 和は 偶数、選び方はnC2 cnt = 0 if m >= 2: cnt += m * (m -1) // 2 if n >=2: cnt += n * (n -1) // 2 print(cnt) if __name__ == '__main__': main()
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
80,385,926,648,132
189
258
# # m_solutions2020 b # import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """7 2 5 3""" output = """Yes""" self.assertIO(input, output) def test_入力例_2(self): input = """7 4 2 3""" output = """No""" self.assertIO(input, output) def resolve(): A, B, C = map(int, input().split()) K = int(input()) for i in range(K): if A >= B: B *= 2 elif B >= C: C *= 2 if A < B < C: print("Yes") break else: print("No") if __name__ == "__main__": # unittest.main() resolve()
r, g, b = map(int, input().split()) k = int(input()) for i in range(k): if r >= g: g *= 2 elif g >= b: b *= 2 print('Yes' if r < g < b else 'No')
1
6,922,976,894,428
null
101
101
import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 n,k = map(int,readline().split()) lst1 = list(map(int,readline().split())) for i in range(n-k): if lst1[i] >= lst1[i+k]: print("No") else: print("Yes")
# N = int(input()) import heapq X, Y, A, B, C = [int(i) for i in input().split()] p = [int(i) for i in input().split()] q = [int(i) for i in input().split()] r = [int(i) for i in input().split()] p = sorted(p, reverse=True)[:X] q = sorted(q, reverse=True)[:Y] heapq.heapify(p) heapq.heapify(q) r_asc = sorted(r, reverse=True) for r in r_asc: p_min = heapq.heappop(p) q_min = heapq.heappop(q) if p_min > q_min and r > q_min: heapq.heappush(q, r) heapq.heappush(p, p_min) elif q_min >= p_min and r > p_min: heapq.heappush(p, r) heapq.heappush(q, q_min) else: heapq.heappush(q, q_min) heapq.heappush(p, p_min) break print(sum(p) + sum(q))
0
null
25,949,645,497,568
102
188
n=int(input()) a=list(map(int,input().split())) X=[] b=a[0] for i in range(1,n) : b^=a[i] for i in range(n) : x=b^a[i] X.append(x) for i in X : print(i,end=" ")
from sys import stdin,stdout LI=lambda:list(map(int,input().split())) MAP=lambda:map(int,input().split()) IN=lambda:int(input()) S=lambda:input() import math from collections import Counter,defaultdict n=IN() a=LI() ans=0 for i in range(n): ans^=a[i] for i in range(n): print(ans^a[i],end=" ")
1
12,575,190,497,308
null
123
123
INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) def do(): a=INT() print(a+a**2+a**3) if __name__ == '__main__': do()
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n, m = map(int, input().split()) h = tuple(map(int, input().split())) edges = {e:[] for e in range(n)} for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(h[b]) edges[b].append(h[a]) r = 0 for i, he in enumerate(h): if not edges[i]: r += 1 else: r += he > max(edges[i]) print(r) if __name__ == '__main__': main()
0
null
17,535,139,212,470
115
155
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) # class UnionFind(): # par = [] # sizes = [] # def __init__(self, N): # self.par = [i for i in range(N)] # self.sizes = [1 for _ in range(N)] # def root(self, x: int)-> int: # if (self.par[x] == x): # return x # return self.root(self.par[x]) # def unite(self, x: int, y: int): # rootX = self.root(x) # rootY = self.root(y) # if rootX == rootY: # return # self.par[rootX] = rootY # self.sizes[rootY] += self.sizes[rootX] # def maxSize(self)-> int: # return max(self.sizes) def friends(N, As): uf = UnionFind(N) setAs = list(set(As)) for val in setAs: uf.union(val[0]-1, val[1]-1) ans = 0 for i in range(N): temp = uf.size(i) if ans < temp: ans = temp return ans if __name__ == "__main__": nm = list(map(int, input().split())) As =[tuple(map(int, input().split())) for _ in range(nm[1])] print(friends(nm[0], As))
class UnionFind(): # 0インデックス def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] if __name__ == "__main__": N, M = map(int, input().split()) # N人、M個の関係 union_find = UnionFind(N) for _ in range(M): A, B = map(int, input().split()) A -= 1 B -= 1 union_find.union(A, B) answer = 0 for i in range(N): answer = max(answer, union_find.size(i)) print(answer)
1
3,961,382,510,528
null
84
84
isPrime=[1 for i in range(10**6+1)] isPrime[0]=0;isPrime[1]=0 for i in range(2,10**6+1): if isPrime[i]==0: continue for j in range(2*i,10**6+1,i): isPrime[j]=0 X=int(input()) for i in range(X,10**6+1): if isPrime[i]==1: print(i) exit()
def crivo(n): primos = [True] * n primos[0] = primos[1] = False i = 2 while i * i < n: if primos[i] == True: for j in range(2*i, n, i): primos[j] = False i += 1 return primos def main(): primos = crivo(100004) x = int(input()) for i in range(x, 100004): if primos[i]: print(i) break main()
1
105,671,543,832,672
null
250
250
N = int(input()) def digitSum(n): s = str(n) array = list(map(int, s)) return sum(array) if digitSum(N) % 9 == 0: print("Yes") else: print("No")
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush import math #inf = 10**17 #mod = 10**9 + 7 n = input().rstrip() k = int(input()) ln = len(n) # dp[i][j]:左からi桁まで見たとき0でない桁がj個ある場合の数 dp1 = [[0]*(k+1) for _ in range(ln+1)] dp2 = [[0]*(k+1) for _ in range(ln+1)] dp2[0][0] = 1 cnt = 0 for i in range(ln): if n[i] != '0': if cnt < k: cnt += 1 dp2[i+1][cnt] = 1 else: dp2[i+1][cnt] = dp2[i][cnt] for i in range(ln): dp1[i+1][0] = 1 for j in range(1, k+1): dp1[i+1][j] += dp1[i][j] + dp1[i][j-1] * 9 if n[i] != '0': dp1[i+1][j] += dp2[i][j-1] * (int(n[i])-1) if j < k: dp1[i+1][j] += dp2[i][j] print(dp1[-1][k] + dp2[-1][k]) if __name__ == '__main__': main()
0
null
40,393,256,900,228
87
224
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): while True: try: a, b = [int(x) for x in input().split(" ")] except: return else: print(gcd(a, b),lcm(a, b)) def lcm(a, b): return (a * b) // gcd(a,b) def gcd(a, b): while b != 0: a, b = b, a % b return a if __name__ == '__main__': main()
while True: try: As,Bs = map(int,input().split()) a,b = As, Bs while True: if a % b == 0: gcd = b break a,b = b, a % b print(gcd,int(As * Bs / gcd)) except EOFError: break
1
658,519,118
null
5
5
a, b = map(int, input().split()) if a > 0 and a < 10: if b > 0 and b < 10: print(a * b) else: print(-1) else: print(-1)
n = int(input()) a = list(map(int, input().split())) q = int(input()) bc = [list(map(int, input().split())) for i in range(q)] l = [0] * 100000 suml = 0 for i in a: l[i-1] += 1 suml += i for i in bc: suml += l[i[0]-1] * (i[1] - i[0]) l[i[1]-1] += l[i[0]-1] l[i[0]-1] = 0 print(suml)
0
null
85,646,013,354,080
286
122
n,k=map(int,input().split()) mod=10**9+7 ans=0 l=[0]*(k+1) for i in range(k,0,-1): l[i]=pow(k//i,n,mod) for j in range(2*i,k+1,i): l[i]-=l[j] l[i]=pow(l[i],1,mod) ans+=l[i]*i ans=pow(ans,1,mod) print(ans)
a,b,c,d,e,f=map(int,input().split()) x=input() for i in range(len(x)): if x[i]=="S": a,b,c,d,e,f=e,a,c,d,f,b if x[i]=="E": a,b,c,d,e,f=d,b,a,f,e,c if x[i]=="N": a,b,c,d,e,f=b,f,c,d,a,e if x[i]=="W": a,b,c,d,e,f=c,b,f,a,e,d print(a)
0
null
18,621,730,957,792
176
33
print(-1*(-1*int(input()) // 2))
# coding: utf-8 H, W = list(map(int, input().split())) S = [] for _ in range(H): S.append(list(input())) grid = [[0 for _ in range(W)] for _ in range(H)] for h in range(1,H): if S[h-1][0] == '#' and S[h][0] == '.': grid[h][0] = grid[h-1][0] + 1 else: grid[h][0] = grid[h-1][0] for w in range(1,W): if S[0][w-1] == '#' and S[0][w] == '.': grid[0][w] = grid[0][w-1] + 1 else: grid[0][w] = grid[0][w-1] for w in range(1,W): for h in range(1,H): if S[h-1][w] == '#' and S[h][w] == '.': next_h = grid[h-1][w] + 1 else: next_h = grid[h-1][w] if S[h][w-1] == '#' and S[h][w] == '.': next_w = grid[h][w-1] + 1 else: next_w = grid[h][w-1] grid[h][w] = min([next_w, next_h]) if S[H-1][W-1] == '#': grid[H-1][W-1] += 1 print(grid[H-1][W-1])
0
null
54,119,154,134,630
206
194
N,A,B = map(int,input().split()) if (B-A)%2: print(min(B-1, N-A, A+(B-A)//2, N-B+1+(B-A)//2)) else: print((B-A)//2)
N=int(input()) A = list(map(int, input().split())) money=1000 stock=0 if A[0]<A[1]: stock=int(money/A[0]) money=money-A[0]*stock for i in range(1,N-1): if A[i-1]<A[i]: money=money+A[i]*stock stock=0 if A[i]<A[i+1]: stock=int(money/A[i]) money=money-A[i]*stock money=money+A[N-1]*stock print(money)
0
null
58,124,697,627,260
253
103
while 1 : n,x=[int(i) for i in input().split()] count=0 if n==x==0: break for i in range(1,n+1): for j in range(i+1,n+1): for k in range(j+1,n+1): if i+j+k==x: count=count+1 print(count)
N = int(input()) S = list(map(int, input().split(" "))) Exchange_Number_of_times = 0 for i in range(N): minj = i for j in range(i, N): if S[j] < S[minj]: minj = j if i != minj: S[i], S[minj] = S[minj], S[i] Exchange_Number_of_times += 1 print(' '.join(map(str,S))) print(Exchange_Number_of_times)
0
null
668,621,948,316
58
15
x = int(input()) print('Yes' if 30 <= x else 'No')
import sys input = sys.stdin.readline def inps(): return str(input()) s = inps().rsplit()[0] t = inps().rsplit()[0] cnt = 0 for i in range(len(s)): if s[i]!=t[i]: cnt+=1 print(cnt)
0
null
8,093,844,921,988
95
116
N = int(input()) A = list(map(int, input().split())) j=0 for i in range(N): if A[i]==j+1: j+=1 if j == 0: print(-1) else: print(N-j)
N, u, v = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N - 1)] graph = [[] for _ in range(N)] for i, (Ai, Bi) in enumerate(AB): graph[Ai - 1].append(Bi - 1) graph[Bi - 1].append(Ai - 1) import heapq MY_INF = 10 ** 18 q = [(0, u - 1)] d_u = [MY_INF] * N d_u[u - 1] = 0 while len(q) > 0: dist, src = heapq.heappop(q) for dst in graph[src]: dist_tmp = dist + 1 if d_u[dst] > dist_tmp: d_u[dst] = dist_tmp heapq.heappush(q, (dist_tmp, dst)) q = [(0, v - 1)] d_v = [MY_INF] * N d_v[v - 1] = 0 while len(q) > 0: dist, src = heapq.heappop(q) for dst in graph[src]: dist_tmp = dist + 1 if d_v[dst] > dist_tmp: d_v[dst] = dist_tmp heapq.heappush(q, (dist_tmp, dst)) # print("#", d_u) # print("#", d_v) ans = 0 for i in range(N): if d_u[i] < d_v[i] and ans < d_v[i] - 1: ans = d_v[i] - 1 print(ans)
0
null
115,496,417,515,872
257
259
from itertools import product n = int(input()) l1 = [] for _ in range(n): l2 = [] for _ in range(int(input())): l2.append(list(map(int, input().split()))) l1.append(l2) ans = 0 for k in product([1, 0], repeat=n): check = True for i, j in enumerate(l1): if k[i] == 0: continue for x in j: if k[x[0] - 1] != x[1]: check = False if check: ans = max(ans, sum(k)) print(ans)
import itertools #a=itertools.product([0,1],repeat=N) N = int(input()) AAA = [[] for i in range(N)] for i in range(N): A = int(input()) for j in range(A): AAA[i].append([int(k) for k in input().split()]) for ifkind in itertools.product([1,0],repeat=N): consistent = True for i,A in enumerate(AAA): if ifkind[i]==1: for x,y in A: x=x-1 if ifkind[x]!=y: consistent = False if consistent==True: print(sum(ifkind)) break
1
121,796,101,534,948
null
262
262
a = int(input()) print(1 if a == 0 else 0)
H, W = map(int, input().split()) while H or W: for i in range(H): for j in range(W): print('#', end='') print() print() H, W = map(int, input().split())
0
null
1,879,095,794,730
76
49
import math N= int(input()) ans = math.ceil(N/2)-1 print(ans)
n = int(input()) print(int(n / 2) - (1 - (n % 2)))
1
152,676,735,322,114
null
283
283
n,k = map(int,input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort() F.reverse() t = sum(A) ok = 10**12 ng = -1 if t <= k: print(0) else: while abs(ok-ng) > 1: cur = 0 mid = (ok+ng)//2 for i in range(n): temp = mid/F[i] if int(temp) == temp: cur += max(0, int(A[i]-temp)) else: if A[i]-temp > 0: cur += int(A[i]-temp)+1 if cur > k: ng = mid else: ok = mid print(ok)
def resolve(): N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) def isok(num): if num >= N: anum = N bnum = num-anum else: anum = num bnum = 0 atotal = sum(A[:anum]) btotal = sum(B[:bnum]) if atotal + btotal <= K: return True i = 0 while not (anum-1-i < 0 or bnum+i >= M): atotal -= A[anum-1-i] btotal += B[bnum+i] if atotal + btotal <= K: return True i += 1 return False left = -1 right = N+M+1 while (right - left) > 1: mid = left + (right - left)//2 if isok(mid): left = mid else: right = mid print(left) if '__main__' == __name__: resolve()
0
null
88,150,066,709,090
290
117
N=str(input()) pon=["0","1","6","8"] hon=["2","4","5","7","9"] bon=["3"] if(N[-1] in pon): print("pon") elif(N[-1] in hon): print("hon") else: print("bon")
N= int(input()) n = N % 10 if n == 2 or n==4 or n ==5 or n == 7 or n == 9: print('hon') elif n == 0 or n ==1 or n == 6 or n == 8: print('pon') elif n == 3: print('bon')
1
19,328,569,234,832
null
142
142
S = input() print("%s:%s:%s"%(S/3600,(S//60)%60,S%60))
s = int(input()) h = s // 3600 m = s % 3600 // 60 s = s % 60 print(f'{h}:{m}:{s}')
1
332,987,027,090
null
37
37
import math len_a, len_b, deg_C = map(int,input().split(" ")) rad_C = math.radians(deg_C) #area S = (1/2) * len_a * len_b * math.sin(rad_C) #Length L = len_a + len_b + math.sqrt(len_a ** 2 + len_b ** 2 - 2 * len_a * len_b * math.cos(rad_C)) #height h = len_b * math.sin(rad_C) print("{:.5f}\n{:.5f}\n{:.5f}".format(S,L,h))
a = int(input()) b = input().split() c = [] for i in range(a * 2): if i % 2 == 0: c.append(b[0][i // 2]) else: c.append(b[1][(i - 1) // 2]) for f in c: print(f,end="")
0
null
56,314,323,730,140
30
255
import bisect n = int(input()) l_li = list(map(int,input().split())) l_li.sort() ans = 0 for i in range(n-2): for j in range(i+1,n-1): ind = bisect.bisect_left(l_li,l_li[i]+l_li[j]) num = ind-1 - j ans += num print(ans)
input() aa = list(map(int, input().split())) state = {(0,False)} skipmax = len(aa)%2 + 1 state_all = {(i, True) for i in range(skipmax+1)}.union({(j, False) for j in range(skipmax+1)}) dp_0 = {a:None for a in state_all } dp_0[(0,False)] = 0 skipcount = 0 def getmax(a, b): if a is None: return b if b is None: return a return max(a,b) for i,a in enumerate(aa): dp_1 = {} for s in state_all: if s[1] & (dp_0[(s[0], False)] is not None): dp_1[s] = dp_0[(s[0], False)] + a continue dp_1[s] = getmax(dp_0[(s[0], True)], dp_0.get((s[0]-1, False), None)) dp_0 = dp_1.copy() if len(aa)%2: print(getmax(dp_0[(2,True)], dp_0[(1,False)])) else: print(getmax(dp_0[(1,True)], dp_0[(0,False)]))
0
null
104,391,070,210,416
294
177
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): k = II() ans = "" for i in range(k): ans += "ACL" print(ans) main()
N=input() i=0 while i<len(N): print("x" ,end='') i+=1
0
null
37,479,511,105,620
69
221
h, w = map(int, input().split()) if h == 1 or w == 1: print(1) else: print((-(-w//2)) * (-(-h//2)) + (w//2) * (h//2))
h,w = [int(i) for i in input().split()] if h == 1 or w == 1: print(1) elif h % 2 == 1 and w % 2 == 1: print(int(h*w/2) + 1) else: print(int(h*w/2))
1
50,645,715,718,758
null
196
196
# B - Common Raccoon vs Monster H,N = map(int,input().split()) A = list(map(int,input().split())) ans = 'Yes' if H<=sum(A) else 'No' print(ans)
A,B,C,K = map(int,input().split()) point = 0 if K-A >=0: point += A else: point += K if K-A-B > 0: point -= K-A-B print(point)
0
null
50,133,355,281,282
226
148
import math a, b, c, d = map(float, input().split()) s1 = (a - c) * (a - c) s2 = (b - d) * (b - d) print("%.6f"%math.sqrt(s1+s2))
n, k = map(int, input().split()) argList = list(map(int, input().split())) print(sum([h >= k for h in argList]))
0
null
89,702,482,769,664
29
298
#!/usr/bin/env python3 # -*- coding: utf-8 -*- B = 4 F = 3 R = 10 SHARPS = 20 def main(): """ The function to be called when this script is run as a script. """ info_number = int(input()) given_info_str = (info.split() for info in ( input() for _ in range(info_number))) given_info_int = (list(map(int, info)) for info in given_info_str) houses = [[[0 for i in range(R)] for j in range(F)] for k in range(B)] for info in given_info_int: houses[info[0] - 1][info[1] - 1][info[2] - 1] += info[3] for num, building in enumerate(houses): for floor in building: print (" " + " ".join(map(str, floor))) if num < (B - 1): print("#" * 20) if __name__ == "__main__": main()
import math h=[int(input())for _ in range(2)] n=int(input()) print(math.ceil(n/max(h)))
0
null
44,859,478,296,468
55
236
from collections import Counter def main(): n = int(input()) s = [input() for _ in range(n)] s_c = Counter(s) s_c_max = s_c.most_common()[0][1] keys =[k for k, v in s_c.items() if v == s_c_max] keys_s = sorted(keys) print(*keys_s, sep='\n') if __name__ == '__main__': main()
rate = int(input()) print(10 - rate//200)
0
null
38,577,661,491,940
218
100
from collections import deque N,U,V = map(int, input().split()) U,V = U-1, V-1 E = [[] for _ in range(N)] for _ in range(N-1): a,b = map(int, input().split()) a,b = a-1, b-1 E[a].append(b) E[b].append(a) def BFS(root): D = [ 0 for _ in range(N) ] visited = [False for _ in range(N)] willSearch = [ False for _ in range(N)] Q = deque() Q.append(root) willSearch[root] = True while len(Q) > 0: now = Q.pop() visited[now] = True for nx in E[now]: if visited[nx] or willSearch[nx]: continue willSearch[nx] = True D[nx] = D[now] + 1 Q.append(nx) return D UD = BFS(U) VD = BFS(V) #print(UD) #print(VD) #初手で青木くんのPOINTにしか行けないケース if E[U] == [V]: print(0) exit(0) ans=0 for i in range(N): if UD[i]<=VD[i]: ans=max(ans,VD[i]-1) print(ans)
# F - Playing Tag on Tree # https://atcoder.jp/contests/abc148/tasks/abc148_f from heapq import heappop, heappush INF = float("inf") def dijkstra(n, G, s): dist = [INF] * n dist[s] = 0 hq = [(0, s)] while hq: d, v = heappop(hq) if dist[v] < d: continue for child, child_d in G[v]: if dist[child] > dist[v] + child_d: dist[child] = dist[v] + child_d heappush(hq, (dist[child], child)) return dist n, u, v = map(int, input().split()) graph = [[] for _ in range(n)] edge = [list(map(int, input().split())) for _ in range(n - 1)] for a, b in edge: graph[a - 1].append((b - 1, 1)) graph[b - 1].append((a - 1, 1)) from_u = dijkstra(n, graph, u - 1) from_v = dijkstra(n, graph, v - 1) # print(from_u) # print(from_v) fil = filter(lambda x : x[0] < x[1], [[fu, fv] for fu, fv in zip(from_u, from_v)]) sfil = sorted(list(fil), key=lambda x: [-x[1], -x[0]]) # print(sfil) print(sfil[0][1] - 1)
1
116,989,332,322,548
null
259
259
N = int(input()) A = [[[0] * 10, [0] * 10, [0] * 10], [[0] * 10, [0] * 10, [0] * 10], [[0] * 10, [0] * 10, [0] * 10], [[0] * 10, [0] * 10, [0] * 10]] for i in range(N): b, f, r, v = [int(j) for j in input().split()] A[b-1][f-1][r-1] += v for a, b in enumerate(A): for f in b: print(' ' + ' '.join([str(i) for i in f])) else: if a != len(A) - 1: print('#' * 20)
All = [[[0 for x in range(10)] for y in range(3)] for z in range(4)] N = int(input()) i = 0 while i < N: b, f, r, v = map(int,input().split()) All[b-1][f-1][r-1] += v i += 1 for x in range(4): for y in range(3): for z in range(10): print(" {}".format(All[x][y][z]), end = "") if z == 9: print("") if x != 3 and y == 2: for j in range(20): print("#", end = "") print("")
1
1,095,166,941,444
null
55
55
import sys def main(): n, x, y = map(int, sys.stdin.buffer.readline().split()) L = [0] * n for i in range(1, n): for j in range(i + 1, n + 1): d = j - i if i <= x and y <= j: d -= y - x - 1 elif i <= x and x < j < y: d = min(d, x - i + y - j + 1) elif x < i < y and y <= j: d = min(d, i - x + j - y + 1) elif x < i and j < y: d = min(d, i - x + y - j + 1) L[d] += 1 for a in L[1:]: print(a) main()
n,x,y=map(int,input().split()) x-=1 y-=1 half=(x+y)//2 ans=[0]*n for i in range(n): for j in range(i,n): if i<=x: if j<=half: ans[j-i]+=1 else: ans[x-i+1+abs(y-j)]+=1 elif x<i and i<=y: ans[min(j-i,i-x+1+abs(y-j))]+=1 else: ans[j-i]+=1 for i in range(1,n): print(ans[i])
1
43,821,736,574,070
null
187
187
i = 1 a = [] while True: x = input() if x == 0: break a.append(x) for i in range(len(a)): print 'Case ' + str(i+1) + ': ' + str(a[i])
i=0 while True: i+=1 a=input() if a==0: break else: print("Case "+str(i)+": "+str(a))
1
470,000,021,700
null
42
42
s = input() n = len(s) t = input() m = len(t) c_max = 0 for i in range(n - m + 1): c = 0 for j in range(m): if s[i + j] == t[j]: c += 1 if c > c_max: c_max = c print(m - c_max)
n = int(input()) s = list(input()) r = s.count('R') g = s.count('G') b = n - r - g ans = r*g*b for i in range(n-2): for j in range(i+1,i+((n-i-1)//2)+1): if s[i] != s[j] and s[i] != s[2*j - i] and s[j] != s[2*j - i]: ans -= 1 print(ans)
0
null
20,045,442,322,368
82
175
if __name__ == "__main__": A,B,C = map(int,input().split()) K = int(input()) count = 0 while A>=B: B *= 2 count += 1 while B>=C: C *= 2 count += 1 print("Yes" if count <= K else "No")
A, B, C = map(int, input().split()) K = int(input()) for i in range(K): if A >= B: B *= 2 continue if B >= C: C *= 2 continue if A < B and B < C: print('Yes') else: print('No')
1
6,856,558,306,874
null
101
101
import numpy as np from functools import * import sys sys.setrecursionlimit(100000) input = sys.stdin.readline def acinput(): return list(map(int, input().split(" "))) def II(): return int(input()) directions=np.array([[1,0],[0,1],[-1,0],[0,-1]]) directions = list(map(np.array, directions)) mod = 10**9+7 def factorial(n): fact = 1 for integer in range(1, n + 1): fact *= integer return fact def serch(x, count): #print("top", x, count) for d in directions: nx = d+x #print(nx) if np.all(0 <= nx) and np.all(nx < (H, W)): if field[nx[0]][nx[1]] == "E": count += 1 field[nx[0]][nx[1]] = "V" count = serch(nx, count) continue if field[nx[0]][nx[1]] == "#": field[nx[0]][nx[1]] = "V" count = serch(nx, count) return count K=int(input()) s = [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] print(s[K-1])
def main(): params = [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] return params[int(input())-1] print(main())
1
50,281,820,702,820
null
195
195
N = int(input()) a = list(map(int,input().split())) if not(1 in a): print(-1) exit(0) cnt = 0 for i in a: if i == cnt + 1: cnt += 1 print(N-cnt)
import bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) N = I() _a = LI() #AB = [LI() for _ in range(N)] #A,B = zip(*AB) a = np.array(_a) #C = np.zeros(N + 1) if not np.amin(a)==1: print(-1) exit() maxNumber = 1 for i in range(N): if a[i] == maxNumber: maxNumber += 1 print(N - (maxNumber-1)) # current = 0 # for i in range(1,200001): # position=[] # position = np.where(a[current:] == i) # if position ==[] or position[0] == []: # break # else: # current = position[0][0] # print(current) # if ans: # print('Yes') # else: # print('No')
1
114,824,245,845,140
null
257
257
from fractions import gcd a,b=map(int,input().split()) print(a*b//gcd(a,b))
import sys for line in sys.stdin: H, W = map(int, line.split()) if H == 0 and W == 0: break for _ in range(H): print( '#' * W ) print("")
0
null
56,911,826,200,852
256
49
N, K = map(int,input().split()) A = list(map(int,input().split())) B = [0];BB=[0] S = set([]);S.add(0) now = 0 Flag = False loop_start = -1 if K <= 2*pow(10,5)+10: for i in range(K): nxt = A[now]-1 BB.append(nxt) now = nxt #print(BB) print(BB[K]+1) exit() for i in range(N*2): nxt = A[now]-1 #print(now,nxt) if nxt in S: if Flag: if nxt == loop_start: #print(nxt,i) loop_cycle = i-loop_num break else: loop_start = nxt loop_num = i B.append(nxt) #print(loop_num,loop_start,B) Flag = True else: B.append(nxt);S.add(nxt) now = nxt loop_num += 1-loop_cycle #print(B,loop_start,loop_cycle,loop_num) loc = (K-loop_num)%loop_cycle+loop_num #print(loc) #print(len(B)) print(B[loc]+1)
N=int(input()) A=list(map(int,input().split())) for i in range(N): A[i] = [i+1, A[i]] A.sort(key=lambda x:x[1]) ans=[] for i in range(N): ans.append(A[i][0]) ans = map(str, ans) print(' '.join(ans))
0
null
101,826,726,829,700
150
299
moji = input() if moji.isupper(): print('A') else: print('a')
n = input() if n >= 'A' and n <= 'Z': print('A') if n >= 'a' and n <= 'z': print('a')
1
11,216,886,055,462
null
119
119
N = int(input()) lst = list(map(int, input().split())) c = True for i in lst: if i%2 ==0: if i%3 != 0 and i%5 != 0: c = False break if c: print('APPROVED') else: print('DENIED')
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())) seen = set() t = ini() for _ in range(t): s = ins() seen.add(s) print(len(seen))
0
null
49,545,226,914,394
217
165
N = int(input()) ans = 0 c = input() redNum = c.count("R") leftWhite = c.count("W", 0,redNum) rightRed = c.count("R", redNum,N) ans += min(leftWhite, rightRed) if leftWhite > rightRed: ans += (leftWhite - rightRed) print(ans)
input() A = [int(i) for i in input().split()] c = 0 def bubble_sort(A): global c flag = True while flag: flag = False for i in range(len(A)-1, 0, -1): if A[i] < A[i -1]: A[i], A[i -1] = A[i -1], A[i] c += 1 flag = True bubble_sort(A) print(*A) print(c)
0
null
3,140,813,439,358
98
14
from math import sqrt # Function to return count of Ordered pairs # whose product are less than N def countOrderedPairs(N): # Initialize count to 0 count_pairs = int(0) # count total pairs p = int(sqrt(N - 1)) + 1 q = N # q = int(sqrt(N)) + 2 for i in range(1, p, 1): for j in range(i, q, 1): if i * j > N-1: break # print(i,j) count_pairs += 1 #print(count_pairs) # multiply by 2 to get ordered_pairs count_pairs *= 2 #print(count_pairs) # subtract redundant pairs (a, b) where a==b. count_pairs -= int(sqrt(N - 1)) # return answer return count_pairs # Driver code N = int(input()) print(countOrderedPairs(N)) # ans=prime_factorize(N) # print(ans)
from math import atan2, degrees a,b,x = map(int, input().split()) s = x/a if x >= a**2*b/2: print(degrees(atan2(2*(a*b-s)/a, a))) else: print(degrees(atan2(b, 2*s/b)))
0
null
82,740,786,810,880
73
289
import math a, b, C=map(int, input().split()) print("{0:.5f}".format((1/2)*a*b*math.sin(C*math.pi/180.0))) print("{0:.5f}".format(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180)))) print("{0:.5f}".format(b*math.sin(C*math.pi/180.0)))
import math def float_print(v): print('{:.5f}'.format(v)) a, b, C = map(float, input().split()) C = math.radians(C) float_print(a * b * math.sin(C) / 2) float_print(a + b + math.sqrt(math.pow(a, 2) + math.pow(b, 2) - 2 * a * b * math.cos(C))) float_print(b * math.sin(C))
1
177,581,605,458
null
30
30
S,W = map(int, input().split()) print("suanfsea f e"[S<=W::2])
S,W=map(int,input().split()) if S<=W:print('unsafe') else:print('safe')
1
29,193,457,150,150
null
163
163
from itertools import product def makelist(BIT): LIST, tmp = [], s[0] for i, bi in enumerate(BIT, 1): if bi == 1: LIST.append(tmp) tmp = s[i] elif bi == 0: tmp = [t + sij for t, sij in zip(tmp, s[i])] else: LIST.append(tmp) return LIST def solve(LIST): CNT, tmp = 0, [li[0] for li in LIST] if any(num > k for num in tmp): return h * w for j in range(1, w): cal = [t + li[j] for t, li in zip(tmp, LIST)] if any(num > k for num in cal): CNT += 1 tmp = [li[j] for li in LIST] else: tmp = cal return CNT h, w, k = map(int, input().split()) s = [[int(sij) for sij in input()] for _ in range(h)] ans = h * w for bit in product([0, 1], repeat=(h - 1)): numlist = makelist(bit) ans = min(ans, solve(numlist) + sum(bit)) print(ans)
A,B = map(int, input().split()) C,D = map(int, input().split()) if D == 1: print("1") else: print("0")
0
null
86,204,570,720,128
193
264
a,b,c,d=input().split() a = int(a) b = int(b) c = int(c) d = int(d) z1 = a*c z2 = a*d z3 = b*c z4 = b*d l = [z1, z2, z3, z4] max_value = max(l) print(max_value)
import sys from functools import reduce def input(): return sys.stdin.readline()[:-1] a, b, c, d = map(int, input().split()) ans1 = a * c ans2 = b * d ans3 = b * c ans4 = a * d print(max([ans1, ans2, ans3, ans4]))
1
3,010,514,461,628
null
77
77
import sys from collections import deque, defaultdict, Counter from itertools import accumulate, product, permutations, combinations from operator import itemgetter from bisect import bisect_left, bisect_right from heapq import heappop, heappush from math import ceil, floor, sqrt, gcd, inf from copy import deepcopy import numpy as np import scipy as sp INF = inf MOD = 1000000007 s = input() tmp = 0 res = "ABC" if s == "ABC": res = "ARC" print(res)
S = input() if S == 'ABC': print('ARC') elif S == 'ARC': print('ABC') else: print('ABC または ARC を入力してください')
1
24,223,211,426,370
null
153
153
import sys sys.setrecursionlimit(10**8) def line_to_int(): return int(sys.stdin.readline()) def line_to_each_int(): return map(int, sys.stdin.readline().split()) def line_to_list(): return list(map(int, sys.stdin.readline().split())) def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)] # def dp(init, i, j): return [[init]*i for i2 in range(j)] #from collections import defaultdict #d = defaultdict(int) d[key] += value #from collections import Counter # a = Counter(A).most_common() # from itertools import accumulate #A = [0]+list(accumulate(A)) # import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a) x = line_to_list() print(x.index(0)+1)
X = list(map(int,input().split())) num = 1 for i in X: if i == 0: print(num) num += 1
1
13,455,809,189,792
null
126
126
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 = 10 ** 5 + 1 # N は必要分だけ用意する fact = [1, 1] factinv = [1, 1] inv = [0, 1] 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) N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() ans = 0 for ri in range(2): for i in range(N): now = cmb(i, K - 1, p) if ri == 1: now = - now ans += A[i] * now ans %= p A.sort(reverse=True) print(ans)
class Combination(): # nCr(mod p) #n<=10**6 def __init__(self, N, MOD): # cmbの前処理 self.mod = MOD self.FACT = [1, 1] # 階乗 self.INV = [0, 1] # 各iの逆元 self.FACTINV = [1, 1] # 階乗の逆元 for i in range(2, N + 1): self.FACT.append((self.FACT[-1] * i) % self.mod) self.INV.append(pow(i, self.mod - 2, self.mod)) self.FACTINV.append((self.FACTINV[-1] * self.INV[-1]) % self.mod) def count(self, N, R): # nCr(mod p) #前処理必要 if (R < 0) or (N < R): return 0 R = min(R, N - R) return self.FACT[N] * self.FACTINV[R] * self.FACTINV[N-R] % self.mod n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) mod = 10 ** 9 + 7 ans = 0 cmb = Combination(n, mod) for i in range(n): cnt = cmb.count(i, k - 1) - cmb.count(n - i - 1, k - 1) ans += a[i] * cnt % mod print(ans % mod)
1
96,095,826,001,448
null
242
242
S = list(input()) if S[-1] == S[-2] and S[-3] == S[-4]: print("Yes") else: print("No")
S = list(input()) a,b=S.pop(),S.pop() c,d=S.pop(),S.pop() if a==b and c==d: print("Yes") else: print("No")
1
41,953,640,609,310
null
184
184
import math dig_six = math.radians(60) def koch(d, p1, p2): if d == 0: return d #calc s, u, t from p1, p2 s_x = (2*p1[0]+1 * p2[0]) / 3 s_y = (2*p1[1]+1 * p2[1]) / 3 s = (s_x, s_y) t_x = (1*p1[0]+2 * p2[0]) / 3 t_y = (1*p1[1]+2 * p2[1]) / 3 t = (t_x, t_y) u_x = (t_x - s_x)*math.cos(dig_six) - (t_y - s_y)*math.sin(dig_six) + s_x u_y = (t_x - s_x)*math.sin(dig_six) + (t_y - s_y)*math.cos(dig_six) + s_y u = (u_x, u_y) koch(d-1, p1, s) print (' '.join([str(x) for x in s])) koch(d-1, s, u) print (' '.join([str(x) for x in u])) koch(d-1, u, t) print (' '.join([str(x) for x in t])) koch(d-1, t, p2) if __name__ == '__main__': iterate = int(input()) p1 = (0.0, 0.0) p2 = (100.0, 0.0) print (' '.join([str(x) for x in p1])) koch(iterate, p1, p2) print (' '.join([str(x) for x in p2]))
import math def koch(n, p1, p2): if n == 0: return s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3] t = [(p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3] u = [(t[0] - s[0]) * math.cos(math.radians(60)) - (t[1] - s[1]) * math.sin(math.radians(60)) + s[0], (t[0] - s[0]) * math.sin(math.radians(60)) + (t[1] - s[1]) * math.cos(math.radians(60)) + s[1]] koch(n - 1, p1, s) print(s[0], s[1]) koch(n - 1, s, u) print(u[0], u[1]) koch(n - 1, u, t) print(t[0], t[1]) koch(n - 1, t, p2) n = int(input()) p1 = (0, 0) p2 = (100, 0) print(p1[0], p1[1]) koch(n, p1, p2) print(p2[0], p2[1])
1
121,445,390,822
null
27
27
import math from decimal import Decimal A, B = list(map(str, input().split())) print(math.floor(Decimal(A) * Decimal(B)))
def main(istr, ostr): x, y = istr.readline().strip().split() a = int(x) b0, _, b1, b2 = y b0, b1, b2 = list(map(int, [b0, b1, b2])) c = a * (100 * b0 + 10 * b1 + b2) res = c // 100 print(res, file=ostr) if __name__ == "__main__": import sys main(sys.stdin, sys.stdout)
1
16,557,343,734,728
null
135
135
def main(): N = [] while True: x = input() if x == '0': break else: N.append(x) for n in N: ans = sum(map(int, list(n))) print(ans) main()
import math n=int(input()) x=math.ceil(n/1.08) if(math.floor(1.08*x)==n): ans=x else: ans=str(":(") print(ans)
0
null
63,367,371,031,970
62
265
H,W,K=map(int,input().split()) S=[[int(s) for s in input()] for i in range(H)] ans=1000000 for i in range(2**(H-1)): tmp=0 L=[] for j in range(H-1): if i>>j&1: L.append(j) tmp+=len(L) L.append(H-1) c=[0]*len(L) for k in range(W): h=0 c1=[0]*len(L) for l in range(len(L)): for m in range(h,L[l]+1): c1[l]+=S[m][k] h=L[l]+1 p=0 for l in range(len(L)): if c1[l]>K: p=2 break elif c[l]+c1[l]>K: p=1 else: c[l]+=c1[l] if p==2: break elif p==1: c=[i for i in c1] tmp+=1 else: ans=min(ans,tmp) print(ans)
import sys input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode() def main(): l,r,d=MI() ans=(r-l)//d a=l+ans*d if r//d*d==-(-a//d)*d: ans+=1 print(ans) if __name__ == "__main__": main()
0
null
28,240,357,189,860
193
104
from sys import exit a, b, c, k = map(int, input().split()) total = 0 if a >= k: print(k) exit() else: total += a k -= a if b >= k: print(total) exit() else: k -= b print(total - k)
d = {n: 'hon' for n in "24579"} d.update({n: 'pon' for n in "0168"}) d.update({"3": 'bon'}) print(d[input()[-1]])
0
null
20,459,375,108,200
148
142
for i in xrange(1, 10): for j in xrange(1, 10): print "%dx%d=%d" % (i, j, i * j)
def __main(): x = 1; while x <= 9 : y = 1; while y <= 9 : z = x * y; print(str(x) + "x" + str(y) + "=" + str(z) ) y = y + 1 x = x + 1 __main()
1
2,633,280
null
1
1
h,n = map(int, input().split()) a = [int(i) for i in input().split()] print("No" if sum(a)<h else "Yes")
H, N = map(int, input().split()) As = list(map(int, input().split())) sumA = sum(As) if sumA >= H: print('Yes') else: print('No')
1
77,661,643,814,588
null
226
226
N, K = map(int, input().split()) d = [0]*K A = [] for i in range(K): d[i] = int(input()) A.append(list(map(int, input().split()))) ans = 0 for i in range(1,N+1): got = False for j in A: for k in j: if i == k: got = True if not got: ans += 1 print(ans)
import sys i=1 for s in sys.stdin: n = int(s) if n == 0: break print("Case ",i,": ",n,sep="") i += 1
0
null
12,440,667,716,620
154
42
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')
s = input() n = len(s) def check(r): if r == r[::-1]: return True print("Yes" if check(s) and check(s[:(n-1)//2]) and check(s[((n-1)//2) + 1:]) else "No")
1
46,230,252,146,380
null
190
190
import math import sys #t=int(sys.stdin.readline()) t=1 for _ in range(t): n,m=map(int,input().split()) print(math.ceil(n/m))
H, A = map(int, input().split()) count = 0 while True: H -= A count += 1 if H <= 0: print(count) exit()
1
77,256,455,317,920
null
225
225
def rectangle(a, b): S = a * b L = a*2 + b*2 print(S, L) a, b =[int(x) for x in input().split()] rectangle(a, b)
s = input() if s in ['hi','hihi','hihihi','hihihihi','hihihihihi']: print('Yes') else: print('No')
0
null
26,896,409,932,630
36
199
#!/usr/bin/env python3 def solve(a,b): str1 = str(a)*b str2 = str(b)*a if str1 < str2: return str1 else: return str2 def main(): a,b = map(int,input().split()) print(solve(a,b)) return if __name__ == '__main__': main()
a,b=map(int,input().split()) x=str(a)*b y=str(b)*a if x<y: print(x) else: print(y)
1
84,179,490,872,580
null
232
232
n = int(input()) a = list(map(int, input().split())) N = sum(a) s = 1 S = 1 if a[0] > 1 or (a[0] >= 1 and len(a) > 1): S = -1 else: for i in range(1,n+1): if a[i] > 2*s: S = -1 break if s*2 <= N: S += s*2 s += s - a[i] else: S += N s += N - s - a[i] N -= a[i] print(S)
def main(): a,b,c = map(int,input().split()) s =[list(map(str,input()))for i in range(a)] cnt =0 count=0 for i in range(2**a): for j in range(2**b): cnt=0 for ia in range(a): for ib in range(b): if not i &(1<<ia) and not j&(1<<ib): if s[ia][ib] =='#': cnt+=1 if cnt ==c: count+=1 print(count) if __name__ =='__main__': main()
0
null
13,905,942,146,550
141
110
#93 B - Iron Bar Cutting WA (hint) N = int(input()) A = list(map(int,input().split())) # 差が最小の切れ目を見つける length = sum(A) left = 0 dist = 0 mdist = length midx = 0 for i,a in enumerate(A): left += a right = length - left dist = abs(left - right) if dist < mdist: mdist = dist midx = i ans = mdist print(ans)
from math import floor X = int(input()) deposit, year = 100, 0 while deposit < X: deposit += deposit // 100 year += 1 print(year)
0
null
84,540,727,610,524
276
159
import math p = 100 for i in range(int(input())): p = math.ceil(p * 1.05) print(p * 1000)
# Debt Hell n = int(input()) value = 100000 for i in xrange(n): value *= 1.05 if value % 1000 != 0: value = int(value / 1000 + 1) * 1000 print value
1
955,868,280
null
6
6
def linear_search(num_list,target): for num in num_list: if num == target: return 1 return 0 n = input() num_list = list(map(int,input().split())) q = input() target_list = list(map(int,input().split())) ans = 0 for target in target_list: ans += linear_search(num_list,target) print(ans)
N = input() S = set(map(int, input().split())) Q = input() T = set(map(int, input().split())) intersection = S & T print(len(intersection))
1
64,801,659,872
null
22
22
n=input() num=int(n) print(num*num*num)
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) n,m = map(int, input().split()) f = [] for x in range(m): ff = [] a,b = map(int, input().split()) ff.append(a) ff.append(b) f.append(ff) uf = UnionFind(n) for i in range(m): a = f[i][0] - 1 b = f[i][1] - 1 uf.union(a, b) ans = 0 for i in range(n): ans = max(ans, uf.size(i)) print(ans)
0
null
2,141,519,525,810
35
84
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def main(): N, K = map(int, input().split()) ans = N % K ans = min(ans, abs(ans - K)) print(ans) if __name__ == '__main__': main()
N,K = map(int,input().split()) def solve(n,k): n %= k return min(n,abs(n-k)) print(solve(N,K))
1
39,274,780,960,830
null
180
180
#ABC165-E Rotation Matching """ 各頂点を円形に並べた時に、距離が等しくならないようにm個の辺を張れば良い。 """ import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 n,m = map(int,readline().split()) mod = n lst1 = [] for i in range(m): lst1.append(i) lst2 = [] for i in range(m): lst2.append(2*m-1-lst1[i]) for i in range(m//2): lst2[i] -= 2*m+1 for i,j in zip(lst1,lst2): print(i%mod+1,j%mod+1)
X, Y = map(int, input().split()) ans = "No" for i in range(101) : for j in range(101) : if(i + j != X) : continue if(2*i + 4*j != Y) : continue ans = "Yes" break print(ans)
0
null
21,167,304,076,810
162
127
N, K = map(int, input().split()) p = list(map(int, input().split())) import numpy as np data = np.array(p) + 1 Pcum = np.zeros(N + 1, np.int32) Pcum[1:] = data.cumsum() length_K_sums = Pcum[K:] - Pcum[0:-K] print(np.max(length_K_sums)/2)
import sys input=sys.stdin.readline import math from collections import defaultdict,deque from itertools import permutations ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) ips=lambda:input().split() """========main code===============""" t,k=ml() n=ll() ans=0 lol=0 for i in range(t): if(i>=k): lol+=((n[i]*(n[i]+1))//2)/n[i] lol-=((n[i-k]*(n[i-k]+1))//2)/n[i-k] else: lol+=((n[i]*(n[i]+1))//2)/n[i] ans=max(ans,lol) print(ans)
1
74,891,693,902,792
null
223
223
N, K = map(int, input().split()) s = N//K s1 = abs(N - K*s) s2 = abs(N - K*(s+1)) print(min(s1, s2))
N, K = map(int, input().split()) t = N % K print(min(t, K-t))
1
39,217,669,447,424
null
180
180
import math a,b,h,m = map(int, input().split()) xh = a*math.cos((60*h+m)/360*math.pi) yh = a*math.sin((60*h+m)/360*math.pi) xm = b*math.cos(m/30*math.pi) ym = b*math.sin(m/30*math.pi) print( ((xh-xm)**2+(yh-ym)**2)**0.5 )
AA1 = input().split() AA2 = input().split() AA3 = input().split() AA4 = [AA1[0],AA2[0],AA3[0]] AA5 = [AA1[1],AA2[1],AA3[1]] AA6 = [AA1[2],AA2[2],AA3[2]] AA7 = [AA1[0],AA2[1],AA3[2]] AA8 = [AA1[2],AA2[1],AA3[0]] N = int(input()) list1 = [] for i in range(N): b = input() list1.append(b) count = 0 bingo =0 for i in list1: if i in AA1: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA2: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA3: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA4: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA5: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA6: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA7: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA8: count +=1 if count ==3 : bingo =1 else: count =0 if bingo ==1: print('Yes') else: print('No')
0
null
39,841,492,148,930
144
207
n, m, k = map(int, input().split()) mod = 998244353 def powerDX(n, r, mod): if r == 0: return 1 if r%2 == 0: return powerDX(n*n % mod, r//2, mod) % mod if r%2 == 1: return n * powerDX(n, r-1, mod) % mod def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod g1 = [1, 1] g2 = [1, 1] inverse = [0, 1] for i in range(2, n + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) ans = 0 for i in range(0, k+1): ans += m*cmb(n-1, i, mod)*pow(m-1, n-i-1, mod) ans %= mod print(ans)
N = int(input()) S = list(input() for _ in range(N)) X = [] for s in S: l,r = 0,0 for c in s: if c == ")": if r > 0: r -= 1 else: l += 1 else: r += 1 X.append([l,r]) X.sort(key = lambda x:x[0]) Y = [] L = 0 for p,q in X: if p > L: print("No") quit() if q >= p: L -= p L += q else: Y.append([p,q]) Y.sort(key = lambda x:-x[1]) for a,b in Y: if a > L: print("No") quit() L -= a L += b if L: print("No") else: print("Yes")
0
null
23,290,405,914,580
151
152
#import numpy as np import sys, math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial#, gcd from bisect import bisect_left #bisect_left(list, value) sys.setrecursionlimit(10**7) enu = enumerate MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] pl = lambda x: print(*x, sep='\n') N, K = map(int, input().split()) d = [0]*(K+1) for i in range(1, K+1): val = K//i d[i] = pow(val, N, MOD) # print(d) for i in range(K, 0, -1): # print('i', i) for j in range(K//i, 1, -1): # print(' j', j) # print(i, i*j) d[i] -= d[i*j] # print(d) res = 0 for i, v in enu(d): res += i*v res %= MOD print(res)
N, K = map(int, input().split()) li = [0]*(K+1) out = 0 mod = 10**9+7 for i in range(K, 0, -1): li[i] = pow(K//i, N, mod) for j in range(i*2, K+1, i): li[i] -= li[j] out += li[i] * i print(out%mod)
1
36,730,889,294,814
null
176
176
import math n = int(input()) mod = 1000000007 all = pow(10, n, mod) s1 = 2 * pow(9, n, mod) % mod s2 = pow(8, n, mod) % mod ans = int(all - s1 + s2)%mod if ans < 0: ans += mod print(ans%mod)
import collections N=int(input()) A=[x for x in input().split()] c = collections.Counter(A) for i in range(N): print(c["{}".format(str(i+1))])
0
null
17,761,486,527,652
78
169
from collections import defaultdict n,k=map(int,input().split()) a=list(map(int,input().split())) a[0]=(a[0]-1)%k for i in range(n-1):a[i+1]=(a[i+1]+a[i]-1)%k d=defaultdict(int) ans=0 d[0]=1 for i in range(n): if i==k-1:d[0]-=1 if i>=k:d[a[i-k]]-=1 ans+=d[a[i]] d[a[i]]+=1 print(ans)
import sys # input = sys.stdin.buffer.readline def getN(): return int(input()) def getNM(): return map(int, input().split()) def getlist(): return list(map(int, input().split())) import math import bisect import heapq from collections import defaultdict, Counter, deque MOD = 10**9 + 7 INF = 10**15 def main(): n, k = getlist() nums = getlist() acc = {0: [0]} tmp = 0 for i, num in enumerate(nums): tmp += num tmp %= k tgt = ((tmp - i -1 + k) % k) if tgt not in acc: acc[tgt] = [i+1] else: acc[tgt].append(i+1) # acc.append(tmp-i-1) # cnt = Counter(acc) ans = 0 for v in acc.values(): for j, cur in enumerate(v): ins = bisect.bisect_left(v, cur+k) # print(ins, j) ans += ins - j - 1 # ans += ((v-1) * v) // 2 # print(acc) print(ans) if __name__ == '__main__': main() """ 9999 3 2916 """
1
137,751,744,047,174
null
273
273
import math z = raw_input() x1, y1, x2, y2 = z.split() x1 = float(x1) x2 = float(x2) y1 = float(y1) y2 = float(y2) d = math.sqrt((x2 - x1) * (x2-x1) + (y2 - y1) * (y2 - y1)) print ("%lf" %(d))
a,b,c,d=map(float,input().split()) x=abs(a-c) y=abs(b-d) z=x**2+y**2 print(pow(z,0.5))
1
154,648,871,520
null
29
29
n = int(input()) ans = 0 for a in range(1,n): for b in range(1,n): c = n-a*b if c <= 0: break ans += 1 print(ans)
def selection_sort(A, N): cnt = 0 for i in range(N): min_j = i for j in range(i, N): if A[j] < A[min_j]: min_j = j if i != min_j: A[i], A[min_j] = A[min_j], A[i] cnt += 1 return A, cnt N = int(input().rstrip()) A = list(map(int, input().rstrip().split())) A, cnt = selection_sort(A, N) string = list(map(str, A)) print(' '.join(string)) print(cnt)
0
null
1,287,511,536,672
73
15
# 深さ優先探索 from sys import setrecursionlimit def genid(a, b): if b < a: a, b = b, a return a * 100000 + b def paint(currentNode, usedColor, parentNode, edges, colors): color = 1 for childNode in edges[currentNode]: if childNode == parentNode: continue if color == usedColor: color += 1 colors[genid(currentNode, childNode)] = color paint(childNode, color, currentNode, edges, colors) color += 1 setrecursionlimit(10 ** 6) N = int(input()) ab = [list(map(int, input().split())) for _ in range(N - 1)] edges = [[] for _ in range(N)] for a, b in ab: edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) colors = {} paint(0, -1, -1, edges, colors) print(max(len(e) for e in edges)) for a, b in ab: print(colors[genid(a - 1, b - 1)])
N = int(input()) a = list(map(int,input().split())) i=0 for x,y in enumerate (a): b=x+1 if b%2!=0 and y%2!=0: i+=1 print(i)
0
null
71,921,196,592,726
272
105
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush import math #inf = 10**17 #mod = 10**9 + 7 n,t = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort(key=lambda x: x[1]) ab.sort(key=lambda x: x[0]) dp = [-1]*(t+1) dp[0] = 0 for a, b in ab: for j in range(t-1, -1, -1): if dp[j] >= 0: if j+a<=t: dp[j+a] = max(dp[j+a], dp[j]+b) else: dp[-1] = max(dp[-1], dp[j]+b) print(max(dp)) if __name__ == '__main__': main()
import math #import numpy as np import queue from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) def main(): n,t = map(int,ipt().split()) dp = [[0,0] for i in range(t)] for _ in range(n): a,b = map(int,ipt().split()) for i in range(t-1,a-1,-1): di = dp[i][1] dpi = dp[i-a][1]+b if di < dpi: dp[i][1] = dpi for i in dp: if i[1] < i[0]+b: i[1] = i[0]+b for i in range(t-1,a-1,-1): di = dp[i][0] dpi = dp[i-a][0]+b if di < dpi: dp[i][0] = dpi print(dp[t-1][1]) return if __name__ == '__main__': main()
1
151,642,934,208,700
null
282
282
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): A, B = map(int, readline().split()) print(max(A - 2 * B, 0)) if __name__ == '__main__': main()
A,B=map(int,input().strip().split()) print(max(A-2*B,0))
1
166,163,240,778,270
null
291
291
x = raw_input() a = int (x)**3 print a
x=int(input()) S=x*x*x print(S)
1
277,188,452,550
null
35
35
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) inf = 10**17 mod = 10**9+7 n, k = map(int, input().split()) r, s, p = map(int, input().split()) t = input().rstrip() memo = [None] * n ans = 0 for i in range(n): if t[i] == 'r': if i - k < 0 or (0 <= i - k and memo[i - k] != 'p'): ans += p memo[i] = 'p' elif n <= i + k or (i + k < n and t[i + k] != 's'): memo[i] = 'r' else: memo[i] = 's' if t[i] == 's': if i - k < 0 or (0 <= i - k and memo[i - k] != 'r'): ans += r memo[i] = 'r' elif n <= i + k or (i + k < n and t[i + k] != 'p'): memo[i] = 's' else: memo[i] = 'p' if t[i] == 'p': if i - k < 0 or (0 <= i - k and memo[i - k] != 's'): ans += s memo[i] = 's' elif n <= i + k or (i + k < n and t[i + k] != 'r'): memo[i] = 'p' else: memo[i] = 'r' print(ans)
K = int(input()) a=[7 % K] for i in range(1, K): a.append((10*a[i-1] + 7) % K) flag = False for i in range(len(a)): if a[i] == 0: print(i+1) flag = True break if not flag: print(-1)
0
null
56,161,674,055,648
251
97
a=int(input()) hours=a//3600 minutes_num=a%3600 minutes=minutes_num//60 seconds=a%60 print(str(hours)+":"+str(minutes)+":"+str(seconds))
x = int(input().rstrip()) if x >= 30: print("Yes") else: print("No")
0
null
3,061,272,890,368
37
95
while True: s = raw_input() if '-' == s: break m = input() for a in range(m): h = input() s = s[h:len(s)]+s[:h] print s
from collections import Counter S = input() MOD = 2019 div10 = 202 # modInverse(10, MOD). Note MOD is not prime so can't use FLT! def solve1(S): # Naive implementation counts = [0 for i in range(MOD)] total = 0 for d in S: d = int(d) nextCounts = [0 for i in range(MOD)] nextCounts[d] += 1 for k, v in enumerate(counts): nextCounts[(10 * k + d) % MOD] += v counts = nextCounts total += counts[0] return total def solve2(S): # Instead of shuffling the entire counts, update how we index into counts instead # The cumulative shuffle function forward is something like a * index + b for some calculable a, b # Then indexing into counts[t][x] is same as indexing into counts[0][(x - b) / a] negPowTen = 1 # our a prefix = 0 # our b counts = [0 for i in range(MOD)] total = 0 for d in S: d = int(d) prefix = (10 * prefix + d) % MOD negPowTen = (negPowTen * div10) % MOD counts[((d - prefix) * negPowTen) % MOD] += 1 total += counts[((0 - prefix) * negPowTen) % MOD] return total def solve3(S): # Alternative solution, precompute prefixes, p[i+1] == (10 * p[i] + S[i]) % MOD # Then you have for S = '1817181712114' # p[1] = 1 # p[2] = 18 # p[3] = 181 # p[4] = 1817 # etc # Then want to count all i j such that: # (p[j] - p[i] * pow(10, j - i)) % M == 0 # Which is equivalent to # (p[j] * pow(10, -j) - p[i] * pow(10, -i) % M == 0 negPowTen = 1 total = 0 prefix = 0 counts = [0 for i in range(MOD)] counts[0] = 1 for d in S: prefix = (prefix * 10 + int(d)) % MOD key = (prefix * negPowTen) % MOD total += counts[key] counts[key] += 1 negPowTen = (negPowTen * div10) % MOD return total def solve4(S): # Compute all suffixes instead # S = '1817181712114' # suf[1] = 4 # suf[2] = 14 # suf[3] = 114 # suf[4] = 2114 # # Difference of suffixes is almost correct but has extra 10s. # For example 2114 to 114 is the string 2 but our difference returns 2000. # Luckily 2 and 5 aren't divisible by 2019 so the extra 10s don't matter when counting. N = len(S) suf = 0 powTen = 1 counts = [0 for i in range(MOD)] total = 0 counts[0] = 1 for i in range(N): d = int(S[N - 1 - i]) suf = (powTen * d + suf) % MOD total += counts[suf] counts[suf] += 1 powTen = (powTen * 10) % MOD return total #assert solve1(S) == solve2(S) == solve3(S) == solve4(S) ans = solve4(S) print(ans)
0
null
16,242,616,666,780
66
166
t,T,a,A,b,B=map(int,open(0).read().split()) x,y=(b-a)*t,(A-B)*T if y-x==0: r="infinity" else: s,t=divmod(x,y-x) r=max(0,s*2+(t!=0)) print(r)
t1,t2 = map(int,input().split()) a1,a2 = map(int,input().split()) b1,b2 = map(int,input().split()) if a1*t1 + a2*t2 == b1*t1 + b2*t2: print("infinity") else: A = a1*t1 + a2*t2 B = b1*t1 + b2*t2 M1,m1 = max(a1*t1,b1*t1),min(a1*t1,b1*t1) M2,m2 = max(A,B),min(A,B) gap1,gap2 = M1-m1,M2-m2 Mv,mv = max(a1,b1),min(a1,b1) vgap = Mv-mv possible = vgap*t1 count = possible//gap2 if possible%gap2 == 0: pitta = 1 else: pitta = 0 if (a1*t1 > b1*t1 and A > B) or (a1*t1 < b1*t1 and A < B): print(0) elif (a1*t1 > b1*t1 and A < B) or (a1*t1 < b1*t1 and A > B): if pitta == 1: print(1+count*2-1) else: print(1+count*2)
1
131,594,770,930,908
null
269
269
N=int(input()) A=N//2+N%2 print(A)
#!/usr/bin/env python3 from networkx.utils import UnionFind import sys def input(): return sys.stdin.readline().rstrip() def main(): n,m=map(int, input().split()) uf = UnionFind() for i in range(1,n+1): _=uf[i] for _ in range(m): a,b=map(int, input().split()) uf.union(a, b) # aとbをマージ print(len(list(uf.to_sets()))-1) #for group in uf.to_sets(): # すべてのグループのリストを返す #print(group) if __name__ == '__main__': main()
0
null
30,615,796,388,800
206
70
X,K,D = map(int,input().split()) X = abs(X) ans = 0 if X>=D and D*K<=X: ans = X - D*K if X>=D and D*K>X: K=K-int(X/D) X=X%D if K%2==0: ans=X else: ans = abs(X-D) if X<D: if K%2==0: ans = X else: ans = abs(X-D) print(ans)
X,K,D = map(int,input().split()) X = abs(X) ans = 0 if (X // D) >= K: ans = X - (K * D) elif (X // D) % 2 == 0: if K % 2 == 0: ans = X % D else: ans = abs((X % D) - D) else: if K % 2 ==1: ans = X % D else: ans = abs((X % D) - D) print(ans)
1
5,284,767,117,700
null
92
92
A,B,C,K = map(int,input().split()) score = 0 if A<K: K -= A score += A else: score += K print(score) exit() if B<K: K -= B else: print(score) exit() score -= min(K,C) print(score)
import queue h,w=map(int,input().split()) s=[] for _ in range(h): s.append(input()) ans=0 for i in range(h): for j in range(w): if s[i][j]==".": seen=[[0 for _ in range(w)] for _ in range(h)] length=[[0 for _ in range(w)] for _ in range(h)] q=queue.Queue() q.put([i,j]) seen[i][j]=1 while not q.empty(): ci,cj=q.get() for ni,nj in [[ci-1,cj],[ci+1,cj],[ci,cj-1],[ci,cj+1]]: if 0<=ni<h and 0<=nj<w and s[ni][nj]=="." and seen[ni][nj]==0: q.put([ni,nj]) length[ni][nj]=length[ci][cj]+1 seen[ni][nj]=1 ans=max(ans,length[ci][cj]) print(ans)
0
null
58,138,856,144,250
148
241