code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from itertools import permutations, accumulate, combinations, combinations_with_replacement from math import sqrt, ceil, floor, factorial from bisect import bisect_left, bisect_right, insort_left, insort_right from copy import deepcopy from operator import itemgetter from functools import reduce, lru_cache # @lru_cache(None) from fractions import gcd import sys def input(): return sys.stdin.readline().rstrip() def I(): return int(input()) def Is(): return (int(x) for x in input().split()) def LI(): return list(Is()) def TI(): return tuple(Is()) def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def TIR(n): return [TI() for _ in range(n)] def S(): return input() def Ss(): return input().split() def LS(): return list(S()) def SR(n): return [S() for _ in range(n)] def SsR(n): return [Ss() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] sys.setrecursionlimit(10**6) MOD = 10**9+7 INF = 10**18 # ----------------------------------------------------------- # n, a, b = Is() if (a + b) % 2 == 0: print((b-a)//2) else: print(min(n-b, a-1)+1+(b-a-1)//2)
i = raw_input() N, A, B = i.split() N = int(N) A = int(A) B = int(B) if abs(A-B)%2 == 0: print int(abs(A-B)/2) else: e = int(min(A-1, N-B)) d = (B-A+1) // 2 print e + d
1
109,544,922,490,908
null
253
253
ans = [] for i, x in enumerate(open(0).readlines()): ans.append("Case %d: %s" % (i+1, x)) open(1,'w').writelines(ans[:-1])
i = 0 x = int(input()) while x != 0: i += 1 print("Case ", i, ": ", x, sep="") x = int(input())
1
479,785,393,808
null
42
42
n = int(input()) a = ord("a") def dfs(s, mx): if len(s) == n: print(s) else: for i in range(a, mx + 2): if i != mx + 1: dfs(s + chr(i), mx) else: dfs(s + chr(i), mx + 1) dfs("a", a)
import math c = math.cos(math.radians(60)) s = math.sin(math.radians(60)) def koch(d,p1,p2): if d == 0: return sx = (2 * p1[0] + p2[0]) / 3 sy = (2 * p1[1] + p2[1]) / 3 tx = (p1[0] + p2[0] * 2) / 3 ty = (p1[1] + p2[1] * 2) / 3 dx = tx - sx dy = ty - sy ux = dx * c - dy * s + sx uy = dx * s + dy * c + sy koch(d-1,p1,(sx,sy)) print("{0:.8f} {1:.8f}".format(sx,sy)) koch(d-1,(sx,sy),(ux,uy)) print("{0:.8f} {1:.8f}".format(ux,uy)) koch(d-1,(ux,uy),(tx,ty)) print("{0:.8f} {1:.8f}".format(tx,ty)) koch(d-1,(tx,ty),p2) n = int(input()) print("{0:.8f} {1:.8f}".format(0,0)) koch(n,(0,0),(100,0)) print("{0:.8f} {1:.8f}".format(100,0))
0
null
26,274,190,149,442
198
27
import math import string import collections from collections import Counter from collections import deque from decimal import Decimal import sys import fractions from operator import itemgetter import itertools def readints(): return list(map(int, input().split())) def nCr(n, r): return math.factorial(n)//(math.factorial(n-r)*math.factorial(r)) def has_duplicates2(seq): seen = [] for item in seq: if not(item in seen): seen.append(item) return len(seq) != len(seen) def divisor(n): divisor = [] for i in range(1, n+1): if n % i == 0: divisor.append(i) return divisor # coordinates dx = [-1, -1, -1, 0, 0, 1, 1, 1] dy = [-1, 0, 1, -1, 1, -1, 0, 1] n = int(input()) d = readints() x = (list(itertools.combinations(d, 2))) ans = 0 for i in range(len(x)): ans += x[i][0]*x[i][1] print(ans)
n = int(input()) lst = list(map(int, input().split())) res = 0 for i in range(n - 1): for j in range(i + 1, n): res += (lst[i] * lst[j]) print(res)
1
168,614,276,475,500
null
292
292
import sys N = input() for i in range ( len ( N )): if '7' == N[i] : print("Yes") sys.exit() print("No")
# A Lucky 7 N = input() for n in N: if n == "7": print("Yes") exit() else: print("No")
1
34,185,592,261,938
null
172
172
n = int(input()) data = [input().split() for i in range(n)] for i in range(n - 2): if int(data[i][0]) == int(data[i][1]) and int(data[i + 1][0]) == int(data[i+1][1]) and int(data[i+2][0]) == int(data[i+2][1]): print('Yes') break else: print('No')
N = int(input()) A = [list(map(int, input().split())) for _ in range(N)] for i in range(N - 2): if all(x == y for (x, y) in A[i:i+3]): print('Yes') break else: print('No')
1
2,492,403,290,148
null
72
72
def main(): n, x, y = map(int, input().split()) ans = [0] * n for i in range(1,n): for j in range(i+1, n+1): r1 = j-i r2 = abs(x-i) + 1 + abs(j-y) r3 = abs(y-i) + 1 + abs(j-x) ans[min(r1,r2,r3)] += 1 for i in range(1,n): print(ans[i]) if __name__ == "__main__": main()
N, M=map(int, input().split()) mat = [[0 for m in range(M)]for n in range(N)] vec = [0 for m in range(M)] for n in range(N): mat[n] = list(map(int , input().split())) for m in range(M): vec[m] = int(input()) c = 0 for n in range(N): for m in range(M): c += mat[n][m] * vec[m] print(c) c = 0
0
null
22,709,616,614,568
187
56
n = int(input()) s = input() h = int(n/2) s=list(s) if s[0:h] == s[h:n]: print("Yes") else: print("No")
N = int(input()) S = input() print('Yes' if (N % 2 == 0) and (S[:N // 2] == S[N // 2:]) else 'No')
1
146,405,007,111,888
null
279
279
i = 1 while True: x = input() if int(x) == 0: break else: print('Case', str(i)+':', x) i += 1
n,q = map(int,input().split()) name = [] time = [] for i in range(n): tmp = input().split() name.append(str(tmp[0])) time.append(int(tmp[1])) total = 0 result = [] while True: try: if time[0] > q: total += q time[0] = time[0] - q tmp = time.pop(0) time.append(tmp) tmp = name.pop(0) name.append(tmp) elif q >= time[0] and time[0] > 0: total += time[0] time.pop(0) a = name.pop(0) print(a,total) else: break except: break
0
null
266,446,006,048
42
19
r = int(input()) pi = 3.14159265359 print(r*2*pi)
n = int(input()) ans = 0 for i in range(1, n + 1): j = i while j <= n: ans += j j += i print(ans)
0
null
21,318,783,204,770
167
118
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def main(): N, K = map(int, input().split()) ans = N % K ans = min(ans, abs(ans - K)) print(ans) if __name__ == '__main__': main()
N = int(input()) An = list(map(int, input().split())) money = 1000 stock = 0 for i in range(N-1): if An[i+1] > An[i]: stock = money // An[i] money += (An[i+1] - An[i]) * stock print(money)
0
null
23,119,005,227,082
180
103
n = int(input()) x = list(map(int, input().split())) ans = 2000000000 for i in range(1,101): sum = 0 for j in x: sum += (i-j)**2 ans = min(sum, ans) print(ans)
n = int(input()) x = list(map(int,input().split())) x.sort() ans = 9999999999999999 for p in range(x[0],x[n-1]+1): tmp = 0 for j in range(n): tmp += (x[j] - p) ** 2 ans = min(tmp,ans) print(ans)
1
65,064,087,060,228
null
213
213
from collections import Counter def aprime_factorize(n: int) -> list: return_list = [] while n % 2 == 0: return_list.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: return_list.append(f) n //= f else: f += 2 if n != 1: return_list.append(n) return return_list judge = [] cnt = 0 while len(judge) <= 40: for i in range(cnt+1): judge.append(cnt) cnt += 1 N = int(input()) list = Counter(aprime_factorize(N)).most_common() res = 0 for i, li in enumerate(list): res += judge[li[1]] print(res)
def prime_factor(n): ass=[] for i in range(2,int(n**0.5)+1): while n%i==0:ass.append(i);n//=i if n!=1:ass.append(n) return ass n = int(input()) ans = 0 pf = prime_factor(n) from collections import Counter c = Counter(pf) for i in c.keys(): v = c[i] for j in range(1, 10**20): if j>v: break ans += 1 v -= j print(ans)
1
16,849,817,297,432
null
136
136
def sell(rate,kabu): money = rate * kabu return money def buy(rate,money): kabu = money//rate otsuri = money % rate return kabu,otsuri N,*A = map(int,open(0).read().split()) max_money = 1000 have_money = 1000 have_kabu = 0 for i in range(N-1): if A[i] < A[i+1] and have_money > A[i]: #買う have_kabu,have_money = buy(A[i],have_money) if A[i] > A[i+1]: #売る have_money += sell(A[i],have_kabu) have_kabu = 0 max_money = max(max_money,have_money) have_money += sell(A[-1],have_kabu) max_money = max(max_money,have_money) print(max_money)
N = int(input()) A = list(map(int,input().split())) LEFT = A[0] RIGHT = sum(A[1:]) MIN = abs(LEFT-RIGHT) for i in range(1,N-1): LEFT += A[i] RIGHT -= A[i] MIN = min(MIN,abs(LEFT-RIGHT)) print(MIN)
0
null
75,043,535,079,790
103
276
n=int(input()) ans=10**12 d=2 while d<=n**(1/2): if n%d==0: ans=min(ans,d+n//d-2) d+=1 if ans==10**12: print(n-1) exit() print(ans)
import math N = int(input()) ans = N - 1 #初期値、√Nの中に答えがなかったときはこれ t = int(math.ceil(N**0.5)) for i in range(1,t+1): j = N / i if N % i == 0: step = i + j -2 if step < ans: ans = int(step) print(ans)
1
160,857,180,038,478
null
288
288
n,m = map(int, input().split()) c=0 if n>1 : c+=n*(n-1) //2 if m>1 : c+=m*(m-1) //2 print(c)
a, b = list(map(int, input().split())) my_result = a * (a - 1) + b * (b - 1) print(int(my_result / 2))
1
45,397,940,496,480
null
189
189
import math a = int(input()) print(a+pow(a,2)+pow(a,3))
N = int(input()) print(N+N*N+N*N*N)
1
10,280,200,983,392
null
115
115
# Take both input K & S, then compare the length of S with K and assign it to length # If the length is <= K print all # And if length is >K print some of the character K = int(input()) S = input() x = 0 length = len(S) if length <= K: print(S) else: while x < K: print(S[x], end=("")) x += 1 print("...")
import numpy as np n = int(input()) a = list(map(int,input().split())) a = np.array(a, dtype='int64') MOD = 10**9+7 ans = 0 for i in range(60): ca = a >> i & 1 c1 = int(ca.sum()) c0 = n - c1 c0c1 = (c0 * c1) % MOD c0c1pow = (c0c1 * 2**i) % MOD ans = (ans + c0c1pow) % MOD print(ans)
0
null
70,949,584,167,782
143
263
N, K = map(int, input().split()) H = list(map(int, input().split())) if N <= K: print(0) exit() H.sort(reverse=True) print(sum(H[K:]))
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if a <= b: print('YNEOS'[a+v*t < b+w*t::2]) else: print('YNEOS'[a-v*t > b-w*t::2])
0
null
46,854,404,960,070
227
131
#!/usr/bin/python3 # -*- coding:utf-8 -*- import numpy def main(): _, _, k = map(int, input().strip().split()) la = numpy.cumsum([0] + list(map(int, input().strip().split()))) lb = numpy.cumsum([0] + list(map(int, input().strip().split())) + [10**9+5]) def bs(x): s, t = 0, len(lb) - 1 while t > s + 1: m = (s + t) // 2 if lb[m] == x: return m if lb[m] > x: t = m else: s = m return s ans = 0 for i, a in enumerate(la): if k - a >= 0: ans = max(ans, i + bs((k - a))) print(ans) if __name__=='__main__': main()
from itertools import accumulate n,m,k = map(int,input().split()) deskA = list(map(int,input().split())) deskB = list(map(int,input().split())) cumA = list(accumulate(deskA)) cumB = list(accumulate(deskB)) cumA = [0] + cumA cumB = [0] + cumB ans = 0 l = m for i in range(n+1): tmp = k - cumA[i] if tmp<0: continue j = l tmp -= cumB[j] while tmp < 0: tmp += cumB[j] j -= 1 tmp -= cumB[j] l = j ans = max(i+j,ans) print(ans)
1
10,712,537,403,932
null
117
117
def insertion_sort(array, g): cnt = 0 for i in range(g,len(array)): key = array[i] j = i - g while j >= 0 and array[j] > key: array[j+g] = array[j] j -= g cnt += 1 array[j+g] = key return cnt def shell_sort(array, ga): cnt = 0 for g in ga: cnt += insertion_sort(array, g) return cnt def print_array(array): print(str(array)[1:-1].replace(', ', ' ')) def main(): N = int(input()) array = [int(input()) for i in range(N)] # ga = [i for i in reversed(range(N)) if i % 3 == 1] ga = [] v = 1 while v <= N: ga.append(v) v = v * 3 + 1 ga.reverse() cnt = shell_sort(array, ga) print(len(ga)) print_array(ga) print(cnt) for v in array: print(v) if __name__ == '__main__': main()
#!python3 import sys from collections import defaultdict from math import gcd iim = lambda: map(int, input().rstrip().split()) def resolve(): N = input() it = map(int, sys.stdin.read().split()) mod = 10**9 + 7 d1 = [defaultdict(int), defaultdict(int)] z0 = 0 for ai, bi in zip(it, it): if ai == 0 and bi == 0: z0 += 1 continue ci = gcd(ai, bi) ai, bi = ai // ci, bi // ci t = ai * bi < 0 if ai < 0: ai, bi = -ai ,-bi elif ai == 0: bi = -1 t = 1 d1[t][(ai, bi)] += 1 a1, a2 = d1 ans = 1 z1 = 0 for (ai, bi), v in a1.items(): k2 = (bi, -ai) if k2 in a2: v2 = a2[k2] ans *= pow(2, v, mod) + pow(2, v2, mod) - 1 ans %= mod else: z1 += v for (ai, bi), v in a2.items(): k2 = (-bi, ai) if k2 in a1: continue z1 += v ans *= pow(2, z1, mod) print((ans-1+z0) % mod) if __name__ == "__main__": resolve()
0
null
10,595,847,637,060
17
146
n,m=map(int,input().split()) d={} ind=[0]*n for i in range(n): d[i+1]='*' for j in range(m): s,c=map(int,input().split()) if ind[s-1]==0: d[s]=c ind[s-1]=1 else: if d[s]!=c: print(-1) exit(0) ans='' if n>=2: if d[1]==0: print(-1) exit(0) for k in range(n): if k==0: if n>=2: if d[k+1]=='*': ans+='1' else: ans+=str(d[k+1]) else: if d[k+1]=='*': ans+='0' else: ans+=str(d[k+1]) else: if d[k+1]=='*': ans+='0' else: ans+=str(d[k+1]) print(ans)
if __name__ == '__main__': N, M = map(int, input().split()) S = [] C = [] for i in range(M): s, c = map(int, input().split()) s -= 1 S.append(s) C.append(c) for num in range(0, pow(10, N)): st_num = str(num) if len(str(st_num))!=N: continue cnt = 0 for m in range(M): if int(st_num[S[m]])==C[m]: cnt += 1 if cnt==M: print(st_num) quit() print(-1)
1
60,710,589,161,072
null
208
208
N = int(input()) s_list = [] t_list = [] for i in range(N): s,t=input().split() s_list.append(s) t_list.append(int(t)) X = input() flag = 0 time = 0 for i, x in enumerate(s_list): if x == X: flag = 1 elif flag == 1: time += t_list[i] print(time)
n,m,q = map(int,input().split()) A = [0]*q B = [0]*q C = [0]*q D = [0]*q for i in range(q): a,b,c,d = map(int,input().split()) A[i] = a B[i] = b C[i] = c D[i] = d walist = [] for i in range(2**(n+m-1)): if bin(i).count("1") == n: wa = 0 seq = [] value = 1 for j in range(n+m-1): if (i>>j)&1 == 1: seq += [value] else: value += 1 for k in range(q): if seq[B[k]-1] - seq[A[k]-1] == C[k]: wa += D[k] walist += [wa] print(max(walist))
0
null
62,295,621,306,438
243
160
pai = 3.141592653589793 r = float(input()) s = pai * r ** 2 l = 2 * pai * r print(s, l)
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall # from decimal import Decimal # from collections import defaultdict, deque sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) MOD = 10 ** 9 + 7 INF = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() ans = 0 for x in range(1, N + 1): n = N // x # Nのうちにxがいくつ含まれるか(等差数列の項数) ans += (n * (2 * x + (n - 1) * x)) // 2 # 初項と公差がxでn項の等差数列の和 print(ans) if __name__ == '__main__': main()
0
null
5,805,490,046,658
46
118
def main(): n = [x for x in input().split(' ')] s = [] for i in n: if i == '+': a = s.pop() b = s.pop() s.append(a + b) elif i == '-': b = s.pop() a = s.pop() s.append(a - b) elif i == '*': a = s.pop() b = s.pop() s.append(a * b) else: s.append(int(i)) print(s.pop()) if __name__ == '__main__': main()
import sys Stack = [] MAX = 1000 def push(x): #if isFull(): # print "ERROR!" # sys.exit() Stack.append(x) def pop(): #if isEmpty(): # print "ERROR!" # sys.exit() Stack.pop(-1) def cul(exp): for v in exp: if v == "+": x = reduce(lambda a,b:int(a)+int(b), Stack[-2:]) for i in range(2): pop() push(x) elif v == "-": x = reduce(lambda a,b:int(a)-int(b), Stack[-2:]) for i in range(2): pop() push(x) elif v == "*": x = reduce(lambda a,b:int(a)*int(b), Stack[-2:]) for i in range(2): pop() push(x) else: push(v) return Stack[0] if __name__ == "__main__": exp = sys.stdin.read().strip().split(" ") ans = cul(exp) print ans
1
36,535,651,570
null
18
18
n,m=map(int, input().split()) alist=[list(map(int, input().split())) for i in range(m)] ans=-1 if n==1: for i in range(9,-1,-1): x=True stri=str(i) for j in range(m): if stri[alist[j][0]-1]!=str(alist[j][1]): x=False if x: ans=i else: for i in range(10**n-1,10**(n-1)-1,-1): x=True stri=str(i) for j in range(m): if stri[alist[j][0]-1]!=str(alist[j][1]): x=False if x: ans=i print(ans)
import sys def main(): input = sys.stdin.buffer.readline n, m = map(int, input().split()) num = [0] * n reserved = [False] * n for _ in range(m): s, c = map(int, input().split()) s -= 1 if reserved[s]: if c != num[s]: print(-1) sys.exit() else: reserved[s] = True num[s] = c if n > 1 and not reserved[0]: num[0] = 1 if n > 1 and num[0] == 0: print(-1) else: print("".join(map(str, num))) if __name__ == "__main__": main()
1
60,774,824,611,282
null
208
208
cnt = 0 def merge(A,left,mid,right): '''n1 = mid - left n2 = right - mid L = [] R = [] for i in range(0,n1): L.append(A[left+i]) for i in range(0,n2): R.append(A[mid+i]) L.append(1000000001) R.append(1000000001) ''' L = A[left:mid]+[1000000001] R = A[mid:right]+[1000000001] i = 0 j = 0 global cnt for k in range(left,right): cnt += 1 if L[i] <= R[j]: A[k]=L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A,left,right): if left+1 < right: mid = (left+right)//2 mergeSort(A,left,mid) mergeSort(A,mid,right) merge(A,left,mid,right) if __name__ == '__main__': n = (int)(input()) a = list(map(int,input().split())) mergeSort(a,0,n) print(*a) print(cnt)
N = int(input()) d = {} for i in range(N): key = input() try: d[key] += 1 except KeyError: d[key] = 1 d = sorted(d.items(), key=lambda x: x[1], reverse=True) ans = [] max = 0 for i in d: if i[1] >= max: ans.append(i[0]) max = i[1] else: break for i in sorted(ans): print(i)
0
null
35,038,191,164,282
26
218
import copy a = [int(c) for c in input().split()] K = a[0] N = a[1] A = [int(c) for c in input().split()] B = list(map(lambda x: x+K,copy.deepcopy(A))) A = A+B l = 0 tmp = 0 cnt = 0 for i in range(N): tmp = A[i+1]-A[i] if tmp > l : cnt = i l = tmp print(K-l)
n = 0 while n == 0: m = map(int,raw_input().split()) if m[0] + m[1] + m[2] == -3: break if m[0] == -1 or m[1] == -1: print "F" else: for i in xrange(2): if m[i] == -1: m[i] = 0 k = m[0] + m[1] if k >= 80: print "A" elif k >= 65: print "B" elif k >= 50: print "C" elif k >= 30: if m[2] >= 50: print "C" else: print "D" elif k < 30: print "F"
0
null
22,399,168,935,418
186
57
n = int(input()) result = "" for s in range(1, n+1): if s % 3 == 0: result += " "+str(s) else: for i in str(s): if i == "3": result += " "+str(s) break print(result)
N=int(input()) A=list(map(int,input().split())) count=0 for i in range(len(A)): if A[i]%2==0: if A[i]%3==0 or A[i]%5==0: count+=1 else: count+=1 if count==len(A): print("APPROVED") else: print("DENIED")
0
null
34,965,450,205,632
52
217
N = int(input()) kuku = [] for x in range(1,10): for y in range(1,10): kuku.append(x*y) if N in kuku: print('Yes') else: print('No')
# coding:utf-8 array = map(int, raw_input().split()) n = array[0] m = array[1] a = [[0 for i in range(m)] for j in range(n)] b = [0 for i in range(m)] answer = [0 for i in range(n)] for i in range(n): a[i] = map(int, raw_input().split()) for j in range(m): b[j] = input() for i in range(n): for j in range(m): answer[i] += a[i][j] * b[j] for i in range(n): print answer[i]
0
null
80,136,384,030,934
287
56
def main(): N = int(input()) S = input() print(S.count("ABC")) if __name__ == "__main__": main()
w,h,x,y,r=map(int,input().split()) print(['No','Yes'][r<=x<=w-r and r<=y<=h-r])
0
null
49,638,571,809,552
245
41
n, k = map(int, input().split()) w = [] for i in range(n): w.append(int(input())) def check(p): i = 0 for _ in range(k): wight = 0 while wight+w[i] <= p: wight += w[i] i += 1 if i == n: return n return i if __name__ == '__main__': left = 0 right = 100000 * 10000 mid = 0 while right - left > 1: mid = (left+right)//2 v = check(mid) if v >= n: right = mid else: left = mid print(right)
# coding: utf-8 import string d = {} for ch in list(string.ascii_lowercase): d[ch] = 0 while True: try: s = list(input().lower()) except EOFError: break for ch in s: if ch.isalpha(): d[ch] += 1 else: pass for k, v in sorted(d.items()): print('{} : {}'.format(k, v))
0
null
892,089,563,648
24
63
import sys input = sys.stdin.readline N=int(input()) L=list(map(int,input().split())) Q=int(input()) R=[0]*(10**5) for i in L: R[i-1]+=1 ans=sum(L) for i in range(Q): a,b=map(int,input().split()) R[b-1]+=R[a-1] ans+=(b-a)*R[a-1] R[a-1]=0 print(ans)
N = int(input()) A = list(map(int,input().split())) Q = int(input()) C = (10**5+1)*[0] T = sum(A) for a in A: C[a]+=1 for q in range(Q): b,c = map(int,input().split()) T+=C[b]*(c-b) C[c]+=C[b] C[b]=0 print(T)
1
12,275,068,749,540
null
122
122
N = int(input()) S = input() cnt = 0 post_c = '' for i in range(len(S)): if post_c != S[i]: post_c = S[i] cnt += 1 print(cnt)
n,k=map(int,input().split()) a=sorted(list(map(int,input().split()))) mod=10**9+7 ans=0 MOD=10**9+7 factorial = [1] inverse = [1] for i in range(1, n+2): factorial.append(factorial[-1] * i % MOD) inverse.append(pow(factorial[-1], MOD - 2, MOD)) # 組み合わせ計算 def nCr(n, r): if n < r or r < 0: return 0 elif r == 0: return 1 return factorial[n] * inverse[r] * inverse[n - r] % MOD for i in range(n-k+1): ans-=a[i]*nCr(n-i-1,k-1)%mod ans%=mod a=a[::-1] for i in range(n-k+1): ans+=a[i]*nCr(n-i-1,k-1)%mod ans%=mod print(ans%mod)
0
null
132,774,608,698,300
293
242
n = int(input()) def koch(n,x1,y1,x2,y2): if n == 0: print(x1,y1) else: a = 3**(1/2)/2 p1 = koch(n-1,x1,y1,(2*x1+x2)/3,(2*y1+y2)/3) if abs(y1 - y2) <= 10**(-4): s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,(x1+x2)/2,y1+(x2-x1)*a/3) u = koch(n-1,(x1+x2)/2,y1+(x2-x1)*a/3,(x1+2*x2)/3,(y1+2*y2)/3) else: if x1 < x2 and y1 < y2: s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x1,(y1+2*y2)/3) u = koch(n-1,x1,(y1+2*y2)/3,(x1+2*x2)/3,(y1+2*y2)/3) elif x1 < x2 and y1 > y2: s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x2,(2*y1+y2)/3) u = koch(n-1,x2,(2*y1+y2)/3,(x1+2*x2)/3,(y1+2*y2)/3) elif x1 > x2 and y1 < y2: s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x2,(2*y1+y2)/3) u = koch(n-1,x2,(2*y1+y2)/3,(x1+2*x2)/3,(y1+2*y2)/3) else: s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x1,(y1+2*y2)/3) u = koch(n-1,x1,(y1+2*y2)/3,(x1+2*x2)/3,(y1+2*y2)/3) t = koch(n-1,(x1+2*x2)/3,(y1+2*y2)/3,x2,y2) return p1,s,u,t X = koch(n,0,0,100,0) print(100,0)
import math def make_stu(p1, p2): s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3] t = [(p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3] u = [s[0] + (t[0] - s[0]) / 2 - math.sqrt(3) * (t[1] - s[1]) / 2, s[1] + (t[1] - s[1]) / 2 + math.sqrt(3) * (t[0] - s[0]) / 2] return s, t, u def koch_curve(n, p1, p2): if n >= 1: s, t, u = make_stu(p1, p2) if n == 1: print(s[0], s[1]) print(u[0], u[1]) print(t[0], t[1]) else: koch_curve(n - 1, p1, s) print(s[0], s[1]) koch_curve(n - 1, s, u) print(u[0], u[1]) koch_curve(n - 1, u, t) print(t[0], t[1]) koch_curve(n - 1, t, p2) n = int(input()) print(0.0, 0.0) koch_curve(n, [0.0, 0.0], [100.0, 0.0]) print(100.0, 0.0)
1
130,294,786,934
null
27
27
def f(x): return x * (x - 1) // 2 n = int(input()) a = list(map(int, input().split())) counter = [0] * n for ai in a: ai -= 1 counter[ai] += 1 m = 0 for c in counter: m += f(c) for i, ai in enumerate(a): ai -= 1 c = counter[ai] if c == 0: print(m) else: print(m - f(c) + f(c - 1))
import collections N=int(input()) A=list(map(int,input().split())) c=collections.Counter(A) s=0 def f(n): return n*(n-1)//2 for i in c: c[i]=(f(c[i]),(f(c[i]-1))) s+=c[i][0] for j in A: print(s-c[j][0]+c[j][1])
1
47,785,921,993,172
null
192
192
from math import pi r = float(input()) print '%.6f %.6f'%(r**2*pi, r*2*pi)
import math r = [float(x) for x in input().split()] print("{0:f} {1:f}".format(r[0] * r[0] * math.pi, r[0] * 2 * math.pi))
1
624,712,604,570
null
46
46
n, m = map(int, input().split()) ac = [0] * n wa = [0] * n for _ in range(m): p, s = input().split() if s == 'AC': ac[int(p) - 1] = 1 elif ac[int(p) - 1] == 0: wa[int(p) - 1] += 1 for i in range(n): if ac[i] == 0: wa[i] = 0 print(sum(ac), sum(wa))
N,K = map(int,input().split()) # from scipy.special import comb # a = comb(n, r) MOD = 10**9 + 7 ans = 0 for k in range(K,N+2): # print(k) right = (N+N-k+1)*k // 2 left = (k-1)*k // 2 ans += right - left + 1 ans %= MOD # print(ans) # ans += comb(N+1, k, exact=True) # print(ans) print(ans)
0
null
63,270,412,393,980
240
170
n, k = map(int,input().split()) p = list(map(int,input().split())) p_sort = sorted(p) p_sum = sum(p_sort[0:k]) print(p_sum)
import sys import math import fractions from collections import defaultdict import bisect stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) N,M=nm() A=nl() A.sort() S=[0] S[0]=A[0] for i in range(1,N): S.append(S[i-1]+A[i]) def clc_shake(x):#x以上の和 tot=0 for i in range(N): th=x-A[i] inds=bisect.bisect_left(A,th) tot+=(N-inds) return tot l=0 r=2*(10**6) c=0 while (l+1<r): c=(l+r)//2 if(clc_shake(c)<M): r=c else: l=c ans=0 for i in range(N): th=r-A[i] inds=bisect.bisect_left(A,th) if(inds!=0): ans+=((N-inds)*A[i]+(S[N-1]-S[inds-1])) else: ans+=((N-inds)*A[i]+(S[N-1])) M2=M-clc_shake(r) ans+=M2*(l) print(ans)
0
null
60,111,017,514,750
120
252
N = int(input()) S = [] for _ in range(N): S.append(input()) import sys from collections import Counter count_dict = Counter(S) most_freq = count_dict.most_common(1)[0][1] words = [] for word, freq in sorted(count_dict.items(), key=lambda x: -x[1]): if freq == most_freq: words.append(word) for word in sorted(words): print(word)
from sys import stdin,stdout def INPUT():return list(int(i) for i in stdin.readline().split()) import math def inp():return stdin.readline() def out(x):return stdout.write(x) import math as M MOD=10**9+7 import sys ##################################### a,b=INPUT() if a>=2*b: print(a-2*b) else: print(0)
0
null
118,913,122,690,340
218
291
import math a,b,c=map(int,input().split()) s=a/2*b*math.sin(math.radians(c)) l=a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(c))) h=b*math.sin(math.radians(c)) print('{:.5f}\n{:.5f}\n{:.5f}'.format(s,l,h))
while True: num = input() if(num == "0"): break ret = 0 for i in num: ret += int(i) print(ret)
0
null
866,037,005,964
30
62
inputStr = input() numList = inputStr.split(' ') numList = [int(x) for x in numList] #print('a: ',numList[0]) #print('b: ',numList[1]) if numList[0]==numList[1]: print('a == b') elif numList[0]>numList[1]: print('a > b') elif numList[0]<numList[1]: print('a < b')
a,b=map(int,input().split()) print('a','<'if a<b else'>'if a>b else'==','b')
1
345,896,771,660
null
38
38
n, k = map(int, input().split()) xs = [i for i in range(1, k + 1)] xs.reverse() dict_x = {} mod = 10 ** 9 + 7 def pow(x, y): global mod a = 1 b = x c = y while c > 0: if c & 1: a = (a * b) % mod b = (b * b) % mod c = c >> 1 return a answer = 0 for x in xs: num = k // x a = pow(num, n) # print(a) s = 2 while x * s <= k: a -= dict_x[x * s] s += 1 dict_x[x] = a answer = (answer + a * x) % mod print(answer)
#!/usr/bin/env python3 import sys sys.setrecursionlimit(300000) MOD = 1000000007 # type: int def solve(N: int, K: int): ret = 0 counts = [0] * (K + 1) for i in range(1, K + 1)[::-1]: c = K // i cnt = pow(c, N, MOD) j = 2 while i * j <= K: cnt -= counts[i * j] j += 1 ret += cnt * i ret %= MOD counts[i] = cnt #print(counts) print(ret) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int solve(N, K) if __name__ == '__main__': main()
1
36,764,327,012,390
null
176
176
W = input() num = 0 while True: line = input() if line == 'END_OF_TEXT': break for word in line.split(): if word.lower() == W.lower(): num += 1 print(num)
n=int(input()) a=list(map(int,input().split())) j=1 for i in a: if j==i:j+=1 print([n-j+1,-1][j==1])
0
null
58,243,538,797,752
65
257
def find_ways(n, x): number_list = [i+1 for i in range(n)] cnt = 0 for j in number_list: if j > n-2: break for k in number_list: if k <= j: continue l = x - j - k if l > n or l <= k: continue else: cnt += 1 return cnt while True: data = list(map(int, list(input().split()))) if data[0] == 0 and data[1] == 0: break else: comb = find_ways(data[0], data[1]) print(comb)
while True: n,x = map(int,input().split(" ")) if n == 0 and x == 0: break #データリスト作成 data = [m for m in range(1,n+1)] data_list = [] cnt = 0 #n種類の数字があって、xになる組み合わせは? for i in range(1,n+1): for j in range(1+i,n+1): for k in range(1+j,n+1): if i+j+k == x: cnt += 1 print(cnt)
1
1,281,086,539,360
null
58
58
import numpy as np import numba i4 = numba.int32 @numba.njit((i4, i4[:], i4[:, :], i4[:]), cache=True) def solve(dd, c_arr, s_arr, t_arr): last_d = np.zeros(26, dtype=np.int32) - 1 score = 0 score_arr = np.zeros(dd, dtype=np.int32) for d in range(dd): score += s_arr[d, t_arr[d] - 1] last_d[t_arr[d] - 1] = d score -= (c_arr * (d - last_d)).sum() score_arr[d] = score return score_arr def main(): d = np.int32(input()) c_arr = np.array(list(map(int, input().split()))).astype(np.int32) s_arr = np.array([list(map(int, input().split())) for _ in range(d)]).astype(np.int32) t_arr = np.array([int(input()) for _ in range(d)]).astype(np.int32) res = solve(d, c_arr, s_arr, t_arr) for r in res: print(r) if __name__ == "__main__": main()
import sys def gcd(a,b): while a % b != 0: a, b = b, a % b return b def lcm(a,b,g): _a = a // g _b = b // g return _a * _b * g def run(): data = [] for n in sys.stdin: a, b = list(map(int, n.split())) data.append((a,b)) for _data in data: a, b = _data g = gcd(a,b) l = lcm(a,b,g) print(g, l) if __name__ == '__main__': run()
0
null
5,004,989,068,352
114
5
N = int(input()) % 10 print('hon' if N in [2, 4, 5, 7, 9] else 'pon' if N in [0, 1, 6, 8] else 'bon')
n = input()[-1] if n in '24579': print('hon') elif n in '0168': print('pon') else: print('bon')
1
19,229,587,596,192
null
142
142
# coding: utf-8 # Here your code ! W, H , x ,y ,r = list(map(int, input().split())) t1_x = x + r t1_y = y + r t2_x = x - r t2_y = y - r if 0 <= t1_x <= W and 0 <= t1_y <= H and 0 <= t2_x <= W and 0 <= t2_y <= H: print("Yes") else: print("No")
W, H, x, y, r = map(int, input().split()) if x == 0 or y == 0 or x < 0 or y < 0: print("No") elif W == x or H == y: print("No") elif W < x or H < y: print("No") elif W < x+r or H < y+r: print("No") else: print("Yes")
1
462,735,584,542
null
41
41
while True: score = [int(i) for i in input().split()] if score == [-1, -1, -1]: break sum = score[0] + score[1] if sum < 30 or score[0] == -1 or score[1] == -1: print('F') elif sum < 50 and score[2] < 50: print('D') elif sum < 65 or (sum < 65 and score[2] >= 50): print('C') elif sum < 80: print('B') elif sum >= 80: print('A')
while True: m, f, r = map(int,input().split()) if m == -1 and f == -1 and r == -1: break if m == -1 or f == -1: print("F") elif m + f >= 80: print("A") elif 65 <= m + f < 80: print("B") elif 50 <= m + f < 65: print("C") elif r >= 50: print("C") elif 30 <= m + f < 50: print("D") elif r >= 50: print("C") else : print("F")
1
1,217,040,354,272
null
57
57
# C from collections import Counter N = int(input()) S = [input() for _ in range(N)] counter = Counter(S) print(len(counter.keys()))
def check(p): global k, wlist loadage = 0 num = 1 for w in wlist: loadage += w if loadage > p: num += 1 if num > k: return False loadage = w return True n, k = map(int, input().split()) wlist = [] for _ in range(n): wlist.append(int(input())) maxw = max(wlist) sumw = sum(wlist) p = 0 while maxw < sumw: p = (maxw + sumw) // 2 if check(p): sumw = p else: maxw = p = p+1 print(p)
0
null
15,086,635,937,110
165
24
S=input() if S[-1] == 's': print(S+"es") else: print(S+"s")
#!/usr/bin/env python # -*- coding: utf-8 -*- # # FileName: B # CreatedDate: 2020-06-27 15:34:06 +0900 # LastModified: 2020-06-27 15:35:45 +0900 # import os import sys # import numpy as np # import pandas as pd def main(): h, n = map(int, input().split()) a = list(map(int, input().split())) if sum(a)>=h: print("Yes") else: print("No") if __name__ == "__main__": main()
0
null
39,964,511,965,910
71
226
n = int(input()) res = [i for i in range(3, n+1) if (i % 3 == 0) or ("3" in str(i))] print(" ",end="") print(*res)
numbers = raw_input() input_numbers = raw_input().split() print(" ".join(input_numbers[::-1]))
0
null
972,742,220,618
52
53
s = input() k = int(input()) tmp = 1 count = 0 for i in range(len(s)-1): if s[i] == s[i+1]: tmp += 1 else: count += tmp // 2 tmp = 1 count += tmp//2 if len(set(s))==1: print(len(s)*k//2) else: if s[0] != s[-1]: print(count*k) else: h = 0 for i in s: if i != s[0]: break else: h += 1 t = 0 for i in s[::-1]: if i != s[-1]: break else: t += 1 print(count*k-(h//2+t//2-(h+t)//2)*(k-1))
while True: H, W = map(int, input().split()) if not(H or W): break for i in range(H): print('#', end='') for j in range(W-2): if i > 0 and i < H - 1: print('.', end='') else: print('#', end='') print('#') print()
0
null
87,990,801,082,786
296
50
n = int(input()) a_nums = list(map(int, input().split())) money = 1000 stock = 0 for i in range(n): if i != n - 1 and a_nums[i] < a_nums[i + 1]: times = money // a_nums[i] stock += times money -= a_nums[i] * times elif i == n - 1 or a_nums[i] > a_nums[i + 1]: money += stock * a_nums[i] stock = 0 print(money)
N = int(input()) A = list(map(int, input().split())) ans = 1000 for i in range(N-1): if A[i] < A[i+1]: temp = ans // A[i] ans -= temp*A[i] ans += temp*A[i+1] print(ans)
1
7,429,746,389,100
null
103
103
from collections import Counter n=int(input()) a=list(map(int,input().split())) dic=Counter(a) for val in dic.values(): if val>=2: print("NO") exit() print("YES")
N = int(input()) A = list(map(int, input().split())) s=set() for i in range(N): s.add(A[i]) if len(s)==N: print("YES") else: print("NO")
1
73,842,709,912,368
null
222
222
import math class Point: def __init__(self, num_x, num_y): self.x = num_x self.y = num_y def kock(n, p1, p2): if n == 0: return s = Point(0, 0) t = Point(0, 0) u = Point(0, 0) s.x = (2 * p1.x + p2.x) / 3.0 s.y = (2 * p1.y + p2.y) / 3.0 t.x = (p1.x + p2.x * 2) / 3.0 t.y = (p1.y + p2.y * 2) / 3.0 u.x = (t.x - s.x) * math.cos(math.pi / 3) - (t.y - s.y) * math.sin(math.pi / 3) + s.x u.y = (t.x - s.x) * math.sin(math.pi / 3) + (t.y - s.y) * math.cos(math.pi / 3) + s.y kock(n - 1, p1, s) print "%.8f %.8f" % (s.x, s.y) kock(n - 1, s, u) print "%.8f %.8f" % (u.x, u.y) kock(n - 1, u, t) print "%.8f %.8f" % (t.x, t.y) kock(n - 1, t, p2) n = input() p1 = Point(0, 0) p2 = Point(100, 0) print "%.8f %.8f" % (p1.x, p1.y) kock(n, p1, p2) print "%.8f %.8f" % (p2.x, p2.y)
X = int(input()) q,mod = divmod(X,100) if 5*q<mod: print(0) else: print(1)
0
null
63,516,787,114,372
27
266
X,Y,Z = map(int,input().split()) A,B,C = X,Y,Z A,B = B,A A,C = C,A print('{} {} {}'.format(A,B,C))
a,b,c=input().split() if(a==b)+(b==c)+(c==a)==1: print('Yes') else: print('No')
0
null
53,035,817,616,512
178
216
K = int(input()) S = input() print(S[:K]+(K<len(S))*"...")
s1 = '' try: while True: t = input() if t == '': break s1 += t except EOFError: pass n = [0] * 26 s = s1.lower() for i in range(len(s)): j = ord(s[i]) - 97 if j >= 0 and j < 26: n[j] += 1 for i in range(26): print('%s : %d' %(chr(i + 97),n[i]))
0
null
10,675,923,940,018
143
63
l=map(str,raw_input().split()) chk=[] op='-+*' while len(l): k=l.pop(0) if k in op: b=chk.pop() a=chk.pop() chk.append(str(eval(a+k+b))) else: chk.append(k) print chk[0]
X = int(input()) a = X // 500 * 1000 b = X % 500 // 5 * 5 print(a + b)
0
null
21,435,708,084,512
18
185
from collections import deque K = int(input()) queue = deque([9, 8, 7, 6, 5, 4, 3, 2, 1]) count = 0 while queue: number = queue.pop() count += 1 if count == K: print(number) break last_number = int(str(number)[-1]) add_center = number * 10 + last_number if last_number > 0: queue.appendleft(add_center - 1) queue.appendleft(add_center) if last_number < 9: queue.appendleft(add_center + 1)
def main(): a,b,c=map(int,input().split()) k = int(input()) for i in range(k): if a < b < c: break elif a >= b: b *= 2 elif b >= c: c *= 2 if a < b < c: print('Yes') else: print('No') main()
0
null
23,554,949,387,880
181
101
import sys import math def MI(): return map(int,sys.stdin.readline().rstrip().split()) N,X,M = MI() if M == 1: print(0) exit() flag = [-1]*M Z = [X] flag[X] = 1 r = X for i in range(2,M+2): r = r ** 2 r %= M if flag[r] != -1: a,b = flag[r],i # [a,b) = 循環節 break else: flag[r] = i Z.append(r) z = len(Z) ans = 0 for i in range(a-1): ans += Z[i] n = N-a+1 q = n//(b-a) r = n % (b-a) for i in range(a-1,a+r-1): ans += (q+1)*Z[i] for i in range(a+r-1,b-1): ans += q*Z[i] print(ans)
N = int(input()) ptn = [[0 for _ in range(10)] for __ in range(10)] for num in range(1, N+1): str_num = str(num) if str_num[-1] != 0: ptn[int(str_num[0])][int(str_num[-1])] += 1 answer = 0 for i in range(10): for j in range(i, 10): if i == j: answer += ptn[i][j]**2 else: answer += ptn[i][j]*ptn[j][i]*2 print(answer)
0
null
44,714,626,188,320
75
234
while True: h, w = map(int, raw_input().split()) if h == 0 and w == 0: break print(("#" * w + "\n") + ("#" + "." * (w-2) + "#" + "\n") * (h-2) + ("#" * w + "\n"))
import math while True: n = int(input()) if n == 0: break arr = list(map(int, input().split())) m = sum(arr) / n t = 0 for i in range(n): t += math.pow(arr[i] - m, 2) a = math.sqrt(t/n) print("{0:5f}".format(a))
0
null
509,917,634,068
50
31
# (c) midandfeed q = [] for i in range(4): b = [] for j in range(3): a = [0 for x in range(10)] b.append(a) q.append(b) t = int(input()) for _ in range(t): b, f, r, v = [int(x) for x in input().split()] q[b-1][f-1][r-1] += v a = 0 for x in q: a += 1 for y in x: for z in range(len(y)): print(" {}".format(y[z]), end='') if (z==(len(y))-1): print() if (a!=4): print("#"*20)
ryou = [0]*4 for i in range(4): ryou[i] = [0]*3 for i in range(4): for j in range(3): ryou[i][j] = [0]*10 sep = '#' * 20 n = int(input()) for i in range(n): b, f, r, v = [int(x) for x in input().split()] ryou[b-1][f-1][r-1] += v for i in range(4): for j in range(3): s = ' ' s += ' '.join(map(str,ryou[i][j])) print(s) if not i == 3: print(sep)
1
1,106,002,588,032
null
55
55
N = int(input()) music = [] for i in range(N): music.append(input().split()) X = (input()) Time = 0 kama = False for s,t in music: if kama: Time += int(t) if s == X: kama = True print(Time)
import math def koch(start,end,n): if n==0: return else: point1=[0,0] point2=[0,0] point3=[0,0] point1[0]=(end[0]-start[0])/3 +start[0] point1[1]=(end[1]-start[1])/3 +start[1] point3[0]=(end[0]-start[0])*2/3+start[0] point3[1]=(end[1]-start[1])*2/3+start[1] rad60 = math.radians(60) point2[0]=(point3[0]-point1[0])* math.cos(rad60) -(point3[1]-point1[1])*math.sin(rad60) +point1[0] point2[1]=(point3[0]-point1[0])* math.sin(rad60) +(point3[1]-point1[1])*math.cos(rad60) +point1[1] koch(start,point1,n-1) print(*point1) koch(point1,point2,n-1) print(*point2) koch(point2,point3,n-1) print(*point3) koch(point3,end,n-1) n=int(input()) start=[0,0] end=[100,0] print(*start) if n>0: koch(start,end,n) print(*end)
0
null
48,614,413,776,192
243
27
from sys import stdin r, c = [int(x) for x in stdin.readline().rstrip().split()] table = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(r)] for row in range(r): table[row] += [sum(table[row])] print(*table[row]) col_sum = [sum(x) for x in zip(*table)] print(*col_sum)
n = str(input()) x = 0 for i in range(3): if n[i] == '7': x += 1; if x == 0: print('No'); else: print('Yes');
0
null
17,947,328,101,780
59
172
import numpy as np D = int(input()) C = np.array(list(map(int, input().split()))) S = [] for i in range(D): s = list(map(int, input().split())) S.append(s) S = np.array(S) T = [int(input()) for _ in range(D)] last = np.zeros(26, dtype=np.int64) def decrease(d, last): res = np.sum(C * (d - last)) # print(d, res, C * (d - last)) return res manzoku = 0 # kaisai = dict() # print(S, T, C) for day, t in enumerate(T): t -= 1 manzoku += S[day, t] # d 日目にタイプi のコンテストを開催した場合、満足度が S[d,i]増加することが予め分かっています。 last[t] = day + 1 manzoku -= decrease(day + 1, last) print(manzoku)
n=int(input()) a=list(map(int,input().split())) m=max(a) b=[0] b*=m for i in range(n): b[a[i]-1]+=1 c=[] for i in range(m): if b[i]>=2: c.append(int(b[i]*(b[i]-1)/2)) else: c.append(0) d=sum(c) for i in range(n): if c[a[i]-1]>=1: e=c[a[i]-1]-int((b[a[i]-1]-1)*(b[a[i]-1]-2)/2) print(d-e) else: print(d)
0
null
28,875,107,363,900
114
192
i = 1 a = input() while a != 0: print "Case %d: %d" % (i, a) i = i + 1 a = input()
i = 1 while True: x = int(raw_input()) if x == 0: break else: print "Case %d: %d" % (i, x) i += 1
1
485,513,127,800
null
42
42
h, w, k = map(int, input().split()) s = [] for _ in range(h): s.append(input()) sum = [[0] * (w+1) for _ in range(h+1)] for i in range(h): for j in range(w): sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (1 if s[i][j] == '1' else 0) ans = h + w - 2 for ptn in range(1<<h-1): cand = 0 sep = [0] for i in range(h-1): if((ptn >> i) & 1): sep.append(i+1) cand += 1 sep.append(h) left = 0 for pos in range(w): cur = [] for i in range(len(sep)-1): cur.append(sum[sep[i+1]][pos+1] - sum[sep[i+1]][left] - sum[sep[i]][pos+1] + sum[sep[i]][left]) if max(cur) > k: if left == pos: cand = h * w break else: cand += 1 left = pos ans = cand if cand < ans else ans print(ans)
input = raw_input() for i in xrange(len(input)): # print "i = " + str(i) + ", input[i] = " + input[i] if input[i].islower(): input = input[:i] + input[i].upper() + input[i + 1:] elif input[i].isupper(): input = input[:i] + input[i].lower() + input[i + 1:] print input
0
null
25,126,780,969,542
193
61
sum = 1 input() for i in map(int,input().split()): sum|=sum<<i input() for j in map(int,input().split()): print(['no','yes'][(sum>>j)&1])
def main(): a = map(int, input().split(" ")) print("bust" if sum(a) >= 22 else "win") main()
0
null
59,681,014,153,310
25
260
import decimal as d a,b=input().split() print(int(int(a)*d.Decimal(b)))
import bisect n=int(input()) l=sorted(list(map(int,input().split()))) ans=0 for i in range(n-1): for j in range(i+1,n): index=bisect.bisect_left(l,l[i]+l[j]) if j<index: ans+=index-j-1 print(ans)
0
null
94,116,611,985,352
135
294
data = input().split() operator = ["+", "*", "-"] stack = [] for x in data: if x in operator: a = stack.pop() b = stack.pop() stack.append(str(eval(b + x + a))) else: stack.append(x) print(stack[0])
class Stack: # ???????????????????????§??????top??????????????????????????????Max???isFull??¨????????????stack???????????????????????§??? def __init__(self): self.top = 0 self.Max = 100 self.stack = [None] def isEmpty(self): return self.top == 0 def isFull(self): return self.top >= self.Max def push(self, x): if self.isFull(): print("Stack overflow!") else: self.top += 1 self.stack.append(x) def pop(self): if self.isEmpty(): print("Stack underflow!") else: self.top -= 1 return self.stack.pop() d_e = input().split() accumlator = Stack() for i in d_e: if i in "+-*": post_op = accumlator.pop() pre_op = accumlator.pop() ans = eval(pre_op + i + post_op) accumlator.push(str(ans)) else: accumlator.push(i) print(int(accumlator.pop()))
1
36,417,757,280
null
18
18
#coding:utf-8 #1_5_B 2015.4.1 while True: length,width = map(int,input().split()) if length == width == 0: break print('#' * width) print(('#' + '.' * (width - 2) + '#\n') * (length - 2),end='') print('#' * width) print()
while True: line = list(map(int,input().split())) if line==[0,0]: break for i in range(line[0]): if i==0 or i==line[0]-1: print('#'*line[1]) else: print('#'+'.'*(line[1]-2)+'#') print()
1
819,892,310,630
null
50
50
a,b,k = map(int,input().split()) if a < k: k -= a a = 0 else : a -= k k = 0 if b < k: b = 0 k = 0 else : b -= k k = 0 print(str(a)+ " " + str(b))
x=int(input()) n=x//500 m=x%500//5 ans=1000*n+5*m print(ans)
0
null
73,922,544,967,258
249
185
list = input().split() stack = [] for i in list: if ( i.isdigit() ): stack.append(int(i)) elif (i == '+'): stack.append(stack.pop() + stack.pop()) elif (i == '*'): stack.append(stack.pop() * stack.pop()) elif (i == '-'): stack.append( (-1)*stack.pop() + stack.pop()) print(stack.pop())
#coding:utf-8 while True: try: a, b = map(int, raw_input(). split()) x = a * b while True: c = a % b a = b b = c if b == 0: break x = x / a print("%d %d" % (a, x)) except: break
0
null
19,579,306,374
18
5
N=int(input()) S=list(input()) S.insert(0,0) R=S.count("R") G=S.count("G") B=S.count("B") ans=R*G*B for i in range(1,N-1): for j in range(i+1,N): k=2*j-i if k<N+1 and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]: ans-=1 print(ans)
import copy n = int(input()) a = list(map(int,input().split())) a.sort(reverse=True) count = 0 for i in range(len(a)-1): count += a[(i+1)//2] print(count)
0
null
22,628,718,706,748
175
111
# coding: utf-8 c1 = {1:[0]*10,2:[0]*10,3:[0]*10} c2 = {1:[0]*10,2:[0]*10,3:[0]*10} c3 = {1:[0]*10,2:[0]*10,3:[0]*10} c4 = {1:[0]*10,2:[0]*10,3:[0]*10} n = int(input()) for i in range(n): b,f,r,v = input().rstrip().split(" ") if int(b) == 1: c1[int(f)][int(r)-1] = c1[int(f)][int(r)-1] + int(v) elif int(b) == 2: c2[int(f)][int(r)-1] = c2[int(f)][int(r)-1] + int(v) elif int(b) == 3: c3[int(f)][int(r)-1] = c3[int(f)][int(r)-1] + int(v) else: c4[int(f)][int(r)-1] = c4[int(f)][int(r)-1] + int(v) for i in (1,2,3): result = " " + str(c1[i][0]) for j in range(1,10): result = result + " " + str(c1[i][j]) print(result) print("####################") for i in (1,2,3): result = " " + str(c2[i][0]) for j in range(1,10): result = result + " " + str(c2[i][j]) print(result) print("####################") for i in (1,2,3): result = " " + str(c3[i][0]) for j in range(1,10): result = result + " " + str(c3[i][j]) print(result) print("####################") for i in (1,2,3): result = " " + str(c4[i][0]) for j in range(1,10): result = result + " " + str(c4[i][j]) print(result)
N, M, K = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) min = 0 cnt = 0 for k in b: min += k j = M for i in range(N+1): while(j > 0 and min > K): j -= 1 min -= b[j] if(min > K): break cnt = max(cnt, i + j) if(i == N): break min += a[i] print(cnt)
0
null
5,935,604,094,862
55
117
def main(): N = input() acc = 0 for idx in range(len(N)): acc += (ord(N[idx]) - ord('0')) print('Yes') if not acc % 9 else print('No') if __name__ == '__main__': main()
n, a, b = map(int, input().split()) mod = 10 ** 9 + 7 ans = pow(2, n, mod) - 1 for i in [a, b]: num = 1 den = 1 for p in range(n, n-i, -1): num = num * p % mod for q in range(1, i+1): den = den * q % mod cmb = num * pow(den, mod-2, mod) % mod ans -= cmb ans %= mod print(ans)
0
null
35,421,009,887,358
87
214
a, b = list(map(int, input().split())) print(a - 2 * b) if a > 2 * b else print(0)
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) MOD = 10 ** 9 + 7 N, K = map(int, input().split()) lst = [0] * (K + 1) for i in range(K, 0, -1): a = K // i tmp = pow(a, N, MOD) for j in range(i + i, K + 1, i): tmp -= lst[j] lst[i] = tmp ans = 0 for i in range(K + 1): ans += i * lst[i] ans %= MOD print (ans)
0
null
101,411,291,968,712
291
176
str = input() num = int(str) if num % 2 == 0: print('-1'); else: i = 1 j = 7 while j % num != 0 and i <= num: j = (j % num) * 10 + 7 i += 1 if i > num: print('-1'); else: print(i);
K = int(input()) if K % 2 == 0 or K % 5 == 0: print(-1) exit() start = j = 7 % K count = 1 #無限ループ while True: #0の時 if j == 0: print(count) exit() j = 10 * j + 7 j = j % K count += 1 #同じ数のループしているかチェック if j == start: print(-1) exit()
1
6,141,641,836,230
null
97
97
from fractions import gcd def lcm(a, b): return (a * b) // gcd(a, b) def f(x): res = 0 while x % 2 == 0: x //= 2 res += 1 return res n, m = map(int, input().split()) a = [int(i) // 2 for i in input().split()] t = f(a[0]) flag = True for i in range(n): if f(a[i]) != t: flag = False else: a[i] >>= t m >>= t l = 1 for i in range(n): l = lcm(l, a[i]) if l > m: flag = False m //= l print(-(-m // 2) if flag else 0)
import fractions, sys input = sys.stdin.buffer.readline def lcm(x, y): return (x * y) // fractions.gcd(x, y) def calc(n, m): for i in range(cycle//m+1): X = m * (i + 0.5) if X > M: print(0) exit() return flag = True for x in n: if (X - x // 2) % x != 0: flag = False break if flag: return int(X) print(0) exit() return N, M = map(int, input().split()) A = list(map(int, input().split())) cycle = 1 ma = 0 for a in A: cycle = lcm(cycle, a) ma = max(ma, a) start = calc(A, ma) print((M - start) // cycle + 1)
1
101,569,379,648,448
null
247
247
from collections import Counter n=int(input()) a=list(map(int,input().split())) dic=Counter(a) for val in dic.values(): if val>=2: print("NO") exit() print("YES")
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()) S, T = map(str, input().split()) ans = "" for i in range(N): ans += S[i] + T[i] print(ans)
0
null
92,813,078,360,002
222
255
N = int(input()) L = list(map(int, input().split())) L.sort(reverse=True) ans = 0 for i in range(N-2): for j in range(i+1, N-1): ok = i ng = N while ng - ok > 1: mid = (ok + ng) // 2 if L[mid] > L[i] - L[j]: ok = mid else: ng = mid if ok > j: ans += ok - j print(ans)
from bisect import bisect_left N = int(input()) L_list = list(map(int, input().split())) L_list.sort() ans = 0 for i in range(N): for j in range(i + 1, N): a, b = L_list[i], L_list[j] r = bisect_left(L_list, a+b) ans += max(0,r-j-1) print(ans)
1
172,116,601,407,200
null
294
294
import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush, heappop BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 global current_time global visited,go_time,back_time global G def dfs(node_id): global current_time #書かないとローカル変数扱いされる go_time[node_id] = current_time current_time += 1 for next_node in G[node_id]: if visited[next_node] == True: continue visited[next_node] = True dfs(next_node) back_time[node_id] = current_time current_time += 1 V = int(input()) G = [[] for i in range(V)] visited = [False]*V go_time = [0]*V back_time = [0]*V for loop in range(V): node_id,num,*tmp_adj = list(map(int,input().split())) node_id -= 1 for i in range(num): G[node_id].append(tmp_adj[i]-1) current_time = 1; for i in range(V): if visited[i] == True: continue visited[i] = True dfs(i) for i in range(V): print("%d %d %d"%(i+1,go_time[i],back_time[i]))
n = int(raw_input()) d = [0] * n f = [0] * n M = [[0]*n for _ in xrange(n)] color = [0] * n tt = 0 WHITE = 0 GRAY = 1 BLACK = 2 def dfs_visit(u): global tt color[u] = GRAY tt += 1 d[u] = tt for v in xrange(n): if M[u][v] == 0: continue if color[v] == WHITE: dfs_visit(v) color[u] = BLACK tt += 1 f[u] = tt return 0 def dfs(): for u in xrange(n): if color[u] == WHITE: dfs_visit(u) for u in xrange(n): print "{} {} {}".format(u+1, d[u], f[u]) return 0 def main(): for i in xrange(n): a = map(int, raw_input().split()) u = a[0]-1 k = a[1] for j in xrange(k): v = a[j+2] - 1 M[u][v] = 1 dfs() return 0 main()
1
2,940,623,830
null
8
8
N = int(input()) cnt = 0 for i in range(1,N//2 + 1): if N - i != i: cnt += 1 print(cnt)
import math import collections import copy import sys n = int(input()) a = list(map(int,input().split())) limit = 10 ** 6 sCheck = math.gcd(a[0],a[1]) if n == 2: if sCheck == 1: print("pairwise coprime") else: print("not coprime") sys.exit() else: for i in range(2,n): sCheck = math.gcd(sCheck,a[i]) beforeQ = collections.deque([int(i) for i in range(3,(limit + 1))]) D = dict() p = 2 D[2] = 2 D[1] = 1 while p < math.sqrt(limit): afterQ = collections.deque() while len(beforeQ) > 0: k = beforeQ.popleft() if k % p != 0: afterQ.append(k) else: D[k] = p beforeQ = copy.copy(afterQ) p = beforeQ.popleft() D[p] = p while len(beforeQ) > 0: k = beforeQ.popleft() D[k] = k ansSet = set() count = 0 for i in a: k = i kSet = set() while k != 1: if D[k] in ansSet: if not(D[k] in kSet): count = 1 break else: ansSet.add(D[k]) kSet.add(D[k]) k = int(k // D[k]) if count == 1: break if count == 0: print("pairwise coprime") elif sCheck == 1: print("setwise coprime") else: print("not coprime")
0
null
78,941,363,002,678
283
85
import os, sys, re, math (A, B) = [int(n) for n in input().split()] print(max(A - B * 2, 0))
a, b = list(map(int, input().split())) remain = a - (b * 2) print(remain if remain >= 0 else 0)
1
166,758,525,371,830
null
291
291
N = int(input()) A = [int(s) - 1 for s in input().split()] M = {} result = 'YES' for a in A: if a in M.keys(): result = 'NO' M[a] = a print(result)
a = list(map(int, input().split())) if a[0]>a[1]: a[0],a[1]=a[1],a[0] if a[0]>a[2]: a[0],a[2]=a[2],a[0] if a[1]>a[2]: a[2],a[1]=a[1],a[2] print(*a)
0
null
37,309,685,732,542
222
40
a,b,c = map(int,input().split()) ab= (a*b)*4 C= (c-a-b)**2 if c-a-b>=0: if ab<C: print("Yes") else : print("No") else : print("No")
from decimal import Decimal import numpy as np a, b, c = map(int, input().split()) if np.sqrt(Decimal(a)) + np.sqrt(Decimal(b)) < np.sqrt(Decimal(c)): print("Yes") else: print("No")
1
51,671,785,748,000
null
197
197
N,M,K=map(int,input().split()) P=998244353 class FactInv: def __init__(self,N,P): fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1) for i in range(1,N): fact[i+1]=(fact[i]*(i+1))%P ifact[-1]=pow(fact[-1],P-2,P) for i in range(N,0,-1): ifact[i-1]=(ifact[i]*i)%P self.fact=fact;self.ifact=ifact;self.P=P def comb(self,n,k): return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P FI=FactInv(N+10,P) ans=0 for k in range(0,K+1): ans+=(M*FI.comb(N-1,k)*pow(M-1,N-1-k,P))%P ans%=P print(ans)
n=int(input()) l="" for i in range(1,n+1): if i % 3==0 or i % 10 == 3 or (i % 100)//10 == 3 or (i % 1000)//100 == 3 or (i % 10000)//1000 == 3: l+=" "+str(i) print(l)
0
null
12,096,244,669,408
151
52
X,N = map(int,input().split()) P = list(map(int,input().split())) for n in range(100): if X-n not in P: print(X-n) break if X+n not in P: print(X+n) break
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値) from heapq import heapify, heappop, heappush from math import * sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9+7 def mint(): return map(int,input().split()) def lint(): return list(map(int,input().split())) def judge(x, l=['Yes', 'No']): print(l[0] if x else l[1]) def lprint(l, sep='\n'): for x in l: print(x, end=sep) N,M = mint() C = [] for _ in range(M): s,c = mint() C.append([s,c]) for x in range(10**(N-1)-(N==1),10**N): x = str(x) if all([x[s-1]==str(c) for s,c in C]): print(x) exit() print(-1)
0
null
37,579,018,106,740
128
208
n,k=map(int,input().split()) #階乗 F = 200005 mod = 10**9+7 fact = [1]*F inv = [1]*F for i in range(2,F): fact[i]=(fact[i-1]*i)%mod inv[F-1]=pow(fact[F-1],mod-2,mod) for i in range(F-2,1,-1): inv[i] = (inv[i+1]*(i+1))%mod ans=1 for i in range(1,min(n,k+1)): comb=(fact[n]*inv[i]*inv[n-i])%mod h=(fact[n-1]*inv[i]*inv[n-1-i])%mod ans=(ans+comb*h)%mod print(ans)
#coding:utf-8 class Combination: def __init__(self,N,P=10**9+7): if N > 10**7: self.fact = lambda x: x * self.fact(x-1) % P if x > 2 else 2 self.perm = lambda x, r: x * self.perm(x-1,r-1) % P if r > 0 else 1 self.cmb = lambda n,r: (self.perm(n,min(n-r,r)) * pow(self.fact(min(n-r,r)) ,P-2 ,P) % P) if r > 0 else 1 else: self.__fact = [1] * (N+1) self.__inv = [1] * (N+1) self.__inv_fact = [1] * (N+1) for i in range(2,N+1): self.__fact[i] = self.__fact[i-1] * i % P self.__inv[i] = - self.__inv[P%i] * (P//i) % P self.__inv_fact[i] = self.__inv_fact[i-1] * self.__inv[i] % P self.fact = lambda n: self.__fact[n] self.perm = lambda n,r: self.__fact[n] * self.__inv_fact[n-r] % P self.cmb = lambda n,r: (self.__fact[n] * self.__inv_fact[n-r] * self.__inv_fact[r] % P) if r > 0 else 1 import sys,os sys.setrecursionlimit(10**6) write = sys.stdout.write dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0 def main(given=sys.stdin.readline): input = lambda: given().rstrip() LMIIS = lambda: list(map(int,input().split())) II = lambda: int(input()) XLMIIS = lambda x: [LMIIS() for _ in range(x)] YN = lambda c : print('Yes') if c else print('No') MOD = 10**9+7 from collections import deque n,k = LMIIS() cmb = Combination(2*n) ans = 1 for i in range(1,min(n,k+1)): ans = (ans + cmb.cmb(n,i) * cmb.cmb(n-1,i)) % MOD print(ans) if __name__ == '__main__': main()
1
67,262,069,479,824
null
215
215
N = int(input()) A = list(map(int,input().split())) A = sorted(A,reverse=True) ans = A[0] for i in range(1,(N-2)//2+1): ans += A[i]*2 if N % 2 == 1: ans += A[(N-2)//2 + 1] print(ans)
while True: (x, y) = [int(i) for i in input().split()] if x < y: print(x, y) elif x > y: print(y, x) elif x == y: if x == 0 and 0 == y: break print(x, y)
0
null
4,838,356,239,904
111
43
def gcd(m, n): while n: m, n = n, m % n return m def lcm(m, n): return m // gcd(m, n) * n for line in open(0).readlines(): a, b = map(int, line.split()) print(gcd(a, b), lcm(a, b))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: map(int, readline().split()) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: map(int, read().split()) in_s = lambda: readline().rstrip().decode('utf-8') INF = 10**9 + 7 def main(): N = in_n() arms = [tuple()] * N for i in range(N): x, l = in_nn() arms[i] = (x - l, x + l) arms.sort(key=lambda x: x[1]) # print(arms) r_max = -INF count = 0 for i in range(N): l, r = arms[i] if r_max <= l: r_max = r count += 1 print(count) if __name__ == '__main__': main()
0
null
44,920,881,413,110
5
237
while True: s = raw_input() if s == '0': break n = 0 for i in s: n += int(i) print n
for a in iter(input,'0'): print(sum([int(s)for s in a]))
1
1,597,656,749,920
null
62
62
def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def solve(): N = read_int() L = read_ints() L.sort() answer = 0 for i in range(2, N): for j in range(1, i): start, end = -1, j while end-start > 1: mid = start+(end-start)//2 if L[i]-L[j] < L[mid]: # valid end = mid else: start = mid answer += j-end return answer if __name__ == '__main__': print(solve())
import sys import bisect N = int(input()) L = list(map(int, input().split())) LS = sorted(L) ans = 0 for i in range(N): for j in range(N): if i < j: index = bisect.bisect_left(LS,LS[i]+LS[j]) ans += index-j-1 print(ans)
1
171,497,244,504,090
null
294
294
inputa = input() print(inputa.swapcase())
N=input() if N.count("7"): print("Yes") else: print("No")
0
null
17,879,576,524,640
61
172
n, m = map(int, input().split()) s = [] c = [] for _ in range(m): S, C = map(int, input().split()) s.append(S) c.append(C) for i in range(m): if s[i] == 1 and c[i] == 0 and n != 1: print(-1) exit() for i in range(m): for j in range(m-1): if s[i] == s[-j-1] and c[i] != c[-j-1]: print(-1) exit() if n == 3: one_hundred = False ten = False one = False for i in range(m): if s[i] == 1: one_hundred = c[i] elif s[i] == 2: ten = c[i] else: one = c[i] if one_hundred == False: one_hundred = 1 if ten == False: ten = 0 if one == False: one = 0 print(one_hundred*100 + ten*10 + one) exit() elif n == 2: ten = False one = False for i in range(m): if s[i] == 1: ten = c[i] else: one = c[i] if ten == False: ten = 1 if one == False: one = 0 print(ten*10 + one) exit() else: one = False for i in range(m): if s[i] == 1: one = c[i] if one == False: one = 0 print(one) exit() print(-1)
while True: a, op, b = input().split() a = int(a) b = int(b) if op == '?': break if op == '+': ans = a+b elif op == '-': ans = a-b elif op == '*': ans = a*b else: ans = a/b print('%d' %(ans))
0
null
30,502,919,948,996
208
47
c= '123' a= str(input()) b= str(input()) c= c.replace(a, '') c= c.replace(b, '') print(c)
N=int(input()) ans = [] for i in range(1,N+1): if i % 3 == 0 and i % 5 == 0: continue elif i % 3 == 0 and i % 5 != 0: continue elif i % 5 == 0 and i % 3 != 0: continue else: ans.append(i) print(sum(ans))
0
null
72,978,385,765,880
254
173
n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a_sums, b_sums = [0], [0] for i in range(n): a_sums.append(a_sums[i] + a[i]) for i in range(m): b_sums.append(b_sums[i] + b[i]) ans = 0 j = m for i in range(n + 1): if a_sums[i] > k: break while a_sums[i] + b_sums[j] > k: j -= 1 ans = max(ans, i + j) print(ans)
from itertools import accumulate n,m,k = map(int,input().split()) deskA = list(map(int,input().split())) deskB = list(map(int,input().split())) cumA = list(accumulate(deskA)) cumB = list(accumulate(deskB)) cumA = [0] + cumA cumB = [0] + cumB ans = 0 l = m for i in range(n+1): tmp = k - cumA[i] if tmp<0: continue j = l tmp -= cumB[j] while tmp < 0: tmp += cumB[j] j -= 1 tmp -= cumB[j] l = j ans = max(i+j,ans) print(ans)
1
10,728,083,946,330
null
117
117
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() d = [] s = set() dd = {} ind = 0 for i in range(n): x = input() if x in s: d[dd[x]][1] += 1 else: dd[x] = ind d.append([x,1]) ind += 1 s.add(x) d.sort(key = lambda x:x[1], reverse = True) # print(d) res = [] for key,va in d: if va < d[0][1]: break res.append(key) res.sort() for x in res: print(x)
n,m=map(int,input().split()) l=list(map(int,input().split())) sum=0 for i in range(m): sum+=l[i] if sum>n: print(-1) else: print(n-sum)
0
null
51,053,626,822,770
218
168
N = int(input()) says = [] for _ in range(N): A = int(input()) say = [list(map(int, input().split())) for _ in range(A)] says.append(say) # print(says) max_upright_count = 0 for i in range(1 << N): integrate = True upright_count = 0 declares = [-1 for _ in range(N)] for j in range(N): if not integrate: continue # もし真偽不明の場合は正しいことを言う場合もあるから無視する if (i >> j & 1) == 1: upright_count += 1 for x, y in says[j]: # print(i, j, x, y, declares) if declares[x - 1] == -1: declares[x - 1] = y else: if declares[x - 1] == y: continue else: integrate = False break # print(bin(i), integrate, declares, upright_count) for j in range(N): # print((i >> j) & 1, declares[j]) if ((i >> j) & 1) != declares[j] and declares[j] != -1: # print(False) integrate = False # print(integrate) if integrate: max_upright_count = max(max_upright_count, upright_count) print(max_upright_count)
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 #mod = 998244353 INF = 10**18 eps = 10**-7 kuku=range(1,10) n=int(input()) d=False for i in kuku: if n%i==0 and n//i<10: d=True if d: print("Yes") else: print("No")
0
null
140,706,492,665,508
262
287