code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
N = int(input()) tmp = 0 for i in range(3): amari = N%10 N //= 10 if amari == 7: print('Yes') tmp = 1 break if tmp != 1: print('No')
A=list(map(int,input())) b=0 for i in range(0,3): if A[i]==7: b+=1 if b==0: print("No") else: print("Yes")
1
34,169,613,230,450
null
172
172
# coding: utf-8 import sys import math import collections import itertools INF = 10 ** 10 MOD = 10 ** 9 + 7 def input() : return sys.stdin.readline().strip() def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y) def lcm(x, y) : return (x * y) // gcd(x, y) def I() : return int(input()) def LI() : return [int(x) for x in input().split()] def RI(N) : return [int(input()) for _ in range(N)] def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)] A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K = I() print(A[K - 1])
import sys def input(): return sys.stdin.readline().rstrip() def main(): X=[int(_) for _ in input().split()] sum=0 for x in X: if x == 1:sum+=300000 elif x==2:sum+=200000 elif x==3:sum+=100000 if X[0]==X[1] and X[0]==1: sum+=400000 print(sum) if __name__=='__main__': main()
0
null
95,209,110,790,108
195
275
a, b, m = map(int, input().split()) pa = list(map(int, input().split())) pb = list(map(int, input().split())) ans = min(pa) + min(pb) for _ in range(m): x, y, c = map(int, input().split()) x -= 1 y -= 1 ans = min(ans, pa[x] + pb[y] - c) print(ans)
a, b, m = list(map(int, input().split())) refrigerator_list = list(map(int, input().split())) microwave_list = list(map(int, input().split())) coupon_list = list() for _ in range(m): coupon_list.append(list(map(int, input().split()))) ans = min(refrigerator_list) + min(microwave_list) for coupon in coupon_list: ans = min(refrigerator_list[coupon[0] - 1] + microwave_list[coupon[1] - 1] - coupon[2], ans) print(ans)
1
53,805,842,056,032
null
200
200
X,Y=map(int,input().split());print((max((4-X),0)+max((4-Y),0)+((0,4)[X*Y==1]))*10**5)
a,b,c,d,e=map(int,input().split()) l=(60*c+d)-(60*a+b) ans=l-e print(ans)
0
null
79,674,773,534,160
275
139
from itertools import permutations n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) l=[i+1 for i in range(n)] perm = permutations(l) perm=list(perm) p=[] for i in perm: k=(''.join(map(str,i))) p.append(int(k)) a=''.join(map(str,a)) b=''.join(map(str,b)) idx1=p.index(int(a)) idx2=p.index(int(b)) print(abs(idx1-idx2))
def liner_search(r,key): for x in r: if x == key: return True return False N = int(input()) S = list(map(int, input().split())) q = int(input()) Key = list(map(int, input().split())) cnt = 0 for i in range(q): if liner_search(S, Key[i]): cnt += 1 print(cnt)
0
null
50,076,873,195,580
246
22
s=input() p=input() s=s+s l=0 s=s.lower() if s.find(p)==-1: print('No') else: print('Yes')
n, m = map(int, input().split()) c = 0 if n >= 2: c += n*(n-1) /2 if m >= 2: c += m*(m-1) /2 print(int(c))
0
null
23,582,479,363,520
64
189
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ?¨?????????? n ????????????????????????????????§????????°???????????°???????¨?????????£?????? ????????????????????????s1, s2 ... sn??¨????????¨??????????¨??????????????±???????????????°???????????????????????? ??????????????????????????¨????????°????????£?±2?????\???????????§??????????????? ?±2 = (???ni=1(si - m)2)/n ?????£?????£????????????????¨???????????±??¨????????? """ import math while True: num = int(input().strip()) if num == 0: break s = list(map(float,input().strip().split())) # ????????? m = 0 for i in range(num): m += s[i] m = m / num # ?¨?????????? a2 = 0 for i in range(num): a2 += (s[i] - m) ** 2 a = math.sqrt(a2 / num) print(a)
# B - Golden Coins # X X = int(input()) kiri_happy = X // 500 inaho_happy = (X - (500 * kiri_happy)) // 5 answer = (kiri_happy * 1000) + (inaho_happy * 5) print(answer)
0
null
21,383,956,539,208
31
185
a,b = map(int,raw_input().split()) d = a/b r = a%b f = round(a*1.0/b, 7) print d,r,f
N, K = map(int, input().split()) H = map(int, input().split()) if K >= N: print(0) exit() H = list(H) H.sort() print(sum(x for x in H[0 : N - K]))
0
null
39,999,292,535,846
45
227
str = raw_input() li = [] for a in list(str): if a.islower(): li.append(a.upper()) elif a.isupper(): li.append(a.lower()) else: li.append(a) print "".join(li)
var=input() print(var.swapcase())
1
1,503,668,636,988
null
61
61
num = input() L = [] house = [] for i in range(int(num)): k = input().split() k[0] = int(k[0]) k[1] = int(k[1]) k[2] = int(k[2]) k[3] = int(k[3]) L.append(k) for i in range(3): a = ["","0","0","0","0","0","0","0","0","0","0"] b = ["","0","0","0","0","0","0","0","0","0","0"] c = ["","0","0","0","0","0","0","0","0","0","0"] d = ["#"*20] house.append([a,b,c,d]) a = ["","0","0","0","0","0","0","0","0","0","0"] b = ["","0","0","0","0","0","0","0","0","0","0"] c = ["","0","0","0","0","0","0","0","0","0","0"] house.append([a,b,c]) for i in L: house[i[0]-1][i[1]-1][i[2]] = str(int(house[i[0]-1][i[1]-1][i[2]])+i[3]) for i in house: for j in i: k = " ".join(j) print(k)
import sys n = int(input()) A=[[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)] #0??§????????? #[[[0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0]], # [[0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0]], # [[0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0]], # [[0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0], # [0 0 0 0 0 0 0 0 0 0]]] #?£? Building = b #??? Floor = f #??? Room = r #??° Number = num for i in range(n): b,f,r,num = input().strip().split() A[int(b)-1][int(f)-1][int(r)-1]+=int(num) for i in range(4): for j in range(3): print('',' '.join(map(str,A[i][j]))) if i!=3: print('#'*20)
1
1,084,497,909,482
null
55
55
N = int(input()) C = input() W_total = C.count("W") R_total = N - W_total w_cur = 0 r_cur = R_total ans = R_total cur = 0 for i in range(N): if C[i] == "W": w_cur += 1 else: r_cur -= 1 ans = min(ans, min(w_cur, r_cur) + abs(w_cur - r_cur)) print(ans)
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)
1
6,314,878,523,018
null
98
98
x=int(input()) n=x//500 m=x%500 k=m//5 print(1000*n+5*k)
n=int(input()) a=list(map(int,input().split())) ans=10**20 p=sum(a) q=0 for i in range(n-1): q+=a[i] ans=min(ans,abs(p-q-q)) print(ans)
0
null
92,376,238,579,350
185
276
r = int(input()) print(r * 3.14159265 * 2);
import os import sys import numpy as np def solve(N, U, V, AB): G = [[0]*0 for _ in range(N+1)] for idx_ab in range(len(AB)): a, b = AB[idx_ab] G[a].append(b) G[b].append(a) P1 = np.zeros(N+1, dtype=np.int64) def dfs1(u): st = [u] while st: v = st.pop() p = P1[v] for u in G[v]: if p != u: st.append(u) P1[u] = v dfs1(U) path_u2v = [U] v = V while v != U: v = P1[v] path_u2v.append(v) path_u2v.reverse() l = len(path_u2v) half = (l-2) // 2 c = path_u2v[half] ng = path_u2v[half+1] Depth = np.zeros(N+1, dtype=np.int64) def dfs2(c): st = [c] P = np.zeros(N+1, dtype=np.int64) while st: v = st.pop() p = P[v] d = Depth[v] for u in G[v]: if p != u and u != ng: st.append(u) P[u] = v Depth[u] = d + 1 dfs2(c) c_ = path_u2v[l-1-half] v = c_ while v != c: Depth[v] = 0 v = P1[v] d = l%2 ans = max(Depth) + half + d return ans # >>> numba compile >>> numba_config = [ [solve, "i8(i8,i8,i8,i8[:,:])"], ] if sys.argv[-1] == "ONLINE_JUDGE": from numba import njit from numba.pycc import CC cc = CC("my_module") for func, signature in numba_config: vars()[func.__name__] = njit(signature)(func) cc.export(func.__name__, signature)(func) cc.compile() exit() elif os.name == "posix": exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}") else: from numba import njit for func, signature in numba_config: vars()[func.__name__] = njit(signature, cache=True)(func) print("compiled!", file=sys.stderr) # <<< numba compile <<< def main(): N, u, v = map(int, input().split()) if N==2: print(0) return AB = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(N-1, 2) ans = solve(N, u, v, AB) print(ans) main()
0
null
74,661,229,376,000
167
259
n,m,k=map(int,input().split()) mod1,mod2=10**9+7,998244353 mod=mod2 MAX=n-1 fact=[1]*(MAX+1) inv=[1]*(MAX+1) for i in range(2,MAX+1): fact[i]=i*fact[i-1]%mod inv[-1]=pow(fact[-1],mod-2,mod) for i in range(MAX,1,-1): inv[i-1]=inv[i]*i%mod def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0 ans=0 cor=pow(m-1,n-1-k,mod) for i in range(k,-1,-1): ans=(ans+comb(n-1,i)*cor)%mod cor=cor*(m-1)%mod print(m*ans%mod)
MOD = 998244353 factorial = None inverse_factorial = None def modpow(a, p): ans = 1 while p: if p&1 == 1: ans = (ans*a)%MOD a = (a*a)%MOD p >>= 1 return ans def nCr(n, r): if r == 0 or r == n: return 1 return (((factorial[n]*inverse_factorial[n-r])%MOD)*inverse_factorial[r])%MOD def init_nCr(max_n): global factorial, inverse_factorial factorial = [1]*(max_n+1) inverse_factorial = [0]*(max_n+1) for i in range(1, max_n+1): factorial[i] = (factorial[i-1]*i)%MOD inverse_factorial[i] = modpow(factorial[i], MOD-2) init_nCr(2*10**5+1) def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def solve(): N, M, K = read_ints() answer = 0 for k in range(0, K+1): answer = (answer+M*modpow(M-1, N-1-k)*nCr(N-1, k))%MOD return answer if __name__ == '__main__': print(solve())
1
23,190,802,918,592
null
151
151
import math x = int(input()) money = 100 count = 0 while money <= x: if x == money: break money = money + money // 100 count += 1 print(count)
X = int(input()) ans = 0 money = 100 for i in range(1, 10**18): money = (money * 101) // 100 if money >= X: ans = i break print(ans)
1
27,023,817,436,288
null
159
159
n = int(input()) arm = [] for _ in range(n): x, l = map(int,input().split()) arm.append([x-l, x+l]) arm.sort(key=lambda x: x[1]) cnt = 0 pr = -float('inf') for a in arm: if pr <= a[0]: cnt += 1 pr = a[1] print(cnt)
n, k = map(int, input().split()) lst = [int(i) for i in input().split()] tele_lst = [] town_set = set() town = 1 while True: if town not in town_set: tele_lst.append(town) town_set.add(town) else: break town = lst[town - 1] ind = tele_lst.index(town) length = len(town_set) circle = length - ind #print(ind, length) #print(tele_lst) if k < ind: town = tele_lst[k] print(town) else: k -= ind k %= circle #print(k) town = tele_lst[ind + k] print(town)
0
null
56,592,533,501,208
237
150
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def lcm(a, m): return a * b / gcd(a, b); while True: try: a, b = map(int, raw_input().split()) print gcd(a, b), lcm(a, b) except (EOFError): break
import sys def solve(): input = sys.stdin.readline N = int(input()) S = input().strip("\n") Left = [set() for _ in range(N)] Right = [set() for _ in range(N)] Left[0] |= {S[0]} Right[N-1] |= {S[N-1]} for i in range(1, N): Left[i] = Left[i-1] | {S[i]} Right[N-i-1] = Right[N-i] | {S[N-i-1]} used = set() for i in range(1, N - 1): mid = S[i] for l in Left[i-1]: for r in Right[i+1]: used |= {l + mid + r} print(len(used)) return 0 if __name__ == "__main__": solve()
0
null
64,038,697,838,710
5
267
import math a, b, c = list(map(int, input().split())) if a+b > c: print("No") elif 4*a*b < (c-a-b)**2: print("Yes") else: print("No")
n = int(input()) s = list(map(int,input().split())) count = 0 def merge(a, left, mid, right): global count l = a[left:mid] + [float("inf")] r = a[mid:right] + [float("inf")] i = j = 0 for k in range(left, right): if l[i] <= r[j]: a[k] = l[i] i += 1 else: a[k] = r[j] j += 1 count += right - left def mergeSort(a, left, right): if left + 1 < right: mid = right + (left - right)//2 mergeSort(a, left, mid) mergeSort(a, mid, right) merge(a, left, mid, right) mergeSort(s, 0, n) print(*s) print(count)
0
null
25,985,393,439,160
197
26
H = [] while True: try: H.append(input()) except EOFError: break H.sort() print(H[-1]) print(H[-2]) print(H[-3])
def check(k, W, p): s = 0 count = 1 for w in W: if s + w > p: count += 1 s = 0 s += w return count <= k n, k = map(int, input().split()) W = [int(input()) for _ in range(n)] right = sum(W) left = max(right // k, max(W)) - 1 while right - left > 1: p = (left + right) // 2 if check(k, W, p): right = p else: left = p print(right)
0
null
43,137,099,260
2
24
n = input() numbers = input().split(" ") numbers.reverse() numbers = " ".join(numbers) print(numbers)
_ = input() x = list(map(int, input().split())) y = [str(i) for i in reversed(x)] print(' '.join(y))
1
988,567,247,430
null
53
53
s = raw_input() p = raw_input() s = s + s if p in s: print 'Yes' else: print 'No'
s = raw_input() s += s p = raw_input() if(p in s): print("Yes") else: print("No")
1
1,757,386,477,460
null
64
64
i = 0 while 1: x = raw_input() i += 1 if x == "0": break print "Case %s: %s" % (i,x)
line1 = input() line2 = input() aryLine1 = line1.split() arystrLine2 = line2.split() K = int(aryLine1[0]); N = int(aryLine1[1]); aryLine2 = [int(s) for s in arystrLine2] #print(aryLine2) aryLine2.sort() #print(aryLine2) ans = K for i in range(0, N): temp1 = int(aryLine2[i]) if i == N - 1: temp2 = int(aryLine2[0]) + K else: temp2 = int(aryLine2[i + 1]) temp = temp1 - temp2 + K if temp < ans: ans = temp print(ans)
0
null
22,102,037,816,170
42
186
from itertools import permutations n = int(input()) x = [] y = [] ans,count,tempx,tempy = 0,0,0,0 for _ in range(n): a,b = map(int,input().split()) x.append(a) y.append(b) order = list(permutations(range(n))) for i in order: for j in i: if j == i[0]: tempx = x[j] tempy = y[j] continue count += (((x[j]-tempx)**2)+((y[j]-tempy)**2)) ** (0.5) tempx = x[j] tempy = y[j] ans += count / len(order) count = 0 print(ans)
def resolve(): X = int(input()) dp = [0 for _ in range(X + 110)] dp[0] = 1 for i in range(X + 1): if dp[i] == 0: continue dp[i + 100] = 1 dp[i + 101] = 1 dp[i + 102] = 1 dp[i + 103] = 1 dp[i + 104] = 1 dp[i + 105] = 1 print(dp[X]) resolve()
0
null
137,818,341,514,142
280
266
# abc155_c.py # https://atcoder.jp/contests/abc155/tasks/abc155_c # C - Poll / # 実行時間制限: 2 sec / メモリ制限: 1024 MB # 配点: 300点 # 問題文 # N枚の投票用紙があり、i (1≤i≤N) 枚目には文字列 Siが書かれています。 # 書かれた回数が最も多い文字列を全て、辞書順で小さい順に出力してください。 # 制約 # 1≤N≤2×105 # Siは英小文字のみからなる文字列 (1≤i≤N) # Siの長さは 1 以上 10 以下 (1≤i≤N) # 入力 # 入力は以下の形式で標準入力から与えられる。 # N # S1 # : # SN # 出力 # あてはまる文字列を全て辞書順で小さい順に、改行区切りで出力せよ。 # 入力例 1 # 7 # beat # vet # beet # bed # vet # bet # beet # 出力例 1 # beet # vet # 書かれた回数は beet と vet が 2回、beat と bed と bet が 1 回です。したがって、2回書かれた beet と vet を出力します。 # 入力例 2 # 8 # buffalo # buffalo # buffalo # buffalo # buffalo # buffalo # buffalo # buffalo # 出力例 2 # buffalo # 入力例 3 # 7 # bass # bass # kick # kick # bass # kick # kick # 出力例 3 # kick # 入力例 4 # 4 # ushi # tapu # nichia # kun # 出力例 4 # kun # nichia # tapu # ushi global FLAG_LOG FLAG_LOG = False def log(value): # FLAG_LOG = True # FLAG_LOG = False if FLAG_LOG: print(str(value)) def calculation(lines): # S = lines[0] N = int(lines[0]) # N, M = list(map(int, lines[0].split())) # values = list(map(int, lines[1].split())) # values = list(map(int, lines[2].split())) values = list() for i in range(N): values.append(lines[i+1]) # valueses = list() # for i in range(N): # valueses.append(list(map(int, lines[i+1].split()))) dic = dict() for value in values: if value in dic: dic[value] += 1 else: dic[value] = 1 tmp = list() for key in dic: tmp.append(dic[key]) ma = max(tmp) results = list() for key in dic: if dic[key] == ma: results.append(key) results.sort() return results # 引数を取得 def get_input_lines(): line = input() N = int(line) lines = list() lines.append(line) for _ in range(N): lines.append(input()) return lines # テストデータ def get_testdata(pattern): if pattern == 1: lines_input = ['7', 'beat', 'vet', 'beet', 'bed', 'vet', 'bet', 'beet'] lines_export = ['beet', 'vet'] if pattern == 2: lines_input = ['8', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo'] lines_export = ['buffalo'] if pattern == 3: lines_input = ['7', 'bass', 'bass', 'kick', 'kick', 'bass', 'kick', 'kick'] lines_export = ['kick'] if pattern == 4: lines_input = ['4', 'ushi', 'tapu', 'nichia', 'kun'] lines_export = ['kun', 'nichia', 'tapu', 'ushi'] return lines_input, lines_export # 動作モード判別 def get_mode(): import sys args = sys.argv global FLAG_LOG if len(args) == 1: mode = 0 FLAG_LOG = False else: mode = int(args[1]) FLAG_LOG = True return mode # 主処理 def main(): import time started = time.time() mode = get_mode() if mode == 0: lines_input = get_input_lines() else: lines_input, lines_export = get_testdata(mode) lines_result = calculation(lines_input) for line_result in lines_result: print(line_result) # if mode > 0: # print(f'lines_input=[{lines_input}]') # print(f'lines_export=[{lines_export}]') # print(f'lines_result=[{lines_result}]') # if lines_result == lines_export: # print('OK') # else: # print('NG') # finished = time.time() # duration = finished - started # print(f'duration=[{duration}]') # 起動処理 if __name__ == '__main__': main()
import sys list = map(int,sys.stdin.readline().split()) list.sort() print(' '.join(map(str,list)))
0
null
35,374,588,762,048
218
40
from sys import stdin from collections import defaultdict from math import gcd def main(): MOD = 1000000007 N, *AB = map(int, stdin.buffer.read().split()) d = defaultdict(int) n_zeros = 0 for a, b in zip(AB[::2], AB[1::2]): if a == 0 and b == 0: n_zeros += 1 continue g = gcd(a, b) a, b = a // g, b // g if a * b > 0 or b == 0: c = (abs(a), abs(b)) else: c = (-abs(a), -abs(b)) d[c] += 1 ans = 1 n_not_paired = 0 for ab, n in d.items(): ab_pair = (-ab[1], -ab[0]) if ab_pair in d: if ab[0] > 0: m = d[ab_pair] ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD else: n_not_paired += n ans = (ans * pow(2, n_not_paired, MOD) + n_zeros - 1) % MOD print(ans) if __name__ == '__main__': main()
N,A,B=map(int,input().split()) D=B-A if D%2: a=A-1 b=N-B print(min(a,b)+1+(D-1)//2) else: print(D//2)
0
null
65,238,666,590,942
146
253
n=int(input()) d=list(map(int,input().split())) s=0 for i in d: s+=i**2 print(int(((sum(d))**2)/2-(s/2)))
import sys a,v = map(int, sys.stdin.readline().rstrip("\n").split()) b,w = map(int, sys.stdin.readline().rstrip("\n").split()) t = int(sys.stdin.readline().rstrip("\n")) between = abs(b - a) speed = v-w if between <= speed*t: print('YES') else: print('NO')
0
null
91,619,904,679,166
292
131
import itertools n,m,q=map(int,input().split()) lst=[] ans=0 for i in range(q): a,b,c,d=map(int,input().split()) lst.append([a,b,c,d]) for x in list(itertools.combinations_with_replacement(range(1,m+1),n)): cnt=0 for i in lst: if x[i[1]-1]-x[i[0]-1]==i[2]: cnt+=i[3] ans=max(ans,cnt) print(ans)
n, m = map(int, input().split()) S = list(map(int, input()))[::-1] L = [] now = 0 while now < n: if n - now <= m: L.append(n - now) break for i in range(m, 0, -1): if not S[now+i]: now += i L.append(i) break else: print(-1) exit() print(*L[::-1])
0
null
83,551,992,390,582
160
274
A,B,C,K = map(int,input().split()) koa = 0 if A<K: koa = A else : koa = K kob = 0 if B<K-koa: kob = B else : kob = K-koa #print (koa) #print (kob) sum = koa+0*kob+(K-(koa+kob))*-1 print (sum)
a,b,c,k = map(int, input().split()) ans = 0 if k <= a: print(k) exit() k -= a ans += a if k <= b: print(ans) exit() k -= b print(ans - k)
1
21,675,761,744,480
null
148
148
# coding=utf-8 import math def koch(p1, p2, n): if n == 0: return None p1_x = p1[0] p1_y = p1[1] p2_x = p2[0] p2_y = p2[1] s_x = (1/3) * (2*p1_x + p2_x) s_y = (1/3) * (2*p1_y + p2_y) t_x = (1/3) * (p1_x + 2*p2_x) t_y = (1/3) * (p1_y + 2*p2_y) u_x = s_x + (1/2)*(t_x-s_x) + (-math.sqrt(3)/2)*(t_y-s_y) u_y = s_y + (math.sqrt(3)/2)*(t_x-s_x) + (1/2)*(t_y-s_y) koch([p1_x, p1_y], [s_x, s_y], n-1) print("%.8f %.8f" %(s_x, s_y)) koch([s_x, s_y], [u_x, u_y], n-1) print("%.8f %.8f" %(u_x, u_y)) koch([u_x, u_y], [t_x, t_y], n-1) print("%.8f %.8f" %(t_x, t_y)) koch([t_x, t_y], [p2_x, p2_y], n-1) n = int(input()) p1 = [0, 0] p2 = [100, 0] print("%.8f %.8f" %(p1[0], p1[1])) koch(p1, p2, n) print("%.8f %.8f" %(p2[0], p2[1]))
def koch(n, p1, p2): if n == 0: return s_x = p1[0] * 2/3 + p2[0] * 1/3 s_y = p1[1] * 2/3 + p2[1] * 1/3 t_x = p1[0] * 1/3 + p2[0] * 2/3 t_y = p1[1] * 1/3 + p2[1] * 2/3 u_x = (t_x - s_x) * 1/2 - (t_y - s_y) * 3 ** 0.5 / 2 + s_x u_y = (t_x - s_x) * 3 ** 0.5 / 2 + (t_y - s_y) / 2 + s_y s, t, u = (s_x, s_y), (t_x, t_y), (u_x, u_y) koch(n - 1, p1, s) print(' '.join(str(i) for i in s)) koch(n - 1, s, u) print(' '.join(str(i) for i in u)) koch(n - 1, u, t) print(' '.join(str(i) for i in t)) koch(n - 1, t, p2) S, G = (0, 0), (100, 0) print(' '.join(str(i) for i in S)) koch(int(input()), S, G) print(' '.join(str(i) for i in G))
1
127,964,016,996
null
27
27
import math import sys def lcm(a, b): return a * b // math.gcd(a, b) input = sys.stdin.readline n = int(input()) A = list(map(int, input().split())) LCM = 1 ans = 0 MOD = 1000000007 for x in A: LCM = lcm(LCM, x) for x in A: ans += LCM // x print(ans%MOD)
k,n = map(int, input().split()) arr = list(map(int, input().split())) prev = 0 m = 0 for i in arr: m = max(m, abs(prev-i)) prev = i m = max(m, k+arr[0]-arr[n-1]) ans = k-m print(ans)
0
null
65,770,986,995,780
235
186
from collections import deque h, w = map(int, input().split()) s = [] for i in range(h): s.append(list(input())) def bfs(x, y): if s[y][x] == '#': return 0 queue = deque() queue.appendleft([x, y]) visited = dict() visited[(x, y)] = 0 while queue: nx, ny = queue.pop() cur = visited[(nx, ny)] if nx - 1 >= 0 and (nx - 1, ny) not in visited: if s[ny][nx - 1] == '.': visited[(nx - 1, ny)] = cur + 1 queue.appendleft((nx - 1, ny)) if nx + 1 < w and (nx + 1, ny) not in visited: if s[ny][nx + 1] == '.': visited[(nx + 1, ny)] = cur + 1 queue.appendleft((nx + 1, ny)) if ny - 1 >= 0 and (nx, ny - 1) not in visited: if s[ny - 1][nx] == '.': visited[(nx, ny - 1)] = cur + 1 queue.appendleft((nx, ny - 1)) if ny + 1 < h and (nx, ny + 1) not in visited: if s[ny + 1][nx] == '.': visited[(nx, ny + 1)] = cur + 1 queue.appendleft((nx, ny + 1)) return max(visited.values()) result = 0 for i in range(h): for j in range(w): r = bfs(j, i) result = max(result, r) print(result)
A, B = map(int, input().split()) ans1 = 0 ans2 = 0 for i in range(10000): ans1 = int(i * 0.08) ans2 = int(i * 0.10) if (ans1) == A and int(ans2) == B: print(i) exit() print(-1)
0
null
75,441,420,978,572
241
203
n=input() a=n.swapcase() print(a)
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): s = S() k = I() same = len(set(list(s)))==1 ans = None if same: ans = len(s)*k//2 else: if s[0]!=s[-1]: cnt = 0 change = False for i in range(1,len(s)): if s[i] == s[i-1] and not change: cnt += 1 change = True else: change = False ans = cnt*k else: char = s[0] start = len(s) goal = -1 cnt = 0 while s[start-1] == char: start -= 1 while s[goal+1] == char: goal += 1 lenth = len(s)-start + goal+1 cnt += lenth//2 * (k-1) ccnt = 0 change = False for i in range(goal+1+1,start): if s[i] == s[i-1] and not change: ccnt += 1 change = True else: change = False cnt += ccnt * (k-2) ccnt = 0 change = False for i in range(1,start): if s[i] == s[i-1] and not change: ccnt += 1 change = True else: change = False cnt += ccnt ccnt = 0 change = False for i in range(goal+1+1, len(s)): if s[i] == s[i-1] and not change: ccnt += 1 change = True else: change = False cnt += ccnt ans = cnt print(ans) main()
0
null
88,088,114,457,028
61
296
a = int(input()) print(a//2-(a%2==0))
English_sentence='' try: while True: line=input() if line=='': break English_sentence+=line except EOFError: pass lowercase=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] uppercase=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] number=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] for _ in range(26): for _2 in English_sentence: if _2==lowercase[_] or _2==uppercase[_]: number[_]+=1 for ans in range(26): print("{0} : {1}".format(lowercase[ans],number[ans]))
0
null
77,564,761,912,946
283
63
n=int(input()) s=set([]) for i in range(n): s_=input() s.add(s_) print(len(s))
from collections import defaultdict def f(s): return int(s) - 1 N, K = map(int, input().split()) P = list(map(f, input().split())) C = list(map(int, input().split())) loop = [] first = -1 x = -1 loop_mem = [] cnt = 0 score = 0 rem = set(range(N)) while len(rem) > 0: if first < 0: first = rem.pop() x = first loop_mem.append(x) if x != first: rem.remove(x) cnt += 1 score += C[x] if first != P[x]: x = P[x] else: loop.append((loop_mem, cnt, score)) first = -1 loop_mem = [] cnt = 0 score = 0 ans = -1e10 for loop_mem, cnt, score in loop: imax = [-1e10 for _ in range(cnt)] imax[0] = 0 for x in loop_mem: tmp = 0 for j in range(1, cnt): tmp += C[x] imax[j] = max(imax[j], tmp) x = P[x] for j in range(2, cnt): imax[j] = max(imax[j-1], imax[j]) if score <= 0: ans = max(ans, imax[-1]) else: M = K // cnt m = K % cnt if M >= 1: tmp = max(score * M + max(imax[m], 0), score * (M-1) + imax[-1]) else: tmp = imax[m] ans = max(ans, tmp) print(ans)
0
null
17,789,262,609,574
165
93
input() s=set(input().split()) print(int(input())-len(set(input().split())-s))
from collections import deque,defaultdict import copy def main(): from collections import defaultdict import copy n,u,v = map(int,input().split()) u -= 1 v -= 1 graph = defaultdict(deque) for _ in range(n-1): a,b = map(int,input().split()) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) depth = dfs(graph,u,n) # print(depth) depth2 = dfs(graph,v,n) # print(depth2) ans = 0 ans2 = 10**6 for i,j in zip(depth,depth2): if i < j: ans = max(j,ans) # elif i == j: # ans2 = min(j,ans2) print(ans-1) def dfs(G,s,n): stack = deque([s]) graph = copy.deepcopy(G) depth = [None] * n depth[s] = 0 while stack: u = stack[-1] if graph[u]: v = graph[u].popleft() if depth[v] == None: depth[v] = depth[u] + 1 stack.append(v) else: stack.pop() return depth main()
0
null
58,941,861,038,488
22
259
N = int(input()) A = list(map(int, input().split())) ans = 1000 for i in range(N - 1): a = A[i] if a < A[i + 1]: units = ans // a ans = (ans - units * a) + units * A[i + 1] # print(i, ans) print(ans)
n = int(input()) a = list(map(int, input().split())) a = a + [0] state = a[0] money = 1000 stock = 0 for i in range(1, n+1): if state < a[i] and stock == 0: stock += (money // state) money %= state elif state > a[i] and stock > 0: money += (stock * state) stock = 0 state = a[i] print(money)
1
7,367,323,258,152
null
103
103
import math def solve(): A, B = [int(i) for i in input().split()] a = A / 0.08 b = B / 0.1 mi = min(a, b) ma = max(a, b) for i in range(math.floor(mi), math.ceil(ma) + 1): if int(i * 0.08) == A and int(i * 0.1) == B: print(i) exit() print(-1) if __name__ == "__main__": solve()
# coding: utf-8 def main(): A, B = map(int, input().split()) ans = -1 for i in range(10001): if i * 8 // 100 == A and i // 10 == B: ans = i break print(ans) if __name__ == "__main__": main()
1
56,686,697,824,682
null
203
203
h,w,k = map(int,input().split()) lst = [] cut1 = [] for i in range(h): l = input() if '#' in l: cut1.append(i) lst.append(l) res = [[float('inf')]*w for _ in range(h)] cut2 = [] for c in cut1: tmp_cut = [] for j in range(len(lst[c])): if lst[c][j]=='#': tmp_cut.append(j) cut2.append(tmp_cut) cnt = 1 for e,i in enumerate(cut1): for j in cut2[e]: res[i][j] = cnt cnt += 1 for r in res: mn = min(r) mx = max(r) if (mn==mx) and (mn==float('inf')): pass else: mx = max(set(r) - {float('inf')}) if mn==mx: for i in range(w): if r[i] == float('inf'): r[i] = mn else: for i in range(w): if r[i] == float('inf'): r[i] = mn else: mn = min(mx, r[i]) for i in range(w): tmp = [] for j in range(h): if res[j][i] != float('inf'): tmp.append(res[j][i]) num = min(tmp) for j in range(h): if res[j][i] == float('inf'): res[j][i] = num else: num = res[j][i] for r in res: print(*r)
N,X,Y = map(int,input().split()) X-=1;Y-=1 ans = [0 for _ in range(N-1)] for i in range(N): for j in range(i+1,N): direct = j-i shortcut = abs(X-i)+1+abs(Y-j) shortest = min(direct,shortcut) ans[shortest-1] += 1 print(*ans,sep="\n")
0
null
94,241,056,883,392
277
187
n,k = map(int, input().split()) al = list(map(int, input().split())) for _ in range(min(100,k)): imos = [0]*(n+1) for i,a in enumerate(al): l = max(0,i-a) r = min(n,i+a+1) imos[l] += 1 imos[r] -= 1 new_al = [] curr_val = 0 for im in imos[:-1]: curr_val += im new_al.append(curr_val) al = new_al[:] print(*al)
s=input() t=input() count=0 for i in range(0,len(s)): if(s[i]==t[i]): continue else: count+=1 print(count)
0
null
12,865,590,424,512
132
116
n = input() for ni in n: if ni == '7': print('Yes') exit() print('No')
s = input() print("Yes" if "7" in s else "No")
1
34,493,012,090,780
null
172
172
# -*- coding: utf-8 -*- # import numpy as np import sys from collections import deque from collections import defaultdict import heapq import collections import itertools import bisect import math def zz(): return list(map(int, sys.stdin.readline().split())) def z(): return int(sys.stdin.readline()) def S(): return sys.stdin.readline() def C(line): return [sys.stdin.readline() for _ in range(line)] def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] N = z() yakusu_nums = [0]*(N+1) for i in range(1, N+1): for j in range(i, N+1, i): yakusu_nums[j] += 1 ans = 0 for i, yakusu_num in enumerate(yakusu_nums): # print(i, yakusu_num) ans += i*yakusu_num print(ans)
import numpy as np a,b=map(int,input().split()) A=(''.join([str(a)]*b)) B=(''.join([str(b)]*a)) print(min(A,B))
0
null
47,902,377,361,680
118
232
input() n = input() count = 0 for i in range(2, len(n)): # print(n[i-2] + n[i-1] + n[i]) if (n[i-2] + n[i-1] + n[i]) == 'ABC': count += 1 print(count)
s = list(input()) num = 0 n = len(s) l = 0 i = 0 while i < n: if s[i] == '<': l+=num num+=1 i+=1 if i==n: l+=num else: cur = 0 while i < n and s[i]=='>': i+=1 cur+=1 if cur <= num: l+=num cur-=1 l+=(cur*(cur+1))//2 num = 0 print(l)
0
null
127,818,562,124,462
245
285
S = input() N = len(S) T = S[:(N-1)//2] U = S[(N+3)//2-1:] if S==S[::-1] and T == T[::-1] and U == U[::-1]: print("Yes") else: print("No")
H, N = map(int, input().split()) Magic = [list(map(int, input().split())) for i in range(N)] MAX_COST = max(Magic)[1] # dp[damage] := モンスターに damage を与えるために必要な最小コスト dp = [float('inf')] * (H + 1) dp[0] = 0 for h in range(H): for damage, cost in Magic: next_index = min(h + damage, H) dp[next_index] = min(dp[next_index], dp[h] + cost) print(dp[-1])
0
null
63,862,009,866,552
190
229
import sys A1,A2,A3 = map(int,input().split()) if not ( 1 <= A1 <= 13 and 1 <= A2 <= 13 and 1 <= A3 <= 13 ): sys.exit() if not ( isinstance(A1,int) and isinstance(A2,int) and isinstance(A3,int) ): sys.exit() print('bust') if A1 + A2 + A3 >= 22 else print('win')
# -*- coding: utf-8 -*- """ Created on Sat May 2 20:55:33 2020 @author: Kanaru Sato """ a = list(map(int, input().split())) if sum(a) >= 22: print("bust") else: print("win")
1
118,579,264,226,878
null
260
260
S = int(input()) sum_all = 0 sum_fizzbuzz = 0 for i in range(1,S+1): sum_all = sum_all + i if i % 3 == 0 or i % 5 == 0 or i % 15 ==0: sum_fizzbuzz = sum_fizzbuzz + i #print(sum_all) #print(sum_fizzbuzz) print(sum_all - sum_fizzbuzz)
def resolve(): n = int(input()) ans = 0 for i in range(1,n+1): if i%3!=0 and i%5!=0: ans += i print(ans) resolve()
1
35,093,263,292,188
null
173
173
s = input() n = len(s) + 1 t = [0]*n for i in range(n-1): if s[i] == '<': t[i+1] = t[i] + 1 for i in range(n-2,-1,-1): if s[i] == '>': t[i] = max(t[i],t[i+1]+1) print(sum(t))
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import itertools import math import sys INF = float('inf') def solve(K: int, S: str): return S[:K] + ['...', ''][len(S) <= K] def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() K = int(next(tokens)) # type: int S = next(tokens) # type: str print(solve(K, S)) if __name__ == '__main__': main()
0
null
88,408,099,633,918
285
143
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines a, b = map(int, readline().split()) ans = a - b * 2 if ans < 0: print(0) else: print(ans)
A,B = map(int,input().split()) if A <= 2*B: x = 0 else: x = A - 2*B print(x)
1
167,056,044,968,682
null
291
291
S = input() print(S.replace('?', 'D'))
T=input() ans=[] for i in range(len(T)): if T[i]=='P': ans.append('P') elif T[i]=='D': ans.append('D') else: ans.append('D') print(''.join(ans))
1
18,437,507,323,600
null
140
140
import math x = int(input()) def lcm(a, b): return (a * b) // math.gcd(a, b) rad = lcm(360, x) print(rad//x)
X = int(input()) eikaku = X if X < 180 else X - 180 cnt = 0 ans = 0 while True: ans += 1 cnt += eikaku if cnt % 360 == 0: print(ans) break
1
13,058,483,859,752
null
125
125
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if (v-w)*t >= abs(a-b): print('YES') else: print('NO')
import sys import math import bisect import heapq from collections import Counter def input(): return sys.stdin.readline().rstrip() def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) AS = [0] it = 0 for i in range(0, N): it += A[i] it %= K sj = (it - i - 1) % K AS.append(sj) # 最初だけ作る C = dict() C[0] = 1 current = 0 for j in range(1, N + 1): if j > K-1: C[AS[j - K]] -= 1 if AS[j] in C: current += C[AS[j]] C[AS[j]] += 1 else: C[AS[j]] = 1 print(current) if __name__ == "__main__": main()
0
null
76,076,252,517,452
131
273
string = input() for s in string: if s.isupper(): print(s.lower(), end='') else: print(s.upper(), end='') print('')
w=input() print(w.swapcase())
1
1,524,173,481,152
null
61
61
a = map(int, raw_input().split()) for i in range(len(a)): point = a[i:].index(min(a[i:])) + i temp = a[i]; a[i] = a[point] a[point] = temp print '%s %s %s' % (str(a[0]), str(a[1]), str(a[2]))
a,b=(map(int,input().split())) c=0 if a<=b: print(0) elif a>b: c=a-b*2 if c>0: print(c) elif c<=0: print(0)
0
null
83,576,179,863,232
40
291
N,K = map(int,input().split()) import numpy as np A = np.array(input().split(),np.int64) B = np.array(input().split(),np.int64) A.sort() ; B.sort() B=B[::-1] right = max(A*B) #時間の可能集合の端点 left = -1 #時間の不可能集合の端点 def test(t): C = A-t//B D= np.where(C<0,0,C) return D.sum()<=K while left+1<right: mid = (left+right)//2 if test(mid): right=mid else: left = mid print(right)
def binary_search(key): """二分探索法 O(logN) Args: key (int): 基準値 Vars: ok (int): 条件を満たすindexの上限値/下限値 ng (int): 条件を満たさないindexの下限値-1/上限値+1 Returns: int: 条件を満たす最小値/最大値 """ ok = 10 ** 12 ng = -1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if isOK(mid, key): ok = mid else: ng = mid return ok def isOK(i, key): """条件判定 Args: i (int): 判定対象の値 key (int): 基準値 Returns: bool: iが条件を満たすか否か """ cnt = 0 for v, d in l: if v > i: cnt += (v - i + d - 1) // d return cnt <= key n, k = map(int, input().split()) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort(reverse=True) f.sort() l = [] for i in range(n): l.append([a[i]*f[i], f[i]]) print(binary_search(k))
1
164,915,457,654,522
null
290
290
N=int(input()) n=len(str(N)) res=0 for a in range(1,N+1): a0=str(a)[0] a1=str(a)[-1] if a0=='0' or a1=='0': a_res=res continue for i in range(1,n+1): if i==1: if a0==a1: res+=1 elif i==2: if 10*int(a1)+int(a0)<=N: res+=1 elif i==n: n0=str(N)[0] n1=str(N)[-1] if n0<a1: res+=0 elif n0>a1: res+=10**(i-2) else: res+=(N-int(a1)*10**(i-1))//10+1 if n1<a0: res-=1 else: res+=10**(i-2) print(res)
n = int(input()) ans = 0 for i in range(1,n+1)[::-1]: head = str(i)[0] tail = str(i)[-1] length = len(str(i)) if tail == '0': continue if head == tail: if length == 1: ans += 1 elif length == 2: ans += 3 else: ans += 3 for j in range(3,length+1): if length > j: ans += 10**(j-2) * 2 else: ans += 2 * (int(str(i)[1:length-1]) + 1) elif head < tail: if length > 2: ans += int('1' * (length-2)) * 2 else: if length > 1: ans += int('1' * (length-1)) * 2 print(ans)
1
86,431,844,488,890
null
234
234
import math import numpy as np n = int(input()) s = math.sqrt(n) i = 2 f = {} while i <= s: while n % i == 0: f[i] = f.get(i,0)+1 n = n // i i += 1 ans = 0 for x in f.values(): e = 0 cumsum = 0 while e + cumsum + 1 <= x: e += 1 cumsum += e ans += e print(ans+(n>1))
from fractions import gcd from functools import reduce n = int(input()) a_list = [int(x) for x in input().split()] temp = 1 for a in a_list: temp *= a // gcd(a, temp) mod = 10 ** 9 + 7 ans = sum([temp // a for a in a_list]) % mod print(ans)
0
null
52,536,486,198,908
136
235
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N = int(input()) A = list(map(int, input().split())) count = 0 pos = 1 for i, a in enumerate(A): if a == pos: pos += 1 else: count += 1 if count <= N - 1: print(count) else: print(-1)
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) a = list(map(int, input().split())) c = 0 ans = -1 for num in a: if num==c+1: c = num else: pass # print(ans) if c>0: ans = max(ans, c) if ans>=0: print(n-ans) else: print(-1)
1
114,489,541,097,240
null
257
257
while True: x = input() if x == '0': break length = len(x) tot = 0 for i in range(length): tot += int(x[i:i + 1]) print(tot)
N = int(input()) ans = [0 for i in range(10100)] for x in range(1,100): for y in range(1,100): for z in range(1,100): n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x if n < 10100: ans[n] += 1 for n in range(N): print(ans[n+1])
0
null
4,759,877,124,000
62
106
n = int(input()) a = [int(i) for i in input().split()] ball_count = [0] * (n + 1) for i in a: ball_count[i] += 1 def nCr(i): if i<=1: return 0 else: return i*(i-1)//2 def get_total(ball_count): ans = 0 for i in ball_count: ans += nCr(i) return ans total = get_total(ball_count) for i in range(1, n + 1): num = ball_count[a[i - 1]] ans = total - nCr(num) + nCr(num-1) print(ans)
import math X = int(input()) a = 100 for i in range(1,200000): a += a//100 if a >= X: break print(i)
0
null
37,546,650,471,790
192
159
from sys import stdin import math def GCD(a,b): if(a%b==0): return b else: c = a%b return GCD(b,c) def LCM(a,b): gcd = GCD(a,b) return int(a*b/gcd) for line in stdin: a,b = line.split(" ") a = int(a) b = int(b) gcd = GCD(a,b) lcm = LCM(a,b) print(str(gcd)+" "+str(lcm))
w = list(input()) if (w[2] == w[3]) and (w[4] == w[5]): print("Yes") else: print("No")
0
null
21,125,512,382,778
5
184
a = int(input()) sum = a + a*a +a*a*a print(sum)
#!/usr/bin/env python3 import sys sys.setrecursionlimit(1000000) from collections import deque # 整数の入力 a = int(input()) print(a+a**2+a**3)
1
10,311,500,707,002
null
115
115
import itertools n=int(input()) ab = [] for _ in range(n): a, b = (int(x) for x in input().split()) ab.append([a, b]) narabi = [0+i for i in range(n)] ans = 0 count = 0 for v in itertools.permutations(narabi, n): count += 1 tmp_len = 0 for i in range(1,n): x, y = abs(ab[v[i-1]][0]-ab[v[i]][0])**2, abs(ab[v[i-1]][1]-ab[v[i]][1])**2 tmp_len += (x + y)**0.5 ans += tmp_len print(ans/count)
import itertools N = int(input()) cities = [tuple(map(int, input().split())) for _ in range(N)] distance = 0 for c in itertools.combinations(range(N), 2): c1, c2 = c distance += ((cities[c1][0] - cities[c2][0]) ** 2 + (cities[c1][1] - cities[c2][1]) ** 2) **0.5 answer = 2 * distance / N print(answer)
1
148,801,517,672,942
null
280
280
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() A = LI() count = [0] * (N + 1) for a in A: count[a] += 1 total = 0 for idx in range(N+1): total += count[idx] * (count[idx] - 1) / 2 for a in A: a_count = count[a] print(int(total - (a_count * (a_count - 1) / 2) + ((a_count - 1)*(a_count - 2)/2))) main()
def main(): N=int(input()) A=[int(a) for a in input().split()] Acnt, Aprob={}, {} for a in A: Acnt[a] = Acnt.get(a, 0) + 1 sumA=0 for k, a in Acnt.items(): Aprob[k]=a*(a-1)//2 sumA+=Aprob[k] #Acnt=[A.count(n) for n in range(N+1)] #Aprob=[Acnt[n]*(Acnt[n]-1)//2 for n in range(N+1)] #sumA=sum(Aprob) for a in A: ans=(Acnt[a]-1)*(Acnt[a]-2)//2 print(ans+sumA-Aprob[a]) main()
1
47,428,229,600,960
null
192
192
r=input().split() a=int(r[0]) b=int(r[1]) if a>=b: ans="" for i in range(a): ans+=str(b) print(int(ans)) else: ans="" for i in range(b): ans+=str(a) print(int(ans))
a,b = input().split() print(a*int(b)) if a < b else print(b*int(a))
1
84,484,725,640,068
null
232
232
import sys sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python import math from copy import copy, deepcopy from copy import deepcopy as dcp from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque, defaultdict #deque(l), pop(), append(x), popleft(), appendleft(x) #q.rotate(n)で → にn回ローテート from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate,combinations,permutations,product#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする from functools import reduce,lru_cache#pypyでもうごく #@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率 from decimal import Decimal def input(): x=sys.stdin.readline() return x[:-1] if x[-1]=="\n" else x def printe(*x):print("## ",*x,file=sys.stderr) def printl(li): _=print(*li, sep="\n") if li else None def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def matmat(A,B): K,N,M=len(B),len(A),len(B[0]) return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] def matvec(M,v): N,size=len(v),len(M) return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] def T(M): n,m=len(M),len(M[0]) return [[M[j][i] for j in range(n)] for i in range(m)] def main(): mod = 1000000007 #w.sort(key=itemgetter(1),reverse=True) #二個目の要素で降順並び替え N = int(input()) s = input() #N, K = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル #L = tuple(int(input()) for i in range(N)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 def bin(x): return format(x, 'b') def bitcount(x): #xは64bit整数 x= x - ((x >> 1) & 0x5555555555555555) x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) return x & 0x7f @lru_cache(None) def r(n): if n==0: return 0 bc=bitcount(n) return r(n%bc)+1 mod=s.count("1") c1=0 c2=0 cur1=1%(mod+1) if mod>1: cur2=1%(mod-1) for i in range(N): if s[-1-i]=="1": c1+=cur1 c1%=(mod+1) c2+=cur2 c2%=(mod-1) cur1=cur1*2%(mod+1) cur2=cur2*2%(mod-1) else: for i in range(N): if s[-1-i]=="1": c1+=cur1 c1%=(mod+1) cur1=cur1*2%(mod+1) for i in range(N): if s[i]=="1": f=-1 cmod=mod-1 else: f=1 cmod=mod+1 if cmod==0: print(0) continue if f==1: n=c1+pow(2,N-1-i,cmod) n%=cmod else: n=c2-pow(2,N-1-i,cmod) n%=cmod print(1+r(n)) #printe(c1,c2) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- def main(): A, B = map(int, input().split()) ans = A - 2 * B if ans < 0: ans = 0 print(ans) if __name__ == "__main__": main()
0
null
87,376,429,180,192
107
291
N=input() N=list(N) N=map(lambda x: int(x),N) if sum(N)%9==0: print("Yes") else: print("No")
N = int(input()) digits = list(map(int,str(N))) if sum(digits) % 9 == 0: print('Yes') else: print('No')
1
4,364,679,498,620
null
87
87
def f(n): res = [] for p in range(2, int(n**0.5)): k = 0 while(n % p == 0): n //= p k += 1 if k: res.append((p, k)) if n != 1: res.append((n,1)) return res n = int(input()) ans = 0 r = f(n) for p,k in r: tmp = 0 cur = 1 while(k>=cur): tmp += 1 k -= cur cur += 1 ans += tmp print(ans)
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)
0
null
13,239,345,135,260
136
113
import math K = int(input()) result = 0 # 全て等しい場合はそれ自身が最大公約数 for i in range(1, K+1): result += i # 二つが等しい場合は二つある方を選ぶので2倍、二数の公約数の三倍で6倍 d = {} for i in range(1, K+1): for j in range(i+1, K+1): d[(i, j)] = math.gcd(i, j) result += 6 * d[(i, j)] # 三つバラバラなら6倍 for i in range(1, K+1): for j in range(i+1, K+1): for k in range(j+1, K+1): tmp = 0 if i < j: tmp = d[(i, j)] else: tmp = d[(j, i)] if tmp < k: result += 6 * d[(tmp, k)] else: result += 6 * d[(k, tmp)] print(result)
import math k = int(input()) ans = 0 for q in range(1,k+1): for r in range(1,k+1): x = math.gcd(q,r) for s in range(1,k+1): ans += math.gcd(x,s) print(ans)
1
35,326,810,567,182
null
174
174
#coding:UTF-8 while True: h,w = map(int,raw_input().split()) if h == 0 and w == 0: break for i in range(h): if i%2 == 1: if w % 2 == 0: print ".#" * (w / 2) else: print ".#" * (w / 2) + "." else: if w % 2 == 0: print "#." * (w/2) else: print "#." * (w/2) + "#" print ""
''' ITP-1_5-C ?????§????????????????????? ??\????????????????????????H cm ?????? W cm ????????§????????????????????¢?????????????????°????????????????????????????????? #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# ?????????????????? 6 cm ?????? 10 cm ???????????¢?????¨?????????????????? ????????¢???????????? "#" ??¨???????????????????????????????????? ???Input ??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§?????? H W H, W ?????¨?????? 0 ?????¨????????\?????????????????¨???????????? ???Output ?????????????????????????????????????????? H cm ?????? W cm ????????????????????????????????? ?????????????????????????????????????????????????????\?????????????????? ''' # import import sys for line in sys.stdin: # ?????°?????????????????? H, W = map(int, line.split()) if H == 0 and W == 0: break # ?????¢?????? for a in range(H): # ?\???°????????? if a%2 == 1: for b in range(W): if b%2 == 1: # ??????????????§'#'?????? print('#', end='') else: # ??????????????§'.'?????? print('.', end='') # ??????????????????????????? print('') # ??¶??°????????? else: for c in range(W): if c%2 == 1: # ??????????????§'.'?????? print('.', end='') else: # ??????????????§'#'?????? print('#', end='') # ??????????????????????????? print('') # ???????????????????????? print('')
1
877,748,483,580
null
51
51
u,s,e,w,n,b = list(map(int, input().split())) rolls = input() for roll in rolls: if roll == 'N': n,u,e,w,b,s = u,s,e,w,n,b elif roll == 'S': s,b,e,w,u,n = u,s,e,w,n,b elif roll == 'E': e,s,b,u,n,w = u,s,e,w,n,b elif roll == 'W': w,s,u,b,n,e = u,s,e,w,n,b else: print('Error') raise(-1) print(u)
u, s, e, w, n, d = input().split() insts = input() for inst in insts: if inst == 'N': u, s, n, d = s, d, u, n elif inst == 'E': u, e, w, d = w, u, d, e elif inst == 'S': u, s, n, d = n, u, d, s elif inst == 'W': u, e, w, d = e, d, u, w print(u)
1
234,689,467,138
null
33
33
n=int(input()) p=list(map(int,input().split())) sai = p[0] answer = 1 for i in range(1,n): if p[i-1]<=sai: sai=p[i-1] if sai >= p[i]: answer = answer + 1 print(answer)
N=int(input()) P=list(map(int,input().split())) m_v=N+1 ans=0 for i in range(N): m_v=min(m_v,P[i]) if m_v==P[i]: ans+=1 print(ans)
1
85,672,863,388,112
null
233
233
#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 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 gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a // gcd(a, b) * b #print(lcm(lcm(1000000,999999),999998)) #print(999998//2*999999) #print(1000000*999999*999998%mod) n=I() lis=LI() promod=1 LCM=1 for i in range(n): LCM=lcm(lis[i],LCM) #print(LCM) for i in range(n): promod=(promod*(lis[i]%mod))%mod smmod=0 for i in range(n): smmod=(smmod+promod*pow(lis[i],mod-2,mod))%mod #print(smmod) x=(promod*pow(LCM%mod,mod-2,mod))%mod ans=(smmod*pow(x,mod-2,mod))%mod print(ans)
import fractions c=0 N=int(input()) L=list(map(int,input().split())) a=L[0] for i in range(1,N): a=(L[i]*a)//fractions.gcd(L[i], a) for i in range(N): c+=(a//L[i]) print(c%(10**9+7))
1
87,612,204,130,260
null
235
235
import sys #input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode('utf-8') class BinaryIndexedTree: def __init__(self,n,default=0): self.s=[default]*(n+1) self.n=n def add(self,val,idx): while idx<self.n+1: self.s[idx]=self.s[idx]+val idx+=idx&(-idx) return def get(self,idx): res=0 while idx>0: res=res+self.s[idx] idx-=idx&(-idx) return res from collections import defaultdict def main(): n=II() s=input() S=[0]+list(s) d=defaultdict(lambda:BinaryIndexedTree(n)) for i,si in enumerate(s): #print(i,si) d[si].add(1,i+1) q=II() for _ in range(q): f,a,b=input().split() if int(f)==1: a=int(a) d[S[a]].add(-1,a) d[b].add(1,a) S[a]=b else: #print(S,a,b) a=int(a) b=int(b) cnt=0 for bit in d.values(): if bit.get(b)-bit.get(a-1)>0: cnt+=1 print(cnt) if __name__=="__main__": main()
class BinaryIndexedTree(): def __init__(self, max_n): self.size = max_n + 1 self.tree = [0] * self.size self.depth = self.size.bit_length() def initialize(self, seq): for i, x in enumerate(seq[1:], 1): self.tree[i] += x j = i + (i & (-i)) if j < self.size: self.tree[j] += self.tree[i] def __repr__(self): return self.tree.__repr__() def get_sum(self, i): s = 0 while i: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i < self.size: self.tree[i] += x i += i & -i def find_kth_element(self, k): x, sx = 0, 0 dx = (1 << self.depth) for i in range(self.depth - 1, -1, -1): dx = (1 << i) if x + dx >= self.size: continue y = x + dx sy = sx + self.tree[y] if sy < k: x, sx = y, sy return x + 1 n = int(input()) s = ["!"]+list(input()) q = int(input()) bit = [BinaryIndexedTree(n+1) for i in range(26)] for i in range(n): ind = ord(s[i+1])-97 bit[ind].add(i+1,1) for i in range(q): a,b,c = input().split() b = int(b) if a == "1": ind = ord(s[b])-97 bit[ind].add(b,-1) ind = ord(c)-97 bit[ind].add(b,1) s[b] = c else: ans = 0 c = int(c) for i in range(26): if bit[i].get_sum(c)-bit[i].get_sum(b-1): ans += 1 print(ans)
1
62,604,162,135,968
null
210
210
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(str, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #import numpy as np from decimal import * K = INT() n = [-1]*11 cnt = 0 def DFS(n): global cnt for i in range(1, 11): if n[-i] == 9: continue elif n[-i-1] != -1 and n[-i] == n[-i-1]+1: continue else: if n[-i] == -1: n[-i] = 1 else: n[-i] += 1 for j in range(i-1, 0, -1): n[-j] = max(0, n[-j-1] - 1) break cnt += 1 if cnt == K: print(*n[bisect(n, -1):], sep = "") exit() DFS(n) DFS(n)
def gcd2(x,y): if y == 0: return x return gcd2(y,x % y) def lcm2(x,y): return x // gcd2(x,y) * y a,b = map(int,input().split()) print(lcm2(a,b))
0
null
76,596,579,902,410
181
256
import sys input = sys.stdin.buffer.readline N = int(input()) ans = 0 for a in range(1, N+1): maxb = (N-1)//a ans += maxb print(ans)
N, M, K = map(int, input().split()) MOD = 998244353 n = N fac = [1]*(n+1) rev = [1]*(n+1) for i in range(1,n+1): fac[i] = i*fac[i-1]%MOD rev[i] = pow(fac[i], MOD-2, MOD) comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD ans = 0 for i in range(K+1): ans += comb(N-1, N-1-i) * M * pow(M-1, N-1-i, MOD) ans %= MOD print(ans)
0
null
12,926,891,789,120
73
151
N=int(input()) S={} for n in range(N): s=input() S[s]=S.get(s,0)+1 maxS=max(S.values()) S={k:v for k, v in S.items() if v==maxS} S=sorted(S.items(), key=lambda x:(-x[1],x[0])) for k,cnt in S: print(k)
n = int(input()) s = [] for i in range(n): s.append(input()) s.sort() # print(s) m = 1 cnt = [1] ans = [] for i in range(1,n): if s[i] == s[i-1]: cnt[-1] += 1 else: if cnt[-1] > m: ans = [s[i-1]] elif cnt[-1] == m: ans.append(s[i-1]) m = max(m, cnt[-1]) cnt.append(1) if i == n-1 and cnt[-1] > m: ans = [s[i]] elif i == n-1 and cnt[-1] == m: ans.append(s[i]) print('\n'.join(ans))
1
69,906,478,293,680
null
218
218
X = int(input()) c1 = X//500 X = X - c1*500 c2 = X//5 print(c1*1000 + c2*5)
x = int(input()) n_500 = x//500 n_5 = (x%500)//5 print(n_500*1000 + n_5*5)
1
42,821,737,662,912
null
185
185
N, K = list(map(int, input().split())) MOD = 10**9+7 gcd_dict = {} for i in range(K, 0, -1): number = pow((K//i), N, MOD) number %= MOD counter = 2 while True: if counter*i in gcd_dict: number -= gcd_dict[counter*i] counter += 1 else: gcd_dict[i] = number % MOD break print(sum([i*j for i, j in gcd_dict.items()]) % MOD)
def maximum(): A,B,C,K = map(int,input().split()) num = 0 max = 0 if A <= K: max = A num = K - A if B <= num: num = num - B max -= num print(max) return else: print(max) return else: print(K) return maximum()
0
null
29,246,833,685,330
176
148
n,k,s = map(int,input().split(" ")) ar = [] for i in range(k): ar.append(s) for i in range(n-k): if s == 10 ** 9: ar.append(1) else: ar.append(s + 1) for i in range(n-1): print(ar[i],end=" ") print(ar[n-1])
X,N=map(int,input().split()) p=list(map(int,input().split())) upper=float("inf") lower=float("inf") a=X b=X while True: if not a in p: upper=a break a+=1 while True: if not b in p: lower=b break b-=1 if abs(upper-X)==abs(lower-X): print(lower) elif abs(upper-X)>abs(lower-X): print(lower) else: print(upper)
0
null
52,421,384,597,932
238
128
from scipy.special import comb from collections import Counter N = int(input()) A = list(map(int, input().split())) C = Counter(A) x = 0 for c in C.values(): x += comb(c, 2, exact=True) for i in range(N): y = x - comb(C[A[i]], 2, exact=True) + comb(C[A[i]] - 1, 2, exact=True) print(y)
def solve(): import collections N = int(input()) A = [int(i) for i in input().split()] counter = collections.Counter(A) combis = {} total = 0 for k,v in counter.items(): combi = v * (v-1) // 2 combis[k] = combi total += combi for i in range(N): cnt = counter[A[i]] if cnt > 1: combi = (cnt-1) * (cnt-2) // 2 else: combi = 0 print(total - combis[A[i]] + combi) if __name__ == "__main__": solve()
1
47,505,082,932,790
null
192
192
a=input().split() if int(a[0])<int(a[1]): print("a < b") elif int(a[0]) == int(a[1]): print("a == b") else: print("a > b")
n, k = map(int, input().split()) w = [int(input()) for _ in range(n)] # k台以内のトラックで運べる荷物の個数 # P: ひとつのトラックに積載できる最大量 def check(P): i = 0 for j in range(k): s = 0 while s + w[i] <= P: s += w[i] i += 1 if i == n: return n return i # 二部探索 left = 0 right = 100000 * 10000 while right - left > 1: mid = (left + right) // 2 v = check(mid) if v >= n: right = mid else: left = mid print(right)
0
null
220,132,652,920
38
24
def main(): import sys b=sys.stdin.buffer input=b.readline n=int(input()) d=[set()for _ in range(n)]+[{c}for c in input()] for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i] r=[] add=r.append input() for q,a,b in zip(*[iter(b.read().split())]*3): i=int(a)+n-1 if q<b'2': d[i]={b[0]} while i: i>>=1 d[i]=d[i+i]|d[i-~i] continue j=int(b)+n s=set() while i<j: if i&1: s|=d[i] i+=1 if j&1: j-=1 s|=d[j] i>>=1 j>>=1 add(len(s)) print(' '.join(map(str,r))) main()
N = int(input()) S = list(input()) Q = int(input()) alphabet = "abcdefghijklmnopqrstuvwxyz" num = dict() for i, var in enumerate(alphabet): num[var] = i class Bit(): def __init__(self, N): self.__N = N self.__arr = [[0] * 26 for _ in range(1 + N)] def add_(self, x, a, i): while(x < self.__N + 1): self.__arr[x][i] += a x += x & -x def sum_(self, x, i): res = 0 while(x > 0): res += self.__arr[x][i] x -= x & -x return res def sub_sum_(self, x, y, i): return self.sum_(y, i) - self.sum_(x, i) Bit = Bit(N) for i, var in enumerate(S): Bit.add_(i+1, 1, num[var]) for i in range(Q): q, l, r = input().split() l = int(l) if q == "1" and r != S[l-1]: temp = S[l-1] S[l-1] = r Bit.add_(l, -1, num[temp]) Bit.add_(l, 1, num[r]) elif q == "2": r = int(r) res = 0 for j in range(26): res += min(1, Bit.sub_sum_(l-1, r, j)) print(res)
1
62,726,439,360,384
null
210
210
N=int(input()) S=input() s=[] for i in S: T=ord(i) - ord('A') + 1+N+64 if T<=90: t=T else: t=T-26 s.append(chr(t)) print(*s,sep='')
n = int(input()) s = input() ans = '' for c in s: ans += chr((ord(c) - ord("A") + n) % 26 + ord("A")) print(ans)
1
134,034,848,672,252
null
271
271
def main(): d = int(input()) c = list(map(int,input().split())) s = [list(map(int,input().split())) for _ in range(d)] t = [int(input()) for _ in range(d)] ptn = len(c) last = [0]*ptn res = 0 for i in range(d): sel = t[i] - 1 last[sel] = i+1 mns = 0 for j in range(ptn): mns += c[j] * (i+1 - last[j]) res += s[i][sel] - mns print(res) if __name__ == '__main__': main()
# 入出力から得点を計算する import sys input = lambda: sys.stdin.readline().rstrip() D = int(input()) c = list(map(int, input().split())) s = [[int(i) for i in input().split()] for _ in range(D)] t = [] for i in range(D): tmp = int(input()) t.append(tmp) # 得点 result = 0 # 最後に開催された日を保存しておく last_day = [0 for _ in range(26)] for i in range(len(t)): # 選んだコンテスト choose = t[i] - 1 # 最終開催日を更新 last_day[choose] = i + 1 # そのコンテストを選んだ時の本来のポイント result += s[i][choose] # そこから満足度低下分をマイナス for j in range(26): result -= c[j] * ((i+1) - last_day[j]) # result += tmp_point print(result) # print(c,s,t)
1
9,851,189,012,028
null
114
114
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) K, N = mapint() As = list(mapint()) lis = [] for i in range(1, N): lis.append(As[i]-As[i-1]) lis.append(As[0]+(K-As[-1])) print(K-max(lis))
while True: n, x = map(int, input().split()) if n == x == 0: break cnt = 0 for a in range(1, x // 3): for b in range(a + 1, x // 2): c = x - a - b if b < c <= n: cnt += 1 print(cnt)
0
null
22,270,153,693,682
186
58
S=input() A=[0]*(len(S)+1) for i in range(len(S)): if S[i]=='<': A[i+1]=max(A[i+1],A[i]+1) for i in range(len(S)-1,-1,-1): if S[i]=='>': A[i]=max(A[i],A[i+1]+1) print(sum(A))
a=list(input()) count=1 ans = 0 temp = 0 for i in range(len(a)-1): if a[i] ==a[i+1]: count+=1 else: if a[i]=='<': ans += count*(count+1)//2 temp = count #print('<', count, ans) count = 1 else: ans += count*(count+1)//2 ans -= min(count, temp) #print('>', count, ans) count =1 else: if a[-1]=='<': ans += count*(count+1)//2 else: ans += count*(count+1)//2 ans -= min(count, temp) print(ans)
1
156,630,144,697,600
null
285
285
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def solve(A: int, B: int): for i in range(1000 + 1): if int(i * 0.08) == A and int(i * 0.1) == B: return i return -1 def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int print(f'{solve(A, B)}') if __name__ == '__main__': main()
import math A, B = map(int, input().split()) answer = -1 for x in range(10000): if math.floor(x * 0.08) == A and math.floor(x * 0.10) == B: answer = x break print(answer)
1
56,528,422,939,460
null
203
203
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())) n,k=mp() h=sorted(lmp()) if n<=k: print(0) else: print(sum(h[:n-k]))
N = int(input()) S = input() third = [[[False]*10 for _ in range(10)] for __ in range(10)] second = [[False]*10 for _ in range(10)] first = [False]*10 for s in S: s = int(s) for i in range(10): if first[i]: for j in range(10): if second[i][j]: third[i][j][s] = True second[i][s] = True first[s] = True res = 0 for i in range(10): for j in range(10): for k in range(10): if third[i][j][k]: # print(i, j, k) res += 1 print(res)
0
null
103,691,955,873,662
227
267
n = int(input()) A = list(input().split()) def insertion_sort(l): for i in range(0, len(l) - 1): x = i + 1 while x != 0 and int(l[x][1]) < int(l[x - 1][1]): temp = l[x] l[x] = l[x - 1] l[x - 1] = temp x -= 1 return l def babble_sort(l): for i in range(0, len(l)): for j in reversed(range(i+1, len(l))): b = int(l[j][1]) a = int(l[j - 1][1]) if b < a: t = l[j] l[j] = l[j-1] l[j-1] = t return l def is_stable(a, l): for i in range(0, len(a)): if a[i] != l[i]: return False return True def print_with_space(l): print(' '.join(str(x) for x in l)) B = insertion_sort(A[:]) babbled = babble_sort(A[:]) print_with_space(babbled) if is_stable(B, babbled): print('Stable') else: print('Not stable') def selection_sort(l): for i in range(0, len(l)): minj = i for j in range(i, len(l)): if int(l[j][1]) < int(l[minj][1]): minj = j t = l[i] l[i] = l[minj] l[minj] = t return l selected = selection_sort(A[:]) print_with_space(selected) if is_stable(B, selected): print('Stable') else: print('Not stable')
A,B,C,K = map(int,input().split()) koa = 0 if A<K: koa = A else : koa = K kob = 0 if B<K-koa: kob = B else : kob = K-koa #print (koa) #print (kob) sum = koa+0*kob+(K-(koa+kob))*-1 print (sum)
0
null
10,840,003,005,180
16
148
def repint(n, k): if n % k == 0: return 0 res = abs((n % k) - k) if (n % k) > res: return res return (n % k) n, k = map(int, input().split()) print(repint(n, k))
N, K = list(map(int, input().split())) ans = min(N % K, K - (N % K)) print(ans)
1
39,117,221,115,798
null
180
180
mountains = [int(input()) for i in range(10)] for i in sorted(mountains)[7:10][::-1]: print(i)
a,b,c,d=list(map(int, input("").split())) la=[] lb=[] if a<0 and b>0: la.append(0) la.append(a) la.append(b) if c<0 and d>0: lb.append(0) lb.append(c) lb.append(d) m=a*c for i in la: for j in lb: o=i*j if o>m: m=o print(m)
0
null
1,517,713,579,430
2
77
n=int(input()) li = [0]*(n+5) for i in range(1,n+1): for j in range(i,n+1,i): li[j] += 1 ans = 0 for i in range(1,n+1): ans += i*li[i] print(ans)
l = int(input()) x = l/3 print(x**3)
0
null
28,923,073,648,832
118
191
N = int(input()) count = 0 for A in range(1, N): N_ = (N - 1) // A count += N_ print(count)
x = input().split() i = list(map(int,x)) a = i[0] b = i[1] if a > b: print('a > b') elif a == b: print('a == b') else: print('a < b')
0
null
1,498,940,628,800
73
38
from sys import stdin from collections import defaultdict, Counter N, P = map(int, stdin.readline().split()) S, = stdin.readline().split() ans = 0 # 2 cases if P == 2 or P == 5: digitdiv = [] for i in range(N): if int(S[i]) % P == 0: ans += i + 1 else: # count = Counter() prefix = [] ten = 1 mod = 0 for i in range(N): x = (int(S[N - i - 1])*ten + mod) % P prefix.append(x) count[x] += 1 ten = (ten * 10) % P mod = x prefix.append(0) count[0] += 1 for val in count.values(): ans += val*(val - 1)//2 print (ans)
N,K=map(int,input().split()) A=list(map(int,input().split())) Nlist=[0]*(10**5+1) P=10**9+7 Nlist[1]=1 for i in range(1, 10**5): Nlist[i+1]=(Nlist[i]*(i+1))%P Ninv=[1]*(10**5+1) Ninv[-1]=pow(Nlist[-1], P-2,P) for i in range(0,10**5): Ninv[-1-i-1]=(Ninv[-1-i]*(10**5-i))%P for i in range(N): A[i]=[A[i], i] A.sort() ans=0 for i in range(K-1,N): if A[i][0]>=0: ans+=(A[i][0]*Nlist[i]*Ninv[K-1]*Ninv[i-K+1])%P else: ans+=(A[i][0]*Nlist[i]*Ninv[K-1]*Ninv[i-K+1])%P-P for i in range(0,N-K+1): if A[i][0]>=0: ans-=(A[i][0]*Nlist[N-i-1]*Ninv[K-1]*Ninv[N-i-K])%P else: ans-=(A[i][0]*Nlist[N-i-1]*Ninv[K-1]*Ninv[N-i-K])%P-P print(ans%P)
0
null
77,156,723,018,620
205
242
import sys import math t1, t2 = [int(i) for i in sys.stdin.readline().split()] a1, a2 = [int(i) for i in sys.stdin.readline().split()] b1, b2 = [int(i) for i in sys.stdin.readline().split()] a1 -= b1 a2 -= b2 _sum = a1 * t1 + a2 * t2 if _sum == 0: print("infinity") elif _sum * a1 > 0: print("0") else: cnt = (-a1 * t1) / _sum res = math.ceil(cnt) * 2 - 1 + (cnt % 1 == 0) print(res)
T1, T2 = [int(i) for i in input().split()] A1, A2 = [int(i) for i in input().split()] B1, B2 = [int(i) for i in input().split()] d1 = T1*(A1-B1) d2 = T2*(B2-A2) if d1 == d2: print('infinity') if d1 * (d2 - d1) < 0: print(0) if d1 * (d2 - d1) > 0: if d1 % (d2 - d1) != 0: print(d1 // (d2 - d1) * 2+ 1) else: print(d1 // (d2 - d1) * 2)
1
131,507,560,183,188
null
269
269
listed = [] nmin = 0 nmax = 0 nsum = 0 n = int(input()) if n > 0 and n <= 10000: listed = list(map(int, input().split(maxsplit=n-1))) nmin = listed[0] nmax = listed[0] for i in listed: if i >= -1000000 and i <= 1000000: if nmin > i: nmin = i if nmax < i: nmax = i nsum += i else: pass else: pass print("{0} {1} {2}".format(nmin, nmax, nsum))
input() list=[int(i) for i in input().split()] print(min(list),max(list),sum(list))
1
744,336,430,538
null
48
48
n, m = map(int, input().split()) ans_dict = {} for _ in range(m): p, s = input().split() if p not in ans_dict: ans_dict[p] = [s] else: ans_dict[p].append(s) ac_cnt = 0 wa_cnt = 0 ac_ans = 0 wa_ans = 0 for key in ans_dict.keys(): ac_cnt = ans_dict[key].count('AC') wa_cnt = ans_dict[key].count('WA') if ac_cnt != 0: ac_ans += 1 # その問題の解答一覧で最初にACとなったインデックスを取得 ac_index = ans_dict[key].index('AC') wa_ans += ans_dict[key][:ac_index].count('WA') print(ac_ans, wa_ans)
import bisect, copy, heapq, math, sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) def celi(a,b): return -(-a//b) sys.setrecursionlimit(5000000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n,m=map(int,input().split()) ps=[input().split() for i in range(m)] dic={} anslst=[0]*n for i in range(m): p,s=ps[i] if s=="AC": dic[p]=1 else: if p in dic: continue else: anslst[int(p)-1]+=1 ans=0 for i in dic.keys(): ans+=anslst[int(i)-1] print(len(dic),ans)
1
93,533,955,043,674
null
240
240
N = int(input()) o = (N+1) // 2 e = N // 2 print(o / N)
import math INF=float('inf') ans1='pairwise coprime' ans2='setwise coprime' ans3='not coprime' n=int(input()) A=list(map(int,input().split())) P=[0]*(10**6+1) for i in A: P[i]+=1 pairwise=True for i in range(2,10**6+1): cnt=0 for j in range(i,10**6+1,i): cnt+=P[j] if cnt>1: pairwise=False break if pairwise: print(ans1) exit() g=math.gcd(A[0],A[1]) for i in A: g=math.gcd(g,i) if g==1: print(ans2) else: print(ans3)
0
null
90,781,064,752,484
297
85
s,t = map(str,input().split()) print(t ,end='') print(s)
base = input().split() print(base[1],end="") print(base[0])
1
103,099,344,581,732
null
248
248
from collections import deque k = int(input()) ans=[] # q = deque([[1],[2],[3],[4],[5],[6],[7],[8],[9]]) q = deque([1,2,3,4,5,6,7,8,9]) while q: a = q.popleft() ans.append(a) if len(ans) > k: break tmp = int(str(a)[-1]) if tmp-1 >= 0: q.append(10*a + tmp-1) q.append(10*a + tmp) if tmp+1 <= 9: q.append(10*a + tmp+1) print(ans[k-1])
from collections import Counter N = int(input()) X = list(map(int, input().split())) ctr = Counter(X) ans = 0 for v in ctr.values(): ans += v * (v - 1) // 2 for i in range(N): val = ctr[X[i]] print(ans - val * (val - 1) // 2 + (val - 1) * (val - 2) // 2)
0
null
43,885,138,544,320
181
192
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] time = [0] g = [0 for i in range(n)] def dfs_visit(s): st[s] = 1 time[0] += 1 d[s] = time[0] for k in range(n): if a[s][k] == 1 and st[k] == 0: dfs_visit(k) st[s] ==2 time[0] += 1 f[s] = time[0] def main(): for s in range(n): if st[s] == 0: dfs_visit(s) for s in range(n): print '%d %d %d' %(s+1, d[s], f[s]) for i in range(n): g = map(int, raw_input().split()) for j in range(g[1]): a[g[0]-1][g[2+j]-1] = 1 main()
n = input() d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] color = [0 for i in range(n)] tt = [0] WHITE = 0 GRAY = 1 BLACK = 2 def dfs_visit(u): color[u] = GRAY tt[0] = tt[0] + 1 d[u] = tt[0] for v in range(n): if M[u][v] == 0: continue if color[v] == WHITE: dfs_visit(v) color[u] == BLACK tt[0] = tt[0] + 1 f[u] = tt[0] def dfs(): for u in range(n): if color[u] == WHITE: dfs_visit(u) for u in range(n): print "%d %d %d" %(u + 1, d[u], f[u]) ### MAIN for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): M[G[0]-1][G[2+j]-1] = 1 dfs()
1
2,887,415,242
null
8
8