code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
N = int(input()) for x in range(N+1): if int(x*1.08) == N: print(x) break else: print(':(')
N=int(input()) for i in range(N+1): if int(i*1.08)==N: print(i) break if all(int(i*1.08)!=N for i in range(N+1))==True: print(":(")
1
125,259,811,556,400
null
265
265
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n = I() a = LI() dic = collections.Counter(a) als = 0 exl = [0 for _ in range(n+1)] for key, value in dic.items(): if value >= 3: choice = (value)*(value-1)//2 choice1 = (value-1)*(value-2)//2 als += choice exl[key] = choice1 - choice elif value == 2: choice = (value)*(value-1)//2 als += choice exl[key] = -choice for ball in a: choices = als + exl[ball] print(choices) main()
n = int(input()) a = [int(x) for x in input().split()] deta = [0] * (n+1) for i in a: deta[i] += 1 ans = [0] * (n+1) for j in range(n+1): if deta[j] > 1: ans[j] = deta[j]*(deta[j]-1)/2 else : ans[j] = 0 add = sum(ans) for k in a: print(int(add - deta[k]*(deta[k]-1)/2 + (deta[k]-1)*(deta[k]-2)/2))
1
47,920,216,315,586
null
192
192
a,b,c=input().split() if a==b and a!=c: print("Yes") elif a==c and a!=b: print("Yes") elif b==c and a!=b: print("Yes") else: print("No")
class UF(): def __init__(self, N): self.par = [-1] * N def union(self, x, y): p1,p2 = self.find(x), self.find(y) if p1 == p2: return if self.par[p1] > self.par[p2]: p1,p2 = p2,p1 self.par[p1] += self.par[p2] self.par[p2] = p1 def find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def size(self, x): return -self.par[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) N,M,K = map(int,input().split()) uf = UF(N) adj = [ [] for _ in range(N)] for _ in range(M): u,v = map(int,input().split()) u -= 1 v -= 1 adj[u].append(v) adj[v].append(u) uf.union(u,v) res = [] for n in range(N): res.append(uf.size(n) - 1 - len(adj[n])) for _ in range(K): u,v = map(int,input().split()) u -= 1 v -= 1 if uf.same(u,v): res[u] -= 1 res[v] -= 1 print(" ".join(map(str, res)))
0
null
64,758,043,224,170
216
209
n = input() data = [] space = [] for i in ['S ', 'H ', 'C ', 'D ']: for j in map( str , xrange(1, 14)): data.append(i + j) for i in xrange(n): data.remove(raw_input()) for i in xrange(len(data)): print data[i]
# E - Bullet from collections import Counter from math import gcd n = int(input()) counter = Counter() # 各ベクトルの個数 for i in range(n): a, b = map(int, input().split()) if b < 0: a, b = -a, -b # 180度回転して第1〜2象限に elif b == 0: a = abs(a) if not a == b == 0: # 既約化 g = gcd(a, b) a //= g b //= g counter[(a, b)] += 1 modulus = 1000000007 vs = set(counter) # 第2象限のベクトルと直交するベクトルを追加 vs.update((b, -a) for a, b in counter if a <= 0) # 第1象限のベクトルのみ抽出 vs = [(a, b) for a, b in vs if a > 0] ncomb = 1 # イワシの選び方の個数 for a, b in vs: # 互いに仲が悪いイワシ群 n1 = counter[(a, b)] n2 = counter[(-b, a)] # それぞれの群から好きな数だけイワシを選ぶ (0匹選ぶことも含む) m = pow(2, n1, modulus) + pow(2, n2, modulus) - 1 ncomb = ncomb * m % modulus ncomb -= 1 # 1匹も選ばない場合を除く # (0, 0)のイワシを1匹だけ選ぶ ncomb += counter[(0, 0)] print(ncomb % modulus)
0
null
10,913,164,608,720
54
146
from itertools import combinations_with_replacement as H N, M, Q = map(int, input().split()) ans = 0 query = [list(map(int, input().split())) for _ in range(Q)] for A in H(list(range(1, M+1)), N): acc = 0 for j in range(Q): a, b, c, d = query[j] if A[b - 1] - A[a - 1] == c: acc += d ans = max(ans, acc) print(ans)
import sys read = sys.stdin.read readlines = sys.stdin.readlines from itertools import combinations_with_replacement def main(): n, m, q = map(int, input().split()) qs = [] for _ in range(q): abcd = tuple(map(int, input().split())) qs.append(abcd) A = tuple(combinations_with_replacement(range(1, m+1), n)) r = 0 for Ae in A: t0 = 0 for qe in qs: if Ae[qe[1]-1] - Ae[qe[0]-1] == qe[2]: t0 += qe[3] r = max(r, t0) print(r) if __name__ == '__main__': main()
1
27,618,653,488,010
null
160
160
from collections import deque def bfs(s): que = deque([(s, 0)]) dist = [None]*n while que: cur, cst = que.popleft() if dist[cur] != None: continue dist[cur] = cst for nxt in es[cur]: que.append((nxt, cst+1)) return dist n,u,v = map(int,input().split()) es = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) es[a-1].append(b-1) es[b-1].append(a-1) dist_u = bfs(u-1) dist_v = bfs(v-1) ans = 0 for i in range(n): if dist_v[i]-dist_u[i] >= 1: ans = max(ans, dist_v[i]) print(max(0, ans-1))
import sys # import re import math import collections # import decimal import bisect import itertools import fractions # import functools import copy # import heapq import decimal # import statistics import queue # import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): n, u, v = ns() edge = [[] for _ in range(n)] for _ in range(n - 1): a, b = ns() a -= 1 b -= 1 edge[a].append(b) edge[b].append(a) dist_takahashi = [-1] * n dist_aoki = [-1] * n def bfs(pos, dist): que = queue.Queue() que.put(pos) dist[pos] = 0 while not que.empty(): current = que.get() for e in edge[current]: if dist[e] == -1: dist[e] = dist[current] + 1 que.put(e) return dist dist_takahashi = bfs(u - 1, dist_takahashi) dist_aoki = bfs(v - 1, dist_aoki) ans = 0 for dt, da in zip(dist_takahashi, dist_aoki): if dt < da: ans = max(ans, da - 1) print(ans) if __name__ == '__main__': main()
1
117,745,903,366,720
null
259
259
x=input() x=x**3 print x
x = input() n = int(x) print(n*n*n)
1
273,028,711,420
null
35
35
#!/usr/bin/env python def main(): t = input() t_list = ['D'] cnt = 0 for s in t: if s == '?': cnt += 1 else: if cnt > 0: t_list.append(cnt) cnt = 0 t_list.append(s) if cnt > 0: t_list.append(cnt) t_list.append('P') for i in range(len(t_list)): if isinstance(t_list[i], int): k = t_list[i] // 2 if t_list[i] % 2 == 0: if t_list[i-1] == 'P': t_list[i] = 'D' + 'PD' * (k-1) if t_list[i+1] == 'P': t_list[i] += 'D' else: t_list[i] += 'P' else: t_list[i] = 'PD' * k else: if t_list[i-1] == 'P': t_list[i] = 'D' + 'PD' * k else: t_list[i] = 'PD' * k if t_list[i+1] == 'P': t_list[i] += 'D' else: t_list[i] += 'P' print(''.join(t_list[1:-1])) if __name__ == '__main__': main()
t=list(input()) if t[0]=='?': t[0]=t[0].replace('?','D') for i in range(1,len(t)-1): if t[i]=='?' and t[i+1]=='D' and t[i-1]=='P': t[i]=t[i].replace('?','D') elif t[i]=='?' and t[i+1]=='P' and t[i-1]=='P': t[i]=t[i].replace('?','D') elif t[i]=='?' and t[i+1]=='D' and t[i-1]=='D': t[i]=t[i].replace('?','P') elif t[i]=='?' and t[i+1]=='P' and t[i-1]=='D': t[i]=t[i].replace('?','D') elif t[i]=='?' and t[i+1]=='?' and t[i-1]=='D': t[i]=t[i].replace('?','P') elif t[i]=='?' and t[i+1]=='?' and t[i-1]=='P': t[i]=t[i].replace('?','D') if t[-1]=='?': t[-1]=t[-1].replace('?','D') for i in t: print(i,end='')
1
18,620,089,910,242
null
140
140
def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) from collections import deque def main(): mod=10**9+7 S=input() from collections import deque dq=deque() for c in S: dq.appendleft(c) rev=0 Q=I() for _ in range(Q): q=input().split() if q[0]=="1": rev=(rev+1)%2 else: f=int(q[1]) c=q[2] if (rev+f)%2==1: dq.append(c) else: dq.appendleft(c) ans=[] if rev: while dq: ans.append(dq.popleft()) else: while dq: ans.append(dq.pop()) print(''.join(map(str, ans))) main()
from collections import deque s = input() Q = int(input()) que = deque(s) cnt = 0 for i in range(Q): q = input().split() if q[0] == '1': cnt += 1 else: reverse = cnt % 2 if q[1] == '1': if reverse == 0: s = que.appendleft(q[2]) else: s = que.append(q[2]) else: if reverse == 0: s = que.append(q[2]) else: s = que.appendleft(q[2]) ans = ''.join(que) if cnt % 2 == 0: print(ans) else: print(ans[::-1])
1
57,552,805,107,656
null
204
204
import sys def main(): input = sys.stdin.buffer.readline a, b, c = map(int, input().split()) if len(set([a, b, c])) == 2: print("Yes") else: print("No") if __name__ == "__main__": main()
A,B,C = map(int,input().split()) if A == B: if A != C: print("Yes") else: print("No") else: if B == C or A == C: print("Yes") else: print("No")
1
68,134,767,859,090
null
216
216
N=int(input()) S=input() indices = list(map(ord, S)) indices2 = [] for idx in indices: if idx + N > 90: indices2.append(idx - 26 + N) else: indices2.append(idx + N) S2 = list(map(chr,indices2)) print(''.join(S2))
a = list(map(int,input().split())) b = list(map(int,input().split())) if a[0]<= sum(b): print("Yes") else: print("No")
0
null
106,342,105,859,356
271
226
nk=input().split() n=int(nk[0]) k=int(nk[1]) data=list(map(int,input().split())) data.sort() s=0 for i in range(k): s += data[i] print(s)
N, M = map(int, input().split()) import math print(math.comb(N, 2)+math.comb(M, 2))
0
null
28,493,373,197,500
120
189
from sys import exit import math import collections ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) s = input() cnt = 0 for i in range(len(s)//2): if s[i] != s[-1-i]: cnt += 1 print(cnt)
a, b = map(int, input().split()) print((a * b) if 0 < a < 10 and 0 < b < 10 else -1)
0
null
139,285,719,277,988
261
286
import sys # input = sys.stdin.readline def main(): N = int(input()) d = list(map(int,input().split())) ans = 0 for i in range(N): for j in range(N): if i !=j: ans += d[i]*d[j] print(int(ans/2)) if __name__ == "__main__": main()
n=int(input()) s=input() l=[] for i in s: x=(ord(i)-65+n)%26 y=chr(65+x) l.append(y) print(''.join(l))
0
null
151,319,154,916,892
292
271
n = int(input()) a = list(map(int, input().split())) for v in a: if v % 2 == 0: if not (v % 3 == 0 or v % 5 == 0): print("DENIED") exit() print("APPROVED")
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split())) ans = "APPROVED" for a in A: if a % 2 == 0: if a % 3 == 0 or a % 5 == 0: pass else: ans = "DENIED" break print(ans)
1
69,253,939,312,256
null
217
217
s = input() n = len(s) for i in range(n//2): if s[i]!=s[n-i-1] : print("No") exit() n1 = (n-1)//2 for i in range(n1//2): if s[i]!=s[n1-i-1] : print("No") exit() n2 = (n+3)//2 for i in range(n-n2): if s[i]!=s[n-i-1] : print("No") exit() print("Yes")
w,h=map(int,input().split()) print("{} {}".format(w*h, (w+h)*2))
0
null
23,348,651,652,480
190
36
s,w = (int(x) for x in input().split()) if s <= w: print("unsafe") else: print("safe")
import math def fact(n): ans = 1 for i in range(2, n+1): ans*= i return ans def comb(n, c): return fact(n)//(fact(n-c)*c) s,w = map(int, input().split()) if(s >w): print('safe') else: print('unsafe')
1
29,034,070,829,712
null
163
163
x1,x2,x3,x4,x5 = map(int,input().split()) P=[x1,x2,x3,x4,x5] for i in range(5): if P[i]==0: print(str(i+1)) else: continue
import sys input = sys.stdin.readline lst = list(map(int, input().split())) for i in range(len(lst)): if lst[i] == 0: print(i+1)
1
13,429,848,128,960
null
126
126
a,b=input().split();print([b*int(a),a*int(b)][a<b])
N = int(input()) A = [int(i) for i in input().split()] def bubbleSort(A, N): count = 0 flag = 1 while flag: flag = 0 for i in range(N-1, 0, -1): if A[i] < A[i-1]: tmp = A[i] A[i] = A[i-1] A[i-1] = tmp flag = 1 count += 1 return A, count A, count = bubbleSort(A, N) print(' '.join([str(i) for i in A])) print(count)
0
null
42,207,090,126,012
232
14
N = int(input()) S, T = map(str, input().split()) S = list(S) T = list(T) ANS = [] for i in range(N): ANS.append(S[i]) ANS.append(T[i]) ANS = ''.join(ANS) print(ANS)
from heapq import heappop, heappush X, Y, A, B, C = map(int, input().split()) h = [] for p in map(int, input().split()): heappush(h, (-p, 1)) for q in map(int, input().split()): heappush(h, (-q, 2)) for r in map(int, input().split()): heappush(h, (-r, 3)) ans = 0 cnt = 0 total = X + Y while cnt < total: point, color = heappop(h) if color == 1: if X > 0: ans += -point X -= 1 cnt += 1 elif color == 2: if Y > 0: ans += -point Y -= 1 cnt += 1 elif color == 3: ans += -point cnt += 1 print(ans)
0
null
78,237,748,874,968
255
188
def gcd(a,b): if b == 1: return 1 elif b == 0: return a else: return gcd(b,a%b) a,b = map(int, raw_input().split(' ')) if a > b: print gcd(a,b) else: print gcd(b,a)
x,y=map(int,input().split()) a=1 while a!=0: if x>y: a=x%y else: a=y%x x=y y=a print(x)
1
7,942,351,900
null
11
11
S = int(input()) MOD = 10 ** 9 + 7 DP = [0] * (S+1) DP[0] = 1 for i in range(S): for nex in range(i+3, S+1): DP[nex] += DP[i] DP[nex] %= MOD print(DP[S] % MOD)
S = int(input()) mod = 10**9+7 dp = [0 for _ in range(S+1)] dp[0] = 1 for i in range(3, S+1): dp[i] = dp[i-1]+dp[i-3] dp[i] = dp[i]%mod print(dp[-1])
1
3,263,660,718,652
null
79
79
ans = [] while True: arr = map(int, raw_input().split()) if arr[0] == 0 and arr[1] == 0: break else: arr.sort() ans.append(arr) for x in ans: print(" ".join(map(str, x)))
# coding: utf-8 while True: x, y = map(int, input().split()) if x == 0 and y == 0: exit() elif x < y: print(x, y) else: print(y, x)
1
510,165,802,272
null
43
43
def divisor(i): s = [] for j in range(1, int(i ** (1 / 2)) + 1): if i % j == 0: s.append(i // j) s.append(j) return sorted(set(s)) n = int(input()) ans = 0 d = divisor(n) d.pop(0) for i in d: x = n while True: if not x % i == 0: break x //= i if x % i == 1: ans += 1 d = divisor(n - 1) ans += len(d) ans -= 1 print(ans)
n = int(input()) from collections import defaultdict dic = defaultdict(int) for _ in range(n): tmp = input() dic[tmp] += 1 print(len(dic))
0
null
35,830,206,274,990
183
165
a,b,n = map(int,input().split()) k = max(0,(n - b + 1) // b) k = min(n,k * b + b - 1) print((a * k) // b - a * (k // b))
from math import floor A,B,N=map(int,input().split()) ans=A*(B-1)//B if N<B: ans=A*N//B print(ans)
1
28,075,279,609,212
null
161
161
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: print('Yes' if b else 'No') YESNO=lambda b: print('YES' if b else 'NO') def main(): N,M=map(int,input().split()) c=list(map(int,input().split())) dp=[[INF]*10**6 for _ in range(M+1)] dp[0][0]=0 ans=INF for i in range(M): for money in range(N+1): dp[i+1][money]=min(dp[i+1][money],dp[i][money]) if money-c[i]>=0: dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1) print(dp[M][N]) if __name__ == '__main__': main()
N = int(input()) memolist = [-1]*(N+1) def fib(x): if memolist[x] == -1: if x == 0 or x == 1: memolist[x] = 1 else: memolist[x] = fib(x - 1) + fib(x - 2) return memolist[x] print(fib(N))
0
null
71,951,074,032
28
7
N = int(input()) A = list(map(int, input().split())) ans = 'APPROVED' for i in range(0,N): if (A[i]%2)==0: if not ((A[i] % 3) == 0 or (A[i] % 5) == 0): ans = 'DENIED' break print(ans)
def main(): N = int(input()) A = list(map(int, input().split())) for i in range(N): if A[i] % 2 == 0 and (A[i] % 3 != 0 and A[i] % 5 != 0): return "DENIED" return "APPROVED" if __name__ == '__main__': print(main())
1
68,824,352,307,302
null
217
217
import math a,b,h,m = map(int,input().split()) h_s = 360*h/12+30*m/60 m_s = 360*m/60 s = abs(h_s - m_s) print(abs(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(s)))))
n,m,k = map(int,input().split()) 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 mod = 998244353 #出力の制限 N = n #Nの最大値 g1 = [0]*(N+1) #元テーブル(p(n,r)) g1[0] = g1[1] = 1 g2 = [0]*(N+1) #逆元テーブル g2[0] = g2[1] = 1 inverse = [0]*(N+1) #逆元テーブル計算用テーブル inverse[0],inverse[1] = 0,1 for i in range(2,N+1): g1[i] = (g1[i-1] * i) % mod inverse[i] = (-inverse[mod % i] * (mod//i)) % mod g2[i] = (g2[i-1] * inverse[i]) % mod # i組 -> m * (n-1)Ci * (m-1)^(n-1-i) ans = 0 for i in range(k+1): ans += m * cmb(n-1,i,mod) * pow(m-1,n-1-i,mod) ans %= mod print(ans)
0
null
21,483,314,381,188
144
151
# coding: utf-8 s = input() print("x" * len(s))
s = input() lenth = len(s) print("x"*lenth)
1
73,175,522,731,212
null
221
221
s = input() t = input() ans = [] for i in range(0, len(s) - len(t) + 1): score = 0 # sをtと同じ文字列分、切り取る u = s[i:i + len(t)] for j in range(len(t)): # 切り取った文字列のsとtが同じかどうか比較する if u[j] != t[j]: score += 1 ans.append(score) print(min(ans))
s=input() t=input() ans=int(len(s)) for i in range(len(s)-len(t)+1): now=int(0) for j in range(len(t)): if s[i+j]!=t[j]: now+=1 ans=min(now,ans) print(ans)
1
3,696,835,062,460
null
82
82
n, k = map(int, input().split()) r, s, p = map(int, input().split()) t = input() me = "" ans = 0 for i in range(n): if t[i] == "r": if i < k: me += "p" ans += p elif me[i-k] != "p": me += "p" ans += p else: if t[i-k] == "p": me += "p" ans += p else: me += "r" elif t[i] == "s": if i < k: me += "r" ans += r elif me[i-k] != "r": me += "r" ans += r else: if t[i-k] == "r": me += "r" ans += r else: me += "s" else: if i < k: me += "s" ans += s elif me[i-k] != "s": me += "s" ans += s else: if t[i-k] == "s": me += "s" ans += s else: me += "p" print(ans)
#153-A H,A = map(int,input().split()) if H % A == 0: print(H // A) else: print( H//A +1)
0
null
91,994,861,579,180
251
225
#float型を許すな #numpyはpythonで import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI2(): return [int(input()) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf = 10**17 mod = 10**9 + 7 def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a // gcd(a, b) * b #print(lcm(lcm(1000000,999999),999998)) #print(999998//2*999999) #print(1000000*999999*999998%mod) n=I() lis=LI() promod=1 LCM=1 for i in range(n): LCM=lcm(lis[i],LCM) #print(LCM) for i in range(n): promod=(promod*(lis[i]%mod))%mod smmod=0 for i in range(n): smmod=(smmod+promod*pow(lis[i],mod-2,mod))%mod #print(smmod) x=(promod*pow(LCM%mod,mod-2,mod))%mod ans=(smmod*pow(x,mod-2,mod))%mod print(ans)
from fractions import gcd import sys input = sys.stdin.buffer.readline mod = 10 ** 9 + 7 def modinv(a, mod): return pow(a, mod - 2, mod) n = int(input()) if n == 1: print(1) exit() A = list(map(int, input().split())) lcm = A[0] for i in range(n): g = gcd(lcm, A[i]) lcm *= A[i] // g ans = 0 for i in range(n): gyaku = modinv(A[i], mod) ans += lcm * gyaku ans %= mod print(ans)
1
87,582,316,605,620
null
235
235
def backtrack(nums, N, cur_state, result): if len(cur_state) == N: result.append(cur_state[:]) else: for i in range(len(nums)): cur_state.append(nums[i]) backtrack(nums[i:], N, cur_state, result) cur_state.pop() def solve(): N,M,Q = [int(i) for i in input().split()] quads = [] for i in range(Q): quads.append([int(i) for i in input().split()]) candidates = [] backtrack(list(range(1, M+1)), N, [], candidates) ans = 0 for candidate in candidates: score = 0 for a,b,c,d in quads: if candidate[b-1] - candidate[a-1] == c: score += d ans = max(score, ans) print(ans) if __name__ == "__main__": solve()
x = int(input()) money1 = x // 500 x %= 500 money2 = x // 5 ans = money1 * 1000 + money2 * 5 print(ans)
0
null
35,152,389,922,970
160
185
n = int(input()) xpy = [] xmy = [] for i in range(n): x,y = map(int,input().split()) xpy.append(x+y) xmy.append(x-y) xpy.sort() xmy.sort() print(max(abs(xpy[0]-xpy[-1]),abs(xmy[0]-xmy[-1])))
import math n = int(raw_input()) debt = 100000 for i in range(n): debt = int(math.ceil(debt * 1.05 / 1000)) * 1000 print debt
0
null
1,682,756,674,468
80
6
list = list(map(int, input().split())) list_num=set(list) if len(list_num)==2: print('Yes') else: print('No')
a,b,c=map(int,input().split()) if a==b==c or (a!=b!=c and a!=c!=b): print("No") else: print("Yes")
1
68,134,963,920,130
null
216
216
N=int(input()) for i in range(1,10): for j in range(1,10): if i*j==N: print("Yes") break else: continue break else: print("No")
def main(): n = int(input()) cnt = 0 # aが1からn-1まで動くと考える for a in range(1, n): # a*bがn-1以下であると考える cnt += (n-1) // a print(cnt) if __name__ == '__main__': main()
0
null
81,485,907,158,588
287
73
def insertion_sort(A, N): yield A for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: # 右にずらす A[j + 1] = A[j] j -= 1 A[j + 1] = v yield A N = int(input()) A = list(map(int, input().split())) for li in insertion_sort(A, N): print(*li)
def main(): n = input() m = int(n[-1]) hon = [2, 4, 5, 7, 9] pon = [0, 1, 6, 8] if m in hon: print('hon') elif m in pon: print('pon') else: print('bon') if __name__ == '__main__': main()
0
null
9,649,006,900,640
10
142
N=int(input()) print(-N%1000)
n=int(input()) print((n+999)//1000*1000-n)
1
8,403,547,880,752
null
108
108
N,A,B = map(int,input().split()) if N % (A+B) > A: C = A elif N % (A+B) <= A: C = N % (A+B) print((N//(A+B))*A + C)
N, A, B = map(int, input().split()) a = N//(A+B) b = N%(A+B) if b > A: b = A ans = a*A + b print(ans)
1
55,292,693,086,400
null
202
202
# -*- coding: utf-8 -*- def main(): s = input() t = s[::-1] n = len(s) // 2 count = 0 for i in range(n): if s[i] != t[i]: count += 1 print(count) if __name__ == '__main__': main()
#coding: Shift_JIS def set_array(a,n): str=input() array=str.split() for i in range(n): a.append(int(array[i])) n=int(input()) S=[] set_array(S,n) q=int(input()) T=[] set_array(T,q) C=0 def linear_search(S,x): S.append(x) l=len(S) i=0 while(l>i): if S[i]==x: break i=i+1 S.pop(-1) if i!=l-1: return 1; else: return 0; for v in T: C+=linear_search(S,v) print(C)
0
null
59,879,971,756,832
261
22
s = input() cs = list(s) for c in cs: if c.islower(): print(c.upper(),end="") else : print(c.lower(),end="") print()
S = input() Slist = list(S) big = ord('A') small = ord('a') diff = big-small for i in range(len(Slist)): w = ord(Slist[i]) if small <= w: #?°????????????? Slist[i] = chr(w+diff) elif big <= w: Slist[i] = chr(w-diff) print(''.join(Slist))
1
1,522,901,712,010
null
61
61
import sys stdin = sys.stdin def ni(): return int(ns()) def na(): return list(map(int, stdin.readline().split())) def naa(N): return [na() for _ in range(N)] def ns(): return stdin.readline().rstrip() # ignore trailing spaces A, B = na() print(A * B)
a = input() b, c, d = [int(x) for x in a.split()] x = [x for x in range(b, c + 1) if x % d == 0] print(len(x))
0
null
11,750,888,274,972
133
104
import sys def main(): lines = sys.stdin.readlines() input_num = 0 ans = [] for line in lines: # print(line) # rm '\n' from string of a line line = line.strip('\n') input_num = int(line) n = input_num # print input_num print "", index_num = 1 flag = 0 while True: # END CHECKNUM if index_num != 1 or flag == 1: if (index_num + 1) > n: break else: index_num += 1 # Go on below else: flag = 1 x = index_num if x % 3 == 0: print index_num, continue if x % 10 == 3: print index_num, continue else: while x > 0: x /= 10 if x % 10 == 3: print index_num, break break if __name__ == "__main__": main()
k = int(input()) def call(m: int) -> str: result = "" for i in range(1, m + 1): if i % 3 == 0 or '3' in str(i): result += " " + str(i) return result print(call(k))
1
911,644,533,280
null
52
52
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) from typing import Iterable import sys def main(N, M, K, AB, CD): friend_chain = UnionFindTree(N) friend_count = [0] * N block_count = [0] * N for a, b in AB: a, b = a - 1, b - 1 friend_chain.union(a, b) friend_count[a] += 1 friend_count[b] += 1 for c, d in CD: c, d = c - 1, d - 1 if friend_chain.same(c, d): block_count[c] += 1 block_count[d] += 1 print(*[friend_chain.size(i) - 1 - friend_count[i] - block_count[i] for i in range(N)]) class UnionFindTree: def __init__(self, n: int) -> None: self.parent = [-1] * n def find(self, x: int) -> int: p = self.parent while p[x] >= 0: x, p[x] = p[x], p[p[x]] return x def union(self, x: int, y: int) -> bool: x, y, p = self.find(x), self.find(y), self.parent if x == y: return False if p[x] > p[y]: x, y = y, x p[x], p[y] = p[x] + p[y], x return True def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def size(self, x: int) -> int: return -self.parent[self.find(x)] def same_all(self, indices: Iterable[int]) -> bool: f, v = self.find, self.find(indices[0]) return all(f(i) == v for i in indices) if __name__ == '__main__': input = sys.stdin.readline N, M, K = map(int, input().split()) AB = [tuple(map(int, input().split())) for _ in range(M)] CD = [tuple(map(int, input().split())) for _ in range(K)] main(N, M, K, AB, CD)
class UnionFind(): def __init__(self, n): self.parents = [-1]*n def root(self, x): if self.parents[x] < 0: return x else: return self.root(self.parents[x]) def unite(self, x, y): x = self.root(x) y = self.root(y) if x == y: return else: if x > y: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x return n, m, k = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] cd = [list(map(int, input().split())) for _ in range(k)] u = UnionFind(n) f = [set() for _ in range(n)] l = [set() for _ in range(n)] for a, b in ab: a, b = a-1, b-1 f[a].add(b) f[b].add(a) u.unite(a, b) for c, d in cd: c, d = c-1, d-1 l[c].add(d) l[d].add(c) ans = [0] * n for i in range(n): r = u.root(i) bl = 0 for j in l[i]: if u.root(j) == r: bl += 1 ans[i] = -u.parents[r] - len(f[i]) - bl - 1 print(*ans)
1
61,764,836,224,896
null
209
209
n = int(input()) if n % 2 == 1: print(0) exit(0) cnt = 0 five = 2 * 5 while n // five > 0: cnt += n // five five *= 5 print(cnt)
import math n = int(input()) ans = 0 if n== 0: print(0) exit() if n%2 == 1: print(0) else: for j in range(1,100): if n//((5**j)*2) == 0: break ans += n//((5**j)*2) print(ans)
1
116,043,557,834,358
null
258
258
n=int(input()) s=100000 for i in range(n): s=s*1.05 if s%1000==0: s=s else: s=(s//1000)*1000+1000 print(int(s))
h1, m1, h2, m2, k = map(int, input().split()) a = m2 - m1 if a < 0: mm = (h2 - h1 - 1) * 60 + (60 + a) else: mm = (h2 - h1) * 60 + a print(0 if mm - k <= 0 else mm - k)
0
null
8,987,753,576,892
6
139
A = sum([list(map(int,input().split()))for _ in range(3)],[]) N = int(input()) b = [int(input()) for _ in range(N)] f=0 for i in range(9): if A[i]in b:f|=1<<i ans=[v for v in [7,56,73,84,146,273,292,448]if f&v==v] print('Yes' if ans else 'No')
a = input() a = a.split() b = input() b = b.split() c = input() c = c.split() d = [a[0],b[0],c[0]] e = [a[1],b[1],c[1]] f = [a[2],b[2],c[2]] g = [a[0],b[1],c[2]] h = [a[2],b[1],c[0]] n = int(input()) for i in range(n): j = int(input()) for k in range(3): if int(a[k])==j: a.pop(k) a.insert(k,0) if int(b[k])==j: b.pop(k) b.insert(k,0) if int(c[k])==j: c.pop(k) c.insert(k,0) if int(d[k])==j: d.pop(k) d.insert(k,0) if int(e[k])==j: e.pop(k) e.insert(k,0) if int(f[k])==j: f.pop(k) f.insert(k,0) if int(g[k])==j: g.pop(k) g.insert(k,0) if int(h[k])==j: h.pop(k) h.insert(k,0) if a == [0,0,0] or b == [0,0,0] or c == [0,0,0] or d == [0,0,0] or e == [0,0,0] or f == [0,0,0] or g == [0,0,0] or h == [0,0,0]: print("Yes") else: print("No")
1
59,859,890,004,928
null
207
207
import sys sys.setrecursionlimit(10 ** 5) def dfs(v): if v > 3234566667: return ans.append(v) d = v % 10 if d - 1 >= 0: dfs(v * 10 + d - 1) dfs(v * 10 + d) if d + 1 < 10: dfs(v * 10 + d + 1) K = int(input()) ans = [] [dfs(i) for i in range(1, 10)] print(sorted(ans)[K - 1])
def chk(l): s=0 for r in l: s+=r if (s<0)|(s>9): return False return True def nml(l): ln=len(l) for i in range(1,ln): if l[-i]==2: l[-i]=-1 l[-i-1]+=1 if l[0]==10: return True return False a=[1] for i in range(int(input())-1): while True: if len(a)==1: a[0]+=1 if a[0]==10: a=[1,-1] else: a[-1]+=1 if nml(a): a=[1]+[-(j==0) for j in range(len(a))] if chk(a): break rt="" ss=0 for i in a: ss+=i rt+=str(ss) print(rt)
1
40,107,672,546,770
null
181
181
from bisect import bisect N = int(input()) S = [input() for _ in range(N)] def count(s): n = len(s) n1 = 0 n2 = 0 for i in range(n): if s[i]=='(': n2 += 1 else: if n2 > 0: n2 -= 1 else: n1 += 1 return n1,n2 l1 = [] l2 = [] m1 = 0 m2 = 0 for i in range(N): n1,n2 = count(S[i]) if n1+n2==0: continue if n1 == 0: m1 += n2 continue if n2 == 0: m2 += n1 continue if n2-n1>=0: l1.append([n1,n2]) else: l2.append([n1,n2]) ans = 'Yes' l1.sort() for i in range(len(l1)): n1,n2 = l1[i] if m1 < n1: ans = 'No' break m1 += n2-n1 l2.sort(key=lambda x:x[1]) for i in range(len(l2)): n1,n2 = l2[i] if m2 < n2: ans = 'No' break m2 += n1-n2 if m1!=m2: ans = 'No' print(ans)
def main(): n = int(input()) if n == 0: print("Yes") return slup = [] sldown = [] for i in range(n): height, mi = 0, 0 for si in input(): if si == "(": height += 1 else: height -= 1 mi = min(mi, height) if height >= 0: slup.append([mi, height]) else: sldown.append([mi-height, -height]) slup.sort(key = lambda x: -x[0]) sldown.sort(key = lambda x: -x[0]) if sum([si[1] for si in slup]) + sum([-si[1] for si in sldown]): print("No") return h = 0 for si in slup: if h+si[0] < 0: print("No") return h += si[1] h = 0 for si in sldown: if h+si[0] < 0: print("No") return h += si[1] print("Yes") if __name__ == "__main__": main()
1
23,600,371,327,480
null
152
152
from sys import stdin, setrecursionlimit def main(): s, t = map(str, stdin.readline().split()) a, b = map(int, stdin.readline().split()) u = stdin.readline()[:-1] if s == u: a -= 1 else: b -= 1 print(a, b) if __name__ == "__main__": setrecursionlimit(10000) main()
n,m,k = map(int,input().split()) if n >= k: print(n-k,m) else: if m - (k-n) < 0: m = 0 else: m -= k - n print(0,m)
0
null
88,042,312,855,688
220
249
from collections import Counter def solve(): N = int(input()) D = list(map(int, input().split())) mod = 998244353 if D[0] != 0: print(0) return cnt = Counter(D) if cnt[0] > 1: print(0) return res = 1 for i in range(1, max(D)+1): if cnt[i-1] == 1: continue res *= cnt[i-1]**cnt[i] %mod res %= mod print(res) solve()
#!/usr/bin/env python3 #coding: utf-8 # Volume0 - 0001 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0001) li = [] for x in range(10): s = input() s = int(s) li.append(s) li.sort() li.reverse() for y in range(3): print(li[y])
0
null
77,308,783,010,662
284
2
n = int(input()) print(n + (n * n) + (n * n * n))
a=int(input()) b=a+a**2+a**3 print(b)
1
10,253,579,263,100
null
115
115
T1, T2 = list(map(int, input().split())) A1, A2 = list(map(int, input().split())) B1, B2 = list(map(int, input().split())) a, b = A1 * T1, A2 * T2 c, d = B1 * T1, B2 * T2 if a + b == c+ d: print("infinity") exit() if a + b < c+d: a,b,c,d = c,d,a,b if a > c: print(0) exit() else: num = 0 if (c-a) % (a+b-c-d) == 0: num = 1 print((c-a-1) // (a+b-c-d) * 2+num+1)
N = int(input()) a = list(map(int, input().split())) count = 0 for i in range(N): minj = i for j in range(i, N): if a[j] < a[minj]: minj = j if a[i] != a[minj]: a[minj], a[i] = a[i], a[minj] count += 1 print(*a) print(count)
0
null
65,895,806,199,008
269
15
n = int(input()) a = list(map(int,input().split())) a = sorted(a) aMax = a[-1] l = len(a) count = 0 k = 0 kSet = set() for i in range(n): value = a[i] if not(value in kSet): if i != 0 and a[i-1] == value: count -= 1 kSet.add(value) continue count += 1 j = 2 k = 0 while k < aMax: k = a[i] * j kSet.add(k) j += 1 print(count)
x = int(input()) p = sorted(list(map(int,input().split()))) d = [True]*(p[-1]+1) e = [False]*(p[-1]+1) for i in p: if e[i]: d[i] = False continue else: e[i] = True idx = 2*i while idx < len(d): d[idx] = False idx += i cnt = 0 for i in p: cnt += int(d[i]) print(cnt)
1
14,291,131,552,060
null
129
129
N = int(input()) S =[str(input()) for i in range(N)] print(len(set(S)))
scnum = int(input()) word = [0]*scnum for i in range(scnum): word[i] = input() word.sort() answer = 1 for j in range(scnum-1): if word[j] != word[j+1]: answer += 1 print(answer)
1
30,329,209,994,720
null
165
165
n = int(input()) t, h = 0, 0 for i in range(n): s1, s2 = input().split() if s1 > s2: t += 3 elif s1 < s2: h += 3 else: t += 1 h += 1 print(t, h)
R = int(input()) import math pi = math.pi around = 2 * R * pi print(around)
0
null
16,598,406,865,180
67
167
n = int(input()) lst = [] while n % 2 == 0: lst.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: lst.append(f) n //= f else: f += 2 if n != 1: lst.append(n) #print(lst) count = 0 while lst: s = 0 i = 1 num = lst[0] for ele in lst: if ele == num: s += 1 for j in range(s): lst.remove(num) while s > 0: s -= i i += 1 if s >= 0: count += 1 #print(lst) print(count)
import queue h, w = map(int, input().split()) maze = [list(input()) for _ in range(h)] # print(maze) def bfs(dist, i, j): q = queue.Queue() q.put((i, j, 0)) while not q.empty(): i, j, c = q.get() # print(i, j, c, dist) if i != 0 and dist[i-1][j] == 0: dist[i-1][j] = c+1 q.put((i-1, j, c+1)) if j != 0 and dist[i][j-1] == 0: dist[i][j-1] = c+1 q.put((i, j-1, c+1)) if i != h-1 and dist[i+1][j] == 0: dist[i+1][j] = c+1 q.put((i+1, j, c+1)) if j != w-1 and dist[i][j+1] == 0: dist[i][j+1] = c+1 q.put((i, j+1, c+1)) return dist, c ans = 0 for i in range(h): for j in range(w): if maze[i][j] == '.': dist = [[(maze[y][x] == '#')*-1 for x in range(w)] for y in range(h)] dist[i][j] = -10 dist, c = bfs(dist, i, j) tmp_ans = c if tmp_ans > ans: ans = tmp_ans print(ans)
0
null
55,949,514,308,448
136
241
X, Y = map(int, input().split()) MOD = 10 ** 9 + 7 def modpow(x, n): ret = 1 while n > 0: if n & 1: ret = ret * x % MOD x = x * x % MOD n >>= 1 return ret def modinv(x): return modpow(x, MOD - 2) def modf(x): ret = 1 for i in range(2, x + 1): ret *= i ret %= MOD return ret ans = 0 if (X + Y) % 3 == 0: m = (2 * X - Y) // 3 n = (2 * Y - X) // 3 if m >= 0 and n >= 0: ans = modf(m + n) * modinv(modf(n) * modf(m)) ans %= MOD print(ans)
import math import sys input = sys.stdin.readline def isPrime(n): i = 2 flag = True while i * i <= n: if n % i == 0: flag = False break else: i += 1 return flag x = int(input()) while True: if isPrime(x): print(x) break else: x += 1
0
null
127,645,224,784,106
281
250
import bisect,collections,copy,heapq,itertools,math,string from collections import defaultdict as D from functools import reduce import numpy as np import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 N,M,X = LI() # c=[] # a=[] # for i in range(n): # ca = LI() # c.append(ca[0]) # a.append(ca[1:]) # print(c) # print(a) _ca = [LI() for _ in range(N)] ca = np.array(_ca, np.int64) # print(ca) # ca = ca.reshape(n,-1) C = ca[:,0] A = ca[:,1:] # print(c) # print(a) result = 10**7 # ビット全探索 for i in range(1 << N): t = [0] * M c = 0 for j in range(N): # i を j回右にシフトして1との論理積を取り、1であればアイテムを購入しているとみなす # 購入していない場合 if (i >> j) & 1 == 0: continue c += C[j] for k in range(M): t[k] += A[j][k] # 全てX以上であれば更新 if all(x >= X for x in t): result = min(result, c) if result == 10**7: print(-1) else: print(result)
# F - Playing Tag on Tree # https://atcoder.jp/contests/abc148/tasks/abc148_f from heapq import heappop, heappush INF = float("inf") def dijkstra(n, G, s): dist = [INF] * n dist[s] = 0 hq = [(0, s)] while hq: d, v = heappop(hq) if dist[v] < d: continue for child, child_d in G[v]: if dist[child] > dist[v] + child_d: dist[child] = dist[v] + child_d heappush(hq, (dist[child], child)) return dist n, u, v = map(int, input().split()) graph = [[] for _ in range(n)] edge = [list(map(int, input().split())) for _ in range(n - 1)] for a, b in edge: graph[a - 1].append((b - 1, 1)) graph[b - 1].append((a - 1, 1)) from_u = dijkstra(n, graph, u - 1) from_v = dijkstra(n, graph, v - 1) # print(from_u) # print(from_v) fil = filter(lambda x : x[0] < x[1], [[fu, fv] for fu, fv in zip(from_u, from_v)]) sfil = sorted(list(fil), key=lambda x: [-x[1], -x[0]]) # print(sfil) print(sfil[0][1] - 1)
0
null
69,655,376,964,628
149
259
n, m, x = map(int, input().split()) ca = [(list(map(int, input().split()))) for _ in range(n)] caca = [0]*(m+1) ans = 12 * 10**5 +1 chk = 0 for nn in range(2**n): for j in range(m+1): caca[j] = 0 cnt = 0 for i in range(n): if (nn>>i) & 1: for j in range(m+1): caca[j] += ca[i][j] for j in range(1, m+1): if caca[j] >= x: cnt += 1 else: break if cnt == m: ans = min(ans, caca[0]) chk = 1 print(ans if chk == 1 else -1)
N, M, X = list(map(int, input().split())) C = [list() for _ in range(N)] for i in range(N): C[i] = list(map(int, input().split())) INF = 10**9 + 7 minpr = INF for i in range(2**N): buy = list() for j in range(N): if i&1==1: buy.append(j) i >>= 1 skill = [0]*M price = 0 for k in range(len(buy)): price += C[buy[k]][0] for l in range(M): skill[l] += C[buy[k]][l+1] for m in range(M): if skill[m] < X: break else: if minpr > price: minpr = price if minpr==INF: print(-1) else: print(minpr)
1
22,115,069,825,270
null
149
149
n = int(input()) a = list(map(int, input().split())) ch = 0 for i in range(n): if a[i] % 2 == 0: if a[i] % 3 != 0 and a[i] % 5 != 0: ch = 1 if ch == 0: ans = 'APPROVED' else: ans = 'DENIED' print(ans)
n, t = map(int, input().split()) ab = [list(map(int, input().split())) for i in range(n)] ab.sort() m = ab[-1][0] dp = [0] * (m + t) for a, b in ab: for j in range(t - 1, -1, -1): dp[a + j] = max(dp[a + j], dp[j] + b) print(max(dp))
0
null
110,161,444,541,400
217
282
def main(): a, b = map(int, input().split(" ")) for i in range(1,1010): ta = i*8//100 tb = i*10//100 if ta == a and tb == b: print(i) return print(-1) if __name__ == "__main__": main()
D = int(input()) c = [*map(int, input().split())] s = [0] + [[*map(int, input().split())] for _ in range(D)] t = [0] + [int(input()) for _ in range(D)] v = 0 last = [0] * 26 for d in range(1, D+1): select = t[d] - 1 v += s[d][select] last[select] = d v -= sum(c[i] * (d - last[i]) for i in range(26)) print(v)
0
null
33,216,914,923,024
203
114
x = [int(x) for x in input().split()] if (x[0]==x[1]): print('Yes') else: print('No')
def main(): N, M = map(int, input().split()) if N == M: print("Yes") exit(0) print("No") if __name__ == "__main__": main()
1
83,247,142,944,000
null
231
231
f=lambda:map(int,input().split()) N,K=f() r,s,p=f() T=list(input()) F=[0]*N res=0 for i in range(N): if F[i]==1: continue if i+K<N: if T[i]==T[i+K]: F[i+K]=1 if T[i]=='s': res+=r elif T[i]=='p': res+=s else: res+=p print(res)
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K = map(int, readline().split()) point = list(map(int, readline().split())) T = readline().strip() T = T.translate(str.maketrans('rsp', '012')) T = list(map(int, T)) ans = 0 for i in range(K): vec = T[i::K] M = len(vec) dp = [[0] * 3 for _ in range(M + 1)] for j in range(M): for k in range(3): dp[j + 1][k] = max(dp[j][(k + 1) % 3], dp[j][(k + 2) % 3]) if (k + 1) % 3 == vec[j]: dp[j + 1][k] += point[k] ans += max(dp[M]) print(ans) return if __name__ == '__main__': main()
1
106,888,356,148,990
null
251
251
import math a,b,x = list(map(int,input().split())) theta = math.degrees(math.atan(a*b*b/2/x)) if(b/math.tan(math.radians(theta)) > a): theta = math.degrees(math.atan((2*a*a*b-2*x)/a/a/a)) print('{:.7f}'.format(theta))
import math a, b, x = map(int, input().split()) x /= a if a * b >= x * 2: c = x * 2 / b print(math.degrees(math.atan2(b, c))) else: c = (a * b - x) * 2 / a print(math.degrees(math.atan2(c, a)))
1
162,534,304,095,070
null
289
289
import sys input = sys.stdin.readline def main(): N = int(input()) A = list(map(int, input().split())) mid = sum(A) / 2 x = 0 near_length = 0 for a in A: x += a if x >= mid: if x - mid > abs(x - a - mid): near_length = abs(x - a) else: near_length = x break ans = int(abs(mid-near_length) * 2) print(ans) if __name__ == "__main__": main()
from collections import Counter n = int(input()) verdicts = Counter([input() for i in range(n)]) for verdict in ["AC", "WA", "TLE", "RE"]: print(f"{verdict} x {verdicts[verdict]}")
0
null
75,105,915,218,378
276
109
A, B, N = [int(i) for i in input().split(' ')] if B > N: x = N else: x = B - 1 m = int(A * x / B) - A * int(x / B) print(m)
import math def main(): A, B, N = map(int, input().split()) x = min([B-1, N]) print(int(math.floor(A * x / B) - A * math.floor(x / B))) if __name__ == '__main__': main()
1
28,225,694,140,348
null
161
161
k=0 n=input() n=n.lower() s=input() while s!='END_OF_TEXT': s=s.lower() S=s.split() #print(S) for i in range(len(S)): if n==S[i]: k+=1 s=input() print(k)
word = input() counter = 0 while 1: s = input() if s == 'END_OF_TEXT': break else: s = list(s.lower().split()) counter += s.count(word) counter += s.count(word + '.') print(counter)
1
1,808,554,977,340
null
65
65
def resolve(): N = int(input()) A = list(map(int, input().split())) mp = dict() ans = 0 for i in range(N): x = i - A[i] ans += mp.get(x, 0) y = A[i] + i mp[y] = mp.get(y, 0) + 1 print(ans) if __name__ == "__main__": resolve()
from collections import Counter N = int(input()) A = list(map(int, input().split())) p = [i+Ai for i, Ai in zip(range(1, N+1), A)] q = [j-Aj for j, Aj in zip(range(1, N+1), A)] pc = Counter(p) qc = Counter(q) r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys()) print(r)
1
25,952,448,108,510
null
157
157
import sys input = sys.stdin.readline def main(): X = int(input()) NUM = X//100 A = X%100 if A <= NUM*5: print(1) else: print(0) if __name__ == '__main__': main()
for i in range ( int ( input ( ) ) ): ( a, b, c ) = sorted ( list ( map ( int, input ( ).split ( ) ) ) ) if ( a ** 2 ) + ( b ** 2 ) == ( c ** 2 ): print ( "YES" ) else: print ( "NO" )
0
null
63,287,601,460,422
266
4
x=0 b=[[0 for col in range(250)] for row in range(10)] a="first" while True: a=list(input()) if a[0]=="-": break m=int(input()) h=0 ans=[0]*250 for i in range(m): h=int(input()) for j in range(h,len(a)): ans[j-h]=a[j] for k in range(h): ans[len(a)-h+k]=a[k] for l in range(len(a)): a[l]=ans[l] for y in range(len(a)): b[x][y]=a[y] x+=1 for i in range(x): # for j in range(len(b[x+1])): for j in range(200): if b[i][j]==0: break print(b[i][j],end="") print()
while True: deck = input() if deck == "-": break m = int(input()) for i in range(m): h = int(input()) deck += deck[:h] deck = deck[h:] print(deck)
1
1,931,272,813,400
null
66
66
from math import gcd from functools import reduce from collections import defaultdict n=int(input()) a=list(map(int,input().split())) g=reduce(gcd,a) if g!=1: print("not coprime") exit() def isPrimeMR(n): d = n - 1 d = d // (d & -d) L = [2] for a in L: t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = (y * y) % n if y == 1 or t == n - 1: return 0 t <<= 1 return 1 def findFactorRho(n): m = 1 << n.bit_length() // 8 for c in range(1, 99): f = lambda x: (x * x + c) % n y, r, q, g = 2, 1, 1, 1 while g == 1: x = y for i in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for i in range(min(m, r - k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 while g == 1: ys = f(ys) g = gcd(abs(x - ys), n) if g < n: if isPrimeMR(g): return g elif isPrimeMR(n // g): return n // g return findFactorRho(g) def primeFactor(n): i = 2 ret = {} rhoFlg = 0 while i*i <= n: k = 0 while n % i == 0: n //= i k += 1 if k: ret[i] = k i += 1 + i % 2 if i == 101 and n >= 2 ** 20: while n > 1: if isPrimeMR(n): ret[n], n = 1, 1 else: rhoFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n > 1: ret[n] = 1 if rhoFlg: ret = {x: ret[x] for x in sorted(ret)} return ret #d=defaultdict(int) s=set() for q in a: p=primeFactor(q) for j in p: if j in s: print("setwise coprime") exit() s.add(j) print("pairwise coprime")
from collections import deque N, M, Q = map(int, input().split()) I = [list(map(int, input().split())) for _ in range(Q)] que = deque() ans = 0 for i in range(1, M+1): que.append([i]) while que: seq = que.popleft() if len(seq) == N: p = 0 for i in range(Q): if seq[I[i][1]-1] - seq[I[i][0]-1] == I[i][2]: p += I[i][3] ans = max(ans, p) else: for i in range(seq[-1], M+1): seq_next = seq + [i] que.append(seq_next) print(ans)
0
null
15,753,724,210,078
85
160
k = int(input()) a, b = list(map(int, input().split())) p = 0 while p <= 1000: if a <= p <= b: print("OK") exit() p += k print("NG")
from decimal import Decimal n,m = map(int, input().split()) A = list(map(int, input().split())) line = Decimal(sum(A) / (4 * m)) cnt = 0 for a in A: if a >= line: cnt += 1 if cnt >= m: print('Yes') break else: print('No')
0
null
32,589,824,369,278
158
179
n = int(input()) if n % 2 != 0: print(0) else: ans = 0 t = 10 while n >= t: ans += n//t t *= 5 print(ans)
def colorchange(i,l,r,col): k=i-1 while(k>=0): if not '#' in G[k]: for j in range(l+1,r+1): A[k][j]=col else: break k-=1 k=i+1 while(k<H): if not '#' in G[k]: for j in range(l+1,r+1): A[k][j]=col else: break k+=1 H,W,K=map(int,input().split()) G=[list(input()) for i in range(H)] s=set() A=[[-1]*W for i in range(H)] now=1 for i in range(H): if not '#' in G[i]: continue last=-1 first=True for j in range(W): if G[i][j]=='#' and j==0: first=False A[i][j]=now if j==W-1: colorchange(i,last,j,now) now+=1 elif G[i][j+1]=='#': if first: first=False else: colorchange(i,last,j,now) last=j now+=1 for i in range(H): print(*A[i])
0
null
130,004,003,820,800
258
277
import sys s1 = str(input()) s2 = str(input()) ans = 0 for i in range(len(s1)): if s1[i] != s2[i]: ans += 1 print(ans)
X = int(input()) rankArr=[2000,1800,1600,1400,1200,1000,800,600,400] for i in range(1,len(rankArr)): if rankArr[i] <= X and X < rankArr[i-1] : print(i) exit()
0
null
8,610,623,179,488
116
100
s = int(input()) if(s<3): print(0) exit() l = s//3 cnt = 0 mod = 10**9+7 for i in range(l): if(i==0): cnt += 1 continue remain = s-3*(i+1) bar_remain = remain+i n = 1 for j in range(i): n*=(bar_remain-j) k = 1 for j in range(1,i+1): k*=j cnt += (n//k)%mod cnt %= mod print(cnt)
import sys input = sys.stdin.readline def main(): S = int(input()) dp = [0]*(S+1) dp[0] = 1 M = 10**9 + 7 for i in range(1, S+1): for j in range(0,i-2): dp[i] += dp[j] dp[i] %= M print(dp[S]) if __name__ == '__main__': main()
1
3,306,748,668,648
null
79
79
n,k=map(int,input().split()) a=list(map(int,input().split())) rui=[0] for i in a: rui.append(rui[-1]+i) hantei=0 for i in range(0,len(rui)-k): if hantei<=rui[i+k]-rui[i]: hantei=rui[i+k]-rui[i] l=i r=i+k ans=0 for i in range(l,r): ans+=(a[i]+1)/2 print(ans)
n, k = map(int, input().split()) lp = list(map(int, input().split())) le = [(p + 1) / 2 for p in lp] e = sum(le[:k]) m = e for i in range(n - k): e -= le[i] e += le[k + i] m = max(m, e) print(m)
1
75,039,370,195,790
null
223
223
# -*- coding: utf-8 -*- # モジュールのインポート import itertools # 標準入力を取得 N = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) # 求解処理 p = 0 q = 0 order = 1 for t in itertools.permutations(range(1, N + 1), N): if t == P: p = order if t == Q: q = order order += 1 ans = abs(p - q) # 結果出力 print(ans)
import sys readline = sys.stdin.buffer.readline N = int(readline()) P = list(map(int, readline().split())) Q = list(map(int, readline().split())) from itertools import permutations p = list(permutations(range(1, N+1))) # print(p) a = p.index(tuple(P)) b = p.index(tuple(Q)) print(abs(a-b))
1
100,597,151,552,040
null
246
246
n,w = map(int,input().split()) items = sorted([list(map(int,input().split())) for i in range(n)]) dp = [[0]*(w+1) for _ in range(n+2)] for i in range(n): wi, vi = items[i] for j in range(w+1): if j+wi<=w: dp[i+1][j+wi] = max(dp[i+1][j+wi], dp[i][j]+vi) dp[i+1][j] = max(dp[i][j], dp[i+1][j]) ans = 0 for i, (wi, vi) in enumerate(items): ans = max(ans, dp[i][w-1]+vi) print(ans)
import math n = int(input()) def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True i = 1 while i > 0: if is_prime(n): break n += 1 print (n)
0
null
128,484,622,537,238
282
250
import itertools n = int(input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) ls = list(itertools.permutations(range(1, n + 1))) print(abs(ls.index(p) - ls.index(q)))
a = int(input()) reslut = pow(a,1) + pow(a,2) + pow(a,3) print(reslut)
0
null
55,239,671,218,872
246
115
n = int(input()) al = list(map(int, input().split())) if n%2 == 1: dp = [ [0]*4 for _ in range(n//2+1) ] for i in range(n//2): dp[i+1][0] = dp[i][0] + al[i*2] dp[i+1][1] = max(dp[i][1]+al[i*2+1], dp[i][0]+al[i*2+1]) dp[i+1][2] = max(dp[i][2]+al[i*2+2], dp[i][0]+al[i*2+2]) dp[i+1][3] = max(dp[i][3]+al[i*2+2], dp[i][1]+al[i*2+2]) ans = max(dp[-1]) print(ans) else: dp = [ [0]*2 for _ in range(n//2+1) ] for i in range(n//2): dp[i+1][0] = dp[i][0] + al[i*2] dp[i+1][1] = max(dp[i][1]+al[i*2+1], dp[i][0]+al[i*2+1]) ans = max(dp[-1]) print(ans)
import numpy as np import sys read = sys.stdin.read def solve(stdin): h, w, m = stdin[:3] row = np.zeros(h, np.int) col = np.zeros(w, np.int) for i in range(3, m * 2 + 3, 2): y, x = stdin[i: i + 2] - 1 row[y] += 1 col[x] += 1 max_cnt_y = max(row) max_cnt_x = max(col) max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x) for i in range(3, m * 2 + 3, 2): y, x = stdin[i: i + 2] - 1 if row[y] == max_cnt_y and col[x] == max_cnt_x: max_pair -= 1 return max_cnt_y + max_cnt_x - (max_pair == 0) print(solve(np.fromstring(read(), dtype=np.int, sep=' ')))
0
null
21,122,868,133,902
177
89
from math import cos, pi A, B, H, M = map(int, input().split()) theta = abs(M * 6 - (H * 30 + M / 2)) / 360 * 2 * pi c = (A ** 2 + B ** 2 - 2 * A * B * cos(theta)) ** 0.5 print(c)
import math A,B,H,M=map(int,input().split()) M_rad = math.radians(M*6) H_rad = math.radians(H*30+M*0.5) rad = M_rad - H_rad ans = math.sqrt(A**2+B**2-2*A*B*math.cos(rad)) print(ans)
1
20,130,210,372,060
null
144
144
s = input() print("Yes" if ("A" in s and "B" in s) else "No")
a = input() if a == "AAA" or a == "BBB" : print ("No") else : print ("Yes")
1
54,558,118,367,908
null
201
201
from collections import defaultdict from math import gcd N = int(input()) MOD = 10**9 + 7 L = defaultdict(lambda: [0,0]) zero = 0 for _ in range(N): A, B = map(int, input().split()) if A==0: d=B elif B==0: d=A else: d=gcd(A,B) if d != 0: A, B = A//d, B//d if A<0: A, B = -A, -B if B>0: L[(A,B)][0] += 1 else: L[(-B,A)][1] += 1 else: zero += 1 res = 1 for x,y in L.values(): res *= pow(2,x,MOD) + pow(2,y,MOD) -1 res %= MOD print((res+zero-1)%MOD)
import sys input = sys.stdin.readline mod = 10**9 + 7 n = int(input()) ab = [[int(x) for x in input().split()] for _ in range(n)] from collections import defaultdict, Counter import math double_zero_cnt = 0 a_zero_cnt = 0 b_zero_cnt = 0 d = defaultdict(list) # [a, b] ngのそれぞれの個数 a_b = [] for a, b in ab: if a == 0 and b == 0: double_zero_cnt += 1 continue elif a == 0: a_zero_cnt += 1 continue elif b == 0: b_zero_cnt += 1 continue g = math.gcd(a, b) a //= g b //= g if b < 0: b *= (-1) a *= (-1) # 必ずbは正 a_b.append((a, b)) c = Counter(a_b) key_list = list(c.keys()) for key in key_list: a, b = key if a < 0: a_ = a*(-1) b_ = b*(-1) else: a_ = a b_ = b if d[(-b_, a_)] != []: continue if c[(-b_, a_)] != 0: d[(a, b)] = [c[(a, b)], c[(-b_, a_)]] ans = 1 used_cnt = double_zero_cnt for key in d.keys(): if d[key] == []: continue x, y = d[key] used_cnt += (x + y) mul = (pow(2, x, mod) + pow(2, y, mod) - 1) % mod ans *= mul ans %= mod if a_zero_cnt > 0 and b_zero_cnt > 0: ans *= (pow(2, a_zero_cnt, mod) + pow(2, b_zero_cnt, mod) - 1) ans %= mod used_cnt += a_zero_cnt + b_zero_cnt elif a_zero_cnt > 0: ans *= pow(2, a_zero_cnt, mod) ans %= mod used_cnt += a_zero_cnt elif b_zero_cnt > 0: ans *= pow(2, b_zero_cnt, mod) ans %= mod used_cnt += b_zero_cnt ans *= pow(2, n - (used_cnt), mod) ans %= mod ans -= 1 ans += double_zero_cnt ans %= mod print(ans)
1
20,798,994,922,870
null
146
146
import math h = int(input()) l = int(math.log(h, 2)) p = (2**l)*2-1 print(p)
h = int(input()) def rc(h): if h == 1: return 1 t = rc(h//2)*2 return t + 1 print(rc(h))
1
80,224,644,216,690
null
228
228
_, S = input(), input().split() _, T = input(), input().split() print(sum(t in S for t in T))
n = int(input()) S = list(map(int, input().split(' '))) q = int(input()) T = list(map(int, input().split(' '))) counter = 0 for t in T: for s in S: if(s == t): counter += 1 break print(counter)
1
66,059,639,658
null
22
22
n=int(input()) a=list(map(int,input().split())) for i in a: if i%2==0 and i%3!=0 and i%5!=0: print("DENIED") exit() print("APPROVED")
n = int(input()) a = list(map(int, input().split())) for i in range(n): if a[i]%2 == 0: if (a[i]%3 != 0) and (a[i]%5 != 0): print('DENIED') exit() print('APPROVED')
1
68,967,825,472,700
null
217
217
N, K, C = list(map(int, input().split())) S = input() work_day_min = [] work_day_max = [] for i in range(N): if S[i] == 'o': if i > 0 and len(work_day_min) > 0: if i - work_day_min[-1] <= C: continue work_day_min.append(i) if len(work_day_min) == K: break for i in range(N): if S[N - i - 1] == 'o': if i > 0 and len(work_day_max) > 0: if work_day_max[-1] - (N - i - 1) <= C: continue work_day_max.append(N - i - 1) if len(work_day_max) == K: break for i in range(K): if work_day_min[i] == work_day_max[K-i-1]: print(work_day_min[i]+1)
# B - Papers, Please # https://atcoder.jp/contests/abc155/tasks/abc155_b n = int(input()) a = list(map(int, input().split())) even = 0 cnt = 0 for i in a: if i % 2 == 0: even += 1 if i % 3 == 0 or i % 5 == 0: cnt += 1 if even == cnt: print('APPROVED') else: print('DENIED')
0
null
54,744,842,973,606
182
217
i = list(map(int, input().split())) o = i[0] - 2 * i[1] if o <= 0: o = 0 print(o)
a,v = map(int, input().split()) b,w = map(int, input().split()) t = int(input()) ans = "NO" if a > b: a,b = a*(-1), b*(-1) if a == b: ans = "YES" elif a < b: if v > w and (b-a) <= (v-w)*t: ans = "YES" print(ans)
0
null
90,888,883,078,710
291
131
# -*- coding:utf-8 -*- def solve(): N = int(input()) """ ■ 解法 N = p^{e1} * p^{e2} * p^{e3} ... と因数分解できるとき、 z = p_i^{1}, p_i^{2}, ... としていくのが最適なので、それを数えていく (例) N = 2^2 * 3^2 * 5 * 7 のとき、 2,3,5,7の4回割れる。(6で割る必要はない) ■ 計算量 素因数分解するのに、O(√N) 割れる回数を計算するのはたかだか素因数分解するより少ないはずなので、 全体としてはO(√N+α)くらいでしょ(適当) """ def prime_factor(n): """素因数分解する""" i = 2 ans = {} while i*i <= n: while n%i == 0: if not i in ans: ans[i] = 0 ans[i] += 1 n //= i i += 1 if n != 1: ans[n] = 1 return ans pf = prime_factor(N) ans = 0 for key, value in pf.items(): i = 1 while value-i >= 0: value -= i ans += 1 i += 1 print(ans) if __name__ == "__main__": solve()
S = str(input()) a = len(S) print('x' * a)
0
null
45,139,158,999,932
136
221
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K = map(int, readline().split()) point = list(map(int, readline().split())) T = readline().strip() T = T.translate(str.maketrans('rsp', '012')) T = list(map(int, T)) ans = 0 for i in range(K): vec = T[i::K] M = len(vec) dp = [[0] * 3 for _ in range(M + 1)] for j in range(M): for k in range(3): dp[j + 1][k] = max(dp[j][(k + 1) % 3], dp[j][(k + 2) % 3]) if (k + 1) % 3 == vec[j]: dp[j + 1][k] += point[k] ans += max(dp[M]) print(ans) return if __name__ == '__main__': main()
def solve(n, a, b): l = (n+1)//2 - 1 r = l + 1 + (n%2==0) lb = sum(sorted(a)[l:r]) ub = sum(sorted(b)[l:r]) return (ub - lb) + 1 n = int(input()) a = [0] * n b = [0] * n for i in range(n): a[i], b[i] = map(int, input().split()) print(solve(n, a, b))
0
null
62,099,440,528,902
251
137
N = int(input()) S, T = input().split() charac = [] for i in range(N): charac += S[i] charac += T[i] print(''.join(charac))
N = int(input()) S, T = map(str, input().split()) ans = "" for i in range(2 * N): if i % 2 == 0: ans += S[i//2] else: ans += T[i//2] print(ans)
1
112,012,942,221,280
null
255
255
a = int(input()) print((a)+(a ** 2)+(a ** 3))
a = int(input()) ans = 0 for i in range(1, 4): ans += (a ** i) print(ans)
1
10,265,167,031,302
null
115
115
class Dice: def __init__(self): self.side = {"top": 0, "front": 0, "right": 0, "left": 0, "back": 0, "bottom": 0} # サイコロを東西南北、どちらか一方に転がした時、それぞれの面の変化 def roll(self, direction): self.direction = direction if self.direction == "N": w = self.side["top"] self.side["top"] = self.side["front"] self.side["front"] = self.side["bottom"] self.side["bottom"] = self.side["back"] self.side["back"] = w elif self.direction == "S": w = self.side["top"] self.side["top"] = self.side["back"] self.side["back"] = self.side["bottom"] self.side["bottom"] = self.side["front"] self.side["front"] = w elif self.direction == "E": w = self.side["top"] self.side["top"] = self.side["left"] self.side["left"] = self.side["bottom"] self.side["bottom"] = self.side["right"] self.side["right"] = w elif self.direction == "W": w = self.side["top"] self.side["top"] = self.side["right"] self.side["right"] = self.side["bottom"] self.side["bottom"] = self.side["left"] self.side["left"] = w # サイコロの面の位置関係 def position_relation(self, top, front): # 北に転がした場合 if top == "top" and front == "front"\ or top == "front" and front == "bottom"\ or top == "bottom" and front == "back"\ or top == "back" and front == "top": self.right = self.side["right"] # 北に転がした時の"top"と"front"を入れ替えた場合 if top == "top" and front == "back"\ or top == "back" and front == "bottom"\ or top == "bottom" and front == "front"\ or top == "front" and front == "top": self.right = self.side["left"] # 東に転がした場合 if top == "top" and front == "right"\ or top == "right" and front == "bottom"\ or top == "bottom" and front == "left"\ or top == "left" and front == "top": self.right = self.side["back"] # 東に転がした時の"top"と"front"を入れ替えた場合 if top == "top" and front == "left"\ or top == "left" and front == "bottom"\ or top == "bottom" and front == "right"\ or top == "right" and front == "top": self.right = self.side["front"] # 西に転がした場合 if top == "front" and front == "right"\ or top == "right" and front == "back"\ or top == "back" and front == "left"\ or top == "left" and front == "front": self.right = self.side["top"] # 西に転がした時の"top"と"front"を入れ替えた場合 if top == "front" and front == "left"\ or top == "left" and front == "back"\ or top == "back" and front == "right"\ or top == "right" and front == "front": self.right = self.side["bottom"] dice = Dice() for s, n in zip(dice.side, input().split()): dice.side[s] = int(n) q = int(input()) for i in range(q): t, f = map(int, input().split()) for k, v in dice.side.items(): if t == v: top = k if f == v: front = k dice.position_relation(top, front) print(dice.right)
class Dice: def __init__(self, data): self.data = data def move(self, direction): if direction == 'E': self.data[0],self.data[3], self.data[5], self.data[2] = \ self.data[3],self.data[5], self.data[2], self.data[0] elif direction == 'N': self.data[0],self.data[1], self.data[5], self.data[4] = \ self.data[1],self.data[5], self.data[4], self.data[0] elif direction == 'S': self.data[0],self.data[1], self.data[5], self.data[4] = \ self.data[4],self.data[0], self.data[1], self.data[5] elif direction == 'W': self.data[0],self.data[2], self.data[5], self.data[3] = \ self.data[2],self.data[5], self.data[3], self.data[0] elif direction == 'R': self.data[1],self.data[2], self.data[4], self.data[3] = \ self.data[2],self.data[4], self.data[3], self.data[1] def getTop(self): return self.data[0] def getRight(self, top, front): if self.data[0] != top: for i in range(4): if self.data[0] == top: break self.move('E') for i in range(4): if self.data[0] == top: break self.move('N') if self.data[1] != front: for i in range(3): self.move('R') if self.data[1] == front and self.data[0] == top: break return self.data[2] dice = Dice(input().split()) hoge = int(input()) fuga = [] for i in range(hoge): (x,y) = [j for j in input().split()] fuga += [dice.getRight(x,y)] for i in fuga: print(i)
1
247,913,542,980
null
34
34
N = int(input()) A = list(map(int, input().split())) Q = int(input()) M = list(map(int, input().split())) combinations = {} def create_combinations(idx, sum): combinations[sum] = 1 if idx >= N: return create_combinations(idx+1, sum) create_combinations(idx+1, sum+A[idx]) return create_combinations(0, 0) for target in M: if target in combinations.keys(): print("yes") else: print("no")
#dpでできないかな? import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,cos,radians,sqrt from operator import itemgetter def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI2(): return [int(input()) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf = 10**17 mod = 10**9 + 7 n,a,b=MI() l=b-a if l%2==0: ans=l//2 print(ans) else: edge=min(n-b,a-1) #print(edge) ans=edge ans+=1 l-=1 ans+=l//2 print(ans)
0
null
54,576,658,027,152
25
253
n = input() s, t = map(str, input().split()) out = [si+ti for si, ti in zip(s, t)] print("".join(out))
n = int(input()) f = 100000 if n == 0: print(int(f)) else: for i in range(n): f *= 1.05 #print(f) #F = f - f%1000 + 1000 if f%1000 != 0: f = (f//1000)*1000 + 1000 #print(i,f) print(int(f))
0
null
55,800,484,144,900
255
6
S = input().rstrip() if S[-1] == 's': print(S + 'es') else: print(S + 's')
a,b = map(int,input().split()) s = list(map(int,input().split())) w = [] for i in range(b): w.append(min(s)) s.remove(min(s)) print(sum(w))
0
null
7,026,906,015,008
71
120
S = list(input()) T = list(input()) count = 0 for i in range(len(S)): if S[i] == T[i]: count += 1 if count == len(S) and len(T) == len(S) + 1: print("Yes") else: print("No")
class Sort(): def __init__(self,n,cards): self.cards = cards self.n = n def bubble_sort(self): # bubble sort flag = 1 while flag != 0: flag = 0 rev = list(range(1,self.n)) rev.reverse() for j in rev: if int(self.cards[j][1]) < int(self.cards[j-1][1]): self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j] flag = 1 def select_sort(self): for i in range(self.n): mini = i for j in range(i,self.n): if int(self.cards[j][1]) < int(self.cards[mini][1]): mini = j if i != mini: self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i] def check_stable(self,origin): check_org = [["" for i in range(self.n)] for k in range(9)] check_sort = [["" for i in range(self.n)] for k in range(9)] for i in range(self.n): check_org[int(origin[i][1])-1][i] = origin[i][0] check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0] flag = 0 for i in range(9): if "".join(check_org[i]) != "".join(check_sort[i]): flag = 1 break if flag == 0: print("Stable") else: print("Not stable") def print_card(self): for i in range(self.n): if i != self.n-1: print("%s" % (self.cards[i]),end=" ") else: print("%s" % (self.cards[i])) if __name__ == '__main__': n = int(input()) card = input().split() card2 = card.copy() card_origin = card.copy() bubble = Sort(n,card) bubble.bubble_sort() bubble.print_card() bubble.check_stable(card_origin) select = Sort(n,card2) select.select_sort() select.print_card() select.check_stable(card_origin)
0
null
10,756,208,508,178
147
16
#!/usr/bin/env python3 a, b, c = map(int, input().split()) print("YNeos"[c - a - b < 0 or 0 <= 4 * a * b - (a + b - c)**2::2])
a, b, c = map(int, input().split()) if a*a + b*b + c*c -2*(a*b + b*c + c*a) > 0 and c-a-b > 0: print("Yes") else: print("No")
1
51,525,118,558,378
null
197
197
elements = [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] K = int(input()) th = K-1 print(elements[th])
s = [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] k = int(input()) print(s[k-1])
1
49,937,666,584,160
null
195
195