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
def main(): import sys input = sys.stdin.readline #Union Find #xの根を求める def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] #xとyの属する集合の併合 def unite(x,y): x = find(x) y = find(y) if x == y: return False else: #sizeの大きいほうがx if par[x] > par[y]: x,y = y,x par[x] += par[y] par[y] = x return True #xとyが同じ集合に属するかの判定 def same(x,y): return find(x) == find(y) #xが属する集合の個数 def size(x): return -par[find(x)] n,m = map(int,input().split()) #初期化 #根なら-size,子なら親の頂点 par = [-1]*n for i in range(m): X,Y = map(int,input().split()) unite(X-1,Y-1) #tank = set([]) for i in range(n): find(i) ans=0 for i in par: if i<0: ans=max(ans,-i) print(ans) if __name__ == '__main__': main()
def insertion_sort(array): '''?????????????´?????????????????????¨??????????????????????????¨???????????????????????§?????\?????????????????°???????????? 1. ??????????????¨??????????????????????´?????????????????????? v ????¨????????????? 2. ????????????????????¨??????????????????v ????????§??????????´??????????????????????????§????????????? 3. ?????????????????????????????????????????????????´? v???????????\?????????''' for i in range(len(array)): v = array[i] j = i - 1 while(j>=0 and array[j] > v): array[j+1] = array[j] j = j - 1 array[j+1] = v print(' '.join(map(str, array))) def test(): '''??? input = 6 5 2 4 6 1 3 -> 5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6''' element_number = int(input()) input_array = list(map(int, input().split())) insertion_sort(input_array) if __name__ == '__main__': test()
0
null
1,978,888,047,610
84
10
def main(): N, M, X = map(int,input().split()) cost = [] effect = [] for _ in range(N): t = list(map(int,input().split())) cost.append(t[0]) effect.append(t[1:]) res = float("inf") for bits in range(1<<N): f = True total = 0 ans = [0] * M for flag in range(N): if (1<< flag) & (bits): total += cost[flag] for idx, e in enumerate(effect[flag]): ans[idx] += e for a in ans: if a < X: f = False if f: res = min(res, total) print(res if res != float("inf") else -1) if __name__ == "__main__": main()
n,m, x = map(int,input().split()) text=[] buy=10**10 for i in range(n): text.append(list(map(int,input().split()))) for i in range(2**n): bag=[0]*(m+1) for j in range(n):#いれる過程 if ((i>>j)&1):#j冊目のフラグがあれば for k in range(m+1): bag[k]+= text[j][k]#bagにいれる if min(bag[1:])>=x and bag[0]<buy: buy=bag[0] if buy==10**10: buy=-1 print(buy)
1
22,140,445,056,252
null
149
149
a, b = map(int, raw_input().split()) print '%d %d %f' %(a/b, a%b, a/float(b))
# coding=utf-8 from math import floor, ceil, sqrt, factorial, log, gcd from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heappushpop, heapify import copy import sys INF = float('inf') mod = 10**9+7 sys.setrecursionlimit(10 ** 6) def lcm(a, b): return a * b / gcd(a, b) # 1 2 3 # a, b, c = LI() def LI(): return list(map(int, sys.stdin.buffer.readline().split())) # a = I() def I(): return int(sys.stdin.buffer.readline()) # abc def # a, b = LS() def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() # a = S() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') # 2 # 1 # 2 # [1, 2] def IR(n): return [I() for i in range(n)] # 2 # 1 2 3 # 4 5 6 # [[1,2,3], [4,5,6]] def LIR(n): return [LI() for i in range(n)] # 2 # abc # def # [abc, def] def SR(n): return [S() for i in range(n)] # 2 # abc def # ghi jkl # [[abc,def], [ghi,jkl]] def LSR(n): return [LS() for i in range(n)] # 2 # abcd # efgh # [[a,b,c,d], [e,f,g,h]] def SRL(n): return [list(S()) for i in range(n)] h, w = LI() s = SRL(h) ans = [] for i in range(h): for j in range(w): if s[i][j] == "#": continue v = [[-1] * w for _ in range(h)] q = deque() q.append((i, j)) v[i][j] = 1 goal = tuple() while q: r, c = q.popleft() for x, y in ((1, 0), (-1, 0), (0, -1), (0, 1)): if r + x < 0 or r + x > h - 1 or c + y < 0 or c + y > w - 1 or s[r + x][c + y] == "#" or v[r + x][c + y] > 0: continue v[r + x][c + y] = v[r][c] + 1 q.append((r + x, c + y)) ans.append(max(chain.from_iterable(v)) - 1) print(max(ans))
0
null
47,661,279,088,400
45
241
n = int(input()) nums = [int(i) for i in input().split(' ')] nums_sorted = sorted(nums) min = nums_sorted[0] max = nums_sorted[n - 1] print(min, max, sum(nums_sorted))
n = int(input()) li = list(map(int, input().split())) print(min(li), max(li), sum(li))
1
709,190,020,108
null
48
48
n = input() print(n.replace(n,'x'*len(n)))
S = input() ans = ''.join(['x' for ch in S]) print(ans)
1
73,208,623,003,310
null
221
221
s = input() l = [] for i in range(len(s)): l.append(s[i]) if l[len(l)-1] == "s": print(s+str("es")) else: print(s+str("s"))
n=int(input()) adj=[] for i in range(n): adj.append(list(map(int, input().split()))) edge=[[0 for i2 in range(n)]for i1 in range(n)] #??£??\??????????????? for i in range(n): for j in range(adj[i][1]): edge[i][adj[i][j+2]-1]=1 time=1 discover=[0 for i in range(n)] final=[0 for i in range(n)] stack=[] def dfs(id,time): for i in range(n): c=0 if edge[id][i]==1 and discover[i]==0: stack.append(id) discover[i]=time c+=1 #print(discover,final,i,stack) dfs(i,time+1) else: pass if c==0: if len(stack)>0: if final[id]==0: final[id] = time #print("back",discover,final,id,stack) dfs(stack.pop(), time + 1) else: #print("back", discover, final, id, stack) dfs(stack.pop(),time) discover[0]=time stack.append(0) dfs(0,time+1) for i in range(n): if discover[i]==0: discover[i]=final[0]+1 stack.append(i) dfs(i,final[0]+2) break for i in range(n): print(i+1,discover[i],final[i])
0
null
1,215,613,908,416
71
8
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);
import sys K=int(input()) if K%2==0 or K%5==0: print('-1') sys.exit() i=1 K=9*K ans=10-K while(1): if 7*(ans-1)%K==0: print(i) sys.exit() i+=1 ans=ans*10%K
1
6,114,322,808,254
null
97
97
from math import pi print(2 * pi * int(input()), end='\n\r')
from __future__ import division, print_function from sys import stdin n = int(stdin.readline()) result = [0, 0] for _ in range(n): taro, hanako = stdin.readline().split() if taro > hanako: result[0] += 3 elif taro < hanako: result[1] += 3 else: result[0] += 1 result[1] += 1 print(*result)
0
null
16,800,325,300,638
167
67
import bisect import math import sys jd = [] for i in range(1,50) : jd.append((1+i)*i//2) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr n = int(input()) if n == 1 : print(0) sys.exit() p = factorization(n) ans = 0 for i in p : c = i[1] ans += bisect.bisect_right(jd, c) print(ans)
import sys input = sys.stdin.buffer.readline import copy def main(): N,K = map(int,input().split()) MOD = 10**9+7 fac = [0 for _ in range(2*10**5+1)] fac[0],fac[1] = 1,1 inv = copy.deepcopy(fac) invfac = copy.deepcopy(fac) for i in range(2,2*10**5+1): fac[i] = (fac[i-1]*i)%MOD inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD invfac[i] = (invfac[i-1]*inv[i])%MOD def coef(x,y): num = (((fac[x]*invfac[y])%MOD)*invfac[x-y]%MOD) return num ans = 0 for i in range(min(N,K+1)): a = coef(N,i) b = coef(N-1,N-i-1) ans += ((a*b)%MOD) print(ans%MOD) if __name__ == "__main__": main()
0
null
42,166,651,469,340
136
215
s=input() ans = 0 for i in range(len(s)): j = len(s)-i-1 if i > j: break if s[i] != s[j]: ans += 1 print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) MOD = 998244353 n, k = map(int, input().split()) s = list() for i in range(k): s.append(tuple(map(int, input().split()))) dp = [0] + [0] * n diff = [0] + [0] * n dp[1] = 1 for i in range(1, n): for j, k in s: if i + j > n: continue diff[i + j] += dp[i] if i + k + 1 > n: continue diff[i + k + 1] -= dp[i] dp[i] = (dp[i - 1] + diff[i]) % MOD dp[i + 1] = (dp[i] + diff[i + 1]) % MOD print(dp[n])
0
null
61,383,567,417,596
261
74
k, x = list(map(int, input().split())) a = k * 500 if a >= x: print("Yes") else: print("No")
watch = int(input()) hour= watch//3600 watch -= hour *3600 minute = watch // 60 watch -=minute*60 print(hour,minute,watch,sep=':')
0
null
49,519,511,217,078
244
37
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * #階乗# lim = 10**6 #必要そうな階乗の限界を入力 fact = [1] * (lim+1) for n in range(1, lim+1): fact[n] = n * fact[n-1] % mod #階乗の逆元# fact_inv = [1]*(lim+1) fact_inv[lim] = pow(fact[lim], mod-2, mod) for n in range(lim, 0, -1): fact_inv[n-1] = n*fact_inv[n]%mod def C(n, r): return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod X, Y = MAP() a = (Decimal("2")*Decimal(str(X))-Decimal(str(Y)))/Decimal("3") b = (Decimal("2")*Decimal(str(Y))-Decimal(str(X)))/Decimal("3") if a%1 == b%1 == 0 and 0 <= a and 0 <= b: print(C(int(a+b), int(a))) else: print(0)
def mod_fact(N,p): mod=1 for n in range(1,N+1): mod = (mod*(n%p))%p mod = mod%p return mod X,Y = list(map(int,input().split())) Z = X+Y ans=0 if Z%3 != 0: ans=0 elif min(X,Y) >= Z//3: b=0 for z in range(Z//3,((Z//3)*2)+1): if z == X: break b+=1 a = Z//3 - b p=(10**9)+7 Z_= mod_fact(Z//3 , p) a_= mod_fact(a , p) b_= mod_fact(b , p) a_= pow(a_,p-2,p) b_= pow(b_,p-2,p) ans=(Z_*(a_*b_))%p print(ans)
1
149,993,518,362,078
null
281
281
from bisect import* n, *l = map(int, open(0).read().split()) l.sort() print(sum(max(0, bisect_left(l, l[i] + l[j]) - j - 1) for i in range(n) for j in range(i+1, n)))
X, K, D = map(int, input().split()) if X - K * D >= 0: ans = abs(X - K * D) elif X + K * D <= 0: ans = abs(X + K * D) else: n = int(abs(X - K * D) / (2 * D)) ans = min(abs(X - K * D + n * 2 * D), abs(X - K * D + (n + 1) * 2 * D)) print(ans)
0
null
88,527,858,926,440
294
92
N=int(input()) if N==1: print('0') exit() def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def divcount(n): cnt=0 while n>=0: n-=cnt+1 cnt+=1 return cnt-1 s=factorization(N) t=[i[1] for i in s] ans=0 for i in t: ans+=divcount(i) print(ans)
import collections def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f**2 <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a count = 0 N = int(input()) if N <= 1: print(0) exit() else: c = collections.Counter(prime_factorize(N)) K = [sum(range(1,i)) for i in range(2,11)] # = [1, 3, 6, 10, 15, 21, 28, 36, 45] for i in c: for j in range(1,len(K)): if c[i] < K[j]: count += j break print(count)
1
16,784,092,194,130
null
136
136
N = int(input()) az = [chr(i) for i in range(97, 97+26)] N = N - 1 tmp1 = 0 for i in range(1, 1000): tmp1 += 26 ** i if tmp1 > N: num = i tmp1 -= 26 ** i N -= tmp1 break tmp = [0 for _ in range(num)] for i in range(num): tmp[i] = N%26 N = N // 26 ans = "" for i in range(len(tmp)): ans = az[tmp[i]] + ans print(ans)
W=input() count=0 while True: text=input() if text == 'END_OF_TEXT': break else: ls = list(map(str, text.split())) for s in ls: if s.lower() == W.lower(): count += 1 print(count)
0
null
6,824,289,699,292
121
65
#!/usr/bin/env python3 a=sorted(input().split()) print(a[0]*int(a[1]))
from math import * def az9(): r = float(input()) print "%5f"%(pi*r*r), "%5f"%(2*pi*r) az9()
0
null
42,236,909,117,490
232
46
n = input() lis = map(int, raw_input().split()) mn = lis[0] mx = lis[0] for t in lis: if mn > t: mn = t if mx < t: mx = t print mn, mx, sum(lis)
#coding:utf-8 input() data = [int(x) for x in input().split()] print(str(min(data))+" "+str(max(data)) + " "+str(sum(data)))
1
736,125,881,062
null
48
48
residence = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] n = int(input()) sep = "#"*20 s = "" for i in range(n): b,f,r,v = map(int,input().split()) residence[b-1][f-1][r-1] += v for i in residence: for j in i: s += " "+" ".join(map(str,j)) + "\n" s += sep+"\n" print(s.rstrip(sep+"\n"))
# -*- coding: utf-8 -*- import math n = int(raw_input()) x = map(int, raw_input().split()) y = map(int, raw_input().split()) d1 = d2 = d3 = d4 = 0.0 for i in range(n): d = math.fabs(x[i]-y[i]) d1 += d d2 += d*d d3 += d*d*d if d4 < d: d4 = d d2 = math.pow(d2, (1.0/2.0)) d3 = math.pow(d3, (1.0/3.0)) print d1 print d2 print d3 print d4
0
null
653,215,575,870
55
32
import sys for l in sys.stdin: x,y=map(int, l.split()) m=x*y while x%y:x,y=y,x%y print "%d %d"%(y,m/y)
def get_input(): while True: try: yield "".join(input()) except EOFError: break def calcGCD(a,b):#?????§??¬?´???°????±?????????????????????????????????????????????¨????????? if a>b: large = a small = b elif a<b: large = b small = a else: return a while True: if large == small: return large temp_small = large - small if temp_small < small: large = small small = temp_small else: large = temp_small small = small def calcLCM(a,b,gcd):#????°???¬?????°????±?????????? lcm = a*b/gcd return lcm if __name__ == "__main__": array = list(get_input()) for i in range(len(array)): temp_a,temp_b = array[i].split() a,b = int(temp_a),int(temp_b) gcd = calcGCD(a,b) lcm = calcLCM(a,b,gcd) lcm = int(lcm) print("{} {}".format(gcd,lcm))
1
781,346,894
null
5
5
s = input() for _ in range(int(input())): o = list(map(str, input().split())) a = int(o[1]) b = int(o[2]) if o[0] == "print": print(s[a:b+1]) elif o[0] == "reverse": s = s[:a] + s[a:b+1][::-1] + s[b+1:] else: s = s[:a] + o[3] + s[b+1:]
string = input() num = int(input()) orders = [input().split() for _ in range(num)] for order in orders: start = int(order[1]) end = int(order[2]) + 1 if order[0] == "reverse": string = string[:start] + string[start:end][::-1] + string[end:] elif order[0] == "replace": string = string[:start] + order[3] + string[end:] elif order[0] == "print": print(string[start:end])
1
2,066,122,809,410
null
68
68
z = int(input()) if z >= 30: print('Yes') else: print('No')
x = int(input()) print("Yes") if x >= 30 else print("No")
1
5,738,950,325,780
null
95
95
def gcd(x, y): if x < y: tmp = x x = y y = tmp r = x % y while r != 0: x = y y = r r = x % y return y x, y = map(int, input().split()) print(gcd(x, y))
n, k = map(int, input().split()) nums = list(map(int, input().split())) # (sums[j] - sums[i]) % K = j - i # (sums[j] - j) % K = (sums[i] - i) % K # 1, 4, 2, 3, 5 # 0, 1, 5, 7, 10, 15 # 0, 0, 3, 0, 2, 2 sums = [0] for x in nums: sums.append(sums[-1] + x) a = [(sums[i] - i) % k for i in range(len(sums))] res = 0 memo = {} i = 0 for j in range(len(a)): memo[a[j]] = memo.get(a[j], 0) + 1 if j - i + 1 > k: memo[a[i]] -= 1 i += 1 res += memo[a[j]] - 1 print(res)
0
null
68,889,778,072,420
11
273
import sys input = sys.stdin.readline class SegTree(): # ここでは操作の都合上根元のindexを1とする def __init__(self, lists, function, basement): self.n = len(lists) self.K = (self.n-1).bit_length() self.f = function self.b = basement self.seg = [basement]*2**(self.K+1) X = 2**self.K for i, v in enumerate(lists): self.seg[i+X] = v for i in range(X-1, 0, -1): self.seg[i] = self.f(self.seg[i << 1], self.seg[i << 1 | 1]) def update(self, k, value): X = 2**self.K k += X self.seg[k] = value while k: k = k >> 1 self.seg[k] = self.f(self.seg[k << 1], self.seg[(k << 1) | 1]) def query(self, L, R): num = 2**self.K L += num R += num vL = self.b vR = self.b while L < R: if L & 1: vL = self.f(vL, self.seg[L]) L += 1 if R & 1: R -= 1 vR = self.f(self.seg[R], vR) L >>= 1 R >>= 1 return self.f(vL, vR) def main(): N = int(input()) S = list(input()) Q = int(input()) que = [tuple(input().split()) for i in range(Q)] alpha = "abcdefghijklmnopqrstuvwxyz" Data = {alpha[i]: [0]*N for i in range(26)} for i in range(N): Data[S[i]][i] += 1 SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)} for X, u, v in que: if X == "1": u = int(u)-1 NOW = S[u] S[u] = v SEG[NOW].update(u, 0) SEG[v].update(u, 1) else: u, v = int(u)-1, int(v)-1 res = 0 for j in range(26): res += SEG[alpha[j]].query(u, v+1) print(res) if __name__ == "__main__": main()
class SegmentTree: def __init__(self, n, init_value, segfunc, ide_ele): self.N0 = 2 ** (n - 1).bit_length() self.ide_ele = ide_ele self.data = [ide_ele] * (2 * self.N0) self.segfunc = segfunc for i in range(n): self.data[i + self.N0 - 1] = init_value[i] for i in range(self.N0 - 2, -1, -1): self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2]) def update(self, _k, x): k = _k + self.N0 - 1 self.data[k] = x while k: k = (k - 1) // 2 self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2]) def query(self, _p, _q): p = _p q = _q if q <= p: return self.ide_ele p += self.N0 - 1 q += self.N0 - 2 res = self.ide_ele while 1 < q - p: if p & 1 == 0: res = self.segfunc(res, self.data[p]) if q & 1 == 1: res = self.segfunc(res, self.data[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = self.segfunc(res, self.data[p]) else: res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q]) return res def popcount(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f def solve(): N = int(input()) S = input() Q = int(input()) init_val = [1 << ord(S[i]) - ord('a') for i in range(N)] def segfunc(a, b): return a | b seg_tree = SegmentTree(N, init_val, segfunc, 0) for _ in range(Q): cmd, *query = input().split() cmd = int(cmd) if cmd == 1: i = int(query[0]) - 1 c = query[1] seg_tree.update(i, 1 << ord(c) - ord('a')) else: l = int(query[0]) - 1 r = int(query[1]) kind = seg_tree.query(l, r) print(popcount(kind)) if __name__ == '__main__': solve()
1
62,717,410,633,218
null
210
210
while 1: (a,b,c) = map(int,raw_input().split()) if a == -1 and b == -1 and c == -1: break if a == -1 or b == -1: print 'F' elif a+b >= 80: print 'A' elif a+b >= 65: print 'B' elif a+b >= 50: print 'C' elif a+b >= 30: if c >= 50: print 'C' else: print 'D' else: print 'F'
N, K = list(map(int, input().split())) mod = 10**9+7 ans = [0]*(K+1) s = 0 for i in range(K, 0, -1): ans[i] = pow(K//i, N, mod) for j in range(2*i, K+1, i): ans[i] -= ans[j] s += ans[i]*i%mod print(s%mod)
0
null
18,950,986,006,432
57
176
from fractions import gcd n = int(input()) a = list(map(int, input().split())) max_a = max(a) mod = 10**9 + 7 inverse = [1] * (max_a + 1) for i in range(2, max_a + 1): inverse[i] = -inverse[mod % i] * (mod // i) % mod lcm = 1 for i in range(n): lcm = lcm * a[i] // gcd(lcm, a[i]) lcm %= mod sum_b = 0 for i in range(n): sum_b = (sum_b + lcm * inverse[a[i]]) % mod print(sum_b)
#!/usr/bin/env python3 import sys from fractions import gcd from functools import reduce input = lambda: sys.stdin.readline().strip() MOD = 1000000007 def lcm(a, b): return a // gcd(a, b) * b n = int(input()) A = [int(x) for x in input().split()] x = reduce(lcm, A) print(sum(x // ai for ai in A) % MOD)
1
87,876,856,028,038
null
235
235
A, B, M = map(int, input().split()) a = [int(a) for a in input().split()] b = [int(b) for b in input().split()] X = [0] * M Y = [0] * M C = [0] * M for i in range(M): X[i], Y[i], C[i] = map(int, input().split()) all_prices = [] for x, y, c in zip(X, Y, C): all_prices.append(a[x-1] + b[y-1] - c) prices = [min(a) + min(b), min(all_prices)] print(min(prices))
N = int(input()) print(1/2 if N%2==0 else (N+1)/(2*N))
0
null
115,338,953,193,312
200
297
a,b,c=map(int,input().split(' ')) a,b,c=c,a,b print(str(a)+" "+str(b)+" "+str(c))
import sys array = list(map(int,input().split())) if not ( 1 <= min(array) and max(array) <= 100 ): sys.exit() check = lambda x: isinstance(x,int) print(array[2],array[0],array[1])
1
38,012,753,467,172
null
178
178
H = int(input()) W = int(input()) N = int(input()) def f(a): if N % a == 0: result = int(N / a) else: result = int(N / a) + 1 print(result) if H <= W: f(W) else: f(H)
H = int(input()) W = int(input()) N = int(input()) m = max(H, W) print((N + m - 1) // m)
1
88,814,517,359,880
null
236
236
from sys import stdin input = stdin.readline def main(): N = int(input()) A = sorted(list(map(int, input().split()))) not_divisible = [False]*(10**6+1) for i in range(N): not_divisible[A[i]] = True prev = 0 for i in range(N): if not_divisible[A[i]]: j = A[i] + A[i] while j <= A[-1]: not_divisible[j] = False j += A[i] if prev == A[i]: not_divisible[A[i]] = False prev = A[i] cnt = 0 for i in range(N): if not_divisible[A[i]]: cnt += 1 print(cnt) if(__name__ == '__main__'): main()
import math x = int(input()) a = 100 cnt = 0 while(1): cnt += 1 a += a//100 if a >= x: break print(cnt)
0
null
20,707,163,787,684
129
159
import itertools n = int(input()) l = list(map(int, input().split())) count = 0 ind_list = list(itertools.combinations(range(0,n), 3)) for ind in ind_list: if (l[ind[0]]+l[ind[1]])>l[ind[2]] and (l[ind[1]]+l[ind[2]])>l[ind[0]] and (l[ind[2]]+l[ind[0]])>l[ind[1]]: if l[ind[0]]!=l[ind[1]] and l[ind[0]]!=l[ind[2]] and l[ind[1]]!=l[ind[2]]: count += 1 print(count)
N = int(input()) L = list(map(int, input().split())) c = 0 for i in range(N): for j in range(i+1,N): for k in range(j+1,N): if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]: if L[i] + L[j] + L[k] > 2 * max(L[i],L[j],L[k]): c +=1 print(c)
1
5,066,572,096,128
null
91
91
s=input() a="RRR" b="RR" c="R" if a in s: print(3) elif b in s: print(2) elif c in s: print(1) else: print(0)
S = input() #print(S.count("R")) con = S.count("R") if con == 1: print(1) elif con == 3: print(3) elif con == 2: for j in range(3): if S[j] =="R": if S[j+1] =="R": print(2) break else: print(1) break elif con == 0: print(0)
1
4,835,449,219,426
null
90
90
from decimal import Decimal as de a,b,c=map(de,input().split()) print('Yes' if a**de('0.5')+b**de('0.5')<c**de('0.5') else 'No')
a, b, c = map(int, input().split()) if (a**2 + b**2 + c**2) > 2*(a*b + a*c + b*c) and (c - a -b) >= 0:print('Yes') else:print('No')
1
51,472,947,873,708
null
197
197
import math str = input().split(' ') x1 = float(str[0]) x2 = float(str[1]) y1 = float(str[2]) y2 = float(str[3]) result = (x1-y1)*(x1-y1) + (x2-y2)*(x2-y2) result = math.sqrt(result) if result != 0 else 0 print('%.6f'%result)
#coding: utf-8 x=input() y=x*x*x print y
0
null
216,343,469,888
29
35
N = int(input()) A = list(map(int, input().split())) maxn = 1000005 prime = [0 for _ in range(maxn)] for i in range(2, maxn): if prime[i] == 0: for j in range(i, maxn, i): prime[j] = i #最大質因數 st = set() #目前出現過的所有質因數,一開始為A[0]的所有質因數 a = A[0] while prime[a]: st.add(prime[a]) x = prime[a] while (a % x == 0): a //= x pairwise = True st2 = st #所有數共有的質因數,一開始為A[0]的所有質因數 for a in A[1:]: tmp = set() for j in st2: if a % j == 0: tmp.add(j) st2 = tmp if pairwise: while prime[a]: if prime[a] in st: pairwise = False st.add(prime[a]) x = prime[a] while (a % x == 0): a //= x if pairwise: print("pairwise coprime") elif len(st2) == 0: print("setwise coprime") else: print("not coprime")
#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
2,036,618,976,002
85
5
import sys n = int(input()) a = dict() for x in map(int, input().split()): if a.get(x) == 1: print('NO') sys.exit() a[x] = 1 print('YES')
# E - Rotation Matching n, m = map(int, input().split()) l, r = 1, n for i in range(m): if 2 * (r - l) == n or 2 * (r - l + 1) == n: l += 1 print(l, r) l, r = l + 1, r - 1
0
null
51,487,252,829,068
222
162
A,B,C,K=map(int,input().split()) print(1*min(A,K)-1*max(0,K-A-B))
n = int(input()) 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 d1 = make_divisors(n) d2 = make_divisors(n-1) ans = 0 for k in d1: if k == 1: continue temp = n while temp%k == 0: temp //= k if temp%k == 1: ans += 1 ans += len(d2)-1 print(ans)
0
null
31,341,179,200,160
148
183
n=int(input()) count=0 for i in range(n): x,y = map(int,input().split()) if x==y: count+=1 else: count=0 if count==3: print('Yes') exit() print('No')
X = int(input()) money = 100 time = 0 while money < X: time += 1 money = money * 101 // 100 print(time)
0
null
14,799,683,604,288
72
159
N, X, Y = map(int, input().split()) count = [0]*(N+1) for i in range(1, N+1): for k in range(i+1, N+1): distik = min(k-i, abs(k-X) + abs(i - Y)+1, abs(k-Y) + abs(i-X)+1) count[distik] += 1 for i in range(1, N): print(count[i])
H, W, M = map(int, input().split()) targets = [list(map(int, input().split())) for _ in range(M)] x_counter = [0 for _ in range(W + 1)] y_counter = [0 for _ in range(H + 1)] y_index = [] x_index = [] check = 0 for i in range(M): x, y = targets[i] y_counter[x] += 1 x_counter[y] += 1 y_max, x_max = max(y_counter), max(x_counter) for i in range(H + 1): if y_counter[i] == y_max: y_index.append(i) for j in range(W + 1): if x_counter[j] == x_max: x_index.append(j) y_index = set(y_index) x_index = set(x_index) check = len(y_index) * len(x_index) for k in range(M): r, c = targets[k] if r in y_index and c in x_index: check -= 1 print(y_max + x_max if check > 0 else y_max + x_max -1)
0
null
24,466,154,064,732
187
89
class Card: def __init__(self, label): suits = ['S', 'H', 'C', 'D'] suit, value = list(label) assert(suit in suits and 0 < int(value) < 10) self.suit = suit self.value = int(value) def __eq__(self, other): """equal >>> Card('S1') == Card('D9') False >>> Card('D9') == Card('S1') False >>> Card('C5') == Card('C5') True """ return self.value == other.value def __lt__(self, other): """less than >>> Card('S1') < Card('D9') True >>> Card('D9') < Card('S1') False """ return self.value < other.value def __gt__(self, other): """greater than >>> Card('S1') > Card('D9') False >>> Card('D9') > Card('S1') True """ return self.value > other.value def __hash__(self): return hash((self.suit, self.value)) def __str__(self): return self.suit + str(self.value) def bubble_sort(deck): """sort deck by bubble sort >>> deck = [Card('H4'), Card('C9'), Card('S4'), Card('D2'), Card('C3')] >>> print(" ".join([str(c) for c in bubble_sort(deck)])) D2 C3 H4 S4 C9 """ size = len(deck) for i in range(size): for j in reversed(range(i+1, size)): if deck[j] < deck[j-1]: deck[j-1], deck[j] = deck[j], deck[j-1] return deck def selection_sort(deck): """sort deck by selection sort >>> deck = [Card('H4'), Card('C9'), Card('S4'), Card('D2'), Card('C3')] >>> print(" ".join([str(c) for c in selection_sort(deck)])) D2 C3 S4 H4 C9 """ size = len(deck) for i in range(size): mini = i for j in range(i, size): if deck[mini] > deck[j]: mini = j deck[i], deck[mini] = deck[mini], deck[i] return deck def is_stable_sorted(org, deck): """check if deck is sorted by stable manner >>> c1 = Card('S1') >>> c2 = Card('D1') >>> is_stable_sorted([c1, c2], [c1, c2]) True >>> is_stable_sorted([c1, c2], [c2, c1]) False """ idx = {c:i for (i, c) in enumerate(org)} return all([c1 < c2 or idx[c1] < idx[c2] for (c1, c2) in zip(deck[:-1], deck[1:])]) def check_stable(org, deck): if is_stable_sorted(org, deck): return "Stable" else: return "Not stable" def run(): _ = int(input()) # flake8: noqa deck = [] for lb in input().split(): deck.append(Card(lb)) db = bubble_sort(deck[:]) print(" ".join([str(c) for c in db])) print(check_stable(deck, db)) ds = selection_sort(deck[:]) print(" ".join([str(c) for c in ds])) print(check_stable(deck, ds)) if __name__ == '__main__': run()
import math N, D = map(int,input().split()) XY = list(list(map(int,input().split())) for _ in range(N)) count = 0 for i in range(N): if math.sqrt(XY[i][0] ** 2 + XY[i][1] ** 2) <= D: count += 1 print(count)
0
null
2,942,062,290,960
16
96
from sys import stdin operate = { '+': lambda lhs, rhs: lhs + rhs, '-': lambda lhs, rhs: lhs - rhs, '*': lambda lhs, rhs: lhs * rhs, '/': lambda lhs, rhs: lhs // rhs, } while True: arr = (stdin.readline().rstrip().split()) a, op, b = int(arr[0]), arr[1], int(arr[2]) if op == '?': break answer = operate[op](a, b) print(answer)
while True: a,b,c = input().split() if b=='?': break elif b =='+': d = int(a) + int(c) elif b=='-': d = int(a) - int(c) elif b=='*': d = int(a)*int(c) else : d = int(a)/int(c) print(int(d))
1
689,976,768,130
null
47
47
N = int(input()) A = list(map(int, input().split())) fumidai = 0 previous = 0 for i in range(N): if previous > A[i]: fumidai += previous - A[i] else: previous = A[i] continue print(fumidai)
x, y = [int(i) for i in input().split()] date = [[int(i) for i in input().split()]for i in range(1,x+1)] date2 =[int(input())for i in range(1,y+1)] date3 =[] for a in range(0,x): for b in range(0,y,): date3 += [date2[b]*date[a][b]] for d in range(0,len(date3),y): print(sum(date3[d:d+y]))
0
null
2,869,531,705,540
88
56
#template def inputlist(): return [int(j) for j in input().split()] #template li = inputlist() for i in range(5): if li[i] == 0: print(i+1)
N = int(input()) S = input() count_R = 0 count_G = 0 count_B = 0 count = 0 for i in range(N): if S[i] == 'R': count_R = count_R+1 elif S[i] == 'G': count_G = count_G+1 else: count_B = count_B+1 count = count_R*count_G*count_B for i in range(N): for j in range(i+1,N): if S[i] != S[j]: k = 2*j-i if k>=N: break else: if S[i] != S[k] and S[j] != S[k]: count = count-1 print(count)
0
null
24,792,313,105,890
126
175
import math a,b,c=(int(x) for x in input().split()) x=c-a-b if x>0: if x*x-4*a*b>0: print('Yes') else: print('No') else: print('No')
n = int(input()) AC = 0 WA = 0 TLE = 0 RE = 0 for i in range(n): x = input() if x == "AC": AC += 1 elif x == "WA": WA += 1 elif x == "TLE": TLE += 1 elif x == "RE": RE += 1 print("AC x " + str(AC)) print("WA x " + str(WA)) print("TLE x " + str(TLE)) print("RE x " + str(RE))
0
null
30,077,160,515,260
197
109
import math A, B, X = map(int, input().split()) h = X / (A*A) r = 0 deg = 0 if (2 * X) - (B * A * A) > 0: r = math.atan(2 * (B-h) / A) elif (2 * X) - (B * A * A) == 0: r = math.atan(B / A) else: h = (2 * X) / (A * B) r = math.atan(B / h) deg = math.degrees(r) print(deg)
x=int(input()) if(x>=400 and x<=599): print('8') elif(x>=600 and x<=799): print('7') elif(x>=800 and x<=999): print('6') elif(x>=1000 and x<=1199): print('5') elif(x>=1200 and x<=1399): print('4') elif(x>=1400 and x<=1599): print('3') elif(x>=1600 and x<=1799): print('2') elif(x>=1800 and x<=1999): print('1')
0
null
84,968,182,991,900
289
100
#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)] n = int(input()) s = [input() for _ in range(n)] h = {} for i in range(n): if (s[i] in h): h[s[i]] += 1 else: h[s[i]] = 1 ans = [] highScore = max(h.values()) for k,v in h.items(): if v== highScore: ans.append(k) ans.sort() for i in range(len(ans)): print(ans[i])
a = int(input()) b = int(input()) t = set([1, 2, 3]) s = set([a,b]) ans = t - s print(list(ans)[0])
0
null
90,509,843,865,288
218
254
import sys from itertools import product sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) def dfs(s, num): if len(s) == n: print(s) return for i in range(num + 1): t = s + chr(97 + i) dfs(t, max(num, i + 1)) dfs("", 0) if __name__ == '__main__': resolve()
import math daviations = [] while True: num = int(input()) if num == 0: break scores = input().split() for i in range(num): scores[i] = float(scores[i]) avr = sum(scores) / num daviation = 0 for a in scores: disp = (a - avr)**2/num daviation += disp daviations.append(round(math.sqrt(daviation),8)) for b in daviations: print(b)
0
null
26,476,401,070,420
198
31
n = int(input()) A = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) # bit all search pattern = [] for i in range(2 ** n): bit_set = [] for j in range(n): if ((i >> j) & 1): bit_set.append(A[j]) pattern.append(sum(bit_set)) #print(pattern) for m in m: if m in pattern: print('yes') else: print('no')
def solve(pos, tot, A): if tot == 0: return True if pos > len(A) - 1: return False return solve(pos+1, tot - A[pos], A) or \ solve(pos+1, tot, A) n = raw_input() b = map(int, raw_input().split()) n = raw_input() t = map(int, raw_input().split()) max = sum(b) + 1 for tt in t: print 'yes' if tt < max and True == solve(0, tt, b) else 'no'
1
100,987,582,080
null
25
25
from _collections import deque from _ast import Num def parser(): while 1: data = list(input().split(' ')) for number in data: if len(number) > 0: yield (number) input_parser = parser() def gw(): global input_parser return next(input_parser) def gi(): data = gw() return int(data) MOD = int(1e9 + 7) import numpy from collections import deque from math import sqrt from math import floor # https://atcoder.jp/contests/abc145/tasks/abc145_e #E - All-you-can-eat """ """ N = gi() M = gi() S = gw() lis = [0] * (N + 5) li = 0 all_good = 1 for i in range(1, N + 1): while (i - li > M or (li < i and S[li] == "1")): li += 1 if li == i: all_good = 0 break lis[i] = li if all_good: ans = [] ci = N while ci > 0: step = ci - lis[ci] ans.append(step) ci -= step ans.reverse() for a in ans: print(a, end=" ") else: print(-1)
import sys input = sys.stdin.readline n, m = map(int, input().split()) s = input().strip() ans = [] now = n while now != 0: tmp = False for i in range(m, 0, -1): if now-i >= 0 and s[now-i] == '0': tmp = True now -= i ans.append(i) break if not tmp: print(-1) sys.exit() print(*ans[::-1])
1
139,502,859,974,752
null
274
274
N,K=map(int,input().split()) H=sorted(list(map(int,input().split()))) if N<=K: print(0) else: if K==0: print(sum(H)) else: print(sum(H[:-K]))
n,k=map(int,input().split());print(sum(sorted(map(int,input().split()),reverse=True)[k:]))
1
78,844,370,564,960
null
227
227
import numpy as np from numpy.fft import rfft, irfft N,M = list(map(int,input().split())) A = list(map(int,input().split())) X = np.zeros(10**5+1) l = 2*(10**5)+10 for i in range(N): X[A[i]] += 1 data = np.rint(irfft(rfft(X, l)**2 )) num = 0 ans = 0 for i in range(len(data) -1 ,0,-1): if data[i] != 0: if num + data[i] >= M: ans += (M - num) * i break else: ans += data[i]*i num += data[i] print(int(ans))
n, m = map(int, input().split()) a = sorted(list(map(int, input().split())), reverse=True) s = [0] for ai in a: s.append(ai + s[-1]) def count(x, accum=False): ret = 0 for ai in a: lo, hi = -1, n while hi - lo > 1: mid = (lo + hi) // 2 if ai + a[mid] >= x: lo = mid else: hi = mid ret += ai * hi + s[hi] if accum else hi return ret lo, hi = 0, 1000000000 while hi - lo > 1: mid = (lo + hi) // 2 if count(mid) >= m: lo = mid else: hi = mid print(count(lo, accum=True) - (count(lo) - m) * lo)
1
108,093,660,941,428
null
252
252
R=int(input()) print((R*2)*3.14)
r = int(input()) print(r*2*3.141)
1
31,496,622,911,588
null
167
167
N = int(input()) A = list(map(int, input().split())) sm=0 mod=10**9+7 s=sum(A) for i in A: s-=i sm+=i*s sm%=mod print(sm)
n = int(input()) a = list(map(int,input().split())) mod = 10**9 + 7 temp = sum(a)**2 for x in a: temp -= x**2 print((temp//2)%mod)
1
3,793,472,775,530
null
83
83
x = int(input()) y = 0 z = 100 while z<x: y+=1 z *= 101 z //= 100 print(y)
def main(): x = int(input()) total = 100 for i in range(10**5): if total >= x: print(i) return total += total//100 if __name__ == "__main__": main()
1
27,040,900,396,572
null
159
159
N = int(input()) As = list(map(int,input().split())) dic = {} array = [] x = As[0] init = 1 - x for i in range(1,N): v = init + i - 1 - As[i] array.append(v) if v not in dic: dic[v] = 1 else: dic[v] += 1 if 0 in dic: ans = dic[0] else: ans = 0 for i in range(1,N): y = As[i] + i - x z = array[i-1] dic[z] -= 1 if y in dic: ans += dic[y] print(ans)
from collections import Counter N = int(input()) nums = list(map(int, input().split())) A = [i + n for i, n in enumerate(nums, start=1)] B = [j - n for j, n in enumerate(nums, start=1)] BC = Counter(B) answer = 0 for a in A: answer += BC[a] print(answer)
1
25,889,556,717,680
null
157
157
import sys def solve(a_list): for a in a_list: if a % 2 == 0: if a % 3 != 0 and a % 5 != 0: return False return True def main(): input = sys.stdin.buffer.readline _ = int(input()) a_list = list(map(int, input().split())) print("APPROVED" if solve(a_list) else "DENIED") if __name__ == "__main__": main()
N = int(input()) A = list(map(int,input().split())) B = len([i for i in A if i % 2==0]) count = 0 for i in A: if i % 2 !=0: continue elif i % 3 ==0 or i % 5==0: count +=1 if count == B: print('APPROVED') else: print('DENIED')
1
69,212,276,845,800
null
217
217
N = int(input()) A = [list(map(int, input().split())) for i in range(N)] # N = 3 # A = [[1, 3], [2, 5], [1, 7]] if N % 2 == 1: minA = sorted([row[0] for row in A]) maxA = sorted([row[1] for row in A]) medA = minA[int(N/2)] medB = maxA[int(N/2)] print(medB-medA+1) else: minA = sorted([row[0] for row in A]) maxA = sorted([row[1] for row in A]) medA = (minA[int(N/2-1)]+minA[int(N/2)])/2 medB = (maxA[int(N/2-1)]+maxA[int(N/2)])/2 print(int((medB-medA)*2+1))
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 == 0: print(0.5) else: print(1.0-((N-1)//2.0)/N)
0
null
96,978,666,369,704
137
297
from collections import defaultdict def main(): d = defaultdict(int) d2 = defaultdict(int) N = int(input()) A = list(map(int, input().split())) for i in range(N): d[i + 1 + A[i]] += 1 d2[max(0, (i + 1) - A[i])] += 1 ans = 0 for k,v in d.items(): if k == 0:continue ans += v * d2[k] print(ans) if __name__ == '__main__': main()
from collections import Counter n = int(input()) a = list(map(int,input().split())) ja1 = [] ja2 = [] for i in range(1,n+1): ja1.append(i-a[i-1]) ja2.append(i+a[i-1]) s = Counter(ja1) t = Counter(ja2) su = 0 for i in s.keys(): su += s[i]*t[i] print(su)
1
26,146,776,816,720
null
157
157
def main(): A, B, K = map(int, input().split()) r = max(0, A + B - K) a = min(r, B) t = r - a print(t, a) if __name__ == '__main__': main()
if __name__ == '__main__': N, K = map(int, input().split()) have_snack = [] for i in range(K): n = int(input()) have_snack.extend(list(map(int, input().split()))) ans = N - len(set(have_snack)) print(ans)
0
null
64,175,508,099,472
249
154
N=int(input()) ans =1 A = list(map(int,input().split())) for i in A: if i == 0: print(0) exit() for i in A: ans *=i if ans >10**18: print(-1) exit() print(ans)
N=int(input()) L=list(map(int,input().split())) A=1 if 0 in L: print(0) exit() for i in range(N): A=A*L[i] if 10**18<A: print(-1) exit() print(A)
1
16,196,670,046,156
null
134
134
import math import itertools n=int(input()) d=[list(map(int,input().split())) for _ in range(n)] ans=cnt=0 for i in itertools.permutations([_ for _ in range(n)]): for j in range(n-1): x1,x2=d[i[j]][0],d[i[j+1]][0] y1,y2=d[i[j]][1],d[i[j+1]][1] ans+=math.sqrt((x1-x2)**2+(y1-y2)**2) cnt+=1 #print(j,ans,cnt) print(ans/cnt)
N = int(input()) towns = [tuple(map(int, input().split())) for _ in range(N)] total_distance = 0 count = 0 for start in range(N-1): for end in range(start+1, N): start_x, start_y = towns[start] end_x, end_y = towns[end] total_distance += ((end_x - start_x)**2 + (end_y - start_y)**2)**0.5 count += 1 answer = total_distance * ((N - 1) / count) print(answer)
1
148,499,364,377,432
null
280
280
import sys N = int(sys.stdin.readline().rstrip()) A = list(map(int, sys.stdin.readline().rstrip().split())) mod = 10**9 + 7 color = A.count(0) ans = 1 cnt = [0] * N for a in A: if a > 0: ans *= (cnt[a - 1] - cnt[a]) cnt[a] += 1 ans %= mod for i in range(cnt[0]): ans *= 3 - i print(ans % mod)
a=int(input()) b=100 i=0 while b<a: b+= b // 100 i+=1 print(i)
0
null
78,557,951,145,180
268
159
from functools import lru_cache @lru_cache(maxsize=None) def solve(i, count): global ans global a if count >= N: return if ans[i][0] == -1: ans[i][0] = count elif ans[i][0] > count: ans[i][0] = count for x in range(a[i][1]): solve(a[i][2 + x] - 1, count + 1) N = int(input()) a = [] for _ in range(N): a.append([int(x) for x in input().split()]) ans = [[-1 for i in range(1)] for j in range(N)] solve(0, 0) for i, x in enumerate(ans): print(i + 1, *x)
import sys from functools import reduce n=int(input()) s=[input() for i in range(n)] t=[2*(i.count("("))-len(i) for i in s] if sum(t)!=0: print("No") sys.exit() st=[[t[i]] for i in range(n)] for i in range(n): now,mi=0,0 for j in s[i]: if j=="(": now+=1 else: now-=1 mi=min(mi,now) st[i].append(mi) now2=sum(map(lambda x:x[0],filter(lambda x:x[1]>=0,st))) v,w=list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st)) v.sort(reverse=True,key=lambda z:z[1]) w.sort(key=lambda z:z[0]-z[1],reverse=True) #print(now2) for vsub in v: if now2+vsub[1]<0: print("No") sys.exit() now2+=vsub[0] for wsub in w: if now2+wsub[1]<0: print("No") sys.exit() now2+=wsub[0] print("Yes")
0
null
11,854,136,794,610
9
152
n = int(input()) s = input() if n % 2 == 1: res = "No" else: if s[:n//2] == s[n//2:]: res = "Yes" else: res = "No" print(res)
def main(): n = int(input()) s = input() if n % 2 == 0: if s[:n // 2] == s[n // 2:]: ans = "Yes" else: ans = "No" else: ans = "No" print(ans) if __name__ == "__main__": main()
1
146,920,359,772,060
null
279
279
n = int(input()) s = input() int_s = [int(i) for i in s] pc = s.count('1') def f(x): bi = bin(x) pc = bi.count('1') cnt = 1 while True: if x == 0: break x = x % pc bi = bin(x) pc = bi.count('1') cnt += 1 return cnt num_pl = 0 for i in range(n): num_pl = (num_pl*2) % (pc+1) num_pl += int_s[i] num_mi = 0 for i in range(n): if pc-1 <= 0: continue num_mi = (num_mi*2) % (pc-1) num_mi += int_s[i] ans = [0]*n pc_pl, pc_mi = pc+1, pc-1 r_pl, r_mi = 1, 1 for i in range(n-1, -1, -1): if int_s[i] == 0: num = num_pl num = (num+r_pl) % pc_pl else: num = num_mi if pc_mi <= 0: continue num = (num-r_mi+pc_mi) % pc_mi ans[i] = f(num) r_pl = (r_pl*2) % pc_pl if pc_mi <= 0: continue r_mi = (r_mi*2) % pc_mi print(*ans, sep='\n')
def popcount(x): xb = bin(x) return xb.count("1") def solve(x, count_1): temp = x %count_1 if(temp == 0): return 1 else: return 1 + solve(temp, popcount(temp)) n = int(input()) x = input() x_b = int(x, 2) mod = x.count("1") xm1 = x_b %(mod+1) if(mod != 1): xm2 = x_b %(mod-1) for i in range(n): if(x[i] == "0"): mi = (((pow(2, n-1-i, mod+1) + xm1) % (mod+1))) if(mi == 0): print(1) else: print(1 + solve(mi, popcount(mi))) else: if(mod == 1): print(0) else: mi = ((xm2-pow(2, n-1-i, mod-1)) % (mod-1)) if((x_b - xm2 == 0)): print(0) elif(mi == 0): print(1) else: print(1 + solve(mi, popcount(mi)))
1
8,253,640,340,240
null
107
107
N = int(input()) anser = 'APPROVED' A_list = list(map(int, input().split())) for A in A_list: if A % 2 == 1: continue if A % 3 == 0: continue if A % 5 == 0: continue anser = 'DENIED' break print(anser)
N = input() A = list(map(int, input().split())) print('APPROVED' if all(a & 1 or a % 3 == 0 or a % 5 == 0 for a in A) else 'DENIED')
1
68,878,423,532,070
null
217
217
r,c = map(int,input().split()) rc = list([int(x) for x in input().split()] for _ in range(r)) [rc[i].append(sum(rc[i])) for i in range(r)] rc.append([sum(i) for i in zip(*rc)]) for col in rc: print(*col)
r, c = map(int, input().split()) data = [] for y in range(r): row = list(map(int, input().split())) data.append(row) colsum = [0 for i in range(c + 1)] for y in range(r): data[y].append(sum(data[y])) for x in range(c + 1): colsum[x] += data[y][x] data.append(colsum) for y in range(r + 1): print(*data[y])
1
1,332,736,178,562
null
59
59
a = input() print(a.replace("?","D"))
a,b = map(float, raw_input().split()) d = int(a / b) e = int(a % b) r = a / b print "%d %d %f" %(d,e,r)
0
null
9,514,150,561,700
140
45
import time start = time.time() n = int(input()) a = list(map(int,input().split())) b = [] m = 0 for i in range(1,n): m = m ^ a[i] b.append(m) for j in range(1,n): m = m ^ a[j-1] m = m ^ a[j] b.append(m) b = map(str,b) print(' '.join(b))
n = int(input()) a = list(map(int, input().split())) def nim(x): bx = [format(i,'030b') for i in x] bz = ''.join([str( sum([int(bx[xi][i]) for xi in range(len(x))]) % 2) for i in range(30)]) return int(bz, 2) nima = nim(a) ans = [ str(nim([nima,aa])) for aa in a ] print(' '.join(ans) )
1
12,496,757,529,618
null
123
123
from collections import defaultdict as dict n, p = map(int, input().split()) s = input() a = [] for x in s: a.append(int(x)) def solve(): l = [0]*p ans = 0 for x in a: l_ = [0] * p for i in range(p): l_[(i * 10 + x) % p] += l[i] l, l_ = l_, l l[x % p] += 1 ans += l[0] print(ans) if p <= 5: solve() exit() x = 0 mem = dict(int) mem[0] = 1 ans = 0 a.reverse() d = 1 for y in a: x += d*y x %= p d = (d * 10) % p ans += mem[x] mem[x] += 1 # print(mem) print(ans)
N,P=map(int,input().split());S,a,i,j,c=input(),0,0,1,[1]+[0]*P if 10%P: for v in S[::-1]:i,j=(i+int(v)*j)%P,j*10%P;a+=c[i];c[i]+=1 else: for v in S: i+=1 if int(v)%P<1:a+=i print(a)
1
57,849,120,385,430
null
205
205
A, B = map(int, input().split()) if A <= 9 and B <= 9: print(A * B) else: print("-1")
def judge99(x): if x <= 9: return True else: return False a, b = map(int,input().split()) if judge99(a) and judge99(b): print(a*b) else: print(-1)
1
158,377,435,265,840
null
286
286
x, y, z = input().split() a = int(x) b = int(y) c = int(z) count = 0 num = a while num <= b: if c % num == 0: count += 1 else: pass num += 1 print(count)
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): r = int(input()) print(r**2) if __name__ == '__main__': main()
0
null
72,610,639,654,202
44
278
def bubblesort(N, A): c, flag = 0, 1 while flag: flag = False for j in range(N-1, 0, -1): if A[j] < A[j-1]: A[j], A[j-1] = A[j- 1], A[j] c += 1 flag = True return (A, c) A, c = bubblesort(int(input()), list(map(int, input().split()))) print(' '.join([str(v) for v in A])) print(c)
def bubble(A,N): flag=1 cnt=0 while flag==1: flag=0 for j in range(1,N): if A[j]<A[j-1]: k=A[j-1] A[j-1]=A[j] A[j]=k flag=1 cnt+=1 return A,cnt n=int(raw_input()) list=map(int,raw_input().split()) list,cnt=bubble(list,n) for x in list: print x, print print cnt,
1
16,817,994,420
null
14
14
n = int(input()) abc="abcdefghijklmnopqrstuvwxyz" ans = "" while True: n -= 1 m = n % 26 ans += abc[m] n = n // 26 if n == 0: break print(ans[::-1])
n=int(input()) def ans(x): a=26 b=1 k=1 ch=0 while ch==0: if b<= x <= b+a**k-1: ch+=1 return k,x-(b-1) else: b=b+a**k k+=1 s,t=ans(n) ans1='' c='abcdefghijklmnopqrstuvwxyz' for i in range(1,s+1): q=0 f=26**(s-i) if i!=s: cc=0 while cc==0: e=t-f*(q+1) if e>0: q+=1 else: cc+=1 if q==25: break t-=f*q g=c[q] ans1=ans1+g else: g=c[t-1] ans1=ans1+g print(ans1)
1
11,846,780,425,778
null
121
121
def main(): mountain=[] for i in range(10): num=int(input()) mountain.append(num) mountain=sorted(mountain) mountain=mountain[::-1] for i in range(3): print(mountain[i]) if __name__=='__main__': main()
a = [] for i in range(10): a.append(int(raw_input())) a.sort() a.reverse() for i in range(3): print a[i]
1
13,362,240
null
2
2
a,b,c=map(int,input().split()) y=0 for i in range(b-a+1): j=1 while (i+a)*j <= c: if (i+a)*j==c: y+=1 break j+=1 print(y)
a, b, c = map(int, raw_input().split()) counter = 0 for i in xrange(a, b+1): if c % i == 0: counter += 1 print counter
1
559,602,537,638
null
44
44
import math def main(): n = int(input()) r = 2 * math.pi * n print(round(r,2)) main()
r = int(input()) print(6.3*r)
1
31,535,961,363,104
null
167
167
import sys read = sys.stdin.buffer.read MOD = 1000000007 def main(): N, *A = map(int, read().split()) M = 60 ans = 0 p = 1 for _ in range(M): n = 0 for i, a in enumerate(A): if not a: continue A[i], d = a // 2, a % 2 if d: n += 1 ans = (ans + n * (N - n) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == '__main__': main()
# coding: utf-8 import math #n, k, s = map(int,input().split()) n = int(input()) A = list(map(int,input().split())) ans = 0 MOD=10**9+7 L0 = [0] * 60 L1 = [0] * 60 for i in range(n): b = A[i] #print(b) b = format(b, '060b') #print(b) for j in range(60): if b[60 - j -1] == "1": L1[j] += 1 else: L0[j] += 1 #print(L0) #print(L1) for i in range(60): ans += L0[i] * L1[i] * 2**i ans %= MOD print(ans)
1
123,078,101,606,228
null
263
263
import sys input = sys.stdin.readline (n, k), (r, s, p), t = map(int, input().split()), map(int, input().split()), input()[:-1] d, res = {'r': p, 's': r, 'p': s}, 0 for i in range(k): b = False for j in range(i, n, k): if i == j: res += d[t[j]]; b = False; continue if (t[j] != t[j-k]) | b: res += d[t[j]]; b = False else: b = True print(res)
k=int(input()) a,b = map(int,input().split()) ans="NG" for i in range(1001): if a<=(i*k)<=b : ans = "OK" print(ans)
0
null
66,761,415,096,640
251
158
N = input() A = list(map(int, input().split())) print('APPROVED' if all(a & 1 or a % 3 == 0 or a % 5 == 0 for a in A) else 'DENIED')
n = int(input()) a = list(map(int, input().split())) for i in range(n): if a[i]%2 == 0: if (a[i]%3 != 0) and (a[i]%5 != 0): print('DENIED') exit() print('APPROVED')
1
69,174,143,001,390
null
217
217
#coding:utf-8 i = input() q = [] for n in range(i): l = map(int, raw_input(). split()) a = min(l) l.remove(min(l)) b = min(l) c = max(l) if a ** 2 + b ** 2 == c ** 2: q.append("YES") else: q.append("NO") for s in xrange(len(q)): print(q[0]) q.pop(0)
import sys for i, x in enumerate(map(int, sys.stdin)): if x == 0 or not x: break; print('Case {0}: {1}'.format(i + 1, x))
0
null
239,237,353,112
4
42
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)
def b171(n, k, plist): plist.sort() return sum(plist[:k]) def main(): n, k = map(int, input().split()) plist = list(map(int, input().split())) print(b171(n, k, plist)) if __name__ == '__main__': main()
1
11,697,079,365,962
null
120
120
# unionfind class Uf: def __init__(self, N): self.p = list(range(N)) self.rank = [0] * N self.size = [1] * N def root(self, x): if self.p[x] != x: self.p[x] = self.root(self.p[x]) return self.p[x] def same(self, x, y): return self.root(x) == self.root(y) def unite(self, x, y): u = self.root(x) v = self.root(y) if u == v: return if self.rank[u] < self.rank[v]: self.p[u] = v self.size[v] += self.size[u] self.size[u] = 0 else: self.p[v] = u self.size[u] += self.size[v] self.size[v] = 0 if self.rank[u] == self.rank[v]: self.rank[u] += 1 def count(self, x): return self.size[self.root(x)] N, M, K = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(M)] CD = [list(map(int, input().split())) for _ in range(K)] uf = Uf(N+1) M = [-1] * (N+1) for a, b in AB: uf.unite(a, b) M[a] -= 1 M[b] -= 1 for c, d in CD: if uf.same(c, d): M[c] -= 1 M[d] -= 1 for i in range(1, N+1): M[i] += uf.count(i) print(" ".join(map(str, M[1:])))
#!/usr/bin/env python3 import sys from collections import deque sys.setrecursionlimit(1000000) class UnionFind: def __init__(self, num): self.par = list(range(1,num+1)) self.size = [1]*num def root(self, n): if self.par[n-1] != n: self.par[n-1] = self.root(self.par[n-1]) return self.par[n-1] def unite(self, a, b): a=self.root(a) b=self.root(b) if a!=b: self.par[b-1]=a self.size[a-1] += self.size[b-1] return def get_size(self, n): return self.size[self.root(n)-1] def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"): fris = [0]*N blos = [0]*N union = UnionFind(N) for ai, bi in zip(A, B): union.unite(ai,bi) fris[ai-1]+=1 fris[bi-1]+=1 for ci, di in zip(C, D): if union.root(ci) == union.root(di): blos[ci-1]+=1 blos[di-1]+=1 ans = [0]*N for i in range(1,N+1): s = union.get_size(i) s -= fris[i-1] s -= blos[i-1] s -= 1 ans[i-1] = s print(*ans) 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 M = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int()] * (M) # type: "List[int]" B = [int()] * (M) # type: "List[int]" for i in range(M): A[i] = int(next(tokens)) B[i] = int(next(tokens)) C = [int()] * (K) # type: "List[int]" D = [int()] * (K) # type: "List[int]" for i in range(K): C[i] = int(next(tokens)) D[i] = int(next(tokens)) solve(N, M, K, A, B, C, D) if __name__ == '__main__': main()
1
61,340,382,834,048
null
209
209
count = 1 while(True): x = int(input()) if x == 0: break print('Case {}: {}'.format(count, x)) count += 1
x=int(input()) n=x//500 m=x%500 k=m//5 print(1000*n+5*k)
0
null
21,768,762,431,900
42
185
def resolve(): # 十進数表記で1~9までの数字がK個入るN桁の数字の数を答える問題 S = input() K = int(input()) n = len(S) # dp[i][k][smaller]: # i:桁数 # K:0以外の数字を使った回数 # smaller:iまでの桁で値以上になっていないかのフラグ dp = [[[0] * 2 for _ in range(4)] for _ in range(105)] dp[0][0][0] = 1 for i in range(n): for j in range(4): for k in range(2): nd = int(S[i]) for d in range(10): ni = i+1 nj = j nk = k if d != 0: nj += 1 if nj > K: continue if k == 0: if d > nd: # 値を超えている continue if d < nd: nk += 1 dp[ni][nj][nk] += dp[i][j][k] ans = dp[n][K][0] + dp[n][K][1] print(ans) if __name__ == "__main__": resolve()
ln = input().split() print(ln[1]+ln[0])
0
null
89,566,786,480,560
224
248
n=int(input()) a=[int(x) for x in input().rstrip().split()] now=1 mod=10**9+7 def lcm(a,b):#最小公倍数 ori_a=a ori_b=b while b!=0: a,b=b,a%b return (ori_a*ori_b)//a for i in a: now=lcm(i,now) # print(now) print(sum([now//i for i in a])%mod)
S = input() t = 'i' for l in S: if t == 'h' and l == 'i': t = 'i' elif t == 'i' and l == 'h': t = 'h' else: print('No') exit() if t == 'h': print('No') exit() print('Yes')
0
null
70,239,419,714,140
235
199
n = int(input()) movies = {} summize = 0 for i in range(n): input_str = input().split() summize += int(input_str[1]) movies.setdefault(input_str[0], summize) title = input() print(summize - movies[title])
N=int(input()) S=input() tmp="" for i in range(len(S)): chtmp=ord(S[i])+N if(chtmp>ord('Z')): chtmp-=(ord('Z') - ord('A') + 1) tmp+=chr(chtmp) print(tmp)
0
null
115,456,034,468,100
243
271
n = int(input()) s="" keta=0 n-=1 while 1 : c = n%26 s=chr( 97+c )+s if n//26>0 : n=n//26 n-=1 keta+=1 else: break print(s)
def base_10_to_n(x, n): ans = [] while x > 0: x -= 1 ans.append(str(x % n + 1)) x //= n return ans[::-1] a = base_10_to_n(int(input()), 26) ans1 = '' for i in a: ans1 += chr(ord('a') + int(i) - 1) print(ans1)
1
11,966,953,251,162
null
121
121
x,y=map(int,input().split()) if y%2 == 1: print('No') elif x*2 > y: print('No') elif x*4 < y: print('No') else: print('Yes')
x, y = map(int, input().split()) if y % 2 == 0 and x*2 <= y <= x*4: print('Yes') else: print('No')
1
13,686,634,799,280
null
127
127
#!/usr/bin/env python3 import sys INF = 1<<32 MOD = 1000000007 # type: int # 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 def solve(n: int, k: int): fact = [1] * (n+1) ifact = [1] * (n+1) for i in range(1, n+1): fact[i] = i*fact[i-1] % MOD ifact[-1] = pow(fact[-1], MOD-2, MOD) for i in range(n-1, 0, -1): ifact[i] = ifact[i+1] * (i+1) % MOD def comb(n, r, MOD=10**9+7): return fact[n] * ifact[n-r] * ifact[r] % MOD ans = 0 for i in range(min(k, n-1)+1): ans += comb(n, i) * comb(n-1, i) % MOD ans %= MOD print(ans) 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()
a,b,k=map(int,input().split()) s=k-a t=k-a-b if s>=0: if t>=0: print(0,0) else: print(0,a+b-k) else: print(a-k,b)
0
null
85,503,451,018,236
215
249
S = input() N = len(S) ans = 0 for i in range(N//2): if S[i] != S[N-i-1]: ans += 1 print(ans)
import math s=input() count=0 for i in range(0,math.floor(len(s)/2)): if s[i]!=s[len(s)-i-1]: count=count+1 print(count)
1
120,063,022,430,428
null
261
261
f=lambda:map(int,input().split()) n,d,a=f() lt=sorted(tuple(f()) for _ in range(n)) from collections import * q=deque() c=s=0 for x,h in lt: while q and q[0][0]<x: s+=q.popleft()[1] h-=s if h>0: t=-h//a; c-=t; s-=t*a; q.append((x+d*2,t*a)) print(c)
from collections import Counter n=int(input()) a=list(map(int,input().split())) c=Counter(a) for i in range(1,n+1): print(c[i])
0
null
57,451,998,320,530
230
169
a, b, x = map(int, input().split()) if x >= a**2*b/2: t = 2*(b*a**2-x)/(a**3) else: t = (a*b**2)/(2*x) import math p = math.atan(t) p = math.degrees(p) print(p)
from decimal import Decimal import math a, b, x = list(map(Decimal, input().split())) if a * a * b > 2 * x: tri = x / a c = tri * Decimal(2) / b d = (c ** 2 + b ** 2) ** Decimal("0.5") cos_a = (b ** 2 + d ** 2 - c ** 2) / (2*b*d) print(90 - math.degrees(math.acos(cos_a))) else: tri = (a * a * b - x) / a e = tri * Decimal(2) / a f = (a ** 2 + e ** 2) ** Decimal("0.5") cos_e = (f ** 2 + a ** 2 - e ** 2) / (2*f*a) print(math.degrees(math.acos(cos_e))) #print(cosin)
1
163,527,029,354,798
null
289
289
n = int(input()) if 360%n: print(360//(360%n)*(360//n)) else: print(360//n)
X = int(input()) tmp = 360 while True: if tmp % X == 0: print(tmp//X) exit() else: tmp+= 360
1
13,098,348,747,762
null
125
125
a1=input() a2=[i for i in a1.split()] a3,a4=[a2[i] for i in (0,1)] A,B=int(a3),int(a4) print(max(0,A-2*B))
a = list(map(int,input().split())) x = a[1]*2 if x>=a[0]: print(0) else: print(a[0]-x)
1
166,878,286,038,310
null
291
291
n,k = map(int, input().split()) p = [int(x) for x in input().split()] p_kitaiti=[float((x+1)/2) for x in p] ruisekiwa=[p_kitaiti[0]] for i in range(1,len(p_kitaiti)): ruisekiwa.append(ruisekiwa[-1]+p_kitaiti[i]) ans=ruisekiwa[k-1] for i in range(1,len(ruisekiwa)-k+1): ans=max(ans,ruisekiwa[i+k-1]-ruisekiwa[i-1]) print(ans)
N, K, C = map(int, input().split()) S = input() mae = [0] * (2 * N) ato = [0] * (2 * N) cnt = 0 n = 0 - N - 100 for i in range(N): if i - n <= C: continue if S[i] == 'o': mae[cnt] = i cnt += 1 n = i cnt = K - 1 n = 2 * N + 100 for i in range(N-1, -1, -1): if n - i <= C: continue if S[i] == 'o': ato[cnt] = i cnt -= 1 n = i for i in range(K): if mae[i] == ato[i]: print(mae[i]+1)
0
null
57,969,743,646,456
223
182
N, K, C = list(map(int,input().split())) s = list(str(input())) L = [] # i+1日目に働くのはL[i]日目以降 R = [] # i+1日目に働くのはL[i]日目以前 for i in range(N): if len(L) >= K: break if s[i] == 'o' and (L == [] or (i + 1) - L[-1] > C): # 出勤可能('o') 且 (Lが空又はi日目時点の最終出勤からc日経過) # ならばLにi+1を追加 L.append(i + 1) for i in range(N - 1, -1, -1): if len(R) >= K: break if s[i] == 'o' and (R == [] or R[-1] - (i + 1) > C): R.append(i + 1) R.reverse() ans = [] for i in range(K): if L[i] == R[i]: print(L[i])
n, k, c = map(int, input().split()) s = input() work = [1]*n rest = 0 for i in range(n): if rest: rest -= 1 work[i] = 0 continue if s[i] == 'x': work[i] = 0 elif s[i] == 'o': rest = c rest = 0 for i in reversed(range(n)): if rest: rest -= 1 work[i] = 0 continue if s[i] == 'o': rest = c if k < sum(work): print() else: for idx, bl in enumerate(work): if bl: print(idx+1)
1
40,398,431,924,160
null
182
182
k = int(input()) a,b = map(int,input().split()) ans = 0 for i in range(a//k,b//k+1): if a <= k * i <= b: ans = 1 if ans == 1: print('OK') else: print('NG')
K = int(input()) A, B = map(int, input().split()) MaxKx = B//K*K if MaxKx >= A : print('OK') else : print('NG')
1
26,417,405,656,710
null
158
158
i,j=map(int,input().split()) listA=[] for n in range(i): listA.append(list(map(int,input().split()))) listA[n].append(sum(listA[n])) listA.append([]) for n in range(j+1): number=0 for m in range(i): number+=listA[m][n] listA[i].append(number) for n in range(i+1): print(' '.join(map(str,listA[n])))
word = list(input()) if word[-1] == "s": word.append("es") ans = "".join(word) else: word.append("s") ans = "".join(word) print(ans)
0
null
1,884,952,594,812
59
71
def solve(n): su = 0 for i in range(1, n+1): m = n//i su += m*(2*i + (m-1)*i)//2 return su n = int(input()) print(solve(n))
n = int(input()) a = [int(i) for i in input().split()] cnt = [0]*(n+1) cnt[-1] = 3 mod = 1000000007 ans = 1 for i in range(n): ans *= cnt[a[i]-1] ans %= mod cnt[a[i]-1] -= 1 cnt[a[i]] += 1 print(ans)
0
null
70,517,643,684,150
118
268
N=int(input()) list1 = list(map(int, input().split())) list2=[] for i in list1: if i%2==0: list2.append(i) else: continue list3=[] for j in list2: if j%3==0 or j%5==0: list3.append(j) else: continue x=len(list2) y=len(list3) if x==y: print('APPROVED') else: print('DENIED')
n=int(input()) a=list(map(int,input().split())) for i in range(n): if a[i]%2==1: pass else: if a[i]%3==0 or a[i]%5==0: pass else: print("DENIED") exit() print("APPROVED")
1
69,269,696,397,276
null
217
217