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
#!/usr/bin/env python #coding: UTF-8 import sys a = sys.stdin.readlines() b = [] for i in a: for j in i: b.append(j.lower()) for i in range(97, 97+26): print chr(i)+" : "+str(b.count(chr(i)))
N,D = map(int, input().split()) XY_s = [list(map(int,input().split())) for _ in range(N)] D**=2 answer = 0 for i in range(N): if D >= XY_s[i][0]**2 + XY_s[i][1]**2: answer+=1 print(answer)
0
null
3,850,919,738,660
63
96
n = int(input()) s = str(input()) w = s[0] num = 0 for i in range(1,n): if w[0] == s[i]: w += s[i] else: num += 1 w = s[i] num += 1 print(num)
N = int(input()) S = input() res = "" pre = "" for s in S: if pre != s: res += s pre = s print(len(res))
1
170,049,926,440,680
null
293
293
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict import bisect con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) def Binary_Search(A, N, M): #初期化 left = 0 right = 10 ** 7 ans = 0 #累積和 Asum = [0] for i in range(N): Asum.append(Asum[i] + A[-1 - i]) leftj = [INF, INF] rightj = [0, 0] #二分探索 while left <= right: mid = (left + right) // 2 var = 0 happiness = 0 for i in range(N): ind = bisect.bisect_left(A, mid - A[i]) ind = N - ind var += ind happiness += ind * A[i] + Asum[ind] # print(var, happiness) if var == M: return happiness elif var > M: leftj = min(leftj, [var, -mid]) left = mid + 1 else: ans = max(ans, happiness) rightj = max(rightj, [var, -mid]) right = mid - 1 # print(ans) # print(leftj) # print(rightj) ans = ans + (M - rightj[0]) * (-leftj[1]) return ans #処理内容 def main(): N, M = getlist() A = getlist() A.sort() ans = Binary_Search(A, N, M) print(ans) if __name__ == '__main__': main()
N, M = map(int, raw_input().split()) matrix = [map(int, raw_input().split()) for n in range(N)] array = [input() for m in range(M)] for n in range(N): c = 0 for m in range(M): c += matrix[n][m] * array[m] print c
0
null
54,467,493,909,052
252
56
n = int(input()) x = input() popcount = x.count('1') p = int(x, 2) % (popcount + 1) q = int(x, 2) % (popcount - 1) if popcount != 1 else 0 for i in range(n): if x[i] == '0': y = (p + pow(2, n-i-1, popcount+1)) % (popcount + 1) else: if popcount != 1: y = (q - pow(2, n-i-1, popcount-1)) % (popcount - 1) else: print(0) continue cnt = 1 while y != 0: y %= bin(y).count('1') cnt += 1 print(cnt)
n = int(input()) dic = {} ma = 1 for i in range(n): wo = input() if(wo in dic): dic[wo] += 1 if(dic[wo] > ma): ma = dic[wo] else: dic.update({wo:1}) ans = [] for i in dic.keys(): if(dic[i] == ma): ans.append(i) ans.sort() for j in ans: print(j)
0
null
39,079,919,230,780
107
218
S = input() Q = int(input()) d = 0 X = [[], []] for i in range(Q): q = input() if q[0] == "1": d = (d + 1) % 2 else: a, f, c = q.split() x = (int(f) + d) % 2 X[x].append(c) if d == 0: v = "".join(X[1])[::-1] + S + "".join(X[0]) else: v = "".join(X[0])[::-1] + S[::-1] + "".join(X[1]) print(v)
s=input() q=int(input()) flag=0 t=['' for _ in range(2)] cnt=0 for _ in range(q): a=list(input().split()) if a[0]=='1': flag=1-flag cnt+=1 else: if a[1]=='1':t[flag]+=a[2] else:t[1-flag]+=a[2] ans=t[0][::-1]+s+t[1] if cnt%2:ans=ans[::-1] print(ans)
1
57,476,770,070,228
null
204
204
import sys [a, b] = [int(x) for x in sys.stdin.readline().split()] d = a / b r = a - a / b * b f = round(1.0 * a / b, 7) print d, r, f
import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) n,u,v=map(int,input().split()) node=[[]for _ in range(n)] for _ in range(n-1): a,b=map(int,input().split()) node[a-1].append(b-1) node[b-1].append(a-1) def dfs(i): visited[i]=1 for x in node[i]: if visited[x]==0: dis[x]=dis[i]+1 dfs(x) inf=10**9 dis=[inf]*n;dis[u-1]=0;visited=[0]*n dfs(u-1) dis2=[] from copy import copy dis_dash=copy(dis) dis2.append(dis_dash) dis[v-1]=0;visited=[0]*n dfs(v-1) dis2.append(dis) cnt=0 for i in range(n): if dis2[0][i]<dis2[1][i]: cnt=max(cnt,dis2[1][i]) print(cnt-1)
0
null
59,072,832,361,268
45
259
from sys import stdin W, H, x, y, r = (int(n) for n in stdin.readline().rstrip().split()) answer = "Yes" if r <= x <= W - r and r <= y <= H - r else "No" print(answer)
W, H, x, y, r = map(int, input().split()) if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H: print("Yes") else: print("No")
1
450,177,488,222
null
41
41
# AtCoder Beginner Contest 146 # F - Sugoroku # https://atcoder.jp/contests/abc146/tasks/abc146_f import sys N, M = map(int, input().split()) *S, = map(int, input()) S.reverse() i = 0 ans = [] while i < N: for m in range(M, 0, -1): if i+m <= N and S[i+m] == 0: i += m ans += [m] break else: print(-1) sys.exit() print(*ans[::-1])
N,M=map(int, input().split()) S=input() now=S[N-1] dp=[float("INF")]*(N+1) dp[N]=0 nowmin=0 right=N for left in range(N-1,-1,-1): while right-left>M or S[right]=="1": right-=1 nowmin=dp[right] if right<=left: print(-1) exit() if S[left]=="1": continue else: dp[left]=1+nowmin #print(dp) #print(dp[0]) now=dp[0] nowi=0 """ if now==float("INF"): print(-1) exit() """ for i in range(1,N+1): if now>dp[i]: print(i-nowi, end=" ") now=dp[i] nowi=i
1
139,421,663,193,608
null
274
274
d = {chr(i):i-96 for i in range(97,123)} D = {val:key for key,val in d.items()} N = int(input()) x = "" while N>0: a = N%26 if a!=0: x += D[a] N = N//26 else: x += "z" N = N//26 N -= 1 print(x[::-1])
n = int(input()) a = list(map(int, input().split())) print(len(list(filter(lambda x: x % 2 == 1, a[::2]))))
0
null
9,865,338,014,100
121
105
n=int(input()) a= list(map(int, input().split())) kt=1 a.sort() for i in range (0,n-1): if a[i]==a[i+1]: kt=0 break if kt==1: print("YES") else: print("NO")
r = int(input()) ans = r * r print(ans)
0
null
109,674,201,772,900
222
278
n=input() count=0 while 1 : x=[i for i in input().split()] if x[0]=="END_OF_TEXT": break for i in range(len(x)): if x[i].lower()==n.lower(): count=count+1 print(count)
word, num = input(), 0 while True: sentence = input() if sentence=="END_OF_TEXT": break word_list = sentence.lower().replace(".", " ").split() for i in word_list: if word==i: num += 1 print(num)
1
1,800,654,974,144
null
65
65
import math r = float(input()) print("%.5f %.5f" % (math.pi*r *r, 2*math.pi*r))
# 改善1:sys入力 # 改善2:ifで分岐させるより、あとから個別対応した方が分岐を毎回やらないですむ? import sys input=sys.stdin.readline def main(): k,n = map(int, input().split()) s = list(map(int, input().split())) l = [] for i in range(1,n): a = s[i] - s[i-1] l.append(a) l.append(k - (s[-1] - s[0])) print(k - max(l)) if __name__ == '__main__': main()
0
null
22,041,274,594,366
46
186
#coding: utf-8 n = raw_input() a = [] for i in range(int(n)): l = map(int,raw_input().split()) a.append(l) for l in a: l = [x * x for x in l] l.sort() if l[0] + l[1] == l[2]: print 'YES' else: print 'NO'
n = input() for i in xrange(n): li = map(int, raw_input().split()) li.sort() if li[0]**2 + li[1]**2 == li[2]**2: print "YES" else: print "NO"
1
264,757,408
null
4
4
input_n = input() n = str(input_n) listN = list(n) #listN = n.split(' ') if listN[len(listN) - 1] == "s": listN.append("e") listN.append("s") else: listN.append("s") for i in range(len(listN)): print(listN[i], end = "")
from collections import deque k=int(input()) d=deque() for i in range(1,10): d.append(i) for i in range(k-1): x=d.popleft() if x%10!=0: d.append(10*x+(x%10)-1) d.append(10*x+(x%10)) if x%10!=9: d.append(10*x+(x%10)+1) print(d.popleft())
0
null
21,242,033,288,780
71
181
# import sys N = int(input()) S,T = input().split() # if not ( 1 <= N <= 100 ): sys.exit() # if not ( len(S) == len(T) and len(S) == N ): sys.exit() # if not ( S.islower() and T.islower() ): sys.exit() for I in range(N): print(S[I],end='') print(T[I],end='')
import sys import math import itertools import collections sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def main(): N = NI() xy = [NLI() for _ in range(N)] ls = [p for p in range(N)] p_list = list(itertools.permutations(ls)) full_course = ["" for _ in range(len(p_list))] for k in range(len(p_list)): distance = 0 for l in range(N-1): departure = p_list[k][l] goal = p_list[k][l+1] Xd = xy[departure][0] Yd = xy[departure][1] Xg = xy[goal][0] Yg = xy[goal][1] distance += ((Xd-Xg)**2 + (Yd-Yg)**2)**(1/2) full_course[k] = distance print(sum(full_course)/len(p_list)) if __name__ == '__main__': main()
0
null
130,261,693,249,088
255
280
N, K = map(int, input().split()) P = list(map(lambda x: int(x) - 1, input().split())) C = list(map(int, input().split())) maxscore = -(10 ** 18) for st in range(N): cumsum = [0] now = st while(P[now] != st): now = P[now] cumsum.append(cumsum[-1] + C[now]) cumsum.append(cumsum[-1] + C[st]) m = len(cumsum) - 1 loopsum = cumsum[-1] if loopsum < 0: maxscore = max(maxscore, max(cumsum[1:min(K + 1, m + 1)])) continue score = (K // m - 1) * loopsum extended_cumsum = cumsum + [cumsum[i] + loopsum for i in range(1, K % m + 1)] score += max(extended_cumsum) maxscore = max(maxscore, score) print(maxscore)
mod=998244353 n,k=map(int,input().split()) LR=[list(map(int,input().split())) for _ in range(k)] DP=[0 for _ in range(n+1)] SDP=[0 for _ in range(n+1)] DP[1]=1 SDP[1]=1 for i in range(2,n+1): for l,r in LR: DP[i] +=(SDP[max(i-l,0)]-SDP[max(i-r,1)-1])%mod DP[i] %=mod SDP[i]=(SDP[i-1]+DP[i])%mod print(DP[n])
0
null
4,056,893,678,464
93
74
x,y = map(int,input().split()) ans = 0 for i in [x,y]: if i==3:ans+=100000 elif i==2:ans+=200000 elif i==1:ans+=300000 if x==y==1: ans += 400000 print(ans)
import sys from collections import defaultdict read = sys.stdin.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): X, Y = map(int, readline().split()) ans = 0 if X==1: ans += 300000 elif X==2: ans += 200000 elif X==3: ans += 100000 else: pass if Y==1: ans += 300000 elif Y==2: ans += 200000 elif Y==3: ans += 100000 else: pass if X==Y==1: ans += 400000 print(ans) if __name__ == '__main__': main()
1
140,512,008,973,702
null
275
275
def l_in(type_): return list(map(type_, input().split())) def i_in(): return int(input()) def m_in(type_): return map(type_, input().split()) def r_in(n, type_): return [type_(input()) for _ in range(n)] ans = None def absmax(a, b): if abs(a) > abs(b): return a return b def absmin(a, b): if abs(a) < abs(b): return a return b a, b, c, d = m_in(int) aa, bb, cc, dd = abs(a), abs(b), abs(c), abs(d) x, y = 0, 0 abm = absmax(a, b) cdm = absmax(c, d) if (abm>0) == (cdm>0): ans = abm*cdm else: abi = absmin(a, b) cdi = absmin(c, d) if (abi>0) == (cdm>0): k = abi*cdm if ans is None or k > ans: ans = k if (abm>0) == (cdi>0): k = abm*cdi if ans is None or k > ans: ans = k k = abi*cdi if ans is None: ans = k print(ans)
a, b, c, d = map(int, input().split()) x_li = [a, b] y_li = [c, d] my_list = [] for x in x_li: for y in y_li: my_list.append(x * y) print(max(my_list))
1
3,031,447,282,332
null
77
77
N,D = [int(i) for i in input().split()] XY = [] count = 0 for i in range(N): XY.append([int(i) for i in input().split()]) for xy in XY: dd = xy[0]**2+xy[1]**2 if dd <= D**2: count +=1 print(count)
import math N,D = map(int,input().split()) ans = 0 for i in range(N): x,y = map(int,input().split()) if math.sqrt(x**2+y**2) <= D: ans += 1 print(ans)
1
5,871,757,219,812
null
96
96
def solve(a, op, b): if op == '+': return a + b elif op == '-': return a - b elif op == '*': return a * b elif op == '/': return a // b return None if __name__ == '__main__': while True: a, op, b = input().split() if op == '?': break print(solve(int(a), op, int(b)))
def count_num_light(a): ret = [0 for _ in range(len(a))] n = len(a) for i in range(n): start = max(0, i-a[i]) end = min(n-1, i+a[i]) ret[start] += 1 if end+1 < n: ret[end+1] -= 1 for i in range(1,n): ret[i] += ret[i-1] return ret n, k = map(int, input().split()) a = list(map(int, input().split())) num_light = count_num_light(a) for i in range(k-1): num_light = count_num_light(num_light) if sum(num_light) == n**2: break print(*num_light)
0
null
8,085,138,739,852
47
132
n = int(input()) x = 0 y = 0 for _ in range(n): a,b=input().split() if a < b: y+=3 elif a ==b: x+=1 y+=1 else: x+=3 print (x,y)
x,y = map(int,input().split()) s = max(0,(4-x)*100000)+max(0,(4-y)*100000) print(s if s!=600000 else s+400000)
0
null
71,661,619,796,832
67
275
A, B, C = input().split() S = A + B + C ans = 'No' for i in range(len(S)): if S.count(S[i]) == 2: ans = 'Yes' break print(ans)
print( 'Yes' if len(set(input().split())) == 2 else 'No')
1
68,343,027,260,842
null
216
216
S = list(input()) T = list(input()) count = 0 for i in range(len(S)): if S[i] != T[i]: count += 1 break if count == 0: print("Yes") else: print("No")
a=input() b=input() if(a==b[0:len(b)-1] and len(b)-len(a)==1): print('Yes') else: print('No')
1
21,453,328,434,400
null
147
147
while True: ins = input().split() x = int(ins[0]) y = int(ins[1]) if x == 0 and y == 0: break else: nums = [x, y] nums.sort() print(" ".join(map(str, nums)))
a, b,c ,d = list(map(int,input().split())) ll = [a*c,a*d,b*c,b*d] print(max(ll))
0
null
1,799,612,334,502
43
77
import sys n = int(input()) A=[int(e)for e in sys.stdin] cnt = 0 G = [int((3**i-1)/2)for i in range(14,0,-1)] G = [v for v in G if v <= n] def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v for g in G: insertionSort(A, n, g) print(len(G)) print(*G) print(cnt) print(*A,sep='\n')
def insertion_sort(array, g, result): for i in range(g, len(array)): v = array[i] j = i - g while j >= 0 and array[j] > v: array[j + g] = array[j] j -= g result['count'] += 1 A[j + g] = v def g_gene(n): yield 1 for i in range(2, n): x = int((3 ** i - 1) / 2) if x < n: yield x else: raise StopIteration() def shell_sort(array, result): result['count'] = 0 G = list(reversed(list(g_gene(len(array))))) m = len(G) result['G'] = G result['m'] = m for i in range(m): insertion_sort(array, G[i], result) if __name__ == '__main__': import sys n = int(sys.stdin.readline()) A = [] for _ in range(n): A.append(int(sys.stdin.readline())) result = {} shell_sort(A, result) print(result['m']) print(' '.join(map(str, result['G']))) print(result['count']) for a in A: print(a)
1
31,066,007,212
null
17
17
def get_num(n, x): ans = 0 for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1): for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1): if n3 + min(n2 - 1, x - n3 - n2): ans += 1 return ans data = [] while True: [n, x] = [int(m) for m in raw_input().split()] if [n, x] == [0, 0]: break # if x < 3: # print(0) # else: print(get_num(n, x))
N = int(input()) S = input() count = 1 check = S[0] for c in S: if c != check: count += 1 check = c print(count)
0
null
85,771,162,940,538
58
293
import sys N,M = map(int,input().split()) array = list(map(int,input().split())) if not ( 1 <= M <= 100 and M <= N <= 100 ): sys.exit() if not (len(array) == len(set(array))): sys.exit() count = 0 standard = sum(array) * (1/(4*M)) for I in array: if I >= standard: count += 1 print('Yes') if count >= M else print('No')
if __name__ == '__main__': N, M = map(int, input().split()) A = list(map(int, input().split())) total = sum(A) threshold = total / (4*M) count = sum([a>=threshold for a in A]) if count >= M: print('Yes') else: print('No')
1
38,553,784,900,418
null
179
179
N = int(input()) for i in range(1, 10): if N % i == 0: j = N // i if 1 <= j and j <= 9: print("Yes") exit() print("No")
import fractions def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) A,B=map(int,input().split()) print(lcm_base(A,B))
0
null
136,192,351,176,490
287
256
# -*- coding: utf-8 -*- def get_input() -> str: """ 標準入力を取得する. Returns:\n str: 標準入力 """ S = input() return S def main(S: str) -> None: """ メイン処理. Args:\n S (str): 文字列(1 <= |S| <= 1000, 英子文字のみ) """ # 求解処理 ans = S if S[-1] == "s": ans += "es" else: ans += "s" # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 S = get_input() # メイン処理 main(S)
S = input() if S[-1] != 's': S = S + 's' elif S[-1] == 's': S = S + 'es' print(S)
1
2,405,736,501,060
null
71
71
N = int(input()) S = list(input()) r = 0 g = 0 b = 0 for i in range(N): if S[i] == 'R': r += 1 elif S[i] == 'G': g += 1 else: b += 1 allcnt = r * g * b sub = 0 for i in range(N): for j in range(i+1,N): if S[i] == S[j]: None else: k = 2*j-i if k >= N or S[i] == S[k] or S[j] == S[k]: None else: sub += 1 print(allcnt - sub)
#!/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(L: int): return L**3 / 27 def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() L = int(next(tokens)) # type: int print(f'{solve(L)}') if __name__ == '__main__': main()
0
null
41,580,574,269,596
175
191
s = input() for _ in range(int(input())): o = input().split() a, b = map(int, o[1:3]) b += 1 c = o[0][2] if c == 'p': s = s[:a]+o[3]+s[b:] elif c == 'i': print(s[a:b]) elif c == 'v': s = s[:a]+s[a:b][::-1]+s[b:]
S = input() n = int(input()) for i in range(n): q = input().split() q[1] = int(q[1]) q[2] = int(q[2]) if q[0] == "print": print(S[q[1]:q[2] + 1]) elif q[0] == "reverse": if q[1] == 0: S = S[:q[1]] + S[q[2]::-1] + S[q[2] + 1:] else: S = S[:q[1]] + S[q[2]:q[1] - 1:-1] + S[q[2] + 1:] elif q[0] == "replace": S = S[:q[1]] + q[3] + S[q[2] + 1:]
1
2,064,909,058,308
null
68
68
#import sys #import numpy as np import math #from fractions import Fraction import itertools from collections import deque from collections import Counter #import heapq #from fractions import gcd #input=sys.stdin.readline import bisect n,m,q=map(int,input().split()) l=[i for i in range(1,m+1)] ab=[list(map(int,input().split())) for _ in range(q)] ans=0 for res in itertools.combinations_with_replacement(l, n): ans_r=0 for i in range(q): a,b,c,d=ab[i] if c==res[b-1]-res[a-1]: ans_r+=d ans=max(ans,ans_r) print(ans)
#169D #Div Game n=int(input()) def factorize(n): fct=[] b,e=2,0 while b**2<=n: while n%b==0: n/=b e+=1 if e>0: fct.append([b,e]) b+=1 e=0 if n>1: fct.append([n,1]) return fct l=factorize(n) ans=0 for i in l: c=1 while i[1]>=c: ans+=1 i[1]-=c c+=1 print(ans)
0
null
22,286,083,975,328
160
136
n,k = map(int, input().split()) s = list(map(int,input().strip().split())) t = 0 ss = sorted(s) for kk in range(k): t += ss[kk] print(t)
n,k=(int(i) for i in input().split()) a=list(map(int, input().split())) a.sort() sum=0 for i in range(k): sum+=a[i] print(sum)
1
11,630,100,737,960
null
120
120
N=int(input()) List = list(map(int, input().split())) Row = int(input()) QList = [] for i in range (Row): QList.append(list(map(int, input().split()))) dictA ={} res = 0 for i in range (N): dictA.setdefault(List[i],0) dictA[List[i]] += 1 res += List[i] num = 0 for i in range(Row): if QList[i][0] not in dictA: pass else: num = dictA[QList[i][0]] res = res - dictA[QList[i][0]] * QList[i][0] dictA[QList[i][0]] = 0 dictA.setdefault(QList[i][1],0) dictA[QList[i][1]] += num res += QList[i][1] * num print(res)
def sum_dict(d): num = 0 for k, v in d.items(): num += k * v return num def create_dict(A): d = {} for a in A: if d.get(a) is None: d[a] = 1 else: d[a] += 1 return d if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) Q = int(input()) BC = [] for i in range(Q): BC.append(tuple(map(int, input().split()))) d = create_dict(A) ans = sum_dict(d) for b, c in BC: db = d.get(b) if db is None: db = 0 if d.get(c) is None: d[c] = 0 d[c] += db d[b] = 0 ans += (c - b) * db print(ans)
1
12,108,904,764,580
null
122
122
num = int(input()) result = num + num**2 + num**3 print(result)
a = int(input()) print(a*(1+a+a**2))
1
10,195,723,179,238
null
115
115
xin = [] while True: x = int(raw_input()) if x == 0: break xin += [x] for i in xin: print sum(map(int , list(str(i))))
while True: n = input() if n == 0: break print sum(map(int, list(str(n))))
1
1,582,505,324,346
null
62
62
import math a,b,C = map(int, input().split()) r = C*math.pi/180 h = b*math.sin(r) print('{0:f}'.format(a*h/2)) print('{0:f}'.format(a+b+(math.sqrt(a**2+b**2-2*a*b*math.cos(r))))) print('{0:f}'.format(h))
# coding: utf-8 # Your code here! N=input().split() a=int(N[0]) b=int(N[1]) c=int(N[2]) if a < b < c: print("Yes") else: print("No")
0
null
279,614,885,768
30
39
import math n = sum([int(x) for x in str(input()).split()]) a, b = divmod(n, 9) print("No" if b else "Yes")
N = str(input()) a = [] for n in range(len(N)): a.append(int(N[n])) if sum(a) % 9 == 0: print('Yes') else: print('No')
1
4,419,530,177,450
null
87
87
k = "a", for _ in range(int(input()) - 1): k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)} print(*sorted(k))
import sys n = int(sys.stdin.readline()) lines = sys.stdin.readlines() #n = int(input()) #import collections #dll = collections.deque() class Node: def __init__(self,v): self.val = v self.prev = None self.next = None class DLL(): def __init__(self): self.tail = Node(None) self.tail.next = self.tail self.tail.prev = self.tail def insert(self,x): n = Node(x) pre = self.tail.next n.next = pre n.prev = self.tail pre.prev = n self.tail.next = n def delete(self,x): node = self.tail.next while node != self.tail: if node.val == x: p = node.prev n = node.next p.next = n n.prev = p return node = node.next def deleteFirst(self): pre = self.tail.next if pre == self.tail: return node = self.tail.next p = node.prev n = node.next p.next = n n.prev = p def deleteLast(self): if self.tail.next == self.tail: return node = self.tail.prev p = node.prev n = node.next p.next = n n.prev = p def inspect(self): node = self.tail.next ret = [] while node != self.tail: ret.append(str(node.val)) node = node.next print(" ".join(ret)) dll=DLL() for i in range(n): q = lines[i] if q[0] == "i": dll.insert(int(q.split()[1])) elif q[6] == " ": dll.delete(int(q.split()[1])) elif q[6] == "L": dll.deleteLast() elif q[6] == "F": dll.deleteFirst() dll.inspect() #print(" ".join(map(str,dll)))
0
null
26,211,147,976,468
198
20
n = int(input()) c = input() red = c.count('R') print(c[red:].count('R'))
import sys input = sys.stdin.readline N, D = map(int, input().split()) count = 0 for i in range(N): a, b = map(int, input().split()) if (a*a + b*b) <= D*D: count += 1 print(count)
0
null
6,079,577,829,730
98
96
import re T = input() print(re.sub(r'\?', 'D', T))
#デフォルト import itertools from collections import defaultdict import collections import math import sys sys.setrecursionlimit(200000) mod = 1000000007 t = list(input()) for i in range(len(t)): if (t[i] == "?"): print("D",end="") else: print(t[i],end="")
1
18,471,007,624,728
null
140
140
x = raw_input().split() m = map(int,x) a = x[0] b = x[1] c = x[2] if a < b and b< c: print "Yes" else: print"No"
def merge_sort(A): if len(A) <= 1: return A, 0 mid = len(A) // 2 left, lcount = merge_sort(A[:mid]) right, rcount = merge_sort(A[mid:]) merged, count = merge(left, right) return merged, lcount + rcount + count def merge(left, right): lpos = 0 rpos = 0 #lcount = 0 #rcount = 0 merged = [] while lpos < len(left) and rpos < len(right): if left[lpos] <= right[rpos]: merged.append(left[lpos]) lpos += 1 #lcount += 1 else: merged.append(right[rpos]) rpos += 1 #rcount += 1 if left[lpos:]: merged.extend(left[lpos:]) #lcount += len(left[lpos:]) if right[rpos:]: merged.extend(right[rpos:]) #rcount += len(right[rpos:]) #print merged #return merged, lcount + rcount return merged, len(merged) if __name__ == '__main__': n = int(raw_input()) A = map(long, raw_input().split()) sorted, count = merge_sort(A) print ' '.join(str(x) for x in sorted) print count
0
null
253,913,573,830
39
26
x,y = map(int,input().split()) a = [0]*210 a[:3] = [300000, 200000, 100000] if x == y and x == 1: print(1000000) else: print(a[x-1] + a[y-1])
X,Y=map(int,input().split());m=4-min(X,Y) if X==Y==1:print(10**6) elif X<=3and Y<=3:print(((4-X)+(4-Y))*10**5) else:print(m*10**5if m>=0else 0)
1
140,884,877,632,092
null
275
275
n,a,b = map(int,input().split()) if n%(a+b)<=a: print(n//(a+b)*a+n%(a+b)) else: print(n//(a+b)*a+a)
n, a, b = map(int, input().split()) q = n // (a + b) r = n % (a + b) if r >= a: res = a else: res = r print(q * a + res)
1
55,498,654,335,950
null
202
202
import math x = int(input()) a = 100 cnt = 0 while(1): cnt += 1 a += a//100 if a >= x: break print(cnt)
N = int(input()) count = 0 for i in range(1, N): if i != N - i: count += 1 print(count // 2)
0
null
90,407,312,992,672
159
283
#import sys #import numpy as np import math #from fractions import Fraction import itertools from collections import deque from collections import Counter import heapq #from fractions import gcd #input=sys.stdin.readline import bisect s=input() t=input() n=len(s) ans=0 for i in range(n): if s[i]!=t[i]: ans+=1 print(ans)
n=int(input()) a=[0]*(n+1) for x in range(1,101): for y in range(1,101): for z in range(1,101): if x*x+y*y+z*z+x*y+x*z+y*z<=n: a[x*x+y*y+z*z+x*y+x*z+y*z]+=1 for i in range(1,n+1): print(a[i])
0
null
9,205,401,457,980
116
106
import sys N=int(sys.stdin.readline()) # ans=sum((N//x)*(N//x+1)*x//2 for x in range(1,N+1)) ans=0 for x in range(1,N+1): y=N//x ans+=y*(y+1)*x//2 print(ans)
# 正整数Xの正約数個数をf(X)とするときの \sum_(K=1)^N {K*f(K)} # 正整数jの倍数でありN以下のものの総和をg(j)とするときの \sum_(j=1)^N g(j) N = int(input()) ans = 0 for j in range(1, N+1): # Y = N/j とすると g(j) = j+2j+...+Yj = (1+2+...+Y)j = Y(Y+1)/2 *j g = (N//j)*(N//j+1)*j//2 ans += g print(ans)
1
10,998,809,346,398
null
118
118
n = int(input()) def saiki(i): if i > 1: return 2 * saiki(i // 2) + 1 if i == 1: return 1 print(saiki(n))
H = int(input()) i = 1 cnt = 0 while H > 0: H //= 2 cnt += i i *= 2 print(cnt)
1
80,038,963,155,890
null
228
228
#import numpy as np #import math #from decimal import * #from numba import njit #@njit def main(): (N, M) = map(int, input().split()) neighbor = [[] for _ in range(N+1)] for _ in range(M): (A,B) = map(int, input().split()) neighbor[A] += B, neighbor[B] += A, guide = [0 for _ in range(N+1)] # 1の部屋から幅優先で道しるべを置く # 探索候補 target = [1] checked = [1] while len(target) > 0: # 候補の先頭から取る n = target.pop(0) # nから伸びる行き先 dests = neighbor[n] # すでに道しるべがあるものは除く dests = filter(lambda d: guide[d] == 0, dests) # 道しるべを置く for d in dests: guide[d] = n checked += d, # 探索候補の末尾に追加 target += d, print('Yes') for i in range(2,N+1): print(guide[i]) main()
import sys from itertools import accumulate read = sys.stdin.buffer.read def main(): N, *L = map(int, read().split()) L.sort() max_L = L[-1] C = [0] * (max_L + 1) for l in L: C[l] += 1 C = list(accumulate(C)) ans = 0 for i in range(N): for j in range(i + 1, N): if L[i] + L[j] > max_L: ans += N - j - 1 else: ans += C[L[i] + L[j] - 1] - j - 1 print(ans) return if __name__ == '__main__': main()
0
null
96,128,929,750,630
145
294
N, K = map(int, input().split()) A = tuple(map(int, input().split())) MOD = 10 ** 9 + 7 if K == N: ans = 1 for x in A: ans = (ans * x) % MOD print(ans) exit() plus, minus = [], [] for a in A: if a >= 0: plus.append(a) else: minus.append(a) plus.sort(reverse=True) minus.sort() if not plus: ans = 1 if K % 2: # 答えは負値になるので絶対値小さいのを取る for x in minus[-K:]: ans = (ans * x) % MOD else: # 答えは非負値になるので絶対値大きいのを取る for x in minus[:K]: ans = (ans * x) % MOD print(ans) exit() idx = 0 for i in range(2, N, 2): if K - i < 0: break if not len(plus) >= K - i + 2: idx += 2 continue if len(minus) >= i: if minus[i - 2] * minus[i - 1] < plus[K - i + 1] * plus[K - i]: break else: idx += 2 ans = 1 for x in minus[:idx] + plus[:K - idx]: ans = (ans * x) % MOD print(ans)
#!/usr/bin/env python3 import sys import heapq MOD = 1000000007 # type: int def containPositive(arr): for a in arr: if a >= 0: return True return False def solve(N: int, K: int, A: "List[int]"): if N == K: m = 1 for a in A: m = m*a%MOD print(m) elif not containPositive(A) and K%2 == 1: A = list(reversed(sorted(A))) m = 1 for i in range(K): m = m*A[i]%MOD print(m) else: m = 1 B = [(abs(a),a) for a in A] B = list(reversed(sorted(B))) lastNegative = 0 lastPositive = 1 hadPositive = False for i in range(K): a = B[i][1] if a < 0: if lastNegative == 0: lastNegative = a else: m = m*lastNegative*a%MOD lastNegative = 0 else: if a > 0 and lastPositive != 1: m = m*lastPositive%MOD if a > 0: lastPositive = a hadPositive = True else: m=m*a%MOD if lastNegative == 0: print(m*lastPositive%MOD) else: nextNegative = 0 for i in range(K,N): b = B[i][1] if b < 0: nextNegative = b break if nextNegative == 0: m = m*B[K][1] print(m*lastPositive%MOD) else: c1 = lastNegative*nextNegative nextPositive = 0 k = K while k < N: a = B[k][1] if a >=0: nextPositive = a break k+=1 c2 = nextPositive*lastPositive if not hadPositive: # This array contain some non-negative value. This means the result value could be positive. But if there were no positive values in the first K values sorted by the absolute value, use just next positive value instead of the last negative values. m = m*nextPositive%MOD print(m) exit() if c1 > c2: m = m*lastNegative*nextNegative%MOD print(m) else: m =m*nextPositive*lastPositive%MOD print(m) # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, K, A) if __name__ == '__main__': main()
1
9,376,145,594,992
null
112
112
n = int(input()) chars = 'Xabcdefghijklmnopqrstuvwxyz' res = '' while True: x = n%26 #最下位の位の文字を求める(係数が26でない最下位の位が余りとして出せる) if x == 0: #Xが26のときのみ余り0で対応させるため26に書き換え x = 26 res += chars[x] #文字を正解リストに追加 n -= x #xを左辺に持っていって右辺で10の位以上の数値を調べる if n == 0 : break n //= 26 #n-xは必ず26の倍数になっている。(xを移項しているから自明) #最下位の位を余りとして扱うために26で割って係数を消している。 print(res[::-1])#resには1の位が一番初めに入っているので、反転させて表示
H, W = map(int, input().split()) S = [input() for _ in range(H)] INF = 10 ** 18 dp = [[INF for _ in range(W)] for _ in range(H)] if S[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 for i in range(H): for j in range(W): if S[i][j] == ".": dp[i][j] = min(dp[i][j], dp[i - 1][j], dp[i][j - 1]) else: dp[i][j] = min(dp[i][j], dp[i - 1][j] if S[i - 1][j] == "#" else dp[i - 1][j] + 1, dp[i][j - 1] if S[i][j - 1] == "#" else dp[i][j - 1] + 1) print(dp[-1][-1])
0
null
30,426,894,835,972
121
194
N = int(input()) GACHA=[input() for n in range(N)] print(len(set(GACHA)))
def main(): N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) total_T_in_A = [0] * (N+1) total_T_in_A[1] = A[0] total_T_in_B = [0] * M total_T_in_B[0] = B[0] for i in range(1, N+1): total_T_in_A[i] = total_T_in_A[i-1] + A[i-1] for i in range(1, M): total_T_in_B[i] = total_T_in_B[i-1] + B[i] result = 0 for i in range(N+1): # A から i 冊読むときにかかる時間 i_A_T = total_T_in_A[i] if K < i_A_T: continue if K == i_A_T: result = max(result, i) continue rem_T = K - i_A_T # total_T_in_B は累積和を格納した、ソート済の配列 # B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す first = total_T_in_B[0] last = total_T_in_B[M-1] if rem_T < first: result = max(result, i) continue if last <= rem_T: result = max(result, i + M) continue # assume that first <= rem_T <= last first_i = 0 last_i = M - 1 while first_i < last_i: if abs(last_i - first_i) == 1: break mid_i = (first_i + last_i) // 2 if rem_T < total_T_in_B[mid_i]: last_i = mid_i else: first_i = mid_i result = max(result, i + first_i + 1) print(result) main()
0
null
20,503,985,868,750
165
117
N = int(input()) A = {int(x): key for key, x in enumerate(input().split(), 1)} sort_a = sorted(A.items(), key=lambda x: x[0]) print(' '.join([str(key) for x, key in sort_a]))
N = int(input()) A = list(map(int, input().split())) for i, a in enumerate(A.copy(), 1): A[a - 1] = i for a in A: print(str(a) + ' ', end='') print()
1
180,730,543,838,768
null
299
299
n = int(input()) count = [0]*n ans = 1 flag = True for d in map(int,input().split()): if flag: if d!=0: print(0) exit() flag = False count[d] += 1 for i in range(1,n): if count[0]!=1: ans = 0 break if count[i]==0: if any(k!=0 for k in count[i:]): ans = 0 break ans *= (count[i-1]**count[i])%998244353 print(ans%998244353)
N = int(input()) D = list(map(int,input().split())) if D[0] != 0: print(0) exit() from collections import Counter ctr = Counter(D) if ctr[0] > 1: print(0) exit() MOD = 998244353 ans = 1 for i in range(len(ctr)-1): ans *= pow(ctr[i], ctr[i+1], MOD) ans %= MOD print(ans)
1
154,819,348,031,744
null
284
284
A = list(map(int, input().split())) H = A[0] W = A[1] K = A[2] colors = [] for line in range(H): color = input() color = list(color) colors.append(color) ans = 0 for i in range(2**H): for j in range(2**W): cnt = 0 for k in range(H): for l in range(W): if list(format(i,"0"+str(H)+"b"))[k] == "0" and list(format(j,"0"+str(W)+"b"))[l] == "0": if colors[k][l] == "#": cnt += 1 if cnt == K: ans+= 1 print(ans)
H,W,K=map(int,input().split()) c_map=[] for _ in range(H): c=input() c_map.append(c) ans=0 for i in range(2**H): for j in range(2**W): cnt=0 for k in range(H): for l in range(W): if c_map[k][l]=='#' and (i>>k)&1==0 and (j>>l)&1==0: cnt+=1 if cnt==K: ans+=1 print(ans)
1
8,935,738,845,660
null
110
110
n = int(input()) a = [0] * n x = [0] * n y = [0] * n for i in range(n): a[i] = int(input()) t = [[int(j) for j in input().split()] for k in range(a[i])] x[i] = [j[0] for j in t] y[i] = [j[1] for j in t] mx = 0 for bit in range(1<<n): flag = True tf = [0] * n for i in range(n): if bit & (1 << i): tf[i] = 1 for i in range(n): if tf[i] == 0: continue for j in range(a[i]): if tf[x[i][j]-1] != y[i][j]: flag = False if flag: mx = max(mx, bin(bit).count("1")) print(mx)
def right_num(m,u): cube = [ {2:3,3:5,4:2,5:4}, {1:4,3:1,4:6,6:3}, {1:2,2:6,5:1,6:5}, {1:5,2:1,5:6,6:2}, {1:3,3:6,4:1,6:4}, {2:4,3:2,4:5,5:3}, ] return cube[m][u] d=input().split() for i in range(int(input())): num = input().split() p = d.index(num[0]) s = int(d.index(num[1])) + 1 print("{}".format(d[(right_num(p, s)-1)]))
0
null
61,011,248,075,370
262
34
K = int(input()) C = [[0]*10 for _ in range(10)] C[0] = [1]*10 D = {0: [0, 1], 1: [0, 1, 2], 2: [1, 2, 3], 3: [2, 3, 4], 4: [3, 4, 5], 5: [4, 5, 6], 6: [5, 6, 7], 7: [6, 7, 8], 8: [7, 8, 9], 9: [8, 9]} for i in range(1, 10): for j in range(10): if j == 0: C[i][j] = C[i-1][j] + C[i-1][j+1] elif j == 9: C[i][j] = C[i-1][j-1] + C[i-1][j] else: C[i][j] = C[i-1][j-1] + C[i-1][j] + C[i-1][j+1] ans = [] temp = K Flag = True for i in range(10): if Flag: for j in range(1, 10): temp -= C[i][j] if temp <= 0: temp += C[i][j] r = i ans.append(j) Flag = False break else: break def f(x, r): temp = x r -= 1 for j in D[ans[-1]]: temp -= C[r][j] if temp <= 0: temp += C[r][j] ans.append(j) break return temp, r while r >= 1: temp, r = f(temp, r) print("".join([str(i) for i in ans]))
import math def calc_combi(n,m): if n<=1: return 0 return math.factorial(n)/(math.factorial(m)*(math.factorial(n-m))) n,m=map(int,input().split()) ans=int(calc_combi(n,2)+calc_combi(m,2)) print(ans)
0
null
42,669,322,675,176
181
189
#a問題 n=int(input()) print(n+(n**2)+(n**3))
a = int(input()) print(a+pow(a,2)+pow(a,3))
1
10,147,660,731,598
null
115
115
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) S,T = readline().decode().rstrip().split() ans = '' for i in range(N): ans += S[i] + T[i] print(ans)
n=int(input()) s,t=input().split() l=[] for i in range(2*n): if i%2==0: l.append(s[i//2]) else: l.append(t[(i-1)//2]) l=''.join(l) print(l)
1
112,087,256,299,460
null
255
255
import string import sys input_str = "" for i in sys.stdin: input_str += i for i in range(26): char = string.ascii_lowercase[i] CHAR = string.ascii_uppercase[i] cnt = input_str.count(char) + input_str.count(CHAR) print("{0} : {1}".format(char, cnt))
import sys s = sys.stdin.read() s = s.lower() alp = "qazxswedcvfrtgbnhyujmkiolp" alp = sorted(alp) for c in alp: print('{} : {}'.format(c,s.count(c)))
1
1,655,624,807,770
null
63
63
import sys import math def resolve(in_): a, b, n = map(int, next(in_).split()) x = min(b - 1, n) return math.floor(a * x / b) - a * math.floor(x / b) def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
a, b, c = [int(x) for x in input().split()] if a + b + c >= 22: print("bust") else: print("win")
0
null
73,603,879,356,448
161
260
N, A, B = map(int, input().split()) ans = 0 roop = int(N / (A + B)) # print(roop) padding = N % (A + B) if padding >= A: ans += roop * A + A else: ans += roop * A + padding print(ans)
N,A,B = map(int,input().split()) d,m = divmod(N,A+B) print(d*A + min(A,m))
1
55,749,447,705,490
null
202
202
from math import gcd def readinput(): n,m=map(int,input().split()) a=list(map(int,input().split())) return n,m,a def lcm(a,b): return a*b//gcd(a,b) def main(n,m,a): #s=set(a) #print(s) x=a[0]//2 for i in range(1,n): x=lcm(x,a[i]//2) #print(x) gusubai=False kisubai=False for i in range(n): if x%a[i]!=0: gusubai=True else: kisubai=True y=m//x #print(y,x,m) if gusubai and not kisubai: ans=y//2+y%2 elif gusubai and kisubai: ans=0 else: ans=y return ans if __name__=='__main__': n,m,a=readinput() ans=main(n,m,a) print(ans)
N, M = map(int, input().split()) A = list(set(map(lambda x : int(x)//2, input().split()))) def _gcd(a, b): return a if b == 0 else _gcd(b, a%b) def _lcm(a,b): return (a*b) // _gcd(a,b) lcm = A[0] for ai in A[1:]: lcm = _lcm(lcm, ai) ret = (M//lcm + 1)//2 for ai in A[1:]: if (lcm // ai) % 2 == 0: ret = 0 break print(ret)
1
101,627,174,769,622
null
247
247
D, T, S = (int(d) for d in input().split()) if T * S >= D: print("Yes") else: print("No")
d, t, s = map(int, input().split()) if t * s >= d: print('Yes') quit() print('No')
1
3,521,656,507,448
null
81
81
# coding=utf-8 class Dice(object): def __init__(self, label): self.label = label def _rotateS(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s5, s1, s3, s4, s6, s2] def _rotateN(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s2, s6, s3, s4, s1, s5] def _rotateE(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s4, s2, s1, s6, s5, s3] def _rotateW(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s3, s2, s6, s1, s5, s4] def _spinPos(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s1, s4, s2, s5, s3, s6] def _spinNeg(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s1, s3, s5, s2, s4, s6] def rotate(self, r): if r == 'S': self._rotateS() elif r == 'N': self._rotateN() elif r == 'E': self._rotateE() elif r == 'W': self._rotateW() elif r == 'SP': self._spinPos() elif r == 'SN': self._spinNeg() elif r == '2S': self._rotateS() self._rotateS() elif r == '2SP': self._spinPos() self._spinPos() def getLabel(self, i): return self.label[i - 1] def match(self, top, front): iTop = self.label.index(top) + 1 topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: '2S'} self.rotate(topRot[iTop]) iFront = self.label.index(front) + 1 frontRot = {2: '', 3: 'SN', 4: 'SP', 5: '2SP'} self.rotate(frontRot[iFront]) def main(): d = Dice(map(int, raw_input().split())) n = input() for _ in xrange(n): top, front = map(int, raw_input().split()) d.match(top, front) print d.getLabel(3) if __name__ == '__main__': main()
import random class Dice: def __init__(self, list = map(str, range(1, 7))): self.top = list[0] self.front = list[1] self.right = list[2] self.left = list[3] self.back = list[4] self.bottom = list[5] def print_all(self): print "top = " + self.top print "front = " + self.front print "right = " + self.right print "left = " + self.left print "back = " + self.back print "bottom = " + self.bottom def roll_N(self): temp = self.top self.top = self.front self.front = self.bottom self.bottom = self.back self.back = temp def roll_S(self): temp = self.top self.top = self.back self.back = self.bottom self.bottom = self.front self.front = temp def roll_W(self): temp = self.top self.top = self.right self.right = self.bottom self.bottom = self.left self.left = temp def roll_E(self): temp = self.top self.top = self.left self.left = self.bottom self.bottom = self.right self.right = temp def random_roll(self): ram = random.randint(1, 4) if ram == 1: self.roll_E() elif ram == 2: self.roll_N() elif ram == 3: self.roll_S() else: self.roll_W() my_dice = Dice(raw_input().split(" ")) q = int(raw_input()) for i in xrange(q): input_dice = raw_input().split(" ") while True: if my_dice.top == input_dice[0] and my_dice.front == input_dice[1]: break else: my_dice.random_roll() print my_dice.right
1
255,968,350,550
null
34
34
while True: n = int(input()) if n == 0: break scores = [int(x) for x in input().split()] ave = sum(scores)/n resi = 0 for s in scores: resi += (s-ave)**2 sd = (resi/n)**0.5 print('{:.6f}'.format(sd))
import math while True: n = int(raw_input()) if n == 0: break s = map(int, raw_input().split()) m = float(sum(s)) / n a2 = (sum(map(lambda x: (x-m)**2, s))) / n a = math.sqrt(a2) print("%f" % (a, ))
1
191,943,620,140
null
31
31
n = int(input()) txt = input() print(txt[:n]+"..." if bool(txt[n:]) else txt)
k, s = open(0).read().split(maxsplit=2) k = int(k) if len(s) <= k: print(s) else: print(s[:k] + "...")
1
19,687,429,390,540
null
143
143
n=int(input()) array=list(map(int,input().split())) ans=0 for m in range(n): if m%2==0 and array[m]%2==1: ans=ans+1 print(ans)
N = int(input()) a = list(map(int, input().split())) cnt = 0 for i in range(N): if i % 2 == 0: if a[i] % 2 == 1: cnt += 1 print(cnt)
1
7,708,866,146,812
null
105
105
n = int(input()) g = [None] * n visited = [0] * n root = set(range(n)) ts = [[0, 0] for _ in range(n)] t = 0 while n: l = list(map(int, input().split())) connected = [i - 1 for i in l[2:]] g[l[0] - 1] = [i - 1 for i in l[2:]] root -= set(connected) n -= 1 def dfs(i): global g, t, ts, visited lts = ts[i] t += 1 lts[0] = t visited[i] = 1 for c in g[i]: if not visited[c]: dfs(c) t += 1 lts[1] = t if root: for r in sorted(root): dfs(r) else: dfs(0) for i, v in enumerate(ts): print(i + 1, *v)
N, X, M = map(int, input().split()) existence = [False] * M a = [] A = X for i in range(N): if existence[A]: break existence[A] = True a.append(A) A = A * A % M for i in range(len(a)): if a[i] == A: break loop_start = i result = sum(a[:loop_start]) a = a[loop_start:] N -= loop_start loops = N // len(a) remainder = N % len(a) result += sum(a) * loops + sum(a[:remainder]) print(result)
0
null
1,432,303,633,988
8
75
import os, sys, re, math N = int(input()) P = [int(n) for n in input().split()] answer = 0 m = 2 * 10 ** 5 for p in P: if p <= m: answer += 1 m = p print(answer)
import sys input = sys.stdin.readline P = 2019 def main(): S = input().rstrip() N = len(S) count = [0] * P count[0] += 1 T = 0 for i in range(N): T = (T + int(S[(N - 1) - i]) * pow(10, i, mod=P)) % P count[T] += 1 ans = 0 for k in count: ans = (ans + k * (k - 1) // 2) print(ans) if __name__ == "__main__": main()
0
null
58,171,667,252,742
233
166
n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(1,len(a)): height_step = a[i] - a[i-1] if height_step < 0: ans -= height_step a[i] = a[i-1] print(ans)
n = input() list = map(int, input().split()) num = 1 a = 0 for i in list: if i == num: num = num +1 else: a = a + 1 if num == 1: print(-1) else: print(a)
0
null
59,514,259,249,732
88
257
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(input()) n,k = readInts() print(min(n%k,k - (n%k)))
# -*- coding: utf-8 -*- def get_input() -> str: """ 標準入力を取得する. Returns:\n str: 標準入力 """ S = input() return S def main(S: str) -> None: """ メイン処理. Args:\n S (str): 文字列(1 <= |S| <= 1000, 英子文字のみ) """ # 求解処理 ans = S if S[-1] == "s": ans += "es" else: ans += "s" # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 S = get_input() # メイン処理 main(S)
0
null
20,979,176,947,392
180
71
n = input() i = 1 num = [] while i <= n: if i % 3 == 0: num.append(i) i +=1 else: x = i while x > 0: if x % 10 == 3: num.append(i) break else: x /= 10 i += 1 print("{}".format(str(num)).replace("["," ").replace("]","").replace(",",""))
import sys input_num = int(sys.stdin.readline()) ans = '' for i in range(3, input_num + 1): if i % 3 == 0 or '3' in str(i): ans += ' ' + str(i) print ans
1
926,116,361,992
null
52
52
n = int(input()) m = int(n ** 0.5 + 1) for i in range(m,0,-1): if n % i == 0: print((i - 1) + ((n // i) - 1)) exit()
import sys def input(): return sys.stdin.readline().rstrip() series = [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] print(series[int(input())-1])
0
null
105,639,899,181,090
288
195
D, T , S = map(int,input().split()) move = T * S if move >= D: print('Yes') else: print('No')
n,a,b=map(int,input().split()) s=a+b if n%s==0: print(int(n/s)*a) else: if n%s>=a: print(int(n//s+1)*a) else: print(int(n//s)*a+n%s)
0
null
29,458,463,109,322
81
202
a, b, c, d = map(int, input().split()) ans = -float("INF") # 答えがマイナスになることがあるので、負の無限大を初期値にしておきます for x in (a, b): for y in (c, d): ans = max(ans, x * y) print(ans)
from collections import deque K = int(input()) if K <= 10: print(K) else: cnt = 9 l = deque(list(range(1,10))) while True: a = l.popleft() a1 = a% 10 if a1 != 0: a2 = a*10 + a1 - 1 cnt += 1 if cnt == K: print(a2) break l.append(a2) a2 = a*10 + a1 cnt += 1 if cnt == K: print(a2) break l.append(a2) if a1 != 9: a2 = a*10 + a1 + 1 cnt += 1 if cnt == K: print(a2) break l.append(a2)
0
null
21,520,259,944,480
77
181
import os import sys import numpy as np def solve(N, M, A): # n 以上上がる方法だけを試した時に、M 回以上の握手を行うことができるか ok = 0 ng = 202020 while ok + 1 < ng: c = ok+ng >> 1 cnt = 0 idx_A = N-1 for a1 in A: while idx_A >= 0 and A[idx_A]+a1 < c: idx_A -= 1 cnt += idx_A + 1 if cnt >= M: ok = c else: ng = c idx_A = N-1 cum_A = np.zeros(len(A)+1, dtype=np.int64) cum_A[1:] = np.cumsum(A) ans = 0 cnt = 0 for a1 in A: while idx_A >= 0 and A[idx_A]+a1 < ok: idx_A -= 1 cnt += idx_A + 1 ans += cum_A[idx_A+1] + (idx_A+1)*a1 ans -= (cnt-M) * ok return ans # >>> numba compile >>> numba_config = [ [solve, "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, M = map(int, input().split()) A = np.array(sorted(map(int, input().split()), reverse=True), dtype=np.int64) ans = solve(N, M, A) print(ans) main()
def main(): S, T = input().split() print(T + S) main()
0
null
105,884,004,860,412
252
248
s = list(input()) k = int(input()) n = len(s) ans = 0 # すべて同じ文字の場合 if s == [s[0]] * n: print((n*k)//2) exit(0) # 先頭と末尾が異なる場合 i = 1 while i < n: if s[i-1] == s[i]: t = 2 i+=1 while i < n and s[i-1] == s[i]: t+=1 i+=1 ans += (t//2)*k i+=1 if s[0] != s[-1]: print(ans) exit(0) # 先頭と末尾が一致する場合 # まず不一致の場合と同様に数えて、左右端の連続長さを数える # 連結したとき、左右の1ブロックのみはそのまま数えられる # 残りのk-1ブロックは、左右がつながった形で数えられる i = 1 left = 1 right = 1 for i in range(n): if s[i] == s[i+1]: left += 1 else: break for i in range(n-1, -1, -1): if s[i] == s[i-1]: right += 1 else: break if s[0] == s[-1]: ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2) print(ans)
N,M=map(int,input().split()) L=[list(input().split()) for i in range(M)] W=[0]*N A=[0]*N a=0 w=0 for i in range(M): if L[i][1]=="AC": A[int(L[i][0])-1]=1 elif L[i][1]=="WA" and A[int(L[i][0])-1]==0: W[int(L[i][0])-1]+=1 #for i in A: #a+=i #for i in W: #w+=i for i in range(N): if A[i]>0: a+=1 w+=W[i] print(a,w)
0
null
134,743,730,592,890
296
240
S = input() A = S.count("R") B = S.count("RR") if A==2: if B==1: print(2) if B==0: print(1) elif A==1: print(1) elif A==3: print(3) else : print(0)
def triangle(N, Ls): result = 0 res = [] numbers = {} edgeLength = list(set(Ls)) for i in edgeLength: numbers[i] = Ls.count(i) for i in range(len(edgeLength)): a = edgeLength[i] copy1 = edgeLength[i+1:] for j in range(len(copy1)): b = copy1[j] copy2 = copy1[j+1:] for k in range(len(copy2)): c = copy2[k] if a + b > c and b + c > a and c + a > b: res.append([a, b, c]) for val in res: result += numbers[val[0]] * numbers[val[1]] * numbers[val[2]] return result if __name__ == "__main__": N = list(map(int, input().split())) Ls = list(map(int, input().split())) print(triangle(N, Ls))
0
null
4,974,796,596,938
90
91
from sys import stdin input = stdin.buffer.readline a, b, c = map(int, input().split()) k = int(input()) cnt = 0 while b <= a: cnt += 1 b *= 2 while c <= b: cnt += 1 c *= 2 if cnt <= k: print('Yes') else: print('No')
S,T = input().split() print(T,S, sep='')
0
null
54,783,992,411,600
101
248
#dpでできないかな? 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 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 h,w=MI() lis=[list(SI()) for i in range(h)] al=[[-1]*w for i in range(h)] dp=[[inf]*w for i in range(h)] '''for i in range(h): for j in range(w): if lis[i][j]=="#": dp[i][j]=-1''' dp[0][0]= 0 if lis[0][0]=="." else 1 q=deque([[0,0]]) step=[[0,1],[1,0]] #print(lis) while q: x,y=q.popleft() if lis[x][y]==".": state=1 else: state=-1 for i,j in step: if x+i>h-1 or y+j>w-1: continue elif state==1: if al[x+i][y+j]<0: al[x+i][y+j]=0 q.append([x+i,y+j]) if lis[x+i][y+j]=="#": dp[x+i][y+j]=min(dp[x+i][y+j],dp[x][y]+1) else: dp[x+i][y+j]=min(dp[x+i][y+j],dp[x][y]) elif state==-1: if al[x+i][y+j]<0: al[x+i][y+j]=0 q.append([x+i,y+j]) dp[x+i][y+j]=min(dp[x+i][y+j],dp[x][y]) print(dp[-1][-1])
import sys sys.setrecursionlimit(10**6) def main(): h, w = map(int, input().split()) s = [input() for _ in range(h)] dp = [[10**5] * w for _ in range(h)] def func(temp, now, flag): x, y = now if y > h - 1 or x > w - 1: return 10**6 if s[y][x] == "#": if not flag: temp += 1 flag = True else: flag = False if x == w-1 and y == h-1: return temp if dp[y][x] <= temp: return 10**6 dp[y][x] = temp piyo = [] return min(func(temp, (x + 1, y), flag), func(temp, (x, y + 1), flag)) print(func(0, (0, 0), False)) main()
1
49,241,351,729,186
null
194
194
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): N = int(input()) A = list(map(int, input().split())) ans = 0 d = defaultdict(int) for a in A: d[a] += 1 ans += a Q = int(input()) for i in range(Q): B, C = map(int, input().split()) if d[B] != 0: ans -= B * d[B] ans += C * d[B] d[C] += d[B] d[B] = 0 print(ans) def main(): solve() if __name__ == '__main__': main()
from collections import defaultdict N=int(input()) count=defaultdict(int) *A,=map(int,input().split()) for i in range(N): count[A[i]] += 1 ans = 0 for k in count.keys(): ans += count[k]*k Q=int(input()) for q in range(Q): b,c = map(int,input().split()) ans += c*count[b] - b*count[b] count[c] += count[b] count[b] = 0 print(ans)
1
12,230,039,141,772
null
122
122
import math class Pos: def __init__(self, x, y): self.x = x self.y = y def __str__(self): return str(self.x) + ' ' + str(self.y) def koch_curve(i, n, start, end): if i < n: f = get_pos(start, end, 1/3) t = get_pos(start, end, 2/3) s = get_sec_pos(start, end, f, t) koch_curve(i + 1, n, start, f) print(f) koch_curve(i + 1, n, f, s) print(s) koch_curve(i + 1, n, s, t) print(t) koch_curve(i + 1, n, t, end) def get_pos(start, end, m): dX = (end.x - start.x) * m dY = (end.y - start.y) * m return Pos(start.x + dX, start.y + dY) def get_sec_pos(start, end, f, t): x = y = 0 if f.y == t.y: x = start.x + (end.x - start.x) / 2 len = math.fabs(t.x - f.x) h = math.sqrt(len**2 - (len/2)**2) if start.x < end.x: y = start.y + h else: y = start.y - h elif f.x < t.x and f.y < t.y: x = start.x y = t.y elif f.x > t.x and f.y < t.y: x = end.x y = f.y elif f.x > t.x and f.y > t.y: x = start.x y = t.y else: x = end.x y = f.y return Pos(x, y) n = int(input()) start = Pos(0, 0) end = Pos(100, 0) print(start) koch_curve(0, n, start, end) print(end)
import sys from math import sin, cos, radians input = sys.stdin.readline deg = radians(60) def Koch(n, p1_x, p1_y, p2_x, p2_y): if n != 0: s_x = (2 * p1_x + p2_x) / 3 s_y = (2 * p1_y + p2_y) / 3 t_x = (p1_x + 2 * p2_x) / 3 t_y = (p1_y + 2 * p2_y) / 3 u_x = (t_x - s_x) * cos(deg) - (t_y - s_y) * sin(deg) + s_x u_y = (t_x - s_x) * sin(deg) + (t_y - s_y) * cos(deg) + s_y Koch(n - 1, p1_x, p1_y, s_x, s_y) print('{:.8f} {:.8f}'.format(s_x, s_y)) Koch(n - 1, s_x, s_y, u_x, u_y) print('{:.8f} {:.8f}'.format(u_x, u_y)) Koch(n - 1, u_x, u_y, t_x, t_y) print('{:.8f} {:.8f}'.format(t_x, t_y)) Koch(n - 1, t_x, t_y, p2_x, p2_y) else: return n = int(input()) p1_x, p1_y = 0, 0 p2_x, p2_y = 100, 0 print('{:.8f} {:.8f}'.format(p1_x, p1_y)) Koch(n, p1_x, p1_y, p2_x, p2_y) print('{:.8f} {:.8f}'.format(p2_x, p2_y))
1
128,451,875,552
null
27
27
#!/usr/bin/env python3 import bisect import heapq import itertools import math import numpy as np from collections import Counter, defaultdict, deque from copy import deepcopy from decimal import Decimal from math import gcd from operator import add, itemgetter, mul, xor def cmb(n,r,mod): bunshi=1 bunbo=1 for i in range(r): bunbo = bunbo*(i+1)%mod bunshi = bunshi*(n-i)%mod return (bunshi*pow(bunbo,mod-2,mod))%mod mod = 10**9+7 def I(): return int(input()) def LI(): return list(map(int,input().split())) def MI(): return map(int,input().split()) def LLI(n): return [list(map(int, input().split())) for _ in range(n)] #いまいるところ, #listとnが与えられたときn回テレポートしたところを出力する def now_place(li,n): now = 1 for i in range(n): now = li[now-1] return now #p回のテレポートでたどってきた道筋のルートを返す def root(li,p): ans = [] now = 1 for j in range(p): ans.append(now_place(li,j+1)) return ans n,k = MI() a = LI() #訪れたところのメモがtown town = [] #訪れたかどうかを0と1で管理 visit=[0]*n p = 1 while visit[p-1] == 0: town.append(p) visit[p-1] = 1 p = a[p-1] #香りだかい町がいつでてきたか→周期に入るまでのテレポート回数 #len(town[l:])は周期を表す l = town.index(p) if k <len(town): print(town[k]) else: print(town[l + (k-l)%(len(town[l:]))])
#!/usr/bin/env python3 def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) Acnt = [0] * N Acnt[0] = 1 telepo = [1] i = 0 while True: Acnt[A[i] - 1] += 1 if Acnt[A[i] - 1] > 1: break telepo.append(A[i]) i = A[i] - 1 roop_s = telepo.index(A[i]) roop = len(telepo) - roop_s ans = 0 if K < roop_s: ans = K else: ans = K - roop_s ans %= roop ans += roop_s print(telepo[ans]) if __name__ == "__main__": main()
1
22,655,756,329,358
null
150
150
class Dice(object): def __init__(self, n): self.n = n def move(self, to): if to == 'N': self.n[0], self.n[1], self.n[4], self.n[5] = self.n[1], self.n[5], self.n[0], self.n[4] elif to == 'E': self.n[0], self.n[2], self.n[3], self.n[5] = self.n[3], self.n[0], self.n[5], self.n[2] elif to == 'S': self.n[0], self.n[1], self.n[4], self.n[5] = self.n[4], self.n[0], self.n[5], self.n[1] elif to == 'W': self.n[0], self.n[2], self.n[3], self.n[5] = self.n[2], self.n[5], self.n[0], self.n[3] def top(self): return self.n[0] dice = Dice([int(i) for i in input().split()]) move = input() for m in move: dice.move(m) print(dice.top())
class Dice: def __init__(self, list1): self.f = list1 def move(self, direct): if direct == "N": self.f[0], self.f[1], self.f[4], self.f[5] = self.f[1], self.f[5], self.f[0], self.f[4] return self.f elif direct == "E": self.f[0], self.f[2], self.f[3], self.f[5] = self.f[3], self.f[0], self.f[5], self.f[2] return self.f elif direct == "S": self.f[0], self.f[1], self.f[4], self.f[5] = self.f[4], self.f[0], self.f[5], self.f[1] return self.f elif direct == "W": self.f[0], self.f[2], self.f[3], self.f[5] = self.f[2], self.f[5], self.f[0], self.f[3] return self.f data = list(map(int, input().split())) direction = input() dice = Dice(data) for i in direction: dice.move(i) print(dice.f[0])
1
241,621,017,298
null
33
33
def resolve(): a = int(input()) print(a + a ** 2 + a ** 3) resolve()
import sys input = sys.stdin.readline n,a,b=map(int,input().split()) val = n//(a+b) pos = n%(a+b) if pos>a: pos = a print(val*a + pos)
0
null
32,979,633,492,608
115
202
import sys input = sys.stdin.readline def inp(): return(int(input())) def inpf(): return(float(input())) def inps(): return str(input()) n = inp() arr= [] cac = 0 cwa = 0 ctle = 0 cra = 0 for i in range(n): s = inps().rsplit()[0] if s=="AC": cac+=1 elif s=="WA": cwa+=1 elif s=="TLE": ctle+=1 else: cra+=1 c = [cac, cwa, ctle, cra] s = ["AC x ", "WA x ", "TLE x ", "RE x "] for i in range(len(s)): print(s[i]+str(c[i]))
N=int(input()) S = [0]*N for i in range(N): S[i]=str(input()) print('AC x {0}'.format(S.count('AC'))) print('WA x {0}'.format(S.count('WA'))) print('TLE x {0}'.format(S.count('TLE'))) print('RE x {0}'.format(S.count('RE')))
1
8,655,260,225,808
null
109
109
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) dist = abs(a - b) vd = v - w if vd > 0: if 0 <= dist/vd/t <= 1: print("YES") else: print("NO") elif vd == 0 and dist == 0: print("YES") else: print("NO")
#151_E n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) mod = 10 ** 9 + 7 f = [1 for _ in range(n)] f_inv = [1 for _ in range(n)] for i in range(2, n): f[i] = (f[i-1] * i) % mod f_inv[i] = pow(f[i], mod-2, mod) def comb(n,k): return f[n]*f_inv[k]*f_inv[n-k]%mod ans = 0 for i in range(n-k+1): ans = (ans + comb(n-i-1, k-1) * (a[-i-1]-a[i]))%mod print(ans)
0
null
55,421,587,171,680
131
242
H, N = map(int, input().split(' ')) A_ls = map(int, input().split(' ')) if sum(A_ls) >= H: print('Yes') else: print('No')
while True: x, y = list(map(int, input().split())) if (x == 0 and y == 0) : break if (x < y) : print(str(x) + " " + str(y)) else : print(str(y) + " " + str(x))
0
null
39,287,680,963,952
226
43
n, d = map(int, input().split()) d_t = d**2 r = 0 for i in range(n): a, b = map(int, input().split()) if d_t >= a**2 + b**2: r += 1 print(r)
from collections import defaultdict def combination(a, b): if b > a - b: return combination(a, a - b) return fact[a] * ifact[b] * ifact[a-b] MOD = 10**9+7 n, k = map(int, input().split()) k = min(k, n-1) # 階乗を前処理 fact = defaultdict(int) fact[0] = 1 for i in range(1, n+1): fact[i] = fact[i-1] * i fact[i] %= MOD # 階乗の逆元を前処理 ifact = defaultdict(int) ifact[n] = pow(fact[n], MOD-2, MOD) for i in reversed(range(1, n + 1)): ifact[i-1] = ifact[i] * i ifact[i-1] %= MOD ans = 0 for i in range(k+1): ans += combination(n, i) * combination((n-i-1)+i, i) ans %= MOD print(ans % MOD)
0
null
36,421,486,180,698
96
215
S = input() T = input() if T[0:len(T) - 1] == S: print("Yes") else: print("No")
s, t = [input() for _ in range(2)] print('Yes' if s == t[:len(s):] else 'No')
1
21,361,546,459,420
null
147
147
# import itertools # import math # import sys import numpy as np # N = int(input()) # S = input() # n, *a = map(int, open(0)) N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) # S = input() # d = sorted(d.items(), key=lambda x:x[0]) # keyでsort # all_cases = list(itertools.permutations(P)) # a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N)) # print(a[0][0]) # print(conditions[0]) A = np.array(A) B = np.array(B) cum_A = np.cumsum(A) cum_A = np.insert(cum_A, 0, 0) cum_B = np.cumsum(B) cum_B = np.insert(cum_B, 0, 0) j = M max_num = 0 for i in range(N + 1): while(True): # j -= 1 if j < 0: break minute = cum_A[i] + cum_B[j] if minute <= K: if i + j > max_num: max_num = i + j break j -= 1 print(max_num)
N, M, K = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) Asum = [0] Bsum = [0] a = 0 b = 0 for i in range(N): a += A[i] Asum.append(a) for i in range(M): b += B[i] Bsum.append(b) Asum.append(0) Bsum.append(0) res, j = 0, M for i in range(N+1): if Asum[i] > K: break while Asum[i] + Bsum[j] > K: j -= 1 res = max(res,i+j) print(res)
1
10,840,491,527,200
null
117
117
import numpy as np from itertools import combinations from itertools import permutations from math import factorial N = int(input()) xy = np.array([list(map(int, input().split())) for _ in range(N)]) cnt = 0 for i in xy: for j in xy: cnt += np.linalg.norm(i - j) print(cnt / N)
n = int(input()) x = [] y = [] for _ in range(n): a,b = map(int,input().split()) x.append(a) y.append(b) ans = 0 for i in range(n): for j in range(n): ans += ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5 print(ans/n)
1
148,017,327,258,330
null
280
280
print((lambda x:('Yes' if (x[1] <= x[0]*500) else 'No'))(list(map(int,input().split()))))
N=list(map(int,input().split())) temp = sum(N) if temp%9 == 0:print("Yes") else:print("No")
0
null
51,252,540,571,860
244
87
import math X = int(input()) i = 1 while True: net = (i * X)/360 if math.floor(net) == math.ceil(net): break else: i+=1 print(i)
print(float(input()) * 2.0 * 3.141592653589)
0
null
22,221,491,693,580
125
167
n = int(input()) minv = int(input()) maxv = -1000000000 for r in [int(input()) for i in range(1,n)]: maxv = max(maxv,r-minv) minv = min(r,minv) print(maxv)
N=int(input()) A=list(map(int,input().split())) ans=[0] cnt=0 hit=0 while cnt<N: if ans[hit]+1==A[cnt]: hit+=1 ans.append(hit) cnt+=1 print(N-len(ans[1:]) if len(ans)>1 else -1)
0
null
57,514,094,691,778
13
257
n,k,c=map(int,input().split()) s=list(input()) for i in range(len(s)): if s[i]=="o": s[i]=True else: s[i]=False i=0 work1=[] while len(work1)<k: if s[i]: work1.append(i) i+=c+1 else: i+=1 i=n-1 work2=[] while len(work2)<k: if s[i]: work2.append(i) i-=c+1 else: i-=1 work2.sort() for i in range(k): if work1[i]==work2[i]: print(work1[i]+1)
n = int(input()) answer = 0 for i in range(1, n+1): md = n // i answer += i * (md *(md+1) // 2) print(answer)
0
null
25,864,801,026,180
182
118
n,k=map(int,input().split()) H = list(map(int, input().split())) if n <= k: print('0') exit() H.sort() H.reverse() print(sum(H)-sum(H[0:k]))
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]))
1
79,192,248,731,176
null
227
227
n,x,m = map(int, input().split()) be = x % m ans = be memo = [[0,0] for i in range(m)] am = [be] memo[be-1] = [1,0] #len-1 for i in range(n-1): be = be**2 % m if be == 0: break elif memo[be-1][0] == 1: kazu = memo[be-1][1] l = len(am) - kazu syou = (n-i-1) // l amari = (n-i-1)%l sum = 0 for k in range(kazu, len(am)): sum += am[k] ans = ans + syou*sum if amari > 0: for j in range(kazu,kazu + amari): ans += am[j] break else: ans += be am.append(be) memo[be-1][0] = 1 memo[be-1][1] = len(am) -1 print(ans)
n, x, m = [int(_) for _ in input().split()] d = {} d_rev = {} d[x] = 0 d_rev[0] = x c = 0 while True: c += 1 x = (x ** 2) % m if x in d: roop_idx = d[x] break else: d[x] = c d_rev[c] = x ans = 0 if roop_idx >= n: for i in range(n): ans += d_rev[i] print(ans) else: for i in range(roop_idx): ans += d_rev[i] roop_num = len(d) - roop_idx roop_sum = 0 for i in range(roop_idx, len(d)): roop_sum += d_rev[i] ans += ((n-roop_idx)//roop_num) * roop_sum roop_last = (n-roop_idx)%roop_num for i in range(roop_last): ans += d_rev[roop_idx + i] print(ans)
1
2,820,784,261,592
null
75
75
N, K = map(int, input().split()) mod = 1000000007 ans = 0 for i in range(K, N+1+1): num_min = i*(i-1)//2 num_max = i*(N+N-i+1)//2 # print(num_min, num_max) ans += (num_max - num_min + 1)%mod print(ans%mod)
N, K = map(int,input().split()) MOD = 10**9 + 7 ans = 0 for k in range(K,N+2): m = (k*(k-1))//2 M = (k*(N+N-k+1))//2 ans += M-m+1 print(ans%MOD)
1
32,966,117,323,688
null
170
170