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
ans = '' r, c = map(int, input().split(' ')) i = 0 L = [0] * (c + 1) while i < r: a = list(map(int, input().split(' '))) atot = 0 j = 0 while j < c: atot += a[j] L[j] += a[j] j += 1 ans += ' '.join(map(str, a)) + ' ' + str(atot) + '\n' L[c] += atot i += 1 if ans != ''...
r,c = map(int,input().split()) a = [list(map(int,input().split(" "))) for i in range(r)] for i in range(r): r_total = sum(a[i]) a[i].append(r_total) c_total = [] for j in range(c+1): s = 0 for k in range(r): s += a[k][j] c_total.append(s) a.append(c_total) for z in range(r+1): for ...
1
1,355,296,579,648
null
59
59
r=int(input()) print(2*3.14*r)
R=int(input()) print((R*2)*3.14)
1
31,216,363,562,020
null
167
167
import math r = int(input()) R = 2*math.pi*r print(R)
m1, d1 = map(int, input().split()) m2, d2 = map(int, input().split()) end = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] if d1 == end[m1-1]: print(1) else: print(0)
0
null
77,993,646,042,960
167
264
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)
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n, m, *a = map(int, read().split()) suma = sum(a) if n < suma: print(-1) else: print(n - suma) if __name__ == '__main__': main()
1
31,834,895,207,310
null
168
168
input() P=map(int,input().split()) ans,mn=0,2*10**5 for x in P: if mn>=x: ans+=1; mn=x print(ans)
N = int(input()) P = list(map(int, input().split())) mi = 202020 ans = 0 for p in P: if p < mi: ans += 1 mi = p print(ans)
1
85,441,724,057,228
null
233
233
S=input() ans=0 if 'R' in S: ans+=1 for i in range(2): if S[i]==S[i+1]=='R': ans+=1 print(ans)
s = input() ans = 0 strek = 0 for i in range(3): if s[i] == 'R': tmp = "R" strek += 1 ans = max(strek, ans) else: strek = 0 print(ans)
1
4,899,000,489,280
null
90
90
from collections import deque def dfs(q): if len(q)==N: print(''.join(q)) return for i in range(min(26, ord(max(q))-ord('a')+2)): q.append(alpha[i]) dfs(q) q.pop() N = int(input()) alpha = 'abcdefghijklmnopqrstuvwxyz' dfs(deque(['a']))
N = int(input()) s = "a" ans = [] def dfs(s,n): if len(s) == n: ans.append(s) return last = 0 for i in range(len(s)): last = max(last,ord(s[i])) limit = chr(last+1) for i in range(26): temp = chr(97+i) if temp <= limit: dfs(s+temp,n) dfs(s,N) print(*ans,sep="\n")
1
52,073,989,355,612
null
198
198
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x-1, MII())) ## dp ## def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)] def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in...
def main(): N, M = map(int, input().split()) if N == M: print("Yes") exit(0) print("No") if __name__ == "__main__": main()
0
null
86,570,895,458,500
237
231
n,k,s = map(int,input().split()) if s == 10**9: t = 1 else: t = s+1 ls = [t]*n for i in range(k): ls[i] = s print(*ls)
n,k,s = map(int,input().split()) if s == 10**9: ans = [1]*n for i in range(k): ans [i] = s else: ans = [s+1]*n for i in range(k): ans[i] = s for i in ans: print(i,end = " ")
1
90,773,326,866,002
null
238
238
danmen = input() down = [] edge = [] pool = [] for (i, line) in enumerate(danmen): if line == "\\": down.append(i) elif down and line == "/": left = down.pop() area = i - left while edge: if edge[-1] > left: edge.pop() area += pool.p...
N=int(input()) x=input() num=0 n=0 def twice(a): ans=0 while a: ans+=a%2 a//=2 return ans ma=5*10**5 dp=[0]*ma for i in range(1,ma): dp[i]=dp[i%twice(i)]+1 c=x.count("1") a=int(x,2)%(c+1) if c==1: for i in range(N): if x[i]=="0": print(dp[(a+pow(2,N-i-1,2))%2]+1)...
0
null
4,189,993,019,672
21
107
def north(d): d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0] def west(d): d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0] def east(d): d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0] def south(d): d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0] F = {'N': north, 'W': west, 'E': east, 'S': south}...
S = input() s = S[::-1] cnt = [0]*2019 cnt[0] = 1 number = 0 d = 1 for i in s: number += int(i)*d cnt[number % 2019] += 1 d *= 10 d = d % 2019 ans = 0 for i in cnt: ans += i*(i-1) // 2 print(ans)
0
null
15,452,136,311,318
33
166
import math a, b, x = map(int, input().split()) theta = math.atan((-2) * x / (a ** 3) + 2 * b / a) if a * math.tan(theta) > b: theta = math.atan2(a * b * b, 2 * x) print(math.degrees(theta))
hei = int(input()) wei = int(input()) n = int(input()) kuro =0 count = 0 if hei > wei: data = hei else: data = wei while kuro<n: kuro +=data count +=1 print(count)
0
null
125,871,504,878,658
289
236
# C from collections import Counter N = int(input()) S = [input() for _ in range(N)] countS = Counter(S) maxS = max(countS.values()) ans = [] for key,value in countS.items(): if value == maxS: ans.append(key) for a in sorted(ans): print(a)
from collections import Counter n = int(input()) d = list(input() for _ in range(n)) D = Counter(d) m = max(D.values()) l = [] for i,j in D.most_common(): if m != j: break l.append(i) l.sort() for i in l: print(i)
1
69,954,054,218,474
null
218
218
X=list(map(int,input().split())) for i in range(0,5): if X[i]==0: print(i+1) break
a,b = list(map(int,input().split())) print("%d %d %f" % ((a//b),(a%b),float((a/b))))
0
null
7,033,151,765,724
126
45
# 数字を取得 N = int(input()) # 数値分ループ calc = [] for cnt in range(1, N + 1): # 3もしくは5の倍数であれば、加算しない if cnt % 3 != 0 and cnt % 5 != 0: calc.append(cnt) # 合計を出力 print(sum(calc))
N = int(input()) SUM = 0 for i in range(1, N + 1): if i % 3 != 0: if i % 5 != 0: SUM += i print(SUM)
1
34,927,375,381,238
null
173
173
import math s = input() print(s[:3])
a = input() print(a[0] + a[1] + a[2])
1
14,873,170,770,940
null
130
130
def main(): s, t = input().split(' ') print(t, end='') print(s) if __name__ == '__main__': main()
N, K = map(int, input().split()) mod = 10**9 + 7 fact_count = [0 for _ in range(K+1)] for k in range(1, K+1): fact_count[k] = K//k ans = 0 count = [0 for _ in range(K+1)] for k in range(K, 0, -1): c = pow(fact_count[k], N, mod) j = 2*k l = 2 while(j<=K): c -= count[j] l += 1 j = k*l count[k...
0
null
69,888,520,518,080
248
176
MOD = 1e9 + 7 n = int(input()) ans = [[0, 1, 1, 8]] for i in range(n-1): a, b, c, d = ans.pop() a = (a * 10 + b + c) % MOD b = (b * 9 + d) % MOD c = (c * 9 + d) % MOD d = (d * 8) % MOD ans.append([a, b, c, d]) a, b, c, d = ans.pop() print(int(a))
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop from functools import lru_cache import math #setrecursionlimit(10**6) rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: map(int, stdin.readline().spl...
1
3,136,787,307,694
null
78
78
n = int(input()) a = list(map(int, input().split())) a = [(i, j) for i, j in enumerate(a, start=1)] a.sort(key=lambda x: x[1]) a = [str(i) for i, j in a] print(' '.join(a))
import bisect import sys input = sys.stdin.readline n,d,a= map(int, input().split()) x= [list(map(int, input().split())) for i in range(n)] x.sort() y=[] for i in range(n): y.append(x[i][0]) x[i][1]=-(-x[i][1]//a) # どのモンスターまで倒したか管理しながら進める。 ans=0 # いつ効力が切れるか記録 z=[0]*(n+1) # 今の攻撃力 atk=0 for i in range(n): ...
0
null
131,087,040,987,450
299
230
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.appen...
import sys sys.setrecursionlimit(10 ** 6) # input = sys.stdin.readline #### int1 = lambda x: int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().spl...
0
null
28,918,274,821,746
162
163
n = int(input()) d = input() x = d[0] count = 1 for i in d: if i != x: count += 1 x = i print(count)
n = int(input()) s = input() res = 1 for i in range(n-1): if s[i] != s[i+1]: res += 1 print(res)
1
170,495,820,973,918
null
293
293
def main(): d,t,s = map(int, input().split()) if s*t >= d: print("Yes") else: print("No") if __name__ == '__main__': main()
import sys # A - Don't be late D, T, S = map(int, input().split()) if S * T >= D: print('Yes') else: print('No')
1
3,607,194,949,560
null
81
81
N = input() R = [int(raw_input()) for _ in xrange(N)] S = [0 for i in xrange(N)] S[N-1] = R[N-1] for i in xrange(N-2, -1, -1): S[i] = max(R[i], S[i+1]) ans = float('-inf') for i in xrange(N-1): ans = max(ans, S[i+1]-R[i]) print ans
n = input() maxv = - 1 * pow(10, 9) minv = input() for _ in xrange(1, n): Rj = input() maxv = max(maxv, Rj - minv) minv = min(minv, Rj) print maxv
1
14,151,636,598
null
13
13
import math r = input() l = 2 * math.pi * float(r) s = math.pi * float(r) * float(r) print("%f %f" % (s, l))
print(['win','bust'][sum(list(map(int,input().split())))>=22])
0
null
60,041,078,756,852
46
260
H,W = map(int,input().split()) if H ==1 or W ==1: print(1) else: a = H*W if a%2 == 0: print(int(a/2)) else: print(int(a/2)+1)
if __name__ == '__main__': N, M = map(int, input().split()) S = [] C = [] for i in range(M): s, c = map(int, input().split()) s -= 1 S.append(s) C.append(c) for num in range(0, pow(10, N)): st_num = str(num) if len(str(st_num))!=N: continue c...
0
null
55,750,875,016,892
196
208
import math import itertools n = int(input()) k = int(input()) f = len(str(n)) if f < k: print(0) else: #f-1桁以内に収まる数 en = 1 for i in range(k): en *= f-1-i de = math.factorial(k) s = en // de * pow(9, k) #f桁目によって絞る kami = int(str(n)[0]) en = 1 for i in range(k-1...
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...
1
76,069,813,268,640
null
224
224
from sys import stdin, setrecursionlimit def main(): n = int(stdin.readline()) print(n // 2) if n % 2 == 0 else print((n + 1) // 2) if __name__ == "__main__": setrecursionlimit(10000) main()
from collections import deque u = int(input()) g = [[i for i in map(int, input().split())] for _ in range(u)] graph = [[] for _ in range(u)] ans = [-1] * u for i in range(u): for j in range(g[i][1]): graph[i].append(g[i][2 + j] - 1) que = deque() que.append(0) ans[0] = 0 while que: v = que.popleft() ...
0
null
29,704,100,996,570
206
9
def az16(): list = [] n = input() for i in range(0,n): list.append(raw_input().split()) for mark in ["S","H","C","D"]: for i in range(1,14): if [mark,repr(i)] not in list: print mark,i az16()
all_set = ['S ' + str(i) for i in range(1, 14)] + ['H ' + str(i) for i in range(1, 14)] + ['C ' + str(i) for i in range(1, 14)] + ['D ' + str(i) for i in range(1, 14)] r = int(input()) for _ in range(r): x = input() if x in all_set: del all_set[all_set.index(x)] for i in all_set: print(i)
1
1,037,499,094,660
null
54
54
l,r,n = map(int,input().split(" ")) count = 0 for i in range(l,r+1): if i % n == 0: count += 1 print(count)
l,R, d = map(int, input().split()) a =0 for i in range(l,R+1): if i % d == 0: a = a+1 print(a)
1
7,630,868,875,604
null
104
104
h,n=map(int,input().split()) l=list(map(int,input().split())) a=0 for i in range(n): a+=l[i] if a>=h: print("Yes") else: print("No")
T1,T2,A1,A2,B1,B2=map(int, open(0).read().split()) C1,C2=A1-B1,A2-B2 if C1<0: C1,C2=-C1,-C2 Y1=C1*T1 Y2=Y1+C2*T2 if Y2>0: print(0) elif Y2==0: print("infinity") else: print(1+Y1//(-Y2)*2-(Y1%(-Y2)==0))
0
null
104,741,572,274,872
226
269
def count(s1, s2): dst = 0 for c1, c2 in zip(s1, s2): if c1 != c2: dst+=1 return dst def execute(S, T): dst = len(T) for i in range(len(S) - len(T)+1): s = S[i:i+len(T)] c = count(s, T) if c < dst: dst = c return dst if __name__ == '__main__': ...
S,T=input().split() A,B=map(int,input().split()) U=input() if(U==S): print("{}".format(A-1)+" {}".format(B)) else: print("{}".format(A)+" {}".format(B-1))
0
null
37,874,265,770,924
82
220
import sys n = int(input()) dic =set() t = sys.stdin.readlines() for i in t: i,op = i.split() if i == 'insert': dic.add(op) else: if op in dic: print('yes') else: print('no')
import numpy as np MOD = 10 ** 9 + 7 N = int(input()) A = np.array(input().split(), dtype=np.int64) total = 0 for shamt in range(65): bits = np.count_nonzero(A & 1) total += (bits * (N - bits)) << shamt A >>= 1 if not A.any(): break print(total % MOD)
0
null
61,776,346,718,678
23
263
S = int(input()) dp = [0] * (S + 1) dp[0] = 1 M = 10 ** 9 + 7 for i in range(1, S + 1): num = 0 for j in range(i - 2): num += dp[j] dp[i] = num % M print(dp[S])
S = int(input()) p = 10**9 +7 def pow_mod(p,a,n): res = 1 while n > 0: if n % 2 == 1: res = (res * a) % p n = n // 2 a = (a*a)%p return res n = 2000 fac = [1] foo = 1 for i in range(1,n+1): foo = (foo*i)%p fac.append(foo) #コンビネーションのmod def comb_mod(n,k): re...
1
3,276,156,512,608
null
79
79
# from sys import stdin # input = stdin.readline from collections import Counter def solve(): x,n = map(int,input().split()) if n != 0: p = set(map(int,input().split())) if n == 0 or x not in p: print(x) return else: for i in range(100): if x - i not in p: ...
n,k=map(int,input().split()) h=list(map(int,input().split())) h.sort() h.reverse() if k>n: k=n for i in range (k): h[i] = 0 print(sum(h))
0
null
46,278,116,005,702
128
227
n=int(input()) s=input().split() q=int(input()) t=input().split() cnt=0 for i in range(q): for j in range(n): if s[j]==t[i]: cnt+=1 break print(cnt)
def main(): D = int(input()) c = list(map(int,input().split())) s = [] for d in range(D): s.append(list(map(int,input().split()))) t = [] for d in range(D): t.append(int(input())-1) last = [0 for i in range(26)] v = 0 for d in range(D): ...
0
null
4,962,843,967,972
22
114
while True: h, w = map(int, input().split()) if w+h == 0: break line = "#"*w for y in range(h): print(line) print()
while True: H, W = map(int, input().split()) if (H, W) == (0, 0): break [print("#"*W+"\n") if i == H-1 else print("#"*W) for i in range(H)]
1
774,441,783,204
null
49
49
import math pi=math.pi def rtod(rad): return 180/pi*rad a,b,x=map(int,input().split()) if b/2<x/a**2: ans=2*(a**2*b-x)/a**3 ans=math.atan(ans) print(rtod(ans)) else: ans=b**2/(2*x)*a ans=math.atan(ans) print(rtod(ans))
ans = 100000 n = int(raw_input()) for i in xrange(n): ans *= 1.05 ans = int((ans+999)/1000)*1000; print ans
0
null
81,419,729,915,950
289
6
from collections import deque import copy H, W = map(int, input().split()) S = [input() for _ in range(H)] def warshall_floyd(d): #d[i][j]: iからjへの最短距離 for k in range(H*W): for i in range(H*W): for j in range(H*W): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d d = [...
a,b = input().split() a = int(a) b = int(b) d = a // b r = a % b f = a / b f = "{0:.8f}".format(f) fmt = "{v} {c} {n}" s = fmt.format(v = d,c = r,n = f) print(s)
0
null
47,817,765,081,850
241
45
n = int(input()) l = list(map(int, input().split())) sum = 0 for i in range(n): sum += l[i] print(min(l), max(l), sum)
N=int(input()) D=[map(int, input().split()) for i in range(N)] x, y = [list(i) for i in zip(*D)] s=0 l=[] for i in range(N): if x[i]==y[i]: s+=1 if i==N-1: l.append(s) elif x[i]!=y[i]: l.append(s) s=0 if max(l)>=3: print("Yes") else: print("No")
0
null
1,594,015,207,100
48
72
from scipy import misc N = int(input()) K = int(input()) d = len(str(N)) first = int(str(N)[0]) if K == 1: print(9*(d-1)+first) elif K == 2: if d == 1: print('0') else: for i in range(1,d): if str(N)[i] != '0': second_dig = i+1 second_num = int(st...
N = input() K = int(input()) L = len(N) dp = [[[0 for j in range(L + 10)] for i in range(L + 10)] for _ in range(2)] dp[0][0][0] = 1 for i in range(L): Ni = int(N[i]) for j in range(L): if Ni == 0: dp[0][i + 1][j + 0] += dp[0][i][j + 0] * 1 dp[0][i + 1][j + 1] += dp[0][i][j + 0...
1
76,015,539,217,312
null
224
224
n, k = map( int, input().split() ) r, s, p = map( int, input().split() ) t = str( input() ) t_list = [ c for c in t ] for i in range( k, n ): if t_list[ i ] == t_list[ i - k ]: t_list[ i ] = "x" score = 0 for hand in t_list: if hand == "r": score += p elif hand == "s": score += r ...
l, r, d = map(int, input().split()) result=0 for i in range(r-l+1): if (l+i) % d == 0: result+=1 print(result)
0
null
57,255,544,348,100
251
104
hei = int(input()) wei = int(input()) n = int(input()) kuro =0 count = 0 if hei > wei: data = hei else: data = wei while kuro<n: kuro +=data count +=1 print(count)
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return map(fn, readline().split()) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): x = gete(int) print('Yes' if x >= 3...
0
null
47,336,391,164,320
236
95
import sys input_num = int(sys.stdin.readline()) ans = '' for i in range(3, input_num + 1): if i % 3 == 0 or '3' in str(i): ans += ' ' + str(i) print ans
#!/usr/bin/env python3 from collections import Counter def main(): S = input() N = len(S) T = [0] * (N+1) for i in range(N-1,-1,-1): T[i] = (T[i+1] + int(S[i]) * pow(10,N-i,2019)) % 2019 l = Counter(T) ans = 0 for v in l.values(): ans += v * (v-1) // 2 print(ans) i...
0
null
15,793,531,084,844
52
166
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import gcd, s...
while True : a = raw_input().split() x = int(a[0]) y = int(a[1]) if x == 0 and y == 0 : break elif x < y : print u"%d %d" % (x, y) else : print u"%d %d" % (y, x)
0
null
75,515,893,197,832
281
43
#ABC156B n,k = map(int,input().split()) ans = 0 while n > 0 : n = n // k ans = ans + 1 print(ans)
n, k = map(int, input().split()) ans = 1 while(True): n = n//k if(n == 0): break ans += 1 print(ans)
1
64,066,591,119,076
null
212
212
a=input() n=int(input()) for i in range(n): b=input().split() if b[0]=='print': print(a[int(b[1]):int(b[2])+1]) elif b[0]=='replace': a=a[:int(b[1])]+b[3]+a[int(b[2])+1:] elif b[0]=='reverse': c=(a[int(b[1]):int(b[2])+1]) c=c[::-1] a=a[:int(b[1])]+c+a[int(b[2])+1:]
s=input() for i in range(int(input())): sou_com=input().split() if sou_com[0]=='print': print(s[int(sou_com[1]):int(sou_com[2])+1]) elif sou_com[0]=='reverse': s=s[:int(sou_com[1])]\ +s[int(sou_com[1]):int(sou_com[2])+1][::-1]\ +s[int(sou_com[2])+1:] elif sou_com[0]=='rep...
1
2,083,847,752,850
null
68
68
#coding:UTF-8 n = map(int,raw_input().split()) n.sort() print n[0],n[1],n[2]
a,b,c = map(int, input().split()) A = min(min(a, b),c) C = max(max(a,b),c) B = (a+b+c) - (A+C) print(A, B, C)
1
421,508,246,918
null
40
40
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1,...
import sys N, M = map(int, input().split()) S = input() tmp = 0 for i in range(N+1): if S[i] == '1': tmp += 1 if tmp == M: print(-1) sys.exit() else: tmp = 0 ans = [] i = N while i > M: ind = S[i-M:i].find('0') ans.append(M-ind) i -= M - ind ans.append(i) print(*ans[::-1])
1
139,330,320,746,948
null
274
274
# -*- coding: utf-8 -*- import functools @functools.lru_cache(maxsize=None) def fib(n): if n <= 1: return 1 else: return fib(n - 1) + fib(n - 2) if __name__ == '__main__': n = int(input()) print(fib(n))
D=int(input()) c=[int(i) for i in input().split()] a=[] for i in range(D): a.append([int(i) for i in input().split()]) last=[0 for i in range(26)] zoku=0 for d in range(D): t=int(input()) zoku+=a[d][t-1] last[t-1]=d+1 for i in range(26): zoku-=c[i]*(d+1-last[i]) print(zoku)
0
null
4,998,486,828,970
7
114
n = input() if n[-1]== "2" or n[-1]== "4" or n[-1]== "5" or n[-1]== "7" or n[-1]== "9": print("hon") elif n[-1]== "3": print("bon") else: print("pon")
s = input() map = {'SSS': 0, 'SSR': 1, 'SRS': 1, 'RSS': 1, 'SRR': 2, 'RSR': 1, 'RRS': 2, 'RRR': 3} for key in map.keys(): if s == key: print(map[key]) break
0
null
12,094,581,087,050
142
90
import math n = int(input()) x = list(map(float, (input().split()))) y = list(map(float, (input().split()))) l = [0.0]*n for i in range(n): l[i] = abs(x[i]-y[i]) print(sum(l)) che = max(l) for i in range(n): l[i] = abs(x[i]-y[i])**2 print(math.sqrt(sum(l))) for i in range(n): l[i] = abs(x[i]-y[i])**3 pri...
n=eval(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) def minkowski(p,x_1,x_2,n): if p==0: return float(max([abs(x_1[i]-x_2[i]) for i in range(n)])) else: return sum([(abs(x_1[i]-x_2[i]))**p for i in range(n)])**(1/p) for i in range(4): print(minkowski((i+1)%4,x,y...
1
213,328,135,868
null
32
32
import bisect import collections N,K=map(int,input().split()) A=list(map(int,input().split())) A.insert(0,0) cuml=[0]*(N+1) cuml[0]=A[0] l=[] cuml2=[] l2=[] buf=[] ans=0 for i in range(N): cuml[i+1]=cuml[i]+A[i+1] #print(cuml) for i in range(N+1): cuml2.append([(cuml[i]-i)%K,i]) cuml[i]=(cuml[i]-i)%K #print...
#!/usr/bin/env python3 import sys from collections import Counter input = sys.stdin.readline INF = 10**9 n, k = [int(item) for item in input().split()] a = [int(item) - 1 for item in input().split()] cumsum = [0] * (n + 1) for i in range(n): cumsum[i+1] = cumsum[i] + a[i] cumsum[i+1] %= k ls = list(set(cumsum...
1
137,197,523,068,480
null
273
273
n, t = map(int, input().split()) dish = [list(map(int, input().split())) for _ in range(n)] dish.sort(key=lambda x: x[0]) dp = [[0 for _ in range(3005)] for _ in range(3005)] ans = 0 for i in range(n): for j in range(t): dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) nj = j + dish[i][0] if nj <...
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...
1
151,030,707,292,000
null
282
282
n = int(input()) a = list(map(int,input().split())) a = sorted(a) aMax = a[-1] l = len(a) count = 0 k = 0 kSet = set() for i in range(n): value = a[i] if not(value in kSet): if i != 0 and a[i-1] == value: count -= 1 kSet.add(value) continue count += 1 ...
N = int(input()) A = list(map(int, input().split())) A.sort() MAX = 10**6+1 cnt = [0]*MAX for x in A: if cnt[x] != 0: cnt[x] = 2 else: for i in range(x, MAX, x): cnt[i] += 1 ans = 0 for x in A: # 2回以上通った数字 (cnt[x]>1) は,その数字より小さい約数が存在する (割り切れる他の数が存在する)。 if cnt[x] == 1: ans += 1 print(...
1
14,353,677,496,220
null
129
129
n = int(input()) s = list(map(int, input().split())) s.sort() dp = [0] * ((10 ** 6) + 100) for ss in s: dp[ss] += 1 A = max(s) pairwise = True setwise = True for i in range(2, A + 1): cnt = 0 for j in range(i, A + 1, i): cnt += dp[j] if cnt > 1: pairwise = False if cnt >= n: ...
from functools import reduce from math import gcd n = int(input()) A = list(map(int, input().split())) def furui(x): memo = [0]*(x+1) primes = [] for i in range(2, x+1): if memo[i]: continue primes.append(i) memo[i] = i for j in range(i*i, x+1, i): if memo[j]: ...
1
4,056,761,902,050
null
85
85
#!/usr/bin/env python3 def main(): print(int(input()) ** 3 / 27) if __name__ == '__main__': main()
print(((1/3)*float(input("")))**3)
1
47,250,163,720,256
null
191
191
from collections import Counter S = list(input()) S.reverse() MOD = 2019 t = [0] r = 1 for i in range(len(S)): q = (t[-1] + (int(S[i]) * r)) % MOD t.append(q) r *= 10 r %= MOD cnt = Counter(t) cnt_mc = cnt.most_common() ans = 0 for _, j in cnt_mc: if j >= 2: ans += j * (j - 1) // 2 ...
from collections import defaultdict s = input() rests = [0] n = 0 a = 0 m = 1 c = defaultdict(int) c[0] += 1 for i in list(s)[::-1]: n = n + int(i)*m c[n % 2019] += 1 m = m * 10 % 2019 for v in c.values(): a += v * (v-1) // 2 print(a)
1
30,999,432,372,612
null
166
166
#template def inputlist(): return [int(j) for j in input().split()] #template mod = 10**9 + 7 N = int(input()) A = inputlist() s = sum(A) ans = 0 for i in range(N): s -= A[i] ans += A[i]*s ans %= mod print(ans)
import sys import math def input(): return sys.stdin.readline().rstrip() def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) ng = 0 ok = 10 ** 9 + 1 while ok - ng > 1: mid = (ok + ng) // 2 ans = sum(list(map(lambda x: math.ceil(x / mid) - 1, A))...
0
null
5,153,536,261,952
83
99
n = int(input()) print("ACL" * n)
n=int(input()) r="ACL"*n print(r)
1
2,200,786,674,952
null
69
69
N = int(input()) a_list = list(map(int, input().split())) all_xor = 0 res = [] for a in a_list: all_xor ^= a for a in a_list: res.append(a ^ all_xor) print(*res)
# n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for i in range(m): # for _ in range(int(input())): #from collections import Counter #from fractions import Fraction n=int(input()) arr=list(map(int,input().split())) var=arr[0] for i in range(1,n): ...
1
12,505,915,524,708
null
123
123
k=int(input()) s=input() l=len(s) if l<=k: print(s) else: s=list(s) t=[] for i in range(k): t.append(s[i]) t.append('...') print(''.join(t))
#import time def main(): K = int(input()) S = input() if len(S) <= K: return S else: return S[:K] + "..." if __name__ == '__main__': #start = time.time() print(main()) #elapsed_time = time.time() - start #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
1
19,740,068,018,720
null
143
143
from collections import defaultdict n = int(input()) A = list(map(int, input().split())) dd = defaultdict(int) ans = 0 for i in range(n): diff = i - A[i] ans += dd[diff] summ = A[i] + i dd[summ] += 1 print(ans)
inp = input() if inp[0] == inp[1] and inp[1] == inp[2]: print("No") else: print("Yes")
0
null
40,552,301,097,212
157
201
#10_B import math a,b,C=map(int,input().split()) S=a*b*math.sin((C*2*math.pi)/360)/2 c=math.sqrt(a**2+b**2-2*a*b*math.cos((C*2*math.pi)/360)) L=a+b+c h=2*float(S)/a print(str(S)+'\n'+str(L)+'\n'+str(h)+'\n')
import math a,b,c=map(float,input().split()) h=b*math.sin(c/180.0*math.pi) ad=a-b*math.cos(c/180.0*math.pi) d=(h*h+ad*ad)**0.5 l = a + b + d s = a * h / 2.0 print('{0:.6f}'.format(s)) print('{0:.6f}'.format(l)) print('{0:.6f}'.format(h))
1
172,294,766,732
null
30
30
import sys input = sys.stdin.readline import numpy as np from scipy.sparse.csgraph import floyd_warshall def main(): N,M,L = map(int,input().split()) edge = np.zeros((N,N)) for _ in range(M): a,b,c = map(int,input().split()) edge[a-1][b-1] = edge[b-1][a-1] = c length = floyd_wa...
n = int(input()) ans = 0 count = 0 a, b, c = 1, 1, 1 while a <= n: # print("A : {0}".format(a)) # print("追加パターン : {0}".format( (n // a) )) if a == 1 : ans = ans + ( (n // a) - 1) else : if n // a == 1 : ans = ans + 1 else : if n % a == 0 : ...
0
null
88,107,800,716,172
295
73
a=int(input()) cnt=0 t=100 while t<a: t=(t*101)//100 cnt+=1 print(cnt)
def insertionsort(A, n, g, cnt): for i in range(g, n): v = A[i] j = i - g while (j >= 0 and A[j] > v): A[j + g] = A[j] j = j - g cnt += 1 A[j + g] = v return cnt A = [] n = int(raw_input()) for i in range(n): A.append(int(raw_input())) cnt = 0 G = [1] while G[-1] * 3 + 1 < n: G.append(G[-1] * 3...
0
null
13,656,327,952,176
159
17
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 s...
def e_handshake(): import numpy as np N, M = [int(i) for i in input().split()] A = np.array(input().split(), np.int64) A.sort() def shake_cnt(x): # 幸福度が x 以上となるような握手を全て行うときの握手の回数 # 全体から行わない握手回数を引く return N**2 - np.searchsorted(A, x - A).sum() # 幸福度の上昇が right 以上となるような握手は...
0
null
99,673,456,518,790
238
252
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) s...
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) # INF = float("inf") INF = 10**18 ...
0
null
133,635,103,300,740
261
279
exchange_cnt = 0 def insertion_sort(w_list, g): """一般化した Insertion ソート 通常の Insertion ソートは gap が 1 固定だが、ここでは、 gap を引数 g で指定できる。 当然、g < len(w_list) でないといけない。 """ global exchange_cnt N = len(w_list) for i in range(g, N): v = w_list[i] j = i - g while j >= 0 and w_...
# E - Bomber from collections import Counter h, w, m = map(int, input().split()) hw = [tuple(map(int, input().split())) for i in range(m)] ys, xs = zip(*hw) ymax, = Counter(ys).most_common(1) xmax, = Counter(xs).most_common(1) bombed = max(ymax[1], xmax[1]) if bombed < m: if ymax[1] > xmax[1]: xs = [b ...
0
null
2,357,407,380,860
17
89
def main(): num = list(map(int,input().split())) if num[0]+num[1]+num[2]<22: print('win') else: print('bust') main()
x, y, z = map(int,input().split()) a = x + y + z if (a >= 22): print("bust") else: print("win")
1
118,756,683,480,370
null
260
260
def main(M_1: int, D_1: int, M_2: int, D_2: int): print(M_2 - M_1) if __name__ == "__main__": M_1, D_1 = map(int, input().split()) M_2, D_2 = map(int, input().split()) main(M_1, D_1, M_2, D_2)
N,K = map(int, input().split()) L,R = [0]*K, [0]*K count = 0 for _ in range(K): a,b = map(int, input().split()) for _1 in range(_): x,y = L[_1],R[_1] if x <= a <= y or x <= b <= y : L[_1] = min(a,x) R[_1] = max(b,y) break else: L[_],R[_] =a,b ...
0
null
63,572,291,754,080
264
74
import sys X=map(int, sys.stdin.readline().split()) print X.index(0)+1
import sys from collections import Counter from itertools import combinations def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(20000000) MOD = 10 ** 9 + 7 INF = float("inf") def main(): N = int(input()) L = list(map(int, input().split())) count = Counter(L) key = count.k...
0
null
9,228,449,799,930
126
91
X, Y = map(int, input().split()) ans = 0 if X == 1: ans += 300000 elif X == 2: ans += 200000 elif X == 3: ans += 100000 else: ans += 0 if Y == 1: ans += 300000 elif Y == 2: ans += 200000 elif Y == 3: ans += 100000 else: ans += 0 if X == 1 and Y == 1: ans += 400000 print(ans)
def Qc(): x, n = map(int, input().split()) if 0 < n: p = list(map(int, input().split())) for i in range(101): if x - i not in p: print(x - i) exit() if x + i not in p: res = x + 1 print(x + i) ...
0
null
77,332,061,273,610
275
128
import bisect import collections N,K=map(int,input().split()) A=list(map(int,input().split())) A.insert(0,0) cuml=[0]*(N+1) cuml[0]=A[0] l=[] cuml2=[] l2=[] buf=[] ans=0 for i in range(N): cuml[i+1]=cuml[i]+A[i+1] #print(cuml) for i in range(N+1): cuml2.append([(cuml[i]-i)%K,i]) cuml[i]=(cuml[i]-i)%K #print...
import numpy as np from collections import defaultdict N, K = map(int, input().split()) As = np.array([0] + list(map(int, input().split()))) #Find (i, j) that satisfies "sum(As[i:j]) % K == j - i" #If 0 < j - i < K then #sum(As[i:j]) % K == j - i % K #<-> (sum(As[:j]) - j) % K == (sum(As[:i]) - i) % K mods = As % K ...
1
137,398,898,831,520
null
273
273
N, M = map(int, input().split(' ')) A_ls = list(map(int, input().split(' '))) A_ls = [i for i in A_ls if i >= sum(A_ls) / (4 * M)] if len(A_ls) >= M: print('Yes') else: print('No')
import sys x = sys.stdin.readline() print int(x) ** 3
0
null
19,616,502,220,320
179
35
input_line = input() a,b = input_line.strip().split(' ') a = int(a) b = int(b) if a < b: print("a < b") elif a > b: print("a > b") elif a == b: print("a == b")
N, S = int(input()), input() print("Yes" if N%2 == 0 and S[:(N//2)] == S[(N//2):] else "No")
0
null
73,721,479,908,900
38
279
def gcd(a,b): while b: a,b = b,a%b return abs(a) K=int(input()) #余裕でTLE? ans=0 for a in range(1, K+1): for b in range(1, K+1): for c in range(1, K+1): temp=a temp=gcd(temp, b) temp=gcd(temp, c) ans+=temp print(ans)
def main(): N = int(input()) A = ( 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 10334...
1
35,448,976,628,298
null
174
174
a, b, c = map(int, input().split()) k = int(input()) cnt = 0 while a >= b: cnt += 1 b *= 2 while b >= c: cnt += 1 c *= 2 if cnt <= k: print("Yes") else: print("No")
import math n = int(input()) x = list(map(int, input().split())) y = list(map(int, input().split())) xy = [] for i in range(n): xy.append(abs(x[i] - y[i])) D = [0, 0, 0, 0] D[0] = sum(xy) D2 = 0 for xyi in xy: D2 += xyi ** 2 D[1] = math.sqrt(D2) D3 = 0 for xyi in xy: D3 += xyi ** 3 D[2] = math.pow(D3, 1.0/3...
0
null
3,590,619,427,820
101
32
N, M = map(int, input().split()) pena= 0 ac = [0]*(10**5) for _ in range(M): tmp = input().split() if ac[int(tmp[0])-1] < 1: if tmp[1] == "AC": pena -= ac[int(tmp[0])-1] ac[int(tmp[0])-1] = 1 else: ac[int(tmp[0])-1] -= 1 #penalty print(ac.count(1), pena)
import bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.r...
1
93,328,114,783,232
null
240
240
import sys n,m,l=map(int,input().split()) e=[list(map(int,e.split()))for e in sys.stdin] for c in e[:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])
import sys lines = [list(map(int,line.split())) for line in sys.stdin] n,m,l = lines[0] A = lines[1:n+1] B = [i for i in zip(*lines[n+1:])] for a in A: row = [] for b in B: row.append(sum([i*j for i,j in zip(a,b)])) print (" ".join(map(str,row)))
1
1,409,737,899,192
null
60
60
def main(): N = int(input()) X = input() def popcount(x): '''xの立っているビット数をカウントする関数 (xは64bit整数)''' # 2bitごとの組に分け、立っているビット数を2bitで表現する x = x - ((x >> 1) & 0x5555555555555555) # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる x = (x & 0x3333333333333333) + ((x >> 2) & 0x...
n,k=map(int,input().split()) lst_ans=[] for i in range(k): s=int(input()) lst_n=list(map(int,input().split())) for j in lst_n: lst_ans.append(j) print(n-len(set(lst_ans)))
0
null
16,491,171,618,172
107
154
cards = list() pattern = ["S", "H", "C","D"] n = int(input()) for i in range(n) : s, r = input().split() #文字列として読み込み r = int(r) #sは文字列、rは数値 if(s == "S") : cards.append(0 + r) elif(s == "H") : cards.append(13 + r) elif(s == "C") : cards.append(26 + r) else : cards.append(39 + r) for i in ra...
from itertools import product (lambda *_: None)( *(lambda full, hand: map(print, filter(lambda c: c not in hand, full)))( map(' '.join, product('SHCD', map(str, range(1, 14)))), set(map(lambda _: input(), range(int(input()))))))
1
1,044,384,029,570
null
54
54
d = list(map(int, input().split())) order = input() class Dice(): def __init__(self, d): self.dice = d def InsSN(self, one, two, five, six): self.dice[0] = one self.dice[1] = two self.dice[4] = five self.dice[5] = six def InsWE(self, one, three, four, six): ...
#!/usr/bin/python3 n = int(input()) if(n%1000==0): print("0") else: ans = n%1000 print(1000-ans)
0
null
4,318,196,791,850
33
108
a, b, c = map(int, input().split()) k = int(input()) cnt = 0 while a >= b: cnt += 1 b *= 2 while b >= c: cnt += 1 c *= 2 if cnt <= k: print("Yes") else: print("No")
n = int(input()) full_set=set([x for x in range(1,14)]) cards={"S":[],"H":[],"C":[],"D":[]} for i in range(n): suit,num = input().split() cards[suit].append(int(num)) for suit in ["S","H","C","D"]: suit_set = set(cards[suit]) for num in sorted(list(full_set - suit_set)): print(suit,num)
0
null
4,013,922,855,360
101
54
n = int(input()) anums = list(map(int, input().split())) result = 'APPROVED' for anum in anums: if (anum % 2 == 0) and not ((anum % 3 == 0) or (anum % 5 == 0)): result = 'DENIED' break print(result)
import sys n=int(input()) data=list(map(int,input().split())) for i in data: if i%2==1: continue if i%3!=0 and i%5!=0: print("DENIED") sys.exit() print("APPROVED")
1
68,662,637,681,540
null
217
217
N=int(input()) M=1000 if N%M==0: print(0) else: print(M-N%M)
d,t,s = [int(x) for x in input().split()] if d/s <= t: print("Yes") else: print("No")
0
null
6,044,149,614,272
108
81
n, k = map(int, input().split(" ")) MOD = (10**9) + 7 def dSum(s, e): s -= 1 _s = s * (s + 1) // 2 _e = e * (e + 1) // 2 return _e - _s ans = 0 for i in range(k, n + 1): # _sum = dSum(n - i - 1, n) - dSum(0, i - 1) + 1 ans += dSum(i, n) - dSum(0, n - i) + 1 print((ans + 1) % MOD)
import sys import copy from collections import deque stdin = sys.stdin mod = 10**9+7 ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n,k = na() if n==k-1: print(1) exit(0) prev_min = sum([i for i in range(k)]) pre...
1
33,248,760,641,572
null
170
170
N,K = map(int,input().split()) MOD = pow(10,9)+7 ans = 0 for i in range(K,N+2): #KからN+1 MAX = i*(2*N-i+1)//2 MIN = i*(i-1)//2 #print(i,MIN,MAX) ans += (MAX-MIN+1)%MOD print(ans%MOD)
a,b = input().split() a = int(a) b = int(b) if a >= 10 or b >=10: print ('-1') else: print (a * b)
0
null
95,776,543,004,930
170
286
def II(): return int(input()) def LI(): return list(map(int, input().split())) N=II() a=LI() A=0 for elem in a: A^=elem ans=[elem^A for elem in a] print(*ans)
n = int(input()) a = list(map(int, input().split())) def nim(x): bx = [format(i,'030b') for i in x] bz = ''.join([str( sum([int(bx[xi][i]) for xi in range(len(x))]) % 2) for i in range(30)]) return int(bz, 2) nima = nim(a) ans = [ str(nim([nima,aa])) for aa in a ] print(' '.join(ans) )
1
12,514,010,017,732
null
123
123
def solve(): N = int(input()) return N*N print(solve())
S = input() T = input() a = len(T) for i in range(len(S)-len(T)+1): c = 0 for j, t in enumerate(T): if S[i+j] != t: c += 1 a = min(a, c) print(a)
0
null
74,229,611,283,908
278
82
from math import * def az9(): r = float(input()) print "%5f"%(pi*r*r), "%5f"%(2*pi*r) az9()
n, m, l = [int(x) for x in input().split()] a = [[int(x) for x in input().split()] for y in range(n)] b = [[int(x) for x in input().split()] for y in range(m)] c = [[0 for x in range(l)] for y in range(n)] for i in range(n): for j in range(l): c[i][j] = sum([a[i][x] * b[x][j] for x in range(m)]) for i in ...
0
null
1,024,090,656,750
46
60
def factorization(n): arr = [] tmp = n for i in range(2, int(-(-n**0.5//1))+1): if tmp % i == 0: cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i arr.append([i, cnt]) if tmp != 1: arr.append([tmp, 1]) if arr == [] and n != 1: arr.append([n, 1]) return arr n = int...
operand = ["+", "-", "*"] src = [x if x in operand else int(x) for x in input().split(" ")] stack = [] for s in src: if isinstance(s, int): stack.append(s) elif s == "+": b, a = stack.pop(), stack.pop() stack.append(a+b) elif s == "-": b, a = stack.pop(), stack.pop() ...
0
null
8,426,161,343,140
136
18
N = int(input()) As = [] Bs = [] for _ in range(N): c = 0 m = 0 for s in input(): if s == '(': c += 1 elif s == ')': c -= 1 m = min(m, c) if c >= 0: As.append((-m, c - m)) else: Bs.append((-m, c - m)) As.sort(key=lambda x: x[0]) Bs.sort(key=lambda x: x[1], reverse=True) f = ...
from sys import exit from itertools import accumulate,chain n,*s=open(0).read().split() t=[2*i.count("(")-len(i) for i in s] if sum(t)!=0: print("No");exit() st=[[min(accumulate(s_,lambda a,b: a+(1 if b=="(" else -1),initial=0)),t_] for s_,t_ in zip(s,t)] now=0 for c in chain(sorted([x for x in st if x[1]>=0])[::-1...
1
23,466,912,209,448
null
152
152
x, n = map(int, input().split()) p = [int(s) for s in input().split()] min_val = 101 for i in range(102): if i not in p: if abs(i - x) < min_val: min_val = abs(i - x) ans = i print(ans)
def inp(): return input() def iinp(): return int(input()) def inps(): return input().split() def miinps(): return map(int,input().split()) def linps(): return list(input().split()) def lmiinps(): return list(map(int,input().split())) def lmiinpsf(n): return [list(map(int,input().split()))for...
0
null
9,549,305,835,770
128
91
a, b, c, k = map(int, input().split()) ans = 0 if a >= k: ans += k k = 0 else: ans += a k -= a if b >= k: k = 0 else: k -= b if c >= k: ans -= k print(ans)
N=int(input()) a=list(map(int, input().split())) a=sorted(a)[::-1] ans =a[0] if len(a)%2 !=0: for i in range(1,int((len(a))/2)+1): for j in range(2): ans +=a[i] print(ans-a[int((len(a))/2)]) else: for i in range(1,(len(a))//2): for j in range(2): ans +=a[i] pr...
0
null
15,518,375,358,652
148
111
a, b = map(int, raw_input().split()) d = a // b r = a % b f = round(float(a)/float(b), 6) print d,r,f
a,b = map(float, raw_input().split()) if b > 10**6: f = 0.0 else: f = a/b d = int(a/b) r = int(a%b) print d, r, f
1
608,021,263,720
null
45
45
n=int(input()) a=list(map(int,input().split())) ans=0 plus=[0]*1000000 minus=[0]*1000000 for i in range(n): ene=i+1 pin=a[i] pl,mi=ene+pin,ene-pin if 0<=pl<1000000: plus[pl]+=1 if 0<=mi<1000000: minus[mi]+=1 for i in range(1000000): ans+=plus[i]*minus[i] print(ans)
import collections N = int(input()) A = list(map(int , input().split())) # N = 32 # A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5] # N = 6 # A = [2, 3, 3, 1, 3, 1] i = [k for k in range(1,N+1)] j = [k for k in range(1,N+1)] Li = [i[k]+A[k] for k in range(N)] Rj...
1
26,211,783,034,020
null
157
157
a, b, c =map(int, input().split()) d=(a-1)//c e=b//c ans=e-d print(ans)
l,r,d = map(int,input().split()) #print(l,r,d) ans = 0 for i in range(101): if d * i > r: break elif d * i >= l: ans += 1 continue else: continue print(ans)
1
7,518,628,050,546
null
104
104
N = int(input()) E = [[] for _ in range(N+1)] for _ in range(N): tmp = list(map(int, input().split())) if tmp[1] == 0: continue E[tmp[0]] = tmp[2:] cnt = [0 for _ in range(N+1)] q = [1] while q: cp = q.pop(0) for np in E[cp]: if cnt[np] != 0: continue cnt[np] = cnt[cp] + 1 q.append(np) for ind, co...
import sys n = int(input()) G = [None]*n for i in range(n): u, k, *vs = map(int, input().split()) G[u-1] = [e-1 for e in vs] from collections import deque dist = [-1]*n que = deque([0]) dist[0] = 0 while que: v = que.popleft() d = dist[v] for w in G[v]: if dist[w] > -1: #already visited ...
1
4,431,594,740
null
9
9
import sys from collections import deque read = sys.stdin.read N, *ab = map(int, read().split()) graph = [[] for _ in range(N + 1)] for a, b in zip(*[iter(ab)] * 2): graph[a].append(b) color = [0] * (N + 1) queue = deque([1]) while queue: V = queue.popleft() number = 1 for v in graph[V]: if ...
N = int(input()) ans = [0] * (N-1) to = [[] for i in range(N-1)] used = [0] * N for i in range(N-1): a, b = map(int, input().split()) to[a-1].append([b-1, i]) for i in range(N-1): unable = used[i] c = 1 for j, id in to[i]: if c == unable: c += 1 ans[id] = c use...
1
135,850,028,014,710
null
272
272
n,k=map(int,input().split()) P=list(map(int,input().split())) for i in range(n): P[i]-=1 C=list(map(int,input().split())) PP=[0]*n A=[0]*n V=[0]*n for i in range(n): if V[i]==1: continue B=[i] c=1 j=i p=C[i] while P[j]!=i: j=P[j] B.append(j) c=c+1 p=p+C[j] for j in B: A[j]=c ...
import sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = MI() A = [0] + LI() for i in range(K+1,N+1): print('Yes' if A[i] > A[i-K] else 'No')
0
null
6,326,198,007,470
93
102