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
n = int(input()) a = list(map(int, input().split())) c = 1 ans = 0 for i in range(n): if a[i] == c: c += 1 else: ans += 1 if c>1: print(ans) else: print(-1)
for a in range(1,10): for b in range(1,10): print(a, end="") print("x", end="") print(b, end="") print("=", end="") print(a*b)
0
null
57,387,391,021,290
257
1
import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) INF=10**20 def main(): N,K,C=mi() S=list(input()) ok,ng = "o","x" OK = [] for i in range(N): if S[i] == ok: OK.append(i+1) # 1-index greeds = [OK[0]] for i in range(1,len(OK)): x = OK[i] if x - greeds[-1] > C: greeds.append(x) if len(greeds) > K: break inv_greeds = [OK[-1]] inv_OK = OK[::-1] for i in range(1,len(OK)): x = inv_OK[i] if -x + inv_greeds[-1] > C: inv_greeds.append(x) if len(inv_greeds) > K: break if len(greeds) < K or len(inv_greeds) < K: exit() greeds = greeds[:K] inv_greeds = inv_greeds[:K][::-1] # print(greeds,inv_greeds) for i in range(len(greeds)): if greeds[i] == inv_greeds[i]: print(greeds[i]) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys N,K,C=map(int, sys.stdin.readline().split()) S=sys.stdin.readline().strip() #左から L=[] over=-1 L_cnt=0 for i,x in enumerate(S): if x=="o" and over<i: L.append(i) L_cnt+=1 if L_cnt==K: break over=i+C #右から R=[] over=-1 R_cnt=0 for i,x in enumerate(S[::-1]): if x=="o" and over<i: R.append(N-1-i) R_cnt+=1 if R_cnt==K: break over=i+C L.sort() R.sort() for x,y in zip(L,R): if x==y: print x+1
1
40,932,585,969,460
null
182
182
while True: try: a,b = map(int,raw_input().split(' ')) print len(str(a+b)) except: break
while True: try: a,b = map(int, input().split()) d = 0 s = sum([a,b]) while (s): s //= 10 d += 1 print(d) except EOFError: break
1
119,703,868
null
3
3
import math a = raw_input() for i, b in enumerate(a.split()): if i==0: W=int(b) elif i==1: H=int(b) elif i==2: x=int(b) elif i==3: y=int(b) else: r=int(b) if r<=x<=W-r and r<=y<=H-r: print 'Yes' else: print 'No'
num = list(map(int,input().split())) circle_px = num[2] + num[4] circle_mx = num[2] - num[4] circle_py = num[3] + num[4] circle_my = num[3] - num[4] if(circle_px <= num[0] and circle_mx >= 0 and circle_py <= num[1] and circle_py >= 0): print("Yes") else: print("No")
1
444,142,488,372
null
41
41
raw_input() a = raw_input().split(" ") a.reverse() print " ".join(a)
import sys def value(w,n,P): tmp_w = 0 k = 1 for i in range(n): if tmp_w + w[i] <= P: tmp_w += w[i] else: tmp_w = w[i] k += 1 return k def test(): inputs = list(map(int,sys.stdin.readline().split())) n = inputs[0] k = inputs[1] w = [] max = 0 sum = 0 for i in range(n): w.append(int(sys.stdin.readline())) if w[i] > max: max = w[i] sum += w[i] while max != sum: mid = (max + sum) // 2 if value(w,n,mid) > k: max = mid + 1 else: sum = mid print(max) if __name__ == "__main__": test()
0
null
528,841,060,100
53
24
n = int(input()) lst = [int(i) for i in input().split()] dic = {} for i in range(n): if lst[i] not in dic: dic[lst[i]] = [1, 0, 0] else: dic[lst[i]][0] += 1 dic[lst[i]][1] = dic[lst[i]][0] * (dic[lst[i]][0] - 1) // 2 dic[lst[i]][2] = (dic[lst[i]][0] - 1) * (dic[lst[i]][0] - 2) // 2 #print(dic) count = 0 for value in dic.values(): count += value[1] for i in range(n): m = lst[i] count -= dic[m][1] count += dic[m][2] print(count) count += dic[m][1] count -= dic[m][2]
n = int(input()) xmin = int(n/1.08) xmax = int((n+1)/1.08) if n%27 == 0: print(xmax) elif (n+1)%27 == 0: print(":(") elif xmin == xmax: print(":(") else: print(xmax)
0
null
87,038,515,750,592
192
265
# Aizu Problem ALDS_1_4_C: Dictionary import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") D = set() N = int(input()) for _ in range(N): cmd, string = input().split() if cmd == "insert": D.add(string) elif cmd == "find": print("yes" if string in D else "no")
def main(): n = int(input()) dictionary = set() for _ in range(n): order, code = input().split() if order == 'insert': dictionary.add(code) elif order == 'find': if code in dictionary: print('yes') else: print('no') else: raise Exception('InputError') if __name__ == '__main__': main()
1
77,816,766,960
null
23
23
n, t = map(int, input().split()) dish = [list(map(int, input().split())) for _ in range(n)] dish.sort(key=lambda x: x[0]) dp = [[0 for _ in range(3005)] for _ in range(3005)] ans = 0 for i in range(n): for j in range(t): dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) nj = j + dish[i][0] if nj < t: dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + dish[i][1]) now = dp[i][t- 1] + dish[i][1] ans = max(ans, now) print(ans)
def resolve(): X = int(input()) m = 100 cnt = 0 while m < X: m += m//100 cnt += 1 print(cnt) if '__main__' == __name__: resolve()
0
null
89,083,449,421,220
282
159
def merge(a, l, m, r): global count Left = a[l:m] Left.append(1e10) Right = a[m:r] Right.append(1e10) i, j = 0, 0 for k in range(l, r): count += 1 if Left[i] <= Right[j]: a[k] = Left[i] i += 1 else: a[k] = Right[j] j += 1 def sort(a, l, r): if r-l > 1: m = (l+r)//2 sort(a, l, m) sort(a, m, r) merge(a, l, m, r) count=0 n=int(input()) a=[int(i) for i in input().split()] sort(a, 0, n) print(*a) print(count)
import sys import math input = sys.stdin.readline a, b = list(map(int, input().split())) print(a * b // math.gcd(a, b))
0
null
56,695,467,261,500
26
256
s=input() count=0 for i in s: count+=1 print('x'*count)
for i in range(len(input()) - 1):print("x",end="") print("x")
1
72,680,897,755,662
null
221
221
s, t = input().split() a, b = map(int, input().split()) u = input() if s == u: x = a - 1 y = b else: x = a y = b - 1 print(x, y)
def solve(): print([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][int(input())-1]) return 0 if __name__ == '__main__': solve()
0
null
61,198,657,457,170
220
195
import itertools n = int(input()) p = tuple([int(i) for i in input().split()]) q = tuple([int(i) for i in input().split()]) lst = list(itertools.permutations(list(range(1, n + 1)))) print(abs(lst.index(p) - lst.index(q)))
import bisect N=int(input()) L=list(map(int,input().split())) L=sorted(L) ans=0 for i in range(N-1): for k in range(i+1,N-1): a=L[i]+L[k] b=bisect.bisect_left(L,a) ans=ans+(b-k-1) print(ans)
0
null
136,260,745,225,040
246
294
a,b,c=map(int,input().split()) d=0 while a!=b+1: if c%a==0:d+=1 a+=1 print(d)
a, b, c = (int(i) for i in input().split()) divisor = 0 for i in range(a, b + 1): if c % i == 0: divisor += 1 print(str(divisor))
1
561,556,218,080
null
44
44
N=input() N=N[::-1]+"0" ans=0 up=0 for i,n in enumerate(N): d=int(n)+up if d>5 or (d==5 and i<len(N)-1 and int(N[i+1])>=5): ans+=(10-d) up=1 else: ans+=d up=0 print(ans)
import statistics from collections import Counter N = int(input()) A = [list(map(int, input().split(" "))) for i in range(N)] xMIN = [] xMAX = [] for i in range(N): xMIN.append(A[i][0]) for j in range(N): xMAX.append(A[j][1]) if N % 2 != 0: medianMIN = statistics.median(xMIN) medianMAX = statistics.median(xMAX) print(int(medianMAX-medianMIN+1)) else: medianMIN_LOW = statistics.median_low(xMIN) medianMIN_HIGH = statistics.median_high(xMIN) medianMAX_LOW = statistics.median_low(xMAX) medianMAX_HIGH = statistics.median_high(xMAX) print((medianMAX_LOW+medianMAX_HIGH)-(medianMIN_LOW+medianMIN_HIGH)+1)
0
null
43,986,833,297,430
219
137
a,b=map(int,input().split()) s=[''.join([str(a)]*b),''.join([str(b)]*a)] print(sorted(s)[0])
#!/usr/bin/env python3 def main(): N, K = map(int, input().split()) A = [int(x) - 1 for x in input().split()] way = [] seen = [False for _ in [0] * (2 * 10 ** 5 + 1)] now = 0 for _ in range(K): if seen[now]: loop_start = way.index(now) loop = way[loop_start:] K -= len(way[:loop_start]) now = loop[K % len(loop)] break way.append(now) seen[now] = True now = A[now] print(now + 1) if __name__ == '__main__': main()
0
null
53,833,421,463,250
232
150
while True: H, W = map(int, input().split()) if not(H or W): break print('#' * W) for i in range(H-2): print('#', end='') for j in range(W-2): print('.', end='') print('#') print('#' * W, end='\n\n')
while True: a=[int(x) for x in input().split()] if a[0]==a[1]==0: break else: print("#"*a[1]) for i in range(a[0]-2): print("#"+"."*(a[1]-2)+"#") print("#"*a[1]) print("")
1
820,125,079,036
null
50
50
x,y=map(int, input().split()) a = int(x * y) b=int(2*x+2*y) #print(x,y) print(a,b)
import sys a, b = [ int( val ) for val in sys.stdin.readline().split( " " ) ] print( "{} {}".format( a*b, a*2+b*2 ) )
1
306,559,956,518
null
36
36
num = input().split() nums = [] for i in num: nums.append(int(i)) #print(nums) price = [300000, 200000, 100000] result = [] #2 3 4 5 6 for i in nums: if int(i) > 3: result.append(0) else: result.append(price[i-1]) value = result[0] + result[1] if value == 600000: print("1000000") else: print(value)
x, y = map(int, input().split()) a = max(0, 100000 * (4 - x)) b = max(0, 100000 * (4 - y)) c = 400000 if x == 1 and y == 1 else 0 print(a + b + c)
1
140,287,362,693,540
null
275
275
x = int(input()) for i in range(2,10): if i <= x/200 < i+1: print(10-i)
#coding:utf-8 #1_6_A 2015.4.1 input() numbers = input().split() numbers.reverse() print(' '.join(numbers))
0
null
3,805,330,145,930
100
53
''' Created on 2020/08/29 @author: harurun ''' def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write A,B,N=map(int,pin().split()) x=min(B-1,N) ans=int(A*x/B)-A*int(x/B) print(ans) return main() #解説AC
def solve(): A,B,N = [int(i) for i in input().split()] x = min(B-1,N) print(int(A*x/B)-A*int(x/B)) if __name__ == "__main__": solve()
1
28,176,663,582,272
null
161
161
N, M = map(int, input().split()) An = [int(i) for i in input().split()] total = sum(An) if total > N: print('-1') else: print(N - total)
def main(): n, m = map(int, input().split(" ")) a =list(map(int, input().split(" "))) if n - sum(a) <0: print(-1) else: print(n-sum(a)) if __name__ == "__main__": main()
1
31,895,965,771,780
null
168
168
N,T = map(int,input().split()) AB = [list(map(int,input().split())) for i in range(N)] AB.sort(key=lambda x: x[0]) #print(AB) W = T + 1 def dp(AB,W): N = len(AB) DP = [[0]*W for i in range(N+1)] for i in range(N): for w in range(W): if w != W-1: if AB[i][0] <= w: DP[i+1][w] = max(DP[i][w-AB[i][0]]+AB[i][1],DP[i][w]) else: DP[i+1][w] = DP[i][w] else: DP[i+1][w] = max(DP[i][w-1]+AB[i][1],DP[i][w]) return DP DP1 = dp(AB,W) ans = DP1[N][T] print(ans)
"""AtCoder.""" n = int(input()[-1]) s = None if n in (2, 4, 5, 7, 9): s = 'hon' elif n in (0, 1, 6, 8): s = 'pon' elif n in (3,): s = 'bon' print(s)
0
null
85,367,105,370,368
282
142
num = map(int, raw_input().split(' ')) print num[0] * num[1], 2 * (num[0] + num[1])
# -*- coding: utf-8 -*- import sys w = sys.stdin.readline().strip() count = 0 while True: t = list(map(str, input().split())) if 'END_OF_TEXT' in t: break for i in range(len(t)): if t[i].lower() == w: count += 1 print(count)
0
null
1,066,180,896,076
36
65
from collections import deque n = int(input()) d = deque() for i in range(n): c = input() if ' ' in c: c, num = c.split() if c == 'insert': d.appendleft(num) elif c == 'delete' and num in d: d.remove(num) else: if c == 'deleteFirst' and d: d.popleft() elif c == 'deleteLast' and d: d.pop() print(' '.join(d))
# -*- coding: utf-8 -*- import sys import os from collections import deque N = int(sys.stdin.readline()) q = deque() lines = sys.stdin.readlines() for s in lines: lst = s.split() command = lst[0] if command == 'insert': q.appendleft(lst[1]) elif command == 'delete': try: q.remove(lst[1]) except Exception: pass elif command == 'deleteFirst': q.popleft() elif command == 'deleteLast': q.pop() print(*q)
1
53,381,746,538
null
20
20
import numpy as np from fractions import gcd def lcm(a,b): return a*b//gcd(a,b) N,M=map(int,input().split()) a=[i//2 for i in map(int,input().split())] b=np.array(a) cnt=0 while all(b%2==0): b//=2 if any(b%2==0): print(0) exit() ans=1 for i in a: ans=lcm(ans,i) print((M//ans-1)//2+1)
INF=float('inf') def solve1(): dp=[[-INF]*2 for i in range(N+1)] dp[0][0]=0;dp[1][0]=A[0];dp[2][1]=A[1] for i in range(N): if dp[i+1][0]==-INF: if i-1>=0: dp[i+1][0]=max(dp[i+1][0],dp[i-1][0]+A[i]) if dp[i+1][1]==-INF: if i-1>=0: dp[i+1][1]=max(dp[i+1][1],dp[i-1][1]+A[i]) if i-2>=0: dp[i+1][1]=max(dp[i+1][1],dp[i-2][0]+A[i]) print(max(dp[N][1],dp[N-1][0])) return def solve2(): dp=[[-INF]*3 for i in range(N+1)] dp[0][0]=0;dp[1][0]=A[0];dp[2][1]=A[1];dp[3][2]=A[2] for i in range(N): if dp[i+1][0]==-INF: if i-1>=0: dp[i+1][0]=max(dp[i+1][0],dp[i-1][0]+A[i]) if dp[i+1][1]==-INF: if i-1>=0: dp[i+1][1]=max(dp[i+1][1],dp[i-1][1]+A[i]) if i-2>=0: dp[i+1][1]=max(dp[i+1][1],dp[i-2][0]+A[i]) if dp[i+1][2]==-INF: if i-1>=0: dp[i+1][2]=max(dp[i+1][2],dp[i-1][2]+A[i]) if i-2>=0: dp[i+1][2]=max(dp[i+1][2],dp[i-2][1]+A[i]) if i-3>=0: dp[i+1][2]=max(dp[i+1][2],dp[i-3][0]+A[i]) print(max(dp[N][2],dp[N-1][1],dp[N-2][0])) return N=int(input()) A=list(map(int,input().split())) if N%2==0: solve1() else: solve2()
0
null
69,486,280,798,858
247
177
import heapq H, N = map(int, input().split()) A = [] #W B = [] #V for i in range(N): ai, bi = map(int, input().split()) A += [ai] B += [bi] maxA = max(A) dp = [[0 for j in range(H+maxA+1)]for i in range(N+1)] for j in range(1, H+maxA+1): dp[0][j] = float('inf') for i in range(N): for j in range(H+maxA+1): if j - A[i] < 0: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + B[i]) ans = float('inf') for j in range(H, H+maxA+1): ans = min(ans, dp[N][j]) print(ans)
n = int(input()) p = [] q = [] r = [] for i in range(2,(int(n**0.5)+1)): N = n if N%i == 0: p.append(i) for i in range(2,(int(n**0.5)+1)): N = n - 1 if N%i == 0: r.append(i) if i != N//i: r.append(N//i) for i in range(len(p)): N = n while N % p[i] == 0: N = N / p[i] if N % p[i] == 1: q.append(p[i]) for i in range(len(r)): if n % r[i] == 1: q.append(r[i]) if n == 2: print(1) else: print(len(q)+2)
0
null
61,261,616,185,588
229
183
# Dice I class Dice: def __init__(self, a1, a2, a3, a4, a5, a6): # サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字) self.v = [a5, a1, a2, a6] # 縦方向 self.h = [a4, a1, a3, a6] # 横方向 # print(self.v, self.h) # サイコロの上面の数字を表示 def top(self): return self.v[1] # サイコロを北方向に倒す def north(self): newV = [self.v[1], self.v[2], self.v[3], self.v[0]] self.v = newV self.h[1] = self.v[1] self.h[3] = self.v[3] return self.v, self.h # サイコロを南方向に倒す def south(self): newV = [self.v[3], self.v[0], self.v[1], self.v[2]] self.v = newV self.h[1] = self.v[1] self.h[3] = self.v[3] return self.v, self.h # サイコロを東方向に倒す def east(self): newH = [self.h[3], self.h[0], self.h[1], self.h[2]] self.h = newH self.v[1] = self.h[1] self.v[3] = self.h[3] return self.v, self.h # サイコロを西方向に倒す def west(self): newH = [self.h[1], self.h[2], self.h[3], self.h[0]] self.h = newH self.v[1] = self.h[1] self.v[3] = self.h[3] return self.v, self.h d = input().rstrip().split() dice1 = Dice(d[0], d[1], d[2], d[3], d[4], d[5]) command = list(input().rstrip()) # print(command) for i, a in enumerate(command): if a == 'N': dice1.north() elif a == 'S': dice1.south() elif a == 'E': dice1.east() elif a == 'W': dice1.west() print(dice1.top())
class Dice: def __init__(self, faces): self.faces = tuple(faces) def roll_north(self): self.faces = (self.faces[1], self.faces[5], self.faces[2], self.faces[3], self.faces[0], self.faces[4]) def roll_south(self): self.faces = (self.faces[4], self.faces[0], self.faces[2], self.faces[3], self.faces[5], self.faces[1]) def roll_west(self): self.faces = (self.faces[2], self.faces[1], self.faces[5], self.faces[0], self.faces[4], self.faces[3]) def roll_east(self): self.faces = (self.faces[3], self.faces[1], self.faces[0], self.faces[5], self.faces[4], self.faces[2]) def number(self, face_id): return self.faces[face_id - 1] dice = Dice(list(map(int, input().split()))) commands = input() for c in commands: if c == "N": dice.roll_north() elif c == "S": dice.roll_south() elif c == "W": dice.roll_west() elif c == "E": dice.roll_east() print(dice.number(1))
1
226,200,418,080
null
33
33
total_stack = [] single_stack = [] def main(): input_line = input() total = 0 for i,s in enumerate(input_line): if s == "\\": total_stack.append(i) elif s == "/" and len(total_stack) != 0: a = total_stack.pop() total += i - a area = 0 while len(single_stack) != 0 and a < single_stack[-1][0]: area += single_stack.pop()[1] single_stack.append([a, area + i - a]) print(total) print(' '.join([str(len(single_stack))] + [str(i[1]) for i in single_stack])) if __name__ == '__main__': main()
s=input() s+='?' x=[] ch=1 if s[0]=='>': x.append(0) for i in range(1,len(s)): if s[i]==s[i-1]: ch+=1 else: x.append(ch) ch=1 x.append(0) a=0 for i in range(len(x)-1): if i%2==0 and x[i]<=x[i+1]: a+=x[i+1] for j in range(x[i]): a+=j for j in range(x[i+1]): a+=j elif i%2==0 and x[i]>x[i+1]: a+=x[i] for j in range(x[i]): a+=j for j in range(x[i+1]): a+=j if (len(x)-1)%2==1: for j in range(x[len(x)-1]): a+=j print(a)
0
null
78,255,315,839,470
21
285
def main(): a, b, c = map(int, input().split()) if (a == b and b != c) or (b == c and a != b) or (a == c and a != b): print('Yes') else: print('No') main()
def main(): a,b,c = map(int,input().split()) if a == b and b==c : print("No") return if a != b and b != c and a != c: print("No") return print("Yes") return if __name__ == "__main__": main()
1
68,050,544,431,912
null
216
216
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: next = self.find(self.parent[x]) self.parent[x] = next return next def size(self, x): return self.tree_size[self.find(x)] def same(self, x, y): if self.find(x) == self.find(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)]))
from itertools import chain import sys def main(): N = int(input()) # TLEs were caused mostly by slow input (1s+) # S = list(input() for _ in range(N)) S = sys.stdin.read().split('\n') print(solve(S)) def get_count(args): s, result = args # messy input to work with map. cum_sum = 0 for c in s: if c == ')': cum_sum -= 1 else: cum_sum += 1 result[0] = max(result[0], -cum_sum) result[1] = result[0] + cum_sum return result # Made-up name, don't remember what to call this. Radix-ish def silly_sort(array, value_min, value_max, get_value): if len(array) == 0: return cache = [None for _ in range(value_max - value_min + 1)] for elem in array: # Assume elem[0] is the value value = get_value(elem) - value_min if cache[value] is None: cache[value] = [] cache[value].append(elem) for values in cache: if values is None: continue for value in values: yield value def solve(S): counts = [[0,0] for _ in range(len(S))] counts = list(map(get_count, zip(S,counts))) first_group = [] second_group = [] min_first_group = float('inf') max_first_group = 0 min_second_group = float('inf') max_second_group = 0 for c in counts: if c[0] - c[1] <= 0: first_group.append(c) max_first_group = max(max_first_group, c[0]) min_first_group = min(min_first_group, c[0]) else: second_group.append(c) max_second_group = max(max_second_group, c[1]) min_second_group = min(min_first_group, c[1]) first_group = silly_sort(first_group, min_first_group, max_first_group, lambda c: c[0]) second_group = reversed(list(silly_sort(second_group, min_second_group, max_second_group, lambda c: c[1]))) order = chain(first_group, second_group) cum_sum = 0 for c in order: cum_sum -= c[0] if cum_sum < 0: return 'No' cum_sum += c[1] if cum_sum == 0: return 'Yes' return 'No' if __name__ == '__main__': main()
0
null
13,947,223,147,890
84
152
import math X = int(input()) i = 1 while True: net = (i * X)/360 if math.floor(net) == math.ceil(net): break else: i+=1 print(i)
X = int(input()) if X < 30: print('No') else: print('Yes')
0
null
9,486,151,067,120
125
95
a=int(input()) b=a//200 if b==2: print(8) elif b==3: print(7) elif b==4: print(6) elif b==5: print(5) elif b==6: print(4) elif b==7: print(3) elif b==8: print(2) elif b==9: print(1)
N, = map(int, input().split()) print(10-N//200)
1
6,709,754,867,460
null
100
100
import math pai = math.pi r = float(input()) print('{:.6f} {:.6f}'.format(pai*r**2,2*pai*r))
import math r = float(input()) pi = float(math.pi) print("{0:.8f} {1:.8f}".format(r*r*pi,r * 2 * pi))
1
643,606,507,790
null
46
46
n = int(input()) s = input() r = s.count('R') g = s.count('G') b = s.count('B') cnt = 0 for i in range(n): j = 1 while i + 2*j <= n-1: # if s[i] != s[i+j] and s[i+j] != s[i+2*j] and s[i+2*j] != s[i]: if len({s[i], s[i+j], s[i+2*j]}) == 3: cnt += 1 j += 1 print(r*g*b-cnt)
import sys def main(): for line in iter(sys.stdin.readline, ""): #print (line) a = line.rstrip("\n") tmp = a.split(" ") a = int(tmp[0]) b = int(tmp[1]) n = int(tmp[2]) cnt = 0 for i in range(1, n+1): if (n % i == 0) and (a <= i and i <= b): cnt = cnt + 1 #print (i) print (cnt) if __name__ == "__main__": main()
0
null
18,495,828,949,050
175
44
ii = 1 while True: x = input() if x == '0': break print("Case {0}: {1}".format(ii, x)) ii = ii + 1
count = 0 while True: count += 1 num = int(input()) if num == 0: break print("Case", str(count) + ":", num)
1
490,323,484,268
null
42
42
n = int(input()) a = list(map(int, input().split())) a = [(i, j) for i, j in enumerate(a, start=1)] a.sort(key=lambda x: x[1]) a = [str(i) for i, j in a] print(' '.join(a))
n = int(input()) a = list(map(int, input().split())) # a = np.array(a) # ans = [] # while a.min() != 9999999: # min_index = a.argmin() # ans.append(min_index+1) # a[min_index] = 9999999 # print(' '.join([str(_) for _ in ans])) l = [] for i in range(n): l.append([i+1, a[i]]) sl = sorted(l, key=lambda x: x[1]) sl0 = [r[0] for r in sl] print(' '.join([str(_) for _ in sl0]))
1
180,778,444,018,398
null
299
299
def bingo(): for i in a: if i[0] in b and i[1] in b and i[2] in b: return True for i in range(3): if a[0][i] in b and a[1][i] in b and a[2][i] in b: return True tmp=[(a[i][i] in b) for i in range(3)] if tmp.count(True)==3: return True tmp=[a[0][2] in b,a[1][1] in b,a[2][0] in b] if tmp.count(True)==3: return True a=[[int(i)for i in input().split()]for j in range(3)] n=int(input()) b=[int(input())for i in range(n)] bingo=bingo() print("Yes" if bingo else "No")
H = [[0] * 3 for i in range(3)] A = [[0] * 3 for i in range(3)] A[0][0],A[0][1],A[0][2] = map(int,input().split()) A[1][0],A[1][1],A[1][2] = map(int,input().split()) A[2][0],A[2][1],A[2][2] = map(int,input().split()) N = int(input()) for i in range(N): ball = int(input()) for l in range(3): for c in range(3): if A[l][c] == ball: H[l][c] = 1 #print(H) flag = 0 for l in range(3): if H[l][0] ==1 and H[l][1] ==1 and H[l][2] ==1: flag =1 for c in range(3): if H[0][c] ==1 and H[1][c] ==1 and H[2][c] ==1: flag =1 if H[0][0]==1 and H[1][1]==1 and H[2][2]== 1: flag = 1 if H[2][0]==1 and H[1][1]==1 and H[0][2]== 1: flag = 1 if flag == 1: print("Yes") else: print("No") #A[2][1] = 10 #print(A) #print(flag)
1
59,813,235,774,080
null
207
207
N, K = map(int, input().split()) R, S, P = map(int, input().split()) T = input() point = [0]*K flag = ["a"]*K k = -1 #K本のリストを用意する 剰余系の中で、同じ手が連続するとき、1、3、5、...は別の手に変える for i in range(N): k = (k+1)%K #mod if T[i] == "r": if flag[k] == "r": flag[k] = "a" else: flag[k] = "r" point[k] += P elif T[i] == "s": if flag[k] == "s": flag[k] = "a" else: flag[k] = "s" point[k] += R if T[i] == "p": if flag[k] == "p": flag[k] = "a" else: flag[k] = "p" point[k] += S print(sum(point))
# coding: utf-8 # マージソート INFTY = int(1E20) count = 0 def merge(A, left, mid, right): global INFTY global count L = [i for i in A[left:mid]] R = [i for i in A[mid:right]] L.append(INFTY) R.append(INFTY) idx_L = 0 idx_R = 0 for idx in range(left, right): count += 1 if L[idx_L] <= R[idx_R]: A[idx] = L[idx_L] idx_L += 1 else: A[idx] = R[idx_R] idx_R += 1 def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) else: return if __name__ == "__main__": n = int(input()) A = [int(i) for i in input().split()] mergeSort(A, 0, n) print(' '.join([str(i) for i in A])) print(count)
0
null
53,760,863,455,680
251
26
import math def main(): A, B, N = map(int, input().split()) x = min([B-1, N]) print(int(math.floor(A * x / B) - A * math.floor(x / B))) if __name__ == '__main__': main()
import math A, B, N = map(int, input().split()) n = min(N, B-1) print(math.floor(A * n / B))
1
28,288,796,995,120
null
161
161
n = int(input()) print(max((n - 1)// 2, 0))
A, B, C = map(int, input().split()) temp = B B = A A = temp temp = C C = A A = temp print(str(A) + " " + str(B) + " " + str(C))
0
null
95,604,256,742,486
283
178
# 10-Structured_Program_I-Print_a_Frame.py # ?????¬??????????????? # ??\????????????????????????H cm ?????? W cm ???????????????????????°????????????????????????????????? # ########## # #........# # #........# # #........# # #........# # ########## # ?????????????????? 6 cm ?????? 10 cm ???????????¨?????????????????? # Input # ??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§?????? # H W # H, W ?????¨?????? 0 ?????¨????????\?????????????????¨???????????? # ????????????????????¨??????????????\???????????¶??????3 ??? H, W ??? 100 ??§?????? # Output # ?????????????????????????????????????????? H cm ?????? W cm ????????????????????????????????? # ?????????????????????????????????????????????????????\?????????????????? # Constraints # H, W ??? 300 # Sample Input # 3 4 # 5 6 # 3 3 # 0 0 # Sample Output # #### # #..# # #### # ###### # #....# # #....# # #....# # ###### # ### # #.# # ### # a = [] # a = [ *map(int,input().split() ) ] H=[] W=[] while 1: temp = input().split() H.append( int(temp[0]) ) W.append( int(temp[1]) ) if H[-1]==0 and W[-1]==0: break; for i in range( len(H) ): for j in range( H[i] ): #???????¨???°????§? if j==0 or j==H[i]-1: #????????????????????????????????? for k in range( W[i] ): print("#",end="") else: print("#",end="") for k in range(W[i]-2): print(".",end="") print("#",end="") print("") #???????¨???°????????? if i !=len(H)-1: print("")
while True: h,w=map(int,input().split()) if h==0 and w==0: break for y in range(h): for x in range(w): if y==0 or y==h-1 or x==0 or x==w-1: print("#",end='') else: print(".",end='') print() print()
1
825,603,529,702
null
50
50
W,H,X,Y,R=map(int,input().split()) ok=True if X<R or W-R<X: ok=False if Y<R or H-R<Y: ok=False if ok: print("Yes") else: print("No")
x = raw_input() W, H, x, y, r = x.split() W = int(W) H = int(H) x = int(x) y = int(y) r = int(r) if (x - r < 0) or (y - r < 0) or (x + r > W) or (y + r > H): print "No" else: print "Yes"
1
444,435,488,298
null
41
41
s = input() q = [] for i in s: q.append(int(i)) if sum(q)%9 == 0: print('Yes') else:print('No')
while True: H, W = list(map(int, input().split())) if H == 0 and W == 0: break else: for i in range(H): if i == 0 or i == (H-1): print('#'*W) else: print('#'+'.'*(W-2)+'#') print()
0
null
2,638,954,861,792
87
50
n = int(input()) S = set(list(map(int,input().split()))) q = int(input()) T = list(map(int,input().split())) ans = 0 for t in T: if t in S: ans += 1 print(ans)
s = input() if(s[0].islower()): print('a') else: print('A')
0
null
5,762,522,252,610
22
119
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)
n = int(input()) s, t = [], [] for i in range(n): si, ti = input().split() ti = int(ti) s.append(si) t.append(ti) x = input() bit = 0 ans = 0 for i in range(n): if s[i] == x: bit = 1 else: if bit == 1: ans += t[i] print(ans)
0
null
52,407,274,284,678
105
243
i = int(input()) print(i + i*i + i*i*i)
X,N = map(int,input().split()) N_List = list(map(int,input().split())) ct = 0 pos = 0 while True: if pos == 0: if X not in N_List: ans = X break else: pos += 1 elif pos > 0: if X-pos not in N_List: ans = X - pos break elif X + pos not in N_List: ans = X + pos break else: pos += 1 print(ans)
0
null
12,140,475,552,348
115
128
n = int(input()) a = [int(x) for x in input().split()] q = int(input()) bc=[] for i in range(q): bc.append([int(x) for x in input().split()]) a_cnt=[0]*(10**5+1) for i in range(len(a)): a_cnt[a[i]]+=1 a_goukei=sum(a) for gyou in range(q): a_goukei+=(bc[gyou][1]-bc[gyou][0])*a_cnt[bc[gyou][0]] print(a_goukei) a_cnt[bc[gyou][1]]+=a_cnt[bc[gyou][0]] a_cnt[bc[gyou][0]]=0
N = int(input()) A = list(map(int,input().split())) tot = sum(A) D = {} for i in range(N): a = A[i] if a not in D: D[a] = 0 D[a] += 1 Q = int(input()) for _ in range(Q): b,c = map(int,input().split()) if b not in D: print(tot) else: d = c-b if c in D: n = D[b] D[c] += D[b] del D[b] else: n = D[b] D[c] = D[b] del D[b] tot += n*d print(tot)
1
12,161,121,904,152
null
122
122
import sys, math from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from itertools import combinations, permutations, product from heapq import heappush, heappop from functools import lru_cache input = sys.stdin.readline rs = lambda: input().strip() ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) mat = lambda x, y, v: [[v]*y for _ in range(x)] ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)] mod = 1000000007 sys.setrecursionlimit(1000000) N = ri() C = rs() l, r = 0, N-1 ans = 0 while l < r: while C[l] == 'R' and l < N-1: l += 1 while C[r] == 'W' and r > 0: r -= 1 if l >= r: break l += 1 r -= 1 ans += 1 print(ans)
from itertools import accumulate n,m,k = map(int,input().split()) deskA = list(map(int,input().split())) deskB = list(map(int,input().split())) cumA = [0] + list(accumulate(deskA)) cumB = [0] + list(accumulate(deskB)) ans = 0 j = m for i in range(n+1): if cumA[i] > k: continue while cumA[i] + cumB[j] > k: j -= 1 ans = max(i+j,ans) print(ans)
0
null
8,569,734,829,084
98
117
import sys # import re # import math import collections # import decimal # import bisect # import itertools # import fractions # import functools import copy # import heapq # import decimal # import statistics import queue sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 MOD2 = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): n = ni() d = na() c = collections.Counter(d) lim = max(c) flg = False if d[0] != 0: flg = True if c[0] != 1: flg = True for i in range(lim + 1): if i not in c.keys(): flg = True break if flg: print(0) exit(0) ans = 1 for i in range(2, lim + 1): ans *= pow(c[i - 1], c[i], MOD2) ans %= MOD2 print(ans) if __name__ == '__main__': main()
import collections n = int(input()) d = list(map(int,input().split())) mod = 998244353 ans = 0 c = collections.Counter(d) if c[0] == 1 and d[0] == 0: ans = 1 for i in range(1,max(d)+1): if c[i] == 0: ans = 0 break ans *= pow(c[i-1],c[i],mod) ans %= mod print(ans%mod)
1
154,754,118,397,550
null
284
284
# coding: utf-8 # Here your code ! import math i = input() count=0 def isPrime(x): global count if x == 2: return True if x>2 and x%2==0: return False i = 3 while i<=math.sqrt(x): if x%i==0: return False i+=2 return True for j in range(int(i)): j=int(input()) if isPrime(j): count+=1 print(count)
def isPrimeNum(in_num): if in_num <= 1: return False elif in_num == 2: return True elif in_num % 2 == 0: return False else: if pow(2, in_num-1, in_num) == 1: return True else: return False num_len = int(input()) cnt = 0 for i in range(num_len): num = int(input()) if isPrimeNum(num)==True: cnt = cnt + 1 print(str(cnt))
1
9,590,588,448
null
12
12
N, K = map(int, input().split()) H = list(map(int, input().split())) ANS = sum(x >= K for x in H) print(ANS)
capstr='ABCDEFGHIJKLMNOPQRSTUVWXYZ' s=input() h=list(capstr) if(h.count(s)==1): print('A') else: print('a')
0
null
95,292,057,178,612
298
119
n, k =map(int,input().split()) MOD = 10**9 + 7 ans = 0 for i in range(k,n+2): L = (i-1)*i / 2 #初項0,末項l,項数iの等差数列の和 H = ((n-i)+(n+1))*i //2 #初項a,末項l,項数iの等差数列の和 ans += H - L + 1 ans %= MOD print(int(ans))
n = int(input()) nums = list(map(int, input().split())) result = "APPROVED" for num in nums: if (num % 2 == 0) and not ((num % 3 == 0) or (num % 5 == 0)): result = "DENIED" break print(result)
0
null
51,166,194,994,818
170
217
N = int(input()) A = list(map(int, input().split())) MOD = 10**9+7 num_one_for_digit = [0]*61 for i in range(N): b = bin(A[i])[2:].zfill(61) for d in range(61): if b[d] == "1": num_one_for_digit[d] += 1 ans = 0 t = 1 for d in range(60, -1, -1): n_1 = num_one_for_digit[d] ans += n_1 * (N - n_1) * t % MOD ans %= MOD t *= 2 print(ans%MOD)
def main(): import sys input = sys.stdin.readline n = int(input()) A = [int(x) for x in input().split()] ans = 0 mod = 10 ** 9 + 7 # 制約がai <= 2^60なので for d in range(61): # d桁目ごとに考える x = 0 for a in A: if (a >> d) & 1: x += 1 ans += x * (n-x) * 2**d ans %= mod print(ans) if __name__ == '__main__': main()
1
123,002,607,916,320
null
263
263
n,m,l=map(int,input().split()) A = [tuple(map(int,input().split())) for _ in range(n)] B = [tuple(map(int,input().split())) for _ in range(m)] BT = tuple(map(tuple,zip(*B))) for a in A: temp=[] for b in BT: temp.append(sum([x*y for (x,y) in zip(a,b)])) print(*temp)
# -*-coding:utf-8 def main(): while True: n, x = map(int, input().split()) if ((n == 0) and (x == 0)): break count = 0 for i in range(1, n+1): for j in range(1, n+1): for k in range(1, n+1): if((i<j) and (j<k) and i+j+k == x): count += 1 print(count) if __name__ == '__main__': main()
0
null
1,357,894,798,112
60
58
import sys input = sys.stdin.readline N = int(input()) S = input().rstrip() Q = int(input()) qs = [input().split() for i in range(Q)] class BinaryIndexedTree: def __init__(self,size): self.N = size self.bit = [0]*(size+1) def add(self,x,w): # 0-indexed x += 1 while x <= self.N: self.bit[x] += w x += (x & -x) def _sum(self,x): # 1-indexed ret = 0 while x > 0: ret += self.bit[x] x -= (x & -x) return ret def sum(self,l,r): # [l,r) return self._sum(r) - self._sum(l) def __str__(self): # for debug arr = [self.sum(i,i+1) for i in range(self.N)] return str(arr) bits = [BinaryIndexedTree(N+1) for i in range(26)] for i,c in enumerate(S): ci = ord(c) - ord('a') bits[ci].add(i,1) now = list(S) for a,b,c in qs: if a=='1': b = int(b) pi = ord(now[b-1]) - ord('a') bits[pi].add(b-1, -1) ci = ord(c) - ord('a') bits[ci].add(b-1, 1) now[b-1] = c else: b,c = int(b),int(c) cnt = 0 for i in range(26): cnt += int(bits[i].sum(b-1,c) > 0) print(cnt)
# セグメント木 最新バージョン #verify class SegTree(): # 1-indexed def __init__(self, lists, function, basement): self.n = len(lists) self.K = (self.n-1).bit_length() self.f = function self.b = basement self.seg = [basement]*(2**(self.K+1)+1) X = 2**self.K for i, v in enumerate(lists): self.seg[i+X] = v for i in range(X-1, 0, -1): self.seg[i] = self.f(self.seg[i << 1], self.seg[i << 1 | 1]) def update(self, k, value): X = 2**self.K k += X self.seg[k] = value while k: k = k >> 1 self.seg[k] = self.f(self.seg[k << 1], self.seg[(k << 1) | 1]) def query(self, L, R): num = 2**self.K L += num R += num vL = self.b vR = self.b while L < R: if L & 1: vL = self.f(vL, self.seg[L]) L += 1 if R & 1: R -= 1 vR = self.f(self.seg[R], vR) L >>= 1 R >>= 1 return self.f(vL, vR) def find_max_index(self, L, R, X): # [L,R)でX以下の物で最大indexを取得 return self.fMi(L, R, X, 1, 0, 2**self.K) def find_min_index(self, L, R, X): # [L,R) でX以下の物で最小のindexを取得する return self.fmi(L, R, X, 1, 0, 2**self.K) def fMi(self, a, b, x, k, l, r): if self.seg[k] > x or r <= a or b <= l: return -1 else: if k >= 2**self.K: return k-2**self.K else: vr = self.fMi(a, b, x, (k << 1) | 1, (l + r) // 2, r) if vr != -1: return vr return self.fMi(a, b, x, k << 1, l, (l + r) // 2) def fmi(self, a, b, x, k, l, r): if self.seg[k] > x or r <= a or b <= l: return -1 else: if k >= 2**self.K: return k-2**self.K else: vl = self.fmi(a, b, x, k << 1, l, (l+r)//2) if vl != -1: return vl return self.fmi(a, b, x, k << 1 | 1, (l+r)//2, r) N = int(input()) S = list(input()) Q = int(input()) que = [tuple(input().split()) for i in range(Q)] alpha = "abcdefghijklmnopqrstuvwxyz" Data = {alpha[i]: [0]*N for i in range(26)} for i in range(N): Data[S[i]][i] += 1 SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)} for X, u, v in que: if X == "1": u = int(u)-1 NOW = S[u] S[u] = v SEG[NOW].update(u, 0) SEG[v].update(u,1) else: s, t = int(u)-1, int(v)-1 res = 0 for j in range(26): res += SEG[alpha[j]].query(s, t+1) print(res)
1
62,497,177,476,860
null
210
210
alp = 'abcdefghijklmnopqrstuvwxyz' if input() in alp: print('a') else: print('A')
n = int(input()) ans = 0 for i in range(1, n): for j in range(1, n): if i*j>=n: break ans += 1 print(ans)
0
null
6,993,999,990,208
119
73
n = int(input()) p = 10 ** 9 + 7 all_ptn = 10 ** n anti_ptn = 2 * (9 ** n) - 8 ** n print((all_ptn - anti_ptn) % p)
NUM = 1000000007 N = int(input()) all_colab = pow(10, N) except_0or9_colab = pow(9, N) except_0and9_colab = pow(8, N) include_0and9_colab = all_colab - (2*except_0or9_colab - except_0and9_colab) print(include_0and9_colab % NUM)
1
3,200,796,603,228
null
78
78
def odd(num): return num//2+num%2 N=int(input()) num = odd(N)/N print("{:.10f}".format(num))
N = int(input()) print('{:.8f}'.format((N + 1) // 2 / N))
1
176,420,549,764,540
null
297
297
import math N, K = map(int,input().split()) logs = list(map(int,input().split())) a = 0 b = max(logs) b_memo = set() count=0 flg =0 while math.ceil(a) != math.ceil(b): c = (a+b)/2 times = [] for i in logs: times.append(math.floor(i/c)) if sum(times) > K: a = c else: b = c if b - a < 0.001: count +=1 if count >20: flg+=1 break if flg == 0: print(math.ceil(b)) else: a = math.ceil(a) times = [] for j in logs: times.append(math.floor(i/a)) if sum(times) > K: print(math.ceil(b)) else: print(math.ceil(a))
n,m,k=map(int,input().split()) mod=998244353 ans=0 fact=[1] * (n+1) # 階乗を格納するリスト factinv=[1] * (n+1) # 階乗を格納するリスト for i in range(n): fact[i+1] = fact[i] * (i+1) % mod # 階乗を計算 factinv[i+1] = pow(fact[i+1], mod-2, mod) # modを法とした逆元(フェルマーの小定理) def nCk(n,k): # 組み合わせ(mod)を返却する return fact[n] * factinv[n-k] * factinv[k] % mod for k_i in range(k+1): ans += m * pow(m-1, n-1-k_i, mod) * nCk(n-1, k_i) ans %= mod print (ans)
0
null
14,905,285,931,712
99
151
n_max, m_max, l_max = (int(x) for x in input().split()) a = [] b = [] c = [] for n in range(n_max): a.append([int(x) for x in input().split()]) for m in range(m_max): b.append([int(x) for x in input().split()]) for n in range(n_max): c.append( [sum(a[n][m] * b[m][l] for m in range(m_max)) for l in range(l_max)]) for n in range(n_max): print(" ".join(str(c[n][l]) for l in range(l_max)))
while True: h=[] S=input() if S=="-": break m=int(input()) for i in range(m): h=int(input()) if len(S)==h: pass else: S=S[h:]+S[:h] print(S)
0
null
1,677,304,730,360
60
66
N = int(input()) hash = {} end = int(N ** (1/2)) for i in range(2, end + 1): while N % i == 0: hash[i] = hash.get(i, 0) + 1 N = N // i if N != 1: hash[i] = hash.get(i, 0) + 1 count = 0 trans = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55] res = 0 for i in hash.values(): for j in range(len(trans)): if i > trans[j]: continue elif i == trans[j]: res += (j + 1) break else: res += j break print(res)
import sys from itertools import accumulate rm = lambda: map(int, sys.stdin.readline().split()) rl = lambda: list(map(int, sys.stdin.readline().split())) n, k = rm() a = [(i+1)/2 for i in rl()] a = [0] + list(accumulate(a)) ans = 0 for i in range(n-k+1): ans = max(ans, a[i+k] - a[i]) print(ans)
0
null
45,995,554,431,752
136
223
c=0 for i in range(int(input())): d1,d2=map(int,input().split()) if d1==d2: c+=1 if c==3: break else: c=0 print('Yes' if c==3 else 'No')
import math a,b,c=map(float,input().split()) C=math.radians(c) D=math.sin(C)*a*b S=D/2 E=a**2+b**2-2*a*b*math.cos(C) F=math.sqrt(E) L=a+b+F if C<90: h=b*math.sin(C) elif C==90: h=b else: h=b*math.sin(180-C) print(S,L,h)
0
null
1,323,461,162,840
72
30
n,a,b = map(int,input().split()) m = 10**9+7 def nCr(n_, r_, m_): c = min(r_ , n_ - r_) bunshi = 1 bunbo = 1 for i in range(1,c+1): bunshi = bunshi * (n_+1-i) % m_ bunbo = bunbo * i % m_ return bunshi * pow(bunbo, m_-2, m_) % m_ ans = pow(2,n,m)-1 ans -= nCr(n,a,m) ans %= m ans -= nCr(n,b,m) ans %= m print(ans)
#!/usr/bin/env python # -*- coding: utf-8 -*- N, M, K = map(int, input().split()) result = 0 # max a_time = list(map(int, input().split())) b_time = list(map(int, input().split())) sum = 0 a_num = 0 for i in range(N): sum += a_time[i] a_num += 1 if sum > K: sum -= a_time[i] a_num -= 1 break i = a_num j = 0 while i >= 0: while sum < K and j < M: sum += b_time[j] j += 1 if sum > K: j -= 1 sum -= b_time[j] if result < i + j: result = i + j i -= 1 sum -= a_time[i] print(result)
0
null
38,484,939,287,090
214
117
N = int(input()) if N == 1: print(0) else: mod = 10**9+7 print((10**N - (2*(9**N) - 8**N)) % mod)
n = int(input()) sum = 0 for i in range(n + 1): if i % 3 != 0 and i % 5 != 0 and i % 15 != 0: sum += i print(sum)
0
null
18,979,482,534,250
78
173
a, b, c = (int(x) for x in input().split()) if a > b: a, b = b, a if a > c: a, c = c, a if b > c: b, c = c, b print(a, b, c)
n = int(input()) answer = 0 for idx1 in range(1, n+1): for idx2 in range(1, ((n+1) // idx1) + 1): c = n - (idx1 * idx2) if 1 <= c < n: answer += 1 print(answer)
0
null
1,508,626,944,278
40
73
N, K = map(int, input().split()) P = list(map(int, input().split())) S = [0] sum_ = 0 for i, p in enumerate(P): sum_ += p S.append(sum_) max_sum = 0 for i in range(N-K+1): max_sum = max(max_sum, S[i+K] - S[i]) res = (max_sum + K) / 2 print(res)
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")
0
null
38,245,010,749,028
223
56
import sys import math from collections import defaultdict from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def main(): N = NI() ans = 0 for a in range(1, N): ans += N // a if N % a == 0: ans -= 1 print(ans) if __name__ == "__main__": main()
def get_sieve_of_eratosthenes(n): if not isinstance(n, int): raise TypeError("n is int-type.") if n < 2: raise ValueError("n is more than 2") data = [i for i in range(2, n + 1)] for d in data: data = [x for x in data if (x == d or x % d != 0)] return data p_list = get_sieve_of_eratosthenes(10**3) def factorization_counta(n): arr = [] temp = n for i in p_list: if i * i > n: break elif temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append(cnt) if temp != 1: arr.append(1) if arr == []: arr.append(1) return arr def main(): N = int(input()) ans = 1 for c in range(2, N): p = factorization_counta(c) tmp = 1 for v in p: tmp *= (v + 1) ans += tmp return ans if __name__ == '__main__': print(main())
1
2,596,104,370,872
null
73
73
import sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,K = LI() A = LI() ans = [] for i in range(K,N): if A[i-K] < A[i]: print('Yes') else: print('No')
n = int(input()) x = n%10 if (x == 2 or x == 4 or x == 5 or x == 7 or x == 9): print("hon") elif (x == 0 or x == 1 or x == 6 or x == 8): print("pon") else: print("bon")
0
null
13,103,371,704,566
102
142
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) n, k, c = nm() a = ns() ans = [] al = [] count = 0 dey = 1 for i in a: if i is "o" and count <= 0: al.append(dey) count = c + 1 dey += 1 count -= 1 ar = [] count = 0 dey = n for i in reversed(a): if i is "o" and count <= 0: ar.append(dey) count = c + 1 dey -= 1 count -= 1 al = al[:k] ar = ar[:k] for i in al: j = ar.pop(-1) if i == j: ans.append(i) for i in ans: print(i)
N, K, C = list(map(int, input().split())) S = input() work_day_min = [] work_day_max = [] for i in range(N): if S[i] == 'o': if i > 0 and len(work_day_min) > 0: if i - work_day_min[-1] <= C: continue work_day_min.append(i) if len(work_day_min) == K: break for i in range(N): if S[N - i - 1] == 'o': if i > 0 and len(work_day_max) > 0: if work_day_max[-1] - (N - i - 1) <= C: continue work_day_max.append(N - i - 1) if len(work_day_max) == K: break for i in range(K): if work_day_min[i] == work_day_max[K-i-1]: print(work_day_min[i]+1)
1
40,760,196,293,070
null
182
182
import numpy as np H, W, M = map(int, input().split()) col = np.zeros(H) row = np.zeros(W) memo = [] for i in range(M): h, w = map(int, input().split()) h -= 1 w -= 1 col[h] += 1 row[w] += 1 memo.append((h,w)) col_max = col.max() row_max = row.max() col_max_indexes = np.where(col == col_max)[0] row_max_indexes = np.where(row == row_max)[0] ans = col_max + row_max - 1 memo = set(memo) for c in col_max_indexes: for r in row_max_indexes: if (c,r) not in memo: ans = col_max + row_max print(int(ans)) exit() print(int(ans))
n = input() s, t = map(str, input().split()) for i in range(int(n)): print(s[i]+t[i], end = '')
0
null
58,520,108,666,554
89
255
# ABC153 # B Common Raccoon VS Monster h, n = map(int, input().split()) a = list(map(int, input().split())) s = sum(a) if h <= s: print("Yes") else: print("No")
H, N = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) print("Yes") if H - sum(A) <= 0 else print("No")
1
78,185,811,147,102
null
226
226
SN=[5,1,2,6] WE=[4,1,3,6] def EWSN(d): global SN,WE if d == "S" : SN = SN[3:4] + SN[0:3] WE[3] = SN[3] WE[1] = SN[1] elif d == "N": SN = SN[1:4] + SN[0:1] WE[3] = SN[3] WE[1] = SN[1] elif d == "E": WE = WE[3:4] + WE[0:3] SN[3] = WE[3] SN[1] = WE[1] elif d == "W": WE = WE[1:4] + WE[0:1] SN[3] = WE[3] SN[1] = WE[1] dice = list(map(int,input().split(" "))) op = input() for i in op: EWSN(i) print(dice[SN[1] - 1])
import sys data=list(map(int,input().split())) order=sys.stdin.readline() char_list=list(order) for i in char_list: if i=='N': k=data[0] m=data[4] data[0]=data[1] data[1]=data[5] data[4]=k data[5]=m elif i=='E': k=data[0] m=data[2] data[0]=data[3] data[2]=k data[3]=data[5] data[5]=m elif i=='S': k=data[0] m=data[1] data[0]=data[4] data[1]=k data[4]=data[5] data[5]=m elif i=='W': k=data[0] m=data[3] data[0]=data[2] data[2]=data[5] data[3]=k data[5]=m print(data[0])
1
234,557,146,122
null
33
33
import sys input = lambda: sys.stdin.readline().rstrip() def main(): s = input() days = ['','SAT','FRI','THU','WED','TUE','MON','SUN'] print(days.index(s)) if __name__ == '__main__': main()
x = input() youbi = { 'SUN': 7 , 'MON': 6 , 'TUE': 5 , 'WED': 4 , 'THU': 3 , 'FRI': 2 , 'SAT': 1 } print(youbi[x])
1
133,466,663,365,980
null
270
270
n=int(input()) if n%2==1: print(0) exit(0) n//=2 from math import floor,factorial ans=0 deno=5 while deno<=n: ans+=n//deno deno*=5 print(ans)
a,b=map(int,input().split()) if a<0 or a>9: print(-1) elif b<0 or b>9: print(-1) else: print(a*b)
0
null
137,291,907,085,190
258
286
number = input().split(" ") print(int(number[0]) * int(number[1]))
from numpy import* n,m,*a=int_(open(0).read().split()) a=int_(fft.irfft(fft.rfft(bincount(a,[1]*n,2**18))**2)+.5) c=0 for i in where(a>0)[0][::-1]: t=min(m,a[i]) c+=i*t m-=t if m<1:break print(c)
0
null
61,912,400,106,352
133
252
inputted = input().split() S = inputted[0] T = inputted[1] answer = T + S print(answer)
ls = list(map(str, input().split())) print(ls[1]+ls[0])
1
103,211,340,882,062
null
248
248
S=input() print(S[0]+S[1]+S[2])
a = input() print(a[0] + a[1] + a[2])
1
14,836,715,418,492
null
130
130
N = int(input()) A = list(map(int, input().split())) s = sum(A) r = 10**10 n = 0 for i in range(N-1): n += A[i] r = min(abs(s-n*2), r) print(r)
a,b=map(int,input().split()) l=list(map(int,input().split())) import itertools b=min(b,50) def ku(l): y=[0]*a for j,x in enumerate(l): y[max(0,j-x)]+=1 r=min(j+x,a-1) if r<a-1: y[r+1]-=1 return itertools.accumulate(y) for _ in range(b): l=ku(l) print(*l)
0
null
79,142,545,208,036
276
132
import sys,bisect sys.setrecursionlimit(15000) s = sys.stdin.readline().rstrip() st = [] ars = [] ar = 0 for i,c in enumerate(s): if c == "\\": st.append(i) elif c == "/": if st: j = st.pop() ar += i-j while ars and j < ars[-1][1]: ar0,_ = ars.pop() ar += ar0 ars.append([ar,j]) ar = 0 print(sum([ar for ar,_ in ars])) if len(ars)==0: print(0) else: print(len(ars)," ".join(map(str,[ar for ar,_ in ars])))
n = int(input()) output = 0 for i in range(n): if (i + 1) % 3 != 0 and (i + 1) % 5 != 0:output += i + 1 print(output)
0
null
17,453,625,652,712
21
173
mod = 1000000007 n,k = map(int, input().split()) d = [0]*(k+1) for i in range(1,k+1): d[i] = pow(k//i,n,mod) for i in range(k,0,-1): for j in range(2*i,k+1,i): d[i] -= d[j] d[i] %= mod ans = 0 for i in range(1,k+1): ans += d[i]*i ans %= mod print(ans)
from sys import stdin def main(): readline = stdin.readline n = int(readline()) s = tuple(readline().strip() for _ in range(n)) plus, minus = [], [] for c in s: if 2 * c.count('(') - len(c) > 0: plus.append(c) else: minus.append(c) plus.sort(key = lambda x: x.count(')')) minus.sort(key = lambda x: x.count('('), reverse = True) plus.extend(minus) sum = 0 for v in plus: for vv in v: sum = sum + (1 if vv == '(' else -1) if sum < 0 : return print('No') if sum != 0: return print('No') return print('Yes') if __name__ == '__main__': main()
0
null
30,046,983,060,640
176
152
n=int(input()) m=int(n/1.08) for i in range(-2,3): if int((m+i)*1.08)==n: print(m+i) exit() print(":(")
n = int(input()) res = -1 for x in range(1, n+1): if int(x * 1.08) == n: res = x if res == -1: print(":(") else: print(res)
1
126,066,092,948,530
null
265
265
while True: a=map(int,raw_input().split()) if a==[0,0]: break if a[0]>a[1]:print(str(a[1])+" "+str(a[0])) else: print(str(a[0])+" "+str(a[1]))
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())
1
512,704,278,240
null
43
43
import sys s2nn = lambda s: [int(c) for c in s.split(' ')] ss2nn = lambda ss: [int(s) for s in ss] ss2nnn = lambda ss: [s2nn(s) for s in ss] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) from collections import deque # 双方向キュー from collections import defaultdict # 初期化済み辞書 from heapq import heapify, heappush, heappop, heappushpop # プライオリティキュー from bisect import bisect_left, bisect_right # 二分探索 sys.setrecursionlimit(int(1e+6)) MOD = int(1e+9) + 7 #import numpy as np # 1.8.2 #import scipy # 0.13.3 def main(): N, K = i2nn() A = i2nn() # 選択の余地がない場合、全部掛けるしかない if N == K: n = 1 for a in A: n = (n * a) % MOD print(n) return Ap = [ n for n in A if n >= 0] An = [-n for n in A if n < 0] Ap.sort() Ap.reverse() An.sort() An.reverse() Np = len(Ap) Nn = len(An) # 結果はプラスにしたい。Aiが全部マイナスかつKが奇数だとNG # 結果をプラスにできない場合、絶対値を最小化する if N == Nn and K % 2 == 1: n = 1 A.sort() A.reverse() for i in range(K): n = (n * A[i]) % MOD print(n) return n = 1 k = K i = 0 j = 0 # 結果をプラスに場合、プラスを維持しつつ、絶対値を最大化する # Kは偶数で考えたい。Kが奇数のとき、一番大きな正の数を取る if k % 2 == 1: n = (n * Ap[i]) % MOD i += 1 k -= 1 while k > 0: if Np - i < 2: n = (n * An[j]) % MOD j += 1 n = (n * An[j]) % MOD j += 1 elif Nn - j < 2: n = (n * Ap[i]) % MOD i += 1 n = (n * Ap[i]) % MOD i += 1 else: np = Ap[i] * Ap[i+1] nn = An[j] * An[j+1] if np >= nn: n = (n * np) % MOD i += 2 else: n = (n * nn) % MOD j += 2 k -= 2 print(n) main()
N, K = map(int, input().split()) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 neg_a = sorted([a for a in A if a < 0], reverse=True) pos_a = sorted([a for a in A if a >= 0]) ans = 1 if len(pos_a) == 0 and K % 2 == 1: for a in neg_a[:K]: ans = ans * a % MOD print(ans) exit() while K > 0: if K == 1 or len(neg_a) <= 1: if len(pos_a) == 0: ans *= neg_a.pop() elif len(pos_a) > 0: ans *= pos_a.pop() K -= 1 elif len(pos_a) <= 1: ans *= neg_a.pop() * neg_a.pop() K -= 2 elif pos_a[-1] * pos_a[-2] > neg_a[-1] * neg_a[-2]: ans *= pos_a.pop() K -= 1 else: ans *= neg_a.pop() * neg_a.pop() K -= 2 ans %= MOD print(ans)
1
9,399,973,160,838
null
112
112
while True: s = input().split(" ") H = int(s[0]) W = int(s[1]) if H == 0 and W == 0: break for i in range(H): for j in range(W): if j == W-1: print("#") else: print("#",end="") print("")
while True: a=[int(x) for x in input().split()] if a[0]==a[1]==0: break else: for i in range(a[0]): print("#"*a[1]) print("")
1
784,167,101,510
null
49
49
n = int(input()) a = list(map(int, input().split())) l = [0] * n for i in range(n - 1): if a[i] > 0: l[a[i] - 1] += 1 for i in range(n): print(l[i])
from collections import Counter n = int(input()) a = list(map(int, input().split())) a += list(range(1,n+1)) a = Counter(a).most_common() a.sort() for i,j in a: print(j-1)
1
32,482,940,859,402
null
169
169
# C - Traveling Salesman around Lake k,n = map(int,input().split()) a = list(map(int,input().split())) bet = [a[0]+k-a[n-1]] for i in range(n-1): bet.append(a[i+1]-a[i]) print(k-max(bet))
K, N = map(int, input().split()) A = tuple(map(int, input().split())) maxd = K - A[-1] + A[0] for i in range(1, N): d = A[i] - A[i-1] maxd = max(maxd, d) ans = K - maxd print(ans)
1
43,426,018,821,172
null
186
186
#!/usr/bin/env python3 import sys MOD = 1000000007 # type: int class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] # 階乗を求めるためのキャッシュ self.invModulos = [0, 1] # n^-1のキャッシュ self.invFactorial_ = [1, 1] # (n^-1)!のキャッシュ def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0]*(n+1-len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n+1): prev = nextArr[i-initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0]*(n+1-len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n+1)): next = -self.invModulos[p % i]*(p//i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0]*(n+1-len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n+1): prev = nextArr[i-initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def choose_k_from_n(self, n, k): if k < 0 or n < k: return 0 k = min(k, n-k) f = self.factorial return f.calc(n)*f.invFactorial(max(n-k, k))*f.invFactorial(min(k, n-k)) % self.MOD def solve(N: int, K: int, A: "List[int]"): c = Combination(MOD) A.sort() minSum = 0 for i in range(N-K+1): remain = N-i-1 minSum = (minSum + A[i]*c.choose_k_from_n(remain, K-1)) % MOD maxSum = 0 A.reverse() for i in range(N-K+1): remain = N-i-1 maxSum = (maxSum + A[i]*c.choose_k_from_n(remain, K-1)) % MOD print((maxSum - minSum + MOD) % MOD) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, K, A) if __name__ == '__main__': main()
n = int(input()) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = map(int, input().split()) z = [0] * n w = [0] * n for i in range(n): z[i] = x[i] + y[i] w[i] = x[i] - y[i] cand1 = max(z) - min(z) cand2 = max(w) - min(w) print(max(cand1, cand2))
0
null
49,789,359,679,068
242
80
def solve(): N, K = list(map(int, input().split())) if(N >= K): tmp = N - ((N // K) * K) ans = min(tmp, abs(abs(tmp) - K)) elif(N < K): if(K <= 2*N): ans = abs(N - K) else: ans = abs(N) print(ans) if __name__ == "__main__": solve()
N,K=map(int,input().split()) if N%K != 0: if abs(K-N%K)<N: print(K-N%K) else: print(N) else: print(0)
1
39,141,173,336,368
null
180
180
s = input() t = input() ans = 1001001001 for i in range(len(s) - len(t) + 1): cnt = 0 for j in range(len(t)): if s[i + j] != t[j]: cnt += 1 if cnt <= ans: ans = cnt print(ans)
S = input() T = input() s = len(S) t = len(T) ans1 = 10000000 for i in range(s - t + 1): ans = 0 for j in range(t): if T[j] != S[i + j]: ans += 1 ans1 = min(ans, ans1) print(ans1)
1
3,695,620,674,214
null
82
82
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)
N = int(input()) MMM = map(int,input().split()) MM =list(MMM) mini = 2020202020 list1 = [] total = 0 for i in MM: total+=i list1.append(total) for i in list1: x = abs(total - 2*i) if mini > x: mini = x print(mini)
0
null
74,941,681,037,352
103
276
class BIT: def __init__(self, n): """ data : BIT木データ el : 元配列 """ self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) """A1 ~ Aiまでの累積和""" def Sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & (-i) #LSB(Least Significant Bit)の獲得:i&(-i) return s """Ai += x""" def Add(self, i, x): self.el[i] += x while i <= self.n: self.data[i] += x i += i & -i """Ai ~ Ajまでの累積和""" def Get(self, i, j=None): if j is None: return self.el[i] return self.Sum(j) - self.Sum(i) def ctoi(c): return ord(c) - 97 n = int(input()) s = list(input()) q = int(input()) bits = [BIT(n) for _ in range(26)] ans = [] for i in range(n): bits[ctoi(s[i])].Add(i+1, 1) for _ in range(q): line = list(input().split()) if line[0] == '1': idx = int(line[1]) bits[ctoi(s[idx-1])].Add(idx, -1) s[idx-1] = line[2] bits[ctoi(line[2])].Add(idx, 1) else: l,r = int(line[1]), int(line[2]) cnt = 0 for i in range(26): if bits[i].Get(l-1,r)!=0: cnt += 1 ans.append(cnt) for a in ans: print(a)
#!/usr/bin/env python3 import sys DEBUG = False class SegmentTree: # Use 1-based index internally def __init__(self, n, merge_func, fillval=sys.maxsize): self.n = 1 while self.n < n: self.n *= 2 self.nodes = [fillval] * (self.n * 2 - 1 + 1) # +1 for 1-based index self.merge_func = merge_func self.fillval = fillval def update(self, idx, val): idx += 1 # for 1-based index nodes = self.nodes mergef = self.merge_func idx += self.n - 1 nodes[idx] = val while idx > 1: # > 1 for 1-based index idx >>= 1 # parent(idx) = idx >> 1 for 1-based index segment tree nodes[idx] = mergef(nodes[idx << 1], nodes[(idx << 1) + 1]) # child(idx) = idx << 1 and idx << 1 + 1 def query(self, l, r): l += 1; r += 1 # for 1-based index l += self.n - 1 r += self.n - 1 acc = self.fillval while l < r: if l & 1: acc = self.merge_func(acc, self.nodes[l]) l += 1 if r & 1: acc = self.merge_func(acc, self.nodes[r - 1]) r -= 1 l >>= 1 r >>= 1 return acc def read(t = str): return t(sys.stdin.readline().rstrip()) def read_list(t = str, sep = " "): return [t(s) for s in sys.stdin.readline().rstrip().split(sep)] def dprint(*args, **kwargs): if DEBUG: print(*args, **kwargs) return def main(): read() s = read() a_ord = ord("a") bit_offsets = {chr(c_ord): c_ord - a_ord for c_ord in range(ord("a"), ord("z") + 1)} apps = SegmentTree(len(s), lambda x, y: x | y, 0) i = 0 for c in s: apps.update(i, 1 << bit_offsets[c]) i += 1 nr_q = read(int) for i in range(0, nr_q): q = read_list() if q[0] == "1": _, i, c = q # i_q in the question starts from 1, not 0 apps.update(int(i) - 1, 1 << bit_offsets[c]) else: _, l, r = q # l_q and r_q in the question start from 1, not 0 print(bin(apps.query(int(l) - 1, int(r) - 1 + 1)).count("1")) # query in the question includes both edges if __name__ == "__main__": main()
1
62,556,457,363,170
null
210
210
n = int(input()) s = input() #print(s) tot = s.count('R') * s.count('G') * s.count('B') #print(tot) for i in range(n): for d in range(1,n): j = i+d k = j+d if k > n-1: break if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]: tot -= 1 print(tot)
n=int(input()) s=input() r=s.count('R') g=s.count('G') b=s.count('B') ans=r*g*b for i in range(len(s)): for j in range(i+1,len(s)): if s[i]!=s[j]: k=j+j-i if k>=len(s): break else: if s[i]!=s[k] and s[j]!=s[k]: ans-=1 print(ans)
1
36,124,127,204,350
null
175
175
K = int(input()) s = input() n=len(s) def find_power(n,mod=10**9+7): powlist=[0]*(n+1) powlist[0]=1 powlist[1]=1 for i in range(2,n+1): powlist[i]=powlist[i-1]*i%(mod) return powlist def find_inv_power(n,mod=10**9+7): powlist=find_power(n) check=powlist[-1] first=1 uselist=[0]*(n+1) secondlist=[0]*30 secondlist[0]=check secondlist[1]=check**2 for i in range(28): secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7) a=format(10**9+5,"b") for j in range(30): if a[29-j]=="1": first=(first*secondlist[j])%(10**9+7) uselist[n]=first for i in range(n,0,-1): uselist[i-1]=(uselist[i]*i)%(10**9+7) return uselist mod = 10**9+7 NUM = (2*10**6)+100 p_lis=find_power(NUM,mod) ip_lis=find_inv_power(NUM,mod) def comb(n,r,mod=10**9+7): if n<r: return 0 elif n>=r: return (p_lis[n]*ip_lis[r]*ip_lis[n-r])%(mod) ans=0 for k in range(K+1): ans+=(comb(n-1+K-k,n-1)* pow(25,K-k,mod)* pow(26,k,mod)) print(ans%mod)
MOD = 10 ** 9 + 7 def solveBrute(K, S): # On the i-th iteration, dp[j] counts all strings of length i which contains S[:j] as a subsequence N = len(S) dp = [0] * (N + 1) dp[0] = 1 for i in range(N + K): nextDp = [0] * (N + 1) for j in range(N): nextDp[j] += dp[j] * 25 nextDp[j + 1] += dp[j] nextDp[N] += dp[N] * 26 dp = nextDp for j in range(N + 1): dp[j] %= MOD # print(dp) return dp[N] def solveBrute2(K, S): import numpy as np def matrixPower(mat, k): assert k >= 0 if k == 0: return np.eye(mat.shape[0], dtype=np.int64) if k == 1: return mat temp = matrixPower(mat, k // 2) ret = (temp @ temp) % MOD if k % 2: return (ret @ mat) % MOD return ret # For intution, can interpret the bruteforce as a matrix multiplication: # {{0, 0, 0, 1}} . MatrixPower[{{25, 0, 0, 0}, {1, 25, 0, 0}, {0, 1, 25, 0}, {0, 0, 1, 26}}, 8] . {{1}, {0}, {0}, {0}} # https://www.wolframalpha.com/input/?i=%7B%7B0%2C+0%2C+0%2C+1%7D%7D+.+MatrixPower%5B%7B%7B25%2C+0%2C+0%2C+0%7D%2C+%7B1%2C+25%2C+0%2C+0%7D%2C+%7B0%2C+1%2C+25%2C+0%7D%2C+%7B0%2C+0%2C+1%2C+26%7D%7D%2C+8%5D+.+%7B%7B1%7D%2C+%7B0%7D%2C+%7B0%7D%2C+%7B0%7D%7D N = len(S) mat = 25 * np.eye(N + 1, dtype=np.int64,) mat[N][N] += 1 for i in range(N): mat[i + 1][i] = 1 vec = np.zeros((N + 1, 1), dtype=np.int64) vec[0] = 1 res = matrixPower(mat, N + K) @ vec return int(res[N]) % MOD def solve(K, S): def modInverse(a, p): # Fermat's little theorem, a**(p-1) = 1 mod p return pow(a, p - 2, p) # Precompute all factorials fact = [1] for i in range(1, 2 * (10 ** 6) + 1): fact.append((fact[-1] * i) % MOD) def nCr(n, r, p=MOD): # Modulo binomial coefficients return (fact[n] * modInverse(fact[r], p) * modInverse(fact[n - r], p)) % p total = 0 N = len(S) for i in range(N, N + K + 1): total += nCr(N + K, i) * pow(25, N + K - i, MOD) total %= MOD return total (K,) = [int(x) for x in input().split()] S = input() ans = solve(K, S) # assert ans == solveBrute(K, S) == solveBrute2(K, S) print(ans)
1
12,757,070,750,890
null
124
124
N = int(input()) a = [int(i) for i in input().split()] cnt = 0 for i,v in enumerate(a,1): if i%2 != 0 and v%2 != 0: cnt += 1 print(cnt)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n = int(readline()) a = list(map(int, readline().split())) ans = 0 for i, x in enumerate(a, 1): if i % 2 == 1 and x % 2 == 1: ans += 1 print(ans) if __name__ == '__main__': main()
1
7,772,043,951,690
null
105
105
from collections import defaultdict (h,n),*ab = [list(map(int, s.split())) for s in open(0)] mxa = max(a for a,b in ab) dp = defaultdict(lambda: float('inf')) dp[0] = 0 for i in range(1, h+mxa): dp[i] = min(dp[i-a] + b for a,b in ab) print(min(v for k,v in dp.items() if k>=h))
import sys input = lambda: sys.stdin.readline().rstrip() INF = 10 ** 9 + 7 H, N = map(int, input().split()) AB = [[] for _ in range(N)] for i in range(N): AB[i] = list(map(int, input().split())) def solve(): dp = [INF] * (H + 1) dp[H] = 0 for h in range(H, 0, -1): if dp[h] == INF: continue next_dp = dp for i in range(N): a, b = AB[i] hh = max(0, h - a) next_dp[hh] = min(dp[hh], dp[h] + b) dp = next_dp print(dp[0]) if __name__ == '__main__': solve()
1
80,791,975,897,792
null
229
229
h,n = map(int,input().split()) a = list(map(int,input().split())) print("Yes" if sum(a)>=h else "No")
H,N=map(int, input().split()) A=list(map(int, input().split())) print('Yes' if sum(A) >= H else 'No')
1
78,192,691,332,520
null
226
226
x,y,z=map(int, input().split()) if x<=y<=z: print(x,y,z) elif x<=z<=y: print(x,z,y) elif y<=z<=x: print(y,z,x) elif y<=x<=z: print(y,x,z) elif z<=x<=y: print(z,x,y) else: print(z,y,x)
N = list(map(int, input().split(' '))) N.sort() print('%d %d %d' % (N[0], N[1], N[2]))
1
424,393,833,992
null
40
40
d = int(input()) if d % 2 == 0: print(d//2) else: print((d//2)+1)
N=int(input()) alst=list(map(int,input().split())) i=1 for a in alst: if a==i: i+=1 i-=1 if i>0: print(N-i) else: print(-1)
0
null
87,252,506,295,912
206
257
""" Template written to be used by Python Programmers. Use at your own risk!!!! Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces). """ import sys import bisect import heapq # from math import * from collections import defaultdict as dd # defaultdict(<datatype>) Free of KeyError. from collections import deque # deque(list) append(), appendleft(), pop(), popleft() - O(1) from collections import Counter as c # Counter(list) return a dict with {key: count} from itertools import combinations as comb from bisect import bisect_left as bl, bisect_right as br, bisect # sys.setrecursionlimit(2*pow(10, 6)) # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") mod = pow(10, 9) + 7 mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(var): sys.stdout.write(var) def l(): return list(map(int, data().split())) def sl(): return list(map(str, data().split())) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)] n, p = sp() s = data() answer = 0 if p == 2: for i in range(n): if (ord(s[i])-ord('0')) % 2 == 0: answer += (i+1) elif p == 5: for i in range(n): if int(s[i]) % 5 == 0: answer += (i+1) else: dp = dd(int) dp[0] += 1 a, tens = 0, 1 for i in range(n-1, -1, -1): a = (a + int(s[i]) * tens) % p answer += dp[a] dp[a] += 1 tens = (tens * 10) % p out(str(answer)) exit(0)
n,p=map(int,input().split()) s=input() ans=0 if p==2 or p==5: for i in range(n): if int(s[i])%p==0: ans+=i+1 else: M=[0]*p M[0]=1 tmp=0 for i in range(n): tmp+=(int(s[-i-1])*pow(10,i,p)) tmp%=p ans+=M[tmp] M[tmp]+=1 print(ans)
1
58,240,424,753,708
null
205
205
import math pages = int(input()) print(math.ceil(pages/2))
import sys n = int(sys.stdin.readline().rstrip("\n")) if n % 2 == 0: print(n // 2) else: print(n // 2 + 1)
1
58,958,895,363,020
null
206
206