submission_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 3 values | code stringlengths 1 522k | compiler_output stringlengths 43 10.2k |
|---|---|---|---|---|
s904468567 | p03776 | C++ | #include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using INT = mp::cpp_int;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount(bit) __builtin_popcount(bit)
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x))) //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x)) //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x)) //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
ll ctoi(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
return -1;
}
template <typename T>
string make_string(T N)
{
string ret;
T now = N;
while (now > 0)
{
T x = now % 10;
ret += (char)('0' + x);
now /= 10;
}
reverse(all(ret));
return ret;
}
template <typename T>
T gcd(T a, T b)
{
if (a % b == 0)
{
return (b);
}
else
{
return (gcd(b, a % b));
}
}
template <typename T>
T lcm(T x, T y)
{
T z = gcd(x, y);
return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
double sqrtn = sqrt(n);
for (T i = 3; i < sqrtn + 1; i++)
{
if (n % i == 0)
{
return false;
}
i++;
}
return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b; // aをbで更新
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b; // aをbで更新
return true;
}
return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
INT fact[301]; //fact[i]=(i!)
void COMinit()
{
INT now = 1;
fact[0] = 1;
for (long long i = 1; i < 301; i++)
{
now *= i;
fact[i] = now;
}
}
INT COM(INT n, INT r)
{
if (n < r)
return 0;
if (n < 0 || r < 0)
return 0;
if (n == r)
return 1;
if (r == 0)
return 1;
INT ans = fact[n];
ans /= fact[r];
ans /= fact[n - r];
return ans;
}
int main()
{
cout << fixed << setprecision(30);
ll N, A, B;
cin >> N >> A >> B;
vector<ll> v(N);
COMinit();
loop(i, N) cin >> v[i];
sort(all(v));
reverse(all(v));
double ans1 = 0;
loop(i, A) ans1 += v[i];
ans1 /= A;
putout(ans1);
/*
vから大きい順にA個取った集合をSとする
Sに異なる数が含まれる場合
A+1個以上取ると平均が減少してしまう
Sで最小の数をmとして、mがS内にa個、S外にb個あるとすると、
答えはCOM(a+b,a)
Sに異なる数が含まれない場合
その数が全体でX個あるとすると、
答えはCOM(X,A)+COM(X,A+1)+...COM(X,B)
(但しs<tならCOM(s,t)=0と仮定する)
*/
vector<INT> S(A);
loop(i, A) S[i] = v[i];
if (S[0] != S[A - 1])
{
INT a = 0, b = 0;
loop(i, A) if (S[i] == S[A - 1]) a++;
loop(i, N - A) if (v[A + i] == S[A - 1]) b++;
putout(COM(a + b, a));
return 0;
}
INT X = 0;
loop(i, N) if (v[i] == v[0]) X++;
INT ans = 0;
for (ll i = A; i <= B; i++)
ans += COM(X, i);
putout(ans);
return 0;
}
| a.cc:1:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
1 | #include <boost/multiprecision/cpp_int.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
|
s921980229 | p03776 | C++ | #include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using INT = mp::cpp_int;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount(bit) __builtin_popcount(bit)
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x))) //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x)) //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x)) //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
ll ctoi(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
return -1;
}
template <typename T>
string make_string(T N)
{
string ret;
T now = N;
while (now > 0)
{
T x = now % 10;
ret += (char)('0' + x);
now /= 10;
}
reverse(all(ret));
return ret;
}
template <typename T>
T gcd(T a, T b)
{
if (a % b == 0)
{
return (b);
}
else
{
return (gcd(b, a % b));
}
}
template <typename T>
T lcm(T x, T y)
{
T z = gcd(x, y);
return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
double sqrtn = sqrt(n);
for (T i = 3; i < sqrtn + 1; i++)
{
if (n % i == 0)
{
return false;
}
i++;
}
return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b; // aをbで更新
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b; // aをbで更新
return true;
}
return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
INT fact(301); //fact[i]=(i!)
void COMinit()
{
INT now = 1;
fact[0] = 1;
for (long long i = 1; i < 301; i++)
{
now *= i;
fact[i] = now;
}
}
INT COM(INT n, INT r)
{
if (n < r)
return 0;
if (n < 0 || r < 0)
return 0;
if (n == r)
return 1;
if (r == 0)
return 1;
INT ans = fact[n];
ans /= fact[r];
ans /= fact[n - r];
return ans;
}
int main()
{
cout << fixed << setprecision(30);
ll N, A, B;
cin >> N >> A >> B;
vector<ll> v(N);
COMinit();
loop(i, N) cin >> v[i];
sort(all(v));
reverse(all(v));
double ans1 = 0;
loop(i, A) ans1 += v[i];
ans1 /= A;
putout(ans1);
/*
vから大きい順にA個取った集合をSとする
Sに異なる数が含まれる場合
A+1個以上取ると平均が減少してしまう
Sで最小の数をmとして、mがS内にa個、S外にb個あるとすると、
答えはCOM(a+b,a)
Sに異なる数が含まれない場合
その数が全体でX個あるとすると、
答えはCOM(X,A)+COM(X,A+1)+...COM(X,B)
(但しs<tならCOM(s,t)=0と仮定する)
*/
vector<INT> S(A);
loop(i, A) S[i] = v[i];
if (S[0] != S[A - 1])
{
INT a = 0, b = 0;
loop(i, A) if (S[i] == S[A - 1]) a++;
loop(i, N - A) if (v[A + i] == S[A - 1]) b++;
putout(COM(a + b, a));
return 0;
}
INT X = 0;
loop(i, N) if (v[i] == v[0]) X++;
INT ans = 0;
for (ll i = A; i <= B; i++)
ans += COM(X, i);
putout(ans);
return 0;
}
| a.cc:1:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
1 | #include <boost/multiprecision/cpp_int.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
|
s760897696 | p03776 | C++ | #include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using INT = mp::cpp_int;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount(bit) __builtin_popcount(bit)
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x))) //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x)) //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x)) //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
ll ctoi(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
return -1;
}
template <typename T>
string make_string(T N)
{
string ret;
T now = N;
while (now > 0)
{
T x = now % 10;
ret += (char)('0' + x);
now /= 10;
}
reverse(all(ret));
return ret;
}
template <typename T>
T gcd(T a, T b)
{
if (a % b == 0)
{
return (b);
}
else
{
return (gcd(b, a % b));
}
}
template <typename T>
T lcm(T x, T y)
{
T z = gcd(x, y);
return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
double sqrtn = sqrt(n);
for (T i = 3; i < sqrtn + 1; i++)
{
if (n % i == 0)
{
return false;
}
i++;
}
return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b; // aをbで更新
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b; // aをbで更新
return true;
}
return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
vector<INT> fact(301); //fact[i]=(i!)
void COMinit()
{
INT now = 1;
fact[0] = 1;
for (long long i = 1; i < 301; i++)
{
now *= i;
fact[i] = now;
}
}
INT COM(INT n, INT r)
{
if (n < r)
return 0;
if (n < 0 || r < 0)
return 0;
if (n == r)
return 1;
if (r == 0)
return 1;
INT ans = fact[n];
ans /= fact[r];
ans /= fact[n - r];
return ans;
}
int main()
{
cout << fixed << setprecision(30);
ll N, A, B;
cin >> N >> A >> B;
vector<ll> v(N);
COMinit();
loop(i, N) cin >> v[i];
sort(all(v));
reverse(all(v));
double ans1 = 0;
loop(i, A) ans1 += v[i];
ans1 /= A;
putout(ans1);
/*
vから大きい順にA個取った集合をSとする
Sに異なる数が含まれる場合
A+1個以上取ると平均が減少してしまう
Sで最小の数をmとして、mがS内にa個、S外にb個あるとすると、
答えはCOM(a+b,a)
Sに異なる数が含まれない場合
その数が全体でX個あるとすると、
答えはCOM(X,A)+COM(X,A+1)+...COM(X,B)
(但しs<tならCOM(s,t)=0と仮定する)
*/
vector<INT> S(A);
loop(i, A) S[i] = v[i];
if (S[0] != S[A - 1])
{
INT a = 0, b = 0;
loop(i, A) if (S[i] == S[A - 1]) a++;
loop(i, N - A) if (v[A + i] == S[A - 1]) b++;
putout(COM(a + b, a));
return 0;
}
INT X = 0;
loop(i, N) if (v[i] == v[0]) X++;
INT ans = 0;
for (ll i = A; i <= B; i++)
ans += COM(X, i);
putout(ans);
return 0;
}
| a.cc:1:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
1 | #include <boost/multiprecision/cpp_int.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
|
s855447739 | p03776 | C++ | #include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using INT = mp::cpp_int;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount(bit) __builtin_popcount(bit)
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x))) //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x)) //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x)) //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
ll ctoi(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
return -1;
}
template <typename T>
string make_string(T N)
{
string ret;
T now = N;
while (now > 0)
{
T x = now % 10;
ret += (char)('0' + x);
now /= 10;
}
reverse(all(ret));
return ret;
}
template <typename T>
T gcd(T a, T b)
{
if (a % b == 0)
{
return (b);
}
else
{
return (gcd(b, a % b));
}
}
template <typename T>
T lcm(T x, T y)
{
T z = gcd(x, y);
return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
double sqrtn = sqrt(n);
for (T i = 3; i < sqrtn + 1; i++)
{
if (n % i == 0)
{
return false;
}
i++;
}
return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b; // aをbで更新
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b; // aをbで更新
return true;
}
return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
vector<INT> fact(301); //fact[i]=(i!)
void COMinit()
{
INT now = 1;
fact[0] = 1;
for (INT i = 1; i < 301; i++)
{
now *= i;
fact[i] = now;
}
}
INT COM(INT n, INT r)
{
if (n < r)
return 0;
if (n < 0 || r < 0)
return 0;
if (n == r)
return 1;
if (r == 0)
return 1;
INT ans = fact[n];
ans /= fact[r];
ans /= fact[n - r];
return ans;
}
int main()
{
cout << fixed << setprecision(30);
ll N, A, B;
cin >> N >> A >> B;
vector<ll> v(N);
COMinit();
loop(i, N) cin >> v[i];
sort(all(v));
reverse(all(v));
double ans1 = 0;
loop(i, A) ans1 += v[i];
ans1 /= A;
putout(ans1);
/*
vから大きい順にA個取った集合をSとする
Sに異なる数が含まれる場合
A+1個以上取ると平均が減少してしまう
Sで最小の数をmとして、mがS内にa個、S外にb個あるとすると、
答えはCOM(a+b,a)
Sに異なる数が含まれない場合
その数が全体でX個あるとすると、
答えはCOM(X,A)+COM(X,A+1)+...COM(X,B)
(但しs<tならCOM(s,t)=0と仮定する)
*/
vector<INT> S(A);
loop(i, A) S[i] = v[i];
if (S[0] != S[A - 1])
{
INT a = 0, b = 0;
loop(i, A) if (S[i] == S[A - 1]) a++;
loop(i, N - A) if (v[A + i] == S[A - 1]) b++;
putout(COM(a + b, a));
return 0;
}
INT X = 0;
loop(i, N) if (v[i] == v[0]) X++;
INT ans = 0;
for (ll i = A; i <= B; i++)
ans += COM(X, i);
putout(ans);
return 0;
}
| a.cc:1:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
1 | #include <boost/multiprecision/cpp_int.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
|
s433012865 | p03776 | C++ | #include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#include<queue>
#include<math.h>
#include<deque>
using namespace std;
#define double long double
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define dc(d) double d;cin>>d;
#define mod 1777777777
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define pi 3.141592653589793238462643383279
#define e_ 2.718281828459045235360287471352
#define P pair<int,int>
#define upp(a,n,x) upper_bound(a,a+n,x)-a;
#define low(a,n,x) lower_bound(a,a+n,x)-a;
#define UF UnionFind
//printf("%.12Lf\n",);
int keta(int x) {
rep(0, i, 30) {
if (x < 10) {
return i + 1;
}
x = x / 10;
}
}
int gcd(int x, int y) {
if (x == 0 || y == 0)return x + y;
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return bb;
}
bb = bb % aa;
if (bb == 0) {
return aa;
}
}
}
int lcm(int x, int y) {
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return x / bb * y;
}
bb = bb % aa;
if (bb == 0) {
return x / aa * y;
}
}
}
int integer(double d){
return long(d);
}
int distance(double a,double b,double c,double d){
return sqrt((b-a)*(b-a)+(c-d)*(c-d));
}
bool p(int x) {
if (x == 1)return false;
rep(2, i, sqrt(x) + 1) {
if (x % i == 0 && x != i) {
return false;
}
}
return true;
}
int max(int a, int b) {
if (a >= b)return a;
else return b;
}
string maxst(string s, string t) {
int n = s.size();
int m = t.size();
if (n > m)return s;
else if (n < m)return t;
else {
rep(0, i, n) {
if (s[i] > t[i])return s;
if (s[i] < t[i])return t;
}
return s;
}
}
int min(int a, int b) {
if (a >= b)return b;
else return a;
}
int n2[41];
int nis[41];
int nia[41];
int mody[41];
int nn;
int com(int n, int y) {
int ni = 1;
for (int i = 0;i < 41;i++) {
n2[i] = ni;
ni *= 2;
}
int bunsi = 1, bunbo = 1;
rep(0, i, y)bunsi = (bunsi * (n - i)) % mod;
rep(0, i, y)bunbo = (bunbo * (i + 1)) % mod;
mody[0] = bunbo;
rep(1, i, 41) {
bunbo = (bunbo * bunbo) % mod;
mody[i] = bunbo;
}
rep(0, i, 41)nis[i] = 0;
nn = mod - 2;
for (int i = 40;i >= 0;i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
bunsi = (bunsi * mody[i]) % mod;
}
}
return bunsi;
}
int newcom(int n,int y){
int bunsi = 1, bunbo = 1;
rep(0, i, y){
bunsi = (bunsi * (n - i)) ;
bunbo = (bunbo * (i + 1)) ;
int k=gcd(bunsi,bunbo);
bunsi/=k;
bunbo/=k;
}
return bunsi/bunbo;
}
int gyakugen(int n, int y) {
int ni = 1;
for (int i = 0;i < 41;i++) {
n2[i] = ni;
ni *= 2;
}
mody[0] = y;
rep(1, i, 41) {
y = (y * y) % mod;
mody[i] = y;
}
rep(0, i, 41)nis[i] = 0;
nn = mod - 2;
for (int i = 40;i >= 0;i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
n = (n * mody[i]) % mod;
}
}
return n;
}
int yakuwa(int n) {
int sum = 0;
rep(1, i, sqrt(n + 1)) {
if (n % i == 0)sum += i + n / i;
if (i * i == n)sum -= i;
}
return sum;
}
int poow(int y, int n) {
if (n == 0)return 1;
n -= 1;
int ni = 1;
for (int i = 0;i < 41;i++) {
n2[i] = ni;
ni *= 2;
}
int yy = y;
mody[0] = yy;
rep(1, i, 41) {
yy = (yy * yy) % mod;
mody[i] = yy;
}
rep(0, i, 41)nis[i] = 0;
nn = n;
for (int i = 40;i >= 0;i -= 1) {
if (nn >= n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
rep(0, i, 41) {
if (nis[i] == 1) {
y = (y * mody[i]) % mod;
}
}
return y;
}
int minpow(int x, int y) {
int sum = 1;
rep(0, i, y)sum *= x;
return sum;
}
int ketawa(int x, int sinsuu) {
int sum = 0;
rep(0, i, 100)sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i));
return sum;
}
int sankaku(int a) {
if(a%2==0) return a /2*(a+1);
else return (a+1)/2*a;
}
int sames(int a[1111111], int n) {
int ans = 0;
rep(0, i, n) {
if (a[i] == a[i + 1]) {
int j = i;
while (a[j + 1] == a[i] && j <= n - 2)j++;
ans += sankaku(j - i);
i = j;
}
}
return ans;
}
using Graph = vector<vector<int>>;
int oya[114514];
int depth[114514];
void dfs(const Graph& G, int v, int p, int d) {
depth[v] = d;
oya[v] = p;
for (auto nv : G[v]) {
if (nv == p) continue; // nv が親 p だったらダメ
dfs(G, nv, v, d + 1); // d を 1 増やして子ノードへ
}
}
/*int H=10,W=10;
char field[10][10];
char memo[10][10];
void dfs(int h, int w) {
memo[h][w] = 'x';
// 八方向を探索
for (int dh = -1; dh <= 1; ++dh) {
for (int dw = -1; dw <= 1; ++dw) {
if(abs(0-dh)+abs(0-dw)==2)continue;
int nh = h + dh, nw = w + dw;
// 場外アウトしたり、0 だったりはスルー
if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
if (memo[nh][nw] == 'x') continue;
// 再帰的に探索
dfs(nh, nw);
}
}
}*/
int XOR(int a, int b) {
if (a == 0 || b == 0) {
return a + b;
}
int ni = 1;
rep(0, i, 41) {
n2[i] = ni;
ni *= 2;
}
rep(0, i, 41)nis[i] = 0;
for (int i = 40;i >= 0;i -= 1) {
if (a >= n2[i]) {
nis[i]++;
a -= n2[i];
}
if (b >= n2[i]) {
nis[i]++;
b -= n2[i];
}
}
int sum = 0;
rep(0, i, 41)sum += (nis[i] % 2 * n2[i]);
return sum;
}
//int ma[1024577][21];
//for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1;
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
for (int i = 0; i < N; i++) par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); //xの根をrx
int ry = root(y); //yの根をry
if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
double v[55];
vector<P> kos;
signed main(){
ic(n) dc(a) dc(b)
rep(0,i,n)cin>>v[i];
sort(v,v+n);
reverse(v,v+n);
double ave=0;
double sum=0;
rep(0,i,a){
ave+=v[i];
sum+=v[i];
}
ave/=a;
printf("%.25Lf\n",ave);
int ans=0;
rep(a,i,b+1){
int l,r=i-1;
while(v[i-1]==v[l]&&l>=0){
l-=1;
}
l++;
while(v[i-1]==v[r]&&r<=n-1){
r++;
}
r-=1;
ans+=newcom(r-l+1,r-i+1);
if(v[min(n-1,i)]!=v[a-1]){
break;
}
}
c(ans)
}
| a.cc: In function 'int main()':
a.cc:348:36: error: invalid types 'long double [55][long double]' for array subscript
348 | if(v[min(n-1,i)]!=v[a-1]){
| ^
a.cc: In function 'long long int keta(long long int)':
a.cc:38:1: warning: control reaches end of non-void function [-Wreturn-type]
38 | }
| ^
a.cc: In function 'long long int gcd(long long int, long long int)':
a.cc:52:1: warning: control reaches end of non-void function [-Wreturn-type]
52 | }
| ^
a.cc: In function 'long long int lcm(long long int, long long int)':
a.cc:65:1: warning: control reaches end of non-void function [-Wreturn-type]
65 | }
| ^
|
s904586582 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll v[100];
ll KK1(ll n, ll r)
{
ll C[r+1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (ll i = 1; i <= n; i++)
{
for (ll j = min(i, r); j > 0; j--)
C[j] = (C[j] + C[j-1]);
}
return C[r];
}
/*
ll KK2(ll n, ll m)
{
ll ans=1;
for(int i=1;i<=m;i++)
{
ans=ans/i*(n-m+i);
}
return ans;
}
*/
int main()
{
ll tot=0;
long double ans=0,sum=0,cnt=0;
map<ll,int>N,R;
int n,a,b;
cin>>n>>a>>b;
for(int i=0; i<n; i++){
cin>>v[i];
N[v[i]]++;
}
sort(arr,arr+n);
ll last ;
last = v[n-1];
for(int i=n-1; i>=0; i--)
{
sum+=v[i];
R[v[i]]++;
cnt++;
if(cnt>b) break;
if(cnt==a) ans=sum/cnt;
if(cnt>=a)
{
if(cnt==a)
tot+=KK1(N[v[i]],R[v[i]]);
else if(v[i]==last) tot+=KK1(N[v[i]],R[v[i]]);
}
}
cout<<setprecision(18)<<fixed<<ans<<endl;
cout<<tot<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:39:10: error: 'arr' was not declared in this scope
39 | sort(arr,arr+n);
| ^~~
|
s008877377 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll v[100];
ll KK1(ll n, ll r)
{
ll C[r+1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (ll i = 1; i <= n; i++)
{
for (ll j = min(i, r); j > 0; j--)
C[j] = (C[j] + C[j-1]);
}
return C[r];
}
/*
ll KK2(ll n, ll m)
{
ll ans=1;
for(int i=1;i<=m;i++)
{
ans=ans/i*(n-m+i);
}
return ans;
}
*/
int main()
{
ll tot=0;
long double ans=0,sum=0,cnt=0;
map<ll,int>N,R;
int n,a,b;
cin>>n>>a>>b;
for(int i=0; i<n; i++){
cin>>v[i];
N[v[i]]++;
}
sort(arr,arr+n);
ll last ;
last = v[n-1];
for(int i=n-1; i>=0; i--)
{
sum+=v[i];
R[v[i]]++;
cnt++;
if(cnt>b) break;
if(cnt==a) ans=sum/cnt;
if(cnt>=a)
{
// if(cnt==a)
tot+=KK1(N[v[i]],R[v[i]]);
//else if(v[i]==last) tot+=KK1(N[v[i]],R[v[i]]);
}
}
cout<<setprecision(18)<<fixed<<ans<<endl;
cout<<tot<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:39:10: error: 'arr' was not declared in this scope
39 | sort(arr,arr+n);
| ^~~
|
s846158498 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll arr[120];
ll nCr(ll n, ll r)
{
ll C[r+1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (ll i = 1; i <= n; i++)
{
for (ll j = min(i, r); j > 0; j--)
C[j] = (C[j] + C[j-1]);
}
return C[r];
}
int main()
{
//cout<<nCr(5,2)<<"\\\\\\\\\\\\\\\\\\\\"<<endl;
ll tot=0;
long double ans=0,sum=0,cnt=0;
map<ll,int>N,R;
int n,a,b;
cin>>n>>a>>b;
for(int i=0; i<n; i++){
cin>>arr[i];
N[arr[i]]++;
}
sort(arr,arr+n);
ll last ;
for(int i=n-1; i>=0; i--)
{
sum+=arr[i];
R[arr[i]]++;
cnt++;
if(cnt>b)
break;
if(cnt==a)
{
last = arr[n-1];
ans=sum/cnt;
}
if(cnt>=a)
{
long double cur=(sum/cnt);
if(cnt==a)
{tot+=nCr(N[arr[i]],R[arr[i]]);
}
}
cout<<setprecision(18)<<fixed<<ans<<endl;
cout<<tot<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:64:6: error: expected '}' at end of input
64 | }
| ^
a.cc:28:5: note: to match this '{'
28 | {
| ^
|
s156372334 | p03776 | C++ | v#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a,b;
cin>>n>>a>>b;
long long v[n];
for(int i=0;i<n;i++){
cin>>v[i];
}
sort(v,v+n,greater<long long>());
long long m=0;
for(int i=0;i<a;i++)m+=v[i];
cout<<m/a<<".";
m%=a;
m*=1000000000;
cout<<m/a<<endl;
a--,b--;
int l=lower_bound(v,v+n,v[a],greater<long long>())-v,r=upper_bound(v,v+n,v[a],greater<long long>())-v;
int vali=r-l;
long long c[vali+1];//combination
//MAX = 50 C 25 < 1.3*10^14
long long wa[vali+1];
c[0]=1;
wa[0]=1;
for(int i=1;i<=vali;i++){
c[i]=c[i-1]*(vali-i+1)/i;
wa[i]=wa[i-1]+c[i];
}
if(v[a]==v[b]){//vali C a+1~b
if(a==l)cout<<wa[b-l]<<endl;
else cout<<wa[b-l]-wa[a-l]<<endl;
}
else{//vali C a+1~vali
if(a==l)cout<<wa[vali]<<endl;
else cout<<wa[vali]-wa[a-l]<<endl;
}
return 0;
}
| a.cc:1:3: error: stray '#' in program
1 | v#include<bits/stdc++.h>
| ^
a.cc:1:1: error: '\U0000ff56' does not name a type
1 | v#include<bits/stdc++.h>
| ^~
a.cc: In function 'int main()':
a.cc:5:5: error: 'cin' was not declared in this scope
5 | cin>>n>>a>>b;
| ^~~
a.cc:10:16: error: 'greater' was not declared in this scope
10 | sort(v,v+n,greater<long long>());
| ^~~~~~~
a.cc:10:24: error: expected primary-expression before 'long'
10 | sort(v,v+n,greater<long long>());
| ^~~~
a.cc:10:5: error: 'sort' was not declared in this scope; did you mean 'short'?
10 | sort(v,v+n,greater<long long>());
| ^~~~
| short
a.cc:13:5: error: 'cout' was not declared in this scope
13 | cout<<m/a<<".";
| ^~~~
a.cc:16:16: error: 'endl' was not declared in this scope
16 | cout<<m/a<<endl;
| ^~~~
a.cc:18:42: error: expected primary-expression before 'long'
18 | int l=lower_bound(v,v+n,v[a],greater<long long>())-v,r=upper_bound(v,v+n,v[a],greater<long long>())-v;
| ^~~~
a.cc:18:11: error: 'lower_bound' was not declared in this scope
18 | int l=lower_bound(v,v+n,v[a],greater<long long>())-v,r=upper_bound(v,v+n,v[a],greater<long long>())-v;
| ^~~~~~~~~~~
a.cc:19:14: error: 'r' was not declared in this scope
19 | int vali=r-l;
| ^
|
s041553421 | p03776 | C++ | #include <cstdio>
#include <queue>
using namespace std;
long long fact(int x){
if(x==0)return 1ll;
return fact(x-1)*x;
}
long long comb(int x, int y){
long long ret=1ll;
for(int i = 1;i <= y;i ++){
ret=ret*(x+1-i)/i;
}
return ret;
}
int main(){
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
vector <long long> v(n);
for(auto&i:v)
scanf("%lld", &i);
sort(v.begin(), v.end());
long double sum=0.0l;
for(int i = n;i > n-a;i --){
sum+=v[i-1];
}
printf("%.10Lf\n", sum/a);
if(v[n-a]!=v[n-1]){//must pick a
printf("%lld\n", comb(count(v.begin(), v.end(), v[n-a]),count(v.begin()+(n-a), v.end(), v[n-a])));
}else{//can pick any number
long long ans=0ll;
for(int i = a;i <= b;i ++){
if(v[n-i]!=v[n-1])
break;
ans+=comb(count(v.begin(), v.end(), v.back()), i);
}
printf("%lld\n", ans);
}
} | a.cc: In function 'int main()':
a.cc:22:9: error: 'sort' was not declared in this scope; did you mean 'short'?
22 | sort(v.begin(), v.end());
| ^~~~
| short
a.cc:29:39: error: 'count' was not declared in this scope
29 | printf("%lld\n", comb(count(v.begin(), v.end(), v[n-a]),count(v.begin()+(n-a), v.end(), v[n-a])));
| ^~~~~
a.cc:35:35: error: 'count' was not declared in this scope
35 | ans+=comb(count(v.begin(), v.end(), v.back()), i);
| ^~~~~
|
s919554644 | p03776 | C++ | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
enum { };
unordered_map<ll,ll> f, fs;
ll ncr(ll n, ll r) {
ll ans = 1;
for (ll i = n; i > max(r, n-r); i--) {
ans *= i;
}
for (ll i = 2; i <= min(r, n-r); i++) {
ans /= i;
}
return ans;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.precision(20);
ll n, a, b; cin >> n >> a >> b;
vector<ll> arr(n);
for (ll i = 0; i < n; i++) {
cin >> arr[i];
f[arr[i]]++;
}
sort(arr.rbegin(), arr.rend());
ll sum = 0, cnt = 0;
for (ll i = 0; i < a; i++) {
sum += arr[i];
fs[arr[i]]++;
cnt++;
}
for (ll i = a; i < b; i++) {
if ((sum + arr[i]) * cnt > sum * (cnt+1)) {
sum += arr[i];
fs[arr[i]]++;
cnt++;
}
}
ll ans = 1;
for (auto fi : fs) {
ans *= ncr(f[fi.first], fi.second);
}
cout << sum / ld(cnt) << endl << ans << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:44:23: error: 'ld' was not declared in this scope; did you mean 'll'?
44 | cout << sum / ld(cnt) << endl << ans << endl;
| ^~
| ll
|
s814035341 | p03776 | C++ | #include <numeric>
#include <bits/stdc++.h>
using namespace std;
// Combination Table
long long C[51][51]; // C[n][k] -> nCk
void comb_table(int N){
for(int i=0;i<=N;++i){
for(int j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1LL;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}}}}
int main(){
cout << fixed << setprecision(8);
int N,A,counter=0;
int B;
cin>>N>>A>>B;
comb_table(N);
double AA=A;
long long counter1=0;
long long counter2=0;
long long answer=0;
long long counter3=1;
vector<long long>vec(N);
for(int i=0;i<N;i++){
cin>>vec.at(i);}
sort(vec.begin(),vec.end());
reverse(vec.begin(), vec.end());
for(int i=0;i<A;i++){
counter+=vec.at(i);}
double a=counter/AA;
cout<<a<<endl;
for(int i=0;i<N;i++){
if(vec.at(i)==vec.at(A-1))
counter1++;
else if(vec.at(i)>vec.at(A-1))
counter2++;}
long long d=min(counter1,B);
if(counter2>0){
answer+=C[counter1][A-counter2];
cout<<answer<<endl;}
else{
for(int j=A-counter2;j<=d;j++){
answer+=C[counter1][j];}
cout<<answer<<endl;}}
| a.cc: In function 'int main()':
a.cc:40:16: error: no matching function for call to 'min(long long int&, int&)'
40 | long long d=min(counter1,B);
| ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:40:16: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
40 | long long d=min(counter1,B);
| ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:40:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
40 | long long d=min(counter1,B);
| ~~~^~~~~~~~~~~~
|
s016899921 | p03776 | C++ | #include <numeric>
#include <bits/stdc++.h>
using namespace std;
// Combination Table
int C[51][51]; // C[n][k] -> nCk
void comb_table(int N){
for(int i=0;i<=N;++i){
for(int j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1LL;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}}}}
int main(){
cout << fixed << setprecision(8);
int N,A,counter=0;
int B;
cin>>N>>A>>B;
comb_table(N);
double AA=A;
int counter1=0;
int counter2=0;
long long answer=0;
long long counter3=1;
vector<long long>vec(N);
for(int i=0;i<N;i++){
cin>>vec.at(i);}
sort(vec.begin(),vec.end());
reverse(vec.begin(), vec.end());
for(int i=0;i<A;i++){
counter+=vec.at(i);}
double a=counter/AA;
cout<<a<<endl;
for(int i=0;i<N;i++){
if(vec.at(i)==vec.at(A-1))
counter1++;
else if(vec.at(i)>vec.at(A-1))
counter2++;}
int d=min(counter1,B);
if(counter2>0){
answer+=C[counter1][A-counter2];
cout<<answer<<endl;}
else{
for(int j=A-counter2;j<=d;j++){
answer+=[counter1][j];}}
cout<<answer<<endl;}
| a.cc: In lambda function:
a.cc:46:19: error: expected '{' before '[' token
46 | answer+=[counter1][j];}}
| ^
a.cc: In function 'int main()':
a.cc:46:19: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'int')
|
s615773337 | p03776 | C++ | #include <numeric>
#include <bits/stdc++.h>
using namespace std;
// Combination Table
long long C[51][51]; // C[n][k] -> nCk
void comb_table(long long N){
for(long long i=0;i<=N;++i){
for(long long j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1LL;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}}}}
long long main(){
cout << fixed << setprecision(8);
long long N,A,counter=0;
long long B;
cin>>N>>A>>B;
comb_table(N);
double AA=A;
long long counter1=0;
long long counter2=0;
long long answer=0;
long long counter3=1;
vector<long long>vec(N);
long long ves[60];
ves[0]=1;
for(long long i=1;i<=50;i++){
ves[i]=i*ves[i-1];}
for(long long i=0;i<N;i++){
cin>>vec.at(i);}
sort(vec.begin(),vec.end());
reverse(vec.begin(), vec.end());
for(long long i=0;i<A;i++){
counter+=vec.at(i);}
double a=counter/AA;
cout<<a<<endl;
for(long long i=0;i<N;i++){
if(vec.at(i)==vec.at(A-1))
counter1++;
else if(vec.at(i)>vec.at(A-1))
counter2++;}
long long d=min(counter1,B);
if(counter2>0){
answer+=C[counter1][A-counter2];
cout<<answer<<endl;}
else{
for(long long j=A-counter2;j<=d;j++){
answer+=[counter1][j];}}
cout<<answer<<endl;}
| cc1plus: error: '::main' must return 'int'
a.cc: In lambda function:
a.cc:50:19: error: expected '{' before '[' token
50 | answer+=[counter1][j];}}
| ^
a.cc: In function 'int main()':
a.cc:50:19: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'long long int')
|
s072556954 | p03776 | C++ | #include <numeric>
#include <bits/stdc++.h>
using namespace std;
// Combination Table
long long C[51][51]; // C[n][k] -> nCk
void comb_table(int K){
for(int i=0;i<=K;++i){
for(int j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1LL;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}}}}
int main(){
comb_table();
cout << fixed << setprecision(8);
long long N,A,counter=0;
long long B;
cin>>N>>A>>B;
double AA=A;
long long counter1=0;
long long counter2=0;
long long answer=0;
long long counter3=1;
vector<long long>vec(N);
long long ves[60];
ves[0]=1;
for(long long i=1;i<=50;i++){
ves[i]=i*ves[i-1];}
for(long long i=0;i<N;i++){
cin>>vec.at(i);}
sort(vec.begin(),vec.end());
reverse(vec.begin(), vec.end());
for(long long i=0;i<A;i++){
counter+=vec.at(i);}
double a=counter/AA;
cout<<a<<endl;
for(long long i=0;i<N;i++){
if(vec.at(i)==vec.at(A-1))
counter1++;
else if(vec.at(i)>vec.at(A-1))
counter2++;}
long long d=min(counter1,B);
if(counter2>0){
answer+=C[counter1][A-counter2];
cout<<answer<<endl;}
else{
for(long long j=A-counter2;j<=d;j++){
answer+=[counter1][j];}}
cout<<answer<<endl;}
| a.cc: In function 'int main()':
a.cc:16:11: error: too few arguments to function 'void comb_table(int)'
16 | comb_table();
| ~~~~~~~~~~^~
a.cc:7:6: note: declared here
7 | void comb_table(int K){
| ^~~~~~~~~~
a.cc: In lambda function:
a.cc:50:19: error: expected '{' before '[' token
50 | answer+=[counter1][j];}}
| ^
a.cc: In function 'int main()':
a.cc:50:19: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'long long int')
|
s367022847 | p03776 | C++ | #include <numeric>
#include <bits/stdc++.h>
using namespace std;
// Combination Table
long long C[51][51]; // C[n][k] -> nCk
void comb_table(int K){
for(int i=0;i<=K;++i){
for(int j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1LL;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}}}}
int main(void){
cout << fixed << setprecision(8);
long long N,A,counter=0;
long long B;
cin>>N>>A>>B;
double AA=A;
long long counter1=0;
long long counter2=0;
long long answer=0;
long long counter3=1;
vector<long long>vec(N);
long long ves[60];
ves[0]=1;
for(long long i=1;i<=50;i++){
ves[i]=i*ves[i-1];}
for(long long i=0;i<N;i++){
cin>>vec.at(i);}
sort(vec.begin(),vec.end());
reverse(vec.begin(), vec.end());
for(long long i=0;i<A;i++){
counter+=vec.at(i);}
double a=counter/AA;
cout<<a<<endl;
for(long long i=0;i<N;i++){
if(vec.at(i)==vec.at(A-1))
counter1++;
else if(vec.at(i)>vec.at(A-1))
counter2++;}
long long d=min(counter1,B);
if(counter2>0){
answer+=C[counter1][A-counter2];
cout<<answer<<endl;}
else{
for(long long j=A-counter2;j<=d;j++){
answer+=[counter1][j];}}
cout<<answer<<endl;}
| a.cc: In lambda function:
a.cc:49:19: error: expected '{' before '[' token
49 | answer+=[counter1][j];}}
| ^
a.cc: In function 'int main()':
a.cc:49:19: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'long long int')
|
s636283090 | p03776 | C++ | #include <numeric>
#include <bits/stdc++.h>
using namespace std;
// Combination Table
long long C[51][51]; // C[n][k] -> nCk
void comb_table(int K){
for(int i=0;i<=K;++i){
for(int j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1LL;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}}}}
int main(void){
cout << fixed << setprecision(8);
long long N,A,counter=0;
long long B;
cin>>N>>A>>B;
double AA=A;
long long counter1=0;
long long counter2=0;
long long answer=0;
long long counter3=1;
vector<long long>vec(N);
long long ves[60];
ves[0]=1;
for(long long i=1;i<=50;i++){
ves[i]=i*ves[i-1];}
for(long long i=0;i<N;i++){
cin>>vec.at(i);}
sort(vec.begin(),vec.end());
reverse(vec.begin(), vec.end());
for(long long i=0;i<A;i++){
counter+=vec.at(i);}
double a=counter/AA;
cout<<a<<endl;
for(long long i=0;i<N;i++){
if(vec.at(i)==vec.at(A-1))
counter1++;
else if(vec.at(i)>vec.at(A-1))
counter2++;}
long long d=min(counter1,B);
if(counter2>0){
answer+=C[counter1][A-counter2];
cout<<answer<<endl;}
else{
for(long long j=A-counter2;j<=d;j++){
answer+=[counter1][j];}
cout<<answer<<endl;}}
| a.cc: In lambda function:
a.cc:49:19: error: expected '{' before '[' token
49 | answer+=[counter1][j];}
| ^
a.cc: In function 'int main()':
a.cc:49:19: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'long long int')
|
s041627056 | p03776 | C++ | #include <numeric>
#include <bits/stdc++.h>
using namespace std;
// Combination Table
long long C[51][51]; // C[n][k] -> nCk
void comb_table(int K){
for(int i=0;i<=K;++i){
for(int j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1LL;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}}}}
int main(void){
cout << fixed << setprecision(8);
long long N,A,counter=0;
long long B;
cin>>N>>A>>B;
double AA=A;
long long counter1=0;
long long counter2=0;
long long answer=0;
long long counter3=1;
vector<long long>vec(N);
long long ves[60];
ves[0]=1;
for(long long i=1;i<=50;i++){
ves[i]=i*ves[i-1];}
for(long long i=0;i<N;i++){
cin>>vec.at(i);}
sort(vec.begin(),vec.end());
reverse(vec.begin(), vec.end());
for(long long i=0;i<A;i++){
counter+=vec.at(i);}
double a=counter/AA;
cout<<a<<endl;
for(long long i=0;i<N;i++){
if(vec.at(i)==vec.at(A-1))
counter1++;
else if(vec.at(i)>vec.at(A-1))
counter2++;}
long long d=min(counter1,B);
if(counter2>0){
answer+=C[counter1][A-counter2];
cout<<answer<<endl;}
else{
for(int j=A-counter2;j<=d;j++){
answer+=[counter1][j];}
cout<<answer<<endl;}}
| a.cc: In lambda function:
a.cc:49:19: error: expected '{' before '[' token
49 | answer+=[counter1][j];}
| ^
a.cc: In function 'int main()':
a.cc:49:19: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'int')
|
s494958593 | p03776 | C++ | #include <numeric>
#include <bits/stdc++.h>
using namespace std;
// Combination Table
long long C[51][51]; // C[n][k] -> nCk
void comb_table(int K){
for(int i=0;i<=K;++i){
for(int j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1LL;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}}}}
int main(void){
cout << fixed << setprecision(8);
long long N,A,counter=0;
long long B;
cin>>N>>A>>B;
double AA=A;
long long counter1=0;
long long counter2=0;
long long answer=0;
long long counter3=1;
vector<long long>vec(N);
long long ves[60];
ves[0]=1;
for(long long i=1;i<=50;i++){
ves[i]=i*ves[i-1];}
for(long long i=0;i<N;i++){
cin>>vec.at(i);}
sort(vec.begin(),vec.end());
reverse(vec.begin(), vec.end());
for(long long i=0;i<A;i++){
counter+=vec.at(i);}
double a=counter/AA;
cout<<a<<endl;
for(long long i=0;i<N;i++){
if(vec.at(i)==vec.at(A-1))
counter1++;
else if(vec.at(i)>vec.at(A-1))
counter2++;}
long long d=min(counter1,B);
if(counter2>0){
answer+=C[counter1][A-counter2];
cout<<answer<<endl;}
else{
for(int j=A-counter2;j<=d;j++){
answer+=[counter1][i];}
cout<<answer<<endl;}}
| a.cc: In lambda function:
a.cc:49:19: error: expected '{' before '[' token
49 | answer+=[counter1][i];}
| ^
a.cc: In function 'int main()':
a.cc:49:20: error: 'i' was not declared in this scope
49 | answer+=[counter1][i];}
| ^
|
s582620446 | p03776 | C++ | #include <numeric>
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
2 using R=double;
3
4 // Combination Table
5 ll C[51][51]; // C[n][k] -> nCk
void comb_table(int N){
8 for(int i=0;i<=N;++i){
9 for(int j=0;j<=i;++j){
10 if(j==0 or j==i){
11 C[i][j]=1LL;
12 }else{
13 C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}}}}
int main(){
cout << fixed << setprecision(8);
long long N,A,counter=0;
long long B;
cin>>N>>A>>B;
double AA=A;
long long counter1=0;
long long counter2=0;
long long answer=0;
long long counter3=1;
vector<long long>vec(N);
long long ves[60];
ves[0]=1;
for(long long i=1;i<=50;i++){
ves[i]=i*ves[i-1];}
for(long long i=0;i<N;i++){
cin>>vec.at(i);}
sort(vec.begin(),vec.end());
reverse(vec.begin(), vec.end());
for(long long i=0;i<A;i++){
counter+=vec.at(i);}
double a=counter/AA;
cout<<a<<endl;
for(long long i=0;i<N;i++){
if(vec.at(i)==vec.at(A-1))
counter1++;
else if(vec.at(i)>vec.at(A-1))
counter2++;}
long long d=min(counter1,B);
if(counter2>0){
answer+=C[counter1][A-counter2];
cout<<answer<<endl;}
else{
for(int j=A-counter2;j<=d;j++){
answer+=[counter1][i];}
cout<<answer<<endl;}}
| a.cc:5:1: error: expected unqualified-id before numeric constant
5 | 2 using R=double;
| ^
a.cc:6:1: error: expected unqualified-id before numeric constant
6 | 3
| ^
a.cc: In function 'void comb_table(int)':
a.cc:10:2: error: expected ';' before 'for'
10 | 8 for(int i=0;i<=N;++i){
| ^~~~
| ;
a.cc:10:15: error: 'i' was not declared in this scope
10 | 8 for(int i=0;i<=N;++i){
| ^
a.cc: In function 'int main()':
a.cc:47:9: error: 'C' was not declared in this scope
47 | answer+=C[counter1][A-counter2];
| ^
a.cc: In lambda function:
a.cc:51:19: error: expected '{' before '[' token
51 | answer+=[counter1][i];}
| ^
a.cc: In function 'int main()':
a.cc:51:20: error: 'i' was not declared in this scope
51 | answer+=[counter1][i];}
| ^
|
s253602323 | p03776 | C++ | #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using namespace std;
typedef long long LL;
LL comb(LL n, LL k){
LL r=1;
for(LL d=1; d<=k; d++){
r*=n;
n--;
r/=d;
}
return r;
}
int main(){
int N, A, B;
cin >> N >> A >> B;
vector<double> v(N);
rep(i,N) cin >> v[i];
sort(v.begin(),v.end(),greater<double>());
double sum=0;
rep(i,A) sum+=v[i];
double ans=sum/A;
LL num=0, n=0;
rep(i,N) if(v[i]==v[0]) n++;
if(n>=A) for(LL k=A; k<=min(n,B); k++) num+=comb(n,k);
else{
n=0;
rep(i,N) if(v[i]==v[A-1]) n++;
LL k=0;
rep(i,A) if(v[i]==v[A-1]) k++;
num+=comb(n,k);
}
cout << fixed << setprecision(15) << ans << endl;
cout << num << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:31:30: error: no matching function for call to 'min(LL&, int&)'
31 | if(n>=A) for(LL k=A; k<=min(n,B); k++) num+=comb(n,k);
| ~~~^~~~~
In file included from /usr/include/c++/14/string:51,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:31:30: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
31 | if(n>=A) for(LL k=A; k<=min(n,B); k++) num+=comb(n,k);
| ~~~^~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:31:30: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
31 | if(n>=A) for(LL k=A; k<=min(n,B); k++) num+=comb(n,k);
| ~~~^~~~~
|
s573852590 | p03776 | C++ | /*temp*/
//
//
//
//
//#undef _DEBUG
//#pragma GCC optimize("Ofast")
//不動小数点の計算高速化
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#include <boost/multiprecision/cpp_int.hpp>
#ifdef _DEBUG
#include "template.h"
#else
#if __cplusplus >= 201703L
/*Atcoderでしか使えない(c++17 && このテンプレートが使えるならAtcoder)*/
#include <boost/sort/pdqsort/pdqsort.hpp>
#define fast_sort boost::sort::pdqsort
#endif
#endif
#ifndef _DEBUG
#ifndef UNTITLED15_TEMPLATE_H
#define UNTITLED15_TEMPLATE_H
#ifdef _DEBUG
#include "bits_stdc++.h"
#else
#include <bits/stdc++.h>
#endif
#ifndef fast_sort
#define fast_sort sort
#endif
//#define use_pq
#define use_for
#define use_for_each
#define use_sort
#define use_fill
#define use_rand
#define use_mgr
#define use_rui
#define use_compress
//
//
//
//
//
//
#define use_pbds
#ifdef use_pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
template<class T, class U, class W, class X> auto count(__gnu_pbds::gp_hash_table<T, U, W> &a, X k) { return a.find(k) != a.end(); }
#endif
using namespace std;
using namespace std::chrono;
/*@formatter:off*/
#define ll long long
using sig_dou = double;
//マクロ省略形 関数等
#define arsz(a) (sizeof(a)/sizeof(a[0]))
#define sz(a) ((ll)(a).size())
#define mp make_pair
#define mt make_tuple
#define pb pop_back
#define pf push_front
#define eb emplace_back
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
template<class T,class U> auto max(T a, U b){return a>b ? a: b;}
template<class T,class U> auto min(T a, U b){return a<b ? a: b;}
//optional<T>について下でオーバーロード(nullopt_tを左辺右辺について単位元として扱う)
template<class T, class U> bool chma(T &a, const U &b) { if (a < b) { a = b; return true; } return false;}
template<class T, class U> bool chmi(T &a, const U &b) { if (b < a) { a = b; return true; } return false;}
//メタ系 meta
//vector<T>でTを返す
#define decl_t(A) decltype(A)::value_type
//vector<vector<.....T>>でTを返す
template<class T> struct decl2 {typedef T type;};
template<class T> struct decl2<vector<T>> {typedef typename decl2<T>::type type;};
//#define decl_max(a, b) decltype(max(MAX<decltype(a)>(), MAX<decltype(b)>()))
#define is_same2(T, U) is_same<T, U>::value
template<class T>struct is_vector : std::false_type{};
template<class T>struct is_vector<std::vector<T>> : std::true_type{};
//大きい型を返す max_type<int, char>::type
//todo mintがlong long より小さいと判定されるためバグる
template<class T1, class T2, bool t1_bigger = (sizeof(T1) > sizeof(T2))>struct max_type{typedef T1 type;};
template<class T1, class T2> struct max_type<T1, T2, false>{typedef T2 type;};
template<typename T, typename U = typename T::value_type>std::true_type value_type_tester(signed);
template<typename T>std::false_type value_type_tester(long);
template<typename T>struct has_value_type: decltype(value_type_tester<T>(0)){};
template<class T> struct vec_rank : integral_constant<int, 0> {};
template<class T> struct vec_rank<vector<T>> : integral_constant<int, vec_rank<T>{} + 1> {};
//N個のTを並べたtupleを返す
//tuple_n<3, int>::type tuple<int, int, int>
template<size_t N, class T, class... Arg> struct tuple_n{typedef typename tuple_n<N-1, T, T, Arg...>::type type;};
template<class T, class...Arg> struct tuple_n<0, T, Arg...>{typedef tuple<Arg...> type;};
struct dummy_t1{};struct dummy_t2{};
struct dummy_t3{};struct dummy_t4{};
struct dummy_t5{};struct dummy_t6{};
//template<class T, require(is_integral<T>::value)>など
#define require_t(bo) enable_if_t<bo>* = nullptr
//複数でオーバーロードする場合、引数が同じだとうまくいかないため
//require_arg(bool, dummy_t1)
//require_arg(bool, dummy_t2)等とする
#define require_arg1(bo) enable_if_t<bo> * = nullptr
#define require_arg2(bo, dummy_type) enable_if_t<bo, dummy_type> * = nullptr
#define require_arg(...) over2(__VA_ARGS__,require_arg2,require_arg1)(__VA_ARGS__)
//->//enable_if_tのtを書き忘れそうだから
#define require_ret(bo, ret_type) enable_if_t<bo, ret_type>
#define int long long //todo 消したら動かない intの代わりにsignedを使う
auto start_time = system_clock::now();
auto past_time = system_clock::now();
#define debugName(VariableName) # VariableName
//最大引数がN
#define over2(o1, o2, name, ...) name
#define over3(o1, o2, o3, name, ...) name
#define over4(o1, o2, o3, o4, name, ...) name
#define over5(o1, o2, o3, o4, o5, name, ...) name
#define over6(o1, o2, o3, o4, o5, o6, name, ...) name
#define over7(o1, o2, o3, o4, o5, o6, o7, name, ...) name
#define over8(o1, o2, o3, o4, o5, o6, o7, o8, name, ...) name
#define over9(o1, o2, o3, o4, o5, o6, o7, o8, o9, name, ...) name
#define over10(o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, name, ...) name
void assert2(bool b,const string& s = ""){ if(!b){ cerr<<s<<endl; exit(1);/*assert(0);*/ }}
//my_nulloptをあらゆる操作の単位元的な物として扱う
//vectorの参照外時に返したり、右辺値として渡されたときに何もしないなど
struct my_nullopt_t {} my_nullopt;
#define nullopt_t my_nullopt_t
#define nullopt my_nullopt
/*@formatter:off*/
//値が無いときは、setを使わない限り代入できない
//=を使っても無視される
template<class T> struct my_optional {
private:
bool is_null;
T v;
public:
typedef T value_type ;
my_optional() : is_null(true) {}
my_optional(const nullopt_t&) : is_null(true) {}
my_optional(const T& v) : v(v), is_null(false) {}
bool has_value() const { return !is_null; }
T &value() { static string mes = "optional has no value";assert2(!is_null, mes);return v;}
const T &value() const { static string mes = "optional has no value";assert2(!is_null, mes);return v;}
void set(const T &nv) {is_null = false;v = nv;}
template<class U> void operator=(const U &v) {
set(v);//null状態でも代入出来るようにした
// if (has_value())value() = v; else return;
}
template<class U> void operator=(const my_optional<U> &v) {
if (/*has_value() && */v.has_value())(*this) = v; else return;
}
/*@formatter:off*/
void reset() { is_null = true; }
void operator=(const nullopt_t &) { reset(); }
template<require_t(!is_same2(T, bool))>
explicit operator bool(){return !is_null;}
//nullの時はエラー
operator T&(){return value();}
operator const T&()const {return value();}
my_optional<T> operator++() { if (this->has_value()) { this->value()++; return *this; } else { return *this; } }
my_optional<T> operator++(signed) { if (this->has_value()) { auto tem = *this; this->value()++; return tem; } else { return *this; } }
my_optional<T> operator--() { if (this->has_value()) { this->value()--; return *this; } else { return *this; } }
my_optional<T> operator--(signed) { if (this->has_value()) { auto tem = *this; this->value()--; return tem; } else { return *this; } }
};
template<class T>istream &operator>>(istream &iss, my_optional<T>& v) { T val; iss>>val; v.set(val); return iss;}
#define optional my_optional
template<class T>
using opt = my_optional<T>;
//template<class T, class A = std::allocator<T>> struct debtor : std::vector<T, A> {
template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key, T> >>
struct o_map : std::map<Key, optional<T>, Compare, Allocator> {
optional<T> emp;
o_map() : std::map<Key, optional<T>, Compare, Allocator>() {}
auto operator()(const nullopt_t&) {return nullopt;}
optional<T> &operator()(const optional<Key> &k) {if (k.has_value()) {return std::map<Key, optional<T>, Compare, Allocator>::operator[](k.value());} else {emp.reset();return emp;}}
optional<T> &operator()(const Key &k) { auto &v = std::map<Key, optional<T>, Compare, Allocator>::operator[](k); if (v.has_value())return v; else { v.set(0); return v; } }
template<class U> void operator[](U){static string mes = "s_map cant []";assert2(0, mes);}
};
//以下、空のoptionalをnulloptと書く
//ov[-1(参照外)] でnulloptを返す
//ov[nullopt] で nulloptをかえす
template<class T> struct ov{
optional<T> emp;
vector<optional<T>> v;
ov(int i = 0, T val = 0):v(i, val){}
template<class U>ov(const U& rhs){v.resize(sz(rhs));for (int i = 0; i < sz(rhs); i ++)v[i].set(rhs[i]);}
optional<T> &operator()(int i) {if (i < 0 || sz(v) <= i) {emp.reset();return emp;} else { return v[i]; }}
optional<T> &operator()(const nullopt_t &) { return operator()(-1); }
optional<T> &operator()(const optional<T> &i) { if (i.has_value())return operator()(i.value()); else { return operator()(-1); } }
/*@formatter:off*/
};
template<class T>string deb_tos(const ov<T>& v){
return deb_tos(v.v);
}
//vectorに対しての処理は.vを呼ぶ
template<class T> class ovv{
optional<T> emp;
public:
vector<vector<optional<T>> > v ;
ovv(int i=0, int j=0, T val = 0) : v(i, vector<optional<T>>(j, val) ){}
optional<T> &operator()(int i, int j) { if (i < 0 || j < 0 || sz(v) <= i || sz(v[i]) <= j) { emp.reset();return emp; } else { return v[i][j]; } }
//再帰ver 遅いと思う
// optional<T>& gets(optional<T>& v){return v;}
// template<class V, class H, class... U> optional<T>& gets(V& v, H i, U... tail){ if constexpr(is_same2(H, nullopt_t))return operator()(-1,-1); else if constexpr(is_same2(H, optional<int>)){ if(i.has_value())return gets(v[(int)i], tail...); else return operator()(-1,-1); }else if constexpr(is_integral<H>::value){ return gets(v[(int)i], tail...); }else{ assert(0); return emp; } }
#if __cplusplus >= 201703L
//if constexprバージョン 上が遅かったらこれで
template<class U, class V> optional<T> &operator()(const U &i, const V &j) { /*駄目な場合を除外*/ if constexpr(is_same2(U, nullopt_t) || is_same2(U, nullopt_t)) { return operator()(-1, -1); /* o, o*/ } else if constexpr(is_same2(U, optional<int>) && is_same2(V, optional<int>)) { return operator()(i.has_value() ? (int) i : -1, j.has_value() ? (int) j : -1); /* o, x*/ } else if constexpr(is_same2(U, optional<int>)) { return operator()(i.has_value() ? (int) i : -1, (int) j); /* x, o*/ } else if constexpr(is_same2(V, optional<int>)) { return operator()((int) i, j.has_value() ? (int) j : -1); /* x, x*/ } else { return operator()((int) i, (int) j); } }
#endif
operator const vector<vector<optional<T>> >&(){
return v;
}
};
template<class T>istream &operator>>(istream &iss, ovv<T> &a) { for (int h = 0; h < sz(a); h ++){ for (int w = 0; w < sz(a[h]); w ++){ iss>>a.v[h][w ]; } } return iss;}
template<class T>string deb_tos(const ovv<T>& v){
return deb_tos(v.v);
}
template<class T> struct ov3{
optional<T> emp;
vector<vector<vector<optional<T>>> > v ;
ov3(int i, int j, int k, T val = 0) : v(i, vector<vector<optional<T>>>(j, vector<optional<T>>(k, val) ) ){}
optional<T> &operator()(int i, int j, int k) { if (i < 0 || j < 0 || sz(v) <= i || sz(v[i]) <= j) { if(k < 0 || sz(v[i][j]) <= k){ emp.reset(); return emp; } } return v[i][j][k]; }
private:
#if __cplusplus >= 201703L
//再帰ver 遅いと思う
template<class V, class H> optional<T> &gets(V &nowv, H i) { if constexpr(is_same2(H, nullopt_t)) { emp.reset(); return emp; } else if constexpr(is_same2(H, optional<int>)) { if (i.has_value()) { return nowv[(int) i]; } else { emp.reset();return emp; } } else if constexpr(is_integral<H>::value) { return nowv[(int) i]; } else { static string mes = "ov3 error not index";assert2(0, mes); emp.reset();return emp; } }
//todo const &消した
template<class V, class H, class... U> optional<T> &gets(V &nowv, H i, U... tail) { if constexpr(is_same2(H, nullopt_t)) { emp.reset();return emp; } else if constexpr(is_same2(H, optional<int>)) { if (i.has_value()) { return gets(nowv[(int) i], tail...); } else { emp.reset();return emp; } } else if constexpr(is_integral<H>::value) { return gets(nowv[(int) i], tail...); } else { static string mes = "ov3 error not index";assert2(0, mes); emp.reset();return emp; } }
#endif
public:
template<class U, class V, class W> optional<T> &operator()(U i, V j, W k) { return gets(v, i, j, k); }
/*@formatter:off*/
};
template<class T>string deb_tos(const ov3<T>& v){
return deb_tos(v.v);
}
//nullopt_t
//優先順位
//null, [opt, tem]
// + と += は違う意味を持つ
//val+=null : val
//val+null : null
//
//+は途中計算
//+=は最終的に格納したい値にだけ持たせる
//+=がvoidを返すのは、途中計算で使うのを抑制するため
//nulloptを考慮する際、計算途中では+を使ってnulloptを作り
//格納する際は+=で無効にする必要がある
//演算子==
//optional<int>(10) == 10
//全ての型に対応させ、value_typeが等しいかを見るようにするのもありかも
//null同士を比較する状況はおかしいのではないか
bool operator==(const nullopt_t &, const nullopt_t&){assert2(0, "nul == null cant hikaku");return false;}
template<class T> bool operator==(const nullopt_t &, const T&){return false;}
template<class T> bool operator!=(const nullopt_t &, const T&){return true;}
template<class T> bool operator==(const T&, const nullopt_t &){return false;}
template<class T> bool operator!=(const T&, const nullopt_t &){return true;}
//nullを
nullopt_t& operator +(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator -(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator *(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator /(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator +=(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator -=(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator *=(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator /=(const nullopt_t &, const nullopt_t&) {return nullopt;}
template<class ANY> nullopt_t operator+(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator-(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator*(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator/(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator+(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> nullopt_t operator-(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> nullopt_t operator*(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> nullopt_t operator/(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> void operator+=(nullopt_t &, const ANY &) {}
template<class ANY> void operator-=(nullopt_t &, const ANY &) {}
template<class ANY> void operator*=(nullopt_t &, const ANY &) {}
template<class ANY> void operator/=(nullopt_t &, const ANY &) {}
template<class ANY> void operator+=(ANY &, const nullopt_t &) {}
template<class ANY> void operator-=(ANY &, const nullopt_t &) {}
template<class ANY> void operator*=(ANY &, const nullopt_t &) {}
template<class ANY> void operator/=(ANY &, const nullopt_t &) {}
template<class T>struct is_optional:false_type{};
template<class T>struct is_optional<optional<T>>:true_type{};
template<class T, class U>
true_type both_optional(optional<T> t, optional<U> u);
false_type both_optional(...);
template<class T, class U> class opt_check : public decltype(both_optional(declval<T>(), declval<U>())) {};
//optionalは同じ型同士しか足せない
//(o, t), (t, o), (o, o)
#define opt_tem(op) \
template<class O, class O_ret = decltype(declval<O>() op declval<O>())>optional<O_ret> operator op(const optional<O> &opt1, const optional<O> &opt2) { if (!opt1.has_value() || !opt2.has_value()) { return optional<O_ret>(); } else { return optional<O_ret>(opt1.value() op opt2.value()); }}\
template<class O, class T, class O_ret = decltype(declval<O>() op declval<O>())> auto operator op(const optional<O> &opt, const T &tem) -> require_ret(!(opt_check<optional<O>, T>::value), optional<O_ret>) { if (!opt.has_value()) { return optional<O_ret>(); } else { return optional<O_ret>(opt.value() op tem); }}\
template<class O, class T, class O_ret = decltype(declval<O>() op declval<O>())> auto operator op(const T &tem, const optional<O> &opt) -> require_ret(!(opt_check<optional<O>, T>::value), optional<O_ret>) { if (!opt.has_value()) { return optional<O_ret>(); } else { return optional<O_ret>(opt.value() op tem); }}
/*@formatter:off*/
opt_tem(+)opt_tem(-)opt_tem(*)opt_tem(/)
//比較はoptional<bool>を返す
opt_tem(<)opt_tem(>)opt_tem(<=)opt_tem(>=)
/*@formatter:on*//*@formatter:off*/
template<class O, class T> bool operator==(const optional<O>& opt, const T& tem){if(opt.has_value()){return opt.value()==tem;}else return nullopt == tem;}
template<class O, class T> bool operator!=(const optional<O>& opt, const T& tem){if(opt.has_value()){return opt.value()!=tem;}else return nullopt != tem;}
template<class O, class T> bool operator==(const T& tem, const optional<O>& opt){if(opt.has_value()){return opt.value()==tem;}else return nullopt == tem;}
template<class O, class T> bool operator!=(const T& tem, const optional<O>& opt){if(opt.has_value()){return opt.value()!=tem;}else return nullopt != tem;}
template<class O> bool operator==(const optional<O>& opt1, const optional<O>& opt2){ if(opt1.has_value() != opt2.has_value()){ return false; }else if(opt1.has_value()){ return opt1.value() == opt2.value(); }else { return nullopt == nullopt; }}
template<class O> bool operator!=(const optional<O>& opt1, const optional<O>& opt2){return !(opt1 == opt2);}
//(a+=null) != (a=a+null)
// a null
template<class T, class O> void operator+=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem += opt.value(); }}
template<class T, class O> void operator-=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem -= opt.value(); }}
template<class T, class O> void operator*=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem *= opt.value(); }}
template<class T, class O> void operator/=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem /= opt.value(); }}
template<class T, class O> void operator+=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() += tem; }}
template<class T, class O> void operator-=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() -= tem; }}
template<class T, class O> void operator*=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() *= tem; }}
template<class T, class O> void operator/=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() /= tem; }}
//
template<class Ol, class Or> void operator+=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl += opr.value(); }}
template<class Ol, class Or> void operator-=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl -= opr.value(); }}
template<class Ol, class Or> void operator*=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl *= opr.value(); }}
template<class Ol, class Or> void operator/=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl /= opr.value(); }}
/*@formatter:off*/
template<class U> auto max(const nullopt_t &, const U &val) { return val; }
template<class U> auto max(const U &val, const nullopt_t &) { return val; }
template<class U> auto min(const nullopt_t &, const U &val) { return val; }
template<class U> auto min(const U &val, const nullopt_t &) { return val; }
template<class T, class U> auto max(const optional<T> &opt, const U &val) { if (opt.has_value())return max(opt.value(), val); else return val; }
template<class T, class U> auto max(const U &val, const optional<T> &opt) { if (opt.has_value())return max(opt.value(), val); else return val; }
template<class T, class U> auto min(const optional<T> &opt, const U &val) { if (opt.has_value())return min(opt.value(), val); else return val; }
template<class T, class U> auto min(const U &val, const optional<T> &opt) { if (opt.has_value())return min(opt.value(), val); else return val; }
//null , optional, T
bool chma(nullopt_t &, const nullopt_t &) { return false; }
template<class T> bool chma(T &opt, const nullopt_t &) { return false; }
template<class T> bool chma(nullopt_t &, const T &opt) { return false; }
template<class T> bool chma(optional<T> &olv, const optional<T> &orv) { if (orv.has_value()) { return chma(olv, orv.value()); } else return false; }
template<class T, class U> bool chma(optional<T> &opt, const U &rhs) { if (opt.has_value()) { return chma(opt.value(), rhs); } else return false; }
template<class T, class U> bool chma(T &lhs, const optional<U> &opt) { if (opt.has_value()) { return chma(lhs, opt.value()); } else return false; }
bool chmi(nullopt_t &, const nullopt_t &) { return false; }
template<class T> bool chmi(T &opt, const nullopt_t &) { return false; }
template<class T> bool chmi(nullopt_t &, const T &opt) { return false; }
template<class T> bool chmi(optional<T> &olv, const optional<T> &orv) { if (orv.has_value()) { return chmi(olv, orv.value()); } else return false; }
template<class T, class U> bool chmi(optional<T> &opt, const U &rhs) { if (opt.has_value()) { return chmi(opt.value(), rhs); } else return false; }
template<class T, class U> bool chmi(T &lhs, const optional<U> &opt) { if (opt.has_value()) { return chmi(lhs, opt.value()); } else return false; }
template<class T> ostream &operator<<(ostream &os, optional<T> p) { if (p.has_value())os << p.value(); else os << "e"; return os;}
template<class T>using opt = my_optional<T>;
struct xorshift {
/*@formatter:on*/
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
/*@formatter:off*/
size_t operator()(const uint64_t& x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); }
size_t operator()(const std::pair<ll, ll>& x) const { ll v = ((x.first) << 32) | x.second; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(v + FIXED_RANDOM); }
template<class T, class U> size_t operator()(const std::pair<T, U>& x) const{ static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); uint64_t hasx = splitmix64(x.first); uint64_t hasy = splitmix64(x.second + FIXED_RANDOM); return hasx ^ hasy; }
template<class T> size_t operator()(const vector<T> &x) const { uint64_t has = 0; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); uint64_t rv = splitmix64(FIXED_RANDOM); for (int i = 0; i < sz(x); i ++){ uint64_t v = splitmix64(x[i] + rv); has ^= v; rv = splitmix64(rv); } return has; }
};
#ifdef _DEBUG
string message;
string res_mes;
//#define use_debtor
//template<class T, class U, class X> auto count(unordered_map<T, U> &a, X k) { return a.find(k) != a.end(); }
#ifdef use_debtor
//https://marycore.jp/prog/cpp/class-extension-methods/ 違うかも
template<class T, class A = std::allocator<T>> struct debtor : std::vector<T, A> {
using std::vector<T, A>::vector;
template<class U> int deb_v(U a, int v) { return v; }
template<class U> int deb_v(debtor<U> &a, int v = 0) { cerr << a.size() << " "; return deb_v(a.at(0), v + 1); }
template<class U> void deb_o(U a) { cerr << a << " "; }
template<class U> void deb_o(debtor<U> &a) { for (int i = 0; i < min((int) a.size(), 15ll); i++) { deb_o(a[i]); } if ((int) a.size() > 15) { cerr << "..."; } cerr << endl; }
typename std::vector<T>::reference my_at(typename std::vector<T>::size_type n, vector<int> &ind) { if (n < 0 || n >= (int) this->size()) { int siz = (int) this->size(); cerr << "vector size = "; int dim = deb_v((*this)); cerr << endl; ind.push_back(n); cerr << "out index at "; for (auto &&i: ind) { cerr << i << " "; } cerr << endl; cerr << endl; if (dim <= 2) { deb_o((*this)); } exit(0); } return this->at(n); }
typename std::vector<T>::reference operator[](typename std::vector<T>::size_type n) { if (n < 0 || n >= (int) this->size()) { int siz = (int) this->size(); cerr << "vector size = "; int dim = deb_v((*this)); cerr << endl; cerr << "out index at " << n << endl; cerr << endl; if (dim <= 2) { deb_o((*this)); } exit(0); } return this->at(n); }
};
#define vector debtor
#endif
#ifdef use_pbds
template<class T> struct my_pbds_tree {
set<T> s;
auto begin() { return s.begin(); }
auto end() { return s.end(); }
auto rbegin() { return s.rbegin(); }
auto rend() { return s.rend(); }
auto empty() { return s.empty(); }
auto size() { return s.size(); }
void clear() { s.clear(); }
template<class U> void insert(U v) { s.insert(v); }
template<class U> void operator+=(U v) { insert(v); }
template<class F> auto erase(F v) { return s.erase(v); }
template<class U> auto find(U v) { return s.find(v); }
template<class U> auto lower_bound(U v) { return s.lower_bound(v); }
template<class U> auto upper_bound(U v) { return s.upper_bound(v); }
auto find_by_order(ll k) { auto it = s.begin(); for (ll i = 0; i < k; i++)it++; return it; }
auto order_of_key(ll v) { auto it = s.begin(); ll i = 0; for (; it != s.end() && *it < v; i++)it++; return i; }
};
#define pbds(T) my_pbds_tree<T>
#endif
//区間削除は出来ない
//gp_hash_tableでcountを使えないようにするため
template<class T, class U> struct my_unordered_map { unordered_map<T, U> m; my_unordered_map() {}; auto begin() { return m.begin(); } auto end() { return m.end(); } auto cbegin() { return m.cbegin(); } auto cend() { return m.cend(); } template<class V> auto erase(V v) { return m.erase(v); } void clear() { m.clear(); } /*countは gp_hash_tableに存在しない*/ /*!= m.end()*/ template<class V> auto find(V v) { return m.find(v); } template<class V> auto &operator[](V n) { return m[n]; }};
template<class K, class V>using umap_f = my_unordered_map<K, V>;
#else
#define endl '\n'
//umapはunorderd_mapになる
//umapiはgp_hash_table
//find_by_order(k) k番目のイテレーター
//order_of_key(k) k以上が前から何番目か
#define pbds(U) __gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>
template<class K, class V>using umap_f = __gnu_pbds::gp_hash_table<K, V, xorshift>;
#endif
#define umapi unordered_map<ll,ll>
#define umapp unordered_map<P,ll>
#define umappp unordered_map<P,P>
#define umapu unordered_map<uint64_t,ll>
#define umapip unordered_map<ll,P>
template<class T, class U, class X> auto count(unordered_map<T, U> &a, X k) { return a.find(k) != a.end(); }
/*@formatter:off*/
#ifdef use_pbds
template<class U, class L> void operator+=(__gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> &s, L v) { s.insert(v); }
#endif
//衝突対策
#define ws ws_
//todo 要らないと思う
template<class A, class B, class C> struct T2 { A f;B s;C t;T2() { f = 0, s = 0, t = 0; }T2(A f, B s, C t) : f(f), s(s), t(t) {}bool operator<(const T2 &r) const { return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t; /*return f != r.f ? f > r.f : s != r.s ?n s > r.s : t > r.t; 大きい順 */ } bool operator>(const T2 &r) const { return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; /*return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順 */ } bool operator==(const T2 &r) const { return f == r.f && s == r.s && t == r.t; } bool operator!=(const T2 &r) const { return f != r.f || s != r.s || t != r.t; }};
template<class A, class B, class C, class D> struct F2 {
A a;B b;C c;D d;
F2() { a = 0, b = 0, c = 0, d = 0; }
F2(A a, B b, C c, D d) : a(a), b(b), c(c), d(d) {}
bool operator<(const F2 &r) const { return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d; /* return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;*/ }
bool operator>(const F2 &r) const { return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;/* return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d;*/ }
bool operator==(const F2 &r) const { return a == r.a && b == r.b && c == r.c && d == r.d; }
bool operator!=(const F2 &r) const { return a != r.a || b != r.b || c != r.c || d != r.d; }
ll operator[](ll i) {assert(i < 4);return i == 0 ? a : i == 1 ? b : i == 2 ? c : d;}
};
typedef T2<ll, ll, ll> T;
typedef F2<ll, ll, ll, ll> F;
//T mt(ll a, ll b, ll c) { return T(a, b, c); }
//F mf(ll a, ll b, ll c, ll d) { return F(a, b, c, d); }
//関数内をまとめる
//初期値l=-1, r=-1
void set_lr12(int &l, int &r, int n) { /*r==-1*/ if (r == -1) { if (l == -1) { l = 0; r = n; } else { r = l; l = 0; } }}
//@マクロ省略系 型,構造
//using で元のdoubleを同時に使えるはず
#define double_big
#ifdef double_big
#define double long double
//#define pow powl
#endif
using dou = double;
/*@formatter:off*/
template<class T> T MAX() { return numeric_limits<T>::max(); }
template<class T> T MIN() { return numeric_limits<T>::min(); }
constexpr ll inf = (ll) 1e9 + 100;
constexpr ll linf = (ll) 1e18 + 100;
constexpr dou dinf = (dou) linf * linf;
constexpr char infc = '{';
const string infs = "{";
template<class T> T INF() { return MAX<T>() / 2; }
template<> signed INF() { return inf; }
template<> ll INF() { return linf; }
template<> double INF() { return dinf; }
template<> char INF() { return infc; }
template<> string INF() { return infs; }
const double eps = 1e-9;
//#define use_epsdou
#ifdef use_epsdou
//基本コメントアウト
struct epsdou { double v; epsdou(double v = 0) : v(v) {} template<class T> epsdou &operator+=(T b) { v += (double) b; return (*this); } template<class T> epsdou &operator-=(T b) { v -= (double) b; return (*this); } template<class T> epsdou &operator*=(T b) { v *= (double) b; return (*this); } template<class T> epsdou &operator/=(T b) { v /= (double) b; return (*this); } epsdou operator+(epsdou b) { return v + (double) b; } epsdou operator-(epsdou b) { return v - (double) b; } epsdou operator*(epsdou b) { return v * (double) b; } epsdou operator/(epsdou b) { return v / (double) b; } epsdou operator-() const { return epsdou(-v); } template<class T> bool operator<(T b) { return v < (double) b; } template<class T> bool operator>(T b) {auto r = (double)b; return v > (double) b; } template<class T> bool operator==(T b) { return fabs(v - (double) b) <= eps; } template<class T> bool operator<=(T b) { return v < (double) b || fabs(v - b) <= eps; } template<class T> bool operator>=(T b) { return v > (double) b || fabs(v - b) <= eps; } operator double() { return v; }};
template<>epsdou MAX(){return MAX<double>();}
template<>epsdou MIN(){return MIN<double>();}
//priqrity_queue等で使うのに必要
bool operator<(const epsdou &a, const epsdou &b) {return a.v < b.v;}
bool operator>(const epsdou &a, const epsdou &b) {return a.v > b.v;}
istream &operator>>(istream &iss, epsdou &a) {iss >> a.v;return iss;}
ostream &operator<<(ostream &os, epsdou &a) {os << a.v;return os;}
#define eps_conr_t(o) template<class T> epsdou operator o(T a, epsdou b) {return (dou) a o b.v;}
#define eps_conl_t(o) template<class T> epsdou operator o(epsdou a, T b) {return a.v o (dou) b;}
eps_conl_t(+)eps_conl_t(-)eps_conl_t(*)eps_conl_t(/)eps_conr_t(+)eps_conr_t(-)eps_conr_t(*)eps_conr_t(/)
//template<class U> epsdou max(epsdou a, U b){return a.v>b ? a.v: b;}
//template<class U> epsdou max(U a, epsdou b){return a>b.v ? a: b.v;}
//template<class U> epsdou min(epsdou a, U b){return a.v<b ? a.v: b;}
//template<class U> epsdou min(U a, epsdou b){return a<b.v ? a: b.v;}
#undef double
#define double epsdou
#undef dou
#define dou epsdou
#endif
template<class T = int, class A, class B = int> T my_pow(A a, B b = 2) {
if(b < 0)return (T)1 / my_pow<T>(a, -b);
#if __cplusplus >= 201703L
if constexpr(is_floating_point<T>::value) { return pow((T) a, (T) b); }
else if constexpr(is_floating_point<A>::value) { assert2(0, "pow <not dou>(dou, )");/*return 0;しない方がコンパイル前に(voidを受け取るので)エラーが出ていいかも*/}
else if constexpr(is_floating_point<B>::value) { assert2(0, "pow <not dou>(, dou)");/*return 0;しない方がコンパイル前に(voidを受け取るので)エラーが出ていいかも*/}
else {
#endif
T ret = 1; T bek = a; while (b) { if (b & 1)ret *= bek; bek *= bek; b >>= 1; } return ret;
#if __cplusplus >= 201703L
}
#endif
}
#define pow my_pow
#define ull unsigned long long
using itn = int;
using str = string;
using bo= bool;
#define au auto
using P = pair<ll, ll>;
#define fi first
#define se second
#define beg begin
#define rbeg rbegin
#define con continue
#define bre break
#define brk break
#define is ==
#define el else
#define elf else if
#define upd update
#define sstream stringstream
#define maxq 1
#define minq -1
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MALLOC(type, len) (type*)malloc((len) * sizeof(type))
#define lam1(ret) [&](auto&& v){return ret;}
#define lam2(v, ret) [&](auto&& v){return ret;}
#define lam(...) over2(__VA_ARGS__,lam2,lam1)(__VA_ARGS__)
#define lamr(right) [&](auto&& p){return p right;}
#define unique(v) v.erase( unique(v.begin(), v.end()), v.end() );
//マクロ省略系 コンテナ
using vi = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vd = vector<double>;
using vc = vector<char>;
using vp = vector<P>;
using vt = vector<T>;
//#define V vector
#define vvt0(t) vector<vector<t>>
#define vvt1(t, a) vector<vector<t>>a
#define vvt2(t, a, b) vector<vector<t>>a(b)
#define vvt3(t, a, b, c) vector<vector<t>> a(b,vector<t>(c))
#define vvt4(t, a, b, c, d) vector<vector<t>> a(b,vector<t>(c,d))
#define vvi(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__)
#define vvb(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__)
#define vvs(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__)
#define vvd(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__)
#define vvc(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__)
#define vvp(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__)
#define vvt(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(T,__VA_ARGS__)
#define vv(type, ...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(type,__VA_ARGS__)
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));}
#define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__)
#define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__)
#define vns(name, ...) auto name = make_v<string>(__VA_ARGS__)
#define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__)
#define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__)
#define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__)
#define vn(type, name, ...) auto name = make_v<type>(__VA_ARGS__)
#define PQ priority_queue<ll, vector<ll>, greater<ll> >
#define tos to_string
using mapi = map<ll, ll>;
using mapp = map<P, ll>;
using mapd = map<dou, ll>;
using mapc = map<char, ll>;
using maps = map<str, ll>;
using seti = set<ll>;
using setp = set<P>;
using setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<ll>;
#define uset unordered_set
#define useti unordered_set<ll,xorshift>
#define mset multiset
#define mseti multiset<ll>
#define umap unordered_map
#define mmap multimap
//任意のマクロサポート用 使う度に初期化する
int index_, v1_, v2_, v3_;
/*@formatter:off*/
string to_string(char c) { string ret = ""; ret += c; return ret;}
template<class T> class pq_min_max { vector<T> d; void make_heap() { for (int i = d.size(); i--;) { if (i & 1 && d[i - 1] < d[i]) swap(d[i - 1], d[i]); int k = down(i); up(k, i); } } inline int parent(int k) const { return ((k >> 1) - 1) & ~1; } int down(int k) { int n = d.size(); if (k & 1) { /* min heap*/ while (2 * k + 1 < n) { int c = 2 * k + 3; if (n <= c || d[c - 2] < d[c]) c -= 2; if (c < n && d[c] < d[k]) { swap(d[k], d[c]); k = c; } else break; } } else { /* max heap*/ while (2 * k + 2 < n) { int c = 2 * k + 4; if (n <= c || d[c] < d[c - 2]) c -= 2; if (c < n && d[k] < d[c]) { swap(d[k], d[c]); k = c; } else break; } } return k; } int up(int k, int root = 1) { if ((k | 1) < (int) d.size() && d[k & ~1] < d[k | 1]) { swap(d[k & ~1], d[k | 1]); k ^= 1; } int p; while (root < k && d[p = parent(k)] < d[k]) { /*max heap*/ swap(d[p], d[k]); k = p; } while (root < k && d[k] < d[p = parent(k) | 1]) { /* min heap*/ swap(d[p], d[k]); k = p; } return k; }public: pq_min_max() {} pq_min_max(const vector<T> &d_) : d(d_) { make_heap(); } template<class Iter> pq_min_max(Iter first, Iter last) : d(first, last) { make_heap(); } void operator+=(const T &x) { int k = d.size(); d.push_back(x); up(k); } void pop_min() { if (d.size() < 3u) { d.pop_back(); } else { swap(d[1], d.back()); d.pop_back(); int k = down(1); up(k); } } void pop_max() { if (d.size() < 2u) { d.pop_back(); } else { swap(d[0], d.back()); d.pop_back(); int k = down(0); up(k); } } const T &get_min() const { return d.size() < 2u ? d[0] : d[1]; } const T &get_max() const { return d[0]; } int size() const { return d.size(); } bool empty() const { return d.empty(); }};
//小さいほうからM個取得するpq
template<class T> struct helper_pq_size { pq_min_max<T> q; T su = 0; int max_size = 0; helper_pq_size() {} helper_pq_size(int max_size) : max_size(max_size) {} void clear() { q = pq_min_max<T>(); su = 0; } void operator+=(T v) { su += v; q += (v); if (sz(q) > max_size) { su -= q.get_max(); q.pop_max(); } } T sum() { return su; } T top() { return q.get_min(); } void pop() { su -= q.get_min(); q.pop_min(); } T poll() { T ret = q.get_min(); su -= ret; q.pop_min(); return ret; } ll size() { return q.size(); }};
//大きいほうからM個取得するpq
template<class T> struct helper_pqg_size { pq_min_max<T> q; T su = 0; int max_size = 0; helper_pqg_size() {} helper_pqg_size(int max_size) : max_size(max_size) {} void clear() { q = pq_min_max<T>(); su = 0; } void operator+=(T v) { su += v; q += (v); if (sz(q) > max_size) { su -= q.get_min(); q.pop_min(); } } T sum() { return su; } T top() { return q.get_max(); } void pop() { su -= q.get_max(); q.pop_max(); } T poll() { T ret = q.get_max(); su -= ret; q.pop_min(); return ret; } ll size() { return q.size(); }};;
template<class T, class Container = vector<T>,class Compare = std::less<typename Container::value_type>>
struct helper_pqg { priority_queue<T, Container, Compare> q;/*小さい順*/ T su = 0; helper_pqg() {} void clear() { q = priority_queue<T, vector<T>, greater<T> >(); su = 0; } void operator+=(T v) { su += v; q.push(v); } T sum() { return su; } T top() { return q.top(); } void pop() { su -= q.top(); q.pop(); } T poll() { T ret = q.top(); su -= ret; q.pop(); return ret; } ll size() { return q.size(); }};
template<class T>
using helper_pq = helper_pqg<T, vector<T>, greater<T>>;
#if __cplusplus >= 201703L
//小さいほうからsize個残る
//Tがoptionalなら空の時nullを返す
template<class T> struct pq {
helper_pq<T> a_q;/*大きい順*/ helper_pq_size<T> b_q;/*大きい順*/ bool aquery;
T su = 0;
pq(int size = inf) {aquery = size == inf;if (!aquery) { b_q = helper_pq_size<T>(size); }}
void clear() { if (aquery) a_q.clear(); else b_q.clear(); }
void operator+=(T v) { if (aquery) a_q += v; else b_q += v; }
//optionalなら空の時nullを返す
T top() { if constexpr(is_optional<T>::value) { if (aquery) { if (sz(a_q) == 0)return T(); return a_q.top(); } else { if (sz(b_q) == 0)return T(); return b_q.top(); } } else { if (aquery)return a_q.top(); else return b_q.top(); } }
T sum() { if (aquery) return a_q.sum(); else return b_q.sum(); }
//optionalなら空の時何もしない
void pop() { if constexpr(is_optional<T>::value) { if (aquery) { if (sz(a_q))a_q.pop(); } else { if (sz(b_q))b_q.pop(); }} else { if (aquery)a_q.pop(); else b_q.pop(); }} /*T*/
T poll() { if constexpr(is_optional<T>::value) { if (aquery) { if (sz(a_q) == 0)return T(); return a_q.poll(); } else { if (sz(b_q) == 0)return T(); return b_q.poll(); } } else { if (aquery)return a_q.poll(); else return b_q.poll(); } }
ll size() { if (aquery) return a_q.size(); else return b_q.size(); }
/*@formatter:off*/
};
template<class T> struct pqg { helper_pqg<T> a_q;/*大きい順*/ helper_pqg_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pqg(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pqg_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }};
#else
//小さいほうからsize個残る
template<class T> struct pq { helper_pq<T> a_q;/*大きい順*/ helper_pq_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pq(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pq_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }};
//大きいほうからsize個残る
template<class T> struct pqg { helper_pqg<T> a_q;/*大きい順*/ helper_pqg_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pqg(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pqg_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }};
#endif
#define pqi pq<ll>
#define pqgi pqg<ll>
template<class T> string deb_tos(pq<T> &q) { vector<T> res; auto temq = q; while (sz(temq))res.push_back(temq.top()), temq.pop(); stringstream ss; ss<< res; return ss.str();}
template<class T> string deb_tos(pqg<T> &q) { vector<T> res; auto temq = q; while (sz(temq))res.push_back(temq.top()), temq.pop(); stringstream ss; ss<< res; return ss.str();}
/*@formatter:off*/
//マクロ 繰り返し
//↓@オーバーロード隔離
//todo 使わないもの非表示
#define rep1(n) for(ll rep1i = 0,rep1lim=n; rep1i < rep1lim ; ++rep1i)
#define rep2(i, n) for(ll i = 0,rep2lim=n; i < rep2lim ; ++i)
#define rep3(i, m, n) for(ll i = m,rep3lim=n; i < rep3lim ; ++i)
#define rep4(i, m, n, ad) for(ll i = m,rep4lim=n; i < rep4lim ; i+= ad)
//逆順 閉区間
#define rer2(i, n) for(ll i = n; i >= 0 ; i--)
#define rer3(i, m, n) for(ll i = m,rer3lim=n; i >= rer3lim ; i--)
#define rer4(i, m, n, dec) for(ll i = m,rer4lim=n; i >= rer4lim ; i-=dec)
#ifdef use_for
//ループを一つにまとめないとフォーマットで汚くなるため
#define nex_ind1(i) i++
#define nex_ind2(i, j, J) i = (j + 1 == J) ? i + 1 : i, j = (j + 1 == J ? 0 : j + 1)
#define nex_ind3(i, j, k, J, K)i = (j + 1 == J && k + 1 == K) ? i + 1 : i, j = (k + 1 == K) ? (j + 1 == J ? 0 : j + 1) : j, k = (k + 1 == K ? 0 : k + 1)
#define nex_ind4(i, j, k, l, J, K, L) i = (j + 1 == J && k + 1 == K && l + 1 == L) ? i + 1 : i, j = (k + 1 == K && l + 1 == L) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L ?(k + 1 == K ? 0 : k + 1) : k), l = l + 1 == L ? 0 : l + 1
#define nex_ind5(i, j, k, l, m, J, K, L, M) i = (j + 1 == J && k + 1 == K && l + 1 == L && m + 1 == M) ? i + 1 : i, j = (k + 1 == K && l + 1 == L && m + 1 == M) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L && m + 1 == M ?(k + 1 == K ? 0 : k + 1) : k), l = m + 1 == M ? l+1 == L ? 0 : l+1 : l, m = m + 1 == M ? 0 : m + 1
#define repss2(i, I) for (int i = 0; i < I; i++)
#define repss4(i, j, I, J) for (int i = (J ? 0 : I), j = 0; i < I; nex_ind2(i, j, J))
#define repss6(i, j, k, I, J, K) for (int i = (J && K ? 0 : I), j = 0, k = 0; i < I; nex_ind3(i, j, k, J, K))
#define repss8(i, j, k, l, I, J, K, L) for (int i = (J && K && L ? 0 : I), j = 0, k = 0, l = 0; i < I; nex_ind4(i, j, k, l, J, K, L))
#define repss10(i, j, k, l, m, I, J, K, L, M)for (int i = (J && K && L && M ? 0 : I), j = 0, k = 0, l = 0, m = 0; i < I; nex_ind5(i, j, k, l, m, J, K, L, M))
//i,j,k...をnまで見る
#define reps2(i, n) repss2(i, n)
#define reps3(i, j, n) repss4(i, j, n, n)
#define reps4(i, j, k, n) repss6(i, j, k, n, n, n)
#define reps5(i, j, k, l, n) repss8(i, j, k, l, n, n, n, n)
template<class T> void nex_repv2(int &i, int &j, int &I, int &J, vector<vector<T>> &s) { while (1) { j++; if (j >= J) { j = 0; i++; if (i < I) { J = (int) s[i].size(); } } if (i >= I || J) return; }}
template<class T> void nex_repv3(int &i, int &j, int &k, int &I, int &J, int &K, vector<vector<vector<T>>> &s) { while (1) { k++; if (k >= K) { k = 0; j++; if (j >= J) { j = 0; i++; if (i >= I)return; } } J = (int) s[i].size(); K = (int) s[i][j].size(); if (J && K) return; }}
#define repv_2(i, a) repss2(i, sz(a))
//正方形である必要はない
//直前を持つのとどっちが早いか
#define repv_3(i, j, a) for (int repvI = (int)a.size(), repvJ = (int)a[0].size(), i = 0, j = 0; i < repvI; nex_repv2(i,j,repvI,repvJ,a))
//箱状になっている事が要求される つまり[i] 次元目の要素数は一定
#define repv_4(i, j, k, a) for (int repvI = (int)a.size(), repvJ = (int)a[0].size(), repvK =(int)a[0][0].size(), i = 0, j = 0, k=0; i < repvI; nex_repv3(i,j,k,repvI,repvJ,repvK,a))
#define repv_5(i, j, k, l, a) repss8(i, j, k, l, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0]))
#define repv_6(i, j, k, l, m, a) repss10(i, j, k, l, m, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0]), sz(a[0][0][0][0]))
#endif
template<typename T> struct has_rbegin_rend { private:template<typename U> static auto check(U &&obj) -> decltype(std::rbegin(obj), std::rend(obj), std::true_type{});static std::false_type check(...);public:static constexpr bool value = decltype(check(std::declval<T>()))::value; };
template<typename T> constexpr bool has_rbegin_rend_v = has_rbegin_rend<T>::value;
template<typename Iterator> class Range { public:Range(Iterator &&begin, Iterator &&end) noexcept: m_begin(std::forward<Iterator>(begin)), m_end(std::forward<Iterator>(end)) {}Iterator begin() const noexcept { return m_begin; }Iterator end() const noexcept { return m_end; }private:const Iterator m_begin;const Iterator m_end; };
template<typename Iterator> static inline Range<Iterator> makeRange(Iterator &&begin, Iterator &&end) noexcept { return Range<Iterator>{std::forward<Iterator>(begin), std::forward<Iterator>(end)}; }
template<typename T> static inline decltype(auto) makeReversedRange(const std::initializer_list<T> &iniList) noexcept { return makeRange(std::rbegin(iniList), std::rend(iniList)); }
template<typename T, typename std::enable_if_t<has_rbegin_rend_v<T>, std::nullptr_t> = nullptr> static inline decltype(auto) makeReversedRange(T &&c) noexcept { return makeRange(std::rbegin(c), std::rend(c)); }/* rbegin(), rend()を持たないものはこっちに分岐させて,エラーメッセージを少なくする*/template<typename T, typename std::enable_if<!has_rbegin_rend<T>::value, std::nullptr_t>::type = nullptr> static inline void makeReversedRange(T &&) noexcept { static_assert(has_rbegin_rend<T>::value, "Specified argument doesn't have reverse iterator."); }
//#define use_for
#define form1(st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it)
#define form3(k, v, st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it)
#define form4(k, v, st, r) for (auto &&form_it = st.begin(); form_it != st.end() && (*form_it).fi < r; ++form_it)
#define form5(k, v, st, l, r) for (auto &&form_it = st.lower_bound(l); form_it != st.end() && (*form_it).fi < r; ++form_it)
#define forrm1(st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it)
#define forrm3(k, v, st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it)
//向こう側で
// ++itか it = st.erase(it)とする
#define fors1(st) for (auto &&it = st.begin(); it != st.end(); )
#define fors2(v, st) for (auto &&it = st.begin(); it != st.end(); )
#define fors3(v, st, r) for (auto &&it = st.begin(); it != st.end() && (*it) < r; )
#define fors4(v, st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it) < r; )
#ifdef use_for
#define forslr3(st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it)
#define forslr4(v, st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it)
#define forslr5(v, st, r, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it)
#define forslr6(v, st, l, r, a, b) for (auto &&forslr_it = st.lower_bound(l); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it)
#define fora_f_init_2(a, A) ;
#define fora_f_init_3(fora_f_i, a, A) auto &&a = A[fora_f_i];
#define fora_f_init_4(a, b, A, B) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i];
#define fora_f_init_5(fora_f_i, a, b, A, B) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i];
#define fora_f_init_6(a, b, c, A, B, C) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i];
#define fora_f_init_7(fora_f_i, a, b, c, A, B, C) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i];
#define fora_f_init_8(a, b, c, d, A, B, C, D) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; auto && d = D[fora_f_i];
#define fora_f_init_9(fora_f_i, a, b, c, d, A, B, C, D) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; auto && d = D[fora_f_i];
#define fora_f_init(...) over9(__VA_ARGS__,fora_f_init_9, fora_f_init_8, fora_f_init_7, fora_f_init_6, fora_f_init_5, fora_f_init_4, fora_f_init_3, fora_f_init_2)(__VA_ARGS__)
#define forr_init_2(a, A) auto &&a = A[forr_i];
#define forr_init_3(forr_i, a, A) auto &&a = A[forr_i];
#define forr_init_4(a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i];
#define forr_init_5(forr_i, a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i];
#define forr_init_6(a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i];
#define forr_init_7(forr_i, a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i];
#define forr_init_8(a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i];
#define forr_init_9(forr_i, a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i];
#define forr_init(...) over9(__VA_ARGS__, forr_init_9, forr_init_8, forr_init_7, forr_init_6, forr_init_5, forr_init_4, forr_init_3, forr_init_2)(__VA_ARGS__)
#define forp_init3(k, v, S) auto &&k = S[forp_i].first;auto &&v = S[forp_i].second;
#define forp_init4(forp_i, k, v, S) auto &&k = S[forp_i].first;auto &&v = S[forp_i].second;
#define forp_init(...) over4(__VA_ARGS__,forp_init4,forp_init3,forp_init2,forp_init1)(__VA_ARGS__)
#define form_init(k, v, ...) auto &&k = (*form_it).fi;auto &&v = (*form_it).se;
#define forrm_init(k, v, ...) auto &&k = (*forrm_it).fi;auto &&v = (*forrm_it).se;
#define fors_init(v, ...) auto &&v = (*it);
#define forlr_init(a, A, ngl, ngr) auto a = A[forlr_i]; auto prev = forlr_i ? A[forlr_i-1] : ngl;auto next = forlr_i+1< rep2lim? A[forlr_i+1] : ngr;
#define forslr_init4(a, A, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr;
#define forslr_init5(a, A, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr;
#define forslr_init6(a, A, l, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr;
#define forslr_init(...) over6(__VA_ARGS__,forslr_init6,forslr_init5,forslr_init4)(__VA_ARGS__);
//こうしないとmapがおかしくなる
#define fora_f_2(a, A) for(auto&& a : A)
#define fora_f_3(fora_f_i, a, A) rep(fora_f_i, sz(A))
#define fora_f_4(a, b, A, B) rep(fora_f_i, sz(A))
#define fora_f_5(fora_f_i, a, b, A, B) rep(fora_f_i, sz(A))
#define fora_f_6(a, b, c, A, B, C) rep(fora_f_i, sz(A))
#define fora_f_7(fora_f_i, a, b, c, A, B, C) rep(fora_f_i, sz(A))
#define fora_f_8(a, b, c, d, A, B, C, D) rep(fora_f_i, sz(A))
#define fora_f_9(fora_f_i, a, b, c, d, A, B, C, D) rep(fora_f_i, sz(A))
#define forr_2(a, A) rer(forr_i, sz(A)-1)
#define forr_3(forr_i, a, A) rer(forr_i, sz(A)-1)
#define forr_4(a, b, A, B) rer(forr_i, sz(A)-1)
#define forr_5(forr_i, a, b, A, B) rer(forr_i, sz(A)-1)
#define forr_6(a, b, c, A, B, C) rer(forr_i, sz(A)-1)
#define forr_7(forr_i, a, b, c, A, B, C) rer(forr_i, sz(A)-1)
#define forr_8(a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1)
#define forr_9(forr_i, a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1)
#endif
//↑@オーバーロード隔離
//rep系はインデックス、for系は中身
#define rep(...) over4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rer(...) over4(__VA_ARGS__,rer4,rer3,rer2,)(__VA_ARGS__)
//自分込みで残りがREM以上の間ループを回す
#define rem(i, N, REM) for (int i = 0; i < N - REM + 1; i++)
//char用のrep
#define repc(i, m, n) for(char i = m,repc3lim=n; i < repc3lim ; ++i)
//i,j,k...をnまで見る
#define reps(...) over5(__VA_ARGS__,reps5,reps4,reps3,reps2,)(__VA_ARGS__)
#define repss(...) over10(__VA_ARGS__, repss10, a, repss8, a, repss6, a, repss4, a, repss2) (__VA_ARGS__)
//vectorのindexを走査する
//repv(i,j,vvi)
#define repv(...) over6(__VA_ARGS__,repv_6,repv_5,repv_4,repv_3,repv_2,)(__VA_ARGS__)
#define rerv(i, A) for (int i = sz(A)-1; i >= 0 ; i--)
//repvn(dp) nは次元
#define repv1(a) repv(i, a)
#define repv2(a) repv(i, j, a)
#define repv3(a) repv(i, j, k, a)
#define repv4(a) repv(i, j, k, l, a)
#ifdef use_for
#define fora_f(...) over9(__VA_ARGS__, fora_f_9, fora_f_8, fora_f_7, fora_f_6, fora_f_5, fora_f_4, fora_f_3, fora_f_2)(__VA_ARGS__)
#endif
#define forr(...) over9(__VA_ARGS__, forr_9, forr_8, forr_7, forr_6, forr_5, forr_4, forr_3, forr_2)(__VA_ARGS__)
//0~N-2まで見る
#define forar_init(v, rv, A) auto &&v = A[forar_i]; auto && rv = A[forar_i+1];
#define forar(v, rv, A) rep(forar_i, sz(A) - 1)
#if __cplusplus >= 201703L
template<size_t M_SZ, bool indexed, class Iterator, class T, class U=T, class V=T, class W=T>
class ite_vec_merge : public Iterator { std::size_t i = 0; vector<T> &A; vector<U> &B; vector<V> &C; vector<W> &D;public : ite_vec_merge(Iterator ita, vector<T> &A) : Iterator(ita), A(A), B(A), C(A), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B) : Iterator(ita), A(A), B(B), C(A), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B, vector<V> &C) : Iterator(ita), A(A), B(B), C(C), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B, vector<V> &C, vector<W> &D) : Iterator(ita), A(A), B(B), C(C), D(D) {} auto &operator++() { ++i; this->Iterator::operator++(); return *this; } auto operator*() const noexcept { if constexpr(!indexed && M_SZ == 1) { return tuple<T &>(A[i]); } else if constexpr(!indexed && M_SZ == 2) { return tuple<T &, U &>(A[i], B[i]); } else if constexpr(!indexed && M_SZ == 3) { return tuple<T &, U &, V &>(A[i], B[i], C[i]); } else if constexpr(!indexed && M_SZ == 4) { return tuple<T &, U &, V &, W &>(A[i], B[i], C[i], D[i]); } else if constexpr(indexed && M_SZ == 1) { return tuple<int, T &>(i, A[i]); } else if constexpr(indexed && M_SZ == 2) { return tuple<int, T &, U &>(i, A[i], B[i]); } else if constexpr(indexed && M_SZ == 3) { return tuple<int, T &, U &, V &>(i, A[i], B[i], C[i]); } else if constexpr(indexed && M_SZ == 4) { return tuple<int, T &, U &, V &, W &>(i, A[i], B[i], C[i], D[i]); } else { assert(0); return tuple<int>(i); } }};
template<size_t M_SZ, bool indexed, class T, class U=T, class V=T, class W=T>
class vec_merge { vector<T> &a; vector<U> &b; vector<V> &c; vector<W> &d;public : vec_merge(vector<T> &a) : a(a), b(a), c(a), d(a) {} vec_merge(vector<T> &a, vector<U> &b) : a(a), b(b), c(a), d(a) {} vec_merge(vector<T> &a, vector<U> &b, vector<V> &c) : a(a), b(b), c(c), d(a) {} vec_merge(vector<T> &a, vector<U> &b, vector<V> &c, vector<W> &d) : a(a), b(b), c(c), d(d) {} auto begin() const { if constexpr(M_SZ == 1) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a}; } else if constexpr(M_SZ == 2) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b}; } else if constexpr(M_SZ == 3) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b, c}; } else if constexpr(M_SZ == 4) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b, c, d}; } else { assert(0); return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a}; } } auto end() const { if constexpr(M_SZ == 1) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a}; } else if constexpr(M_SZ == 2) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b}; } else if constexpr(M_SZ == 3) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b, c}; } else if constexpr(M_SZ == 4) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b, c, d}; } else { assert(0); return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a}; } }};
#endif
#define fora_2(a, A) for(auto&& a : A)
#if __cplusplus >= 201703L
#define fora_3(i, a, A) for(auto[i, a] : vec_merge<1, true, decl_t(A)>(A))
#define fora_4(a, b, A, B) for(auto[a, b] : vec_merge<2, false, decl_t(A), decl_t(B)>(A, B))
#define fora_5(i, a, b, A, B) for(auto[i, a, b] : vec_merge<2, true, decl_t(A), decl_t(B)>(A, B))
#define fora_6(a, b, c, A, B, C) for(auto[a, b, c] : vec_merge<3, false, decl_t(A), decl_t(B), decl_t(C)>(A, B, C))
#define fora_7(i, a, b, c, A, B, C) for(auto[i, a, b, c] : vec_merge<3, true, decl_t(A), decl_t(B), decl_t(C)>(A, B, C))
#define fora_8(a, b, c, d, A, B, C, D) for(auto[a, b, c, d] : vec_merge<4, false, decl_t(A), decl_t(B), decl_t(C), decl_t(D)>(A, B, C, D))
#define fora_9(i, a, b, c, d, A, B, C, D) for(auto[i, a, b, c, d] : vec_merge<4, true, decl_t(A), decl_t(B), decl_t(C), decl_t(D)>(A, B, C, D))
#endif
//構造化束縛ver
//1e5要素で40ms程度
//遅いときはfora_fを使う
#define fora(...) over9(__VA_ARGS__, fora_9, fora_8, fora_7, fora_6, fora_5, fora_4, fora_3, fora_2)(__VA_ARGS__)
//#define forr(v, a) for(auto&& v : makeReversedRange(a))
//参照を取らない
/*@formatter:off*/
#ifdef use_for
template<class U> vector<U> to1d(vector<U> &a) { return a; }
template<class U> auto to1d(vector<vector<U>> &a) { vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)res.push_back(a2); return res;}
template<class U> vector<U> to1d(vector<vector<vector<U>>> &a) { vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) res.push_back(a3); return res;}
template<class U> vector<U> to1d(vector<vector<vector<vector<U>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)res.push_back(a4); return res;}
template<class U> vector<U> to1d(vector<vector<vector<vector<vector<U>>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)for (auto &&a5 : a4)res.push_back(a5); return res;}
template<class U> vector<U> to1d(vector<vector<vector<vector<vector<vector<U>>>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)for (auto &&a5 : a4)for (auto &&a6 : a5)res.push_back(a6); return res;}
#define forv(a, b) for(auto a : to1d(b))
//インデックスを前後含めて走査
#define ring(i, s, len) for (int i = s, prev = (s == 0) ? len - 1 : s - 1, next = (s == len - 1) ? 0 : s + 1, cou = 0; cou < len; cou++, prev = i, i = next, next = (next == len - 1) ? 0 : next + 1)
//値と前後を見る
#define ringv(v, d) index_=0;for (auto prev = d[sz(d)-1],next= (int)d.size()>1?d[1]:d[0],v = d[0]; index_ < sz(d); index_++, prev = v, v = next, next = (index_>=sz(d)-1?d[0]:d[index_+1]))
// 左右をnext prevで見る 0の左と nの右
#define forlr(v, d, banpei_l, banpei_r) rep(forlr_i,sz(d))
#endif
#define form(...) over5(__VA_ARGS__,form5,form4,form3,form2,form1)(__VA_ARGS__)
#define forrm(...) over5(__VA_ARGS__,forrm5,forrm4,forrm3,forrm2,forrm1)(__VA_ARGS__)
#define fors(...) over4(__VA_ARGS__,fors4,fors3,fors2,fors1)(__VA_ARGS__)
#define forslr(...) over6(__VA_ARGS__,forslr6,forslr5,forslr4,forslr3)(__VA_ARGS__)
#define forp3(k, v, st) rep(forp_i,sz(st))
#define forp4(forp_i, k, v, st) rep(forp_i,sz(st))
#define forp(...) over4(__VA_ARGS__,forp4,forp3)(__VA_ARGS__)
//マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const double PI = 3.1415926535897932384626433832795029L;
constexpr bool ev(ll a) { return !(a & 1); }
constexpr bool od(ll a) { return (a & 1); }
//@拡張系 こう出来るべきというもの
//埋め込み 存在を意識せずに機能を増やされているもの
namespace std {
template<> class hash<std::pair<signed, signed>> { public:size_t operator()(const std::pair<signed, signed> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }};
template<> class hash<std::pair<ll, ll>> { public:/*大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断*/size_t operator()(const std::pair<ll, ll> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }};
}
//stream まとめ
/*@formatter:off*/
istream &operator>>(istream &iss, P &a) {iss >> a.first >> a.second;return iss;}
template<typename T> istream &operator>>(istream &iss, vector<T> &vec_) {for (T &x: vec_) iss >> x;return iss;}
template<class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) {os << p.fi << " " << p.se;return os;}
ostream &operator<<(ostream &os, T p) {os << p.f << " " << p.s << " " << p.t;return os;}
ostream &operator<<(ostream &os, F p) {os << p.a << " " << p.b << " " << p.c << " " << p.d;return os;}
template<typename T> ostream &operator<<(ostream &os, vector<T> &vec_) {for (ll i = 0; i < vec_.size(); ++i)os << vec_[i] << (i + 1 == vec_.size() ? "" : " ");return os;}
template<typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec_) {for (ll i = 0; i < vec_.size(); ++i) {for (ll j = 0; j < vec_[i].size(); ++j) { os << vec_[i][j] << " "; }os << endl;}return os;}
template<typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &m) {os << endl;for (auto &&v:m) os << v << endl;return os;}
template<class T> ostream &operator<<(ostream &os, set<T> s) { fora(v, s) { os << v << " "; } return os;}
template<class T> ostream &operator<<(ostream &os, mset<T> s) { fora(v, s) { os << v << " "; } return os;}
template<class T> ostream &operator<<(ostream &os, deque<T> a) { fora(v, a) { os << v << " "; } return os;}
ostream &operator<<(ostream &os, vector<vector<char>> &vec_) { rep(h, sz(vec_)) { rep(w, sz(vec_[0])) { os << vec_[h][w]; } os << endl; } return os;}
template<class T> struct range_now {
int l;
vector<T> A;
range_now(const vector<T>& A, int l) : A(A), l(l){}
};
/*@formatter:off*/
//template<class T,class U>ostream &operator<<(ostream &os, vector<pair<T,U>>& a) {fora_f(v,a)os<<v<<endl;return os;}
template<typename W, typename H> void resize(W &vec_, const H head) { vec_.resize(head); }
template<typename W, typename H, typename ... T> void resize(W &vec_, const H &head, const T ... tail) {vec_.resize(head);for (auto &v: vec_)resize(v, tail...);}
//#define use_for_each //_each _all_of _any_of _none_of _find_if _rfind_if _contains _count_if _erase_if _entry_if
#ifdef use_for_each
//todo Atcoderの過去問がc++17に対応したら
#if __cplusplus >= 201703L
//for_each以外はconst & (呼び出し側のラムダも)
template<typename T, typename F> bool all_of2(const T &v, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : v) { if (!all_of2(v_, f))return false; } return true; } else { return f(v); }}
template<typename T, typename F> bool any_of2(const T &v, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : v) { if (!any_of2(v_, f))return true; } return false; } else { return f(v); }}
template<typename T, typename F> bool none_of2(const T &v, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : v) { if (none_of2(v_, f))return false; } return true; } else { return f(v); }}
//存在しない場合
//1次元 Nを返す
//多次元-1を返す
template<typename T, typename F> ll find_if2(const vector<T> &v, F f) { rep(i, sz(v)) { if (f(v[i]))return i; } return sz(v);}
template<typename T, typename F> tuple<int, int> find_if2(const vector<vector<T> > &v, F f) { rep(i, sz(v)) { rep(j, sz(v[i])) { if (f(v[i][j])) { return tuple<int, int>(i, j); }}} return tuple<int, int>(-1, -1);}
template<typename T, typename F> auto find_if2(const vector<vector<vector<T> > > &v, F f) { rep(i, sz(v)) { if (auto ret = find_if2(v[i], f); get<0>(ret) != -1) { return tuple_cat(tuple<int>(i), ret); }} auto bad = tuple_cat(tuple<int>(-1), find_if2(v[0], f)); return bad;}
template<class T, class F> auto find_if2(const range_now<T> &v, F f) {return find_if2(v.A, f) + v.l;}
//存在しない場合
//1次元 -1を返す
//多次元-1を返す
template<typename T, typename F> ll rfind_if2(const vector<T> &v, F f) { rer(i, sz(v) - 1) { if (f(v[i]))return i; } return -1;}
template<typename T, typename F> tuple<int, int> rfind_if2(const vector<vector<T> > &v, F f) { rer(i, sz(v) - 1) { rer(j, sz(v[i]) - 1) { if (f(v[i][j])) { return tuple<int, int>(i, j); }}} return tuple<int, int>(-1, -1);}
template<typename T, typename F> auto rfind_if2(const vector<vector<vector<T> > > &v, F f) { rer(i, sz(v) - 1) { if (auto ret = rfind_if2(v[i], f); get<0>(ret) != -1) { return tuple_cat(tuple<int>(i), ret); }} auto bad = tuple_cat(tuple<int>(-1), rfind_if2(v[0], f)); return bad;}
//todo まとめられそう string,vector全般
template<class T> bool contains(const string &s, const T &v) { return s.find(v) != string::npos; }
template<typename T> bool contains(const vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); }
template<typename T, typename F> bool contains_if2(const vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); }
template<typename T, typename F> ll count_if2(const T &v, F f) { if constexpr(has_value_type<T>::value) { ll ret = 0; for (auto &&v_ : v) { ret += count_if2(v_, f); } return ret; } else { return f(v); }}
template<typename T, typename F> void for_each2(T &a, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : a)for_each2(v_, f); } else { f(a); }}
#else
template<typename T, typename F> bool all_of2(const T &v, F f) { return f(v); }
template<typename T, typename F> bool all_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (!all_of2(v[i], f))return false; } return true;}
template<typename T, typename F> bool any_of2(const T &v, F f) { return f(v); }
template<typename T, typename F> bool any_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (any_of2(v[i], f))return true; } return false;}
template<typename T, typename F> bool none_of2(const T &v, F f) { return f(v); }
template<typename T, typename F> bool none_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (none_of2(v[i], f))return false; } return true;}
template<typename T, typename F> bool find_if2(const T &v, F f) { return f(v); }
template<typename T, typename F> ll find_if2(const vector<T> &v, F f) { rep(i, sz(v)) { if (find_if2(v[i], f))return i; } return sz(v);}
template<typename T, typename F> bool rfind_if2(const T &v, F f) { return f(v); }
template<typename T, typename F> ll rfind_if2(const vector<T> &v, F f) { rer(i, sz(v) - 1) { if (rfind_if2(v[i], f))return i; } return -1;}
template<class T> bool contains(const string &s, const T &v) { return s.find(v) != string::npos; }
template<typename T> bool contains(const vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); }
template<typename T, typename F> bool contains_if2(const vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); }
template<typename T, typename F> ll count_if2(const T &v, F f) { return f(v); }
template<typename T, typename F> ll count_if2(const vector<T> &vec_, F f) { ll ret = 0; fora(v, vec_) { ret += count_if2(v, f); } return ret;}
template<typename T, typename F> void for_each2(T &a, F f) {
f(a);
}
template<typename T, typename F> void for_each2(vector<T> &a, F f) {
for (auto &&v_ : a)for_each2(v_, f);
}
#endif
template<typename W> ll count_od(const vector<W> &a) { return count_if2(a, [](ll v) { return v & 1; }); }
template<typename W> ll count_ev(const vector<W> &a) { return count_if2(a, [](ll v) { return !(v & 1); }); }
//削除した後のvectorを返す
template<typename T, typename F> vector<T> erase_if2(const vector<T> &v, F f) { vector<T> nv; rep(i, sz(v)) { if (!f(v[i])) { nv.push_back(v[i]); }} return nv;}
template<typename T, typename F> vector<vector<T>> erase_if2(const vector<vector<T>> &v, F f) { vector<vector<T>> res; rep(i, sz(v)) { res[i] = erase_if2(v[i], f); } return res;}
template<typename T, typename F> vector<T> entry_if2(const vector<T> &v, F f) {vector<T> nv;rep(i, sz(v)) { if (f(v[i])) { nv.push_back(v[i]); }}return nv;}
template<typename T, typename F> vector<vector<T>> entry_if2(const vector<vector<T>> &v, F f) {vector<vector<T>> res;rep(i, sz(v)) { res[i] = entry_if2(v[i], f); }return res;}
template<typename T, typename F> ll l_rfind_if(const vector<T> &v, F f) {rer(i, sz(v) - 1) { if (f(v[i]))return i; }return -1;}
template<typename T, typename F> bool l_contains_if(const vector<T> &v, F f) {rer(i, sz(v) - 1) { if (f(v[i]))return true; }return false;}
template<class A, class B, class C> auto t_all_of(A a, B b, C c) { return std::all_of(a, b, c); }
template<class A, class B, class C> auto t_any_of(A a, B b, C c) { return std::any_of(a, b, c); }
template<class A, class B, class C> auto t_none_of(A a, B b, C c) { return std::none_of(a, b, c); }
template<class A, class B, class C> auto t_find_if(A a, B b, C c) { return std::find_if(a, b, c); }
template<class A, class B, class C> auto t_count_if(A a, B b, C c) { return std::count_if(a, b, c); }
#define all_of_s__2(a, right) (t_all_of(ALL(a),lamr(right)))
#define all_of_s__3(a, v, siki) (t_all_of(ALL(a),[&](auto v){return siki;}))
#define all_of_s(...) over3(__VA_ARGS__,all_of_s__3,all_of_s__2)(__VA_ARGS__)
//all_of(A, %2);
//all_of(A, a, a%2);
#define all_of__2(a, right) all_of2(a,lamr(right))
#define all_of__3(a, v, siki) all_of2(a,[&](auto v){return siki;})
#define all_of(...) over3(__VA_ARGS__,all_of__3,all_of__2)(__VA_ARGS__)
#define all_of_f(a, f) all_of2(a,f)
#define any_of_s__2(a, right) (t_any_of(ALL(a),lamr(right)))
#define any_of_s__3(a, v, siki) (t_any_of(ALL(a),[&](auto v){return siki;}))
#define any_of_s(...) over3(__VA_ARGS__,any_of_s__3,any_of_s__2)(__VA_ARGS__)
#define any_of__2(a, right) any_of2(a,lamr(right))
#define any_of__3(a, v, siki) any_of2(a,[&](auto v){return siki;})
#define any_of(...) over3(__VA_ARGS__,any_of__3,any_of__2)(__VA_ARGS__)
#define any_of_f(a, f) any_of2(a,f)
#define none_of_s__2(a, right) (t_none_of(ALL(a),lamr(right)))
#define none_of_s__3(a, v, siki) (t_none_of(ALL(a),[&](auto v){return siki;}))
#define none_of_s(...) over3(__VA_ARGS__,none_of_s__3,none_of_s__2)(__VA_ARGS__)
#define none_of__2(a, right) none_of2(a,lamr(right))
#define none_of__3(a, v, siki) none_of2(a,[&](auto v){return siki;})
#define none_of(...) over3(__VA_ARGS__,none_of__3,none_of__2)(__VA_ARGS__)
#define none_of_f(a, f) none_of2(a,f)
#define find_if_s__2(a, right) (t_find_if(ALL(a),lamr(right))-a.begin())
#define find_if_s__3(a, v, siki) (t_find_if(ALL(a),[&](auto v){return siki;})-a.begin())
#define find_if_s(...) over3(__VA_ARGS__,find_if_s__3,find_if_s__2)(__VA_ARGS__)
#define find_if__2(a, right) find_if2(a,lamr(right))
#define find_if__3(a, v, siki) find_if2(a,[&](auto v){return siki;})
#define find_if__4(a, l, v, siki) (find_if2(decltype(a)(a.begin()+l , a.end()),[&](auto v){return siki;}) + l)
#define find_if(...) over4(__VA_ARGS__,find_if__4, find_if__3,find_if__2)(__VA_ARGS__)
#define find_if_f(a, f) find_if2(a,f)
#define rfind_if_s__2(a, right) l_rfind_if(a, lamr(right))
#define rfind_if_s__3(a, v, siki) l_rfind_if(a, [&](auto v){return siki;})
#define rfind_if_s(...) over3(__VA_ARGS__,rfind_if_s__3,rfind_if_s__2)(__VA_ARGS__)
#define rfind_if__2(a, right) rfind_if2(a,lamr(right))
#define rfind_if__3(a, v, siki) rfind_if2(a,[&](auto v){return siki;})
#define rfind_if(...) over3(__VA_ARGS__,rfind_if__3,rfind_if__2)(__VA_ARGS__)
#define rfind_if_f(a, f) rfind_if2(a,f)
#define contains_if_s__2(a, right) l_contains_if(a, lamr(right))
#define contains_if_s__3(a, v, siki) l_contains_if(a, [&](auto v){return siki;})
#define contains_if_s(...) over3(__VA_ARGS__,contains_if_s__3,contains_if_s__2)(__VA_ARGS__)
#define contains_if__2(a, right) contains_if2(a,lamr(right))
#define contains_if__3(a, v, siki) contains_if2(a,[&](auto v){return siki;})
#define contains_if(...) over3(__VA_ARGS__,contains_if__3,contains_if__2)(__VA_ARGS__)
#define contains_if_f(a, f) contains_if2(a,f)
#define count_if_s__2(a, right) (t_count_if(ALL(a),lamr(right)))
#define count_if_s__3(a, v, siki) (t_count_if(ALL(a),[&](auto v){return siki;}))
#define count_if_s(...) over3(__VA_ARGS__,count_if_s__3,count_if_s__2)(__VA_ARGS__)
#define count_if__2(a, right) count_if2(a,lamr(right))
#define count_if__3(a, v, siki) count_if2(a,[&](auto v){return siki;})
#define count_if(...) over3(__VA_ARGS__,count_if__3,count_if__2)(__VA_ARGS__)
#define count_if_f(a, f) count_if2(a,f)
//vector<vi>で、viに対して操作
#define for_each_s__2(a, right) do{fora(v,a){v right;}}while(0)
#define for_each_s__3(a, v, shori) do{fora(v,a){shori;}}while(0)
#define for_each_s(...) over3(__VA_ARGS__,for_each_s__3,for_each_s__2)(__VA_ARGS__)
//vector<vi>で、intに対して操作
#define for_each__2(a, right) for_each2(a,lamr(right))
#define for_each__3(a, v, shori) for_each2(a,[&](auto& v){shori;})
#define for_each(...) over3(__VA_ARGS__,for_each__3,for_each__2)(__VA_ARGS__)
#define for_each_f(a, f) for_each2(a, f);
template<class T, class F> vector<T> help_for_eached(const vector<T> &A, F f) { vector<T> ret = A; for_each(ret, v, f(v)); return ret;}
#define for_eached__2(a, right) help_for_eached(a, lamr(right))
#define for_eached__3(a, v, shori) help_for_eached(a, lam(v, shori))
#define for_eached(...) over3(__VA_ARGS__,for_eached__3,for_eached__2)(__VA_ARGS__)
#define for_eached_f(a, f) for_eached2(a, f);
#define each for_each
#define eached for_eached
//#define erase_if_s__2(a, right) l_erase_if2(a,lamr(right))
//#define erase_if_s__3(a, v, siki) l_erase_if2(a,[&](auto v){return siki;})
//#define erase_if_s(...) over3(__VA_ARGS__,erase_if_s__3,erase_if_s__2)(__VA_ARGS__)
#define erase_if__2(a, right) erase_if2(a,lamr(right))
#define erase_if__3(a, v, siki) erase_if2(a,[&](auto v){return siki;})
#define erase_if(...) over3(__VA_ARGS__,erase_if__3,erase_if__2)(__VA_ARGS__)
#define erase_if_f(a, f) erase_if2(a,f)
//#define entry_if_s__2(a, right) l_entry_if2(a,lamr(right))
//#define entry_if_s__3(a, v, siki) l_entry_if2(a,[&](auto v){return siki;})
//#define entry_if_s(...) over3(__VA_ARGS__,entry_if_s__3,entry_if_s__2)(__VA_ARGS__)
#define entry_if__2(a, right) entry_if2(a,lamr(right))
#define entry_if__3(a, v, siki) entry_if2(a,[&](auto v){return siki;})
#define entry_if(...) over3(__VA_ARGS__,entry_if__3,entry_if__2)(__VA_ARGS__)
#define entry_if_f(a, f) entry_if2(a,f)
#endif
/*@formatter:off*/
template<class T, class U, class W> void replace(vector<W> &a, T key, U v) { rep(i, sz(a))if (a[i] == key)a[i] = v; }
template<class T, class U, class W> void replace(vector<vector<W>> &A, T key, U v) { rep(i, sz(A))replace(A[i], key, v); }
void replace(str &a, char key, str v) { if (v == "")a.erase(remove(ALL(a), key), a.end()); }
void replace(str &a, char key, char v) { replace(ALL(a), key, v); }
//keyと同じかどうか01で置き換える
template<class T, class U> void replace(vector<T> &a, U k) { rep(i, sz(a)) a[i] = a[i] == k; }
template<class T, class U> void replace(vector<vector<T >> &a, U k) { rep(i, sz(a))rep(j, sz(a[0])) a[i][j] = a[i][j] == k; }
void replace(str &a) { int dec = 0; if ('a' <= a[0] && a[0] <= 'z')dec = 'a'; if ('A' <= a[0] && a[0] <= 'Z')dec = 'A'; fora(v, a) { v -= dec; }}
void replace(str &a, str key, str v) { stringstream t; ll kn = sz(key); std::string::size_type Pos(a.find(key)); ll l = 0; while (Pos != std::string::npos) { t << a.substr(l, Pos - l); t << v; l = Pos + kn; Pos = a.find(key, Pos + kn); } t << a.substr(l, sz(a) - l); a = t.str();}
template<class T> bool is_permutation(vector<T> &a, vector<T> &b) { return is_permutation(ALL(a), ALL(b)); }
template<class T> bool next_permutation(vector<T> &a) { return next_permutation(ALL(a)); }
vi iota(ll s, ll len) {vi ve(len);iota(ALL(ve), s);return ve;}
template<class A, class B> auto vtop(vector<A> &a, vector<B> &b) { assert(sz(a) == sz(b)); /*stringを0で初期化できない */ vector<pair<A, B>> res; rep(i, sz(a))res.eb(a[i], b[i]); return res;}
template<class A, class B> void ptov(vector<pair<A, B>> &p, vector<A> &a, vector<B> &b) { a.resize(sz(p)), b.resize(sz(p)); rep(i, sz(p))a[i] = p[i].fi, b[i] = p[i].se;}
template<class A, class B, class C> auto vtot(vector<A> &a, vector<B> &b, vector<C> &c) { assert(sz(a) == sz(b) && sz(b) == sz(c)); vector<T2<A, B, C>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i]); return res;}
template<class A, class B, class C, class D> auto vtof(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { assert(sz(a) == sz(b) && sz(b) == sz(c) && sz(c) == sz(d)); vector<F2<A, B, C, D>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i], d[i]); return res;}
/*@formatter:off*/
template<class T> void sort(vector<T> &a, int l = -1, int r = -1) { set_lr12(l, r, sz(a)); fast_sort(a.begin() + l, a.begin() + r);}
template<class T> void rsort(vector<T> &a, int l = -1, int r = -1) { set_lr12(l, r, sz(a)); fast_sort(a.begin() + l, a.begin() + r, greater<T>());};
template<class A, class B> void sortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); sort(c); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}
template<class A, class B> void rsortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); rsort(c); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;}
template<class A, class B, class C> void sortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); sort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class A, class B, class C> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); rsort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class... T, class U> auto sorted(U head, T... a) { sort(head, a...); return head;}
template<class... T, class U> auto rsorted(U head, T... a) {rsort(head, a...);return head;}
//sortindex 元のvectorはソートしない
template<class T> vi sorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind); return ind;}
//#define use_sort
#ifdef use_sort
enum pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd };
enum tcomparator { fisiti, fisitd, fisdti, fisdtd, fdsiti, fdsitd, fdsdti, fdsdtd, fitisi, fitisd, fitdsi, fitdsd, fdtisi, fdtisd, fdtdsi, fdtdsd, sifiti, sifitd, sifdti, sifdtd, sdfiti, sdfitd, sdfdti, sdfdtd, sitifi, sitifd, sitdfi, sitdfd, sdtifi, sdtifd, sdtdfi, sdfdfd, tifisi, tifisd, tifdsi, tifdsd, tdfisi, tdfisd, tdfdsi, tdfdsd, tisifi, tisifd, tisdfi, tisdfd, tdsifi, tdsifd, tdsdfi, tdsdfd};
template<class A, class B> void sort(vector<pair<A, B>> &a, pcomparator type) {typedef pair<A, B> U;if (type == fisi) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; }); else if (type == fisd) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; }); else if (type == fdsi) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; }); else if (type == fdsd) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; }); else if (type == sifi) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; }); else if (type == sifd) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; }); else if (type == sdfi) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; }); else if (type == sdfd) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });};
template<class U> void sort(vector<U> &a, pcomparator type) { if (type == fisi) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == fisd) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == fdsi) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == fdsd) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == sifi) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == sifd) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == sdfi) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == sdfd) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f > r.f; }); };
template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D> > &a, pcomparator type) {typedef F2<A, B, C, D> U;if (type == fisi) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == fisd) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == fdsi) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == fdsd) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == sifi) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == sifd) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == sdfi) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == sdfd) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a > r.a; });};
template<class U> void sort(vector<U> &a, tcomparator type) {if (type == 0) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 1) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 2) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 3) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 4) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 5) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 6) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 7) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 8) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 9) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 10) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 11) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 12) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 13) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 14) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 15) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 16) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 17) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 18) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 19) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 20) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 21) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 22) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 23) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 24) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 25) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 26) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 27) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 28) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 29) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 30) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 31) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 32) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 33) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 34) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 35) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 36) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 37) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 38) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 39) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 40) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 41) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 42) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 43) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f > r.f; }); else if (type == 44) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 45) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 46) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 47) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f > r.f; });}
template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D>> &a, tcomparator type) { typedef F2<A, B, C, D> U; if (type == 0) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 1) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 2) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 3) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 4) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 5) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 6) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 7) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 8) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 9) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 10) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 11) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 12) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 13) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 14) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 15) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 16) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 17) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 18) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 19) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 20) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 21) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 22) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 23) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 24) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 25) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 26) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 27) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 28) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 29) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 30) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 31) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 32) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 33) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 34) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 35) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 36) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 37) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 38) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 39) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 40) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 41) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 42) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 43) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a > r.a; }); else if (type == 44) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 45) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 46) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 47) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a > r.a; });}
/*@formatter:off*/
void sort(string &a) { sort(ALL(a)); }
void rsort(string &a) { sort(RALL(a)); }
void sort(int &a, int &b) { if (a > b)swap(a, b); }
void sort(int &a, int &b, int &c) { sort(a, b); sort(a, c); sort(b, c);}
void rsort(int &a, int &b) { if (a < b)swap(a, b); }
void rsort(int &a, int &b, int &c) { rsort(a, b); rsort(a, c); rsort(b, c);}
//P l, P rで f(P) の形で渡す
template<class U, class F> void sort(vector<U> &a, F f) { sort(ALL(a), [&](U l, U r) { return f(l) < f(r); }); };
template<class U, class F> void rsort(vector<U> &a, F f) { sort(ALL(a), [&](U l, U r) { return f(l) > f(r); }); };
//F = T<T>
//例えばreturn p.fi + p.se;
template<class A, class B, class F> void sortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); sort(c, f); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}
template<class A, class B, class F> void rsortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); rsort(c, f); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;}
template<class A, class B, class C, class F> void sortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); sort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class A, class B, class C, class F> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); rsort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class A, class B, class C, class D> void sortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); sort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;}
template<class A, class B, class C, class D> void rsortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); rsort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;}
/*indexの分で型が変わるためpcomparatorが必要*/
template<class T> vi sorti(vector<T> &a, pcomparator f) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind, f); return ind;}
template<class T, class F> vi sorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(a[x]) < f(a[y]); }); return ind;}
template<class T> vi rsorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); rsortp(b, ind); return ind;}
template<class T, class F> vi rsorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(a[x]) > f(a[y]); }); return ind;}
template<class A, class B, class F> vi sortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(c[x]) < f(c[y]); }); return ind;}
template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b, pcomparator f) { vi ind = iota(0, sz(a)); auto c = a; auto d = b; sortt(c, d, ind, f); return ind;}
template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fisi); };
template<class A, class B, class F> vi rsortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(c[x]) > f(c[y]); }); return ind;}
template<class A, class B> vi rsortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fdsd); };
template<class A, class B, class C, class F> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(d[x]) < f(d[y]); }); return ind;}
template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, pcomparator f) { vi ind = iota(0, sz(a)); auto d = vtof(a, b, c, ind); sort(d, f); rep(i, sz(a))ind[i] = d[i].d; return ind;}
template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] < c[y]; else return b[x] < b[y]; } else { return a[x] < a[y]; }}); return ind;}
template<class A, class B, class C, class F> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(d[x]) > f(d[y]); }); return ind;}
template<class A, class B, class C> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] > c[y]; else return b[x] > b[y]; } else { return a[x] > a[y]; }}); return ind;}
template<class T> void sort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)sort(a[i]); }
template<class T> void rsort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)rsort(a[i]); }
#endif
template<class T> bool includes(vector<T> &a, vector<T> &b) { vi c = a; vi d = b; sort(c); sort(d); return includes(ALL(c), ALL(d));}
template<class T> bool distinct(const vector<T> &A) { if ((int) (A).size() == 1)return true; if ((int) (A).size() == 2)return A[0] != A[1]; if ((int) (A).size() == 3)return (A[0] != A[1] && A[1] != A[2] && A[0] != A[2]); auto B = A; sort(B); int N = (B.size()); unique(B); return N == (int) (B.size());}
template<class H, class... T> bool distinct(const H &a, const T &...b) { return distinct(vector<H>{a, b...}); }
/*@formatter:off*/
template<typename W, typename T> void fill(W &xx, const T vall) { xx = vall; }
template<typename W, typename T> void fill(vector<W> &vecc, const T vall) { for (auto &&vx : vecc)fill(vx, vall); }
template<typename W, typename T> void fill(vector<W> &xx, const T v, ll len) { rep(i, len)xx[i] = v; }
template<typename W, typename T> void fill(vector<W> &xx, const T v, int s, ll t) { rep(i, s, t)xx[i] = v; }
template<typename W, typename T> void fill(vector<vector<W>> &xx, T v, int sh, int th, int sw, int tw) { rep(h, sh, th)rep(w, sw, tw)xx[h][w] = v; }
//#define use_fill //_sum _array _max _min
#ifdef use_fill
template<typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) { rep(i, N)a[i] = v; }
template<typename A, size_t N, size_t O, typename T> void fill(A (&a)[N][O], const T &v) { rep(i, N)rep(j, O)a[i][j] = v; }
template<typename A, size_t N, size_t O, size_t P, typename T> void fill(A (&a)[N][O][P], const T &v) { rep(i, N)rep(j, O)rep(k, P)a[i][j][k] = v; }
template<typename A, size_t N, size_t O, size_t P, size_t Q, typename T> void fill(A (&a)[N][O][P][Q], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)a[i][j][k][l] = v; }
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, typename T> void fill(A (&a)[N][O][P][Q][R], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)a[i][j][k][l][m] = v; }
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S, typename T> void fill(A (&a)[N][O][P][Q][R][S], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)a[i][j][k][l][m][n] = v; }
template<class T, class U> void fill(vector<T> &a, const vi &ind, U val) { fora(v, ind) { a[v] = val; }}
template<typename A, size_t N> A sum(A (&a)[N]) {A res = 0; rep(i, N)res += a[i]; return res;}
template<typename A, size_t N, size_t O> A sum(A (&a)[N][O]) {A res = 0; rep(i, N)rep(j, O)res += a[i][j]; return res;}
template<typename A, size_t N, size_t O, size_t P> A sum(A (&a)[N][O][P]) {A res = 0; rep(i, N)rep(j, O)rep(k, P)res += a[i][j][k]; return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q> A sum(A (&a)[N][O][P][Q]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)res += a[i][j][k][l]; return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A sum(A (&a)[N][O][P][Q][R]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)res += a[i][j][k][l][m]; return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A sum(A (&a)[N][O][P][Q][R][S]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)res += a[i][j][k][l][m][n]; return res;}
template<typename A, size_t N> A max(A (&a)[N]) {A res = a[0]; rep(i, N)res = max(res, a[i]); return res;}
template<typename A, size_t N, size_t O> A max(A (&a)[N][O]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q> A max(A (&a)[N][O][P][Q], const T &v) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A max(A (&a)[N][O][P][Q][R]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A max(A (&a)[N][O][P][Q][R][S]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N> A min(A (&a)[N]) { A res = a[0]; rep(i, N)res = min(res, a[i]); return res;}
template<typename A, size_t N, size_t O> A min(A (&a)[N][O]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q> A min(A (&a)[N][O][P][Q], const T &v) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A min(A (&a)[N][O][P][Q][R]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A min(A (&a)[N][O][P][Q][R][S]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
#endif
/*@formatter:off*/
template<class T, class U> void inc(pair<T, U> &a, U v = 1) { a.first += v, a.second += v; }
template<class T, class U> void inc(T &a, U v = 1) { a += v; }
template<class T, class U = int> void inc(vector<T> &a, U v = 1) { for (auto &u:a)inc(u, v); }
template<class T, class U> void dec(T &a, U v = 1) { a -= v; }
template<class T, class U = int> void dec(vector<T> &a, U v = 1) { for (auto &u :a)dec(u, v); }
template<class U> void dec(string &a, U v = 1) { for (auto &u :a)dec(u, v); }
template<class T, class U, class W> void dec(vector<T> &a, vector<U> &b, W v = 1) {for (auto &u :a)dec(u, v);for (auto &u :b)dec(u, v);}
template<class T, class U, class W> void dec(vector<T> &a, vector<U> &b, vector<W> &c) { for (auto &u :a)dec(u, 1); for (auto &u :b)dec(u, 1); for (auto &u :c)dec(u, 1);}
bool ins(ll h, ll w, ll H, ll W) { return h >= 0 && w >= 0 && h < H && w < W; }
bool san(ll l, ll v, ll r) { return l <= v && v < r; }
template<class T> bool ins(vector<T> &a, ll i, ll j = 0) { return san(0, i, sz(a)) && san(0, j, sz(a)); }
#define inside ins
ll u0(ll a) { return a < 0 ? 0 : a; }
template<class T> vector<T> u0(vector<T> &a) { vector<T> ret = a; fora(v, ret) { v = u(v); } return ret;}
//todo 名前
bool d_(int a, int b) {if (b == 0)return false;return (a % b) == 0;}
//エラー
void ole() {
#ifdef _DEBUG
cerr << "ole" << endl;exit(0);
#endif
string a = "a"; rep(i, 30)a += a; rep(i, 1 << 17)cout << a << endl; cout << "OLE 出力長制限超過" << endl;exit(0);
}
void re(string s = "") {cerr << s << endl;assert(0 == 1);exit(0);}
void tle() { while (inf)cout << inf << endl; }
//@汎用便利関数 入力
ll in() {ll ret;cin >> ret;return ret;}
template<class T> T in() { T ret; cin >> ret; return ret;}
string sin() { string ret; cin >> ret; return ret;}
template<class T> void in(T &head) { cin >> head; }
template<class T, class... U> void in(T &head, U &... tail) { cin >> head; in(tail...);}
//value_typeを持つ場合呼べる
//len回要素を追加する
template<class Iterable, class T = typename Iterable::value_type> Iterable tin(int len) { Iterable ret; T tem; while (len--) { cin >> tem; ret += tem; } return ret;}
template<class T> T tin() { T ret; cin >> ret; return ret;}
template<class T> T tind(int len = 0) { auto ret = tin<T>(len); dec(ret, 1); return ret;}
#define din_t2(type, a) type a;cin>>a
#define din_t3(type, a, b) type a,b;cin>>a>> b
#define din_t4(type, a, b, c) type a,b,c;cin>>a>>b>>c
#define din_t5(type, a, b, c, d) type a,b,c,d;cin>>a>>b>>c>>d
#define din_t6(type, a, b, c, d, e) type a,b,c,d,e;cin>>a>>b>>c>>d>>e
#define din_t7(type, a, b, c, d, e, f) type a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f
#define din_t(...) over7(__VA_ARGS__,din_t7,din_t6,din_t5,din_t4,din_t3 ,din_t2)(__VA_ARGS__)
#define din(...) din_t(int,__VA_ARGS__)
#define d_in
#define dsig(...) din_t(signed,__VA_ARGS__)
#define dst(...) din_t(string,__VA_ARGS__)
#define dstr dst
#define d_str dst
#define dcha(...) din_t(char,__VA_ARGS__)
#define dchar dcha
#define ddou(...) din_t(double,__VA_ARGS__)
#define din1d(a) din_t2(int, a);a--
#define din2d(a, b) din_t3(int, a,b);a--,b--
#define din3d(a, b, c) din_t4(int, a,b,c);a--,b--,c--
#define din4d(a, b, c, d) din_t5(int, a,b,c,d);a--,b--,c--,d--
#define dind(...) over4(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__)
/*@formatter:off*/
#ifdef _DEBUG
template<class T> void err2(T &&head) { cerr << head; }
template<class T, class... U> void err2(T &&head, U &&... tail) { cerr << head << " "; err2(tail...);}
template<class T, class... U> void err(T &&head, U &&... tail) { cerr << head << " "; err2(tail...); cerr << "" << endl;}
template<class T> void err(T &&head) { cerr << head << endl; }
void err() { cerr << "" << endl; }
//debで出力する最大長
constexpr int DEB_LEN = 20;
constexpr int DEB_LEN_H = 12;
string deb_tos(const int &v) { if (abs(v) == inf || abs(v) == linf)return "e"; else return to_string(v); }
template<class T> string deb_tos(const T &a) {stringstream ss;ss << a;return ss.str();}
#ifdef use_epsdou
string deb_tos(const epsdou &a) {return deb_tos(a.v);}
#endif
template<class T> string deb_tos(const optional<T> &a) { if (a.has_value()) { return deb_tos(a.value()); } else return "e"; }
template<class T> string deb_tos(const vector<T> &a, ll W = inf) { stringstream ss; if (W == inf)W = min(sz(a), DEB_LEN); if (sz(a) == 0)return ss.str(); rep(i, W) { ss << deb_tos(a[i]); if (typeid(a[i]) == typeid(P)) { ss << endl; } else { ss << " "; } } return ss.str();}
template<class T> string deb_tos(const vector<vector<T> > &a, vi H, vi W, int key = -1) { stringstream ss; ss << endl; vi lens(sz(W)); fora(h, H) { rep(wi, sz(W)) { lens[wi] = max(lens[wi], sz(deb_tos(a[h][W[wi]])) + 1); lens[wi] = max(lens[wi], sz(deb_tos(W[wi])) + 1); } } if (key == -1)ss << " *|"; else ss << " " << key << "|"; int wi = 0; fora(w, W) { ss << std::right << std::setw(lens[wi]) << w; wi++; } ss << "" << endl; rep(i, sz(W))rep(lens[i])ss << "_"; rep(i, 3)ss << "_"; ss << "" << endl; fora(h, H) { ss << std::right << std::setw(2) << h << "|"; int wi = 0; fora(w, W) { ss << std::right << std::setw(lens[wi]) << deb_tos(a[h][w]); wi++; } ss << "" << endl; } return ss.str();}
template<class T> string deb_tos(const vector<vector<T> > &a, ll H = inf, ll W = inf, int key = -1) { H = (H != inf) ? H : min({H, sz(a), DEB_LEN_H}); W = min({W, sz(a[0]), DEB_LEN_H}); vi hs, ws; rep(h, H) { hs.push_back(h); } rep(w, W) { ws.push_back(w); } return deb_tos(a, hs, ws, key);}
template<class T> string deb_tos(const vector<vector<vector<T> > > &a, ll H = inf) { stringstream ss; if (H == inf)H = DEB_LEN_H; H = min(H, sz(a)); rep(i, H) { ss << endl; ss << deb_tos(a[i], inf, inf, i); } return ss.str();}
template<class T> string deb_tos(vector<set<T> > &a, ll H = inf, ll W = inf, int key = -1) { vector<vector<T> > b(sz(a)); rep(i, sz(a)) { fora(v, a[i]) { b[i].push_back(v); }} return deb_tos(b, H, W, key);}
template<class T, size_t A> string deb_tos(T (&a)[A]) { return deb_tos(vector<T>(begin(a), end(a))); }
template<class T, size_t A, size_t B> string deb_tos(T (&a)[A][B]) { return deb_tos(vector<vector<T> >(begin(a), end(a))); }
template<class T, size_t A, size_t B, size_t C> string deb_tos(T (&a)[A][B][C]) { return deb_tos(vector<vector<vector<T> > >(begin(a), end(a))); }
/*@formatter:off*/
template<class T> void out2(T head) { cout << head; res_mes += deb_tos(head);}
template<class T, class... U> void out2(T head, U ... tail) { cout << head << " "; res_mes += deb_tos(head) + " "; out2(tail...);}
template<class T, class... U> void out(T head, U ... tail) { cout << head << " "; res_mes += deb_tos(head) + " "; out2(tail...); cout << "" << endl; res_mes += "\n";}
template<class T> void out(T head) { cout << head << endl; res_mes += deb_tos(head) + "\n";}
void out() { cout << "" << endl; }
#else
#define err(...);
template<class T> void out2(T &&head) { cout << head; }
template<class T, class... U> void out2(T &&head, U &&... tail) { cout << head << " "; out2(tail...);}
template<class T, class... U> void out(T &&head, U &&... tail) { cout << head << " "; out2(tail...); cout << "" << endl;}
template<class T> void out(T &&head) { cout << head << endl;}
void out() { cout << "" << endl;}
#endif
template<class T> void outl(const vector<T> &a, int n = inf) { rep(i, min(n, sz(a)))cout << a[i] << endl; }
//テーブルをスペースなしで出力
template<class T> void outt(vector<vector<T>> &a) { rep(i, sz(a)) { rep(j, sz(a[i])) { cout << a[i][j]; } cout << endl; }}
//int型をbit表記で出力
void outb(int a) { cout << bitset<20>(a) << endl; }
/*@formatter:off*/
template<class T> void na(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i];}
template<class T> void na(set<T> &a, ll n) { rep(i, n)a.insert(in()); }
#define dna(a, n) vi a; na(a, n);/*nを複数使うと n==in()の時バグる事に注意*/
#define dnad(a, n) vi a; nad(a, n);
template<class T> void nao(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1];}
template<class T> void naod(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1], a[i + 1]--;}
template<class T> void nad(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i], a[i]--;}
template<class T> void nad(set<T> &a, ll n) { rep(i, n)a.insert(in() - 1); }
template<class T, class U> void na2(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i];}
template<class T, class U> void na2(set<T> &a, set<U> &b, ll n) { rep(i, n) { a.insert(in()); b.insert(in()); }}
#define dna2(a, b, n) vi a,b; na2(a,b,n);
template<class T, class U> void nao2(vector<T> &a, vector<U> &b, ll n) { a.resize(n + 1); b.resize(n + 1); a[0] = b[0] = 0; rep(i, n)cin >> a[i + 1] >> b[i + 1];}
template<class T, class U> void na2d(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i], a[i]--, b[i]--;}
#define dna2d(a, b, n) vi a,b; na2d(a,b,n);
template<class T, class U, class W> void na3(vector<T> &a, vector<U> &b, vector<W> &c, ll n) {a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i];}
#define dna3(a, b, c, n) vi a,b,c; na3(a,b,c,n);
template<class T, class U, class W> void na3d(vector<T> &a, vector<U> &b, vector<W> &c, ll n) {a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--, c[i]--;}
#define dna3d(a, b, c, n) vi a,b,c; na3d(a,b,c,n);
template<class T, class U, class W, class X> void na4(vector<T> &a, vector<U> &b, vector<W> &c, vector<X> &d, ll n) {a.resize(n); b.resize(n); c.resize(n); d.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i] >> d[i];}
#define dna4(a, b, c, d, n) vi a,b,c,d; na4(a,b,c,d,n);
#define dna4d(a, b, c, d, n) vi a,b,c,d; na4d(a,b,c,d,n);
#define nt(a, h, w) resize(a,h,w);rep(nthi,h)rep(ntwi,w) cin >> a[nthi][ntwi];
#define ntd(a, h, w) resize(a,h,w);rep(ntdhi,h)rep(ntdwi,w) cin >> a[ntdhi][ntdwi], a[ntdhi][ntdwi]--;
#define ntp(a, h, w) resize(a,h+2,w+2);fill(a,'#');rep(ntphi,1,h+1)rep(ntpwi,1,w+1) cin >> a[ntphi][ntpwi];
#define dnt(S, h, w) vvi(S,h,w);nt(S,h,w);
#define dntc(S, h, w) vvc(S,h,w);nt(S,h,w);
#define dnts(S, h, w) vvs(S,h,w);nt(S,h,w);
//デバッグ
#define sp << " " <<
/*@formatter:off*/
#define deb1(x) debugName(x)<<" = "<<deb_tos(x)
#define deb_2(x, ...) deb1(x) <<", "<< deb1(__VA_ARGS__)
#define deb_3(x, ...) deb1(x) <<", "<< deb_2(__VA_ARGS__)
#define deb_4(x, ...) deb1(x) <<", "<< deb_3(__VA_ARGS__)
#define deb5(x, ...) deb1(x) <<", "<< deb_4(__VA_ARGS__)
#define deb6(x, ...) deb1(x) <<", "<< deb5(__VA_ARGS__)
//#define deb7(x, ...) deb1(x) <<", "<< deb6(__VA_ARGS__)
//#define deb8(x, ...) deb1(x) <<", "<< deb7(__VA_ARGS__)
//#define deb9(x, ...) deb1(x) <<", "<< deb8(__VA_ARGS__)
//#define deb10(x, ...) deb1(x) <<", "<< deb9(__VA_ARGS__)
/*@formatter:off*/
#ifdef _DEBUG
bool was_deb = false;
#define deb(...) do{was_deb=true;cerr<< over10(__VA_ARGS__,deb10,deb9,deb8,deb7,deb6,deb5,deb_4,deb_3,deb_2,deb1)(__VA_ARGS__) <<endl;}while(0)
#define base_keta 8
void print_n_base(int x, int base) { cerr << bitset<base_keta>(x) << endl; }
template<class T> void print_n_base(vector<T> X, int base) {cerr << endl; for (auto &&x:X) { print_n_base(x, base); } cerr << endl;}
//n進数
#define deb2(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 2);
#define deb3(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 3);
#define deb4(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 4);
#define deb_ex_deb(x, len) debugName(x)<<" = "<<deb_tos(x, len)
#define call_deb_ex_deb(x, len) deb_ex_deb(x, len)
//要素が存在する行だけ出力(vvt)
#define deb_ex(v) do {int N = sz(v);int s = N;int t = 0;rep(i, N) {if (sz(v[i])) {chmi(s, i);chma(t, i);}}auto ex_v = sub(v, s, N);str S = deb_tos(ex_v, sz(ex_v));debugName(v);cerr<<" = "<<endl;cerr << S << endl;} while (0);
#define debi(A) {int len=min(sz(A),20); was_deb=true;cerr<<debugName(A)<<" = "<<endl;rep(i, len)cerr<<std::right << std::setw((int)(sz(tos(A[i]))+(i ? 1 : 0)))<<(i%10);cerr<<endl;rep(i, len)cerr<<std::right << std::setw((int)(sz(tos(A[i]))+(i ? 1 : 0)))<<A[i];cerr<<endl;}
template<class T, class F> string deb_tos_f(vector<vector<T> > &a, F f, int key = -1) {vi hs, ws_; int H = sz(a), W = sz(a[0]); vi exh(H), exw(W); rep(h, H) { rep(w, W) { if (f(a[h][w])) { exh[h] = true; exw[w] = true; } } } rep(h, H) if (exh[h])hs.push_back(h); rep(w, W) if (exw[w])ws_.push_back(w); return deb_tos(a, hs, ws_, key);}
template<class T, class F> string deb_tos_f(vector<vector<vector<T>>> &a, F f) {stringstream ss; int H = sz(a); if (sz(a) == 0)return ss.str(); rep(i, H) { ss << deb_tos_f(a[i], f, i); } ss << "" << endl; return ss.str();}
#define debf_normal(tab, f) do{cerr<<debugName(tab)<<" = "<<endl;cerr<< deb_tos_f(tab, f)<<endl;}while(0);
#define debf2(tab, siki_r) debf_normal(tab, lamr(siki_r))
#define debf3(tab, v, siki) debf_normal(tab, lam(siki))
//S, sikir
//S, v, siki
#define debf(...) over3(__VA_ARGS__,debf3,debf2,debf1)(__VA_ARGS__)
#else
#define deb(...) ;
#define deb2(...) ;
#define deb3(...) ;
#define deb4(...) ;
#define deb_ex(...) ;
#define debf(...) ;
#define debi(...) ;
#endif
#define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'
/*@formatter:off*/
using u32 = unsigned;
using u64 = unsigned long long;
using u128 = __uint128_t;
using bint =__int128;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {std::ostream::sentry s(dest);if (s) {__uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } ll len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } }return dest;}
__int128 to_bint(string &s) {__int128 ret = 0; for (ll i = 0; i < (ll) s.length(); ++i) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret;}
void operator>>(istream &iss, bint &v) {string S; iss >> S; v = 0; rep(i, sz(S)) { v *= 10; v += S[i] - '0'; }}
//便利関数
/*@formatter:off*/
//テスト用
#define rand xor128_
unsigned long xor128_(void) {static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t; t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));}
char ranc() { return (char) ('a' + rand() % 26); }
ll rand(ll min, ll max) {assert(min <= max); if (min >= 0 && max >= 0) { return rand() % (max + 1 - min) + min; } else if (max < 0) { return -rand(-max, -min); } else { if (rand() % 2) { return rand(0, max); } else { return -rand(0, -min); }}}
ll rand(ll max) { return rand(0, max); }
template<class T> T rand(vector<T> &A) { return A[rand(sz(A) - 1)]; }
//重複することがある
template<class T> vector<T> ranv(vector<T> &A, int N) {vector<T> ret(N); rep(i, N) { ret[i] = rand(A); } return ret;}
template<class T> vector<T> ranv_unique(vector<T> &A, int N) {vector<T> ret(N); umapi was; rep(j, N) { int i; while (1) { i = rand(sz(A) - 1); if (was.find(i) == was.end())break; } ret[j] = A[i]; was[i] = 1; } return ret;}
vi ranv(ll n, ll min, ll max) {vi v(n); rep(i, n)v[i] = rand(min, max); return v;}
/*@formatter:off*/
#ifdef _DEBUG
bool timeup(int time) {static bool never = true; if (never)message += "may timeup, because slow"; never = false; auto end_time = system_clock::now(); auto part = duration_cast<milliseconds>(end_time - start_time); auto lim = milliseconds(time); return part >= lim;}
#else
bool timeup(int time) {
auto end_time = system_clock::now();
auto part = duration_cast<milliseconds>(end_time - start_time);
auto lim = milliseconds(time);
return part >= lim;
}
#endif
void set_time() { past_time = system_clock::now(); }
//MS型(millisecqnds)で返る
//set_timeをしてからの時間
auto calc_time_milli() {auto now = system_clock::now(); auto part = duration_cast<milliseconds>(now - past_time); return part;}
auto calc_time_micro() {auto now = system_clock::now(); auto part = duration_cast<microseconds>(now - past_time); return part;}
auto calc_time_nano() {auto now = system_clock::now(); auto part = duration_cast<nanoseconds>(now - past_time); return part;}
bool calc_time(int zikan) { return calc_time_micro() >= microseconds(zikan); }
using MS=std::chrono::microseconds;
int div(microseconds a, microseconds b) { return a / b; }
int div(nanoseconds a, nanoseconds b) {if (b < nanoseconds(1)) { return a / nanoseconds(1); } int v = a / b; return v;}
//set_time();
//rep(i,lim)shori
//lim*=time_nanbai();
//rep(i,lim)shoriと使う
//全体でmilliかかっていいときにlimを何倍してもう一回できるかを返す
int time_nanbai(int milli) {auto dec = duration_cast<nanoseconds>(past_time - start_time); auto part = calc_time_nano(); auto can_time = nanoseconds(milli * 1000 * 1000); can_time -= part; can_time -= dec; return div(can_time, part);}
/*@formatter:off*/
//#define use_rand
#ifdef use_rand
str ransu(ll n) {str s; rep(i, n)s += (char) rand('A', 'Z'); return s;}
str ransl(ll n) {str s; rep(i, n)s += (char) rand('a', 'z'); return s;}
//単調増加
vi ranvinc(ll n, ll min, ll max) {vi v(n); bool bad = 1; while (bad) { bad = 0; v.resize(n); rep(i, n) { if (i && min > max - v[i - 1]) { bad = 1; break; } if (i)v[i] = v[i - 1] + rand(min, max - v[i - 1]); else v[i] = rand(min, max); } } return v;}
//便利 汎用
#endif
void ranvlr(ll n, ll min, ll max, vi &l, vi &r) {l.resize(n); r.resize(n); rep(i, n) { l[i] = rand(min, max); r[i] = l[i] + rand(0, max - l[i]); }}
template<class Iterable, class T = typename Iterable::value_type> vector<pair<T, int>> run_length(const Iterable &a) {vector<pair<T, int>> ret; ret.eb(a[0], 1); rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }} return ret;}
/*@formatter:off*/
//#define use_mgr //_goldd _goldt
#ifdef use_mgr
//->[i, f(i)]
template<class T, class U, class F> auto mgr(T ok, U ng, const F &f, require_arg(is_integral<T>::value &&is_integral<U>::value)) { auto mid = (ok + ng); if (ok < ng) while (ng - ok > 1) { mid = (ok + ng) >> 1; if (f(mid))ok = mid; else ng = mid; } else while (ok - ng > 1) { mid = (ok + ng) >> 1; if (f(mid))ok = mid; else ng = mid; } return ok;}
//[l, r)の中で,f(i)がtrueとなる範囲を返す okはそこに含まれる
template<class F> P mgr_range(int l, int r, F f, int ok) {if (f(ok) == 0) { out("f(ok) must true"); re(); } return mp(mgr(ok, l - 1, f), mgr(ok, r, f) + 1);}
template<class F> auto mgrd(dou ok, dou ng, F f, int kai = 100) {if (ok < ng) rep(i, kai) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } else rep(i, kai) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } return ok;}
template<class F> dou mgrd_time(dou ok, dou ng, F f, int time = 1980) {bool han = true; if (ok < ng) while (1) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); if (timeup(time)) { break; } } else while (1) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); if (timeup(time)) { break; } } return ok;}
//todo 減らす
template<class F> auto goldd_l(ll left, ll right, F calc) {double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } ll minScore = MAX<ll>(); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (minScore > score) { minScore = score; resIndex = i; } } return make_tuple(resIndex, calc(resIndex));}
template<class F> auto goldt_l(ll left, ll right, F calc) {double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } if (left > right) { ll l = left; left = right; right = l; } ll maxScore = MIN<ll>(); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (maxScore < score) { maxScore = score; resIndex = i; } } return make_tuple(resIndex, calc(resIndex));}
/*loopは200にすればおそらく大丈夫 余裕なら300に*/
template<class F> auto goldd_d(dou left, dou right, F calc, ll loop = 200) {dou GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); /*200にすればおそらく大丈夫*/ /*余裕なら300に*/ ll k = 141; loop++; while (--loop) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return make_tuple(left, calc(left));}
template<class F> auto goldt_d(dou left, dou right, F calc, ll loop = 200) {double GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); loop++; while (--loop) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return make_tuple(left, calc(left));}
//l ~ rを複数の区間に分割し、極致を与えるiを返す time-20 msまで探索
template<class F> auto goldd_ls(ll l, ll r, F calc, ll time = 2000) { auto lim = milliseconds(time - 20); ll mini = 0, minv = MAX<ll>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldd_l(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(mini, calc(mini));}
template<class F> auto goldt_ls(ll l, ll r, F calc, ll time = 2000) {auto lim = milliseconds(time - 20); ll maxi = 0, maxv = MIN<ll>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldt_l(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(maxi, calc(maxi));}
template<class F> auto goldd_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を持つ*/ auto lim = milliseconds(time - 20); dou mini = 0, minv = MAX<dou>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldd_d(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(mini, calc(mini));}
template<class F> auto goldt_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を残している*/ auto lim = milliseconds(time - 20); dou maxi = 0, maxv = MIN<dou>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldt_d(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(maxi, calc(maxi));}
#endif
//strを整数として比較
string smax(str &a, str b) { if (sz(a) < sz(b)) { return b; } else if (sz(a) > sz(b)) { return a; } else if (a < b)return b; else return a; }
//strを整数として比較
string smin(str &a, str b) { if (sz(a) > sz(b)) { return b; } else if (sz(a) < sz(b)) { return a; } else if (a > b)return b; else return a; }
//エラー-1
template<typename W, typename T> ll find(vector<W> &a, int l, const T key) {rep(i, l, sz(a))if (a[i] == key)return i;return -1;}
template<typename W, typename T> ll find(vector<W> &a, const T key) {rep(i, sz(a))if (a[i] == key)return i;return -1;}
template<typename W, typename T> P find(vector<vector<W >> &a, const T key) {rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return mp(i, j);return mp(-1, -1);}
//getid(find())を返す 1次元にする
template<typename W, typename T> int findi(vector<vector<W >> &a, const T key) {rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return i * sz(a[0]) + j;return -1;}
template<typename W, typename U> tuple<int, int, int> find(vector<vector<vector<W >>> &a, const U key) { rep(i, sz(a))rep(j, sz(a[0]))rep(k, sz(a[0][0]))if (a[i][j][k] == key)return tuple<int, int, int>(i, j, k); return tuple<int, int, int>(-1, -1, -1);}
//無ければ-1
int find(string &s, const string key) { int klen = sz(key); rep(i, sz(s) - klen + 1) { if (s[i] != key[0])continue; if (s.substr(i, klen) == key) { return i; } }return -1;}
int find(string &s, int l, const string key) { int klen = sz(key); rep(i, l, sz(s) - klen + 1) { if (s[i] != key[0])continue; if (s.substr(i, klen) == key) { return i; } } return -1;}
int find(string &s, const char key) { rep(i, sz(s)) { if (s[i] == key)return i; } return -1;}
int find(string &s, int l, const char key) { rep(i, l, sz(s)) { if (s[i] == key)return i; } return -1;}
//N箇所について右のkeyの場所を返す
template<typename W, typename T> vi finds(const W &a, const T& key) { int n = sz(a); vi rpos(n, -1); rer(i, n-1){ if(i<n-1){ rpos[i] = rpos[i+1]; } if(a[i]==key)rpos[i] = i; } return rpos;}
template<typename W, typename T> vi rfinds(const W &a, const T& key) { int n = sz(a); vi lpos(n, -1); rep(i, n){ if(i> 0){ lpos[i] = lpos[i-1]; } if(a[i]==key)lpos[i] = i; } return lpos;}
//todoz
#if __cplusplus >= 201703L
template<typename W, typename T, class Iterable = typename W::value_type>
ll count(const W &a, const T &k) { return count_if(a, ==k); }
/*@formatter:on*/
template<typename W, class Iterable = typename W::value_type> vi count(const W &a) {
vi res;
for_each(a, v, if (sz(res) <= (int) v)res.resize((int) v + 1);
res[v]++;);
return res;
}
#endif
/*@formatter:off*/
ll count(const str &a, const str &k) { ll ret = 0, len = k.length(); auto pos = a.find(k); while (pos != string::npos)pos = a.find(k, pos + len), ++ret; return ret;}
/*@formatter:off*/
//'a' = 'A' = 0 として集計 既に-'a'されていても動く
vi count(str &a, int l, int r) { vi cou(26); char c = 'a'; if ('A' <= a[l] && a[l] <= 'Z')c = 'A'; if ('a' <= a[l] && a[l] <= 'z') c = 'a'; else c = 0; rep(i, l, r)++cou[a[i] - c]; return cou;}
#define couif count_if
//algorythm
ll rev(ll a) { ll res = 0; while (a) { res *= 10; res += a % 10; a /= 10; } return res;}
template<class T> auto rev(const vector<T> &a) { auto b = a; reverse(ALL(b)); return b;}
/* \反転 */ template<class U>
auto rev(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[h][w]; return b;}
/* |反転 */ template<class U>
auto revw(vector<vector<U>> &a) { vector<vector<U> > b(sz(a), vector<U>(sz(a[0]))); int W = sz(a[0]); rep(h, sz(a)) rep(w, sz(a[0])) { b[h][W - 1 - w] = a[h][w]; } return b;}
/* ー反転 */ template<class U>
auto revh(vector<vector<U>> &a) { vector<vector<U> > b(sz(a), vector<U>(sz(a[0]))); int H = sz(a); rep(h, sz(a)) rep(w, sz(a[0])) { b[H - 1 - h][w] = a[h][w]; } return b;}
/* /反転 */ template<class U>
auto revr(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); int H = sz(a); int W = sz(a[0]); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[H - 1 - h][W - 1 - w]; return b;}
auto rev(const string &a) { string b = a; reverse(ALL(b)); return b;}
template<class T> auto rev(const T &v, int i) {return v[sz(v) - 1 - i];}
int rev(int N, int i) {return N-1-i;}
constexpr ll p10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000ll, 100000000000ll, 1000000000000ll, 10000000000000ll, 100000000000000ll, 1000000000000000ll, 10000000000000000ll, 100000000000000000ll, 1000000000000000000ll};
//0は0桁
ll keta(ll v, int if_zero_res) { if(!v)return if_zero_res;if (v < p10[9]) { if (v < p10[4]) { if (v < p10[2]) { if (v < p10[1]) { if (v < p10[0])return 0; else return 1; } else return 2; } else { if (v < p10[3]) return 3; else return 4; }} else { if (v < p10[7]) { if (v < p10[5]) return 5; else if (v < p10[6])return 6; else return 7; } else { if (v < p10[8])return 8; else return 9; }}} else { if (v < p10[13]) { if (v < p10[11]) { if (v < p10[10]) return 10; else return 11; } else { if (v < p10[12]) return 12; else return 13; }} else { if (v < p10[15]) { if (v < p10[14]) return 14; else return 15; } else { if (v < p10[17]) { if (v < p10[16]) return 16; else return 17; } else { if (v < p10[18])return 18; else return 19; }}}}}
#if __cplusplus >= 201703L
ll getr(ll a, ll keta) { return (a / pow<ll>(10, keta)) % 10; }
#else
ll getr(ll a, ll keta) { return (a / (int)pow(10, keta)) % 10; }
#endif
//上から何桁目か
ll getl(ll a, ll ket) {int sketa = keta(a, 1);return getr(a, sketa - 1 - ket);}
ll dsum(ll v, ll sin = 10) {ll ret = 0;for (; v; v /= sin)ret += v % sin;return ret;}
ll mask10(ll v) { return p10[v] - 1; }
//変換系
template<class T, class U> auto to_v1(vector<reference_wrapper<U>>& ret, vector<T> &A) { rep(i, sz(A))ret.push_back(A[i]); return ret;}
template<class T, class U> auto to_v1(vector<reference_wrapper<U>>& ret, vector<vector<T> > &A) {rep(i, sz(A))to_v1(ret, A[i]);return ret;}
//参照付きで1次元に起こす
template<class T> auto to_v1(vector<vector<T> > &A) { vector<reference_wrapper<typename decl2<decltype(A)>::type>> ret; rep(i, sz(A))to_v1(ret, A[i]); return ret;}
//[v] := iとなるようなvectorを返す
//存在しない物は-1
//空でも動く(なぜか)
template<class T> auto keys(const T& a) { vector<decltype((a.begin())->fi)> res; for (auto &&k :a)res.push_back(k.fi); return res;}
template<class T> auto values(const T& a) { vector<decltype((a.begin())->se)> res; for (auto &&k :a)res.push_back(k.se); return res;}
//todo 可変長で
template<class T> constexpr T min(T a, T b, T c) { return a >= b ? b >= c ? c : b : a >= c ? c : a; }
template<class T> constexpr T max(T a, T b, T c) { return a <= b ? b <= c ? c : b : a <= c ? c : a; }
template<class V, class T = typename V::value_type> T min(V &a, ll s = -1, ll n = -1) { set_lr12(s, n, sz(a)); return *min_element(a.begin() + s, a.begin() + min(n, sz(a))); }
template<class V, class T = typename V::value_type> T max(V &a, ll s = -1, ll n = -1) { set_lr12(s, n,sz(a)); return *max_element(a.begin() + s, a.begin() + min(n, sz(a))); }
template<class T> int mini(const vector<T> &a) { return min_element(ALL(a)) - a.begin(); }
template<class T> int maxi(const vector<T> &a) { return max_element(ALL(a)) - a.begin(); }
template<class T> T sum(const vector<T> &A, int l = -1, int r = -1) { T s = 0; set_lr12(l, r, sz(A)); rep(i, l, r)s += A[i]; return s;}
template<class T> auto sum(const vector<vector<T>> &A) { decl2<decltype(A)> s = 0; rep(i, sz(A))s += sum(A[i]); return s;}
template<class T> T min(const vector<T>& A, int l = -1, int r = -1 ){T s=MAX<T>();set_lr12(l, r, sz(A));rep(i, l, r)s=min(s, A[i]);return s;}
template<class T> auto min(const vector<vector<T>>& A ){using S =decl2<decltype(A)>; S s=MAX<S>();rep(i, sz(A))s=min(s, A[i]);return s;}
template<class T> T max(const vector<T>& A, int l = -1, int r = -1 ){T s=MIN<T>();set_lr12(l, r, sz(A));rep(i, l, r); rep(i, l, r)s=max(s, A[i]);return s;}
template<class T> auto max(const vector<vector<T>>& A ){using S =decl2<decltype(A)>;S s=MIN<S>();rep(i, sz(A))s=max(s, A[i]);return s;}
template<class T> T mul(vector<T> &v, ll t = inf) { T ret = v[0]; rep(i, 1, min(t, sz(v)))ret *= v[i]; return ret;}
//template<class T, class U, class... W> auto sumn(vector<T> &v, U head, W... tail) { auto ret = sum(v[0], tail...); rep(i, 1, min(sz(v), head))ret += sum(v[i], tail...); return ret;}
//indexを持つvectorを返す
vi inds_(vi &a) { int n = max(a) + 1; vi ret(n, -1); rep(i, sz(a)) { assert(ret[a[i]] ==-1);ret[a[i]] = i; } return ret;}
void clear(PQ &q) { q = PQ(); }
void clear(priority_queue<int> &q) { q = priority_queue<int>(); }
template<class T> void clear(queue<T> &q) { while (q.size())q.pop(); }
//template<class T> T *negarr(ll size) { T *body = (T *) malloc((size * 2 + 1) * sizeof(T)); return body + size;}
//template<class T> T *negarr2(ll h, ll w) { double **dummy1 = new double *[2 * h + 1]; double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)]; dummy1[0] = dummy2 + w; for (ll i = 1; i <= 2 * h + 1; ++i) { dummy1[i] = dummy1[i - 1] + 2 * w + 1; } double **a = dummy1 + h; return a;}
template<class T> struct ruiC {
vector<T> rui;
ruiC(vector<T> &ru) : rui(ru) {}
/*先頭0*/
ruiC() : rui(1, 0) {}
T operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } return rui[r] - rui[l]; }
T operator()(int r = inf) { return operator()(0, min(r, sz(rui) - 1)); }
/*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/
/*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/
// T operator[](ll i) { return rui[i + 1] - rui[i]; }
T operator[](ll i) { return rui[i]; }
/*0から順に追加される必要がある*/
void operator+=(T v) { rui.push_back(rui.back() + v); }
void add(int i, T v) {if (sz(rui) - 1 != i)ole();operator+=(v);}
T back() { return rui.back(); }
ll size() { return rui.size(); }
auto begin() { return rui.begin(); }
auto end() { return rui.end(); }
};
template<class T> string deb_tos(const ruiC<T> &a) {return deb_tos(a.rui);}
template<class T> ostream &operator<<(ostream &os, ruiC<T> a) { fora(v, a.rui){os << v << " "; } return os;}
template<class T> vector<T> ruiv(const vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i]; return ret;}
template<class T> ruiC<T> ruic(const vector<T> &a) { vector<T> ret = ruiv(a); return ruiC<T>(ret);}
template<class T> ruiC<T> ruic() { return ruiC<T>(); }
//imoは0-indexed
//ruiは1-indexed
template<class T> vector<T> imo(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret;}
//#define use_rui //_imo _ruic _ruiv
#ifdef use_rui
//kと同じものの数
template<class T, class U> vi imo(const vector<T> &a, U k) { vi equ(sz(a)); rep(i, sz(a)){ equ[i] = a[i]==k; } return imo(equ);}
template<class T> vector<T> imox(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] ^= ret[i]; return ret;}
//漸化的に最小を持つ
template<class T> vector<T> imi(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chmi(ret[i + 1], ret[i]); return ret;}
template<class T> vector<T> ima(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chma(ret[i + 1], ret[i]); return ret;}
template<class T> vector<T> rimi(const vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chmi(ret[i - 1], ret[i]); return ret;}
template<class T> vector<T> rima(const vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chma(ret[i - 1], ret[i]); return ret;}
template<class T> struct ruimax {
template<typename Monoid> struct SegmentTree { /*pairで処理*/ int sz; vector<Monoid> seg; const Monoid M1 = mp(MIN<T>(), -1); Monoid f(Monoid a, Monoid b) { return max(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } };
private:
vector<T> ve;
SegmentTree<pair<T, int>> seg;
vector<T> rv;
vector<int> ri;
bool build = false;
public:
int n;
ruimax(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; T ma = MIN<T>(); rv.resize(n + 1); ri.resize(n + 1); rv[0] = -INF<T>; ri[0] = -1; rep(i, n) { if (chma(ma, a[i])) { index = i; } rv[i + 1] = ma; ri[i + 1] = index; } }
T operator()(int l, int r) { if (!(l <= r && 0 <= l && r <= n)) { deb(l, r, n); assert(0); } if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } }
T operator()(int r = inf) { return operator()(0, min(r, n)); }
T operator[](int r) { return operator()(0, r); }
T getv(int l, int r) { return operator()(l, r); }
T getv(int r = inf) { return getv(0, min(r, n)); };
int geti(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } }
int geti(int r = inf) { return geti(0, min(r, n)); };
auto begin() { return rv.begin(); }
auto end() { return rv.end(); }
};
template<class T> struct ruimin {
template<typename Monoid> struct SegmentTree { /*pairで処理*/ int sz;vector<Monoid> seg; const Monoid M1 = mp(MAX<T>(), -1); Monoid f(Monoid a, Monoid b) { return min(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } };
private:
vector<T> ve;
SegmentTree<pair<T, int>> seg;
vector<T> rv;
vector<int> ri;
bool build = false;
int n;
public:
ruimin(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; T mi = MAX<T>(); rv.resize(n + 1); ri.resize(n + 1); rv[0] = INF<T>; ri[0] = -1; rep(i, n) { if (chmi(mi, a[i])) { index = i; } rv[i + 1] = mi; ri[i + 1] = index; } }
T operator()(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } }
T operator()(int r = inf) { return operator()(0, min(r, n)); }
T operator[](int r) { return operator()(0, r); }
T getv(int l, int r) { return operator()(l, r); }
T getv(int r = inf) { return getv(0, min(r, n)); };
int geti(int l, int r) { { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } } assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } }
int geti(int r = inf) { return geti(0, min(r, n)); };
auto begin() { return rv.begin(); }
auto end() { return rv.end(); }
};/*@formatter:off*/
vvi() ruib(vi &a) { vvi(res, 61, sz(a) + 1); rep(k, 61) { rep(i, sz(a)) { res[k][i + 1] = res[k][i] + ((a[i] >> k) & 1); }} return res;}
vector<ruiC<int>> ruibc(vi &a) {vector<ruiC<int>> ret(61); vvi(res, 61, sz(a)); rep(k, 61) { rep(i, sz(a)) { res[k][i] = (a[i] >> k) & 1; } ret[k] = ruic(res[k]); } return ret;}
//kと同じものの数
template<class T, class U> vi ruiv(T &a, U k) { vi ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + (a[i] == k); return ret;}
template<class T, class U> ruiC<ll> ruic(T &a, U k) { vi ret = ruiv(a, k); return ruiC<ll>(ret);}
template<class T> struct ruiC2 {
int H;
vector<ruiC<T>> rui;
ruiC<T> dummy;//変なのをよばれたときはこれを返す//todo
ruiC2(const vector<vector<T>> &ru) : rui(sz(ru)), H(sz(ru)) { for (int h = 0; h < H; h++) { if (sz(ru[h]) == 0)continue; if (sz(dummy) == 1) dummy = ruic(vector<T>(sz(ru[h]))); rui[h] = ruic(ru[h]); } }
//WについてHを返す
vector<T> operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } vector<T> res(H); for (int h = 0; h < H; h++)res[h] = rui[h](l, r); return res; }
//HについてWを返す
ruiC<T> &operator[](ll h) {
#ifdef _DEBUG
if (h >= H) {message += "warning ruiC h >= H";}
#endif
if (h >= H || sz(rui[h]) == 1)return dummy;else return rui[h];
}
/*@formatter:off*/
// vector<T> operator()(int r) { return operator()(0, r); }
/*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/
/*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/
// T operator[](ll i) { return rui[i + 1] - rui[i]; }
/*0から順に追加される必要がある*/
// T back() { return rui.back(); }
// ll size() { return rui.size(); }
// auto begin(){return rui.begin();}
// auto end(){return rui.end();}
};
template<class T, class U> ruiC<ll> ruicou(vector<T> &a, U b) { vi cou(sz(a)); rep(i, sz(a)) { cou[i] = a[i] == b; } return ruic(cou);}
//メモリは形式によらず(26*N)
// rui(l,r)でvector(26文字について, l~rのcの個数)
// rui[h] ruic()を返す
// 添え字は'a', 'A'のまま扱う (予め-='a','A'されているものが渡されたらそれに従う)
template<typename Iterable, class is_Iterable = typename Iterable::value_type>
ruiC2<ll> ruicou(const Iterable &a) { int H = max(a) + 1; vvi(cou, H); rep(i, sz(a)) { if (sz(cou[a[i]]) == 0)cou[a[i]].resize(sz(a)); cou[a[i]][i] = 1; } return ruiC2<ll>(cou); }
/*@formatter:off*/
//h query
template<class T> vector<T> imoh(vector<vector<T>> &v, int w) { vector<T> ret(sz(v)); rep(h, sz(ret)) { ret[h] = v[h][w]; } rep(i, sz(ret) - 1) { ret[i + 1] += ret[i]; } return ret;}
template<class T> vector<T> ruih(vector<vector<T>> &v, int w) { vector<T> ret(sz(v) + 1); rep(h, sz(v)) { ret[h + 1] = v[h][w]; } rep(i, sz(v)) { ret[i + 1] += ret[i]; } return ret;}
template<class T> ruiC<T> ruihc(vector<vector<T>> &a, int w) { vector<T> ret = ruih(a, w); return ruiC<T>(ret);}
//xor
template<class T> struct ruixC {
vector<T> rui;
ruixC(vector<T> &ru) : rui(ru) {}
T operator()(ll l, ll r) { if (l > r) { cerr << "ruiXc "; deb(l, r); assert(0); } return rui[r] ^ rui[l]; }
T operator[](ll i) { return rui[i]; }
T back() { return rui.back(); }
ll size() { return rui.size(); }
};
template<class T> vector<T> ruix(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] ^ a[i]; return ret;}
template<class T> ruixC<ll> ruixc(vector<T> &a) { vi ret = ruix(a); return ruixC<ll>(ret);}
//差分を返す(累積を取ると元に戻る)
//101なら
//1111を返す
//元の配列で[l, r)へのxorは
//[l]と[r]へのxorになる https://atcoder.jp/contests/abc155/tasks/abc155_f
vi ruix_diff(vi &A) { int N = sz(A); assert(N); vi res(N + 1); res[0] = A[0]; rep(i, 1, N) { res[i] = A[i - 1] ^ A[i]; } res[N] = A[N - 1]; return res;}
template<class T> vector<T> ruim(vector<T> &a) { vector<T> res(a.size() + 1, 1); rep(i, a.size())res[i + 1] = res[i] * a[i]; return res;}
//漸化的に最小を1indexで持つ
template<class T> vector<T> ruimi(vector<T> &a) {ll n = sz(a); vector<T> ret(n + 1); rep(i, 1, n) { ret[i] = a[i - 1]; chmi(ret[i + 1], ret[i]); } return ret;}
//template<class T> T *rrui(vector<T> &a) {
//右から左にかけての半開区間 (-1 n-1]
template<class T> struct rruiC {
vector<T> rui;
int n;
rruiC(vector<T> &a) : n(sz(a)) { rui.resize(n + 1); rer(i, n - 1) { rui[i] = rui[i + 1] + a[i]; } }
/*[r l)*/
T operator()(int r, int l) { r++; l++; assert(l <= r && l >= 0 && r <= n); return rui[l] - rui[r]; }
T operator()(int l) { return operator()(n - 1, l); }
T operator[](int i) { return operator()(i); }
};
template<class T> ostream &operator<<(ostream &os, rruiC<T> a) { fora(v, a.rui){os << v << " "; } return os;}
template<class T> string deb_tos(rruiC<T> &a) {return deb_tos(a.rui);}
#define rrui rruic
template<class T> rruiC<T> rruic(vector<T> &a) { return rruiC<T>(a); }
//掛け算
template<class T> struct ruimulC {
vector<T> rv;
int n;
ruimulC(vector<T> &a) : rv(a), n(sz(a)) { rv.resize(n + 1); rv[0] = 1; rep(i, n) { rv[i + 1] = a[i] * rv[i]; } }
ruimulC() : n(0) { rv.resize(n + 1); rv[0] = 1; }
void operator+=(T v) { rv.push_back(rv.back() * v); n++; }
T operator()(int l, int r) { assert(l <= r && 0 <= l && r <= n); return rv[r] / rv[l]; }
T operator()(int r = inf) { return operator()(0, min(r, n)); }
T operator[](int r) { return operator()(0, r); }
auto begin() { return rv.begin(); }
auto end() { return rv.end(); }
};
template<class T> ruimulC<T> ruimul(vector<T> &a) { return ruimulC<T>(a); }
template<class T> ruimulC<T> ruimul() { vector<T> a; return ruimulC<T>(a);}
template<class T> T *rruim(vector<T> &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; res[len - 1] = 1; rer(i, len - 1)res[i - 1] = res[i] * a[i]; return res;}
template<class T, class U, class W> T lowerBound(ruiC <T> &a, U v, W banpei) { return lowerBound(a.rui, v, banpei); }
template<class T, class U, class W> T upperBound(ruiC <T> &a, U v, W banpei) { return upperBound(a.rui, v, banpei); }
template<class T, class U, class W> T rlowerBound(ruiC <T> &a, U v, W banpei) { return rlowerBound(a.rui, v, banpei); }
template<class T, class U, class W> T rupperBound(ruiC <T> &a, U v, W banpei) { return rupperBound(a.rui, v, banpei); }
#endif
constexpr bool bget(ll m, ll keta) {
#ifdef _DEBUG
assert(keta <= 62);//オーバーフロー 1^62までしか扱えない
#endif
return (m >> keta) & 1;
}
//bget(n)次元
// NならN-1まで
vector<vi> bget2(vi &a, int keta_size) { vvi(res, keta_size, sz(a)); rep(k, keta_size) { rep(i, sz(a)) { res[k][i] = bget(a[i], k); }} return res;}
vi bget1(vi &a, int keta) { vi res(sz(a)); rep(i, sz(a)) { res[i] = bget(a[i], keta); } return res;}
#if __cplusplus >= 201703L
ll bget(ll m, ll keta, ll sinsuu) { m /= pow<ll>(sinsuu, keta); return m % sinsuu;}
#else
ll bget(ll m, ll keta, ll sinsuu) { m /= (ll)pow(sinsuu, keta); return m % sinsuu;}
#endif
constexpr ll bit(ll n) {
#ifdef _DEBUG
assert(n <= 62);//オーバーフロー 1^62までしか扱えない
#endif
return (1LL << (n));
}
#if __cplusplus >= 201703L
ll bit(ll n, ll sinsuu) { return pow<ll>(sinsuu, n); }
#else
ll bit(ll n, ll sinsuu) { return (ll)pow(sinsuu, n); }
#endif
ll mask(ll n) { return (1ll << n) - 1; }
//aをbitに置きなおす
//{0, 2} -> 101
ll bit(const vi &a) { int m = 0; for (auto &&v:a) m |= bit(v); return m;}
//{1, 1, 0} -> 011
//bitsetに置き換える感覚 i が立っていたら i bit目を立てる
ll bit_bool(vi &a) { int m = 0; rep(i, sz(a)) if (a[i])m |= bit(i); return m;}
#define bcou __builtin_popcountll
//最下位ビット
ll lbit(ll n) { assert(n);return n & -n; }
ll lbiti(ll n) { assert(n);return log2(n & -n); }
//最上位ビット
ll hbit(ll n) { assert(n);n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); n |= (n >> 32); return n - (n >> 1);}
ll hbiti(ll n) { assert(n);return log2(hbit(n)); }
//ll hbitk(ll n) { ll k = 0; rer(i, 5) { ll a = k + (1ll << i); ll b = 1ll << a; if (b <= n)k += 1ll << i; } return k;}
//初期化は0を渡す
ll nextComb(ll &mask, ll n, ll r) { if (!mask)return mask = (1LL << r) - 1; ll x = mask & -mask; /*最下位の1*/ ll y = mask + x; /*連続した下の1を繰り上がらせる*/ ll res = ((mask & ~y) / x >> 1) | y; if (bget(res, n))return mask = 0; else return mask = res;}
//n桁以下でビットがr個立っているもののvectorを返す
vi bitCombList(ll n, ll r) { vi res; ll m = 0; while (nextComb(m, n, r)) { res.push_back(m); } return res;}
/*over*/#define forbit1_2(i, mas) for (int forbitj = !mas ? 0 : lbit(mas), forbitm = mas, i = !mas ? 0 :log2(forbitj); forbitm; forbitm = forbitm ^ forbitj, forbitj = !forbitm ? 1 : lbit(forbitm), i = log2(forbitj))
/*over*/#define forbit1_3(i, N, mas) for (int forbitj = !mas ? 0 : lbit(mas), forbitm = mas, i = !mas ? 0 :log2(forbitj); forbitm && i < N; forbitm = forbitm ^ forbitj, forbitj = !forbitm ? 1 : lbit(forbitm), i = log2(forbitj))
//masの立ってるindexを見る
// i, [N], mas
#define forbit1(...) over3(__VA_ARGS__, forbit1_3, forbit1_2)(__VA_ARGS__)
//masが立っていないindexを見る
// i, N, mas
#define forbit0(i, N, mas) forbit1(i, mask(N) & (~(mas)))
//forsubをスニペットして使う
//Mの部分集合(0,M含む)を見る 3^sz(S)個ある
#define forsub_all(m, M) for (int m = M; m != -1; m = m == 0 ? -1 : (m - 1) & M)
//BASE進数
template<size_t BASE> class base_num {
int v;
public:
base_num(int v = 0) : v(v) {};
int operator[](int i) { return bget(v, i, BASE); }
void operator++() { v++; }
void operator++(signed) { v++; }
operator int() { return v; }
};
#define base3(mas, lim, BASE) for (base_num<BASE> mas; mas < lim; mas++)
#define base2(mas, lim) base3(mas, lim, 2)
#define base(...) over3(__VA_ARGS__,base3,base2,base1)(__VA_ARGS__)
//aにある物をtrueとする
vb bool_(vi a, int n) { vb ret(max(max(a) + 1, n)); rep(i, sz(a))ret[a[i]] = true; return ret;}
char itoal(ll i) { return 'a' + i; }
char itoaL(ll i) { return 'A' + i; }
ll altoi(char c) { if ('A' <= c && c <= 'Z')return c - 'A'; return c - 'a';}
ll ctoi(char c) { return c - '0'; }
char itoc(ll i) { return i + '0'; }
ll vtoi(vi &v) { ll res = 0; if (sz(v) > 18) { debugline("vtoi"); deb(sz(v)); ole(); } rep(i, sz(v)) { res *= 10; res += v[i]; } return res;}
vi itov(ll i) { vi res; while (i) { res.push_back(i % 10); i /= 10; } res = rev(res); return res;}
vi stov(string &a) { ll n = sz(a); vi ret(n); rep(i, n) { ret[i] = a[i] - '0'; } return ret;}
//基準を満たさないものは0になる
vi stov(string &a, char one) { ll n = sz(a); vi ret(n); rep(i, n)ret[i] = a[i] == one; return ret;}
vector<vector<ll>> ctoi(vector<vector<char>> s, char c) { ll n = sz(s), m = sz(s[0]); vector<vector<ll>> res(n, vector<ll>(m)); rep(i, n)rep(j, m)res[i][j] = s[i][j] == c; return res;}
//#define use_compress
//[i] := vを返す
//aは0~n-1で置き換えられる
vi compress(vi &a) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(ALL(b), a[i]) - b.begin(); } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
#ifdef use_compress
//ind[i] := i番目に小さい数
//map[v] := vは何番目に小さいか
vi compress(vi &a, umapi &map) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { ll v = a[i]; a[i] = lower_bound(ALL(b), a[i]) - b.begin(); map[v] = a[i]; } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vi &a, vi &r) { vi b; ll len = a.size(); fora(v, a){b.push_back(v);} fora(v, r){b.push_back(v);} sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(ALL(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(ALL(b), r[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vi &a, vi &r, vi &s) { vi b; ll len = a.size(); fora(v, a){b.push_back(v);} fora(v, r){b.push_back(v);} fora(v, s){b.push_back(v); } sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(ALL(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(ALL(b), r[i]) - b.begin(); for (ll i = 0; i < sz(s); ++i) r[i] = lower_bound(ALL(b), s[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vector<vi> &a) { vi b; fora(vv, a){fora(v, vv){b.push_back(v);}} sort(b); unique(b); fora(vv, a){fora(v, vv){v = lower_bound(ALL(b), v) - b.begin(); }} ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vector<vector<vi >> &a) { vi b; fora(vvv, a){fora(vv, vvv){fora(v, vv){b.push_back(v);}}} sort(b); unique(b); fora(vvv, a){fora(vv, vvv){fora(v, vv){v = lower_bound(ALL(b), v) - b.begin();}}} ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
void compress(ll a[], ll len) { vi b; for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(ALL(b), a[i]) - b.begin(); }}
#endif
//要素が見つからなかったときに困る
#define binarySearch(a, v) (binary_search(ALL(a),v))
#define lowerIndex(a, v) (lower_bound(ALL(a),v)-a.begin())
#define upperIndex(a, v) (upper_bound(ALL(a),v)-a.begin())
#define rlowerIndex(a, v) (upper_bound(ALL(a),v)-a.begin()-1)
#define rupperIndex(a, v) (lower_bound(ALL(a),v)-a.begin()-1)
template<class T, class U, class W> T lowerBound(vector<T> &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T upperBound(vector<T> &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T rlowerBound(vector<T> &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T rupperBound(vector<T> &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else { return *(--it); }}
//todo 消せないか
template<class T, class U, class W> T lowerBound(set<T> &a, U v, W banpei) { auto it = a.lower_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T upperBound(set<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T rlowerBound(set<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T rupperBound(set<T> &a, U v, W banpei) {auto it = a.lower_bound(v);if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T lowerBound(mset<T> &a, U v, W banpei) { auto it = a.lower_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T upperBound(mset<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T rlowerBound(mset<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T rupperBound(mset<T> &a, U v, W banpei) {auto it = a.lower_bound(v);if (it == a.begin())return banpei; else { return *(--it); }}
#define next2(a) next(next(a))
#define prev2(a) prev(prev(a))
//狭義の単調増加列 長さを返す
template<class T> int lis(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX<T>()); rep(i, n) { int id = lowerIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX<T>());}
template<class T> int lis_eq(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX<T>()); rep(i, n) { int id = upperIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX<T>());}
//iteratorを返す
//valueが1以上の物を返す 0は見つけ次第削除
//vを減らす場合 (*it).se--でいい
template<class T, class U, class V> auto lower_map(map<T, U> &m, V k) { auto ret = m.lower_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;}
template<class T, class U, class V> auto upper_map(map<T, U> &m, V k) { auto ret = m.upper_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;}
//存在しなければエラー
template<class T, class U, class V> auto rlower_map(map<T, U> &m, V k) { auto ret = upper_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;}
template<class T, class U, class V> auto rupper_map(map<T, U> &m, V k) { auto ret = lower_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;}
template<class... T> void fin(T... s) {out(s...); exit(0); }
//便利 数学 math
//sub ⊂ top
bool subset(int sub, int top) {return (sub & top) == sub;}
//-180 ~ 180 degree
double atand(double h, double w) {return atan2(h, w) / PI * 180;}
//% -mの場合、最小の正の数を返す
ll mod(ll a, ll m) {if (m < 0) m *= -1;return (a % m + m) % m;}
//ll pow(ll a) { return a * a; };
template<class T> T fact(int v) { static vector<T> fact(2, 1); if (sz(fact) <= v) { rep(i, sz(fact), v + 1) { fact.emplace_back(fact.back() * i); }} return fact[v];}
ll comi(ll n, ll r) { assert(n < 100); static vvi(pas, 100, 100); if (pas[0][0])return pas[n][r]; pas[0][0] = 1; rep(i, 1, 100) { pas[i][0] = 1; rep(j, 1, i + 1)pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j]; } return pas[n][r];}
//二項係数の偶奇を返す
int com_mod2(int n,int r){return n == ( r | (n - r) );}
double comd2(ll n, ll r) { static vvd(comb, 2020, 2020); if (comb[0][0] == 0) { comb[0][0] = 1; rep(i, 2000) { comb[i + 1][0] = 1; rep(j, 1, i + 2) { comb[i + 1][j] = comb[i][j] + comb[i][j - 1]; } } } return comb[n][r];}
double comd(int n, int r) { if (r < 0 || r > n) return 0; if (n < 2020)return comd2(n, r); static vd fact(2, 1); if (sz(fact) <= n) { rep(i, sz(fact), n + 1) { fact.push_back(fact.back() * i); }} return fact[n] / fact[n - r] / fact[r];}
#define gcd my_gcd
ll gcd(ll a, ll b) {while (b) a %= b, swap(a, b);return abs(a);}
ll gcd(vi b) {ll res = b[0];rep(i, 1, sz(b))res = gcd(b[i], res);return res;}
#define lcm my_lcm
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll lcm(vi a) {ll res = a[0];rep(i, 1, sz(a))res = lcm(a[i], res);return res;}
ll ceil(ll a, ll b) {if (b == 0) {debugline("ceil");deb(a, b);ole();return -1;} else if (a < 0) { return 0; } else { return (a + b - 1) / b; }}
#define hypot my_hypot
double hypot(double dx, double dy){return std::sqrt(dx*dx+ dy*dy);}
ll sig0(int t) { return t <= 0 ? 0 : ((1 + t) * t) >> 1; }
bint sig0(bint t) {return t <= 0 ? 0 : ((1 + t) * t) >> 1; }
//ll sig(ll s, ll t) { return ((s + t) * (t - s + 1)) >> 1; }
ll sig(ll s, ll t) {if (s > t)swap(s, t);return sig0(t - s) + s * (t - s + 1);}
#define tousa_i tosa_i
#define lower_tousa_i lower_tosa_i
#define upper_tousa upper_tosa
#define upper_tousa_i upper_tosa_i
ll tosa_i(ll st, ll ad, ll v) { assert(((v - st) % ad) == 0); return (v - st) / ad;}
ll tosa_s(ll st, ll ad, ll len) { return st * len + sig0(len - 1) * ad;}
// ax + r (x は非負整数) で表せる整数のうち、v 以上となる最小の整数
ll lower_tosa(ll st, ll ad, ll v) { if (st >= v) return st; return (v - st + ad - 1) / ad * ad + st;}
//第何項か
ll lower_tosa_i(ll st, ll ad, ll v) { if (st >= v) return 0; return (v - st + ad - 1) / ad;}
ll upper_tosa(ll st, ll ad, ll v) { return lower_tosa(st, ad, v + 1); }
ll upper_tosa_i(ll st, ll ad, ll v) { return lower_tosa_i(st, ad, v + 1); }
//b * res <= aを満たす [l, r)を返す div
P drange_ika(int a, int b) { P null_p = mp(linf, linf); if (b == 0) { if (a >= 0) { return mp(-linf, linf + 1)/*全て*/; } else { return null_p/*無い*/; } } else { if (a >= 0) { if (b > 0) { return mp(-linf, a / b + 1); } else { return mp(-(a / -b), linf + 1); } } else { if (b > 0) { return mp(-linf, -ceil(-a, b) + 1); } else { return mp(ceil(-a, -b), linf + 1); } } }}
//v * v >= aとなる最小のvを返す
ll sqrt(ll a) { if (a < 0) { debugline("sqrt"); deb(a); ole(); } ll res = (ll) std::sqrt(a); while (res * res < a)++res; return res;}
double log(double e, double x) { return log(x) / log(e); }
/*@formatter:off*/
//機能拡張
#define dtie(a, b) int a, b; tie(a, b)
template<class T, class U> string to_string(T a, U b) { string res = ""; res += a; res += b; return res;}
template<class T, class U, class V> string to_string(T a, U b, V c) { string res = ""; res += a; res += b; res += c; return res;}
template<class T, class U, class V, class W> string to_string(T a, U b, V c, W d) { string res = ""; res += a; res += b; res += c; res += d; return res;}
template<class T, class U, class V, class W, class X> string to_string(T a, U b, V c, W d, X e) { string res = ""; res += a; res += b; res += c; res += d; res += e; return res;}
//todo stringもセットで
template<class T> vector<T> sub(const vector<T> &A, int l, int r) { assert(0 <= l && l <= r && r <= sz(A)); vector<T> ret(r - l); std::copy(A.begin() + l, A.begin() + r, ret.begin()); return ret;}
template<class T> vector<T> sub(const vector<T> &A, int r) { return sub(A, 0, r); }
template<class T> vector<T> subn(const vector<T> &A, int l, int len) { return sub(A, l, l + len); }
string sub(string &A, int l, int r) { assert(0 <= l && l <= r && r <= sz(A)); return A.substr(l, r - l);}
template<class T, class F>
//sub2で呼ぶ
vector<T> sub(const vector<vector<T> >& A, int h, int w, int ah,int aw, F f){ vector<T> res; while(0<= h && h < sz(A) && 0 <= w && w < sz(A[h]) && f(A[h][w])){ res.emplace_back(A[h][w]); h += ah; w += aw; } return res;}
template<class T> vector<T>sub(const vector<vector<T> >& A, int h, int w, int ah,int aw){return sub(A, h, w, ah, aw, [&](T v){return true;});}
//range_nowを返す(find_ifでしか使われない)
template<class T> auto subr(const vector<T> &A, int l) {return range_now(A, l);}
#define sub25(A, h, w, ah, aw) sub(A, h, w, ah, aw)
#define sub26(A, h, w, ah, aw, siki_r) sub(A, h, w, ah, aw, [&](auto v){return v siki_r;})
#define sub27(A, h, w, ah, aw, v, siki) sub(A, h, w, ah, aw, [&](auto v){return siki;})
#define sub2(...) over7(__VA_ARGS__,sub27,sub26,sub25)(__VA_ARGS__)
constexpr int bsetlen = k5 * 2;
//constexpr int bsetlen = 5050;
#define bset bitset<bsetlen>
bool operator<(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return false;}
bool operator>(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return false;}
bool operator<=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return true;}
bool operator>=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return true;}
string operator~(string &a) {string res = a;for (auto &&c:res) {if (c == '0')c = '1';else if (c == '1')c = '0';else {cerr << "cant ~" << a << "must bit" << endl;exit(0);}}return res;}
ostream &operator<<(ostream &os, bset& a) { bitset<10> b; vi list; rep(i,bsetlen){ if(a[i])list.push_back(i),b[i]=1; } os<<b<<", "<<list; return os;}
int hbiti(bset&a){rer(i,bsetlen){if(a[i])return i;}return -1;}
#define hk(a, b, c) (a <= b && b < c)
//O(N/64)
bset nap(bset &a, int v) {bset r = a | a << v;return r;}
bset nap(bset &a, bset &v) {bset r = a;rep(i, bsetlen) {if (v[i])r |= a << i;}return r;}
template<class T> int count(set<T> &S, T l, T r) { assert(l < r); auto it = S.lower_bound(l); return it != S.end() && (*it) < r;}
//template<class T> void seth(vector<vector<T>> &S, int w, vector<T> &v) {assert(sz(S) == sz(v));assert(w < sz(S[0]));rep(h, sz(S)) { S[h][w] = v[h]; }}
template<class T> vector<T> geth(vector<vector<T>> &S, int w) { assert(w < sz(S[0])); vector<T> ret(sz(S)); rep(h, sz(S)) { ret[h] = S[h][w]; } return ret;}
//vector<bool>[i]は参照を返さないため、こうしないとvb[i] |= trueがコンパイルエラー
vb::reference operator|=(vb::reference a, bool b){return a = a | b;}
vb::reference operator&=(vb::reference a, bool b){return a = a & b;}
template<class T, class U> void operator+=(pair<T,U> &a, pair<T,U> & b) {a.fi+=b.fi;a.se+=b.se;}
template<class T, class U> pair<T, U> operator+(const pair<T, U> &a, const pair<T, U> &b) { return pair<T, U>(a.fi + b.fi, a.se + b.se); }
template<class T, class U> pair<T,U> operator-(const pair<T,U> &a, const pair<T,U> & b) {return pair<T,U>(a.fi-b.fi,a.se-b.se);}
template<class T, class U> pair<T,U> operator-(const pair<T, U>& a){return pair<T, U>(-a.first, -a.second);}
template<typename CharT, typename Traits, typename Alloc> basic_string<CharT, Traits, Alloc> operator+(const basic_string<CharT, Traits, Alloc> &lhs, const int rv) {
#ifdef _DEBUG
static bool was = false;if (!was)message += "str += 65 is 'A' not \"65\" ";was = true;
#endif
return lhs + (char) rv;
}
template<typename CharT, typename Traits, typename Alloc> void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const int rv) { lhs = lhs + rv;}
template<typename CharT, typename Traits, typename Alloc> basic_string<CharT, Traits, Alloc> operator+(const basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { const int rv2 = rv; return lhs + rv2;}
template<typename CharT, typename Traits, typename Alloc> void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const signed rv) {const int v = rv; lhs += v; }
template<typename CharT, typename Traits, typename Alloc> void operator*=(basic_string<CharT, Traits, Alloc> &s, int num) { auto bek = s; s = ""; for (; num; num >>= 1) { if (num & 1) { s += bek; } bek += bek; }}
template<class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }template<class T, class U> void operator+=(deque<T> &a, U v) { a.push_back(v); }template<class T> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, vector<T> &v) { fora(d, v){a.push(d);} return a;}template<class T, class U> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, U v) { a.push(v); return a;}template<class T, class U> priority_queue<T> &operator+=(priority_queue<T> &a, U v) { a.push(v); return a;}template<class T> set<T> &operator+=(set<T> &a, vector<T> v) { fora(d, v){a.insert(d);} return a;}template<class T, class U> auto operator+=(set<T> &a, U v) { return a.insert(v); }template<class T, class U> auto operator-=(set<T> &a, U v) { return a.erase(v); }template<class T, class U> auto operator+=(mset<T> &a, U v) { return a.insert(v); }template<class T, class U> set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) { a.insert(v); return a;}template<class T, class U> vector<T> &operator+=(vector<T> &a, U v) { a.push_back(v); return a;}template<class T, class U> vector<T> operator+(U v,const vector<T> &a) { vector<T> ret = a; ret.insert(ret.begin(), v); return ret;}template<class T> vector<T> operator+(const vector<T>& a, const vector<T>& b) { vector<T> ret; ret = a; fora(v, b){ret += v; } return ret;}template<class T> vector<T> &operator+=(vector<T> &a,const vector<T> &b) { rep(i, sz(b)) {/*こうしないとa+=aで両辺が増え続けてバグる*/ a.push_back(b[i]); } return a;}template<class T, class U> map<T, U> &operator+=(map<T, U> &a, map<T, U> &b) { for(auto&& bv : b) { a[bv.first] += bv.second; } return a;}template<class T, class U> vector<T> operator+(const vector<T> &a, const U& v) { vector<T> ret = a; ret += v; return ret;}template<class T, class U> auto operator+=(uset<T> &a, U v) { return a.insert(v); }
template<class T> vector<T> operator%(vector<T>& a, int v){ vi ret(sz(a)); rep(i,sz(a)){ ret[i] = a[i] % v; } return ret;}
template<class T> vector<T> operator%=(vector<T>& a, int v){ rep(i,sz(a)){ a[i] %= v; } return a;}
vi operator&(vi& a, vi& b){ assert(sz(a)==sz(b)); vi ret(sz(a)); rep(i,sz(a)){ ret[i] = min(a[i],b[i]); } return ret;}
template<class T> void operator+=(mset<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); }
template<class T> void operator+=(set<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); }
template<class T> void operator+=(vector<T> &a, set<T>& v) { for(auto&& u : v)a.emplace_back(u); }
template<class T> void operator+=(vector<T> &a, mset<T>& v) { for(auto&& u : v)a.emplace_back(u); }
template<class T> vector<T> &operator-=(vector<T> &a, vector <T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-="); deb(a); deb(b); exit(0); } rep(i, sz(a))a[i] -= b[i]; return a;}
template<class T> vector<T> operator-(vector<T> &a, vector<T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-"); deb(a); deb(b); ole(); } vector<T> res(sz(a)); rep(i, sz(a))res[i] = a[i] - b[i]; return res;}
//template<class T, class U> void operator*=(vector<T> &a, U b) { vector<T> ta = a; rep(b-1){ a+=ta; }}
template<typename T> void erase(vector<T> &v, unsigned ll i) { v.erase(v.begin() + i); }
template<typename T> void erase(vector<T> &v, unsigned ll s, unsigned ll e) { v.erase(v.begin() + s, v.begin() + e); }
template<typename T> void pop_front(vector<T> &v) { erase(v, 0); }
template<typename T> void entry(vector<T> &v, unsigned ll s, unsigned ll e) { erase(v, e, sz(v));erase(v,0,s);}
template<class T, class U> void erase(map<T, U> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); }
template<class T> void erase(set<T> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); }
template<typename T> void erasen(vector<T> &v, unsigned ll s, unsigned ll n) { v.erase(v.begin() + s, v.begin() + s + n); }
template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, U t) { v.insert(v.begin() + i, t); }
template<typename T, typename U> void push_front(vector<T> &v, U t) { v.insert(v.begin(), t); }
template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, vector<T> list) { for (auto &&va:list)v.insert(v.begin() + i++, va); }
vector<string> split(const string &a, const char deli) { string b = a + deli; ll l = 0, r = 0, n = b.size(); vector<string> res; rep(i, n) { if (b[i] == deli) { r = i; if (l < r)res.push_back(b.substr(l, r - l)); l = i + 1; } } return res;}
vector<string> split(const string &a, const string deli) { vector<string> res; ll kn = sz(deli); std::string::size_type Pos(a.find(deli)); ll l = 0; while (Pos != std::string::npos) { if (Pos - l)res.push_back(a.substr(l, Pos - l)); l = Pos + kn; Pos = a.find(deli, Pos + kn); } if (sz(a) - l)res.push_back(a.substr(l, sz(a) - l)); return res;}
ll stoi(string& s){return stol(s);}
#define assert_yn(yn_v, v); assert(yn_v == 0 || yn_v == v);yn_v = v;
//不完全な対策、現状はautohotkeyで対応
int yn_v = 0;
void yn(bool a) { assert_yn(yn_v, 1);if (a)cout << "yes" << endl; else cout << "no" << endl; }
void fyn(bool a) { assert_yn(yn_v, 1);yn(a); exit(0);}
void Yn(bool a) { assert_yn(yn_v, 2);if (a)cout << "Yes" << endl; else cout << "No" << endl; }
void fYn(bool a) { assert_yn(yn_v, 2);Yn(a); exit(0);}
void YN(bool a) { assert_yn(yn_v, 3);if (a)cout << "YES" << endl; else cout << "NO" << endl; }
void fYN(bool a) { assert_yn(yn_v, 3);YN(a); exit(0);}
int ab_v = 0;
void fAb(bool a) { assert_yn(ab_v, 1);if(a)cout<<"Alice"<<endl;else cout<<"Bob";}
void fAB(bool a) { assert_yn(yn_v, 2);if(a)cout<<"ALICE"<<endl;else cout<<"BOB";}
int pos_v = 0;
void Possible(bool a) { assert_yn(pos_v, 1);if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0);}
void POSSIBLE(bool a) { assert_yn(pos_v, 2);if (a)cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; exit(0);}
void fPossible(bool a) { assert_yn(pos_v, 1)Possible(a);exit(0);}
void fPOSSIBLE(bool a) { assert_yn(pos_v, 2)POSSIBLE(a);exit(0);}
template<typename T> class fixed_point : T {public: explicit constexpr fixed_point(T &&t) noexcept: T(std::forward<T>(t)) {} template<typename... Args> constexpr decltype(auto) operator()(Args &&... args) const { return T::operator()(*this, std::forward<Args>(args)...); }};template<typename T> static inline constexpr decltype(auto) fix(T &&t) noexcept { return fixed_point<T>{std::forward<T>(t)}; }
//未分類
//0,2,1 1番目と2番目の次元を入れ替える
template<class T> auto irekae(vector<vector<vector<T> > > &A, int x, int y, int z) {
#define irekae_resize_loop(a, b, c) resize(res,a,b,c);rep(i,a)rep(j,b)rep(k,c)
vector<vector<vector<T> > > res; if (x == 0 && y == 1 && z == 2) { res = A; } else if (x == 0 && y == 2 && z == 1) { irekae_resize_loop(sz(A), sz(A[0][0]), sz(A[0])) { res[i][j][k] = A[i][k][j]; } } else if (x == 1 && y == 0 && z == 2) { irekae_resize_loop(sz(A[0]), sz(A), sz(A[0][0])) { res[i][j][k] = A[j][i][k]; } } else if (x == 1 && y == 2 && z == 0) { irekae_resize_loop(sz(A[0]), sz(A[0][0]), sz(A)) { res[i][j][k] = A[k][i][j]; } } else if (x == 2 && y == 0 && z == 1) { irekae_resize_loop(sz(A[0][0]), sz(A), sz(A[0])) { res[i][j][k] = A[j][k][i]; } } else if (x == 2 && y == 1 && z == 0) { irekae_resize_loop(sz(A[0][0]), sz(A[0]), sz(A)) { res[i][j][k] = A[k][j][i]; } } return res;
#undef irekae_resize_loop
}
template<class T> auto irekae(vector<vector<T>>&A,int i=1,int j=0){ vvt(res,sz(A[0]),sz(A)); rep(i,sz(A)){ rep(j,sz(A[0])){ res[j][i]=A[i][j]; } } return res;}
//tou分割する
template<typename Iterable> vector<Iterable> table(const Iterable &a, int tou = 2) {int N = sz(a); vector<Iterable> res(tou); int hab = N / tou; vi lens(tou, hab); rep(i, N % tou) { lens[tou - 1 - i]++; } int l = 0; rep(i, tou) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;}
//長さn毎に分割する
template<typename Iterable> vector<Iterable> table_n(const Iterable &a, int len) { int N = sz(a); vector<Iterable> res(ceil(N, len)); vi lens(N / len, len); if (N % len)lens.push_back(N % len); int l = 0; rep(i, sz(lens)) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;}
//縦を返す
vi& geth(vvi()& a, int w){ static vi ret; ret.resize(sz(a)); rep(i,sz(a)){ ret[i] = a[i][w]; } return ret;}
//@起動時
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
srand((unsigned) clock() + (unsigned) time(NULL));
};
} initonv;
//#define pre prev
//#define nex next
//gra mll pr
//上下左右
const string udlr = "udlr";
string UDLR = "UDLR";//x4と連動 UDLR.find('U') := x4[0]
vc atoz = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x','y', 'z'};
vc AtoZ = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X','Y', 'Z'};
//右、上が正
constexpr ll h4[] = {1, -1, 0, 0};
constexpr ll w4[] = {0, 0, -1, 1};
constexpr ll h8[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr ll w8[] = {1, 0, -1, 0, 1, -1, 1, -1};
int mei_inc(int h, int w, int H, int W, int i) {while (++i < 4) { if (inside(h + h4[i], w + w4[i], H, W))return i; }return i;}
#define mei(nh, nw, h, w) for (int i = mei_inc(h, w, H, W, -1), nh = i<4? h + h4[i] : 0, nw = i<4? w + w4[i] : 0; i < 4; i=mei_inc(h,w,H,W,i), nh = h+h4[i], nw = w+w4[i])
int mei_inc8(int h, int w, int H, int W, int i) { while (++i < 8) { if (inside(h + h8[i], w + w8[i], H, W))return i; } return i;}
#define mei8(nh, nw, h, w) for (int i = mei_inc8(h, w, H, W, -1), nh = i<8? h + h8[i] : 0, nw = i<8? w + w8[i] : 0; i < 8; i=mei_inc8(h,w,H,W,i), nh = h+h8[i], nw = w+w8[i])
int mei_incv(int h, int w, int H, int W, int i, vp &p) { while (++i < sz(p)) { if (inside(h + p[i].fi, w + p[i].se, H, W))return i; } return i;}
#define meiv(nh, nw, h, w, p) for (int i = mei_incv(h, w, H, W, -1, p), nh = i<sz(p)? h + p[i].fi : 0, nw = i<sz(p)? w + p[i].se : 0; i < sz(p); i=mei_incv(h,w,H,W,i,p), nh = h+p[i].fi, nw = w+p[i].se)
//H*Wのグリッドを斜めに分割する
//右上
vector<vp> naname_list_ne(int H, int W) { vector<vp> res(H + W - 1); rep(sh, H) { int sw = 0; res[sh] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh--; nw++; if (0 <= nh && nw < W) { res[sh] += mp(nh, nw); }else{ break; } } } rep(sw, 1, W) { int sh = H - 1; res[H + sw - 1] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh--; nw++; if (0 <= nh && nw < W) { res[H + sw-1] += mp(nh, nw); }else{ break; } } } return res;}
//右下
vector<vp> naname_list_se(int H, int W) { vector<vp> res(H + W - 1); rep(sh, H) { int sw = 0; res[sh] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh++; nw++; if (0 <= nh && nh< H && nw < W) { res[sh] += mp(nh, nw); } else { break; } } } rep(sw, 1, W) { int sh = 0; res[H + sw - 1] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh++; nw++; if (0 <= nh && nh < H && nw < W) { res[H + sw - 1] += mp(nh, nw); } else { break; } } } return res;}
//グラフ内で #undef getid
//#define getidとしているため、ここを書き直したらgraphも書き直す
#define getid_2(h, w) ((h) * (W) + (w))
#define getid_1(p) ((p).first * W + (p).second)
#define getid(...) over2(__VA_ARGS__, getid_2, getid_1) (__VA_ARGS__)
#define getp(id) mp(id / W, id % W)
//#define set_shuffle() std::random_device seed_gen;std::mt19937 engine(seed_gen())
//#define shuffle(a) std::shuffle((a).begin(), (a).end(), engine);
//1980 開始からtime ms経っていたらtrue
vb bit_bool(int v, int len) { assert(bit(len) > v); vb ret(len); rep(i, len) { ret[i] = bget(v, i); } return ret;}
vi range(int l, int r) {vi ret;ret.resize(r - l);rep(v, l, r) {ret[v - l] = v;}return ret;}
vi range(int r) {return range(0, r);}
vi tov(vb& a){ vi ret; rep(i,sz(a)){ if(a[i])ret.push_back(i); } return ret;}
bool kaibun(const str& S){return S==rev(S);}
template<class T> vector<T> repeat(const vector<T> &A, int kaisu) { vector<T> ret; while (kaisu--) { ret += A; } return ret;}
#define rge range
#define upd update
//S[{s, t, d}]
#define strs slice_str
struct slice_str {
string S;
slice_str() {}
slice_str(const string &S) : S(S) {}
slice_str(int len, char c) : S(len, c) {}
auto size(){return S.size();}
char& operator[](int p) { return S[p]; }
string operator[](initializer_list<int> p) { if (sz(p) == 1) { return S.substr(0, *(p.begin())); } else if (sz(p) == 2) { int l = *(p.begin()); int r = *(next(p.begin())); return S.substr(l, r - l); } else { auto it = p.begin(); int s = *(it++); int t = *(it++); int d = *(it); if (d == -1) { int s_ = sz(S) - s - 1; int t_ = sz(S) - t - 1; return rev(S).substr(s_, t_ - s_); } else if (d < 0) { t = max(-1ll, t); string ret; while (s > t) { ret += S[s]; s += d; } return ret; } else { t = min(sz(S), t); string ret; while (s < t) { ret += S[s]; s += d; } return ret; } } }
operator string &() { return S; }
template<class T> void operator+=(const T &a) { S += a; }
bool operator==(const slice_str& rhs){return S==rhs.S;}
};
ostream &operator<<(ostream &os, const slice_str &a) { os << a.S; return os;}
istream &operator>>(istream &iss, const slice_str &a) { iss >> a.S; return iss;}
template<class T> bool can(const T &v, int i) { return 0 <= i && i < sz(v); }
#if __cplusplus >= 201703L
//template<class T> auto sum(int a, T v...) {return (v + ... + 0);}
#endif
#define VEC vector
#endif /*UNTITLED15_TEMPLATE_H*/
#endif
//† ←template終了
/*@formatter:on*/
//vectorで取れる要素数
//bool=> 1e9 * 8.32
//int => 1e8 * 2.6
//ll => 1e8 * 1.3
//3次元以上取るとメモリがヤバい
//static配列を使う
vvc (ba);
ll N, M, H, W;
vi A, B, C;
void solve() {
in(N);
vi A;
din(L, R);
na(A, N);
rsort(A);
if (all_of(sub(A, L), ==A[0])) {
int cou = count(A, A[0]);
out(A[0]);
int res = 0;
rep(i, L - 1, R) {
if (A[i] == A[0]) {
res += comi(cou, i);
}
}
out(res);
} else {
out(sum(A, L) / (dou) L);
int all = 0;
int ned = 0;
{
int l = find(A, A[L - 1]);
int rr = find_if(subr(A, l+1), != A[L-1]);
deb(l, rr);
ned = L - l;
all = rr - l;
}
deb(all, ned);
out(comi(all, ned));
}
}
auto my(ll n, vi &a) {
return 0;
}
auto sister(ll n, vi &a) {
ll ret = 0;
return ret;
}
signed main() {
solve();
#define arg n,a
#ifdef _DEBUG
bool bad = 0;
for (ll i = 0, ok = 1; i < k5 && ok; ++i) {
ll n = rand(1, 8);
vi a = ranv(n, 1, 10);
auto myres = my(arg);
auto res = sister(arg);
ok = myres == res;
if (!ok) {
out(arg);
cerr << "AC : " << res << endl;
cerr << "MY : " << myres << endl;
bad = 1;
break;
}
}
if (!bad) {
//solveを書き直す
//solveを呼び出す
}
if (was_deb && sz(res_mes)) {
cerr << "result = " << endl << res_mes << endl;
}
if (sz(message)) {
cerr << "****************************" << endl;
cerr << "Note." << endl;
cerr << message << endl;
cerr << "****************************" << endl;
}
#endif
return 0;
};
| a.cc:17:10: fatal error: boost/sort/pdqsort/pdqsort.hpp: No such file or directory
17 | #include <boost/sort/pdqsort/pdqsort.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
|
s200693035 | p03776 | C++ | /*temp*/
//
//
//
//
//#undef _DEBUG
//#pragma GCC optimize("Ofast")
//不動小数点の計算高速化
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#include <boost/multiprecision/cpp_int.hpp>
#ifdef _DEBUG
#include "template.h"
#else
#if __cplusplus >= 201703L
/*Atcoderでしか使えない(c++17 && このテンプレートが使えるならAtcoder)*/
#include <boost/sort/pdqsort/pdqsort.hpp>
#define fast_sort boost::sort::pdqsort
#endif
#endif
#ifndef _DEBUG
#ifndef UNTITLED15_TEMPLATE_H
#define UNTITLED15_TEMPLATE_H
#ifdef _DEBUG
#include "bits_stdc++.h"
#else
#include <bits/stdc++.h>
#endif
#ifndef fast_sort
#define fast_sort sort
#endif
//#define use_pq
#define use_for
#define use_for_each
#define use_sort
#define use_fill
#define use_rand
#define use_mgr
#define use_rui
#define use_compress
//
//
//
//
//
//
#define use_pbds
#ifdef use_pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
template<class T, class U, class W, class X> auto count(__gnu_pbds::gp_hash_table<T, U, W> &a, X k) { return a.find(k) != a.end(); }
#endif
using namespace std;
using namespace std::chrono;
/*@formatter:off*/
#define ll long long
using sig_dou = double;
//マクロ省略形 関数等
#define arsz(a) (sizeof(a)/sizeof(a[0]))
#define sz(a) ((ll)(a).size())
#define mp make_pair
#define mt make_tuple
#define pb pop_back
#define pf push_front
#define eb emplace_back
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
template<class T,class U> auto max(T a, U b){return a>b ? a: b;}
template<class T,class U> auto min(T a, U b){return a<b ? a: b;}
//optional<T>について下でオーバーロード(nullopt_tを左辺右辺について単位元として扱う)
template<class T, class U> bool chma(T &a, const U &b) { if (a < b) { a = b; return true; } return false;}
template<class T, class U> bool chmi(T &a, const U &b) { if (b < a) { a = b; return true; } return false;}
//メタ系 meta
//vector<T>でTを返す
#define decl_t(A) decltype(A)::value_type
//vector<vector<.....T>>でTを返す
template<class T> struct decl2 {typedef T type;};
template<class T> struct decl2<vector<T>> {typedef typename decl2<T>::type type;};
//#define decl_max(a, b) decltype(max(MAX<decltype(a)>(), MAX<decltype(b)>()))
#define is_same2(T, U) is_same<T, U>::value
template<class T>struct is_vector : std::false_type{};
template<class T>struct is_vector<std::vector<T>> : std::true_type{};
//大きい型を返す max_type<int, char>::type
//todo mintがlong long より小さいと判定されるためバグる
template<class T1, class T2, bool t1_bigger = (sizeof(T1) > sizeof(T2))>struct max_type{typedef T1 type;};
template<class T1, class T2> struct max_type<T1, T2, false>{typedef T2 type;};
template<typename T, typename U = typename T::value_type>std::true_type value_type_tester(signed);
template<typename T>std::false_type value_type_tester(long);
template<typename T>struct has_value_type: decltype(value_type_tester<T>(0)){};
template<class T> struct vec_rank : integral_constant<int, 0> {};
template<class T> struct vec_rank<vector<T>> : integral_constant<int, vec_rank<T>{} + 1> {};
//N個のTを並べたtupleを返す
//tuple_n<3, int>::type tuple<int, int, int>
template<size_t N, class T, class... Arg> struct tuple_n{typedef typename tuple_n<N-1, T, T, Arg...>::type type;};
template<class T, class...Arg> struct tuple_n<0, T, Arg...>{typedef tuple<Arg...> type;};
struct dummy_t1{};struct dummy_t2{};
struct dummy_t3{};struct dummy_t4{};
struct dummy_t5{};struct dummy_t6{};
//template<class T, require(is_integral<T>::value)>など
#define require_t(bo) enable_if_t<bo>* = nullptr
//複数でオーバーロードする場合、引数が同じだとうまくいかないため
//require_arg(bool, dummy_t1)
//require_arg(bool, dummy_t2)等とする
#define require_arg1(bo) enable_if_t<bo> * = nullptr
#define require_arg2(bo, dummy_type) enable_if_t<bo, dummy_type> * = nullptr
#define require_arg(...) over2(__VA_ARGS__,require_arg2,require_arg1)(__VA_ARGS__)
//->//enable_if_tのtを書き忘れそうだから
#define require_ret(bo, ret_type) enable_if_t<bo, ret_type>
#define int long long //todo 消したら動かない intの代わりにsignedを使う
auto start_time = system_clock::now();
auto past_time = system_clock::now();
#define debugName(VariableName) # VariableName
//最大引数がN
#define over2(o1, o2, name, ...) name
#define over3(o1, o2, o3, name, ...) name
#define over4(o1, o2, o3, o4, name, ...) name
#define over5(o1, o2, o3, o4, o5, name, ...) name
#define over6(o1, o2, o3, o4, o5, o6, name, ...) name
#define over7(o1, o2, o3, o4, o5, o6, o7, name, ...) name
#define over8(o1, o2, o3, o4, o5, o6, o7, o8, name, ...) name
#define over9(o1, o2, o3, o4, o5, o6, o7, o8, o9, name, ...) name
#define over10(o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, name, ...) name
void assert2(bool b,const string& s = ""){ if(!b){ cerr<<s<<endl; exit(1);/*assert(0);*/ }}
//my_nulloptをあらゆる操作の単位元的な物として扱う
//vectorの参照外時に返したり、右辺値として渡されたときに何もしないなど
struct my_nullopt_t {} my_nullopt;
#define nullopt_t my_nullopt_t
#define nullopt my_nullopt
/*@formatter:off*/
//値が無いときは、setを使わない限り代入できない
//=を使っても無視される
template<class T> struct my_optional {
private:
bool is_null;
T v;
public:
typedef T value_type ;
my_optional() : is_null(true) {}
my_optional(const nullopt_t&) : is_null(true) {}
my_optional(const T& v) : v(v), is_null(false) {}
bool has_value() const { return !is_null; }
T &value() { static string mes = "optional has no value";assert2(!is_null, mes);return v;}
const T &value() const { static string mes = "optional has no value";assert2(!is_null, mes);return v;}
void set(const T &nv) {is_null = false;v = nv;}
template<class U> void operator=(const U &v) {
set(v);//null状態でも代入出来るようにした
// if (has_value())value() = v; else return;
}
template<class U> void operator=(const my_optional<U> &v) {
if (/*has_value() && */v.has_value())(*this) = v; else return;
}
/*@formatter:off*/
void reset() { is_null = true; }
void operator=(const nullopt_t &) { reset(); }
template<require_t(!is_same2(T, bool))>
explicit operator bool(){return !is_null;}
//nullの時はエラー
operator T&(){return value();}
operator const T&()const {return value();}
my_optional<T> operator++() { if (this->has_value()) { this->value()++; return *this; } else { return *this; } }
my_optional<T> operator++(signed) { if (this->has_value()) { auto tem = *this; this->value()++; return tem; } else { return *this; } }
my_optional<T> operator--() { if (this->has_value()) { this->value()--; return *this; } else { return *this; } }
my_optional<T> operator--(signed) { if (this->has_value()) { auto tem = *this; this->value()--; return tem; } else { return *this; } }
};
template<class T>istream &operator>>(istream &iss, my_optional<T>& v) { T val; iss>>val; v.set(val); return iss;}
#define optional my_optional
template<class T>
using opt = my_optional<T>;
//template<class T, class A = std::allocator<T>> struct debtor : std::vector<T, A> {
template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key, T> >>
struct o_map : std::map<Key, optional<T>, Compare, Allocator> {
optional<T> emp;
o_map() : std::map<Key, optional<T>, Compare, Allocator>() {}
auto operator()(const nullopt_t&) {return nullopt;}
optional<T> &operator()(const optional<Key> &k) {if (k.has_value()) {return std::map<Key, optional<T>, Compare, Allocator>::operator[](k.value());} else {emp.reset();return emp;}}
optional<T> &operator()(const Key &k) { auto &v = std::map<Key, optional<T>, Compare, Allocator>::operator[](k); if (v.has_value())return v; else { v.set(0); return v; } }
template<class U> void operator[](U){static string mes = "s_map cant []";assert2(0, mes);}
};
//以下、空のoptionalをnulloptと書く
//ov[-1(参照外)] でnulloptを返す
//ov[nullopt] で nulloptをかえす
template<class T> struct ov{
optional<T> emp;
vector<optional<T>> v;
ov(int i = 0, T val = 0):v(i, val){}
template<class U>ov(const U& rhs){v.resize(sz(rhs));for (int i = 0; i < sz(rhs); i ++)v[i].set(rhs[i]);}
optional<T> &operator()(int i) {if (i < 0 || sz(v) <= i) {emp.reset();return emp;} else { return v[i]; }}
optional<T> &operator()(const nullopt_t &) { return operator()(-1); }
optional<T> &operator()(const optional<T> &i) { if (i.has_value())return operator()(i.value()); else { return operator()(-1); } }
/*@formatter:off*/
};
template<class T>string deb_tos(const ov<T>& v){
return deb_tos(v.v);
}
//vectorに対しての処理は.vを呼ぶ
template<class T> class ovv{
optional<T> emp;
public:
vector<vector<optional<T>> > v ;
ovv(int i=0, int j=0, T val = 0) : v(i, vector<optional<T>>(j, val) ){}
optional<T> &operator()(int i, int j) { if (i < 0 || j < 0 || sz(v) <= i || sz(v[i]) <= j) { emp.reset();return emp; } else { return v[i][j]; } }
//再帰ver 遅いと思う
// optional<T>& gets(optional<T>& v){return v;}
// template<class V, class H, class... U> optional<T>& gets(V& v, H i, U... tail){ if constexpr(is_same2(H, nullopt_t))return operator()(-1,-1); else if constexpr(is_same2(H, optional<int>)){ if(i.has_value())return gets(v[(int)i], tail...); else return operator()(-1,-1); }else if constexpr(is_integral<H>::value){ return gets(v[(int)i], tail...); }else{ assert(0); return emp; } }
#if __cplusplus >= 201703L
//if constexprバージョン 上が遅かったらこれで
template<class U, class V> optional<T> &operator()(const U &i, const V &j) { /*駄目な場合を除外*/ if constexpr(is_same2(U, nullopt_t) || is_same2(U, nullopt_t)) { return operator()(-1, -1); /* o, o*/ } else if constexpr(is_same2(U, optional<int>) && is_same2(V, optional<int>)) { return operator()(i.has_value() ? (int) i : -1, j.has_value() ? (int) j : -1); /* o, x*/ } else if constexpr(is_same2(U, optional<int>)) { return operator()(i.has_value() ? (int) i : -1, (int) j); /* x, o*/ } else if constexpr(is_same2(V, optional<int>)) { return operator()((int) i, j.has_value() ? (int) j : -1); /* x, x*/ } else { return operator()((int) i, (int) j); } }
#endif
operator const vector<vector<optional<T>> >&(){
return v;
}
};
template<class T>istream &operator>>(istream &iss, ovv<T> &a) { for (int h = 0; h < sz(a); h ++){ for (int w = 0; w < sz(a[h]); w ++){ iss>>a.v[h][w ]; } } return iss;}
template<class T>string deb_tos(const ovv<T>& v){
return deb_tos(v.v);
}
template<class T> struct ov3{
optional<T> emp;
vector<vector<vector<optional<T>>> > v ;
ov3(int i, int j, int k, T val = 0) : v(i, vector<vector<optional<T>>>(j, vector<optional<T>>(k, val) ) ){}
optional<T> &operator()(int i, int j, int k) { if (i < 0 || j < 0 || sz(v) <= i || sz(v[i]) <= j) { if(k < 0 || sz(v[i][j]) <= k){ emp.reset(); return emp; } } return v[i][j][k]; }
private:
#if __cplusplus >= 201703L
//再帰ver 遅いと思う
template<class V, class H> optional<T> &gets(V &nowv, H i) { if constexpr(is_same2(H, nullopt_t)) { emp.reset(); return emp; } else if constexpr(is_same2(H, optional<int>)) { if (i.has_value()) { return nowv[(int) i]; } else { emp.reset();return emp; } } else if constexpr(is_integral<H>::value) { return nowv[(int) i]; } else { static string mes = "ov3 error not index";assert2(0, mes); emp.reset();return emp; } }
//todo const &消した
template<class V, class H, class... U> optional<T> &gets(V &nowv, H i, U... tail) { if constexpr(is_same2(H, nullopt_t)) { emp.reset();return emp; } else if constexpr(is_same2(H, optional<int>)) { if (i.has_value()) { return gets(nowv[(int) i], tail...); } else { emp.reset();return emp; } } else if constexpr(is_integral<H>::value) { return gets(nowv[(int) i], tail...); } else { static string mes = "ov3 error not index";assert2(0, mes); emp.reset();return emp; } }
#endif
public:
template<class U, class V, class W> optional<T> &operator()(U i, V j, W k) { return gets(v, i, j, k); }
/*@formatter:off*/
};
template<class T>string deb_tos(const ov3<T>& v){
return deb_tos(v.v);
}
//nullopt_t
//優先順位
//null, [opt, tem]
// + と += は違う意味を持つ
//val+=null : val
//val+null : null
//
//+は途中計算
//+=は最終的に格納したい値にだけ持たせる
//+=がvoidを返すのは、途中計算で使うのを抑制するため
//nulloptを考慮する際、計算途中では+を使ってnulloptを作り
//格納する際は+=で無効にする必要がある
//演算子==
//optional<int>(10) == 10
//全ての型に対応させ、value_typeが等しいかを見るようにするのもありかも
//null同士を比較する状況はおかしいのではないか
bool operator==(const nullopt_t &, const nullopt_t&){assert2(0, "nul == null cant hikaku");return false;}
template<class T> bool operator==(const nullopt_t &, const T&){return false;}
template<class T> bool operator!=(const nullopt_t &, const T&){return true;}
template<class T> bool operator==(const T&, const nullopt_t &){return false;}
template<class T> bool operator!=(const T&, const nullopt_t &){return true;}
//nullを
nullopt_t& operator +(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator -(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator *(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator /(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator +=(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator -=(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator *=(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator /=(const nullopt_t &, const nullopt_t&) {return nullopt;}
template<class ANY> nullopt_t operator+(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator-(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator*(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator/(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator+(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> nullopt_t operator-(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> nullopt_t operator*(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> nullopt_t operator/(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> void operator+=(nullopt_t &, const ANY &) {}
template<class ANY> void operator-=(nullopt_t &, const ANY &) {}
template<class ANY> void operator*=(nullopt_t &, const ANY &) {}
template<class ANY> void operator/=(nullopt_t &, const ANY &) {}
template<class ANY> void operator+=(ANY &, const nullopt_t &) {}
template<class ANY> void operator-=(ANY &, const nullopt_t &) {}
template<class ANY> void operator*=(ANY &, const nullopt_t &) {}
template<class ANY> void operator/=(ANY &, const nullopt_t &) {}
template<class T>struct is_optional:false_type{};
template<class T>struct is_optional<optional<T>>:true_type{};
template<class T, class U>
true_type both_optional(optional<T> t, optional<U> u);
false_type both_optional(...);
template<class T, class U> class opt_check : public decltype(both_optional(declval<T>(), declval<U>())) {};
//optionalは同じ型同士しか足せない
//(o, t), (t, o), (o, o)
#define opt_tem(op) \
template<class O, class O_ret = decltype(declval<O>() op declval<O>())>optional<O_ret> operator op(const optional<O> &opt1, const optional<O> &opt2) { if (!opt1.has_value() || !opt2.has_value()) { return optional<O_ret>(); } else { return optional<O_ret>(opt1.value() op opt2.value()); }}\
template<class O, class T, class O_ret = decltype(declval<O>() op declval<O>())> auto operator op(const optional<O> &opt, const T &tem) -> require_ret(!(opt_check<optional<O>, T>::value), optional<O_ret>) { if (!opt.has_value()) { return optional<O_ret>(); } else { return optional<O_ret>(opt.value() op tem); }}\
template<class O, class T, class O_ret = decltype(declval<O>() op declval<O>())> auto operator op(const T &tem, const optional<O> &opt) -> require_ret(!(opt_check<optional<O>, T>::value), optional<O_ret>) { if (!opt.has_value()) { return optional<O_ret>(); } else { return optional<O_ret>(opt.value() op tem); }}
/*@formatter:off*/
opt_tem(+)opt_tem(-)opt_tem(*)opt_tem(/)
//比較はoptional<bool>を返す
opt_tem(<)opt_tem(>)opt_tem(<=)opt_tem(>=)
/*@formatter:on*//*@formatter:off*/
template<class O, class T> bool operator==(const optional<O>& opt, const T& tem){if(opt.has_value()){return opt.value()==tem;}else return nullopt == tem;}
template<class O, class T> bool operator!=(const optional<O>& opt, const T& tem){if(opt.has_value()){return opt.value()!=tem;}else return nullopt != tem;}
template<class O, class T> bool operator==(const T& tem, const optional<O>& opt){if(opt.has_value()){return opt.value()==tem;}else return nullopt == tem;}
template<class O, class T> bool operator!=(const T& tem, const optional<O>& opt){if(opt.has_value()){return opt.value()!=tem;}else return nullopt != tem;}
template<class O> bool operator==(const optional<O>& opt1, const optional<O>& opt2){ if(opt1.has_value() != opt2.has_value()){ return false; }else if(opt1.has_value()){ return opt1.value() == opt2.value(); }else { return nullopt == nullopt; }}
template<class O> bool operator!=(const optional<O>& opt1, const optional<O>& opt2){return !(opt1 == opt2);}
//(a+=null) != (a=a+null)
// a null
template<class T, class O> void operator+=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem += opt.value(); }}
template<class T, class O> void operator-=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem -= opt.value(); }}
template<class T, class O> void operator*=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem *= opt.value(); }}
template<class T, class O> void operator/=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem /= opt.value(); }}
template<class T, class O> void operator+=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() += tem; }}
template<class T, class O> void operator-=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() -= tem; }}
template<class T, class O> void operator*=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() *= tem; }}
template<class T, class O> void operator/=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() /= tem; }}
//
template<class Ol, class Or> void operator+=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl += opr.value(); }}
template<class Ol, class Or> void operator-=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl -= opr.value(); }}
template<class Ol, class Or> void operator*=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl *= opr.value(); }}
template<class Ol, class Or> void operator/=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl /= opr.value(); }}
/*@formatter:off*/
template<class U> auto max(const nullopt_t &, const U &val) { return val; }
template<class U> auto max(const U &val, const nullopt_t &) { return val; }
template<class U> auto min(const nullopt_t &, const U &val) { return val; }
template<class U> auto min(const U &val, const nullopt_t &) { return val; }
template<class T, class U> auto max(const optional<T> &opt, const U &val) { if (opt.has_value())return max(opt.value(), val); else return val; }
template<class T, class U> auto max(const U &val, const optional<T> &opt) { if (opt.has_value())return max(opt.value(), val); else return val; }
template<class T, class U> auto min(const optional<T> &opt, const U &val) { if (opt.has_value())return min(opt.value(), val); else return val; }
template<class T, class U> auto min(const U &val, const optional<T> &opt) { if (opt.has_value())return min(opt.value(), val); else return val; }
//null , optional, T
bool chma(nullopt_t &, const nullopt_t &) { return false; }
template<class T> bool chma(T &opt, const nullopt_t &) { return false; }
template<class T> bool chma(nullopt_t &, const T &opt) { return false; }
template<class T> bool chma(optional<T> &olv, const optional<T> &orv) { if (orv.has_value()) { return chma(olv, orv.value()); } else return false; }
template<class T, class U> bool chma(optional<T> &opt, const U &rhs) { if (opt.has_value()) { return chma(opt.value(), rhs); } else return false; }
template<class T, class U> bool chma(T &lhs, const optional<U> &opt) { if (opt.has_value()) { return chma(lhs, opt.value()); } else return false; }
bool chmi(nullopt_t &, const nullopt_t &) { return false; }
template<class T> bool chmi(T &opt, const nullopt_t &) { return false; }
template<class T> bool chmi(nullopt_t &, const T &opt) { return false; }
template<class T> bool chmi(optional<T> &olv, const optional<T> &orv) { if (orv.has_value()) { return chmi(olv, orv.value()); } else return false; }
template<class T, class U> bool chmi(optional<T> &opt, const U &rhs) { if (opt.has_value()) { return chmi(opt.value(), rhs); } else return false; }
template<class T, class U> bool chmi(T &lhs, const optional<U> &opt) { if (opt.has_value()) { return chmi(lhs, opt.value()); } else return false; }
template<class T> ostream &operator<<(ostream &os, optional<T> p) { if (p.has_value())os << p.value(); else os << "e"; return os;}
template<class T>using opt = my_optional<T>;
struct xorshift {
/*@formatter:on*/
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
/*@formatter:off*/
size_t operator()(const uint64_t& x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); }
size_t operator()(const std::pair<ll, ll>& x) const { ll v = ((x.first) << 32) | x.second; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(v + FIXED_RANDOM); }
template<class T, class U> size_t operator()(const std::pair<T, U>& x) const{ static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); uint64_t hasx = splitmix64(x.first); uint64_t hasy = splitmix64(x.second + FIXED_RANDOM); return hasx ^ hasy; }
template<class T> size_t operator()(const vector<T> &x) const { uint64_t has = 0; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); uint64_t rv = splitmix64(FIXED_RANDOM); for (int i = 0; i < sz(x); i ++){ uint64_t v = splitmix64(x[i] + rv); has ^= v; rv = splitmix64(rv); } return has; }
};
#ifdef _DEBUG
string message;
string res_mes;
//#define use_debtor
//template<class T, class U, class X> auto count(unordered_map<T, U> &a, X k) { return a.find(k) != a.end(); }
#ifdef use_debtor
//https://marycore.jp/prog/cpp/class-extension-methods/ 違うかも
template<class T, class A = std::allocator<T>> struct debtor : std::vector<T, A> {
using std::vector<T, A>::vector;
template<class U> int deb_v(U a, int v) { return v; }
template<class U> int deb_v(debtor<U> &a, int v = 0) { cerr << a.size() << " "; return deb_v(a.at(0), v + 1); }
template<class U> void deb_o(U a) { cerr << a << " "; }
template<class U> void deb_o(debtor<U> &a) { for (int i = 0; i < min((int) a.size(), 15ll); i++) { deb_o(a[i]); } if ((int) a.size() > 15) { cerr << "..."; } cerr << endl; }
typename std::vector<T>::reference my_at(typename std::vector<T>::size_type n, vector<int> &ind) { if (n < 0 || n >= (int) this->size()) { int siz = (int) this->size(); cerr << "vector size = "; int dim = deb_v((*this)); cerr << endl; ind.push_back(n); cerr << "out index at "; for (auto &&i: ind) { cerr << i << " "; } cerr << endl; cerr << endl; if (dim <= 2) { deb_o((*this)); } exit(0); } return this->at(n); }
typename std::vector<T>::reference operator[](typename std::vector<T>::size_type n) { if (n < 0 || n >= (int) this->size()) { int siz = (int) this->size(); cerr << "vector size = "; int dim = deb_v((*this)); cerr << endl; cerr << "out index at " << n << endl; cerr << endl; if (dim <= 2) { deb_o((*this)); } exit(0); } return this->at(n); }
};
#define vector debtor
#endif
#ifdef use_pbds
template<class T> struct my_pbds_tree {
set<T> s;
auto begin() { return s.begin(); }
auto end() { return s.end(); }
auto rbegin() { return s.rbegin(); }
auto rend() { return s.rend(); }
auto empty() { return s.empty(); }
auto size() { return s.size(); }
void clear() { s.clear(); }
template<class U> void insert(U v) { s.insert(v); }
template<class U> void operator+=(U v) { insert(v); }
template<class F> auto erase(F v) { return s.erase(v); }
template<class U> auto find(U v) { return s.find(v); }
template<class U> auto lower_bound(U v) { return s.lower_bound(v); }
template<class U> auto upper_bound(U v) { return s.upper_bound(v); }
auto find_by_order(ll k) { auto it = s.begin(); for (ll i = 0; i < k; i++)it++; return it; }
auto order_of_key(ll v) { auto it = s.begin(); ll i = 0; for (; it != s.end() && *it < v; i++)it++; return i; }
};
#define pbds(T) my_pbds_tree<T>
#endif
//区間削除は出来ない
//gp_hash_tableでcountを使えないようにするため
template<class T, class U> struct my_unordered_map { unordered_map<T, U> m; my_unordered_map() {}; auto begin() { return m.begin(); } auto end() { return m.end(); } auto cbegin() { return m.cbegin(); } auto cend() { return m.cend(); } template<class V> auto erase(V v) { return m.erase(v); } void clear() { m.clear(); } /*countは gp_hash_tableに存在しない*/ /*!= m.end()*/ template<class V> auto find(V v) { return m.find(v); } template<class V> auto &operator[](V n) { return m[n]; }};
template<class K, class V>using umap_f = my_unordered_map<K, V>;
#else
#define endl '\n'
//umapはunorderd_mapになる
//umapiはgp_hash_table
//find_by_order(k) k番目のイテレーター
//order_of_key(k) k以上が前から何番目か
#define pbds(U) __gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>
template<class K, class V>using umap_f = __gnu_pbds::gp_hash_table<K, V, xorshift>;
#endif
#define umapi unordered_map<ll,ll>
#define umapp unordered_map<P,ll>
#define umappp unordered_map<P,P>
#define umapu unordered_map<uint64_t,ll>
#define umapip unordered_map<ll,P>
template<class T, class U, class X> auto count(unordered_map<T, U> &a, X k) { return a.find(k) != a.end(); }
/*@formatter:off*/
#ifdef use_pbds
template<class U, class L> void operator+=(__gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> &s, L v) { s.insert(v); }
#endif
//衝突対策
#define ws ws_
//todo 要らないと思う
template<class A, class B, class C> struct T2 { A f;B s;C t;T2() { f = 0, s = 0, t = 0; }T2(A f, B s, C t) : f(f), s(s), t(t) {}bool operator<(const T2 &r) const { return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t; /*return f != r.f ? f > r.f : s != r.s ?n s > r.s : t > r.t; 大きい順 */ } bool operator>(const T2 &r) const { return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; /*return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順 */ } bool operator==(const T2 &r) const { return f == r.f && s == r.s && t == r.t; } bool operator!=(const T2 &r) const { return f != r.f || s != r.s || t != r.t; }};
template<class A, class B, class C, class D> struct F2 {
A a;B b;C c;D d;
F2() { a = 0, b = 0, c = 0, d = 0; }
F2(A a, B b, C c, D d) : a(a), b(b), c(c), d(d) {}
bool operator<(const F2 &r) const { return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d; /* return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;*/ }
bool operator>(const F2 &r) const { return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;/* return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d;*/ }
bool operator==(const F2 &r) const { return a == r.a && b == r.b && c == r.c && d == r.d; }
bool operator!=(const F2 &r) const { return a != r.a || b != r.b || c != r.c || d != r.d; }
ll operator[](ll i) {assert(i < 4);return i == 0 ? a : i == 1 ? b : i == 2 ? c : d;}
};
typedef T2<ll, ll, ll> T;
typedef F2<ll, ll, ll, ll> F;
//T mt(ll a, ll b, ll c) { return T(a, b, c); }
//F mf(ll a, ll b, ll c, ll d) { return F(a, b, c, d); }
//関数内をまとめる
//初期値l=-1, r=-1
void set_lr12(int &l, int &r, int n) { /*r==-1*/ if (r == -1) { if (l == -1) { l = 0; r = n; } else { r = l; l = 0; } }}
//@マクロ省略系 型,構造
//using で元のdoubleを同時に使えるはず
#define double_big
#ifdef double_big
#define double long double
//#define pow powl
#endif
using dou = double;
/*@formatter:off*/
template<class T> T MAX() { return numeric_limits<T>::max(); }
template<class T> T MIN() { return numeric_limits<T>::min(); }
constexpr ll inf = (ll) 1e9 + 100;
constexpr ll linf = (ll) 1e18 + 100;
constexpr dou dinf = (dou) linf * linf;
constexpr char infc = '{';
const string infs = "{";
template<class T> T INF() { return MAX<T>() / 2; }
template<> signed INF() { return inf; }
template<> ll INF() { return linf; }
template<> double INF() { return dinf; }
template<> char INF() { return infc; }
template<> string INF() { return infs; }
const double eps = 1e-9;
//#define use_epsdou
#ifdef use_epsdou
//基本コメントアウト
struct epsdou { double v; epsdou(double v = 0) : v(v) {} template<class T> epsdou &operator+=(T b) { v += (double) b; return (*this); } template<class T> epsdou &operator-=(T b) { v -= (double) b; return (*this); } template<class T> epsdou &operator*=(T b) { v *= (double) b; return (*this); } template<class T> epsdou &operator/=(T b) { v /= (double) b; return (*this); } epsdou operator+(epsdou b) { return v + (double) b; } epsdou operator-(epsdou b) { return v - (double) b; } epsdou operator*(epsdou b) { return v * (double) b; } epsdou operator/(epsdou b) { return v / (double) b; } epsdou operator-() const { return epsdou(-v); } template<class T> bool operator<(T b) { return v < (double) b; } template<class T> bool operator>(T b) {auto r = (double)b; return v > (double) b; } template<class T> bool operator==(T b) { return fabs(v - (double) b) <= eps; } template<class T> bool operator<=(T b) { return v < (double) b || fabs(v - b) <= eps; } template<class T> bool operator>=(T b) { return v > (double) b || fabs(v - b) <= eps; } operator double() { return v; }};
template<>epsdou MAX(){return MAX<double>();}
template<>epsdou MIN(){return MIN<double>();}
//priqrity_queue等で使うのに必要
bool operator<(const epsdou &a, const epsdou &b) {return a.v < b.v;}
bool operator>(const epsdou &a, const epsdou &b) {return a.v > b.v;}
istream &operator>>(istream &iss, epsdou &a) {iss >> a.v;return iss;}
ostream &operator<<(ostream &os, epsdou &a) {os << a.v;return os;}
#define eps_conr_t(o) template<class T> epsdou operator o(T a, epsdou b) {return (dou) a o b.v;}
#define eps_conl_t(o) template<class T> epsdou operator o(epsdou a, T b) {return a.v o (dou) b;}
eps_conl_t(+)eps_conl_t(-)eps_conl_t(*)eps_conl_t(/)eps_conr_t(+)eps_conr_t(-)eps_conr_t(*)eps_conr_t(/)
//template<class U> epsdou max(epsdou a, U b){return a.v>b ? a.v: b;}
//template<class U> epsdou max(U a, epsdou b){return a>b.v ? a: b.v;}
//template<class U> epsdou min(epsdou a, U b){return a.v<b ? a.v: b;}
//template<class U> epsdou min(U a, epsdou b){return a<b.v ? a: b.v;}
#undef double
#define double epsdou
#undef dou
#define dou epsdou
#endif
template<class T = int, class A, class B = int> T my_pow(A a, B b = 2) {
if(b < 0)return (T)1 / my_pow<T>(a, -b);
#if __cplusplus >= 201703L
if constexpr(is_floating_point<T>::value) { return pow((T) a, (T) b); }
else if constexpr(is_floating_point<A>::value) { assert2(0, "pow <not dou>(dou, )");/*return 0;しない方がコンパイル前に(voidを受け取るので)エラーが出ていいかも*/}
else if constexpr(is_floating_point<B>::value) { assert2(0, "pow <not dou>(, dou)");/*return 0;しない方がコンパイル前に(voidを受け取るので)エラーが出ていいかも*/}
else {
#endif
T ret = 1; T bek = a; while (b) { if (b & 1)ret *= bek; bek *= bek; b >>= 1; } return ret;
#if __cplusplus >= 201703L
}
#endif
}
#define pow my_pow
#define ull unsigned long long
using itn = int;
using str = string;
using bo= bool;
#define au auto
using P = pair<ll, ll>;
#define fi first
#define se second
#define beg begin
#define rbeg rbegin
#define con continue
#define bre break
#define brk break
#define is ==
#define el else
#define elf else if
#define upd update
#define sstream stringstream
#define maxq 1
#define minq -1
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MALLOC(type, len) (type*)malloc((len) * sizeof(type))
#define lam1(ret) [&](auto&& v){return ret;}
#define lam2(v, ret) [&](auto&& v){return ret;}
#define lam(...) over2(__VA_ARGS__,lam2,lam1)(__VA_ARGS__)
#define lamr(right) [&](auto&& p){return p right;}
#define unique(v) v.erase( unique(v.begin(), v.end()), v.end() );
//マクロ省略系 コンテナ
using vi = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vd = vector<double>;
using vc = vector<char>;
using vp = vector<P>;
using vt = vector<T>;
//#define V vector
#define vvt0(t) vector<vector<t>>
#define vvt1(t, a) vector<vector<t>>a
#define vvt2(t, a, b) vector<vector<t>>a(b)
#define vvt3(t, a, b, c) vector<vector<t>> a(b,vector<t>(c))
#define vvt4(t, a, b, c, d) vector<vector<t>> a(b,vector<t>(c,d))
#define vvi(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__)
#define vvb(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__)
#define vvs(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__)
#define vvd(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__)
#define vvc(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__)
#define vvp(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__)
#define vvt(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(T,__VA_ARGS__)
#define vv(type, ...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(type,__VA_ARGS__)
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));}
#define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__)
#define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__)
#define vns(name, ...) auto name = make_v<string>(__VA_ARGS__)
#define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__)
#define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__)
#define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__)
#define vn(type, name, ...) auto name = make_v<type>(__VA_ARGS__)
#define PQ priority_queue<ll, vector<ll>, greater<ll> >
#define tos to_string
using mapi = map<ll, ll>;
using mapp = map<P, ll>;
using mapd = map<dou, ll>;
using mapc = map<char, ll>;
using maps = map<str, ll>;
using seti = set<ll>;
using setp = set<P>;
using setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<ll>;
#define uset unordered_set
#define useti unordered_set<ll,xorshift>
#define mset multiset
#define mseti multiset<ll>
#define umap unordered_map
#define mmap multimap
//任意のマクロサポート用 使う度に初期化する
int index_, v1_, v2_, v3_;
/*@formatter:off*/
string to_string(char c) { string ret = ""; ret += c; return ret;}
template<class T> class pq_min_max { vector<T> d; void make_heap() { for (int i = d.size(); i--;) { if (i & 1 && d[i - 1] < d[i]) swap(d[i - 1], d[i]); int k = down(i); up(k, i); } } inline int parent(int k) const { return ((k >> 1) - 1) & ~1; } int down(int k) { int n = d.size(); if (k & 1) { /* min heap*/ while (2 * k + 1 < n) { int c = 2 * k + 3; if (n <= c || d[c - 2] < d[c]) c -= 2; if (c < n && d[c] < d[k]) { swap(d[k], d[c]); k = c; } else break; } } else { /* max heap*/ while (2 * k + 2 < n) { int c = 2 * k + 4; if (n <= c || d[c] < d[c - 2]) c -= 2; if (c < n && d[k] < d[c]) { swap(d[k], d[c]); k = c; } else break; } } return k; } int up(int k, int root = 1) { if ((k | 1) < (int) d.size() && d[k & ~1] < d[k | 1]) { swap(d[k & ~1], d[k | 1]); k ^= 1; } int p; while (root < k && d[p = parent(k)] < d[k]) { /*max heap*/ swap(d[p], d[k]); k = p; } while (root < k && d[k] < d[p = parent(k) | 1]) { /* min heap*/ swap(d[p], d[k]); k = p; } return k; }public: pq_min_max() {} pq_min_max(const vector<T> &d_) : d(d_) { make_heap(); } template<class Iter> pq_min_max(Iter first, Iter last) : d(first, last) { make_heap(); } void operator+=(const T &x) { int k = d.size(); d.push_back(x); up(k); } void pop_min() { if (d.size() < 3u) { d.pop_back(); } else { swap(d[1], d.back()); d.pop_back(); int k = down(1); up(k); } } void pop_max() { if (d.size() < 2u) { d.pop_back(); } else { swap(d[0], d.back()); d.pop_back(); int k = down(0); up(k); } } const T &get_min() const { return d.size() < 2u ? d[0] : d[1]; } const T &get_max() const { return d[0]; } int size() const { return d.size(); } bool empty() const { return d.empty(); }};
//小さいほうからM個取得するpq
template<class T> struct helper_pq_size { pq_min_max<T> q; T su = 0; int max_size = 0; helper_pq_size() {} helper_pq_size(int max_size) : max_size(max_size) {} void clear() { q = pq_min_max<T>(); su = 0; } void operator+=(T v) { su += v; q += (v); if (sz(q) > max_size) { su -= q.get_max(); q.pop_max(); } } T sum() { return su; } T top() { return q.get_min(); } void pop() { su -= q.get_min(); q.pop_min(); } T poll() { T ret = q.get_min(); su -= ret; q.pop_min(); return ret; } ll size() { return q.size(); }};
//大きいほうからM個取得するpq
template<class T> struct helper_pqg_size { pq_min_max<T> q; T su = 0; int max_size = 0; helper_pqg_size() {} helper_pqg_size(int max_size) : max_size(max_size) {} void clear() { q = pq_min_max<T>(); su = 0; } void operator+=(T v) { su += v; q += (v); if (sz(q) > max_size) { su -= q.get_min(); q.pop_min(); } } T sum() { return su; } T top() { return q.get_max(); } void pop() { su -= q.get_max(); q.pop_max(); } T poll() { T ret = q.get_max(); su -= ret; q.pop_min(); return ret; } ll size() { return q.size(); }};;
template<class T, class Container = vector<T>,class Compare = std::less<typename Container::value_type>>
struct helper_pqg { priority_queue<T, Container, Compare> q;/*小さい順*/ T su = 0; helper_pqg() {} void clear() { q = priority_queue<T, vector<T>, greater<T> >(); su = 0; } void operator+=(T v) { su += v; q.push(v); } T sum() { return su; } T top() { return q.top(); } void pop() { su -= q.top(); q.pop(); } T poll() { T ret = q.top(); su -= ret; q.pop(); return ret; } ll size() { return q.size(); }};
template<class T>
using helper_pq = helper_pqg<T, vector<T>, greater<T>>;
#if __cplusplus >= 201703L
//小さいほうからsize個残る
//Tがoptionalなら空の時nullを返す
template<class T> struct pq {
helper_pq<T> a_q;/*大きい順*/ helper_pq_size<T> b_q;/*大きい順*/ bool aquery;
T su = 0;
pq(int size = inf) {aquery = size == inf;if (!aquery) { b_q = helper_pq_size<T>(size); }}
void clear() { if (aquery) a_q.clear(); else b_q.clear(); }
void operator+=(T v) { if (aquery) a_q += v; else b_q += v; }
//optionalなら空の時nullを返す
T top() { if constexpr(is_optional<T>::value) { if (aquery) { if (sz(a_q) == 0)return T(); return a_q.top(); } else { if (sz(b_q) == 0)return T(); return b_q.top(); } } else { if (aquery)return a_q.top(); else return b_q.top(); } }
T sum() { if (aquery) return a_q.sum(); else return b_q.sum(); }
//optionalなら空の時何もしない
void pop() { if constexpr(is_optional<T>::value) { if (aquery) { if (sz(a_q))a_q.pop(); } else { if (sz(b_q))b_q.pop(); }} else { if (aquery)a_q.pop(); else b_q.pop(); }} /*T*/
T poll() { if constexpr(is_optional<T>::value) { if (aquery) { if (sz(a_q) == 0)return T(); return a_q.poll(); } else { if (sz(b_q) == 0)return T(); return b_q.poll(); } } else { if (aquery)return a_q.poll(); else return b_q.poll(); } }
ll size() { if (aquery) return a_q.size(); else return b_q.size(); }
/*@formatter:off*/
};
template<class T> struct pqg { helper_pqg<T> a_q;/*大きい順*/ helper_pqg_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pqg(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pqg_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }};
#else
//小さいほうからsize個残る
template<class T> struct pq { helper_pq<T> a_q;/*大きい順*/ helper_pq_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pq(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pq_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }};
//大きいほうからsize個残る
template<class T> struct pqg { helper_pqg<T> a_q;/*大きい順*/ helper_pqg_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pqg(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pqg_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }};
#endif
#define pqi pq<ll>
#define pqgi pqg<ll>
template<class T> string deb_tos(pq<T> &q) { vector<T> res; auto temq = q; while (sz(temq))res.push_back(temq.top()), temq.pop(); stringstream ss; ss<< res; return ss.str();}
template<class T> string deb_tos(pqg<T> &q) { vector<T> res; auto temq = q; while (sz(temq))res.push_back(temq.top()), temq.pop(); stringstream ss; ss<< res; return ss.str();}
/*@formatter:off*/
//マクロ 繰り返し
//↓@オーバーロード隔離
//todo 使わないもの非表示
#define rep1(n) for(ll rep1i = 0,rep1lim=n; rep1i < rep1lim ; ++rep1i)
#define rep2(i, n) for(ll i = 0,rep2lim=n; i < rep2lim ; ++i)
#define rep3(i, m, n) for(ll i = m,rep3lim=n; i < rep3lim ; ++i)
#define rep4(i, m, n, ad) for(ll i = m,rep4lim=n; i < rep4lim ; i+= ad)
//逆順 閉区間
#define rer2(i, n) for(ll i = n; i >= 0 ; i--)
#define rer3(i, m, n) for(ll i = m,rer3lim=n; i >= rer3lim ; i--)
#define rer4(i, m, n, dec) for(ll i = m,rer4lim=n; i >= rer4lim ; i-=dec)
#ifdef use_for
//ループを一つにまとめないとフォーマットで汚くなるため
#define nex_ind1(i) i++
#define nex_ind2(i, j, J) i = (j + 1 == J) ? i + 1 : i, j = (j + 1 == J ? 0 : j + 1)
#define nex_ind3(i, j, k, J, K)i = (j + 1 == J && k + 1 == K) ? i + 1 : i, j = (k + 1 == K) ? (j + 1 == J ? 0 : j + 1) : j, k = (k + 1 == K ? 0 : k + 1)
#define nex_ind4(i, j, k, l, J, K, L) i = (j + 1 == J && k + 1 == K && l + 1 == L) ? i + 1 : i, j = (k + 1 == K && l + 1 == L) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L ?(k + 1 == K ? 0 : k + 1) : k), l = l + 1 == L ? 0 : l + 1
#define nex_ind5(i, j, k, l, m, J, K, L, M) i = (j + 1 == J && k + 1 == K && l + 1 == L && m + 1 == M) ? i + 1 : i, j = (k + 1 == K && l + 1 == L && m + 1 == M) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L && m + 1 == M ?(k + 1 == K ? 0 : k + 1) : k), l = m + 1 == M ? l+1 == L ? 0 : l+1 : l, m = m + 1 == M ? 0 : m + 1
#define repss2(i, I) for (int i = 0; i < I; i++)
#define repss4(i, j, I, J) for (int i = (J ? 0 : I), j = 0; i < I; nex_ind2(i, j, J))
#define repss6(i, j, k, I, J, K) for (int i = (J && K ? 0 : I), j = 0, k = 0; i < I; nex_ind3(i, j, k, J, K))
#define repss8(i, j, k, l, I, J, K, L) for (int i = (J && K && L ? 0 : I), j = 0, k = 0, l = 0; i < I; nex_ind4(i, j, k, l, J, K, L))
#define repss10(i, j, k, l, m, I, J, K, L, M)for (int i = (J && K && L && M ? 0 : I), j = 0, k = 0, l = 0, m = 0; i < I; nex_ind5(i, j, k, l, m, J, K, L, M))
//i,j,k...をnまで見る
#define reps2(i, n) repss2(i, n)
#define reps3(i, j, n) repss4(i, j, n, n)
#define reps4(i, j, k, n) repss6(i, j, k, n, n, n)
#define reps5(i, j, k, l, n) repss8(i, j, k, l, n, n, n, n)
template<class T> void nex_repv2(int &i, int &j, int &I, int &J, vector<vector<T>> &s) { while (1) { j++; if (j >= J) { j = 0; i++; if (i < I) { J = (int) s[i].size(); } } if (i >= I || J) return; }}
template<class T> void nex_repv3(int &i, int &j, int &k, int &I, int &J, int &K, vector<vector<vector<T>>> &s) { while (1) { k++; if (k >= K) { k = 0; j++; if (j >= J) { j = 0; i++; if (i >= I)return; } } J = (int) s[i].size(); K = (int) s[i][j].size(); if (J && K) return; }}
#define repv_2(i, a) repss2(i, sz(a))
//正方形である必要はない
//直前を持つのとどっちが早いか
#define repv_3(i, j, a) for (int repvI = (int)a.size(), repvJ = (int)a[0].size(), i = 0, j = 0; i < repvI; nex_repv2(i,j,repvI,repvJ,a))
//箱状になっている事が要求される つまり[i] 次元目の要素数は一定
#define repv_4(i, j, k, a) for (int repvI = (int)a.size(), repvJ = (int)a[0].size(), repvK =(int)a[0][0].size(), i = 0, j = 0, k=0; i < repvI; nex_repv3(i,j,k,repvI,repvJ,repvK,a))
#define repv_5(i, j, k, l, a) repss8(i, j, k, l, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0]))
#define repv_6(i, j, k, l, m, a) repss10(i, j, k, l, m, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0]), sz(a[0][0][0][0]))
#endif
template<typename T> struct has_rbegin_rend { private:template<typename U> static auto check(U &&obj) -> decltype(std::rbegin(obj), std::rend(obj), std::true_type{});static std::false_type check(...);public:static constexpr bool value = decltype(check(std::declval<T>()))::value; };
template<typename T> constexpr bool has_rbegin_rend_v = has_rbegin_rend<T>::value;
template<typename Iterator> class Range { public:Range(Iterator &&begin, Iterator &&end) noexcept: m_begin(std::forward<Iterator>(begin)), m_end(std::forward<Iterator>(end)) {}Iterator begin() const noexcept { return m_begin; }Iterator end() const noexcept { return m_end; }private:const Iterator m_begin;const Iterator m_end; };
template<typename Iterator> static inline Range<Iterator> makeRange(Iterator &&begin, Iterator &&end) noexcept { return Range<Iterator>{std::forward<Iterator>(begin), std::forward<Iterator>(end)}; }
template<typename T> static inline decltype(auto) makeReversedRange(const std::initializer_list<T> &iniList) noexcept { return makeRange(std::rbegin(iniList), std::rend(iniList)); }
template<typename T, typename std::enable_if_t<has_rbegin_rend_v<T>, std::nullptr_t> = nullptr> static inline decltype(auto) makeReversedRange(T &&c) noexcept { return makeRange(std::rbegin(c), std::rend(c)); }/* rbegin(), rend()を持たないものはこっちに分岐させて,エラーメッセージを少なくする*/template<typename T, typename std::enable_if<!has_rbegin_rend<T>::value, std::nullptr_t>::type = nullptr> static inline void makeReversedRange(T &&) noexcept { static_assert(has_rbegin_rend<T>::value, "Specified argument doesn't have reverse iterator."); }
//#define use_for
#define form1(st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it)
#define form3(k, v, st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it)
#define form4(k, v, st, r) for (auto &&form_it = st.begin(); form_it != st.end() && (*form_it).fi < r; ++form_it)
#define form5(k, v, st, l, r) for (auto &&form_it = st.lower_bound(l); form_it != st.end() && (*form_it).fi < r; ++form_it)
#define forrm1(st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it)
#define forrm3(k, v, st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it)
//向こう側で
// ++itか it = st.erase(it)とする
#define fors1(st) for (auto &&it = st.begin(); it != st.end(); )
#define fors2(v, st) for (auto &&it = st.begin(); it != st.end(); )
#define fors3(v, st, r) for (auto &&it = st.begin(); it != st.end() && (*it) < r; )
#define fors4(v, st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it) < r; )
#ifdef use_for
#define forslr3(st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it)
#define forslr4(v, st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it)
#define forslr5(v, st, r, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it)
#define forslr6(v, st, l, r, a, b) for (auto &&forslr_it = st.lower_bound(l); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it)
#define fora_f_init_2(a, A) ;
#define fora_f_init_3(fora_f_i, a, A) auto &&a = A[fora_f_i];
#define fora_f_init_4(a, b, A, B) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i];
#define fora_f_init_5(fora_f_i, a, b, A, B) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i];
#define fora_f_init_6(a, b, c, A, B, C) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i];
#define fora_f_init_7(fora_f_i, a, b, c, A, B, C) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i];
#define fora_f_init_8(a, b, c, d, A, B, C, D) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; auto && d = D[fora_f_i];
#define fora_f_init_9(fora_f_i, a, b, c, d, A, B, C, D) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; auto && d = D[fora_f_i];
#define fora_f_init(...) over9(__VA_ARGS__,fora_f_init_9, fora_f_init_8, fora_f_init_7, fora_f_init_6, fora_f_init_5, fora_f_init_4, fora_f_init_3, fora_f_init_2)(__VA_ARGS__)
#define forr_init_2(a, A) auto &&a = A[forr_i];
#define forr_init_3(forr_i, a, A) auto &&a = A[forr_i];
#define forr_init_4(a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i];
#define forr_init_5(forr_i, a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i];
#define forr_init_6(a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i];
#define forr_init_7(forr_i, a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i];
#define forr_init_8(a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i];
#define forr_init_9(forr_i, a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i];
#define forr_init(...) over9(__VA_ARGS__, forr_init_9, forr_init_8, forr_init_7, forr_init_6, forr_init_5, forr_init_4, forr_init_3, forr_init_2)(__VA_ARGS__)
#define forp_init3(k, v, S) auto &&k = S[forp_i].first;auto &&v = S[forp_i].second;
#define forp_init4(forp_i, k, v, S) auto &&k = S[forp_i].first;auto &&v = S[forp_i].second;
#define forp_init(...) over4(__VA_ARGS__,forp_init4,forp_init3,forp_init2,forp_init1)(__VA_ARGS__)
#define form_init(k, v, ...) auto &&k = (*form_it).fi;auto &&v = (*form_it).se;
#define forrm_init(k, v, ...) auto &&k = (*forrm_it).fi;auto &&v = (*forrm_it).se;
#define fors_init(v, ...) auto &&v = (*it);
#define forlr_init(a, A, ngl, ngr) auto a = A[forlr_i]; auto prev = forlr_i ? A[forlr_i-1] : ngl;auto next = forlr_i+1< rep2lim? A[forlr_i+1] : ngr;
#define forslr_init4(a, A, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr;
#define forslr_init5(a, A, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr;
#define forslr_init6(a, A, l, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr;
#define forslr_init(...) over6(__VA_ARGS__,forslr_init6,forslr_init5,forslr_init4)(__VA_ARGS__);
//こうしないとmapがおかしくなる
#define fora_f_2(a, A) for(auto&& a : A)
#define fora_f_3(fora_f_i, a, A) rep(fora_f_i, sz(A))
#define fora_f_4(a, b, A, B) rep(fora_f_i, sz(A))
#define fora_f_5(fora_f_i, a, b, A, B) rep(fora_f_i, sz(A))
#define fora_f_6(a, b, c, A, B, C) rep(fora_f_i, sz(A))
#define fora_f_7(fora_f_i, a, b, c, A, B, C) rep(fora_f_i, sz(A))
#define fora_f_8(a, b, c, d, A, B, C, D) rep(fora_f_i, sz(A))
#define fora_f_9(fora_f_i, a, b, c, d, A, B, C, D) rep(fora_f_i, sz(A))
#define forr_2(a, A) rer(forr_i, sz(A)-1)
#define forr_3(forr_i, a, A) rer(forr_i, sz(A)-1)
#define forr_4(a, b, A, B) rer(forr_i, sz(A)-1)
#define forr_5(forr_i, a, b, A, B) rer(forr_i, sz(A)-1)
#define forr_6(a, b, c, A, B, C) rer(forr_i, sz(A)-1)
#define forr_7(forr_i, a, b, c, A, B, C) rer(forr_i, sz(A)-1)
#define forr_8(a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1)
#define forr_9(forr_i, a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1)
#endif
//↑@オーバーロード隔離
//rep系はインデックス、for系は中身
#define rep(...) over4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rer(...) over4(__VA_ARGS__,rer4,rer3,rer2,)(__VA_ARGS__)
//自分込みで残りがREM以上の間ループを回す
#define rem(i, N, REM) for (int i = 0; i < N - REM + 1; i++)
//char用のrep
#define repc(i, m, n) for(char i = m,repc3lim=n; i < repc3lim ; ++i)
//i,j,k...をnまで見る
#define reps(...) over5(__VA_ARGS__,reps5,reps4,reps3,reps2,)(__VA_ARGS__)
#define repss(...) over10(__VA_ARGS__, repss10, a, repss8, a, repss6, a, repss4, a, repss2) (__VA_ARGS__)
//vectorのindexを走査する
//repv(i,j,vvi)
#define repv(...) over6(__VA_ARGS__,repv_6,repv_5,repv_4,repv_3,repv_2,)(__VA_ARGS__)
#define rerv(i, A) for (int i = sz(A)-1; i >= 0 ; i--)
//repvn(dp) nは次元
#define repv1(a) repv(i, a)
#define repv2(a) repv(i, j, a)
#define repv3(a) repv(i, j, k, a)
#define repv4(a) repv(i, j, k, l, a)
#ifdef use_for
#define fora_f(...) over9(__VA_ARGS__, fora_f_9, fora_f_8, fora_f_7, fora_f_6, fora_f_5, fora_f_4, fora_f_3, fora_f_2)(__VA_ARGS__)
#endif
#define forr(...) over9(__VA_ARGS__, forr_9, forr_8, forr_7, forr_6, forr_5, forr_4, forr_3, forr_2)(__VA_ARGS__)
//0~N-2まで見る
#define forar_init(v, rv, A) auto &&v = A[forar_i]; auto && rv = A[forar_i+1];
#define forar(v, rv, A) rep(forar_i, sz(A) - 1)
#if __cplusplus >= 201703L
template<size_t M_SZ, bool indexed, class Iterator, class T, class U=T, class V=T, class W=T>
class ite_vec_merge : public Iterator { std::size_t i = 0; vector<T> &A; vector<U> &B; vector<V> &C; vector<W> &D;public : ite_vec_merge(Iterator ita, vector<T> &A) : Iterator(ita), A(A), B(A), C(A), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B) : Iterator(ita), A(A), B(B), C(A), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B, vector<V> &C) : Iterator(ita), A(A), B(B), C(C), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B, vector<V> &C, vector<W> &D) : Iterator(ita), A(A), B(B), C(C), D(D) {} auto &operator++() { ++i; this->Iterator::operator++(); return *this; } auto operator*() const noexcept { if constexpr(!indexed && M_SZ == 1) { return tuple<T &>(A[i]); } else if constexpr(!indexed && M_SZ == 2) { return tuple<T &, U &>(A[i], B[i]); } else if constexpr(!indexed && M_SZ == 3) { return tuple<T &, U &, V &>(A[i], B[i], C[i]); } else if constexpr(!indexed && M_SZ == 4) { return tuple<T &, U &, V &, W &>(A[i], B[i], C[i], D[i]); } else if constexpr(indexed && M_SZ == 1) { return tuple<int, T &>(i, A[i]); } else if constexpr(indexed && M_SZ == 2) { return tuple<int, T &, U &>(i, A[i], B[i]); } else if constexpr(indexed && M_SZ == 3) { return tuple<int, T &, U &, V &>(i, A[i], B[i], C[i]); } else if constexpr(indexed && M_SZ == 4) { return tuple<int, T &, U &, V &, W &>(i, A[i], B[i], C[i], D[i]); } else { assert(0); return tuple<int>(i); } }};
template<size_t M_SZ, bool indexed, class T, class U=T, class V=T, class W=T>
class vec_merge { vector<T> &a; vector<U> &b; vector<V> &c; vector<W> &d;public : vec_merge(vector<T> &a) : a(a), b(a), c(a), d(a) {} vec_merge(vector<T> &a, vector<U> &b) : a(a), b(b), c(a), d(a) {} vec_merge(vector<T> &a, vector<U> &b, vector<V> &c) : a(a), b(b), c(c), d(a) {} vec_merge(vector<T> &a, vector<U> &b, vector<V> &c, vector<W> &d) : a(a), b(b), c(c), d(d) {} auto begin() const { if constexpr(M_SZ == 1) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a}; } else if constexpr(M_SZ == 2) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b}; } else if constexpr(M_SZ == 3) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b, c}; } else if constexpr(M_SZ == 4) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b, c, d}; } else { assert(0); return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a}; } } auto end() const { if constexpr(M_SZ == 1) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a}; } else if constexpr(M_SZ == 2) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b}; } else if constexpr(M_SZ == 3) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b, c}; } else if constexpr(M_SZ == 4) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b, c, d}; } else { assert(0); return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a}; } }};
#endif
#define fora_2(a, A) for(auto&& a : A)
#if __cplusplus >= 201703L
#define fora_3(i, a, A) for(auto[i, a] : vec_merge<1, true, decl_t(A)>(A))
#define fora_4(a, b, A, B) for(auto[a, b] : vec_merge<2, false, decl_t(A), decl_t(B)>(A, B))
#define fora_5(i, a, b, A, B) for(auto[i, a, b] : vec_merge<2, true, decl_t(A), decl_t(B)>(A, B))
#define fora_6(a, b, c, A, B, C) for(auto[a, b, c] : vec_merge<3, false, decl_t(A), decl_t(B), decl_t(C)>(A, B, C))
#define fora_7(i, a, b, c, A, B, C) for(auto[i, a, b, c] : vec_merge<3, true, decl_t(A), decl_t(B), decl_t(C)>(A, B, C))
#define fora_8(a, b, c, d, A, B, C, D) for(auto[a, b, c, d] : vec_merge<4, false, decl_t(A), decl_t(B), decl_t(C), decl_t(D)>(A, B, C, D))
#define fora_9(i, a, b, c, d, A, B, C, D) for(auto[i, a, b, c, d] : vec_merge<4, true, decl_t(A), decl_t(B), decl_t(C), decl_t(D)>(A, B, C, D))
#endif
//構造化束縛ver
//1e5要素で40ms程度
//遅いときはfora_fを使う
#define fora(...) over9(__VA_ARGS__, fora_9, fora_8, fora_7, fora_6, fora_5, fora_4, fora_3, fora_2)(__VA_ARGS__)
//#define forr(v, a) for(auto&& v : makeReversedRange(a))
//参照を取らない
/*@formatter:off*/
#ifdef use_for
template<class U> vector<U> to1d(vector<U> &a) { return a; }
template<class U> auto to1d(vector<vector<U>> &a) { vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)res.push_back(a2); return res;}
template<class U> vector<U> to1d(vector<vector<vector<U>>> &a) { vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) res.push_back(a3); return res;}
template<class U> vector<U> to1d(vector<vector<vector<vector<U>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)res.push_back(a4); return res;}
template<class U> vector<U> to1d(vector<vector<vector<vector<vector<U>>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)for (auto &&a5 : a4)res.push_back(a5); return res;}
template<class U> vector<U> to1d(vector<vector<vector<vector<vector<vector<U>>>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)for (auto &&a5 : a4)for (auto &&a6 : a5)res.push_back(a6); return res;}
#define forv(a, b) for(auto a : to1d(b))
//インデックスを前後含めて走査
#define ring(i, s, len) for (int i = s, prev = (s == 0) ? len - 1 : s - 1, next = (s == len - 1) ? 0 : s + 1, cou = 0; cou < len; cou++, prev = i, i = next, next = (next == len - 1) ? 0 : next + 1)
//値と前後を見る
#define ringv(v, d) index_=0;for (auto prev = d[sz(d)-1],next= (int)d.size()>1?d[1]:d[0],v = d[0]; index_ < sz(d); index_++, prev = v, v = next, next = (index_>=sz(d)-1?d[0]:d[index_+1]))
// 左右をnext prevで見る 0の左と nの右
#define forlr(v, d, banpei_l, banpei_r) rep(forlr_i,sz(d))
#endif
#define form(...) over5(__VA_ARGS__,form5,form4,form3,form2,form1)(__VA_ARGS__)
#define forrm(...) over5(__VA_ARGS__,forrm5,forrm4,forrm3,forrm2,forrm1)(__VA_ARGS__)
#define fors(...) over4(__VA_ARGS__,fors4,fors3,fors2,fors1)(__VA_ARGS__)
#define forslr(...) over6(__VA_ARGS__,forslr6,forslr5,forslr4,forslr3)(__VA_ARGS__)
#define forp3(k, v, st) rep(forp_i,sz(st))
#define forp4(forp_i, k, v, st) rep(forp_i,sz(st))
#define forp(...) over4(__VA_ARGS__,forp4,forp3)(__VA_ARGS__)
//マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const double PI = 3.1415926535897932384626433832795029L;
constexpr bool ev(ll a) { return !(a & 1); }
constexpr bool od(ll a) { return (a & 1); }
//@拡張系 こう出来るべきというもの
//埋め込み 存在を意識せずに機能を増やされているもの
namespace std {
template<> class hash<std::pair<signed, signed>> { public:size_t operator()(const std::pair<signed, signed> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }};
template<> class hash<std::pair<ll, ll>> { public:/*大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断*/size_t operator()(const std::pair<ll, ll> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }};
}
//stream まとめ
/*@formatter:off*/
istream &operator>>(istream &iss, P &a) {iss >> a.first >> a.second;return iss;}
template<typename T> istream &operator>>(istream &iss, vector<T> &vec_) {for (T &x: vec_) iss >> x;return iss;}
template<class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) {os << p.fi << " " << p.se;return os;}
ostream &operator<<(ostream &os, T p) {os << p.f << " " << p.s << " " << p.t;return os;}
ostream &operator<<(ostream &os, F p) {os << p.a << " " << p.b << " " << p.c << " " << p.d;return os;}
template<typename T> ostream &operator<<(ostream &os, vector<T> &vec_) {for (ll i = 0; i < vec_.size(); ++i)os << vec_[i] << (i + 1 == vec_.size() ? "" : " ");return os;}
template<typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec_) {for (ll i = 0; i < vec_.size(); ++i) {for (ll j = 0; j < vec_[i].size(); ++j) { os << vec_[i][j] << " "; }os << endl;}return os;}
template<typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &m) {os << endl;for (auto &&v:m) os << v << endl;return os;}
template<class T> ostream &operator<<(ostream &os, set<T> s) { fora(v, s) { os << v << " "; } return os;}
template<class T> ostream &operator<<(ostream &os, mset<T> s) { fora(v, s) { os << v << " "; } return os;}
template<class T> ostream &operator<<(ostream &os, deque<T> a) { fora(v, a) { os << v << " "; } return os;}
ostream &operator<<(ostream &os, vector<vector<char>> &vec_) { rep(h, sz(vec_)) { rep(w, sz(vec_[0])) { os << vec_[h][w]; } os << endl; } return os;}
/*@formatter:off*/
//template<class T,class U>ostream &operator<<(ostream &os, vector<pair<T,U>>& a) {fora_f(v,a)os<<v<<endl;return os;}
template<typename W, typename H> void resize(W &vec_, const H head) { vec_.resize(head); }
template<typename W, typename H, typename ... T> void resize(W &vec_, const H &head, const T ... tail) {vec_.resize(head);for (auto &v: vec_)resize(v, tail...);}
//#define use_for_each //_each _all_of _any_of _none_of _find_if _rfind_if _contains _count_if _erase_if _entry_if
#ifdef use_for_each
//todo Atcoderの過去問がc++17に対応したら
#if __cplusplus >= 201703L
//for_each以外はconst & (呼び出し側のラムダも)
template<typename T, typename F> bool all_of2(const T &v, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : v) { if (!all_of2(v_, f))return false; } return true; } else { return f(v); }}
template<typename T, typename F> bool any_of2(const T &v, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : v) { if (!any_of2(v_, f))return true; } return false; } else { return f(v); }}
template<typename T, typename F> bool none_of2(const T &v, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : v) { if (none_of2(v_, f))return false; } return true; } else { return f(v); }}
//存在しない場合
//1次元 Nを返す
//多次元-1を返す
template<typename T, typename F> ll find_if2(const vector<T> &v, F f) { rep(i, sz(v)) { if (f(v[i]))return i; } return sz(v);}
template<typename T, typename F> tuple<int, int> find_if2(const vector<vector<T> > &v, F f) { rep(i, sz(v)) { rep(j, sz(v[i])) { if (f(v[i][j])) { return tuple<int, int>(i, j); }}} return tuple<int, int>(-1, -1);}
template<typename T, typename F> auto find_if2(const vector<vector<vector<T> > > &v, F f) { rep(i, sz(v)) { if (auto ret = find_if2(v[i], f); get<0>(ret) != -1) { return tuple_cat(tuple<int>(i), ret); }} auto bad = tuple_cat(tuple<int>(-1), find_if2(v[0], f)); return bad;}
//存在しない場合
//1次元 -1を返す
//多次元-1を返す
template<typename T, typename F> ll rfind_if2(const vector<T> &v, F f) { rer(i, sz(v) - 1) { if (f(v[i]))return i; } return -1;}
template<typename T, typename F> tuple<int, int> rfind_if2(const vector<vector<T> > &v, F f) { rer(i, sz(v) - 1) { rer(j, sz(v[i]) - 1) { if (f(v[i][j])) { return tuple<int, int>(i, j); }}} return tuple<int, int>(-1, -1);}
template<typename T, typename F> auto rfind_if2(const vector<vector<vector<T> > > &v, F f) { rer(i, sz(v) - 1) { if (auto ret = rfind_if2(v[i], f); get<0>(ret) != -1) { return tuple_cat(tuple<int>(i), ret); }} auto bad = tuple_cat(tuple<int>(-1), rfind_if2(v[0], f)); return bad;}
//todo まとめられそう string,vector全般
template<class T> bool contains(const string &s, const T &v) { return s.find(v) != string::npos; }
template<typename T> bool contains(const vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); }
template<typename T, typename F> bool contains_if2(const vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); }
template<typename T, typename F> ll count_if2(const T &v, F f) { if constexpr(has_value_type<T>::value) { ll ret = 0; for (auto &&v_ : v) { ret += count_if2(v_, f); } return ret; } else { return f(v); }}
template<typename T, typename F> void for_each2(T &a, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : a)for_each2(v_, f); } else { f(a); }}
#else
template<typename T, typename F> bool all_of2(const T &v, F f) { return f(v); }
template<typename T, typename F> bool all_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (!all_of2(v[i], f))return false; } return true;}
template<typename T, typename F> bool any_of2(const T &v, F f) { return f(v); }
template<typename T, typename F> bool any_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (any_of2(v[i], f))return true; } return false;}
template<typename T, typename F> bool none_of2(const T &v, F f) { return f(v); }
template<typename T, typename F> bool none_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (none_of2(v[i], f))return false; } return true;}
template<typename T, typename F> bool find_if2(const T &v, F f) { return f(v); }
template<typename T, typename F> ll find_if2(const vector<T> &v, F f) { rep(i, sz(v)) { if (find_if2(v[i], f))return i; } return sz(v);}
template<typename T, typename F> bool rfind_if2(const T &v, F f) { return f(v); }
template<typename T, typename F> ll rfind_if2(const vector<T> &v, F f) { rer(i, sz(v) - 1) { if (rfind_if2(v[i], f))return i; } return -1;}
template<class T> bool contains(const string &s, const T &v) { return s.find(v) != string::npos; }
template<typename T> bool contains(const vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); }
template<typename T, typename F> bool contains_if2(const vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); }
template<typename T, typename F> ll count_if2(const T &v, F f) { return f(v); }
template<typename T, typename F> ll count_if2(const vector<T> &vec_, F f) { ll ret = 0; fora(v, vec_) { ret += count_if2(v, f); } return ret;}
template<typename T, typename F> void for_each2(T &a, F f) {
f(a);
}
template<typename T, typename F> void for_each2(vector<T> &a, F f) {
for (auto &&v_ : a)for_each2(v_, f);
}
#endif
template<typename W> ll count_od(const vector<W> &a) { return count_if2(a, [](ll v) { return v & 1; }); }
template<typename W> ll count_ev(const vector<W> &a) { return count_if2(a, [](ll v) { return !(v & 1); }); }
//削除した後のvectorを返す
template<typename T, typename F> vector<T> erase_if2(const vector<T> &v, F f) { vector<T> nv; rep(i, sz(v)) { if (!f(v[i])) { nv.push_back(v[i]); }} return nv;}
template<typename T, typename F> vector<vector<T>> erase_if2(const vector<vector<T>> &v, F f) { vector<vector<T>> res; rep(i, sz(v)) { res[i] = erase_if2(v[i], f); } return res;}
template<typename T, typename F> vector<T> entry_if2(const vector<T> &v, F f) {vector<T> nv;rep(i, sz(v)) { if (f(v[i])) { nv.push_back(v[i]); }}return nv;}
template<typename T, typename F> vector<vector<T>> entry_if2(const vector<vector<T>> &v, F f) {vector<vector<T>> res;rep(i, sz(v)) { res[i] = entry_if2(v[i], f); }return res;}
template<typename T, typename F> ll l_rfind_if(const vector<T> &v, F f) {rer(i, sz(v) - 1) { if (f(v[i]))return i; }return -1;}
template<typename T, typename F> bool l_contains_if(const vector<T> &v, F f) {rer(i, sz(v) - 1) { if (f(v[i]))return true; }return false;}
template<class A, class B, class C> auto t_all_of(A a, B b, C c) { return std::all_of(a, b, c); }
template<class A, class B, class C> auto t_any_of(A a, B b, C c) { return std::any_of(a, b, c); }
template<class A, class B, class C> auto t_none_of(A a, B b, C c) { return std::none_of(a, b, c); }
template<class A, class B, class C> auto t_find_if(A a, B b, C c) { return std::find_if(a, b, c); }
template<class A, class B, class C> auto t_count_if(A a, B b, C c) { return std::count_if(a, b, c); }
#define all_of_s__2(a, right) (t_all_of(ALL(a),lamr(right)))
#define all_of_s__3(a, v, siki) (t_all_of(ALL(a),[&](auto v){return siki;}))
#define all_of_s(...) over3(__VA_ARGS__,all_of_s__3,all_of_s__2)(__VA_ARGS__)
//all_of(A, %2);
//all_of(A, a, a%2);
#define all_of__2(a, right) all_of2(a,lamr(right))
#define all_of__3(a, v, siki) all_of2(a,[&](auto v){return siki;})
#define all_of(...) over3(__VA_ARGS__,all_of__3,all_of__2)(__VA_ARGS__)
#define all_of_f(a, f) all_of2(a,f)
#define any_of_s__2(a, right) (t_any_of(ALL(a),lamr(right)))
#define any_of_s__3(a, v, siki) (t_any_of(ALL(a),[&](auto v){return siki;}))
#define any_of_s(...) over3(__VA_ARGS__,any_of_s__3,any_of_s__2)(__VA_ARGS__)
#define any_of__2(a, right) any_of2(a,lamr(right))
#define any_of__3(a, v, siki) any_of2(a,[&](auto v){return siki;})
#define any_of(...) over3(__VA_ARGS__,any_of__3,any_of__2)(__VA_ARGS__)
#define any_of_f(a, f) any_of2(a,f)
#define none_of_s__2(a, right) (t_none_of(ALL(a),lamr(right)))
#define none_of_s__3(a, v, siki) (t_none_of(ALL(a),[&](auto v){return siki;}))
#define none_of_s(...) over3(__VA_ARGS__,none_of_s__3,none_of_s__2)(__VA_ARGS__)
#define none_of__2(a, right) none_of2(a,lamr(right))
#define none_of__3(a, v, siki) none_of2(a,[&](auto v){return siki;})
#define none_of(...) over3(__VA_ARGS__,none_of__3,none_of__2)(__VA_ARGS__)
#define none_of_f(a, f) none_of2(a,f)
#define find_if_s__2(a, right) (t_find_if(ALL(a),lamr(right))-a.begin())
#define find_if_s__3(a, v, siki) (t_find_if(ALL(a),[&](auto v){return siki;})-a.begin())
#define find_if_s(...) over3(__VA_ARGS__,find_if_s__3,find_if_s__2)(__VA_ARGS__)
#define find_if__2(a, right) find_if2(a,lamr(right))
#define find_if__3(a, v, siki) find_if2(a,[&](auto v){return siki;})
#define find_if(...) over3(__VA_ARGS__,find_if__3,find_if__2)(__VA_ARGS__)
#define find_if_f(a, f) find_if2(a,f)
#define rfind_if_s__2(a, right) l_rfind_if(a, lamr(right))
#define rfind_if_s__3(a, v, siki) l_rfind_if(a, [&](auto v){return siki;})
#define rfind_if_s(...) over3(__VA_ARGS__,rfind_if_s__3,rfind_if_s__2)(__VA_ARGS__)
#define rfind_if__2(a, right) rfind_if2(a,lamr(right))
#define rfind_if__3(a, v, siki) rfind_if2(a,[&](auto v){return siki;})
#define rfind_if(...) over3(__VA_ARGS__,rfind_if__3,rfind_if__2)(__VA_ARGS__)
#define rfind_if_f(a, f) rfind_if2(a,f)
#define contains_if_s__2(a, right) l_contains_if(a, lamr(right))
#define contains_if_s__3(a, v, siki) l_contains_if(a, [&](auto v){return siki;})
#define contains_if_s(...) over3(__VA_ARGS__,contains_if_s__3,contains_if_s__2)(__VA_ARGS__)
#define contains_if__2(a, right) contains_if2(a,lamr(right))
#define contains_if__3(a, v, siki) contains_if2(a,[&](auto v){return siki;})
#define contains_if(...) over3(__VA_ARGS__,contains_if__3,contains_if__2)(__VA_ARGS__)
#define contains_if_f(a, f) contains_if2(a,f)
#define count_if_s__2(a, right) (t_count_if(ALL(a),lamr(right)))
#define count_if_s__3(a, v, siki) (t_count_if(ALL(a),[&](auto v){return siki;}))
#define count_if_s(...) over3(__VA_ARGS__,count_if_s__3,count_if_s__2)(__VA_ARGS__)
#define count_if__2(a, right) count_if2(a,lamr(right))
#define count_if__3(a, v, siki) count_if2(a,[&](auto v){return siki;})
#define count_if(...) over3(__VA_ARGS__,count_if__3,count_if__2)(__VA_ARGS__)
#define count_if_f(a, f) count_if2(a,f)
//vector<vi>で、viに対して操作
#define for_each_s__2(a, right) do{fora(v,a){v right;}}while(0)
#define for_each_s__3(a, v, shori) do{fora(v,a){shori;}}while(0)
#define for_each_s(...) over3(__VA_ARGS__,for_each_s__3,for_each_s__2)(__VA_ARGS__)
//vector<vi>で、intに対して操作
#define for_each__2(a, right) for_each2(a,lamr(right))
#define for_each__3(a, v, shori) for_each2(a,[&](auto& v){shori;})
#define for_each(...) over3(__VA_ARGS__,for_each__3,for_each__2)(__VA_ARGS__)
#define for_each_f(a, f) for_each2(a, f);
template<class T, class F> vector<T> help_for_eached(const vector<T> &A, F f) { vector<T> ret = A; for_each(ret, v, f(v)); return ret;}
#define for_eached__2(a, right) help_for_eached(a, lamr(right))
#define for_eached__3(a, v, shori) help_for_eached(a, lam(v, shori))
#define for_eached(...) over3(__VA_ARGS__,for_eached__3,for_eached__2)(__VA_ARGS__)
#define for_eached_f(a, f) for_eached2(a, f);
#define each for_each
#define eached for_eached
//#define erase_if_s__2(a, right) l_erase_if2(a,lamr(right))
//#define erase_if_s__3(a, v, siki) l_erase_if2(a,[&](auto v){return siki;})
//#define erase_if_s(...) over3(__VA_ARGS__,erase_if_s__3,erase_if_s__2)(__VA_ARGS__)
#define erase_if__2(a, right) erase_if2(a,lamr(right))
#define erase_if__3(a, v, siki) erase_if2(a,[&](auto v){return siki;})
#define erase_if(...) over3(__VA_ARGS__,erase_if__3,erase_if__2)(__VA_ARGS__)
#define erase_if_f(a, f) erase_if2(a,f)
//#define entry_if_s__2(a, right) l_entry_if2(a,lamr(right))
//#define entry_if_s__3(a, v, siki) l_entry_if2(a,[&](auto v){return siki;})
//#define entry_if_s(...) over3(__VA_ARGS__,entry_if_s__3,entry_if_s__2)(__VA_ARGS__)
#define entry_if__2(a, right) entry_if2(a,lamr(right))
#define entry_if__3(a, v, siki) entry_if2(a,[&](auto v){return siki;})
#define entry_if(...) over3(__VA_ARGS__,entry_if__3,entry_if__2)(__VA_ARGS__)
#define entry_if_f(a, f) entry_if2(a,f)
#endif
/*@formatter:off*/
template<class T, class U, class W> void replace(vector<W> &a, T key, U v) { rep(i, sz(a))if (a[i] == key)a[i] = v; }
template<class T, class U, class W> void replace(vector<vector<W>> &A, T key, U v) { rep(i, sz(A))replace(A[i], key, v); }
void replace(str &a, char key, str v) { if (v == "")a.erase(remove(ALL(a), key), a.end()); }
void replace(str &a, char key, char v) { replace(ALL(a), key, v); }
//keyと同じかどうか01で置き換える
template<class T, class U> void replace(vector<T> &a, U k) { rep(i, sz(a)) a[i] = a[i] == k; }
template<class T, class U> void replace(vector<vector<T >> &a, U k) { rep(i, sz(a))rep(j, sz(a[0])) a[i][j] = a[i][j] == k; }
void replace(str &a) { int dec = 0; if ('a' <= a[0] && a[0] <= 'z')dec = 'a'; if ('A' <= a[0] && a[0] <= 'Z')dec = 'A'; fora(v, a) { v -= dec; }}
void replace(str &a, str key, str v) { stringstream t; ll kn = sz(key); std::string::size_type Pos(a.find(key)); ll l = 0; while (Pos != std::string::npos) { t << a.substr(l, Pos - l); t << v; l = Pos + kn; Pos = a.find(key, Pos + kn); } t << a.substr(l, sz(a) - l); a = t.str();}
template<class T> bool is_permutation(vector<T> &a, vector<T> &b) { return is_permutation(ALL(a), ALL(b)); }
template<class T> bool next_permutation(vector<T> &a) { return next_permutation(ALL(a)); }
vi iota(ll s, ll len) {vi ve(len);iota(ALL(ve), s);return ve;}
template<class A, class B> auto vtop(vector<A> &a, vector<B> &b) { assert(sz(a) == sz(b)); /*stringを0で初期化できない */ vector<pair<A, B>> res; rep(i, sz(a))res.eb(a[i], b[i]); return res;}
template<class A, class B> void ptov(vector<pair<A, B>> &p, vector<A> &a, vector<B> &b) { a.resize(sz(p)), b.resize(sz(p)); rep(i, sz(p))a[i] = p[i].fi, b[i] = p[i].se;}
template<class A, class B, class C> auto vtot(vector<A> &a, vector<B> &b, vector<C> &c) { assert(sz(a) == sz(b) && sz(b) == sz(c)); vector<T2<A, B, C>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i]); return res;}
template<class A, class B, class C, class D> auto vtof(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { assert(sz(a) == sz(b) && sz(b) == sz(c) && sz(c) == sz(d)); vector<F2<A, B, C, D>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i], d[i]); return res;}
/*@formatter:off*/
template<class T> void sort(vector<T> &a, int l = -1, int r = -1) { set_lr12(l, r, sz(a)); fast_sort(a.begin() + l, a.begin() + r);}
template<class T> void rsort(vector<T> &a, int l = -1, int r = -1) { set_lr12(l, r, sz(a)); fast_sort(a.begin() + l, a.begin() + r, greater<T>());};
template<class A, class B> void sortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); sort(c); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}
template<class A, class B> void rsortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); rsort(c); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;}
template<class A, class B, class C> void sortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); sort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class A, class B, class C> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); rsort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class... T, class U> auto sorted(U head, T... a) { sort(head, a...); return head;}
template<class... T, class U> auto rsorted(U head, T... a) {rsort(head, a...);return head;}
//sortindex 元のvectorはソートしない
template<class T> vi sorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind); return ind;}
//#define use_sort
#ifdef use_sort
enum pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd };
enum tcomparator { fisiti, fisitd, fisdti, fisdtd, fdsiti, fdsitd, fdsdti, fdsdtd, fitisi, fitisd, fitdsi, fitdsd, fdtisi, fdtisd, fdtdsi, fdtdsd, sifiti, sifitd, sifdti, sifdtd, sdfiti, sdfitd, sdfdti, sdfdtd, sitifi, sitifd, sitdfi, sitdfd, sdtifi, sdtifd, sdtdfi, sdfdfd, tifisi, tifisd, tifdsi, tifdsd, tdfisi, tdfisd, tdfdsi, tdfdsd, tisifi, tisifd, tisdfi, tisdfd, tdsifi, tdsifd, tdsdfi, tdsdfd};
template<class A, class B> void sort(vector<pair<A, B>> &a, pcomparator type) {typedef pair<A, B> U;if (type == fisi) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; }); else if (type == fisd) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; }); else if (type == fdsi) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; }); else if (type == fdsd) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; }); else if (type == sifi) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; }); else if (type == sifd) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; }); else if (type == sdfi) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; }); else if (type == sdfd) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });};
template<class U> void sort(vector<U> &a, pcomparator type) { if (type == fisi) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == fisd) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == fdsi) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == fdsd) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == sifi) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == sifd) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == sdfi) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == sdfd) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f > r.f; }); };
template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D> > &a, pcomparator type) {typedef F2<A, B, C, D> U;if (type == fisi) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == fisd) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == fdsi) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == fdsd) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == sifi) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == sifd) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == sdfi) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == sdfd) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a > r.a; });};
template<class U> void sort(vector<U> &a, tcomparator type) {if (type == 0) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 1) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 2) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 3) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 4) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 5) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 6) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 7) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 8) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 9) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 10) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 11) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 12) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 13) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 14) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 15) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 16) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 17) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 18) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 19) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 20) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 21) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 22) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 23) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 24) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 25) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 26) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 27) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 28) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 29) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 30) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 31) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 32) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 33) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 34) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 35) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 36) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 37) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 38) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 39) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 40) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 41) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 42) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 43) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f > r.f; }); else if (type == 44) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 45) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 46) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 47) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f > r.f; });}
template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D>> &a, tcomparator type) { typedef F2<A, B, C, D> U; if (type == 0) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 1) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 2) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 3) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 4) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 5) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 6) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 7) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 8) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 9) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 10) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 11) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 12) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 13) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 14) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 15) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 16) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 17) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 18) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 19) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 20) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 21) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 22) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 23) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 24) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 25) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 26) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 27) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 28) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 29) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 30) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 31) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 32) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 33) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 34) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 35) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 36) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 37) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 38) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 39) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 40) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 41) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 42) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 43) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a > r.a; }); else if (type == 44) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 45) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 46) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 47) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a > r.a; });}
/*@formatter:off*/
void sort(string &a) { sort(ALL(a)); }
void rsort(string &a) { sort(RALL(a)); }
void sort(int &a, int &b) { if (a > b)swap(a, b); }
void sort(int &a, int &b, int &c) { sort(a, b); sort(a, c); sort(b, c);}
void rsort(int &a, int &b) { if (a < b)swap(a, b); }
void rsort(int &a, int &b, int &c) { rsort(a, b); rsort(a, c); rsort(b, c);}
//P l, P rで f(P) の形で渡す
template<class U, class F> void sort(vector<U> &a, F f) { sort(ALL(a), [&](U l, U r) { return f(l) < f(r); }); };
template<class U, class F> void rsort(vector<U> &a, F f) { sort(ALL(a), [&](U l, U r) { return f(l) > f(r); }); };
//F = T<T>
//例えばreturn p.fi + p.se;
template<class A, class B, class F> void sortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); sort(c, f); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}
template<class A, class B, class F> void rsortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); rsort(c, f); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;}
template<class A, class B, class C, class F> void sortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); sort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class A, class B, class C, class F> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); rsort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class A, class B, class C, class D> void sortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); sort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;}
template<class A, class B, class C, class D> void rsortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); rsort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;}
/*indexの分で型が変わるためpcomparatorが必要*/
template<class T> vi sorti(vector<T> &a, pcomparator f) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind, f); return ind;}
template<class T, class F> vi sorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(a[x]) < f(a[y]); }); return ind;}
template<class T> vi rsorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); rsortp(b, ind); return ind;}
template<class T, class F> vi rsorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(a[x]) > f(a[y]); }); return ind;}
template<class A, class B, class F> vi sortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(c[x]) < f(c[y]); }); return ind;}
template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b, pcomparator f) { vi ind = iota(0, sz(a)); auto c = a; auto d = b; sortt(c, d, ind, f); return ind;}
template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fisi); };
template<class A, class B, class F> vi rsortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(c[x]) > f(c[y]); }); return ind;}
template<class A, class B> vi rsortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fdsd); };
template<class A, class B, class C, class F> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(d[x]) < f(d[y]); }); return ind;}
template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, pcomparator f) { vi ind = iota(0, sz(a)); auto d = vtof(a, b, c, ind); sort(d, f); rep(i, sz(a))ind[i] = d[i].d; return ind;}
template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] < c[y]; else return b[x] < b[y]; } else { return a[x] < a[y]; }}); return ind;}
template<class A, class B, class C, class F> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(d[x]) > f(d[y]); }); return ind;}
template<class A, class B, class C> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] > c[y]; else return b[x] > b[y]; } else { return a[x] > a[y]; }}); return ind;}
template<class T> void sort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)sort(a[i]); }
template<class T> void rsort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)rsort(a[i]); }
#endif
template<class T> bool includes(vector<T> &a, vector<T> &b) { vi c = a; vi d = b; sort(c); sort(d); return includes(ALL(c), ALL(d));}
template<class T> bool distinct(const vector<T> &A) { if ((int) (A).size() == 1)return true; if ((int) (A).size() == 2)return A[0] != A[1]; if ((int) (A).size() == 3)return (A[0] != A[1] && A[1] != A[2] && A[0] != A[2]); auto B = A; sort(B); int N = (B.size()); unique(B); return N == (int) (B.size());}
template<class H, class... T> bool distinct(const H &a, const T &...b) { return distinct(vector<H>{a, b...}); }
/*@formatter:off*/
template<typename W, typename T> void fill(W &xx, const T vall) { xx = vall; }
template<typename W, typename T> void fill(vector<W> &vecc, const T vall) { for (auto &&vx : vecc)fill(vx, vall); }
template<typename W, typename T> void fill(vector<W> &xx, const T v, ll len) { rep(i, len)xx[i] = v; }
template<typename W, typename T> void fill(vector<W> &xx, const T v, int s, ll t) { rep(i, s, t)xx[i] = v; }
template<typename W, typename T> void fill(vector<vector<W>> &xx, T v, int sh, int th, int sw, int tw) { rep(h, sh, th)rep(w, sw, tw)xx[h][w] = v; }
//#define use_fill //_sum _array _max _min
#ifdef use_fill
template<typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) { rep(i, N)a[i] = v; }
template<typename A, size_t N, size_t O, typename T> void fill(A (&a)[N][O], const T &v) { rep(i, N)rep(j, O)a[i][j] = v; }
template<typename A, size_t N, size_t O, size_t P, typename T> void fill(A (&a)[N][O][P], const T &v) { rep(i, N)rep(j, O)rep(k, P)a[i][j][k] = v; }
template<typename A, size_t N, size_t O, size_t P, size_t Q, typename T> void fill(A (&a)[N][O][P][Q], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)a[i][j][k][l] = v; }
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, typename T> void fill(A (&a)[N][O][P][Q][R], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)a[i][j][k][l][m] = v; }
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S, typename T> void fill(A (&a)[N][O][P][Q][R][S], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)a[i][j][k][l][m][n] = v; }
template<class T, class U> void fill(vector<T> &a, const vi &ind, U val) { fora(v, ind) { a[v] = val; }}
template<typename A, size_t N> A sum(A (&a)[N]) {A res = 0; rep(i, N)res += a[i]; return res;}
template<typename A, size_t N, size_t O> A sum(A (&a)[N][O]) {A res = 0; rep(i, N)rep(j, O)res += a[i][j]; return res;}
template<typename A, size_t N, size_t O, size_t P> A sum(A (&a)[N][O][P]) {A res = 0; rep(i, N)rep(j, O)rep(k, P)res += a[i][j][k]; return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q> A sum(A (&a)[N][O][P][Q]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)res += a[i][j][k][l]; return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A sum(A (&a)[N][O][P][Q][R]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)res += a[i][j][k][l][m]; return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A sum(A (&a)[N][O][P][Q][R][S]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)res += a[i][j][k][l][m][n]; return res;}
template<typename A, size_t N> A max(A (&a)[N]) {A res = a[0]; rep(i, N)res = max(res, a[i]); return res;}
template<typename A, size_t N, size_t O> A max(A (&a)[N][O]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q> A max(A (&a)[N][O][P][Q], const T &v) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A max(A (&a)[N][O][P][Q][R]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A max(A (&a)[N][O][P][Q][R][S]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N> A min(A (&a)[N]) { A res = a[0]; rep(i, N)res = min(res, a[i]); return res;}
template<typename A, size_t N, size_t O> A min(A (&a)[N][O]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q> A min(A (&a)[N][O][P][Q], const T &v) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A min(A (&a)[N][O][P][Q][R]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A min(A (&a)[N][O][P][Q][R][S]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
#endif
/*@formatter:off*/
template<class T, class U> void inc(pair<T, U> &a, U v = 1) { a.first += v, a.second += v; }
template<class T, class U> void inc(T &a, U v = 1) { a += v; }
template<class T, class U = int> void inc(vector<T> &a, U v = 1) { for (auto &u:a)inc(u, v); }
template<class T, class U> void dec(T &a, U v = 1) { a -= v; }
template<class T, class U = int> void dec(vector<T> &a, U v = 1) { for (auto &u :a)dec(u, v); }
template<class U> void dec(string &a, U v = 1) { for (auto &u :a)dec(u, v); }
template<class T, class U, class W> void dec(vector<T> &a, vector<U> &b, W v = 1) {for (auto &u :a)dec(u, v);for (auto &u :b)dec(u, v);}
template<class T, class U, class W> void dec(vector<T> &a, vector<U> &b, vector<W> &c) { for (auto &u :a)dec(u, 1); for (auto &u :b)dec(u, 1); for (auto &u :c)dec(u, 1);}
bool ins(ll h, ll w, ll H, ll W) { return h >= 0 && w >= 0 && h < H && w < W; }
bool san(ll l, ll v, ll r) { return l <= v && v < r; }
template<class T> bool ins(vector<T> &a, ll i, ll j = 0) { return san(0, i, sz(a)) && san(0, j, sz(a)); }
#define inside ins
ll u0(ll a) { return a < 0 ? 0 : a; }
template<class T> vector<T> u0(vector<T> &a) { vector<T> ret = a; fora(v, ret) { v = u(v); } return ret;}
//todo 名前
bool d_(int a, int b) {if (b == 0)return false;return (a % b) == 0;}
//エラー
void ole() {
#ifdef _DEBUG
cerr << "ole" << endl;exit(0);
#endif
string a = "a"; rep(i, 30)a += a; rep(i, 1 << 17)cout << a << endl; cout << "OLE 出力長制限超過" << endl;exit(0);
}
void re(string s = "") {cerr << s << endl;assert(0 == 1);exit(0);}
void tle() { while (inf)cout << inf << endl; }
//@汎用便利関数 入力
ll in() {ll ret;cin >> ret;return ret;}
template<class T> T in() { T ret; cin >> ret; return ret;}
string sin() { string ret; cin >> ret; return ret;}
template<class T> void in(T &head) { cin >> head; }
template<class T, class... U> void in(T &head, U &... tail) { cin >> head; in(tail...);}
//value_typeを持つ場合呼べる
//len回要素を追加する
template<class Iterable, class T = typename Iterable::value_type> Iterable tin(int len) { Iterable ret; T tem; while (len--) { cin >> tem; ret += tem; } return ret;}
template<class T> T tin() { T ret; cin >> ret; return ret;}
template<class T> T tind(int len = 0) { auto ret = tin<T>(len); dec(ret, 1); return ret;}
#define din_t2(type, a) type a;cin>>a
#define din_t3(type, a, b) type a,b;cin>>a>> b
#define din_t4(type, a, b, c) type a,b,c;cin>>a>>b>>c
#define din_t5(type, a, b, c, d) type a,b,c,d;cin>>a>>b>>c>>d
#define din_t6(type, a, b, c, d, e) type a,b,c,d,e;cin>>a>>b>>c>>d>>e
#define din_t7(type, a, b, c, d, e, f) type a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f
#define din_t(...) over7(__VA_ARGS__,din_t7,din_t6,din_t5,din_t4,din_t3 ,din_t2)(__VA_ARGS__)
#define din(...) din_t(int,__VA_ARGS__)
#define d_in
#define dsig(...) din_t(signed,__VA_ARGS__)
#define dst(...) din_t(string,__VA_ARGS__)
#define dstr dst
#define d_str dst
#define dcha(...) din_t(char,__VA_ARGS__)
#define dchar dcha
#define ddou(...) din_t(double,__VA_ARGS__)
#define din1d(a) din_t2(int, a);a--
#define din2d(a, b) din_t3(int, a,b);a--,b--
#define din3d(a, b, c) din_t4(int, a,b,c);a--,b--,c--
#define din4d(a, b, c, d) din_t5(int, a,b,c,d);a--,b--,c--,d--
#define dind(...) over4(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__)
/*@formatter:off*/
#ifdef _DEBUG
template<class T> void err2(T &&head) { cerr << head; }
template<class T, class... U> void err2(T &&head, U &&... tail) { cerr << head << " "; err2(tail...);}
template<class T, class... U> void err(T &&head, U &&... tail) { cerr << head << " "; err2(tail...); cerr << "" << endl;}
template<class T> void err(T &&head) { cerr << head << endl; }
void err() { cerr << "" << endl; }
//debで出力する最大長
constexpr int DEB_LEN = 20;
constexpr int DEB_LEN_H = 12;
string deb_tos(const int &v) { if (abs(v) == inf || abs(v) == linf)return "e"; else return to_string(v); }
template<class T> string deb_tos(const T &a) {stringstream ss;ss << a;return ss.str();}
#ifdef use_epsdou
string deb_tos(const epsdou &a) {return deb_tos(a.v);}
#endif
template<class T> string deb_tos(const optional<T> &a) { if (a.has_value()) { return deb_tos(a.value()); } else return "e"; }
template<class T> string deb_tos(const vector<T> &a, ll W = inf) { stringstream ss; if (W == inf)W = min(sz(a), DEB_LEN); if (sz(a) == 0)return ss.str(); rep(i, W) { ss << deb_tos(a[i]); if (typeid(a[i]) == typeid(P)) { ss << endl; } else { ss << " "; } } return ss.str();}
template<class T> string deb_tos(const vector<vector<T> > &a, vi H, vi W, int key = -1) { stringstream ss; ss << endl; vi lens(sz(W)); fora(h, H) { rep(wi, sz(W)) { lens[wi] = max(lens[wi], sz(deb_tos(a[h][W[wi]])) + 1); lens[wi] = max(lens[wi], sz(deb_tos(W[wi])) + 1); } } if (key == -1)ss << " *|"; else ss << " " << key << "|"; int wi = 0; fora(w, W) { ss << std::right << std::setw(lens[wi]) << w; wi++; } ss << "" << endl; rep(i, sz(W))rep(lens[i])ss << "_"; rep(i, 3)ss << "_"; ss << "" << endl; fora(h, H) { ss << std::right << std::setw(2) << h << "|"; int wi = 0; fora(w, W) { ss << std::right << std::setw(lens[wi]) << deb_tos(a[h][w]); wi++; } ss << "" << endl; } return ss.str();}
template<class T> string deb_tos(const vector<vector<T> > &a, ll H = inf, ll W = inf, int key = -1) { H = (H != inf) ? H : min({H, sz(a), DEB_LEN_H}); W = min({W, sz(a[0]), DEB_LEN_H}); vi hs, ws; rep(h, H) { hs.push_back(h); } rep(w, W) { ws.push_back(w); } return deb_tos(a, hs, ws, key);}
template<class T> string deb_tos(const vector<vector<vector<T> > > &a, ll H = inf) { stringstream ss; if (H == inf)H = DEB_LEN_H; H = min(H, sz(a)); rep(i, H) { ss << endl; ss << deb_tos(a[i], inf, inf, i); } return ss.str();}
template<class T> string deb_tos(vector<set<T> > &a, ll H = inf, ll W = inf, int key = -1) { vector<vector<T> > b(sz(a)); rep(i, sz(a)) { fora(v, a[i]) { b[i].push_back(v); }} return deb_tos(b, H, W, key);}
template<class T, size_t A> string deb_tos(T (&a)[A]) { return deb_tos(vector<T>(begin(a), end(a))); }
template<class T, size_t A, size_t B> string deb_tos(T (&a)[A][B]) { return deb_tos(vector<vector<T> >(begin(a), end(a))); }
template<class T, size_t A, size_t B, size_t C> string deb_tos(T (&a)[A][B][C]) { return deb_tos(vector<vector<vector<T> > >(begin(a), end(a))); }
/*@formatter:off*/
template<class T> void out2(T head) { cout << head; res_mes += deb_tos(head);}
template<class T, class... U> void out2(T head, U ... tail) { cout << head << " "; res_mes += deb_tos(head) + " "; out2(tail...);}
template<class T, class... U> void out(T head, U ... tail) { cout << head << " "; res_mes += deb_tos(head) + " "; out2(tail...); cout << "" << endl; res_mes += "\n";}
template<class T> void out(T head) { cout << head << endl; res_mes += deb_tos(head) + "\n";}
void out() { cout << "" << endl; }
#else
#define err(...);
template<class T> void out2(T &&head) { cout << head; }
template<class T, class... U> void out2(T &&head, U &&... tail) { cout << head << " "; out2(tail...);}
template<class T, class... U> void out(T &&head, U &&... tail) { cout << head << " "; out2(tail...); cout << "" << endl;}
template<class T> void out(T &&head) { cout << head << endl;}
void out() { cout << "" << endl;}
#endif
template<class T> void outl(const vector<T> &a, int n = inf) { rep(i, min(n, sz(a)))cout << a[i] << endl; }
//テーブルをスペースなしで出力
template<class T> void outt(vector<vector<T>> &a) { rep(i, sz(a)) { rep(j, sz(a[i])) { cout << a[i][j]; } cout << endl; }}
//int型をbit表記で出力
void outb(int a) { cout << bitset<20>(a) << endl; }
/*@formatter:off*/
template<class T> void na(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i];}
template<class T> void na(set<T> &a, ll n) { rep(i, n)a.insert(in()); }
#define dna(a, n) vi a; na(a, n);/*nを複数使うと n==in()の時バグる事に注意*/
#define dnad(a, n) vi a; nad(a, n);
template<class T> void nao(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1];}
template<class T> void naod(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1], a[i + 1]--;}
template<class T> void nad(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i], a[i]--;}
template<class T> void nad(set<T> &a, ll n) { rep(i, n)a.insert(in() - 1); }
template<class T, class U> void na2(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i];}
template<class T, class U> void na2(set<T> &a, set<U> &b, ll n) { rep(i, n) { a.insert(in()); b.insert(in()); }}
#define dna2(a, b, n) vi a,b; na2(a,b,n);
template<class T, class U> void nao2(vector<T> &a, vector<U> &b, ll n) { a.resize(n + 1); b.resize(n + 1); a[0] = b[0] = 0; rep(i, n)cin >> a[i + 1] >> b[i + 1];}
template<class T, class U> void na2d(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i], a[i]--, b[i]--;}
#define dna2d(a, b, n) vi a,b; na2d(a,b,n);
template<class T, class U, class W> void na3(vector<T> &a, vector<U> &b, vector<W> &c, ll n) {a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i];}
#define dna3(a, b, c, n) vi a,b,c; na3(a,b,c,n);
template<class T, class U, class W> void na3d(vector<T> &a, vector<U> &b, vector<W> &c, ll n) {a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--, c[i]--;}
#define dna3d(a, b, c, n) vi a,b,c; na3d(a,b,c,n);
template<class T, class U, class W, class X> void na4(vector<T> &a, vector<U> &b, vector<W> &c, vector<X> &d, ll n) {a.resize(n); b.resize(n); c.resize(n); d.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i] >> d[i];}
#define dna4(a, b, c, d, n) vi a,b,c,d; na4(a,b,c,d,n);
#define dna4d(a, b, c, d, n) vi a,b,c,d; na4d(a,b,c,d,n);
#define nt(a, h, w) resize(a,h,w);rep(nthi,h)rep(ntwi,w) cin >> a[nthi][ntwi];
#define ntd(a, h, w) resize(a,h,w);rep(ntdhi,h)rep(ntdwi,w) cin >> a[ntdhi][ntdwi], a[ntdhi][ntdwi]--;
#define ntp(a, h, w) resize(a,h+2,w+2);fill(a,'#');rep(ntphi,1,h+1)rep(ntpwi,1,w+1) cin >> a[ntphi][ntpwi];
#define dnt(S, h, w) vvi(S,h,w);nt(S,h,w);
#define dntc(S, h, w) vvc(S,h,w);nt(S,h,w);
#define dnts(S, h, w) vvs(S,h,w);nt(S,h,w);
//デバッグ
#define sp << " " <<
/*@formatter:off*/
#define deb1(x) debugName(x)<<" = "<<deb_tos(x)
#define deb_2(x, ...) deb1(x) <<", "<< deb1(__VA_ARGS__)
#define deb_3(x, ...) deb1(x) <<", "<< deb_2(__VA_ARGS__)
#define deb_4(x, ...) deb1(x) <<", "<< deb_3(__VA_ARGS__)
#define deb5(x, ...) deb1(x) <<", "<< deb_4(__VA_ARGS__)
#define deb6(x, ...) deb1(x) <<", "<< deb5(__VA_ARGS__)
//#define deb7(x, ...) deb1(x) <<", "<< deb6(__VA_ARGS__)
//#define deb8(x, ...) deb1(x) <<", "<< deb7(__VA_ARGS__)
//#define deb9(x, ...) deb1(x) <<", "<< deb8(__VA_ARGS__)
//#define deb10(x, ...) deb1(x) <<", "<< deb9(__VA_ARGS__)
/*@formatter:off*/
#ifdef _DEBUG
bool was_deb = false;
#define deb(...) do{was_deb=true;cerr<< over10(__VA_ARGS__,deb10,deb9,deb8,deb7,deb6,deb5,deb_4,deb_3,deb_2,deb1)(__VA_ARGS__) <<endl;}while(0)
#define base_keta 8
void print_n_base(int x, int base) { cerr << bitset<base_keta>(x) << endl; }
template<class T> void print_n_base(vector<T> X, int base) {cerr << endl; for (auto &&x:X) { print_n_base(x, base); } cerr << endl;}
//n進数
#define deb2(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 2);
#define deb3(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 3);
#define deb4(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 4);
#define deb_ex_deb(x, len) debugName(x)<<" = "<<deb_tos(x, len)
#define call_deb_ex_deb(x, len) deb_ex_deb(x, len)
//要素が存在する行だけ出力(vvt)
#define deb_ex(v) do {int N = sz(v);int s = N;int t = 0;rep(i, N) {if (sz(v[i])) {chmi(s, i);chma(t, i);}}auto ex_v = sub(v, s, N);str S = deb_tos(ex_v, sz(ex_v));debugName(v);cerr<<" = "<<endl;cerr << S << endl;} while (0);
#define debi(A) {int len=min(sz(A),20); was_deb=true;cerr<<debugName(A)<<" = "<<endl;rep(i, len)cerr<<std::right << std::setw((int)(sz(tos(A[i]))+(i ? 1 : 0)))<<(i%10);cerr<<endl;rep(i, len)cerr<<std::right << std::setw((int)(sz(tos(A[i]))+(i ? 1 : 0)))<<A[i];cerr<<endl;}
template<class T, class F> string deb_tos_f(vector<vector<T> > &a, F f, int key = -1) {vi hs, ws_; int H = sz(a), W = sz(a[0]); vi exh(H), exw(W); rep(h, H) { rep(w, W) { if (f(a[h][w])) { exh[h] = true; exw[w] = true; } } } rep(h, H) if (exh[h])hs.push_back(h); rep(w, W) if (exw[w])ws_.push_back(w); return deb_tos(a, hs, ws_, key);}
template<class T, class F> string deb_tos_f(vector<vector<vector<T>>> &a, F f) {stringstream ss; int H = sz(a); if (sz(a) == 0)return ss.str(); rep(i, H) { ss << deb_tos_f(a[i], f, i); } ss << "" << endl; return ss.str();}
#define debf_normal(tab, f) do{cerr<<debugName(tab)<<" = "<<endl;cerr<< deb_tos_f(tab, f)<<endl;}while(0);
#define debf2(tab, siki_r) debf_normal(tab, lamr(siki_r))
#define debf3(tab, v, siki) debf_normal(tab, lam(siki))
//S, sikir
//S, v, siki
#define debf(...) over3(__VA_ARGS__,debf3,debf2,debf1)(__VA_ARGS__)
#else
#define deb(...) ;
#define deb2(...) ;
#define deb3(...) ;
#define deb4(...) ;
#define deb_ex(...) ;
#define debf(...) ;
#define debi(...) ;
#endif
#define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'
/*@formatter:off*/
using u32 = unsigned;
using u64 = unsigned long long;
using u128 = __uint128_t;
using bint =__int128;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {std::ostream::sentry s(dest);if (s) {__uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } ll len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } }return dest;}
__int128 to_bint(string &s) {__int128 ret = 0; for (ll i = 0; i < (ll) s.length(); ++i) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret;}
void operator>>(istream &iss, bint &v) {string S; iss >> S; v = 0; rep(i, sz(S)) { v *= 10; v += S[i] - '0'; }}
//便利関数
/*@formatter:off*/
//テスト用
#define rand xor128_
unsigned long xor128_(void) {static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t; t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));}
char ranc() { return (char) ('a' + rand() % 26); }
ll rand(ll min, ll max) {assert(min <= max); if (min >= 0 && max >= 0) { return rand() % (max + 1 - min) + min; } else if (max < 0) { return -rand(-max, -min); } else { if (rand() % 2) { return rand(0, max); } else { return -rand(0, -min); }}}
ll rand(ll max) { return rand(0, max); }
template<class T> T rand(vector<T> &A) { return A[rand(sz(A) - 1)]; }
//重複することがある
template<class T> vector<T> ranv(vector<T> &A, int N) {vector<T> ret(N); rep(i, N) { ret[i] = rand(A); } return ret;}
template<class T> vector<T> ranv_unique(vector<T> &A, int N) {vector<T> ret(N); umapi was; rep(j, N) { int i; while (1) { i = rand(sz(A) - 1); if (was.find(i) == was.end())break; } ret[j] = A[i]; was[i] = 1; } return ret;}
vi ranv(ll n, ll min, ll max) {vi v(n); rep(i, n)v[i] = rand(min, max); return v;}
/*@formatter:off*/
#ifdef _DEBUG
bool timeup(int time) {static bool never = true; if (never)message += "may timeup, because slow"; never = false; auto end_time = system_clock::now(); auto part = duration_cast<milliseconds>(end_time - start_time); auto lim = milliseconds(time); return part >= lim;}
#else
bool timeup(int time) {
auto end_time = system_clock::now();
auto part = duration_cast<milliseconds>(end_time - start_time);
auto lim = milliseconds(time);
return part >= lim;
}
#endif
void set_time() { past_time = system_clock::now(); }
//MS型(millisecqnds)で返る
//set_timeをしてからの時間
auto calc_time_milli() {auto now = system_clock::now(); auto part = duration_cast<milliseconds>(now - past_time); return part;}
auto calc_time_micro() {auto now = system_clock::now(); auto part = duration_cast<microseconds>(now - past_time); return part;}
auto calc_time_nano() {auto now = system_clock::now(); auto part = duration_cast<nanoseconds>(now - past_time); return part;}
bool calc_time(int zikan) { return calc_time_micro() >= microseconds(zikan); }
using MS=std::chrono::microseconds;
int div(microseconds a, microseconds b) { return a / b; }
int div(nanoseconds a, nanoseconds b) {if (b < nanoseconds(1)) { return a / nanoseconds(1); } int v = a / b; return v;}
//set_time();
//rep(i,lim)shori
//lim*=time_nanbai();
//rep(i,lim)shoriと使う
//全体でmilliかかっていいときにlimを何倍してもう一回できるかを返す
int time_nanbai(int milli) {auto dec = duration_cast<nanoseconds>(past_time - start_time); auto part = calc_time_nano(); auto can_time = nanoseconds(milli * 1000 * 1000); can_time -= part; can_time -= dec; return div(can_time, part);}
/*@formatter:off*/
//#define use_rand
#ifdef use_rand
str ransu(ll n) {str s; rep(i, n)s += (char) rand('A', 'Z'); return s;}
str ransl(ll n) {str s; rep(i, n)s += (char) rand('a', 'z'); return s;}
//単調増加
vi ranvinc(ll n, ll min, ll max) {vi v(n); bool bad = 1; while (bad) { bad = 0; v.resize(n); rep(i, n) { if (i && min > max - v[i - 1]) { bad = 1; break; } if (i)v[i] = v[i - 1] + rand(min, max - v[i - 1]); else v[i] = rand(min, max); } } return v;}
//便利 汎用
#endif
void ranvlr(ll n, ll min, ll max, vi &l, vi &r) {l.resize(n); r.resize(n); rep(i, n) { l[i] = rand(min, max); r[i] = l[i] + rand(0, max - l[i]); }}
template<class Iterable, class T = typename Iterable::value_type> vector<pair<T, int>> run_length(const Iterable &a) {vector<pair<T, int>> ret; ret.eb(a[0], 1); rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }} return ret;}
/*@formatter:off*/
//#define use_mgr //_goldd _goldt
#ifdef use_mgr
//->[i, f(i)]
template<class T, class U, class F> auto mgr(T ok, U ng, const F &f, require_arg(is_integral<T>::value &&is_integral<U>::value)) { auto mid = (ok + ng); if (ok < ng) while (ng - ok > 1) { mid = (ok + ng) >> 1; if (f(mid))ok = mid; else ng = mid; } else while (ok - ng > 1) { mid = (ok + ng) >> 1; if (f(mid))ok = mid; else ng = mid; } return ok;}
//[l, r)の中で,f(i)がtrueとなる範囲を返す okはそこに含まれる
template<class F> P mgr_range(int l, int r, F f, int ok) {if (f(ok) == 0) { out("f(ok) must true"); re(); } return mp(mgr(ok, l - 1, f), mgr(ok, r, f) + 1);}
template<class F> auto mgrd(dou ok, dou ng, F f, int kai = 100) {if (ok < ng) rep(i, kai) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } else rep(i, kai) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } return ok;}
template<class F> dou mgrd_time(dou ok, dou ng, F f, int time = 1980) {bool han = true; if (ok < ng) while (1) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); if (timeup(time)) { break; } } else while (1) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); if (timeup(time)) { break; } } return ok;}
//todo 減らす
template<class F> auto goldd_l(ll left, ll right, F calc) {double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } ll minScore = MAX<ll>(); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (minScore > score) { minScore = score; resIndex = i; } } return make_tuple(resIndex, calc(resIndex));}
template<class F> auto goldt_l(ll left, ll right, F calc) {double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } if (left > right) { ll l = left; left = right; right = l; } ll maxScore = MIN<ll>(); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (maxScore < score) { maxScore = score; resIndex = i; } } return make_tuple(resIndex, calc(resIndex));}
/*loopは200にすればおそらく大丈夫 余裕なら300に*/
template<class F> auto goldd_d(dou left, dou right, F calc, ll loop = 200) {dou GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); /*200にすればおそらく大丈夫*/ /*余裕なら300に*/ ll k = 141; loop++; while (--loop) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return make_tuple(left, calc(left));}
template<class F> auto goldt_d(dou left, dou right, F calc, ll loop = 200) {double GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); loop++; while (--loop) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return make_tuple(left, calc(left));}
//l ~ rを複数の区間に分割し、極致を与えるiを返す time-20 msまで探索
template<class F> auto goldd_ls(ll l, ll r, F calc, ll time = 2000) { auto lim = milliseconds(time - 20); ll mini = 0, minv = MAX<ll>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldd_l(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(mini, calc(mini));}
template<class F> auto goldt_ls(ll l, ll r, F calc, ll time = 2000) {auto lim = milliseconds(time - 20); ll maxi = 0, maxv = MIN<ll>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldt_l(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(maxi, calc(maxi));}
template<class F> auto goldd_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を持つ*/ auto lim = milliseconds(time - 20); dou mini = 0, minv = MAX<dou>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldd_d(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(mini, calc(mini));}
template<class F> auto goldt_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を残している*/ auto lim = milliseconds(time - 20); dou maxi = 0, maxv = MIN<dou>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldt_d(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(maxi, calc(maxi));}
#endif
//strを整数として比較
string smax(str &a, str b) { if (sz(a) < sz(b)) { return b; } else if (sz(a) > sz(b)) { return a; } else if (a < b)return b; else return a; }
//strを整数として比較
string smin(str &a, str b) { if (sz(a) > sz(b)) { return b; } else if (sz(a) < sz(b)) { return a; } else if (a > b)return b; else return a; }
//エラー-1
template<typename W, typename T> ll find(vector<W> &a, int l, const T key) {rep(i, l, sz(a))if (a[i] == key)return i;return -1;}
template<typename W, typename T> ll find(vector<W> &a, const T key) {rep(i, sz(a))if (a[i] == key)return i;return -1;}
template<typename W, typename T> P find(vector<vector<W >> &a, const T key) {rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return mp(i, j);return mp(-1, -1);}
//getid(find())を返す 1次元にする
template<typename W, typename T> int findi(vector<vector<W >> &a, const T key) {rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return i * sz(a[0]) + j;return -1;}
template<typename W, typename U> tuple<int, int, int> find(vector<vector<vector<W >>> &a, const U key) { rep(i, sz(a))rep(j, sz(a[0]))rep(k, sz(a[0][0]))if (a[i][j][k] == key)return tuple<int, int, int>(i, j, k); return tuple<int, int, int>(-1, -1, -1);}
//無ければ-1
int find(string &s, const string key) { int klen = sz(key); rep(i, sz(s) - klen + 1) { if (s[i] != key[0])continue; if (s.substr(i, klen) == key) { return i; } }return -1;}
int find(string &s, int l, const string key) { int klen = sz(key); rep(i, l, sz(s) - klen + 1) { if (s[i] != key[0])continue; if (s.substr(i, klen) == key) { return i; } } return -1;}
int find(string &s, const char key) { rep(i, sz(s)) { if (s[i] == key)return i; } return -1;}
int find(string &s, int l, const char key) { rep(i, l, sz(s)) { if (s[i] == key)return i; } return -1;}
//N箇所について右のkeyの場所を返す
template<typename W, typename T> vi finds(const W &a, const T& key) { int n = sz(a); vi rpos(n, -1); rer(i, n-1){ if(i<n-1){ rpos[i] = rpos[i+1]; } if(a[i]==key)rpos[i] = i; } return rpos;}
template<typename W, typename T> vi rfinds(const W &a, const T& key) { int n = sz(a); vi lpos(n, -1); rep(i, n){ if(i> 0){ lpos[i] = lpos[i-1]; } if(a[i]==key)lpos[i] = i; } return lpos;}
//todoz
#if __cplusplus >= 201703L
template<typename W, typename T, class Iterable = typename W::value_type>
ll count(const W &a, const T &k) { return count_if(a, ==k); }
/*@formatter:on*/
template<typename W, class Iterable = typename W::value_type> vi count(const W &a) {
vi res;
for_each(a, v, if (sz(res) <= (int) v)res.resize((int) v + 1);
res[v]++;);
return res;
}
#endif
/*@formatter:off*/
ll count(const str &a, const str &k) { ll ret = 0, len = k.length(); auto pos = a.find(k); while (pos != string::npos)pos = a.find(k, pos + len), ++ret; return ret;}
/*@formatter:off*/
//'a' = 'A' = 0 として集計 既に-'a'されていても動く
vi count(str &a, int l, int r) { vi cou(26); char c = 'a'; if ('A' <= a[l] && a[l] <= 'Z')c = 'A'; if ('a' <= a[l] && a[l] <= 'z') c = 'a'; else c = 0; rep(i, l, r)++cou[a[i] - c]; return cou;}
#define couif count_if
//algorythm
ll rev(ll a) { ll res = 0; while (a) { res *= 10; res += a % 10; a /= 10; } return res;}
template<class T> auto rev(const vector<T> &a) { auto b = a; reverse(ALL(b)); return b;}
/* \反転 */ template<class U>
auto rev(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[h][w]; return b;}
/* |反転 */ template<class U>
auto revw(vector<vector<U>> &a) { vector<vector<U> > b(sz(a), vector<U>(sz(a[0]))); int W = sz(a[0]); rep(h, sz(a)) rep(w, sz(a[0])) { b[h][W - 1 - w] = a[h][w]; } return b;}
/* ー反転 */ template<class U>
auto revh(vector<vector<U>> &a) { vector<vector<U> > b(sz(a), vector<U>(sz(a[0]))); int H = sz(a); rep(h, sz(a)) rep(w, sz(a[0])) { b[H - 1 - h][w] = a[h][w]; } return b;}
/* /反転 */ template<class U>
auto revr(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); int H = sz(a); int W = sz(a[0]); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[H - 1 - h][W - 1 - w]; return b;}
auto rev(const string &a) { string b = a; reverse(ALL(b)); return b;}
template<class T> auto rev(const T &v, int i) {return v[sz(v) - 1 - i];}
int rev(int N, int i) {return N-1-i;}
constexpr ll p10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000ll, 100000000000ll, 1000000000000ll, 10000000000000ll, 100000000000000ll, 1000000000000000ll, 10000000000000000ll, 100000000000000000ll, 1000000000000000000ll};
//0は0桁
ll keta(ll v, int if_zero_res) { if(!v)return if_zero_res;if (v < p10[9]) { if (v < p10[4]) { if (v < p10[2]) { if (v < p10[1]) { if (v < p10[0])return 0; else return 1; } else return 2; } else { if (v < p10[3]) return 3; else return 4; }} else { if (v < p10[7]) { if (v < p10[5]) return 5; else if (v < p10[6])return 6; else return 7; } else { if (v < p10[8])return 8; else return 9; }}} else { if (v < p10[13]) { if (v < p10[11]) { if (v < p10[10]) return 10; else return 11; } else { if (v < p10[12]) return 12; else return 13; }} else { if (v < p10[15]) { if (v < p10[14]) return 14; else return 15; } else { if (v < p10[17]) { if (v < p10[16]) return 16; else return 17; } else { if (v < p10[18])return 18; else return 19; }}}}}
#if __cplusplus >= 201703L
ll getr(ll a, ll keta) { return (a / pow<ll>(10, keta)) % 10; }
#else
ll getr(ll a, ll keta) { return (a / (int)pow(10, keta)) % 10; }
#endif
//上から何桁目か
ll getl(ll a, ll ket) {int sketa = keta(a, 1);return getr(a, sketa - 1 - ket);}
ll dsum(ll v, ll sin = 10) {ll ret = 0;for (; v; v /= sin)ret += v % sin;return ret;}
ll mask10(ll v) { return p10[v] - 1; }
//変換系
template<class T, class U> auto to_v1(vector<reference_wrapper<U>>& ret, vector<T> &A) { rep(i, sz(A))ret.push_back(A[i]); return ret;}
template<class T, class U> auto to_v1(vector<reference_wrapper<U>>& ret, vector<vector<T> > &A) {rep(i, sz(A))to_v1(ret, A[i]);return ret;}
//参照付きで1次元に起こす
template<class T> auto to_v1(vector<vector<T> > &A) { vector<reference_wrapper<typename decl2<decltype(A)>::type>> ret; rep(i, sz(A))to_v1(ret, A[i]); return ret;}
//[v] := iとなるようなvectorを返す
//存在しない物は-1
//空でも動く(なぜか)
template<class T> auto keys(const T& a) { vector<decltype((a.begin())->fi)> res; for (auto &&k :a)res.push_back(k.fi); return res;}
template<class T> auto values(const T& a) { vector<decltype((a.begin())->se)> res; for (auto &&k :a)res.push_back(k.se); return res;}
//todo 可変長で
template<class T> constexpr T min(T a, T b, T c) { return a >= b ? b >= c ? c : b : a >= c ? c : a; }
template<class T> constexpr T max(T a, T b, T c) { return a <= b ? b <= c ? c : b : a <= c ? c : a; }
template<class V, class T = typename V::value_type> T min(V &a, ll s = -1, ll n = -1) { set_lr12(s, n, sz(a)); return *min_element(a.begin() + s, a.begin() + min(n, sz(a))); }
template<class V, class T = typename V::value_type> T max(V &a, ll s = -1, ll n = -1) { set_lr12(s, n,sz(a)); return *max_element(a.begin() + s, a.begin() + min(n, sz(a))); }
template<class T> int mini(const vector<T> &a) { return min_element(ALL(a)) - a.begin(); }
template<class T> int maxi(const vector<T> &a) { return max_element(ALL(a)) - a.begin(); }
template<class T> T sum(const vector<T> &A, int l = -1, int r = -1) { T s = 0; set_lr12(l, r, sz(A)); rep(i, l, r)s += A[i]; return s;}
template<class T> auto sum(const vector<vector<T>> &A) { decl2<decltype(A)> s = 0; rep(i, sz(A))s += sum(A[i]); return s;}
template<class T> T min(const vector<T>& A, int l = -1, int r = -1 ){T s=MAX<T>();set_lr12(l, r, sz(A));rep(i, l, r)s=min(s, A[i]);return s;}
template<class T> auto min(const vector<vector<T>>& A ){using S =decl2<decltype(A)>; S s=MAX<S>();rep(i, sz(A))s=min(s, A[i]);return s;}
template<class T> T max(const vector<T>& A, int l = -1, int r = -1 ){T s=MIN<T>();set_lr12(l, r, sz(A));rep(i, l, r); rep(i, l, r)s=max(s, A[i]);return s;}
template<class T> auto max(const vector<vector<T>>& A ){using S =decl2<decltype(A)>;S s=MIN<S>();rep(i, sz(A))s=max(s, A[i]);return s;}
template<class T> T mul(vector<T> &v, ll t = inf) { T ret = v[0]; rep(i, 1, min(t, sz(v)))ret *= v[i]; return ret;}
//template<class T, class U, class... W> auto sumn(vector<T> &v, U head, W... tail) { auto ret = sum(v[0], tail...); rep(i, 1, min(sz(v), head))ret += sum(v[i], tail...); return ret;}
//indexを持つvectorを返す
vi inds_(vi &a) { int n = max(a) + 1; vi ret(n, -1); rep(i, sz(a)) { assert(ret[a[i]] ==-1);ret[a[i]] = i; } return ret;}
void clear(PQ &q) { q = PQ(); }
void clear(priority_queue<int> &q) { q = priority_queue<int>(); }
template<class T> void clear(queue<T> &q) { while (q.size())q.pop(); }
//template<class T> T *negarr(ll size) { T *body = (T *) malloc((size * 2 + 1) * sizeof(T)); return body + size;}
//template<class T> T *negarr2(ll h, ll w) { double **dummy1 = new double *[2 * h + 1]; double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)]; dummy1[0] = dummy2 + w; for (ll i = 1; i <= 2 * h + 1; ++i) { dummy1[i] = dummy1[i - 1] + 2 * w + 1; } double **a = dummy1 + h; return a;}
template<class T> struct ruiC {
vector<T> rui;
ruiC(vector<T> &ru) : rui(ru) {}
/*先頭0*/
ruiC() : rui(1, 0) {}
T operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } return rui[r] - rui[l]; }
T operator()(int r = inf) { return operator()(0, min(r, sz(rui) - 1)); }
/*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/
/*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/
// T operator[](ll i) { return rui[i + 1] - rui[i]; }
T operator[](ll i) { return rui[i]; }
/*0から順に追加される必要がある*/
void operator+=(T v) { rui.push_back(rui.back() + v); }
void add(int i, T v) {if (sz(rui) - 1 != i)ole();operator+=(v);}
T back() { return rui.back(); }
ll size() { return rui.size(); }
auto begin() { return rui.begin(); }
auto end() { return rui.end(); }
};
template<class T> string deb_tos(const ruiC<T> &a) {return deb_tos(a.rui);}
template<class T> ostream &operator<<(ostream &os, ruiC<T> a) { fora(v, a.rui){os << v << " "; } return os;}
template<class T> vector<T> ruiv(const vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i]; return ret;}
template<class T> ruiC<T> ruic(const vector<T> &a) { vector<T> ret = ruiv(a); return ruiC<T>(ret);}
template<class T> ruiC<T> ruic() { return ruiC<T>(); }
//imoは0-indexed
//ruiは1-indexed
template<class T> vector<T> imo(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret;}
//#define use_rui //_imo _ruic _ruiv
#ifdef use_rui
//kと同じものの数
template<class T, class U> vi imo(const vector<T> &a, U k) { vi equ(sz(a)); rep(i, sz(a)){ equ[i] = a[i]==k; } return imo(equ);}
template<class T> vector<T> imox(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] ^= ret[i]; return ret;}
//漸化的に最小を持つ
template<class T> vector<T> imi(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chmi(ret[i + 1], ret[i]); return ret;}
template<class T> vector<T> ima(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chma(ret[i + 1], ret[i]); return ret;}
template<class T> vector<T> rimi(const vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chmi(ret[i - 1], ret[i]); return ret;}
template<class T> vector<T> rima(const vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chma(ret[i - 1], ret[i]); return ret;}
template<class T> struct ruimax {
template<typename Monoid> struct SegmentTree { /*pairで処理*/ int sz; vector<Monoid> seg; const Monoid M1 = mp(MIN<T>(), -1); Monoid f(Monoid a, Monoid b) { return max(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } };
private:
vector<T> ve;
SegmentTree<pair<T, int>> seg;
vector<T> rv;
vector<int> ri;
bool build = false;
public:
int n;
ruimax(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; T ma = MIN<T>(); rv.resize(n + 1); ri.resize(n + 1); rv[0] = -INF<T>; ri[0] = -1; rep(i, n) { if (chma(ma, a[i])) { index = i; } rv[i + 1] = ma; ri[i + 1] = index; } }
T operator()(int l, int r) { if (!(l <= r && 0 <= l && r <= n)) { deb(l, r, n); assert(0); } if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } }
T operator()(int r = inf) { return operator()(0, min(r, n)); }
T operator[](int r) { return operator()(0, r); }
T getv(int l, int r) { return operator()(l, r); }
T getv(int r = inf) { return getv(0, min(r, n)); };
int geti(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } }
int geti(int r = inf) { return geti(0, min(r, n)); };
auto begin() { return rv.begin(); }
auto end() { return rv.end(); }
};
template<class T> struct ruimin {
template<typename Monoid> struct SegmentTree { /*pairで処理*/ int sz;vector<Monoid> seg; const Monoid M1 = mp(MAX<T>(), -1); Monoid f(Monoid a, Monoid b) { return min(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } };
private:
vector<T> ve;
SegmentTree<pair<T, int>> seg;
vector<T> rv;
vector<int> ri;
bool build = false;
int n;
public:
ruimin(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; T mi = MAX<T>(); rv.resize(n + 1); ri.resize(n + 1); rv[0] = INF<T>; ri[0] = -1; rep(i, n) { if (chmi(mi, a[i])) { index = i; } rv[i + 1] = mi; ri[i + 1] = index; } }
T operator()(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } }
T operator()(int r = inf) { return operator()(0, min(r, n)); }
T operator[](int r) { return operator()(0, r); }
T getv(int l, int r) { return operator()(l, r); }
T getv(int r = inf) { return getv(0, min(r, n)); };
int geti(int l, int r) { { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } } assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } }
int geti(int r = inf) { return geti(0, min(r, n)); };
auto begin() { return rv.begin(); }
auto end() { return rv.end(); }
};/*@formatter:off*/
vvi() ruib(vi &a) { vvi(res, 61, sz(a) + 1); rep(k, 61) { rep(i, sz(a)) { res[k][i + 1] = res[k][i] + ((a[i] >> k) & 1); }} return res;}
vector<ruiC<int>> ruibc(vi &a) {vector<ruiC<int>> ret(61); vvi(res, 61, sz(a)); rep(k, 61) { rep(i, sz(a)) { res[k][i] = (a[i] >> k) & 1; } ret[k] = ruic(res[k]); } return ret;}
//kと同じものの数
template<class T, class U> vi ruiv(T &a, U k) { vi ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + (a[i] == k); return ret;}
template<class T, class U> ruiC<ll> ruic(T &a, U k) { vi ret = ruiv(a, k); return ruiC<ll>(ret);}
template<class T> struct ruiC2 {
int H;
vector<ruiC<T>> rui;
ruiC<T> dummy;//変なのをよばれたときはこれを返す//todo
ruiC2(const vector<vector<T>> &ru) : rui(sz(ru)), H(sz(ru)) { for (int h = 0; h < H; h++) { if (sz(ru[h]) == 0)continue; if (sz(dummy) == 1) dummy = ruic(vector<T>(sz(ru[h]))); rui[h] = ruic(ru[h]); } }
//WについてHを返す
vector<T> operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } vector<T> res(H); for (int h = 0; h < H; h++)res[h] = rui[h](l, r); return res; }
//HについてWを返す
ruiC<T> &operator[](ll h) {
#ifdef _DEBUG
if (h >= H) {message += "warning ruiC h >= H";}
#endif
if (h >= H || sz(rui[h]) == 1)return dummy;else return rui[h];
}
/*@formatter:off*/
// vector<T> operator()(int r) { return operator()(0, r); }
/*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/
/*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/
// T operator[](ll i) { return rui[i + 1] - rui[i]; }
/*0から順に追加される必要がある*/
// T back() { return rui.back(); }
// ll size() { return rui.size(); }
// auto begin(){return rui.begin();}
// auto end(){return rui.end();}
};
template<class T, class U> ruiC<ll> ruicou(vector<T> &a, U b) { vi cou(sz(a)); rep(i, sz(a)) { cou[i] = a[i] == b; } return ruic(cou);}
//メモリは形式によらず(26*N)
// rui(l,r)でvector(26文字について, l~rのcの個数)
// rui[h] ruic()を返す
// 添え字は'a', 'A'のまま扱う (予め-='a','A'されているものが渡されたらそれに従う)
template<typename Iterable, class is_Iterable = typename Iterable::value_type>
ruiC2<ll> ruicou(const Iterable &a) { int H = max(a) + 1; vvi(cou, H); rep(i, sz(a)) { if (sz(cou[a[i]]) == 0)cou[a[i]].resize(sz(a)); cou[a[i]][i] = 1; } return ruiC2<ll>(cou); }
/*@formatter:off*/
//h query
template<class T> vector<T> imoh(vector<vector<T>> &v, int w) { vector<T> ret(sz(v)); rep(h, sz(ret)) { ret[h] = v[h][w]; } rep(i, sz(ret) - 1) { ret[i + 1] += ret[i]; } return ret;}
template<class T> vector<T> ruih(vector<vector<T>> &v, int w) { vector<T> ret(sz(v) + 1); rep(h, sz(v)) { ret[h + 1] = v[h][w]; } rep(i, sz(v)) { ret[i + 1] += ret[i]; } return ret;}
template<class T> ruiC<T> ruihc(vector<vector<T>> &a, int w) { vector<T> ret = ruih(a, w); return ruiC<T>(ret);}
//xor
template<class T> struct ruixC {
vector<T> rui;
ruixC(vector<T> &ru) : rui(ru) {}
T operator()(ll l, ll r) { if (l > r) { cerr << "ruiXc "; deb(l, r); assert(0); } return rui[r] ^ rui[l]; }
T operator[](ll i) { return rui[i]; }
T back() { return rui.back(); }
ll size() { return rui.size(); }
};
template<class T> vector<T> ruix(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] ^ a[i]; return ret;}
template<class T> ruixC<ll> ruixc(vector<T> &a) { vi ret = ruix(a); return ruixC<ll>(ret);}
//差分を返す(累積を取ると元に戻る)
//101なら
//1111を返す
//元の配列で[l, r)へのxorは
//[l]と[r]へのxorになる https://atcoder.jp/contests/abc155/tasks/abc155_f
vi ruix_diff(vi &A) { int N = sz(A); assert(N); vi res(N + 1); res[0] = A[0]; rep(i, 1, N) { res[i] = A[i - 1] ^ A[i]; } res[N] = A[N - 1]; return res;}
template<class T> vector<T> ruim(vector<T> &a) { vector<T> res(a.size() + 1, 1); rep(i, a.size())res[i + 1] = res[i] * a[i]; return res;}
//漸化的に最小を1indexで持つ
template<class T> vector<T> ruimi(vector<T> &a) {ll n = sz(a); vector<T> ret(n + 1); rep(i, 1, n) { ret[i] = a[i - 1]; chmi(ret[i + 1], ret[i]); } return ret;}
//template<class T> T *rrui(vector<T> &a) {
//右から左にかけての半開区間 (-1 n-1]
template<class T> struct rruiC {
vector<T> rui;
int n;
rruiC(vector<T> &a) : n(sz(a)) { rui.resize(n + 1); rer(i, n - 1) { rui[i] = rui[i + 1] + a[i]; } }
/*[r l)*/
T operator()(int r, int l) { r++; l++; assert(l <= r && l >= 0 && r <= n); return rui[l] - rui[r]; }
T operator()(int l) { return operator()(n - 1, l); }
T operator[](int i) { return operator()(i); }
};
template<class T> ostream &operator<<(ostream &os, rruiC<T> a) { fora(v, a.rui){os << v << " "; } return os;}
template<class T> string deb_tos(rruiC<T> &a) {return deb_tos(a.rui);}
#define rrui rruic
template<class T> rruiC<T> rruic(vector<T> &a) { return rruiC<T>(a); }
//掛け算
template<class T> struct ruimulC {
vector<T> rv;
int n;
ruimulC(vector<T> &a) : rv(a), n(sz(a)) { rv.resize(n + 1); rv[0] = 1; rep(i, n) { rv[i + 1] = a[i] * rv[i]; } }
ruimulC() : n(0) { rv.resize(n + 1); rv[0] = 1; }
void operator+=(T v) { rv.push_back(rv.back() * v); n++; }
T operator()(int l, int r) { assert(l <= r && 0 <= l && r <= n); return rv[r] / rv[l]; }
T operator()(int r = inf) { return operator()(0, min(r, n)); }
T operator[](int r) { return operator()(0, r); }
auto begin() { return rv.begin(); }
auto end() { return rv.end(); }
};
template<class T> ruimulC<T> ruimul(vector<T> &a) { return ruimulC<T>(a); }
template<class T> ruimulC<T> ruimul() { vector<T> a; return ruimulC<T>(a);}
template<class T> T *rruim(vector<T> &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; res[len - 1] = 1; rer(i, len - 1)res[i - 1] = res[i] * a[i]; return res;}
template<class T, class U, class W> T lowerBound(ruiC <T> &a, U v, W banpei) { return lowerBound(a.rui, v, banpei); }
template<class T, class U, class W> T upperBound(ruiC <T> &a, U v, W banpei) { return upperBound(a.rui, v, banpei); }
template<class T, class U, class W> T rlowerBound(ruiC <T> &a, U v, W banpei) { return rlowerBound(a.rui, v, banpei); }
template<class T, class U, class W> T rupperBound(ruiC <T> &a, U v, W banpei) { return rupperBound(a.rui, v, banpei); }
#endif
constexpr bool bget(ll m, ll keta) {
#ifdef _DEBUG
assert(keta <= 62);//オーバーフロー 1^62までしか扱えない
#endif
return (m >> keta) & 1;
}
//bget(n)次元
// NならN-1まで
vector<vi> bget2(vi &a, int keta_size) { vvi(res, keta_size, sz(a)); rep(k, keta_size) { rep(i, sz(a)) { res[k][i] = bget(a[i], k); }} return res;}
vi bget1(vi &a, int keta) { vi res(sz(a)); rep(i, sz(a)) { res[i] = bget(a[i], keta); } return res;}
#if __cplusplus >= 201703L
ll bget(ll m, ll keta, ll sinsuu) { m /= pow<ll>(sinsuu, keta); return m % sinsuu;}
#else
ll bget(ll m, ll keta, ll sinsuu) { m /= (ll)pow(sinsuu, keta); return m % sinsuu;}
#endif
constexpr ll bit(ll n) {
#ifdef _DEBUG
assert(n <= 62);//オーバーフロー 1^62までしか扱えない
#endif
return (1LL << (n));
}
#if __cplusplus >= 201703L
ll bit(ll n, ll sinsuu) { return pow<ll>(sinsuu, n); }
#else
ll bit(ll n, ll sinsuu) { return (ll)pow(sinsuu, n); }
#endif
ll mask(ll n) { return (1ll << n) - 1; }
//aをbitに置きなおす
//{0, 2} -> 101
ll bit(const vi &a) { int m = 0; for (auto &&v:a) m |= bit(v); return m;}
//{1, 1, 0} -> 011
//bitsetに置き換える感覚 i が立っていたら i bit目を立てる
ll bit_bool(vi &a) { int m = 0; rep(i, sz(a)) if (a[i])m |= bit(i); return m;}
#define bcou __builtin_popcountll
//最下位ビット
ll lbit(ll n) { assert(n);return n & -n; }
ll lbiti(ll n) { assert(n);return log2(n & -n); }
//最上位ビット
ll hbit(ll n) { assert(n);n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); n |= (n >> 32); return n - (n >> 1);}
ll hbiti(ll n) { assert(n);return log2(hbit(n)); }
//ll hbitk(ll n) { ll k = 0; rer(i, 5) { ll a = k + (1ll << i); ll b = 1ll << a; if (b <= n)k += 1ll << i; } return k;}
//初期化は0を渡す
ll nextComb(ll &mask, ll n, ll r) { if (!mask)return mask = (1LL << r) - 1; ll x = mask & -mask; /*最下位の1*/ ll y = mask + x; /*連続した下の1を繰り上がらせる*/ ll res = ((mask & ~y) / x >> 1) | y; if (bget(res, n))return mask = 0; else return mask = res;}
//n桁以下でビットがr個立っているもののvectorを返す
vi bitCombList(ll n, ll r) { vi res; ll m = 0; while (nextComb(m, n, r)) { res.push_back(m); } return res;}
/*over*/#define forbit1_2(i, mas) for (int forbitj = !mas ? 0 : lbit(mas), forbitm = mas, i = !mas ? 0 :log2(forbitj); forbitm; forbitm = forbitm ^ forbitj, forbitj = !forbitm ? 1 : lbit(forbitm), i = log2(forbitj))
/*over*/#define forbit1_3(i, N, mas) for (int forbitj = !mas ? 0 : lbit(mas), forbitm = mas, i = !mas ? 0 :log2(forbitj); forbitm && i < N; forbitm = forbitm ^ forbitj, forbitj = !forbitm ? 1 : lbit(forbitm), i = log2(forbitj))
//masの立ってるindexを見る
// i, [N], mas
#define forbit1(...) over3(__VA_ARGS__, forbit1_3, forbit1_2)(__VA_ARGS__)
//masが立っていないindexを見る
// i, N, mas
#define forbit0(i, N, mas) forbit1(i, mask(N) & (~(mas)))
//forsubをスニペットして使う
//Mの部分集合(0,M含む)を見る 3^sz(S)個ある
#define forsub_all(m, M) for (int m = M; m != -1; m = m == 0 ? -1 : (m - 1) & M)
//BASE進数
template<size_t BASE> class base_num {
int v;
public:
base_num(int v = 0) : v(v) {};
int operator[](int i) { return bget(v, i, BASE); }
void operator++() { v++; }
void operator++(signed) { v++; }
operator int() { return v; }
};
#define base3(mas, lim, BASE) for (base_num<BASE> mas; mas < lim; mas++)
#define base2(mas, lim) base3(mas, lim, 2)
#define base(...) over3(__VA_ARGS__,base3,base2,base1)(__VA_ARGS__)
//aにある物をtrueとする
vb bool_(vi a, int n) { vb ret(max(max(a) + 1, n)); rep(i, sz(a))ret[a[i]] = true; return ret;}
char itoal(ll i) { return 'a' + i; }
char itoaL(ll i) { return 'A' + i; }
ll altoi(char c) { if ('A' <= c && c <= 'Z')return c - 'A'; return c - 'a';}
ll ctoi(char c) { return c - '0'; }
char itoc(ll i) { return i + '0'; }
ll vtoi(vi &v) { ll res = 0; if (sz(v) > 18) { debugline("vtoi"); deb(sz(v)); ole(); } rep(i, sz(v)) { res *= 10; res += v[i]; } return res;}
vi itov(ll i) { vi res; while (i) { res.push_back(i % 10); i /= 10; } res = rev(res); return res;}
vi stov(string &a) { ll n = sz(a); vi ret(n); rep(i, n) { ret[i] = a[i] - '0'; } return ret;}
//基準を満たさないものは0になる
vi stov(string &a, char one) { ll n = sz(a); vi ret(n); rep(i, n)ret[i] = a[i] == one; return ret;}
vector<vector<ll>> ctoi(vector<vector<char>> s, char c) { ll n = sz(s), m = sz(s[0]); vector<vector<ll>> res(n, vector<ll>(m)); rep(i, n)rep(j, m)res[i][j] = s[i][j] == c; return res;}
//#define use_compress
//[i] := vを返す
//aは0~n-1で置き換えられる
vi compress(vi &a) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(ALL(b), a[i]) - b.begin(); } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
#ifdef use_compress
//ind[i] := i番目に小さい数
//map[v] := vは何番目に小さいか
vi compress(vi &a, umapi &map) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { ll v = a[i]; a[i] = lower_bound(ALL(b), a[i]) - b.begin(); map[v] = a[i]; } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vi &a, vi &r) { vi b; ll len = a.size(); fora(v, a){b.push_back(v);} fora(v, r){b.push_back(v);} sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(ALL(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(ALL(b), r[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vi &a, vi &r, vi &s) { vi b; ll len = a.size(); fora(v, a){b.push_back(v);} fora(v, r){b.push_back(v);} fora(v, s){b.push_back(v); } sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(ALL(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(ALL(b), r[i]) - b.begin(); for (ll i = 0; i < sz(s); ++i) r[i] = lower_bound(ALL(b), s[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vector<vi> &a) { vi b; fora(vv, a){fora(v, vv){b.push_back(v);}} sort(b); unique(b); fora(vv, a){fora(v, vv){v = lower_bound(ALL(b), v) - b.begin(); }} ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vector<vector<vi >> &a) { vi b; fora(vvv, a){fora(vv, vvv){fora(v, vv){b.push_back(v);}}} sort(b); unique(b); fora(vvv, a){fora(vv, vvv){fora(v, vv){v = lower_bound(ALL(b), v) - b.begin();}}} ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
void compress(ll a[], ll len) { vi b; for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(ALL(b), a[i]) - b.begin(); }}
#endif
//要素が見つからなかったときに困る
#define binarySearch(a, v) (binary_search(ALL(a),v))
#define lowerIndex(a, v) (lower_bound(ALL(a),v)-a.begin())
#define upperIndex(a, v) (upper_bound(ALL(a),v)-a.begin())
#define rlowerIndex(a, v) (upper_bound(ALL(a),v)-a.begin()-1)
#define rupperIndex(a, v) (lower_bound(ALL(a),v)-a.begin()-1)
template<class T, class U, class W> T lowerBound(vector<T> &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T upperBound(vector<T> &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T rlowerBound(vector<T> &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T rupperBound(vector<T> &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else { return *(--it); }}
//todo 消せないか
template<class T, class U, class W> T lowerBound(set<T> &a, U v, W banpei) { auto it = a.lower_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T upperBound(set<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T rlowerBound(set<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T rupperBound(set<T> &a, U v, W banpei) {auto it = a.lower_bound(v);if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T lowerBound(mset<T> &a, U v, W banpei) { auto it = a.lower_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T upperBound(mset<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T rlowerBound(mset<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T rupperBound(mset<T> &a, U v, W banpei) {auto it = a.lower_bound(v);if (it == a.begin())return banpei; else { return *(--it); }}
#define next2(a) next(next(a))
#define prev2(a) prev(prev(a))
//狭義の単調増加列 長さを返す
template<class T> int lis(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX<T>()); rep(i, n) { int id = lowerIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX<T>());}
template<class T> int lis_eq(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX<T>()); rep(i, n) { int id = upperIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX<T>());}
//iteratorを返す
//valueが1以上の物を返す 0は見つけ次第削除
//vを減らす場合 (*it).se--でいい
template<class T, class U, class V> auto lower_map(map<T, U> &m, V k) { auto ret = m.lower_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;}
template<class T, class U, class V> auto upper_map(map<T, U> &m, V k) { auto ret = m.upper_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;}
//存在しなければエラー
template<class T, class U, class V> auto rlower_map(map<T, U> &m, V k) { auto ret = upper_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;}
template<class T, class U, class V> auto rupper_map(map<T, U> &m, V k) { auto ret = lower_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;}
template<class... T> void fin(T... s) {out(s...); exit(0); }
//便利 数学 math
//sub ⊂ top
bool subset(int sub, int top) {return (sub & top) == sub;}
//-180 ~ 180 degree
double atand(double h, double w) {return atan2(h, w) / PI * 180;}
//% -mの場合、最小の正の数を返す
ll mod(ll a, ll m) {if (m < 0) m *= -1;return (a % m + m) % m;}
//ll pow(ll a) { return a * a; };
template<class T> T fact(int v) { static vector<T> fact(2, 1); if (sz(fact) <= v) { rep(i, sz(fact), v + 1) { fact.emplace_back(fact.back() * i); }} return fact[v];}
ll comi(ll n, ll r) { assert(n < 100); static vvi(pas, 100, 100); if (pas[0][0])return pas[n][r]; pas[0][0] = 1; rep(i, 1, 100) { pas[i][0] = 1; rep(j, 1, i + 1)pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j]; } return pas[n][r];}
//二項係数の偶奇を返す
int com_mod2(int n,int r){return n == ( r | (n - r) );}
double comd2(ll n, ll r) { static vvd(comb, 2020, 2020); if (comb[0][0] == 0) { comb[0][0] = 1; rep(i, 2000) { comb[i + 1][0] = 1; rep(j, 1, i + 2) { comb[i + 1][j] = comb[i][j] + comb[i][j - 1]; } } } return comb[n][r];}
double comd(int n, int r) { if (r < 0 || r > n) return 0; if (n < 2020)return comd2(n, r); static vd fact(2, 1); if (sz(fact) <= n) { rep(i, sz(fact), n + 1) { fact.push_back(fact.back() * i); }} return fact[n] / fact[n - r] / fact[r];}
#define gcd my_gcd
ll gcd(ll a, ll b) {while (b) a %= b, swap(a, b);return abs(a);}
ll gcd(vi b) {ll res = b[0];rep(i, 1, sz(b))res = gcd(b[i], res);return res;}
#define lcm my_lcm
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll lcm(vi a) {ll res = a[0];rep(i, 1, sz(a))res = lcm(a[i], res);return res;}
ll ceil(ll a, ll b) {if (b == 0) {debugline("ceil");deb(a, b);ole();return -1;} else if (a < 0) { return 0; } else { return (a + b - 1) / b; }}
#define hypot my_hypot
double hypot(double dx, double dy){return std::sqrt(dx*dx+ dy*dy);}
ll sig0(int t) { return t <= 0 ? 0 : ((1 + t) * t) >> 1; }
bint sig0(bint t) {return t <= 0 ? 0 : ((1 + t) * t) >> 1; }
//ll sig(ll s, ll t) { return ((s + t) * (t - s + 1)) >> 1; }
ll sig(ll s, ll t) {if (s > t)swap(s, t);return sig0(t - s) + s * (t - s + 1);}
#define tousa_i tosa_i
#define lower_tousa_i lower_tosa_i
#define upper_tousa upper_tosa
#define upper_tousa_i upper_tosa_i
ll tosa_i(ll st, ll ad, ll v) { assert(((v - st) % ad) == 0); return (v - st) / ad;}
ll tosa_s(ll st, ll ad, ll len) { return st * len + sig0(len - 1) * ad;}
// ax + r (x は非負整数) で表せる整数のうち、v 以上となる最小の整数
ll lower_tosa(ll st, ll ad, ll v) { if (st >= v) return st; return (v - st + ad - 1) / ad * ad + st;}
//第何項か
ll lower_tosa_i(ll st, ll ad, ll v) { if (st >= v) return 0; return (v - st + ad - 1) / ad;}
ll upper_tosa(ll st, ll ad, ll v) { return lower_tosa(st, ad, v + 1); }
ll upper_tosa_i(ll st, ll ad, ll v) { return lower_tosa_i(st, ad, v + 1); }
//b * res <= aを満たす [l, r)を返す div
P drange_ika(int a, int b) { P null_p = mp(linf, linf); if (b == 0) { if (a >= 0) { return mp(-linf, linf + 1)/*全て*/; } else { return null_p/*無い*/; } } else { if (a >= 0) { if (b > 0) { return mp(-linf, a / b + 1); } else { return mp(-(a / -b), linf + 1); } } else { if (b > 0) { return mp(-linf, -ceil(-a, b) + 1); } else { return mp(ceil(-a, -b), linf + 1); } } }}
//v * v >= aとなる最小のvを返す
ll sqrt(ll a) { if (a < 0) { debugline("sqrt"); deb(a); ole(); } ll res = (ll) std::sqrt(a); while (res * res < a)++res; return res;}
double log(double e, double x) { return log(x) / log(e); }
/*@formatter:off*/
//機能拡張
#define dtie(a, b) int a, b; tie(a, b)
template<class T, class U> string to_string(T a, U b) { string res = ""; res += a; res += b; return res;}
template<class T, class U, class V> string to_string(T a, U b, V c) { string res = ""; res += a; res += b; res += c; return res;}
template<class T, class U, class V, class W> string to_string(T a, U b, V c, W d) { string res = ""; res += a; res += b; res += c; res += d; return res;}
template<class T, class U, class V, class W, class X> string to_string(T a, U b, V c, W d, X e) { string res = ""; res += a; res += b; res += c; res += d; res += e; return res;}
//todo stringもセットで
template<class T> vector<T> sub(const vector<T> &A, int l, int r) { assert(0 <= l && l <= r && r <= sz(A)); vector<T> ret(r - l); std::copy(A.begin() + l, A.begin() + r, ret.begin()); return ret;}
template<class T> vector<T> sub(const vector<T> &A, int r) { return sub(A, 0, r); }
template<class T> vector<T> subn(const vector<T> &A, int l, int len) { return sub(A, l, l + len); }
string sub(string &A, int l, int r) { assert(0 <= l && l <= r && r <= sz(A)); return A.substr(l, r - l);}
template<class T, class F>
//sub2で呼ぶ
vector<T> sub(const vector<vector<T> >& A, int h, int w, int ah,int aw, F f){ vector<T> res; while(0<= h && h < sz(A) && 0 <= w && w < sz(A[h]) && f(A[h][w])){ res.emplace_back(A[h][w]); h += ah; w += aw; } return res;}
template<class T> vector<T>sub(const vector<vector<T> >& A, int h, int w, int ah,int aw){return sub(A, h, w, ah, aw, [&](T v){return true;});}
#define sub25(A, h, w, ah, aw) sub(A, h, w, ah, aw)
#define sub26(A, h, w, ah, aw, siki_r) sub(A, h, w, ah, aw, [&](auto v){return v siki_r;})
#define sub27(A, h, w, ah, aw, v, siki) sub(A, h, w, ah, aw, [&](auto v){return siki;})
#define sub2(...) over7(__VA_ARGS__,sub27,sub26,sub25)(__VA_ARGS__)
constexpr int bsetlen = k5 * 2;
//constexpr int bsetlen = 5050;
#define bset bitset<bsetlen>
bool operator<(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return false;}
bool operator>(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return false;}
bool operator<=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return true;}
bool operator>=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return true;}
string operator~(string &a) {string res = a;for (auto &&c:res) {if (c == '0')c = '1';else if (c == '1')c = '0';else {cerr << "cant ~" << a << "must bit" << endl;exit(0);}}return res;}
ostream &operator<<(ostream &os, bset& a) { bitset<10> b; vi list; rep(i,bsetlen){ if(a[i])list.push_back(i),b[i]=1; } os<<b<<", "<<list; return os;}
int hbiti(bset&a){rer(i,bsetlen){if(a[i])return i;}return -1;}
#define hk(a, b, c) (a <= b && b < c)
//O(N/64)
bset nap(bset &a, int v) {bset r = a | a << v;return r;}
bset nap(bset &a, bset &v) {bset r = a;rep(i, bsetlen) {if (v[i])r |= a << i;}return r;}
template<class T> int count(set<T> &S, T l, T r) { assert(l < r); auto it = S.lower_bound(l); return it != S.end() && (*it) < r;}
//template<class T> void seth(vector<vector<T>> &S, int w, vector<T> &v) {assert(sz(S) == sz(v));assert(w < sz(S[0]));rep(h, sz(S)) { S[h][w] = v[h]; }}
template<class T> vector<T> geth(vector<vector<T>> &S, int w) { assert(w < sz(S[0])); vector<T> ret(sz(S)); rep(h, sz(S)) { ret[h] = S[h][w]; } return ret;}
//vector<bool>[i]は参照を返さないため、こうしないとvb[i] |= trueがコンパイルエラー
vb::reference operator|=(vb::reference a, bool b){return a = a | b;}
vb::reference operator&=(vb::reference a, bool b){return a = a & b;}
template<class T, class U> void operator+=(pair<T,U> &a, pair<T,U> & b) {a.fi+=b.fi;a.se+=b.se;}
template<class T, class U> pair<T, U> operator+(const pair<T, U> &a, const pair<T, U> &b) { return pair<T, U>(a.fi + b.fi, a.se + b.se); }
template<class T, class U> pair<T,U> operator-(const pair<T,U> &a, const pair<T,U> & b) {return pair<T,U>(a.fi-b.fi,a.se-b.se);}
template<class T, class U> pair<T,U> operator-(const pair<T, U>& a){return pair<T, U>(-a.first, -a.second);}
template<typename CharT, typename Traits, typename Alloc> basic_string<CharT, Traits, Alloc> operator+(const basic_string<CharT, Traits, Alloc> &lhs, const int rv) {
#ifdef _DEBUG
static bool was = false;if (!was)message += "str += 65 is 'A' not \"65\" ";was = true;
#endif
return lhs + (char) rv;
}
template<typename CharT, typename Traits, typename Alloc> void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const int rv) { lhs = lhs + rv;}
template<typename CharT, typename Traits, typename Alloc> basic_string<CharT, Traits, Alloc> operator+(const basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { const int rv2 = rv; return lhs + rv2;}
template<typename CharT, typename Traits, typename Alloc> void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const signed rv) {const int v = rv; lhs += v; }
template<typename CharT, typename Traits, typename Alloc> void operator*=(basic_string<CharT, Traits, Alloc> &s, int num) { auto bek = s; s = ""; for (; num; num >>= 1) { if (num & 1) { s += bek; } bek += bek; }}
template<class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }template<class T, class U> void operator+=(deque<T> &a, U v) { a.push_back(v); }template<class T> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, vector<T> &v) { fora(d, v){a.push(d);} return a;}template<class T, class U> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, U v) { a.push(v); return a;}template<class T, class U> priority_queue<T> &operator+=(priority_queue<T> &a, U v) { a.push(v); return a;}template<class T> set<T> &operator+=(set<T> &a, vector<T> v) { fora(d, v){a.insert(d);} return a;}template<class T, class U> auto operator+=(set<T> &a, U v) { return a.insert(v); }template<class T, class U> auto operator-=(set<T> &a, U v) { return a.erase(v); }template<class T, class U> auto operator+=(mset<T> &a, U v) { return a.insert(v); }template<class T, class U> set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) { a.insert(v); return a;}template<class T, class U> vector<T> &operator+=(vector<T> &a, U v) { a.push_back(v); return a;}template<class T, class U> vector<T> operator+(U v,const vector<T> &a) { vector<T> ret = a; ret.insert(ret.begin(), v); return ret;}template<class T> vector<T> operator+(const vector<T>& a, const vector<T>& b) { vector<T> ret; ret = a; fora(v, b){ret += v; } return ret;}template<class T> vector<T> &operator+=(vector<T> &a,const vector<T> &b) { rep(i, sz(b)) {/*こうしないとa+=aで両辺が増え続けてバグる*/ a.push_back(b[i]); } return a;}template<class T, class U> map<T, U> &operator+=(map<T, U> &a, map<T, U> &b) { for(auto&& bv : b) { a[bv.first] += bv.second; } return a;}template<class T, class U> vector<T> operator+(const vector<T> &a, const U& v) { vector<T> ret = a; ret += v; return ret;}template<class T, class U> auto operator+=(uset<T> &a, U v) { return a.insert(v); }
template<class T> vector<T> operator%(vector<T>& a, int v){ vi ret(sz(a)); rep(i,sz(a)){ ret[i] = a[i] % v; } return ret;}
template<class T> vector<T> operator%=(vector<T>& a, int v){ rep(i,sz(a)){ a[i] %= v; } return a;}
vi operator&(vi& a, vi& b){ assert(sz(a)==sz(b)); vi ret(sz(a)); rep(i,sz(a)){ ret[i] = min(a[i],b[i]); } return ret;}
template<class T> void operator+=(mset<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); }
template<class T> void operator+=(set<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); }
template<class T> void operator+=(vector<T> &a, set<T>& v) { for(auto&& u : v)a.emplace_back(u); }
template<class T> void operator+=(vector<T> &a, mset<T>& v) { for(auto&& u : v)a.emplace_back(u); }
template<class T> vector<T> &operator-=(vector<T> &a, vector <T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-="); deb(a); deb(b); exit(0); } rep(i, sz(a))a[i] -= b[i]; return a;}
template<class T> vector<T> operator-(vector<T> &a, vector<T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-"); deb(a); deb(b); ole(); } vector<T> res(sz(a)); rep(i, sz(a))res[i] = a[i] - b[i]; return res;}
//template<class T, class U> void operator*=(vector<T> &a, U b) { vector<T> ta = a; rep(b-1){ a+=ta; }}
template<typename T> void erase(vector<T> &v, unsigned ll i) { v.erase(v.begin() + i); }
template<typename T> void erase(vector<T> &v, unsigned ll s, unsigned ll e) { v.erase(v.begin() + s, v.begin() + e); }
template<typename T> void pop_front(vector<T> &v) { erase(v, 0); }
template<typename T> void entry(vector<T> &v, unsigned ll s, unsigned ll e) { erase(v, e, sz(v));erase(v,0,s);}
template<class T, class U> void erase(map<T, U> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); }
template<class T> void erase(set<T> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); }
template<typename T> void erasen(vector<T> &v, unsigned ll s, unsigned ll n) { v.erase(v.begin() + s, v.begin() + s + n); }
template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, U t) { v.insert(v.begin() + i, t); }
template<typename T, typename U> void push_front(vector<T> &v, U t) { v.insert(v.begin(), t); }
template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, vector<T> list) { for (auto &&va:list)v.insert(v.begin() + i++, va); }
vector<string> split(const string &a, const char deli) { string b = a + deli; ll l = 0, r = 0, n = b.size(); vector<string> res; rep(i, n) { if (b[i] == deli) { r = i; if (l < r)res.push_back(b.substr(l, r - l)); l = i + 1; } } return res;}
vector<string> split(const string &a, const string deli) { vector<string> res; ll kn = sz(deli); std::string::size_type Pos(a.find(deli)); ll l = 0; while (Pos != std::string::npos) { if (Pos - l)res.push_back(a.substr(l, Pos - l)); l = Pos + kn; Pos = a.find(deli, Pos + kn); } if (sz(a) - l)res.push_back(a.substr(l, sz(a) - l)); return res;}
ll stoi(string& s){return stol(s);}
#define assert_yn(yn_v, v); assert(yn_v == 0 || yn_v == v);yn_v = v;
//不完全な対策、現状はautohotkeyで対応
int yn_v = 0;
void yn(bool a) { assert_yn(yn_v, 1);if (a)cout << "yes" << endl; else cout << "no" << endl; }
void fyn(bool a) { assert_yn(yn_v, 1);yn(a); exit(0);}
void Yn(bool a) { assert_yn(yn_v, 2);if (a)cout << "Yes" << endl; else cout << "No" << endl; }
void fYn(bool a) { assert_yn(yn_v, 2);Yn(a); exit(0);}
void YN(bool a) { assert_yn(yn_v, 3);if (a)cout << "YES" << endl; else cout << "NO" << endl; }
void fYN(bool a) { assert_yn(yn_v, 3);YN(a); exit(0);}
int ab_v = 0;
void fAb(bool a) { assert_yn(ab_v, 1);if(a)cout<<"Alice"<<endl;else cout<<"Bob";}
void fAB(bool a) { assert_yn(yn_v, 2);if(a)cout<<"ALICE"<<endl;else cout<<"BOB";}
int pos_v = 0;
void Possible(bool a) { assert_yn(pos_v, 1);if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0);}
void POSSIBLE(bool a) { assert_yn(pos_v, 2);if (a)cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; exit(0);}
void fPossible(bool a) { assert_yn(pos_v, 1)Possible(a);exit(0);}
void fPOSSIBLE(bool a) { assert_yn(pos_v, 2)POSSIBLE(a);exit(0);}
template<typename T> class fixed_point : T {public: explicit constexpr fixed_point(T &&t) noexcept: T(std::forward<T>(t)) {} template<typename... Args> constexpr decltype(auto) operator()(Args &&... args) const { return T::operator()(*this, std::forward<Args>(args)...); }};template<typename T> static inline constexpr decltype(auto) fix(T &&t) noexcept { return fixed_point<T>{std::forward<T>(t)}; }
//未分類
//0,2,1 1番目と2番目の次元を入れ替える
template<class T> auto irekae(vector<vector<vector<T> > > &A, int x, int y, int z) {
#define irekae_resize_loop(a, b, c) resize(res,a,b,c);rep(i,a)rep(j,b)rep(k,c)
vector<vector<vector<T> > > res; if (x == 0 && y == 1 && z == 2) { res = A; } else if (x == 0 && y == 2 && z == 1) { irekae_resize_loop(sz(A), sz(A[0][0]), sz(A[0])) { res[i][j][k] = A[i][k][j]; } } else if (x == 1 && y == 0 && z == 2) { irekae_resize_loop(sz(A[0]), sz(A), sz(A[0][0])) { res[i][j][k] = A[j][i][k]; } } else if (x == 1 && y == 2 && z == 0) { irekae_resize_loop(sz(A[0]), sz(A[0][0]), sz(A)) { res[i][j][k] = A[k][i][j]; } } else if (x == 2 && y == 0 && z == 1) { irekae_resize_loop(sz(A[0][0]), sz(A), sz(A[0])) { res[i][j][k] = A[j][k][i]; } } else if (x == 2 && y == 1 && z == 0) { irekae_resize_loop(sz(A[0][0]), sz(A[0]), sz(A)) { res[i][j][k] = A[k][j][i]; } } return res;
#undef irekae_resize_loop
}
template<class T> auto irekae(vector<vector<T>>&A,int i=1,int j=0){ vvt(res,sz(A[0]),sz(A)); rep(i,sz(A)){ rep(j,sz(A[0])){ res[j][i]=A[i][j]; } } return res;}
//tou分割する
template<typename Iterable> vector<Iterable> table(const Iterable &a, int tou = 2) {int N = sz(a); vector<Iterable> res(tou); int hab = N / tou; vi lens(tou, hab); rep(i, N % tou) { lens[tou - 1 - i]++; } int l = 0; rep(i, tou) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;}
//長さn毎に分割する
template<typename Iterable> vector<Iterable> table_n(const Iterable &a, int len) { int N = sz(a); vector<Iterable> res(ceil(N, len)); vi lens(N / len, len); if (N % len)lens.push_back(N % len); int l = 0; rep(i, sz(lens)) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;}
//縦を返す
vi& geth(vvi()& a, int w){ static vi ret; ret.resize(sz(a)); rep(i,sz(a)){ ret[i] = a[i][w]; } return ret;}
//@起動時
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
srand((unsigned) clock() + (unsigned) time(NULL));
};
} initonv;
//#define pre prev
//#define nex next
//gra mll pr
//上下左右
const string udlr = "udlr";
string UDLR = "UDLR";//x4と連動 UDLR.find('U') := x4[0]
vc atoz = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x','y', 'z'};
vc AtoZ = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X','Y', 'Z'};
//右、上が正
constexpr ll h4[] = {1, -1, 0, 0};
constexpr ll w4[] = {0, 0, -1, 1};
constexpr ll h8[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr ll w8[] = {1, 0, -1, 0, 1, -1, 1, -1};
int mei_inc(int h, int w, int H, int W, int i) {while (++i < 4) { if (inside(h + h4[i], w + w4[i], H, W))return i; }return i;}
#define mei(nh, nw, h, w) for (int i = mei_inc(h, w, H, W, -1), nh = i<4? h + h4[i] : 0, nw = i<4? w + w4[i] : 0; i < 4; i=mei_inc(h,w,H,W,i), nh = h+h4[i], nw = w+w4[i])
int mei_inc8(int h, int w, int H, int W, int i) { while (++i < 8) { if (inside(h + h8[i], w + w8[i], H, W))return i; } return i;}
#define mei8(nh, nw, h, w) for (int i = mei_inc8(h, w, H, W, -1), nh = i<8? h + h8[i] : 0, nw = i<8? w + w8[i] : 0; i < 8; i=mei_inc8(h,w,H,W,i), nh = h+h8[i], nw = w+w8[i])
int mei_incv(int h, int w, int H, int W, int i, vp &p) { while (++i < sz(p)) { if (inside(h + p[i].fi, w + p[i].se, H, W))return i; } return i;}
#define meiv(nh, nw, h, w, p) for (int i = mei_incv(h, w, H, W, -1, p), nh = i<sz(p)? h + p[i].fi : 0, nw = i<sz(p)? w + p[i].se : 0; i < sz(p); i=mei_incv(h,w,H,W,i,p), nh = h+p[i].fi, nw = w+p[i].se)
//H*Wのグリッドを斜めに分割する
//右上
vector<vp> naname_list_ne(int H, int W) { vector<vp> res(H + W - 1); rep(sh, H) { int sw = 0; res[sh] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh--; nw++; if (0 <= nh && nw < W) { res[sh] += mp(nh, nw); }else{ break; } } } rep(sw, 1, W) { int sh = H - 1; res[H + sw - 1] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh--; nw++; if (0 <= nh && nw < W) { res[H + sw-1] += mp(nh, nw); }else{ break; } } } return res;}
//右下
vector<vp> naname_list_se(int H, int W) { vector<vp> res(H + W - 1); rep(sh, H) { int sw = 0; res[sh] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh++; nw++; if (0 <= nh && nh< H && nw < W) { res[sh] += mp(nh, nw); } else { break; } } } rep(sw, 1, W) { int sh = 0; res[H + sw - 1] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh++; nw++; if (0 <= nh && nh < H && nw < W) { res[H + sw - 1] += mp(nh, nw); } else { break; } } } return res;}
//グラフ内で #undef getid
//#define getidとしているため、ここを書き直したらgraphも書き直す
#define getid_2(h, w) ((h) * (W) + (w))
#define getid_1(p) ((p).first * W + (p).second)
#define getid(...) over2(__VA_ARGS__, getid_2, getid_1) (__VA_ARGS__)
#define getp(id) mp(id / W, id % W)
//#define set_shuffle() std::random_device seed_gen;std::mt19937 engine(seed_gen())
//#define shuffle(a) std::shuffle((a).begin(), (a).end(), engine);
//1980 開始からtime ms経っていたらtrue
vb bit_bool(int v, int len) { assert(bit(len) > v); vb ret(len); rep(i, len) { ret[i] = bget(v, i); } return ret;}
vi range(int l, int r) {vi ret;ret.resize(r - l);rep(v, l, r) {ret[v - l] = v;}return ret;}
vi range(int r) {return range(0, r);}
vi tov(vb& a){ vi ret; rep(i,sz(a)){ if(a[i])ret.push_back(i); } return ret;}
bool kaibun(const str& S){return S==rev(S);}
template<class T> vector<T> repeat(const vector<T> &A, int kaisu) { vector<T> ret; while (kaisu--) { ret += A; } return ret;}
#define rge range
#define upd update
//S[{s, t, d}]
#define strs slice_str
struct slice_str {
string S;
slice_str() {}
slice_str(const string &S) : S(S) {}
slice_str(int len, char c) : S(len, c) {}
auto size(){return S.size();}
char& operator[](int p) { return S[p]; }
string operator[](initializer_list<int> p) { if (sz(p) == 1) { return S.substr(0, *(p.begin())); } else if (sz(p) == 2) { int l = *(p.begin()); int r = *(next(p.begin())); return S.substr(l, r - l); } else { auto it = p.begin(); int s = *(it++); int t = *(it++); int d = *(it); if (d == -1) { int s_ = sz(S) - s - 1; int t_ = sz(S) - t - 1; return rev(S).substr(s_, t_ - s_); } else if (d < 0) { t = max(-1ll, t); string ret; while (s > t) { ret += S[s]; s += d; } return ret; } else { t = min(sz(S), t); string ret; while (s < t) { ret += S[s]; s += d; } return ret; } } }
operator string &() { return S; }
template<class T> void operator+=(const T &a) { S += a; }
bool operator==(const slice_str& rhs){return S==rhs.S;}
};
ostream &operator<<(ostream &os, const slice_str &a) { os << a.S; return os;}
istream &operator>>(istream &iss, const slice_str &a) { iss >> a.S; return iss;}
template<class T> bool can(const T &v, int i) { return 0 <= i && i < sz(v); }
#if __cplusplus >= 201703L
//template<class T> auto sum(int a, T v...) {return (v + ... + 0);}
#endif
#define VEC vector
#endif /*UNTITLED15_TEMPLATE_H*/
#endif
//† ←template終了
/*@formatter:on*/
//vectorで取れる要素数
//bool=> 1e9 * 8.32
//int => 1e8 * 2.6
//ll => 1e8 * 1.3
//3次元以上取るとメモリがヤバい
//static配列を使う
vvc (ba);
ll N, M, H, W;
vi A, B, C;
void solve() {
in(N);
vi A;
din(L, R);
na(A, N);
rsort(A);
bool ok=1;
fora(a, sub(A,L))ok &= a==A[0];
if (ok) {
int cou = count(A, A[0]);
out(A[0]);
int res = 0;
rep(i, L-1, R) {
if(A[i] == A[0]){
res += comi(cou, i);
}
}
out(res);
}else{
out(sum(A, L)/ (dou)L);
int all = 0;
int ned = 0;
{
int l = find(A, A[L-1]);
int rr= l+1;
for (; rr< N; rr++){
if(A[rr] != A[L-1])break;
}
deb(l, rr);
ned = L - l;
all = rr - l;
}
deb(all, ned);
out(comi(all, ned));
}
}
auto my(ll n, vi &a) {
return 0;
}
auto sister(ll n, vi &a) {
ll ret = 0;
return ret;
}
signed main() {
solve();
#define arg n,a
#ifdef _DEBUG
bool bad = 0;
for (ll i = 0, ok = 1; i < k5 && ok; ++i) {
ll n = rand(1, 8);
vi a = ranv(n, 1, 10);
auto myres = my(arg);
auto res = sister(arg);
ok = myres == res;
if (!ok) {
out(arg);
cerr << "AC : " << res << endl;
cerr << "MY : " << myres << endl;
bad = 1;
break;
}
}
if (!bad) {
//solveを書き直す
//solveを呼び出す
}
if (was_deb && sz(res_mes)) {
cerr << "result = " << endl << res_mes << endl;
}
if (sz(message)) {
cerr << "****************************" << endl;
cerr << "Note." << endl;
cerr << message << endl;
cerr << "****************************" << endl;
}
#endif
return 0;
};
| a.cc:17:10: fatal error: boost/sort/pdqsort/pdqsort.hpp: No such file or directory
17 | #include <boost/sort/pdqsort/pdqsort.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
|
s452410166 | p03776 | C++ | /*temp*/
//
//
//
//
//#undef _DEBUG
//#pragma GCC optimize("Ofast")
//不動小数点の計算高速化
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#include <boost/multiprecision/cpp_int.hpp>
#ifdef _DEBUG
#include "template.h"
#else
#if __cplusplus >= 201703L
/*Atcoderでしか使えない(c++17 && このテンプレートが使えるならAtcoder)*/
#include <boost/sort/pdqsort/pdqsort.hpp>
#define fast_sort boost::sort::pdqsort
#endif
#endif
#ifndef _DEBUG
#ifndef UNTITLED15_TEMPLATE_H
#define UNTITLED15_TEMPLATE_H
#ifdef _DEBUG
#include "bits_stdc++.h"
#else
#include <bits/stdc++.h>
#endif
#ifndef fast_sort
#define fast_sort sort
#endif
//#define use_pq
#define use_for
#define use_for_each
#define use_sort
#define use_fill
#define use_rand
#define use_mgr
#define use_rui
#define use_compress
//
//
//
//
//
//
#define use_pbds
#ifdef use_pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
template<class T, class U, class W, class X> auto count(__gnu_pbds::gp_hash_table<T, U, W> &a, X k) { return a.find(k) != a.end(); }
#endif
using namespace std;
using namespace std::chrono;
/*@formatter:off*/
#define ll long long
using sig_dou = double;
//マクロ省略形 関数等
#define arsz(a) (sizeof(a)/sizeof(a[0]))
#define sz(a) ((ll)(a).size())
#define mp make_pair
#define mt make_tuple
#define pb pop_back
#define pf push_front
#define eb emplace_back
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
template<class T,class U> auto max(T a, U b){return a>b ? a: b;}
template<class T,class U> auto min(T a, U b){return a<b ? a: b;}
//optional<T>について下でオーバーロード(nullopt_tを左辺右辺について単位元として扱う)
template<class T, class U> bool chma(T &a, const U &b) { if (a < b) { a = b; return true; } return false;}
template<class T, class U> bool chmi(T &a, const U &b) { if (b < a) { a = b; return true; } return false;}
//メタ系 meta
//vector<T>でTを返す
#define decl_t(A) decltype(A)::value_type
//vector<vector<.....T>>でTを返す
template<class T> struct decl2 {typedef T type;};
template<class T> struct decl2<vector<T>> {typedef typename decl2<T>::type type;};
//#define decl_max(a, b) decltype(max(MAX<decltype(a)>(), MAX<decltype(b)>()))
#define is_same2(T, U) is_same<T, U>::value
template<class T>struct is_vector : std::false_type{};
template<class T>struct is_vector<std::vector<T>> : std::true_type{};
//大きい型を返す max_type<int, char>::type
//todo mintがlong long より小さいと判定されるためバグる
template<class T1, class T2, bool t1_bigger = (sizeof(T1) > sizeof(T2))>struct max_type{typedef T1 type;};
template<class T1, class T2> struct max_type<T1, T2, false>{typedef T2 type;};
template<typename T, typename U = typename T::value_type>std::true_type value_type_tester(signed);
template<typename T>std::false_type value_type_tester(long);
template<typename T>struct has_value_type: decltype(value_type_tester<T>(0)){};
template<class T> struct vec_rank : integral_constant<int, 0> {};
template<class T> struct vec_rank<vector<T>> : integral_constant<int, vec_rank<T>{} + 1> {};
//N個のTを並べたtupleを返す
//tuple_n<3, int>::type tuple<int, int, int>
template<size_t N, class T, class... Arg> struct tuple_n{typedef typename tuple_n<N-1, T, T, Arg...>::type type;};
template<class T, class...Arg> struct tuple_n<0, T, Arg...>{typedef tuple<Arg...> type;};
struct dummy_t1{};struct dummy_t2{};
struct dummy_t3{};struct dummy_t4{};
struct dummy_t5{};struct dummy_t6{};
//template<class T, require(is_integral<T>::value)>など
#define require_t(bo) enable_if_t<bo>* = nullptr
//複数でオーバーロードする場合、引数が同じだとうまくいかないため
//require_arg(bool, dummy_t1)
//require_arg(bool, dummy_t2)等とする
#define require_arg1(bo) enable_if_t<bo> * = nullptr
#define require_arg2(bo, dummy_type) enable_if_t<bo, dummy_type> * = nullptr
#define require_arg(...) over2(__VA_ARGS__,require_arg2,require_arg1)(__VA_ARGS__)
//->//enable_if_tのtを書き忘れそうだから
#define require_ret(bo, ret_type) enable_if_t<bo, ret_type>
#define int long long //todo 消したら動かない intの代わりにsignedを使う
auto start_time = system_clock::now();
auto past_time = system_clock::now();
#define debugName(VariableName) # VariableName
//最大引数がN
#define over2(o1, o2, name, ...) name
#define over3(o1, o2, o3, name, ...) name
#define over4(o1, o2, o3, o4, name, ...) name
#define over5(o1, o2, o3, o4, o5, name, ...) name
#define over6(o1, o2, o3, o4, o5, o6, name, ...) name
#define over7(o1, o2, o3, o4, o5, o6, o7, name, ...) name
#define over8(o1, o2, o3, o4, o5, o6, o7, o8, name, ...) name
#define over9(o1, o2, o3, o4, o5, o6, o7, o8, o9, name, ...) name
#define over10(o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, name, ...) name
void assert2(bool b,const string& s = ""){ if(!b){ cerr<<s<<endl; exit(1);/*assert(0);*/ }}
//my_nulloptをあらゆる操作の単位元的な物として扱う
//vectorの参照外時に返したり、右辺値として渡されたときに何もしないなど
struct my_nullopt_t {} my_nullopt;
#define nullopt_t my_nullopt_t
#define nullopt my_nullopt
/*@formatter:off*/
//値が無いときは、setを使わない限り代入できない
//=を使っても無視される
template<class T> struct my_optional {
private:
bool is_null;
T v;
public:
typedef T value_type ;
my_optional() : is_null(true) {}
my_optional(const nullopt_t&) : is_null(true) {}
my_optional(const T& v) : v(v), is_null(false) {}
bool has_value() const { return !is_null; }
T &value() { static string mes = "optional has no value";assert2(!is_null, mes);return v;}
const T &value() const { static string mes = "optional has no value";assert2(!is_null, mes);return v;}
void set(const T &nv) {is_null = false;v = nv;}
template<class U> void operator=(const U &v) {
set(v);//null状態でも代入出来るようにした
// if (has_value())value() = v; else return;
}
template<class U> void operator=(const my_optional<U> &v) {
if (/*has_value() && */v.has_value())(*this) = v; else return;
}
/*@formatter:off*/
void reset() { is_null = true; }
void operator=(const nullopt_t &) { reset(); }
template<require_t(!is_same2(T, bool))>
explicit operator bool(){return !is_null;}
//nullの時はエラー
operator T&(){return value();}
operator const T&()const {return value();}
my_optional<T> operator++() { if (this->has_value()) { this->value()++; return *this; } else { return *this; } }
my_optional<T> operator++(signed) { if (this->has_value()) { auto tem = *this; this->value()++; return tem; } else { return *this; } }
my_optional<T> operator--() { if (this->has_value()) { this->value()--; return *this; } else { return *this; } }
my_optional<T> operator--(signed) { if (this->has_value()) { auto tem = *this; this->value()--; return tem; } else { return *this; } }
};
template<class T>istream &operator>>(istream &iss, my_optional<T>& v) { T val; iss>>val; v.set(val); return iss;}
#define optional my_optional
template<class T>
using opt = my_optional<T>;
//template<class T, class A = std::allocator<T>> struct debtor : std::vector<T, A> {
template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key, T> >>
struct o_map : std::map<Key, optional<T>, Compare, Allocator> {
optional<T> emp;
o_map() : std::map<Key, optional<T>, Compare, Allocator>() {}
auto operator()(const nullopt_t&) {return nullopt;}
optional<T> &operator()(const optional<Key> &k) {if (k.has_value()) {return std::map<Key, optional<T>, Compare, Allocator>::operator[](k.value());} else {emp.reset();return emp;}}
optional<T> &operator()(const Key &k) { auto &v = std::map<Key, optional<T>, Compare, Allocator>::operator[](k); if (v.has_value())return v; else { v.set(0); return v; } }
template<class U> void operator[](U){static string mes = "s_map cant []";assert2(0, mes);}
};
//以下、空のoptionalをnulloptと書く
//ov[-1(参照外)] でnulloptを返す
//ov[nullopt] で nulloptをかえす
template<class T> struct ov{
optional<T> emp;
vector<optional<T>> v;
ov(int i = 0, T val = 0):v(i, val){}
template<class U>ov(const U& rhs){v.resize(sz(rhs));for (int i = 0; i < sz(rhs); i ++)v[i].set(rhs[i]);}
optional<T> &operator()(int i) {if (i < 0 || sz(v) <= i) {emp.reset();return emp;} else { return v[i]; }}
optional<T> &operator()(const nullopt_t &) { return operator()(-1); }
optional<T> &operator()(const optional<T> &i) { if (i.has_value())return operator()(i.value()); else { return operator()(-1); } }
/*@formatter:off*/
};
template<class T>string deb_tos(const ov<T>& v){
return deb_tos(v.v);
}
//vectorに対しての処理は.vを呼ぶ
template<class T> class ovv{
optional<T> emp;
public:
vector<vector<optional<T>> > v ;
ovv(int i=0, int j=0, T val = 0) : v(i, vector<optional<T>>(j, val) ){}
optional<T> &operator()(int i, int j) { if (i < 0 || j < 0 || sz(v) <= i || sz(v[i]) <= j) { emp.reset();return emp; } else { return v[i][j]; } }
//再帰ver 遅いと思う
// optional<T>& gets(optional<T>& v){return v;}
// template<class V, class H, class... U> optional<T>& gets(V& v, H i, U... tail){ if constexpr(is_same2(H, nullopt_t))return operator()(-1,-1); else if constexpr(is_same2(H, optional<int>)){ if(i.has_value())return gets(v[(int)i], tail...); else return operator()(-1,-1); }else if constexpr(is_integral<H>::value){ return gets(v[(int)i], tail...); }else{ assert(0); return emp; } }
#if __cplusplus >= 201703L
//if constexprバージョン 上が遅かったらこれで
template<class U, class V> optional<T> &operator()(const U &i, const V &j) { /*駄目な場合を除外*/ if constexpr(is_same2(U, nullopt_t) || is_same2(U, nullopt_t)) { return operator()(-1, -1); /* o, o*/ } else if constexpr(is_same2(U, optional<int>) && is_same2(V, optional<int>)) { return operator()(i.has_value() ? (int) i : -1, j.has_value() ? (int) j : -1); /* o, x*/ } else if constexpr(is_same2(U, optional<int>)) { return operator()(i.has_value() ? (int) i : -1, (int) j); /* x, o*/ } else if constexpr(is_same2(V, optional<int>)) { return operator()((int) i, j.has_value() ? (int) j : -1); /* x, x*/ } else { return operator()((int) i, (int) j); } }
#endif
operator const vector<vector<optional<T>> >&(){
return v;
}
};
template<class T>istream &operator>>(istream &iss, ovv<T> &a) { for (int h = 0; h < sz(a); h ++){ for (int w = 0; w < sz(a[h]); w ++){ iss>>a.v[h][w ]; } } return iss;}
template<class T>string deb_tos(const ovv<T>& v){
return deb_tos(v.v);
}
template<class T> struct ov3{
optional<T> emp;
vector<vector<vector<optional<T>>> > v ;
ov3(int i, int j, int k, T val = 0) : v(i, vector<vector<optional<T>>>(j, vector<optional<T>>(k, val) ) ){}
optional<T> &operator()(int i, int j, int k) { if (i < 0 || j < 0 || sz(v) <= i || sz(v[i]) <= j) { if(k < 0 || sz(v[i][j]) <= k){ emp.reset(); return emp; } } return v[i][j][k]; }
private:
#if __cplusplus >= 201703L
//再帰ver 遅いと思う
template<class V, class H> optional<T> &gets(V &nowv, H i) { if constexpr(is_same2(H, nullopt_t)) { emp.reset(); return emp; } else if constexpr(is_same2(H, optional<int>)) { if (i.has_value()) { return nowv[(int) i]; } else { emp.reset();return emp; } } else if constexpr(is_integral<H>::value) { return nowv[(int) i]; } else { static string mes = "ov3 error not index";assert2(0, mes); emp.reset();return emp; } }
//todo const &消した
template<class V, class H, class... U> optional<T> &gets(V &nowv, H i, U... tail) { if constexpr(is_same2(H, nullopt_t)) { emp.reset();return emp; } else if constexpr(is_same2(H, optional<int>)) { if (i.has_value()) { return gets(nowv[(int) i], tail...); } else { emp.reset();return emp; } } else if constexpr(is_integral<H>::value) { return gets(nowv[(int) i], tail...); } else { static string mes = "ov3 error not index";assert2(0, mes); emp.reset();return emp; } }
#endif
public:
template<class U, class V, class W> optional<T> &operator()(U i, V j, W k) { return gets(v, i, j, k); }
/*@formatter:off*/
};
template<class T>string deb_tos(const ov3<T>& v){
return deb_tos(v.v);
}
//nullopt_t
//優先順位
//null, [opt, tem]
// + と += は違う意味を持つ
//val+=null : val
//val+null : null
//
//+は途中計算
//+=は最終的に格納したい値にだけ持たせる
//+=がvoidを返すのは、途中計算で使うのを抑制するため
//nulloptを考慮する際、計算途中では+を使ってnulloptを作り
//格納する際は+=で無効にする必要がある
//演算子==
//optional<int>(10) == 10
//全ての型に対応させ、value_typeが等しいかを見るようにするのもありかも
//null同士を比較する状況はおかしいのではないか
bool operator==(const nullopt_t &, const nullopt_t&){assert2(0, "nul == null cant hikaku");return false;}
template<class T> bool operator==(const nullopt_t &, const T&){return false;}
template<class T> bool operator!=(const nullopt_t &, const T&){return true;}
template<class T> bool operator==(const T&, const nullopt_t &){return false;}
template<class T> bool operator!=(const T&, const nullopt_t &){return true;}
//nullを
nullopt_t& operator +(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator -(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator *(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator /(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator +=(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator -=(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator *=(const nullopt_t &, const nullopt_t&) {return nullopt;}
nullopt_t& operator /=(const nullopt_t &, const nullopt_t&) {return nullopt;}
template<class ANY> nullopt_t operator+(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator-(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator*(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator/(const nullopt_t&, const ANY &) {return nullopt;}
template<class ANY> nullopt_t operator+(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> nullopt_t operator-(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> nullopt_t operator*(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> nullopt_t operator/(const ANY &, const nullopt_t &) {return nullopt;}
template<class ANY> void operator+=(nullopt_t &, const ANY &) {}
template<class ANY> void operator-=(nullopt_t &, const ANY &) {}
template<class ANY> void operator*=(nullopt_t &, const ANY &) {}
template<class ANY> void operator/=(nullopt_t &, const ANY &) {}
template<class ANY> void operator+=(ANY &, const nullopt_t &) {}
template<class ANY> void operator-=(ANY &, const nullopt_t &) {}
template<class ANY> void operator*=(ANY &, const nullopt_t &) {}
template<class ANY> void operator/=(ANY &, const nullopt_t &) {}
template<class T>struct is_optional:false_type{};
template<class T>struct is_optional<optional<T>>:true_type{};
template<class T, class U>
true_type both_optional(optional<T> t, optional<U> u);
false_type both_optional(...);
template<class T, class U> class opt_check : public decltype(both_optional(declval<T>(), declval<U>())) {};
//optionalは同じ型同士しか足せない
//(o, t), (t, o), (o, o)
#define opt_tem(op) \
template<class O, class O_ret = decltype(declval<O>() op declval<O>())>optional<O_ret> operator op(const optional<O> &opt1, const optional<O> &opt2) { if (!opt1.has_value() || !opt2.has_value()) { return optional<O_ret>(); } else { return optional<O_ret>(opt1.value() op opt2.value()); }}\
template<class O, class T, class O_ret = decltype(declval<O>() op declval<O>())> auto operator op(const optional<O> &opt, const T &tem) -> require_ret(!(opt_check<optional<O>, T>::value), optional<O_ret>) { if (!opt.has_value()) { return optional<O_ret>(); } else { return optional<O_ret>(opt.value() op tem); }}\
template<class O, class T, class O_ret = decltype(declval<O>() op declval<O>())> auto operator op(const T &tem, const optional<O> &opt) -> require_ret(!(opt_check<optional<O>, T>::value), optional<O_ret>) { if (!opt.has_value()) { return optional<O_ret>(); } else { return optional<O_ret>(opt.value() op tem); }}
/*@formatter:off*/
opt_tem(+)opt_tem(-)opt_tem(*)opt_tem(/)
//比較はoptional<bool>を返す
opt_tem(<)opt_tem(>)opt_tem(<=)opt_tem(>=)
/*@formatter:on*//*@formatter:off*/
template<class O, class T> bool operator==(const optional<O>& opt, const T& tem){if(opt.has_value()){return opt.value()==tem;}else return nullopt == tem;}
template<class O, class T> bool operator!=(const optional<O>& opt, const T& tem){if(opt.has_value()){return opt.value()!=tem;}else return nullopt != tem;}
template<class O, class T> bool operator==(const T& tem, const optional<O>& opt){if(opt.has_value()){return opt.value()==tem;}else return nullopt == tem;}
template<class O, class T> bool operator!=(const T& tem, const optional<O>& opt){if(opt.has_value()){return opt.value()!=tem;}else return nullopt != tem;}
template<class O> bool operator==(const optional<O>& opt1, const optional<O>& opt2){ if(opt1.has_value() != opt2.has_value()){ return false; }else if(opt1.has_value()){ return opt1.value() == opt2.value(); }else { return nullopt == nullopt; }}
template<class O> bool operator!=(const optional<O>& opt1, const optional<O>& opt2){return !(opt1 == opt2);}
//(a+=null) != (a=a+null)
// a null
template<class T, class O> void operator+=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem += opt.value(); }}
template<class T, class O> void operator-=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem -= opt.value(); }}
template<class T, class O> void operator*=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem *= opt.value(); }}
template<class T, class O> void operator/=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem /= opt.value(); }}
template<class T, class O> void operator+=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() += tem; }}
template<class T, class O> void operator-=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() -= tem; }}
template<class T, class O> void operator*=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() *= tem; }}
template<class T, class O> void operator/=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() /= tem; }}
//
template<class Ol, class Or> void operator+=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl += opr.value(); }}
template<class Ol, class Or> void operator-=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl -= opr.value(); }}
template<class Ol, class Or> void operator*=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl *= opr.value(); }}
template<class Ol, class Or> void operator/=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl /= opr.value(); }}
/*@formatter:off*/
template<class U> auto max(const nullopt_t &, const U &val) { return val; }
template<class U> auto max(const U &val, const nullopt_t &) { return val; }
template<class U> auto min(const nullopt_t &, const U &val) { return val; }
template<class U> auto min(const U &val, const nullopt_t &) { return val; }
template<class T, class U> auto max(const optional<T> &opt, const U &val) { if (opt.has_value())return max(opt.value(), val); else return val; }
template<class T, class U> auto max(const U &val, const optional<T> &opt) { if (opt.has_value())return max(opt.value(), val); else return val; }
template<class T, class U> auto min(const optional<T> &opt, const U &val) { if (opt.has_value())return min(opt.value(), val); else return val; }
template<class T, class U> auto min(const U &val, const optional<T> &opt) { if (opt.has_value())return min(opt.value(), val); else return val; }
//null , optional, T
bool chma(nullopt_t &, const nullopt_t &) { return false; }
template<class T> bool chma(T &opt, const nullopt_t &) { return false; }
template<class T> bool chma(nullopt_t &, const T &opt) { return false; }
template<class T> bool chma(optional<T> &olv, const optional<T> &orv) { if (orv.has_value()) { return chma(olv, orv.value()); } else return false; }
template<class T, class U> bool chma(optional<T> &opt, const U &rhs) { if (opt.has_value()) { return chma(opt.value(), rhs); } else return false; }
template<class T, class U> bool chma(T &lhs, const optional<U> &opt) { if (opt.has_value()) { return chma(lhs, opt.value()); } else return false; }
bool chmi(nullopt_t &, const nullopt_t &) { return false; }
template<class T> bool chmi(T &opt, const nullopt_t &) { return false; }
template<class T> bool chmi(nullopt_t &, const T &opt) { return false; }
template<class T> bool chmi(optional<T> &olv, const optional<T> &orv) { if (orv.has_value()) { return chmi(olv, orv.value()); } else return false; }
template<class T, class U> bool chmi(optional<T> &opt, const U &rhs) { if (opt.has_value()) { return chmi(opt.value(), rhs); } else return false; }
template<class T, class U> bool chmi(T &lhs, const optional<U> &opt) { if (opt.has_value()) { return chmi(lhs, opt.value()); } else return false; }
template<class T> ostream &operator<<(ostream &os, optional<T> p) { if (p.has_value())os << p.value(); else os << "e"; return os;}
template<class T>using opt = my_optional<T>;
struct xorshift {
/*@formatter:on*/
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
/*@formatter:off*/
size_t operator()(const uint64_t& x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); }
size_t operator()(const std::pair<ll, ll>& x) const { ll v = ((x.first) << 32) | x.second; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(v + FIXED_RANDOM); }
template<class T, class U> size_t operator()(const std::pair<T, U>& x) const{ static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); uint64_t hasx = splitmix64(x.first); uint64_t hasy = splitmix64(x.second + FIXED_RANDOM); return hasx ^ hasy; }
template<class T> size_t operator()(const vector<T> &x) const { uint64_t has = 0; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); uint64_t rv = splitmix64(FIXED_RANDOM); for (int i = 0; i < sz(x); i ++){ uint64_t v = splitmix64(x[i] + rv); has ^= v; rv = splitmix64(rv); } return has; }
};
#ifdef _DEBUG
string message;
string res_mes;
//#define use_debtor
//template<class T, class U, class X> auto count(unordered_map<T, U> &a, X k) { return a.find(k) != a.end(); }
#ifdef use_debtor
//https://marycore.jp/prog/cpp/class-extension-methods/ 違うかも
template<class T, class A = std::allocator<T>> struct debtor : std::vector<T, A> {
using std::vector<T, A>::vector;
template<class U> int deb_v(U a, int v) { return v; }
template<class U> int deb_v(debtor<U> &a, int v = 0) { cerr << a.size() << " "; return deb_v(a.at(0), v + 1); }
template<class U> void deb_o(U a) { cerr << a << " "; }
template<class U> void deb_o(debtor<U> &a) { for (int i = 0; i < min((int) a.size(), 15ll); i++) { deb_o(a[i]); } if ((int) a.size() > 15) { cerr << "..."; } cerr << endl; }
typename std::vector<T>::reference my_at(typename std::vector<T>::size_type n, vector<int> &ind) { if (n < 0 || n >= (int) this->size()) { int siz = (int) this->size(); cerr << "vector size = "; int dim = deb_v((*this)); cerr << endl; ind.push_back(n); cerr << "out index at "; for (auto &&i: ind) { cerr << i << " "; } cerr << endl; cerr << endl; if (dim <= 2) { deb_o((*this)); } exit(0); } return this->at(n); }
typename std::vector<T>::reference operator[](typename std::vector<T>::size_type n) { if (n < 0 || n >= (int) this->size()) { int siz = (int) this->size(); cerr << "vector size = "; int dim = deb_v((*this)); cerr << endl; cerr << "out index at " << n << endl; cerr << endl; if (dim <= 2) { deb_o((*this)); } exit(0); } return this->at(n); }
};
#define vector debtor
#endif
#ifdef use_pbds
template<class T> struct my_pbds_tree {
set<T> s;
auto begin() { return s.begin(); }
auto end() { return s.end(); }
auto rbegin() { return s.rbegin(); }
auto rend() { return s.rend(); }
auto empty() { return s.empty(); }
auto size() { return s.size(); }
void clear() { s.clear(); }
template<class U> void insert(U v) { s.insert(v); }
template<class U> void operator+=(U v) { insert(v); }
template<class F> auto erase(F v) { return s.erase(v); }
template<class U> auto find(U v) { return s.find(v); }
template<class U> auto lower_bound(U v) { return s.lower_bound(v); }
template<class U> auto upper_bound(U v) { return s.upper_bound(v); }
auto find_by_order(ll k) { auto it = s.begin(); for (ll i = 0; i < k; i++)it++; return it; }
auto order_of_key(ll v) { auto it = s.begin(); ll i = 0; for (; it != s.end() && *it < v; i++)it++; return i; }
};
#define pbds(T) my_pbds_tree<T>
#endif
//区間削除は出来ない
//gp_hash_tableでcountを使えないようにするため
template<class T, class U> struct my_unordered_map { unordered_map<T, U> m; my_unordered_map() {}; auto begin() { return m.begin(); } auto end() { return m.end(); } auto cbegin() { return m.cbegin(); } auto cend() { return m.cend(); } template<class V> auto erase(V v) { return m.erase(v); } void clear() { m.clear(); } /*countは gp_hash_tableに存在しない*/ /*!= m.end()*/ template<class V> auto find(V v) { return m.find(v); } template<class V> auto &operator[](V n) { return m[n]; }};
template<class K, class V>using umap_f = my_unordered_map<K, V>;
#else
#define endl '\n'
//umapはunorderd_mapになる
//umapiはgp_hash_table
//find_by_order(k) k番目のイテレーター
//order_of_key(k) k以上が前から何番目か
#define pbds(U) __gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>
template<class K, class V>using umap_f = __gnu_pbds::gp_hash_table<K, V, xorshift>;
#endif
#define umapi unordered_map<ll,ll>
#define umapp unordered_map<P,ll>
#define umappp unordered_map<P,P>
#define umapu unordered_map<uint64_t,ll>
#define umapip unordered_map<ll,P>
template<class T, class U, class X> auto count(unordered_map<T, U> &a, X k) { return a.find(k) != a.end(); }
/*@formatter:off*/
#ifdef use_pbds
template<class U, class L> void operator+=(__gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> &s, L v) { s.insert(v); }
#endif
//衝突対策
#define ws ws_
//todo 要らないと思う
template<class A, class B, class C> struct T2 { A f;B s;C t;T2() { f = 0, s = 0, t = 0; }T2(A f, B s, C t) : f(f), s(s), t(t) {}bool operator<(const T2 &r) const { return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t; /*return f != r.f ? f > r.f : s != r.s ?n s > r.s : t > r.t; 大きい順 */ } bool operator>(const T2 &r) const { return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; /*return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順 */ } bool operator==(const T2 &r) const { return f == r.f && s == r.s && t == r.t; } bool operator!=(const T2 &r) const { return f != r.f || s != r.s || t != r.t; }};
template<class A, class B, class C, class D> struct F2 {
A a;B b;C c;D d;
F2() { a = 0, b = 0, c = 0, d = 0; }
F2(A a, B b, C c, D d) : a(a), b(b), c(c), d(d) {}
bool operator<(const F2 &r) const { return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d; /* return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;*/ }
bool operator>(const F2 &r) const { return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;/* return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d;*/ }
bool operator==(const F2 &r) const { return a == r.a && b == r.b && c == r.c && d == r.d; }
bool operator!=(const F2 &r) const { return a != r.a || b != r.b || c != r.c || d != r.d; }
ll operator[](ll i) {assert(i < 4);return i == 0 ? a : i == 1 ? b : i == 2 ? c : d;}
};
typedef T2<ll, ll, ll> T;
typedef F2<ll, ll, ll, ll> F;
//T mt(ll a, ll b, ll c) { return T(a, b, c); }
//F mf(ll a, ll b, ll c, ll d) { return F(a, b, c, d); }
//関数内をまとめる
//初期値l=-1, r=-1
void set_lr12(int &l, int &r, int n) { /*r==-1*/ if (r == -1) { if (l == -1) { l = 0; r = n; } else { r = l; l = 0; } }}
//@マクロ省略系 型,構造
//using で元のdoubleを同時に使えるはず
#define double_big
#ifdef double_big
#define double long double
//#define pow powl
#endif
using dou = double;
/*@formatter:off*/
template<class T> T MAX() { return numeric_limits<T>::max(); }
template<class T> T MIN() { return numeric_limits<T>::min(); }
constexpr ll inf = (ll) 1e9 + 100;
constexpr ll linf = (ll) 1e18 + 100;
constexpr dou dinf = (dou) linf * linf;
constexpr char infc = '{';
const string infs = "{";
template<class T> T INF() { return MAX<T>() / 2; }
template<> signed INF() { return inf; }
template<> ll INF() { return linf; }
template<> double INF() { return dinf; }
template<> char INF() { return infc; }
template<> string INF() { return infs; }
const double eps = 1e-9;
//#define use_epsdou
#ifdef use_epsdou
//基本コメントアウト
struct epsdou { double v; epsdou(double v = 0) : v(v) {} template<class T> epsdou &operator+=(T b) { v += (double) b; return (*this); } template<class T> epsdou &operator-=(T b) { v -= (double) b; return (*this); } template<class T> epsdou &operator*=(T b) { v *= (double) b; return (*this); } template<class T> epsdou &operator/=(T b) { v /= (double) b; return (*this); } epsdou operator+(epsdou b) { return v + (double) b; } epsdou operator-(epsdou b) { return v - (double) b; } epsdou operator*(epsdou b) { return v * (double) b; } epsdou operator/(epsdou b) { return v / (double) b; } epsdou operator-() const { return epsdou(-v); } template<class T> bool operator<(T b) { return v < (double) b; } template<class T> bool operator>(T b) {auto r = (double)b; return v > (double) b; } template<class T> bool operator==(T b) { return fabs(v - (double) b) <= eps; } template<class T> bool operator<=(T b) { return v < (double) b || fabs(v - b) <= eps; } template<class T> bool operator>=(T b) { return v > (double) b || fabs(v - b) <= eps; } operator double() { return v; }};
template<>epsdou MAX(){return MAX<double>();}
template<>epsdou MIN(){return MIN<double>();}
//priqrity_queue等で使うのに必要
bool operator<(const epsdou &a, const epsdou &b) {return a.v < b.v;}
bool operator>(const epsdou &a, const epsdou &b) {return a.v > b.v;}
istream &operator>>(istream &iss, epsdou &a) {iss >> a.v;return iss;}
ostream &operator<<(ostream &os, epsdou &a) {os << a.v;return os;}
#define eps_conr_t(o) template<class T> epsdou operator o(T a, epsdou b) {return (dou) a o b.v;}
#define eps_conl_t(o) template<class T> epsdou operator o(epsdou a, T b) {return a.v o (dou) b;}
eps_conl_t(+)eps_conl_t(-)eps_conl_t(*)eps_conl_t(/)eps_conr_t(+)eps_conr_t(-)eps_conr_t(*)eps_conr_t(/)
//template<class U> epsdou max(epsdou a, U b){return a.v>b ? a.v: b;}
//template<class U> epsdou max(U a, epsdou b){return a>b.v ? a: b.v;}
//template<class U> epsdou min(epsdou a, U b){return a.v<b ? a.v: b;}
//template<class U> epsdou min(U a, epsdou b){return a<b.v ? a: b.v;}
#undef double
#define double epsdou
#undef dou
#define dou epsdou
#endif
template<class T = int, class A, class B = int> T my_pow(A a, B b = 2) {
if(b < 0)return (T)1 / my_pow<T>(a, -b);
#if __cplusplus >= 201703L
if constexpr(is_floating_point<T>::value) { return pow((T) a, (T) b); }
else if constexpr(is_floating_point<A>::value) { assert2(0, "pow <not dou>(dou, )");/*return 0;しない方がコンパイル前に(voidを受け取るので)エラーが出ていいかも*/}
else if constexpr(is_floating_point<B>::value) { assert2(0, "pow <not dou>(, dou)");/*return 0;しない方がコンパイル前に(voidを受け取るので)エラーが出ていいかも*/}
else {
#endif
T ret = 1; T bek = a; while (b) { if (b & 1)ret *= bek; bek *= bek; b >>= 1; } return ret;
#if __cplusplus >= 201703L
}
#endif
}
#define pow my_pow
#define ull unsigned long long
using itn = int;
using str = string;
using bo= bool;
#define au auto
using P = pair<ll, ll>;
#define fi first
#define se second
#define beg begin
#define rbeg rbegin
#define con continue
#define bre break
#define brk break
#define is ==
#define el else
#define elf else if
#define upd update
#define sstream stringstream
#define maxq 1
#define minq -1
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MALLOC(type, len) (type*)malloc((len) * sizeof(type))
#define lam1(ret) [&](auto&& v){return ret;}
#define lam2(v, ret) [&](auto&& v){return ret;}
#define lam(...) over2(__VA_ARGS__,lam2,lam1)(__VA_ARGS__)
#define lamr(right) [&](auto&& p){return p right;}
#define unique(v) v.erase( unique(v.begin(), v.end()), v.end() );
//マクロ省略系 コンテナ
using vi = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vd = vector<double>;
using vc = vector<char>;
using vp = vector<P>;
using vt = vector<T>;
//#define V vector
#define vvt0(t) vector<vector<t>>
#define vvt1(t, a) vector<vector<t>>a
#define vvt2(t, a, b) vector<vector<t>>a(b)
#define vvt3(t, a, b, c) vector<vector<t>> a(b,vector<t>(c))
#define vvt4(t, a, b, c, d) vector<vector<t>> a(b,vector<t>(c,d))
#define vvi(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__)
#define vvb(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__)
#define vvs(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__)
#define vvd(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__)
#define vvc(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__)
#define vvp(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__)
#define vvt(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(T,__VA_ARGS__)
#define vv(type, ...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(type,__VA_ARGS__)
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));}
#define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__)
#define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__)
#define vns(name, ...) auto name = make_v<string>(__VA_ARGS__)
#define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__)
#define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__)
#define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__)
#define vn(type, name, ...) auto name = make_v<type>(__VA_ARGS__)
#define PQ priority_queue<ll, vector<ll>, greater<ll> >
#define tos to_string
using mapi = map<ll, ll>;
using mapp = map<P, ll>;
using mapd = map<dou, ll>;
using mapc = map<char, ll>;
using maps = map<str, ll>;
using seti = set<ll>;
using setp = set<P>;
using setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<ll>;
#define uset unordered_set
#define useti unordered_set<ll,xorshift>
#define mset multiset
#define mseti multiset<ll>
#define umap unordered_map
#define mmap multimap
//任意のマクロサポート用 使う度に初期化する
int index_, v1_, v2_, v3_;
/*@formatter:off*/
string to_string(char c) { string ret = ""; ret += c; return ret;}
template<class T> class pq_min_max { vector<T> d; void make_heap() { for (int i = d.size(); i--;) { if (i & 1 && d[i - 1] < d[i]) swap(d[i - 1], d[i]); int k = down(i); up(k, i); } } inline int parent(int k) const { return ((k >> 1) - 1) & ~1; } int down(int k) { int n = d.size(); if (k & 1) { /* min heap*/ while (2 * k + 1 < n) { int c = 2 * k + 3; if (n <= c || d[c - 2] < d[c]) c -= 2; if (c < n && d[c] < d[k]) { swap(d[k], d[c]); k = c; } else break; } } else { /* max heap*/ while (2 * k + 2 < n) { int c = 2 * k + 4; if (n <= c || d[c] < d[c - 2]) c -= 2; if (c < n && d[k] < d[c]) { swap(d[k], d[c]); k = c; } else break; } } return k; } int up(int k, int root = 1) { if ((k | 1) < (int) d.size() && d[k & ~1] < d[k | 1]) { swap(d[k & ~1], d[k | 1]); k ^= 1; } int p; while (root < k && d[p = parent(k)] < d[k]) { /*max heap*/ swap(d[p], d[k]); k = p; } while (root < k && d[k] < d[p = parent(k) | 1]) { /* min heap*/ swap(d[p], d[k]); k = p; } return k; }public: pq_min_max() {} pq_min_max(const vector<T> &d_) : d(d_) { make_heap(); } template<class Iter> pq_min_max(Iter first, Iter last) : d(first, last) { make_heap(); } void operator+=(const T &x) { int k = d.size(); d.push_back(x); up(k); } void pop_min() { if (d.size() < 3u) { d.pop_back(); } else { swap(d[1], d.back()); d.pop_back(); int k = down(1); up(k); } } void pop_max() { if (d.size() < 2u) { d.pop_back(); } else { swap(d[0], d.back()); d.pop_back(); int k = down(0); up(k); } } const T &get_min() const { return d.size() < 2u ? d[0] : d[1]; } const T &get_max() const { return d[0]; } int size() const { return d.size(); } bool empty() const { return d.empty(); }};
//小さいほうからM個取得するpq
template<class T> struct helper_pq_size { pq_min_max<T> q; T su = 0; int max_size = 0; helper_pq_size() {} helper_pq_size(int max_size) : max_size(max_size) {} void clear() { q = pq_min_max<T>(); su = 0; } void operator+=(T v) { su += v; q += (v); if (sz(q) > max_size) { su -= q.get_max(); q.pop_max(); } } T sum() { return su; } T top() { return q.get_min(); } void pop() { su -= q.get_min(); q.pop_min(); } T poll() { T ret = q.get_min(); su -= ret; q.pop_min(); return ret; } ll size() { return q.size(); }};
//大きいほうからM個取得するpq
template<class T> struct helper_pqg_size { pq_min_max<T> q; T su = 0; int max_size = 0; helper_pqg_size() {} helper_pqg_size(int max_size) : max_size(max_size) {} void clear() { q = pq_min_max<T>(); su = 0; } void operator+=(T v) { su += v; q += (v); if (sz(q) > max_size) { su -= q.get_min(); q.pop_min(); } } T sum() { return su; } T top() { return q.get_max(); } void pop() { su -= q.get_max(); q.pop_max(); } T poll() { T ret = q.get_max(); su -= ret; q.pop_min(); return ret; } ll size() { return q.size(); }};;
template<class T, class Container = vector<T>,class Compare = std::less<typename Container::value_type>>
struct helper_pqg { priority_queue<T, Container, Compare> q;/*小さい順*/ T su = 0; helper_pqg() {} void clear() { q = priority_queue<T, vector<T>, greater<T> >(); su = 0; } void operator+=(T v) { su += v; q.push(v); } T sum() { return su; } T top() { return q.top(); } void pop() { su -= q.top(); q.pop(); } T poll() { T ret = q.top(); su -= ret; q.pop(); return ret; } ll size() { return q.size(); }};
template<class T>
using helper_pq = helper_pqg<T, vector<T>, greater<T>>;
#if __cplusplus >= 201703L
//小さいほうからsize個残る
//Tがoptionalなら空の時nullを返す
template<class T> struct pq {
helper_pq<T> a_q;/*大きい順*/ helper_pq_size<T> b_q;/*大きい順*/ bool aquery;
T su = 0;
pq(int size = inf) {aquery = size == inf;if (!aquery) { b_q = helper_pq_size<T>(size); }}
void clear() { if (aquery) a_q.clear(); else b_q.clear(); }
void operator+=(T v) { if (aquery) a_q += v; else b_q += v; }
//optionalなら空の時nullを返す
T top() { if constexpr(is_optional<T>::value) { if (aquery) { if (sz(a_q) == 0)return T(); return a_q.top(); } else { if (sz(b_q) == 0)return T(); return b_q.top(); } } else { if (aquery)return a_q.top(); else return b_q.top(); } }
T sum() { if (aquery) return a_q.sum(); else return b_q.sum(); }
//optionalなら空の時何もしない
void pop() { if constexpr(is_optional<T>::value) { if (aquery) { if (sz(a_q))a_q.pop(); } else { if (sz(b_q))b_q.pop(); }} else { if (aquery)a_q.pop(); else b_q.pop(); }} /*T*/
T poll() { if constexpr(is_optional<T>::value) { if (aquery) { if (sz(a_q) == 0)return T(); return a_q.poll(); } else { if (sz(b_q) == 0)return T(); return b_q.poll(); } } else { if (aquery)return a_q.poll(); else return b_q.poll(); } }
ll size() { if (aquery) return a_q.size(); else return b_q.size(); }
/*@formatter:off*/
};
template<class T> struct pqg { helper_pqg<T> a_q;/*大きい順*/ helper_pqg_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pqg(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pqg_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }};
#else
//小さいほうからsize個残る
template<class T> struct pq { helper_pq<T> a_q;/*大きい順*/ helper_pq_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pq(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pq_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }};
//大きいほうからsize個残る
template<class T> struct pqg { helper_pqg<T> a_q;/*大きい順*/ helper_pqg_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pqg(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pqg_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }};
#endif
#define pqi pq<ll>
#define pqgi pqg<ll>
template<class T> string deb_tos(pq<T> &q) { vector<T> res; auto temq = q; while (sz(temq))res.push_back(temq.top()), temq.pop(); stringstream ss; ss<< res; return ss.str();}
template<class T> string deb_tos(pqg<T> &q) { vector<T> res; auto temq = q; while (sz(temq))res.push_back(temq.top()), temq.pop(); stringstream ss; ss<< res; return ss.str();}
/*@formatter:off*/
//マクロ 繰り返し
//↓@オーバーロード隔離
//todo 使わないもの非表示
#define rep1(n) for(ll rep1i = 0,rep1lim=n; rep1i < rep1lim ; ++rep1i)
#define rep2(i, n) for(ll i = 0,rep2lim=n; i < rep2lim ; ++i)
#define rep3(i, m, n) for(ll i = m,rep3lim=n; i < rep3lim ; ++i)
#define rep4(i, m, n, ad) for(ll i = m,rep4lim=n; i < rep4lim ; i+= ad)
//逆順 閉区間
#define rer2(i, n) for(ll i = n; i >= 0 ; i--)
#define rer3(i, m, n) for(ll i = m,rer3lim=n; i >= rer3lim ; i--)
#define rer4(i, m, n, dec) for(ll i = m,rer4lim=n; i >= rer4lim ; i-=dec)
#ifdef use_for
//ループを一つにまとめないとフォーマットで汚くなるため
#define nex_ind1(i) i++
#define nex_ind2(i, j, J) i = (j + 1 == J) ? i + 1 : i, j = (j + 1 == J ? 0 : j + 1)
#define nex_ind3(i, j, k, J, K)i = (j + 1 == J && k + 1 == K) ? i + 1 : i, j = (k + 1 == K) ? (j + 1 == J ? 0 : j + 1) : j, k = (k + 1 == K ? 0 : k + 1)
#define nex_ind4(i, j, k, l, J, K, L) i = (j + 1 == J && k + 1 == K && l + 1 == L) ? i + 1 : i, j = (k + 1 == K && l + 1 == L) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L ?(k + 1 == K ? 0 : k + 1) : k), l = l + 1 == L ? 0 : l + 1
#define nex_ind5(i, j, k, l, m, J, K, L, M) i = (j + 1 == J && k + 1 == K && l + 1 == L && m + 1 == M) ? i + 1 : i, j = (k + 1 == K && l + 1 == L && m + 1 == M) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L && m + 1 == M ?(k + 1 == K ? 0 : k + 1) : k), l = m + 1 == M ? l+1 == L ? 0 : l+1 : l, m = m + 1 == M ? 0 : m + 1
#define repss2(i, I) for (int i = 0; i < I; i++)
#define repss4(i, j, I, J) for (int i = (J ? 0 : I), j = 0; i < I; nex_ind2(i, j, J))
#define repss6(i, j, k, I, J, K) for (int i = (J && K ? 0 : I), j = 0, k = 0; i < I; nex_ind3(i, j, k, J, K))
#define repss8(i, j, k, l, I, J, K, L) for (int i = (J && K && L ? 0 : I), j = 0, k = 0, l = 0; i < I; nex_ind4(i, j, k, l, J, K, L))
#define repss10(i, j, k, l, m, I, J, K, L, M)for (int i = (J && K && L && M ? 0 : I), j = 0, k = 0, l = 0, m = 0; i < I; nex_ind5(i, j, k, l, m, J, K, L, M))
//i,j,k...をnまで見る
#define reps2(i, n) repss2(i, n)
#define reps3(i, j, n) repss4(i, j, n, n)
#define reps4(i, j, k, n) repss6(i, j, k, n, n, n)
#define reps5(i, j, k, l, n) repss8(i, j, k, l, n, n, n, n)
template<class T> void nex_repv2(int &i, int &j, int &I, int &J, vector<vector<T>> &s) { while (1) { j++; if (j >= J) { j = 0; i++; if (i < I) { J = (int) s[i].size(); } } if (i >= I || J) return; }}
template<class T> void nex_repv3(int &i, int &j, int &k, int &I, int &J, int &K, vector<vector<vector<T>>> &s) { while (1) { k++; if (k >= K) { k = 0; j++; if (j >= J) { j = 0; i++; if (i >= I)return; } } J = (int) s[i].size(); K = (int) s[i][j].size(); if (J && K) return; }}
#define repv_2(i, a) repss2(i, sz(a))
//正方形である必要はない
//直前を持つのとどっちが早いか
#define repv_3(i, j, a) for (int repvI = (int)a.size(), repvJ = (int)a[0].size(), i = 0, j = 0; i < repvI; nex_repv2(i,j,repvI,repvJ,a))
//箱状になっている事が要求される つまり[i] 次元目の要素数は一定
#define repv_4(i, j, k, a) for (int repvI = (int)a.size(), repvJ = (int)a[0].size(), repvK =(int)a[0][0].size(), i = 0, j = 0, k=0; i < repvI; nex_repv3(i,j,k,repvI,repvJ,repvK,a))
#define repv_5(i, j, k, l, a) repss8(i, j, k, l, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0]))
#define repv_6(i, j, k, l, m, a) repss10(i, j, k, l, m, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0]), sz(a[0][0][0][0]))
#endif
template<typename T> struct has_rbegin_rend { private:template<typename U> static auto check(U &&obj) -> decltype(std::rbegin(obj), std::rend(obj), std::true_type{});static std::false_type check(...);public:static constexpr bool value = decltype(check(std::declval<T>()))::value; };
template<typename T> constexpr bool has_rbegin_rend_v = has_rbegin_rend<T>::value;
template<typename Iterator> class Range { public:Range(Iterator &&begin, Iterator &&end) noexcept: m_begin(std::forward<Iterator>(begin)), m_end(std::forward<Iterator>(end)) {}Iterator begin() const noexcept { return m_begin; }Iterator end() const noexcept { return m_end; }private:const Iterator m_begin;const Iterator m_end; };
template<typename Iterator> static inline Range<Iterator> makeRange(Iterator &&begin, Iterator &&end) noexcept { return Range<Iterator>{std::forward<Iterator>(begin), std::forward<Iterator>(end)}; }
template<typename T> static inline decltype(auto) makeReversedRange(const std::initializer_list<T> &iniList) noexcept { return makeRange(std::rbegin(iniList), std::rend(iniList)); }
template<typename T, typename std::enable_if_t<has_rbegin_rend_v<T>, std::nullptr_t> = nullptr> static inline decltype(auto) makeReversedRange(T &&c) noexcept { return makeRange(std::rbegin(c), std::rend(c)); }/* rbegin(), rend()を持たないものはこっちに分岐させて,エラーメッセージを少なくする*/template<typename T, typename std::enable_if<!has_rbegin_rend<T>::value, std::nullptr_t>::type = nullptr> static inline void makeReversedRange(T &&) noexcept { static_assert(has_rbegin_rend<T>::value, "Specified argument doesn't have reverse iterator."); }
//#define use_for
#define form1(st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it)
#define form3(k, v, st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it)
#define form4(k, v, st, r) for (auto &&form_it = st.begin(); form_it != st.end() && (*form_it).fi < r; ++form_it)
#define form5(k, v, st, l, r) for (auto &&form_it = st.lower_bound(l); form_it != st.end() && (*form_it).fi < r; ++form_it)
#define forrm1(st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it)
#define forrm3(k, v, st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it)
//向こう側で
// ++itか it = st.erase(it)とする
#define fors1(st) for (auto &&it = st.begin(); it != st.end(); )
#define fors2(v, st) for (auto &&it = st.begin(); it != st.end(); )
#define fors3(v, st, r) for (auto &&it = st.begin(); it != st.end() && (*it) < r; )
#define fors4(v, st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it) < r; )
#ifdef use_for
#define forslr3(st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it)
#define forslr4(v, st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it)
#define forslr5(v, st, r, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it)
#define forslr6(v, st, l, r, a, b) for (auto &&forslr_it = st.lower_bound(l); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it)
#define fora_f_init_2(a, A) ;
#define fora_f_init_3(fora_f_i, a, A) auto &&a = A[fora_f_i];
#define fora_f_init_4(a, b, A, B) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i];
#define fora_f_init_5(fora_f_i, a, b, A, B) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i];
#define fora_f_init_6(a, b, c, A, B, C) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i];
#define fora_f_init_7(fora_f_i, a, b, c, A, B, C) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i];
#define fora_f_init_8(a, b, c, d, A, B, C, D) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; auto && d = D[fora_f_i];
#define fora_f_init_9(fora_f_i, a, b, c, d, A, B, C, D) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; auto && d = D[fora_f_i];
#define fora_f_init(...) over9(__VA_ARGS__,fora_f_init_9, fora_f_init_8, fora_f_init_7, fora_f_init_6, fora_f_init_5, fora_f_init_4, fora_f_init_3, fora_f_init_2)(__VA_ARGS__)
#define forr_init_2(a, A) auto &&a = A[forr_i];
#define forr_init_3(forr_i, a, A) auto &&a = A[forr_i];
#define forr_init_4(a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i];
#define forr_init_5(forr_i, a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i];
#define forr_init_6(a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i];
#define forr_init_7(forr_i, a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i];
#define forr_init_8(a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i];
#define forr_init_9(forr_i, a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i];
#define forr_init(...) over9(__VA_ARGS__, forr_init_9, forr_init_8, forr_init_7, forr_init_6, forr_init_5, forr_init_4, forr_init_3, forr_init_2)(__VA_ARGS__)
#define forp_init3(k, v, S) auto &&k = S[forp_i].first;auto &&v = S[forp_i].second;
#define forp_init4(forp_i, k, v, S) auto &&k = S[forp_i].first;auto &&v = S[forp_i].second;
#define forp_init(...) over4(__VA_ARGS__,forp_init4,forp_init3,forp_init2,forp_init1)(__VA_ARGS__)
#define form_init(k, v, ...) auto &&k = (*form_it).fi;auto &&v = (*form_it).se;
#define forrm_init(k, v, ...) auto &&k = (*forrm_it).fi;auto &&v = (*forrm_it).se;
#define fors_init(v, ...) auto &&v = (*it);
#define forlr_init(a, A, ngl, ngr) auto a = A[forlr_i]; auto prev = forlr_i ? A[forlr_i-1] : ngl;auto next = forlr_i+1< rep2lim? A[forlr_i+1] : ngr;
#define forslr_init4(a, A, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr;
#define forslr_init5(a, A, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr;
#define forslr_init6(a, A, l, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr;
#define forslr_init(...) over6(__VA_ARGS__,forslr_init6,forslr_init5,forslr_init4)(__VA_ARGS__);
//こうしないとmapがおかしくなる
#define fora_f_2(a, A) for(auto&& a : A)
#define fora_f_3(fora_f_i, a, A) rep(fora_f_i, sz(A))
#define fora_f_4(a, b, A, B) rep(fora_f_i, sz(A))
#define fora_f_5(fora_f_i, a, b, A, B) rep(fora_f_i, sz(A))
#define fora_f_6(a, b, c, A, B, C) rep(fora_f_i, sz(A))
#define fora_f_7(fora_f_i, a, b, c, A, B, C) rep(fora_f_i, sz(A))
#define fora_f_8(a, b, c, d, A, B, C, D) rep(fora_f_i, sz(A))
#define fora_f_9(fora_f_i, a, b, c, d, A, B, C, D) rep(fora_f_i, sz(A))
#define forr_2(a, A) rer(forr_i, sz(A)-1)
#define forr_3(forr_i, a, A) rer(forr_i, sz(A)-1)
#define forr_4(a, b, A, B) rer(forr_i, sz(A)-1)
#define forr_5(forr_i, a, b, A, B) rer(forr_i, sz(A)-1)
#define forr_6(a, b, c, A, B, C) rer(forr_i, sz(A)-1)
#define forr_7(forr_i, a, b, c, A, B, C) rer(forr_i, sz(A)-1)
#define forr_8(a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1)
#define forr_9(forr_i, a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1)
#endif
//↑@オーバーロード隔離
//rep系はインデックス、for系は中身
#define rep(...) over4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rer(...) over4(__VA_ARGS__,rer4,rer3,rer2,)(__VA_ARGS__)
//自分込みで残りがREM以上の間ループを回す
#define rem(i, N, REM) for (int i = 0; i < N - REM + 1; i++)
//char用のrep
#define repc(i, m, n) for(char i = m,repc3lim=n; i < repc3lim ; ++i)
//i,j,k...をnまで見る
#define reps(...) over5(__VA_ARGS__,reps5,reps4,reps3,reps2,)(__VA_ARGS__)
#define repss(...) over10(__VA_ARGS__, repss10, a, repss8, a, repss6, a, repss4, a, repss2) (__VA_ARGS__)
//vectorのindexを走査する
//repv(i,j,vvi)
#define repv(...) over6(__VA_ARGS__,repv_6,repv_5,repv_4,repv_3,repv_2,)(__VA_ARGS__)
#define rerv(i, A) for (int i = sz(A)-1; i >= 0 ; i--)
//repvn(dp) nは次元
#define repv1(a) repv(i, a)
#define repv2(a) repv(i, j, a)
#define repv3(a) repv(i, j, k, a)
#define repv4(a) repv(i, j, k, l, a)
#ifdef use_for
#define fora_f(...) over9(__VA_ARGS__, fora_f_9, fora_f_8, fora_f_7, fora_f_6, fora_f_5, fora_f_4, fora_f_3, fora_f_2)(__VA_ARGS__)
#endif
#define forr(...) over9(__VA_ARGS__, forr_9, forr_8, forr_7, forr_6, forr_5, forr_4, forr_3, forr_2)(__VA_ARGS__)
//0~N-2まで見る
#define forar_init(v, rv, A) auto &&v = A[forar_i]; auto && rv = A[forar_i+1];
#define forar(v, rv, A) rep(forar_i, sz(A) - 1)
#if __cplusplus >= 201703L
template<size_t M_SZ, bool indexed, class Iterator, class T, class U=T, class V=T, class W=T>
class ite_vec_merge : public Iterator { std::size_t i = 0; vector<T> &A; vector<U> &B; vector<V> &C; vector<W> &D;public : ite_vec_merge(Iterator ita, vector<T> &A) : Iterator(ita), A(A), B(A), C(A), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B) : Iterator(ita), A(A), B(B), C(A), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B, vector<V> &C) : Iterator(ita), A(A), B(B), C(C), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B, vector<V> &C, vector<W> &D) : Iterator(ita), A(A), B(B), C(C), D(D) {} auto &operator++() { ++i; this->Iterator::operator++(); return *this; } auto operator*() const noexcept { if constexpr(!indexed && M_SZ == 1) { return tuple<T &>(A[i]); } else if constexpr(!indexed && M_SZ == 2) { return tuple<T &, U &>(A[i], B[i]); } else if constexpr(!indexed && M_SZ == 3) { return tuple<T &, U &, V &>(A[i], B[i], C[i]); } else if constexpr(!indexed && M_SZ == 4) { return tuple<T &, U &, V &, W &>(A[i], B[i], C[i], D[i]); } else if constexpr(indexed && M_SZ == 1) { return tuple<int, T &>(i, A[i]); } else if constexpr(indexed && M_SZ == 2) { return tuple<int, T &, U &>(i, A[i], B[i]); } else if constexpr(indexed && M_SZ == 3) { return tuple<int, T &, U &, V &>(i, A[i], B[i], C[i]); } else if constexpr(indexed && M_SZ == 4) { return tuple<int, T &, U &, V &, W &>(i, A[i], B[i], C[i], D[i]); } else { assert(0); return tuple<int>(i); } }};
template<size_t M_SZ, bool indexed, class T, class U=T, class V=T, class W=T>
class vec_merge { vector<T> &a; vector<U> &b; vector<V> &c; vector<W> &d;public : vec_merge(vector<T> &a) : a(a), b(a), c(a), d(a) {} vec_merge(vector<T> &a, vector<U> &b) : a(a), b(b), c(a), d(a) {} vec_merge(vector<T> &a, vector<U> &b, vector<V> &c) : a(a), b(b), c(c), d(a) {} vec_merge(vector<T> &a, vector<U> &b, vector<V> &c, vector<W> &d) : a(a), b(b), c(c), d(d) {} auto begin() const { if constexpr(M_SZ == 1) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a}; } else if constexpr(M_SZ == 2) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b}; } else if constexpr(M_SZ == 3) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b, c}; } else if constexpr(M_SZ == 4) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b, c, d}; } else { assert(0); return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a}; } } auto end() const { if constexpr(M_SZ == 1) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a}; } else if constexpr(M_SZ == 2) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b}; } else if constexpr(M_SZ == 3) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b, c}; } else if constexpr(M_SZ == 4) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b, c, d}; } else { assert(0); return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a}; } }};
#endif
#define fora_2(a, A) for(auto&& a : A)
#if __cplusplus >= 201703L
#define fora_3(i, a, A) for(auto[i, a] : vec_merge<1, true, decl_t(A)>(A))
#define fora_4(a, b, A, B) for(auto[a, b] : vec_merge<2, false, decl_t(A), decl_t(B)>(A, B))
#define fora_5(i, a, b, A, B) for(auto[i, a, b] : vec_merge<2, true, decl_t(A), decl_t(B)>(A, B))
#define fora_6(a, b, c, A, B, C) for(auto[a, b, c] : vec_merge<3, false, decl_t(A), decl_t(B), decl_t(C)>(A, B, C))
#define fora_7(i, a, b, c, A, B, C) for(auto[i, a, b, c] : vec_merge<3, true, decl_t(A), decl_t(B), decl_t(C)>(A, B, C))
#define fora_8(a, b, c, d, A, B, C, D) for(auto[a, b, c, d] : vec_merge<4, false, decl_t(A), decl_t(B), decl_t(C), decl_t(D)>(A, B, C, D))
#define fora_9(i, a, b, c, d, A, B, C, D) for(auto[i, a, b, c, d] : vec_merge<4, true, decl_t(A), decl_t(B), decl_t(C), decl_t(D)>(A, B, C, D))
#endif
//構造化束縛ver
//1e5要素で40ms程度
//遅いときはfora_fを使う
#define fora(...) over9(__VA_ARGS__, fora_9, fora_8, fora_7, fora_6, fora_5, fora_4, fora_3, fora_2)(__VA_ARGS__)
//#define forr(v, a) for(auto&& v : makeReversedRange(a))
//参照を取らない
/*@formatter:off*/
#ifdef use_for
template<class U> vector<U> to1d(vector<U> &a) { return a; }
template<class U> auto to1d(vector<vector<U>> &a) { vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)res.push_back(a2); return res;}
template<class U> vector<U> to1d(vector<vector<vector<U>>> &a) { vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) res.push_back(a3); return res;}
template<class U> vector<U> to1d(vector<vector<vector<vector<U>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)res.push_back(a4); return res;}
template<class U> vector<U> to1d(vector<vector<vector<vector<vector<U>>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)for (auto &&a5 : a4)res.push_back(a5); return res;}
template<class U> vector<U> to1d(vector<vector<vector<vector<vector<vector<U>>>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)for (auto &&a5 : a4)for (auto &&a6 : a5)res.push_back(a6); return res;}
#define forv(a, b) for(auto a : to1d(b))
//インデックスを前後含めて走査
#define ring(i, s, len) for (int i = s, prev = (s == 0) ? len - 1 : s - 1, next = (s == len - 1) ? 0 : s + 1, cou = 0; cou < len; cou++, prev = i, i = next, next = (next == len - 1) ? 0 : next + 1)
//値と前後を見る
#define ringv(v, d) index_=0;for (auto prev = d[sz(d)-1],next= (int)d.size()>1?d[1]:d[0],v = d[0]; index_ < sz(d); index_++, prev = v, v = next, next = (index_>=sz(d)-1?d[0]:d[index_+1]))
// 左右をnext prevで見る 0の左と nの右
#define forlr(v, d, banpei_l, banpei_r) rep(forlr_i,sz(d))
#endif
#define form(...) over5(__VA_ARGS__,form5,form4,form3,form2,form1)(__VA_ARGS__)
#define forrm(...) over5(__VA_ARGS__,forrm5,forrm4,forrm3,forrm2,forrm1)(__VA_ARGS__)
#define fors(...) over4(__VA_ARGS__,fors4,fors3,fors2,fors1)(__VA_ARGS__)
#define forslr(...) over6(__VA_ARGS__,forslr6,forslr5,forslr4,forslr3)(__VA_ARGS__)
#define forp3(k, v, st) rep(forp_i,sz(st))
#define forp4(forp_i, k, v, st) rep(forp_i,sz(st))
#define forp(...) over4(__VA_ARGS__,forp4,forp3)(__VA_ARGS__)
//マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const double PI = 3.1415926535897932384626433832795029L;
constexpr bool ev(ll a) { return !(a & 1); }
constexpr bool od(ll a) { return (a & 1); }
//@拡張系 こう出来るべきというもの
//埋め込み 存在を意識せずに機能を増やされているもの
namespace std {
template<> class hash<std::pair<signed, signed>> { public:size_t operator()(const std::pair<signed, signed> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }};
template<> class hash<std::pair<ll, ll>> { public:/*大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断*/size_t operator()(const std::pair<ll, ll> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }};
}
//stream まとめ
/*@formatter:off*/
istream &operator>>(istream &iss, P &a) {iss >> a.first >> a.second;return iss;}
template<typename T> istream &operator>>(istream &iss, vector<T> &vec_) {for (T &x: vec_) iss >> x;return iss;}
template<class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) {os << p.fi << " " << p.se;return os;}
ostream &operator<<(ostream &os, T p) {os << p.f << " " << p.s << " " << p.t;return os;}
ostream &operator<<(ostream &os, F p) {os << p.a << " " << p.b << " " << p.c << " " << p.d;return os;}
template<typename T> ostream &operator<<(ostream &os, vector<T> &vec_) {for (ll i = 0; i < vec_.size(); ++i)os << vec_[i] << (i + 1 == vec_.size() ? "" : " ");return os;}
template<typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec_) {for (ll i = 0; i < vec_.size(); ++i) {for (ll j = 0; j < vec_[i].size(); ++j) { os << vec_[i][j] << " "; }os << endl;}return os;}
template<typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &m) {os << endl;for (auto &&v:m) os << v << endl;return os;}
template<class T> ostream &operator<<(ostream &os, set<T> s) { fora(v, s) { os << v << " "; } return os;}
template<class T> ostream &operator<<(ostream &os, mset<T> s) { fora(v, s) { os << v << " "; } return os;}
template<class T> ostream &operator<<(ostream &os, deque<T> a) { fora(v, a) { os << v << " "; } return os;}
ostream &operator<<(ostream &os, vector<vector<char>> &vec_) { rep(h, sz(vec_)) { rep(w, sz(vec_[0])) { os << vec_[h][w]; } os << endl; } return os;}
/*@formatter:off*/
//template<class T,class U>ostream &operator<<(ostream &os, vector<pair<T,U>>& a) {fora_f(v,a)os<<v<<endl;return os;}
template<typename W, typename H> void resize(W &vec_, const H head) { vec_.resize(head); }
template<typename W, typename H, typename ... T> void resize(W &vec_, const H &head, const T ... tail) {vec_.resize(head);for (auto &v: vec_)resize(v, tail...);}
//#define use_for_each //_each _all_of _any_of _none_of _find_if _rfind_if _contains _count_if _erase_if _entry_if
#ifdef use_for_each
//todo Atcoderの過去問がc++17に対応したら
#if __cplusplus >= 201703L
//for_each以外はconst & (呼び出し側のラムダも)
template<typename T, typename F> bool all_of2(const T &v, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : v) { if (!all_of2(v_, f))return false; } return true; } else { return f(v); }}
template<typename T, typename F> bool any_of2(const T &v, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : v) { if (!any_of2(v_, f))return true; } return false; } else { return f(v); }}
template<typename T, typename F> bool none_of2(const T &v, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : v) { if (none_of2(v_, f))return false; } return true; } else { return f(v); }}
//存在しない場合
//1次元 Nを返す
//多次元-1を返す
template<typename T, typename F> ll find_if2(const vector<T> &v, F f) { rep(i, sz(v)) { if (f(v[i]))return i; } return sz(v);}
template<typename T, typename F> tuple<int, int> find_if2(const vector<vector<T> > &v, F f) { rep(i, sz(v)) { rep(j, sz(v[i])) { if (f(v[i][j])) { return tuple<int, int>(i, j); }}} return tuple<int, int>(-1, -1);}
template<typename T, typename F> auto find_if2(const vector<vector<vector<T> > > &v, F f) { rep(i, sz(v)) { if (auto ret = find_if2(v[i], f); get<0>(ret) != -1) { return tuple_cat(tuple<int>(i), ret); }} auto bad = tuple_cat(tuple<int>(-1), find_if2(v[0], f)); return bad;}
//存在しない場合
//1次元 -1を返す
//多次元-1を返す
template<typename T, typename F> ll rfind_if2(const vector<T> &v, F f) { rer(i, sz(v) - 1) { if (f(v[i]))return i; } return -1;}
template<typename T, typename F> tuple<int, int> rfind_if2(const vector<vector<T> > &v, F f) { rer(i, sz(v) - 1) { rer(j, sz(v[i]) - 1) { if (f(v[i][j])) { return tuple<int, int>(i, j); }}} return tuple<int, int>(-1, -1);}
template<typename T, typename F> auto rfind_if2(const vector<vector<vector<T> > > &v, F f) { rer(i, sz(v) - 1) { if (auto ret = rfind_if2(v[i], f); get<0>(ret) != -1) { return tuple_cat(tuple<int>(i), ret); }} auto bad = tuple_cat(tuple<int>(-1), rfind_if2(v[0], f)); return bad;}
//todo まとめられそう string,vector全般
template<class T> bool contains(const string &s, const T &v) { return s.find(v) != string::npos; }
template<typename T> bool contains(const vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); }
template<typename T, typename F> bool contains_if2(const vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); }
template<typename T, typename F> ll count_if2(const T &v, F f) { if constexpr(has_value_type<T>::value) { ll ret = 0; for (auto &&v_ : v) { ret += count_if2(v_, f); } return ret; } else { return f(v); }}
template<typename T, typename F> void for_each2(T &a, F f) { if constexpr(has_value_type<T>::value) { for (auto &&v_ : a)for_each2(v_, f); } else { f(a); }}
#else
template<typename T, typename F> bool all_of2(const T &v, F f) { return f(v); }
template<typename T, typename F> bool all_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (!all_of2(v[i], f))return false; } return true;}
template<typename T, typename F> bool any_of2(const T &v, F f) { return f(v); }
template<typename T, typename F> bool any_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (any_of2(v[i], f))return true; } return false;}
template<typename T, typename F> bool none_of2(const T &v, F f) { return f(v); }
template<typename T, typename F> bool none_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (none_of2(v[i], f))return false; } return true;}
template<typename T, typename F> bool find_if2(const T &v, F f) { return f(v); }
template<typename T, typename F> ll find_if2(const vector<T> &v, F f) { rep(i, sz(v)) { if (find_if2(v[i], f))return i; } return sz(v);}
template<typename T, typename F> bool rfind_if2(const T &v, F f) { return f(v); }
template<typename T, typename F> ll rfind_if2(const vector<T> &v, F f) { rer(i, sz(v) - 1) { if (rfind_if2(v[i], f))return i; } return -1;}
template<class T> bool contains(const string &s, const T &v) { return s.find(v) != string::npos; }
template<typename T> bool contains(const vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); }
template<typename T, typename F> bool contains_if2(const vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); }
template<typename T, typename F> ll count_if2(const T &v, F f) { return f(v); }
template<typename T, typename F> ll count_if2(const vector<T> &vec_, F f) { ll ret = 0; fora(v, vec_) { ret += count_if2(v, f); } return ret;}
template<typename T, typename F> void for_each2(T &a, F f) {
f(a);
}
template<typename T, typename F> void for_each2(vector<T> &a, F f) {
for (auto &&v_ : a)for_each2(v_, f);
}
#endif
template<typename W> ll count_od(const vector<W> &a) { return count_if2(a, [](ll v) { return v & 1; }); }
template<typename W> ll count_ev(const vector<W> &a) { return count_if2(a, [](ll v) { return !(v & 1); }); }
//削除した後のvectorを返す
template<typename T, typename F> vector<T> erase_if2(const vector<T> &v, F f) { vector<T> nv; rep(i, sz(v)) { if (!f(v[i])) { nv.push_back(v[i]); }} return nv;}
template<typename T, typename F> vector<vector<T>> erase_if2(const vector<vector<T>> &v, F f) { vector<vector<T>> res; rep(i, sz(v)) { res[i] = erase_if2(v[i], f); } return res;}
template<typename T, typename F> vector<T> entry_if2(const vector<T> &v, F f) {vector<T> nv;rep(i, sz(v)) { if (f(v[i])) { nv.push_back(v[i]); }}return nv;}
template<typename T, typename F> vector<vector<T>> entry_if2(const vector<vector<T>> &v, F f) {vector<vector<T>> res;rep(i, sz(v)) { res[i] = entry_if2(v[i], f); }return res;}
template<typename T, typename F> ll l_rfind_if(const vector<T> &v, F f) {rer(i, sz(v) - 1) { if (f(v[i]))return i; }return -1;}
template<typename T, typename F> bool l_contains_if(const vector<T> &v, F f) {rer(i, sz(v) - 1) { if (f(v[i]))return true; }return false;}
template<class A, class B, class C> auto t_all_of(A a, B b, C c) { return std::all_of(a, b, c); }
template<class A, class B, class C> auto t_any_of(A a, B b, C c) { return std::any_of(a, b, c); }
template<class A, class B, class C> auto t_none_of(A a, B b, C c) { return std::none_of(a, b, c); }
template<class A, class B, class C> auto t_find_if(A a, B b, C c) { return std::find_if(a, b, c); }
template<class A, class B, class C> auto t_count_if(A a, B b, C c) { return std::count_if(a, b, c); }
#define all_of_s__2(a, right) (t_all_of(ALL(a),lamr(right)))
#define all_of_s__3(a, v, siki) (t_all_of(ALL(a),[&](auto v){return siki;}))
#define all_of_s(...) over3(__VA_ARGS__,all_of_s__3,all_of_s__2)(__VA_ARGS__)
//all_of(A, %2);
//all_of(A, a, a%2);
#define all_of__2(a, right) all_of2(a,lamr(right))
#define all_of__3(a, v, siki) all_of2(a,[&](auto v){return siki;})
#define all_of(...) over3(__VA_ARGS__,all_of__3,all_of__2)(__VA_ARGS__)
#define all_of_f(a, f) all_of2(a,f)
#define any_of_s__2(a, right) (t_any_of(ALL(a),lamr(right)))
#define any_of_s__3(a, v, siki) (t_any_of(ALL(a),[&](auto v){return siki;}))
#define any_of_s(...) over3(__VA_ARGS__,any_of_s__3,any_of_s__2)(__VA_ARGS__)
#define any_of__2(a, right) any_of2(a,lamr(right))
#define any_of__3(a, v, siki) any_of2(a,[&](auto v){return siki;})
#define any_of(...) over3(__VA_ARGS__,any_of__3,any_of__2)(__VA_ARGS__)
#define any_of_f(a, f) any_of2(a,f)
#define none_of_s__2(a, right) (t_none_of(ALL(a),lamr(right)))
#define none_of_s__3(a, v, siki) (t_none_of(ALL(a),[&](auto v){return siki;}))
#define none_of_s(...) over3(__VA_ARGS__,none_of_s__3,none_of_s__2)(__VA_ARGS__)
#define none_of__2(a, right) none_of2(a,lamr(right))
#define none_of__3(a, v, siki) none_of2(a,[&](auto v){return siki;})
#define none_of(...) over3(__VA_ARGS__,none_of__3,none_of__2)(__VA_ARGS__)
#define none_of_f(a, f) none_of2(a,f)
#define find_if_s__2(a, right) (t_find_if(ALL(a),lamr(right))-a.begin())
#define find_if_s__3(a, v, siki) (t_find_if(ALL(a),[&](auto v){return siki;})-a.begin())
#define find_if_s(...) over3(__VA_ARGS__,find_if_s__3,find_if_s__2)(__VA_ARGS__)
#define find_if__2(a, right) find_if2(a,lamr(right))
#define find_if__3(a, v, siki) find_if2(a,[&](auto v){return siki;})
#define find_if(...) over3(__VA_ARGS__,find_if__3,find_if__2)(__VA_ARGS__)
#define find_if_f(a, f) find_if2(a,f)
#define rfind_if_s__2(a, right) l_rfind_if(a, lamr(right))
#define rfind_if_s__3(a, v, siki) l_rfind_if(a, [&](auto v){return siki;})
#define rfind_if_s(...) over3(__VA_ARGS__,rfind_if_s__3,rfind_if_s__2)(__VA_ARGS__)
#define rfind_if__2(a, right) rfind_if2(a,lamr(right))
#define rfind_if__3(a, v, siki) rfind_if2(a,[&](auto v){return siki;})
#define rfind_if(...) over3(__VA_ARGS__,rfind_if__3,rfind_if__2)(__VA_ARGS__)
#define rfind_if_f(a, f) rfind_if2(a,f)
#define contains_if_s__2(a, right) l_contains_if(a, lamr(right))
#define contains_if_s__3(a, v, siki) l_contains_if(a, [&](auto v){return siki;})
#define contains_if_s(...) over3(__VA_ARGS__,contains_if_s__3,contains_if_s__2)(__VA_ARGS__)
#define contains_if__2(a, right) contains_if2(a,lamr(right))
#define contains_if__3(a, v, siki) contains_if2(a,[&](auto v){return siki;})
#define contains_if(...) over3(__VA_ARGS__,contains_if__3,contains_if__2)(__VA_ARGS__)
#define contains_if_f(a, f) contains_if2(a,f)
#define count_if_s__2(a, right) (t_count_if(ALL(a),lamr(right)))
#define count_if_s__3(a, v, siki) (t_count_if(ALL(a),[&](auto v){return siki;}))
#define count_if_s(...) over3(__VA_ARGS__,count_if_s__3,count_if_s__2)(__VA_ARGS__)
#define count_if__2(a, right) count_if2(a,lamr(right))
#define count_if__3(a, v, siki) count_if2(a,[&](auto v){return siki;})
#define count_if(...) over3(__VA_ARGS__,count_if__3,count_if__2)(__VA_ARGS__)
#define count_if_f(a, f) count_if2(a,f)
//vector<vi>で、viに対して操作
#define for_each_s__2(a, right) do{fora(v,a){v right;}}while(0)
#define for_each_s__3(a, v, shori) do{fora(v,a){shori;}}while(0)
#define for_each_s(...) over3(__VA_ARGS__,for_each_s__3,for_each_s__2)(__VA_ARGS__)
//vector<vi>で、intに対して操作
#define for_each__2(a, right) for_each2(a,lamr(right))
#define for_each__3(a, v, shori) for_each2(a,[&](auto& v){shori;})
#define for_each(...) over3(__VA_ARGS__,for_each__3,for_each__2)(__VA_ARGS__)
#define for_each_f(a, f) for_each2(a, f);
template<class T, class F> vector<T> help_for_eached(const vector<T> &A, F f) { vector<T> ret = A; for_each(ret, v, f(v)); return ret;}
#define for_eached__2(a, right) help_for_eached(a, lamr(right))
#define for_eached__3(a, v, shori) help_for_eached(a, lam(v, shori))
#define for_eached(...) over3(__VA_ARGS__,for_eached__3,for_eached__2)(__VA_ARGS__)
#define for_eached_f(a, f) for_eached2(a, f);
#define each for_each
#define eached for_eached
//#define erase_if_s__2(a, right) l_erase_if2(a,lamr(right))
//#define erase_if_s__3(a, v, siki) l_erase_if2(a,[&](auto v){return siki;})
//#define erase_if_s(...) over3(__VA_ARGS__,erase_if_s__3,erase_if_s__2)(__VA_ARGS__)
#define erase_if__2(a, right) erase_if2(a,lamr(right))
#define erase_if__3(a, v, siki) erase_if2(a,[&](auto v){return siki;})
#define erase_if(...) over3(__VA_ARGS__,erase_if__3,erase_if__2)(__VA_ARGS__)
#define erase_if_f(a, f) erase_if2(a,f)
//#define entry_if_s__2(a, right) l_entry_if2(a,lamr(right))
//#define entry_if_s__3(a, v, siki) l_entry_if2(a,[&](auto v){return siki;})
//#define entry_if_s(...) over3(__VA_ARGS__,entry_if_s__3,entry_if_s__2)(__VA_ARGS__)
#define entry_if__2(a, right) entry_if2(a,lamr(right))
#define entry_if__3(a, v, siki) entry_if2(a,[&](auto v){return siki;})
#define entry_if(...) over3(__VA_ARGS__,entry_if__3,entry_if__2)(__VA_ARGS__)
#define entry_if_f(a, f) entry_if2(a,f)
#endif
/*@formatter:off*/
template<class T, class U, class W> void replace(vector<W> &a, T key, U v) { rep(i, sz(a))if (a[i] == key)a[i] = v; }
template<class T, class U, class W> void replace(vector<vector<W>> &A, T key, U v) { rep(i, sz(A))replace(A[i], key, v); }
void replace(str &a, char key, str v) { if (v == "")a.erase(remove(ALL(a), key), a.end()); }
void replace(str &a, char key, char v) { replace(ALL(a), key, v); }
//keyと同じかどうか01で置き換える
template<class T, class U> void replace(vector<T> &a, U k) { rep(i, sz(a)) a[i] = a[i] == k; }
template<class T, class U> void replace(vector<vector<T >> &a, U k) { rep(i, sz(a))rep(j, sz(a[0])) a[i][j] = a[i][j] == k; }
void replace(str &a) { int dec = 0; if ('a' <= a[0] && a[0] <= 'z')dec = 'a'; if ('A' <= a[0] && a[0] <= 'Z')dec = 'A'; fora(v, a) { v -= dec; }}
void replace(str &a, str key, str v) { stringstream t; ll kn = sz(key); std::string::size_type Pos(a.find(key)); ll l = 0; while (Pos != std::string::npos) { t << a.substr(l, Pos - l); t << v; l = Pos + kn; Pos = a.find(key, Pos + kn); } t << a.substr(l, sz(a) - l); a = t.str();}
template<class T> bool is_permutation(vector<T> &a, vector<T> &b) { return is_permutation(ALL(a), ALL(b)); }
template<class T> bool next_permutation(vector<T> &a) { return next_permutation(ALL(a)); }
vi iota(ll s, ll len) {vi ve(len);iota(ALL(ve), s);return ve;}
template<class A, class B> auto vtop(vector<A> &a, vector<B> &b) { assert(sz(a) == sz(b)); /*stringを0で初期化できない */ vector<pair<A, B>> res; rep(i, sz(a))res.eb(a[i], b[i]); return res;}
template<class A, class B> void ptov(vector<pair<A, B>> &p, vector<A> &a, vector<B> &b) { a.resize(sz(p)), b.resize(sz(p)); rep(i, sz(p))a[i] = p[i].fi, b[i] = p[i].se;}
template<class A, class B, class C> auto vtot(vector<A> &a, vector<B> &b, vector<C> &c) { assert(sz(a) == sz(b) && sz(b) == sz(c)); vector<T2<A, B, C>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i]); return res;}
template<class A, class B, class C, class D> auto vtof(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { assert(sz(a) == sz(b) && sz(b) == sz(c) && sz(c) == sz(d)); vector<F2<A, B, C, D>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i], d[i]); return res;}
/*@formatter:off*/
template<class T> void sort(vector<T> &a, int l = -1, int r = -1) { set_lr12(l, r, sz(a)); fast_sort(a.begin() + l, a.begin() + r);}
template<class T> void rsort(vector<T> &a, int l = -1, int r = -1) { set_lr12(l, r, sz(a)); fast_sort(a.begin() + l, a.begin() + r, greater<T>());};
template<class A, class B> void sortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); sort(c); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}
template<class A, class B> void rsortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); rsort(c); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;}
template<class A, class B, class C> void sortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); sort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class A, class B, class C> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); rsort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class... T, class U> auto sorted(U head, T... a) { sort(head, a...); return head;}
template<class... T, class U> auto rsorted(U head, T... a) {rsort(head, a...);return head;}
//sortindex 元のvectorはソートしない
template<class T> vi sorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind); return ind;}
//#define use_sort
#ifdef use_sort
enum pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd };
enum tcomparator { fisiti, fisitd, fisdti, fisdtd, fdsiti, fdsitd, fdsdti, fdsdtd, fitisi, fitisd, fitdsi, fitdsd, fdtisi, fdtisd, fdtdsi, fdtdsd, sifiti, sifitd, sifdti, sifdtd, sdfiti, sdfitd, sdfdti, sdfdtd, sitifi, sitifd, sitdfi, sitdfd, sdtifi, sdtifd, sdtdfi, sdfdfd, tifisi, tifisd, tifdsi, tifdsd, tdfisi, tdfisd, tdfdsi, tdfdsd, tisifi, tisifd, tisdfi, tisdfd, tdsifi, tdsifd, tdsdfi, tdsdfd};
template<class A, class B> void sort(vector<pair<A, B>> &a, pcomparator type) {typedef pair<A, B> U;if (type == fisi) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; }); else if (type == fisd) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; }); else if (type == fdsi) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; }); else if (type == fdsd) sort(ALL(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; }); else if (type == sifi) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; }); else if (type == sifd) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; }); else if (type == sdfi) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; }); else if (type == sdfd) sort(ALL(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });};
template<class U> void sort(vector<U> &a, pcomparator type) { if (type == fisi) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == fisd) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == fdsi) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == fdsd) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == sifi) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == sifd) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == sdfi) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == sdfd) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f > r.f; }); };
template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D> > &a, pcomparator type) {typedef F2<A, B, C, D> U;if (type == fisi) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == fisd) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == fdsi) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == fdsd) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == sifi) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == sifd) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == sdfi) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == sdfd) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a > r.a; });};
template<class U> void sort(vector<U> &a, tcomparator type) {if (type == 0) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 1) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 2) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 3) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 4) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 5) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 6) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 7) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 8) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 9) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 10) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 11) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 12) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 13) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 14) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 15) sort(ALL(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 16) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 17) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 18) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 19) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 20) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 21) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 22) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 23) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 24) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 25) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 26) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 27) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 28) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 29) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 30) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 31) sort(ALL(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 32) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 33) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 34) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 35) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 36) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 37) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 38) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 39) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 40) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 41) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 42) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 43) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f > r.f; }); else if (type == 44) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 45) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 46) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 47) sort(ALL(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f > r.f; });}
template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D>> &a, tcomparator type) { typedef F2<A, B, C, D> U; if (type == 0) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 1) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 2) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 3) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 4) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 5) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 6) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 7) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 8) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 9) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 10) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 11) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 12) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 13) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 14) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 15) sort(ALL(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 16) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 17) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 18) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 19) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 20) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 21) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 22) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 23) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 24) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 25) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 26) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 27) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 28) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 29) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 30) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 31) sort(ALL(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 32) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 33) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 34) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 35) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 36) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 37) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 38) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 39) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 40) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 41) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 42) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 43) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a > r.a; }); else if (type == 44) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 45) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 46) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 47) sort(ALL(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a > r.a; });}
/*@formatter:off*/
void sort(string &a) { sort(ALL(a)); }
void rsort(string &a) { sort(RALL(a)); }
void sort(int &a, int &b) { if (a > b)swap(a, b); }
void sort(int &a, int &b, int &c) { sort(a, b); sort(a, c); sort(b, c);}
void rsort(int &a, int &b) { if (a < b)swap(a, b); }
void rsort(int &a, int &b, int &c) { rsort(a, b); rsort(a, c); rsort(b, c);}
//P l, P rで f(P) の形で渡す
template<class U, class F> void sort(vector<U> &a, F f) { sort(ALL(a), [&](U l, U r) { return f(l) < f(r); }); };
template<class U, class F> void rsort(vector<U> &a, F f) { sort(ALL(a), [&](U l, U r) { return f(l) > f(r); }); };
//F = T<T>
//例えばreturn p.fi + p.se;
template<class A, class B, class F> void sortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); sort(c, f); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}
template<class A, class B, class F> void rsortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); rsort(c, f); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;}
template<class A, class B, class C, class F> void sortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); sort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class A, class B, class C, class F> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); rsort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;}
template<class A, class B, class C, class D> void sortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); sort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;}
template<class A, class B, class C, class D> void rsortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); rsort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;}
/*indexの分で型が変わるためpcomparatorが必要*/
template<class T> vi sorti(vector<T> &a, pcomparator f) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind, f); return ind;}
template<class T, class F> vi sorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(a[x]) < f(a[y]); }); return ind;}
template<class T> vi rsorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); rsortp(b, ind); return ind;}
template<class T, class F> vi rsorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(a[x]) > f(a[y]); }); return ind;}
template<class A, class B, class F> vi sortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(c[x]) < f(c[y]); }); return ind;}
template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b, pcomparator f) { vi ind = iota(0, sz(a)); auto c = a; auto d = b; sortt(c, d, ind, f); return ind;}
template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fisi); };
template<class A, class B, class F> vi rsortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(c[x]) > f(c[y]); }); return ind;}
template<class A, class B> vi rsortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fdsd); };
template<class A, class B, class C, class F> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(d[x]) < f(d[y]); }); return ind;}
template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, pcomparator f) { vi ind = iota(0, sz(a)); auto d = vtof(a, b, c, ind); sort(d, f); rep(i, sz(a))ind[i] = d[i].d; return ind;}
template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] < c[y]; else return b[x] < b[y]; } else { return a[x] < a[y]; }}); return ind;}
template<class A, class B, class C, class F> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { return f(d[x]) > f(d[y]); }); return ind;}
template<class A, class B, class C> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(ALL(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] > c[y]; else return b[x] > b[y]; } else { return a[x] > a[y]; }}); return ind;}
template<class T> void sort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)sort(a[i]); }
template<class T> void rsort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)rsort(a[i]); }
#endif
template<class T> bool includes(vector<T> &a, vector<T> &b) { vi c = a; vi d = b; sort(c); sort(d); return includes(ALL(c), ALL(d));}
template<class T> bool distinct(const vector<T> &A) { if ((int) (A).size() == 1)return true; if ((int) (A).size() == 2)return A[0] != A[1]; if ((int) (A).size() == 3)return (A[0] != A[1] && A[1] != A[2] && A[0] != A[2]); auto B = A; sort(B); int N = (B.size()); unique(B); return N == (int) (B.size());}
template<class H, class... T> bool distinct(const H &a, const T &...b) { return distinct(vector<H>{a, b...}); }
/*@formatter:off*/
template<typename W, typename T> void fill(W &xx, const T vall) { xx = vall; }
template<typename W, typename T> void fill(vector<W> &vecc, const T vall) { for (auto &&vx : vecc)fill(vx, vall); }
template<typename W, typename T> void fill(vector<W> &xx, const T v, ll len) { rep(i, len)xx[i] = v; }
template<typename W, typename T> void fill(vector<W> &xx, const T v, int s, ll t) { rep(i, s, t)xx[i] = v; }
template<typename W, typename T> void fill(vector<vector<W>> &xx, T v, int sh, int th, int sw, int tw) { rep(h, sh, th)rep(w, sw, tw)xx[h][w] = v; }
//#define use_fill //_sum _array _max _min
#ifdef use_fill
template<typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) { rep(i, N)a[i] = v; }
template<typename A, size_t N, size_t O, typename T> void fill(A (&a)[N][O], const T &v) { rep(i, N)rep(j, O)a[i][j] = v; }
template<typename A, size_t N, size_t O, size_t P, typename T> void fill(A (&a)[N][O][P], const T &v) { rep(i, N)rep(j, O)rep(k, P)a[i][j][k] = v; }
template<typename A, size_t N, size_t O, size_t P, size_t Q, typename T> void fill(A (&a)[N][O][P][Q], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)a[i][j][k][l] = v; }
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, typename T> void fill(A (&a)[N][O][P][Q][R], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)a[i][j][k][l][m] = v; }
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S, typename T> void fill(A (&a)[N][O][P][Q][R][S], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)a[i][j][k][l][m][n] = v; }
template<class T, class U> void fill(vector<T> &a, const vi &ind, U val) { fora(v, ind) { a[v] = val; }}
template<typename A, size_t N> A sum(A (&a)[N]) {A res = 0; rep(i, N)res += a[i]; return res;}
template<typename A, size_t N, size_t O> A sum(A (&a)[N][O]) {A res = 0; rep(i, N)rep(j, O)res += a[i][j]; return res;}
template<typename A, size_t N, size_t O, size_t P> A sum(A (&a)[N][O][P]) {A res = 0; rep(i, N)rep(j, O)rep(k, P)res += a[i][j][k]; return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q> A sum(A (&a)[N][O][P][Q]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)res += a[i][j][k][l]; return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A sum(A (&a)[N][O][P][Q][R]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)res += a[i][j][k][l][m]; return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A sum(A (&a)[N][O][P][Q][R][S]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)res += a[i][j][k][l][m][n]; return res;}
template<typename A, size_t N> A max(A (&a)[N]) {A res = a[0]; rep(i, N)res = max(res, a[i]); return res;}
template<typename A, size_t N, size_t O> A max(A (&a)[N][O]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q> A max(A (&a)[N][O][P][Q], const T &v) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A max(A (&a)[N][O][P][Q][R]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A max(A (&a)[N][O][P][Q][R][S]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}
template<typename A, size_t N> A min(A (&a)[N]) { A res = a[0]; rep(i, N)res = min(res, a[i]); return res;}
template<typename A, size_t N, size_t O> A min(A (&a)[N][O]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q> A min(A (&a)[N][O][P][Q], const T &v) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A min(A (&a)[N][O][P][Q][R]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A min(A (&a)[N][O][P][Q][R][S]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}
#endif
/*@formatter:off*/
template<class T, class U> void inc(pair<T, U> &a, U v = 1) { a.first += v, a.second += v; }
template<class T, class U> void inc(T &a, U v = 1) { a += v; }
template<class T, class U = int> void inc(vector<T> &a, U v = 1) { for (auto &u:a)inc(u, v); }
template<class T, class U> void dec(T &a, U v = 1) { a -= v; }
template<class T, class U = int> void dec(vector<T> &a, U v = 1) { for (auto &u :a)dec(u, v); }
template<class U> void dec(string &a, U v = 1) { for (auto &u :a)dec(u, v); }
template<class T, class U, class W> void dec(vector<T> &a, vector<U> &b, W v = 1) {for (auto &u :a)dec(u, v);for (auto &u :b)dec(u, v);}
template<class T, class U, class W> void dec(vector<T> &a, vector<U> &b, vector<W> &c) { for (auto &u :a)dec(u, 1); for (auto &u :b)dec(u, 1); for (auto &u :c)dec(u, 1);}
bool ins(ll h, ll w, ll H, ll W) { return h >= 0 && w >= 0 && h < H && w < W; }
bool san(ll l, ll v, ll r) { return l <= v && v < r; }
template<class T> bool ins(vector<T> &a, ll i, ll j = 0) { return san(0, i, sz(a)) && san(0, j, sz(a)); }
#define inside ins
ll u0(ll a) { return a < 0 ? 0 : a; }
template<class T> vector<T> u0(vector<T> &a) { vector<T> ret = a; fora(v, ret) { v = u(v); } return ret;}
//todo 名前
bool d_(int a, int b) {if (b == 0)return false;return (a % b) == 0;}
//エラー
void ole() {
#ifdef _DEBUG
cerr << "ole" << endl;exit(0);
#endif
string a = "a"; rep(i, 30)a += a; rep(i, 1 << 17)cout << a << endl; cout << "OLE 出力長制限超過" << endl;exit(0);
}
void re(string s = "") {cerr << s << endl;assert(0 == 1);exit(0);}
void tle() { while (inf)cout << inf << endl; }
//@汎用便利関数 入力
ll in() {ll ret;cin >> ret;return ret;}
template<class T> T in() { T ret; cin >> ret; return ret;}
string sin() { string ret; cin >> ret; return ret;}
template<class T> void in(T &head) { cin >> head; }
template<class T, class... U> void in(T &head, U &... tail) { cin >> head; in(tail...);}
//value_typeを持つ場合呼べる
//len回要素を追加する
template<class Iterable, class T = typename Iterable::value_type> Iterable tin(int len) { Iterable ret; T tem; while (len--) { cin >> tem; ret += tem; } return ret;}
template<class T> T tin() { T ret; cin >> ret; return ret;}
template<class T> T tind(int len = 0) { auto ret = tin<T>(len); dec(ret, 1); return ret;}
#define din_t2(type, a) type a;cin>>a
#define din_t3(type, a, b) type a,b;cin>>a>> b
#define din_t4(type, a, b, c) type a,b,c;cin>>a>>b>>c
#define din_t5(type, a, b, c, d) type a,b,c,d;cin>>a>>b>>c>>d
#define din_t6(type, a, b, c, d, e) type a,b,c,d,e;cin>>a>>b>>c>>d>>e
#define din_t7(type, a, b, c, d, e, f) type a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f
#define din_t(...) over7(__VA_ARGS__,din_t7,din_t6,din_t5,din_t4,din_t3 ,din_t2)(__VA_ARGS__)
#define din(...) din_t(int,__VA_ARGS__)
#define d_in
#define dsig(...) din_t(signed,__VA_ARGS__)
#define dst(...) din_t(string,__VA_ARGS__)
#define dstr dst
#define d_str dst
#define dcha(...) din_t(char,__VA_ARGS__)
#define dchar dcha
#define ddou(...) din_t(double,__VA_ARGS__)
#define din1d(a) din_t2(int, a);a--
#define din2d(a, b) din_t3(int, a,b);a--,b--
#define din3d(a, b, c) din_t4(int, a,b,c);a--,b--,c--
#define din4d(a, b, c, d) din_t5(int, a,b,c,d);a--,b--,c--,d--
#define dind(...) over4(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__)
/*@formatter:off*/
#ifdef _DEBUG
template<class T> void err2(T &&head) { cerr << head; }
template<class T, class... U> void err2(T &&head, U &&... tail) { cerr << head << " "; err2(tail...);}
template<class T, class... U> void err(T &&head, U &&... tail) { cerr << head << " "; err2(tail...); cerr << "" << endl;}
template<class T> void err(T &&head) { cerr << head << endl; }
void err() { cerr << "" << endl; }
//debで出力する最大長
constexpr int DEB_LEN = 20;
constexpr int DEB_LEN_H = 12;
string deb_tos(const int &v) { if (abs(v) == inf || abs(v) == linf)return "e"; else return to_string(v); }
template<class T> string deb_tos(const T &a) {stringstream ss;ss << a;return ss.str();}
#ifdef use_epsdou
string deb_tos(const epsdou &a) {return deb_tos(a.v);}
#endif
template<class T> string deb_tos(const optional<T> &a) { if (a.has_value()) { return deb_tos(a.value()); } else return "e"; }
template<class T> string deb_tos(const vector<T> &a, ll W = inf) { stringstream ss; if (W == inf)W = min(sz(a), DEB_LEN); if (sz(a) == 0)return ss.str(); rep(i, W) { ss << deb_tos(a[i]); if (typeid(a[i]) == typeid(P)) { ss << endl; } else { ss << " "; } } return ss.str();}
template<class T> string deb_tos(const vector<vector<T> > &a, vi H, vi W, int key = -1) { stringstream ss; ss << endl; vi lens(sz(W)); fora(h, H) { rep(wi, sz(W)) { lens[wi] = max(lens[wi], sz(deb_tos(a[h][W[wi]])) + 1); lens[wi] = max(lens[wi], sz(deb_tos(W[wi])) + 1); } } if (key == -1)ss << " *|"; else ss << " " << key << "|"; int wi = 0; fora(w, W) { ss << std::right << std::setw(lens[wi]) << w; wi++; } ss << "" << endl; rep(i, sz(W))rep(lens[i])ss << "_"; rep(i, 3)ss << "_"; ss << "" << endl; fora(h, H) { ss << std::right << std::setw(2) << h << "|"; int wi = 0; fora(w, W) { ss << std::right << std::setw(lens[wi]) << deb_tos(a[h][w]); wi++; } ss << "" << endl; } return ss.str();}
template<class T> string deb_tos(const vector<vector<T> > &a, ll H = inf, ll W = inf, int key = -1) { H = (H != inf) ? H : min({H, sz(a), DEB_LEN_H}); W = min({W, sz(a[0]), DEB_LEN_H}); vi hs, ws; rep(h, H) { hs.push_back(h); } rep(w, W) { ws.push_back(w); } return deb_tos(a, hs, ws, key);}
template<class T> string deb_tos(const vector<vector<vector<T> > > &a, ll H = inf) { stringstream ss; if (H == inf)H = DEB_LEN_H; H = min(H, sz(a)); rep(i, H) { ss << endl; ss << deb_tos(a[i], inf, inf, i); } return ss.str();}
template<class T> string deb_tos(vector<set<T> > &a, ll H = inf, ll W = inf, int key = -1) { vector<vector<T> > b(sz(a)); rep(i, sz(a)) { fora(v, a[i]) { b[i].push_back(v); }} return deb_tos(b, H, W, key);}
template<class T, size_t A> string deb_tos(T (&a)[A]) { return deb_tos(vector<T>(begin(a), end(a))); }
template<class T, size_t A, size_t B> string deb_tos(T (&a)[A][B]) { return deb_tos(vector<vector<T> >(begin(a), end(a))); }
template<class T, size_t A, size_t B, size_t C> string deb_tos(T (&a)[A][B][C]) { return deb_tos(vector<vector<vector<T> > >(begin(a), end(a))); }
/*@formatter:off*/
template<class T> void out2(T head) { cout << head; res_mes += deb_tos(head);}
template<class T, class... U> void out2(T head, U ... tail) { cout << head << " "; res_mes += deb_tos(head) + " "; out2(tail...);}
template<class T, class... U> void out(T head, U ... tail) { cout << head << " "; res_mes += deb_tos(head) + " "; out2(tail...); cout << "" << endl; res_mes += "\n";}
template<class T> void out(T head) { cout << head << endl; res_mes += deb_tos(head) + "\n";}
void out() { cout << "" << endl; }
#else
#define err(...);
template<class T> void out2(T &&head) { cout << head; }
template<class T, class... U> void out2(T &&head, U &&... tail) { cout << head << " "; out2(tail...);}
template<class T, class... U> void out(T &&head, U &&... tail) { cout << head << " "; out2(tail...); cout << "" << endl;}
template<class T> void out(T &&head) { cout << head << endl;}
void out() { cout << "" << endl;}
#endif
template<class T> void outl(const vector<T> &a, int n = inf) { rep(i, min(n, sz(a)))cout << a[i] << endl; }
//テーブルをスペースなしで出力
template<class T> void outt(vector<vector<T>> &a) { rep(i, sz(a)) { rep(j, sz(a[i])) { cout << a[i][j]; } cout << endl; }}
//int型をbit表記で出力
void outb(int a) { cout << bitset<20>(a) << endl; }
/*@formatter:off*/
template<class T> void na(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i];}
template<class T> void na(set<T> &a, ll n) { rep(i, n)a.insert(in()); }
#define dna(a, n) vi a; na(a, n);/*nを複数使うと n==in()の時バグる事に注意*/
#define dnad(a, n) vi a; nad(a, n);
template<class T> void nao(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1];}
template<class T> void naod(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1], a[i + 1]--;}
template<class T> void nad(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i], a[i]--;}
template<class T> void nad(set<T> &a, ll n) { rep(i, n)a.insert(in() - 1); }
template<class T, class U> void na2(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i];}
template<class T, class U> void na2(set<T> &a, set<U> &b, ll n) { rep(i, n) { a.insert(in()); b.insert(in()); }}
#define dna2(a, b, n) vi a,b; na2(a,b,n);
template<class T, class U> void nao2(vector<T> &a, vector<U> &b, ll n) { a.resize(n + 1); b.resize(n + 1); a[0] = b[0] = 0; rep(i, n)cin >> a[i + 1] >> b[i + 1];}
template<class T, class U> void na2d(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i], a[i]--, b[i]--;}
#define dna2d(a, b, n) vi a,b; na2d(a,b,n);
template<class T, class U, class W> void na3(vector<T> &a, vector<U> &b, vector<W> &c, ll n) {a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i];}
#define dna3(a, b, c, n) vi a,b,c; na3(a,b,c,n);
template<class T, class U, class W> void na3d(vector<T> &a, vector<U> &b, vector<W> &c, ll n) {a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--, c[i]--;}
#define dna3d(a, b, c, n) vi a,b,c; na3d(a,b,c,n);
template<class T, class U, class W, class X> void na4(vector<T> &a, vector<U> &b, vector<W> &c, vector<X> &d, ll n) {a.resize(n); b.resize(n); c.resize(n); d.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i] >> d[i];}
#define dna4(a, b, c, d, n) vi a,b,c,d; na4(a,b,c,d,n);
#define dna4d(a, b, c, d, n) vi a,b,c,d; na4d(a,b,c,d,n);
#define nt(a, h, w) resize(a,h,w);rep(nthi,h)rep(ntwi,w) cin >> a[nthi][ntwi];
#define ntd(a, h, w) resize(a,h,w);rep(ntdhi,h)rep(ntdwi,w) cin >> a[ntdhi][ntdwi], a[ntdhi][ntdwi]--;
#define ntp(a, h, w) resize(a,h+2,w+2);fill(a,'#');rep(ntphi,1,h+1)rep(ntpwi,1,w+1) cin >> a[ntphi][ntpwi];
#define dnt(S, h, w) vvi(S,h,w);nt(S,h,w);
#define dntc(S, h, w) vvc(S,h,w);nt(S,h,w);
#define dnts(S, h, w) vvs(S,h,w);nt(S,h,w);
//デバッグ
#define sp << " " <<
/*@formatter:off*/
#define deb1(x) debugName(x)<<" = "<<deb_tos(x)
#define deb_2(x, ...) deb1(x) <<", "<< deb1(__VA_ARGS__)
#define deb_3(x, ...) deb1(x) <<", "<< deb_2(__VA_ARGS__)
#define deb_4(x, ...) deb1(x) <<", "<< deb_3(__VA_ARGS__)
#define deb5(x, ...) deb1(x) <<", "<< deb_4(__VA_ARGS__)
#define deb6(x, ...) deb1(x) <<", "<< deb5(__VA_ARGS__)
//#define deb7(x, ...) deb1(x) <<", "<< deb6(__VA_ARGS__)
//#define deb8(x, ...) deb1(x) <<", "<< deb7(__VA_ARGS__)
//#define deb9(x, ...) deb1(x) <<", "<< deb8(__VA_ARGS__)
//#define deb10(x, ...) deb1(x) <<", "<< deb9(__VA_ARGS__)
/*@formatter:off*/
#ifdef _DEBUG
bool was_deb = false;
#define deb(...) do{was_deb=true;cerr<< over10(__VA_ARGS__,deb10,deb9,deb8,deb7,deb6,deb5,deb_4,deb_3,deb_2,deb1)(__VA_ARGS__) <<endl;}while(0)
#define base_keta 8
void print_n_base(int x, int base) { cerr << bitset<base_keta>(x) << endl; }
template<class T> void print_n_base(vector<T> X, int base) {cerr << endl; for (auto &&x:X) { print_n_base(x, base); } cerr << endl;}
//n進数
#define deb2(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 2);
#define deb3(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 3);
#define deb4(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 4);
#define deb_ex_deb(x, len) debugName(x)<<" = "<<deb_tos(x, len)
#define call_deb_ex_deb(x, len) deb_ex_deb(x, len)
//要素が存在する行だけ出力(vvt)
#define deb_ex(v) do {int N = sz(v);int s = N;int t = 0;rep(i, N) {if (sz(v[i])) {chmi(s, i);chma(t, i);}}auto ex_v = sub(v, s, N);str S = deb_tos(ex_v, sz(ex_v));debugName(v);cerr<<" = "<<endl;cerr << S << endl;} while (0);
#define debi(A) {int len=min(sz(A),20); was_deb=true;cerr<<debugName(A)<<" = "<<endl;rep(i, len)cerr<<std::right << std::setw((int)(sz(tos(A[i]))+(i ? 1 : 0)))<<(i%10);cerr<<endl;rep(i, len)cerr<<std::right << std::setw((int)(sz(tos(A[i]))+(i ? 1 : 0)))<<A[i];cerr<<endl;}
template<class T, class F> string deb_tos_f(vector<vector<T> > &a, F f, int key = -1) {vi hs, ws_; int H = sz(a), W = sz(a[0]); vi exh(H), exw(W); rep(h, H) { rep(w, W) { if (f(a[h][w])) { exh[h] = true; exw[w] = true; } } } rep(h, H) if (exh[h])hs.push_back(h); rep(w, W) if (exw[w])ws_.push_back(w); return deb_tos(a, hs, ws_, key);}
template<class T, class F> string deb_tos_f(vector<vector<vector<T>>> &a, F f) {stringstream ss; int H = sz(a); if (sz(a) == 0)return ss.str(); rep(i, H) { ss << deb_tos_f(a[i], f, i); } ss << "" << endl; return ss.str();}
#define debf_normal(tab, f) do{cerr<<debugName(tab)<<" = "<<endl;cerr<< deb_tos_f(tab, f)<<endl;}while(0);
#define debf2(tab, siki_r) debf_normal(tab, lamr(siki_r))
#define debf3(tab, v, siki) debf_normal(tab, lam(siki))
//S, sikir
//S, v, siki
#define debf(...) over3(__VA_ARGS__,debf3,debf2,debf1)(__VA_ARGS__)
#else
#define deb(...) ;
#define deb2(...) ;
#define deb3(...) ;
#define deb4(...) ;
#define deb_ex(...) ;
#define debf(...) ;
#define debi(...) ;
#endif
#define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'
/*@formatter:off*/
using u32 = unsigned;
using u64 = unsigned long long;
using u128 = __uint128_t;
using bint =__int128;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {std::ostream::sentry s(dest);if (s) {__uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } ll len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } }return dest;}
__int128 to_bint(string &s) {__int128 ret = 0; for (ll i = 0; i < (ll) s.length(); ++i) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret;}
void operator>>(istream &iss, bint &v) {string S; iss >> S; v = 0; rep(i, sz(S)) { v *= 10; v += S[i] - '0'; }}
//便利関数
/*@formatter:off*/
//テスト用
#define rand xor128_
unsigned long xor128_(void) {static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t; t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));}
char ranc() { return (char) ('a' + rand() % 26); }
ll rand(ll min, ll max) {assert(min <= max); if (min >= 0 && max >= 0) { return rand() % (max + 1 - min) + min; } else if (max < 0) { return -rand(-max, -min); } else { if (rand() % 2) { return rand(0, max); } else { return -rand(0, -min); }}}
ll rand(ll max) { return rand(0, max); }
template<class T> T rand(vector<T> &A) { return A[rand(sz(A) - 1)]; }
//重複することがある
template<class T> vector<T> ranv(vector<T> &A, int N) {vector<T> ret(N); rep(i, N) { ret[i] = rand(A); } return ret;}
template<class T> vector<T> ranv_unique(vector<T> &A, int N) {vector<T> ret(N); umapi was; rep(j, N) { int i; while (1) { i = rand(sz(A) - 1); if (was.find(i) == was.end())break; } ret[j] = A[i]; was[i] = 1; } return ret;}
vi ranv(ll n, ll min, ll max) {vi v(n); rep(i, n)v[i] = rand(min, max); return v;}
/*@formatter:off*/
#ifdef _DEBUG
bool timeup(int time) {static bool never = true; if (never)message += "may timeup, because slow"; never = false; auto end_time = system_clock::now(); auto part = duration_cast<milliseconds>(end_time - start_time); auto lim = milliseconds(time); return part >= lim;}
#else
bool timeup(int time) {
auto end_time = system_clock::now();
auto part = duration_cast<milliseconds>(end_time - start_time);
auto lim = milliseconds(time);
return part >= lim;
}
#endif
void set_time() { past_time = system_clock::now(); }
//MS型(millisecqnds)で返る
//set_timeをしてからの時間
auto calc_time_milli() {auto now = system_clock::now(); auto part = duration_cast<milliseconds>(now - past_time); return part;}
auto calc_time_micro() {auto now = system_clock::now(); auto part = duration_cast<microseconds>(now - past_time); return part;}
auto calc_time_nano() {auto now = system_clock::now(); auto part = duration_cast<nanoseconds>(now - past_time); return part;}
bool calc_time(int zikan) { return calc_time_micro() >= microseconds(zikan); }
using MS=std::chrono::microseconds;
int div(microseconds a, microseconds b) { return a / b; }
int div(nanoseconds a, nanoseconds b) {if (b < nanoseconds(1)) { return a / nanoseconds(1); } int v = a / b; return v;}
//set_time();
//rep(i,lim)shori
//lim*=time_nanbai();
//rep(i,lim)shoriと使う
//全体でmilliかかっていいときにlimを何倍してもう一回できるかを返す
int time_nanbai(int milli) {auto dec = duration_cast<nanoseconds>(past_time - start_time); auto part = calc_time_nano(); auto can_time = nanoseconds(milli * 1000 * 1000); can_time -= part; can_time -= dec; return div(can_time, part);}
/*@formatter:off*/
//#define use_rand
#ifdef use_rand
str ransu(ll n) {str s; rep(i, n)s += (char) rand('A', 'Z'); return s;}
str ransl(ll n) {str s; rep(i, n)s += (char) rand('a', 'z'); return s;}
//単調増加
vi ranvinc(ll n, ll min, ll max) {vi v(n); bool bad = 1; while (bad) { bad = 0; v.resize(n); rep(i, n) { if (i && min > max - v[i - 1]) { bad = 1; break; } if (i)v[i] = v[i - 1] + rand(min, max - v[i - 1]); else v[i] = rand(min, max); } } return v;}
//便利 汎用
#endif
void ranvlr(ll n, ll min, ll max, vi &l, vi &r) {l.resize(n); r.resize(n); rep(i, n) { l[i] = rand(min, max); r[i] = l[i] + rand(0, max - l[i]); }}
template<class Iterable, class T = typename Iterable::value_type> vector<pair<T, int>> run_length(const Iterable &a) {vector<pair<T, int>> ret; ret.eb(a[0], 1); rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }} return ret;}
/*@formatter:off*/
//#define use_mgr //_goldd _goldt
#ifdef use_mgr
//->[i, f(i)]
template<class T, class U, class F> auto mgr(T ok, U ng, const F &f, require_arg(is_integral<T>::value &&is_integral<U>::value)) { auto mid = (ok + ng); if (ok < ng) while (ng - ok > 1) { mid = (ok + ng) >> 1; if (f(mid))ok = mid; else ng = mid; } else while (ok - ng > 1) { mid = (ok + ng) >> 1; if (f(mid))ok = mid; else ng = mid; } return ok;}
//[l, r)の中で,f(i)がtrueとなる範囲を返す okはそこに含まれる
template<class F> P mgr_range(int l, int r, F f, int ok) {if (f(ok) == 0) { out("f(ok) must true"); re(); } return mp(mgr(ok, l - 1, f), mgr(ok, r, f) + 1);}
template<class F> auto mgrd(dou ok, dou ng, F f, int kai = 100) {if (ok < ng) rep(i, kai) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } else rep(i, kai) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } return ok;}
template<class F> dou mgrd_time(dou ok, dou ng, F f, int time = 1980) {bool han = true; if (ok < ng) while (1) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); if (timeup(time)) { break; } } else while (1) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); if (timeup(time)) { break; } } return ok;}
//todo 減らす
template<class F> auto goldd_l(ll left, ll right, F calc) {double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } ll minScore = MAX<ll>(); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (minScore > score) { minScore = score; resIndex = i; } } return make_tuple(resIndex, calc(resIndex));}
template<class F> auto goldt_l(ll left, ll right, F calc) {double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } if (left > right) { ll l = left; left = right; right = l; } ll maxScore = MIN<ll>(); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (maxScore < score) { maxScore = score; resIndex = i; } } return make_tuple(resIndex, calc(resIndex));}
/*loopは200にすればおそらく大丈夫 余裕なら300に*/
template<class F> auto goldd_d(dou left, dou right, F calc, ll loop = 200) {dou GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); /*200にすればおそらく大丈夫*/ /*余裕なら300に*/ ll k = 141; loop++; while (--loop) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return make_tuple(left, calc(left));}
template<class F> auto goldt_d(dou left, dou right, F calc, ll loop = 200) {double GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); loop++; while (--loop) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return make_tuple(left, calc(left));}
//l ~ rを複数の区間に分割し、極致を与えるiを返す time-20 msまで探索
template<class F> auto goldd_ls(ll l, ll r, F calc, ll time = 2000) { auto lim = milliseconds(time - 20); ll mini = 0, minv = MAX<ll>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldd_l(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(mini, calc(mini));}
template<class F> auto goldt_ls(ll l, ll r, F calc, ll time = 2000) {auto lim = milliseconds(time - 20); ll maxi = 0, maxv = MIN<ll>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldt_l(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(maxi, calc(maxi));}
template<class F> auto goldd_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を持つ*/ auto lim = milliseconds(time - 20); dou mini = 0, minv = MAX<dou>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldd_d(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(mini, calc(mini));}
template<class F> auto goldt_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を残している*/ auto lim = milliseconds(time - 20); dou maxi = 0, maxv = MIN<dou>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldt_d(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return make_tuple(maxi, calc(maxi));}
#endif
//strを整数として比較
string smax(str &a, str b) { if (sz(a) < sz(b)) { return b; } else if (sz(a) > sz(b)) { return a; } else if (a < b)return b; else return a; }
//strを整数として比較
string smin(str &a, str b) { if (sz(a) > sz(b)) { return b; } else if (sz(a) < sz(b)) { return a; } else if (a > b)return b; else return a; }
//エラー-1
template<typename W, typename T> ll find(vector<W> &a, int l, const T key) {rep(i, l, sz(a))if (a[i] == key)return i;return -1;}
template<typename W, typename T> ll find(vector<W> &a, const T key) {rep(i, sz(a))if (a[i] == key)return i;return -1;}
template<typename W, typename T> P find(vector<vector<W >> &a, const T key) {rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return mp(i, j);return mp(-1, -1);}
//getid(find())を返す 1次元にする
template<typename W, typename T> int findi(vector<vector<W >> &a, const T key) {rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return i * sz(a[0]) + j;return -1;}
template<typename W, typename U> tuple<int, int, int> find(vector<vector<vector<W >>> &a, const U key) { rep(i, sz(a))rep(j, sz(a[0]))rep(k, sz(a[0][0]))if (a[i][j][k] == key)return tuple<int, int, int>(i, j, k); return tuple<int, int, int>(-1, -1, -1);}
//無ければ-1
int find(string &s, const string key) { int klen = sz(key); rep(i, sz(s) - klen + 1) { if (s[i] != key[0])continue; if (s.substr(i, klen) == key) { return i; } }return -1;}
int find(string &s, int l, const string key) { int klen = sz(key); rep(i, l, sz(s) - klen + 1) { if (s[i] != key[0])continue; if (s.substr(i, klen) == key) { return i; } } return -1;}
int find(string &s, const char key) { rep(i, sz(s)) { if (s[i] == key)return i; } return -1;}
int find(string &s, int l, const char key) { rep(i, l, sz(s)) { if (s[i] == key)return i; } return -1;}
//N箇所について右のkeyの場所を返す
template<typename W, typename T> vi finds(const W &a, const T& key) { int n = sz(a); vi rpos(n, -1); rer(i, n-1){ if(i<n-1){ rpos[i] = rpos[i+1]; } if(a[i]==key)rpos[i] = i; } return rpos;}
template<typename W, typename T> vi rfinds(const W &a, const T& key) { int n = sz(a); vi lpos(n, -1); rep(i, n){ if(i> 0){ lpos[i] = lpos[i-1]; } if(a[i]==key)lpos[i] = i; } return lpos;}
//todoz
#if __cplusplus >= 201703L
template<typename W, typename T, class Iterable = typename W::value_type>
ll count(const W &a, const T &k) { return count_if(a, ==k); }
/*@formatter:on*/
template<typename W, class Iterable = typename W::value_type> vi count(const W &a) {
vi res;
for_each(a, v, if (sz(res) <= (int) v)res.resize((int) v + 1);
res[v]++;);
return res;
}
#endif
/*@formatter:off*/
ll count(const str &a, const str &k) { ll ret = 0, len = k.length(); auto pos = a.find(k); while (pos != string::npos)pos = a.find(k, pos + len), ++ret; return ret;}
/*@formatter:off*/
//'a' = 'A' = 0 として集計 既に-'a'されていても動く
vi count(str &a, int l, int r) { vi cou(26); char c = 'a'; if ('A' <= a[l] && a[l] <= 'Z')c = 'A'; if ('a' <= a[l] && a[l] <= 'z') c = 'a'; else c = 0; rep(i, l, r)++cou[a[i] - c]; return cou;}
#define couif count_if
//algorythm
ll rev(ll a) { ll res = 0; while (a) { res *= 10; res += a % 10; a /= 10; } return res;}
template<class T> auto rev(const vector<T> &a) { auto b = a; reverse(ALL(b)); return b;}
/* \反転 */ template<class U>
auto rev(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[h][w]; return b;}
/* |反転 */ template<class U>
auto revw(vector<vector<U>> &a) { vector<vector<U> > b(sz(a), vector<U>(sz(a[0]))); int W = sz(a[0]); rep(h, sz(a)) rep(w, sz(a[0])) { b[h][W - 1 - w] = a[h][w]; } return b;}
/* ー反転 */ template<class U>
auto revh(vector<vector<U>> &a) { vector<vector<U> > b(sz(a), vector<U>(sz(a[0]))); int H = sz(a); rep(h, sz(a)) rep(w, sz(a[0])) { b[H - 1 - h][w] = a[h][w]; } return b;}
/* /反転 */ template<class U>
auto revr(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); int H = sz(a); int W = sz(a[0]); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[H - 1 - h][W - 1 - w]; return b;}
auto rev(const string &a) { string b = a; reverse(ALL(b)); return b;}
template<class T> auto rev(const T &v, int i) {return v[sz(v) - 1 - i];}
int rev(int N, int i) {return N-1-i;}
constexpr ll p10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000ll, 100000000000ll, 1000000000000ll, 10000000000000ll, 100000000000000ll, 1000000000000000ll, 10000000000000000ll, 100000000000000000ll, 1000000000000000000ll};
//0は0桁
ll keta(ll v, int if_zero_res) { if(!v)return if_zero_res;if (v < p10[9]) { if (v < p10[4]) { if (v < p10[2]) { if (v < p10[1]) { if (v < p10[0])return 0; else return 1; } else return 2; } else { if (v < p10[3]) return 3; else return 4; }} else { if (v < p10[7]) { if (v < p10[5]) return 5; else if (v < p10[6])return 6; else return 7; } else { if (v < p10[8])return 8; else return 9; }}} else { if (v < p10[13]) { if (v < p10[11]) { if (v < p10[10]) return 10; else return 11; } else { if (v < p10[12]) return 12; else return 13; }} else { if (v < p10[15]) { if (v < p10[14]) return 14; else return 15; } else { if (v < p10[17]) { if (v < p10[16]) return 16; else return 17; } else { if (v < p10[18])return 18; else return 19; }}}}}
#if __cplusplus >= 201703L
ll getr(ll a, ll keta) { return (a / pow<ll>(10, keta)) % 10; }
#else
ll getr(ll a, ll keta) { return (a / (int)pow(10, keta)) % 10; }
#endif
//上から何桁目か
ll getl(ll a, ll ket) {int sketa = keta(a, 1);return getr(a, sketa - 1 - ket);}
ll dsum(ll v, ll sin = 10) {ll ret = 0;for (; v; v /= sin)ret += v % sin;return ret;}
ll mask10(ll v) { return p10[v] - 1; }
//変換系
template<class T, class U> auto to_v1(vector<reference_wrapper<U>>& ret, vector<T> &A) { rep(i, sz(A))ret.push_back(A[i]); return ret;}
template<class T, class U> auto to_v1(vector<reference_wrapper<U>>& ret, vector<vector<T> > &A) {rep(i, sz(A))to_v1(ret, A[i]);return ret;}
//参照付きで1次元に起こす
template<class T> auto to_v1(vector<vector<T> > &A) { vector<reference_wrapper<typename decl2<decltype(A)>::type>> ret; rep(i, sz(A))to_v1(ret, A[i]); return ret;}
//[v] := iとなるようなvectorを返す
//存在しない物は-1
//空でも動く(なぜか)
template<class T> auto keys(const T& a) { vector<decltype((a.begin())->fi)> res; for (auto &&k :a)res.push_back(k.fi); return res;}
template<class T> auto values(const T& a) { vector<decltype((a.begin())->se)> res; for (auto &&k :a)res.push_back(k.se); return res;}
//todo 可変長で
template<class T> constexpr T min(T a, T b, T c) { return a >= b ? b >= c ? c : b : a >= c ? c : a; }
template<class T> constexpr T max(T a, T b, T c) { return a <= b ? b <= c ? c : b : a <= c ? c : a; }
template<class V, class T = typename V::value_type> T min(V &a, ll s = -1, ll n = -1) { set_lr12(s, n, sz(a)); return *min_element(a.begin() + s, a.begin() + min(n, sz(a))); }
template<class V, class T = typename V::value_type> T max(V &a, ll s = -1, ll n = -1) { set_lr12(s, n,sz(a)); return *max_element(a.begin() + s, a.begin() + min(n, sz(a))); }
template<class T> int mini(const vector<T> &a) { return min_element(ALL(a)) - a.begin(); }
template<class T> int maxi(const vector<T> &a) { return max_element(ALL(a)) - a.begin(); }
template<class T> T sum(const vector<T> &A, int l = -1, int r = -1) { T s = 0; set_lr12(l, r, sz(A)); rep(i, l, r)s += A[i]; return s;}
template<class T> auto sum(const vector<vector<T>> &A) { decl2<decltype(A)> s = 0; rep(i, sz(A))s += sum(A[i]); return s;}
template<class T> T min(const vector<T>& A, int l = -1, int r = -1 ){T s=MAX<T>();set_lr12(l, r, sz(A));rep(i, l, r)s=min(s, A[i]);return s;}
template<class T> auto min(const vector<vector<T>>& A ){using S =decl2<decltype(A)>; S s=MAX<S>();rep(i, sz(A))s=min(s, A[i]);return s;}
template<class T> T max(const vector<T>& A, int l = -1, int r = -1 ){T s=MIN<T>();set_lr12(l, r, sz(A));rep(i, l, r); rep(i, l, r)s=max(s, A[i]);return s;}
template<class T> auto max(const vector<vector<T>>& A ){using S =decl2<decltype(A)>;S s=MIN<S>();rep(i, sz(A))s=max(s, A[i]);return s;}
template<class T> T mul(vector<T> &v, ll t = inf) { T ret = v[0]; rep(i, 1, min(t, sz(v)))ret *= v[i]; return ret;}
//template<class T, class U, class... W> auto sumn(vector<T> &v, U head, W... tail) { auto ret = sum(v[0], tail...); rep(i, 1, min(sz(v), head))ret += sum(v[i], tail...); return ret;}
//indexを持つvectorを返す
vi inds_(vi &a) { int n = max(a) + 1; vi ret(n, -1); rep(i, sz(a)) { assert(ret[a[i]] ==-1);ret[a[i]] = i; } return ret;}
void clear(PQ &q) { q = PQ(); }
void clear(priority_queue<int> &q) { q = priority_queue<int>(); }
template<class T> void clear(queue<T> &q) { while (q.size())q.pop(); }
//template<class T> T *negarr(ll size) { T *body = (T *) malloc((size * 2 + 1) * sizeof(T)); return body + size;}
//template<class T> T *negarr2(ll h, ll w) { double **dummy1 = new double *[2 * h + 1]; double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)]; dummy1[0] = dummy2 + w; for (ll i = 1; i <= 2 * h + 1; ++i) { dummy1[i] = dummy1[i - 1] + 2 * w + 1; } double **a = dummy1 + h; return a;}
template<class T> struct ruiC {
vector<T> rui;
ruiC(vector<T> &ru) : rui(ru) {}
/*先頭0*/
ruiC() : rui(1, 0) {}
T operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } return rui[r] - rui[l]; }
T operator()(int r = inf) { return operator()(0, min(r, sz(rui) - 1)); }
/*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/
/*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/
// T operator[](ll i) { return rui[i + 1] - rui[i]; }
T operator[](ll i) { return rui[i]; }
/*0から順に追加される必要がある*/
void operator+=(T v) { rui.push_back(rui.back() + v); }
void add(int i, T v) {if (sz(rui) - 1 != i)ole();operator+=(v);}
T back() { return rui.back(); }
ll size() { return rui.size(); }
auto begin() { return rui.begin(); }
auto end() { return rui.end(); }
};
template<class T> string deb_tos(const ruiC<T> &a) {return deb_tos(a.rui);}
template<class T> ostream &operator<<(ostream &os, ruiC<T> a) { fora(v, a.rui){os << v << " "; } return os;}
template<class T> vector<T> ruiv(const vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i]; return ret;}
template<class T> ruiC<T> ruic(const vector<T> &a) { vector<T> ret = ruiv(a); return ruiC<T>(ret);}
template<class T> ruiC<T> ruic() { return ruiC<T>(); }
//imoは0-indexed
//ruiは1-indexed
template<class T> vector<T> imo(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret;}
//#define use_rui //_imo _ruic _ruiv
#ifdef use_rui
//kと同じものの数
template<class T, class U> vi imo(const vector<T> &a, U k) { vi equ(sz(a)); rep(i, sz(a)){ equ[i] = a[i]==k; } return imo(equ);}
template<class T> vector<T> imox(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] ^= ret[i]; return ret;}
//漸化的に最小を持つ
template<class T> vector<T> imi(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chmi(ret[i + 1], ret[i]); return ret;}
template<class T> vector<T> ima(const vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chma(ret[i + 1], ret[i]); return ret;}
template<class T> vector<T> rimi(const vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chmi(ret[i - 1], ret[i]); return ret;}
template<class T> vector<T> rima(const vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chma(ret[i - 1], ret[i]); return ret;}
template<class T> struct ruimax {
template<typename Monoid> struct SegmentTree { /*pairで処理*/ int sz; vector<Monoid> seg; const Monoid M1 = mp(MIN<T>(), -1); Monoid f(Monoid a, Monoid b) { return max(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } };
private:
vector<T> ve;
SegmentTree<pair<T, int>> seg;
vector<T> rv;
vector<int> ri;
bool build = false;
public:
int n;
ruimax(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; T ma = MIN<T>(); rv.resize(n + 1); ri.resize(n + 1); rv[0] = -INF<T>; ri[0] = -1; rep(i, n) { if (chma(ma, a[i])) { index = i; } rv[i + 1] = ma; ri[i + 1] = index; } }
T operator()(int l, int r) { if (!(l <= r && 0 <= l && r <= n)) { deb(l, r, n); assert(0); } if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } }
T operator()(int r = inf) { return operator()(0, min(r, n)); }
T operator[](int r) { return operator()(0, r); }
T getv(int l, int r) { return operator()(l, r); }
T getv(int r = inf) { return getv(0, min(r, n)); };
int geti(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } }
int geti(int r = inf) { return geti(0, min(r, n)); };
auto begin() { return rv.begin(); }
auto end() { return rv.end(); }
};
template<class T> struct ruimin {
template<typename Monoid> struct SegmentTree { /*pairで処理*/ int sz;vector<Monoid> seg; const Monoid M1 = mp(MAX<T>(), -1); Monoid f(Monoid a, Monoid b) { return min(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } };
private:
vector<T> ve;
SegmentTree<pair<T, int>> seg;
vector<T> rv;
vector<int> ri;
bool build = false;
int n;
public:
ruimin(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; T mi = MAX<T>(); rv.resize(n + 1); ri.resize(n + 1); rv[0] = INF<T>; ri[0] = -1; rep(i, n) { if (chmi(mi, a[i])) { index = i; } rv[i + 1] = mi; ri[i + 1] = index; } }
T operator()(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } }
T operator()(int r = inf) { return operator()(0, min(r, n)); }
T operator[](int r) { return operator()(0, r); }
T getv(int l, int r) { return operator()(l, r); }
T getv(int r = inf) { return getv(0, min(r, n)); };
int geti(int l, int r) { { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } } assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } }
int geti(int r = inf) { return geti(0, min(r, n)); };
auto begin() { return rv.begin(); }
auto end() { return rv.end(); }
};/*@formatter:off*/
vvi() ruib(vi &a) { vvi(res, 61, sz(a) + 1); rep(k, 61) { rep(i, sz(a)) { res[k][i + 1] = res[k][i] + ((a[i] >> k) & 1); }} return res;}
vector<ruiC<int>> ruibc(vi &a) {vector<ruiC<int>> ret(61); vvi(res, 61, sz(a)); rep(k, 61) { rep(i, sz(a)) { res[k][i] = (a[i] >> k) & 1; } ret[k] = ruic(res[k]); } return ret;}
//kと同じものの数
template<class T, class U> vi ruiv(T &a, U k) { vi ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + (a[i] == k); return ret;}
template<class T, class U> ruiC<ll> ruic(T &a, U k) { vi ret = ruiv(a, k); return ruiC<ll>(ret);}
template<class T> struct ruiC2 {
int H;
vector<ruiC<T>> rui;
ruiC<T> dummy;//変なのをよばれたときはこれを返す//todo
ruiC2(const vector<vector<T>> &ru) : rui(sz(ru)), H(sz(ru)) { for (int h = 0; h < H; h++) { if (sz(ru[h]) == 0)continue; if (sz(dummy) == 1) dummy = ruic(vector<T>(sz(ru[h]))); rui[h] = ruic(ru[h]); } }
//WについてHを返す
vector<T> operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } vector<T> res(H); for (int h = 0; h < H; h++)res[h] = rui[h](l, r); return res; }
//HについてWを返す
ruiC<T> &operator[](ll h) {
#ifdef _DEBUG
if (h >= H) {message += "warning ruiC h >= H";}
#endif
if (h >= H || sz(rui[h]) == 1)return dummy;else return rui[h];
}
/*@formatter:off*/
// vector<T> operator()(int r) { return operator()(0, r); }
/*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/
/*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/
// T operator[](ll i) { return rui[i + 1] - rui[i]; }
/*0から順に追加される必要がある*/
// T back() { return rui.back(); }
// ll size() { return rui.size(); }
// auto begin(){return rui.begin();}
// auto end(){return rui.end();}
};
template<class T, class U> ruiC<ll> ruicou(vector<T> &a, U b) { vi cou(sz(a)); rep(i, sz(a)) { cou[i] = a[i] == b; } return ruic(cou);}
//メモリは形式によらず(26*N)
// rui(l,r)でvector(26文字について, l~rのcの個数)
// rui[h] ruic()を返す
// 添え字は'a', 'A'のまま扱う (予め-='a','A'されているものが渡されたらそれに従う)
template<typename Iterable, class is_Iterable = typename Iterable::value_type>
ruiC2<ll> ruicou(const Iterable &a) { int H = max(a) + 1; vvi(cou, H); rep(i, sz(a)) { if (sz(cou[a[i]]) == 0)cou[a[i]].resize(sz(a)); cou[a[i]][i] = 1; } return ruiC2<ll>(cou); }
/*@formatter:off*/
//h query
template<class T> vector<T> imoh(vector<vector<T>> &v, int w) { vector<T> ret(sz(v)); rep(h, sz(ret)) { ret[h] = v[h][w]; } rep(i, sz(ret) - 1) { ret[i + 1] += ret[i]; } return ret;}
template<class T> vector<T> ruih(vector<vector<T>> &v, int w) { vector<T> ret(sz(v) + 1); rep(h, sz(v)) { ret[h + 1] = v[h][w]; } rep(i, sz(v)) { ret[i + 1] += ret[i]; } return ret;}
template<class T> ruiC<T> ruihc(vector<vector<T>> &a, int w) { vector<T> ret = ruih(a, w); return ruiC<T>(ret);}
//xor
template<class T> struct ruixC {
vector<T> rui;
ruixC(vector<T> &ru) : rui(ru) {}
T operator()(ll l, ll r) { if (l > r) { cerr << "ruiXc "; deb(l, r); assert(0); } return rui[r] ^ rui[l]; }
T operator[](ll i) { return rui[i]; }
T back() { return rui.back(); }
ll size() { return rui.size(); }
};
template<class T> vector<T> ruix(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] ^ a[i]; return ret;}
template<class T> ruixC<ll> ruixc(vector<T> &a) { vi ret = ruix(a); return ruixC<ll>(ret);}
//差分を返す(累積を取ると元に戻る)
//101なら
//1111を返す
//元の配列で[l, r)へのxorは
//[l]と[r]へのxorになる https://atcoder.jp/contests/abc155/tasks/abc155_f
vi ruix_diff(vi &A) { int N = sz(A); assert(N); vi res(N + 1); res[0] = A[0]; rep(i, 1, N) { res[i] = A[i - 1] ^ A[i]; } res[N] = A[N - 1]; return res;}
template<class T> vector<T> ruim(vector<T> &a) { vector<T> res(a.size() + 1, 1); rep(i, a.size())res[i + 1] = res[i] * a[i]; return res;}
//漸化的に最小を1indexで持つ
template<class T> vector<T> ruimi(vector<T> &a) {ll n = sz(a); vector<T> ret(n + 1); rep(i, 1, n) { ret[i] = a[i - 1]; chmi(ret[i + 1], ret[i]); } return ret;}
//template<class T> T *rrui(vector<T> &a) {
//右から左にかけての半開区間 (-1 n-1]
template<class T> struct rruiC {
vector<T> rui;
int n;
rruiC(vector<T> &a) : n(sz(a)) { rui.resize(n + 1); rer(i, n - 1) { rui[i] = rui[i + 1] + a[i]; } }
/*[r l)*/
T operator()(int r, int l) { r++; l++; assert(l <= r && l >= 0 && r <= n); return rui[l] - rui[r]; }
T operator()(int l) { return operator()(n - 1, l); }
T operator[](int i) { return operator()(i); }
};
template<class T> ostream &operator<<(ostream &os, rruiC<T> a) { fora(v, a.rui){os << v << " "; } return os;}
template<class T> string deb_tos(rruiC<T> &a) {return deb_tos(a.rui);}
#define rrui rruic
template<class T> rruiC<T> rruic(vector<T> &a) { return rruiC<T>(a); }
//掛け算
template<class T> struct ruimulC {
vector<T> rv;
int n;
ruimulC(vector<T> &a) : rv(a), n(sz(a)) { rv.resize(n + 1); rv[0] = 1; rep(i, n) { rv[i + 1] = a[i] * rv[i]; } }
ruimulC() : n(0) { rv.resize(n + 1); rv[0] = 1; }
void operator+=(T v) { rv.push_back(rv.back() * v); n++; }
T operator()(int l, int r) { assert(l <= r && 0 <= l && r <= n); return rv[r] / rv[l]; }
T operator()(int r = inf) { return operator()(0, min(r, n)); }
T operator[](int r) { return operator()(0, r); }
auto begin() { return rv.begin(); }
auto end() { return rv.end(); }
};
template<class T> ruimulC<T> ruimul(vector<T> &a) { return ruimulC<T>(a); }
template<class T> ruimulC<T> ruimul() { vector<T> a; return ruimulC<T>(a);}
template<class T> T *rruim(vector<T> &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; res[len - 1] = 1; rer(i, len - 1)res[i - 1] = res[i] * a[i]; return res;}
template<class T, class U, class W> T lowerBound(ruiC <T> &a, U v, W banpei) { return lowerBound(a.rui, v, banpei); }
template<class T, class U, class W> T upperBound(ruiC <T> &a, U v, W banpei) { return upperBound(a.rui, v, banpei); }
template<class T, class U, class W> T rlowerBound(ruiC <T> &a, U v, W banpei) { return rlowerBound(a.rui, v, banpei); }
template<class T, class U, class W> T rupperBound(ruiC <T> &a, U v, W banpei) { return rupperBound(a.rui, v, banpei); }
#endif
constexpr bool bget(ll m, ll keta) {
#ifdef _DEBUG
assert(keta <= 62);//オーバーフロー 1^62までしか扱えない
#endif
return (m >> keta) & 1;
}
//bget(n)次元
// NならN-1まで
vector<vi> bget2(vi &a, int keta_size) { vvi(res, keta_size, sz(a)); rep(k, keta_size) { rep(i, sz(a)) { res[k][i] = bget(a[i], k); }} return res;}
vi bget1(vi &a, int keta) { vi res(sz(a)); rep(i, sz(a)) { res[i] = bget(a[i], keta); } return res;}
#if __cplusplus >= 201703L
ll bget(ll m, ll keta, ll sinsuu) { m /= pow<ll>(sinsuu, keta); return m % sinsuu;}
#else
ll bget(ll m, ll keta, ll sinsuu) { m /= (ll)pow(sinsuu, keta); return m % sinsuu;}
#endif
constexpr ll bit(ll n) {
#ifdef _DEBUG
assert(n <= 62);//オーバーフロー 1^62までしか扱えない
#endif
return (1LL << (n));
}
#if __cplusplus >= 201703L
ll bit(ll n, ll sinsuu) { return pow<ll>(sinsuu, n); }
#else
ll bit(ll n, ll sinsuu) { return (ll)pow(sinsuu, n); }
#endif
ll mask(ll n) { return (1ll << n) - 1; }
//aをbitに置きなおす
//{0, 2} -> 101
ll bit(const vi &a) { int m = 0; for (auto &&v:a) m |= bit(v); return m;}
//{1, 1, 0} -> 011
//bitsetに置き換える感覚 i が立っていたら i bit目を立てる
ll bit_bool(vi &a) { int m = 0; rep(i, sz(a)) if (a[i])m |= bit(i); return m;}
#define bcou __builtin_popcountll
//最下位ビット
ll lbit(ll n) { assert(n);return n & -n; }
ll lbiti(ll n) { assert(n);return log2(n & -n); }
//最上位ビット
ll hbit(ll n) { assert(n);n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); n |= (n >> 32); return n - (n >> 1);}
ll hbiti(ll n) { assert(n);return log2(hbit(n)); }
//ll hbitk(ll n) { ll k = 0; rer(i, 5) { ll a = k + (1ll << i); ll b = 1ll << a; if (b <= n)k += 1ll << i; } return k;}
//初期化は0を渡す
ll nextComb(ll &mask, ll n, ll r) { if (!mask)return mask = (1LL << r) - 1; ll x = mask & -mask; /*最下位の1*/ ll y = mask + x; /*連続した下の1を繰り上がらせる*/ ll res = ((mask & ~y) / x >> 1) | y; if (bget(res, n))return mask = 0; else return mask = res;}
//n桁以下でビットがr個立っているもののvectorを返す
vi bitCombList(ll n, ll r) { vi res; ll m = 0; while (nextComb(m, n, r)) { res.push_back(m); } return res;}
/*over*/#define forbit1_2(i, mas) for (int forbitj = !mas ? 0 : lbit(mas), forbitm = mas, i = !mas ? 0 :log2(forbitj); forbitm; forbitm = forbitm ^ forbitj, forbitj = !forbitm ? 1 : lbit(forbitm), i = log2(forbitj))
/*over*/#define forbit1_3(i, N, mas) for (int forbitj = !mas ? 0 : lbit(mas), forbitm = mas, i = !mas ? 0 :log2(forbitj); forbitm && i < N; forbitm = forbitm ^ forbitj, forbitj = !forbitm ? 1 : lbit(forbitm), i = log2(forbitj))
//masの立ってるindexを見る
// i, [N], mas
#define forbit1(...) over3(__VA_ARGS__, forbit1_3, forbit1_2)(__VA_ARGS__)
//masが立っていないindexを見る
// i, N, mas
#define forbit0(i, N, mas) forbit1(i, mask(N) & (~(mas)))
//forsubをスニペットして使う
//Mの部分集合(0,M含む)を見る 3^sz(S)個ある
#define forsub_all(m, M) for (int m = M; m != -1; m = m == 0 ? -1 : (m - 1) & M)
//BASE進数
template<size_t BASE> class base_num {
int v;
public:
base_num(int v = 0) : v(v) {};
int operator[](int i) { return bget(v, i, BASE); }
void operator++() { v++; }
void operator++(signed) { v++; }
operator int() { return v; }
};
#define base3(mas, lim, BASE) for (base_num<BASE> mas; mas < lim; mas++)
#define base2(mas, lim) base3(mas, lim, 2)
#define base(...) over3(__VA_ARGS__,base3,base2,base1)(__VA_ARGS__)
//aにある物をtrueとする
vb bool_(vi a, int n) { vb ret(max(max(a) + 1, n)); rep(i, sz(a))ret[a[i]] = true; return ret;}
char itoal(ll i) { return 'a' + i; }
char itoaL(ll i) { return 'A' + i; }
ll altoi(char c) { if ('A' <= c && c <= 'Z')return c - 'A'; return c - 'a';}
ll ctoi(char c) { return c - '0'; }
char itoc(ll i) { return i + '0'; }
ll vtoi(vi &v) { ll res = 0; if (sz(v) > 18) { debugline("vtoi"); deb(sz(v)); ole(); } rep(i, sz(v)) { res *= 10; res += v[i]; } return res;}
vi itov(ll i) { vi res; while (i) { res.push_back(i % 10); i /= 10; } res = rev(res); return res;}
vi stov(string &a) { ll n = sz(a); vi ret(n); rep(i, n) { ret[i] = a[i] - '0'; } return ret;}
//基準を満たさないものは0になる
vi stov(string &a, char one) { ll n = sz(a); vi ret(n); rep(i, n)ret[i] = a[i] == one; return ret;}
vector<vector<ll>> ctoi(vector<vector<char>> s, char c) { ll n = sz(s), m = sz(s[0]); vector<vector<ll>> res(n, vector<ll>(m)); rep(i, n)rep(j, m)res[i][j] = s[i][j] == c; return res;}
//#define use_compress
//[i] := vを返す
//aは0~n-1で置き換えられる
vi compress(vi &a) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(ALL(b), a[i]) - b.begin(); } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
#ifdef use_compress
//ind[i] := i番目に小さい数
//map[v] := vは何番目に小さいか
vi compress(vi &a, umapi &map) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { ll v = a[i]; a[i] = lower_bound(ALL(b), a[i]) - b.begin(); map[v] = a[i]; } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vi &a, vi &r) { vi b; ll len = a.size(); fora(v, a){b.push_back(v);} fora(v, r){b.push_back(v);} sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(ALL(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(ALL(b), r[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vi &a, vi &r, vi &s) { vi b; ll len = a.size(); fora(v, a){b.push_back(v);} fora(v, r){b.push_back(v);} fora(v, s){b.push_back(v); } sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(ALL(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(ALL(b), r[i]) - b.begin(); for (ll i = 0; i < sz(s); ++i) r[i] = lower_bound(ALL(b), s[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vector<vi> &a) { vi b; fora(vv, a){fora(v, vv){b.push_back(v);}} sort(b); unique(b); fora(vv, a){fora(v, vv){v = lower_bound(ALL(b), v) - b.begin(); }} ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
vi compress(vector<vector<vi >> &a) { vi b; fora(vvv, a){fora(vv, vvv){fora(v, vv){b.push_back(v);}}} sort(b); unique(b); fora(vvv, a){fora(vv, vvv){fora(v, vv){v = lower_bound(ALL(b), v) - b.begin();}}} ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;}
void compress(ll a[], ll len) { vi b; for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(ALL(b), a[i]) - b.begin(); }}
#endif
//要素が見つからなかったときに困る
#define binarySearch(a, v) (binary_search(ALL(a),v))
#define lowerIndex(a, v) (lower_bound(ALL(a),v)-a.begin())
#define upperIndex(a, v) (upper_bound(ALL(a),v)-a.begin())
#define rlowerIndex(a, v) (upper_bound(ALL(a),v)-a.begin()-1)
#define rupperIndex(a, v) (lower_bound(ALL(a),v)-a.begin()-1)
template<class T, class U, class W> T lowerBound(vector<T> &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T upperBound(vector<T> &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T rlowerBound(vector<T> &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T rupperBound(vector<T> &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else { return *(--it); }}
//todo 消せないか
template<class T, class U, class W> T lowerBound(set<T> &a, U v, W banpei) { auto it = a.lower_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T upperBound(set<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T rlowerBound(set<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T rupperBound(set<T> &a, U v, W banpei) {auto it = a.lower_bound(v);if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T lowerBound(mset<T> &a, U v, W banpei) { auto it = a.lower_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T upperBound(mset<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.end())return banpei; else return *it;}
template<class T, class U, class W> T rlowerBound(mset<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.begin())return banpei; else { return *(--it); }}
template<class T, class U, class W> T rupperBound(mset<T> &a, U v, W banpei) {auto it = a.lower_bound(v);if (it == a.begin())return banpei; else { return *(--it); }}
#define next2(a) next(next(a))
#define prev2(a) prev(prev(a))
//狭義の単調増加列 長さを返す
template<class T> int lis(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX<T>()); rep(i, n) { int id = lowerIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX<T>());}
template<class T> int lis_eq(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX<T>()); rep(i, n) { int id = upperIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX<T>());}
//iteratorを返す
//valueが1以上の物を返す 0は見つけ次第削除
//vを減らす場合 (*it).se--でいい
template<class T, class U, class V> auto lower_map(map<T, U> &m, V k) { auto ret = m.lower_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;}
template<class T, class U, class V> auto upper_map(map<T, U> &m, V k) { auto ret = m.upper_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;}
//存在しなければエラー
template<class T, class U, class V> auto rlower_map(map<T, U> &m, V k) { auto ret = upper_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;}
template<class T, class U, class V> auto rupper_map(map<T, U> &m, V k) { auto ret = lower_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;}
template<class... T> void fin(T... s) {out(s...); exit(0); }
//便利 数学 math
//sub ⊂ top
bool subset(int sub, int top) {return (sub & top) == sub;}
//-180 ~ 180 degree
double atand(double h, double w) {return atan2(h, w) / PI * 180;}
//% -mの場合、最小の正の数を返す
ll mod(ll a, ll m) {if (m < 0) m *= -1;return (a % m + m) % m;}
//ll pow(ll a) { return a * a; };
template<class T> T fact(int v) { static vector<T> fact(2, 1); if (sz(fact) <= v) { rep(i, sz(fact), v + 1) { fact.emplace_back(fact.back() * i); }} return fact[v];}
ll comi(ll n, ll r) { assert(n < 100); static vvi(pas, 100, 100); if (pas[0][0])return pas[n][r]; pas[0][0] = 1; rep(i, 1, 100) { pas[i][0] = 1; rep(j, 1, i + 1)pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j]; } return pas[n][r];}
//二項係数の偶奇を返す
int com_mod2(int n,int r){return n == ( r | (n - r) );}
double comd2(ll n, ll r) { static vvd(comb, 2020, 2020); if (comb[0][0] == 0) { comb[0][0] = 1; rep(i, 2000) { comb[i + 1][0] = 1; rep(j, 1, i + 2) { comb[i + 1][j] = comb[i][j] + comb[i][j - 1]; } } } return comb[n][r];}
double comd(int n, int r) { if (r < 0 || r > n) return 0; if (n < 2020)return comd2(n, r); static vd fact(2, 1); if (sz(fact) <= n) { rep(i, sz(fact), n + 1) { fact.push_back(fact.back() * i); }} return fact[n] / fact[n - r] / fact[r];}
#define gcd my_gcd
ll gcd(ll a, ll b) {while (b) a %= b, swap(a, b);return abs(a);}
ll gcd(vi b) {ll res = b[0];rep(i, 1, sz(b))res = gcd(b[i], res);return res;}
#define lcm my_lcm
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll lcm(vi a) {ll res = a[0];rep(i, 1, sz(a))res = lcm(a[i], res);return res;}
ll ceil(ll a, ll b) {if (b == 0) {debugline("ceil");deb(a, b);ole();return -1;} else if (a < 0) { return 0; } else { return (a + b - 1) / b; }}
#define hypot my_hypot
double hypot(double dx, double dy){return std::sqrt(dx*dx+ dy*dy);}
ll sig0(int t) { return t <= 0 ? 0 : ((1 + t) * t) >> 1; }
bint sig0(bint t) {return t <= 0 ? 0 : ((1 + t) * t) >> 1; }
//ll sig(ll s, ll t) { return ((s + t) * (t - s + 1)) >> 1; }
ll sig(ll s, ll t) {if (s > t)swap(s, t);return sig0(t - s) + s * (t - s + 1);}
#define tousa_i tosa_i
#define lower_tousa_i lower_tosa_i
#define upper_tousa upper_tosa
#define upper_tousa_i upper_tosa_i
ll tosa_i(ll st, ll ad, ll v) { assert(((v - st) % ad) == 0); return (v - st) / ad;}
ll tosa_s(ll st, ll ad, ll len) { return st * len + sig0(len - 1) * ad;}
// ax + r (x は非負整数) で表せる整数のうち、v 以上となる最小の整数
ll lower_tosa(ll st, ll ad, ll v) { if (st >= v) return st; return (v - st + ad - 1) / ad * ad + st;}
//第何項か
ll lower_tosa_i(ll st, ll ad, ll v) { if (st >= v) return 0; return (v - st + ad - 1) / ad;}
ll upper_tosa(ll st, ll ad, ll v) { return lower_tosa(st, ad, v + 1); }
ll upper_tosa_i(ll st, ll ad, ll v) { return lower_tosa_i(st, ad, v + 1); }
//b * res <= aを満たす [l, r)を返す div
P drange_ika(int a, int b) { P null_p = mp(linf, linf); if (b == 0) { if (a >= 0) { return mp(-linf, linf + 1)/*全て*/; } else { return null_p/*無い*/; } } else { if (a >= 0) { if (b > 0) { return mp(-linf, a / b + 1); } else { return mp(-(a / -b), linf + 1); } } else { if (b > 0) { return mp(-linf, -ceil(-a, b) + 1); } else { return mp(ceil(-a, -b), linf + 1); } } }}
//v * v >= aとなる最小のvを返す
ll sqrt(ll a) { if (a < 0) { debugline("sqrt"); deb(a); ole(); } ll res = (ll) std::sqrt(a); while (res * res < a)++res; return res;}
double log(double e, double x) { return log(x) / log(e); }
/*@formatter:off*/
//機能拡張
#define dtie(a, b) int a, b; tie(a, b)
template<class T, class U> string to_string(T a, U b) { string res = ""; res += a; res += b; return res;}
template<class T, class U, class V> string to_string(T a, U b, V c) { string res = ""; res += a; res += b; res += c; return res;}
template<class T, class U, class V, class W> string to_string(T a, U b, V c, W d) { string res = ""; res += a; res += b; res += c; res += d; return res;}
template<class T, class U, class V, class W, class X> string to_string(T a, U b, V c, W d, X e) { string res = ""; res += a; res += b; res += c; res += d; res += e; return res;}
//todo stringもセットで
template<class T> vector<T> sub(const vector<T> &A, int l, int r) { assert(0 <= l && l <= r && r <= sz(A)); vector<T> ret(r - l); std::copy(A.begin() + l, A.begin() + r, ret.begin()); return ret;}
template<class T> vector<T> sub(const vector<T> &A, int r) { return sub(A, 0, r); }
template<class T> vector<T> subn(const vector<T> &A, int l, int len) { return sub(A, l, l + len); }
string sub(string &A, int l, int r) { assert(0 <= l && l <= r && r <= sz(A)); return A.substr(l, r - l);}
template<class T, class F>
//sub2で呼ぶ
vector<T> sub(const vector<vector<T> >& A, int h, int w, int ah,int aw, F f){ vector<T> res; while(0<= h && h < sz(A) && 0 <= w && w < sz(A[h]) && f(A[h][w])){ res.emplace_back(A[h][w]); h += ah; w += aw; } return res;}
template<class T> vector<T>sub(const vector<vector<T> >& A, int h, int w, int ah,int aw){return sub(A, h, w, ah, aw, [&](T v){return true;});}
#define sub25(A, h, w, ah, aw) sub(A, h, w, ah, aw)
#define sub26(A, h, w, ah, aw, siki_r) sub(A, h, w, ah, aw, [&](auto v){return v siki_r;})
#define sub27(A, h, w, ah, aw, v, siki) sub(A, h, w, ah, aw, [&](auto v){return siki;})
#define sub2(...) over7(__VA_ARGS__,sub27,sub26,sub25)(__VA_ARGS__)
constexpr int bsetlen = k5 * 2;
//constexpr int bsetlen = 5050;
#define bset bitset<bsetlen>
bool operator<(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return false;}
bool operator>(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return false;}
bool operator<=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return true;}
bool operator>=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return true;}
string operator~(string &a) {string res = a;for (auto &&c:res) {if (c == '0')c = '1';else if (c == '1')c = '0';else {cerr << "cant ~" << a << "must bit" << endl;exit(0);}}return res;}
ostream &operator<<(ostream &os, bset& a) { bitset<10> b; vi list; rep(i,bsetlen){ if(a[i])list.push_back(i),b[i]=1; } os<<b<<", "<<list; return os;}
int hbiti(bset&a){rer(i,bsetlen){if(a[i])return i;}return -1;}
#define hk(a, b, c) (a <= b && b < c)
//O(N/64)
bset nap(bset &a, int v) {bset r = a | a << v;return r;}
bset nap(bset &a, bset &v) {bset r = a;rep(i, bsetlen) {if (v[i])r |= a << i;}return r;}
template<class T> int count(set<T> &S, T l, T r) { assert(l < r); auto it = S.lower_bound(l); return it != S.end() && (*it) < r;}
//template<class T> void seth(vector<vector<T>> &S, int w, vector<T> &v) {assert(sz(S) == sz(v));assert(w < sz(S[0]));rep(h, sz(S)) { S[h][w] = v[h]; }}
template<class T> vector<T> geth(vector<vector<T>> &S, int w) { assert(w < sz(S[0])); vector<T> ret(sz(S)); rep(h, sz(S)) { ret[h] = S[h][w]; } return ret;}
//vector<bool>[i]は参照を返さないため、こうしないとvb[i] |= trueがコンパイルエラー
vb::reference operator|=(vb::reference a, bool b){return a = a | b;}
vb::reference operator&=(vb::reference a, bool b){return a = a & b;}
template<class T, class U> void operator+=(pair<T,U> &a, pair<T,U> & b) {a.fi+=b.fi;a.se+=b.se;}
template<class T, class U> pair<T, U> operator+(const pair<T, U> &a, const pair<T, U> &b) { return pair<T, U>(a.fi + b.fi, a.se + b.se); }
template<class T, class U> pair<T,U> operator-(const pair<T,U> &a, const pair<T,U> & b) {return pair<T,U>(a.fi-b.fi,a.se-b.se);}
template<class T, class U> pair<T,U> operator-(const pair<T, U>& a){return pair<T, U>(-a.first, -a.second);}
template<typename CharT, typename Traits, typename Alloc> basic_string<CharT, Traits, Alloc> operator+(const basic_string<CharT, Traits, Alloc> &lhs, const int rv) {
#ifdef _DEBUG
static bool was = false;if (!was)message += "str += 65 is 'A' not \"65\" ";was = true;
#endif
return lhs + (char) rv;
}
template<typename CharT, typename Traits, typename Alloc> void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const int rv) { lhs = lhs + rv;}
template<typename CharT, typename Traits, typename Alloc> basic_string<CharT, Traits, Alloc> operator+(const basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { const int rv2 = rv; return lhs + rv2;}
template<typename CharT, typename Traits, typename Alloc> void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const signed rv) {const int v = rv; lhs += v; }
template<typename CharT, typename Traits, typename Alloc> void operator*=(basic_string<CharT, Traits, Alloc> &s, int num) { auto bek = s; s = ""; for (; num; num >>= 1) { if (num & 1) { s += bek; } bek += bek; }}
template<class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }template<class T, class U> void operator+=(deque<T> &a, U v) { a.push_back(v); }template<class T> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, vector<T> &v) { fora(d, v){a.push(d);} return a;}template<class T, class U> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, U v) { a.push(v); return a;}template<class T, class U> priority_queue<T> &operator+=(priority_queue<T> &a, U v) { a.push(v); return a;}template<class T> set<T> &operator+=(set<T> &a, vector<T> v) { fora(d, v){a.insert(d);} return a;}template<class T, class U> auto operator+=(set<T> &a, U v) { return a.insert(v); }template<class T, class U> auto operator-=(set<T> &a, U v) { return a.erase(v); }template<class T, class U> auto operator+=(mset<T> &a, U v) { return a.insert(v); }template<class T, class U> set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) { a.insert(v); return a;}template<class T, class U> vector<T> &operator+=(vector<T> &a, U v) { a.push_back(v); return a;}template<class T, class U> vector<T> operator+(U v,const vector<T> &a) { vector<T> ret = a; ret.insert(ret.begin(), v); return ret;}template<class T> vector<T> operator+(const vector<T>& a, const vector<T>& b) { vector<T> ret; ret = a; fora(v, b){ret += v; } return ret;}template<class T> vector<T> &operator+=(vector<T> &a,const vector<T> &b) { rep(i, sz(b)) {/*こうしないとa+=aで両辺が増え続けてバグる*/ a.push_back(b[i]); } return a;}template<class T, class U> map<T, U> &operator+=(map<T, U> &a, map<T, U> &b) { for(auto&& bv : b) { a[bv.first] += bv.second; } return a;}template<class T, class U> vector<T> operator+(const vector<T> &a, const U& v) { vector<T> ret = a; ret += v; return ret;}template<class T, class U> auto operator+=(uset<T> &a, U v) { return a.insert(v); }
template<class T> vector<T> operator%(vector<T>& a, int v){ vi ret(sz(a)); rep(i,sz(a)){ ret[i] = a[i] % v; } return ret;}
template<class T> vector<T> operator%=(vector<T>& a, int v){ rep(i,sz(a)){ a[i] %= v; } return a;}
vi operator&(vi& a, vi& b){ assert(sz(a)==sz(b)); vi ret(sz(a)); rep(i,sz(a)){ ret[i] = min(a[i],b[i]); } return ret;}
template<class T> void operator+=(mset<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); }
template<class T> void operator+=(set<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); }
template<class T> void operator+=(vector<T> &a, set<T>& v) { for(auto&& u : v)a.emplace_back(u); }
template<class T> void operator+=(vector<T> &a, mset<T>& v) { for(auto&& u : v)a.emplace_back(u); }
template<class T> vector<T> &operator-=(vector<T> &a, vector <T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-="); deb(a); deb(b); exit(0); } rep(i, sz(a))a[i] -= b[i]; return a;}
template<class T> vector<T> operator-(vector<T> &a, vector<T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-"); deb(a); deb(b); ole(); } vector<T> res(sz(a)); rep(i, sz(a))res[i] = a[i] - b[i]; return res;}
//template<class T, class U> void operator*=(vector<T> &a, U b) { vector<T> ta = a; rep(b-1){ a+=ta; }}
template<typename T> void erase(vector<T> &v, unsigned ll i) { v.erase(v.begin() + i); }
template<typename T> void erase(vector<T> &v, unsigned ll s, unsigned ll e) { v.erase(v.begin() + s, v.begin() + e); }
template<typename T> void pop_front(vector<T> &v) { erase(v, 0); }
template<typename T> void entry(vector<T> &v, unsigned ll s, unsigned ll e) { erase(v, e, sz(v));erase(v,0,s);}
template<class T, class U> void erase(map<T, U> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); }
template<class T> void erase(set<T> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); }
template<typename T> void erasen(vector<T> &v, unsigned ll s, unsigned ll n) { v.erase(v.begin() + s, v.begin() + s + n); }
template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, U t) { v.insert(v.begin() + i, t); }
template<typename T, typename U> void push_front(vector<T> &v, U t) { v.insert(v.begin(), t); }
template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, vector<T> list) { for (auto &&va:list)v.insert(v.begin() + i++, va); }
vector<string> split(const string &a, const char deli) { string b = a + deli; ll l = 0, r = 0, n = b.size(); vector<string> res; rep(i, n) { if (b[i] == deli) { r = i; if (l < r)res.push_back(b.substr(l, r - l)); l = i + 1; } } return res;}
vector<string> split(const string &a, const string deli) { vector<string> res; ll kn = sz(deli); std::string::size_type Pos(a.find(deli)); ll l = 0; while (Pos != std::string::npos) { if (Pos - l)res.push_back(a.substr(l, Pos - l)); l = Pos + kn; Pos = a.find(deli, Pos + kn); } if (sz(a) - l)res.push_back(a.substr(l, sz(a) - l)); return res;}
ll stoi(string& s){return stol(s);}
#define assert_yn(yn_v, v); assert(yn_v == 0 || yn_v == v);yn_v = v;
//不完全な対策、現状はautohotkeyで対応
int yn_v = 0;
void yn(bool a) { assert_yn(yn_v, 1);if (a)cout << "yes" << endl; else cout << "no" << endl; }
void fyn(bool a) { assert_yn(yn_v, 1);yn(a); exit(0);}
void Yn(bool a) { assert_yn(yn_v, 2);if (a)cout << "Yes" << endl; else cout << "No" << endl; }
void fYn(bool a) { assert_yn(yn_v, 2);Yn(a); exit(0);}
void YN(bool a) { assert_yn(yn_v, 3);if (a)cout << "YES" << endl; else cout << "NO" << endl; }
void fYN(bool a) { assert_yn(yn_v, 3);YN(a); exit(0);}
int ab_v = 0;
void fAb(bool a) { assert_yn(ab_v, 1);if(a)cout<<"Alice"<<endl;else cout<<"Bob";}
void fAB(bool a) { assert_yn(yn_v, 2);if(a)cout<<"ALICE"<<endl;else cout<<"BOB";}
int pos_v = 0;
void Possible(bool a) { assert_yn(pos_v, 1);if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0);}
void POSSIBLE(bool a) { assert_yn(pos_v, 2);if (a)cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; exit(0);}
void fPossible(bool a) { assert_yn(pos_v, 1)Possible(a);exit(0);}
void fPOSSIBLE(bool a) { assert_yn(pos_v, 2)POSSIBLE(a);exit(0);}
template<typename T> class fixed_point : T {public: explicit constexpr fixed_point(T &&t) noexcept: T(std::forward<T>(t)) {} template<typename... Args> constexpr decltype(auto) operator()(Args &&... args) const { return T::operator()(*this, std::forward<Args>(args)...); }};template<typename T> static inline constexpr decltype(auto) fix(T &&t) noexcept { return fixed_point<T>{std::forward<T>(t)}; }
//未分類
//0,2,1 1番目と2番目の次元を入れ替える
template<class T> auto irekae(vector<vector<vector<T> > > &A, int x, int y, int z) {
#define irekae_resize_loop(a, b, c) resize(res,a,b,c);rep(i,a)rep(j,b)rep(k,c)
vector<vector<vector<T> > > res; if (x == 0 && y == 1 && z == 2) { res = A; } else if (x == 0 && y == 2 && z == 1) { irekae_resize_loop(sz(A), sz(A[0][0]), sz(A[0])) { res[i][j][k] = A[i][k][j]; } } else if (x == 1 && y == 0 && z == 2) { irekae_resize_loop(sz(A[0]), sz(A), sz(A[0][0])) { res[i][j][k] = A[j][i][k]; } } else if (x == 1 && y == 2 && z == 0) { irekae_resize_loop(sz(A[0]), sz(A[0][0]), sz(A)) { res[i][j][k] = A[k][i][j]; } } else if (x == 2 && y == 0 && z == 1) { irekae_resize_loop(sz(A[0][0]), sz(A), sz(A[0])) { res[i][j][k] = A[j][k][i]; } } else if (x == 2 && y == 1 && z == 0) { irekae_resize_loop(sz(A[0][0]), sz(A[0]), sz(A)) { res[i][j][k] = A[k][j][i]; } } return res;
#undef irekae_resize_loop
}
template<class T> auto irekae(vector<vector<T>>&A,int i=1,int j=0){ vvt(res,sz(A[0]),sz(A)); rep(i,sz(A)){ rep(j,sz(A[0])){ res[j][i]=A[i][j]; } } return res;}
//tou分割する
template<typename Iterable> vector<Iterable> table(const Iterable &a, int tou = 2) {int N = sz(a); vector<Iterable> res(tou); int hab = N / tou; vi lens(tou, hab); rep(i, N % tou) { lens[tou - 1 - i]++; } int l = 0; rep(i, tou) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;}
//長さn毎に分割する
template<typename Iterable> vector<Iterable> table_n(const Iterable &a, int len) { int N = sz(a); vector<Iterable> res(ceil(N, len)); vi lens(N / len, len); if (N % len)lens.push_back(N % len); int l = 0; rep(i, sz(lens)) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;}
//縦を返す
vi& geth(vvi()& a, int w){ static vi ret; ret.resize(sz(a)); rep(i,sz(a)){ ret[i] = a[i][w]; } return ret;}
//@起動時
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
srand((unsigned) clock() + (unsigned) time(NULL));
};
} initonv;
//#define pre prev
//#define nex next
//gra mll pr
//上下左右
const string udlr = "udlr";
string UDLR = "UDLR";//x4と連動 UDLR.find('U') := x4[0]
vc atoz = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x','y', 'z'};
vc AtoZ = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X','Y', 'Z'};
//右、上が正
constexpr ll h4[] = {1, -1, 0, 0};
constexpr ll w4[] = {0, 0, -1, 1};
constexpr ll h8[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr ll w8[] = {1, 0, -1, 0, 1, -1, 1, -1};
int mei_inc(int h, int w, int H, int W, int i) {while (++i < 4) { if (inside(h + h4[i], w + w4[i], H, W))return i; }return i;}
#define mei(nh, nw, h, w) for (int i = mei_inc(h, w, H, W, -1), nh = i<4? h + h4[i] : 0, nw = i<4? w + w4[i] : 0; i < 4; i=mei_inc(h,w,H,W,i), nh = h+h4[i], nw = w+w4[i])
int mei_inc8(int h, int w, int H, int W, int i) { while (++i < 8) { if (inside(h + h8[i], w + w8[i], H, W))return i; } return i;}
#define mei8(nh, nw, h, w) for (int i = mei_inc8(h, w, H, W, -1), nh = i<8? h + h8[i] : 0, nw = i<8? w + w8[i] : 0; i < 8; i=mei_inc8(h,w,H,W,i), nh = h+h8[i], nw = w+w8[i])
int mei_incv(int h, int w, int H, int W, int i, vp &p) { while (++i < sz(p)) { if (inside(h + p[i].fi, w + p[i].se, H, W))return i; } return i;}
#define meiv(nh, nw, h, w, p) for (int i = mei_incv(h, w, H, W, -1, p), nh = i<sz(p)? h + p[i].fi : 0, nw = i<sz(p)? w + p[i].se : 0; i < sz(p); i=mei_incv(h,w,H,W,i,p), nh = h+p[i].fi, nw = w+p[i].se)
//H*Wのグリッドを斜めに分割する
//右上
vector<vp> naname_list_ne(int H, int W) { vector<vp> res(H + W - 1); rep(sh, H) { int sw = 0; res[sh] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh--; nw++; if (0 <= nh && nw < W) { res[sh] += mp(nh, nw); }else{ break; } } } rep(sw, 1, W) { int sh = H - 1; res[H + sw - 1] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh--; nw++; if (0 <= nh && nw < W) { res[H + sw-1] += mp(nh, nw); }else{ break; } } } return res;}
//右下
vector<vp> naname_list_se(int H, int W) { vector<vp> res(H + W - 1); rep(sh, H) { int sw = 0; res[sh] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh++; nw++; if (0 <= nh && nh< H && nw < W) { res[sh] += mp(nh, nw); } else { break; } } } rep(sw, 1, W) { int sh = 0; res[H + sw - 1] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh++; nw++; if (0 <= nh && nh < H && nw < W) { res[H + sw - 1] += mp(nh, nw); } else { break; } } } return res;}
//グラフ内で #undef getid
//#define getidとしているため、ここを書き直したらgraphも書き直す
#define getid_2(h, w) ((h) * (W) + (w))
#define getid_1(p) ((p).first * W + (p).second)
#define getid(...) over2(__VA_ARGS__, getid_2, getid_1) (__VA_ARGS__)
#define getp(id) mp(id / W, id % W)
//#define set_shuffle() std::random_device seed_gen;std::mt19937 engine(seed_gen())
//#define shuffle(a) std::shuffle((a).begin(), (a).end(), engine);
//1980 開始からtime ms経っていたらtrue
vb bit_bool(int v, int len) { assert(bit(len) > v); vb ret(len); rep(i, len) { ret[i] = bget(v, i); } return ret;}
vi range(int l, int r) {vi ret;ret.resize(r - l);rep(v, l, r) {ret[v - l] = v;}return ret;}
vi range(int r) {return range(0, r);}
vi tov(vb& a){ vi ret; rep(i,sz(a)){ if(a[i])ret.push_back(i); } return ret;}
bool kaibun(const str& S){return S==rev(S);}
template<class T> vector<T> repeat(const vector<T> &A, int kaisu) { vector<T> ret; while (kaisu--) { ret += A; } return ret;}
#define rge range
#define upd update
//S[{s, t, d}]
#define strs slice_str
struct slice_str {
string S;
slice_str() {}
slice_str(const string &S) : S(S) {}
slice_str(int len, char c) : S(len, c) {}
auto size(){return S.size();}
char& operator[](int p) { return S[p]; }
string operator[](initializer_list<int> p) { if (sz(p) == 1) { return S.substr(0, *(p.begin())); } else if (sz(p) == 2) { int l = *(p.begin()); int r = *(next(p.begin())); return S.substr(l, r - l); } else { auto it = p.begin(); int s = *(it++); int t = *(it++); int d = *(it); if (d == -1) { int s_ = sz(S) - s - 1; int t_ = sz(S) - t - 1; return rev(S).substr(s_, t_ - s_); } else if (d < 0) { t = max(-1ll, t); string ret; while (s > t) { ret += S[s]; s += d; } return ret; } else { t = min(sz(S), t); string ret; while (s < t) { ret += S[s]; s += d; } return ret; } } }
operator string &() { return S; }
template<class T> void operator+=(const T &a) { S += a; }
bool operator==(const slice_str& rhs){return S==rhs.S;}
};
ostream &operator<<(ostream &os, const slice_str &a) { os << a.S; return os;}
istream &operator>>(istream &iss, const slice_str &a) { iss >> a.S; return iss;}
template<class T> bool can(const T &v, int i) { return 0 <= i && i < sz(v); }
#if __cplusplus >= 201703L
//template<class T> auto sum(int a, T v...) {return (v + ... + 0);}
#endif
#define VEC vector
#endif /*UNTITLED15_TEMPLATE_H*/
#endif
//† ←template終了
/*@formatter:on*/
//vectorで取れる要素数
//bool=> 1e9 * 8.32
//int => 1e8 * 2.6
//ll => 1e8 * 1.3
//3次元以上取るとメモリがヤバい
//static配列を使う
vvc (ba);
ll N, M, H, W;
vi A, B, C;
void solve() {
in(N);
vi A;
din(L, R);
na(A, N);
rsort(A);
if (all_of(sub(A, L), ==A[0])) {
int cou = count(A, A[0]);
out(A[0]);
int res = 0;
rep(i, L-1, R) {
if(A[i] == A[0]){
res += comi(cou, i);
}
}
out(res);
}else{
out(sum(A, L)/ (dou)L);
int all = 0;
int ned = 0;
{
int l = find(A, A[L-1]);
int rr = find_if(range(N), i , i > l && A[i]!= A[L-1]);
deb(l, rr);
ned = L - l;
all = rr - l;
}
deb(all, ned);
out(comi(all, ned));
}
}
auto my(ll n, vi &a) {
return 0;
}
auto sister(ll n, vi &a) {
ll ret = 0;
return ret;
}
signed main() {
solve();
#define arg n,a
#ifdef _DEBUG
bool bad = 0;
for (ll i = 0, ok = 1; i < k5 && ok; ++i) {
ll n = rand(1, 8);
vi a = ranv(n, 1, 10);
auto myres = my(arg);
auto res = sister(arg);
ok = myres == res;
if (!ok) {
out(arg);
cerr << "AC : " << res << endl;
cerr << "MY : " << myres << endl;
bad = 1;
break;
}
}
if (!bad) {
//solveを書き直す
//solveを呼び出す
}
if (was_deb && sz(res_mes)) {
cerr << "result = " << endl << res_mes << endl;
}
if (sz(message)) {
cerr << "****************************" << endl;
cerr << "Note." << endl;
cerr << message << endl;
cerr << "****************************" << endl;
}
#endif
return 0;
};
| a.cc:17:10: fatal error: boost/sort/pdqsort/pdqsort.hpp: No such file or directory
17 | #include <boost/sort/pdqsort/pdqsort.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
|
s903887574 | p03776 | Java | import java.util.*;
public class Main {
public static long gcd(long x,long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static long lcm(long x,long y){
return x*y/gcd(x,y);
}
public static long fac(long x){
if(x==0) return 1;
return x*fac(x-1);
}
public static long per(long x,long y){
return fac(x)/fac(x-y);
}
public static long com(long x,long y){
return per(x,y)/fac(y);
}
public static long com2(long x,long y){
if(y==0 || y==x) return 1;
if(x < y) return 0;
return com2(x-1,y-1)+com2(x-1,y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
long [] in = new long [a];
long [] [] pascal = new long [51][51];
for(int i=0;i<=50;i++){
for(int j=0;j<=i;j++){if(j==0 || j==i){pascal[i][j]=1;}
else{pascal[i][j]=pascal[i-1][j-1]+pascal[i-1][j];}
}
}
double d = 0;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
long e = 0;
long f = 0;
long g = 0;
for(int i=0;i<b;i++){d+=in[a-i-1];
}
d/=b;
for(int i=0;i<a;i++){if(in[i]==in[a-b]){f++;if(i>=a-b){g++;}}
}
if(d==in[a-1]){for(int i=b;i<=c;i++){e+=pascal[f][i];}}
else{e=pascal[f][g];}
System.out.println(d);
System.out.println(e);
}
}
| Main.java:52: error: incompatible types: possible lossy conversion from long to int
if(d==in[a-1]){for(int i=b;i<=c;i++){e+=pascal[f][i];}}
^
Main.java:53: error: incompatible types: possible lossy conversion from long to int
else{e=pascal[f][g];}
^
Main.java:53: error: incompatible types: possible lossy conversion from long to int
else{e=pascal[f][g];}
^
3 errors
|
s474718564 | p03776 | Java | import java.util.*;
public class Main {
public static long gcd(long x,long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static long lcm(long x,long y){
return x*y/gcd(x,y);
}
public static long fac(long x){
if(x==0) return 1;
return x*fac(x-1);
}
public static long per(long x,long y){
return fac(x)/fac(x-y);
}
public static long com(long x,long y){
return per(x,y)/fac(y);
}
public static long com2(long x,long y){
if(y==0 || y==x) return 1;
if(x < y) return 0;
return com2(x-1,y-1)+com2(x-1,y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
long [] in = new long [a];
double d = 0;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
long e = 0;
long f = 0;
long g = 0;
long k;
for(int i=0;i<h;i++){d+=in[a-i-1];
}
d/=b;
for(int i=0;i<a;i++){if(in[i]==in[a-b]){f++;if(i>=a-b){g++;}}
}
if(d==in[a-1]){for(int i=b;i<=c;i++){k=com2(f,i);e+=k;}}
else{e=com2(f,g);}
System.out.println(d);
System.out.println(e);
}
}
| Main.java:41: error: cannot find symbol
for(int i=0;i<h;i++){d+=in[a-i-1];
^
symbol: variable h
location: class Main
1 error
|
s174091643 | p03776 | Java | import java.util.*;
public class Main {
public static long gcd(long x,long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static long lcm(long x,long y){
return x*y/gcd(x,y);
}
public static long fac(long x){
if(x==0) return 1;
return x*fac(x-1);
}
public static long per(long x,long y){
return fac(x)/fac(x-y);
}
public static long com(long x,long y){
return per(x,y)/fac(y);
}
public static long com2(long x,long y){
if(y==0 || y==x) return 1;
if(x < y) return 0;
return com2(x-1,y-1)+com2(x-1,y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
long [] in = new long [a];
double d = 0;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
long e = 0;
long f = 0;
long g = 0;
long k;
for(int i=0;i<h;i++){d+=in[a-i-1];
}
d/=b;
for(int i=0;i<a;i++){if(in[i]==in[a-b]){f++;if(i>=a-b){g++;}}
}
if(d==in[a-1]){for(int i=h;i<=c;i++){k=com2(f,i);e+=k;}}
else{e=com2(f,g);}
System.out.println(d);
System.out.println(e);
}
}
| Main.java:41: error: cannot find symbol
for(int i=0;i<h;i++){d+=in[a-i-1];
^
symbol: variable h
location: class Main
Main.java:47: error: cannot find symbol
if(d==in[a-1]){for(int i=h;i<=c;i++){k=com2(f,i);e+=k;}}
^
symbol: variable h
location: class Main
2 errors
|
s658535436 | p03776 | Java | import java.util.*;
public class Main {
public static long gcd(long x,long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static long lcm(long x,long y){
return x*y/gcd(x,y);
}
public static long fac(long x){
if(x==0) return 1;
return x*fac(x-1);
}
public static long per(long x,long y){
return fac(x)/fac(x-y);
}
public static long com(long x,long y){
return per(x,y)/fac(y);
}
public static long com2(long x,long y){
if(y==0 || y==x) return 1;
if(x < y) return 0;
return com2(x-1,y-1)+com2(x-1,y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
long [] in = new long [a];
double d = 0;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
long e = 0;
long f = 0;
long g = 0;
import java.util.*;
public class Main {
public static long gcd(long x,long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static long lcm(long x,long y){
return x*y/gcd(x,y);
}
public static long fac(long x){
if(x==0) return 1;
return x*fac(x-1);
}
public static long per(long x,long y){
return fac(x)/fac(x-y);
}
public static long com(long x,long y){
return per(x,y)/fac(y);
}
public static long com2(long x,long y){
if(y==0 || y==x) return 1;
if(x < y) return 0;
return com2(x-1,y-1)+com2(x-1,y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
long b = sc.nextLong();
long c = sc.nextLong();
long [] in = new long [a];
double d = 0;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
long e = 0;
long f = 0;
long g = 0;
long k;
for(int i=0;i<h;i++){d+=in[a-i-1];
}
d/=b;
for(int i=0;i<a;i++){if(in[i]==in[a-h]){f++;if(i>=a-h){g++;}}
}
if(d==in[a-1]){for(int i=h;i<=j;i++){k=com2(f,i);e+=k;}}
else{e=com2(f,g);}
System.out.println(d);
System.out.println(e);
}
} | Main.java:40: error: illegal start of expression
import java.util.*;
^
Main.java:40: error: <identifier> expected
import java.util.*;
^
Main.java:40: error: illegal start of expression
import java.util.*;
^
Main.java:41: error: illegal start of expression
public class Main {
^
Main.java:91: error: reached end of file while parsing
}
^
5 errors
|
s238165320 | p03776 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
ll comb[52][52];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n, a, b;
cin >> n >> a >> b;
vector<ll> v(n);
rep(i, n) cin >> v[i];
sort(all(v)); reverse(all(v));
ll sum = 0;
rep(i, a) sum += v[i];
cout << (double)sum / a << '\n';
int cnt = 0;
rep(i, b) if (v[i] == v[a - 1]) cnt++;
int use = 0;
rep(i, a) if (v[i] > v[a - 1]) use++;
comb[0][0] = 1;
for (int i = 1; i <= n; i++) {
rep(j, i + 1) {
comb[i][j] += comb[i - 1][j];
if (j != 0) comb[i][j] += comb[i - 1][j - 1];
}
}
ll ans = comb[cnt][i];
if (sum == v[a - 1] * a) for (int i = a - use + 1; i <= cnt; i++) ans += comb[cnt][i];
cout << ans << '\n';
} | a.cc: In function 'int main()':
a.cc:65:28: error: 'i' was not declared in this scope
65 | ll ans = comb[cnt][i];
| ^
|
s494580908 | p03776 | Java | import java.util.*;
public class Main {
public static long gcd(long x,long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static long lcm(long x,long y){
return x*y/gcd(x,y);
}
public static long fac(long x){
if(x==0) return 1;
return x*fac(x-1);
}
public static long per(long x,long y){
return fac(x)/fac(x-y);
}
public static long com(long x,long y){
return per(x,y)/fac(y);
}
public static long com2(long x,long y){
if(y==0) return 1;
if(y==x) return 1;
return com2(x-1,y-1)+com2(x-1,y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
long [] in = new long [a];
double d = 0;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
long e = 0;
long f = 0;
long g = 0;
for(int i=0;i<b;i++){d+=in[a-i-1];
}
d/=b;
for(int i=0;i<a;i++){if(in[i]==in[a-b]){f++;if(i>=a-b){g++;}}
}
if(d=in[a-1]){for(long i=g;i<=f;i++){e+=com(f,i);}}
else{e=com(f,g);}
System.out.println(d);
System.out.println(e);
}
}
| Main.java:46: error: incompatible types: double cannot be converted to boolean
if(d=in[a-1]){for(long i=g;i<=f;i++){e+=com(f,i);}}
^
1 error
|
s258897684 | p03776 | Java | import java.util.*;
public class Main {
public static Long gcd(Long x,Long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static Long lcm(Long x,Long y){
return x*(y/gcd(x,y));
}
public static Long fac(Long x){
if(x==0) return x+1;
return x*fac(x-1);
}
public static Long per(Long x,Long y){
return fac(x)/fac(x-y);
}
public static Long com(Long x,Long y){
return per(x,y)/fac(y);
}
public static Long com2(Long x,Long y){
if(y==0) return y+1;
if(y==x) return com2(x,0);
return com2(x-1,y-1)+com2(x-1,y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
Long [] in = new Long [a];
double d = 0;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
Long e = in[0]-in[0];
Long f = e;
Long g = e;
for(int i=0;i<b;i++){d+=in[a-i-1];
}
d/=b;
for(int i=0;i<a;i++){if(i>=a-c && in[i]==in[a-b]){f++;if(i>=a-b){g++;}}
}
if(g==b){for(Long i=g;i<=f;i++){e+=com2(f,i);}}
else{e+=com2(f,g);}
System.out.println(d);
System.out.println(e);
}
}
| Main.java:23: error: incompatible types: int cannot be converted to Long
if(y==x) return com2(x,0);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
|
s770008253 | p03776 | C++ | #include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <unordered_map>
#include <queue>
#include <set>
#include <bitset>
#include <regex>
using namespace std;
#define rep(i,n) for(lint i = 0; i < n; i++)
#define repr(i,n) for(lint i = n - 1; i >= 0; i--)
#define repi(i,ini,n) for(lint i = ini; i < n; i++)
#define repir(i,ini,n) for(lint i = n-1; i >= ini; i--)
#define repb(i,start,end) for(lint i = start; i <= end; i++)
#define repbr(i,start,end) for(lint i = end; i >= start; i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rg(v, n) v.begin(), v.begin()+n
#define rrg(v, n) v.rbegin(), v.rbegin()+n
#define ret return 0;
namespace {
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
struct xy
{
lint x, y;
xy() :x(0), y(0) {}
xy(lint _x, lint _y) : x(_x), y(_y) {}
xy operator+(const xy& p) const
{
return xy(x + p.x, y + p.y);
}
bool operator<(xy p) const
{
if (y == p.y)
return x < p.x;
return y < p.y;
}
};
struct xyd
{
ld x, y;
xyd() :x(0), y(0) {}
xyd(long double _x, long double _y) : x(_x), y(_y) {}
};
using vec = vector<lint>;
using vecd = vector<ld>;
using vecs = vector<string>;
using vecp = vector<xy>;
template<class T> using vect = vector<T>;
class vec2 : public vector<vector<lint>>
{
public:
vec2() {}
vec2(lint h, lint w) : vector(h, vector<lint>(w)) {}
vec2(lint h, lint w, lint v) : vector(h, vector<lint>(w, v)) {}
};
const ulint mod = 1000000007;
const double pi = 3.141592653589793238462;
const lint intmax = 9223372036854775807;
const ld eps = 0.0000001;
const lint alpn = 'z' - 'a' + 1;
template<class It>
constexpr auto acc(It begin, It end)
{
return accumulate(begin, end, It::value_type(0));
}
template<class T>
constexpr auto msum(T arg0)
{
return arg0;
}
template<class T, class ...Types>
constexpr auto msum(T arg0, Types ...args)
{
static_assert(sizeof...(args) > 0, "arg err");
return arg0 + msum(args...);
}
template<class It>
constexpr typename It::value_type mmax(It begin, It end)
{
return *max_element(begin, end);
}
template<class It>
constexpr typename It::value_type mmin(It begin, It end)
{
return *min_element(begin, end);
}
template<class T>
constexpr auto mmax(T arg)
{
return arg;
}
template<class T, class ...Types>
constexpr auto mmax(T arg0, Types ...args)
{
using promote_t = decltype(msum(arg0, args...));
return max(static_cast<promote_t>(arg0), static_cast<promote_t>(mmax(args...)));
}
template<class T>
constexpr auto mmin(T arg)
{
return arg;
}
template<class T, class ...Types>
constexpr auto mmin(T arg0, Types ...args)
{
using promote_t = decltype(msum(arg0, args...));
return min(static_cast<promote_t>(arg0), static_cast<promote_t>(mmin(args...)));
}
constexpr auto clamp(lint val, lint left, lint right)
{
return mmax(mmin(val, right), left);
}
constexpr lint div2(lint p, lint q)
{
return (p + q - 1) / q;
}
lint gcd(lint a, lint b) {
while (1) {
if (a < b) swap(a, b);
if (!b) break;
a %= b;
}
return a;
}
lint lcm(lint a, lint b)
{
return a / gcd(a, b) * b;
}
lint powInt(lint a, lint b)
{
if (b == 0)
{
return 1;
}
if (b == 1)
{
return a;
}
lint tmp = powInt(a, b / 2);
return (b % 2 == 1 ? a * tmp * tmp : tmp * tmp);
}
template<class T>
T sgn(T val)
{
if (val == T(0))
return T(0);
if (val < 0)
return T(-1);
if (val > 0)
return T(1);
}
template<class T>
constexpr auto modK_belowN(T k, T MOD, T n)
{
return (n + MOD - k - 1) / MOD;
}
template<class It, class T>
bool exist(It begin, It end, const T& val)
{
return find(begin, end, val) != end;
}
template<class It, class Pr>
bool exist_if(It begin, It end, Pr pred)
{
return find_if(begin, end, pred) != end;
}
template<class T>
bool between(T val, T l, T r)
{
return (val >= l) && (val <= r);
}
template<class It>
auto carr(It begin, It end) {
vec c;
c.push_back(1);
auto before = *begin;
for (auto it = begin + 1; it != end; it++) {
if (before != *it) {
c.push_back(0);
before = *it;
}
c.back()++;
}
return c;
}
template<class T>
struct nval {
lint n;
T val;
nval() : n(0) {};
nval(lint _n, T _val) : n(_n), val(_val) {};
};
template<class It>
auto carr2(It begin, It end) {
using T = nval<remove_reference_t<decltype(*begin)>>;
vect<T> c;
c.push_back(T(1, *begin));
auto before = *begin;
for (auto it = begin + 1; it != end; it++) {
if (before != *it) {
c.push_back(T(0, *it));
before = *it;
}
c.back().n++;
}
return c;
}
template<class It, class ...T>
void sort2(It begin, It end, T ...p)
{
using val_t = remove_reference_t<decltype(*begin)>;
sort(begin, end, [p...](val_t a, val_t b) {
bool neq[] = { (a.*p != b.*p)... };
bool sg[] = { (a.*p < b.*p)... };
rep(i, sizeof...(p)) {
if (neq[i])
{
return sg[i];
}
}
return false;
});
}
template<size_t _K, size_t _N, class ...Types, size_t ...indices>
auto constexpr __ModKtuple_Impl(index_sequence<indices...>, tuple<Types...> args)
{
return make_tuple(get<indices * _N + _K>(args)...);
}
template<size_t K, size_t N, class ...Types>
auto constexpr ModKtuple(Types ...args)
{
return __ModKtuple_Impl<K, N>(make_index_sequence<modK_belowN(K, N, sizeof...(args))>{}, forward_as_tuple(args...));
}
template<class It, class ...T, class ...Tsg, size_t ...indices>
void __sort3_Impl(It begin, It end, tuple<T...> p, tuple<Tsg...> sgf, index_sequence<indices...>)
{
using val_t = remove_reference_t<decltype(*begin)>;
sort(begin, end, [p, sgf](val_t a, val_t b) {
bool neq[] = { (a.*(get<indices>(p)) != b.*(get<indices>(p)))... };
bool sg[] = { ((a.*(get<indices>(p)) < b.*(get<indices>(p))) != (get<indices>(sgf))) ... };
rep(i, sizeof...(indices)) {
if (neq[i])
{
return sg[i];
}
}
return false;
});
}
template<class It, class ...T>
void sort3(It begin, It end, T ...p)
{
using val_t = remove_reference_t<decltype(*begin)>;
auto p_forward = ModKtuple<0, 2>(p...);
auto sgf_forward = ModKtuple<1, 2>(p...);
constexpr auto p_sz = tuple_size<decltype(p_forward)>::value;
constexpr auto sgf_sz = tuple_size<decltype(sgf_forward)>::value;
static_assert(p_sz == sgf_sz, "arg err");
__sort3_Impl(begin, end, p_forward, sgf_forward, make_index_sequence<p_sz>{});
}
char caesar(char s, lint key)
{
if (between(s, 'A', 'Z'))
{
return (s - 'A' + key) % alpn + 'A';
}
if (between(s, 'a', 'z'))
{
return (s - 'a' + key) % alpn + 'a';
}
return s;
}
string caesar(string s, lint key)
{
rep(i, s.length())
s[i] = caesar(s[i], key);
return s;
}
template<class It, class It2>
auto spacel(It i, It2 end)
{
if (i + 1 == end)
{
return '\n';
}
else
{
return ' ';
}
}
template<class It>
bool next_comb(lint n, It begin, It end)
{
auto rend = make_reverse_iterator(begin);
auto rbegin = make_reverse_iterator(end);
auto rit = rbegin;
for (; rit != rend; rit++)
{
if ((rit == rbegin && (*rit) + 1 != n) ||
(rit != rbegin && (*rit) + 1 != *(rit - 1)))
{
goto found;
}
}
return false;
found:;
(*rit)++;
for (auto it = rit.base(); it != end; it++)
{
(*it) = (*(it - 1)) + 1;
}
return true;
}
ostream& setp(ostream& ost)
{
cout << setprecision(60) << fixed;
return ost;
}
#ifdef _LOCAL
auto& dbg = cout;
#else
struct dummy_cout
{
template<class T>
dummy_cout& operator<<(T&& op)
{
return *this;
}
using endl_t = basic_ostream<char, char_traits<char>>;
dummy_cout& operator<<(endl_t& (*)(endl_t&))
{
return *this;
}
};
dummy_cout dbg;
#endif
};
lint nCr(lint n, lint r)
{
lint ans = 1;
//repb(i, n - r + 1, n)
// ans *= i;
//repb(i, 1, r)
// ans /= i;
lint i = n - r + 1, j = 1;
while (i <= n || j <= r)
{
while (j <= r && ans % j == 0)
{
ans /= j;
j++;
}
if (i <= n)
{
ans *= i;
i++;
}
}
return ans;
}
int main()
{
//repb(i, 1, 50)
//{
// cout << i << ' ' << nCr(50, i) << endl;
//}
lint n, a, b;
cin >> n >> a >> b;
vec v(n);
rep(i, n)
cin >> v[i];
sort(rall(v));
lint sum = acc(rg(v, a));
lint bo = v[a - 1];
cout << setp << ld(sum) / a << endl;
lint ans = 0;
lint c = count(all(v), bo);
repb(i, a, b)
{
lint cs = count(rg(v, i), bo);
ans += nCr(c, cs);
if (v[i - 1] != v[0])
break;
if (c == cs)
break;
}
cout << ans << endl;
return 0;
}
| a.cc: In instantiation of 'constexpr auto {anonymous}::acc(It, It) [with It = __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >]':
a.cc:452:16: required from here
452 | lint sum = acc(rg(v, a));
| ~~~^~~~~~~~~~
a.cc:85:61: error: dependent-name 'It::value_type' is parsed as a non-type, but instantiation yields a type
85 | return accumulate(begin, end, It::value_type(0));
| ~~~~~~~~~~~~~~^~~
a.cc:85:61: note: say 'typename It::value_type' if a type is meant
|
s950107177 | p03776 | C++ | #include<iostream>
#include<algorithm>
#include<vector>
using namepsace std;
int factor(int n) {
int ret=1;
for(int i = n; i > 1; i++)
ret *= i;
return ret;
}
int main() {
int N,A,B;
cin >> N >> A >> B;
vector<int> vec = new vector<int>(N);
for(int i = 0; i < N; i++) {
cin >> vec[i];
}
sort(vec.begin(), vec.end());
int current_dupl = 1;
int count = 0;
int choice = 1;
int sum;
for(int i = vec.size()-1; i >= 0; i++){
if(count < A || (current_dupl > 1 && count < B)) {
sum += vec[i];
if((i < (vec.size()-1)) && (vec[i] == vec[i-1])){
current_dupl++;
}
else {
choice += factor(current_dupl);
current_dupl = 1;
}
}
count++;
}
return 0;
} | a.cc:4:7: error: expected nested-name-specifier before 'namepsace'
4 | using namepsace std;
| ^~~~~~~~~
a.cc: In function 'int main()':
a.cc:14:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
14 | cin >> N >> A >> B;
| ^~~
| std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
62 | extern istream cin; ///< Linked to standard input
| ^~~
a.cc:15:3: error: 'vector' was not declared in this scope
15 | vector<int> vec = new vector<int>(N);
| ^~~~~~
a.cc:15:3: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
from a.cc:3:
/usr/include/c++/14/bits/stl_vector.h:428:11: note: 'std::vector'
428 | class vector : protected _Vector_base<_Tp, _Alloc>
| ^~~~~~
/usr/include/c++/14/vector:93:13: note: 'std::pmr::vector'
93 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
| ^~~~~~
a.cc:15:10: error: expected primary-expression before 'int'
15 | vector<int> vec = new vector<int>(N);
| ^~~
a.cc:17:12: error: 'vec' was not declared in this scope
17 | cin >> vec[i];
| ^~~
a.cc:19:8: error: 'vec' was not declared in this scope
19 | sort(vec.begin(), vec.end());
| ^~~
a.cc:19:3: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
19 | sort(vec.begin(), vec.end());
| ^~~~
| std::sort
In file included from /usr/include/c++/14/algorithm:86,
from a.cc:2:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
| ^~~~
|
s327204005 | p03776 | Java | import java.util.*;
public class Main {
public static Long gcd(Long x,Long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static Long lcm(Long x,Long y){
return x*y/gcd(x,y);
}
public static Long fac(Long x){
if(x==0) return x+1;
return x*fac(x-1);
}
public static Long per(Long x,Long y){
return fac(x)/fac(x-y);
}
public static Long com(Long x,Long y){
return per(x,y)/fac(y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
Long [] in = new Long [a];
double d = 0;
Long e = d-d;
Long f = e;
Long g = e;
f++;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
for(int i=0;i<b;i++){d+=in[a-i-1];
}
d/=b;
for(int i=0;i<a;i++){if(i>=a-c && in[i]==in[a-b]){f++;if(i>=a-b){g++;}}
}
for(Long i=g;i<=f;i++){e+=com(f,i);}
System.out.println(d);
System.out.println(e);
}
}
| Main.java:28: error: incompatible types: double cannot be converted to Long
Long e = d-d;
^
1 error
|
s246458430 | p03776 | Java | import java.util.*;
public class Main {
public static Long gcd(Long x,Long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static Long lcm(Long x,Long y){
return x*y/gcd(x,y);
}
public static Long fac(Long x){
if(x==0) return x+1;
return x*fac(x-1);
}
public static Long per(Long x,Long y){
return fac(x)/fac(x-y);
}
public static Long com(Long x,Long y){
return per(x,y)/fac(y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
Long c = sc.nextInt();
Long [] in = new int [a];
double d = 0;
Long e = c-c;
Long f = e;
Long g = e;
f++;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
for(int i=0;i<b;i++){d+=in[a-i-1];
}
d/=b;
for(int i=0;i<a;i++){if(i>=a-c && in[i]==in[a-b]){f++;if(i>=a-b){g++;}}
}
for(Long i=g;i<=f;i++){e+=com(f,i);}
System.out.println(d);
System.out.println(e);
}
}
| Main.java:25: error: incompatible types: int cannot be converted to Long
Long c = sc.nextInt();
^
Main.java:26: error: incompatible types: int[] cannot be converted to Long[]
Long [] in = new int [a];
^
2 errors
|
s955481212 | p03776 | Java | import java.util.*;
public class Main {
public static Long gcd(Long x,Long y){
if(x < y) return gcd(y, x);
if(y == 0) return x;
return gcd(y, x % y);
}
public static Long lcm(Long x,Long y){
return x*y/gcd(x,y);
}
public static Long fac(Long x){
if(x==0) return x+1;
return x*fac(x-1);
}
public static Long per(Long x,Long y){
return fac(x)/fac(x-y);
}
public static Long com(Long x,Long y){
return per(x,y)/fac(y);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
Long b = sc.nextLong();
Long c = sc.nextLong();
Long [] in = new int [a];
double d = 0;
Long e = a-a;
Long f = e;
Long g = e;
f++;
for(int i=0;i<a;i++){
in[i] = sc.nextLong();
}
Arrays.sort(in);
for(int i=0;i<b;i++){d+=in[a-i-1];
}
d/=b;
for(int i=0;i<a;i++){if(i>=a-c && in[i]==in[a-b]){f++;if(i>=a-b){g++;}}
}
for(Long i=g;i<=f;i++){e+=com(f,i);}
System.out.println(d);
System.out.println(e);
}
} | Main.java:26: error: incompatible types: int[] cannot be converted to Long[]
Long [] in = new int [a];
^
Main.java:28: error: incompatible types: int cannot be converted to Long
Long e = a-a;
^
Main.java:39: error: incompatible types: possible lossy conversion from long to int
for(int i=0;i<a;i++){if(i>=a-c && in[i]==in[a-b]){f++;if(i>=a-b){g++;}}
^
3 errors
|
s476868881 | p03776 | C++ | #include <bits/stdc++.h>
using namespace std;
long long comb(long long n, long long r) {
long long ret = 1;
for (long long i = n; i > n-r; i--) ret *= i;
for (long long i = 2; i <= r; i++) ret /= i;
return ret;
}
long long Pow(long long x, long long n) {
if (n == 0) return 1;
if (n % 2 == 1) return (x * Pow(x, n - 1));
long long t = Pow(x, n / 2);
return (t * t);
}
int main() {
int n, a, b;
cin >> n >> a >> b;
map<long long, long long> mp;
vector<pair<long long, long long>> data;
for (int i = 0; i < n; i++) {
long long e; cin >> e; mp[e]++;
}
for (const auto& e : mp) data.emplace_back(e);
sort(data.begin(), data.end(), greater<pair<long long, long long>>());
long long cnt = 0;
long long sum = 0, ans = 0;
double ave;
for (int i = 0; i < (int)data.size(); i++) {
long long v, c; tie(v, c) = data[i];
if (a <= c && i == 0) {
ave = v;
ans = Pow(2LL, min(b, c)) - 1;
break;
}
if (cnt + c < a) {
cnt += c; sum += (c * v);
} else {
int add = a - cnt;
sum += (v * add);
ave = (double)sum / a;
ans = comb(c, add);
break;
}
}
assert(0.00 <= ave && 0 <= ans);
cout << fixed << setprecision(10) << ave << '\n';
cout << ans << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:36:31: error: no matching function for call to 'min(int&, long long int&)'
36 | ans = Pow(2LL, min(b, c)) - 1;
| ~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:36:31: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
36 | ans = Pow(2LL, min(b, c)) - 1;
| ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:36:31: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
36 | ans = Pow(2LL, min(b, c)) - 1;
| ~~~^~~~~~
|
s497713868 | p03776 | C++ | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a) for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a) for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y) for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}
// dsu start
vi root(200001,0);
vi size(200001,1);
int find(int x){while(x!=root[x])x = root[x];return x;}
bool same(int a,int b){return find(a)==find(b);}
void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
// dsu end
vi vis(200001,0);
vi adj[200001];
ll C[101][101]; // C[n][k] -> nCk
void comb_table(int N){
for(int i=0;i<=N;++i){
for(int j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
//string bitstring = std::bitset< 3 >( 7 ).to_string(); <bits> (num)
//srand(time(0));
//cin.tie(NULL);
//cout.tie(NULL);
int n;
cin>>n;
comb_table(100);
int a,b;
cin>>a>>b;
vl vec;
mapii mps,mps2,mps3;
for(int i=0; i<n; ++i)
{
ll x;
cin>>x;
vec.pb(x);
++mps[x];
}
sort(all(vec));
double avg = 0.0;
reverse(all(vec));
//cout<<"\n"<<"\n";
//print(vec);
double sum = 0.0;
int idx = 0;
int x=vec[0];
int flag = 0;
for(int i=0; i<a; ++i)
{
sum+=(double)vec[i];
if(vec[i]==x)
++flag;
}
ll ans = 0;
avg = sum/a;
if(flag==a)
{
int y = mps[x];
for(int i=a; i<=b; ++i)
{
ans+=C[y][i];
}
cout<<fixed<<avg<<"\n";
cout<<ans<<"\n";
return 0;
}
ans = 1;
for(int i=0; i<a; ++i)
{
++mps2[vec[i]];
}
for(int i=0; i<a; ++i)
{
//cout<<vec[i]<<" "<<C[mps[vec[i]]][mps2[vec[i]]]<<"\n";
if(!mps3[vec[i]])
{
ans*=C[mps[vec[i]]][mps2[vec[i]]];
++mps3[vec[i]];
}
}
cout<<fixed<<avg<<"\n";
cout<<ans<<"\n";
}#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a) for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a) for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y) for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"
ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}
// dsu start
vi root(200001,0);
vi size(200001,1);
int find(int x){while(x!=root[x])x = root[x];return x;}
bool same(int a,int b){return find(a)==find(b);}
void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
// dsu end
vi vis(200001,0);
vi adj[200001];
ll C[101][101]; // C[n][k] -> nCk
void comb_table(int N){
for(int i=0;i<=N;++i){
for(int j=0;j<=i;++j){
if(j==0 or j==i){
C[i][j]=1;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
//string bitstring = std::bitset< 3 >( 7 ).to_string(); <bits> (num)
//srand(time(0));
//cin.tie(NULL);
//cout.tie(NULL);
int n;
cin>>n;
comb_table(100);
int a,b;
cin>>a>>b;
vl vec;
mapii mps,mps2,mps3;
for(int i=0; i<n; ++i)
{
ll x;
cin>>x;
vec.pb(x);
++mps[x];
}
sort(all(vec));
double avg = 0.0;
reverse(all(vec));
//cout<<"\n"<<"\n";
//print(vec);
double sum = 0.0;
int idx = 0;
int x=vec[0];
int flag = 0;
for(int i=0; i<a; ++i)
{
sum+=(double)vec[i];
if(vec[i]==x)
++flag;
}
ll ans = 0;
avg = sum/a;
if(flag==a)
{
int y = mps[x];
for(int i=a; i<=b; ++i)
{
ans+=C[y][i];
}
cout<<fixed<<avg<<"\n";
cout<<ans<<"\n";
return 0;
}
ans = 1;
for(int i=0; i<a; ++i)
{
++mps2[vec[i]];
}
for(int i=0; i<a; ++i)
{
//cout<<vec[i]<<" "<<C[mps[vec[i]]][mps2[vec[i]]]<<"\n";
if(!mps3[vec[i]])
{
ans*=C[mps[vec[i]]][mps2[vec[i]]];
++mps3[vec[i]];
}
}
cout<<fixed<<avg<<"\n";
cout<<ans<<"\n";
} | a.cc:144:2: error: stray '#' in program
144 | }#include <bits/stdc++.h>
| ^
a.cc: In function 'void unite(int, int)':
a.cc:58:53: error: reference to 'size' is ambiguous
58 | void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
272 | size(const _Tp (&)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
262 | size(const _Container& __cont) noexcept(noexcept(__cont.size()))
| ^~~~
a.cc:55:4: note: 'std::vector<int> size'
55 | vi size(200001,1);
| ^~~~
a.cc:58:61: error: reference to 'size' is ambiguous
58 | void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
| ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
272 | size(const _Tp (&)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
262 | size(const _Container& __cont) noexcept(noexcept(__cont.size()))
| ^~~~
a.cc:55:4: note: 'std::vector<int> size'
55 | vi size(200001,1);
| ^~~~
a.cc:58:79: error: reference to 'size' is ambiguous
58 | void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
| ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
272 | size(const _Tp (&)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
262 | size(const _Container& __cont) noexcept(noexcept(__cont.size()))
| ^~~~
a.cc:55:4: note: 'std::vector<int> size'
55 | vi size(200001,1);
| ^~~~
a.cc:58:90: error: reference to 'size' is ambiguous
58 | void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
| ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
272 | size(const _Tp (&)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
262 | size(const _Container& __cont) noexcept(noexcept(__cont.size()))
| ^~~~
a.cc:55:4: note: 'std::vector<int> size'
55 | vi size(200001,1);
| ^~~~
a.cc: At global scope:
a.cc:144:3: error: 'include' does not name a type
144 | }#include <bits/stdc++.h>
| ^~~~~~~
a.cc:149:11: error: redefinition of 'const int INF'
149 | const int INF = 1e9;
| ^~~
a.cc:6:11: note: 'const int INF' previously defined here
6 | const int INF = 1e9;
| ^~~
a.cc:180:10: error: redefinition of 'std::ifstream fin'
180 | ifstream fin("input.txt");
| ^~~
a.cc:37:10: note: 'std::ifstream fin' previously declared here
37 | ifstream fin("input.txt");
| ^~~
a.cc:181:10: error: redefinition of 'std::ofstream fout'
181 | ofstream fout("output.txt");
| ^~~~
a.cc:38:10: note: 'std::ofstream fout' previously declared here
38 | ofstream fout("output.txt");
| ^~~~
a.cc:188:4: error: redefinition of 'long long int fast_exp(long long int, long long int)'
188 | ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
| ^~~~~~~~
a.cc:45:4: note: 'long long int fast_exp(long long int, long long int)' previously defined here
45 | ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
| ^~~~~~~~
a.cc:189:5: error: redefinition of 'int gcd(int, int)'
189 | int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
| ^~~
a.cc:46:5: note: 'int gcd(int, int)' previously defined here
46 | int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
| ^~~
a.cc:190:5: error: redefinition of 'int val(char)'
190 | int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
| ^~~
a.cc:47:5: note: 'int val(char)' previously defined here
47 | int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
| ^~~
a.cc:191:4: error: redefinition of 'long long int pows(int, int)'
191 | ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
| ^~~~
a.cc:48:4: note: 'long long int pows(int, int)' previously defined here
48 | ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
| ^~~~
a.cc:192:4: error: redefinition of 'long long int logx(long long int, long long int)'
192 | ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
| ^~~~
a.cc:49:4: note: 'long long int logx(long long int, long long int)' previously defined here
49 | ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
| ^~~~
a.cc:193:4: error: redefinition of 'long long int divisibles(long long int, long long int, long long int)'
193 | ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
| ^~~~~~~~~~
a.cc:50:4: note: 'long long int divisibles(long long int, long long int, long long int)' previously defined here
50 | ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
| ^~~~~~~~~~
a.cc:194:8: error: redefinition of 'std::string bitstring(int, int)'
194 | string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}
| ^~~~~~~~~
a.cc:51:8: note: 'std::string bitstring(int, int)' previously defined here
51 | string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}
| ^~~~~~~~~
a.cc:197:4: error: redefinition of 'std::vector<int> root'
197 | vi root(200001,0);
| ^~~~
a.cc:54:4: note: 'std::vector<int> root' previously declared here
54 | vi root(200001,0);
| ^~~~
a.cc:198:4: error: redefinition of 'std::vector<int> size'
198 | vi size(200001,1);
| ^~~~
a.cc:55:4: note: 'std::vector<int> size' previously declared here
55 | vi size(200001,1);
| ^~~~
a.cc:199:5: error: redefinition of 'int find(int)'
199 | int find(int x){while(x!=root[x])x = root[x];return x;}
| ^~~~
a.cc:56:5: note: 'int find(int)' previously defined here
56 | int find(int x){while(x!=root[x])x = root[x];return x;}
| ^~~~
a.cc:200:6: error: redefinition of 'bool same(int, int)'
200 | bool same(int a,int b){return find(a)==find(b);}
| ^~~~
a.cc:57:6: note: 'bool same(int, int)' previously defined here
57 | bool same(int a,int b){return find(a)==find(b);}
| ^~~~
a.cc:201:6: error: redefinition of 'void unite(int, int)'
201 | void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
| ^~~~~
a.cc:58:6: note: 'void unite(int, int)' previously defined here
58 | void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
| ^~~~~
a.cc: In function 'void unite(int, int)':
a.cc:201:53: error: reference to 'size' is ambiguous
201 | void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
| ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
272 | size(const _Tp (&)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
262 | size(const _Container& __cont) noexcept(noexcept(__cont.size()))
| ^~~~
a.cc:55:4: note: 'std::vector<int> size'
55 | vi size(200001,1);
| ^~~~
a.cc:201:61: error: reference to 'size' is ambiguous
201 | void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}
| ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
272 | size(const _Tp (&)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
262 | size(const _Container& __cont) noexcept(noexcept(__cont.size()))
|
s319892237 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main(){
COMinit();
int N,A,B; cin>>N>>A>>B;
vi C(N);
rep(i,0,N) cin>>C[i];
sort(ALL(C),vi,greater<int>());
int sum=0;
rep(i,0,A) sum+=C[i];
double ans=sum*1.0/A;
printf("%.10lf\n",ans);
int Ans=1;
int E=0,D=0;
rep(i,0,A){
if(C[i]==C[A-1]) D++;
}
rep(i,A,N){
if(C[i]==C[A-1]) E++;
}
Ans*=COM(D+E,D);
if(C[0]==C[A-1]){
REP(i,A+1,min(B,D+E)){
Ans*=COM(D+E,i);
Ans%=MOD;
}
}
cout<<Ans<<endl;
}
| a.cc: In function 'int main()':
a.cc:47:17: error: expected primary-expression before ',' token
47 | sort(ALL(C),vi,greater<int>());
| ^
|
s078570313 | p03776 | C++ | #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
long long COMB(int n, int k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
int cnt = 0;
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0)cnt++;
}
if (cnt != 1)return false;
else return n != 1;
}
int gcd(int x, int y) {
if (y == 0)return x;
return gcd(y, x % y);
}
int lcm(int x, int y) {
return x / gcd(x, y) * y;
}
int mod_pow(int x, int y, int m) {
int res = 1;
while (y) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i; res %= mod;
}
return res;
}
int comb(int x, int y) {
if (y > x)return 0;
return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
class UnionFind {
protected:
int* par, * rank, * size;
public:
UnionFind(unsigned int size) {
par = new int[size];
rank = new int[size];
this->size = new int[size];
rep(i, size) {
par[i] = i;
rank[i] = 0;
this->size[i] = 1;
}
}
int find(int n) {
if (par[n] == n)return n;
return par[n] = find(par[n]);
}
void unite(int n, int m) {
n = find(n);
m = find(m);
if (n == m)return;
if (rank[n] < rank[m]) {
par[n] = m;
size[m] += size[n];
}
else {
par[m] = n;
size[n] += size[m];
if (rank[n] == rank[m])rank[n]++;
}
}
bool same(int n, int m) {
return find(n) == find(m);
}
int getsize(int n) {
return size[find(n)];
}
};
int n, a, b;
int v[55];
map<int, int>mp;
signed main() {
cin >> n >> a >> b;
rep(i, n)cin >> v[i];
sort(a, a + n);
reverse(a, a + n);
double ave = 0;
rep(i, a)ave += v[i];
cout << double(ave / a) << endl;
if (v[0] == v[a - 1]) {
int ans = 0;
for (int i = a; i <= b; i++) {
ans += comb(n, i);
}
cout << ans << endl;
}
else {
int memoa = 0, memob = 0;
rep(i, n) {
if (v[i] == v[a - 1])memoa++;
}
rep(i, a) {
if (v[i] == v[a - 1])memob++;
}
cout << comb(memoa, memob) << endl;
}
ggr
} | In file included from /usr/include/c++/14/algorithm:61,
from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h: In instantiation of 'void std::reverse(_BIter, _BIter) [with _BIter = long long int]':
a.cc:138:9: required from here
138 | reverse(a, a + n);
| ~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1089:63: error: no matching function for call to '__iterator_category(long long int&)'
1089 | std::__reverse(__first, __last, std::__iterator_category(__first));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_iterator_base_funcs.h:66,
from /usr/include/c++/14/string:47,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: note: candidate: 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&)'
239 | __iterator_category(const _Iter&)
| ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: note: template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_iterator_base_types.h: In substitution of 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&) [with _Iter = long long int]':
/usr/include/c++/14/bits/stl_algo.h:1089:63: required from 'void std::reverse(_BIter, _BIter) [with _BIter = long long int]'
1089 | std::__reverse(__first, __last, std::__iterator_category(__first));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
a.cc:138:9: required from here
138 | reverse(a, a + n);
| ~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: error: no type named 'iterator_category' in 'struct std::iterator_traits<long long int>'
239 | __iterator_category(const _Iter&)
| ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h: In instantiation of 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/14/bits/stl_algo.h:1817:25: required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1817 | std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1908 | std::__final_insertion_sort(__first, __last, __comp);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4772:18: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = long long int]'
4772 | std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:137:6: required from here
137 | sort(a, a + n);
| ~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1780:17: error: no type named 'value_type' in 'struct std::iterator_traits<long long int>'
1780 | __val = _GLIBCXX_MOVE(*__i);
| ^~~~~
In file included from /usr/include/c++/14/bits/exception_ptr.h:41,
from /usr/include/c++/14/exception:166,
from /usr/include/c++/14/ios:41:
/usr/include/c++/14/bits/stl_algo.h:1780:25: error: invalid type argument of unary '*' (have 'long long int')
1780 | __val = _GLIBCXX_MOVE(*__i);
| ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1782:15: error: invalid type argument of unary '*' (have 'long long int')
1782 | *__first = _GLIBCXX_MOVE(__val);
| ^~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = long long int; _Iterator2 = long long int]':
/usr/include/c++/14/bits/stl_algo.h:1777:14: required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1777 | if (__comp(__i, __first))
| ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25: required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1817 | std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1908 | std::__final_insertion_sort(__first, __last, __comp);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4772:18: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = long long int]'
4772 | std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:137:6: required from here
137 | sort(a, a + n);
| ~~~~^~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:45:16: error: invalid type argument of unary '*' (have 'long long int')
45 | { return *__it1 < *__it2; }
| ^~~~~~
/usr/include/c++/14/bits/predefined_ops.h:45:25: error: invalid type argument of unary '*' (have 'long long int')
45 | { return *__it1 < *__it2; }
| ^~~~~~
In file included from /usr/include/c++/14/bits/stl_algo.h:61:
/usr/include/c++/14/bits/stl_heap.h: In instantiation of 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/14/bits/stl_algo.h:1593:23: required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1593 | std::__make_heap(__first, __middle, __comp);
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1868:25: required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1868 | std::__heap_select(__first, __middle, __last, __comp);
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1884:27: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = long long int; _Size = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1884 | std::__partial_sort(__first, __last, __last, __comp);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1905:25: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1905 | std::__introsort_loop(__first, __last,
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
1906 | std::__lg(__last - __first) * 2,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1907 | __comp);
| ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4772:18: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = long long int]'
4772 | std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:137:6: required from here
137 | sort(a, a + n);
| ~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:344:11: error: no type named 'value_type' in 'struct std::iterator_traits<long long int>'
344 | _ValueType;
| ^~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:346:11: error: no type named 'difference_type' in 'struct std::iterator_traits<long long int>'
346 | _DistanceType;
| ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h: In instantiation of 'void std::__pop_heap(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/14/bits/stl_algo.h:1596:19: required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
1596 | std::__pop_heap(__first, __middle, __i, __comp);
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl |
s529204901 | p03776 | C++ | #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " <<to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
ll n,a,b;
vector<double>v;
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
if(K < 0 || N < K) return 0;
T ret = 1;
for(T i = 1; i <= K; ++i) {
ret *= N--;
ret /= i;
}
return ret;
}
void solve(){
cin>>n>>a>>b;
v.resize(n);
rep(i,n)cin>>v[i];
sort(v.rbegin(),v.rend());
ll c=0;
double sum=0;
rep(i,a)sum+=v[i];
sum/=a;
int pos=0;
map<double,ll>mp;
while(pos<n){
mp[-v[pos++]]++;
}
if(v[0]==v[a-1]){
for(ll i=a;i<=y+1;++i){
c+=binomial<ll>(mp[-v[i-1]],i);
}
}
else {
ll cal=0;
for(auto e:mp){
if(e.first==-v[a-1])break;
cal+=e.second;
}
c=binomial<ll>(mp[-v[a-1]],a-cal);
}
cout<<sum<<"\n";
cout<<c<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(15);
solve();
return 0;
}
| a.cc: In function 'void solve()':
a.cc:166:19: error: 'y' was not declared in this scope
166 | for(ll i=a;i<=y+1;++i){
| ^
|
s525687334 | p03776 | C++ | #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " <<to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
ll n,a,b;
vector<double>v;
bool C(double mid,int k){
double sum=0;
rep(i,k)sum+=v[i]-mid;
return sum>=0;
}
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
if(K < 0 || N < K) return 0;
T ret = 1;
for(T i = 1; i <= K; ++i) {
ret *= N--;
ret /= i;
}
return ret;
}
void solve(){
cin>>n>>a>>b;
v.resize(n);
rep(i,n)cin>>v[i];
sort(v.rbegin(),v.rend());
ll c=0;
double l=1.0,r=1e15+1;
rep(i,100){
double mid=(l+r)/2.0;
if(C(mid,a))l=mid;
else r=mid;
}
int pos=0;
map<double,ll>mp;
while(pos<n){
if(!mp.count(v[pos])&&mp.size()+1>a)break;
mp[v[pos++]]++;
}
int y=-1;
rep(i,b){
if(v[0]!=v[i]){
y=i;
break;
}
}
ll x=a;
if(y>=a-1){
for(ll i=a;i<=y;++i){
c+=binomial<ll>(n,i);
}
}
else {
c=1;
rep(i,a)c*=x[i];
}
cout<<l<<"\n";
cout<<c<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(15);
solve();
return 0;
}
| a.cc: In function 'void solve()':
a.cc:188:17: error: invalid types 'll {aka long long int}[int]' for array subscript
188 | rep(i,a)c*=x[i];
| ^
|
s687258646 | p03776 | C++ | #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " <<to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
ll n,a,b;
vector<double>v;
bool C(double mid,int k){
double sum=0;
rep(i,k)sum+=v[i]-mid;
return sum>=0;
}
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
if(K < 0 || N < K) return 0;
T ret = 1;
for(T i = 1; i <= K; ++i) {
ret *= N--;
ret /= i;
}
return ret;
}
void solve(){
cin>>n>>a>>b;
v.resize(n);
rep(i,n)cin>>v[i];
sort(v.rbegin(),v.rend());
ll c=1;
double l=1.0,r=1e15+1;
rep(i,100){
double mid=(l+r)/2.0;
if(C(mid,a))l=mid;
else r=mid;
}
int pos=0;
map<double,ll>mp;
while(pos<n){
if(!mp.count(v[pos])&&mp.size()+1>a)break;
mp[v[pos++]]++;
}
vector<ll>x;
for(auto e:mp){
x.pb(e.second);
}
sort(x.rbegin(),x.rend());
int y=-1;
rep(i,b){
if(v[0]!=v[i]){
y=i;
break;
}
}
if(y>=0){
c=0;
for(ll i=a;i<=b;++i){
c+=binomial<ll>(n,i);
}
}
else for(auto e:mp)c+=binomial<ll>(n,e);
cout<<l<<"\n";
cout<<c<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(15);
solve();
return 0;
}
| a.cc: In function 'void solve()':
a.cc:191:40: error: cannot convert 'std::pair<const double, long long int>' to 'll' {aka 'long long int'}
191 | else for(auto e:mp)c+=binomial<ll>(n,e);
| ^
| |
| std::pair<const double, long long int>
a.cc:145:31: note: initializing argument 2 of 'T binomial(ll, ll) [with T = long long int; ll = long long int]'
145 | T binomial(int64_t N, int64_t K) {
| ^
|
s817214184 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b,n;
long long c[51];double d[51];
ll f[51][51];
bool cmp(long long a,long long b)
{
return a>b;
}
void fi()
{
memset(f,0,sizeof(f));
f[0][0]=1;
for(int i=1;i<=50;i++)
{
f[i][0]=1;
for(int j=1;j<=i;j++)
f[i][j]=f[i-1][j-1]+f[i-1][j];
}
}
int main()
{
scanf("%d%d%d",&n,&a,&b);
for(int i=0;i<n;i++)
scanf("%lld",&c[i]);
sort(c,c+n,cmp);
for(int i=1;i<=n;i++)
d[i]=d[i-1]+c[i-1];
int p=upper_bound(c,c+n,c[a-1],greater<int>())-c;
int q=lower_bound(c,c+n,c[a-1],greater<int>())-c;
fi();
if(a==1&&p==1)
{
printf("%.10lf\n",d[1]/1);
printf("1\n");
}
else if((a>=2&&c[a-1]==c[0])||(a==1&&c[1]==c[0]))
{
printf("%.10lf\n",d[1]/1);
ll sum=0;
for(int i=a;i<=b;i++)
sum+=f[p][i];
printf("%lld\n",sum);
}
else
{
printf("%.10lf\n",(double)d[a]/a);
printf("%lld\n",f[p-q][a-q]);
}
return 0;
| a.cc: In function 'int main()':
a.cc:54:13: error: expected '}' at end of input
54 | return 0;
| ^
a.cc:26:1: note: to match this '{'
26 | {
| ^
|
s883656690 | p03776 | C++ | #include <bits/stdc++.h>
#include <quadmath.h>
#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;
static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static map<type_index, const char* const> scanType = {
{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};
template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);
ll_ll dp[51][51];
int main(int argc, char* argv[]) {
ll n, a, b;
cin >> n >> a >> b;
vec<ll> v(n);
scan(v);
rep(i, 0, 51) rep(j, 0, 51) dp[i][j] = make_pair(-1, -1);
dp[0][0].first = 0;
dp[0][0].second = 1;
rep(i, 0, n) rep(j, 0, n) {
if (dp[i][j].first == -1) continue;
if (dp[i + 1][j].first == -1) dp[i + 1][j] = make_pair(0, 0);
if (dp[i + 1][j].first < dp[i][j].first) {
dp[i + 1][j].first = dp[i][j].first;
dp[i + 1][j].second = dp[i][j].second;
} else if (dp[i + 1][j].first == dp[i][j].first) {
dp[i + 1][j].second += dp[i][j].second;
}
if (dp[i + 1][j + 1].first == -1) dp[i + 1][j + 1] = make_pair(0, 0);
if (dp[i + 1][j + 1].first < (dp[i][j].first + v[i])) {
dp[i + 1][j + 1].first = dp[i][j].first + v[i];
dp[i + 1][j + 1].second = dp[i][j].second;
} else if (dp[i + 1][j + 1].first == (dp[i][j].first + v[i])) {
dp[i + 1][j + 1].second += dp[i][j].second;
}
}
__float128 max_avg = 0.0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
if (avg > max_avg) max_avg = avg;
// chmax(max_avg, avg);
}
ll sum = 0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
if (abs<__float128>(max_avg - avg) <= EPS) sum += dp[n][i].second;
}
putf(double(max_avg), 20);
put(sum);
return 0;
}
template <class T> static void scan(vector<T>& v) {
auto tFormat = scanType[typeid(T)];
for (T& n : v) {
scanf(tFormat, &n);
}
}
static void scan(vector<string>& v, bool isWord) {
if (isWord) {
for (auto& n : v) {
cin >> n;
}
return;
}
int i = 0, size = v.size();
string s;
getline(cin, s);
if (s.size() != 0) {
i++;
v[0] = s;
}
for (; i < size; ++i) {
getline(cin, v[i]);
}
}
template <class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }
template <class T> inline T lcm(T a, T b) {
T c = min(a, b), d = max(a, b);
return c * (d / gcd(c, d));
}
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
std::fill((T*)arr, (T*)(arr + N), val);
}
template <class T> T mod(T a, T m) { return (a % m + m) % m; }
| In file included from /usr/include/c++/14/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
from a.cc:1:
/usr/include/c++/14/complex: In instantiation of '_Tp std::__complex_abs(const complex<_Tp>&) [with _Tp = __float128]':
/usr/include/c++/14/complex:892:56: required from '_Tp std::abs(const complex<_Tp>&) [with _Tp = __float128]'
892 | abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); }
| ~~~~~~~~~~~~~^~~~~~~~~~~~~
a.cc:93:24: required from here
93 | if (abs<__float128>(max_avg - avg) <= EPS) sum += dp[n][i].second;
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/complex:876:24: error: call of overloaded 'sqrt(__float128)' is ambiguous
876 | return __s * sqrt(__x * __x + __y * __y);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/features.h:523,
from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
from /usr/include/c++/14/cassert:43,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:176:1: note: candidate: 'double sqrt(double)'
176 | __MATHCALL (sqrt,, (_Mdouble_ __x));
| ^~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:114:
/usr/include/c++/14/cmath:442:3: note: candidate: 'constexpr float std::sqrt(float)'
442 | sqrt(float __x)
| ^~~~
/usr/include/c++/14/cmath:446:3: note: candidate: 'constexpr long double std::sqrt(long double)'
446 | sqrt(long double __x)
| ^~~~
|
s033115806 | p03776 | C++ | #include <bits/stdc++.h>
#include <quadmath.h>
#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;
static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static map<type_index, const char* const> scanType = {
{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};
template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);
ll_ll dp[51][51];
int main(int argc, char* argv[]) {
ll n, a, b;
cin >> n >> a >> b;
vec<ll> v(n);
scan(v);
rep(i, 0, 51) rep(j, 0, 51) dp[i][j] = make_pair(-1, -1);
dp[0][0].first = 0;
dp[0][0].second = 1;
rep(i, 0, n) rep(j, 0, n) {
if (dp[i][j].first == -1) continue;
if (dp[i + 1][j].first == -1) dp[i + 1][j] = make_pair(0, 0);
if (dp[i + 1][j].first < dp[i][j].first) {
dp[i + 1][j].first = dp[i][j].first;
dp[i + 1][j].second = dp[i][j].second;
} else if (dp[i + 1][j].first == dp[i][j].first) {
dp[i + 1][j].second += dp[i][j].second;
}
if (dp[i + 1][j + 1].first == -1) dp[i + 1][j + 1] = make_pair(0, 0);
if (dp[i + 1][j + 1].first < (dp[i][j].first + v[i])) {
dp[i + 1][j + 1].first = dp[i][j].first + v[i];
dp[i + 1][j + 1].second = dp[i][j].second;
} else if (dp[i + 1][j + 1].first == (dp[i][j].first + v[i])) {
dp[i + 1][j + 1].second += dp[i][j].second;
}
}
__float128 max_avg = 0.0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
chmax(max_avg, avg);
}
ll sum = 0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
if (abs<__float128>(max_avg - avg) <= EPS) sum += dp[n][i].second;
}
putf(double(max_avg), 20);
put(sum);
return 0;
}
template <class T> static void scan(vector<T>& v) {
auto tFormat = scanType[typeid(T)];
for (T& n : v) {
scanf(tFormat, &n);
}
}
static void scan(vector<string>& v, bool isWord) {
if (isWord) {
for (auto& n : v) {
cin >> n;
}
return;
}
int i = 0, size = v.size();
string s;
getline(cin, s);
if (s.size() != 0) {
i++;
v[0] = s;
}
for (; i < size; ++i) {
getline(cin, v[i]);
}
}
template <class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }
template <class T> inline T lcm(T a, T b) {
T c = min(a, b), d = max(a, b);
return c * (d / gcd(c, d));
}
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
std::fill((T*)arr, (T*)(arr + N), val);
}
template <class T> T mod(T a, T m) { return (a % m + m) % m; }
| In file included from /usr/include/c++/14/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
from a.cc:1:
/usr/include/c++/14/complex: In instantiation of '_Tp std::__complex_abs(const complex<_Tp>&) [with _Tp = __float128]':
/usr/include/c++/14/complex:892:56: required from '_Tp std::abs(const complex<_Tp>&) [with _Tp = __float128]'
892 | abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); }
| ~~~~~~~~~~~~~^~~~~~~~~~~~~
a.cc:92:24: required from here
92 | if (abs<__float128>(max_avg - avg) <= EPS) sum += dp[n][i].second;
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/complex:876:24: error: call of overloaded 'sqrt(__float128)' is ambiguous
876 | return __s * sqrt(__x * __x + __y * __y);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/features.h:523,
from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
from /usr/include/c++/14/cassert:43,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:176:1: note: candidate: 'double sqrt(double)'
176 | __MATHCALL (sqrt,, (_Mdouble_ __x));
| ^~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:114:
/usr/include/c++/14/cmath:442:3: note: candidate: 'constexpr float std::sqrt(float)'
442 | sqrt(float __x)
| ^~~~
/usr/include/c++/14/cmath:446:3: note: candidate: 'constexpr long double std::sqrt(long double)'
446 | sqrt(long double __x)
| ^~~~
|
s104340783 | p03776 | C++ | #include <bits/stdc++.h>
#include <quadmath.h>
#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;
static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static map<type_index, const char* const> scanType = {
{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};
template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);
ll_ll dp[51][51];
int main(int argc, char* argv[]) {
ll n, a, b;
cin >> n >> a >> b;
vec<ll> v(n);
scan(v);
rep(i, 0, 51) rep(j, 0, 51) dp[i][j] = make_pair(-1, -1);
dp[0][0].first = 0;
dp[0][0].second = 1;
rep(i, 0, n) rep(j, 0, n) {
if (dp[i][j].first == -1) continue;
if (dp[i + 1][j].first == -1) dp[i + 1][j] = make_pair(0, 0);
if (dp[i + 1][j].first < dp[i][j].first) {
dp[i + 1][j].first = dp[i][j].first;
dp[i + 1][j].second = dp[i][j].second;
} else if (dp[i + 1][j].first == dp[i][j].first) {
dp[i + 1][j].second += dp[i][j].second;
}
if (dp[i + 1][j + 1].first == -1) dp[i + 1][j + 1] = make_pair(0, 0);
if (dp[i + 1][j + 1].first < (dp[i][j].first + v[i])) {
dp[i + 1][j + 1].first = dp[i][j].first + v[i];
dp[i + 1][j + 1].second = dp[i][j].second;
} else if (dp[i + 1][j + 1].first == (dp[i][j].first + v[i])) {
dp[i + 1][j + 1].second += dp[i][j].second;
}
}
__float128 max_avg = 0.0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
chmax(max_avg, avg);
}
ll sum = 0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
if (abs<__float128>(max_avg - avg) <= EPS) sum += dp[n][i].second;
}
putf(max_avg, 20);
put(sum);
return 0;
}
template <class T> static void scan(vector<T>& v) {
auto tFormat = scanType[typeid(T)];
for (T& n : v) {
scanf(tFormat, &n);
}
}
static void scan(vector<string>& v, bool isWord) {
if (isWord) {
for (auto& n : v) {
cin >> n;
}
return;
}
int i = 0, size = v.size();
string s;
getline(cin, s);
if (s.size() != 0) {
i++;
v[0] = s;
}
for (; i < size; ++i) {
getline(cin, v[i]);
}
}
template <class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }
template <class T> inline T lcm(T a, T b) {
T c = min(a, b), d = max(a, b);
return c * (d / gcd(c, d));
}
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
std::fill((T*)arr, (T*)(arr + N), val);
}
template <class T> T mod(T a, T m) { return (a % m + m) % m; }
| a.cc: In function 'int main(int, char**)':
a.cc:17:60: error: ambiguous overload for 'operator<<' (operand types are 'std::basic_ostream<char>' and '__float128')
17 | #define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~ ~~~
| |
| std::basic_ostream<char>
a.cc:94:3: note: in expansion of macro 'putf'
94 | putf(max_avg, 20);
| ^~~~
In file included from /usr/include/c++/14/istream:41,
from /usr/include/c++/14/sstream:40,
from /usr/include/c++/14/complex:45,
from /usr/include/c++/14/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
from a.cc:1:
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
174 | operator<<(long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
178 | operator<<(unsigned long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
182 | operator<<(bool __n)
| ^~~~~~~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
96 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
189 | operator<<(unsigned short __n)
| ^~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
110 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
200 | operator<<(unsigned int __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
211 | operator<<(long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
215 | operator<<(unsigned long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
231 | operator<<(double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
235 | operator<<(float __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
243 | operator<<(long double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:573:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, char) [with _CharT = char; _Traits = char_traits<char>]'
573 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:579:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char) [with _Traits = char_traits<char>]'
579 | operator<<(basic_ostream<char, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:590:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, signed char) [with _Traits = char_traits<char>]'
590 | operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:595:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, unsigned char) [with _Traits = char_traits<char>]'
595 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
| ^~~~~~~~
/usr/include/c++/14/complex: In instantiation of '_Tp std::__complex_abs(const complex<_Tp>&) [with _Tp = __float128]':
/usr/include/c++/14/complex:892:56: required from '_Tp std::abs(const complex<_Tp>&) [with _Tp = __float128]'
892 | abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); }
| ~~~~~~~~~~~~~^~~~~~~~~~~~~
a.cc:92:24: required from here
92 | if (abs<__float128>(max_avg - avg) <= EPS) sum += dp[n][i].second;
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/complex:876:24: error: call of overloaded 'sqrt(__float128)' is ambiguous
876 | return __s * sqrt(__x * __x + __y * __y);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/features.h:523,
from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
from /usr/include/c++/14/cassert:43,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:176:1: note: candidate: 'double sqrt(double)'
176 | __MATHCALL (sqrt,, (_Mdouble_ __x));
| ^~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:114:
/usr/include/c++/14/cmath:442:3: note: candidate: 'constexpr float std::sqrt(float)'
442 | sqrt(float __x)
| ^~~~
/usr/include/c++/14/cmath:446:3: note: candidate: 'constexpr long double std::sqrt(long double)'
446 | sqrt(long double __x)
| ^~~~
|
s322372871 | p03776 | C++ | #include <bits/stdc++.h>
#include <quadmath.h>
#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;
static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static map<type_index, const char* const> scanType = {
{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};
template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);
ll_ll dp[51][51];
int main(int argc, char* argv[]) {
ll n, a, b;
cin >> n >> a >> b;
vec<ll> v(n);
scan(v);
rep(i, 0, 51) rep(j, 0, 51) dp[i][j] = make_pair(-1, -1);
dp[0][0].first = 0;
dp[0][0].second = 1;
rep(i, 0, n) rep(j, 0, n) {
if (dp[i][j].first == -1) continue;
if (dp[i + 1][j].first == -1) dp[i + 1][j] = make_pair(0, 0);
if (dp[i + 1][j].first < dp[i][j].first) {
dp[i + 1][j].first = dp[i][j].first;
dp[i + 1][j].second = dp[i][j].second;
} else if (dp[i + 1][j].first == dp[i][j].first) {
dp[i + 1][j].second += dp[i][j].second;
}
if (dp[i + 1][j + 1].first == -1) dp[i + 1][j + 1] = make_pair(0, 0);
if (dp[i + 1][j + 1].first < (dp[i][j].first + v[i])) {
dp[i + 1][j + 1].first = dp[i][j].first + v[i];
dp[i + 1][j + 1].second = dp[i][j].second;
} else if (dp[i + 1][j + 1].first == (dp[i][j].first + v[i])) {
dp[i + 1][j + 1].second += dp[i][j].second;
}
}
__float128 max_avg = 0.0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
chmax(max_avg, avg);
}
ll sum = 0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
if (abs(max_avg - avg) <= EPS) sum += dp[n][i].second;
}
putf(max_avg, 20);
put(sum);
return 0;
}
template <class T> static void scan(vector<T>& v) {
auto tFormat = scanType[typeid(T)];
for (T& n : v) {
scanf(tFormat, &n);
}
}
static void scan(vector<string>& v, bool isWord) {
if (isWord) {
for (auto& n : v) {
cin >> n;
}
return;
}
int i = 0, size = v.size();
string s;
getline(cin, s);
if (s.size() != 0) {
i++;
v[0] = s;
}
for (; i < size; ++i) {
getline(cin, v[i]);
}
}
template <class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }
template <class T> inline T lcm(T a, T b) {
T c = min(a, b), d = max(a, b);
return c * (d / gcd(c, d));
}
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
std::fill((T*)arr, (T*)(arr + N), val);
}
template <class T> T mod(T a, T m) { return (a % m + m) % m; }
| a.cc: In function 'int main(int, char**)':
a.cc:17:60: error: ambiguous overload for 'operator<<' (operand types are 'std::basic_ostream<char>' and '__float128')
17 | #define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~ ~~~
| |
| std::basic_ostream<char>
a.cc:94:3: note: in expansion of macro 'putf'
94 | putf(max_avg, 20);
| ^~~~
In file included from /usr/include/c++/14/istream:41,
from /usr/include/c++/14/sstream:40,
from /usr/include/c++/14/complex:45,
from /usr/include/c++/14/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
from a.cc:1:
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
174 | operator<<(long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
178 | operator<<(unsigned long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
182 | operator<<(bool __n)
| ^~~~~~~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
96 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
189 | operator<<(unsigned short __n)
| ^~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
110 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
200 | operator<<(unsigned int __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
211 | operator<<(long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
215 | operator<<(unsigned long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
231 | operator<<(double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
235 | operator<<(float __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
243 | operator<<(long double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:573:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, char) [with _CharT = char; _Traits = char_traits<char>]'
573 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:579:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char) [with _Traits = char_traits<char>]'
579 | operator<<(basic_ostream<char, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:590:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, signed char) [with _Traits = char_traits<char>]'
590 | operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:595:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, unsigned char) [with _Traits = char_traits<char>]'
595 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
| ^~~~~~~~
|
s280370980 | p03776 | C++ | #include <bits/stdc++.h>
#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;
static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static map<type_index, const char* const> scanType = {
{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};
template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);
ll_ll dp[51][51];
int main(int argc, char* argv[]) {
ll n, a, b;
cin >> n >> a >> b;
vec<ll> v(n);
scan(v);
rep(i, 0, 51) rep(j, 0, 51) dp[i][j] = make_pair(-1, -1);
dp[0][0].first = 0;
dp[0][0].second = 1;
rep(i, 0, n) rep(j, 0, n) {
if (dp[i][j].first == -1) continue;
if (dp[i + 1][j].first == -1) dp[i + 1][j] = make_pair(0, 0);
if (dp[i + 1][j].first < dp[i][j].first) {
dp[i + 1][j].first = dp[i][j].first;
dp[i + 1][j].second = dp[i][j].second;
} else if (dp[i + 1][j].first == dp[i][j].first) {
dp[i + 1][j].second += dp[i][j].second;
}
if (dp[i + 1][j + 1].first == -1) dp[i + 1][j + 1] = make_pair(0, 0);
if (dp[i + 1][j + 1].first < dp[i][j].first + v[i]) {
dp[i + 1][j + 1].first = dp[i][j].first + v[i];
dp[i + 1][j + 1].second = dp[i][j].second;
} else if (dp[i + 1][j + 1].first == dp[i][j].first + v[i]) {
dp[i + 1][j + 1].second += dp[i][j].second;
}
}
__float128 max_avg = 0.0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
chmax(max_avg, avg);
}
ll sum = 0;
rep(i, a, b + 1) {
ll value = dp[n][i].first;
__float128 avg = double(value) / i;
if (abs(max_avg - avg) < EPS) sum += dp[n][i].second;
}
putf(max_avg, 20);
put(sum);
return 0;
}
template <class T> static void scan(vector<T>& v) {
auto tFormat = scanType[typeid(T)];
for (T& n : v) {
scanf(tFormat, &n);
}
}
static void scan(vector<string>& v, bool isWord) {
if (isWord) {
for (auto& n : v) {
cin >> n;
}
return;
}
int i = 0, size = v.size();
string s;
getline(cin, s);
if (s.size() != 0) {
i++;
v[0] = s;
}
for (; i < size; ++i) {
getline(cin, v[i]);
}
}
template <class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }
template <class T> inline T lcm(T a, T b) {
T c = min(a, b), d = max(a, b);
return c * (d / gcd(c, d));
}
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
std::fill((T*)arr, (T*)(arr + N), val);
}
template <class T> T mod(T a, T m) { return (a % m + m) % m; }
| a.cc: In function 'int main(int, char**)':
a.cc:16:60: error: ambiguous overload for 'operator<<' (operand types are 'std::basic_ostream<char>' and '__float128')
16 | #define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~ ~~~
| |
| std::basic_ostream<char>
a.cc:93:3: note: in expansion of macro 'putf'
93 | putf(max_avg, 20);
| ^~~~
In file included from /usr/include/c++/14/istream:41,
from /usr/include/c++/14/sstream:40,
from /usr/include/c++/14/complex:45,
from /usr/include/c++/14/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
from a.cc:1:
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
174 | operator<<(long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
178 | operator<<(unsigned long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
182 | operator<<(bool __n)
| ^~~~~~~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
96 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
189 | operator<<(unsigned short __n)
| ^~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
110 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
200 | operator<<(unsigned int __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
211 | operator<<(long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
215 | operator<<(unsigned long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
231 | operator<<(double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
235 | operator<<(float __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
243 | operator<<(long double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:573:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, char) [with _CharT = char; _Traits = char_traits<char>]'
573 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:579:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char) [with _Traits = char_traits<char>]'
579 | operator<<(basic_ostream<char, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:590:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, signed char) [with _Traits = char_traits<char>]'
590 | operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:595:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, unsigned char) [with _Traits = char_traits<char>]'
595 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
| ^~~~~~~~
|
s981032271 | p03776 | Java | import java.util.*;
public class ABC057D {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int min = in.nextInt();
int max = in.nextInt();
long[] nums = new long[n];
for( int i = 0; i < n; i++ ) nums[i] = in.nextLong();
Arrays.sort(nums);
boolean same = true;
long ave = 0;
int totalPostSame = 0;
int postSame = 0;
for( int i = n-1; i >= 0; i-- ) {
// flag if not everything is the same
if( i >= 1 ) if( nums[i] != nums[i-1] ) same = false;
// get average
if( i >= n-min ) ave += nums[i];
// count nums that are the same as the one at A
if( nums[i] == nums[n-min] ) {
totalPostSame++;
if( i >= n-min ) postSame++; // everything before A (sorted)
}
}
System.out.println((double)ave/min);
// pascals triangle
long[][] pascal = new long[n+1][n+1];
pascal[0][0] = 1;
for( int i = 1; i <= n; i++ ) {
for( int j = 0; j <= i; j++ ) {
if( i == j ) pascal[i][j] = 1;
else if( j == 0 ) pascal[i][j] = 1;
else pascal[i][j] = pascal[i-1][j-1] + pascal[i-1][j];
}
}
System.out.println(Arrays.deepToString(pascal));
if( same ) {
long total = 0;
for( int i = min; i <= max; i++ ) {
total += pascal[i][min];
}
System.out.println(total);
} else {
System.out.println(pascal[totalPostSame][postSame]);
}
}
} | Main.java:3: error: class ABC057D is public, should be declared in a file named ABC057D.java
public class ABC057D {
^
1 error
|
s757146336 | p03776 | C++ | from collections import defaultdict
import operator as op
from functools import reduce
def ncr(n, r):
r = min(r, n-r)
numer = reduce(op.mul, range(n, n-r, -1), 1)
denom = reduce(op.mul, range(1, r+1), 1)
if n == 0 or n < r:
return 0
return numer // denom
n, a, b = map(int, input().split())
v = sorted(list(map(int, input().split())))
mydict = defaultdict(lambda: 0)
mynewdict = defaultdict(lambda: 0)
for num in v:
mydict[num]+=1
new_v = v[n-a:]
for num in new_v:
mynewdict[num]+=1
x = 1
for key in mynewdict:
x *= ncr(mydict[key], mynewdict[key])
ave = sum(new_v)/a
print("{0:.16f}".format(ave))
if ave in v[:n-a]:
for i in range(1,b-a+1):
x += ncr(mydict[ave],i+a)
print(x) | a.cc:1:1: error: 'from' does not name a type
1 | from collections import defaultdict
| ^~~~
|
s362711537 | p03776 | C++ | #include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
long long com[51][51];
void combination(int n){
//combination
com[0][0] = 1;
for (int i = 1; i <=n; ++i) {
for (int j = 0; j <= i; ++j) {
com[i][j] += com[i-1][j];
if (j > 0) com[i][j] += com[i-1][j-1];
}
}
}
int main(void){
int N, a, b;
cin >> N >> a >> b;
combination(N);
vector<long long> v(N);
for (int i = 0; i < N; ++i)
cin >> v[i];
sort(v.begin(), v.end(), greater<long long>());
long long sum = 0;
for (int i = 0; i < a; ++i){
sum += v[i];
}
double ave = (double)(sum) / a;
long long res = 0;
int num = 0;
for (int i = 0; i < N; ++i) if (v[i] == v[a-1]) ++num;
if (v[0] == v[a-1]) {
for (int j = a; j <= b; ++j) {
res += c[num][j];
}
}
else {
int ans = 0;
for (int i = 0; i < a; ++i) if (v[i] == v[a-1]) ans++;
res = c[num][ans];
}
cout << fixed << setprecision(20) << ave << endl;
cout << res << endl;
}
| a.cc: In function 'int main()':
a.cc:50:20: error: 'c' was not declared in this scope
50 | res += c[num][j];
| ^
a.cc:57:15: error: 'c' was not declared in this scope
57 | res = c[num][ans];
| ^
|
s408934865 | p03776 | C++ | #include <bits/stdc++.h>
using namespace std;
int n,a=0,b=0;
long long low,high,ans=1000000000,count=0;
long long num[n],sum[n+1][n+1];
void calc(){
if(a+b==n){
if(low<=b && b<=high){
bool x=(bool)sum[a][b]/(bool)b;
if(x==ans) count++;
else {
ans=min(ans,x); count=0;
}
}return;
}a++;sum[a][b]=sum[a-1][b];
calc();a--;
b++;sum[a][b]+=sum[a][b-1]+num[b-1];
calc();
return;
}
int main(){
cin>>n>>low>>high;
for(int i=0;i<n;i++){
cin>>num[i];
}calc();
cout<<ans<<endl;
cout<<count<<endl;
} | a.cc:6:15: error: size of array 'num' is not an integral constant-expression
6 | long long num[n],sum[n+1][n+1];
| ^
a.cc:6:28: error: size of array 'sum' is not an integral constant-expression
6 | long long num[n],sum[n+1][n+1];
| ~^~
a.cc:6:23: error: size of array 'sum' is not an integral constant-expression
6 | long long num[n],sum[n+1][n+1];
| ~^~
a.cc: In function 'void calc()':
a.cc:12:18: error: reference to 'count' is ambiguous
12 | if(x==ans) count++;
| ^~~~~
In file included from /usr/include/c++/14/algorithm:86,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
| ^~~~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:4025:5: note: 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
4025 | count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
| ^~~~~
a.cc:5:35: note: 'long long int count'
5 | long long low,high,ans=1000000000,count=0;
| ^~~~~
a.cc:14:14: error: no matching function for call to 'min(long long int&, bool&)'
14 | ans=min(ans,x); count=0;
| ~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:14:14: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'bool')
14 | ans=min(ans,x); count=0;
| ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:14:14: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
14 | ans=min(ans,x); count=0;
| ~~~^~~~~~~
a.cc:14:23: error: reference to 'count' is ambiguous
14 | ans=min(ans,x); count=0;
| ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
| ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note: 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
4025 | count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
| ^~~~~
a.cc:5:35: note: 'long long int count'
5 | long long low,high,ans=1000000000,count=0;
| ^~~~~
a.cc: In function 'int main()':
a.cc:32:9: error: reference to 'count' is ambiguous
32 | cout<<count<<endl;
| ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
| ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note: 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
4025 | count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
| ^~~~~
a.cc:5:35: note: 'long long int count'
5 | long long low,high,ans=1000000000,count=0;
| ^~~~~
|
s489235421 | p03776 | C++ | #include <bits/stdc++.h>
using namespace std;
long long n,low,high,ans=1000000000,a=0,b=0,count=0;
long long num[n],sum[n+1][n+1];
void calc(){
if(a+b==n){
if(low<=b && b<=high){
bool x=(bool)sum[a][b]/(bool)b;
if(x==ans) count++;
else {
ans=min(ans,x); count=0;
}
}return;
}a++;sum[a][b]=sum[a-1][b];
calc();a--;
b++;sum[a][b]+=sum[a][b-1]+num[b-1];
calc();
return;
}
int main(){
cin>>n>>low>>high;
for(int i=0;i<n;i++){
cin>>num[i];
}calc();
cout<<ans<<endl;
cout<<count<<endl;
} | a.cc:5:15: error: size of array 'num' is not an integral constant-expression
5 | long long num[n],sum[n+1][n+1];
| ^
a.cc:5:28: error: size of array 'sum' is not an integral constant-expression
5 | long long num[n],sum[n+1][n+1];
| ~^~
a.cc:5:23: error: size of array 'sum' is not an integral constant-expression
5 | long long num[n],sum[n+1][n+1];
| ~^~
a.cc: In function 'void calc()':
a.cc:11:18: error: reference to 'count' is ambiguous
11 | if(x==ans) count++;
| ^~~~~
In file included from /usr/include/c++/14/algorithm:86,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
| ^~~~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:4025:5: note: 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
4025 | count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
| ^~~~~
a.cc:4:45: note: 'long long int count'
4 | long long n,low,high,ans=1000000000,a=0,b=0,count=0;
| ^~~~~
a.cc:13:14: error: no matching function for call to 'min(long long int&, bool&)'
13 | ans=min(ans,x); count=0;
| ~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:13:14: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'bool')
13 | ans=min(ans,x); count=0;
| ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:13:14: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
13 | ans=min(ans,x); count=0;
| ~~~^~~~~~~
a.cc:13:23: error: reference to 'count' is ambiguous
13 | ans=min(ans,x); count=0;
| ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
| ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note: 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
4025 | count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
| ^~~~~
a.cc:4:45: note: 'long long int count'
4 | long long n,low,high,ans=1000000000,a=0,b=0,count=0;
| ^~~~~
a.cc: In function 'int main()':
a.cc:31:9: error: reference to 'count' is ambiguous
31 | cout<<count<<endl;
| ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
| ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note: 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
4025 | count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
| ^~~~~
a.cc:4:45: note: 'long long int count'
4 | long long n,low,high,ans=1000000000,a=0,b=0,count=0;
| ^~~~~
|
s788277585 | p03776 | C++ | #include <stdio.h>
#include <vector>
#include <tuple>
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
constexpr long double EPS = 1e-10;
using lli = long long int;
using info = std::pair<lli, lli>;
// DP[i][j] = (v, c) := 品物 1, ..., i から j 個選んだ時の価値の総和v, その方法数 c
std::vector<std::vector<info>> DP;
int main(void){
int n, a, b; scanf("%d%d%d", &n, &a, &b);
DP.resize(n+1, std::vector<info>(n+1, info(0, 0)));
DP[0][0] = {0, 1};
REP(i, n){
lli v; scanf("%lld", &v);
for(int j = 0; j <= i; ++j){
// not chosen
if(DP[i+1][j].first < DP[i][j].first)
DP[i+1][j] = DP[i][j];
else if(DP[i+1][j].first == DP[i][j].first)
DP[i+1][j].second += DP[i][j].second;
// chosen
if(DP[i+1][j+1].first < DP[i][j].first + v)
DP[i+1][j+1] = {DP[i][j].first + v, DP[i][j].second};
else if(DP[i+1][j+1].first == DP[i][j].first + v)
DP[i+1][j+1].second += DP[i][j].second;
}
}
long double average = 0; lli cnt = 0;
for(int x = a; x <= b; ++x){
double val = DP[n][x].first; val /= x;
if(fabsl(average - val) <= EPS){
cnt += DP[n][x].second;
}
else if(average < val){
average = val;
cnt = DP[n][x].second;
}
}
printf("%.16Lf\n%lld\n", average, cnt);
return 0;
}
| a.cc: In function 'int main()':
a.cc:38:12: error: 'fabsl' was not declared in this scope
38 | if(fabsl(average - val) <= EPS){
| ^~~~~
|
s190361830 | p03776 | C++ | #include <stdio.h>
#include <vector>
#include <tuple>
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
constexpr long double EPS = 1e-10;
using info = std::pair<lli, lli>;
// DP[i][j] = (v, c) := 品物 1, ..., i から j 個選んだ時の価値の総和v, その方法数 c
std::vector<std::vector<info>> DP;
int main(void){
int n, a, b; scanf("%d%d%d", &n, &a, &b);
DP.resize(n+1, std::vector<info>(n+1, info(0, 0)));
DP[0][0] = {0, 1};
REP(i, n){
lli v; scanf("%lld", &v);
for(int j = 0; j <= i; ++j){
// not chosen
if(DP[i+1][j].first < DP[i][j].first)
DP[i+1][j] = DP[i][j];
else if(DP[i+1][j].first == DP[i][j].first)
DP[i+1][j].second += DP[i][j].second;
// chosen
if(DP[i+1][j+1].first < DP[i][j].first + v)
DP[i+1][j+1] = {DP[i][j].first + v, DP[i][j].second};
else if(DP[i+1][j+1].first == DP[i][j].first + v)
DP[i+1][j+1].second += DP[i][j].second;
}
}
long double average = 0; lli cnt = 0;
for(int x = a; x <= b; ++x){
double val = DP[n][x].first; val /= x;
if(fabsl(average - val) <= EPS){
cnt += DP[n][x].second;
}
else if(average < val){
average = val;
cnt = DP[n][x].second;
}
}
printf("%.16Lf\n%lld\n", average, cnt);
return 0;
} | a.cc:9:24: error: 'lli' was not declared in this scope
9 | using info = std::pair<lli, lli>;
| ^~~
a.cc:9:29: error: 'lli' was not declared in this scope
9 | using info = std::pair<lli, lli>;
| ^~~
a.cc:9:32: error: template argument 1 is invalid
9 | using info = std::pair<lli, lli>;
| ^
a.cc:9:32: error: template argument 2 is invalid
a.cc:11:25: error: 'info' was not declared in this scope
11 | std::vector<std::vector<info>> DP;
| ^~~~
a.cc:11:25: error: template argument 1 is invalid
a.cc:11:25: error: template argument 2 is invalid
a.cc:11:29: error: template argument 1 is invalid
11 | std::vector<std::vector<info>> DP;
| ^~
a.cc:11:29: error: template argument 2 is invalid
a.cc: In function 'int main()':
a.cc:15:8: error: request for member 'resize' in 'DP', which is of non-class type 'int'
15 | DP.resize(n+1, std::vector<info>(n+1, info(0, 0)));
| ^~~~~~
a.cc:15:32: error: 'info' was not declared in this scope
15 | DP.resize(n+1, std::vector<info>(n+1, info(0, 0)));
| ^~~~
a.cc:15:36: error: template argument 1 is invalid
15 | DP.resize(n+1, std::vector<info>(n+1, info(0, 0)));
| ^
a.cc:15:36: error: template argument 2 is invalid
a.cc:16:7: error: invalid types 'int[int]' for array subscript
16 | DP[0][0] = {0, 1};
| ^
a.cc:18:9: error: 'lli' was not declared in this scope
18 | lli v; scanf("%lld", &v);
| ^~~
a.cc:18:31: error: 'v' was not declared in this scope
18 | lli v; scanf("%lld", &v);
| ^
a.cc:21:18: error: invalid types 'int[int]' for array subscript
21 | if(DP[i+1][j].first < DP[i][j].first)
| ^
a.cc:21:37: error: invalid types 'int[int]' for array subscript
21 | if(DP[i+1][j].first < DP[i][j].first)
| ^
a.cc:22:23: error: invalid types 'int[int]' for array subscript
22 | DP[i+1][j] = DP[i][j];
| ^
a.cc:22:36: error: invalid types 'int[int]' for array subscript
22 | DP[i+1][j] = DP[i][j];
| ^
a.cc:23:23: error: invalid types 'int[int]' for array subscript
23 | else if(DP[i+1][j].first == DP[i][j].first)
| ^
a.cc:23:43: error: invalid types 'int[int]' for array subscript
23 | else if(DP[i+1][j].first == DP[i][j].first)
| ^
a.cc:24:23: error: invalid types 'int[int]' for array subscript
24 | DP[i+1][j].second += DP[i][j].second;
| ^
a.cc:24:44: error: invalid types 'int[int]' for array subscript
24 | DP[i+1][j].second += DP[i][j].second;
| ^
a.cc:27:18: error: invalid types 'int[int]' for array subscript
27 | if(DP[i+1][j+1].first < DP[i][j].first + v)
| ^
a.cc:27:39: error: invalid types 'int[int]' for array subscript
27 | if(DP[i+1][j+1].first < DP[i][j].first + v)
| ^
a.cc:28:23: error: invalid types 'int[int]' for array subscript
28 | DP[i+1][j+1] = {DP[i][j].first + v, DP[i][j].second};
| ^
a.cc:28:39: error: invalid types 'int[int]' for array subscript
28 | DP[i+1][j+1] = {DP[i][j].first + v, DP[i][j].second};
| ^
a.cc:28:59: error: invalid types 'int[int]' for array subscript
28 | DP[i+1][j+1] = {DP[i][j].first + v, DP[i][j].second};
| ^
a.cc:29:23: error: invalid types 'int[int]' for array subscript
29 | else if(DP[i+1][j+1].first == DP[i][j].first + v)
| ^
a.cc:29:45: error: invalid types 'int[int]' for array subscript
29 | else if(DP[i+1][j+1].first == DP[i][j].first + v)
| ^
a.cc:30:23: error: invalid types 'int[int]' for array subscript
30 | DP[i+1][j+1].second += DP[i][j].second;
| ^
a.cc:30:46: error: invalid types 'int[int]' for array subscript
30 | DP[i+1][j+1].second += DP[i][j].second;
| ^
a.cc:34:30: error: 'lli' was not declared in this scope
34 | long double average = 0; lli cnt = 0;
| ^~~
a.cc:36:24: error: invalid types 'int[int]' for array subscript
36 | double val = DP[n][x].first; val /= x;
| ^
a.cc:37:12: error: 'fabsl' was not declared in this scope
37 | if(fabsl(average - val) <= EPS){
| ^~~~~
a.cc:38:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
38 | cnt += DP[n][x].second;
| ^~~
| int
a.cc:38:22: error: invalid types 'int[int]' for array subscript
38 | cnt += DP[n][x].second;
| ^
a.cc:42:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
42 | cnt = DP[n][x].second;
| ^~~
| int
a.cc:42:21: error: invalid types 'int[int]' for array subscript
42 | cnt = DP[n][x].second;
| ^
a.cc:45:39: error: 'cnt' was not declared in this scope; did you mean 'int'?
45 | printf("%.16Lf\n%lld\n", average, cnt);
| ^~~
| int
|
s348347840 | p03776 | Java | import java.io.PrintWriter;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int N = Integer.parseInt(sc.next());
int A = Integer.parseInt(sc.next());
int B = Integer.parseInt(sc.next());
PriorityQueue<Long> v = new PriorityQueue<>(Comparator.reverseOrder());
for(int i=0;i<N;i++) {
v.add(Long.parseLong(sc.next()));
}
double dp[] = new double[N+1];
dp[0] = 0;
int counter = 1;
long f=0,ins=0;
for(int i=1;i<A+1;i++) {
f = v.poll();
dp[i] = (dp[i-1]+f) / i;
}
for(int i=A+1;i<N+1;i++) {
ins = v.poll();
if(f == ins) {
counter ++;
}
dp[i] = ((dp[i-1]*(i-1))+ins)/i;
}
int result = 0;
//counter expresses the number of the replacible elements.
for(int i=A;i<=B;i++) {
if(dp[A] == dp[i]) {
result += combination(counter,i);
}
}
out.println(dp[A]);
out.println(result);
out.flush();
}
public static long combination(int n,int k) {
if(n < k) {
return 0;
}
else {
long numerator = 1,denominator = 1;
for(int i=n;i>n-k;i--) {
numerator = numerator * i;
}
for(int i=k;i>0;i--) {
denominator = denominator * i;
}
return numerator / denominator;
} | Main.java:60: error: reached end of file while parsing
}
^
1 error
|
s004756384 | p03776 | C++ | //#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib> // srand,rand
using namespace std;
#define ll long long
#define modd 1000000007
#define INF 1000000000000000000ll
typedef pair<long long, long long> pl;
typedef string::const_iterator State;
class ParseError {};
class UnionFind {
public:
vector <ll> par;
vector <ll> siz;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった
for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}
// Member Function
// Find
ll root(ll x) { // 根の検索
while (par[x] != x) {
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
/*
struct SegmentTree {
private:
ll n;
vector<ll> node;
public:
// 元配列 v をセグメント木で表現する
SegmentTree(vector<ll> v) {
// 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
// セグメント木全体で必要なノード数は 2n-1 個である
ll sz = v.size();
n = 1; while (n < sz) n *= 2;
node.resize(2 * n - 1, INF);
// 最下段に値を入れたあとに、下の段から順番に値を入れる
// 値を入れるには、自分の子の 2 値を参照すれば良い
for (ll i = 0; i < sz; i++) node[i + n - 1] = v[i];
for (ll i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
}
void update(ll x, ll val) {
// 最下段のノードにアクセスする
x += (n - 1);
// 最下段のノードを更新したら、あとは親に上って更新していく
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = min(node[2 * x + 1], node[2 * x + 2]);
}
}
};
*/
ll N, M, K, a, b, c, d, e, H, W, L, T;
ll x, y;
ll A[2000004] = {};
ll B[2000004] = {};
ll C[2000004] = {};
ll D[1000006] = {};
ll E[1000006] = {};
bool f, ff;
string S[200000];
string SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[300005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;
queue<ll> ql;
multiset<pl> plmset;
struct ST
{
ll first;
ll second;
ll kaisuu;
/*bool operator<(const ST& another) const
{
return first < another.first;//比較
};*/
};
queue<ST> qpl;
/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/
/*
long long modinv(long long aa, long long mm) {
long long bb = mm, uu = 1, vv = 0;
while (bb) {
long long tt = aa / bb;
aa -= tt * bb; swap(aa, bb);
uu -= tt * vv; swap(uu, vv);
}
uu %= mm;
if (uu < 0) uu += mm;
return uu;
}
*/
ll zettai(ll aa) {
if (aa < 0) {
aa *= -1;
}
return aa;
}
/*
struct edge {
ll from;
ll to;
ll cost;
};
ll V, E, d[300000];
edge es[300000];
bool fa[5000][5000];
bool ffa[5000];
bool has_negative_loop(ll s) {
fill(d, d + V, 50000000000000000);
d[s] = 0;
for (ll i = 0; i <=2* V+1; i++) {
for (ll j = 0; j < E; j++) {
edge e = es[j];
if (d[(int)e.to] > d[(int)e.from] + e.cost) {
d[(int)e.to] = d[(int)e.from] + e.cost;
if (i >= V+1 && fa[(int)e.to][V-1]==true &&fa[0][(int)e.from] == true) {
return true;
}
}
}
}
return false;
}
*/
/*struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } }star;
bool is_prime[1000000 + 1];
vector<int> P;
void Eratosthenes(const int N)
{
for (int i = 0; i <= N; i++)
{
is_prime[i] = true;//初期化
}
for (int i = 2; i <= N; i++)
{
if (is_prime[i])
{
for (int j = 2 * i; j <= N; j += i)
{
is_prime[j] = false;
}
P.emplace_back(i);
}
}
}*/
ll t;
ll RepeatSquaring(ll N, ll P, ll MO) {
if (P == 0) return 1;
if (P % 2 == 0) {
ll t = RepeatSquaring(N, P / 2, MO);
return t * t % MO;
}
return N * RepeatSquaring(N, P - 1, MO);
}
ll gyakugen(ll numb, ll MO) {
return RepeatSquaring(numb, MO - 2, MO);
}
/*
ll Com(ll NN, ll KK) {
e = D[NN];
e *= C[KK];
e %= modd;
e *= C[NN - KK];
e %= modd;
return e;
}
*/
double an;
int main() {
cin >> N >> a >> b;
for (int i = 0; i < N; i++) {
cin >> A[i];
vll.push_back(A[i]);
}
sort(vll.begin(), vll.end());
reverse(vll.begin(), vll.end());
for (int i = 0; i < a; i++) {
an += (double)vll[i];
x = vll[i];
}
an /= (double)a;
d = -1;
for (int i = 0; i < N; i++) {
if(vll[i]==x){
c++;
if (d == -1) {
d = i;
H = c;
}
}
}
e = min(c, b - d);
y = 1;
for (int j = H; j <= e; j++) {
y = 1;
for (int i = 0; i < j; i++) {
y *= (c - i);
y /= (i + 1);
}
W += y;
}
cout << fixed << setprecision(10) << an << endl;
cout << W << endl;
//cout << fixed << setprecision(10) << ansa << endl;
return 0;
}
//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib> // srand,rand
using namespace std;
#define ll long long
#define modd 1000000007
#define INF 1000000000000000000ll
typedef pair<long long, long long> pl;
typedef string::const_iterator State;
class ParseError {};
class UnionFind {
public:
vector <ll> par;
vector <ll> siz;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった
for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}
// Member Function
// Find
ll root(ll x) { // 根の検索
while (par[x] != x) {
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
/*
struct SegmentTree {
private:
ll n;
vector<ll> node;
public:
// 元配列 v をセグメント木で表現する
SegmentTree(vector<ll> v) {
// 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
// セグメント木全体で必要なノード数は 2n-1 個である
ll sz = v.size();
n = 1; while (n < sz) n *= 2;
node.resize(2 * n - 1, INF);
// 最下段に値を入れたあとに、下の段から順番に値を入れる
// 値を入れるには、自分の子の 2 値を参照すれば良い
for (ll i = 0; i < sz; i++) node[i + n - 1] = v[i];
for (ll i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
}
void update(ll x, ll val) {
// 最下段のノードにアクセスする
x += (n - 1);
// 最下段のノードを更新したら、あとは親に上って更新していく
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = min(node[2 * x + 1], node[2 * x + 2]);
}
}
};
*/
ll N, M, K, a, b, c, d, e, H, W, L, T;
ll x, y;
ll A[2000004] = {};
ll B[2000004] = {};
ll C[2000004] = {};
ll D[1000006] = {};
ll E[1000006] = {};
bool f, ff;
string S[200000];
string SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[300005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;
queue<ll> ql;
multiset<pl> plmset;
struct ST
{
ll first;
ll second;
ll kaisuu;
/*bool operator<(const ST& another) const
{
return first < another.first;//比較
};*/
};
queue<ST> qpl;
/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/
/*
long long modinv(long long aa, long long mm) {
long long bb = mm, uu = 1, vv = 0;
while (bb) {
long long tt = aa / bb;
aa -= tt * bb; swap(aa, bb);
uu -= tt * vv; swap(uu, vv);
}
uu %= mm;
if (uu < 0) uu += mm;
return uu;
}
*/
ll zettai(ll aa) {
if (aa < 0) {
aa *= -1;
}
return aa;
}
/*
struct edge {
ll from;
ll to;
ll cost;
};
ll V, E, d[300000];
edge es[300000];
bool fa[5000][5000];
bool ffa[5000];
bool has_negative_loop(ll s) {
fill(d, d + V, 50000000000000000);
d[s] = 0;
for (ll i = 0; i <=2* V+1; i++) {
for (ll j = 0; j < E; j++) {
edge e = es[j];
if (d[(int)e.to] > d[(int)e.from] + e.cost) {
d[(int)e.to] = d[(int)e.from] + e.cost;
if (i >= V+1 && fa[(int)e.to][V-1]==true &&fa[0][(int)e.from] == true) {
return true;
}
}
}
}
return false;
}
*/
/*struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } }star;
bool is_prime[1000000 + 1];
vector<int> P;
void Eratosthenes(const int N)
{
for (int i = 0; i <= N; i++)
{
is_prime[i] = true;//初期化
}
for (int i = 2; i <= N; i++)
{
if (is_prime[i])
{
for (int j = 2 * i; j <= N; j += i)
{
is_prime[j] = false;
}
P.emplace_back(i);
}
}
}*/
ll t;
ll RepeatSquaring(ll N, ll P, ll MO) {
if (P == 0) return 1;
if (P % 2 == 0) {
ll t = RepeatSquaring(N, P / 2, MO);
return t * t % MO;
}
return N * RepeatSquaring(N, P - 1, MO);
}
ll gyakugen(ll numb, ll MO) {
return RepeatSquaring(numb, MO - 2, MO);
}
/*
ll Com(ll NN, ll KK) {
e = D[NN];
e *= C[KK];
e %= modd;
e *= C[NN - KK];
e %= modd;
return e;
}
*/
double an;
int main() {
cin >> N >> a >> b;
for (int i = 0; i < N; i++) {
cin >> A[i];
vll.push_back(A[i]);
}
sort(vll.begin(), vll.end());
reverse(vll.begin(), vll.end());
for (int i = 0; i < a; i++) {
an += (double)vll[i];
x = vll[i];
}
an /= (double)a;
d = -1;
for (int i = 0; i < N; i++) {
if(vll[i]==x){
c++;
if (d == -1) {
d = i;
H = c;
}
}
}
e = min(c, b - d);
y = 1;
for (int j = H; j <= e; j++) {
y = 1;
for (int i = 0; i < j; i++) {
y *= (c - i);
y /= (i + 1);
}
W += y;
}
cout << fixed << setprecision(10) << an << endl;
cout << W << endl;
//cout << fixed << setprecision(10) << ansa << endl;
return 0;
}
| a.cc:376:7: error: redefinition of 'class ParseError'
376 | class ParseError {};
| ^~~~~~~~~~
a.cc:32:7: note: previous definition of 'class ParseError'
32 | class ParseError {};
| ^~~~~~~~~~
a.cc:385:7: error: redefinition of 'class UnionFind'
385 | class UnionFind {
| ^~~~~~~~~
a.cc:41:7: note: previous definition of 'class UnionFind'
41 | class UnionFind {
| ^~~~~~~~~
a.cc:473:4: error: redefinition of 'long long int N'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:4: note: 'long long int N' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:7: error: redefinition of 'long long int M'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:7: note: 'long long int M' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:10: error: redefinition of 'long long int K'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:10: note: 'long long int K' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:13: error: redefinition of 'long long int a'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:13: note: 'long long int a' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:16: error: redefinition of 'long long int b'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:16: note: 'long long int b' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:19: error: redefinition of 'long long int c'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:19: note: 'long long int c' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:22: error: redefinition of 'long long int d'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:22: note: 'long long int d' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:25: error: redefinition of 'long long int e'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:25: note: 'long long int e' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:28: error: redefinition of 'long long int H'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:28: note: 'long long int H' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:31: error: redefinition of 'long long int W'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:31: note: 'long long int W' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:34: error: redefinition of 'long long int L'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:34: note: 'long long int L' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:473:37: error: redefinition of 'long long int T'
473 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:129:37: note: 'long long int T' previously declared here
129 | ll N, M, K, a, b, c, d, e, H, W, L, T;
| ^
a.cc:474:4: error: redefinition of 'long long int x'
474 | ll x, y;
| ^
a.cc:130:4: note: 'long long int x' previously declared here
130 | ll x, y;
| ^
a.cc:474:7: error: redefinition of 'long long int y'
474 | ll x, y;
| ^
a.cc:130:7: note: 'long long int y' previously declared here
130 | ll x, y;
| ^
a.cc:475:4: error: redefinition of 'long long int A [2000004]'
475 | ll A[2000004] = {};
| ^
a.cc:131:4: note: 'long long int A [2000004]' previously defined here
131 | ll A[2000004] = {};
| ^
a.cc:476:4: error: redefinition of 'long long int B [2000004]'
476 | ll B[2000004] = {};
| ^
a.cc:132:4: note: 'long long int B [2000004]' previously defined here
132 | ll B[2000004] = {};
| ^
a.cc:477:4: error: redefinition of 'long long int C [2000004]'
477 | ll C[2000004] = {};
| ^
a.cc:133:4: note: 'long long int C [2000004]' previously defined here
133 | ll C[2000004] = {};
| ^
a.cc:478:4: error: redefinition of 'long long int D [1000006]'
478 | ll D[1000006] = {};
| ^
a.cc:134:4: note: 'long long int D [1000006]' previously defined here
134 | ll D[1000006] = {};
| ^
a.cc:479:4: error: redefinition of 'long long int E [1000006]'
479 | ll E[1000006] = {};
| ^
a.cc:135:4: note: 'long long int E [1000006]' previously defined here
135 | ll E[1000006] = {};
| ^
a.cc:480:6: error: redefinition of 'bool f'
480 | bool f, ff;
| ^
a.cc:136:6: note: 'bool f' previously declared here
136 | bool f, ff;
| ^
a.cc:480:9: error: redefinition of 'bool ff'
480 | bool f, ff;
| ^~
a.cc:136:9: note: 'bool ff' previously declared here
136 | bool f, ff;
| ^~
a.cc:481:8: error: redefinition of 'std::string S [200000]'
481 | string S[200000];
| ^
a.cc:137:8: note: 'std::string S [200000]' previously declared here
137 | string S[200000];
| ^
a.cc:482:8: error: redefinition of 'std::string SS'
482 | string SS;
| ^~
a.cc:138:8: note: 'std::string SS' previously declared here
138 | string SS;
| ^~
a.cc:483:16: error: redefinition of 'std::set<long long int> sll'
483 | set <long long>sll;
| ^~~
a.cc:139:16: note: 'std::set<long long int> sll' previously declared here
139 | set <long long>sll;
| ^~~
a.cc:484:4: error: redefinition of 'pl bufpl'
484 | pl bufpl;
| ^~~~~
a.cc:140:4: note: 'pl bufpl' previously defined here
140 | pl bufpl;
| ^~~~~
a.cc:485:19: error: redefinition of 'std::vector<long long int> vl [300005]'
485 | vector <long long>vl[300005];
| ^~
a.cc:141:19: note: 'std::vector<long long int> vl [300005]' previously declared here
141 | vector <long long>vl[300005];
| ^~
a.cc:486:19: error: redefinition of 'std::vector<long long int> vll'
486 | vector <long long>vll;
| ^~~
a.cc:142:19: note: 'std::vector<long long int> vll' previously declared here
142 | vector <long long>vll;
| ^~~
a.cc:487:12: error: redefinition of 'std::vector<std::pair<long long int, long long int> > vpl'
487 | vector <pl>vpl;
| ^~~
a.cc:143:12: note: 'std::vector<std::pair<long long int, long long int> > vpl' previously declared here
143 | vector <pl>vpl;
| ^~~
a.cc:488:17: error: redefinition of 'std::vector<std::__cxx11::basic_string<char> > vs'
488 | vector <string> vs;
| ^~
a.cc:144:17: note: 'std::vector<std::__cxx11::basic_string<char> > vs' previously declared here
144 | vector <string> vs;
| ^~
a.cc:489:9: error: redefinition of 'std::set<long long int> llset'
489 | set<ll> llset;
| ^~~~~
a.cc:145:9: note: 'std::set<long long int> llset' previously declared here
145 | set<ll> llset;
| ^~~~~
a.cc:490:14: error: redefinition of 'std::multiset<long long int> llmset'
490 | multiset<ll> llmset;
| ^~~~~~
a.cc:146:14: note: 'std::multiset<long long int> llmset' previously declared here
146 | multiset<ll> llmset;
| ^~~~~~
a.cc:491:11: error: redefinition of 'std::queue<long long int> ql'
491 | queue<ll> ql;
| ^~
a.cc:147:11: note: 'std::queue<long long int> ql' previously declared here
147 | queue<ll> ql;
| ^~
a.cc:492:14: error: redefinition of 'std::multiset<std::pair<long long int, long long int> > plmset'
492 | multiset<pl> plmset;
| ^~~~~~
a.cc:148:14: note: 'std::multiset<std::pair<long long int, long long int> > plmset' previously declared here
148 | multiset<pl> plmset;
| ^~~~~~
a.cc:495:8: error: redefinition of 'struct ST'
495 | struct ST
| ^~
a.cc:151:8: note: previous definition of 'struct ST'
151 | struct ST
| ^~
a.cc:508:11: error: redefinition of 'std::queue<ST> qpl'
508 | queue<ST> qpl;
| ^~~
a.cc:164:11: note: 'std::queue<ST> qpl' previously declared here
164 | queue<ST> qpl;
| ^~~
a.cc:534:4: error: redefinition of 'long long int zettai(long long int)'
534 | ll zettai(ll aa) {
| ^~~~~~
a.cc:190:4: note: 'long long int zettai(long long int)' previously defined here
190 | ll zettai(ll aa) {
| ^~~~~~
a.cc:603:4: error: redefinition of 'long long int t'
603 | ll t;
| ^
a.cc:259:4: note: 'long long int t' previously declared here
259 | ll t;
| ^
a.cc:605:4: error: redefinition of 'long long int RepeatSquaring(long long int, long long int, long long int)'
605 | ll RepeatSquaring(ll N, ll P, ll MO) {
| ^~~~~~~~~~~~~~
a.cc:261:4: note: 'long long int RepeatSquaring(long long int, long long int, long long int)' previously defined here
261 | ll RepeatSquaring(ll N, ll P, ll MO) {
| ^~~~~~~~~~~~~~
a.cc:614:4: error: redefinition of 'long long int gyakugen(long long int, long long int)'
614 | ll gyakugen(ll numb, ll MO) {
| ^~~~~~~~
a.cc:270:4: note: 'long long int gyakugen(long long int, long long int)' previously defined here
270 | ll gyakugen(ll numb, ll MO) {
| ^~~~~~~~
a.cc:633:8: error: redefinition of 'double an'
633 | double an;
| ^~
a.cc:289:8: note: 'double an' previously declared here
289 | double an;
| ^~
a.cc:635:5: error: redefinition of 'int main()'
635 | int main() {
| ^~~~
a.cc:291:5: note: 'int main()' previously defined here |
s436060966 | p03776 | C++ | #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vp> matP;
const int MAX_N = 60;
vec nCm(MAX_N+1,0);
vec fact(MAX_N+1,0),fact_inv(MAX_N+1,0);
ll fastpow(ll a, ll pw) {
ll res = 1;
while (pw) {
if (pw & 1) res = res * a % MOD;
a = a * a % MOD;
pw >>= 1;
}
return res;
}
void makefact(ll n){//MODは素数かつnより大きい
ll ans = 1;
fact.at(0) = ans;
fact_inv.at(0) = ans;
reps(i,1,n+1){
(ans *= i)%=MOD;
fact.at(i) = ans;
fact_inv.at(i) = fastpow(ans,MOD-2);
}
return;
}
void makenCm(ll n){
rep(i,n+1){
ll ans = fact.at(n);
(((ans*=fact_inv.at(n-i))%=MOD)*=fact_inv.at(i))%=MOD;
nCm.at(i) = ans;
}
return;
}
int main() {
cin>>N>>A>>B;
makefact(60);
vec v(N);
rep(i,N) cin>>v[i];
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
long double ans = 0;
rep(i,A) ans += v[i];
long double div = A;
cout<<fixed<<setprecision(10)<<ans / div<<endl;
//まずA個選ぶ時の重複#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vp> matP;
int main() {
cin>>N>>A>>B;
vec v(N);
rep(i,N) cin>>v[i];
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
long double ans = 0;
rep(i,A) ans += v[i];
long double div = A;
cout<<fixed<<setprecision(10)<<ans / div<<endl;
//まずA個選ぶ時の重複
ll sameV = 0;
rep(i,N) sameV += v[i] == v[A-1];
ll num_dif = 0;
rep(i,A) num_dif += v[i] != v[A-1];
vec nCm(sameV + 1,1); //sameV C iの値
reps(i, 1, sameV + 1){
nCm[i] = ((nCm[i-1] * (sameV - i + 1)) / i);
}
ll out = nCm.at(A - num_dif);
//A個より多く選べる場合
if(v[0] == v[A-1]){
reps(i, A, B){
if(v[i] != v[A-1]) break;
out += nCm.at(i + 1);
//cout<<i+1<<' '<<nCm.at(i+1)<<endl;
}
}
cout<<out<<endl;
}
ll sameV = 0;
rep(i,N) sameV += v[i] == v[A-1];
ll num_dif = 0;
rep(i,A) num_dif += v[i] != v[A-1];
makenCm(sameV);
//cout<<A<<' '<<num_dif<<endl;
ll out = nCm.at(A - num_dif);
//A個より多く選べる場合
if(v[0] == v[A-1]){
reps(i, A, B){
if(v[i] != v[A-1]) break;
out += nCm.at(i + 1 - num_dif);
}
}
cout<<out<<endl;
} | a.cc: In function 'int main()':
a.cc:87:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
87 | int main() {
| ^~
a.cc:87:9: note: remove parentheses to default-initialize a variable
87 | int main() {
| ^~
| --
a.cc:87:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:87:12: error: a function-definition is not allowed here before '{' token
87 | int main() {
| ^
|
s494263507 | p03776 | Java | import java.util.*;
public class ABC057{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=Integer.parseInt(sc.next());
int a=Integer.parseInt(sc.next());
int b=Integer.parseInt(sc.next());
ArrayList<Long> v=new ArrayList<Long>();
for(int i=0;i<n;i++){
v.add(Long.parseLong(sc.next()));
}
sc.close();
Collections.sort(v,(v1, v2)->{
if(v1<v2) return 1;
else if(v1>v2) return -1;
else return 0;
});
long min=v.get(a-1);
int minCount=0;
int befA=1;
double avg=0;
for(int i=0;i<n;i++){
if(i<a) avg+=v.get(i);
if(v.get(i)==min) minCount++;
if(i==a-1) befA=minCount;
}
avg=avg/((double) a);
long pattern=0;
long minCj;
int minCount2;
int j_max=befA;
if(min==v.get(0)) j_max+=b-a;
for(int j=befA;j<=j_max;j++){
minCount2=minCount;
minCj=1;
for(int d=1;d<=j;d++){
minCj*=minCount2;
minCount2--;
minCj/=d;
}
pattern+=minCj;
}
System.out.println(String.format("%.6f", avg));
System.out.println(pattern);
}
} | Main.java:3: error: class ABC057 is public, should be declared in a file named ABC057.java
public class ABC057{
^
1 error
|
s540757271 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
const long long maxn=1e15;
long long n,m,d,ans1,ans2=0,cnt1,cnt2;
int a[maxn],C[100][100];
bool cmp(long long x,long long y)
{
return x>y;
}
void init()
{
C[0][0]=1;
C[1][0]=1;
C[1][1]=1;
for(int i=1;i<=50;i++)
{
C[i][0]=1;
for(int j=1;j<=i;j++)
C[i][j]=C[i-1][j]+C[i-1][j-1];
}
}
int main()
{
init();
cin>>n>>m>>d;
for(long long i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a+1,a+n+1,cmp);
for(long long i=1;i<=m;i++)
{
ans1+=a[i];
}
for(long long i=1;i<=n;i++)
{
if(a[i]==a[m])
{
cnt1++;
}
}
for(long long i=1;i<=m;i++)
{
if(a[i]==a[m])
{
cnt2++;
}
}
if(a[1]==a[m])
{
for(long long i=m;i<=min(cnt2,d);i++)
{
ans2+=C[cnt2][i-1];
}
}
else ans2=C[cnt1][cnt2];
printf("%lf\n%lld",(double)ans1/m,ans2);
return 0;
} | /tmp/cccNL6ua.o: in function `init()':
a.cc:(.text+0x1f): relocation truncated to fit: R_X86_64_PC32 against symbol `C' defined in .bss section in /tmp/cccNL6ua.o
a.cc:(.text+0x29): relocation truncated to fit: R_X86_64_PC32 against symbol `C' defined in .bss section in /tmp/cccNL6ua.o
a.cc:(.text+0x33): relocation truncated to fit: R_X86_64_PC32 against symbol `C' defined in .bss section in /tmp/cccNL6ua.o
a.cc:(.text+0x6c): relocation truncated to fit: R_X86_64_PC32 against symbol `C' defined in .bss section in /tmp/cccNL6ua.o
a.cc:(.text+0xb9): relocation truncated to fit: R_X86_64_PC32 against symbol `C' defined in .bss section in /tmp/cccNL6ua.o
a.cc:(.text+0xf9): relocation truncated to fit: R_X86_64_PC32 against symbol `C' defined in .bss section in /tmp/cccNL6ua.o
a.cc:(.text+0x135): relocation truncated to fit: R_X86_64_PC32 against symbol `C' defined in .bss section in /tmp/cccNL6ua.o
/tmp/cccNL6ua.o: in function `main':
a.cc:(.text+0x39b): relocation truncated to fit: R_X86_64_PC32 against symbol `C' defined in .bss section in /tmp/cccNL6ua.o
a.cc:(.text+0x419): relocation truncated to fit: R_X86_64_PC32 against symbol `C' defined in .bss section in /tmp/cccNL6ua.o
collect2: error: ld returned 1 exit status
|
s294686100 | p03776 | C++ | #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
vector<ll> C(60, vector<ll>(60));
void PascalTriangle() {
rep(i, 60) {
C[i][0] = C[i][i] = 1;
}
for(int i = 2; i < 60; i++) {
for(int j = 1; j < i; j++) {
C[i][j] = C[i-1][j] + C[i-1][j-1];
}
}
}
int main() {
int n, a, b;
cin >> n >> a >> b;
vector<ll> v(n);
rep(i, n) {
cin >> v[i];
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
ll sum = 0;
rep(i, a) {
sum += v[i];
}
double avg = (double)sum/a;
printf("%.7f\n", avg);
PascalTriangle();
ll ans = 0;
if(v[0] != v[a-1]) {
int x = 0, y = 0;
rep(i, n) {
if(v[i] == v[a-1]) {
x++;
}
}
rep(i, a) {
if(v[i] == v[a-1]) {
y++;
}
}
ans = C[x][y];
}
else if(v[0] == v[a-1]) {
int x = 0;
rep(i, n) {
if(v[i] == v[0]) {
x++;
}
}
for(int i = a; i <= min(b, x); i++) {
ans += C[x][i];
}
}
cout << ans << endl;
return 0;
} | a.cc:16:32: error: no matching function for call to 'std::vector<long long int>::vector(int, std::vector<long long int>)'
16 | vector<ll> C(60, vector<ll>(60));
| ^
In file included from /usr/include/c++/14/vector:66,
from a.cc:7:
/usr/include/c++/14/bits/stl_vector.h:707:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with <template-parameter-2-2> = _InputIterator; _Tp = long long int; _Alloc = std::allocator<long long int>]'
707 | vector(_InputIterator __first, _InputIterator __last,
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:707:9: note: template argument deduction/substitution failed:
a.cc:16:32: note: deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<long long int>')
16 | vector<ll> C(60, vector<ll>(60));
| ^
/usr/include/c++/14/bits/stl_vector.h:678:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
678 | vector(initializer_list<value_type> __l,
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:678:43: note: no known conversion for argument 1 from 'int' to 'std::initializer_list<long long int>'
678 | vector(initializer_list<value_type> __l,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:659:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; std::__type_identity_t<_Alloc> = std::allocator<long long int>]'
659 | vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:659:23: note: no known conversion for argument 1 from 'int' to 'std::vector<long long int>&&'
659 | vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
| ~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_vector.h:640:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>; std::false_type = std::false_type]'
640 | vector(vector&& __rv, const allocator_type& __m, false_type)
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:640:7: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_vector.h:635:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>; std::true_type = std::true_type]'
635 | vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:635:7: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_vector.h:624:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; std::__type_identity_t<_Alloc> = std::allocator<long long int>]'
624 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:624:28: note: no known conversion for argument 1 from 'int' to 'const std::vector<long long int>&'
624 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:620:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
620 | vector(vector&&) noexcept = default;
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:620:7: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:601:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
601 | vector(const vector& __x)
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:601:7: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:569:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; size_type = long unsigned int; value_type = long long int; allocator_type = std::allocator<long long int>]'
569 | vector(size_type __n, const value_type& __value,
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:569:47: note: no known conversion for argument 2 from 'std::vector<long long int>' to 'const std::vector<long long int>::value_type&' {aka 'const long long int&'}
569 | vector(size_type __n, const value_type& __value,
| ~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; size_type = long unsigned int; allocator_type = std::allocator<long long int>]'
556 | vector(size_type __n, const allocator_type& __a = allocator_type())
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:556:51: note: no known conversion for argument 2 from 'std::vector<long long int>' to 'const std::vector<long long int>::allocator_type&' {aka 'const std::allocator<long long int>&'}
556 | vector(size_type __n, const allocator_type& __a = allocator_type())
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:542:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
542 | vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:542:7: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:531:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
531 | vector() = default;
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:531:7: note: candidate expects 0 arguments, 2 provided
a.cc: In function 'void PascalTriangle()':
a.cc:21:13: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}[int]' for array subscript
21 | C[i][0] = C[i][i] = 1;
| ^
a.cc:21:23: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}[int]' for array subscript
21 | C[i][0] = C[i][i] = 1;
| ^
a.cc:26:17: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}[int]' for array subscript
26 | C[i][j] = C[i-1][j] + C[i-1][j-1];
| ^
a.cc:26:29: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}[int]' for array subscript
26 | C[i][j] = C[i-1][j] + C[i-1][j-1];
| ^
a.cc:26:41: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}[int]' for array subscript
26 | C[i][j] = C[i-1][j] + C[i-1][j-1];
| ^
a.cc: In function 'int main()':
a.cc:66:19: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}[int]' for array subscript
66 | ans = C[x][y];
| ^
a.cc:78:24: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}[int]' for array subscript
78 | ans += C[x][i];
| ^
|
s577153710 | p03776 | C++ |
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
int c[1100][1100];
void comb_table(void){
for(int i=0;i<=1000;i++){
for(int j=0;j<=i;j++){
if(j==0||j==i){
c[i][j] = 1LL;
}
else{
c[i][j]=(c[i-1][j-1]+c[i-1][j]);
}
}
}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(20);
int n,a,b;
cin>>n>>a>>b;
map<int,int> mp;
vi v(n);
rep(i,n){
cin>>v[i];
mp[v[i]]++;
}
sort(all(v));
reverse(all(v));
int s=0,t=0;
rep(i,n){
if(v[i]==v[a-1]){
s++;
if(i<a) t++;
}
}
double ave=0;
rep(i,a){
ave+=v[i];
}
ave/=a;
comb_table();
cout<<ave<<endl;
int ans=0;
if(a==t){
FOR(i,a,b+1){
ans+=c[s][i];
}
}else{
ans=c[mp[v[p]]][a-p];
}
cout<<ans<<endl;
} | a.cc: In function 'int main()':
a.cc:84:16: error: 'p' was not declared in this scope
84 | ans=c[mp[v[p]]][a-p];
| ^
|
s722571686 | p03776 | C++ | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cfloat>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;
llong C[55][55];
void comb_table(int N){
for(int i=0;i<=N;++i){
for(int j=0;j<=i;++j){
if(j==0 || j==i){
C[i][j]=1LL;
}else{
C[i][j]=(C[i-1][j-1]+C[i-1][j]);
}
}
}
}
llong n, a, b;
llong v[55];
llong sum[55];
int main() {
comb_table(50);
cin >> n >> a >> b;
for (llong i = 1; i <= n; i++) {
cin >> v[i];
}
sort(v + 1, v + n + 1, greater<>());
for (llong i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + v[i];
}
__float128 maxv = 0;
for (llong i = a; i <= b; i++) {
__float128 avg = (sum[i]) / ((__float128)i);
maxv = max(avg, maxv);
}
llong ans = 0 , last = -1;
for (llong i = a; i <= b; i++) {
__float128 avg = (__float128)sum[i] / (__float128)i;
if (maxv == avg) {
llong t = v[i];
llong N = 0;
llong K = 0;
assert(last == -1 || last == a[i]);
for (llong j = 1; j <= n; j++) {
if (v[j] == t) N++;
}
for (llong j = i; j > 0; j--) {
if (v[j] == t) K++;
}
ans += C[N][K];
}
}
printf("%.*lf\n", DBL_DIG, (double)maxv);
printf("%lld\n", ans);
return 0;
}
| a.cc: In function 'int main()':
a.cc:67:41: error: invalid types 'llong {aka long long int}[llong {aka long long int}]' for array subscript
67 | assert(last == -1 || last == a[i]);
| ^
a.cc:67:11: error: 'assert' was not declared in this scope
67 | assert(last == -1 || last == a[i]);
| ^~~~~~
a.cc:14:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
13 | #include <cfloat>
+++ |+#include <cassert>
14 | using namespace std;
|
s632615470 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;
void add(long long &a, long long b) {
a += b;
if (a >= MOD) a -= MOD;
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX = 51000000000000000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int N, A, B; cin >> N >> A >> B;
vector<long long> v(N);
for (int i = 0; i < N; ++i) cin >> v[i];
sort(v.begin(), v.end(), greater<long long>());
// 最大値
long long sum = 0;
COMinit();
for (int i = 0; i < A; ++i) sum += v[i];
double ave = (double)(sum) / A;
// 小さいやつの個数
long long res = 0;
int num = 0;
for (int i = 0; i < N; ++i) if (v[i] == v[A-1]) ++num;
if (v[0] == v[A-1]) {
for (int j = A; j <= B; ++j) {
res += COM(num, j);
}
}
else {
int a = 0;
for (int i = 0; i < A; ++i) if (v[i] == v[A-1]) ++a;
res = COM(num, a);
}
cout << fixed << setprecision(10) << ave << endl;
cout << res << endl;
}
| a.cc:24:17: warning: overflow in conversion from 'long int' to 'int' changes value from '51000000000000000' to '-745832448' [-Woverflow]
24 | const int MAX = 51000000000000000;
| ^~~~~~~~~~~~~~~~~
a.cc:26:18: error: narrowing conversion of '-745832448' from 'int' to 'long unsigned int' [-Wnarrowing]
26 | long long fac[MAX], finv[MAX], inv[MAX];
| ^
a.cc:26:15: error: size '-745832448' of array 'fac' is negative
26 | long long fac[MAX], finv[MAX], inv[MAX];
| ^~~
a.cc:26:29: error: narrowing conversion of '-745832448' from 'int' to 'long unsigned int' [-Wnarrowing]
26 | long long fac[MAX], finv[MAX], inv[MAX];
| ^
a.cc:26:26: error: size '-745832448' of array 'finv' is negative
26 | long long fac[MAX], finv[MAX], inv[MAX];
| ^~~
a.cc:26:39: error: narrowing conversion of '-745832448' from 'int' to 'long unsigned int' [-Wnarrowing]
26 | long long fac[MAX], finv[MAX], inv[MAX];
| ^
a.cc:26:36: error: size '-745832448' of array 'inv' is negative
26 | long long fac[MAX], finv[MAX], inv[MAX];
| ^~~
|
s022039622 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;
void add(long long &a, long long b) {
a += b;
if (a >= MOD) a -= MOD;
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int N, A, B; cin >> N >> A >> B;
vector<long long> v(N);
for (int i = 0; i < N; ++i) cin >> v[i];
sort(v.begin(), v.end(), greater<ll>());
ll sum = 0;
for (int i = 0; i < A; ++i) sum += v[i];
double ave = (double)(sum) / A;
ll ans = 0;
int num = 0;
COMinit()
rep(i,N) {
if(v[i] == v[A-1]) ++num;
}
if(v[0] == v[A-1]){
for (int j = A; j <= B; ++j) {
ans += COM(num, j);
}
}
else{
int a = 0;
for (int i = 0; i < A; ++i) if (v[i] == v[A-1]) ++a;
ans = COM(num, a);
}
cout << fixed << setprecision(10) << ave << endl;
cout << ans << endl;
} | a.cc: In function 'int main()':
a.cc:60:14: error: expected ';' before 'for'
60 | COMinit()
| ^
| ;
a.cc:61:9: error: 'i' was not declared in this scope
61 | rep(i,N) {
| ^
a.cc:5:43: note: in definition of macro 'rep'
5 | #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
| ^
a.cc:61:9: error: 'i_len' was not declared in this scope
61 | rep(i,N) {
| ^
a.cc:5:45: note: in definition of macro 'rep'
5 | #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
| ^
|
s918540776 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;
void add(long long &a, long long b) {
a += b;
if (a >= MOD) a -= MOD;
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int N, A, B; cin >> N >> A >> B;
vector<long long> v(N);
for (int i = 0; i < N; ++i) cin >> v[i];
sort(v.begin(), v.end(), greater<ll>());
ll sum = 0;
for (int i = 0; i < A; ++i) sum += v[i];
double ave = (double)(sum) / A;
ll ans = 0;
int num = 0;
COMinit()
rep(i,N) {
if(v[i] == v[A-1]) ++num;
}
if(v[0] == v[A-1]){
for (int j = A; j <= B; ++j) {
ans += COM(num, j);
}
}
else{
int a = 0;
for (int i = 0; i < A; ++i) if (v[i] == v[A-1]) ++a;
ans = COM(num, a);
}
cout << fixed << setprecision(10) << ave << endl;
cout << res << endl;
} | a.cc: In function 'int main()':
a.cc:60:14: error: expected ';' before 'for'
60 | COMinit()
| ^
| ;
a.cc:61:9: error: 'i' was not declared in this scope
61 | rep(i,N) {
| ^
a.cc:5:43: note: in definition of macro 'rep'
5 | #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
| ^
a.cc:61:9: error: 'i_len' was not declared in this scope
61 | rep(i,N) {
| ^
a.cc:5:45: note: in definition of macro 'rep'
5 | #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
| ^
a.cc:75:13: error: 'res' was not declared in this scope; did you mean 'rep'?
75 | cout << res << endl;
| ^~~
| rep
|
s065935128 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;
void add(long long &a, long long b) {
a += b;
if (a >= MOD) a -= MOD;
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int N, A, B; cin >> N >> A >> B;
vector<long long> v(N);
for (int i = 0; i < N; ++i) cin >> v[i];
sort(v.begin(), v.end(), greater<ll>());
ll sum = 0;
for (int i = 0; i < A; ++i) sum += v[i];
double ave = (double)(sum) / A;
ll ans = 0;
int num = 0;
COMinit()
rep(i,N) if(v[i] == v[A-1]) ++num;
if(v[0] == v[A-1]){
for (int j = A; j <= B; ++j) {
res += COM(num, j);
}
}
else{
int a = 0;
for (int i = 0; i < A; ++i) if (v[i] == v[A-1]) ++a;
ans = COM(num, a);
}
cout << fixed << setprecision(10) << ave << endl;
cout << res << endl;
} | a.cc: In function 'int main()':
a.cc:60:14: error: expected ';' before 'for'
60 | COMinit()
| ^
| ;
a.cc:61:9: error: 'i' was not declared in this scope
61 | rep(i,N) if(v[i] == v[A-1]) ++num;
| ^
a.cc:5:43: note: in definition of macro 'rep'
5 | #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
| ^
a.cc:61:9: error: 'i_len' was not declared in this scope
61 | rep(i,N) if(v[i] == v[A-1]) ++num;
| ^
a.cc:5:45: note: in definition of macro 'rep'
5 | #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
| ^
a.cc:64:13: error: 'res' was not declared in this scope; did you mean 'rep'?
64 | res += COM(num, j);
| ^~~
| rep
a.cc:73:13: error: 'res' was not declared in this scope; did you mean 'rep'?
73 | cout << res << endl;
| ^~~
| rep
|
s038783350 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;
void add(long long &a, long long b) {
a += b;
if (a >= MOD) a -= MOD;
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int N, A, B; cin >> N >> A >> B;
vector<long long> v(N);
for (int i = 0; i < N; ++i) cin >> v[i];
sort(v.begin(), v.end(), greater<ll>());
ll sum = 0;
for (int i = 0; i < A; ++i) sum += v[i];
double ave = (double)(sum) / A;
ll ans = 0;
int num = 0;
COMinit()
rep(i,N) if(v[i] == v[A-1]) ++num;
if(v[0] == v[A-1]){
for (int j = A; j <= B; ++j) {
res += COM(num, j);
}
}
else{
int a = 0;
for (int i = 0; i < A; ++i) if (v[i] == v[A-1]) ++a;
ans = COM(num, a);
}
cout << fixed << setprecision(10) << ave << endl;
cout << res << endl;
} | a.cc:24:11: error: redefinition of 'const int MOD'
24 | const int MOD = 1000000007;
| ^~~
a.cc:13:11: note: 'const int MOD' previously defined here
13 | const int MOD = 1000000007;
| ^~~
a.cc: In function 'int main()':
a.cc:61:14: error: expected ';' before 'for'
61 | COMinit()
| ^
| ;
a.cc:62:9: error: 'i' was not declared in this scope
62 | rep(i,N) if(v[i] == v[A-1]) ++num;
| ^
a.cc:5:43: note: in definition of macro 'rep'
5 | #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
| ^
a.cc:62:9: error: 'i_len' was not declared in this scope
62 | rep(i,N) if(v[i] == v[A-1]) ++num;
| ^
a.cc:5:45: note: in definition of macro 'rep'
5 | #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
| ^
a.cc:65:13: error: 'res' was not declared in this scope; did you mean 'rep'?
65 | res += COM(num, j);
| ^~~
| rep
a.cc:74:13: error: 'res' was not declared in this scope; did you mean 'rep'?
74 | cout << res << endl;
| ^~~
| rep
|
s714254230 | p03776 | C++ | #include <bits/stdc++.h>
using namespace std;
double m[55];
bool cmp(double x,double y)
{
return x>y;
}
ll A(ll n,ll m)
{
ll cnt = 1;
if(n < m)
return 0;
while(m--)
{
cnt*=n;
n--;
}
return cnt;
}
ll C(ll n,ll m)
{
if(n < m)
return 0;
return A(n,m)/A(m,m);
}
int main()
{
int n,a;
double b;
cin>>n>>a>>b;
for(int i=1;i<=n;i++)
{
cin>>m[i];
}
sort(m+1,m+1+n,cmp);
double sum = 0;
for(int i=1;i<=a;i++)
{
sum += m[i];
}
double ave = sum/a;
double k = m[a];
int cnt1 = 0,cnt2 = 0 ;
for(int i=1;i<=n;i++)
{
if(m[i] == k){
cnt1++;
}
}
for(int i=1;i<=a;i++)
{
if(m[i] == k){
cnt2++;
}
}
int res = 0;
if(cnt2 == a){
for(int i=a;i<=b;i++)
{
res += C(cnt1,i);
}
}else{
res = C(cnt1,cnt2);
}
printf("%.8lf",ave);
printf("%d\n",res);
return 0;
}
| a.cc:8:1: error: 'll' does not name a type
8 | ll A(ll n,ll m)
| ^~
a.cc:21:1: error: 'll' does not name a type
21 | ll C(ll n,ll m)
| ^~
a.cc: In function 'int main()':
a.cc:61:20: error: 'C' was not declared in this scope
61 | res += C(cnt1,i);
| ^
a.cc:64:15: error: 'C' was not declared in this scope
64 | res = C(cnt1,cnt2);
| ^
|
s647257482 | p03776 | C++ | #include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
ll c[100];
bool cmp(ll a,ll b){
return a > b;
}
ll C(ll a,ll b){
if(b == 0 || a == b)return 1ll;
if(b == 1)return a;
return (C(a-1,b-1)+C(a-1,b));
}
int main() {
//pld(C)
ll n;
sld(n)
ll a,b;
sld(a) sdl(b)
for(ll i = 0; i < n; i ++){
sld(c[i])
}
ll sum = 0;
sort(c,c+n,cmp);
ll x = c[a-1];
ll count0 = 0;
for(ll i = a-1; i >= 0; i --){
if(c[i] == x){
count0 ++;
}
sum += c[i];
}
ll count1 = 0;
for(ll i = a; i < n; i ++){
if(c[i] == x){
count1 ++;
}
}
pf("%.6lf",(lf)sum/(lf)a); pn
pld(C(count0+count1,count0)); pn
return 0;
}
| a.cc: In function 'int main()':
a.cc:52:12: error: 'sdl' was not declared in this scope; did you mean 'sld'?
52 | sld(a) sdl(b)
| ^~~
| sld
a.cc:53:19: error: 'i' was not declared in this scope
53 | for(ll i = 0; i < n; i ++){
| ^
|
s647631888 | p03776 | C++ | #include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
void Yes(){
cout<<"Yes"<<endl;
exit(0);
}
void No(){
cout<<"No"<<endl;
exit(0);
}
ll C[51][51];
void comb_table(int N){
for(int i = 0;i <= N; ++i){
for(int j = 0;j <= i; ++j){
if(j == 0 || j == i){
C[i][j] = 1LL;
}else{
C[i][j] = C[i-1][j-1] + C[i-1][j];
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, A, B; cin >> N >> A >> B;
comb_table(N);
ld v[55]; rep(i, N) cin >> v[i];
sort(v, v + N, greater<ll>());
ld mini = v[A - 1];
int cnt = 0, cnt1 = 0;
rep(i, N) {
if(v[i] == mini) cnt ++;
}
ld ans = 0;
rep(i, A) {
ans += v[i];
if(v[i] == mini) cnt1 ++;
}
ans /= A;
cout << fixed << setprecison(8) << ans << endl;
if(v[0] != mini) {
cout << C[cnt][cnt1] << endl;
} else {
ll ans1 = 0;
Rep(i, A, B + 1) {
if(cnt < i) break;
ans1 += C[cnt][i];
}
cout << ans1 << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:87:22: error: 'setprecison' was not declared in this scope
87 | cout << fixed << setprecison(8) << ans << endl;
| ^~~~~~~~~~~
|
s234948761 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)
const ll INF=1e9+7;
ll n,a,b,ans,k,l;
int te[51];
ll s[51],g;
double h;
ll C[51][51];
void init()
{
memset(C,0,sizeof(C));
C[0][0]=1;
for(int i=1;i<=50;i++)
{
C[i][0]=1;
for(int j=1;j<=i;j++)
C[i][j]=C[i-1][j-1]+C[i-1][j];
}
}
int main()
{
/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
init();
cin>>n>>a>>b;
rep(i,n){
cin>>s[i];
}
sort(s+1,s+n+1);
s[n+1]=s[n];
for(int i=n;i>=1;i--){
if(s[i]!=s[i+1]){
te[++l]=k;
k=0;
}
k++;
}
k=0;
l=0;
for(int i=n;i>=n-a+1;i--){
g+=s[i];
if(s[i]!=s[i+1]){
k=0;
}
k++;
}
// cout<<k<<' '<<upper_bound(s+1,s+n,s[n-b+1])-s<<' '<<lower_bound(s+1,s+n,s[n-b+1])-s<<endl;
int v=min(b,upper_bound(s+1,s+n+1,s[n-b+1])-lower_bound(s+1,s+n+1,s[n-b+1]));
for(int i=k;i<=v;i++){
ans+=C[upper_bound(s+1,s+n+1,s[n-b+1])-lower_bound(s+1,s+n+1,s[n-b+1])][i];
}
double t=g;
h=t/a;
printf("%.7f",h);
cout<<endl<<ans;
return 0;
} | a.cc: In function 'int main()':
a.cc:54:18: error: no matching function for call to 'min(long long int&, long int)'
54 | int v=min(b,upper_bound(s+1,s+n+1,s[n-b+1])-lower_bound(s+1,s+n+1,s[n-b+1]));
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:54:18: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
54 | int v=min(b,upper_bound(s+1,s+n+1,s[n-b+1])-lower_bound(s+1,s+n+1,s[n-b+1]));
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:54:18: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
54 | int v=min(b,upper_bound(s+1,s+n+1,s[n-b+1])-lower_bound(s+1,s+n+1,s[n-b+1]));
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
s059120918 | p03776 | C++ | #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
double dp[55][55];
long long table[55][55];
void make_pascal() {
for(int i = 0; i < 55; ++i) {
table[i][0] = 1;
for (int j = 1; j < i; j++) {
table[i][j] = table[i-1][j-1] + table[i-1][j];
}
table[i][i] = 1;
}
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(false);
int N,A,B; cin >> N >> A >> B;
double v[50]; REP(i,N) cin >> v[i];
make_pascal();
REP(i,N) {
REP(j,N){
double next = (dp[i][j] + v[i]) / (j+1);
chmax(dp[i+1][j+1], next);
chmax(dp[i+1][j ], dp[i][j]);
}
}
// count
sort(v, v + N, greater<double>());
int num = 0, pos = 0;
for(int i=0;i<N;++i){
if(v[i] == v[A-1]) {
++num;
if(i < A) ++pos;
}
}
ll cnt = 0LL;
if(pos == A){
for(pos = A; pos <= B; ++pos) cnt += table[num][pos];
} else {
cnt += table[num][pos];
}
double ans = 0.0;
REP(i,N+1) if(A<=i && i<=B) chmax(ans, dp[N][i]);
cout << fixed << setprecision(10) << ans << '\n';
cout << cnt << '\n';
return 0;
}
// build O(n), query O(logn)
struct SegmentTree {
vector<int> data;
int n;
SegmentTree(int n_) {
for(n = 1; n < n_; n *= 2);
data.assign(n*2 - 1, INT_MAX);
}
void update(int i,int x){
i += n - 1;
data[i] = x;
while(i){
i = (i-1) / 2;
data[i] = min(data[i*2 + 1], data[i*2 + 2]);
}
}
// query for [a,b)
int query(int a,int b,int i,int l,int r){
if(b<=l || r<=a) return INT_MAX;
if(a<=l && r<=b) return data[i];
int vl = query(a, b, i*2+1, l, (l+r)/2);
int vr = query(a, b, i*2+2, (l+r)/2, r);
return min(vl,vr);
}
int query(int a,int b){
return query(a, b, 0, 0, n);
}
} | a.cc:95:2: error: expected ';' after struct definition
95 | }
| ^
| ;
a.cc: In constructor 'SegmentTree::SegmentTree(int)':
a.cc:73:30: error: 'INT_MAX' was not declared in this scope
73 | data.assign(n*2 - 1, INT_MAX);
| ^~~~~~~
a.cc:8:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
7 | #include <iomanip>
+++ |+#include <climits>
8 | using namespace std;
a.cc: In member function 'int SegmentTree::query(int, int, int, int, int)':
a.cc:86:33: error: 'INT_MAX' was not declared in this scope
86 | if(b<=l || r<=a) return INT_MAX;
| ^~~~~~~
a.cc:86:33: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
|
s471747922 | p03776 | C++ | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
std::vector<std::vector<long long>> comb(ll n, ll r) {
std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
for (ll i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (ll j = 1; j < v.size(); j++) {
for (ll k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v;
}
int main(){
ll N,A,B;
cin>>N>>A>>B;
vector <ll> v(N);
for (ll i(0);i<N;i++) cin>>v[i];
sort(v.begin(),v.end(),greater<ll>());
ll sum(0);
ll cnti(0);
for (ll i(A-1);i>=0;i--){
if(v[A-1]==v[i])cnti++;
sum+=v[i];
}
double ans=(double)sum / A;
cout <<setprecision(20)<<ans<<endl;
ll cnt(0);
for (ll i(0);i<N;i++){
if (v[i]==v[A-1]) cnt++;
}
ll ans(0);
if (cnt==N){
for (ll i(A);i<=B;i++){
if (cnt>=i) ans+=comb(cnt,i)[cnt][i];
}
cout << ans <<endl;
return 0;
}
ans=comb(cnt,cnti)[cnt][cnti];
cout << ans<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:37:6: error: conflicting declaration 'll ans'
37 | ll ans(0);
| ^~~
a.cc:31:16: note: previous declaration as 'double ans'
31 | double ans=(double)sum / A;
| ^~~
|
s662269533 | p03776 | C++ | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
std::vector<std::vector<long long>> comb(ll n, ll r) {
std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
for (ll i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (ll j = 1; j < v.size(); j++) {
for (ll k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v;
}
ll main(){
ll N,A,B;
cin>>N>>A>>B;
vector <ll> v(N);
for (ll i(0);i<N;i++) cin>>v[i];
sort(v.begin(),v.end(),greater<ll>());
ll sum(0);
ll cnti(0);
for (ll i(A-1);i>=0;i--){
if(v[A-1]==v[i])cnti++;
sum+=v[i];
}
cout <<setprecision(8)<< (double)sum / A<<endl;
ll cnt(0);
for (ll i(0);i<N;i++){
if (v[i]==v[A-1]) cnt++;
}
ll ans(0);
if (cnt==N){
for (ll i(A);i<=B;i++){
if (cnt>=i) ans+=comb(cnt,i)[cnt][i];
}
cout << ans <<endl;
return 0;
}
ans=comb(cnt,cnti)[cnt][cnti];
cout << ans<<endl;
return 0;
}
| a.cc:19:1: error: '::main' must return 'int'
19 | ll main(){
| ^~
|
s096931369 | p03776 | C++ | #include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl; }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}
const double eps = 1e-12;
typedef ll Int;
const int N = 128;
ll dp[N][N];
ll rec(int n, int r) {
if (n < 0 || r < 0) return 0;
if (dp[n][r] != -1) return dp[n][r];
if (n == 0 || n == r) return dp[n][r] = 1;
return dp[n][r] = rec(n-1, r) + rec(n-1, r-1);
}
class C_cls {
static const int N = 1000000;
vector<Int> facts;
public:
C_cls() : facts(vector<Int>(N, 1)){
FOR(i,1,N) facts[i] = facts[i-1] * Int(i);
}
Int choose(int n, int r) { return rec(n, r); }
};
C_cls C;
double error(double a, double b) {
double abs_error = fabs(a - b);
if (a > eps) { return min(abs_error, abs_error / a); }
return abs_error;
}
int main() {
REP(i,N) REP(j,N) dp[i][j] = -1;
int n, a, b;
while (cin >> n >> a >> b) {
vll v(n);
REP(i,n) cin >> v[i];
sort(RALL(v));
double average = 0;
auto ave = [&](int c) { return accumulate(v.begin(), v.begin() + c, 0.0) / c; };
FOR(c,a,b+1) {
gs(average, ave(c));
}
ll cnt = 0;
FOR(c,a,b+1) if (error(average - ave(c)) < eps) {
// cout << "# c = " << c << endl;
map<ll,int> mn, mr;
ll t = 1;
REP(i,n) mn[v[i]]++;
REP(i,c) mr[v[i]]++;
for (const auto& e: mr) {
// cout << "+= " << mn[e.first] << " C " << e.second << " = " <<
// C.choose(mn[e.first], e.second) << endl;
t *= C.choose(mn[e.first], e.second);
}
cnt += t;
}
printf("%.9lf\n%lld\n", average, cnt);
}
}
| a.cc: In function 'int main()':
a.cc:90:27: error: too few arguments to function 'double error(double, double)'
90 | FOR(c,a,b+1) if (error(average - ave(c)) < eps) {
| ~~~~~^~~~~~~~~~~~~~~~~~
a.cc:67:8: note: declared here
67 | double error(double a, double b) {
| ^~~~~
|
s369410927 | p03776 | C++ | #include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
int64_t GetCombination(int64_t n, int64_t r) {
cerr << "\033[93m" << n << " " << r << "\033[m" << endl;
if (n / 2 < r) {
r = n - r;
}
assert(r >= 0);
assert(n >= 0);
if (r == 0) return 1;
return n * GetCombination(n - 1, r - 1) / r;
}
void OutputError(std::string s) {
cerr << "\033[93m" << s << "\033[m" << endl;
return;
}
int main(void) {
cout << std::fixed << std::setprecision(10);
cin.tie(0);
std::ios::sync_with_stdio(false);
int64_t n, a, b;
cin >> n >> a >> b;
std::vector<int64_t> v(n);
int64_t sum = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
std::sort(v.begin(), v.end(), std::greater<int64_t>());
bool all_same = true;
for (int i = 0; i < a; i++) {
sum += v[i];
if (i >= 1 && v[i - 1] != v[i]) {
all_same = false;
}
}
int64_t pattern = 0;
if (all_same) {
cerr << "allsame" << endl;
int64_t number_canchoose = 0;
for (int i = 0; i < n; i++) {
cerr << "\033[93m"
<< "roop 1"
<< "\033[m" << endl;
if (v[i] == v[0]) {
number_canchoose++;
} else
break;
}
for (int i = a; i <= b && i <= number_canchoose; i++) {
pattern += GetCombination(number_canchoose, i);
}
} else {
cerr << "not allsame" << endl;
int64_t number_canchoose = 0;
for (int i = 0; i < n; i++) {
if (v[i] == v[a - 1]) {
number_canchoose++;
}
}
int64_t number_shouldchoose = 0;
for (int i = 0; i < a; i++) {
if (v[i] == v[a - 1]) {
number_shouldchoose++;
}
}
pattern = GetCombination(number_canchoose, number_shouldchoose);
}
cout << (double)sum / a << endl;
cout << pattern << endl;
return 0;
}
| a.cc: In function 'int64_t GetCombination(int64_t, int64_t)':
a.cc:20:3: error: 'assert' was not declared in this scope
20 | assert(r >= 0);
| ^~~~~~
a.cc:9:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
8 | #include <utility>
+++ |+#include <cassert>
9 | #include <vector>
|
s663275429 | p03776 | C++ | #include <iostream>
using namespace std;
typedef long long ll;
ll c[51][51];
ll com(ll n, ll k){
if(k == 0) return 1;
if(k == n) return 1;
if(k > n) return 0;
if(c[n][k]) return c[n][k];
return c[n][k] = com(n - 1, k) + com(n - 1, k - 1);
}
int main()
{
int n, a, b;
cin >> n >> a >> b;
ll v[51];
for(int i = 0; i < n; i++){
cin >> v[i];
}
sort(v, v + n, greater<ll>());
for(int i = 0; i <= 50; i++){
for(int j = 0; j <= 50; j++){
c[i][j] = 0;
}
}
ll lim = v[a - 1];
ll sum = 0;
for(int i = 0; i < a; i++){
sum += v[i];
}
printf("%.15f\n", sum * 1.0 / a);
int lsum = 0;
int lbf = 0;
for(int i = 0; i < n; i++){
if(v[i] == lim){
lsum++;
if(i < a) lbf++;
}
}
if(v[0] != lim) cout << com(lsum, lbf) << endl;
else{
ll ans = 0;
for(int i = a; i <= b; i++){
ans += com(lsum, i);
}
cout << ans << endl;
}
} | a.cc: In function 'int main()':
a.cc:23:5: error: 'sort' was not declared in this scope; did you mean 'short'?
23 | sort(v, v + n, greater<ll>());
| ^~~~
| short
|
s690251767 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define int long long
int nCm(int n,int m){
m=min(m,n-m);
if( m==0)return 0;
else return nCm(n-1,m-1)+nCm(n-1,m);
}
signed main(){
int n,a,b;cin>>n>>a>>b;
vector<int> v(n);
for(auto&& w:v)cin>>w;
int sm=accumulate(v.begin(),v,begin()+a,0);
double avg=(double)sm/a;
sort(v.begin(),v.end(),greater<int>());
int a0=v[a-1];
int x=count(v.begin(),v.end(),a0);
int y=count(v.begin(),v.begin()+a,a0);
int cnt;
if(y<a){cnt=nCm(x,y);}
else {int b0=min(b,y);
for(int i=0;i+a<b0;i++){
cnt+=nCm(y,(x+i));}
}
cout<<cnt<<endl;
cout.setprecision(10);
cout<<avg<<endl;
} | a.cc: In function 'int main()':
a.cc:16:44: error: no matching function for call to 'begin()'
16 | int sm=accumulate(v.begin(),v,begin()+a,0);
| ~~~~~^~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
from /usr/include/c++/14/bits/stl_algo.h:59,
from /usr/include/c++/14/algorithm:61,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/initializer_list:88:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)'
88 | begin(initializer_list<_Tp> __ils) noexcept
| ^~~~~
/usr/include/c++/14/initializer_list:88:5: note: candidate expects 1 argument, 0 provided
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:52:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)'
52 | begin(_Container& __cont) -> decltype(__cont.begin())
| ^~~~~
/usr/include/c++/14/bits/range_access.h:52:5: note: candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/range_access.h:63:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)'
63 | begin(const _Container& __cont) -> decltype(__cont.begin())
| ^~~~~
/usr/include/c++/14/bits/range_access.h:63:5: note: candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/range_access.h:95:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])'
95 | begin(_Tp (&__arr)[_Nm]) noexcept
| ^~~~~
/usr/include/c++/14/bits/range_access.h:95:5: note: candidate expects 1 argument, 0 provided
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/valarray:1227:5: note: candidate: 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)'
1227 | begin(valarray<_Tp>& __va) noexcept
| ^~~~~
/usr/include/c++/14/valarray:1227:5: note: candidate expects 1 argument, 0 provided
/usr/include/c++/14/valarray:1238:5: note: candidate: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)'
1238 | begin(const valarray<_Tp>& __va) noexcept
| ^~~~~
/usr/include/c++/14/valarray:1238:5: note: candidate expects 1 argument, 0 provided
a.cc:33:14: error: 'std::ostream' {aka 'class std::basic_ostream<char>'} has no member named 'setprecision'; did you mean 'std::streamsize std::ios_base::_M_precision'? (not accessible from this context)
33 | cout.setprecision(10);
| ^~~~~~~~~~~~
In file included from /usr/include/c++/14/streambuf:43,
from /usr/include/c++/14/bits/streambuf_iterator.h:35,
from /usr/include/c++/14/iterator:66,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/ios_base.h:578:25: note: declared protected here
578 | streamsize _M_precision;
| ^~~~~~~~~~~~
|
s467370472 | p03776 | C++ | #include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>
#include<stack>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<complex>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
/**** Type Define ****/
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
typedef complex<double> C;
/**** Macro Define ****/
#define cx real()
#define cy imag()
/**** Const List ****/
const ll INF = 1LL << 62;
const double DINF = 1e30;
const ll mod = 1000000007;
const ll MAX_FLOW_MAX_V = 10000;
const ll MIN_COST_FLOW_MAX_V = 10000;
const ll BIPARTITE_MATCHING_MAX_V = 10000;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const C I = C(0, 1);
const double EPS = 1e-10;
/**** General Functions ****/
template <typename T>
T tmin(T a, T b) { return a > b ? b : a; };
template <typename T>
T tmax(T a, T b) { return a > b ? a : b; };
template <typename T>
T tadd(T a, T b) { return a + b; };
template <typename T>
T tmul(T a, T b) { return a * b; };
template <typename T>
T tpow(T a, T b) { return a * b; };
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1, y = 0; return a;
}
ll q = a/b, g = extgcd(b, a - q*b, x, y);
ll z = x - q * y;
x = y;
y = z;
return g;
}
ll invmod (ll a, ll m) { // a^-1 mod m
ll x, y;
extgcd(a, m, x, y);
x %= m;
if (x < 0) x += m;
return x;
}
ll nCk(ll n, ll k, ll mod) {
ll ans = 1;
for (ll i = n, j = 1; j <= k; i--, j++) ans = (((ans * i) % mod) * invmod(j, mod)) % mod;
return ans;
}
ll lmin(ll a, ll b) { return a > b ? b : a; };
ll lmax(ll a, ll b) { return a > b ? a : b; };
ll lsum(ll a, ll b) { return a + b; };
/**** Matrix ****/
template <typename T>
struct Matrix {
typedef vector<T> vec;
typedef vector<vec> mat;
ll x, y; // x: horizon y: vertical
mat d;
Matrix(ll _y, ll _x = -1) {
if (_x == -1) _x = _y;
x = _x, y = _y;
for (int i = 0; i < y; i++) for (int j = 0; j < x; j++) d[i][j] = 0;
}
void unit() {
for (int i = 0; i < y; i++) for (int j = 0; j < x; j++) d[i][j] = i == j ? 1 : 0;
}
Matrix copy() {
Matrix m(y, x);
for (int i = 0; i < y; i++) for (int j = 0; j < x; j++) m.d[i][j] = d[i][j];
return m;
}
Matrix<T> operator + (Matrix<T>& t) { // No error check! Don't forget to check Matrix size!!
Matrix<T> m(y, x);
for (int i = 0; i < y; i++) for (int j = 0; j < x; j++) m.d[i][j] = d[i][j] + t.d[i][j];
return m;
}
Matrix<T> operator - (Matrix<T>& t) {
Matrix<T> m(y, x);
for (int i = 0; i < y; i++) for (int j = 0; j < x; j++) m.d[i][j] = d[i][j] - t.d[i][j];
return m;
}
Matrix<T> operator * (T t) {
Matrix<T> m(y, x);
for (int i = 0; i < y; i++) for (int j = 0; j < x; j++) m.d[i][j] = d[i][j] * t;
return m;
}
Matrix<T> det(Matrix<T>& t) { // x need to correspond to t.y
Matrix<T> m(y, x);
for (int i = 0; i < y; i++)
for (int j = 0; j < x; j++)
for (int k = 0; k < t.x; k++) m.d[i][j] += d[i][k] * t.d[k][j]; ////////////// mod???
return m;
}
};
/**** Zip ****/
template <typename T>
class Zip {
vector<T> d;
bool flag;
public:
Zip() {
flag = false;
}
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) { // T need to have operator < !!
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return (ll)d.size();
}
};
/**** Union Find ****/
class UnionFind {
vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
void init(ll n) {
par.resize(n, 1); rank.resize(n, 0);
}
ll getSize(ll x) {
return par[find(x)];
}
ll find(ll x) {
if (par[x] > 0) return x;
return -(par[x] = -find(-par[x]));
}
void merge(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y) return;
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = -y;
} else {
par[x] += par[y];
par[y] = -x;
if (rank[x] == rank[y]) rank[x]++;
}
}
bool isSame(ll x, ll y) {
return find(x) == find(y);
}
};
template <typename T>
struct UnionFindT {
vector<ll> par;
vector<ll> rank;
vector<T> diff_weight;
UnionFindT(ll n = 1, T SUM_UNITY = 0) {
init(n, SUM_UNITY);
}
void init(ll n = 1, T SUM_UNITY = 0) {
par.resize(n); rank.resize(n); diff_weight.resize(n);
for (ll i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
}
ll find(ll x) {
if (par[x] == x) {
return x;
}
else {
ll r = find(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
T weight(ll x) {
find(x);
return diff_weight[x];
}
bool isSame(ll x, ll y) {
return find(x) == find(y);
}
bool merge(ll x, ll y, T w) {
w += weight(x); w -= weight(y);
x = find(x); y = find(y);
if (x == y) return false;
if (rank[x] < rank[y]) swap(x, y), w = -w;
if (rank[x] == rank[y]) ++rank[x];
par[y] = x;
diff_weight[y] = w;
return true;
}
T diff(ll x, ll y) {
return weight(y) - weight(x);
}
};
class PersistentUnionFind {
vector<ll> rank, fin, par;
ll index;
public:
void init(ll n) {
index = 0;
par.resize(n); rank.resize(n, 1); fin.resize(n, 0);
for (ll i = 0; i < n; i++) par[i] = i;
}
ll find(ll x, ll t) {
if (t >= fin[x] && par[x] != x) return find(par[x], t);
return x;
}
void merge(ll x, ll y) {
x = find(x, index);
y = find(y, index);
index++;
if (x == y) return;
if (rank[x] < rank[y]) par[x] = y, fin[x] = index;
else {
par[y] = x, fin[y] = index;
if (rank[x] == rank[y]) rank[x]++;
}
}
bool isSame(ll x, ll y, ll t) { return find(x, t) == find(y, t); }
};
/**** Segment Tree ****/
template <typename T>
class SegmentTree {
ll n;
vector<T> node;
function<T(T, T)> fun, fun2;
bool customChange;
T outValue, initValue;
public:
void init(ll num, function<T(T, T)> resultFunction, T init, T out, function<T(T, T)> changeFunction = NULL) {
// changeFunction: (input, beforevalue) => newvalue
fun = resultFunction;
fun2 = changeFunction;
customChange = changeFunction != NULL;
n = 1;
while (n < num) n *= 2;
node.resize(2 * n - 1, init);
outValue = out;
initValue = init;
}
void valueChange(ll num, T value) {
num += n-1;
if (customChange) node[num] = fun2(value, node[num]);
else node[num] = value;
while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
}
T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
if (r == -1) r = n;
if (a <= l && r <= b) return node[k];
if (b <= l || r <= a) return outValue;
ll mid = (l + r) / 2;
return fun(rangeQuery(a, b, l, mid, 2*k+1), rangeQuery(a, b, mid, r, 2*k+2));
}
};
template <typename T>
class LazySegmentTree {
ll n;
vector<T> node;
vector<T> lazyNode;
function<T(T, T)> fun, fun2;
function<T(T, ll)> fun3;
T outValue, initValue;
T substitution(T a, T b) { return a; }
void eval(ll k, ll l, ll r) {
if (lazyNode[k] == 0) return;
node[k] = fun2(fun3(lazyNode[k], r - l), node[k]);
if (r - l > 1) {
lazyNode[2 * k + 1] = fun2(lazyNode[k], lazyNode[2 * k + 1]);
lazyNode[2 * k + 2] = fun2(lazyNode[k], lazyNode[2 * k + 2]);
}
lazyNode[k] = initValue;
}
public:
void init(ll num, function<T(T, T)> resultFunction, function<T(T, T)> changeFunction, function<T(T, ll)> lazyFunction, T init, T out) {
// changeFunction: (input, beforevalue) => newvalue
// lazyFunction: (lazyNode, diff) => newvalue
fun = resultFunction;
fun2 = changeFunction;
fun3 = lazyFunction;
n = 1;
while (n < num) n *= 2;
node.resize(2 * n - 1, init);
lazyNode.resize(2 * n - 1, init);
outValue = out;
initValue = init;
}
void rangeChange(ll a, ll b, T value, ll l = 0, ll r = -1, ll k = 0) {
if (r == -1) r = n;
eval(k, l, r);
if (b <= l || r <= a) return;
if (a <= l && r <= b) {
lazyNode[k] = fun2(value, lazyNode[k]);
eval(k, l, r);
} else {
ll mid = (l + r) / 2;
rangeChange(a, b, value, l, mid, 2*k+1);
rangeChange(a, b, value, mid, r, 2*k+2);
node[k] = fun(node[2*k+1], node[2*k+2]);
}
}
T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
if (r == -1) r = n;
if (b <= l || r <= a) return outValue;
eval(k, l, r);
if (a <= l && r <= b) return node[k];
ll mid = (l + r) / 2;
return fun(rangeQuery(a, b, l, mid, 2*k+1), rangeQuery(a, b, mid, r, 2*k+2));
}
};
/**** Network Flow ****/
class MaxFlow {
public:
struct edge { ll to, cap, rev; };
vector<edge> G[MAX_FLOW_MAX_V];
bool used[MAX_FLOW_MAX_V];
ll level[MAX_FLOW_MAX_V];
ll iter[MAX_FLOW_MAX_V];
void init() {
for (ll i = 0; i < MAX_FLOW_MAX_V; i++) {
G[i].clear();
}
}
void add_edge(ll from, ll to, ll cap) {
G[from].push_back((edge){to, cap, (ll)G[to].size()});
G[to].push_back((edge){from, 0, (ll)G[from].size() - 1});
}
void add_undirected_edge(ll e1, ll e2, ll cap) {
G[e1].push_back((edge){e2, cap, (ll)G[e2].size()});
G[e2].push_back((edge){e1, cap, (ll)G[e1].size() - 1});
}
ll dfs(ll v, ll t, ll f) {
if (v == t) return f;
used[v] = true;
for (ll i = 0; i < (ll)G[v].size(); i++) {
edge &e = G[v][i];
if (!used[e.to]&& e.cap > 0) {
ll d = dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
ll max_flow(ll s, ll t) {
ll flow = 0;
while (1) {
memset(used, 0, sizeof(used));
ll f = dfs(s, t, INF);
if (f == 0) return flow;
flow += f;
}
}
void bfs(ll s) {
memset(level, -1, sizeof(level));
queue<ll> que;
level[s] = 0;
que.push(s);
while (!que.empty()) {
ll v = que.front(); que.pop();
for (ll i = 0; i < (ll)G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
que.push(e.to);
}
}
}
}
ll dinic_dfs(ll v, ll t, ll f) {
if (v == t) return f;
for (ll &i= iter[v]; i < (ll)G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && level[v] < level[e.to]) {
ll d = dinic_dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
ll dinic(ll s, ll t) {
ll flow = 0;
while (1) {
bfs(s);
if (level[t] < 0) return flow;
memset(iter, 0, sizeof(iter));
ll f;
while ((f = dinic_dfs(s, t, INF)) > 0) {
flow += f;
}
}
}
};
/**** bipartite matching ****/
class BipartiteMatching {
public:
ll V;
vector<ll> G[BIPARTITE_MATCHING_MAX_V];
ll match[BIPARTITE_MATCHING_MAX_V];
bool used[BIPARTITE_MATCHING_MAX_V];
BipartiteMatching(ll v) {
V = v;
}
void init(ll v) {
V = v;
for (ll i = 0; i < BIPARTITE_MATCHING_MAX_V; i++) {
G[i].clear();
}
}
void add_edge(ll u, ll v) {
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(ll v) {
used[v] = true;
for (ll i = 0; i < (ll)G[v].size(); i++) {
ll u = G[v][i], w = match[u];
if (w < 0 || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
ll max_matching() {
ll res = 0;
memset(match, -1, sizeof(match));
for (ll v = 0; v < V;v++) {
if (match[v] < 0) {
memset(used, 0, sizeof(used));
if (dfs(v)) {
res++;
}
}
}
return res;
}
};
class MinCostFlow {
public:
struct edge { ll to, cap, cost, rev; };
ll V;
vector<edge> G[MIN_COST_FLOW_MAX_V];
ll dist[MIN_COST_FLOW_MAX_V];
ll prevv[MIN_COST_FLOW_MAX_V];
ll preve[MIN_COST_FLOW_MAX_V];
ll h[MIN_COST_FLOW_MAX_V];
MinCostFlow(ll v) {
V = v;
}
void init() {
for (ll i = 0; i < MAX_FLOW_MAX_V; i++) {
G[i].clear();
}
}
void add_edge(ll from, ll to, ll cap, ll cost) {
G[from].push_back((edge){to, cap, cost, (ll)G[to].size()});
G[to].push_back((edge){from, 0, -cost, (ll)G[from].size() - 1});
}
void add_undirected_edge(ll e1, ll e2, ll cap, ll cost) {
add_edge(e1, e2, cap, cost);
add_edge(e2, e1, cap, cost);
}
ll min_cost_flow(ll s, ll t, ll f) { // minas
ll res = 0;
while (f > 0) {
fill(dist, dist + V, INF);
dist[s] = 0;
bool update = true;
while (update) {
update = false;
for (ll v = 0; v < V; v++) {
if (dist[v] == INF) continue;
for (ll i = 0; i < (ll)G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
dist[e.to] = dist[v] + e.cost;
prevv[e.to] = v;
preve[e.to] = i;
update = true;
}
}
}
}
if (dist[t] == INF) {
return -1;
}
ll d = f;
for (ll v = t; v != s; v = prevv[v]) {
d = min(d, G[prevv[v]][preve[v]].cap);
}
f -= d;
res += d * dist[t];
for (ll v = t; v != s; v = prevv[v]) {
edge &e = G[prevv[v]][preve[v]];
e.cap -= d;
G[v][e.rev].cap += d;
}
}
return res;
}
ll min_cost_flow_dijkstra(ll s, ll t, ll f) {
ll res = 0;
fill(h, h + V, 0);
while (f > 0) {
priority_queue<P, vector<P>, greater<P> > que;
fill(dist, dist + V, 0);
dist[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top(); que.pop();
int v = p.second;
if (dist[v] < p.first) continue;
for (int i = 0; i < G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
prevv[e.to] = v;
preve[e.to] = i;
que.push(P(dist[e.to], e.to));
}
}
}
if (dist[t] == INF) {
return -1;
}
for (int v = 0; v < V; v++) h[v] += dist[v];
int d = f;
for (int v = t; v != s; v = prevv[v]) {
d = tmin<ll>(d, G[prevv[v]][preve[v]].cap);
}
f -= d;
res += d * h[t];
for (int v = t; v != s; v = prevv[v]) {
edge &e = G[prevv[v]][preve[v]];
e.cap -= d;
G[v][e.rev].cap += d;
}
return res;
}
return 0;
}
};
/**** LIS ****/
ll lis(ll* a, ll n, ll* dp) {
fill(dp, dp + n, INF);
for (ll i = 0; i < n; i++) *lower_bound(dp, dp + n, a[i]) = a[i];
return (ll)(lower_bound(dp, dp + n, INF) - dp);
}
/**** Binary Search ****/
ll binarySearch(function<bool(ll)> check, ll ok, ll ng) {
while ((ok - ng > 1) || (ng - ok > 1)) {
ll mid = (ok + ng) / 2;
if (check(mid)) ok = mid;
else ng = mid;
}
return ok;
}
double binarySearchDouble(function<bool(double)> check, double ok, double ng) {
while ((ok - ng > EPS) || (ng - ok > EPS)) {
double mid = (ok + ng) / 2;
if (check(mid)) ok = mid;
else ng = mid;
}
return ok;
}
/**** Geometry ****/
bool isEqual(double a, double b) { return abs(a - b) < EPS; }
bool isCEqual(C a, C b) { return isEqual(a.cx, a.cy) && isEqual(a.cy, a.cy); }
bool isZero(double a) { return abs(a) < EPS; } // a == 0
bool isUZero(double a) { return a > EPS; } // a > 0
bool isUEZero(double a) { return a > -EPS; } // a >= 0
bool isLZero(double a) { return a < -EPS; } // a < 0
bool isLEZero(double a) { return a < EPS; } // a <= 0
C getUnitVector(C a) { double len = abs(a); return isZero(len) ? C(0.0, 0.0) : a / len; }
double dot(C a, C b) { return a.cx * b.cx + a.cy * b.cy; } // |a||b|cosθ
double det(C a, C b) { return a.cx * b.cy - a.cy * b.cx; } // |a||b|sinθ
bool isLineOrthogonal(C a1, C a2, C b1, C b2) { return isZero(dot(a1 - a2, b1 - b2)); } // a1-a2, b1-b2
bool isLineParallel(C a1, C a2, C b1, C b2) { return isZero(det(a1 - a2, b1 - b2)); } // a1-a2, b1-b2
bool isPointOnLine(C a, C b, C c) { return isZero(det(b - a, c - a)); } // a-b <- c
/*
bool isPointOnLineSegment(C a, C b, C c) { // a-b <- c
return isZero(det(b - a, c - a)) && isUEZero(dot(b - a, c - a)) && isUEZero(dot(a - b, c - b));
}
*/
bool isPointOnLineSegment(C a, C b, C c) { return isZero(abs(a-c) + abs(c-b) - abs(a-b)); }
double distanceLineAndPoint(C a, C b, C c) { return abs(det(b-a, c-a)) / abs(b-a); } // a-b <- c
double distanceLineSegmentAndPoint(C a, C b, C c) { // a-b <- c
if (isLEZero(dot(b-a, c-a))) return abs(c-a);
if (isLEZero(dot(a-b, c-b))) return abs(c-b);
return abs(det(b-a, c-a)) / abs(b-a);
}
bool isIntersectedLine(C a1, C a2, C b1, C b2) { // a1-a2, b1-b2
return !isLineParallel(a1, a2, b1, b2);
}
C intersectionLine(C a1, C a2, C b1, C b2) { // isIntersectedLine-> true
C a = a2 - a1, b = b2 - b1;
return a1 + a * det(b, b1 - a1) / det(b, a);
}
/**** NG Words ****/
// cx cy P Q C
// Warning: EPS
/**** main function ****/
ll n, a, b, v[50];
cpp_int nCk_cpp(cpp_int n, cpp_int k) {
cpp_int ans = 1;
for (cpp_int i = 0; i < k; i++) ans = ans * (n - i) / (i + 1);
return ans;
}
int main() {
scanf("%lld", &n);
scanf("%lld%lld", &a, &b);
for (ll i = 0; i < n; i++) scanf("%lld", &v[i]);
sort(v, v+n, greater<ll>());
ll ans = 0, counter = 0, c2 = 0;
for (ll i = 0; i < a; i++) ans += v[i];
for (ll i = 0; i < n; i++) {
if (v[i] == v[a-1]) counter++;
if (v[i] > v[a-1]) c2++;
}
printf("%.10lf\n", (double)ans / a);
ll temp = (ll)nCk_cpp(counter, a-c2);
if (c2 == 0) {
for (ll i = a; v[i] == v[0] && i < b; i++) {
temp += (ll)nCk_cpp(counter, i+1);
}
}
printf("%lld\n", temp);
}
| a.cc:13:9: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
13 | #include<boost/multiprecision/cpp_int.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
|
s117632824 | p03776 | Java | import java.math.BigInteger;
import java.util.stream.*;
import java.util.*;
public class Main {
static Scanner scanner = new Scanner(System.in);
public static void main(String[]$) {
int n = scanner.nextInt();
int a = scanner.nextInt();
int b = scanner.nextInt();
long[] v = IntStream.range(0, n).mapToLong(i -> scanner.nextLong()).sorted().toArray();
double ave = Arrays.stream(v).skip(n - a).average().getAsDouble();
int count = 0;
int max = 0, min;
for (int i = 0; i < n; i++) {
if (v[i] == v[n - a]) {
count++;
max = i;
}
}
min = a - n + max + 1;
max = max + 1 == n ? Math.min(b - n + max + 1, count) : min;
BigInteger[] fac = new BigInteger[count + 1];
fac[0] = BigInteger.ONE;
for (int i = 1; i <= count; i++) {
fac[i] = fac[i - 1].multiply(BigInteger.valueOf(i));
}
long ans = 0;
for (int i = min; i <= max; i++) {
ans += fac[count].divide(fac[count - i].multiply(fac[i])).longValue();
}
System.out.println(ave);
System.out.println(ans);
Util.println(count, min, max);
System.out.println(Arrays.toString(v));
}
} | Main.java:41: error: cannot find symbol
Util.println(count, min, max);
^
symbol: variable Util
location: class Main
1 error
|
s026369297 | p03776 | C++ | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ull=unsigned long long;
using uint=unsigned int;
using pcc=pair<char,char>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using pdd=pair<double,double>;
using tuplis=pair<ll,pll>;
using tuplis2=pair<pll,ll>;
template<class T> using pq=priority_queue<T,vector<T>,greater<T>>;
const ll LINF=0x1fffffffffffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
const int INF=0x3fffffff;
const ld DINF=numeric_limits<ld>::infinity();
const ld EPS=1e-8;
const vector<pii> four={{-1,0},{0,1},{1,0},{0,-1}};
#define _overload4(_1,_2,_3,_4,name,...) name
#define _overload3(_1,_2,_3,name,...) name
#define _rep1(n) for(ll i=0;i<n;++i)
#define _rep2(i,n) for(ll i=0;i<n;++i)
#define _rep3(i,a,b) for(ll i=a;i<b;++i)
#define _rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) _overload4(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(ll i=n-1;i>=0;i--)
#define _rrep2(i,n) for(ll i=n-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=b-1;i>=a;i--)
#define _rrep4(i,a,b,c) for(ll i=a+(b-a-1)/c*c;i>=a;i-=c)
#define rrep(...) _overload4(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define each(i,a) for(auto &i:a)
#define sum(...) accumulate(range(__VA_ARGS__),0LL)
#define dsum(...) accumulate(range(__VA_ARGS__),double(0))
#define _range(i) (i).begin(),(i).end()
#define _range2(i,k) (i).begin(),(i).begin()+k
#define _range3(i,a,b) (i).begin()+a,(i).begin()+b
#define range(...) _overload3(__VA_ARGS__,_range3,_range2,_range)(__VA_ARGS__)
#define _rrange(i) (i).rbegin(),(i).rend()
#define _rrange2(i,k) (i).rbegin(),(i).rbegin()+k
#define _rrange3(i,a,b) (i).rbegin()+a,(i).rbegin()+b
#define rrange(...) _overload3(__VA_ARGS__,_rrange3,_rrange2,_rrange)(__VA_ARGS__)
#define elif else if
#define unless(a) if(!(a))
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
volatile struct SETTINGS{SETTINGS(){cout<<fixed<<setprecision(20);};};volatile SETTINGS _SETTINGS();
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline constexpr T min(vector<T> &v){return *min_element(range(v));}
inline char min(string &v){return *min_element(range(v));}
template<class T> inline constexpr T max(vector<T> &v){return *max_element(range(v));}
inline char max(string &v){return *max_element(range(v));}
inline constexpr ll intpow(const ll&a,const ll&b){if(b==0)return 1;ll ans=intpow(a,b/2);return ans*ans*(b&1?a:1);}
inline constexpr ll modpow(const ll&a,const ll&b,const ll&mod=MOD){if(b==0)return 1;ll ans=modpow(a,b/2,mod);ans=ans*ans%mod;if(b&1)ans=ans*a%mod;return ans;}
template<typename T>
inline constexpr bool update_min(T &mn,const T &cnt){if(mn>cnt){mn=cnt;return 1;}else return 0;}
template<typename T>
inline constexpr bool update_max(T &mx,const T &cnt){if(mx<cnt){mx=cnt;return 1;}else return 0;}
inline int scan(){return getchar();}
inline void scan(bool &a){int b;scanf("%d",&b);a=b;}
inline void scan(int &a){scanf("%d",&a);}
inline void scan(unsigned &a){scanf("%u",&a);}
inline void scan(ll &a){scanf("%lld",&a);}
inline void scan(ull &a){scanf("%llu",&a);}
inline void scan(char &a){scanf("%c",&a);}
inline void scan(float &a){scanf("%f",&a);}
inline void scan(double &a){scanf("%lf",&a);}
inline void scan(ld &a){scanf("%Lf",&a);}
template<class T> inline istream &operator >> (istream &is, vector<T> &vec);
template<class T,size_t size> inline istream &operator >> (istream &is, array<T,size> &vec);
template<class T,class L> inline istream &operator >> (istream &is, pair<T,L> &p);
template<class T> inline istream &operator >> (istream &is, T vec[]);
template<class T> inline istream &operator >> (istream &is, vector<T> &vec){each(i,vec)scan(i);return is;}
template<class T,size_t size> inline istream &operator >> (istream &is, array<T,size> &vec){each(i,vec)scan(i);return is;}
template<class T,class L> inline istream &operator >> (istream &is, pair<T,L> &p){scan(p.first);scan(p.second);return is;}
template<class T> inline istream &operator >> (istream &is, T vec[]){each(i,vec)scan(i);return is;}
template<class T> inline void scan(T &a){cin>>a;}
inline void in(){}
template <class Head, class... Tail>
inline void in(Head &&head,Tail&&... tail){scan(head);in(move(tail)...);}
inline void print(){printf("\n");}
inline void print(const bool &a){printf("%d",a);}
inline void print(const int &a){printf("%d",a);}
inline void print(const unsigned &a){printf("%u",a);}
inline void print(const ll &a){printf("%lld",a);}
inline void print(const ull &a){printf("%llu",a);}
inline void print(const char &a){printf("%c",a);}
inline void print(const char a[]){printf("%s",a);}
inline void print(const float &a){printf("%f",a);}
inline void print(const double &a){printf("%lf",a);}
inline void print(const ld &a){printf("%Lf",a);}
inline void print(const bool &&a){printf("%d",a);}
inline void print(const int &&a){printf("%d",a);}
inline void print(const unsigned &&a){printf("%u",a);}
inline void print(const ll &&a){printf("%lld",a);}
inline void print(const ull &&a){printf("%llu",a);}
inline void print(const char &&a){printf("%c",a);}
inline void print(const float &&a){printf("%f",a);}
inline void print(const double &&a){printf("%lf",a);}
inline void print(const ld &&a){printf("%Lf",a);}
template<class T> inline ostream &operator << (ostream &os,const vector<T> &vec);
template<class T,size_t size> inline ostream &operator << (ostream &os,const array<T,size> &vec);
template<class T,class L> inline ostream &operator << (ostream &os,const pair<T,L> &p);
template<class T> inline typename enable_if<is_same<T,const char>::value==0,ostream>::type &operator << (ostream &os,T vec[]);
template<class T> inline ostream &operator << (ostream &os,const vector<T> &vec){print(vec.front());for(auto i=vec.begin();++i!=vec.end();){print(' ');print(*i);}return os;}
template<class T,size_t size> inline ostream &operator << (ostream &os,const array<T,size> &vec){print(vec.front());for(auto i=vec.begin();++i!=vec.end();){print(' ');print(*i);}return os;}
template<class T,class L> inline ostream &operator << (ostream &os,const pair<T,L> &p){print(p.first);print(' ');print(p.second);return os;}
template<class T> inline typename enable_if<is_same<T,const char>::value==0,ostream>::type &operator << (ostream &os,T vec[]){print(*vec);for(auto i=vec;++i!=end(vec);){print(' ');print(*i);}return os;}
template<class T> inline void print(const T &a){cout<<a;}
inline bool out(){printf("\n");return 0;}
template <class Head, class... Tail>
inline bool out(const Head &head,const Tail&... tail){print(head);print(' ');out(tail...);return 0;}
template <class T>
inline void err(T t){cerr<<t<<'\n';}
inline void err(){cerr<<'\n';}
inline bool yes(bool i){return out(i?"yes":"no");}
inline bool Yes(bool i){return out(i?"Yes":"No");}
inline bool YES(bool i){return out(i?"YES":"NO");}
inline bool Yay(bool i){return out(i?"Yay!":":(");}
inline bool Possible(bool i){return out(i?"Possible":"Impossible");}
inline bool POSSIBLE(bool i){return out(i?"POSSIBLE":"IMPOSSIBLE");}
inline void Case(ll i){cout<<"Case #"<<i<<": ";}
ll comb(ll n,ll r){
ll ans=1;
rep(r){
ans*=n-i;
ans/=i+1;
}
return ans;
}
signed main(){
LL(n,a,b);
VEC(ll,v,n);
sort(rrange(v));
out(sum(v,a)/double(a));
ll cnt1=0,cnt2=0,i=a-1;
for(;i>=0&&v[i]==v[a-1];i--)cnt1++;
for(i++;i<n&&v[i]==v[a-1];i++)cnt2++;
if(sum(v,a)==v[0]*a){
ll ans=0;
rep(i,a,b+1)ans+=comb(cnt2,i);
out(ans);
}
else out(comb(cnt2,cnt1));
}
| a.cc:58:1: error: 'volatile' can only be specified for objects and functions
58 | volatile struct SETTINGS{SETTINGS(){cout<<fixed<<setprecision(20);};};volatile SETTINGS _SETTINGS();
| ^~~~~~~~
|
s281028291 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
int N,A,B;
vector<long long> v(60);
long long dp[60][60];
long long dq[60][60];
int main(){
cin >> N >> A >> B;
for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){dq[i][j]=1;}
}
dq[0][0]=1;
for(int i=0;i<N;i++)cin >> v[i];
for(int i=0;i<N;i++){
for(int j=0;j<i;j++){
if(dp[i][j+1]==dp[i][j]+v[i]){dq[i+1][j+1]+=dq[i][j+1];}
dp[i+1][j+1]=max(dp[i][j]+v[i],dp[i][j+1]);
}
}
double rec=0; long long ans=0;
for(int i=A;i<=B;i++){
if(rec<dp[N][i]*1.0/i){rec=dp[N][i]*1.0/i; ans=dq[N][i];}
if(rec==dp[N][i]*1.0/i){ans+=dq[N][i];}
}
cout << rec << endl;
cout << ans << endl; | a.cc: In function 'int main()':
a.cc:28:23: error: expected '}' at end of input
28 | cout << ans << endl;
| ^
a.cc:9:11: note: to match this '{'
9 | int main(){
| ^
|
s850843598 | p03776 | C++ | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807
int n,a,b,v,ans,tmpa,memo[51][51],sum;
map<int,int> m;
long double anssum;
signed main() {
cin >> n >> a >> b;tmpa = a;
rep(i,n+1) for(int j=0;j<=i;j++) {
if (j==0 || j==i) memo[i][j] = 1;
else memo[i][j] = memo[i-1][j-1]+memo[i-1][j];
}
rep(i,n) cin >> v,m[v]++;
auto itr = m.rbegin();
if (a <= itr->se) {
anssum = itr->fi;
int hogepiyo = min(b,itr->se);
for(int i=a;i<=hogepiyo;i++) ans += memo[hogepiyo][i];
}
else {
do {
a -= itr->se;
b -= itr->se;
sum += itr->fi*itr->se;
++itr;
}while(a > itr->se);
sum += itr->fi*a;
anssum = sum/tmpa(long double);
ans += memo[itr->se][a];
}
cout << fixed << anssum << endl;
cout << ans << endl;
}
| a.cc: In function 'int main()':
a.cc:46:27: error: expected primary-expression before 'long'
46 | anssum = sum/tmpa(long double);
| ^~~~
a.cc:46:38: error: 'tmpa' cannot be used as a function
46 | anssum = sum/tmpa(long double);
| ^
|
s938318586 | p03776 | C++ | #include<bits/stdc++.h>
#define ll long long
#define met(a, x) memset(a,x,sizeof(a))
#define inf 0x3f3f3f3f
#define ull unsigned long long
#define mp make_pair
using namespace std;
const int mod = 998244353;
const int N = 3e5 + 10;
const int M = 1e6 + 10;
ll a[N];
bool cmp(int x, int y) {
return x > y;
}
ll C[300][300];
void init() {
met(C, 0);
C[0][0] = 1;
for (int i = 1; i <= 50; i++) {
C[i][0] = 1;
for (int j = 1; j <= i; j++)
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
init();
int n, l, r;
while (cin >> n >> l >> r) {
for (int i = 0; i <n; i++)
cin >> a[i];
sort(a, a + n , cmp);
double ans=0;
for(int i=;i<l;i++){
ans+=a[i];
}
ans/=l;
int num=0,cnt=0;
for(int i=0;i<n;i++){
if(a[i]==a[l-1]){
num++;
if(i<l){
cnt++;
}
}
}
ll sum=0;
if(cnt==l){
for(int i=l;i<=r;i++){
sum+=C[num][i];
}
}else{
sum+=C[num][cnt];
}
cout<<fixed<<setprecision(10)<<ans<<endl<<sum<<endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:42:19: error: expected primary-expression before ';' token
42 | for(int i=;i<l;i++){
| ^
|
s587958164 | p03776 | C++ | #define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FS first
#define SC second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for (auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for (auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&a){return accumulate(ALL(a),T());}
template<typename T>T max(vector<T>&a){return *max_element(ALL(a));}
template<typename T>T min(vector<T>&a){return *max_element(ALL(a));}
template<typename T>T max_index(vector<T>&a){return distance((a).begin(),max_element(ALL(a)));}
template<typename T>T min_index(vector<T>&a){return distance((a).begin(),min_element(ALL(a)));}
struct edge { int to, cost; };
template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
const int INF = 1e18;
const int MOD_N = 1e9+7;
signed main()
{
int N, A, B; cin >> N >> A >> B;
V<int> v(N);
REP(i, N) {
cin >> v[i];
}
map<int,int> cnt;
REP(i, N) {
cnt[v[i]]++;
}
int num = 0, sum = 0;
REACH(i, cnt) {
int n = i->SC, x = i->FS;
if (num + n <= A) {
num += n;
sum += n * x;
} else {
sum += (A - num) * x;
break;
}
}
printf("%.9lf\n", (double)sum/A);
cout << (cnt.size() == 1 ? (1LL<<50)-1 : 1) << endl;
return 0;
}
| a.cc:30:41: error: 'pair' does not name a type
30 | template<typename T,typename U> using P=pair<T,U>;
| ^~~~
a.cc:31:30: error: 'vector' does not name a type
31 | template<typename T> using V=vector<T>;
| ^~~~~~
a.cc:34:27: error: 'vector' was not declared in this scope
34 | template<typename T>T sum(vector<T>&a){return accumulate(ALL(a),T());}
| ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
+++ |+#include <vector>
1 | #define int long long int
a.cc:34:35: error: expected primary-expression before '>' token
34 | template<typename T>T sum(vector<T>&a){return accumulate(ALL(a),T());}
| ^
a.cc:34:37: error: 'a' was not declared in this scope
34 | template<typename T>T sum(vector<T>&a){return accumulate(ALL(a),T());}
| ^
a.cc:34:39: error: expected ';' before '{' token
34 | template<typename T>T sum(vector<T>&a){return accumulate(ALL(a),T());}
| ^
| ;
a.cc:35:27: error: 'vector' was not declared in this scope
35 | template<typename T>T max(vector<T>&a){return *max_element(ALL(a));}
| ^~~~~~
a.cc:35:27: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:35:35: error: expected primary-expression before '>' token
35 | template<typename T>T max(vector<T>&a){return *max_element(ALL(a));}
| ^
a.cc:35:37: error: 'a' was not declared in this scope
35 | template<typename T>T max(vector<T>&a){return *max_element(ALL(a));}
| ^
a.cc:35:39: error: expected ';' before '{' token
35 | template<typename T>T max(vector<T>&a){return *max_element(ALL(a));}
| ^
| ;
a.cc:36:27: error: 'vector' was not declared in this scope
36 | template<typename T>T min(vector<T>&a){return *max_element(ALL(a));}
| ^~~~~~
a.cc:36:27: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:36:35: error: expected primary-expression before '>' token
36 | template<typename T>T min(vector<T>&a){return *max_element(ALL(a));}
| ^
a.cc:36:37: error: 'a' was not declared in this scope
36 | template<typename T>T min(vector<T>&a){return *max_element(ALL(a));}
| ^
a.cc:36:39: error: expected ';' before '{' token
36 | template<typename T>T min(vector<T>&a){return *max_element(ALL(a));}
| ^
| ;
a.cc:37:33: error: 'vector' was not declared in this scope
37 | template<typename T>T max_index(vector<T>&a){return distance((a).begin(),max_element(ALL(a)));}
| ^~~~~~
a.cc:37:33: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:37:41: error: expected primary-expression before '>' token
37 | template<typename T>T max_index(vector<T>&a){return distance((a).begin(),max_element(ALL(a)));}
| ^
a.cc:37:43: error: 'a' was not declared in this scope
37 | template<typename T>T max_index(vector<T>&a){return distance((a).begin(),max_element(ALL(a)));}
| ^
a.cc:37:45: error: expected ';' before '{' token
37 | template<typename T>T max_index(vector<T>&a){return distance((a).begin(),max_element(ALL(a)));}
| ^
| ;
a.cc:38:33: error: 'vector' was not declared in this scope
38 | template<typename T>T min_index(vector<T>&a){return distance((a).begin(),min_element(ALL(a)));}
| ^~~~~~
a.cc:38:33: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:38:41: error: expected primary-expression before '>' token
38 | template<typename T>T min_index(vector<T>&a){return distance((a).begin(),min_element(ALL(a)));}
| ^
a.cc:38:43: error: 'a' was not declared in this scope
38 | template<typename T>T min_index(vector<T>&a){return distance((a).begin(),min_element(ALL(a)));}
| ^
a.cc:38:45: error: expected ';' before '{' token
38 | template<typename T>T min_index(vector<T>&a){return distance((a).begin(),min_element(ALL(a)));}
| ^
| ;
a.cc:42:26: error: declaration of 'operator<<' as non-function
42 | template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
| ^~~~~~~~
a.cc:42:37: error: 'ostream' was not declared in this scope
42 | template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
| ^~~~~~~
a.cc:1:1: note: 'std::ostream' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
+++ |+#include <ostream>
1 | #define int long long int
a.cc:42:45: error: 's' was not declared in this scope
42 | template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
| ^
a.cc:42:47: error: expected primary-expression before 'const'
42 | template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
| ^~~~~
a.cc:43:37: error: declaration of 'operator<<' as non-function
43 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
| ^~~~~~~~
a.cc:43:48: error: 'ostream' was not declared in this scope
43 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
| ^~~~~~~
a.cc:43:48: note: 'std::ostream' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:43:56: error: 's' was not declared in this scope
43 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
| ^
a.cc:43:58: error: expected primary-expression before 'const'
43 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
| ^~~~~
a.cc:43:72: error: expected primary-expression before '>' token
43 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
| ^
a.cc:43:74: error: 'p' was not declared in this scope
43 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
| ^
a.cc:44:26: error: declaration of 'operator<<' as non-function
44 | template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
| ^~~~~~~~
a.cc:44:37: error: 'ostream' was not declared in this scope
44 | template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
| ^~~~~~~
a.cc:44:37: note: 'std::ostream' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:44:45: error: 's' was not declared in this scope
44 | template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
| ^
a.cc:44:47: error: expected primary-expression before 'const'
44 | template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
| ^~~~~
a.cc:45:37: error: declaration of 'operator<<' as non-function
45 | template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
| ^~~~~~~~
a.cc:45:48: error: 'ostream' was not declared in this scope
45 | template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
| ^~~~~~~
a.cc:45:48: note: 'std::ostream' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:45:56: error: 's' was not declared in this scope
45 | template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
| ^
a.cc:45:58: error: expected primary-expression before 'const'
45 | template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto |
s444782869 | p03776 | C++ | using ll=long long;
using R=double;
// Combination Table
ll C[51][51]; // C[n][k] -> nCk
void comb_table(int N){
for(int i=0;i<n+1;++i){
for(int j=0;j<=i;++j){
if(j==0||j==i){
C[i][j]=1;
}
else{
C[i][j]=C[i-1][j-1]+C[i-1][j];
}
}
}
}
int main(void){
int N,A,B;
cin>> N>>A>>B;
const int NMAX=50;
ll v[NMAX];
for(int i=0;i<N;++i){
cin >> v[i];
}
comb_table(N);
sort(v,v+N);
reverse(v,v+N);
R max_average=0.0;
for(int i=0;i<A;++i){
max_average+=v[i];
}
max_average/=A;
int a_th_val_num=0,a_th_val_pos=0;
for(int i=0;i<N;++i){
if(v[i]==v[A-1]){
a_th_val_num++;
if(i<A){
a_th_val_pos++;
} }
}
ll cnt=0LL;
if(a_th_val_pos==A){
for(a_th_val_pos=A;a_th_val_pos<=B;++a_th_val_pos){
cnt+=C[a_th_val_num][a_th_val_pos];
} }else{
cnt+=C[a_th_val_num][a_th_val_pos];
}
cout.precision(20);
cout << fixed << max_average << endl;
cout << cnt << endl;
return 0; } | a.cc: In function 'void comb_table(int)':
a.cc:7:19: error: 'n' was not declared in this scope
7 | for(int i=0;i<n+1;++i){
| ^
a.cc: In function 'int main()':
a.cc:21:1: error: 'cin' was not declared in this scope
21 | cin>> N>>A>>B;
| ^~~
a.cc:28:5: error: 'sort' was not declared in this scope; did you mean 'short'?
28 | sort(v,v+N);
| ^~~~
| short
a.cc:29:5: error: 'reverse' was not declared in this scope
29 | reverse(v,v+N);
| ^~~~~~~
a.cc:50:5: error: 'cout' was not declared in this scope
50 | cout.precision(20);
| ^~~~
a.cc:51:13: error: 'fixed' was not declared in this scope
51 | cout << fixed << max_average << endl;
| ^~~~~
a.cc:51:37: error: 'endl' was not declared in this scope
51 | cout << fixed << max_average << endl;
| ^~~~
|
s741979350 | p03776 | C++ |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility>
#define rep(i,m,n) for(int i = m;i < n;i++)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
//combination table
ll C[51][51];
void comb_table(int N) {
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 or j == i) {
C[i][j] = 1LL;
}
else {
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
}
}
}
int main(){
int N, A, B;
cin >> N >> A >> B;
vector<ll> data;
rep(i, 0, N) {
ll x;
cin >> x;
data.push_back(x);
}
sort(data.begin(), data.end());
reverse(data.begin(), data.end());
R max_ave = 0.0;
//まず平均を出力
rep(i, 0, A) {
max_ave += data[i];
}
max_ave /= A;
//組み合わせの計算
comb_table(N);
int a_th_cnt=0;
int a_th_in_cnt = 0;
rep(i, 0, N) {
if (data[i] == data[A - 1]) {
a_th_cnt++;
if (i <= A - 1) {
a_th_in_cnt++;
}
}
}
ll ans = 0LL;
if (data[0] == data[A-1]) {
for(a_th_in_cnt = A; a_th_in_cnt <= B;a_th_in_cnt++) {
ans += C[a_th_cnt][a_th_in_cnt];
}
}
else {
ans = C[a_th_cnt][a_th_in_cnt];
}
cout.precision(20);
cout << fixed << max_ave << endl;
cout << ans << endl; | a.cc: In function 'int main()':
a.cc:92:29: error: expected '}' at end of input
92 | cout << ans << endl;
| ^
a.cc:38:11: note: to match this '{'
38 | int main(){
| ^
|
s407157587 | p03776 | C++ | #include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility>
#define rep(i,m,n) for(int i = m;i < n;i++)
using namespace std;
using ll = long long;
const ll inf = 1LL << 50;
ll comb(ll n, ll r) {
ll ans = 1;
for (ll i = n; i > n - r; --i) {
ans = ans * i;
}
for (ll i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
int main(){
ll N, A, B;
cin >> N >> A >> B;
vector<ll> sum;
vector<ll> data;
map<ll, ll> m;
rep(i, 0, N) {
ll x;
cin >> x;
data.push_back(x);
sum.push_back(x);
m[x]++;
}
sort(data.begin(), data.end());
reverse(data.begin(), data.end());
sort(sum.begin(), sum.end());
reverse(sum.begin(), sum.end());
rep(i, 1, N) {
sum[i] += sum[i - 1];
}
ll temp[2] = { 0,0 };
ll cnt=1;
rep(i, A - 1, B) {
map<ll, ll> s;
rep(j, 0, i + 1) {
s[data[j]]++;
}
if (i == A - 1) {
temp[0] = sum[i];
temp[1] = i + 1;
for (auto a: s) {
cnt *= comb(m[a.first],a.second);
}
}
else if (temp[1] * sum[i] > temp[0] * (i + 1)) {
temp[0] = sum[i];
temp[1] = i + 1;
cnt = 1;
for (auto a:s) {
cnt *= comb(m[a.first], a.second);
}
}
else if (temp[1] * sum[i] == temp[0] * (i + 1)) {
ll tempnum = 1;
for (auto a : s) {
tempnum *= comb(m[a.first], a.second);
}
cnt += tempnum;
}
}
long double ans = long double(temp[0]) / long double(temp[1]);
printf("%f\n", ans);
cout << cnt << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:89:27: error: expected primary-expression before 'long'
89 | long double ans = long double(temp[0]) / long double(temp[1]);
| ^~~~
|
s350321795 | p03776 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setprecision(20)
#define EPS 1e-9
typedef long long ll;
typedef pair<ll, ll> P;
ll comb[51][51];
void makeComb()
{
comb[0][0] = 1;
for (ll i = 0; i <= 50; i++) {
for (ll j = 0; j <= i; j++) {
if (i == 0 || j == 0 || j == i)
comb[i][j] = 1;
else
comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
}
}
}
ll main()
{
makeComb();
/*for (ll i = 0; i < 10; i++) {
for (ll j = 0; j < 10; j++) {
cout << setw(3) << comb[i][j] << ' ';
}
cout << endl;
}*/
ll N, A, B;
cin >> N >> A >> B;
vector<ll> v(N);
REP(i, N) cin >> v[i];
sort(ALL(v), greater<ll>());
/*for (ll i = 0; i < N; i++) cout << v[i] << ' ';
cout << endl;*/
long double sum = 0;
for (ll i = 0; i < A; i++) { sum += v[i]; }
cout << Decimal << (sum / A) << endl;
if (v[0] == v[A - 1]) {
ll bef = A - 1, aft = A;
while (bef >= 0 && v[bef] == v[A-1]) bef--;
while (aft < B && v[aft] == v[A-1]) aft++;
bef = A - 1 - bef;
aft = aft - A;
ll ans = 0;
for (ll i = 0; i <= aft; i++) {
ans += comb[bef + aft][bef + i];
}
cout << ans << endl;
} else {
ll bef = A - 1, aft = A;
while (bef >= 0 && v[bef] == v[A-1]) bef--;
while (aft < N && v[aft] == v[A-1]) aft++;
bef = A - 1 - bef;
aft = aft - A;
cout << comb[bef + aft][bef] << endl;
}
return 0;
}
| a.cc:43:1: error: '::main' must return 'int'
43 | ll main()
| ^~
|
s923203109 | p03776 | C++ | a | a.cc:1:1: error: 'a' does not name a type
1 | a
| ^
|
s185632376 | p03776 | C++ | aaa | a.cc:1:1: error: 'aaa' does not name a type
1 | aaa
| ^~~
|
s212334822 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,a,b;cin>>n>>a>>b;
ll v[n];for(ll i=0;i<n;i++)cin>>v[i];
pair<ll,ll>dp[n+1][n+1];
for(ll i=0;i<=n;i++)for(ll j=0;j<=n;j++)dp[i][j]=make_pair(-1,0);
for(ll i=0;i<=n;i++)dp[i][0]=make_pair(0,0);
for(ll i=0;i<n;i++){
for(ll j=0;j<n;j++){
ll f=dp[i][j].first;
ll s=dp[i][j].second;
if(f>=0){
if(dp[i+1][j].first<f)dp[i+1][j]=dp[i][j];
else if(dp[i+1][j].first==f)dp[i+1][j].second+=s;
if(dp[i+1][j+1].first<f+v[i])dp[i+1][j+1]=make_pair(f+v[i],max((ll)1,s));
else if(dp[i+1][j+1].first==f+v[i]){
dp[i+1][j+1].second+=s;
if(j==0)dp[i+1][j+1].second=1;
}
}
}
double ma=0.0;
double num[n+1];
for(ll i=a;i<=b;i++){
num[i]=(dp[n][i].first)/(i*1.0);
ma=max(ma,num[i]);
}
ll ans=0;
for(ll i=a;i<=b;i++){
if(num[i]==ma)ans+=dp[n][i].second;
}
cout<<ma<<endl;
cout<<ans<<endl;
} | a.cc: In function 'int main()':
a.cc:36:2: error: expected '}' at end of input
36 | }
| ^
a.cc:4:11: note: to match this '{'
4 | int main(){
| ^
|
s498857129 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,a,b;cin>>n>>a>>b;
ll v[n];for(ll i=0;i<n;i++)cin>>v[i];
pair<ll,ll>dp[n+1][n+1];
for(ll i=0;i<=n;i++)for(ll j=0;j<=n;j++)dp[i][j]=make_pair(-1,0);
for(ll i=0;i<=n;i++)dp[i][0]=make_pair(0,0);
for(ll i=0;i<n;i++){
for(ll j=0;j<n;j++){
ll f=dp[i][j].first;
ll s=dp[i][j].second;
if(f>=0){
if(dp[i+1][j].first<f)dp[i+1][j]=dp[i][j];
else if(dp[i+1][j].first==f)dp[i+1][j].second+=s;
if(dp[i+1][j+1].first<f+v[i])dp[i+1][j+1]=make_pair(f+v[i],s);
else if(dp[i+1][j+1].first==f+v[i])dp[i+1][j+1].second+=s;
}
}
}
double ma=0.0;
double num[n+1];
for(ll i=a;i<=b;i++){
num[i]=(dp[n][i].first)/(i*1.0);
ma=max(ma,num);
}
ll ans=0;
for(ll i=a;i<=b;i++){
if(num[i]==ma)ans+=dp[n][i].second;
}
cout<<ans<<endl;
} | a.cc: In function 'int main()':
a.cc:26:11: error: no matching function for call to 'max(double&, double [(n + 1)])'
26 | ma=max(ma,num);
| ~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:26:11: note: deduced conflicting types for parameter 'const _Tp' ('double' and 'double [(n + 1)]')
26 | ma=max(ma,num);
| ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:26:11: note: mismatched types 'std::initializer_list<_Tp>' and 'double'
26 | ma=max(ma,num);
| ~~~^~~~~~~~
|
s833400717 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,a,b;cin>>n>>a>>b;
ll v[n];for(ll i=0;i<n;i++)cin>>v[i];
pair<ll,ll>dp[n+1][n+1];
for(ll i=0;i<=n;i++)for(ll j=0;j<=n;j++)dp[i][j]=make_pair(-1,0);
for(ll i=0;i<=n;i++)dp[i][0]=make_pair(0,0);
for(ll i=0;i<n;i++){
for(ll j=0;j<n;j++){
ll f=dp[i][j].first;
ll s=dp[i][j].second;
if(f>=0){
if(dp[i+1][j].first<f)dp[i+1][j]=dp[i][j];
else if(dp[i+1][j].first==f)dp[i+1][j].second+=s;
if(dp[i+1][j+1].first<f+v[i])dp[i+1][j+1]=make_pair(f+a[i],s);
else if(dp[i+1][j+1].first==f+v[i])dp[i+1][j+1].second+=s;
}
}
}
double ma=0.0;
double num[n+1];
for(ll i=a;i<=b;i++){
num[i]=(dp[n][i].first)/(i*1.0);
ma=max(ma,num);
}
ll ans=0;
for(ll i=a;i<=b;i++){
if(num[i]==ma)ans+=dp[n][i].second;
}
cout<<ans<<endl;
} | a.cc: In function 'int main()':
a.cc:17:64: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
17 | if(dp[i+1][j+1].first<f+v[i])dp[i+1][j+1]=make_pair(f+a[i],s);
| ^
a.cc:26:11: error: no matching function for call to 'max(double&, double [(n + 1)])'
26 | ma=max(ma,num);
| ~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:26:11: note: deduced conflicting types for parameter 'const _Tp' ('double' and 'double [(n + 1)]')
26 | ma=max(ma,num);
| ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:26:11: note: mismatched types 'std::initializer_list<_Tp>' and 'double'
26 | ma=max(ma,num);
| ~~~^~~~~~~~
|
s930578322 | p03776 | C++ | #include <bits/stdc++.h>
using namespace std;
#define ll long long;
int calc(ll x){
int count = 0;
while(x>0){
x/=10;
count++;
}
return count;
}
int F(ll A,ll B){
return max(calc(A),calc(B));
}
int main(){
ll N;
cin>>N;
int min=1<<29;
for(ll i=1;i*i<=N;i++) {
if(N%i==0){
min=min(min,F(i, N/i));
}
}
cout<<min<<endl;
return 0;
}
| a.cc:3:21: error: expected ')' before ';' token
3 | #define ll long long;
| ^
a.cc:4:10: note: in expansion of macro 'll'
4 | int calc(ll x){
| ^~
a.cc:4:9: note: to match this '('
4 | int calc(ll x){
| ^
a.cc:4:13: error: 'x' does not name a type
4 | int calc(ll x){
| ^
a.cc:3:21: error: expected ')' before ';' token
3 | #define ll long long;
| ^
a.cc:12:7: note: in expansion of macro 'll'
12 | int F(ll A,ll B){
| ^~
a.cc:12:6: note: to match this '('
12 | int F(ll A,ll B){
| ^
a.cc:12:10: error: 'A' does not name a type
12 | int F(ll A,ll B){
| ^
a.cc:12:15: error: 'B' does not name a type
12 | int F(ll A,ll B){
| ^
a.cc: In function 'int main()':
a.cc:3:17: error: declaration does not declare anything [-fpermissive]
3 | #define ll long long;
| ^~~~
a.cc:16:3: note: in expansion of macro 'll'
16 | ll N;
| ^~
a.cc:16:6: error: 'N' was not declared in this scope
16 | ll N;
| ^
a.cc:3:17: error: declaration does not declare anything [-fpermissive]
3 | #define ll long long;
| ^~~~
a.cc:19:7: note: in expansion of macro 'll'
19 | for(ll i=1;i*i<=N;i++) {
| ^~
a.cc:19:10: error: 'i' was not declared in this scope
19 | for(ll i=1;i*i<=N;i++) {
| ^
a.cc:19:20: error: expected ')' before ';' token
19 | for(ll i=1;i*i<=N;i++) {
| ~ ^
| )
a.cc:19:21: error: 'i' was not declared in this scope
19 | for(ll i=1;i*i<=N;i++) {
| ^
|
s114048227 | p03776 | C++ | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n,a,b,t=0;
cin>>n>>a>>b;
vector<ll> c(n);
for(int i=0;i<n;i++){
cin>>c[i];
}
sort(c.begin(),c.end());
reverse(c.begin(),c.end());
for(int i=0;i<a;i++){
t+=c[i];
}
cout<<fixed;
cout<<seprecision(8)<<(double)t/(double)a<<endl;
} | a.cc: In function 'int main()':
a.cc:17:9: error: 'seprecision' was not declared in this scope
17 | cout<<seprecision(8)<<(double)t/(double)a<<endl;
| ^~~~~~~~~~~
|
s745940727 | p03776 | C++ | def inpl(): return [int(i) for i in input().split()]
N, A, B = inpl()
V = inpl()
V = list(reversed(sorted(V)))
x1 = N-1
x2 = 0
for i in range(N):
if V[i] == V[A]:
x1 = min(x1,i)
x2 = max(x2,i)
print(sum(V[0:A])/A)
from scipy.special import comb
ans = 0
if x1 == 0:
for l in range(min(B-1,x2)-A+2):
ans += comb(x2-x1+1,l-x1+1, exact=True)
print(ans)
else:
print(comb(x2-x1+1,A-x1+1, exact=True)) | a.cc:1:1: error: 'def' does not name a type
1 | def inpl(): return [int(i) for i in input().split()]
| ^~~
|
s400766029 | p03776 | C++ | #include "stdafx.h"
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
using namespace std;
int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };
ll gcd(ll x, ll y) {
ll m = max(x, y), n = min(x, y);
if (m%n == 0)return n;
else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
return x / gcd(x, y)*y;
}
ll myPow(ll x, ll n, ll m) {
if (n == 0)
return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
long long nCr(int n, int r) {
if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
long long ans = 1;
int i;
for (i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
const int MOD = 1000000007;
ll v[60];
int main() {
int N, A, B; cin >> N >> A >> B;
REP(i, N) {
cin >> v[i];
}
SORT(v, N); REVERSE(v, N);
double ave = 0;
REP(i, A) {
ave += v[i] / double(A);
}
cout <<setprecision(20)<< ave << endl;
bool equal = true;
int c = 0;
REP(i, A) {
if (v[i] != v[0]) {
equal = false;
c = i;
break;
}
}
int c2 = 0;
bool equal2=true;
if (equal) {
FOR(i, A, B) {
if (v[i] != v[0]) {
equal2 = false;
c2 = i;
break;
}
}
ll ans = 0;
if (equal2) {
FOR(i, A, B + 1) {
ans += nCr(B, i);
}
cout << ans << endl;
return 0;
}
else {
FOR(i, A, c2+1) {
ans += nCr(c2, i);
}
cout << ans << endl;
return 0;
}
}
else {
int cnt = 0;
int c3 = 0;
REP(i, N) {
if (v[i] == v[A - 1]) {
c3 = i;
break;
}
}
REP(i, N) {
if (v[i] == v[A - 1]) {
cnt++;
}
}
ll ans = 0;
ans = nCr(cnt, c3);
cout << ans << endl;
}
}
| a.cc:1:10: fatal error: stdafx.h: No such file or directory
1 | #include "stdafx.h"
| ^~~~~~~~~~
compilation terminated.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.