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
x,y=map(int,input().split()) ans=0 x=max(4-x,0) y=max(4-y,0) ans+=x*100000+y*100000 if x==3 and y==3: ans+=400000 print(ans)
X,Y = map(int,input().split()) money = [3*10**5,2*10**5,10**5] ans = 0 if X == 1 and Y == 1: ans = 2*money[0] + 4*10**5 print(ans) else: if X <= 3: ans += money[X-1] if Y <= 3: ans += money[Y-1] print(ans)
1
140,465,852,495,608
null
275
275
import collections N = int(input()) lsA = list(map(int,input().split())) cout = collections.Counter(lsA) ans = 'YES' for i in cout.values(): if i > 1: ans = 'NO' break print(ans)
N = int(input()) L = [] for i in range(N): L.append(list(input().split())) S = input() ans = 0 f = 0 for i in range(N): if f == 1: ans += int(L[i][1]) if L[i][0] == S: f = 1 print(ans)
0
null
85,183,988,019,190
222
243
n = int(input()) arr = list(map(int, input().split())) ans = 0 for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): if arr[i] != arr[j] and arr[i] != arr[k] and arr[j] != arr[k]: if (arr[i] + arr[j]) > arr[k] and (arr[i] + arr[k]) > arr[j] and (arr[j] + arr[k]) > arr[i]: ans += 1 print(ans)
x,n = map(int, input().split()) p = list(map(int, input().split())) ans = 0 for i in range(x+1): if x - i not in p: ans = x - i break elif x + i not in p: ans = x + i break print(ans)
0
null
9,551,470,501,188
91
128
n = input() minSeq = input() maxv = -float("inf") while True: try: R = input() if R - minSeq > maxv: maxv = R - minSeq if R < minSeq: minSeq = R except EOFError: break print(maxv)
from sys import exit import math import collections ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) n = ii() s,t = input().split() for i in range(len(s)): print(s[i] + t[i] ,end = "")
0
null
56,346,988,835,170
13
255
from math import * def trycut(val): ret = 0 for i in range(n): ret += ceil(a[i]/val)-1 return ret n,k=map(int,input().split()) a = [int(i) for i in input().split()] low = 0 high = 1000000000 ans =-1 while low <= high: mid = (low + high)/2 cut = trycut(mid) # ~ print("low=",low, "high=", high,"val = ",mid,"ret = ",cut) if cut <= k: high = mid-0.0000001 ans = mid else: low = mid+0.0000001 # ~ if low < high: print(low, high, "je reviens") ans = int(ans*1000000)/1000000 # ~ print(ans) print(int(ceil(ans)))
s = set() for _ in range(int(input())): s.add(input()) print(len(s))
0
null
18,381,412,710,640
99
165
a,b,c,d,e=input().split() a=int(a) b=int(b) c=int(c) d=int(d) e=int(e) if a==0: print('1') elif b==0: print('2') elif c==0: print('3') elif d==0: print('4') elif e==0: print('5')
A=list(map(int,input().rstrip().split(" "))) #print(A) B=A.index(0) print(B+1)
1
13,413,075,839,268
null
126
126
import sys def gcd(a, b): "?????§??¬?´???°????±???????" if a < b: c = a a = b b = c if b == 0: return a else: return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return g * (a // g) * (b // g) for line in sys.stdin: a, b = map(int, line.split()) print("%d %d" % (gcd(a, b), lcm(a, b)))
a,b = map(int, input().split()) if a > 9 or b > 9: print(-1) else: print(a*b)
0
null
79,053,331,500,220
5
286
str = input() for char in str: if char.islower(): print(char.upper(), end='') else: print(char.lower(), end='') print("");
from math import floor s = input() k = int(input()) if len(set(s)) == 1: print(floor(len(s) * k / 2)) exit(0) x = s[0] y = 1 ans = 0 for i in s[1:]: if i == x: y += 1 else: ans += floor(y / 2) x = i y = 1 ans += floor(y / 2) if s[0] != s[-1]: print(ans * k) else: x = s[0] y = 1 for i in s[1:]: if x == i: y += 1 else: a = y break y = 0 for i in s[::-1]: if x == i: y += 1 else: b = y break print(ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1)))
0
null
88,484,894,799,730
61
296
A,B = map(int,input().split()) print(max(0,A-B*2))
[A,B] = list(map(int,input().split())) nokori = A - B*2 if nokori>=0: print(nokori) else: print(0)
1
167,199,314,345,882
null
291
291
input_list = [] for i in range(0, 3): input_list.append(int(input())) h = input_list[0] w = input_list[1] n = input_list[2] temp_num = 0 if w <= h: temp_num = h else: temp_num = w answer = 0 if n % temp_num == 0: answer = int(n / temp_num) else: answer = (n // temp_num) + 1 print(answer)
s=list(map(int,list(input()))) if sum(s)%9==0: print('Yes') else: print('No')
0
null
46,655,832,757,170
236
87
a,b,c= list(map(int,input().split())) n = int(input()) ans = "No" for i in range(n): if b <= a: b = 2*b elif c <= b: c = 2*c if a<b<c: ans = "Yes" print(ans)
a,b,c=map(int,input().split()) k=int(input()) while k>0: if a<b: break b*=2 k-=1 while k>0: if b<c: break c*=2 k-=1 if a<b<c: print('Yes') else: print('No')
1
7,006,302,299,250
null
101
101
import sys input = sys.stdin.readline class Dice: """ 0:top, 1:south, 2:east, 3:west, 4:north, 5:bottom """ def __init__(self, surfaces): self.surface = surfaces def roll(self, direction: str): if direction == "E": self.surface = [self.surface[3], self.surface[1], self.surface[0], self.surface[5], self.surface[4], self.surface[2]] elif direction == "N": self.surface = [self.surface[1], self.surface[5], self.surface[2], self.surface[3], self.surface[0], self.surface[4]] elif direction == "S": self.surface = [self.surface[4], self.surface[0], self.surface[2], self.surface[3], self.surface[5], self.surface[1]] elif direction == "W": self.surface = [self.surface[2], self.surface[1], self.surface[5], self.surface[0], self.surface[4], self.surface[3]] return def get_top(self): return self.surface[0] def main(): surface = [int(i) for i in input().strip().split()] spins = input().strip() dice = Dice(surface) for d in spins: dice.roll(d) print(dice.get_top()) if __name__ == "__main__": main()
def rotate(dice,d): if d == "N": temp = dice[0] dice[0] = dice[1] dice[1] = dice[5] dice[5] = dice[4] dice[4] = temp elif d == "E": temp = dice[0] dice[0] = dice[3] dice[3] = dice[5] dice[5] = dice[2] dice[2] = temp elif d == "W": temp = dice[0] dice[0] = dice[2] dice[2] = dice[5] dice[5] = dice[3] dice[3] = temp elif d == "S": temp = dice[0] dice[0] = dice[4] dice[4] = dice[5] dice[5] = dice[1] dice[1] = temp return dice dice = input().split() dArr = list(input()) for i in range(len(dArr)): dice = rotate(dice,dArr[i]) print(dice[0])
1
243,531,798,656
null
33
33
import sys read = sys.stdin.read readlines = sys.stdin.readlines import numpy as np def main(): n, *a = map(int, read().split()) p = np.array(a) minp = np.minimum.accumulate(p) r = np.count_nonzero(minp >= p) print(r) if __name__ == '__main__': main()
n = int(input()) p = list(map(int,input().split())) mini = 10**9 ans =0 for i in range(n): if p[i] <= mini: mini = p[i] ans += 1 print(ans)
1
85,852,942,075,852
null
233
233
#coding:utf-8 input() data = [int(x) for x in input().split()] print(str(min(data))+" "+str(max(data)) + " "+str(sum(data)))
n=int(input()) ans=0 for x in range(1,n+1): b=n//x c=x*b ans1=(x+c)*b//2 ans+=ans1 print(ans)
0
null
5,931,078,247,570
48
118
#coding:utf-8 a,b=map(int,input().split()) print(str(a//b)+" "+str(a%b)+" "+"%.6f"%(a/b))
a=list(map(int,input().split())) string=str(a[0]//a[1])+" "+str(a[0]%a[1])+" "+str("%.10f"%(a[0]/a[1])) print(string)
1
606,795,147,712
null
45
45
import math z = raw_input() x1, y1, x2, y2 = z.split() x1 = float(x1) x2 = float(x2) y1 = float(y1) y2 = float(y2) d = math.sqrt((x2 - x1) * (x2-x1) + (y2 - y1) * (y2 - y1)) print ("%lf" %(d))
import math def main2(): n = int(input()) x = int(math.ceil(n / 1.08)) if int(x*1.08) == n: print(x) else: print(":(") if __name__ == "__main__": main2()
0
null
63,229,572,869,440
29
265
from math import ceil h = int(input()) w = int(input()) n = int(input()) print(ceil(n/max(h,w)))
X, Y, Z = [int(x) for x in input().split()] print("%d %d %d" % (Z, X, Y))
0
null
63,470,826,275,772
236
178
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() s = sorted(inplL(n)) tmp = '' ans = [] anscnt = -1 for i in range(n): if tmp == s[i]: ans[anscnt][1] += 1 else: ans.append([s[i],1]) anscnt += 1 tmp = s[i] ans.sort(key=lambda x: x[1],reverse=True) tmp = 0 ret = [] for i in range(len(ans)): if i == 0 or tmp == ans[i][1]: ret.append(''.join(ans[i][0])) tmp = ans[i][1] elif tmp != ans[i][1] : break ret.sort() for i in range(len(ret)): print(ret[i])
from functools import lru_cache @lru_cache(maxsize=None) def solve(n): if n == 1: return 1 else: return solve(n//2) * 2 + 1 H = int(input()) print(solve(H))
0
null
75,482,330,125,062
218
228
#-*-coding:utf-8-*- import sys input=sys.stdin.readline import collections def main(): bosses=[] count={} n = int(input()) bosses=list(map(int,input().split())) ans=[0]*n for i in bosses: ans[i-1]+=1 for a in ans: print(a) if __name__=="__main__": main()
# C - management n = int(input()) al = list(map(int,input().split())) s = [0]*n level = 1 al.sort() for i in range(len(al)): if al[i] == level: s[level-1] += 1 elif al[i] >= level: level = al[i] s[level-1] += 1 for j in s: print(j)
1
32,648,496,491,080
null
169
169
# # abc147 c # import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """3 1 2 1 1 1 1 1 2 0""" output = """2""" self.assertIO(input, output) def test_入力例_2(self): input = """3 2 2 1 3 0 2 3 1 1 0 2 1 1 2 0""" output = """0""" self.assertIO(input, output) def test_入力例_3(self): input = """2 1 2 0 1 1 0""" output = """1""" self.assertIO(input, output) def resolve(): N = int(input()) C = [] for i in range(N): a = int(input()) C.append([list(map(int, input().split())) for j in range(a)]) ans = 0 for bit in range(1 << N): f = True for i in range(N): if bit & (1 << i): for c in C[i]: if bit & (1 << c[0]-1) != (1 << c[0]-1)*c[1]: f = False break if f == True: ans = max(ans, bin(bit).count("1")) print(ans) if __name__ == "__main__": # unittest.main() resolve()
n = int(input()) a = [] for _ in range(n): a.append([list(map(int,input().split())) for __ in range(int(input()))]) l = [] for i in range(2**n): flag2 = 0 for j in range(n): if i >> j & 1 == 1: flag1 = 0 for k in a[j]: if i >> (k[0]-1) & 1 != k[1]: flag1 = 1 flag2 += 1 break if flag1 : break if flag2 == 0 :l.append(list(bin(i)).count('1')) print(max(l))
1
122,065,433,431,608
null
262
262
n=int(input()) B=[] for i in range(n): x,l=map(int,input().split()) B.append([x-l,x+l]) B.sort(key=lambda x:x[1]) max_l=-10**18-5 ans=0 for b in B: if max_l <= b[0]: max_l = b[1] ans+=1 print(ans)
# import time # p0 = time.time() N = int(input()) A = list(map(int,input().split())) # print(A) A = [[A[i],i] for i in range(N)] A.sort(reverse=True) # print("A :",A) dp = [[0]*(N+1) for _ in range(N+1)] # print(dp) #dp[x][y] : x人は Ai*(i-pi),y人は Ai*(pi-i) # piは 0,1,2... piはN-1,N-2,N-3,, # p1 = time.time()-p0 dp[0][0] = 0 # y = 0 for x in range(1,N+1): dp[x][0] = dp[x-1][0]+A[x-1][0]*(A[x-1][1]-x+1) # print(x,dp) # x = 0 for y in range(1,N+1): dp[0][y] = dp[0][y-1]+A[y-1][0]*(N-y - A[y-1][1]) # print(x,dp) # p2 = time.time()-p0 for x in range(1,N): for y in range(1,N+1-x): A0 = A[x+y-1][0] A1 = A[x+y-1][1] dp[x][y] = max(dp[x-1][y] + A0*(A1+1 - x), dp[x][y-1] + A0*(N-y - A1)) # print(dp) # p3 = time.time()-p0 c = 0 for i in range(N): if c < dp[i][N-i]: c = dp[i][N-i] print(c) # print(p1,p2,p3)
0
null
61,883,862,612,496
237
171
import math x1,y1,x2,y2 = tuple(float(n) for n in input().split()) D = math.sqrt((x2-x1)**2 + (y2-y1)**2) print("{:.8f}".format(D))
t = list(input()) a = 0 b = 0 for i in range(len(t)): if i == 0 and t[i] == '?': t[i] = 'D' if 0 < i < len(t) - 1 and t[i] == '?': if t[i-1] == 'P': t[i] = 'D' elif t[i+1] == 'P': t[i] = 'D' else: t[i] = 'P' if i == len(t) -1 and t[i] == '?': t[i] = 'D' print(''.join(t))
0
null
9,221,883,040,942
29
140
S=input() if S=="hi" or S=="hihi" or S=="hihihi" or S=="hihihihi" or S=="hihihihihi": print("Yes") else: print("No")
s=input() if len(s)&1: print('No') exit() for i in list(s[i*2:i*2+2] for i in range(len(s)//2)): if i!='hi': print('No') exit() print('Yes')
1
53,440,351,147,600
null
199
199
# Debt Hell n = int(input()) value = 100000 for i in xrange(n): value *= 1.05 if value % 1000 != 0: value = int(value / 1000 + 1) * 1000 print value
n=int(input()) syakkin=100000 for i in range(n): syakkin*=1.05 if syakkin%1000!=0: syakkin=syakkin-syakkin%1000+1000 print(int(syakkin))
1
1,109,382,818
null
6
6
import sys N = int(input()) p = list(map(int, input().split())) for i in range(N): if p[i] == 0: print(0) sys.exit() product = 1 for i in range(N): product = product * p[i] if product > 10 ** 18: print(-1) sys.exit() break print(product)
import math print(math.ceil(int(input())/2))
0
null
37,414,920,775,778
134
206
#セグ木 from collections import deque def f(L, R): return L|R # merge def g(old, new): return old^new # update zero = 0 #零元 class segtree: def __init__(self, N, z): self.M = 1 while self.M<N: self.M *= 2 self.dat = [z] * (self.M*2-1) self.ZERO = z def update(self, x, idx, l=0, r=-1): if r==-1: r = self.M idx += self.M-1 self.dat[idx] = g(self.dat[idx], x) while idx > 0: idx = (idx-1)//2 self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2]) def query(self, a, b=-1, idx=0, l=0, r=-1): if r==-1: r = self.M if b==-1: b = self.M q = deque([]) q.append([l, r, 0]) ret = self.ZERO while len(q): tmp = q.popleft() L = tmp[0] R = tmp[1] if R<=a or b<=L: continue elif a<=L and R<=b: ret = f(ret, self.dat[tmp[2]]) else: q.append([L, (L+R)//2, tmp[2]*2+1]) q.append([(L+R)//2, R, tmp[2]*2+2]) return ret n = int(input()) s = list(input()) q = int(input()) seg = segtree(n+1, 0) for i in range(n): num = ord(s[i]) - ord("a") seg.update((1<<num), i) for _ in range(q): a, b, c = input().split() b = int(b) - 1 if a == "1": pre = ord(s[b]) - ord("a") now = ord(c) - ord("a") seg.update((1<<pre), b) seg.update((1<<now), b) s[b] = c else: q = seg.query(b, int(c)) bin(q).count("1") print(bin(q).count("1"))
#!/usr/bin python3 # -*- coding: utf-8 -*- def main(): H, W = map(int,input().split()) sth, stw = 0, 0 glh, glw = H-1, W-1 INF = 10000 Gmap = [list(input()) for _ in range(H)] Dist = [[INF]*W for _ in range(H)] direc = {(1,0), (0,1)} if Gmap[0][0]=='#': Dist[0][0]=1 else: Dist[0][0]=0 for h in range(H): for w in range(W): nw = Gmap[h][w] for d in direc: hs, ws = h + d[0], w + d[1] if 0<=hs<H and 0<=ws<W: cr = Gmap[hs][ws] Dist[hs][ws] = min(Dist[hs][ws], Dist[h][w] + (cr=='#' and nw=='.')) print(Dist[glh][glw]) if __name__ == '__main__': main()
0
null
55,600,514,330,998
210
194
a = input() b, c, d = [int(x) for x in a.split()] x = [x for x in range(b, c + 1) if x % d == 0] print(len(x))
class Dice(object): def __init__(self, n): self.n = n def move(self, to): if to == 'N': self.n[0], self.n[1], self.n[4], self.n[5] = self.n[1], self.n[5], self.n[0], self.n[4] elif to == 'E': self.n[0], self.n[2], self.n[3], self.n[5] = self.n[3], self.n[0], self.n[5], self.n[2] elif to == 'S': self.n[0], self.n[1], self.n[4], self.n[5] = self.n[4], self.n[0], self.n[5], self.n[1] elif to == 'W': self.n[0], self.n[2], self.n[3], self.n[5] = self.n[2], self.n[5], self.n[0], self.n[3] def top(self): return self.n[0] dice = Dice([int(i) for i in input().split()]) move = input() for m in move: dice.move(m) print(dice.top())
0
null
3,939,574,093,180
104
33
A = input().split() B = sorted(A) C = map(str, B) print(' '.join(C))
x = sorted([int(i) for i in input().split()]) print("{0} {1} {2}".format(x[0],x[1],x[2]))
1
428,451,413,514
null
40
40
from math import log2 N = int(input()) log = int(log2(N)+1) ans = (2**log-1) print(ans)
from sys import stdin import sys import math from functools import reduce import functools import itertools @functools.lru_cache(None) def aa(k): if k > 1: return 2*aa(k//2) + 1 return 1 h = int(stdin.readline().rstrip()) print(aa(h))
1
79,887,686,840,598
null
228
228
N =input() flag = 0 for i in range(len(N)): if N[i] == "7": flag = 1 break if flag == 1: print("Yes") else: print("No")
A, B, K= list(map(int, input().split())) if A>= K: print(A-K, end=" ") print(B) else: print(0, end=" ") print(max(B-(K-A),0))
0
null
69,385,732,712,490
172
249
if __name__ == '__main__': N = int(input()) D = [input() for i in range(N)] for i in range(2,N): if (D[i][0] == D[i][-1]) \ and (D[i-1][0] == D[i-1][-1]) \ and (D[i-2][0] == D[i-2][-1]): print('Yes') break if i == N-1: print('No')
n = int(input()) cou = 0 ans = False for i in range(n): da, db = map(int, input().split()) if da == db: cou += 1 else: cou = 0 if cou == 3: ans = True if ans: print('Yes') else: print('No')
1
2,513,164,959,558
null
72
72
n, m = map(int, raw_input().split()) c = map(int, raw_input().split()) INF = 1000000000 t = [INF] * (n + 1) t[0] = 0 for i in range(m): for j in range(c[i], n + 1): t[j] = min([t[j], t[j - c[i]] + 1]) print(t[n])
n, m = map(int, input().split()) c = list(map(int, input().split())) dp = [float("inf")] * (n+1) dp[0] = 0 for i in range(1, n + 1): for j in range(m): if i >= c[j]: dp[i] = min(dp[i], dp[i-c[j]]+1) print(dp[n])
1
142,473,221,892
null
28
28
import math def prime(num): judge = True for i in range(2, int(math.sqrt(num)+1)): if num % i == 0: judge = False return judge n = int(input()) cnt = 0 ns=[] for i in range(n): num = int(input()) if prime(num): cnt += 1 print(cnt)
sortingThreeNum = list(map(int, input().split())) sortingThreeNum.sort() print(sortingThreeNum[0], sortingThreeNum[1], sortingThreeNum[2])
0
null
218,569,387,102
12
40
N, M, X = list(map(int, input().split())) A = [0]*N for i in range(N): A[i] = list(map(int, input().split())) min_sump = -1 for i in range(2**(N+1)): sump = 0 sume = [0]*M for j in range(N): ns = "0" + str(N) +"b" bi = format(i,ns) if bi[-1-j] == "1": sump += A[j][0] sume = list(map(sum, zip(sume, A[j][1:]))) if all([i >= X for i in sume]): if min_sump == -1: min_sump = sump else: min_sump = min(min_sump,sump) print(min_sump)
import sys N, M, X = map(int, sys.stdin.readline().split()) D = 12*100001 m = D Clst = [] for i in range(N): Ci = list(map(int, sys.stdin.readline().split())) Clst.append(Ci) for i in range(2**N): ch = True buy = [] total = 0 for j in range(N): if ((i>>j)&1): buy.append(Clst[j]) total += Clst[j][0] if total >= m: ch = False break if ch: for l in range(1,M+1): skill = 0 for k in buy: skill = skill + k[l] if skill < X: ch = False break if ch: m = total if m == D: print(-1) else: print(m)
1
22,263,174,358,448
null
149
149
N=int(input()) P=list(map(int,input().split())) m_v=N+1 ans=0 for i in range(N): m_v=min(m_v,P[i]) if m_v==P[i]: ans+=1 print(ans)
n = int(input()) a = [i for i in range(1,n+1) if (i%3==0 or "3" in list(str(i)))] print(" ",end="") print(*a,sep=" ")
0
null
43,323,650,060,560
233
52
data = raw_input() while data.count('-1') < 3: m,f,r = map(int,data.split(" ")) if m+f < 30 or m == -1 or f == -1: print 'F' elif m+f >=80: print 'A' elif m+f >= 65: print 'B' elif m+f >= 50 or (m+f >=30 and r>= 50): print 'C' elif m+f >= 30: print 'D' elif m+f <30: print 'F' data = raw_input()
import sys #fin = open("test.txt", "r") fin = sys.stdin while True: [m, f, r] = list(map(int, fin.readline().split())) if m == -1 and f == -1 and r == -1: break sum_mf = m + f if m == -1 or f == -1: print("F") elif sum_mf >= 80: print("A") elif sum_mf >= 65: print("B") elif sum_mf >= 50: print("C") elif sum_mf >= 30: if r >= 50: print("C") else: print("D") else: print("F")
1
1,207,988,779,748
null
57
57
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) inf = 10**17 mod = 10**9+7 n = int(input()) s = input() ans = 0 for i in range(n): if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C': ans += 1 print(ans)
n = int(input()) s = input() print(s.count('ABC'))
1
99,206,121,083,130
null
245
245
import sys input=sys.stdin.readline sys.setrecursionlimit(10 ** 8) from itertools import accumulate from itertools import permutations from itertools import combinations from collections import defaultdict from collections import Counter import fractions import math from collections import deque from bisect import bisect_left from bisect import bisect_right from bisect import insort_left import itertools from heapq import heapify from heapq import heappop from heapq import heappush import heapq from copy import deepcopy from decimal import Decimal alf = list("abcdefghijklmnopqrstuvwxyz") ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") #import numpy as np INF = float("inf") #d = defaultdict(int) #d = defaultdict(list) MOD = 10**9+7 N = int(input()) A = list(map(int,input().split())) L = A[0] for i in range(1,N): g = math.gcd(L,A[i]) L = L*A[i]//g ans = 0 L %= MOD for i in range(N): ans += (L*pow(A[i],MOD-2,MOD)) ans %= MOD print(ans)
N = int(input()) A = list(map(int, input().split())) MOD = 10**9 + 7 def gcd(n, m): if m == 0: return n return gcd(m, n % m) def lcm(a, b): return a * b // gcd(a, b) L = 1 for a in A: L = lcm(L, a) L %= MOD coef = 0 for a in A: coef += pow(a, MOD - 2, MOD) print((L * coef) % MOD)
1
87,768,532,685,460
null
235
235
while True: mid_score, term_score, re_score = map(int, input().split()) if mid_score == term_score == re_score == -1: break test_score = mid_score + term_score score = '' if test_score >= 80: score = 'A' elif test_score >= 65: score = 'B' elif test_score >= 50: score = 'C' elif test_score >=30: if re_score >= 50: score = 'C' else: score = 'D' else: score = 'F' if mid_score == -1 or term_score == -1: score = 'F' print(score)
if __name__ == "__main__": while True: score = [int(i) for i in input().split()] if score[0] == score[1] == score[2] == -1: break if score[0] == -1 or score[1] == -1: print ('F') else: if score[0] + score[1] >= 80: print ('A') elif score[0] + score[1] >= 65: print ('B') elif score[0] + score[1] >= 50: print ('C') elif score[0] + score[1] >= 30: if score[2] == -1: print ('D') else: if score[2] >= 50: print ('C') else: print ('D') else: print ('F')
1
1,215,091,215,650
null
57
57
def is_prime(q): q = abs(q) if q == 2: return True if q < 2 or q&1 == 0: return False return pow(2, q-1, q) == 1 if __name__ == '__main__': i = 0 N = int(input()) a = [] for j in range(N): a.append(int(input())) if(is_prime(a[j])) == True: i += 1 print(i)
def isPrimeNum(in_num): if in_num <= 1: return False elif in_num == 2: return True elif in_num % 2 == 0: return False else: if pow(2, in_num-1, in_num) == 1: return True else: return False num_len = int(input()) cnt = 0 for i in range(num_len): num = int(input()) if isPrimeNum(num)==True: cnt = cnt + 1 print(str(cnt))
1
9,818,256,228
null
12
12
S = input() ans = 0 cnt = 0 for w in S: if w == 'S': ans = max(ans,cnt) cnt = 0 else: cnt += 1 ans = max(cnt,ans) print(ans)
s = list(input()) ans = 0 a = 0 for i in range(len(s)): if s[i] == 'R': a += 1 else: a = 0 ans = max(ans,a) print(ans)
1
4,890,743,406,880
null
90
90
n = int(input()) A = list(map(int, input().split())) A.sort() l = [False]*(A[n-1] + 1) fix = [] for i in A: if l[i]: fix.append(i) l[i] = True for i in range(A[n-1]+1): if l[i]: for j in range(i*2, A[n-1]+1, i): l[j] = False for i in fix: l[i] = False ans = [i for i in range(A[n-1] + 1) if l[i]] print(len(ans))
M = 10**6 N = int(input()) A = list(map(int, input().split())) def solve(): amax = max(A)+1 memo = [0] * amax for a in A: i = 1 while i*a < amax: memo[i*a] += 1 i += 1 count = 0 for a in A: if memo[a] == 1: count += 1 return count if __name__ == "__main__": print(solve())
1
14,361,393,951,460
null
129
129
from sys import stdin def main(): #入力 readline=stdin.readline A,B=map(int,readline().split()) C=max(0,A-B*2) print(C) if __name__=="__main__": main()
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) a,b=map(str,input().split()) print(int(a*int(b)) if int(a)<=int(b) else int(b*int(a)))
0
null
125,753,580,839,040
291
232
import math while True: n=int(input()) if n==0: break s=list(map(int,input().split())) m=sum(s)/len(s) a=0 for i in range(n): a+=(s[i]-m)**2 b=math.sqrt(a/n) print('{:.5f}'.format(b))
import math n, m = map(int,input().split()) a = list(map(int,input().split())) sum = sum(a) x = 0 for i in a: if i * 4 * m >= sum: x += 1 if x >= m: print('Yes') else: print('No')
0
null
19,582,960,608,318
31
179
h,n=map(int, input().split()) a=[0]*n b=[0]*n for i in range(n): a[i],b[i]=map(int,input().split()) max_a=max(a) dp=[float("inf")]*(h+max_a+1) dp[0]=0 for i in range(h): for j in range(n): dp[i+a[j]] = min(dp[i+a[j]], dp[i]+b[j]) print(min(dp[h:]))
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)
0
null
106,837,198,023,622
229
269
a,b,c=[int(x) for x in input().split()] print('Yes' if a<b<c else 'No')
def main(): n = int(input()) s = input() if n % 2 == 0: sl = len(s) // 2 s1 = s[:sl] s2 = s[sl:] if s1 == s2: print('Yes') else: print('No') else: print('No') if __name__ == '__main__': main()
0
null
73,904,603,650,880
39
279
n = int(input()) cnt = 0 for a in range(1, n): cnt += ~-n//a print(cnt)
N,M=map(int,input().split()) ans=[] if N%2==1: for i in range(M): ans.append([i+1,N-i]) else: for i in range(M//2): ans.append([i+1,2*M-i+1]) for j in range(M-M//2): ans.append([j+M//2+1,2*M-M//2-j]) for k in ans: print(*k,sep=' ')
0
null
15,657,665,633,980
73
162
import sys sentence = sys.stdin.read().lower() alf=[chr(i) for i in range(ord('a'), ord('z')+1)] ans=dict(zip(alf, [0]*26)) for a in sentence: if a in ans: ans[a] += 1 for (key, val) in sorted(ans.items()): print(key ,":" , val)
import sys s = sys.stdin.read().lower() for i in range(ord("a"), ord("z")+1): print(chr(i), ":", s.count(chr(i)))
1
1,661,713,449,912
null
63
63
s=input() n=len(s)+1 mountain=[0,0] count=[0,0] sum=0 for i in range(n-1): if s[i]=="<": mountain[1]+=1 else: if mountain[1]>0: sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]]) count=mountain mountain=[1,0] else: mountain[0]+=1 sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]]) print(sum)
import sys input = sys.stdin.readline N, D, a = [int(x) for x in input().split()] XH = [] for _ in range(N): XH.append([int(x) for x in input().split()]) XH.sort() #####segfunc###### def segfunc(x,y): return x + y def init(init_val): #set_val for i in range(n): seg[i+num-1]=init_val[i] #built for i in range(num-2,-1,-1) : seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) def update(k,x): k += num-1 seg[k] = x while k: k = (k-1)//2 seg[k] = segfunc(seg[k*2+1],seg[k*2+2]) def query(p,q): if q<=p: return ide_ele p += num-1 q += num-2 res=ide_ele while q-p>1: if p&1 == 0: res = segfunc(res,seg[p]) if q&1 == 1: res = segfunc(res,seg[q]) q -= 1 p = p//2 q = (q-1)//2 if p == q: res = segfunc(res,seg[p]) else: res = segfunc(segfunc(res,seg[p]),seg[q]) return res #入力 n = N A = [0] * N #####単位元###### ide_ele = 0 #num:n以上の最小の2のべき乗 num =2**(n-1).bit_length() seg=[ide_ele]*2*num #init init(A) import bisect X = [] H = [] for i in XH: X.append(i[0]) H.append(i[1]) ans = 0 for i in range(N): x, h = X[i], H[i] idx_left = bisect.bisect_left(X, x - 2 * D) idx_right = i tmp = query(idx_left, idx_right) if tmp < h: h -= tmp cnt = h // a + int(h % a != 0) ans += cnt update(i, a * cnt) print(ans)
0
null
119,073,271,417,216
285
230
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) X = input() cnt_init = X.count("1") x_init = int(X, 2) a = x_init % (cnt_init + 1) if cnt_init - 1 != 0: b = x_init % (cnt_init - 1) for i in range(n): if X[i] == "0": cnt = cnt_init + 1 x = (a + pow(2, (n - i - 1), cnt)) % cnt res = 1 else: cnt = cnt_init - 1 if cnt != 0: x = (b - pow(2, (n - i - 1), cnt)) % cnt res = 1 else: x = 0 res = 0 while x: cnt = bin(x).count("1") x %= cnt res += 1 print(res) if __name__ == '__main__': resolve()
N,K= list(map(int, input().split())) Ps = list(map(int, input().split())) ruisekiwa = [0] for P in Ps: ruisekiwa.append(P + ruisekiwa[-1]) #print(ruisekiwa) ans = 0 for i in range(N-K+1): ans = max(ans, (ruisekiwa[i+K] - ruisekiwa[i] + K) / 2) # print(ans) print(ans)
0
null
41,746,690,589,600
107
223
n = int(input()) alphabet = [chr(i) for i in range(97, 97+26)] ans = "" i = 0 # 次26**iを引いたらマイナスになるよ、というところで抜ける while n - 26**i >= 0: n -= 26**i i += 1 # ここを抜けた時,iは桁数、nは「i桁の中でn番目」を表す # したからk番目は、26**kで割った余り(に対応するアルファベット) # 「上の桁で表現しきれなかった数」=「その桁での表現」 # これ、10進法をn進法に変換するアルゴリズムの正当性の説明を適用するとしっかりわかるわ! for _ in range(i): q,r = divmod(n,26) n = q ans += alphabet[r] print(ans[::-1])
def resolve(): N = int(input()) ans = "" while N > 0: rem = N % 26 rem = 25 if rem == 0 else rem - 1 ans = chr(ord("a")+rem) + ans N = (N-1) // 26 print(ans) if '__main__' == __name__: resolve()
1
11,958,228,885,900
null
121
121
n=int(input()) s=list() for i in range(n): s.append(input()) import collections c=collections.Counter(s) l=list() max_=0 for cc in c.values(): max_=max(cc, max_) for ca,cb in c.items(): if max_==cb: l.append(ca) l.sort() for ll in l: print(ll)
from collections import Counter def main(): n = int(input()) s = (input() for i in range(n)) d = Counter(s) num = d.most_common(1)[0][1] ans = sorted(j[0] for j in d.items() if j[1] == num) for i in ans: print(i) main()
1
69,973,567,540,670
null
218
218
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): S = input() T = input() #TがSの部分文字列になるようにSを書き換える N = len(S) M = len(T) L = N - M #Sを調べるループの回数 #二重ループが許される ans = M for i in range(L+1): #最大M個一致していない。 cnt = M for j in range(M): if S[i+j] == T[j]: cnt -= 1 #最小を取る ans = min(ans, cnt) print(ans) if __name__ == '__main__': main()
n,m=map(int,input().split()) for i in range(m): print(i+1,n-i-((i>=m/2)&~n))
0
null
16,114,603,034,082
82
162
def is_prime(x): if x == 1: return False l = x ** 0.5 n = 2 while n <= l: if x % n == 0: return False n += 1 return True import sys def solve(): file_input = sys.stdin N = file_input.readline() cnt = 0 for l in file_input: x = int(l) if is_prime(x): cnt += 1 print(cnt) solve()
import math #n個からr個とるときの組み合わせの数 def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) S = int(input()) ans = 0 mod = 10 ** 9 + 7 for i in range(1,S // 3 + 1): #長さiの数列のとき x = S - 3 * i #3を分配後の余り ans += (combinations_count(x + i - 1, i - 1)) % mod #重複組み合わせを足す ans %= mod print(ans)
0
null
1,631,256,695,460
12
79
N = int(input()) A = [0 for _ in range(N)] B = [0 for _ in range(N)] for i in range(N): a,b = map(int,input().split()) A[i] = a B[i] = b A_sort = sorted(A) B_sort = sorted(B) if N % 2 == 1: print(B_sort[N//2] - A_sort[N//2] + 1) else: med_A = (A_sort[N//2] + A_sort[N//2 - 1]) med_B = (B_sort[N//2] + B_sort[N//2 - 1]) print(med_B - med_A + 1)
n=input().split() x=int(n[0]) y=int(n[1]) if 1<=x<1000000000 and 1<=y<=1000000000: if x>y: while y!=0: t=y y=x%t x=t print(x) else: while x!=0: t=x x=y%t y=t print(y)
0
null
8,697,732,630,048
137
11
import math n=int(input()) print((n-math.floor(n/2))/n)
#A import math n = int(input()) print((math.ceil(n / 2)) / n)
1
176,956,910,485,120
null
297
297
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, k = map(int, input().split()) friends = UnionFind(n) direct_friends = [0] * n enemies = [[] for _ in range(n)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 direct_friends[a] += 1 direct_friends[b] += 1 friends.union(a, b) for i in range(k): c, d = map(int, input().split()) c -= 1 d -= 1 enemies[c].append(d) enemies[d].append(c) ans = [] for i in range(n): num = friends.size(i) - 1 - direct_friends[i] for enm in enemies[i]: if friends.same(i, enm): num -= 1 ans.append(num) print(*ans)
import sys ris=lambda:map(int,next(sys.stdin).split()) N,M,K=ris() adj=[set() for _ in range(N)] for _ in range(M): A,B=ris() A,B=A-1,B-1 adj[A].add(B) adj[B].add(A) colors=[-1]*N ct={} color=-1 for u in range(N): if colors[u]!=-1: continue color+=1 colors[u]=color stk=[u] while stk: u=stk.pop() ct[color]=ct.get(color,0)+1 for v in adj[u]: if colors[v]==-1: colors[v]=color stk.append(v) blk=[{*()} for _ in range(N)] for _ in range(K): A,B=ris() A,B=A-1,B-1 if colors[A]==colors[B]: blk[A].add(B) blk[B].add(A) ans=[0]*N for u in range(N): c=colors[u] g=len(adj[u]) b=len(blk[u]) k=ct[c]-1-g-b ans[u]=k print(*ans)
1
61,611,788,792,992
null
209
209
a, b = map(int, input().split()) for i in range(max(a, b)): print(str(min(a, b)), end="")
# ABC155E s = input() d0 = [0,1,2,3,4,5,6,7,8,9] d1 = [0,1,2,3,4,5,5,4,3,2] # 通常時 a0 = d1[int(s[0])] a1 = d1[int(s[0]) + 1] if int(s[0])<=8 else 1 for c in s[1:]: c = int(c) b0 = min(a0 + c, a1 + (10 - c)) b1 = min(a0 + c + 1, a1 + (9 - c)) if c <=8 else a1 a0, a1 = b0, b1 print(a0)
0
null
77,472,946,538,328
232
219
n = int(input()) print(int(n/2+0.9))
N = int(input().rstrip()) r = (N + 1) / 2 print(int(r))
1
59,061,810,286,448
null
206
206
def zeroTrim(s): while s[0] == '0': if len(s) == 1: break s = s[1:] return s N = input() K = int(input()) def calc(N, K): digit = len(N) res = 0 if K == 1: if digit > 1: res += (digit - 1) * 9 res += int(N[0]) elif K == 2: if digit <= 1: return 0 if digit > 2: res += 9 * 9 * (digit - 1) * (digit - 2) // 2 for i in range(int(N[0])-1): res += calc('9'*(digit-1), 1) res += calc(zeroTrim(N[1:]), 1) else: if digit <= 2: return 0 if digit > 3: res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6 for i in range(int(N[0])-1): res += calc('9'*(digit-1), 2) res += calc(zeroTrim(N[1:]), 2) return res print(calc(N, K))
S = input() N = len(S) K = int(input()) dp = [[[0 for _ in range(5)] for _ in range(2)] for _ in range(N+1)] dp[0][0][0] = 1 """ 遷移 dp[i][1][j] -> dp[i+1][1][j] : i-1桁目までに0以外の数字がj個あり、i桁目に0を入れた dp[i][1][j] -> dp[i+1][1][j+1] : i-1桁目までに0以外の数字がj個あり、i桁目に0以外を入れた dp[i][0][j] -> dp[i+1][1][j] : i-1桁目がSと一致していて、i-1桁目までに0以外の数字がj個あり、までに0以外の数字がj個あり、i桁目に0を入れた dp[i][0][j] -> dp[i+1][1][j] : i-1桁目がSと一致していて、i-1桁目までに0以外の数字がj個あり、までに0以外の数字がj個あり、i桁目に0以外を入れた dp[i][0][j] -> dp[i+1][0][j+?] : i桁目までSと一致。i桁目が0以外なら、?=1 """ for i in range(N): for k in range(4): for j in range(10): if j == 0: # i桁目に0をあてた dp[i+1][1][k] += dp[i][1][k] else: # i桁目に0以外をあてた dp[i+1][1][k+1] += dp[i][1][k] if j < int(S[i]): if j == 0: dp[i+1][1][k] += dp[i][0][k] else: dp[i+1][1][k+1] += dp[i][0][k] elif j == int(S[i]): if j == 0: dp[i+1][0][k] += dp[i][0][k] else: dp[i+1][0][k+1] += dp[i][0][k] print(dp[-1][0][K] + dp[-1][1][K])
1
76,028,800,272,192
null
224
224
import sys N,K = map(int,input().split()) array = [ a for a in range(1,N+1) ] for I in range(K): _ = input() sweets = list(map(int,input().split())) for K in sweets: if K in array: array.remove(K) print(len(array))
N, K = map(int,input().split()) a = [] n = 1 while n <= N: a = a + [n] n += 1 for i in range(K): d = int(input()) A = list(map(int,input().split())) for j in range(d): if A[j] in a: a.remove(A[j]) ans = len(a) print(ans)
1
24,692,953,458,800
null
154
154
h,w=map(int,input().split()) if h==1 or w==1: print(1) exit() w-=1 even=int(w/2)+1 odd=int((w+1)/2) if h%2==0: print( (even+odd)*h//2 ) else: print( (even+odd)*(h-1)//2 + even )
H,W=map(int,input().split()) ans=0 if H==1 or W==1: ans=1 else: if H%2==0: ans=H*W//2 else: if W%2!=0: ans = H*(W-1)//2+(H//2+1) else: ans=H*W//2 print(ans)
1
50,998,408,463,708
null
196
196
import numpy as np N = int(input()) A = [] B = [] for i in range(N): a, b = [int(x) for x in input().split()] A.append(a) B.append(b) C = np.array(A) D = np.array(B) m_inf = np.median(C) m_sup = np.median(D) if N % 2 == 0: ans = 2 * m_sup - 2 * m_inf + 1 else: ans = m_sup - m_inf + 1 print(int(ans))
from statistics import median N = int(input()) A = [] B = [] for n in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) #AB = sorted(AB, key=lambda x: x[0]) #print(AB) cenA = median(A) cenB = median(B) if N % 2 == 1: print(int(cenB - cenA + 1)) elif N % 2 == 0: print(int((cenB - cenA)*2 + 1)) else: print('RE')
1
17,248,003,033,628
null
137
137
import queue h,w=map(int,input().split()) s=[] for _ in range(h): s.append(input()) ans=0 for i in range(h): for j in range(w): if s[i][j]==".": seen=[[0 for _ in range(w)] for _ in range(h)] length=[[0 for _ in range(w)] for _ in range(h)] q=queue.Queue() q.put([i,j]) seen[i][j]=1 while not q.empty(): ci,cj=q.get() for ni,nj in [[ci-1,cj],[ci+1,cj],[ci,cj-1],[ci,cj+1]]: if 0<=ni<h and 0<=nj<w and s[ni][nj]=="." and seen[ni][nj]==0: q.put([ni,nj]) length[ni][nj]=length[ci][cj]+1 seen[ni][nj]=1 ans=max(ans,length[ci][cj]) print(ans)
from collections import deque H, W = map(int, input().split()) L = [] for _ in range(H): s = input() a = [] for i in range(len(s)): a.append(s[i]) L.append(a) dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] def bfs(x, y): dp = [[10000000] * W for _ in range(H)] dp[y][x] = 0 if L[y][x] == '#': return dp else: d = deque() d.append([x, y]) while len(d) > 0: s = d.popleft() for i in range(4): if (s[1] + dy[i] >= 0 and s[1] + dy[i] < H and s[0] + dx[i] >= 0 and s[0] + dx[i] < W): if L[s[1] + dy[i]][s[0] + dx[i]] == '.' and dp[s[1] + dy[i]][s[0] + dx[i]] == 10000000: d.append([s[0] + dx[i], s[1] + dy[i]]) dp[s[1] + dy[i]][s[0] + dx[i]] = dp[s[1]][s[0]] + 1 return dp max_num = 0 for i in range(H): for j in range(W): dp = bfs(j, i) for k in dp: for p in k: if (p == 10000000): continue max_num = max(max_num, p) print(max_num)
1
94,514,634,900,532
null
241
241
#!/usr/bin/python3 # -*- coding: utf-8 -*- n, k, c = map(int, input().split()) S = [1 if a == "o" else 0 for a in input()] count = 0 X = [0] * n Y = [0] * n i = 0 while i < n: if S[i]: count += 1 X[i] = 1 i += c + 1 else: i += 1 if count > k: exit() i = n - 1 while i >= 0: if S[i]: Y[i] = 1 i -= c + 1 else: i -= 1 for i in range(0, n): if X[i] and Y[i]: print(i + 1)
mountain = [] for _ in range(10): mountain.append(int(input())) mountain.sort() mountain.reverse() print(mountain[0]) print(mountain[1]) print(mountain[2])
0
null
20,306,204,025,720
182
2
import bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) N =I() _P= LI() #AB = [LI() for _ in range(N)] #A,B = zip(*AB) P = np.array(_P) #C = np.zeros(N + 1) def main(): # count = 1 # # if (len(P)==1): # # return count # min_array =[P[0]] # for i in range(1,N): # if (P[i]<=min_array[i-1]): # count += 1 # if P[i-1]>P[i]: # min_array.append(P[i]) # else: # min_array.append(P[i-1]) # return count # print(min_array) Q = np.minimum.accumulate(P) count = np.count_nonzero(P <= Q) return count print(main()) # if ans: # print('Yes') # else: # print('No')
N = int(input()) P = list(map(int, input().split())) mi = 202020 ans = 0 for p in P: if p < mi: ans += 1 mi = p print(ans)
1
85,324,620,803,308
null
233
233
x1, y1, x2, y2 = map(float,input().split()) r = ((x1-x2)**2+(y1-y2)**2)**.5 print("{:.8f}".format(r))
N, M = map(int, input().split()) print(max(-1, N-sum(map(int, input().split()))))
0
null
16,132,882,687,390
29
168
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() M=65 A=LI() cnt=[0]*M for i in range(N): a=A[i] for j in range(M): if a>>j & 1: cnt[j]+=1 ans=0 for i in range(M): a=cnt[i] b=N-a ans=(ans + a*b*pow(2,i,mod))%mod print(ans) main()
L = int(input()) L = L/3 V=1 for i in range (3): V*=L print (V)
0
null
84,607,313,894,978
263
191
n = int(input()) ans = "" while n: n -= 1 ans += chr(ord('a') + (n % 26)) n //= 26 print(ans[::-1])
def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) for i in range(N-K): if A[i] < A[K+i]: print("Yes") else: print("No") if __name__ == "__main__": main()
0
null
9,473,610,687,270
121
102
n = int(input()) ans = "" k = 0 while n // (26**(k)) > 0: ans = ans + str(chr(((n-1) % (26**(k+1))+1)//(26**k) + 96)) n = n - ((n-1) % (26**(k+1))+1) k += 1 print(ans[::-1])
N = int(input()) # 26進数に変換する問題 ans = "" alphabet = "Xabcdefghijklmnopqrstuvwxyz" while N > 0: mod = N % 26 if mod == 0: mod = 26 ans = alphabet[mod] + ans N -= mod N //= 26 print(ans)
1
11,833,978,168,038
null
121
121
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, t = map(int, input().split()) AB = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0]) res = 0 dp = [[0] * (t + 1) for _ in range(n + 1)] for i in range(1, n + 1): a, b = AB[i - 1] for j in range(1, t + 1): if j - a >= 0: dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a] + b) else: dp[i][j] = max(dp[i - 1][j], dp[i][j]) now = dp[i - 1][t - 1] + b res = max(res, now) print(res) if __name__ == '__main__': resolve()
import sys input = sys.stdin.readline n, u, v = [int(x) for x in input().split()] import heapq def dijkstra_heap(s): #始点sから各頂点への最短距離 d = [float("inf")] * n used = [True] * n #True:未確定 d[s] = 0 used[s] = False edgelist = [] for e in edge[s]: heapq.heappush(edgelist,e) while len(edgelist): minedge = heapq.heappop(edgelist) #まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge[1]]: continue v = minedge[1] d[v] = minedge[0] used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist,[e[0]+d[v],e[1]]) return d ################################ n, w = n, n - 1 #n:頂点数 w:辺の数 edge = [[] for i in range(n)] #edge[i] : iから出る道の[重み,行先]の配列 for i in range(w): x,y = map(int,input().split()) z = 1 edge[x - 1].append([z,y - 1]) edge[y - 1].append([z,x - 1]) takahashi = dijkstra_heap(u - 1) aoki = dijkstra_heap(v - 1) ans = -1 for i, j in zip(takahashi, aoki): if j - i > 0: ans = max(ans, j - 1) print(ans)
0
null
134,488,667,196,884
282
259
d = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for i in range(d)] t = [int(input()) for i in range(d)] ans = 0 l = [0 for i in range(26)] for i in range(d): ans += s[i][t[i] - 1] l = list(map(lambda x:x+1, l)) l[t[i] - 1] = 0 for j in range(26): ans -= c[j] * l[j] print(ans)
D=int(input()) c=[int(x) for x in input().split()] s=[[0]*i for i in range(D)] t=[] last_d=[0]*26 for i in range(D): s[i]=[int(x) for x in input().split()] for i in range(D): t.append(int(input())) v=0 for i in range(D): a=0 for j in range(26): if j!=t[i]-1: n=i+1-last_d[j] a+=c[j]*n v=v+s[i][t[i]-1]-a print(v) last_d[t[i]-1]=i+1
1
9,908,601,139,470
null
114
114
def show_list(a): for x in a: print x, print def stable_check(sorted_values,sorted_suits,default_values,default_suits,n): for i in xrange(1,10): check_ss = [] check_ds = [] if i in sorted_values: for x in xrange(n): if i == sorted_values[x]: check_ss.append(sorted_suits[x]) if i == default_values[x]: check_ds.append(default_suits[x]) for x in xrange(len(check_ss)): if check_ss[x]!=check_ds[x]: return "Not stable" return "Stable" def bubble_sort(values,suits,n): flag = True while flag: flag = False for j in reversed(xrange(1,n)): if values[j] < values[j-1]: tmp = values[j] values[j] = values[j-1] values[j-1] = tmp tmp = suits[j] suits[j] = suits[j-1] suits[j-1] = tmp flag = True show_list(marge_suits_values(values,suits,n)) def selection_sort(values,suits,n): for i in xrange(n): minj = i for j in xrange(i,n): if values[j]<values[minj]: minj = j if minj!=i: tmp = values[i] values[i]=values[minj] values[minj]=tmp tmp = suits[i] suits[i]=suits[minj] suits[minj]=tmp show_list(marge_suits_values(values,suits,n)) def marge_suits_values(values,suits,n): ans = [] for x in xrange(n): ans.append(suits[x]+str(values[x])) return ans def main(): n = input() a = raw_input().split() suits1 = [] values1 =[] for x in xrange(n): suits1.append(a[x][0]) values1.append(int(a[x][1])) suits2 = list(suits1) values2 = list(values1) bubble_sort(values1,suits1,n) print stable_check(values1,suits1,values2,suits2,n) values1 = list(values2) suits1 = list(suits2) selection_sort(values2,suits2,n) print stable_check(values2,suits2,values1,suits1,n) if __name__ == '__main__': main()
from collections import deque S=deque(input()) Q=int(input()) ans=0 for i in range(Q): q=input() if q[0]=='2': if ans%2==0: if q[2]=='1': S.appendleft(q[4]) else: S.append(q[4]) else: if q[2]=='1': S.append(q[4]) else: S.appendleft(q[4]) else: ans+=1 S="".join(S) print(S if ans%2==0 else S[::-1])
0
null
28,532,427,312,292
16
204
import sys n = int(input()) command = sys.stdin.readlines() Q = {} for i in range(n): a,b = command[i].split() if a == "insert": Q[b] = 0 else: if b in Q.keys(): print("yes") else: print("no")
def insertion_sort(seq): print(' '.join(map(str, seq))) for i in range(1, len(seq)): key = seq[i] j = i - 1 while j >= 0 and seq[j] > key: seq[j+1] = seq[j] j -= 1 seq[j+1] = key print(' '.join(map(str, seq))) return seq n = int(input()) seq = list(map(int, input().split())) insertion_sort(seq)
0
null
43,060,681,716
23
10
S = input() k = len(S) if k%2==1: print("No") exit() frag = True for i in range(0,k,2): if S[i]+S[i+1]!="hi": frag = False if frag: print("Yes") else: print("No")
S=input().replace("hi","") print("Yes" if S=="" else "No")
1
53,429,715,041,312
null
199
199
n=input() n=int(n) s="" for i in range(1,n+1): if i%3==0: s+=" "+str(i) elif "3" in list(str(i)): s+=" "+str(i) print(s)
n, m, k = [int(i) for i in input().split()] subsets = [] splits = [i for i in range(1, n)] n -= 1 for i in range(2**n): x = [] for j in range(n): if i&(1<<j): x.append(j) subsets.append(x) n+=1 A = [] for i in range(n): A.append([int(j) for j in input()]) ans = n*m for subset in subsets: cur_ans = len(subset) tmp = [] col = 0 subset.append(100000) running_sum = [0 for i in range(len(subset))] while col<m: row_ptr = 0 for row in range(n): if row > subset[row_ptr]: row_ptr += 1 running_sum[row_ptr] += A[row][col] if running_sum[row_ptr] > k: col -= 1 running_sum = [0 for i in range(len(subset))] cur_ans += 1 break col += 1 if cur_ans >= ans: break ans = min(ans, cur_ans) print(ans)
0
null
24,656,386,384,068
52
193
N, M = map(int, input().split()) S = input() p = N prev = N flag = True ans = [] for i in range(N, -1, -1): if (prev - i) > M: ans.append(prev - p) prev = p if (prev - i) > M: flag = False break if S[i] == "0": p = i ans.append(prev) if flag: print(" ".join(map(str, ans[::-1]))) else: print(-1)
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() class SWAG(object): def __init__(self,dot): self.__front=[]; self.__back=[]; self.__dot=dot def __bool__(self): return bool(self.__front or self.__back) def __len__(self): return len(self.__front)+len(self.__back) def append(self,x): back=self.__back if(not back): back.append((x,x)) else: back.append((x,self.__dot(back[-1][1],x))) def popleft(self): assert(self) front=self.__front; back=self.__back if(not front): front.append((back[-1][0],back[-1][0])) back.pop() while(back): front.append((back[-1][0],self.__dot(back[-1][0],front[-1][1]))) back.pop() return front.pop()[0] def sum(self): assert(self) front=self.__front; back=self.__back if(not front): return back[-1][1] elif(not back): return front[-1][1] else: return self.__dot(front[-1][1],back[-1][1]) def resolve(): n,m=map(int,input().split()) S=list(map(int,input())) dp=[INF]*(n+1) # dp[i] : i から何手でゴールできるか dp[-1]=0 swag=SWAG(min) for i in range(n-1,-1,-1): swag.append(dp[i+1]) if(len(swag)>m): swag.popleft() if(S[i]==1): continue dp[i]=swag.sum()+1 if(dp[0]==INF): print(-1) return ans=[] now=0 turn=dp[0] for i in range(1,n+1): if(dp[i]==INF): continue if(turn>dp[i]): ans.append(i-now) now=i turn=dp[i] print(*ans) resolve()
1
139,187,948,530,290
null
274
274
import itertools # import math # import sys # import numpy as np # K = int(input()) # S = input() # n, *a = map(int, open(0)) N, M, Q = map(int, input().split()) # A = list(map(int, input().split())) # Q = list(map(int, input().split())) # S = input() # d = sorted(d.items(), key=lambda x:x[0]) # keyでsort conditions = [] for i in range(Q): conditions.append(list(map(int, input().split()))) # all_cases = list(itertools.permutations(P)) a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N)) # print(a[0][0]) # print(conditions[0]) max_score = 0 for t in a: tot = 0 for condition in conditions: if t[condition[1] - 1] - t[condition[0] - 1] == condition[2]: tot += condition[3] if tot > max_score: max_score = tot print(max_score)
from itertools import combinations_with_replacement as comb_rplc N,M,Q = map(int,input().split()) array = [ list(map(int,input().split())) for _ in range(Q) ] ans = 0 for seq in comb_rplc(range(1, M + 1), N): score = 0 for a,b,c,d in array: if seq[b-1] - seq [a-1] == c: score += d ans = max(score,ans) print(ans)
1
27,603,101,560,772
null
160
160
a=input() if(a=="RSS")|(a=="SRS")|(a=="SSR")|(a=="RSR"): print(1) elif(a=="SRR")|(a=="RRS"): print(2) elif(a=="RRR"): print(3) else: print(0)
n = input() ans = 0 temp = 0 for i in range(len(n)): if n[i] == "R": temp += 1 ans = max(temp,ans) else: temp = 0 print(ans)
1
4,956,374,909,440
null
90
90
tem = int(input()) if tem >= 30: print("Yes") else: print("No")
N = int(input()) primes = {} for num in range(2, int(N**0.5)+1): while N%num == 0: if num in primes: primes[num] += 1 else: primes[num] = 1 N //= num ans = 0 for p in primes.values(): n = 1 while n*(n+1)//2 <= p: n += 1 ans += n-1 if N > 1: ans += 1 print(ans)
0
null
11,303,522,518,028
95
136
import math k = int(input()) ans = 0 for q in range(1,k+1): for r in range(1,k+1): x = math.gcd(q,r) for s in range(1,k+1): ans += math.gcd(x,s) print(ans)
l=[1,9,30,76,141,267,400,624,885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,1691292,1726717,1782111,1827492,1887772,1925853,1986837,2033674,2089776,2145333,2197483,2246640,2332104,2379085,2434833,2490534,2554600,2609625,2693919,2742052,2813988,2875245,2952085,3003306,3096024,3157249,3224511,3306240,3388576,3444609,3533637,3591322,3693924,3767085,3842623,3912324,4027884,4102093,4181949,4270422,4361548,4427853,4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692] print(l[int(input())-1])
1
35,594,147,273,740
null
174
174
#!/usr/bin/env python3 import sys def solve(N: int, A: "List[int]"): if N == 0: if A == [0]: print('0') elif A == [1]: print('1') else: print('-1') return if N == 1: if A == [0, 1]: print('2') elif A == [0, 2]: print('3') else: print('-1') return if A[0] != 0: print('-1') return f = [0 for i in range(N)] f[0] = 1 count = sum(A) - 1 for d in range(1, N): f[d] = 2 * min(f[d - 1], count) - A[d] + min(max(f[d - 1] - count, 0), f[d - 1]) count -= min(f[d - 1], count) if f[d] <= 0: print('-1') return if A[-1] > 2 * f[N-1]: print('-1') return print(sum(f) + sum(A)) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N - 0 + 1)] # type: "List[int]" solve(N, A) if __name__ == '__main__': main()
def ABC_154_A(): S,T = map(str, input().split()) A,B = map(int, input().split()) U = input() if U == S: print(str(A-1)+' '+str(B)) else: print(str(A)+' '+str(B-1)) if __name__ == '__main__': ABC_154_A()
0
null
45,440,535,792,968
141
220
N = int(input()) A = [] xy = [] for i in range(N): a = int(input()) A.append(a) xy.append([list(map(int, input().split())) for j in range(a)]) ans = 0 p = [-1]*N def dfs(i, p): global ans if i == N: ans = max(ans, sum(p)) else: p_true = p.copy() if p_true[i] != 0: p_true[i] = 1 ok = True for x, y in xy[i]: if y == p_true[x-1] or p_true[x-1] == -1: p_true[x-1] = y else: ok = False if ok: dfs(i+1, p_true) p_false = p.copy() if p_false[i] != 1: p_false[i] = 0 dfs(i+1, p_false) dfs(0, p) print(ans)
#!/usr/bin/env python3 def main(): import numpy as np N = int(input()) testimony = np.zeros((N, N), dtype=np.int64) for i in range(N): A = int(input()) INF = 10 ** 10 for _ in range(A): x, y = map(int, input().split()) testimony[i, x - 1] += 1 if y else -INF # 正直者のパターンをbit全探索 ans = 0 for bit in range(1 << N): honest = set() pick = np.zeros(N, dtype=np.int64) for i in range(N): if bit & (1 << i): honest.add(i) pick += testimony[i, :] flag = True for j in range(N): value = pick[j] # 下記3つの内1つでも満たしたら,仮定が間違っていると分かる. if (0 or (j in honest and value < 0) # 正直者なのに嘘つきと言われる or (j not in honest and value > 0) # 嘘つきなのに正直者と言われる or (value < 0 and value % INF != 0)): # 正直とも嘘つきとも言われる flag = False break if flag: ans = max(ans, len(honest)) print(ans) if __name__ == '__main__': main()
1
121,299,778,704,348
null
262
262
N=int(input()) A=list(map(int,input().split())) M=1 if 0 in A: print('0') else: for i in range(len(A)): M*=A[i] if M > 10**18: break if M > 10**18: print('-1') else: print(int(M))
N = int(input()) alist = list(map(int, input().split())) k = 1 if 0 in alist: print(0) else: for i in range(0,N): k = k*alist[i] if k > 1000000000000000000: k= -1 break print(k)
1
16,156,542,382,090
null
134
134
Ss, Ts = input().split() A, B = map(int, input().split()) Us = input().rstrip() if Ss == Us: A -= 1 elif Ts == Us: B -= 1 print(A, B)
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() ans = 0 if n % 2 == 1: ans = 0 else: div = 10 while div <= n: ans += n // div div *= 5 print(ans)
0
null
93,817,987,528,668
220
258
import itertools n = int(input()) town = [list(map(int, input().split())) for _ in range(n)] x = 1 for i in range(1, n+1): x *= i l = [] for j in range(n): l.append(j) ans = 0 for a in itertools.permutations(l, n): newl = a length = 0 for b in range(n-1): length += ((town[newl[b]][0] - town[newl[b+1]][0])**2 + (town[newl[b]][1] - town[newl[b+1]][1])**2)**(1/2) ans += length print(ans/x)
N = int(input()) x = [0]*N y = [0]*N dist = [[0]*N]*N ans = 0 for i in range(N): x[i],y[i]=map(int, input().split()) for i in range(N): for j in range(N): dist[i][j]=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5 ans += dist[i][j] print(ans/N)
1
148,599,769,718,080
null
280
280
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)
import sys sys.setrecursionlimit(1000000000) from itertools import count from functools import lru_cache from collections import defaultdict ii = lambda: int(input()) mis = lambda: map(int, input().split()) lmis = lambda: list(mis()) INF = float('inf') def meg(f, ok, ng): while abs(ok-ng)>1: mid = (ok+ng)//2 if f(mid): ok=mid else: ng=mid return ok # def main(): T1,T2 = mis() A1,A2 = mis() B1,B2 = mis() d1 = T1*A1 - T1*B1 d2 = T2*A2 - T2*B2 if d1 + d2 == 0: print('infinity') elif d1 < 0 > d2 or d1 > 0 < d2: print(0) else: if d1 < 0: d1 *= -1 d2 *= -1 if d1 + d2 > 0: print(0) elif d1 % (d1+d2) == 0: print(d1 // abs(d1+d2) * 2) else: print(d1 // abs(d1+d2) * 2 + 1) main()
1
131,453,075,709,560
null
269
269
#!/usr/bin/env python letters = [] for i in range(26): letters.append(chr(i + 97) + " : ") contents = [] while True: try: text = input() except EOFError: break contents.append(text) #65-90 uppercase #97-122lowercase i = 0 for y in letters: value = 0 for text in contents: for x in text: if x.isupper(): x = x.lower() if x in y: value += 1 elif x.islower(): if x in y: value += 1 letters[i] = letters[i] + str(value) i += 1 for x in letters: print(x)
import sys s = sys.stdin.read() s = s.lower() c = 97 while chr(c-1)!='z': print('{0} : {1}'.format(chr(c),s.count(chr(c)))) c += 1
1
1,680,377,920,984
null
63
63
S = input() K = int(input()) curr = S[0] tmp = "" T = [] for s in S: if s == curr: tmp += s else: T.append(tmp) curr = s tmp = s T.append(tmp) if len(T) == 1: res = (len(S) * K) // 2 print(res) exit(0) res = 0 t_first = T[0] t_last = T[-1] if t_first[0] != t_last[0]: res += (len(t_first) // 2) * K res += (len(t_last) // 2) * K else: res += len(t_first) // 2 res += len(t_last) // 2 res += (len(t_first + t_last) // 2) * (K - 1) for t in T[1:-1]: res += (len(t) // 2) * K print(res)
def main3(): s = input() k = int(input()) if len(set(s)) == 1: print(len(s)*k//2) else: s1 = list(s) s2 = list(s + s) c1, c2 = 0, 0 for i in range(len(s1) - 1): if s1[i] == s1[i + 1]: c1 += 1 s1[i + 1] = "-" for i in range(len(s2) - 1): if s2[i] == s2[i + 1]: c2 += 1 s2[i + 1] = "-" d = c2 - c1 print(c1 + (k - 1) * d) if __name__ == "__main__": main3()
1
175,228,356,475,978
null
296
296
T = int(input()) print('Yes' if T >= 30 else 'No')
a, b = map(int, raw_input().split()) if a < b: print('a < b') elif b < a: print('a > b') else: print('a == b')
0
null
3,025,222,612,540
95
38
import sys input = sys.stdin.readline import math def INT(): return int(input()) def MAPINT(): return map(int, input().split()) def LMAPINT(): return list(map(int, input().split())) def STR(): return input() def MAPSTR(): return map(str, input().split()) def LMAPSTR(): return list(map(str, input().split())) f_inf = float('inf') n = INT() a = sorted(LMAPINT()) length = (max(a) + 1) ans = [0] * length for x in a: # 重複 if ans[x] != 0: ans[x] = 2 continue for j in range(x, length, x): ans[j] += 1 count = 0 for x in a: if ans[x] == 1: count += 1 print(count)
import sys from collections import deque import numpy as np import math sys.setrecursionlimit(10**6) def S(): return sys.stdin.readline().rstrip() def SL(): return map(str,sys.stdin.readline().rstrip().split()) def I(): return int(sys.stdin.readline().rstrip()) def IL(): return map(int,sys.stdin.readline().rstrip().split()) def solve(): f = math.ceil(n/1.08) if math.floor(f*1.08)==n: print(f) else: print(':(') return if __name__=='__main__': n = I() solve()
0
null
70,217,117,430,916
129
265
from math import gcd class Factor: def __init__(self, max_element): self.minFactor = [-1]*(max_element+1) for i in range(2, max_element+1): if self.minFactor[i] == -1: for j in range(i, max_element+1, i): self.minFactor[j] = i def getFactorSet(self, element): retSet = set(1) while element > 1: retSet.add(element) retSet.add(self.minFactor[element]) element //= self.minFactor[element] return retSet def getPrimeFactorSet(self, element): retSet = set() while element > 1: retSet.add(self.minFactor[element]) element //= self.minFactor[element] return retSet def getPrimeFactorDic(self, element): retDic = {} while element > 1: val = self.minFactor[element] if val in retDic: retDic[val] += 1 else: retDic[val] = 1 element //= val return retDic def main(): n = int(input()) a = list(map(int, input().split())) f = True fact = Factor(max(a)) st = set() for v in a: fac_set = fact.getPrimeFactorSet(v) for u in fac_set: if u in st: f = False break st.add(u) if not f: break if f: print("pairwise coprime") else: all_gcd = a[0] for i in range(1, n): all_gcd = gcd(all_gcd, a[i]) if all_gcd == 1: print("setwise coprime") else: print("not coprime") if __name__ == "__main__": main()
from math import gcd from functools import reduce from collections import defaultdict n=int(input()) a=list(map(int,input().split())) if reduce(gcd,a)!=1: print("not coprime") exit() def primes(x): ret=[] for i in range(1,int(x**0.5)+1): if x%i==0: ret.append(i) if x//i!=i: ret.append(x//i) ret.sort() return ret[1:] s=set() for q in a: p=primes(q) for j in p: if j in s: print("setwise coprime") exit() s.add(j) print("pairwise coprime")
1
4,101,365,734,282
null
85
85
n = int(raw_input()) d = [100 for i in range(n)] G = [0 for i in range(n)] v = [[0 for i in range(n)] for j in range(n)] def BFS(s): for e in range(n): if v[s][e] == 1: if d[e] > d[s] + 1: d[e] = d[s]+1 BFS(e) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): v[G[0]-1][G[j+2]-1] = 1 d[0] = 0 for i in range(n): BFS(i) for i in range(n): if d[i] == 100: d[i] = -1 for i in range(n): print i+1, d[i]
from collections import deque def main(): inf = 1000000007 n = int(input()) e = [[] for _ in range(n)] d = [inf]*n for i in range(n): m = list(map(int,input().split())) for j in range(2,len(m)): e[m[0]-1].append(m[j]-1) d[0] = 0 dq = deque([]) dq.append([0,0]) while dq: c,v = dq.popleft() for u in e[v]: if d[u]==inf: d[u] = c+1 dq.append([c+1,u]) for i in range(n): if d[i]==inf:print (i+1,-1) else :print (i+1,d[i]) if __name__ == '__main__': main()
1
3,749,064,732
null
9
9
values = [] while True: v = int(input()) if 0 == v: break values.append(v) for i, v in enumerate(values): print('Case {0}: {1}'.format(i + 1, v))
S = input() K = int(input()) ss = [] seq = 1 for a,b in zip(S,S[1:]): if a==b: seq += 1 else: ss.append(seq) seq = 1 ss.append(seq) if len(ss)==1: print(len(S)*K//2) exit() if S[0] != S[-1]: ans = sum([v//2 for v in ss]) * K print(ans) else: ans = sum([v//2 for v in ss[1:-1]]) * K ans += (ss[0]+ss[-1])//2 * (K-1) ans += ss[0]//2 + ss[-1]//2 print(ans)
0
null
87,861,717,561,342
42
296
a, b = map(int, input().split()) if (a >= 1) and (a <= 9) and (b >= 1) and (b <= 9): print(a * b) else: print(-1)
a, b = map(int, input().split()) if a > 0 and a < 10: if b > 0 and b < 10: print(a * b) else: print(-1) else: print(-1)
1
158,753,541,905,742
null
286
286
N, K = list(map(int, input().split())) A = list(map(int, input().split())) U = max(A)+1 L = 0 def can(x, K): ct = 0 for i in range(N): ct += (A[i]-1)//x if ct <= K: return True else: return False while U-L > 1: x = (U+L+1)//2 if can(x, K): U = x else: L = x print(U)
def maximum_volume(): """ 立方体に近いほど体積が大きくなる """ # 入力 L = int(input()) # 処理 one_side = L / 3 # 体積 return one_side ** 3 result = maximum_volume() print(result)
0
null
26,723,101,626,660
99
191
N = int(input()) n = min(N, 10**6) is_Prime = [True] * (n + 1) is_Prime[0] = False is_Prime[1] = False for i in range(2, int(n**(1/2)+1)): for j in range(2*i, n+1, i): if j % i == 0: is_Prime[j] = False P = [i for i in range(n+1) if is_Prime[i]] count = 0 for p in P: count_p = 0 while N % p == 0: count_p += 1 N /= p count += int((-1+(1+8*count_p)**(1/2))/2) if p == P[-1] and N != 1: count += 1 print(count)
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 N, T = map(int, readline().split()) dishes = [] for _ in range(N): A, B = map(int, readline().split()) dishes.append([A, B]) dp1 = [[0]*T for _ in range(N)] # i and less than i dp2 = [[0]*T for _ in range(N+1)] # more than i for i, dish in enumerate(dishes[:-1]): a, b = dish i = i + 1 for t in range(T): if a > t: dp1[i][t] = dp1[i-1][t] else: if dp1[i-1][t-a] + b > dp1[i-1][t]: dp1[i][t] = dp1[i-1][t-a] + b else: dp1[i][t] = dp1[i-1][t] for i, dish in enumerate(reversed(dishes[1:])): a, b = dish i = N - i - 1 for t in range(T): if a > t: dp2[i][t] = dp2[i+1][t] else: if dp2[i+1][t-a] + b > dp2[i+1][t]: dp2[i][t] = dp2[i+1][t-a] + b else: dp2[i][t] = dp2[i+1][t] ans = 0 for last in range(1, N+1): for j in range(T): a = dishes[last-1][1] a += dp1[last-1][T-1-j] + dp2[last][j] ans = a if ans < a else ans print(ans) if __name__ == '__main__': solve()
0
null
84,385,676,119,960
136
282
from scipy.sparse.csgraph import floyd_warshall from numpy import where n,m,l=map(int,input().split()) abc=[list(map(int,input().split()))for i in range(m)] q=int(input()) st=[list(map(int, input().split()))for i in range(q)] t=[[float("inf")]*n for _ in range(n)] for a,b,c in abc: if c<=l:t[a-1][b-1]=c f=floyd_warshall(t,0) l=floyd_warshall(where(f<=l,1,f),0) for s, t in st:print(-1if l[s-1,t-1]==float("inf")else int(l[s-1,t-1])-1)
import sys input = sys.stdin.readline N,M,L = map(int,input().split()) ABC = [list(map(int,input().split())) for _ in [0]*M] Q = int(input()) ST = [list(map(int,input().split())) for _ in [0]*Q] INF = (L+1)*N d = [[INF]*N for _ in [0]*N] for i in range(N): d[i][i] = 0 for a,b,c in ABC: a-=1;b-=1 d[a][b] = c d[b][a] = c def Warshall_Floyd(d,N=None): if N==None : N = len(d) for k in range(N): for i in range(N): for j in range(N): d[i][j] = min(d[i][j],d[i][k]+d[k][j]) Warshall_Floyd(d,N) d2 = [None]*N for i,row in enumerate(d): d2[i] = [1 if e<=L else INF for e in row] d2[i][i] = 0 Warshall_Floyd(d2,N) for s,t in ST: s-=1;t-=1 ans = (d2[s][t]%INF)-1 print(ans)
1
173,547,162,362,848
null
295
295
k, x = list(map(int, input().split())) print('Yes') if k *500 >= x else print('No')
k, m = list(map(int, input().split())) if 500 * k >= m: print('Yes') elif 500 * k < m: print('No') else: print('No')
1
98,434,159,949,372
null
244
244
def show_list(a): for x in a: print x, print def stable_check(sorted_values,sorted_suits,default_values,default_suits,n): for i in xrange(1,10): check_ss = [] check_ds = [] if i in sorted_values: for x in xrange(n): if i == sorted_values[x]: check_ss.append(sorted_suits[x]) if i == default_values[x]: check_ds.append(default_suits[x]) for x in xrange(len(check_ss)): if check_ss[x]!=check_ds[x]: return "Not stable" return "Stable" def bubble_sort(values,suits,n): flag = True while flag: flag = False for j in reversed(xrange(1,n)): if values[j] < values[j-1]: tmp = values[j] values[j] = values[j-1] values[j-1] = tmp tmp = suits[j] suits[j] = suits[j-1] suits[j-1] = tmp flag = True show_list(marge_suits_values(values,suits,n)) def selection_sort(values,suits,n): for i in xrange(n): minj = i for j in xrange(i,n): if values[j]<values[minj]: minj = j if minj!=i: tmp = values[i] values[i]=values[minj] values[minj]=tmp tmp = suits[i] suits[i]=suits[minj] suits[minj]=tmp show_list(marge_suits_values(values,suits,n)) def marge_suits_values(values,suits,n): ans = [] for x in xrange(n): ans.append(suits[x]+str(values[x])) return ans def main(): n = input() a = raw_input().split() suits1 = [] values1 =[] for x in xrange(n): suits1.append(a[x][0]) values1.append(int(a[x][1])) suits2 = list(suits1) values2 = list(values1) bubble_sort(values1,suits1,n) print stable_check(values1,suits1,values2,suits2,n) values1 = list(values2) suits1 = list(suits2) selection_sort(values2,suits2,n) print stable_check(values2,suits2,values1,suits1,n) if __name__ == '__main__': main()
import copy def BubbleSort(C, n): flag = 1 while flag: flag = 0 for i in range(n-1, 0, -1): if int(C[i][1]) < int(C[i - 1][1]): C[i], C[i-1] = C[i-1], C[i] flag = 1 return C def SelectionSort(C, n): for i in range(n-1): minj = i for j in range(i, n): if int(C[j][1]) < int(C[minj][1]): minj = j if minj != i: C[i], C[minj] = C[minj], C[i] return C n = int(input()) C = list(input().split()) C2 = C.copy() print(*BubbleSort(C, n), sep=' ') print("Stable") print(*SelectionSort(C2, n), sep=' ') if C ==C2: print("Stable") else: print("Not stable")
1
23,770,649,252
null
16
16