anchor stringlengths 10 14.3k | positive stringlengths 10 14.9k |
|---|---|
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]... |
#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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.