code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
import sys input = sys.stdin.readline # 二分木 import bisect n,d,a = map(int,input().split()) xh = [list(map(int, input().split())) for _ in range(n)] xh.sort() x = [ tmp[0] for tmp in xh] damage = [0] * (n+1) ans = 0 for i in range(n): damage[i+1] += damage[i] if( damage[i+1] >= xh[i][1] ): continue atk_num = (xh[i][1] - damage[i+1] - 1)//a +1 ans += atk_num damage[i+1] += atk_num * a right = bisect.bisect_right(x, xh[i][0] + 2*d) if( right < n): damage[right+1] -= atk_num * a print(ans)
import bisect import math N,D,A=map(int,input().split()) tmp=[list(map(int,input().split())) for i in range(N)] tmp.sort(key=lambda x:x[0]) monster=[];X=[] for i in range(N): monster.append(tmp[i][1]);X.append(tmp[i][0]) minus=[0]*(N+1) ans=0 damage=0 for i in range(N): damage-=minus[i] monster[i]=max(0,monster[i]-damage) if(monster[i]==0): continue cnt=math.ceil(monster[i]/A) monster[i]=0 ans+=cnt b=bisect.bisect_left(X,X[i]+2*D+1) minus[b]+=cnt*A damage+=A*cnt print(ans)
1
81,756,486,445,952
null
230
230
import sys input = sys.stdin.readline sys.setrecursionlimit(10**8) def main(): n,m = map(int,input().split()) x = m//2 y = m - x for i in range(x): print(i+1,2*x+1-i) for i in range(y): print(2*x+2+i,2*x+2*y+1-i) if __name__ == "__main__": main()
n, m = map(int, input().split()) def out(s, e): while s < e: print("{} {}".format(s, e)) s += 1 e -= 1 if m % 2 == 0: out(1, m) out(m + 1, 2 * m + 1) else: out(1, m + 1) out(m + 2, 2 * m + 1)
1
28,591,671,576,540
null
162
162
n = int(raw_input().strip()) commands = [] for i in range(n): commands.append(raw_input().strip()) d = [False]*67108870 def hash(s): ret = 0 i = 0 for dg in s: if dg == 'A': ret += 0 * 4**i elif dg == 'C': ret += 1 * 4**i elif dg == 'G': ret += 2 * 4**i elif dg == 'T': ret += 3 * 4**i i += 1 return ret def insert(d,s): h = hash(s) d[h] = True def find(d,s): h = hash(s) if d[h]: print 'yes' else: print 'no' for c in commands: c += 'C' if c[0] == 'i': insert(d,c[7:]) else: find(d,c[5:])
n = int(input()) h = {} for i in range(n): op, st = input().split() if op == 'insert': h[st] = 'yes' else: print (h.get(st, 'no'))
1
77,881,693,970
null
23
23
n = int(input()) x = list(map(int,input().split())) ans = 1000000000000 for i in range(1,101): b = 0 for num in x: b += (num - i)**2 ans = min(b,ans) print(ans)
while True: h, w = map(int, input().split()) if h == 0 and w == 0: break print("#" * w) for _ in range(h-2): print("#","." * (w-2), "#", sep="") print("#" * w) print()
0
null
32,936,404,124,260
213
50
N = int(input()) multiplication = [] for x in range(1, 10): for y in range(1, 10): multiplication.append(x*y) if N in multiplication: print( "Yes" ) else: print( "No" )
import sys def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 a = [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 = I() print(a[K -1 ])
0
null
104,996,538,645,700
287
195
a, b, m = map(int, input().split()) reizo = list(map(int, input().split())) renji = list(map(int, input().split())) p = [list(map(int,input().split())) for i in range(m)] ans = [] for i in range(m): cost = reizo[p[i][0] - 1] + renji[p[i][1] - 1] - p[i][2] ans.append(cost) ans.append(min(reizo) + min(renji)) print(min(ans))
n,m = map(int, input().split()) shukudai = sum(list(map(int,input().split()))) if n >= shukudai: print(n-shukudai) else: print(-1)
0
null
43,068,381,126,588
200
168
c=str(input()) print('Yes' if c[2]==c[3] and c[4]==c[5] else'No')
s=str(input()) j="No" if s[2]==s[3] and s[4]==s[5]: j="Yes" print(j)
1
42,120,363,641,642
null
184
184
S=input().split("S") print(len(max(S)))
import math a, b, n = map(int, input().split()) x = min(b - 1, n) ans = math.floor(a * x / b) - a * math.floor(x / b) print(ans)
0
null
16,427,874,871,968
90
161
from collections import Counter N = int(input()) A = list(map(int, input().split())) Q = int(input()) BC = [list(map(int, input().split())) for _ in range(Q)] counter = Counter(A) counter_sum = sum(k*v for k, v in counter.items()) for b, c in BC: counter[c] += counter[b] counter_sum -= b * counter[b] counter_sum += c * counter[b] counter[b] = 0 print(counter_sum)
import math import collections N = int(input()) Point = collections.namedtuple('Point', ['x', 'y']) def koch(d, p1, p2): if d == 0: return th = math.pi * 60 / 180 s = Point(x=(2 * p1.x + p2.x) / 3, y=(2 * p1.y + p2.y) / 3) t = Point(x=(p1.x + 2 * p2.x) / 3, y=(p1.y + 2 * p2.y) / 3) u = Point(x=(t.x - s.x) * math.cos(th) - (t.y - s.y) * math.sin(th) + s.x, y=(t.x - s.x) * math.sin(th) + (t.y - s.y) * math.cos(th) + s.y) koch(d - 1, p1, s) print('{:.8f} {:.8f}'.format(s.x, s.y)) koch(d - 1, s, u) print('{:.8f} {:.8f}'.format(u.x, u.y)) koch(d - 1, u, t) print('{:.8f} {:.8f}'.format(t.x, t.y)) koch(d - 1, t, p2) p1 = Point(x=0, y=0) p2 = Point(x=100, y=0) print('{:.8f} {:.8f}'.format(p1.x, p1.y)) koch(N, p1, p2) print('{:.8f} {:.8f}'.format(p2.x, p2.y))
0
null
6,209,606,670,320
122
27
def resolve(): H, A = list(map(int, input().split())) import math print(math.ceil(H/A)) if '__main__' == __name__: resolve()
def main(): N = int(input()) price = [int(input()) for i in range(N)] minv = float("inf") maxv = -float("inf") for p in price: maxv = max(maxv, p-minv) minv = min(minv, p) print(maxv) if __name__ == "__main__": import os import sys if len(sys.argv) > 1: if sys.argv[1] == "-d": fd = os.open("input.txt", os.O_RDONLY) os.dup2(fd, sys.stdin.fileno()) main() else: main()
0
null
38,474,552,248,740
225
13
N=int(input()) A=list(map(int,input().split())) total=sum(A) cost=total cumulative=0 for i in range(N): cumulative+=A[i] cost=min(cost,abs(cumulative-(total-cumulative))) print(cost)
n = int(input()) A = list(map(int, input().split())) count = 0 def swap(a, b): t = a a = b b = t return [a, b] def selection_sort(l): global count for i in range(0, len(l)): mini = i for j in range(i, len(l)): if l[j] < l[mini]: mini = j if i != mini: count += 1 l[i], l[mini] = swap(l[i], l[mini]) return l l = selection_sort(A) print(' '.join(str(x) for x in l)) print(count)
0
null
70,695,587,221,632
276
15
n = int(input()) lst = [int(i) for i in input().split()] lst.sort() #print(lst) if 1 in lst: count = 0 for i in range(n): if lst[i] == 1: count += 1 if count == 2: break if count == 1: print(1) else: print(0) else: tf_lst = [1] * lst[n - 1] count = 0 if n > 1: pre = 0 for i in range(n): tf_lst[pre:lst[i] - 1] = [0] * (lst[i] - pre - 1) pre = lst[i] if tf_lst[lst[i] - 1] == 0: continue if i <= n - 2: if lst[i] == lst[i + 1]: tf_lst[lst[i] - 1] = 0 for j in range(lst[i] * 2, lst[n - 1] + 1, lst[i]): tf_lst[j - 1] = 0 #print(tf_lst) for i in tf_lst: count += i else: count += 1 print(count)
n,k=map(int,input().split()) def main(n,k): if n//k: return main(n//k,k)+str(n%k) return str(n%k) print(len(main(n,k)))
0
null
39,532,113,334,072
129
212
N = int(input()) c = input() l = len(c) a = 0 b = 0 for i in range(l): if c[i] == "R": a += 1 for i in range(a, l): if c[i] == "R": b += 1 print(b)
import math N, M = map(int, input().split()) if N%2 == 1: a = 1 b = N for i in range(M): print(a,b) a += 1 b -= 1 else: m = N//2 - 1 a = N//4 b = a + 1 c = N//2 + N//4 d = c + 2 for i in range(M): if i%2 == 0: print(a,b) a -= 1 b += 1 else: print(c,d) c -= 1 d += 1
0
null
17,569,722,280,838
98
162
from logging import * basicConfig(level=DEBUG, format='%(levelname)s: %(message)s') disable(CRITICAL) MOD = 10**9 + 7 INF = MOD def mmul(a, b): return a*b%MOD n, k = map(int, input().split()) A = [*map(int, input().split())] P, M = [], [] # plus, minus for a in A: if a < 0: M.append(a) else: P.append(a) debug('A {}'.format(sorted(A, reverse=True, key=lambda x:abs(x)))) def mix(): len_p = len(P); len_m = len(M) P.sort(reverse=True); M.sort() P.append(-1); M.append( 1) # add endpoint debug('P {}'.format(P));debug('M {}'.format(M)) pa, ma = [], [] while len(pa) + len(ma) < k: if P[len(pa)] < -M[len(ma)]: ma.append(M[len(ma)]) else: pa.append(P[len(pa)]) debug('pa {}'.format(pa));debug('ma {}'.format(ma)) if len(ma)%2 == 0: return pa + ma exist_pa = len(pa) > 0; exist_ma = len(ma) > 0 remain_p = len_p - len(pa) > 0; remain_m = len_m - len(ma) > 0 debug('exist_pa {}'.format(exist_pa));debug('exist_ma {}'.format(exist_ma)) debug('remain_p {}'.format(remain_p));debug('remain_m {}'.format(remain_m)) if exist_pa & exist_ma & remain_p & remain_m: p_in = pa[-1]; p_out = P[len(pa)] m_in = ma[-1]; m_out = M[len(ma)] if abs(p_in*p_out) < abs(m_in*m_out): pa.pop(); ma.append(m_out) else: ma.pop(); pa.append(p_out) debug('pa {}'.format(pa));debug('ma {}'.format(ma)) return pa + ma # if (not exist_pa) & exist_ma & remain_p & (not remain_m): # if exist_ma & remain_p & (not remain_m): if exist_ma & remain_p: m_in = ma[-1]; p_out = P[len(pa)] ma.pop(); pa.append(p_out) debug('pa {}'.format(pa));debug('ma {}'.format(ma)) return pa + ma # if exist_pa & (not exist_ma) & (not remain_p) & remain_m: # if exist_pa & (not remain_p) & remain_m: if exist_pa & remain_m: p_in = pa[-1]; m_out = M[len(ma)] pa.pop(); ma.append(m_out) debug('pa {}'.format(pa));debug('ma {}'.format(ma)) return pa + ma # -------------------------------- P.pop(); M.pop() P.sort(); M.sort(reverse=True) P.append(-1); M.append( 1) # add endpoint debug('---') debug('P {}'.format(P));debug('M {}'.format(M)) pa, ma = [], [] while len(pa) + len(ma) < k: if P[len(pa)] >= -M[len(ma)]: ma.append(M[len(ma)]) else: pa.append(P[len(pa)]) debug('pa {}'.format(pa));debug('ma {}'.format(ma)) if len(ma)%2 == 1: return pa + ma exist_pa = len(pa) > 0; exist_ma = len(ma) > 0 remain_p = len_p - len(pa) > 0; remain_m = len_m - len(ma) > 0 debug('exist_pa {}'.format(exist_pa));debug('exist_ma {}'.format(exist_ma)) debug('remain_p {}'.format(remain_p));debug('remain_m {}'.format(remain_m)) if exist_pa & exist_ma & remain_p & remain_m: p_in = pa[-1]; p_out = P[len(pa)] m_in = ma[-1]; m_out = M[len(ma)] if abs(p_in*p_out) >= abs(m_in*m_out): pa.pop(); ma.append(m_out) else: ma.pop(); pa.append(p_out) debug('pa {}'.format(pa));debug('ma {}'.format(ma)) return pa + ma # if (not exist_pa) & exist_ma & remain_p & (not remain_m): if exist_ma & remain_p: m_in = ma[-1]; p_out = P[len(pa)] ma.pop(); pa.append(p_out) debug('pa {}'.format(pa));debug('ma {}'.format(ma)) return pa + ma # if exist_pa & (not exist_ma) & (not remain_p) & remain_m: if exist_pa & remain_m: p_in = pa[-1]; m_out = M[len(ma)] pa.pop(); ma.append(m_out) debug('pa {}'.format(pa));debug('ma {}'.format(ma)) return pa + ma # return [0] return pa + ma ans = 1 if k==n: debug('k==n: {} == {} '.format(k,n)) debug('A {}'.format(A)) for a in A: ans = mmul(ans, a) else: debug('k<n: {} < {} '.format(k,n)) if len(P) == n: debug('n({}) all plus({})'.format(n,len(P))) P.sort(reverse=True) debug('P[:k] {}'.format(P[:k])) for a in P[:k]: ans = mmul(ans, a) elif len(M) == n: debug('n({}) all minus({})'.format(n,len(M))) if k%2: debug('k({}) is odd ({})'.format(k,k%2)) M.sort(reverse=True) else: debug('k({}) is even ({})'.format(k,k%2)) M.sort() debug('M[:k] {}'.format(M[:k])) for a in M[:k]: ans = mmul(ans, a) else: debug('n({}) mix plus({}):minus({})'.format(n,len(P),len(M))) for a in mix(): ans = mmul(ans, a) ans += MOD; ans %= MOD debug('ans {}'.format(ans)) print(ans)
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) from collections import defaultdict from collections import Counter import bisect from functools import reduce def main(): mod = 10 ** 9 + 7 N, K = MI() A = LI() flag = 0 for a in A: if a >= 0: flag = 1 break A.sort(key=lambda x: abs(x), reverse=True) if K == N: ans = 1 for a in A: ans *= a ans %= mod print(ans % mod) exit() elif flag == 0 and K % 2 != 0: B = A[::-1] ans = 1 for i in range(K): ans *= B[i] ans %= mod ans %= mod print(ans) exit() else: ans = 1 now_p = 0 now_n = 0 cnt_n = 0 for i in range(K): a = A[i] ans *= a ans %= mod if a > 0: now_p = a elif a < 0: now_n = a cnt_n += 1 else: print(0) exit() if cnt_n % 2 == 0: print(ans) exit() else: next_p = 0 next_n = 0 flag_p = 0 flag_n = 0 for i in range(K, N): a = A[i] if a > 0 and flag_p == 0: next_p = a flag_p = 1 elif a < 0 and flag_n == 0: next_n = a flag_n = 1 if flag_n == 1 and flag_p == 1: break if a == 0: break if now_p == 0: ans *= (pow(now_n, mod - 2, mod) * next_p) % mod ans %= mod elif next_p != 0 and next_n != 0: if now_p * next_p <= now_n * next_n: ans *= (pow(now_p, mod - 2, mod) * next_n) % mod ans %= mod else: ans *= (pow(now_n, mod - 2, mod) * next_p) % mod ans %= mod elif next_p == 0: ans *= (pow(now_p, mod - 2, mod) * next_n) % mod ans %= mod elif next_n == 0: ans *= (pow(now_n, mod - 2, mod) * next_p) % mod ans %= mod print(ans) if __name__ == "__main__": main()
1
9,357,767,389,520
null
112
112
a,b,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=min(a)+min(b) for i in range(m): p,q,r=map(int,input().split()) ans=min(a[p-1]+b[q-1]-r,ans) print(ans)
T1,T2=map(int,input().split()) a,b=map(int,input().split()) c,d=map(int,input().split()) e=T1*a f=T1*c if e>f: g=e-f e=T2*b f=T2*d if e>f: print(0) else: h=f-e if g==h: print("infinity") elif g>h: print(0) else: k=h-g if k>g: print(1) elif (g/k)%1!=0: print(1+(g//k)*2) else: print((g//k)*2) elif e<f: g=f-e e=T2*b f=T2*d if e<f: print(0) else: h=e-f if g==h: print("infinity") elif g>h: print(0) else: k=h-g if k>g: print(1) elif (g/k)%1!=0: print(1+(g//k)*2) else: print((g//k)*2)
0
null
93,269,887,067,542
200
269
import math A, B = input().split() A = int(A) B = float(B) B = int(B * 100 + 1e-5) res = int(math.floor((A * B) // 100)) print(res)
H, W, K = map(int, input().split()) M = [[1 if c == "#" else 0 for c in input()] for _ in range(H)] ans = 0 for hselection in range(1 << H): for wselection in range(1 << W): count = 0 for h in range(H): if hselection & (1 << h): continue for w in range(W): if wselection & (1 << w): continue count += M[h][w] if count == K: ans += 1 print(ans)
0
null
12,781,674,737,370
135
110
import sys input = sys.stdin.readline sys.setrecursionlimit(10**8) def main(): n,m = map(int,input().split()) x = m//2 y = m - x for i in range(x): print(i+1,2*x+1-i) for i in range(y): print(2*x+2+i,2*x+2*y+1-i) if __name__ == "__main__": main()
import math N, M = map(int, input().split()) if N%2 == 1: a = 1 b = N for i in range(M): print(a,b) a += 1 b -= 1 else: m = N//2 - 1 a = N//4 b = a + 1 c = N//2 + N//4 d = c + 2 for i in range(M): if i%2 == 0: print(a,b) a -= 1 b += 1 else: print(c,d) c -= 1 d += 1
1
28,722,943,938,478
null
162
162
N,M=map(int,input().split()) A=list(map(int,input().split())) A.sort() from bisect import bisect_left def isok(n): sum=0 for i in range(N): sum+=N-bisect_left(A,n-A[i]) return sum>=M start,end=0,2*10**5+1 while end-start>1: mid=(start+end)//2 if isok(mid): start=mid else: end=mid b=[A[0]] for i in range(1,N): b.append(b[-1]+A[i]) l=0 ans=0 bn=b[N-1] for i in range(N): a=bisect_left(A,start-A[i]) l+=N-a if a>0: ans+=A[i]*(N-a)+bn-b[a-1] else: ans+=A[i]*(N-a)+bn ans-=start*(l-M) print(ans)
a, b=map(int, input().split()) s=a*b m=a+a+b+b print(s, m)
0
null
54,120,428,557,140
252
36
string = input() numbers = string.split(' ') numbers.sort() print(numbers[0], numbers[1], numbers[2])
a = map(int, raw_input().split()) for i in range(len(a)): point = a[i:].index(min(a[i:])) + i temp = a[i]; a[i] = a[point] a[point] = temp print '%s %s %s' % (str(a[0]), str(a[1]), str(a[2]))
1
414,534,973,952
null
40
40
x = input() print(x ** 3)
print((lambda x : x**3)(int(input())))
1
276,533,044,902
null
35
35
h,w,k=map(int,input().split()) ans = 0 def get(sta): ret = set() for i in range(6): if sta & 1: ret.add(i) sta //= 2 return ret grd=[input() for i in range(h)] for i in range(2**h): hs=get(i) for j in range(2**w): ws=get(j) chk = 0 for a in range(h): for b in range(w): if a in hs or b in ws or grd[a][b]==".":continue chk += 1 if chk == k: ans += 1 print(ans)
import copy H, W, K = map(int, input().split()) inputdata = [list(str(input())) for i in range(H)] data = [] temp = [] give = 0 for x in inputdata: data.append(list(x)) for i in range(2 ** H): for j in range(2 ** W): ans = 0 temp = copy.deepcopy(data) for m in range(H): for n in range(W): if ((int(bin(i)[2:]) >> m) & 1) or ((int(bin(j)[2:]) >> n) & 1): temp[m][n] = "@" if temp[m][n] == "#": ans += 1 if ans == K: give += 1 print(give)
1
9,012,875,556,730
null
110
110
N,M=map(int,input().split()) sets=[] if N%2==1: for i in range(M): sets.append((i+1,i+1+(N-3-2*i)+1)) elif N%2==0: count=0 kukan=[] for i in range(N//2-1): kukan.append(count) count+=2 if count==N//2 or count==N//2-1: count+=1 kukan.reverse() for i in range(M): sets.append((i+1,i+1+kukan[i]+1)) for set1 in sets: print(set1[0],set1[1])
import sys input = sys.stdin.readline N, M = map(int, input().split()) if M%2: cnt = 0 for i in range(1, M//2 + 1): cnt += 1 print(i, M + 2 - i) print(M + 1 + i, 2*M + 2 - i) i = cnt + 1 print(i, M + 2 - i) else: for i in range(1, M//2 + 1): print(i, M + 2 - i) print(M + 1 + i, 2*M + 2 - i)
1
28,825,613,331,840
null
162
162
N=int(input()) print("ACL"*N)
li1 = [] li2 = [] for i, s in enumerate(input()): if s == "\\": li1.append(i) elif s == "/" and li1: j = li1.pop() c = i - j while li2 and li2[-1][0] > j: c += li2[-1][1] li2.pop() li2.append((j, c)) if li2: li3 = list(zip(*li2))[1] print(sum(li3)) print(len(li3), *li3) else: print(0, 0, sep="\n")
0
null
1,143,188,409,784
69
21
N = int(input()) C = input() W_total = C.count("W") R_total = N - W_total w_cur = 0 r_cur = R_total ans = R_total cur = 0 for i in range(N): if C[i] == "W": w_cur += 1 else: r_cur -= 1 ans = min(ans, min(w_cur, r_cur) + abs(w_cur - r_cur)) print(ans)
n = int(input()) # cs = ['W' for i in range(200000)] cs = input() w_count = 0 for c in cs: if c == 'W': w_count += 1 if w_count == 0: print(0) exit() rest = cs[-w_count:] answer = 0 for c in rest: if c == 'R': answer += 1 print(answer)
1
6,314,878,523,018
null
98
98
X , Y , Z = map(int,input().split()) tmp = 0 tmp = X X = Y Y = tmp tmp = X X = Z Z = tmp print( str( X ) + " " + str( Y ) + " " + str( Z ) )
xyz = list(map(int,input().split())) xyz[0] ,xyz[1] = xyz[1],xyz[0] xyz[0], xyz[2] = xyz[2], xyz[0] print(*xyz)
1
37,967,957,870,282
null
178
178
n = int(input()) X = list(map(int,input().split())) Y = list(map(int,input().split())) for p in range(1,5): if p != 4: D = 0.0 for i in range(n): D += ((abs(X[i]-Y[i]))**p) D = D**(1/p) print("{:.6f}".format(D)) else: print("{:.6f}".format(max(abs(x-y)for x,y in zip(X,Y))))
n=int(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) d= [abs(x[i] - y[i]) for i in range(n)] for i in range(1, 4): a = 0 for j in d: a += j**i print("{:.6f}".format(a**(1/i))) print("{:.6f}".format(max(d)))
1
210,117,352,990
null
32
32
import math r = float(raw_input()) l = 2 * math.pi * r S = math.pi * r ** 2 print "%f %f" %(S, l)
n,m=map(int, input().split()) arr=[[] for i in range(n+1)] gro=[0]*(n+1) for i in range(m): a,b=map(int, input().split()) arr[a].append(b) arr[b].append(a) from collections import deque deque=deque() gro_no=0 for i in range(1,n+1): if gro[i]==0: gro_no+=1 gro[i]=gro_no deque.append(i) while deque: j=deque.popleft() for k in arr[j]: if gro[k]==0: gro[k]=gro_no deque.append(k) print(gro_no-1)
0
null
1,437,628,356,800
46
70
from collections import deque H,W=map(int,input().split()) S=[input() for _ in range(H)] ans=0 d=deque([]) for i in range(H): for j in range(W): if S[i][j]=='#': continue d.append((i,j,0)) visited=[[-1]*W for _ in range(H)] visited[i][j]=0 while d: x,y,c=d.popleft() for dx,dy in [(0,1),(1,0),(0,-1),(-1,0)]: nx,ny=x+dx,y+dy if 0<=nx<H and 0<=ny<W and visited[nx][ny]==-1 and S[nx][ny]=='.': visited[nx][ny]=c+1 d.append((nx,ny,c+1)) ans=max(ans,c) print(ans)
h,w = map(int,input().split()) f = [] for i in range(h): s = list(map(lambda x:0 if x== "." else 1,list(input()))) f.append(s) from collections import deque def dfs_field(field,st,go): """ :param field: #が1,.が0になったfield st: [i,j] go: [i,j] :return: 色々今は回数returnしている。 """ h = len(field) w = len(field[0]) around = [[-1,0],[1,0],[0,1],[0,-1]] que = deque() visited = set() visited.add(str(st[0])+","+str(st[1])) que.append([st[0],st[1],0]) max_cos = 0 while True: if len(que) == 0: return max_cos top = que.popleft() nowi = top[0] nowj = top[1] cost = top[2] for a in around: ni = nowi+a[0] nj = nowj+a[1] if ni < 0 or ni > h-1 or nj < 0 or nj > w-1: continue if field[ni][nj] == 1: continue if ni == go[0] and nj == go[1]: return cost+1 else: key = str(ni)+","+str(nj) if key not in visited: que.append([ni,nj,cost+1]) visited.add(key) if cost+1 > max_cos: max_cos = cost+1 # print(que) ans = 0 for i in range(h): for j in range(w): if f[i][j] == 0: ct = dfs_field(f,[i,j],[-2,-2]) if ans < ct: ans = ct print(ans)
1
94,730,517,199,362
null
241
241
n = int(input()) a = list(map(int,input().split())) money = 1000 kabu = 0 if a[0] < a[1]: flg = 'kau' elif a[0] > a[1]: flg = 'uru' else: flg = 'f' for i in range(1,n): if a[i-1] < a[i]: if flg != 'uru': kabu = money // a[i-1] money -= kabu * a[i-1] flg = 'uru' elif a[i-1] > a[i]: if flg != 'kau': money += kabu * a[i-1] kabu = 0 flg = 'kau' else: pass if kabu > 0: money += kabu * a[-1] print(money)
a=int(input()) count1=0 count2=0 count3=0 count4=0 for i in range(a): b=str(input()) count=0 if b=='AC': count1+=1 if b=='RE': count2+=1 if b=='TLE': count3+=1 if b=='WA': count4+=1 print('AC x ',end='') print(count1) print('WA x ',end='') print(count4) print('TLE x ',end='') print(count3) print('RE x ',end='') print(count2)
0
null
7,913,226,023,712
103
109
a = input() print("Yes" if (a[2] == a[3]) and (a[4] == a[5]) else "No")
print(str(input())[:3])
0
null
28,351,591,815,044
184
130
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(500000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def calc(p, P): ans = 0 for i in range(1, len(p)): x1, y1 = P[p[i - 1]] x2, y2 = P[p[i]] ans += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) return ans def solve(): N = int(input()) P = [] for _ in range(N): X, Y = map(int, input().split()) P.append((X, Y)) ans = 0 num = 0 for p in permutations(range(N)): ans += calc(p, P) num += 1 print(ans / num) def main(): solve() if __name__ == '__main__': main()
a = input() * 2 b = input() if b in a: print("Yes") else: print("No")
0
null
74,989,972,678,258
280
64
N, K = map(int, input().split()) MOD = 10 ** 9 + 7 ans = 0 A = list(0 for _ in range(K + 1)) B = list(0 for _ in range(K + 1)) for i in range(1, K + 1): A[i] = pow((K // i), N, MOD) for i in range(K, 0, -1): a = 0 for j in range(i * 2, K + 1, i): a += B[j] B[i] = A[i] - a B[i] %= MOD for i in range(K + 1): ans += B[i] * i % MOD ans %= MOD print(ans)
n, k = map(int, input().split()) mod = 10**9+7 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 X = [0]*(k+1) ans = 0 for g in reversed(range(1, k+1)): temp = power(k//g, n, mod) j = g while j <= k: temp -= X[j] j += g ans += temp*g X[g] = temp ans %= mod print(ans)
1
36,657,526,838,624
null
176
176
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] MOD = 2019 # INF = int(1e15) def solve(): S = Scanner.string() S = S[::-1] cnt = [0 for _ in range(MOD)] tmp = 0 ans = 0 x = 1 for s in S: cnt[tmp] += 1 tmp += int(s) * x tmp %= MOD x *= 10 x %= MOD ans += cnt[tmp] print(ans) def main(): # sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
n, x, m = map(int, input().split()) tmp = [] while True: tmp.append(x) x = pow(x, 2, m) if x in tmp: break k = 0 while True: if tmp[k] == x: break k += 1 if k > n: print(sum(tmp[:n])) else: t = k a = (n - k) // (len(tmp) - k) s = (n - k) % (len(tmp) - k) print(sum(tmp[:k]) + sum(tmp[k:]) * a + sum(tmp[k: k + s]))
0
null
16,827,508,541,738
166
75
import sys M = 1044697 H = [None] * M table = str.maketrans({"A":"1","C":"2","G":"3","T":"4"}) def getChar(ch): if ch == "A": return 1 elif ch == "C": return 2 elif ch == "G": return 3 elif ch == "T": return 4 else: return 0 def getKey(string): sum = 0 p = 1 for i in range(len(string)): sum += p*(getChar(string[i])) p *= 5 return sum #print(getKey(string)) def h1(key): return key % M def h2(key): return 1 + (key % (M-1)) # 関数の中のwhile文はreturnで抜け出せる def find(string): i = 0 key = getKey(string) while True: h = (h1(key) + i * h2(key)) % M if H[h] == string: return 1 elif H[h] is None: return 0 else: i += 1 def insert(string): i = 0 key = getKey(string) while True: h = (h1(key) + i * h2(key)) % M if H[h] is None: H[h] = string break else: i += 1 input = sys.stdin.readline n = int(input()) for _ in range(n): com,string = input().split() if com == "insert": insert(string) elif com == "find": if find(string): print("yes") else: print("no")
S = input() if S[-1] != "s": print(S+"s") else: print(S+"es")
0
null
1,208,578,584,512
23
71
def gcd(X,Y): x = X y = Y if y > x: x,y = y,x while x % y: x,y = y,x%y return y number = [int(i) for i in input().split()] print(gcd(number[0],number[1]))
def getResult(a,b): if a<b: a,b=b,a while b!=0: r = a%b a = b b = r return a a,b = map(int,input().strip().split()) print(getResult(a,b))
1
7,385,023,382
null
11
11
def common_raccoon_vs_monster(): # 入力 H, N = map(int, input().split()) A = list(map(int, input().split())) # 必殺技の合計攻撃力 sum_A = 0 # 必殺技の攻撃力の合計 for i in range(len(A)): sum_A += A[i] # 比較 if H > sum_A: return 'No' else: return 'Yes' result = common_raccoon_vs_monster() print(result)
a, b, c, k = (int(i) for i in input().split()) re = k na = min(a, re) re -= na nb = min(b, re) re -= nb nc = min(c, re) print(na - nc)
0
null
50,034,378,266,530
226
148
N,K = map(int,input().split()) def solve(n,k): n %= k return min(n,abs(n-k)) print(solve(N,K))
def factorization(n): arr = [] tmp = n for i in range(2, int(-(-n**0.5//1))+1): if tmp % i == 0: cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i arr.append([i, cnt]) if tmp != 1: arr.append([tmp, 1]) if arr == [] and n != 1: arr.append([n, 1]) return arr n = int(input()) c = factorization(n) ans = 0 for k, v in c: cnt = 1 while v >= cnt: v -= cnt cnt += 1 ans += (cnt - 1) print(ans)
0
null
28,173,753,685,948
180
136
X = int(input()) ans = 0 W = 360 while(True): W -= X ans += 1 if W == 0: break if W < 0: W += 360 print(ans)
def main(): import sys input=sys.stdin.buffer.readline n=int(input()) d=[0]*n+[1<<c-97for c in input()[:n]] for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i] r=[] for _ in range(int(input())): q,a,b=input().split() i,s=int(a)+n-1,0 if q<b'2': d[i]=1<<b[0]-97 while i: i//=2 d[i]=d[i+i]|d[i-~i] continue j=int(b)+n while i<j: if i&1: s|=d[i] i+=1 if j&1: j-=1 s|=d[j] i//=2 j//=2 r+=bin(s).count('1'), print(' '.join(map(str,r))) main()
0
null
37,780,025,857,002
125
210
class Dice: def __init__(self, faces): self.faces = tuple(faces) def roll_north(self): self.faces = (self.faces[1], self.faces[5], self.faces[2], self.faces[3], self.faces[0], self.faces[4]) def roll_south(self): self.faces = (self.faces[4], self.faces[0], self.faces[2], self.faces[3], self.faces[5], self.faces[1]) def roll_west(self): self.faces = (self.faces[2], self.faces[1], self.faces[5], self.faces[0], self.faces[4], self.faces[3]) def roll_east(self): self.faces = (self.faces[3], self.faces[1], self.faces[0], self.faces[5], self.faces[4], self.faces[2]) def number(self, face_id): return self.faces[face_id - 1] dice = Dice(list(map(int, input().split()))) commands = input() for c in commands: if c == "N": dice.roll_north() elif c == "S": dice.roll_south() elif c == "W": dice.roll_west() elif c == "E": dice.roll_east() print(dice.number(1))
a, b, c, d, e, f = map(int, input().split()) directions = [x for x in input()] class Dice(): def __init__(self, a, b, c, d, e, f): self.a = a self.b = b self.c = c self.d = d self.e = e self.f = f def rotation(self, directions): for direction in directions: if direction == 'N': self.a, self.b, self.f, self.e = self.b, self.f, self.e, self.a if direction == 'S': self.a, self.b, self.f, self.e = self.e, self.a, self.b, self.f if direction == 'E': self.a, self.c, self.f, self.d = self.d, self.a, self.c, self.f if direction == 'W': self.a, self.c, self.f, self.d = self.c, self.f, self.d, self.a return self dice = Dice(a, b, c, d, e, f) print(dice.rotation(directions).a)
1
228,522,916,830
null
33
33
import math n = int(input()) x = list(map(float, input().split())) y = list(map(float, input().split())) for p in [1.0, 2.0, 3.0]: a = 0 for i in range(n): a += abs(x[i] - y[i]) ** p D = a ** (1/p) print(D) inf_D = float("-inf") for i in range(n): if abs(x[i] - y[i]) > inf_D: inf_D = abs(x[i] - y[i]) print(inf_D)
#!python3 from collections import deque LI = lambda: list(map(int, input().split())) # input N, M = LI() S = input() INF = 10 ** 6 def main(): w = [(INF, INF)] * (N + 1) w[0] = (0, 0) # (cost, index) dq = deque([(0, 0)]) for i in range(1, N + 1): if i - dq[0][1] > M: dq.popleft() if len(dq) == 0: print(-1) return if S[i] == "0": w[i] = (dq[0][0] + 1, i - dq[0][1]) dq.append((w[i][0], i)) ans = [] x = N while x > 0: d = w[x][1] ans.append(d) x -= d ans = ans[::-1] print(*ans) if __name__ == "__main__": main()
0
null
69,471,292,808,462
32
274
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)
class Saikoro: def sai(self,one,two,three,four,five,six): self.s1=int(one) self.s2=int(two) self.s3=int(three) self.s4=int(four) self.s5=int(five) self.s6=int(six) def turnE(self): e=[self.s4,self.s2,self.s1,self.s6,self.s5,self.s3] self.s1=e[0] self.s2=e[1] self.s3=e[2] self.s4=e[3] self.s5=e[4] self.s6=e[5] def turnN(self): n=[self.s2,self.s6,self.s3,self.s4,self.s1,self.s5] self.s1=n[0] self.s2=n[1] self.s3=n[2] self.s4=n[3] self.s5=n[4] self.s6=n[5] def turnS(self): s=[self.s5,self.s1,self.s3,self.s4,self.s6,self.s2] self.s1=s[0] self.s2=s[1] self.s3=s[2] self.s4=s[3] self.s5=s[4] self.s6=s[5] def turnW(self): w=[self.s3,self.s2,self.s6,self.s1,self.s5,self.s4] self.s1=w[0] self.s2=w[1] self.s3=w[2] self.s4=w[3] self.s5=w[4] self.s6=w[5] l=input().split() m=list(input()) sai1=Saikoro() sai1.sai(l[0],l[1],l[2],l[3],l[4],l[5]) n=len(m) i=0 while i<n: if m[i]=="E": sai1.turnE() elif m[i]=="N": sai1.turnN() elif m[i]=="S": sai1.turnS() else: sai1.turnW() i+=1 print(sai1.s1)
0
null
26,165,029,944,040
198
33
""" n = int(input()) ab = [list(map(int,input().split())) for _ in range(n)] mod = 1000000007 ab1 = [] ab2 = [] ab3 = [] ab4 = [] count00 = 0 count01 = 0 count10 = 0 for i in range(n): if ab[i][0] != 0 and ab[i][1] != 0: ab1.append(ab[i][0]/ab[i][1]) ab2.append(-ab[i][1]/ab[i][0]) if ab[i][0]/ab[i][1] > 0: ab3.append((ab[i][0]/ab[i][1],-ab[i][1]/ab[i][0])) else: ab4.append((ab[i][0]/ab[i][1],-ab[i][1]/ab[i][0])) elif ab[i][0] == 0 and ab[i][1] == 0: count00 += 1 elif ab[i][0] == 0 and ab[i][1] == 1: count01 += 1 else: count10 += 1 dict1 = {} dict2 = {} ab3.sort() ab4.sort(reverse = True) print(ab3) print(ab4) for i in ab1: if i in dict1: dict1[i] += 1 else: dict1[i] = 1 for i in ab2: if i in dict2: dict2[i] += 1 else: dict2[i] = 1 sorted1 = sorted(dict1.items(), key = lambda x: x[0]) sorted2 = sorted(dict2.items(), key = lambda x: x[0]) print(sorted1) print(sorted2) cnt = 0 num1 = n - count00 - count01 - count10 ans = 0 for i in range(len(ab3)): a,b = ab3[i] num1 -= 1 if cnt < len(sorted2): while cnt < len(sorted2): if sorted2[cnt][0] == a: ans += pow(2, num1+count01+count10-sorted2[cnt][1], mod) ans %= mod break elif sorted2[cnt][0] < a: cnt += 1 else: ans += pow(2, num1+count01+count10, mod) ans %= mod break else: ans += pow(2, num1+count01+count10, mod) - pow(2, ) ans %= mod print(ans) for i in range(len(ab4)): num1 -= 1 ans += pow(2, num1+count01+count10, mod) ans %= mod print(ans) ans += pow(2, count01, mod) -1 print(ans) ans += pow(2, count10, mod) -1 print(ans) ans += count00 print(ans) print(ans % mod) """ from math import gcd n = int(input()) dict1 = {} mod = 1000000007 cnt00 = 0 cnt01 = 0 cnt10 = 0 for _ in range(n): a,b = map(int,input().split()) if a == 0 and b == 0: cnt00 += 1 elif a == 0: cnt01 += 1 elif b == 0: cnt10 += 1 else: c = gcd(a,b) if b < 0: a *= -1 b *= -1 set1 = (a//c, b//c) if set1 in dict1: dict1[set1] += 1 else: dict1[set1] = 1 ans = 1 for k,v in dict1.items(): a,b = k if dict1[(a,b)] == -1: continue if a > 0: if (-b,a) in dict1: ans *= 2**v + 2**dict1[(-b,a)] - 1 dict1[(-b,a)] = -1 else: ans *= 2**v else: if (b,-a) in dict1: ans *= 2**v + 2**dict1[(b,-a)] - 1 dict1[(b,-a)] = -1 else: ans *= 2**v ans %= mod ans *= 2 ** cnt01 + 2 ** cnt10 - 1 ans += cnt00 - 1 print(ans%mod)
from collections import defaultdict import sys input = sys.stdin.readline from math import gcd MOD = 1000000007 dic1 = defaultdict(int) All_zero = 0 S = set() N = int(input()) ans = 0 #仲が悪い数を数える for i in range(N): a, b = map(int, input().split()) if a == 0 and b == 0: #なんでもOK All_zero += 1 elif a == 0: S.add((0, 1)) dic1[(0, 1)] += 1 elif b == 0: S.add((1, 0)) dic1[(1, 0)] += 1 else: GCD = gcd(a, b) a //= GCD b //= GCD if a < 0: #aを必ず正にする a *= -1 b *= -1 S.add((a, b)) dic1[(a, b)] += 1 lst = [] for a, b in S: tmp11 = dic1[(a, b)] A = a B = b if B <= 0: B *= -1 A *= -1 tmp2 = dic1[(B, -A)] # print (a, b, A, B) dic1[(B, -A)] = 0 if tmp11 > 0: lst.append((tmp11, tmp2)) # print (lst) ans = 1 for a, b in lst: tmp = (pow(2, a, MOD) - 1) + (pow(2, b, MOD) - 1) + 1 #左側を入れる、右側を入れる、両方入れない ans *= tmp ans %= MOD ans = (ans - 1 + All_zero) % MOD print (ans % MOD) # print (S)
1
20,985,435,228,240
null
146
146
S = int(input()) for i in range(9) : i = i + 1 if S % i == 0 and S // i <= 9: result = "Yes" break else : result = "No" print(result)
n = int(input()) a = 0 for i in range(1,10): for j in range(1,10): if(n==i*j): a+=1 if(a>=1): print("Yes") else: print("No")
1
159,959,426,413,010
null
287
287
n=int(input()) output='' for _ in range(n): output+='ACL' print(output)
mod = 10**9 + 7 N = int(input()) A = [int(i)%mod for i in input().split()][:N] wa = sum(A) total = 0 for n in range(N-1): wa -= A[n] total += A[n] * wa total %= mod print(total)
0
null
3,039,861,171,100
69
83
S = input() N = len(S) ans = 'No' # 文字列strの反転は、str[::-1] if S == S[::-1] and S[:(N-1)//2] == S[:(N-1)//2][::-1] and S[(N+1)//2:] == S[(N+1)//2:][::-1]: ans = 'Yes' print(ans)
h,w,m = ( int(x) for x in input().split() ) h_array = [ 0 for i in range(h) ] w_array = [ 0 for i in range(w) ] ps = set() for i in range(m): hi,wi = ( int(x)-1 for x in input().split() ) h_array[hi] += 1 w_array[wi] += 1 ps.add( (hi,wi) ) h_great = max(h_array) w_great = max(w_array) h_greats = list() w_greats = list() for i , hi in enumerate(h_array): if hi == h_great: h_greats.append(i) for i , wi in enumerate(w_array): if wi == w_great: w_greats.append(i) ans = h_great + w_great for _h in h_greats: for _w in w_greats: if (_h,_w) in ps: continue print(ans) exit() print(ans-1)
0
null
25,494,891,949,790
190
89
N=int(input()) if N==2: print(1) exit() def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors #N-1の約数(1は除く) Nそのもの #2 d=make_divisors(N-1) if not 2 in d: d.append(2) #print(d) d2=make_divisors(N) #print(len(d)) for i in d2: if i!=N and i!=1 and i not in d: now=N while now%i==0: now/=i if now%i==1: d.append(i) print(len(d))
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, read().split()) X = list(map(int, str(N))) L = len(X) dp1 = [[0] * (K + 1) for _ in range(L + 1)] dp2 = [[0] * (K + 1) for _ in range(L + 1)] dp1[0][0] = 1 for i, x in enumerate(X): for j in range(K + 1): if x != 0: if j > 0: dp1[i + 1][j] = dp1[i][j - 1] else: dp1[i + 1][j] = dp1[i][j] if j > 0: dp2[i + 1][j] = dp2[i][j - 1] * 9 if x != 0: dp2[i + 1][j] += dp1[i][j - 1] * (x - 1) dp2[i + 1][j] += dp2[i][j] if x != 0: dp2[i + 1][j] += dp1[i][j] print(dp1[L][K] + dp2[L][K]) return if __name__ == '__main__': main()
0
null
58,854,406,630,990
183
224
n,m = map(int,input().split()) x,y = map(int,input().split()) if n!=x: print(1) else: print(0)
from sys import exit a, b, c, k = map(int, input().split()) total = 0 if a >= k: print(k) exit() else: total += a k -= a if b >= k: print(total) exit() else: k -= b print(total - k)
0
null
73,159,630,300,252
264
148
#!usr/bin/env python3 from collections import defaultdict, deque, Counter from heapq import heappush, heappop from itertools import permutations import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): a, b, c = LI() k = I() for i in range(k): if a >= b: b *= 2 elif b >= c: c *= 2 if a < b < c: print('Yes') else: print('No') return # Solve if __name__ == "__main__": solve()
n = int(input()) A = list(map(int, input().split())) count = 0 def merge(A, left, mid, right): global count n1 = mid - left n2 = right - mid L = [0] * (n1 + 1) R = [0] * (n2 + 1) for i in range(n1): L[i] = A[left + i] for i in range(n2): R[i] = A[mid + i] L[n1] = 1.0e+9 + 1 R[n2] = 1.0e+9 + 1 i = 0 j = 0 for k in range(left, right): count += 1 if L[i] <= R[j]: A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 def mergeSort(A, left, right): if left + 1 < right: mid = int((left + right) / 2) mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) mergeSort(A, 0, len(A)) print(" ".join(map(str, A))) print(count)
0
null
3,484,449,259,600
101
26
def solve(n): if n % 2 == 0: return n // 2 - 1 else: return (n - 1) // 2 def main(): n = int(input()) res = solve(n) print(res) def test(): assert solve(4) == 1 assert solve(999999) == 499999 if __name__ == "__main__": test() main()
n = int(input()) if n-2 == 0: print(0) elif n%2 == 0: if n != 3: print(int(n/2)-1) else: print(1) else: print(int(n/2))
1
153,417,591,583,688
null
283
283
def kougeki(H): if H == 1: return 1 else: return 2 * kougeki(H//2) + 1 H = int(input()) print(kougeki(H))
h = int(input()) i =1 while h>1: h //=2 i += 1 print(2**i-1)
1
80,070,489,002,738
null
228
228
N, M = list(map(int, input().split())) H = list(map(int, input().split())) good = [True]*N for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 if H[a] >= H[b]: good[b] = False if H[a] <= H[b]: good[a] = False print(good.count(True))
N, M = map(int, input().split()) H = [0] + list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] h = [0] * (N + 1) for i in range(M): h[AB[i][0]] = max(h[AB[i][0]], H[AB[i][1]]) h[AB[i][1]] = max(h[AB[i][1]], H[AB[i][0]]) ans = 0 for i in range(N + 1): if h[i] < H[i]: ans += 1 print(ans)
1
25,024,426,130,088
null
155
155
n,k=map(int,input().split()) a=list(map(int,input().split())) a.append(0) s=input() ans=0 for i in range(k,n): if s[i]==s[i-k]: s=s[:i]+'z'+s[i+1:] for i in range(n): ans+=a['sprz'.index(s[i])] print(ans)
def resolve(): a,b = map(int,input().split()) print(0 if a<b*2 else a-b*2) resolve()
0
null
137,015,849,203,102
251
291
import sys n=int(input()) s=[list(input()) for i in range(n)] L1=[] L2=[] for i in range(n): ct3=0 l=[0] for j in s[i]: if j=='(': ct3+=1 l.append(ct3) else: ct3-=1 l.append(ct3) if l[-1]>=0: L1.append((min(l),l[-1])) else: L2.append((min(l)-l[-1],-l[-1])) L1.sort() L1.reverse() ct4=0 for i in L1: if ct4+i[0]<0: print('No') sys.exit() ct4+=i[1] L2.sort() L2.reverse() ct5=0 for i in L2: if ct5+i[0]<0: print('No') sys.exit() ct5+=i[1] if ct4!=ct5: print('No') sys.exit() print('Yes')
N = int(input()) A = [] for i in range(N): a = int(input()) xy = [list(map(int, input().split())) for _ in range(a)] A.append([a, xy]) # print(A) # 下からi桁目のbitが1->人iは正直 # 下からi桁目のbitが0->人iは不親切 # 不親切な人の証言は無視して良い ans = 0 for i in range(2**N): for j in range(N): flag = 0 if (i >> j) & 1: for k in range(A[j][0]): l = A[j][1][k][0] m=A[j][1][k][1] # print(i,j,k,(l,m),(i >> (l-1))) if not (i >> (l-1)) & 1 == A[j][1][k][1]: flag = 1 break if flag == 1: break else: # print(bin(i)) ct = 0 for l in range(N): ct += ((i >> l) & 1) ans = max(ans, ct) print(ans)
0
null
72,575,140,137,412
152
262
a = list(map(int, input().split())) for i in range(1,len(a)): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v print("{} {} {}".format(a[0],a[1],a[2]))
def swap(m, n, items): x = items[n] items[n] = items[m] items[m] = x ABC = input().split() if ABC[0] > ABC[1]: swap(0, 1, ABC) if ABC[1] > ABC[2]: swap(1, 2, ABC) if ABC[0] > ABC[1]: swap(0, 1, ABC) elif ABC[1] > ABC[2]: swap(1, 2, ABC) if ABC[0] > ABC[1]: swap(0, 1, ABC) print(ABC[0], ABC[1], ABC[2])
1
423,355,990,818
null
40
40
while True: h,w = [int(s) for s in input().split(' ')] if h==0 and w==0: break else: low = '#' * w rectangle = (low+'\n') * h print(rectangle)
# coding: utf-8 # Your code here! # ITP1_5_A while(True): x,y=map(int,input().split()) if x==0 and y==0: break else: for r in range(0,x): print("#"*y) print("")
1
789,481,016,192
null
49
49
score = list(map(int,input().split())) if score[0] <= score[1]: print('unsafe') else: print('safe')
global cnt cnt = 0 def merge(A, left, mid, right): L = A[left:mid] + [float("inf")] R = A[mid:right] + [float("inf")] i = 0 j = 0 global cnt for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 cnt += 1 def mergesort(A, left, right): rsl = [] if left+1 < right: mid = int((left+right)/2) mergesort(A, left, mid) mergesort(A, mid, right) rsl = merge(A, left, mid, right) return rsl n = int(input()) S = list(map(int, input().split())) mergesort(S, 0, n) print(*S) print(cnt)
0
null
14,785,930,160,990
163
26
k = int(input()) s = input() L = len(s) mod = 10**9+7 MAX = 2*10**6 fact = [1]*(MAX+1) for i in range(1, MAX+1): fact[i] = (fact[i-1]*i) % mod inv = [1]*(MAX+1) for i in range(2, MAX+1): inv[i] = inv[mod % i]*(mod-mod//i) % mod fact_inv = [1]*(MAX+1) for i in range(1, MAX+1): fact_inv[i] = fact_inv[i-1] * inv[i] % mod def comb(n, k): if n < k: return 0 return fact[n] * fact_inv[n-k] * fact_inv[k] % mod p25 = [1]*(k+1) p26 = [1]*(k+1) for i in range(k): p25[i+1] = p25[i]*25%mod p26[i+1] = p26[i]*26%mod ans = 0 for p in range(k+1): chk = p25[p]*comb(L-1+p,L-1)%mod chk *= p26[k-p]%mod ans += chk ans %= mod print(ans)
n = int(input()) l = sorted(list(map(int, input().split()))) ans = 0 import bisect for i in range(n-2): for j in range(i+1, n-1): ab = l[i]+l[j] idx = bisect.bisect_left(l, ab) ans += max(0, idx-j-1) print(ans)
0
null
92,113,245,876,388
124
294
a = str(input()) if a=="ABC": print("ARC") elif a=="ARC": print("ABC")
import sys sys.setrecursionlimit(10**5) n,m,k = map(int, input().split()) F = [[] for _ in range(n+1)] B = [[] for _ in range(n+1)] for _ in range(m): x,y = map(int, input().split()) F[x].append(y) F[y].append(x) for _ in range(k): x,y = map(int, input().split()) B[x].append(y) B[y].append(x) belongs = [-1 for _ in range(n+1)] group_ID = 0 def f_search(root, group_ID): for j in F[root]: if belongs[j] == -1: belongs[j] = group_ID f_search(j, group_ID) for i in range(n+1): if belongs[i] == -1: belongs[i] = group_ID f_search(i, group_ID) group_ID += 1 cnt_members = [0 for _ in range(len(set(belongs)))] for i in belongs[1:]: cnt_members[i] += 1 ans = [0 for _ in range(n+1)] for i in range(1, n+1): tmp = 0 for j in B[i]: if belongs[j] == belongs[i]: tmp += 1 ans[i] = cnt_members[belongs[i]] - 1 - len(F[i]) - tmp print(*ans[1:])
0
null
42,841,937,190,940
153
209
#!/usr/bin/env python3 N = int(input().split()[0]) xlt_list = [] for _ in range(N): x, l = list(map(int, input().split())) xlt_list.append((x, l, x + l)) xlt_list = sorted(xlt_list, key=lambda x: x[2]) count = 0 before_t = -float("inf") for i, xlt in enumerate(xlt_list): x, l, t = xlt if x - l >= before_t: count += 1 before_t = t ans = count print(ans)
N = int(input()) robot = [] ans = 0 for i in range(N): x,l = map(int,input().split()) robot.append([x+l,x-l]) robot.sort() cur = -float('inf') for i in range(N): if cur <= robot[i][1]: ans += 1 cur = robot[i][0] print(ans)
1
89,867,944,179,390
null
237
237
import math x1, y1, x2, y2 = map(float, input().split()) a = x2 - x1 b = y2 - y1 print(math.sqrt(a**2 + b**2))
H, W, M = map(int, input().split()) row = [0] * (H + 1) col = [0] * (W + 1) bom = [] for i in range(M): h, w = map(int, input().split()) bom.append([h, w]) row[h] += 1 col[w] += 1 rmax = max(row) cmax = max(col) cnt = row.count(rmax) * col.count(cmax) for h, w in bom: if rmax == row[h] and cmax == col[w]: cnt -= 1 print(rmax + cmax - (cnt == 0))
0
null
2,448,767,440,118
29
89
from math import floor def main(): a, b = map(int, input().split()) for yen in range(1, 1100): if floor(yen * 0.08) == a and floor(yen * 0.1) == b: print(yen) return print(-1) if __name__ == '__main__': main()
s,w=map(int,input().split()) print("un"*(w>=s)+"safe")
0
null
42,820,089,534,900
203
163
n = input() ans = 0 for i in range(len(n)): ans += int(n[i]) ans %= 9 print("Yes" if ans % 9 == 0 else "No")
n = input() a = list(map(int, input().split())) b = sum(a) sum = 0 for i in range(len(a)): b -= a[i] sum += a[i]*b print(sum%(10**9+7))
0
null
4,063,013,732,664
87
83
v=input() v=int(v) print(v**3)
x = int(input()) if x == 0: x = 1 else: x = 0 print(x)
0
null
1,582,436,635,780
35
76
n,m = map(int,input().split()) mod =10**9+7 sum = 0 min = 0 max = 0 for k in range(1,n+2): min += k-1 max += n-(k-1) if k >= m: sum = (sum + max-min+1) % mod print(sum)
A, B, C, D = map(int, input().split()) if C % B == 0: Takahashi_attacks = C // B else: Takahashi_attacks = C // B + 1 if A % D == 0: Aoki_attacks = A // D else: Aoki_attacks = A // D + 1 if Takahashi_attacks <= Aoki_attacks: print('Yes') else: print('No')
0
null
31,498,798,616,590
170
164
import math a, b, h, m = map(int, input().split()) theta_a = (60*h+m)/720*2*math.pi theta_b = m/60*2*math.pi theta_a_b = abs(theta_a-theta_b) ans = math.sqrt(a**2+b**2-2*a*b*math.cos(theta_a_b)) print(ans)
import math a, b, C = map(int, input().split()) rad = C/180*math.pi print('%.8f' % (a*b*math.sin(rad)/2)) print('%.8f' % ((a**2-2*a*b*math.cos(rad)+b**2)**0.5 + a + b)) print('%.8f' % (b * math.sin(C/180*math.pi)))
0
null
10,119,204,183,956
144
30
N = int(input()) def divisor(n): if n==1:return [] ret = [n] for i in range(2,n+1): if i*i==n: ret.append(i) elif i*i > n: break elif n%i==0: ret.append(i) ret.append(n//i) ret.sort() return ret ans = len(divisor(N-1)) for k in divisor(N): M = N while M%k==0: M//=k if M%k==1: ans += 1 print(ans)
a = list(map(int, input().split())) c = 0 for b in a: c = c + 1 if b == 0: print(c)
0
null
27,477,231,067,540
183
126
N, K = map(int, input().split()) MOD = 998244353 move = [] for _ in range(K): L, R = map(int, input().split()) move.append((L, R)) dp = [0]*(N+1) dp[0] = 1 dp[1] = -1 for i in range(1, N+1): dp[i] += dp[i-1] for l, r in move: if i - l >= 0: dp[i] += dp[i-l] if i - r - 1 >= 0: dp[i] -= dp[i-r-1] dp[i] %= MOD print(dp[N-1])
# 解説を見て解き直し N, K = [int(x) for x in input().split()] ranges = [tuple(int(x) for x in input().split()) for _ in range(K)] ranges.sort() p = 998244353 dp = [0] * (N + 1) dpsum = [0] * (N + 1) dp[1] = 1 dpsum[1] = 1 for i in range(2, N + 1): for l, r in ranges: rj = i - l lj = max(1, i - r) # 1以上 if rj <= 0: continue dp[i] += dpsum[rj] - dpsum[lj - 1] dp[i] %= p dpsum[i] = dpsum[i - 1] + dp[i] dpsum[i] %= p print(dp[N])
1
2,707,438,836,352
null
74
74
import itertools n=int(input()) a= list(map(int, input().split())) # aを偶数奇数の要素で振り分け a1=[] a2=[] for i in range(n): if i%2==0: a1.append(a[i]) else: a2.append(a[i]) # 累積和も作っておく a3=list(itertools.accumulate(a1)) a4=list(itertools.accumulate(a2)) x1=sum(a1) x2=sum(a2) if n%2==0: ans=-float('inf') for i in range(n//2): ans=max(a3[i]+x2-a4[i],ans) print(max(ans,x1,x2)) else: # 奇数番目だけの要素を選んだ時の最大値 ans1=sum(a1)-min(a1) # dp1[i]=奇数偶数奇数or偶数奇数と移動した時のi番目までのMAX dp1 = [-float('inf')] * (n // 2 + 1) dp1[0] = a1[0] # dp2[i]=奇数偶数or偶数のみと移動した時のi番目までのMAX dp2 = [-float('inf')] * (n // 2) dp2[0] = a2[0] for i in range(n // 2 - 1): dp2[i + 1] = max(a3[i] + a2[i + 1], dp2[i] + a2[i + 1]) if i==0: dp1[i + 2] = dp2[i] + a1[i + 2] else: dp1[i + 2] = max(dp2[i] + a1[i + 2], dp1[i + 1] + a1[i + 2]) print(max(dp1[-1], dp2[-1],ans1))
import sys #import copy #import numpy as np #import itertools #import collections #from collections import deque #from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson #from scipy.sparse import csr_matrix sys.setrecursionlimit(10**6) readline = sys.stdin.readline #read = sys.stdin.buffer.read inf = float('inf') #inf = pow(10, 10) def main(): # input N = int(readline()) A = list(map(int, readline().split())) K = N//2 DP0 = [-inf] * N DP1 = [-inf] * N DP2 = [-inf] * N DP2[0] = A[0] DP2[1] = max(A[0], A[1]) DP1[:2] = [0] * 2 DP0[:4] = [0] * 4 for i in range(2, N): if i%2 == 0: DP2[i] = DP2[i-2] + A[i] DP1[i] = max(DP2[i-1], DP1[i-2] + A[i]) DP0[i] = max(DP1[i-1], DP0[i-2] + A[i]) else: DP2[i] = max(DP2[i-2] + A[i], DP2[i-1]) DP1[i] = max(DP1[i-1], DP1[i-2] + A[i]) DP0[i] = max(DP0[i-1], DP0[i-2] + A[i]) if N%2 == 0: ans = DP2[N-1] else: ans = DP1[N-1] #print(DP0) #print(DP1) #print(DP2) print(ans) if __name__ == "__main__": main()
1
37,120,320,942,180
null
177
177
import sys def main(): H, W, K = map(int, sys.stdin.readline().split()) s = ['.' * (W+1)] + ['.' + sys.stdin.readline().rstrip() for _ in range(H)] res = [[None for _ in range(W + 2)]] + [[None] + [0 for _ in range(W)] + [None] for _ in range(H)] + [[None for _ in range(W + 2)]] number = 1 for i in range(1, H+1): if not '#' in s[i]: continue else: j = 1 while j <= W: res[i][j] = number if s[i][j] == '#': res[i][j] = number if '#' in s[i][j+1:]: number += 1 j += 1 number += 1 for i in range(1, H+1): if res[i][1] == 1: count = i break for i in range(1, count): res[i] = res[count] for i in range(1, H): if res[i+1][1] == 0: res[i+1] = res[i] for i in range(1, H+1): print(' '.join(map(str, res[i][1:W+1]))) if __name__ == '__main__': main()
a,b=map(int,input().split()) #a,bの最大公約数 def gcd(a, b): while b: a, b = b, a % b return a #a,bの最小公倍数 def lcm(a, b): return a * b // gcd (a, b) print(lcm(a,b))
0
null
128,484,686,064,350
277
256
N=str(input()) pon=["0","1","6","8"] hon=["2","4","5","7","9"] bon=["3"] if(N[-1] in pon): print("pon") elif(N[-1] in hon): print("hon") else: print("bon")
n=int(input()) if n%10==3: print("bon") elif n%10==0 or n%10==1 or n%10==6 or n%10==8: print("pon") else: print("hon")
1
19,377,701,280,560
null
142
142
class Dice: def __init__(self): d = map(int, raw_input().split(" ")) self.c = raw_input() self.rows = [d[0], d[4], d[5], d[1]] self.cols = [d[0], d[2], d[5], d[3]] def __move_next(self, x, y): temp = y.pop(0) y.append(temp) x[0] = y[0] x[2] = y[2] def __move_prev(self, x, y): temp = y.pop(3) y.insert(0, temp) x[0] = y[0] x[2] = y[2] def execute(self): for i in self.c: self.__move(i, self.rows, self.cols) def __move(self, com, x, y): if com == "N": self.__move_prev(y, x) elif com == "S": self.__move_next(y, x) elif com == "E": self.__move_prev(x, y) elif com == "W": self.__move_next(x, y) def print_top(self): print self.rows[0] dice = Dice() dice.execute() dice.print_top()
class Dice: def __init__(self,u,s,e,w,n,d): self.n = n self.e = e self.s = s self.w = w self.u = u self.d = d def roll(self,dir): if (dir == "N"): tmp = self.n self.n = self.u self.u = self.s self.s = self.d self.d = tmp elif (dir == "E"): tmp = self.e self.e = self.u self.u = self.w self.w = self.d self.d = tmp elif (dir == "S"): tmp = self.s self.s = self.u self.u = self.n self.n = self.d self.d = tmp elif (dir == "W"): tmp = self.w self.w = self.u self.u = self.e self.e = self.d self.d = tmp spots = raw_input().split() operations = raw_input() dice = Dice(*spots) for i in operations: dice.roll(i) print dice.u
1
241,549,511,798
null
33
33
def solve(): a, b = input().split() if a > b: print(b*int(a)) else: print(a*int(b)) if __name__ == '__main__': solve()
a,b=input().split() if a*int(b)>=b*int(a): print(b*int(a)) else: print(a*int(b))
1
84,281,599,099,772
null
232
232
from random import random class Node: def __init__(self, key, value:int=-1): self.left = None self.right = None self.key = key self.value = value self.priority = int(random()*10**7) # self.count_partial = 1 self.sum_partial = value class Treap: #Node [left, right, key, value, priority, num_partial, sum_partial] def __init__(self): self.root = None def update(self, node) -> Node: if node.left is None: # left_count = 0 left_sum = 0 else: # left_count = node.left.count_partial left_sum = node.left.sum_partial if node.right is None: # right_count = 0 right_sum = 0 else: # right_count = node.right.count_partial right_sum = node.right.sum_partial # node.count_partial = left_count + right_count + 1 node.sum_partial = left_sum + node.value + right_sum return node def merge(self, left :Node, right:Node): if left is None or right is None: return left if right is None else right if left.priority > right.priority: left.right = self.merge(left.right,right) return self.update(left) else: right.left = self.merge(left,right.left) return self.update(right) # def node_size(self, node:Node) -> int: # return 0 if node is None else node.count_partial def node_key(self, node: Node) -> int: return -1 if node is None or node.key is None else node.key def node_sum(self, node: Node) -> int: return 0 if node is None else node.sum_partial #指定された場所のノードは右の木に含まれる def split(self, node:None, key:int) -> (Node, Node): if node is None: return None,None if key <= self.node_key(node): left,right = self.split(node.left, key) node.left = right return left, self.update(node) else: left,right = self.split(node.right, key) node.right = left return self.update(node),right def insert(self, key:int, value:int =-1): value = value if value > 0 else key left, right = self.split(self.root, key) new_node = Node(key,value) self.root = self.merge(self.merge(left,new_node),right) def erase(self, key:int): # print('erase pos=',pos,'num=',self.search(pos),'num_nodes=',self.root.count_partial) middle,right = self.split(self.root, key+1) # print(middle.value if middle is not None else -1,middle.count_partial if middle is not None else -1,right.value if right is not None else -1,right.count_partial if right is not None else -1) left,middle = self.split(middle, key) # print(left.value if left is not None else -1,left.count_partial if left is not None else -1, middle.value if middle is not None else -1,middle.count_partial if middle is not None else -1,) self.root = self.merge(left,right) def printTree(self, node=None, level=0): node = self.root if node is None else node if node is None: print('level=',level,'root is None') return else: print('level=',level,'k=',node.key,'v=',node.value, 'p=',node.priority) if node.left is not None: print('left') self.printTree(node.left,level+1) if node.right is not None: print('right') self.printTree(node.right,level+1) def find(self, key): #return self.search_recursively(pos,self.root) v = self.root while v: v_key = self.node_key(v) if key == v_key: return v.value elif key < v_key: v = v.left else: v = v.right return -1 def interval_sum(self, left_key, right_key): lt_left, ge_left = self.split(self.root,left_key) left_to_right, gt_right = self.split(ge_left, right_key + 1) res = self.node_sum(left_to_right) self.root = self.merge(lt_left, self.merge(left_to_right, gt_right)) return res def main(): from sys import setrecursionlimit, stdin, stderr from os import environ from collections import defaultdict, deque, Counter from math import ceil, floor from itertools import accumulate, combinations, combinations_with_replacement setrecursionlimit(10**6) dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0 input = lambda: stdin.readline().rstrip() LMIIS = lambda: list(map(int,input().split())) II = lambda: int(input()) P = 10**9+7 INF = 10**18+10 N,D,A = LMIIS() enemies = [] for i in range(N): x, h = LMIIS() enemies.append((x, ceil(h/A))) enemies.sort() bomb = Treap() ans = 0 for i, (x, h) in enumerate(enemies): left = x - D right = x + D remain_h = h - bomb.interval_sum(left, right) if remain_h <= 0: continue ans += remain_h bomb.insert(x + D, remain_h) print(ans) main()
while True: H,W = [int(x) for x in input().split()] if (H,W)==(0,0): break for i in range(H): if i==0 or i==H-1: print("#"*W) else: print("#" + "."*(W-2) + "#") print("")
0
null
41,435,055,405,380
230
50
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N ** 0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) class Edge: def __init__(self, to_, id_): self.to = to_ self.id = id_ ans = None G = None K = None def dfs(to, c): global G global ans nc = c % K + 1 for g in G[to]: if ans[g.id] != -1: continue ans[g.id] = nc dfs(g.to, nc) nc = nc % K + 1 def solve(): global G global ans global K N = Scanner.int() G = [[] for _ in range(N)] for i in range(N - 1): x, y = Scanner.map_int() x -= 1 y -= 1 G[x].append(Edge(y, i)) G[y].append(Edge(x, i)) K = 0 for i in range(N): K = max(K, len(G[i])) ans = [-1 for _ in range(N - 1)] dfs(0, 0) print(K) print(*ans, sep='\n') def main(): sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
A, B = map(int, input().split()) print(A*B if 1 <= A <= 9 and 1 <= B <= 9 else '-1')
0
null
147,528,926,273,652
272
286
from math import pi def main(): R = int(input()) print(2*pi*R) if __name__ == '__main__': main()
from collections import defaultdict as dd from collections import deque import bisect import heapq def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): n = ri() C = input() if C[0] == "R": R = [1] W = [0] else: R = [0] W = [1] for c in C[1:]: if c == "R": R.append(1 + R[-1]) W.append(W[-1]) else: W.append(1 + W[-1]) R.append(R[-1]) best_cost = min(R[-1], W[-1]) for i in range(n): rl = R[i] wl = W[i] rr = R[-1] - rl wr = W[-1] - wl swaps = min(wl, rr) flips = wl + rr - 2 * swaps best_cost = min(best_cost, flips + swaps) print (best_cost) mode = 's' if mode == 'T': t = ri() for i in range(t): solve() else: solve()
0
null
18,815,544,834,862
167
98
s = list(input()) t = list(input()) length = len(s)-len(t) + 1 max = 0 for i in range(length): count = 0 for j in range(len(t)): if t[j] == s[i+j]: count += 1 if j == len(t)-1 and max < count: max = count print(len(t) - max)
s = input() t = input() ls = len(s) lt = len(t) min_count = 1000 for i in range(ls-lt+1): count = 0 for j in range(lt): if s[i:i+lt][j] != t[j]: count += 1 if min_count > count: min_count = count print(min_count)
1
3,673,658,778,230
null
82
82
K = int(input()) S = input() X = len(S) mod = 10**9+7 def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 2*10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) def power(n, r, mod): if r == 0: return 1 if r%2 == 0: return power(n*n % mod, r//2, mod) % mod if r%2 == 1: return n * power(n, r-1, mod) % mod A = 0 B = K temp = cmb(A+X-1,X-1,mod)*power(25,A,mod) temp %= mod temp *= power(26,B,mod) temp %= mod ans = temp for i in range(X+1,K+X+1): temp *= 25 temp %= mod temp *= pow(26, mod-2, mod) temp %= mod temp *= i-1 temp %= mod temp *= pow(i-X, mod-2, mod) temp %= mod ans += temp ans %= mod print(ans)
K = int(input()) S = input() N = len(S) MOD = 10 ** 9 + 7 # 逆元の前計算 factorial = [1, 1] inverse = [1, 1] invere_base = [0, 1] for i in range(2, K + N + 1): factorial.append((factorial[-1] * i) % MOD) invere_base.append((-invere_base[MOD % i] * (MOD // i)) % MOD) inverse.append((inverse[-1] * invere_base[-1]) % MOD) def nCr(n, r): if (r < 0 or r > n): return 0 r = min(r, n - r) return factorial[n] * inverse[r] * inverse[n - r] % MOD ans = 0 for i in range(K + 1): ans += pow(25, i, MOD) * nCr(i + N - 1, N - 1) * pow(26, K - i, MOD) % MOD ans %= MOD print(ans % MOD)
1
12,875,076,282,040
null
124
124
from heapq import heappop, heappush MOD = int(1e9+7) def div(a, b): return a * pow(b, MOD-2, MOD) % MOD def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) q = [] numneg = 0 for a in A: if a < 0: heappush(q, [a, "n"]) numneg += 1 elif a >= 0: heappush(q, [-a, "p"]) if K % 2 == 1 and numneg == N or N == K: ans = 1 A.sort(reverse=True) for i in range(K): ans = (ans * A[i]) % MOD print(ans) return ans = 1 is_positive = True prevpos = None prevneg = None for i in range(K): num, posneg = heappop(q) ans = (ans * -num) % MOD if posneg == "n": is_positive = not is_positive prevneg = num else: prevpos = num if ans != 0 and not is_positive: nextpos = None nextneg = None while len(q) and (nextneg is None or nextpos is None): num, posneg = heappop(q) if posneg == "p" and nextpos is None: nextpos = num elif posneg == "n" and nextneg is None: nextneg = num # nextneg / prevpos < nextpos / prevneg if prevpos is None or nextneg is None: ans = div(ans * nextpos, prevneg) elif prevneg is None or nextpos is None: ans = div(ans * nextneg, prevpos) else: if nextneg * prevneg < nextpos * prevpos: ans = div(ans * nextpos, prevneg) else: ans = div(ans * nextneg, prevpos) print(ans) if __name__ == "__main__": main()
n, m = map(int, input().split()) h = [int(x) for x in input().split()] cnt = [1] * n for _ in range(m): a, b = map(int, input().split()) if h[a-1] > h[b-1]: cnt[b-1] = 0 elif h[a-1] < h[b-1]: cnt[a-1] = 0 else: cnt[a-1] = 0 cnt[b-1] = 0 print(cnt.count(1))
0
null
17,257,120,195,392
112
155
import bisect if __name__ == '__main__': def check(mid): count = 0 for i in range(n): position = bisect.bisect_left(a, (mid - a[i])) count += (n - position) return count < m n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() # 左手でa[i]の手を握るとする # a[i]を持っているときに和がx未満になるときの右手の数字はx - a[i]未満の数字である # lower_bound # この値をNから引くことで和がx以上になるペアの個数がわかる # この値の合計がM未満になればそこが最大の幸福度である # 要するに、M個のペアを作るためには最大いくらの和を採用できるかを二分探索する ng = 0 ok = 10 ** 5 * (n + 1) while 1 < abs(ok - ng): # mid -> boundとなる和。これより大きい和をもつペアをM個作れるかを判定する mid = (ok + ng) // 2 c = check(mid) # ペアの個数がmより小さい場合は、okの範囲を下げる if c: ok = mid # そうでない場合はまだ余裕があるので、ngをあげる else: ng = mid # ここが終了した時点でngにはm個以上のペアを作るための最大のboundが入っている # upper_boundで左手にa[i]がある場合のng - a[i]の数を判定する # ansに求めた数 * a[i] + 右手に持つ幸福度の総和を足す # mから求めた数を引く ans = 0 sum_array = [0] * (n + 1) # 累積和で高速化をする # (x + a[i]) + (x + a[i + 1) + (x + a[i + 2])..... # -> (x * 個数) * (a[i] + a[i + 1] + a[i + 2]) for i in range(n): sum_array[i + 1] = sum_array[i] + a[i] for i in range(n): position = bisect.bisect_right(a, ng - a[i]) ans += (n - position) * a[i] + sum_array[n] - sum_array[position] m -= (n - position) ans += ng * m print(ans)
def solve(): print(eval(input().replace(' ', '*'))) if __name__ == '__main__': solve()
0
null
62,358,764,731,708
252
133
def bubble_sort(A, N): sw = 0 flag = True while flag: flag = False for j in reversed(range(1, N)): if A[j - 1] > A[j]: A[j - 1], A[j] = A[j], A[j - 1] sw += 1 flag = True return sw def main(): N = int(input().rstrip()) A = list(map(int, input().rstrip().split())) sw = bubble_sort(A, N) print(' '.join(map(str, A))) print(sw) if __name__ == '__main__': main()
def bubbleSort(A, N): global count flag = True while flag: flag = False for j in range(N-1, 0, -1): if A[j] < A[j-1]: A[j], A[j-1] = A[j-1], A[j] flag = True count += 1 N = int(input()) A = [int(i) for i in input().split()] count = 0 bubbleSort(A, N) print(*A) print(count)
1
15,885,582,510
null
14
14
r = int(input()) x = 2*3.141592 * r print(x)
import math r = int(input()) h = 2 * r * math.pi print(h)
1
31,246,262,349,510
null
167
167
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) b = 0 tb = 0 for i in range(M): if tb + B[i] > K: break tb += B[i] b = i+1 ans = [0, b] m = b a = 0 ta = 0 for i in range(N): if ta + A[i] > K: break a = i+1 ta += A[i] while True: if ta + tb > K: if b == 0:break b -= 1 tb -= B[b] else: if a + b > m: m = a + b ans = [a, b] break print(ans[0]+ans[1])
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値) from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9+7 def lcm(x,y): return x*y//gcd(x,y) def lgcd(l): return reduce(gcd,l) def llcm(l): return reduce(lcm,l) def powmod(n,i,mod): return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod) def div2(x): return x.bit_length() def div10(x): return len(str(x))-(x==0) def perm(n,mod=None): ans = 1 for i in range(1,n+1): ans *= i if mod!=None: ans %= mod return ans def intput(): return int(input()) def mint(): return map(int,input().split()) def lint(): return list(map(int,input().split())) def ilint(): return int(input()), list(map(int,input().split())) def judge(x, l=['Yes', 'No']): print(l[0] if x else l[1]) def lprint(l, sep='\n'): for x in l: print(x, end=sep) def ston(c, c0='a'): return ord(c)-ord(c0) def ntos(x, c0='a'): return chr(x+ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self,x,d=1): self.setdefault(x,0) self[x] += d class comb(): def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self,k): l,n,mod = self.l, self.n, self.mod k = n-k if k>n//2 else k while len(l)<=k: i = len(l) l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod) return l[k] H,W=mint() s=[input() for _ in range(H)] dp=[[0]*W for _ in range(H)] dp[0][0]=int(s[0][0]=='#') for i in range(H): for j in range(W): if i==j==0: continue tmp = INF if i>0: tmp = min(tmp,dp[i-1][j]+int(s[i-1][j]=='.' and s[i][j]=='#')) if j>0: tmp = min(tmp,dp[i][j-1]+int(s[i][j-1]=='.' and s[i][j]=='#')) dp[i][j] = tmp print(dp[H-1][W-1])
0
null
29,801,179,663,344
117
194
N = int(input()) ST = [input().split() for _ in range(N)] X = input() flag = False ans = 0 for i in range(N): if flag: ans += int(ST[i][1]) if ST[i][0] == X: flag = True print(ans)
n=int(input()) a=[list(input().split()) for _ in range(n)] x=input() s=0 for i in range(n): if a[i][0]==x: p=i break for i in range(p+1,n): s+=int(a[i][1]) print(s)
1
97,098,650,565,812
null
243
243
N,K=map(int,input().split()) R,S,P=map(int,input().split()) T=input()+'*'*K h=['']*N f,n='','' ans=0 for i in range(N): if K<=i:f=h[i-K] n=T[i+K] if T[i]=='r': if f=='p':h[i]=n else:ans+=P;h[i]='p' if T[i]=='p': if f=='s':h[i]=n else:ans+=S;h[i]='s' if T[i]=='s': if f=='r':h[i]=n else:ans+=R;h[i]='r' print(ans)
n, k = map(int,input().split()) r,s,p = map(int,input().split()) t = list(input()) ans = 0 for i in range(len(t)): tmp = t[i] if i >= k: if tmp == t[i-k]: t[i] = "c" continue if tmp == "r": ans += p elif tmp == "s": ans += r elif tmp == "p": ans += s print(ans)
1
106,811,912,969,410
null
251
251
import sys input = sys.stdin.readline from itertools import accumulate N, K = map(int, input().split()) A = map(int, input().split()) B = accumulate(A) C = [0]+[(b-i)%K for i, b in enumerate(B,start=1)] cnt = dict() cnt[C[0]] = 1 res = 0 for i in range(1, N+1): if i >= K: cnt[C[i-K]] = cnt.get(C[i-K],0) - 1 res += cnt.get(C[i], 0) cnt[C[i]] = cnt.get(C[i],0) + 1 print(res)
from collections import defaultdict from itertools import accumulate import bisect n,k = map(int, input().split()) a = list(map(int,input().split())) s = list(accumulate([0]+a)) b = [s[i]-i for i in range(n+1)] d = defaultdict(list) for i in range(n+1): d[b[i]%k].append(i) ans = 0 for x in d.keys(): l = d[x] for j in range(len(l)): y = l[j] ans += max(0,bisect.bisect_right(l,k+y-1)-j-1) print(ans)
1
137,746,783,801,188
null
273
273
N = int(input()) A = list(map(int,input().split())) for i in range(N): A[i] = (A[i],i+1) A.sort() ans = '' for tup in A: v, i = tup ans+=str(i)+' ' print(ans)
N=int(input()) A=list(map(int,input().split())) for i in range(N): A[i] = [i+1, A[i]] A.sort(key=lambda x:x[1]) ans=[] for i in range(N): ans.append(A[i][0]) ans = map(str, ans) print(' '.join(ans))
1
180,349,408,610,948
null
299
299
import sys input = sys.stdin.readline def main(): N = int(input()) A = list(map(int, input().split())) p = 10**9 + 7 total = 0 for i in range(60): cnt_1, cnt_0 = 0, 0 for j in range(N): if (A[j]>>i)&1: cnt_1 += 1 else: cnt_0 += 1 total += pow(2, i, p) * cnt_0 * cnt_1 %p print(total%p) main()
def main(): N = int(input()) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 ans = 0 L = 100 for l in range(L): one = 0 zero = 0 for a in A: if (a & (1<<(L - l - 1))): one += 1 else: zero += 1 ans += (one * zero) * 2 ** (L - l - 1) ans %= MOD print(ans) if __name__ == "__main__": main()
1
123,302,116,818,482
null
263
263
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)))
i=0 while 1: i+=1 x,y=map(int, raw_input().split()) if x==0 and y==0: break print min(x,y),max(x,y)
1
520,713,836,260
null
43
43
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 T=LI() A=LI() B=LI() d1=(A[0]-B[0])*T[0] d2=(A[1]-B[1])*T[1] if d1>=0: #最初は必ず正の方向へいかないように調整 d1*=-1 d2*=-1 if d1+d2==0: print("infinity") elif d1==0:#d1=0のパターンを排除した print(0) elif d1+d2<=0: print(0) else: cnt=(-1*d1)//(d1+d2) ans=cnt*2+1 if cnt*(d1+d2)==-1*d1: ans-=1 print(ans) main()
def abc172c_tsundoku(): n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) A = [0] * (n + 1) B = [0] * (m + 1) for i in range(1, n + 1): A[i] = A[i - 1] + a[i - 1] if A[i] > k: n = i - 1 break for i in range(1, m + 1): B[i] = B[i - 1] + b[i - 1] if B[i] > k: m = i - 1 break ans = 0 for i in range(0, n + 1): j = max(ans - i, 0) if j > m or A[i] + B[j] > k: continue while j <= m: if A[i] + B[j] > k: j -= 1 break j += 1 j = min(m,j) ans = max(i + j, ans) print(ans) abc172c_tsundoku()
0
null
71,320,385,127,420
269
117
import sys def main(): for x in sys.stdin: if x == "0\n": break else: X = list(x) total = 0 for i in range(len(X) - 1): total += int(X[i]) print(total) if __name__ == "__main__": main()
def f(s): return sum(map(int, s)) while True: s = input() if s == "0": break print(f(s))
1
1,594,750,009,578
null
62
62
S=input() if S=="hi" or S=="hihi" or S=="hihihi" or S=="hihihihi" or S=="hihihihihi": print("Yes") else: print("No")
s=input() if len(s)&1: print('No') exit() for i in list(s[i*2:i*2+2] for i in range(len(s)//2)): if i!='hi': print('No') exit() print('Yes')
1
53,440,351,147,600
null
199
199
# https://atcoder.jp/contests/abc163/tasks/abc163_d def main(): MOD = 10**9 + 7 n, k = [int(i) for i in input().strip().split()] table = [0] * (n + 2) table[1] = 1 for i in range(2, n + 1): table[i] = table[i - 1] + i ans = 0 for i in range(k, n + 1): _min = table[i - 1] _max = table[n] - table[n - i] ans += _max - _min + 1 ans %= MOD print((ans + 1) % MOD) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): x = int(input()) print(1-x) if __name__ == "__main__": main()
0
null
18,145,243,886,140
170
76
S=str(input()) ls = ["SAT","FRI","THU","WED","TUE","MON","SUN"] for i in range(7): if S == ls[i]: print(i+1)
k,n = map(int,input().split(" ")) a = list(map(int,input().split(" "))) m = a[0] + k - a[n-1] for i in range(n-1): l = a[i+1] - a[i] if l > m: m = l ans = k - m print(ans)
0
null
88,086,632,826,998
270
186
import sys def main(): orders = sys.stdin.readlines()[1:] dna_set = set() for order in orders: command, dna = order.split(" ") if command == "insert": dna_set.add(dna) elif command == "find": if dna in dna_set: print("yes") else: print("no") if __name__ == "__main__": main()
def main(): n = input() non_zero = int(input()) length = len(n) dp = [[[0, 0] for _ in range(non_zero + 1)] for _ in range(length + 1)] dp[0][0][0] = 1 for i in range(length): for j in range(non_zero + 1): for k in range(2): now_digit = int(n[i]) for next_d in range(10): new_i = i + 1 new_j = j new_k = k if next_d > 0: new_j += 1 if new_j > non_zero: continue if k == 0: if next_d > now_digit: continue elif next_d < now_digit: new_k = 1 dp[new_i][new_j][new_k] += dp[i][j][k] print(sum(dp[length][non_zero])) if __name__ == '__main__': main()
0
null
38,017,152,658,728
23
224
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: map(int, readline().split()) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: map(int, read().split()) in_s = lambda: readline().rstrip().decode('utf-8') def main(): H, W, K = in_nn() a = [list(in_s()) for _ in range(H)] ans = [[0 for _ in range(W)] for _ in range(H)] stb = [] for y in range(H): for x in range(W): if a[y][x] == '#': stb.append((x, y)) for i, (x, y) in enumerate(stb): ans[y][x] = i + 1 for i, (x, y) in enumerate(stb): l = x while l != 0: if ans[y][l - 1] == 0: l -= 1 else: break r = x while r != W - 1: if ans[y][r + 1] == 0: r += 1 else: break u = y while u != 0: if sum(ans[u - 1][l:r + 1]) == 0: u -= 1 else: break d = y while d != H - 1: if sum(ans[d + 1][l:r + 1]) == 0: d += 1 else: break for yy in range(u, d + 1): for xx in range(l, r + 1): ans[yy][xx] = i + 1 for i in range(H): print(' '.join(map(str, ans[i]))) if __name__ == '__main__': main()
H,W,K=map(int, input().split()) S=[input()for _ in range(H)] A=[[0]*W for _ in range(H)] c=0 for i in range(H): d=0 for j in range(W): if S[i][j]=="#": c+=1 d=c A[i][j]=d p=0 for j in range(W-1,-1,-1): if A[i][j]==0: A[i][j]=p p=A[i][j] if S[i].find("#")<0 and i!=0: A[i][:]=A[i-1] for i in range(H-2,-1,-1): if all(a==0 for a in A[i]): A[i][:]=A[i+1] for i in range(H): print(*A[i])
1
143,407,380,781,628
null
277
277
N=int(input()) S=list(input()) ans=[] while len(S)>1: if S[0]==S[1]: S.pop(0) else: ans.append(S.pop(0)) print(len(ans)+1)
n = int(input()) S = input() res = 1 tmp = S[0] for i in range(1,n): if S[i] != tmp: res += 1 tmp = S[i] print(res)
1
170,362,195,387,962
null
293
293
N = int(input()) S = input() ans = S.count("R")*S.count("G")*S.count("B") for i in range(N): for j in range(i+1,N): k = 2*j-i if k<N and S[i]!=S[j]!=S[k]!=S[i]: ans-=1 print(ans)
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() s = S() rgb = ["R","G","B"] rgb_st = set(rgb) rgb_acc = [[0]*n for _ in range(3)] index = rgb.index(s[0]) rgb_acc[index][0] += 1 ans = 0 for i in range(1,n): for j in range(3): rgb_acc[j][i] = rgb_acc[j][i-1] index = rgb.index(s[i]) rgb_acc[index][i] += 1 for i in range(n-2): for j in range(i+1,n-1): if s[i] != s[j]: ex = (rgb_st-{s[i],s[j]}).pop() index = rgb.index(ex) cnt = rgb_acc[index][-1] - rgb_acc[index][j] if j<2*j-i<n: if s[2*j-i] == ex: cnt -= 1 ans += cnt print(ans) main()
1
36,050,038,908,142
null
175
175
r=float(input()) a=r*r*(3.141592653589) b=(r+r)*(3.141592653589) print(f"{a:.6f} {b:.6f}")
m1,d1=map(int,input().split()) m2,d2=map(int,input().split()) if (m1+1)%13==m2: if d2==1: print(1) exit() print(0)
0
null
62,262,314,718,978
46
264
a,b,c,d=map(int,input().split()) x=a*c if x<a*d: x=a*d if x<b*c: x=b*c if x<b*d: x=b*d print(x)
a, b, c, d = list(map(int, input().split(" "))) if a <= b and c <= d: print(max(a*c, a*d, b*c, b*d))
1
3,017,271,722,532
null
77
77
n = int(input()) stack = [["",0] for i in range(10**6*4)] stack[0] = ["a",1] pos = 0 while(pos>=0): if(len(stack[pos][0]) == n): print(stack[pos][0]) pos-=1 else: nowstr = stack[pos][0] nowlen = stack[pos][1] #print(nowlen) pos-=1 for ii in range(nowlen+1): i = nowlen-ii pos+=1 stack[pos][0] = nowstr+chr(ord('a')+i) if(i == nowlen): stack[pos][1] = nowlen+1 else: stack[pos][1] = nowlen
from sys import stdin N,M,K = [int(x) for x in stdin.readline().rstrip().split()] mod = 998244353 maxn = 2*10**5+1 fac = [0 for _ in range(maxn)] finv = [0 for _ in range(maxn)] inv = [0 for _ in range(maxn)] fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2,maxn): fac[i] = fac[i-1] * i % mod inv[i] = mod - inv[mod%i] * (mod // i) % mod finv[i] = finv[i-1] * inv[i] % mod def combinations(n,k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n-k] % mod) % mod ans = 0 for i in range(0,K+1): tmp = 1 tmp *= M*pow(M-1,N-i-1,mod) tmp %= mod tmp *= combinations(N-1,i) tmp %= mod ans += tmp print(ans%mod)
0
null
37,727,065,798,880
198
151