code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
S=input() N=int(input()) for i in range(N): command=input().split() if command[0]=="replace": a=int(command[1]) b=int(command[2]) x=command[3] A=S[:a] B=S[b+1:] S=A+x+B elif command[0]=="reverse": a=int(command[1]) b=int(command[2]) A=S[:a] B=S[a:b+1] C=S[b+1:] T="" for p in range(len(B)): T+=B[len(B)-1-p] S=A+T+C else: #command[0]=="print" a=int(command[1]) b=int(command[2]) print(S[a:b+1])
s = str(input()) q = int(input()) for i in range(q): arr = list(map(str, input().split())) c = arr[0] n1 = int(arr[1]) n2 = int(arr[2]) if c == 'print': print(s[n1:n2 + 1]) if c == 'replace': s = s[0:n1] + arr[3] + s[n2 + 1:len(s)] if c == 'reverse': l = n2 - n1 + 1 reverse = '' for i in range(l): reverse += s[n2 - i] s = s[0:n1] + reverse + s[n2 + 1:len(s)]
1
2,101,020,950,898
null
68
68
N = int(input()) A = list(map(int, input().split())) j=0 for i in range(N): if A[i]==j+1: j+=1 if j == 0: print(-1) else: print(N-j)
while True: [a,b,c]=[x for x in input().split()] [a,c]=[int(a),int(c)] op=b if op=="?": break elif op=="+": print(a+c) elif op=="-": print(a-c) elif op=="*": print(a*c) else: print(a//c)
0
null
57,363,331,399,712
257
47
line = list(input()) N = len(line) i = 1 for i in range(N): if line[i] == "?": line[i] = "D" print("".join(line))
N,K = map(int, input().split()) z = 1 cnt = 0 while z <= N: z *= K cnt += 1 print(cnt)
0
null
41,369,374,241,440
140
212
x,n=map(int,input().split()) p=list(map(int,input().split())) temp=100 for i in range(x-51,x+51): a=abs(x-i) if a<temp and i not in p: temp=a ans=[i] if a==temp and i not in p: ans+=[i] print(min(ans))
def draft(A, K, N): for _ in range(1, K+1):# 2 * 10**5 tmp = [0]*(N+1) for i in range(N):# 2 * 10**5 L = max(0, i - A[i]) R = min(N, i + A[i]+1) tmp[L] += 1 tmp[R] -= 1 f = True for i in range(N): tmp[i+1] += tmp[i] A[i] = tmp[i] if A[i] != N: f = False if f: break for i in range(N): print(A[i], end=" ") def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) draft(A, K, N) if __name__ == "__main__": main()
0
null
14,780,147,299,550
128
132
import sys sys.setrecursionlimit(10**6) from math import floor,ceil,sqrt,factorial,log from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from copy import deepcopy from operator import itemgetter from fractions import gcd mod = 10 ** 9 + 7 inf = float('inf') ninf = -float('inf') #整数input def ii(): return int(sys.stdin.readline().rstrip()) #int(input()) def mii(): return map(int,sys.stdin.readline().rstrip().split()) def limii(): return list(mii()) #list(map(int,input().split())) def lin(n:int): return [ii() for _ in range(n)] def llint(n: int): return [limii() for _ in range(n)] #文字列input def ss(): return sys.stdin.readline().rstrip() #input() def mss(): return sys.stdin.readline().rstrip().split() def limss(): return list(mss()) #list(input().split()) def lst(n:int): return [ss() for _ in range(n)] def llstr(n: int): return [limss() for _ in range(n)] #本当に貪欲法か? DP法では?? #本当に貪欲法か? DP法では?? #本当に貪欲法か? DP法では?? mod=998244353 n=ii() arr=limii() if arr[0]!=0: print(0) exit() if n==1 and arr[0]==0: print(1) exit() chk=True p=Counter(arr) if p[0]!=1: print(0) exit() tmp=0 for i in range(1,max(list(p))+1): if p[i]>0: pass else: print(0) exit() ans=1 #掛け算の場合 # (a*b)%mod と同等 def mul(a, b): return ((a % mod) * (b % mod)) % mod #割り算の場合 # (a//b)%mod と同等 def div(a,b): return a*pow(b, mod-2, mod) #累乗の場合 #a**n %p と同等 def p_f(a,n,pp): bi=str(format(n,"b"))#2進表現に res=1 for i in range(len(bi)): res=(res*res) %pp if bi[i]=="1": res=(res*a) %pp return res for i in range(max(p.keys())): ans=(ans*pow(p[i], p[i+1], mod)) %mod print(ans%mod)
mod = 998244353 n= int(input()) d= list(map(int,input().split())) if (d[0]!=0) or (0 in d[1:]): print(0) exit(0) md=max(d) def pf(a,n,p): bi=str(format(n,"b")) res=1 for i in range(len(bi)): res=(res*res) %p if bi[i]=="1": res=(res*a) %p return res tl=[0]*md for c in d[1:]:tl[c-1]+=1 if 0 in tl: print(0) exit(0) ans=1 for i in range(md-1):ans=(ans%mod*pf(tl[i],tl[i+1],mod))%mod print(ans)
1
154,847,613,698,130
null
284
284
import numpy as np D = int(input()) C = np.array(list(map(int, input().split()))) S = [] for i in range(D): s = list(map(int, input().split())) S.append(s) S = np.array(S) T = [int(input()) for _ in range(D)] last = np.zeros(26, dtype=np.int64) def decrease(d, last): res = np.sum(C * (d - last)) # print(d, res, C * (d - last)) return res manzoku = 0 # kaisai = dict() # print(S, T, C) for day, t in enumerate(T): t -= 1 manzoku += S[day, t] # d 日目にタイプi のコンテストを開催した場合、満足度が S[d,i]増加することが予め分かっています。 last[t] = day + 1 manzoku -= decrease(day + 1, last) print(manzoku)
import sys input = sys.stdin.readline import numpy as np from numba import njit def read(): D = int(input().strip()) C = np.fromstring(input().strip(), dtype=np.int32, sep=" ") S = np.empty((D, 26), dtype=np.int32) for i in range(D): s = np.fromstring(input().strip(), dtype=np.int32, sep=" ") S[i, :] = s[:] T = np.array([int(input().strip()) for i in range(D)], dtype=np.int32) return D, C, S, T @njit def satisfaction(d, C, S, T, last): v = 0 v += S[d, T[d]-1] last[T[d]-1] = d+1 for i in range(26): v -= C[i] * ((d+1) - last[i]) return v @njit def solve(D, C, S, T): last = np.zeros(26, dtype=np.int32) cumsat = 0 for i in range(D): sat = satisfaction(i, C, S, T, last) cumsat += sat print(cumsat) if __name__ == '__main__': inputs = read() outputs = solve(*inputs) if outputs is not None: print("%s" % str(outputs))
1
9,958,581,537,504
null
114
114
import math def LI(): return list(map(int, input().split())) L, R, d = LI() Ld = (L-1)//d Rd = R//d ans = Rd-Ld print(ans)
def main(): L, R, d = map(int,input().split()) if L%d==0 and R%d==0: print(int((R-L)/d) + 1) return else: l = L - L % d r = R - R % d print(int((r - l)/d)) return if __name__=='__main__': main()
1
7,548,390,915,172
null
104
104
import sys N,M = map(int,input().split()) array = list(map(int,input().split())) if not ( 1 <= M <= 100 and M <= N <= 100 ): sys.exit() if not (len(array) == len(set(array))): sys.exit() count = 0 standard = sum(array) * (1/(4*M)) for I in array: if I >= standard: count += 1 print('Yes') if count >= M else print('No')
A, B = map(int, input().split()) ans = 0 for i in range(B): ans += A if ans%B == 0: break print(ans)
0
null
76,235,992,585,622
179
256
N = int(input()) total = 0 for n in range(1, N+1): if (n % 3 > 0) and (n % 5 > 0): # print(n) total += n print(total)
N = int(input()) answer = 0 for i in range(1, N + 1): if i % 3 != 0 and i % 5 != 0: answer = answer + i print(answer)
1
34,841,117,405,742
null
173
173
for c in input(): if c.isupper(): print(c.lower(), end='') elif c.islower(): print(c.upper(), end='') else: print(c, end='') print()
if __name__ == "__main__": input_word = input() print(input_word.swapcase())
1
1,503,709,446,372
null
61
61
# for内をご丁寧に書いていたらTLEを食らった # PyPyだとそのままで通った、すごい # for内の冗長な部分を排除しまくったらPythonでも通った # N=6とかで実験して、横で見ていたのを縦から眺めてみると良い(伝われ) # (1+2+...+6) + (2+4+6) + ... + (6)と見る # 結局何を足したいのか考えて約数のところを書き換える(伝われ) N = int(input()) ans = 0 for i in range(1, N + 1): n = N // i temp = (n * (n + 1) * i) // 2 ans += temp print(ans)
def main(N): x = 0 for i in range(1,N+1): for j in range(i,N+1,i): x += j return x N = int(input()) print(main(N))
1
11,004,227,710,112
null
118
118
n,k = map(int,input().split()) h = list(map(int,input().split())) print(sum(sorted(h)[:n-k]) if n-k>0 else 0)
X = int(input()) A = [] for i in range(200): A.append(pow(i, 5)) for i in range(200): for j in range(200): a = abs(A[i] - A[j]) b = A[i] + A[j] if a == X: if i <= j: B = [j, i] else: B = [i, j] print(' '.join(map(str, B))) exit() elif b == X: B = [i, -j] print(' '.join(map(str, B))) exit()
0
null
52,592,786,448,972
227
156
a, b = input().split() a = int(a) b1, b2 = b.split('.') b = int(b1 + b2) print(a * b // 100)
from decimal import Decimal a, b = [Decimal(i) for i in input().split()] print(int(a * b))
1
16,546,238,102,300
null
135
135
import math n = int(input()) x, y = math.floor(n / 1.08), math.ceil(n / 1.08) ans = ":(" if int(x * 1.08) == n: ans = x elif int(y * 1.08) == n: ans = y print(ans)
# -*- coding: utf-8 -*- import math def main(): N = int(input()) if N % 1.08 == 0: print(N/1.08) else: x = math.ceil(N/1.08) if x < (N+1)/1.08: print(x) else: print(':(') return if __name__ == '__main__': main()
1
125,217,222,222,168
null
265
265
S = input() a = "RRR" b = "RR" c = "R" if a == S: print(3) elif b in S: print(2) elif c in S: print(1) else: print(0)
S = input() if 'RRR' in S: ANS = 3 elif 'RR' in S: ANS = 2 elif 'RS' in S: ANS = 1 elif 'SR' in S: ANS = 1 elif 'SSS' in S: ANS = 0 print(ANS)
1
4,916,378,618,480
null
90
90
import sys def solve(): input = sys.stdin.readline N = int(input()) S = input().strip("\n") Left = [set() for _ in range(N)] Right = [set() for _ in range(N)] Left[0] |= {S[0]} Right[N-1] |= {S[N-1]} for i in range(1, N): Left[i] = Left[i-1] | {S[i]} Right[N-i-1] = Right[N-i] | {S[N-i-1]} used = set() for i in range(1, N - 1): mid = S[i] for l in Left[i-1]: for r in Right[i+1]: used |= {l + mid + r} print(len(used)) return 0 if __name__ == "__main__": solve()
n=int(input()) s=input() cnt=0 def judge(n): pos=0 pos=s.find(n[0],pos) if pos==-1: return 0 pos=s.find(n[1],pos+1) if pos==-1: return 0 pos=s.find(n[2],pos+1) if pos==-1: return 0 return 1 for i in range(1000): p=str(i).rjust(3,'0') if judge(p): cnt+=1 print(cnt)
1
128,476,202,234,182
null
267
267
r,cr,c = map(int,input().split()) matrix_a = [list(map(int,input().split())) for i in range(r)] matrix_b = [list(map(int,input().split())) for i in range(cr)] matrix_c = [ [0 for a in range(c)] for b in range(r)] for j in range(r): for k in range(c): for l in range(cr): matrix_c[j][k] += matrix_a[j][l]*matrix_b[l][k] for x in matrix_c: print(" ".join(list(map(str,x))))
n,m,l = map(int,input().split()) A,B,C = [],[],[] for i in range(n): A.append(list(map(int,input().split()))) for ii in range(m): B.append(list(map(int,input().split()))) for k in range(n): ans = [] for s in range(l): cul = 0 for kk in range(m): cul += A[k][kk] * B[kk][s] ans.append(cul) ans = list(map(str,ans)) print(" ".join(ans))
1
1,426,220,633,100
null
60
60
c = input() if c.islower(): print('a') else: print('A')
str = input() if str.islower(): print('a') else: print('A')
1
11,382,538,891,936
null
119
119
from math import ceil,floor A,B=map(int,input().split()) x_min=int(min(ceil(A/0.08)-5, ceil(B/0.1)-5)) x_max=int(max(ceil((A+1)/0.08)+5, ceil((B+1)/0.1)+5)) exists=0 for i in range(x_min, x_max): if floor(i*0.08)==A and floor(i*0.1)==B: print(i) exists=1 break if not exists:print(-1)
h,w,y=map(int,input().split()) c=[input() for _ in range(h)] black=0 for i in range(h): for j in range(w): if c[i][j]=="#": black+=1 if black<y: print("0") exit() hb=[] wb=[] for i in range(h): hb.append(c[i].count("#")) for i in range(w): count=0 for j in range(h): if c[j][i]=="#": count+=1 wb.append(count) bit=[] for i in range(2**(h+w)): #行:[:h]、列:[h+1:] bit.append(bin(i)[2:].zfill(h+w)) ans=0 for i in bit: x=black for j in range(h): if i[j]=="1": for k in range(w): if i[h+k]=="1" and c[j][k]=="#": x+=1 for j in range(h): if i[j]=="1": x-=hb[j] for j in range(w): if i[h+j]=="1": x-=wb[j] if x==y: ans+=1 print(ans)
0
null
32,700,415,629,222
203
110
a = input() iff3 = a[2] iff4 = a[3] iff5 = a[4] iff6 = a[5] if iff3 == iff4 : if iff5 == iff6 : print("Yes") else : print("No") else : print("No")
import sys s = input() if s[2] == s[3] and s[4] == s[5]: print("Yes") sys.exit() print("No")
1
41,887,249,711,088
null
184
184
x,y,a,b,c = map(int,input().split()) p = list(map(int,input().split())) q = list(map(int,input().split())) r = list(map(int,input().split())) p.sort(reverse=True) q.sort(reverse=True) apples = p[:x] + q[:y] + r apples.sort(reverse=True) print(sum(apples[:x+y]))
l = [int(x) for x in input().split()] X, N = l[0], l[1] p = [int(x) for x in input().split()] delta = 0 while True: if not X - delta in p: print(X-delta) break if not X + delta in p: print(X + delta) break delta += 1
0
null
29,428,879,079,420
188
128
#E N = int(input()) A = list(map(int,input().split())) B = [] for i in range(N): B.append([A[i],i+1]) B.sort(reverse=True) DP = [[0 for _ in range(N+1)] for _ in range(N+1)] #dp[x][y] x->1,2,3... y->N,N-1,N-2... for i in range(N): I = i+1 b,ind = B[i] for j in range(I+1): if j == 0: DP[j][I-j] = DP[j][I-j-1] + b*abs(N-(I-j)-ind+1) elif I-j == 0: DP[j][I-j] = DP[j-1][I-j] + b*abs(ind-j) else: DP[j][I-j] = max(DP[j][I-j-1]+b*abs(N-(I-j)-ind+1),DP[j-1][I-j]+b*abs(ind-j)) ans = 0 for i in range(N+1): ans = max(ans,DP[i][N-i]) #print(B) print(ans)
n,m=map(int,input().split()) h=list(map(int,input().split())) l=[1]*n for i in range(m): a,b=map(int,input().split()) if h[a-1]==h[b-1]: l[a-1]=0 l[b-1]=0 if h[a-1]>h[b-1]: l[b-1]=0 if h[a-1]<h[b-1]: l[a-1]=0 print(l.count(1))
0
null
29,457,161,159,452
171
155
import math a = int(input()) if a%2 == 0: print(int((a/2-1))) else: b = int(math.floor(a/2)) print(b)
n=int(input()) n=int(n/2+0.5-1) print(n)
1
152,617,354,399,032
null
283
283
def main(): for N in range(1,10): for M in range(1,10): print(str(N)+"x"+str(M)+"="+str(N*M)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- loop = 1 while(loop): l = input().strip().split() H = int(l[0]) W = int(l[1]) if(H == 0 and W == 0): break else: for y in (range(H)): for x in (range(W)): if((x % 2 == 0) and(y % 2 == 0) or (x % 2 != 0) and(y % 2 != 0)): print("#",end="") else: print(".",end="") print() print()
0
null
438,803,750,498
1
51
import numpy as np from numba import njit @njit #処理の並列化_これがない場合は'TLE' def imos(n, a): l=np.zeros((n+1), dtype = np.int64) for i, x in enumerate(a):# x_光の強さ_これで照射範囲が決まる left = max(0, i - x) #StartIndex_照らせる範囲 right = min(n, i + x + 1) #EndIndex + 1_照らせる範囲 l[left] += 1 # 各々を'+1'と'-1'で表し... l[right] -= 1 return np.cumsum(l)[:n] # 累積和をとる_cumulative sum n, k = map(int, input().split()) a = list(map(int, input().split())) for _ in range(k): a = imos(n, a) if a.min() == n: # すべての要素が最大値'n'になるとbreak break print(*a)
import numpy as np from numba import njit n,k =map(int,input().split()) a= np.array(list(map(int,input().split()))) @njit(cache=True) def light(n,a_list): outcome= np.zeros(n+1, dtype=np.int64) for i in range(n): outcome[max(0,i-a_list[i])] += 1 outcome[min(n,i+a_list[i]+1)] -= 1 outcome = np.cumsum(outcome)[:-1] return outcome for _ in range(k): if min(a) == n: break a = light(n,a) [print(aa,end=' ') for aa in a]
1
15,607,258,174,430
null
132
132
# -*- coding:utf-8 -*- x = int(input()) if x == False: print("1") else: print("0")
N = int(input()) MX = 10**4 ans = {} for x in range(1, 100): for y in range(1, 100): for z in range(1, 100): tmp = x**2+y**2+z**2+x*y+x*z+y*z if tmp > MX: break if not(tmp in ans): ans[tmp] = 1 else: ans[tmp] += 1 for i in range(1, N+1): if i in ans: print(ans[i]) else: print(0)
0
null
5,490,779,825,598
76
106
a = str(input()) if 'A'<=a and a<='Z': print('A') else: print('a')
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 a = str(readline().rstrip().decode('utf-8')) print("A" if a.isupper() else "a") if __name__ == '__main__': solve()
1
11,257,755,483,348
null
119
119
N = int(input()) s = input() res = 0 search = [("00"+str(s))[-3:] for s in range(0,1000)] for v in search: tmp = s if v[0] in tmp: tmp = tmp[tmp.index(v[0])+1:] else: continue if v[1] in tmp: tmp = tmp[tmp.index(v[1])+1:] else: continue if v[2] in tmp: res += 1 print(res)
from collections import deque def breadth_first_search(adj_matrix, n): distance = [0] + [-1] * (n - 1) searching = deque([0]) while len(searching) > 0: start = searching.popleft() for end in range(n): if adj_matrix[start][end] and distance[end] == -1: searching.append(end) distance[end] = distance[start] + 1 return distance def main(): n = int(input()) adj = [[False for _ in range(n)] for _ in range(n)] for _ in range(n): ukv = input().split() id = int(ukv[0]) dim = int(ukv[1]) if dim > 0: nodes = map(int, ukv[2:]) for node in nodes: adj[id - 1][node - 1] = True distance = breadth_first_search(adj, n) for i in range(n): print("{} {}".format(i + 1, distance[i])) if __name__ == "__main__": main()
0
null
64,656,860,342,442
267
9
import sys def input(): return sys.stdin.readline().rstrip() def main(): k = int(input()) keta = 1 mod = 7%k while keta < 10**7: if mod==0: print(keta) break keta += 1 mod = (mod*10 + 7)%k else: print(-1) if __name__=='__main__': main()
def main(): k=int(input()) s=7 for i in range(10**6): if s%k == 0: print(i+1) break s = (s*10+7)%k else: print(-1) if __name__ == "__main__": main()
1
6,106,116,214,862
null
97
97
def main(): N, M = map(int, input().split()) num = [-1] * N for _ in range(M): s, c = map(int, input().split()) s -= 1 if s == 0 and c == 0: if N != 1: print(-1) return if num[s] == -1: num[s] = c elif num[s] != c: print(-1) return ans = "" for i in range(len(num)): c = num[i] if c == -1: if i != 0 or N == 1: ans += "0" else: ans += "1" else: ans += str(c) print(ans) main()
import sys N,M = map(int,input().split()) s = [] c = [] for i in range(M): S,C = map(int,input().split()) s.append(S) c.append(C) for i in range(10**(N+1)): st = str(i) if len(st) == N and all([st[s[j]-1] == str(c[j]) for j in range(M)]): print(st) sys.exit() print(-1)
1
60,932,860,603,810
null
208
208
from collections import deque h, w = list(map(int, input().split())) grid = [input() for _ in range(h)] ans = [[10000]*w for _ in range(h)] ans[0][0] = 0 if grid[0][0] == "." else 1 queue = deque([(0, 0)]) while len(queue) > 0: x, y = queue.popleft() for xo, yo in [(0, 1), (1, 0)]: xnext, ynext = x+xo, y+yo if xnext >= w or ynext >= h: continue if grid[y][x] == "." and grid[ynext][xnext] == "#": if ans[y][x] + 1 < ans[ynext][xnext]: ans[ynext][xnext] = ans[y][x] + 1 queue.append((xnext, ynext)) else: if ans[y][x] < ans[ynext][xnext]: ans[ynext][xnext] = ans[y][x] queue.append((xnext, ynext)) print(ans[h-1][w-1])
import sys sys.setrecursionlimit(10**6) def main(): h, w = map(int, input().split()) s = [input() for _ in range(h)] dp = [[10**5] * w for _ in range(h)] def func(temp, now, flag): x, y = now if y > h - 1 or x > w - 1: return 10**6 if s[y][x] == "#": if not flag: temp += 1 flag = True else: flag = False if x == w-1 and y == h-1: return temp if dp[y][x] <= temp: return 10**6 dp[y][x] = temp piyo = [] return min(func(temp, (x + 1, y), flag), func(temp, (x, y + 1), flag)) print(func(0, (0, 0), False)) main()
1
49,178,074,288,086
null
194
194
N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) result = -float('inf') for i in range(N): p = P[i] - 1 c = C[p] k = K - 1 t = c while p != i and k != 0: p = P[p] - 1 c += C[p] t = max(t, c) k -= 1 if k == 0 or c <= 0: result = max(result, t) continue l = K - k c = c * (K // l - 1) k = K - (K // l - 1) * l t = c while k != 0: p = P[p] - 1 c += C[p] t = max(t, c) k -= 1 result = max(result, t) print(result)
N = int(input()) S = input() total = 0 for i in range(N-2): if S[i] == "R": num_G = S[i+1:].count('G') num_B = S[i+1:].count('B') total += num_G * num_B elif S[i] == "G": num_B = S[i+1:].count('B') num_R = S[i+1:].count('R') total += num_B * num_R elif S[i] == "B": num_G = S[i+1:].count('G') num_R = S[i+1:].count('R') total += num_G * num_R for i in range(N-2): for j in range(i+1, N-1): if 2*j-i >= N: continue if S[j] != S[i] and S[2*j-i] != S[j] and S[2*j-i] != S[i]: total -= 1 print(total)
0
null
20,686,212,320,088
93
175
a,b=map(int, input().split()) print("{0} {1} {2:.5f}".format(a//b, a%b, a/b))
import sys import math import bisect from collections import defaultdict,deque # input = sys.stdin.readline def inar(): return [int(el) for el in input().split()] # def find(a,b,c): # gc=math.gcd(a,b) # return math.gcd(gc,c) def main(): n=int(input()) string=input() r=[] g=[] b=[] for i in range(n): if string[i]=="R": r.append(i) elif string[i]=="G": g.append(i) else: b.append(i) ans=0 r.sort() g.sort() b.sort() # print(r) # print(g) # print(b) # print(len(b)) # ans1=0 # fir=[] # for i in range(len(r)): # for j in range(len(g)): # for k in range(len(b)): # ls=[r[i],g[j],b[k]] # ls.sort() # if ls[1]-ls[0]!=ls[2]-ls[1]: # ans1+=1 # fir.append(ans1) # # print(ans1) # print("-------------------check---------------") # are=[] for i in range(len(r)): for j in range(len(g)): ans+=len(b) chota=min(g[j],r[i]) bada=max(g[j],r[i]) diff=bada-chota left=bisect.bisect_left(b,bada+diff) right=bisect.bisect_left(b,chota-diff) lol=(bada+chota) if lol%2==0: beech=lol//2 ind=bisect.bisect_left(b,beech) if ind<len(b) and b[ind]==beech: ans-=1 if (left<len(b) and b[left]==bada+diff): ans-=1 if (right<len(b) and b[right]==chota-diff): ans-=1 # are.append(ans) print(ans) # for i in range(len(are)): # print(are[i],fir[i]) if __name__ == '__main__': main()
0
null
18,246,324,968,300
45
175
import sys n,k = map(int,input().split()) ans = 0; h = [int(x) for x in input().split()] h.sort(reverse = True) h = h[k:] if len(h) > 0: ans += sum(h) print(ans)
import sys input = sys.stdin.readline (n, k), s, res, sm = map(int, input().split()), list(map(lambda x: (int(x) + 1) / 2, input().split())), 0, 0 for i in range(n): if i < k: sm += s[i] else: sm += s[i]; sm -= s[i-k] res = max(res, sm) print(f'{res:.10f}') # print(f'{max([sum(s[i:i+k]) for i in range(n - k + 1)]):.10f}')
0
null
77,172,286,882,648
227
223
alp =['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'] a = str(input()) if a in alp: print('A') else: print('a')
letter = input() if letter.isupper() == True: print("A") else: print("a")
1
11,399,694,373,732
null
119
119
def solve(): N = int(input()) A = list(map(int, input().split())) square = [] for i in A: square.append(i**2) return (sum(A)**2 - sum(square))//2 % (10**9+7) print(solve())
n = int(input()) a = list(map(int, input().split())) m = 1000000007 s = 0 suma = sum(a) for i in range(n): suma -= a[i] s += a[i] * suma print(s % m)
1
3,823,472,209,284
null
83
83
# -*- coding: utf-8 -*- from collections import deque if __name__ == '__main__': n = int(input()) L = deque() for _ in range(n): command = input().split(" ") if command[0] == "insert": L.appendleft(command[1]) elif command[0] == "delete": try: L.remove(command[1]) except: pass elif command[0] == "deleteFirst": L.popleft() elif command[0] == "deleteLast": L.pop() print(" ".join(L))
from collections import deque import sys deq = deque() q = int(input()) for _ in range(q): s = input() if s == 'deleteFirst': deq.popleft() elif s == 'deleteLast': deq.pop() else: ss, num = s.split() if ss == 'insert': deq.appendleft(num) else: try: deq.remove(num) except: pass print(" ".join(deq))
1
48,895,728,352
null
20
20
cnt=0 def merge(a,left,mid,right): n1=mid-left n2=right-mid l=a[left:mid] r=a[mid:right] l.append(float("inf")) r.append(float("inf")) i=0 j=0 for k in range(left,right): global cnt cnt+=1 if(l[i] <= r[j]): a[k] = l[i] i+=1 else: a[k]=r[j] j+=1 def merge_sort(a,left,right): if(left+1<right): mid=(left+right)//2 merge_sort(a,left,mid) merge_sort(a,mid,right) merge(a,left,mid,right) n=int(input()) s=input() a=list(map(int,s.split())) merge_sort(a,0,n) a=map(str,a) print(" ".join(list(a))) print(cnt)
N=int(input()) *A,=map(int, input().split()) B=[(i+1,a) for i,a in enumerate(A)] from operator import itemgetter B.sort(reverse=True, key=itemgetter(1)) dp = [[-1] * (N+1) for _ in range(N+1)] dp[0][0] = 0 for i in range(1,N+1): idx, act = B[i-1] for j in range(i+1): k = i-j if 0<j: dp[j][k] = max(dp[j][k], dp[j-1][k] + act * abs(idx-j)) if 0<k: dp[j][k] = max(dp[j][k], dp[j][k-1] + act * abs(idx-(N-k+1))) ans=0 for j in range(N+1): ans = max(ans, dp[j][N-j]) print(ans)
0
null
16,931,833,963,588
26
171
def main(): n = int(input()) ans = 0 for k in range(1,n+1): ans += k * (n//k) * (n//k+1) //2 print(ans) if __name__ == "__main__": main()
a=int(input()) b=(a)//2+1 ans=0 for i in range(1,b,1): x=a//i ans+=((x**2+x)//2)*i ans+=(a**2+a+b-b**2)//2 print(ans)
1
11,028,804,706,062
null
118
118
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()
from numba import njit @njit("i8(i8)") def f(n): l = [1]*(n+1) l[0] = 0 ans = l[1] for i in range(2,n+1): for j in range(i,n+1,i): l[j] += 1 ans += (l[i]*i) return ans n = int(input()) print(f(n))
0
null
59,061,003,348,512
251
118
a, nums = map(int, input().split()) add = 0 lst = list(map(int, input().split())) lst.sort() for i in range(0,nums): add += lst[i] print(add)
a=input() l=a.split(" ") n=int(l[0]) k=int(l[1]) f=input() fruits=f.split(" ") for d in range(0, len(fruits)): fruits[d]=int(fruits[d]) ans=0 b=0 while(b<k): g=min(fruits) ans+=g fruits.remove(g) b+=1 print(ans)
1
11,572,211,803,820
null
120
120
def main(): N = int(input()) L = sorted(list(map(int, input().split()))) ans = 0 for ia in range(N-2): a = L[ia] ic = ia + 2 for ib in range(ia+1, N-1): b = L[ib] while ic < N and L[ic] < a+b: ic += 1 ans += ic - (ib + 1) print(ans) main()
import sys def main(): input = sys.stdin.buffer.readline n, k = map(int, input().split()) i = 1 while k ** i <= n: i += 1 print(i) if __name__ == "__main__": main()
0
null
117,833,975,202,228
294
212
X = int(input()) cnt = 1 deg = X while deg%360!=0: deg += X cnt += 1 print(cnt)
x = int(input()) xSum = 0 cnt = 1 while True: xSum += x if xSum%360 == 0: break cnt += 1 print(cnt)
1
13,057,565,489,220
null
125
125
M1, D1 = [int(_) for _ in input().split(" ")] M2, D2 = [int(_) for _ in input().split(" ")] if M1 == M2: print (0) else: print (1)
#coding:utf-8 data = input() xmax = len(data) data_list = list(data) data_list.reverse() reverse_data = [] for sig in data_list: if sig == "\\": reverse_data.append("/") elif sig == "/": reverse_data.append("\\") else: reverse_data.append(sig) reverse_data = "".join(reverse_data) def partialSqu(h, sig): if sig == "\\": squ = h + 1/2 h += 1 elif sig == "/": squ = h - 1/2 h -= 1 elif sig == "_": squ = h return squ, h x_squ_dict = {} cnt = 0 sw, x, h, totalSqu = 0, 0, 0, 0 for sig in data: x += 1 if sw == 0 and sig == "\\": sw = 1 if sw == 1 : squ, h = partialSqu(h, sig) totalSqu += squ if h == 0: x_squ_dict[x] = totalSqu totalSqu = 0 sw = 0 keys = x_squ_dict.keys() sw, x, h, totalSqu = 0, 0, 0, 0 for sig in reverse_data: x += 1 if sw == 0 and sig == "\\" : sw = 1 x_p = xmax - x +1 if sw == 1 : squ, h = partialSqu(h, sig) totalSqu += squ if h == 0: x_squ_dict[x_p] = totalSqu totalSqu = 0 sw = 0 keys = x_squ_dict.keys() keys = list(keys) keys.sort() squ_list = [] for key in keys: squ_list.append(x_squ_dict[key]) a = int(sum(squ_list)) print(a) squ_list.insert(0,len(keys)) squ_list = " ".join([str(int(num)) for num in squ_list]) print(squ_list)
0
null
62,177,151,867,750
264
21
n=int(input()) dept=100000 for i in range(n): dept*=1.05 if dept%1000!=0: dept=dept-dept%1000+1000 print(int(dept))
from math import floor n = int(input()) def debt(week): debt = 100000 for i in range(1,n+1): debt *= 1.05 amari = debt % 1000 if amari: debt += 1000 - amari return int(debt) print(debt(n))
1
1,120,096,868
null
6
6
k, x = map(int, input().split()) ans = 'Yes' if 500 * k < x: ans = 'No' print(ans)
import itertools import math import fractions import functools k, x = map(int, input().split()) if 500*k >= x: print("Yes") else: print("No")
1
98,518,668,080,690
null
244
244
import sys N, M = map(int,input().split()) S = input() S = S[::-1] i = 0 ans = [] while i < N: flag = 0 for j in range(M,0,-1): if i + j <= N and S[i + j] == '0': i += j flag = 1 ans.append(j) break if flag: continue print(-1) sys.exit() ans.reverse() print(*ans)
N,M=map(int, input().split()) S=list(input()) T=S[::-1] D=[0]*N if N<=M: print(N) exit() renzoku,ma=0,0 for i in range(1,N+1): if S[i]=='1': renzoku+=1 else: ma=max(ma,renzoku) renzoku=0 if ma>=M: print(-1) exit() r=0 for i in range(1,M+1): if T[i]!='1': r=i ans=[r] while r+M<N: for i in range(M,0,-1): if T[r+i]=='0': ans.append(i) r+=i break ans.append(N-r) print(*ans[::-1])
1
139,411,356,576,190
null
274
274
import math a,b,c=[int(i) for i in input().split()] e=math.ceil(a/c) if(e<=b): print('Yes') else: print('No')
N=int(input()) A=list(map(int,input().split())) def f(x): if x==1: return dict() y=x r=dict() for i in range(2,int(x**0.5)+1): if y%i==0: r[i]=0 while y%i==0: r[i]+=1 y=y//i if y==1: break if y!=1: r[y]=1 return r B=[f(A[i]) for i in range(N)] def g(X): if len(X)==1: return X[0] a,b=g(X[:len(X)//2]),g(X[len(X)//2:]) c=list(set(a.keys())|set(b.keys())) for i in range(len(c)): a[c[i]]=max(a.get(c[i],0),b.get(c[i],0)) return a G=g(B) X=1 mod=10**9+7 P=0 Y=list(G.keys()) for i in range(len(Y)): X=X*pow(Y[i],G[Y[i]],mod)%mod for i in range(N): P=(P+X*pow(A[i],mod-2,mod))%mod print(P)
0
null
45,865,515,949,890
81
235
# -*- coding: utf-8 -*- # import numpy as np import sys from collections import deque from collections import defaultdict import heapq import collections import itertools import bisect import math def zz(): return list(map(int, sys.stdin.readline().split())) def z(): return int(sys.stdin.readline()) def S(): return sys.stdin.readline() def C(line): return [sys.stdin.readline() for _ in range(line)] def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] N = z() yakusu_nums = [0]*(N+1) for i in range(1, N+1): for j in range(i, N+1, i): yakusu_nums[j] += 1 ans = 0 for i, yakusu_num in enumerate(yakusu_nums): # print(i, yakusu_num) ans += i*yakusu_num print(ans)
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)
1
11,112,106,684,192
null
118
118
n,p=map(int,input().split()) s=input() ans=0 if p==2: for i in range(n): if int(s[i])%2==0: ans+=i+1 print(ans) elif p==5: for i in range(n): if int(s[i])%5==0: ans+=i+1 print(ans) else: s=s[::-1] accum=[0]*n d=dict() for i in range(n): accum[i]=int(s[i])*pow(10,i,p)%p for i in range(n-1): accum[i+1]+=accum[i] accum[i+1]%=p accum[-1]%=p #print(accum) for i in range(n): if accum[i] not in d: if accum[i]==0: ans+=1 d[accum[i]]=1 else: if accum[i]==0: ans+=1 ans+=d[accum[i]] d[accum[i]]+=1 #print(d) print(ans)
import sys # import bisect # from collections import Counter, deque, defaultdict # import copy # from heapq import heappush, heappop, heapify # from fractions import gcd # import itertools # from operator import attrgetter, itemgetter # import math # from numba import jit # from scipy import # import numpy as np # import networkx as nx # import matplotlib.pyplot as plt readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, p = list(map(int, readline().split())) s = input() ans = 0 if p == 2 or p == 5: for i in range(n): if int(s[i]) % p == 0: ans += (i + 1) else: c = [0] * p prev = 0 c[0] = 1 for i in range(n): num = int(s[n - i - 1]) m = (num * pow(10, i, p) + prev) % p c[m] += 1 prev = m for i in range(p): cnt = c[i] ans += cnt * (cnt - 1) // 2 print(ans) if __name__ == '__main__': main()
1
58,058,537,079,228
null
205
205
n = int(input()) C = list(input()) a, b = 0, 0 for i in range(n): if C[i] == "R": a += 1 ans = max(a, b) for i in range(n): if C[i] == "R": a -= 1 else: b += 1 tmp = max(a, b) ans = min(ans, tmp) print(ans)
k=int(input()) a,b=map(int,input().split()) cnt=0 for i in range(a, b+1): if i%k==0: cnt+=1 if cnt>0: print('OK') else : print('NG')
0
null
16,581,366,135,850
98
158
r=input();p=3.14159265358979323846;print "%.10f"%(p*r*r),r*2*p
x = input() print x**3
0
null
457,020,581,404
46
35
import sys nums = [ int( val ) for val in sys.stdin.readline().split( " " ) ] if nums[0] < nums[1]: print( "a < b" ) elif nums[0] > nums[1]: print( "a > b" ) else: print( "a == b" )
i=map(int,raw_input().split()) if i[0]>i[1]: print "a > b" if i[0]<i[1]: print "a < b" if i[0]==i[1]: print "a == b"
1
364,958,578,112
null
38
38
N = int(input()) li = [] for i in input().split(): li.append(int(i)) a = 1 count = 0 for i in li: if a % 2 == 1 and i % 2 == 1: count += 1 a += 1 print(count)
# coding: utf-8 n = int(input()) a_array = list(map(int, input().split())) count = 0 for i, a in enumerate(a_array): if i % 2 == 0 and a % 2 != 0: count += 1 print(count)
1
7,780,082,041,852
null
105
105
n,a,b = map(int,input().split()) mod = n%(a+b) if mod > a : ans = a else: ans = mod ans += (n//(a+b))*a print(ans)
a = input() if a == "AAA" : print("No") elif a == "BBB": print("No") else: print("Yes")
0
null
54,924,313,212,020
202
201
import sys input = sys.stdin.readline n = int(input()) a = [int(x) for x in input().split()] max_a = [0]*(n + 1) if n == 0 and a[0] == 0: print(-1) sys.exit() for i in range(n + 1): if i == 0: max_a[i] = 1 else: max_a[i] = (max_a[i - 1] - a[i - 1])*2 if max_a[i] < 0: print(-1) sys.exit() # print(max_a) for i in range(n, -1, -1): if i == n: if max_a[i] < a[i]: print(-1) sys.exit() max_a[i] = a[i] else: min_p = max_a[i + 1] // 2 + int(max_a[i + 1] % 2 == 1) max_p = max_a[i + 1] if max_a[i] < min_p: print(-1) sys.exit() max_a[i] = min(max_p + a[i], max_a[i]) print(sum(max_a)) # print(max_a)
n = int(input()) a = list(map(int, input().split())) s = sum(a) k = 1-a[0] s -= a[0] ans = 1 for i in range(1,n+1): if k*2 <= s: k *= 2 else: k = s ans += k k -= a[i] s -= a[i] if k == 0 and s == 0: print(ans) else: print(-1)
1
18,911,107,553,348
null
141
141
# -*- coding: utf-8 -*- import numpy as np import sys from collections import deque from collections import defaultdict import heapq import collections import itertools import bisect def zz(): return list(map(int, sys.stdin.readline().split())) def z(): return int(sys.stdin.readline()) def S(): return sys.stdin.readline() def C(line): return [sys.stdin.readline() for _ in range(line)] N = z() A = zz() ans = 0 for i, a in enumerate(A): if(((i+1) % 2 == 1) and(a % 2 == 1)): ans += 1 print(ans)
#!/usr/bin/env python import math n = int(input()) a = list(map(int, input().split())) mod = 10**9+7 def lcm(a, b): return a*b//math.gcd(a, b) l = a[0] for i in range(n): l = lcm(l, a[i]) l %= mod ans = 0 for i in range(n): inv = pow(a[i], mod-2, mod) ans += (l*inv)%mod print(ans%mod)
0
null
47,438,000,840,662
105
235
a, b = map(int, input().split()) print('{0} {1} {2:f}'.format(a // b, a % b, a / b))
n = int(input()) d = set() for _ in range(n): c, s = input().split() if c == 'insert': d.add(s) else: print('yes' if s in d else 'no')
0
null
343,535,878,620
45
23
t = input().split() N = int(t[0]) M = int(t[1]) if N == M: print('Yes') else: print('No')
n,m=map(int,input().split()) print("Yes" if n<=m else "No")
1
83,030,556,382,404
null
231
231
def check(p, k, arr): subtotal = 0 num_of_tracks = 1 for a in arr: subtotal += a if subtotal > p: num_of_tracks += 1 if num_of_tracks > k: return False subtotal = a return True n, k = map(int, input().split()) arr = [int(input()) for i in range(n)] min_p = max(arr) max_p = sum(arr) while min_p < max_p: mid_p = (min_p + max_p) // 2 if check(mid_p, k, arr): max_p = mid_p else: min_p = mid_p + 1 print(min_p)
def binary_search(n, k, lw): left = 0 right = max(lw) * n while left < right: mid = (left + right)//2 if is_underweight(n, k, lw, p=mid): right = mid else: left = mid + 1 return left def is_underweight(n, k, lw, p): i = 0 w = 0 ck = 1 while i < n: if lw[i] > p: return False rest = p - w if lw[i] <= rest: w += lw[i] i += 1 else: w = 0 ck += 1 return ck <= k def main(): n, k = map(int, input().split()) lw = [] for _ in range(n): lw.append(int(input())) p = binary_search(n, k, lw) print(p) if __name__ == '__main__': main()
1
91,289,145,584
null
24
24
import bisect N = int(input()) L = list(map(int,input().split())) ans = 0 L = sorted(L) for i in range(N): for j in range(N): if i >= j: continue a = L[i] b = L[j] c = bisect.bisect_left(L,a+b) ans += c - j - 1 print(ans)
import bisect n = int(input()) l = list(map(int, input().split())) l.sort() ans = 0 for i in range(n-1): b = l[:i] c = l[i+1:] for j in b: ans += bisect.bisect_left(c, l[i] + j)#2番目の棒より短く(left), 一定以上の長さを持つ([i+1:]) print(ans)
1
171,713,525,633,078
null
294
294
n = int(input()) ans = -1 for k in range(n, 0, -1): if n == k * 108 // 100: ans = k break if ans > 0: print(ans) else: print(':(')
n = int(input()) mod = 10**9+7 def pow(n, num): s = num for i in range(1,n): s = s*num%mod return s print((pow(n,10) - 2*pow(n,9) + pow(n,8))%mod)
0
null
64,473,837,532,352
265
78
from sys import stdin input = stdin.readline from time import time from random import randint from copy import deepcopy start_time = time() def calcScore(t, s, c): scores = [0]*26 lasts = [0]*26 for i in range(1, len(t)): scores[t[i]] += s[i][t[i]] dif = i - lasts[t[i]] scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2 lasts[t[i]] = i for i in range(26): dif = len(t) - lasts[i] scores[i] -= c[i] * dif * (dif-1) // 2 return scores def greedy(c, s): day_lim = len(s) socres = [0]*26 t = [0]*day_lim lasts = [0]*26 for i in range(1, day_lim): pls = [v for v in socres] mns = [v for v in socres] for j in range(26): pls[j] += s[i][j] mns[j] -= c[j] * (i - lasts[j]) sum_mns = sum(mns) pt = sum_mns - mns[0] + pls[0] idx = 0 for j in range(1, 26): tmp = sum_mns - mns[j] + pls[j] if pt < tmp: pt = tmp idx = j t[i] = idx lasts[idx] = i for j in range(26): if j == idx: socres[j] = pls[j] else: socres[j] = mns[j] return socres, t def subGreedy(c, s, t, day): day_lim = len(s) socres = [0]*26 t = [0]*day_lim lasts = [0]*26 for i in range(1, day_lim): if day <= i: pls = [v for v in socres] mns = [v for v in socres] for j in range(26): pls[j] += s[i][j] mns[j] -= c[j] * (i - lasts[j]) sum_mns = sum(mns) pt = sum_mns - mns[0] + pls[0] idx = 0 for j in range(1, 26): tmp = sum_mns - mns[j] + pls[j] if pt < tmp: pt = tmp idx = j t[i] = idx lasts[idx] = i for j in range(26): if j == idx: socres[j] = pls[j] else: socres[j] = mns[j] else: scores[t[i]] += s[i][t[i]] lasts[t[i]] = i for j in range(26): dif = i - lasts[j] scores[j] -= c[j] * dif return socres, t D = int(input()) c = list(map(int, input().split())) s = [[0]*26 for _ in range(D+1)] for i in range(1, D+1): s[i] = list(map(int, input().split())) scores, t = greedy(c, s) sum_score = sum(scores) while time() - start_time < 1.86: typ = randint(1, 100) if typ <= 70: for _ in range(300): tmp_t = deepcopy(t) tmp_t[randint(1, D)] = randint(0, 25) tmp_scores = calcScore(tmp_t, s, c) sum_tmp_score = sum(tmp_scores) if sum_score < sum_tmp_score: sum_score = sum_tmp_score t = deepcopy(tmp_t) scores = deepcopy(tmp_scores) elif typ <= 98: for _ in range(100): tmp_t = deepcopy(t) dist = randint(1, 15) p = randint(1, D-dist) q = p + dist tmp_t[p], tmp_t[q] = tmp_t[q], tmp_t[p] tmp_scores = calcScore(tmp_t, s, c) sum_tmp_score = sum(tmp_scores) if sum_score < sum_tmp_score or randint(1, 100) <= 3: sum_score = sum_tmp_score t = deepcopy(tmp_t) scores = deepcopy(tmp_scores) elif typ <= 100: tmp_t = deepcopy(t) day = randint(D//4*3, D) tmp_scores, tmp_t = subGreedy(c, s, tmp_t, day) sum_tmp_score = sum(tmp_scores) if sum_score < sum_tmp_score: sum_score = sum_tmp_score t = deepcopy(tmp_t) scores = deepcopy(tmp_scores) for v in t[1:]: print(v+1)
# Aizu Problem ALDS_1_4_C: Dictionary import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") D = set() N = int(input()) for _ in range(N): cmd, string = input().split() if cmd == "insert": D.add(string) elif cmd == "find": print("yes" if string in D else "no")
0
null
4,843,863,301,500
113
23
N = int(input()) A = sorted(list(map(int,input().split())),reverse=True) ans = A[0] for i in range(1,N//2): ans += 2* A[i] if N%2 == 1: ans += A[N//2] print(ans)
#!/usr/bin/python3 # -*- coding:utf-8 -*- def main(): n = int(input()) la = list(map(int, input().strip().split())) la.sort(reverse=True) ans = sum(la[:(n+1)//2]) * 2 - la[0] - (la[(n+1)//2-1] if n%2==1 else 0) print(ans) if __name__=='__main__': main()
1
9,222,372,975,428
null
111
111
n,m = map(int,input().split()) x,y = map(int,input().split()) if n!=x: print(1) else: print(0)
x1,y1,x2,y2,t=map(int,input().split()) print((x2-x1)*60+(y2-y1)-t)
0
null
71,317,534,922,190
264
139
def arg(operator): try: return elements.index(operator) except: return 100000000000000 elements = [elem if elem in ['+', '-', '*'] else int(elem) for elem in input().split()] while len(elements) != 1: if arg('+') or arg('-') or arg('*'): i = arg('+') i = min(i, arg('-')) i = min(i, arg('*')) if elements[i] == '+': r = elements[i-2] + elements[i-1] elif elements[i] == '-': r = elements[i-2] - elements[i-1] elif elements[i] == '*': r = elements[i-2] * elements[i-1] # i, i-1, i-2 -> one element elements = elements[:i-2] + [r] + elements[i+1:] else: break print(elements[0])
N = int(input()) if N % 2 == 0: print("0.5") else: a = N // 2 + 1 print(a/N)
0
null
88,453,693,708,990
18
297
x = list(map(int, input().split())) if len(set(x))==2: kotae='Yes' else: kotae='No' print(kotae)
import math a, b, h, m = map(int, input().split()) theta_a = (60*h+m)/720*2*math.pi theta_b = m/60*2*math.pi theta_a_b = abs(theta_a-theta_b) ans = math.sqrt(a**2+b**2-2*a*b*math.cos(theta_a_b)) print(ans)
0
null
44,172,719,001,018
216
144
H = int(input()) W = int(input()) N = int(input()) cnt=wcnt=hcnt=0 while N>0: a = max(H-hcnt, W-wcnt) N -= a cnt+=1 if a==W: H-=1 hcnt+=1 elif a==H: W-=1 wcnt+=1 print(cnt)
input_list = [] for i in range(0, 3): input_list.append(int(input())) h = input_list[0] w = input_list[1] n = input_list[2] temp_num = 0 if w <= h: temp_num = h else: temp_num = w answer = 0 if n % temp_num == 0: answer = int(n / temp_num) else: answer = (n // temp_num) + 1 print(answer)
1
88,686,384,080,260
null
236
236
num=[] num=list(map(int,input().split())) for i in range(5): if num[i]==0: print(i+1) break else: continue
data = [int(x) for x in input().split(" ")] for i in range(len(data)): if data[i] == 0: print(i+1)
1
13,412,761,853,568
null
126
126
import bisect import math import sys from collections import Counter, defaultdict, deque from copy import copy, deepcopy from heapq import heapify, heappop, heappush from itertools import combinations, permutations from queue import Queue read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def SI(): return int(readline()) def MI(): return map(int, readline().split()) def MLI(): return map(int, open(0).read().split()) inf = float("inf") def check(k, P, W): count = 1 tmp_sum = 0 for w in W: if tmp_sum + w <= P: tmp_sum += w else: tmp_sum = w count += 1 if count <= k: return True else: return False def main(): n, k, *W = MLI() lb = max(W) ub = sum(W) while ub - lb > 1: P = (lb + ub) // 2 if check(k, P, W): ub = P else: lb = P if check(k, lb, W): print(lb) else: print(ub) if __name__ == "__main__": main()
n, k = map(int, input().split()) w = [int(input()) for _ in range(n)] # k台以内のトラックで運べる荷物の個数 # P: ひとつのトラックに積載できる最大量 def check(P): i = 0 for j in range(k): s = 0 while s + w[i] <= P: s += w[i] i += 1 if i == n: return n return i # 二部探索 left = 0 right = 100000 * 10000 while right - left > 1: mid = (left + right) // 2 v = check(mid) if v >= n: right = mid else: left = mid print(right)
1
91,924,815,852
null
24
24
N = int(input()) s = [0] * N t = [0] * N for i in range(N): s[i], t[i] = map(str, input().split()) for i in range(N): t[i] = int(t[i]) X = input() not_listened = False ans = 0 for i in range(N): if not_listened: ans += t[i] if s[i] == X: not_listened = True print(ans)
N=int(input()) p=[list(map(str,input().split())) for _ in range(N)] X=input() flag=0 cnt=0 for i in range(N): if flag==1: cnt=cnt+int(p[i][1]) if p[i][0]==X: flag=1 print(cnt)
1
97,042,971,360,034
null
243
243
c=str(input()) print('Yes' if c[2]==c[3] and c[4]==c[5] else'No')
import sys from functools import reduce def input(): return sys.stdin.readline()[:-1] a, b, c, d = map(int, input().split()) ans1 = a * c ans2 = b * d ans3 = b * c ans4 = a * d print(max([ans1, ans2, ans3, ans4]))
0
null
22,464,220,792,572
184
77
from itertools import combinations_with_replacement N, M, Q = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(Q)] ans = 0 for i in combinations_with_replacement(range(1, M+1), N): tmp = 0 for a, b, c, d in A: if i[b-1] - i[a-1] == c: tmp += d ans = max(ans, tmp) print(ans)
number=list(map(int,input().split())) n,m,q=number[0],number[1],number[2] nums=[] for i in range(q): tmp=list(map(int,input().split())) nums.append(tmp) answer=0 mid=0 List1=[] for i in range(m): List1.append(i) import itertools for i in list(itertools.combinations_with_replacement(List1,n)): mid=0 for j in range(q): if i[nums[j][1]-1]-i[nums[j][0]-1]==nums[j][2]: mid+=nums[j][3] answer=max(mid,answer) print(answer)
1
27,710,261,776,992
null
160
160
class Stack: def __init__(self): self.values = [] self.n = 0 def pop(self): if self.n == 0: raise Exception("stack underflow") else: v = self.values[-1] del self.values[-1] self.n -= 1 return v def push(self,x): self.values.append(x) self.n += 1 operators = set(['+', '-', '*']) stack = Stack() for op in raw_input().split(' '): if op in operators: b = stack.pop() a = stack.pop() if op == '+': stack.push(a+b) elif op == '-': stack.push(a-b) elif op == '*': stack.push(a*b) else: raise Exception("Unkown operator") else: stack.push(int(op)) print stack.pop()
# 2020/08/08 # AtCoder Beginner Contest 174 - A # Input n, a, b = map(int,input().split()) # Calc sa = abs(b - a) if sa % 2 == 0: ans = sa // 2 else: # B go Right and 1 lose bgr = n - b + 1 bgra = a + bgr rans = (n - bgra) // 2 + bgr # A go Left and 1 lose agl = a - 1 + 1 aglb = b - agl lans = (aglb - 1) // 2 + agl ans = min(rans, lans) # Output print(ans)
0
null
55,001,782,981,552
18
253
# 161 A X,Y,Z = list(map(int, input().split())) print(('{} {} {}').format(str(Z), str(X), str(Y)))
rate = int(input()) rank=8-((rate-400)//200) print((rank))
0
null
22,256,217,539,950
178
100
def main(n,k,a): for _ in range(k): b=[0]*(n+1) for i,j in enumerate(a): b[max(0,i-j)]+=1 b[min(n,i+j+1)]-=1 for i in range(n): b[i+1]+=b[i] if a==b:break a=b print(*a[:-1]) N,K,*A=map(int,open(0).read().split()) main(N,K,A)
n,t=map(int,input().split()) dp=[[-1 for j in range(2)] for i in range(t+1)] dp[0][0]=0 d=[] for i in range(n): d.append(list(map(int,input().split()))) d.sort() for i in range(n): for j in range(t,-1,-1): for k in range(1,-1,-1): if k==0: if dp[j][k]>=0 and j+d[i][0]<t: dp[j+d[i][0]][k]=max(dp[j+d[i][0]][k],dp[j][k]+d[i][1]) if k==1: if dp[j][0]>=0: dp[j][k]=max(dp[j][k],dp[j][0]+d[i][1]) ans=0 for i in range(t+1): for j in range(2): ans=max(ans,dp[i][j]) print(ans)
0
null
83,819,170,530,976
132
282
S = input() cnt = 0 for i,ch in enumerate(S): if cnt == 0: if ch == "R": cnt = 1 elif ch == "R" and S[i-1] == "R": cnt += 1 print(cnt)
def resolve(): s = input() print('x'*len(s)) resolve()
0
null
38,808,611,848,118
90
221
def solve(): S = input() if S[2] == S[3] and S[4] == S[5]: print("Yes") else: print("No") if __name__ == "__main__": solve()
# ABC160A def f(s): if s[2:3] == s[3:4] and s[4:5] == s[5:6]: print('Yes') else: print('No') s = input() f(s)
1
42,138,344,315,238
null
184
184
H, W = list(map(int, input().split())) while H != 0 or W != 0 : print('#' * W) for i in range(H-2) : print('#', end = '') print('.' * (W - 2), end = '') print('#') print('#' * W) print() H, W = list(map(int, input().split()))
H=1 W=1 while H!=0 or W!=0: H,W = [int(i) for i in input().split()] if H!=0 or W!=0: for i in range(W): print('#',end='') print() for i in range(H-2): print('#',end='') for j in range(W-2): print('.',end='') print('#',end='\n') for i in range(W): print('#',end='') print('\n')
1
807,494,747,108
null
50
50
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,a,b = map(int,input().split()) m = 10**9+7 def nCr(n_, r_, m_): c = min(r_ , n_ - r_) bunshi = 1 bunbo = 1 for i in range(1,c+1): bunshi = bunshi * (n_+1-i) % m_ bunbo = bunbo * i % m_ return bunshi * pow(bunbo, m_-2, m_) % m_ ans = pow(2,n,m)-1 ans -= nCr(n,a,m) ans %= m ans -= nCr(n,b,m) ans %= m print(ans)
0
null
43,513,293,553,280
145
214
def main(): a,b,c,k = list(map(int,input().split())) if k<=a: print(k) elif k<=a+b: print(a) elif k < a+b+c: print(a-(k-(a+b))) else: print(a-c) main()
n,m = map(int,input().split()) A = list(map(int,input().split())) s = sum(A) d = s * (1/(4*m)) t = sum(a >= d for a in A) print('Yes' if t >= m else 'No')
0
null
30,241,453,254,602
148
179
#16D8101014F Kurume Ryunosuke 久留米竜之介 2018/5/16 Python3 n = int(input()) box = set() for _ in range(n): tmp,mozi= input().split() if tmp == "find": if mozi in box: print("yes") else: print("no") else: box.add(mozi)
import sys n = int(input()) command = sys.stdin.readlines() Q = {} for i in range(n): a,b = command[i].split() if a == "insert": Q[b] = 0 else: if b in Q.keys(): print("yes") else: print("no")
1
76,792,526,480
null
23
23
a,b = input().split() if 500 * int(a) >= int(b): print('Yes') else: print('No')
from sys import stdin line = stdin.readline() input = [int(x) for x in line.rstrip().split()] if input[0] * 500 >= input[1]: print('Yes') else: print('No')
1
97,754,706,416,250
null
244
244
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))
a, b, h, m = map(int,input().split()) angle = 30*h - 5.5*m import math ans = (a*a + b*b - 2*a*b*math.cos(math.radians(angle)))**0.5 print(ans)
1
20,007,400,183,582
null
144
144
A, B, C = map(int, input().split()) print(C, A, B)
X,Y,Z = (int(X) for X in input().split()) Y,X = X,Y Z,X = X,Z print('{} {} {}'.format(X,Y,Z))
1
38,267,602,697,742
null
178
178
from collections import deque n, qt = map(int, input().split()) queue = deque() for i in range(n): name, time = input().split() queue.append([name, int(time)]) total_time = 0 while queue: q_t = queue.popleft() if q_t[1] <= qt: total_time += q_t[1] print(q_t[0], total_time) else: total_time += qt q_t[1] -= qt queue.append(q_t)
while(True): a=list(map(int,input().split())) if(a[0]==0 and a[1]==0): break for x in range(a[0]): if x==0 or x==a[0]-1: print("#"*a[1]) else: print("#"+"."*(a[1]-2)+"#") print()
0
null
427,529,010,522
19
50
from collections import Counter D = int(input()) c = list(map(int, input().split())) s = [] for i in range(D): temp_s = list(map(int, input().split())) s.append(temp_s) my_count = Counter() t = list(int(input()) for i in range(D)) c_sum = sum(c) my_sum = 0 my_minus = 0 for d in range(D): my_count [t[d]] = c[t[d] - 1] * (d + 1) my_sum += s[d][t[d] - 1] my_minus += sum(dict(my_count).values()) - c_sum * (d + 1) print(my_sum + my_minus)
a=int(input()) b='' for i in range(a): b=b+'ACL' print(b)
0
null
6,021,559,412,228
114
69
n,a,b=map(int,input().split()) mod=10**9+7 def modpow(a,n): if n<1: return 1 ans=modpow(a,n//2) ans=(ans*ans)%mod if n%2==1: ans*=a return ans%mod def cmb(n,i):#逆元 inv,ans=1,1 for j in range(1,i+1): ans=ans*(n-j+1)%mod inv=inv*j%mod return (ans*modpow(inv,mod-2))%mod ans_n=pow(2,n,mod)-1 ans_a=cmb(n,a)%mod ans_b=cmb(n,b)%mod print((ans_n-ans_a-ans_b)%mod)
s=input() d_in={'/':1,'\\':-1,'_':0} stack_h=[] pairs_x=[] for i in range(len(s)): if d_in[s[i]]==-1: stack_h.append(i) elif d_in[s[i]]==1: if len(stack_h)!=0: pairs_x.append([stack_h.pop(),i+1]) stack_ans=[] for i in range(len(pairs_x)): pair_i=pairs_x.pop() if len(stack_ans)==0: stack_ans.append(pair_i) elif pair_i[1]<=stack_ans[-1][0]: stack_ans.append(pair_i) area=[0]*len(stack_ans) sum_area=0 for i in range(len(stack_ans)): p=stack_ans.pop() h=0 for j in range(p[0],p[1]): area[i]+=h h-=d_in[s[j]] sum_area+=area[i] print(sum_area) if len(area)==0: print(0) else: print(len(area),end=' ') print(' '.join(map(str,area)))
0
null
33,277,611,138,482
214
21
from sys import stdin test = list(stdin.readline().rstrip()) result=0 for i in test: result = result + int(i) if (result % 9) == 0: print('Yes') else: print('No')
a =[] for i in range(3): a .append(list(map(int, input().split()))) n = int(input()) b =[] for i in range(n): b.append(int(input())) flag = 0 cnt = 0 # yoko for i in range(3): for j in range(3): if a[i][j] in b: cnt += 1 else: if cnt == 3: print("Yes") flag += 1 exit() else: cnt = 0 # tate if flag == 0: for i in range(3): for j in range(3): if a[j][i] in b: cnt += 1 else: if cnt == 3: print("Yes") flag += 1 exit() else: cnt = 0 # ななめ1 if flag == 0: for i in range(3): if a[i][i] in b: cnt += 1 else: if cnt == 3: print("Yes") flag += 1 exit() else: cnt = 0 # ななめ2 if flag == 0: if a[2][0] in b: if a[1][1] in b: if a[0][2] in b: print("Yes") flag += 1 if flag == 0: print("No")
0
null
32,140,046,585,920
87
207
from random import * D=int(input()) C=list(map(int,input().split())) S=[list(map(int,input().split())) for i in range(D)] X=[0]*26 XX=X[:] Y=X[:] YY=X[:] P=[] SC=0 N,M,L,O=0,0,0,0 for i in range(D): for j in range(26): X[j]+=C[j] XX[j]+=X[j] N,M=-1,-10**20 L,O=N,M for j in range(26): if Y==-1: N,M=0,X[0]+S[i][0] if M<X[j]+S[i][j]: L,O=N,M N,M=j,X[j]+S[i][j] elif O<X[j]+S[i][j]: L,O=j,X[j]+S[i][j] XX[N]-=X[N] X[N]=0 P.append([N,L]) SC+=X[N] SC2=0 for i in range(10**5): SC2=SC d,q=randrange(0,D),randrange(0,26) SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 elif randrange(0,10000)==0: if randrange(0,2): P[d][0]=q XX=YY[:] SC=SC2 else: P[d][1]=q for d in range(D): for q in range(26): SC2=SC SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 for i in range(10**5): SC2=SC d,q=randrange(0,D),randrange(0,26) SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 elif randrange(0,10000)==0: if randrange(0,2): P[d][0]=q XX=YY[:] SC=SC2 else: P[d][1]=q for d in range(D): for q in range(26): SC2=SC SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 for i in range(D): SC2=SC d,q=i,P[i][1] SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d]=P[d][::-1] XX=YY[:] SC=SC2 for i in range(D): print(P[i][0]+1)
from random import randint, random, seed from math import exp from time import time import sys input = sys.stdin.readline INF = 9223372036854775808 def calc_score(D, C, S, T): """ 開催日程Tを受け取ってそこまでのスコアを返す コンテストi 0-indexed d 0-indexed """ score = 0 last = [0]*26 # コンテストiを前回開催した日 for d, t in enumerate(T): last[t] = d + 1 for i in range(26): score -= (d + 1 - last[i]) * C[i] score += S[d][t] return score def update_score(D, C, S, T, score, ct, ci): """ ct日目のコンテストをコンテストciに変更する スコアを差分更新する ct: change t 変更日 0-indexed ci: change i 変更コンテスト 0-indexed """ new_score = score last = [0]*26 # コンテストiを前回開催した日 prei = T[ct] # 変更前に開催する予定だったコンテストi for d, t in enumerate(T, start=1): last[t] = d new_score += (d - last[prei])*C[prei] new_score += (d - last[ci])*C[ci] last = [0]*26 for d, t in enumerate(T, start=1): if d-1 == ct: last[ci] = d else: last[t] = d new_score -= (d - last[prei])*C[prei] new_score -= (d - last[ci])*C[ci] new_score -= S[ct][prei] new_score += S[ct][ci] return new_score def evaluate(D, C, S, T, k): """ d日目終了時点での満足度を計算し, d + k日目終了時点での満足度の減少も考慮する """ score = 0 last = [0]*26 for d, t in enumerate(T): last[t] = d + 1 for i in range(26): score -= (d + 1 - last[i]) * C[i] score += S[d][t] for d in range(len(T), min(len(T) + k, D)): for i in range(26): score -= (d + 1 - last[i]) * C[i] return score def greedy(D, C, S): Ts = [] for k in range(7, 9): T = [] # 0-indexed max_score = -INF for d in range(D): # d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する max_score = -INF best_i = 0 for i in range(26): T.append(i) score = evaluate(D, C, S, T, k) if max_score < score: max_score = score best_i = i T.pop() T.append(best_i) Ts.append((max_score, T)) return max(Ts, key=lambda pair: pair[0]) def local_search(D, C, S, score, T): sTime = time() T0 = 55e2 T1 = 9e2 TL = 1.96 Temp = T0 k = 0 e = 0 best_score = score best_T = T while e < 1.3: if k % 100 == 0: e = (time() - sTime) if e > TL: break t = e / TL Temp = pow(T0, 1-t) * pow(T1, t) sel = randint(1, 2+k//10000) if sel == 1: # ct 日目のコンテストをciに変更 ct = randint(0, D-1) ci = randint(0, 25) new_score = update_score(D, C, S, T, score, ct, ci) if score < new_score or \ (new_score > 4*10**6 + k*10000 and exp((score - new_score)/Temp) > 0.5): T[ct] = ci score = new_score else: # ct1 日目と ct2 日目のコンテストをswap ct1 = randint(0, D-1) ct2 = randint(0, D-1) ci1 = T[ct1] ci2 = T[ct2] new_score = update_score(D, C, S, T, score, ct1, ci2) new_score = update_score(D, C, S, T, new_score, ct2, ci1) if score < new_score or \ (new_score > 4*10**6 + k*10000 and exp((score - new_score)/Temp) > 0.5): score = new_score T[ct1] = ci2 T[ct2] = ci1 if best_score < score: best_score = score best_T = T k += 1 return best_T if __name__ == '__main__': seed(1) D = int(input()) C = [int(i) for i in input().split()] S = [[int(i) for i in input().split()] for j in range(D)] init_score, T = greedy(D, C, S) T = local_search(D, C, S, init_score, T) for t in T: print(t+1)
1
9,682,071,485,860
null
113
113
def solve(): num_lines = int(raw_input()) s = set() for i in xrange(num_lines): command, target = raw_input().split(" ") if command[0] == "i":# insert s.add(target) continue if target in s: print "yes" else: print "no" if __name__ == "__main__": solve()
def main(): n = int(input()) operation = [input().split() for _ in range(n)] dictionary = {} for command, char in operation: if command == "insert": dictionary[char] = True elif command == "find": try: if dictionary[char]: print("yes") except KeyError: print("no") return if __name__ == "__main__": main()
1
73,389,318,980
null
23
23
k = int(input()) num=[1,2,3,4,5,6,7,8,9] if k<10: print(num[k-1]) exit() ans=9 def hantei(): global ans ans+=1 if ans==k: print(num[-1]) exit() for i in range(10**10): hitoketa=num[0]%10 if hitoketa==0: num.append(10*num[0]+0) hantei() num.append(10*num[0]+1) hantei() num.pop(0) elif hitoketa==9: num.append(10*num[0]+8) hantei() num.append(10*num[0]+9) hantei() num.pop(0) else: num.append(10*num[0]+(hitoketa-1)) hantei() num.append(10*num[0]+(hitoketa)) hantei() num.append(10*num[0]+(hitoketa+1)) hantei() num.pop(0)
# -*- coding: utf-8 -*- import queue K = int(input()) q = queue.Queue() count = 0 for i in range(1, 10): q.put(i) a = 0 while count < K: a = q.get() fp = int(str(a)[-1]) if fp == 0: q.put(a*10) q.put(a*10 + 1) elif fp == 9: q.put(a*10 + 8) q.put(a*10 + 9) else: q.put(a*10 + fp - 1) q.put(a*10 + fp) q.put(a*10 + fp + 1) count += 1 print(a)
1
40,129,778,061,580
null
181
181
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) cnt = 1 def dfs(x): global cnt if s[x] == None: s[x] = cnt cnt += 1 for v in edges[x]: if s[v] == None: dfs(v) g[x] = cnt cnt += 1 return n = I() edges = [[] for _ in range(n)] for i in range(n): edges[i] = list(map(lambda x:x-1,LI()[2:])) s = [None]*n g = [None]*n for i in range(n): if s[i] == None: dfs(i) for i in range(n): print(i+1,s[i],g[i])
WHITE = 0 GRAY = 1 BLACK = 2 NIL = -1 def dfs(u): global time color[i] = GRAY time += 1 d[u] = time for v in range(n): if m[u][v] and (color[v] == WHITE): dfs(v) color[u] = BLACK time += 1 f[u] = time def next(u): for v in range(nt[u], n + 1): nt[u] = v + 1 if m[u][v]: return v return NIL n = int(input()) m = [[0 for i in range(n + 1)] for j in range(n + 1)] vid = [0] * n d = [0] * n f = [0] * n S = [] color = [WHITE] * n time = 0 nt = [0] * n tmp = [] for i in range(n): nums=list(map(int,input().split())) tmp.append(nums) vid[i] = nums[0] for i in range(n): for j in range(tmp[i][1]): m[i][vid.index(tmp[i][j + 2])] = 1 for i in range(n): if color[i] == WHITE: dfs(i) for i in range(n): print(vid[i], d[i], f[i])
1
2,791,287,030
null
8
8
K = int(input()) S = input() if len(S) <= K: print(S) else: print(S[0:K] + '...')
a=[] n = int(input()) s = input().rstrip().split(" ") for i in range(n): a.append(int(s[i])) a=a[::-1] for i in range(n-1): print(a[i],end=' ' ) print(a[n-1])
0
null
10,334,974,261,624
143
53
mod = 10 ** 9 + 7 n, k = map(int, input().split()) binomial = [1] cum = 1 for i in range(1, n + 2): cum *= i cum = cum % mod binomial.append(cum) inv = [] tmp = pow(cum, mod - 2, mod) inv.append(tmp) for j in range(n + 1, 0, -1): tmp = j * tmp % mod inv.append(tmp) inv.reverse() def comb(n, k): return binomial[n] * inv[n - k] % mod * inv[k] % mod if n >= k else 0 k = min(k, n - 1) ans = 0 for m in range(k + 1): tmp = comb(n, m) * binomial[n - 1] * inv[n - 1 - m] * inv[m] ans += tmp % mod ans %= mod print(ans)
import itertools import functools import math def OK(): N = int(input()) sum = 0 cnt = 0 for i in range(1,N+1): for j in range(1,N+1): chk = math.gcd(i,j) for k in range(1,N+1): sum += math.gcd(chk,k) print(sum) OK()
0
null
51,465,812,357,450
215
174
N = int(input()) if (N - 1) % 2 == 0: a = (N-1) / 2 print(int(a)) else: b = N / 2 - 1 print(int(b))
from bisect import bisect_left from itertools import accumulate n, m = map(int, input().split()) hands = [int(x) for x in input().split()] increasing = sorted(hands) hands = list(reversed(increasing)) xs = [0] + list(accumulate(hands)) max_x = 2 * 10**5 + 1 min_x = 0 def canGet(x): count = 0 for hand in increasing: idx = bisect_left(increasing, x-hand) count += n - idx return count >= m while max_x - min_x > 1: # left mid = (max_x + min_x) // 2 if canGet(mid): min_x = mid else: max_x = mid ans = 0 count = 0 for Ai in hands: idx = bisect_left(increasing, min_x-Ai) ans += Ai*(n-idx) + xs[n-idx] count += n-idx print(ans-(count-m)*min_x)
0
null
130,681,942,657,782
283
252
a, b = map(float, input().split()) print(int(a)*int(b*100+0.5)//100)
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 X,Y=MI() N3=X+Y if N3%3!=0: print(0) exit() N=N3//3 a=0 b=0 for i in range(N+1): if 2*i + (N-i) == X: a=i b=N-i break if a==0 and b==0: print(0) exit() fact=[1,1] factinv=[1,1] inv=[0,1] for i in range(2, N + 5): fact.append((fact[-1] * i) % mod) inv.append((-inv[mod % i] * (mod // i)) % mod) factinv.append((factinv[-1] * inv[-1]) % mod) ans=fact[N]*factinv[a]*factinv[b] print(ans%mod) main()
0
null
83,149,871,058,848
135
281
N, M = [int(x) for x in input().split()] P = [0] * (N + 1) #各問題のペナルティの回数を記録 ok = [False] * (N + 1) #その問題でACが出たかどうか記録 correct = 0 #正答数を記録 penalty = 0 #ペナルティ数を記録 for i in range(M): query = input().split() p = int(query[0]) S = query[1] if ok[p] == False: if S == 'AC': ok[p] = True correct += 1 penalty += P[p] else: # S = 'WA' P[p] += 1 print(correct, end=' ') print(penalty)
n,m = map(int,input().split()) if m != 0: l = [list(input().split()) for i in range(m)] p,s = [list(i) for i in zip(*l)] t = [0] * n ac = 0 wa = 0 for i in range(m): if s[i] == 'WA' and t[int(p[i])-1] != 'AC': t[int(p[i])-1] += 1 elif s[i] == 'AC' and t[int(p[i])-1] != 'AC': ac += 1 wa += t[int(p[i])-1] t[int(p[i])-1] = 'AC' else: pass print(ac,wa)
1
93,261,547,316,608
null
240
240
import sys import copy #import math #import itertools #import numpy as np #import re def func(x,m): return x**2%m N,X,M=[int(c) for c in input().split()] myset = {X} mydict = {X:0} A = [] A.append(X) s = X i = 0 i_stop = i #i=0は計算したので1から for i in range(1,N): A.append(func(A[i-1],M)) if A[i] in myset: i_stop = i break myset.add(A[i]) mydict[A[i]] = i s+=A[i] if i == N-1: print(s) sys.exit(0) if A[i] == 0: print(s) sys.exit(0) if i!=0: #最後にA[i]が出現したのは? A_repeat = A[mydict[A[i_stop]]:i_stop] s+=((N-1)-(i_stop-1))//len(A_repeat)*sum(A_repeat) for k in range(((N-1)-(i_stop-1))%len(A_repeat)): s+=A_repeat[k] print(s)
from fractions import gcd N=int(input()) A=list(map(int, input().split())) p=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) % p) inv.append((-inv[p % i] * (p // i)) % p) #factinv.append((factinv[-1] * inv[-1]) % p) #a//gcd(a,b)*b def lcm(a,b): g=gcd(a,b) #return ((a*b)*pow(g,p-2,p))%p return a//gcd(a,b)*b LCM=1 for x in A: LCM=lcm(LCM,x) #print(LCM) ans=0 LCM%=p for i in range(N): ans+=(LCM*inv[A[i]])%p #ans+=(LCM*pow(A[i],p-2,p))%p ans%=p print(ans)
0
null
45,078,165,794,656
75
235
n= int(input()) A = list(map(int, input().split())) q = int(input()) Mi = map(int, input().split()) PS={} def solve(i,m): if m == 0: return True if (i,m) in PS: return PS[(i,m)] if i >= n: return False res = solve(i+1, m) or solve(i + 1, m - A[i]) PS[(i,m)] = res return res for m in Mi: if solve(0, m): print("yes") else: print("no")
def solve(pos, tot, A): if tot == 0: return True if pos > len(A) - 1: return False return solve(pos+1, tot - A[pos], A) or \ solve(pos+1, tot, A) n = raw_input() b = map(int, raw_input().split()) n = raw_input() t = map(int, raw_input().split()) max = sum(b) + 1 for tt in t: print 'yes' if tt < max and True == solve(0, tt, b) else 'no'
1
100,382,306,190
null
25
25