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.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 = ... |
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<... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.