anchor stringlengths 10 14.3k | positive stringlengths 10 14.9k |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 998244353;
long long qpow(long long a, long long b) {
long long ans = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
long long gcd(long long a, ... |
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Andy Phan
*/
public class p1173e {
static int MOD = 998244353;
static int n;
... |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
int A;
vector<int> tail_vec(N, -1);
auto comp = greater<int>();
for (int i = 0; i < N; ++i) {
cin >> A;
*upper_bound(tail_vec.begin(), tail_vec.end(), A, comp) = A;
}
auto end = lower_bound(tail_vec.begin(), tail_vec.end(), -1, com... | from bisect import bisect_right
n = int(input())
color = [0] * (n+1)
for i in range(n):
a = int(input())
j = bisect_right(color, a)
color[j-1] = a+1
ans = 0
for t in color:
if t != 0:
ans += 1
print(ans)
|
#include <bits/stdc++.h>
using namespace std;
typedef long long signed int LL;
#define incID(i, l, r) for(LL i = (l) ; i < (r); ++i)
#define inc(i, n) incID(i, 0, n)
#define FI first
#define SE second
// ---- ----
const int MOD = 998244353;
int n, BIT[200001];
pair<int, int> p[200000];
LL e2[200001];
int su... | import java.io.*;
import java.nio.CharBuffer;
import java.util.*;
public class Main {
private static final int MOD = 998244353;
public static void main(String[] args) {
SimpleScanner scanner = new SimpleScanner(System.in);
PrintWriter writer = new PrintWriter(System.out);
int n = sca... |
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(in... | import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
new Main().run();
}
void run() throws FileNotFoundException {
solver();
}
@Supp... |
import java.io.*;
import java.util.*;
public class E {
public static void main (String[] args) { new E(); }
E() {
Scanner s = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
System.err.println("");
int n = s.nextInt(), m = s.nextInt(), k = s.nextInt();
if(k == n || m == n*(n-1)/2)... | #include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[303];
int b[303];
int c[303];
int g[303][303];
inline void dfs(int v) {
c[v] = 1;
for (int i = 0; i < n; ++i)
if (!c[i] && g[v][i]) {
printf("%d %d\n", v + 1, i + 1);
g[v][i] = g[i][v] = 0;
--m;
dfs(i);
}
}
int main() {... |
for e in iter(input,'0'):
n=int(e);m,f=[[0]*n for _ in[0]*n],'{:4}'*n
s=lambda x:-~x%n
j=n//2;i=j+1
m[i][j]=1
for k in range(2,n*n+1):
i,j,t=s(i),s(j),j
if m[i][j]:i,j=s(i),t
m[i][j]=k
for r in m:print(f.format(*r))
| import static java.lang.Math.atan2;
import static java.lang.Math.sqrt;
import static java.util.Arrays.deepToString;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
new Main().run();
}
void tr(Object... os) {
System.err.println(deepToString(os));
}
Scanner sc = new Scan... |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
int a[n][n];
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &a[i][j]);
if (i == j) {
ans = ans + a[i][j];
}
}
}
int q;
int x;
scanf("%d", &q);
int t;
while (q--) {
... |
import java.util.*;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
static int [][] mat=null;
static int n;
public static void main(String[] args) throws IOException {
StreamTokenizer st = new StreamTokenizer(... |
#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e18;
const long long minN = -1e18;
const int INF = 2e9;
const long long MOD = 1e9 + 7;
const long long MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const long double PI = acos(-1);
const long long limit = 2e5 + 5;
const ... | import java.io.*;
import java.util.*;
public class C {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
static class Pair {
int r, b;
public Pair(int r, int b) {
this.r = r;
this.b = b;
}
}
static int max = 0;
static class Options {
List<Pair> lst = new ArrayList<>(60)... |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
return x * f;
}
const int MAXN = 300;
const double eps = 1e-9;
int N, l[MAXN], r[MAX... | import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
import java.util.Scanner;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class E {
static int n, from, to;
static int[] left, right;
static double[][][] res;
stati... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n;
vector<int> e[maxn];
int ans[maxn];
int have[maxn][27];
void dfs(int cur, int from) {
for (int i = 0; i < e[cur].size(); i++) {
int t = e[cur][i];
if (t == from) continue;
dfs(t, cur);
for (int j = 0; j < 26; j++) have[cur][... | import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.u... |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n;
long int qtde_i, qtde_a;
char ch;
cin >> n;
qtde_i = 0;
qtde_a = 0;
for (long int i = 0; i < n; i++) {
cin >> ch;
if (ch == 'I') {
qtde_i += 1;
} else if (ch == 'A') {
qtde_a += 1;
}
}
if (0) {
cout ... | n=int(input())
arr=list(input())
if arr.count("I")==0:
print(arr.count("A"))
elif arr.count("I")==1:
print(1)
else:
print(0) |
n,a=int(input()),list(map(int,input().split()));dp=[[None]*n for _ in range(n)]
for i in range(n):dp[i][i]=a[i]
for j in range(1,n):
for i in range(n-j):dp[i][j+i]=max(a[i]-dp[i+1][j+i],a[j+i]-dp[i][j+i-1])
print(dp[0][-1]) | import java.util.*;
import java.io.*;
class Main{
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
thi... |
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.List;
import java.util.StringTokenizer;
import java.io.Writer;
import j... | from sys import stdin
from itertools import repeat
from bisect import bisect
def main():
n, m = map(int, stdin.readline().split())
dat = map(int, stdin.read().split(), repeat(10, 2 * n))
s = [0] * (m + 1)
for i, x in enumerate(dat):
if i & 1:
s[x] -= 1
else:
s[x-1... |
#####################################
import atexit, io, sys, collections, math, heapq
buffer = io.BytesIO()
sys.stdout = buffer
@atexit.register
def write(): sys.__stdout__.write(buffer.getvalue())
#####################################
def f(ais):
m = min(ais)
for j in range(len(ais)):
if ais[j] == m:
bre... | #include <bits/stdc++.h>
using namespace std;
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define mod 1000000007
#define mod2 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define en "\n"
#define MN INT_MIN
#define MX 100000001
#define fr(i,a,b) for(long long int i=a;i<b;i... |
import math
import sys
read = sys.stdin.readline
n = int(read())
sub = [[] for _ in range(n)]
for i in range(n):
data = read().strip()
for j in data.split('-'):
tree = list(map(int, j.split(':')[1].split(',')))
for k in range(len(tree)):
tree[k] -= 1
sub[i].append(sorted(tree... | #include <bits/stdc++.h>
using namespace std;
int n, ja[3030], grau[3030];
vector<set<int> > ramos[3030];
set<set<int> > ori[3030];
vector<pair<int, int> > ans;
vector<int> adj[3030];
void dfs(int v, int p, set<int>& pr) {
pr.insert(v);
for (int(i) = (0); (i) < (((int)(adj[v]).size())); (i)++)
if (p != adj[v][i... |
n = input()
lr1 = [map(int, raw_input().split()) for i in range(n)]
m = input()
lr2 = [map(int, raw_input().split()) for i in range(m)]
min_r1 = min(map(lambda (l, r): r, lr1))
min_r2 = min(map(lambda (l, r): r, lr2))
max_l1 = max(map(lambda (l, r): l, lr1))
max_l2 = max(map(lambda (l, r): l, lr2))
print max(0, max... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
long long int m, cnt = 0, maxi = 0;
cin >> m;
long long int c[m], d[m];
for (int i = 0; i < m; i++) {
cin >> c[i] >> d[i];
}
... |
#!/usr/bin/env python3
from collections import defaultdict
DEBUG = False
def main():
if DEBUG:
test()
n = int(input())
paths = cycles(n)
print(len(paths))
for p in paths:
print('%d %s' % (len(p), ' '.join([str(v) for v in p])))
def cycles(n):
"""Builds a set of cycles fo... | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
public class abcd {
public static void main(String[] args) {
FS in = new FS();
... |
import java.util.Scanner;
public class alarm {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x = input.nextInt();
int h= input.nextInt();
int m = input.nextInt();
int count= 0;
while(h%10!=7 && m%10!=7){
m-=x;
... | #include <bits/stdc++.h>
int counter = 0;
void check(int hh, int mm, int snooze) {
while (mm % 10 != 7 && hh % 10 != 7) {
mm -= snooze;
if (mm < 0) {
mm = mm + 60;
hh--;
if (hh < 0) hh = hh + 24;
}
counter++;
}
}
int main(void) {
int snooze;
int hh, mm;
scanf("%d", &snooze);
... |
#include <iostream>
using namespace std;
#define MAX 100000
#define INF 1 << 31
struct Node
{
int parent;
int cost;
};
int parent[MAX];
int depth[MAX];
int cost[MAX];
Node findParent(int child)
{
Node tmp;
if (child != parent[child])
{
tmp = findParent(parent[child]);
parent[child] = tmp.parent;
... | import sys
input = sys.stdin.readline
class UnionFindWeighted:
"""ポテンシャル付きUnionFind"""
def __init__(self, n):
self.parent = [-1] * n
self.weight = [0] * n
self.cnt = n
self.INF = 10 ** 18
def root(self, x):
"""頂点xの根を求める"""
if self.parent[x] < 0:
... |
import java.util.*;
import java.io.*;
public class Candy {
public static void main(String [] args) {
Solver s = new Solver () ;
s.solve();
}
static class Solver {
int min_value(ArrayList <Pair> a) {
int mn = Integer.MAX_VALUE;
for(Pair i : a) {
... | #include <bits/stdc++.h>
using namespace std;
int n, cnt, ans[1000000][2];
struct data {
int val, id;
} a[1010];
bool cmp(const data x, const data y) {
return x.val == y.val ? x.id < y.id : x.val > y.val;
}
void Remove() {
int t = a[2].val / a[3].val;
while (t) {
if (t & 1) {
a[2].val -= a[3].val;
... |
#include <bits/stdc++.h>
using namespace std;
int f[1000005], a, b, n;
int main() {
scanf("%d", &n);
for (int x, i = 1; i <= n; ++i) {
scanf("%d", &x);
if (x == 1) {
++a;
} else {
++b;
}
}
f[0] = 1;
f[1] = 1;
f[2] = 2;
for (int i = 3; i <= a; ++i) {
f[i] = (f[i - 1] + 1ll *... | import java.util.*;
import java.io.*;
public class PE {
final static long mod = 1000000007;
public static void main(String[] args) throws Exception {
Parser in = new Parser(System.in);
int n = in.nextInt();
int count2s = 0;
for(int i = 0; i < n; i++) {
int checker = in.nextInt();
if(checker == 2) {
... |
#include <bits/stdc++.h>
#define MAXN 3007
#define MOD 998244353
using namespace std;
long long dp[MAXN][MAXN];
int main()
{
int a,b,c,d; cin>>a>>b>>c>>d;
dp[a][b]=1;
for(int i=a;i<=c;i++) for(int j=b;j<=d;j++) if(a!=i || b!=j) dp[i][j]=(i*dp[i][j-1]+j*dp[i-1][j]-((i-1LL)*(j-1LL)*dp[i-1][j-1])%MOD+MOD)%MOD;
cout<<d... | mod=998244353
a,b,c,d=map(int,input().split())
if a==c and b==d:
print(1)
exit()
dp=[[0]*d for _ in range(c)]
tmp=1
for i in range(a,c):
tmp*=b
tmp%=mod
dp[i][b-1]=tmp
tmp=1
for i in range(b,d):
tmp*=a
tmp%=mod
dp[a-1][i]=tmp
for i in range(b,d):
tmp=0
for j in range(a,c):
tmp*=i
tmp+=dp[j-1... |
import itertools
def get(permutation):
ans = 0
for i in range(len(permutation)):
for j in range(i + 1, len(permutation)):
if permutation[j] < permutation[i]:
ans += 1
return ans
def check(s, pat):
for i in range(len(pat)):
if pa... | #include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> a, b[20];
bool p[20] = {};
int ans[20] = {};
void rec(int tnum, int wnum, int c, int st, int pnum) {
if (st >= b[tnum].size()) return;
while (st < b[tnum].size() && b[tnum][st] != a[wnum]) st++;
if (st >= b[tnum].size()) return;
p[wnum] = tr... |
#include <bits/stdc++.h>
using namespace std;
vector<int> l[100010], r[100010], chosenl[100010], chosenr[100010];
vector<bool> badl[100010], badr[100010];
bool monst[100010];
int ans[100010];
vector<pair<int, int> > edges[100010];
int cnt[100010], toFather[100010], fromFather[100010];
void longPathChild(int v, int f) {... | //https://github.com/EgorKulikov/yaal/tree/master/lib/main/net/egork
import java.util.*;
import java.io.*;
public class E{
static PrintWriter out;
static InputReader in;
public static void main(String args[]){
out = new PrintWriter(System.out);
in = new InputReader();
new E(... |
t = int(input())
for i in range(t):
s = input()
n = 0
a = 0
b = 0
for c in s:
if c == '(':
a += 1
if c == '[':
b += 1
if c == ')' and a > 0:
n += 1
a -= 1
if c == ']' and b > 0:
n += 1
b -= 1
print(n) | #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c... |
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
//指定された頭文字からはじまる文字列とそれの出現回数を
//扱う、クラス。sort用に比較も用意。
class Moji implements Comparable<Moji>{
String str="";
int count=0;
Moji(String a,int b){
str=a;
count=b;
}
@Override
public int compareTo(Moji o) {
// TODO 自動生成されたメソッド・スタブ
if(t... | from collections import defaultdict
while True:
n = int(input())
if n==0:
break
initial = defaultdict(set)
cnt = defaultdict(int)
for _ in range(n):
l = list(input().split())
for li in l:
initial[li[0]].add(li)
cnt[li] += 1
... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class _526E {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
int n=fs.n... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
struct matrix {
int x, y;
long long v;
} a[N];
int n, convex_hull[N];
long long f[N];
double slope(int i, int j) { return (double)(f[i] - f[j]) / (a[i].x - a[j].x); }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%... |
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Task242A {
public static void main(String... args) throws NumberFormatException,
IOException {
Solution.main(System.in, System.out);... | #include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > V;
int main(void) {
int x, y, a, b;
scanf("%d %d %d %d", &x, &y, &a, &b);
int cnt = 0;
for (int i = a; i <= x; i++) {
for (int j = b; j <= y; j++) {
if (i > j) cnt++;
}
}
printf("%d\n", cnt);
for (int i = a; i <= x; i++) {... |
n = int(input())
masks = [1 << x for x in range(n)]
for i in range(1 << n):
sub = [idx for idx, mask in enumerate(masks) if i & mask != 0b00]
print('{}: {}'.format(i, ' '.join(map(str, sub)))) if len(sub) != 0 else print(f'{i}:')
| #include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
double n2;
cin >> n;
n2 = n;
int bit[n];
int selection[n];
for( int i = 0; i < n; i++ )
{
bit[i] = i;
selection[i] = 0;
}
for( int i = 0; i < pow( 2, n2 ); i++ )
{
int... |
#include <bits/stdc++.h>
using namespace std;
long long x, c, arr[1000];
bool b;
string num_to_string(int num) {
stringstream ss;
ss << num;
return ss.str();
}
void O_o() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
int main() {
O_o();
priority_queue<int> q;
int ... |
import java.util.Arrays;
import java.util.Scanner;
public class mo {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int size = input.nextInt();
int lima = input.nextInt();
int[] arr = new int [size - 1];
for (int i = 0; i < arr.length; i++) {
arr[i] = input.nextInt()... |
s = raw_input().strip()
keys = [ None for i in range(int(raw_input())) ]
for i in range(len(keys)):
keys[i] = raw_input().strip()
best_length, best_pos = 0, 0
def kosher(left, right):
pos_range = range(right - 1, left - 1, -1)
#print(left, right)
for key in keys:
for pos in pos_range:
... | import java.io.*;
import java.util.*;
import static java.lang.Math.min;
public class Code implements Runnable {
public static void main(String[] args) throws IOException {
new Thread(new Code()).start();
}
private void solve() throws IOException {
String mess = nextToken();
int n... |
import java.util.*;
public class SuperAgent {
public static void main(String[]args){
String[] s = new String[3];
Scanner input = new Scanner(System.in);
for(int i = 0;i < 3;i++){
s[i] = input.next();
}
char[] arrmid = s[1].toCharArray();
int j = arrmid.length-1;
for(int i = 0;i < j;i... | #include <bits/stdc++.h>
int main() {
char passKey[4][4];
char revKey[4][4];
for (int i = 0; i < 3; i++) {
scanf("%s", &passKey[i][0]);
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
revKey[2 - i][2 - j] = passKey[i][j];
}
}
bool isOk = true;
for (int i = 0; i < 3; i++) ... |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> tree[2010];
int dfs(int pos) {
int ret = 0;
for (int i = 0; i < tree[pos].size(); i++)
ret = max(ret, 1 + dfs(tree[pos][i]));
return ret;
}
int main() {
scanf("%d", &n);
vector<int> allah;
for (int i = 0; i < n; i++) {
int x;
scanf... | import java.util.*;
import java.io.*;
public class Main {
static class Scan {
private byte[] buf=new byte[1024];
private int index;
private InputStream in;
private int total;
public Scan()
{
in=System.in;
}
public int scan()throws IOExcepti... |
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A155 {
FastScanner in;
PrintWriter out;
public void solve() throws IOException {
int ... | n = int(input())
a = [int(s) for s in input().split()]
maxi, mini, k = a[0],a[0],0
for i in range(1,len(a)):
if maxi < a[i]:
maxi = a[i]
k += 1
elif mini > a[i]:
mini = a[i]
k += 1
print(k) |
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) throws Exception{
Scanner scan = new Scanner(System.in);
int r1 = scan.nextInt();
int r2 = scan.nextInt();
int c1 = scan.nextInt();
int c2 = scan.nextInt();
int d1 = sc... | #include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
int a11 = (r1 + c1 - d2) / 2;
int a12 = r1 - a11;
int a21 = c1 - a11;
int a22 = d1 - a11;
if (a11 != a12 && a11 != a21 && a11 != a22 && a12 != a21 && a12 != a22 &&
a21 != a... |
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), m = sc.nextInt(), x = sc.nextInt();
x = x*x;
... | from math import sqrt
n, m, x = map(int, input().split())
arr=[]
for i in range(n):
arr.append([k for k in input()])
r=input()
s = input()
di={}
present=set()
for p in range(65,91):
di[chr(p).lower()] = -1
shift=[]
for a in range(n):
for b in range(m):
if arr[a][b] == "S":
shift.append([... |
import java.io.*;
import java.util.*;
public class Main{
static class base implements Comparable<base>{
int d,g;
base(int dd,int gg){
d=dd;g=gg;
}
@Override
public int compareTo(base o) {
return d-o.d;
}
}
static long inf=(long)1e15+7;
static long[][]adj;
static int V, s, t;
static long ... | #include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int INF = 1e9 + 5;
const long long INF_LL = 1e15 + 5;
int g[N][N], dist[N][N];
struct Ship {
int loc, attack, fuel, price;
void read() {
cin >> loc >> attack >> fuel >> price;
--loc;
}
};
vector<pair<int, int>> reward[N];
struct Base {... |
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],n;
long long ans;
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++)scanf("%d",&a[i]);
a[0]=-1;
for (int i=1;i<=n;i++)
if (a[i-1]<a[i]-1){
puts("-1");
return 0;
}
for (int i=n;i;i--){
if (a[i]==a[i+1]-1)continue;
ans+=a[i];
}... | n = int(input())
prev = ans = -1
a = [int(input()) for _ in range(n)]
for i in a:
if i - prev > 1:
print(-1)
exit()
elif i - prev == 1:
ans += 1
else:
ans += i
prev = i
print(ans) |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
for (auto& v : t) {
i >> v;
}
return i;
}
templat... | import java.util.*;
public class TakeMetro {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int M = scanner.nextInt();
//saves mod annoyances
int S = scanner.nextInt()-1;
long T = scanner.nextLong();
... |
def positive_problem():
pos_num, neg_num = 0, 0
n = eval(input())
a = input().split(' ')
for i in range(len(a)):
a[i] = eval(a[i])
for i in range(len(a)):
if a[i] > 0:
pos_num += 1
elif a[i] < 0:
neg_num += 1
if n % 2 == 0:
p = n // 2
e... | #include <bits/stdc++.h>
using namespace std;
double a[200];
int n;
int main() {
cin >> n;
int po = 0, ni = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > 0)
po++;
else if (a[i] < 0)
ni++;
}
double x = 2;
if (po >= ceil((double)n / 2)) {
cout << 2;
return 0;
} els... |
import java.util.*;
public class Main{
public static void main(String[] args){
double ans = 0;
Scanner sc = new Scanner(System.in);
double t = sc.nextInt();
double x = sc.nextInt();
ans = t / x;
System.out.println(ans);
}
} | #include <stdio.h>
int main() {
float t, x, a;
scanf("%f%f", &t, &x);
a = t / x;
printf("%f\n", a);
} |
import java.io.*;
import java.util.*;
public class D1 {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
int b;
int decode(int x, int y) {
return x * b + y;
}
static final String DIRS = "ULDR";
static final int[] DX = { 0, -1, 0, 1 };
static final int[] DY = { 1, 0, -1, 0 };
stati... | #include <bits/stdc++.h>
using namespace std;
template <class T>
void setmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
void setmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
... |
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+... | T = int(raw_input())
for case_ in xrange(T):
n = int(raw_input())
ts = map(int, raw_input().split())
ss = map(int, raw_input().split())
dp = [0 for i in xrange(n)]
for i in xrange(n):
for j in xrange(i - 1, -1, -1):
if ts[i] == ts[j]:
continue
delta... |
import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;
p... | #include <bits/stdc++.h>
using namespace std;
struct node {
int l, r, x;
node *L, *R;
pair<int, int> v;
} nd[100100], *nil = &nd[100099], *root;
pair<int, int> p[100100];
int n, k, m, l, r;
long long a, b, c, d;
pair<int, int> upd(pair<int, int> l, pair<int, int> r) {
return make_pair(l.second + r.second,
... |
#include <bits/stdc++.h>
using namespace std;
int O[50000 + 5], on[50000 + 5], C;
map<int, int> Edge[50000 + 2];
vector<int> H[50000 + 2], gr[50000 + 2];
void On(int u) {
on[u] = 1;
if (gr[u].size() < C) {
for (int it = 0; it < gr[u].size(); it++)
if (gr[u][it] > 0) O[gr[u][it]]++;
}
}
void Off(int u) {... | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashSet;
im... |
#include <bits/stdc++.h>
int ind[10];
using namespace std;
int main() {
int n;
int a[100100];
int s = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
ind[a[i]]++;
}
if (ind[0] == 0) {
cout << -1;
return 0;
}
int kt = 1;
if (s % 3 != 0)
for (int j = 1; j <= ... | //package CodeForces;
import java.util.HashMap;
import java.util.Scanner;
public class Hometask {
static StringBuilder solve(int arr[])
{
if(arr[0]==0)
{
StringBuilder ans=new StringBuilder("-1");
return ans;
}
int temp=arr[1]+arr[4]+arr[7]+2*(arr[2]+arr[5]+arr[8]);
int x=temp%3;
if(x==1)
... |
while True:
H, W = map(int, input().split())
if H == 0 and W == 0:
break
for x in range(H):
for y in range(W):
if (x + y) % 2 == 0: print('#', end='')
else: print('.', end='')
print()
print()
| import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
Scanner sc = new Scanner(System.in);
int i, j;
// 最初の文字の固まりを整数値と想定して読み込む
while (true) {
int H = sc.nextInt();
int W= sc.nextInt();
if (H == 0 && W == 0) {
break; }
for(i=0; i<H; i++){
for(j=0; j<W; j++){
... |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
return a * a;
}
const int INF = INT_MAX / 2;
const long double EPS = 1e-9;
const... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ProblemC {
static int[][] board;
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] num = ... |
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A {
public static int gcd(int a, int b) {
if(a == 0 || b == 0) return a+b; // base case
return gcd(b,a%b);
}
public static void main(Stri... | #include <bits/stdc++.h>
using namespace std;
int GCD(int A, int B) {
if (B == 0)
return A;
else
return GCD(B, A % B);
}
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
int i = n / 2 - 1;
int j = n / 2 + 1;
while (GCD(i, j) != 1) {
i--;
j++;
}
cout << i << " " << j;
}... |
import sys
sys.setrecursionlimit(10**9)
n=int(input())
l=[[] for i in range(n)]
C=[0]*n
for i in range(n-1):
a,b,c=map(int,input().split())
a-=1
b-=1
l[a].append([b,c])
l[b].append([a,c])
def dfs(now,par,cost):
C[now]=cost
L=l[now]
for i in range(len(L)):
if L[i][0]==par:
... | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
vector<pair<int,int>> gra[100010];
ll dist[100010];
void dfs(ll x,ll y){
for(const auto& it:gra[x]){
ll s=it.first,len=it.second;
if(dist[s]!=-1)continue;
dist[s]=y+len;
dfs(s,dist[s]);
}
}
i... |
def solve():
from sys import stdin
f_i = stdin
while True:
N, T, L, B = map(int, f_i.readline().split())
if N == 0:
break
skip = {}
sq_attr = [None] * N
for i in range(L):
sq = int(f_i.readline())
sq_attr[sq] = 'Lose'
... | import java.util.Scanner;
public class Main {
Scanner in = new Scanner(System.in);
int N, T, L, B;
double[][] dp;
boolean[] lose, back;
public void run() {
while (true) {
N = in.nextInt();
T = in.nextInt();
L = in.nextInt();
B = in.nextInt();
if (B == 0 && N == 0 && T == 0 && L == 0) break;
... |
while True:
r, c, q = map(int, input().split())
if r == 0: break
querys = [list(map(int, input().split())) for _ in range(q)]
querys.reverse()
r_used = [False] * r
c_used = [False] * c
r_cnt = c
c_cnt = r
ans = 0
for a, b, o in querys:
if a == 0:
if not r_used[b]:
r_used[b] = True
... | import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {
void run() {
Scanner sc = new Scanner(System.in);
while (true) {
int r = sc.nextInt();
int c = sc.nextInt();
int q = sc.nextInt();
if ((r | c | q) == 0)
... |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[8][3], b[8][3], pos[8][3];
bool ok = 0;
bool isCube() {
map<long long int, long long int> mp;
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
long long int dt = (((long long int)a[i][0] - (long long int)a[j][0]) *
... | //package com.company;
import java.io.*;
import java.util.*;
public class Main {
static long TIME_START, TIME_END;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
// Scanner sc = new Scanner(new FileInputStream("Test.in"));
PrintWriter pw... |
import java.util.*;
import java.io.*;
public class BrokenSequence {
public static void main(String[] args) throws IOException {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(rd.readLine());
StringTokenizer st = new StringTokenizer(rd.readLine());
int numMissing... | M=10**9+7
n=input()
a=[0]*n
l=map(int,raw_input().split())
for v in l:a[v-1]|=v>0
z=[0,0]
for x,y in zip(a,l):z[x]+=y<0
n,m=z
a=0;b=1
for i in range(m):b=b*-~i%M
for i in range(n):a,b=b,(a*i+b*(i+m))%M
print b
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int dp[N], ans[N];
int cumxor[N];
int lo(int n, int k) {
if (k % 2) {
if (n % k) return 0;
int ans = n / k - k / 2;
if (ans <= 0) ans = 0;
return ans;
} else {
if ((2 * n) % k) return 0;
int mid = 2 * n / k;
if (mid % 2... | import math
from collections import Counter
n = int(input())
g = [0 for i in range(n + 1)]
prefix_xor = g.copy()
def in_range(d, k):
if (2 * k - d * d + d) % (2 * d) != 0:
return -1
x = (2 * k - d * d + d) / (2 * d)
return int(x) if x > 0 else -1
def mex(arr):
counter = Counter()
for i ... |
#include <bits/stdc++.h>
using namespace std;
const int MN = 360360;
long long dp[MN + 1], a, b, k, lol, dp2[MN + 1];
long long solve(long long st, long long en) {
memset(dp2, 0, sizeof(dp2));
for (long long i = st + 1; i <= en; i++) {
dp2[i - st] = 1LL << 60;
for (int j = 2; j <= k; j++) {
long long ... | import java.util.*;
public class f {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
long a = input.nextLong(), b = input.nextLong();
int k = input.nextInt();
int lcm = 1;
for(int i = 2; i<=k; i++) lcm = lcm(lcm, i);
int[] dp = new int[2*lcm];
int start = (in... |
from collections import deque
n = int(input())
g = [[] for _ in range(n)]
for i in range(n):
_, _, *edge = map(lambda x: int(x)-1, input().split())
g[i] = edge
q = deque()
q.append(0)
dist = [-1 for _ in range(n)]
dist[0] = 0
while(len(q) > 0):
v = q.popleft()
for nv in g[v]:
if(dist[nv] !=... | //template code, C343, 2019
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;
import java.util.*;
class Graph {
private int totalVertex;
private LinkedList<LinkedList<Integer>> adjList;
//adjacency list of edges
public Graph() { totalVertex = 0; }
public void loadAdjList() {
Scann... |
from math import *
n = int(input())
dx1 = 0
dx2 = 0
dy1 = 0
dy2 = 0
a = []
for i in range(n):
x,y = [int(x) for x in input().split()]
a.append([x,y,i])
a.sort(key = lambda item: atan2(item[1],item[0]))
a.append(a[0])
dx1 = (a[0][0]*a[1][0]+a[0][1]*a[1][1])
dy1 = abs(a[0][0]*a[1][1]-a[1][0]*a[0][1])
minx = (dx1)... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
public class Main_Educational1_C {
public static void main(String[] args) {
Scanner s... |
/**
* @author derrick20
*/
import java.io.*;
import java.util.*;
public class NavigationSystem {
public static void main(String args[]) throws Exception {
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
N = sc.nextInt();
M = sc.nextInt();
... | #include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> v[200007];
int f[200007];
int cnt[200007];
int len;
int seq[200007];
void bfs(int st) {
queue<int> q;
f[st] = 1;
cnt[st] = 0;
q.push(st);
while (q.empty() == false) {
int x = q.front();
q.pop();
int sz = v[x].size();
for (int ... |
#!/usr/bin/env python
from __future__ import division, print_function
import io
import os
import sys
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
else:
from io import BytesIO as StringIO... |
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class GraphWithoutLong... |
import java.util.*;
import java.awt.geom.*;
public class Main {
double EPS = 1.0e-08;
int INF = 1 << 24;
Comparator< Point2D > com = new Comparator< Point2D >() {
public int compare(Point2D o1, Point2D o2) {
if(o1.getX() < o2.getX()) return -1;
else if(o1.getX() > o2.getX()) return 1;
else if(o1.getY() <... | from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def dot3(O, A, B):
ox, oy = O; ax, ay = A; bx, by = B
return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy)
def cross3(O, A, B):
ox, oy = O; ax, ay = A; bx, by = B
return (ax - ox) * (by - oy) - (bx - o... |
import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;
import static java.util.Arrays.fill;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStrea... | #include <bits/stdc++.h>
using namespace std;
long long kk[10] = {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000};
map<long long, int> flag;
int id[11], a[11], n, ans;
long long Cantor(int p[]) {
long long tmp = 0;
for (int i = 1; i <= n; i++) tmp =... |
N = int(input())
for i in range(N):
L = []
while 1:
*s, = map(int, input().split())
if s[-1] == 0:
L.extend(s[:-1])
break
L.extend(s)
G = []
st = []
cur = 0
for s in L:
if s > 0:
G.append([])
if st:
u... | import java.util.*;
public class Main {
//0140 start
//0200 end
//0430 restart
//0442 sample match WA
//0509 WA * 2
//0920 WA * 2
//0921 AC
class C{
int count, rest;
ArrayList<Integer> list;
public C(int count, int rest) {
this.count = count;
this.rest = rest;
this.list = new ArrayList<Integer>... |
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
public class C {
static class Task {
private boolean isPrime(int num) {
int end = (int) Math.sqrt(num);
for (int i = 2; i <= end; i++) {
... | #include <bits/stdc++.h>
using namespace std;
void solve(int n, int x, int y) {
if (n == 2) {
cout << x << " " << y << endl;
return;
}
int val = y - x;
int ans = INT_MAX;
int ind_x, ind_y;
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
if (val % (j - i) == 0) {
in... |
import java.io.*;
import java.util.*;
public class H {
public static void main(String[] args) {
try {
new H().solve();
} catch (Exception e) {
e.printStackTrace();
}
}
void solve() throws IOException {
// Scanner sc = new Scanner(System.in);
... | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * (b / (gcd(a, b))); }
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline long long toL... |
#include <iostream>
using namespace std;
#define NM 20000
int main()
{
bool p[NM] = {0};
p[0]=p[1]=1;
for(int i=2; i*i<NM; i++)
{
if(!p[i])
for(int j=i*2; j<NM; j+=i)
{
p[j] = 1;
}
}
int n;
while(cin >> n)
{
int c=0;
for(int i=1; i<n+1; i++)
{
if((!p[i]) && (!p[n-i+1]))
{
c++;
... | import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String is;
while((is = in.readLine()) != null){
int a = Integer.par... |
n=int(input())
a,b=map(int,input().split())
c=int(input())
d=sorted([int(input()) for _ in [0]*n],reverse=True)
for i in d:
if c/a<(c+i)/(a+b):
c+=i
a+=b
else:
break
print(c//a)
| // 2012/11/19 Tazoe
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int N;
cin >> N;
int A, B;
cin >> A >> B;
int C;
cin >> C;
int D[100];
for(int i=0; i<N; i++){
cin >> D[i];
}
sort(D, D+N);
int c_sum = C;
int p_sum = A;
for(int i=N-1; i>=0; i--){
if(c_sum/p_sum>(c_s... |
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws FileNotFoundException {
//Scanner sc = new Scanner(new FileReader(new File("input")));
//System.setOut(new PrintStream(new FileOutp... | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, a[105], n, max_n = 0, m, x, maxm = 0, sum = 0;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] > maxm) {
maxm = a[i];
max_n = 1;
} else if (a[i] == maxm) {
max_n++;
}
}
sum = max... |
N = int(input())
A = list(map(int, input().split()))
print(sum([i&1 and a&1 for i,a in enumerate(A,1)])) | #include<bits/stdc++.h>
using namespace std;
#define int int64_t
signed main(){
int n,a,ans=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a;
if(i%2==1&&a%2==1) ans++;
}
cout<<ans<<"\n";
} |
#include<bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
u64 arr[] = {
2,
3,
2,
395069,
2,
83,
2,
3,
2,
7,
2,
17,
2,
3,
2,
11,
2,
5,
2,
3,
2,
103,
2,
7,
2,
3,
2,
5,
2,
... | import java.math.*;
class Main{
public static void main(String[]z){
BigInteger b=BigInteger.ONE;
int i=2,n=new java.util.Scanner(System.in).nextInt();
for(;i<1501;i++)b=b.multiply(new BigInteger(String.valueOf(i)));System.out.println(b.add(new BigInteger("2")));
for(i=0;i<n;i++)System.out.println(i+2);
}
} |
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
def main():
n,m = map(int,input().split())
MOD = 998244353
adjList = []
dist = []
ans = []
for _ in range(n):
adjList.append([])
for _ in range(m):
a,b = map(int,input().split())
adjList[a - 1... | #include <bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define F(i, j, k) for (int i = j; i <= k; ++i)
#define DF(i, j, k) for (int i = j; i >= k; --i)
using namespace std;
template <typename T> inline void read(T &n) {
T w = 1;
n = 0;
char ch = getchar();
while (!isdigit(ch) &&... |
#include "bits/stdc++.h"
using namespace std;
long long int N,M,K,L,R,H,W;
const long long int MOD=1000000007;
int main(){
while(cin>>N,N){
M=0;
for(int i=2;i<=N;i++){
if((N*2)%i)continue;
K=N*2/i;
R=K+i-1;
if(R&1)continue;
R/=2;
L=R-i+1;
if(R+L==K&&L>=1)M++;
}
cout<<M<<endl;
}
ret... | while True:
n=input()
if n==0:break
cnt=0
for i in range(1,n):
temp=0
for j in range(i,n):
temp+=j
if temp==n:
cnt+=1
elif temp>n:
break
print cnt |
import java.util.Scanner;
public class codefo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner ob =new Scanner(System.in);
int t=ob.nextInt();
while(t-->0)
{
int n=ob.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=ob.nextInt();
}
... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = n - 1; i >= 0; i--) cout << a[i]... |
import java.io.*;
import java.util.*;
public class Template implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void init() throws FileNotFoundException {
try {
in = new BufferedReader(new FileReader("input.txt"));
o... | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2 * MOD;
int n, m;
int main() {
std::ios_base::sync_with_stdio(false);
set<int> zeros[17];
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 0; i < 17; ++i) {
zeros[i].insert(0);
zeros[i].insert(n + 1... |
import sys
from array import array # noqa: F401
def readline(): return sys.stdin.buffer.readline().decode('utf-8')
def build_bridge_tree(v_count, edge_count, adj, edge_index):
from collections import deque
preorder = [0]
parent, order, low = [0]+[-1]*v_count, [0]+[-1]*(v_count-1), [0]*v_count
stac... | #include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0,... |
#include <bits/stdc++.h>
using namespace std;
string a, b;
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> a >> b;
cin >> n;
cout << a << " " << b << '\n';
while (n--) {
string x, y;
cin >> x >> y;
if (x == a)
a = y;
else
b = y;
cout << a <... | import java.util.*;
import java.util.Arrays;
public class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String na=sc.next();
String nb=sc.next();
String a , b;
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
... |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF... |
import java.util.*;
public class Main {
//1140 start
private void doit(){
Scanner sc = new Scanner(System.in);
while(true){
int n = sc.nextInt();
int m = sc.nextInt();
int K = sc.nextInt();
if((n|m|K) == 0)break;
long [][] dp = new long[n+1][n * m + 1];
for(int i = 1; i < m+1; i++){
dp[1]... |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll t;
cin>>t;
while(t--){
ll x=0,y=0,n,c=0,sum=0,d,k;
cin>>d>>k;
while(1){
x+=k;
if(x*x+y*y>d*d)
break;
sum++;
y+=k;
if... | import java.util.*;
import java.io.*;
public class D{
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main (String[] args) throws IOException{
int t = Inte... |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100000 + 10];
int t[100000 + 10];
void solve() {
int res = 0;
for (int i = 0; i < n; i++) {
if (t[i]) res += a[i];
}
int tmp = 0, sum = 0;
for (int i = 0; i < k; i++) {
if (t[i] == 0) tmp += a[i];
}
for (int i = 0; i + k <= n; i++) {
... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class CF0961B_LectureSleep {
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
... |
t = int(input())
for _ in range(t):
n, x = map(int, input().split())
# n is the length of binary string. x is the balance: count of 0 - count of 1
s = input()
# prefix balance array
pref = [0]*n
pref[0] = 1 if s[0] == '0' else -1
x_found = 0
# infinite case
for i in range(n):... | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string itos(int n) {
stringstream ss;
ss << n;
string second = ss.str();
return second;
}
long long ppow(long long x, long long y, long long mod) {
long long res = 1;
while (y) {
if (y & 1) res = res * x % mod;
y >>= 1;
x =... |
import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
#print = stdout.write
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
need = sum([i for i in arr if i >= 0]... | #include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return fa... |
n= map(int, raw_input().split())
a = map(int, raw_input().split())
a1 = [0]*len(a)
table = {}
for i,x in enumerate(a):
if x-1 in table:
tmp = table[x-1]
table[x] = [tmp[1], i+1, tmp[2]+1]
a1[i] = tmp[1]-1
else:
table[x] = [-1,i+1,1]
a1[i] = -1
maxlen = 0
k = -1
for key, val in table.iteritems():
if val[2]... | /*
"जय श्री कृष्णा"
*/
import java.util.*;
import java.io.*;
public class Consecutive_Subsequences implements Runnable
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
this.br = new BufferedReader(new InputStreamReade... |
import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
static Scanner in = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
// Scanner in = new Scanner(new BufferedReader(new FileReader("input.txt")));
// PrintWriter out = new PrintWriter(new FileWriter("o... | '''
Created on Oct 11, 2015
@author: Ismael
'''
n=int(input())
l=[int(c) for c in input().split()]
count = 0
i=0
direc=1
change=0
while(count < n):
v = l[i]
if v <= count:
#print(i,"grab")
l[i] = n+1
count += 1
if count == n:
break
if (i == 0 and direc == -1) or (i == n-... |
//package round93;
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.HashMap;
import java.util.Map;
import java.util.TreeSet;
public class E {
InputStream is;
PrintWriter out;... | #include <bits/stdc++.h>
using namespace std;
const int le = 20, ri = 21;
char z[] = "BRWY";
set<int> U;
int a[7][8], P[4][4], L[10], R[10], A[10], B[10], T = -1, p[22][22];
bool v[7][8], w[10][10], r2[7][8], d2[7][8], u[22];
char s[13][15], S[13][15];
void add(int x, int y) {
static int t = 0;
P[x][y] = P[y][x] = ... |
import sys
from collections import defaultdict as di
range = range
input = raw_input
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the lazy segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._... | #include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 35100;
int n, k;
long long tree[60][4 * maxn];
long long lazy[64][4 * maxn];
int tail[maxn];
void push_up(int st, int pos) {
tree[st][pos] = max(tree[st][pos << 1] + lazy[st][pos << 1],
tree[... |
import sys
from collections import deque
from bisect import bisect_left
input = sys.stdin.buffer.readline
N, K = map(int, input().split())
Ps = list(map(int, input().split()))
downs = []
for i in range(N-1):
if Ps[i+1] < Ps[i]:
downs.append(i)
if not downs:
print(1)
exit()
min_wait = deque()
max... | 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 Main {
static InputStream is;
static PrintWriter out;
static String INPUT = "";
static void solve()
{
int n = ... |
n, a, b = map(int, input().split())
ans = 0
for i in range(1, n+1):
if a <= sum(map(int, list(str(i)))) <= b:
ans += i
print(ans) | #include <iostream>
using namespace std;
int main(){
int n,a,b;
cin>>n>>a>>b;
int s=0;
for(int i=1; i<=n; i++){
int t=i,s1=0;
while(t!=0){
s1+=t%10;
t=t/10;
}
if(s1>=a && s1<=b){
s+=i;
}
}
cout<<s<<endl;
return 0;
} |
GetNetPeeringIdOk returns a tuple with the NetPeeringId field value if set, nil otherwise and a boolean to check if the value has been set. | func (o *CreateRouteRequest) GetNetPeeringIdOk() (*string, bool) {
if o == nil || o.NetPeeringId == nil {
return nil, false
}
return o.NetPeeringId, true
} |
WithAddr returns Option that sets addr | func WithAddr(addr string) Option {
return func(c *gatewayClient) {
if len(addr) != 0 {
c.addr = addr
}
}
} |
NewModExpr evaluates a % b, given two Numbers. | func NewModExpr(scanner parser.Scanner, a, b Expr) Expr {
return newArithExpr(scanner, a, b, "%%", func(a, b float64) float64 {
return math.Mod(a, b)
})
} |
Deprecated: Use Evidence.ProtoReflect.Descriptor instead. | func (*Evidence) Descriptor() ([]byte, []int) {
return file_tendermint_types_evidence_proto_rawDescGZIP(), []int{0}
} |
UnmarshalJSON supports json.Unmarshaler interface | func (v *Ingredient) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonD2b7633eDecodeBackendInternalModels8(&r, v)
return r.Error()
} |
AWSCloudFormationType returns the AWS CloudFormation resource type | func (r *AWSCodeDeployDeploymentGroup_AutoRollbackConfiguration) AWSCloudFormationType() string {
return "AWS::CodeDeploy::DeploymentGroup.AutoRollbackConfiguration"
} |
kubePutFn is entry point for `kube.put' callable. TODO(dmitryilyevskiy): Return Status object from the response as Starlark dict. | func (m *kubePackage) kubePutFn(t *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var name, namespace, apiGroup, subresource string
data := &starlark.List{}
unpacked := []interface{}{
"name", &name,
"data", &data,
"namespace?", &namespace,
// TOD... |
StringSliceContains returns if a string slice contains a particular string | func StringSliceContains(haystack []string, needle string) bool {
for _, str := range haystack {
if str == needle {
return true
}
}
return false
} |
wrapping struct: cel.Env export cel_Env_CTor | func cel_Env_CTor() CGoHandle {
return CGoHandle(handleFromPtr_cel_Env(&cel.Env{}))
} |
Transact invokes the (paid) contract method with params as input values. | func (_Hello *HelloTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _Hello.Contract.contract.Transact(opts, method, params...)
} |
Replace replaces all nonoverlapping matches of the left pattern of t with the results of applying the right pattern of t. | func (t *T) Replace(needle string) (string, error) {
var out strings.Builder
cur := 0
if err := t.Search(needle, func(start, end int, match string) error {
out.WriteString(needle[cur:start])
out.WriteString(match)
cur = end
return nil
}); err != nil {
return "", err
}
return out.String(), nil
} |
RunJSONSerializationTestForCacheExpirationActionParameters_STATUS runs a test to see if a specific instance of CacheExpirationActionParameters_STATUS round trips to JSON and back losslessly | func RunJSONSerializationTestForCacheExpirationActionParameters_STATUS(subject CacheExpirationActionParameters_STATUS) string {
// Serialize to JSON
bin, err := json.Marshal(subject)
if err != nil {
return err.Error()
}
// Deserialize back into memory
var actual CacheExpirationActionParameters_STATUS
err = js... |
ChangeAdmin is a paid mutator transaction binding the contract method 0x8f283970. Solidity: function changeAdmin(admin_ address) returns() | func (_EtherDelta *EtherDeltaTransactorSession) ChangeAdmin(admin_ common.Address) (*types.Transaction, error) {
return _EtherDelta.Contract.ChangeAdmin(&_EtherDelta.TransactOpts, admin_)
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.