anchor stringlengths 10 14.3k | positive stringlengths 10 14.9k |
|---|---|
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.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper... | #include <bits/stdc++.h>
using namespace std;
struct data {
long long sum;
int num;
};
int a[100010], gcd[100010][20], ch[100010], lg, cnt;
long long sum[100010], pre[2][100010];
data A[100010];
int calc(int a, int b) {
int y = a % b;
while (y) {
a = b;
b = y;
y = a % b;
}
return b;
}
int get_gc... |
#include <bits/stdc++.h>
using namespace std;
double mx = 0;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, j = 0;
cin >> n;
string s = "", c[7] = {"R", "O", "Y", "G", "B", "I", "V"};
for (int i = 0; i < n - 3; i++, j++) {
if (j == 4) j = 0;
s += c[j];
}
s += "BIV";
cout... | import java.util.*;
public class B{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
char[] colors = {'R','O','Y','G','B','I','V'};
for (int i = 0; i < 4; i++){
// fill star... |
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
const int INF = 1000000000;
inline void update(int& x, int y){
if(x > y) x = y;
}
int main(){
int n, m, l, s, t;
while(cin >> n >> m >> l >> s >> t && n > 0){
s--;
int dist[300][300];
REP... | from heapq import heappush, heappop
import sys
def main():
readline = sys.stdin.readline
write = sys.stdout.write
L2 = 1 << 16
bc = [0]*L2
for i in range(1, L2):
bc[i] = bc[i ^ (i & -i)] + 1
INF = 10**18
def solve():
N, M, L, s, T = map(int, readline().split())
if N =... |
# coding: utf-8
# Your code here!
class UnionFind:
def __init__(self, n):
self.parent = list(range(n)) #親ノード
self.size = [1]*n #グループの要素数
self.cycle = [0]*n
def root(self, x): #root(x): xの根ノードを返す.
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]... | /**************************************************************
File name: E.cpp
Author: huhao
Email: 826538400@qq.com
Create time: 2019/8/24 下午9:22:27
**************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#defi... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main{
public static void main(String args[]) {
BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
String str="";
try {
while(true) {
str=bfr.readLine();
if(str=="") {
System... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0, i = 1;
scanf("%d", &n);
while (true) {
if (i * 2 - 1 > n) {
printf("%d\n", ans);
return 0;
} else {
ans++;
}
i *= 2;
}
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
const int vmax=5010;
const int inf=1<<30;
struct edge{int to,cap,rev;};
vector<edge> graph[vmax];
int level[vmax],iter[vmax];
void reset(){
rep(i,vmax) graph[i].clear();
}
void add_edge(int from,int to,int cap){
// cout <<... | 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.*;
public class Main{
Scanner sc=new Scanner(System.in);
int INF=1<<28;
int n, w;
int[] a, b;
void run(){
n=sc.nextInt();
w=sc... |
// practice with rainboy
import java.io.*;
import java.util.*;
public class CF613B extends PrintWriter {
CF613B() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF613B o = new CF613B(); o.main(); o.flush();
}
void main() {
int n = sc.nextInt();
int a... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, cf, cm, L, R;
long long A, M, sk[maxn], mn[maxn], ans, meg, nw[maxn];
vector<long long> sm;
pair<int, int> srt[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> A >> cf >> cm >> M;
for (int i = 0; i < n; i+... |
N = int(input())
X = list(map(int, input().split()))
ans = 0
mod = 998244353
for i, x in enumerate(X):
ans = (ans * 2 + x * pow(x+1, i, mod)) % mod
print(ans)
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll MOD = 998244353;
ll power(ll x, ll n){
x %= MOD;
ll res = 1;
while(n > 0){
if(n&1){
res *= x;
res %= MOD;
}
x *= x;
x %= MOD;
n >>= 1;
}
return res;
}
i... |
import java.util.*;
import java.io.*;
public class Solution{
public static Integer INT(String s){
return Integer.parseInt(s);
}
public static Long LONG(String s){
return Long.parseLong(s);
}
//==================================================================================================================... | N = int(input())
s = input()
leftSum = sum(int(c) for c in s[:N//2] if c != '?')
rightSum = sum(int(c) for c in s[N//2:] if c != '?')
leftOptions = 0
leftSum = 0
for c in s[:N//2]:
if c == '?':
leftOptions += 1
else:
leftSum += int(c)
rightOptions = 0
rightSum = 0
for c in s[N//2:]:
... |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, pos, l, r, ans = 0, k = 0;
cin >> n >> pos >> l >> r;
if (pos < l) {
ans += l - pos;
pos = l;
if (r != n) {
ans += (r - l);
pos = r;
}
} else if (pos > r) {
ans += pos - r;
pos = r;
if (l != 1) {
... | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
@SuppressWarnings("unchecked")
public class P915B {
public void run() throws Exception {
int n = nextInt(), p = nextInt(), l = nextInt(), r = nextInt();
if ((l == 1) && (r == n)) {
println(0);
} else if (l == 1) ... |
def main():
n, mod = [int(x) for x in input().split()]
coupl = [[] for _ in range(n)]
for _ in range(n-1):
u,v = [int(x)-1 for x in input().split()]
coupl[u].append(v)
coupl[v].append(u)
subtree_memo = [-1]*n
@bootstrap
def subtrees_with_black_root(node, parent):
... | import java.io.*;
import java.util.*;
public class Main {
private static Scanner sc;
private static Printer pr;
private static void solve() {
int n = sc.nextInt();
int m = sc.nextInt();
int[][] xy = sc.nextIntArrays(2, n - 1);
RoutedTree rt = new RoutedTree(n);
for (int i = 0; i < n - 1; i++) {
in... |
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
using Array = vector<double>;
using Matrix = vector<Array>;
const double eps = 1e-10;
Array GaussJordan(const Matrix& A, const Array& b) {
int n ... |
import java.io.IOException;
import java.io.PrintWriter;
public class Main {
int D;
double[] V = new double[10];
public void solve() {
while(true){
D = nextInt();
if(D == 0) break;
for(int i = 0; i < D + 3; i++){
V[i] = Double.parseDouble(next());
}
DoubleMatrix mat = new DoubleMatrix(D + 1, D... |
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
public class test{
Scanner in;
PrintWriter out;
boolean[] v;
... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e6 + 3;
const long long INF = 2e15;
int a[1234][1234];
std::vector<int> adj[32];
int deg[34];
int vis[34];
bool cmp(int x, int y) {
if (deg[x] != deg[y]) {
return deg[x] < deg[y];
}
return x < y;
}
void dfs(int u) {
vis[u] = 1;
for (int i = 0;... |
// No sorceries shall previal. //
import java.util.Scanner;
import java.io.PrintWriter;
import java.util.*;
import java.util.Arrays;
public class _InVoker_ {
public static void sort(long arr[], int start, int end) {
if(start>=end)
return;
int mid=(start+end)/2;
sort(arr,start,mi... | n,k=map(int,input().strip().split())
a =list(map(int,input().strip().split()))
from collections import deque, Counter
temp = Counter(a)
a = deque(sorted(map(lambda x: [x,temp[x]], temp)))
# print(a)
while( (k>=a[0][1] or k>=a[-1][1] ) and len(a)>1):
# forward
cf,f,smf = a[0][1], a[0][0], a[1][0]
cr,r,smr = ... |
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
long h = scan.nextLong();
int n = scan.nextInt();
long sum = 0;
int i;
for(i = 0; i < n; i++)
sum += scan.nextLong();
if(sum >= h)
System.out.println("Yes");
else
Syst... | #include<bits/stdc++.h>
using namespace std;
int main(){
int h, n, x; cin >> h >> n;
for(int i = 0; i < n; ++i){
cin >> x;
h -= x;
}
cout << (h <= 0 ? "Yes" : "No") << endl;
} |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class P572D {
public static long solve(int n, int k, long[] A) {
Arrays.sort(A);
int q = n / k;
int r = n % k;
long[] M = {0L};
// System.err.println(... | #include <bits/stdc++.h>
using namespace std;
int n, k, A[300000];
long long done[5001][5001];
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) scanf("%d", &A[i]);
sort(A, A + n);
int x = n / k, y = n % k;
for (int i = 1; i < k + 1; i++)
for (int j = 0; j < min(y, i) + 1; j++) {
if (j == 0)
... |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
typedef class Point {
public:
int x, y;
Point() {}
Point(int x, int y) : x(x), y(y) {}
} Point;
int n, X, Y, Z;
int xs[N], ys[N], zs[N];
Point xy[N], xz[N], yz[N], yx[N], zx[N], zy[N];
long long ans = 0;
vector<Point> solve1(Point* S, int R, in... | //package round419;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.List;
public class D {
InputStream is... |
N=int(input())
l=input()
for i in range(len(l)):
print(chr((ord(l[i])+N-65)%26+65),end="")
| import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String A = sc.next();
char c = ' ';
for(int i=0;i<A.length();i++) {
c = A.charAt(i);
for(int k=0;k<N;k++) {
if(c=='Z'){
c='A';
--c;
}
... |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Div2_406E {
public static void... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long md = (1e9) + 7;
int n;
struct segtree {
struct node {
int sum;
node *l, *r;
node(int s) {
sum = s;
l = r = 0;
}
node(node *left, node *right) {
l = left;
r = right;
sum = 0;
if (... |
import math
from collections import Counter
n = int(input())
a = Counter(map(int, input().rstrip().split()))
li = []
for i in range(n):
maxm = max(a)
a[maxm] -= 1
for x in li:
a[math.gcd(x, maxm)] -= 2
li += [maxm]
a += Counter()
print(*li) | #include <bits/stdc++.h>
using namespace std;
map<int, int> ma;
int a[500 * 500 + 10];
int gcd(int p, int q) {
if (q == 0)
return p;
else
return gcd(q, p % q);
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n * n; i++) {
scanf("%d", &a[i]);
ma[a[i]]++;
}
sort(a + 1, a + 1 + n * n);
... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args)
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
try {
String entrada = read.readLine();
String respuesta = "";
char[] let... | #include <bits/stdc++.h>
using namespace std;
int main() {
string t;
cin >> t;
int i = 1, mid = 0, k = 0;
mid = (t.size() - 1) / 2;
cout << t[mid];
while (1) {
k = mid + i;
if (k == t.size())
break;
else
cout << t[k];
k = mid - i;
if (k < 0)
break;
else
cout <... |
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <array>
#include <cassert>
using namespace std;
using ll = long long;
const int MOD = 998244353;
template<int N>
struct Dsu {
array<int, N> p, r, d;
array<array<int, N>, 2> h;
ll hash;
Dsu() : hash(0) {
io... | import java.io.*;
import java.util.*;
/*
polyakoff
*/
public class Main {
static FastReader in;
static PrintWriter out;
static Random rand = new Random();
static final int oo = (int) 1e9 + 10;
static final long OO = (long) 2e18 + 10;
static final int MOD = 998244353;
static final int N = ... |
#include <bits/stdc++.h>
using namespace std;
int fact[] = {1, 1, 2, 6, 24, 120, 720,
5040, 40320, 362880, 3628800, 39916800, 479001600};
int perm[13];
int used[13];
int main() {
int a, b;
scanf("%d%d", &a, &b);
if (a < 13 && b > fact[a]) {
printf("-1\n");
return... | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
BufferedReader in;
StringTokenizer st;
PrintWriter out;
static ArrayList<Long> list = new ArrayList<Long>();
static void gen(long a, int len) {
// if (a != 0)
list.add(a);
if (len >... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.ArrayDeque;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
SC sc = new SC(System.in);
int N... | #include <iostream>
#include <queue>
using namespace std;
int main() {
int n; cin >> n;
char a, b, t;
queue<char> p;
for (int i = 0; i < n; ++i) {
cin >> t;
p.push(t);
if (p.size() == 2) {
a = p.front(); p.pop(); b = p.front(); p.pop();
if (a == 'T' && b == 'F') p.push('F');
else p.push('T');
}
... |
import java.io.*;
import java.util.*;
public class F2 {
int mod = 1000000007;
int[][] prob;
public static int invInt(int a, int mod) {
int res = 1;
int b = mod - 2;
while (b > 0) {
if ((b & 1) != 0) {
res = (int) ((long) res * a % mod);
}
... | #include <bits/stdc++.h>
using namespace std;
const int N = 7, M = 20, MOD = 1000 * 1000 * 1000 + 7;
int sum(int a, int b) { return ((a + b) % MOD + MOD) % MOD; }
void _sum(int &a, int b) { a = sum(a, b); }
int mul(int a, int b) { return 1LL * a * b % MOD; }
void _mul(int &a, int b) { a = mul(a, b); }
int power(int a, ... |
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
... | import itertools
class Dice:
N = [0, 1, 5, 4]
S = N[::-1]
E = [0, 3, 5, 2]
W = E[::-1]
R = [1, 2, 4, 3]
L = R[::-1]
def __init__(self, numbers):
self.numbers = numbers
def __eq__(self, other):
if isinstance(other, Dice):
newdice = Dice(other.numbers.copy())... |
import sys
input = sys.stdin.readline
N = int(input())
graph = [[] for _ in range(N)]
Edges = {}
for i in range(N-1):
a, b = map(int, input().split())
a -= 1; b -= 1
graph[a].append(b)
graph[b].append(a)
Edges[str(a) + "," + str(b)] = i
Edges[str(b) + "," + str(a)] = i
ans = [-1]*(N-1)
ind = 0... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int values[N] = {};
vector<pair<int, int>> g[N];
bool cmp(vector<pair<int, int>> a, vector<pair<int, int>> b) {
return a.size() > b.size();
}
void solve(int n) {
int m = 0;
for (int i = 0; i < n; ++i) {
for (auto& p : g[i]) {
if (value... |
tv=[]
n=int(input())
for i in range(n):
l,r=map(int,input().split())
tv.append([l,r,i+1])
tv.sort()
ans=-1
r=tv[0][1]
l=tv[0][0]
tmp=tv[0][2]
for i in range(1,n):
if(tv[i][0]<=l and tv[i][1]>=r):
ans=tmp
break;
if(tv[i][1]<=r):
ans=tv[i][2]
break;
else:
l=max(... | #include <bits/stdc++.h>
using namespace std;
int mp[400000];
pair<int, int> tv[200000];
vector<pair<bool, int> > ev[400000];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < (int)n; ++i) {
scanf("%d%d", &tv[i].first, &tv[i].second);
++tv[i].second;
mp[i << 1] = tv[i].first;
mp[i << 1 | 1]... |
n, m, k = map(int, raw_input().split())
a = [map(int, raw_input().split()) for _ in range(n)]
c, s = [0] * m, [0] * n
for _ in range(k):
x, y = map(lambda x: int(x) - 1, raw_input().split())
s[x], c[y] = s[x] + 1, c[y] + 1
for i in range(n):
print sum(a[i][j] * c[j] for j in range(m)) - s[i],
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
int *wrk = new int[n];
int *chat = new int[m];
int **a = new int *[n];
for (int i = 0; i < n; ++i) a[i] = new int[m];
for (int i = 0; i < m; i++) chat[i] = 0;
for (int i = 0; i < n; i++) {
wrk[i] = 0;
for... |
#include <bits/stdc++.h>
using namespace std;
int a[10000005], l[10000005], r[10000005];
long long c[10000005], ans = 0;
stack<pair<int, long long> > A;
deque<pair<int, long long> > B, C;
int TakeInputAndInitialise() {
int n, m;
vector<vector<int> > u(1), v(1);
scanf("%d%d", &n, &m);
while (n--) {
int k;
... | //package round541;
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 G {
InputStream is;
PrintWriter out;
String INPUT = "";
// String INPUT = "1 7\n" +
// "7\n" ... |
#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline int qread() {
register char c =
(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
? EOF
: *p1++);
register int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-... | from __future__ import division, print_function
def main():
# Template 1.0
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor
from heapq import heappush, heappop, heapify, nlargest, nsmal... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a;
cin >> n >> m;
double x;
vector<int> t;
for (int i = 0; i < n; i++) {
cin >> a >> x;
auto idx = upper_bound(t.begin(), t.end(), a);
if (idx == t.end())
t.push_back(a);
else
*idx = a;
}
cout << n - t.size() ... |
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
public class f
{
public static void print(String str,int val){
System.out.println(str+" "+val);
}
public long gcd(long a, long b) {
if (b==0L) return a;
... |
# Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import Byt... | #pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back... |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, sum = 0;
long long int n;
cin >> n;
long long int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
}
for (i = 0; i < n; i++) {
long long int c = b[i] / 2;
if ((b[i] !=... | n=int(input())
ar=map(int,raw_input().split())
br=map(int,raw_input().split())
sj=0
for i in xrange(n):
s1=int(br[i]/2)
s2=(br[i]-s1)
if (1<=s1<=ar[i])and(1<=s2<=ar[i]):
sj+=(s1*s2)
else:
sj-=1
print sj
|
q = int(input())
A = [0 for i in range(1500000)]
A[0] = 'end'
cursor = 0
head = [0 for i in range(1500000)]
head_len = 0
def insert(x):
global cursor
cursor += 1
A[cursor] = x
def move(d):
global cursor, head, head_len
if d >= 0:
head[head_len-1+d+(1): head_len-1+(1):-1] = A[cursor-d+1:cursor+1]
else:
A[curs... | //import java.lang.Math;
import java.util.*;
import java.util.List;
//import java.util.ListIterator;
//import java.util.Iterator;
//import java.util.LinkedList;
class Main{
public static void main(String[] arg){
Scanner sc=new Scanner(System.in);
int cnt=sc.nextInt();
LinkedList<Integer> list= new LinkedLi... |
import java.util.*;
import java.io.*;
public class QuestionB2 {
static Reader sc = new Reader();
public static void main(String[] args) throws IOException{
int t = sc.nextInt();
while(t-->0) {
solve();
}
}
public static void solve() throws IOException{
int n = sc.nextInt();
int k = sc.nextInt();
... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int a[maxn];
int main() {
int t;
cin >> t;
while (t--) {
int n, k, l;
cin >> n >> k >> l;
int flag = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = l - a[i];
a[i] = min(a[i], k);
if (a[i] < 0) {... |
#include <bits/stdc++.h>
using namespace std;
int n, i, j;
int main() {
scanf("%d", &n);
int res = 0;
for (i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (x % 2 == 0)
x = 1;
else
x = 0;
res ^= x;
if (res == 0)
printf("2\n");
else
printf("1\n");
}
}
|
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class SpiderMan {
private void solve() {
int n = in.nextInt();
int config = 0;
for (int i =... |
import java.io.*;
import java.util.*;
public class Main {
static InputStream is;
static PrintWriter out;
static String INPUT = "";
static void solve()
{
char[] s = ns().toCharArray();
int n = s.length;
int mod = 998244353;
int als = 1;
for(int i = 0;i < n;i++){
if(s[i] != s[0])als = 0;
}
i... | def solve(s):
if all(a == b for a, b in zip(s, s[1:])):
return 1
if len(s) == 2:
return 2
elif len(s) == 3:
if s[0] == s[1] or s[1] == s[2]:
return 6
elif s[0] == s[2]:
return 7
else:
return 3
# dp[has succession=0][mod 3][last ... |
import java.util.*;
import java.io.*;
public class FloodFill {
public static void main(String[] args) {
FastScanner scanner = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int N = scanner.nextInt();
int[] cols = new int[N];
for(int i = 0; i < N; i++) cols... | n=int(raw_input())
arr = [int(x) for x in raw_input().split()]
ls = [arr[0]]
for el in arr[1:]:
if el!=ls[-1]:
ls.append(el)
n=len(ls)
dpa = list()
dpb = [0] * (n+1)
for sz in range(2,n+1):
dp=[]
for start in range(n-sz+1):
if ls[start] == ls[start+sz-1]:
#if dpa[start+1] < min(... |
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex... |
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
//0を北とする
int dir = 0;
//一周したかの判定にスタックを使う
//Rでpush, Lでpopとすることで
//sizeが5になったら1周完了、0なら回転失敗と判断
Stack<Integer> stack = new Stack<... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int sum = 0;
for (int i = 0; i < n; i++) {
sum = sum + a[i];
}
int m;
cin >> m;
int i = 0;
for (i; i < m; i++) {
int l, r;
cin >> l >> r;
... | ##n = int(input())
##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
n = int(input())
a = list(map(int, input().split()))
tot = 0
for e in a:
tot += e
m = int(input())
for i in range(m):
[l , r] = list(map(int, input().split()))
if l <= tot and tot <= r:
print(tot)
ex... |
from fractions import Fraction
def higher(x1, y1, x2, y2):
if x1 == 0:
if x2 == 0:
return
def min_days(p, q, pr):
ma = max(a for a, b in pr)
mb = max(b for a, b in pr)
pr.sort(key=lambda t: (t[0], -t[1]))
ch = [(0, mb)]
for a, b in pr:
if a == ch[-1][0]:
... | #include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-1;
bool is_zero(long double a) {
if (a > eps) return false;
if (a < -eps) return false;
return true;
}
bool zgodne(pair<long double, long double> a, pair<long double, long double> b,
pair<long double, long double> c) {
if (is_z... |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,i,j,k,now,num,ans,v[1010],a[1010],f[2][310][310],p=1e9+7;
int main(){
scanf("%lld",&n);
m=n*2;
for(i=1;i<=m;i++)scanf("%lld",&a[i]);
for(i=1;i<=m;i+=2)if(a[i]==-1||a[i+1]==-1){
num+=(a[i]==-1)&&(a[i+1]==-1);
if(a[i]!=-1)v[a[i]]=1;
else ... | 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.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using db = double;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
ll gcd(ll a, ll b) {
... | import math
def maxSubArraySum(a, size):
max_so_far = int(-1e-19)
max_ending_here = 0
st = 0
ef = 0
et = 0
sf = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
ef = i... |
n=input()
x=0
y=0
def dis(x,y,a,b):
return (x-a)**2+(y-b)**2
lst=[]
ans=[0]*n
lst2=[]
lst4=[]
ans2=[0]*n
for i in range(0,n):
a,b=map(int,raw_input().split())
lst4.append((a,b))
lst.append((a*a,a,b,i))
lst2.append((b*b,a,b,i))
lst.sort(reverse=True)
lst2.sort(reverse=True)
for i in range(0,n):
a=lst[i][1]
... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
long long X, Y;
int ans[maxn];
pair<pair<int, int>, int> s[maxn];
int main() {
int N, x, y, i;
scanf("%d", &N);
for (i = 1; i <= N; i++) {
scanf("%d%d", &x, &y);
s[i] = make_pair(make_pair(x, y), i);
}
while (true) {
random_shu... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual soluti... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 252;
const int inf = 0x3f3f3f3f;
const double eps = 1e-2;
int a[maxn];
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++) {
int sum = 0;
int mmax = -inf;
for (int k = 0; k < 250; k++) {
scanf("%d", &... |
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
cin>>S;
int cnt=0,res=0;
for(int i=0;i<S.length();++i){
char ch=S[i];
if(ch=='A'||ch=='T'||ch=='C'||ch=='G'){
cnt++;
res=max(res,cnt);
}
else cnt=0;
}
cout<<res;
return 0;
} | import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern p = Pattern.compile("[ACGT]+");
Scanner s = new Scanner(System.in);
int result = 0;
String inS = s.next();
Matcher m = p.matcher(inS);
for(... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct Info {
int a, b;
Info operator+(const Info& B) const {
return (Info){a + B.a, max(b + B.a, B.b)};
}
};
struct Segment_Tree {
const static int NODE = N << 2;
bool setv[NODE];
Info A[NODE];
void pushdown(int o, int L, int R) {
... | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class DivCmb_502G implements Runnable {
public static void ma... |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class Main {
private static StreamTokenizer inputReader = new Stre... | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1061109567;
const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
map<int, int> mp;
int main() {
int n, x;
long long ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
... |
import static java.lang.Math.*;
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String next() {
while (st==null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (Exception e) {}
... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long T, S, q, ans = 0;
cin >> T >> S >> q;
while (1) {
if (S >= T) break;
ans++;
S = S + S * (q - 1);
}
cout << ans << endl;
}
|
// Test ..
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000 + 100;
long long d[maxn];
int main() {
ios::sync_with_stdio(false);
long long n, m;
cin >> n >> m;
long long p = 0;
long long Cn3 = (n * (n - 1) * (n - 2)) / 6;
for (int i = 0; i < m; ++i) {
int t1, t2;
cin >> t1 >> t2;
t... |
''' codeforces: Chemical
using disjoint sets
'''
n,m=map(int,raw_input().split())
if m==0:
print 1
exit(0)
global store
store=[-1 for _ in range(n)]
def find_root(x):
if store[x]>=0:
store[x]=find_root(store[x])
return store[x]
else:
return x
def merge(x,y):
root1=fi... | import java.util.* ;
import java.io.* ;
import java.util.regex.* ;
import java.text.* ;
import java.math.* ;
public class Main {
public static void main( String[] args ) {
InputStream isObj ;
OutputStream osObj ;
InputReader irObj ;
PrintWriter pwObj ;
String inputFileName , outputFileName ;
File fObj1 , ... |
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public cla... | #include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
struct Matrix {
int n, m;
long long a[105][105];
Matrix(int x, int y) {
n = x, m = y;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) a[i][j] = 0;
}
}
void init() {
for (int i = 1; i <= min(n, m); i++) a[i][... |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m;
int id[300010], f[300010], g[300010];
double b[300010], an;
inline bool cc1(const int &A, const int &B) { return b[A] < b[B]; }
int getg(int x) { return g[x] == x ? x : g[x] = getg(g[x]); }
int getf(int x) { return f[x] == x ? x : f[x] = getf(f[x]); }
int... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
public class Main223E {
private FastScanner in;
private PrintWriter out;
... |
from heapq import heappush, heappop
h, w = map(int, input().split())
def get_area():
mp = ["#" * (w + 2)]
for _ in range(h):
mp.append("#" + input() + "#")
mp.append("#" * (w + 2))
return mp
areas = [get_area()]
times = {}
n = int(input())
for i in range(n):
times[int(input())] = i + 1
... | #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
struct Loc{
void set(int arg_row,int arg_col){
row = arg_row;
col = arg_col;
}
int row,col;
};... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
private void solve() throws IOException {
int N = nextInt();
long a[] = new long[N];
for (int i = 0; i < N; ... | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 1000 * 100 + 47;
struct node {
long long ss[6 + 1][12];
};
long long a[MAX];
node t[MAX];
vector<long long> ss[6 + 4];
int n;
void calcs() {
for... |
count = 0
def merge(a, left, mid, right):
global count
l = a[left:mid]
r = a[mid:right]
l.append(10**9+1)
r.append(10**9+1)
i = 0
j = 0
for k in range(left, right):
count += 1
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = ... | import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
public class Main {
private static FastScanner sc = new FastScanner();
static int cnt = 0;
public static void main(String[] args) {
int n = sc.nextInt();
int[] A = new int[n];
for(int i=0; i<n; i++) {
A[i] ... |
import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Cf2802D {
private static InputReader in = new InputReader(System.in);
private static OutputWriter out = new OutputWriter(System.out);
private static void solve() throws Exception{
int n = in.readInt... | #include <bits/stdc++.h>
using namespace std;
struct seg {
int long long sum, sum2;
seg(int long long sum = 0, int long long sum2 = 0) : sum(sum), sum2(sum2) {}
};
int long long x, y;
vector<seg> t;
void update(int long long l, int long long r, int long long pos,
int long long v, int long long w) {
if... |
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class D {
static final int MAXV = 500_000;
public static void main(String... args) throws Exception {
FastScan sc = new FastS... | # Your circuit's dead, there's something wrong!
# Can you hear me, Major Tom?...
m, k, n, s = map(int, input().split())
fl = [int(x) for x in input().split()]
seq = [int(x) for x in input().split()]
d = {}
p = {}
for i in seq:
d[i] = d.get(i, 0) + 1
p[i] = d[i]
f = False
collect = s
keys = set(d.keys())
... |
while 1:
s = raw_input()
if s == "#": break
l = len(s)
ps = [(int(c)-1) % 3 for c in s]
dpl = [1e9]*l; dpr = [1e9]*l
dpl[0] = dpr[0] = 0
for i in xrange(1, l):
if ps[i-1] <= ps[i]:
dpl[i] = dpr[i-1]
if ps[i] <= ps[i-1]:
dpr[i] = dpl[i-1]
dpl[i]... | import java.io.*;
import java.util.*;
import java.lang.ArrayIndexOutOfBoundsException;
import java.math.BigInteger;
/**
* @author yoshikyoto
*/
class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while(true){
char[] s... |
#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2e5 + 10;
int n, m, T;
int a[MAXN];
bool cmp(int a, int b) { return a > b; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n, cmp);
for (int i = 1; i <=... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUF... |
from sys import stdin
n, m = [int(i) for i in stdin.readline().split()]
ori = [int(i) for i in stdin.readline().split()]
pre = [-1] * n
ans = list()
for i in range(n-1):
if ori[i] != ori[i+1]:
pre[i+1] = i
else:
pre[i+1] = pre[i]
for i in range(m):
l, r, x = [int(i) for i in stdin.readline().split()]
tem = r -... |
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;
public class P622C{
static long mod=1000000007;
public static void main(String[] args) throws Exception{
InputReader in = new InputReader(System.in);
Print... |
import java.util.Scanner;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner myScanner = new Scanner(System.in);
int n = myScanner.nextInt();
myScanner.nextLine();
for(int i=0;i<n;i++){
String line = m... | n = int(input())
while n!=0:
l = input()
if len(l)<=10:
print(l)
else:
newl = []
newl.append(l[0])
newl.append(len(l[1:-1]))
newl.append(l[-1])
nl = "".join([str(ele) for ele in newl])
print(nl)
n-=1 |
#include <iostream>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
using namespace std;
char buff[512];
int main(){
while(scanf("%s", buff), buff[0] != '#'){
int cnt = 0;
int var[3];
int neg = 1;
bool ans = false;
for(int i = 0; buff[i]; i++){
if(buff[i] == '~'){
neg =... | import java.util.Scanner;
class Main {
private static char[] expr;
private static int ptr;
private static void consume(char c) {
assert expr[ptr] == c : "expected " + c + ", but got " + expr[ptr];
ptr++;
}
private static boolean expression() {
do {
consume('(')... |
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
public class Main{
static IntStream REPS(int v){return IntStream.range(0,v);}
static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
static IntStream INS(int n) {return REPS(n).map(i->getInt());}
static Scanner s=... | #include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N;
cin>>N;
int jump[N];
for(int i=0;i<N;i++){
cin>>jump[i];
}
int jum_dis=0;
for(int i=0;i<N-1;i++){
jum_dis=max(jum_dis,jump[i]);
if(jum_dis<10){cout<<"no\n";return 0;}
jum_dis -= 10;
}
jum_dis=0;
for(int ... |
// これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
static PrintWriter fop = new PrintWriter(System.ou... | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, l, t, r, s, m, n, a, b, c, d, e, f, g, h, u, v;
scanf("%d %d", &c, &d);
scanf("%d %d", &n, &m);
scanf("%d", &k);
a = n * m;
a = a - k;
if (a > 0) {
e = a / n;
h = 100000000;
g = 0;
if (a % n > 0) ++e;
for (i = 0; i... |
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
... | def ans(N): # N:foat
n=int(N)
d=N-n
ans_l=bin(n)[2:]
ans_r=''
for _ in range(4):
ans_r+=str(int(d*2))
d=d*2-int(d*2)
if n>=256 or d!=0:
return 'NA'
else:
return '0'*(8-len(ans_l))+ans_l+'.'+ans_r
while True:
INP=float(input())
if INP<0: break
prin... |
#!/usr/bin/env python3
# http://codeforces.com/contest/633/problem/C
from collections import deque
# import sys
# sys.setrecursionlimit(10001)
n = int(input())
s = input()
m = int(input())
words = []
for i in range(0, m):
words.append(input())
dict_words = {}
for word in words:
dict_words[word.lower()[::-1... | #include <bits/stdc++.h>
using namespace std;
int n, m, cur, ch;
int cntNodes = 1;
int trie[1001000][26];
int DP[1001000];
int isWord[1001000];
string str, auxStr;
vector<string> words;
void insert(string str, int idx) {
cur = 1;
for (int i = 0; i < str.length(); i++) {
ch = (str[i] >= 'a') ? str[i] - 'a' : str... |
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main ( String args[] ) throws Exception {
(new P7()).solve();
}
}
class P7
{
int n, wantedTime;
char a[];
int getTime ( int startCnt )
{
int cnt = -startCnt, lastH = -1;
ArrayList<Integer> first = new ArrayLi... | #include <bits/stdc++.h>
int n, t, len;
char s[500005];
bool check(int x) {
int num = x, End = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'H')
num--, End = i;
else if (s[i] == 'S') {
num++;
if (!num) End = i;
}
}
if (num < 0) return 0;
int last = -1, ans = 0;
num = x;
for (... |
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.*;
public class Main{
Scanner sc=new Scanner(System.in);
int INF=1<<28;
double EPS=1e-12;
int n, m, nb, k;
int[] us, vs, ws;
int s,... | // #include<iostream>
// #include<map>
// #include<algorithm>
// #include<queue>
// #include<vector>
// using namespace std;
// typedef pair<int,int> P;
// typedef pair<int,P> P2;
// int n,m,l,k;
// int u,v,c;
// int s,g,t;
// int b[7];
// int dis[51][1<<7][10],vis[51][1<<7];
// vector<P> G[51];
// const int INF... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayList;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public s... | #!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def main():
t = int(input())
for _ in range(t):... |
import java.io.*;
import java.util.*;
public class E {
BufferedReader br;
StringTokenizer in;
PrintWriter out;
public String nextToken() throws IOException {
while (in == null || !in.hasMoreTokens()) {
in = new StringTokenizer(br.readLine());
}
return in.nextToken()... | #include <bits/stdc++.h>
inline int gd(int x) {
int s = 0;
for (; !(x & 1); x >>= 1) s++;
return s;
}
double s[201][201];
int main() {
int x, k, p_i;
scanf("%d %d %d", &x, &k, &p_i);
double p = (double)p_i / 100, q = 1 - p;
for (register int i = 0; i <= k; i++) s[0][i] = gd(x + i);
for (register int j =... |
import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;
public class CODEFORCES {
private InputStream is;
private PrintWriter out;
void solve() {
int n = ni(), p = ni(), k = ni();
int a1[] = new int[n + 1], a2[] = new int[n + 1];
int a3[] = new int[n + 1];
int tem = n... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
int dp[2][MAXN][55][55];
bool quest[2][MAXN];
int n, p, k;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> p >> k;
int m, val;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> val;
quest[0][val] = ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
int sum = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
sum += x;
}
if (sum + n - 1 == x)
cout << "YES";
else
cout << "NO";
}
| import java.util.Scanner;
public class JpCross {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int x = input.nextInt();
int[] arr = new int[n];
int k = 0;
for(int i = 0; i < n; i++){
arr[i] = i... |
from fractions import Fraction
q, p = list(map(int, input().split()))
is_equal_to = Fraction(q, p)
n = int(input())
a = list(map(int, input().split()))
pos = -1
def continued_fraction(n, a):
if n == 1:
return a[0]
score = a[-1]
for i in range(n - 2, 0, -1):
score = a[i] + Fraction(1, scor... | #include <bits/stdc++.h>
using namespace std;
int n;
long long a, b;
long long v[1000];
bool verif(int pos, long long a, long long b) {
if (pos == n + 1) {
return (b == 0);
} else {
if (b == 0 || a / b < v[pos]) {
return false;
}
return verif(pos + 1, b, a - v[pos] * b);
}
}
int main() {
i... |
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a,b;
cin>>a>>b;
cout<<a/b<<"\n";
}
| N,A=map(int,input().split())
print(float(N/A)) |
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, k = map(int, input().split())
adj = [[] for _ in range(n)]
dp = [[0] * (1 << n) for _ in range(1 << n)]
for u, v in (map(int, input().split()) for _ in range(m)):
u, v = u - 1, v - 1
a... | import java.util.*;
public class E {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt(), m = s.nextInt(), k = s.nextInt();
int[][] a = new int[m][];
int[][] count = new int[1 << n][1 << n];
for (int i = 0; i < m; ++i) {
int u = s.nextInt() - 1, v = s.nextInt(... |
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.HashMap;
/**
* Actual solution is at the top
* @author Erasy... | #include <bits/stdc++.h>
using namespace std;
bool check(long long int mid, long long int a[], long long int b[],
long long int k, long long int n) {
for (int i = 0; i < n; i++) {
long long int req = a[i] * mid;
long long int need = max((long long int)0, req - b[i]);
if (k >= need) {
k -=... |
#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 30000020;
int bufpos;
char buf[MAXSIZE];
void init() {
buf[fread(buf, 1, MAXSIZE, stdin)] = '\0';
bufpos = 0;
}
int readint() {
int val = 0;
for (; !isdigit(buf[bufpos]); bufpos++)
;
for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + b... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.util.Collec... |
#include <bits/stdc++.h>
using namespace std;
const long long mod[5] = {99998363, 99998377, 99998413, 99998417, 1000000007};
const int MAXN = 200005;
long long hashed[MAXN][5], pow2[MAXN][5];
int sum[MAXN][2];
bool cksame(int l1, int l2, int len) {
if (len == 0) return true;
for (int it = 0; it < 5; ++it) {
lon... | import sys
input = sys.stdin.readline
n=int(input())
t=input().strip()
q=int(input())
ZEROS=[0]*n
ZERO_ONE=[]
ONECOUNT=[0]*n
ind=0
count=0
for i in range(n):
ZEROS[i]=ind
if t[i]=="0":
ind+=1
ONECOUNT[i]=count%2
ZERO_ONE.append(count%2)
count=0
else:
count+=1
... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int> > arr(n, vector<int>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> arr[i][j];
vector<pair<int, int> > ans;
vector<... | def solve(Amat, n, m):
actions = []
Bmat = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n - 1):
for j in range(m - 1):
if Amat[i][j] and Amat[i + 1][j] and Amat[i][j + 1] and Amat[i + 1][j + 1]:
Bmat[i][j] = 1
Bmat[i + 1][j] = 1
... |
n =int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
dp = [0] * (n//2+1)
dp2 = [0] * (n//2+1)
fi = 0
se = 0
for i in range(n):
fi +=a[i] * i
fi +=b[-i-1] * (i+n)
dp[0] = fi
for i in range(n):
if i != 0:
se +=a[-i] * (i+n)
se +=b[i] * (i+1)
dp2[0] = se
gou = sum(a)+ sum(b) -... | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
int n;
int g[2][MAXN];
long long suffsum[2][MAXN + 1];
long long wsuffsum[2][MAXN + 1];
long long dp[2][MAXN + 1];
void run() {
scanf("%d", &n);
for (int x = (0); x < (2); ++x)
for... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> n >> m;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long w1 = 0;
long long w3 = 0;
long long w4 = 0;
for (long long aa = 2; aa <= 2 * m - 1; aa++) {
long long s;
if (a[0] % aa <= (aa - 1) / 2)... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOExcept... |
/*
ID: tommatt1
LANG: JAVA
TASK:
*/
import java.util.*;
import java.io.*;
public class cf1313d{
public static void main(String[] args)throws IOException {
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
BufferedReader bf=new BufferedReader(new InputStreamReader(Syste... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 50;
int n, m, k, a[MAXN];
struct Node {
int l, r;
} z[MAXN];
void readInput() {
int t;
scanf("%d%d%d", &m, &t, &k);
vector<int> v;
for (int i = 1; i <= m; i++) {
scanf("%d%d", &z[i].l, &z[i].r);
z[i].r++;
v.push_back(z[i].l);
... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--) {
int n, m;
cin >> n >> m;
vector<int> t(n);
for (int i = 0; i < n; i++) cin >> t[i];
long long sum = 0;
int ans = 0;
for (int i = 0; i < n; ... | a = []
total = 0
def binary_search(n, l):
first = 0
last = len(l)-1
found = False
mid = (first+last)//2
while(first<=last and not found):
mid = (first+last)//2
if l[mid] == n:
found = True
elif n <l[mid]:
last = mid - 1
else:
first ... |
import java.io.*;
import java.util.*;
public class Main {
static InputStream is;
static PrintWriter out;
static String INPUT = "";
static void solve()
{
char[] s = ns().toCharArray();
int n = s.length;
int mod = 998244353;
int als = 1;
for(int i = 0;i < n;i++){
if(s[i] != s[0])als = 0;
}
i... | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 200050
#define mod 998244353
int n, ans, f[maxn][3][3][2], sum;
char a[maxn];
int read()
{
int x = 0, k = 1;
char c; c = getchar();
while(c < '0' || c > '9') { if(c == '-') k = -1; }
while(c >= '0' && c <= '9') x = x * 10 ... |
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int k;
int q;
struct st {
int x1;
int y1;
int x2;
int y2;
int id;
};
vector<st> ev[200002];
vector<int> v[200002];
int seg[200002 * 4];
inline void add(int b, int l, int r, int ll, int x) {
if (l <= ll && ll < r) {
if (l + 1 == r) {
seg[b... | import java.io.FileNotFoundException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.File;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileReader;
import java.util.Arrays;
import java.u... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamW... | from fractions import gcd
def gcdL(L):
g=L[0]
for i in range(1,len(L)):
if g==1:
return(g)
g=gcd(g,L[i])
return g
def play(A,i):
A[i]-=1
g=gcdL(A)
return [x//g for x in A]
def cnt(A):
odd,even=0,0
for a in A:
if a%2:
odd+=1
else:
... |
#include <bits/stdc++.h>
using namespace std;
int cmp(pair<int, int> a, pair<int, int> b) {
return a.first == b.first ? a.second < b.second : a.first < b.first;
}
int main() {
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<pair<int, int>> all(n);
priority_q... | import java.io.*;
import java.util.*;
public class Main {
private static void execute(ContestReader reader, PrintWriter out) {
int t = reader.nextInt();
for (int i = 0; i < t; i++) {
int n = reader.nextInt();
int[] ms = new int[n];
int[] ps = new int[n];
for (int j = 0; j < n; j++) {
... |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class TaskD {
/**
* @param args
*/
public static void main(String[] args) {
TaskD task = new TaskD();
task.read();
}
int m, n, p;
ArrayList<Map<Integer,... | In=lambda:map(int,raw_input().split())
n,m,p=In()
a=In()
c=In()
b={};ans=[];s=[];d=m
for x in a:b[x]=0
for x in c:b[x]=0
for x in c:b[x]+=1
for q in range(p):
for i in range(q,n,p):
s.append([a[i],i+1])
for i in range(min(m,n)):
d+=-1 if b[s[i][0]]>0 else 1
b[s[i][0]]-=1
for i in range(m,n):
if ... |
from collections import deque
R,C,ay,ax,by,bx = map(int,input().split())
MOD = INF = 10**9+7
dists = [[INF]*C for i in range(R)]
dists[ay][ax] = 0
ptns = [[0]*C for i in range(R)]
ptns[ay][ax] = 1
q = deque([(0,ax,ay)])
dxs = [1,0,-1,0]
dys = [0,1,0,-1]
ans_d = None
while q:
d,x,y = q.popleft()
if ans_d is not... | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct Pos { int x, y, c; };
int R, C, ax, ay, bx, by, cost[555][555];
lint card[555][555], MOD = (lint)1e9 + 7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
void update(int x, int y, int nx, int ny, int nc, queue< Pos >& que)... |
from math import *
n,m,k=map(int,raw_input().split())
def c(n,k):
if k>n: return 0
return factorial(n)/(factorial(k)*factorial(n-k))
print (c(n-1,2*k)*c(m-1,2*k))%(10**9+7) | import java.io.*;
import java.util.*;
public class CF129E {
static int M = 1000000007;
static int add(int a, int b) {
return (a + b) % M;
}
static int mul(int a, int b) {
return (int) ((long) a * b % M);
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(ne... |
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.ConnectException;
import java.rmi.dgc.Lease;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.u... | #include<iostream>
#include<cstring>
using namespace std;
char board[105][105];
int dp[105][105];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>board[i]+1;
memset(dp,127,sizeof(dp));
dp[1][1] = (board[1][1]=='#');
for(int i=1;i<=n;i++)... |
#include <bits/stdc++.h>
using namespace std;
int n, a[100], b, mx;
int main() {
cin >> n >> b;
for (int i = 0; i < n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
}
int v = 0;
for (int i = 0; i < n; i++) {
v += mx - a[i];
}
if (v > b) {
cout << -1 << endl;
return 0;
}
b -= v;
for (in... | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int n = s.nextInt();
double k = s.nextDouble();
double[] a = new double[n];
double max = Double.MIN_VALUE;
for(int i = 0; i < n; i++... |
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public stat... | #include <bits/stdc++.h>
using namespace std;
struct Y_X {
int cy, cx;
} counter;
Y_X yazn(string s) {
counter.cy = 0;
counter.cx = 0;
int x = s.size();
for (int i = 0; i < x; i++) {
if (s[i] == 'y')
counter.cy++;
else
counter.cx++;
}
return counter;
}
void Y(int x) {
for (int i = 0;... |
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
new Main().run();
}
private void run() throws IOException {
Scanner scanner = new Scanner(... | # from line_profiler import LineProfiler
from collections import deque
from sys import stdin
def main():
while(True):
W, H = map(int, stdin.readline().split())
if not W: break
tx,ty = map(int, stdin.readline().split())
kx,ky = map(int, stdin.readline().split())
ma = [[False]... |
n = int(input())
if n == 1:
print(1)
else:
adj = [[] for i in range(n+10)]
s = input().split()
for i in range(2,n+1):
pi = int(s[i-2])
adj[i].append(pi)
adj[pi].append(i)
num = 1
curr = [1]
nextcurr = []
disco = [1]
visited = {1:True}
while num < ... | #include <bits/stdc++.h>
using namespace std;
int dp[100009];
vector<int> adj[100009];
int vis[100009];
int totleaf;
int calc(int s) {
vis[s] = 1;
int lf = 0, loc = 0;
for (int i = 0; i < adj[s].size(); i++) {
if (!vis[adj[s][i]]) {
loc = 1;
lf += calc(adj[s][i]);
}
}
if (!loc) lf += 1;
... |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int times = 1;
for (int i = 0; i < times; i++) {
solve();
cout << '\n';
}
return 0;
}
int a, b, c, d, e, f, g, h;
int arr[500000 + 50], arr1[500000 + 50], arr2[500000 + 5... | n = int(input())
l = 0
r = 0
books = {}
z = input().split()
books[z[1]] = 0
for i in range(n-1):
z = input().split()
if z[0]=='L':
l -= 1
books[z[1]] = l
elif z[0]=='R':
r += 1
books[z[1]] = r
else:
print(min(r-books[z[1]], books[z[1]]-l)) |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
@SuppressWarnings("unchecked")
class Main{
static List<Integer> edges[];
static long[] m;
static long[] w;
static long[] v;
static long dfs(int p){
w[p] += m[... | #include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
typedef long long ll;
struct data
{
ll val, w, lim;
} arr[55];
ll sz[55], sum[55], dp[200005];
std::vector<int> son[55];
void dfs(int u)
{
sz[u] = 1;
for (int v : son[u])
{
dfs(v);
sz[u] += sz[v];
sum[u] += sum[v];
}
}
int ma... |
#include <bits/stdc++.h>
using namespace std;
long long rdtsc() {
long long tmp;
asm("rdtsc" : "=A"(tmp));
return tmp;
}
inline int myrand() { return abs((rand() << 15) ^ rand()); }
inline int rnd(int x) { return myrand() % x; }
const int INF = (int)1e9 + 1;
const long double EPS = 1e-9;
int gcd(int a, int b) {
... | import static java.lang.Math.PI;
import static java.lang.Math.abs;
import static java.lang.Math.acos;
import static java.lang.Math.cos;
import static java.lang.Math.min;
import static java.lang.Math.sin;
import static java.lang.Math.sqrt;
import static java.lang.System.in;
import static java.lang.System.out;
import j... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.