code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
input_list = [] for i in range(0, 3): input_list.append(int(input())) h = input_list[0] w = input_list[1] n = input_list[2] temp_num = 0 if w <= h: temp_num = h else: temp_num = w answer = 0 if n % temp_num == 0: answer = int(n / temp_num) else: answer = (n // temp_num) + 1 print(answer)
h, w, n = map(int, [input() for _ in range(3)]) print((n-1)//max(h, w)+1)
1
88,972,088,527,908
null
236
236
deck = [(s, n) for s in ['S', 'H', 'C', 'D'] for n in range(1, 14)] N = input() for n in range(N): s, n = raw_input().split() deck.remove((s, int(n))) for s, n in deck: print s, n
import sys input = sys.stdin.readline n = int(input()) print(8 - int((n - 400) / 200))
0
null
3,876,929,060,170
54
100
N = int(input()) A = list(map(int, input().split())) if A[0] == 1: if len(A) > 1: print(-1) exit() else: print(1) exit() elif A[0] > 1: print(-1) exit() S = [0] * (N + 2) for i in range(N, -1, -1): S[i] = S[i + 1] + A[i] sec = [0] * (N + 1) sec[0] = 1 for i in range(1, N + 1): a = A[i] v = sec[i - 1] * 2 if v < a: print(-1) exit() sec[i] = min(v - a, S[i + 1]) print(sum(A) + sum(sec[:-1])) # print(sec) # print(A)
import math N = int(input()) A = list(map(int,input().split())) up = [[] for _ in range(N+1)] # 葉から考慮した場合の、最小値 up[N] = [A[N],A[N]] #print(up) for i in reversed(range(N)): Min, Max = up[i+1] #print(Min,Max) Min_n = math.ceil(Min/2) + A[i] Max_n = Max + A[i] #print(A[i],i) up[i] = [Min_n, Max_n] #print(up) if up[0][0] >= 2: print(-1) else: down = 1 #print(down) ans = 1 for i in range(1, N+1): down *= 2 down = min(down,up[i][1]) - A[i] ans += down + A[i] print(ans)
1
18,763,977,242,500
null
141
141
def main(): n = int(input()) bit = input()[::-1] count = bit.count("1") count_plus = count+1 count_minus = count-1 pow_plus = [1 % count_plus] for i in range(n): pow_plus.append(pow_plus[-1]*2 % count_plus) if count_minus != 0: pow_minus = [1 % count_minus] for i in range(n): pow_minus.append(pow_minus[-1]*2 % count_minus) else: pow_minus = [] bit_plus = 0 bit_minus = 0 for i in range(n): if bit[i] == "1": bit_plus = (bit_plus+pow_plus[i]) % count_plus if count_minus != 0: for i in range(n): if bit[i] == "1": bit_minus = (bit_minus+pow_minus[i]) % count_minus ans = [] for i in range(n): if bit[i] == "1": if count_minus == 0: ans.append(0) continue bit_ans = (bit_minus-pow_minus[i]) % count_minus count = count_minus else: bit_ans = (bit_plus+pow_plus[i]) % count_plus count = count_plus cnt = 1 while bit_ans: b = str(bin(bit_ans)).count("1") bit_ans = bit_ans % b cnt += 1 ans.append(cnt) for i in ans[::-1]: print(i) main()
h, a = map(int, input().split()) b = 0 while h-a > 0: h = h - a b += 1 print(b + 1)
0
null
42,796,510,158,160
107
225
# coding: utf-8 s = input() print("x" * len(s))
a=input() b=a.split(" ") c=list(map(int,b)) w=c[0] h=c[1] x=c[2] y=c[3] r=c[4] if((x-r)<0 or (x+r)>w or (y-r)<0 or (y+r)>h): str="No" else : str="Yes" print(str)
0
null
36,780,676,126,012
221
41
X = int(input()) A = 100 for i in range(10**5): A = A*101//100 if X <= A: break print(i+1)
import math from decimal import Decimal X = int(input()) now = 100 year = 0 while True: if now >= X: break #now = int(now * Decimal("1.01")) now = int(now * round(Decimal(1.01), 2)) year += 1 print(year)
1
26,950,766,529,050
null
159
159
import sys sys.setrecursionlimit(10 ** 9) from collections import Counter class UnionFind: def __init__(self, N): self.root = [n for n in range(N)] def get_root(self, x): if self.root[x] == x: return x else: self.root[x] = self.get_root(self.root[x]) return self.root[x] def unite(self, x, y): root_x = self.get_root(x) root_y = self.get_root(y) if root_x != root_y: self.root[root_x] = root_y def final(self): for i in range(N): root_r = self.get_root(self.root[i]) if root_r != self.root[i]: self.root[self.root[i]] = root_r def main(N, M, AB): uf = UnionFind(N) {uf.unite(*ab) for ab in AB} c = Counter(map(uf.get_root, uf.root)) print(len(c) - 1) if __name__ == '__main__': N, M = list(map(int, input().split())) AB = {tuple(map(lambda x:int(x)-1, input().split())) for m in range(M)} main(N, M, AB)
def main(): x = int(input()) ans=int(x/500)*1000 x-=int(x/500)*500 ans+=int(x/5)*5 print(ans) main()
0
null
22,436,282,887,262
70
185
n,p=map(int,input().split()) s=input() ans=0 if p==2: for i in range(n): if int(s[i])%2==0: ans+=i+1 print(ans) elif p==5: for i in range(n): if int(s[i])%5==0: ans+=i+1 print(ans) else: s=s[::-1] accum=[0]*n d=dict() for i in range(n): accum[i]=int(s[i])*pow(10,i,p)%p for i in range(n-1): accum[i+1]+=accum[i] accum[i+1]%=p accum[-1]%=p #print(accum) for i in range(n): if accum[i] not in d: if accum[i]==0: ans+=1 d[accum[i]]=1 else: if accum[i]==0: ans+=1 ans+=d[accum[i]] d[accum[i]]+=1 #print(d) print(ans)
def main(): N, P = map(int, input().split()) S = input() ans = 0 mods = [0 for i in range(N+1)] digits = 1 if P == 2 or P == 5: for i in range(N-1, -1, -1): if int(S[i])%P == 0: ans += i+1 print(ans) return for i in range(N-1, -1, -1): mods[i] = (int(S[i]) * digits % P + mods[i+1]) % P digits = digits * 10 % P count = [0 for i in range(P)] for i in range(N, -1, -1): ans += count[mods[i]] count[mods[i]] += 1 print(ans) main()
1
58,285,885,675,468
null
205
205
from sys import stdin def main(): #入力 readline=stdin.readline n,m=map(int,readline().split()) s=readline().strip() ans=[] flag=False i=n while True: max_i=i for sa in range(1,m+1): if i-sa==0: ans.append(sa) flag=True break else: if s[i-sa]=="0": max_i=i-sa if flag: break else: if max_i!=i: ans.append(i-max_i) i=max_i else: break if flag: ans.reverse() print(*ans) else: print(-1) if __name__=="__main__": main()
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,m = list(map(int, input().split())) s = input() c = n ans = [] while c>0: val = None for i in range(1,m+1): if c-i>=0 and s[c-i]=="0": val = i if val is None: ans = -1 break c = c-val ans.append(val) if ans==-1: print(ans) else: write(" ".join(map(str, ans[::-1])))
1
138,736,943,574,458
null
274
274
def solve(): n = int(input()) if n % 2 == 0: print(0.5) else: print(((n+1)//2) / n) if __name__ == '__main__': solve()
n = int(input()) if n%2 == 0: print(1/2) else: n2 = (n//2) + 1 print(n2/n)
1
177,166,038,286,820
null
297
297
def main(): num = int(input()) print(1-((int(num/2)/num))) main()
X, N = list(map(int, input().split())) p = set(map(int, input().split())) dist = 0 if N == 0: print(X) dist_max = -2 else: dist_max = max(abs(max(p) - X), abs(min(p) - X)) while dist <= dist_max+1: if (X - dist in p) and (X + dist in p): dist += 1 continue if not (X - dist in p): print(X - dist) break elif not (X + dist in p): print(X + dist) break
0
null
96,059,240,958,812
297
128
from itertools import accumulate as acc from bisect import bisect_right N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) A_acc = [0] + list(acc(A)) B_acc = [0] + list(acc(B)) max_num = 0 for i in range(min(K+1, N+1)): # Aからi冊読む count_a = i time = A_acc[i] # Bから読めるだけ読む count_b = bisect_right(B_acc, K-time)-1 time += B_acc[count_b] # print(time, count_a, count_b) count = count_a + count_b if time <= K: max_num = max(max_num, count) print(max_num)
n,m,k = map(int,input().split()) a = [0] + list(map(int,input().split())) b = [0] + list(map(int,input().split())) for i in range(1,n+1): a[i] += a[i-1] for i in range(1,m+1): b[i] += b[i-1] ans,ai,bi = 0,0,0 for i in range(n+1): if a[i]<=k: ai = i for j in range(m+1): if a[ai]+b[j]<=k: bi = j ans = ai+bi for i in range(ai): for j in range(bi,m+1): if a[ai-i-1]+b[j]>k: bi = j break else: ans = max(ans,ai-i-1+j) print(ans)
1
10,766,072,309,398
null
117
117
#!/usr/bin/env python3 import sys, math input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') sys.setrecursionlimit(10**8) inf = float('inf') ans=count=0 n,m=map(int,input().split()) A=list(map(int,input().split())) dp=[inf]*(n+1) dp[0]=0 for a in A: for i in range(a,n+1): dp[i]=min(dp[i],dp[i-a]+1) print(dp[n])
n,m = map(int,input().split()) C = list(map(int,input().split())) INF = 50010 dp = [[INF]*(n+1) for _ in range(m+1)] for i in range(m): dp[i+1][0] = 0 for j in range(1,n+1): if j-C[i] >= 0: dp[i+1][j] = min(dp[i+1][j-C[i]]+1,dp[i][j]) else: dp[i+1][j] = dp[i][j] print(dp[m][n])
1
144,635,396,300
null
28
28
from sys import stdin while True: h, w = (int(n) for n in stdin.readline().rstrip().split()) if h == w == 0: break for _ in range(h): print("#" * w) print()
while 1 : try: h,w=map(int,input().split()) #print(h,w) if( h==0 and w==0 ): break else: for hi in range(h): print("#" * w) print() #?????? if( h==0 and w==0 ): break except (EOFError): #print("EOFError") break
1
762,328,851,778
null
49
49
s = input() t = input() print(sum(s[i] != t[i] for i in range(len(s))))
s = input() t = input() l = len(s) x = 0 for i in range(l): if s[i] != t[i]: x += 1 print(x)
1
10,576,100,641,792
null
116
116
MOD = 10**9+7 n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() #print(a) kai = [1] gai = [] for i in range(n): j = (kai[i] * (i+1)) % MOD kai.append(j) for i in range(n+1): j = kai[i] l = pow(j, MOD-2, MOD) gai.append(l) #print(kai) #print(gai) ans = 0 for i in range(n): if i <= (n-k): #print('xあり') x = (a[i] * kai[n-i-1] * gai[n-i-k] * gai[k-1]) % MOD else: x = 0 #print('xha', x) if i >= (k-1): #print('yあり') y = (a[i] * kai[i] * gai[i-k+1] * gai[k-1]) % MOD else: y = 0 #print('yha', y) ans = (ans + y - x) % MOD #print(ans) print(ans)
import sys sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline class Combination: def __init__(self, n: int, mod: int): self.mod = mod self.fact = [0] * (n + 1) self.factinv = [0] * (n + 1) self.inv = [0] * (n + 1) self.fact[0] = self.fact[1] = 1 self.factinv[0] = self.factinv[1] = 1 self.inv[1] = 1 for i in range(2, n + 1): self.fact[i] = (self.fact[i - 1] * i) % mod self.inv[i] = (-self.inv[mod % i] * (mod // i)) % mod self.factinv[i] = (self.factinv[i - 1] * self.inv[i]) % mod def ncr(self, n: int, r: int): if r < 0 or n < r: return 0 r = min(r, n - r) return self.fact[n] * self.factinv[r] % self.mod * self.factinv[n - r] % self.mod def nhr(self, n: int, r: int): return self.ncr(n + r - 1, r) def npr(self, n: int, r: int): if r < 0 or n < r: return 0 return self.fact[n] * self.factinv[n - r] % self.mod def solve(): N, K = map(int, rl().split()) A = list(map(int, rl().split())) MOD = 10 ** 9 + 7 A.sort() com = Combination(N, MOD) ans = 0 for i in range(N): ans += com.ncr(i, K - 1) * A[i] % MOD ans -= com.ncr(N - i - 1, K - 1) * A[i] % MOD ans %= MOD print(ans) if __name__ == '__main__': solve()
1
95,407,598,496,080
null
242
242
import itertools n = int(input()) p = list(map(int,input().split())) q = list(map(int,input().split())) l = [int(x) for x in range(1,n+1)] i = 0 p_i = 0 q_i = 0 for v in itertools.permutations(l, len(l)): i += 1 if p==list(v): p_i = i #print(list(v)) if q==list(v): q_i = i #print(i,list(v)) print(abs(p_i-q_i))
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) n = INT() p = LIST() q = LIST() count = 0 for x in permutations(range(1, n+1), n): count += 1 if all( x[j] == p[j] for j in range(n)): a = count if all( x[j] == q[j] for j in range(n)): b = count print(abs(a-b))
1
100,736,418,583,688
null
246
246
import collections N = int(input()) A = list(map(int, input().split())) Q = int(input()) query = [] for _ in range(Q): query.append(tuple(map(int, input().split()))) dict_A = collections.Counter(A) # print(dict_A) ans = sum(A) for i in range(Q): if query[i][0] in dict_A.keys(): val = dict_A.pop(query[i][0]) if query[i][1] in dict_A.keys(): dict_A[query[i][1]] += val else: dict_A[query[i][1]] = val ans = ans - (val*query[i][0]) + (val*query[i][1]) print(ans)
import sys A,B = map(int,input().split()) if not ( 1 <= A <= 20 ): sys.exit() if not ( 1 <= B <= 20 ): sys.exit() if not (isinstance(A,int) and isinstance(B,int)): sys.exit() print(A*B) if A <= 9 and B <= 9 else print(-1)
0
null
85,187,544,752,958
122
286
h, w, k = map(int, input().split()) c = [list(input()) for i in range(h)] ans = 0 for i in range(1 << h): for j in range(1 << w): black = 0 for x in range(h): for y in range(w): if (i >> x) & 1: continue if (j >> y) & 1: continue if c[x][y] == '#': black += 1 if black == k: ans += 1 print(ans)
import itertools import numpy as np h, w, k = map(int, input().split()) c = [input() for _ in range(h)] count = 0 for ph in itertools.product([0, 1], repeat=h): for pw in itertools.product([0, 1], repeat=w): squares = np.array([[1 if cell == '#' else -1 for cell in row] for row in c]) squares[np.array(ph) == 1, :] *= 0 squares[:, np.array(pw) == 1] *= 0 count += np.count_nonzero(squares == 1) == k print(count)
1
9,035,803,603,122
null
110
110
import math a, b, h, m = list(map(int, input().split())) deg_m = (m / 60) * 360 deg_h = ((60 * h + m) / 720) * 360 deg = abs(deg_h - deg_m) deg = math.radians(min(360 - deg, deg)) x2 = b ** 2 + a ** 2 - 2 * b * a * math.cos(deg) print(x2**0.5)
dic = {} pat = ['S','H','C','D'] rank = [k for k in range(1,14)] for k in pat: for j in rank: dic[(k,j)]=0 n = int(raw_input()) for k in range(n): p,r = raw_input().split() r = int(r) dic[(p,r)] +=1 for k in pat: for j in rank: if dic[(k,j)]==0: print '%s %d' % (k,j)
0
null
10,448,416,403,230
144
54
from collections import deque import numpy as np # (sx, sy) から (gx, gy) への最短距離を求める # 辿り着けないと INF def bfs(sx, sy): # すべての点を INF で初期化 d = [[float("-inf")] * m for i in range(n)] # 移動4方向のベクトル dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] # スタート地点をキューに入れ、その点の距離を0にする que = deque([]) que.append((sx, sy)) d[sx][sy] = 0 # キューが空になるまでループ while que: # キューの先頭を取り出す p = que.popleft() # 取り出してきた状態がゴールなら探索をやめる #if p[0] == gx and p[1] == gy: # break # 移動4方向をループ for i in range(4): # 移動した後の点を (nx, ny) とする nx = p[0] + dx[i] ny = p[1] + dy[i] # 移動が可能かの判定とすでに訪れたことがあるかの判定 # d[nx][ny] != INF なら訪れたことがある if 0 <= nx < n and 0 <= ny < m and maze[nx][ny] != "#" and d[nx][ny] == float("-inf"): # 移動できるならキューに入れ、その点の距離を p からの距離 +1 で確定する que.append((nx, ny)) d[nx][ny] = d[p[0]][p[1]] + 1 a = np.max(d) return a n, m = map(int, input().split()) maze = [list(input()) for i in range(n)] ans = 1 for x in range(n): for y in range(m): sx = x sy = y if maze[sx][sy] == "#": continue A = bfs(sx, sy) ans = max(A, ans) print(int(ans))
from collections import deque h,w=map(int,input().split()) l=list() l.append('#'*(w+2))#壁 for i in range(h): l.append('#'+input()+'#') l.append('#'*(w+2))#壁 p=0 for i in range(1,h+1): for j in range(1,w+1): if l[i][j]=='#': continue s=[[-1 for a in b] for b in l] q=deque([[i,j]]) s[i][j]=0 while len(q)>0: a,b=q.popleft() for x,y in [[1,0],[0,1],[-1,0],[0,-1]]: if l[a+x][b+y]=='#' or s[a+x][b+y]>-1: continue q.append([a+x,b+y]) s[a+x][b+y]=s[a][b]+1 r=0 for x in s: for y in x: r=max(y,r) p=max(r,p) print(p)
1
94,675,566,424,130
null
241
241
# [箱A, 箱B, 箱C] list = input().split() # 箱Aと箱B入れ替え list[0], list[1] = list[1], list[0] # 箱Aと箱C入れ替え list[0], list[2] = list[2], list[0] print(' '.join(list))
s=input() sl=len(s) a=[] count=1 for i in range(sl-1): if s[i+1]==s[i]: count+=1 else: a.append(count) count=1 a.append(count) ans=0 al=len(a) if s[0]=="<": for i in range(0,al-1,2): m,n=max(a[i],a[i+1]),min(a[i],a[i+1]) ans+=(m*(m+1)+n*(n-1))/2 if al%2==1: ans+=a[-1]*(a[-1]+1)/2 elif s[0]==">": ans+=a[0]*(a[0]+1)/2 for i in range(1,al-1,2): m,n=max(a[i],a[i+1]),min(a[i],a[i+1]) ans+=(m*(m+1)+n*(n-1))/2 if al%2==0: ans+=a[-1]*(a[-1]+1)/2 print(int(ans))
0
null
97,147,428,338,400
178
285
import sys n = int(input()) dic = set() input_ = [x.split() for x in sys.stdin.readlines()] for c, s in input_: if c == 'insert': dic.add(s) else: if s in dic: print('yes') else: print('no')
n = input() dic = set([]) for i in xrange(n): order = raw_input().split() if order[0][0] == 'i': dic.add(order[1]) else: print "yes" if order[1] in dic else "no"
1
79,567,142,098
null
23
23
n = int(input()) AC = 0 WA = 0 TLE = 0 RE = 0 for i in range(n): s = input() if(s == "AC"): AC += 1 elif(s == "WA"): WA += 1 elif(s == "TLE"): TLE += 1 else: RE += 1 print('AC x {}'.format(AC)) print('WA x {}'.format(WA)) print('TLE x {}'.format(TLE)) print('RE x {}'.format(RE))
# AAA or BBB ならNo S = list(input()) S_sorted = ''.join(sorted(S)) # print(S_sorted) if S_sorted == 'AAA' or S_sorted == 'BBB': print('No') else: print('Yes')
0
null
31,912,837,977,148
109
201
r=int(input()) print(3.141592653589793*r*2)
print(int(input())*3.141592*2)
1
31,462,354,285,922
null
167
167
from collections import deque n=int(input()) alpha=['a','b','c','d','e','f','g','h','i','j','k'] q=deque(['a']) for i in range(n-1): qi_ans=[] while(len(q)>0): qi=q.popleft() qiword_maxind=0 for j in range(len(qi)): qi_ans.append(qi+qi[j]) qij_ind=alpha.index(qi[j]) if(qiword_maxind<qij_ind): qiword_maxind=qij_ind else: qi_ans.append(qi+alpha[qiword_maxind+1]) qi_ans=sorted(list(set(qi_ans))) # print(qi_ans) q.extend(qi_ans) lenq=len(q) for i in range(lenq): print(q.popleft())
n,m = map(int,input().split()) coins = sorted(list(map(int,input().split())),reverse=True) dp = [float("inf")]*50001 dp[0] = 0 for i in range(50001): for coin in coins: if i+coin > 50000: continue else: dp[i+coin] = min(dp[i+coin], dp[i]+1) print(dp[n])
0
null
26,206,277,854,720
198
28
print("aA"[input()<"a"])
from collections import deque n, k = map(int, input().split()) a = list(map(int, input().split())) #kを法とする配列を作る a = [(i - 1) for i in a] acc_a = [0 for i in range(n+1)] acc_a[0] = 0 acc_a[1] = a[0] % k #kを法とする累積和 for i in range(2,len(a) + 1): acc_a[i] = (a[i - 1] + acc_a[i-1]) % k ans = 0 count = {} q = deque() for i in acc_a: if i not in count: count[i] = 0 ans += count[i] count[i] += 1 q.append(i) if len(q) == k: count[q.popleft()] -= 1 print(ans)
0
null
74,623,725,842,780
119
273
N = int(input()) S =list(map(int,input())) ans = 0 for x in [0,1,2,3,4,5,6,7,8,9]: if x in S: x_index = S.index(x) for y in [0,1,2,3,4,5,6,7,8,9]: if y in S[x_index+1:]: y_index = S[x_index+1:].index(y) for z in [0,1,2,3,4,5,6,7,8,9]: if z in S[x_index + 1 + y_index+1:]: ans += 1 print(ans)
n = int(input()) num_list = list(map(int,input())) cnt = 0 for i in range(10): if i not in num_list: continue else: first_pwd = num_list.index(i) new_num_list = num_list[first_pwd + 1:] for j in range(10): if j not in new_num_list: continue else: second_pwd = new_num_list.index(j) new_new_num_list = new_num_list[second_pwd+1:] for k in range(10): if k not in new_new_num_list: continue else: cnt += 1 print(cnt)
1
128,605,915,635,748
null
267
267
n,m,k = map(int, input().split()) # --------------------------------------- # nCr(n, r, m) テンプレ mod = 998244353 fac = [1,1] # 階乗 n! inv = [0,1] # 逆元 1/n finv = [1,1] # 逆元の階乗 (n^-1)! = (1/n)! for i in range(2, n+1): fac.append( (fac[-1] * i ) % mod ) inv.append( (-inv[mod%i] * (mod//i)) % mod ) finv.append( (finv[-1] * inv[-1]) % mod ) def nCr(n, r, m): if (n<0 or r<0 or n<r): return 0 r = min(r, n-r) return fac[n] * finv[n-r] * finv[r] % m # ---------------------------- ans = 0 colors = m for p in range(n-1, -1, -1): if p <= k: groups = nCr(n-1, p, mod) ans += groups * colors % mod ans %= mod colors *= m - 1 colors %= mod ans += mod ans %= mod print(ans)
n=int(input()) def make(floor,kind,name): #floor=何階層目か,kind=何種類使ってるか if floor==n+1: print(name) return num=min(floor,kind+1) for i in range(num): use=0 #新しい文字使ってるか if kind-1<i: use=1 make(floor+1,kind+use,name+chr(i+97)) make(1,0,"")
0
null
37,961,327,888,552
151
198
N = int(input()) i = 1 while True: M = 1000*i if M >= N: break i += 1 ans = M-N print(ans)
T=int(input()) a=T//1000 T=T-1000*a if T==0: print(0) else: print(1000-T)
1
8,469,319,593,124
null
108
108
from _collections import deque n = int(input()) data_input = [] dlList = deque() for i in range(n): x = input().split() if x[0] == 'insert': dlList.appendleft(x[1]) elif x[0] == 'delete': if x[1] in dlList: dlList.remove(x[1]) else : pass elif x[0] == 'deleteFirst': dlList.popleft() elif x[0] == 'deleteLast': dlList.pop() else: pass print(' '.join(dlList))
from collections import deque import sys c=sys.stdin def main(): q = deque() N=int(input()) for i in range(N): order=c.readline() if order[6]==" ": if order[0]=="i": q.appendleft(int(order[7:])) else: try : q.remove(int(order[7:])) except: pass else: if order[6]=="F": q.popleft() else: q.pop() print(*list(q)) if __name__ == "__main__": main()
1
48,514,135,600
null
20
20
num_list = raw_input().split() num_list = map(int, num_list) def gcd(x, y): if x < y: x, y = y, x while (y>0): r = x % y x = y y = r return x x = num_list[0] y = num_list[1] print gcd(x, y)
def gcd(a, b): """calculate the greatest common divisor of a, b >>> gcd(54, 20) 2 >>> gcd(147, 105) 21 >>> gcd(100000002, 39273000) 114 """ if a > b: a, b = b, a if a == 0: return b return gcd(b % a, a) def run(): a, b = [int(i) for i in input().split()] print(gcd(a, b)) if __name__ == '__main__': run()
1
6,983,424,548
null
11
11
import sys input = sys.stdin.readline a,b=map(int,input().split()) if a>b: print(str(b)*a) else: print(str(a)*b)
a,b = map(int,input().split()) word = "" for i in range(max(a,b)): word += str(min(a,b)) print(word)
1
84,666,846,958,792
null
232
232
import math r = float(input()) s = r ** 2 * math.pi l = 2 * r * math.pi print("{:.6f}".format(s), "{:.6f}".format(l))
# -*- coding: utf-8 -*- pi = 3.141592653589793 r = float( input() ) area = r * r * pi circle = 2 * r * pi print(format(area, '.10f'), format(circle, '.10f'))
1
635,550,196,496
null
46
46
from collections import deque K = int(input()) Q = deque() for i in range(1, 10): Q.append(i) temp = 0 for i in range(K): temp = Q.popleft() if temp%10 != 0: Q.append(temp*10+temp%10-1) Q.append(temp*10+temp%10) if temp%10 != 9: Q.append(temp*10+temp%10+1) print(temp)
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() def resolve(): k = int(input()) queue = list(range(1, 10)) cnt = 0 for v in queue: cnt += 1 if k == cnt: print(v) return r = v % 10 for d in range(r - 1, r + 2): if 0 <= d <= 9: queue.append(v * 10 + d) resolve()
1
40,307,253,863,054
null
181
181
n, k = map(int, input().split()) mod = 10**9 + 7 res = 0 z = n*(n+1)//2 for x in range(k, n+2): min_ = (x-1)*x//2 max_ = z - (n-x)*(n+1-x)//2 res += max_ - min_ + 1 res %= mod print(res)
N, K = map(int, input().split()) mod = pow(10, 9)+7 Cmax = ((N+N-K+1)*K)//2 Cmin = ((K-1)*K)//2 ans = 1 for i in range(K, N+1): ans = (ans+Cmax-Cmin+1) Cmin += i Cmax += (N-i) print(ans % mod)
1
33,172,596,604,540
null
170
170
S = input() h = S/3600 m = S%3600 / 60 s = S%60 print'%d:%d:%d' % (h,m,s)
def show (nums): for i in range(len(nums)): if i!=len(nums)-1: print(nums[i],end=' ') else : print(nums[i]) n=int(input()) nums=list(map(int,input().split())) show(nums) for i in range(1,n): v=nums[i] j=i-1 while (j>=0 and nums[j]>v): nums[j+1]=nums[j] j-=1 nums[j+1]=v show(nums)
0
null
164,938,386,250
37
10
N = input() result = int(N) ** 3 print(result)
cube = input() print(cube**3)
1
282,353,501,078
null
35
35
#!/usr/bin/env python3 def main(): import sys input = sys.stdin.readline A, B, N = map(int, input().split()) x = min(B - 1, N) print((A * x) // B - A * (x // B)) if __name__ == '__main__': main()
x = int(input()) money1 = x // 500 x %= 500 money2 = x // 5 ans = money1 * 1000 + money2 * 5 print(ans)
0
null
35,584,694,031,392
161
185
n, x, m = (int(x) for x in input().split()) dic = {} count = 1 dic[x]=0 ans = [x] bool = True while (count < n): x = pow(x, 2, m) if x not in dic: dic[x] = count ans.append(x) else: roop = ans[dic[x]:count] ans = sum(ans[:dic[x]]) roop_count = (n-dic[x])//len(roop) roop_hasuu = (n-dic[x])%len(roop) ans+=roop_count*sum(roop)+sum(roop[:roop_hasuu]) print(ans) bool = False count = pow(10, 13) count+=1 if bool: print(sum(ans))
n,x,m=map(int,input().split()) ans=x count=1 table=[0]*m table[x]=1 r=[0,x] #一般項 f=1 for i in range(n-1): x=pow(x,2,m) ans+=x count+=1 if table[x]: f=0 break r.append(x) table[x]=count if f or table[0]: print(ans) exit() ans=0 ''' table[x]項目とcount項目が同じ loop前の項+loopの項*loop数+足りない分 ''' ans=sum(r[:table[x]]) loop=(n-table[x]+1)//(count-table[x]) ans+=sum(r[table[x]:])*loop nokori=(n-table[x]+1)%(count-table[x]) for i in range(nokori): ans+=r[table[x]+i] print(ans)
1
2,820,581,164,800
null
75
75
import math import collections N = int(input()) Point = collections.namedtuple('Point', ['x', 'y']) def koch(d, p1, p2): if d == 0: return th = math.pi * 60 / 180 s = Point(x=(2 * p1.x + p2.x) / 3, y=(2 * p1.y + p2.y) / 3) t = Point(x=(p1.x + 2 * p2.x) / 3, y=(p1.y + 2 * p2.y) / 3) u = Point(x=(t.x - s.x) * math.cos(th) - (t.y - s.y) * math.sin(th) + s.x, y=(t.x - s.x) * math.sin(th) + (t.y - s.y) * math.cos(th) + s.y) koch(d - 1, p1, s) print('{:.8f} {:.8f}'.format(s.x, s.y)) koch(d - 1, s, u) print('{:.8f} {:.8f}'.format(u.x, u.y)) koch(d - 1, u, t) print('{:.8f} {:.8f}'.format(t.x, t.y)) koch(d - 1, t, p2) p1 = Point(x=0, y=0) p2 = Point(x=100, y=0) print('{:.8f} {:.8f}'.format(p1.x, p1.y)) koch(N, p1, p2) print('{:.8f} {:.8f}'.format(p2.x, p2.y))
from sys import stdin,stdout def INPUT():return list(int(i) for i in stdin.readline().split()) def inp():return stdin.readline() def out(x):return stdout.write(x) import math import random ######################################################## F=[1]*(10**6+1) for i in range(2,10**6+1): for j in range(i,10**6+1,i): F[j]+=1 ans=0 n=int(input()) for c in range(1,n): ans+=F[n-c] print(ans)
0
null
1,375,375,841,070
27
73
n=int(input()) a=[int(i) for i in input().split()] aaa=" ".join(map(str,a)) print(aaa) for i in range(1,n): key=a[i] j=i-1 while j >= 0 and a[j] > key: a[j+1]=a[j] j=j-1 a[j+1]=key aaa=" ".join(map(str,a)) print(aaa)
n = int(input()) data = list(map(int, input().split())) def insertionsort(a, n): for i in range(n): v = a[i] j = i - 1; while (j >= 0 and a[j] > v): a[j+1] = a[j] j -= 1 a[j+1] = v print(*a) insertionsort(data, n)
1
5,553,698,322
null
10
10
n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() mod=10**9+7 ans=1 i=0 j=-1 k_1=k while k_1>1: if a[i]*a[i+1]>a[j]*a[j-1]: ans=ans*a[i]*a[i+1]%mod i+=2 k_1-=2 else: ans=ans*a[j]%mod j-=1 k_1-=1 if k_1==1: ans=ans*a[j]%mod if a[-1]<0 and k%2==1: ans=1 for i in a[n-k:]: ans=ans*i%mod print(ans)
n, k = (int(x) for x in input().split()) A = list(int(x) for x in input().split()) MOD = 10**9 + 7 A.sort() l = 0 r = n - 1 sign = 1 # 1 or -1 ans = 1 if k % 2 == 1: ans = A[r] r -= 1 k -= 1 if ans < 0: sign = -1 while k: x = A[l] * A[l + 1] y = A[r] * A[r - 1] if x * sign > y * sign: ans *= x % MOD ans %= MOD l += 2 else: ans *= y % MOD ans %= MOD r -= 2 k -= 2 print(ans)
1
9,440,147,454,630
null
112
112
# import string import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): N = int(input()) A = list(map(int, input().split())) from itertools import accumulate B = [0] + A B = list(accumulate(B)) # 累積和を格納したリスト作成 # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り S=B[-1] minans = 10 ** 20 for i in range(1,N): val=abs(B[i]-(S-B[i])) minans=min(minans,val) print(minans) resolve()
N = int(input()) A = list(map(int, input().split())) ans = float('inf') sum_A = sum(A) hoge = 0 for i in range(N-1): hoge = hoge + A[i] ans = min(ans,abs(sum_A - (hoge*2))) print(ans)
1
142,606,021,892,110
null
276
276
import math a = float(input()) print(str("{0:.6f}".format((a * a) * math.pi)) + " " + str("{0:.5f}".format((a + a) * math.pi)))
import sys import math def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 r = int(readline()) print(r * 2 * math.pi) if __name__ == '__main__': solve()
0
null
16,067,409,194,942
46
167
n=int(input()) s=input() tmp=s[0] ans=1 for i in range(1,n): if s[i]!=tmp: tmp=s[i] ans+=1 print(ans)
n = int(input()) st = input() ans = 1 for i in range(n-1): if st[i] != st[i+1]: ans += 1 print(ans)
1
169,475,145,344,142
null
293
293
n=int(input()) ac=0 wa=0 tle=0 re=0 for _ in range(n): s=input() if s=="AC": ac+=1 elif s=="WA": wa+=1 elif s=="TLE": tle+=1 else: re+=1 print("AC x ",ac) print("WA x ",wa) print("TLE x ",tle) print("RE x ",re)
n=int(input()) l = [input() for i in range(n)] ac = 0 wa = 0 tle = 0 re = 0 for i in l: if i == 'AC': ac += 1 if i == 'WA': wa += 1 if i == 'TLE': tle += 1 if i == 'RE': re += 1 print('AC x '+str(ac)) print('WA x '+str(wa)) print('TLE x '+str(tle)) print('RE x '+str(re))
1
8,748,678,454,212
null
109
109
N = str(input()) lenN = len(N) fN =N[0:(lenN - 1)//2] lN =N[(lenN + 3)//2-1:] print(("No","Yes")[(0,1)[fN == fN[-1::-1]]*(0,1)[lN == lN[-1::-1]]*(0,1)[lN == fN]])
S = input() N = len(S) def is_palindrome(s): return s == ''.join(list(reversed(s))) ans = 'Yes' if is_palindrome(S) and is_palindrome(S[:(N-1)//2]) and is_palindrome(S[(N+1)//2:]) else 'No' print(ans)
1
46,420,454,782,450
null
190
190
ls = list(map(int, input().split(' '))) if sum(ls) >= 22: print('bust') else: print('win')
num_lis = list(map(int,input().split())) amount = sum(num_lis) if amount >= 22: print("bust") else: print("win")
1
118,350,940,021,494
null
260
260
def solve(): s = input() if s == 'SUN': print(7) elif s == 'MON': print(6) elif s == 'TUE': print(5) elif s == 'WED': print(4) elif s == 'THU': print(3) elif s == 'FRI': print(2) elif s == 'SAT': print(1) if __name__ == '__main__': solve()
s=input() dict1={7:'SUN',6:'MON',5:'TUE',4:'WED',3:'THU',2:'FRI',1:'SAT'} keys = [k for k, v in dict1.items() if v == s] print(keys[0])
1
132,910,281,209,180
null
270
270
mod=10**9+7 def fact(n): ans=1 for i in range(1,n+1): ans*=i ans%=mod return ans x,y=map(int,input().split()) if (x+y)%3!=0: print(0) else: temp=(x+y)//3 if x<temp or x>2*temp: print(0) else: dx=x-temp fc_temp=fact(temp) fc_dx=fact(dx) fc_temp_dx=fact(temp-dx) fc_dx=pow(fc_dx,mod-2,mod) fc_temp_dx=pow(fc_temp_dx,mod-2,mod) ans=fc_temp*fc_dx%mod*fc_temp_dx%mod print(ans)
n=int(input()) a=[0,1,2,0,4,0,0,7,8,0,0,11,0,13,14] s=0 for i in range(n+1): if a[i%15]!=0: s+=a[i%15]+i//15*15 print(s)
0
null
92,951,327,293,120
281
173
#E H,N=map(int,input().split()) A=[] B=[] DP=[0]+[float('Inf')]*(2*10**4) for i in range(N): a,b=map(int,input().split()) A.append(a) B.append(b) for j in range(10**4): for i in range(N): DP[j+A[i]]=min(B[i]+DP[j],DP[j+A[i]]) print(min(DP[H:]))
n,t=map(int,input().split()) l=[list(map(int,input().split())) for _ in range(n)] dp=[0]*(t+max(l)[0]) l.sort() for a,b in l: for i in range(0,t+a)[::-1]: if i-a>=0: dp[i]=max(dp[i],dp[i-a]+b) print(max(dp[t:]))
0
null
116,106,848,467,808
229
282
import math N = int(input()) X = N / 1.08 floor = math.ceil(N/1.08) ceil = math.ceil((N+1)/1.08) for i in range(floor,ceil): print(i) break else: print(":(")
N = int(input()) for i in range(1, N + 1): if i + (i * 8) // 100 == N: print(i) break else: print(":(")
1
125,975,968,885,088
null
265
265
x = [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] y = input() K = int(y) print(x[K-1])
from itertools import accumulate n = int(input()) A = list(map(int, input().split())) L = [0] R = [] min_L = float("inf") for i, a in enumerate(A): b = A[-(i+1)] if i%2 == 0: L.append(a) else: R.append(a) R.append(0) L = list(accumulate(L)) R = list(accumulate(R[::-1]))[::-1] ans = -float("inf") if n%2: def f(A): temp = 0 left = 0 right = 0 for i in range(2, n, 2): temp += A[i] res = max(ans, temp) for i in range(1, n//2): temp -= A[i*2] left, right = left+A[2*(i-1)], max(left, right)+A[2*(i-1)+1] res = max(res, temp+max(left, right)) return res ans = max(f(A), f(A[::-1])) temp = 0 for i in range(1, n, 2): temp += A[i] ans = max(ans, temp) else: for l, r in zip(L, R): ans = max(ans, l+r) print(ans)
0
null
43,943,613,526,340
195
177
n,m=map(int, input().split()) roads=[] for _ in range(m): a,b=map(int, input().split()) roads.append([a,b]) group=[i for i in range(n)] group2=[] while group2!=group: group2=list(group) for road in roads: if group[road[1]-1]>group[road[0]-1]: group[road[1]-1]=group[road[0]-1] else: group[road[0]-1]=group[road[1]-1] counter=1 group.sort() for i in range(n-1): if group[i]!=group[i+1]: counter+=1 print(counter-1)
''' Date : 2020-08-09 00:46:52 Author : ssyze Description : ''' n, k = map(int, input().split()) a = list(map(int, input().split())) def check(m): sum = 0 for i in range(len(a)): sum += (a[i] - 1) // m if sum > k: return False else: return True l = 1 r = 10**9 ans = 10**9 while l < r: mid = (l + r) // 2 if check(mid) == 1: r = mid ans = mid else: l = mid + 1 print(ans)
0
null
4,408,406,874,760
70
99
s = input() t = input() # S_r = ''.join(list(reversed(S))) cont = 0 for i in range(len(s)): if s[i] == t[i]: cont += 1 print(len(s)-cont)
n = int(input()) a = list(map(int, input().split())) L = sum(a) l = 0 i = 0 while l < L / 2: l += a[i] i += 1 print(min(abs(sum(a[:i - 1]) - sum(a[i - 1:])), abs(sum(a[:i]) - sum(a[i:]))))
0
null
76,147,989,345,022
116
276
n = int(input()) ans = [] def dfs(A): if len(A) == n: ans.append(''.join(A)) return for i in range(len(set(A))+1): v = chr(i+ord('a')) A.append(v) dfs(A) A.pop() dfs([]) ans.sort() for i in range(len(ans)): print(ans[i])
from collections import deque n,m=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 g[a].append(b) g[b].append(a) def bfs(u): queue = deque([u]) d = [None]*n d[u] = 0 while queue: v=queue.popleft() for i in g[v]: if d[i] is None: d[i] = d[v]+1 queue.append(i) return d d = bfs(0) print('Yes') for i in range(1,n): for j in g[i]: if d[j]<d[i]: print(j+1) break
0
null
36,511,934,523,840
198
145
n=int(input()) a=list(map(int,input().split())) b=[i&1 for i in a[::2]] print(sum(b))
w=input() ll=list() while True: T=input() if T=="END_OF_TEXT": break T=T.lower() t=T.split() for i in t: ll.append(i) ans=ll.count(w) print(ans)
0
null
4,777,708,604,580
105
65
x = int(input()) if x == 1: print("0") elif x == 0: print("1")
from collections import defaultdict s = input() rests = [0] n = 0 a = 0 m = 1 c = defaultdict(int) c[0] += 1 for i in list(s)[::-1]: n = n + int(i)*m c[n % 2019] += 1 m = m * 10 % 2019 for v in c.values(): a += v * (v-1) // 2 print(a)
0
null
16,951,030,508,032
76
166
import sys from collections import Counter import numba as nb import numpy as np input = sys.stdin.readline @nb.njit("i8(i8[:],i8[:])", cache=True) def solve(keys, values): MAX_A = 10 ** 6 divisible = [False] * (MAX_A + 1) ans = 0 for k, v in zip(keys, values): if v == 1 and not divisible[k]: ans += 1 for i in range(k, MAX_A + 1, k): divisible[i] = True return ans def main(): N = int(input()) A = list(map(int, input().split())) A.sort() c = Counter(A) keys = np.array(tuple(c.keys()), dtype=np.int64) values = np.array(tuple(c.values()), dtype=np.int64) ans = solve(keys, values) print(ans) if __name__ == "__main__": main()
x = int(input()) y = int(input()) z = int(input()) a = max(x,y) if z%a == 0: print(z//a) else: print(z//a+1)
0
null
51,451,465,364,520
129
236
N = input() K = int(input()) L = len(N) dp = [[[0]*(K+2) for _ in range(2)] for _ in range(L+1)] dp[0][0][0] = 1 for i in range(1,L+1): a = int(N[i-1]) for k in range(K+1): dp[i][0][k] += dp[i-1][0][k] if a==0 else dp[i-1][0][k-1] dp[i][1][k] += dp[i-1][1][k-1]*9 + dp[i-1][1][k] if a>0: dp[i][1][k] += dp[i-1][0][k-1]*(a-1) + dp[i-1][0][k] print(dp[L][0][K]+dp[L][1][K])
N=int(input()) K=int(input()) s=str(N) N=len(s) # dp[i][smaller][k] :=i桁目までで0以外の数を使用したのがk個である数の個数。 # smallerが1ならNより小さく、0ならNと等しい数であるとする。 dp=[[[0]*(K+2) for j in range(2)] for i in range(N+1)] dp[0][0][0]=1 for i in range(N): for k in range(K+1): ni=int(s[i]) # i桁目まででNより小さいならi+1桁目は何でも良い dp[i+1][1][k+1]+=dp[i][1][k]*9 # i+1桁目が0以外 dp[i+1][1][k]+=dp[i][1][k] # i+1桁目が0 # i桁目まででNと同じで、i+1桁目はNより小さい時 if ni>0: dp[i+1][1][k+1]+=dp[i][0][k]*(ni-1) # i+1桁目が0以外 dp[i+1][1][k]+=dp[i][0][k] # i+1桁目が0以外 # i桁目までNと同じで、i+1桁目もNと同じ数の時 if ni>0: dp[i+1][0][k+1]=dp[i][0][k] # i+1桁目が0以外 else: dp[i+1][0][k]=dp[i][0][k] # i+1桁目が0 print(dp[N][0][K]+dp[N][1][K])
1
75,978,315,666,750
null
224
224
N,X,M = map(int,input().split()) S = X A = [X] exists = [0]*M exists[X] = 1 for i in range(2,N+1): A_i = (A[-1]*A[-1])%M A.append(A_i) S += A_i if exists[A_i] == 0: exists[A_i] = 1 else: S -= A_i del A[-1] B = A[A.index(A_i):] S += ((N-len(A))//len(B))*sum(B) + sum(B[:((N-len(A))%len(B))]) break print(S)
#!/usr/bin/env python3 import sys # https://en.wikipedia.org/wiki/Cycle_detection def floyd_cycle_finding(f, x0): ''' 循環していない部分の長さをlam 循環部分の長さをmuとして (lam, mu) を返す >>> floyd_cycle_finding(lambda x: x**2 % 3, 2) (1, 1) >>> floyd_cycle_finding(lambda x: x**2 % 1001, 2) (2, 4) >>> floyd_cycle_finding(lambda x: x**2 % 16, 2) (2, 1) >>> floyd_cycle_finding(lambda x: x*2 % 5, 3) (0, 4) >>> floyd_cycle_finding(lambda x: x*2 % 5, 0) (0, 1) ''' tortoise = f(x0) hare = f(f(x0)) while tortoise != hare: tortoise = f(tortoise) hare = f(f(hare)) lam = 0 tortoise = x0 while tortoise != hare: tortoise = f(tortoise) hare = f(hare) lam += 1 mu = 1 hare = f(tortoise) while tortoise != hare: hare = f(hare) mu += 1 return lam, mu def solve(N: int, X: int, M: int): f = lambda x: x**2 % M def g(x): while True: yield x x = f(x) lam, mu = floyd_cycle_finding(f, X) ans = 0 gg = g(X) k = max((N - lam) // mu, 0) for i in range(min(N, lam)): ans += next(gg) for i in range(mu): ans += k * next(gg) for i in range(max((N-lam)%mu, 0)): ans += next(gg) return ans # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools 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 X = int(next(tokens)) # type: int M = int(next(tokens)) # type: int print(solve(N, X, M)) def test(): import doctest doctest.testmod() if __name__ == '__main__': #test() main()
1
2,794,836,794,360
null
75
75
n, m = map(int, input().split()) a =[[0 for i in range(m)]for j in range(n)] for i in range(n): a[i] = list(map(int, input().split())) b = [0 for j in range(m)] for j in range(m): b[j] = int(input()) c = [0 for i in range(n)] for i in range(n): for j in range(m): c[i] += a[i][j] * b[j] print(c[i])
input() S = set(input().split()) input() T = set(input().split()) print(len(S & T))
0
null
608,861,013,212
56
22
# coding: utf-8 # Your code here! s=input() ans=ord(s)+1 print(chr(ans))
import sys input = sys.stdin.readline a = input() n = int(a) s = [[0] * 9 for _ in range(9)] for i in range(1, n+1): j = str(i) k = int(j[0]) l = int(j[-1]) if l != 0: s[k-1][l-1] += 1 ans = 0 #print(s) for i in range(1, 10): for j in range(1, 10): ans += s[i-1][j-1] * s[j-1][i-1] print(ans)
0
null
89,054,410,829,440
239
234
d=set() for _ in[0]*int(input()): c,g=input().split() if'i'==c[0]:d|=set([g]) else:print(['no','yes'][g in d])
import sys n = int(input()) dic = set() for i in range(n): cmd = sys.stdin.readline().split() if cmd[0] == "insert": dic.add(cmd[1]) else: print("yes" if cmd[1] in dic else "no")
1
73,322,067,808
null
23
23
c = [] def listcreate(): global c c = [] for y in range(a[0]): b = [] for x in range(a[1]): b.append("#") c.append(b) return def listdraw(): global c for y in range(len(c)): for x in range(len(c[0])): print(c[y][x], end='') print() return for i in range(10000): a = list(map(int,input().split())) if sum(a)==0: break listcreate() listdraw() print()
S = input() DAY = ["SUN","MON","TUE","WED","THU","FRI","SAT"] for num in range(7): if DAY[num] == S: print(7-num)
0
null
66,816,784,949,810
49
270
n =int(input()) first =[] second =[] for i in range(n): d1 , d2 = map(int , input().split()) first.append(d1) second.append(d2) for i in range(n-2): count = 0 for j in range(i ,i+3): if first[j]==second[j]: count +=1 else: break if count ==3: print("Yes") break else: print("No")
import math x1, y1, x2, y2 = map(float, input().split()) x = x2 - x1 y = y2 - y1 result = x**2 + y**2 print(math.sqrt(result))
0
null
1,319,983,632,120
72
29
n,*a=map(int,open(0).read().split()) a.sort() num=[True for i in range(a[-1]+1)] for i in range(n): if num[a[i]]: for j in range(a[-1]//a[i]+1): if j<2: continue num[a[i]*j]=False if i==n-1: pass elif a[i]==a[i+1]: num[a[i]]=False else: pass else: continue ans=0 for i in range(n): if num[a[i]]: ans+=1 print(ans)
import sys def Ii():return int(sys.stdin.buffer.read()) def Mi():return map(int,sys.stdin.buffer.readline().split()) def Li():return list(map(int,sys.stdin.buffer.readline().split())) h1,m1,h2,m2,k = Mi() ans = h2*60+m2-h1*60-m1-k print(ans)
0
null
16,294,701,264,908
129
139
ls = [1,2,3] ls.remove(int(input())) ls.remove(int(input())) print(ls[0])
N = input() if (N[-1] == str(3)): print('bon') elif(int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8 ): print('pon') else: print('hon')
0
null
64,849,604,446,760
254
142
_, S = input(), input().split() _, T = input(), input().split() print(sum(t in S for t in T))
N = int(input()) S = list(map(int, input().split())) Q = int(input()) T = list(map(int, input().split())) C = 0 for i in range(Q): if T[i] in S: C+=1 print(C)
1
66,932,214,410
null
22
22
a, b, m = map(int, input().split()) a_p = list(map(int, input().split())) b_p = list(map(int, input().split())) min_price = min(a_p) + min(b_p) for i in range(m): x, y, c = map(int, input().split()) min_price = min(min_price, a_p[x-1] + b_p[y-1] - c) print(min_price)
import sys sys.setrecursionlimit(10**5) n, u, v = map(int, input().split()) u -= 1 v -= 1 m_mat = [[] for i in range(n)] for _ in range(n-1): a, b = map(int, input().split()) a -= 1 b -= 1 m_mat[a].append(b) m_mat[b].append(a) u_map = [-1]*n v_map = [-1]*n u_map[u] = 0 v_map[v] = 0 def dfs(current, depth, ma): for nex in m_mat[current]: if ma[nex] > -1: continue ma[nex] = depth dfs(nex, depth+1, ma) dfs(u, 1, u_map) dfs(v, 1, v_map) ans = -1 for i in range(n): if u_map[i] < v_map[i] and v_map[i] > ans: ans = v_map[i] print(ans-1)
0
null
85,316,682,275,890
200
259
#!/usr/bin/env python3 import collections as cl import math import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() print(math.ceil(N / 2)) main()
n=int(input()) s=input() judge='' for i in range(n): if s[i]==judge: n-=1 judge=s[i] print(n)
0
null
114,619,505,737,762
206
293
N = int(input()) print(sum([i for i in range(1, N+1) if i%3 if i%5]))
import sys n = int(input()) x = sorted(list(map(int, input().split()))) if len(list(set(x))) == 1: print(0) sys.exit() if n == 1: print(0) sys.exit() x_min = x[0] x_max = x[n-1] min_sum = 10000000 for p in range(x_min, x_max): sum = 0 for e in x: len = (e - p)**2 sum += len # print("p", p, "sum", sum, "min_sum", min_sum) if sum <= min_sum: min_sum = sum print(min_sum)
0
null
50,043,462,899,300
173
213
while True: h, w = map(int, input().split()) if h == 0 and w == 0: break for y in range(h): isOddLine = True if y % 2 == 0: isOddLine = False else: isOddLine = True for x in range(w): if isOddLine: if x % 2 == 0: print('.', end='') else: print('#', end='') else: if x % 2 == 0: print('#', end='') else: print('.', end='') print('') print('')
while True: a, b = map(int, input().split()) if a == 0 and b == 0: break for n in range(a): mark1 = "#" mark2 = "." outLen = "" if n % 2 == 0 : mark1 = "." mark2 = "#" for m in range(b): if m % 2 != 0: outLen = outLen + mark1 else: outLen = outLen + mark2 print(outLen) print("")
1
880,614,591,610
null
51
51
SN=[5,1,2,6] WE=[4,1,3,6] def EWSN(d): global SN,WE if d == "S" : SN = SN[3:4] + SN[0:3] WE[3] = SN[3] WE[1] = SN[1] elif d == "N": SN = SN[1:4] + SN[0:1] WE[3] = SN[3] WE[1] = SN[1] elif d == "E": WE = WE[3:4] + WE[0:3] SN[3] = WE[3] SN[1] = WE[1] elif d == "W": WE = WE[1:4] + WE[0:1] SN[3] = WE[3] SN[1] = WE[1] dice = list(map(int,input().split(" "))) op = input() for i in op: EWSN(i) print(dice[SN[1] - 1])
tmp = [int(e) for e in input().split()] a = tmp[0] b = tmp[1] c = tmp[2] d = tmp[3] res = a * c tmp = a * d if tmp > res: res = tmp tmp = b * c if tmp > res: res = tmp tmp = b * d if tmp > res: res = tmp print(res)
0
null
1,656,295,784,260
33
77
N,A,B = map(int,input().split()) if (B-A)%2==0: print((B-A)//2) else: print(min(A,N-B+1)+(B-A-1)//2)
from sys import stdin input = stdin.readline def main(): N, K = list(map(int, input().split())) R, S, P = list(map(int, input().split())) T = input()[:-1] mem = [] hand_map = {'r': 'p', 's': 'r', 'p': 's'} score_map = {'r': P, 's': R, 'p': S} score = 0 for i in range(K): mem.append(hand_map[T[i]]) score += score_map[T[i]] for i in range(K, N): if not mem[i-K] == hand_map[T[i]]: mem.append(hand_map[T[i]]) score += score_map[T[i]] continue cand = ['r', 's', 'p'] # print(mem[i-K]) cand.remove(mem[i-K]) if i+K < N and not(mem[i-K] == hand_map[T[i+K]]): cand.remove(hand_map[T[i+K]]) mem.append(cand[0]) print(score) if(__name__ == '__main__'): main()
0
null
107,973,511,096,992
253
251
k=int(input()) def dfs(keta, val): lunlun.append(val) if keta==10: return for i in range(-1,2): add=(val%10)+i if 0<=add<=9: dfs(keta+1, val*10+add) lunlun=[] for i in range(1,10): dfs(1, i) lunlun.sort() print(lunlun[k-1])
T,H = 0,0 n = int(input()) for i in range(n): S1,S2 = input().split() if S1 < S2: H += 3 elif S1 > S2: T += 3 else: T += 1 H += 1 print(T,H)
0
null
20,970,084,712,840
181
67
import itertools S = input()[::-1] m = [0]*len(S) tmp = 1 for i in range(len(S)): m[i] = int(S[i])*tmp%2019 tmp = tmp*10%2019 cum = [0]+[0]*len(S) for i in range(1,len(S)+1): cum[i] = (cum[i-1]+m[i-1])%2019 d = {} ans = 0 for i in range(len(cum)): if cum[i] not in d: d[cum[i]] = 1 else: ans += d[cum[i]] d[cum[i]] += 1 print(ans)
from collections import deque s=input()[::-1] l=[0]*2019 ten=1 sm=0 cnt=0 l[0]=1 for i in range(len(s)): sm += int(s[i])*ten sm %= 2019 cnt += l[sm] l[sm] += 1 ten = ten *10 %2019 print(cnt)
1
30,845,284,443,590
null
166
166
A, B = map(int, input().split()) lb_a = int(-(-A // 0.08)) ub_a = int(-(-(A + 1) // 0.08) - 1) lb_b = int(-(-B // 0.1)) ub_b = int(-(-(B + 1) // 0.1) - 1) if ub_b < lb_a or ub_a < lb_b: print(-1) else: print(max(lb_a, lb_b))
a,b = map(int,input().split()) astart, aend = int(a//0.08+1), int((a+1)//0.08) #[astart, aend) bstart, bend = int(b//0.10+1), int((b+1)//0.10) alst = set(range(astart,aend)) blst = set(range(bstart,bend)) share = alst & blst if len(share) == 0: print(-1) else: print(list(share)[0])
1
56,349,888,269,220
null
203
203
n,a,b = map(int,input().split()) mod = n%(a+b) if mod > a : ans = a else: ans = mod ans += (n//(a+b))*a print(ans)
import math def plot(x,y): print(f"{x:.8f} {y:.8f}") def koch(n,x1,y1,x2,y2): if n==0: plot(x1,y1) return ax=(2*x1+x2)/3 ay=(2*y1+y2)/3 bx=(x1+2*x2)/3 by=(y1+2*y2)/3 cx=(bx-ax)*(1/2)-(by-ay)*(math.sqrt(3)/2)+ax cy=(bx-ax)*(math.sqrt(3)/2)+(by-ay)*(1/2)+ay koch(n-1,x1,y1,ax,ay) koch(n-1,ax,ay,cx,cy) koch(n-1,cx,cy,bx,by) koch(n-1,bx,by,x2,y2) n=int(input()) koch(n,0,0,100,0) plot(100,0)
0
null
27,735,479,180,610
202
27
import math def isprime(x): if x == 2: return True if x < 2 or x % 2 == 0: return False i = 3 while(i <= math.sqrt(x)): if x % i == 0: return False i += 2 return True num = raw_input() count = 0 for i in range(int(num)): x = raw_input() if isprime(int(x)): count += 1 print count
from math import sqrt n = int(input()) p = 0 for i in range(n): x = int(input()) ad = 1 j = 2 while j < (int(sqrt(x))+1): if x%j == 0: ad = 0 break else: j += 1 p += ad print(p)
1
10,558,834,210
null
12
12
N, M = map(int, input().split()) res = 0 if N >= 2: res += N * (N - 1) / 2 if M >= 2: res += M * (M - 1) / 2 print(int(res))
from math import floor n,m = map(int,input().split()) a =(n*(n-1))/2 b =(m*(m-1))/2 print(floor(a+b))
1
45,617,417,468,558
null
189
189
from functools import lru_cache @lru_cache(maxsize=None) def fib(n): if n < 2: return n return fib(n-1) + fib(n-2) class Fibonacci(object): memo = [1, 1] def get_nth(self, n): if n < len(Fibonacci.memo): return Fibonacci.memo[n] # print('fib({0}) not found'.format(n)) for i in range(len(Fibonacci.memo), n+1): result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2] Fibonacci.memo.append(result) # print('fib({0})={1} append'.format(i, result)) return Fibonacci.memo[n] if __name__ == '__main__': # ??????????????\??? num = int(input()) # ?????£??????????????°????¨???? #f = Fibonacci() #result = f.get_nth(num) result = fib(num+1) # ??????????????? print('{0}'.format(result))
class Fib(): f = [1] * 50 def fib(self, n): for i in range(2, n + 1): self.f[i] = self.f[i - 1] + self.f[i - 2] return(self.f[n]) x = Fib() print(x.fib(int(input())))
1
2,029,164,320
null
7
7
N=int(input()) #people li = list(map(int, input().split())) Ave1=sum(li)//N Ave2=sum(li)//N+1 S1=0 S2=0 for i in range(N): S1=S1+(Ave1-li[i])**2 for i in range(N): S2=S2+(Ave2-li[i])**2 if S1>S2: print(S2) else: print(S1)
import math n= int(input()) x=n+1 for i in range(2,int(math.sqrt(n)+1)): if n%i==0: x= i+ (n/i) print(int(x)-2)
0
null
113,621,104,833,150
213
288
N = int(input()) count = [[0] * 10 for _ in range(10)] for i in range(1, N + 1): s = str(i) count[int(s[0])][int(s[-1])] += 1 ans = sum(count[i][j] * count[j][i] for i in range(1, 10) for j in range(1, 10)) print(ans)
#同値なものはリストでまとめる n = int(input()) c = [[[] for i in range(9)] for i in range(9)] for i in range(1,n+1): s = str(i) if s[-1] == '0': continue c[int(s[0])-1][int(s[-1])-1].append(i) ans = 0 for i in range(9): for j in range(9): ans += len(c[i][j])*len(c[j][i]) print(ans)
1
86,505,963,959,830
null
234
234
n = int(input()) s = input() if n % 2 != 0: print('No') exit() if s[:n//2] == s[n//2:n]: print('Yes') else: print('No')
def swap(m, n, items): x = items[n] items[n] = items[m] items[m] = x ABC = input().split() if ABC[0] > ABC[1]: swap(0, 1, ABC) if ABC[1] > ABC[2]: swap(1, 2, ABC) if ABC[0] > ABC[1]: swap(0, 1, ABC) elif ABC[1] > ABC[2]: swap(1, 2, ABC) if ABC[0] > ABC[1]: swap(0, 1, ABC) print(ABC[0], ABC[1], ABC[2])
0
null
73,591,334,387,360
279
40
import math while 1: try: a,b = map(int, input().split()) print(math.gcd(a,b), int(a*b/math.gcd(a,b))) except: break
N,K = map(int,input().split()) R,S,P = map(int,input().split()) T = input() V = {"s":R, "p":S, "r":P} ans = 0 for i in range(K): check = T[i] ans += V[T[i]] while True: i += K if i >= N: break if check == T[i]: check = -1 else: ans += V[T[i]] check = T[i] print(ans)
0
null
53,416,760,565,952
5
251
import sys import os import math import bisect import collections import itertools import heapq import re import queue from decimal import Decimal # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N, X, Y = il() k = {n:0 for n in range(N-1)} X -= 1 Y -= 1 for i in range(N-1): for j in range(i+1, N): m = min(abs(i-j), abs(X-i) + abs(Y-j) + 1, abs(X-j) + abs(Y-i) + 1) k[m-1] += 1 for i in range(len(k)): print(k[i]) if __name__ == '__main__': main()
i = 0 while 1: i += 1 x = input() if x == '0': break print(f"Case {i}: {x}")
0
null
22,288,461,324,008
187
42
ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) n,u,v = mi() data = [[] for _ in range(n)] for i in range(n-1): a,b = mi() a -= 1 b -= 1 data[a].append(b) data[b].append(a) inf = -1 oni = [inf]*n ko = [inf]*n from collections import deque def start(hazime,alis): d = deque() d.append((hazime-1,0)) alis[hazime-1] = 0 while d: ima,num = d.popleft() num += 1 for i in data[ima]: if alis[i] != inf: continue alis[i] = num d.append((i,num)) start(u,ko) start(v,oni) if len(data[u]) == 1 and data[u] == v: print(0) exit() ans = -1 for i in range(n): if ko[i] <= oni[i]: ans = max(ans,oni[i]-1) print(ans)
n = int(input()) A = list(map(int, input().split())) P = [0]*n for i in range(n): P[A[i]-1] = i+1 print(*P,sep=' ')
0
null
149,217,903,518,340
259
299
N = int(input()) A = list(map(int, input().split())) B = [] if N == 0: if A[0] != 1: print(-1) exit() else: print(1) exit() else: if A[0] != 0: print(-1) exit() else: B.append(1) for i in range(1, N + 1): B.append((B[i - 1] - A[i - 1]) * 2) if (A[i] > B[i] or (A[i] == B[i] and i != N)): print(-1) exit() ans = 0 ans += A[N] B[N] = A[N] for i in range(N - 1, -1, -1): ans += min(B[i], B[i + 1] + A[i]) B[i] = min(B[i], B[i + 1] + A[i]) print(ans) exit()
#!/usr/bin/env python """NOMURA プログラミングコンテスト 2020: C - Folia https://atcoder.jp/contests/nomura2020/tasks/nomura2020_c """ def main(): N = int(input()) As = list(map(int, input().split())) leaves_count = sum(As) node_count = 1 ans = 0 for i, a in enumerate(As): leaves_count -= a next_node_count = min(leaves_count, (node_count - a) * 2) if next_node_count < 0: ans = -1 break ans += node_count node_count = next_node_count print(ans) if __name__ == '__main__': main()
1
18,769,182,080,700
null
141
141
import math while True: try: n=input() x=100000 for i in xrange(n): x=math.ceil(x*1.05/1000)*1000 print(int(x)) except EOFError: break
money = 100000 for _ in range(int(input())): money += int(money * 0.05) if money % 1000 != 0: while money % 1000 != 0: money += 1 print(money)
1
1,091,723,220
null
6
6
a, b = map(int, input().split()) for i in range(10000): if int(i * 0.08) == a and int(i * 0.1) == b: print(i) exit() print('-1')
n,t=map(int,input().split()) dp=[[-1 for j in range(2)] for i in range(t+1)] dp[0][0]=0 d=[] for i in range(n): d.append(list(map(int,input().split()))) d.sort() for i in range(n): for j in range(t,-1,-1): for k in range(1,-1,-1): if k==0: if dp[j][k]>=0 and j+d[i][0]<t: dp[j+d[i][0]][k]=max(dp[j+d[i][0]][k],dp[j][k]+d[i][1]) if k==1: if dp[j][0]>=0: dp[j][k]=max(dp[j][k],dp[j][0]+d[i][1]) ans=0 for i in range(t+1): for j in range(2): ans=max(ans,dp[i][j]) print(ans)
0
null
104,355,296,036,068
203
282
N=int(input()) if N%2: print(0) else: ans=0 tmp=10 while tmp<=N: ans+=N//tmp tmp*=5 print(ans)
n = int(input()) nums = list(map(int,input().split())) nums.sort() ans = 0 cnt = {} flag = [0]*1000005 for i in nums: cnt[i] = cnt.get(i,0) + 1 for i in nums: if flag[i] == 0 and cnt[i] == 1: ans += 1 if flag[i] == 1: continue for j in range(i,1000001,i): flag[j] = 1 print(ans)
0
null
65,191,411,040,800
258
129
import math p=math.pi r=int(input()) print(2*r*p)
r=int(input()) print(3.141592653589793*r*2)
1
31,409,673,525,090
null
167
167
import sys a = int(sys.stdin.readline().strip()) print("ACL" * a)
k = int(input()) string = "ACL" s = string * k print(s)
1
2,182,106,264,298
null
69
69
from numba import jit import numpy as np n=10**7 @jit("i8[:](i8)") def Make(n): return np.array([i for i in range(n)]) @jit ("i8(i8[:])") def f(a): mod=10**9+7 ans=0 for i in a: ans+=i ans%=mod return ans k=Make(n) f(k) a,b=map(int,input().split()) print(a*b)
class ModCombination: """ nCk (mod m)を扱うクラス """ def __init__(self, mod, n_max): """ イニシャライザ 予め 1~nの階乗と階乗の逆元を計算しておく :param mod: 法 :param n_max: nの最大値(100,000で約1秒) """ self.mod = mod self.n_max = n_max self.facts = [1, 1] self.inverses = [None, 1] self.fact_inverses = [1, 1] for i in range(2, self.n_max + 1): self.facts.append(self.facts[i - 1] * i % self.mod) # self.inverses.append(mod_inverse(i, self.mod)) self.inverses.append( self.mod - self.inverses[self.mod % i] * (self.mod // i) % self.mod ) self.fact_inverses.append( self.fact_inverses[i - 1] * self.inverses[i] % self.mod ) def mod_combination(self, n, k): """ nCk (mod m)を計算する :param n: n :param k: k :return: nCk (mod m) """ if k > n: raise ValueError elif k == n: return 1 elif k == 0: return 1 denominator = self.fact_inverses[k] * self.fact_inverses[n - k] % self.mod return self.facts[n] * denominator % self.mod def mod_pow(a, n, mod): """ 二分累乗法による a^n (mod m)の実装 :param a: 累乗の底 :param n: 累乗の指数 :param mod: 法 :return: a^n (mod m) """ result = 1 a_n = a while n > 0: if n & 1: result = result * a_n % mod a_n = a_n * a_n % mod n >>= 1 return result MOD = 10 ** 9 + 7 K = int(input()) S = input() n = len(S) comb = ModCombination(mod=MOD, n_max=n + K) ans = 0 for i in range(K + 1): ans += (mod_pow(25, i, MOD) * comb.mod_combination(i + n - 1, n - 1)) % MOD * mod_pow(26, K - i, MOD) ans %= MOD print(ans)
0
null
14,363,050,517,750
133
124
str = input() n = int(len(str) / 2) cnt = 0 for i in range(n): if str[i] != str[-1-i]: cnt += 1 print(cnt)
s=list(input()) t=s[::-1] ans=0 for i in range(len(s)): if s[i]!=t[i]: s[i]=t[i];s[-1-i]=t[-1-i];ans+=1 print(ans)
1
120,666,342,584,060
null
261
261
from sys import stdin import collections input = stdin.readline Y, X, M = map(int, input().split()) bomb = set([tuple(map(int,inp.split())) for inp in stdin.read().splitlines()]) cx = collections.defaultdict(int) cy = collections.defaultdict(int) for y,x in bomb: cx[x] += 1 cy[y] += 1 mx = max(cx.values()) my = max(cy.values()) candidateX = [x for (x,v) in cx.items() if v == mx] candidateY = [y for (y,v) in cy.items() if v == my] res = mx + my -1 for x in candidateX: for y in candidateY: if (y,x) not in bomb: res += 1 break else: continue break print(res)
L,R,d=map(int,input().split()) R_=R//d L_=(L-1)//d print(R_-L_)
0
null
6,217,228,722,500
89
104
import math arr = input().split( ) a = int(arr[0]) b1, b2 = arr[1].split('.') b = int(b1)*100 + int(b2) print(a*b//100)
#decimalを使った別解 import decimal deci = decimal.Decimal a,b = input().split() x,y = deci(a),deci(b) ans = (x*y).quantize(deci('0'),rounding=decimal.ROUND_FLOOR) print(ans)
1
16,620,050,582,180
null
135
135
s=input() print("Yes" if s=="hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s=="hihihihihi" else "No")
string = input() n = int(input()) for _ in range(n): query = input().split() if query[0] == 'replace': op, a, b, p = query a, b = int(a), int(b) string = string[:a] + p + string[b + 1:] elif query[0] == 'reverse': op, a, b = query a, b = int(a), int(b) string = string[:a] + ''.join(reversed(string[a:b + 1])) + string[b + 1:] elif query[0] == 'print': op, a, b = query a, b = int(a), int(b) print(string[a: b + 1])
0
null
27,775,461,114,954
199
68