anchor
stringlengths
10
14.3k
positive
stringlengths
10
14.9k
import java.io.*; import java.util.*; public class CF { class Pers { int id, left, right, v; Pers(int id, int left, int v, int right) { this.id = id; this.left = left; this.right = right; this.v = v; } } int MAX = (int) (3 * 1e5 + 11); class SegTree { int n; int[] sum; int[] maxPref; ...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.wri...
import java.util.*; import java.lang.*; import java.io.*; public class GFG { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuffer sb = new StringBuffer(); int Q = Integer.parseInt(br.readLine()); for(int q = 0; q < Q...
#include <bits/stdc++.h> #pragma GCC optimize "O3" using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int N = 4000; int huh[N + 5]; int ile[N + 5], pt; void solve() { memset(ile, 0, sizeof(ile)); int n; cin >> n; pt = N; while (n) { ile[pt] += n / huh[pt]; ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.UncheckedIOException; import java.util.Objects; import java.nio.charset.C...
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++) #define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++) #define ALL(obj) begin(obj), end(obj) #define RALL(obj) rbegin(obj), rend(obj) #define fi first #define se s...
import java.util.*; public class Main { Scanner in = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main() { new Problem_B(); } class Problem_B{ int h,w,ph,pw; int[][] a; boolean[][] b; boolean[][] c; int sum(int start_x,int start_y){ int result = 0; f...
#ifndef _WIN32 #include<iostream> #endif #include<cmath> #include<iomanip> #include<algorithm> #include<vector> #include<string> using namespace std; typedef long long LL; #define FOR(i,bg,ed) for(int (i)=(bg);(i)<(ed);(i)++) #define REP(i,n) FOR(i,0,n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0);...
n = int(raw_input()) a = map(int, raw_input().split()) m = int(raw_input()) b = map(int, raw_input().split()) if sum(a) != sum(b): print -1 else: sum_a, sum_b, i, j = 0, 0, 0, 0 output = 0 while i < n: output += 1 sum_a += a[i] sum_b += b[j] i += 1 j += 1 while sum_a != sum_b: if sum_a < sum_b: ...
import java.util.*; import java.io.*; public class Forces{ public static void main(String ...arg) { Read cin = new Read(); long sum1 = 0,sum2=0; int n = cin.nextInt(); Long[] a = new Long[n]; for(int i=0;i<n;i++) { a[i] = cin.nextLong(); sum1 += a[i]; } int m = cin.nextInt(); Long[] b = ...
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[200000], arr1[200000] = {}, counter = 1, counter2 = 0, index; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; if (counter2 == 0 && arr[i] == 0) { index = i; counter2++; arr1[i] = 0; } } for (int i = inde...
import math #t=int(input()) #for i in range(t): #n,a,b = map(int, input().strip().split(' ')) n=int(input()) lst = list(map(int, input().strip().split(' '))) p=[] for j in range(n): if lst[j]==0: p.append(j) l=len(p) #print(p) if l==1: for j in range(n): print(abs(p[0]-j),end=" ") else: i1=0...
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; /* public class _480D { } */ public cla...
#include <bits/stdc++.h> using namespace std; int MAX_N = 500; int MAX_DURABILITY = 1000; int N, S; vector<int> in, out, weight, durability, value; vector<vector<int> > start; vector<vector<int> > finish; vector<int> temp; vector<vector<int> > cache; int solve(int part, int D) { int &result = cache[part][D]; if (re...
import java.util.Scanner; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(), k = sc.nextInt(); System.out.println((n + 1) / 2 >= k ? "YES" : "NO"); } }
n, k = map(int, input().split()) if n >= k*2-1: print('YES') else: print('NO')
def aaa(): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input())) b=[0]+b+[0] for ii in range(n): aa=a[ii] bl=b[ii] br=b[ii+1] if bl==0: lo=hi=aa l1=ii+1 else: lo=min(lo,aa) hi=max(hi,aa) if br==0: r1=ii+1 if lo!=l1 or hi!=r1: return 1 aaa=aaa() print("NO" if aaa...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pranay2516 */ public class...
from fractions import gcd n=input() nums=map(int,raw_input().split()) mx=max(nums);nums.sort() difMax=map(lambda x:mx-x,nums) y=reduce(gcd,difMax) z=sum(difMax)/y print z,y
import java.util.Scanner; public class cf { static long maxx(long a,long b){ if(a > b)return a; else return b; } static long Quick_GCD(long a,long b) { if(a==0) return b; if(b==0) return a; if(!(a%2==1)&&!(b%2==1)) { return Quick_GCD(a>>1,b>>1)<<1; } else if(!(b%2==1)) ...
n = int(input()) a = [int(x) for x in input().strip().split()] a = sorted(a) d = [] for i in range(len(a) - 1): d.append(a[i + 1] - a[i]) def gcd(a, b): if(b == 0): return a else: return gcd(b, a % b) g = d[0] for e in d: g = gcd(g, e) cnt = len(a) print( int( ( a[len(a) - 1] -...
import java.util.*; public class Solution { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); Long[] arr=new Long[n]; for(int i=0;i<n;i++) { arr[i]=in.nextLong(); } Arrays.sort(arr); long s...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") const double PI(acos(-1.0)); using namespace std; long double dp[55][55][55], cnk[55][55]; int v[55]; int main() { cout.precision(2); srand(unsigned(time(nullptr))); int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) scanf("%d", &v[...
import java.io.*; import java.util.*; import java.math.*; public class c { int stud, room; int[] wash; double[][][] prob; long[][] c; void solve() throws Exception { stud = nextInt(); room = nextInt(); wash = new int[room]; for (int i = 0; i < room; ++i) wash[i] = nextInt(); c = new long[51][51]; ...
#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <stack> #include <vector> #include <map> #include <set> #include <queue> #include <list> #include <iostream> #include <climits> #include <cfloat> using namespace std; double distance(double x1, double y1, double x2,...
import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { final int n = sc.nextInt(); if(n == 0){ break; } Point2D[] input = new Point2D[n]; for(int i = 0; i < n; i++){ S...
N, K = map(int, input().split(" ")) print(N - K if K >= 2 else 0)
#include <iostream> using namespace std; int main(){ int n, k; cin >> n >> k; if( k != 1) cout << n - k; else cout << 0; return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int arr[107]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; int cnt = arr[0]; for (int i = 1; i < n; i++) { int curr = arr[i]; if (cnt > curr) swap(cnt, cu...
n = int(input()) x = list(map(int, input().split())) ##greatest common divisor def gcd(a , b): while b > 0: (a, b) = (b, a % b) return a res = x[0] for i in x[1:]: res = gcd(res, i) print(res*len(x))
#include <bits/stdc++.h> inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int N = 1e5 + 5; int n, m, k, p, a[N], h[N]; pair<long long, i...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOExcept...
#include <bits/stdc++.h> using namespace std; const int MAXN = 300000; int n, m; vector<int> v[MAXN]; bool u[MAXN]; pair<long long, long long> dfs(int x) { u[x] = true; pair<long long, long long> res{1, 0}; for (int y : v[x]) { if (!u[y]) { pair<long long, long long> cur = dfs(y); res.first += cur...
//package Graphs; import java.io.PrintWriter; import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; public class M771A { public static Scanner enter = new Scanner(System.in); public static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { ...
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void wr...
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class A5 { InputStream is; PrintWriter out; String INPUT = ""; final int mod = 1000000007; public static int[][] enu...
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 0, k, p, a, i, e = 0, b, c, d, cou = 0; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a; if (a <= k) m++; else { p = a / k; b = a % k; if (p % 2 == 1 && b != 0) { p++; cou = cou + (p / 2); ...
n, k = map(int, input().split()) w = list(map(int, input().split())) q=0 t=0 for i in range(n): a=w[i]//k w[i]%=k q+=(a//2) t+=(a%2) # print(a, w[i], t, q) if t==2: t=0 q+=1 if w[i]>0: if t==1: t=0 w[i]=0 q+=1 else: w[i]=0 t+=1 if t>0: q+=1 print(q)
#define _CRT_SECURE_NO_WARNINGS #include "stdio.h" #include <vector> #include "memory.h" #include "string.h" #include "math.h" #include <set> #include <map> #include <iostream> #include <algorithm> #include <functional> #include <queue> using namespace std; vector<vector<int> > C; vector<vector<int> > N; vector<int...
import sys from heapq import heapify, heappop, _heapify_max, heappush, _heappop_max f = sys.stdin def line(): return f.readline().strip().split() class UnionFind: def __init__(self, n): self.link = [-1]*n self.rank = [0]*n def add_link(self,node,parent): self.link[node] = parent ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.util.ArrayList; import java.io.UncheckedIOException; import java.util.List; import java.io.Closeable; import java.io.Writer; import java.io.OutputStreamWriter; import...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MOD = 1e9 + 7; const int N = 1e5 + 10; int n, k, m, x, y, g[N], lv[N], depth; vector<int> v[N]; queue<int> q; bool check(int M) { long long sum = 0, cost = 1LL * M * depth; for (int R = depth, L = depth + 1; R > 0; R--) { while (L > 1 ...
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <set> using namespace std; int dx[] = {-1, -1, 0, 1, 1, 0}; int dy[] = {-1, 0, 1, 1, 0, -1}; vector<pair<int, int>> make_set(string &s, int i){ vector<pair<int, int>> ret; auto pos = make_pair(0, 0); ret.push_back(pos); for (a...
import java.util.*; import java.util.Scanner; import static java.lang.Math.*; public class Main { final Scanner sc=new Scanner(System.in); final int INF=Integer.MAX_VALUE/4; public static void main(String[] args) { new Main().doIt(); } void doIt(){ new AOJ1228(); } class AOJ1228{ final int[] vx={0,1,1,0,...
from __future__ import print_function from sys import stdin inp = [int(x) for x in stdin.read().split()] n, m = inp[0], inp[1] in_idx = 2 n += 1 adj = [[] for _ in range(n)] edge_index = [[] for _ in range(n)] for i in range(m): a = inp[in_idx] in_idx += 1 b = inp[in_idx] in_idx += 1 adj[a].append(b) edge_inde...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; int n, m; set<int> adj[N]; set<pair<int, int> > edges; void input() { scanf("%d %d", &n, &m); int u, v; for (int i = (0); i < (m); i++) { scanf("%d %d", &u, &v); adj[u].insert(v); adj[v].insert(u); if (u > v) { swap(u, v); ...
from sys import stdin,stdout,setrecursionlimit,maxint,exit #setrecursionlimit(2*10**5) def listInput(): return map(long,stdin.readline().split()) def printBS(li): for i in xrange(len(li)-1): stdout.write("%d "%li[i]) stdout.write("%d\n"%li[-1]) def sin(): return stdin.readline().rstrip() n,k=listInput() li=listIn...
#include <bits/stdc++.h> using namespace std; long long i, j, n, m, a[110000], k, num, ans, p; long long s[110000]; long long search(long long l, long long r, long long j) { long long c; if (l == r) return l; if (l == r - 1) { if ((j - l) * a[j] <= s[j - 1] - s[l - 1] + k) return l; return r; } c = (l...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int p = m; vector<int> ans; int cnt = 0; for (int i = 0; i < n; i++) { cnt = 0; if (a[i] <= p) { p -= a[i]; if (p == 0) { cnt++; p = ...
n, m = map(int, raw_input().split()) a_l = map(int, raw_input().split()) oc = 0 for a in a_l: first = min(a, m - oc) if a + oc < m: oc += first print 0, elif a + oc == m: oc = 0 print 1, else: ans = 1 a -= first ans += a / m oc = a % m print ans,
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; public class Main { int mod = 1000000007; ...
T = int(input()) for t in range(T): n = int(input()) A = [int(i) for i in input().split()] print(*A[::-1])
#include <bits/stdc++.h> using namespace std; int main () { int N, M; cin >> N >> M; int C = N + 1; vector<int> T(N); for (int i = 0; i < N; i++) T[i] = i + 1; for (int i = 0; i < M; i++) { int x, y; cin >> x >> y; x = T[x-1], y = T[y-1]; for (auto &j : T) { if ...
n, m = map(int, input().split()) q = [] for _ in range(m): a, b = map(int, input().split()) i, j = -1, -1 for k in range(len(q)): if i == -1: if a in q[k]: i = k if j == -1: if b in q[k]: j = k if i >= 0 and j >= 0: ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.util.PriorityQueue; import java.util.AbstractQueue; import java.util.Random; import java.util.ArrayList; import java.io.OutputStreamWriter; import java.io.OutputStream; import java.util.Co...
#include <bits/stdc++.h> using namespace std; const int N = 1e8; const int Maxn = 10010; int ansx[Maxn], xl, ansy[Maxn], yl; int main() { srand(233); int i, j, k; int t = rand() % N + 1; while (1) { cout << "0 " << t << " " << t << endl; int dis; cin >> dis; if (dis != 0) break; t = rand() %...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.concurrent.ThreadLocalRandom; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in *...
#include <bits/stdc++.h> using namespace std; long long n, m, ans, u, v, sum; long long a[100005], s[100005]; long long gcd(long long xx, long long yy) { long long r = xx % yy; if (r == 0) return yy; else return gcd(yy, r); } void solve() { long long i, j, g; u = 0; s[1] = 0; for (i = 2; i <= n; i...
//package round180; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; public class E { InputStream is; PrintWriter out; String INPUT = ""; void sol...
#include <bits/stdc++.h> using namespace std; const int MAXN(101); const int MAXE(5000010); const int MAXK(100010); const int MAXC(2); const int INF((INT_MAX - 1) / 2); const int BASE(20); const double LIM(1e50); const double EPS(1e-5); const double PER(0.02); const double MUL(3.5); int IT; template <typename T> inline...
import sys f = lambda s: int(s)-1 n = int(input()) b = [0]*(n+1) def update(bit,idx,val): idx += 1 while idx < n+1: bit[idx] += val idx += idx&(-idx) def getSum(bit,idx): idx += 1 ans = 0 while idx > 0: ans += bit[idx] idx -= idx&(-idx) return ans a = list(map(f...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const int M = 200010; const long long inf = 0x7fffffff; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { ...
#include <bits/stdc++.h> using namespace std; const long long inf = LONG_MAX; const long long arr = 1000000; bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first == b.first) return a.second < b.second; else return a.first < b.first; } int main(void) { long long n; cin >> n...
import java.util.Scanner; /** * Created by soumen.porel on 02/07/17. */ public class InfiniteSequence { public static void main(String[] atgs){ Scanner scanner = new Scanner(System.in); long num = scanner.nextLong(); long n = num; long j=1; for (int i=1; n > 0;i++){ ...
import java.util.Scanner; public class C54 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); double[]p = new double[n+1]; for (int i = 1; i <= n; i++) { long L = sc.nextLong(); long R = sc.nextLong(); ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0), eps = 1e-8; const int inf = ~0U >> 2; int mod = 1e9 + 7; int Pow(int x, long long t) { int r = 1; for (; t; t >>= 1, x = (long long)x * x % mod) if (t & 1) r = (long long)r * x % mod; return r; } const int N = 1010; int n; long long l...
from bisect import bisect import sys readline = sys.stdin.readline write = sys.stdout.write def construct(N, S, base, MOD): L = 26 root = [0, 0, N-1, [None]*L] nds = [root] for i, s in enumerate(S): node = root for c in s: h, a, b, nt = node if nt[c] is None: ...
#include <bits/stdc++.h> using namespace std; using psi = pair<string, int>; template <typename T> class merge_tree { const int n; vector<vector<T>> data; int size(int x) { int res; for (res = 1; res < x; res <<= 1); return res; } int query(int node, T val) { return lower_bound(data[node].begin(), data[no...
import java.util.*; import static java.lang.System.*; public class Main { Scanner sc = new Scanner(in); void run() { int m; int money, year, n; m = sc.nextInt(); for (int i = 0; i < m; i++) { money = sc.nextInt(); year = sc.nextInt(); n = sc.nextInt(); int max = 0; for (int j = 0; j < n; j+...
import sys n = int(raw_input()) for i in xrange(n): im = int(raw_input()) y = int(raw_input()) n = int(raw_input()) fm = 0 for j in xrange(n): w, ir, c = raw_input().split() w, ir, c = int(w), float(ir), int(c) if w == 1: ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class LittlePigsAndWolves { public static void main(String[] args)throws IOException { littlePigsAndWolves(); } public static void littlePigsAndWolves() throws IOException { BufferedReader re...
#include <bits/stdc++.h> using namespace std; int n, m, cnt, next_x, next_y; char maze[15][15]; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; map<pair<int, int>, int> w; map<int, pair<int, int> > w_rev; map<pair<int, int>, int> taken; bool valid(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); } int m...
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pair<ll,ll>P; int n; ll x; ll b[200000],l[200000],u[200000]; P s[200000]; int id[200000]; ll sum=0; bool C(ll t){ ll m=t/x; if(m>=n)return true; ll S=0; rep(i,m)S+=s[i].first; ll r=t%x; ll Max=0; r...
import math def main(): buf = input() buflist = buf.split() N = int(buflist[0]) X = int(buflist[1]) iblu = [] for i in range(N): buf = input() buflist = buf.split() iblu.append((i, int(buflist[0]), int(buflist[1]), int(buflist[2]))) aoki_score = 0 takahashi_score...
def extgcd(a, b, d=0): """solve ax + by = gcd(a, b) return x, y, gcd(a, b) unproved """ g = a if b == 0: x, y = 1, 0 else: x, y, g = extgcd(b, a % b) x, y = y, x - a // b * y return x, y, g a, b = map(int, input().split()) print(*extgcd(a, b)[:2])
#include<cstdio> #include<cstring> #include<iostream> using namespace std; int a,b,c,x,y; int exgcd(int a,int b){ if(!b){ x=1; y=0; return a; } int e=exgcd(b,a%b); int kkz=x; x=y; y=kkz-a/b*y; return e; } int main() { scanf("%d%d",&a,&b); ...
import java.util.*; public class Main { Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main() { new B().doIt(); } class B{ void doIt(){ int n = sc.nextInt(); String str = sc.next(); char ctr[] =...
n = int(input()) x = input() d = int(input()) swap = {} for i in range(n): if d == 0:break if x[i] == "0": swap[i] = True d -= 1 for i in range(n - 1, -1, -1): if d == 0:break if x[i] == "1": swap[i] = True d -= 1 print("".join([x[i] if i not in swap else ("0" if x[i] == "1" else "1") for i in ra...
import java.util.Arrays; import java.util.Scanner; public class CF453B { public static void main(String[] args) throws Exception { new CF453B().solve(); } static final int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 }; static class ElmWithIndex implem...
#include <bits/stdc++.h> using namespace std; int n, a[107], F[107], optEl[107][(1LL << (18))], dp[107][(1LL << (18))]; int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59}; vector<int> rst; void factorise() { for (int x = 1; x <= 60; ++x) { for (int i = 0; i < 17; ++i) { if ((x %...
n = int(raw_input()) m = int(raw_input()) a = map(int,raw_input().split()) b = map(int,raw_input().split()) arr = [] for i in range(n): arr.append(b[-i]) arr.append(a[-1-i]) x = m ans = 0 flag = 0 for i in range(2*n): if arr[i] - 1 <=0: flag =1 break ans = x*1.0/(arr[i]-1) x += ans ans = x-m if flag ==1: ans ...
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; long long ans = 0; for (int i = 0; i < n; ++i) if (b[i] == 1) { ans += a[i]; a[i] = 0; } lon...
n,k = map(int, raw_input().split()) tab_th = map(int, raw_input().split()) tab_sl = map(int, raw_input().split()) wyn_1 = 0 wyn_2 = 0 for x in range(0, len(tab_sl), +1): if tab_sl[x] == 1: wyn_1 += tab_th[x] else: if x < k: wyn_2 += tab_th[x] temp_wyn = wyn_1+wyn_2 wyn = temp_wyn for...
import java.awt.*; import java.io.PrintWriter; import java.util.*; public class Main { static LinkedList<Integer> adj[]; static boolean vis[];static int dp[],inDeg[],dist[]; public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(),m=sc.nextInt(); ...
#include <bits/stdc++.h> using namespace std; int dis[100005]; vector<int>v[100005]; int n, m; int dfs(int x){ if(dis[x] != -1)return dis[x]; int ret = 0; for(int i = 0; i < v[x].size(); i++){ ret = max(ret, dfs(v[x][i]) + 1); } return dis[x] = ret; } int main(){ cin >> n >> m; for(int i = 0; i <= n; i++)dis[i...
def increase_difference(to_start, diff): res = 1 for i in to_start: if i + diff < 10: break if i + diff > 9: diff = diff - (9 - i) res += 1 return res def decrease_difference(to_start, diff): res = 1 for i in to_start: if i - diff > -1: ...
#include <bits/stdc++.h> using namespace std; string in; int ans = INT_MAX, cnt; vector<string> v; void solve(string str) { if (str.length() == 6) { int ltemp[3], rtemp[3], lsum = 0, rsum = 0; for (int i = 0; i < 3; i++) { ltemp[i] = str[i] - '0'; lsum += ltemp[i]; } for (int i = 3; i < 6;...
def main(): from itertools import chain n, m = map(int, input().split()) b1, b2, b3, b4 = ([0] * m for _ in range(4)) it = iter(range(1, m + 1)) try: for i in range(n): b1[i] = next(it) b4[i] = next(it) for i in range(n): b2[i] = next(it) ...
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Edu11B { public static void main(String[] args) throws NumberFormatException, IOException {...
#include <bits/stdc++.h> using namespace std; inline void pisz(int n) { printf("%d\n", n); } const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; template <typename T, typename TT> ostream& operator...
//package compete; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.security.acl.LastOwnerException; import java.util.*; import java.util.ArrayDeque; import java.util....
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class ProgressBar { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t, s; cin >> n >> k >> t; s = n * k * t / 100; for (int i = 0; i < n; i++) { if (s >= k) { cout << k << " "; s -= k; } else if (s > 0) { cout << s << " "; s = 0; } else cout << "0 "; } return 0; }
import java.lang.*; import java.math.*; import java.util.*; import java.io.*; public class Main { void solve() { int n=ni(),m=ni(); int a[][]=new int[m+1][]; for(int i=1;i<=m;i++){ int sz=ni(); a[i]=new int[sz]; for(int j=0;j<sz;j++){ a[i]...
def use_fast_io(): import sys class InputStorage: def __init__(self, lines): lines.reverse() self.lines = lines def input_func(self): if self.lines: return self.lines.pop() else: return "" input_storage_obj = I...
import java.io.*; import java.util.*; public class Main { private void solve() { int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; long total = 0; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); b[i] ...
import copy shroud = [] aBerrySum = 0 bBerrySum = 0 n,k = map(int,input().split()) isAllRemainderCovered = False remainderCovered = [False for _ in range(k)] remainderCovered[0] = True for _ in range(n): a,b = map(int,input().split()) shroud.append([a,b]) aBerrySum += a bBerrySum += b if a >= k an...
import collections def doit(): N = int(input()) graph = dict() for n in range(N) : graph[n] = list() for n in range(N - 1): a, b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) msize = 0 for k in graph: msize = max(msize, len(gr...
//package cf780; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; import java.util.Arrays; import java.ut...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, count = 0, n; string s; cin >> s; n = s.size(); stack<char> st; for (i = 0; i < n; i++) { if (st.empty()) { st.push(s[i]); } else { if (st.top() == s[i]) { count++; st.pop(); } else { ...
//var input = readline() var str = readline() var ans = []; var cnt = 0; for (var j=0; j<str.length; j++) { if (ans[ans.length-1] == str[j]) { //while(s[j] == s[j+1] && s.length > 0) { ans.pop(); //print('pop = '+ ans.join('')); cnt ++; }...
n,a=map(int,raw_input().split()) x=map(int,raw_input().split()) x=sorted(x) if n==1: print 0 exit(0) else: print min(x[-2]-x[0]+abs(a-x[0]),x[-1]-x[1]+abs(x[1]-a), x[-2]-x[0]+abs(a-x[-2]),x[-1]-x[1]+abs(x[-1]-a))
import java.util.Arrays; import java.util.Scanner; public class Main { Scanner cin = new Scanner(System.in); public Main() { while (cin.hasNext()) { int n = cin.nextInt(), a = cin.nextInt(); int[] array = new int[n]; for (int i = 0; i < n; i++) array[i] = cin.nextInt(); if (n == 1) { System.ou...
mp = {"ani":"square1001","otouto":"e869120"} s = input() print(mp[s])
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); if (s.equals("ani")) { System.out.println("square1001"); } else { System.out.println("e869120"); } } }
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x in sys.stdi...
#include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) for(int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; const int INF = 100000000; using namespace std; int main(){ int h, w; cin >> w >> h; char m[100][1...
#include <iostream> #include <list> #include <iterator> #include <vector> void dump(std::list<int> L) { if (L.empty()) { std::cout << std::endl; return; } auto it = L.begin(); std::cout << *it; it++; for (; it != L.end(); it++) { std::cout << ' ' << *it; } ...
import sys from collections import deque sys.setrecursionlimit(10**9) n,q = map(int, input().split()) l = [deque() for _ in range(n)] for _ in range(q): query = input().split() if query[0] == "0": # insert idx = int(query[1]) l[idx].append(query[2]) elif query[0] == "1": # dump idx = int(query[1]) print(" ...
import sys def read(): return int(input()) def reads(): return [int(x) for x in input().split()] N,M=reads() table=[reads() for i in range(N)] A=[[0]*N for i in range(N)] B=[[0]*N for i in range(N)] for i in range(N): for j in range(N): res=10**9+7 for k in range(M): res=min(res,...
#include <bits/stdc++.h> using namespace std; struct str { int x, y; bool operator<(const str& A) const { return x < A.x; } }; int n, m, k, anscnt; int arr[20][30001]; int pre[20][20], qre[20][20]; int dp[20][20][1 << 16], first; map<int, int> mp; int cal(int cur, int val) { if (val == (1 << n) - 1) return qre[fi...
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200200; char buffer[N]; string read() { scanf("%s", buffer); return buffer; } string solve(string a, string b, char c) { a += c; b += c; string result = ""; for (int i = 0, j = 0; i < a.size() || j < b.size()...
//package binaryliterature; import java.util.*; import java.io.*; public class binaryliterature { public static void main(String[] args) throws IOException { BufferedReader fin = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(fin.readLine()); StringBuilder fout = new StringBuild...
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Reader in = new Reader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int n = in.nextInt(); int m = in.n...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int MOD = 1000000007; signed main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(0); int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; if (k < n + 1 || n <= 4) cout << -1 << '\n', exit(0); else { c...
#include <bits/stdc++.h> using namespace std; long long Abs(long long x) { if (x < 0) return -x; return x; } int Solve0(long long x0, long long y0, long long x1, long long y1, long long a) { x0 += y0; x1 += y1; if (x0 > x1) swap(x0, x1); if (x0 < 0) { long long tmp = ((-x0) / (2 * a) + 1) * 2...
import java.util.*; import java.io.*; import java.text.*; public class D124 { static long INF = (long) 1e9; static long a, b; public static long find1(long x1, long y1) { long lo = -INF; long hi = INF; long k = -INF; while (lo <= hi) { long mid = lo + hi >> 1; if (2 * a * mid - x1 < y1) { k = mi...
#include <bits/stdc++.h> using namespace std; using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,b) rng(i,0,b) #define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--) #define per(i,b) gnr(i,0,b) #define pb push_back #define eb emplace_back #define a first #define b second ...
""" #If FastIO not needed, use this and don't forget to strip #import sys, math #input = sys.stdin.readline """ import os import sys from io import BytesIO, IOBase import heapq as h from bisect import bisect_left, bisect_right import time from types import GeneratorType BUFSIZE = 8192 class FastIO(IOBase): newl...
def solve(): s = input() l = len(s) i = 0 ans = [] while i < l: if i + 5 <= l: # print(s[i:i+5]) if s[i:i+5] == "twone": ans.append(i+3) i += 4 continue if i + 3 <= l: if s[i:i+3] == "two" or s[i:i+3]...
import java.io.*; import java.util.*; public class Solution { public static void main(String ag[]) { Scanner sc=new Scanner(System.in); int i,j,k; int T=sc.nextInt(); while(T-->0) { char str[]=sc.next().toCharArray();; int N=str.length; ...
#include <bits/stdc++.h> using namespace std; int xx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int yy[] = {1, -1, 0, 0, 1, -1, -1, 1}; inline long long MAX(long long a, long long b) { return (a > b) ? a : b; } inline long long MIN(long long a, long long b) { return (a > b) ? b : a; } inline double dis(double ax, double ay, doub...
import java.util.Scanner; public class E_TVGame { /** * 3:03 * 4:47 */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); String line = sc.nextLine(); int[] nums = new int[n*2]; f...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (auto& i : a) cin >> i; sort(a.begin(), a.end(), greater<int>()); vector<int> nums(3, a[0]); int i = 1, c = 1; while (i < n && c < 3) { int ok = 1;...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import java.util.TreeSet; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new...
import java.io.*; import java.math.BigInteger; import java.nio.Buffer; import java.sql.BatchUpdateException; import java.util.*; import java.util.stream.Stream; import java.util.Vector; import static java.lang.Math.*; public class icpc { public static void main(String[] args)throws IOException { Reade...
n, k = map(int, raw_input().split()) peebles = map(int, raw_input().split()) mini = min(peebles) if max(peebles) - mini > k: print "NO" else: for i in range(n): peebles[i] = peebles[i] - mini print "YES" for i in range(n): for j in range(mini): print 1, for j in ran...
import java.io.IOException; import java.io.InputStream; import java.util.*; import java.math.BigInteger; public class Main implements Runnable { static int mod = 1000000007; public static void main(String[] args) { new Thread(null, new Main(), "", 1024 * 1024 * 1024).start(); } public void ...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll) 1e15; ll dp[105][10005]; pll V[105]; int main() { ...
import re s = input() s = re.sub(r"( *),( *)", ", ", s) s = re.sub(r"( *)\?( *)", "? ", s) s = re.sub(r"( *)\.( *)", ". ", s) s = re.sub(r"( *)!( *)", "! ", s) s = re.sub(r" +", " ", s) print(s)
#include <bits/stdc++.h> int main() { int u, i, j = 0; char str[10000], orj[10000]; gets(str); u = strlen(str); for (i = 0; i < u; i++) { if (str[i] == ' ' && (str[i + 1] == ' ' || str[i + 1] == '.' || str[i + 1] == ',' || str[i + 1] == '!' || str[i + 1] == '?')) continue; if ((...
#include <bits/stdc++.h> using namespace std; const long long inf = 100005 * 1000000000LL; int tree[100005], n, cnt, data[100005]; long long sum[100005], x[100005], k; void insert(int x, int k) { for (int i = x; i <= n; i += i & (-i)) tree[i] += k; } int ask(int x) { if (x == 0) return 0; int ret = 0; for (int ...
import java.io.*; import java.util.Random; import java.util.StringTokenizer; public class Main { final long INF = (long)1000000000*100000; private void solve() throws IOException { int n = in.nextInt(); long k = in.nextLong(); int[] a= new int[n]; for (int i = 0; i < n; ++i) ...
//package round722; import java.io.*; import java.util.ArrayDeque; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Queue; public class E { InputStream is; FastWriter out; String INPUT = "4"; void solve() { final int mod = 998244353; int n = ni(); if(n == 1){ out.print...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native") #define ll long long #define int ll #define ull unsigned ll #define ld long double #define rep(a) rep1(i,a) #define rep1(i,a) rep2(i,0,a) #define rep2(i,b,a) ...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; public class popo { public static boolean prime[]; public static ArrayList[] ad=new ArrayList[2555]; public static ArrayList<Long> xor1,xor2;...
#include <bits/stdc++.h> using namespace std; inline bool dfs(long long a, long long b) { if (a == 0 || b == 0) return 0; if (a > b) swap(a, b); long long z = b % a; if (!dfs(a, z)) return 1; if ((b / a) % (a + 1) % 2 == 0) return 1; else return 0; } signed main() { ios::sync_with_stdio(false); ...
import java.util.*; public class c { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(), k = input.nextInt(); int[] data = new int[n]; for(int i = 0; i<n; i++) data[i] = input.nextInt(); Arrays.sort(data); if(data[0] <= k+1) System.out.printl...
#include <bits/stdc++.h> using namespace std; const long long inf = 1LL << 28; const long long mod = 1LL; int arr[3 * 100010]; int main() { int n, k, i, ans, flag, j; while (scanf("%d %d", &n, &k) == 2) { for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } sort(arr, arr + n); ans = arr[0]; w...
import java.io.BufferedOutputStream; import java.io.Closeable; import java.io.DataInputStream; import java.io.Flushable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.util.InputMismatchException; /** * Built using CHelper plug-in * Actual so...
#include <bits/stdc++.h> using namespace std; const long long int inf = 1000000000; const long long int mod = 1000000000 + 7; inline void IO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); } template <class T> inline int CHECK(T M...
beats = { 'R':'S', 'S':'P', 'P':'R' } t = int(input()) for __ in range(t): n = int(input()) a, b, c = map(int, input().split()) s = input() counts = { 'R': 0, 'S': 0, 'P': 0 } for e in s: counts[e] += 1 wins = 0 wins += min(counts['R'], b) wins += mi...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string o[100]; int n, a, b, c, r, p, s; string sb; string sa; for (int j = 0; j < t; j++) { cin >> n >> a >> b >> c >> sb; r = 0; p = 0; s = 0; for (int i = 0; i < n; i++) { if (sb[i] == 'R') r++; i...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20; const long long MOD = 1e9 + 7, INF = 1e18 + 9; const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1}; const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1}; void debug() { cerr << "\n"; } template <typename Head, typename... Tail> ...
import java.util.*; import java.io.*; import java.math.*; public class Main { static class Reader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} public int read() {if (nu...
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import javax.swing.undo.StateEdit; public class Main { InputStream is; boolean __FILE_DEBUG_FL...
#include<bits/stdc++.h> #define N 100 #define D 100001 #define INF (1e9) using namespace std; typedef pair<int,int> P; int n,hp[N],m,mp[N],damage[N],ans,cnt; int dpAll[D],dpSin[D]; string name,target[N]; vector<P> v; vector<int> minv; int bynary_search(int x){ int L=0,R=v.size(); while(L<R){ int M=(L+R)/2; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, inv2 = (mod + 1) / 2; const int lim = (1 << 17); int bit[lim + 2]; long long sav[lim + 2], fib[lim + 2]; const long long Cor[2][2] = {{1, 0}, {1, 1}}, ICor[2][2] = {{1, 0}, {mod - 1, 1}}; const long long Cand[2][2] = {{0, 1}, {...
import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.System.exit; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class G { static final int BITS = 1...
import java.util.Scanner; import java.util.LinkedList; public class p3{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); LinkedList <Integer> lista = new LinkedList <Integer>(); int n = scan.nextInt(); int m = scan.nextInt(); int k = scan.nextInt(); int suma = 0; for(int...
#include <bits/stdc++.h> using namespace std; int N, M, K, P[105]; int main() { scanf("%d %d %d", &N, &M, &K); for (int i = 0; i < K; i++) scanf("%d", &P[i]); int ans = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { int x; scanf("%d", &x); int idx; for (int k = 0; k <...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
import java.math.BigInteger; import java.security.SecureRandom; import java.text.DecimalFormat; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { IO io ; try { io = new IO("in.in", null); } catch (IOException...
#!/usr/bin/python2 # -*- coding: utf-8 -*- import sys import os def main(): line = sys.stdin.readline().strip() i = line.find('0') if i >= 0: print line[0:i] + line[i+1:] else: print line[:-1] if __name__ == '__main__': main()
import java.util.*; public class elephantandbits { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { String x = in.next(); boolean r = false; int t = 0; for (int i = 0; i < x.length(); i++) { if ((x.charAt(i) == '0') && r == false) { t = i; ...
import java.util.*; import java.io.*; public class MrKitayutaVsBamboos { public static void main(String[] args) throws Exception { FastScanner in = new FastScanner(System.in); int n = in.nextInt(); long m = in.nextInt(); int k = in.nextInt(); long p = in.nextInt(); long[] height = new long[n]; lon...
#include <bits/stdc++.h> using namespace std; const int N = 100005; struct node { int now; long long ret; bool operator<(const node &x) const { return x.ret < ret; } }; int n, m, k; long long h[N], a[N], l, r, ans, p, dis[N]; bool check(long long x) { priority_queue<node> q; for (int i = 1; i <= n; ++i) dis[i...
import java.io.*; import java.util.*; import java.util.function.IntConsumer; public class Solution333 { static MyScanner sc; private static PrintWriter out; static long M2 = 1_000_000_000L + 7; public static void main(String[] s) throws Exception { StringBuilder stringBuilder = new StringBui...
#include <bits/stdc++.h> using namespace std; int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; const double eps = 1e-6; const double Pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int maxn = 3010; const int maxq = 4e5 + 10; vector<int> edge[maxn]; struct query { int id, f, t, k; query(int _id = -1, int _f = ...
import sys, io, os input = lambda: sys.stdin.readline().encode() #input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline read = lambda: map(int, input().split()) M = 10 ** 9 + 7 out = [] for _ in range(int(input())): n, k = read() c = [0] * n c[0] = 1 t = 1 for i in range(k - 1): if i ...
import java.io.*; import java.util.*; public class C { static int[][][] dp; static int mod = (int) 1e9 + 7, n, k, N = 1001, K = 1001; public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); dp = new int[N][K][2]; ...
import java.io.*; import java.util.*; public class Main { FastScanner in; PrintWriter out; class Frac implements Comparable<Frac>{ long x, y; public Frac(long x, long y) { this.x = x; this.y = y; } @Override public int compareTo(Frac o) { ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=200005; int read(){ int f=1,g=0; char ch=getchar(); for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1; for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0'; return f*g; } int n,fa[N],f[N],h[N]; ll ans; struct node{int i,x,y;}a[N]; void operat...
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.math.BigInteger; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author...
#include <bits/stdc++.h> using namespace std; template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple) {} template <int POS, class TUPLE, class H, class... Ts> void deploy(std::ostream &os, const TUPLE &t) { os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); ...
'''input 5 4 1 0 00000 ''' from sys import stdin import collections import math def get_working(string): aux = [] first = None if string[0] == 1: pass else: first = -1 for i in range(len(string)): if string[i] == '1': if first == None: first = i elif first != None: aux.append([first, i, (i - ...
import java.io.*; import java.util.*; public class p11{ static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try...
// D - Coloring Edges on Tree #include <bits/stdc++.h> using namespace std; #define rp(i,s,e) for(int i=(s);i<(e);++i) #define NMAX 100000 int K = 1; int C[NMAX+1];//child int S[NMAX+1];//sibling int colors[NMAX+1]; void dfs(int p, int p_color){ int color = 1; for(int c=C[p]; c; c=S[c]){ if(colors[c]) continue; ...
import java.util.*; public class Main { static class Node{ List<Integer> to; Node(){ to = new ArrayList<Integer>(); } } static public class IntPair{ int x, y; public IntPair(int xx, int yy){ x = xx; y = yy; } @Overri...
a, b, c = map(int, raw_input().split(" ")) if (a+b+c)%2 == 1 or 2*max(a,b,c) > a + b + c: print "Impossible" else: print (a+b-c)/2,(b+c-a)/2,(c+a-b)/2
import java.io.*; import java.math.BigInteger; import java.util.*; public class maxpro100krut { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); for (int i = 0; i <= a; ++i) { ...
import java.io.*; import java.util.*; public class Solution { public static void main(String args[])throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[]=new int[n]; int flag=0,count=0; char temp[] =sc.next().toCharArray(); for(in...
a=int(input()) n=input() n='0'+n+'0' if '11' in n or '000' in n: print ('No') else: print('Yes')
//package codeforces.cfr330div2; import java.io.*; import java.util.*; import java.util.function.Function; /** * Created by raggzy on 28-Jan-16. */ public class E { private static class Reader implements Closeable { private BufferedReader br; private StringTokenizer st; public Reader(I...
#include <bits/stdc++.h> using namespace std; int n, k; int x[100000], y[100000], xx[100000], yy[100000]; int ord[100000]; vector<int> inds; inline bool cmpx(const int &lhs, const int &rhs) { return x[lhs] < x[rhs]; } inline bool cmpy(const int &lhs, const int &rhs) { return y[lhs] < y[rhs]; } vector<int> xs, ys; void ...
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for...
import sys readline = sys.stdin.readline write = sys.stdout.write EPS = 1e-9 def line_cross_point(P1, P2, Q1, Q2): x0, y0 = P1; x1, y1 = P2 x2, y2 = Q1; x3, y3 = Q2 dx0 = x1 - x0; dy0 = y1 - y0 dx1 = x3 - x2; dy1 = y3 - y2 s = (y0-y2)*dx1 - (x0-x2)*dy1 sm = dx0*dy1 - dy0*dx1 if -EPS < sm ...
#include <bits/stdc++.h> using namespace std; template <class A, class B> A cvt(B x) { stringstream ss; ss << x; A y; ss >> y; return y; } int n, k; vector<pair<int, int> > ch[100000]; int d[100000], p[100000][17]; void build(int x, int px) { if (px == x) d[x] = 0; else d[x] = d[px] + 1; p[x][0]...
import java.util.*; import java.io.*; public class E { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); new E(new FastScanner(), out); out.close(); } Graph g; int[] left, right, ids, level; int cnt; void dfs(int i, int p, int d) { ...
import java.io.*; import java.util.*; public class CF { FastScanner in; PrintWriter out; int[] primes = new int[100]; int[] cnt = new int[100]; int sz; int[] div; void get(int v) { sz = 0; while (v != 1) { int d = div[v]; cnt[sz] = 0; primes[sz] = d; while (v % d == 0) { cnt[sz]++; v /...
#include <bits/stdc++.h> using namespace std; int b[1000]; vector<int> primes; int d[1100000]; int w[1100000]; int diff[1100000]; int f[1100000]; int invf[1100000]; int pow1(int x, int y) { int i; long long ret; ret = 1; for (i = 30; i >= 0; i--) { ret = ret * ret % 1000000007; if (((1 << i) & y) != 0) ...
import java.util.Scanner; public class F { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); long[][] left = new long[n][2]; long[][] right = new long[n][2]; int[] get = new int[n-1]; for(int i = 0; i < n-1; i++) get[i] = scan.nextInt(); long max = ...
#include <bits/stdc++.h> using namespace std; void MAIN(); int main() { MAIN(); return 0; } const long long N = 1e6 + 1, mod = 1e9 + 7; int n, m, a[N], sll[N], slc[N]; long long sum[N], odd[N], even[N], turn[N], go[N]; long long cal(int i) { return turn[i - 1] - sum[i - 1]; } void MAIN() { scanf("%d", &n); for ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import java.util.stream.Collectors; public class Solution extends Thread { static class FastReader { BufferedReader br; StringTokenizer st; public Fa...
import sys def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s); sys.stdout.write('\n') def wi(n): sys.stdout.write(str(n)); sys.stdout.write('\n') def wia(a, sep=' '): sys.stdout.write(sep...
def main(): n = int(input()) a = [int(x) for x in input().split()] temp = [1] * n for i in range(1, n): if a[i] != a[i-1]: temp[i] = temp[i-1]+1 else: temp[i] = 1 print((max(temp) - 1)//2) temp2 = [-1] * n i = 0 while i < n: if a[i...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int a[maxn]; bool make; vector<int> ans, ve; int mx = 0, n; void put_num() { int f = ve[0], s = ve.back(); mx = max(mx, ((int)ve.size() - 1) / 2); for (int i = 0; i < (int)ve.size() / 2; i++) ans.push_back(f); for (int i = (int)ve.size() /...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; cin >> n; long long int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } long long int ans = 0; for (int i = 0; i < 30; i++) { long long int l1 = pow(2, i)...
import java.io.*; import java.util.*; public class Main { public static int lower_bound(int[] A, int low, int high, int x) { if (A[low] >= x) { return low; } else if (A[high] < x) { return high + 1; } while (low <= high) { int mid = (low + high) / 2; if (A[mid] < x) { low = mid + 1; } else ...
/* If you want to aim high, aim high Don't let that studying and grades consume you Just live life young ****************************** If I'm the sun, you're the moon Because when I go up, you go down ******************************* I'm working for the day I will surpass you https://www.a2oj.com/Ladder16.html */ impor...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; vector<vector<char>> a, b, c; int n, m; int check1(string& second, int line) { int res = 0; for (int i = 1; i <= m; ++i) { res += (a[line][i] != second[i % 2]); } return res; } int solve1(vector<vector<char>>& check) { int res = 0; ...
#include <bits/stdc++.h> std::string s; int main(int argc, char *argv[]) { std::cin >> s; int ans = 0; for (int i = s.length() - 1; i >= 0; i--) { if (s[i] == '0') { ans++; } else { if (ans <= 0) { s[i] = '0'; } else { ans--; } } } std::cout << s; }
S = input() N = len(S) p = q = 0 prv = S[0] c = 0 C = [] if S[0] == '1': C.append(0) for ch in S: if ch != prv: C.append(c) c = 1 prv = ch else: c += 1 C.append(c) ans = [] r = 0 L = len(C) for i in range(L-1, -1, -1): c = C[i] if i % 2: r += c if i ...
#include <bits/stdc++.h> using namespace std; int main() { int t, p, a[105], i; cin >> t >> p; for (i = 0; i < t; i++) cin >> a[i]; sort(a, a + t, greater<int>()); cout << a[p - 1]; return 0; }
/** * Created with IntelliJ IDEA. * User: den * Date: 4/19/14 * Time: 8:17 AM * To change this template use File | Settings | File Templates. */ import java.io.*; import java.util.*; public class TaskB extends Thread { private void solve() throws IOException { int n = _int(); int k = _int()...
#include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int n, k; while(cin >> n >> k) { if (n == 0 && k == 0) { break; } vector<int> data(n+1, 0); int a; for (int i = 0; i < k; i++) { cin >> a; data[a] = 1; } int MAX = data[n]; for (int i = n-1; i > 0; i--)...
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc=new Scanner(System.in); for(;;){ int n = sc.nextInt(),k=sc.nextInt(); if(n+k==0)b...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int maxn = 2e5; tuple<int, int> mn[2][4 * maxn]; void upd(int p, int c, int v = 1, int l = 0, int r = maxn) { if(r - l == 1) { mn[p % 2][v] = tuple<int, int>(c, p); return; } int m = (l + r) / 2; if(p < m) ...
from heapq import heappop, heappush INF = 10**30 class Rmin(): def __init__(self, size): #the number of nodes is 2n-1 self.n = 1 while self.n < size: self.n *= 2 self.node = [INF] * (2*self.n-1) def Access(self, x): return self.node[x+self.n-1] def Update(self, x, val): x += self.n-1 self.node[x]...