code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
def replacing_integer(): # 入力 N, K = map(int, input().split()) # 処理 now_num = N % K while True: if abs(now_num - K) <= now_num: now_num = abs(now_num - K) else: return now_num result = replacing_integer() print(result)
def main(): n = int(input()) % 10 hon = [2, 4, 5, 7, 9] pon = [0, 1, 6, 8] bon = [3] if n in hon: print("hon") elif n in pon: print("pon") elif n in bon: print("bon") if __name__ == '__main__': main()
0
null
29,406,391,612,634
180
142
a=list(map(int,input().split())) k=int(input()) while a[0]>=a[1]: k-=1 a[1]*=2 while a[1]>=a[2]: k-=1 a[2]*=2 if k>=0: print("Yes") else: print("No")
a,b,c = map(int,input().split()) k = int(input()) for i in range(k): if a >= b: b *= 2 elif b >= c: c *= 2 else: pass if a < b and b < c: print('Yes') else: print('No')
1
6,973,862,337,440
null
101
101
import sys import numpy as np import numba from numba import njit, b1, i4, i8, f8 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines uf_t = numba.types.UniTuple(i8[:], 2) @njit((uf_t, i8), cache=True) def find_root(uf, x): root = uf[0] while root[x] != x: root[x] = root[root[x]] x = root[x] return x @njit((uf_t, i8, i8), cache=True) def merge(uf, x, y): root, size = uf x, y = find_root(uf, x), find_root(uf, y) if x == y: return False if size[x] < size[y]: x, y = y, x size[x] += size[y] root[y] = root[x] return True @njit((i8, i8, i8[:]), cache=True) def main(N, M, AB): ans = N - 1 root = np.arange(N + 1, dtype=np.int64) size = np.ones_like(root) uf = (root, size) for i in range(0, len(AB), 2): a, b = AB[i:i + 2] if merge(uf, a, b): ans -= 1 return ans N, M = map(int, readline().split()) AB = np.array(read().split(), np.int64) print(main(N, M, AB))
code = """ # distutils: language=c++ # distutils: include_dirs=[/home/USERNAME/.local/lib/python3.8/site-packages/numpy/core/include, /opt/ac-library] # cython: boundscheck=False # cython: wraparound=False from libcpp cimport bool from libc.stdio cimport getchar, printf from libcpp.string cimport string from libcpp.vector cimport vector cdef extern from "<atcoder/dsu>" namespace "atcoder": cdef cppclass dsu: dsu(int n) int merge(int a, int b) bool same(int a, int b) int leader(int a) int size(int a) vector[vector[int]] groups() cdef class Dsu: cdef dsu *_thisptr def __cinit__(self, int n): self._thisptr = new dsu(n) cpdef int merge(self, int a, int b): return self._thisptr.merge(a, b) cpdef bool same(self, int a, int b): return self._thisptr.same(a, b) cpdef int leader(self, int a): return self._thisptr.leader(a) cpdef int size(self, int a): return self._thisptr.size(a) cpdef vector[vector[int]] groups(self): return self._thisptr.groups() cpdef inline vector[int] ReadInt(int n): cdef int b, c cdef vector[int] *v = new vector[int]() for i in range(n): c = 0 while 1: b = getchar() - 48 if b < 0: break c = c * 10 + b v.push_back(c) return v[0] cpdef inline vector[string] Read(int n): cdef char c cdef vector[string] *vs = new vector[string]() cdef string *s for i in range(n): s = new string() while 1: c = getchar() if c<=32: break s.push_back(c) vs.push_back(s[0]) return vs[0] cpdef inline void PrintLongN(vector[long] l): cdef int n = l.size() for i in range(n): printf("%ld\\n", l[i]) cpdef inline void PrintLong(vector[long] l): cdef int n = l.size() for i in range(n): printf("%ld ", l[i]) """ import os, sys, getpass if sys.argv[-1] == 'ONLINE_JUDGE': code = code.replace("USERNAME", getpass.getuser()) open('atcoder.pyx','w').write(code) os.system('cythonize -i -3 -b atcoder.pyx') sys.exit(0) from atcoder import Dsu, ReadInt def main(): N,M = ReadInt(2) dsu = Dsu(N) for i in range(M): a,b = ReadInt(2) dsu.merge(a-1,b-1) print(len(dsu.groups())-1) if __name__ == "__main__": main()
1
2,311,622,003,792
null
70
70
x,y,a,b,c=map(int,input().split()) p=sorted(list(map(int,input().split())),reverse=1)[:x] q=sorted(list(map(int,input().split())),reverse=1)[:y] r=sorted(list(map(int,input().split())),reverse=1) pq=sorted(p+q,reverse=1) ans=sum(pq) n=len(r) count=-1 for i in range(n): if r[i]>pq[count]: ans+=(r[i]-pq[count]) count-=1 print(ans)
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): x, y, a, b, c = MI() p = LI() q = LI() r = LI() p.sort(reverse=True) q.sort(reverse=True) r.sort(reverse=True) p_selected = p[:x] q_selected = q[:y] ans = [*p_selected, *q_selected] ans.sort() i = 0 while i < x + y and i < c and ans[i] < r[i]: ans[i] = r[i] i += 1 print(sum(ans)) main()
1
44,682,541,573,670
null
188
188
a=int(input()) x = 0 i = 0 while(1): x += a i += 1 x %= 360 if x: continue else: print(i) quit()
import sys import math import numpy as np import functools import operator import collections import itertools X=int(input()) ans=1 for i in range(1,100000): if (X*i)%360==0: print(ans) sys.exit() ans+=1
1
13,122,934,441,210
null
125
125
import math import sys sys.setrecursionlimit(10**9) MOD = 10**9+7 n, k = map(int, input().split()) k = min(k, n-1) fact = [1] for i in range(1, 10**6): fact.append((fact[i-1]*i)%MOD) inv = [None]*10**6 def inv_fact(n): if inv[n] == None: inv[n] = pow(fact[n], MOD-2, MOD) return inv[n] def comb(n, r): return (fact[n]*inv_fact(n-r)*inv_fact(r))%MOD ans = 0 for i in range(k+1): ans = (ans + comb(n-1, i)*comb(n, i))%MOD print(ans)
D = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for i in range(D)] t = [0]*D for i in range(D): t[i] =int(input()) m=[0]*D last_day=[0]*26 a=[[0 for i in range(26)] for j in range(D)] for u in range(D): i=t[u] for y in range(u,D): a[y][i-1]=u+1 if u==0: m[u]=s[u][i-1] else: m[u]=m[u-1]+s[u][i-1] mm=[0]*D for d in range(D): for i in range(26): mm[d]+=c[i]*(d+1-a[d][i]) if not d==0: mm[d]+=mm[d-1] for d in range(D): m[d]-=mm[d] print(m[d])
0
null
38,438,999,688,518
215
114
# -*- config: utf-8 -*- if __name__ == '__main__': hills = [] for i in range(10): tmp = raw_input() hills.append(int(tmp)) hills.sort(reverse=True) for i in range(3): print hills[i]
a = [input() for i in range(10)] a.sort(reverse=True) print a[0] print a[1] print a[2]
1
15,050,372
null
2
2
def CP(a,b): x = a[1]*b[2]-a[2]*b[1] y = a[2]*b[0]-a[0]*b[2] z = a[0]*b[1]-a[1]*b[0] return (x,y,z) minus = lambda d:tuple(-i for i in d) class dice: def __init__(self,data): names = [(1,0,0),(0,0,1),(0,1,0),(0,-1,0),(0,0,-1),(-1,0,0)] self.faces = {n:d for n,d in zip(names,data)} self.top = (1,0,0) self.north = (0,0,-1) def turn(self,direction): if direction == 'N': self.top,self.north = minus(self.north),self.top elif direction == 'S': [self.turn('N') for i in range(3)] elif direction == 'W': self.top = CP(self.top,self.north) elif direction == 'E': [self.turn('W') for i in range(3)] if __name__ == '__main__': data = [int(i) for i in input().split()] operations = input() d = dice(data) [d.turn(o) for o in operations] print(d.faces[d.top])
inp = map(int, raw_input().split()) x = max(inp) y = min(inp) while True: r = x % y x = y y = r if y == 0: break print x
0
null
123,071,254,498
33
11
X,N=map(int,input().split()) P=[int(x) for x in input().split()] index=0 while(1): if X-index not in P: print(X-index) break if X+index not in P: print(X+index) break index+=1
import bisect def abc170c_forbidden_list(): x, n = map(int, input().split()) p = list(map(int, input().split())) if n == 0: print(x) return p.sort() for i in range(100): idx = bisect.bisect_left(p, x - i) if idx >= n or p[idx] != x - i: print(x - i) return idx = bisect.bisect_left(p, x + i) if idx >= n or p[idx] != x + i: print(x + i) return abc170c_forbidden_list()
1
14,190,140,536,868
null
128
128
A, B, N = map(int, input().split()) if N >= B - 1: x = B - 1 c = (A * x) // B - A * (x // B) else: x = N c = (A * x) // B - A * (x // B) print(c)
N = int(input()) N_List = {i:0 for i in range(1,N+1)} E_List = list(map(int,input().split())) for i in E_List: N_List[i] += 1 for i in N_List.values(): print(i)
0
null
30,430,126,558,852
161
169
c=str(input()) print('Yes' if c[2]==c[3] and c[4]==c[5] else'No')
import math a,b,c = map(float,input().split()) H = b * math.sin(math.radians(c)) S = (a*(b*math.sin(math.radians(c))))/2 L = a + b + ((a**2) + (b**2) -(((2*a)*b)*math.cos(math.radians(c))))**0.5 print(float(S)) print(float(L)) print(float(H))
0
null
21,048,348,139,104
184
30
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_c # 横で切り分けてから、いちごが無い行は上の行のをコピる import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline rr = range def read_ints(): return list(map(int, read().split())) def read_map_as_int(H): ''' #→1,.→0として読み込む ''' ret = [] for _ in range(H): ret.append([1 if s == '#' else 0 for s in read()[:-1]]) # 内包表記はpypyでは若干遅いことに注意 # #numpy使うだろうからこれを残しておくけど return ret MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from fractions import gcd c = 0 def ret_row(s: list): ret = [-1] * W l = 0 global c for r, ss in enumerate(s): if ss == 1: c += 1 for j in rr(l, r + 1): ret[j] = c l = r + 1 for j in rr(l, W): ret[j] = c # assert -1 not in ret # あとで消す return ret H, W, K = read_ints() S = read_map_as_int(H) ans = [] for s in S: if 1 not in s: ans.append([-1] * W) else: ans.append(ret_row(s)) if ans[0][0] == -1: i = 0 while ans[i][0] == -1: i += 1 for j in rr(W): ans[0][j] = ans[i][j] for i in rr(1, H): if ans[i][0] != -1: continue for j in rr(W): ans[i][j] = ans[i - 1][j] for a in ans: print(*a)
n=int(input()) rec=[False]*n for i in range(n): a,b=map(int,input().split()) if a==b: rec[i]=True for i in range(n-2): if rec[i] and rec[i+1] and rec[i+2]: print("Yes") exit() print("No")
0
null
72,973,402,139,750
277
72
height,width=map(int,input().split()) A=[] for i in range(height): A.append([int(j) for j in input().split()]) for i in range(height): print(' '.join(map(str,A[i])),str(sum(A[i]))) B=[] C=[0 for _ in range(width)] for i in range(width): for j in range(height): s=0 s+=A[j][i] B.append(s) C[i]=sum(B) B=[] print(' '.join(map(str,C)),str(sum(C)))
(r, c) = [int(i) for i in input().split()] ct = [0 for d in range(c)] tmp = [] for rc in range(r): tmp = [int(i) for i in input().split()] total = 0 for cc in range(c): ct[cc] += tmp[cc] total += tmp[cc] print(tmp[cc], end=' ') print(total) total = sum(ct) print(' '.join([str(i) for i in ct]), total)
1
1,363,510,942,820
null
59
59
import sys def input(): return sys.stdin.readline().rstrip() def main(): n=int(input()) print((n-1)//2) if __name__=='__main__': main()
import math import numpy as np N = int(input()) N_half = math.floor(N/2) counts = 0 for i in np.arange(1, N): j = N-i if(i != j ): counts += 1 print(int(counts/2))
1
153,141,707,931,392
null
283
283
a,b,c=map(int,input().split()) print('Yes' if c>a+b and 4*a*b<(c-a-b)**2 else 'No')
a,b,c = map(int,input().split()) if c<=a+b: print("No") else: if 4*a*b<(c-a-b)**2: print("Yes") else: print("No")
1
51,900,237,976,844
null
197
197
import sys from collections import Counter input = sys.stdin.readline N = int(input()) ans = 1 mod = 998244353 D = list(map(int, input().split())) if D[0] != 0: print(0) exit() D = sorted(Counter(D).items()) tmp = D[0][1] stream = 0 for n, i in D: if stream != n: print(0) exit() if n == 0 and i == 1: stream += 1 continue elif n==0: print(0) exit() ans *= pow(tmp, i) ans %= mod tmp = i stream += 1 print(ans)
import sys readline = sys.stdin.readline N = int(readline()) D = list(map(int,readline().split())) counts = [0] * (max(D) + 1) from collections import Counter counter = Counter(D) for k,v in counter.items(): counts[k] = v if D[0] != 0 or counts[0] != 1: print(0) exit(0) ans = 1 DIV = 998244353 for i in range(1, len(counts)): ans *= pow(counts[i - 1],counts[i],DIV) ans %= DIV print(ans)
1
155,233,713,367,450
null
284
284
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul, itemgetter from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# N, U, V = getNM() U -= 1 V -= 1 # 高橋君はできるだけ遅くゲームが終了するように移動し、青木君はできるだけ早くゲームが終了するように移動します。 # 高橋君は逃げ、青木君は追いかける dist = [[] for i in range(N)] for i in range(N - 1): a, b = getNM() dist[a - 1].append(b - 1) dist[b - 1].append(a - 1) taka_d = [-1] * N aoki_d = [-1] * N taka_d[U] = 0 pos = deque([[U, taka_d[U]]]) while len(pos) > 0: u, dis = pos.popleft() for i in dist[u]: if taka_d[i] == -1: taka_d[i] = dis + 1 pos.append([i, taka_d[i]]) aoki_d[V] = 0 pos = deque([[V, aoki_d[V]]]) while len(pos) > 0: u, dis = pos.popleft() for i in dist[u]: if aoki_d[i] == -1: aoki_d[i] = dis + 1 pos.append([i, aoki_d[i]]) ans = 0 for a, b in zip(taka_d, aoki_d): if a < b: ans = max(ans, b - 1) print(ans)
#N, K = map(int, input().split( )) #L = list(map(int, input().split( ))) N = int(input()) i = 0 ans = [] #26^{i}がNを越えるまで以下の操作を繰り返す while N != 0: s = N%26 if s == 0: s = 26 N -= s N //= 26 ans.append(chr(s + 96)) print(''.join(list(reversed(ans))))
0
null
64,523,059,660,070
259
121
n = int(input()) DP = [None] * (n + 1) # 計算結果を保存する配列 DP[0] = 1 # 定義より DP[1] = 1 # 定義より def fib(n): # フィボナッチ数を2からnまで順に求めていく for i in range(2, n + 1): DP[i] = DP[i-1] + DP[i-2] return DP[n] print(fib(n))
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N = int(readline()) dp = [0] * 47 dp[0] = 1 dp[1] = 1 for i in range(2,N+1): dp[i] = dp[i-1] + dp[i-2] print(dp[N]) if __name__ == '__main__': main()
1
1,983,009,132
null
7
7
from itertools import product n = int(input()) l1 = [] for _ in range(n): l2 = [] for _ in range(int(input())): l2.append(list(map(int, input().split()))) l1.append(l2) ans = 0 for k in product([1, 0], repeat=n): check = True for i, j in enumerate(l1): if k[i] == 0: continue for x in j: if k[x[0] - 1] != x[1]: check = False if check: ans = max(ans, sum(k)) print(ans)
n = int(input()) tst = [[] for i in range(n)] for i in range(n): a = int(input()) for j in range(a): x,y = map(int,input().split()) tst[i].append([x,y]) ans = 0 for bit in range(1<<n): honest = [0]*n check = 1 for i in range(n): if (bit>>i)&1: honest[-1-i] = 1 for i in range(n): if not honest[i]: continue for l in tst[i]: if l[1]!=honest[l[0]-1]: check = 0 break if check: ans = max(ans,sum(honest)) print(ans)
1
121,786,798,718,688
null
262
262
import sys for line in range(int(input())): str = input().split(" ") nums = sorted([int(str[2]), int(str[1]), int(str[0])]) if nums[2]*nums[2] == nums[1]*nums[1] + nums[0]*nums[0]: print("YES") else: print("NO")
(r, c) = [int(i) for i in input().split()] a = [] for i in range(r): a.append([int(i) for i in input().split()]) a.append([0 for i in range(c)]) for i in range(r + 1): sum = 0 count = 0 for j in a[i]: print(j, end=' ') sum += j if i != r: a[r][count] += j count += 1 print(sum)
0
null
689,284,285,028
4
59
#!/usr/bin/env python3 import sys def solve(L: int): return (L / 3) ** 3 def main(): L = int(sys.stdin.readline().strip()) # type: int print(solve(L)) if __name__ == '__main__': main()
l = int(input()) ans = l * l * l / 27 print(ans)
1
47,351,503,686,222
null
191
191
r, c, k = map(int, input().split()) rcv = [list(map(int, input().split())) for i in range(k)] area = [[0] * (c+1) for i in range(r+1)] for a, b, v in rcv: area[a-1][b-1] = v # dp[i][j][k]: その行でiまで拾っており、 # j行k列目に到達時点の最大スコア dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)] dp[0][0][0] = 0 for rr in range(r+1): for cc in range(c+1): for i in range(4): # 取って右 if i+1<4 and cc<c and area[rr][cc]>0: dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1], dp[i][rr][cc]+area[rr][cc]) # 取って下 if i+1<4 and rr<r and area[rr][cc]>0: dp[0][rr+1][cc] = max(dp[0][rr+1][cc], dp[i][rr][cc]+area[rr][cc]) # 取らずに右 if cc<c: dp[i][rr][cc+1] = max(dp[i][rr][cc+1], dp[i][rr][cc]) # 取らずに下 if rr<r: dp[0][rr+1][cc] = max(dp[0][rr+1][cc], dp[i][rr][cc]) # ans: r行c列目の最大値(iは問わず) ans = max([dp[i][r][c] for i in range(4)]) print(ans)
N, X, T = map(int, input().split()) t = N % X s = N // X if t != 0: print(T * (s + 1)) else: print(T * s)
0
null
4,947,708,334,010
94
86
a, b = list(map(int, input().split())) if a * 500 >= b: my_result = 'Yes' else: my_result = 'No' print(my_result)
from collections import defaultdict from math import gcd mod = 10 ** 9 + 7 n = int(input()) fishes = defaultdict(int) zero_zero = 0 zero = 0 inf = 0 for _ in range(n): a, b = map(int, input().split()) if a == 0 and b == 0: zero_zero += 1 elif a == 0: zero += 1 elif b == 0: inf += 1 else: div = gcd(a, b) a //= div b //= div if b < 0: a *= -1 b *= -1 key = (a, b) fishes[key] += 1 def get_bad_pair(fish): a, b = fish if a < 0: a *= -1 b *= -1 return (-b, a) ans = 1 counted_key = set() for fish_key, count in fishes.items(): if fish_key in counted_key: continue bad_pair = get_bad_pair(fish_key) if bad_pair in fishes: pair_count = fishes[bad_pair] pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1 counted_key.add(bad_pair) else: pattern = pow(2, count, mod) ans = ans * pattern % mod ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1 if zero_zero: ans += zero_zero ans -= 1 print(ans % mod)
0
null
59,383,907,318,438
244
146
N, X, T = map(int, input().split()) times = N // X if N % X != 0: times += 1 print(T * times)
a, b, c, k = (int(i) for i in input().split()) res = 1 * min(a, k) + 0 * min(b, max(0, k - a)) + -1 * min(c, max(0, k - a - b)) print(res)
0
null
13,080,135,340,578
86
148
N = int(input()) an = x = [int(i) for i in input().split()] count = 0 for i in range(len(an)): if ((i + 1) % 2 == 0): continue if (an[i] % 2 != 0): count = count + 1 print(count)
n,x,m=map(int,input().split()) # 一定回数を経ると循環するので最後にかければよい a_i = x log = [x] app=[-1]*m app[x]=0 last = x for i in range(1,n): a_i = (a_i**2)%m if app[a_i] > -1: last = a_i break app[a_i] = i log.append(a_i) # ループの手前(or最後)まで足し合わせる ans = sum(log[:min(n, app[last])]) if n > app[last]: # ループ中合計 ans += sum(log[app[last]:]) * ((n-app[last]) // (len(log) - app[last])) # 末端合計 ans += sum(log[app[last]:app[last] + (n-app[last]) % (len(log) - app[last])]) print(ans)
0
null
5,302,180,123,058
105
75
N,K = map(int, input().split()) P = [int(p) for p in input().split()] C = [int(c) for c in input().split()] ans = max(C) for i in range(N): used = [0]*N used[i] = 1 loop = [C[i]] j = P[i]-1 while used[j] == 0: used[j] = 1 loop.append(loop[-1]+C[j]) j = P[j]-1 M = len(loop) if K >= M: if K%M == 0: t = 0 else: t = max(loop[:K%M]) t = max(t, 0) num = max(loop[-1]*(K//M)+t, max(loop), loop[-1]*(K//M-1)+max(loop)) else: num = max(loop[:K]) ans = max(ans, num) if max(C) <= 0: ans = max(C) print(ans)
import sys def gcd(inta, intb): large = max(inta, intb) small = min(inta,intb) mod = large % small if mod ==0: return small else: return gcd(small, mod) def lcm(inta, intb, intgcd): return (inta * intb // intgcd) sets = sys.stdin.readlines() for line in sets: a, b = map(int, line.split()) c = gcd(a, b) print(c, lcm(a, b, c))
0
null
2,683,130,425,500
93
5
from decimal import * x,y,z = map(int,input().split()) a=Decimal(x) b=Decimal(y) c=Decimal(z) if Decimal((c-a-b)**Decimal(2)) > Decimal(Decimal(4)*a*b) and c-a-b > 0: print('Yes') else: print('No')
def main(): a,b,c = map(int,input().split()) rhs = c - a - b lhs = 4 * a * b if rhs > 0 and lhs < rhs ** 2: print('Yes') else: print('No') main()
1
51,326,551,352,582
null
197
197
s = [x for x in input()] t = [y for y in input()] count = 0 for _ in range(len(s)): if s[_] != t[_]: count+=1 print(count)
from scipy.special import comb from collections import Counter n = int(input()) A = [int(i) for i in input().split()] count = Counter(A) combs = {k:comb(count[k], 2) for k in count.keys()} combs_minas_one = {k:comb(count[k]-1, 2) for k in count.keys()} all = sum(combs.values()) for a in A: ans = all - combs[a] + combs_minas_one[a] print(int(ans))
0
null
29,172,647,851,100
116
192
import math def lcm(x, y): return (x * y) // math.gcd(x, y) if __name__ == '__main__': a, b = map(int, input().split()) print(lcm(a, b))
a = [] b = [] a = input().split() b = input().split() if a[0] == b[0]: print("0") else: print("1")
0
null
118,800,472,269,142
256
264
n = int(input()) ans = (n - 1) // 2 print(ans)
n = int(input()) if n % 2 == 0: ans = n / 2 - 1 else: ans = n / 2 print(int(ans))
1
153,493,487,758,752
null
283
283
n = int(input()) ans = "" while n: n -= 1 ans += chr(ord('a') + (n % 26)) n //= 26 print(ans[::-1])
from collections import deque # dequeはappendleftができるので。 letter = ['z'] + [chr(i) for i in range(97, 123)] # [0, a, b, c, ... , z]というリスト N = int(input()) i = 0 n_24 = deque() while N > 0: n_24.appendleft(N % 26) if N%26== 0: N -= 26 N = N // 26 ans = '' for dig in (n_24): ans += letter[dig] print(ans)
1
11,901,915,967,590
null
121
121
a, b, c = [int(i) for i in input().split()] if a < b: if b < c: print('Yes') else: print('No') else: print('No')
#k = int(input()) #s = input() #a, b = map(int, input().split()) #l = list(map(int, input().split())) x = int(input()) yokin = 100 for i in range(1, 100000000000): yokin *= 101 yokin = yokin //100 if (yokin >= x): print(i) break
0
null
13,724,923,574,292
39
159
h,n=map(int,input().split()) c=[list(map(int,input().split()))for _ in range(n)] d=[0]+[0]*20001 for i in range(h): d[i]=min(d[i-a]+b for a,b in c) print(d[h-1])
num = input() streaks = [] streak = 0 for letter in num: if letter == "R": streak += 1 elif letter != "R": streaks.append(streak) streak = 0 else: streaks.append(streak) print(max(streaks))
0
null
43,138,813,646,812
229
90
n=int(input()) s,p=10**100,10**100 t,q=-1000000000000,-1000000000000 for i in range(n): x,y=map(int,input().split()) s=min(s,x+y) t=max(t,x+y) p=min(p,x-y) q=max(q,x-y) print(max(t-s,q-p))
n = int(input()) xy = [] for _ in range(n): xy.append(list(map(int, input().split()))) tmp1 = [] tmp2 = [] for i in range(n): tmp1.append([xy[i][0]+xy[i][1], xy[i][0], xy[i][1]]) tmp2.append([xy[i][0]-xy[i][1], xy[i][0], xy[i][1]]) tmp1.sort() tmp2.sort() ans = 0 if (tmp1[-1][2]-tmp1[0][2])*(tmp1[-1][1]-tmp1[0][1]) >= 0: tmp = tmp1[-1][0]-tmp1[0][0] ans = max(tmp, ans) if (tmp2[-1][2]-tmp2[0][2])*(tmp2[-1][1]-tmp2[0][1]) <= 0: tmp = tmp2[-1][0]-tmp2[0][0] ans = max(tmp, ans) print(ans)
1
3,430,248,478,020
null
80
80
n, k = list(map(int, input().split())) list = list(map(int, input().split())) ans = [l for l in list if l >= k] print(len(ans))
num_persons, need_height = map(int, input().split()) a = map(int, input().split()) height_list = list(a) count_height_ok = 0 for i in height_list: if i >= need_height: count_height_ok += 1 print(count_height_ok)
1
179,055,917,161,330
null
298
298
n = int(input()) s = input() ans = s.count("ABC") print(ans)
n = int(input()) t = 0 h = 0 for _ in range(n): a_lst = input().rstrip().split(" ") #print(a_lst) b_lst = sorted(a_lst) #print(b_lst) if a_lst[0] == a_lst[1]: t += 1 h += 1 elif a_lst == b_lst: h += 3 else: t += 3 print(t, h)
0
null
50,563,150,212,288
245
67
x,k,d=map(int,input().split()) x=abs(x) if x//d <=k: ans=x%d if (k-x//d)%2==1: ans=abs(ans-d) print(ans) else: ans=x-d*k print(ans)
X, K, D = [int(v) for v in input().split()] X = abs(X) m = X // D p = K - m if m <= K else 0 if p == 0: print(X - (K*D)) else: X -= m * D if p & 1: print(abs(X-D)) else: print(X)
1
5,190,850,851,580
null
92
92
import sys while True: h, w = [ int( val ) for val in sys.stdin.readline().split( " " ) ] if 0 ==h and 0 == w: break pa = [ "#", "." ] ouput = [] for i in range( h ): for j in range( w ): ouput.append( pa[(i+j)%2] ) ouput.append( "\n" ) print( "".join( ouput ) )
# coding: utf-8 board = ['#', '.'] while True: h, w = map(int, input().split()) if h == 0 and w == 0: exit() for row in range(h): for column in range(w): print(board[(row + column) % 2], end='') print() print()
1
893,466,990,950
null
51
51
a,b,c=map(int,input().split()) if (a==b and b==c) or (a!=b and b!=c and c!=a): print("No") else: print("Yes")
a,b,c =map(int,input().split()) flag1 = 0 flag2 = 0 flag3 = 0 if a == b: flag1 = 1 if b == c: flag2 =1 if a == c: flag3 =1 if flag1 ==1 and flag2 ==1: print("No") elif flag1 ==0 and flag2 ==0 and flag3 == 0: print("No") else: print("Yes")
1
67,949,035,000,032
null
216
216
def main(): S = input() ans = [s if s != '?' else 'D' for s in S] print(''.join(ans)) if __name__ == '__main__': main()
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N, u, v = mapint() query = [[] for _ in range(N)] for _ in range(N-1): a, b = mapint() query[a-1].append(b-1) query[b-1].append(a-1) from collections import deque def dfs(start): Q = deque([start]) dist = [10**18]*N dist[start] = 0 while Q: now = Q.pop() for nx in query[now]: if dist[nx]>=10**18: dist[nx] = dist[now] + 1 Q.append(nx) return dist taka = dfs(u-1) aoki = dfs(v-1) ans = 0 for i in range(N): t, a = taka[i], aoki[i] if t<=a: ans = max(ans, a-1) print(ans)
0
null
67,703,220,456,340
140
259
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def s(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 cnt = 1 ans = 0 inf = float("inf") s = s() k = k() if s[0]*len(s) == s: print(len(s)*k // 2) sys.exit() res = [1] for i in range(len(s)-1): if s[i] == s[i+1]: res[-1] += 1 else: res.append(1) for i in res: ans += (i//2)*k if s[0] == s[-1]: diff = (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2) ans += diff*(k-1) print(ans)
s = input() k = int(input()) l=len(s) s+='?' ch = 1 ans=0 j=0 for i in range(l): if s[i]==s[i+1]: ch+=1 else: ans+=ch//2 if j==0: st=ch if s[i+1]=='?': gl=ch ch=1 j=1 ans*=k if st%2==1 and gl%2==1 and s[0]==s[l-1]: ans+=k-1 if st==l: ans=l*k//2 print(ans)
1
175,365,712,925,348
null
296
296
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N = int(readline()) P = list(map(int, readline().split())) cur = N + 1 ans = 0 for x in P: if cur > x: ans += 1 cur = x print(ans) if __name__ == '__main__': main()
N,K = map(int,input().split()) ls = list(map(int,input().split())) ls.sort(reverse=True) if N <= K: print(0) else: print(sum(ls[K:N+1]))
0
null
82,187,133,015,308
233
227
H1,M1,H2,M2,K = map (int, input ().split ()) S = H1*60+M1 G = H2*60+M2 p = G-S if p-K < 0: print (0) else: print (p-K)
import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(20000000) MOD = 10 ** 9 + 7 INF = float("inf") def main(): H1, M1, H2, M2, K = map(int, input().split()) if M2 >= M1: time = (H2 - H1) * 60 + M2 - M1 else: time = (H2 - H1 - 1) * 60 + M2 + 60 - M1 answer = max(time - K, 0) print(answer) if __name__ == "__main__": main()
1
18,049,790,902,560
null
139
139
from math import ceil N, K = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) F = sorted(list(map(int, input().split()))) def is_valid(A, F, K, T): for a, f in zip(A, F): if a*f > T: k = ceil(a - T/f) if k <= K: K -= k else: return False return True def solve(N, K, A, F): i = 0 left, right = 0, 10**12 while left < right: mid = (left + right) // 2 if is_valid(A, F, K, mid): right = mid else: left = mid + 1 if is_valid(A, F, K, mid-1) and (not is_valid(A, F, K, mid)): return mid-1 elif is_valid(A, F, K, mid): return mid else: return mid+1 print(solve(N, K, A, F))
def resolve(): N = int(input()) ans = 0 for i in range(1, N+1): n = N//i ans += (n*(n+1)*i)//2 print(ans) if '__main__' == __name__: resolve()
0
null
88,025,946,745,792
290
118
h, a = map(int, input().split()) print( - ( - h // a))
#!/usr/bin/env python # -*- coding: utf-8 -*- # # FileName: A # CreatedDate: 2020-06-27 15:30:40 +0900 # LastModified: 2020-06-27 15:33:43 +0900 # import os import sys # import numpy as np # import pandas as pd def main(): h, a = map(int, input().split()) if float(h/a).is_integer(): print(h//a) else: print(h//a+1) if __name__ == "__main__": main()
1
76,890,829,071,518
null
225
225
def resolve(): import math print(2*math.pi*int(input())) if '__main__' == __name__: resolve()
n, k = map(int, input().split()) a = [0] + list(map(int, input().split())) journey = [1] for i in range(n): journey.append(a[journey[i]]) if k <= n: print(journey[k]) exit() cycle_end = n cycle_start = n - 1 while journey[cycle_start] != journey[cycle_end]: cycle_start -= 1 cycle_range = cycle_end - cycle_start cycle_cnt = (k - n) // cycle_range extra = (k - n) - (cycle_range * cycle_cnt) for i in range(extra): journey.append(a[journey[i + n]]) print(journey[-1])
0
null
27,033,352,625,498
167
150
a = input() if a == '1': print('0') else: print('1')
if(int(input())==1): print(0) else: print(1)
1
2,902,331,782,126
null
76
76
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N,K=MI() h=LI() h.sort() if K>=N: print(0) exit() for i in range(K): h[-1-i]=0 ans=sum(h) print(ans) main()
number = list(map(int,input().split())) score = list(map(int,input().split())) score.sort() answer = 0 if number[1] > number [0]: number[1] = number[0] for i in range(number[1]): score[number[0]-1-i] = 0 for j in range(number[0]): answer += score[j] print(answer)
1
79,049,425,167,690
null
227
227
k = int(input()) hp = [i for i in range(k+4)] r, w = 1, 10 while w <= k: n = hp[r] r += 1 nm = n % 10 val = n * 10 + nm if nm != 0: hp[w] = val - 1 w += 1 hp[w] = val w += 1 if nm != 9: hp[w] = val + 1 w += 1 print(hp[k])
from collections import deque K=int(input()) queue=deque(list(range(1,10))) for i in range(K): k=queue.popleft() mod=k%10 for diff in range(mod-1,mod+2): if diff<0 or 9<diff: continue queue.append(10*k+diff) print(k)
1
39,964,125,942,784
null
181
181
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)
first_string = input() second_string = input() count = 0 for x, y in zip(first_string, range(len(first_string))): if(second_string[y] != x): count += 1 print(count)
0
null
32,934,053,089,714
202
116
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N = int(readline()) cnt = 0 ans = -1 for _ in range(N): x, y = map(int, readline().split()) if x == y: cnt += 1 ans = max(ans, cnt) else: cnt = 0 if ans >=3: print('Yes') else: print('No') if __name__ == '__main__': main()
a=[int(input()) for i in range(10)] a.sort() a.reverse() print(a[0]) print(a[1]) print(a[2])
0
null
1,244,036,675,040
72
2
from collections import deque n,m=map(int,input().split()) adj=[[] for _ in range(n)] for _ in range(m): a,b =map(int,input().split()) a-=1 b-=1 adj[a].append(b) adj[b].append(a) ans=[0]*n que=deque([]) que.append(0) while que: e=que.popleft() for i in adj[e]: if ans[i]!=0: continue ans[i]=e+1 que.append(i) print("Yes") for i in range(1,n): print(ans[i])
#import numpy as np #import math #from decimal import * #from numba import njit #@njit def main(): (N, M) = map(int, input().split()) neighbor = [[] for _ in range(N+1)] for _ in range(M): (A,B) = map(int, input().split()) neighbor[A] += B, neighbor[B] += A, guide = [0 for _ in range(N+1)] # 1の部屋から幅優先で道しるべを置く # 探索候補 target = [1] checked = [1] while len(target) > 0: # 候補の先頭から取る n = target.pop(0) # nから伸びる行き先 dests = neighbor[n] # すでに道しるべがあるものは除く dests = filter(lambda d: guide[d] == 0, dests) # 道しるべを置く for d in dests: guide[d] = n checked += d, # 探索候補の末尾に追加 target += d, print('Yes') for i in range(2,N+1): print(guide[i]) main()
1
20,514,424,038,690
null
145
145
a,v = map(int, input().split()) b,w = map(int, input().split()) t = int(input()) if v-w>0: if abs(a-b)/(v-w) <= t: print('YES') exit() print('NO')
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) D = abs(A - B) if (V > W) and \ (D / (V - W) <= T): print("YES") else: print("NO")
1
15,078,905,675,438
null
131
131
n,m = map(int,input().split()) ans = 0 if n > 1: ans += n * (n -1) / 2 if m > 1: ans += m *(m - 1) / 2 print(int(ans))
n, m = (int(i) for i in input().split()) tot = sum(int(i) for i in input().split()) if tot > n: print(-1) else: print(n - tot)
0
null
38,813,536,779,842
189
168
if __name__ == '__main__': from sys import stdin while True: m, f, r = (int(n) for n in stdin.readline().rstrip().split()) if m == f == r == -1: break s = m + f result = "F" if m == -1 or f == -1 \ else "A" if 80 <= s \ else "B" if 65 <= s \ else "C" if 50 <= s or 50 <= r \ else "D" if 30 <= s \ else "F" print(result)
def code(): l = [] while True: m,f,r = map(int,input().split()) if m == f == r == -1: break else: l.append([m,f,r]) for i in l: s = '' x = i[0]+i[1] if i[0] == -1 or i[1] == -1: s = 'F' elif x >= 80: s = 'A' elif x >= 65: s = 'B' elif x >= 50: s = 'C' elif x >= 30: s = 'D' if i[2] >= 50: s = 'C' else: s = 'F' print(s) code()
1
1,247,206,102,240
null
57
57
A,B=input().split() A=int(A) B=int(100*float(B)+0.5) print(A*B//100)
a, b, c, k = map(int, input().split()) sum = 0 rest_k = k if rest_k <= a: sum += rest_k rest_k = 0 else: sum += a rest_k -= a if rest_k <= b: rest_k = 0 else: rest_k -= b sum -= rest_k print(sum)
0
null
19,142,634,738,078
135
148
a = int(input()) b_list = list(map(int, input().split())) count = 0 mini=a for i in range(len(b_list)): if b_list[i] <= mini: count += 1 mini = b_list[i] print(count)
n = int(input()) l = list(map(int, input().split())) s = 0 m = l[0] for i in range(n): if m >= l[i]: m = l[i] s += 1 print(s)
1
85,647,166,624,320
null
233
233
# Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042 x= int(input()) def prime_check(num,count): while True: while num % count == 0: num = num + 1 count = 2 if num <= count**2: print(num) break else: count = count + 1 if x==2 : print (2) else: prime_check(x,2)
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from functools import reduce, lru_cache import collections, heapq, itertools, bisect import math, fractions import sys, copy sys.setrecursionlimit(1000000) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline().rstrip()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline().rstrip()) def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 def main(): K, N = LI() A = LI() res = [A[0] + K - A[-1]] for i in range(N-1): res.append(A[i+1] - A[i]) res = sorted(res) print(K - res[-1]) if __name__ == '__main__': main()
0
null
74,578,500,868,842
250
186
s,t=map(str,input().split()) print(t+s,sep='')
def readinput(): n=int(input()) a=list(map(int,input().split())) return n,a def main(n,a): a.sort() for i in range(n-1): if a[i]==a[i+1]: return 'NO' return 'YES' if __name__=='__main__': n,a=readinput() ans=main(n,a) print(ans)
0
null
88,048,053,199,840
248
222
def main(): A = map(int, input().split()) print('bust' if sum(A) >= 22 else 'win') if __name__ == '__main__': main()
print(['win','bust'][sum(list(map(int,input().split())))>=22])
1
119,374,167,593,092
null
260
260
while True: try: m,f,r = map(int,input().split(" ")) if m == -1: if f == -1: if r == -1: break if m == -1 or f == -1: print("F") continue if m+f >= 80: print("A") if m+f >= 65 and m+f < 80: print("B") if m+f >= 50 and m+f < 65: print("C") if m+f >= 30 and m+f < 50: if r >= 50: print("C") else: print("D") if m+f < 30: print("F") except EOFError: break
MOD = 998244353 factorial = None inverse_factorial = None def modpow(a, p): ans = 1 while p: if p&1 == 1: ans = (ans*a)%MOD a = (a*a)%MOD p >>= 1 return ans def nCr(n, r): if r == 0 or r == n: return 1 return (((factorial[n]*inverse_factorial[n-r])%MOD)*inverse_factorial[r])%MOD def init_nCr(max_n): global factorial, inverse_factorial factorial = [1]*(max_n+1) inverse_factorial = [0]*(max_n+1) for i in range(1, max_n+1): factorial[i] = (factorial[i-1]*i)%MOD inverse_factorial[i] = modpow(factorial[i], MOD-2) init_nCr(2*10**5+1) def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def solve(): N, M, K = read_ints() answer = 0 for k in range(0, K+1): answer = (answer+M*modpow(M-1, N-1-k)*nCr(N-1, k))%MOD return answer if __name__ == '__main__': print(solve())
0
null
12,236,827,912,380
57
151
n = int(input()) ansl = [] def dfs(s, max_s): if len(s) == n: ansl.append(s) return ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' for i in range(max_s+1): dfs(s+ascii_lowercase[i], max(i+1, max_s)) dfs("", 0) for a in ansl: print(a)
n = int(input()) def dfs(i,s): if i == n: print(s) return ma = 0 for j in s: ma = max(ma,ord(j)) for j in range(ma - 95): dfs(i+1,s+chr(97+j)) return dfs(1,"a")
1
52,248,393,876,032
null
198
198
n, k = list(map(int, input().split())) enemy = list(map(int, input().split())) enemy = sorted(enemy, reverse=True) enemy = enemy[k:] print(sum(enemy))
n, k = map(int, input().split()) H = list(map(int, input().split())) H.sort() print(sum(H[:max(n-k, 0)]))
1
79,401,392,806,912
null
227
227
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys INF = 10**10 def main(N, K, P, C): ans = max(C) for i in range(N): used = [False] * N now = 0 mx = -INF cnt = 0 while True: if used[i] or cnt >= K: break used[i] = True i = P[i] - 1 now += C[i] mx = max(mx, now) cnt += 1 tmp = max(mx, now) if now > 0: cycle, mod = divmod(K, cnt) if cycle > 1: tmp = max(tmp, now * (cycle - 1) + mx) t = now * cycle tmp = max(tmp, t) for j in range(mod): i = P[i] - 1 t += C[i] tmp = max(tmp, t) ans = max(ans, tmp) print(ans) if __name__ == '__main__': input = sys.stdin.readline N, K = map(int, input().split()) *P, = map(int, input().split()) *C, = map(int, input().split()) main(N, K, P, C)
ac = input() acc ='abcdefghijklmnopqrstuvwxyz' print(acc[acc.index(ac) + 1])
0
null
48,794,396,301,328
93
239
n,a,b = map(int, input().split()) if a%2==b%2: print((b-a)//2) exit() print(min(a-1,n-b) +1+ (b-a-1)//2)
a,b=map(int,input().split()) s=[''.join([str(a)]*b),''.join([str(b)]*a)] print(sorted(s)[0])
0
null
97,296,561,757,010
253
232
def is_leq_S(A, lim, K): S = [0] * K ai = 0 si = 0 while ai < len(A): if S[si] + A[ai] <= lim: S[si] += A[ai] ai += 1 else: si += 1 if si == K: return False return True def main(): N, K = [int(_) for _ in input().split()] A = [] for _ in range(N): A.append(int(input())) l = 0 r = 100000 * 100000 while l + 1 < r: m = (l + r) // 2 if is_leq_S(A, m, K): S = m r = m else: l = m print(S) main()
from heapq import heappush, heappop N, M = map(int, input().split()) s = input() INF = 10**18 dp_cnt = [INF]*(N+1) dp_next = [0]*(N+1) dp_cnt[N] = 0 q = [(0,N)] for i in range(N-1, -1, -1): while True: cnt, j = q[0] if j-i>M: heappop(q) else: break dp_cnt[i] = cnt if s[i]=='1': cnt = INF j = 0 cnt += 1 heappush(q, (cnt, i)) dp_next[i] = j if dp_cnt[0]>=INF: print(-1) exit() x = 0 ans = [] while x<N: y = dp_next[x] ans += [str(y-x)] x = y print(*ans)
0
null
69,960,274,536,374
24
274
N = int(input()) A = list(map(int, input().split())) B = [i for i in A if i % 2 == 0] o = 'APPROVED' for i in B: if i % 3 != 0 and i % 5 != 0: o = 'DENIED' break print(o)
from itertools import groupby s = input() A = [(key, sum(1 for _ in group)) for key, group in groupby(s)] tmp = 0 ans = 0 for key, count in A: if key == '<': ans += count*(count+1)//2 tmp = count else: if tmp < count: ans -= tmp ans += count ans += (count-1)*count//2 tmp = 0 print(ans)
0
null
112,447,527,406,510
217
285
a,v = map(int,input().split()) b,w = map(int,input().split()) t = int(input()) if a > b: oni = a + (-1*v) * t nige = b + (-1*w) * t if oni <= nige: print("YES") else: print("NO") else: oni = a + v*t nige = b + w * t if oni >= nige: print("YES") else: print("NO")
class SegmentTree(): def __init__(self,n): self.e = 0 self.r = 0 #ノードの段数 cnt = 0 while cnt<n: cnt=2**self.r self.r +=1 self.tree = [self.e]*(2**self.r -1)# 0-index self.n = 2**(self.r-1) #一番下のnodeの数 def func(self,a,b): #適宜書き換え return a|b def update(self,i,val): i += self.n -1 self.tree[i] = val while i>0: i = (i-1)//2 self.tree[i] = self.func(self.tree[i*2+1],self.tree[i*2+2]) def query(self,l,r): l += self.n -1 r += self.n -1 #開区間 idxはr-1 lval = self.e rval = self.e while r>l: if l%2 == 0: lval = self.func(lval,self.tree[l]) l+=1 if r%2==0: rval = self.func(rval,self.tree[r-1]) r-=1 r//=2 l//=2 return self.func(lval,rval) def index(self,i): return i+self.n -1 def sid(s): return ord(s)-ord("a") #chr("a") == 0 import sys input = sys.stdin.readline n = int(input()) S = input()[:-1] Q = int(input()) seg = SegmentTree(n) for i in range(n): s = S[i] seg.update(i,2**(sid(s))) for q in range(Q): num,a,b = input().split() if num=="1": seg.update(int(a)-1,2**sid(b)) #print(a,b,list(map(lambda x:bin(x)[2:],seg.tree))) else: print(bin(seg.query(int(a)-1,int(b))).count("1"))
0
null
38,763,742,887,620
131
210
n = int(input()) l = list(map(int, input().split())) def judge(l, i, j, k): a = l[i] b = l[j] c = l[k] if a != b and b != c and c != a: if a + b > c and b + c > a and c + a > b: return 1 else: return 0 else: return 0 cnt = 0 for i in range(n - 2): for j in range(i + 1, n - 1): for k in range(j + 1, n): cnt += judge(l, i, j, k) print(cnt)
n = int(input()) l = list(sorted(map(int, input().split()))) x = 0 if n >= 3: for k in range(n - 2): for j in range(k + 1): for i in range(j + 1): if l[i] < l[j + 1] < l[k + 2] and l[i] + l[j + 1] > l[k + 2]: x += 1 print(x)
1
5,040,412,632,614
null
91
91
N = int(input()) kuku = [] for x in range(1,10): for y in range(1,10): kuku.append(x*y) if N in kuku: print('Yes') else: print('No')
def modpow(a, b, mod): ret = 1 while b > 0: if b % 2 == 1: ret = ret * a % mod a = a * a % mod b //= 2 return ret mod = 10 ** 9 + 7 N, K = map(int, input().split()) LUT, ans = [0] * (K + 1), 0 for g in range(K, 0, -1): LUT[g] = modpow(K // g, N, mod) LUT[g] = (LUT[g] - sum([LUT[i] for i in range(g * 2, K + 1, g)])) % mod for i in range(K + 1): ans = (ans + i * LUT[i]) % mod print(ans)
0
null
97,963,039,978,164
287
176
import math hp, attack = map(int, input().split()) print(math.ceil(hp / attack)) # x, y = divmod(hp, attack) # # if y == 0: # print(x) # else: # print(x + 1) # count = 0 # # while True: # hp -= attack # count += 1 # # if hp <= 0: # print(count) # break #
h,a = map(int, input().split()) an, bn = divmod(h,a) if bn == 0: print(an) else: print(an+1)
1
76,932,046,489,280
null
225
225
x = int(input()) if 30 <= x: print("Yes") else: print("No")
import sys #from collections import defaultdict, deque, Counter #from bisect import bisect_left #import heapq #import math #from itertools import groupby as gb #from itertools import permutations as perm #from itertools import combinations as comb #from fractions import gcd #import numpy as np stdin = sys.stdin sys.setrecursionlimit(10 ** 7) MIN = -10 ** 9 MOD = 10 ** 9 + 7 INF = float("inf") IINF = 10 ** 18 #n = int(stdin.readline().rstrip()) #l = list(map(int, stdin.readline().rstrip().split())) n,m = map(int, stdin.readline().rstrip().split()) #AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)] if n==m: print("Yes") else: print("No")
0
null
44,644,327,619,460
95
231
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, input().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): h, a = MI() ans = h // a if h % a != 0: ans += 1 print(ans) main()
n = int(input()) for i in range(n): a,b,c = map(int,input().split(" ")) if a**2 == b**2 + c**2: print("YES") elif b**2 == a**2 + c**2: print("YES") elif c**2 == a**2 + b**2: print("YES") else: print("NO")
0
null
38,642,086,203,718
225
4
n = int(raw_input()) A = map(int, raw_input().strip().split(' ')) q = int(raw_input()) M = map(int, raw_input().strip().split(' ')) S = [0]*len(A) flags = [False]*len(M) def brute_force(n): if n == len(S): ans = 0 for i in range(len(S)): if S[i] == 1: ans += A[i] for i in range(len(M)): if ans == M[i]: flags[i] = True else: S[n] = 0 brute_force(n+1) S[n] = 1 brute_force(n+1) brute_force(0) for flag in flags: if flag: print "yes" else: print "no"
n = int(input()) a = list(map(int,input().split())) c = [0,0,0] count = 1 for i in range(n): match = (a[i]==c[0])+(a[i]==c[1])+(a[i]==c[2]) if match==0: count = 0 break elif match==1 or a[i]==0: c[c.index(a[i])] += 1 else: c[c.index(a[i])] += 1 count = (count*match)%(1e+9+7) if count != 0: c = sorted(c,reverse=True) while 0 in c: c.pop() memory = set() kinds = 0 for x in c: if not x in memory: kinds += 1 for i in range(3,3-kinds,-1): count = (count*i)%(1e+9+7) print(int(count))
0
null
65,275,385,912,088
25
268
n = int(input()) s = list(input()) s = [ord(i)-97 for i in s] dic = {} for i in range(26): dic[i] = [] for i in range(n): dic[s[i]].append(i) for i in range(26): dic[i].append(float('inf')) from bisect import bisect_left q = int(input()) for i in range(q): x, y, z = input().split() if x == '1': y, z = int(y) - 1, ord(z) - 97 p = bisect_left(dic[s[y]], y) dic[s[y]].pop(p) dic[z].insert(bisect_left(dic[z], y), y) s[y] = z else: res = 0 y, z = int(y) - 1, int(z) - 1 for i in range(26): p = dic[i][bisect_left(dic[i], y)] if p <= z: res += 1 print(res)
def main(): k = int(input()) s = input() n = len(s) def cmb1(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 = 10**9+7 N = 2*10**6 fac = [1]*(N+1) finv = [1]*(N+1) for i in range(N): fac[i+1] = fac[i] * (i+1) % mod finv[-1] = pow(fac[-1], mod-2, mod) for i in reversed(range(N)): finv[i] = finv[i+1] * (i+1) % mod def cmb1(n, r, mod): if r <0 or r > n: return 0 r = min(r, n-r) return fac[n] * finv[r] * finv[n-r] % mod def power(a, n, mod): bi=str(format(n,"b")) #2進数 res=1 for i in range(len(bi)): res=(res*res) %mod if bi[i]=="1": res=(res*a) %mod return res ans = 0 for i in range(k+1): temp = power(25, i, mod) temp *= cmb1(i+n-1, n-1, mod) temp %= mod temp *= power(26, k-i, mod) temp %= mod ans += temp print(ans%mod) if __name__ == '__main__': main()
0
null
37,574,945,362,910
210
124
def draw(h, w): for i in range(h): if i % 2 == 0: print(("#."*w)[:w]) else: print((".#"*w)[:w]) print("") while True: H, W = map(int, input().split()) if H == W == 0: break draw(H, W)
cnt = 0 x = int(input()) m = 100 for i in range(4000): if m >= x: print(i) exit() else: m += m//100
0
null
13,970,315,382,538
51
159
t1,t2=map(int,input().split()) a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) if a1>b1 and a2>b2: print(0) elif b1>a1 and b2>a2: print(0) elif a1*t1+a2*t2==b1*t1+b2*t2: print("infinity") else: ans=-1 num2=-1 num3=-1 if a1*t1+a2*t2>b1*t1+b2*t2: if a1>b1: ans=0 else: num2=(b1-a1)*t1 num3=((a1-b1)*t1)+((a2-b2)*t2) if num2//num3==num2/num3: ans=(num2//num3)*2 else: ans=(num2//num3)*2+1 else: if b1>a1: ans=0 else: num2=(a1-b1)*t1 num3=((b1-a1)*t1)+((b2-a2)*t2) if num2//num3==num2/num3: ans=(num2//num3)*2 else: ans=(num2//num3)*2+1 print(ans)
n, m, q = map(int, input().split()) candidate = [] def gen(cur): if len(cur) == n: candidate.append(cur) else: t = cur[-1] for tv in range(t, m + 1): nex = cur[:] nex.append(tv) gen(nex) for i in range(1, m + 1): arr = [i] gen(arr) ask = [] for _ in range(q): ask.append(list(map(int, input().split()))) ans = 0 for cv in candidate: tmp = 0 for av in ask: if cv[av[1] - 1] - cv[av[0] - 1] == av[2]: tmp += av[3] ans = max(ans, tmp) print(ans)
0
null
79,218,134,381,060
269
160
def coin(larger=False, single=False): """ ナップサックに入れる重さが W 丁度になる時の価値の最小値 :param larger: False = (重さ = W)の時の最小価値 True = (重さ =< W)の時の最小価値 :param single: False = 重複あり dp[weight <= W+1] = 重さを固定した時の最小価値 dp[W+1] = 重さがWより大きい時の最小価値 """ W2 = W + 1 # dp[W+1] に W より大きい時の全ての場合の情報を持たせる dp_max = float("inf") # 総和価値の最大値 dp = [dp_max] * (W2 + 1) dp[0] = 0 # 重さ 0 の時は価値 0 for item in range(N): if single: S = range(W2, weight_list[item] - 1, -1) else: S = range(W2) for weight in S: dp[min2(weight + weight_list[item], W2)] = min2(dp[min2(weight + weight_list[item], W2)], dp[weight] + cost_list[item]) if larger: return min(dp[w] for w in range(W, W2+1)) else: return dp[W] ####################################################################################################### import sys input = sys.stdin.readline def max2(x, y): return x if x > y else y def min2(x, y): return x if x < y else y W, N = map(int, input().split()) # N: 品物の種類 W: 重量制限 cost_list = [] weight_list = [] for _ in range(N): """ cost と weight が逆転して入力されている場合有り """ weight, cost = map(int, input().split()) cost_list.append(cost) weight_list.append(weight) print(coin(larger=True, single=False))
def chmin(dp, i, *x): dp[i] = min(dp[i], *x) INF = float("inf") # dp[i] := min 消耗する魔力 to H -= i h, n = map(int, input().split()) dp = [0] + [INF]*h for _ in [None]*n: a, b = map(int, input().split()) for j in range(h + 1): chmin(dp, min(j + a, h), dp[j] + b) print(dp[h])
1
80,908,806,222,988
null
229
229
P = 10**9+7 N, K = map(int, input().split()) S = list(map(int, input().split())) S.sort() ans = 0 c = 1 for i in range(N-K+1): ans += (S[K-1+i]*c)%P ans -= (S[N-K-i]*c)%P ans %= P c = c*(K+i)*pow(i+1, P-2, P)%P print(ans)
k, m = list(map(int, input().split())) if 500 * k >= m: print('Yes') elif 500 * k < m: print('No') else: print('No')
0
null
97,074,803,230,432
242
244
N=int(input()) P=list(map(int,input().split())) m=N ans=0 for i in range(N): if m>=P[i]: ans+=1 m=min(m,P[i]) print(ans)
import math def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def solve(): N = read_int() P = read_ints() min_so_far = math.inf count = 0 for p in P: min_so_far = min(min_so_far, p) if min_so_far >= p: count += 1 return count if __name__ == '__main__': print(solve())
1
85,537,043,627,070
null
233
233
def pop_count(n): return bin(n).count("1") def f(n): if n == 0: return 0 return f(n % pop_count(n)) + 1 N = int(input()) X = list(map(int, input())) X_m = 0 X_p = 0 pop_X = X.count(1) for i in range(N): if X[i] == 0: continue X_p += pow(2, N - i - 1, pop_X + 1) X_p %= pop_X + 1 if pop_X > 1: X_m += pow(2, N - i - 1, pop_X - 1) X_m %= pop_X - 1 for i in range(N): ans = 1 if X[i] == 0: ans += f((X_p + pow(2, N - i - 1, pop_X + 1)) % (pop_X + 1)) elif pop_X > 1: ans += f((X_m - pow(2, N - i - 1, pop_X - 1)) % (pop_X - 1)) else: ans = 0 print(ans)
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy # from collections import Counter,defaultdict,deque # from itertools import permutations, combinations # from heapq import heappop, heappush # # input = sys.stdin.readline # sys.setrecursionlimit(10**8) # mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() s = input() pre = '' ans = 0 for t in s: if(pre != t): ans += 1 pre = t print(ans)
0
null
89,441,297,672,452
107
293
n = input() for e in n: if e == '7': print('Yes') break else: print('No')
if "7" in input(): print("Yes") else: print("No")
1
34,082,145,807,190
null
172
172
N = int(input()) S,T = input().split() for s,t in zip(S,T): print(s+t,end="")
while True: s = input() if s=="0": break print(sum(map(int,s)))
0
null
57,092,460,260,668
255
62
n = int(input()) def dfs(s, mx_idx): if len(s) == n: print(s) else: for i in range(mx_idx+1): nc = chr(ord('a') + i) if i == mx_idx: dfs(s + nc, mx_idx + 1) else: dfs(s+nc, mx_idx) dfs('a', 1)
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) MOD = 10 ** 9 + 7 N = int(input()) lst1 = [('a', 0)] lst2 = [] for i in range(N - 1): if i % 2 == 0: #lst1 -->lst2 lst2 = [] for s, t in lst1: last = max(ord(s[i]) - ord('a'), t) for j in range(last + 2): lst2.append((s + chr(j + ord('a')), max(t, j))) else: lst1 = [] for s, t in lst2: last = max(ord(s[i]) - ord('a'), t) for j in range(last + 2): lst1.append((s + chr(j + ord('a')), (max(t, j)))) if len(lst2) > len(lst1): lst2.sort() for s, t in lst2: print (s) else: lst1.sort() for s, t in lst1: print (s)
1
52,166,290,033,020
null
198
198
# YouTube解説 MOD = 1000000007 n, k = [int(x) for x in input().split()] d = [pow(k // i, n, MOD) if i > 0 else 0 for i in range(0, k + 1)] for i in range(k, 0, -1): # 大きいほうから for j in range(i * 2, k + 1, i): # iの倍数 # d[6] = d'[6] - d[12] - d[18] ... d[i] -= d[j] d[i] %= MOD ans = 0 for i, item in enumerate(d): ans += i * item ans %= MOD print(ans)
N, K = map(int, input().split()) numgcd = [0]*(K+1) sumgcd = 0 mod = 10**9+7 for i in range(1, K+1)[::-1]: numgcd[i] = pow(K//i, N, mod) count = 2 while count*i <= K: numgcd[i] -= numgcd[count*i] count += 1 sumgcd += numgcd[i]*i print(sumgcd%mod)
1
36,653,321,830,690
null
176
176
[W,H,x,y,r] = input().split(' ') W = int(W) H = int(H) x = int(x) y = int(y) r = int(r) h = False if r<=x and x <= W - r and r <=y and y <= H - r: print ('Yes') else: print ('No')
S = input() A = S.count("R") B = S.count("RR") if A==2: if B==1: print(2) if B==0: print(1) elif A==1: print(1) elif A==3: print(3) else : print(0)
0
null
2,663,528,934,980
41
90
N,K,*A=map(int,open(0).read().split()) 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])
from sys import stdin from math import ceil inp = lambda : stdin.readline().strip() n, x, t = [int(x) for x in inp().split()] print(ceil(n/x)*t)
0
null
9,903,054,825,698
132
86
import sys, math import bisect sys.setrecursionlimit(500000) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] def isPrime(n): if n < 2: return False i = 2 while i*i <= n: if n%i==0: return False i += 1 return True def main(): l = [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 = ii() print(l[K-1]) if __name__ == '__main__': main()
c = [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] N = n=int(input()) print(c[N-1])
1
50,364,225,394,438
null
195
195
s = str(input()) t = str(input()) t_before = '' for i in range(len(s)): t_before += t[i] if s == t_before: print('Yes') else: print('No')
def registration(): S = input() T = input() for i, j in enumerate(S): if T[i] != j: break else: print("Yes") return print("No") registration()
1
21,392,467,772,698
null
147
147
import sys from fractions import gcd read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def lcm(x, y): return x * y // gcd(x, y) def main(): N, M = map(int, input().split()) A = list(map(int, input().split(" "))) A = [a // 2 for a in A] semi_lcm = 1 for a in A: semi_lcm = lcm(semi_lcm, a) if semi_lcm > M or semi_lcm // a % 2 == 0: print(0) return print((M // semi_lcm + 1) // 2) return if __name__ == '__main__': main()
from math import gcd n, m = map(int, input().split()) A = list(map(int, input().split())) A = [a//2 for a in A] lcm = 1 for i in range(n): lcm = lcm * A[i] // gcd(lcm, A[i]) if lcm > m: print(0) exit() for a in A: if lcm // a % 2 == 0: print(0) exit() print((m//lcm + 1) // 2)
1
101,552,623,482,940
null
247
247
from math import gcd k=int(input()) ans = 0 for a in range(1,k+1): for b in range(1,k+1): gab=gcd(a,b) for c in range(1,k+1): ans+=gcd(gab,c) print(ans)
import math from functools import reduce INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) def do(): k=INT() ans=0 for i in range(1,k+1): for j in range(1,k+1): for h in range(1,k+1): ans+=math.gcd(math.gcd(i,j),h) #print(ans,i,j,h) print(ans) if __name__ == '__main__': do()
1
35,823,442,393,398
null
174
174
def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a // gcd(a, b) * b n = int(input()) a = list(map(int, input().split())) l = 1 for i in a: l = lcm(l, i) ans = 0 for i in a: ans += l // i print(ans % 1000000007)
MOD = 10**9 + 7 def main(): import sys input = sys.stdin.buffer.readline _ = int(input()) A = [int(i) for i in input().split()] def gcd(x, y): if y == 0: return x while y != 0: x, y = y, x % y return x def lcm(x, y): return x*y//gcd(x, y) L = A[0] for a in A[1:]: L = lcm(L, a) L %= MOD ans = 0 for a in A: ans += L*pow(a, MOD-2, MOD) print(ans % MOD) if __name__ == '__main__': main()
1
87,851,031,199,064
null
235
235
import bisect N = int(input()) L = sorted([int(i) for i in input().split()]) ans = 0 for j in range(N-2): for k in range(j+1,N-1): S = L[j] + L[k] a = bisect.bisect_left(L, S) ans += a - 1 - k print(ans)
import bisect N=int(input()) L=list(map(int,input().split())) L=sorted(L) ans=0 for i in range(N-1): for k in range(i+1,N-1): a=L[i]+L[k] b=bisect.bisect_left(L,a) ans=ans+(b-k-1) print(ans)
1
171,602,777,109,540
null
294
294
import sys stdin = sys.stdin ns = lambda : stdin.readline().rstrip() ni = lambda : int(ns()) na = lambda : list(map(int, stdin.readline().split())) sys.setrecursionlimit(10 ** 7) def main(): m, d = na() n, s = na() if s == 1: print(1) else: print(0) if __name__ == '__main__': main()
p = 10**9+7 N = int(input()) A = list(input().split()) B = [0 for _ in range(N)] for i in range(N): a = A[i] b = bin(int(a))[2:] b = "0"*(60-len(b))+b B[i] = b C = {i:0 for i in range(60)} for j in range(60): cnt = 0 for i in range(N): if B[i][j]=="1": cnt += 1 C[j] = cnt tot = 0 for j in range(60): n = C[j] k = (N*(N-1))//2-(n*(n-1))//2-((N-n)*(N-n-1))//2 tot = (tot+k*(2**(60-1-j)))%p print(tot)
0
null
123,569,939,905,490
264
263
import sys alphabets = range(ord('a'), ord('z') + 1) dic = { chr(c): 0 for c in alphabets } text = sys.stdin.read() for c in text: c = c.lower() if ord(c) in alphabets: dic[c] += 1 for c, n in sorted(dic.items()): print(c, ":", n)
a = [list(map(int,input().split())) for _ in range(3)] n = int(input()) b = [int(input()) for _ in range(n)] for k in range(n): for i in range(3): for j in range(3): if a[i][j]==b[k]: a[i][j]=-1 def result(): for i in range(3): if a[i][0]==a[i][1]==a[i][2]==-1 or a[0][i]==a[1][i]==a[2][i]==-1: return 'Yes' if a[0][0]==a[1][1]==a[2][2]==-1 or a[0][2]==a[1][1]==a[2][0]==-1: return 'Yes' else: return 'No' print(result())
0
null
30,911,364,311,808
63
207
N=int(input()) d=[] for x in range(N): S=input() d.append(S) print(len(set(d)))
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,202,844,577,380
null
165
165
# -*- coding utf-8 -*- MOD = 10 ** 9 + 7 r = int(input()) ans = r * r print(ans)
top = 0 def push(x): global top L.append(x) top += 1 def pop(): global top x = L.pop(top) top -= 1 return x L = [0] S = input().split() for i in S: if i == "+": a = pop() b = pop() push(a + b) elif i == "-": a = pop() b = pop() push(b - a) elif i == "*": a = pop() b = pop() push(a * b) else: push(int(i)) print(str(pop()))
0
null
72,445,894,936,998
278
18
s = input().split() st = [] for i in range(len(s)): c = s.pop(0) if c == '+': b = st.pop(0) a = st.pop(0) ans = a + b st.insert(0,ans) elif c == '-': b = st.pop(0) a = st.pop(0) ans = a - b st.insert(0,ans) elif c == '*': b = st.pop(0) a = st.pop(0) ans = a * b st.insert(0,ans) else: st.insert(0, int(c)) print(st.pop(0))
stack = input().split() temp = [] num=0 for loop in stack: a = loop if a is "+": num = temp.pop() + temp.pop() temp.append(num) elif a is "-": b=temp.pop() c=temp.pop() num = c-b temp.append(num) elif a is "*": num = temp.pop() * temp.pop() temp.append(num) else: temp .append(int(a)) print(temp[0])
1
36,465,475,830
null
18
18
def readinput(): n=int(input()) a=list(map(int,input().split())) return n,a def main(n,a): a.sort() for i in range(n-1): if a[i]==a[i+1]: return 'NO' return 'YES' if __name__=='__main__': n,a=readinput() ans=main(n,a) print(ans)
import math def koch(start, end, n, r): if n > 0: #途中の頂点をa, b, cとする a = [(start[0]*2 + end[0]*1) / 3, (start[1]*2 + end[1]*1) / 3] c = [(start[0]*1 + end[0]*2) / 3, (start[1]*1 + end[1]*2) / 3] x = c[0] - a[0] y = c[1] - a[1] b = [x * math.cos(math.pi/3) - y * math.sin(math.pi/3) + a[0], x * math.sin(math.pi/3) + y * math.cos(math.pi/3) + a[1]] koch(start, a, n-1, r) koch(a, b, n-1, r) koch(b, c, n-1, r) koch(c, end, n-1, r) else: r.append(start) n = int(input()) r = [] koch([0, 0], [100, 0], n, r) r.append([100, 0]) for rr in r: print(str(rr[0]) + ' ' + str(rr[1]))
0
null
36,809,213,601,280
222
27
x,k,d = map(int, input().split()) if x == 0: if k % 2 == 1: x = d elif x > 0: if x >= k*d: x -= k*d else: n = x//d x -= n*d k -= n if k%2 ==1: x -= d else: if x <= -(k*d): x += k*d else: n = abs(x)//d x += n*d k -= n if k%2 ==1: x += d print(abs(x))
def main(): H, W, K = map(int, input().split()) chocolate = [list(map(int,list(input()))) for _ in range(H)] choco = [[0]*W for _ in range(H)] ids = [0] * H ans = 10 ** 9 for bit in range(1<<(H-1)): group_id = 0 for i in range(H): ids[i] = group_id if (bit>>i)&1: group_id += 1 group_id += 1 for i in range(group_id): for j in range(W): choco[i][j] = 0 for i in range(H): for j in range(W): choco[ids[i]][j] += chocolate[i][j] if any(choco[i][j] > K for i in range(group_id) for j in range(W)): continue num = group_id - 1 now = [0] * group_id def add(j): for i in range(group_id): now[i] += choco[i][j] if any(now[i] > K for i in range(group_id)): return False else: return True for j in range(W): if not add(j): num += 1 now = [0] * group_id add(j) ans = min(ans, num) print(ans) if __name__ == "__main__": main()
0
null
26,963,453,973,498
92
193