code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
h , w , m = map(int,input().split()) retu = [0 for i in range(w)] gyo = [0 for i in range(h)] basyo = set() for i in range(m): a , b = map(lambda x:int(x)-1,input().split()) retu[b] += 1 gyo[a] += 1 basyo.add((a,b)) t = max(retu) mare = [i for i, v in enumerate(retu) if v == t] s = max(gyo) magy = [i for i, v in enumerate(gyo) if v == s] for i in magy: for j in mare: if not (i,j) in basyo: print(s+t) exit() print(s+t-1)
from itertools import combinations_with_replacement n, m, q = map(int, input().split()) abcd = [list(map(int, input().split())) for i in range(q)] ans = 0 for i in combinations_with_replacement(range(1, m + 1), n): cnt = 0 for a, b, c, d in abcd: if i[b - 1] - i[a - 1] == c: cnt += d ans = max(ans, cnt) print(ans)
0
null
16,155,145,018,352
89
160
n=int(input()) m=[] M=[] for _ in range(n): x,y=map(int,input().split()) m.append(x) M.append(y) m=sorted(m) M=sorted(M) z=n//2 if n%2==1: a=m[z] b=M[z] print(b-a+1) else: a=m[z]+m[z-1] b=M[z]+M[z-1] print(b-a+1)
import statistics N = int(input()) AB = [map(int, input().split()) for _ in range(N)] A,B = [list(i) for i in zip(*AB)] if N%2 == 1: low_med = statistics.median(A) high_med = statistics.median(B) print(high_med - low_med +1) else: low_med = statistics.median(A) high_med = statistics.median(B) print(int(2 * (high_med - low_med) +1))
1
17,451,833,274,450
null
137
137
moji = input() if moji.isupper() == True: print("A") else: print("a")
def data_input(): D = int(input()) C = tuple(map(int, input().split())) S = [] for i in range(D): s = tuple(map(int, input().split())) S.append(s) return D, C, S def score(D, C, S, T): """入力D, C, Sと出力Tからスコアを計算する関数""" last = [0] * 26 # 0で初期化されている def decrease(d, last): """d日めにiを開催した時の満足度の減少を返す関数""" res = 0 for i in range(26): ith = C[i] * (d+1 - last[i]) res -= ith return res V = [] # V[d]はd日めの満足度を表す for d, i in enumerate(T): if d == 0: v = 0 last[i] = d + 1 v += S[d][i] + decrease(d, last) V.append(v) return V D, C, S = data_input() T = [] for i in range(D): t = int(input()) - 1 T.append(t) V = score(D, C, S, T) for v in V: print(v)
0
null
10,597,416,732,138
119
114
a = input().split() if a[0] == a[1]: print("Yes") else: print("No")
print('YNeos'[eval(input().replace(' ','!='))::2])
1
83,289,868,846,080
null
231
231
l,r,n = map(int,input().split(" ")) count = 0 for i in range(l,r+1): if i % n == 0: count += 1 print(count)
k=int(input()) count=1 num=7 for _ in range(k): if num%k == 0: print(count) break else: count += 1 num = (num % k)*10 + 7 else: print(-1)
0
null
6,892,192,886,684
104
97
a, b = list(map(int, input().split())) if a >= 10: my_result = b else: my_result = b + 100 * (10 - a) print(my_result)
N,P=map(int, input().split()) if N<=9: print(100*(10-N)+P) else: print(P)
1
63,505,296,934,900
null
211
211
input_line = input().rstrip().split() if (input_line[0]==input_line[1]): print("Yes") else: print("No")
def Base_10_to_n(X, n): if int(X/n): return Base_10_to_n(int(X/n), n) + str(X%n) return str(X%n) N, K = map(int, input().split()) print(len(Base_10_to_n(N,K)))
0
null
73,491,833,883,172
231
212
s = list(map(int,input())) s.reverse() t = len(s) mod = 2019 arr = [0] * (t+1) arr[-2] = s[0] for i in range(1,t): arr[t-i-1] = (arr[t-i] + s[i]*pow(10,i,mod)) % mod from collections import Counter arr = Counter(arr) ans = 0 for i in arr: ans += (arr[i] - 1) * arr[i] // 2 print(ans)
from bisect import bisect_right N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort() def calc(m): #m以下の組が何通りあるかを数える count = 0 #組数を数える for a in A: b = m - a #b以上のは含める count += N - bisect_right(A, b - 0.5) return count l = 0 r = 3 * 10 ** 5 while r - l > 1: mid = (l + r) // 2 if calc(mid) >= M: #合計mid以上の組と手を繋ぐとしたとき、とM回以上握手できる l = mid else: r = mid B = [0] * (N + 1) for i in range(N): B[i + 1] = B[i] + A[i] # print(B) flag = False for i in range(mid + 3, -1, -1): if calc(i) < M: flag = False else: #初めて手をにぎる回数がM回を下回ったとき break i += 1 #合計この値までは全て使う、残り回数を調整 ans = 0 for a in A: b = i - a tmp = bisect_right(A, b - 0.5) M -= (N - tmp) #使った数 ans += a * (N - tmp) + (B[-1] - B[tmp]) ans += M * (i - 1) print (ans)
0
null
69,750,179,816,752
166
252
import numpy as np a, b, c, d = map(int, input().split()) x = np.array([a, b]) y = np.array([c, d]) z = np.outer(x, y) print(z.max())
a,b,c,d = map(int,input().split()) val = [None]*4 val = [a*c,a*d,b*c,b*d] top = a*c for i in range(1,4): if top < val[i]: top = val[i] print(top)
1
3,020,822,751,984
null
77
77
N = int(input()) P = list(map(int,input().split())) P_min = [] a = 200000 ans = 0 for i in range(N): if a >= P[i]: ans += 1 a = P[i] print(ans)
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce, lru_cache import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def MAP1() : return map(lambda x:int(x)-1,input().split()) def LIST() : return list(MAP()) def LIST1() : return list(MAP1()) n = INT() k = INT() @lru_cache(None) def F(n, k): # n以下で0でないものがちょうどk個ある数字の個数 if n < 10: if k == 0: return 1 if k == 1: return n return 0 q, r = divmod(n, 10) ret = 0 if k >= 1: ret += F(q, k-1) * r ret += F(q-1, k-1) * (9-r) ret += F(q, k) return ret print(F(n, k))
0
null
80,665,515,618,870
233
224
import sys input = sys.stdin.readline import collections # 持っているビスケットを叩き、1枚増やす # ビスケット A枚を 1円に交換する # 1円をビスケット B枚に交換する def main(): x = int(input()) for a in range(-200, 200): for b in range(-200, 200): ans = a ** 5 - b ** 5 if ans == x: print(a, b) exit() def bi(num, a, b, x): print((a * num) + (b * len(str(b)))) if (a * num) + (b * len(str(b))) <= x: return False return True def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
X = int(input()) for i in range(-120,120): for j in range(-120,120): if i**5 - j**5 == X: print(i,j) exit()
1
25,439,072,406,582
null
156
156
n = int(input()) x, y = [list(map(int, input().split())) for _ in range(2)] print(sum([abs(x[i] - y[i]) for i in range(n)])) print(pow(sum([(x[i] - y[i]) ** 2 for i in range(n)]), 1/2)) print(pow(sum([abs(x[i] - y[i]) ** 3 for i in range(n)]), 1/3)) print(max([abs(x[i] - y[i]) for i in range(n)]))
print(len(max((input().split('S')))))
0
null
2,576,331,505,440
32
90
n = int(input()) num = int(n / 2) if n % 2 == 1: num += 1 print(num)
def main(): n = int(input()) div, mod = divmod(n, 2) if mod != 0: print(div + 1) else: print(div) if __name__ == '__main__': main()
1
58,692,732,004,220
null
206
206
h=int(input()) w=int(input()) n=int(input()) print(-(-n//max(h,w)))
H=int(input()) W=int(input()) N=int(input()) if N%max(H,W)==0: print(N//max(H,W)) else: print(N//max(H,W)+1)
1
88,833,022,093,420
null
236
236
import math r = input() print ("%.5f " "%.5f")% (r*r*math.pi, 2*r*math.pi)
K=int(input()) S=input() if len(S) <= K : print(S) else: print(S[:K]+'...',end='')
0
null
10,144,116,328,544
46
143
N, M = map(int, input().split()) C = [-1] * 3 for i in range(M): s, c = map(int, input().split()) if C[s - 1] == -1: C[s - 1] = c else: if C[s - 1] != c: print(-1) exit() if N == 1 and (M == 0 or (M == 1 and C[0] == 0)): print(0) exit() for i in range(10 ** (N - 1), 10 ** N): si = str(i) flg = True for j in range(N): if C[j] != -1 and si[j] != str(C[j]): flg = False break if flg: print(i) exit() print(-1)
import sys import math import copy from heapq import heappush, heappop, heapify from functools import cmp_to_key from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = float("inf") MOD = 10**9 + 7 divide = lambda x: pow(x, MOD-2, MOD) def solve(): n, t = getList() li = [] for i in range(n): li.append(getList()) li.sort(key=lambda x: 30000 * x[0] + x[1]) dp = [0] * t ans = 0 for a, b in li: tmp = copy.copy(dp) ans = max(ans, dp[-1] + b) for idx, dd in enumerate(dp): # tmp[idx] = max(tmp[idx], dd) if idx + a < t: tmp[idx + a] = max(dp[idx + a], dp[idx] + b) dp = tmp for j in range(len(dp) - 1): dp[j+1] = max(dp[j], dp[j+1]) # print(dp) # print(li) print(ans) def main(): n = getN() for _ in range(n): solve() return if __name__ == "__main__": # main() solve()
0
null
106,571,001,366,688
208
282
while True: n = int(input()) if n == 0: break else: score = [int(x) for x in input().split()] a = 0 m = sum(score)/n for s in score: a += (s-m)**2 a = (a/n)**0.5 print('{:.8f}'.format(a))
a,b,c = map(int,input().split()) if a>= c: print(a-c,b) elif a+b<=c: print("0 0") elif a < c and c < a+b: print("0",a+b-c)
0
null
52,274,972,654,720
31
249
a = int(input()) s = a s = s * a + a s = s * a + a print(s)
# -*- coding: utf-8 -*- a=int(input()) s=a+a**2+a**3 print(s)
1
10,119,319,286,580
null
115
115
from time import time from random import random limit_secs = 2 start_time = time() D = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(D)] def calc_score(t): score = 0 S = 0 last = [-1] * 26 for d in range(len(t)): S += s[d][t[d]] last[t[d]] = d for i in range(26): S -= c[i] * (d - last[i]) score += max(10 ** 6 + S, 0) return score def solution1(): return [i % 26 for i in range(D)] def solution2(): t = None score = -1 for i in range(26): nt = [(i + j) % 26 for j in range(D)] if calc_score(nt) > score: t = nt return t def solution3(): t = [] for _ in range(D): score = -1 best = -1 t.append(0) for i in range(26): t[-1] = i new_score = calc_score(t) if new_score > score: best = i score = new_score t[-1] = best return t def optimize0(t): return t def optimize1(t): score = calc_score(t) while time() - start_time + 0.15 < limit_secs: d = int(random() * D) q = int(random() * 26) old = t[d] t[d] = q new_score = calc_score(t) if new_score < score: t[d] = old else: score = new_score return t t = solution3() t = optimize0(t) print('\n'.join(str(e + 1) for e in t))
from copy import copy import random import math import sys input = sys.stdin.readline D = int(input()) c = list(map(int,input().split())) s = [list(map(int,input().split())) for _ in range(D)] last = [0]*26 ans = [0]*D score = 0 for i in range(D): ps = [0]*26 for j in range(26): pl = copy(last) pl[j] = i+1 ps[j] += s[i][j] for k in range(26): ps[j] -= c[k]*(i+1-pl[k]) idx = ps.index(max(ps)) last[idx] = i+1 ans[i] = idx+1 score += max(ps) for k in range(1,40001): na = copy(ans) x = random.randint(1,365) y = random.randint(1,365) na[x-1] = na[y-1] last = [0]*26 ns = 0 for i in range(D): last[na[i]-1] = i+1 ns += s[i][na[i]-1] for j in range(26): ns -= c[j]*(i+1-last[j]) if k%100 == 1: T = 80-(79*k/40000) p = pow(math.e,-abs(ns-score)/T) if ns > score or random.random() < p: ans = na score = ns for a in ans: print(a)
1
9,707,044,710,494
null
113
113
s = input() t = input() ans = 1001001001 for i in range(len(s) - len(t) + 1): cnt = 0 for j in range(len(t)): if s[i + j] != t[j]: cnt += 1 if cnt <= ans: ans = cnt print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *A=map(int,read().split()) bound = [0]*(N+1) bound[0] = 1 #Nが0のとき if N == 0: if A[0] == 1: print(1) else: print(-1) sys.exit() #Nが0以外のとき #上から for i in range(1,N+1): bound[i] = (bound[i-1]-A[i-1]) *2 if bound[i] < A[i]: print(-1) sys.exit() #下からのと最小値を取る cum_sum = 0 for i in range(N,-1,-1): cum_sum += A[i] bound[i] = min(bound[i],cum_sum) print(sum(bound))
0
null
11,214,736,744,872
82
141
N, K = map(int,input().split()) P = [int(x)-1 for x in input().split()] C = [int(x) for x in input().split()] def loop(s): value = 0 done = set() while s not in done: done.add(s) s = P[s] value += C[s] return len(done), value def f(s,K): ans = -10**18 total = 0 done = set() while s not in done: done.add(s) s = P[s] total += C[s] ans = max(ans,total) K -= 1 if K==0: return ans lamb, value = loop(s) if K > 2*lamb: if value > 0: K -= lamb total += (K//lamb)*value ans = max(ans,total) K -= (K//lamb)*lamb K += lamb if value <= 0: K = min(K,lamb+5) while K > 0: s = P[s] total += C[s] ans = max(ans,total) K -= 1 return ans print(max([f(s,K) for s in range(N)]))
l = list(input()) h = [0] for i in range(len(l)): if l[i] == "\\": h.append(h[i]-1) elif l[i] == "/": h.append(h[i]+1) else: h.append(h[i]) A = 0 k = 0 L = [] i = 0 if "".join(l[5:65]) + (" ") == "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ " and "".join(l[1:61]) + (" ") != "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ " : print("1"+"\n"+ "1" + " " + "1") else: while i in range(len(l)): if l[i] == "\\" and h[i] <= max(h[i+1:len(l)+2]): s = 0 a = h[i] s += 0.5 i += 1 while h[i] < a: s += a - (h[i] + h[i+1])*0.5 i += 1 A += int(s) k += 1 L.append(int(s)) else: i += 1 print(A) print(k,end="") if len(L) >0: print(" ",end="") print(" ".join(map(str, L))) else: print("")
0
null
2,692,205,066,630
93
21
n = int(input()) ans = [] def dfs(A): if len(A) == n: ans.append(''.join(A)) return for i in range(len(set(A))+1): v = chr(i+ord('a')) A.append(v) dfs(A) A.pop() dfs([]) ans.sort() for i in range(len(ans)): print(ans[i])
K,N=map(int,input().split()) A=[int(x) for x in input().split()] A+=[K+A[0]] print(K-max(A[i+1]-A[i] for i in range(N)))
0
null
47,945,219,294,160
198
186
def func(x): return x + x**2 + x**3 if __name__=="__main__": input = input() print(func(int(input)))
import math import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") a = I() ans = a * (1+a+a**2) print(ans)
1
10,225,790,847,840
null
115
115
def main(): N = int(input()) A = list(map(int,input().split())) list_a = [0]*N for i in range(len(A)): list_a[A[i]-1] += 1 for i in range(N): print(list_a[i]) main()
n = int(input()) a = list(map(int, input().split())) number_buka = [0]*n for i in a: number_buka[i-1] += 1 for j in number_buka: print(j)
1
32,752,846,989,658
null
169
169
t = input() h = t / 3600 t %= 3600 m = t / 60 s = t % 60 print str(h) + ":" + str(m) + ":" + str(s)
import sys readline = sys.stdin.readline N = int(readline()) ans = 0 for a in list(map(int,readline().split()))[::2]: ans += (a & 1) print(ans)
0
null
4,079,617,413,258
37
105
S = list(input()) if S.count('A') == 3 or S.count('A') == 0: print('No') else: print('Yes')
s = input() for _ in range(int(input())): c = input().split() a = int(c[1]) b = int(c[2]) if c[0] == "replace": s = s[:a] + c[3] + s[b+1:] elif c[0] == "reverse": s = s[:a] + s[a:b+1][::-1] + s[b+1:] else: print(s[a:b+1])
0
null
28,442,299,534,280
201
68
a, b, c, d = map(int, input().split()) ac = a * c ad = a * d bc = b * c bd = b * d ans_1 = max(ac,ad) ans_2 = max(bc, bd) ans = max(ans_1, ans_2) print(ans)
N = int(input()) A = list(map(int, input().split())) count = 0 now = 1 for i in range(len(A)): if A[i] == now: now += 1 else: count += 1 print(count if now != 1 else -1)
0
null
58,877,800,894,016
77
257
import re import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def v(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 6) mod = 10**9+7 cnt = 0 ans = 0 inf = float("inf") al = "abcdefghijklmnopqrstuvwxyz" AL = al.upper() n = k() if n%2==1: print(0) else: for i in range(1,n): if n>=2*(5**i): cnt += n//(2*(5**i)) else: break print(cnt)
n = int(input()) if n % 2 == 1: print(0) elif n % 2 == 0: ans = 0 k = 10 while n >= k: ans += n//k k *= 5 print(ans)
1
116,272,372,364,430
null
258
258
import math a,b,h,m=map(int, input().split()) a_x=math.cos(abs(math.radians(6*m)-math.radians(30*h+0.5*m))) print((a**2+b**2-2*a*b*a_x)**0.5)
import math def solve(): a,b,h,m=map(int,input().split()) sita=math.pi*2*((h+m/60)/12-m/60) c=math.sqrt(a*a+b*b-2*a*b*math.cos(sita)) return c print(solve())
1
20,057,579,457,490
null
144
144
a = int(input()) b = int(input()) ans = 0 if a == 1: if b == 2: ans = 3 else: ans = 2 elif a == 2: if b == 1: ans = 3 else: ans = 1 else: if b == 1: ans = 2 else: ans = 1 print(ans)
a = list(map(int, input().split())) HP = a[0] x = [] for i in range(a[1]): x1, y1 = [int(i) for i in input().split()] x.append((x1, y1)) max_tup = max(x, key=lambda x: x[0]) #最高攻撃力の呪文を記憶 max_a = max_tup[0] #その攻撃力を記録 #1次元 横:与えるダメージ 中身:最小魔力 dp = [10**10] * (HP + max_a) #DP表はHP+最高攻撃力 dp[0] = 0 for i in range(1, len(dp)): for a, b in x: if i >= a: dp[i] = min(dp[i],dp[i - a] + b ) print(min(dp[HP:]))
0
null
95,858,190,640,758
254
229
#!/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() num = 0 for i in range(N): a, b = MI() if a == b: num += 1 if num == 3: print("Yes") return else: num = 0 print("No") main()
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_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(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() D = [len(set(LIST()))==1 for _ in range(N)] for i in range(N): if sum(D[i:i+3]) == 3: print("Yes") break else: print("No")
1
2,469,525,265,728
null
72
72
S = input() T = input() N = len(S) if len(T) == N+1: Ts = T[:N] if Ts == S: print('Yes') else: print('No') else: print('No')
def check(a,b,c): if a==b or a==c or b==c: return False if a+b>c and b+c>a and c+a>b: return True return False n=int(input()) c=list(map(int,input().split())) count=0 for i in range(len(c)-2): for j in range(i+1,len(c)-1): for k in range(j+1,len(c)): if check(c[i],c[j],c[k]): count+=1 print(count)
0
null
13,311,429,097,418
147
91
from collections import Counter n = int(input()) a = list(map(int, input().split())) q = int(input()) counter = Counter(a) sum_res = sum(a) # はじめの合計、名前がsumだとsum関数とかぶってよくないので # q回操作します。ループ変数は使わないので_とします(Pythonの慣習) for _ in range(q): before, after = map(int, input().split()) # 合計を変更します sum_res -= before * counter[before] sum_res += after * counter[before] # 個数を変更します counter[after] += counter[before] counter[before] = 0 print(sum_res)
#coding:utf-8 ''' a ÷ b : d (整数) a ÷ b の余り : r (整数) a ÷ b : f (浮動小数点数) ''' a, b = map(int, input().split()) d = a // b r = a % b f = a / b print('%d %d %.8f' % (d, r, f))
0
null
6,389,333,127,228
122
45
[a,b,c]=raw_input().split() x=int(a) y=int(b) z=int(c) ans=[] for n in range(x,y+1): if z%n==0: ans.append(n) print len(ans)
N=int(input()) A=list(map(int,input().split())) A.sort(reverse=True) if N%2==0: x=A[0] x+=sum(A[1:N//2])*2 print(x) else: x=A[0] x+=sum(A[1:(N-1)//2])*2 x+=A[(N-1)//2] print(x)
0
null
4,833,391,262,492
44
111
N,K=map(int, input().split()) if K>=N: print(min(N, K-N)) else: res = N % K print(min(res, K-res))
N,K=map(int,input().split()) a=N%K b=abs(N%K-K) print(min(a,b))
1
39,431,845,071,030
null
180
180
import itertools import decimal import math import collections import sys input = sys.stdin.readline T=input() T=T.replace('?','D') print(T)
import sys input = sys.stdin.readline t = input() t_update = "" for i in t: if i == "?": i = "D" t_update += i print(t_update)
1
18,445,412,726,788
null
140
140
h, w, k = map(int, input().split()) tbl = [input() for _ in range(h)] # ビット全探索で全パターンをチェック # n個のものからいくつか選ぶ組み合わせの数は 2**n # 例えば、3個の場合は 2**3 = 8通り # 0: 0b000 # 1: 0b001 # 2: 0b010 # 3: 0b011 # 4: 0b100 # 5: 0b101 # 6: 0b110 # 7: 0b111 # バイナリの 0 は選ばれている、1 は選ばれていない # https://drken1215.hatenablog.com/entry/2019/12/14/171657 ans = 0 for i in range(2**h): for j in range(2**w): ct = 0 for ii in range(h): for jj in range(w): # 塗りつぶされない黒をカウントする # カウントした結果が残った数と同じであれば、回答に+1 if (i>>ii)&1 == 0 and (j>>jj)&1 == 0: if tbl[ii][jj] == '#': ct += 1 if ct == k: ans += 1 print(ans)
l = input().split() a = int(l[0]) b = int(l[1]) c = int(l[2]) d = [] for i in range(a,b+1): if c % i == 0: d.append(i) print(len(d))
0
null
4,702,675,962,610
110
44
N, K = map(int, input().split()) Have = set([]) for _ in range(K): _ = input() Have |= set(map(int, input().split())) print(N-len(Have))
a = input() print("Yes" if (a[2] == a[3]) and (a[4] == a[5]) else "No")
0
null
33,178,911,096,682
154
184
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, t = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(n)] AB.sort() res = 0 dp = [[0] * (t + 1) for _ in range(n + 1)] for i in range(1, n + 1): a, b = AB[i - 1] for j in range(1, t + 1): if j - a >= 0: dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a] + b) else: dp[i][j] = dp[i - 1][j] for k in range(i, n): _, b = AB[k] res = max(res, dp[i][j - 1] + b) print(res) if __name__ == '__main__': resolve()
from sys import stdout printn = lambda x: stdout.write(str(x)) inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True and False BIG = 999999999 R = 10**9 + 7 def ddprint(x): if DBG: print(x) n,t = inm() ab = [] for i in range(n): aa,bb = inm() ab.append((aa,-bb)) ab.sort() d = [ [-1]*(t+1) for i in range(n+1) ] for i in range(n+1): d[i][0] = 0 #ddprint(d) for i in range(n): for j in range(t+1): d[i+1][j] = max(d[i+1][j], d[i][j]) if j<t and d[i][j]>=0: s = min(t,j+ab[i][0]) d[i+1][s] = max(d[i+1][s], d[i][j]-ab[i][1]) if DBG: for i in range(n): printn(i) ddprint(d[i]) mx = 0 for j in range(t,-1,-1): if d[n][j]>=0: mx = max(mx,d[n][j]) print(mx)
1
151,728,532,890,402
null
282
282
import math import sys sys.setrecursionlimit(10**9) MOD = 10**9+7 n, k = map(int, input().split()) k = min(k, n-1) fact = [1] for i in range(1, 10**6): fact.append((fact[i-1]*i)%MOD) inv = [None]*10**6 def inv_fact(n): if inv[n] == None: inv[n] = pow(fact[n], MOD-2, MOD) return inv[n] def comb(n, r): return (fact[n]*inv_fact(n-r)*inv_fact(r))%MOD ans = 0 for i in range(k+1): ans = (ans + comb(n-1, i)*comb(n, i))%MOD print(ans)
n,d=map(int,input().split()) print(sum(eval("(("+input().replace(" ",")**2+(")+")**2)")**0.5<=d for _ in range(n)))
0
null
36,390,830,251,788
215
96
from collections import Counter s = list(input()) k = int(input()) ans = 0 s_d = s*2 for i in range(1,len(s_d)): if s_d[i-1]==s_d[i]: s_d[i] = '_' if i>=len(s_d)//2: ans+=k-1 else: ans+=1 s_s = set(s) if len(s_s)==1 and len(s)%2!=0: ans = len(s)*(k//2)+(k%2==1)*(len(s)//2) print(ans)
s = input() k = int(input()) from itertools import groupby n=len(s) cnt =0 gp = groupby(s) Keys=[] values=[] for key,value in gp: Keys.append(key) values.append(len(list(value))) if len(Keys)==1: print(values[0]*k//2) exit(0) if k==1: for i in values: cnt+=i//2 print(cnt) exit(0) if k>=2: if Keys[0]==Keys[-1]: values2=list(reversed(values)) m=len(values) for i in range(m-1): if values[i]>=2: cnt+=values[i]//2 if values2[i]>=2: cnt+=values2[i]//2 cnt+= (k-1) * ((values[0]+values[-1])//2) for j in range(m): if j==0 or j==m-1: continue else: cnt+= (k-2)*(values[j]//2) print(cnt) exit(0) for i in values: if i>1: cnt += k*(i//2) print(cnt)
1
175,506,729,611,420
null
296
296
import math a,b,x=map(int,input().split()) c=b-(x/(a*a)) k=math.sqrt(c**2+(a*a/4)) if x<=a*a*b/2: o=(x*2/b)/a k=math.sqrt(o**2+b*b) print(math.degrees(math.acos(o/k))) else: print(math.degrees(math.acos(a/(2*k))))
import math a,b,x = map(int, input().split()) x /= a if 2* x > a * b: temp = 2*(a*b - x)/(a**2) else: temp = b**2/(2*x) print(math.degrees(math.atan(temp)))
1
162,860,950,530,432
null
289
289
n,k = map(int, input().split()) WL = [int(input()) for i in range(n)] #P????????°??¨??????????????¬??§??????Wi????????°?????????????????¢??° def howmany(P): ans = 0 truck = 1 i = 0 while truck <= k and i <= n-1: rp = P while rp >= WL[i]: ans += 1 rp -= WL[i] i += 1 if i == n: break truck += 1 return ans low = 0 high = 100000 * 100000 # n * k????????§??? while low != high: mid = (low + high) // 2 if howmany(mid) == n: high = mid else: low = mid + 1 print(str(low))
s1 = '' try: while True: t = input() if t == '': break s1 += t except EOFError: pass n = [0] * 26 s = s1.lower() for i in range(len(s)): j = ord(s[i]) - 97 if j >= 0 and j < 26: n[j] += 1 for i in range(26): print('%s : %d' %(chr(i + 97),n[i]))
0
null
885,188,073,220
24
63
def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) n, m = map(int, input().split()) a = list(map(int, input().split())) l = a[0] // 2 for i in range(n): a[i] //= 2 l = lcm(l, a[i]) c = 0 while True: for i in range(n): if a[i] % 2 == 1: c += 1 else: a[i] //= 2 if not c == 0: break print(((m // l) + 1) // 2 if c == n else 0)
n = input() x = map(int, input().split()) y = map(int, input().split()) x_y = [abs(xi - yi) for xi, yi in zip(x, y)] for p in range(1, 4): print(sum(i ** p for i in x_y) ** (1 / p)) print(max(x_y))
0
null
51,209,078,343,500
247
32
n, k = map(int, input().split()) pp = list(map(int, input().split())) p = [pp[i]-1 for i in range(n)] c = list(map(int, input().split())) ans = -(10**9+1) for i in range(n): s = 0 x = i for j in range(k): x = p[x] s += c[x] ans = max(ans,s) if i == x: break a = int(k/(j+1)) m = k%(j+1) if m == 0 and a > 1: m = j+1 a -= 1 s *= a ans = max(ans,s) for l in range(m): x = p[x] s += c[x] ans = max(ans, s) print (ans)
import sys input = sys.stdin.readline N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) ans = -10**18 for i in range(N): now = i visit = [False]*N visit[now] = True l = [] while True: nex = P[now]-1 l.append(C[nex]) if visit[nex]: break visit[nex] = True now = nex s = sum(l) acc = 0 for j in range(min(K, len(l))): acc += l[j] ans = max(ans, acc+max(0, (K-j-1)//len(l)*s)) print(ans)
1
5,430,087,542,018
null
93
93
h, a = map(int, input().split()) i = 0 while a*i < h: i = i + 1 print(int(i))
# coding: utf-8 # Here your code ! n=int(input()) A=[int(i) for i in input().split()] q=int(input()) m=[int(i) for i in input().split()] from itertools import combinations x=[] for i in range(len(A)): t=(list(combinations(A,i))) x.append(t) combi=set() for i in x: for j in i: combi.add(sum(j)) for i in m: if i in combi: print("yes") else: print("no")
0
null
38,572,620,239,488
225
25
n = raw_input() a = n.split(" ") b = int(a[0]) c = int(a[1]) print b*c ,(b+c)*2
import sys a, b = [ int( val ) for val in sys.stdin.readline().split( " " ) ] print( "{} {}".format( a*b, a*2+b*2 ) )
1
312,424,143,008
null
36
36
import sys import fractions input = sys.stdin.readline mod = 10 ** 9 + 7 N = int(input().strip()) A = list(map(int, input().strip().split(" "))) lcm = 1 for a in A: lcm = a // fractions.gcd(a, lcm) * lcm ans = 0 for a in A: ans += lcm // a print(ans % mod)
from functools import reduce from fractions import gcd from collections import defaultdict,Counter import copy n = int(input()) a = list(map(int,input().split())) mod = 10**9+7 dic = defaultdict(int) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a for i in a: c = Counter(prime_factorize(i)) for j,k in c.items(): if dic[j] < k: dic[j] = k l = 1 for i,j in dic.items(): l *= pow(i,j,mod) l %= mod point = 0 for i in a: point += l*pow(i,mod-2,mod) point %= mod print(point%mod)
1
87,835,992,579,120
null
235
235
import sys, bisect, math, itertools, string, queue, copy #import numpy as np #import scipy from collections import Counter,defaultdict,deque # from itertools import permutations, combinations # from heapq import heappop, heappush # from fractions import gcd # input = sys.stdin.readline # sys.setrecursionlimit(10**8) # mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) s = input() q = int(input()) ql = [input().split() for i in range(q)] ans = deque(s) isrev=False for i in range(q): if ql[i][0] == '1': isrev = not isrev continue if (ql[i][1] == '2') == isrev: ans.appendleft(ql[i][2]) else: ans.append(ql[i][2]) if isrev: ans.reverse() s = ''.join(ans) print(s)
import statistics def stddev(values): """ calculate standard deviation >>> s = stddev([70, 80, 100, 90, 20]) >>> print('{:.5f}'.format(s)) 27.85678 >>> s = stddev([80, 80, 80]) >>> print('{:.5f}'.format(s)) 0.00000 """ return statistics.pstdev(values) def run(): while True: c = int(input()) # flake8: noqa if c == 0: break values = [int(i) for i in input().split()] print(stddev(values)) if __name__ == '__main__': run()
0
null
28,927,094,074,768
204
31
class Stack: def __init__(self): self.values = [] self.n = 0 def pop(self): if self.n == 0: raise Exception("stack underflow") else: v = self.values[-1] del self.values[-1] self.n -= 1 return v def push(self,x): self.values.append(x) self.n += 1 operators = set(['+', '-', '*']) stack = Stack() for op in raw_input().split(' '): if op in operators: b = stack.pop() a = stack.pop() if op == '+': stack.push(a+b) elif op == '-': stack.push(a-b) elif op == '*': stack.push(a*b) else: raise Exception("Unkown operator") else: stack.push(int(op)) print stack.pop()
ops = [op for op in input().split(" ")] stack = [] for op in ops: if op == "+": stack = stack[:-2]+[stack[-2]+stack[-1]] elif op == "-": stack = stack[:-2]+[stack[-2]-stack[-1]] elif op == "*": stack = stack[:-2]+[stack[-2]*stack[-1]] else: stack.append(int(op)) print(stack[0])
1
36,625,936,028
null
18
18
# encoding: utf-8 import sys __input = sys.stdin.readlines() length_1 = int(__input[0]) array_1 = list(map(int, __input[1].split())) length_2 = int(__input[2]) array_2 = list(map(int, __input[3].split())) record = [False] * 2000 def solution(): # print(length_1, array_1, length_2, array_2) assert length_1 == len(array_1) and length_2 == len(array_2) for i in array_1: # record[i] = True for j in range(2000 - i, 0, -1): if record[j]: # print(j, i + j) record[i + j] = True record[i] = True for index in array_2: if record[index]: print("yes") else: print("no") if __name__ == '__main__': solution()
import numpy as np N = int(input()) A = np.array(list(map(int, input().split()))) A_cs = A.cumsum() A_cs = A_cs - A_cs[-1]/2 div = np.abs(A_cs).argmin() print(abs(A[:div+1].sum() - A[div+1:].sum()))
0
null
71,089,515,336,674
25
276
while True: string = input() if string == "-": break times = int(input()) for i in range(times): cut=int(input()) string = string[cut:]+string[:cut] print(string)
# coding: utf-8 output = [] # ?????????????????? while (1): texts = input().strip() if (texts == '-'): break # ?????£??????????????° m = int(input()) # ?????£??????????????°?????????????????? for i in range(m): h = int(input()) temp_texts = texts[:h] new_texts = texts[h:] + temp_texts texts = new_texts output.append(texts) for i in output: print(i)
1
1,924,188,875,648
null
66
66
# Union-Find def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] def unite(x, y): x = find(x) y = find(y) if x == y: return False if par[x] > par[y]: x, y = y, x par[x] += par[y] par[y] = x return True def same(x, y): return find(x) == find(y) def size(x): return -par[find(x)] N, M, K = map(int, input().split()) Friend = [[] for _ in range(N)] par = [-1] * N for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 unite(a, b) Friend[a].append(b) Friend[b].append(a) Block = [[] for _ in range(N)] for i in range(K): c, d = map(int, input().split()) c -= 1 d -= 1 Block[c].append(d) Block[d].append(c) Ans = [] for i in range(N): ans = size(i) - 1 ans -= len(Friend[i]) for b in Block[i]: if same(i, b): ans -= 1 Ans.append(str(ans)) print(' '.join(Ans))
S = [i for i in input()] print('Yes' if S[2] == S[3] and S[4] == S[5] else 'No')
0
null
52,095,306,466,184
209
184
#!/usr/bin/env python # encoding: utf-8 import sys class Solution: def __init__(self): self.count = 0 def shell_sort(self): array_length = int(input()) # array = [] # array_length = 10 # array = [15, 12, 8, 9, 3, 2, 7, 2, 11, 1] array = list(map(int, sys.stdin.readlines())) G = [1] while True: g = G[0] * 3 + 1 if g > array_length: break G.insert(0, g) g_length = len(G) result = [] for j in range(g_length): result = self.insertion_sort(array=array, array_length=array_length, g=G[j]) # print(result, 'r', G[j]) print(g_length) print(" ".join(map(str, G))) print(self.count) for k in range(array_length): print(result[k]) def insertion_sort(self, array, array_length, g): # write your code here for i in range(g, array_length): v = array[i] j = i - g while j >= 0 and array[j] > v: array[j + g] = array[j] j -= g self.count += 1 array[j + g] = v # print(" ".join(map(str, array))) return array if __name__ == '__main__': solution = Solution() solution.shell_sort()
n, m = map(int, input().split()) s = input() if "1" * m in s: print(-1) exit() pos = n ans = [] while pos > 0: prev = max(pos - m, 0) while s[prev] == "1": prev += 1 ans.append(pos - prev) pos = prev ans = ans[::-1] print(*ans)
0
null
69,822,439,830,448
17
274
num = int(input()) A = list(map(int, input().split(' '))) def intersection(A,N): for i in range(len(A)): #output if i==len(A)-1: print(A[i]) else: print(A[i], end=' ') for i in range(1,N): v = A[i] j = i-1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v for i in range(len(A)): if i == len(A) - 1: #output print(A[i]) else: print(A[i], end=' ') intersection(A,num)
int(input()) x=map(int,raw_input().split()) print min(x),max(x),sum(x)
0
null
365,440,789,632
10
48
#dp #dp[T] T分での最大幸福 幸福度B、時間A N,T = map(int,input().split()) li = [list(map(int,input().split())) for _ in range(N)] li = sorted(li,key=lambda x: x[0]) dp = [0]*T counter = 0 for i in range(N-1): A,B = li[i] counter = max(counter,max(dp)+B) if A>T-1: continue for t in range(T-A-1,-1,-1): dp[t+A]=max(dp[t]+B,dp[t+A]) print(max(max(dp)+li[N-1][1],counter))
from subprocess import* call(('pypy3','-c',""" n,t=[int(j) for j in input().split()] ab=[] ans=[] dp=[0]*t for i in range(n): tmp=[int(j) for j in input().split()] ab.append(tmp) ab.sort() for a,b in ab: for i in range(t)[::-1]: if dp[i]!=0 or i==0: if i+a>=t: ans.append(dp[i]+b) else: dp[i+a]=max(dp[i+a],dp[i]+b) if ans: print(max(ans)) else: print(max(dp)) """))
1
152,245,260,366,660
null
282
282
N = int(input()) A = list(map(int, input().split())) mod = 10 ** 9 + 7 ans = 0 for i in range(60): ones = 0 for a in A: # 数列Aの全要素の(二進法表記の)i桁目の1の数を集計する if a & (1 << i): ones += 1 # Aの要素から任意の2つを選んで排他的論理和をとってできた数列をBとすると、 # 数列Bの全要素のi桁目の合計は、(Aのi桁目の1の数)*(0の数)となる # 選んだ2つのAの要素が(0,1)の組み合わせになっている場合(XOR)だけに、Bの桁を構成する要素になるため ans = (ans + ones * (N - ones) * (1 << i)) % mod print(ans)
from sys import setrecursionlimit, exit setrecursionlimit(1000000000) def main(): n = int(input()) ans = 0 for i in range(1, n + 1): s = str(i) if s[-1] == '0': continue if s[0] == s[-1]: ans += 1 if i < 10: continue if s[0] == s[-1]: ans += 2 l = len(s) for i in range(2, l): ans += 10 ** (i - 2) * 2 if s[0] < s[-1]: continue if s[0] > s[-1]: ans += 10 ** (l - 2) * 2 elif l > 2: dp = int(s[1]) for i in range(2, l - 1): dp *= 10 dp += int(s[i]) ans += dp * 2 print(ans) main()
0
null
105,360,915,573,462
263
234
def main(): t = input() ans = '' for c in t: if c == '?': ans += 'D' else: ans += c print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline S=tuple(input().strip()) N=len(S)+1 sets = [] count = 0 for c in S: d = 1 if c == '<' else -1 if count * d < 0: sets.append(count) count = d else: count += d sets.append(count) sum = 0 for i in range(len(sets)): k=sets[i] if k > 0: sum += (k*(k+1))//2 else: sum += (k*(k-1))//2 if i > 0: sum -= min(sets[i-1], -k) print(sum)
0
null
87,151,735,286,980
140
285
# usr/bin/python # coding: utf-8 ################################################################################ #Write a program which prints multiplication tables in the following format: # #1x1=1 #1x2=2 #. #. #9x8=72 #9x9=81 # ################################################################################ if __name__ == "__main__": for i in range(1, 10): for j in range(1, 10): print("{0}x{1}={2}".format(i,j,i*j)) exit(0)
h, w = map(int, input().split()) print(1) if h == 1 or w == 1 else print((h * w) // 2 + (w * h) % 2)
0
null
25,373,309,152,668
1
196
inp=input().split() n=int(inp[0]) m=int(inp[1]) arr=[] pares=0 impares=0 count=1 nums=0 def binary(arr, menor, mayor, x): if mayor >= menor: med = (mayor + menor) // 2 if arr[med] == x: return med elif arr[med] > x: return binary(arr, menor, med - 1, x) else: return binary(arr, med + 1, mayor, x) else: return -1 while len(arr)<(m+n): if count%2==0 and pares<n: arr.append(count) pares+=1 elif count%2!=0 and impares<m: arr.append(count) impares+=1 count+=1 sums=[] for x in arr: for y in arr: if(x+y)%2==0 and binary(sums, 0, len(sums)-1, [y,x])==-1 and x!=y: sums.append([x,y]) nums+=1 print(nums)
N,M = map(int,input().split()) if N>=2: gyu = N*(N-1)//2 else: gyu = 0 if M>=2: ki = M*(M-1)//2 else: ki = 0 print(gyu+ki)
1
45,438,887,135,770
null
189
189
def gcd(a, b): a, b = max(a, b), min(a, b) if b == 0: return a return gcd(b, a % b) def main(): X = int(input()) ans = 360 // gcd(X, 360) print(ans) if __name__ == "__main__": main()
a = int(input()) n = 1 while True: if a*n % 360 == 0: break else: n += 1 print(n)
1
13,126,759,033,092
null
125
125
def print0(): print(0) exit() n = int(input()) d = list(map(int, input().split())) mod = 998244353 ans = 1 maxd = max(d) numcnt = [0] * (maxd + 1) for i in d: numcnt[i] += 1 if not d[0] == 0 or not numcnt[0] == 1: print0() for i in range(1, maxd + 1): if numcnt[i] == 0: print0() ans *= pow(numcnt[i - 1], numcnt[i], mod) ans %= mod print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) Ds = list(mapint()) mod = 998244353 from collections import Counter c = Counter(Ds) if Ds[0]!=0: print(0) elif c[0]>1: print(0) else: ans = 1 for i in range(1, N): ans *= pow(c[i-1], c[i], mod) ans %= mod print(ans)
1
154,633,972,982,490
null
284
284
n = int(input()) a = [int(i) for i in input().split()] new_a = set(a) if len(new_a) != n: print("NO") else: print("YES")
N = int(input()) A = list(map(int, input().split())) A = sorted(A) count = 0 for i in range(N-1): if A[i] == A[i+1]: count += 1 i += 1 if count > 0: print('NO') if count == 0: print('YES')
1
73,842,801,816,228
null
222
222
a = int(input()) res = 0 for i in range(a+1): if i % 3 ==0 or i % 5 ==0: pass else: res += i print(res)
n = int(input()) sum = 0 for i in range(n + 1): if i % 3 != 0 and i % 5 != 0 and i % 15 != 0: sum += i print(sum)
1
34,675,591,346,932
null
173
173
K, N = [int(a) for a in input().split()] A = [int(a) for a in input().split()] max_diff = 0 dsum = 0 for i in range(len(A)): if i < len(A)-1: diff = A[i+1] - A[i] else: diff = K - A[i] + A[0] dsum += diff if diff > max_diff: max_diff = diff ans = dsum - max_diff print(ans)
K, N = [int(i) for i in input().split()] A = [int(i) for i in input().split()] A.append(A[0]+K) res = [] for i in range(N): res.append(abs(A[i]-A[i+1])) print(K - max(res))
1
43,533,474,444,420
null
186
186
N,K = map(int,input().split()) cc = list(map(int,input().split())) memo = [] aa = ['.']*N a = 1 while aa[a-1] == '.': memo.append(a) aa[a-1] = 'v' a = cc[a-1] if len(memo)>K: print(memo[K]) else: b = memo.index(a) m = len(memo)-b mm = (K-b) % m del memo[:b] print(memo[mm])
def is_prime(x): if x == 2: return True if (x < 2) or (x%2 == 0): return False return all(x%i for i in xrange(3, int(x**(0.5) + 1), 2)) N = input() print sum(is_prime(input()) for i in range(N))
0
null
11,291,420,337,162
150
12
def insertion_sort(A, N): for i in range(N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v print(' '.join(map(str, A))) def main(): N = int(input().rstrip()) A = list(map(int, input().rstrip().split())) insertion_sort(A, N) if __name__ == '__main__': main()
def main(): N = int(input()) A = list(map(int, input().split(' '))) insertion_sort(A, N) def insertion_sort(A, N): print(' '.join([str(n) for n in A])) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(' '.join([str(n) for n in A])) return A if __name__ == '__main__': main()
1
6,275,793,216
null
10
10
n = int(input()) rate = 600 rank = 8 while True: if n < rate: print(rank) break rate += 200 rank -= 1
x = int(input()) if 400 <= x and x <= 599: ans = 8 elif 600 <= x and x <= 799: ans = 7 elif 800 <= x and x <= 999: ans = 6 elif 1000 <= x and x <= 1199: ans = 5 elif 1200 <= x and x <= 1399: ans = 4 elif 1400 <= x and x <= 1599: ans = 3 elif 1600 <= x and x <= 1799: ans = 2 else: ans = 1 print(ans)
1
6,706,931,729,728
null
100
100
N = int(input()) L = [x * y for x in range(1, 10) for y in range(1, 10)] if L.count(N) != 0: print("Yes") else: print("No")
n=int(input()) t=0 flag=False for i in range(1,10): for j in range(1,10): if n==i*j: print('Yes') t+=1 flag=True break if flag: break if t==0: print('No')
1
159,102,768,857,088
null
287
287
time = int(input()) h = time // 3600 m = (time - h * 3600) // 60 s = time - h * 3600 - m * 60 print("{0}:{1}:{2}".format(h, m, s))
n=input() h=n/3600 m=(n-h*3600)/60 print ':'.join(map(str,[h,m,n%60]))
1
332,217,714,442
null
37
37
N = int(input()) an = list(map(int, input().split())) count = 0 for i in range(N): if (i+1) % 2 != 0: if an[i] % 2 != 0: count += 1 print(count)
#import sys #sys.setrecursionlimit(10**9) H, N = map(int, input().split()) magic = [_ for _ in range(N)] for k in range(N): magic[k] = list(map(int, input().split())) magic[k].append(magic[k][0]/magic[k][1]) magic.sort(key = lambda x: x[2], reverse=True) ans = [0 for _ in range(H+1)] visited = [0] anskouho = [float('inf')] ans2 = float('inf') """ def solve(start, power, point, maryoku): if start == H: print(min(point, min(anskouho))) exit() elif start > H: anskouho.append(point) return 0 elif ans[start] != 0: return 0 else: visited.append(start) ans[start] = point solve(start+power, power, point+maryoku, maryoku) """ for k in range(N): for item in visited: #solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1]) start = item+magic[k][0] power = magic[k][0] point = ans[item]+ magic[k][1] maryoku = magic[k][1] for _ in range(10**5): if start == H: print(min(point, ans2)) exit() elif start > H: ans2 = min(ans2, point) break elif ans[start]!=0: break else: visited.append(start) ans[start] = point start += power point += maryoku print(ans2)
0
null
44,320,994,647,840
105
229
#coding: utf-8 import math n = int(input()) x = [int(i) for i in input().split(" ")] y = [int(i) for i in input().split(" ")] d1 = d2 = d3 = di = 0 for i in range(n): d1 += abs(x[i] - y[i]) d2 += abs(x[i] - y[i])**2 d3 += abs(x[i] - y[i])**3 if di < abs(x[i] - y[i]): di = abs(x[i] - y[i]) print(d1) print(math.pow(d2, 1.0/2.0)) print(math.pow(d3, 1.0/3.0)) print(di)
import math n = input() x = map(float, raw_input().split()) y = map(float, raw_input().split()) temp = p1 = p2 = p3 = pinf = 0 for i,j in zip(x, y): temp = math.fabs(i - j) p1 += temp p2 += temp ** 2 p3 += temp ** 3 if temp > pinf: pinf = temp print u"%f\n%f\n%f\n%f" % (p1, p2**(1.0/2), p3**(1.0/3), pinf)
1
203,564,422,012
null
32
32
import sys input = sys.stdin.readline class UnionFind(): def __init__(self, N): self.N = N self.r = [-1] * (N+1) def root(self, x): if (self.r[x] < 0): return x else: self.r[x] = self.root(self.r[x]) return self.r[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False if self.r[x] > self.r[y]: x, y = y, x self.r[x] += self.r[y] self.r[y] = x return True def size(self, x): return -self.r[self.root(x)] def same(self, x, y): return self.root(x) == self.root(y) def main(): N, M = map(int, input().split()) uf = UnionFind(N) for _ in range(M): A, B = map(lambda i: int(i)-1, input().split()) uf.unite(A, B) ans = 0 for i in range(N): ans = max(ans, uf.size(i)) print(ans) main()
n, m = map(int, input().split()) class UnionFind(): def __init__(self, n): self.n = n self.parent = [int(x) for x in range(n)] self.tree_size = [1 for _ in range(n)] def unite(self, x, y): x_root = self.find(x) y_root = self.find(y) if self.same(x_root, y_root): return if self.size(x_root) >= self.size(y_root): self.parent[y_root] = x_root self.tree_size[x_root] += self.tree_size[y_root] else: self.parent[x_root] = y_root self.tree_size[y_root] += self.tree_size[x_root] def find(self, x): if self.parent[x] == x: return x else: next = self.find(self.parent[x]) self.parent[x] = next return next def size(self, x): return self.tree_size[self.find(x)] def same(self, x, y): if self.find(x) == self.find(y): return True else: return False uf = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) uf.unite(a-1, b-1) # print([uf.size(i) for i in range(n)]) print(max([uf.size(i) for i in range(n)]))
1
3,951,226,270,110
null
84
84
import sys import numpy as np input = sys.stdin.buffer.readline N = int(input()) A = np.array(list(map(int, input().split()))) MOD = 10**9 + 7 answer = 0 for n in range(63): B = (A >> n) & 1 x = np.count_nonzero(B) y = N - x x *= y for _ in range(n): x = x * 2 % MOD answer += x answer %= MOD print(answer)
d=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split()))for _ in range(d)] class Score: def __init__(self,t): self.x=[d*[0]for _ in range(26)] self.scor=0 self.ans=[] for i in range(d): v=t[i] self.scor+=s[i][v] for j in range(26): if j!=v: self.x[j][i]+=1 if i!=0:self.x[j][i]+=self.x[j][i-1] self.scor-=c[j]*self.x[j][i] self.ans.append(self.scor) def solve(self): return [self.scor,self.ans] t=[int(input())-1 for _ in range(d)] x=Score(t) _,ans=x.solve() for i in ans:print(i)
0
null
66,735,177,280,748
263
114
week=["SUN","MON","TUE","WED","THU","FRI","SAT"] s=input() if s in week: x=week.index(s) print(7-x)
Day = ['', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN'] print(Day.index(input()))
1
133,033,272,843,130
null
270
270
# coding: utf-8 while True: try: data = map(int, raw_input().split()) if data[0] > data[1]: a = data[0] b = data[1] else: a = data[1] b = data[0] r = 1 while r > 0: q = a / b r = a - b * q a = b b = r gcd = a lcm = data[0] * data[1] / gcd print("{:} {:}".format(gcd, lcm)) except EOFError: break
# AOJ 0005 GCD and LCM # Python3 2018.6.9 bal4u def lcm(a, b): return a // gcd(a, b) * b def gcd(a, b): while b != 0: r = a % b a = b b = r return a while True: try: a = list(map(int, input().split())) print(gcd(a[0], a[1]), lcm(a[0], a[1])) except EOFError: break
1
489,366,250
null
5
5
L, R, d = map(int, input().split()) print(sum(1 for i in range(L, R + 1) if i % d == 0))
L, R, d = map(int, input().split()) print((R // d) - (L // d) + (1 if L % d == 0 else 0))
1
7,557,845,441,520
null
104
104
def main(): input_lines_lrd = input() arrLRD = input_lines_lrd.split(" ") l = int(arrLRD[0]) r = int(arrLRD[1]) d = int(arrLRD[2]) cnt = 0 for n in range(l, r+1): if n % d == 0: cnt = cnt + 1 print(cnt) if __name__ == "__main__": main()
if input() == '0': print('1') else: print('0')
0
null
5,214,158,669,358
104
76
A = int(input()) print(int((A-1)/2))
a, b, x = map(int, input().split()) from math import atan from math import pi if x > a*a*b/2: theta = atan(2 * (a*a*b - x) / (a**3)) else: theta = atan(a*b*b / (2*x)) print(theta * 180 / pi)
0
null
157,853,867,786,720
283
289
s=int(input()) a=s//3600 b=(s%3600)//60 c=(s%3600)%60 print(str(a)+":"+str(b)+":"+str(c))
X = int(input()) a = X // 100 b = X % 100 m = 5*a if b > m: print(0) else: print(1)
0
null
63,925,014,210,482
37
266
l = list("abcdefghijklmnopqrstuvwxyz") C = input() i = l.index(C) print(l[i+1])
a = list(map(int,input().split())); a[0],a[1] = a[1],a[0] a[0],a[2] = a[2],a[0] for i in range(3): print(a[i],end=' ');
0
null
65,489,555,070,476
239
178
from fractions import gcd N=int(input()) d={} #l=[] MOD = 1000000007 nz=0 for _ in range(N): a,b=map(int,input().split()) if a==0 and b==0: nz+=1 #p=(0,0) continue elif a==0: p=(0,1) elif b==0: p=(1,0) else: c=gcd(a,b) a,b=a//c,b//c if b > 0: p=(a,b) else: # b < 0 p=(-a,-b) #l.append(p) if p in d: d[p]+=1 else: d[p] = 1 ans=1 #for p in l: while len(d) > 0: p,np=d.popitem() if p==(1,0): q=(0,1) elif p==(0,1): q=(1,0) else: pa,pb=p if pa > 0: q=(-pb,pa) else: #pa < 0 q=(pb,-pa) if q in d: nq=d.pop(q) else: nq=0 ans *= ((2**np + 2**nq - 1) % MOD) ans %= MOD ans -= 1 ans += nz ans %= MOD print(ans)
s = input() k = int(input()) n = len(s) l = [1]*n ''' S = set(s) n1 = len(s) n2 = len(S) l = [0]*n1 for i in range(n2): for j in range(n1): temp = 0 chk = 0 if s[i] == s[j]: l[chk] += 1 else: chk += 1 ''' chk = 0 temp = 0 for i in range(n-1): if s[i+1] == s[i]: l[chk] += 1 else: chk += 1 if s[0] == s[n-1]: temp = 1 memo = 0 edge = 0 ans = 0 for i in range(n-1,-1,-1): if l[i] != 1 and memo == 0 and temp == 1: memo += 1 edge = i ans += k*(l[i]//2) if temp == 1 and edge != 0: if (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1: ans += k-1 elif temp == 1: if l[0] % 2 == 1: ans += k//2 if n == 1: ans = k//2 print(ans)
0
null
98,264,482,636,294
146
296
print(1*(input()[:2]!=input()[:2]))
s1 = list(map(int,input().split())) s2 = list(map(int,input().split())) if int(s1[0])+1 == int(s2[0]): print(1) else: print(0)
1
124,697,995,344,260
null
264
264
def main(): import sys def input(): return sys.stdin.readline().rstrip() n, k = map(int, input().split()) a = list(map(int, input().split())) mod = 10 ** 9+ 7 ans = 1 def answer(a): ans =1 for x in a: ans *= x ans %= mod return ans if n == k: print(answer(a)) return a.sort(reverse=True, key= lambda x:abs(x)) if sum(x<0 for x in a[:k])%2 == 0: print(answer(a[:k])) else: if all(x < 0 for x in a): print(answer(a[-k:])) else: try: x1, y1= min([x for x in a[:k] if x > 0]), min([x for x in a[k:] if x < 0]) except ValueError: x1, y1 = 1, 0 try: x2, y2= max([x for x in a[:k] if x < 0]),\ max([x for x in a[k:] if x >= 0]) except ValueError: x2, y2 = 1, 0 if abs(x2*y1) > abs(x1*y2): a[a.index(x1)] = y1 else: a[a.index(x2)] = y2 print(answer(a[:k])) if __name__ == '__main__': main()
N,K=map(int,input().split()) A=list(map(int,input().split())) mod=10**9+7 if N==K: #全部 ans=1 for i in range(N): ans*=A[i] ans%=mod print(ans) exit() if max(A)<0 and K%2==1: #答えがマイナス A.sort(reverse=True) ans=1 for i in range(K): ans*=A[i] ans%=mod print(ans) exit() plus=[] minus=[] for i in range(N): if A[i]>=0: plus.append(A[i]) else: minus.append(A[i]) plus.sort(reverse=True) #5,3,1 minus.sort() #-5,-3,-1 plus_k=0 minus_k=0 if K%2==0: ans=1 else: ans=plus[0] plus_k=1 for _ in range(K): if plus_k+minus_k==K: break if plus_k>=len(plus)-1: ans*=minus[minus_k]*minus[minus_k+1]%mod ans%=mod minus_k+=2 continue if minus_k>=len(minus)-1: ans*=plus[plus_k]*plus[plus_k+1]%mod ans%=mod plus_k+=2 continue if plus[plus_k]*plus[plus_k+1]>minus[minus_k]*minus[minus_k+1]: ans*=plus[plus_k]*plus[plus_k+1]%mod ans%=mod plus_k+=2 continue else: ans*=minus[minus_k]*minus[minus_k+1]%mod ans%=mod minus_k+=2 continue print(ans)
1
9,400,664,851,718
null
112
112
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N, M, Q = MI() targets = [[] for i in range(Q)] for i in range(Q): target = LI() targets[i] = target ans = 0 for i in range(1, 2**(M+N)): i_str = format(i, f"0{M+N-1}b") A = [] tmp = 1 for k in range(len(i_str)): if i_str[k] == "1": tmp += 1 else: A.append(tmp) if len(A) != N: continue score = 0 for query in targets: a, b, c, d = query if A[b-1] - A[a-1] == c: score += d ans = max(ans, score) print(ans) main()
import sys sys.setrecursionlimit(10 ** 6) N, M, Q = map(int, input().split()) abcd = [list(map(int, input().split())) for i in range(Q)] A = [] def rec(itr, lst): if itr == N: res = 0 for a, b, c, d in abcd: if A[b-1] - A[a-1] == c: res += d return res else: res = 0 for i in range(lst, M): A.append(i) res = max(res, rec(itr + 1, i)) A.pop() return res print(rec(0, 0))
1
27,408,542,022,928
null
160
160
s=input()[::-1] n=len(s) cnts=[0]*2019 cnts[0]=1 num=0 for i in range(n): num+=int(s[i])*pow(10,i,2019) num%=2019 cnts[num]+=1 ans=0 for cnt in cnts: ans+=cnt*(cnt-1)//2 print(ans)
# https://atcoder.jp/contests/abc164/tasks/abc164_d import sys input = sys.stdin.readline S = input().rstrip() res = 0 x = 0 p = 1 L = len(S) MOD = 2019 reminder = [0]*2019 reminder[0] = 1 for s in reversed(S): """ 累積和 """ x = (int(s)*p + x)%MOD p = p*10%MOD res += reminder[x] reminder[x] += 1 print(res)
1
30,893,298,164,958
null
166
166
n, m, l = map(int, input().split()) A = [[int(num) for num in input().split()] for i in range(n)] B = [[int(num) for num in input().split()] for i in range(m)] B = list(zip(*B)) # 列を行に置き換える C = [[0 for i in range(l)] for j in range(n)] for i, A_line in enumerate(A): for j, B_line in enumerate(B): for A_element, B_element in zip(A_line, B_line): C[i][j] += A_element * B_element for line in C: for i, element in enumerate(line): if i == l - 1: print(element) else: print(element, end=' ')
def main(): H, W = map(int ,input().split()) if H == 1 or W == 1: print(1) else: L1 = 0 L2 = 0 L1 = L2 = W // 2 if W % 2 == 1: L1 += 1 ans = (L1 + L2) * (H//2) if H % 2 == 1: ans += L1 print(ans) if __name__ == "__main__": main()
0
null
26,282,094,831,552
60
196
# -*- coding: utf-8 -*- import sys A,B,C,K = list(map(int, input().rstrip().split())) #----- sum_num = 0 for num,cnt in [(1,A), (0,B), (-1,C)]: if cnt <= K: K -= cnt sum_num += num*cnt else: print( sum_num + num*K ) sys.exit() print(sum_num)
N, A, B = map(int, input().split()) MAX = 2 * 10 ** 5 + 1 MOD = 10 ** 9 + 7 # Factorial fac = [0] * (MAX + 1) fac[0] = 1 fac[1] = 1 # Inverse inv = [0] * (MAX + 1) inv[1] = 1 # Inverse factorial finv = [0] * (MAX + 1) finv[0] = 1 finv[1] = 1 for i in range(2, MAX + 1): fac[i] = fac[i - 1] * i % MOD inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD # Factorial for large facl = [0] * (MAX + 1) facl[0] = N for i in range(1, MAX + 1): facl[i] = facl[i - 1] * (N - i) % MOD # Solution ans = pow(2, N, MOD) - 1 ans -= facl[A - 1] * finv[A] % MOD ans %= MOD ans -= facl[B - 1] * finv[B] % MOD ans %= MOD print(ans)
0
null
43,920,997,590,500
148
214
s,t=input().split() S,T=map(int,input().split()) dis=input() if s==dis: print(S-1,T) else: print(S,T-1)
n = input() nn = input() nnn = list(nn) nnn.pop(-1) nn = "".join(nnn) if nn == n: print("Yes") else: print("No")
0
null
46,638,761,333,020
220
147
import sys import math from collections import deque from collections import defaultdict def main(): n, k = list(map(int,sys.stdin.readline().split())) ans = n//k if n%k != 0: ans += 1 print(ans) return 0 if __name__ == "__main__": main()
#x,a=[int(x) for x in input().split]t,input() x,a=map(int,input().split()) counter=0 while(x>0): x-=a counter+=1 print(counter)
1
76,637,570,679,010
null
225
225
N = int(input()) C = list(input()) r = C.count("R") cnt = 0 for i in range(r): if C[i] == "W": cnt += 1 print(cnt)
def resolve(): s = input() print(s[:3]) if 'unittest' not in globals(): resolve()
0
null
10,576,135,580,668
98
130
H, W = list(map(int, input().split())) if H == 1 or W == 1: print(1) else: print(H*W//2 + (H*W)%2)
h, w = map(int, input().split()) print(1) if h == 1 or w == 1 else print((h * w + 1) // 2)
1
51,042,555,331,908
null
196
196
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall n, m, l = map(int, input().split()) INF = 1 << 60 # 距離のmatrixを作る dist = [[INF] * n for _ in range(n)] # 対角行列の成分は0 for i in range(n): dist[i][i] = 0 # 燃料の最大値より小さい場合に辺が張れる for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 if c > l: continue dist[a][b] = c dist[b][a] = c # 全点間の最短距離を求める dist = floyd_warshall(csr_matrix(dist)) # 初期状態を1にする。燃料が足りない経路は迂回したいのでINFを置いておく dist2 = np.full_like(dist, 1) dist2[np.where(dist > l)] = INF # 足し込むことで何回給油するべきかがわかる dist2 = floyd_warshall(dist2, directed=False) dist2 = dist2.astype(int) # 無限大の経路は辿れない。-1を出力したいので0を置いていく dist2[dist2 == INF] = 0 q = int(input()) # 初期状態を1としているので、1を引いて答えとする ans = [] for _ in range(q): s, t = map(int, input().split()) ans.append(dist2[s - 1, t - 1] - 1) print(*ans, sep="\n")
#!/usr/bin/env python3 N, M, L = [int(s) for s in input().split()] edge = [[int(s) for s in input().split()] for _ in range(M)] dist = [[10 ** 10] * N for _ in range(N)] graph = [[] for _ in range(N)] Q = int(input()) for i, j, w in edge: dist[i - 1][j - 1] = w dist[j - 1][i - 1] = w for k in range(N): for i in range(N): for j in range(N): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) for i in range(N): for j in range(N): dist[i][j] = 1 if dist[i][j] <= L else 10 ** 10 for k in range(N): for i in range(N): for j in range(N): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) for _ in range(Q): s, t = [int(a) - 1 for a in input().split()] print(dist[s][t] - 1 if dist[s][t] < 10**10 else -1)
1
173,006,782,943,904
null
295
295
X, Y = map(int, input().split()) award = [300000, 200000, 100000] ans = 0 if X <= 3: ans += award[X-1] if Y <= 3: ans += award[Y-1] if X == 1 and Y == 1: ans += 400000 print(ans)
if __name__ == "__main__": n = int(raw_input()) v = map( int, raw_input().split()) min = 1000000 max = -1000000 s = 0 i = 0 while i < n: if min > v[i]: min = v[i] if max < v[i]: max = v[i] s += v[i] i += 1 print "{0} {1} {2}".format( min, max, s)
0
null
70,640,533,341,912
275
48
from queue import deque n, m, k = map(int, input().split()) friends = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 friends[a].append(b) friends[b].append(a) checked = [False] * n groups = [] for i in range(n): if checked[i]: continue checked[i] = True que = deque([i]) group = [i] while que: now = que.popleft() friends_now = friends[now] for friend in friends_now: if checked[friend] == False: checked[friend] = True group.append(friend) que.append(friend) groups.append(group) # print(groups) D = dict() for i in range(len(groups)): for j in groups[i]: D[j] = i # print(D) block = [0] * n for _ in range(k): c, d = map(int, input().split()) c -= 1 d -= 1 if D[c] == D[d]: block[c] += 1 block[d] += 1 for i in range(n): group_i = D[i] print(len(groups[group_i]) - block[i] - len(friends[i]) - 1)
s = input() if s in "abcdefghijklmnopqrstuvwxyz": print("a") else: print("A")
0
null
36,633,345,382,352
209
119
def distance(x, y, p): """returns Minkowski's distance of vactor x and y if p > 0. if p == 0, returns Chebyshev distance >>> d = distance([1, 2, 3], [2, 0, 4], 1) >>> print('{:.6f}'.format(d)) 4.000000 >>> d = distance([1, 2, 3], [2, 0, 4], 2) >>> print('{:.6f}'.format(d)) 2.449490 >>> d = distance([1, 2, 3], [2, 0, 4], 3) >>> print('{:.6f}'.format(d)) 2.154435 >>> d = distance([1, 2, 3], [2, 0, 4], 0) >>> print('{:.6f}'.format(d)) 2.000000 """ if p == 0: return max([abs(a-b) for (a, b) in zip(x, y)]) else: return sum([abs(a-b) ** p for (a, b) in zip(x, y)]) ** (1/p) def run(): dim = int(input()) # flake8: noqa x = [int(i) for i in input().split()] y = [int(j) for j in input().split()] print(distance(x, y, 1)) print(distance(x, y, 2)) print(distance(x, y, 3)) print(distance(x, y, 0)) if __name__ == '__main__': run()
import sys LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() data = [[a,i] for i,a in enumerate(LI())] data.sort(reverse=True) dp = [[0] * (N+1) for _ in range(N+1)] for i in range(N): a, p = data[i] for j in range(i+1): dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + abs(N-1-j-p)*a) dp[i+1][j] = max(dp[i+1][j], dp[i][j] + abs(i-j-p)*a) print(max(dp[-1]))
0
null
17,105,786,787,958
32
171
n=int(input()) a=list(map(int,input().split())) d={} for i in range(n): if a[i] in d: d[a[i]]+=1 else: d[a[i]]=1 ans=0 D=list(d.values()) for i in range(len(D)): s=D[i]*(D[i]-1)//2 ans+=s for i in range(n): print(ans-d[a[i]]+1)
s = list(input()) n = len(s) m = n//2 s_f = [] s_l = [] for i in range(m): s_f.append(s[i]) for i in range(1,m + 1): s_l.append(s[-i]) s_r = list(reversed(s)) s_f_r = list(reversed(s_f)) s_l_r = list(reversed(s_l)) if s_r == s: if s_f_r == s_f and s_l_r == s_l: print("Yes") else: print("No") else: print("No")
0
null
46,945,624,769,078
192
190
def main2(): K = int(input()) rem = set() n = ans = 0 while True: n = n * 10 + 7 ans += 1 if n % K == 0: print(ans) break else: n = n % K if n in rem: print(-1) break else: rem.add(n) if __name__ == "__main__": main2()
ni = lambda: int(input()) nm = lambda: map(int, input().split()) nl = lambda: list(map(int, input().split())) k = ni() a = [0]*(10**6+1) a[1] = 7%k for i in range(2,k+1): a[i] = (a[i-1]*10+7)%k for i in range(1,k+1): if a[i]==0: print(i) exit() print(-1)
1
6,064,509,892,640
null
97
97
n, k = map(int, input().split()) LR = [tuple(map(int, input().split())) for _ in range(k)] mod = 998244353 dp = [1] acc = [0, 1] for i in range(1, n): new = 0 for l, r in LR: if i < l: continue r = min(r, i) new += acc[i-l+1] - acc[i-r] new %= mod dp.append(new) acc.append((acc[-1]+new) % mod) print(dp[-1])
n,d = map(int, input().split()) x = [] y = [] for i in range(n): a,b = map(int, input().split()) x.append(a) y.append(b) count = 0 for i in range(n): if (x[i]**2 + y[i]**2)**(1/ 2) <= d: count += 1 print(count)
0
null
4,316,567,632,542
74
96
from collections import Counter N = int(input()) A = list(map(int, input().split())) L = dict(Counter([i+A[i] for i in range(N)])) R = dict(Counter([i-A[i] for i in range(N)])) cnt = 0 for x in L: cnt += L[x]*R.get(x, 0) print(cnt)
K = int(input()) S = input() if len(S) <= K: ans = S else: ans = S[0:K] + '...' print(ans)
0
null
22,958,916,959,826
157
143