code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
import sys input=lambda :sys.stdin.readline().rstrip() mod = 10**9+7 n, k = map(int, input().split()) d = [0] * (k+1) for i in range(1, k+1): d[i] = pow(k//i, n, mod) for i in range(k, 0, -1): for j in range(2*i, k+1, i): d[i] -= d[j] d[i] %= mod ans=0 for i in range(1, k+1): ans += d[i]*i ans %= mod print(ans)
N, K = map(int,input().split()) mod = 10**9+7 gcd_num = [1]*(K+1) for i in range(K//2, 0, -1): gcd_num[i] = pow((K//i), N, mod) for j in range(2, K//i + 1): gcd_num[i] -= gcd_num[i*j] gcd_num[i] = gcd_num[i]%mod ans = 0 for i in range(1,K+1): ans += i * gcd_num[i] % mod print(ans%mod)
1
36,935,762,500,870
null
176
176
import math r = input() print ("%.5f " "%.5f")% (r*r*math.pi, 2*r*math.pi)
H,W,K = map(int,input().split()) s=[list(input()) for i in range(H)] area=[[0 for _ in range(W)] for _ in range(H)] st_num=[0]*H st_pos=[[] for _ in range(H)] for i in range(H): for j in range(W): if s[i][j]=="#": st_num[i] += 1 st_pos[i].append(j) upper=0 cnt=0 for i in range(H): if st_num[i]==0: upper=min(upper,i) else: cnt+=1 #左の余白 if st_pos[i][0]>0: for p in range(upper,i+1): for q in range(st_pos[i][0]): area[p][q]=cnt #左端のいちごから右端のいちご左まで for j in range(st_num[i]-1): for p in range(upper,i+1): for q in range(st_pos[i][j],st_pos[i][j+1]): area[p][q]=cnt cnt+=1 #右端のいちごから右 for p in range(upper,i+1): for q in range(st_pos[i][-1],W): area[p][q]=cnt upper = i+1 if upper!=H: #下端のいちごよりも下の領域 for p in range(upper,H): for q in range(W): area[p][q]=area[upper-1][q] for i in area: print(*i)
0
null
72,517,412,005,312
46
277
x=int(input()) x+=1 print(x%2)
N, = map(int, input().split()) print(1-N)
1
2,925,866,568,768
null
76
76
import math r = int(input()) print(int(r * r))
r = int(input()) r2 = r**2 ans = r**2 / 1 print(int(ans))
1
144,924,400,033,648
null
278
278
import sys from collections import deque input = sys.stdin.readline n=int(input()) L=deque([i for i in range(1,10)]) if n<=9: ans = L[n-1] else: cnt = 9 for i in range(1,n): c=L.popleft() if c%10!=0: L.append(c*10+(c%10)-1) cnt+=1 if cnt>=n: break L.append(c*10+(c%10)) cnt+=1 if cnt>=n: break if c%10!=9: L.append(c*10+(c%10)+1) cnt+=1 if cnt>=n: break ans = L[-1] print(ans)
k = int(input()) cand = [[1,2,3,4,5,6,7,8,9]] for i in range(9): tmp = [] for val in cand[-1]: if val % 10 != 0: tmp.append(val*10 + (val%10 - 1)) tmp.append(val*10 + (val % 10)) if val % 10 != 9: tmp.append(val*10 + (val%10 + 1)) cand.append(tmp) ans = [] for j in range(len(cand)): for val in cand[j]: ans.append(val) ans = sorted(ans) print(ans[k - 1])
1
40,101,050,588,060
null
181
181
p = input() * 2 s = input() print('Yes' if s in p else 'No')
x = input().split() x[0], x[1], x[2] = x[2], x[0], x[1] print(x[0]+' '+x[1]+' '+x[2])
0
null
19,944,784,142,848
64
178
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) gap=abs(a-b) if v>w: c=gap/(v-w) if t>=c: print('YES') else: print('NO') else: print('NO')
a,v = map(int, input().split()) b,w = map(int, input().split()) T = int(input()) if abs(b-a) <= (v-w)*T: print('YES') else: print('NO')
1
15,071,797,606,892
null
131
131
import math n = int(input()) xn_list = list(map(int, input().split())) ans = float('inf') for i in range(1, 100): temp = 0 for j in xn_list: temp += (j-i)**2 ans = min(ans, temp) print(ans)
D = int(input()) c = [int(i) for i in input().split()] s = [] for i in range(D): tmp = [int(j) for j in input().split()] s.append(tmp) t = [] for i in range(D): t.append(int(input())) sat = 0 lst = [0 for i in range(26)] for i in range(D): sat += s[i][t[i]-1] lst[t[i]-1] = i + 1 for j in range(26): sat -= c[j] * ((i + 1) - lst[j]) print(sat)
0
null
37,604,197,512,640
213
114
N = int(input()) S, T = (x for x in input().split()) ans = '' for i in range(N): ans += (S[i] + T[i]) print(ans)
def answer(n: int, s: str, t: str) -> str: new_str = '' for i in range(n): new_str += f'{s[i]}{t[i]}' return new_str def main(): n = int(input()) s, t = input().split() print(answer(n, s, t)) if __name__ == '__main__': main()
1
112,065,199,094,068
null
255
255
def main(): T = input() T = T.replace("?", "D") print(T) if __name__ == '__main__': main()
import sys n,k=map(int,input().split()) A=[] mod=10**9+7 zero=0 a=list(map(int,input().split())) for i in range(n): if a[i]>0: A.append([a[i],0]) elif a[i]<0: A.append([-a[i],1]) else: zero+=1 if k>n-zero: print(0) sys.exit() A=list(reversed(sorted(A))) cnt=0 for i in range(k): cnt+=A[i][1] chk=0 for i in range(n-zero): chk+=A[i][1] if cnt%2==0: ans=1 for i in range(k): ans=ans*A[i][0]%mod print(ans) elif chk==n-zero: if zero>0: print(0) sys.exit() ans=1 for i in range(k): ans=ans*A[n-i-1][0]%mod print((-ans)%mod) elif k==n-zero: ans=1 if zero>0: print(0) else: for i in range(k): ans=ans*A[i][0]%mod print((-ans)%mod) else: if A[k][1]==0: p=A[k][0] m=0 for i in range(k+1,n-zero): if A[i][1]==1: m=A[i][0] break else: m=A[k][0] p=0 for i in range(k+1,n-zero): if A[i][1]==0: p=A[i][0] break #print(m,p) if A[k-1][1]==0: l=0 Xl=-1 for i in range(k-1): if A[k-i-2][1]==1: l=A[k-i-2][0] Xl=k-i-2 break #print(l,k) if m*l>p*A[k-1][0] or Xl==-1: ans=1 for i in range(k-1): ans=ans*A[i][0]%mod ans=ans*m%mod print(ans) else: ans=1 for i in range(k): if i==Xl: continue ans=ans*A[i][0]%mod ans=ans*p%mod print(ans) else: l=0 Xl=-1 for i in range(k-1): if A[k-i-2][1]==0: l=A[k-i-2][0] Xl=k-i-2 break #print(l,k) if p*l>m*A[k-1][0] or Xl==-1: ans=1 for i in range(k-1): ans=ans*A[i][0]%mod ans=ans*p%mod print(ans) else: ans=1 for i in range(k): if i==Xl: continue ans=ans*A[i][0]%mod ans=ans*m%mod print(ans)
0
null
13,999,563,394,530
140
112
N = int(input()) MOD = 10**9+7 nums = list(map(int, input().split())) B = [0 for _ in range(60)] for num in nums: for i in range(60): if num>>i&1: B[i] += 1 answer = 0 for i, b in enumerate(B): if b > 0: answer = (answer+b*(N-b)*2**i)%MOD print(answer)
def mod_pow(a, n): res = 1 while n > 0: if n & 1: res = res * a % mod a = a * a % mod n >>= 1 return res n = int(input()) a = list(map(int, input().split())) mod = 10 ** 9 + 7 cnt = [0] * 60 for v in a: for i in range(60): if (v >> i) & 1: cnt[i] += 1 pow_2 = [1] for i in range(60): pow_2.append(pow_2[-1] * 2 % mod) res = 0 for v in a: for i in range(60): if (v >> i) & 1: res = (res + (n - cnt[i]) * pow_2[i] % mod) % mod else: res = (res + cnt[i] * pow_2[i] % mod) % mod print(res * mod_pow(2, mod - 2) % mod)
1
122,792,313,722,100
null
263
263
a,b,c=input().split() print(c,a,b)
A,B,C = map(int, input().split()) print('{} {} {}'.format(C,A,B))
1
37,844,261,685,780
null
178
178
S = list(str(input())) T = list(str(input())) tt = 0 cnt = 0 for i in S: if i != T[tt]: cnt += 1 tt += 1 print(cnt)
def solver(S,T): counter = 0 for i in range(len(S)): Si = S[i] Ti = T[i] if Si != Ti: counter += 1 return counter S = input() T = input() print(solver(S,T))
1
10,457,225,087,022
null
116
116
#!/usr/bin/env python3 def pow(N,R,mod): ans = 1 i = 0 while((R>>i)>0): if (R>>i)&1: ans *= N ans %= mod N = (N*N)%mod i += 1 return ans%mod def main(): N,K = map(int,input().split()) li = [0 for _ in range(K)] mod = 10**9+7 ans = 0 for i in range(K,0,-1): mm = K//i mm = pow(mm,N,mod) for j in range(2,(K//i)+1): mm -= li[i*j-1] li[i-1] = mm ans += (i*mm)%mod ans %= mod print(ans) if __name__ == '__main__': main()
#!/usr/bin/env python # coding: utf-8 def ri(): return int(input()) def rl(): return list(input().split()) def rli(): return list(map(int, input().split())) def main(): t = input() bef = '!' s = "" for c in t: nc = c if c == '?': nc = "D" bef = nc s += nc print(s) if __name__ == '__main__': main()
0
null
27,482,869,386,982
176
140
a,b,c=map(int,input().split()) n = a // (b+c) m = a - (b+c)*n res = n*b if m < b: res += m else: res += b print(res)
S=input() P=input() I=S*2 if P in I: print('Yes') else: print('No')
0
null
28,477,881,750,684
202
64
n1 = int(input()) r1 = n1 * n1 print(r1)
from collections import deque def main(): d = deque() for _ in range(int(input())): command = input() if command[0] == 'i': d.appendleft(command[7:]) elif command[6] == ' ': try: d.remove(command[7:]) except ValueError: pass elif len(command) == 11: d.popleft() else: d.pop() print(*d) if __name__ == '__main__': main()
0
null
72,485,126,940,172
278
20
N=int(input()) S=input() count = 0 for i in range(1000): if i < 100: target_1 = "0" if i < 10: target_2 = "0" target_3 = str(i) else: target_2 = str(i)[0] target_3 = str(i)[1] else: target_1 = str(i)[0] target_2 = str(i)[1] target_3 = str(i)[2] step = 1 for j in range(N): if S[j] == target_1 and step == 1: step = 2 pass elif S[j] == target_2 and step == 2: step = 3 elif S[j] == target_3 and step == 3: count += 1 break print(count)
N = int(input()) S = str(input()) num = [] for _ in range(10): num.append([]) for i in range(N): num[int(S[i])].append(i) ans = 0 for X1 in range(0, 10): for X2 in range(0, 10): for X3 in range(0, 10): X = str(X1) + str(X2) + str(X3) if num[X1] != [] and num[X2] != [] and num[X3] != []: if num[X1][0] < num[X2][-1]: for i in num[X2]: if num[X1][0] < i < num[X3][-1]: ans += 1 break print(ans)
1
128,630,467,884,488
null
267
267
h,a = map(int,input().split()) ans = 0 for _ in range(h): h -= a ans += 1 if h <= 0: break print(ans)
import math H, A = list(map(int, input().split())) if H % A == 0: print(H // A) else: print(math.ceil(H / A))
1
76,896,985,466,910
null
225
225
a = input() if(a[0]=='7' or a[1]=='7' or a[2]=='7'): print("Yes") else: print("No")
x = int(input()) deposit = 100 year = 0 rate = 101 while(deposit < x): deposit = deposit * rate // 100 year += 1 print(year)
0
null
30,740,168,090,368
172
159
N = int(input()) L = input().split() n = int(input()) l = input().split() dup = [] count = 0 for i in range(N): for j in range(n): if L[i] == l[j]: dup.append(L[i]) break dup = list(set(dup)) print(len(dup))
def main(): n = int(stdinput()) S = [*map(int, stdinput().split())] q = int(stdinput()) T = [*map(int, stdinput().split())] S = sorted(S) T = sorted(T) i = j = c = 0 while i < n and j < q: if S[i] == T[j]: c += 1 i += 1 j += 1 elif S[i] > T[j]: j += 1 else: i += 1 print(c) def stdinput(): from sys import stdin return stdin.readline().strip() if __name__ == '__main__': main() # import cProfile # cProfile.run('main()')
1
69,196,359,008
null
22
22
N,A,B=map(int,input().split()) div=N//(A+B) mod=N%(A+B) print(div*A+min(mod,A))
n = int(input()) dict = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", 9:"i", 10:"j"} dict2 = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10} #ans = [["a", 1]] #for i in range(n-1): # newans = [] # for lis in ans: # now = lis[0] # count = lis[1] # for j in range(1, count + 2): # newans.append([now + dict[j], max(j, count)]) # ans = newans #for lis in ans: # print(lis[0]) def dfs(s): if len(s) == n: print(s) return m = max(s) count = dict2[m] for i in range(1, count+2): dfs(s+dict[i]) dfs("a")
0
null
54,005,944,163,680
202
198
n = int(input()) for _ in range(n): edges = sorted([int(i) for i in input().split()]) if edges[0] ** 2 + edges[1] ** 2 == edges[2] ** 2: print("YES") else: print("NO")
deta_set_count = int(input()) for _ in range(deta_set_count): k = list(map(int, input().split())) k= sorted(k) if k[0]**2 + k[1]**2 == k[2]**2: print('YES') else: print('NO')
1
317,980,324
null
4
4
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")
s = input() l = [0] m = [0] a = 0 b = 0 arr = [] for i in range(len(s)): if s[i] == '<': a += 1 else: a = 0 l.append(a) if s[len(s) - i - 1] == '>': b += 1 else: b = 0 m.append(b) m = m[::-1] for i in range(len(l)): arr.append(max(l[i], m[i])) ans = sum(arr) print(ans)
0
null
80,221,860,192,980
87
285
a = list(input()) if a[-1] == 's': a.append('e') a.append('s') else: a.append('s') print(''.join(a))
str = input() if str[len(str)-1] == "s": str = str + "es" else: str = str + "s" print(str)
1
2,373,292,977,630
null
71
71
#D from collections import deque n,k = map(int,input().split()) a = list(map(int,input().split())) tel = deque() tel.append(1) visit = [False for _ in range(n)] visit[0] = True for i in range(n): nx = a[tel[i]-1] if visit[nx-1] == True : tel.append(nx) #ループの始まりのindexをidxに格納 idx = tel.index(nx) break tel.append(nx) visit[nx-1] = True #print(tel) #print(visit) if k <= idx: goal = tel[k] else: k -= idx loop_num = len(tel) - idx - 1 #print('idx:',idx) #print('loop_num:',loop_num) goal = tel[idx + k%loop_num] print(goal)
N, K = map(int, input().split()) portals = [0] + list(map(int, input().split())) visitTowns = list() visitTimes = [0 for _ in range(N + 1)] curTown = 1 timeBackTo = 0 curTime = 0 while True: if visitTimes[curTown] > 0: timeBackTo = visitTimes[curTown] break visitTowns.append(curTown) visitTimes[curTown] = curTime # teleport curTown = portals[curTown] curTime += 1 nonLoopCount = timeBackTo loopSpan = len(visitTowns) - nonLoopCount if K <= nonLoopCount: print(visitTowns[K]) exit() rem = (K - nonLoopCount) % loopSpan print(visitTowns[nonLoopCount + rem])
1
22,599,508,367,040
null
150
150
from math import gcd mod = 1000000007 n = int(input()) zero = 0 bad = {} for i in range(n): x, y = map(int, input().split()) if x == 0 and y == 0: zero += 1 continue g = gcd(x, y) x //= g y //= g if y < 0: x, y = -x, -y if y==0 and x<0: x, y = -x, -y is_rotate90 = (x <= 0) if is_rotate90: x, y = y, x y = -y if not (x, y) in bad: bad[x, y] = [0, 0] if is_rotate90: bad[x, y][0] += 1 else: bad[x, y][1] += 1 # print(bad) cnt = 1 for x, y in bad: c1, c2 = bad[x, y] c3 = 1 c3 += pow(2, c1, mod) - 1 c3 += pow(2, c2, mod) - 1 cnt = cnt * c3 % mod ans = (cnt + zero - 1) % mod # print('cnt',cnt) # print('zero',zero) # print('ans',ans) print((ans+mod) % mod)
import sys input = sys.stdin.readline input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode() #import numpy as np from math import gcd from collections import defaultdict def main(): n=II() mod=10**9+7 ans=1 cnt=0 d=defaultdict(int) for _ in range(n): a,b=MI() if a==b==0: cnt+=1 elif a==0: d[(1,0)]+=1 elif b==0: d[(0,-1)]+=1 else: g=gcd(abs(a),abs(b)) if a*b>0: d[(abs(a//g),abs(b//g))]+=1 else: d[(abs(a//g),-abs(b//g))]+=1 s=set() for a,b in list(d): #print(a,b,s) if (a,b) in s: continue if b>=0: x=d[(a,b)] y=d[(b,-a)] s.add((a,b)) s.add((b,-a)) else: x=d[(a,b)] y=d[(-b,a)] s.add((a,b)) s.add((-b,a)) ans*=2**x+2**y-1 ans%=mod ans+=cnt-1 print(ans%mod) if __name__ == "__main__": main()
1
20,920,714,847,820
null
146
146
def main(): x = int(input()) if x >= 30: print('Yes') else: print('No') if __name__ == '__main__': main()
if(int(input()) >= 30): print('Yes') else: print('No')
1
5,705,562,679,620
null
95
95
import itertools as it import math def Dist (x1,y1,x2,y2): dis = (x2 - x1)**2 + (y2 - y1)**2 return math.sqrt(dis) N = int(input()) Pos = [] res = 0 for i in range(N): pos = list(map(int,input().split())) Pos.append(pos) array = list(it.permutations(i for i in range(N))) for i in range(math.factorial(N)): for j in range(N-1): res += Dist(Pos[array[i][j]][0],Pos[array[i][j]][1],Pos[array[i][j+1]][0],Pos[array[i][j+1]][1]) print(res / math.factorial(N))
from fractions import gcd def main(): N = int(input()) A = list(map(int, input().split())) MOD = 10**9 + 7 lcm = 1 for a in A: lcm = lcm * a // gcd(lcm, a) ans = 0 for a in A: ans += lcm // a print(ans % MOD) if __name__ == "__main__": main()
0
null
118,293,479,563,556
280
235
n = str(input()) flag = 0 for i in range(3): if n[i] == '7': flag = 1 if flag == 1: print('Yes') else: print('No')
n = input() print('Yes' if '7' in n else 'No')
1
34,413,057,543,042
null
172
172
n = int(input()) d = set() for _ in range(n): c, s = input().split() if c == 'insert': d.add(s) else: print('yes' if s in d else 'no')
class Dictionary_class: def __init__(self): self.dic = set() def insert(self, str): self.dic.add(str) def find(self, str): if str in self.dic: return True else: return False n = int(input()) answer = "" dic = Dictionary_class() for i in range(n): instruction = input().split() if instruction[0] == "insert": dic.insert(instruction[1]) elif instruction[0] == "find": if dic.find(instruction[1]): answer += "yes\n" else: answer += "no\n" print(answer, end = "")
1
76,580,726,040
null
23
23
s = input() right = [0]*(len(s)+1) for i in range(len(s)): if s[i] == '<': right[i+1] = right[i] + 1 left = [0]*(len(s)+1) for i in range(len(s)-1, -1, -1): if s[i] == '>': left[i] = left[i+1] + 1 ans = 0 for i in range(len(s)+1): ans += max(right[i], left[i]) print(ans)
s = input() de_num = 0 le_num = 0 ans = [0]*(len(s)+1) for i in range(len(s)): if s[i] == "<": de_num += 1 else: de_num = 0 ans[i+1] = de_num s = s[::-1] ans.reverse() for i in range(len(s)): if s[i] == ">": le_num += 1 else: le_num = 0 ans[i+1] = max(le_num,ans[i+1]) print(sum(ans))
1
156,855,274,654,328
null
285
285
N=int(input()) res=[1000000000000] for i in range(1,int(N**0.5)+1): if(N%i==0): res.append(i+N//i-2) print(min(res))
def make_divisors(n): ans = 10 ** 12 + 10 i = 1 while i*i <= n: if n % i == 0: t = 0 if i != n // i: t = i + (n//i) - 2 else: t = i * 2 - 2 #print(i, n//i, t) if ans > t: ans = t i += 1 return ans n = int(input()) print(make_divisors(n))
1
161,450,417,967,644
null
288
288
import sys input = sys.stdin.readline from collections import * def bfs(s): q = deque([s]) dist = [-1]*N dist[s] = 0 while q: v = q.popleft() for nv in G[v]: if dist[nv]==-1: dist[nv] = dist[v]+1 q.append(nv) if s==V-1: is_leaf[v] = False return dist N, U, V = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(N-1): A, B = map(int, input().split()) G[A-1].append(B-1) G[B-1].append(A-1) is_leaf = [True]*N d1 = bfs(V-1) d2 = bfs(U-1) ans = 0 for i in range(N): if not is_leaf[i] and d2[i]<=d1[i]: ans = max(ans, d1[i]) print(ans)
n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a_sums, b_sums = [0], [0] for i in range(n): a_sums.append(a_sums[i] + a[i]) for i in range(m): b_sums.append(b_sums[i] + b[i]) ans = 0 j = m for i in range(n + 1): if a_sums[i] > k: break while a_sums[i] + b_sums[j] > k: j -= 1 ans = max(ans, i + j) print(ans)
0
null
63,745,617,219,902
259
117
N = int(input()) R = [int(input()) for _ in range(N)] maxv = -2000000000 minv = R[0] for i in range(1,N): maxv = max([maxv, R[i] - minv ]) minv = min([minv, R[i]]) print(maxv)
# coding: utf-8 def getint(): return int(input().rstrip()) def main(): n = getint() values = [] for i in range(n): values.append(getint()) maxv = values[1] - values[0] minv = values[0] for j in range(1,n): maxv = max(maxv, values[j]-minv) minv = min(minv, values[j]) print(maxv) if __name__ == '__main__': main()
1
14,222,804,142
null
13
13
from typing import List def main(): n = int(input()) m = xyz(n) for i in m: print(i) def f(x, y, z): return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x def xyz(n: int) -> List[int]: result = [0] * n for x in range(1, 100): for y in range(1, 100): for z in range(1, 100): m = f(x, y, z) if m > n: break result[m - 1] += 1 return result if __name__ == '__main__': main()
N=int(input()) ans=[0]*(N+1) for x in range(1,101): for y in range(1,101): for z in range(1,101): fn=x**2+y**2+z**2+x*y+y*z+z*x if fn>N: break else: ans[fn]=ans[fn]+1 for n in range(1,N+1): print(ans[n])
1
7,902,867,404,740
null
106
106
m=[0]*50 f=[0]*50 r=[0]*50 result=[""]*50 num=0 while True: a,b,c=map(int,input().split()) if a == b == c ==-1: break else: m[num],f[num],r[num]=a,b,c num+=1 for i in range(num): if m[i] == -1 or f[i]==-1: result[i]="F" elif m[i]+f[i]>=80: result[i]="A" elif m[i]+f[i]>=65: result[i]="B" elif m[i]+f[i]>=50: result[i]="C" elif m[i]+f[i]>=30: if r[i] >=50: result[i]="C" else: result[i]="D" else: result[i]="F" for i in range(num): print(result[i])
while True: m, f, r = [int(_) for _ in input().split()] if m == -1 and f == -1 and r == -1: break sum = m+f if m == -1 or f == -1 or sum < 30: print("F") else: if sum >= 80: print("A") elif sum >= 65: print("B") elif sum >= 50: print("C") else: if r >= 50: print("C") else: print("D")
1
1,216,617,023,068
null
57
57
N, K, S = map(int, input().split()) S2 = S-1 if S == 1000000000 else S+1 As = [S]*K+[S2]*(N-K) print(" ".join(map(str, As)))
n,k,s = map(int, input().split()) if s < 10**9: ans = [s+1] * n else: ans = [1]*n ans[:k] = [s]*k print(" ".join(map(str,ans)))
1
90,654,909,269,430
null
238
238
import sys sys.setrecursionlimit(300000) def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 INF = float('inf') X, K, D = MI() if abs(X) >= K * D: print(abs(X) - K * D) else: a = abs(abs(X) - (abs(X) // D) * D) K -= (abs(X) // D) if K % 2 == 0: print(a) else: print(abs(a - D))
inp = list(map(int, input().split())) a, b = inp[0], inp[1] if a > b*2: print(a-b*2) else: print(0)
0
null
85,830,962,586,202
92
291
while(True): a=list(map(int,input().split())) if(a[0]==0 and a[1]==0): break for x in range(a[0]): if x==0 or x==a[0]-1: print("#"*a[1]) else: print("#"+"."*(a[1]-2)+"#") print()
#coding:utf-8 #1_5_B 2015.4.1 while True: length,width = map(int,input().split()) if (length,width) == (0,0): break for i in range(length): for j in range(width): if j == width - 1: print('#') elif i == 0 or i == length - 1 or j == 0: print('#', end='') else: print('.', end='') print()
1
827,600,907,112
null
50
50
S,T = input().split() print(T,S, sep='')
input() ia=[int(i) for i in input().split(" ")] print(min(ia),max(ia),sum(ia))
0
null
51,743,731,591,720
248
48
import math r = int(input()) h = 2 * r * math.pi print(h)
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) x = [0] * (N + 1) y = [0] * (M + 1) for i in range(N): x[i + 1] = x[i] + A[i] for i in range(M): y[i + 1] = y[i] + B[i] j = M ans = 0 for i in range(N + 1): if x[i] > K: continue while j >= 0 and x[i] + y[j] > K: j -= 1 ans = max(ans, i + j) print(ans)
0
null
21,024,224,385,230
167
117
print("YES") if int(input()) == len(list(set(input().split(" ")))) else print("NO")
N,K=map(int,input().split()) mod=10**9+7 X=[0]+[pow(K//d,N,mod) for d in range(1,K+1)] ''' Y=[[] for i in range(K+1)] for i in range(1,K+1): for j in range(i,K+1,i): Y[j].append(i) ''' #print(X) isPrime=[1 for i in range(K+1)] isPrime[0]=0;isPrime[1]=0 for i in range(K+1): if isPrime[i]==0: continue for j in range(2*i,K+1,i): isPrime[j]=0 Mebius=[1 for i in range(K+1)] Mebius[0]=0 for i in range(2,K+1): if isPrime[i]==0: continue for j in range(i,K+1,i): Mebius[j]*=-1 for i in range(2,K+1): for j in range(i*i,K+1,i*i): Mebius[j]=0 Z=[0 for i in range(K+1)] for i in range(1,K+1): for j in range(i,K+1,i): Z[i]+=X[j]*Mebius[j//i] ans=0 for i in range(1,K+1): ans+=Z[i]*i ans%=mod print(ans) ''' P(G%d==0) Gがd,2d,3d,...の可能性がある P(d)-P(2d)-P(3d)-P(5d)+P(6d)-P(7d) '''
0
null
55,171,956,914,460
222
176
x=input() s=x*2 y=input() if y in s: print("Yes") else: print("No")
def main(): s = input() p = input() if (s + s).__contains__(p): print('Yes') else: print('No') if __name__ == '__main__': main()
1
1,749,673,068,600
null
64
64
def get_dice(pips): return [[0, pips[4], 0, 0], [pips[3], pips[0], pips[2], pips[5]], [0, pips[1], 0, 0]] def move_e(dice): dice[1] = dice[1][3:] + dice[1][:3] return dice def move_n(dice): return [[0, dice[1][1], 0, 0], [dice[1][0], dice[2][1], dice[1][2], dice[0][1]], [0, dice[1][3], 0, 0]] def move_s(dice): return [[0, dice[1][3], 0, 0], [dice[1][0], dice[0][1], dice[1][2], dice[2][1]], [0, dice[1][1], 0, 0]] def move_w(dice): dice[1] = dice[1][1:] + dice[1][:1] return dice func = {'E':move_e,'N':move_n,'S':move_s,'W':move_w} dice = get_dice(list(map(int, input().split()))) for c in input(): dice = func[c](dice) print(dice[1][1])
""" Hが少ないので、縦で割るパターンは全探索して見る。 dpとか使わずに、貪欲的に割っていけばよい。 """ H,W,K = map(int,input().split()) choco = [list(input()) for _ in range(H)] accum = [[0]*W for _ in range(H)] for i in range(H): for j in range(W): accum[i][j] = accum[i][j-1] + int(choco[i][j]) ans = float("INF") for i in range(2**H): """ i を2進数表記したときに1になっているインデックスに該当する行数で分割する。 例えば00100なら3行目と4行目の間で分割する。 """ binI = format(i,"0"+str(H)+"b") group = {} groupNum = 0 for j in range(H): group[j] = groupNum if binI[j] == "1": groupNum += 1 breakCnt = groupNum tmp = [0]*(groupNum+1) for j in range(W): tmp2 = [0]*(groupNum+1) for k in range(H): groupNum = group[k] if choco[k][j] == "1": tmp2[groupNum] += 1 if max(tmp2) > K: break else: for l in range(groupNum+1): tmp[l] += tmp2[l] if max(tmp) > K: breakCnt += 1 tmp = tmp2 else: ans = min(ans,breakCnt) print(ans)
0
null
24,227,454,434,680
33
193
r,c = map(int,input().split()) matrix = [list(map(int,input().split())) for i in range(r)] for i in range(r): matrix[i].append(sum(matrix[i])) row = [] for i in range (c+1): row_sum = 0 for j in range(r): row_sum += matrix[j][i] row.append(row_sum) matrix.append(row) for i in range(r+1): for j in range(c+1): print(matrix[i][j],end="") if j != c: print(" ",end="") if j == c : print("")
d=input().split() for o in list(input()): s={'N':(0,1,5,4),'W':(0,2,5,3),'E':(0,3,5,2),'S':(0,4,5,1)}[o] for i in range(3):d[s[i+1]],d[s[i]]=d[s[i]],d[s[i+1]] print(d[0])
0
null
803,490,834,770
59
33
a=int(input()) b=int(input()) ans = set() ans.add(a) ans.add(b) all = {1,2,3} print((all-ans).pop())
A=int(input()) #pr#print(A) int(A) B=int(input()) if A + B == 3: print(3) elif A+B==4: print(2) else: print(1)
1
110,404,045,977,240
null
254
254
N = int(input()) s = [] t = [] for i in range(N) : p, q = input().split() s.append(p) t.append(int(q)) X = input() xi = s.index(X) ans = 0 for i in range(xi+1, N) : ans += t[i] print(ans)
print((int(input())+1)//2-1)
0
null
125,074,680,625,752
243
283
N = int(input()) def cnt(s): r = [0] * (len(s)+1) for i, v in enumerate(s): if v == '(': r[i+1] = r[i] + 1 else: r[i+1] = r[i] - 1 return r[0], r[-1], min(r) # S1 := 始点 < 終点 S1 = [] # S2 := 始点 => 終点 S2 = [] for i in range(N): s = input() t = tuple(cnt(s)) if t[1] > 0: S1.append(t) else: S2.append(t) def main(): # Sの終点を合計して0じゃなかったら、終わり if sum([s[1] for s in S1]) + sum([s[1] for s in S2]) != 0: print("No") return # S1の中で、最小値が大きい順に並べる X1 = sorted(S1, key=lambda x: x[2], reverse=True) # S2の中で、最小値が小さい順に並べる X2 = sorted(S2, key=lambda x: x[2]-x[1]) T = 0 # X1を並べきった後に、X2を並べて実現可能か調べる、終点を合計して0になることは確認済み for s, t, mi in X1: if T + mi < 0: print("No") return T += t for s, t, mi in X2: if T + mi < 0: print("No") return T += t print("Yes") main()
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def resolve(): N = ir() pos = [] neg = [] tot = 0 for i in range(N): tmp = 0 b = 0 for c in sr(): if c == '(': tmp += 1 else: tmp -= 1 b = min(b, tmp) if tmp > 0: pos.append([tmp, b]) else: neg.append([-tmp, b-tmp]) tot += tmp if tot != 0: print('No') return pos = sorted(pos, key=lambda x: (x[1], x[0]))[::-1] neg = sorted(neg, key=lambda x: (x[1], x[0]))[::-1] c = 0 for p in pos: t, b = p if c+b < 0: print('No') return c += t c = 0 for n in neg: t, b = n if c+b < 0: print('No') return c += t print('Yes') return resolve()
1
23,664,593,224,430
null
152
152
### ---------------- ### ここから ### ---------------- import sys from io import StringIO import unittest def yn(b): print("Yes" if b==1 else "No") return def resolve(): readline=sys.stdin.readline n,m=map(int, readline().rstrip().split()) ac=[0]*n wa=[0]*n for i in range(m): p,s=readline().rstrip().split() p=int(p)-1 if s=="AC": ac[p]=1 continue if ac[p]==0: wa[p]+=1 for i in range(n): wa[i]*=ac[i] print(sum(ac),sum(wa)) return if 'doTest' not in globals(): resolve() sys.exit() ### ---------------- ### ここまで ### ----------------
X = int(input()) ans = 0 num = 100 while X > num: num = num+num//100 ans += 1 print(ans)
0
null
60,220,051,438,810
240
159
l = list(map(int,input().split())) l.sort() if (l[0]==l[1] and l[1] != l[2]) or (l[0] != l[1] and l[1]==l[2]): print('Yes') else: print('No')
a, b, c = map(int, input().split()) if(a==b or a==c or c==b): if(a==b and b==c): pass else: print("Yes") exit() print("No")
1
68,065,405,133,810
null
216
216
h, a = map(int, input().split()) print( - ( - h // a))
n,m = map(int,input().split()) # 受け取った文字をスペースで分けてリスト化 a = list(input().split()) # 文字列のリストの値を整数化 a_int = [int(i) for i in a] # 夏休みの日数がリスト内の日数の合計より多ければ残日数を表示 if n >= sum(a_int): print(n - sum(a_int)) # リスト内の日数の合計が夏休みの日数より多ければ-1を表示 else: print("-1")
0
null
54,246,605,924,378
225
168
n = int(input()) a = set(input().split()) if len(a) == n: print("YES") else: print("NO")
n = int(input()) l = list(map(int, input().split())) edge = [0 for x in range(n)] if l[0] != 0: print(0) exit() for i in l: edge[i]+=1 ans = 1 for i in range(1, n): ans *= edge[l[i] - 1] ans %= 998244353 print(ans)
0
null
114,484,139,259,112
222
284
# abc158_b.py # https://atcoder.jp/contests/abc158/tasks/abc158_b # B - Count Balls / # 実行時間制限: 2 sec / メモリ制限: 1024 MB # 配点 : 200点 # 問題文 # 高橋君は青と赤の 2色のボールを持っており、これらを一列に並べようとしています。 # 初め、列にボールはありません。 # 根気のある高橋君は、次の操作を 10100回繰り返します。 # 列の末尾に、A個の青いボールを加える。その後、列の末尾に B個の赤いボールを加える。 # こうしてできる列の先頭から N個のボールのうち、青いボールの個数はいくつでしょうか。 # 制約 # 1≤N≤1018 # A,B≥0 # 0<A+B≤1018 # 入力は全て整数である # 入力 # 入力は以下の形式で標準入力から与えられる。 # N A B # 出力 # 列の先頭から N個のボールのうち、青いボールの個数を出力せよ。 # 入力例 1 # 8 3 4 # 出力例 1 # 4 # 青いボールをb、赤いボールを rで表すと、列の先頭から 8個のボールは bbbrrrrb であるので、このうち青いボールは 4個です。 # 入力例 2 # 8 0 4 # 出力例 2 # 0 # そもそも赤いボールしか並んでいません。 # 入力例 3 # 6 2 4 # 出力例 3 # 2 # bbrrrr のうち青いボールは 2個です。 global FLAG_LOG FLAG_LOG = False def log(value): # FLAG_LOG = True # FLAG_LOG = False if FLAG_LOG: print(str(value)) def calculation(lines): # S = lines[0] # N = int(lines[0]) N, A, B = list(map(int, lines[0].split())) # values = list(map(int, lines[1].split())) # values = list(map(int, lines[2].split())) # values = list() # for i in range(N): # values.append(int(lines[i])) # valueses = list() # for i in range(N): # valueses.append(list(map(int, lines[i+1].split()))) q, mod = divmod(N, A+B) result = q*A + min(mod, A) return [result] # 引数を取得 def get_input_lines(lines_count): lines = list() for _ in range(lines_count): lines.append(input()) return lines # テストデータ def get_testdata(pattern): if pattern == 1: lines_input = ['8 3 4'] lines_export = [4] if pattern == 2: lines_input = ['8 0 4'] lines_export = [0] if pattern == 3: lines_input = ['6 2 4'] lines_export = [2] return lines_input, lines_export # 動作モード判別 def get_mode(): import sys args = sys.argv global FLAG_LOG if len(args) == 1: mode = 0 FLAG_LOG = False else: mode = int(args[1]) FLAG_LOG = True return mode # 主処理 def main(): import time started = time.time() mode = get_mode() if mode == 0: lines_input = get_input_lines(1) else: lines_input, lines_export = get_testdata(mode) lines_result = calculation(lines_input) for line_result in lines_result: print(line_result) # if mode > 0: # print(f'lines_input=[{lines_input}]') # print(f'lines_export=[{lines_export}]') # print(f'lines_result=[{lines_result}]') # if lines_result == lines_export: # print('OK') # else: # print('NG') # finished = time.time() # duration = finished - started # print(f'duration=[{duration}]') # 起動処理 if __name__ == '__main__': main()
N,A,B = map(int, input().split()) C = A + B print(min(A, N%C) + N//C * A)
1
55,696,905,646,820
null
202
202
N = int(input()) memo = [-1]*500 def fibo(x): if memo[x] != -1: return memo[x] if x == 0 or x == 1: ans=1 memo[x] = ans return ans ans = fibo(x-1) + fibo(x-2) memo[x] = ans return ans print(fibo(N))
N, K = map(int, input().split()) preans = [] for n in range(K, N+2): MIN = (0+n-1) * n / 2 MAX = (N + (N-n+1)) * n / 2 preans.append(MAX - MIN+1) print(int(sum(preans)%(10**9 + 7)))
0
null
16,586,241,262,770
7
170
a, b, c, d = map(int, input().split()) ans = 10**20 * -1 ans = max(ans, a * c) ans = max(ans, a * d) ans = max(ans, b * c) ans = max(ans, b * d) print(ans)
l = list(map(int,input().split())) mx = float('-inf') for i in range(2): for j in range(2,4): mx = max(mx,l[i]*l[j]) print(mx)
1
3,040,163,574,932
null
77
77
a=[input() for i in range(2)] a1=[int(i) for i in a[0].split()] a2=int(a[1]) count=0 while a1[1]<=a1[0]: a1[1]=a1[1]*2 count+=1 while a1[2]<=a1[1]: a1[2]=a1[2]*2 count+=1 if count<=a2: print("Yes") else: print("No")
import math x1,y1,x2,y2=map(float,input().split(' ')) res=math.sqrt((x1-x2)**2+(y1-y2)**2) print(res)
0
null
3,529,083,189,380
101
29
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) a = list(map(int, input().split())) c = 0 ans = -1 for num in a: if num==c+1: c = num else: pass # print(ans) if c>0: ans = max(ans, c) if ans>=0: print(n-ans) else: print(-1)
n,k=map(int,input().split()) a=list(map(int,input().split())) visit=[0 for i in range(n)] goal,loop=[],[] now=0 while visit[now]!=2 : if visit[now]==0 : goal.append(now) else : loop.append(now) visit[now]+=1 now=a[now]-1 if len(goal)>k : print(goal[k]+1) else : res=len(goal)-len(loop) print(loop[(k-res)%len(loop)]+1)
0
null
68,737,397,381,610
257
150
startX, countK, distanceD = map(int, input().split()) n = int(abs(startX) / distanceD) ans = abs(startX) % distanceD if n > countK: ans += distanceD * (n - countK) else: if (countK - n) % 2 == 1: ans= abs(ans - distanceD) print(ans)
N = int(input()) A = list(map(int, input().split())) is_approved = True for i in range(N): if A[i] % 2 != 0: continue if A[i] % 3 != 0 and A[i] % 5 != 0: is_approved = False break if is_approved: print("APPROVED") else: print("DENIED")
0
null
37,236,374,129,262
92
217
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(str, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #import numpy as np from decimal import * #再帰バージョン N = INT() def DFS(n): if len(n) == N: print(n) else: for i in range(len(set(n))+1): m = n+ascii_lowercase[i] DFS(m) DFS("a")
s="abcdefghij" n=int(input()) ans=[["a",1]] c=1 while(c<n): an=[] for i in ans: lim=min(i[1]+1,10) for j in range(lim): if (j==i[1]) and (j!=10): an.append([i[0]+s[j],i[1]+1]) else: an.append([i[0]+s[j],i[1]]) ans=an c+=1 for i in ans: print(i[0])
1
52,658,606,550,528
null
198
198
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_A ??§????????¨?°????????????\????????? ????????????????????????????°?????????¨??§???????????\????????????????????°???????????????????????????????????? """ if __name__ == '__main__': # ???????????????????????\??? raw_input = input() # ??§??????????°????????????\?????????????????? print(raw_input.swapcase())
text = raw_input() t = list(text) for i in range(len(t)): if t[i].isupper(): t[i] = t[i].lower() elif t[i].islower(): t[i] = t[i].upper() print "".join(t)
1
1,503,968,872,640
null
61
61
# coding: utf-8 # Your code here! n=int(input()) sum=0 min=1000001 max=-1000001 table=list(map(int,input().split(" "))) for i in table: sum+=i if max<i: max=i if min>i: min=i print(str(min)+" "+str(max)+" "+str(sum))
class MinMaxAndSum: def output(self, a): print "%d %d %d" % (min(a), max(a), sum(a)) if __name__ == "__main__": mms = MinMaxAndSum() raw_input() a = map(int, raw_input().split()) mms.output(a)
1
712,509,676,266
null
48
48
i = input() i_l = i.split() count = 0 for each in range(int(i_l[0]),int(i_l[1])+1): if int(i_l[2]) % each == 0: count += 1 else: print(count)
def main(): numbers = input().split() a, b, c = map(int, numbers) a_to_b = list(range(a, b + 1)) #a to b result = [x for x in a_to_b if c % x == 0] #約数検索 count = int(len(result)) print(count) if __name__=="__main__": main()
1
545,331,769,092
null
44
44
import sys while 1: H,W = map(int, raw_input().split()) if H == 0 and W == 0: break for i in range(H): for j in range(W): if i%2 == 0: if j%2 == 0: sys.stdout.write("#") else: sys.stdout.write(".") if i%2 != 0: if j%2 != 0: sys.stdout.write("#") else: sys.stdout.write(".") if j == W-1: print "" print ""
import re def bubble_sort(C, N): for i in range(N): for j in reversed(range(1, N)): if C[j][1] < C[j-1][1]: # 1???????????????????°????????????°?????? C[j], C[j-1] = C[j-1], C[j] return C def selection_sort(C, N): for i in range(N): # i ?????????????????¨???????????? minj = i for j in range(i, N): # ?????????????????¨??????????°??????????????????? if C[j][1] < C[minj][1]: minj = j # ??????????????¨??????????°????????????????????????\???????????? C[i], C[minj] = C[minj], C[i] return C def is_stable(C, sorted): # ????????°???????????????????¨???????????????????????´??????????????????? c_container = [] s_container = [] for i in range(len(C)): # C ??§ i ????????\?????????????????§????????°????????????????????¢??? for j in range(len(C)): # ????????°???????????????????????£?????´??? if C[i][1] == C[j][1]: # C ????????????????¨????????????? c_container.append(C[j][0]) # ????????°???????????????????????¨????????´??? if len(c_container) >= 2: # C ??§ i ???????????????????????°?????¨????????°????????????????????¢??? for k in range(len(sorted)): # ????±??????????????????°?????¨????????°???????¨?????????????????????????????????????????????????????´? if sorted[k][1] == C[i][1]: s_container.append(sorted[k][0]) # ??????????????´?????????????????£?????´??? if c_container != s_container: # Not Stable return False # ????????????????????? c_container = [] s_container = [] return True if __name__ == '__main__': N = int(input()) # ??????????????????????????????????????¨?????¨??°?????¨?????????????????????????´? cards = input().split() C = [[] for i in range(N)] for i in range(N): # ??????????¨??????¨??°???????????? symbol_and_num = re.findall(r'(\d+|\D+)', cards[i]) C[i] = [symbol_and_num[0], int(symbol_and_num[1])] # ?????????????????????????????? bubble_sorted = bubble_sort(C.copy(), N) # ?¨??????¨??????????????? bubble_sorted_cards = [val[0] + str(val[1]) for val in bubble_sorted] # ????????????????????? print(' '.join(bubble_sorted_cards)) # stable or not stable print('Stable' if is_stable(C, bubble_sorted) else 'Not stable') # ????????????????????? selection_sorted = selection_sort(C.copy(), N) # ?¨??????¨??????????????? selection_sorted_cards = [val[0] + str(val[1]) for val in selection_sorted] # ????????????????????? print(' '.join(selection_sorted_cards)) # stable or not stable print('Stable' if is_stable(C, selection_sorted) else 'Not stable')
0
null
439,847,914,648
51
16
# エイシング プログラミング コンテスト 2020: B – An Odd Problem N = int(input()) a = [int(i) for i in input().split()] num_odd = 0 for idx in range(1, N + 1, 2): if a[idx -1] % 2 == 1: num_odd += 1 print(num_odd)
print(sum(map(lambda x:int(x)%2,open(0).read().split()[1::2])))
1
7,774,051,126,788
null
105
105
m1,d1=map(int, input().split()) m2,d2=map(int, input().split()) print("1" if m2==m1+1 else "0")
n, s = open(0).read().split() s = list(map(int, list(s))) from itertools import product,repeat ans = 0 for a,b,c in product(range(10), range(10), range(10)): abc = [a,b,c] tmp = 0 for dig in s: if dig == abc[tmp]: tmp += 1 if tmp == 3: ans += 1 break print(ans)
0
null
126,727,282,147,508
264
267
# author: Taichicchi # created: 15.09.2020 21:22:26 import sys X, K, D = map(int, input().split()) X = abs(X) if X >= K * D: print(X - (K * D)) else: k = K - X // D x = X - D * (X // D) if k % 2: print(abs(x - D)) else: print(x)
import bisect N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-1, 1, -1): for j in range(i-1, 0, -1): a, b = L[i], L[j] c = a - b + 1 if c > b: continue ans += (j - bisect.bisect_left(L, c)) print(ans)
0
null
88,315,916,458,980
92
294
import math N = int(input()) n_max = int(math.sqrt(N)) a = [] for i in range(1,n_max + 1): if N % i == 0: a.append(i) ans = 2 * N for i in a: if (i + (N // i) - 2) < ans: ans = i + (N // i) - 2 print(ans)
def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] n = int(input()) divisors = make_divisors(n) #print(divisors) if len(divisors)%2==1: print(divisors[len(divisors)//2]*2-2) else: m = len(divisors)//2 print(divisors[m-1]+divisors[m]-2)
1
161,209,721,306,172
null
288
288
def solve(string): n = int(string) return str(sum(i * (n // i) * (n // i + 1) // 2 for i in range(1, n + 1))) if __name__ == '__main__': import sys print(solve(sys.stdin.read().strip()))
N = int(input()) sum = 0 for i in range(1,N+1): sum+=i*(1+N//i)*(N//i)/2 print(int(sum))
1
10,931,474,917,220
null
118
118
x = int(input()) if x == 0: print(1) else: print(0)
# -*- coding: utf-8 -*- from sys import stdin input = stdin.readline def main(): n = int(input().strip()) print('1' if n == 0 else '0') if __name__ == "__main__": main()
1
2,930,909,039,138
null
76
76
import operator def poland(A): l = [] ops = { "+": operator.add, "-": operator.sub, '*' : operator.mul } for i in range(len(A)): item = A.pop(0) if item in ops: l.append(ops[item](l.pop(-2),l.pop())) else: l.append(int(item)) return l.pop() if __name__ == '__main__': A = input().split() print (poland(A[:]))
arr = list(map(str, input().split())) i = 0 operand = [] while i < len(arr): if arr[i] == '+': a = operand.pop(-1) b = operand.pop(-1) operand.append(b + a) elif arr[i] == '-': a = operand.pop(-1) b = operand.pop(-1) operand.append(b - a) elif arr[i] == '*': a = operand.pop(-1) b = operand.pop(-1) operand.append(b * a) else: operand.append(int(arr[i])) i += 1 print(operand[0])
1
36,997,729,960
null
18
18
# import math # import fractions n = int(input()) a = list(map(int, input().split())) mod = 10 ** 9 + 7 def prime_factorize(n): a = {} while n % 2 == 0: if 2 not in a: a[2] = 0 a[2] += 1 n //= 2 f = 3 while f * f <= n: if n % f == 0: if f not in a: a[f] = 0 a[f] += 1 n //= f else: f += 2 if n != 1: if n not in a: a[n] = 0 a[n] += 1 return a # 最小公倍数を素因数分解した形で持つ l = prime_factorize(a[0]) # print(l) # xs = {} # xs[a[0]] = prime_factorize(a[0]) for i in range(1, n): ps = prime_factorize(a[i]) # print(ps) # xs[a[i]] = ps for k, v in ps.items(): if k in l: l[k] = max(v, l[k]) else: l[k] = v # print(l) # print(xs) L = 1 for k, v in l.items(): L = L * pow(k, v, mod) % mod answer = 0 for x in a: answer = (answer + L * pow(x, mod - 2, mod)) % mod print(answer)
from fractions import gcd def main(): N = int(input()) A = list(map(int, input().split())) MOD = 10**9 + 7 lcm = 1 for a in A: lcm = lcm * a // gcd(lcm, a) ans = 0 for a in A: ans += lcm // a print(ans % MOD) if __name__ == "__main__": main()
1
87,526,631,385,920
null
235
235
while True: n = input() if n == "0": break print(sum([int(i) for i in n]))
while True: total = 0 x = input() if x == "0": break for c in x: total += int(c) print(total)
1
1,568,455,684,402
null
62
62
ans=[] while True: a=input() if '?' in a: break eval('ans.append(int({0}))'.format(a)) for a in ans: print(a)
a = [] while True: m,n,o = input().split() m=int(m) o=int(o) if n == "?": break if n=="+": a.append(m+o) elif n=="-": a.append(m-o) elif n=="*": a.append(m*o) elif n=="/": a.append(int(m/o)) for i in a: print(i)
1
665,918,350,750
null
47
47
N = int(input()) ct = [] for i in range(N): ct.append([int(i) for i in input().split()]) dist = 0 for a in ct: for b in ct: dist += (abs(a[0] - b[0])**2 +abs(a[1] - b[1])**2)**0.5 print(dist/N)
n=int(input()) x=[] y=[] for i in range(n): a,b=map(int,input().split()) x.append(a) y.append(b) p=1 for i in range(n): p*=i+1 def D(a,b): a=a-1 b=b-1 return ((x[a]-x[b])**2+(y[a]-y[b])**2)**(0.5) def f(x): ans=0 while x>0: ans+=x%2 x=x//2 return ans def r(x): ans=1 for i in range(x): ans*=(i+1) return ans dp=[[0]*(n+1) for _ in range(2**n)] for i in range(1,2**n): for j in range(1,n+1): for k in range(1,n+1): if (i>>(j-1))&1 and not (i>>(k-1)&1): dp[i+2**(k-1)][k]+=dp[i][j]+r((f(i)-1))*D(j,k) print(sum(dp[2**n-1])/p)
1
148,160,164,024,584
null
280
280
N, M = map(int, input().split()) route = [[] for _ in range(N)] sign = [0]*N #print(route) for i in range(M): a,b = map(int, input().split()) route[a-1].append(b-1) route[b-1].append(a-1) #print(route) marked = {0} q = [0] for i in q: for j in route[i]: if j in marked: continue q.append(j) marked.add(j) sign[j] = i+1 print('Yes') [print(i) for i in sign[1:]]
def resolve(): N, M, Q = list(map(int, input().split())) Q = [list(map(int, input().split())) for _ in range(Q)] import itertools maxpoint = 0 for seq in itertools.combinations_with_replacement(range(1, M+1), N): point = 0 for a, b, c, d in Q: if seq[b-1] - seq[a-1] == c: point += d maxpoint = max(maxpoint, point) print(maxpoint) if '__main__' == __name__: resolve()
0
null
24,020,225,002,460
145
160
#!/usr/bin/env python3 (R, C, K), *D = [[*map(int,o.split())] for o in open(0)] V = [[0] * C for _ in [None] * R] for r, c, v in D: V[r - 1][c - 1] = v dp = [[[-1] * C for _ in [None] * R] for _ in [None] * 4] dp[0][0][0] = 0 for r in range(R): for c in range(C): v = V[r][c] for i in range(4): if dp[i][r][c] > -1: if r < R - 1: dp[0][r + 1][c] = max(dp[0][r + 1][c], dp[i][r][c]) if c < C - 1: dp[i][r][c + 1] = max(dp[i][r][c + 1], dp[i][r][c]) if i < 3 and v: if r < R - 1: dp[0][r + 1][c] = max(dp[0][r + 1][c], dp[i][r][c] + v) if c < C - 1: dp[i + 1][r][c + 1] = max(dp[i + 1][r][c + 1], dp[i][r][c] + v) v = V[R - 1][C - 1] ans = dp[3][R - 1][C - 1] for i in range(3): ans = max(ans, dp[i][R - 1][C - 1] + v) print(ans)
# pypy import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines R, C, K = map(int, readline().split()) rcv = list(map(int, read().split())) rc2v = {} for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]): rc2v[(rr, cc)] = vv dp = [[0]*4 for c in range(C+1)] for r in range(1, R+1): for c in range(1, C+1): v = rc2v[(r, c)] if (r, c) in rc2v else 0 dp[c][0] = max(dp[c-1][0], max(dp[c])) dp[c][1] = max(dp[c-1][1], dp[c][0] + v) dp[c][2] = max(dp[c-1][2], dp[c-1][1] + v) dp[c][3] = max(dp[c-1][3], dp[c-1][2] + v) print(max(dp[-1]))
1
5,636,917,566,342
null
94
94
from math import factorial N = int(input()) ans = 0 for a in range(1,N): ans += (N-1) // a print(ans)
n = int(input()) ans = 0 for a in range(1,n): if n%a == 0: ans += n//a -1 else: ans += n//a print(ans)
1
2,604,446,229,840
null
73
73
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall i8 = np.int64 i4 = np.int32 def main(): stdin = open('/dev/stdin') pin = np.fromstring(stdin.read(), i8, sep=' ') N = pin[0] M = pin[1] L = pin[2] ABC = pin[3: M * 3 + 3].reshape((-1, 3)) A = ABC[:, 0] - 1 B = ABC[:, 1] - 1 C = ABC[:, 2] Q = pin[M * 3 + 3] st = (pin[M * 3 + 4: 2 * Q + M * 3 + 4] - 1).reshape((-1, 2)) s = st[:, 0] t = st[:, 1] graph = csr_matrix((C, (A, B)), shape=(N, N)) dist = np.array(floyd_warshall(graph, directed=False)) dist[dist > L + 0.5] = 0 dist[dist > 0] = 1 min_dist = np.array(floyd_warshall(dist)) min_dist[min_dist == np.inf] = 0 min_dist = (min_dist + .5).astype(int) x = min_dist[s, t] - 1 print('\n'.join(x.astype(str).tolist())) if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, M, L = map(int, readline().split()) G = [[INF] * N for _ in range(N)] for _ in range(M): a, b, c = map(int, readline().split()) G[a - 1][b - 1] = G[b - 1][a - 1] = c for i in range(N): G[i][i] = 0 Q, *ST = map(int, read().split()) for k in range(N): for i in range(N): for j in range(N): if G[i][j] > G[i][k] + G[k][j]: G[i][j] = G[i][k] + G[k][j] H = [[INF] * N for _ in range(N)] for i in range(N - 1): for j in range(i + 1, N): if G[i][j] <= L: H[i][j] = H[j][i] = 1 for i in range(N): H[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): if H[i][j] > H[i][k] + H[k][j]: H[i][j] = H[i][k] + H[k][j] ans = [0] * Q for i, (s, t) in enumerate(zip(*[iter(ST)] * 2)): s -= 1 t -= 1 if H[s][t] == INF: ans[i] = -1 else: ans[i] = H[s][t] - 1 print(*ans, sep='\n') return if __name__ == '__main__': main()
1
174,094,597,369,138
null
295
295
from collections import deque times = int(input()) stack = deque() for i in range(times): op = input().split() if op[0] == "insert": stack.appendleft(op[1]) if op[0] == "delete": if op[1] in stack: stack.remove(op[1]) if op[0] == "deleteFirst": stack.popleft() if op[0] == "deleteLast": stack.pop() print(*stack)
import sys import math input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) n = ini() a = inl() x = sum(a) // n ans = 0 for i in a: ans += (i - x) * (i - x) x = math.ceil(sum(a) / n) ans2 = 0 for i in a: ans2 += (i - x) * (i - x) print(min(ans, ans2))
0
null
32,695,597,440,030
20
213
n = int(input()) songs = [] for i in range(n): s,t = map(str,input().split()) t = int(t) songs.append([s,t]) x = input() number = 0 for i in range(n): if songs[i][0] == x: number = i + 1 #print("number: " + str(number)) ans = 0 for j in range(number,n): ans += songs[j][1] print(ans)
N = int(input()) dict = {} strings = [] for i in range(N): x = input() if x in dict.keys(): dict[x] += 1 else: dict[x] = 1 maximum = 1 for i in dict: maximum = max(maximum,dict[i]) for word in dict: if dict[word] == maximum: strings.append(word) strings.sort() for word in strings: print(word)
0
null
83,443,580,864,028
243
218
n=int(input()) ans="No" for i in range(1,10): for j in range(1,10): if n==i*j: ans="Yes" break else: continue break print(ans)
N=int(input()) S=input() while True: x='' ans='' for i in S: if (x==''): x=i continue if x!=i: #print("p:",x,i,ans) ans+=x x=i #print("a:",x,i,ans) ans+=x #print('ans:',ans) if ans==S: break else: S=ans print(len(ans))
0
null
164,589,652,768,140
287
293
e=input print(int(e())^int(e()))
import sys def solve(): input = sys.stdin.readline A = int(input()) B = int(input()) C = list(set([1, 2, 3]) - set([A, B])) print(C[0]) return 0 if __name__ == "__main__": solve()
1
111,162,306,713,028
null
254
254
S = input() print('ARC' if S[1]=='B' else 'ABC')
n,r=map(int,input().split()) inn=0 if n<10: inn=100*(10-n) print(r+inn) else: print(r)
0
null
43,628,905,190,400
153
211
# -*- coding: utf-8 -*- def merge(A, left, mid, right): global cnt n1 = mid - left n2 = right - mid L = A[left:left+n1] R = A[mid:mid+n2] L.append(float('inf')) R.append(float('inf')) i = 0 j = 0 for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 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) if __name__ == '__main__': n = int(input()) S = [int(s) for s in input().split(" ")] cnt = 0 mergeSort(S, 0, n) print(" ".join(map(str, S))) print(cnt)
from math import sqrt as r from math import floor as f X = int(input()) going = True def judge(X): for i in range(3, f(r(X)) + 1, 2): if X % i == 0: return False return True if X == 2 or X == 3: print(X) going = False elif X % 2 == 0: X += 1 while going: if judge(X): print(X) break X += 2
0
null
52,883,160,262,218
26
250
def check(i,N,Ls): count=0 for j in range(N): if (i>>j)%2==1: for k in Ls[j]: if ((i>>(k[0]-1))%2)!=k[1]: return 0 count+=1 return count N=int(input()) A_ls=[] Ls=[] for i in range(N): A=int(input()) A_ls.append(A) ls=[] for j in range(A): x,y=map(int,input().split()) ls.append((x,y)) Ls.append(ls) ans=0 for i in range(2**N): num=check(i,N,Ls) if num>ans: ans=num print(ans)
def II(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) N=II() ans=0 List=[[-1 for _ in range(N)] for _ in range(N)] for j in range(N): A=II() for i in range(A): x,y=MI() x-=1 List[j][x]=y for i in range(1<<N): honests=[0]*N for j in range(N): if 1&(i>>j): honests[j]=1 ok=True for j in range(N): if honests[j]: for k in range(N): if List[j][k]==-1: continue if List[j][k]!=honests[k]: ok=False if ok: ans=max(ans,honests.count(1)) print(ans)
1
121,221,021,603,044
null
262
262
import sys from collections import Counter n = int(input()) D = list(map(int,input().split())) if D[0] != 0 or D.count(0) != 1: print(0) sys.exit() D = Counter(D) L = sorted(D.items()) pk = 0 pv = 1 ans = 1 for i,j in L: if i == 0: continue if i != pk+1: print(0) break ans *= pv**j ans %= 998244353 pk = i pv = j else: print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) Ds = list(mapint()) if Ds[0]!=0: print(0) exit(0) Ds.sort() mod = 998244353 from collections import Counter c = Counter(Ds) dmax = Ds[-1] if c[0]>1: print(0) else: ans = 1 for i in range(1, dmax+1): ans *= pow(c[i-1], c[i], mod) ans %= mod print(ans)
1
154,813,998,233,652
null
284
284
h, w = map(int, input().split()) maze = [list(input()) for i in range(h)] dp = [[0] * w for i in range(h)] for i in range(h): for j in range(w): if i == j == 0: if maze[i][j] == "#": dp[i][j] += 1 if i == 0 and j != 0: if maze[0][j] != maze[0][j - 1]: dp[0][j] = dp[0][j - 1] + 1 else: dp[0][j] = dp[0][j - 1] if j == 0 and i != 0: if maze[i][0] != maze[i - 1][0]: dp[i][0] = dp[i - 1][0] + 1 else: dp[i][0] = dp[i - 1][0] if i != 0 and j != 0: dp[i][j] = min(dp[i - 1][j] + (1 if maze[i][j] != maze[i - 1][j] else 0), dp[i][j - 1] + (1 if maze[i][j] != maze[i][j - 1] else 0)) if i == h - 1 and j == w - 1: if maze[i][j] == "#": dp[i][j] += 1 ans = dp[h - 1][w - 1] // 2 print(ans)
import numpy as np H, W = map(int, input().split()) masu = [input() for i in range(H)] #temp = [list(input().replace("#","0").replace(".","1")) for i in range(H)] #masu = [[int(temp[i][j]) for j in range(W)] for i in range(H)] #dp = np.zeros((H, W)) dp = [[0]*W for i in range(H)] if masu[0][0] == "#": dp[0][0] = 1 for i in range(0,H): for j in range(0,W): if i == 0: a = 100000 else: if masu[i][j] == "#" and masu[i-1][j] == ".": a = dp[i-1][j] + 1 else: a = dp[i-1][j] if j == 0: b = 100000 else: if masu[i][j] == "#" and masu[i][j-1] == ".": b = dp[i][j-1] + 1 else: b = dp[i][j-1] if a != 100000 or b != 100000: dp[i][j] = min([a, b]) print(int(dp[H-1][W-1]))
1
49,149,918,178,820
null
194
194
from collections import deque # 両端を扱うならdequeが速い # 内側を扱うならリストが速い S = input() q = deque() for s in list(S): q.append(s) Q = int(input()) direction = True for _ in range(Q): line = input() # TrueならFalseに、FalseならTrueに変える if line == "1": direction = not direction else: if (direction and line[2] == '1') or (not direction and line[2] == '2'): # 左端に追加する場合 q.appendleft(line[4]) else: # 右端に追加する場合 q.append(line[4]) if direction: print("".join(q)) elif not direction: q.reverse() print("".join(q))
N, A = map(int,input().split()) print("Yes" if 500*N >= A else "No")
0
null
77,490,790,853,310
204
244
from math import * def calcAngle(h,m): # validate the input if (h < 0 or m < 0 or h > 12 or m > 60): print('Wrong input') if (h == 12): h = 0 if (m == 60): m = 0 h += 1; if(h>12): h = h-12; # Calculate the angles moved by # hour and minute hands with # reference to 12:00 hour_angle = 0.5 * (h * 60 + m) minute_angle = 6 * m # Find the difference between two angles angle = abs(hour_angle - minute_angle) # Return the smaller angle of two # possible angles angle = min(360 - angle, angle) return angle a,b,h,m=[int(i) for i in input().split()] theta=calcAngle(h,m)*pi/180 ans=(a**2+b**2-2*a*b*cos(theta))**(1/2) print("{:.15f}".format(ans))
import math A,B,H,M=map(int,input().split()) C2=A**2+B**2-2*A*B*math.cos((30*H-11*M/2)/180*math.pi) print(C2**(1/2))
1
20,047,848,287,846
null
144
144
while True: cards = raw_input() if cards == '-': break n = input() for _ in xrange(n): h = input() cards = cards[h:] + cards[:h] print cards
N = int(input()) S = input() slime = S[0] for i in range(1, N): if S[i] != slime[-1]: slime += S[i] print(len(slime))
0
null
85,869,031,425,142
66
293
def main(): X, Y, Z = map(int, input().split()) return " ".join(map(str, [Z, X, Y])) if __name__ == '__main__': print(main())
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print('\n'.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) n,a,b = readints() if (b-a)%2==0: print((b-a)//2) else: print(min(n-b+(b-a)//2+1,a-1+(b-a)//2+1))
0
null
73,397,087,360,840
178
253
from sys import stdin n = int(stdin.readline()) M = [None] M += [list(map(int, stdin.readline().split()[2:])) for i in range(n)] sndf = [None] sndf += [[False, i] for i in range(1, n + 1)] tt = 0 def dfs(u): global tt sndf[u][0] = True tt += 1 sndf[u].append(tt) for v in M[u]: if not sndf[v][0]: dfs(v) tt += 1 sndf[u].append(tt) for i in range(1, n + 1): if not sndf[i][0]: dfs(i) for x in sndf[1:]: print(*x[1:])
dp = [0 for i in range(1000000)] N = int(input()) for i in range(2,1000): if i**2>N: break if dp[i]!=0: continue for j in range(i,1000000,i): dp[j] = 1 while dp[N]!=0: N += 1 print(N)
0
null
52,634,799,665,272
8
250
x=int(input()) for m in range(1,180): if 360*m%x==0: print(360*m//x) exit(0)
import math import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def main(): X = ii() print(360//math.gcd(X,360)) if __name__ == "__main__": main()
1
13,110,268,219,390
null
125
125
n,k = map(int,input().split()) w = [] for loop in range(n): w.append(int(input())) left = max(w) right = 100000 * 10000 mid = (left+right)//2 ans = right def check(P): tmp_sum = 0 cnt = 1 for loop in range(n): if tmp_sum + w[loop] <= P: tmp_sum += w[loop] else: tmp_sum = w[loop] cnt += 1 if cnt > k: return False return True while left <= right: if check(mid): ans = mid right = mid - 1 else: left = mid + 1 mid = (left+right)//2 print(ans)
def f(w, n, k, v): # how many things in list w of length n can fill in k cars with capacity v? i = 0 space = 0 while i < n: if space >= w[i]: space -= w[i] i += 1 else: # space < w[i] if k == 0: break k -= 1 space = v return i if __name__ == '__main__': n, k = map(int, raw_input().split()) w = [] maxv = -1 for i in range(n): x = int(raw_input()) w.append(x) maxv = max(maxv, x) left = 0 right = n * maxv # range: (left, right] # loop until left + 1 = right, then right is the answer # why? because right works, but right - 1 doesn't work # so right is the smallest capacity while right - left > 1: mid = (left + right) / 2 v = f(w, n, k, mid) if v >= n: # range: (left, mid] # in fact, v cannot > n right = mid else: # range: (mid, right] left = mid print right
1
89,447,221,500
null
24
24
n=map(int,input().split()) a=list(map(int,input().split())) N=0 new_a=a[::2] for i in new_a: if i%2==0: N += 1 print(len(new_a)-N)
n = int(input()) z = input().split() odd = 0 for i in range(n): if i % 2 == 0: if int(z[i]) % 2 == 1: odd += 1 print(odd)
1
7,772,453,224,340
null
105
105
from collections import deque n = int(input()) x = input() memo = {0: 0} def solve(X): x = X stack = deque([]) while x: if x in memo: break stack.append(x) x = x % bin(x).count("1") cnt = memo[x] + 1 while stack: x = stack.pop() memo[x] = cnt cnt += 1 return cnt - 1 ans = [] px = x.count("1") memo1 = [1 % (px - 1)] if px > 1 else [] memo2 = [1 % (px + 1)] x1 = 0 x2 = 0 for i in range(n): if px > 1: memo1.append(memo1[-1] * 2 % (px-1)) memo2.append(memo2[-1] * 2 % (px+1)) for i in range(n): if x[-i-1] == '1': if px > 1: x1 += memo1[i] x1 %= (px-1) x2 += memo2[i] x1 %= (px+1) for i in range(n): if x[-i-1] == "1": if px > 1: ans.append(solve((x1-memo1[i])%(px-1)) + 1) else: ans.append(0) else: ans.append(solve((x2+memo2[i])%(px+1)) + 1) for ansi in reversed(ans): print(ansi)
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)
1
8,191,280,654,480
null
107
107
from bisect import bisect_left as lower_bound from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate import sys import bisect import string import math import time def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def ItoS(nn): return chr(nn+97) def input(): return sys.stdin.readline().rstrip() def show(*inp, end='\n'): if show_flg: print(*inp, end=end) YN = ['No', 'Yes'] MOD = 10**9+7 inf = float('inf') IINF = 10**19 l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() sys.setrecursionlimit(10**6) nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] show_flg = False # show_flg = True def main(): N = I() XL = [] ans = 0 for i in range(N): x, l = MI() XL.append((x + l, x - l)) # print(XL) XL.sort() cur = -10**19 r = 0 for i in range(N): if XL[i][1] >= cur: r += 1 cur = XL[i][0] # print(i, cur) print(r) if __name__ == '__main__': main()
n=int(input()) import heapq q=[] for i in range(n): x,l=map(int,input().split()) heapq.heappush(q,(x+l,l)) largest=-float('inf') c=0 while q: a,l=heapq.heappop(q) if largest<=a-2*l: largest=a c+=1 print(c)
1
90,213,306,946,340
null
237
237
import math import itertools n = int(input()) xy = [] for i in range(n): xy.append(list(map(int,input().split()))) total_distance = 0 list_keiro = [] for team in itertools.permutations(range(n)): list_keiro.append(team) def distance(x1,x2,y1,y2): return (math.sqrt((x1-x2)**2 + (y1-y2)**2)) for i in list_keiro: dis_tmp = 0 for j in range(n-1): dis_tmp += distance(xy[i[j]][0],xy[i[j+1]][0],xy[i[j]][1],xy[i[j+1]][1]) total_distance += dis_tmp print(total_distance / len(list_keiro))
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res 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)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n = I() a = LI() count = 0 for i in range(1,n+1): if i % 2 != 0 and a[i-1] % 2 != 0: count += 1 print(count) return if __name__ == "__main__": solve()
0
null
77,670,729,595,928
280
105
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) n=int(input()) l=[input().split() for i in range(n)] x=input() ans=0 c=False for s,t in l: if c: ans+=int(t) if x==s: c=True print(ans)
M1, D1 = [int(x) for x in input().split()] M2, D2 = [int(x) for x in input().split()] print(0 if M1 == M2 else 1)
0
null
110,462,230,327,708
243
264
S = input() Q = int(input()) reverse = False before = [] after = [] for i in range(Q): q = input().split() if len(q) == 1: reverse = not reverse else: T, F, C = q if (F == '1' and not reverse) or (F == '2' and reverse): before.append(C) else: after.append(C) if not reverse: answer = ''.join(before[::-1]) + S + ''.join(after) else: answer = ''.join(after[::-1]) + S[::-1] + ''.join(before) print(answer)
#A H,W = map(int,input().split()) G = [list(str(input())) for _ in range(H)] inf = float("inf") dist = [[inf for w in range(W)] for h in range(H)] if G[0][0] == "#": dist[0][0] = 1 else: dist[0][0] = 0 for i in range(H): for j in range(W): if i == 0 and j == 0: pass elif j == 0: dist[i][j] = dist[i-1][j] if G[i][j] == "#" and G[i-1][j] != "#": dist[i][j]+=1 elif i == 0: dist[i][j] = dist[i][j-1] if G[i][j] == "#" and G[i][j-1] != "#": dist[i][j]+=1 else: d1 = dist[i-1][j] d2 = dist[i][j-1] if G[i][j] == "#" and G[i-1][j] != "#": d1+=1 if G[i][j] == "#" and G[i][j-1] != "#": d2+=1 dist[i][j] = min(d1,d2) print(dist[H-1][W-1])
0
null
53,291,507,804,120
204
194