code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
R, C, K = map(int, input().split()) score = [[0]*C for i in range(R)] for i in range(K): r, c, v = map(int, input().split()) score[r-1][c-1]+=v ans0 = [[0]*C for i in range(R)] ans1 = [[0]*C for i in range(R)] ans2 = [[0]*C for i in range(R)] ans3 = [[0]*C for i in range(R)] ans1[0][0]=score[0][0] ans2[0][0]=score[0][0] ans3[0][0]=score[0][0] for i in range(R): for j in range(C): if i>0: ans0[i][j]=max(ans0[i][j],ans3[i-1][j]) ans1[i][j]=max(ans1[i][j],ans3[i-1][j]+score[i][j]) ans2[i][j]=max(ans2[i][j],ans3[i-1][j]+score[i][j]) ans3[i][j]=max(ans3[i][j],ans3[i-1][j]+score[i][j]) if j>0: ans0[i][j]=max(ans0[i][j],ans0[i][j-1]) ans1[i][j]=max(ans1[i][j],ans0[i][j-1]+score[i][j],ans1[i][j-1]) ans2[i][j]=max(ans2[i][j],ans1[i][j-1]+score[i][j],ans2[i][j-1]) ans3[i][j]=max(ans3[i][j],ans2[i][j-1]+score[i][j],ans3[i][j-1]) print(ans3[R-1][C-1])
R, C, K = map(int, input().split()) V = [[0]*(C+1) for _ in range(R+1)] for _ in range(K): r, c, v = map(int, input().split()) V[r][c] = v dp0 = [[0]*(C+1) for _ in range(R+1)] dp1 = [[0]*(C+1) for _ in range(R+1)] dp2 = [[0]*(C+1) for _ in range(R+1)] dp3 = [[0]*(C+1) for _ in range(R+1)] for i in range(R+1): for j in range(C+1): v = V[i][j] la = lb = lc = ld = 0 if j > 0: la = dp0[i][j-1] lb = dp1[i][j-1] lc = dp2[i][j-1] ld = dp3[i][j-1] dp2[i][j] = max(dp2[i][j], lc, lb + v) dp3[i][j] = max(dp3[i][j], ld, lc + v) if i > 0: max_p = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j]) dp0[i][j] = max(dp0[i][j], max_p, la) dp1[i][j] = max(dp1[i][j], max_p + v, lb, la + v) print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))
1
5,572,017,784,420
null
94
94
def main(): S, T = input().split() print(T + S) main()
n = int(input()) A = [] B = [] for i in range(n): a,b = list(map(int, input().split())) A.append(a) B.append(b) A.sort() B.sort() j = n//2 if n%2 == 0: print((B[j]+B[j-1])-(A[j]+A[j-1])+1) else: print(B[j]-A[j]+1)
0
null
60,218,995,758,592
248
137
import sys def gcd(a,b): if a%b==0: return b return gcd(b,a%b) r=[list(map(int,line.split())) for line in sys.stdin] for i in r: o=gcd(i[0],i[1]) p=i[0]*i[1]/o print(o,int(p))
s = input() k = int(input()) ans = 0 lens = len(s) # n -> n//2 def tansaku(moji, n, m, k): # n以上 m未満を探索する. ansr = 0 cntt = 1 for i in range(n, m-1): if moji[i] == moji[i + 1]: cntt += 1 else: ansr += (cntt // 2) * k cntt = 1 ansr += (cntt // 2) * k return ansr cnnt = 1 hentai = False for i in range(lens-1): if s[i] == s[i+1]: cnnt += 1 if cnnt == lens: hentai = True if not hentai: if k >= 2: zencnts = 0 atocnts = 0 if s[lens-1] == s[0]: for i in range(lens): if s[lens-1-i] == s[lens-1]: zencnts += 1 else: break for i in range(lens): if s[i] == s[0]: atocnts += 1 else: break news = s[atocnts:] + s[:atocnts] news1 = s[atocnts:] news2 = s[:atocnts] ans += tansaku(news, 0, lens, k-1) ans += tansaku(news1, 0, lens-atocnts, 1) ans += tansaku(news2, 0, atocnts, 1) print(ans) else: ans += tansaku(s, 0, lens, 1) print(ans) else: print((lens*k)//2)
0
null
87,380,862,952,530
5
296
n = int(input()) x = list(map(float, input().split())) y = list(map(float, input().split())) def minc_dis(n, x, y, p): sum = 0 for i in range(n): sum = sum + (abs(x[i] - y[i])) ** p return sum ** (1/p) def cheb_dis(n, x, y): dis = 0 for i in range(n): dif = abs(x[i] - y[i]) if dis < dif: dis = dif return dis for p in range(1 , 4): print(minc_dis(n, x, y, p)) print(cheb_dis(n, x, y)) #print(cheb_dis(2, [1, 2, 3], [2, 0, 4]))
dim = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) d1 = [abs(x - y) for x, y in zip(a, b)] print(sum(d1)) d2 = [(x - y)**2 for x, y in zip(a, b)] print(pow(sum(d2), 1/2)) d3 = [(abs(x - y))**3 for x, y in zip(a, b)] print(pow(sum(d3), 1/3)) print(max(d1))
1
218,795,319,440
null
32
32
input_line = input().rstrip().split() if (input_line[0]==input_line[1]): print("Yes") else: print("No")
import math S = input() ans = 0 l = int(math.floor(len(S)/2)) for i in range(l): if S[i] != S[len(S)-1-i]: ans += 1 print(ans)
0
null
101,247,674,688,512
231
261
import math H = int(input()) ans = 0 num = 0 while True: ans += 2**num if H == 1: print(ans) break else: H = math.floor(H/2) num += 1
from math import floor H = int(input()) ans = 0 r = H n = 0 while not (r == 1): n += 1 ans += 2 ** n r = floor(r / 2) ans += 1 print(ans)
1
79,968,308,616,910
null
228
228
import sys from collections import deque input = lambda: sys.stdin.readline().rstrip() def main(): s = deque(input()) q = int(input()) reverse = False for _ in range(q): query = list(input().split()) if query[0] == '1': reverse ^= True else: if reverse: if query[1] == '1': s.append(query[2]) else: s.appendleft(query[2]) else: if query[1] == '1': s.appendleft(query[2]) else: s.append(query[2]) s = ''.join(s) if reverse: s = s[::-1] print(s) if __name__ == '__main__': main()
h,n,*t = map(int,open(0).read().split()) dp = [0] + [10**8]* h for a,b in zip(*[iter(t)]*2): for life_point in range(h +1): original_life = max(0,life_point - a) # print(original_life) magic_consum = dp[original_life]+ b # print(magic_consum) dp[life_point] = min(dp[life_point],magic_consum) # print(dp) print(dp[h])
0
null
69,492,661,033,920
204
229
import itertools import math N=int(input()) zahyou=[list(map(int,input().split()))for i in range(N)] jyunban=list(itertools.permutations(range(N))) dist=list() for i in range(len(jyunban)): tmp=0 for j in range(N-1): tmp+=math.sqrt((zahyou[jyunban[i][j]][0]-zahyou[jyunban[i][j+1]][0])**2+(zahyou[jyunban[i][j]][1]-zahyou[jyunban[i][j+1]][1])**2) dist.append(tmp) print(sum(dist)/math.factorial(N))
X = int(input()) tmp = 360 while True: if tmp % X == 0: print(tmp//X) exit() else: tmp+= 360
0
null
81,084,167,268,930
280
125
x = 0 y = 0 z = 0 for i in range(9): x += 1 y = 0 for j in range(9): y += 1 z = x*y print(x, end = 'x') print(y, end = '=') print(z)
# Aizu Problem 0000: QQ # import sys, math, os # read input: #PYDEV = os.environ.get('PYDEV') #if PYDEV=="True": # sys.stdin = open("sample-input2.txt", "rt") for i in range(1, 10): for j in range(1, 10): print("%dx%d=%d" % (i, j, i*j))
1
2,582,300
null
1
1
print("Yes" if input().count("7") > 0 else "No")
n = input() for i in range(len(n)): if n[i] == '7': print('Yes') exit() print('No')
1
34,351,218,674,980
null
172
172
import sys A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] for e in sys.stdin: c.append(list(map(int, e.split()))) ans = min(a) + min(b) for i in range(len(c)): temp_val = a[c[i][0]-1] + b[c[i][1]-1] - c[i][2] if temp_val < ans: ans = temp_val print(ans)
n = list(raw_input()) for i in xrange(len(n)): if n[i].isupper(): n[i]=n[i].lower() elif n[i].islower(): n[i]=n[i].upper() print ''.join(n)
0
null
27,808,386,909,536
200
61
n = int(input()) a = list(map(int,input().split())) largest = max(a) b = [True] * (largest+1) dict = {} ans = 0 for num in a: if num in dict.keys(): b[num] = False else: dict[num] = 1 y = num * 2 while(y <= largest): b[y] = False y += num for num in a: if b[num] == True: ans += 1 print(ans)
n = int(input()) a = [int(i) for i in input().split()] max_a = max(a) cnt_d = [0] * (max_a + 1) for ai in a: for multi in range(ai, max_a + 1, ai): cnt_d[multi] += 1 print(sum(cnt_d[ai] == 1 for ai in a))
1
14,436,391,704,108
null
129
129
a,b=map(int,input().split()) s=list(map(int,input().split())) ans=0 s=sorted(s) for i in range(b): ans+=s[i] print(ans)
N, K = map(int, input().split()) P = list(map(int, input().split())) assert len(P) == N # 1 <= K <= N <= 1000 P = sorted(P) print(sum(P[:K]))
1
11,672,776,176,678
null
120
120
import sys import math for line in sys.stdin: a = line.split() print int(math.log10(int(a[0]) + int(a[1]))) + 1
import sys l = sys.stdin.readlines() for i in l: x,y = map(int,i.split()) print(str(len(str(x+y))))
1
110,295,088
null
3
3
def read_n_lows_input(n): Alist=[int(input()) for i in range(n)] return Alist def print_list(A): print(*A, sep=" ") def print_list_multi_low(A): for i in A: print(i) def insertion_sort(A, n, g, cnt): for i in range(g-1, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j -= g cnt += 1 A[j+g] = v return A, cnt def shell_sort(A, n): cnt = 0 G0 = [797161, 265720, 88573, 29524, 9841, 3280, 1093, 364, 121, 40, 13, 4, 1] G = [i for i in G0 if i <= n] m = len(G) print(m) print_list(G) for i in range(m): A, cnt = insertion_sort(A, n, G[i], cnt) print(cnt) print_list_multi_low(A) n=int(input()) A = read_n_lows_input(n) shell_sort(A, n)
import sys import math ct= 0 def insertion_sort(a, n, g): global ct for j in range(0,n-g): v = a[j+g] while j >= 0 and a[j] > v: a[j+g] = a[j] j = j-g ct += 1 a[j+g] = v n = int(input()) a = list(map(int, sys.stdin.readlines())) b = 701 g = [x for x in [1,4,10,23,57,132,301,701] if x <= n] while True: b = math.floor(2.25*b) if b > n: break g.append(b) g = g[::-1] for i in g: insertion_sort(a, n, i) print(len(g)) print(*g, sep=" ") print(ct) print(*a, sep="\n")
1
30,416,422,530
null
17
17
# Pythonのスライスは最後が開区間だから癖がある t = input() for i in range(int(input())): cmd = list(input().split()) cmd[1] = int(cmd[1]) cmd[2] = int(cmd[2]) if cmd[0] == "print": print(t[cmd[1] : cmd[2]] + t[cmd[2]]) elif cmd[0] == "reverse": tmp = t[cmd[1] : cmd[2]] + t[cmd[2]] tmp = tmp[::-1] t = t[:cmd[1]] + tmp + t[cmd[2]+1:] elif cmd[0] == "replace": t = t[:cmd[1]] + cmd[3] + t[cmd[2]+1:]
#def area############################### def pr(s,a,b): print s[int(a):int(b)+1] def rv(s,a,b): # a="abcdefghijklmn"len=14 # ra="nmlkjihgfedcba" # edc=9,10,11 # ans="abedcfghijklmn" # reverse 2 4 # 14-b-1,14-a-1 # " tmp=s[::-1] news=s[:int(a)]+tmp[len(tmp)-int(b)-1:len(tmp)-int(a)]+s[int(b)+1:] return news def rp(s,a,b,p): news=s[:int(a)]+p+s[int(b)+1:] return news ######################################## I=raw_input() n=int(input()) for i in range(n): k=raw_input().split(" ") if k[0]=="replace": I=rp(I,k[1],k[2],k[3]) elif k[0]=="reverse": I=rv(I,k[1],k[2]) elif k[0]=="print": pr(I,k[1],k[2])
1
2,063,995,664,712
null
68
68
n=input() k=map(int,raw_input().split()) print min(k),max(k),sum(k)
# coding=utf-8 class Dice(object): def __init__(self, label): self.label = label def _rotateS(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s5, s1, s3, s4, s6, s2] def _rotateN(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s2, s6, s3, s4, s1, s5] def _rotateE(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s4, s2, s1, s6, s5, s3] def _rotateW(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s3, s2, s6, s1, s5, s4] def _spinPos(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s1, s4, s2, s5, s3, s6] def _spinNeg(self): s1, s2, s3, s4, s5, s6 = self.label self.label = [s1, s3, s5, s2, s4, s6] def rotate(self, r): if r == 'S': self._rotateS() elif r == 'N': self._rotateN() elif r == 'E': self._rotateE() elif r == 'W': self._rotateW() elif r == 'SP': self._spinPos() elif r == 'SN': self._spinNeg() elif r == '2S': self._rotateS() self._rotateS() elif r == '2SP': self._spinPos() self._spinPos() def getLabel(self, i): return self.label[i - 1] def match(self, top, front): iTop = self.label.index(top) + 1 topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: '2S'} self.rotate(topRot[iTop]) iFront = self.label.index(front) + 1 frontRot = {2: '', 3: 'SN', 4: 'SP', 5: '2SP'} self.rotate(frontRot[iFront]) def main(): d = Dice(map(int, raw_input().split())) n = input() for _ in xrange(n): top, front = map(int, raw_input().split()) d.match(top, front) print d.getLabel(3) if __name__ == '__main__': main()
0
null
497,188,557,580
48
34
def dfs(v): global t, d, f, visited d[v] = t visited[v] = True t += 1 for u in AL[v]: if not visited[u]: dfs(u) f[v] = t t += 1 # 入力 n = int(input()) AL = [[] for _ in range(n + 1)] for v in range(1, n + 1): AL[v] = [int(x) for x in input().split()][2:] # 計算 d = [0] * (n + 1) f = [0] * (n + 1) t = 1 visited = [False] * (n + 1) for v in range(1, n + 1): if not visited[v]: dfs(v) # 出力 for v in range(1, n + 1): print(v, d[v], f[v])
N = int(input()) edge = [[0] for _ in range(N)] for i in range(N): A = list(map(int, input().split())) for i,a in enumerate(A): A[i] -= 1 edge[A[0]] = sorted(A[2:]) ans = [[0,0] for _ in range(N)] import sys sys.setrecursionlimit(10**8) def dfs(v,now): if len(edge[v])>0: for u in edge[v]: if visited[u]==False: visited[u]=True now += 1 ans[u][0] = now now = dfs(u,now) now += 1 ans[v][1] = now return now visited = [False]*N now = 0 for i in range(N): if visited[i]==False: visited[i]=True now += 1 ans[i][0] = now now = dfs(i,now) for i in range(N): ans[i] = '{} {} {}'.format(i+1,ans[i][0],ans[i][1]) print(*ans,sep='\n')
1
3,167,432,290
null
8
8
n = int(input()) l = list(map(str, input().split())) l.reverse() print(' '.join(l))
a=[input() for i in range(2)] a1=[int(i) for i in a[0].split()] a2=int(a[1]) count=0 while a1[1]<=a1[0]: a1[1]=a1[1]*2 count+=1 while a1[2]<=a1[1]: a1[2]=a1[2]*2 count+=1 if count<=a2: print("Yes") else: print("No")
0
null
3,933,815,708,600
53
101
S = input().replace("hi","") if S == "": print("Yes") else: print("No")
s = input() x = ["hi", "hihi", "hihihi", "hihihihi", "hihihihihi"] if s in x: print("Yes") else: print("No")
1
53,079,422,610,370
null
199
199
import itertools N = int(input()) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) perm = list(itertools.permutations(range(1,N+1))) for i in range(len(perm)): if P == perm[i]: a = i if Q == perm[i]: b = i print(abs(a-b))
def make_text(): temp = [] while True: row = input().split() if row == ['END_OF_TEXT']: break temp.append(list(map(lambda x: x.lower(), row))) return temp def find_word(word,text): num = 0 for row in text: for t in row: if t == word: num += 1 return num if __name__ == '__main__': w = input() t = make_text() num = find_word(w,t) print(num)
0
null
51,304,522,834,990
246
65
for i in range ( int ( input ( ) ) ): ( a, b, c ) = sorted ( list ( map ( int, input ( ).split ( ) ) ) ) if ( a ** 2 ) + ( b ** 2 ) == ( c ** 2 ): print ( "YES" ) else: print ( "NO" )
num = input() for x in range(0, int(num)): l = map(int, input().split()) lists = sorted(l) if lists[2] ** 2 == lists[0] ** 2 + lists[1] ** 2: print("YES") else: print("NO")
1
323,859,520
null
4
4
def dfs(A): if len(A) == n+1: global ans total = 0 for i in range(q): if A[b[i]]-A[a[i]] == c[i]: total += d[i] if total > ans: ans = total return num = A[-1] while num <= m: dfs(A[:]+[num]) num += 1 if __name__ == "__main__": n, m, q = map(int, input().split()) a, b, c, d = [None]*q, [None]*q, [None]*q, [None]*q for i in range(q): a[i], b[i], c[i], d[i] = map(int, input().split()) ans = 0 dfs([1]) print(ans)
from itertools import combinations_with_replacement as R N,M,Q = map(int, input().split()) L = [tuple(map(int, input().split())) for _ in range(Q)] print(max([sum((d if S[b-1] - S[a-1] == c else 0) for a,b,c,d in L) for S in R(range(1, M+1), N)]))
1
27,672,490,789,750
null
160
160
import sys inf = 1<<30 def solve(): n, m = map(int, input().split()) c = [int(i) for i in input().split()] c.sort() dp = [inf] * (n + 1) dp[0] = 0 for i in range(1, n + 1): for cj in c: if i - cj < 0: break dp[i] = min(dp[i], dp[i - cj] + 1) ans = dp[n] print(ans) if __name__ == '__main__': solve()
k = int(input()) a, b = map(int,input().split()) list1 = [] x =(k+a-1)//k y = b // k for i in range(x,y+1): list1.append(i) if list1 == []: print('NG') else: print('OK')
0
null
13,283,505,025,180
28
158
d=int(input()) #365 c=list(map(int,input().split())) s=[] for i in range(d): s.append(list(map(int,input().split()))) ll=[0 for i in range(26)] l=[] ans=[] for i in range(d): for j in range(26): ll[j]+=1 m=-(10**10) for j in range(26): t=s[i][j]+ll[j]*c[j] if m<t: m=t tt=j l.append(ll[tt]) ans.append(tt) ll[tt]=0 print("\n".join(map(lambda x:str(x+1),ans)))
import sys import numpy as np from numba import njit @njit('(i8[:],)', cache=True) def solve(inp): def bitree_sum(bit, t, i): s = 0 while i > 0: s += bit[t, i] i ^= i & -i return s def bitree_add(bit, n, t, i, x): while i <= n: bit[t, i] += x i += i & -i def bitree_lower_bound(bit, n, d, t, x): sum_ = 0 pos = 0 for i in range(d, -1, -1): k = pos + (1 << i) if k <= n and sum_ + bit[t, k] < x: sum_ += bit[t, k] pos += 1 << i return pos + 1 def initial_score(d, ccc, sss): bit_n = d + 3 bit = np.zeros((26, bit_n), dtype=np.int64) INF = 10 ** 18 for t in range(26): bitree_add(bit, bit_n, t, bit_n - 1, INF) ttt = np.zeros(d, dtype=np.int64) last = np.full(26, -1, dtype=np.int64) score = 0 for i in range(d): best_t = 0 best_diff = -INF costs = ccc * (i - last) costs_sum = costs.sum() for t in range(26): tmp_diff = sss[i, t] - costs_sum + costs[t] if best_diff < tmp_diff: best_t = t best_diff = tmp_diff ttt[i] = best_t last[best_t] = i score += best_diff bitree_add(bit, bit_n, best_t, i + 2, 1) return bit, score, ttt def calculate_score(d, ccc, sss, ttt): last = np.full(26, -1, dtype=np.int64) score = 0 for i in range(d): t = ttt[i] last[t] = i score += sss[i, t] - (ccc * (i - last)).sum() return score def update_score(bit, bit_n, bit_d, ccc, sss, ttt, d, q): diff = 0 t = ttt[d] k = bitree_sum(bit, t, d + 2) c = bitree_lower_bound(bit, bit_n, bit_d, t, k - 1) - 2 e = bitree_lower_bound(bit, bit_n, bit_d, t, k + 1) - 2 b = ccc[t] diff -= b * (d - c) * (e - d) diff -= sss[d, t] k = bitree_sum(bit, q, d + 2) c = bitree_lower_bound(bit, bit_n, bit_d, q, k) - 2 e = bitree_lower_bound(bit, bit_n, bit_d, q, k + 1) - 2 b = ccc[q] diff += b * (d - c) * (e - d) diff += sss[d, q] return diff d = inp[0] ccc = inp[1:27] sss = np.zeros((d, 26), dtype=np.int64) for r in range(d): sss[r] = inp[27 + r * 26:27 + (r + 1) * 26] bit, score, ttt = initial_score(d, ccc, sss) bit_n = d + 3 bit_d = int(np.log2(bit_n)) loop = 6 * 10 ** 6 tolerant_min = -3000.0 best_score = score best_ttt = ttt.copy() for lp in range(loop): cd = np.random.randint(0, d) ct = np.random.randint(0, 26) while ttt[cd] == ct: ct = np.random.randint(0, 26) diff = update_score(bit, bit_n, bit_d, ccc, sss, ttt, cd, ct) progress = lp / loop if diff > (1 - progress) * tolerant_min: score += diff bitree_add(bit, bit_n, ttt[cd], cd + 2, -1) bitree_add(bit, bit_n, ct, cd + 2, 1) ttt[cd] = ct if score > best_score: best_score = score best_ttt = ttt.copy() return best_ttt + 1 inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ') ans = solve(inp) print('\n'.join(map(str, ans)))
1
9,708,617,569,992
null
113
113
input = raw_input() 3 input = int(input) ans = input**3 print ans
S = input().strip() INFTY=10**8 dp = [[INFTY for _ in range(2)] for _ in range(len(S))] for k in range(10): n = int(S[-1]) if k>= n: dp[0][0] = min(dp[0][0],2*k-n) else: dp[0][1] = min(dp[0][1],2*k-n+10) for i in range(1,len(S)): n = int(S[-(1+i)]) for k in range(10): if k>n: dp[i][0] = min(dp[i][0],2*k-n+dp[i-1][0],k+(k-1)-n+dp[i-1][1]) elif k==n: dp[i][0] = min(dp[i][0],2*k-n+dp[i-1][0]) if n==0: dp[i][1] = min(dp[i][1],k+(k-1)%10-n+dp[i-1][1]) else: dp[i][1] = min(dp[i][1],k+10-n+k-1+dp[i-1][1]) elif k<n: dp[i][1] = min(dp[i][1],k+10-n+k+dp[i-1][0],k+10-n+k-1+dp[i-1][1]) print(min(dp[len(S)-1][0],dp[len(S)-1][1]+1))
0
null
35,771,140,751,892
35
219
from itertools import product def makelist(BIT): LIST, tmp = [], s[0] for i, bi in enumerate(BIT, 1): if bi == 1: LIST.append(tmp) tmp = s[i] elif bi == 0: tmp = [t + sij for t, sij in zip(tmp, s[i])] else: LIST.append(tmp) return LIST def solve(LIST): CNT, tmp = 0, [li[0] for li in LIST] if any(num > k for num in tmp): return h * w for j in range(1, w): cal = [t + li[j] for t, li in zip(tmp, LIST)] if any(num > k for num in cal): CNT += 1 tmp = [li[j] for li in LIST] else: tmp = cal return CNT h, w, k = map(int, input().split()) s = [[int(sij) for sij in input()] for _ in range(h)] ans = h * w for bit in product([0, 1], repeat=(h - 1)): numlist = makelist(bit) ans = min(ans, solve(numlist) + sum(bit)) print(ans)
# Circle Pond R = int(input()) print(R*2 * 3.14159265)
0
null
40,002,091,746,688
193
167
n, k, s = map(int,input().split()) t1 = [str(s)] * k if s != 10**9: t2 = [str(s+1)] * (n-k) else: t2 = [str(1)] * (n-k) print(*(t1+t2))
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,k,s = map(int, input().split()) if s==10**9: a = [10**9]*k + [1]*(n-k) else: a = [s]*k + [s+1]*(n-k) print(" ".join(map(str, a)))
1
90,948,890,492,650
null
238
238
import string print(input().translate(str.maketrans( string.ascii_uppercase + string.ascii_lowercase, string.ascii_lowercase + string.ascii_uppercase)))
x = int(input()) ans = '' if 400 <= x < 600: ans = '8' elif x < 800: ans = '7' elif x < 1000: ans = '6' elif x < 1200: ans = '5' elif x < 1400: ans = '4' elif x < 1600: ans = '3' elif x < 1800: ans = '2' elif x < 2000: ans = '1' print(ans)
0
null
4,083,529,518,446
61
100
cnt = int(input()) string = input() if len(string) <= cnt: print(string) else: print(string[:cnt] + "...")
def li(): return [int(x) for x in input().split()] N = int(input()) A = li() import math from functools import reduce from collections import defaultdict # 最大公約数(リスト引数) # 空のリストを渡さないよう注意 def GCD_list(numbers): return reduce(math.gcd, numbers) # 数列全ての高速素因数分解 MAX = 10 ** 6 is_prime = [True] * (MAX + 1) divs = [1] * (MAX + 1) is_prime[0], is_prime[1] = False, False i = 1 while i * i <= MAX: if not is_prime[i]: i += 1 continue for j in range(2 * i, MAX + 1, i): is_prime[j] = False divs[j] = i i += 1 pairwise_coprime = True all_primes = defaultdict(int) for k in range(N): n = A[k] p = divs[n] primes = defaultdict(int) while p > 1: primes[p] += 1 n = n // p p = divs[n] # 最後に残った数は1か素数にしかならない if n != 1: primes[n] += 1 for key in primes: if all_primes[key] > 0 and primes[key] > 0: pairwise_coprime = False break all_primes[key] += primes[key] gcd = GCD_list(A) setwise_comprime = (gcd == 1) if pairwise_coprime: print('pairwise coprime') elif setwise_comprime: print('setwise coprime') else: print('not coprime')
0
null
11,850,205,910,364
143
85
import itertools n = int(input()) p = tuple([int(i) for i in input().split()]) q = tuple([int(i) for i in input().split()]) lst = list(itertools.permutations(list(range(1, n + 1)))) print(abs(lst.index(p) - lst.index(q)))
from collections import defaultdict N, X, Y = map(int, input().split()) ctr = defaultdict(int) for i in range(1, N + 1): for j in range(i + 1, N + 1): d = min(j - i, abs(i - X) + 1 + abs(j - Y)) ctr[d] += 1 for i in range(1, N): print(ctr[i])
0
null
72,140,462,857,668
246
187
lit=input() print(lit.swapcase())
N = int(input()) if N == 1: print(0) else: mod = 10**9+7 print((10**N - (2*(9**N) - 8**N)) % mod)
0
null
2,381,623,966,688
61
78
a,b=(input().split()) print("Yes" if(a==b) else "No")
import sys input = sys.stdin.readline class BIT: def __init__(self, n): self.n = n self.bit = [0]*(n+1) def add(self, i, x): i += 1 while i<=self.n: self.bit[i] += x i += i&(-i) def acc(self, i): s = 0 while i>0: s += self.bit[i] i -= i&(-i) return s N = int(input()) S = list(input()[:-1]) bits = [BIT(N) for _ in range(26)] for i in range(N): j = ord(S[i])-ord('a') bits[j].add(i, 1) Q = int(input()) for _ in range(Q): q = input().split() if q[0]=='1': i, c = int(q[1])-1, q[2] j = ord(S[i])-ord('a') bits[j].add(i, -1) k = ord(c)-ord('a') bits[k].add(i, 1) S[i] = c else: l, r = int(q[1])-1, int(q[2])-1 ans = 0 for i in range(26): if bits[i].acc(r+1)-bits[i].acc(l)>0: ans += 1 print(ans)
0
null
72,938,530,504,630
231
210
def biserch(n,List): left = 0 right = len(List) while left < right: mid = (left+right)//2 if n <= List[mid]: right = mid else: left = mid + 1 return left N = int(input()) L = list(map(int,input().split())) L.sort() ans = 0 for i in range(N): for j in range(i+1,N): key = L[i] + L[j] anchor = biserch(key,L) ans += max(anchor - (j+1),0) print(ans)
import bisect import sys from bisect import bisect_left from operator import itemgetter sys.setrecursionlimit(10**9) input = sys.stdin.readline def ii(): return int(input()) def mi(): return map(int, input().split()) def lmi(): return list(map(int, input().split())) def lmif(n): return [list(map(int, input().split())) for _ in range(n)] def main(): N = ii() L = lmi() L.sort() # print(L) # 2辺を固定して、2辺の和より長い辺の数を数える count = 0 for i in range(N): for j in range(i+1, N): limit = L[i] + L[j] longer = bisect_left(L, limit) tmp = longer - (j + 1) # print(limit, longer, tmp) count += longer - (j + 1) print(count) return main()
1
171,871,243,939,292
null
294
294
def cmb(n, r, mod): if (r < 0) or (n < r): return 0 r = min(r, n-r) return fact[n]*factinv[r]*factinv[n-r]%mod mod = 10**9+7 N = 10**6 # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N+1): fact.append((fact[-1]*i)%mod) inv.append((-inv[mod%i]*(mod//i))%mod) factinv.append((factinv[-1]*inv[-1])%mod) n, k = map(int,input().split()) ans = 0 for i in range(0, min(n, k+1)): #0がi個 ans = (ans + cmb(n, i, mod) * cmb(n-1, i, mod)) % mod print(ans)
MOD = int(1e9+7) def main(): N, K = map(int, input().split()) dp = [0] * (K+1) ans = 0 for i in range(1, K+1)[::-1]: tmp = pow(K//i, N, MOD) for j in range(i*2, K+1, i): tmp = (tmp - dp[j]) % MOD dp[i] = tmp ans = (ans + tmp * i) % MOD print(ans) if __name__ == "__main__": main()
0
null
52,134,660,024,240
215
176
A, B, K = map(int, input().split()) i = 0 if A <= K: K = K - A A = 0 if A > K: A = A - K K = 0 if B <= K and A == 0: K = K - B B = 0 if B >= K and A == 0: B = B - K K = 0 print(A) print(B)
import bisect,collections,copy,heapq,itertools,math,numpy,string import sys sys.setrecursionlimit(10**7) def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): A,B,K = LI() A_ans = A-K if A>=K else 0 B_ans = B-(K-A) if K>A else B B_ans = B_ans if B_ans>=0 else 0 print(A_ans,B_ans) main()
1
103,735,985,960,660
null
249
249
n = int(input()) data = list(map(int, input().split())) def insertion_sort(A, N): print(*A) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(*A) insertion_sort(data, n)
n = int(input()) array = [int(a) for a in input().split()] for i in range(n): j = i while j < n: if j != 0 and array[j-1] > array[j]: array[j-1], array[j] = array[j], array[j-1] j -= 1 continue else: break for k in range(n): if k != n-1: print(array[k], end=' ') else: print(array[k])
1
5,204,996,538
null
10
10
a = sum(map(int, input().split())) if a > 21: print("bust") else: print("win")
x, k, d = map(int, input().split()) x = abs(x) k_ = min(k, x // d) k = k - k_ x = x-k_*d if k % 2 != 0: x = abs(x-d) print(x)
0
null
62,213,846,984,540
260
92
import sys def I(): return int(sys.stdin.readline().rstrip()) def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N = I() S = LS2() ans = 0 for i in range(N-2): if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C': ans += 1 print(ans)
set = raw_input().split() if int(set[0]) < int(set[1]) < int(set[2]): print 'Yes' else: print 'No'
0
null
49,839,291,500,558
245
39
from collections import deque import sys INFTY=sys.maxsize WHITE=0 GRAY=1 BLACK=2 color=[] d=[] Q=deque([]) n=0 L=[] def readinput(): global n global L n=int(input()) for i in range(n+1): L.append([]) for i in range(n): inp=list(map(int,input().split())) L[inp[0]]=inp[2:] def bfs(s): global color global d global Q for i in range(n+1): color=[WHITE]*(n+1) d=[-1]*(n+1) color[s]=GRAY d[s]=0 Q.append(s) while(len(Q)>0): u = Q.popleft() for l in L[u]: if(color[l]==WHITE): color[l]=GRAY d[l]=d[u]+1 Q.append(l) color[u]=BLACK if __name__=='__main__': readinput() bfs(1) for i in range(1,n+1): print('{} {}'.format(i, d[i]))
import math import sys n,m = map(int, input().split()) a = list(map(int, input().split())) def gcd(x,y): if x < y: x,y = y,x while x%y != 0: x,y = y,x%y return y def lcm(x,y): return x/gcd(x,y)*y def f(x): count = 0 while x%2 == 0: x /= 2 count += 1 return count for i in range(n): if a[i]%2 == 1: print(0) sys.exit() a[i] /= 2 count = f(a[0]) for i in range(n): if f(a[i]) != count: print(0) sys.exit() a[i] /= 2**count m /= 2**count l = 1 for i in range(n): l = lcm(l,a[i]) if l > m: print(0) sys.exit() m /= l ans = (m+1)/2 print(int(ans))
0
null
51,079,051,534,410
9
247
N, P = map(int, input().split()) S = input() if P == 2 or P == 5: cnt = 0 cnt_a = 0 for s in S[::-1]: if int(s) % P == 0: cnt_a += 1 cnt += cnt_a else: r_lst = [0] * P r_lst[0] = 1 cnt = 0 num = 0 for i, s in enumerate(S[::-1]): num = (num + int(s) * pow(10, i, P)) % P cnt += r_lst[num] r_lst[num] += 1 print(cnt)
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): N, P = map(int, input().split()) S = str(input()) def main(): if P == 2: res = 0 for i in range(N): if int(S[N - 1 - i]) % 2 == 0: res += N - i elif P == 5: res = 0 for i in range(N): if int(S[N - 1 - i]) == 0 or int(S[N - 1 - i]) == 5: res += N - i else: mods = [0] * P # mods[i]はPで割ったあまりがiである連続部分列の個数 tenfactor = 1 mod = 0 mods[mod] += 1 for i in range(N): mod = (mod + int(S[N - i - 1]) * tenfactor) % P tenfactor = (tenfactor * 10) % P mods[mod] += 1 res = 0 for p in range(P): res += mods[p] * (mods[p] - 1) // 2 return res print(main()) resolve()
1
58,056,142,486,738
null
205
205
N,M = map(int,input().split()) print("Yes" if M>=N else "No")
n,m = (int(i) for i in input().split()) print("Yes" if n==m else"No")
1
82,980,058,370,222
null
231
231
def main(): S = input() Q = int(input()) Query=[input().split() for q in range(Q)] cnt=0 prefix, suffix = '', '' for q in Query: if q[0]=='1': cnt=1^cnt prefix, suffix = suffix, prefix #print(cnt) else: if q[1]=='1': prefix=prefix+q[2] else: suffix=suffix+q[2] if cnt: S=S[::-1] print(prefix[::-1]+S+suffix) main()
from collections import deque s = str(input()) q = int(input()) stat = 0 l = [] a = deque() b = deque() for i in range(q): l = list(map(str, input().split())) t = int(l[0]) if t == 1: stat += 1 else: f = int(l[1]) c = l[2] if stat % 2 == 0: if f == 1: a.appendleft(c) else: b.append(c) else: if f == 1: b.append(c) else: a.appendleft(c) #print(a, b, stat % 2) ans = ''.join(a)+s+''.join(b) if stat % 2 == 1: ans = ans[::-1] print(ans)
1
57,086,429,362,788
null
204
204
n=input() count=0 while 1 : x=[i for i in input().split()] if x[0]=="END_OF_TEXT": break for i in range(len(x)): if x[i].lower()==n.lower(): count=count+1 print(count)
import sys s = input().lower() t = sys.stdin.read().lower().split() print(t.count(s))
1
1,795,043,277,664
null
65
65
import sys 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 h, w = LI() if h == 1 or w == 1: print(1) else: if (h * w) % 2 == 0: print(int(h * w / 2)) else: print(int(h * w / 2 + 1))
H, W = map(int, input().split()) if W == 1: print(1) elif H == 1: print(1) else: ans = W * (H // 2) if H % 2 == 1: if W % 2 == 0: ans += W // 2 else: ans += W // 2 + 1 print(ans)
1
50,868,673,185,748
null
196
196
A, B, K = map(int, input().split()) d = min(A, K) #print('d:', d) A -= d K -= d d = min(B, K) #print('d:', d) B -= d K -= d print(A, B)
A, B, K = map(int,input().split()) if K <= A: print(A-K, B) elif K <= A+B: print(0, B-(K-A)) else: print(0,0)
1
104,267,644,353,148
null
249
249
n,k = map(int,input().split()) A = list(map(int,input().split())) c = 0 from collections import Counter d = Counter() d[0] = 1 ans = 0 r = [0]*(n+1) for i,x in enumerate(A): if i>=k-1: d[r[i-(k-1)]]-=1#ここで範囲kからはみ出たものの数を減らす c = (c+x-1)%k ans += d[c] d[c] += 1 r[i+1] = c print(ans)
from collections import defaultdict n, k = map(int, input().split()) a = list(map(int, input().split())) d = defaultdict(int) sa = [0] * (n + 1) d[0] = 1 if k == 1: print(0) exit() for i in range(n): sa[i + 1] = sa[i] + a[i] sa[i + 1] %= k ans = 0 for i in range(1, n + 1): v = sa[i] - i v %= k ans += d[v] d[v] += 1 if 0 <= i - k + 1: vv = sa[i - k + 1] - (i - k + 1) vv %= k d[vv] -= 1 print(ans)
1
137,182,535,453,182
null
273
273
_ = input() S = input() count = 0 for i in range(len(S)-2): if S[i] + S[i+1] + S[i+2] == 'ABC': count += 1 print(count)
n = int(input()) s = input().replace('ABC','1') print(s.count('1'))
1
99,352,581,146,658
null
245
245
while True: try: a = int(input()) t=0 h=0 for i in range(a): b,c=input().split() if b>c: t+=3 elif c>b: h+=3 else: t+=1 h+=1 print(t,h) except EOFError:break
x = int(input()) num = (x//500)*1000 num += ((x%500)//5)*5 print(num)
0
null
22,449,823,112,750
67
185
ri = raw_input().split() stack = [] for i in xrange(len(ri)): if ri[i] == "+": b = stack.pop() a = stack.pop() stack.append(str(int(a)+int(b))) elif ri[i] == "-": b = stack.pop() a = stack.pop() stack.append(str(int(a)-int(b))) elif ri[i] == "*": b = stack.pop() a = stack.pop() stack.append(str(int(a)*int(b))) else: stack.append(ri[i]) print stack.pop()
n=int(input()) arr1=[] arr2=[] for _ in range(n): s=input() cnt1=0 cnt2=0 for i in range(len(s)): if s[i]=='(': cnt1+=1 else: if cnt1==0: cnt2+=1 else: cnt1-=1 if cnt1-cnt2>=0: arr1.append([cnt1,cnt2]) else: arr2.append([cnt1,cnt2]) arr1=sorted(arr1,key=lambda x:x[1]) arr2=sorted(arr2,reverse=True,key=lambda x:x[0]) arr=arr1+arr2 cnt=0 for a,b in arr: if b>cnt: print('No') break else: cnt+=a-b else: if cnt==0: print('Yes') else: print('No')
0
null
11,745,022,088,702
18
152
N = int(input()) A = list(map(int, input().split())) temp = 0 for a in A: temp ^= a ans =[] for a in A: ans.append(temp^a) print(*ans)
n = int(input()) a = [int(i) for i in input().split()] s = 0 for i in a: s ^= i for i in a: print(s^i,end = ' ')
1
12,534,323,578,172
null
123
123
n = int(input()) a = list(map(str, input().split())) a.reverse() for i in range(n): if i == n - 1: print(a[i], end='') else: print(a[i] + ' ', end='') print('')
input() l = [int(i) for i in input().split()] print(" ".join(map(str,l[::-1])))
1
991,903,526,532
null
53
53
n, k = map(int, input().split()) r, s, p = map(int, input().split()) t = input() tt = list(t) d = {'r':p, 's': r, 'p':s} dp = [d[t[i]] for i in range(n)] for i in range(n-k): if tt[i]==tt[i+k]: dp[i+k] = 0 tt[i+k] = 'x' print(sum(dp))
from math import sqrt x1, y1, x2, y2 = map(float, input().split()) r = sqrt((x1 - x2)**2 + (y1 - y2)**2 ) print('{0:.5f}'.format(r))
0
null
53,338,150,203,392
251
29
mtheight = [] for i in xrange(0,10): mtheight.append(input()) mtheight.sort() for i in xrange(0,3): print mtheight[9 - i]
a,b,c = [int(x) for x in input().split( )] div = [] for x in range(1,c+1): if c % x == 0: div.append(x) r = [] for x in range(a,b+1): r.append(x) answer = 0 for x in div: for y in r: if x == y: answer += 1 print(answer)
0
null
281,533,604,098
2
44
N = int(input()) if N % 10 in [2, 4, 5, 7, 9]: print("hon") elif N % 10 in [0, 1, 6, 8]: print("pon") else: print("bon")
N=int(input()) print(sum([((N-1)//1)//i for i in range(1, N)]))
0
null
10,905,678,522,112
142
73
N,K=list(map(int,input().split())) A = [int(x) for x in input().split()] A.sort() print(sum(A[:K]))
import math , sys from decimal import Decimal A , B = list( map( Decimal , input().split())) print( int(A * B ) )
0
null
14,100,129,318,330
120
135
N,K = map(int, input().split()) Sum = 0 while True: Sum += 1 if K ** Sum > N: break print(Sum)
import sys from itertools import accumulate import bisect def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def main(): D = ii() c = list(mi()) s = [list(mi()) for i in range(D)] t = [ii()-1 for i in range(D)] last = [[0]*26 for i in range(D)] v = [0]*D for d in range(D): for i in range(26): if i == t[d]: last[d][i] = d+1 else: last[d][i] = last[d-1][i] k = sum(c[i]*(d+1-last[d][i]) for i in range(26)) v[d] = v[d-1] + s[d][t[d]] - k print(*v, sep='\n') if __name__ == '__main__': main()
0
null
37,332,629,893,960
212
114
from copy import deepcopy H, W = map(int, input().split()) S = [list(input()) for i in range(H)] ans = 0 queue = [[1,0],[-1,0],[0,1],[0,-1]] def now(n,s): t = [] for i in queue: j = n[0] + i[0] k = n[1] + i[1] if 0 <= j < H and 0 <= k < W: if s[j][k] == ".": t.append([j,k]) s[j][k] = "#" return [t,s] def bfs(trust, a, s): t = [] for i in trust: tt, s = now(i,s) t += tt if len(t) == 0: return a else: a = a + 1 return bfs(t, a, s) for i in range(H): for j in range(W): s = deepcopy(S) if S[i][j] == ".": s[i][j] = "#" ans = max(ans, bfs([[i,j]], 0, s)) print(ans)
n,k = map(int,input().split()) l = list(map(int,input().split())) l.sort() price = 0 for i in range(k) : price += l[i] print(price)
0
null
52,934,518,676,500
241
120
x = int(input()) print(2*x*3.14)
import math radius=int(input()) print(2*math.pi*radius)
1
31,349,751,649,466
null
167
167
n, k = map(int, input().split()) # from collections import OrderedDict # d = OrderedDict() # a = list(input().split()) # b = list(map(int, input().split())) # print(r + max(0, 100*(10-n))) # print("Yes" if 500*n >= k else "No") # s = input() # a = int(input()) # b = int(input()) # c = int(input()) print("Yes" if n == k else "No")
r, g, b = map(int, input().split()) t = 0 while r >= g: g *= 2; t += 1 while g >= b: b *= 2; t += 1 print('No' if t > int(input()) else 'Yes')
0
null
45,228,714,735,970
231
101
X, Y = map(int, input().split(' ')) print('Yes' if (X * 2 <= Y <= X * 4) and (Y % 2 == 0) else 'No')
s = list(input()) for i in range(int(input())): cmd, a, b, *c = input().split() a = int(a); b = int(b) if cmd == "print": print(*s[a:b+1], sep='') elif cmd == "reverse": s[a:b+1] = reversed(s[a:b+1]) else: s[a:b+1] = c[0]
0
null
7,853,747,645,240
127
68
import itertools a=int(input()) b=list(map(int,input().split())) c=list(map(int,input().split())) n=sorted(b) m=list(itertools.permutations(n)) m=[list(i) for i in m] print(abs(m.index(b)-m.index(c)))
n,k = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] s = [0] for i in range(len(a)): s.append(s[-1]+a[i]) for i in range(len(s)): s[i] = (s[i] - i) % k # print(s) d = {0:1} ans = 0 for j in range(1,n+1): if s[j] in d: d[s[j]] += 1 else: d[s[j]] = 1 if j >= k: d[s[j-k]] -= 1 ans += d[s[j]] - 1 # print(d) # print(ans) print(ans)
0
null
118,781,505,765,440
246
273
n = int(input()) def sieve1(n): isPrime = [True] * (n+1) isPrime[0] = False isPrime[1] = False for i in range(2*2, n+1, 2): isPrime[i] = False for i in range(3, n+1): if isPrime[i]: for j in range(i+i, n+1, i): isPrime[j] = False return isPrime numOfDivisors = [2] * (n+1) numOfDivisors[1] = 1 numOfDivisors[0] = 0 isPrime = sieve1(n) for i in range(2, n+1): if isPrime[i]: for j in range(2*i, n+1, i): x = j // i numOfDivisors[j] += numOfDivisors[x] - 1 ans = 0 for k in range(1, n+1): ans += numOfDivisors[k] * k print (ans)
import sys input = sys.stdin.readline N = int(input()) S = input()[:-1] R = S.count('R') accR = [0] for Si in S: accR.append(accR[-1]+(1 if Si=='R' else 0)) ans = 10**18 for i in range(N+1): ans = min(ans, abs(i-R)+abs(i-accR[i])) print(ans)
0
null
8,761,004,545,812
118
98
import sys alpha = 'abcdefghijklmnopqrstuvwxyz' dic = {c:0 for c in alpha} t = sys.stdin.read() for s in t: s = s.lower() if s in alpha: dic[s] += 1 for i in sorted(dic): print("{} : {}".format(i,dic[i]))
import sys import string def main(): tmp = '' try: while True: tmp += input() except EOFError: pass tmp = list(filter(lambda x: x in string.ascii_lowercase, tmp.lower())) for c in string.ascii_lowercase: print('{} : {}'.format(c, tmp.count(c))) return 0 if __name__ == '__main__': sys.exit(main())
1
1,691,035,108,320
null
63
63
k = int(input()) a, b = map(int, input().split()) i = 1 ans = "NG" while k*i <= b: if a <= k*i: ans = "OK" break i += 1 print(ans)
from math import gcd def lcm(a,b):return (a*b)//(gcd(a,b)) def f(x): cnt=0 while(x%2==0): cnt+=1 x=x//2 return cnt n,m=map(int,input().split()) a=list(map(int,input().split())) a=list(map(lambda x: x//2,a)) t=f(a[0]) for i in range(n): if(f(a[i])!=t): print(0) exit() a[i]=a[i]//(2**t) m=m//(2**t) l=1 for i in range(n): l=lcm(l,a[i]) if(l>m): print(0) exit() m=m//l print((m+1)//2)
0
null
64,252,901,612,640
158
247
N = int(input()) S = str(N) m = len(S) K = int(input()) #dp[i][j][k]: 上からi桁目までに0以外がj個あって、Nと一致しているならばk=0 dp = [[[0] * 2 for _ in range(4)] for _ in range(m+1)] dp[0][0][0] = 1 for i in range(m): #i=0は架空の桁に相当。 for j in range(4): for k in range(2): #dp[i][j][k]という状態が次の桁でどこに遷移するかを考える。遷移先のni,nj,nkを決定する。 nd = int(S[i]) #Nのi桁目。1桁目はS[0]。 for d in range(10): #dというのが今の桁(i+1)の値 ni = i+1 #今の桁 nj = j nk = k if d != 0: #もし今の桁が0でなければjは一つ増える。 nj += 1 if nj > K: #もしnjが許容値のKを超えたら無視。 continue if k == 0: #ここまで完全一致の時 if d > nd: #今の桁がNのi桁目より大きいつまりNを超えているので無視。 continue elif d < nd: #今の桁がNのi桁目より小さいなら完全一致ではないのでnk=1と変更。 nk = 1 dp[ni][nj][nk] += dp[i][j][k] ans = dp[m][K][0] + dp[m][K][1] print(ans)
a, b, c, k = map(int,input().split()) ans = 0 if a > k: print(k) elif a+b > k: print(a) else: print(a-(k-a-b))
0
null
49,046,194,645,222
224
148
from __future__ import division, print_function, unicode_literals from future_builtins import * N = int(raw_input()) A = list(map(int, raw_input().split())) print(" ".join(map(str, A))) for i in xrange(1,N): j, p = i-1, A[i] while j >= 0 and A[j] > p: A[j+1] = A[j] j -= 1 A[j+1] = p print(" ".join(map(str, A)))
def insertionSort(lst, n): for i in range(1, n): v = lst[i] j = i - 1 while j >= 0 and lst[j] > v: lst[j+1] = lst[j] j = j - 1 lst[j+1] = v print(" ".join([str(n) for n in lst])) if __name__ == "__main__": n = int(input()) lst = [int(n) for n in input().split()] print(" ".join([str(n) for n in lst])) insertionSort(lst, n)
1
5,668,209,830
null
10
10
n,m = map(int,input().split()) if 0 < n and n < 10 and 0 < m and m < 10: print(n*m) else: print(-1)
input_line = input() stack = [] area = 0 pond_area = 0 pond_areas = [] for i,s in enumerate(input_line): if s == '\\': stack.append(i) if pond_area: pond_areas.append((l, pond_area)) pond_area = 0 elif stack and s == '/': l = stack.pop() area += i - l while True: if not pond_areas or pond_areas[-1][0] < l: break else: pond_area += pond_areas.pop()[1] pond_area += i-l if pond_area > 0: pond_areas.append((l, pond_area)) print(area) print( " ".join([str(len(pond_areas))] + [str(a[1]) for a in pond_areas]) )
0
null
79,109,920,497,840
286
21
import sys import collections import bisect readline = sys.stdin.readline def main(): n = int(readline().rstrip()) aList = sorted(list(map(int, readline().rstrip().split()))) z = [0] * n for a in aList: z[a-1] += 1 for i in range(n): print(z[i]) if __name__ == '__main__': main()
import sys n = int(input()) A = list(map(int, sys.stdin.readline().split())) ans = [0] * n for i in A: ans[i-1] += 1 print('\n'.join(map(str, ans)))
1
32,627,448,741,492
null
169
169
import math import sys n,m = map(int, input().split()) a = list(map(int, input().split())) def gcd(x,y): if x < y: x,y = y,x while x%y != 0: x,y = y,x%y return y def lcm(x,y): return x/gcd(x,y)*y def f(x): count = 0 while x%2 == 0: x /= 2 count += 1 return count for i in range(n): if a[i]%2 == 1: print(0) sys.exit() a[i] /= 2 count = f(a[0]) for i in range(n): if f(a[i]) != count: print(0) sys.exit() a[i] /= 2**count m /= 2**count l = 1 for i in range(n): l = lcm(l,a[i]) if l > m: print(0) sys.exit() m /= l ans = (m+1)/2 print(int(ans))
from fractions import gcd # for python 3.5~, use math.gcd def main(): N, M = list(map(int, input().split(' '))) half_A = list(map(lambda x: int(x) // 2, input().split(' '))) lcm = 1 for half_a in half_A: lcm *= half_a // gcd(lcm, half_a) if lcm > M: print(0) exit(0) for half_a in half_A: if (lcm // half_a) % 2 == 0: print(0) exit(0) num_multiples = M // lcm print((num_multiples + 1) // 2) # count only cases that ratios are odd numbers. if __name__ == '__main__': main()
1
102,191,577,554,870
null
247
247
#シェルソート def insertionSort(A, n, g): global cnt for i in range(g, n): #その間隔で比較できる最も左から始める.vが基準値 v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j -= g cnt += 1 A[j+g] = v n = int(input()) A = [int(input()) for i in range(n)] cnt = 0 G = [1] for i in range(100): if n < 1 + 3*G[-1]: break G.append(1+3*G[-1]) m = len(G) G.reverse() for i in range(m): insertionSort(A, n, G[i]) print(m) print(*G) print(cnt) print(*A, sep='\n')
n,m,l=list(map(int,input().split())) m_A=[list(map(int,input().split())) for i in range(n)] m_B=[list(map(int,input().split())) for i in range(m)] for i in range(n): t=[] for k in range(l): s=0 for j in range(m): s+=m_A[i][j]*m_B[j][k] t.append(s) print(*t)
0
null
745,698,465,512
17
60
T = input() r_T = T.replace('?', 'D') #print(r_T.count('PD')) #print(r_T.count('D')) print(r_T)
def main(): n, k, c = map(int,input().split()) s = input() schedule = [w == "o" for w in s] left = [] l_day = 0 right = [] r_day = n - 1 while len(left) < k: if schedule[l_day]: left.append(l_day) l_day += c l_day += 1 while len(right) < k: if schedule[r_day]: right.append(r_day) r_day -= c r_day -= 1 right.reverse() for i in range(k): if left[i] == right[i]: print(left[i] + 1) if __name__ == "__main__": main()
0
null
29,548,786,987,250
140
182
D,T,S = (int(x) for x in input().split()) disable = D - T*S if disable>0: print("No") else: print("Yes")
a, b, c = map(int, input().split()) if a / c <= b: print("Yes") else: print("No")
1
3,519,463,733,980
null
81
81
x = input().split() n = int(x[0]) r = int(x[1]) if n >= 10: pass else: r = r + 100 *(10-n) print(r)
x,y = list(input().split()) x = int(x) y = int(y[0]+y[2]+y[3]) print(x*y//100)
0
null
40,115,561,540,992
211
135
for j in range(1,10): for k in range(1,10): print str(j)+"x"+str(k)+"="+str(j*k)
n, k = map(int, input().split()) def cul(x): ans = (1 + x)*x/(2*x) return ans p = list(map(cul, list(map(int, input().split())))) cnt = sum(p[0:k]) ans = cnt for i in range(k, n): cnt += p[i] - p[i - k] ans = max(ans, cnt) print(ans)
0
null
37,413,863,537,852
1
223
a, b, k = map(int, input().split()) if a >= k: a = a - k else: b = b + a - k a = 0 if b < 0: b = 0 print(str(a) + " " + str(b))
A, B, K = map(int, input().split()) a = max(0, A - K) b = B if K - A > 0: b = max(0, B - K + A) print(a, b)
1
104,367,423,450,820
null
249
249
# Aizu Problem ITP_1_2_B: Range # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") a, b, c = [int(_) for _ in input().split()] print("Yes" if a < b < c else "No")
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N ** 0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def solve(): N = Scanner.int() A = [[-1 for _ in range(N)] for _ in range(N)] for i in range(N): a = Scanner.int() for _ in range(a): x, y = Scanner.map_int() x -= 1 A[i][x] = y ans = 0 for i in range(1 << N): truth = [False for _ in range(N)] for j in range(N): if i >> j & 1: truth[j] = True isOK = True for j in range(N): if not truth[j]: continue for k in range(N): if j == k: continue if A[j][k] == 0 and truth[k]: isOK = False if A[j][k] == 1 and not truth[k]: isOK = False if isOK: ans = max(sum(truth), ans) print(ans) def main(): # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
0
null
61,023,701,577,310
39
262
n=int(input()) ans=':(' for i in range(1,n+1): if int((i*1.08)//1)==n: ans=i break print(ans)
from collections import Counter n=int(input()) stri=list(input()) cc=Counter(stri) count=cc['R']*cc['G']*cc['B'] for i in range(n-2): for j in range(i+1,n-1): if stri[j]==stri[i]:continue lib=['R','G','B'] lib.remove(stri[i]) lib.remove(stri[j]) t=lib.pop() skip_k=2*j-i #print(i,j,skip_k) if skip_k>n-1:continue if stri[skip_k]==t: count-=1 print(count)
0
null
81,281,992,546,566
265
175
nums = [int(i) for i in input().split()] nums.sort() print("{} {} {}".format(nums[0], nums[1], nums[2]))
i = map(int, raw_input().split()) i.sort() print "%d %d %d" %(i[0],i[1],i[2])
1
406,184,471,488
null
40
40
a,b = input().split() if len(a) + len(b) == 2: print(int(a) * int(b)) else: print(-1)
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") a,b = list(map(int, input().split())) if 1<=a<=9 and 1<=b<=9: ans = a*b else: ans = -1 print(ans)
1
158,775,598,906,790
null
286
286
n = int(input()) S = set(list(map(int,input().split()))) q = int(input()) T = list(map(int,input().split())) ans = 0 for t in T: if t in S: ans += 1 print(ans)
s = input() res = 0 cur = 0 for i in s: if i =='S': cur = 0 else: cur += 1 res = max(cur, res) print(res)
0
null
2,508,389,993,778
22
90
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 5 3 1 3 4 3 output: 3 """ import sys def solve(): # write your code here max_profit = -1 * float('inf') min_stock = prices[0] for price in prices[1:]: max_profit = max(max_profit, price - min_stock) min_stock = min(min_stock, price) return max_profit if __name__ == '__main__': _input = sys.stdin.readlines() p_num = int(_input[0]) prices = list(map(int, _input[1:])) print(solve())
N = int(input()) list_price = [int(input()) for i in range(N)] minv = list_price[0] maxv = list_price[1] - list_price[0] for x in list_price[1:]: maxv = max(maxv, x - minv) minv = min(minv, x) print(maxv)
1
12,828,256,288
null
13
13
from math import ceil N,K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort(reverse=True) F.sort() wk = 0 for i in range(N): wk += A[i] * F[i] #print(wk) def is_ok(arg): # 条件を満たすかどうか?問題ごとに定義 cnt = 0 for i in range(N): a,f = A[i], F[i] if a*f <= arg: continue else: #(a-k) * f <= arg # a - arg/f <= k cnt += ceil(a-arg/f) return cnt <= K def meguru_bisect(ng, ok): ''' 初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す まずis_okを定義すべし ng ok は とり得る最小の値-1 とり得る最大の値+1 最大最小が逆の場合はよしなにひっくり返す ''' while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok ng = -1 ok = 10**12 + 10 ans = meguru_bisect(ng,ok) print(ans)
def f(point): k = K for i in range(N): a = A[i] f = F[i] if a*f > point: k -= a - point//f if k < 0: return False # print(point, k) return True N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) l = -1 r = 10**18+1 while (r-l) > 1: mid = (r+l)//2 if f(mid): r = mid else: l = mid print(r)
1
164,523,599,120,580
null
290
290
import sys,queue,math,copy sys.setrecursionlimit(10**7) input = sys.stdin.readline INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in input().split()] _LI = lambda : [int(x)-1 for x in input().split()] N = int(input()) A = LI() c =[0,0,0] cnt = [0 for _ in range(N)] for i in range(N): cnt[i] = c.count(A[i]) if cnt[i] == 0: print (0) exit (0) for j in range(3): if c[j] == A[i]: c[j] += 1 break ans = 1 for i in range(N): ans = (ans * cnt[i]) % MOD print (ans)
N, M = map(int, input().split()) a, w = 0, 0 P = set() W = {} for _ in range(M): p, S = map(str, input().split()) if p in P: continue if S == 'WA': W.setdefault(p, 0) W[p] += 1 if S == 'AC': a += 1 P.add(p) if p in W: w += W[p] print(a, w)
0
null
111,957,007,164,868
268
240
S = input() l = len(S) if l % 2 == 0 and S == l // 2 * "hi": print("Yes") else: print("No")
print('No' if input().replace('hi', '') else 'Yes')
1
53,210,094,790,212
null
199
199
S, T = input().split() A, B = map(int, input().split()) U = input() if U == S: print("%d %d" % (A-1, B)) else: print("%d %d" % (A, B-1))
def main(): s, t = input().split() a, b = map(int, input().split()) u = input() if u == s: a -= 1 else: b -= 1 print(a, b) if __name__ == '__main__': main()
1
71,678,182,148,160
null
220
220
def az11(): n, xs = int(input()), map(int,raw_input().split()) print min(xs), max(xs), sum(xs) az11()
# -*- coding: utf-8 -*- n = input() a = map(int, raw_input().split()) max = a[0] min = a[0] sum = 0 for i in range(n): if a[i] > max: max = a[i] elif a[i] < min: min = a[i] else: pass sum += a[i] print "%d %d %d" %(min, max, sum)
1
720,297,421,452
null
48
48
N, M = map(int, input().split()) A = list(map(int, input().split())) A = sorted(A) A = A[::-1] X = sum(A) Y = 1/4/M ans = 'Yes' for i in range(M): if A[i]/X < Y: ans = 'No' print(ans)
import sys # sys.setrecursionlimit(100000) import bisect def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return [int(i) for i in input().split()] def main(): n = input_int() L = sorted(input_int_list()) ans = 0 for i in range(n - 2): for j in range(i + 1, n - 1): idx = bisect.bisect_left(L, L[i] + L[j]) ans += idx - j - 1 print(ans) return if __name__ == "__main__": main()
0
null
105,398,751,771,500
179
294
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N = int(readline()) P = list(map(int, readline().split())) cur = N + 1 ans = 0 for x in P: if cur > x: ans += 1 cur = x print(ans) if __name__ == '__main__': main()
N = int(input()) A = list(map(int, input().split())) min = A[0] count = 1 for i in range(1, N): if A[i] <= min: count += 1 min = A[i] else: continue print(count)
1
85,386,968,756,648
null
233
233
from collections import deque n = int(input()) G = [] for _ in range(n): u, k, *v = map(int, input().split()) u -= 1 G.append(v) q = deque() seen = [False] * n dist = [-1] * n def main(): q.append(0) seen[0] = True dist[0] = 0 while len(q) > 0: now_v = q.popleft() for new_v in G[now_v]: new_v -= 1 if seen[new_v] is True: continue seen[new_v] = True q.append(new_v) # print(now_v, new_v) dist[new_v] = dist[now_v] + 1 for i in range(n): print(i+1, dist[i]) if __name__ == '__main__': main()
import sys n = int(input()) G = [None]*n for i in range(n): u, k, *vs = map(int, input().split()) G[u-1] = [e-1 for e in vs] from collections import deque dist = [-1]*n que = deque([0]) dist[0] = 0 while que: v = que.popleft() d = dist[v] for w in G[v]: if dist[w] > -1: #already visited continue dist[w] = d + 1 que.append(w) for i in range(n): print(i+1, dist[i])
1
4,465,279,300
null
9
9
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS()) def main(): a, b = GIS() print(a * b) main()
S = input() s=[] for i in S: s.append(i) ans = s[:3] print("".join(map(str, ans)))
0
null
15,180,013,637,700
133
130
import numpy as np import numba from numba import njit, b1, i4, i8, f8 @njit((i8,i8,i8[:],i8[:]), cache=True) def main(H,N,A,B): INF = 1<<30 dp = np.full(H+1,INF,np.int64) dp[0] = 0 for i in range(N): for h in range(A[i],H): dp[h] = min(dp[h],dp[h-A[i]]+B[i]) dp[H] = min(dp[H],min(dp[H-A[i]:H]+B[i])) ans = dp[-1] return ans H, N = map(int, input().split()) A = np.zeros(N,np.int64) B = np.zeros(N,np.int64) for i in range(N): A[i],B[i] = map(int, input().split()) print(main(H,N,A,B))
num=int(input()) if num%1000==0: print(0) else: print(1000-num%1000)
0
null
44,581,981,413,920
229
108
MOD = 1000000007 N, K = map(int, input().split()) ans = 0 f = [0] * (K+1) g = [0] * (K+1) for t in range(K, 0, -1): f[t] = pow(K//t, N, MOD) g[t] = f[t] for s in range(2 * t, K+1, t): g[t] -= g[s] ans = (ans + t * g[t]) % MOD print(ans)
n,m = map(int,input().split()) alist = list(map(int,input().split())) alist.sort(reverse=True) allvote = sum(alist) count = 0 for i in range(n): if alist[i] >= allvote/(4*m): count+=1 if count >= m: print("Yes") else: print("No")
0
null
37,849,348,473,926
176
179
#!/usr/bin/env python3 YES = "Yes" # type: str NO = "No" # type: str def solve(A: int, B: int, C: int, D: int): while True: # 高橋 C -= B if C <= 0: return YES # 青木 A -= D if A <= 0: return NO def main(): A, B, C, D = map(int, input().split()) answer = solve(A, B, C, D) print(answer) if __name__ == "__main__": main()
a, b, c, d = map(int, input().split()) print('Yes' if -(-c//b) <= -(-a//d) else 'No')
1
29,935,765,334,650
null
164
164
a = int(input()) b = 0 for i in str(a): if i=="7": b+=1 if b>0: print("Yes") else: print("No")
print('Yes' if '7' in input() else ('No'))
1
34,438,999,146,230
null
172
172
N = int(input()) if N%2 == 1 : print(0) exit() n = 0 i = 0 for i in range(1,26) : n += N//((5**i)*2) print(n)
import sys def input(): return sys.stdin.readline().rstrip() def main(): n=int(input()) if n%2==1: print(0) else: m=n//2 ans=0 for i in range(1,30): ans+=m//(5**i) print(ans) if __name__=='__main__': main()
1
115,818,112,112,648
null
258
258
s=set() l = [0] * ( 10 ** 5 + 1 ) sum=0 N = int(input()) A = list(map(int, input().split())) for i in range(len(A)): l[A[i]] += 1 s.add(A[i]) sum += A[i] Q = int(input()) for i in range(Q): B, C = map(int, input().split()) if l[B] > 0: s.add(C) sum = sum + l[B] * ( C - B ) l[C] += l[B] l[B] = 0 s.discard(B) print(sum)
def freq(my_list): count = {} for i in my_list: count[i] = count.get(i, 0) + 1 return count n = int(input()) l = list(map(int, input().split())) s,f = sum(l), freq(l) for _ in range(int(input())): x, y = map(int, input().split()) if x in f: v = f[x] if y in f: f[y]+=v f.pop(x) else: f[y]=f.pop(x) s += (y-x)*v print(s)
1
12,254,967,551,246
null
122
122
n=list(input()) n=n[::-1] k=int(n[0]) if k==3: print("bon") elif k==2 or k==4 or k==5 or k==7 or k==9: print("hon") else: print("pon")
import sys N = input() array_hon = [2,4,5,7,9] array_pon = [0,1,6,8] array_bon = [3] if not ( int(N) <= 999 ): sys.exit() if int(N[-1]) in array_hon: print('hon') if int(N[-1]) in array_pon: print('pon') if int(N[-1]) in array_bon: print('bon')
1
19,253,904,263,580
null
142
142
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)
x = int(input()) n = 100 ans = 0 while (x > n): n += (n//100) ans += 1 print(ans)
1
27,158,589,557,340
null
159
159
n = int(input()) taro = 0 hanako = 0 for i in range(n): t,h =input().split() if t > h: taro+=3 elif t<h: hanako += 3 else: taro += 1 hanako += 1 print("%d %d" % (taro,hanako))
def main(): N = int(input()) C = list(input()) C_ = sorted(C) wr = rw = 0 for i in range(len(C_)): if C[i] != C_[i]: if C[i] == "R" and C_[i] == "W": rw += 1 else: wr += 1 print(max(wr, rw)) if __name__ == "__main__": main()
0
null
4,175,879,594,540
67
98