code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
N = int(input()) if N%2 == 0: print(0.5) else: print((N+1)/2/N)
import sys N = int(input()) if not ( 1 <= N <= 100 ):sys.exit() print(1-(int(N/2)/N))
1
176,735,848,511,882
null
297
297
n = input() n = n.split() m = int(n[1]) n = int(n[0]) a = input() a = a.split() c = int(a[0]) for b in range(n-1): c = c + int(a[b+1]) c = c / (4 * m) e = 0 for d in range(n): if int(a[d]) >= c : e = e + 1 if e >= m: print("Yes") else: print("No")
ring_str=input() key=input() ring_str+=ring_str if key in ring_str: print('Yes') else: print('No')
0
null
20,136,335,717,410
179
64
s = input() t = input() i = 0 for key, val in enumerate(s): if (val != t[key]): i+=1 print(i)
n,d = map(int,input().split(" ")) ans = 0 for i in range(n): a,b = map(int,input().split(" ")) if (a*a + b*b) <= d*d: ans += 1 print(ans)
0
null
8,261,564,743,936
116
96
import sys sys.setrecursionlimit(2147483647) INF = 1 << 60 MOD = 10**9 + 7 # 998244353 input = lambda:sys.stdin.readline().rstrip() from functools import cmp_to_key def resolve(): n = int(input()) positive, negative = [], [] for _ in range(n): balance = min_balance = 0 for c in input(): if c == '(': balance += 1 else: balance -= 1 min_balance = min(min_balance, balance) if balance > 0: positive.append((min_balance, balance)) else: negative.append((min_balance, balance)) now = 0 # positive は min_balance の大きい方から足せば良い positive.sort(reverse = 1) for min_balance, balance in positive: if now + min_balance < 0: print("No") return now += balance # negative は sort を工夫 def cmp(s1, s2): m1, b1 = s1 m2, b2 = s2 return -1 if min(m1, b1 + m2) > min(m2, b2 + m1) else 1 negative.sort(key = cmp_to_key(cmp)) for min_balance, balance in negative: if now + min_balance < 0: print("No") return now += balance print("Yes" if now == 0 else "No") resolve()
a=int(input()) if a==11 or a==13 or a==17 or a==19 or a==22 or a==23 or a==26 or a==29 or a==31 or a==33 or a==34 or a==37 or a==38 or a==39 or a==41 or a==43 or a==44 or a==46 or a==47 or a==50 or a==51 or a==52 or a==53 or a==55 or a==57 or a==58 or a==59 or a==60 or a==61 or a==62 or a==65 or a==66 or a==67 or a==68 or a==69 or a==70 or a==71 or a==73 or a==74 or a==75 or a==76 or a==77 or a==78 or a==79 or a==80 or a>=82: print("No") else: print("Yes")
0
null
91,634,453,253,502
152
287
n=int(input()) s=str(input()) if(n%2!=0): print('No') else: if(s[0:len(s)//2]==s[len(s)//2:]): print('Yes') else: print('No')
N = int(input()) a = input().split(" ") print(" ".join(reversed(a)))
0
null
73,854,167,811,306
279
53
N = int(input()) P = list(map(int, input().split())) temp = P[0] res = 1 for i in range(1,N): if P[i] <= temp: temp = P[i] res += 1 print(res)
n = int(input()) p = list(map(int, input().split())) count = 0 for i in range(n) : if i == 0 : mn = p[i] count += 1 else : if mn > p[i] : mn = p[i] count += 1 print(count)
1
85,838,260,563,848
null
233
233
N,M=map(int,input().split()) A=list(map(int,input().split())) B=[i for i in A if i >= sum(A)/(4*M)] print("Yes" if len(B)>=M else "No")
###################### # _ ____ # # U /"\ u U /"___| # # \/ _ \/ \| | u # # / ___ \ | |/__ # # /_/ \_\ \____| # # \\ >> _// \\ # # (__) (__)(__)(__) # # Compro by NULL_CT© # ###################### from sys import stdin import numpy as np import math input = stdin.readline def divisor(_n): result = [] for i in range(1, int(math.sqrt(_n)) + 1): if _n % i == 0: result.append(i) if _n % (_n / i) == 0: result.append(int(_n / i)) return result k,x = map(int,input().split()) if 500 * k >= x: print("Yes") else: print("No")
0
null
68,306,395,138,520
179
244
x,y,a,b,c=map(int,input().split()) p=sorted(list(map(int,input().split())),reverse=1)[:x] q=sorted(list(map(int,input().split())),reverse=1)[:y] r=sorted(list(map(int,input().split())),reverse=1) pq=sorted(p+q,reverse=1) ans=sum(pq) n=len(r) count=-1 for i in range(n): if r[i]>pq[count]: ans+=(r[i]-pq[count]) count-=1 print(ans)
# -*- coding:utf-8 -*- def Selection_Sort(A,n): for i in range(n): mini = i for j in range(i,n): #i以上の要素において最小のAをminiに格納 if int(A[j][1]) < int(A[mini][1]): mini = j if A[i] != A[mini]: A[i], A[mini] = A[mini], A[i] return A def Bubble_Sort(A, n): for i in range(n): for j in range(n-1,i,-1): if int(A[j][1]) < int(A[j-1][1]): A[j], A[j-1] = A[j-1], A[j] return A n = int(input()) A = input().strip().split() B = A[:] A = Bubble_Sort(A,n) print (' '.join(A)) print ("Stable") B =Selection_Sort(B,n) print (' '.join(B)) if A == B: print ("Stable") else: print ("Not stable")
0
null
22,277,684,941,632
188
16
import math a = int(input()) if a%2 == 0: print(int((a/2-1))) else: b = int(math.floor(a/2)) print(b)
n,*l=map(int,open(0).read().split()) a=t=0 for i in l: if i>t: t=i a+=t-i print(a)
0
null
78,476,964,326,372
283
88
whxyr = input().split() [w, h, x, y, r] = [int(x) for x in whxyr] if 0 <= x - r and x + r <= w and 0 <= y - r and y + r <= h: print("Yes") else: print("No")
import cmath cmp_s = cmath.rect(1/3, 0) cmp_u = cmath.rect(3**(-1/2), cmath.pi / 6) cmp_t = cmath.rect(2/3, 0) def koch_curve(p1: complex, p2: complex, n): if n != 0: cmp = p2 - p1 s, u, t = [p1 + cmp * c for c in (cmp_s, cmp_u, cmp_t)] koch_curve(p1, s, n-1) print('{0:8f} {1:8f}'.format(s.real, s.imag)) koch_curve(s, u, n-1) print('{0:8f} {1:8f}'.format(u.real, u.imag)) koch_curve(u, t, n-1) print('{0:8f} {1:8f}'.format(t.real, t.imag)) koch_curve(t, p2, n-1) def main(): n = int(input()) print('{0:8f} {1:8f}'.format(.0, .0)) koch_curve(complex(.0, .0), complex(100.0, .0), n) print('{0:8f} {1:8f}'.format(100.0, .0)) if __name__ == '__main__': main()
0
null
289,714,427,958
41
27
import sys from heapq import heappush, heappop, heapify import math from math import gcd import itertools as it from collections import deque def inp(): return int(input()) def inpl(): return list(map(int, input().split())) INF = 1001001001 # --------------------------------------- n, k = inpl() p = [0] + inpl() c = [0] + inpl() ans = - INF for i in range(1, n + 1): cycle_cnt = 0 cycle_sum = 0 v = i while True: v = p[v] cycle_cnt += 1 cycle_sum += c[v] if v == i: break cnt = 0 path = 0 while True: v = p[v] cnt += 1 path += c[v] if cnt > k: break num = (k - cnt) // cycle_cnt score = path + max(0, cycle_sum) * num ans = max(ans, score) if v == i: break print(ans)
str=input() l=len(str) n=0 while l>0: n=n+int(str[l-1]) l=l-1 if n%9 == 0: print("Yes") else : print("No")
0
null
4,887,401,696,452
93
87
def backtrack(books, cur_book_ids, threshold, result): if len(cur_book_ids) > len(books): return if len(cur_book_ids) == len(books): achieved = True price_skills = [0] * len(books[0]) for book,is_bought in zip(books, cur_book_ids): for j in range(len(book)): price_skills[j] += book[j]*is_bought for i in range(1, len(price_skills)): if price_skills[i] < threshold: achieved = False if achieved: if not result: result.append(price_skills[0]) else: result[0] = min(result[0], price_skills[0]) for i in (0,1): cur_book_ids.append(i) backtrack(books, cur_book_ids, threshold, result) cur_book_ids.pop() def solve(): N,M,X = [int(i) for i in input().split()] books = [] for i in range(N): book = [int(i) for i in input().split()] books.append(book) result = [] backtrack(books, [], X, result) if not result: print(-1) else: print(result[0]) if __name__ == "__main__": solve()
n,m,x=map(int,input().split()) c=[list(map(int,input().split())) for _ in range(n)] ans=float('inf') for i in range(2**n): data=[0]*(m+1) for j in range(n): if i&(1<<j): for k in range(m+1): data[k]+=c[j][k] cnt=0 for l in range(1,m+1): if data[l]>=x: cnt+=1 if cnt==m: ans=min(ans,data[0]) if ans==float('inf'): print(-1) exit() print(ans)
1
22,201,847,575,420
null
149
149
import sys stdin = sys.stdin def main(): N = int(stdin.readline().rstrip()) A = list(map(int,stdin.readline().split())) mod = 10**9+7 ans = 0 for i in range(61): bits = 0 for x in A: if (x>>i)&1: bits += 1 ans += ((bits*(N-bits))* 2**i) %mod ans %= mod print(ans) main()
n = int(input()) t = 0 h = 0 for i in range(n): taro,hana = input().split() if taro == hana: t += 1 h += 1 else: m = list((taro,hana)) m.sort() if m == list((taro,hana)): h += 3 else: t += 3 print("{} {}".format(t,h))
0
null
62,155,196,547,224
263
67
from collections import Counter N = int(input()) A = [int(x) for x in input().split()] c = Counter(A) ans = 0 for i in c: ans += c[i] * (c[i] - 1) // 2 for i in range(len(A)): if c[A[i]] == 1: print(ans) else: tmp = c[A[i]] print(ans - tmp * (tmp - 1) // 2 + (tmp - 1) * (tmp - 2) // 2)
""" スニペット """ def get_int(): return int(input()) def get_ints(): return list(map(int, input().split())) """ スニペット """ import math # 2つ選ぶ通り数を算出 nC2 def choose2(n): return math.floor(n*(n-1)/2) # インプット N = get_int() An = get_ints() """ 全ての要素から2つのボールを選ぶ通り数を求める """ uni = [0] * (N+1) # ユニーク数の配列を求める for i in range(N): uni[An[i]] += 1 sumWay = 0 # 各数値の2通りの選択通り数を足していく ここのindex=0がいらない for i in range(N+1): sumWay += choose2(uni[i]) """ 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """ for i in range(N): print(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1))
1
47,962,626,778,650
null
192
192
arr = "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".split(", ") K = int(input()) print(arr[K-1])
N = int(input()) A = list(map(int, input().split())) Q = int(input()) B = [] C = [] for q in range(Q): b, c = map(int, input().split()) B.append(b) C.append(c) sam = sum(A) baketu = [0]*(100001) for a in A: baketu[a] += 1 for q in range(Q): sam = sam + baketu[B[q]] * (C[q] - B[q]) baketu[C[q]] += baketu[B[q]] baketu[B[q]] = 0 #print(baketu) print(sam)
0
null
31,120,223,440,130
195
122
a, b, c = map(int, input().split()) if(a < b and b < c): print('Yes') else: print('No')
# coding: utf-8 board = ['#', '.'] while True: h, w = map(int, input().split()) if h == 0 and w == 0: exit() for row in range(h): for column in range(w): print(board[(row + column) % 2], end='') print() print()
0
null
634,903,301,990
39
51
from scipy.sparse import* f=csgraph.johnson n,m,l,*t=map(int,open(0).read().split()) m*=3 [*map(print,f(f(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1)]
from scipy.sparse.csgraph import csgraph_from_dense from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall import numpy as np N,M,L=map(int,input().split()) A=[0]*M B=[0]*M C=[0]*M for i in range(M): A[i],B[i],C[i] = map(int,input().split()) A[i] -=1 B[i] -=1 Q=int(input()) ST=[list(map(int,input().split())) for _ in range(Q)] G = csr_matrix((C, (A, B)), shape=(N, N)) d = floyd_warshall(G, directed=False) G=np.full((N,N), np.inf) G[d<=L]=1 G = csr_matrix(G) E = floyd_warshall(G, directed=False) for s,t in ST: if E[s-1][t-1]==float('inf'): print(-1) else: print(int(E[s-1][t-1]-1))
1
173,411,990,849,238
null
295
295
a = list(input()) b = list(input()) flag = True for i,j in enumerate(a): if j !=b[i]: print('No') flag = False break if flag == True: print('Yes')
S=str(input()) T=str(input()) if S==T[:-1]: print('Yes') else: print('No')
1
21,258,281,033,262
null
147
147
a = int(input()) if a % 2 is 0: print(a // 2 - 1) else: print(a // 2)
n=int(input()) n=n-1 print (n//2)
1
153,238,839,750,212
null
283
283
#Exhaustive Search (bit全探索ver) n = int(input()) A = list(map(int,input().split())) q = int(input()) m = list(map(int,input().split())) count_list = [] for i in range(1<<n): copy_A = A.copy() count = 0 for j in range(n): mask = 1 << j if mask & i != 0: count += A[j] count_list.append(count) for k in m: if k in count_list: print('yes') else: print('no')
from numba import njit, i8 @njit(i8(i8)) def solve(N): ans = 0 for i in range(1, N + 1): j = N // i ans += j * (j + 1) // 2 * i return ans N = int(input()) print(solve(N))
0
null
5,517,710,009,120
25
118
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import itertools import math import sys INF = float('inf') def solve(A: int, B: int, C: int, K: int): return min(K, A) - max(K-A-B, 0) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int K = int(next(tokens)) # type: int print(solve(A, B, C, K)) if __name__ == '__main__': main()
a, b, c, k = (int(i) for i in input().split()) res = 1 * min(a, k) + 0 * min(b, max(0, k - a)) + -1 * min(c, max(0, k - a - b)) print(res)
1
21,798,338,312,322
null
148
148
r=int(input()) import math c=2*r*math.pi print("{0:.6}".format(c))
r=int(input()) pi=3.14159265358979323846 a=2*pi*r print(a)
1
31,374,087,100,828
null
167
167
n=int(input()) a=list(map(int,input().split())) if a[0]!=0: print(0) exit() r=1 b=0 g=0 pos=3 for i in range(1,n): pre=0 de=0 if a[i]==r: pre += 1 r += 1 de=1 if a[i]==b: pre += 1 if de==0: b += 1 de=1 if a[i]==g: pre += 1 if de==0: g += 1 pos *= pre print(pos%(10**9+7))
x=list(map(int,input())) if x[-1]==2 or x[-1]==4 or x[-1]==5 or x[-1]==7 or x[-1]==9: print("hon") elif x[-1]==0 or x[-1]==1 or x[-1]==6 or x[-1]==8: print("pon") else: print("bon")
0
null
75,063,940,686,552
268
142
import itertools import decimal import math import collections import sys input = sys.stdin.readline T=input() T=T.replace('?','D') print(T)
N=int(input()) arms=[list(map(int,input().split())) for _ in range(N)] points=[] for i in range(N): points.append([arms[i][0]-arms[i][1],arms[i][0]+arms[i][1]]) #print(points) points.sort(key=lambda x:x[1]) #print(points) nowr=-float("inf") cnt=0 for i in points: l,r=i if nowr<=l: nowr=r cnt=cnt+1 print(cnt)
0
null
54,335,987,189,860
140
237
N, X, M = map(int, input().split()) ans = 0 flag = [0]*(10**5 + 2) lst = [X] for i in range(N): X = (X**2)%M if flag[X] == 1: break flag[X] = 1 lst.append(X) preindex = lst.index(X) preloop = lst[:preindex] loop = lst[preindex:] loopnum = (N - len(preloop))//len(loop) loopafternum = (N - len(preloop))%len(loop) ans = sum(preloop) + sum(loop)*loopnum + sum(loop[:loopafternum]) print(ans)
n = int(input()) a = list(map(int,input().split())) tmp = [0] * (n+1) ans = 0 for i in range(n): tmp[a[i]] += 1 for i in range(1,len(tmp)): if tmp[i] > 1: ans += int(tmp[i] * (tmp[i] - 1) / 2) for i in range(n): if tmp[a[i]] > 1: print(ans - int(tmp[a[i]] * (tmp[a[i]] - 1) / 2) + int((tmp[a[i]] - 1) * (tmp[a[i]] - 2) / 2)) else: print(ans)
0
null
25,166,388,787,680
75
192
ini = lambda : int(input()) inm = lambda : map(int,input().split()) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors #maincode------------------------------------------------- n = ini() s = input() r = s.count('R') g = s.count('G') b = s.count('B') ans = r*g*b for j in range(n): for i in range(j): k = 2*j-i if k < n: if (s[i] == s[j]): continue if (s[i] == s[k]): continue if (s[j] == s[k]): continue ans -= 1 print(ans)
import copy n = int(input()) s = list(input()) cnt = [[0]*n for i in range(3)] r, g, b = 0, 0, 0 for i in range(n-1, -1, -1): if s[i] == 'R': r += 1 cnt[0][i] = copy.deepcopy(r) cnt[1][i] = copy.deepcopy(g) cnt[2][i] = copy.deepcopy(b) if s[i] == 'G': g += 1 cnt[0][i] = copy.deepcopy(r) cnt[1][i] = copy.deepcopy(g) cnt[2][i] = copy.deepcopy(b) if s[i] == 'B': b += 1 cnt[0][i] = copy.deepcopy(r) cnt[1][i] = copy.deepcopy(g) cnt[2][i] = copy.deepcopy(b) ans = 0 t = ['R', 'G', 'B'] for i in range(n-2): for j in range(i+1,n-1): if s[i] == s[j] : continue if s[i] != 'R' and s[j] != 'R': k = 0 elif s[i] != 'G' and s[j] != 'G': k = 1 else: k = 2 if 2*j - i < n and s[2*j - i] == t[k]: ans += cnt[k][j+1] - 1 else: ans += cnt[k][j+1] print(ans)
1
35,975,821,484,122
null
175
175
print("A" if input().isupper() else "a")
A=input() if str.isupper(A): print('A') else: print('a')
1
11,300,559,311,934
null
119
119
N=int(input()) c=input() right_r=0 right_w=0 left_r=0 left_w=0 for i in range(N): if c[i]=='R': right_r+=1 else: right_w+=1 ans=right_r for j in range(N): cnt=0 if c[j]=='W': left_w+=1 right_w-=1 else: left_r+=1 right_r-=1 if right_r<=left_w: cnt+=right_r cnt+=left_w-right_r else: cnt+=left_w cnt+=right_r-left_w if cnt<ans: ans=cnt print(ans)
n=int(input()) c=input() r_cnt=c.count('R') w_cnt=c.count('W') last_c='R'*r_cnt+'W'*w_cnt num=0 for i in range(n): if c[i]!=last_c[i]: num+=1 print((num+2-1)//2)
1
6,261,494,924,860
null
98
98
N,K = map(int,input().split()) count = N//K N = abs( N - count*K ) N_2 = abs( N - K ) print( N if N <= N_2 else N_2 )
N, K = list(map(int, input().split())) if abs(N - K) > N: print(N) else: if N % K == 0: N = 0 else: N = abs(N % K - K) print(N)
1
39,497,393,316,480
null
180
180
import sys import math input = sys.stdin.readline ceil = math.ceil def main(): def isok(z,val):##適宜変更 return (z-val<=2*d) def bisect(ls,val): ##valの関数isok(x,val)がTrueとなる一番右のindex を返す 全部Falseなら-1 ok = -1 ng = len(ls) idx = (ok+ng)//2 while ng-ok>1: num = ls[idx] if isok(num,val): ok = idx else: ng = idx idx = (ok+ng)//2 return ok ##一番右のTrueのindex Trueの個数はok+1こ n,d,a = map(int,input().split()) mon = [] for i in range(n): x,h = map(int,input().split()) mon.append((x,h)) mon.sort() keys = [ls[0] for ls in mon] #bisect用の配列 damage = [0]*(n+1) ans = 0 for i in range(n): x,h = mon[i] res = h-damage[i] if res>0:##体力が残ってたら c = ceil(res/a) ans+=c idx = bisect(keys,x) ##爆風が届くぎりぎりの位置 if idx==-1:continue damage[i] +=a*c damage[idx+1] -=a*c damage[i+1] += damage[i] print(ans) if __name__=="__main__": main()
import sys from collections import deque from bisect import bisect_right from math import ceil def input(): return sys.stdin.readline().strip() N, D, A = map(int, input().split()) monsters = [(-1, -1)] for _ in range(N): x, h = map(int, input().split()) monsters.append((x, h)) monsters.sort() #print("monsters = {}".format(monsters)) """ どうせ左端のモンスターはいつか倒さないといけない(かつ爆弾投下順は不問)ので、 左端のモンスターから順に、なるべく爆弾を右に寄せて落としていけば良い。 別解としてBITでも殴ってみた """ class BIT: """ https://tjkendev.github.io/procon-library/python/range_query/bit.html Binary index treeの実装 配列[a1, a2,...,an]に対して以下のクエリをO(logn)で行う: 1. aiにxを加える 2. 区間和 ai + a(i+1) + ... + aj の和を求める """ def __init__(self, n): """ 添字は1スタート """ self.n = n self.data = [0] * (n + 1) self.el = [0] * (n + 1) def add(self, i, x): """ i>0に対してaiにxを加算(x < 0でもOK) """ if i <= 0 or self.n < i: print("i should be within 1 to n") else: self.el[i] += x while i <= self.n: self.data[i] += x i += i & -i def sum(self, i): """ 添字1からiまでの累積和を求める """ s = 0 while i > 0: s += self.data[i] i -= i & -i return s def get(self, i, j=None): """ 添字iからjまでの累積和を求める j=Noneの場合はaiの値を返す """ if j is None: return self.el[i] return self.sum(j) - self.sum(i - 1) """ BITで区間に対する加算をする場合はimos法を利用することに注意する """ Damage = BIT(N) ans = 0 for i in range(1, N + 1): x, h = monsters[i] d = Damage.sum(i) # モンスターiに入っているダメージ if d < h: times = ceil((h - d) / A) ans += times new_damage = times * A #print("ans+={} for monster {}".format(times, i)) idx = bisect_right(monsters, (monsters[i][0] + 2 * D, 10**10)) Damage.add(i, new_damage) if idx != N + 1: Damage.add(idx, -new_damage) print(ans)
1
82,013,353,753,760
null
230
230
while True: m, f, r = map(int, input().split()) if m == -1 and f== -1 and r == -1: break mf = m + f if m == -1 or f == -1 or mf < 30: print('F') elif mf < 50: if r < 50: print('D') else: print('C') elif mf < 65: print('C') elif mf < 80: print('B') else: print('A')
n,k=map(int,input().split()) hlist=list(map(int,input().split())) counter=0 for h in hlist: if h >= k: counter += 1 print(counter)
0
null
90,130,397,158,500
57
298
# https://atcoder.jp/contests/keyence2020/tasks/keyence2020_c n, k, s = map(int, input().split()) if s == 10 ** 9: ans = [1] * n for i in range(k): ans[i] = s else: ans = [s + 1] * n for i in range(k): ans[i] = s print(*ans)
n, k, s = map(int, input().split()) L = [0] * n for i in range(n): if i < k: L[i] = s else: if s != 10 ** 9: L[i] = s + 1 else: L[i] = s - 1 print(*L)
1
90,597,711,874,110
null
238
238
from collections import deque n,u,v=map(int,input().split()) g=[set([]) for _ in range(n+1)] for i in range(n-1): a,b=map(int,input().split()) g[a].add(b) g[b].add(a) leaf=[] for i in range(1,n+1): if(len(g[i])==1): leaf.append(i) d_u=[-1 for _ in range(n+1)] d_v=[-1 for _ in range(n+1)] def bfs(start,d): d[start]=0 q=deque([start]) while(len(q)>0): qi=q.popleft() di=d[qi] next_qi=g[qi] for i in next_qi: if(d[i]==-1): d[i]=di+1 q.append(i) return d d_u=bfs(u, d_u) d_v=bfs(v, d_v) if(u in leaf and list(g[u])[0]==v): print(0) else: ans=0 for li in leaf: if(d_u[li]<d_v[li]): ans=max(ans,d_v[li]-1) print(ans)
def main(): x, n = map(int, input().split()) if n == 0: print(x) return p_tuple = tuple(map(int, input().split())) radius = 0 for i in range(100): if x-radius not in p_tuple: print(x-radius) return elif x+radius not in p_tuple: print(x+radius) return else: radius += 1 if __name__ == '__main__': main()
0
null
65,674,324,915,362
259
128
L = int(input()) a = L / 3 ans = a**3 print("{:.10f}".format(ans))
print((int(input())/3)**3)
1
47,116,946,923,772
null
191
191
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod s = int(input()) mod = 10 **9 + 7 N = s g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) l = s//3 ans = 0 if s <= 2: print(0) else: for i in range(l): ans += cmb(s%3 + 3 * i +(l-i)-1, (l-i)-1,mod) print(ans%mod)
n = int(input()) a = list(map(int, input().split(" "))) for lil_a in a[-1:0:-1]: print("%d "%lil_a, end="") print("%d"%a[0])
0
null
2,116,371,753,200
79
53
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N,R = MI() print(R if N >= 10 else R+100*(10-N))
N = int(input()) S = input() ans = 0 for i in range(10): for j in range(10): for k in range(10): a = [i, j, k] l = 0 for s in S: if l < 3 and a[l] == int(s): l += 1 if l == 3: ans += 1 print(ans)
0
null
96,480,526,339,600
211
267
a, b = map(int, raw_input().split(" ")) if (a == b) : print "a == b" elif (a > b) : print "a > b" elif (a < b) : print "a < b"
s = input() ans = 0 for i in range(3): if s[i] == 'R': ans += 1 else: if ans == 1: break print(ans)
0
null
2,656,250,648,960
38
90
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)
N, K, C = [int(input_) for input_ in input().split(" ")] tick_cross = input() def find_earliest_work_days(K, C, tick_cross): """ Find the list of the earliest day in all possible days for the n-th work day. Parameters: K (int): The number of work days. C (int): Minimum interval between the previous work day and the next work day. tick_cross (str): The character string of days he can go to work. Returns: List[int]: The list of the earliest day in all possible days for the n-th work day. """ N = len(tick_cross) day = 0 earliest_work_days = [] number_of_work_days = len(earliest_work_days) while (day < N) and (number_of_work_days < K): if tick_cross[day] == "o": earliest_work_days.append(day+1) number_of_work_days = len(earliest_work_days) day += C + 1 else: day += 1 return earliest_work_days def find_latest_work_days(K, C, tick_cross): """ Find the list of the latest day in all possible days for the n-th work day. Parameters K (int): The number of work days. C (int): Minimum interval between the previous work day and the next work day. tick_cross (str): The character string of days he can go to work. Returns: List[int]: The list of the latest day in all possible days for the n-th work day. """ N = len(tick_cross) day = N - 1 latest_work_days = [] number_of_work_days = len(latest_work_days) while (day >= 0) and (number_of_work_days < K): if tick_cross[day] == "o": latest_work_days.append(day+1) number_of_work_days = len(latest_work_days) day -= (C + 1) else: day -= 1 return sorted(latest_work_days) earliest_work_days = find_earliest_work_days(K, C, tick_cross) latest_work_days = find_latest_work_days(K, C, tick_cross) for earliest, latest in zip(earliest_work_days, latest_work_days): if earliest == latest: print(earliest)
0
null
25,410,033,196,768
114
182
def solve(): s=input() if(len(s)%2==0): print("No") return else : n=len(s)//2 str1=s[:n] str2=s[n+1:] # print(str1,str2) if(str1==str2): print("Yes") else: print("No") if __name__ == "__main__": solve()
X = int(input()) A = [] for i in range(200): A.append(pow(i, 5)) for i in range(200): for j in range(200): a = abs(A[i] - A[j]) b = A[i] + A[j] if a == X: if i <= j: B = [j, i] else: B = [i, j] print(' '.join(map(str, B))) exit() elif b == X: B = [i, -j] print(' '.join(map(str, B))) exit()
0
null
35,865,162,370,000
190
156
num = input() print "", for x in xrange(1,num+1): if x%3==0: print x, elif "3" in str(x): print x, else: pass
X,N=map(int,input().split()) p=list(map(int,input().split())) ans=0 for i in range(1,102): if i not in p: if abs(X-i)<abs(X-ans): ans=i print(ans)
0
null
7,439,899,638,458
52
128
# いきぬきreview 忘れた問題 # gluttony N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) F.sort() A.sort(reverse=True) def func(X): s = 0 for i in range(N): a, f = A[i], F[i] s += max(0, a-X//f) return s <= K R = 10**12 L = -1 while R-L > 1: m = (R+L)//2 if func(m): R = m else: L = m print(R)
N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) max_a = max(A) max_f = max(F) left = 0 right = max_a * max_f while left <= right: x = (left + right) // 2 sum_ = 0 for i in range(N): if A[i] * F[i] > x: sum_ += (A[i] - int(x / F[i])) if sum_ > K: left = x + 1 if sum_ <= K: right = x - 1 print(left)
1
165,547,109,883,858
null
290
290
N = int(input()) ans = set() for i in range(N): ans.add(input()) print(len(ans))
hs=[int(input()) for i in range(10)] h=sorted(hs,reverse=True) for i in range(3): print(h[i])
0
null
15,014,390,848,880
165
2
import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) L = I() len_edge = L/3 print(len_edge**3)
l = int(input()) print("{:.9f}".format((l ** 3) / 27))
1
47,171,196,026,188
null
191
191
r = input() suq = int(r) * int(r) print(suq)
import sys def main(): r = int(input()) print(r*r) main()
1
144,986,958,053,380
null
278
278
N, K, C = map(int, input().split()) S = input() s = [] count = 0 for i in range(N): if len(s) == K: break if count == 0: if S[i] == 'x': continue else: count = C s.append(i+1) else: count -= 1 s2 = [] count = 0 for i in range(N-1, -1, -1): if len(s2) == K: break if count == 0: if S[i] == 'x': continue else: s2.append(i+1) count = C else: count -= 1 for a, b in zip(s, s2[::-1]): if a == b: print(a)
nkc=input().split() K=int(nkc[1]) C=int(nkc[2]) s=input() workday_list=[] for i,youso in enumerate(s) : if youso=='o' : workday_list.append(i+1) s=1 current_num=0 current_num1=1 list1=[] list1.append(workday_list[0]) while(s<K) : if current_num1>=len(workday_list): break elif workday_list[current_num1]-workday_list[current_num]>C : current_num=current_num1 list1.append(workday_list[current_num1]) s+=1 else : current_num1=current_num1+1 m=1 current_num2=len(workday_list)-1 current_num3=len(workday_list)-2 list2=[] list2.append(workday_list[-1]) while(m<K) : if current_num3<0: break elif workday_list[current_num2]-workday_list[current_num3]>C : current_num2=current_num3 list2.append(workday_list[current_num3]) m+=1 else : current_num3=current_num3-1 list2.reverse() flag=True for i in range(len(list1)) : if list1[i]==list2[i] : flag=False print(list1[i]) if flag : print()
1
40,757,710,737,292
null
182
182
from sys import stdin n = int(stdin.readline().strip()) a_lst = [int(x) for x in stdin.readline().strip().split()] pos = len(a_lst) // 2 min_diff = 10000000000000000000 while(True): left = sum(a_lst[:pos]) right = sum(a_lst[pos:]) diff = right - left if min_diff > abs(diff): min_diff = abs(diff) else: break if diff > 0: pos += 1 elif diff < 0: pos -= 1 print(min_diff)
n = int(input()) a = list(map(int,input().split())) barlen = 0 for x in a: barlen += x halflen = barlen/2 curbarlen = 0 minhalfdis = barlen for i in range(n): curbarlen += a[i] minhalfdis = min(minhalfdis,abs(halflen-curbarlen)) print(int(minhalfdis*2))
1
141,849,106,355,038
null
276
276
X, Y, A, B, C = map(int, input().split(' ')) apples = [] for p in map(int, input().split(' ')): apples.append((p, 0)) for q in map(int, input().split(' ')): apples.append((q, 1)) for r in map(int, input().split(' ')): apples.append((r, 2)) apples.sort(reverse=True) pq = [] r = [] x = X y = Y for d, t in apples: if t == 0: if x > 0: x -= 1 pq.append(d) else: continue elif t == 1: if y > 0: y -= 1 pq.append(d) else: continue else: r.append(d) pq_len = len(pq) for i in range(len(r)): if i >= pq_len: break if r[i] <= pq[-(i + 1)]: break pq[-(i + 1)] = r[i] print(sum(pq))
def solve(x, y, a, b, c, p, q, r): p = sorted(p)[::-1] q = sorted(q)[::-1] r = sorted(r)[::-1] v = sorted(p[:x] + q[:y]) n = len(v) t = sum(v) for i in range(min(n,c)): if v[i] < r[i]: t += r[i] - v[i] return t x, y, a, b, c = map(int, input().split()) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) print(solve(x, y, a, b, c, p, q, r))
1
44,954,438,367,926
null
188
188
ma = lambda :map(int,input().split()) ni = lambda:int(input()) import collections import math import itertools import fractions gcd = fractions.gcd a,b = ma() print(a*b//gcd(a,b))
a,b=map(int,input().split()) for i in range(1,a+1): if b*i%a==0: print(b*i) break
1
113,082,615,421,852
null
256
256
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64) import base64 import subprocess import zlib exe_bin = "c%1E9e{dUhcK_;!V<mPZIXH<41dAZJm?XkV>|iJLVcAl$;^f2^JCIVsMwaAQM3!7>6&xl&I3?lsj3C@FG@YYu+H0?2rc=1~u4OtmhfTN`ZrU3|OPdys3s;~Lg-HT5I3bDp-gm!WX?LwX?r!=|XY%#fZ{KI%d;7lc`@Y}Z{qFN4fzT$i$wYXwkgpQtjxAL9ZidgSDT@HsLFU8X8_04p4|uCePETh|T52m_N73srE4-dwPqfseqBX?04K!*gA+E9>`r5i&L0gx*G_=63J7(|F=$V<G!1M$r&#9B?amxE=Wxs<A*Hb^yQY)kV?@LiUey>5{^>mPEDcAct=*=U)eseOqja|<uE;GzuPWd?8mWU6nZ@VoKU6Y6>v*T;VJJzpR-{#4rJZq^>PA0o~%XTV{<84;?+{iFIf2w)cBJuLk3*Ts~`|Q#Ezv%kP+lBkhOoopeM%V<Jd{`Tg*7s(fspTf;w10x%MOE-|Fu0-$e!qeIb_4wPP1W(J0e;fJj@3YZzyM!hfInt{pE0=ZE(5%o@XXh?4F>j~G{Bt(b~YN|e{JB;3b5Zmt|i?rMa#(&@Gpph@48XJn|NYEUS_0dWYsFn#q~rKcaNr$Vnzz5B~c_|aIjB|#?rCf@r)Ep5BBvYQpwn0cqkE5&Q(8i&z6CBIuqCyr-!LTCV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Jc?+k=0V^I)@cf`u=LGoGSj|xxv0(o*TS;YEHOdaQXP(v!y+i35$E$hqCcR6pOCJp-iT7wpwA9-X1NSie$1hy?8;DE^1Zc-rcP#oGMqV>5TuXDmYCU80fKjEtNw!(aJS!Ro$-Cd(ClpPBork#a)%cIPJxVC$n!<3J(F5(h42nNAV<>93!4&N{V?P9BZWTZpK04c<8vSiAM?LM#7m9;)(7{f<1*wY30mbh;2NT)G#8POUDvn6l6zZ2?;L=<AjHv-6=SLEQh}|R-SZ<PJK^oge^lO(R76a>yd~U8;``sBvGRM_f*yt#RflyYlcVT5jda*A*+Z7R>x6T#;UE(zj4ET2E29f`-)LrHg6^!e-lyO?YX|b?%Ac2*T0^5b^820kW=@U=;QaV^YCuZ_4)fErz;uG_e1orZ(E46_rdk~dnKp5&KqA7O)7o9PjMH~);ja|Pfp*}1xz2m`-rl4!S(rjDyOS;{+o4l4^j3)IM3f_Ipu{@^O&Fd{y#{Rm~wso-peW9pV7yU_x~W%?_oTDKjze>(qCFd{|Tb5`L67bamx3Rc+-!+tkdW3+nmnm<efVDv`(MDmvgF*mrY0iNT<)=BRE~8+edI}S@K<-K7SwJRKI<o@Bed5pFgYd_aXgzkzSwE?-T9(H~RkrqwBw<)93pOoX+YJULVibbozWBg43IH^7{Gn7E$V3`MzJ}{}~isA8-Bm{TEU83b;OhkL_Mw-Cw=_r=&8suvPwFgk4{?eyH`hUq@M=^!uwjnic-|mt6mnPQU!V#0Z~fdVSu^Y(ur&f2QBW^mo;DY2>?g`n4wI`udGQuHT}=tL>Xt`=<_p>CdwHgZCj1nY(_>SNX2-lP&!FbqTA_p9TZ{AF+kk`6cW3{{kH-Ur7" open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod +x ./kyomu"], shell=True) subprocess.run(["./kyomu"], shell=True)
import math a, b, h, m = list(map(int, input().split())) ang = abs(h * 30 + m * 0.5 - m * 6) print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(ang * math.pi / 180)))
0
null
11,364,376,330,020
73
144
n = int(input()) d = [list(map(int,input().split())) for i in range(n)] count = 0 # [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]] for i in d: if i[0] == i[1]: count += 1 else: count = 0 if count == 3: print('Yes') exit() print('No')
from fractions import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import product, combinations,permutations from copy import deepcopy import sys import numpy as np sys.setrecursionlimit(4100000) if __name__ == '__main__': N = int(input()) S = input() Z = ord('Z') ans = '' for s in S: if ord(s)+N>ord('Z'): ans += chr(ord('A')+ord(s)+N-ord('Z')-1) else: ans += chr(ord(s)+N) print(ans)
0
null
68,495,300,750,710
72
271
import sys w = input().lower() lines = sys.stdin.read() line=lines[0:lines.find('END_OF_TEXT')].lower().split() print(line.count(w))
#!/usr/bin/env python import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**6) def main(): A,V = map(int,input().split()) B,W = map(int,input().split()) T = int(input()) dx = abs(A-B) dv = V-W if dv*T >= dx: print("YES") else: print("NO") if __name__ == "__main__": main()
0
null
8,511,569,725,360
65
131
X = int(input()) ans, rem = divmod(X, 500) ans *= 1000 ans += rem // 5 * 5 print(ans)
import math pi=math.pi r=float(input()) menseki=r*r*pi ensyu=2*r*pi print(str(menseki)+" "+str(ensyu))
0
null
21,618,976,948,576
185
46
w = input() t = [] while True: s = [1 if i.lower() == w else 'fin' if i == 'END_OF_TEXT' else 0 for i in input().split()] t += s if 'fin' in s: break print(t.count(1))
I=input;s=I()*2;print(['No','Yes'][I()in s])
0
null
1,788,165,299,114
65
64
#!/usr/bin/env python3 import sys sys.setrecursionlimit(300000) MOD = 1000000007 # type: int def solve(N: int, K: int): ret = 0 counts = [0] * (K + 1) for i in range(1, K + 1)[::-1]: c = K // i cnt = pow(c, N, MOD) j = 2 while i * j <= K: cnt -= counts[i * j] j += 1 ret += cnt * i ret %= MOD counts[i] = cnt #print(counts) print(ret) return 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 solve(N, K) if __name__ == '__main__': main()
N = int(input()) S = input() ans = 0 numlist = [str(i) for i in range(10)] for a in numlist: idx_a = S.find(a) if idx_a == -1 or idx_a >= N - 2: continue for b in numlist: idx_b = S[idx_a+1:].find(b) if idx_b == -1 or idx_a + idx_b + 1 >= N - 1: continue for c in numlist: if c in S[idx_a + idx_b + 2:]: ans += 1 print(ans)
0
null
82,767,123,975,878
176
267
#Union-Find木の実装 from collections import Counter N,M=map(int,input().split()) #初期化 par=[i for i in range(N)]#親の要素(par[x]=xのときxは木の根) rank=[0]*N#木の深さ #木の根を求める def find(x): #xが根だった場合xをそのまま返す if par[x] == x: return x else: #根が出るまで再帰する par[x] = find(par[x]) return par[x] #xとyの属する集合を併合 def unite(x,y): x=find(x)#xの根 y=find(y)#yの根 #根が同じなら何もしない if x == y: return #もし根の深さがyの方が深いなら if rank[x] < rank[y]: par[x] = y#yを根にする else: par[y] = x#xを根にする if rank[x] == rank[y]: rank[x]+=1 #xとyが同じ集合に属するか否か #def same(x,y): #return find(x)==find(y) for _ in range(M): a,b = map(int,input().split()) a,b = a-1, b-1 unite(a,b) for i in range(N): find(i) c=Counter(par) print(len(c)-1)
N = int(input()) S = [input() for _ in range(N)] d = {} for s in S: if s in d: d[s] += 1 else: d[s] = 1 maxcount = max([d[k] for k in d]) maxlist = list(filter(lambda x: d[x] == maxcount, d)) maxlist = sorted(maxlist) for m in maxlist: print(m)
0
null
36,333,150,222,138
70
218
from copy import deepcopy def getval(): r,c,k = map(int,input().split()) item = [[0 for i in range(c)] for i in range(r)] for i in range(k): ri,ci,vi = map(int,input().split()) item[ri-1][ci-1] = vi return r,c,k,item def main(r,c,k,item): #DP containing the information of max value given k items picked in i,j prev = [[0 for i in range(4)]] inititem = item[0][0] prev[0] = [0,inititem,inititem,inititem] for i in range(1,r): initval = prev[i-1][3] temp = [] cur = item[i][0] for j in range(4): temp.append(initval) for j in range(1,4): temp[j] += cur prev.append(temp) for j in range(1,c): init = deepcopy(prev[0]) for i in range(1,4): init[i] = max(prev[0][i],prev[0][i-1]+item[0][j]) curcol = [init] for i in range(1,r): cur = item[i][j] left = curcol[-1] down = prev[i] temp = [max(left[3],down[0])] for k in range(1,4): temp.append(max(max(left[3],down[k-1])+cur,down[k])) curcol.append(temp) prev = curcol print(max(prev[-1])) if __name__=="__main__": r,c,k,item = getval() main(r,c,k,item)
# coding: utf-8 # Your code here! n,m=input().split() a=n*int(m) b=m*int(n) nlist=[a,b] nlist.sort() print(nlist[0])
0
null
45,199,335,594,240
94
232
import math while True: n=int(input()) if n==0: break s=list(map(int,input().split())) m=sum(s)/len(s) a=0 for i in range(n): a+=(s[i]-m)**2 b=math.sqrt(a/n) print('{:.5f}'.format(b))
n, m = map(int, input().split()) route = [[] for _ in range(n+1)] ans = [0]*n for _ in range(m): a, b = map(int, input().split()) route[a].append(b) route[b].append(a) q = [1] l = set() while True: if len(q) == 0: break p = q.pop(0) for i in route[p]: if i not in l: l.add(i) ans[i-1] = p q.append(i) if ans.count(0) > 1: print("No") else: print("Yes") for i in range(1, n): print(ans[i])
0
null
10,349,903,056,868
31
145
n,k,s=list(map(int,input().split())) if s>n: ans=["1" for _ in range(n)] else: ans=[str(s+1) for _ in range(n)] for i in range(k): ans[i]=str(s) print(" ".join(ans))
N = int(input()) ans = 0 for a in range(1, 10 ** 6 + 1): for b in range(1, 10 ** 6 + 1): if a * b >= N: break ans += 1 print(ans)
0
null
47,026,612,635,310
238
73
import sys from collections import deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,X,Y = map(int,readline().split()) ans = [0]*N graph = [[] for _ in range(N)] for i in range(N-1): graph[i].append(i+1) graph[i+1].append(i) graph[X-1].append(Y-1) graph[Y-1].append(X-1) def bfs(x,q,dist): while q: v = q.popleft() for nx in graph[v]: if dist[nx] != 0: continue dist[nx] = dist[v] + 1 q.append(nx) if nx > x: ans[dist[nx]] +=1 for i in range(N): dist = [0]*N q = deque([i]) bfs(i,q,dist) print('\n'.join(str(n) for n in ans[1:]))
N,X,Y = map(int,input().split()) X-=1;Y-=1 ans = [0 for _ in range(N-1)] for i in range(N): for j in range(i+1,N): direct = j-i shortcut = abs(X-i)+1+abs(Y-j) shortest = min(direct,shortcut) ans[shortest-1] += 1 print(*ans,sep="\n")
1
44,040,698,827,170
null
187
187
n,m,l = map(int,input().split()) A = [] for i in range(n): a = [int(j) for j in input().split()] A.append(a) B = [] for j in range(m): b = [int(k) for k in input().split()] B.append(b) for i in range(n): c = [] for k in range(l): x = 0 for j in range(m): x += A[i][j]*B[j][k] c.append(str(x)) print(" ".join(c))
N = int(input()) A = set(input().split()) if N==len(A): print("YES") else: print("NO")
0
null
37,815,994,069,120
60
222
N = int(input()) def dfs(s, mx): if len(s) == N: print(s) else: c = 'a' while ord(c) <= ord(mx): if c == mx: dfs(s + c, chr(ord(mx) + 1)) else: dfs(s + c, mx) c = chr(ord(c) + 1) dfs('', 'a')
n = int(input()) print(((n + 1) // 2) / n)
0
null
114,500,187,110,332
198
297
s=[ord(i) for i in input()] n=[ord(i) for i in input()] flag=0 flack=0 for i in range(len(s)): flack=0 if n[0]==s[i]: flack=1 for j in range(1,len(n)): if i+j>=len(s): if n[j]==s[i+j-len(s)]: flack=flack+1 else: break else: if n[j]==s[i+j]: flack=flack+1 else: break if flack==len(n): flag=1 break if flag: print('Yes') else: print('No')
from itertools import permutations n = int(input()) l = [tuple(map(int,input().split())) for _ in range(2)] a = list(permutations(range(1,n+1))) print(abs(a.index(l[0]) - a.index(l[1])))
0
null
51,356,604,523,968
64
246
def shu(a,b): for i in range(a): b[i]=list(map(int,input().split())) n,m,l = map(int,input().split()) A=[[]for i in range(n)] B=[[]for i in range(m)] C=[[0 for i in range(l)]for i in range(n)] shu(n,A) shu(m,B) for k in range(m): for i in range(n): for j in range(l): C[i][j] += (A[i][k]*B[k][j]) for i in range(n): print(' '.join(map(str,C[i])))
nml=input().split() n,m,l=int(nml[0]),int(nml[1]),int(nml[2]) A_=[input() for i in range(n)] B_=[input() for i in range(m)] A,B=[],[] for i in range(n): A_[i]=A_[i].split() for i in A_: A.append(list(map(lambda i:int(i),i))) for i in range(m): B_[i]=B_[i].split() for i in B_: B.append(list(map(lambda i:int(i),i))) AB=[] for i in range(n): AB.append([]) for i in range(n): for j in range(l): AB[i].append(0) for i in range(n): for j in range(l): for k in range(m): AB[i][j]+=(A[i][k]*B[k][j]) for i in AB: print(*i)
1
1,414,696,815,180
null
60
60
import sys input = sys.stdin.readline from collections import * H1, M1, H2, M2, K = map(int, input().split()) print(60*H2+M2-(60*H1+M1)-K)
list = input().split() m1 = int(list[0])*60 + int(list[1]) m2 = int(list[2])*60 + int(list[3]) #print(m1,m2) ans = m2 - m1 print(ans-int(list[4]))
1
17,890,312,253,814
null
139
139
n,x,m = map(int,input().split()) place = [0] * m place[x] = 1 cur = [x] ends = 0 for i in range(m): x = (x**2) % m if place[x] == 0: place[x] = i+2 cur.append(x) else: ends = i+2 break roopsum = sum(cur[place[x]-1:ends-1]) rooplen = ends - place[x] curlen = cur[place[x]-1:] mm = min(n,ends-1) ans = 0 for i in range(mm): ans += cur[i] if n-mm == 0: print(ans) else: roopamo = (n-mm) // rooplen roopama = (n-mm) % rooplen ans += roopamo * roopsum for i in range(roopama): ans += curlen[i] print(ans)
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)
1
2,830,345,157,188
null
75
75
n,a,b=input().split() n=int(n) a=int(a) b=int(b) c=a+b if n%c>a: print((n//c)*a+a) else: print((n//c)*a+n%c)
n,m = map(int, raw_input().split()) a = [] b = [0]*m for i in xrange(n): x = map(int,raw_input().split(" ")) a.append(x) for i in xrange(m): b[i] = input() result = [0]*n for i in xrange(n): for j in xrange(m): result[i] += a[i][j]*b[j] print result[i]
0
null
28,325,959,454,588
202
56
n = int(input()) s = input() ans = 0 for i in range(1000): i = str(i).zfill(3) f = True x = -1 for j in range(3): x = s.find(i[j],x+1) f = f and bool(x >= 0) ans += f print(ans)
import itertools def solve(): N = int(input()) S = input() l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] p = itertools.product(l,repeat=3) count = 0 for v in p: S_temp = S dig_0_index = S_temp.find(v[0]) if dig_0_index != -1: S_temp = S_temp[dig_0_index+1::] dig_1_index = S_temp.find(v[1]) if dig_1_index != -1: S_temp = S_temp[dig_1_index+1::] dig_2_index = S_temp.find(v[2]) if dig_2_index != -1: count += 1 print(count) if __name__ == "__main__": solve()
1
128,726,195,510,832
null
267
267
def main(): n = int(input()) a_list = list(map(int, input().split())) num = 1 for a in a_list: if a == num: num += 1 if num == 1: print(-1) else: print(n - num + 1) if __name__ == "__main__": main()
import sys inint = lambda: int(sys.stdin.readline()) inintm = lambda: map(int, sys.stdin.readline().split()) inintl = lambda: list(inintm()) instrm = lambda: map(str, sys.stdin.readline().split()) instrl = lambda: list(instrm()) n = inint() A = inintl() cnt = 1 ans = 0 for a in A: if a != cnt: ans += 1 continue else: cnt += 1 if cnt == 1: if ans == 0: print(ans) else: print(-1) else: print(ans)
1
114,119,910,866,470
null
257
257
n = int(input()) g = [[] for _ in range(n)] for i in range(n): a = int(input()) for j in range(a): x, y = map(int, input().split()) x -= 1 g[i].append((x, y)) ans = 0 for i in range(2**n): temp = [-1]*n for j in range(n): if (i >> j) & 1: temp[j] = 1 else: temp[j] = 0 flag = True for j in range(n): if temp[j] == 1: for x, y in g[j]: if temp[x] != y: flag = False if flag: ans = max(ans, sum(temp)) print(ans)
#!/usr/bin/env python3 n = int(input()) a = [] for _ in range(n): a.append([[*map(int, input().split())] for _ in range(int(input()))]) ans = 0 for i in range(2**n): hone = set() unki = set() for j in range(n): if i >> j & 1: hone |= {j + 1} for k in a[j]: if k[1] == 1: hone |= {k[0]} else: unki |= {k[0]} else: unki |= {j + 1} if hone & unki == set(): ans = max(ans, len(hone)) print(ans)
1
121,397,085,976,800
null
262
262
def alp(c): return chr(c+64) def Base10to(n,k): if(int(n/k)): if n%k ==0 and n/k==1: return str(alp(26)) elif n%k ==0: return Base10to(int((n/k)-1),k)+str(alp(26)) else: return Base10to(int(n/k),k)+str(alp(n%k)) return str(alp(n%k)) n = int(input()) k = 26 ans = Base10to(n,k) print(ans.lower())
n = int(input()) ans = "" check = "abcdefghijklmnopqrstuvwxyz" while n != 0: n -= 1 ans += check[n % 26] n //= 26 print(ans[::-1])
1
11,775,170,132,700
null
121
121
from collections import deque while True: str = input() if str == "-": break dq = deque(char for char in list(str)) shuffle_count = int(input()) for i in range(shuffle_count): h = int(input()) dq.rotate(h * -1) print(''.join(dq))
while True: string = str(input()) box = "" if string == "-": break shuffle = int(input()) h = [0]*shuffle for a in range(shuffle): h[a] = int(input()) for b in range(shuffle): box = string[0:h[b]] string = string[h[b]:] string = string+box box = "" print(string)
1
1,943,548,362,980
null
66
66
n,r=map(int,input().split()) res = r if n < 10: res += 100 * (10 - n) print(res)
n = int(input()) li = [] for _ in range(n): s = input() count = 0 while True: if count + 1 >= len(s): break if s[count] == '(' and s[count+1] == ')': s = s[:count] + s[count+2:] count = max(0, count-1) else: count += 1 li.append(s) li2 = [] for i in li: count = 0 for j in range(len(i)): if i[j] == ')': count += 1 else: break li2.append((count, len(i) - count)) li3 = [] li4 = [] for i in li2: if i[0] <= i[1]: li3.append(i) else: li4.append(i) li3.sort() li4.sort(key = lambda x: x[1], reverse = True) now = [0,0] for l,r in li3: if l == 0 and r == 0: pass elif l == 0: now[1] += r else: now[1] -= l if now[1] < 0: print('No') exit() now[1] += r for l,r in li4: if l == 0 and r == 0: pass elif r == 0: now[1] -= l if now[1] < 0: print('No') exit() else: now[1] -= l if now[1] < 0: print('No') exit() now[1] += r if now[0] == 0 and now[1] == 0: print('Yes') else: print('No')
0
null
43,502,343,658,972
211
152
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)
a,b = input().split() x = int(a) * b y = int(b) * a l = [] l.append(x) l.append(y) l = sorted(l) print(min(l))
0
null
46,372,563,448,410
110
232
S = input()[::-1] ## 余りを0~2018で総数保持 counts = [0]*2019 ## 0桁の余りは0 counts[0] = 1 num, d = 0, 1 for c in S: ## 右から~桁の数字 num += int(c) * d num %= 2019 ## 次の桁 d *= 10 d %= 2019 counts[num] += 1 ans = 0 for cnt in counts: ## nC2の計算 ans += cnt * (cnt-1) //2 print(ans)
n = int(input()) a = list(map(int, input().split())) num = [0]*(10**6+1) for x in a: num[x] += 1 f = 1 for i in range(2, 10**6+1): s = sum(num[i::i]) if s == n: print("not coprime") exit() if s > 1 : f = 0 if f == 0: print("setwise coprime") else: print("pairwise coprime")
0
null
17,364,531,718,560
166
85
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# X, Y, A, B, C = getNM() P = getList() Q = getList() R = getList() P.sort() Q.sort() lista = P[-X:] + Q[-Y:] + R lista.sort() print(sum(lista[-(X + Y):]))
import heapq x,y,a,b,c = map(int,input().split()) P = list(map(int,input().split())) Q = list(map(int,input().split())) R = list(map(int,input().split())) P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) x_tmp = P[:x] y_tmp = Q[:y] tmp_li = x_tmp+y_tmp heapq.heapify(tmp_li) for i in range(c): if R[i]>tmp_li[0]: heapq.heapreplace(tmp_li,R[i]) print(sum(tmp_li))
1
44,784,858,516,448
null
188
188
a=[] for i in range(2): m=input().split() a.append(m) list_1=[int(l) for l in a[0]] list_2=[int(l) for l in a[1]] total=0 largest=list_2[0] smallest=list_2[0] for x in range(list_1[0]): if largest<list_2[x]: largest=list_2[x] if smallest>list_2[x]: smallest=list_2[x] for x in list_2: total+=x print(smallest,largest,total)
n = int(input()) dna = set() for i in range(n): command = input().split() if command[0] == 'insert': dna.add(command[1]) else: print('yes' if command[1] in dna else 'no')
0
null
408,025,436,830
48
23
n,m = map(int,input().split()) s = input() now = n ans_rev = [] while(now != 0): for i in range( max(0,now-m),now+1): if(i == now): print(-1) exit() if(s[i] == '1'): continue ans_rev.append(now - i) now = i break print(' '.join(map(str, ans_rev[::-1])))
n = int(input()) cnt = 0 for i in range(1, 10): if len(str(n//i)) == 1 and n%i == 0: cnt +=1 if cnt >= 1: print('Yes') else : print('No')
0
null
149,289,369,358,790
274
287
import heapq n = int(input()) A = list(map(int, input().split())) A = sorted(A, reverse=True) ans = 0 q = [] heapq.heappush(q, A[0]*-1) for i in range(1, n): tmp = heapq.heappop(q) ans += tmp heapq.heappush(q, A[i] * -1) heapq.heappush(q, A[i] * -1) print(ans*-1)
a,b,n = list(map(int,input().split())) if n < b : x = n else : x = b-1 print(a*x//b-a*(x//b))
0
null
18,760,327,235,240
111
161
n=int(input()) heights=list(map(int, input().split())) std=heights.pop(0) ans=0 if n==1: ans=0 else: for height in heights: if std>height: ans+=std-height else: std=height print(ans)
N = int(input()) A = list(map(int, input().split())) max_list = [] m = 0 ans = 0 for a in A: ans += max(m - a, 0) max_list.append(m) m = max(m, a) print(ans)
1
4,578,772,651,388
null
88
88
import sys input = sys.stdin.readline P = [list(map(int,input().split())) for i in range(2)] T = int(input()) if(P[0][1]<P[1][1]): print('NO') else: if(abs(P[0][0]-P[1][0])<=abs(P[0][1]-P[1][1])*T): print('YES') else: print('NO')
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) #a,b間の距離 d=abs(b-a) #速度差 V=v-w if V<=0: print("NO") exit() T=d/V if T<=t: print("YES") else: print("NO")
1
15,027,984,997,600
null
131
131
import numpy as np n,m = map(int, input().split()) h = np.array([int(i) for i in input().split()]) h_i = np.ones((n)) for i in range(m): a,b = map(int, input().split()) if h[a-1] < h[b-1]: h_i[a-1] = 0 elif h[b-1] < h[a-1]: h_i[b-1] = 0 elif h[a-1] == h[b-1]: h_i[a-1] = 0 h_i[b-1] = 0 ans = (h_i > 0).sum() print(ans)
n = int(input()) a = list(map(int, input().split())) result = 2020202020 num_left = 0 num_right = sum(a) for i in range(n): num_left += a[i] num_right -= a[i] result = min(result, abs(num_left - num_right)) print(result)
0
null
83,829,859,822,240
155
276
l = int(input()) x = l/3 print(x**3)
n=int(input()) print((n/3)*(n/3)*(n/3))
1
46,792,222,734,500
null
191
191
mountain = [] for _ in range(10): mountain.append(int(input())) mountain.sort() mountain.reverse() print(mountain[0]) print(mountain[1]) print(mountain[2])
H,W,K = map(int, input().split()) S = [input() for _ in range(H)] L = [[0]*(W) for _ in range(H)] for i in range(H): for j in range(W): if S[i][j] == "1": L[i][j] = 1 ans = H*W for i in range(2**(H-1)): cnt = 0 used = [0]*W memo = [] for j in range(H-1): if i & (1<<j): cnt += 1 memo.append(j+1) memo.append(H) num = [0]*(cnt+1) for j in range(W): idx = 0 for k in range(H): if memo[idx] == k: idx += 1 num[idx] += L[k][j] f = False for k in range(len(num)): if num[k] > K: f = True break if f: if j == 0 or used[j-1] == 1: cnt = H*W break used[j-1] = 1 cnt += 1 num = [0]*len(num) idx = 0 for k in range(H): if memo[idx] == k: idx += 1 num[idx] += L[k][j] ans = min(ans, cnt) print(ans)
0
null
24,328,504,255,822
2
193
n = int(input()) ans = 0 for a in range (1,n): for b in range(1, n): if n <= a * b: break ans += 1 print(ans)
n = int(input()) cnt = 0 for i in range(1,n): cnt += int((n-1)/i) print(cnt)
1
2,614,109,539,290
null
73
73
# -*- coding: utf-8 -*- class dice_class: def __init__(self, top, front, right, left, back, bottom): self.top = top self.front = front self.right = right self.left = left self.back = back self.bottom = bottom def roll(self, s): for i in s: if i == 'E': self.rollE() elif i == 'N': self.rollN() elif i == 'S': self.rollS() elif i == 'W': self.rollW() def rollE(self): tmp = self.top self.top = self.left self.left = self.bottom self.bottom = self.right self.right = tmp def rollN(self): tmp = self.top self.top = self.front self.front = self.bottom self.bottom = self.back self.back = tmp def rollS(self): tmp = self.top self.top = self.back self.back = self.bottom self.bottom = self.front self.front = tmp def rollW(self): tmp = self.top self.top = self.right self.right = self.bottom self.bottom = self.left self.left = tmp if __name__ == "__main__": a = map(int, raw_input().split()) s = str(raw_input()) dice = dice_class(a[0], a[1], a[2], a[3], a[4], a[5]) dice.roll(s) print dice.top
class Dice: D = {'E':(3,1,0,5,4,2), 'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1), 'N':(1,5,2,3,0,4)} def __init__(self, tp, fwd, rs, ls, bk, bm): self.nbrs = [tp, fwd, rs, ls, bk, bm] def rll(self, drctn): return [self.nbrs[i] for i in self.D[drctn]] A = input().split() for i in input(): dice = Dice(A[0], A[1], A[2], A[3], A[4], A[5]) A = dice.rll(i) print(A[0])
1
232,711,844,300
null
33
33
a,b,k=map(int,input().split()) if a>=k: a-=k elif a+b>=k: b-=k-a a=0 else: a=0 b=0 print('{} {}'.format(a,b))
import sys input=sys.stdin.buffer.readline mod=10**9+7 n=int(input()) d={} z=0 from math import gcd for i in range(n): x,y=map(int,input().split()) if x==y==0:z+=1 else: f=gcd(x,y) x//=f;y//=f if x<0:x*=-1;y*=-1 if x==0 and y<0:y=-y if (x,y)not in d:d[(x,y)]=1 else:d[(x,y)]+=1 ans=1 for (a,s) in d: if d[(a,s)]==0:continue ng=0 if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0 if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0 ans*=(pow(2,d[(a,s)],mod)-1 + pow(2,ng,mod)-1 +1)%mod ans%=mod d[(a,s)]=0 print((ans+z-1)%mod)
0
null
62,792,534,790,048
249
146
import sys class alphabet: #Trueなら大文字 def __init__(self, capitalize): self.num = dict() #アルファベットを数字に変換 self.abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"\ ,"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] if capitalize: for i in range(26): self.abc[i] = self.abc[i].upper() for i, a in enumerate(self.abc): self.num[a] = i def solve(): input = sys.stdin.readline N = int(input()) S = input().strip("\n") Ans = "" Alphabet = alphabet(True) for i in range(len(S)): sNum = Alphabet.num[S[i]] rotateNum = (sNum + N) % 26 Ans += Alphabet.abc[rotateNum] print(Ans) return 0 if __name__ == "__main__": solve()
a, b, c = [int(i) for i in input().split()] print('Yes' if len(set([a, b, c])) == 2 else 'No')
0
null
101,253,576,849,678
271
216
A, B, N = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = [] l.append(min(a) + min(b)) for _ in range(N): aq, bq, d = map(int, input().split()) l.append( a[aq-1] + b[bq-1] - d ) print(min(l))
r, c = map(int, input().split()) args = [] for i in range(r): args.append(list(map(int, input().split()))) r_sum = 0 for j in args[i]: r_sum += j args[i].append(r_sum) l_row = [] for k in range(c + 1): c_sum = 0 for l in range(r): c_sum += args[l][k] l_row.append(c_sum) for m in range(r): print(' '.join(map(str, args[m]))) print(' '.join(map(str, l_row)))
0
null
27,659,644,936,378
200
59
# 問題: https://atcoder.jp/contests/abc144/tasks/abc144_c import math n = int(input()) a = int(math.sqrt(n)) b = 0 while b == 0: if n % a > 0: a -= 1 continue b = n / a res = a + b - 2 print(int(res))
n, k = map(int, input().split()) x = n % k y = abs(x - k) if x >= y: print(y) else: print(x)
0
null
100,287,077,253,680
288
180
n=list(map(int,input().split())) p=['2354','3146','2651','1562','1364','2453'] for _ in range(int(input())): t,m=map(int,input().split()) t=n.index(t) m=str(n.index(m)+1) print(n[int(p[t][(p[t].index(m)+1)%4])-1])
from heapq import heappush, heappop import sys input = sys.stdin.readline N = int(input()) pos = [] zero = [] neg = [] for _ in range(N): S = input().rstrip() m = s = 0 for c in S: if c == '(': s += 1 else: s -= 1 m = min(m, s) if s > 0: heappush(pos, (-m, s)) # take larger mins first elif s == 0: heappush(zero, (m, s)) else: heappush(neg, (m - s, s)) # take smaller mins first num = 0 while pos: m, s = heappop(pos) if num - m < 0: print('No') exit() num += s while zero: m, s = heappop(zero) if num + m < 0: print('No') exit() while neg: m, s = heappop(neg) m += s if num + m < 0: print('No') exit() num += s if num == 0: print('Yes') else: print('No')
0
null
11,918,226,181,160
34
152
s = input() p = input() s2 = s + s if(p in s2): print("Yes") else: print("No")
s = input() p = input() if p in s*2: print('Yes') else: print('No')
1
1,703,673,220,198
null
64
64
s = input() k = int(input()) ans = 0 soui = 0 moji = s[0] for i in range(1,len(s)): if s[i] == s[i-1] and soui == 0: ans += 1 soui = 1 elif soui == 1: soui = 0 flag = 0 a = 0 b = 0 while s[0] == s[a] and a != len(s)-1: a += 1 while s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1: b += 1 if s[0] == s[len(s)-1]: flag = 1 for i in range(len(s)): if moji != s[i]: break elif i == len(s)-1: flag = 2 if flag == 1: print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2)))) elif flag == 2: print((k*len(s))//2) else: print(k*ans)
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 13 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 n = I() x = input() cnt = x.count("1") if cnt == 1: for i in range(n): if x[i] == "1": print(0) elif i == n - 1: print(2) else: print(1) exit() def f(x): if x==0: return 0 return 1+f(x%bin(x).count('1')) xx = int(x, 2) Y = xx % (cnt + 1) Z = xx % (cnt - 1) for i in range(n): if x[i] == '1': print(1 + f((Z - pow(2, n - i - 1, cnt - 1)) % (cnt - 1))) else: print(1 + f((Y + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)))
0
null
91,560,359,137,780
296
107
import sys sys.setrecursionlimit(10 ** 9) input = sys.stdin.readline def main(): t1, t2 = map(int, input().split()) a1, a2 = map(int, input().split()) b1, b2 = map(int, input().split()) P = t1 * (b1 - a1) Q = t2 * (b2 - a2) if P + Q == 0: print("infinity") return if P * (P + Q) > 0: print(0) return P = abs(P) Q = abs(Q) T = P % (Q - P) S = P // (Q - P) if T == 0: ans = 2 * S else: ans = 2 * S + 1 print(ans) main()
a, b, k =map(int, input().split()) if k <= a: a = a-k b = b elif a+b <= k: a = 0 b = 0 else: b = a+b-k a = 0 print(a, b)
0
null
117,695,653,630,640
269
249
c = input() alphabet = 'abcdefghijklmnopqrstuvwxyz' list_a = list(alphabet) num_c = list_a.index(c) print(list_a[num_c + 1])
C = str(input()) print(chr(ord(C)+1))
1
92,185,445,288,112
null
239
239
n = int(input()) a = list(map(int, input().split())) a.sort() def main(a): if 0 in a: ans = 0 else: ans = 1 for item in a: ans *= item if ans > 1000000000000000000: ans = -1 break return ans ans = main(a) print(ans)
n = int(input()) mod = 10**18 li = list(map(int, input().split())) li.sort() ans = 1 for i in range(n): ans *= li[i] if ans > mod: ans = -1 break print(ans)
1
16,136,143,792,470
null
134
134
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) # INF = float("inf") INF = 10**18 import bisect import statistics mod = 10**9+7 # mod = 998244353 N = int(input()) if N % 2 == 0: print(0.5) else: print(1.0-((N-1)//2.0)/N)
def main(): num = int(input()) print(1-((int(num/2)/num))) main()
1
177,266,844,329,184
null
297
297
n,m=map(int,input().split()) A=list(map(int,input().split())) ans=0 for i in range(n): if 4*m*A[i]<sum(A): continue else: ans+=1 if ans<m: print('No') else: print('Yes')
N, M = map(int, input().split()) A = list(map(int, input().split())) line = sum(A)/(4*M) cnt = 0 for a in A: if a >= line: cnt += 1 if cnt >= M: print("Yes") else: print("No")
1
38,951,949,922,090
null
179
179
s_l = list(input()) t_l = list(input()) count_difference = 0 for s, t in zip(s_l, t_l): if s != t: count_difference += 1 print(count_difference)
s_list=[] while True: s = input()#文字列 if s == "-": break shuffle = int(input()) for i in range(shuffle): h=int(input()) s = s[h:]+s[:h] s_list.append(s) for i in range(len(s_list)): print(s_list[i])
0
null
6,153,722,895,712
116
66
n=int(input()) s,t = map(str, input().split()) print(''.join([s[i] + t[i] for i in range(0,n)]))
n=int(input()) s,t=input().split() ans='' for i in range(2*n): ans=ans+(s[i//2] if i%2==0 else t[(i-1)//2]) print(ans)
1
111,995,242,878,068
null
255
255
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) ruiseki_A = [0] ruiseki_B = [0] for i in range(len(A)): ruiseki_A.append(ruiseki_A[i]+A[i]) for i in range(len(B)): ruiseki_B.append(ruiseki_B[i]+B[i]) #print(ruiseki_A) ans = 0 for i in range(len(ruiseki_A)): tmp = K - ruiseki_A[i] if tmp < 0: continue r = len(ruiseki_B) l = 0 while r-l > 1: mid = (r + l) // 2 if ruiseki_B[mid] <= tmp: l = mid else: r = mid ans = max(ans, i+l) print(ans)
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) from bisect import bisect_right from itertools import accumulate n,m,k=nii() a=lnii() b=lnii() ar=[0]+list(accumulate(a)) br=list(accumulate(b)) ans=0 for i in range(n+1): time=ar[i] if time>k: break t_ans=i inx=bisect_right(br,k-time) t_ans+=inx ans=max(ans,t_ans) print(ans)
1
10,705,106,959,930
null
117
117