code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
X = int(input()) Y = X//200 print(10-Y)
c = input() a = ord(c) a += 1 print(chr(a))
0
null
49,428,375,631,040
100
239
n = int(input()) data = list(map(int, input().split())) def insertion_sort(A, N): print(*A) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(*A) insertion_sort(data, n)
size = int(input()) element = list(map(int,input().split())) print(" ".join(map(str,element))) for i in range(1,len(element)): v = element[i] j = i-1 while j >=0 and element[j] > v: element[j+1] = element[j] j -=1 element[j+1] = v print(" ".join(map(str,element)))
1
5,631,258,670
null
10
10
a = list(map(int, input().split())) print('un' * (a[0] <= a[1]) + 'safe')
def main(): sw = list(map(int, input().split())) print('unsafe' if sw[0] <= sw[1] else 'safe') if __name__ == '__main__': main()
1
29,187,797,806,750
null
163
163
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)
S,T = input().split() a,b = map(int,input().split()) u = input() if u == S: a -= 1 elif u ==T: b -= 1 print("{} {}".format(a,b))
0
null
69,320,767,464,138
215
220
N = input() K = int(input()) L = len(N) dp = [[[0 for j in range(L + 10)] for i in range(L + 10)] for _ in range(2)] dp[0][0][0] = 1 for i in range(L): Ni = int(N[i]) for j in range(L): if Ni == 0: dp[0][i + 1][j + 0] += dp[0][i][j + 0] * 1 dp[0][i + 1][j + 1] += dp[0][i][j + 0] * 0 dp[1][i + 1][j + 0] += dp[0][i][j + 0] * 0 + dp[1][i][j + 0] * 1 dp[1][i + 1][j + 1] += dp[0][i][j + 0] * 0 + dp[1][i][j + 0] * 9 else: dp[0][i + 1][j + 0] += dp[0][i][j + 0] * 0 dp[0][i + 1][j + 1] += dp[0][i][j + 0] * 1 dp[1][i + 1][j + 0] += dp[0][i][j + 0] * 1 + dp[1][i][j + 0] * 1 dp[1][i + 1][j + 1] += dp[0][i][j + 0] * (Ni - 1) + dp[1][i][j + 0] * 9 #print(dp[0]) #print(dp[1]) print(dp[0][L][K] + dp[1][L][K])
n = list(map(int, list(input()))) k = int(input()) dp = [[0,0,0] for _ in range(len(n))] counter = 0 for i in range(len(n)): dp[i][0] += dp[i-1][0] + 9*(counter > 0) dp[i][1] += dp[i-1][0]*9 + dp[i-1][1] dp[i][2] += dp[i-1][1]*9 + dp[i-1][2] if n[i] > 0: if counter >= 1 and counter <= 3: dp[i][counter-1] += 1 counter += 1 if counter <= 3: dp[i][counter-1] += n[i]-1 print(dp[len(n)-1][k-1]+(counter==k))
1
76,310,662,914,112
null
224
224
N = int(input()) A = list(map(int, input().split())) dp = [0]*(N) dp[0] = 1000 for i in range(1,N): dp[i] = dp[i-1] for j in range(i): dp[i] = max(dp[i], (dp[j]//A[j])*A[i]+dp[j]%A[j]) ans = 0 for i in range(N): ans = max(ans, dp[i]) print(ans)
import sys input = sys.stdin.readline INF = 10**18 def li(): return [int(x) for x in input().split()] N = int(input()) A = [INF] + li() M = 1000 K = 0 for i in range(1,N+1): if i == N: sell_cnt = K K = 0 M += sell_cnt * A[i] break if A[i+1] > A[i] and A[i] <= A[i-1]: buy_cnt = M // A[i] K += buy_cnt M -= buy_cnt * A[i] elif A[i+1] < A[i] and A[i] >= A[i-1]: sell_cnt = K K = 0 M += sell_cnt * A[i] print(M)
1
7,394,568,559,462
null
103
103
num_a = [1, 2, 3, 4, 5, 6, 7, 8, 9] for i in num_a: for j in num_a: print(i, 'x', j, '=', i*j, sep='')
for a in [1,2,3,4,5,6,7,8,9]: for b in [1,2,3,4,5,6,7,8,9]: print ("{0}x{1}={2}".format(a,b,a*b))
1
20,210
null
1
1
N=int(input()) list1 = list(map(int, input().split())) list2=[] for i in list1: if i%2==0: list2.append(i) else: continue list3=[] for j in list2: if j%3==0 or j%5==0: list3.append(j) else: continue x=len(list2) y=len(list3) if x==y: print('APPROVED') else: print('DENIED')
A,B,C,K=map(int,input().split()) if A>=K: print(K) elif B>=K-A: print(A) else: print(A-1*(K-A-B))
0
null
45,409,598,498,368
217
148
import itertools def main(): N = int(input()) n_x_y = {} for n in range(N): A = int(input()) x_y = {} for _ in range(A): x, y = map(int, input().split()) x_y[x-1] = y n_x_y[n] = x_y ans = 0 for flags in itertools.product([1, 0], repeat=N): sat = True for n, flag in enumerate(flags): if flag == 0: continue for x, y in n_x_y[n].items(): if (y == 1 and flags[x] == 0) or (y == 0 and flags[x] == 1): sat = False break if sat is False: break if sat is True and sum(flags) > ans: ans = sum(flags) print(ans) if __name__ == '__main__': main()
def main(): N = int(input()) shougen = [] for _ in range(N): A = int(input()) shougen.append([list(map(int, input().split())) for _ in range(A)]) ans = 0 for i in range(2**N): state = [1]*N for j in range(N): if (i >> j) & 1: state[j] = 0 flag = True for k in range(N): if not flag: break if state[k] == 1: for ele in shougen[k]: if state[ele[0]-1] != ele[1]: flag = False break if flag: ans = max(ans, sum(state)) print(ans) if __name__ == '__main__': main()
1
121,443,651,104,090
null
262
262
S=input() if(S[0]==S[1] and S[1]==S[2]): print("No") else: print("Yes")
s = list(input()) s = list(set(s)) print('Yes') if len(s) >1 else print('No')
1
54,490,175,832,752
null
201
201
K = int(input()) for i in range(0, K): print("ACL", end="")
from collections import Counter n,p = map(int,input().split()) S = input() dp = [0] mod = p if p==2: ans =0 for i in reversed(range(n)): if int(S[i])%2==0: ans += i+1 print(ans);exit() elif p==5: ans =0 for i in reversed(range(n)): if int(S[i])%5==0: ans += i+1 print(ans);exit() for i in reversed(range(n)): dp.append(dp[-1]%mod + pow(10,n-1-i,mod)*int(S[i])) dp[-1]%=mod count = Counter(dp) ans = 0 for key,val in count.items(): if val>=2: ans += val*(val-1)//2 print(ans)
0
null
30,142,236,794,798
69
205
''' Rjの最小値を保持することで最大利益の更新判定をn回で終わらせる ''' r = [] n = int(input()) for i in range(n): i = int(input()) r.append(i) minv = r[0] maxv = r[1] - r[0] for j in range(1,n): maxv = max(maxv, r[j]-minv) minv = min(minv, r[j]) print(maxv)
#! /usr/local/bin/python3 # coding: utf-8 n = int(input()) min_r = int(input()) max_margin = -1000000001 for i in range(n - 1): r = int(input()) max_margin = max(r - min_r, max_margin) min_r = min(r, min_r) print(max_margin)
1
12,734,308,898
null
13
13
S = raw_input().split(" ") for i in range(0, len(S)): S[i] = int(S[i]) primeNum = 0 for i in range(S[0], S[1]+1): if(S[2] % i == 0): primeNum = primeNum+1 print(primeNum)
A = [[[0 for i in range(10)] for i in range(3)] for i in range(4)] info = int(input()) for i in range(info): b,f,r,v = [int(i) for i in input().split()] A[b-1][f-1][r-1] += v if A[b-1][f-1][r-1] < 0: A[b-1][f-1][r-1] = 0 elif A[b-1][f-1][r-1] > 9: A[b-1][f-1][r-1] = 9 for i in range(3): print(' '+' '.join([str(i) for i in A[0][i]])) print('#'*20) for i in range(3): print(' '+' '.join([str(i) for i in A[1][i]])) print('#'*20) for i in range(3): print(' '+' '.join([str(i) for i in A[2][i]])) print('#'*20) for i in range(3): print(' '+' '.join([str(i) for i in A[3][i]]))
0
null
822,052,797,280
44
55
# ?????????????????????????? # ケース12と13、完全にバグとしか思えないのですが????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? # もしかして:頂点1は必ず0? n = int(input()) a = list(map(int, input().split())) if a[0] != 0: print(0) exit() a = sorted(a) d = {} for av in a: if av not in d: d[av] = 1 else: d[av] += 1 if d[0] != 1: print(0) exit() MOD = 998244353 ans = 1 for i in range(1, a[-1] + 1): if i not in d: ans = 0 break ans *= pow(d[i - 1], d[i], MOD) print(ans % MOD)
n = int(input()) s = input() t = s[:len(s)//2] if 2*t == s: print("Yes") else: print("No")
0
null
150,778,555,568,672
284
279
n,p=map(int,input().split()) s=input() if p==2 or p==5: a=0 for i in range(n): if int(s[i])%p==0: a+=i+1 print(a) else: a=0 g=[0]*(n+1) t=[0]*p t[0]=1 d=1 for i in range(n-1,-1,-1): g[i]=(g[i+1]+int(s[i])*d)%p a+=t[g[i]] t[g[i]]+=1 d*=10 d%=p print(a)
from collections import deque n, k = map(int, input().split()) a = [-1] + list(map(int, input().split())) town = [-1] * (n + 1) town[1] = 0 now_town = 1 second_first = 0 while True: if town[a[now_town]] != -1: second_first = a[now_town] break town[a[now_town]] = town[now_town] + 1 if town[a[now_town]] == k: print(a[now_town]) exit() now_town = a[now_town] # print(town) start_index = town[second_first] end_index = max(town) rest = k - end_index div = (rest-1) % (end_index - start_index + 1) # print(rest, div) ans = town.index((start_index) + div) print(ans)
0
null
40,523,971,978,122
205
150
n = int(input()) A = list(map(int, input().split())) freq = [0] * (max(A)+1) for a in A: freq[a] += 1 total = 0 for f in freq: total += f*(f-1)//2 for a in A: print (total - max(freq[a]-1, 0))
def solve(): import collections N = int(input()) A = [int(i) for i in input().split()] counter = collections.Counter(A) combis = {} total = 0 for k,v in counter.items(): combi = v * (v-1) // 2 combis[k] = combi total += combi for i in range(N): cnt = counter[A[i]] if cnt > 1: combi = (cnt-1) * (cnt-2) // 2 else: combi = 0 print(total - combis[A[i]] + combi) if __name__ == "__main__": solve()
1
47,517,464,557,280
null
192
192
A=[] fp =0 bp =0 n=int(raw_input()) while n: s = raw_input() if s[0] == 'i': A.append(int(s[7:])) fp += 1 elif s[6] == ' ': try: i = A[::-1].index(int(s[7:])) if i!=-1: del A[-i-1] fp -=1 except: pass elif s[6] == 'F': A.pop() fp -=1 elif s[6] == 'L': bp +=1 n -=1 for e in A[bp:fp+1][::-1]: print int(e),
import collections a = collections.deque() for i in range(int(input())): b = input() # 命令がinsertだった場合、 if b[0] == 'i': # キーxを先頭に追加(数字は文字列bの7文字目以降にある) a.appendleft(b[7:]) # 命令がdeleteだった場合 elif b[6] == ' ': # 命令のキーが含まれる場合そのキーのデータを消すが、なければ何もしない try: a.remove(b[7:]) except: pass # 命令がdeleteFirstだった場合 elif len(b) > 10: a.popleft() # 命令がdeleteLastだった場合 elif len(b) > 6: a.pop() print(*a)
1
49,491,741,828
null
20
20
import itertools N = int(input()) P = list(map(int, input().split())) Q = list(map(int, input().split())) a = [i for i in range(1,N+1)] cnt = 0 ans_a, ans_b = 0, 0 for target in itertools.permutations(a): cnt += 1 if list(target) == P: ans_a = cnt if list(target) == Q: ans_b = cnt print(abs(ans_a-ans_b))
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) n = INT() a = LIST() m = max(a) c = [0]*(m+1) for x in a: c[x] += 1 for i in range(1, m+1): if c[i] > 0: if c[i] > 1: c[i] = 0 j = i + i while j <= m: c[j] = 0 j += i ans = sum(c) print(ans)
0
null
57,670,264,703,898
246
129
N = int(input()) S = [int(i) for i in input().split()] q = int(input()) T = [int(i) for i in input().split()] count = 0 for t in T: S.append(t) i = 0 while t != S[i]: i += 1 if i != (len(S) - 1): count += 1 S.pop() print(count)
n = int(input()) S =input().split(" ") l =int(input()) T = input().split(" ") ans =0 for t in T: S.append(t) j =0 while S[j] !=t: j+=1 if j !=n: ans +=1 S=S[:-1] print(ans)
1
66,496,462,828
null
22
22
X = int(input()) item_num = X // 100 if item_num * 5 >= X - item_num * 100: print('1') else: print('0')
def main(): X = int(input()) if X < 100: print(0) elif 2000 <= X: print(1) else: a = X // 100 b = a * 5 if X % 100 <= b: print(1) else: print(0) if __name__ == '__main__': main()
1
126,589,215,221,390
null
266
266
date1 = input().split(" ") date2 = input().split(" ") if date1[0] != date2[0]: print("1") else: print("0")
M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) if M1 in [1, 3, 5, 7, 8, 10, 12]: if D1 == 31: print(1) else: print(0) elif M1 in [4, 6, 9, 11]: if D1 == 30: print(1) else: print(0) elif M1 == 2: if D1 == 28: print(1) else: print(0)
1
124,156,079,173,602
null
264
264
def main(): import sys readline = sys.stdin.buffer.readline n, x, y = map(int, readline().split()) l = [0] * (n-1) for i in range(1, n): for j in range(i+1, n+1): s = min(j-i, abs(x-i)+abs(j-y)+1) l[s-1] += 1 for i in l: print(i) main()
index=int(input()) alist=[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] index-=1 print(alist[index])
0
null
46,849,433,375,046
187
195
import heapq X, Y, A, B, C = map(int, input().split()) apples = [] for x in input().split(): apples.append((int(x), 'r')) for x in input().split(): apples.append((int(x), 'g')) for x in input().split(): apples.append((int(x), 'n')) apples.sort() apples.reverse() r_count = 0 g_count = 0 n_count = 0 yummy = 0 for _ in range(A+B+C): apple = apples[_] if apple[1] == 'g' and not g_count == Y: g_count += 1 yummy += apple[0] elif apple[1] == 'r' and not r_count == X: r_count += 1 yummy += apple[0] elif apple[1] == 'n': n_count += 1 yummy += apple[0] if g_count + r_count + n_count == X+Y: break print(yummy)
from sys import stdin def main(): x, y, a, b, c = map(int, stdin.readline().split()) p = list(map(int, stdin.readline().split())) q = list(map(int, stdin.readline().split())) r = list(map(int, stdin.readline().split())) pqr = [] for pi in p: pqr.append([pi, 0]) for qi in q: pqr.append([qi, 1]) for ri in r: pqr.append([ri, 2]) pqr.sort(reverse=True) ans = 0 c_a = 0 c_b = 0 c_c = 0 for pqri in pqr: if pqri[1] == 0 and c_a < x: ans += pqri[0] c_a += 1 elif pqri[1] == 1 and c_b < y: ans += pqri[0] c_b += 1 elif pqri[1] == 2 and (c_a < x or c_b < y) and c_a + c_b + c_c < x + y: ans += pqri[0] c_c += 1 if c_a + c_b + c_c == x + y: print(ans) exit() if __name__ == "__main__": main()
1
44,658,663,440,262
null
188
188
a,b,c=map(int,input().split()) if a>b: n=a a=b b=n else: pass if b>c: n=b b=c c=n else: pass if a>b: n=a a=b b=n else: pass print(a,b,c)
from collections import defaultdict def main(): N, P = list(map(int, input().split())) S = input() if P in [2, 5]: ans = 0 # P = 2, 5の時は一番下の位の数だけ見ればカウント可能 for right in range(N - 1, - 1, - 1): if int(S[right]) % P == 0: ans += right + 1 print(ans) return # 例:S = 3543, P = 3 # 左からn番目 ~ 1番右の数のmod Pの値を計算 # C = [3543, 543, 43, 3] % P = [0, 0, 1, 0] # C[m] == C[n] なる m < nのペア数 + C[n] == 0なるnの個数を求める # 3 + 3 = 6 cur_c = 0 C = [0] * N pw = 1 for n, s in enumerate(S[::-1]): cur_c = (cur_c + pw * int(s)) % P C[N - 1 - n] = cur_c pw = (pw * 10) % P counter = defaultdict(int) for c in C: counter[c] += 1 ans = 0 for c in C: counter[c] -= 1 ans += counter[c] ans += len([c for c in C if c == 0]) print(ans) if __name__ == '__main__': main()
0
null
29,467,666,122,048
40
205
N, K = map(int, input().split()) R, S, P = map(int, input().split()) T = input() divided_T = [[] for _ in range(K)] for i in range(N): divided_T[i%K].append(T[i]) ans = 0 for target in divided_T: dp = [[0]*3 for _ in range(len(target))] dp[0][0] = R if target[0] == 's' else 0 dp[0][1] = P if target[0] == 'r' else 0 dp[0][2] = S if target[0] == 'p' else 0 for i in range(1,len(target)): dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + (R if target[i] == 's' else 0) dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + (P if target[i] == 'r' else 0) dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + (S if target[i] == 'p' else 0) ans += max(dp[-1]) print(ans)
import math import sys # 比較回数をここに記録 # 理論上 n * lg n を越えることはない。 _exchange = 0 def merge_sort(A, left, right): """数列 A を in place に昇順にソートする。 left は A の先頭のインデックス、right は末尾のインデックスのひとつ後ろ。 """ if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): """ソート済みの部分列をマージする。 数列 A の left から mid - 1 の要素、mid から right - 1 までの 2つの部分列はソート済みである。これをマージして、left から right - 1 まで ソートする。 """ first = A[left:mid] first.append(math.inf) # 番兵 second = A[mid:right] second.append(math.inf) # 番兵 global _exchange i = j = 0 for k in range(left, right): _exchange += 1 if first[i] <= second[j]: A[k] = first[i] i += 1 else: A[k] = second[j] j += 1 if __name__ == '__main__': n = int(input()) A = list(map(int, sys.stdin.readline().split())) merge_sort(A, 0, n) print(*A) print(_exchange)
0
null
53,390,140,677,704
251
26
n = int(input()) c = 0 for i in range(1,n): if (i%2==1): c+=1 print("{0:.10f}".format(1-(c/n)))
n = int(input()) if n%2 == 0: print(1/2) else : print((n//2+1)/n)
1
177,224,466,169,570
null
297
297
input() A = [i for i in input().split()] A.reverse() print(' '.join(A))
input() a=list(map(int, input().split())) a.reverse() print(*a)
1
979,256,198,360
null
53
53
# AGC 043 A H,W = map(int, input().split()) table = [input() for _ in range(H)] inf = 10**9 dp = [[inf] * (W+1) for _ in range(H+1)] dp[0][0] = 0 if table[0][0] == "." else 1 for h in range(H): for w in range(W): flg = table[h][w] == "." and (table[h][w+1] == "#" if w < W-1 else True) dp[h][w+1] = min(dp[h][w+1], dp[h][w] + 1 if flg else dp[h][w]) flg = table[h][w] == "." and (table[h+1][w] == "#" if h < H-1 else True) dp[h+1][w] = dp[h][w] + 1 if flg else dp[h][w] print(dp[H-1][W-1])
h, w = map(int, input().split()) g = [[0] * w for _ in range(h)]#白が1、黒が0 for i in range(h): s = list(input()) for j in range(w): if s[j] == '.': g[i][j] = 1 INF = 10**9 dp = [[INF] * w for _ in range(h)] if g[0][0] == 0: dp[0][0] = 1 else: dp[0][0] = 0 for i in range(h): for j in range(w): for dx, dy in ((1, 0), (0, 1)): nx = j + dx ny = i + dy if ny >= h or nx >= w: continue add = 0 if g[ny][nx] == 0 and g[i][j] == 1: add = 1 dp[ny][nx] = min(dp[ny][nx], dp[i][j] + add) print(dp[h-1][w-1])
1
49,261,487,004,492
null
194
194
import sys from functools import lru_cache read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def com(n, r): if n < r or n < 0 or r < 0: return 0 r = min(r, n - r) numer = denom = 1 for i in range(n - r + 1, n + 1): numer = numer * i for i in range(1, r + 1): denom = denom * i return numer // denom def main(): N, K = map(int, read().split()) S = str(N) L = len(S) @lru_cache(maxsize=None) def rec(i, k, smaller): if i == L: if k == 0: return 1 else: return 0 if k == 0: return 1 if smaller: return com(L - i, k) * pow(9, k) if S[i] == '0': return rec(i + 1, k, False) ans = 0 ans += rec(i + 1, k, True) ans += rec(i + 1, k - 1, True) * (int(S[i]) - 1) ans += rec(i + 1, k - 1, False) return ans ans = rec(0, K, False) print(ans) return if __name__ == '__main__': main()
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = input() k = int(input()) # 桁DP def digit_DP(S, K): L = len(S) # dp[決定した桁数][未満フラグ][0以外の数字を使った個数] dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)] dp[0][0][0] = 1 for i in range(L): # 今見ている桁 D = int(S[i]) for j in range(2): # 未満フラグ(0 or 1) for k in range(4): # 0以外の数字を使った個数が0~3 for d in range(10 if j else D + 1): cnt = k if d != 0: cnt += 1 if cnt > K: continue dp[i + 1][j or (d < D)][cnt] += dp[i][j][k] return dp[L][0][K] + dp[L][1][K] print(digit_DP(n, k)) if __name__ == '__main__': resolve()
1
75,916,995,621,060
null
224
224
dice = map(int, raw_input().split()) inst = raw_input() def rolling(inst, dice): if inst == 'E': dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5] elif inst == 'W': dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5] elif inst == 'N': dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5] elif inst == 'S': dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5] for i in range(len(inst)): rolling(inst[i], dice) print dice[0]
import enum class Direction(enum.Enum): N = "N" E = "E" W = "W" S = "S" @classmethod def value_of(cls, value): return [v for v in cls if v.value == value][0] class Dice: def __init__(self, *value_list): self.__value_list = list(value_list) def rotate(self, direction): l = self.__value_list if direction == Direction.N: l[0],l[1],l[5],l[4] = l[1],l[5],l[4],l[0] elif direction == Direction.E: l[0],l[2],l[5],l[3] = l[3],l[0],l[2],l[5] elif direction == Direction.W: l[0],l[2],l[5],l[3] = l[2],l[5],l[3],l[0] elif direction == Direction.S: l[0],l[1],l[5],l[4] = l[4],l[0],l[1],l[5] def top_value(self): return self.__value_list[0] dice = Dice(*input().split()) for i in input(): dice.rotate(Direction.value_of(i)) print(dice.top_value())
1
228,680,068,648
null
33
33
import sys def solve(): a = [] for line in sys.stdin: a.append(int(line)) a.sort() a.reverse() for k in xrange(3): print a[k] if __name__ == '__main__': solve()
n = int(input()) print(- n % 1000)
0
null
4,172,529,898,288
2
108
# A - DDCC Finals def main(): X, Y = map(int, input().split()) prize_table = {1: 300000, 2: 200000, 3: 100000} prize = 0 for rank in (X, Y): if rank in prize_table: prize += prize_table[rank] if X == Y and X == 1: prize += 400000 print(prize) if __name__ == "__main__": main()
def resolve(): x,y=(int(i) for i in input().split()) if x==1 and y==1: print(1000000) return c=0 if x==1: c+=300000 if x==2: c+=200000 if x==3: c+=100000 if y==1: c+=300000 if y==2: c+=200000 if y==3: c+=100000 print(c) if __name__ == "__main__": resolve()
1
140,297,427,563,968
null
275
275
string = list(input()) times = int(input()) for i in range(times): order = input().split() if order[0] == "print": print("".join(string[int(order[1]):int(order[2]) + 1])) elif order[0] == "replace": string[int(order[1]):int(order[2]) + 1] = order[3] else: string[int(order[1]):int(order[2]) + 1] = list(reversed(string[int(order[1]):int(order[2]) + 1]))
#1st line input_str = input().strip() #2nd line command_max_times = int(input().strip()) command_cnt = 0 while command_cnt < command_max_times: command_cnt = command_cnt + 1 input_line = input().strip().split(" ") input_command = input_line[0] input_sta = int(input_line[1]) input_end = int(input_line[2]) if input_command == "print": print(input_str[input_sta:input_end+1]) elif input_command == "replace": str_replace = input_line[3] input_str = input_str[:input_sta] + str_replace + input_str[input_end+1:] elif input_command == "reverse": str_temp = input_str[input_sta:input_end+1] input_str = input_str[:input_sta] + str_temp[::-1] + input_str[input_end+1:]
1
2,075,025,619,248
null
68
68
N = int(input()) edge = [[] for _ in range(N)] for _ in range(N): l = list(map(int, input().split())) for j in range(l[1]): edge[l[0]-1].append(l[2+j]-1) now_list = [0] next_list = [] dist = 0 dists = [-1] * N while len(now_list) > 0: for _ in range(len(now_list)): v = now_list.pop() if dists[v] == -1: dists[v] = dist else: continue for nv in edge[v]: next_list.append(nv) now_list = next_list next_list = [] dist += 1 for i in range(N): print(1+i, dists[i])
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from math import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect import heapq # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 INF = float('inf') from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) H,W,M = readInts() dic1 = Counter() dic2 = Counter() s = set() for i in range(M): h,w = map(lambda x:int(x)-1, input().split()) dic1[h] += 1 dic2[w] += 1 s.add((h,w)) # print(dic) ans = 0 # 重なっているもので最大値がある時もあれば # 行、列の交差点でボムなしが一番大きいものがある for h,w in s: ans = max(ans, dic1[h] + dic2[w] - 1) dic1 = dic1.most_common() dic2 = dic2.most_common() max1 = dic1[0][1] max2 = dic2[0][1] for k1,v1 in dic1: if v1 < max1: break # continueする必要がない most_commonで大きい方から集めてるので for k2,v2 in dic2: if v2 < max2: break # 同じく if (k1,k2) in s: # 一度計算したもの continue # 両方とも最大であればok ans = max(ans, v1 + v2) break print(ans)
0
null
2,355,545,798,220
9
89
import datetime from sys import stdin h1, m1, h2, m2, k = [int(x) for x in stdin.readline().rstrip().split()] d1 = datetime.datetime(year=2018, month=1, day=7, hour=h1, minute=m1, second=0, microsecond=0) d2 = datetime.datetime(year=2018, month=1, day=7, hour=h2, minute=m2, second=0, microsecond=0) delta = d2 - d1 dt2 = delta.seconds / 60 dt2 -= k if dt2 < 0 : dt2 = 0 print(int(dt2))
a,b=[int(i) for i in input().split()] if(a%b==0): print(a//b) else: print((a//b)+1)
0
null
47,242,531,509,798
139
225
import sys input = sys.stdin.readline N = int(input()) AB = [tuple(map(int,input().split())) for i in range(N)] A = [] B = [] for a,b in AB: A.append(a) B.append(b) A.sort() B.sort() if N%2==0: m = N//2 b = B[m] + B[m-1] a = A[m] + A[m-1] print(b - a + 1) else: m = N//2 print(B[m] - A[m] + 1)
n=int(input()) alist=[] blist=[] for i in range(n): a,b=map(int,input().split()) alist.append(a) blist.append(b) alist.sort() blist.sort() if n%2==1: num1=-1*(n//-2)-1 print(blist[num1]-alist[num1]+1) else: num1=n//2-1 num2=num1+1 print((blist[num2]+blist[num1])-(alist[num2]+alist[num1])+1)
1
17,274,425,080,730
null
137
137
h,w,k = map(int,input().split()) c = [] for i in range(0,h): c.append(input()) def white(c,r,co): count = 0 for i in range(0,h): for j in range(0,w): if r[i] != 0 and co[j] != 0 and c[i][j] == "#": count += 1 return count import itertools listr = list(itertools.product([0,1],repeat = h)) listc = list(itertools.product([0,1],repeat = w)) ans = 0 for i in range(0,2**h): for j in range(0,2**w): if white(c,listr[i],listc[j]) == k: ans += 1 print(ans)
import copy H,W,K=map(int,input().split()) L=[[x for x in input()] for i in range(H)] ans=0 for i in range(2**H): for j in range(2**W): C=copy.deepcopy(L) for k in range(H): if (i>>k&1): C[k]=["r"]*W for l in range(W): if (j>>l&1): for m in range(H): C[m][l]="r" count=0 for p in range(H): for q in range(W): if C[p][q]=="#": count+=1 if count==K: ans+=1 print(ans)
1
8,964,681,675,408
null
110
110
while True: [h,w] = map(int,input().split()) if h==0 and w ==0: break print(('#'*w + '\n')*h)
b = [] c = [] while True: a = input().split() a[0] = int(a[0]) a[1] = int(a[1]) if a[0] == 0 and a[1] == 0: break else: b.append("#"*a[1]) c.append(a[0]) for i in range(len(c)): for j in range(c[i]): print(b[i]) print("\n",end="")
1
775,750,013,680
null
49
49
S=input() if S=='ABC': print('ARC') else: print('ABC')
N, A, B = map(int, input().split()) a = N//(A+B) b = N%(A+B) if b > A: b = A ans = a*A + b print(ans)
0
null
39,823,969,795,662
153
202
for i in range(100000): h,w = map(int,input().split(" ")) if h + w == 0: break print("#"*w) for j in range(h-2): print("#" + "."*(w-2) + "#") print("#"*w) print("")
#coding:utf-8 #1_5_B 2015.4.1 while True: length,width = map(int,input().split()) if (length,width) == (0,0): break for i in range(length): for j in range(width): if j == width - 1: print('#') elif i == 0 or i == length - 1 or j == 0: print('#', end='') else: print('.', end='') print()
1
839,547,737,800
null
50
50
w, h, x, y, r = [int(n) for n in input().split()] if x+r > w or y+r > h or x-r < 0 or y-r < 0: print("No") else: print("Yes")
def makeRelation(): visited=[False]*(N+1) g=0 # group for n in range(1,N+1): if visited[n]: continue q={n} D.append(set()) while q: j=q.pop() for i in F[j]: # search for friend if not visited[i]: visited[i]=True q.add(i) D[g]|={i} g+=1 def main(): makeRelation() #print(D) for g in D: for d in g: ans[d]=len(g) - len(F[d]) - len(g&B[d]) - 1 print(*ans[1:]) if __name__=='__main__': N, M, K = map(int, input().split()) F=[set() for n in range(N+1)] AB=[list(map(int, input().split())) for m in range(M)] for a,b in AB: F[a].add(b) F[b].add(a) B=[set() for n in range(N+1)] CD=[list(map(int, input().split())) for k in range(K)] for c,d in CD: B[c].add(d) B[d].add(c) D=[] #print(F) #print(B) ans=[0]*(N+1) main()
0
null
31,053,993,408,380
41
209
def main(): n = int(input()) bit = input()[::-1] count = bit.count("1") count_plus = count+1 count_minus = count-1 pow_plus = [1 % count_plus] for i in range(n): pow_plus.append(pow_plus[-1]*2 % count_plus) if count_minus != 0: pow_minus = [1 % count_minus] for i in range(n): pow_minus.append(pow_minus[-1]*2 % count_minus) else: pow_minus = [] bit_plus = 0 bit_minus = 0 for i in range(n): if bit[i] == "1": bit_plus = (bit_plus+pow_plus[i]) % count_plus if count_minus != 0: for i in range(n): if bit[i] == "1": bit_minus = (bit_minus+pow_minus[i]) % count_minus ans = [] for i in range(n): if bit[i] == "1": if count_minus == 0: ans.append(0) continue bit_ans = (bit_minus-pow_minus[i]) % count_minus count = count_minus else: bit_ans = (bit_plus+pow_plus[i]) % count_plus count = count_plus cnt = 1 while bit_ans: b = str(bin(bit_ans)).count("1") bit_ans = bit_ans % b cnt += 1 ans.append(cnt) for i in ans[::-1]: print(i) main()
def mpow(a,b,m): ans=1 while b >0 : if b&1: ans = (ans*a)%m a=(a*a)%m b=b>>1 return ans def calcmod(X,m,N): mod=0 X=X[::-1] # print(X) for i in range(N): if X[i] == '1': # if X & (1<<i) >0: mod += mpow(2,i,m) mod%=m return mod def popcount(m): return bin(m).count("1") def findsteps(mm): cnt=0 while mm !=0: cnt+=1 mm=mm%popcount(mm) return cnt N=int(input()) x=input() X=int(x,2) ##we need to find X%(m-1) and X%(m+1) m=popcount(X) m1=m+1 m2=m-1 firstmod=calcmod(x,m1,N) if m2 !=0: secondmod=calcmod(x,m2,N) fans=[0 for i in range(N)] k=0 for i in range(N-1,-1,-1): if X & (1<<i) >0: ##the bit was set ##we need to find X%(m-1) - (2^i)%(m-1) if m2 == 0: ans=0 else: mm=secondmod - mpow(2,i,m2) if mm < 0: mm+=m2 mm=mm%m2 ans=1+findsteps(mm) else: mm = firstmod + mpow(2,i,m1) mm=mm%m1 ans=1+findsteps(mm) fans[k] = ans k+=1 ##the bit was not set for i in fans: print(i)
1
8,210,556,918,712
null
107
107
n = int(input()) a = list(map(int, input().split())) counter = 0 for i in range((len(a)+1)//2): if a[i*2]%2 == 1: counter += 1 print(counter)
H,N = map(int,input().split()) AB = [tuple(map(int,input().split())) for _ in range(N)] INF = float("inf") dp0 = [INF]*(H+1) dp1 = [0]*(H+1) dp0[0] = 0 for i in range(N): a,b = AB[i] dp1[H] = dp0[H] for h in range(H-1, -1, -1): dp1[h] = min(dp0[h], dp1[h+1]) for h in range(H+1): dp1[h] = min(dp1[h], dp1[max(h-a,0)]+b) t = dp1 dp1 = dp0 dp0 = t print(dp0[H])
0
null
44,381,487,076,850
105
229
H1, M1, H2, M2, K = map(int, input().split()) T = (H2 - H1) * 60 + (M2 - M1) print(T - K)
import sys import fractions def main(): dataset = sys.stdin.readlines() for data in dataset: a, b = map(int, data.split()) gcd_num = fractions.gcd(a, b) print('%d %d' % (gcd_num, a * b / gcd_num)) main()
0
null
9,021,245,939,552
139
5
n = int(input()) a = map(int, input().split()) cnt = 0 for i, v in enumerate(a): if (i+1) % 2 == 1 and v % 2 == 1: cnt+=1 print(cnt)
N = int(input()) an = x = [int(i) for i in input().split()] count = 0 for i in range(len(an)): if ((i + 1) % 2 == 0): continue if (an[i] % 2 != 0): count = count + 1 print(count)
1
7,776,116,283,738
null
105
105
# -*- coding: utf-8 -*- from sys import stdin input = stdin.readline def main(): a, b, c, d = list(map(int,input().split())) print(max([a*c, a*d, b*c, b*d])) if __name__ == "__main__": main()
a,b,c,d = map(int,input().split()) l1 = [a,b] l2 = [c,d] if(a<0 and 0<b): l1.append(0) if(c<0 and 0<d): l2.append(0) l = [] for x in l1: for y in l2: l.append(x*y) print(max(l))
1
3,026,458,412,650
null
77
77
# import dice class dice: def __init__(self): self.top = 1 # self.srf = [[2,4,3,5],[6,4,3,1],[6,2,5,1],[6,5,2,1],[6,4,3,1],[5,4,3,2]] self.bottom = 2 self.up = 5 self.left = 4 self.right = 3 self.reverse = 6 def move(self, dim): if dim == "N": temp = self.top self.top = self.bottom self.bottom = self.reverse self.reverse = self.up self.up = temp elif dim == "E": temp = self.top self.top = self.left self.left = self.reverse self.reverse = self.right self.right = temp elif dim == "W": temp = self.top self.top = self.right self.right = self.reverse self.reverse = self.left self.left = temp elif dim == "S": temp = self.top self.top = self.up self.up = self.reverse self.reverse = self.bottom self.bottom = temp x = [] x = list(map(int, input().split())) mv = [] mv = list(input()) dc = dice() for i in range(len(mv)): dc.move(mv[i]) print(x[dc.top - 1])
class Dice: def __init__(self, ary): # [top, front, right, left, back, bottom] self.__top = ary[0] self.__fro = ary[1] self.__rit = ary[2] self.__lft = ary[3] self.__bak = ary[4] self.__btm = ary[5] def turn_e(self): # 右に転がる self.__top, self.__lft, self.__btm, self.__rit = \ self.__lft, self.__btm, self.__rit, self.__top def turn_s(self): # 手前に転がる self.__top, self.__fro, self.__btm, self.__bak = \ self.__bak, self.__top, self.__fro, self.__btm def turn_w(self): # 左に転がる self.__top, self.__lft, self.__btm, self.__rit = \ self.__rit, self.__top, self.__lft, self.__btm def turn_n(self): # 奥に転がる self.__top, self.__fro, self.__btm, self.__bak = \ self.__fro, self.__btm, self.__bak, self.__top def spin_r(self): # 右回転 self.__rit, self.__fro, self.__lft, self.__bak = \ self.__bak, self.__rit, self.__fro, self.__lft def spin_l(self): # 左回転 self.__rit, self.__fro, self.__lft, self.__bak = \ self.__fro, self.__lft, self.__bak, self.__rit def is_same_setting(self, ary): # 同じように置いているか if self.__top == ary[0] and self.__fro == ary[1] and self.__rit == ary[2] and \ self.__lft == ary[3] and self.__bak == ary[4] and self.__btm == ary[5]: return True def is_same_dice(self, ary): # 回転させて同じダイスになるか is_same = False for _ in range(2): for _ in range(3): for _ in range(4): if self.is_same_setting(ary): is_same = True self.spin_r() self.turn_n() self.spin_r() self.turn_s() return is_same def show_top(self): # 上面の値を表示 return self.__top surfaces = list(map(int,input().split())) instructions = list(input()) dice = Dice(surfaces) for inst in instructions: if inst == "E": dice.turn_e() if inst == "N": dice.turn_n() if inst == "S": dice.turn_s() if inst == "W": dice.turn_w() print(dice.show_top())
1
229,796,804,496
null
33
33
H,N = map(int,input().split()) A = list(map(int,input().split())) def battle(a,n): ans = 0 for i in range(n): ans += a[i] return ans if H <= battle(A,N): print("Yes") else: print("No")
import sys, re from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left, bisect_right from functools import reduce from decimal import Decimal, getcontext # input = sys.stdin.readline def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 6) INF = float('inf') MOD = 10 ** 9 + 7 num_list = [] str_list = [] def main(): n = i_input() xs = i_list() min_list = [] for i in range(1, 101): tmp = 0 for x in xs: tmp += (i - x)**2 min_list.append(tmp) print(min(min_list)) if __name__ == '__main__': main()
0
null
71,726,331,511,822
226
213
s = input() a = 0 ans = 0 b = 0 d = [0] e = [] now = 0 for i in range(len(s)): if s[i] == '<': if a != 0: if a > now: ans = ans - d[-1] + a for j in range(a): ans = ans + j d.append(a - j) e.append(">") now = 0 a = 0 ans = ans + now + 1 now = now + 1 d.append(now) else: a = a + 1 b = 0 if a != 0: if a > now: ans = ans - d[-1] + a for j in range(a): ans = ans + j d.append(a - j) e.append(">") print(ans)
N,M,K = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) a_sum = [0 for i in range(N+1)] for i in range(N): a_sum[i+1] = a_sum[i] + A[i] b_sum = [0 for i in range(M+1)] for i in range(M): b_sum[i+1] = b_sum[i] + B[i] ans = 0 for i in range(N+1): t = a_sum[i] l = 0 r = len(b_sum) while(l+1<r): c = (l+r)//2 if t+b_sum[c]<=K: l = c else: r = c if a_sum[i]+b_sum[l]<=K: ans = max(ans,i+l) print(ans)
0
null
83,314,918,124,608
285
117
S = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51" N = list(map(int,S.split(","))) K = int(input()) print(N[K-1])
s = map(int, raw_input().split()) s.sort() print ' '.join(map(str, s))
0
null
25,233,274,286,638
195
40
kazu = ['pon','pon','hon','bon','hon','hon','pon','hon','pon','hon'] n = int(input()) print(kazu[n%10])
def main(): s = (input()) l = ['x' for i in range(len(s))] print(''.join(l)) main()
0
null
46,085,803,603,218
142
221
n = int(input()) dict = {0:1,1:1} def fib(n): if n in dict.keys(): return dict[n] else: dict[n] = fib(n-1) + fib(n-2) return dict[n] print(fib(n))
n = input() s1 = [] s2 = [] for i in range(len(n)): if n[i] == '\\': s1.append(i) elif n[i] == '/' and len(s1) > 0: a = s1.pop(-1) s2.append([a, i - a]) i = 0 while len(s2) > 1: if i == len(s2) - 1: break elif s2[i][0] > s2[i + 1][0]: s2[i + 1][1] += s2.pop(i)[1] i = 0 else: i += 1 s = [] total = 0 for i in s2: s.append(str(int(i[1]))) total += int(i[1]) print(total) if len(s2) == 0: print('0') else: print('{} {}'.format(len(s2), ' '.join(s)))
0
null
30,851,330,240
7
21
import fractions A,B=map(int,input().split()) def lcm(x,y): return int((x*y)/fractions.gcd(x,y)) print(lcm(A,B))
cross_section = input() visited = {0: -1} height = 0 pools = [] for i, c in enumerate(cross_section): if c == '\\': height -= 1 elif c == '/': height += 1 if height in visited: width = i - visited[height] sm = 0 while pools and pools[-1][0] > visited[height]: _, volume = pools.pop() sm += volume pools.append((i, sm + width - 1)) visited[height] = i print(sum(v for _, v in pools)) print(len(pools), *(v for _, v in pools))
0
null
56,480,230,675,300
256
21
import sys import itertools # import numpy as np import time import math sys.setrecursionlimit(10 ** 7) from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(input()) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 x = 1 ans = 0 for i in range(60): ones = 0 zeros = 0 for a in A: if a & (1 << i) > 0: ones += 1 else: zeros += 1 ans += (ones * zeros * x) % MOD x *= 2 print(ans % MOD)
# -*- utf-8 -*- while True: try: inp = raw_input() i = map(int, inp.split()) a = i[0] b = i[1] s = a + b except: break ans = 0 while s >= 1: s /= 10 ans += 1 print ans
0
null
61,672,057,271,808
263
3
import math x1,y1,x2,y2=map(float,input().split()) A=abs(y1-y2) B=abs(x1-x2) C=math.sqrt(A**2+B**2) print(f'{C:.8f}')
# -*-coding:utf-8 class Dice: def __init__(self, diceList): self.d1, self.d2, self.d3, self.d4, self.d5, self.d6 = diceList def diceRoll(self, r): if(r == 'N'): self.d1, self.d2, self.d5, self.d6 = self.d2, self.d6, self.d1, self.d5 elif(r == 'E'): self.d1, self.d3, self.d4, self.d6 = self.d4, self.d1, self.d6, self.d3 elif(r == 'W'): self.d1, self.d3, self.d4, self.d6 = self.d3, self.d6, self.d1, self.d4 elif(r == 'S'): self.d1, self.d2, self.d5, self.d6 = self.d5, self.d1, self.d6, self.d2 def main(): inputDiceList = list(map(int, input().split())) rollList = list(input()) d = Dice(inputDiceList) for i in rollList: d.diceRoll(i) print(d.d1) if __name__ == '__main__': main()
0
null
199,038,744,002
29
33
from sys import stdin N = int(stdin.readline().rstrip()) C = stdin.readline().rstrip() rc = C.count('R') ans = 0 for i in range(rc): if C[i] == 'W': ans += 1 print(ans)
from sys import exit import math ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) n = li() N = [] N.append(n[0]) for i in range(1,3,1): if n[i] in N: continue N.append(n[i]) if len(N) == 2: print('Yes') else: print('No')
0
null
37,171,120,328,120
98
216
while(True): h,w=map(int,input().split()) if h==0 and w==0: break rect='#'*w+'\n' rect+=('#'+'.'*(w-2)+'#\n')*(h-2) rect+='#'*w+'\n' print(rect)
import sys def input(): return sys.stdin.readline().rstrip() def main(): h1, m1, h2, m2, k = map(int,input().split()) print(h2*60+m2-h1*60-m1-k) if __name__=='__main__': main()
0
null
9,469,165,968,640
50
139
import sys input = sys.stdin.readline n = int(input()) a = [int(x) for x in input().split()] max_a = [0]*(n + 1) if n == 0 and a[0] == 0: print(-1) sys.exit() for i in range(n + 1): if i == 0: max_a[i] = 1 else: max_a[i] = (max_a[i - 1] - a[i - 1])*2 if max_a[i] < 0: print(-1) sys.exit() # print(max_a) for i in range(n, -1, -1): if i == n: if max_a[i] < a[i]: print(-1) sys.exit() max_a[i] = a[i] else: min_p = max_a[i + 1] // 2 + int(max_a[i + 1] % 2 == 1) max_p = max_a[i + 1] if max_a[i] < min_p: print(-1) sys.exit() max_a[i] = min(max_p + a[i], max_a[i]) print(sum(max_a)) # print(max_a)
n = int(input()) ai = [int(i) for i in input().split()] tmp = 0 ans = 0 old = 0 a_mnmx = [[0 for i in range(2)] for j in range(n+1)] #print(a_max) old = ai[n] a_mnmx[n][0] = old a_mnmx[n][1] = old for i in range(n): a_mnmx[n-i-1][0] = (a_mnmx[n-i][0]+1)//2 + ai[n-i-1] a_mnmx[n-i-1][1] = a_mnmx[n-i][1] + ai[n-i-1] #print(a_mnmx) if a_mnmx[0][1] < 1 or a_mnmx[0][0] > 1: print(-1) exit() old = 1 ans = 1 for i in range(n): old = min(a_mnmx[i+1][1],old*2) ans += old old -= ai[i+1] #print(old) print(ans)
1
18,932,644,056,340
null
141
141
def main(): H, W, K = [int(k) for k in input().split(" ")] C = [] black_in_row = [] black_in_col = [0] * W for i in range(H): C.append(list(input())) black_in_row.append(C[i].count("#")) for j in range(W): if C[i][j] == "#": black_in_col[j] += 1 black = sum(black_in_row) if black < K: print(0) return 0 cnt = 0 for i in range(2 ** H): row_bit = [f for f, b in enumerate(list(pad_zero(format(i, 'b'), H))) if b == "1"] r = sum([black_in_row[y] for y in row_bit]) for j in range(2 ** W): col_bit = [f for f, b in enumerate(list(pad_zero(format(j, 'b'), W))) if b == "1"] c = sum([black_in_col[x] for x in col_bit]) bl = black - r - c + sum([1 for p in row_bit for q in col_bit if C[p][q] == "#"]) if bl == K: cnt += 1 print(cnt) def pad_zero(s, n): s = str(s) return ("0" * n + s)[-n:] main()
x, y = map(int, input().split()) while x != 0 or y != 0: if x < y: print(x, y) else: print(y, x) x, y = map(int, input().split())
0
null
4,747,993,950,780
110
43
a,b = input().split() print(a*int(b)) if a < b else print(b*int(a))
#ALDS_1_1_D Maximum Profit N=int(input()) A=[] for i in range(N): A.append(int(input())) MIN= A[0] MAX= A[1]-A[0] for i in range(1,N): MAX=max(MAX,A[i]-MIN) MIN=min(MIN,A[i]) print(MAX)
0
null
42,256,707,176,096
232
13
def show (nums): for i in range(len(nums)): if i!=len(nums)-1: print(nums[i],end=' ') else : print(nums[i]) n=int(input()) nums=list(map(int,input().split())) show(nums) for i in range(1,n): v=nums[i] j=i-1 while (j>=0 and nums[j]>v): nums[j+1]=nums[j] j-=1 nums[j+1]=v show(nums)
class Combination(): # nCr(mod p) #n<=10**6 def __init__(self, N, MOD): # cmbの前処理 self.mod = MOD self.FACT = [1, 1] # 階乗 self.INV = [0, 1] # 各iの逆元 self.FACTINV = [1, 1] # 階乗の逆元 for i in range(2, N + 1): self.FACT.append((self.FACT[-1] * i) % self.mod) self.INV.append(pow(i, self.mod - 2, self.mod)) self.FACTINV.append((self.FACTINV[-1] * self.INV[-1]) % self.mod) def calculate(self, N, R): # nCr(mod p) #前処理必要 if (R < 0) or (N < R): return 0 R = min(R, N - R) return self.FACT[N] * self.FACTINV[R] * self.FACTINV[N-R] % self.mod n, m, k = map(int, input().split()) mod = 998244353 cmb = Combination(n,mod) cnt = 0 for i in range(k + 1): cnt += (m * pow(m - 1, n - i - 1, mod) * cmb.calculate(n - 1, i)) % mod print(cnt % mod)
0
null
11,504,735,344,480
10
151
N,K,C=map(int, input().split()) S=input() L=[0]*N R=[0]*N c=1 last=-C-1 for i in range(N): if i-last>C and S[i]!='x' and c<=K: L[i]=c c+=1 last=i c=K last=N+C for i in range(N-1,-1,-1): if last-i>C and S[i]!='x' and c>=1: R[i]=c c-=1 last=i for i in range(N): if 0<L[i]==R[i]: print(i+1)
n,k,c=map(int,input().split()) s=input() l=[] r=[] i=0 j=0 while len(l)<k and i<n: if s[i]=='o': l.append(i+1) i+=c+1 else: i+=1 while len(r)<k and j<n: if s[-j-1]=='o': r.append(n-j) j+=c+1 else: j+=1 for n in range(k): if l[n]==r[-n-1]: print(l[n])
1
40,751,437,487,332
null
182
182
A, B, C = list(map(int, input().split())) K = int(input()) res = 0 while True: if B <= A: B *= 2 res += 1 else: break while True: if C <= B: C *= 2 res += 1 else: break if res <= K: print("Yes") else: print("No")
A, B, C = map(int, input().split()) K = int(input()) for i in range(K): if A >= B: B *= 2 continue if B >= C: C *= 2 continue if A < B and B < C: print('Yes') else: print('No')
1
6,858,600,217,040
null
101
101
import math x,k,d = map(int,input().split()) abs_x = abs(x) max_len = math.ceil(abs_x/d)*d min_len = max_len-d if abs_x-k*d >= 0: print(abs_x-k*d) exit() if (math.ceil(abs_x/d)-1)%2 == k%2: print(abs(abs_x-min_len)) else: print(abs(abs_x-max_len))
import sys x, y = map(int, input().split()) ans = 0 for i in range(x+1): if y == i*2 + (x - i)* 4: ans = 1 break if ans == 1: print("Yes") else: print("No")
0
null
9,413,815,727,100
92
127
def main(): n = int(input()) a_list = list(map(int, input().split())) num = 1 for a in a_list: if a == num: num += 1 if num == 1: print(-1) else: print(n - num + 1) if __name__ == "__main__": main()
nm = input().split() n = int(nm[0]) m = int(nm[1]) ans = 0 n1 = n*(n-1)/2 n2 = m*(m-1)/2 ans = int(n1 + n2) print(ans)
0
null
79,656,060,811,068
257
189
def area(a,b): return a * b def perimetro(a,b): return 2 * (a + b) def main(): a,b = map(int,input().split()) ar = area(a,b) pe = perimetro(a,b) return ar, pe ar, pe = main() print(ar, pe)
nums = input().split() a = int(nums[0]) b = int(nums[1]) print(a * b, 2 * a + 2 * b)
1
296,246,867,774
null
36
36
import collections import sys input = sys.stdin.readline def main(): N = int(input()) S = [input().rstrip() for _ in range(N)] c = collections.Counter(S).most_common() max_freq = None max_S = [] for s, freq in c: if max_freq is None: max_freq = freq max_S.append(s) elif freq == max_freq: max_S.append(s) else: break print('\n'.join(sorted(max_S))) if __name__ == "__main__": main()
import collections N = int(input()) S = [input() for _ in range(N)] c = collections.Counter(S) d = c.most_common() cnt = 0 for i in range(len(c)-1): if d[i][1] == d[i+1][1]: cnt += 1 else: break e = [] for j in range(cnt+1): e.append(d[j][0]) e.sort() for k in range(len(e)): print(e[k])
1
70,317,255,743,280
null
218
218
n=int(input());print((n//2)/n if n%2==0 else -(-n//2)/n)
N = int(input()) L = [i for i in range(1, N + 1) if i % 2 != 0] A = len(L) / N print(A)
1
176,944,205,537,532
null
297
297
n = int(input()) S = input() rs = [s=="R" for s in S] gs = [s=="G" for s in S] bs = [s=="B" for s in S] ind_r = [i for i,s in enumerate(rs) if s == 1] ind_g = [i for i,s in enumerate(gs) if s == 1] ind_b = [i for i,s in enumerate(bs) if s == 1] ans = 0 ng = sum(gs) for i in ind_r: for j in ind_b: # print(i,j) kM = max(i,j) + abs(i-j) km = min(i,j) - abs(i-j) ans += ng if (max(i,j) - min(i,j))%2==0: # print("aaa",(max(i,j)+min(i,j))//2) ans -= gs[(max(i,j)+min(i,j))//2] if kM < n: ans -= gs[kM] if 0 <= km: ans -= gs[km] print(ans)
N = int(input()) D = list(map(int, input().split())) mod = 998244353 from collections import Counter, deque def solve(N,D): if D[0]!=0: return 0 c = Counter(D) if c[0]>1: return 0 ans = 1 m = max(D) for i in range(1,m): if c[i]==0: ans = 0 continue ans *= pow(c[i],c[i+1],mod) ans %= mod return ans print(solve(N,D))
0
null
95,443,969,345,412
175
284
from collections import deque INFTY = 10**6 N,u,v = map(int,input().split()) G = {i:[] for i in range(1,N+1)} for _ in range(N-1): a,b = map(int,input().split()) G[a].append(b) G[b].append(a) du = [INFTY for _ in range(N+1)] du[u] = 0 que = deque([(0,u)]) hist = [0 for _ in range(N+1)] hist[u] = 1 while que: c,i = que.popleft() for j in G[i]: if hist[j]==0: que.append((c+1,j)) du[j] = c+1 hist[j] = 1 dv = [INFTY for _ in range(N+1)] dv[v] = 0 que = deque([(0,v)]) hist = [0 for _ in range(N+1)] hist[v] = 1 while que: c,i = que.popleft() for j in G[i]: if hist[j]==0: que.append((c+1,j)) dv[j] = c+1 hist[j] = 1 cmax = 0 for i in range(1,N+1): if du[i]<dv[i]: cmax = max(cmax,dv[i]) print(cmax-1)
import sys sys.setrecursionlimit(10 ** 5) n, u, v = map(int, input().split()) u -= 1 v -= 1 es = [[] for i in range(n)] for i in range(n-1): a, b = map(int, input().split()) es[a-1].append(b-1) es[b-1].append(a-1) def dfs(v, dist, p=-1, d=0): dist[v] = d for nv in es[v]: if nv == p: continue dfs(nv, dist, v, d+1) def calc_dist(x): dist = [-1] * n dfs(x, dist) return dist dist_t = calc_dist(u) dist_a = calc_dist(v) mx = 0 for i in range(n): if dist_t[i] < dist_a[i]: mx = max(mx, dist_a[i]) ans = mx - 1 print(ans)
1
117,206,892,924,540
null
259
259
n, k, c = map(int, input().split()) s = input() work = [1]*n rest = 0 for i in range(n): if rest: rest -= 1 work[i] = 0 continue if s[i] == 'x': work[i] = 0 elif s[i] == 'o': rest = c rest = 0 for i in reversed(range(n)): if rest: rest -= 1 work[i] = 0 continue if s[i] == 'o': rest = c if k < sum(work): print() else: for idx, bl in enumerate(work): if bl: print(idx+1)
n,k,c = map(int, input().split()) s = input() # 計算途中はi=0~n-1日とする # [a,b] i日までで、限界まで働くとa回働けてb日まで働けない pre = [[0,0] for i in range(n)] if s[0]=='o': pre[0]=[1,c] for j in range(c): if 1+j < n: pre[1+j] = pre[0] + [] for i in range(1,n): if pre[i]==[0,0]: if s[i]=='o': pre[i][0]=pre[i-1][0]+1 pre[i][1]+=i+c for j in range(c): if i+j+1<n: pre[i+j+1]=pre[i]+[] else: pre[i]=pre[i-1]+[] # i日以降で限界まで働くとa回働ける post = [0 for i in range(n)] if s[-1]=='o': post[-1]=1 for j in range(c): if 0 <= n-1-j-1 < n: post[-1-j-1] = post[-1] for i in range(1,n): if post[n-i-1]==0: if s[n-i-1]=='o': post[n-i-1]=post[n-i]+1 for j in range(c): if 0<=n-i-1-j-1<n: post[n-i-1-j-1]=post[n-i-1] else: post[n-i-1]=post[n-i] # 0日、n+1日を追加。iを1~n日にする pre = [[0,0]]+pre+[[0,0]] post = [0]+post+[0] # i日に休んだときに、働く回数がkに到達するか調べる ans = [] for i in range(1,n+1): if s[i-1]=='o': work, rest = pre[i-1] day = min(max(rest,i)+1,n+1) work = work + post[day] if work<k: ans.append(i) for i in range(len(ans)): print(ans[i])
1
40,487,493,666,080
null
182
182
import math n = int(input()) while 1: flg=1 for i in range(2,int(math.sqrt(n))+1): if n % i == 0: flg=0 break if flg==1: print(n) break n+=1
import sys import math def isPrime(num): if num < 2: return False elif num == 2: return True elif num % 2 == 0: return False for i in range(3, math.floor(math.sqrt(num))+1, 2): if num % i == 0: return False return True def callIsPrime(input_num): numbers = [] for i in range(1, input_num): if isPrime(i): numbers.append(i) return numbers def main(): input = sys.stdin.readline x = int(input()) primes = callIsPrime(x+1000) ans = [i for i in primes if i>=x] print(min(ans)) if __name__ == "__main__": main()
1
105,730,579,526,494
null
250
250
import itertools N = int(input()) l = [] kyori = [] for _ in range(N): xy = list(map(int, input().split())) l.append(xy) for i in itertools.combinations(l,2): t = ((i[0][0]-i[1][0])**2 + (i[0][1] - i[1][1])**2)**0.5 kyori.append(t) print((N-1)*sum(kyori)/len(kyori))
N = int(input()) ans = 0 MOD = 10**9+7 ans = 10**N-2*9**N+8**N ans %= MOD print(ans)
0
null
75,837,015,217,150
280
78
import sys if __name__ == "__main__": for i in sys.stdin: a,b = list(map(int,i.strip().split())) print(len(str(a+b)))
n = int(input()) dic = set() for i in range(n): x = input() if 'insert' in x: dic.add(x.strip('insert ')) else : if x.strip('find ') in dic: print('yes') else : print('no')
0
null
39,602,570,272
3
23
n,m=list(map(int,input().split())) s=input() a=[0]*(n+1) a[0]=1 for i in range(1,n+1): if s[i]=='1': continue for j in range(max(0,i-m),i): if s[j]=='1': continue if a[j]>0: break a[i]=i-j ans='' cur=n while cur>0: d=a[cur] cur-=d if d==0: print(-1) exit(0) ans=str(d)+' '+ans print(ans[:-1])
# AtCoder Beginner Contest 146 # F - Sugoroku # https://atcoder.jp/contests/abc146/tasks/abc146_f import sys N, M = map(int, input().split()) *S, = map(int, input()) S.reverse() i = 0 ans = [] while i < N: for m in range(M, 0, -1): if i+m <= N and S[i+m] == 0: i += m ans += [m] break else: print(-1) sys.exit() print(*ans[::-1])
1
138,772,248,252,808
null
274
274
n, m = map(int, input().split()) class UnionFind(): def __init__(self, n): self.n = n self.parent = [int(x) for x in range(n)] self.tree_size = [1 for _ in range(n)] def unite(self, x, y): x_root = self.find(x) y_root = self.find(y) if self.same(x_root, y_root): return if self.size(x_root) >= self.size(y_root): self.parent[y_root] = x_root self.tree_size[x_root] += self.tree_size[y_root] else: self.parent[x_root] = y_root self.tree_size[y_root] += self.tree_size[x_root] def find(self, x): if self.parent[x] == x: return x else: return self.find(self.parent[x]) def size(self, x): return self.tree_size[self.find(x)] def same(self, x, y): if x == y: return True else: return False uf = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) uf.unite(a-1, b-1) # print([uf.size(i) for i in range(n)]) print(max([uf.size(i) for i in range(n)]))
class Union_Find(): def __init__(self, N): self.N = N self.par = [n for n in range(N)] self.rank = [0] * N def root(self, x): if self.par[x] == x: return x else: return self.root(self.par[x]) def same(self, x, y): if self.root(x) == self.root(y): return True else: return False def unite(self, x, y): x = self.root(x) y = self.root(y) if (x==y): return if (self.rank[x] < self.rank[y]): self.par[x] = y self.rank[y] += self.rank[x] + 1 else: self.par[y] = x self.rank[x] += self.rank[y] + 1 N, M = map(int, input().split()) UF = Union_Find(N) for _ in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 UF.unite(a, b) ans = -1 for n in range(N): ans = max(ans, UF.rank[n]) print(ans+1)
1
3,929,264,292,880
null
84
84
X=int(input()) C=X//500 c=(X-X//500*500)//5 print(C*1000+c*5)
process_num, qms = map(int, input().split()) raw_procs = [input() for i in range(process_num)] if __name__ == '__main__': procs = [] for row in raw_procs: name, time = row.split() procs.append({ "name": name, "time": int(time), }) total_time = 0 current_proc = 0 while len(procs) > 0: if procs[current_proc]["time"] > qms: procs[current_proc]["time"] = procs[current_proc]["time"] - qms total_time += qms if current_proc == len(procs)-1: current_proc = 0 else: current_proc += 1 else: total_time += procs[current_proc]["time"] print("{} {}".format(procs[current_proc]["name"], total_time)) del procs[current_proc] if current_proc == len(procs): current_proc = 0
0
null
21,360,203,732,864
185
19
import math N = int(input()) min = math.floor(N / 1.08) max = math.ceil(N/ 1.08) flag = False for i in range(min,max+1): ans = math.floor(i*1.08) if N == ans: X = i flag = True break if(flag): print(X) else: print(':(')
import math n=int(input()) if int(math.ceil(n/1.08)*1.08)==n: print(math.ceil(n/1.08)) else: print(":(")
1
125,326,076,436,850
null
265
265
import sys word=input() text=sys.stdin.read() print(text.lower().split().count(word))
def main(): import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, k = map(int, readline().split()) a = list(map(int, readline().split())) memo = [0] * (n + 1) for _ in range(k): flag = True for i, aa in enumerate(a): bf = (i - aa if i - aa >= 0 else 0) af = (i + aa + 1 if i + aa < n else n) memo[bf] += 1 memo[af] -= 1 for i in range(n): memo[i + 1] += memo[i] a[i] = memo[i] if a[i] != n: flag = False memo[i] = 0 if flag: break print(*a) if __name__ == '__main__': main()
0
null
8,712,474,960,608
65
132
n, a, b = map( int, input().split() ) mod = 10 ** 9 + 7 N = pow( 2, n, mod ) - 1 def comb( n, r ): c = 1 m = 1 r = min( n - r, r ) for i in range( r ): c = c * ( n - i ) % mod m = m * ( i + 1 ) % mod return c * pow( m, mod - 2, mod ) % mod A = comb( n, a ) B = comb( n, b ) print( ( N - A - B ) % mod )
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) from collections import defaultdict import bisect from functools import reduce def main(): def comb(n, r): numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)]) denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)]) return numerator * pow(denominator, mod - 2, mod) % mod mod = 10 ** 9 + 7 N, A, B = MI() p = pow(2, N, mod) - 1 a = comb(N, A) b = comb(N, B) ans = (p - a - b) % mod print(ans) if __name__ == "__main__": main()
1
66,201,863,617,568
null
214
214
N = int(input()) count = 0 for i in range(1,N): if int(N/i)-N/i == 0: count += int(N/i)-1 else: count += int(N/i) print(count)
N = int(input()) if N % 2 == 0: ans = int(N / 2) - 1 else: ans = int(N / 2) print(ans)
0
null
77,969,447,062,330
73
283
N, X, M = map(int, input().split()) id = [-1] * M a = [] l = 0 tot = 0 while id[X] == -1: a.append(X) id[X] = l l += 1 tot += X X = X ** 2 % M c = l - id[X] s = 0 for i in range(id[X], l): s += a[i] ans = 0 if N <= l: for i in range(N): ans += a[i] else: ans += tot N -= l ans += s * (N // c) N %= c for i in range(N): ans += a[id[X] + i] print(ans)
n=int(input()) a=list(map(int,input().split())) if a[0]>=2: print(-1) else: pN=1 s=1 l=[] S=sum(a) b=0 z=1 for k in range(len(a)): b+=a[k] l.append(b) for i in range(1,n+1): if a[i]>2*pN: print(-1) z=0 break else: pN=min(2*pN-a[i],S-l[i]) s+=pN s+=S if n==0: s=1 if a[0]==1 and n>=1: print(-1) z=0 if z: print(s)
0
null
10,873,993,352,278
75
141
n=int(input()) ans = False for j in range(1,10): for k in range(1,10): if j*k == n: ans = True break if ans: break if ans: print("Yes") else: print("No")
import sys input = sys.stdin.readline n = int(input()) flag = False for i in range(1, 10): if n % i == 0 and 1 <= n // i <= 9: flag = True break if flag: print("Yes") else: print("No")
1
160,053,802,778,640
null
287
287
N=int(input()) S=input() cnt=0 for i in range(N): left=i-1 right=i+1 while 0<=left and right<N: if S[i]!=S[left] and S[i]!=S[right] and S[left]!=S[right]: cnt+=1 left-=1 right+=1 x=S.count('R') y=S.count('G') z=S.count('B') print(x*y*z-cnt)
N = int(input()) S = input() r = [0 for _ in range(N + 1)] g = [0 for _ in range(N + 1)] b = [0 for _ in range(N + 1)] for i in reversed(range(N)): r[i] = r[i + 1] g[i] = g[i + 1] b[i] = b[i + 1] if S[i] == "R": r[i] += 1 if S[i] == "G": g[i] += 1 if S[i] == "B": b[i] += 1 ans = 0 for i in range(N): if S[i] == "R": for j in range(i + 1, N): if S[j] == "G": if 2 * j - i < N: if S[2 * j - i] == "B": ans += (b[j + 1] - 1) else: ans += b[j + 1] else: ans += b[j + 1] for i in range(N): if S[i] == "R": for j in range(i + 1, N): if S[j] == "B": if 2 * j - i < N: if S[2 * j - i] == "G": ans += (g[j + 1] - 1) else: ans += g[j + 1] else: ans += g[j + 1] for i in range(N): if S[i] == "B": for j in range(i + 1, N): if S[j] == "R": if 2 * j - i < N: if S[2 * j - i] == "G": ans += (g[j + 1] - 1) else: ans += g[j + 1] else: ans += g[j + 1] for i in range(N): if S[i] == "B": for j in range(i + 1, N): if S[j] == "G": if 2 * j - i < N: if S[2 * j - i] == "R": ans += (r[j + 1] - 1) else: ans += r[j + 1] else: ans += r[j + 1] for i in range(N): if S[i] == "G": for j in range(i + 1, N): if S[j] == "R": if 2 * j - i < N: if S[2 * j - i] == "B": ans += (b[j + 1] - 1) else: ans += b[j + 1] else: ans += b[j + 1] for i in range(N): if S[i] == "G": for j in range(i + 1, N): if S[j] == "B": if 2 * j - i < N: if S[2 * j - i] == "R": ans += (r[j + 1] - 1) else: ans += r[j + 1] else: ans += r[j + 1] print(ans)
1
36,177,908,419,892
null
175
175
n=int(input()) m=1000000007 print(((pow(10,n,m)-2*pow(9,n,m)+pow(8,n,m))+m)%m)
MOD = 10**9+7 def solve(n): """ 0: {} 1: {0} 2: {9} 3: {0,9} """ dp = [[0]*4 for i in range(n+1)] dp[0][0] = 1 x = [1,0,0,0] for i in range(n): x = [ (8*x[0]) % MOD, (9*x[1] + x[0]) % MOD, (9*x[2] + x[0]) % MOD, (10*x[3] + x[2] + x[1]) % MOD ] return x[3] n = int(input()) print(solve(n))
1
3,189,445,027,132
null
78
78
def main(): d, t, s = map(int, input().split()) if d <= (t*s): ans = 'Yes' else: ans = 'No' print(ans) if __name__ == "__main__": main()
# import sys # import math #sqrt,gcd,pi # import decimal # import queue # queue # import bisect # import heapq # priolity-queue # import time # from itertools import product,permutations,\ # combinations,combinations_with_replacement # 重複あり順列、順列、組み合わせ、重複あり組み合わせ # import collections # deque # from operator import itemgetter,mul # from fractions import Fraction # from functools import reduce mod = int(1e9+7) # mod = 998244353 INF = 1<<50 def readInt(): return list(map(int,input().split())) def main(): n,k = readInt() r,s,p = readInt() rsp = {"s":r,"p":s,"r":p} t = input() ans = 0 u = [] for i in range(n): if i<k: ans += rsp[t[i]] u.append(t[i]) else: if t[i]!=u[i-k]: ans += rsp[t[i]] u.append(t[i]) else: u.append("f") print(ans) return if __name__=='__main__': main()
0
null
55,364,956,194,142
81
251
S, T = map(str, input().split()) print(T+S)
a,b = map(int,input().split()) for i in range(1,100000): x = i*8 y = i*10 if x//100 == a and y//100 == b: print(i) exit() print(-1)
0
null
79,562,237,085,188
248
203
import numpy as np n,m = map(int, input().split()) h = np.array([int(i) for i in input().split()]) h_i = np.ones((n)) for i in range(m): a,b = map(int, input().split()) if h[a-1] < h[b-1]: h_i[a-1] = 0 elif h[b-1] < h[a-1]: h_i[b-1] = 0 elif h[a-1] == h[b-1]: h_i[a-1] = 0 h_i[b-1] = 0 ans = (h_i > 0).sum() print(ans)
#!/usr/bin/env python3 def main(): import sys input = sys.stdin.readline N, M = map(int, input().split()) H = [0] + [int(x) for x in input().split()] graph = [[] for _ in [0] * (N + 1)] for i in range(M): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) res = N for i in range(1, N + 1): if graph[i]: for j in graph[i]: if H[j] >= H[i]: res -= 1 break print(res) if __name__ == '__main__': main()
1
24,995,550,535,812
null
155
155
# 入力 D, T, S = input().split() # 以下に回答を記入 D = int(D) T = int(T) S = int(S) if T * S >= D: print('Yes') else: print('No')
import sys # A - Don't be late D, T, S = map(int, input().split()) if S * T >= D: print('Yes') else: print('No')
1
3,582,879,276,970
null
81
81
n = int(input()) a = list(map(int, input().split())) #print(a) a.reverse() print(*a)
N,K = map(int,input().split()) a = list(map(int,input().split())) for i in range(1,N-K+1): if a[K+i-1]>a[i-1]: print("Yes") else: print("No")
0
null
3,998,456,997,600
53
102
a = int(input()) s = 100000 for i in range(a): s = s * 1.05 if s % 1000: s = s - (s % 1000) + 1000 print(int(s))
import math in_week = int(input().rstrip()) tmp_debt = 100000 for i in range(in_week): tmp_debt = int(math.ceil( (tmp_debt*1.05)/1000.0 )) * 1000 print(str(tmp_debt))
1
1,123,501,050
null
6
6
import math x = math.pi r=int(input()) print(2*r*x)
a=int(input()) print(a*6.283185307178)
1
31,464,692,555,050
null
167
167
import math a,b,c=(int(x) for x in input().split()) s=1/2*a*b*math.sin(c/180*math.pi) l=math.sqrt(a**2+b**2-2*a*b*math.cos(c/180*math.pi))+a+b h=s/a*2 print('{:.05f}'.format(s)) print('{:.05f}'.format(l)) print('{:.05f}'.format(h))
N,M = map(int,input().split()) ki = (N*(N-1))//2 gu = (M*(M-1))//2 print (ki+gu)
0
null
22,820,471,398,950
30
189
n = int(input()) record = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] for i in range(n): b, f, r, v = [int(x) for x in input().split()] record[b-1][f-1][r-1] += v for b in range(4): for f in record[b]: print(' '+' '.join([str(x) for x in f])) if b != 3: print(''.join(['#' for x in range(20)]))
h = [[[0]*10 for i in range(3)] for j in range(4)] n = int(input()) for i in range(n): b,f,r,v = map(int,input().split()) h[b-1][f-1][r-1] += v s = "" for i in range(4): for j in range(3): for k in range(10): s += " " + str(h[i][j][k]) s += "\n" if i < 3: s += "####################\n" print(s,end="")
1
1,114,339,839,970
null
55
55
h,a=map(int,input().split()) wa=list(map(int,input().split())) if sum(wa)>=h: print("Yes") else: print("No")
from collections import Counter import itertools n=int(input()) rgb=list(input()) rgb_counter=Counter(rgb) n_list=[i for i in range(1,n+1)] count=0 for i,j in itertools.combinations(n_list,2): k=2*j-i if k<=n and rgb[j-1]!=rgb[i-1] and rgb[j-1]!=rgb[k-1] and rgb[i-1]!=rgb[k-1]: count+=1 print(rgb_counter["R"]*rgb_counter["G"]*rgb_counter["B"]-count)
0
null
57,253,121,547,960
226
175
X, N = map(int, input().split()) ps = list(map(int, input().split())) bgr, smr = X, X while bgr <= 100: if bgr not in ps: break bgr += 1 while smr >= 1: if smr not in ps: break smr -= 1 print(bgr) if bgr - X < X - smr else print(smr)
N = int(input()) S = [input() for _ in range(N)] res = {} for s in S: if s in res: res[s] += 1 else: res[s] = 1 max_ = max(res.values()) ans = [] for k in res: if res[k] == max_: ans.append(k) ans.sort() for a in ans: print(a)
0
null
42,048,238,806,420
128
218
n,x,y=map(int,input().split()) mi={i:0 for i in range(1,n)} for i in range(1,n): for j in range(i+1,n+1): if i<=x and y<=j: mi[x-i+1+j-y]+=1 elif x<i and y<=j: mi[min(i-x+1+j-y,j-i)]+=1 elif i<=x and j<y: mi[min(x-i+1+y-j,j-i)]+=1 elif x<i and j<y: mi[min(i-x+1+y-j,j-i)]+=1 else: mi[j-i]+=1 for i in range(1,n): print(mi[i])
rooms = [0] * (4*3*10) n = input(); for i in xrange(n): b,f,r,v = map(int, raw_input().split()) rooms[(b-1)*30+(f-1)*10+(r-1)] += v sep = "#" * 20 for b in xrange(4): for f in xrange(3): t = 30*b + 10*f print ""," ".join(map(str, rooms[t:t+10])) if b < 3: print sep
0
null
22,449,769,846,280
187
55
# -*- coding: utf-8 -*- n = int(raw_input()) tp = hp = 0 for i in range(n): ts, hs = map(str, raw_input().split()) if ts > hs: tp += 3 elif ts < hs: hp += 3 else: tp += 1 hp += 1 print "%d %d" %(tp, hp)
n=int(input()) xl=[list(map(int, input().split())) for _ in range(n)] rl=[] for x,l in xl: right=x-l left=x+l rl.append([right,left]) rl.sort(key=lambda x: x[1]) # print(rl) cnt=0 pos=-float('inf') for i in range(n): if rl[i][0]>=pos: pos=rl[i][1] cnt+=1 print(cnt)
0
null
45,953,824,269,220
67
237
n,m = map(int,input().split()) v1 = [ input().split() for _ in range(n) ] v2 = [ int(input()) for _ in range(m) ] l = [sum(map(lambda x,y:int(x)*y,v,v2)) for v in v1 ] print(*l,sep="\n")
def main(): n, m = map(int, input().split()) matrix = [ list(map(int, input().split())) for _ in range(n) ] vector = [ int(input()) for _ in range(m) ] for v in matrix: res = sum(x * y for x, y in zip(v, vector)) print(res) if __name__ == "__main__": main()
1
1,131,834,540,476
null
56
56
N = input() K = int(input()) m = len(N) dp = [[[0] * (K+1) for _ in range(2)] for _ in range(m+1)] dp[0][0][0] = 1 for i in range(1,m+1): l = int(N[i-1]) for k in range(K+1): if k-1>=0: if l!=0: dp[i][0][k]=dp[i-1][0][k-1] dp[i][1][k] = dp[i-1][1][k] + 9 * dp[i-1][1][k-1]+dp[i-1][0][k] + (l-1) * dp[i-1][0][k-1] else: dp[i][0][k] = dp[i-1][0][k] dp[i][1][k] = dp[i-1][1][k] + 9 * dp[i-1][1][k-1] else: dp[i][0][k] = 0 dp[i][1][k] = 1 print(dp[m][0][K] + dp[m][1][K])
from sys import setrecursionlimit setrecursionlimit(10 ** 6) MAXN = 100 n = input() k = int(input()) dl = [[None] * (MAXN + 1) for _ in range(MAXN + 1)] de = [[None] * (MAXN + 1) for _ in range(MAXN + 1)] def n_num_e(d, i): # d: n of digits # i: n of nonzero digits if d == 0: if i == 0: return 1 else: return 0 elif de[d][i] is not None: return de[d][i] else: if int(n[d - 1]) == 0: result = n_num_e(d - 1, i) else: result = n_num_e(d - 1, i - 1) de[d][i] = result return result def n_num_l(d, i): # d: n of digits # i: n of nonzero digits if d == 0: return 0 elif dl[d][i] is not None: return dl[d][i] else: if int(n[d - 1]) == 0: ne = 0 nl = 9 * n_num_l(d - 1, i - 1) + n_num_l(d - 1, i) result = ne + nl else: ne = (int(n[d - 1]) - 1) * n_num_e(d - 1, i - 1) + n_num_e(d - 1, i) nl = 9 * n_num_l(d - 1, i - 1) + n_num_l(d - 1, i) result = ne + nl dl[d][i] = result return result answer = n_num_e(len(n), k) + n_num_l(len(n), k) print(answer)
1
75,954,595,470,628
null
224
224