code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
t1,t2=map(int,input().split()) a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) d1=t1*a1+t2*a2 d2=t1*b1+t2*b2 import sys if d1>d2: dif=d1-d2 gap=(b1-a1)*t1 elif d1<d2: dif=d2-d1 gap=(a1-b1)*t1 else: print('infinity') sys.exit() if (b1-a1)*(b2-a2)>0 or (b1-a1)*(d2-d1)>0: print(0) sys.exit() if gap%dif!=0: print(gap//dif*2+1) else: print(gap//dif*2)
T1, T2 = [int(i) for i in input().split()] A1, A2 = [int(i) for i in input().split()] B1, B2 = [int(i) for i in input().split()] d1 = T1*(A1-B1) d2 = T2*(B2-A2) if d1 == d2: print('infinity') if d1 * (d2 - d1) < 0: print(0) if d1 * (d2 - d1) > 0: if d1 % (d2 - d1) != 0: print(d1 // (d2 - d1) * 2+ 1) else: print(d1 // (d2 - d1) * 2)
1
131,731,985,043,770
null
269
269
taro = 0 hanako = 0 n = int(input()) for _ in range(n): taro_card, hanako_card = input().split() if taro_card > hanako_card: taro += 3 elif taro_card < hanako_card: hanako += 3 else: taro += 1 hanako += 1 print(taro, hanako)
n=int(input()) t_won=0 h_won=0 for _ in range(n): t_wd,h_wd = input().split() if t_wd > h_wd: t_won += 1 elif t_wd < h_wd: h_won += 1 print(t_won*3 + (n-t_won-h_won), h_won*3 + (n-t_won-h_won))
1
1,978,777,354,008
null
67
67
from sys import setrecursionlimit, exit setrecursionlimit(1000000000) def main(): n = int(input()) a = [(int(v), i) for i, v in enumerate(input().split())] a.sort(reverse=True) dp = [[0] * (n + 1) for _ in range(n + 1)] dp[0][0] = a[0][0] * (n - 1 - a[0][1]) dp[0][1] = a[0][0] * a[0][1] for i, v in enumerate(a[1:]): dp[i+1][0] = dp[i][0] + v[0] * abs(n - 1 - (i + 1) - v[1]) dp[i+1][i+2] = dp[i][i+1] + v[0] * abs(v[1] - (i + 1)) for j in range(1, i + 2): dp[i+1][j] = max( dp[i][j] + v[0] * abs(n - 1 - (i + 1) + j - v[1]), dp[i][j-1] + v[0] * abs(v[1] - (j - 1))) ans = -float('inf') for i in dp[n-1]: ans = max(ans, i) print(ans) main()
def main(): N = int(input()) INF = float('inf') A = [(i+1, a) for i, a in enumerate(map(int, input().split()))] A = sorted(A, key=lambda x: x[1], reverse = True) dp = [[-INF] * (N+1) for _ in range(N+1)] dp[0][0] = 0 for s in range(1, N+1): for l in range(s+1): r = s - l dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0])) ans = 0 for m in range(N): if(dp[m][N-m] > ans): ans = dp[m][N-m] print(ans) main()
1
33,525,049,339,480
null
171
171
#!python3 LI = lambda: list(map(int, input().split())) # input N, P = LI() S = input() def solve2(): ans = 0 for i in range(N): if int(S[i]) % 2 == 0: ans += i + 1 return ans def solve5(): ans = 0 for i in range(N): if int(S[i]) % 5 == 0: ans += i + 1 return ans def solve(): d = [0] * P d[0] = 1 w = 0 ans = 0 m = 1 for s in S[::-1]: x = int(s) v = x * m % P w = (w + v) % P ans += d[w] d[w] += 1 m = 10 * m % P return ans def main(): if P == 2: ans = solve2() elif P == 5: ans = solve5() else: ans = solve() print(ans) if __name__ == "__main__": main()
from collections import Counter def mpow(a,b,mod): ret=1 while b>0: if b&1: ret=(ret*a)%mod a=(a*a)%mod b>>=1 return ret n,p=map(int,input().split()) s=[int(i) for i in input()] if p==2 or p==5: ans=0 for i in range(n): if s[i]%p==0: ans+=i+1 print(ans) else: ans=0 d=Counter() d[0]+=1 num=0 for i in range(n-1,-1,-1): num=(num+s[i]*mpow(10,n-1-i,p))%p ans+=d[num] d[num]+=1 print(ans)
1
58,072,791,975,328
null
205
205
word = input() if word[-1] == 's': word += "e" print(word + "s")
S = input() if S[-1] != 's': S = S + 's' elif S[-1] == 's': S = S + 'es' print(S)
1
2,406,412,443,040
null
71
71
n, m = map(int, input().split()) a = list(map(int, input().split())) dp = [0] + [float('inf')]*(n) for i in range(m): for j in range(a[i],n+1): dp[j] = min(dp[j],dp[j-a[i]]+1) print(dp[-1])
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) A, B = input().split() B = int(''.join(B.split('.'))) print(int(A)*B//100)
0
null
8,274,727,088,992
28
135
import math while True: n = input() if n == "0": break else: score = list(map(float, input().split())) m = sum(score)/len(score) for i in range(len(score)): score[i] = (score[i]-m)**2 answer = math.sqrt(sum(score)/len(score)) print(answer)
X=input().split(" ") print(int(X[0])*int(X[1]))
0
null
8,061,981,935,958
31
133
# Union Find # xの根を求める def find(x): if par[x] < 0: return x else: tank = [] while par[x] >= 0: tank.append(x) x = par[x] for elt in tank: par[elt] = x return x # xとyの属する集合の併合 def unite(x, y): x = find(x) y = find(y) if x == y: return False else: # sizeの大きいほうがx if par[x] > par[y]: x, y = y, x par[x] += par[y] par[y] = x return True # xとyが同じ集合に属するかの判定 def same(x, y): return find(x) == find(y) # xが属する集合の個数 def size(x): return -par[find(x)] # 初期化 # 根なら-size,子なら親の頂点 n,m = map(int,input().split()) par = [-1] * n ans = 0 for i in range(m): X,Y = map(int,input().split()) unite(X-1,Y-1) for i in range(n): ans = max(size(i),ans) print(ans)
[print(y) for y in sorted([int(input()) for x in range(10)], reverse=True)[:3]]
0
null
2,006,579,043,392
84
2
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = min(a) + min(b) for i in range(M): x, y, c = map(int, input().split()) ans = min(ans, a[x-1] + b[y-1] - c) print(ans)
#test N,K = map(int,input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) AF = [A[i]*F[i] for i in range(N)] l = -1 r = max(AF) while r-l > 1: x = (l+r)//2 k =0 #スコアをx以下にするのに必要な最小コストを算出 for i in range(N): if AF[i]<=x: continue else: k += A[i]-x//F[i] if k <= K: r = x else: l=x print(r)
0
null
109,337,800,392,652
200
290
n, q = list(map(int, input().split())) que = [] for _ in range(n): name, time = input().split() que.append([name, int(time)]) elapsed_time = 0 while que: name, time = que.pop(0) dt = min(q, time) time -= dt elapsed_time += dt if time > 0: que.append([name, time]) else: print (name, elapsed_time)
from functools import reduce n = int(input()) a = list(map(int, input().split())) b = reduce(lambda ac, x: ac ^ x, a) print(*map(lambda x: x ^ b, a))
0
null
6,345,169,377,120
19
123
# -*- coding: utf-8 -*- import sys import os import math a, b = list(map(int, input().split())) # a?????§????????????????????? if b > a: a, b = b, a def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) result = gcd(a, b) print(result)
import math as m def main(): L = int(input()) print(m.pow(L/3, 3)) if __name__ == '__main__': main()
0
null
23,670,579,375,754
11
191
t1, t2 = map(int,input().split()) a1, a2 = map(int,input().split()) b1, b2 = map(int,input().split()) a1 = t1*a1 a2 = t2*a2 b1 = t1*b1 b2 = t2*b2 if (a1 + a2) == (b1 + b2): print('infinity') exit(0) elif (a1 + a2) > (b1 + b2): a1, b1 = b1, a1 a2, b2 = b2, a2 if b1 > a1: print(0) exit(0) tmp00 = a1 - b1 tmp01 = b1 + b2 - a1 - a2 ans = tmp00 // tmp01 * 2 + 1 if tmp00 % tmp01 == 0: ans -= 1 print(ans)
n = int(input()) for i in range(1, 50000): if i * 108 // 100 == n: print(i) exit() print(':(')
0
null
128,538,483,807,580
269
265
N = int(input()) print(len({ input() for i in range(N) }))
N = int(input()) S = [] for _ in range(N): S.append(input()) ans = set(S) print(len(ans))
1
30,028,765,543,660
null
165
165
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush import math #from math import gcd #inf = 10**17 #mod = 10**9 + 7 n,k,c = map(int, input().split()) s = input().rstrip() left = [0]*n day = 0 temp = 0 while day < n: if s[day] == 'o': temp += 1 left[day] = temp for i in range(c): if day+i+1 < n: left[day+i+1] = temp day += c else: left[day] = temp day += 1 right = [0]*n day = n-1 temp = 0 while 0 <= day: if s[day] == 'o': temp += 1 right[day] = temp for i in range(c): if day-i-1 >= 0: right[day-i-1] = temp day -= c else: right[day] = temp day -= 1 res = [] for i in range(n): if s[i] == 'o': if i-c-1 < 0: pre = 0 else: pre = left[i-c-1] if i+c+1 >= n: pos = 0 else: pos = right[i+c+1] if pre + pos == k-1: res.append(i+1) for i in range(len(res)): if i-1>=0: l = res[i-1] else: l = -1000000 if i+1<len(res): r = res[i+1] else: r = 10000000 if res[i]-l>c and r-res[i] > c: print(res[i]) if __name__ == '__main__': main()
#from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 #R = 998244353 def ddprint(x): if DBG: print(x) n,k,c = inm() s = ins() l = [0]*n r = [0]*n for i in range(n): if s[i]=='x': l[i] = l[max(0,i-1)] else: l[i] = max(l[max(0,i-1)], (l[i-c-1]+1) if i>c else 1) for i in range(n-1,-1,-1): if s[i]=='x': r[i] = r[min(n-1,i+1)] else: r[i] = max(r[min(n-1,i+1)], (r[i+c+1]+1) if i<n-c-1 else 1) #ddprint(l) #ddprint(r) ans = [] for i in range(n): if s[i]=='o' and \ (l[i-1] if i>0 else 0)+(r[i+1] if i<n-1 else 0)==k-1: ans.append(i+1) for x in ans: print(x)
1
40,545,492,221,838
null
182
182
n=input() ans=0 if n=="0": print("Yes") else: for i in n: ans+=int(i) if ans%9==0: print("Yes") else: print("No")
number = list(input()) sum = 0 for i in number: sum += int(i) if (sum % 9) == 0 : print("Yes") else: print("No")
1
4,389,038,716,670
null
87
87
import sys import string s = sys.stdin.read().lower() for c in string.ascii_lowercase: print(c, ":", s.count(c))
a,b=map(int, raw_input().split()) if a==b: print "a == b" elif a>b: print "a > b" else: print "a < b"
0
null
1,006,375,862,440
63
38
import sys from functools import reduce def gcd(a, b): return gcd(b, a % b) if b else abs(a) def lcm(a, b): return abs(a // gcd(a, b) * b) n, m, *a = map(int, sys.stdin.read().split()) def main(): for i in range(n): a[i] //= 2 b = set() for x in a: cnt = 0 while x % 2 == 0: x //= 2 cnt += 1 b.add(cnt) if len(b) == 2: print(0); return l = reduce(lcm, a, 1) res = (m // l + 1) // 2 print(res) if __name__ == '__main__': main()
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): N, K = LI() A = LI() # 最大の長さがxになるような切断回数 def cut_num(x): ret = sum([math.ceil(i / x) - 1 for i in A]) return ret ng = 0 ok = max(A) while abs(ok-ng)>10**(-6): m = (ng+ok)/2 if cut_num(m) <= K: ok = m else: ng = m print(math.ceil(ok)) if __name__ == '__main__': resolve()
0
null
54,021,342,854,532
247
99
n= int(input()) list=input() strlist=list.split(' ') output='' for i in range(n): output=output+strlist[0][i]+strlist[1][i] print(output)
N=int(input()) S,T=map(str,input().split()) def ans148(N:int, S:str, T:str): newstr="" for i in range(0,N): newstr=newstr+S[i]+T[i] return newstr print(ans148(N,S,T))
1
112,179,130,172,150
null
255
255
import sys read = sys.stdin.read #readlines = sys.stdin.readlines def main(): x = int(input()) if x >= 30: print('Yes') else: print('No') if __name__ == '__main__': main()
import math k=int(input()) ans=0 for a in range(1,k+1): for b in range(1,k+1): tmp=math.gcd(a,b) for c in range(1,k+1): ans+=math.gcd(tmp,c) print(ans)
0
null
20,711,206,009,352
95
174
N, K = map(int, input().split()) R, S, P = map(int, input().split()) T = input() points = {'r': P, 's': R, 'p': S} is_changed = [False] * K + [False] * (N - K) score = 0 for i in range(K): score += points[T[i]] for i in range(K, N): if T[i] == T[i - K] and not is_changed[i - K]: is_changed[i] = True else: score += points[T[i]] print(score)
S=input();print(sum(a!=b for a,b in zip(S,S[::-1]))//2)
0
null
113,275,854,658,810
251
261
n = int(input()) total = 0 for i in range(n): a,b = map(int, input().split()) if a == b: total += 1 if total == 3: break else: total = 0 if total == 3: print('Yes') else: print('No')
s = list(input()) sur_list = [0 for i in range(2019)] sur = 0 keta = 1 ans = 0 s.reverse() for i in range(len(s)): keta = (keta*10)%2019 sur_list[sur] += 1 sur = (int(s[i]) * keta + sur) % 2019 ans += sur_list[sur] print(ans)
0
null
16,535,916,422,432
72
166
n,k,s = map(int, input().split()) if s == 10**9: ansl = [] for i in range(n): if i < k: ansl.append(s) else: ansl.append(1) print(*ansl) else: ansl = [] for i in range(n): if i < k: ansl.append(s) else: ansl.append(10**9) print(*ansl)
n, x, m = map(int, input().split()) ans = [] c = [0]*m flag = False for i in range(n): if c[x] == 1: flag = True break ans.append(x) c[x] = 1 x = x**2 % m if flag: p = ans.index(x) l = len(ans) - p d, e = divmod(n-p, l) print(sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e])) else: print(sum(ans))
0
null
46,686,845,841,874
238
75
from collections import deque s = deque(input()) q = int(input()) flag = True for _ in range(q): temp = input().split() if len(temp) == 1: flag = not flag else: if flag: if temp[1] == "1": s.appendleft(temp[2]) else: s.append(temp[2]) else: if temp[1] == "1": s.append(temp[2]) else: s.appendleft(temp[2]) if flag: print("".join(s)) else: print("".join(list(s)[::-1]))
s = int(input()) a = [0] * (s+1) if s == 1: print(0) else: a[0]=1 a[1]=0 a[2]=0 mod = 10**9+7 for i in range(3,s+1): a[i] = a[i-1]+a[i-3] print(int(a[s] % mod))
0
null
30,290,329,863,260
204
79
list =[] i=0 index=1 while(index != 0): index=int(input()) list.append(index) i +=1 for i in range(0,i): if list[i] == 0: break print("Case",i+1,end='') print(":",list[i])
input() myarr = list(map(int, input().split())) for i in range(len(myarr)): for j in range(i, 0,-1): if myarr[j] < myarr[j-1]: t = myarr[j] myarr[j] = myarr[j-1] myarr[j-1] = t else: break print(" ".join(map(str, myarr)))
0
null
251,248,959,540
42
10
# encoding:utf-8 while True: L = list(map(int, input().split(" "))) if L[0] == 0 and L[1] == 0: break L.sort() print("{0} {1}".format(L[0],L[1]))
a,b = map(int,input().split()) print(-1) if a > 9 or b > 9 else print(a*b)
0
null
79,326,454,974,130
43
286
from bisect import bisect_right n, d, a = map(int, input().split()) xh = sorted(list(map(int, input().split())) for _ in range(n)) x = [0] * (n + 1) h = [0] * (n + 1) s = [0] * (n + 1) for i, (f, g) in enumerate(xh): x[i], h[i] = f, g x[n] = 10 ** 10 + 1 ans = 0 for i in range(n): if i > 0: s[i] += s[i - 1] h[i] -= s[i] if h[i] > 0: num = 0 - - h[i] // a ans += num s[i] += num * a j = bisect_right(x, x[i] + d * 2) s[j] -= num * a print(ans)
k = int(input()) a, b = map(int, input().split()) print('NG' if b // k == (a - 1) // k else 'OK')
0
null
54,045,666,381,728
230
158
#------------------------------------------------------------------------------- # coding: utf-8 # Created: 16/12/2015 import sys io = sys.stdin while True: arr = io.readline().split() h, w = int(arr[0]), int(arr[1]) if h==0 and w ==0 : break for x in xrange(h): print "#"*w print pass
while True: H, W = map(int, input().split()) if H == 0 and W == 0 : break for j in range(H): for i in range(W): print('#',end='') print() print() if H == 0 and W == 0 : break
1
763,105,566,212
null
49
49
N= int(input()) S = input() abc = "ABC" ans = 0 j = 0 for i in range(N): if S[i] == abc[j]: j += 1 if S[i] == "C": j = 0 ans += 1 elif S[i] == "A": j = 1 else: j = 0 print(ans)
n = int(input()) s = input() ans = 0 for i in range(n-2): if s[i:i+3] == "ABC": ans += 1 print(ans)
1
99,011,485,187,160
null
245
245
import sys def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 h, w = LI() if h == 1 or w == 1: print(1) else: if (h * w) % 2 == 0: print(int(h * w / 2)) else: print(int(h * w / 2 + 1))
N = input() S,T = input().split() txt = '' for si,ti in zip(S,T): txt += si+ti print(txt)
0
null
81,667,649,723,698
196
255
h, w = map(int,input().split()) s = [input() for i in range(h)] def f(i, j): t = [[-1]*w for j in range(h)] t[i][j] = 0 q = [(i,j)] while q: y, x = q.pop(0) if y - 1 >= 0 and s[y-1][x] != "#" and t[y-1][x] == -1: t[y-1][x] = t[y][x] + 1 q.append((y-1,x)) if y + 1 < h and s[y+1][x] != "#" and t[y+1][x] == -1: t[y+1][x] = t[y][x]+1 q.append((y+1,x)) if x - 1 >= 0 and s[y][x-1] != "#" and t[y][x-1] == -1: t[y][x-1] = t[y][x] + 1 q.append((y,x-1)) if x + 1 < w and s[y][x+1] != "#" and t[y][x+1] == -1: t[y][x+1] = t[y][x] + 1 q.append((y,x+1)) return max(max(tt) for tt in t) result = 0 for i in range(h): for j in range(w): if s[i][j] != "#": result = max(result,f(i,j)) print(result)
from collections import defaultdict, deque h, w = map(int, input().split()) tizu = [input() for _ in range(h)] ans = 0 directions = [[1, 0], [-1, 0], [0, 1], [0, -1]] for i in range(h): for j in range(w): if tizu[i][j] == "#": continue check = [[False for _ in range(w)] for _ in range(h)] check[i][j] = True queue = deque() queue.append([i, j]) queue.append(0) while queue: pos = queue.popleft() ans_sub = queue.popleft() for dh, dw in directions: nh = pos[0] + dh nw = pos[1] + dw if nh == -1 or nh == h or nw == -1 or nw == w: continue if tizu[nh][nw] == "#": continue if check[nh][nw]: continue check[nh][nw] = True queue.append([nh, nw]) queue.append(ans_sub + 1) ans = max(ans, ans_sub) print(ans)
1
94,989,976,568,970
null
241
241
import math import collections N,M=map(int,input().split()) A=list(map(int,input().split())) A.sort() cumax=(2*10**5)+10 cuml=[0]*cumax #print(A) ind=0 l=[] c=collections.Counter(A) values=list(c.values()) #aのCollectionのvalue値のリスト(n_1こ、n_2こ…) key=list(c.keys()) #先のvalue値に相当する要素のリスト(要素1,要素2,…) for i in range(len(key)): l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix lr=[] v=[] for i in range(len(key)): lr.append([0,l[i][0]]) v.append(l[i][1]) for i in range(len(v)): l=lr[i][0] r=lr[i][1] cuml[l]=cuml[l]+v[i] if r+1<cumax: cuml[r+1]=cuml[r+1]-v[i] for i in range(cumax-1): cuml[i+1]=cuml[i+1]+cuml[i] #print(cuml) maxind=2*10**5+10 minind=0 while maxind-minind>1: piv=minind+(maxind-minind)//2 #pivは握手の幸福度 cnt=0 for i in range(N): x=piv-A[i] cnt=cnt+cuml[max(x,0)] if cnt<=M: maxind=piv else: minind=piv #print(cnt,maxind,piv,minind) #print(minind) thr=minind cuml2=[0]*(N+1) A.sort(reverse=True) for i in range(N): cuml2[i+1]=cuml2[i]+A[i] #print(cuml2,thr,A) ans=0 counts=0 #print(cuml[0:10]) for i in range(N): x=thr-A[i] #print(x) cnt=cuml[max(x,0)] #print(cnt) ans=ans+(A[i]*cnt)+cuml2[cnt] counts=counts+cnt ans=ans-(counts-M)*thr #print() print(ans)
import numpy as np def convolve(A, B): # 畳み込み # 要素は整数 # 3 つ以上の場合は一度にやった方がいい dtype = np.int64 fft, ifft = np.fft.rfft, np.fft.irfft a, b = len(A), len(B) if a == b == 1: return np.array([A[0]*B[0]]) n = a+b-1 # 返り値のリストの長さ k = 1 << (n-1).bit_length() AB = np.zeros((2, k), dtype=dtype) AB[0, :a] = A AB[1, :b] = B return np.rint(ifft(fft(AB[0]) * fft(AB[1]))).astype(np.int64)[:n] import sys input = sys.stdin.readline n,m = map(int, input().split()) a = list(map(int, input().split())) cnt = np.zeros(100001) for i in a: cnt[i] += 1 c = convolve(cnt,cnt) ans = 0 for i in range(len(c))[::-1]: if c[i] > 0: p = min(m,c[i]) m -= p ans += i*p if m == 0: break print(ans)
1
108,098,141,314,140
null
252
252
l = input() s = l[-1] c = '' if s == 's': c = l + 'es' else: c = l + 's' print(c)
def gotoS(org, n): res = [0] * n for i in range(1, n+1): res[org[i-1]-1] = i return res n = int(input()) org = list(map(int, input().split())) print(*gotoS(org, n))
0
null
91,951,327,806,730
71
299
# local search is all you need # 「日付 d とコンテストタイプ q をランダムに選び、d 日目に開催するコンテストをタイプ q に変更する」 # このデメリット→変化させる量が小さすぎるとすぐに行き止まり (局所最適解) に陥ってしまい、逆に、変化させる量が 大きすぎると闇雲に探す状態に近くなって、改善できる確率が低くなってしまう。 # 今回ならば、開催日が全体的に遠すぎず近すぎない感じのlocal minimumに収束する∵d日目のコンテストをi→jに変更したとする。iの開催期間はすごく伸びると2乗でスコアが下がるため、iの開催期間が比較的近いところのiしか選ばれない # →じゃ2点スワップを導入して改善してみよう # あといっぱい回すためにinitやscoreも若干高速化 from time import time t0 = time() import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(read()) def ints(): return list(map(int, read().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from random import randint, random def score(D, C, S, T): '''2~3*D回のループでスコアを計算する''' # last = [-1] * 26 date_by_contest = [[-1] for _ in range(26)] for d, t in enumerate(T): date_by_contest[t].append(d) for i in range(26): date_by_contest[i].append(D) # 番兵 # print(*date_by_contest, sep='\n') score = 0 for d in range(D): score += S[d][T[d]] for c, dates in enu(date_by_contest): for i in range(len(dates) - 1): dd = (dates[i + 1] - dates[i]) # for ddd in range(dd): # score -= C[c] * (ddd) score -= C[c] * (dd - 1) * dd // 2 return score D = a_int() C = ints() S = read_tuple(D) def maximizer(newT, bestT, bestscore): tmpscore = score(D, C, S, newT) if tmpscore > bestscore: return newT, tmpscore else: return bestT, bestscore def ret_init_T(): '''greedyで作ったTを初期値とする。 return ---------- T, score ... 初期のTとそのTで得られるscore ''' def _make_T(n_days): # editorialよりd日目の改善は、改善せずにd+n_days経過したときの関数にしたほうが # 最終的なスコアと相関があるんじゃない? T = [] last = [-1] * 26 for d in range(D): ma = -INF for i in range(26): tmp = S[d][i] dd = d - last[i] tmp += C[i] * (((dd + n_days + dd) * (n_days) // 2)) if tmp > ma: t = i ma = tmp last[t] = d # Tを選んだあとで決める T.append(t) return T T = _make_T(2) sco = score(D, C, S, T) for i in range(3, 16): T, sco = maximizer(_make_T(i), T, sco) return T, sco bestT, bestscore = ret_init_T() def add_noise(T, thre_p, days_near): '''確率的にどちらかの操作を行う 1.日付dとコンテストqをランダムに選びd日目に開催するコンテストのタイプをqに変更する 2.10日以内の点でコンテストを入れ替える thre_pはどちらの行動を行うかを調節、days_nearは近さのパラメータ''' ret = T.copy() if random() < thre_p: d = randint(0, D - 1) q = randint(0, 25) ret[d] = q return ret else: i = randint(0, D - 2) j = randint(i - days_near, i + days_near) j = max(j, 0) j = min(j, D - 1) if i == j: j += 1 ret[i], ret[j] = ret[j], ret[i] return ret while time() - t0 < 1.92: bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) # print(bestscore) # print(score(D, C, S, T)) print(*mina(*bestT, sub=-1), sep='\n')
import numpy as np import sys read = sys.stdin.read D = int(input()) CS = np.array(read().split(), np.int32) C = CS[:26] S = CS[26:].reshape((-1, 26)) del CS last = np.zeros((26, )) ans = [] def getContestType_at_d(d): s = -10000000 for i in range(26): mask = np.ones((26, )) mask[i] = 0 tmp = S[d][i] - np.sum(C * (d + 1 - last) * mask) if s < tmp: s = tmp t = i last[t] = d + 1 return t + 1, s for d in range(D): s = -10000000 for i in range(26): mask = np.ones((26, )) mask[i] = 1 score = S[d][i] - np.sum(C * (d + 1 - last) * mask) if s < score: s = score t = i last[t] = d + 1 ans.append(t + 1) print('\n'.join(map(str, ans)))
1
9,660,523,385,552
null
113
113
from math import ceil t1,t2 = map(int,input().split()) a1,a2 = map(int,input().split()) b1,b2 = map(int,input().split()) a1 -= b1 a2 -= b2 if t1*a1 + t2*a2 == 0: print("infinity") exit() if a1*a2 > 0: print(0) exit() a1 *= t1 a2 *= t2 if (a1 > 0 and a1+a2>0) or (a1<0 and a1+a2<0): print(0) exit() if a1 > 0: x = -a1/(a1+a2) n = ceil(x) if n == x: print(2*n) else: print(2*n-1) if a2 > 0: x = a1 / (-(a1 + a2)) n = ceil(x) if n == int(x): print(2 * n) else: print(2 * n - 1)
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) SI = lambda : sys.stdin.readline().rstrip() T = LI() A = LI() B = LI() p1 = (A[0] - B[0]) * T[0] p2 = p1 + (A[1] - B[1]) * T[1] if p1 * p2 > 0: print(0) return elif p2 == 0: print('infinity') return ans = 1 if p2 + p1 == 0: print(2) return p2 = abs(p2) p1 = abs(p1) if p2 > p1: print(1) return if p1 % p2 == 0: ans -= 1 ans += (p1 // p2) * 2 print(ans) if __name__ == '__main__': main()
1
131,878,792,054,400
null
269
269
# Rem of sum is Num # Reviewing problem from collections import defaultdict def cnt_func(X): res = 0 right = 0 L = len(X) for i in range(L): while right+1 < L and X[right+1] < K+X[i]: right += 1 res += right-i return res N, K = map(int, input().split()) A = list(map(int, input().split())) A.insert(0, 0) for i in range(1, N+1): A[i] += A[i-1] B = [0 for i in range(N+1)] for i in range(N+1): B[i] = (A[i]-i) % K ans = 0 Mod = defaultdict(list) for i in range(N+1): Mod[B[i]].append(i) for X in Mod.values(): ans += cnt_func(X) print(ans)
from itertools import accumulate from collections import defaultdict n, k = map(int, input().split()) a = list(map(int, input().split())) acc = [0] + list(accumulate(a)) sm = [(e - i) % k for i, e in enumerate(acc)] d = defaultdict(int) ans = 0 for r in range(1, n + 1): if r - k >= 0: e = sm[r - k] d[e] -= 1 e = sm[r - 1] d[e] += 1 e = sm[r] ans += d[e] print(ans)
1
137,721,239,839,328
null
273
273
n,m,l = map(int,raw_input().split()) a = [map(int,raw_input().split()) for _ in range(n)] b = [map(int,raw_input().split()) for _ in range(m)] c = [[0 for i in range(l)] for j in range(n)] for i in range(n): for j in range(l): s = 0 for k in range(m): s += a[i][k] * b[k][j] c[i][j] = s for i in range(n): print ' '.join(map(str,c[i]))
N, M, L = map(int, raw_input().split()) nm = [map(int, raw_input().split()) for n in range(N)] ml = [map(int, raw_input().split()) for m in range(M)] for n in range(N): col = [0] * L for l in range(L): for m in range(M): col[l] += nm[n][m] * ml[m][l] print ' '.join(map(str, col))
1
1,425,029,292,062
null
60
60
sentence = input() for i in sentence: if i.isupper() == True: print(i.lower(), end = "") elif i.islower() == True: print(i.upper(), end = "") else: print(i, end = "") print()
n = input() print(n.swapcase())
1
1,507,754,479,100
null
61
61
import math member = [] score = [] while True: num = int(raw_input()) if num == 0: break member.append(num) score.append(map(int, raw_input().split())) alpha = [] for m, s in zip(member, score): average = sum(s)/float(m) sigma = 0 for t in s: sigma += (t - average)**2 else: alpha += [sigma/m] for a in alpha: #print '%.8f' % math.sqrt(a) print math.sqrt(a)
n, m, k = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] aa = [0] bb = [0] for s in range(n): aa.append(aa[s] + a[s]) for s in range(m): bb.append(bb[s] + b[s]) ans = 0 j = m for i in range(n+1): if aa[i] > k: break while bb[j] > k - aa[i]: j -= 1 ans = max(ans, i+j) print(ans)
0
null
5,425,140,569,728
31
117
while(True): (H,W)=[int(s) for s in input().split()] if (H,W) == (0,0): break for j in range(H): print("#"*W) print("")
input = raw_input() input = int(input) ans = input**3 print ans
0
null
522,659,901,948
49
35
n, *a = map(int, open(0).read().split()) a.sort() if a[0] == 0: print(0) exit() b = 1 for c in a: b *= c if b > 10 ** 18: print(-1) exit() print(b)
input() a=1 d=1000000000000000000 for i in input().split(): a=min(a*int(i),d+1) print([a,-1][a>d])
1
16,231,602,261,248
null
134
134
s,t,a,b,u=open(0).read().split() if s==u: print(int(a)-1,b) elif t==u: print(a,int(b)-1)
import sys,math def is_prime_number(arg): arg_sqrt=int(math.floor(math.sqrt(arg))) i=2 while i <=arg_sqrt: if arg %i ==0: return False i+=1 return True n=0 prime_numbers=0 for line in sys.stdin: l=int(line) if n == 0: n=l continue if is_prime_number(l): prime_numbers+=1 print prime_numbers
0
null
35,965,033,666,430
220
12
n = int(input()) s = input() if n % 2 != 0: print("No") else: t = s[:int((n / 2))] u = t + t print("Yes" if s == u else "No")
S,T = (input().split()) A,B = (int(i) for i in input().split()) U = input() if S == U : A = A - 1 elif T == U: B = B - 1 print(A,B)
0
null
109,290,886,303,776
279
220
n = int(input()) r = n % 27 if r == 13 or r == 26: print(':(') elif r ==0: x = int(100*n/108) print(x) else: for i in range(1, 25): if 1.08*(i-1) < r <= 1.08*i: break x = int(100*(n - i)/108) + i print(x)
N = int(input()) for X in range(1, N+1): if X*108//100==N: print(X) break else: print(':(')
1
126,180,076,548,640
null
265
265
n = int(input()) p = list(map(int,input().split())) ans = n m = 2 * (10 ** 5) for i in range(n): m = min(p[i],m) if p[i] > m: ans -= 1 print(ans)
import numpy as np N = int(input()) x = [] y = [] xy1 = [] xy2 = [] for i in range(N): a, b = (int(t) for t in input().split()) x.append(a) y.append(b) xy1.append(a + b) xy2.append(a - b) max1 = max(xy1) - min(xy1) max2 = max(xy2) - min(xy2) print(max((max1, max2)))
0
null
44,183,885,531,250
233
80
n,m =map(int,input().split()) if n <= m: print('unsafe') else: print("safe")
s,w = [int(s) for s in input().split()] if w>=s: print("unsafe") else: print("safe")
1
29,182,403,140,168
null
163
163
import sys #f = open("test.txt", "r") f = sys.stdin num_rank = 14 s_list = [False] * num_rank h_list = [False] * num_rank c_list = [False] * num_rank d_list = [False] * num_rank n = f.readline() n = int(n) for i in range(n): [suit, num] = f.readline().split() num = int(num) if suit == "S": s_list[num] = True elif suit == "H": h_list[num] = True elif suit == "C": c_list[num] = True else: d_list[num] = True for i in range(1, num_rank): if not s_list[i]: print("S " + str(i)) for i in range(1, num_rank): if not h_list[i]: print("H " + str(i)) for i in range(1, num_rank): if not c_list[i]: print("C " + str(i)) for i in range(1, num_rank): if not d_list[i]: print("D " + str(i))
import itertools n = int(input()) lis = [] for i in range(n): x, y = map(int, input().split()) lis.append((x, y)) LIS = [i for i in range(n)] big_lis = list(itertools.permutations(LIS)) L = len(big_lis) def sai(i, j): return (lis[A[i + 1]][j] - lis[A[i]][j]) ** 2 keep = 0 ANS = 0 for i in range(L): A = list(big_lis[i]) keep = 0 for j in range(n - 1): keep += (sai(j, 0) + sai(j, 1)) ** (1 / 2) ANS += keep print(ANS / L)
0
null
75,119,826,917,262
54
280
import sys; input = sys.stdin.readline from math import ceil d, t, s = map(int, input().split()) u, l = ceil(d/t), d//t if u == l: if u <= s: print("Yes") else: print("No") else: if d/t <= s: print("Yes") else:print("No")
import sys n = sys.stdin.readlines() for i in n: a = [int(x) for x in i.split()] if a[0] == 0 and a[1] == 0: break print(*sorted(a))
0
null
2,003,467,052,490
81
43
def gcd(a,b): for i in range(1,min(a,b)+1): if a%i ==0 and b % i ==0: ans = i return ans x =int(input()) print(360//gcd(360,x))
n = int(input()) if n%2==1: print(0) else: # 2の倍数には不足しないので、5の倍数を数える i=1 cnt=0 while n//(5**i*2) > 0: cnt += n//((5**i)*2) i += 1 print(cnt)
0
null
64,327,246,109,472
125
258
x=int(raw_input()) print x*x*x
N, A = map(int,input().split()) print("Yes" if 500*N >= A else "No")
0
null
49,184,078,153,980
35
244
import sys from collections import defaultdict N,S=map(int, sys.stdin.readline().split()) A=map(int, sys.stdin.readline().split()) mod=998244353 cur=defaultdict(lambda: 0) new=defaultdict(lambda: 0) cur[0]=1 for a in A: for i in cur.keys(): if i+a<=S: new[i+a]+=cur[i] new[i+a]%=mod new[i]+=cur[i]*2 new[i]%=mod cur=new new=defaultdict(lambda: 0) print cur[S]
import sys mod = 998244353 def solve(): input = sys.stdin.readline N, S = map(int, input().split()) A = [int(a) for a in input().split()] DP = [[0 for _ in range(S + 1)] for i in range(N)] DP[0][0] = 2 if A[0] <= S: DP[0][A[0]] = 1 ans = 0 for i, a in enumerate(A[1:]): for s in range(S + 1): if DP[i][s] > 0: DP[i+1][s] += (DP[i][s] * 2) % mod DP[i+1][s] %= mod if s + a <= S: DP[i+1][s+a] += DP[i][s] DP[i+1][s+a] %= mod print(DP[N-1][S]) #print(DP) return 0 if __name__ == "__main__": solve()
1
17,602,426,783,676
null
138
138
n, k, s = map(int, input().split()) ans = [] for i in range(k): ans.append(s) if s == 10 ** 9: out_of_s = 1 else: out_of_s = s + 1 for i in range(n - k): ans.append(out_of_s) for a in ans: print(a, end=' ')
A = [int(input()) for i in range(10)] for i in sorted(A)[:-4:-1]: print(i)
0
null
45,277,905,517,088
238
2
n = int(input()) a = list(map(int, input().split())) ans = [None]*n all = 0 for i in range(n): all = all^a[i] for i in range(n): ans[i]=str(all^a[i]) print(' '.join(ans))
#!/usr/bin/python3 # -*- coding:utf-8 -*- from functools import reduce def main(): n = int(input()) la = list(map(int, input().strip().split())) x = reduce(lambda x, y: x ^ y, la) print(' '.join([str(x ^ a) for a in la])) if __name__=='__main__': main()
1
12,410,382,466,960
null
123
123
(L,R,d) = map(int, input().split()) out=int(R/d)-int(L/d)+1 if ( L%d == 0): print (out) else: print(out-1)
# coding: utf-8 from operator import add, sub, mul op_dict = {'+': add, '-': sub, '*': mul} def calcurate(list_): s = [] for l in list_: if l.isdigit(): s.append(int(l)) elif l in ['+', '-', '*']: a = s.pop() b = s.pop() s.append(op_dict[l](b, a)) return s[0] def main(): inputs = raw_input().split() print calcurate(inputs) if __name__ == '__main__': main()
0
null
3,748,954,100,836
104
18
import math r = float(raw_input()) print '%.5f %.5f' % (r*r*math.pi, 2*r*math.pi)
s= input() x = "x" * len(s) print(x)
0
null
36,992,641,371,770
46
221
N = int(input()) S = input() if N % 2 == 1: print("No") else: if S[:N // 2] == S[N // 2:]: print("Yes") else: print("No")
N=int(input()) S=input() l=len(S) a='' for i in range(l): if ord(S[i])+N>90: a+=chr(ord(S[i])+N-26) else: a+=chr(ord(S[i])+N) print(a)
0
null
140,748,278,431,660
279
271
#!/usr/bin/env python3 print(6-eval(input()+"+"+input()))
n=int(input()) def func(n): fibonacci = [1,2] for i in range(2,n): fibonacci.append(fibonacci[i-2]+fibonacci[i-1]) return fibonacci[n-1] print(func(n))
0
null
55,425,165,729,212
254
7
(n, k), p, c = [[*map(int, i.split())] for i in open(0)] def solve(x, t): visit = [0] * n visit[x] = 1 loop = [0] * n count = 0 ans = c[p[x] - 1] l = True sub = 0 while True: x = p[x] - 1 if l: if visit[x]: if loop[x]: ln = sum(loop) if t > ln: sub += (t//ln -1)*count*(count>0) t %= ln t += ln l = False count += c[x] loop[x] = 1 visit[x] = 1 sub += c[x] t -= 1 ans = max(sub, ans) if t < 1: return ans print(max(solve(i, k) for i in range(n)))
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) n=int(input()) z=[] w=[] for i in range(n): x,y=nii() z.append(x-y) w.append(x+y) z_ans=max(z)-min(z) w_ans=max(w)-min(w) print(max(z_ans,w_ans))
0
null
4,353,223,851,900
93
80
N = int(input()) graph = [[] for _ in range(N+1)] AB = [] for _ in range(N-1): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) AB.append((a, b)) root = 1 parent = [0] * (N+1) order = [] stack = [root] while stack: x = stack.pop() order.append(x) for y in graph[x]: if y == parent[x]: continue parent[y] = x stack.append(y) color = [-1] * (N+1) K = -1 for x in order: ng = color[x] c = 1 for y in graph[x]: if y == parent[x]: continue if c == ng: c += 1 K = max(c, K) color[y] = c c += 1 ans = [] for a, b in AB: if parent[a] == b: ans.append(color[a]) else: ans.append(color[b]) print(K) for i in ans: print(i)
def bubble_sort(List): cnt=0 l=len(List) for i in range(l): for j in range(l-1,i,-1): if List[j]<List[j-1]: temp=List[j] List[j]=List[j-1] List[j-1]=temp cnt+=1 return cnt def main(): N=input() N_List=map(int,raw_input().split()) cnt=bubble_sort(N_List) for k in range(len(N_List)): N_List[k]=str(N_List[k]) print(" ".join(N_List)) print(cnt) if __name__=='__main__': main()
0
null
67,896,274,190,276
272
14
x=list(map(int, input().split())) if x[1]*2>x[0]: print(0) else: print(x[0]-x[1]*2)
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) from collections import defaultdict, deque from sys import exit import math import copy from bisect import bisect_left, bisect_right from heapq import * import sys # sys.setrecursionlimit(1000000) INF = 10 ** 17 MOD = 1000000007 from fractions import * def inverse(f): # return Fraction(f.denominator,f.numerator) return 1 / f def combmod(n, k, mod=MOD): ret = 1 for i in range(n - k + 1, n + 1): ret *= i ret %= mod for i in range(1, k + 1): ret *= pow(i, mod - 2, mod) ret %= mod return ret MOD = 10 ** 9 + 7 def solve(): n = getN() bit_array = [[0, 0] for i in range(61)] nums = getList() for num in nums: digit = 0 while(digit < 61): if num % 2 == 0: bit_array[digit][0] += 1 else: bit_array[digit][1] += 1 digit += 1 num //= 2 # print(bit_array) ans = 0 for i, tgt in enumerate(bit_array): ans += pow(2, i, MOD) * tgt[0] * tgt[1] ans %= MOD print(ans ) def main(): n = getN() for _ in range(n): solve() if __name__ == "__main__": solve()
0
null
145,224,872,793,242
291
263
import itertools n = int(input()) a = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) able = [0] * (max(n * max(a) + 1, 2001)) for item in itertools.product([0, 1], repeat=n): total = sum([i * j for i, j in zip(a, item)]) able[total] = 1 for m in M: print('yes' if able[m] else 'no')
n = int(input()) for x in range(1, 50005): if x * 108//100 == n: print(x) exit() else: print(':(')
0
null
62,742,535,718,632
25
265
import re W = input() T = [] count = 0 while(1): line = input() if (line == "END_OF_TEXT"): break words = list(line.split()) for word in words: T.append(word) for word in T: matchOB = re.fullmatch(W, word.lower()) if matchOB: count += 1 print(count)
s = input() s = s[::-1] n = len(s) # stmp = s[::-1] # for i in range(len(s)): # for j in range(i,len(s)): # sint = int(stmp[i:j+1]) # if sint % 2019 == 0: # print(n-j,n-i) # print(sint) # print() rem2019_cnts = [0]*2019 rem2019_cnts[0] = 1 curr_rem = int(s[0]) rem2019_cnts[curr_rem] = 1 curr_10_rem = 1 ans = 0 for i,si in enumerate(s[1:]): sint = int(si) next_10_rem = (curr_10_rem*10)%2019 next_rem = (next_10_rem*sint + curr_rem)%2019 ans += rem2019_cnts[next_rem] rem2019_cnts[next_rem] += 1 curr_10_rem = next_10_rem curr_rem = next_rem # print(i+2, curr_rem) print(ans)
0
null
16,457,540,989,398
65
166
m,d = map(int,input().split()) m2,d2 = map(int,input().split()) print(1 if m != m2 else 0)
import sys n,m=map(int,input().split()) ans=[0]*n for i in range(m): s,c=map(int,input().split()) s-=1 if ans[s]!=0 and ans[s]!=c: print(-1) sys.exit() else: ans[s]=c if n==3 and m==1 and ans==[0,0,0]: print(-1) sys.exit() if n!=1 and ans[0]==0: ans[0]=1 for i in range(n): ans[i]=str(ans[i]) print("".join(ans))
0
null
92,761,039,877,212
264
208
n,k=map(int,input().split()) r,s,p=map(int,input().split()) t=input() hand=["" for _ in range(k)] point=[0 for _ in range(k)] for i in range(n): index=i%k #初めの手(制限なし) if index==i: if t[i]=="r": hand[index]="p" point[index]+=p elif t[i]=="s": hand[index]="r" point[index]+=r else: hand[index]="s" point[index]+=s #2番目以降の手 else: if t[i]=="r": if hand[index]=="p": hand[index]="x" else: hand[index]="p" point[index]+=p elif t[i]=="s": if hand[index]=="r": hand[index]="x" else: hand[index]="r" point[index]+=r else: if hand[index]=="s": hand[index]="x" else: hand[index]="s" point[index]+=s print(sum(point))
import sys import itertools def resolve(in_): N, K = map(int, next(in_).split()) R, S, P = map(int, next(in_).split()) T = next(in_).rstrip() r = ord(b'r') s = ord(b's') p = ord(b'p') temp = [0] * (N + 1) ans = 0 for i, v in enumerate(T): j = i - K if j < 0: if v == r: ans += P temp[i] = p elif v == s: ans += R temp[i] = r elif v == p: ans += S temp[i] = s else: if v == r and temp[j] != p: ans += P temp[i] = p elif v == s and temp[j] != r: ans += R temp[i] = r elif v == p and temp[j] != s: ans += S temp[i] = s return ans def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
1
107,101,605,760,130
null
251
251
from collections import deque N,K = map(int,input().split()) H = list(map(int,input().split())) H.sort(reverse=True) deqH = deque(H) if N <= K: print(0) else: for i in range(K): deqH.popleft() #H.remove(max(H)) #print(H) print(sum(deqH))
n = int(input()) dp = [1] * (n+1) for j in range(n-1): dp[j+2] = dp[j+1] + dp[j] print(dp[n])
0
null
39,649,329,710,396
227
7
max = 10 for x in xrange(1, max): for y in xrange(1, max): print "%dx%d=%d" % (x, y, x * y)
#cやり直し import numpy n = int(input()) a = list(map(int, input().split())) ans = 0 mod = 10**9 +7 before = a[-1] for i in range(n-1,0,-1): ans += (a[i-1]*before)%mod before += a[i-1] print(ans%mod)
0
null
1,927,921,921,042
1
83
def main(): n = int(input()) if n%2==1: print(0) return md = 10 cnt = 0 while n>=md: cnt += n//md md = md*5 print(cnt) if __name__ == "__main__": main()
while True: l = input().split() a = int(l[0]) o = l[1] b = int(l[2]) if o =='?': break if o == '+': print( '%d'%(a+b)) elif o == '-': print('%d'%(a-b)) elif o =='*': print('%d'%(a*b)) else: o =='/' print('%d'%(a//b))
0
null
58,542,797,554,660
258
47
if __name__ == '__main__': n = int(input()) s = set(input().split()) if len(s) == n: print("YES") else: print("NO")
input() A = input().split() a_set = set(A) if len(A) == len(a_set): print('YES') else: print('NO')
1
73,945,682,947,460
null
222
222
def myAnswer(a:int,b:int,c:int) -> str: A = ( a + b - c) ** 2 B = 4 * a * b return "Yes" if( A - B > 0 and (c - a - b) > 0) else "No" def modelAnswer(): return def main(): a,b,c = map(int,input().split()) print(myAnswer(a,b,c)) if __name__ == '__main__': main()
from decimal import * import math a, b, c = list(map(int, input().split())) print('Yes' if c - a - b> 0 and 4*a*b < (c - a - b)**2 else 'No')
1
51,357,807,083,720
null
197
197
n = int(input()) s = input() ans = "" for i in range(len(s)): x = ord(s[i]) - ord('A') + n ans += chr(x % 26 + ord('A')) print(ans)
if __name__ == "__main__": S = input() list_s = [s for s in S] ans = 0 if list_s[0] == 'S' and list_s[1] == 'S' and list_s[2] == 'S': ans = 0 elif list_s[0] == 'S' and list_s[1] == 'S' and list_s[2] == 'R': ans = 1 elif list_s[0] == 'S' and list_s[1] == 'R' and list_s[2] == 'R': ans = 2 elif list_s[0] == 'R' and list_s[1] == 'R' and list_s[2] == 'R': ans = 3 elif list_s[0] == 'R' and list_s[1] == 'S' and list_s[2] == 'R': ans = 1 elif list_s[0] == 'R' and list_s[1] == 'R' and list_s[2] == 'S': ans = 2 elif list_s[0] == 'R' and list_s[1] == 'S' and list_s[2] == 'S': ans = 1 elif list_s[0] == 'S' and list_s[1] == 'R' and list_s[2] == 'S': ans = 1 print(ans)
0
null
69,869,689,670,350
271
90
import sys import math import functools def resolve(in_): N = int(next(in_)) A = tuple(map(int, next(in_).split())) max_a = max(A) temp = [0] * (max_a + 1) temp[1] = 1 for i in range(2, max_a + 1): if temp[i]: continue j = i while j < max_a + 1: if not temp[j]: temp[j] = i j += i B = set() for a in A: s = set() while a > 1: s.add(temp[a]) a = a // temp[a] for v in s: if v in B: if functools.reduce(math.gcd, A) == 1: return 'setwise coprime' else: return 'not coprime' B.add(v) return 'pairwise coprime' def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
import math from functools import reduce def gcd_list(numbers): return reduce(math.gcd, numbers) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a N = int(input()) A = list(map(int, input().split())) if gcd_list(A) != 1: print('not coprime') exit() primes = set() for a in A: len_primes = len(primes) divs = set(prime_factorize(a)) primes |= divs if len(primes) != len_primes + len(divs): print('setwise coprime') exit() print('pairwise coprime')
1
4,105,499,016,226
null
85
85
X = int(input()) if 400 <= X < 600: print(8) elif 600 <= X < 800: print(7) elif 800 <= X < 1000: print(6) elif 1000 <= X < 1200: print(5) elif 1200 <= X < 1400: print(4) elif 1400 <= X < 1600: print(3) elif 1600 <= X < 1800: print(2) else: print(1)
n,d = map(int, input().split()) z = [list(map(int, input().split())) for _ in range(n)] ans = 0 for i in z: distance = i[0]*i[0] + i[1]*i[1] if distance <= d**2: ans += 1 print(ans)
0
null
6,283,213,407,130
100
96
a, b = map(int, input().split()) alpha = str(b) beta = str(a) if a >= b: for k in range(a - 1): alpha = alpha + str(b) print(int(alpha)) else: for k in range(b - 1): beta = beta + str(a) print(beta)
import sys import math N = int(input()) A = map(int, input().split()) s = [0] * N for a in A: s[a-1] += 1 for i in range(N): print(s[i])
0
null
58,517,339,082,862
232
169
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): N = I() s = 'abcdefghijklmnopqrstuvwxyz' assert len(s) == 26 cur = [] while N > 0: amari = N % 26 if amari == 0: amari += 26 cur.append(s[amari-1]) N -= amari N //= 26 print(''.join(cur[::-1])) main()
alps = 'abcdefghijklmnopqrstuvwxyz' n = int(input()) if n == 1: print('a') exit() ansl = [] curr_n = n for i in range(15, -1, -1): if n <= pow(26,i): continue val = curr_n//pow(26,i) ansl.append(val) curr_n -= val*pow(26,i) for j in range(100): for i in range(len(ansl)-1): if ansl[i+1] == 0: ansl[i+1] = 26 ansl[i] -= 1 ans = '' for a in ansl: if a == 0: continue ans += alps[a-1] print(ans)
1
11,820,212,368,640
null
121
121
N = input() straw = input() straw = straw.split('ABC') print(len(straw) - 1)
import math while True: try: a, b = [int(i) for i in input().split()] gcd = math.gcd(a, b) lcm = a * b // gcd print(f'{gcd} {lcm}') except EOFError: break
0
null
49,431,180,251,950
245
5
mylist1 = [2,4,5,7,9] mylist2 = [0,1,6,8] N = int(input()) X = N % 10 if X in mylist1: print('hon') elif X in mylist2: print('pon') else: print('bon')
N = int(input()) N = N % 10 if N in (2, 4, 5, 7, 9): print ("hon") elif N in (0, 1, 6, 8): print ("pon") elif N == 3: print ("bon")
1
19,283,675,703,776
null
142
142
import sys import math import bisect from collections import defaultdict,deque # input = sys.stdin.readline def inar(): return [int(el) for el in input().split()] # def find(a,b,c): # gc=math.gcd(a,b) # return math.gcd(gc,c) def main(): n=int(input()) string=input() r=[] g=[] b=[] for i in range(n): if string[i]=="R": r.append(i) elif string[i]=="G": g.append(i) else: b.append(i) ans=0 r.sort() g.sort() b.sort() # print(r) # print(g) # print(b) # print(len(b)) # ans1=0 # fir=[] # for i in range(len(r)): # for j in range(len(g)): # for k in range(len(b)): # ls=[r[i],g[j],b[k]] # ls.sort() # if ls[1]-ls[0]!=ls[2]-ls[1]: # ans1+=1 # fir.append(ans1) # # print(ans1) # print("-------------------check---------------") # are=[] for i in range(len(r)): for j in range(len(g)): ans+=len(b) chota=min(g[j],r[i]) bada=max(g[j],r[i]) diff=bada-chota left=bisect.bisect_left(b,bada+diff) right=bisect.bisect_left(b,chota-diff) lol=(bada+chota) if lol%2==0: beech=lol//2 ind=bisect.bisect_left(b,beech) if ind<len(b) and b[ind]==beech: ans-=1 if (left<len(b) and b[left]==bada+diff): ans-=1 if (right<len(b) and b[right]==chota-diff): ans-=1 # are.append(ans) print(ans) # for i in range(len(are)): # print(are[i],fir[i]) if __name__ == '__main__': main()
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) N,M = list(map(int,input().split())) Network = UnionFind(N) out=0 for i in range(M): a,b = list(map(int,input().split())) Network.union(a-1,b-1) print(-1*min(Network.parents))
0
null
19,934,602,522,988
175
84
def insertionSort(A,n,g,cnt): for i in range(g,n): v = A[i] j = i-g while (j>=0)*(A[j]>v): A[j+g]=A[j] j = j-g cnt[0] += 1 A[j+g] = v A =[] N = int(input()) for i in range(N): A.append(int(input())) cnt = [0] import math m = math.floor(math.log(N,2))+1 G = [math.ceil(N/2)] for i in range(1,m-1): G.append(math.ceil(G[i-1]/2)) G.append(N-sum(G)) if G[len(G)-1] != 1: G[len(G)-1] = 1 for k in range(m): insertionSort(A,N,G[k],cnt) print(m) for i in range(m): print(f"{G[i]}",end=" ") print(f"\n{cnt[0]}") for i in range(N): print(f"{A[i]}")
def insertion_sort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j + g] = A[j] j -= g cnt += 1 A[j + g] = v def shell_sort(A, n): G = [] i = 1 while i <= n: G.append(i) i = i * 3 + 1 G_inv = G[::-1] for g in G_inv: insertion_sort(A, n, g) return len(G), G_inv, A N = int(input()) a = [int(input()) for i in range(N)] cnt = 0 m, Gl, A = shell_sort(a, N) print(m) print(' '.join(str(g) for g in Gl)) print(cnt) print('\n'.join(str(e) for e in A))
1
30,266,933,280
null
17
17
a,b = map(int, raw_input().split()) A = [map(int, raw_input().split()) for _ in xrange(a)] B = [input() for _ in xrange(b)] C = [sum([A[i][j] * B[j] for j in xrange(b)]) for i in xrange(a)] for x in C: print x
R = int(input()) print(R*2*3.14159265358979)
0
null
16,146,062,959,072
56
167
# coding: utf-8 import sys from collections import deque output_str = deque() data_cnt = int(input()) for i in range(data_cnt): line = input().rstrip() if line.find(" ") > 0: in_command, in_str = line.split(" ") else: in_command = line if in_command == "insert": output_str.appendleft(in_str) elif in_command == "delete": if output_str.count(in_str) > 0: output_str.remove(in_str) elif in_command == "deleteFirst": output_str.popleft() elif in_command == "deleteLast": output_str.pop() print(" ".join(output_str))
from collections import deque import sys deq = deque() q = int(input()) for _ in range(q): s = input() if s == 'deleteFirst': deq.popleft() elif s == 'deleteLast': deq.pop() else: ss, num = s.split() if ss == 'insert': deq.appendleft(num) else: try: deq.remove(num) except: pass print(" ".join(deq))
1
49,193,705,440
null
20
20
n=int(input()) s,t=input().split() ans="" for i,j in zip(list(s),list(t)):ans+=i+j print(ans)
x=int(input()) a=0 while True: for b in range(10**3): if a**5-b**5==x: print(a,b) exit() elif a**5+b**5==x: print(a,-b) exit() elif -a**5+b**5==x: print(-a,-b) exit() a+=1
0
null
68,606,798,505,812
255
156
import numpy as np a,b,c = map(int,input().split()) print(int(np.ceil(a/b)*c))
N = input() d = -999999999 R = input() for i in range(N-1): r = input() d = max(d,(r-R)) R = min(R,r) print d
0
null
2,129,193,478,332
86
13
n = int(input()) L = list(map(int,input().split())) L = sorted(L) import bisect ans = 0 for i in range(n-2): for j in range(i+1,n-1): a = bisect.bisect_left(L,L[i]+L[j]) ans += a-j-1 print(ans)
import sys from bisect import bisect_left,bisect_right sys.setrecursionlimit(10**7) input = sys.stdin.readline N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for b in range(N): for a in range(b): ab = L[a] + L[b] r = bisect_left(L, ab) l = b + 1 ans += max(0, r - l) print(ans)
1
172,122,767,358,538
null
294
294
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) A = list(map(int, input().split())) res = 0 for i in range(60): cnt = 0 for a in A: cnt += (a >> i) & 1 res += (cnt * (n - cnt)) % mod * (1 << i) % mod res %= mod print(res) if __name__ == '__main__': resolve()
def input_num(): ls = input().strip().split(" ") return [int(e) for e in ls] n,r = input_num() if n >= 10: print(r) else: print(r+100*(10-n))
0
null
92,946,293,858,206
263
211
inp = [int(input()) for i in range(10)] m1, m2, m3 = 0, 0, 0 for h in inp: if(h > m1): m3 = m2 m2 = m1 m1 = h elif(h > m2): m3 = m2 m2 = h elif(h > m3): m3 = h print(m1) print(m2) print(m3)
N=10 A=[int(input()) for i in range(N)] A.sort(reverse=True) for i in range(3): print(A[i])
1
11,182,150
null
2
2
from itertools import combinations n = int(input()) L = list(map(int, input().split())) cnt = 0 for edges in list(combinations(L, 3)): if len(set(edges)) != 3: continue e1 = edges[0] < edges[1] + edges[2] e2 = edges[1] < edges[0] + edges[2] e3 = edges[2] < edges[0] + edges[1] if e1 and e2 and e3: cnt += 1 print(cnt)
N = int(input()) L = list(map(int, input().split())) c = 0 for i in range(N): for j in range(i+1,N): for k in range(j+1,N): if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]: if L[i] + L[j] + L[k] > 2 * max(L[i],L[j],L[k]): c +=1 print(c)
1
5,092,757,056,762
null
91
91
n = int(input()) r = -10000000000 y = int(input()) m = y x = y for i in range(1, n): x = int(input()) if r < (x - m): r = (x - m) if x < m: m = x print(r)
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() from collections import defaultdict def resolve(): n,k=map(int,input().split()) A=list(map(int,input().split())) S=[0]*(n+1) for i in range(n): S[i+1]=S[i]+A[i] for i in range(n+1): S[i]-=i S[i]%=k ans=0 D=defaultdict(int) for i in range(n+1): s=S[i] ans+=D[s] D[s]+=1 if(i>=k-1): D[S[i-k+1]]-=1 print(ans) resolve()
0
null
68,514,489,508,442
13
273
import sys, math from functools import lru_cache from collections import deque sys.setrecursionlimit(500000) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] def solve(d): if d == 1: return ['a'] l = solve(d-1) rsl = [] for w in l: m = ord(max(w)) for i in range(ord('a'), m+2): rsl.append(w+chr(i)) return rsl def main(): print(*solve(ii()), sep='\n') if __name__ == '__main__': main()
while True: x = input().split() a = int(x[0]) b = int(x[1]) if a == 0 and b == 0: break elif a > b: print('{0} {1}'.format(b, a)) else: print('{0} {1}'.format(a, b))
0
null
26,472,157,546,310
198
43
def readinput(): n=int(input()) x=input() return n,x poptbl=[0]*(2*10**5+1) def popcount(x): global poptbl #if poptbl[x]!=0: # return poptbl[x] poptbl[x]=bin(x).count('1') return poptbl[x] ftbl=[0]*(2*10**5+1) def f(x): global ftbl #if ftbl[x]!=0: # return ftbl[x] #print('f(x), x: {}'.format(x)) if x==0: return 0 else: ans=f(x%popcount(x))+1 #print(ans) ftbl[x]=ans return ans def main(): n=int(input()) x=input() m=x.count('1') #print('m: {}'.format(m)) xint=int(x,2) #print('xint: {}'.format(xint)) if m!=1: xmodm1=xint%(m-1) else: xmodm1=1 xmodp1=xint%(m+1) pow2mod1=[0]*n pow2mod2=[0]*n pow2mod1[0]=1 pow2mod2[0]=1 for i in range(1,n): if m!=1: pow2mod1[i]=pow2mod1[i-1]*2 % (m-1) pow2mod2[i]=pow2mod2[i-1]*2 % (m+1) ans=[] #b=2**(n-1) for i in range(n): if x[i]=='1': if m==1: a=0 ans.append(a) else: xx=( xmodm1 + (m-1) -pow2mod1[n-i-1] )%(m-1) #ans.append(f(xx)+1) a=f(xx)+1 ans.append(a) else: xx=( xmodp1 + pow2mod2[n-i-1] )%(m+1) #ans.append(f(xx)+1) a=f(xx)+1 ans.append(a) #b=b//2 print(a) return ans if __name__=='__main__': #n,x=readinput() ans=main() #for a in ans: # print(a)
n,m=map(int,input().split()) lange=[1]*(n+1) for i in range(1,n+1): a=i b=n-a if lange[a]:lange[b]=0 langes=[] for i in range(1,n): if lange[i]: if len(langes)%2:langes.append(i) else:langes.append(n-i) langes.sort(reverse=1) for i in range(m):print(i+1,i+1+langes[i])
0
null
18,555,919,118,000
107
162
W, H, x, y, r = map(int, input().split()) if x < r or y < r or W - x < r or H - y < r: print("No") else: print("Yes")
inl=map(int, raw_input().split()) if inl[0]>=inl[2]+inl[4] and inl[2]-inl[4]>=0 and inl[1]>=inl[3]+inl[4] and inl[3]-inl[4]>=0: print "Yes" else: print "No"
1
455,941,616,420
null
41
41
def main(): n = int(input()) mod = 1000000007 print((pow(10, n, mod) - 2 * pow(9, n, mod) + pow(8, n, mod)) % mod) if __name__ == '__main__': main()
n = int(input()) mod= 10 ** 9 + 7 ans = ((2*(10**n-9**n))-(10**n-8**n))%mod print(ans)
1
3,154,609,443,698
null
78
78
inputNum = [] for i in range(0, 10): inputNum.append(int(raw_input())) inputNum.sort(reverse=True) for i in range(0, 3): print inputNum[i]
from collections import defaultdict n=int(input()) a=[int(i) for i in input().split()] INF=float('inf') dp0=defaultdict(lambda: -INF) dp1=defaultdict(lambda: -INF) dp0[(0,0)]=0 for i in range(1,n+1): for j in range(i//2-1,(i+1)//2+1): dp0[(i,j)]=max(dp0[(i-1,j)],dp1[(i-1,j)]) dp1[(i,j)]=dp0[(i-1,j-1)]+a[i-1] print(max(dp0[(n,n//2)],dp1[(n,n//2)]))
0
null
18,672,911,430,152
2
177
#!/usr/bin/env python # -*- coding: utf-8 -*- # # FileName: C_fix # CreatedDate: 2020-06-27 13:59:01 +0900 # LastModified: 2020-06-27 14:04:38 +0900 # import os import sys # import numpy as np # import pandas as pd def main(): n = int(input()) s = [] for i in range(n): s.append(input()) s = list(set(s)) print(len(s)) if __name__ == "__main__": main()
def resolve(): n = int(input()) s = [input() for _ in range(n)] print(len(set(s))) resolve()
1
30,417,575,920,208
null
165
165
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop from functools import lru_cache import math # setrecursionlimit(10**7) rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: map(int, stdin.readline().split()) rlf = lambda: map(float, stdin.readline().split()) INF, NINF = float('inf'), float('-inf') MOD = 10**9 + 7 def main(): n = int(rl()) dp = [[[0 for k in range(2)] for j in range(2)] for i in range(n+1)] dp[0][0][0] = 1 for i in range(n): for j in range(2): for k in range(2): for d in range(10): nj = j or d == 0 nk = k or d == 9 dp[i+1][nj][nk] += dp[i][j][k] dp[i+1][nj][nk] %= MOD ans = dp[n][1][1] print(ans) stdout.close() if __name__ == "__main__": main()
import sys read = sys.stdin.buffer.read n, k, *p = map(int, read().split()) p.sort() print(sum(p[:k]))
0
null
7,367,192,546,072
78
120
#!/usr/bin/env python import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**6) INF = float("inf") def main(): N = int(input()) S = input().decode().rstrip() if N%2==0 and S[0:N//2]==S[N//2:]: print("Yes") else: print("No") if __name__ == "__main__": main()
n=int(input()) s=input() ans='No' if n%2==0: if s[:n//2]==s[n//2:]: ans='Yes' print(ans)
1
146,153,149,913,472
null
279
279
n,k=map(int,input().split()) a=range(n+1) max=sum(a[n+1-k:]) min=sum(a[:k]) ans=max-min+1 if n+1==k: print(ans) exit() for i in range(k+1,n+2): max += a[n+1-i] min += a[i-1] ans += max-min+1 print(ans%(10**9+7))
n = int(input()) p= [] AC = 0 WA = 0 TLE = 0 RE = 0 for i in range(n): p.append(input()) for j in p : if j == "AC": AC += 1 elif j == "WA": WA += 1 elif j == "TLE": TLE += 1 else: RE += 1 print("AC x " + str(AC)) print("WA x " + str(WA)) print("TLE x " + str(TLE)) print("RE x " + str(RE))
0
null
20,907,689,504,438
170
109
n, k, c = map(int, input().split()) s = input() bound_to_work = [0] * n def get_days(s): days = [0] * n changes = [0] * n last_day = -1 ndays = 0 for i in range(n): if (last_day == -1 or i - last_day > c) and s[i] == 'o': ndays += 1 last_day = i changes[i] = 1 days[i] = ndays return days ldays = get_days(s) rdays = get_days(s[::-1])[::-1] for i in range(n): lchanges = (i > 0 and ldays[i] != ldays[i - 1] or i == 0) rchanges = i == n - 1 or rdays[i + 1] != rdays[i] if lchanges and rchanges and ldays[i] + rdays[i] == k + 1: bound_to_work[i] = 1 for i, f in enumerate(bound_to_work): if f: print(i + 1)
N = int(input()) l = [1] for i in range(1,12): l.append(26**i + l[i-1]) for i in range(12): if l[-(i+1)] > N: continue else: order = 12 - i break a = [] for i in range(order): a.append(26**i) n = N - l[order-1] s = "" for i in range(order): s += ( chr( ord("a") + (n // a[-(i+1)]) ) ) n -= a[-(i+1)] * (n // a[-(i+1)]) print(s)
0
null
26,156,989,835,170
182
121
import math N = int(input()) A = list(map(int, input().split())) Sum = 0 mod = (10 ** 9) + 7 for i in range(len(bin(max(A)))-2): Sum_1 = 0 for j in range(N): #print(i, j) if ((A[j] >> i) & 1): Sum_1 += 1 Sum_0 = N - Sum_1 Sum = (Sum + ((Sum_0 * Sum_1) % mod * (2 ** i)) % mod) % mod # print(Sum_0,Sum_1) print(Sum)
N = int(input()) A = list(map(int, input().split())) num_list = [0] * 100 P = 10 ** 9 + 7 for i in A: tmp = i for j in range(len(bin(i)) - 2): num_list[j] += (tmp & 1) tmp = tmp >> 1 ans = 0 def func(N, n): return (N - n) * n for i in range(100): ans = (ans + func(N, num_list[i]) * 2 ** i) % P print(ans)
1
123,161,796,115,232
null
263
263
def resolve(): N,K,C = map(int,input().split()) S=input() dpt1=[0]*K dpt2=[0]*K pnt = 0 for i in range(K): while S[pnt]=="x": pnt+=1 dpt1[i]=pnt pnt += C+1 pnt = N-1 for i in range(K-1,-1,-1): while S[pnt] == "x": pnt -=1 dpt2[i]=pnt pnt-=C+1 for a,b in zip(dpt1,dpt2): if a == b: print(a+1) if __name__ == "__main__": resolve()
_, S = input(), input().split() _, T = input(), input().split() print(sum(t in S for t in T))
0
null
20,341,445,279,590
182
22
a, b, c = [int(_) for _ in input().split()] if a + b > c: print("No") elif 4 * a * b < (c - b - a) ** 2: print("Yes") else: print("No")
arr = map(int,raw_input().split()) arr.sort() arr = map(str,arr) print ' '.join(arr)
0
null
25,819,744,156,288
197
40
N, K = map(int, input().split()) vec = [0] * N for _ in range(K): d = int(input()) A = list(map(int, input().split())) for i in range(d): vec[A[i]-1] += 1 print(vec.count(0))
N, K = map(int, input().split()) sunukes = [0 for k in range(N)] for k in range(K): d = int(input()) A = list(map(int, input().split())) for a in A: sunukes[a-1] += 1 assert len(A) == d print(len([k for k in sunukes if k == 0]))
1
24,480,429,132,000
null
154
154