code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
n,m = map(int,input().split()) dic = {} ac = 0 wa = 0 for _ in range(m): p,s = map(str,input().split()) p = int(p) if p not in dic: if s =='AC': ac += 1 dic[p] = s else: dic[p] = 1 elif dic[p]=='AC': continue else: if s =='AC': ac += 1 wa +=dic[p] dic[p] = s else: dic[p] += 1 print(str(ac) + ' ' + str(wa))
H,N = map(int,input().split()) A = list(map(int,input().split())) sum =0 for i in range(len(A)): sum = sum + A[i] if sum >= H: print("Yes") else: print("No")
0
null
85,760,156,303,078
240
226
x=list(input()) print('Yes' if '7' in x else 'No')
n = input() if "7" in n: print('Yes') else: print('No')
1
34,165,645,054,012
null
172
172
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) import numpy as np n, m = map(int, readline().split()) a = np.array(read().split(), np.int64) a.sort() def check(mid): mid = np.searchsorted(a, mid - a) return n * n - mid.sum() >= m left = 0 right = 10 ** 6 while left + 1 < right: mid = (left + right) // 2 if check(mid): left = mid else: right = mid mid = np.searchsorted(a, right - a) cumsum = np.zeros(n + 1, np.int64) cumsum[1:] = np.cumsum(a) ans = (cumsum[-1] - cumsum[mid]).sum() + (a * (n - mid)).sum() + (m - n * n + mid.sum()) * left print(ans)
import sys read = sys.stdin.buffer.read input = sys.stdin.buffer.readline inputs = sys.stdin.buffer.readlines import bisect n,m=map(int,input().split()) A=list(map(int,input().split())) A.sort() def hand(x): cnt=0 for i in range(n): p=x-A[i] cnt+=n-bisect.bisect_left(A,p) return cnt def main(): l=0 h=2*10**5+1 mid=(l+h)//2 while l+1<h: mid=(l+h)//2 if hand(mid)<m: h=mid else: l=mid B=A[::-1] for i in range(n-1): B[i+1]+=B[i] B=B[::-1] ans=0 cnt=0 for i in range(n): y=l-A[i]+1 index=bisect.bisect_left(A,y) if n==index: continue else: ans+=(n-index)*A[i]+B[index] cnt+=(n-index) ans+=(m-cnt)*l print(ans) if __name__ == "__main__": main()
1
108,552,715,983,008
null
252
252
n = int(input()) a = list(map(int,input().split())) count = 0 for i in range(n): minij =i for j in range(i,n): if a[j] < a[minij]: minij = j if a[i] > a[minij]: count+=1 a[i],a[minij] = a[minij],a[i] print(' '.join(map(str,a))) print(count)
N = int(input()) cnt = 0 for A in range(1, N + 1): for B in range(1, N // A + 1): C = N - A * B if C >= 1 and A * B + C == N: cnt += 1 print(cnt)
0
null
1,284,034,515,520
15
73
s = input() ans = '' for i in range(len(s)): ans = ans + 'x' print(ans)
input = input() L, R, d = [int(n) for n in input.split()] count = 0 for n in range(L, R+1): if n % d == 0: count += 1 print(count)
0
null
40,073,172,646,080
221
104
N,X,T = [int(i) for i in input().split()] print((N+X-1)//X*T)
a,b,c=map(int,input().split()) x = 0 y = 0 for i in range(a): x = x + c y = y + b if a <= y: print(x) break
1
4,261,699,517,800
null
86
86
import collections N=int(input()) A=list(map(int,input().split())) A=sorted(A) c=collections.Counter(A) if __name__=="__main__": if 1 in A: if c[1]==1: print(1) else: print(0) else: A=[] dp=[True for _ in range(10**6+10)] for key,value in c.items(): if value==1: A.append(key) else: if dp[key]: i=2 while i*key<=10**6: dp[i*key]=False i+=1 if len(A)==0: print(0) else: for a in A: if dp[a]: i=2 while i*a<=10**6: dp[i*a]=False i+=1 ans=0 for a in A: if dp[a]: ans+=1 print(ans)
n = int(input()) a = [] for i in range(n): s = str(input()) a.append(s) b = set(a) print(len(b))
0
null
22,218,923,697,860
129
165
import sys readline=sys.stdin.readline N=int(readline()) # 1~(N - 1)の約数を数える ans = 0 for i in range(1, N): for j in range(i, N, i): ans += 1 print(ans)
import sys input = sys.stdin.readline n = int(input()) ans = 0 for a in range(1,n+1): ans += (n-1) // a print(ans)
1
2,596,839,777,840
null
73
73
n,m = map(int,input().split()) a = list(map(int,input().split())) ans = 0 for i in range(m): ans += a[i] if n < ans: print(-1) else: print(n-ans)
def nishin(n): return str(bin(n)[2:])[::-1] N=int(input()) L=list(map(int,input().split())) mod=1000000007 ans=sum(L)*(N-1) c=[0]*61 for i in L: i=nishin(i) for j in range(len(i)): if i[j]=="1": c[j]+=1 for i in range(61): ans-=(pow(2,i,mod)*c[i]*(c[i]-1))%mod print(ans%mod)
0
null
77,079,903,543,962
168
263
from fractions import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations def main(): A, B, K = map(int, input().split()) if A >= K: print(A - K, B) elif A < K: if K - A >= B: print(0, 0) else: print(0, B - (K - A)) if __name__ == '__main__': main()
a, b = map(int, input().split()) if b * 2 >= a: print('0') else: print(a - b * 2)
0
null
135,807,898,544,932
249
291
X = int(input()) A = 0 B = 0 if X >= 500: A = X // 500 X = X % 500 if X >= 5: B = X // 5 X = X % 5 print(A * 1000 + B * 5)
#!/usr/bin/env python3 x, y = [int(x) for x in input().split()] p = [300000, 200000, 100000] if x == 1 and y == 1: print(1000000) elif x <= 3 and y <= 3: print(p[x - 1] + p[y - 1]) elif x <= 3: print(p[x - 1]) elif y <= 3: print(p[y - 1]) else: print(0)
0
null
91,203,582,541,020
185
275
N, M = map(int, input().split()) A = list(map(int, input().split())) cr = sum(A) / (4*M) Arev = sorted(A, reverse = True) if Arev[M-1] >= cr: print('Yes') else: print('No')
n,m = map(int,input().split()) a = list(map(int,input().split())) b = sum(a)/(4*m) cnt = 0 for i in a: if b <= i: cnt += 1 if cnt >= m: print("Yes") exit() print("No")
1
38,579,846,226,350
null
179
179
import math N, K=map(int, input().split()) A=list(map(int, input().split())) F=list(map(int, input().split())) A=sorted(A, reverse=False) F=sorted(F, reverse=True) a=-1 b=max([A[i]*F[-i-1] for i in range(N)]) while b-a>1: tmp=(a+b)//2 c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)]) if c<=K: b=tmp else: a=tmp print(b)
# coding: utf-8 # hello worldと表示する #float型を許すな #numpyはpythonで import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial,sqrt from operator import itemgetter def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI2(): return [int(input()) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf = 10**17 mod = 10**9 + 7 def ceiler(a,b): return -((-a)//b) n,k=MI() costs=LI() difs=LI() costs.sort() difs.sort(reverse=True) lis=[0 for i in range(n)] #print(costs) #print(difs) for i in range(n): lis[i]=costs[i]*difs[i] #print(lis) def judge(x): times=0 for i in range(n): u=ceiler(lis[i]-x,difs[i]) times+=max(0,u) #print(u) #print(x,times<=k) return times<=k l,r=-1,10**13 while l+1<r: mid=(l+r)//2 if judge(mid): r=mid else: l=mid print(r)
1
165,381,915,834,680
null
290
290
import sys from itertools import combinations 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()) n = I() s = S() # print(s.count('ABC')) ans = 0 for i in range(len(s)-2): if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C': ans += 1 print(ans)
from collections import defaultdict, deque V, E = map(int, input().split()) graph = defaultdict(dict) for _ in range(E): a, b = map(int, input().split()) graph[a][b] = True graph[b][a] = True components = [] # list of components visited = set() for i in range(1, V+1): if i in visited: continue # do bfs starting from i current_component = set() queue = deque([i]) visited.add(i) while queue: x = queue.popleft() current_component.add(x) for nbr in graph[x]: if nbr not in visited: queue.append(nbr) visited.add(nbr) components.append(current_component) print(max(map(len, components)))
0
null
51,871,711,714,760
245
84
A, B = [int(x) for x in input().split(" ")] if A > B*2: print(A-B*2) else: print(0)
N = int(input()) list = input().split() answer = [0] * N for i in range(N): answer[int(list[i]) - 1] = str(i + 1) print(' '.join(answer))
0
null
173,737,308,660,448
291
299
BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 while True: M,F,R = map(int,input().split()) if M == -1 and F == -1 and R == -1: break if M == -1 or F == -1: print("F") elif M+F >= 80: print("A") elif M+F >= 65: print("B") elif M+F >= 50: print("C") elif M+F >= 30: if R >= 50: print("C") else: print("D") else: print("F")
S = input() cnt = 0 for i in range(len(S)//2): if S[i] != S[-1-i]: cnt += 1 else: continue print(cnt)
0
null
60,794,826,899,004
57
261
import math def standard_deviation() : while True : n = input() if n==0 : break s_d = [0]*n average = 0 standard = 0 s_d= map(float,raw_input().split()) for i in range(n): average += s_d[i] average /= float(n) for i in range(n): standard += pow(s_d[i]-average,2) / float(n) print(math.sqrt(standard)) standard_deviation()
import statistics while True: n = int(input()) if n == 0: break s = map(int, input().split()) print('{:.5f}'.format(statistics.pstdev(s)))
1
193,941,259,552
null
31
31
import sys def main(): for line in iter(sys.stdin.readline, ""): #print (line) a = line.rstrip("\n") tmp = a.split(" ") a = int(tmp[0]) b = int(tmp[1]) n = int(tmp[2]) cnt = 0 for i in range(1, n+1): if (n % i == 0) and (a <= i and i <= b): cnt = cnt + 1 #print (i) print (cnt) if __name__ == "__main__": main()
z = input() a = list(map(int, z.split())) cnt = 0 for i in range(a[0], a[1] + 1, 1): if a[2] % i == 0: cnt += 1 print(cnt)
1
559,838,054,580
null
44
44
a, b, m = map(int, input().split()) a_s = list(map(int, input().split())) b_s = list(map(int, input().split())) m_s =[] for _ in range(m): m_s.append(list(map(int, input().split()))) mini = min(a_s) + min(b_s) for am, bm, sale in m_s: mini = min(mini, a_s[am-1]+b_s[bm-1]-sale) print(mini)
s = input() k = int(input()) n = len(s) ss = set(s) # print(ss) ans = 0 if len(ss) == 1: print(k*n//2) # print('y') exit() if n == 1: print(n//2) exit() streaks = [] cnt = 0 now = s[0] for i in range(n): if now == s[i]: cnt += 1 else: streaks.append(cnt) now = s[i] cnt = 1 streaks.append(cnt) # print(streaks) m = len(streaks) if s[0] == s[-1]: for i in range(1, m-1): ans += streaks[i]//2 # print(ans) ans *= k # print(ans) ans += (streaks[0] + streaks[m-1])//2*(k-1) # print(ans) ans += streaks[0]//2 + streaks[m-1]//2 # print(ans) else: for i in range(m): ans += streaks[i]//2 ans *= k print(ans)
0
null
114,823,908,463,968
200
296
cnt = 0 n = int(input()) a = list(map(int,input().split())) for i in range(0,n): mini = i for j in range(i,n): if a[j]<a[mini]: mini = j a[i],a[mini] = a[mini],a[i] if i!=mini: cnt += 1 print(" ".join(map(str,a))) print(cnt)
L = int(input("")) a = L / 3.0 print(pow(a,3))
0
null
23,341,810,097,608
15
191
N,M=map(int, input().split()) A=list(map(int, input().split())) A = sorted(A, reverse=True) s = sum(A) th = s * 1/(4*M) if A[M-1] < th: print('No') else: print('Yes')
import math def lcm(A, B): return int((A * B) / math.gcd(A, B)) A, B = map(int, input().split()) print(lcm(A,B))
0
null
76,280,486,522,930
179
256
N, K, S = map(int, input().split()) if S == 10 ** 9: res = [S] * K res.extend([1] * (N - K)) else: res = [S] * K res.extend([S + 1] * (N - K)) print(*res)
n,k,s = map(int,input().split()) u = [] if n == k: for i in range(n): u.append(s) else: if s%2==0: for i in range(k+1): u.append(int(s/2)) for i in range(n-k-1): u.append(10**9-1) else: if s==1: for i in range(k): u.append(1) for i in range(n-k): u.append(10**9) else: if k%2==0: u.append(int((s-1)/2)) for i in range(int(k/2)): u.append(int((s+1)/2)) u.append(int((s-1)/2)) for i in range(n-k-1): u.append(10**9) else: for i in range(int((k+1)/2)): u.append(int((s+1)/2)) u.append(int((s-1)/2)) for i in range(n-k-1): u.append(10**9) print(' '.join(map(str,u)))
1
91,182,236,252,640
null
238
238
for a in range(1,10): for b in range(1,10): print("%dx%d=%d" % (a,b,a*b))
y = 1 while y<10: x = 1 while x<10: print str(y)+'x'+str(x)+'='+str(y*x) x += 1 y += 1
1
3,108,380
null
1
1
#ALDS_11_B - 深さ優先探索 import sys input = sys.stdin.readline sys.setrecursionlimit(10**9)#再帰回数の上限 def DFS(u, cnt): visited.add(u) first_contact = cnt cnt += 1 for nb in edge[u]: if nb not in visited: cnt = DFS(nb, cnt) stamp[u] = first_contact, cnt return cnt+1 N = int(input()) edge = [[] for i in range(N)] for _ in range(N): tmp = list(map(int,input().split())) if tmp[1] != 0: edge[tmp[0]-1] = list(map(lambda x: int(x-1),tmp[2:])) stamp = [None]*N visited = set() c = 1 for i in range(N): if i not in visited: c = DFS(i, c) for i,s in enumerate(stamp): print(i+1,*s)
import sys input = sys.stdin.buffer.readline import numpy as np def main(): N,M = map(int,input().split()) a = np.array(input().split(),np.int64) a = np.sort(a) cum = np.zeros(N+1,dtype=int) cum[1:] = np.cumsum(a) l,r = -1,10**6+1 while r-l > 1: mid = (l+r)//2 ab_mid = (N-np.searchsorted(a,mid-a,side="left")).sum() if ab_mid >= M: l = mid else: r = mid pos_rev = np.searchsorted(a,r-a,side="left") count = (N-pos_rev).sum() ans = (cum[-1]-cum[pos_rev]).sum() ans += (a*(N-pos_rev)).sum() ans += (M-count)*l print(ans) if __name__ == "__main__": main()
0
null
53,981,724,992,960
8
252
N, X, M = map(int, input().split()) checked = [-1] * M a = X i = 0 while checked[a] == -1 and i < N: checked[a] = i a = a**2 % M i += 1 if i == N: a = X ans = 0 for _ in range(N): ans += a a = a**2%M print(ans) else: cycle_size = i - checked[a] cycle_num = a cycle = [] cycle_sum = 0 for _ in range(cycle_size): cycle.append(cycle_num) cycle_sum += cycle_num cycle_num = cycle_num**2 % M before_cycle_size = checked[a] before_cycle = [] before_cycle_sum = 0 num = X for _ in range(before_cycle_size): before_cycle.append(num) before_cycle_sum += num num = num**2 % M ans = before_cycle_sum ans += (N-before_cycle_size)//cycle_size * cycle_sum after_cycle_size = (N-before_cycle_size)%cycle_size for i in range(after_cycle_size): ans += cycle[i] print(ans)
l=map(int,raw_input().split()) a=l[0] b=l[1] c=l[2] if a>b: a,b=b,a if b>c: b,c=c,b if a>b: a,b=b,a print a,b,c
0
null
1,588,105,770,004
75
40
icase=0 if icase==0: k,x=map(int,input().split()) if 500*k>=x: print("Yes") else: print("No")
# coding: utf-8 s = list(input().rstrip()) ht = [] ponds=[] for i, ch in enumerate(s): if ch == "\\": ht.append(i) elif ch == "/": if ht: b = ht.pop() ap = i - b if not ponds: ponds.append([b, ap]) else: while ponds: p = ponds.pop() if p[0] > b: ap += p[1] else: ponds.append([p[0],p[1]]) break ponds.append([b,ap]) else: pass ans = "" area = 0 for point, ar in ponds: area += ar ans += " " ans += str(ar) print(area) print(str(len(ponds)) + ans)
0
null
48,956,403,826,528
244
21
from operator import itemgetter N,M = map(int,input().split()) PS = [list(map(str,input().split())) for i in range(M)] for i in range(M) : PS[i][0] = int(PS[i][0]) submits = [["null"] for i in range(N)] for i in range(M) : submits[PS[i][0]-1][0] = PS[i][0]-1 submits[PS[i][0]-1].append(PS[i][1]) ac = 0 pena = 0 for i in range(len(submits)) : if submits[i][0] == "null" : continue flag = False wabuf1 = 0 for j in range(1,len(submits[i])) : if submits[i][j] == "AC" : ac += 1 flag = True break else : wabuf1 += 1 if flag == True : pena += wabuf1 print(ac,pena)
import collections a=int(input()) b=list(map(int,input().split())) c=collections.Counter(b) n,m=zip(*c.most_common()) n,m=list(n),list(m) o=c.most_common() result=[0]*a for i in range(len(o)): result[o[i][0]-1]=o[i][1] for i in result: print(i)
0
null
62,955,772,083,512
240
169
N, K = map(int, input().split()) p = list(map(int, input().split())) E = [0] * N for i in range(N): P = 0.5 * p[i] * (p[i] + 1) E[i] = P / p[i] S = sum(E[:K]) s = S for i in range(N - K): s -= E[i] s += E[i + K] S = max(S, s) print(S)
N,K=map(int,input().split()) p=list(map(int,input().split())) exp0 = (sum(p[:K])+K)/2 MAX=exp0 old = exp0 for i in range(1,N-K+1): new = old + (p[K+i-1]+1)/2 - (p[i-1]+1)/2 if new > MAX: MAX = new old = new print(MAX)
1
75,221,097,153,368
null
223
223
while True: s = input().rstrip().split(' ') a = int(s[0]) b = int(s[2]) op = s[1] if op == "?": break elif op == "+": print(str(a + b)) elif op == "-": print(str(a - b)) elif op == "*": print(str(a * b)) elif op == "/": print(str(int(a / b)))
# coding: utf-8 while 1: a, op, b = input().split() if op == "+": ans = int(a) + int(b) elif op == "-": ans = int(a) - int(b) elif op == "*": ans = int(a) * int(b) elif op == "/": ans = int(a) // int(b) else: break print(ans)
1
676,413,949,222
null
47
47
n = int(input()) x = input() original_pop_count = x.count('1') one_pop_count = original_pop_count - 1 # 0になりうる zero_pop_count = original_pop_count + 1 # X mod p(X) += 1 の前計算 one_mod = 0 zero_mod = 0 for b in x: if one_pop_count != 0: one_mod = (one_mod * 2 + int(b)) % one_pop_count zero_mod = (zero_mod * 2 + int(b)) % zero_pop_count # f の前計算 f = [0] * 220000 pop_count = [0] * 220000 for i in range(1, 220000): # pop_count[i] = pop_count[i // 2] + i % 2 pop_count[i] = bin(i)[2:].count('1') f[i] = f[i % pop_count[i]] + 1 for i in range(n-1, -1, -1): if x[n-i-1] == '1': if one_pop_count != 0: nxt = one_mod nxt -= pow(2, i, one_pop_count) nxt %= one_pop_count print(f[nxt] + 1) else: print(0) elif x[n-i-1] == '0': nxt = zero_mod nxt += pow(2, i, zero_pop_count) nxt %= zero_pop_count print(f[nxt] + 1)
n = int(input()) s = input() int_s = [int(i) for i in s] pc = s.count('1') def f(x): bi = bin(x) pc = bi.count('1') cnt = 1 while True: if x == 0: break x = x % pc bi = bin(x) pc = bi.count('1') cnt += 1 return cnt num_pl = 0 for i in range(n): num_pl = (num_pl*2) % (pc+1) num_pl += int_s[i] num_mi = 0 for i in range(n): if pc-1 <= 0: continue num_mi = (num_mi*2) % (pc-1) num_mi += int_s[i] ans = [0]*n pc_pl, pc_mi = pc+1, pc-1 r_pl, r_mi = 1, 1 for i in range(n-1, -1, -1): if int_s[i] == 0: num = num_pl num = (num+r_pl) % pc_pl else: num = num_mi if pc_mi <= 0: continue num = (num-r_mi+pc_mi) % pc_mi ans[i] = f(num) r_pl = (r_pl*2) % pc_pl if pc_mi <= 0: continue r_mi = (r_mi*2) % pc_mi print(*ans, sep='\n')
1
8,200,465,941,500
null
107
107
import numpy as np from numba import njit @njit def solve(stdin): n, k = stdin[:2] A = stdin[2: 2 + n] A = np.sort(A)[::-1] F = np.sort(stdin[2 + n:]) def is_ok(x): tmp = 0 for a, f in zip(A, F): y = a * f if y > x: tmp += a - x // f return tmp <= k ok = 10 ** 16 ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok print(solve(np.fromstring(open(0).read(), dtype=np.int64, sep=' ')))
n,k=map(int,input().split()) a=list(map(int,input().split())) f=list(map(int,input().split())) a.sort() f.sort(reverse=True) ok=10**15 ng=-1 while ok-ng>1: check=(ok+ng)//2 cnt=0 for i in range(n): cnt+=(max(0,a[i]-check//f[i])) if cnt > k:ng = (ok+ng)//2 else: ok = (ok+ng)//2 print(ok)
1
164,534,941,138,528
null
290
290
D = int(input()) c = [int(i) for i in input().split()] s = [] for i in range(D): tmp = [int(j) for j in input().split()] s.append(tmp) t = [] for i in range(D): t.append(int(input())) sat = 0 lst = [0 for i in range(26)] for i in range(D): sat += s[i][t[i]-1] lst[t[i]-1] = i + 1 for j in range(26): sat -= c[j] * ((i + 1) - lst[j]) print(sat)
import sys readline = sys.stdin.readline D = int(readline()) C = list(map(int,readline().split())) S = [None] * D for i in range(D): s = list(map(int,readline().split())) S[i] = s def calc_score(arr): point = 0 last_submit = [-1] * 26 for i in range(len(arr)): point += S[i][arr[i]] last_submit[arr[i]] = i for j in range(len(last_submit)): point -= (i - last_submit[j]) * C[j] print(point) return point T = [None] * D for i in range(D): T[i] = int(readline()) - 1 ans = calc_score(T)
1
9,863,349,676,042
null
114
114
n = int(input()) L = list(map(int,input().split())) L.sort() import bisect ans = 0 for i in range(1,n): for j in range(i+1,n): tmp = L[:i] v = L[j]-L[i] idv = bisect.bisect_right(tmp,v) if idv!=len(tmp): ans += len(tmp)-idv print(ans)
mod = 10 ** 9 + 7 N = int(input()) result = 0 ten = pow(10, N, mod) nine = pow(9, N, mod) eight = pow(8, N, mod) result = (ten - 2 * nine + eight) % mod print(result)
0
null
87,498,258,617,942
294
78
import math a = float(input()) print(a*a*math.pi, 2*a*math.pi)
x = map(int, raw_input().split()) x.sort() print "%d %d %d" %(x[0],x[1],x[2])
0
null
536,349,973,780
46
40
#!/usr/bin python3 # -*- coding: utf-8 -*- r, c, k = map(int, input().split()) itm = [[0]*(c) for _ in range(r)] for i in range(k): ri, ci, vi = map(int, input().split()) itm[ri-1][ci-1] = vi dp0 = [[0]*4 for c_ in range(3005)] dp1 = [[0]*4 for c_ in range(3005)] for i in range(r): for j in range(c): nowv = itm[i][j] dp0[j][3] = max(dp0[j][3], dp0[j][2] + nowv) dp0[j][2] = max(dp0[j][2], dp0[j][1] + nowv) dp0[j][1] = max(dp0[j][1], dp0[j][0] + nowv) dp0[j+1][0] = max(dp0[j+1][0], dp0[j][0]) dp0[j+1][1] = max(dp0[j+1][1], dp0[j][1]) dp0[j+1][2] = max(dp0[j+1][2], dp0[j][2]) dp0[j+1][3] = max(dp0[j+1][3], dp0[j][3]) dp1[j][0] = max(dp1[j][0], max(dp0[j])) dp0 = dp1.copy() print(max(dp1[c-1]))
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): H, W, k = map(int, input().split()) grid = [[0] * W for _ in range(H)] for _ in range(k): r, c, v = map(int, input().split()) grid[r - 1][c - 1] = v # dp[i][h][w]:h行目のアイテムをi個取得した時の、座標(h,w)における価値の最大値 dp = [[[0] * W for _ in range(H)] for _ in range(4)] dp[1][0][0] = grid[0][0] for h in range(H): for w in range(W): for i in range(4): # 下に移動する場合 if h + 1 < H: # アイテムを取らない dp[0][h + 1][w] = max(dp[0][h + 1][w], dp[i][h][w]) # アイテムを取る dp[1][h + 1][w] = max(dp[1][h + 1][w], dp[i][h][w] + grid[h + 1][w]) # 右に移動する場合 if w + 1 < W: # アイテムを取らない dp[i][h][w + 1] = max(dp[i][h][w + 1], dp[i][h][w]) # アイテムを取る(但し、4個以上所持してはいけない) if i + 1 < 4: dp[i + 1][h][w + 1] = max(dp[i + 1][h][w + 1], dp[i][h][w] + grid[h][w + 1]) res = 0 for i in range(4): res = max(res, dp[i][-1][-1]) print(res) if __name__ == '__main__': resolve()
1
5,577,267,731,002
null
94
94
N = int(input()) num_odd = int(N/2+0.5) print(num_odd/N)
N=int(input()) if N==1: print('{:.10f}'.format(1)) elif N%2==0: print('{:.10f}'.format(0.5)) else: print('{:.10f}'.format((N+1)/(2*N)))
1
177,469,421,304,110
null
297
297
N=int(input()) if(N%1000==0): print(0) else: print(-(-N//1000)*1000-N)
# import numpy as np import sys, math, heapq from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial, gcd from bisect import bisect_left, bisect_right sys.setrecursionlimit(10 ** 7) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline()[:-1] pl = lambda x: print(*x, sep="\n") H, W, M = map(int, input().split()) hw = [list(map(int, input().split())) for _ in range(M)] hb = defaultdict(int) wb = defaultdict(int) bomb = defaultdict(int) for hwi in hw: h, w = hwi hb[h] += 1 wb[w] += 1 bomb[(h, w)] += 1 # print(hb, wb) mhb = max(hb.values()) mwb = max(wb.values()) maxh = [key for key, val in hb.items() if val == mhb] maxw = [key for key, val in wb.items() if val == mwb] # print(maxh, maxw) for h in maxh: for w in maxw: if bomb[(h, w)] == 0: print(mhb + mwb) exit() print(mhb + mwb - 1)
0
null
6,549,668,702,180
108
89
def aizu001 (): xs = map(int,raw_input().split()) a = xs[0] b = xs[1] if a > b: print "a > b" elif a < b: print "a < b" else : print "a == b" aizu001()
s = input() s = s.split() n = [] for i in s: n.append(int(i)) a = n[0] b = n[1] print("a",end = " ") if a > b: print(">",end = " ") elif a < b: print("<",end = " ") else: print("==",end = " ") print("b")
1
364,715,423,138
null
38
38
# Aizu Problem ALDS_1_1_A: Insertion Sort # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input2.txt", "rt") def printA(A): print(' '.join([str(a) for a in A])) def insertion_sort(A): for i in range(1, len(A)): key = A[i] # insert A[i] into the sorted sequence A[0,...,j-1] j = i - 1 while j >= 0 and A[j] > key: A[j+1] = A[j] j -= 1 A[j+1] = key printA(A) N = int(input()) A = [int(_) for _ in input().split()] printA(A) insertion_sort(A)
def insertion_sort(A, n, g): global cnt for i in range(g, n): val = A[i] j = i - g while j >= 0 and A[j] > val: A[j + g] = A[j] j = j - g cnt += 1 A[j + g] = val def shell_sort(A, n): global cnt cnt = 0 G = [] h = 1 while h <= len(A): G.append(h) h = 3 * h + 1 G.reverse() print(len(G)) print(' '.join(map(str, G))) for i in range(0, len(G)): insertion_sort(A, n, G[i]) if __name__ == '__main__': n = int(input()) l = [int(input()) for _ in range(n)] shell_sort(l, n) print(cnt) for i in l: print(i)
0
null
17,872,850,112
10
17
INF = 10**18 N, K, C = map(int, input().split()) S = input() lt = [-INF for _ in range(K + 1)] rt = [-INF for _ in range(K + 1)] j = -1 for i in range(1, K + 1): while True: j += 1 if S[j] == 'o' and j - lt[i - 1] > C: lt[i] = j break j = -1 for i in range(1, K + 1): while True: j += 1 if S[-1 - j] == 'o' and j - rt[i - 1] > C: rt[i] = j break lt = lt[1:] rt = rt[1:] rt = [N - x - 1 for x in rt] rt = rt[::-1] res = [] for i in range(K): if lt[i] == rt[i]: res.append(lt[i] + 1) print('\n'.join(map(str, res)))
from heapq import heappush, heappop N, K, C = map(int, input().split()) S = input() if C == 0 : if K == S.count('o') : for i, s in enumerate(S) : if s == 'o' : print(i + 1) else : N += 2 S = 'x' + S + 'x' dpL = [0] * N dpR = [0] * N for l in range(1, N) : r = N - 1 - l dpL[l] = max(dpL[l - 1], int(S[l] == 'o')) dpR[r] = max(dpR[r + 1], int(S[r] == 'o')) if l - C - 1 >= 0 and S[l] == 'o' : dpL[l] = max(dpL[l], dpL[l - C - 1] + 1) if r + C + 1 < N and S[r] == 'o' : dpR[r] = max(dpR[r], dpR[r + C + 1] + 1) h = [] for r in range(C + 1) : heappush(h, (-dpR[r], r)) for l in range(1, N) : r = l - 1 + C + 1 if r < N : cost = dpL[l - 1] + dpR[r] else : cost = dpL[l - 1] heappush(h, (-cost, r)) while h[0][1] <= l : heappop(h) if -h[0][0] < K and S[l] == 'o' : print(l)
1
40,469,735,438,500
null
182
182
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) n=int(input()) z=[] w=[] for i in range(n): x,y=nii() z.append(x-y) w.append(x+y) z_ans=max(z)-min(z) w_ans=max(w)-min(w) print(max(z_ans,w_ans))
import re print(re.sub(r"\?","D",input()))
0
null
10,949,854,570,112
80
140
data = list(map(int,input().split())) if(data[0] < data[1]): data[0],data[1] = data[1],data[0] def gcd(x,y): return x if y == 0 else gcd(y,x%y) print(gcd(data[0],data[1]))
from collections import deque l=deque() for _ in range(input()): a=raw_input().split() c=a[0][-4] if c=="i": l.popleft() elif c=="L": l.pop() elif c=="s": l.appendleft(a[1]) else: try: l.remove(a[1]) except: pass print " ".join(l)
0
null
29,920,259,260
11
20
from collections import Counter n = int(input()) a = list(map(int, input().split())) q = int(input()) C = Counter(a) ans = sum(a) for i in range(q): b, c = map(int, input().split()) ans += (c-b)*C[b] C[c] += C[b] C[b] = 0 print(ans)
n = int(input()) a = list(map(int, input().split())) q = int(input()) sums = sum(a) d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 for i in range(q): b,c = map(int, input().split()) if b in d: sums += d[b]*(c-b) if c in d: d[c] += d[b] else: d[c] = d[b] d[b] = 0 print(sums)
1
12,224,910,730,592
null
122
122
from sys import stdin,stdout def INPUT():return list(int(i) for i in stdin.readline().split()) import math def inp():return stdin.readline() def out(x):return stdout.write(x) import math as M MOD=10**9+7 import random ##################################### n=int(input()) A=INPUT() D=[0]*(n+1) for i in range(n): D[A[i]]=(i+1) print(*D[1:])
import collections N = int(input()) def pf(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a c = collections.Counter(pf(N)) ans = 0 for i in c.keys(): for j in range(1,40): if j*(j+1)/2 <= c[i] < (j+1)*(j+2)/2: ans += j print(ans)
0
null
99,290,939,031,290
299
136
S = input() h = S // 3600 m = S % 3600 //60 s = S % 3600 % 60 print str(h) + ':' + str(m) + ':' + str(s)
S=input() h=int(S)/3600 m=(int(S)%3600)/60 s=((int(S)%3600)%60)/1 print(int(h),':',int(m),':',int(s),sep='')
1
330,094,614,290
null
37
37
N = int(input()) for i in range(1,int(N**(1/2)) + 1)[::-1]: if N%i == 0: print(i + N//i - 2) exit()
import math n, m = map(int, input().split(" ")) if n == m: print("Yes") else: print("No")
0
null
122,952,189,893,918
288
231
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) answer = [] for i in range(M): x, y, c = map(int, input().split()) answer.append(a[x-1]+b[y-1]-c) print(min(min(answer), min(a)+min(b)))
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict from fractions import gcd import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): a,b,m = readInts() A = readInts() B = readInts() ans = float('inf') for i in range(m): x,y,c = readInts() x -=1 y -=1 ans = min(ans,A[x] + B[y] - c) # Aの商品の中で1番最小のやつを買うだけでもいいかもしれない # Bの商品の中で1番最小のやつを買うだけでもいいかもしれない ans = min(ans,min(A) + min(B)) print(ans) if __name__ == '__main__': main()
1
54,186,590,119,188
null
200
200
T1,T2 = list(map(int,input().split())) A1,A2 = list(map(int,input().split())) B1,B2 = list(map(int,input().split())) a1 = A1*T1 a2 = A2*T2 b1 = B1*T1 b2 = B2*T2 if a1+a2 < b1+b2: a1,b1 = b1,a1 a2,b2 = b2,a2 #print(a1,a2,b1,b2) if a1+a2 == b1+b2: print('infinity') else: if a1 > b1: print(0) else: c = (b1-a1)/((a1+a2)-(b1+b2)) print(int(c)*2 if c.is_integer() else int(c)*2+1)
s,t = map(int,input().split()) k,l = map(int,input().split()) m,n = map(int,input().split()) a = (k-m)*s b = (l-n)*t if a+b == 0: print("infinity") elif a>0 and a+b>0: print(0) elif a<0 and a+b<0: print(0) else: div = abs(a) // abs(a+b) if div == abs(a) / abs(a+b): print(div*2) else: print(div*2+1)
1
131,477,737,888,860
null
269
269
t = input() leng = len(t) print('x' * leng)
S=str(input()) print('x'*len(S))
1
73,059,850,961,600
null
221
221
# 最大の友達集団の人の数ぶんだけグループに分ける必要がある。 # union-findを使用する必要がある。 class UnionFind: # この時点でそれぞれのノードは自分を親としている # 初期化時に問題が0の頂点を認めるかに注意すること def __init__(self, n): self.N = n self.parent = [i for i in range(n)] self.rank = [0 for _ in range(n)] # xの根を返す関数 def root(self, x): visited_nodes = [] while True: p = self.parent[x] if p == x: # 縮約 for node in visited_nodes: self.parent[node] = x return x else: visited_nodes.append(x) x = p # 木の結合を行う。親の配下に入る def unite(self, x, y): if not self.root(x) == self.root(y): if self.rank[x] > self.rank[y]: self.parent[self.root(y)] = self.root(x) else: self.parent[self.root(x)] = self.root(y) if self.rank[x] == self.rank[y]: self.rank[self.root(y)] += 1 def ifSame(self, x, y): return self.root(x) == self.root(y) # 木の根に到達すまでにたどるノードの配列を返す def printDebugInfo(self): print([self.root(i) for i in range(self.N)]) N, M = map(int, input().split()) tree = UnionFind(N) for i in range(M): A, B = map(int, input().split()) tree.unite(A-1, B-1) bag = {} for i in range(N): boss = tree.root(i) if not boss in bag.keys(): bag[boss] = 1 else: bag[boss] += 1 print(max(bag.values()))
import sys sys.setrecursionlimit(1 << 25) readline = sys.stdin.buffer.readline read = sys.stdin.readline # 文字列読み込む時はこっち ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(readline()) def ints(): return list(map(int, readline().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, readline().split()))) return ret def read_matrix(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため class UnionFind: def __init__(self, N): self.N = N # ノード数 self.n_groups = N # グループ数 # 親ノードをしめす。負は自身が親ということ。 self.parent = [-1] * N # idxが各ノードに対応。 def root(self, A): # print(A) # ノード番号を受け取って一番上の親ノードの番号を帰す if (self.parent[A] < 0): return A self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き return self.parent[A] def size(self, A): # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。 return -self.parent[self.root(A)] def unite(self, A, B): # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。 # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。 A = self.root(A) B = self.root(B) # すでにくっついている場合 if (A == B): return False # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較 if (self.size(A) < self.size(B)): A, B = B, A # くっつける self.parent[A] += self.parent[B] # sizeの更新 self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる self.n_groups -= 1 return True def is_in_same(self, A, B): return self.root(A) == self.root(B) MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b N, M = ints() uf = UnionFind(N) for _ in range(M): a, b = mina(*ints()) uf.unite(a, b) # あとはなるべく別々になるように # →サイズを1ずつ引いて1グループ # いやmaxのsizeか print(-min(uf.parent))
1
3,977,053,148,900
null
84
84
N, K = map(int, input().split()) MOD = 10 ** 9 + 7 ans = 1 for i in range(K, N + 1): ans += i * (2 * N - i + 1) // 2 % MOD - i * (i - 1) // 2 % MOD + 1 ans %= MOD print(ans)
n, k = map(int, input().split()) su = 0 for i in range(k, n+2): co = (n+(n-i+1))*i/2 - (i-1)*i/2 + 1 su = (su + int(co)) % (10**9 + 7) print(su)
1
33,242,811,998,332
null
170
170
W, H, x, y, r = map(int, input().split()) flg = False for X in [x - r, x + r]: for Y in [y - r, y + r]: if not 0 <= X <= W or not 0 <= Y <= H: flg = True print(["Yes", "No"][flg])
n=int(input()) list={} list1=[] for i in range(n): a,b=map(str,input().split()) if a=="insert": list.setdefault(b,i) if a=="find": if b in list: list1.append("yes") else: list1.append("no") for i in list1: print(i)
0
null
253,888,753,700
41
23
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64) # Original source code : """ #include <stdio.h> int main() { int d, t, s; scanf("%d %d %d", &d, &t, &s); if (s * t >= d) { puts("Yes"); } else { puts("No"); } } """ import base64 import subprocess import zlib exe_bin = "c%1E7eQZ<L6~E6(hy#gZNC5M(VYSW_*2N?cAdIHu1t+{rNk}1KR0W<Ke<U7`o!QS_K;4FvGRdOuJZaKUyQ!5XO?2wC_K!_eleVCAU8hYNmA18Nsl=)>1y;0dtPx`(-nsAH^Zf4hdz4B0lcPB2o!>p@-0%C&J@1=+gZ(Z^B1l!_F+!!{3PbK;cyWWN0$3NRga4l)n+a8`w&;ocw#0L{S&w1Y<uYWEZzepKEWCy|(@Y)D3GthDw5=B!4D>>SpW~CP-f0(a=VEpjncYREk9?6eY*FZ6HT#V+e<BYNo>wzIa!rfU=T7EG<c|`bqut|Rw}RY1c^N;%>T?>GqpZEiaUQlM6XUx&w<V)($wVqQ(>Bw!t8G_jFq;l;*W2V}x(9~GbbUJCIJC69nPIfNe*TU;@}oZ<X?p7gY2C}GKUkNY`?19A%PaH#=&J;0j;D?ATVsQ7alrRE-~|W&s~q&d@1WlfzlUsa0^=H?!?=s6Y9gDC?AfDcBjHq>Oy{&LU|B63IjKe_Ppa{7A_+ibCalI2sc<rJItC)Or%D-3oeC#X<iOxS?|yZAaJTu?X+CWa?j-8K=#UzXWnvSFtQO0R4((5-Q?b$Tc#?XXm`bOZH`P$JRixyC`J^*ktv^d3(YeEQwmy+)pk<FUtXY?<$dgRYZA{cryBO2Q^@sbZSZnZC1$>0zZZD6c{BEPc>E5uerK=Xa+JY}waO*j<Xu)eO_-zaBw%~INr@Af+{+0!=vf!63xOE>Zvmd*ab2Z&7{X{uCr@2a(mDxAk^JaNz=Z!i)DYbkI{~NdTz!Q}xY0>qoC7_lMsZ6_m{jx5<M`hZi>vOvNPmtq9OMR_Mp}P(gqRP4ImR5@8LjhmMoKhGJG%JPCfLAGKf%=8l!1`P$(A@abP{6x46sZ6D!(e#@s#<soiooF9(*a*p+3~3ECD#NkZ=DB~pHY>=pz^o(7mfjo2OGCMqt_lUcHA7uzkNc<f2hoUv^X+4Sg835Xe)(=TeKmCZmM5e`#EUyzZ$oMbZ7vCF{Mx=16TIkR`S=h4KQSP+{TbK94}oh*KmBEj#62seWiAVoi5$Y)@86)E-hCn`9<Z@!ahZMQ+az?^MS)l%waus=;ZHA_v@fWa@&;I?(fm3G1{Jb<y`mkAT1P@OQi(`y6|SrcR-e?`59_=Yd)^`hpHdH9;c(C%kr1yBLn$&<S`k>qGhQ@?`j+6hvod;f&9|o)@%A2xpcQ`;SYC9CFSf*&EN4pwr4PZXE47M%Ku$1HD6I?=Oty&2e}(`4Lx~WJ|-WRPsr+gvE2S!^K8wrRVKmeZHfBzKk`H@ONP@#+Elf-i>=dVp-O7`d*H7CzXJRX;K!h&qrj8UlaDA4{0owC?o*OZA0pC>SK3rx>n=*QUW)7Qda!%Mvi|M$2??M+)Yn6~$J_7meW`KP*W72wzKwf7za#Jv+S7Ne5A>}2liD7GpBHeA0wGVk>)1+<TVAD?Q=6yhd_sHlGpX0({kE&u<9n{E&*Lvt_j+2Ntx-Jf-&&z~x@K#KJUtmtm+WbmJ*~YSKj?veug9&QZFD>?fFJ8Q@PHoB1A0LBOBnxPykor&QL1PBB^I=>aGo@?Ll3WS7*}m#GM<SW8OQi)vrzuYaw$#ud3K0lY*b`H48|-MS@}vP|D5qvjQbd0OL)Rq=mLv_@T^p@AB<z{wVv^#H9UU4ns4_U<9Hp!`aer}z5kSq{z(j4X7W+yuT(DAX_3kOto+|hw#Ib-Ps01ANPlMi|10B5_qrV4gD_q`uz&v-{jFo;xs;ak?+)$^wzuub=~BlxI=X`Gom&m`etgm!K$p!+kKPkTZSg9i+2Ymay5sR0bG`BS3UgiZc&#~KJnlB<naAtQ^~B>V&2`7)tIYk!<Mm|D7H{B#eG~T(uPxqa?q?qN62C3J+RPj9_!=^8i#M6)1CKYG=K_zfwOyB0WSzN>c^r1F*ADj)uPwfz0;Bt{n*5_A;%*1LiO{peL*|6>T+49oG6&Sk@DTxjOs~7#PCN&O^ykX)(U_m2;OC64UpdZB?SE0%UqiGyvBX~gC;I=UiuU|c_ft7vzhU}fd*0LkSFWF%x}VDVt&(W|1J*6m$8Fgp+2=pb>UiaP*e2QMQDlkc3D#GvlLlSCa$hJ8exeTeEb}k6r|8iB7Xe@GT5q14NUu=bvLEsI_yrrEm)Ls1Jjd&V*6Sla!B3v)V;&aoM8A^^eQ_M#!SQGM8pE$R^mmE1U-aX0+4py|%RXQAYu&%ixkr;v!3c?Dw5*nk$KkP@WKy*$HA1sTG@%tus}srecsQv>wR9${hI2C{lAfAQ#<W;8xO>;0E_)@K^h&7VOeTCvjit2ADH6|wr($X}H#Kz%Oe~TLni{97s{M!Lp+2>5I7Aa$yh4<yp(lprp@IE;iJk`o=)mxp+NUrNO6U+#4-6jcl?T;>{r!jgM%7Wdcd$>zTwElZ)0=wFOdCz^_4IIgxmYx;g)0(%Wu?x_WS`(cr5?;y^Qk;FnoX;d;Z&5S`34R`K{Sz4bJ<wb+HTr;kjJxG=0;B`@`=fErMsa7dWD1Pm@VXUmVBd0FnelB3y%ZWG6tW-r$h=oO_N|Mt;K?J??9Uto?y~MDi<8jC6dv$M3m^#WH>uXg3(hc@Mmx>W0X7<%VZPj6ep-qmWd_9RFOSRCpB6n3;=x$PNd;Mi_O4)eKv!cv_3(>*d$wOlhI6BGE9wyV_4ub)DWIZMBqU;hp{C=SnpG?Fm3kN|4KBjr|%{_f1SRoAc^_)hY6pv6u(>e1${9*>JaQPo<kn^6nmO?S%O#^?J@2<FSH+z8!?O-CdOR@?J+(?{w~8YAB^^RFE~Q@Zxt9vBFFm-k~n@Rh;dgydyF@c<5`UDcM1F?G438HV_b^7$D#d5rwL}@4Z`>p`J7O{*#BpkeJ|Eu!*jfkQE{D({d1)Jt&I}C7m(w<4N08;ykL)UGx8om-z)I%3ijp$<KlR^1^xrU9^a?PUBZ3C%ZucPf<4A1$i*;D?ElMz-@h0~Aa54*Mf=wTd#CS*PWHbN?D3v}+$}74aXfzuKZvT!_j&VsqP@O2{(pjBqs1QM*jMk<{x8HBd$ccquQg=+PP;;|!+AVUjQ)%HhzpH|eDqW5zaiM0@uZipN3=&;WEk3GeCGAq>x<{lCkzuW=xD#y!QRU4^3*-d-p2-xzGogGmHWTW(snByU1xAHA0W1WwS#?;Rj@4JqWymX{m5y7" open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod +x ./kyomu"], shell=True) subprocess.run(["./kyomu"], shell=True)
from collections import deque import sys input = sys.stdin.readline n = int(input()) a = [0]*n b = [0]*n for i in range(n): a[i], b[i] = map(int, input().split()) a.sort() b.sort() if n%2!=0 : l = a[int(n/2)] u = b[int(n/2)] ans = u - l + 1 else: l = a[int(n/2-1)] + a[int(n/2)] u = b[int(n/2-1)] + b[int(n/2)] ans = u - l +1 print(ans)
0
null
10,483,659,799,812
81
137
def solve(A, i, m, n): """Return if it is possible to make value m with some elements in A. n is length of A. i is index. R is the record of answer i, m. Using Divide-and-Conquer method. """ if R[i][m] != None: return R[i][m] if m == 0: R[i][m] = True return True elif i >= n: R[i][m] = False return False else: ans = solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n) R[i][m] = ans return ans import sys n = int(sys.stdin.readline()) A = tuple(map(int, sys.stdin.readline().split())) q = int(sys.stdin.readline()) M = tuple(map(int, sys.stdin.readline().split())) s_A = sum(A) R = [[None] * 2000 for i in range(n + 1)] ans = '' for m in M: if s_A < m: ans += 'no\n' elif solve(A, 0, m, n): ans += 'yes\n' else: ans += 'no\n' print(ans, end = '')
input() bits = 1 for a in map(int, input().split()): bits |= bits << a input() print(*("yes"*((bits >> q) & 1)or"no" for q in map(int, input().split())), sep='\n')
1
103,176,726,070
null
25
25
print(str(input())[:3])
import math s = input() print(s[:3])
1
14,834,313,624,032
null
130
130
def main(): n = int(input()) if n == 0: print("Yes") return slup = [] sldown = [] for i in range(n): height, mi = 0, 0 for si in input(): if si == "(": height += 1 else: height -= 1 mi = min(mi, height) if height >= 0: slup.append([mi, height]) else: sldown.append([mi-height, -height]) slup.sort(key = lambda x: -x[0]) sldown.sort(key = lambda x: -x[0]) if sum([si[1] for si in slup]) + sum([-si[1] for si in sldown]): print("No") return h = 0 for si in slup: if h+si[0] < 0: print("No") return h += si[1] h = 0 for si in sldown: if h+si[0] < 0: print("No") return h += si[1] print("Yes") if __name__ == "__main__": main()
n,k = map(int,input().split()) i = 0 while True : s = k **i if n < s : ans = i break i += 1 print(ans)
0
null
44,038,962,628,220
152
212
n = int(input()) X = [int(x) for x in input().split()] Y = [int(y) for y in input().split()] d1 = 0 d2 = 0 d3 = 0 Di = [] for i in range(n) : d1 += abs(X[i] - Y[i]) print(f"{d1:.6f}") for i in range(n) : d2 += abs(X[i] - Y[i]) ** 2 print(f"{(d2)**(1/2):.6f}") for i in range(n) : d3 += abs(X[i] - Y[i]) ** 3 print(f"{(d3)**(1/3):.6f}") for i in range(n) : Di.append(abs(X[i] - Y[i])) print(f"{max(Di):.6f}")
import math n=int(input()) x=[int(0) for i in range(n)] y=[int(0) for i in range(n)] x[:]=(int(a) for a in input().split()) y[:]=(int(a) for a in input().split()) p1=0 p2=0 p3=0 px=0 for i in range(n): p1+=abs(x[i]-y[i]) p2+=abs(x[i]-y[i])**2 p3+=abs(x[i]-y[i])**3 if px<abs(x[i]-y[i]): px=abs(x[i]-y[i]) p2=math.sqrt(p2) p3=p3**(1/3) print('{:.05f}'.format(p1)) print('{:.05f}'.format(p2)) print('{:.05f}'.format(p3)) print('{:.05f}'.format(px))
1
218,111,449,920
null
32
32
k=int(input()) a,b=map(int,input().split()) ans=False for i in range(a,b+1): if i%k==0: ans=True break print("NOGK"[ans::2])
n, m = map(int,input().split()) lst = [[0, 0] for i in range(n)] for i in range(m): p, s = map(str,input().split()) p = int(p) - 1 if (lst[p][0] == 0): if (s == "AC"): lst[p][0] = 1 else: lst[p][1] = lst[p][1] + 1 ans = 0 pena = 0 for i in range(n): if (lst[i][0] == 1): ans = ans + 1 pena = pena + lst[i][1] print(ans, pena)
0
null
59,860,975,180,578
158
240
''' Online Python Compiler. Code, Compile, Run and Debug python program online. Write your code in this editor and press "Run" button to execute it. ''' ip=list(input()) sum=0 for i in ip: sum+=int(i) if sum%9==0: print('Yes') else: print('No')
n, k = map(int, input().split()) l = list(map(int, input().split())) cnt = 0; for i in l: if i >= k: cnt += 1; print(cnt)
0
null
91,884,624,499,552
87
298
N = int(input()) A = map(int, input().split()) curr = 0 ans = 0 for a in A: if curr > a: ans += curr - a else: curr = a print(ans)
n = int(input()) a_int = list(map(int, input().split())) height = 0 base = 0 for j in range(0, n - 1): if a_int[j] + base > a_int[j + 1] + base: base = a_int[j] - a_int[j + 1] height += base a_int[j + 1] += base base = 0 print(height)
1
4,601,004,436,138
null
88
88
import random import time import copy start = time.time() D = int(input()) s = [[0 for j in range(26)] for i in range(D)] c = list(map(int, input().split(" "))) result = [] total = -10000000 for i in range(D): a = list(map(int, input().split(" "))) for j, k in enumerate(a): s[i][j] = int(k) #while(1): for t in range(26): result_tmp = [] total_tmp = 0 last = [0 for i in range(26)] for i in range(D): score = [0 for i in range(26)] score_tmp = [0 for i in range(26)] for j in range(26): score[j] = s[i][j] score_tmp[j] = s[i][j] for k in range(26): if j != k: score_tmp[j] -= (i + 1 + t - last[k]) * c[k] score[j] -= (i + 1 - last[k]) * c[k] score_sort = sorted(score_tmp, reverse=True) score_max = score_sort[0] tmp = [] for j in range(26): if score_max == score_tmp[j]: score_max = j result_tmp.append(score_max) last[score_max] = i + 1 total_tmp += score[score_max] if total < total_tmp: total = total_tmp result = result_tmp.copy() end = time.time() if end - start > 1.8: break for i in range(D): print(result[i]+1)
import time import copy start_time = time.time() #input D = int(input()) c_list = list(map(int, input().split())) s_grid = [] for i in range(D): array = list(map(int, input().strip().split(' '))) s_grid.append(array) def calculate_score(d,t,last): score = s_grid[d][t] last[t] = -1 for i in range(26): score -= c_list[i]*(last[i]+1) return score t_list = [] #task_list last_list = [0 for _ in range(26)] total_score = 0 for k in range(0,D): X = -1 # k-日目に変える番号を探す p = 0 last = copy.deepcopy(last_list) for i in range(26): # 26通り試す tmp = calculate_score(k,i,last) if tmp > p: X = i p = tmp #最大のXを投入 total_score += p t_list.append(X) last_list = [i+1 for i in last_list] last_list[X] = 0 #if time.time() - start_time > 1.9: # break for j in range(len(t_list)): print(int(t_list[j]) + 1)
1
9,680,286,570,318
null
113
113
r = int(input()) print(r * 3.1416 * 2)
from math import pi def main(): S = int(input()) print(2 * pi * S) if __name__ == "__main__": main()
1
31,250,060,050,000
null
167
167
A = int (input ()) B = int (input ()) N = int (input ()) if A < B: X = N//B if N%B == 0: print (X) else: print (X+1) else: X = N//A if N%A == 0: print (X) else: print (X+1)
n = int(input()) N = int(n/1.08) for i in range(3): if int((N + i) * 1.08) == n: print(N+i) break else: print(':(')
0
null
107,322,093,353,892
236
265
s,w=list(map(int, input().split())) a='' if s<=w: a='un' print(a+'safe')
import numpy as np N = int(input()) A = [] B = [] for i in range(N): a, b = [int(x) for x in input().split()] A.append(a) B.append(b) C = np.array(A) D = np.array(B) m_inf = np.median(C) m_sup = np.median(D) if N % 2 == 0: ans = 2 * m_sup - 2 * m_inf + 1 else: ans = m_sup - m_inf + 1 print(int(ans))
0
null
23,226,478,986,308
163
137
Ss = input().rstrip() print('x' * len(Ss))
t=int(input()) taro=0 hanako=0 for i in range(t): S=input().split() if S[0]==S[1]: taro+=1 hanako+=1 elif S[0]>S[1]: taro+=3 else: hanako+=3 print(taro,hanako)
0
null
37,579,406,993,440
221
67
import math h,w = map(int,input().split()) if w < h: h,w = w,h if h==1: print(1) else: ans = math.ceil((h*w)/2) print(max(1,ans))
from collections import defaultdict n, k = map(int, input().split()) m = defaultdict(int) for _ in range(k): input() for x in input().split(): m[int(x)] += 1 result = 0 for i in range(1, n+1): if m[i] == 0: result += 1 print(result)
0
null
37,862,729,241,410
196
154
def main(): N = int(input()) S = str(input()) ans = 0 for i in range(N - 2): if S[i] == 'A' and S[i + 1] == 'B' and S[i + 2] == 'C': ans += 1 print(ans) main()
def isok(t): cnt = 0 for i in range(n): cnt += max(a[i] - t // f[i], 0) if cnt > k: return False return True n,k = map(int,input().split()) a = list(map(int,input().split())) f = list(map(int,input().split())) a.sort(reverse = 1) f.sort() ok = a[0] * f[-1] ng = -1 bool = True while abs(ok - ng) > 1: mid = (ok + ng) // 2 if isok(mid): ok = mid else: ng = mid #print(ng,mid,ok) print(ok)
0
null
132,002,924,980,222
245
290
count = int(raw_input()) S = [] H = [] C = [] D = [] while count: arr = map(str, raw_input().split(" ")) if arr[0] == "S": S.append(int(arr[1])) elif arr[0] == "H": H.append(int(arr[1])) elif arr[0] == "C": C.append(int(arr[1])) else: D.append(int(arr[1])) count -= 1 S.sort() H.sort() C.sort() D.sort() ans_s = [] ans_h = [] ans_c = [] ans_d = [] for x in range(1, 14): if not x in S: ans_s.append(x) if not x in H: ans_h.append(x) if not x in C: ans_c.append(x) if not x in D: ans_d.append(x) def answer(arr, value): for x in arr: print "%s %s" % (value, str(x)) answer(ans_s, 'S') answer(ans_h, 'H') answer(ans_c, 'C') answer(ans_d, 'D')
def is_prime(x): if x == 2: return True if x < 2 or x % 2 == 0: return False i = 3 while i * i <= x: if x % i == 0: return False i += 2 return True n = int(raw_input()) ans = 0 for i in range(n): x = int(raw_input()) if (is_prime(x)): ans += 1 print ans
0
null
514,615,495,020
54
12
# dp[i][j]:=(総和がiで長さがjの数列の個数)とする # このままだとO(s^3)だが、全てのjに対してΣ(k=0→i-3)dp[k][j]をあらかじめ持っておけばO(s^2)となる # dpの遷移式立てたときはちゃんと紙に書いて眺めなきゃ(使命感) s=int(input()) mod=10**9+7 dp=[[0]*(s+1) for _ in range(s+1)] accum=[0]*(s+1) dp[0][0]=1 for i in range(3,s+1): for j in range(s): accum[j]+=dp[i-3][j] dp[i][j+1]+=accum[j] dp[i][j+1]%=mod print(sum(dp[s])%mod)
#!/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(): N = II() A = LI() for a in A: if a % 2 == 0: if a % 3 != 0 and a % 5 != 0: print("DENIED") exit() print("APPROVED") main()
0
null
36,290,620,116,100
79
217
N, M = map(int, input().split()) A = list(map(int, input().split())) D = sum(A) cnt = 0 for i in range(N): if A[i] * 4 * M >= D: cnt += 1 if cnt >= M: print('Yes') else: print('No')
from decimal import Decimal n,m = map(int, input().split()) A = list(map(int, input().split())) line = Decimal(sum(A) / (4 * m)) cnt = 0 for a in A: if a >= line: cnt += 1 if cnt >= m: print('Yes') break else: print('No')
1
38,696,258,231,360
null
179
179
import math import numpy as np import numba from numba import njit, b1, i4, i8, f8 from numba import jit import collections import bisect from collections import deque from copy import copy, deepcopy import time def main(): N,X,T = map(int,input().split()) print(math.ceil(N/X) * T) if __name__ == '__main__': main()
n = int(input()) c = input() left, right = 0, n - 1 cnt = 0 while left <= right: while left < n and c[left] == 'R': left += 1 while right > -1 and c[right] == 'W': right -= 1 if left == n or right == -1 or left >= right: break left += 1 right -= 1 cnt += 1 print(cnt)
0
null
5,331,857,933,014
86
98
l = input().split() print(l[2], l[0], l[1])
import itertools import numpy as np def distance(x2,x1,y2,y1): return ((x2-x1)**2 + (y2-y1)**2)**0.5 N = int(input()) X = [] Y = [] for _ in range(N): x, y = map(int, input().split()) X.append(x) Y.append(y) routes = list(itertools.permutations(range(N), N)) ans = [] for route in routes: dist = 0 for i in range(1, N): dist += distance(X[route[i]], X[route[i-1]], Y[route[i]], Y[route[i-1]]) ans.append(dist) print(np.mean(ans))
0
null
93,085,121,854,790
178
280
import math def div(x, y): #x>y A = 1 for i in range(1, int(math.sqrt(x))+1): if x % i == 0 and y % i == 0: A = max(A, i) j = int(x/i) if x % j == 0 and y % j == 0: A = max(A, j) return A x, y = map(int, input().split(" ")) print(div(x,y))
from math import * print(gcd(*map(int, input().split())))
1
7,693,458,620
null
11
11
import math h,w,k = map(int,input().split()) s = [str(input()) for i in range(h)] ans = h * w if h == 1: print(math.ceil("1".count(s[0])/k)) exit() for i in range(2 ** (h-1)): ss = str(format(i,"b").zfill(h-1)) cnt = 0 zero = 0 key = 1 for j in range(len(ss)): if ss[j] == "0": zero += 1 now = [0 for i in range(zero+1)] for j in range(w): next = [] num = 0 for n in range(h): if s[n][j] == "1": num += 1 if num > k: key = 0 if n < h-1 and ss[n] == "0": next.append(num) num = 0 next.append(num) keykey = 1 for n in range(zero+1): if keykey: if now[n] + next[n] > k: now = next cnt += 1 keykey = 0 else: now[n] += next[n] if key:ans = min(ans,cnt+zero) print(ans)
#E H,W,K = map(int,input().split()) S = [list(str(input())) for _ in range(H)] inf = float("inf") ans = inf T = 2**(H-1) for i in range(T): b = bin(i) b = b.lstrip("0b") blist = list(b) lb = len(b) clist = blist[::-1] while lb < H-1: clist.append("0") lb+=1 r = clist.count("1") count = r nw = [0]*(r+1) for w in range(W): nind = 0 for h in range(H): if h > 0: if clist[h-1] == "1": nind+=1 if S[h][w] == "1": nw[nind]+=1 if w == 0: pass else: for k in nw: if k > K: count+=1 nw = [0]*(r+1) nind = 0 for h in range(H): if h > 0: if clist[h-1] == "1": nind+=1 if S[h][w] == "1": nw[nind]+=1 if max(nw) > K: count = inf break ans = min(ans,count) print(ans)
1
48,473,667,130,320
null
193
193
from sys import stdin,stdout def INPUT():return list(int(i) for i in stdin.readline().split()) def inp():return stdin.readline() def out(x):return stdout.write(x) import math import random J=998244353 ######################################################## n,k=INPUT() A=[] for i in range(k): x,y=INPUT() A.append([x,y]) A.sort() s,e=-1,-1 S=[] for i in range(len(A)): if i==0: S.append([A[i][0],A[i][1]]) else: if A[i][0]>S[-1][1]: S.append([A[i][0],A[i][1]]) else: S[-1][1]=A[i][1] cum=[0]*(n+1) dp=[0]*(n+1) dp[1]=1 cum[1]=1 for i in range(2,n+1): for ele in S: x=ele[0] y=ele[1] dp[i]=(dp[i]+cum[max(i-x,0)]-cum[max(0,i-y-1)])%J cum[i]=(cum[i-1]+dp[i])%J print(dp[n])
n, k = [int(_) for _ in input().split()] s = [] for i in range(k): s.append([int(_) for _ in input().split()]) dp = [0 for i in range(n)] dp[0] = 1 dp_s = [0 for i in range(n+1)] dp_s[1] = 1 for i in range(1, n): for j in range(len(s)): r, l = s[j] if i-r >= 0: if i-l >= 0: dp[i] += dp_s[i-r+1] - dp_s[i-l] else: dp[i] += dp_s[i-r+1] - dp_s[0] dp[i] = dp[i] % 998244353 dp_s[i+1] += dp_s[i] + dp[i] dp_s[i+1] = dp_s[i+1] % 998244353 print(dp[-1])
1
2,689,323,916,850
null
74
74
import sys input = sys.stdin.readline import collections # 持っているビスケットを叩き、1枚増やす # ビスケット A枚を 1円に交換する # 1円をビスケット B枚に交換する def main(): x = int(input()) for a in range(-200, 200): for b in range(-200, 200): ans = a ** 5 - b ** 5 if ans == x: print(a, b) exit() def bi(num, a, b, x): print((a * num) + (b * len(str(b)))) if (a * num) + (b * len(str(b))) <= x: return False return True def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
X = int(input()) quint = [0] * 1001 for i in range(1, 1001): quint[i] = i ** 5 for i in range(0, 1001): a = X - quint[i] b = X + quint[i] try: c = quint.index(a) print("{} {}".format(c, -i)) break except: try: c = quint.index(b) print("{} {}".format(c, i)) break except: continue
1
25,488,272,817,852
null
156
156
#coding:utf-8 #1_4_C 2015.3.29 while True: data = input() if '?' in data: break print(eval(data.replace('/','//')))
while True: a, op, b = map(str, raw_input().split()) if op in "+": print int(a)+int(b) elif op in "-": print int(a)-int(b) elif op in "*": print int(a)*int(b) elif op in "/": print int(a)/int(b) else : break;
1
680,868,378,960
null
47
47
while 1: H, W = map(int, input().split()) if H == 0 and W == 0: break else: for i in range(H): print("#" * W) print()
while True: L = map(int,raw_input().split()) H = (L[0]) W = (L[1]) if H == 0 and W == 0:break for x in range(0,H):print "#" * W print ""
1
768,363,207,458
null
49
49
S = input() hi = [] for i in range(5): hi.append("hi"*(i+1)) print("Yes" if S in hi else "No")
S = input() flg = True for i in range(len(S)): if flg == True and S[i] == "h": flg = False continue elif flg == False and S[i] == "i": flg = True continue else: print("No") break else: if flg == False: print("No") else: print("Yes")
1
53,309,078,102,726
null
199
199
s=int(raw_input()) print str(s//3600)+':'+str(s//60%60)+':'+str(s%60)
from math import * PI = 3.1415926535898 while True: try: t = input() ans = "" ans += str(t/(60*60)) t %= 60*60 ans += ":" ans += str(t/60) t %= 60 ans += ":" ans += str(t) print ans except EOFError: break
1
329,487,417,722
null
37
37
n=input().split() x=int(n[0]) y=int(n[1]) if 1<=x<1000000000 and 1<=y<=1000000000: if x>y: while y!=0: t=y y=x%t x=t print(x) else: while x!=0: t=x x=y%t y=t print(y)
def resolve(): X = list(map(int, input().split())) print(X.index(0)+1) if '__main__' == __name__: resolve()
0
null
6,758,688,884,388
11
126
t1,t2=map(int,input().split()) a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) if a1>b1 and a2>b2: print(0) elif b1>a1 and b2>a2: print(0) elif a1*t1+a2*t2==b1*t1+b2*t2: print("infinity") else: ans=-1 num2=-1 num3=-1 if a1*t1+a2*t2>b1*t1+b2*t2: if a1>b1: ans=0 else: num2=(b1-a1)*t1 num3=((a1-b1)*t1)+((a2-b2)*t2) if num2//num3==num2/num3: ans=(num2//num3)*2 else: ans=(num2//num3)*2+1 else: if b1>a1: ans=0 else: num2=(a1-b1)*t1 num3=((b1-a1)*t1)+((b2-a2)*t2) if num2//num3==num2/num3: ans=(num2//num3)*2 else: ans=(num2//num3)*2+1 print(ans)
t1, t2 = map(int, input().split()) a1, a2 = map(int, input().split()) b1, b2 = map(int, input().split()) c1 = t1*(a1-b1) c2 = t2*(a2-b2) d = c1 + c2 if d == 0: print("infinity") elif c1*c2 > 0 or c1*d > 0: print(0) else: if abs(c1)%abs(d)==0: print((abs(c1)//abs(d))*2) else: print((abs(c1)//abs(d))*2+1)
1
130,955,256,425,852
null
269
269
from math import ceil debt=100000 bigets=1000 interest_rate=1.05 def calc_debt(n): d=debt//bigets while n>0: d=ceil(d*interest_rate) n -= 1 return d*bigets n=int(input()) print(calc_debt(n))
import sys input = sys.stdin.readline def check(s): h = 0 for p in s: b = h + p[0] if b < 0: return False h += p[1] return True N = int(input()) S = [input().strip() for i in range(N)] total = 0 ps, ms = [], [] for s in S: h, b = 0, 0 for c in s: if c == '(': h += 1 else: h -= 1 b = min(b, h) if h > 0: ps.append([b, h]) else: ms.append([b-h, -h]) total += h ps.sort(reverse=True) ms.sort(reverse=True) if check(ps) and check(ms) and total == 0: print('Yes') else: print('No')
0
null
11,879,347,320,928
6
152
N,D = map(int,input().split()) ans = 0 for i in range(N): X1,Y1 = map(int,input().split()) if X1*X1+Y1*Y1 <= D*D: ans += 1 print(ans)
a,b,c=map(int,input().split(" ")) print((a//b+(a%b>0))*c)
0
null
5,125,485,895,570
96
86
from collections import Counter n = int(input()) A = list(map(int, input().split())) ANS = sum(A) A = Counter(A) Q = int(input()) for i in range(Q): B, C = map(int, input().split()) print(ANS + (C - B) * A[B]) ANS += (C - B) * A[B] A[C] = A[C] + A[B] A[B] = 0
class Dice: __x = 1 __y = 0 def __init__(self,dice): self.dice = dice def output(self): print(self.dice[0]) def move(self,str): if str == 'N': temp = self.dice[0] self.dice[0] = self.dice[1] self.dice[1] = self.dice[5] self.dice[5] = self.dice[4] self.dice[4] = temp elif str == 'S': temp = self.dice[0] self.dice[0] = self.dice[4] self.dice[4] = self.dice[5] self.dice[5] = self.dice[1] self.dice[1] = temp elif str == 'E': temp = self.dice[0] self.dice[0] = self.dice[3] self.dice[3] = self.dice[5] self.dice[5] = self.dice[2] self.dice[2] = temp elif str == 'W': temp = self.dice[0] self.dice[0] = self.dice[2] self.dice[2] = self.dice[5] self.dice[5] = self.dice[3] self.dice[3] = temp di = list(map(int,input().split())) m = list(input()) di = Dice(di) for i in m: di.move(i) di.output()
0
null
6,165,547,795,540
122
33
import math import numpy as np N,M=map(int,input().split()) A=list(map(int,input().split())) c=1 test=A[0] l=0 while test%2 == 0: test=test//2 c*=2 def lcm_base(x, y): return (x * y) // math.gcd(x, y) for i in np.arange(N-1): if A[i+1]%c!=0: print(0) l=1 break elif A[i+1]%(c*2)==0: print(0) l=1 break else: k=A[i+1]//c test=lcm_base(test, k) if l==0: k=test*c//2 print(M//k//2 + M//k%2)
N = int(input()) for i in range(1,11): need = 1000 * i if N <= need: print(need - N) break
0
null
55,136,257,946,958
247
108
class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): # ノードxのrootノードを見つける if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def unite(self, x, y): # 木の併合、入力は併合したい各ノード⇒(a,b) x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): # ノードxが属する木のサイズを返す return -self.parents[self.find(x)] def same(self, x, y): # 入力ノード(x,y)が同じグループに属するかを返す return self.find(x) == self.find(y) def members(self, x): #ノードxが属するメンバーをリスト形式で返す root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): #親全てをリスト形式で返す return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): #グループ数の合計を返す return len(self.roots()) import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline n,m=map(int,input().split()) u=UnionFind(n) for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 u.unite(a,b) ans=u.roots() print(len(ans)-1)
import sys sys.setrecursionlimit(10**9) input = sys.stdin.buffer.readline N, M = map(int, input().split()) nextcity = [[] for _ in range(N)] sgn = [0 for _ in range(N)] while M: M -= 1 A, B = map(int, input().split()) A -= 1 B -= 1 nextcity[A].append(B) nextcity[B].append(A) def bfs(cnt, lis): nextvisit = [] for j in lis: for item in nextcity[j]: if sgn[item] == 0: nextvisit.append(item) sgn[item] = cnt if nextvisit: bfs(cnt, nextvisit) return None else: return None cnt = 0 for k in range(N): if sgn[k] == 0: cnt += 1 sgn[k] = cnt bfs(cnt, [k]) print(cnt -1)
1
2,286,016,909,682
null
70
70
from math import * n=int(input()) a=[] for i in range(n): s=input() a.append(s) s=set(a) print(len(s))
N ,*S = open(0).read().split() s = list(set(S)) print(len(s))
1
30,279,763,199,750
null
165
165
#!python3 import sys iim = lambda: map(int, sys.stdin.readline().rstrip().split()) from functools import lru_cache @lru_cache(maxsize=2*10**5) def f2(x): if x == 0: return 0 y = bin(x).count("1") return 1 + f2(x % y) def resolve(): N = int(input()) S = input() cnt0 = S.count("1") if cnt0 == 0: print(*[1]*N, sep="\n") return X = int(S, 2) dc = {} for k, v in (("0", 1), ("1", -1)): x = cnt0 + v y = X % x if x else 0 dc[k] = (x, v, y, [1, N-1]) ans = [0] * N for i in reversed(range(N)): si = S[i] cnt, v, n, m1 = dc[si] if cnt == 0: ans[i] = 0 continue ni = N - i - 1 m2 = (m1[0]<<(m1[1]-i)) % cnt n = (n + v*m2) % cnt m1[0] = m2; m1[1] = i ans[i] = 1 + f2(n) print(*ans, sep="\n") if __name__ == "__main__": resolve()
n = int(input()) x = input() def popcount(ni): n_b = str(bin(ni)) return n_b.count("1") def ans(n,x): x_i = int(x, 2) x_orig = popcount(x_i) x_i_t = x_i % (x_orig+1) if x_orig != 1: x_i_b = x_i % (x_orig-1) else: x_i_b = x_i solve = 0 for i in range(n): x_count = x_orig if x[i] == "0": x_count += 1 solve = x_i_t + pow(2,n-1-i,x_count) else: x_count -= 1 if x_count != 0: solve = x_i_b - pow(2,n-1-i,x_count) else: print(0) continue count = 0 if x_count != 0 : solve = solve % x_count count+=1 while solve > 0: solve = solve % popcount(solve) count+=1 print(count) ans(n,x)
1
8,262,964,207,328
null
107
107
N = int(input()) S = input() abc = S.count('R')*S.count('G')*S.count('B') L = (N-1)//2 for i in range(1,L+1): for j in range(N-2*i): if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]: abc -= 1 print(abc)
from itertools import permutations n = int(input()) s = input() out = 0 ans = s.count("R")*s.count("G")*s.count("B") combi = list(permutations(["R","G","B"],3)) for i in range(1,n): for j in range(n-i*2): if (s[j], s[j+i], s[j+i*2]) in combi: ans -= 1 print(ans)
1
36,097,632,686,918
null
175
175
N = int(input()) A = list(map(int, input().split())) num_list = [0] * 100 P = 10 ** 9 + 7 for i in A: tmp = i for j in range(len(bin(i)) - 2): num_list[j] += (tmp & 1) tmp = tmp >> 1 ans = 0 def func(N, n): return (N - n) * n for i in range(100): ans = (ans + func(N, num_list[i]) * 2 ** i) % P print(ans)
import sys a=[map(int,i.split()) for i in sys.stdin] [print(len(str(b+c))) for b,c in a]
0
null
61,751,713,074,562
263
3
n=int(input()) A=[] for i in range(n): for _ in range(int(input())): x,y=map(int,input().split()) A+=[(i,x-1,y)] a=0 for i in range(2**n): if all(i>>j&1<1 or i>>x&1==y for j,x,y in A): a=max(a,sum(map(int,bin(i)[2:]))) print(a)
def gcd(x, y): while y != 0: x,y = y, x % y return x A = list(map(int,input().split())) print(gcd(A[0], A[1]))
0
null
60,526,165,114,828
262
11
n=int(input()) arr=list(map(int,input().split())) if n<=3: print(max(arr)) exit() lim=n%2+2 dp=[[0]*lim for _ in range(n+1)] for i in range(n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) if lim==3: dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i]) print(max(dp[-1][:lim]))
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K, *H = map(int, read().split()) H.sort(reverse=True) print(sum(H[K:])) return if __name__ == '__main__': main()
0
null
58,290,956,145,358
177
227
N = int(input()) d = list(map(int,input().split())) amount = 0 b = [0] * N for i in range(N): b[i] = amount amount += d[N-1-i] ans = 0 for i in range(N): ans += d[i]*b[N-1-i] print(ans)
N = int(input()) d = list(map(int,input().split())) sum = 0 for i in range(0,len(d)): for j in range(0,len(d)): if(i != j): sum += d[i] * d[j] print(int(sum/2))
1
168,303,128,988,710
null
292
292
n = int(input()) # cs = ['W' for i in range(200000)] cs = input() w_count = 0 for c in cs: if c == 'W': w_count += 1 if w_count == 0: print(0) exit() rest = cs[-w_count:] answer = 0 for c in rest: if c == 'R': answer += 1 print(answer)
import math w = 0 k = int(input()) for i in range(1, k+1): for j in range(1, k+1): m = math.gcd(i, j) for l in range(1, k+1): w += math.gcd(m, l) print(w)
0
null
20,965,751,984,450
98
174
def down(d, last, c): result = 0 for i in range(26): result += c[i] * (d - last[i]) return result def main(): D = int(input()) C = [int(c) for c in input().split()] S = [0] * D for d in range(D): S[d] = [int(s) for s in input().split()] last = [0] * 26 score = 0 scores = [0] * D for d in range(D): t = int(input()) - 1 score += S[d][t] last[t] = d + 1 score -= down(d + 1, last, C) scores[d] = score for score in scores: print(score) if __name__ == "__main__": main()
S = input() L = S.split() a = L[0] b = L[1] c = L[2] a = int(a) b = int(b) c = int(c) if a < b < c: print('Yes') else : print('No')
0
null
5,195,963,562,588
114
39
from sys import stdin import math inp = lambda : stdin.readline().strip() n = int(inp()) a = [int(x) for x in inp().split()] ans = 0 for i in range(1, n): if a[i] < a[i-1]: ans += a[i-1] - a[i] a[i] += a[i-1] - a[i] print(ans)
n = int(input()) a = list(map(int, input().split())) maxa = 0 ans = 0 for i in range(n): if maxa > a[i]: ans += maxa - a[i] else: maxa = a[i] print(ans)
1
4,549,529,222,116
null
88
88
from collections import defaultdict MOD = 998244353 N,S = map(int,input().split()) A = map(int,input().split()) dp = [0]*(S+1) dp[0] = 1 for a in A: ndp = [0]*(S+1) for total,cnt in enumerate(dp): ndp[total] += dp[total]*2 ndp[total] %= MOD if total+a <= S: ndp[total+a] += dp[total] ndp[total+a] %= MOD dp = ndp print(dp[-1]%MOD)
N, S = map(int, input().split()) MOD = 998244353 A = list(map(int, input().split())) dp = [[0]*(S+1) for i in range(N+1)] dp[0][0] = 1 for i, a in enumerate(A, 1): for s in range(S+1): dp[i][s] = 2*dp[i-1][s] if a <= s: dp[i][s] += dp[i-1][s-a] dp[i][s] %= MOD print(dp[-1][-1])
1
17,729,540,040,368
null
138
138
N,K = map(int, input().split()) A = [0] + list(map(int, input().split())) for i in range(K+1, N+1): if A[i-K] >= A[i]: print('No') else: print('Yes')
# coding: utf-8 import itertools from functools import reduce from collections import deque N, K = list(map(int, input().split(" "))) A = list(map(int, input().split(" "))) for i in range(N): if i > K-1: if A[i] > A[i-K]: print("Yes") else: print("No")
1
7,025,698,354,682
null
102
102
taro_p = 0 hana_p = 0 for i in range(input()): taro,hana = raw_input().split(' ') if taro > hana: taro_p = taro_p + 3 hana_p = hana_p + 0 elif taro < hana: taro_p = taro_p + 0 hana_p = hana_p + 3 else: taro_p = taro_p + 1 hana_p = hana_p + 1 print taro_p,hana_p
from math import sqrt #def area######################################## def Manhattan(x,y): D=0.0 for i in range(n): D+=abs(x[i]-y[i]) return D def Euclid(x,y): D=0.0 for i in range(n): D+=(x[i]-y[i])**2 D=sqrt(D) return D def Noname(x,y): D=0.0 for i in range(n): D+=abs((x[i]-y[i])**3) D**=1.0/3 return D def Infinity(x,y): L=list() for i in range(n): L.append(abs(x[i]-y[i])) return max(L) ################################################# n=int(input()) x=map(float,raw_input().split(" ")) y=map(float,raw_input().split(" ")) print Manhattan(x,y) print Euclid(x,y) print Noname(x,y) print Infinity(x,y)
0
null
1,096,165,250,660
67
32