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
from sys import stdin,stdout st=lambda:list(stdin.readline().strip()) li=lambda:list(map(int,stdin.readline().split())) mp=lambda:map(int,stdin.readline().split()) inp=lambda:int(stdin.readline()) pr=lambda n: stdout.write(str(n)+"\n") mod=1000000007 INF=float('inf') for _ in range(1): s=st() if s[-1]=='s': print(''.join(s)+'es') else: print(''.join(s)+'s')
d, t, s = map(int, input().split(" ")) ans = "Yes" if d <= t*s else "No" print(ans)
0
null
2,945,765,035,190
71
81
# -*- coding:utf-8 -*- import sys def cross_section_diagram(diagram): stack = [] area = [] for i, ch in enumerate(diagram): if ch == "\\": stack.append(i) elif ch == "/": if stack: point = stack.pop() area.insert(0, (point, i - point)) else: pass result = [] if area: p1, cnt1 = area.pop(0) for p2, cnt2 in area: if p1 < p2: cnt1 += cnt2 else: result.insert(0, cnt1) p1 = p2 cnt1 = cnt2 result.insert(0, cnt1) print(sum(result)) result.insert(0, len(result)) print(" ".join([str(n)for n in result])) return result if __name__ == "__main__": diagram = [val for val in sys.stdin.read().splitlines()] cross_section_diagram(diagram[0])
W=input() s=0 while True: T=list(input().split()) if T==['END_OF_TEXT']: break else: for i in T: if i.lower()==W.lower(): s+=1 print(s)
0
null
950,222,005,278
21
65
import sys for l in sys.stdin: n, m = map(int, l.split()) print(len(str(n+m)))
try: s = [] while True: l = input().split() t = int(l[0]) + int(l[1]) n = str(t) print(len(n)) except EOFError: pass
1
156,808,928
null
3
3
from sys import stdin, setrecursionlimit def gcd(x, y): if x % y == 0: return y return gcd(y, x % y) def main(): input = stdin.buffer.readline a, b = map(int, input().split()) print(a * b // gcd(a, b)) if __name__ == "__main__": setrecursionlimit(10000) main()
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) A, B = mapint() from math import gcd print(A*B//gcd(A, B))
1
113,520,716,388,310
null
256
256
import math h = int(input()) cnt = 0 while h > 1: h = h // 2 cnt += 1 ans = 0 for i in range(cnt+1): ans += 2 ** i print(ans)
h = int(input()) count = 0 for i in range(40): count += 2**i if h >= 2 ** i and h < 2 ** (i+1): break print(count)
1
79,898,164,682,010
null
228
228
S = input() length = len(S) print('x' * length)
import numpy as np N=int(input()) A=list(map(int,input().split())) SUM=sum(A) Q=int(input()) List=np.array([0 for _ in range(10**5+1)]) for a in A: List[a]+=1 for q in range(Q): B,C=map(int,input().split()) SUM-=B*List[B] SUM+=C*List[B] List[C]+=List[B] List[B]=0 print(SUM)
0
null
42,361,999,793,960
221
122
#!/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, X: "List[int]"): return min([sum([(x-i)**2 for x in X]) for i in range(1, 100+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() N = int(next(tokens)) # type: int X = [int(next(tokens)) for _ in range(N)] # type: "List[int]" print(f'{solve(N, X)}') if __name__ == '__main__': main()
n = int(input()) x = [int(y.strip()) for y in input().split()] lower = min(x) upper = max(x) i = lower ans = 10000*100 for i in range(upper+1): ttl = 0 for j in x: dist = (j - i)**2 ttl = ttl + dist if ttl < ans: ans = ttl print(ans)
1
65,254,120,342,372
null
213
213
x,k,d = map(int, input().split()) if x == 0: if k % 2 == 1: x = d elif x > 0: if x >= k*d: x -= k*d else: n = x//d x -= n*d k -= n if k%2 ==1: x -= d else: if x <= -(k*d): x += k*d else: n = abs(x)//d x += n*d k -= n if k%2 ==1: x += d print(abs(x))
startX, countK, distanceD = map(int, input().split()) n = int(abs(startX) / distanceD) ans = abs(startX) % distanceD if n > countK: ans += distanceD * (n - countK) else: if (countK - n) % 2 == 1: ans= abs(ans - distanceD) print(ans)
1
5,233,360,793,440
null
92
92
a = int(input()) print(a*((a+1)*(a+1)-a))
from collections import namedtuple Task = namedtuple('Task', 'name time') class Queue: def __init__(self, n): self.n = n self._l = [None for _ in range(self.n + 1)] self._head = 0 self._tail = 0 def enqueue(self, x): self._l[self._tail] = x self._tail += 1 if self._tail > self.n: self._tail -= self.n def dequeue(self): if self.isEmpty(): raise IndexError("pop from empty queue") else: e = self._l[self._head] self._l[self._head] = None self._head += 1 if self._head > self.n: self._head -= self.n return e def isEmpty(self): return self._head == self._tail def isFull(self): return self._tail == self.n if __name__ == '__main__': n, q = map(int, input().split()) queue = Queue(n+1) for _ in range(n): name, time = input().split() time = int(time) queue.enqueue(Task(name=name, time=time)) now = 0 while not queue.isEmpty(): task = queue.dequeue() t = task.time if t <= q: now += t print(task.name, now) else: now += q queue.enqueue(Task(task.name, t - q))
0
null
5,088,569,592,304
115
19
import sys input = sys.stdin.buffer.readline N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) A = sorted(A) F = sorted(F)[::-1] left = -1 right = max(A) * max(F) while left + 1 < right: mid = (left + right) // 2 tmp = 0 for i in range(N): a, f = A[i], F[i] if a * f > mid: tmp += -(-(a * f - mid) // f) if tmp <= K: right = mid else: left = mid print(right)
import sys def main(): input = sys.stdin.readline n, k = map(int, input().split()) a = [int(x) for x in input().split()] f = [int(x) for x in input().split()] a.sort(reverse=True) f.sort() l, r = -1, pow(10, 12)+1 while r-l > 1: judge = (r+l)//2 sub = 0 for i in range(n): if a[i]*f[i] <= judge: continue sub += a[i]-judge//f[i] if sub <= k: r = judge else: l = judge print(r) if __name__ == "__main__": main()
1
164,529,264,258,242
null
290
290
import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int, readline().split())) if N % 2 == 0: dp = [[0, 0] for i in range(N)] dp[1] = [A[0], A[1]] for i in range(3, N, 2): dp[i][0] = dp[i - 2][0] + A[i - 1] dp[i][1] = max(dp[i - 2][0] + A[i], dp[i - 2][1] + A[i]) print(max(dp[N - 1])) else: dp = [[0, 0, 0] for i in range(N)] dp[0] = [A[0], 0, 0] for i in range(2, N, 2): dp[i][0] = dp[i - 2][0] + A[i] dp[i][1] = max(dp[i - 2][0], dp[i - 2][1] + A[i - 1]) dp[i][2] = max(dp[i - 2][1] + A[i], dp[i - 2][2] + A[i]) print(max(dp[N - 1]))
def swap(l, i, j): tmp = l[i] l[i] = l[j] l[j] = tmp return l def selection_sort(l): cnt = 0 for i in range(len(l)): minj = i for j in range(i + 1, len(l)): if l[j] < l[minj]: minj = j if i != minj: swap(l, i, minj) cnt += 1 return l, cnt if __name__ == '__main__': N = int(input()) l = list(map(int, input().split())) sl, cnt = selection_sort(l) print(' '.join(map(str, sl))) print(cnt)
0
null
18,645,828,982,690
177
15
a,b,c,d=map(float,input().split()) e=(c-a)**2 f=(d-b)**2 print(f"{(e+f)**(1/2):.8f}")
MOD = 10**9+7 n = int(input()) a = list(map(int, input().split())) cnt = [0 for _ in range(n)] ans = 1 for x in a: if x > 0: ans *= cnt[x-1] - cnt[x] else: ans *= 3 - cnt[0] cnt[x] += 1 ans %= MOD print(ans)
0
null
65,425,490,984,448
29
268
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 h, w, k = list(map(int, readline().split())) s = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)] cnt = 0 ls = [] lsd = -1 for i in range(h): if s[i].count("#") != 0: lsd = i is_f = True cnt += 1 for j in range(w): if s[i][j] == "#": if is_f: is_f = False else: cnt += 1 s[i][j] = cnt while ls: ti = ls.pop() for j in range(w): s[ti][j] = s[i][j] else: ls.append(i) if i == h - 1: while ls: ti = ls.pop() for j in range(w): s[ti][j] = s[lsd][j] for i in range(len(s)): print(*s[i]) if __name__ == '__main__': solve()
def main(): h,w,_ = map(int,input().split()) ls = [list(input()) for _ in range(h)] check = [False for _ in range(h)] for i in range(h): flg = False for j in range(w): if ls[i][j] == "#": flg = True if flg: check[i] = True ans = [[0 for _ in range(w)] for _ in range(h)] now = 1 for i,flg in enumerate(check): if flg: ball = False for j in range(w): if ball == True and ls[i][j]=="#": now +=1 ans[i][j]=now elif ball == False and ls[i][j]=="#": ans[i][j]=now ball = True else: ans[i][j]=now now += 1 else: pass for i,flg in enumerate(check): if flg: pass else: k = i while 1: if k == h-1 and check[h-1]==False: break if check[k]: break else: k += 1 for j in range(w): ans[i][j] = ans[k][j] if check[-1]==False: index = 0 for i in range(h): if check[i]==True: index = i else: pass for i in range(index+1,h): for j in range(w): ans[i][j]=ans[index][j] for i in range(h): for j in range(w): print(ans[i][j],end=" ") print("\n") if __name__ == "__main__": main()
1
143,521,086,559,522
null
277
277
def get_num(n, x): ans = 0 for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1): for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1): for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1): if n3 == x - n1 - n2: ans += 1 break return ans data = [] while True: [n, x] = [int(m) for m in raw_input().split()] if [n, x] == [0, 0]: break if x < 3: # print(0) data.append(0) else: # print(get_num(n, x)) data.append(get_num(n, x)) for n in data: print(n)
while True: (n, x) = [int(i) for i in input().split()] if n == x == 0: break dataset = [] for a in range(1, n + 1): for b in range(a + 1, n + 1): for c in range(b + 1, n + 1): dataset.append([a,b,c]) count = 0 for data in dataset: if sum(data) == x: count += 1 print(count)
1
1,306,814,387,970
null
58
58
n = int(input()) pricies = list(map(int, input().split())) m = 1000 stocks = 0 ask = 0 for i in range(n): price = pricies[i] isHigher = False isLower = False if stocks > 0: if price >= ask: m += price * stocks stocks = 0 for j in range(i+1, n): if pricies[j] >= price: isHigher = True break else: isLower = True if isHigher and not isLower: stocks, m = stocks + m // price, m % price ask = price print(m)
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) n = I() m500 = n//500 n -= 500 * m500 m5 = n//5 print(1000 * m500 + m5 * 5)
0
null
24,930,943,611,196
103
185
N = int(input()) A = [int(x) for x in input().split()] B = [] for i, a in enumerate(A): B.append([a, i + 1]) B.sort() ans = [] for b in B: ans.append(b[1]) print(*ans)
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) n,k=nii() a=lnii() a.sort() mod=10**9+7 MAX_N = n+5 fac = [1,1] + [0]*MAX_N finv = [1,1] + [0]*MAX_N inv = [0,1] + [0]*MAX_N for i in range(2,MAX_N): 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 nCk(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 min_X=0 for i in range(n-k+1): min_X+=a[i]*nCk(n-i-1,k-1) min_X%=mod max_X=0 for i in range(k-1,n): max_X+=a[i]*nCk(i,k-1) max_X%=mod ans=max_X-min_X ans%=mod print(ans)
0
null
137,912,158,434,260
299
242
print((lambda x: (x[0]-1)//x[1]+1)(list(map(int,input().split()))))
def main(): H, A = map(int, input().split()) ans = (H + (A - 1)) // A print(ans) if __name__ == '__main__': main()
1
77,177,545,724,930
null
225
225
a,b = map(int,input().split()) if a >= b: i = 1 while i > 0: if (a*i) % b == 0: print(a*i) break i += 1 else: i = 1 while i > 0: if (a*i) % b == 0: print(a*i) break i += 1
n = int(input()) li = ["#"*20 if i%4==0 else "0"*10 for i in range(1, 16)] for _ in range(n): b, f, r, v = map(int, input().split()) h = 4*b-(4-f)-1 li[h] = li[h].replace(li[h], ''.join([str(int(list(li[h])[r-1])+v) if i == r-1 else list(li[h])[i] for i in range(10)])) li = [' '+' '.join(li[i]) if (i+1)%4!=0 else li[i] for i in range(len(li))] print('\n'.join(li))
0
null
56,961,242,948,510
256
55
import time start = time.time() n = int(input()) a = list(map(int,input().split())) b = [] m = 0 for i in range(1,n): m = m ^ a[i] b.append(m) for j in range(1,n): m = m ^ a[j-1] m = m ^ a[j] b.append(m) b = map(str,b) print(' '.join(b))
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())) n = Ii() a = Li() b = 0 for i in range(n): b ^= a[i] ans = [] for i in range(n): print(b^a[i],end=' ')
1
12,438,709,447,020
null
123
123
box_A,box_B,box_C = map(int,input().split()) box_A,box_B = box_B,box_A box_A,box_C = box_C,box_A print(box_A,box_B,box_C)
import math import sys readline = sys.stdin.readline def main(): a, b, c = map(int, readline().rstrip().split()) print(c, a, b) if __name__ == '__main__': main()
1
38,312,661,073,212
null
178
178
def main(): s = input() if s[0]==s[1]==s[2]: print("No") else: print("Yes") if __name__ == "__main__": main()
s = input() if ("A" in s) and ("B" in s): print("Yes") else: print("No")
1
54,745,936,638,400
null
201
201
K, N = map(int, input().split()) A = list(map(int, input().split())) dists = [] for i in range(N): if i==N-1: dists.append(K-A[N-1]+A[0]) else: dists.append(A[i+1]-A[i]) print(K-max(dists))
w,h,x,y,r = map(int,raw_input().split()) if w-r >= x and h-r >= y and x-r >= 0 and y-r >= 0: print "Yes" else: print "No"
0
null
22,055,615,828,672
186
41
# AOJ ITP1_8_B def numinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def main(): while True: n = int(input()) if n == 0: break sum = 0 while n > 0: sum += n % 10 n = n // 10 print(sum) if __name__ == "__main__": main()
while True: x = input().rstrip('\r\n') if x == '0': break sum = 0 for ii in range(len(x)): sum += int(x[ii]) print(sum)
1
1,574,710,956,000
null
62
62
n, m = map(int, input().split()) A = [list(map(int, input().split())) for _ in [None] * n] b = [int(input()) for _ in [None] * m] for a in A: print(sum([i * j for i, j in zip(a, b)]))
N = int(input()) % 10 print('hon' if N in [2, 4, 5, 7, 9] else 'pon' if N in [0, 1, 6, 8] else 'bon')
0
null
10,136,664,466,308
56
142
while True : m, f, r = map(int, input().split()) if(m == -1 and f == -1 and r == -1) : break elif(m == -1 or f == -1) : print("F") elif(m + f >= 80) : print("A") elif(65 <= m + f and m + f < 80) : print("B") elif(50 <= m + f and m + f < 65) : print("C") elif(30 <= m + f and m + f < 50) : if(50 <= r) : print("C") else : print("D") else : print("F")
m=[0]*50 f=[0]*50 r=[0]*50 result=[""]*50 num=0 while True: a,b,c=map(int,input().split()) if a == b == c ==-1: break else: m[num],f[num],r[num]=a,b,c num+=1 for i in range(num): if m[i] == -1 or f[i]==-1: result[i]="F" elif m[i]+f[i]>=80: result[i]="A" elif m[i]+f[i]>=65: result[i]="B" elif m[i]+f[i]>=50: result[i]="C" elif m[i]+f[i]>=30: if r[i] >=50: result[i]="C" else: result[i]="D" else: result[i]="F" for i in range(num): print(result[i])
1
1,204,347,834,400
null
57
57
import math N = int(input()) O = N // 2 + N % 2 print(O)
k=int(input()) a,b = map(int,input().split()) while b>=a: if b%k==0: print('OK') break b-=1 if b<a: print('NG')
0
null
42,625,753,238,562
206
158
n = int(input()) v = [] for i in range(n): v_i = list(map(int,input().split()))[2:] v.append(v_i) d = [-1]*n d[0]=0 queue = [1] dis = 1 while len(queue)!=0: queue2 = [] for i in queue: for nex in v[i-1]: if d[nex-1]==-1: d[nex-1]=dis queue2.append(nex) dis +=1 queue = queue2 for i in range(n): print(i+1,d[i])
pages=int(input()) papers=pages/2 res=int(papers) if pages%2==0: print(res) else: print(res+1)
0
null
29,453,928,597,640
9
206
W=input() num=0 while True: T=input() t=str.lower(T) if (T == 'END_OF_TEXT'):break t_split=(t.split()) for i in range(len(t_split)): if t_split[i] == W: num+=1 print(num)
W=input() s=0 while True: T=list(input().split()) if T==['END_OF_TEXT']: break else: for i in T: if i.lower()==W.lower(): s+=1 print(s)
1
1,827,073,696,828
null
65
65
A , B, M = map(int,input().split(" ")) a = list(map(int,input().split(" "))) b = list(map(int,input().split(" "))) res = min(a) + min(b) for _ in range(M): x,y, c = list(map(int,input().split(" "))) x-=1 y-=1 res = min(res,a[x]+b[y]-c) print(res)
a, b, m = map(int, input().split()) reizo = list(map(int, input().split())) renji = list(map(int, input().split())) p = [list(map(int,input().split())) for i in range(m)] ans = [] for i in range(m): cost = reizo[p[i][0] - 1] + renji[p[i][1] - 1] - p[i][2] ans.append(cost) ans.append(min(reizo) + min(renji)) print(min(ans))
1
54,359,896,698,392
null
200
200
S = str(input()) s = list(map(str,S)) if s[2] == s[3] and s[4] == s[5]: print('Yes') else: print('No')
import bisect X, N = map(int, input().split()) P = set(map(int, input().split())) A = {i for i in range(102)} S = list(A - P) T = bisect.bisect_left(S, X) if T == 0: print(S[0]) elif X - S[T-1] > S[T] - X: print(S[T]) else: print(S[T-1])
0
null
27,937,828,096,612
184
128
import numpy as np a,b,h,m=list(map(int,input().split())) deg = min(abs(h*360/12+m*360/12/60-m*360/60),360-abs(h*360/12+m*360/12/60-m*360/60)) theta = deg * np.pi /180 ans = np.sqrt(np.power(a,2)+np.power(b,2)-2*a*b*np.cos(theta)) print(ans)
import bisect N,M,K=map(int,input().split()) arr1=list(map(int,input().split())) arr2=list(map(int,input().split())) A=[0] for i in range(N): A.append(arr1[i]+A[-1]) B=[0] for i in range(M): B.append(arr2[i]+B[-1]) ans=0 for i in range(N+1): if A[i]>K: break j=bisect.bisect_right(B,K-A[i])-1 ans=max(ans,i+j) print(ans)
0
null
15,456,904,589,760
144
117
a=input() if(a=='AAA' or a=='BBB'): print('No') else: print('Yes')
# AAA or BBB ならNo S = list(input()) S_sorted = ''.join(sorted(S)) # print(S_sorted) if S_sorted == 'AAA' or S_sorted == 'BBB': print('No') else: print('Yes')
1
54,814,918,075,200
null
201
201
N, M = map(int,input().split()) ans = [] if N %2 == 0: L1 = list(range(1,N//2+1)) L2 = list(range(N//2+1,N+1)) L = len(L1) i = 0 j = 0 # print(L) for m in range(M): if m %2 == 0: ans.append([L1[L//2-1-i],L1[L//2+i]]) i += 1 else: ans.append([L2[L//2-1-j], L2[L//2+1+j]]) j += 1 else: for i in range(1,M+1): ans.append([i,N+1-i]) for a in ans: print(*a)
from math import ceil n, m = (int(x) for x in input().split()) if n % 2 == 1: for i in range(1, m + 1): print(i, n - i) else: k = (n - 2) // 2 l = ceil(k / 2) ANS = [] for i in range(1, l+1): ANS.append((i, n - i + 1)) for i in range(l+2, k+2): ANS.append((i, n - i + 2)) for a, b in ANS[:m]: print(a, b)
1
28,669,815,671,368
null
162
162
H,N=map(int,input().split()) L=[0]*N for i in range(N): a,b=map(int,input().split()) L[i]=(a,b) DP=[float("inf")]*(H+1) DP[0]=0 for (A,B) in L: for k in range(1,H+1): if k>=A: DP[k]=min(DP[k],DP[k-A]+B) else: DP[k]=min(DP[k],B) print(DP[-1])
def solve(): H,N = map(int,input().split()) ap = [] mp = [] for _ in range(N): a,b = map(int,input().split()) ap.append(a) mp.append(b) ap_max = max(ap) dp = [[float('inf')] * (H+ap_max+1) for _ in range(N+1)] for i in range(N+1): dp[i][0] = 0 for i in range(N): for sum_h in range(H+ap_max+1): if sum_h - ap[i] >= 0: dp[i+1][sum_h] = min(dp[i][sum_h-ap[i]] + mp[i], dp[i][sum_h]) dp[i+1][sum_h] = min(dp[i+1][sum_h-ap[i]] + mp[i], dp[i][sum_h]) dp[i+1][sum_h] = min(dp[i+1][sum_h], dp[i][sum_h]) ans = float('inf') for sum_h in range(H, H+ap_max+1): ans = min(ans,dp[N][sum_h]) print(ans) if __name__ == '__main__': solve()
1
81,393,943,950,242
null
229
229
from sys import stdin A, B, C = [int(_) for _ in stdin.readline().rstrip().split()] K = int(stdin.readline().rstrip()) for i in range(K): if not B > A: B *= 2 elif not C > B: C *= 2 if A < B < C: print("Yes") else: print("No")
A, B, C = list(map(int, input().split())) K = int(input()) while(B <= A): B *= 2 K -= 1 while(C <= B): C *= 2 K -= 1 if(K >= 0): print("Yes") else: print("No")
1
6,927,225,957,280
null
101
101
def main(): import sys input = sys.stdin.readline n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in range(n)] ab = [(x,y) for x,y in zip(a,b)] from operator import itemgetter ab = sorted(ab,key=itemgetter(0),reverse=True) dp = [[-10**14]*(n+1) for i in range(n+1)] dp[0][0] = 0 for i in range(n): for j in range(i+2): if j >= 1: dp[i+1][j] = max(dp[i][j]+ab[i][0]*abs(ab[i][1]-(n-1-(i-j))),dp[i][j-1]+ab[i][0]*abs(ab[i][1]+1-j)) if j == 0: dp[i+1][0] = dp[i][0] + ab[i][0]*abs(ab[i][1]-(n-1-i)) print(max(dp[n])) if __name__ == '__main__': main()
import sys input = sys.stdin.buffer.readline n = int(input()) A = list(map(int, input().split())) L = [(a, i+1) for i, a in enumerate(A)] L.sort(reverse=True) dp = [[-1]*(n+1) for _ in range(n+1)] dp[0][0] = 0 for i in range(n+1): for j in range(n+1-i): a, idx = L[i+j-1] if i: dp[i][j] = max(dp[i][j], dp[i-1][j]+a*(idx-i)) if j: dp[i][j] = max(dp[i][j], dp[i][j-1]+a*(n+1-j-idx)) ans = 0 for i in range(n+1): ans = max(ans, dp[i][n-i]) print(ans)
1
33,574,106,523,780
null
171
171
from math import atan, degrees a,b,x= map(int,input().split()) yoseki = a**2*b if x <= yoseki/2: # b*y*a/2==x y= 2*x/b/a # 90からシータを引けば良い print(90-degrees(atan(y/b))) else: # a*y*a/2==yoseki-x y = 2*(yoseki-x)/a**2 print(degrees(atan(y/a)))
# https://atcoder.jp/contests/abc144/tasks/abc144_d import math a, b, x = list(map(int, input().split())) if a * a * b * (1/2) <= x: tmp = 2 * (a*a*b-x) / (a*a*a) print(math.degrees(math.atan(tmp))) else: tmp = a*b*b / (2*x) print(math.degrees(math.atan(tmp)))
1
163,075,695,222,142
null
289
289
# -*- coding: utf 8 -*- # Bubble Sort # 2019. 4/22 def bubbleSort(A, N): sw = 0 flag = 1 i = 0 while flag: flag = 0 for j in range(int(N) - 1, i, -1): if A[j - 1] > A[j]: A[j], A[j - 1] = A[j - 1], A[j] flag = 1 sw = sw + 1 i = i + 1 return A, sw if __name__ == '__main__': N = int(input()) A = list(map(int, input().split())) A_sorted, num_sw = bubbleSort(A, N) for i in range(N-1): print(A[i], end=" ") print(A[N-1]) print(num_sw)
from collections import defaultdict def main(): N = int(input()) d = defaultdict(int) results = ["AC", "WA", "TLE", "RE"] for _ in range(N): d[input()] += 1 for r in results: print(f"{r} x {d[r]}") if __name__ == '__main__': main()
0
null
4,410,727,293,188
14
109
from collections import deque infty = 10 ** 9 def BFS(graph, parent, u): queue = deque() queue.append(u) visited = [False for k in range(len(parent))] #探索が始まったか否か visited[u] = True while queue: v = queue.popleft() for j in graph[v]: if not visited[j]: queue.append(j) visited[j] = True parent[j] = v n, m = map(int, input().split()) graph = [[] for i in range(n)] for i in range(m): a, b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) parent = [-1 for i in range(n)] BFS(graph, parent, 0) if -1 in parent[1:]: print("No") else: print("Yes") for p in parent[1:]: print(p+1)
N = int(input()) A = list(map(int, input().split())) l = [0]*N for i in A: l[i-1] += 1 print(*l, sep="\n")
0
null
26,714,777,170,200
145
169
dic = {} line = [] for i in range(int(input())): line.append(input().split()) for i in line: if i[0][0] == "i": dic[i[1]] = None else: print("yes" if i[1] in dic else "no")
dic = set() n = int(input()) for i in range(n): cmd, val = input().split() if cmd == "insert": dic.add(val) elif cmd == "find": print("yes" if val in dic else "no") else: print("wrong command")
1
77,603,081,530
null
23
23
A,B,C,D=input().split() num = 0 while(int(A)>=0 and int(C)>=0): if int(A)<= 100 and 0 <= int(B)<= 100 and int(C)<= 100 and 0 <= int(D)<= 100: if num %2 == 0: C = int(C)-int(B) if int(C)<=0: print("Yes") break num += 1 elif num %2 !=0: A = int(A)-int(D) if int(A)<=0: print("No") break num += 1 else: break
x = list(map(int,input().split())) i = 0 while (x[i] != 0): i+=1 print(i+1)
0
null
21,549,637,151,168
164
126
#Take input separated by space(?) h,a = map(int, input().split()) #Divide, just round off and add 1 if decimal hit = round(h//a) if h%a != 0: hit = hit + 1 print(hit)
def main(): num = list(map(int,input().split())) if num[0]%num[1]==0: print(int(num[0]/num[1])) else: print(int(num[0]/num[1])+1) main()
1
77,050,861,295,772
null
225
225
row = int(input()) colmun = int(input()) top = int(input()) low, high = 0,0 if row <= colmun: low, high = row, colmun else: low, high = colmun, row for n in range(low): if (n + 1) * high >= top: print(n + 1) break
# Binary Search def isOK(i, key): ''' 問題に応じて返り値を設定 ''' cnt = 0 for v in a: cnt += (v + i - 1) // i - 1 return cnt <= key def binary_search(key): ''' 条件を満たす最小/最大のindexを求める O(logN) ''' ok = 10 ** 9 # 条件を満たすindexの上限値/下限値 ng = 0 # 条件を満たさないindexの下限値-1/上限値+1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if isOK(mid, key): # midが条件を満たすか否か ok = mid else: ng = mid return ok n, k = map(int, input().split()) a = list(map(int, input().split())) print(binary_search(k))
0
null
47,696,704,391,100
236
99
while True: try: a, b = list(map(int, input().split())) print(len(str(a + b))) except EOFError: break except ValueError: break
def main(): n, a, b = map(int, input().split()) ab_diff = abs(a-b) if ab_diff%2 == 0: print(ab_diff//2) return a_edge_diff = min(abs(a-1),abs(n-a)) b_edge_diff = min(abs(b-1),abs(n-b)) # near_diff = min(a_edge_diff, b_edge_diff) if a_edge_diff <= b_edge_diff: print(a_edge_diff+1+ (ab_diff-1)//2) else: print(b_edge_diff+1+ (ab_diff-1)//2) if __name__ == "__main__": main()
0
null
54,937,055,527,790
3
253
def resolve(): s = str(input()) ans = 0 if 'R' in s: ans = 1 if 'RR' in s: ans = 2 if 'RRR' in s: ans = 3 print(ans) resolve()
def resolve(): data = [len(x) for x in input().split("S") if x] print(max(data) if data else 0) resolve()
1
4,886,955,492,092
null
90
90
import sys input = sys.stdin.readline def main(): n , m = map( int , input().split() ) h = list( map( int , input().split() ) ) goods = [ 1 for i in range(n) ] for i in range( m ): a , b = map( lambda x : int(x) - 1 , input().split() ) if ( h[a] > h[b] ): goods[ b ] = 0 if ( h[a] < h[b] ): goods[ a ] = 0 if ( h[a] == h[b] ): goods[ a ] = 0 goods[ b ] = 0 print( sum(goods) ) main()
n,m=map(int,input().split()) h=list(map(int,input().split())) final=[1]*n for i in range(m): a,b=map(int,input().split()) if h[a-1]<h[b-1]: final[a-1]=0 elif h[a-1]>h[b-1]: final[b-1]=0 else: final[a-1]=0 final[b-1]=0 print(sum(final))
1
25,157,357,468,990
null
155
155
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def main(): l = list(map(int, '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'.replace(',', '').split())) K = int(input()) - 1 print(l[K]) if __name__ == '__main__': main()
N, K = map(int, input().split()) mod = 10 ** 9 + 7 cnt = [0] * (K + 1) answer = 0 for i in range(K, 0, -1): tmp = pow(K // i, N, mod) - sum(cnt[::i]) cnt[i] = tmp answer = (answer + tmp * i) % mod print(answer)
0
null
43,418,318,239,760
195
176
# -*- coding: utf-8 -*- import sys import os s = input().strip() N = int(input()) for i in range(N): lst = input().split() command = lst[0] if command == 'replace': a = int(lst[1]) b = int(lst[2]) p = lst[3] s = s[:a] + p + s[b+1:] elif command == 'reverse': a = int(lst[1]) b = int(lst[2]) part = s[a:b+1] part = part[::-1] s = s[:a] + part + s[b+1:] elif command == 'print': a = int(lst[1]) b = int(lst[2]) print(s[a:b+1]) else: print('error') #print('s', s)
s = int(input()) h = s // 3600 m = s % 3600 // 60 s = s % 60 print(f'{h}:{m}:{s}')
0
null
1,230,799,578,220
68
37
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): S, T = input().split() A, B = map(int, input().split()) U = input() if S == U: A -= 1 if T == U: B -= 1 print(A, B) if __name__ == '__main__': solve()
s,t = [x for x in input().split()] a,b = [int(x) for x in input().split()] ss = input() if ss == s: print(a-1,b) else: print(a,b-1)
1
71,857,888,492,130
null
220
220
N, K = map(int, input().split()) SC = list(map(int, input().split())) T = input() Q = [] for i in range(len(T)): if T[i] == "r": Q.append(0) elif T[i] == "s": Q.append(1) else: Q.append(2) my = [0 for i in range(N)] ans = 0 for i in range(N): if i < K: my[i] = (Q[i] - 1) % 3 ans += SC[my[i]] else: n = (Q[i] - 1) % 3 if my[i - K] != n: my[i] = n ans += SC[my[i]] else: if i + K < N: my[i] = Q[i+K] print(ans)
# B - Battle # 入力 A B C D A, B, C, D = map(int, input().split(maxsplit=4)) while True: C -= B if C <= 0: answer = 'Yes' break A -= D if A <= 0: answer = 'No' break print(answer)
0
null
68,426,675,232,060
251
164
class Dice: def __init__(self,s1,s2,s3,s4,s5,s6): self.s1 = s1 self.s2= s2 self.s3= s3 self.s4= s4 self.s5 = s5 self.s6= s6 def east(self): prev_s1 = self.s1 #prev_s1を固定していないと以前の値が後述でs1に値を代入するとき変わってしまう。 prev_s3 = self.s3 prev_s4 = self.s4 prev_s6 = self.s6 self.s1 = prev_s4 self.s3 = prev_s1 self.s4 = prev_s6 self.s6 = prev_s3 def west(self): prev_s1 = self.s1 prev_s3 = self.s3 prev_s4 = self.s4 prev_s6 = self.s6 self.s1 = prev_s3 self.s3 = prev_s6 self.s4 = prev_s1 self.s6 = prev_s4 def south(self): prev_s1 = self.s1 prev_s2 = self.s2 prev_s5 = self.s5 prev_s6 = self.s6 self.s1 = prev_s5 self.s2 = prev_s1 self.s5 = prev_s6 self.s6 = prev_s2 def north(self): prev_s1 = self.s1 prev_s2 = self.s2 prev_s5 = self.s5 prev_s6 = self.s6 self.s1 = prev_s2 self.s2 = prev_s6 self.s5 = prev_s1 self.s6 = prev_s5 def top(self): return self.s1 s1,s2,s3,s4,s5,s6 = map(int,input().split()) dice = Dice(s1,s2,s3,s4,s5,s6) order = input() for c in order: if c =='N': dice.north() elif c =='S': dice.south() elif c =='E': dice.east() elif c == 'W': dice.west() print(dice.top())
def dist(x0, y0, x1, y1): from math import sqrt return sqrt((x1-x0)**2 + (y1-y0)**2) from itertools import permutations N = int(input()) points = [tuple(map(int, input().split())) for _ in range(N)] #; print(points) dsum = 0 for i, j in permutations(points, 2): dsum += dist(*i, *j) print(dsum/N)
0
null
74,619,673,524,318
33
280
K, N = map(int, input().split()) nums = list(map(int, input().split())) before = 0 max_n = 0 for num in nums: dist = num - before max_n = max(max_n, dist) before = num max_n = max(max_n, K-nums[-1]+nums[0]) print(K-max_n)
import math x1,y1,x2,y2 = tuple(float(n) for n in input().split()) D = math.sqrt((x2-x1)**2 + (y2-y1)**2) print("{:.8f}".format(D))
0
null
21,822,493,671,942
186
29
# -*- coding: utf-8 -*- import sys N=int(sys.stdin.readline().strip()) A=map(int, sys.stdin.readline().split()) AA=[] for i,val in enumerate(A): AA.append((val,i+1)) AA.append((float("inf"),None)) #1-indexedにする AA.sort(reverse=True) dp=[ [ 0 for r in range(N+1) ] for l in range(N+1) ] dp[0][0]=0 l=0 for l in range(N): for r in range(N-l): val,idx=AA[l+r+1][0],AA[l+r+1][1] dp[l+1][r]=max( dp[l+1][r], dp[l][r]+abs(val*(idx-l-1)) ) dp[l][r+1]=max( dp[l][r+1], dp[l][r]+abs(val*(N-r-idx)) ) ans=float("-inf") for l in dp: ans=max(ans,max(l)) print ans
import sys LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() data = [[a,i] for i,a in enumerate(LI())] data.sort(reverse=True) dp = [[0] * (N+1) for _ in range(N+1)] for i in range(N): a, p = data[i] for j in range(i+1): dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + abs(N-1-j-p)*a) dp[i+1][j] = max(dp[i+1][j], dp[i][j] + abs(i-j-p)*a) print(max(dp[-1]))
1
33,959,111,367,390
null
171
171
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read from heapq import heappop, heappush from collections import defaultdict sys.setrecursionlimit(10**7) import math #from itertools import product, accumulate, combinations, product #import bisect #import numpy as np #from copy import deepcopy #from collections import deque #from decimal import Decimal #from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10 ** 9 + 7 def mapline(t = int): return map(t, sysread().split()) def mapread(t = int): return map(t, read().split()) def run(): N, *A = mapread() ans = 1 current = [0,0,0] for a in A: transition = 0 cache = None for i, c in enumerate(current): if c == a: transition += 1 cache = i ans *= transition ans %= mod if cache == None: print(0) return current[cache] += 1 #print(current) print(ans) if __name__ == "__main__": run()
import sys from collections import Counter as cc def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) def main(): mod = 10**9 + 7 n = ii() a = li() t = [0]*(n) ans = 1 for i in range(n): if a[i] == 0: tmp = 3 else: tmp = t[a[i]-1] ans *= tmp-t[a[i]] ans %= mod t[a[i]] += 1 print(ans) if __name__ == '__main__': main()
1
129,997,868,508,982
null
268
268
def gcd(x, y): '''?????????????????????????????? x>=y?????¨??????gcd(x, y)??¨gcd(y, x%y)?????????????????¨????????¨??????''' if x < y: x, y = y, x while y > 0: x, y = y, x % y return x def test(): '''??? input = 147 105 -> 21''' x, y = map(int, input().split()) result = gcd(x, y) print(result) if __name__ == '__main__': test()
import sys input = sys.stdin.readline sys.setrecursionlimit(10**8) def main(): n,m = map(int,input().split()) x = m//2 y = m - x for i in range(x): print(i+1,2*x+1-i) for i in range(y): print(2*x+2+i,2*x+2*y+1-i) if __name__ == "__main__": main()
0
null
14,282,632,468,930
11
162
import math import numpy as np a,b,h,m = list(map(int, input().split())) a_radian = math.radians(h * 30 + m / 2) a_ = np.array([a * math.cos(a_radian), a * math.sin(a_radian)]) b_radian = math.radians(6 * m) b_ = np.array([b * math.cos(b_radian), b * math.sin(b_radian)]) print(np.linalg.norm(a_ - b_))
import numpy as np a,b,h,m=[int(i) for i in input().split()] def get_angle(h,m): long_angle=2*np.pi*m/60 short_angle=2*np.pi*h/12+(2*np.pi/12)*m/60 big_angle=max(long_angle,short_angle) small_angle = min(long_angle, short_angle) angle=min(big_angle-small_angle,2*np.pi-big_angle+small_angle) return angle def yogen(a,b,theta): ans=a**2+b**2-2*a*b*np.cos(theta) return ans**0.5 print(yogen(a,b,get_angle(h,m)))
1
20,182,075,487,948
null
144
144
n = int(input()) a = list(map(int, input().split())) status = [0, 0, 0] mod = 1000000007 ans = status.count(a[0]) status[0] += 1 for i in range(1, n): ans *= status.count(a[i]) ans %= mod for j in range(len(status)): if status[j] == a[i]: status[j] += 1 break print(ans)
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right def main(): N = int(input()) A = list(map(int, input().split())) p = 10**9+7 # check[i]:= Aの中のiが出てきた順番 check = [[] for _ in range(N)] for i in range(N): check[A[i]].append(i) # print(check) ans = 1 for i in range(len(check[0])): ans *= (3-i) for i in range(1,N): if len(check[i-1]) < len(check[i]): exit(print(0)) # check[i]がcheck[i-1]のなかで何番目か調べる for j in range(len(check[i])): d = bisect_right(check[i-1],check[i][j]) if d < j: exit(print(0)) ans *= d-j ans %= p # print(ans) print(ans) if __name__ == "__main__": main()
1
130,293,819,378,600
null
268
268
def divisors(N): U = int(N ** 0.5) + 1 L = [i for i in range(1, U) if N % i == 0] return L + [N // i for i in reversed(L) if N != i * i] def solve(k): n = N while n % k == 0: n //= k return (n % k == 1) N = int(input()) K = set(divisors(N) + divisors(N - 1)) - {1} print(sum(solve(k) for k in K))
N = int(input()) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr L1 = factorization(N - 1) s = 1 # print(L1) for [a, b] in L1: s *= (b + 1) # print(s) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] for i in set(make_divisors(N))-{1}: temp = N while temp % i == 0: temp //= i if (temp-1) % i == 0: s += 1 s -= 1 if N == 2: print(1) else: print(s)
1
41,211,523,084,872
null
183
183
N=input() N=int(N) q1, mod = divmod(N,2) if mod == 0: print(q1) else: print(q1 + 1)
a = [list(map(int,input().split())) for i in range(3)] n = int(input()) b = [int(input()) for i in range(n)] for i in range(3): for j in range(3): if a[i][j] in b: a[i][j] = "o" for i in range(3): if a[i][0] == a[i][1] == a[i][2]: print("Yes") exit() elif a[0][i] == a[1][i] == a[2][i]: print("Yes") exit() elif a[0][0] == a[1][1] == a[2][2]: print("Yes") exit() elif a[0][2] == a[1][1] == a[2][0]: print("Yes") exit() elif i == 2: print("No")
0
null
59,630,473,753,152
206
207
while 1: try: a, b = map(int,raw_input().split()) except EOFError: break ac, bc = a, b while 1: if a < b: b = b - a elif b < a: a = a - b elif a == b: x = [a,ac*bc/a] print "{:.10g} {:.10g}".format(*x) break
N = int(input()) A = [int(a) for a in input().split()] attend = [0] * N for i in range(N): attend[A[i]-1] = str(i+1) res = ' '.join(attend) print(res)
0
null
90,652,302,284,950
5
299
import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] tin=lambda : map(int, input().split()) lin=lambda : list(IN()) mod=1000000007 #+++++ def main(): #a = int(input()) #b , c = tin() s = input() if s[0] == '>': s = '<' + s if s[-1] == '<': s = s + '>_' else: s = s + '_' dd = [] pre = '<' count = [1,0] for c in s[1:]: if c == '<' and pre == '<': count[0] += 1 elif c == '>' and pre == '>': count[1] += 1 elif c == '>' and pre == '<': pre = '>' count[1] = 1 elif c == '<' and pre == '>': pre = '<' dd.append(count) count=[1,0] else: dd.append(count) ret_sum = 0 for l, r in dd: ret_sum += (r*(r+1)//2) + (l*(l+1)//2) - min(r,l) print(ret_sum) #+++++ isTest=False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform =='ios': if input_method==input_methods[0]: ic=input_clipboard() input = lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else: pass isTest=True else: pass #input = sys.stdin.readline ret = main() if ret is not None: print(ret)
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし S = LS2() N = len(S)+1 ANS = [0]*N for i in range(N-1): if S[i] == '<': ANS[i+1] = ANS[i]+1 for i in range(N-2,-1,-1): if S[i] == '>': ANS[i] = max(ANS[i],ANS[i+1]+1) print(sum(ANS))
1
156,410,332,815,800
null
285
285
S = input() if S[0] =="R" and S[1] == "R" and S[2] == "R": print(3) elif (S[0] =="R" and S[1] == "R") or (S[1] == "R" and S[2] == "R"): print(2) elif S[0] =="R" or S[1] == "R" or S[2] == "R": print(1) else: print(0)
s = input() cnt = 0 for x in range(2): if s[x] == 'R' and s[x+1] == 'R': cnt += 1 for x in s: if x == 'R': cnt += 1 break print(cnt)
1
4,900,041,903,068
null
90
90
# coding: utf-8 # Your code here! # 幅優先探索(行きがけ) import collections import sys import copy import re import math def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): N,M = LI() loadArray = [LI() for _ in range(M)] ans = 0 class UnionFind(): #クラスコンストラクタ #selfはインスタンス自身 def __init__(self, n): #親ノードを-1に初期化する 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] #xとyの木を併合する def union(self, x, y): #x,yの根をX,Yとする X = self.find(x) Y = self.find(y) #根が同じなら結合済み if X == Y: return #ノード数が多い方をXとする if self.parents[X] > self.parents[Y]: X, Y = Y, X #XにYのノード数を足す self.parents[X] += self.parents[Y] #Yの根を X>0 とする self.parents[Y] = X uf = UnionFind(N) for a, b in loadArray: #インデックスを調整し、a,bの木を結合 a -= 1; b -= 1 uf.union(a, b) for u in uf.parents: if u<0: ans += 1 print(ans-1) if __name__ == '__main__': main()
import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def main(): n, m = map(int, input().split()) if n < 2: even = 0 else: even = combinations_count(n, 2) if m < 2: odd = 0 else: odd = combinations_count(m, 2) print(even + odd) if __name__ == "__main__": main()
0
null
23,871,087,552,312
70
189
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) n=int(input()) def divisore(n): divisors=[] for i in range(1,int(n**0.5)+1): if n%i==0: divisors.append(i) if i!=n//i: divisors.append(n//i) divisors.sort() return divisors ans_l=divisore(n-1)[1:] d=divisore(n) for i in d[1:]: nn=n while nn%i==0: nn//=i if nn%i==1: ans_l.append(i) print(len(ans_l))
from collections import deque def deque_divisor(n): d = deque() for i in range(int(n**(1/2)),0,-1): if i**2 == n: d.append(i) continue if n % i == 0: d.appendleft(i) d.append(n//i) return d n = int(input()) candidate = (set(deque_divisor(n)) | set(deque_divisor(n-1))) candidate.discard(1) ans = 0 for i in candidate: k = n while k % i == 0: k //= i k %= i if k == 1: ans += 1 print(ans)
1
41,304,033,436,768
null
183
183
from collections import deque H,W = map(int,input().split()) field = [list(input()) for _ in range(H)] dist = [[-1]*W for _ in range(H)] dx = [1,0,-1,0] dy = [0,1,0,-1] mx = 0 for h in range(H): for w in range(W): if field[h][w] == "#": continue dist = [[-1]*W for _ in range(H)] dist[h][w] = 0 que = deque([]) que.append([h,w]) while que != deque([]): u,v = que.popleft() for dir in range(4): nu = u + dx[dir] nv = v + dy[dir] if (nu < 0) or (nu >= H) or (nv < 0) or (nv >= W): continue if field[nu][nv] == "#": continue if dist[nu][nv] != -1: continue que.append([nu,nv]) dist[nu][nv] = dist[u][v] + 1 for i in range(H): for j in range(W): if mx < dist[i][j]: mx = dist[i][j] print(mx)
import copy from collections import deque n, st, sa = map(int,input().split()) st -= 1 sa -= 1 e = [[] for i in range(n)] for i in range(n-1): a, b = map(int, input().split()) a -= 1 b -= 1 e[a].append(b) e[b].append(a) visited = [False] * n visited[st] = True d = deque() d.append([st, 0]) tx = {} if len(e[st]) == 1: tx[st] = 0 cnt = 0 while d: f, cnt = d.popleft() flg = True for t in e[f]: if not visited[t]: flg = False d.append([t, cnt+1]) visited[t] = True if flg: tx[f] = cnt visited = [False] * n visited[sa] = True d = deque() d.append([sa, 0]) ax = {} if len(e[sa]) == 1: ax[sa] = 0 cnt = 0 while d: f, cnt = d.popleft() flg = True for t in e[f]: if not visited[t]: flg = False d.append([t, cnt+1]) visited[t] = True if flg: ax[f] = cnt ax = sorted(ax.items(), key=lambda x:x[1], reverse=True) for i in range(len(ax)): x, d = ax[i][0], ax[i][1] if d > tx[x]: ans = d - 1 break print(ans)
0
null
105,821,192,881,712
241
259
# -*- coding: utf-8 -*- import sys from collections import deque N,u,v=map(int, sys.stdin.readline().split()) al=[ [] for i in range(N+1) ] #隣接リスト for _ in range(N-1): a,b=map(int, sys.stdin.readline().split()) al[a].append(b) al[b].append(a) dist_t=[ 0 for _ in range(N+1) ] #高橋君のスタート地点からの各頂点までの距離 dist_a=[ 0 for _ in range(N+1) ] #青木君のスタート地点からの各頂点までの距離 #print "al :: ",al #高橋君のスタート地点からの各頂点までの距離 Visit=[ 0 for _ in range(N+1) ] q=deque() q.append(u) Visit[u]=1 while q: fro=q.popleft() for to in al[fro]: if Visit[to]==0: Visit[to]=1 #訪問済みに1をセット dist_t[to]=dist_t[fro]+1 #距離を計算 q.append(to) #print "dist_t :: ",dist_t #青木君のスタート地点からの各頂点までの距離 Visit=[ 0 for _ in range(N+1) ] q=deque() q.append(v) Visit[v]=1 while q: fro=q.popleft() for to in al[fro]: if Visit[to]==0: Visit[to]=1 #訪問済みに1をセット dist_a[to]=dist_a[fro]+1 #距離を計算 q.append(to) #print "dist_a :: ",dist_a ans=0 max_a=0 for t,a in zip(dist_t,dist_a): if t<a: ans=max(ans,a) print ans-1
N, U, V = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N - 1)] graph = [[] for _ in range(N + 1)] for A, B in AB: graph[A].append(B) graph[B].append(A) INF = 10 ** 15 dist_U = [INF] * (N + 1) dist_V = [INF] * (N + 1) def dfs(start, dist): stack = [start] dist[start] = 0 while stack: s = stack.pop() for g in graph[s]: if dist[g] > dist[s] + 1: dist[g] = dist[s] + 1 stack.append(g) dfs(U, dist_U) dfs(V, dist_V) #print("dist_U", dist_U) #print("dist_V", dist_V) answer = [] for i in range(1, N + 1): if dist_U[i] < dist_V[i]: answer.append(dist_V[i] - 1) print(max(answer))
1
117,328,702,562,880
null
259
259
a=input() b=input() if(a==b[0:len(b)-1] and len(b)-len(a)==1): print('Yes') else: print('No')
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): a, b, c, k = map(int, input().split()) r = min(k, a) k -= a if k > 0: k -= b if k > 0: r -= k print(r) if __name__ == '__main__': main()
0
null
21,791,494,296,740
147
148
n = input() A = [int(i) for i in input().split(' ')] def trace(A): for index, v in enumerate(A): print(v, end='') if index != len(A) - 1: print(' ', end='') print() trace(A) for i in range(1, len(A)): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v trace(A)
n = raw_input() num = raw_input() array = [] array = num.strip().split(" ") int_array = map(int, array) for i in range(1, int(n)): array = map(str, int_array) print " ".join(array) v = int_array[i] j = i - 1 while j >= 0 and int_array[j] > v: int_array[j + 1] = int_array[j] j -= 1 int_array[j + 1] = v array = map(str, int_array) print " ".join(array)
1
6,139,827,890
null
10
10
A,B,M=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) x=[input().split() for l in range(M)] tot_1=min(a)+min(b) lis=[] for i in range(M): tot=a[int(x[i][0])-1]+b[int(x[i][1])-1]-int(x[i][2]) lis.append(tot) if tot_1<=min(lis): print(tot_1) else: print(min(lis))
A, B, M = map(int, input().split()) a = [int(s) for s in input().split()] b = [int(s) for s in input().split()] m = [] for n in range(M): m.append([int(s) for s in input().split()]) minValue = min(a) + min(b) for i in range(M): discountPrice = a[m[i][0] - 1] + b[m[i][1] - 1] - m[i][2] if discountPrice < minValue: minValue = discountPrice print(minValue)
1
54,000,959,280,000
null
200
200
from collections import defaultdict from collections import deque N, M = map(int, input().split()) edges = defaultdict(list) ans = [0]*(N+1) num = 1 q = deque([1]) currentdepth = {1} nextdepth = set() for _ in range(M): a, b = map(int, input().split()) edges[a].append(b) edges[b].append(a) while q: current = q.popleft() for nextver in edges[current]: if ans[nextver]==0: q.append(nextver) ans[nextver] = current print('Yes') print(*(ans[2:]),sep='\n')
import collections N, M = map(int, input().split()) ways = collections.defaultdict(set) for _ in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 ways[a].add(b) ways[b].add(a) dist = [-1] * N q = collections.deque() dist[0] = True q.append(0) while q: n = q.popleft() for adjacent in ways[n]: if dist[adjacent] != -1: continue dist[adjacent] = dist[n] + 1 q.append(adjacent) if -1 in dist: print('No') else: print('Yes') for n, d in enumerate(dist): if n == 0: continue for adjacent in ways[n]: if d - 1 == dist[adjacent]: print(adjacent + 1) break
1
20,609,559,075,428
null
145
145
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()
a = input() print('Yes' if input() in a+a else 'No')
0
null
76,480,485,931,070
282
64
import collections n= int(input()) g=[] for _ in range(n): v,k,*varray= map(int,input().split()) g.append(varray) d= [-1]* (n+10) d[0]=0 q= collections.deque() q.append(0) while len(q)> 0: cur = q.popleft() for next in g[cur]: if d[next-1]== -1: d[next-1]= d[cur]+1 q.append(next-1) for i in range(n): print(i+1,d[i])
from collections import deque N = int(input()) Graph = {} Node = [] visited = [-1]*(N) for i in range(N): tmp = input().split() if int(tmp[1]) != 0: Graph[i] = [int(x)-1 for x in tmp[2:]] else: Graph[i] = [] queue = deque([0]) visited[0] = 0 while queue: x = queue.popleft() for i in Graph[x]: if visited[i] == -1: visited[i] = visited[x] + 1 queue.append(i) for i,j in enumerate(visited, 1): print(i, j)
1
4,592,982,230
null
9
9
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * N = INT() A = LIST() ans = INF A_sum = sum(A) tmp = 0 for x in A: tmp += x ans = min(ans, abs(tmp-(A_sum-tmp))) print(ans)
import sys input = sys.stdin.readline def main(): N = int(input()) A = list(map(int, input().split())) sum_A = sum(A) center = sum_A / 2 total = 0 near_center = 0 for a in A: total += a if abs(total - center) < abs(near_center - center): near_center = total ans = abs((sum_A - near_center) - near_center) print(ans) if __name__ == "__main__": main()
1
142,482,551,319,910
null
276
276
from collections import Counter N = input() D_list = list(map(int, input().split())) max_D = max(D_list) cnt_dic = dict(Counter(D_list)) if (D_list[0] == 0) & (cnt_dic.get(0) == 1): ans = 1 for n in range(1, max_D + 1): ans *= cnt_dic.get(n - 1, 0) ** cnt_dic.get(n, 1) print(ans % 998244353) else: print(0)
def main(): import sys def input(): return sys.stdin.readline().rstrip() n = int(input()) d = list(map(int, input().split())) mod = 998244353 from collections import Counter as cc c = cc(d) if c[0] != 1 or d[0] != 0: print(0) return m = max(d) ans = 1 for i in range(1, m+1): ans *= pow(c[i-1], c[i], mod) ans %= mod print(ans) if __name__ == '__main__': main()
1
155,015,951,966,132
null
284
284
n, a, b = map(int, input().split()) c = n//(a+b) ans = c*a n = n - c*(a+b) if n < a: print(ans + n) else: print(ans + a)
from collections import Counter N = int(input()) nums = list(map(int, input().split())) A = [i + n for i, n in enumerate(nums, start=1)] B = [j - n for j, n in enumerate(nums, start=1)] BC = Counter(B) answer = 0 for a in A: answer += BC[a] print(answer)
0
null
40,788,261,468,890
202
157
import sys from io import StringIO import unittest import os # 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む) sys.setrecursionlimit(999999999) class youk_prepare: def __init__(self, n, mod=pow(10, 9) + 7): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= mod factorials.append(f) inv = pow(f, mod - 2, mod) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= mod invs[m - 1] = inv self.factorials = factorials self.invs = invs self.mod = mod def cmb(self, n, r): if len(self.factorials) - 1 < n: raise ValueError("コンストラクタで指定した要素数を超えているので無理。") return (self.factorials[n] * self.invs[r] * self.invs[n - r]) % self.mod def multi_cmb(self, n, r): if len(self.factorials) - 1 < n: raise ValueError("コンストラクタで指定した要素数を超えているので無理。") return (self.factorials[n] * self.invs[r] * self.invs[n - r]) * ( self.factorials[n - 1] * self.invs[r] * self.invs[n - 1 - r]) % self.mod # 実装を行う関数 def resolve(test_def_name=""): try: n, k = map(int, input().split()) a_s = list(map(int, input().split())) a_s.sort() youk = youk_prepare(n) # 最小値の合計を計算 sum_mini = 0 for i in range(n - k + 1): target = a_s[i] val = target * youk.cmb(n - i - 1, k - 1) sum_mini += val # 最大値の合計を計算 sum_max = 0 for i in range(k - 1, n): target = a_s[i] val = target * youk.cmb(i, k - 1) sum_max += val ans = (sum_max - sum_mini) % (pow(10, 9) + 7) print(ans) except IndexError as err: print("インデックスエラー:", err.args[0]) # テストクラス class TestClass(unittest.TestCase): def assertIO(self, assert_input, output): stdout, sat_in = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(assert_input) resolve(sys._getframe().f_back.f_code.co_name) sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, sat_in self.assertEqual(out, output) def test_input_1(self): test_input = """4 2 1 1 3 4""" output = """11""" self.assertIO(test_input, output) def test_input_2(self): test_input = """6 3 10 10 10 -10 -10 -10""" output = """360""" self.assertIO(test_input, output) def test_input_3(self): test_input = """3 1 1 1 1""" output = """0""" self.assertIO(test_input, output) def test_input_4(self): test_input = """10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0""" output = """999998537""" self.assertIO(test_input, output) # 自作テストパターン def test_original(self): test_input = """4 2 1 2 3 4""" output = """10""" self.assertIO(test_input, output) # 実装orテストの呼び出し if __name__ == "__main__": if os.environ.get("USERNAME") is None: # AtCoder提出時の場合 resolve() else: # 自PCの場合 unittest.main()
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10**9) mod=10**9+7 MAX=10**5+100 g1=[1,1] g2=[1,1] for i in range(2,MAX+1): num_1=g1[-1]*i%mod g1.append(num_1) g2.append(pow(num_1,mod-2,mod)) def cmb(n,r): return g1[n]*g2[r]*g2[n-r]%mod N,K = I() A = l() A.sort() ans = 0 for i in range(N-K+1): ans -= A[i]*cmb(N-i-1,K-1) ans %= mod A = A[::-1] for i in range(N-K+1): ans += A[i]*cmb(N-i-1,K-1) ans %= mod print(ans%mod)
1
96,151,346,412,870
null
242
242
def main(): n, q = map(int, input().split()) queue = [[x for x in input().split()] for _ in range(n)] queue = [(x[0], int(x[1])) for x in queue] elapsed_time = 0 while len(queue) > 0: process, time = queue.pop(0) if time > q: queue.append((process, time - q)) elapsed_time += q else: elapsed_time += time print('{} {}'.format(process, str(elapsed_time))) return main()
import sys, bisect, math, itertools, heapq, collections from operator import itemgetter # a.sort(key=itemgetter(i)) # i番目要素でsort from functools import lru_cache # @lru_cache(maxsize=None) sys.setrecursionlimit(10**8) input = sys.stdin.readline INF = float('inf') mod = 10**9 + 7 eps = 10**-7 def inp(): ''' 一つの整数 ''' return int(input()) def inpl(): ''' 一行に複数の整数 ''' return list(map(int, input().split())) class combination(): def __init__(self, mod): ''' modを指定して初期化 ''' self.mod = mod self.fac = [1, 1] # 階乗テーブル self.ifac = [1, 1] # 階乗の逆元テーブル self.inv = [0, 1] # 逆元計算用 def calc(self, n, k): ''' nCk%modを計算する ''' if k < 0 or n < k: return 0 self.make_tables(n) # テーブル作成 k = min(k, n - k) return self.fac[n] * (self.ifac[k] * self.ifac[n - k] % self.mod) % self.mod def make_tables(self, n): ''' 階乗テーブル・階乗の逆元テーブルを作成 ''' for i in range(len(self.fac), n + 1): self.fac.append((self.fac[-1] * i) % self.mod) self.inv.append( (-self.inv[self.mod % i] * (self.mod // i)) % self.mod) self.ifac.append((self.ifac[-1] * self.inv[-1]) % self.mod) mod = 998244353 comb = combination(mod) n, m, k = inpl() ans = 0 for i in range(min(n, k + 1)): ans += m * pow(m - 1, n - 1 - i, mod) * comb.calc(n - 1, i) % mod ans %= mod print(ans)
0
null
11,706,813,846,002
19
151
a = int(input()) b = int(input()) n = int(input()) t = max(a, b) print((n + t - 1) // t)
s=input() t=input() l=len(s) ans=0 for i in range(l): if s[i]==t[i]: ans+=1 print(l-ans)
0
null
49,838,748,891,652
236
116
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] # MOD = int(1e09) + 7 MOD = 998244353 INF = int(1e15) def divisor(N): res = [] i = 2 while i * i <= N: if N % i == 0: res.append(i) if i != N // i: res.append(N // i) i += 1 if N != 1: res.append(N) return res def solve(): N = Scanner.int() d0 = divisor(N - 1) ans = len(d0) d1 = divisor(N) for d in d1: X = N while X % d == 0: X //= d if X % d == 1: ans += 1 print(ans) def main(): # sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
N = int(input()) X_ls = list(map(int, input().split(' '))) rst = -1 for i in range(min(X_ls), max(X_ls) + 1): val = 0 for j in X_ls: val += (i - j) ** 2 if rst == -1: rst = val else: rst = min(rst, val) print(rst)
0
null
53,421,754,278,510
183
213
a=sorted(input().split()) print(a[0]*int(a[1]))
a, b = map(int, input().split()) A = str(a) * b B = str(b) * a print(A) if A < B else print(B)
1
84,096,062,983,508
null
232
232
def floyd_warshall(G): for k in range(N): for i in range(N): for j in range(N): G[i][j]=min(G[i][j],G[i][k]+G[k][j]) import sys input=sys.stdin.readline INF=10**30 N,M,L=map(int,input().split()) dp1=[[INF]*N for i in range(N)] for i in range(N): dp1[i][i]=0 for _ in range(M): A,B,C=map(int,input().split()) A,B=A-1,B-1 dp1[A][B]=C dp1[B][A]=C floyd_warshall(dp1) dp2=[[INF]*N for i in range(N)] for i in range(N): for j in range(N): if i==j: dp2[i][j]=0 else: dp2[i][j]=1 if dp1[i][j]<=L else INF floyd_warshall(dp2) Q=int(input()) for _ in range(Q): s,t=map(lambda x:int(x)-1,input().split()) print (dp2[s][t]-1 if dp2[s][t]!=INF else -1)
n = int(input()) DifMax = -9999999999999 R = [int(input())] RMin = R[0] for i in range(1, n): if RMin > R[i-1]: RMin = R[i-1] R.append(int(input())) if DifMax < R[i] - RMin: DifMax = R[i] - RMin print(DifMax)
0
null
86,498,715,470,530
295
13
from itertools import permutations import math n = int(input()) x = [] y = [] for i in range(n): xi, yi = map(int, input().split(' ')) x.append(xi) y.append(yi) l = [i for i in range(n)] route = list(permutations(l)) length = 0 for ls in route: for i in range(n-1): length += math.sqrt((x[ls[i+1]]-x[ls[i]])**2+(y[ls[i+1]]-y[ls[i]])**2) ans = length/math.factorial(n) print(ans)
import itertools n = int(input()) twn = [list(map(int, input().split())) for _ in range(n)] twnst = list(itertools.permutations(twn)) dstttl = 0 for i in twnst: for j in range(0, len(i) - 1): dstttl += (abs(i[j][0] - i[j+1][0])**2 + abs(i[j][1] - i[j+1][1])**2)**0.5 print(dstttl / len(twnst))
1
148,552,300,014,898
null
280
280
import numpy as np a, b, x = map(int,input().split()) if x >= a**2*b/2: ans = np.arctan(2*(b-x/a**2)/a) else: ans = np.arctan(a*b/2/x*b) print(ans*180/np.pi)
import sys from math import atan, pi read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): a, b, x = map(int, readline().split()) if x > a * a * b / 2: angle = atan(2 * (a * a * b - x) / a ** 3) else: angle = atan(a * b * b / (2 * x)) print(angle / pi * 180) return if __name__ == '__main__': main()
1
163,527,008,521,358
null
289
289
def main(): N = int(input()) A = list(map(int, input().split())) a0, a1, a2, b0, b1, b2 = 0, 0, 0, 0, 0, 0 for i, a in enumerate(A): a0, a1, a2, b0, b1, b2 = ( b0, max(b1, a0), max(b2, a1), a0 + a, a1 + a if i >= 1 else a1, a2 + a if i >= 2 else a2) if N & 1: return max(b2, a1) else: return max(b1, a0) print(main())
x = int(input()) print(int(not x))
0
null
20,091,060,430,692
177
76
import queue n,u,v = map(int, input().split()) u -= 1 v -= 1 path = [[] for i in range(n)] for i in range(n-1): a,b = map(int, input().split()) a -= 1 b -= 1 path[a].append(b) path[b].append(a) t = [10**9]*n t[u]=0 q = queue.Queue() q.put(u) while not q.empty(): p = q.get() for x in path[p]: if t[x]>t[p]+1: q.put(x) t[x]=t[p]+1 a = [10**9]*n a[v]=0 q = queue.Queue() q.put(v) while not q.empty(): p = q.get() for x in path[p]: if a[x]>a[p]+1: q.put(x) a[x]=a[p]+1 c = [a[i] for i in range(n) if a[i]>t[i]] print(max(c)-1)
S = input() count = 0 for i in range(len(S)//2): if(S[i] != S[-i-1]): count += 1 print(count)
0
null
118,810,530,428,352
259
261
n=input() data=input().split() data.reverse() print(' '.join(data))
a = int(input()) if a % 2 == 0 : print((a - a / 2 ) / a) else: print((a - a // 2) / a) # 5 ,4 ,3 ,2 ,1 # 3 /5
0
null
88,712,157,610,460
53
297
#dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()] print('ACL'*inp())
class ARepeatACL(): def main(self): K = int(input()) print('ACL' * K) if __name__ == "__main__": this_class = ARepeatACL() this_class.main()
1
2,180,507,931,368
null
69
69
ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) n,u,v = mi() data = [[] for _ in range(n)] for i in range(n-1): a,b = mi() a -= 1 b -= 1 data[a].append(b) data[b].append(a) inf = -1 oni = [inf]*n ko = [inf]*n from collections import deque def start(hazime,alis): d = deque() d.append((hazime-1,0)) alis[hazime-1] = 0 while d: ima,num = d.popleft() num += 1 for i in data[ima]: if alis[i] != inf: continue alis[i] = num d.append((i,num)) start(u,ko) start(v,oni) if len(data[u]) == 1 and data[u] == v: print(0) exit() ans = -1 for i in range(n): if ko[i] <= oni[i]: ans = max(ans,oni[i]-1) print(ans)
import sys,heapq input = sys.stdin.readline def main(): n,u,v = map(int,input().split()) u,v = u-1,v-1 edge = [[] for _ in range(n)] for _ in [0]*(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) #cost:vからの距離 cost = [0]*n new = [v] c = 1 while len(new): tank = [] for e in new: for go in edge[e]: if go != v and cost[go] == 0: cost[go] = c tank.append(go) c += 1 new = tank if cost[u]%2 == 1: res = cost[u]//2 now = u for _ in [0]*res: for e in edge[now]: if cost[now] > cost[e]: now = e new = [now] while len(new): tank = [] for e in new: for go in edge[e]: if cost[go] > cost[e]: tank.append(go) res += 1 new = tank print(res-1) else: res = cost[u]//2-1 now = u for _ in [0]*res: for e in edge[now]: if cost[now] > cost[e]: now = e new = [now] while len(new): tank = [] for e in new: for go in edge[e]: if cost[go] > cost[e]: tank.append(go) res += 1 new = tank print(res) if __name__ == '__main__': main()
1
117,550,794,365,450
null
259
259
import itertools #h,w=map(int,input().split()) #S=[list(map(int,input().split())) for _ in range(h)] n=int(input()) P=list(map(int,input().split())) Q=list(map(int,input().split())) num=0 numlist=[i for i in range(1,n+1)] pall=list(itertools.permutations(numlist)) for pp in pall: if P==list(pp): pnum=num if Q==list(pp): qnum=num num+=1 print(abs(pnum-qnum))
n = int(input()) p = str(tuple(map(int, input().split()))) q = str(tuple(map(int, input().split()))) import itertools n_l = [ i+1 for i in range(n) ] d = {} for i, v in enumerate(itertools.permutations(n_l)): d[str(v)] = i print(abs(d[p]-d[q]))
1
101,154,118,427,606
null
246
246
import math n,a,b=map(int,input().split()) mod=10**9+7 c1=1 c2=1 for i in range(n-a+1,n+1): c1*=i c1%=mod for j in range(1,a+1): c1*=pow(j,mod-2,mod) c1%=mod for i in range(n-b+1,n+1): c2*=i c2%=mod for j in range(1,b+1): c2*=pow(j,mod-2,mod) c2%=mod ans=pow(2,n,mod)-1 print((ans-c1-c2)%mod)
import math N=int(input()) A=[0]*N B=[0]*N for i in range(N): A[i],B[i]=map(int,input().split()) total=0 for i in range(N): for j in range(i+1,N): total+=((A[i]-A[j])**2+(B[i]-B[j])**2)**0.5 print(total/N*2)
0
null
107,495,537,972,540
214
280
a, b = map(str, input().split()) a = int(a) c, d = map(int, b.split('.')) b = c * 100 + d b *= a print(int(("00" + str(b))[:-2]))
import math from decimal import Decimal A, B = input().split() A = int(A) B = Decimal(B) C = A * B ans = math.floor(C) print(ans)
1
16,597,971,615,068
null
135
135
def FizzBuzz_sum(): # 入力 N = int(input()) # 初期処理 N = [i for i in range(1,N+1)] sum = 0 # 比較処理 for i in N: if i % 3 == 0 and i % 5 == 0: pass elif i % 3 == 0: pass elif i % 5 == 0: pass else: sum += i return sum result = FizzBuzz_sum() print(result)
N = int(input()) S = 0 for i in range(1, N + 1): if i % 15 == 0: S += 0 elif i % 3 == 0: S += 0 elif i % 5 == 0: S += 0 else: S += i print(S)
1
34,729,860,554,158
null
173
173
import math A = list(map(int, input().split())) H = A[0] W = A[1] first = math.ceil(H/2) second = math.floor(H/2) if H>= 2 and W>=2: ans = math.ceil(W/2)*first + math.floor(W/2)*second elif W==1: ans = 1 elif H==1: ans = 1 print(ans)
N,X = map(int,input().split()) Y = N - sum(map(int,input().split())) print(("-1",Y)[Y >= 0])
0
null
41,582,162,223,676
196
168
s = input()[::-1] dataset = [0]*2019 dataset[0] = 1 n = 0 d = 1 for i in s: n += int(i) * d a = n % 2019 dataset[a] += 1 d *= 10 d %= 2019 count = 0 for i in dataset: count += i * (i-1) // 2 print(count)
import sys while True: (H, W) = [int(i) for i in sys.stdin.readline().split()] if H == W == 0: break line = "#." * int(W / 2 + 1) for i in range(H): if i % 2: print(line[1:W+1]) else: print(line[:W]) print("")
0
null
15,881,939,964,700
166
51
n=int(input()) c = [[0]*10 for i in range(10)] n_len = len(str(n)) for k in range(1,n+1): k_str = str(k) l,r=int(k_str[0]),int(k_str[-1]) c[l][r]+=1 cnt = 0 for i in range(10): for j in range(10): cnt += c[i][j]*c[j][i] print(cnt)
def main(): N = int(input()) n = str(N) cnt = [[0] * (10) for _ in range(10)] for i in range(1, N+1): a = int(str(i)[0]) b = i%10 cnt[a][b] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): ans += cnt[i][j]*cnt[j][i] print(ans) main()
1
86,505,584,852,830
null
234
234
n=int(input()) if n<600: print(8) exit() if n<800: print(7) exit() if n<1000: print(6) exit() if n<1200: print(5) exit() if n<1400: print(4) exit() if n<1600: print(3) exit() if n<1800: print(2) exit() if n<2000: print(1) exit()
X = int(input()) if ((2000-X)%200) == 0: print((2000-X)//200) else: print((2000-X)//200+1)
1
6,702,193,413,470
null
100
100
while True: l = input().split() h = int(l[0]) w = int(l[1]) if h == 0 and w == 0: break element = h*(w+1) for i in range(element): if (i+1)%(w+1) == 0: print("") if i == element-1: print("") elif i+1 < w or i+1 > element-w-1: print("#", end="") else: if (i+1)%(w+1) == 1 or (i+1)%(w+1) == w: print("#", end="") else: print(".", end="")
import math def f(n): pop = 0 ntemp = n for i in range(int(math.log2(n)) + 1): pop += ntemp % 2 ntemp //= 2 return n % pop n = int(input()) S = input() popcount = 0 for i in range(n): popcount += int(S[i]) # 1が1個しかない場合の例外処理 if popcount == 1: if S[-1] == 1: ans = [2] * n ans[-1] = 0 else: ans = [1] * n ans[-1] = 2 for i in range(n): if S[i] == '1': ans[i] = 0 for i in range(n): print(ans[i]) exit() Sint = int(S, 2) remminus = Sint % (popcount - 1) remplus = Sint % (popcount + 1) # 1,2,4,...の余りのリストを準備 remlistminus = [] remlistplus = [] temp = 1 for i in range(n): remlistminus.append(temp) temp = (temp * 2) % (popcount - 1) temp = 1 for i in range(n): remlistplus.append(temp) temp = (temp * 2) % (popcount + 1) remlistminus.reverse() remlistplus.reverse() ans = [] for i in range(n): count = 1 if S[i] == '0': rem = (remplus + remlistplus[i]) % (popcount + 1) while rem > 0: rem = f(rem) count += 1 else: rem = (remminus - remlistminus[i]) % (popcount - 1) while rem > 0: rem = f(rem) count += 1 ans.append(count) for i in range(n): print(ans[i])
0
null
4,508,476,862,460
50
107
def selection_sort(numbers, n): """selection sort method Args: numbers: a list of numbers to be sorted n: len(numbers) Returns: sorted numberd, number of swapped times """ counter = 0 for i in range(0, n - 1): min_j = i for j in range(i + 1, n): if numbers[j] < numbers[min_j]: min_j = j if min_j != i: numbers[min_j], numbers[i] = numbers[i], numbers[min_j] counter += 1 return numbers, counter length = int(raw_input()) numbers = [int(x) for x in raw_input().split()] numbers, number_of_swapped_times = selection_sort(numbers, length) print(" ".join([str(x) for x in numbers])) print(number_of_swapped_times)
#coding: UTF-8 import sys import math class Algo: @staticmethod def insertionSort(r, n): count = 0 for i in range(0,n): minj = i for j in range(i,n): if r[j] < r[minj]: minj = j if r[i] != r[minj]: r[i], r[minj] = r[minj], r[i] count += 1 for i in range(0,n): if i == n-1: print(r[i]) else: print(r[i], " ", sep="", end="") print(count) N = int(input()) R= list(map(int, input().split())) Algo.insertionSort(R, N)
1
20,699,165,888
null
15
15
W,H,x,y,r = map(int, input().split()) if W < (x+r) or H < (y + r) or 0 > (x-r) or 0 > (y-r) : print("No") else : print("Yes")
d=raw_input().split(" ") l=list(map(int,d)) if(l[2]>0 and l[3]>0): if(l[0]>=(l[2]+l[4])): if(l[1]>=(l[3]+l[4])): print "Yes" else: print "No" else: print "No" else: print "No"
1
438,077,582,008
null
41
41
#!/usr/bin/env python3 n=int(input()) print((n-n//2)/n)
N = int(input()) odd = (N+1)//2 print(odd/N)
1
177,254,435,592,170
null
297
297