anchor stringlengths 10 14.3k | positive stringlengths 10 14.9k |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const unsigned gen_seed =
std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);
class stree {
public:
std::vector<int> t;
int s;
void build(std::vector<int>& a, int v, int tl, int tr) {
i... | def evens(A):
n = len(A)
l = n//2-1; r = n//2
if len(A)%2 == 1: l+= 1
ans = [max(A[l], A[r])]
while r < n-1:
l-= 1; r+= 1
ans.append(max(ans[-1], A[l], A[r]))
return ans
def interleave(A, B):
q = []
for i in range(len(B)): q+= [A[i], B[i]]
if len(A) != len(B): q.appe... |
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class cf1450a {
public static void main(String[] args) throws IOException {
int t = ri();
while (t --> 0) {
int n = ri();
char[] s = rcha();
sort(s);
... | maxK = 51
maxN = 10001
if __name__ == '__main__':
t = int(input())
for _ in range(t):
n = int(input())
s = input()
bs = 0
for ch in s:
if ch == 'b':
bs += 1
for _ in range(bs):
print('b', end='')
for ch in s:
... |
//package april2016;
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 D {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
long n = nl();
i... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T first, T second) {
while (second > 0) {
first %= second;
swap(first, second);
}
return first;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class _T>
inline _T sqr(const _T &first) {
return first... |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& t) {
return in >> t.first >> t.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2>& t) {
return out <<... | n,m = map(int, input().split())
g = [[] for i in range(n)]
fs = set()
for i in range(n):
a = list(map(int , input().split()))
c = a[0]
if c == 0:
fs.add(i)
continue
for j in range(1,c+1):
g[i].append(a[j]-1)
s = int(input())-1
prev0 = [None for i in range(n)]
prev1=[None for i i... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.AbstractCo... | #include <bits/stdc++.h>
using namespace std;
const int N = 123456;
const int LN = 19;
const long long INF = 1LL << 60LL;
int n, m, k, q;
int parent[N];
int depth[N];
int anc[LN][N];
long long dp[LN][N];
long long dist[N];
vector<pair<int, int>> adj[N];
vector<tuple<long long, int, int>> edges;
vector<pair<int, long lo... |
#!/usr/bin/env python3
n = int(input())
d, d1 = {}, {}
for i in range(n):
a , b = map(int, input().split())
d[a], d1[b] = b, a
res = []
for i in d.keys():
if i not in d1:
res.append(i)
res.append(d.get(0))
for i in range(2, n):
res.append(d.get(res[i - 2]))
print(*res)
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Hello world!
*... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.Collection;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List... | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
T gcd(T a, T b) {
return ((b == 0) ? a : gcd(b, a % b));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long a, b;
int f = 0;
cin >> a >> b;
if (b < a) f = 1, swap(a, b... |
n = int(input())
bits = set()
c1 = 0
count = 0
ans = []
for i in range(n):
x = int(input())
if x in bits:
y = x
while c1 < y and y in bits:
y -= 1
if y <= c1:
y = 0
if y == 0 and count != x:
c1 = max(x, c1)
ans.append("No")
... | #include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
template<typename T, typename E> class SegmentTree {
public:
typedef function<T (T, T)> Operator;
typedef function<T (T, E)> Apply;
vector<T> data;
ll n;
T e;
Operator op;
App... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Input... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, m, q, w1, w2, v[4][N][2], dp[N];
char f[4][N];
int main() {
cin >> n >> m >> q;
scanf("%s%s%s%s", f[0] + 1, f[1] + 1, f[2] + 1, f[3] + 1);
for (int z = 0; z <= 3; z++) {
int l = strlen(f[z] + 1);
for (int i = 1; i <= l; i++) {
... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import java.util.Collection;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;
/*... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N], fa[N * 2];
struct Edge {
int u, v, w;
bool operator<(const Edge &b) const { return w > b.w; }
} e[N * 2];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
int main() {
int m, n, s, x;
scanf("%d%d", &m, &n);
fo... |
import java.util.*;
public class abc {
static int[] a = new int[5010];
static int[] b = new int[5010];
static Set<Integer> st = new HashSet<Integer>();
static int[] ans = new int[5010];
static int[] vis = new int[5010];
static int[] c = new int[5010];
static int _find(int l, int r, int x)
{
while(l <= r)
{... | primes = map(int, '''
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173
179 1... |
/*input
10
1
248618
3
12 10 8
6
100 11 15 9 7 8
4
0 1 1 0
2
0 0
2
0 1
2
1 0
2
1 1
3
0 1 0
3
1 0 1
*/
import java.math.*;
import java.io.*;
import java.util.*;
public class Main
{
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private b... | """
Satwik_Tiwari ;) .
4th july , 2020 - Saturday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, ... |
import java.util.*;
class Main{
static final int nbits = 32;
static BitSet bs;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
long a = sc.nextLong();
long b = sc.nextLong();
BitSet bsa = new BitSet(nbits);
BitSet bsb = new BitSet(nbits);
for(int i = 0; i < nbits; i++){
i... | #include<iostream>
#include<bitset>
using namespace std;
int main()
{
long long int n, m;
cin >> m >> n;
typedef bitset<32> bbl;
bbl a(m), b(n);
cout << (a&b) << endl;
cout << (a | b) << endl;
cout << (a^b) << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector<int>v[12];
for(int i=2;i<=9;i++)
{
for(int j=1;j<=i*15;j++)
{
if(j<i)continue;
else
{
int flag=0;
int temp=j;
while(temp!=0)
{
if(temp%10==i)
{
v[i].... |
import java.util.Scanner;
public class Testing {
public static void main(String[] args) {
Scanner o=new Scanner(System.in);
int t=o.nextInt();
while(t>0) {
int n=o.nextInt();
char d=o.next().charAt(0);
int ar[]=new int[n];
for(int i=0;i<n;i++) {
ar[i]=o.nextInt();
}
for(int val:ar) {
boolean ... |
#include <bits/stdc++.h>
using namespace std;
const int P = 1000000007;
inline int mex(int a, int b) {
if (a != 0 && b != 0) return 0;
if (a != 1 && b != 1) return 1;
return 2;
}
const int MaxN = 1000;
const int MaxSegN = 150;
int main() {
int n, m;
cin >> n >> m;
static int fact[MaxN + 1];
fact[0] = 1;
... | M = 10 ** 9 + 7
n, p = map(int, raw_input().split())
s = [[1, 2, 0]]
i = j = 0
x = 3
while x <= p:
a = min(s[i][1] * 3 + 2, p)
b = min(s[j][1] * 3 / 2, p)
c = min(set(range(0, 3)) - set([s[i][2], s[j][2]]))
if a <= b:
i += 1
if b <= a:
j += 1
y = min(a, b)
if s[-1][2] == c:
s[-1][1] = y
else:
s += [[x, ... |
rr=raw_input
rrI = lambda: int(rr())
rrM = lambda: map(int,rr().split())
debug=0
if debug:
fi = open('t.txt','r')
rr=lambda: fi.readline().replace('\n','')
from string import ascii_lowercase as alpha
MOD = 10**9 +7
G = rrI()
A = rr()
dp = [0] * (G+1)
su = [0] * (G+1)
dp[0] = 1
for _ in xrange(G):
last = {... | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
public class Test {
static PrintWriter writer =
new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void main(String[] args) ... |
#include <bits/stdc++.h>
inline long long rd() {
long long _x = 0;
int _ch = getchar(), _f = 1;
for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
;
if (_ch == '-') {
_f = 0;
_ch = getchar();
}
for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
return _f ? _x :... | import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
void solve(){
int n=ni();
val=new long[n+1];
for(int i=1;i<=n;i++) val[i]=nl();
int from[]=new int[n-1];
int to[]=new int[n-1];
g=new int[n+1][];
for(int i=1;i<... |
#include <bits/stdc++.h>
using namespace std;
int ncnt;
struct Node {
Node *next[2];
} node[100100 * 60], *root;
void insert(long long x) {
Node *tmp = root;
for (int i = 59; i >= 0; i--) {
int k = (x & (1ll << i)) ? 1 : 0;
if (!tmp->next[k]) tmp->next[k] = &node[ncnt++];
tmp = tmp->next[k];
}
}
lon... | import java.util.Arrays;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int len=(int)Integer.parseInt(in.nextLine());
long[] s=new long[len+1];
long[] pxor=new long[len+1];
String[] value=(String[])in.nextLine().split(" ");
for(int i... |
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.util.Map.Entry;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringToke... | n=int(input())
lst=[*map(int,input().split())]
summa=sum(lst)
div,mod=summa//n,summa%n
lst=[*reversed(sorted(lst))]
res,i=0,0
for i,x in enumerate(lst):
if x<=div:break
if i<mod:res+=(x-(div+1))
else:res+=(x-div)
i+=1
print(res) |
import sys
n,k=map(int,input().split())
a=[0]*(k+2)
if k*(k+1)>n*2:
print("NO")
sys.exit()
for i in range(1,k+1):
a[i]=i
n-=k*(k+1)//2
rest=n//k
n-=rest*k
a[1]+=rest
for i in range(2,k+1):
a[i]=a[i-1]+1
rest=n//(k-i+1)
tmp=min(rest,a[i-1]*2-a[i])
a[i]+=tmp
n-=(k-i+1)*tmp
if n>0:
pri... | import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.*;
import static java.lang.System.exit;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class A {
static BufferedReader in;
stat... |
n = int(input()) # number of vertices
a = list(map(int,input().split())) # connection
b = list(map(int,input().split())) # colour
tree = []
for i in range(1,n + 1):
tree.append([i])
for j in range(2,n + 1):
tree[a[j - 2] - 1].append(j)
s = 0
for each in tree:
if len(each) == 1:
s += 1
tree.r... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 10001;
vector<int> g[maxn];
int res;
int color[maxn];
int vis[maxn];
void solve(int root, int c) {
vis[root] = 1;
if (color[root] != c) res++;
for (int i = 0; i < g[root].size(); i++) {
int to = g[root][i];
if (vis[to]) continue;
solve(to,... |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ll t;
cin>>t;
while(t--){
string a,b;
cin>>a>>b;
int n=a.length(),m=b.length();
int dp[n+1][m+1],res=0;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i == 0 ... | t=int(input())
for _ in range(t):
ans=0
s=str(input())
s1=str(input())
for i in range(0,len(s)):
e=''
for j in range(i,len(s)):
e=e+s[j]
if(e in s1 and len(e)>ans):
ans=len(e)
else:
pass
print((len(s)+len(s1))-2*ans) |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
int d[N], b[N], p[N], s[N];
pair<int, int> h;
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> d[i];
}
int m;
cin ... | import sys,os,io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range (int(input())):
n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
p = []
s = []
mp = 0
for i in range (m):
pi, si = [int(i) for i in input().split()]
if si:
... |
import java.util.*;
import java.io.*;
/*
6 7
1 6
2 1 6
2 3 5
3 4 9
4 6 4
4 6 5
4 5 1
3 1 3
*/
public class a
{
public static void main(String[] args) throws IOException
{
new a();
}
long best;
int numRoads;
int road1;
int road2;
int n, m;
int s, t;
ArrayList<Edge>[] adj;
public a() throws IOException
{
... | #include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vlli = vector<long long int>;
using vpii = vector<pair<int, int>>;
const int N = 1010;
const int M = 30010;
lli n, m, u, v, w, s, t... |
import java.io.BufferedReader;
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.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util... | n, m = map(int , raw_input().split())
turn = 0
L = [[2,1,0],[0,1,2]]
while True:
succ = 0
for x in L[turn]:
if x <= n and (220 - 100 * x)//10 <= m:
n = n - x
m = m - (220 - 100 * x)//10
succ = 1
break
if succ == 0:
break
turn = 1 - turn... |
N=int(raw_input().strip())
print N//2+N%2 | import java.util.*;
import java.io.*;
public class Untitled {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); int N = sc.nextInt();
int g = 0; if(N==1) g = 1; else if(N%2 == 0) g = N/2; else g = (N/2) + 1;
System.out.println(g);
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
struct HAP {
int x, y, val;
void init(int x, int y, int val) {
this->x = x;
this->y = y;
this->val = val;
}
bool operator<(const HAP &p) const { return val > p.val; }
} hs[maxn];
int n, m, top, a[1005][1005], vis[1005][1005], b[... | import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
public class Cf3003F {
private static InputReader in = new InputReader(System.in);
private static OutputWriter out = new OutputWriter(System.out);
private static long req;
static int n,m,hei... |
from collections import Counter
import string
import math
import sys
from fractions import Fraction
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variables):
if arrber_of_variables==1:
return int(sys.stdin.readline())
if arrber_of_variables>=2:
ret... | #include <bits/stdc++.h>
using namespace std;
template <class AK>
void r(AK &x) {
x = 0;
int f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
f |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = f ? -x :... |
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
// Tree Construction
// 2012/12/20
public class Main{
Scanner sc=new Scanner(System.in);
int INF=1<<28;
int n;
int[] xs, ys;
voi... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pa... |
import java.io.*;
import java.util.*;
public class E {
public static void main(String[] args) {
int t = sc.nextInt();
while(t-- > 0)
solve();
out.close();
}
public static void sort(int[] a) {
int l = 0, r = a.length;
ArrayList<Integer> list=new ArrayList<>();
for (int... | #include <bits/stdc++.h>
using namespace std;
bool test_cases_exist = true;
void solve() {
long long int n, k;
cin >> n >> k;
vector<long long int> v(n);
for (auto &z : v) cin >> z;
for (int i = 0, j; i < n; i++) cin >> j;
long long int lst = 0;
vector<long long int> arr(n + 5);
long long int ans = 0;
... |
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
// TODO ?????????????????????????????????????????????
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
double b=0,c=0,d=0,e=0;
int x[]=new int[a];
for(int z=0;... | # coding=utf-8
from __future__ import division
from math import sqrt
def main():
d = input()
x = map(int, raw_input().split())
y = map(int, raw_input().split())
z = [x - y for x, y in zip(x, y)]
print sum([abs(w) for w in z])
print sqrt(sum([w ** 2 for w in z]))
print sum([abs(w) ** 3 for ... |
import queue
di = [0, 1, 0, -1]
dj = [1, 0, -1, 0]
while True:
w,h = map(int,input().split())
if w == 0:
break
f, m, o = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(h)]
d = [[[1e9]*w for x in range(h)] for y in range(m+1)]
que = queue.PriorityQueue()
... | #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int> P;
#define fr first
#define sc second
#define INFTY ( 1 << 28 )
int W,H,mas[10][10],f,m,o,ret;
int min_cost[10][10][50];
void solve(int y,int x,int bit,int air,int cost){
if(air <= 0) return;
if(!(bit ... |
n=int(input())
a=int(input())
b=int(input())
c=int(input())
a=min(a,b)
print((n>1)*a+(n>2)*(n-2)*min(a,c)) | #include <bits/stdc++.h>
int main() {
int n, a, b, c;
while (~scanf("%d%d%d%d", &n, &a, &b, &c)) {
int sum = 0, flag = 1;
n -= 1;
while (n--) {
if (flag == 1) {
if (a > b) {
sum += b;
flag = 2;
} else {
sum += a;
flag = 3;
}
} e... |
s=raw_input()
d=raw_input()
a=[0]
m={}
for i in range(8):
for j in range(8):
m[chr(ord('a')+j)+str(8-i)]=i*8+j
ss=m[s]
dd=m[d]
r=dd/8-ss/8
c=dd%8-ss%8
#~ print(r,c)
print(abs(abs(r)-abs(c))+min(abs(r),abs(c)))
def lu(r):
r=abs(r)
for i in range(abs(r)):
print("LU")
def ru(r):
r=abs(r)
for i in range... | //package codeforcesQuestions;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class cdf3a
{
static void merge(int arr[], int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int [n1];
int R[] = new int [n2];
... |
n, root = map(int, input().split())
a = list(map(int, input().split()))
def push(d, x, val):
if x not in d:
d[x] = 0
d[x]+=val
if d[x]==0:
del d[x]
d = {}
for x in a:
push(d, x, 1)
min_ = 0
root -= 1
inf = 9999999
if a[root] != 0:
min_+=1
push(d, a[root], -1)
... | #include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200005];
int cnt[200005];
vector<int> v;
int ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (i != m) {
if (!a[i]) a[i] = n + 2;
++cnt[a[... |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
using P = pair<int, int>;
const int mx = 105;
int n, a, b, t, ans;
P c[2][mx];
set<int> st;
int main(){
scanf("%d", &n);
rep(i,2){
rep(j,n){
scanf("%d%d", &a, &b);
c[i][j] = P(a,b);
}
sort(c[i],c[i]+n);
}
rep(i,n){
... | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
static int n;
static Pair[] redPairs;
static Pair[] bluePairs;
static Map<Pair,List<Pair>> map;
public static void main(String[] args) {
Scanner scanner = new Scanner(... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
string S;
cin >> S;
int n = (int)S.size();
if (S[0] == '1' || S.back() == '1') {
cout << -1 << endl;
return 0;
}
vector<int> nxt(n, -1);
int ptr = 0;
for (int i = 1; i < n; i++) {
if (S[i] == '1') {
... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;
import java.util.ArrayList;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
publ... |
#include <iostream>
using namespace std;
int dp[1001][1001][3];
int M, N, K;
int a, b, c, d;
int solve(int a, int b, int c, int d, int t){
int ret = 0;
for(int i = a; i <= c; i++){
ret += dp[i][d][t] - dp[i][b-1][t];
}
return ret;
}
int main(void){
cin >> M >> N;
cin >> K;
for(int i = 1; i <= M; i+... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0560
"""
import sys
from sys import stdin
input = stdin.readline
def solve(M, N, K, field):
dp_J = [[0] * (N+1) for _ in range(M+1)]
dp_O = [[0] * (N+1) for _ in range(M+1)]
dp_I = [[0] * (N+1) for _ in range(M+1)]
f... |
import io
import os
from math import ceil
def solve(N, M, TXY):
def ceildivI(x, y):
# x and y are ints
return (x + y - 1) // y
def ceildivF(x, y):
# x and y are floats, returns int
return ceil(x / y)
M100000 = float(M * 10 ** 5) # Can be up to 10**10
possible = {0}
... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper... |
from math import *
print int(ceil(log(input(),3))) | #include<bits/stdc++.h>
using namespace std;
#define INF 1000000
//????¬????dp
int main(){
int n; cin >> n;
int ans = 0;
while(n != 1){
int r = n % 3;
n = n / 3;
if(r > 0) n++;
ans++;
}
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll INF=1000000010;
const ll MOD=1000000007;
const ll LINF=4000000000000000000;
const long double EPS=1e-9;
typedef pair<int,int> P;
struct UnionFind{
vector<int> par;
vector<int> dep;
UnionFind(int... | n, m, k = map(int, input().split())
parent = [i for i in range(n)]
club = [-1 for _ in range(n)]
def find(x):
if x == parent[x]:
return x
ret = find(parent[x])
parent[x] = ret
return ret
for count in range(1, k + 1):
t, a, b = map(int, input().split())
a -= 1
b -= 1
if t == 1:
p_a = find(a)
... |
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.writa... | #include <bits/stdc++.h>
using namespace std;
struct dv {
int lenh, l, r, x, stt;
};
int n, k, m;
int comp(dv l, dv r) { return l.l < r.l; }
int dd[5555], so[5555], save[5555], vt[5555], change[5555];
vector<dv> a, b;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
dd[i] = 0;
so[i] = 0;
cha... |
def main():
n, a, b, t = map(int, input().split())
b += 1
l = [b if char == "w" else 1 for char in input()]
t -= sum(l) - a * (n + 2)
hi, n2 = n, n * 2
n3 = n2 + 1
lo = res = 0
l *= 2
while lo <= n and hi < n2:
t -= l[hi]
hi += 1
while (hi - lo + (hi if hi < n... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, t;
cin >> n >> a >> b >> t;
string s;
cin >> s;
int m = n - 1;
vector<int> tl(m);
vector<int> tr(m);
for (int i = 1; i < n; i++) {
int tt = a + (s[i] == 'h' ? 1 : 1 + b);
tl[i - 1] = tt;
tr[m - i] = tt;
}
for (int i ... |
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)... | from math import sqrt
n = input()
ps = [map(float, raw_input().split()) for i in xrange(n)]
ps.sort()
def cross(a, b, c, d):
return (b[0]-a[0])*(d[1]-c[1]) - (b[1]-a[1])*(d[0]-c[0])
def convex_hull(ps):
qs = []
n = len(ps)
for p in ps:
while len(qs)>1 and cross(qs[-1], qs[-2], qs[-1], p) >= 0:
... |
import sys
n, a, b = map(int, sys.stdin.readline().split())
w_arr = map(int, sys.stdin.readline().split())
print(" ".join( map(str, [(w * a % b) // a for w in w_arr] ))) | #include <bits/stdc++.h>
using namespace std;
inline void read(void) {}
long long int n, a, b;
long long int data[100003];
vector<pair<long long int, long long int> > v;
inline void solve(void) {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) scanf("%lld", &data[i]);
for (int i = 0; i < n; i++) {
printf("%ll... |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int n;
long long k;
int w;
long long days;
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> w;
if (w % k == 0) {
days += w / k;
} else {
days += (w / k) + 1;
}
}
if (days % 2 == ... | import java.util.*;
import java.io.*;
public class pebbles
{
public static void main(String args[])throws IOException
{
try
{
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(is);
String tokens[] = new String[2];
tokens = bf.readLine().split(" ");
... |
n=input()
s=raw_input()
a=[]
maxx=0
for i in s:
a.append(i)
if i=='(':
maxx+=1
else:
maxx-=1
if maxx!=0:
print 0
print 1,1
else:
x=1
y=1
maxx=0
dp=[0]*n
val=0
for i in range(n):
if a[i]=='(':
val+=1
else:
val-=1
... | #include <bits/stdc++.h>
using namespace std;
int n;
char s[600010];
int stk[300010], top = 0, dep[600010], sum[600010], p[600010], ss[600010],
ans = 0, l = 1, r = 1;
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) s[i + n] = s[i];
int mn = 0, cnt = 0, x = 0;
fo... |
import java.util.Scanner;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.util.Collections;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
pub... | #include <bits/stdc++.h>
int cmp(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int main() {
int n, m, i, x, y;
int a[55];
while (scanf("%d%d", &n, &m) != EOF) {
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
qsort(a, n, sizeof(a[0]), cmp);
if (m > n)
printf("-1\n");
... |
#include<bits/stdc++.h>
#define ll long long
#define lp(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define lps(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define... | def solve():
from itertools import product
from sys import stdin
f_i = stdin
# idices of faces
indices = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5),
(0, 4, 3, 2, 1, 5), (0, 3, 1, 4, 2, 5),
(1, 0, 3, 2, 5, 4), (1, 3, 5, 0, 2, 4),
(1, 5, 2, 3, 0, 4), (1, ... |
import java.io.*;
import java.util.*;
public class D {
private void solve() throws IOException {
int n = nextInt();
int[] operationType = new int[n];
int[] operationValue = new int[n];
HashSet<Integer> interesting = new HashSet<Integer>();
for (int i = 0; i < n; i++) {
String op = nextToken();
if ("s... | #include <bits/stdc++.h>
using namespace std;
struct node {
int cnt;
long long sum[6];
};
node seg[4 * 100000];
struct info {
string str;
int num;
};
info data[100000 + 20];
map<int, int> m;
vector<int> v;
string s;
void insert(int idx, int st, int ed, int pos, int val) {
if (st == ed) {
if (val < 0)
... |
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int odd = 0;
for (int i = 0; i < 3; i++) {
odd += sc.nextInt() % 2;
}
System.out.println(odd >= 2 ? "Hom" : "Tem");
}
}
| #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
//INSERT ABOVE HERE
signed... |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N; cin >> N;
vector<long long> V;
for(int i = 0; i < N; ++i){
int x; cin >> x;
if(i == 0)V.push_back(x);
else if(*V.rbegin() != x)V.push_back(x);
}
int cnt = 1;
N = V.size();
for(int i = 2; i < N; ++i){
if((V[i] - V[i - 1]) * (V... | import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import jav... |
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
//Rock Man
public class Main{
int n, COUNT, INF = 1<<29, res;
List<E>[] edge, rev;
Map<String, Integer> ref;
int get(String s){
if(ref.containsKey(s))return ref.get(s);
ref.put(s, COU... | import sys
sys.setrecursionlimit(10000)
def checkloop(pdict,product,inroute,made):
inroute.append(product)
if pdict[product][1] in made:
return (False,product)
elif pdict[product][1]==product:
return (False,product)
elif pdict[product][1] in inroute:
return (True,pdict[product]... |
#include <bits/stdc++.h>
using namespace std;
int Rank[4000010];
int Parent[4000010];
struct DisjointSet {
int NumberOfComponents;
DisjointSet() { NumberOfComponents = 0; }
void Add(int x) {
if (Rank[x] != -1) return;
Parent[x] = x;
Rank[x] = 0;
++NumberOfComponents;
}
int Find(int x) {
if... | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;
public class Main {
public static void main(String[] args) throws IOException {
new Thread(null, new Runnable() {
public voi... |
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int b[11] = {63,6,91,79,102,109,125,39,127,111,0};
int now = 11;
int k;
int n;
while(cin >> n){
if(n == -1) break;
cin >> k;
for(int i=6;i>-1;i--) printf("%d", (b[k]>>i)&1);
now = k;
cout << endl;
n--;
... | s=[0b0111111,0b0000110,0b1011011,0b1001111,0b1100110,0b1101101,0b1111101,0b0100111,0b1111111,0b1101111]
while 1:
n=int(input())
if n<0:break
a=0
for _ in range(n):
b=int(input())
print(bin(a^s[b])[2:].zfill(7))
a=s[b] |
import java.math.BigInteger;
import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int mod = 1000000007;
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
if (k == 1 || k > n) {
... | #include <bits/stdc++.h>
using namespace std;
inline void FAST_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
template <class F, class S>
ostream& operator<<(ostream& os, pair<F, S>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T, class S>
ostream& operator<<(o... |
n, k = map(int, input().split())
s = list(map(int, input()))
cnt = 0
ans = 0
start = 0
for i in range(n):
if s[i] == 0 and (i == 0 or s[i - 1] == 1):
cnt += 1
if cnt == k + 1:
while True:
start += 1
if s[start - 1] == 0 and s[start] == 1:
break
... | import java.io.*;
import java.util.*;
import static java.lang.System.out;
public class Main {
static MyReader in = new MyReader();
public static void main(String[] args) {
int N = in.i();
int K = in.i();
char[] S = in.s(N);
IntQueue q = new IntQueue(N + 2);
int count = ... |
from operator import *
def arr_2d(n):
return [[int(x) for x in input().split()] for i in range(n)]
card ,c,point= arr_2d(int(input())),1,0
card.sort(reverse=True, key=itemgetter(1, 0))
for i, j in card:
if c==0:
break
c+=j-1
point+=i
print(point)
| #include <bits/stdc++.h>
struct card {
int a, b;
bool operator<(const card &x) const {
if (b == x.b) return a > x.a;
return b > x.b;
}
} cards[1000];
int n, i, score = 0, rem = 1;
int main() {
scanf("%d", &n);
for (i = 0; i < n; ++i) scanf("%d%d", &cards[i].a, &cards[i].b);
std::sort(cards, cards + ... |
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int n1;
n1 = 2 * n - 1;
int a[n1];
int sum = 0, i;
bool b = true;
for (i = 1; i <= n1; i++) {
cin >> a[i];
sum += a[i];
if (a[i] < 0) b = false;
}
if (b) {
cout << sum << endl;
} else {
int max = sum;
... |
# coding: utf-8
import sys
sys.setrecursionlimit(1000000)
class DFSSolver:
def __init__(self, table, h, w):
self.table = table
self.count = 0
self.h = h
self.w = w
def delta(self, i, j):
candididate = [(i-1, j-1), (i-1, j), (i-1, j+1),
(i, j-1)... | #include <iostream>
#include <cstring>
using namespace std;
int W, H;
int map[55][55];
void dfs(int cx, int cy) {
map[cy][cx] = 0;
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
if (map[cy + dy][cx + dx] == 1) dfs(cx + dx, cy + dy);
}
}
}
int solver() {
int cnt = 0;
for (in... |
import sys
a=[float(i) for i in sys.stdin]
print(max(a)-min(a))
| import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//?????°?¨????
Scanner sc = new Scanner(System.in);
double max = Integer.MIN_VALUE;
double min = Integer.MAX_VALUE;
while(sc.hasNext()) {
double num = sc.nextDouble();
max = Math.max(max, num);
min = Math.min... |
import java.util.*;
public class CodeForces835B{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int k = input.nextInt();
String s = input.next();
long sum = 0;
int[] a = new int[10];
for(int i = 0;i<s.length();i++){
int c = Integer.parseInt(s.charAt(i)+"");
sum+= c;... | k = int(input())
n = input()
sum = 0
pt = []
for i in range(len(n)):
a = 9-int(n[i])
pt.append(a)
sum += int(n[i])
diff = k - sum
pt.sort()
pt.reverse()
#print(pt)
if diff <= 0:
print("0")
else:
for i in range(len(pt)):
diff -= pt[i]
if diff<=0:
... |
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
class Reader {
BufferedReader in;
Reader() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
}
Reader(String name) throws IOException {
... | #include<bits/stdc++.h>
#define fint register int
#define h 5001
#define p 347589
#define mods 998244353
#define int long long
using namespace std;
int f[p],s[p],l[p],r[p];
signed main()
{
int n,k;
cin>>n>>k;
for(fint i=1;i<=k;i++)
cin>>l[i]>>r[i];
f[1]=1,s[1]=1;
for(fint i=2;i<=n;i++)
{
for(fint j=1;j<=k;j++)... |
import java.io.*;
import java.util.*;
public class F {
void run() {
int n = in.nextInt();
int k = in.nextInt();
long[] p = new long[n];
for (int i = 0; i < n; i++) {
p[i] = in.nextLong();
}
List<Long> seg = new ArrayList<>();
{
int i = 0;
while (i + 1 < n && p[i] >= p[i + 1]) {
i++;
}
... | #include <bits/stdc++.h>
using namespace std;
const int NMAX = 4000010;
int n, k, seqn, seqleftn, iteration;
int seqprev[NMAX], seqnext[NMAX], removed[NMAX];
long long p[NMAX], seq[NMAX];
pair<long long, int> seqleft[NMAX], pivot;
queue<int> q;
bool used[NMAX];
void debugSeq() {
for (int i = seqnext[0]; i > 0; i = se... |
#include <iostream>
int f(const int &a, const int &m) {
auto res = a;
int count = 1;
while (res != 1) {
res = (res * a) % m;
++count;
}
return count;
}
long long int gcd(const long long int &a, const int &b) {
if (b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
long long int lcd(const long long... | def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
def rooptimes(ai, mi):
x = ai % mi
i = 1
while x != 1:
x = ai * x % mi
i += 1
return(i)
while True:
a = list(map(int, input().split()))
if a.count(0) == 6:
break
ix = rooptimes(a[0], a[1])
iy = roop... |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,... | N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
D=[[0]*(X+1) for i in range(N//2+2)]
D[1][L[0]]=1
for l in L[1:]:
ND=[[0]*(X+1) for i in range(N//2+1)]
for c in range(1,N//2+1):
for s in range(X+1):
if D[c][s]==0:
continue
... |
#include <bits/stdc++.h>
const int bufSize = 1e6;
using namespace std;
inline char nc() {
return getchar();
static char buf[bufSize], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2)
? EOF
: *p1++;
}
inline void read(char *s) {
static... | // https://codeforces.com/blog/entry/80562
import java.io.*;
import java.util.*;
public class CF1384E extends PrintWriter {
CF1384E() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1384E o = new CF1384E(); o.main(); o.flush();
}
static final int A = 20;
int... |
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public int getP(int pos){
if(pos==0) return 2;
if(pos==1) return 3;
if(pos==2) return 5;
if(pos==3) return 7;
if(pos==4) return 11;
if(pos==5) retur... | #include <bits/stdc++.h>
using namespace std;
const int N = 1100;
const int inf = 0x3f3f3f3f;
const long long infll = 0x3f3f3f3f3f3f3f3fll;
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
long long dp[N][N][11];
long long fpow(long long a, long long b) {
;
long long c = 1;
for (; b; b >>= 1, a = a * a)
i... |
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
char c[]=sc.next().toCharArray();
int ans=0;
for(int i=0;i<c.length;i++){
ans+=(c[i]-'0');
}System.out.println(ans%9==0?"Yes":"No");
}
} | #include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int sum=0;
char c;
while((c=getchar())&&'0'<=c&&c<='9')
sum+=(c-'0');
puts(sum%9?"No":"Yes");
return 0;
}
|
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): ret... | import java.util.*;
import java.io.*;
public class Div680 {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////... |
n,m = map(int,input().split())
lis = list(map(int,input().split()))
li = [0 for i in range(n)]
for i in range(n):li[lis[i]-1] += 1
li.sort(reverse = True)
ans = 0
for k in range(m):
ans += li[k]
print(n-ans) | #include <bits/stdc++.h>
using namespace std;
int cnt[200001],n,k;
int main() {
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++) {
int v;
scanf("%d",&v);
cnt[v]++;
}
vector<int> arr;
for(int i=1;i<=n;i++) arr.push_back(cnt[i]);
sort(arr.begin(),arr.end());
int ans=0;
f... |
import java.util.Scanner;
public class E {
static long xg, yg;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int s = sc.nextInt();
long c3 = 0, c4 = 0, c5 = 0;
for (int i = 1; i <= n; i++) {
int t = sc.n... | #include <bits/stdc++.h>
using namespace std;
int f(int c3, int k3, int c4, int k4, int c5, int k5) {
return abs(c3 * k3 - c4 * k4) + abs(c4 * k4 - c5 * k5);
}
int main() {
int n, s;
int c3 = 0, c4 = 0, c5 = 0;
int k3 = -1, k4 = -1, k5 = -1;
int bk3 = -1, bk4 = -1, bk5 = -1;
int minval = 100000000;
cin >>... |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx,tune=native")
using namespace std;
struct state {
int tp;
};
state states[10];
void ander(int ind, int vl) {
if (vl == 1)
return;
else
states[ind].tp = 1;
}
void orer(int ind, int vl) {
if (vl == 0)
ret... | 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 Pradyumn
*/
public class M... |
for _ in range(int(input())):
n, m = map(int, input().split())
a = [input() for x in range(n)]
ans = 0
for j in range(m):
w = 0
for i in range(n):
w = min((w, j, m - j - 1))
for k in range(w + 1):
if a[i][j + k] == '.' or a[i][j - k] == '.':
... | #include<iostream>
#include<cstring>
using namespace std;
string sn;
int vis[550][550];
char list[550][550];
int main() {
int n,m;
int t;
cin>>t;
while(t--) {
int n,m;
cin>>n>>m;
for(int i=0; i<n; i++) {
scanf("%s",list[i]);
}
int ans = 0 ;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if... |
import java.io.BufferedReader;
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.Arrays;
import java.util.StringTokenizer;
import java.util.Tr... | '''input
4
mail
ai
lru
cf
'''
import sys
pow2 = pow # for modular expo pow2(base, n, mod)
from math import *
from time import time
from collections import defaultdict
from bisect import bisect_right, bisect_left
from string import ascii_lowercase as lcs
from string import ascii_uppercase as ucs
from fract... |
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int getChar() {
static char buf[1 << 16];
static int pos = 0, size = 0;
if (pos == size) {
pos = 0;
... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Random;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/... |
print(function(n, a) {
a.sort(function(a, b) {
return b - a;
});
var sum = 0;
var b =a.map(function(v) {
return sum += v;
});
var ans = 0;
for (var i = 1; i <= n; i *= 4) {
ans += b[i - 1];
}
return ans;
}(+readline(), readline().split(' ').map(Number)));
| 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... |
import java.util.*;
import java.io.*;
public class aaaaaaaaaaaaaaaa {
public void run() throws Exception {
Scanner file = new Scanner(System.in);
int times= file.nextInt();
ArrayList<Integer> a = new ArrayList();
int max = Integer.MIN_VALUE;
for (int i = 0; i < times; i++) {
int tm=file.nextInt();
max... | n=int(input())
arr=[int(i) for i in input().split()]
x=max(arr)
ans=0
A=[]
j=arr.index(x)
for i in range(j,n):
if (arr[i]==x):
ans+=1
else:
A.append(ans)
ans=0
A.append(ans)
print(max(A)) |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
i... | #include <bits/stdc++.h>
using namespace std;
long long ksm(long long a, long long b) {
if (!b) return 1;
long long ns = ksm(a, b >> 1);
ns = ns * ns % 1000000009;
if (b & 1) ns = ns * a % 1000000009;
return ns;
}
long long jc[155], bjc[155];
void ch(vector<int> &r, int tp) {
for (int i = 0; i < r.size(); i... |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class KForPriceOfOne {
static final in... | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, p, k, a[N];
bool check(int x) {
int cost = 0;
while (x > 0) {
cost += a[x];
if (cost > p) return false;
x -= k;
}
return true;
}
int main() {
int test;
cin >> test;
while (test--) {
cin >> n >> p >> k;
for (int... |
#include <bits/stdc++.h>
using namespace std;
long long n, m, s;
long long hoge(long long a, long long b) {
long long mx = 0, i, j;
for (i = 1; i <= sqrt(a); i++) {
if (a % i) continue;
if (s - i + 2 > 0) {
long long tmp = (a / i) * int(b / (s - i + 2));
mx = max(mx, tmp);
}
if (s - a / ... | import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list... |
import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Bunyod Xalilov
*/
public class Main {
public static void main(String[] args) {
InputStre... | #include <bits/stdc++.h>
using namespace std;
int a[1001];
unsigned long long int sum = 0;
inline int read_int() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') {
w = -1;
}
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
... |
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution ... | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
int l[6][6], r[6][6], a[6][6];
vector<pair<int, int> > v;
int t = 1;
int table[30][15000][16];
bool was[30][15000][16];
int bad = -100000000;
inline void pars... |
while 1:
n=int(raw_input())
if n==0: break
x=sorted(map(int,[raw_input() for _ in [0]*n]))
s=a=0
for e in x[:-1]: a+=e; s+=a
print s | #include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n;
while(cin>>n,n){
int a[10000];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
long long int ans = 0;
for(int i=0;i<n-1;i++){
ans += a[i]*(n-i-1);
}
... |
#include <bits/stdc++.h>
using namespace std;
inline int II() {
int n;
scanf("%d", &n);
return n;
}
struct ii {
long long v, k;
};
ii ft[300002];
int N;
void update(int k, long long deltav, long long deltak) {
for (; k; k -= (k & (-k))) {
ft[k].v = (ft[k].v + deltav + 1000000007LL) % 1000000007LL;
ft[... | import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitS... |
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
int x[] = {
1, 8, 6, 3,
2, 0, 7, 4,
3, 1, 8, 5,
4, 2, 0, 6,
5, 3, 1, 7,
6, 4, 2, 8,
7, 5, 3, 0,
8, 6, 4, 1,
0, 7, 5, 2
};
int a[362889][9], p[11], cnt, fact[11]; bool used[11];
void build(int pos) {
if (pos == 9) {
for (int i = 0; i... | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.InputMismatchExc... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class d {
static class BitTrie{
BitTrie zero = null, one = null;
int height;
BitTrie(int h){
height = h;
}
void insert(int thisInt, int bit) {
if(height == 0) {
}
else {
int direction = (... | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
const int INF = 1e9;
const lint INFL = 1e18;
void solve(int cur, int b, int& res, vector<int>& list) {
if (b == -1) {
res = min(res, cur);
return;
}
int bit = 1 << b;
vector<int> L, R;
for (int i : list) {
if (bit & i)
... |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100010];
vector<int> g[100010];
char used_centroid[100010];
int sz[100010];
int cnt = 0;
long long an = 0;
int c1[100010];
int c[20][2];
void dfs(int v, int par, int sum, int centroid) {
an += sum;
if (v != centroid) {
c1[v] = sum;
int t = sum ^ ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Rene
*/
public class Main {
public sta... |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
template <class T>
T gcd(T a, T b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int x[100000];
int value;
void bsearch(int left, int right) {
if (right - left < 2) {
if (x[right] <= value)
printf("%d\n"... |
import java.util.Scanner;
public class Codeforces706a {
static double minTime = Double.MAX_VALUE;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int myX = scanner.nextInt();
int myY = scanner.nextInt();
int cars = scanner.nextInt();
... |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3
0.0 0.0
2.0 0.0
1.0 1.0
output:
1.41421356237
"""
import math
import sys
from operator import attrgetter
class ClosestPair(object):
def __init__(self, ):
"""
Init closest pairs points set.
"""
_input = sys.stdin.readline... | import java.util.*;
import java.text.DecimalFormat;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.StringTokenizer;
class Main {
static final double EPS = 1e-12;
// for two points x(x0,x1) and y(y0,y1), wh... |
#include <bits/stdc++.h>
using namespace std;
namespace patch {
template <typename T>
std::string to_string(const T& n) {
std::ostringstream stm;
stm << n;
return stm.str();
}
} // namespace patch
int m, lim, len;
long long dp[1 << 18][101];
string s;
long long fac[19];
int freq[10];
long long solve(int mask, in... | d = '0123456789ABCDEFGH'
prev = {d[i]: d[i - 1] for i in range(1, 18)}
next = {d[i]: d[i + 1] for i in range(17)}
n, m = raw_input().split()
p, m = ['0'] * 10, int(m)
k, l = 1, len(n)
for x in map(int, n): p[x] = next[p[x]]
a = ''.join(p)
u, v = {a: [0] * m}, {}
u[a][0] = 1
for r in range(1, l + 1):
if r == l an... |
#include <bits/stdc++.h>
using namespace std;
long long int pow_mod(long long int a, long long int b) {
long long int res = 1;
while (b) {
if (b & 1) res = (res * a);
a = (a * a);
b >>= 1;
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
long long int n;
cin >> n;
long long int num... | import java.util.Scanner;
public class Main {
public static boolean check(long temp) {
long temp1;
while (temp > 0) {
temp1 = temp % 10;
temp /= 10;
if (temp1 > 1)
return false;
}
return true;
}
public static void main(Strin... |
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
d = int(input())
disable = [False] * n
base = 5001
ds = [int(input())-1 for _ in range(d)]
for ele in ds:
disable[ele] = True
# Create Graph
childs = [[] for i in range(... | import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
void solve() {
n=ni(); m=ni();
int p[]=new int[n+1];
for(int i=1;i<=n;i++) p[i]=ni();
int c[]=new int[n+1];
for(int i=1;i<=n;i++) c[i]=ni();
int d=ni();
int k[]=... |
from __future__ import division, print_function
def main():
class DSU:
def __init__ (self,n):
self.parent=list(range(n))
self.size=[1]*n
self.count_sets=n
def find(self,u):
to_update=[]
while u!=self.parent[u]:
to_update.app... | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class cf1184e1 {
static int par[];
static int find(int i) {
return par[i] == i ? i : (par[i] = find(par[i]));
}
static boolean union(int i, int j) {
int a = find(i), b = fi... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
bool booly = false;
int index = -1;
vector<pair<int, int>> e;
for (int i = 0; i < k; i++) {
int u, v;
cin >> u >> v;
if (u == n && v == m) {
booly = true;
index = i;
}
e.push_back({u, ... | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class d
{
/*
0 - col before lit
... |
import java.util.*;
import java.io.*;
import java.io.PrintWriter;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
// Scanner sc = new Scanner(System.in);
// FastScanner sc = new FastScanner(System.in);
FastScanner sc = new FastScanner... | /* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < (n); i++)
#define cont(i, n) for(int i = 1; i <= (n); i++)
#define circ(i, a, b) for(int i = ... |
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static class FastReader {
BufferedReader br;
StringTokenizer root;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (root == null || !root... | #include <bits/stdc++.h>
using namespace std;
const int N = 2e2;
double memo[N + 5][N + 5][N + 5];
bool vis[N + 5][N + 5][N + 5];
double p[N + 5];
int bobot[N + 5];
int n, l, k;
double dp(int idx, int need, int space) {
if (space < 0) return 0.0;
if (need < 0) return dp(idx, 0, space);
if (space > n) return dp(id... |
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#endif
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef std::vector<vector<int> > vv... | import math
class RMQ:
def __init__(self, arr):
self.n = len(arr)
self.logn = int(math.log2(self.n)) + 1
self.arr = [0] + arr
self.Log = [0] * (self.n + 1)
self.Log[2] = 1
for i in range(3, self.n + 1):
self.Log[i] = self.Log[i // 2] + 1
self.min =... |
#include<bits/stdc++.h>
#define f fafa
#define s second
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
int n,m, k, a, b, minim;
int adj[3005][3005];
int deg[3005], ndeg[3005];
vector<int> v[3005];
bool flag[3005];
bool relax[3005];
int constructt(bool first) {
int res = 0, id2 = -1;
bool fafa = ... | from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
sys.setrecursionlimit(10**5)
def solve():
N, M, K = map(int, readline().split())
G = [[] for i in range(N)]
for i in range(M):
a, b = map(int, readline().split())
G[a-1].append(b-1)
G[b-1]... |
import java.io.*;
import java.util.*;
import java.util.function.Function;
@SuppressWarnings("ALL")
public class Main {
static int M, N;
static int[][][] K;
public static void main(String[] args) {
FastScanner sc = new FastScanner(System.in);
M = sc.nextInt();
N = sc.nextInt();
... | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.