code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
import sys import math import itertools import collections from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def main(): N = NI() ans = 0 for n in range(1,N+1): ans += (N//n)*(2*n+(N//n-1)*n)//2 print(ans) if __name__ == '__main__': main()
N = int(input()) P = list(map(int, input().split())) mn = N + 1 ans = 0 for p in P: if p < mn: ans += 1 mn = min(mn, p) print(ans)
0
null
48,229,050,531,548
118
233
n,r = [int(x) for x in input().split()] if n > 10: print(r) else: print(r + 100 * (10 - n))
def generate_arr(a): if len(a) == N: arr.append(a) return for i in range(1,N+1): if i not in a: generate_arr(a+[i]) N = int(input()) P = list(map(int, input().split())) Q = list(map(int, input().split())) arr = [] generate_arr([]) arr.sort() ans_p = 0 ans_q = 0 for i in range(len(arr)): if arr[i] == P: ans_p = i+1 if arr[i] == Q: ans_q = i+1 print(abs(ans_p-ans_q))
0
null
81,855,542,067,530
211
246
n = int(input()) s = input() if n % 2 == 1: print("No") else: t = s[:n//2] if t * 2 == s: print("Yes") else: print("No")
a,b=map(int,input().split());print(a//b,a%b,'%.8f'%(a/b))
0
null
73,780,295,040,440
279
45
n = int(input()) #a, b = map(int, input().split()) #l = list(map(int, input().split())) s = input() ans = 1 last = s[0] for i in range(1,n): if last != s[i]: last = s[i] ans = ans + 1 print(ans)
N = int(input()) S = input() A = [] x = 0 for i in range(N): A.append(S[i]) for i in range(N): if i != N - 1: if A[i + 1] == A[i]: x += 1 print(len(A) - x)
1
169,353,620,063,850
null
293
293
a, b, c = map(int, input().split()) divisitor = [] for i in range(a, b+1): if a < 0 or b < 0 or c < 0: break elif a > 10001 or b > 10001 or c > 10001: break elif a > b: break elif c % i == 0: divisitor.append(int(c/i)) print((len(divisitor)))
from itertools import repeat print(sum((lambda a, b, c: map(lambda r, n: n % r == 0, range(a, b+1), repeat(c)) )(*map(int, input().split()))))
1
554,870,367,840
null
44
44
import sys from fractions import gcd [print("{} {}".format(gcd(k[0], k[1]), (k[0] * k[1]) // gcd(k[0], k[1]))) for i in sys.stdin for k in [[int(j) for j in i.split()]]]
#ALDS1_3-B Elementary data structures - Queue n,q = [int(x) for x in input().split()] Q=[] for i in range(n): Q.append(input().split()) t=0 res=[] while Q!=[]: if int(Q[0][1])<=q: res.append([Q[0][0],int(Q[0][1])+t]) t+=int(Q[0][1]) else: Q.append([Q[0][0],int(Q[0][1])-q]) t+=q del Q[0] for i in res: print(i[0]+" "+str(i[1]))
0
null
22,398,109,450
5
19
def main(): H1,M1,H2,M2,K = [int(x) for x in input().split()] if M2 >= M1: diff = (H2-H1)*60 + M2-M1 else: diff = (H2-H1)*60 + 60-M1+M2 -60 if diff <= 0: print(0) else: print(diff - K) if __name__ == '__main__': main()
N = int(input().rstrip()) l = list(map(int, input().rstrip().split())) #l = list(set(l)) l.sort(reverse=True) num = 0 for i in range(len(l) - 2): for j in range(i + 1, len(l) - 1): if l[i] == l[j]: continue for k in range(j + 1, len(l)): if l[j] == l[k]: continue if l[i] < (l[j] + l[k]): num += 1 print(num)
0
null
11,595,049,796,288
139
91
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * from heapq import heapify, heappop, heappush import math import random import string from copy import deepcopy from itertools import combinations, permutations, product from operator import mul, itemgetter from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# """ N日間のうちK日選んで働く 働いたらそれからC日間は働かない Sにxがついていたら働かない oの付いてる日のみ働く 全ての通りを求めてみよう N, K, C = 11, 3, 2 S = ooxxxoxxxoo の時 働けるのは[1, 2, 6, 10, 11]日目 ここから3つ以上間が空く条件で3つ選ぶと条件を満たす 全ての通りでi日目に働く必要がある A = [1, 2, 5, 7, 11, 13, 16] M = 4 C = 3 for bit in range(1 << len(A)): cnt = [] for i in range(len(A)): if bit & (1 << i): cnt.append(A[i]) if len(cnt) == 4: for i in range(1, len(cnt)): if cnt[i] - cnt[i - 1] <= C: break else: print(cnt) # python index.py [1, 5, 11, 16] [1, 7, 11, 16] [2, 7, 11, 16] A = [1, 2, 5, 10, 24] M = 3 C = 2 [1, 5, 10] [2, 5, 10] [1, 5, 24] [2, 5, 24] [1, 10, 24] [2, 10, 24] [5, 10, 24] [1, 5, 10, 24] M + 1回以上ジャンプできる場合には答えが[]になる A[0]から頑張ってもM回しかジャンプできない 間がC + 1以上離れたM個の集合はどのように求める? 必ず働く日の特性は? 動かすと? 場所は固定? """ # N, K, C = getNM() # S = getN() N, K, C = getNM() S = input() # i回目に選べる要素の上限と下限を比べる place = [] for i in range(N): if S[i] == 'o': place.append(i) # 下限 出来るだけ前の仕事を選べるように fore = [place[0]] for i in place[1:]: if i - fore[-1] > C: fore.append(i) # 上限 出来るだけ後ろの仕事を選ぶように back = deque([]) back.append(place[-1]) for i in place[::-1]: if back[0] - i > C: back.appendleft(i) back = list(back) if len(fore) != K: print() exit() ans = [] for a, b in zip(fore, back): if a == b: ans.append(a + 1) for i in ans: print(i) """ fore = [0] * N if S[0] == 'o': fore[0] = 1 for i in range(1, N): fore[i] = fore[i - 1] if S[i] == 'o' and i - C - 1 >= 0: fore[i] = max(fore[i], fore[i - C - 1] + 1) back = [float('inf')] * N ma = max(fore) if S[N - 1] == 'o': back[N - 1] = ma for i in range(N - 2, -1, -1): back[i] = min(ma, back[i + 1]) if S[i] == 'o' and i + C + 1 < N: back[i] = min(back[i], back[i + C + 1] - 1) print(back) """
import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] tin=lambda : map(int, input().split()) lin=lambda : list(tin()) mod=1000000007 #+++++ def main(): #a = int(input()) n, k, c_yutori = tin() if n == 1: return 1 s = input() can_work = [0]*n can_work[0] = 1 if s[0]=='o' else 0 yn = c_yutori if s[0]=='o' else 0 for i, c in enumerate( list(s)[1:],1): if yn == 0 and c == 'o': can_work[i] = can_work[i-1]+1 yn = c_yutori else: can_work[i] = can_work[i-1] yn = max(0, yn - 1) need_to_work = [k]*n if s[-1]=='o': need_to_work[-1] = k-1 yn = c_yutori else: need_to_work[-1]=k yn=0 for i, c in enumerate(list(s)[-2::-1],1): pos = n-i-1 if yn == 0 and c == 'o': need_to_work[pos] = need_to_work[pos+1]-1 yn = c_yutori else: need_to_work[pos]=need_to_work[pos+1] yn = max(0, yn-1) #pa(can_work) #pa(need_to_work) if need_to_work[1] == 1: print(1) for i in range(1, n-1): if can_work[i-1] < need_to_work[i+1]: print(i+1) if can_work[-2]==k-1: print(n) #+++++ isTest=False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform =='ios': if input_method==input_methods[0]: ic=input_clipboard() input = lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else: pass isTest=True else: pass #input = sys.stdin.readline ret = main() if ret is not None: print(ret)
1
40,737,856,885,660
null
182
182
n=int(input());s=input();print('No'if s[:n//2]!=s[n//2:] else'Yes')
number = list(map(int,input().split())) score = list(map(int,input().split())) waza = 0 for i in range(number[1]): waza += score[i] if number[0] <= waza: print('Yes') else: print('No')
0
null
112,297,311,704,192
279
226
A,B,C = map(int, input().split()) K = int(input()) for i in range(K): if B >= C or A >= C: C *= 2 else: if A >= B: B *= 2 if C > B and B > A: print("Yes") else: print("No")
# B>G>R R,G,B = map(int,input().split()) K = int(input()) cnt = 0 while not G>R: G *= 2 cnt += 1 while not B>G: B *= 2 cnt += 1 if cnt<=K: print("Yes") else: print("No")
1
6,913,417,059,360
null
101
101
import math import sys from collections import Counter readline = sys.stdin.readline def main(): l = int(readline().rstrip()) print((l/3)**3) if __name__ == '__main__': main()
n = int(input()) a = list(map(int, input().split())) t1 = 0 t2 = sum(a) ans = 10**18 for i in a: t1 += i t2 -= i ans = min(ans, abs(t1 - t2)) print(ans)
0
null
94,505,529,203,360
191
276
n=int(input()) p=10**9+7 A=list(map(int,input().split())) binA=[] for i in range(n): binA.append(format(A[i],"060b")) lis=[0 for i in range(60)] for binAi in binA: for j in range(60): lis[j]+=int(binAi[j]) binary=[0 for i in range(60)] for i in range(n): for j in range(60): if binA[i][j]=="0": binary[j]+=lis[j] else: binary[j]+=n-lis[j] binary[58]+=binary[59]//2 binary[59]=0 explis=[1] for i in range(60): explis.append((explis[i]*2)%p) ans=0 for i in range(59): ans=(ans+binary[i]*explis[58-i])%p print(ans)
line = list(input()) N = len(line) i = 1 for i in range(N): if line[i] == "?": line[i] = "D" print("".join(line))
0
null
70,676,795,565,880
263
140
data = [] for i in xrange(4): tou = [] data.append(tou) for j in xrange(3): kai = [0 for k in xrange(10)] tou.append(kai) n = int(raw_input()) for i in xrange(n): b,f,r,v = map(int, raw_input().split(" ")) data[b-1][f-1][r-1] = max(0, data[b-1][f-1][r-1] + v) for tou in data: if not tou is data[0]: print "#" * 20 for kai in tou: print " " + " ".join(map(str, kai))
n = int(input()) room_list = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] for i in range(n): b, f, r, v = map(int, input().split()) room_list[b - 1][f - 1][r - 1] += v output =[] for i in range(4): for j in range(3): output = list(map(str, room_list[i][j])) print(" " + " ".join(output)) if i < 3: print("#" * 20)
1
1,111,233,129,028
null
55
55
a=input().split() if (a[0]==a[1] and a[1]==a[2] and a[0]==a[2] )or (a[0]!=a[1] and a[1]!=a[2] and a[0]!=a[2]): print('No') else: print('Yes')
from collections import defaultdict def main(): N = int(input()) d = defaultdict(int) results = ["AC", "WA", "TLE", "RE"] for _ in range(N): d[input()] += 1 for r in results: print(f"{r} x {d[r]}") if __name__ == '__main__': main()
0
null
38,260,216,860,160
216
109
MOD = int(1e9+7) def main(): S = int(input()) dp = [[0] * (S+1) for _ in range(S//3+2)] for i in range(3, S+1): dp[1][i] = 1 for i in range(2, S//3+2): sm = sum(dp[i-1]) % MOD sm = (sm - sum(dp[i-1][S-2:S+1])) % MOD for j in range(3*i, S+1)[::-1]: dp[i][j] = sm sm = (sm - dp[i-1][j-3]) % MOD ans = 0 for i in range(S//3+2): ans = (ans + dp[i][S]) % MOD print(ans) if __name__ == "__main__": main()
n = int(input()) print((n+2-1)//2)
0
null
31,143,507,227,712
79
206
import math K = int(input()) S = 0 for a in range(1, K+1): for b in range(1, K+1): T = math.gcd(a, b) for c in range(1, K+1): S += math.gcd(T, c) print(S)
import sys def II(): return int(input()) def MI(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def TI(): return tuple(map(int,input().split())) def RN(N): return [input().strip() for i in range(N)] def main(): a, b = MI() L = sorted([a, b]) if L[0] == a: ans = int(str(a)*b) else: ans = int(str(b)*a) print(ans) if __name__ == "__main__": main()
0
null
60,236,700,685,000
174
232
r = int(input()) ans = r * r print(ans)
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if not V > W: print("NO") elif (V-W)*T >= abs(B-A): print("YES") else: print("NO")
0
null
80,195,320,777,352
278
131
N, K = map(int, input().split()) n = N%K m = K - n print(min(abs(n), abs(m)))
n,k = map(int, input().split()) ans=n % k if abs(ans-k)<ans: print(abs(ans-k)) else: print(ans)
1
39,359,718,407,490
null
180
180
r, c = map(int, input().split(' ')) matrix = [] total_cols = [0 for i in range(c+1)] for i in range(r): rows = list(map(int, input().split(' '))); total = sum(rows) rows.append(total) total_cols = [ total_cols[i] + x for i, x in enumerate(rows) ] matrix.append(rows) matrix.append(total_cols) for row in matrix: print(' '.join([str(i) for i in row]))
import math n = int(input()) from collections import defaultdict d = defaultdict(list) s = set() zc = 0 for i in range(n): a,b = map(int, input().split()) g = math.gcd(a,b) if g!=0: a //= g; b //= g if a<0: a,b = -a, -b elif a==0 and b<0: b *= -1 d[a,b].append(i) if a==b==0: zc += 1 v = 1 s = set() M = 10**9+7 for (a,b),val in d.items(): aa,bb = b,-a if aa<0: aa,bb = -aa, -bb elif aa==0 and bb<0: bb *= -1 if (a,b) in s or (aa,bb) in s: continue if (aa,bb) in d.keys(): v *= (pow(2, len(val), M) + pow(2, len(d[aa,bb]), M) - 1) else: v *= pow(2, len(val), M) v %= M s.add((a,b)) s.add((aa,bb)) v -= 1 v += zc print(v%M)
0
null
11,050,028,411,620
59
146
n = int(input()) list = [[0 for i in range(10)] for j in range(12)] for i in range(n): b,f,r,v = map(int,input().split()) list[3*(b - 1)+(f - 1)][r - 1] += v for i in range(12): if i % 3 == 0 and i != 0: print('####################') for j in range(10): print(' {}'.format(list[i][j]),end = "") if j == 9: print('')
# 20-String-Shuffle.py # ?????£????????? # ???????????¢????????????????????????????????? n ???????????????????±±????????£????????????????????? # 1???????????£???????????§??????????????? h ???????????????????????¨???????????????????????????????????£????????????????±±?????????????????????????????? # ?????????????±±?????\???????????????????????????????????§????????????????????? # abcdeefab # ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? # ????????°???????????? h ??? 4 ??§?????£?????????????????¨????????????4?????? abcd ?????? # ??????????????? eefab ???????°??????£?????????????????§??\?????????????????????????????? # eefababcd # ???????????£???????????????????????°?????????????????? # ?????????????±±???????????????????????????????????¨ h ??????????????????????????? # ?????????????????????????????????????????????????????°????????????????????????????????? # Constraints # ?????????????????????200????¶?????????? # ?????£?????????????????°???100????¶?????????? # Input # ?????°??????????????????????????\?????¨?????????????????????????????????????????????????????\????????¢?????§????????????????????? # ????????????????????¨???????????? # ?????£??????????????° m # h1 # h2 # . # . # hm # ????????????????????¨??????????????? "-" ?????¨?????\?????????????????¨???????????? # Output # ?????????????????????????????????????????????????????????????????????????????????????????????????????? # Sample Input # aabc # 3 # 1 # 2 # 1 # vwxyz # 2 # 3 # 4 # - # Sample Output # aabc # xyzvw card=[] shuffle_times=[] shuffle_num=[] #??\??? while 1: card.append( input() ) if card[-1]=="-": break; shuffle_times.append( int(input()) ) # print("shuffle_times",shuffle_times) # print("shuffle_times[-1]",shuffle_times[-1]) temp=[] for i in range(shuffle_times[-1]): temp.append( int(input()) ) shuffle_num.append(temp) #??\????????? for i in range(len(card)-1): for j in range(shuffle_times[i]): card[i] = card[i][shuffle_num[i][j]:] + card[i][:shuffle_num[i][j]] # ?????? print(card[i])
0
null
1,486,571,339,840
55
66
r = int(input()) print( 2 * 3.14159268 * r )
n=int(input());print((n//2)/n if n%2==0 else -(-n//2)/n)
0
null
104,026,961,483,962
167
297
s = input("") if "RRR" in s: print(3) elif "RR" in s: print(2) elif "R" in s: print(1) else: print(0)
s = input() ans = 0 for i in range(3): if s[i] == 'R': ans += 1 else: if ans == 1: break print(ans)
1
4,954,177,691,450
null
90
90
from collections import deque n = int(input()) dlist = deque() for i in range(n): code = input().split() if code[0] == "insert": dlist.insert(0,code[1]) if code[0] == "delete": try: dlist.remove(code[1]) except: continue if code[0] == "deleteFirst": dlist.popleft() if code[0] == "deleteLast": dlist.pop() print(*dlist,sep=" ")
from collections import deque n = int(input()) l = deque() for _ in range(n): cmd = input().split() if cmd[0] == 'insert': l.appendleft(cmd[1]) elif cmd[0] == 'delete': try: l.remove(cmd[1]) except: pass elif cmd[0] == 'deleteFirst': l.popleft() else: l.pop() print(*l)
1
53,543,602,070
null
20
20
N = int(input()) A = [list(map(int, input().split())) for _ in range(N)] for i in range(N - 2): if all(x == y for (x, y) in A[i:i+3]): print('Yes') break else: print('No')
#!/usr/bin/env python3 def next_line(): return input() def next_int(): return int(input()) def next_int_array_one_line(): return list(map(int, input().split())) def next_int_array_multi_lines(size): return [int(input()) for _ in range(size)] def next_str_array(size): return [input() for _ in range(size)] def main(): h, w, k = map(int, input().split()) ch = [] for _ in range(h): ch.append(next_line()) # print(ch) res = 0 for i in range(1 << h): for j in range(1 << w): count = 0 for l in range(h): for m in range(w): if ch[l][m] == "#" and (i & (1 << l) == 0) and (j & (1 << m) == 0): count += 1 if count == k: res += 1 print(res) if __name__ == '__main__': main()
0
null
5,693,794,744,000
72
110
n, p = map(int, input().split()) s = input() r = set() last = 0 d = {0: 0} total = 0 rem = 0 if p == 2: for i in range(0, len(s)): if int(s[i]) % 2 == 0: total += i + 1 print(total) elif p == 5: for i in range(0, len(s)): if int(s[i]) % 5 == 0: total += i + 1 print(total) else: power = 1 for i in range(len(s) - 1, -1, -1): # handling of 0's as n and rem n = int(s[i]) * power + rem power *= 10 power = power % p rem = n % p if rem in d.keys(): d[rem] += 1 else: d[rem] = 1 total += d[rem] - 1 print(total + d[0])
n, p = map(int, input().split()) s = input() a = [] c = 0 if p == 2: b = [0]*n for i in range(n): if int(s[i])%2 == 0: b[i] += 1 for i in range(n): if b[i] == 1: c += i+1 elif p == 5: b = [0]*n for i in range(n): if int(s[i])%5 == 0: b[i] += 1 for i in range(n): if b[i] == 1: c += i+1 else: b = [0]*p b[0] = 1 d = [1] a.append(int(s[-1])%p) for i in range(n-1): d.append(d[-1]*10%p) for i in range(1, n): a.append((int(s[-i-1])*d[i]+a[i-1])%p) for i in range(n): b[a[i]] += 1 for i in range(p): c += int(b[i]*(b[i]-1)/2) print(c)
1
58,214,724,256,058
null
205
205
import sys input=lambda :sys.stdin.readline().rstrip() mod = 10**9+7 n, k = map(int, input().split()) d = [0] * (k+1) for i in range(1, k+1): d[i] = pow(k//i, n, mod) for i in range(k, 0, -1): for j in range(2*i, k+1, i): d[i] -= d[j] d[i] %= mod ans=0 for i in range(1, k+1): ans += d[i]*i ans %= mod print(ans)
import sys input=lambda: sys.stdin.readline().rstrip() n,k=map(int,input().split()) mod=10**9+7 A=[0]*(k+1) for i in range(1,k+1)[::-1]: cur=pow(k//i,n,mod) for j in range(2,k+1): if i*j>k: break else: cur-=A[i*j] A[i]=cur ans=0 for i in range(1,k+1): ans=(ans+i*A[i])%mod print(ans)
1
36,868,590,495,462
null
176
176
y=x=int(input()) while y%360:y+=x print(y//x)
x = int(input()) idx = 0 tmp = 0 while 1: tmp += x idx += 1 if tmp % 360 == 0: break print(idx)
1
13,093,134,882,308
null
125
125
# 解説を参考に作成 # import sys # sys.setrecursionlimit(10 ** 6) # import bisect # from collections import deque import math # from decorator import stop_watch # # # @stop_watch def solve(N, K, As): ans = max(As) l, r = 1, ans for _ in range(30): m = (l + r) // 2 cnt = 0 for A in As: cnt += math.ceil(A / m) - 1 if cnt <= K: ans = min(ans, m) r = m - 1 else: l = m + 1 if l > r: break print(ans) if __name__ == '__main__': # S = input() # N = int(input()) N, K = map(int, input().split()) As = [int(i) for i in input().split()] # Bs = [int(i) for i in input().split()] solve(N, K, As)
while True: y,x = [int(i) for i in input().split()] if y==x==0: break print('#'*x) for i in range(y-2): print('#'+'.'*(x-2)+'#') if y > 1: print('#'*x) print()
0
null
3,630,001,606,192
99
50
N, K, S = map(int, input().split()) if S == 1000000000: fill = 1000000000 - 1 else: fill = S+1 print(' '.join(map(str, ([S]*K + [fill]*(N-K)))))
N,K,S = map(int,input().split()) if S != 10**9: for _ in range(K): print(S,end = ' ') for _ in range(N - K): print(10**9,end = ' ') else: for _ in range(K): print(10**9,end = ' ') for _ in range(N - K): print(1,end = ' ') print()
1
90,995,063,869,480
null
238
238
def main(): S = list(input()) T = [] reverse = False n_q = int(input()) for i in range(n_q): q = input().split(" ") if q[0] == "1": reverse = not reverse elif q[0] == "2": f = q[1] c = q[2] if (f == "1" and not reverse) or (f == "2" and reverse): T.append(c) elif (f == "1" and reverse) or (f == "2" and not reverse): S.append(c) if reverse: S.reverse() ans = S + T elif not reverse: T.reverse() ans = T + S print("".join(ans)) main()
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() A = inpl() B = inpl() aa = 0 bb = 0 i = 0 for tmp in itertools.permutations(range(1,n+1)): i += 1 if list(tmp) == A: aa = i if list(tmp) == B: bb = i print(abs(aa - bb))
0
null
78,886,841,473,738
204
246
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()
s=input() res="No" if len(s)==6 and s[2]==s[3] and s[4]==s[5]:res="Yes" print(res)
0
null
21,741,509,567,052
62
184
# Transformation string = input() commandAmount = int(input()) for i in range(commandAmount): command = input().rstrip().split() start = int(command[1]) end = int(command[2]) if command[0] == 'print': print(string[start : end + 1]) # ここはコメントアウトしないこと elif command[0] == 'reverse': replacedString = list(string) # print(replacedString) for i in range(start, end + 1): replacedString[i] = list(string)[start + end - i] # print(replacedString) string = ''.join(replacedString) elif command[0] == 'replace': string = list(string) replace = list(command[3]) for i in range(start, end + 1): string[i] = replace[i - start] string = ''.join(string)
def Reverse(str, A, B): a = int(A) b = int(B) if a == 0: str = str[0:a] + str[b::-1] + str[b + 1:] else: str = str[0:a] + str[b:a - 1:-1] + str[b + 1:] return str def Replace(str, a, b, c): str2 = '' Str = list(str) for i in range(int(b) - int(a) + 1): Str[i + int(a)] = c[i] for i in range(len(Str)): str2 += Str[i] return str2 str = input() n = int(input()) for i in range(n): a = input() A = a.split() if A[0] == 'print': print(str[int(A[1]):int(A[2]) + 1]) elif A[0] == 'reverse': str = Reverse(str, A[1], A[2]) elif A[0] == 'replace': str = Replace(str, A[1], A[2], A[3])
1
2,113,085,983,260
null
68
68
# -*- coding:utf8 -*- from collections import deque n = int(input()) c = [input() for _ in range(n)] d = deque() for com in c: if com[0] == 'i': d.appendleft(com[7:]) else: s = com[6] if s == 'F': d.popleft() elif s == 'L': d.pop() else: try: d.remove(com[7:]) except ValueError: pass print(' '.join(d))
#! python3 # doubly_linked_list.py from collections import deque keys = deque([]) n = int(input()) for i in range(n): command = input() if command == 'deleteFirst': keys.popleft() elif command == 'deleteLast': keys.pop() else: command, x = command.split(' ') if command == 'insert': keys.appendleft(int(x)) elif command == 'delete': if int(x) in keys: keys.remove(int(x)) print(' '.join([str(k) for k in keys]))
1
50,951,044,652
null
20
20
import math x = int(input()) def is_prime(n): for i in range(2,int(math.sqrt(n)) + 1): if n % i == 0: return False return True while True: if is_prime(x): print(x) exit() x += 1
t_HP, t_A, a_HP, a_A = map(int,input().split()) ans = False while True: a_HP -= t_A if a_HP <= 0: ans = True break t_HP -= a_A if t_HP <= 0: break if ans == True: print("Yes") else: print("No")
0
null
67,837,775,562,398
250
164
n = int(input()) digit = 1 while n > 26 ** digit: n -= 26 ** digit digit += 1 ans = [] n -= 1 char = 'abcdefghijklmnopqrstuvwxyz' for i in list(range(digit)): ans.append(char[n % 26]) n -= n%26 n = int(n/26) print(''.join(reversed(ans)))
hs=[int(input()) for i in range(10)] h=sorted(hs,reverse=True) for i in range(3): print(h[i])
0
null
5,926,802,277,980
121
2
#!/usr/bin/env python3 import sys input = lambda: sys.stdin.readline().strip() h, w = [int(x) for x in input().split()] g = [input() for _ in range(h)] ans = 0 for si in range(h): for sj in range(w): if g[si][sj] != '#': d = [[-1 for j in range(w)] for i in range(h)] d[si][sj] = 0 q = [(si, sj)] for i, j in q: ans = max(ans, d[i][j]) for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni, nj = i + di, j + dj if 0 <= ni < h and 0 <= nj < w and g[ni][nj] != '#' and d[ni][nj] == -1: d[ni][nj] = d[i][j] + 1 q.append((ni, nj)) print(ans)
# D - Maze Master # https://atcoder.jp/contests/abc151/tasks/abc151_d from collections import deque def main(): height, width = [int(num) for num in input().split()] maze = [input() for _ in range(height)] ans = 0 next_to = ((0, 1), (1, 0), (0, -1), (-1, 0)) for start_x in range(height): for start_y in range(width): if maze[start_x][start_y] == '#': continue queue = deque() queue.append((start_x, start_y)) reached = [[-1] * width for _ in range(height)] reached[start_x][start_y] = 0 while queue: now_x, now_y = queue.popleft() for move_x, move_y in next_to: adj_x, adj_y = now_x + move_x, now_y + move_y # Python は index = -1 が通ってしまうことに注意。 # except IndexError では回避できない。 if (not 0 <= adj_x < height or not 0 <= adj_y < width or maze[adj_x][adj_y] == '#' or reached[adj_x][adj_y] != -1): continue queue.append((adj_x, adj_y)) reached[adj_x][adj_y] = reached[now_x][now_y] + 1 most_distant = max(max(row) for row in reached) ans = max(most_distant, ans) print(ans) if __name__ == '__main__': main()
1
94,514,963,974,240
null
241
241
import sys N = int(input()) A = list(map(int, input().split())) LA = len(A) ans = A[0] for j in range(LA): if A[j] == 0: print('0') sys.exit() for i in range(LA-1): ans = ans*A[i+1] if ans > 10**18: print('-1') sys.exit() print(ans)
d,t,s= map(int,input().split(" ")) print("Yes" if t>=d*1.0/s else "No")
0
null
9,783,364,320,158
134
81
while 1: h, w = map(int, raw_input().split()) if h == 0 and w == 0: break else: print '#'*w for i in range(h-2): print '#' + '.'*(w-2) + '#' print '#'*w print ''
while True: l = input().split() h = int(l[0]) w = int(l[1]) if h == 0 and w == 0: break element = h*(w+1) for i in range(element): if (i+1)%(w+1) == 0: print("") if i == element-1: print("") elif i+1 < w or i+1 > element-w-1: print("#", end="") else: if (i+1)%(w+1) == 1 or (i+1)%(w+1) == w: print("#", end="") else: print(".", end="")
1
816,218,376,960
null
50
50
# python3.4.2用 import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9+7 INF = float('inf') #無限大 def gcd(a,b):return fractions.gcd(a,b) #最大公約数 def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数 def iin(): return int(sys.stdin.readline()) #整数読み込み def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み def isn(): return sys.stdin.readline().split() #文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) #整数map取得 def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=''): return s.join(l) #リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数 def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離 def m_add(a,b): return (a+b) % MOD def lprint(l): print(*l, sep='\n') def sieves_of_e(n): is_prime = [True] * (n+1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5)+1): if not is_prime[i]: continue for j in range(i * 2, n+1, i): is_prime[j] = False return is_prime H,W = imn() s = [input() for _ in range(H)] dp = [[INF for _ in range(W)] for _ in range(H)] dp[0][0] = 0 if s[0][0] == '#': dp[0][0] = 1 for i in range(H): for j in range(W): if i+1 < H: cnt = dp[i][j] if s[i][j] == "." and s[i+1][j] == "#": cnt += 1 dp[i+1][j] = min(dp[i+1][j], cnt) if j+1 < W: cnt = dp[i][j] if s[i][j] == "." and s[i][j+1] == "#": cnt += 1 dp[i][j+1] = min(dp[i][j+1], cnt) print(dp[-1][-1])
h, w = map(int,input().split()) maze = [] for i in range(h): t = list(input()) maze.append(t) dx = [1, 0] dy = [0, 1] dp = [[10000]*w for i in range(h)] if maze[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 for x in range(w): for y in range(h): for dxi, dyi in zip(dx, dy): if not (0<=x+dxi<w and 0<=y+dyi<h): continue dp[y+dyi][x+dxi] = min(dp[y+dyi][x+dxi], dp[y][x]+(maze[y][x]=="." and maze[y+dyi][x+dxi]=="#")) #print(*dp) print(dp[h-1][w-1])
1
49,152,743,039,392
null
194
194
n,m = map(int, input().split()) print("Yes") if n-m==0 else print("No")
y=x=int(input()) while y%360:y+=x print(y//x)
0
null
48,006,896,326,970
231
125
a,b,c,d = map(int, input().split()) if a >=0: if c > 0: print(b * d) elif d < 0: print(a * d) else: print(b*d) elif a < 0 and b >= 0: if c >= 0: print(b * d) elif d <= 0: print(a * c) else: ac = a * c bd = b * d if ac >= bd: print(ac) else: print(bd) else: if c >= 0: print(b * c) elif d <= 0: print(a * c) else: print(a * c)
a,b,c,d=map(int,input().split()) m=max(a*c,a*d,b*c,b*d) print(m)
1
3,070,804,812,882
null
77
77
k = int(input()) def call(m: int) -> str: result = "" for i in range(1, m + 1): if i % 3 == 0 or '3' in str(i): result += " " + str(i) return result print(call(k))
n = int(input()) for i in range(1, n + 1): if i % 3 == 0 or str(i).find("3") != -1: print(" {}".format(i), end = '') print()
1
923,821,591,460
null
52
52
from collections import deque DLL = deque() n = int(input()) for i in range(n): Line = input().split() if Line[0] == "insert": DLL.appendleft(Line[1]) elif Line[0] == "delete": try: DLL.remove(Line[1]) except ValueError: None elif Line[0] == "deleteFirst": DLL.popleft() elif Line[0] == "deleteLast": DLL.pop() print(" ".join(DLL))
l=[] for i in range(3): l.append(list(map(int,input().split()))) d=list(zip(*l)) s=[] f=0 n=int(input()) for i in range(n): s.append(int(input())) for i in range(3): c=0 for j in range(3): if(l[i][j] in s): c+=1 if(c==3): f=1 break if(l[1][1] in s and l[0][0] in s and l[2][2] in s): f=1 if(l[0][2] in s and l[1][1] in s and l[2][0] in s): f=1 for i in range(3): c=0 for j in range(3): if(d[i][j] in s): c+=1 if(c==3): f=1 break if(f==1): print("Yes") else: print("No")
0
null
29,863,775,607,354
20
207
s = input() print("ABC" if s[1]=="R" else "ARC")
s=input() if s=="ABC": print("ARC") else : print("ABC")
1
24,043,412,661,792
null
153
153
# -*-coding:utf-8 def main(): while True: n, x = map(int, input().split()) if ((n == 0) and (x == 0)): break count = 0 for i in range(1, n+1): for j in range(1, n+1): for k in range(1, n+1): if((i<j) and (j<k) and i+j+k == x): count += 1 print(count) if __name__ == '__main__': main()
import itertools while True: n, x = map(int, input().split()) if n == x == 0: break result = 0 for i in itertools.combinations(range(1, n + 1), 3): if sum(i) == x: result += 1 print(result)
1
1,291,248,752,980
null
58
58
def BubbleSort(C,N): for i in range(N): j = N-1 while True: if j == 0: break a,b = list(C[j]),list(C[j-1]) if a[1] < b[1]: tmp = C[j-1] C[j-1] = C[j] C[j] = tmp j -= 1 return C def SelectionSort(D,N): for i in range(N): minj = i for j in range(i,N): a,b = list(D[j]),list(D[minj]) if a[1] < b[1]: minj = j tmp = D[i] D[i] = D[minj] D[minj] = tmp return D n = int(input()) d = input().split() d2 = list(d) d = BubbleSort(d,n) for i in range(len(d)-1): print(d[i],end = ' ') print(d[-1]) print('Stable') d2 = SelectionSort(d2,n) for i in range(len(d2)-1): print(d2[i],end = ' ') print(d2[-1]) if d2 == d: print('Stable') else: print('Not stable')
import math a, b, c = map(float, input().split()) s = a*b*math.sin(math.radians(c))/2 h = 2*s/a l = a + b + (a**2+b**2 - 2*a*b*math.cos(math.radians(c)))**0.5 print("{0:.5f} {1:.5f} {2:.5f}".format(s,l,h))
0
null
95,307,080,868
16
30
import random d=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split())) for _ in range(d)] #print(d,c,s) t=[int(input()) for _ in range(d)] cnt=0 last=[0]*27 for i in range(d): cnt+=s[i][t[i]-1] last[t[i]-1]=i+1 for j in range(26): cnt-=c[j]*(i+1-last[j]) print(cnt)
def down(d, last, c): result = 0 for i in range(26): result += c[i] * (d - last[i]) return result def main(): D = int(input()) C = [int(c) for c in input().split()] S = [0] * D for d in range(D): S[d] = [int(s) for s in input().split()] last = [0] * 26 score = 0 scores = [0] * D for d in range(D): t = int(input()) - 1 score += S[d][t] last[t] = d + 1 score -= down(d + 1, last, C) scores[d] = score for score in scores: print(score) if __name__ == "__main__": main()
1
9,977,646,152,348
null
114
114
def call(n): s = "" for i in range(1,n+1): if i%3 == 0: s += " {0}".format(i) else: x = i while x > 0: if x%10 == 3: s += " {0}".format(i) break x = x // 10 print(s) m = int(input()) call(m)
input_line1 = raw_input() work = input_line1.split(' ') ret = 'a == b' if int(work[0]) < int(work[1]): ret = 'a < b' if int(work[0]) > int(work[1]): ret = 'a > b' print(ret)
0
null
655,557,693,532
52
38
while True: m,f,r=map(int,input().split()) if (m,f,r)==(-1,-1,-1): break h=m+f if m == -1 or f == -1: print('F') elif h >= 80: print('A') elif h>=65 and h<80: print('B') elif h>=50 and h<65: print('C') elif h>=30 and h<50 and r>=50: print('C') elif h>=30 and h<50 and r<50: print('D') else: print('F')
while True: m, f, r = map(int, input().split()) if m == f == r == -1: break s = m + f if m == -1 or f == -1: print("F") elif s >= 80: print("A") elif s >= 65: print("B") elif s >= 50 or r >= 50: print("C") elif s >= 30: print("D") else: print("F")
1
1,216,496,936,060
null
57
57
A=int(input()) B=int(input()) print(6-(A+B))
a = int(input()) b = int(input()) s = a + b print(6-s)
1
110,609,006,293,588
null
254
254
S=input() if "RRR" in S: print(3) elif "RR" in S: print(2) elif "R" in S: print(1) else: print(0)
from sys import stdin import sys, math n = int(stdin.readline().rstrip()) a = [0 for i in range(n)] d = [int(x) for x in stdin.readline().rstrip().split()] for i in range(n-1): k = d[i] a[k-1] = a[k-1] + 1 for i in range(n): print(a[i])
0
null
18,616,819,416,250
90
169
al = "abcdefghijklmnopqrstuvwxyz" C = input() print(al[al.index(C)+1])
def main(): from string import ascii_lowercase c = input() ind = ascii_lowercase.index(c) ind += 1 print(ascii_lowercase[ind]) if __name__ == '__main__': main()
1
92,521,313,770,692
null
239
239
import sys try: #d = int(input('D: ')) #t = int(input('T: ')) #s = int(input('S: ')) nums = [int(e) for e in input().split()] except ValueError: print('エラー:整数以外を入力しないでください') sys.exit(1) if 1 <= nums[0] <= 10000 and 1 <= nums[1] <= 10000 and 1 <= nums[2] <= 10000: take_time = nums[0] / nums[2] if take_time <= nums[1]: print("Yes") else: print("No") else: print('エラー:各入力は1~10000までの整数です')
"""A.""" import sys input = sys.stdin.readline # noqa: A001 D, T, S = map(int, input()[:-1].split(' ')) print('Yes' if T * S >= D else 'No')
1
3,560,924,550,720
null
81
81
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): LI = lambda : [int(x) for x in sys.stdin.readline().split()] N,K = LI() A = LI() c = 0 d = collections.Counter() d[0] = 1 ans = 0 r = [0] * (N+1) for i,x in enumerate(A): if i >= K-1: d[r[i-(K-1)]] -= 1 c = (c + x - 1) % K ans += d[c] d[c] += 1 r[i+1] = c print(ans) if __name__ == '__main__': main()
s=input() r=input() n=len(s) c=0 for i in range(n): if(s[i]!=r[i]): c=c+1 print(c)
0
null
73,738,638,270,398
273
116
x = int(input()) xSum = 0 cnt = 1 while True: xSum += x if xSum%360 == 0: break cnt += 1 print(cnt)
x = int(input()) idx = 0 tmp = 0 while 1: tmp += x idx += 1 if tmp % 360 == 0: break print(idx)
1
13,129,877,872,998
null
125
125
S = input() N = len(S) flag = [0,0,0] if S=="".join(reversed(list(S))): flag[0]=1 if S[:int((N-1)/2)]=="".join(reversed(list(S[:int((N-1)/2)]))): flag[1]=1 if S[int((N+3)/2)-1:]=="".join(reversed(list(S[int((N+3)/2)-1:]))): flag[2]=1 print("Yes" if flag==[1,1,1] else "No")
def resolve(): n = int(input()) p = tuple(map(int,input().split())) min_p = p[0] cnt = 1 for i in range(1,n): if min_p > p[i]: min_p = p[i] cnt += 1 print(cnt) resolve()
0
null
66,186,803,384,068
190
233
text = input() result = '' for i in range(len(text)): code = ord(text[i]) if ord('A') <= code <= ord('Z'): result += chr(code + 32) elif ord('a') <= code <= ord('z'): result += chr(code - 32) else: result += chr(code) print(result)
s=input() res='' for i in s: if i.islower(): i=i.upper() elif i.isupper(): i=i.lower() res+=i print(res)
1
1,474,590,911,200
null
61
61
import sys input = sys.stdin.readline N,u,v=map(int,input().split()) E=[tuple(map(int,input().split())) for i in range(N-1)] EDGE=[[] for i in range(N+1)] for x,y in E: EDGE[x].append(y) EDGE[y].append(x) from collections import deque T=[-1]*(N+1) Q=deque() Q.append(u) T[u]=0 while Q: x=Q.pop() for to in EDGE[x]: if T[to]==-1: T[to]=T[x]+1 Q.append(to) A=[-1]*(N+1) Q=deque() Q.append(v) A[v]=0 while Q: x=Q.pop() for to in EDGE[x]: if A[to]==-1: A[to]=A[x]+1 Q.append(to) OK=[0]*(N+1) for i in range(N+1): if T[i]<A[i]: OK[i]=1 ANS=0 for i in range(N+1): if OK[i]==1: ANS=max(ANS,A[i]) print(max(0,ANS-1))
n = int(input()) d = dict(zip([i for i in range(1, n + 1)], [0] * n)) l = map(int, input().split()) for i in l: d[i] += 1 for i in d.values(): print(i)
0
null
75,047,328,507,982
259
169
import bisect,collections,copy,heapq,itertools,math,string import sys def S(): return sys.stdin.readline().rstrip() def M(): return map(int,sys.stdin.readline().rstrip().split()) def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) a, b, c, d = M() li = list() li.append(a*c) li.append(a*d) li.append(b*c) li.append(b*d) li.sort() print(li[-1])
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ?????????????????????Merge Sort??????????????±??????????????\??????????????¢?????´???????????§??? ?¬?????????????????£????????????¨?????§???????????? merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; L[0...n1], R[0...n2] ????????? for i = 0 to n1-1 L[i] = A[left + i] for i = 0 to n2-1 R[i] = A[mid + i] L[n1] = INFTY R[n2] = INFTY i = 0 j = 0 for k = left to right-1 if L[i] <= R[j] A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 mergeSort(A, left, right) if left+1 < right mid = (left + right)/2; mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) n ????????´??°???????????°??? S ????????????????????????????????£???????????????????????§ ???????????´?????????????????°???????????????????????????????????? ?????????merge???????????????????????°????????°?????±???????????????????????? """ MAX = 1000000001 def merge(A, left, mid, right, cnt): n1 = mid - left n2 = right - mid # L = [] # R = [] # for i in range(n1): # L.append(A[left + i]) # # for i in range(n2): # R.append(A[mid + i]) L = A[left:mid] R = A[mid:right] L.append(MAX) R.append(MAX) # print("l:{} m:{} r:{} cnt:{} n1:{} n2:{}".format(left,mid,right,cnt,n1,n2)) # print("left:{} right:{}".format(L,R)) i = 0 j = 0 for k in range(left, right): # print("k:{} i:{} j:{}".format(k,i,j)) if L[i] <= R[j]: A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 cnt += 1 return cnt def mergeSort(A, left, right, cnt): if left + 1 < right: mid = int((left + right) / 2) cnt = mergeSort(A, left, mid, cnt) cnt = mergeSort(A, mid, right, cnt) cnt = merge(A, left, mid, right, cnt) return cnt def main(): """ ????????? """ n = int(input()) S = list(map(int,input().split())) cnt = mergeSort(S, 0, n, 0) print(" ".join(map(str,S))) print(cnt) if __name__ == '__main__': main()
0
null
1,595,479,331,098
77
26
N, A, B = map(int, input().split()) distance =(B - A - 1 )//2 if( (A % 2 == 0 and B % 2 ==0) or (A%2==1 and B%2==1)): ans=(B - A)//2 else: ans = min(A-1,N - B) + 1 + distance print(ans)
n=int(input()) nyukyo=[list(map(int, input().split())) for i in range(n)] bld=[[[0 for i in range(10)] for j in range(3)] for k in range(4)] for ny in nyukyo: bld[ny[0]-1][ny[1]-1][ny[2]-1]+=ny[3] for i,b in enumerate(bld): for f in b: print("",*f) if i != 3: print("####################")
0
null
55,430,274,808,008
253
55
while True: h, w = map(int, input().split(" ")) if h == 0 and w == 0: break print("#"*w) print(("#"+ "."*(w-2) +"#" + "\n")*(h-2) + "#" * w) if h >2 and w>=2 else 0 print("#"*w) if h == 2 else 0 print("")
while 1: H, W = map(int, input().split()) if H == 0 and W == 0: break print("#"*W) line = '#' + ('.' * (W - 2)) + '#' for i in range(0, H - 2): print(line) print("#"*W) print()
1
833,748,333,120
null
50
50
from sys import stdin input = stdin.readline def solve(): n,m = map(int,input().split()) p = [tuple(map(int,inp.split())) for inp in stdin.read().splitlines()] father = [-1] * n count = n def getfather(x): if father[x] < 0: return x father[x] = getfather(father[x]) return father[x] def union(x, y): x = getfather(x) y = getfather(y) nonlocal count if x != y: count -= 1 if father[x] > father[y]: x,y = y,x father[x] += father[y] father[y] = x for a,b in p: union(a-1,b-1) print(count - 1) if __name__ == '__main__': solve()
import sys sys.setrecursionlimit(10**5) n,m=map(int,input().split()) g=[[] for i in range(10**5+10)] for i in range(m): a,b=map(lambda x:int(x)-1, input().split()) g[a].append(b) g[b].append(a) chk=[-1]*n def dfs(s,cnt): for u in g[s]: if chk[u]>-1: continue; chk[u]=cnt dfs(u,cnt) cnt=0 for i in range(n): if chk[i]==-1: chk[i]=cnt dfs(i,cnt) cnt+=1 print(max(chk))
1
2,291,553,739,200
null
70
70
import math E=0 A,B,C=map(int,input().split()) print((1/2)*A*B*(math.sin(math.radians(C)))) print(((A**2)+(B**2)-2*A*B*(math.cos(math.radians(C))))**(1/2)+A+B) print(((1/2)*A*B*(math.sin(math.radians(C))))*2/A)
import math data = list(map(float, input().split())) a, b, theta = data[0], data[1], data[2]/180*math.pi data[1] = (a**2+b**2-2*a*b*math.cos(theta)) ** 0.5 + a + b data[2] = b * math.sin(theta) data[0] = a * data[2] / 2 for i in range(3): print(data[i])
1
175,918,739,590
null
30
30
#!/usr/bin/env python # coding: utf-8 def ri(): return int(input()) def rl(): return list(input().split()) def rli(): return list(map(int, input().split())) def main(): t = input() bef = '!' s = "" for c in t: nc = c if c == '?': nc = "D" bef = nc s += nc print(s) if __name__ == '__main__': main()
inf = float("inf") S = input() N = len(S) bestP = [None for i in range(N)] bestD = [None for i in range(N)] if S[0] in ["?", "D"]: bestP[0] = 0 bestD[0] = 1 else: bestP[0] = 0 bestD[0] = 0 for i in range(1, N): bestP[i] = max(bestD[i - 1], bestP[i - 1]) bestD[i] = max(bestD[i - 1] + 1, bestP[i - 1] + 2) if S[i] != "?": if S[i] == "P": bestD[i] = -inf else: assert S[i] == "D" bestP[i] = -inf ans = [None for i in range(N)] if bestP[-1] > bestD[-1]: ans[-1] = 'P' else: ans[-1] = 'D' for i in range(N - 2, -1, -1): if S[i] != '?': ans[i] = S[i] else: prev = ans[i + 1] if prev == 'D': if bestP[i] + 2 > bestD[i] + 1: ans[i] = 'P' else: ans[i] = 'D' else: if bestP[i] > bestD[i]: ans[i] = 'P' else: ans[i] = 'D' print(''.join(ans))
1
18,374,430,067,840
null
140
140
N = int(input()) A = list(int(x) for x in input().split()) ans = 0 for i in range(N): if i == N - 1: break if A[i] > A[i+1]: sa = A[i] - A[i+1] A[i+1] += sa ans = ans + sa print(ans)
S = int(input()) dp = [0] * (S + 1) dp[0] = 1 M = 10 ** 9 + 7 for i in range(1, S + 1): num = 0 for j in range(i - 2): num += dp[j] dp[i] = num % M print(dp[S])
0
null
3,879,707,211,776
88
79
n = int(input()) mydict = {} answer_list = [] for i in range(n) : query, wd = input().split() if query == "insert" : mydict[wd] = 1 else : if wd in mydict.keys() : answer_list.append("yes") else : answer_list.append("no") for i in answer_list : print(i)
import sys n = int(input()) command = sys.stdin.readlines() Q = {} for i in range(n): a,b = command[i].split() if a == "insert": Q[b] = 0 else: if b in Q.keys(): print("yes") else: print("no")
1
80,216,587,878
null
23
23
import sys input = sys.stdin.readline def main(): N = int(input()) c = input() cnt_r = 0 cnt_w = 0 for i in c: if i == 'R': cnt_r += 1 else: cnt_w += 1 w_left = 0 r_right = cnt_r ans = N for i in range(N): ans = min(ans, max(w_left, r_right)) if c[i] == 'W': w_left += 1 else: r_right -= 1 print(min(ans, max(w_left, r_right))) main()
from fractions import gcd def lcm(a, b): return a * b // gcd(a, b) n = int(input()) a = list(map(int,input().split())) mod = 10 ** 9 + 7 LCM = 1 a_mod = 0 for i in range(n): LCM = lcm(LCM, a[i]) a_mod = (a_mod + pow(a[i], mod - 2, mod)) % mod LCM = LCM % mod ans = LCM * a_mod print(ans % mod)
0
null
46,954,983,236,396
98
235
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if a <= b: print('YNEOS'[a+v*t < b+w*t::2]) else: print('YNEOS'[a-v*t > b-w*t::2])
import sys input = sys.stdin.readline def main(): a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) d = v - w if abs(a-b) <= t * d: print("YES") else: print("NO") if __name__ == "__main__": main()
1
15,077,566,305,840
null
131
131
from itertools import groupby s = input() k = int(input()) r = len(s) * k // 2 a = [len(tuple(g)) & 1 for _, g in groupby(s)] if len(a) > 1: r -= sum(a) * k // 2 if s[0] == s[-1] and a[0] & a[-1]: r += k - 1 print(r)
S = list(input()) K = int(input()) S1 = list(S) cnt1 = 0 for i in range(1, len(S1)): if S1[i] == S1[i - 1]: S1[i] = '*' cnt1 += 1 S2 = list(S) * 2 cnt2 = 0 for i in range(1, len(S2)): if S2[i] == S2[i - 1]: S2[i] = '*' cnt2 += 1 S3 = list(S) * 3 cnt3 = 0 for i in range(1, len(S3)): if S3[i] == S3[i - 1]: S3[i] = '*' cnt3 += 1 # print("#", S1, S2, S3) # print("#", cnt1, cnt2, cnt3) ans = cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2) print(ans)
1
175,963,182,330,462
null
296
296
A,B = input().split() A = int(A) x = "" for i in range(len(B)): if B[i]!=".": x += B[i] B = int(x) C = A*B C = C//100 print(C)
def main(): A, B = input().split() A = int(A) B100 = int(B[0] + B[2:]) print(A*B100//100) if __name__ == "__main__": main()
1
16,643,385,509,518
null
135
135
def segfunc(x,y): return set(x)|set(y) ide_ele=set() class SegTree(): def __init__(self,init_val,segfunc,ide_ele): n=len(init_val) self.segfunc=segfunc self.ide_ele=ide_ele self.num=1<<(n-1).bit_length() self.tree=[ide_ele]*2*self.num for i in range(n): self.tree[self.num+i]=init_val[i] for i in range(self.num-1,0,-1): self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1]) def update(self,k,x): k+=self.num self.tree[k]=x while k>1: self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1]) k>>=1 def query(self,l,r): res=self.ide_ele l+=self.num r+=self.num while l<r: if l&1: res=self.segfunc(res,self.tree[l]) l+=1 if r&1: res=self.segfunc(res,self.tree[r-1]) l>>=1 r>>=1 return res n=int(input()) s=input() q=int(input()) st=SegTree(s,segfunc,ide_ele) for _ in range(q): q,c,r=input().split() if q=='1':st.update(int(c)-1,r) else:print(len(st.query(int(c)-1,int(r))))
class SegmentTree: def __init__(self, lst, op, e): self.n = len(lst) self.N = 1 << ((self.n - 1).bit_length()) self.op = op # operation self.e = e # identity element self.v = self._build(lst) # self.v is set to be 1-indexed for simplicity def _build(self, lst): # construction of a tree # total 2 * self.N elements (tree[0] is not used) tree = [self.e] * (self.N) + lst + [self.e] * (self.N - self.n) for i in range(self.N - 1, 0, -1): tree[i] = self.op(tree[i << 1], tree[(i << 1)|1]) return tree def __getitem__(self, i): return self.v[i + self.N] # update a_i to be x def update(self, i, x): v, op = self.v, self.op i += self.N v[i] = x while i > 0: i >>= 1 # move to parent v[i] = op(v[i << 1], v[(i << 1)|1]) # returns answer for the query interval [l, r) def fold(self, l, r): N, e, v, op = self.N, self.e, self.v, self.op left = l + N; right = r + N L = R = e while left < right: if left & 1: # self.v[left] is the right child L = op(L, v[left]) left += 1 if right & 1: # self.v[right-1] is the left child right -= 1 R = op(v[right], R) left >>= 1; right >>= 1 return op(L, R) def wa(set1, set2): return set1 | set2 n = int(input()) s = input() lst = [] for i in range(n): lst.append(set([s[i]])) st = SegmentTree(lst, wa, set([])) ans = [] q = int(input()) for i in range(q): que = input() if que[0] == '1': kind, i, c = que.split() i = int(i) - 1 st.update(i, set([c])) else: kind, l, r = map(int, que.split()) l -= 1 ans.append(len(st.fold(l, r))) for i in ans: print(i)
1
62,458,886,938,590
null
210
210
K, N = map(int, input().split()) A = list(map(int, input().split())) ans = K for i in range(N): start = A[i] end = K+A[i-1] if A[i-1] < A[i] else A[i-1] path = end-start ans = min(path, ans) print(ans)
H, N = map(int, input().split()) dp = [10 ** 9] * (H + 1) dp[0] = 0 for _ in range(N): a, b = map(int, input().split()) for i in range(H): idx = min(H, i + a) dp[idx] = min(dp[idx], dp[i] + b) print(dp[H])
0
null
62,356,598,047,982
186
229
def robin(process, q): if int(process[0][1]) - q > 0: process[0][1] = int(process[0][1]) - q process.append([process[0][0],process[0][1]]) process.pop(0) return process, q else: q = int(process[0][1]) process.pop(0) return process, q n, q = input().split() n, q = int(n), int(q) process = [] for i in range(n): process.append([i for i in input().split()]) time = 0 while len(process) != 0: length = len(process) name = process[0][0] process, process_time = robin(process, q) time += process_time if length > len(process): print(name,time)
class Queue(): def __init__(self, size=10): self.queue = [None] * size self.head = self.tail = 0 self.MAX = size self.num_items = 0 def is_empty(self): return self.num_items == 0 def is_full(self): return self.num_items == self.MAX def enqueue(self, x): if self.is_full(): raise IndexError self.queue[self.tail] = x self.num_items += 1 if self.tail+1 == self.MAX: self.tail = 0 else: self.tail += 1 def dequeue(self): if self.is_empty(): raise IndexError x = self.queue[self.head] self.num_items -= 1 if self.head+1 == self.MAX: self.head = 0 else: self.head += 1 return x class Process: def __init__(self, name, time): self.name = name self.time = time def print_time(self): return self.time def print_name(self): return self.name def main(): n, q = map(int, input().split()) qq = Queue(n) t = 0 for i in range(n): name, time = input().split() p = Process(name, int(time)) qq.enqueue(p) while not qq.is_empty(): p = qq.dequeue() if p.time - q <= 0: t += p.time print("{} {}".format(p.name, t)) else: p.time -= q t += q qq.enqueue(p) if __name__ == '__main__': main()
1
42,123,423,930
null
19
19
N = int(input()) S,T = input().split() for i in range(N): print(S[i],end = "") print(T[i],end = "")
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) S,T = readline().decode().rstrip().split() ans = '' for i in range(N): ans += S[i] + T[i] print(ans)
1
111,560,415,658,340
null
255
255
N, A, B = map(int, input().split()) s = N // (A+B) t = N % (A+B) k = 0 if t <= A: k = t else: k = A print(s*A+k)
def resolve(): n = int(input()) 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 divisors = make_divisors(n) min_pair = 10**19 for i in divisors: pair_i = n//i min_pair = min(min_pair, ((i-1)+(pair_i-1))) print(min_pair) resolve()
0
null
108,749,057,669,380
202
288
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math from copy import copy, deepcopy from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意 from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする def input(): return sys.stdin.readline()[:-1] def printl(li): print(*li, sep="\n") def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def dfs(H,W,L): d=0 c=True if L[0][0]==False: d=1 c=False q=deque([(d*10000,c)]) dxs=((0,1),(1,0)) visited=[False]*10000 while len(q): #print(q) dxy,c=q.popleft()#ここをpopleftにすると幅優先探索BFSになる d,xy=divmod(dxy,10000) x,y=divmod(xy,100) if visited[xy]: continue visited[xy]=True if x==H-1 and y==W-1: return d for dx in dxs: nx=x+dx[0] ny=y+dx[1] if nx>=H or ny>=W: continue if visited[nx*100+ny]:continue if L[nx][ny] or c==False: q.appendleft((d*10000+nx*100+ny,L[nx][ny])) else: q.append(((d+1)*10000+nx*100+ny,False)) def main(): mod = 10**9+7 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え #N = int(input()) H,W = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル L = list(list(input()) for i in range(H)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 #Lt=[[True]*H for _ in range(W)] for i in range (H): for j in range(W): if L[i][j]=='#': L[i][j]=False else: L[i][j]=True ans=dfs(H,W,L) print(ans) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- while True: n, x = map(int, raw_input().split()) if n == x == 0: break count = 0 for a in range(1, n+1): for b in range(a+1, n+1): for c in range(b+1, n+1): if a+b+c == x: count += 1 break print count
0
null
25,460,898,317,468
194
58
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) sum_A = [0] * (N + 1) sum_B = [0] * (M + 1) for a in range(1, N + 1): sum_A[a] = sum_A[a - 1] + A[a - 1] for b in range(1, M + 1): sum_B[b] = sum_B[b - 1] + B[b - 1] count = 0 # print(sum_A) # print(sum_B) last_index = M for a in range(len(sum_A)): # print("----------------------") # print("a", a) if sum_A[a] > K: count = max(count, a - 1) break elif sum_A[a] == K: count = max(count, a) now = sum_A[a] rest = K - now # print("last_index", last_index) #able = len([i for i in sum_B[:last_index + 1] if i <= rest]) - 1 while True: if last_index < 0: able = 0 break if sum_B[last_index] > rest: last_index -= 1 else: able = last_index break # print("now", now, "rest", rest, "able", able) # print("今回の最大countは", "a + able = ", a + able) count = max(count, a + able) # print("これまでの最大count", count) print(count)
def move(up,bottom,right,left,front,back,direction): if direction == "N": return (front,back,right,left,bottom,up) elif direction == "S": return (back,front,right,left,up,bottom) elif direction == "E": return (left,right,up,bottom,front,back) elif direction == "W": return (right,left,bottom,up,front,back) up,front,right,left,back,bottom = input().split() direction = list(input()) for i in range(len(direction)): up,bottom,right,left,front,back = move(up,bottom,right,left,front,back,direction[i]) print(up)
0
null
5,445,825,652,540
117
33
# -*- coding: utf-8 -*- n = input() x = y = 0 for _ in xrange(n): a, b = raw_input().split() if a==b: x += 1 y += 1 elif a>b: x += 3 else: y += 3 print x, y
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,013,290,656,508
null
67
67
H = [[0] * 3 for i in range(3)] A = [[0] * 3 for i in range(3)] A[0][0],A[0][1],A[0][2] = map(int,input().split()) A[1][0],A[1][1],A[1][2] = map(int,input().split()) A[2][0],A[2][1],A[2][2] = map(int,input().split()) N = int(input()) for i in range(N): ball = int(input()) for l in range(3): for c in range(3): if A[l][c] == ball: H[l][c] = 1 #print(H) flag = 0 for l in range(3): if H[l][0] ==1 and H[l][1] ==1 and H[l][2] ==1: flag =1 for c in range(3): if H[0][c] ==1 and H[1][c] ==1 and H[2][c] ==1: flag =1 if H[0][0]==1 and H[1][1]==1 and H[2][2]== 1: flag = 1 if H[2][0]==1 and H[1][1]==1 and H[0][2]== 1: flag = 1 if flag == 1: print("Yes") else: print("No") #A[2][1] = 10 #print(A) #print(flag)
N,K=map(int,input().split()) ans=0 mod=10**9+7 A=[0 for i in range(K)] for i in range(K,0,-1): l=pow(K//i,N,mod) a=2 while a*i<=K: l-=A[a*i-1] a+=1 ans+=l*i%mod ans%=mod A[i-1]=l print(ans)
0
null
48,405,257,797,760
207
176
pen = int(input()[-1]) if pen in [2, 4, 5, 7, 9]: print('hon') elif pen in [0, 1, 6, 8]: print('pon') elif pen in [3]: print('bon')
N=int(input())%10 if N==3 :print('bon') elif N==0 or N==1 or N==6 or N==8:print('pon') else:print('hon')
1
19,210,390,919,900
null
142
142
N = int(input()) S = input() if S == S[:N//2]*2: print("Yes") else: print("No")
n=int(input()) s=input() ans="No" if n%2==0: p=n//2 if s[:p]==s[p:]: ans="Yes" print(ans)
1
146,730,817,200,220
null
279
279
# B - An Odd Problem def main(): _, *A = map(int, open(0).read().split()) print(sum(i % 2 for i in A[::2])) if __name__ == "__main__": main()
N=int(input()) count=0 for A in range(1,N): count+=(N-1)//A print(count)
0
null
5,138,129,645,040
105
73
x=int(input()) k=100 a=1 for i in range(1,4000): k=(101*k)//100 if k<x: a=a+1 print(a)
N = int(input()) S = [] for x in range(N): S += [input()] S_set = set(S) print(len(S_set))
0
null
28,538,464,382,578
159
165
N,M=map(int,input().split()) A=[int(x) for x in input().split()] print(max(-1,(N-sum(A))))
import sys s = '' for line in sys.stdin: s += line s = s.lower() count = {letter: s.count(letter) for letter in set(s)} for c in range(97,97+26): if chr(c) in count: print("%c : %d" % (chr(c), count[chr(c)])) else: print("%c : 0" % chr(c))
0
null
16,680,226,567,370
168
63
# E - Colorful Blocks import sys sys.setrecursionlimit(10**8) MOD = 998244353 N,M,K = map(int,input().split()) inv_M = pow(M-1,-1,MOD) if M>1 else 0 ans = 0 tmp = pow(M-1,N-1,MOD) if M>1 else 0 comb = 1 for i in range(K+1): ans = (ans+M*comb*tmp)%MOD if i==K: break tmp = (tmp*inv_M)%MOD comb = (comb*(N-1-i)*pow(i+1,-1,MOD))%MOD if M==1 and K==N-1: ans += 1 print(ans)
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math from copy import copy, deepcopy from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意 from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする def input(): return sys.stdin.readline()[:-1] def printl(li): print(*li, sep="\n") def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def extgcd1(a0,b0): u=1 v=0 a=a0 b=b0 while b: t=a//b a-=t*b a,b=b,a u-=t*v u,v=v,u if a!=1: #print("not 素") return -1 return u%b0 #a0*u=1(mod b0) def main(): mod =998244353 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え #N = int(input()) N, M, K = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル #L = tuple(int(input()) for i in range(N)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 # dp=[0]*2 # ndp=copy(dp) # dp[0]=0 # dp[1]=M # for i in range(2,N+1): # if i<=K+1: # ndp[0]=((M-1)*(dp[0]+dp[1])+dp[0])%mod # ndp[1]=dp[1] # else: # ndp[0]=(M*dp[0]+(M-1)*dp[1])%mod # ndp[1]=0 # dp=copy(ndp) # ans=(dp[0]+dp[1])%mod # #print(ans) #n0=math.factorial(N-1) #ks=[1]*(N-1+1) #for k in range(2,N-1+1): # ks[k]=ks[k-1]*k ans=0 c0=1 c1=pow(M-1,N-1,mod) inv=[1,1]+[extgcd1(i,mod) for i in range(2,N)] #print("ok1") ifac=[1]*(N) nfac=1 for i in range(1,N): nfac=(i*nfac)%mod ifac[i]=(ifac[i-1]*inv[i])%mod #print("ok2") #print(ifac) mp=[1]*(N) for i in range(1,N): mp[i]=(mp[i-1]*(M-1))%mod #print("ok3") ans=0 #print(nfac) #print(mp) for k in range(0,K+1): #print((n0//ks[k]//ks[N-1-k])) ans=ans+(mp[N-1-k]*nfac*ifac[k]*ifac[N-1-k])%mod ans%=mod #print(ans) #print(ks) ans=(ans*M)%mod print(ans) if __name__ == "__main__": main()
1
23,178,778,088,380
null
151
151
a,b,c = list(map(int,input().split(" "))) div=0 for i in range(a,b+1): if c % i == 0: div += 1 print(div)
import math a, b, c = map(int, input().split()) l = []; d = int(math.sqrt(c)); e = 0 for i in range(1, d + 1): if i * i == c: l += [i] elif c % i == 0: l += [i, c // i] for x in l: if a <= x <= b: e += 1 print(e)
1
553,832,269,952
null
44
44
n=int(input()) a=list(map(int,input().split())) b=a+a b.sort(reverse=True) ans=0 for i in range(1,n): ans+=b[i] print(ans)
a, b, c, d = map(int,input().split()) while a > 0: c -= b a -= d if c <= 0: print('Yes') else: print('No')
0
null
19,473,011,298,322
111
164
""" 入力例 1 11 3 2 ooxxxoxxxoo ->6 入力例 2 5 2 3 ooxoo ->1 ->5 入力例 3 5 1 0 ooooo -> 入力例 4 16 4 3 ooxxoxoxxxoxoxxo ->11 ->16 """ n,k,c = map(int,input().split()) s = input() r=[0]*n l=[0]*n ki=0 ci=100000 for i in range(n): ci += 1 if s[i]=='x': continue if ci > c: ci = 0 ki+=1 l[i]=ki if ki == k: break ki=k ci=100000 for i in range(n): ci += 1 if s[n-1-i]=='x': continue if ci > c: ci = 0 r[n-1-i]=ki ki-=1 if ki == 0: break ret=[] for i in range(n): if r[i]==l[i] and r[i]!=0: ret.append(i+1) # print(l) # print(r) for i in range(len(ret)): print(ret[i])
import sys, bisect, math, itertools, heapq, collections from operator import itemgetter # a.sort(key=itemgetter(i)) # i番目要素でsort from functools import lru_cache # @lru_cache(maxsize=None) sys.setrecursionlimit(10**8) input = sys.stdin.readline INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): ''' 一つの整数 ''' return int(input()) def inpl(): ''' 一行に複数の整数 ''' return list(map(int, input().split())) n, k, c = inpl() s = list(input())[:-1] q = collections.deque() cool = 0 left = [0] * n right = [0] * n val=-1 for i in range(n): if cool<=0 and s[i]=="o" and val<k: val += 1 cool = c else: cool-=1 left[i] = val cool = 0 val+=1 for i in range(n-1,-1,-1): if cool<=0 and s[i]=="o" and val>0: val -= 1 cool = c else: cool-=1 right[i]=val # print(left) # print(right) for i in range(n): if left[i]==right[i] and (i == 0 or left[i] - left[i - 1] == 1) and (i == n - 1 or right[i + 1] - right[i] == 1): print(i + 1)
1
40,619,464,280,514
null
182
182
n,x,m = map(int,input().split()) mod = m ans = 0 bit = [-1 for i in range(m)] cycle = False for i in range(n): if i == 0 : a = x bit[a] = i ans += a else: a = (a**2)% mod if bit[a] != -1: cy_st = bit[a] cy_fi = i -1 cycle = True break else: bit[a] = i ans += a if cycle: ans2 = 0 b = -1 for j in range(cy_st): if j == 0 : b = x ans2 += b else: b = (b**2)% mod ans2 += b cy_num = ans - ans2 cy_repe = (n-cy_st) // (cy_fi - cy_st + 1) ans3 = cy_num * cy_repe cy_amari = (n-cy_st) % (cy_fi - cy_st + 1) if b == -1: for j in range(cy_amari): if j == 0 : b = x ans3 += b else: b = (b**2)% mod ans3 += b else: for i in range(cy_amari): b = (b**2)% mod ans3 += b print(ans2+ans3) else: print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N, X, mod = mapint() first = set() second = set() in_loop = [] ans = 0 for i in range(min(10**5*2, N)): if X in first: if X in second: break in_loop.append(X) second.add(X) first.add(X) ans += X X = pow(X, 2, mod) else: print(ans) exit() loop_len = len(in_loop) rest = N-len(first)-len(in_loop) ans += (rest//loop_len)*sum(in_loop) amari = rest%loop_len for i in range(amari): ans += in_loop[i] print(ans)
1
2,806,865,951,328
null
75
75
n,m=map(int,input().split()) a=list(map(int,input().split())) import math def lcm(x, y): return (x * y) // math.gcd(x, y) x=1 for i in range(n): x=lcm(x,a[i]//2) power=[0]*n for i in range(n): while a[i]%2==0: a[i]//=2 power[i]+=1 if power.count(power[0])==n: print((m+x)//(2*x)) else: print(0)
N, M = map(int, input().split(' ')) ac_set = set() wa_cnt_list = [0] * N ac_cnt, wa_cnt = 0, 0 for i in range(M): num, res = input().split(' ') num = int(num) - 1 if num not in ac_set: if res == 'AC': ac_cnt += 1 wa_cnt += wa_cnt_list[num] ac_set.add(num) else: wa_cnt_list[num] += 1 print(ac_cnt, wa_cnt)
0
null
97,592,177,987,648
247
240
N,M=input().split() N=int(N) M=int(M) if N==M: print("Yes") else: print("No")
# 二通りのやり方で解いてみよう。 # Aそれぞれに対してBを二分探索→M(累積和構成) + NlogM # Aを昇順、Bを降順に動かす→O(N+M) このコードはこっち★ n, m, k = list(map(int, input().split())) aa = list(map(int, input().split())) bb = list(map(int, input().split())) time_sum = sum(bb) a_idx = 0 b_idx = m-1 ans = 0 # 最初はA無し、B全部からスタート book_num = m while True: if time_sum > k: if b_idx < 0: break time_sum -= bb[b_idx] b_idx -= 1 book_num -= 1 else: # 実行可能な読み方 ans = max(ans, book_num) if a_idx > n-1: break time_sum += aa[a_idx] a_idx += 1 book_num += 1 print(ans)
0
null
46,856,677,584,900
231
117
n = int(input()) info = [] for _ in range(n): temp = [int(x) for x in input().split( )] info.append(temp) state = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] for a in info: state[a[0]-1][a[1]-1][a[2]-1] += a[3] for b in range(4): for f in range(3): string = '' for k in range(10): string += ' ' + str(state[b][f][k]) print(string) if b < 3: print('#'*20)
import re import sys try: a = int(input()) if not 1 <= a <= 10: sys.exit() print(a+(a**2)+(a**3)) except: sys.exit()
0
null
5,620,460,365,992
55
115
import sys from bisect import bisect_left, bisect_right, insort sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() S = list('-' + sr()) d = [[] for _ in range(26)] for i in range(1, N+1): s = S[i] o = ord(s) - ord('a') d[o].append(i) Q = ir() for _ in range(Q): q, a, b = sr().split() if q == '1': a = int(a) if S[a] == b: continue prev = ord(S[a]) - ord('a') d[prev].pop(bisect_left(d[prev], a)) next = ord(b) - ord('a') insort(d[next], a) S[a] = b else: a = int(a); b = int(b) ans = 0 for alpha in range(26): if bisect_right(d[alpha], b) - bisect_left(d[alpha], a) >= 1: ans += 1 print(ans)
# test!!!!!!!!!!! from bisect import bisect_left, bisect_right N = int(input()) S = list(input()) Q = int(input()) memo = {chr(ord('a') + i): [] for i in range(26)} for key,val in enumerate(S): memo[val].append(key) for q in range(Q): query = list(input().split()) if query[0] == '1': i, x = int(query[1])-1, query[2] now = S[i] if now == x: continue memo[now].remove(i) next_i = bisect_left(memo[x], i) memo[x].insert(next_i, i) S[i] = x else: start, end = int(query[1])-1, int(query[2])-1 tmp_cout = 0 for alf_array in memo.values(): if len(alf_array) == 0: continue ss = bisect_left(alf_array, start) gg = bisect_right(alf_array, end) if gg- ss > 0: tmp_cout += 1 print(tmp_cout)
1
62,449,722,090,798
null
210
210
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) X, Y, A, B, C = lr() P = lr(); P.sort(reverse=True) Q = lr(); Q.sort(reverse=True) R = lr(); R.sort(reverse=True) P = P[:X] Q = Q[:Y] Z = P + Q + R Z.sort(reverse=True) answer = sum(Z[:X+Y]) print(answer)
apple = list(map(int, input().split())) x = apple[0] y = apple[1] #to eat a = apple[2] b = apple[3] #i have c = apple[4] p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) r.sort(reverse=True) XredApl = [] for i in range(x): XredApl.append(p[i]) YgrnApl = [] for i in range(y): YgrnApl.append(q[i]) fnlst = XredApl + YgrnApl + r fnlst.sort(reverse=True) s = 0 for i in range(x+y): s += fnlst[i] print(s)
1
44,856,324,586,204
null
188
188
N = int(input()) evidence = [[] for _ in range(N)] for i in range(N): A = int(input()) for _ in range(A): x,y = map(int,input().split()) evidence[i].append((x-1,y)) result = 0 for i in range(1,2**N): consistent = True for j in range(N): if (i>>j)&1 == 1: for x,y in evidence[j]: if (i>>x)&1 != y: consistent = False break if not consistent: break if consistent: result = max(result,bin(i)[2:].count("1")) print(result)
N, M = map(int, input().split()) ac = 0 pena = 0 count = [0 for _ in range(N+1)] for _ in range(M): p, S = input().split() p = int(p) if S == 'AC': if count[p] > -1: pena += count[p] ac += 1 count[p] = -10**5-1 else: count[p] += 1 print(ac, pena)
0
null
107,277,794,710,382
262
240
n = int(input()) ranges = [] for i in range(n): x, l = map(int, input().split()) ranges.append([max(x-l, 0), x+l]) ranges.sort(key=lambda x: x[1]) start = 0 ans = 0 for range in ranges: if range[0] >= start: start = range[1] ans += 1 print(ans)
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from functools import reduce, lru_cache import collections, heapq, itertools, bisect import math, fractions import sys, copy sys.setrecursionlimit(1000000) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline().rstrip()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline().rstrip()) def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 def main(): K, N = LI() A = LI() res = [A[0] + K - A[-1]] for i in range(N-1): res.append(A[i+1] - A[i]) res = sorted(res) print(K - res[-1]) if __name__ == '__main__': main()
0
null
66,872,681,397,350
237
186
mod = 10**9+7 def factorials(n,m): # 0~n!のリスト f = [1,1] for i in range(2,n+1): f.append(f[-1]*i%m) # 0~n!の逆元のリスト g = [1] for i in range(n): g.append(pow(f[i+1],m-2,m)) return f,g f,g = factorials(4*10**5,mod) n,k = map(int, input().split()) if k>=n-1: print((f[2*n-1]*g[n]*g[n-1])%mod) else: ans = 0 for x in range(k+1): ans += f[n-1]*g[x]*g[n-x-1]*f[n]*g[n-x]*g[x] ans %= mod print(ans)
int = int(input()) print(int*int)
0
null
106,373,884,083,048
215
278
k=int(input()) a=[] judge=0 a.append("") a.append(7%k) for i in range(2,k+1): a.append((a[i-1]*10+7)%k) for i in range(1,k+1): if a[i]==0: print(i) judge=1 break if judge==0: print(-1)
K = int(input()) if K%2==0 or K%5==0: print(-1) else: ans = 1 rest = 7%K while rest != 0: rest *= 10 rest += 7 rest %= K ans += 1 print(ans)
1
6,118,752,125,682
null
97
97
import math def float_print(v): print('{:.5f}'.format(v)) a, b, C = map(float, input().split()) C = math.radians(C) float_print(a * b * math.sin(C) / 2) float_print(a + b + math.sqrt(math.pow(a, 2) + math.pow(b, 2) - 2 * a * b * math.cos(C))) float_print(b * math.sin(C))
import math a, b, C = map(float, input().split()) S = (a * b * math.sin(math.radians(C))) / 2 L = a + b + (a**2 + b**2 - 2 * a * b * math.cos(math.radians(C)))**0.5 h = b * math.sin(math.radians(C)) print(S) print(L) print(h)
1
182,190,082,408
null
30
30
n = input() Max = -4300000000 Min = input() for i in range(n - 1): IN_NOW = input() Max = max(Max, (IN_NOW - Min)) Min = min(Min, IN_NOW) print Max
import sys tscore = hscore = 0 n = int( sys.stdin.readline() ) for i in range( n ): tcard, hcard = sys.stdin.readline().rstrip().split( " " ) if tcard < hcard: hscore += 3 elif hcard < tcard: tscore += 3 else: hscore += 1 tscore += 1 print( "{:d} {:d}".format( tscore, hscore ) )
0
null
1,020,194,927,488
13
67