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
N, A, B=map(int, input().split(" ")) result=A*(N//(A+B))+min(N%(A+B), A) print(result)
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 998244353 ############# # Main Code # ############# # N:ブロック # M:色(バリエーション) # K:隣合う組み # N, M, K = 6, 2, 3のとき # K = 0 のとき # 121212, 212121 # K = 1のとき, # 12121 のどこかに同じ数字を挟み込めば # 112121, 122121という風にできる # K = 2のとき # 1212 のどこかに同じ数字を挟む を2回行う # 112212, 112122もできるし # 111212, 122212もできる N, M, K = getNM() # 重複組み合わせのため # 繰り返し使うのでこのタイプ Y = N + K + 1 fact =[1] #階乗 for i in range(1, Y + 1): fact.append(fact[i - 1] * i % mod) facv = [0] * (Y + 1) #階乗の逆元 facv[-1] = pow(fact[-1], mod - 2 , mod) for i in range(Y - 1, -1, -1): facv[i] = facv[i + 1] * (i + 1) % mod def cmb(n, r): if n < r: return 0 return fact[n] * facv[r] * facv[n - r] % mod ans = 0 for i in range(K + 1): opt = M * pow(M - 1, N - i - 1, mod) * cmb(N - i + i - 1, i) ans += opt % mod print(ans % mod)
0
null
39,647,989,982,562
202
151
k=int(input()) s,m,c,a=input(),10**9+7,1,1 for i in range(k):c*=25*(k+len(s)-i)*pow(i+1,m-2,m)%m;c%=m;a+=c print(a%m)
K = int(input()) S = input() MAX = 2 * 10 ** 6 + 1 MOD = 10 ** 9 + 7 # Factorial fac = [0] * (MAX + 1) fac[0] = 1 fac[1] = 1 for i in range(2, MAX + 1): fac[i] = fac[i - 1] * i % MOD # Inverse factorial finv = [0] * (MAX + 1) finv[MAX] = pow(fac[MAX], MOD - 2, MOD) for i in reversed(range(1, MAX + 1)): finv[i - 1] = finv[i] * i % MOD def comb(n, k): if n < k or k < 0: return 0 return (fac[n] * finv[k] * finv[n - k]) % MOD N = len(S) ans = 0 for i in range(K + 1): tmp = (pow(25, K - i, MOD) * pow(26, i, MOD)) % MOD ans += comb(N + K - i - 1, N - 1) * tmp ans %= MOD print(ans)
1
12,742,486,694,178
null
124
124
n = int(input()) a = list(map(int,input().split())) b = [None] *n for idx,person in enumerate(a): b[person-1] = idx+1 for j in b: print(j,end=' ')
D = input() W = ['SUN','MON','TUE','WED','THU','FRI','SAT'] print(7 - W.index(D))
0
null
156,915,769,696,948
299
270
x = int(input()) a = int(x/500) * 1000 + x % 500 - x % 5 print(a)
x=list(map(int, input().split())) L=x[0] R=x[1] d=x[2] res=0 while L<=R: if L%d==0: res+=1 L+=1 print(res)
0
null
25,056,147,962,652
185
104
A = input().split() a = A.count(A[0]) b = A.count(A[1]) c = A.count(A[2]) if a == 2 or b == 2 or c == 2: print("Yes") else: print("No")
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) n = int(input()) def bs(ok, ng, solve): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid return ok ans = bs(n, 0, lambda x: x * 1.08 >= n) if int(ans * 1.08) == n: print(ans) else: print(':(')
0
null
96,632,290,416,650
216
265
n = int(input()) x = list(map(float, input().split(' '))) y = list(map(float, input().split(' '))) p1 = 0.0 p2 = 0.0 p3 = 0.0 pm = 0.0 i = 0 while i < n: p1 += abs(x[i] - y[i]) p2 += pow(abs(x[i] - y[i]), 2) p3 += pow(abs(x[i] - y[i]), 3) pm = max(pm, abs(x[i] - y[i])) i += 1 p2 = pow(p2, 0.5) p3 = pow(p3, 0.333333333333333) ans = '{0:.8f}'.format(p1) + '\n' ans += '{0:.8f}'.format(p2) + '\n' ans += '{0:.8f}'.format(p3) + '\n' ans += '{0:.8f}'.format(pm) print(ans)
def main(): n = int(input()) x = list(map(int, input().split())) y = list(map(int, input().split())) for answer in calc(n, x, y): print("{:.6f}".format(answer)) def calc(n, x, y): ret = [] patterns = [1, 2, 3] for pattern in patterns: sum = 0 for i in range(0, n): sum += (abs(x[i] - y[i])) ** pattern ret.append(sum ** (1 / pattern)) last = 0 for i in range(0, n): last = max(last, abs(x[i] - y[i])) ret.append(last) return ret if __name__ == "__main__": main()
1
215,179,408,168
null
32
32
n, m, L = map(int, input().split()) abc = [list(map(int, input().split())) for _ in range(m)] q = int(input()) st = [list(map(int, input().split())) for _ in range(q)] d = [[float('inf') for _ in range(n)] for _ in range(n)] for a, b, c in abc: if c > L: continue d[a-1][b-1] = c d[b-1][a-1] = c def warshall_floyd(d): for k in range(n): for i in range(n): if i == k or d[i][k] > L: continue for j in range(n): if i == j: continue d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d warshall_floyd(d) for i in range(n): for j in range(n): if i == j: continue elif d[i][j] <= L: d[i][j] = 1 else: d[i][j] = float('inf') warshall_floyd(d) for s, t in st: if d[s-1][t-1] == float('inf'): print(-1) else: print(d[s-1][t-1] - 1)
import sys input=sys.stdin.readline N=int(input()) S=input() Q=int(input()) D={} A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] for i in range(26): D[A[i]]=i n=1 while n<N: n*=2 seg=[0 for i in range(n*2)] #print(seg) for i in range(N): seg[n-1+i]=1<<D[S[i]] k=n-1+i while k>0: k=(k-1)//2 seg[k]=(seg[k*2+1]|seg[k*2+2]) #print(list(bin(seg[0])).count("1")) #0indexでa番目の値をbに変更 def update(a,b): a+=n-1 seg[a]=1<<D[b] while a>0: a=(a-1)//2 seg[a]=(seg[a*2+1]|seg[a*2+2]) #print(seg) #A~B-1(0-index)までの累積和を求める #1~2までの累積和なら(1,3,0,0,n) #Kは接点番号?L,Rはその接点が[L,R)に対応づいていることを表す? #外部からはquery(A,B,0,0,n)として呼び出す def query(A,B,K,L,R): if K>=len(seg): return 0 if R<=A or B<=L: return 0 elif A<=L and R<=B: return seg[K] else: vl=query(A,B,K*2+1,L,(L+R)//2) vr=query(A,B,K*2+2,(L+R)//2,R) #print(vl,vr) return vl|vr #print(n,len(seg)) #print("P",query(2,4,0,0,n),len(query(2,4,0,0,n))) #update(3,"a") #print(seg) #print(query(2,4,0,0,n)) for i in range(Q): x,y,z=list(input().split()) if x=="1": update(int(y)-1,z) else: print(list(bin(query(int(y)-1,int(z),0,0,n))).count("1"))
0
null
118,223,889,727,222
295
210
a, b = map(int, input().split()) def base10to(n, b): if (int(n/b)): return base10to(int(n/b), b) + str(n%b) return str(n%b) print(len(base10to(a,b)))
import itertools n = int(input()) p = list(map(int,input().split())) q = list(map(int,input().split())) c_p = 0 c_q = 0 count = 0 for i in itertools.permutations(sorted(p),len(p)): if p == list(i): c_p = count if q == list(i): c_q = count count += 1 print(abs(c_p - c_q))
0
null
82,220,906,233,700
212
246
num = map(int, raw_input().split()) for i in range(0,2): for j in range(0,2): if num[j] > num[j+1]: tmp_box = num[j] num[j] = num[j+1] num[j+1] = tmp_box sort = map(str, num) print sort[0] + " " + sort[1] + " " + sort[2]
A, B = map(int, input().split()) if A > 9 or B > 9: ans = -1 else: ans = A*B print(ans)
0
null
78,914,512,807,142
40
286
k, n = map(int, input().split()) a = list(map(int, input().split())) a += [k + a[0]] print(k - max([a[i + 1] - a[i] for i in range(n)]))
K, N = map(int,input().split()) L = list(map(int,input().split())) d = [L[i+1]-L[i] for i in range(N-1)] d.append(L[0] - (L[-1]-K)) m = max(d) ans = sum(d) - m print(ans)
1
43,535,887,993,610
null
186
186
N=int(input()) print(int((N+2-1)/2))
n=input() a=(int(n)+1)//2 print(a)
1
58,970,412,047,998
null
206
206
from math import ceil a,b,c,d = map(int,input().split()) if ceil(c/b) <= ceil(a/d): print("Yes") else: print("No")
#!/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()
1
29,772,212,505,430
null
164
164
i = 1 a = input() while a != 0: print "Case %d: %d" % (i, a) i = i + 1 a = input()
x = 0 while True: x += 1 n = input() if int(n) == 0: break print("Case " + str(x) + ": " + n)
1
472,519,537,952
null
42
42
X, N = map(int, input().split()) ps = list(map(int, input().split())) bgr, smr = X, X while bgr <= 100: if bgr not in ps: break bgr += 1 while smr >= 1: if smr not in ps: break smr -= 1 print(bgr) if bgr - X < X - smr else print(smr)
def Euclidean(input_list): # print input_list x = input_list[1] y = input_list[0] r = x % y if r != 0: list = [r, y] list.sort() return Euclidean(list) else: return y list = map(int, raw_input().split(" ")) list.sort() print Euclidean(list)
0
null
6,974,256,763,320
128
11
#!/usr/bin/env python3 import sys def solve(N: int, A: "List[int]"): dp = [[0,0] for _ in range(N+1)] dp[2] = [A[0],A[1]] for i in range(2,N): if (i+1)%2 ==0: dp[i+1][0] = dp[i-1][0]+A[i-1] else: dp[i+1][0] = max(dp[i]) dp[i+1][1] = max(dp[i-1])+A[i] print(max(dp[N])) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == '__main__': main()
import sys sys.setrecursionlimit(500000) N = int(input()) #道を双方向に記録する。 g = [[] for _ in range(N)] for i in range(N-1): #木の辺の数はN-1 #iが辺のID a,b = map(int,input().split()) a -= 1; b -= 1 #ここで引いて頂点を0スタートにしないとオーバーフロー g[a].append((b,i)) g[b].append((a,i)) #これが答え。 ans = [-1 for _ in range(N-1)] #vという頂点からpという親にcolorという色で繋がっている。 def dfs(v, color, p): k = 1 #色の初期値 for i in range(len(g[v])): #vから繋がっている頂点をtoとして探す TO = g[v][i][0] ID = g[v][i][1] if TO == p: #親は一つでそれ以外は子。親の時だけ無視すればよい。 continue if k == color: #親から繋がっている色と被ったらダメ。 k += 1 ans[ID] = k k += 1 #ここで足す1をしないとこのfor loopの中の辺で色が被る。 dfs(TO,ans[ID],v) dfs(0,0,-1) #根を0として、仮想親の-1から仮想色0で繋がっている。 print(max(ans)) for i in ans: print(i)
0
null
87,065,217,179,986
177
272
x,y,xx,yy=map(float, input().split()) print('%5f'%((x-xx)**2+(y-yy)**2)**0.5)
while True: x = input() if int(x) == 0: break print(sum([int(i) for i in x]))
0
null
874,967,002,400
29
62
from collections import defaultdict as dd from collections import deque import bisect import heapq def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): k = ri() a, b = rl() for i in range(k, 1001, k): if a <= i <= b: print ("OK") return print ("NG") mode = 's' if mode == 'T': t = ri() for i in range(t): solve() else: solve()
def main(): N = int(input()) A = {input() for i in range(N)} print(len(A)) if __name__ == '__main__': main()
0
null
28,380,993,579,460
158
165
x = int(input()) a = x // 100 b = x - a * 100 while b > 5: b = b - 5 a -= 1 if a>=1: print(1) else: print(0)
n = int(input()) s = input() ans = 0 for i in range(1000): i = str(i).zfill(3) f = True x = -1 for j in range(3): x = s.find(i[j],x+1) f = f and bool(x >= 0) ans += f print(ans)
0
null
128,039,297,049,440
266
267
import collections import sys import math 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()) def NIJIGEN(H): return [list(input()) for i in range(H)] K=int(input()) if K%2==0 or K%5==0: print(-1) ans=7%K for i in range(K): if ans==0: print(i+1) exit() ans=((ans*10)+7)%K
K = int(input()) s = 7 flg = False cnt = 0 for i in range(K+1): cnt += 1 if s % K == 0: flg = True break s *= 10 s %= K s += 7 if flg: print(cnt) else: print(-1)
1
6,147,922,725,920
null
97
97
(x, y, a, b, c), p, q, r = [map(int, o.split()) for o in open(0)] print(sum(sorted(sorted(p)[-x:] + sorted(q)[-y:] + list(r))[-x-y:]))
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # . ' Udit Gupta @luctivud , # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## ## ####### # # ###### ## ## ## ## ### ## ## ## ## # # # ## ######### ####### # # ## # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import sys import math # sys.setrecursionlimit(10**6) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def printwsp(*args): return print(*args, end="") def printsp(*args): return print(*args, end=" ") def printchk(*args): return print(*args, end="tst, ") MODPRIME = int(1e9+7); BABYMOD = 998244353; # ################################ HELPER PROGRAMS USED ################################### # ################################## MAIN STARTS HERE ##################################### # for _testcases_ in range(int(input())): x, y, a, b, c = get_ints() la = get_array() lb = get_array() lc = get_array() la.sort(reverse = True) lb.sort(reverse = True) for i in range(x): lc.append(la[i]) for i in range(y): lc.append(lb[i]) lc.sort(reverse = True) sum = 0 for i in range(x+y): sum += lc[i] print(sum) # ######################################################################################### ''' THE LOGIC AND APPROACH IS BY ME @luctivud. SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE:: (I Own the code if no link is provided here or I may have missed mentioning it) : DO NOT PLAGIARISE. '''
1
45,025,920,189,296
null
188
188
def main(): s, t = map(str, input().split()) a, b = map(int, input().split()) u = str(input()) if s == u: print(a-1, b) else: print(a, b-1) if __name__ == "__main__": main()
N = int(input()) A = list(map(int, input().split())) LN = max(A) + 1 L = [0 for i in range(LN)] count = 0 for i in A: for j in range(i, LN, i): L[j] += 1 for i in A: if L[i] == 1: count += 1 print(count)
0
null
43,201,846,813,594
220
129
from math import * n=int(input()) a=[] for i in range(n): s=input() a.append(s) s=set(a) print(len(s))
# coding: utf-8 list = [] while True: num = input().rstrip().split(" ") if (int(num[0]) == 0) and (int(num[1]) == 0): break list.append(num) for i in range(len(list)): for j in range(int(list[i][0])): if (j == 0) or (j == (int(list[i][0])-1)): print("#"*int(list[i][1])) else: print("#" + "."*(int((list[i][1]))-2) + "#") print()
0
null
15,483,435,976,928
165
50
N = int(input()) from itertools import permutations P=tuple(map(int, input().split())) Q=tuple(map(int, input().split())) A=list(permutations([i for i in range(1, N+1)])) a=A.index(P) b=A.index(Q) print(abs(a-b))
from itertools import permutations n=int(input()) p=tuple(int(i)for i in input().split()) q=tuple(int(i)for i in input().split()) permutation_n=list(permutations(range(1,n+1))) a=b=0 for i in permutation_n: if i<p:a+=1 if i<q:b+=1 print(abs(a-b))
1
100,266,597,729,180
null
246
246
n,m=[int(x) for x in input().split()] h=[int(x) for x in input().split()] t=[[]for i in range(n)] ans=0 for i in range(m): a,b=[int(x) for x in input().split()] t[a-1].append(b-1) t[b-1].append(a-1) for i in range(n): if t[i]==[]: ans+=1 else: c=[] for j in t[i]: if h[i]<=h[j]: c.append(False) if c==[]: ans+=1 print(ans)
K=int(input()) A,B=map(int,input().split()) for i in range(A,B+1): if i%K==0: print('OK') exit() print('NG')
0
null
25,930,215,099,540
155
158
from decimal import * import math A, B = input().split() a = Decimal(A) b = Decimal(B) ib = Decimal(100*b) print(math.floor((a*ib)/Decimal(100)))
import sys while(1): H, W = map(int, raw_input().split()) if(H == 0 and W == 0): break else: for i in range(H): for j in range(W): if(i%2==0 and j%2==0): sys.stdout.write("#") elif(i%2==0 and j%2==1): sys.stdout.write(".") elif(i%2==1 and j%2==0): sys.stdout.write(".") else: sys.stdout.write("#") print print
0
null
8,787,764,727,238
135
51
import copy a = [int(c) for c in input().split()] K = a[0] N = a[1] A = [int(c) for c in input().split()] B = list(map(lambda x: x+K,copy.deepcopy(A))) A = A+B l = 0 tmp = 0 cnt = 0 for i in range(N): tmp = A[i+1]-A[i] if tmp > l : cnt = i l = tmp print(K-l)
# -*- coding: utf-8 -*- k, n = map(int, input().split()) a = list(map(int, input().split())) fst = a[0] a.append(k+fst) dis= [] for i in range(n): dis.append(a[i+1]-a[i]) print(sum(dis)-max(dis))
1
43,577,883,913,850
null
186
186
N, X, Y = map(int, input().split()) ans = [0] * (N + 1) for i in range(1, N): for j in range(i+1, N+1): dis1 = j-i dis2 = abs(X-i) + 1 + abs(Y - j) dis3 = abs(Y-i) + 1 + abs(X - j) d = min(dis1,dis2,dis3) ans[d] += 1 for i in range(1, N): print(ans[i])
import sys sys.setrecursionlimit(10000000) n,x,y=map(int,input().split()) x-=1 y-=1 res=[0]*n for i in range(n): for j in range(i+1,n): m = min(j-i, abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1) res[m]+=1 for i in range(1,n): print(res[i])
1
44,297,956,937,660
null
187
187
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N,X,Y=MI() X-=1 Y-=1 ans=[0]*N for i in range(N): for j in range(i+1,N): if j<=X: d=j-i elif i>=Y: d=j-i elif i<=X and j>=Y: d=X-i + j-Y +1 elif i<=X and j<=Y: d=min(j-i,X-i +1 +Y-j) elif i>=X and j>=Y: d=min(j-i, i-X +1 +j-Y) else:#どっちも内側 d=min(j-i, i-X +1 +Y-j) ans[d-1]+=1 for i in range(N-1): print(ans[i]) main()
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split())) count = 0 flag = 0 for i in range(N): if N == 1: break minj = i for j in range(i, N): if A[j] < A[minj]: minj = j flag = 1 if flag == 1: A[i], A[minj] = A[minj], A[i] count += 1 flag = 0 for i in range(N): if i == N - 1: print("{0}".format(A[i])) else: print("{0} ".format(A[i]), end="") print(count)
0
null
21,911,032,033,352
187
15
import math A, B, H, M = map(int, input().split()) SP_HOUR = 360 / (12 * 60) SP_MIN = 360 / 60 angle = (H * 60 + M) * SP_HOUR - M * SP_MIN if angle < 0: angle += 360 # print(math.cos(0)) # print(math.cos(3.14)) # print("angle", angle) # print("angle in radian", math.radians(angle)) #Law of cosines ans_squ = A * A + B * B - 2 * A * B * math.cos(math.radians(angle)) print(math.sqrt(ans_squ))
li =[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] a=int(input()) a-=1 print(li[a])
0
null
34,875,465,333,480
144
195
S = input() ans = S.replace("hi", "") if ans == "": print("Yes") else: print("No")
s=input() if len(s)%2==0: for i in range(len(s)//2): if s[2*i:2*i+2]=="hi": continue print("No") break else: print("Yes") else: print("No")
1
53,368,137,971,770
null
199
199
line1 = input() line2 = input() aryLine1 = line1.split() arystrLine2 = line2.split() K = int(aryLine1[0]); N = int(aryLine1[1]); aryLine2 = [int(s) for s in arystrLine2] #print(aryLine2) aryLine2.sort() #print(aryLine2) ans = K for i in range(0, N): temp1 = int(aryLine2[i]) if i == N - 1: temp2 = int(aryLine2[0]) + K else: temp2 = int(aryLine2[i + 1]) temp = temp1 - temp2 + K if temp < ans: ans = temp print(ans)
N = int(input()) S = input() ans = 0 for i in range(10): for j in range(10): for k in range(10): nums = [str(x) for x in [i, j, k]] for s in S: if s == nums[0]: nums = nums[1:] if len(nums) == 0: ans += 1 break print(ans)
0
null
86,052,473,592,668
186
267
N = int(input()) A = list(map(int, input().split())) nSwap = 0 for i in range(N): for j in range(N-1, i, -1): if A[j] < A[j-1]: A[j-1], A[j] = A[j], A[j-1] nSwap += 1 print(' '.join(map(str, A))) print(nSwap)
import collections from math import factorial def permutations_count(n, r): ''' 順列 ''' return factorial(n) // factorial(n - r) def combinations_count(n, r): ''' 組み合わせ ''' return factorial(n) // (factorial(n - r) * factorial(r)) S = input() lis = [] amari = 1 lis.append(int(S[-1])) for i in range(2,len(S)+1): amari = (amari * 10) % 2019 lis.append((int(S[-1*i]) * amari + lis[i-2]) % 2019) c = collections.Counter(lis) su = 0 for k in c: if c[k] > 1: su += combinations_count(c[k], 2) su += c[0] print(su)
0
null
15,548,609,984,072
14
166
bank = 100 x = int(input()) i = 1 while 1: bank += bank // 100 if bank >= x: break i += 1 print(i)
X = int(input()) money = 100 ans = 0 while money < X: tax = money // 100 money += tax ans += 1 print(ans)
1
27,011,867,252,978
null
159
159
from sys import stdin input = stdin.readline from collections import Counter def solve(): n = int(input()) verdict = [ inp for inp in stdin.read().splitlines()] c = Counter(verdict) print(f'AC x {c["AC"]}') print(f'WA x {c["WA"]}') print(f'TLE x {c["TLE"]}') print(f'RE x {c["RE"]}') if __name__ == '__main__': solve()
N = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for _ in range(N): a = input() if a == "AC": ac += 1 if a == "WA": wa += 1 if a == "TLE": tle += 1 if a =="RE": re += 1 print(f"AC x {ac}") print(f"WA x {wa}") print(f"TLE x {tle}") print(f"RE x {re}")
1
8,683,837,431,492
null
109
109
import sys input = sys.stdin.readline n = int(input()) plus = [] minus = [] for _ in range(n): min_s = 0 ts = 0 s = input().strip() for c in s: ts += 1 if c == '(' else -1 min_s = min(ts, min_s) if ts >= 0: plus.append((-min_s, ts)) else: minus.append((-(min_s - ts), -ts)) plus.sort() minus.sort() s1 = 0 for m, t in plus: if s1 - m < 0: print('No') exit() s1 += t s2 = 0 for m, t in minus: if s2 - m < 0: print('No') exit() s2 += t if s1 == s2: print('Yes') else: print('No')
A,B = map(int,input().split()) print(A*B,2*(A+B))
0
null
11,941,897,506,380
152
36
import math R=int(input()) cir=2*math.pi*R print(cir)
a=int(input()) print(2*3.1416*a)
1
31,365,011,186,850
null
167
167
import sys for line in sys.stdin: l = map(int, line.split()) print len(str(l[0]+l[1]))
# -*- coding: utf-8 -*- """ Created on Sat Sep 26 21:02:43 2020 @author: liang """ K = int(input()) ans = "" for i in range(K): ans += "ACL" print(ans)
0
null
1,092,488,834,620
3
69
# # author sidratul Muntaher # date: Aug 19 2020 # n = int(input()) from math import pi print(pi* (n*2))
H = int(input()) W = int(input()) N = int(input()) print(-(-N//max(H,W)))
0
null
60,316,167,203,852
167
236
import math def dist(a,b,n): s=0 m=0 for i in range(len(a)): d=math.fabs(b[i]-a[i]) m=max(m,d) s+=d**n return (s**(1/n),m) n=int(input()) a=list(map(float,input().split())) b=list(map(float,input().split())) print('%.6f'%(dist(a,b,1)[0])) print('%.6f'%(dist(a,b,2)[0])) print('%.6f'%(dist(a,b,3)[0])) print('%.6f'%(dist(a,b,1)[1]))
n=eval(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) def minkowski(p,x_1,x_2,n): if p==0: return float(max([abs(x_1[i]-x_2[i]) for i in range(n)])) else: return sum([(abs(x_1[i]-x_2[i]))**p for i in range(n)])**(1/p) for i in range(4): print(minkowski((i+1)%4,x,y,n))
1
216,803,601,472
null
32
32
# coding: utf-8 n = int(input()) R = [ int(input()) for i in range(n)] MIN = R[0] MAXdiff = R[1]-R[0] for i in range(1,n): MAXdiff = max(MAXdiff,R[i]-MIN) MIN = min(MIN,R[i]) print(MAXdiff)
n = int(input()) ans = float("-INF") min_v = int(input()) for _ in range(n-1): r = int(input()) ans = max(ans, r - min_v) min_v = min(min_v, r) print(ans)
1
13,831,629,690
null
13
13
def Warshall_Floyd(dist,n,restoration=False): next_point = [[j for j in range(n)] for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): if dist[j][k] > dist[j][i] + dist[i][k]: next_point[j][k] = next_point[j][i] dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]) if restoration: return dist,next_point else: return dist n,m,l = map(int,input().split()) inf = 10**18 dist = [[inf for i in range(n)] for j in range(n)] for i in range(n): dist[i][i] = 0 for i in range(m): a,b,c = map(int,input().split()) a -= 1 b -= 1 if c <= l: dist[a][b] = c dist[b][a] = c dist = Warshall_Floyd(dist,n) route = [[inf for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): if i == j: route[i][j] = 0 elif dist[i][j] <= l: route[i][j] = 1 route = Warshall_Floyd(route,n) q = int(input()) for i in range(q): s,t = map(int,input().split()) s -= 1 t -= 1 print(route[s][t]-1 if route[s][t] < inf else -1)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): from collections import defaultdict n, m, l = map(int, readline().split()) dist = [[INF] * n for _ in range(n)] for _ in range(m): a, b, c = map(int, readline().split()) a, b = a - 1, b - 1 dist[a][b] = c dist[b][a] = c for k in range(n): for i in range(n): for j in range(n): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) dist2 = [[INF] * n for _ in range(n)] for i in range(n): for j in range(n): if dist[i][j] <= l: dist2[i][j] = 1 for k in range(n): for i in range(n): for j in range(n): dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) q = int(readline()) for _ in range(q): s, t = map(int, readline().split()) s, t = s - 1, t - 1 if dist2[s][t] == INF: print(-1) else: print(dist2[s][t] - 1) if __name__ == '__main__': main()
1
174,294,994,702,818
null
295
295
import math n=int(input()) x=100000 for i in range(n): x=x*1.05 # print('5%',x) x=x/1000 #print('/1000',x) x=math.ceil(x) #print('cut',x) x=x*1000 #print('*1000',x) print(x)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): week = int(input()) base = 100000 x = base for i in range(week): x = round(x * 1.05) if x % 1000 > 0: x = (x // 1000) *1000 +1000 print(x) if __name__ == '__main__': main()
1
955,211,820
null
6
6
nums = input().split() a = int(nums[0]) b = int(nums[1].replace('.', '')) result = str(a * b) if len(result) < 3: print(0) else: print(result[:-2])
import sys def insertionSort(A, N): for n in range(N-1): print (A[n], end=" ") print(A[N-1]) 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 = j - 1 A[j + 1] = v for n in range(N-1): print (A[n], end=" ") print(A[N-1]) return A N = int(input()) A = input() A = A.split(" ") for i in range(N): A[i] = int(A[i]) val = insertionSort(A, N)
0
null
8,207,886,762,976
135
10
import itertools import math N = int(input()) L = [list(map(int,input().split())) for n in range(N)] I = list(itertools.permutations(L)) sum = 0 for i in I: for n in range(N-1): sum += math.sqrt((i[n+1][0]-i[n][0])**2+(i[n+1][1]-i[n][1])**2) print(sum/len(I))
a,b,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) x=[list(map(int,input().split())) for _ in range(m)] ans=min(a)+min(b) for i in range(m): ans=min(ans,(a[x[i][0]-1]+b[x[i][1]-1]-x[i][2])) print(ans)
0
null
101,022,495,781,492
280
200
n = input().split() a = int(n[0]) b = int(n[1]) c = int(n[2]) if a > b: bf = a a = b b = bf if b > c: bf = b b = c c = bf if a > b: bf = a a = b b = bf print(str(a) + " " + str(b) + " " + str(c))
n = int(input()) ans = [0]*n for i in range(1,101): for j in range(1,101): for k in range(1,101): l = i**2 + j**2 + k**2 + i*j + j*k + k*i if l <= n: ans[l-1] += 1 for m in range(n): print(ans[m])
0
null
4,243,308,214,880
40
106
n=int(input()) if n>=400 and n<=599: print("8") elif n>=600 and n<=799: print("7") elif n>=800 and n<=999: print("6") elif n>=1000 and n<=1199: print("5") elif n>=1200 and n<=1399: print("4") elif n>=1400 and n<=1599: print("3") elif n>=1600 and n<=1799: print("2") elif n>=1800 and n<=1999: print("1")
def main(): N, K = map(int, input().split()) R, S, P = map(int, input().split()) d = {'r': R, 's': S, 'p': P} T = input() scores = [] for t in T: if t == 'r': scores.append('p') elif t == 's': scores.append('r') else: scores.append('s') for i in range(N-K): if scores[i] == scores[i+K]: scores[i+K] = 0 print(sum([d[v] for v in scores if v in ['p', 'r', 's']])) if __name__ == '__main__': main()
0
null
56,876,660,344,922
100
251
n,a,b = map(int,input().split()) m = 10**9 + 7 comb_a = 1 comb_b = 1 a_num = list(range(1,a+1)) j = 0 for i in range(1,a+1): comb_a *= (n-i+1) comb_a *= pow(a_num[i-1],m-2,m) comb_a = comb_a % m b_num = list(range(1,b+1)) j = 0 for i in range(1,b+1): comb_b *= (n-i+1) comb_b *= pow(b_num[i-1],m-2,m) comb_b = comb_b % m ans = pow(2,n,m) - comb_a - comb_b - 1 print(int(ans) % m)
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) s = ins() if s == "AAA" or s == "BBB": print("No") else: print("Yes")
0
null
60,675,226,015,690
214
201
n, m = [int(x) for x in input().split()] a = [[int(x) for x in input().split()] for y in range(n)] b = [int(input()) for x in range(m)] c = [0 for i in range(n)] for i in range(n): c[i] = sum([a[i][x] * b[x] for x in range(m)]) for i in c: print(i)
M1, D1=input().split() M2, D2=input().split() M1=int(M1) M2=int(M2) if M1==M2: print(0) else: print(1)
0
null
62,803,535,155,140
56
264
H = int(input()) W = int(input()) N = int(input()) HW =H*W ans =H+W for h in range(0,H+1): for w in range(0,W+1): cntB = HW - (H-h)*(W-w) if cntB>=N: ans = min(ans, h+w) print(ans)
a,b,c=map(int,input().split()) if a+b+c>21:print('bust') else:print('win')
0
null
104,022,926,757,900
236
260
# -*- coding: utf-8 -*- 'import sys' input() a=[int(i) for i in input().split()] a.reverse() f=0 for i in range(len(a)): if f: print(" ",end="") print("{}".format(a[i]),end="") f=1 print("")
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors n = int(input()) ans = len(make_divisors(n - 1)) - 1 for x in make_divisors(n): if x == 1: continue m = n while m % x == 0: m //= x if m % x == 1: ans += 1 print(ans)
0
null
21,215,883,362,670
53
183
#!/usr/bin/env python3 s = input() l = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'] if s == 'SUN': print(7) else: print(6 - l.index(s))
a = input() arr = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] p = arr.index(a) print(7-p)
1
133,728,185,479,648
null
270
270
N = int(input()) AB = [list(map(int, input().split())) for _ in range(N)] A = [a for a, b in AB] B = [b for a, b in AB] A.sort() B.sort() if N % 2: ma = B[N // 2] mi = A[N // 2] else: ma = B[N // 2 - 1] + B[N // 2] mi = A[N // 2 - 1] + A[N // 2] print(ma - mi + 1)
def main(): n = int(input()) A = [0]*n B = [0]*n for i in range(n): a,b = map(int,input().split()) A[i] = a B[i] = b A.sort() B.sort() if n%2 == 0: m1 = (A[n//2-1]+A[n//2])/2 m2 = (B[n//2-1]+B[n//2])/2 print(int(2*(m2-m1))+1) else: print(B[(n+1)//2-1]-A[(n+1)//2-1]+1) main()
1
17,235,471,162,348
null
137
137
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import time,random sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 mod2 = 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def JA(a, sep): return sep.join(map(str, a)) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def main(): n = I() aa = LI() if n == 0: if aa[0] == 1: return 1 return -1 if aa[0] != 0: return -1 b = [1] c = 1 for a in aa[1:-1]: if a > c * 2: return -1 c = c * 2 - a b.append(c) if c * 2 < aa[-1]: return -1 r = c = aa[-1] for a,b in list(zip(aa[:-1],b))[::-1]: t = (c+1) // 2 if t > b: return -1 c = a + min(b, c) r += c if c != 1: return -1 return r print(main())
import numpy as np import math import collections N = int(input()) A = list(map(int, input().split())) ans = 0 node_num = 1 pre_node_num = 1 B = [1 - A[0]] ruisekiA = [0 for i in range(N + 2)] ruisekiA[N] = A[N] ruisekiA[N + 1] = 0 for i in range(N - 1, -1, -1): ruisekiA[i] = ruisekiA[i + 1] + A[i] for i in range(1, N + 1): tmpB = min(2 * B[i - 1] - A[i], ruisekiA[i + 1]) #print(tmpB, B[i - 1] - A[i]) if (tmpB < 0) or (tmpB < B[i - 1] - A[i]): ans = -1 break if i == N: tmpB = 0 B.append(tmpB) if N == 0 and A[0] != 1: ans = -1 if ans != -1: ans = sum(A) + sum(B) print(ans)
1
18,829,687,241,442
null
141
141
# https://atcoder.jp/contests/abc163/tasks/abc163_d def main(): MOD = 10**9 + 7 n, k = [int(i) for i in input().strip().split()] table = [0] * (n + 2) table[1] = 1 for i in range(2, n + 1): table[i] = table[i - 1] + i ans = 0 for i in range(k, n + 1): _min = table[i - 1] _max = table[n] - table[n - i] ans += _max - _min + 1 ans %= MOD print((ans + 1) % MOD) if __name__ == "__main__": main()
import sys from collections import deque input = sys.stdin.readline def bfs(S, sh, sw, dist): dist[sh][sw] = 0 queue = deque([(sh, sw)]) while queue: h, w = queue.popleft() for i, j in ((0, 1), (0, -1), (1, 0), (-1, 0)): y, x = h + i, w + j if S[y][x] == "#": continue if dist[y][x] == -1: dist[y][x] = dist[h][w] + 1 queue.append((y, x)) def main(): H, W = map(int, input().split()) S = [None] * (H + 2) S[0] = S[-1] = "#" * (W + 2) for i in range(1, H + 1): S[i] = "".join(["#", input().rstrip(), "#"]) ans = 0 for sh in range(1, H + 1): for sw in range(1, W + 1): if S[sh][sw] == "#": continue dist = [[-1] * (W + 2) for _ in range(H + 2)] bfs(S, sh, sw, dist) max_dist = max(map(max, dist)) ans = max(ans, max_dist) print(ans) if __name__ == "__main__": main()
0
null
63,852,165,287,560
170
241
A,B,N=map(int,input().split()) if N<B: x=N elif N==B: x=N-1 else: x=(N//B)*B-1 ans=(A*x/B)//1-A*(x//B) print(int(ans))
a=int(input()) b=int(input()) v=[1,2,3] for i in v: if a!=i and b!=i: print(i) break
0
null
69,585,719,518,468
161
254
s = input() t = s[::-1] n = len(s) resid = [0] * 2019 resid[0] = 1 csum = 0 powoften = 1 for i in range(n): csum = (csum + int(t[i]) * powoften) % 2019 powoften = (10 * powoften) % 2019 resid[csum] += 1 ans = 0 for i in range(2019): ans += resid[i] * (resid[i] - 1) // 2 print(ans)
from collections import Counter S = list(input()) S.reverse() MOD = 2019 t = [0] r = 1 for i in range(len(S)): q = (t[-1] + (int(S[i]) * r)) % MOD t.append(q) r *= 10 r %= MOD cnt = Counter(t) cnt_mc = cnt.most_common() ans = 0 for _, j in cnt_mc: if j >= 2: ans += j * (j - 1) // 2 print(ans)
1
30,950,962,763,840
null
166
166
n = int(input()) a = 0 for i in range(10): for j in range(10): if i*j == n: a +=1 if a == 0: print("No") else: print("Yes")
N=int(input()) for num in range(1,10): if (N/num).is_integer() and 1<=(N/num)<=9: print("Yes") break else: print("No")
1
159,447,062,754,460
null
287
287
X=int(input()) while True: flg = True for i in range(2,int(X**1/2)+1): if X%i == 0: flg = False break if flg == True: print(X) break else: X += 1
X = int(input()) if X <= 2: print(2) exit() S = [2] for i in range(3, 10**6, 2): f = True for s in S: if s > i**(0.5): break if i % s == 0: f = False break if f: S.append(i) if i >= X: print(i) break
1
105,296,113,390,310
null
250
250
N=int(input()) u="ACL" print(u*N)
result = [] while True: (m, f, r) = [int(i) for i in input().split()] sum = m + f if m == f == r == -1: break if m == -1 or f == -1: result.append('F') elif sum >= 80: result.append('A') elif sum >= 65: result.append('B') elif sum >= 50: result.append('C') elif sum >= 30: if r >= 50: result.append('C') else: result.append('D') else: result.append('F') [print(result[i]) for i in range(len(result))]
0
null
1,738,717,152,030
69
57
list = [] x = 1 while x > 0: x = input() if x > 0: list.append(x) for i,j in enumerate(list): print "Case " + str(i+1) + ": " + str(j)
flag = "go" cnt = 0 while flag == "go": cnt += 1 x = int(input()) if x == 0: flag = "stop" else: print("Case " + str(cnt) + ": " + str(x))
1
494,539,368,830
null
42
42
n=int(input()) for i in range(1,361): if (n*i)%360==0: print(i);exit()
tmp = input() array = tmp.split(' ') a = int(array[0]) b = int(array[1]) print(str(a*b) + " " + str((a*2)+(b*2)))
0
null
6,657,657,199,310
125
36
x = int(input()) ans = x // 500 * 1000 x = x % 500 ans += x // 5 * 5 print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = 10**6#float('inf') #mod = 10 ** 9 + 7 mod = 998244353 #from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N, M = MAP() a = LIST() A = sorted([x//2 for x in a], reverse=True) b = A[0] cnt = 0 while b%2 == 0: b //= 2 cnt += 1 for x in A: if x%pow(2, cnt) or (x//pow(2, cnt))%2 == 0: print(0) exit() lcm = A[-1] for x in A: lcm = lcm*x//gcd(lcm, x) r = lcm//A[0] n = M//A[0] #2p+1が1<=2p+1<=n の範囲で rの倍数となるpの個数 if r%2 == 0: print(0) else: print(n//r - n//(2*r))
0
null
71,956,233,050,440
185
247
X = int(input()) if (X < 30): print('No') else: print('Yes')
x = int(input()) if x >= 30: ans = 'Yes' else: ans = 'No' print(ans)
1
5,686,149,600,002
null
95
95
N = int(input()) X = list(map(int, input().split())) ans = 1000000000 for i in range(1, max(X)+1): l = 0 for j in range(N): l += (i - X[j]) ** 2 ans = min(ans, l) print(ans)
x, y = map(int, input().split()) prise_dict = {3: 100000, 2: 200000, 1: 300000} ans = 0 if x in prise_dict.keys(): ans += prise_dict[x] if y in prise_dict.keys(): ans += prise_dict[y] if x == y == 1: ans += 400000 print(ans)
0
null
102,615,496,887,958
213
275
S = input() T = input() ans = 1001 for i in range(len(S)-len(T)+1): ans = min(ans, sum(S[i+j] != T[j] for j in range(len(T)))) print(ans)
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) from collections import defaultdict from collections import deque import bisect from decimal import * def main(): a, b, c, d = MI() print(max(a * c, b * d, a * d, b * c)) if __name__ == "__main__": main()
0
null
3,357,153,700,208
82
77
print ((int(raw_input()))**3)
import numpy as np R=int(input()) circle=float(R*2*np.pi) print(circle)
0
null
15,813,696,293,450
35
167
def expect(n): return (n+1)/2 nk = input().split() N = int(nk[0]) K = int(nk[1]) p = input().split() tmp = 0 for i in range (K): tmp += expect(int(p[i])) tmpMax = tmp for i in range(N - K): tmp -= expect(int(p[i])) tmp += expect(int(p[i+K])) tmpMax = max(tmpMax, tmp) print(tmpMax)
n = int(input()) s = [list(input()) for i in range(n)] r = [] l = [] ans = 0 for i in s: now = 0 c = 0 for j in i: if j =="(": now += 1 else: now -= 1 c = min(c,now) if c == 0: ans += now elif now >= 0: l.append([c,now]) else: r.append([c-now,now]) l.sort(reverse =True) r.sort() for i,j in l: if ans + i < 0: print("No") exit() else: ans += j for i,j in r: if ans +i+j < 0: print("No") exit() else: ans += j if ans == 0: print("Yes") else: print("No")
0
null
49,478,113,532,640
223
152
import math n = int(input()) folia = list(map(int, input().split())) #print(n, folia) #_1 木の一番下から順に各深さの頂点数[min, max]を取得 seq = [[folia[-1], folia[-1]]] for i in range(n): # 深さ'n'分 tmp = folia[-(i+2)] sml = math.ceil(seq[i][0] / 2) + tmp big = seq[i][1] + tmp seq += [[sml, big]] #print(seq) #_2 一番根本の頂点数[min, max]に'1'を含まない場合は '存在しない木' if not (seq[-1][0] <= 1 <= seq[-1][1]): print(-1) exit() #_3 木の一番上から順に各深さで理論最大頂点数と'#_1のmax'との'min'をとる ans =[1] for j in range(n): # 深さ'n'分 tmp = min((ans[j] - folia[j]) * 2, seq[-(j+2)][1]) ans.append(tmp) print(sum(ans)) # その合計が'ans'
k=int(input()) l=['ACL']*k print(*l,sep='')
0
null
10,624,858,250,370
141
69
N = int(input()) def answer(N: int) -> str: x = 0 for i in range(1, 10): for j in range(1, 10): if N == i * j: x = 1 return 'Yes' if x == 0: return 'No' print(answer(N))
N=int(input()) resurt='' for i in range(1,10): if N%i ==0 and N//i<=9: result='Yes' break else: result='No' print(result)
1
159,541,837,273,280
null
287
287
def main(): n = int(input()) S = list(map(int, input().split())) q = int(input()) T = list(map(int, input().split())) res = 0 for i in T: if i in S: res += 1 print(res) if __name__ == '__main__': main()
n = int(input()) s = list(map(int,input().split())) q = int(input()) r = list(map(int,input().split())) cou = 0 for i in range(q): for j in range(n): if(s[j] == r[i]): cou += 1 break print(cou)
1
67,554,556,410
null
22
22
result = [] def combination(n, x): count = 0 for i in range(1, n + 1): for j in range(1,i): for k in range(1, j): if i + j + k == x: count += 1 result.append(count) while True: (n, x) = [int(i) for i in input().split()] if n == x == 0: break combination(n, x) [print(result[x]) for x in range(len(result))]
# -*- coding: utf-8 -*- while True: n, x = map(int, raw_input().split()) if n == x == 0: break count = 0 for a in range(1, n+1): for b in range(a+1, n+1): for c in range(b+1, n+1): if a+b+c == x: count += 1 break print count
1
1,292,281,797,170
null
58
58
n = int(input()) a = list(map(int, input().split())) MOD = 1000000007 dic = {} dic[0] = 3 for i in range(1,n+1): dic[i] = 0 ans = 1 for i in range(n): ans = ans * dic[a[i]] % MOD dic[a[i]] -= 1 dic[a[i] + 1] += 1 print(ans)
N = int(input()) A = list(map(int, input().split())) mod = 10**9+7 color = [0]*3 ans = 1 for i in range(N): if A[i] not in color: ans = 0 break ind = color.index(A[i]) ans *= len([c for c in color if c == A[i]]) ans %= mod color[ind] += 1 #ans = rec(color,0) print(ans)
1
130,080,401,591,660
null
268
268
H,W,M=map(int,input().split()) HSum=[0 for _ in range(H)] WSum=[0 for _ in range(W)] bombs = set() for _ in range(M): hi,wi = map(lambda x:int(x)-1,input().split()) HSum[hi] += 1 WSum[wi] += 1 bombs.add( (hi,wi) ) # print(HSum) # print(WSum) curMax = 0 ## 計算量多すぎ。。 # for h in range(H): # for w in range(W): # tmp = HSum[h] + WSum[w] # if curMax <= tmp: # if (h,w) in bombs: # tmp -= 1 # curMax = max( curMax, tmp ) hMax = max(HSum) wMax = max(WSum) tmpMax = hMax + wMax ans = 0 hSumMaxOnly = [h for h, x in enumerate(HSum) if x == hMax] wSumMaxOnly = [w for w, y in enumerate(WSum) if y == wMax] for h in hSumMaxOnly: if ans == tmpMax: break for w in wSumMaxOnly: if (h,w) in bombs: ans = tmpMax - 1 else: ans = tmpMax break print(ans)
MOD = 10 ** 9 + 7 N = int(input()) Sall = pow(10, N, MOD) S0 = S9 = pow(9, N, MOD) S09 = pow(8, N, MOD) ans = (Sall - (S0 + S9 - S09)) % MOD print(ans)
0
null
3,876,874,125,216
89
78
from collections import deque LIM=200004 L=[0]*LIM def bin_sum(Y): S=bin(Y)[2:] count=0 for i in range(len(S)): count+=int(S[i]) return count def bin_sum2(Y): count=0 for i in range(len(Y)): count+=int(Y[i]) return count for i in range(1,LIM): L[i]+=bin_sum(i) def pop_num(N,b,L): if N==0: return 0 v=N%b return pop_num(v,L[v],L)+1 M=[0]*200005 for i in range(1,200004): M[i]+=pop_num(i,L[i],L) X=int(input()) Y=input() d=bin_sum2(Y) e=int(Y,2)%(d+1) f=int(Y,2)%max(1,(d-1)) O=[1]*(X+2) P=[1]*(X+2) q=max(d-1,1) for i in range(1,X+1): O[i]=O[i-1]*2%q P[i]=P[i-1]*2%(d+1) for i in range(X): if int(Y[i])==1: b=max(d-1,1) flag=max(0,d-1) g=(f-O[X-1-i]+b)%b else: b=d+1 flag=1 g=(e+P[X-1-i])%b if flag==0: print(0) elif g==0: print(1) else: print(M[g]+1)
def popcount(x): xb = bin(x) return xb.count("1") def solve(x, count_1): temp = x %count_1 if(temp == 0): return 1 else: return 1 + solve(temp, popcount(temp)) n = int(input()) x = input() x_b = int(x, 2) mod = x.count("1") xm1 = x_b %(mod+1) if(mod != 1): xm2 = x_b %(mod-1) for i in range(n): if(x[i] == "0"): mi = (((pow(2, n-1-i, mod+1) + xm1) % (mod+1))) if(mi == 0): print(1) else: print(1 + solve(mi, popcount(mi))) else: if(mod == 1): print(0) else: mi = ((xm2-pow(2, n-1-i, mod-1)) % (mod-1)) if((x_b - xm2 == 0)): print(0) elif(mi == 0): print(1) else: print(1 + solve(mi, popcount(mi)))
1
8,271,369,539,352
null
107
107
import numpy as np n = int(input()) s = np.array(input().split(), np.int64) mod = 10 ** 9 + 7 res = 0 po2 = 1 for i in range(61): bit = (s >> i) & 1 x = np.count_nonzero(bit) y = n - x res += x * y % mod * po2 res %= mod po2 *= 2 % mod print(res)
import sys X, Y = map(int, input().split()) mod = int(1e9) + 7 N = 10**6 g1 = [1, 1] g2 = [1, 1] inverse = [0, 1] # 組み合わせ(1e9+7で割る場合) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) # 方針:Xについてすべての動かし方を列挙する。Yに符合すれば組み合わせ計算、それ以外であれば没 kake = 0 ans = 0 while X >= 0: temp = X if temp*2 + kake*1 == Y: ans += cmb(temp + kake, kake, mod) kake += 1 X -= 2 print(ans)
0
null
135,883,894,170,508
263
281
n,k = map(int,input().split()) l = list(map(int,input().split())) l.sort() x,y=0,10**9 while y>x+1: m = (x+y)//2 c=0 for i in l: c+=(i-1)//m if c<=k: y=m else: x=m print(y)
s=input() for _ in range(int(input())): a=input().split() if a[0][0]=='p':print(s[int(a[1]):int(a[2])+1]) else: t=a[3]if'p'==a[0][2]else s[int(a[1]):int(a[2])+1][::-1] s=s[0:int(a[1])]+t+s[int(a[2])+1:]
0
null
4,334,222,453,540
99
68
N=int(input()) S=input() l=[] for i in range(N-1): if S[i]!=S[i+1]: l.append(S[i]) l.append(S[N-1]) print(len(l))
N, M = map(int, input().split(' ')) result = 0 if N > 1: result += N * (N - 1) / 2 if M > 1: result += M * (M - 1) / 2 print(int(result))
0
null
107,699,340,724,768
293
189
N, M = map(int, input().split()) A = list(set(map(int, input().split(" ")))) G = A.copy() while not any(x % 2 for x in G): G = [i // 2 for i in G] if not all(x % 2 for x in G): print(0) exit(0) def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) total = 1 for x in A: total = lcm(total, x // 2) print((M // total + 1) // 2)
# coding: utf-8 a, b = map(str,input().split()) a = int(a) b = int(b.replace(".", "")) print(a*b//100)
0
null
59,351,686,888,660
247
135
N, M = map(int, input().split()) A = list(map(int, input().split())) A1 = sum(A) if N - A1 >= 0: print(N - A1) else: print("-1")
N, M = map(int, input().split()) A = map(int, input().split()) A_sum = sum(A) if (N - A_sum) >= 0: print(N - A_sum) else: print(-1)
1
31,764,726,592,180
null
168
168
if sum(list(map(int,input().split())))>21: print("bust") else: print("win")
a,b,c= (int(x) for x in input().split()) A = int(a) B = int(b) C = int(c) if A+B+C >= 22: print("bust") else: print("win")
1
118,451,192,268,710
null
260
260
(h,n),*t=[[*map(int,t.split())]for t in open(0)] d=[0]*9**8 for i in range(h):d[i+1]=min(b+d[i-a+1]for a,b in t) print(d[h])
def chmin(dp, i, *x): dp[i] = min(dp[i], *x) INF = float("inf") # dp[i] := min 消耗する魔力 to H -= i h, n = map(int, input().split()) dp = [0] + [INF]*h for _ in [None]*n: a, b = map(int, input().split()) for j in range(h + 1): chmin(dp, min(j + a, h), dp[j] + b) print(dp[h])
1
81,035,956,075,840
null
229
229
k, a, b = map(int, open(0).read().split()) print("OK" if b // k * k >= a else "NG")
from bisect import bisect_right N, M = map(int, input().split()) S = [N - i for i, s in enumerate(input()) if s == '0'] S = S[::-1] ans = [] now = 0 while now < N: i = bisect_right(S, now + M) - 1 if S[i] == now: print('-1') exit() ans.append(S[i] - now) now = S[i] print(*ans[::-1])
0
null
82,478,821,548,800
158
274
import sys import itertools input = sys.stdin.readline def SI(): return str(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): H, W, K = MI() grid = [SI().rstrip('\n') for _ in range(H)] n = H + W ans = 0 for i in itertools.product(range(2),repeat = H): for j in itertools.product(range(2),repeat = W): count = 0 for k in range(H): if i[k] == 1: continue for l in range(W): if j[l] == 1: continue if grid[k][l] == "#": count += 1 if count == K: ans +=1 print(ans) main()
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値) from heapq import heapify, heappop, heappush from math import * sys.setrecursionlimit(10**6) INF = 10**20 MOD = 10**9+7 def mint(): return map(int,input().split()) def lint(): return list(map(int,input().split())) def judge(x, l=['Yes', 'No']): print(l[0] if x else l[1]) def lprint(l, sep='\n'): for x in l: print(x, end=sep) N,A = int(input()),lint() S = dict() for a in A: S.setdefault(a,0) S[a] += 1 ans = 0 for k in S: ans += S[k]*(S[k]-1)//2 for a in A: print(ans-(S[a]-1))
0
null
28,279,034,759,470
110
192
#coding:utf-8 import math def isPrime(n): if n == 2: return True elif n % 2 == 0: return False else: for i in range(3,math.ceil(math.sqrt(n))+1,2): if n % i == 0: return False return True n = int(input()) c = 0 for i in range(n): if isPrime(int(input())): c += 1 print(c)
N1=int(input()) array1=input().split() N2=int(input()) array2=input().split() c=0 for n2 in range(N2): if array2[n2] in array1: c+=1 print(c)
0
null
36,544,275,822
12
22
H,W=map(int,input().split()) import math A=[0,math.ceil(W/2)] if (H-1)*(W-1)!=0: c=W*math.floor(H/2)+A[H%2] else: c=1 print(c)
#ABC 174 C k = int(input()) sevens = [0] * k sevens[0] = 7 % k if k == 7 or k == 1: print(1) else: for i in range(1, k): new = (sevens[i - 1] * 10 + 7) % k sevens[i] = new if new == 0: print(i + 1) break else: print(-1)
0
null
28,489,028,660,960
196
97
N,M = map(int,input().split()) A = [0]*M B = [0]*M for i in range(M): A[i],B[i] = map(int,input().split()) from collections import deque links = [[] for _ in range(N+1)] for i in range(M): links[A[i]].append(B[i]) links[B[i]].append(A[i]) result = [-1]*(N+1) q = deque([1]) while q: i = q.popleft() for j in links[i]: if result[j] == -1: result[j] = i q.append(j) print('Yes') print('\n'.join(str(i) for i in result[2:]))
n,m=map(int,input().split()) graph=[[] for _ in range(n)] for _ in range(m): a,b=map(int,input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) sign=[-1]*n sign[0]=0 work=[] work_next=graph[0] for x in work_next: sign[x]=0 while work_next: work=work_next[:] work_next=[] for x in work: for y in graph[x]: if sign[y]>=0 : continue if y in work_next : continue sign[y]=x work_next.append(y) if -1 in sign : print("No");exit() print("Yes") for i in range(1,n): print(sign[i]+1)
1
20,709,063,645,664
null
145
145
h,w,k=map(int,input().split()) board=[list(input()) for _ in range(h)] acum=[[0]*w for _ in range(h)] def count(x1,y1,x2,y2): #事前に求めた2次元累積和を用いて左上の点が(x1,y1)、右下の点(x2,y2)の長方形に含まれる1の個数を数える ret=acum[y2][x2] if x1!=0: ret-=acum[y2][x1-1] if y1!=0: ret-=acum[y1-1][x2] if x1!=0 and y1!=0: ret+=acum[y1-1][x1-1] return ret for i in range(h): #2次元累積和により左上の点が(0,0)、右下の点が(j,i)の長方形に含まれる1の個数を数える for j in range(w): if board[i][j] == '1': acum[i][j]+=1 if i!=0: acum[i][j]+=acum[i-1][j] if j!=0: acum[i][j]+=acum[i][j-1] if i!=0 and j!=0: acum[i][j]-=acum[i-1][j-1] ans = 10**18 for i in range(2**(h-1)): cnt = 0 list = [] flag = format(i,'b')[::-1] # '1'と'10'と'100'の区別のために必要 #print(flag) for j in range(len(flag)): if flag[j] == '1': # ''をつける! cnt += 1 list.append(j) list.append(h-1) #print(list) x1 = 0 for x2 in range(w-1): #x1(最初は0)とx1+1の間からx=w-1とx=wの間までの区切り方をそれぞれ確かめる y1 = 0 for y2 in list: #長方形のブロックの右下の点のy座標の候補をすべて試す if count(x1,y1,x2,y2) > k: #ある横の区切り方の下で、どのように縦を区切ってもブロックに含まれる1の個数がKより大きくなるとき、条件を満たす切り分け方は存在しない cnt += 10**18 if count(x1,y1,x2,y2) <= k and count(x1,y1,x2+1,y2) > k: #ある位置でブロックを区切ると1の個数がK以下になるが、区切る位置を1つ進めると1の個数がKより大きくなるとき、その位置で区切る必要がある cnt += 1 x1 = x2+1 #ある位置x2で区切ったとき、次からはx2+1を長方形のブロックの左上の点のx座標として見ればよい break y1 = y2+1 #(いま見ているブロックの右下の点のy座標)+1が次に見るブロックの左上の点のy座標に等しくなる y1 = 0 for y2 in list: if count(x1,y1,w-1,y2) > k: #最後に縦で区切った位置以降で、あるブロックに含まれる1の個数がKより大きくなるとき、条件を満たすような区切り方は存在しない cnt += 10**18 break y1 = y2+1 ans = min(ans,cnt) print(ans)
import sys #UnionFindTreeクラスの定義 class UnionFind(): #クラスコンストラクタ #selfはインスタンス自身 def __init__(self, n): #親ノードを-1に初期化する self.parents = [-1] * n #根を探す(再帰関数) def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] #xとyの木を併合する def union(self, x, y): #x,yの根をX,Yとする X = self.find(x) Y = self.find(y) #根が同じなら結合済み if X == Y: return #ノード数が多い方をXとする if self.parents[X] > self.parents[Y]: X, Y = Y, X #XにYのノード数を足す self.parents[X] += self.parents[Y] #Yの根を X>0 とする self.parents[Y] = X N, M = map(int, input().split()) info = [tuple(map(int, s.split())) for s in sys.stdin.readlines()] #UnionFindインスタンスの生成 uf = UnionFind(N) for a, b in info: #インデックスを調整し、a,bの木を結合 a -= 1; b -= 1 uf.union(a, b) c = 0 for i in range(N): if uf.parents[i] < 0: c += 1 print(c-1)
0
null
25,362,638,815,318
193
70
print(['bust','win'][sum(map(int,input().split()))<22])
a, b, c = [int(x) for x in input().split()] if a + b + c >= 22: print("bust") else: print("win")
1
118,861,727,624,498
null
260
260
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**20 def I(): return int(input()) def F(): return float(input()) def S(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def resolve(): N = I() fact = [] for i in range(1, int(N ** 0.5) + 1): if N % i == 0: fact.append((i, N // i)) print(sum(fact[-1]) - 2) if __name__ == '__main__': resolve()
s = list(input()) t = list(input()) leng = len(s) if s[0:leng] == t[0:leng]: print("Yes") else: print("No")
0
null
91,474,359,951,520
288
147
def sep(): return map(int,input().strip().split(" ")) def lis(): return list(sep()) a,b=sep() for i in range(1,10005): if (i*8)//100==a and (i*10)//100==b: print(i) quit() print(-1)
import sys input = sys.stdin.readline def check(s): h = 0 for p in s: b = h + p[0] if b < 0: return False h += p[1] return True N = int(input()) S = [input().strip() for i in range(N)] total = 0 ps, ms = [], [] for s in S: h, b = 0, 0 for c in s: if c == '(': h += 1 else: h -= 1 b = min(b, h) if h > 0: ps.append([b, h]) else: ms.append([b-h, -h]) total += h ps.sort(reverse=True) ms.sort(reverse=True) if check(ps) and check(ms) and total == 0: print('Yes') else: print('No')
0
null
39,965,031,046,500
203
152
# input n, q = map(int, raw_input().split()) procs = [raw_input().split() for i in xrange(n)] procs = list(reversed(procs)) # procsessing cnt, lack = 0, 1 while lack > 0: lack = 0 tprocs = [] for i in xrange(n): proc = procs.pop() t = int(proc[1]) if t <= q: cnt += t print proc[0], cnt n -= 1 else: # t > q cnt += q t = t - q lack += t proc[1] = str(t) tprocs.append(proc) procs = list(reversed(tprocs))
n,x,y = map(int, input().split()) g = [0]*(n) for i in range(1,n+1): for j in range(1,i): e = abs(y-i)+1+abs(x-j) f = i-j g[min(e,f)]+=1 for i in g[1:]: print(i)
0
null
22,210,935,756,412
19
187
D = 100000 N = int(raw_input()) for i in xrange(N): D += D/20 if D % 1000 > 0: D += 1000-D%1000 print D
from math import factorial as fac x,y=map(int,input().split()) a=(2*y-x)/3 b=(2*x-y)/3 mod=10**9+7 if a>=0 and b>=0 and a==int(a) and b==int(b): a=int(a) b=int(b) a1=1 a2=1 n3=10**9+7 for i in range(a): a1*=a+b-i a2*=i+1 a1%=n3 a2%=n3 a2=pow(a2,n3-2,n3) print((a1*a2)%n3) else: print(0)
0
null
74,815,914,846,802
6
281
ans = 0 x, y = map(int,input().split()) ans += 100000*max((4-x),0) ans += 100000*max((4-y),0) if x == y == 1: ans += 400000 print(ans)
while True: card = str(input()) if card == '-': break S = int(input()) for i in range(S): h = int(input()) card = card[h:] + card[:h] print(card)
0
null
71,127,558,893,248
275
66
from itertools import combinations N,M = map(int,input().split()) a=["A" for i in range(0,N)] b=["B" for i in range(0,M)] tmp1=(len(list(combinations(a,2)))) tmp2=(len(list(combinations(b,2)))) print(tmp1+tmp2)
N, M = map(int, input().split()) import math print(math.comb(N, 2)+math.comb(M, 2))
1
45,462,651,441,570
null
189
189
i = 1 while True: n = input() if n != 0: print 'Case %s: %s' % (str(i), str(n)) i = i + 1 else: break
#coding:utf-8 #1_7_B 2015.4.5 while True: n,x = map(int,input().split()) if n == x == 0: break count = 0 for i in range(1 , n + 1): for j in range(1 , n + 1): if i < j < (x - i - j) <= n: count += 1 print(count)
0
null
880,195,871,744
42
58
K=int(input());S="" for i in range(K): S=S+"ACL" print(S)
n, m = map(int, input().split()) h = list(map(int, input().split())) ab = [True] * n for _ in range(m): a, b = map(int, input().split()) if h[a-1] > h[b-1]: ab[b-1] = False elif h[b-1] > h[a-1]: ab[a-1] = False else: ab[a-1] = False ab[b-1] = False print(ab.count(True))
0
null
13,558,094,371,000
69
155
import collections hoge = collections.defaultdict(lambda: 'no') num = int(input()) for _ in range(num): command, key = input().split() if command == 'insert': hoge[key] = 'yes' else: print(hoge[key])
def main(): n = int(input()) d = set([]) for i in range(n): command, string = input().split() if (command == 'insert'): d.add(string) elif (command == 'find'): if string in d: print('yes') else: print('no') if __name__ == "__main__": main()
1
79,483,772,550
null
23
23
n = int(input()) x = 0 if n%2 == 0: x = 1 print(n // 2 - x)
n=int(input()) a=list(map(int,input().split())) res=1000 for i in range(1,n): if a[i]>a[i-1]: t=(res//a[i-1])*a[i]+res%a[i-1] res=t print(res)
0
null
80,484,630,157,752
283
103
while True: m,f,r=map(int,input().split()) if m==f and f==r and r==-1: break if m==-1 or f==-1: print("F") elif (m+f)>=80: print("A") elif 65<=(m+f): print("B") elif 50<=(m+f) or r>=50: print("C") elif 30<=(m+f): print("D") else: print("F")
while(True): m, f, r = map(int, input().split(" ")) if (m == -1) and (f == -1) and (r == -1): exit() if (m == -1) or (f == -1): print("F") elif (m + f >= 80): print("A") elif (m + f >= 65) and (m + f < 80): print("B") elif (m + f >= 50) and (m + f < 65): print("C") elif (m + f >= 30) and (m + f < 50): if (r >= 50): print("C") else: print("D") else: print("F")
1
1,240,058,041,372
null
57
57
n = int(input()) sum = 0 for i in range(n + 1): if i % 3 != 0 and i % 5 != 0 and i % 15 != 0: sum += i print(sum)
def input_int(): return(int(input())) def input_int_list(): return(list(map(int,input().split()))) def input_int_map(): return(map(int,input().split())) def run(): S = list(input()) left = [0] * (len(S) + 1) right = [0] * (len(S) + 1) for i in range(len(S)): if S[i] == '<': left[i + 1] += 1 + left[i] for i in range(len(S) - 1, -1, -1): if S[i] == '>': right[i] = right[i + 1] + 1 ans = [0] * (len(S) + 1) for i in range(len(S) + 1): ans[i] = max(left[i], right[i]) print(sum(ans)) run()
0
null
95,834,647,323,172
173
285