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
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate 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(): def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] def unite(x,y): x = root(x) y = root(y) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 n,m = LI() rank = [0]*n par = [i for i in range(n)] for _ in range(m): a,b = LI() a -= 1 b -= 1 if root(a) != root(b): unite(a,b) cnt = [0]*n for i in range(n): cnt[root(i)] += 1 print(max(cnt)) return #Solve if __name__ == "__main__": solve()
n = input().split(" ") for i,j in enumerate(n,1): if 0 == int(j): print(i)
0
null
8,712,712,466,118
84
126
code = r""" # distutils: language=c++ # distutils: include_dirs=/opt/ac-library from libcpp cimport bool from libcpp.vector cimport vector cdef extern from "<atcoder/dsu>" namespace "atcoder": cdef cppclass dsu: dsu(int n) int merge(int a, int b) bool same(int a, int b) int leader(int a) int size(int a) vector[vector[int]] groups() from libc.stdio cimport getchar, printf cdef inline int read() nogil: cdef int b, c = 0 while 1: b = getchar() - 48 if b < 0: return c c = c * 10 + b cdef int n = read(), i cdef dsu *u = new dsu(n) for i in range(read()): u.merge(read() - 1, read() - 1) printf('%lu\n', u.groups().size() - 1) """ import os, sys if sys.argv[-1] == 'ONLINE_JUDGE': open('solve.pyx', 'w').write(code) os.system('cythonize -i -3 -b solve.pyx') import solve
n = int(input()) adj = [None] for i in range(n): adj_i = list(map(int, input().split()[2:])) adj.append(adj_i) isSearched = [None] + [False] * n distance = [None] + [-1] * n def bfs(u): d = 0 isSearched[u] = True distance[u] = d edge = [u] while edge: q = list(edge) edge = [] d += 1 for c_e in q: for n_e in adj[c_e]: if not isSearched[n_e]: isSearched[n_e] = True edge.append(n_e) distance[n_e] = d bfs(1) for i, x in enumerate(distance[1:], start=1): print(i, x)
0
null
1,141,928,880,132
70
9
n=int(input()) li=list(map(int,input().split())) dic={} ans=0 for i in range(n): val=dic.get(li[i],-1) if val==-1: dic[li[i]]=1 else: dic[li[i]]=val+1 ans+=li[i] q=int(input()) for i in range(q): a,b=map(int,input().split()) val=dic.get(a,-1) if val==-1 or val==0: print(ans) else: nb=dic.get(b,-1) if nb==-1: dic[b]=val else: dic[b]=val+nb ans+=(b-a)*val dic[a]=0 print(ans)
import sys,itertools,collections,bisect from collections import deque,Counter,defaultdict from heapq import heappush,heappop,heapify read=sys.stdin.readline sys.setrecursionlimit(10**6) MOD=10**9+7 N=int(input()) A=list(map(int,input().split())) cum=[0]*(N+1) for i in range(N): cum[i+1]=(cum[i]+A[i])%MOD ans=0 for i in range(N): res=(cum[N]-cum[i+1]+MOD)%MOD*A[i]%MOD ans=(ans+res)%MOD print(ans)
0
null
7,952,726,255,360
122
83
X,Y,Z = (int(X) for X in input().split()) Y,X = X,Y Z,X = X,Z print('{} {} {}'.format(X,Y,Z))
def resolve(): N,K,C = map(int,input().split()) S=input() dpt1=[0]*K dpt2=[0]*K pnt = 0 for i in range(K): while S[pnt]=="x": pnt+=1 dpt1[i]=pnt pnt += C+1 pnt = N-1 for i in range(K-1,-1,-1): while S[pnt] == "x": pnt -=1 dpt2[i]=pnt pnt-=C+1 for a,b in zip(dpt1,dpt2): if a == b: print(a+1) if __name__ == "__main__": resolve()
0
null
39,473,351,077,312
178
182
# 不親切な人の証言は、正しかろうが間違っていようが検証できないので無視する # bit全探索で正直者を仮定・固定して、証言に矛盾が出なければ人数を数えて記録する from itertools import product n = int(input()) Ev = [[] for _ in range(n)] for i in range(n): A = int(input()) for a in range(A): x, y = map(int, input().split()) Ev[i].append((x - 1, y)) bit = list(product([1, 0], repeat=n)) ans = 0 for b in bit: for i, v in enumerate(b): # v == 1 or 0 if v == 1: for x, y in Ev[i]: # 証言1つ1つを取り出して検証 if b[x] != y: # bitで仮定している正直者リストと矛盾する証言を正直者が行ったらアウト break else: continue break else: ans = max(b.count(1), ans) print(ans)
n = int(input()) v = [[tuple(map(int, input().split()))for i in range(int(input()))] for i in range(n)] ans = 0 for i in range(2**n): f = True a = 0 for j in range(n): if (i >> j) & 1: if all(i >> (x - 1) & 1 == y for x, y in v[j]): a += 1 else: f = False break if f: ans = max(ans, a) print(ans)
1
121,184,097,364,162
null
262
262
l=list(input()) if(l[0]==l[1]==l[2]): print("No") else: print("Yes")
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): def meguru_bisect(left, right): """ is_okを定義して下さい :param left: 取りうる最小の値-1 :param right: 取りうる最大の値+1 :return: is_okを満たす最小(もしくは最大)の値 """ while abs(left - right) > 1: mid = (left + right) // 2 if is_ok(mid): right = mid else: left = mid return right def is_ok(x): total = 0 for i in range(n): total += max(0, A[i] - x // F[i]) return total <= k n, k = map(int, input().split()) A = sorted(list(map(int, input().split()))) F = sorted(list(map(int, input().split())), reverse=True) left = -1 right = 10 ** 12 + 1 res = meguru_bisect(left, right) print(res) if __name__ == '__main__': resolve()
0
null
109,966,916,036,980
201
290
from itertools import permutations n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) l=[i+1 for i in range(n)] perm = permutations(l) perm=list(perm) p=[] for i in perm: k=(''.join(map(str,i))) p.append(int(k)) a=''.join(map(str,a)) b=''.join(map(str,b)) idx1=p.index(int(a)) idx2=p.index(int(b)) print(abs(idx1-idx2))
import itertools N = int(input()) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) l = [] for i in range(1,N+1): l.append(i) tmp = sorted(list(itertools.permutations(l))) p = tmp.index(P) q = tmp.index(Q) print(abs(p-q))
1
100,156,325,840,802
null
246
246
n=input() print':'.join(map(str,[n/3600,n%3600/60,n%60]))
print("YES") if int(input()) == len(list(set(input().split(" ")))) else print("NO")
0
null
37,046,474,532,660
37
222
import math def main(): data = [] while 1: try: n = input().split() a = int(n[0]) b = int(n[1]) ans = int(math.log10(a+b)+1) data.append(ans) except EOFError: break for i in data: print(i) if __name__ == "__main__": main()
import sys a = [] answer_array = [] for line in sys.stdin: a.append(map(int, line.strip().split())) #except StopIteration: #break for i in range(len(a)): sum_up = a[i][0] + a[i][1] answer = len(str(sum_up)) answer_array.append(answer) for j in range(len(answer_array)): print answer_array[j]
1
80,294,588
null
3
3
from collections import deque n = int(input()) a = deque() for i in range(n): s = input().split(" ") if s[0] == "insert": a.appendleft(int(s[1])) elif s[0] == "delete": if int(s[1]) in a: a.remove(int(s[1])) elif s[0] == "deleteLast": a.pop() elif s[0] == "deleteFirst": a.popleft() b = list(a) for i in range(len(b)): if i == len(b)-1: print(b[i]) else: print(b[i],end=" ")
n, x, m = map(int, input().split()) a = x s = 0 h = [] h.append(a) i = 0 fl = 0 while i < n: s += a a = (a*a) % m if a == 0: break i += 1 if fl == 0 and a in h: fl = 1 po = h.index(a) ss = 0 for j in range(po): ss += h[j] s2 = s - ss f = (n - po) // (i - po) s2 *= f s = s2 + ss i2 = i - po i2 *= f i = i2 + po else: h.append(a) print(s)
0
null
1,405,113,501,440
20
75
X = int(input()) def define_rate(X): if X >= 1800: return 1 elif X >= 1600: return 2 elif X >= 1400: return 3 elif X >= 1200: return 4 elif X >= 1000: return 5 elif X >= 800: return 6 elif X >= 600: return 7 elif X >= 400: return 8 print(define_rate(X))
n = int(input()) mod = 10 ** 9 + 7 start,zero,nine,ans = 1,0,0,0 for i in range(n): ans = (ans * 10 + zero + nine) % mod zero = (zero * 9 + start) % mod nine = (nine * 9 + start) % mod start = (start * 8) % mod print(ans)
0
null
4,969,078,491,234
100
78
def main(): from sys import setrecursionlimit, stdin, stderr from os import environ from collections import defaultdict, deque, Counter from math import ceil, floor from itertools import accumulate, combinations, combinations_with_replacement setrecursionlimit(10**6) dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0 input = lambda: stdin.readline().rstrip() LMIIS = lambda: list(map(int,input().split())) II = lambda: int(input()) P = 10**9+7 INF = 10**18+10 H,W,M = LMIIS() targets_row = [] targets_column = [] targets = [] for i in range(M): column,row = LMIIS() targets_row.append(row) targets_column.append(column) targets.append((column,row)) common_columns = Counter(targets_column).most_common() common_rows = Counter(targets_row).most_common() max_columns = defaultdict(bool) num_max_column = common_columns[0][1] for k,v in common_columns: if v < num_max_column: break max_columns[k] = True max_rows = defaultdict(bool) num_max_row = common_rows[0][1] for k,v in common_rows: if v < num_max_row: break max_rows[k] = True dbg(max_columns) dbg(max_rows) num_candidates = len(max_columns)*len(max_rows) num_target_on_intersection = 0 for column, row in targets: if max_columns[column] and max_rows[row]: num_target_on_intersection += 1 ans = common_columns[0][1] + common_rows[0][1] dbg(num_target_on_intersection) dbg(num_candidates) print(ans if num_target_on_intersection < num_candidates else ans - 1) main()
h , w , m = map(int,input().split()) retu = [0 for i in range(w)] gyo = [0 for i in range(h)] basyo = set() for i in range(m): a , b = map(lambda x:int(x)-1,input().split()) retu[b] += 1 gyo[a] += 1 basyo.add((a,b)) t = max(retu) mare = [i for i, v in enumerate(retu) if v == t] s = max(gyo) magy = [i for i, v in enumerate(gyo) if v == s] for i in magy: for j in mare: if not (i,j) in basyo: print(s+t) exit() print(s+t-1)
1
4,721,232,540,220
null
89
89
s=input() dic={} cur=0 power=0 for i in range(0,len(s)+1): s_int=len(s)-i-1 if cur in dic: dic[cur]+=1 else: dic[cur]=1 try: num=int(s[s_int]) cur+=num*pow(10,power,2019) cur%=2019 power+=1 except IndexError: break res=0 for i in range(len(dic)): t=dic.popitem() cc=t[1] res+=cc*(cc-1)//2 print(res)
n=int(input()) a=list(map(int,input().split())) mini=a[0] count=0 for i in range(n): if mini>=a[i]: count+=1 mini=a[i] else: pass print(count)
0
null
58,158,890,222,802
166
233
i = input() a = input().split() c = a[0] d = a[0] for j in range(int(i)): if int(c) > int(a[j]): c = int(a[j]) for j in range(int(i)): if int(d) < int(a[j]): d = int(a[j]) e = sum(int(o) for o in a) print('{0} {1} {2}'.format(int(c),int(d),int(e)))
class MyClass(): def main(self): self.n = input() self.A = map(int,raw_input().split()) self.q = input() self.M = map(int,raw_input().split()) W = map(self.solve,self.M) for w in W: print w def solve(self,m): w = self.rec(m,self.A) if w: return "yes" else: return "no" def rec(self,m,A): if len(A) == 1: r1 = False else: r1 = self.rec(m,A[1:]) m_new = m - A[0] if m_new == 0: r2 = True elif len(A) > 1 and min(A[1:]) <= m_new <= sum(A[1:]): r2 = self.rec(m_new,A[1:]) else: r2 = False if r1 or r2: return True else: return False if __name__ == "__main__": MC = MyClass() MC.main()
0
null
415,975,731,098
48
25
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) # INF = float("inf") INF = 10**18 import bisect import statistics mod = 10**9+7 # mod = 998244353 N = int(input()) if N % 2 == 1: print(0) else: i = 1 ans = 0 while N > 0: N = N // 5 ans += N // 2 print(ans)
import sys import math N = int(input()) if N % 2 == 1: print(0) sys.exit() count_2 = 0 count_5 = 0 deno = 2 while deno <= N: count_2 += N // deno deno *= 2 deno = 10 while deno <= N: count_5 += N // deno deno *= 5 print(min(count_2, count_5))
1
116,222,507,135,228
null
258
258
import sys import math char = "abcdefghijklmnopqrstuvwxyz" cnt = {} for S in sys.stdin: for x in S: x = x.lower() if x not in cnt: cnt[x] = 0 cnt[x] += 1 for c in char: sys.stdout.write(c + " : ") if c not in cnt: print 0 else: print cnt[c]
def get_input(): while True: try: yield ''.join(raw_input().strip()) except EOFError: break inlist = list(get_input()) instr = "".join(inlist) instr = instr.lower() ascstart = 97 ascfin = 122 strlist = [0 for i in xrange(97,122+1)] # print len(strlist) for x in xrange(len(instr)): if ord(instr[x]) < ascstart or ord(instr[x]) > ascfin: continue strlist[ord(instr[x])-ascstart] +=1 for x in xrange(ascstart,ascfin+1): print "%s : %d" % (chr(x),strlist[x-ascstart])
1
1,632,707,115,028
null
63
63
n = int(input()) A = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) memo = [[None]*2000 for i in range(2000)] def exhaustivesearch(i, target): if memo[i][target] is not None: return memo[i][target] if target == 0: memo[i][target] = True return True if i >= n: memo[i][target] = False return False else: memo[i][target] = exhaustivesearch(i + 1, target) or exhaustivesearch(i + 1, target-A[i]) return memo[i][target] for j in m: if exhaustivesearch(0, j): print("yes") else: print("no")
n=int(input()) A=list(map(int,input().split())) q=int(input()) M=list(map(int,input().split())) pattern=[] for i in range(2**n): s=0 for j in range(n): if i >> j & 1: s+=A[j] pattern.append(s) P=set(pattern) for m in M: print('yes' if m in P else 'no')
1
99,771,922,170
null
25
25
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 True if(self.__front or self.__back) else False 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() front.pop() 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())) swag=SWAG(min) dp=[INF]*(n+1) dp[n]=0 for i in range(n-1,-1,-1): if(i+1+m<=n): swag.popleft() swag.append(dp[i+1]) if(S[i]==1): continue dp[i]=swag.sum()+1 if(dp[0]==INF): print(-1) return ans=[] now=0 next=0 while(now!=n): next+=1 if(dp[next]!=INF and dp[now]!=dp[next]): ans.append(next-now) now=next print(*ans) resolve()
# https://atcoder.jp/contests/abc146/submissions/8617148 def solve(N, M, S): from collections import namedtuple from heapq import heappop, heappush INF = N * 2 V = namedtuple('V', 'cnt index') cnt_from_N = [INF] * (N + 1) cnt_from_N[N] = 0 parent = [0] * (N + 1) h = [V(cnt=0, index=N)] for j in range(N - 1, -1, -1): # S[j]に到達する最小回数とその経路を求める if S[j]: continue while h: cnt, par = h[0] if par > j + M: # jまで移動できない(距離>M) heappop(h) continue break # jまで最小回数で到達できる頂点par # parまでの回数cnt if not h: return -1, # jまで到達できる頂点がない cnt_from_N[j] = cnt + 1 parent[j] = par heappush(h, V(cnt=cnt + 1, index=j)) ret = [] curr = 0 while curr < N: par = parent[curr] ret.append(par - curr) curr = par return ret def main(): N, M = map(int, input().split()) *S, = map(int, input()) print(*solve(N, M, S)) if __name__ == '__main__': main()
1
138,752,189,992,640
null
274
274
def run(): X, N = [int(v) for v in input().rstrip().split()] p = [] if N > 0: p = [int(v) for v in input().rstrip().split()] i = -1 try: i = p.index(X) except ValueError: pass if i == -1: # not contained return X d1 = {} for k in range(0, 102): d1[k] = k for v in p: del d1[v] l2 = sorted(list(d1.keys())) l2.append(X) l2.sort() i = l2.index(X) r = 0 if i == 0: r = l2[1] elif (i + 1) == len(l2): r = l2[-2] else: v1 = l2[i + 1] - X v2 = X - l2[i - 1] if v1 < v2 : r = l2[i + 1] elif v1 > v2 : r = l2[i - 1] else: # v1 == v2 r = l2[i - 1] return r r = run() print(r)
import bisect def abc170c_forbidden_list(): x, n = map(int, input().split()) p = list(map(int, input().split())) if n == 0: print(x) return p.sort() for i in range(100): idx = bisect.bisect_left(p, x - i) if idx >= n or p[idx] != x - i: print(x - i) return idx = bisect.bisect_left(p, x + i) if idx >= n or p[idx] != x + i: print(x + i) return abc170c_forbidden_list()
1
14,107,571,845,568
null
128
128
h,w,m = map(int,input().split()) x = {} y = {} dic = {} for _ in range(m): a,b = map(int,input().split()) dic[(a,b)] = 1 x[a] = x.get(a,0) + 1 y[b] = y.get(b,0) + 1 p = max(x.values()) q = max(y.values()) cnt = 1 a = [i for i in x if x[i] == p] b = [j for j in y if y[j] == q] for i in a: for j in b: if dic.get((i,j),-1) == -1: cnt = 0 break if not cnt: break print(p+q-cnt)
import sys #DEBUG=True DEBUG=False if DEBUG: f=open("202007_2nd/D_input.txt") else: f=sys.stdin #from 2nd count def cnt_func(num): cnt=0 while num: num%=bin(num).count("1") cnt+=1 return cnt+1 n=int(f.readline().strip()) s=f.readline().strip() input_val=int(s,2) input_one_count=s.count("1") #Base value zero_first=input_val%(input_one_count+1) one_first=input_val%(input_one_count-1) if input_one_count>1 else 0 ans=0 for idx,emt in enumerate(s): p=n-idx-1 if emt=="0": #inverted to "1" ans=cnt_func((zero_first+(pow(2,p,input_one_count+1)))%(input_one_count+1)) else: #inverted to "0" if input_one_count>1: ans=cnt_func((one_first-(pow(2,p,input_one_count-1)))%(input_one_count-1)) else: ans=0 print(ans) f.close()
0
null
6,494,060,842,248
89
107
n = int(input()) L11= [0] * 10 L12= [0] * 10 L13= [0] * 10 L21= [0] * 10 L22= [0] * 10 L23= [0] * 10 L31= [0] * 10 L32= [0] * 10 L33= [0] * 10 L41= [0] * 10 L42= [0] * 10 L43= [0] * 10 for i in range(n): b,f,r,v = map(int, input().split()) r -= 1 if b == 1: if f == 1: L11[r] += v if f == 2: L12[r] += v if f == 3: L13[r] += v if b == 2: if f == 1: L21[r] += v if f == 2: L22[r] += v if f == 3: L23[r] += v if b == 3: if f == 1: L31[r] += v if f == 2: L32[r] += v if f == 3: L33[r] += v if b == 4: if f == 1: L41[r] += v if f == 2: L42[r] += v if f == 3: L43[r] += v def PV(L): for i in range(9): print(" " + str(L[i]), end="") print(" " + str(L[9])) def PL(): print("#" * 20) PV(L11) PV(L12) PV(L13) PL() PV(L21) PV(L22) PV(L23) PL() PV(L31) PV(L32) PV(L33) PL() PV(L41) PV(L42) PV(L43)
import math N = int(input()) n = int(math.sqrt(N)) ans = 0 l = [] for i in range(1,2*n): if int(N/i) == N/i: l.append(i+N/i-2) print(int(min(l)))
0
null
80,989,934,724,750
55
288
# -*- coding: utf-8 -*- """ Created on Thu May 7 23:19:34 2020 @author: Kanaru Sato """ def dfs(v): global t d[v] = t t += 1 if conlist[v]: for connectedv in conlist[v]: if d[connectedv] == -1: dfs(connectedv) f[v] = t t += 1 n = int(input()) conlist = [[] for i in range(n)] for i in range(n): _ = list(map(int,input().split())) [conlist[i].append(_[k]-1) for k in range(2,_[1]+2)] d = [-1 for i in range(n)] f = [-1 for i in range(n)] t = 1 for i in range(n): if d[i] == -1: dfs(i) for i in range(n): print(i+1,d[i],f[i])
h,w = list(map(int, input().split())) board = [] dp = [] INF=10**18 for _ in range(h): board.append(input()) dp.append([INF]*w) dxy=[(0,1), (0,-1), (1,0), (-1,0)] dp[0][0]=1 if board[0][0] == '#' else 0 for y in range(h): for x in range(w): dp_list=[dp[y][x]] if x>0: dp_left = dp[y][x-1] if board[y][x-1] != board[y][x] and board[y][x] == '#': dp_left += 1 dp_list.append(dp_left) if y>0: dp_up=dp[y-1][x] if board[y-1][x] != board[y][x] and board[y][x] == '#': dp_up += 1 dp_list.append(dp_up) dp[y][x]=min(dp_list) print(dp[h-1][w-1])
0
null
24,481,204,043,214
8
194
n,k = map(int, input().split()) ans = 0 while n > 0: n /= k n = int(n) ans += 1 print(ans)
n = int(input()) s = [] for _ in range(n): s.append(str(input())) print('AC x ' + str(s.count('AC'))) print('WA x ' + str(s.count('WA'))) print('TLE x ' + str(s.count('TLE'))) print('RE x ' + str(s.count('RE')))
0
null
36,478,547,212,312
212
109
a = input() a = a.split() x=int(a[0]) y=int(a[1]) if x>y: print("safe") else: print("unsafe")
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
31,172,872,234,448
163
170
def main(): import sys input = sys.stdin.readline n, d, a = [int(i) for i in input().split()] chk = [] for i in range(n): x, h = [int(i) for i in input().split()] chk.append((x, 0, h)) from heapq import heapify, heappop, heappush heapify(chk) atk_cnt = 0; ans = 0 while chk: x, t, h = heappop(chk) if t == 0: if atk_cnt * a >= h: continue remain = h - atk_cnt * a new_atk = (remain - 1) // a + 1 heappush(chk, (x + 2 * d, 1, new_atk)) ans += new_atk atk_cnt += new_atk else: atk_cnt -= h print(ans) if __name__ == '__main__': main()
def main(): import sys from collections import deque from operator import itemgetter b = sys.stdin.buffer N,D,A = map(int, b.readline().split()) m = map(int, b.read().split()) ans = 0 Q = deque() d = 0 for x,h in sorted(zip(m,m), key=itemgetter(0)): while Q and Q[0][0] < x: _,d_ = Q.popleft() d += d_ h = h+d if h <= 0: continue n = -(-h // A) d -= n * A ans += n Q.append((x+2*D,n * A)) print(ans) main()
1
82,131,391,422,770
null
230
230
from math import * n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() def is_ok(arg): tmp=0 for i in a: tmp+=ceil(i/arg)-1 return tmp<=k def meguru_bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok print(meguru_bisect(0, max(a)))
from sys import stdin input = stdin.readline def Judge(S, T): ls = len(S) lt = len(T) m = 0 for i in range(ls-lt+1): tmp = 0 for j in range(lt): if S[i+j] == T[j]: tmp += 1 if m < tmp: m = tmp return lt - m S = input().strip() T = input().strip() print(Judge(S, T))
0
null
5,088,554,530,470
99
82
N = int(input()) P = list(map(int, input().split())) min = P[0] ans = 0 for i in range(N): if i == 0: ans += 1 elif min > P[i]: ans += 1 min = P[i] print(ans)
H, W = map(int, input().split()) if H > 1 and W > 1: if H*W % 2 == 0: s = (H * W) // 2 elif H*W % 2 != 0: s = (H * W + 1) // 2 elif H == 1 or W == 1: s = 1 print(s)
0
null
68,502,474,330,780
233
196
X = int(input()) print(10 - X // 200)
a, b, c, k = map(int, input().split()) if k <= a: print(int(k)) elif k <= a + b: print(int(a)) else: print(int(2*a + b - k))
0
null
14,408,138,829,062
100
148
a = list(map(int, input().split())) a.sort() while a[0] > 0: b = a[1]%a[0] a[1] = a[0] a[0] = b print(a[1])
import numpy as np S = input() a = [0]*(len(S)+1) for i in range(len(S)): if S[i] == '<': a[i+1] =max(a[i+1], a[i]+1) else: a[i] = max(a[i],a[i+1]+1) for i in range(len(S)-1,-1,-1): if S[i] == '<': a[i+1] =max(a[i+1], a[i]+1) else: a[i] = max(a[i],a[i+1]+1) print(sum(a))
0
null
78,533,229,039,648
11
285
#!/usr/bin/env python3 import sys from itertools import chain def solve(K: int, S: str): if len(S) <= K: return S else: return S[:K] + "..." def main(): tokens = chain(*(line.split() for line in sys.stdin)) K = int(next(tokens)) # type: int S = next(tokens) # type: str answer = solve(K, S) print(answer) if __name__ == "__main__": main()
#import time def main(): K = int(input()) S = input() if len(S) <= K: return S else: return S[:K] + "..." if __name__ == '__main__': #start = time.time() print(main()) #elapsed_time = time.time() - start #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
1
19,722,213,419,880
null
143
143
def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p p = 10 ** 9 + 7 N = 2 * 10 ** 6 # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) X, Y = map(int, input().split()) #(1, 2)の回数をn, (2, 1)の回数をmとする。 n = (-X + 2 * Y) / 3 m = (-Y + 2 * X) / 3 #いけない場合を除外 if n % 1 != 0: print(0) quit() elif m % 1 != 0: print(0) quit() #n + m C nで答え ans = cmb(int(n + m), int(n), p) print(ans)
kMod = 1000000007 X, Y = map(int, input().split()) if (X+Y) % 3 != 0: print(0) exit() offset = (X+Y)//3 X, Y = X-offset, Y-offset if X < 0 or Y < 0: print(0) exit() X, Y = max(X, Y), min(X, Y) ans = 1 for i in range(X+1, X+Y+1): ans *= i ans %= kMod for i in range(2, Y+1): ans *= pow(i, kMod-2, kMod) ans %= kMod print(ans)
1
150,319,381,572,866
null
281
281
import sys readline = sys.stdin.readline N,M = map(int,readline().split()) A = list(map(int,readline().split())) MAX_VAL = 10 ** 5 + 1 hand = [0] * MAX_VAL for a in A: hand[a] += 1 import numpy as np def convolve(f, g): fft_len = 1 while 2 * fft_len < len(f) + len(g) - 1: fft_len *= 2 fft_len *= 2 Ff = np.fft.rfft(f, fft_len) Fg = np.fft.rfft(g, fft_len) Fh = Ff * Fg h = np.fft.irfft(Fh, fft_len) h = np.rint(h).astype(np.int64) return h[:len(f) + len(g) - 1] right_hand = np.array(hand, dtype = int) left_hand = np.array(hand, dtype = int) H = convolve(left_hand, right_hand) # Hを大きいほうから見ていくと、 # 幸福度iの握手をH[i]種類できることが分かる # 上から順に足していって、最後H[i]種類の握手を足せないときは、残りの握手回数だけ足す ans = 0 for i in range(len(H) - 1, -1, -1): if H[i] == 0: continue if H[i] <= M: # H[i]回の握手ができる ans += i * H[i] M -= H[i] else: # H[i]回の握手ができないので、残った回数だけ握手する ans += M * i break print(ans)
n = int(input()) print(sum([i for i in range(1, n + 1) if i % 3 and i % 5]))
0
null
71,323,434,238,720
252
173
X, N = map(int,input().split()) p = list(map(int,input().split())) i = 0 while True: if not X - i in p: print(X - i) break if not X + i in p: print(X + i) break i += 1
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] #a = [input() for _ in range(n)] x,n = map(int, input().split()) p = list(map(int, input().split())) ans = x for i in range(x, 102): if i not in p: ans = i break ans2 = x for i in range(x-1, -1, -1): if i not in p: ans2 = i break #print(ans,ans2) tmp1 = abs(ans - x) tmp2 = abs(x - ans2) if (tmp1 < tmp2): print(ans) elif (tmp1 == tmp2): print(min(ans, ans2)) else: print(ans2)
1
14,115,134,675,902
null
128
128
a=list(map(int, input().split())) b=list(map(int, input().split())) ou=b[0]-a[0] if ou == 1: print(1) elif ou==0: print(0) elif ou==1-12: print(1) else: print(0)
m,d = map(int,input().split()) m2,d2 = map(int,input().split()) print(1 if m != m2 else 0)
1
124,410,543,841,080
null
264
264
import math a, b, C = map(int, input().split()) rad = C/180*math.pi print('%.8f' % (a*b*math.sin(rad)/2)) print('%.8f' % ((a**2-2*a*b*math.cos(rad)+b**2)**0.5 + a + b)) print('%.8f' % (b * math.sin(C/180*math.pi)))
import math a, b, C = map(int, input().split()) C2 = math.radians(C) sin = math.sin(C2) cos = math.cos(C2) c = math.sqrt(a**2 + b**2 - 2*a*b*cos) S =(a*b*sin) / 2 L = a+b+c #L**2 = a**2 + b**2 - 2*a*b*cos h = (a*b*sin/2)/(a/2) print("{0:.8f}".format(S)) print("{0:.8f}".format(L)) print("{0:.8f}".format(h))
1
175,839,557,868
null
30
30
a=input() print(a.replace('?','D'))
#デフォルト import itertools from collections import defaultdict import collections import math import sys sys.setrecursionlimit(200000) mod = 1000000007 t = list(input()) for i in range(len(t)): if (t[i] == "?"): print("D",end="") else: print(t[i],end="")
1
18,523,595,523,488
null
140
140
(N,), *XL = [list(map(int, s.split())) for s in open(0)] XL.sort(key=lambda x: x[0] + x[1]) curr = -float("inf") ans = 0 for x, l in XL: if x - l >= curr: curr = x + l ans += 1 print(ans)
# シェルソート N = int(input()) A = [] for i in range(N): A.append(int(input())) cnt = 0 def insertionSort(A, n, g): global cnt for i in range(g, n): for j in range(i-g, -1, -g): if A[j+g] < A[j]: A[j + g], A[j] = A[j], A[j + g] cnt += 1 else: break def shellSort(A, n): # gn+1 = 3gn + 1 h = 1 G = [] while h <= n: G.append(h) h = 3 * h + 1 G.reverse() print(len(G)) print(" ".join([str(x) for x in G])) for g in G: insertionSort(A, n, g) shellSort(A, N) print(cnt) for a in A: print(a)
0
null
45,024,155,279,174
237
17
s = str(input()) t = str(input()) ans = len(t) for i in range(len(s) - len(t) + 1): tmp_ans = 0 for j in range(len(t)): if s[i+j] != t[j]: tmp_ans += 1 ans = min(ans, tmp_ans) print(ans)
n=int(input()) a=[] b=[] for i in range(n): x,y=map(int,input().split()) a.append(x+y) b.append(x-y) a=sorted(a) b=sorted(b) ans=max(a[-1]-a[0],b[-1]-b[0]) print(ans)
0
null
3,537,418,166,020
82
80
n = int(input()) z = list() w = list() for i in range(n): x,y = list(map(int,input().split())) z.append(x + y) w.append(x - y) ans = max(max(z) - min(z),max(w)-min(w)) print(ans)
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 19 MOD = 10 ** 9 + 7 N = INT() A = LIST() if N == 0: if A[0] == 1: print(1) else: print(-1) exit() cond1 = [0] * (N+1) cond1[N] = A[N] for i in range(N-1, -1, -1): cond1[i] = cond1[i+1] + A[i] if min(cond1) <= 0: print(-1) exit() cond2 = [0] * (N+1) cond2[0] = 1 for i in range(1, N+1): cond2[i] = min(cond1[i], (cond2[i-1]-A[i-1]) * 2) if min(cond2) <= 0: print(-1) exit() if cond2[N] < A[N]: print(-1) exit() ans = sum(cond2) print(ans)
0
null
11,131,068,798,454
80
141
import sys input = sys.stdin.readline sys.setrecursionlimit(2147483647) class Edge: def __init__(self, to, id): self.to = to self.id = id N = int(input()) graph = {} ans = [0] * (N-1) def dfs(v, c=-1, p=-1): global graph, ans k = 1 for edge in graph[v]: nv = edge.to if nv == p:continue if k == c:k += 1 ans[edge.id] = k dfs(nv, k, v) k += 1 def main(): global N, graph, ans for i in range(N): graph[i] = set() for i in range(N-1): a, b = map(int, input().split()) graph[a-1].add(Edge(b-1, i)) graph[b-1].add(Edge(a-1, i)) color_count = 0 for i in range(N): color_count = max(color_count, len(graph[i])) dfs(0, 0, -1) print(color_count) for x in ans: print(x) if __name__ == "__main__": main()
N = int(input()) es = [[] for _ in range(N)] connected = [0] * N for i in range(N-1): a,b = map(int, input().split()) a,b = a-1, b-1 connected[a] += 1 connected[b] += 1 es[a].append((b, i)) es[b].append((a, i)) ans = [0] * (N-1) used = [False] * (N-1) q = [] q.append((0, 0)) while q: curr, pc = q.pop() nxt_es_color = 1 for nxt, es_num in es[curr]: if used[es_num]: continue if nxt_es_color == pc: nxt_es_color += 1 ans[es_num] = nxt_es_color used[es_num] = True q.append((nxt, ans[es_num])) nxt_es_color += 1 print(max(connected)) print(*ans, sep="\n")
1
135,824,715,799,652
null
272
272
a, b, c, d = map(int, input().split()) cnt1 = 0 cnt2 = 0 while c > 0: c -= b cnt1 += 1 while a > 0: a -= d cnt2 += 1 if cnt1 <= cnt2: print('Yes') else: print('No')
# -*- coding: utf-8 -*- import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines R, C, K = map(int, readline().split()) V = [[0]*(C+1) for _ in range(R+1)] for i in range(K): r,c,v = map(int,readline().split()) V[r][c] = v dp = [0] * (C+1) dp[0] = 0 for i in range(1,R+1): ndp = [0] * (C+1) row = V[i] ldp = [0] * 4 for j in range(1,C+1): # ldp[0] = max(ldp[0], dp[j]) ldp[0] = dp[j] for k in range(2,-1,-1): ldp[k+1] = max(ldp[k+1], ldp[k] + row[j]) # 取る場合と取らない場合 ndp[j] = max(ldp) dp = ndp print(dp[C])
0
null
17,564,995,361,020
164
94
import sys N,K=map(int,input().split()) plist=[0]+list(map(int,input().split())) clist=[-float("inf")]+list(map(int,input().split())) if max(clist)<=0: print(max(clist)) sys.exit(0) if K<=N: max_answer=0 for i in range(1,N+1): pos=i max_score=0 score=0 for c in range(K): pos=plist[pos] score+=clist[pos] max_score=max(score,max_score) #print(i,max_score) max_answer=max(max_answer,max_score) print(max_answer) sys.exit(0) max_answer=0 for i in range(1,N+1): pos=i cycle_list=[] score_list=[] for _ in range(N): pos=plist[pos] cycle_list.append(pos) score_list.append(clist[pos]) if pos==i: break num_cycle=K//len(cycle_list) cycle_score=sum(score_list) #print(cycle_list,score_list,num_cycle,cycle_score) score=0 max_score=0 if cycle_score>=0: score+=(num_cycle-1)*cycle_score K2=K-len(cycle_list)*(num_cycle-1) for _ in range(K2): pos=plist[pos] score+=clist[pos] max_score=max(score,max_score) #print(i,max_score) max_answer=max(max_answer,max_score) print(max_answer)
r = int(input()) print("{}".format(r**2))
0
null
75,675,388,634,200
93
278
sum = 0 while 1: x = int(raw_input()) sum = sum + 1 if x == 0: break print 'Case %s: %s' %(sum, x)
import math a, b, c = map(float,input().split()) c = math.radians(c) S = (1/2) * a * b * math.sin(c) d = math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * math.cos(c))) L = a + b + d H = (2 * S) / a print(S,L,H)
0
null
321,090,212,948
42
30
#a問題(できなかった) s = input() p=s[0]=='R' q=s[1]=='R' r=s[2]=='R' if p and q and r==True: print(3) elif (p and q)or(q and r)==True: print(2) elif p or q or r ==True: print(1) else: print(0)
N,D,A=map(int, input().split()) B=[list(map(int, input().split())) for _ in range(N)] C=sorted(B) d,E=zip(*C) import bisect Damage=[0]*N for i in range(N): e=bisect.bisect_right(d,d[i]+2*D) Damage[i]=e dd=[0]*(N+1) cnt=0 for i in range(N): if i!=0: dd[i]+=dd[i-1] h=E[i] h-=dd[i] if h>0: bomb=-(-h//A) cnt+=bomb dd[i]+=A*bomb dd[Damage[i]]-=A*bomb print(cnt)
0
null
43,424,932,492,160
90
230
A,B=map(int,input().split()) print("safe" if A>B else "unsafe")
import math n=int(input()) m=100000 k=100000 for i in range(n): m=1.05*k m=m/1000 k=math.ceil(m)*1000 print(k)
0
null
14,561,227,867,566
163
6
n = int(input()) s = input() print(['No','Yes'][s[:n//2]==s[n//2:]])
N=int(input()) S=input() if S[0:N//2]==S[N//2:N]: print("Yes") else: print("No")
1
146,583,812,170,052
null
279
279
print(2*3.14159*int(input()))
n = int(input()) s = input() total = s.count("R") * s.count("G") * s.count("B") #l = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"] lR = [0]*n lG = [0]*n lB = [0]*n for i in range(len(s)): if s[i] == "R": lR[i] += 1 elif s[i] == "G": lG[i] += 1 else: lB[i] += 1 #print(lR) #print(lG) #print(lB) for i in range(n): j = 1 if lR[i]: while i-j >= 0 and i+j < n: if lG[i+j]!=0 and lG[i+j] == lB[i-j]: total -= 1 elif lG[i-j]!=0 and lG[i-j] == lB[i+j]: total -= 1 j += 1 elif lG[i]: while i-j >= 0 and i+j < n: if lR[i+j]!=0 and lR[i+j] == lB[i-j]: total -= 1 elif lR[i-j]!=0 and lR[i-j] == lB[i+j]: total -= 1 j += 1 elif lB[i]: while i-j >= 0 and i+j < n: if lG[i+j]!=0 and lG[i+j] == lR[i-j]: total -= 1 elif lG[i-j]!=0 and lG[i-j] == lR[i+j]: total -= 1 j += 1 print(total)
0
null
33,866,607,311,680
167
175
temperature = int(input()) if temperature >= 30: print('Yes') else: print('No')
a=int(input('')) if a>=30: print('Yes') else: print('No')
1
5,783,125,738,192
null
95
95
def main(): a,b = map(int,input().split()) if a > b: print('a > b') elif a < b: print('a < b') elif a == b: print('a == b') else: print('error') if __name__=="__main__": main()
from collections import Counter as coun from itertools import combinations as comb import sys input = sys.stdin.readline N = int(input()) S = input() C = coun(S) ans = C["R"] * C["G"] * C["B"] for i, j in comb(range(N), 2): k = 2 * j - i if k < N: A, B, C = S[i], S[j], S[k] if A != B and B != C and C != A: ans -= 1 print(ans)
0
null
18,303,282,475,108
38
175
a = int(input()) print(int(a**2))
import os def main(): r = int(input()) print(r*r//1) if __name__ == "__main__": main()
1
145,153,886,999,150
null
278
278
n=int(input()) nyukyo=[list(map(int, input().split())) for i in range(n)] bld=[[[0 for i in range(10)] for j in range(3)] for k in range(4)] for ny in nyukyo: bld[ny[0]-1][ny[1]-1][ny[2]-1]+=ny[3] for i,b in enumerate(bld): for f in b: print("",*f) if i != 3: print("####################")
h = [[[0]*10 for i in range(3)] for j in range(4)] n = int(input()) for i in range(n): b,f,r,v = map(int,input().split()) h[b-1][f-1][r-1] += v s = "" for i in range(4): for j in range(3): for k in range(10): s += " " + str(h[i][j][k]) s += "\n" if i < 3: s += "####################\n" print(s,end="")
1
1,105,528,963,830
null
55
55
a = input() t = list(a) if t[len(t)-1] == "?": t[len(t)-1] = "D" if t[0] == "?": if t[1] == "D" or t[1] == "?": t[0] = "P" else: t[0] = "D" for i in range(1, len(t)-1): if t[i] == "?" and t[i-1] == "P": t[i] = "D" elif t[i] == "?" and t[i+1] == "D": t[i] = "P" elif t[i] == "?" and t[i+1] == "?": t[i] = "P" elif t[i] == "?": t[i] = "D" answer = "".join(t) print(answer)
import sys def main(): n, x, y = map(int, sys.stdin.buffer.readline().split()) L = [0] * n for i in range(1, n): for j in range(i + 1, n + 1): d = j - i if i <= x and y <= j: d -= y - x - 1 elif i <= x and x < j < y: d = min(d, x - i + y - j + 1) elif x < i < y and y <= j: d = min(d, i - x + j - y + 1) elif x < i and j < y: d = min(d, i - x + y - j + 1) L[d] += 1 for a in L[1:]: print(a) main()
0
null
31,078,479,668,768
140
187
from itertools import product n = int(input()) ans = n-1 for a in range(1, int(n**0.5)+1): if n%a==0: b = n//a ans = min(ans, b+a-2) print(ans)
n, m = map(int, input().split()) if 2*m>=n: print(0) else: print(n-2*m)
0
null
164,565,351,250,150
288
291
fact = [None]*1000001 inv = [0,1] finv = [1,1] x, y = map(int, input().split()) total = x+y ans = 0 MOD = 10**9+7 if total%3 == 0 and max(x,y) <= min(x,y)*2: fact[1] = 1 for i in range(2,1000001): fact[i] = fact[i-1]*i%MOD inv.append((-inv[MOD%i] * (MOD//i)) % MOD) finv.append(finv[-1] * inv[-1] % MOD) step = int(total/3) sa = abs(x-y) a = int((step-sa)/2) b = int((step+sa)/2) ans = fact[step] * finv[a] * finv[b] % MOD print(ans)
N=int(input()) if N==1: print(0) exit() def primeryNum(n): border=int(n**0.5)+1 ary=list(range(int(n**0.5)+2)) ary[1]=0 for a in ary: if a>border: break elif a==0: continue for i in range(a*2,int(n**0.5)+2,a): ary[i]=0 return ary primeryNumL=primeryNum(N) # print(primeryNumL) ans=0 N_=N for x in primeryNumL: if x==0 or N%x!=0: continue n=N cnt=0 while n%x==0: cnt+=1 n/=x N_//=x**cnt buf=cnt-1 res=1 # print(x,cnt) for i in range(2,cnt+1): if buf<i: break buf-=i res+=1 ans+=res if N_>1: ans+=1 print(ans)
0
null
83,586,671,270,330
281
136
n = input() lst = list(map(int, input().split())) print(min(lst), max(lst), sum(lst))
input() a = map(int, raw_input().split()) print min(a), max(a), sum(a)
1
723,592,501,358
null
48
48
s=int(input()) p=10**9+7 if s<=2: print(0) exit() n=s//3 ans=0 x=[0]*(s+1) x[0]=1 x[1]=1 y=[0]*(s+1) for i in range(2,s+1): x[i]=x[i-1]*i%p y[s]=pow(x[s],p-2,p) for i in range(s): y[s-1-i]=y[s-i]*(s-i)%p for k in range(1,n+1): ans+=x[s-2*k-1]*y[k-1]*y[s-3*k]%p print(ans%p)
from scipy.special import comb import copy MOD = 10**9+7 s = int(input()) cnt = 0 ans = 1 if s <= 2: print(0) else : s = s-3 while s >= 3: s -= 3 cnt += 1 if s > 0: ans += comb(s+cnt, cnt, exact=True) ans %= MOD else : ans += 1 ans %= MOD print(ans)
1
3,252,762,115,680
null
79
79
from collections import defaultdict, deque import sys, heapq, bisect, math, itertools, string, queue, copy, time from fractions import gcd import numpy as np sys.setrecursionlimit(10**8) INF = float('inf') MOD = 10**9+7 EPS = 10**-7 a, b = map(int, input().split()) if a >= b: ans = str(b)*a else: ans = str(a)*b print(int(ans))
from itertools import permutations n = int(input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) perm = list(permutations(p)) perm.sort() a = perm.index(p) b = perm.index(q) print(abs(a- b))
0
null
92,591,272,157,822
232
246
N=int(input()) A=list(map(int,input().split())) if N%2==0: dp=[[-float("inf") for _ in range(2)] for _ in range(N+10)] if N==2: print(max(A[0],A[1])) else: for i in range(N): if i==0: dp[i][0]=A[0] elif i==1: dp[i][1]=A[1] elif i==2: dp[i][0]=A[0]+A[2] else: for j in range(2): if j==0: dp[i][0]=max(dp[i][0],dp[i-2][0]+A[i]) elif j==1: dp[i][1]=max(dp[i][1],dp[i-2][1]+A[i],dp[i-3][0]+A[i]) print(max(dp[N-1])) else: #print(A[0],A[1]) dp=[[-float("inf") for _ in range(3)] for _ in range(N+10)] if N==3: print(max(A[0],A[1],A[2])) else: for i in range(N): if i<4: if i==0: dp[i][0]=A[0] if i==1: dp[i][1]=A[1] if i==2: dp[i][2]=A[2] dp[i][0]=A[0]+A[2] if i==3: dp[i][1]=max(dp[1][1]+A[3],dp[0][0]+A[3]) else: for j in range(3): if j==0:#ここでも2こずつ規則よく飛ばすと決めた dp[i][0]=max(dp[i][0],dp[i-2][0]+A[i]) elif j==1:#1回だけ無茶した dp[i][1]=max(dp[i][1],dp[i-2][1]+A[i],dp[i-3][0]+A[i]) else: dp[i][2]=max(dp[i][2],dp[i-2][2]+A[i],dp[i-3][1]+A[i],dp[i-4][0]+A[i]) print(max(dp[N-1]))
def main(): N = int(input()) A = list(map(int, input().split())) a0, a1, a2, b0, b1, b2 = 0, 0, 0, 0, 0, 0 for i, a in enumerate(A): a0, a1, a2, b0, b1, b2 = ( b0, max(b1, a0), max(b2, a1), a0 + a, a1 + a if i >= 1 else a1, a2 + a if i >= 2 else a2) if N & 1: return max(b2, a1) else: return max(b1, a0) print(main())
1
37,229,839,219,670
null
177
177
n = int(input()) i = 0 list_n = [n] map_n = map(int, input().split()) list_n = list(map_n) for value in reversed(list_n): print(value, end ='') if value != list_n[0]: print(' ', end = '') print()
input() print(' '.join(input().split()[::-1]))
1
983,272,243,030
null
53
53
r, c = map(int, input().split()) matrix = [[0 for i in range(c+1)] for j in range(r+1)] for i in range(r): a = list(map(int, input().split())) for j in range(c): matrix[i][j] = a[j] matrix[i][c] = sum(a) for l in range(c+1): for m in range(r): matrix[r][l] += matrix[m][l] for cv in range(r+1): for fv in range(c+1): print(matrix[cv][fv], end='') if fv != c: print(" ", end='') print()
a, b = map(int, input().split()) al = [] b_lis = [] for _ in range(a): g = list(map(int, input().split())) g.append(sum(g)) al.append(g) for i in range(b+1): p = 0 for j in range(a): p += al[j][i] b_lis.append(p) al.append((b_lis)) for i in al: print(' '.join([str(v) for v in i]))
1
1,365,968,007,342
null
59
59
a,b = map(int,input().split()) if a >= 10: print(str(b)) else: print(str(b+100*(10-a)))
N,R=input().split() n,r=int(N),int(R) if n>=10: print(r) else: print(r+100*(10-n))
1
63,022,161,038,112
null
211
211
s = input().split() stack = [] for i in s: if i.isdigit(): stack.append(int(i)) else: if i == "+": f = lambda x, y: x + y elif i == "-": f = lambda x, y: x - y elif i == "*": f = lambda x, y: x * y y = stack.pop() x = stack.pop() stack.append(f(x, y)) print(stack[0])
s = input() ans = s + 'es' if s[-1]=='s' else s + 's' print(ans)
0
null
1,229,902,003,330
18
71
import numpy as np def main(): n,s=map(int,input().split()) A=list(map(int,input().split())) dp=np.array([0 for i in range(s+1)]) dp[0]=1 for ai in A: tmp=dp[:-ai].copy() #print(tmp) dp*=2 dp[ai:]+=tmp dp%=998244353 print(dp[s]) if __name__=="__main__": main()
import numpy as np mod = 998244353 n, s = map(int, input().split()) A = list(map(int, input().split())) DP = np.zeros(3005, dtype=np.int64) for num, a in enumerate(A): double = DP * 2 shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64) DP = double + shift DP[a] += pow(2, num, mod) DP %= mod print(DP[s])
1
17,654,915,241,438
null
138
138
input() s = input().split() input() t = input().split() cnt = 0 for t1 in t: for s1 in s: if t1 == s1: cnt += 1 break print(cnt)
def linear_search(A, n, key): A.append(key) i = 0 while A[i] != key: i += 1 A.pop() return i != n n = int(input()) S = list(map(int, input().split())) q = int(input()) T = list(map(int, input().split())) ans = 0 for t in T: if linear_search(S, n, t): ans += 1 print(ans)
1
71,352,730,528
null
22
22
N,u,v = map(int,input().split()) u -= 1 v -= 1 data = [[] for _ in range(N)] for i in range(N-1): A,B = map(int,input().split()) A -= 1 B -= 1 data[A].append(B) data[B].append(A) #print(data) stack = [[u,u]] taka_dis = [0] * N while stack: x = stack.pop() #print(x) for y in data[x[1]]: if y == x[0]: continue else: stack.append([x[1],y]) taka_dis[y] = taka_dis[x[1]] + 1 #print(stack) stack = [[v,v]] aoki_dis = [0] * N while stack: x = stack.pop() for y in data[x[1]]: if y == x[0]: continue else: stack.append([x[1],y]) aoki_dis[y] = aoki_dis[x[1]] + 1 can = [0] * N for i in range(N): if aoki_dis[i] - taka_dis[i] > 0: can[i] = aoki_dis[i] else: can[i] = 0 #print(aoki_dis) #print(taka_dis) #print(can) print(max(can) -1 )
n = int(input()) s = [] t = [] for i in range(n): s_, t_ = map(str, input().split()) s.append(s_) t.append(int(t_)) x = input() for i in range(n): if s[i] == x: break ans = 0 for j in range(n-1, i, -1): ans += t[j] print(ans)
0
null
107,346,706,432,618
259
243
import itertools N = int(input()) S = input() RGB = {"R":[0]*N, "G":[0]*N, "B":[0]*N} for i in range(N): if S[i] == "R": RGB["R"][i] = 1 elif S[i] == "G": RGB["G"][i] = 1 else: RGB["B"][i] = 1 for k in RGB.keys(): RGB[k] = list(itertools.accumulate(RGB[k])) ans = 0 for i in range(N-2): l_i = S[i] for j in range(i+1, N-1): l_j = S[j] d = {"R", "G", "B"} if l_i != l_j: d.remove(l_i) d.remove(l_j) l_k = d.pop() ans += RGB[l_k][N-1] - RGB[l_k][j] if j*2 - i <= N-1: if S[j*2 - i] == l_k: ans -= 1 print(ans)
n = int(input()) s = input() total = 1 for c in 'RGB': total *= s.count(c) for i in range(1, n - 1): for j in range(1, min(i + 1, n - i)): if s[i] != s[i - j] and s[i - j] != s[i + j] and s[i] != s[i + j]: total -= 1 print(total)
1
36,194,410,012,512
null
175
175
mh=[] for i in range(1,11): mh.append(int(input())) mh.sort(reverse=True) print(mh[0]) print(mh[1]) print(mh[2])
l, r, d = map(int, input().split()) num = 0 for i in range(r - l +1): if (i + l) / d == int((i + l) / d): num += 1 print(num)
0
null
3,822,045,871,780
2
104
N ,D = map(int , input().split()) sum = 0 for i in range(N): a,b = map(int , input().split()) if(((a ** 2 + b ** 2)**(1/2)) <= D): sum += 1 print(sum)
import sys STRING = "" for line in sys.stdin: STRING += line.lower() CHRS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',\ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] for i in CHRS: print("%s : %d" % (i, STRING.count(i)))
0
null
3,770,760,430,542
96
63
h = int(input()) w = int(input()) n = int(input()) print(int((n-1)/max(h, w))+1)
H = int(input()) W = int(input()) N = int(input()) X = max(H, W) print((N + X - 1) // X)
1
89,126,761,549,324
null
236
236
N = int(input()) A = [int(_) for _ in input().split()] A.sort(reverse=True) ans = 0 for i in range(N-1): ans += A[(i+1) // 2] print(ans)
import sys chash = {} for i in range( ord( 'a' ), ord( 'z' )+1 ): chash[ chr( i ) ] = 0 lines = sys.stdin.readlines() for i in range( len( lines ) ): for j in range( len( lines[i] ) ): if lines[i][j].isalpha(): chash[ lines[i][j].lower() ] += 1 for i in range( ord( 'a' ), ord( 'z' )+1 ): print( "{:s} : {:d}".format( chr( i ), chash[ chr( i ) ] ) )
0
null
5,373,990,978,262
111
63
N, K = map(int, input().split()) count = 1 while N >= K: N //= K count +=1 print(count)
N,M,X=[int(s) for s in input().split()] Book=[[int(s) for s in input().split()] for _ in range(N)] INF=10**7 ans=set() ans.add(INF) for n in range(2**N): #Bit全探索 Xls=[0 for i in range(M)] cost=0 for i in range(N): if ((n>>i)&1)==1: cost+=Book[i][0] for b in range(M): Xls[b]+=Book[i][b+1] if min(Xls)>=X: ans.add(cost) if min(ans)==INF: print(-1) else: print(min(ans))
0
null
43,358,298,206,118
212
149
n,k,s = map(int,input().split()) if s == 10**9: t = 1 else: t = s+1 ls = [t]*n for i in range(k): ls[i] = s print(*ls)
N = int(input()) A = list(map(int, input().split())) # number_to_prime[i]: i の最小の素因数, iが素数ならば0 number_to_prime = [0] * (10**6 + 1) # preprocess for i in range(2, 10**6+1): if not number_to_prime[i]: j = 1 while j*i <= 10**6: number_to_prime[j*i] = i j += 1 def is_pairwise(): used_primes = [False] * (10**6 + 1) pairwise_flag = 1 for a in A: curr_primes = set() while a > 1: prime = number_to_prime[a] while a % prime == 0: a //= prime if used_primes[prime]: return False used_primes[prime] = 1 return True def is_setwise(*A): import math from functools import reduce return reduce(math.gcd, A) == 1 if is_pairwise(): print("pairwise coprime") elif is_setwise(*A): print("setwise coprime") else: print("not coprime")
0
null
47,358,585,945,920
238
85
a, b = input().split() print(a * int(b) if a < b else b * int(a))
from collections import deque n = int(input()) q = deque() for _ in range(n): com = input() if com[0] == "i": q.appendleft(com[7:]) elif len(com) == 11: q.popleft() elif len(com) == 10: q.pop() else: try: q.remove(com[7:]) except: pass print(*q)
0
null
42,087,658,529,300
232
20
#import sys #import numpy as np import math #from fractions import Fraction import itertools from collections import deque from collections import Counter import heapq #from fractions import gcd #input=sys.stdin.readline import bisect n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) ar=[0]*(n+1) br=[0]*(m+1) ans=0 for i in range(n): ar[i+1]=ar[i]+a[i] for i in range(m): br[i+1]=br[i]+b[i] for i in range(m+1): sup=k-br[i] if sup<0: break res=bisect.bisect_right(ar,sup)+i-1 ans=max(res,ans) print(ans)
n, m, k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) As = [0] * (n + 1) Bs = [0] * (m + 1) for i in range(n): As[i + 1] = A[i] + As[i] for i in range(m): Bs[i + 1] = B[i] + Bs[i] l = 0 r = n + m + 1 while r - l > 1: p = (l + r) // 2 best = min( As[i] + Bs[p - i] for i in range(p + 1) if min(i, n) + min(p - i, m) == p ) if best <= k: l = p else: r = p print(l)
1
10,749,534,618,382
null
117
117
import math N = int(input()) a = list(map(int,input().split())) m = max(a) c = [0] * (m+1) for i in a: c[i] += 1 pairwise = True for i in range(2, m+1, 1): cnt = 0 for j in range(i, m+1, i): cnt += c[j] if cnt > 1: pairwise = False break if pairwise: print("pairwise coprime") exit() g = 0 for i in range(N): g = math.gcd(g, a[i]) if g == 1: print("setwise coprime") exit() print("not coprime")
N = int(input()) As = list(map(int, input().split())) sum = 0 for i in range(N): sum += As[i] sum %= 10**9+7 ans = 0 for i in range(N): sum -= As[i] ans += As[i]*sum ans %= 10**9+7 print(ans)
0
null
4,005,357,905,020
85
83
n=int(input()) a=list(map(int,input().split())) import numpy as np x = np.argsort(a) for i in range(n): print(x[i]+1)
N = int(input()) for i in range(50000): if N <= i*1.08 < N + 1: print(i) break else: print(":(")
0
null
153,324,535,102,132
299
265
n,d = map(int, input().split()) x = [] y = [] for i in range(n): a,b = map(int, input().split()) x.append(a) y.append(b) count = 0 for i in range(n): if (x[i]**2 + y[i]**2)**(1/ 2) <= d: count += 1 print(count)
import math def main(): n, d = map(int, input().split()) ans = 0 for _ in range(n): x, y = map(int, input().split()) ans += 1 if math.sqrt(x**2 + y**2) <= d else 0 print(ans) if __name__ == '__main__': main()
1
5,941,049,183,750
null
96
96
d=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split()))for _ in range(d)] class Score: def __init__(self,t): self.x=[d*[0]for _ in range(26)] self.scor=0 self.ans=[] for i in range(d): v=t[i] self.scor+=s[i][v] for j in range(26): if j!=v: self.x[j][i]+=1 if i!=0:self.x[j][i]+=self.x[j][i-1] self.scor-=c[j]*self.x[j][i] self.ans.append(self.scor) def solve(self): return [self.scor,self.ans] t=[int(input())-1 for _ in range(d)] x=Score(t) _,ans=x.solve() for i in ans:print(i)
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)] SUM = 0 last = [0] * 28 for d in range(1, D + 1): i = T[d - 1] SUM += S[d - 1][i - 1] SU = 0 last[i] = d for j in range(1, 27): SU += (c[j - 1] * (d - last[j])) SUM -= SU print(SUM)
1
9,966,434,172,900
null
114
114
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(input()) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=' '): print(k.join(list(map(str, lst)))) INF = float('inf') # from math import ceil, floor, log2 # from collections import deque # from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush # import numpy as np # cumsum # from bisect import bisect_left, bisect_right def solve(): S = list(map(int, LS())) S = S[::-1] ln = len(S) mod = 2019 times = 1 for i in range(ln): S[i] = S[i] * times times = times * 10 % mod R = [0] * (ln+1) memo = {0: 1} ans = 0 for i in range(1, ln+1): tmp = (R[i-1] + S[i-1]) % mod R[i] = tmp cnt = memo.get(tmp, 0) ans = ans + cnt memo[tmp] = cnt + 1 print(ans) if __name__ == '__main__': solve()
A, B, K = map(int, input().split()) if A >= K: print(str(A - K) + ' ' + str(B)) else: print(str(0) + ' ' + str(max((B - (K - A)), 0)))
0
null
67,183,671,590,532
166
249
n = int(raw_input()) ai_list = map(int, raw_input().split()) max_ai = max(ai_list) min_ai = min(ai_list) sum_ai = sum(ai_list) print '%d %d %d' % (min_ai, max_ai, sum_ai)
# -*- coding:utf-8 -*- import sys data = [] count = 0 for i in sys.stdin: data.append(int(i)) count = count+1 if count == 10: break N = len(data) m = 100 for i in range(m): for n in range(N-1): a = data[n] b = data[n+1] if a <= b: data[n] = b data[n+1] = a else: pass for i in range(3): print(data[i])
0
null
354,748,972,226
48
2
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') L, R, d = MI() ans = 0 for i in range(L, R + 1): if i % d == 0: ans += 1 print(ans)
#!/usr/bin/env python3 l, r, d = map(int, input().split()) n = (l-1) // d + 1 m = r // d print(m-n+1)
1
7,537,167,396,650
null
104
104
def insertion_sort(a, n, g, cnt): for i in range(g,n,1): v = a[i] j = i - g #initial value while j>=0 and a[j]>v: a[j+g]=a[j] j -= g cnt += 1 a[j+g] = v return a, cnt def shell_sort(a,n,m,g): cnt = 0 for i in range(m): sorted_list, cnt = insertion_sort(a,n,g[i],cnt) return sorted_list, cnt def seqforshell(n): seq = [1] next_num = 3*seq[0] + 1 while next_num<n: seq.insert(0, next_num) next_num = 3*next_num + 1 return seq if __name__ == "__main__": a = [] n = int(input()) for i in range(n): a.append(int(input())) g = seqforshell(n) m = len(g) res, cnt = shell_sort(a,n,m,g) print(m) print(*g) print(cnt) for i in range(n): print(res[i])
print('Yes' if '7' in input() else 'No')
0
null
17,179,877,748,080
17
172
a, b, c = map(int, input().split()) k = int(input()) flg = False c = (2**k) * c for i in range(k): if a < b < c: flg = True break b *= 2 c //= 2 if flg: print('Yes') else: print('No')
a, b = [int(temp) for temp in input().split()] print(a // b, a % b, '%.5f' % (a / b))
0
null
3,804,548,389,028
101
45
from collections import deque s = input() Q = int(input()) l = deque() l.append(s) rev = True for i in range(Q): q = list(input().split()) if q[0] == "1": rev = not rev else: if rev: if q[1] == "1": l.appendleft(q[2]) else: l.append(q[2]) else: if q[1] == "1": l.append(q[2]) else: l.appendleft(q[2]) ans = "" for i in l: ans += i if not rev: print(ans[::-1]) else: print(ans)
from sys import stdin from collections import defaultdict as dd from collections import deque as dq import itertools as it from math import sqrt, log, log2 from fractions import Fraction # t = int(stdin.readline()) # for _ in range(t): # n, m = map(int, stdin.readline().split()) # nums = list(map(int, stdin.readline().split())) # n = int(input()) # if n%10 in [2, 4, 5, 7, 9]: # print('hon') # elif n%10 in [0, 1, 6, 8]: # print('pon') # else: # print('bon') k = int(input()) s = input() ans = s[:k] + ('...' if len(s) > k else '') print(ans)
0
null
38,600,039,764,120
204
143
N= int(input()) S = input() abc = "ABC" ans = 0 j = 0 for i in range(N): if S[i] == abc[j]: j += 1 if S[i] == "C": j = 0 ans += 1 elif S[i] == "A": j = 1 else: j = 0 print(ans)
import sys N = int(input()) S = input() array_S = list(S) if not ( 3 <= N <= 50 and S.isupper() ): sys.exit() count = 0 for I in range(N-2): if ''.join(array_S[I:I+3]) == 'ABC': count += 1 print(count)
1
99,031,743,073,450
null
245
245
from decimal import Decimal T = tuple(map(Decimal, input().split())) A = list(map(Decimal, input().split())) B = list(map(Decimal, input().split())) ans = 0 if A[0] < B[0]: tmp = (A[0], A[1]) A[0], A[1] = B[0], B[1] B[0], B[1] = tmp[0], tmp[1] a = abs(T[0]*A[0] - T[0]*B[0]) b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1]) if b == 0: print("infinity") elif b < 0: print(0) exit(0) else: ans += 1 if b > a: print(1) elif b == a: print("infinity") else: if a % b == 0: print((a//b)*2) else: print((a//b)*2 + 1)
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e n = int(input()) A = list(map(int, input().split())) MOD = 1000000007 counts = [0, 0, 0] result = 1 for i in range(n): a = A[i] # print(a, counts, result) cnt = counts.count(a) result *= cnt result %= MOD for j in range(len(counts)): if counts[j] == a: counts[j] += 1 break print(result)
0
null
130,396,432,166,208
269
268
n=int(input()) s=0 ok=0 for i in range(n): lis=input().split() if lis[0]==lis[1]: s+=1 if s>=3: ok=1 else: s=0 if ok==1: print("Yes") else: print("No")
h, n = map(int, input().split()) a, b = [], [] for _ in range(n): A, B = map(int, input().split()) a.append(A) b.append(B) a_max = max(a) dp = [0]*(h+a_max) for i in range(h+a_max): dp[i] = min(dp[i-a] + b for a, b in zip(a, b)) print(min(dp[h-1:]))
0
null
41,837,087,747,362
72
229
#! python3 a, b = [int(x) for x in input().strip().split(' ')] if a > b: print('a > b') elif a < b: print('a < b') else: print('a == b')
a, b = [int(x) for x in raw_input().split(" ")] if a > b: print("a > b") elif a < b: print("a < b") else: print("a == b")
1
363,906,755,212
null
38
38
import math n = float(raw_input()) a = n * n * math.pi b = 2 * n * math.pi print ('%.6f %.6f' % (a, b))
numbers = [int(i) for i in input().split()] D, S, T = numbers[0], numbers[1], numbers[2] if D <= S*T: print("Yes") else: print("No")
0
null
2,074,710,280,192
46
81
if __name__ == '__main__': n = int(input()) a = list(map(lambda x: int(x) + 1, input().split())) counts = [0] * (n + 1) counts[0] = 3 ans = 1 for i in range(n): ans *= counts[a[i] - 1] ans %= (10 ** 9 + 7) counts[a[i] - 1] -= 1 counts[a[i]] += 1 print(ans)
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) A = list(map(int, input().split())) res = 1 cnt = [3 if i == 0 else 0 for i in range(n + 1)] for a in A: res = res * cnt[a] % mod cnt[a] -= 1 cnt[a + 1] += 1 print(res) if __name__ == '__main__': resolve()
1
130,104,443,738,100
null
268
268
n=int(input()) l=[['a1']]+[[] for _ in range(9)] for i in range(9): for b in l[i]: t=b[-1] for p in range(int(t)): l[i+1].append(b[:-1]+chr(97+p)+t) l[i+1].append(b[:-1]+chr(97+int(t))+str(int(t)+1)) for i in l[n-1]: if len(i)==12: print(i[:-2]) else: print(i[:-1])
N = int(input()) count = 0 count += int(N/2) if int(N/2)-N/2 == 0: for i in range(1,int(N/2)): if int(N/i)-N/i == 0: count += int(N/i)-1 else: count += int(N/i) else: for i in range(1,int(N/2)+1): if int(N/i)-N/i == 0: count += int(N/i)-1 else: count += int(N/i) print(count)
0
null
27,392,922,827,144
198
73
R,C,K=map(int,input().split()) point=[[0]*C for _ in range(R)] for _ in range(K): r,c,v=map(int,input().split()) point[r-1][c-1]=v dp=[[[0]*C for _ in range(R)] for _ in range(4)] dp[1][0][0]=point[0][0] for i in range(R): for j in range(C-1): for k in range(4): dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) if k!=0: dp[k][i][j+1]=max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1]) if i==R-1: break for j in range(C): mx=0 for k in range(4): mx=max(dp[k][i][j],mx) dp[0][i+1][j]=mx dp[1][i+1][j]=mx+point[i+1][j] ans=0 for i in range(4): ans=max(ans,dp[i][R-1][C-1]) print(ans)
D = int(input()) C = list(map(int, input().split())) S = [list(map(int, input().split())) for _ in range(D)] import copy MAX_SCORE = -float('inf') MAX_ANS = -1 for K in range(26): v = 0 ans = [0]*D L = [0]*26 for i in range(1, D+1): max_score = -float('inf') max_idx = 0 for j in range(26): temp = v temp += S[i-1][j] L_ = copy.copy(L) L_[j] = i for k in range(26): for l in range(i, min(i+K+1, D+1)): temp -= C[k]*(l-L_[k]) if temp >= max_score: max_score = temp max_idx = j v += S[i-1][max_idx] L[max_idx] = i for k in range(26): v -= C[k]*(i-L[k]) ans[i-1] = max_idx+1 if v >= MAX_SCORE: MAX_SCORE = v MAX_ANS = ans print(*MAX_ANS, sep='\n')
0
null
7,689,783,701,600
94
113
print('ACL'*int(input()))
N=int(input()) print("ACL"*N)
1
2,196,157,620,172
null
69
69
import sys from collections import deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines in_n = lambda: int(readline()) in_nn = lambda: map(int, readline().split()) in_s = lambda: readline().rstrip().decode('utf-8') in_nl = lambda: list(map(int, readline().split())) in_nl2 = lambda H: [in_nl() for _ in range(H)] in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')] in_map2 = lambda H: [in_map() for _ in range(H)] in_all = lambda: map(int, read().split()) def bfs(N, v0, edge): search = [-1] * N search[v0] = 0 q = deque() q.append(v0) while q: v = q.popleft() for nv in edge[v]: if search[nv] == -1: q.append(nv) search[nv] = search[v] + 1 return search def bfs2(N, v0, edge, dis): q = deque() q.append(v0) max_dis = dis[v0] while q: v = q.popleft() for nv in edge[v]: if dis[v] < dis[nv]: q.append(nv) max_dis = max(max_dis, dis[nv]) return max_dis def main(): N, taka, aoki = in_nn() taka, aoki = taka - 1, aoki - 1 edge = [[] for _ in range(N)] for i in range(N - 1): x, y = in_nn() x, y = x - 1, y - 1 edge[x].append(y) edge[y].append(x) dis = bfs(N, aoki, edge) if dis[taka] > 2: x = (dis[taka] + 1) // 2 - 1 for _ in range(x): for v in edge[taka]: if dis[v] < dis[taka]: taka = v break ans = bfs2(N, taka, edge, dis) - 1 print(ans) if __name__ == '__main__': main()
N, u, v = map(int, input().split()) u, v = u-1, v-1 ABs = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)] #%% roots = [[] for _ in range(N)] for AB in ABs: roots[AB[0]].append(AB[1]) roots[AB[1]].append(AB[0]) #BFS def BFS(roots, start): from collections import deque seen = [-1 for _ in range(N)] seen[start] = 0 todo = deque([start]) while len(todo) > 0: checking = todo.pop() for root in roots[checking]: if seen[root] == -1: seen[root] = seen[checking] +1 todo.append(root) return seen from_u = BFS(roots, u) from_v = BFS(roots, v) from collections import deque todo = deque([u]) max_distance = from_v[u] position = u seen = [False for _ in range(N)] seen[u] = True while len(todo) > 0: checking = todo.pop() for root in roots[checking]: if from_u[root] < from_v[root] and seen[root] == False: seen[root] = True todo.append(root) if max_distance < from_v[root]: max_distance = from_v[root] position = root print(max_distance-1)
1
117,918,516,928,538
null
259
259
import sys N = int(input()); A = list(map(int,input().split())) if N == 2: print(max(A)) sys.exit() dp = [0,max(A[:3]),A[0]+A[2]] tmp1 = dp[:] tmp2 = [0,max(A[:2]),0] flag1 = False flag2 = True if A[0] < A[2] and A[1] < A[2] else False flag3 = False for i in range(3,N): b = A[i] if i%2 == 0: dp[0] = max(tmp2[0],tmp1[0]+b) flag1 = True if tmp2[0] < tmp1[0]+b else False if flag3: dp[1] = max(tmp2[1],tmp1[1]+b) flag2 = True if tmp2[1] < tmp1[1]+b else False else: dp[1] = max(tmp2[1],tmp2[0]+b,tmp1[1]+b) flag2 = True if tmp2[1] < tmp2[0]+b or tmp2[1] < tmp1[1]+b else False dp[2] += A[i] tmp1 = dp[:] else: if flag1: dp[0] = max(tmp1[1],tmp2[0]+b) flag3 = True if tmp1[1] < tmp2[0]+b else False else: dp[0] = max(tmp1[1],tmp1[0]+b,tmp2[0]+b) flag3 = True if tmp1[1] < tmp1[0]+b or tmp1[1] < tmp2[0]+b else False if flag2: dp[1] = max(tmp1[2],tmp2[1]+b) else: dp[1] = max(tmp1[2],tmp1[1]+b,tmp2[1]+b) tmp2 = dp[:] print (dp[1])
#!/usr/bin/env python3 # coding: utf-8 import collections import math def debug(arg): if __debug__: pass else: import sys print(arg, file=sys.stderr) def main(): pass N, *A = map(int, open(0).read().split()) a = dict(enumerate(A, 1)) dp = collections.defaultdict(lambda: -float("inf")) dp[0, 0] = 0 dp[1, 0] = 0 dp[1, 1] = a[1] for i in range(2, N + 1): jj = range(max(math.floor(i // 2 - 1), 1), math.ceil((i + 1) // 2) + 1) for j in jj: x = dp[i - 2, j - 1] + a[i] y = dp[i - 1, j] dp[i, j] = max(x, y) print(dp[N, N // 2]) if __name__ == "__main__": main()
1
37,310,114,362,992
null
177
177
#!/usr/bin/env python3 import sys from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import Fraction # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10) def main(): mod = 1000000007 # 10^9+7 inf = float('inf') # sys.float_info.max = 1.79e+308 # inf = 2 ** 63 - 1 # (for fast JIT compile in PyPy) 9.22e+18 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def isp(): return input().split() def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) L = list(map(int, reversed(li()))) n = len(L) payment = L[:] payment.append(0) ans = 0 carry = False for i in range(n): if 5 < payment[i] or (5 == payment[i] and 5 <= payment[i+1]): ans += 9 - L[i] if carry else 10 - L[i] payment[i] = 0 payment[i+1] += 1 carry = True else: carry = False # print(L) # print(list(reversed(payment))) ans += sum(payment) # ans = 0 # ans += sum(payment) # a = int(''.join(list(map(str, reversed(L))))) # b = int(''.join(list(map(str, reversed(payment))))) # # print(f"required {a}, paid: {b}") # ans += sum(map(int, list(str(b - a)))) print(ans) if __name__ == "__main__": main()
import math n = int(input()) x_buf = input().split() y_buf = input().split() x = [] y = [] for i in range(n): x.append(int(x_buf[i])) y.append(int(y_buf[i])) sum1 = 0 sum2 = 0 sum3 = 0 sum_inf = 0 max_inf = 0 for i in range(n): sum1 += abs(x[i] - y[i]) sum2 += abs(x[i] - y[i]) ** 2 sum3 += abs(x[i] - y[i]) ** 3 sum_inf = abs(x[i] - y[i]) if max_inf < sum_inf: max_inf = sum_inf d1 = sum1 d2 = math.sqrt(sum2) d3 = sum3 ** (1/3) d4 = max_inf print(d1) print(d2) print(d3) print(d4)
0
null
35,357,549,800,708
219
32
#!python3 iim = lambda: map(int, input().rstrip().split()) def resolve(): n, m = iim() C = list(iim()) dp = [n] * (n + 1) dp[0] = 0 for co in C: for i in range(co, n+1): dp[i] = min(dp[i], dp[i-co] + 1) print(dp[n]) if __name__ == "__main__": resolve()
n, m = map(int, input().split()) c = list(map(int, input().split())) dp = [float('inf') for _ in range(n + 10001)] dp[0] = 0 for i in range(n): for j in c: dp[i + j] = min(dp[i + j], dp[i] + 1) print(dp[n])
1
134,491,761,150
null
28
28
n = input() A = map(int, raw_input().split()) print "%d %d %d" %(min(A), max(A), sum(A))
S,T = open(0).read().split() ls = len(S) lt = len(T) ans = float('inf') for i in range(ls-lt+1): temp = S[i:i+lt] t2 = 0 for j in range(lt): if temp[j] != T[j]: t2 += 1 ans = min(ans,t2) print(ans)
0
null
2,179,842,363,340
48
82
N = int(input()) S = list(map(int, input().split())) Q = int(input()) T = list(map(int, input().split())) C = 0 for i in range(Q): if T[i] in S: C+=1 print(C)
cnt = 0 n = int(input()) a = list(map(int,input().split())) for i in range(0,n): mini = i for j in range(i,n): if a[j]<a[mini]: mini = j a[i],a[mini] = a[mini],a[i] if i!=mini: cnt += 1 print(" ".join(map(str,a))) print(cnt)
0
null
43,365,295,948
22
15
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from bisect import bisect_right, bisect_left import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor, gamma, log from operator import mul from functools import reduce from copy import deepcopy sys.setrecursionlimit(2147483647) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 n = I() def make_divisors(n): divisors = set() for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.add(i) divisors.add(n // i) return divisors # sortしたリストで欲しい時はsorted(divisors) ret = 0 a = make_divisors(n) for k in a: if k == 1: continue m = n while m % k == 0: m //= k if m % k == 1: ret += 1 s = make_divisors(n - 1) s.discard(1) print(ret + len(s))
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors N = int(input()) ans = len(make_divisors(N-1))-1 for i in make_divisors(N): if i == 1: continue Ni = int(N/i) while Ni % i == 0: Ni = int(Ni/i) if Ni % i == 1: ans+=1 print(ans)
1
41,220,798,042,380
null
183
183