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 from io import StringIO import unittest import collections def resolve(): readline=sys.stdin.readline n=int(readline()) arr=list(map(int, readline().rstrip().split())) c=collections.Counter(arr) tb=[False]*(10**6 + 10) ans=0 for x in c.keys(): for j in range(x*2,10**6+5,x): tb[j]=True for x in c.keys(): if tb[x]==0 and c[x]==1: ans+=1 print(ans) return if 'doTest' not in globals(): resolve() sys.exit() ### ---------------- ### ここまで ### ----------------
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n = I() a = LI() lst = [0 for _ in range(10**6+1)] a.sort() cnt = 0 st = set() for i in a: if lst[i] == -1: pass elif lst[i] == 0: cnt += 1 lst[i] = 1 time = 10**6//i for j in range(2,time+1): lst[i*j] = -1 elif lst[i] == 1: st.add(i) ans = cnt - len(st) print(ans) main()
1
14,428,559,727,610
null
129
129
n = int(input()) dic = {} for i in range(n): req = input().split() if(req[0] == "insert"): dic[req[1]] = i elif(req[0] == "find"): if(req[1] in dic): print("yes") else: print("no")
S = list(input()) for i in range(len(S)): S[i] = "x" print(''.join(S))
0
null
36,318,264,182,968
23
221
s,t=list(input().split()) a,b=list(map(int,input().split())) u=input() if u==s: print(str(a-1)+" "+str(b)) else: print(str(a)+" "+str(b-1))
MM = int(input()) AA = input().split() count = 0 for j in AA: i = int(j) if i%2 ==0: if i%3 !=0 and i%5 !=0: count +=1 if count == 0: print('APPROVED') else: print('DENIED')
0
null
70,802,309,777,430
220
217
N = int(input()) A = list(map(int,input().split())) c = 0 if N%2 == 0: for i in range(N//2): c += A[2*i+1] cm = c # print(c) for i in range(N//2): # print(2*i,2*i+1) c += A[2*i]-A[2*i+1] cm = max(c,cm) print(cm) else: dp = [[0]*(3) for _ in range(N//2)] # print(dp) # 初期化 dp[0][0] = A[0] dp[0][1] = A[1] dp[0][2] = A[2] for i in range(0,N//2-1): dp[i+1][0] = dp[i][0] + A[2*i+2] dp[i+1][1] = max(dp[i][0] + A[2*i+3], dp[i][1] + A[2*i+3]) dp[i+1][2] = max(dp[i][0] + A[2*i+4], dp[i][1] + A[2*i+4], dp[i][2] + A[2*i+4]) # print(dp) print(max(dp[N//2-1][0],dp[N//2-1][1],dp[N//2-1][2]))
n=int(input()) a=list(map(int,input().split())) if n%2==1: dp=[[0 for j in range(3)] for i in range(n//2)] dp[0][0]=a[0] dp[0][1]=a[1] dp[0][2]=a[2] for i in range(n//2-1): dp[i+1][0]=(dp[i][0]+a[2*(i+1)]) dp[i+1][1]=max(dp[i][0],dp[i][1])+a[2*(i+1)+1] dp[i+1][2]=max(dp[i])+a[2*(i+1)+2] print(max(dp[-1])) if n%2==0: dp=[[0 for j in range(2)] for i in range(n//2)] dp[0][0]=a[0] dp[0][1]=a[1] for i in range(n//2-1): dp[i+1][0]=(dp[i][0]+a[2*(i+1)]) dp[i+1][1]=max(dp[i][0],dp[i][1])+a[2*(i+1)+1] #dp[i+1][2]=max(dp[i])+a[2*(i+2)+2] print(max(dp[-1]))
1
37,164,509,206,758
null
177
177
import math A, B, X = map(int, input().split()) h = X / (A*A) r = 0 deg = 0 if (2 * X) - (B * A * A) > 0: r = math.atan(2 * (B-h) / A) elif (2 * X) - (B * A * A) == 0: r = math.atan(B / A) else: h = (2 * X) / (A * B) r = math.atan(B / h) deg = math.degrees(r) print(deg)
import sys from math import atan, pi read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): a, b, x = map(int, readline().split()) if x > a * a * b / 2: angle = atan(2 * (a * a * b - x) / a ** 3) else: angle = atan(a * b * b / (2 * x)) print(angle / pi * 180) return if __name__ == '__main__': main()
1
163,476,200,433,620
null
289
289
from sys import stdin from collections import deque # 入力 n = int(input()) # command = [stdin.readline()[:-1] for a in range(n)] command = stdin # process output = deque([]) for a in command: if a[0] == 'i': output.appendleft(int(a[7:])) elif a[0:7] == 'delete ': try: output.remove(int(a[7:])) except ValueError: pass elif a[6] == 'F': output.popleft() else: output.pop() # 出力 print(*list(output))
from collections import deque import sys dq = deque() num = int(sys.stdin.readline()) line = sys.stdin.readlines() for i in range(num): order = line[i].split() if order[0] == 'insert': dq.appendleft(order[1]) elif order[0] == 'deleteFirst': dq.popleft() elif order[0] == 'deleteLast': dq.pop() else: if order[1] in dq: dq.remove(order[1]) print(' '.join(dq))
1
51,636,077,790
null
20
20
def Qc(): x, n = map(int, input().split()) if 0 < n: p = list(map(int, input().split())) for i in range(101): if x - i not in p: print(x - i) exit() if x + i not in p: res = x + 1 print(x + i) exit() else: # 整数列がなにもない場合は自分自身が含まれていない最近値になる print(x) exit() if __name__ == "__main__": Qc()
spam = [int(input()) for i in range(0, 10)] spam.sort() spam.reverse() for i in range(0,3): print(spam[i])
0
null
7,055,807,904,420
128
2
n = int(input()) t_score = 0 h_score = 0 for i in range(n): t_card, h_card = input().split() if t_card < h_card: h_score += 3 elif t_card > h_card: t_score += 3 else: h_score += 1 t_score += 1 print(t_score, h_score)
# coding: utf-8 # Your code here! n = int(input()) ta = 0 ha = 0 for i in range(n): a, b = list(input().split()) if a == b: ta += 1 ha += 1 elif a > b: ta += 3 else: ha += 3 print(ta,ha)
1
2,006,564,322,622
null
67
67
ni = lambda: int(input()) nm = lambda: map(int, input().split()) nl = lambda: list(map(int, input().split())) n,k = nm() MOD = 10**9+7 ans = 0 for kk in range(k,n+2): # print() aa = (n-kk+n+1)*kk//2 bb = (0+kk-1)*kk//2 # print(aa) # print(bb) a=aa-bb # print(a) ans+=a+1%MOD print(ans%MOD)
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n,k = map(int, input().split()) mod = 10**9+7 ans = 0 for i in range(k, n + 2): mi = (i - 1) * i // 2 ma = (n + n - i + 1) * i // 2 ans += ma - mi + 1 print(ans % mod)
1
33,205,968,085,718
null
170
170
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)
num = map(int, raw_input().split()) flg=1 while flg==1: flg=0 for i in range(2): if num[i]>num[i+1]: box = num[i] num[i]=num[i+1] num[i+1]=box flg=1 print "%d %d %d" % (num[0],num[1],num[2])
0
null
220,115,485,202
14
40
S = input() def is_kaibun(s): l = len(s) # print('former', s[:int(l/2)]) # print('latter', s[:-(int(l/2))-1:-1]) if s[:int(l/2)] == s[:-(int(l/2))-1:-1]: return True else: return False if is_kaibun(S): if is_kaibun(S[:int((len(S)-1)/2)]): if is_kaibun(S[int((len(S)+3)/2)-1:]): print('Yes') exit() print('No')
S = input() s = list(S) f = s[:int((len(s)-1)/2)] l = s[int((len(s)+3)/2-1):] if f == l: while len(f) > 1: if f[0] == f[-1]: f.pop(0) f.pop() if len(f) <= 1: while len(l) > 1: if l[0] == l[-1]: l.pop(0) l.pop() if len(l) <= 1: print('Yes') else: print('No') else: print('No') else: print('No')
1
46,515,495,614,968
null
190
190
h = int(input()) num = 0 t = 0 while h != 1: h = h//2 num += 2**t t += 1 num += 2**t print(num)
n,m=map(int, input().split()) h=list(map(int, input().split())) near=[[0] for i in h] for i in range(m): a,b=map(int, input().split()) near[a-1].append(h[b-1]) near[b-1].append(h[a-1]) cnt=0 for i in range(n): if max(near[i])<h[i]: cnt+=1 print(cnt)
0
null
52,835,395,208,462
228
155
from collections import deque n = int(input()) a = deque() for i in range(n): c = input() if c == "deleteFirst": a.popleft() elif c == "deleteLast": a.pop() else: c, v = c.split() if c == "insert": a.appendleft(v) else: try: a.remove(v) except: pass print(" ".join(a))
from sys import stdin n = int(stdin.readline()) q = [] bottom = 0 for i in range(n): cmd = stdin.readline()[:-1] if cmd[0] == 'i': q.append(cmd[7:]) elif cmd[6] == ' ': try: q.pop(~q[::-1].index(cmd[7:])) except: pass elif cmd[6] == 'F': q.pop() else: bottom += 1 print(' '.join(q[bottom:][::-1]))
1
51,419,661,720
null
20
20
n=int(input()) itv=[] for i in range(n): x,l=map(int,input().split()) itv+=[(x+l,x-l)] itv=sorted(itv) l=-10**18 cnt=0 for t,s in itv: if l<=s: l=t cnt+=1 print(cnt)
N = int(input()) X = list(map(int, input().split())) MOD = 10 ** 9 + 7 ans = 0 for b in range(61): ctr = [0, 0] for i in range(N): ctr[X[i] >> b & 1] += 1 ans += (1 << b) * ctr[0] * ctr[1] ans %= MOD print(ans)
0
null
106,252,208,493,252
237
263
X = int(input()) Y = X ** 3 print(Y)
#!/usr/bin/env python3 import sys def cube(x): if not isinstance(x,int): x = int(x) return x*x*x if __name__ == '__main__': i = sys.stdin.readline() print('{}'.format( cube( int(i) ) ))
1
275,458,129,312
null
35
35
x = int(input()) if x == 0: print('1') elif x == 1: print('0')
import copy H,W,K=map(int,input().split()) S=[] for _ in range(H): S.append([int(x) for x in list(input())]) ans=(H-1)+(W-1) for i in range(2**(H-1)): check=[0]*H for j in range(H-1): if ((i>>j)&1): check[j+1]=check[j]+1 else: check[j+1]=check[j] g=check[H-1]+1 A=[0]*g c=0 f=0 for j in range(W): B=[0]*g for k in range(H): if S[k][j]==1: B[check[k]]+=1 if B[check[k]]>K: c=10**4 f=1 break if f: break #print("AB",A,B) for l in range(g): if B[l]==0: continue elif A[l]+B[l]>K: c+=1 A=copy.copy(B) break else: A[l]+=B[l] ans=min(ans,c+g-1) print(ans)
0
null
25,715,533,451,384
76
193
from sys import stdin score = [ 0, # Taro 0 # Hanako ] n = int(stdin.readline().rstrip()) for i in range(n): card_pair = stdin.readline().rstrip().split() if card_pair[0] > card_pair[1]: score[0] += 3 elif card_pair[0] < card_pair[1]: score[1] += 3 else: score[0] += 1 score[1] += 1 print(*score)
x, k, d = map(int, input().split()) x = abs(x) k_ = min(k, x // d) k = k - k_ x = x-k_*d if k % 2 != 0: x = abs(x-d) print(x)
0
null
3,651,649,753,820
67
92
MOD = 1e9 + 7 n = int(input()) ans = [[0, 1, 1, 8]] for i in range(n-1): a, b, c, d = ans.pop() a = (a * 10 + b + c) % MOD b = (b * 9 + d) % MOD c = (c * 9 + d) % MOD d = (d * 8) % MOD ans.append([a, b, c, d]) a, b, c, d = ans.pop() print(int(a))
N, K = map(int, input().split()) A = list(map(int, input().split())) r = max(A) l = 0 while l+1 < r: mid = (l+r)//2 cnt = 0 for a in A: if(a > mid): if(a%mid == 0): cnt += (a//mid)-1 else: cnt += a//mid if(cnt > K): l = mid else: r = mid print(r)
0
null
4,843,974,527,822
78
99
N = int(input()) A = list(map(int, input().split())) m = 1000000007 result = 0 for i in range(60): j = 1 << i c = sum((a & j) >> i for a in A) result += (c * (N - c)) << i result %= m print(result)
MOD = 1000000007 n = int(input()) aas = list(map(int, input().split())) KET = 60 arr_0 = [0]*KET arr_1 = [0]*KET for i in aas: bits = format(i,'060b') for j in reversed(range(KET)): if bits[j] == '0': arr_0[KET-j-1] += 1 else: arr_1[KET-j-1] += 1 res = 0 for i in range(KET): res += (arr_0[i]%MOD * arr_1[i]%MOD)%MOD * pow(2,i,MOD) res %= MOD print(res)
1
123,447,075,132,160
null
263
263
N = int(raw_input()) A = map(int, raw_input().split()) counter = 0 while True: ischanged = False for i in xrange(1, N): if A[N-i] < A[N-i-1]: tmp = A[N-i] A[N-i] = A[N-i-1] A[N-i-1] = tmp counter += 1 ischanged = True if ischanged == False: break print " ".join(map(str, A)) print counter
def bubble_sort(array): isEnd = False count_swap = 0 while isEnd is False: isEnd = True for j in reversed(range(1,len(array))): if array[j - 1] > array[j]: tmp = array[j - 1] array[j - 1] = array[j] array[j] = tmp count_swap += 1 isEnd = False return count_swap def print_array(array): print(str(array)[1:-1].replace(', ', ' ')) def main(): N = int(input()) array = [int(s) for s in input().split(' ')] count = bubble_sort(array) print_array(array) print(count) if __name__ == '__main__': main()
1
16,917,867,800
null
14
14
h, w = map(int, input().split()) if h==1 or w == 1: print(1) else: ans = h * w //2 + (h*w)%2 print(ans)
import math H, W = map(int, input().split()) ans = int(H / 2) * W if (H % 2) == 1: ans += math.ceil(W / 2) if H == 1 or W == 1: ans = 1 print(ans)
1
50,806,453,640,530
null
196
196
a,b,c,d=map(int,input().split()) for i in range(a, 0, -d): c=c-b a=a-d if c<=0: print("Yes") else: print("No")
# 高橋君と青木君がモンスターを闘わせます。 # 高橋君のモンスターは体力が Aで攻撃力が Bです。 青木君のモンスターは体力が Cで攻撃力が Dです。 # 高橋君→青木君→高橋君→青木君→... の順に攻撃を行います。 攻撃とは、相手のモンスターの体力の値を自分のモンスターの攻撃力のぶんだけ減らすことをいいます。 # このことをどちらかのモンスターの体力が 0以下になるまで続けたとき、 先に自分のモンスターの体力が 0以下になった方の負け、そうでない方の勝ちです。 # 高橋君が勝つなら Yes、負けるなら No を出力してください。 A, B, C, D = map(int, input().split()) while A or C > 0: aoki_hitpoint = C - B if aoki_hitpoint <= 0: C = 0 print("Yes") exit() else: C = aoki_hitpoint takahashi_hitpoint = A - D if takahashi_hitpoint <= 0: print("No") A = 0 exit() else: A = takahashi_hitpoint
1
29,697,802,581,852
null
164
164
import numpy as np from numba import njit N = np.array([int(_) for _ in input()]) dp = np.array([[0, 0] for _ in range(len(N))]) @njit def solve(N, dp): dp[0, 0] = min(N[0], 11 - N[0]) dp[0, 1] = min(N[0] + 1, 10 - N[0]) for i in range(1, len(N)): dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i]) dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i]) print(dp[-1][0]) solve(N, dp)
from collections import deque n = int(input()) q = deque() for i in range(n): c = input() if c[0] == 'i': q.appendleft(c[7:]) elif c[6] == ' ': try: q.remove(c[7:]) except: pass elif c[6] == 'F': q.popleft() else: q.pop() print(*q)
0
null
35,507,256,183,162
219
20
n,a,b = map(int,input().split()) mod = 10**9+7 def comb(N,x): numerator = 1 for i in range(N-x+1,N+1): numerator = numerator *i%mod denominator = 1 for j in range(1,x+1): denominator = denominator *j%mod d = pow(denominator,mod-2,mod) return (numerator*d)%mod al = pow(2,n,mod)-1 ac =comb(n,a) bc =comb(n,b) print((al-ac-bc)%mod)
A = [int(input()) for i in range(10)] for i in sorted(A)[:-4:-1]: print(i)
0
null
32,912,609,852,028
214
2
def partpall(s,n): if s!=s[::-1]: return False else: return True def pall(s,n): if s!=s[::-1]: return False return partpall(s[n//2 +1 :],n) and partpall(s[:n//2 ],n) # s=input("enter:") s=input() # print("sucess",s,s[::-1]) # revStr=s[::-1] n=len(s) # print(n) if pall(s,n): print("Yes") else: print("No")
S = input() N = len(S) one = S[:(N-1) // 2] two = S[(N+3) // 2 - 1:] if S == S[::-1]: if one == one[::-1]: if two == two[::-1]: print('Yes') exit() print('No')
1
46,035,587,741,088
null
190
190
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() a = nl() ok = -1 ng = 10**18 ans = -1 while ng - ok > 1: v = mid = (ok + ng) // 2 c = 0 cnt = 0 for x in a[:0:-1]: cnt += c + x c += x d = (c - 1) // 2 + 1 if v > c - d: v -= c - d d = c elif v > 0: d += v v = 0 c = d if a[0] + c > 1: ng = mid else: ok = mid ans = cnt + 1 print(ans) return solve()
from itertools import accumulate n = int(input()) As = list(map(int, input().split())) # ノードが1個しかないとき if n == 0: if As[0] == 1:print(1) else:print(-1) exit() # 深さが2以上のとき、初め0ならアウト if As[0] != 0: print(-1) exit() acc_r = list(accumulate(As[::-1])) acc_r = acc_r[::-1] # 一個ずれる acc = acc_r[1:] + [acc_r[-1]] p = 1 ans = 1 for s, a in zip(acc,As): p = min((p-a)*2, s) if p < 0: print(-1) exit() ans += p print(ans)
1
19,001,067,278,260
null
141
141
n,m = [int(x) for x in input().split()] a=[] b=[] for i in range(n): a.append([int(x) for x in input().split()]) for j in range(m): b.append(int(input())) for a_row in a: print(sum([x*y for x,y in zip(a_row,b)]))
N=int(input()) L=list(map(int,input().split())) sort_L=sorted(L,reverse=True) ans=0 for n in range(N-2): for o in range(n+1,N-1): lar=sort_L[n] kouho=sort_L[o+1:] mid=sort_L[o] sa=lar-mid left=0 right=N-o-2 if kouho[-1]>sa: ans+=right+1 else: while right > left + 1: half = (right + left) // 2 if kouho[half] <= sa: right = half else: left = half if kouho[right]<=sa and kouho[left]<=sa: continue elif kouho[right]>sa: ans+=right+1 else: ans+=left+1 print(ans)
0
null
86,902,360,454,848
56
294
import math case_num = 0 N = int(input()) for num in range(N - 1): num += 1 case_num += ( math.ceil(N / num) - 1 ) print(case_num)
N = int(input()) if(N%2 != 0): print(0) else: cnt = 0 n = 1 while n <= N: n *= 5 if(n > N): break num = n*2 cnt += N//num print(cnt)
0
null
59,395,028,821,522
73
258
XY = [int(s) for s in input().split()] X = XY[0] Y = XY[1] if Y % 2 == 0 and Y <= 4 * X and Y >= 2* X: print('Yes') else: print('No')
import sys sys.setrecursionlimit(10**8) 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 li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)] def dp2(ini, i, j): return [[ini]*i for i2 in range(j)] #import bisect #bisect.bisect_left(B, a) #from collections import defaultdict #d = defaultdict(int) d[key] += value #from collections import Counter # a = Counter(A).most_common() #from itertools import accumulate #list(accumulate(A)) S = input() N = len(S) cnt = 0 for i in range(N//2): if S[i] != S[-1-i]: cnt += 1 print(cnt)
0
null
67,151,848,965,310
127
261
import numpy as np def solve(H, A, B): A_max = A.max() dp = np.zeros(H + A_max + 1, dtype=np.int64) for i in range(A_max + 1, H + A_max + 1): dp[i] = np.min(dp[i - A] + B) return dp[-1] H, N, *AB = map(int, open(0).read().split()) A = np.array(AB[::2], dtype=np.int64) B = np.array(AB[1::2], dtype=np.int64) print(solve(H, A, B))
import sys input = sys.stdin.readline H, N = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N)] dp = [10**10]*(H+1) dp[0] = 0 for i in range(H): for ab in AB: a,b = ab[0], ab[1] idx = i+a if i+a < H else H dp[idx] = min(dp[idx], dp[i]+b) print(dp[H])
1
81,011,752,497,350
null
229
229
n = int(input()) a =list(map(int,input().split())) b = sorted(a) c = [0]*n for i in range(0,n-1): c[a[i]-1]+=1 for i in range(n): print(c[i])
n = int(input()) lst = list(map(int,input().split())) lst2 = [0 for i in range(n)] for i in range(n - 1): x = lst[i] lst2[x - 1] = lst2[x - 1] + 1 for i in range(n): print(lst2[i])
1
32,477,460,443,742
null
169
169
from collections import deque num = deque() n = int(input()) for i in range(n): com = input().split() if com[0] == "deleteFirst": num.popleft() elif com[0] == "deleteLast": num.pop() elif com[0] == "insert": num.insert(0, com[1]) elif com[0] == "delete": if num.count(com[1]): num.remove(com[1]) print(" ".join(num))
data = input() x = int(data) x = x*x*x print("{0}".format(x))
0
null
163,243,665,610
20
35
# -*- coding: utf-8 -*- import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) A = list(map(int,readline().split())) INF = 10 ** 18 # -2 -1 0 1 #dp_use 見ている文字を使った dp_not_use 見ている文字を使わない dp_use = [-INF] * 4 dp_not_use = [-INF] * 4 dp_not_use[0] = 0 for a in A: tmp_use = [-INF] * 4 tmp_not_use = [-INF] * 4 for current_diff in range(-2,2): if current_diff - 1 >= -2: tmp_use[current_diff] = dp_not_use[current_diff-1] + a if current_diff + 1 < 2: tmp_not_use[current_diff] = max(dp_use[current_diff+1],dp_not_use[current_diff+1]) dp_use = tmp_use dp_not_use = tmp_not_use diff = -1 + (N+1) % 2 print(max(dp_use[diff],dp_not_use[diff]))
#!/usr/bin/env python from fractions import gcd def main(): A, B = map(int, input().split()) print(A * B // gcd(A, B)) if __name__ == '__main__': main()
0
null
75,428,807,461,568
177
256
from functools import reduce n = int(input()) a = list(map(int, input().split())) b = reduce(lambda acc, cur: acc ^ cur, a[1:], a[0]) print(*map(lambda x: x ^ b, a))
from bisect import bisect_right N, D, A = map(int, input().split()) xh = sorted([list(map(int, input().split())) for _ in range(N)]) ds = [0]*(N+2) b = 0 for i, (x, h) in enumerate(xh, 1): ds[i] += ds[i-1]###(*) ###これまでのやつに与えたダメージは引き継がれるものとする d = ds[i] if d>=h: continue###すでに体力以上のダメージを与えた敵 h -= d###ダメージを与える times = h//A if h%A==0 else h//A+1 ds[i] += times*A ds[bisect_right(xh, [x+2*D, float('inf')])+1] -= times*A ###(*)のせいで, 2Dよりも向こう側にも、今考えたダメージの影響が ###出てしまうので. それを打ち消すために与えるダメージを引いておく b += times print(b)
0
null
47,450,945,019,572
123
230
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = sr() bl = False if S[2] == S[3] and S[4] == S[5]: bl = True print('Yes' if bl else 'No')
def resolve(): S = input() print('Yes' if S[2]==S[3] and S[4]==S[5] else 'No') resolve()
1
42,218,549,444,722
null
184
184
n=int(input()) flag=0 for i in range(1,10): if (n%i)==0: if (n//i)<=9: flag=1 break if flag==1: print ('Yes') else: print ('No')
def main(): n = int(input()) a_lst = list(map(int, input().split())) dic = dict() for i in range(n - 1): if a_lst[i] in dic: dic[a_lst[i]] += 1 else: dic[a_lst[i]] = 1 dic_keys = dic.keys() for i in range(1, n + 1): if i in dic_keys: print(dic[i]) else: print(0) if __name__ == "__main__": main()
0
null
96,415,680,512,640
287
169
import math import fractions import collections import itertools import pprint N=int(input()) A=list(map(int,input().split())) que=[] dp=[[0 for _ in range(N+1)] for _ in range(N+1)] #dp[i][j]…左にiこ、みぎにjこあること状態になった時の最大をいれる for i in range(N): que.append([A[i],i]) que.sort(key=lambda x:x[0],reverse=True) #pprint.pprint(dp) #print(que) for i in range(0,N+1): if i!=0: for j in range(i+1): if j==0:#dp[i][0],左にiこつまる状態に dp[i-j][j]=dp[i-j-1][j]+(que[i-1][0]*abs((i-1)-que[i-1][1])) elif j==i:#dp[0][i],みぎにiこ詰まる状態に dp[i-j][j]=dp[i-j][j-1]+(que[i-1][0]*abs(N-j-que[i-1][1])) else: dp[i-j][j]=max(dp[i-j-1][j]+(que[i-1][0]*abs(((i-1)-j)-que[i-1][1])),dp[i-j][j-1]+(que[i-1][0]*abs(N-j-que[i-1][1]))) #input() #pprint.pprint(dp) ma=0 for i in range(0,N+1): #print(dp[N-i][i]) ma=max(ma,dp[N-i][i]) print(ma) """ st=[-1]*N en=[-1]*N s=[[0,[0,0]] for _ in range(N*N)] for i in range(N): for j in range(N): s[i*N+j][0]=A[i]*abs(i-j) s[i*N+j][1][0]=i s[i*N+j][1][1] = j s.sort(key=lambda x:x[0],reverse=True) print(s) cnt=0 for i in range(len(s)): a=s[i][1][0] b=s[i][1][1] c=s[i][0] if (st[a]==-1)and(en[b]==-1): cnt=cnt+c st[a]=0 en[b]=0 print(cnt) """
(N,) = map(int, input().split()) As = list(enumerate(map(int, input().split()))) As.sort(key=lambda x: -x[1]) dp = [[0] * (N + 1) for _ in range(N + 1)] for i, (pos, val) in enumerate(As): for j in range(i + 1): k = i - j dp[j + 1][k] = max(dp[j + 1][k], dp[j][k] + abs(j - pos) * val) dp[j][k + 1] = max(dp[j][k + 1], dp[j][k] + abs(N - 1 - k - pos) * val) print(max(dp[i][N - i] for i in range(N + 1)))
1
33,733,663,856,298
null
171
171
import sys input = sys.stdin.readline #n = int(input()) #l = list(map(int, input().split())) ''' a=[] b=[] for i in range(): A, B = map(int, input().split()) a.append(A) b.append(B)''' import numpy as np n=int(input()) a = np.array([int(i) for i in input().split()]) ans=0 for i in range(60): cnt=np.count_nonzero(a&1) ans+=(n-cnt)*cnt*(2**i) if ans>=10**9+7: ans%=(10**9+7) a>>=1 print(ans)
p0 = 10**9+7 def pow(x,m): if m==0: return 1 if m==1: return x if m%2==0: return (pow(x,m//2)**2)%p0 else: return (x*(pow(x,(m-1)//2)**2)%p0)%p0 N = int(input()) A = list(map(int,input().split())) A = [bin(A[i])[2:] for i in range(N)] A = ["0"*(60-len(A[i]))+A[i] for i in range(N)] C = {k:0 for k in range(60)} for i in range(N): for m in range(60): if A[i][m]=="1": C[59-m] += 1 B = [0 for _ in range(60)] for k in range(60): p = C[k] m = N-C[k] B[k] = p*m cnt = 0 for k in range(60): cnt = (cnt+B[k]*pow(2,k))%p0 print(cnt)
1
123,058,587,421,548
null
263
263
a,b,n = list(map(int,input().split())) i = min(n,b-1) print(a*i//b)
N = input() keta = len(N) dp = [[10**18 for i in range(2)] for j in range(keta)] t = int(N[-1]) dp[0][0] = t dp[0][1] = 10 - t for i in range(keta - 2, -1, -1): t = int(N[i]) #print(keta-i,i,t) dp[keta-i-1][0] = min(dp[keta-i-2][0]+t,dp[keta-i-2][1]+t+1) dp[keta-i-1][1] = min(dp[keta-i-2][0]+(10-t),dp[keta-i-2][1]+(10-(t+1))) #a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1))) #print(dp) print(min(dp[keta-1][0],dp[keta-1][1]+1))
0
null
49,708,064,596,802
161
219
import math n=input() m=math.radians(60) def kock(n, p1x, p1y, p2x, p2y): if(n == 0): return sx=(2*p1x+1*p2x)/3 sy=(2*p1y+1*p2y)/3 tx=(1*p1x+2*p2x)/3 ty=(1*p1y+2*p2y)/3 ux=(tx-sx)*math.cos(m)-(ty-sy)*math.sin(m)+sx uy=(tx-sx)*math.sin(m)+(ty-sy)*math.cos(m)+sy kock(n-1, p1x, p1y, sx, sy) print round(sx,8),round(sy, 8) kock(n-1, sx, sy, ux, uy) print round(ux, 8),round(uy, 8) kock(n-1, ux, uy, tx, ty) print round(tx, 8),round(ty, 8) kock(n-1, tx, ty, p2x, p2y) p1x = 0.00000000 p1y = 0.00000000 p2x = 100.00000000 p2y = 0.00000000 print p1x, p1y kock(n, p1x, p1y, p2x, p2y) print p2x, p2y
import math n = int(raw_input()) def func(i, ox1, oy1, ox2, oy2): if i != n: nx1 = ox1 + (ox2 - ox1) / 3 ny1 = oy1 + (oy2 - oy1) / 3 nx2 = ox1 + (ox2 - ox1) * 2 / 3 ny2 = oy1 + (oy2 - oy1) * 2 / 3 if nx1 < nx2: if ny1 == ny2: nx3 = nx1 + (nx2 - nx1) / 2 ny3 = ny1 + (nx2 - nx1) * math.sqrt(3) / 2 elif ny1 < ny2: nx3 = ox1 ny3 = ny2 elif ny1 > ny2: nx3 = ox2 ny3 = ny1 elif nx1 > nx2: if ny1 == ny2: nx3 = nx1 + (nx2 - nx1) / 2 ny3 = ny1 - (nx1 - nx2) * math.sqrt(3) / 2 elif ny1 < ny2: nx3 = ox2 ny3 = ny1 elif ny1 > ny2: nx3 = ox1 ny3 = ny2 func(i+1, ox1, oy1, nx1, ny1) func(i+1, nx1, ny1, nx3, ny3) func(i+1, nx3, ny3, nx2, ny2) func(i+1, nx2, ny2, ox2, oy2) elif i == n: print(str(ox1) + str(" ") + str(oy1)) func(0, 0.0, 0.0, 100.0, 0.0) print(str(100) + str(" ") + str(0))
1
125,415,304,910
null
27
27
n=int(input()) s_str=[] for i in range(2): s_str.append(input().split()) s_int=[] for i in s_str: s_int.append([int(s) for s in i]) manh=0 yu=0 p_3=0 che=[] for i in range(n): manh+=abs(s_int[0][i]-s_int[1][i]) yu+=(s_int[0][i]-s_int[1][i])**2 p_3+=(abs(s_int[0][i]-s_int[1][i]))**3 che.append(abs(s_int[0][i]-s_int[1][i])) print(manh) print(yu**(1/2)) print(p_3**(1/3)) print(max(che))
def minkovsky(A,B,n = 0): C = [abs(a - b) for a , b in zip(A,B)] if n == 0: return max(C) else: d = 0 for c in C: d += c ** n d = d ** (1 / n) return d N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) print(minkovsky(A,B,1)) print(minkovsky(A,B,2)) print(minkovsky(A,B,3)) print(minkovsky(A,B))
1
204,153,472,588
null
32
32
import sys read = sys.stdin.read def main(): N, K = map(int, read().split()) dp1 = [0] * (K + 1) dp2 = [0] * (K + 1) dp1[0] = 1 for x in map(int, str(N)): dp1, dp1_prev = [0] * (K + 1), dp1 dp2, dp2_prev = [0] * (K + 1), dp2 for j in range(K, -1, -1): if j > 0: dp2[j] = dp2_prev[j - 1] * 9 if x != 0: dp2[j] += dp1_prev[j - 1] * (x - 1) dp2[j] += dp2_prev[j] if x != 0: dp2[j] += dp1_prev[j] if x != 0: if j > 0: dp1[j] = dp1_prev[j - 1] else: dp1[j] = dp1_prev[j] print(dp1[K] + dp2[K]) return if __name__ == '__main__': main()
n=int(input()) K=int(input()) m=len(str(n)) N=list(map(int,str(n))) dp=[[[0,0]for j in range(K+1)]for i in range(m+1)] dp[0][0][0]=1 for i in range(1,1+m): for j in range(K+1): for k in range(10): if k==0: if N[i-1]==k: dp[i][j][0]+=dp[i-1][j][0] elif N[i-1]>k: dp[i][j][1]+=dp[i-1][j][0] dp[i][j][1]+=dp[i-1][j][1] else: if j<K: if N[i-1]==k: dp[i][j+1][0]+=dp[i-1][j][0] elif N[i-1]>k: dp[i][j+1][1]+=dp[i-1][j][0] dp[i][j+1][1]+=dp[i-1][j][1] print(sum(dp[-1][K]))
1
76,113,684,793,196
null
224
224
N = input() n = int(N[-1]) if n in [2,4,5,7,9]: print('hon') elif n == 3: print('bon') else: print('pon')
n = input() a = n[-1] if a in '3': print('bon') elif a in '0168': print('pon') else: print('hon')
1
19,112,951,909,570
null
142
142
import bisect import copy import heapq import math import sys from collections import * from itertools import accumulate, combinations, permutations, product from math import gcd def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n,m=map(int,input().split()) half=n//2 lst=[] if n%2==1: for i in range(m): lst.append([half-i,half+i+1]) else: for i in range(m): if i%2==0: lst.append([half-i//2,half+i//2+1]) else: lst.append([1+i//2,n-1-i//2]) for i in range(m): print(*lst[i]) # dic=defaultdict(int) # for i in range(m): # tmp=lst[i] # dic[tmp[1]-tmp[0]]+=1 # dic[n-tmp[1]+tmp[0]]+=1 # print(dic)
a=int(input());print(a-~a*a*a)
0
null
19,455,094,575,140
162
115
import fractions a,b=map(int,input().split()) c = fractions.gcd(a,b) print(int((a*b)/c))
A, B = map(int, input().split(" ")) if A % B == 0: print(A) elif B % A == 0: print(B) else: A_, B_ = A, B common = 1 n_max = int(min(A,B)**0.5+1) for n in range(2, n_max+1): while True: if (A_ % n == 0) and (B_ % n == 0): common *= n A_ = A_ // n B_ = B_ // n else: break print(common * A_ * B_)
1
113,667,337,657,510
null
256
256
H, W= map(int, input().split()) A=[] b=[] ans=[0 for i in range(H)] for i in range(H): A.append(list(map(int, input().split()))) for j in range(W): b.append(int(input())) for i in range(H): for j in range(W): ans[i]+=A[i][j]*b[j] print(ans[i])
n,m = map(int, input().split()) c = [] d = [] for i in range(n): arr = input().split() c.append(arr) for j in range(m): d.append(int(input())) for i in range(n): sum = 0 for j in range(m): sum += int(c[i][j])*d[j] print(sum)
1
1,177,400,510,690
null
56
56
#ABC165-A K = int(input()) X = list(map(int,input().split())) if (X[0] // K + 1) * K <= X[1] or X[0] % K == 0: print("OK") else: print("NG")
K = int(input()) A, B = map(int, input().split()) XK = list(x * K for x in range(1, 1000//K + 1)) for i in XK: if (A <= i) & (i <= B): print('OK') break else: print('NG')
1
26,550,595,638,752
null
158
158
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 #mod = 998244353 INF = 10**18 eps = 10**-7 N = int(input()) 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() m=len(divisors) if m%2==0: print(divisors[m//2]+divisors[m//2-1]-2) else: print(divisors[m//2]*2-2)
k = int(input()) n = 7 for i in range(k): if n % k == 0: print(i+1) exit() n %= k n = (n*10+7) % k print(-1)
0
null
83,627,032,836,762
288
97
d, t, f = map(int, input().split()) if (d/t) <= f: print('Yes') else: print('No')
d,t,s = input().split() if(int(s) * int(t) >= int(d)): print('Yes') else: print('No')
1
3,494,158,187,960
null
81
81
from itertools import permutations from math import sqrt, pow, factorial N = int(input()) l = [list(map(int, input().split())) for _ in range(N)] def calc(a, b): [x1, y1] = a [x2, y2] = b return sqrt(pow(x1 - x2, 2) + pow(y1 -y2, 2)) ans = 0 for order in permutations(range(N)): tmp = 0 for i in range(1, N): tmp += calc(l[order[i]], l[order[i-1]]) ans += tmp print(ans/factorial(N))
import math, itertools n = int(input()) X = list(list(map(int,input().split())) for _ in range(n)) L = list(itertools.permutations(range(n),n)) ans = 0 for l in L: dist = 0 for i in range(n-1): s,t = l[i],l[i+1] vx = X[s][0] - X[t][0] vy = X[s][1] - X[t][1] dist += math.sqrt(vx**2 + vy**2) ans += dist print(ans/len(L))
1
147,969,871,679,052
null
280
280
s,t,a,b,u=open(0).read().split() if s==u: print(int(a)-1,b) elif t==u: print(a,int(b)-1)
a = list(map(int,input().split())) print(15-sum(a))
0
null
42,704,715,164,228
220
126
data = [] while True: in_line = raw_input().split() m = int(in_line[0]) f = int(in_line[1]) r = int(in_line[2]) if m == -1 and f == -1 and r == -1: break if m == -1 or f == -1: data.append("F") elif m + f >= 80: data.append("A") elif m + f >= 65: data.append("B") elif m + f >= 50: data.append("C") elif m + f >= 30: if r >= 50: data.append("C") else: data.append("D") else: data.append("F") for n in data: print n
s = input() if s == 'RRR': print(3) elif s[:2] == "RR" or s[1:] == "RR": print(2) elif 'R' in s: print(1) else: print(0)
0
null
3,061,983,073,090
57
90
import sys import math n, k = map(int, sys.stdin.readline().split()) W = [] for _ in range(n): w = int(sys.stdin.readline()) W.append(w) r = sum(W) l = max(W) pre_p = 0 while l < r: current = 0 num_tracks = 1 p = (l + r) // 2 # 値を設定 # 積み込めるか確認 for w in W: if current + w > p: num_tracks += 1 # 次のトラックを持ってくる current = w else: current += w if num_tracks > k: # 現在の p ではトラックが足りない場合 l = p + 1 # 最少値を上げる else: r = p # 最大値を下げる print(l)
while True: mid_score, term_score, re_score = map(int, input().split()) if mid_score == term_score == re_score == -1: break test_score = mid_score + term_score score = '' if test_score >= 80: score = 'A' elif test_score >= 65: score = 'B' elif test_score >= 50: score = 'C' elif test_score >=30: if re_score >= 50: score = 'C' else: score = 'D' else: score = 'F' if mid_score == -1 or term_score == -1: score = 'F' print(score)
0
null
645,706,233,758
24
57
#coding:utf-8 #1_1_B def gcd(x, y): while x%y != 0: x, y = y, x%y return y x, y = map(int, input().split()) print(gcd(x, y))
def gcd(a, b): # ?????§??¬?´???° while b > 0: a, b = b, a % b return a a, b = map(int, input().split()) print(gcd(a, b))
1
7,876,214,592
null
11
11
n = input() a, b = input().split(" ") output = "" for s, t in zip(a, b): output += s output += t print(output)
n = int(input()) s,t = map(str, input().split()) res = str() for i in range(n): res += s[i] res += t[i] print(res)
1
112,465,082,462,550
null
255
255
import math a,b,x = map(int,input().split()) if b*a**2 == x: print(0) exit() s = 2*x/(a*b) if s < a: print(math.atan(b/s)/math.pi*180) else: s = 2*b-2*x/(a**2) print(90-math.atan(a/s)/math.pi*180)
n = int(input()) if n%2!=0: print(0) else: cnt = 0 n = n//2 while n>0: cnt = cnt + (n//5) n = n//5 print(cnt)
0
null
139,994,103,208,472
289
258
from collections import deque import sys input = sys.stdin.readline N, u, v = map(int, input().split()) u -= 1 v -= 1 edges = [[] for _ in range(N)] for _ in range(N - 1): fr, to = map(int, input().split()) fr -= 1 to -= 1 edges[fr].append(to) edges[to].append(fr) def minDist(start): minDist = [10**10] * N que = deque([(start, 0, -1)]) while que: now, d, pr = que.popleft() if minDist[now] <= d: continue minDist[now] = d for to in edges[now]: if to == pr: continue if minDist[to] > d + 1: que.append((to, d + 1, now)) return minDist minDistU = minDist(u) minDistV = minDist(v) ans = 0 for du, dv in zip(minDistU, minDistV): if du <= dv: ans = max(ans, dv - 1) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) INF = float('inf') N, u, v = map(int, input().split()) u, v = u-1, v-1 adjL = [[] for _ in range(N)] for _ in range(N-1): a, b = map(int, input().split()) a, b = a-1, b-1 adjL[a].append(b) adjL[b].append(a) def bfsMinCosts(adjList, vSt, INF): numV = len(adjList) costs = [INF] * numV costs[vSt] = cost = 0 vs = [vSt] while vs: cost += 1 v2s = [] for v in vs: for v2 in adjList[v]: if costs[v2] == INF: costs[v2] = cost v2s.append(v2) vs = v2s return costs costUs = bfsMinCosts(adjL, u, INF) costVs = bfsMinCosts(adjL, v, INF) ans = 0 for x in range(N): if costUs[x] < costVs[x]: if costVs[x] > ans: ans = costVs[x] print(ans-1)
1
117,251,750,772,530
null
259
259
m = 100000 for i in range(int(raw_input())): m*=1.05 m=(int((m+999)/1000))*1000 print m
S,T = input().split() A,B = map(int, input().split()) U = input() ans=0 if U==S: ans=A-1,B else: ans=A,B-1 print(' '.join(map(str,ans)))
0
null
35,732,168,662,420
6
220
def sum_part(N, k): return k*(2*N-k+1)/2-k*(k-1)/2+1 N, K = map(int, input().split()) ans = 0 for k in range(K,N+2): ans += sum_part(N, k) ans = ans % (10**9 + 7) print(int(ans))
r = float(input()) pi = 3.141592653589 S = r * r * pi L = 2 * r * pi print(str(S) + " " + str(L))
0
null
16,868,230,570,750
170
46
x, y = map(int,input().split()) while True: if x >= y: x %= y else: y %= x if x == 0 or y == 0: print(x+y) break
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)
0
null
16,579,298,021,220
11
170
from sys import stdin, maxsize def stdinput(): return stdin.readline().strip() def main(): n = int(stdinput()) *A, = map(int, stdinput().split(' ')) o = mergeSort(A, 0, n) print(*A) print(o) def merge(A, left, mid, right): L = A[left:mid] R = A[mid:right] cap = maxsize L.append(cap) R.append(cap) i = j = 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 return i + j def mergeSort(A, left, right): o = 0 if left + 1 < right: mid = (left + right) // 2 o += mergeSort(A, left, mid) o += mergeSort(A, mid, right) o += merge(A, left, mid, right) return o if __name__ == '__main__': main() # import cProfile # cProfile.run('main()')
def merge(a, left, mid, right): global count l = a[left:mid] + [sentinel] r = a[mid:right] + [sentinel] i = j = 0 for k in range(left, right): if l[i] <= r[j]: a[k] = l[i] i += 1 else: a[k] = r[j] j += 1 count += right - left def merge_sort(a, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(a, left, mid) merge_sort(a, mid, right) merge(a, left, mid, right) sentinel = 10 ** 9 + 1 n = int(input()) a = list(map(int, input().split())) count = 0 merge_sort(a, 0, len(a)) print(*a) print(count)
1
112,296,467,836
null
26
26
MOD=10**9+7 class Fp(int): def __new__(self,x=0):return super().__new__(self,x%MOD) def inv(self):return self.__class__(super().__pow__(MOD-2,MOD)) def __add__(self,value):return self.__class__(super().__add__(value)) def __sub__(self,value):return self.__class__(super().__sub__(value)) def __mul__(self,value):return self.__class__(super().__mul__(value)) def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv()) def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD)) __radd__=__add__ __rmul__=__mul__ def __rsub__(self,value):return self.__class__(-super().__sub__(value)) def __rfloordiv__(self,value):return self.__class__(self.inv()*value) def __iadd__(self,value):self=self+value;return self def __isub__(self,value):self=self-value;return self def __imul__(self,value):self=self*value;return self def __ifloordiv__(self,value):self=self //value;return self def __ipow__(self,value):self=self**value;return self def __neg__(self):return self.__class__(super().__neg__()) def main(): N,*A=map(int, open(0).read().split()) C=[0]*(N+1) C[-1]=3 ans=Fp(1) for a in A: ans*=C[a-1] C[a-1]-=1 C[a]+=1 print(ans) if __name__ == "__main__": main()
p_max = 100000 * 10000 nk = list(map(int, input().split())) w = [int(input()) for i in range(nk[0])] def search(pt): m = 0 for j in range(nk[1]): weight = 0 while weight + w[m] <= pt: weight += w[m] m += 1 if m == nk[0]: return nk[0] return m def main(): st_p = p = 0 en_p = p_max while en_p - st_p > 1: p = int((en_p + st_p) / 2) chk = search(p) if chk >= nk[0]: en_p = p else: st_p = p return en_p if __name__ == '__main__': print(main())
0
null
65,179,910,291,818
268
24
n = input().split(" ") print(int(n[0]) * int(n[1]))
n=int(input());s=input();print('No' if n%2!=0 or s[:n//2]!=s[n//2:] else 'Yes')
0
null
81,344,969,300,448
133
279
while True : H, W = map(int, raw_input().split(" ")) if (H == W == 0) : break ans = "" for h in range(0, H) : for w in range(0, W) : if ((w + h) % 2 == 0) : ans += "#" else : ans += "." ans += "\n" print("%s" % (ans))
n, *a = map(int, open(0).read().split()) mod = 10 ** 9 + 7 ans = 0 for i in range(60): cnt = 0 for j in range(n): cnt += a[j] >> i & 1 ans = (ans + (1 << i) * cnt * (n - cnt) % mod) % mod print(ans)
0
null
61,695,418,434,910
51
263
def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p p = 10 ** 9 + 7 N = 2 * 10 ** 6 # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) X, Y = map(int, input().split()) #(1, 2)の回数をn, (2, 1)の回数をmとする。 n = (-X + 2 * Y) / 3 m = (-Y + 2 * X) / 3 #いけない場合を除外 if n % 1 != 0: print(0) quit() elif m % 1 != 0: print(0) quit() #n + m C nで答え ans = cmb(int(n + m), int(n), p) print(ans)
import sys from io import StringIO import unittest import os # 検索用タグ、10^9+7 組み合わせ、スプレッドシートでのトレース # 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む) sys.setrecursionlimit(999999999) def cmb(n, r): mod = 10 ** 9 + 7 ans = 1 for i in range(r): ans *= n - i ans %= mod for i in range(1, r + 1): ans *= pow(i, mod - 2, mod) ans %= mod return ans def prepare_simple(n, mod=pow(10, 9) + 7): # n! の計算 f = 1 for m in range(1, n + 1): f *= m f %= mod fn = f # n!^-1 の計算 inv = pow(f, mod - 2, mod) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= mod invs[m - 1] = inv return fn, invs def prepare(n, mod=pow(10, 9) + 7): # 1! - n! の計算 f = 1 factorials = [1] # 0!の分 for m in range(1, n + 1): f *= m f %= mod factorials.append(f) # n!^-1 の計算 inv = pow(f, mod - 2, mod) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= mod invs[m - 1] = inv return factorials, invs # 実装を行う関数 def resolve(test_def_name=""): x, y = map(int, input().split()) all_move_count = (x + y) // 3 x_move_count = all_move_count y_move_count = 0 x_now = all_move_count * 2 y_now = all_move_count canMake= False for i in range(all_move_count+1): if x_now == x and y_now == y: canMake = True break x_move_count -= 1 y_move_count += 1 x_now -= 1 y_now += 1 if not canMake: print(0) return ans = cmb(all_move_count,x_move_count) print(ans) # テストクラス class TestClass(unittest.TestCase): def assertIO(self, assert_input, output): stdout, sat_in = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(assert_input) resolve(sys._getframe().f_back.f_code.co_name) sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, sat_in self.assertEqual(out, output) def test_input_1(self): test_input = """3 3""" output = """2""" self.assertIO(test_input, output) def test_input_2(self): test_input = """2 2""" output = """0""" self.assertIO(test_input, output) def test_input_3(self): test_input = """999999 999999""" output = """151840682""" self.assertIO(test_input, output) # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること def tes_t_1original_1(self): test_input = """データ""" output = """データ""" self.assertIO(test_input, output) # 実装orテストの呼び出し if __name__ == "__main__": if os.environ.get("USERNAME") is None: # AtCoder提出時の場合 resolve() else: # 自PCの場合 unittest.main()
1
149,987,941,162,588
null
281
281
s=input() t=input() if len(s)+1==len(t) and t.find(s)==0: 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,479,603,667,478
null
147
147
import sys import math def gcd(x,y): if(x%y==0): return y else: return(gcd(y,x%y)) try: while True: a,b= map(int, input().split()) max1=gcd(a,b) min1=(a*b)//gcd(a,b) print(str(max1)+' '+str(min1)) except EOFError: pass
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))
0
null
76,749,672,052,352
5
283
X = int(input()) ans="No" if X>=30: ans='Yes' print(ans)
def main(): X = int(input()) if X >=30: return "Yes" return "No" if __name__ == '__main__': print(main())
1
5,757,182,569,700
null
95
95
h, n = map(int, input().split()) ab = [] for _ in range(n): ab.append(map(int, input().split())) m = 20010 dp = [1000000000] * m dp[0] = 0 for a, b in ab: for i in range(m): if i - a >= 0: dp[i] = min(dp[i], dp[i - a] + b) print(min(dp[h:]))
N,A,B=map(int,input().split()) if (B-A)%2==0: print((B-A)//2) else: if A-1<=N-B: #Aが1に到達するまで+AとBの距離が2の倍数になるまで x=A-1+1 #Aは負け続け、Bは勝ち続ける y=(B-A)//2 print(x+y) else: #BがNに到達するまで+AとBの距離が2の倍数になるまで x=N-B+1 #Aは勝ち続け、Bは負け続ける y=(B-A)//2 print(x+y)
0
null
94,780,204,561,498
229
253
a=int(input('')) if a==0: print('1') else: print('0')
w, h, x, y, r = map(int, input().split()) if x>=r and y>=r and x<= w-r and y<=h-r: print("Yes") else: print("No")
0
null
1,691,711,360,232
76
41
a = [int(input()) for i in range(2)] if a[0] == 1: if a[1] == 2: my_result = 3 else: my_result = 2 elif a[0] == 2: if a[1] == 1: my_result = 3 else: my_result = 1 else: if a[1] == 1: my_result = 2 else: my_result = 1 print(my_result)
def main(): a = int(input()) b = int(input()) if a == 1 and b == 2 or a == 2 and b == 1: print(3) elif a == 2 and b == 3 or a == 3 and b == 2: print(1) elif a == 3 and b == 1 or a == 1 and b == 3: print(2) if __name__ == '__main__': main()
1
110,617,222,646,138
null
254
254
n=input() if 65<=ord(n)<=90: print("A") else: print("a")
import math import sys # sys.setrecursionlimit(100000) def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return [int(i) for i in input().split()] def main(): n = input_int() _x = [] _y = [] for _ in range(n): x, y = input_int_list() # 座標系を45度回転させて考える _x.append(x - y) _y.append(x + y) ans = max(max(_x) - min(_x), max(_y) - min(_y)) print(ans) return if __name__ == "__main__": main()
0
null
7,326,913,553,120
119
80
S, T = map(str, input().split()) print(T+S)
A, B, M = map(int, input().split()) a = [int(s) for s in input().split()] b = [int(s) for s in input().split()] m = [] for n in range(M): m.append([int(s) for s in input().split()]) minValue = min(a) + min(b) for i in range(M): discountPrice = a[m[i][0] - 1] + b[m[i][1] - 1] - m[i][2] if discountPrice < minValue: minValue = discountPrice print(minValue)
0
null
78,668,125,472,680
248
200
a,b=map(int,raw_input().split()) print(a*b)
A,B=input().split() A=int(A) B=int(100*float(B)+0.1) print(int(A*B/100))
1
15,708,992,148,768
null
133
133
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): print('Yes' if ni() >= 30 else 'No') return solve()
# coding: utf-8 # Your code here! import sys import math n=int(input()) ans=n for i in range(1,int(math.sqrt(n))+1): if n%i==0: a=i b=int(n/i) if a+b-2<ans: ans=a+b-2 print(ans)
0
null
83,969,088,103,290
95
288
def main(): N, K, C = map(int, input().split()) S = input() # greedy head, tail = [-C - 1] * (K + 1), [N + C + 1] * (K + 1) idx = 0 for i in range(N): if S[i] == 'o' and i - head[idx] > C: idx += 1 head[idx] = i if idx == K: break idx = K for i in range(N - 1, -1, -1): if S[i] == 'o' and tail[idx] - i > C: idx -= 1 tail[idx] = i if idx == 0: break # ans for i in range(K): if head[i + 1] == tail[i]: print(tail[i] + 1) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(1000000) input = sys.stdin.readline INF = 2**62-1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(N, K, C, S): def f(S): r = 0 w = [] c = 0 for s in S: if r == 0 and s == 'o': w.append(1) r = C c += 1 else: w.append(0) r = max(0, r-1) return w lw = f(S) rw = list(reversed(f(reversed(S)))) if sum(lw) != K: return for i, (l, r) in enumerate(zip(lw, rw)): if l == r == 1: print(i+1) def main(): N, K, C = read_int_n() S = read_str() (slv(N, K, C, S)) if __name__ == '__main__': main()
1
40,885,449,625,702
null
182
182
if __name__ == "__main__": N = int(input()) ans = 'No' for i in range(1, 10): for j in range(1, 10): if i*j == N: ans = 'Yes' print(ans)
N = int(input()) A = list(map(int,input().split())) + [0] kabu = 0 money = 1000 for p in range(N): #株がない時 if A[p] < A[p+1]: kabu += money//A[p] money -= (money//A[p])*A[p] #株があるとき if A[p] > A[p+1]: money += kabu*A[p] kabu = 0 #print(str(p+1) + "日目" + str(money) + " " +str(kabu)) print(money)
0
null
83,212,885,355,350
287
103
if __name__ == '__main__': n = int(input()) print(n + n * n + n * n * n )
a=int(input()) result=a+a**2+a**3 print(int(result))
1
10,156,657,629,678
null
115
115
import sys prm = sys.stdin.readline() S = int(prm) h = S / (60 * 60); S = S % (60 * 60); m = S / 60; s = S % 60; print str(h)+':'+str(m)+':'+str(s)
def main(): match_count = int(input()) matches = [input().split() for i in range(match_count)] taro_result = [3 if match[0] > match[1] else 1 if match[0] == match[1] else 0 for match in matches] print('%d %d' % (sum(taro_result), sum(3 if item == 0 else 1 if item == 1 else 0 for item in taro_result)) ) main()
0
null
1,152,709,525,230
37
67
n, m = list(map(int, input().split())) A = [list(map(int, input().split())) for i in range(n)] bt = [int(input()) for i in range(m)] for i in range(n): print(sum([x * y for (x, y) in zip(A[i], bt)]))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines H,W = map(int,readline().split()) S = ''.join(read().decode().split()) INF = 10 ** 9 N = H*W U = 250 dp = [[INF] * U for _ in range(N)] # そのマスをいじる回数 → 総回数の最小値 dp[0] = list(range(U)) for n in range(H*W): for i in range(U-1,0,-1): if dp[n][i-1]> dp[n][i]: dp[n][i-1] = dp[n][i] for i in range(1,U): if dp[n][i-1] + 1 < dp[n][i]: dp[n][i] = dp[n][i-1] + 1 s = S[n] if s == '#': for i in range(0,U,2): dp[n][i] = INF else: for i in range(1,U,2): dp[n][i] = INF x,y = divmod(n,W) to = [] if y < W - 1: to.append(n+1) if x < H - 1: to.append(n+W) for m in to: for i in range(U): if dp[m][i] > dp[n][i]: dp[m][i] = dp[n][i] print(min(dp[-1]))
0
null
25,127,174,453,778
56
194
while True: n=input() if n=='-': break else: m=int(input()) for i in range(m): h=int(input()) n=n[h:len(n)]+n[:h] print(n)
ans = [] while (1) : word = input().strip() try : inputLen = int( input().strip() ) except : break for i in range(0, inputLen) : h = int( input().strip() ) word = word[h:] + word[:h] ans.append(word) for s in ans : print(s)
1
1,889,309,489,672
null
66
66
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])
from itertools import accumulate N, K = map(int, input().split()) mod = 998244353 Move = [list(map(int, input().split())) for _ in range(K)] DP = [0] * N DP[0] = 1 DP[1] = -1 cnt = 0 for i in range(N): DP[i] += cnt DP[i] %= mod cnt = DP[i] for l, r in Move: if i + l < N: DP[i+l] += DP[i] if i + r + 1 < N: DP[i + r + 1] -= DP[i] print(DP[-1])
1
2,706,697,977,084
null
74
74
n = int(input()) squares = list(map(int, input().split(" "))) odd = 0 for i in range(0, n, 2): if squares[i] % 2: odd += 1 print(odd)
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate, product, combinations_with_replacement import sys import bisect import string import math import time def I(): return int(input()) def S(): return input() def MI(): return map(int, input().split()) def MS(): return map(str, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def ItoS(nn): return chr(nn+97) def input(): return sys.stdin.readline().rstrip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def print_matrix(mat): for i in range(len(mat)): print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]]) yn = {False: 'No', True: 'Yes'} YN = {False: 'NO', True: 'YES'} MOD = 10**9+7 inf = float('inf') IINF = 10**19 l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() sys.setrecursionlimit(10**6) nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] show_flg = False # show_flg = True def gcd(a, b): if b == 0: return a return gcd(b, a % b) def main(): N = I() zero = 0 cnts = defaultdict(int) used = set() for i in range(N): a, b = MI() if a == 0 and b == 0: zero += 1 continue g = gcd(abs(a), abs(b)) a = a // g b = b // g if b < 0: a = -a b = -b cnts[(a, b)] += 1 # print(cnts) ans = 1 for key, c in cnts.items(): if key in used: continue a, b = key if a > 0: rev = (-b, a) else: rev = (b, -a) if rev in cnts: # keyの集合から一個以上選ぶ + revの集合から一個以上選ぶ + どれも選ばない ans *= (pow(2, cnts[key], MOD) - 1) + (pow(2, cnts[rev], MOD) - 1) + 1 # print(key, rev, ans) ans %= MOD used.add(rev) else: ans *= pow(2, cnts[key], MOD) ans += zero ans -= 1 print(ans % MOD) if __name__ == '__main__': main()
0
null
14,394,583,556,402
105
146
from sys import stdin #入力 readline=stdin.readline N,K=map(int,readline().split()) A=list(map(int,readline().split())) A.sort() mod=10**9+7 fact=[1]*(N+1) finv=[1]*(N+1) inv=[1]*(N+1) inv[0]=0 for i in range(2,N+1): fact[i]=(fact[i-1]*i%mod) inv[i]=(-inv[mod%i]*(mod//i))%mod finv[i]=(finv[i-1]*inv[i])%mod def com(N,K,mod): if (K<0) or (N<K): return 0 return fact[N]*finv[K]*finv[N-K]%mod s=0 for i in range(N-1,K-2,-1): s+=A[i]*com(i,K-1,mod) for i in range(N-K+1): s-=A[i]*com(N-i-1,K-1,mod) s%=mod print(s)
# !/usr/local/bin/python3 MOD = int(1e9+7) def nCk(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n]*(finv[n-k]*finv[k]%MOD)%MOD def solve(): a.sort() for i in range(2, MAX_N): fac[i] = fac[i-1]*i%MOD inv[i] = MOD-(inv[MOD%i])*(MOD//i)%MOD finv[i] = finv[i-1]*inv[i]%MOD max_x = 0 for i in range(k-1, n): max_x = (max_x+a[i]*nCk(i, k-1))%MOD min_x = 0 for i in range(n-k+1): min_x = (min_x+a[i]*nCk(n-i-1, k-1))%MOD return((max_x-min_x)%MOD) if __name__ == "__main__": n, k = list(map(int, input().split())) a = [(lambda x: int(x))(x) for x in input().split()] MAX_N = n+5 fac = [1, 1]+[0 for _ in range(MAX_N)] finv = [1, 1]+[0 for _ in range(MAX_N)] inv = [0, 1]+[0 for _ in range(MAX_N)] print(solve())
1
95,822,870,332,160
null
242
242
S = input() mx = 0 c = 0 for si in S: if si == 'R': c += 1 mx = max(mx, c) else: c = 0 print(mx)
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 s = str(readline().rstrip().decode('utf-8')) if s == "RRR": print(3) elif s == "RRS" or s == "SRR": print(2) elif s.count("R") == 0: print(0) else: print(1) if __name__ == '__main__': solve()
1
4,943,215,619,188
null
90
90
N, K = map(int, input().split()) A = list(map(int, input().split())) A = [0] + A #print(A) machi = 1 road = [0,1] Keiyu = [0]*(N+1) for n in range(1, N+1): if Keiyu[machi] == 0: Keiyu[machi] = n road.append(A[machi]) machi = A[machi] else: S = Keiyu[machi] - 1 E = n - 1 break #print(road) #print(Keiyu) #print(S) #print(E) if K <= S: print(road[K+1]) else: K = K - S K = S + K % (E-S) print(road[K+1])
n,k=map(int,input().split()) A=[0]+list(map(int,input().split())) color=["white" for _ in range(n+1)] DP,index=[],1 while 1: if color[index]=="white":color[index]="gray" elif color[index]=="gray":color[index]="black" DP.append(A[index]) index=A[index] if color[index]=="black":break repeat=[] for i in DP: if color[i]=="black": repeat.append(i) if repeat[0]==i and len(repeat)!=1: repeat.pop() break length=len(repeat) cnt=0 for i in DP: if repeat[0]==i:break cnt +=1 if k<=cnt+length: print(DP[k-1]) else: k -=cnt k %=length print(repeat[k-1])
1
22,732,822,738,472
null
150
150
n, k = map(int, input().split()) xs = set() for i in range(k): d = int(input()) xs = xs.union(set(map(int, input().split()))) print(n - len(xs))
n,m,l=map(int, input().split()) a=[] b=[] for i in range(n): a.append(list(map(int, input().split()))) for j in range(m): b.append(list(map(int, input().split()))) for i in range(n): ci=[0]*l for k in range(l): for j in range(m): ci[k]+=a[i][j]*b[j][k] print(*ci)
0
null
13,063,504,350,536
154
60
D, T, S = map(int, input().split()) print("Yes" if D <= (T*S) else 'No')
import sys def input(): return sys.stdin.readline().rstrip() from collections import Counter def main(): n = int(input()) C = input() C_cunt = Counter(C) cunt_r = C_cunt['R'] ans = 0 for i in range(cunt_r): if C[i] == 'W': ans += 1 print(ans) if __name__=='__main__': main()
0
null
4,906,737,455,802
81
98
l = [int(i) for i in input().split()] l.sort() print(str(l[0])+' '+str(l[1])+' '+str(l[2]))
S, T = map(str, input().split()) A, B = map(int, input().split()) U = input() if U == S: A -= 1 A = str(A) B = str(B) print(A+' '+B) else : B -= 1 A = str(A) B = str(B) print(A+' '+B)
0
null
36,351,004,485,500
40
220
a1, a2, a3 = (map(int, input().split())) if sum([a1, a2, a3]) >= 22: print('bust') else: print('win')
A,B,C=map(int, input().split()) D=A+B+C if D>=22: print('bust') else : print('win')
1
118,889,191,315,340
null
260
260
def main(): A, B, C = map(int, input().split()) K = int(input()) while K > 0 and A >= B: B *= 2 K -= 1 while K > 0 and B >= C: C *= 2 K -= 1 if A < B < C: print("Yes") else: print("No") if __name__ == "__main__": main()
num = map(int,input().split()) s=sum(num) print(15-s)
0
null
10,089,498,347,480
101
126
n = int(input()) a = list(map(int, input().split())) c = 1 ans = 0 for i in range(n): if a[i] == c: c += 1 else: ans += 1 if c>1: print(ans) else: print(-1)
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() lst = LI() cnt = 1 ans = 0 for brock in lst: if brock == cnt: cnt += 1 else: ans += 1 if cnt != 1: print(ans) else: print(-1) main()
1
115,029,570,134,638
null
257
257
from functools import reduce n = input() a = list(map(int, input().split())) s = int(reduce(lambda i,j: i^j, a)) print(' '.join(list(map(lambda x: str(x^s), a))))
N = int(input()) L = list(map(int,input().split())) ans = [0 for i in range(N)] for i in range(len(L)): ans[L[i]-1] += 1 for i in range(N): print(ans[i])
0
null
22,470,804,241,920
123
169
H, W = map(int, input().split()) S = [list(input()) for h in range(H)] table = [[0 for w in range(W)] for h in range(H)] table[0][0] = int(S[0][0]=='#') for i in range(1, H): table[i][0] = table[i-1][0] + int(S[i-1][0]=='.' and S[i][0]=='#') for j in range(1, W): table[0][j] = table[0][j-1] + int(S[0][j-1]=='.' and S[0][j]=='#') for i in range(1, H): for j in range(1, W): table[i][j] = min(table[i-1][j] + int(S[i-1][j]=='.' and S[i][j]=='#'), table[i][j-1] + int(S[i][j-1]=='.' and S[i][j]=='#')) print(table[-1][-1])
# A - Range Flip Find Route h,w=map(int,input().split()) s=[input() for i in range(h)] inf=10**18 dp=[[inf]*(w+1) for i in range(h+1)] if s[0][0]=="#": dp[0][0]=1 else: dp[0][0]=0 for i in range(h): for j in range(w): for y,x in ([1,0],[0,1]): ni,nj=i+y,j+x if ni>=h or nj>=w:continue c=0 if s[ni][nj]=="#" and s[i][j]==".":c=1 dp[ni][nj]=min(dp[ni][nj],dp[i][j]+c) print(dp[h-1][w-1])
1
49,313,064,340,978
null
194
194
# Aizu Problem ITP_1_7_A: Grading # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") while True: m, f, r = [int(_) for _ in input().split()] score = m + f if m == f == r == -1: break elif m == -1 or f == -1: print('F') elif score >= 80: print('A') elif score >= 65: print('B') elif score >= 50 or (score >= 30 and r >= 50): print('C') elif score >= 30: print('D') else: print('F')
n,m = map(int,input().split()) if 0 < n and n < 10 and 0 < m and m < 10: print(n*m) else: print(-1)
0
null
79,683,568,247,230
57
286
while True: L = map(int,raw_input().split()) H = (L[0]) W = (L[1]) if H == 0 and W == 0:break for x in range(0,H):print "#" * W print ""
#!/usr/bin/env python3 # -*- coding: utf-8 -*- n = int(input()) r = False for i in range(1,10): if n % i == 0: if n // i < 10: r = True break if r: print('Yes') else: print('No')
0
null
80,362,875,867,088
49
287
n = int(raw_input()) tp = 0; hp = 0 for i in range(n): tw,hw = raw_input().split() if tw == hw: tp += 1 hp += 1 elif tw > hw: tp += 3 elif tw < hw: hp += 3 print '%s %s' % (tp,hp)
h=t=0 for _ in range(int(input())): a,b=input().split() if a>b:t+=3 elif a<b:h+=3 else:t+=1;h+=1 print(t,h)
1
2,030,454,031,388
null
67
67
s = input() map = {'SSS': 0, 'SSR': 1, 'SRS': 1, 'RSS': 1, 'SRR': 2, 'RSR': 1, 'RRS': 2, 'RRR': 3} for key in map.keys(): if s == key: print(map[key]) break
s=input() num=s.count("R") if num==2: if s=="RSR": ans=1 else: ans=2 else: ans=num print(ans)
1
4,865,492,204,970
null
90
90
INF = 10 ** 9 + 7 N, K = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) if K == 1: print(a[0]) exit() if K == N: ans = 1 for i in a: ans *= i ans %= INF print(ans) exit() if a[0] < 0: ans = 1 if K % 2 == 1: for i in range(K): ans *= a[i] ans %= INF else: for i in range(K): ans *= a[-i - 1] ans %= INF print(ans) exit() sei = [] hu = [] for i in a: if i >= 0: sei.append(i) else: hu.append(i) hu.sort() seis = [] hus = [] total = [] ans = 1 if K % 2 != 0: ans = sei[0] % INF for i in range(2, len(sei), 2): seis.append(sei[i] * sei[i - 1]) else: for i in range(1, len(sei), 2): seis.append(sei[i] * sei[i - 1]) for i in range(1, len(hu), 2): hus.append(hu[i] * hu[i - 1]) total = hus + seis total.sort(reverse=True) for i in range(K // 2): ans *= total[i] ans %= INF print(ans)
mod = 1000000007 N, K = map(int, input().split()) pos = [] neg = [] A = list(map(int, input().split())) for i in range(N): if A[i] > 0: pos.append(A[i]) else: neg.append(A[i]) ans = 1 if len(pos) == 0: if K % 2 == 0: neg.sort(reverse=True) else: neg.sort() for i in range(K): ans = (ans * neg.pop()) % mod elif N == K: for i in pos: ans = (ans * i) % mod for i in neg: ans = (ans * i) % mod else: pos.sort() neg.sort(reverse=True) if K % 2 == 1: ans = pos.pop() for i in range(K//2): if len(pos) > 1 and len(neg) > 1: if pos[-1] * pos[-2] > neg[-1] * neg[-2]: for _ in range(2): ans = ans * pos.pop() % mod else: for _ in range(2): ans = ans * neg.pop() % mod elif len(pos) > 1: for _ in range(2): ans = ans * pos.pop() % mod else: for _ in range(2): ans = ans * neg.pop() % mod print(ans)
1
9,484,119,876,272
null
112
112
import sys def m(): d={};input() for e in sys.stdin: if'f'==e[0]:print('yes'if e[5:]in d else'no') else:d[e[7:]]=0 if'__main__'==__name__:m()
n = int(input()) ans = -1 for k in range(n, 0, -1): if n == k * 108 // 100: ans = k break if ans > 0: print(ans) else: print(':(')
0
null
62,953,932,020,640
23
265