anchor stringlengths 10 14.3k | positive stringlengths 10 14.9k |
|---|---|
import sys
a=[float(i) for i in sys.stdin]
print(max(a)-min(a))
| import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//?????°?¨????
Scanner sc = new Scanner(System.in);
double max = Integer.MIN_VALUE;
double min = Integer.MAX_VALUE;
while(sc.hasNext()) {
double num = sc.nextDouble();
max = Math.max(max, num);
min = Math.min... |
import java.util.*;
public class CodeForces835B{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int k = input.nextInt();
String s = input.next();
long sum = 0;
int[] a = new int[10];
for(int i = 0;i<s.length();i++){
int c = Integer.parseInt(s.charAt(i)+"");
sum+= c;... | k = int(input())
n = input()
sum = 0
pt = []
for i in range(len(n)):
a = 9-int(n[i])
pt.append(a)
sum += int(n[i])
diff = k - sum
pt.sort()
pt.reverse()
#print(pt)
if diff <= 0:
print("0")
else:
for i in range(len(pt)):
diff -= pt[i]
if diff<=0:
... |
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
class Reader {
BufferedReader in;
Reader() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
}
Reader(String name) throws IOException {
... | #include<bits/stdc++.h>
#define fint register int
#define h 5001
#define p 347589
#define mods 998244353
#define int long long
using namespace std;
int f[p],s[p],l[p],r[p];
signed main()
{
int n,k;
cin>>n>>k;
for(fint i=1;i<=k;i++)
cin>>l[i]>>r[i];
f[1]=1,s[1]=1;
for(fint i=2;i<=n;i++)
{
for(fint j=1;j<=k;j++)... |
import java.io.*;
import java.util.*;
public class F {
void run() {
int n = in.nextInt();
int k = in.nextInt();
long[] p = new long[n];
for (int i = 0; i < n; i++) {
p[i] = in.nextLong();
}
List<Long> seg = new ArrayList<>();
{
int i = 0;
while (i + 1 < n && p[i] >= p[i + 1]) {
i++;
}
... | #include <bits/stdc++.h>
using namespace std;
const int NMAX = 4000010;
int n, k, seqn, seqleftn, iteration;
int seqprev[NMAX], seqnext[NMAX], removed[NMAX];
long long p[NMAX], seq[NMAX];
pair<long long, int> seqleft[NMAX], pivot;
queue<int> q;
bool used[NMAX];
void debugSeq() {
for (int i = seqnext[0]; i > 0; i = se... |
#include <iostream>
int f(const int &a, const int &m) {
auto res = a;
int count = 1;
while (res != 1) {
res = (res * a) % m;
++count;
}
return count;
}
long long int gcd(const long long int &a, const int &b) {
if (b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
long long int lcd(const long long... | def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
def rooptimes(ai, mi):
x = ai % mi
i = 1
while x != 1:
x = ai * x % mi
i += 1
return(i)
while True:
a = list(map(int, input().split()))
if a.count(0) == 6:
break
ix = rooptimes(a[0], a[1])
iy = roop... |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,... | N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
D=[[0]*(X+1) for i in range(N//2+2)]
D[1][L[0]]=1
for l in L[1:]:
ND=[[0]*(X+1) for i in range(N//2+1)]
for c in range(1,N//2+1):
for s in range(X+1):
if D[c][s]==0:
continue
... |
#include <bits/stdc++.h>
const int bufSize = 1e6;
using namespace std;
inline char nc() {
return getchar();
static char buf[bufSize], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2)
? EOF
: *p1++;
}
inline void read(char *s) {
static... | // https://codeforces.com/blog/entry/80562
import java.io.*;
import java.util.*;
public class CF1384E extends PrintWriter {
CF1384E() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1384E o = new CF1384E(); o.main(); o.flush();
}
static final int A = 20;
int... |
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public int getP(int pos){
if(pos==0) return 2;
if(pos==1) return 3;
if(pos==2) return 5;
if(pos==3) return 7;
if(pos==4) return 11;
if(pos==5) retur... | #include <bits/stdc++.h>
using namespace std;
const int N = 1100;
const int inf = 0x3f3f3f3f;
const long long infll = 0x3f3f3f3f3f3f3f3fll;
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
long long dp[N][N][11];
long long fpow(long long a, long long b) {
;
long long c = 1;
for (; b; b >>= 1, a = a * a)
i... |
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
char c[]=sc.next().toCharArray();
int ans=0;
for(int i=0;i<c.length;i++){
ans+=(c[i]-'0');
}System.out.println(ans%9==0?"Yes":"No");
}
} | #include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int sum=0;
char c;
while((c=getchar())&&'0'<=c&&c<='9')
sum+=(c-'0');
puts(sum%9?"No":"Yes");
return 0;
}
|
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): ret... | import java.util.*;
import java.io.*;
public class Div680 {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////... |
n,m = map(int,input().split())
lis = list(map(int,input().split()))
li = [0 for i in range(n)]
for i in range(n):li[lis[i]-1] += 1
li.sort(reverse = True)
ans = 0
for k in range(m):
ans += li[k]
print(n-ans) | #include <bits/stdc++.h>
using namespace std;
int cnt[200001],n,k;
int main() {
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++) {
int v;
scanf("%d",&v);
cnt[v]++;
}
vector<int> arr;
for(int i=1;i<=n;i++) arr.push_back(cnt[i]);
sort(arr.begin(),arr.end());
int ans=0;
f... |
import java.util.Scanner;
public class E {
static long xg, yg;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int s = sc.nextInt();
long c3 = 0, c4 = 0, c5 = 0;
for (int i = 1; i <= n; i++) {
int t = sc.n... | #include <bits/stdc++.h>
using namespace std;
int f(int c3, int k3, int c4, int k4, int c5, int k5) {
return abs(c3 * k3 - c4 * k4) + abs(c4 * k4 - c5 * k5);
}
int main() {
int n, s;
int c3 = 0, c4 = 0, c5 = 0;
int k3 = -1, k4 = -1, k5 = -1;
int bk3 = -1, bk4 = -1, bk5 = -1;
int minval = 100000000;
cin >>... |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx,tune=native")
using namespace std;
struct state {
int tp;
};
state states[10];
void ander(int ind, int vl) {
if (vl == 1)
return;
else
states[ind].tp = 1;
}
void orer(int ind, int vl) {
if (vl == 0)
ret... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Pradyumn
*/
public class M... |
for _ in range(int(input())):
n, m = map(int, input().split())
a = [input() for x in range(n)]
ans = 0
for j in range(m):
w = 0
for i in range(n):
w = min((w, j, m - j - 1))
for k in range(w + 1):
if a[i][j + k] == '.' or a[i][j - k] == '.':
... | #include<iostream>
#include<cstring>
using namespace std;
string sn;
int vis[550][550];
char list[550][550];
int main() {
int n,m;
int t;
cin>>t;
while(t--) {
int n,m;
cin>>n>>m;
for(int i=0; i<n; i++) {
scanf("%s",list[i]);
}
int ans = 0 ;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if... |
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Tr... | '''input
4
mail
ai
lru
cf
'''
import sys
pow2 = pow # for modular expo pow2(base, n, mod)
from math import *
from time import time
from collections import defaultdict
from bisect import bisect_right, bisect_left
from string import ascii_lowercase as lcs
from string import ascii_uppercase as ucs
from fract... |
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int getChar() {
static char buf[1 << 16];
static int pos = 0, size = 0;
if (pos == size) {
pos = 0;
... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Random;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/... |
print(function(n, a) {
a.sort(function(a, b) {
return b - a;
});
var sum = 0;
var b =a.map(function(v) {
return sum += v;
});
var ans = 0;
for (var i = 1; i <= n; i *= 4) {
ans += b[i - 1];
}
return ans;
}(+readline(), readline().split(' ').map(Number)));
| import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self... |
import java.util.*;
import java.io.*;
public class aaaaaaaaaaaaaaaa {
public void run() throws Exception {
Scanner file = new Scanner(System.in);
int times= file.nextInt();
ArrayList<Integer> a = new ArrayList();
int max = Integer.MIN_VALUE;
for (int i = 0; i < times; i++) {
int tm=file.nextInt();
max... | n=int(input())
arr=[int(i) for i in input().split()]
x=max(arr)
ans=0
A=[]
j=arr.index(x)
for i in range(j,n):
if (arr[i]==x):
ans+=1
else:
A.append(ans)
ans=0
A.append(ans)
print(max(A)) |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
i... | #include <bits/stdc++.h>
using namespace std;
long long ksm(long long a, long long b) {
if (!b) return 1;
long long ns = ksm(a, b >> 1);
ns = ns * ns % 1000000009;
if (b & 1) ns = ns * a % 1000000009;
return ns;
}
long long jc[155], bjc[155];
void ch(vector<int> &r, int tp) {
for (int i = 0; i < r.size(); i... |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class KForPriceOfOne {
static final in... | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, p, k, a[N];
bool check(int x) {
int cost = 0;
while (x > 0) {
cost += a[x];
if (cost > p) return false;
x -= k;
}
return true;
}
int main() {
int test;
cin >> test;
while (test--) {
cin >> n >> p >> k;
for (int... |
#include <bits/stdc++.h>
using namespace std;
long long n, m, s;
long long hoge(long long a, long long b) {
long long mx = 0, i, j;
for (i = 1; i <= sqrt(a); i++) {
if (a % i) continue;
if (s - i + 2 > 0) {
long long tmp = (a / i) * int(b / (s - i + 2));
mx = max(mx, tmp);
}
if (s - a / ... | import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list... |
import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Bunyod Xalilov
*/
public class Main {
public static void main(String[] args) {
InputStre... | #include <bits/stdc++.h>
using namespace std;
int a[1001];
unsigned long long int sum = 0;
inline int read_int() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') {
w = -1;
}
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
... |
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution ... | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
int l[6][6], r[6][6], a[6][6];
vector<pair<int, int> > v;
int t = 1;
int table[30][15000][16];
bool was[30][15000][16];
int bad = -100000000;
inline void pars... |
while 1:
n=int(raw_input())
if n==0: break
x=sorted(map(int,[raw_input() for _ in [0]*n]))
s=a=0
for e in x[:-1]: a+=e; s+=a
print s | #include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n;
while(cin>>n,n){
int a[10000];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
long long int ans = 0;
for(int i=0;i<n-1;i++){
ans += a[i]*(n-i-1);
}
... |
#include <bits/stdc++.h>
using namespace std;
inline int II() {
int n;
scanf("%d", &n);
return n;
}
struct ii {
long long v, k;
};
ii ft[300002];
int N;
void update(int k, long long deltav, long long deltak) {
for (; k; k -= (k & (-k))) {
ft[k].v = (ft[k].v + deltav + 1000000007LL) % 1000000007LL;
ft[... | import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitS... |
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
int x[] = {
1, 8, 6, 3,
2, 0, 7, 4,
3, 1, 8, 5,
4, 2, 0, 6,
5, 3, 1, 7,
6, 4, 2, 8,
7, 5, 3, 0,
8, 6, 4, 1,
0, 7, 5, 2
};
int a[362889][9], p[11], cnt, fact[11]; bool used[11];
void build(int pos) {
if (pos == 9) {
for (int i = 0; i... | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.InputMismatchExc... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class d {
static class BitTrie{
BitTrie zero = null, one = null;
int height;
BitTrie(int h){
height = h;
}
void insert(int thisInt, int bit) {
if(height == 0) {
}
else {
int direction = (... | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
const int INF = 1e9;
const lint INFL = 1e18;
void solve(int cur, int b, int& res, vector<int>& list) {
if (b == -1) {
res = min(res, cur);
return;
}
int bit = 1 << b;
vector<int> L, R;
for (int i : list) {
if (bit & i)
... |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100010];
vector<int> g[100010];
char used_centroid[100010];
int sz[100010];
int cnt = 0;
long long an = 0;
int c1[100010];
int c[20][2];
void dfs(int v, int par, int sum, int centroid) {
an += sum;
if (v != centroid) {
c1[v] = sum;
int t = sum ^ ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Rene
*/
public class Main {
public sta... |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
template <class T>
T gcd(T a, T b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int x[100000];
int value;
void bsearch(int left, int right) {
if (right - left < 2) {
if (x[right] <= value)
printf("%d\n"... |
import java.util.Scanner;
public class Codeforces706a {
static double minTime = Double.MAX_VALUE;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int myX = scanner.nextInt();
int myY = scanner.nextInt();
int cars = scanner.nextInt();
... |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3
0.0 0.0
2.0 0.0
1.0 1.0
output:
1.41421356237
"""
import math
import sys
from operator import attrgetter
class ClosestPair(object):
def __init__(self, ):
"""
Init closest pairs points set.
"""
_input = sys.stdin.readline... | import java.util.*;
import java.text.DecimalFormat;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.StringTokenizer;
class Main {
static final double EPS = 1e-12;
// for two points x(x0,x1) and y(y0,y1), wh... |
#include <bits/stdc++.h>
using namespace std;
namespace patch {
template <typename T>
std::string to_string(const T& n) {
std::ostringstream stm;
stm << n;
return stm.str();
}
} // namespace patch
int m, lim, len;
long long dp[1 << 18][101];
string s;
long long fac[19];
int freq[10];
long long solve(int mask, in... | d = '0123456789ABCDEFGH'
prev = {d[i]: d[i - 1] for i in range(1, 18)}
next = {d[i]: d[i + 1] for i in range(17)}
n, m = raw_input().split()
p, m = ['0'] * 10, int(m)
k, l = 1, len(n)
for x in map(int, n): p[x] = next[p[x]]
a = ''.join(p)
u, v = {a: [0] * m}, {}
u[a][0] = 1
for r in range(1, l + 1):
if r == l an... |
#include <bits/stdc++.h>
using namespace std;
long long int pow_mod(long long int a, long long int b) {
long long int res = 1;
while (b) {
if (b & 1) res = (res * a);
a = (a * a);
b >>= 1;
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
long long int n;
cin >> n;
long long int num... | import java.util.Scanner;
public class Main {
public static boolean check(long temp) {
long temp1;
while (temp > 0) {
temp1 = temp % 10;
temp /= 10;
if (temp1 > 1)
return false;
}
return true;
}
public static void main(Strin... |
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
d = int(input())
disable = [False] * n
base = 5001
ds = [int(input())-1 for _ in range(d)]
for ele in ds:
disable[ele] = True
# Create Graph
childs = [[] for i in range(... | import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
void solve() {
n=ni(); m=ni();
int p[]=new int[n+1];
for(int i=1;i<=n;i++) p[i]=ni();
int c[]=new int[n+1];
for(int i=1;i<=n;i++) c[i]=ni();
int d=ni();
int k[]=... |
from __future__ import division, print_function
def main():
class DSU:
def __init__ (self,n):
self.parent=list(range(n))
self.size=[1]*n
self.count_sets=n
def find(self,u):
to_update=[]
while u!=self.parent[u]:
to_update.app... | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class cf1184e1 {
static int par[];
static int find(int i) {
return par[i] == i ? i : (par[i] = find(par[i]));
}
static boolean union(int i, int j) {
int a = find(i), b = fi... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
bool booly = false;
int index = -1;
vector<pair<int, int>> e;
for (int i = 0; i < k; i++) {
int u, v;
cin >> u >> v;
if (u == n && v == m) {
booly = true;
index = i;
}
e.push_back({u, ... | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class d
{
/*
0 - col before lit
... |
import java.util.*;
import java.io.*;
import java.io.PrintWriter;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
// Scanner sc = new Scanner(System.in);
// FastScanner sc = new FastScanner(System.in);
FastScanner sc = new FastScanner... | /* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < (n); i++)
#define cont(i, n) for(int i = 1; i <= (n); i++)
#define circ(i, a, b) for(int i = ... |
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static class FastReader {
BufferedReader br;
StringTokenizer root;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (root == null || !root... | #include <bits/stdc++.h>
using namespace std;
const int N = 2e2;
double memo[N + 5][N + 5][N + 5];
bool vis[N + 5][N + 5][N + 5];
double p[N + 5];
int bobot[N + 5];
int n, l, k;
double dp(int idx, int need, int space) {
if (space < 0) return 0.0;
if (need < 0) return dp(idx, 0, space);
if (space > n) return dp(id... |
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#endif
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef std::vector<vector<int> > vv... | import math
class RMQ:
def __init__(self, arr):
self.n = len(arr)
self.logn = int(math.log2(self.n)) + 1
self.arr = [0] + arr
self.Log = [0] * (self.n + 1)
self.Log[2] = 1
for i in range(3, self.n + 1):
self.Log[i] = self.Log[i // 2] + 1
self.min =... |
#include<bits/stdc++.h>
#define f fafa
#define s second
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
int n,m, k, a, b, minim;
int adj[3005][3005];
int deg[3005], ndeg[3005];
vector<int> v[3005];
bool flag[3005];
bool relax[3005];
int constructt(bool first) {
int res = 0, id2 = -1;
bool fafa = ... | from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
sys.setrecursionlimit(10**5)
def solve():
N, M, K = map(int, readline().split())
G = [[] for i in range(N)]
for i in range(M):
a, b = map(int, readline().split())
G[a-1].append(b-1)
G[b-1]... |
import java.io.*;
import java.util.*;
import java.util.function.Function;
@SuppressWarnings("ALL")
public class Main {
static int M, N;
static int[][][] K;
public static void main(String[] args) {
FastScanner sc = new FastScanner(System.in);
M = sc.nextInt();
N = sc.nextInt();
... | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
... | #include <bits/stdc++.h>
using namespace std;
int n, m, k;
int dp[5005][26][26], cnt[26];
double t[26];
int main() {
string s;
cin >> s;
n = s.size();
for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;
for (int i = 0; i < 26; i++) t[i] = (double)cnt[i] / (double)n;
double ans = 0;
for (int i = 0; i < n; i++) ... |
nums = map(int, raw_input('').split(' '))
n = nums[0]
if n <= 3:
print "NO"
elif n == 4:
print "YES"
print '4 * 3 = 12'
print '12 * 2 = 24'
print '24 * 1 = 24'
elif n == 5:
print 'YES'
print '1 + 2 = 3'
print '4 * 3 = 12'
print '5 - 3 = 2'
print '12 * 2 = 24'
else:
print 'YES... | #include <bits/stdc++.h>
using namespace std;
void output() {
cout << "1 * 2 = 2" << endl;
cout << "2 * 3 = 6" << endl;
cout << "6 * 4 = 24" << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
if (n < 4) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
if (... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
int p = 0;
int t = 0;
while (p < n) {
vector<pair<int, int> > x;
while (x.size() < m && p < n) {
int T, X;
scanf("%d%d", &T, &X);
x.push_back(make_pair(X, p));
t = max(t, T);
p++;
... | import java.io.*;
import java.security.SecureRandom;
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
class Student implements Comparable<Student> {
int index;
long x;
public Student(int index, long x) {
thi... |
import sys
def sieve (n):
ms_sieve = [0,0,0,0,0,0]
ms_sieve += [1 for i in range(n-5)]
ms_prime = []
d = 6
while d <= n:
if ms_sieve[d] == 0:
d += 1
continue
if d % 7 != 1 and d % 7 != 6:
ms_sieve[d] = 0
d += 1
continue
ms_prime.append(d)
prod = 2
while d * prod <= n:
ms_sieve[d*prod] =... | import java.util.Arrays;
import java.util.Scanner;
public class Main
{
public static void main(String arg[])
{
Scanner in=new Scanner(System.in);
for(;;)
{
int n=in.nextInt();
if(n==1)
return;
boolean a[]=new boolean[300001];
Arrays.fill(a, true);
for(int i=2;i*i<=300000;i++)
{
if(!a[... |
#include <bits/stdc++.h>
int num[4][4];
int main() {
int i, j, sum;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
num[i][j] = (getchar() == '.' ? 0 : 1);
}
getchar();
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
sum = 0;
sum = num[i][j] + num[i][j + 1] + num[i + ... | import sys
def check(raw, col, grid):
if (grid[raw][col] == "." and
grid[raw+1][col] == "." and
grid[raw][col+1] == "." and
grid[raw+1][col+1]== "."):
return True
elif (grid[raw][col] == "#" and
grid[raw+1][col] == "#" and
grid[raw][col+1] == "#" and
grid... |
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static int[][] move_dir ... | #include<cstdio>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int h,w;
char B[20][20];
// ツタツイツδ?セツーツδ仰づ個湘ョツ陛ア
int n;
int id[8],val[8],s[8],g[8];
int val_sum[1<<8];
int dp[101][20][20][1<<8];
int dfs(int t,int y,int x,int S){
int &res... |
a,b,c = map(int, input().split())
fiblist = []
fiblist.append(a)
fiblist.append(b)
while (len(fiblist) - 1) < c:
for i in range(2, 22):
x = fiblist[i - 1] + fiblist[i - 2]
fiblist.append(x)
else:
print(fiblist[c]) | #include <bits/stdc++.h>
using namespace std;
bool flag;
int a[71720], n, i, sumend, dp[811][811], m, j, k, x, y, z, b, c;
long long int sum;
bool cmp(int a, int b) { return a > b; }
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
int maxx(short int a, short int b) {
if (a > b) return a;
retur... |
#include <bits/stdc++.h>
using namespace std;
const int bignumlen = 2200;
const int Blen = 8;
const long long base = 100000000;
struct bignum {
int len;
long long data[bignumlen];
long long &operator[](int x) { return (data[x]); }
const long long &operator[](int x) const { return (data[x]); }
bignum() {
m... | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.math.*;
public class Solution
{
public static class Frac
{
BigInteger numer, denom;
Frac () { numer = BigInteger.ZERO; denom = BigInteger.ONE; }
Frac (BigInteger num, BigInteger den) { numer = num; denom = d... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is... | n = int(raw_input())
input = [(map(int, raw_input().split(" ")) + [str(i + 1)]) for i in xrange(n)]
P = [0 for _ in xrange(2001)]
S = [[] for _ in xrange(2001)]
input.sort(key=lambda x: x[1])
for t, d, p, i in input:
for x in range(t, d)[::-1]:
if P[x] < P[x - t] + p:
P[x] = P[x - t] + p
... |
from operator import itemgetter
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
A = []
B = []
s = []
max = 0
sum = 0
c = k - len(set(a))
if c == 0:
print(0)
else:
for i in range(n):
A.append((a[i],b[i]))
B = sorted(A, key=itemgette... | #include <bits/stdc++.h>
using namespace std;
int a[100010];
long long b[100010];
vector<pair<long long, int> > v[100010];
int now;
int n, k;
long long res;
vector<long long> ans;
bool vs[100010];
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for... |
s, v1, v2, p1, p2 = map(int, input().split())
t1 = 2 * p1 + s * v1
t2 = 2 * p2 + s * v2
if t1 < t2:
print('First')
elif t2 < t1:
print('Second')
else:
print('Friendship')
| #include <bits/stdc++.h>
using namespace std;
int main() {
int s, v1, v2, t1, t2;
cin >> s >> v1 >> v2 >> t1 >> t2;
if ((s * v1 + 2 * t1) < (s * v2 + 2 * t2)) {
cout << "First";
} else if ((s * v1 + 2 * t1) > (s * v2 + 2 * t2)) {
cout << "Second";
} else {
cout << "Friendship";
}
return 0;
}
|
import sys,os
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
n = int(input())
... | #include <bits/stdc++.h>
using namespace std;
class dsu {
vector<int> p;
public:
dsu(int n) {
p.resize(n);
iota(p.begin(), p.end(), 0);
}
int get(int v) { return (v == p[v] ? v : p[v] = get(p[v])); }
void unite(int u, int v) { p[get(u)] = get(v); }
};
int main() {
ios::sync_with_stdio(0);
cin.ti... |
/*
* Date Created : 24/11/2020
* Have A Good Day !
*/
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.InputMismatchException;
import java.io.IOException;
import java.util.Tre... | import sys
input = sys.stdin.readline
def Unique(arr):
freq_dic={}
index_dic={}
for i, val in enumerate(arr):
freq_dic[val]=freq_dic.get(val,0)+1
index_dic[val]=i
ans=sys.maxsize
for i in index_dic:
if freq_dic[i]==1:
ans=min(ans, i)
index=in... |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct var_t {
int id;
string name;
string op;
string values[2];
int values_i[2];
};
var_t vars[6000];
map<string, int> var_id;
int count_var_cache[6000];
bool count_var(var_t& var_d, int b_i, int b_v) {
;
auto key = var_d.id;
if (count_var_cache[k... | n, m = map(int, input().split())
vars = {}
def mxor(a, b):
if a == b:
return '0'
elif (a == '0' and b == '1') or (a == '1' and b =='0'):
return '1'
elif (a == '0' and b == 'x') or (a == 'x' and b == '0'):
return 'x'
elif (a == '0' and b == '!') or (a == '!' and b == '0'):
... |
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main(){
int N;
cin >> N;
int p[N][3];
int i, j;
for(i = 0; i < N; i++){
for(j = 0; j < 3; j++){
cin >> p[i][j];
}
}
set< set<int> > Q;
for(int k = 0; k < N; k++){
set<int> R;
for(int l = 0; l < 3; l++)... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;import java.util.Collections;
public class Main {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(... |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = "";
for(int i = 1; i <= n; i++){
if(i % 3 == 0){
s += " " + i;
}else{
int k = i;
while(k != 0){
if(k % 10 == 3){
s += " " +... | print(*['']+[i for i in range(3,int(input())+1)if i%3==0 or '3' in str(i)]) |
from math import ceil
def isok(x):
res=0
for i in range(N):
H=h[i]-B*x
if H<=0:
continue
res+=ceil(H/(A-B))
return True if res<=x else False
N,A,B=map(int,input().split())
h=[int(input()) for i in range(N)]
ng,ok=-1,10**10
while(ok-ng>1):
mid=(ok+ng)//2
if isok(... | // practice with Dukkha
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 100000;
int aa[N];
int main() {
int n, a, b; cin >> n >> a >> b;
int c = a - b;
for (int i = 0; i < n; i++)
cin >> aa[i];
int lower = 0, upper = 1000000000;
while (upper - lower > 1) {
int k = (lower + upper... |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, Mod = 1e9 + 7, MAXN = 3e5 + 10, LG = 20, M = 1e9,
P = 727, Sq = 710;
const long long inf = 3e18 + 10;
vector<pair<long long, int> > v[Sq + 5];
long long a[N], n, q, lazy[Sq + 5];
vector<int> cur;
int main() {
ios_base::sync_with_stdio(0);
... | import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
public class Main {
private long[][] blocks;
private ArrayList<HashSet<Long>> checkList;
private long[] add;
private int N, SIZE_OF_BLOCK;
public void solve() {
N = nextInt();
SIZE_OF_BLOCK = (int) Math.sqrt(N);// 1ブロックのサイズ
i... |
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define mod 1000000007
#define maxn 100005
char s[maxn];
int num[maxn];
int all[maxn];
int main()
{
scanf("%s",s);
int len=strlen(s);
for(int i=0;i<len;i++)
{
... | 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-9;
String s;
void run() {
s = sc.n... |
#include <iostream>
using namespace std;
int n;
int data[8][8];
bool flag;
struct A{
bool visited[8][8];
};
void rec(A);
void rec2(int, int, int, int, A);
void print(A a) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(a.visited[i][j]) cout << '#';
else cout << ' ';
}
cout ... | while True:
n = int(input())
if n == 0:break
mp = [list(map(int, input().split())) for _ in range(n)]
used = [[False] * n for _ in range(n)]
inits = []
for y in range(n):
for x in range(n):
if mp[y][x] < 0:
inits.append((x, y, mp[y][x]))
used[y][x] = True
vec = ((0, 1), (-1... |
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(ro... | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class CFE {
public static void main(String[] args) throws Throwable {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new... |
import math
def gcdsum(x):
y = [int(d) for d in str(x)]
a = 0
for i in range(len(y)):
a += y[i]
return math.gcd(x, a)
t = int(input())
for z in range(t):
x = int(input())
while gcdsum(x) <= 1:
x += 1
print(x) | #include<bits/stdc++.h>
using namespace std;
int sum(long long int n)
{
int s =0 ;
while(n)
{
s += (n%10);
n /= 10;
}
return s;
}
long long int gcd(long long int a,long long int b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NUL... |
s = input()
print("Good" if s[0] != s[1] and s[1] != s[2] and s[2] != s[3] else "Bad") | #include<bits/stdc++.h>
using namespace std;
int main(){
string S;cin>>S;
if(S.at(0)==S.at(1) or S.at(1)==S.at(2) or S.at(2)==S.at(3))cout<<"Bad"<<endl;
else cout<<"Good"<<endl;
} |
//package croc2013.r2;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
public class E {
InputStream is;
PrintWriter out;
String INPUT = "";
int L... | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int c[maxn];
long long ans = 0;
int n, L, W;
int fa, w;
int tot, mn, root;
bool vis[maxn];
vector<pair<int, int> > vec;
int lowbit(int x) { return x & (-x); }
void add(int x, int v) {
while (x <= L + 2) {
c[x] += ... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.Stack;
import java.util.StringTokenizer;
public class E {
private void... | #include <bits/stdc++.h>
using namespace std;
double arr[45];
int num[2000005];
inline double inter(double l, double r, double x, double y) {
return max(min(r, y) - max(l, x), 0.0);
}
int main() {
for (int i = 0; i < 20; i++) num[1 << i] = i;
int nf, ne, ns, df, de;
double rf, re, rs;
scanf("%d%d%d%lf%lf%lf%d... |
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
* Actual so... | #include <bits/stdc++.h>
using namespace std;
struct atype {
int ty, v;
char ch;
};
atype op[100010];
int depth2[100010], lg2[100010], depth1[100010];
long long hash2[100010][20], p[100010][20];
long long ex[100010];
char upedge[100010];
int cmp(int x, int y) {
if (x == y) return 0;
for (int k = (19); k >= (0);... |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long sum = 1, n;
int main() {
cin >> n;
for (int i = 1; i <= (int)(n - 1); i++) {
sum = (sum * 3) % 1000003;
}
co... | n=int(input())
if (n<1):
print (1)
else:
print (3**(n-1)%1000003) |
from collections import defaultdict, Counter
def go():
n,m = [int(i) for i in raw_input().split(" ")]
a = [int(i) for i in raw_input().split(" ")]
dd = defaultdict(list)
c = Counter(a)
o=0
e=0
s = set(c.keys())
next_odd = 1
next_even = 2
x=[]
for k in c:
if k%2:
... | #include <bits/stdc++.h>
using std::cerr;
using std::make_tuple;
using std::pair;
using std::vector;
int order[200010];
int print[200010];
int main() {
int n, m;
scanf("%d%d", &n, &m);
std::map<int, int> map;
std::set<int> set;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int a;
scanf("%d", ... |
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math
# import collections
# import string
# import re
# from random import randint
# ===================================
for _ in range(int(input())):
n = int(input())
q = [list(input()) for _... | #include <bits/stdc++.h>
using namespace std;
namespace {
template <typename T>
void __f(const char*, T&&);
template <typename T1, typename... T2>
void __f(const char*, T1&&, T2&&...);
void rd_nums(long long, long long max_size = 10);
void rd_str(long long, string allowed = "abcdefghijklmnopqrstuvwxyz");
} // namespac... |
rows, columns = [int(x) for x in input().split()]
table = []
count = 0
for i in range(rows):
table.append([int(x) for x in input().split()])
for test in table[0]:
if test == 1:
count += 1
for test in table[-1]:
if test == 1:
count += 1
for i in range(rows):
if table[i][0] == 1:
c... | import java.util.Scanner;
public class Table {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn = new Scanner(System.in);
int n, m, a;
n = scn.nextInt();
m = scn.nextInt();
boolean isTwo = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a... |
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
const int inf = 0x3f3f3f3f;
int n, a[N], b[N], m, sum[N], c[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
for (int i = 1; i <= n; ++i) {
sum[i] = sum[i ... | import java.io.IOException;
import java.io.InputStreamReader;
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
* @author she... |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long int n, k;
cin >> n >> k;
long long int arr[n];
for (long long int i = 0; i < n; i++) cin >> arr[i];
double mx = 0;
for (long long int i = 0; i < n; i++) {
long long int sum =... | import java.util.Scanner;
public class IntenseHeat_1003C {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n, k;
n = scan.nextInt()+1; // days
k = scan.nextInt(); // mininum of days in a segment
int[] a = new int[n];
long[] pre = new long[n];
double max = 0;
... |
import java.util.*;
class Main{
public static void main(String args[]){
int table[][]=new int[100][100];
int dp[][]=new int[100][100];
Scanner s=new Scanner(System.in);
int count=0;
for(int i=0;i<100;i++)
for(int j=0;j<100;j++)
table[i][j]=dp[i][j]=0;
while(s.hasNext()){
String str=s.next();
... | #include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
vector<int>x;
int main(){
string s;
while(getline(std::cin,s)){
int i;
for(i=0;i<s.size();i++)if (s[i]==',')s[i]=' ';
stringstream ss(s);
vector<int>A,B;
while(ss>>i)A.push_back(i);
if(x.size()<A.size()){
x.... |
//package codeforces.globalround7;
import java.util.*;
public class E {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] p = new int[n];
int[] pRev = new int[n];
for (int i = 0; i < n; i++) {
p[i] = in.nextInt() - 1;
pRev[p[i]] = i;
}
int a... | import sys
input = sys.stdin.readline
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
LAZY=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
def indexes(L,R... |
n = int(input())
l = []
left = dict()
right = dict()
top = dict()
bottom = dict()
for i in range(n):
l.append([int(x) for x in input().split()])
if l[-1][1] not in left.keys():
left[l[-1][1]] = l[-1][0]
right[l[-1][1]] = l[-1][0]
if l[-1][0] not in bottom.keys():
bottom[l[-1][0]] = l[-1][1]
top[l[-1][0]] = l... | import java.util.*;
public class A165 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan= new Scanner(System.in);
int n= scan.nextInt();
int[] ar= new int[n];
int[] br= new int[n];
for(int i=0; i<n; i... |
n = int(input())
x, h = [], []
for i in range(n):
xi, hi = map(int, input().split())
x += [xi]
h += [hi]
lx = x[0]
cnt = min(n, 2)
for i in range(1, n - 1):
if x[i] - lx > h[i]:
cnt += 1
lx = x[i]
elif x[i + 1] - x[i] > h[i]:
cnt += 1
lx = x[i] + h[i]
else:
... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int x[n], h[n];
for (int i = 0; i < n; i++) cin >> x[i] >> h[i];
vector<pair<unsigned long long int, unsigned long long int>> range(n);
range[0].first = INT_MAX;... |
import java.io.*;
import java.util.*;
public class CODEFORCES
{
@SuppressWarnings("rawtypes")
static InputReader in;
static PrintWriter out;
static long mod = (long) 1e9 + 7;
static long pow(long a, long b)
{
long ans = 1;
while (b > 0)
{
if ((b & 1) == 1)
ans = (ans * a) % mod;
a = (a * a) % m... | #include <bits/stdc++.h>
using namespace std;
inline void _RD(int &x) { scanf("%d", &x); }
inline void _RD(long long &x) { scanf("%lld", &x); }
inline void _RD(double &x) { scanf("%lf", &x); }
inline void _RD(long double &x) { scanf("%Lf", &x); }
inline void _RD(char &x) { scanf(" %c", &x); }
inline void RD() {}
templa... |
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
String s=in.next();
int n=s.length();
int[][] dp=new int[n+n+1][n+n+1];
int[] c1=new int[n+1];
int[] c2=new int[n+1];
for (int i=1;i<=n;++i) {
c1[i]=c1[i-1];
c2[i]=c2[i-1];
if (s.c... | import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(ro... |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T alex(T x) {
return (x > 0) ? x : -x;
}
template <class T>
void read(T& x) {
x = 0;
T f = 1;
char ch = getchar();
while ((ch < 48 || ch > 57) && ch != 45) ch = getcha... | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
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 CHe... |
#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<pair<long long int, long long int> > v;
bool cmp(pair<long long int, long long int> p1,
pair<long long int, long long int> p2) {
if (p1.second + p2.first < p1.first + p2.second) return true;
return false;
}
int main() {
cin >> n;
for... |
import java.util.*;
import java.math.*;
import java.text.*;
import java.io.*;
public class Main {
static BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out=new ... |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int MOD;
const int N = 401;
int dp[2][N][N][2][2][2];
void add(int &a, int b){
a += b;
... | // Main Code at the Bottom
import java.util.*;
import java.io.*;
public class Main{
//Fast IO class
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
boolean env=System.getProperty("ONLINE_JUDGE") != null;
//env=true;
if(!en... |
n=int(input())
a=[int(i) for i in input().split()]
v=[0]*n
m=int(input())
f=[i+1 for i in range(n)]
ans=[]
for i in range(m):
q=[int(i) for i in input().split()]
if q[0]==1:
p,x=q[1],q[2]
xyz=[]
j=p-1
while j<n:
tmp=x+v[j]-a[j]
if tmp<=0:
v... | import java.util.Scanner;
import java.util.TreeSet;
/*
3
5 10 8
6
1 1 16
2 2
2 3
1 3 1
2 3
2
5 10
6
1 1 4
2 1
1 2 5
1 1 4
2 1
2 2
3
5 10 8
6
1 1 12
2 2
1 1 6
1 3 2
2 2
2 3
3
5 10 8
6
1 1 12
2 2
1 1 6
1 3 2
2 2
2 3
*/
public class D {
public static void main(String[] args) {
Scanner reader = new Sca... |
#include <bits/stdc++.h>
using namespace std;
long long n, x, y;
int main() {
cin >> n >> x >> y;
if (n > y) {
printf("-1\n");
return 0;
}
if ((y - n + 1) * (y - n + 1) + (n - 1) >= x) {
printf("%d\n", (int)(y - n + 1));
for (int i = 1; i < n; i++) {
printf("1\n");
}
return 0;
} ... | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class CodeH
{
static class Scanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokeni... |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, arr[101], sum = 0;
cin >> n;
for (int i = (0); i < (n); i++) cin >> arr[i];
sum = arr[0];
for (int i = (1); i < (n); i++) {
sum += ((arr[i] - 1) * (i + 1));
sum++;
}
cout << sum;
return 0;
}
| import java.math.BigInteger;
import java.util.Scanner;
public class TestingPantsforSadness {
public static void main (String [] args)
{
Scanner scan = new Scanner(System.in);
int n=scan.nextInt();
BigInteger count=new BigInteger("0");
for (int i=0;i<n;i++)
{
... |
import java.util.Scanner;
public class Main {
public static long MOD = 1000000007;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
long[][] dp = new long[n+1][n+1];
dp[1][0] = 1;
for(int i=0;i<m;i++) {
long[][] next = new long[n... | mod=10**9+7
N,M=map(int,input().split())
dp=[[0 for i in range(N+1)] for j in range(N+1)]
dp[N][N]=1
for i in range(M-1,-1,-1):
for k in range(1,N+1):
for j in range(k,N+1):
if j==k:
if j<N:
dp[j][k]=(j*dp[j][k]+(N-j)*dp[j+1][k])%mod
else:
... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
string s1, s2;
cin >> s1 >> s2;
if (s1 == s2)
cout << "-1";
else
cout << max(s1.size(), s2.size());
return 0;
}
| # my first python code
str1=raw_input()
str2=raw_input()
if str1==str2:
print "-1"
else:
print max(len(str1),len(str2)) |
#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 ans;
ans = a[0];
for (int i = 0; i < n ; i++) {
ans = min(ans, a[i]);
}
int b;
b = 0;
for (int i = 0; i < n; i++) {
if (a[i] == ans) {
b = i;
break;
... | N = int(input())
a = list(map(int, input().split()))
mina = min(a)
ans = a.index(mina)
print(ans + 1)
|
n = int(input())
edges = [int(x) for x in input().split()]
color = [int(x) for x in input().split()]
graph = [[] for _ in range(n)]
for a,b in enumerate(edges):
graph[a+1].append(b)
graph[b].append(a+1)
dp = [[0]*2 for _ in range(n)]
visited = [0]*n
stack = [0]
while stack:
v = stack[-1]
visited[v] = ... | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
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.List;
im... |
n, k = map(int, input().split())
a = list(map(int, input().split()))
print(sum(min(x.count(1), x.count(2)) for x in (a[i::k] for i in range(k))))
| #include <bits/stdc++.h>
using namespace std;
int n, k, ans, num[100][3], tmp;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &tmp);
num[i % k][tmp]++;
}
for (int i = 0; i < k; i++) ans = ans + min(num[i][1], num[i][2]);
printf("%d", ans);
}
|
import java.util.*;
import java.io.*;
import java.math.*;
public class Sample implements Runnable
{
public void run()
{
int n,x;
n=i();
x=i();
if(n==1){ out.println("YES");out.print(x);}
... | n,x = map(int,input().split())
num = 1<<17
val = 0
if n==1:
print('YES\n%d'%x)
elif n==2:
print('NO' if x==0 else 'YES\n0 %d'%x)
else:
print('YES')
for i in range(1,n-2):
print(i,end=' ')
val ^= i
if x!=val:
print(num^x,num^val,0)
else:
print(num,num<<1,num^(num<<... |
import java.io.*;
import java.util.*;
public class B33 {
public static void main(String[] args) {
InputReader in = new InputReader();
OutputWriter out = new OutputWriter(System.out);
int divisors[] = new int[16];
int power = 4;
divisors[0] = 1;
for(int i = 1; i < 16;... | n = int(input())
if n % 32640 == 0:
print('32640')
elif n % 8128 == 0:
print('8128')
elif n % 2016 == 0:
print ('2016')
elif n % 496 == 0:
print('496')
elif n % 120 == 0:
print('120')
elif n % 28 == 0:
print('28')
elif n % 6 == 0:
print('6')
else:
print('1') |
n = int(input())
for j in range(n):
m = int(input())
L = [int(e) for e in input().strip().split()]
L = L[: (len(L)//2) + 1 ]
if len(L) == 1: pass
elif L[-1] == L[-2]:
i = -2
while( i >= len(L)*-1 and L[i] == L[-1]):
i -= 1
L = L[:i+1]
else:
L =... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n];
for (auto i = 0; i < n; i += 1) {
cin >> a[i];
}
vector<long long> v;
long long c = 1;
long long eq = a[0];
for (auto i = 1; i < n; i += ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long pro;
long long max = 0;
vector<long long> v;
while (n > 0) {
v.push_back(n % 10);
n /= 10;
}
for (long long i = 0; i < v.size(); i++) {
pro = 1;
for (long long j = 0; j < i; j++) {
pro *= 9;... | def cal(k):
if (k == 0):
return 1
if (k < 10):
return k
return max(cal(k // 10) * (k % 10), cal(k // 10 - 1) * 9)
def main():
answer = input()
answer = int(answer)
print(cal(answer))
main()
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class SwapSort {
public static void main(String[] args){
InputScanner is = new InputScanner();
try {
int n = is.nextInt();
... | def find_min(i):
min = 1000000001
index = 0
for j in range(i, n):
if a[j] < min:
min = a[j]
index = j
return index
n = int(input())
a = input().split()
for i in range(n):
a[i] = int(a[i])
k = 0
ans = ()
for i in range(n):
m = find_min(i) # ����� ����������� ��... |
import java.io.*;
import java.lang.*;
import java.util.Scanner;
public class GFG {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();int ctr1=0;
String str=sc.nextLine();
String s=sc.nextLine();
for(int i=0;i<n;i++)
{
... | #include <bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0;
int n;
string s;
cin >> n >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '+') cnt++;
if (s[i] == '-') {
if (cnt == 0)
continue;
else
cnt--;
}
}
cout << cnt << endl;
return 0;
}
|
#include<iostream>
#include<set>
#include<cassert>
#include<cmath>
#include<vector>
#include<algorithm>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
using namespace std;
typedef pair<int,int> ii;
set<string> used;
int cnt = 0;
ii raint[4];
void dfs(int cur,int st,string pe... | import java.io.IOException;
import java.util.InputMismatchException;
public class Main {
int cnt;
int[][] p;
int[][] f;
void bt(int x, int y) {
if (4 <= y) {
cnt++;
return;
}
int nx = x + 1;
int ny = y;
if (4 <= nx) {
nx = 0;
ny++;
}
if (f[y][x] == 0) {
for (int i = 0; i < 4; i++) {
... |
import sys
readline = sys.stdin.buffer.readline
class E:
def __init__(self,to,nx):
self.to=to
self.nx=nx
class Graph:
def __init__(self,n):
self.n=n
self.head=[None]*n
def ae(self,a,b):
head=self.head
head[a]=E(b,head[a])
#head[b]=E(a,head[b])
return head[a]
def scc(g):
n=g.n
cur=g.head
last=... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>; ... |
import java.util.*;
import java.io.*;
public class Main{
BufferedReader in;
StringTokenizer str = null;
PrintWriter out;
private String next() throws Exception{
while (str == null || !str.hasMoreElements())
str = new StringTokenizer(in.readLine());
return str.nextToken();
}
... | #include <bits/stdc++.h>
const int N = 100005;
using namespace std;
long long ar[N], n, k, sm = 0;
long long R = 0;
bool can(long long r) {
long long lef = k;
for (int i = 1; i <= n; i++) {
lef -= min(ar[i], r);
}
R = lef;
return lef >= 0;
}
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
ci... |
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... | #include <bits/stdc++.h>
using namespace std;
int n, m, k, q;
vector<pair<int, pair<int, int> > > v;
bool calc(int mid) {
int mat[505][505];
memset(mat, 0, sizeof(mat));
for (int i = 0; v[i].first <= mid && i < v.size(); i++) {
mat[v[i].second.first][v[i].second.second] = 1;
}
for (int i = 0; i < 505; i++... |
import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer=null;
public static void main(String[] args) throws IOException
{
new Main().execute();
}
void debug(Object...os)
{
System.ou... | #import sys
#sys.stdin = open('in', 'r')
n,m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
#n,m = map(int, input().split())
r = 0
bi = 0
for i in range(n):
cd = abs(a[i]-b[bi])
while bi < m - 1 and abs(a[i]-b[bi + 1]) <= cd:
bi += 1
cd = ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.