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,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() up = 0 down = 0 mp = [] mm = [] for _ in range(N): w = INF e = 0 for s in sys.stdin.readline().rstrip(): if s == '(': e += 1 else: e -= 1 w = min(w,e) if w < 0: if e > 0 :mp.append((w,e)) elif w == e: down += e else: mm.append((w,e)) else: up += e mp.sort(reverse=True) for w,e in mp: if up + w < 0: print('No') exit(0) up += e mm.sort(reverse=True) for w,e in mm: if down - w > 0: print('No') exit(0) down += e if up + down == 0: print('Yes') else: print('No') if __name__ == '__main__': main()
from sys import stdin readline = stdin.buffer.readline def r_map(): return map(int, readline().rstrip().split()) def r_list(): return list(r_map()) def main(): N = int(readline().rstrip()) A = r_list() M = max(A) d = [0] * (M + 1) g = True for a in A: d[a] += 1 for i in range(2, M + 1): c = sum(d[i::i]) if c == N: print("not coprime") exit() elif c > 1: g = False if g: print('pairwise coprime') else: print('setwise coprime') if __name__ == "__main__": main()
0
null
13,891,757,488,290
152
85
n = int(input()) i = 1 ret = "" while True: x = i if x % 3 == 0: ret += " " + str(i) elif x % 10 == 3: ret += " " + str(i) else: x //= 10 while x != 0: if x % 10 == 3: ret += " " + str(i) break x //= 10 i+=1 if i > n: break print(ret)
n=int(input()) a,c,i=[],0,1 while i <= n: if c==0: x=i if x%3==0: print(' '+str(i), end='') i+=1 continue c=0 if x%10==3: print(' '+str(i), end='') i+=1 continue x//=10 if x == 0: i+=1 continue else: c=1 print()
1
950,750,277,510
null
52
52
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines X = int(readline()) def make_divisors(n): lower_divisors = [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) i += 1 return lower_divisors A = make_divisors(X) for a in A: for b in range(10**3,-(10**3),-1): Y = X // a if ((b+a)**4 + b*(b+a)**3 + b**2*(b+a)**2 + b**3*(b+a) + b**4) == Y: print(b+a,b) sys.exit()
x = int(input()) n = 120 for i in range(n): for j in range(i): if x == i**5-j**5: print(i,j) exit(0) if x == i**5+j**5: print(i,-j) exit(0)
1
25,588,417,164,530
null
156
156
import sys N = int(input()) S = input() if N%2!=0 : print("No") sys.exit(0) else: for i in range(int(N/2)): if S[i]!=S[i+int(N/2)]: print("No") sys.exit(0) print("Yes")
N=int(input()) S=input() if N%2==1:print('No') else: s1,s2=S[:N//2],S[N//2:] ok=1 for i in range(N//2): if s1[i]!=s2[i]: print('No') ok=0 break if ok==1:print('Yes')
1
146,604,704,954,878
null
279
279
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) if A1 < B1: A1, A2, B1, B2 = B1, B2, A1, A2 if A1*T1+A2*T2 == B1*T1+B2*T2: print('infinity') exit() if (A1-B1)*T1 > (B2-A2)*T2: print(0) exit() d = abs(A1*T1+A2*T2 - B1*T1-B2*T2) # T1,T2が終わった後に開く距離 L = abs(A1-B1)*T1 # T1の間に開く距離 # print(d, L) if L % d == 0: print(L//d*2) else: ans = L//d*2+1 print(ans) # if d*L//d <= L: # ans += 1
h, w, k = map(int, input().split()) mat = [input() for i in range(h)] num = 0 ans = [[0]*w for _ in range(h)] heights = [0]*h for i in range(h): for j in range(w): if mat[i][j] == "#": heights[i] += 1 hs = [] for v in range(h): if heights[v] >= 1: hs.append(v) for i in range(len(hs)): h1 = 0 h2 = h-1 if i >= 1: h1 = hs[i-1] + 1 if i < len(hs)-1: h2 = hs[i] ws = [] for j in range(h1, h2+1): for k in range(w): if mat[j][k] == "#": ws.append(k) ws.sort() for j in range(len(ws)): w1 = 0 w2 = w-1 if j >= 1: w1 = ws[j-1]+1 if j < len(ws)-1: w2 = ws[j] num += 1 for k in range(h1, h2+1): for l in range(w1, w2+1): ans[k][l] = num for i in range(h): print(*ans[i])
0
null
137,210,366,243,098
269
277
A = input() B = input() se = set(["1","2","3"]) a = se-set([A,B]) print(a.pop())
x='123' for _ in range(2): x=x.replace(input(),'') print(x)
1
110,565,142,482,668
null
254
254
import math char = str(input()) char = char.replace('?','D') print(char)
t = input() if(len(t) == 1): if (t[0] == '?'): t = "D" if(t[0] == '?'): if (t[1] == 'D'): t = "".join(['P' , t[1:]]) elif(t[1] == '?'): t = "".join(['PD', t[2:]]) else: t = "".join(['D' , t[1:]]) if(t[-1] == '?'): t = "".join([t[:-1], 'D']) for i in range(len(t)-1): if(t[i] == '?'): if(t[i-1] == 'P'): t = "".join([t[:i], 'D' , t[i+1:]]) elif(t[i+1] == 'D'): t = "".join([t[:i], 'P' , t[i+1:]]) elif(t[i+1] == 'P'): t = "".join([t[:i], 'D' , t[i+1:]]) elif(t[i+1] == '?'): t = "".join([t[:i], 'PD', t[i+2:]]) print(t)
1
18,413,735,896,150
null
140
140
def main(): import sys input = sys.stdin.readline N = int(input()) plus = [] minus = [] total = 0 for _ in range(N): s = input().strip() h = 0 bottom = 0 for ss in s: if ss == "(": h += 1 else: h -= 1 bottom = min(bottom, h) total += h if h > 0: plus.append((bottom, h)) else: minus.append((bottom-h, -h)) if total != 0: print("No") sys.exit() plus.sort(reverse=True) minus.sort(reverse=True) height = 0 for b, h in plus: if height + b < 0: print("No") sys.exit() height += h height = 0 for b, h in minus: if height + b < 0: print("No") sys.exit() height += h print("Yes") if __name__ == '__main__': main()
# coding: utf-8 import sys from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import combinations, product #import bisect# lower_bound etc #import numpy as np #import queue# queue,get(), queue.put() def run(): N = int(input()) current = 0 ways = [] dic = {'(': 1, ')': -1} SS = read().split() for S in SS: path = [0] for s in S: path.append(path[-1]+ dic[s]) ways.append((path[-1], min(path))) ways_pos = sorted([(a,b) for a,b in ways if a >= 0], key = lambda x:(x[1], x[0]), reverse=True) ways_neg = sorted([(a,b) for a,b in ways if a < 0], key = lambda x:(x[1] - x[0], -x[0])) for i in range(len(ways_pos)): go, max_depth = ways_pos[i] if current + max_depth >= 0: current += go else: print("No") return None for i in range(len(ways_neg)): go, max_depth = ways_neg[i] if current + max_depth >= 0: current += go else: print("No") return None if current == 0: print('Yes') else: print('No') if __name__ == "__main__": run()
1
23,785,970,484,260
null
152
152
n = input() A = [i for i in input().split()] A.reverse() print(' '.join(A))
num = int(input()) numbers = list(map(int,input().split())) for i in reversed(numbers): print(i,end="") if i != numbers[0]: print(" ",end="") print()
1
987,524,937,300
null
53
53
def main(): N, S = map(int, input().split()) A = tuple(map(int, input().split())) MOD = 998244353 dp = [[0]*(S+1) for _ in range(N+1)] dp[0][0] = 1 # morau for i, a in enumerate(A): dp[i][0] = pow(2, i, MOD) for j in range(S+1): if j >= a: dp[i+1][j] = 2 * dp[i][j] dp[i+1][j] %= MOD dp[i+1][j] += dp[i][j-a] dp[i+1][j] %= MOD else: dp[i+1][j] = 2 * dp[i][j] dp[i+1][j] %= MOD print(dp[N][S]) if __name__ == "__main__": main()
def main(): h,w,k=map(int,input().split()) grid=[input() for _ in [0]*h] ans=[[0]*w for _ in [0]*h] berry=0 for i in range(h): if "#" in grid[i]: cnt=0 berry+=1 for j in range(w): if grid[i][j]=="#": cnt+=1 if cnt>1: berry+=1 ans[i][j]=berry for i in range(1,h): if ans[i][0]==0: for j in range(w): ans[i][j]=ans[i-1][j] for i in range(h-2,-1,-1): if ans[i][0]==0: for j in range(w): ans[i][j]=ans[i+1][j] for i in ans: print(*i) main()
0
null
81,066,397,215,440
138
277
import sys def resolve(in_): A, B = map(int, in_.readline().split()) for i in range(1, 1251): if i * 8 // 100 == A and i // 10 == B: return i return -1 def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
alp=list("abcdefghijklmnopqrstuvwxyz") print(alp[alp.index(input())+1])
0
null
74,084,625,750,762
203
239
a = int(input()) b = int(a + a ** 2 + a ** 3) print(b)
n = int(input()) pr = {} for i in range(n): s = input() if pr != s: pr[s] = True print(len(pr))
0
null
20,356,589,983,688
115
165
n=int(input()) Ns=list(map(int, input().split() ) ) ans=0 for i in range(n): for j in range(i,n): for k in range(j,n): a , b , c = sorted([Ns[i] , Ns[j] , Ns[k]]) if a+b>c and a!=b and b!=c: ans+=1 print(ans)
nums = input().split(' ') a = int(nums[0]) b = int(nums[1]) c = int(nums[2]) d = int(nums[3]) multi = [] multi.append(a * c) multi.append(a * d) multi.append(b * c) multi.append(b * d) ans = - 10 ** 18 for i in range(4): if multi[i] > ans: ans = multi[i] print(ans)
0
null
4,039,496,426,910
91
77
import math x1, y1, x2, y2 = map(float, input().split()) a = x2 - x1 b = y2 - y1 print(math.sqrt(a**2 + b**2))
import math x1,y1,x2,y2=input().split() x1=float(x1) y1=float(y1) x2=float(x2) y2=float(y2) r=math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) print(r)
1
154,350,161,810
null
29
29
S,T=list(input().split()) T+=S print(T)
def q1(): S, T = input().split() print('{}{}'.format(T, S)) if __name__ == '__main__': q1()
1
103,057,429,224,288
null
248
248
a,b,c=map(int,input().split()) d=0 while b<=a: b*=2 d+=1 while c<=b: c*=2 d+=1 print("Yes"if d<=int(input())else"No")
import math n = float(raw_input()) a = n * n * math.pi b = 2 * n * math.pi print ('%.6f %.6f' % (a, b))
0
null
3,752,089,901,212
101
46
import numpy as np n = int(input()) k = np.arange(1,n+1) d = n // k print((k*d*(d+1)//2).sum())
N=int(input()) ans = 0 for k in range(1,N+1): n_ = N // k ans_ = k*n_*(n_+1)//2 ans+= ans_ print(ans)
1
11,052,279,597,572
null
118
118
N=int(input()) S=input() l=[] for i in range(N-1): if S[i]!=S[i+1]: l.append(S[i]) l.append(S[N-1]) print(len(l))
N=int(input()) S=list(map(str,input())) ans=1 for i in range(N-1): if S[i]!=S[i+1]: ans+=1 print(ans)
1
169,822,736,543,460
null
293
293
from math import * def main(): n = int(input()) print(n+n**2+n**3) main()
n,k = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) b = [0]*(k-n) a.extend(b) print(sum(a[k:]))
0
null
44,398,836,872,580
115
227
n = int(input()) c = list('abcdefghijklmnopqrstuvwxyz') ans = [] def calc(k): if k == 0: return '' else: k -= 1 return calc(k // 26) + c[k % 26] print(calc(n))
def main(): n = int(input()) ab_max = n-1 ans = sum(ab_max // a for a in range(1, n)) return ans if __name__ == '__main__': print(main())
0
null
7,290,610,500,708
121
73
import sys l = sys.stdin.readlines() for i in l: if "?" in i: break else: str = i.replace('/','//') print(eval(str))
n = int(input()) s = str(input()) a = 0 c = len(s)//2 if n % 2 == 0: for i in range(c): if s[i] == s[c+i]: a += 1 if a == n/2 : print("Yes") else : print("No") else : print("No")
0
null
73,905,426,892,038
47
279
x = int(input()) print('1' if x == 0 else '0')
x = not(int(input())) print(int(x))
1
2,932,677,675,682
null
76
76
import sys from collections import defaultdict # from collections import Counter # from queue import PriorityQueue # sys.setrecursionlimit(2000000) def distance(X, Y, start, goal): ans = float('inf') tmp = goal - start if tmp < ans: ans = tmp # start ~ X ~ Y ~ goal, tmp = abs(X - start) + 1 + abs(goal - Y) if tmp < ans: ans = tmp # start ~ Y ~ X ~ goal tmp = abs(Y - start) + 1 + abs(goal - X) if tmp < ans: ans = tmp return ans # # 短絡パスを使える場合 # if start <= X and Y <= goal # # 短絡パスを使えないならば、普通に距離を計算 # if X < start: # return goal - start # # 短絡パスを使えても、隣のパスへの距離は1 # if goal - start == 1: # return 1 # # 短絡パスより手前だと使えない # if goal < Y: # return goal - start # return goal - start - 1 def main(): # N = int(input()) N, X, Y = [int(s) for s in input().split()] distance_dict = defaultdict(int) for i in range(1, N+1): for j in range(i + 1, N+1): d = distance(X, Y, i, j) # sys.stderr.write('{} to {} : d = {}\n'.format(i, j, d)) # ditance_dict[(i, j)] = d distance_dict[d] += 1 for k in range(1, N): # print(str(distance_dict[k])) print(distance_dict[k]) # As = [] # Bs = [] # for i in range(N): # A, B = [int(s) for s in input().split()] # As.append(A) # Bs.append(B) return 0 if __name__ == '__main__': sys.exit(main())
n = int(input()) s = input() ans = 0 for i in range(n-2): if s[i] == 'A': if s[i+1] == 'B': if s[i+2] == 'C': ans += 1 print(ans)
0
null
71,847,948,908,018
187
245
N,X,M = map(int,input().split()) ls = [X] for i in range(M): Ai = ls[-1]**2 % M if Ai in ls: loop = ls[ls.index(Ai):] lenloop = len(loop) sumloop = sum(loop) startls = ls[:ls.index(Ai)] break ls.append(Ai) if N <= len(startls): ans = sum(startls[:N]) else: ans = sum(startls) + ((N-len(startls))//lenloop)*sumloop + sum(loop[:(N-len(startls))%lenloop]) print(ans)
import collections n = int(input()) x = list(map(int, input().split())) y = collections.Counter(x) for i in range(1, len(x)+2): print(y[i], end = "\n")
0
null
17,836,028,177,570
75
169
# 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)
N, K = map(int, input().split()) *A, = map(int, input().split()) b = [i for i in A] for c in range(K): buf = [0]*(N+1) for i, j in enumerate(b): buf[max(i-j, 0)] += 1 buf[min(i+j+1, N)] -= 1 for i in range(1, N+1): buf[i] += buf[i-1] b = [buf[i] for i in range(N)] if all([i==N for i in b]): break print(*b)
0
null
8,787,487,456,360
68
132
count, outrate = map(int, input().split()) if count >= 10: result = outrate print(result) else: result = outrate + 100 * (10 - count) print(result)
H,W,K = map(int,input().split()) A = [] for i in range(H): b = list(input()) b.append("0") A.append(b) ans = 10**6 for i in range(2**(H-1)): p = "0" + str(H-1) bin_list = list(format(i,p+"b")) sec = [] for i in range(H-1): if bin_list[i] == "1": sec.append(i) sec.append(H-1) l = len(sec) W_start = 0 k = 0 while(True): H_start = 0 pross = 10**4 for i in range(l): H_end = sec[i] + 1 j = W_start c = 0 while(True): for t in range(H_start,H_end): if A[t][j] == "1": c += 1 j += 1 if c > K or j > W: pross = min(pross,j-W_start) break H_start = sec[i] + 1 k += 1 W_start += pross-1 if W_start > W-1 or pross == 1: break if pross != 1: ans = min(ans,k+l-2) print(ans)
0
null
56,291,902,493,540
211
193
#162B #FizzBuzz Sum n=int(input()) print(sum(x for x in range(1,n+1) if x%3!=0 and x%5!=0))
n,k = map(int,input().split()) a = list(map(int,input().split())) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**5+100 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) a.sort() if k == 1: print(0) else: ma,mi = 0,0 for i in range(n-k+1): mi = (mi + (a[i] * cmb(n-1-i,k-1,mod))) % mod ma = (ma + (a[n-1-i] * cmb(n-1-i,k-1,mod))) % mod print((ma + mod - mi) % mod)
0
null
65,694,933,894,272
173
242
a,b,c=[int(i) for i in input().split()] if a < b and b < c: print("Yes"); else: print("No");
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) n,k=mp() h=sorted(lmp()) if n<=k: print(0) else: print(sum(h[:n-k]))
0
null
39,908,189,687,808
39
227
a, b = map(int, input().split()) mat = [map(int, input().split()) for i in range(a)] vec = [int(input()) for i in range(b)] for row in mat: print(sum([x*y for x, y in zip(row, vec)]))
def modpow(val, n, mod): ret = 1 while n: if n & 1: ret = (ret * val) % mod val = (val * val) % mod n = n >> 1 return ret mod = 10 ** 9 + 7 n, k = map(int, input().split()) my_dict = dict() ret = 0 for i in range(k, 0, -1): tmp = modpow(k // i, n, mod) cnt = 2 while True: val = i * cnt if val > k: break else: cnt += 1 tmp -= my_dict[val] my_dict[i] = tmp ret += tmp * i % mod print(ret % mod)
0
null
18,997,689,141,740
56
176
N,K = map(int,input().split()) S = [tuple(map(int,input().split())) for _ in range(K)] MOD=998244353 dp=[0]*N dp[0]=1 for i in range(N-1): x = dp[i] dp[0]=0 for k in range(K): l,r = S[k] if i+l < N: dp[i+l]+=x dp[i+l]%=MOD if i+r+1 < N: dp[i+r+1]-=x dp[i+r+1]%=MOD dp[i+1]+=dp[i] dp[i+1]%=MOD print(dp[-1]%MOD)
def scoring(d, t, k=10): arr = [l for l in last] arr[t] = d penalty = sum((d - l) * c for l, c in zip(arr, C)) score = S[d][t] - penalty score -= (min(D, d + k) - d - 1) * penalty return score D = int(input()) C = list(map(int, input().split())) S = [] for _ in range(D): s = list(map(int, input().split())) S.append(s) last = [-1] * 26 ans = [] for i in range(D): res = -10 ** 6 idx = -1 for j in range(26): tmp = scoring(i, j) if tmp > res: res = tmp idx = j last[idx] = i ans.append(idx+1) print(*ans, sep='\n')
0
null
6,214,531,196,608
74
113
from scipy.sparse.csgraph import csgraph_from_dense from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall import numpy as np N,M,L=map(int,input().split()) A=[0]*M B=[0]*M C=[0]*M for i in range(M): A[i],B[i],C[i] = map(int,input().split()) A[i] -=1 B[i] -=1 Q=int(input()) ST=[list(map(int,input().split())) for _ in range(Q)] G = csr_matrix((C, (A, B)), shape=(N, N)) d = floyd_warshall(G, directed=False) G=np.full((N,N), np.inf) G[d<=L]=1 G = csr_matrix(G) E = floyd_warshall(G, directed=False) for s,t in ST: if E[s-1][t-1]==float('inf'): print(-1) else: print(int(E[s-1][t-1]-1))
# N=int(input()) A,B=[int(x) for x in input().rstrip().split()] if A<=B*2: print(0) else: print(A-B*2)
0
null
170,222,048,869,288
295
291
s = input() summation = sum([int(i) for i in s]) is_mul = summation%9 if is_mul == 0: print("Yes") else: print("No")
n = int(input()) a = set([input() for i in range(n)]) print(len(a))
0
null
17,321,902,335,738
87
165
# B Popular Vote N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse = True) border = sum(A) / (4 * M) cnt = 0 for a in A: if a >= border: cnt += 1 else: break if cnt >= M: print("Yes") else: print("No")
N,M=map(int, input().split()) a=[0]*(N+1) w=[0]*(N+1) for _ in range(M): p,s=input().split() p=int(p) if s=='AC': a[p]=1 else: if a[p]==0: w[p]+=1 a2=0 w2=0 for n in range(N+1): if a[n]==1: a2+=a[n] w2+=w[n] print(a2, w2)
0
null
66,382,074,374,182
179
240
def solve(sup,rest,digit,used1,used2): if rest<0: return 0 if digit==0: if rest==0: return 1 else: return 0 sum=0 for i in range(1,sup+1): if i!=used1 and i!=used2: if used1==0: sum+=solve(sup,rest-i,digit-1,i,used2) elif used2==0: sum+=solve(sup,rest-i,digit-1,used1,i) else: sum+=solve(sup,rest-i,digit-1,used1,used2) return sum N=[] X=[] while True: n,x=map(int,raw_input().split()) if (n,x)==(0,0): break N.append(n) X.append(x) for i in range(len(N)): print('%d'%(solve(N[i],X[i],3,0,0)/6))
def get_num(n, x): ans = 0 for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1): for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1): if n3 + min(n2 - 1, x - n3 - n2): ans += 1 # for n1 in xrange(min(n2 - 1, x - n3 - n2), x - n3 - n2 - 1, -1): # if n3 == x - n1 - n2: # ans += 1 # break return ans data = [] while True: [n, x] = [int(m) for m in raw_input().split()] if [n, x] == [0, 0]: break if x < 3: print(0) else: print(get_num(n, x))
1
1,281,927,099,168
null
58
58
def main(): a, b, c, d = map(int, input().split()) if a*b > 0 and c*d > 0 and a*c < 0: print(max(a*d, b*c)) else: print(max(a*c, b*d, 0)) if __name__ == "__main__": main()
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)
1
3,030,434,519,502
null
77
77
n, a, b = map(int, input().split()) if a % 2 == b % 2: print((b - a) // 2) else: if a > n - b + 1: rest = (b - a) // 2 print(n - a - rest) else: rest = (b - a) // 2 print(b - 1 - rest) #print(max(a, n - b + 1) - 1)
n = int(input()) my_cards = {input() for _ in range(n)} lost_cards = ( "{} {}".format(s, i) for s in ('S', 'H', 'C', 'D') for i in range(1, 13 + 1) if "{} {}".format(s, i) not in my_cards ) for card in lost_cards: print (card)
0
null
54,940,630,735,620
253
54
# print(max([len(v) for v in input().split('S')])) d = { 'RRR': 3, 'RRS': 2, 'RSR': 1, 'RSS': 1, 'SRR': 2, 'SRS': 1, 'SSR': 1, 'SSS': 0, } print(d[input()])
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,924,109,114,358
null
90
90
X=int(input()) #m1,d1=map(int,input().split()) #hl=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] flag=0 for i in range(1,1001): if i*100 <= X and X <= i*105: flag=1 break print(flag)
# -*- coding:utf-8 -*- import math def insertion_sort(num_list, length, interval): cnt = 0 for i in range(interval, length): v = num_list[i] j = i - interval while j >= 0 and num_list[j] > v: num_list[j+interval] = num_list[j] j = j - interval cnt = cnt + 1 num_list[j+interval] = v return cnt def shell_sort(num_list, length): cnt = 0 h = 4 intervals = [1,] while length > h: intervals.append(h) h = 3 * h + 1 for i in reversed(range(len(intervals))): cnt = cnt + insertion_sort(num_list, length, intervals[i]) print(len(intervals)) print(*reversed(intervals)) print(cnt) input_num = int(input()) input_list = list() for i in range(input_num): input_list.append(int(input())) shell_sort(input_list, input_num) for num in input_list: print(num)
0
null
63,432,378,583,560
266
17
X,Y,A,B,C=map(int,input().split()) 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) P.append(float("inf")) Q.append(float("inf")) ans=sum(P[:X]+Q[:Y]) rfinish=False gfinish=False r,g,f=X-1,Y-1,0 while f<C and (R[f]>P[r] or R[f]>Q[g]): if P[r]<Q[g]: ans=ans-P[r]+R[f] r-=1 f+=1 else: ans=ans-Q[g]+R[f] g-=1 f+=1 print(ans)
K = int(input()) S = str(input()) SK = S[0: (K)] if len(S) <= K: print(S) else: print(SK + '...')
0
null
32,136,841,133,812
188
143
n,a,b = map(int,input().split()) A=n//(a+b) B=n%(a+b) ans = a * A if B>=a: ans += a else: ans += B print(ans)
N, A, B = input().split(' ') N = int(N) A = int(A) B = int(B) a = A * (N // (A+B)) if (N%(A+B)) > A: a += A else: a += (N%(A+B)) print(a)
1
55,482,209,919,488
null
202
202
x,y = map(int,input().split()) a = [0]*210 a[:3] = [300000, 200000, 100000] if x == y and x == 1: print(1000000) else: print(a[x-1] + a[y-1])
#!/usr/bin/env python3 x, y = map(int, input().split()) ans = (x == y == 1) * 400000 ans += 100000 * max(0, 4 - x) ans += 100000 * max(0, 4 - y) print(ans)
1
141,048,758,711,260
null
275
275
N = int(input()) XL = [list(map(int, input().split())) for x in range(N)] XL = sorted(XL, key=lambda x: x[0]+x[1]) cnt = 0 prev_right = -10**9+10 for x, l in XL: left = x - l right = x + l if left >= prev_right: cnt += 1 prev_right = right print(cnt)
class Modulo_Error(Exception): pass class Modulo(): def __init__(self,a,n): self.a=a%n self.n=n def __str__(self): return "{} (mod {})".format(self.a,self.n) #+,- def __pos__(self): return self def __neg__(self): return Modulo(-self.a,self.n) #等号,不等号 def __eq__(self,other): if isinstance(other,Modulo): return (self.a==other.a) and (self.n==other.n) elif isinstance(other,int): return (self-other).a==0 def __neq__(self,other): return not(self==other) #加法 def __add__(self,other): if isinstance(other,Modulo): if self.n!=other.n: raise Modulo_Error("異なる法同士の演算です.") return Modulo(self.a+other.a,self.n) elif isinstance(other,int): return Modulo(self.a+other,self.n) def __radd__(self,other): if isinstance(other,int): return Modulo(self.a+other,self.n) #減法 def __sub__(self,other): return self+(-other) def __rsub__(self,other): if isinstance(other,int): return -self+other #乗法 def __mul__(self,other): if isinstance(other,Modulo): if self.n!=other.n: raise Modulo_Error("異なる法同士の演算です.") return Modulo(self.a*other.a,self.n) elif isinstance(other,int): return Modulo(self.a*other,self.n) def __rmul__(self,other): if isinstance(other,int): return Modulo(self.a*other,self.n) #Modulo逆数 def Modulo_Inverse(self): x0, y0, x1, y1 = 1, 0, 0, 1 a,b=self.a,self.n while b != 0: q, a, b = a // b, b, a % b x0, x1 = x1, x0 - q * x1 y0, y1 = y1, y0 - q * y1 if a!=1: raise Modulo_Error("{}の逆数が存在しません".format(self)) else: return Modulo(x0,self.n) #除法 def __truediv__(self,other): return self*other.Modulo_Inverse() #累乗 def __pow__(self,m): u=abs(m) r=Modulo(1,self.n) while u>0: if u%2==1: r*=self self*=self u=u>>1 if m>=0: return r else: return r.Modulo_Inverse() #------------------------------------------------------------------------- M=10**9+7 n,a,b=map(int,input().split()) C=[Modulo(1,M)]*(b+1) for k in range(1,b+1): C[k]=C[k-1]*Modulo(n-(k-1),M)/Modulo(k,M) print((Modulo(2,M)**n-(C[a]+C[b])-1).a)
0
null
77,894,107,408,220
237
214
ans = ["1","2","3"] a,b = input(),input() ans.remove(a) ans.remove(b) print(ans[0])
N, K =map(int,input().split()) p = list(map(int,input().split())) for i in range(N): for n in range(N-1): if p[n]>p[n+1]: tmp = p[n] p[n] = p[n+1] p[n+1] = tmp ans =0 for i in range(K): ans += p[i] print(ans)
0
null
60,881,743,294,812
254
120
s = input() p = input() ret = 'No' tts = s + s[:len(p)] if p in tts: ret = 'Yes' print(ret)
n=str(input()) a=len(n) N=list(n) m=str(input()) A=len(m) x=0 for i in range(a): C=[] for i in range(A): C.append(N[i]) B=''.join(C) c=N[0] if B==m: x=x+1 N.remove(c) N.append(c) if x>0: print('Yes') else: print('No')
1
1,770,323,494,632
null
64
64
input() A = [i for i in input().split()] A.reverse() print(' '.join(A))
raw_input() print " ".join([i for i in raw_input().split()][::-1])
1
979,633,127,220
null
53
53
number = int(input()) Total = [] for i in range(1, number + 1): if number % 3 == 0 and i % 5 ==0: "FizzBuzz" elif i % 3 ==0: "Fizz" elif i % 5 == 0: "Buzz" else: Total.append(i) print(sum(Total))
n = int(input()) x = 0 for i in range(1, n + 1): if i % 5 == 0 or i % 3 == 0: pass else: x += i print(x)
1
34,929,952,031,140
null
173
173
N = int(input()) S, T = map(str, input().split()) S = list(S) T = list(T) ANS = [] for i in range(N): ANS.append(S[i]) ANS.append(T[i]) ANS = ''.join(ANS) print(ANS)
d=list(map(int,input().split())) c=list(input()) class dice(object): def __init__(self, d): self.d = d def roll(self,com): a1,a2,a3,a4,a5,a6=self.d if com=="E": self.d = [a4,a2,a1,a6,a5,a3] elif com=="W": self.d = [a3,a2,a6,a1,a5,a4] elif com=="S": self.d = [a5,a1,a3,a4,a6,a2] elif com=="N": self.d = [a2,a6,a3,a4,a1,a5] dice1=dice(d) for com in c: dice1.roll(com) print(dice1.d[0])
0
null
56,053,891,383,350
255
33
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) S = S() if S[2] == S[3] and S[4] == S[5]: print('Yes') else: print('No')
data = list(map(int,input().split())) if(data[0] < data[1]): data[0],data[1] = data[1],data[0] def gcd(x,y): return x if y == 0 else gcd(y,x%y) print(gcd(data[0],data[1]))
0
null
20,900,766,818,678
184
11
N=input() if N.isupper(): print("A") else: print("a")
import sys # sys.setrecursionlimit(100000) from collections import deque 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(): s = deque(list(input())) q = input_int() inverse = False for _ in range(q): data = input().split() if len(data) == 1: inverse = not inverse else: if (data[1] == "1" and not inverse) or (data[1] == "2" and inverse): s.appendleft(data[2]) else: s.append(data[2]) if inverse: print("".join(reversed(s))) else: print("".join(s)) return if __name__ == "__main__": main()
0
null
34,456,173,220,300
119
204
L = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51" L = L.split(", ") k = int(input()) print(L[k-1])
import sys from math import sqrt, gcd, ceil, log from bisect import bisect from collections import defaultdict inp = sys.stdin.readline read = lambda: list(map(int, inp().strip().split())) # sys.setrecursionlimit(10**6) def solve(): s = inp().strip(); dic = defaultdict(int); dic[0] = 1 # sett.add(0) ans = 0; cum = 0 for i in range(len(s)-1, -1, -1): cum += (int(s[i])*pow(10, (len(s)-i-1), 2019)) % 2019 cum %= 2019 dic[cum] += 1 # print(dic) for i in dic: ans += ((dic[i])*(dic[i]-1))//2 print(ans) if __name__ == "__main__": solve()
0
null
40,350,769,187,300
195
166
k = int(input()) s = input() MOD = 10**9+7 class Facts(): # O(max_num) def __init__(self, max_num=10**5, p=10**9+7): self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) self.rev = [1] * (self.max_num + 1) for i in range(1, self.max_num + 1): self.fact[i] = (self.fact[i-1] * i) % self.p self.rev[self.max_num] = self.power_func(self.fact[self.max_num], self.p-2) for i in range(self.max_num-1, 0, -1): self.rev[i] = self.rev[i+1] * (i + 1) % self.p def comb(self, n, k): if n < 0 or k < 0 or n < k: return 0 if n == 0 or k == 0: return 1 res = ((self.fact[n] * self.rev[k] % self.p) * self.rev[n - k]) % self.p return res def power_func(self, a, b): # a^b mod p # O(log(b)) ans = 1 while b > 0: if b & 1: ans = ans * a % self.p a = a * a % self.p b >>= 1 return ans r26 = [1 for _ in range(k + 1)] r25 = [1 for _ in range(k + 1)] for i in range(1, k+1): r26[i] = (r26[i-1] * 26) % MOD r25[i] = (r25[i-1] * 25) % MOD facts = Facts(max_num=len(s)+k+1, p=MOD) total = len(s) + k ans = 0 for s_n in range(len(s), total+1): d = total - s_n ans += facts.comb(total - d - 1, len(s) - 1) * r25[k-d] * r26[d] ans %= MOD print(ans)
N, M, L = map(int, raw_input().split()) nm = [map(int, raw_input().split()) for n in range(N)] ml = [map(int, raw_input().split()) for m in range(M)] ml_t = [] for l in range(L): tmp = [] for m in range(M): tmp.append(ml[m][l]) ml_t.append(tmp) for n in range(N): tmp1 = nm[n] col = [0]*L for l in range(L): tmp2 = ml_t[l] for m in range(M): col[l] += tmp1[m] * tmp2[m] print ' '.join(map(str, col))
0
null
7,128,057,263,172
124
60
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')
a=map(int,raw_input().split()) print(str(a[0]*a[1])+" "+str(2*(a[0]+a[1])))
0
null
749,646,485,210
57
36
N = int(input()) A = sorted(list(map(int,input().split()))) ans = "YES" for i in range(1,N,2): boollist = [ A[i-1] == A[i] ] if i < N-1 : boollist.append(A[i] == A[i+1]) if any(boollist): ans = "NO" break print(ans)
# -*- coding:utf-8 -*- class Cards: trump = [False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,] def HaveCards(self,num): self.trump[num] = True def TransCards(self,s,num): if(s == 'H'): num += 13 elif(s == 'C'): num +=26 elif(s == 'D'): num += 39 return num def CheckCards(self,num): if(num <= 12): return 'S' ,num+1 elif(num >= 13 and num <= 25): return 'H' ,num-12 elif(num >= 26 and num <= 38): return 'C',num-25 elif(num >= 39 and num <=51): return 'D',num-38 n = int(input()) ob = Cards() for i in range(n): s,str_num = input().split() number = int(str_num) Num=ob.TransCards(s,number-1) ob.HaveCards(Num) for i in range(len(Cards.trump)): if Cards.trump[i] == False: Str,Num=ob.CheckCards(i) print(Str,Num)
0
null
37,276,548,991,460
222
54
n, m, x = map(int, input().split()) ca = [list(map(int, input().split())) for _ in range(n)] # 購買する全パターンを回す most_row_price = 10**10 for i in range(2**n): comb = str(bin(i)[2:]).zfill(n) # 購買パターン毎の購入金額と理解度を算出する money_per_pattern = [0] * n # 購買パターン毎の金額の初期化 understanding = [0] * m # 理解度の初期化 total_money = 0 # 合計購入金額の初期化 for j in range(n): # 購入しないケースは除外する if comb[j] == '0': continue # 購入するケースだけ、金額算出する money_per_pattern[j] = ca[j][0] # 当該パターンの理解度を算出する for k in range(m): understanding[k] += ca[j][k+1] total_money = sum(money_per_pattern) judge_flg = 'ok' for j in range(m): if understanding[j] < x: judge_flg = 'ng' if judge_flg == 'ok': most_row_price = min(total_money, most_row_price) if most_row_price == 10**10: print(-1) else: print(most_row_price)
import math N,M=map(int,input().split()) def comb(num,k): if num<2: return 0 return math.factorial(num)/(math.factorial(k)*math.factorial(num-k)) ans=int(comb(N,2)+comb(M,2)) print(ans)
0
null
33,927,833,515,800
149
189
import sys def main(): sys.stdin.readline() list1 = [int(i) for i in sys.stdin.readline().split()] print(min(list1), max(list1), sum(list1)) if __name__ == '__main__': main()
A,B,C = map(int,input().split()) if A == B: if A != C: print("Yes") else: print("No") else: if B == C or A == C: print("Yes") else: print("No")
0
null
34,469,522,267,164
48
216
def resolve(): S = input() print('Yes' if S[2]==S[3] and S[4]==S[5] else 'No') resolve()
co ="coffee" S = input() if S[2]!=S[3]: print("No") elif S[4]!=S[5]: print("No") else: print("Yes")
1
42,330,873,321,702
null
184
184
res = [] n = int(input()) for i in range(n): r = input() res.append(r) ac = res.count("AC") wa = res.count("WA") tle = res.count("TLE") re = res.count("RE") print("AC x "+str(ac)) print("WA x "+str(wa)) print("TLE x "+str(tle)) print("RE x "+str(re))
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): status = input() if status == 'AC': ac += 1 elif status == 'WA': wa += 1 elif status == 'TLE': tle += 1 else: re += 1 print('AC x', ac) print('WA x', wa) print('TLE x', tle) print('RE x', re)
1
8,677,545,423,260
null
109
109
import math as mt a,b,h,m=map(int, input().split()) print(mt.sqrt(a**2+b**2-2*a*b*mt.cos(2*mt.pi*(1/12*(h+m/60)-m/60))))
import math a, b, h, m = map(int, input().split()) x = 6 * m y = 30 * h + 0.5 * m C = max(x, y) - min(x, y) C = min(C, 360 - C) print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))))
1
20,196,075,671,770
null
144
144
def resolve(): N, M = list(map(int, input().split())) H = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] good = [True for i in range(N)] for a, b in AB: a, b = a-1, b-1 if H[a] < H[b]: good[a] = False elif H[a] == H[b]: good[a] = False good[b] = False else: good[b] = False cnt = 0 for g in good: if g: cnt += 1 print(cnt) if '__main__' == __name__: resolve()
n = int(input()) s = input().replace("ABC", "") print((n-len(s))//3)
0
null
62,354,509,163,798
155
245
n = int(input()) a = int(n**0.5+1) ans = [0]*n for x in range(1, a): for y in range(1, a): for z in range(1, a): if x**2 + y**2 + z**2 + x*y + y*z + z*x <= n: ans[x**2 + y**2 + z**2 + x*y + y*z + z*x -1] += 1 [print(i) for i in ans]
while True: text = input() if text == '0': break total = 0 for a in range(len(text)): total += int(text[a]) print(total)
0
null
4,798,304,507,062
106
62
a, b, c, d = map(int, input().split()) x = 0 y = 0 while c > 0: c -= b x += 1 while a > 0: a -= d y += 1 if x <= y: print('Yes') else: print('No')
def main(): s = input() t = input() ans = 0 for i, char in enumerate(s): if char != t[i]: ans += 1 print(ans) if __name__ == '__main__': main()
0
null
20,236,793,265,718
164
116
a, b = input().split() a = int(a) b = int(b) if a > b: print('a > b') elif a < b: print('a < b') else: print('a == b')
x=raw_input() list=x.split() a=int(list[0]) b=int(list[1]) if a<b: print 'a < b' elif a>b: print 'a > b' elif a==b: print 'a == b'
1
365,547,475,100
null
38
38
x,n=map(int,input().split()) if n==0: print(x) exit() p=[int(y) for y in input().split()] a=0 for i in range(101): if x-a not in p: print(x-a) break elif x+a not in p: print(x+a) break a+=1
X, N = map(int, input().split()) p_list = list(map(int, input().split())) if N == 0: print(X) else: for i in range(0,100): if not X-i in p_list: print(X-i) break elif not X+i in p_list: print(X+i) break
1
14,007,025,238,820
null
128
128
mod = 998244353 N, S = map(int, input().split()) A = list(map(int, input().split())) dp = [[0]*(S+1) for _ in range(N+1)] dp[0][0] = 1 for i in range(1,N+1): dp[i][0] = dp[i-1][0]*2%mod for i in range(1,N+1): for j in range(1,S+1): dp[i][j] = dp[i-1][j]*2%mod if j>=A[i-1]: dp[i][j] += dp[i-1][j-A[i-1]] ans = dp[-1][-1]%mod print(ans)
#!/usr/bin/env python3 import sys input = sys.stdin.readline MOD = 998244353 n, s = map(int, input().split()) a = [int(item) for item in input().split()] dp = [[0] * (s + 1) for _ in range(n+1)] dp[0][0] = 1 for i, item in enumerate(a): for j in range(s, -1, -1): if dp[i][j] == 0: continue if j + item <= s: dp[i+1][j+item] += dp[i][j] dp[i+1][j] += dp[i][j] * 2 dp[i+1][j] %= MOD print(dp[-1][-1] % MOD)
1
17,603,634,760,228
null
138
138
# -*- coding: utf-8 -*- H, N = map(int, input().split(' ')) nums = [float('inf') for _ in range(H+1)] nums[0] = 0 for _ in range(N): a, b = map(int, input().split(' ')) for i in range(H + 1): j = min(H, i+a) nums[j] = min(nums[j], nums[i] + b) print(nums[H])
h,n=map(int,input().split()) A=[] B=[] for i in range(n): a,b=map(int,input().split()) A.append(a) B.append(b) dp=[10**10 for i in range(h+1)] dp[h]=0 for i in reversed(range(1,h+1)): for j in range(n): if i-A[j]>=0: dp[i-A[j]]=min(dp[i-A[j]],dp[i]+B[j]) else: dp[0]=min(dp[0],dp[i]+B[j]) print(dp[0])
1
81,220,359,735,120
null
229
229
def gcd(a,b): # assume a,b are +ve integers. if a>b: a,b = b,a if b%a==0: return a return gcd(a,b%a) print(360//(gcd(360,int(input()))))
sentence = input().lower() ans = input().lower() doublesentence = sentence + sentence print("Yes" if ans in doublesentence else "No")
0
null
7,475,016,463,798
125
64
n = int(input()) ans = ['a'] # 最初の一文字は'a'で固定 for i in range(n-1): # 'a'に'n-1'文字分ループで足す tmp = [] # リセット for j in ans: l = len(set(j)) # 'j'の使用文字種の数をカウント for k in range(l+1): # 'j'の使用文字種の数 '+1'回ループして... tmp.append(j + chr(ord('a') + k)) # 'j'に appendする ans = tmp[:] # 'ans'を書き換える for i in ans: print(i)
def A(): n, x, t = map(int, input().split()) print(t * ((n+x-1)//x)) def B(): n = list(input()) s = 0 for e in n: s += int(e) print("Yes" if s % 9 == 0 else "No") def C(): int(input()) a = list(map(int, input().split())) l = 0 ans = 0 for e in a: if e < l: ans += l - e l = max(l, e) print(ans) A()
0
null
28,237,785,866,940
198
86
import math r=float(input()) print('%f %f' %(math.pi*r*r, 2*math.pi*r))
r = float(input()) pi = 3.141592653589793 print(pi*r**2, 2*pi*r)
1
645,516,567,498
null
46
46
from sys import stdin, setrecursionlimit def main(): input = stdin.buffer.readline l = int(input()) print((l / 3) ** 3) if __name__ == "__main__": setrecursionlimit(10000) main()
n,m,k=map(int, input().split( )) mod = 998244353 ans=0 if m==1:##コーナー print(1 if k==n-1 else 0) exit() tmp=m*pow(m-1,n-1,mod) m_inv=pow(m-1,mod-2,mod) invs=[0]+[pow(i+1,mod-2,mod) for i in range(n)] for i in range(1,k+2): ans+=tmp #print(ans) tmp*=m_inv if i<n:##? tmp*=n-i tmp*=invs[i] tmp%=mod print(ans%mod)
0
null
35,024,331,392,058
191
151
def main(): A, B, C, K = map(int, input().split()) result = A if K >= A else K K -= A if K <= 0: print(result) return K -= B if K <= 0: print(result) return result -= K print(result) main()
from sys import exit A, B, C, K = [int(x) for x in input().split()] if A + B >= K: print(min(A, K)) exit() print(A - (K - (A + B)))
1
21,842,205,899,430
null
148
148
N=int(input()) def num_divisors_table(n): table=[0]*(n+1) for i in range(1,n+1): for j in range(i,n+1,i): table[j]+=1 return table l=num_divisors_table(N-1) print(sum(l))
import sys sys.setrecursionlimit(2147483647) INF = 1 << 60 MOD = 10**9 + 7 # 998244353 input = lambda:sys.stdin.readline().rstrip() class modfact(object): def __init__(self, n): fact, invfact = [1] * (n + 1), [1] * (n + 1) for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD invfact[n] = pow(fact[n], MOD - 2, MOD) for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD self._fact, self._invfact = fact, invfact def inv(self, n): return self._fact[n - 1] * self._invfact[n] % MOD def fact(self, n): return self._fact[n] def invfact(self, n): return self._invfact[n] def comb(self, n, k): if k < 0 or n < k: return 0 return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD def perm(self, n, k): if k < 0 or n < k: return 0 return self._fact[n] * self._invfact[n - k] % MOD def resolve(): n, k = map(int, input().split()) mf = modfact(n) res = 0 for i in range(min(k + 1, n)): res += mf.comb(n, i) * mf.comb(n - 1, i) % MOD res %= MOD print(res) resolve()
0
null
35,009,509,000,816
73
215
import collections N = int(input()) S = input() S_list = [S[i] for i in range(N)] S_c = collections.Counter(S_list) list12 = [] list1 = [] ans = 0 for i in range(N-2): s1 = S_list[i] S_c[s1] = S_c[s1]-1 if s1 in list1: continue S_c23 = S_c.copy() list1.append(s1) for j in range(i+1,N-1): s2 = S_list[j] S_c23[s2] = S_c23[s2] - 1 if (s1+s2) in list12: continue else: list12.append(s1+s2) for key in S_c23.keys(): if S_c23[key] != 0: ans+=1 print(ans)
a=list(input().split()) b=set(a) if len(b) == 2: print('Yes') else: print('No')
0
null
98,520,060,858,648
267
216
n = int(input()) s = 0 q = int(n ** .5) for i in range(1, q+1): x = n // i s += i * (x * (x+1)) / 2 if x**2 != n: y = max(n // (i+1), q) s += (i * (i+1) // 2) * ((x * (x+1) // 2) - (y * (y+1) // 2)) print(int(s))
h,w = map(int,input().split()) s = [input() for _ in range(h)] dp = [[float('inf')]*w for i in range(h)] dp[0][0] = 1 if s[0][0]=='#' else 0 for x in range(h): for y in range(w): if x+1<h: a = 1 if s[x][y]=='.' and s[x+1][y]=='#' else 0 dp[x+1][y] = min(dp[x][y]+a,dp[x+1][y]) if y+1<w: a = 1 if s[x][y]=='.' and s[x][y+1]=='#' else 0 dp[x][y+1] = min(dp[x][y]+a,dp[x][y+1]) print(dp[h-1][w-1])
0
null
29,956,328,427,462
118
194
input_line = set([]) input_line.add(int(input())) input_line.add(int(input())) for i in range(1,4): if i not in input_line: print(i)
import sys n = int( sys.stdin.readline() ) nums = sys.stdin.readline().rstrip().split( " " ) nums.reverse() print( " ".join( nums ) )
0
null
55,699,335,331,640
254
53
from collections import * from heapq import * import sys input=lambda :sys.stdin.readline().rstrip() N=int(input()) A=list(map(int,input().split())) mod=10**9+7 count=1 lst=[0,0,0] for a in A: data=[i for i in range(3) if lst[i] == a] if not data: count=0 break count*=len(data) count%=mod i=data[0] lst[i]+=1 print(count)
h1, m1, h2, m2, K = map(int, input().split()) h = h2-(h1+1) m = m2+60-m1 m += 60*h m -= K print(m)
0
null
74,496,619,782,590
268
139
N=int(input()) S=input() cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B') ans=cntR*cntG*cntB for i in range(N-2): for j in range(i+1,N-1): if S[i]!=S[j]: k=2*j-i if k<N and S[k]!=S[i] and S[k]!=S[j]: ans-=1 print(ans)
N = int(input()) S = input() ans = S.count("R")*S.count("G")*S.count("B") for i in range(N): for j in range(i+1,N): k = 2*j-i if k<N and S[i]!=S[j]!=S[k]!=S[i]: ans-=1 print(ans)
1
35,893,315,354,850
null
175
175
import math (a,b,C) = [int(i) for i in input().split()] c = math.sqrt(a ** 2 + b ** 2 - (2 * a * b) * math.cos(C * math.pi / 180)) h = float(b * math.sin(C * math.pi / 180)) s = float(a * h / 2) l = float(a + b + c) print(s) print(l) print(h)
def GCD(x, y): if y == 0: return x return GCD(y, x % y) N, M = map(int, input().split()) A = list(map(int, input().split())) A = sorted(set(A)) check = set() for a in A: cnt = 0 while a % 2 == 0: cnt += 1 a //= 2 check.add(cnt) if len(check) > 1: print(0) exit() LCM = 1 for a in A: gcd = GCD(LCM, a // 2) LCM = LCM * (a // 2) // gcd ans = (M - LCM) // (2 * LCM) + 1 print(ans)
0
null
51,001,952,444,928
30
247
import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) n, u, v = map(int, input().split()) GRAPH = {i:[] for i in range(1, n + 1)} for _ in range(n - 1): a, b = map(int, input().split()) GRAPH[a].append(b) GRAPH[b].append(a) def dfs(now, prev = 0): PARENT[now] = prev DEPTH[now] = DEPTH[prev] + 1 if len(GRAPH[now]) == 1: LEAVES.append((DEPTH[now], now)) for w in GRAPH[now]: if w == prev: continue next = w dfs(next, now) PARENT = {} DEPTH = {0:-1} LEAVES = [] dfs(v) PATH = {i:False for i in range(1, n + 1)} now = u while True: PATH[now] = True if now == v: break now = PARENT[now] LEAVES.sort(reverse = True) for leaf in LEAVES: now = leaf[1] while True: if PATH[now]: break now = PARENT[now] lca = now du, dv = DEPTH[u] - DEPTH[lca], DEPTH[lca] if du < dv: print(leaf[0] - 1) exit()
N,u,v = map(int, input().split()) G=[[] for i in range(N)] for i in range(N-1): s,t = map(int, input().split()) G[s-1].append(t-1) G[t-1].append(s-1) def expro(u): D=[0]*N D[u]=0 S=[] S.append(u) L=[] q=0 while(q<N): l=S[q] for i in range(len(G[l])): m=G[l][i] if(len(G[l])==1 and l!=u): L.append(l) if(D[m]==0 and m!=u): D[m]=D[l]+1 S.append(m) #S.remove(l) q+=1 return L,D L,D = expro(u-1) M,E = expro(v-1) k=0 ans=0 #print(G) #print(D) #print(L) for i in M: if D[i]<E[i]: if k<E[i]: k=E[i] ans=E[i]-1 print(ans)
1
117,365,150,833,720
null
259
259
N, K, C = map(int, input().split()) S = input() L, R = [], [] i = 0 while len(L) < K: if S[i] == "o": L.append(i) i += C+1 else: i += 1 i = N-1 while len(R) < K: if S[i] == "o": R.append(i) i -= C+1 else: i -= 1 R = R[::-1] for i in range(K): if L[i] == R[i]: print (L[i]+1)
print('pphbhhphph'[int(input()[-1])]+'on')
0
null
29,822,439,897,342
182
142
n, k = list(map(int, input().split())) mod = 1000000007 fac = [1] inv = [1] for i in range(n * 2): fac.append(fac[-1] * (i + 1) % mod) inv.append(pow(fac[-1], mod - 2, mod)) def cmb(n, k): if k < 0 or k > n: return 0 return ((fac[n] * inv[k]) % mod * inv[n - k]) % mod ret = 0 for m in range(min(k + 1, n)): ret = (ret + (cmb(n, m) * cmb(n - 1, n - m - 1)) % mod) % mod print(ret)
#coding:utf-8 class Combination: def __init__(self,N,P=10**9+7): if N > 10**7: self.fact = lambda x: x * self.fact(x-1) % P if x > 2 else 2 self.perm = lambda x, r: x * self.perm(x-1,r-1) % P if r > 0 else 1 self.cmb = lambda n,r: (self.perm(n,min(n-r,r)) * pow(self.fact(min(n-r,r)) ,P-2 ,P) % P) if r > 0 else 1 else: self.__fact = [1] * (N+1) self.__inv = [1] * (N+1) self.__inv_fact = [1] * (N+1) for i in range(2,N+1): self.__fact[i] = self.__fact[i-1] * i % P self.__inv[i] = - self.__inv[P%i] * (P//i) % P self.__inv_fact[i] = self.__inv_fact[i-1] * self.__inv[i] % P self.fact = lambda n: self.__fact[n] self.perm = lambda n,r: self.__fact[n] * self.__inv_fact[n-r] % P self.cmb = lambda n,r: (self.__fact[n] * self.__inv_fact[n-r] * self.__inv_fact[r] % P) if r > 0 else 1 import sys,os sys.setrecursionlimit(10**6) write = sys.stdout.write dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0 def main(given=sys.stdin.readline): input = lambda: given().rstrip() LMIIS = lambda: list(map(int,input().split())) II = lambda: int(input()) XLMIIS = lambda x: [LMIIS() for _ in range(x)] YN = lambda c : print('Yes') if c else print('No') MOD = 10**9+7 from collections import deque n,k = LMIIS() cmb = Combination(2*n) ans = 1 for i in range(1,min(n,k+1)): ans = (ans + cmb.cmb(n,i) * cmb.cmb(n-1,i)) % MOD print(ans) if __name__ == '__main__': main()
1
67,237,089,400,232
null
215
215
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N = input() s = 0 for i in range(len(N)): s += int(N[i]) if s%9 == 0: print('Yes') else: print('No') if __name__ == '__main__': main()
strN = input() s = 0 for c in strN: s += int(c) if s % 9 == 0: print("Yes") else: print("No")
1
4,402,202,013,312
null
87
87
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 from fractions import gcd 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() sign = [-1]*n pre = -1 for i in range(1,n): if a[i] > a[i - 1]: sign[i] = 1 pre = 1 elif a[i] < a[i - 1]: sign[i] = -1 pre = -1 else: sign[i] = pre money = 1000 stock = 0 for i in range(n): if sign[i] == 0 or (i != n-1 and sign[i] == sign[i + 1]): continue if sign[i] == 1: #売る money += a[i] * stock stock = 0 elif sign[i] == -1: flg = False if [j for j in sign[i:] if j == 1]: flg = True #買う if flg == True: buy = money // a[i] stock += buy money -= a[i] * buy print(money)
input() A=list(map(int,input().split())) M=[0,1000] for i in range(0,len(A)-1): if A[i]>A[i+1]: M[1]+=A[i]*M[0] M[0]=0 elif A[i]<A[i+1]: M[0]+=int(M[1]/A[i]) M[1]=M[1]%A[i] M[1]+=A[i+1]*M[0] M[0]=0 print(M[1])
1
7,303,848,196,772
null
103
103
n, d = map(int, input().split()) s = 0 for i in range(n): a, b = map(int, input().split()) if (a ** 2 + b ** 2) ** 0.5 <= d: s += 1 print(s)
import math n = int(input()) i = 1 tmp = n-1 while i <= math.sqrt(n): if n%i == 0: j = n//i if i + j < tmp: tmp = i + j -2 else: pass else: pass i += 1 print(tmp)
0
null
83,505,112,429,496
96
288
n = int(input()) p = list(map(int, input().split())) ans = 0 min_p = n for i in p: if i <= min_p: min_p = i ans += 1 print(ans)
n=int(input()) p=list(map(int,input().split())) min_val=10**18 ans=0 for i in range(n): if i==0: min_val=p[i] ans+=1 continue if min_val>=p[i]: min_val=p[i] ans+=1 print(ans)
1
85,420,588,721,540
null
233
233
data = [int(i) for i in input().split()] print(f'{data[0] * data[1]} {data[0] * 2 + data[1] * 2}')
(a,b) = map(int,raw_input().split()) print '%d %d' %(a*b,(a+b)*2)
1
307,174,248,990
null
36
36
H = int(input()) import math def caracal(H): if H == 1: return 1 return 2*caracal(math.floor(H/2)) + 1 print(caracal(H))
n=int(input()) a=0 b=0 while n!=0: n=n//2 a+=2**b b+=1 print(a)
1
79,810,695,666,970
null
228
228
import sys input = sys.stdin.readline x, y = [int(x) for x in input().split()] ans = 0 for i in [x, y]: if i == 1: ans += 300000 elif i == 2: ans += 200000 elif i == 3: ans += 100000 if x == 1 and y == 1: ans += 400000 print(ans)
x, y=map(int, input().split()) s=0 if (x==3): s+=100000 if (x==2): s+=200000 if (x==1): s+=300000 if (y==3): s+=100000 if (y==2): s+=200000 if (y==1): s+=300000 if (s==600000): s+=400000 print(s)
1
140,302,354,951,980
null
275
275
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)
n, a, b = map(int,input().split()) tmp = abs(a-b) if tmp%2 == 0: print(tmp//2) else: x = a-1 y = n-b print(min(x,y)+1+((b-a-1)//2))
1
109,368,039,772,940
null
253
253
a=int(input()) b=[input() for i in range(a)] c=0 d=0 e=0 f=0 for i in range(a): if b[i]=="AC": c=c+1 if b[i]=="WA": d=d+1 if b[i]=="TLE": e=e+1 if b[i]=="RE": f=f+1 print("AC","x",c) print("WA","x",d) print("TLE","x",e) print("RE","x",f)
input() P=map(int,input().split()) ans,mn=0,2*10**5 for x in P: if mn>=x: ans+=1; mn=x print(ans)
0
null
47,016,106,255,448
109
233
import sys def calc_cell(x, y): return '.' if (x + y) % 2 else '#' def print_chessboard(height, width): for y in range(height): l = [] for x in range(width): l.append(calc_cell(x, y)) print ''.join(l) if __name__ == '__main__': while True: h, w = map(int, sys.stdin.readline().split()) print_chessboard(h, w) if not h or not w: break print
A = [] b = [] row, col = (int(x) for x in input().split()) for i in range(row): A.append([int(x) for x in input().split()]) for i in range(col): b.append(int(input())) for i in range(row): print(sum(A[i][j]*b[j] for j in range(col)))
0
null
1,028,180,953,670
51
56
n = input() A=[int(j) for j in input().split()] nums = [0,0,0] ans = 1 for a in A: ans = (ans*nums.count(a))%(10**9 +7) for i in range(len(nums)): if nums[i] == a: nums[i] = a+1 break print(ans)
#!/usr/bin/env python3 def main(): h,w,k = map(int, input().split()) s = [input() for i in range(h)] l = [[0]*w for i in range(h)] from collections import deque d = deque() c = 1 for i in range(h): for j in range(w): if s[i][j] == '#': d.append([i, j]) l[i][j] = c c += 1 while len(d) > 0: x,y = d.pop() c = l[x][y] l[x][y] = c f1 = True f2 = True for i in range(1,w): if y+i < w and l[x][y+i] == 0 and s[x][y+i] != '#' and f1: l[x][y+i] = c else: f1 = False if 0 <= y-i and l[x][y-i] == 0 and s[x][y-i] != '#' and f2: l[x][y-i] = c else: f2 = False for i in range(h): if all(l[i]) == 0: k1 = 1 while 0 < i+k1 < h and all(l[i+k1]) == 0: k1 += 1 # print("test: ", i, k1) if i+k1 < h: for j in range(i, i+k1): for r in range(w): l[j][r] = l[i+k1][r] for i in range(h-1, -1, -1): if all(l[i]) == 0: k1 = 1 while 0 < i-k1 < h and all(l[i-k1]) == 0: k1 += 1 # print("test: ", i, k1) if 0 <= i-k1 < h: for j in range(i, i-k1, -1): for r in range(w): l[j][r] = l[i-k1][r] for i in range(h): print(' '.join(map(str, l[i]))) if __name__ == '__main__': main()
0
null
137,252,417,071,360
268
277
a,b,c=map(int,input().split()) import math d=math.radians(c) S=a*b*math.sin(d)*(1/2) e=math.cos(d) x=a**2+b**2-2*a*b*e L=a+b+math.sqrt(x) h=2*S/a print('{:.6f}'.format(S)) print('{:.6f}'.format(L)) print('{:.6f}'.format(h))
import math a,b,c = map(float,input().split()) rad = math.radians(c) x = (a**2+b**2-2*a*b*math.cos(rad))**(1/2) L = a+b+x S = a*b*math.sin(rad)/2 h = 2*S/a print("{:.8f}\n{:.8f}\n{:.8f}".format(S,L,h))
1
174,950,267,510
null
30
30
# -*- coding: utf-8 -*- n = int(raw_input()) dic = set() for i in range(n): com, s = map(str, raw_input().split()) if com == "insert": dic.add(s) elif com == "find": if s in dic: print "yes" else: print "no"
h, w, k = map(int, input().split()) c = [list(input()) for i in range(h)] ans = 0 for i in range(1 << h): for j in range(1 << w): black = 0 for x in range(h): for y in range(w): if (i >> x) & 1: continue if (j >> y) & 1: continue if c[x][y] == '#': black += 1 if black == k: ans += 1 print(ans)
0
null
4,558,199,453,262
23
110
import collections N, X, Y = [int(x) for x in input().split()] c = collections.Counter() for i in range(1, N + 1): for j in range(i, N + 1): if (i == X and j == Y) or (i == Y and j == X): c[1] += 1 else: c[min([j - i, abs(X - i) + 1 + abs(Y - j), abs(X - j) + 1 + abs(Y - i)])] += 1 for i in range(1, N): print(c[i])
N,X,Y =map(int,input().split()) count = [0] * (N-1) for i in range(1,N): path = abs(X-i) +1 for j in range(i+1,N+1): dist = min(j-i, path+abs(Y-j)) count[dist-1] +=1 print(*count, sep="\n")
1
44,081,272,680,550
null
187
187
N = int(input()) amount = 0 for i in range(1, N + 1): if (i % 15 == 0) or (i % 3 == 0) or (i % 5 == 0): pass else: amount = amount + i print(amount)
def main(): n = int(input()) ans = 0 for i in range(1, n + 1): if (i % 3 != 0) and (i % 5 != 0): ans += i print(ans) main()
1
34,945,575,854,882
null
173
173
def abc160c_traveling_salesman_around_lake(): k, n = map(int, input().split()) a = list(map(int, input().split())) total = 0 max_distance = 0 for i in range(n - 1): total += a[i + 1] - a[i] max_distance = max(max_distance, a[i + 1] - a[i]) total += k - a[n - 1] + a[0] max_distance = max(max_distance, k - a[n - 1] + a[0]) print(total-max_distance) abc160c_traveling_salesman_around_lake()
K,N=map(int,input().split()) lis=list(map(int,input().split())) dt=[lis[i+1]-lis[i] for i in range(N-1)]+[lis[0]+(K-lis[-1])] print(K-max(dt))
1
43,321,029,550,888
null
186
186
import numpy as np N = int(input()) X = str(input()) num_one = X.count("1") dp = [-1] * N dp[0] = 0 def dfs(n): if dp[n] == -1: dp[n] = 1 + dfs(n % bin(n).count('1')) return dp[n] num_one = X.count("1") bool_arr = np.array([True if X[N-i-1] == "1" else False for i in range(N)]) zero_ver = np.array([pow(2, i, num_one + 1) for i in range(N)]) zero_ver_sum = sum(zero_ver[bool_arr]) one_ver = -1 one_ver_sum = 0 flag = False if num_one != 1: one_ver = np.array([pow(2, i, num_one - 1) for i in range(N)]) one_ver_sum = sum(one_ver[bool_arr]) else: flag = True for i in range(1,N+1): start = 0 if bool_arr[N-i] == False: start = (zero_ver_sum + pow(2, N - i, num_one + 1)) % (num_one + 1) print(dfs(start)+1) else: if flag: print(0) else: start = (one_ver_sum - pow(2, N - i, num_one - 1)) % (num_one - 1) print(dfs(start)+1)
X=int(input()) ans=1000*(X//500)+5*((X-(X//500*500))//5) print(ans)
0
null
25,395,280,560,430
107
185
import sys from functools import reduce from math import gcd read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines mod = 10 ** 9 + 7 N = int(readline()) A = list(map(int,readline().split())) lcm = reduce(lambda x,y:x*y//gcd(x,y),A) ans = 0 ans = sum(lcm//x for x in A) print(ans%mod)
def factorize(n): tmp = n for i in range(2, int(n**0.5)+1): if tmp % i == 0: cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if i in fact: fact[i] = max(fact[i],cnt) else: fact[i] = cnt if tmp != 1: if tmp in fact: fact[tmp] = max(fact[tmp],1) else: fact[tmp] = 1 if len(fact) == 0: if N in fact: fact[N] = max(fact[N],1) else: fact[N] = 1 def inv(n, p): return pow(n, p-2, p) N = int(input()) A = list(map(int, input().split())) p = 10**9+7 fact = {} for i in range(N): if A[i] != 1: factorize(A[i]) lcm = 1 for key, val in fact.items(): lcm *= pow(key, val, p) lcm %= p inv_sum = 0 for i in range(N): inv_sum += inv(A[i], p) inv_sum %= p print(lcm * inv_sum % p)
1
87,720,118,352,020
null
235
235
n,K = map(int, input().split()) mod = 10**9 + 7 def modcomb(n,a,mod): cnt = 1 for i in range(a): cnt *= (n-i) cnt *= pow(i+1,mod-2,mod) cnt %= mod # print(cnt) return cnt def modconb(n,mod): # テーブルを作る fac = [0]*(n+1) finv = [0]*(n+1) inv = [0]*(n+1) fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2,n+1): fac[i] = fac[i-1]*i % mod inv[i] = mod - inv[mod%i] * (mod//i) % mod finv[i] = finv[i-1] * inv[i] %mod return fac,finv # return(fac[n]*(finv[k]*finv[n-k]%mod)%mod) cnt = 0 if n-1 >= K: fac1,finv1 = modconb(n,mod) for k in range(K+1): c1 = fac1[n]*(finv1[k]*finv1[n-k]%mod)%mod c2 = fac1[n-1]*(finv1[k]*finv1[n-1-k]%mod)%mod cnt += c1*c2 cnt %= mod print(cnt%mod) else: cnt1 = modcomb(2*(n-1),n-1,mod) cnt2 = modcomb(2*(n-1),n,mod) ans = (cnt1+cnt2)%mod print(ans)
a,b = map(int, input().split()) d = a/b r = a%b print('%d %d %f' % (d,r,d))
0
null
33,803,779,436,448
215
45
from collections import deque q=deque() n=int(input()) for i in range(n): cmd=input() if cmd=="deleteFirst": try: q.popleft() except: pass elif cmd=="deleteLast": try: q.pop() except: pass else: cmd,number=cmd.split() if cmd=="delete": try: q.remove(number) except: pass elif cmd=="insert": q.appendleft(number) print(*q)
if __name__ == "__main__": S = input() list_s = [s for s in S] ans = 0 if list_s[0] == 'S' and list_s[1] == 'S' and list_s[2] == 'S': ans = 0 elif list_s[0] == 'S' and list_s[1] == 'S' and list_s[2] == 'R': ans = 1 elif list_s[0] == 'S' and list_s[1] == 'R' and list_s[2] == 'R': ans = 2 elif list_s[0] == 'R' and list_s[1] == 'R' and list_s[2] == 'R': ans = 3 elif list_s[0] == 'R' and list_s[1] == 'S' and list_s[2] == 'R': ans = 1 elif list_s[0] == 'R' and list_s[1] == 'R' and list_s[2] == 'S': ans = 2 elif list_s[0] == 'R' and list_s[1] == 'S' and list_s[2] == 'S': ans = 1 elif list_s[0] == 'S' and list_s[1] == 'R' and list_s[2] == 'S': ans = 1 print(ans)
0
null
2,475,239,647,090
20
90