submission_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 3
values | code stringlengths 1 522k | compiler_output stringlengths 43 10.2k |
|---|---|---|---|---|
s004014053 | p03648 | C++ | k = input()
epoch = k / 50
tweak = 50 - k % 50
ans = [50 + epoch for _ in range(50)]
for i in range(50):
if i < tweak:
ans[i] += -50 + tweak - 1
else:
ans[i] += tweak
ans_st = " ".join(map(str, ans))
print 50
print ans_st
| a.cc:1:1: error: 'k' does not name a type
1 | k = input()
| ^
|
s074471037 | p03648 | C++ | #include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
using namespace std;
int i, j, k;
int main() {
_int64 k;
cin >> k;
_int64 a[50];
rep(i, 0, 50) {
a[i] = k / 50 + 50;
}
int b;
b = 50 - k % 50;
rep(i, 0, k % 50) {
a[i] += b;
}
rep(i, k%50, 50) {
a[i] = a[i] - 50 + b - 1;;
}
rep(i, 0, 50) {
cout << a[i];
if (i != 49)
cout << " ";
}
cout << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:21:9: error: '_int64' was not declared in this scope; did you mean 'sinf64'?
21 | _int64 k;
| ^~~~~~
| sinf64
a.cc:23:15: error: expected ';' before 'a'
23 | _int64 a[50];
| ^~
| ;
a.cc:25:17: error: 'a' was not declared in this scope
25 | a[i] = k / 50 + 50;
| ^
a.cc:30:17: error: 'a' was not declared in this scope
30 | a[i] += b;
| ^
a.cc:33:17: error: 'a' was not declared in this scope
33 | a[i] = a[i] - 50 + b - 1;;
| ^
a.cc:36:25: error: 'a' was not declared in this scope
36 | cout << a[i];
| ^
|
s342774927 | p03648 | C++ | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
int main() {
long long k;
cin >> k;
cout << 50 << endl;
imfor(i, 50) {
cout << i + (i + k) / 50 <<< " ";
}
return 0;
} | a.cc: In function 'int main()':
a.cc:21:36: error: expected primary-expression before '<' token
21 | cout << i + (i + k) / 50 <<< " ";
| ^
|
s228641627 | p03648 | C++ | using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
ll K;
ll a[50];
cin >> K;
ll t = (ll)(K/50);
cout << 50 << endl;
rep(i,50)
{
a[i] = i-K%50;
if(a[i]<0)
a[i]+=51;
cout << a[i]+t << " ";
}
cout << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:13:3: error: 'cin' was not declared in this scope
13 | cin >> K;
| ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
+++ |+#include <iostream>
1 | using namespace std;
a.cc:17:3: error: 'cout' was not declared in this scope
17 | cout << 50 << endl;
| ^~~~
a.cc:17:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:17:17: error: 'endl' was not declared in this scope
17 | cout << 50 << endl;
| ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
+++ |+#include <ostream>
1 | using namespace std;
|
s572765202 | p03648 | C++ | https://arc079.contest.atcoder.jp/submissions/me# | a.cc:1:1: error: 'https' does not name a type
1 | https://arc079.contest.atcoder.jp/submissions/me#
| ^~~~~
|
s597206666 | p03648 | C++ | https://arc079.contest.atcoder.jp/submissions/me# | a.cc:1:1: error: 'https' does not name a type
1 | https://arc079.contest.atcoder.jp/submissions/me#
| ^~~~~
|
s422913217 | p03648 | C++ | https://arc079.contest.atcoder.jp/submissions/me# | a.cc:1:1: error: 'https' does not name a type
1 | https://arc079.contest.atcoder.jp/submissions/me#
| ^~~~~
|
s296277545 | p03648 | C++ | https://arc079.contest.atcoder.jp/submissions/me# | a.cc:1:1: error: 'https' does not name a type
1 | https://arc079.contest.atcoder.jp/submissions/me#
| ^~~~~
|
s452746572 | p03648 | C++ | https://arc079.contest.atcoder.jp/submissions/me# | a.cc:1:1: error: 'https' does not name a type
1 | https://arc079.contest.atcoder.jp/submissions/me#
| ^~~~~
|
s631456140 | p03648 | C++ | #include <iostream>
#include <map>
using namespace std;
int main(){
long long N;
cin >> N;
1
cout << 2 << endl;
if( N % 2 == 0 ){
cout << N / 2 + 1 << " " << N / 2 + 1 << endl;
}else{
cout << N / 2 + 1 - 1 << " " << N / 2 + 1 + 2 << endl;
}
} | a.cc: In function 'int main()':
a.cc:8:10: error: expected ';' before 'cout'
8 | 1
| ^
| ;
9 |
10 | cout << 2 << endl;
| ~~~~
|
s100190982 | p03648 | C++ | #include<iostream>
using namespace std;
int main()
{
int K, N = 50, m, arr[N];
cin >> K;
for(int i=0; i<N; i++){
arr[i]=i;
}
for(int i=0; i<K; i++){
m=i%N;
arr[m] = arr[m]+N+1;
for(int j=0; j<N; j++){
arr[j] = arr[j]-1;
}
}
cout << N << "\n";
#include<iostream>
using namespace std;
int main()
{
int K, N = 50, m, arr[N];
cin >> K;
for(int i=0; i<N; i++){
arr[i]=i;
}
for(int i=0; i<K; i++){
m=i%N;
arr[m] = arr[m]+N+1;
for(int j=0; j<N; j++){
arr[j] = arr[j]-1;
}
}
cout << N << "\n";
cout << arr[0] << ' ' << arr[1] << ' ' << arr[2] << ' ' << arr[3] << ' ' << arr[4] << ' ' << arr[5] << ' ' << arr[6] << ' ' << arr[7] << ' ' << arr[8] << ' ' << arr[9] << ' ' << arr[10] << ' ' << arr[11] << ' ' << arr[12] << ' ' << arr[13] << ' ' << arr[14] << ' ' << arr[15] << ' ' << arr[16] << ' ' << arr[17] << ' ' << arr[18] << ' ' << arr[19] << ' ' << arr[20] << ' ' << arr[21] << ' ' << arr[22] << ' ' << arr[23] << ' ' << arr[24] << ' ' << arr[25] << ' ' << arr[26] << ' ' << arr[27] << ' ' << arr[28] << ' ' << arr[29] << ' ' << arr[30] << ' ' << arr[31] << ' ' << arr[32] << ' ' << arr[33] << ' ' << arr[34] << ' ' << arr[35] << ' ' << arr[36] << ' ' << arr[37] << ' ' << arr[38] << ' ' << arr[39] << ' ' << arr[40] << ' ' << arr[41] << ' ' << arr[42] << ' ' << arr[43] << ' ' << arr[44] << ' ' << arr[45] << ' ' << arr[46] << ' ' << arr[47] << ' ' << arr[48] << ' ' << arr[49] << endl;
return 0;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:21:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
21 | int main()
| ^~
a.cc:21:9: note: remove parentheses to default-initialize a variable
21 | int main()
| ^~
| --
a.cc:21:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:22:1: error: a function-definition is not allowed here before '{' token
22 | {
| ^
|
s298006830 | p03648 | C++ | #include <stdio.h>
#include <algorithm>
#include <math.h>
#include <conio.h>
int data[50];
int main()
{
long long int K;
scanf("%lld", &K);
if (K < 1)
{
printf("4\n3 3 3 3\n");
return 0;
}
else if (K == 1)
{
printf("3\n1 0 3\n");
}
else if (2 <= K && K <= 50)
{
printf("%lld\n%lld", K, K);
for (long long int a = 1; a < K; ++a)
{
printf(" %lld", K);
}
puts("");
}
else
{
for (int a = 0; a < 50; ++a)
{
data[((K % 50) + a) % 50] = K - a;
}
printf("%lld\n%lld", 50LL, data[0]);
for (int a = 1; a < 50; ++a)
{
printf(" %lld", data[a]);
}
puts("");
}
_getch();
return 0;
} | a.cc:4:10: fatal error: conio.h: No such file or directory
4 | #include <conio.h>
| ^~~~~~~~~
compilation terminated.
|
s135740125 | p03648 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
ll K;
ll q,c;
cin >> K;
cout << "50" << endl;
vector <ll> result(50,49);
q = K/50;
c = K%50;
for(ll i = 0;i<50;i++){a[i]+=q;};
for(ll i =0;i<c;i++){
for(ll j =0;j<50;j++){
a[j]--;
}
a[i]+=51;
}
for(i = 0;i<50;i++){
cout << a[i] << " ";
}
cout << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:21:26: error: 'a' was not declared in this scope
21 | for(ll i = 0;i<50;i++){a[i]+=q;};
| ^
a.cc:24:7: error: 'a' was not declared in this scope
24 | a[j]--;
| ^
a.cc:26:5: error: 'a' was not declared in this scope
26 | a[i]+=51;
| ^
a.cc:30:7: error: 'i' was not declared in this scope
30 | for(i = 0;i<50;i++){
| ^
a.cc:31:13: error: 'a' was not declared in this scope
31 | cout << a[i] << " ";
| ^
|
s814829236 | p03648 | Java |
import java.util.Scanner;
public class TaskD {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Long k=sc.nextLong();
int N=50;
System.out.println(N);
int b=(int) (N-1+k/N-k%N);
//System.out.println(b);
for (int i = 0; i <N; i++) {
System.out.print(b+ (i<k%N?N:0)+ (i==N-1 ? "\n" : " "));
}
}
}
| Main.java:4: error: class TaskD is public, should be declared in a file named TaskD.java
public class TaskD {
^
1 error
|
s379943736 | p03648 | C++ | // failed to generate code
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
//
// 1234567894848 * 10
// 1234567891011
// 1234567900000
// 3800/10 = 380
//
// 7 * 3 = 21
// 27
//
// K * N
//
// N - (N-1) * K
// 50 - 49
// 50*10^16 -
//
// 1000+193+256+777+0+1+1192+1234567891011+48+425
// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
istringstream is(s);
T res;
is >> res;
return res;
}
template <class T> string to_s(const T &a) {
ostringstream os;
os << a;
return os.str();
}
ull K;
ull MAX = 10e16 + 1000L;
bool solve(ll N) {
if (K == 0) {
cout << "2" << endl;
cout << "1 1" << endl;
return true;
} else if (K == 1) {
cout << "2" << endl;
cout << "3 0" << endl;
return true;
}
ll sum = K * N;
vll v(N, 0);
// dump(sum);
// ll buf = 0;
REP(i, N) { v[i] = i + 1; }
cout << N << endl;
REP(i, N) {
cout << v[i];
if (i != N - 1)
cout << " ";
}
cout << endl;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin >> K;
// K = 10e16 * 50;
// for (int i = 2; i <= 50; ++i)
// if (solve(i))
// return 0;
if (K > 50) {
REP(i, 1L << 60) REP(j, 1L << 60) { dump(i); }
return;
}
solve(K);
}
| a.cc: In function 'int main()':
a.cc:104:5: error: return-statement with no value, in function returning 'int' [-fpermissive]
104 | return;
| ^~~~~~
|
s249569461 | p03648 | C++ | #include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cmath>
using namespace std;
int main(){
long long int k;
cin>>k;
cout<<50<<endl;
int n=50;
vector<int> a(n);
long long int x=k/50;
for(int i=0;i<n;i++)a[i]=i+x;
while(1){
if(x==k)break;
//cout<<a[0]<<endl;
a[0]+=n;
for(int i=1;i<n;i++)a[i]--;
x++;
sort(a.begin(),a.end());
}
for(int i=0;i<n-1;i++)cout<<a[i]<<" ";
cout<<a[49]<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:23:5: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
23 | sort(a.begin(),a.end());
| ^~~~
| sqrt
|
s838103804 | p03648 | Java | import java.util.Scanner;
public class Main{
static final long MAX = 10_000_000_000_001_000L;
static long k;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
k = sc.nextLong();
long[] a = null;
for(int n = 2; n <= 50; n++){
long s = n * (n - 1) + k - ((k - 1) * n + (n + 1));
long r = s % (n - 1);
a = new long[n];
a[0] = (k - 1) * n + (n + 1);
a[1] = s / (n - 1) + r;
for(int i = 1; i < n; i++){
a[i] = s / (n - 1);
}
boolean ok = true;
for(int i = 0; i < n; i++){
if(a[i] < 0 || a[i] > MAX){
ok = false;
break;
}
}
if(ok){
break;
}
}
System.out.println(n);
for(int i = 0; i < a.length; i++){
System.out.print(a[i] + " ");
}
System.out.println();
}
} | Main.java:33: error: cannot find symbol
System.out.println(n);
^
symbol: variable n
location: class Main
1 error
|
s433394945 | p03648 | C++ | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define SZ(a) ((int)((a).size()))
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF ((int)1e9)
#define SYNC std::ios::sync_with_stdio(false); cin.tie(NULL);
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll k, a[55] = {};
#define A ((ll)1e16+1000)
int main() {
SYNC
FOR(n,2,51) {
ll done = 0;
FOR0(i, n - 1) {
a[i] = max(0LL, n-k-1);
done += (a[i] + k - n )/ (n + 1) + 1;
}
if(done <= k) {
a[i] = (k - done) - k - 1 + n;
}
if(a[i] <= A && a[i] >= 0)
cout << n << endl;
FOR0(i, n) cout << a[i ] << " ";
return 0;
}
} | a.cc: In function 'int main()':
a.cc:35:15: error: 'i' was not declared in this scope
35 | a[i] = (k - done) - k - 1 + n;
| ^
a.cc:37:14: error: 'i' was not declared in this scope
37 | if(a[i] <= A && a[i] >= 0)
| ^
|
s994266773 | p03648 | C++ | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define SZ(a) ((int)((a).size()))
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF ((int)1e9)
#define SYNC std::ios::sync_with_stdio(false); cin.tie(NULL);
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll k, a[55] = {};
#define A ((ll)1e16+1000)
int main() {
SYNC
FOR(n,2,51) {
ll done = 0;
FOR0(i, n - 1) {
a[i] = max(0LL, n-k-1);
done += (a[i] + k - n )/ (n + 1) + 1;
}
if(done <= k) {
a[i] = (k - done) - k - 1 + n;
}
if(a[i] <= A && a[i] >= 0)
cout << n << endl;
FOR0(i, n) cout << a[i ] << " ";
return 0;
}
} | a.cc: In function 'int main()':
a.cc:35:15: error: 'i' was not declared in this scope
35 | a[i] = (k - done) - k - 1 + n;
| ^
a.cc:37:14: error: 'i' was not declared in this scope
37 | if(a[i] <= A && a[i] >= 0)
| ^
|
s754482792 | p03648 | Java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long K = scanner.nextLong();
System.out.println("2");
if((K % 3) == 1) {
int n = K ;
int x = n / 2;
int y = K - x + 1;
System.out.printf("%d %d%n", x, y);
} else if((K % 3) == 2) {
int n = K + 1;
int x = n / 2;
int y = K - x;
System.out.printf("%d %d%n", x, y);
} else if((K % 3) == 0) {
int n = K;
int x = n / 2;
int y = K - x;
System.out.printf("%d %d%n", x, y);
}
}
} | Main.java:11: error: incompatible types: possible lossy conversion from long to int
int n = K ;
^
Main.java:13: error: incompatible types: possible lossy conversion from long to int
int y = K - x + 1;
^
Main.java:16: error: incompatible types: possible lossy conversion from long to int
int n = K + 1;
^
Main.java:18: error: incompatible types: possible lossy conversion from long to int
int y = K - x;
^
Main.java:21: error: incompatible types: possible lossy conversion from long to int
int n = K;
^
Main.java:23: error: incompatible types: possible lossy conversion from long to int
int y = K - x;
^
6 errors
|
s612121367 | p03648 | C++ | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef vector<vector<ll> > matrix;
const int mod = 1e9+7;
ll gcd(ll a,ll b){
if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
ll ans = 1;
while(pow!=0){
if(pow&1==1){ans = ans*base;ans = ans%mod;}
base *= base;base%=mod;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}
double pi = 3.141592653589793238462643;
double error = 0.0000001;
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1}; // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/* -------Template ends here-------- */
const int M = 100001;
int main(){
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
ll o_lo = 0 , o_hi = 1e16 + 1000;
ll to;
sll(to);
ll large = 1e16;
while(o_lo <= o_hi){
ll o_mid = (o_lo + o_hi)/2;
vector<ll> vec(50 , 0);
vector<ll> hh(50 , 0);
for(int i = 0 ; i < 20 ; i++){
vec[i] = o_mid;
hh[i] = o_mid;
}
ll ans = 0;
int n = hh.size();
while(1){
sort(vec.begin() , vec.end());
ll term = vec[n - 1];
if(term < n) break;
ll lo = 0 , hi = large;
ll here = 0;
while(lo <= hi){
ll mid = (lo + hi)/2;
ll mak = term - mid*(n);
if(mak >= n){
lo = mid + 1;
}
else{
here = mid;
hi = mid - 1;
}
}
// if(steps > 20) break;
vec[n - 1] -= (here*n);
for(int i = 0 ; i < n - 1 ; i++){
vec[i] += (here);
}
ans += here;
}
if(ans == to){
cout<<hh.size()<<endl;
for(int i = 0 ; i < hh.size() ; i++){
cout<<hh[i]<<" ";
}
return 0;
}
else if(ans > to){
o_hi = o_mid - 1;
}
else{
o_lo = o_mid + 1;
}
}
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef vector<vector<ll> > matrix;
const int mod = 1e9+7;
ll gcd(ll a,ll b){
if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
ll ans = 1;
while(pow!=0){
if(pow&1==1){ans = ans*base;ans = ans%mod;}
base *= base;base%=mod;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}
double pi = 3.141592653589793238462643;
double error = 0.0000001;
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1}; // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/* -------Template ends here-------- */
const int M = 100001;
int main(){
//freopen("input.txt", "rt", stdin);
//freopen("output.txt", "wt", stdout);
ll o_lo = 0 , o_hi = 1e16 + 1000;
ll to;
sll(to);
ll large = 1e16;
while(o_lo <= o_hi){
ll o_mid = (o_lo + o_hi)/2;
vector<ll> vec(50 , 0);
vector<ll> hh(50 , 0);
for(int i = 0 ; i < 10 ; i++){
vec[i] = o_mid;
hh[i] = o_mid;
}
for(int i = 10 ; i < 20 ; i++){
vec[i] = o_mid/2;
hh[i] = o_mid/2;
}
for(int i = 20 ; i < 30 ; i++){
vec[i] = o_mid/3;
hh[i] = o_mid/3;
}
for(int i = 30 ; i < 40 ; i++){
vec[i] = o_mid/4;
hh[i] = o_mid/4;
}
for(int i = 40 ; i < 50 ; i++){
vec[i] = o_mid/5;
hh[i] = o_mid/5;
}
ll ans = 0;
int n = hh.size();
while(1){
sort(vec.begin() , vec.end());
ll term = vec[n - 1];
if(term < n) break;
ll lo = 0 , hi = large;
ll here = 0;
while(lo <= hi){
ll mid = (lo + hi)/2;
ll mak = term - mid*(n);
if(mak >= n){
lo = mid + 1;
}
else{
here = mid;
hi = mid - 1;
}
}
// if(steps > 20) break;
vec[n - 1] -= (here*n);
for(int i = 0 ; i < n - 1 ; i++){
vec[i] += (here);
}
ans += here;
}
if(ans == to){
cout<<hh.size()<<endl;
for(int i = 0 ; i < hh.size() ; i++){
cout<<hh[i]<<" ";
}
return 0;
}
else if(ans > to){
o_hi = o_mid - 1;
}
else{
o_lo = o_mid + 1;
}
}
}
| a.cc:138:11: error: redefinition of 'const int mod'
138 | const int mod = 1e9+7;
| ^~~
a.cc:9:11: note: 'const int mod' previously defined here
9 | const int mod = 1e9+7;
| ^~~
a.cc:139:4: error: redefinition of 'long long int gcd(long long int, long long int)'
139 | ll gcd(ll a,ll b){
| ^~~
a.cc:10:4: note: 'long long int gcd(long long int, long long int)' previously defined here
10 | ll gcd(ll a,ll b){
| ^~~
a.cc:142:4: error: redefinition of 'long long int expo(long long int, long long int)'
142 | ll expo(ll base,ll pow){
| ^~~~
a.cc:13:4: note: 'long long int expo(long long int, long long int)' previously defined here
13 | ll expo(ll base,ll pow){
| ^~~~
a.cc:148:4: error: redefinition of 'long long int inv(long long int)'
148 | ll inv(ll x){return expo(x,mod-2);}
| ^~~
a.cc:19:4: note: 'long long int inv(long long int)' previously defined here
19 | ll inv(ll x){return expo(x,mod-2);}
| ^~~
a.cc:150:8: error: redefinition of 'double pi'
150 | double pi = 3.141592653589793238462643;
| ^~
a.cc:21:8: note: 'double pi' previously defined here
21 | double pi = 3.141592653589793238462643;
| ^~
a.cc:151:8: error: redefinition of 'double error'
151 | double error = 0.0000001;
| ^~~~~
a.cc:22:8: note: 'double error' previously defined here
22 | double error = 0.0000001;
| ^~~~~
a.cc:152:5: error: redefinition of 'int dx [8]'
152 | int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1}; // last 4 diagonal
| ^~
a.cc:23:5: note: 'int dx [8]' previously defined here
23 | int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1}; // last 4 diagonal
| ^~
a.cc:153:5: error: redefinition of 'int dy [8]'
153 | int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
| ^~
a.cc:24:5: note: 'int dy [8]' previously defined here
24 | int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
| ^~
a.cc:156:11: error: redefinition of 'const int M'
156 | const int M = 100001;
| ^
a.cc:27:11: note: 'const int M' previously defined here
27 | const int M = 100001;
| ^
a.cc:159:5: error: redefinition of 'int main()'
159 | int main(){
| ^~~~
a.cc:30:5: note: 'int main()' previously defined here
30 | int main(){
| ^~~~
|
s338729961 | p03648 | Java | //( ͡° ͜ʖ ͡°) °º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤º°` looking at my code...
#define ONLINE_JUDGE //in case i forget to uncomment this, sometimes the grader defines the macro ^.^
#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>
#else
#include "stdc++.h"
#endif
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define INF (int)1e9
#define int long long
using namespace std;
signed main() {
#ifndef ONLINE_JUDGE
freopen("/Users/kdkdk/Desktop/input.txt", "r", stdin);
//freopen("/Users/kdkdk/Desktop/output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int k; cin >> k;
int low = (k/50);
vector<int> arr(50,49+low);
cout << 50 << endl;
for(int i = 0; i < 50; ++i) {
if(i < k % 50) arr[i] = arr[i] + 50 - (k % 50)+1;
cout << arr[i] << " ";
}
return 0;
}
| Main.java:3: error: illegal character: '#'
#define ONLINE_JUDGE //in case i forget to uncomment this, sometimes the grader defines the macro ^.^
^
Main.java:4: error: illegal character: '#'
#ifdef ONLINE_JUDGE
^
Main.java:5: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:6: error: illegal character: '#'
#else
^
Main.java:7: error: illegal character: '#'
#include "stdc++.h"
^
Main.java:8: error: illegal character: '#'
#endif
^
Main.java:9: error: illegal character: '#'
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
^
Main.java:10: error: illegal character: '#'
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
^
Main.java:11: error: illegal character: '#'
#define INF (int)1e9
^
Main.java:13: error: illegal character: '#'
#define int long long
^
Main.java:17: error: illegal character: '#'
#ifndef ONLINE_JUDGE
^
Main.java:20: error: illegal character: '#'
#endif
^
Main.java:25: error: not a statement
int k; cin >> k;
^
Main.java:28: error: not a statement
vector<int> arr(50,49+low);
^
Main.java:29: error: not a statement
cout << 50 << endl;
^
Main.java:32: error: not a statement
cout << arr[i] << " ";
^
Main.java:16: error: unnamed classes are a preview feature and are disabled by default.
signed main() {
^
(use --enable-preview to enable unnamed classes)
Main.java:17: error: ';' expected
#ifndef ONLINE_JUDGE
^
Main.java:22: error: ';' expected
ios_base::sync_with_stdio(false);
^
Main.java:28: error: ';' expected
vector<int> arr(50,49+low);
^
Main.java:28: error: ';' expected
vector<int> arr(50,49+low);
^
21 errors
|
s748171254 | p03648 | Java | //( ͡° ͜ʖ ͡°) °º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤º°` looking at my code...
#define ONLINE_JUDGE //in case i forget to uncomment this, sometimes the grader defines the macro ^.^
#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>
#else
#include "stdc++.h"
#endif
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define INF (int)1e9
#define int long long
using namespace std;
signed main() {
#ifndef ONLINE_JUDGE
freopen("/Users/kdkdk/Desktop/input.txt", "r", stdin);
//freopen("/Users/kdkdk/Desktop/output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int k; cin >> k;
int low = (k/50);
vector<int> arr(50,49+low);
cout << 50 << endl;
for(int i = 0; i < 50; ++i) {
if(i < k % 50) arr[i] = arr[i] + 50 - (k % 50)+1;
cout << arr[i] << " ";
}
return 0;
}
| Main.java:3: error: illegal character: '#'
#define ONLINE_JUDGE //in case i forget to uncomment this, sometimes the grader defines the macro ^.^
^
Main.java:4: error: illegal character: '#'
#ifdef ONLINE_JUDGE
^
Main.java:5: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:6: error: illegal character: '#'
#else
^
Main.java:7: error: illegal character: '#'
#include "stdc++.h"
^
Main.java:8: error: illegal character: '#'
#endif
^
Main.java:9: error: illegal character: '#'
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
^
Main.java:10: error: illegal character: '#'
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
^
Main.java:11: error: illegal character: '#'
#define INF (int)1e9
^
Main.java:13: error: illegal character: '#'
#define int long long
^
Main.java:17: error: illegal character: '#'
#ifndef ONLINE_JUDGE
^
Main.java:20: error: illegal character: '#'
#endif
^
Main.java:25: error: not a statement
int k; cin >> k;
^
Main.java:28: error: not a statement
vector<int> arr(50,49+low);
^
Main.java:29: error: not a statement
cout << 50 << endl;
^
Main.java:32: error: not a statement
cout << arr[i] << " ";
^
Main.java:16: error: unnamed classes are a preview feature and are disabled by default.
signed main() {
^
(use --enable-preview to enable unnamed classes)
Main.java:17: error: ';' expected
#ifndef ONLINE_JUDGE
^
Main.java:22: error: ';' expected
ios_base::sync_with_stdio(false);
^
Main.java:28: error: ';' expected
vector<int> arr(50,49+low);
^
Main.java:28: error: ';' expected
vector<int> arr(50,49+low);
^
21 errors
|
s412600475 | p03648 | C++ | #include<iostream>
using namespace std;
typedef long long ll;
ll ceil(ll a, ll b){
return a / b + (a % b ? 1 : 0);
}
int main(){
ll k; cin >> k;
if(k == 0){
cout << 2 << endl;
cout << 0 << " " << 0 << endl;
}else if(k == 1){
cout << 2 << endl;
cout << 0 << " " << 2 << endl;
}else if(k == 2){
cout << 2 << endl;
cout << 2 << " " << 2 << endl;
}else if(k == 3){
cout << 2 << endl;
cout << 1 << " " << 3 << endl;
}else if(k == 4){
cout << 2 << endl;
cout << 0 << " " << 6 << endl;
}else if(k == 5){
cout << 2 << endl;
cout << 2 << " " << 4 << endl;
}else if(k > (20000000000000000 + 1000) * 2){
cout << 5 << endl;
for(int i = 0; i < 5; ++i){
cout << (5 - 1 + k) / 5 + (i < (4 + k) % 5 ? 1 : 0) << " ";
}
cout << endl;
}else{
/*for(ll i = 2; i <= 50; ++i){
if(ceil(i - 1 + k, i) >= i * i){
cout << i << endl;
for(ll j = 0; j < i; ++j){
cout << (i - 1 + k) / i + (j < (i - 1 + k) % i ? 1 : 0) << " ";
}
cout << endl;
return 0;
}
}*/
if(k % 2){
cout << 2 << endl;
cout << k / 2 + 1 << " " << k / 2 << endl;
}else{
cout << 2 << endl;
cout << k / 2 + 1 << " " << k / 2 + 1 << endl;
}
} | a.cc: In function 'int main()':
a.cc:53:2: error: expected '}' at end of input
53 | }
| ^
a.cc:9:11: note: to match this '{'
9 | int main(){
| ^
|
s433171587 | p03648 | C++ | #include <bits/stdc++.h>
const int N = 55;
long long k;
void init() {
std::cin >> k;
}
void work() {
static long long answer[N];
long long n = 50;
for (int i = 1; i <= n; i++) {
answer[i] = n - 1 + k / n;
}
answer[1] += n * (k % n);
for (int i = 2; i <= n; i++) {
answer[i] -= k % n;
}
std::cout << n << std::endl;
for (int i = 1; i <= n; i++) {
printf("%lld%c", answer[i], " \n"[i == n]);
}
}
int main() {
freopen("d.i
init();
work();
return 0;
}
| a.cc:30:17: warning: missing terminating " character
30 | freopen("d.i
| ^
a.cc:30:17: error: missing terminating " character
30 | freopen("d.i
| ^~~~
a.cc: In function 'int main()':
a.cc:31:15: error: expected ')' before ';' token
31 | init();
| ^
| )
a.cc:30:16: note: to match this '('
30 | freopen("d.i
| ^
|
s971903929 | p03648 | C++ | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2017/07/29 Problem: ARC 079 B / Link: http://arc079.contest.atcoder.jp/tasks/arc079_b ----- */
/* ------問題------
-----問題ここまで----- */
/* -----解説等-----
----解説ここまで---- */
ll N;
ll ans = 0LL;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
ll K;
cin >> K;
if (K == -1)break;
N = 50;
ll lef = K%N;
ll div = K / N;
assert(lef + div*N == K);
cout << N << endl;
FOR(i, 0, N) {
ans = div;
if (i <lef)ans +=1;
ll sita = ans*(N + 1) - K;
ll ue = ans*(N + 1) - K + N;
ll x = sita;
ll shi = 1;// ue - sita;
while (shi * 2 < ue - sita)shi *= 2; shi *= 2;
while (1) {
if (shi == 0)break;
if (x + shi < ue/*&&(x+shi<=(1e16+1000))*/) {
x += shi;
}
shi /= 2;
}
assert(x >= 0 && x <= (1e16 + 1000));
cout << x << " ";
}
cout << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:41:29: error: break statement not within loop or switch
41 | if (K == -1)break;
| ^~~~~
|
s145931198 | p03648 | C++ | #include<bits/stdc++.h>
#define int long long
using namespace std;
main(){
int n;
cin>>n;
cout<<50<<endl;
for(i=0;i<49;i++){
if(50*n>1e16){
cout<<1e16<<' ';
n-=2*1e14;
}
}
for(;i<49;i++)cout<<0<<' ';
cout<<endl;
}
| a.cc:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
4 | main(){
| ^~~~
a.cc: In function 'int main()':
a.cc:8:7: error: 'i' was not declared in this scope
8 | for(i=0;i<49;i++){
| ^
a.cc:14:8: error: 'i' was not declared in this scope
14 | for(;i<49;i++)cout<<0<<' ';
| ^
|
s574828226 | p03648 | Java | import java.math.BigInteger;
import java.util.*;
public class ZZZZ {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String k = s.next();
BigInteger b = new BigInteger(k);
BigInteger TWO = new BigInteger("2");
BigInteger THREE = new BigInteger("3");
BigInteger HALF = b.divide(TWO);
if(b.mod(TWO).equals(BigInteger.ZERO)) System.out.println(HALF.add(BigInteger.ONE)+ " " + HALF.add(BigInteger.ONE));
else System.out.println(HALF.add(THREE) + " " + HALF);
}
}
| Main.java:4: error: class ZZZZ is public, should be declared in a file named ZZZZ.java
public class ZZZZ {
^
1 error
|
s912519803 | p03648 | C++ | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
int main()
{
ll K; cin >> K;
ll N = min(K, 50);
cout << N << endl;
ll nokori = K - K / N;
FOR(i,1,N+1) {
if(i <= nokori) cout << K / N + 2 * N - 1<< " ";
else cout << K / N + N - 1 - nokori << " ";
}
cout << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:22:13: error: no matching function for call to 'min(ll&, int)'
22 | ll N = min(K, 50);
| ~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
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:22:13: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
22 | ll N = min(K, 50);
| ~~~^~~~~~~
/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:22:13: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
22 | ll N = min(K, 50);
| ~~~^~~~~~~
|
s501965387 | p03648 | C++ | #include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
int main(){
long long k;
cin>>k;
if(k==0){
cout<<2<<endl;
cout<<1<<' '<<1<<endl;
}
else{
cout<<50<<endl;
long long a=k/50;
long long r=k%50;
for(int i=1;i<=50;i++){
if(i<=r) cout<<50+a<<' ';
else cout<<49+a<<' ';
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:18:9: error: 'cin' was not declared in this scope
18 | cin>>k;
| ^~~
a.cc:14:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
13 | #include <cstdio>
+++ |+#include <iostream>
14 | using namespace std;
a.cc:20:17: error: 'cout' was not declared in this scope
20 | cout<<2<<endl;
| ^~~~
a.cc:20:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:20:26: error: 'endl' was not declared in this scope
20 | cout<<2<<endl;
| ^~~~
a.cc:14:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
13 | #include <cstdio>
+++ |+#include <ostream>
14 | using namespace std;
a.cc:24:17: error: 'cout' was not declared in this scope
24 | cout<<50<<endl;
| ^~~~
a.cc:24:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:24:27: error: 'endl' was not declared in this scope
24 | cout<<50<<endl;
| ^~~~
a.cc:24:27: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
|
s791137697 | p03648 | Java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long K = sc.nextLong();
if(K == 0) {
System.out.println(2);
System.out.println(0 + " " + 0);
} else if(K == 1) {
System.out.println(2);
System.out.println(0 + " " + 2);
} else if(K == 2) {
System.out.println(2);
System.out.println(2 + " " + 2);
} else {
long d = 0;
for(long i = 0; i < (long)Math.pow(10, 8); i++) {
if(K % i == 0) {
d = (long)i;
break;
}
}
System.out.println(d);
long s = K / d;
for(int i = 0; i < d; i++) {
System.out.print(N - 1 + s);
if(i < d - 1) System.out.print(" ");
}
System.out.println();
}
}
} | Main.java:27: error: cannot find symbol
System.out.print(N - 1 + s);
^
symbol: variable N
location: class Main
1 error
|
s409733764 | p03648 | C++ | #include <bits/stdc++.h>
#include "example.h"
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)
long long k;
class Solution {
public:
void solve(std::istream& in, std::ostream& out)
{
in >> k;
out << 2 << "\n";
out << 1 << k << "\n";
}
};
void solve(std::istream& in, std::ostream& out)
{
out << std::setprecision(12);
Solution solution;
solution.solve(in, out);
}
| a.cc:2:10: fatal error: example.h: No such file or directory
2 | #include "example.h"
| ^~~~~~~~~~~
compilation terminated.
|
s246475618 | p03648 | C++ | #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
#define mk make_pair
using namespace std;
int main(){
long long n;
cin>>n;
c out<<1000000000000000000<<endl;
r(i,1000000000000000000-1)printf("0 ");
cout<<n+1000000000000000000<<endl;
} | a.cc: In function 'int main()':
a.cc:10:3: error: 'c' was not declared in this scope
10 | c out<<1000000000000000000<<endl;
| ^
|
s925485083 | p03649 | Java | // copied
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
typedef long long ll;
ll ans,a[60];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
cin>>a[i];
}
ll* p;
while(*(p=max_element(a+1,a+n+1)) >= (ll)n){
for(int i=1;i<=n;++i){
if(a+i!=p){
a[i]+=(*p)/(ll)n;
}
}
ans+=(*p)/(ll)n;
(*p)%=(ll)n;
}
cout<<ans<<endl;
return 0;
}
| Main.java:2: error: illegal character: '#'
#include<cstdio>
^
Main.java:3: error: illegal character: '#'
#include<iostream>
^
Main.java:4: error: illegal character: '#'
#include<algorithm>
^
Main.java:6: error: unnamed classes are a preview feature and are disabled by default.
int n;
^
(use --enable-preview to enable unnamed classes)
Main.java:7: error: class, interface, enum, or record expected
typedef long long ll;
^
Main.java:8: error: class, interface, enum, or record expected
ll ans,a[60];
^
Main.java:12: error: not a statement
cin>>a[i];
^
Main.java:14: error: not a statement
ll* p;
^
Main.java:24: error: not a statement
cout<<ans<<endl;
^
Main.java:10: error: illegal start of expression
scanf("%d",&n);
^
Main.java:15: error: illegal start of expression
while(*(p=max_element(a+1,a+n+1)) >= (ll)n){
^
Main.java:18: error: illegal start of expression
a[i]+=(*p)/(ll)n;
^
Main.java:21: error: illegal start of expression
ans+=(*p)/(ll)n;
^
Main.java:22: error: illegal start of expression
(*p)%=(ll)n;
^
14 errors
|
s372643637 | p03649 | C++ | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const int INF = 1e9 + 7;
int N;
ll A[51];
void solve() {
cin>>N;
rep(i,N) cin>>A[i];
ll ret=0;
rep(x,1000000) {
rep(i,N) if(A[i]>=N) {
ll del=A[i]/N;
ret += del;
A[i] -= del*N;
rep(j,N) if(i!=j) A[j] += del;
}
}
cout<<ret<<endl;
} | /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
|
s809097554 | p03649 | C++ | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a) (a).begin(),(a).end()
#define elif else if
int low(V<int> &a,int b){
auto c=lower_bound(a.begin(),a.end(),b);
int d=c-a.bgn;
return d;
}
int upp(V<int> &a,int b){
auto c=upper_bound(a.begin(),a.end(),b);
int d=c-a.bgn;
return d;
}
template<class T>
void cou(vector<vector<T>> a){
int b=a.size();
int c=a[0].size();
fo(i,b){
fo(j,c){
cout<<a[i][j];
if(j==c-1)
cout<<endl;
else
cout<<' ';
}
}
}
int wari(int a,int b) {
if(a%b==0)
return a/b;
else
return a/b+1;
}
int keta(int a){
double b=a;
b=log10(b);
int c=b;
return c+1;
}
int souwa(int a){
return a*(a+1)/2;
}
int gcm(int a,int b){
if(a%b==0)
return b;
return gcm(b,a%b);
}
bool prime(int a){
if(a<2)
return false;
else if(a==2)
return true;
else if(a%2==0)
return false;
for(int i=3;i<=sqrt(a)+1;i+=2){
if (a%i==0)
return false;
}
return true;
}
struct Union{
vector<int> par;
Union(int a){
par=vector<int>(a,-1);
}
int find(int a){
if(par[a]<0)
return a;
else
return par[a]=find(par[a]);
}
bool same(int a,int b){
return find(a)==find(b);
}
int Size(int a){
return -par[find(a)];
}
void unite(int a,int b){
a=find(a);
b=find(b);
if(a==b)
return;
if(Size(b)>Size(a))
swap<int>(a,b);
par[a]+=par[b];
par[b]=a;
}
};
int ketas(int a){
string b=to_string(a);
int c=0;
fo(i,keta(a)){
c+=b[i]-'0';
}
return c;
}
bool fe(int a,int b){
a%=10;
b%=10;
if(a==0)
a=10;
if(b==0)
b=10;
if(a>b)
return true;
else
return false;
}
int INF=1000000007;
struct edge{int s,t,d; };
V<int> mojisyu(string a){
V<int> b(26,0);
fo(i,a.sz){
b[a[i]-'a']++;
}
return b;
}
int wa2(int a){
if(a%2==1)
return a/2;
return a/2-1;
}
/*signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}
?*/
int nCr(int n,int r){
int a=1;
r=min(r,n-r);
for(int i=n;i>n-r;i--){
a*=i;
a/=n-i+1;
}
return a;
}
/*void sea(int x,int y){
if(x<0||a<=x||y<0||b<=y||c[x][y]=='#')
return;
if(d[x][y])
return;
d[x][y]++;
sea(x+1,y);
sea(x-1,y);
sea(x,y+1);
sea(x,y-1);
}*/
int kaijou(int a){
int b=1;
fo(i,a)
b*=i+1;
return b;
}
int nPr(int a,int b){
if(a<b)
return 0;
if(b==0)
return 1;
int c=1;
for(int i=a;i>a-b;i--){
c*=i;
c%=INF;
}
return c;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
return modpow(a, mod - 2, mod);
}
int lcm(int a,int b){
int c=modinv(gcm(a,b),INF);
return ((a*c)%INF)*(b%INF)%INF;
}
int MOD=INF;
int fac[1000010], finv[1000010], inv[1000010];
// テーブルを作る前処理
//先にCOMinit()で前処理をする
//ABC145D
void COMinit() {
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for(int i=2;i<1000010;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;
}
}
// 二項係数計算
int 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;
}
bool naka(int a,int b,V<V<char>> c){
return (a>=0&&b>=0&&a<c.sz&&b<c[0].sz);
}
V<P<int,int>> mawari8={{0,-1},{0,1},{1,0},{-1,0},{-1,-1},{1,1},{1,-1},{-1,-1}};
int inf=1000000000000000007;
V<P<int,int>> mawari4={{0,-1},{0,1},{1,0},{-1,0}};
//最短経路の表 a(全部INFで初期化)
//縦横 x,y
//迷路 f
//スタートsx,sy
//ゴールgx,gy
//文字はgから使おうね
/*int bfs_haba(){
Q<P<int,int>> b;
a[sx][sy]=0;
b.push({sx,sy});
while(!b.empty()){
P<int,int> c=b.front();
b.pop();
if(c.fi==gx&&c.se==gy){
break;
}
fo(i,4){
int d=c.fi+mawari4[i].fi;
int e=c.se+mawari4[i].se;
if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){
b.push({d,e});
a[d][e]=1+a[c.fi][c.se];
}
}
}
return a[gx][gy];
}*/
V<int> onajibubun(string a){
V<int> b(a.sz);
for(int i=1,j=0;i<a.sz;i++){
if(i+b[i-j]<j+b[j])
b[i]=b[i-j];
else{
int c=max<int>(0,j+b[j]-i);
while(i+c<a.sz&&a[c]==a[i+c])
c++;
b[i]=c;
j=i;
}
}
b[0]=a.sz;
return b;
}
//各頂点ごとにどこに辺が出てるかの表がc
//各頂点ごとの色を表すV<int>(頂点数max)のcolorを用意する
//aはどこ塗るか、bは何で塗るかなので、(0,1,c)でよぶとおけ
V<int> color(200005);
bool nibu_hantei(int a,int b,V<V<int>> c){
color[a]=b;
fo(i,c[a].sz){
if(b==color[c[a][i]])
return false;
if(color[c[a][i]]==0&&!nibu_hantei(c[a][i],-b,c))
return false;
}
return true;
}
//aは頂点数
//nibu_hanteiの上にcolorを用意する
//各頂点ごとにどこに辺が出てるかの表がc
bool renketujanai_nibu_hantei(int a,V<V<int>> c){
fo(i,a){
if(color[i]==0){
if(!nibu_hantei(i,1,c))
return false;
}
}
return true;
}
struct segmin{
vector<int> seg;
int b;
segmin(V<int> a){
b=1;
while(b<a.sz)
b*=2;
seg=vector<int>(2*b-1,inf);
fo(i,a.sz){
seg[i+b-1]=a[i];
}
for(int i=b-2;i>=0;i--){
seg[i]=min(seg[2*i+1],seg[2*i+2]);
}
}
void update(int i,int a){
i+=b-1;
seg[i]=a;
while(i){
i=(i-1)/2;
seg[i]=min(seg[2*i+1],seg[2*i+2]);
}
}
//最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで
//l,rは探すところ
int getmin(int x,int y,int a,int l,int r){
if(r==INF)
r=b;
if(r<=x||y<=l)
return INF;
if(x<=l&&r<=y)
return seg[a];
int a1=getmin(x,y,2*a+1,l,(l+r)/2);
int a2=getmin(x,y,2*a+2,(l+r)/2,r);
return min(a1,a2);
}
};
struct segadd{
vector<int> seg;
int b;
segadd(V<int> a){
b=1;
while(b<a.sz)
b*=2;
seg=vector<int>(2*b-1,0);
fo(i,a.sz){
seg[i+b-1]=a[i];
}
for(int i=b-2;i>=0;i--){
seg[i]=seg[2*i+1]+seg[2*i+2];
}
}
void update(int i,int a){
i+=b-1;
seg[i]=a;
while(i){
i=(i-1)/2;
seg[i]=seg[2*i+1]+seg[2*i+2];
}
}
//最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで
//l,rは探すところ
int getadd(int x,int y,int a,int l,int r){
if(r==INF)
r=b;
if(r<=x||y<=l)
return 0;
if(x<=l&&r<=y)
return seg[a];
int a1=getadd(x,y,2*a+1,l,(l+r)/2);
int a2=getadd(x,y,2*a+2,(l+r)/2,r);
return a1+a2;
}
};
struct sege{
vector<P<int,V<int>>> seg;
int b;
sege(string a){
b=1;
while(b<a.sz)
b*=2;
seg=vector<P<int,V<int>>>(2*b-1);
fo(i,a.sz){
seg[i+b-1].fi=1;
seg[i+b-1].se.pb(a[i]-'a');
}
for(int i=b-2;i>=0;i--){
V<int> d=seg[2*i+1].se;
fo(j,seg[2*i+2].se.sz){
d.pb(seg[2*i+2].se[j]);
}
Sort(d);
uni(d);
seg[i].se=d;
seg[i].fi=d.sz;
}
}
V<int> mu;
void update(int i,char a){
i+=b-1;
seg[i].se=mu;
seg[i].se.pb(a-'a');
seg[i].fi=1;
while(i){
i=(i-1)/2;
V<int> d=seg[2*i+1].se;
fo(j,seg[2*i+2].se.sz){
d.pb(seg[2*i+2].se[j]);
}
Sort(d);
uni(d);
seg[i].se=d;
seg[i].fi=d.sz;
}
}
void unko(){
fo(i,2*b-1)
cout<<seg[i].fi<<' ';
}
//最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで
//l,rは探すところ
P<int,V<int>> gete(int x,int y,int a,int l,int r){
if(r==INF)
r=b;
if(r<=x||y<=l)
return {0,mu};
if(x<=l&&r<=y)
return seg[a];
P<int,V<int>> a1=gete(x,y,2*a+1,l,(l+r)/2);
P<int,V<int>> a2=gete(x,y,2*a+2,(l+r)/2,r);
fo(i,a2.se.sz)
a1.se.pb(a2.se[i]);
Sort(a1.se);
uni(a1.se);
return {a1.se.sz,a1.se};
}
};/*
signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}*/
//aのb乗mod c
int kurikaesijijou(int a,int b,int c){
a%=c;
b%=c;
if(b==0)
return 1;
if(b%2==0){
int d=kurikaesijijou(a,b/2,c);
d%=c;
return d*d%c;
}
return a*kurikaesijijou(a,b-1,c)%c;
}
int waINF(int a){
if(a>=0)
return a%INF;
return (a+INF*INF)%INF;
}
signed main(){
int a;
cin>>a;
V<int> b(a);
fo(i,a)
cin>>b[i];
int l=0,r=inf;
int c;
while(r-l>1){
int d=(l+r)/2;
int f=0;
fo(i,a){
int e=b[i]-a+1;
e+=d;
f+=max<int>(0,(e+a)/(1+a));
}
// cout<<l<<' '<<r<<' '<<f<<endl;
if(f<=d)
r=d;
else
l=d;
}
int g=r;
fo(j,a+1){
int f=0;
fo(i,a){
int e=b[i]-a+1;
e+=j;
f+=max<int>(0,(e+a)/(1+a));
}
// cout<<l<<' '<<r<<' '<<f<<endl;
if(f<=j){
r=min(r,j);
break;
}
}
for(int j=g;j>=max<int>(0,r-a-5),j--){
int f=0;
fo(i,a){
int e=b[i]-a+1;
e+=j;
f+=max<int>(0,(e+a)/(1+a));
}
// cout<<l<<' '<<r<<' '<<f<<endl;
if(f<=j){
r=min(r,j);
}
}
cout<<r<<endl;
} | a.cc: In function 'int main()':
a.cc:563:39: error: expected ';' before ')' token
563 | for(int j=g;j>=max<int>(0,r-a-5),j--){
| ^
| ;
|
s439887050 | p03649 | C++ | #include <bits/stdc++.h>
using namespace std;
const int N=55;
int n;
long long arr[N],cur[N];
bool can(long long x)
{
for(int i=0;i<n;i++)
{
cur[i]=arr[i]+x;
}
long long ans=0;
for(int i=0;i<n;i++)
{
long long dif=cur[i]-(n-1);
ans+=(dif+n)/(n+1);
}
return ans<=x;
}
int main()
{
cin >> n;
for(int i=0;i<n;i++)
{
cin >> arr[i];
}
long long st=0,en=(1LL<<60),ans=(1LL<<60);
while(st<=en)
{
long long mid=st+(en-st)/2;
if(can(mid))
{
ans=mid; en=mid-1;
}
else st=mid+1;
}
for(long long curr=max(ans-1e5,0LL);curr<=ans;curr++)
{
if(can(curr))
{
ans=curr;
break;
}
}
cout << ans << endl;
} | a.cc: In function 'int main()':
a.cc:42:31: error: no matching function for call to 'max(double, long long int)'
42 | for(long long curr=max(ans-1e5,0LL);curr<=ans;curr++)
| ~~~^~~~~~~~~~~~~
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:42:31: note: deduced conflicting types for parameter 'const _Tp' ('double' and 'long long int')
42 | for(long long curr=max(ans-1e5,0LL);curr<=ans;curr++)
| ~~~^~~~~~~~~~~~~
/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:42:31: note: mismatched types 'std::initializer_list<_Tp>' and 'double'
42 | for(long long curr=max(ans-1e5,0LL);curr<=ans;curr++)
| ~~~^~~~~~~~~~~~~
|
s801001152 | p03649 | C++ | #include <bits/stdc++.h>
using namespace std;
long long INF = 100000000000000000;
int main(){
int N;
cin >> N;
vector<long long> a(N);
for (int i = 0; i < N; i++){
cin >> a[i];
}
long long tv = -100;
long long fv = INF;
while (fv - tv > 1){
long long mid = (tv + fv) / 2;
vector<long long> b(N);
for (int i = 0; i < N; i++){
b[i] = a[i] + mid;
}
long long cnt = 0;
for (int i = 0; i < N; i++){
cnt += b[i] / (N + 1) - 1;
}
if (cnt >= mid){
tv = mid;
} else {
fv = mid;
}
}
long long ans = tv;
long long curr = tv;
while (1){
vector<long long> b(N);
for (int i = 0; i < N; i++){
b[i] = a[i] + curr;
}
long long cnt = 0;
for (int i = 0; i < N; i++){
cnt += b[i] / (N + 1);
}
ans = curr - 1;
if (cnt < curr && currr > 0 || curr == tv + 1000000){
break;
}
curr++;
}
cout << ans << endl;
} | a.cc: In function 'int main()':
a.cc:41:23: error: 'currr' was not declared in this scope; did you mean 'curr'?
41 | if (cnt < curr && currr > 0 || curr == tv + 1000000){
| ^~~~~
| curr
|
s536640846 | p03649 | C++ | #include <iostream>
#include <array>
using namespace std;
typedef long long ll;
#define FOR(i,n) for (int i = 0; i < n; i++)
int N;
array<ll, 51> A;
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>A[i];
ll ret=0;
FOR(x,1000000) {
FOR(i,N) if(A[i]>=N) {
ll del=A[i]/N;
ret += del;
A[i] -= del*N;
FOR(j,N) if(i!=j) A[j] += del;
}
}
cout<<ret<<endl;
}
| /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
|
s540038878 | p03649 | C++ | #include <iostream>
using namespace std;
typedef long long ll;
#define FOR(i,n) for (int i = 0; i < n; i++)
int N;
ll A[51];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>A[i];
ll ret=0;
FOR(x,1000000) {
FOR(i,N) if(A[i]>=N) {
ll del=A[i]/N;
ret += del;
A[i] -= del*N;
FOR(j,N) if(i!=j) A[j] += del;
}
}
cout<<ret<<endl;
}
| /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
|
s243330055 | p03649 | C++ | #include <iostream>
using namespace std;
typedef long long ll;
#define FOR(i,n) for (int i = 0; i < n; i++)
int N;
ll A[51];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>A[i];
ll ret=0;
FOR(x,1000000) {
FOR(i,N) if(A[i]>=N) {
ll del=A[i]/N;
ret += del;
A[i] -= del*N;
FOR(j,N) if(i!=j) A[j] += del;
}
}
cout<<ret<<endl;
}
| /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
|
s341891795 | p03649 | C++ | #include <iostream>
using namespace std;
typedef long long ll;
int N;
ll A[51];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>A[i];
ll ret=0;
FOR(x,1000000) {
FOR(i,N) if(A[i]>=N) {
ll del=A[i]/N;
ret += del;
A[i] -= del*N;
FOR(j,N) if(i!=j) A[j] += del;
}
}
cout<<ret<<endl;
}
| a.cc: In function 'void solve()':
a.cc:11:5: error: 'FOR' was not declared in this scope
11 | FOR(i,N) cin>>A[i];
| ^~~
|
s947796491 | p03649 | C++ | #include <iostream>
typedef long long ll;
int N;
ll A[51];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>A[i];
ll ret=0;
FOR(x,1000000) {
FOR(i,N) if(A[i]>=N) {
ll del=A[i]/N;
ret += del;
A[i] -= del*N;
FOR(j,N) if(i!=j) A[j] += del;
}
}
cout<<ret<<endl;
} | a.cc: In function 'void solve()':
a.cc:7:24: error: 'string' was not declared in this scope
7 | int i,j,k,l,r,x,y; string s;
| ^~~~~~
a.cc:7:24: note: suggested alternatives:
In file included from /usr/include/c++/14/iosfwd:41,
from /usr/include/c++/14/ios:40,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/stringfwd.h:77:33: note: 'std::string'
77 | typedef basic_string<char> string;
| ^~~~~~
In file included 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:
/usr/include/c++/14/string:76:11: note: 'std::pmr::string'
76 | using string = basic_string<char>;
| ^~~~~~
a.cc:9:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
9 | cin>>N;
| ^~~
| std::cin
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
62 | extern istream cin; ///< Linked to standard input
| ^~~
a.cc:10:5: error: 'FOR' was not declared in this scope
10 | FOR(i,N) cin>>A[i];
| ^~~
a.cc:21:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
21 | cout<<ret<<endl;
| ^~~~
| std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
63 | extern ostream cout; ///< Linked to standard output
| ^~~~
a.cc:21:16: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
21 | cout<<ret<<endl;
| ^~~~
| std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
744 | endl(basic_ostream<_CharT, _Traits>& __os)
| ^~~~
|
s911973010 | p03649 | C++ | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> a;
int n;
bool isok(ll m) {
ll cnt = 0;
for (int i = 0; i < n && cnt <= m; i++) {
ll t = a[i] + m - (n - 1);
ll d = n+1;
cnt += (t+d-1) / d;
}
return cnt <= m;
}
int main() {
cin >> n;
a.resize(n);
for (int i = 0; i < n; i++) cin >> a[i];
ll ng = -1;
ll ok = 1e18;
while (ok - ng > 1) {
ll mid = (ok+ng) / 2;
(isok(mid) ? ok : ng) = mid;
}
for (int i = 0; i <= n; i++) {
if (isok(i)) {
ok = i; break;
}
}
else cout << ok << endl;
} | a.cc: In function 'int main()':
a.cc:32:3: error: 'else' without a previous 'if'
32 | else cout << ok << endl;
| ^~~~
|
s565899291 | p03649 | C++ | #include <bits/stdc++.h>
using namespace std;
usibg ll = long long;
vector<ll> a;
int n;
bool isok(ll m) {
ll cnt = 0;
for (int i = 0; i < n && cnt <= m; i++) {
ll t = a[i] + m - (n - 1);
ll d = n+1;
cnt += (t+d-1) / d;
}
return cnt <= m;
}
int main() {
cin >> n;
a.resize(n);
for (int i = 0; i < n; i++) cin >> a[i];
ll ng = -1;
ll ok = 1e18;
while (ok - ng > 1) {
ll mid = (ok+ng) / 2;
(isok(mid) ? ok : ng) = mid;
}
cout << ok << endl;
} | a.cc:3:1: error: 'usibg' does not name a type
3 | usibg ll = long long;
| ^~~~~
a.cc:4:8: error: 'll' was not declared in this scope
4 | vector<ll> a;
| ^~
a.cc:4:10: error: template argument 1 is invalid
4 | vector<ll> a;
| ^
a.cc:4:10: error: template argument 2 is invalid
a.cc:7:11: error: 'll' was not declared in this scope
7 | bool isok(ll m) {
| ^~
a.cc: In function 'int main()':
a.cc:19:5: error: request for member 'resize' in 'a', which is of non-class type 'int'
19 | a.resize(n);
| ^~~~~~
a.cc:20:39: error: invalid types 'int[int]' for array subscript
20 | for (int i = 0; i < n; i++) cin >> a[i];
| ^
a.cc:21:3: error: 'll' was not declared in this scope
21 | ll ng = -1;
| ^~
a.cc:22:5: error: expected ';' before 'ok'
22 | ll ok = 1e18;
| ^~~
| ;
a.cc:23:10: error: 'ok' was not declared in this scope
23 | while (ok - ng > 1) {
| ^~
a.cc:23:15: error: 'ng' was not declared in this scope; did you mean 'n'?
23 | while (ok - ng > 1) {
| ^~
| n
a.cc:24:7: error: expected ';' before 'mid'
24 | ll mid = (ok+ng) / 2;
| ^~~~
| ;
a.cc:25:11: error: 'mid' was not declared in this scope
25 | (isok(mid) ? ok : ng) = mid;
| ^~~
a.cc:25:14: error: 'isok' cannot be used as a function
25 | (isok(mid) ? ok : ng) = mid;
| ^
a.cc:27:11: error: 'ok' was not declared in this scope
27 | cout << ok << endl;
| ^~
|
s729046156 | p03649 | C++ | #include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long
template <class T>
struct DelaySegmentTree{
using F = function<T(T,T)>;
F f;
T inf;
int n;
vector<int> node,delay_val,delay_add;
vector<bool> delayflag;
DelaySegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){
n = 1; while(n < v.size()) n *= 2;
node.resize(2*n-1,inf);
delay_val.resize(2*n-1,inf);
delay_add.resize(2*n-1,0);
delayflag.resize(2*n-1,false);
for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
}
void eval(int k,int l,int r){
if(delayflag[k]){
node[k] = delay_val[k];
if(r-l > 1){
delay_val[2*k+1] = delay_val[2*k+2] = delay_val[k];
delayflag[2*k+1] = delayflag[2*k+2] = true;
}
delayflag[k] = false;
}
if(delay_add[k] != 0){
node[k] += delay_add[k];
if(r-l > 1){
delay_add[2*k+1] += delay_add[k] / 2;
delay_add[2*k+2] += delay_add[k] / 2;
}
delay_add[k] = 0;
}
}
void update(int a,int b,T x){ update(a,b,x,0,0,n); }
void update(int a,int b,T x,int k,int l,int r){
eval(k,l,r);
if(b <= l || r <= a) return;
if(a <= l && r <= b){
delay_val[k] = x;
delayflag[k] = true;
eval(k,l,r);
}
else {
update(a,b,x,2*k+1,l,(l+r)/2);
update(a,b,x,2*k+2,(l+r)/2,r);
node[k] = f(node[2*k+1],node[2*k+2]);
}
}
void add(int a,int b,T x){ add(a,b,x,0,0,n); }
void add(int a,int b,T x,int k,int l,int r){
eval(k,l,r);
if(b <= l || r <= a) return;
if(a <= l && r <= b){
delay_add[k] += x * (r - l);
eval(k,l,r);
}
else {
add(a,b,x,2*k+1,l,(l+r)/2);
add(a,b,x,2*k+2,(l+r)/2,r);
node[k] = f(node[2*k+1],node[2*k+2]);
}
}
T getval(int a,int b){ return getval(a,b,0,0,n); }
T getval(int a,int b,int k,int l,int r){
//区間[a, b)の値を返す
eval(k,l,r);
if(b <= l || r <= a) return inf;
if(a <= l && r <= b) return node[k];
T vl = getval(a, b, 2*k+1, l, (l+r)/2);
T vr = getval(a, b, 2*k+2, (l+r)/2, r);
return f(vl, vr);
}
};
signed main(){
int n; cin >> n;
vector<pair<int,int>> a(n);
for(int i = 0; i < n; i++){
cin >> a[i].first;
a[i].second = i;
}
using P = pair<int,int>;
const P INF = {1LL<<60,1LL<<60};
DelaySegmentTree<P> seg(a,INF,[&](P x,P y){
return max(x, y);
});
int ans = 0;
while(1){
auto p = seg.getval(0, n);
int val = p.first;
if(val < n) break;
ans += val / n;
seg.update(p.second, p.second+1, {val - val/n * n, i});
seg.add(0, p.second, val / n); //pairのaddどうすんの
seg.add(p.second+1, n, val / n);
}
cout << ans << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:110:56: error: 'i' was not declared in this scope
110 | seg.update(p.second, p.second+1, {val - val/n * n, i});
| ^
a.cc:110:15: error: no matching function for call to 'DelaySegmentTree<std::pair<long long int, long long int> >::update(long long int&, long long int, <brace-enclosed initializer list>)'
110 | seg.update(p.second, p.second+1, {val - val/n * n, i});
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:46:8: note: candidate: 'void DelaySegmentTree<T>::update(long long int, long long int, T) [with T = std::pair<long long int, long long int>]'
46 | void update(int a,int b,T x){ update(a,b,x,0,0,n); }
| ^~~~~~
a.cc:46:29: note: no known conversion for argument 3 from '<brace-enclosed initializer list>' to 'std::pair<long long int, long long int>'
46 | void update(int a,int b,T x){ update(a,b,x,0,0,n); }
| ~~^
a.cc:47:8: note: candidate: 'void DelaySegmentTree<T>::update(long long int, long long int, T, long long int, long long int, long long int) [with T = std::pair<long long int, long long int>]'
47 | void update(int a,int b,T x,int k,int l,int r){
| ^~~~~~
a.cc:47:8: note: candidate expects 6 arguments, 3 provided
a.cc:111:12: error: no matching function for call to 'DelaySegmentTree<std::pair<long long int, long long int> >::add(int, long long int&, long long int)'
111 | seg.add(0, p.second, val / n); //pairのaddどうすんの
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:62:8: note: candidate: 'void DelaySegmentTree<T>::add(long long int, long long int, T) [with T = std::pair<long long int, long long int>]'
62 | void add(int a,int b,T x){ add(a,b,x,0,0,n); }
| ^~~
a.cc:62:26: note: no known conversion for argument 3 from 'long long int' to 'std::pair<long long int, long long int>'
62 | void add(int a,int b,T x){ add(a,b,x,0,0,n); }
| ~~^
a.cc:63:8: note: candidate: 'void DelaySegmentTree<T>::add(long long int, long long int, T, long long int, long long int, long long int) [with T = std::pair<long long int, long long int>]'
63 | void add(int a,int b,T x,int k,int l,int r){
| ^~~
a.cc:63:8: note: candidate expects 6 arguments, 3 provided
a.cc:112:12: error: no matching function for call to 'DelaySegmentTree<std::pair<long long int, long long int> >::add(long long int, long long int&, long long int)'
112 | seg.add(p.second+1, n, val / n);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:62:8: note: candidate: 'void DelaySegmentTree<T>::add(long long int, long long int, T) [with T = std::pair<long long int, long long int>]'
62 | void add(int a,int b,T x){ add(a,b,x,0,0,n); }
| ^~~
a.cc:62:26: note: no known conversion for argument 3 from 'long long int' to 'std::pair<long long int, long long int>'
62 | void add(int a,int b,T x){ add(a,b,x,0,0,n); }
| ~~^
a.cc:63:8: note: candidate: 'void DelaySegmentTree<T>::add(long long int, long long int, T, long long int, long long int, long long int) [with T = std::pair<long long int, long long int>]'
63 | void add(int a,int b,T x,int k,int l,int r){
| ^~~
a.cc:63:8: note: candidate expects 6 arguments, 3 provided
a.cc: In instantiation of 'DelaySegmentTree<T>::DelaySegmentTree(std::vector<_Tp>, T, F) [with T = std::pair<long long int, long long int>; F = std::function<std::pair<long long int, long long int>(std::pair<long long int, long long int>, std::pair<long long int, long long int>)>]':
a.cc:102:4: required from here
102 | });
| ^
a.cc:19:16: error: no matching function for call to 'std::vector<long long int>::resize(long long int, std::pair<long long int, long long int>&)'
19 | node.resize(2*n-1,inf);
| ~~~~~~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
from /usr/include/c++/14/functional:64,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1013:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; size_type = long unsigned int]'
1013 | resize(size_type __new_size)
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1013:7: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1034:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(size_type, const value_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; size_type = long unsigned int; value_type = long long int]'
1034 | resize(size_type __new_size, const value_type& __x)
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1034:54: note: no known conversion for argument 2 from 'std::pair<long long int, long long int>' to 'const std::vector<long long int>::value_type&' {aka 'const long long int&'}
1034 | resize(size_type __new_size, const value_type& __x)
| ~~~~~~~~~~~~~~~~~~^~~
a.cc:20:21: error: no matching function for call to 'std::vector<long long int>::resize(long long int, std::pair<long long int, long long int>&)'
20 | delay_val.resize(2*n-1,inf);
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1013:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; size_type = long unsigned int]'
1013 | resize(size_type __new_size)
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1013:7: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1034:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(size_type, const value_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; size_type = long unsigned int; value_type = long long int]'
1034 | resize(size_type __new_size, const value_type& __x)
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1034:54: note: no known conversion for argument 2 from 'std::pair<long long int, long long int>' to 'const std::vector<long long int>::value_type&' {aka 'const long long int&'}
1034 | resize(size_type __new_size, const value_type& __x)
| ~~~~~~~~~~~~~~~~~~^~~
a.cc:23:51: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} to '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} in assignment
23 | for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
a.cc:24:46: error: no match for call to '(DelaySegmentTree<std::pair<long long int, long long int> >::F {aka std::function<std::pair<long long int, long long int>(std::pair<long long int, long long int>, std::pair<long long int, long long int>)>}) (__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
24 | for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
| ~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/functional:59:
/usr/include/c++/14/bits/std_function.h:587:7: note: candidate: '_Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = std::pair<long long int, long long int>; _ArgTypes = {std::pair<long long int, long long int>, std::pair<long long int, long long int>}]'
587 | operator()(_ArgTypes... __args) const
| ^~~~~~~~
/usr/include/c++/14/bits/std_function.h:587:27: note: no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'std::pair<long long int, long long int>'
587 | operator()(_ArgTypes... __args) const
| ~~~~~~~~~^~~~~~~~~~
a.cc: In instantiation of 'T DelaySegmentTree<T>::getval(long long int, long long int, long long int, long long int, long long int) [with T = std::pair<long long int, long long int>]':
a.cc:77:39: required from 'T DelaySegmentTree<T>::getval(long long int, long long int) [with T = std::pair<long long int, long long int>]'
77 | T getval(int a,int b){ return getval(a,b,0,0,n); }
| ~~~~~~^~~~~~~~~~~
a.cc:106:24: required from here
106 | auto p = seg.getval(0, n);
| ~~~~~~~~~~^~~~~~
a.cc:82:39: error: could not convert '((DelaySegmentTree<std::pair<long long int, long long int> >*)this)->DelaySegmentTree<std::pair<long long int, long long int> >::node.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)k))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'std::pair<long long int, long long int>'
82 | if(a <= l && r <= b) return node[k];
| ^
| |
| __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}
|
s098909643 | p03649 | C++ | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long
signed main(){
int N;cin>>N;
std::vector<int> v(N);
for(int i=0;i<N;i++)cin>>v[i];
sort(v.begin(),v.end());
int ans=0;
while(v[N-1]>N-1){
int k=0;
for(int i=0;i<N;i++){
int a=max((v[i]-(N-1)-1)/N+1,0);
k+=a;v[i]-=a*(N+1);
}
for(int i=0;i<N;i++)v[i]+=k;
ans+=k;
sort(v.begin(),v.end());
}
cout<<ans<<endl;
}
| a.cc: In function 'int main()':
a.cc:18:16: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
18 | int a=max((v[i]-(N-1)-1)/N+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~~
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:18:16: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
18 | int a=max((v[i]-(N-1)-1)/N+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~~
/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:18:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
18 | int a=max((v[i]-(N-1)-1)/N+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~~
|
s312161221 | p03649 | C++ | #include<iostream>
#include<stdint>
using namespace std;
const int MAX = 50;
const int64_t INF = 4611686018427387903; // 10^62-1、使わない辺とかに用いる
bool check(int64_t x, int64_t *a, int N) {
for (int i = 0;i < N;i ++) {
int64_t operate = 0;
for (int j = 0;j < N;j ++) {
operate += (a[j] + x - i + 1) / (N + 1);
}
if (operate <= x - i) return false;
}
return true;
}
int64_t binarySearch(int64_t l, int64_t r, int64_t *a, int N) {
int64_t mid;
for (mid = r >> 1;r - l > 1;mid = l + (r - l >> 1)) {
if (check(mid, a, N)) l = mid;
else r = mid;
}
return mid;
}
int main() {
int N;
int64_t a[MAX];
cin >> N;
for (int i = 0;i < N;i ++) cin >> a[i];
int64_t ans = binarySearch(0, INF, a, N);
if (check(ans, a, N)) ans ++;
cout << ans;
return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー
操作回数をX回と決め打ちます
この時、ある数aに対して行わなければならない操作回数は(a+X-N+1)/(N+1)の端数切り上げです
ということは、O(N^2)でX回以内にできるか分かります
よって後はXを二分探索すれば良いです、O(N^2log(max(a)))
*/ | a.cc:2:9: fatal error: stdint: No such file or directory
2 | #include<stdint>
| ^~~~~~~~
compilation terminated.
|
s774038304 | p03649 | C++ | #include <iostream>
#include <vector>
using namespace std;
int main(){
long long int N;
cin >> N;
vector<long long int> A(N);
for(int i = 0; i < N; ++i) cin >> A[i];
if(*max_element(A.begin(), A.end()) < N){
cout << 0 << endl;
return 0;
}
long long int ng = 0, ok = 1e18;
while(ok - ng > 1){
long long int m = (ok + ng)/2, t = 0;
for(int i = 0; i < N; ++i){
t += (A[i] + m)/(N+1);
//if((A[i] + m)%(N+1) == N) --t;
}
if(t < m) ok = m;
else ng = m;
}
cout << ng << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:10:7: error: 'max_element' was not declared in this scope
10 | if(*max_element(A.begin(), A.end()) < N){
| ^~~~~~~~~~~
|
s866218817 | p03649 | C | #include<cstdio>
#include<algorithm>
using namespace std;
using LL = long long;
LL N, M, S;
LL A[50];
inline LL ceil(LL d, LL n) {return (d+n-1)/n;}
inline bool ok(LL x) {
if(M < S-x) return false;
LL s = 0;
for(auto i=0; i<N; ++i) s += max(0ll, ceil(A[i]+x+1-N, N+1));
return s <= x;
}
int main() {
scanf("%lld", &N);
M=N*(N-1);
for(auto i=0; i<N; ++i) scanf("%lld", A+i), S+=A[i];
LL l = -1, h = 1e18;
while(l+1 < h) {
LL m = (l+h)>>1;
if(ok(m)) h = m;
else l = m;
}
for(auto x=max(0ll,h-N*N); x<=h; ++x) if(ok(x)) {
printf("%lld\n",x);
break;
}
} | main.c:1:9: fatal error: cstdio: No such file or directory
1 | #include<cstdio>
| ^~~~~~~~
compilation terminated.
|
s462368989 | p03649 | C++ | #include<iostream>
#include<vector>
#include<math.h>
#include<map>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define INF int(1e9)
#define N 50
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
typedef pair<int, int> P;
typedef pair<pair<P, P>, P>PP;
typedef long long LL;
LL n, sum;
LL a[N];
vector<LL> sm, bi;
bool judge()
{
REP(i, n)
if (a[i] > n - 1)
return false;
return true;
}
void solve(LL ans)
{
LL sum = 0, s;
REP(i, n)
{
s = a[i] / n;
sum += s;
a[i] %= n;
a[i] -= s;
}
REP(i, n)
{
a[i] += sum;
}
judge() ? printf("%lld\n", ans + sum) : solve(ans + sum);
}
int main()
{
cin >> n;
REP(i, n)
cin >> a[i];
sort(a, a + n);
judge() ? printf("0\n") : solve(0);
return 0;
} | a.cc: In function 'void solve(LL)':
a.cc:42:25: error: third operand to the conditional operator is of type 'void', but the second operand is neither a throw-expression nor of type 'void'
42 | judge() ? printf("%lld\n", ans + sum) : solve(ans + sum);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:50:25: error: third operand to the conditional operator is of type 'void', but the second operand is neither a throw-expression nor of type 'void'
50 | judge() ? printf("0\n") : solve(0);
| ~~~~~~^~~~~~~
|
s848530901 | p03649 | C++ | use std::ops::{Index, IndexMut};
use std::cmp::{Ordering};
use std::collections::BinaryHeap;
use std::cmp::{min, max};
// use std::clone::Clone;
fn getline() -> String{
let mut res = String::new();
std::io::stdin().read_line(&mut res).ok();
res
}
macro_rules! split {
($x: expr) => {
($x).trim().split(' ').collect()
}
}
macro_rules! parse {
($x: expr) => {
($x).parse().unwrap()
}
}
macro_rules! debug {
($x: expr) => {
println!("{}: {}", stringify!($x), $x)
}
}
fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
for (i,e) in v.into_iter().enumerate() {
if i != 0 {
print!(" ");
}
print!("{}", e);
}
println!();
}
fn main() {
let s = getline();
let iv: Vec<_> = split!(s);
let n: i64 = parse!(iv[0]);
let s = getline();
let iv: Vec<_> = split!(s);
let a: Vec<i64> = iv.into_iter().map(|x| parse!(x)).collect();
let mut f = true;
for e in &a {
if *e >= n {
f = false;
break;
}
}
if f {
println!("{}",0);
return;
}
let mut l: i64 = 0;
let mut r: i64 = 1e16 as i64;
let check = |x: i64| {
let mut res = false;
for i in 0..n*2 {
let m = x+i;
let sum: i64 = a.clone().into_iter().map(|x| max((x-(n-1-m)+n)/(n+1),0)).sum();
res = res || sum <= m;
}
res
};
while r-l > 1 {
let m = (l+r)/2;
let sum: i64 = a.clone().into_iter().map(|x| max((x-(n-1-m)+n)/(n+1),0)).sum();
// debug!(l); debug!(r); debug!(m); debug!(sum);
if !check(m) {
l = m;
} else {
r = m;
}
}
// for m in 0..20 {
// let sum: i64 = a.clone().into_iter().map(|x| max((x-(n-1-m)+n)/(n+1),0)).sum();
// debug!(m); debug!(sum <= m);
// }
let mut ans = -100;
for i in 0..n*2 {
let m = r+i;
let sum: i64 = a.clone().into_iter().map(|x| max((x-(n-1-m)+n)/(n+1),0)).sum();
if sum <= m {
ans = r+i;
break;
}
}
println!("{}",ans);
}
| a.cc:66:18: error: too many decimal points in number
66 | for i in 0..n*2 {
| ^~~~
a.cc:89:14: error: too many decimal points in number
89 | for i in 0..n*2 {
| ^~~~
a.cc:1:1: error: 'use' does not name a type
1 | use std::ops::{Index, IndexMut};
| ^~~
a.cc:2:1: error: 'use' does not name a type
2 | use std::cmp::{Ordering};
| ^~~
a.cc:3:1: error: 'use' does not name a type
3 | use std::collections::BinaryHeap;
| ^~~
a.cc:4:1: error: 'use' does not name a type
4 | use std::cmp::{min, max};
| ^~~
a.cc:7:1: error: 'fn' does not name a type
7 | fn getline() -> String{
| ^~
a.cc:13:1: error: 'macro_rules' does not name a type
13 | macro_rules! split {
| ^~~~~~~~~~~
a.cc:19:1: error: 'macro_rules' does not name a type
19 | macro_rules! parse {
| ^~~~~~~~~~~
a.cc:25:1: error: 'macro_rules' does not name a type
25 | macro_rules! debug {
| ^~~~~~~~~~~
a.cc:31:1: error: 'fn' does not name a type
31 | fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
| ^~
a.cc:41:1: error: 'fn' does not name a type
41 | fn main() {
| ^~
|
s661614554 | p03649 | C++ | #include <iostream>
using namespace sdt;
int main() {
long long n, tmp, res = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tmp;
res += tmp / n;
}
cout << res << endl;
}
| a.cc:2:17: error: 'sdt' is not a namespace-name
2 | using namespace sdt;
| ^~~
a.cc: In function 'int main()':
a.cc:6:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
6 | cin >> n;
| ^~~
| 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:11:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
11 | cout << res << endl;
| ^~~~
| std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
63 | extern ostream cout; ///< Linked to standard output
| ^~~~
a.cc:11:20: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
11 | cout << res << endl;
| ^~~~
| std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
744 | endl(basic_ostream<_CharT, _Traits>& __os)
| ^~~~
|
s291036888 | p03649 | C++ |
use std::io;
use std::collections::VecDeque;
fn main() {
let stdin = io::stdin();
let mut buf = String::new();
stdin
.read_line(&mut buf)
.expect("ERROR Can't read array size");
let n:usize = buf.trim().parse().unwrap();
let mut buf = String::new();
stdin
.read_line(&mut buf)
.expect("ERROR Can't read array size");
let mut a: Vec<i64> = buf.split_whitespace()
.map(|n| n.parse().unwrap())
.collect();
let mut ans = 0i64;
let mut flag = true;
while flag {
flag = false;
for i in 0..n {
let x = a[i] / (n as i64);
if x > 0 {
for j in 0..n {
if j!=i {
a[j] += x;
}
}
ans += x;
a[i] = a[i] % (n as i64);
flag = true;
}
}
}
println!("{}", ans);
}
| a.cc:25:18: error: too many decimal points in number
25 | for i in 0..n {
| ^~~~
a.cc:28:26: error: too many decimal points in number
28 | for j in 0..n {
| ^~~~
a.cc:2:1: error: 'use' does not name a type
2 | use std::io;
| ^~~
a.cc:3:1: error: 'use' does not name a type
3 | use std::collections::VecDeque;
| ^~~
a.cc:5:1: error: 'fn' does not name a type
5 | fn main() {
| ^~
|
s894202989 | p03649 | C++ | #include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<utility>
#ifdef XS
#include<De>
#endif
using namespace std;
#define MS(m) memset(m,0,sizeof(m))
typedef unsigned U;
typedef pair<int,int > P;
typedef long long ll;
void inp();
int main(){
#ifdef XS
//freopen(".in","r",stdin);
#endif
//while(1)
//int n;scanf("%d",&n);for(int i=1;i<=n;i++)
inp();
return 0;
}
const int N = 51;
void inp(){
ll n,sum,A[N];cin>>n;
for(int i = 1;i<=n;i++)cin>>A[i];
ll k = 0;
while(1){
sum = 0;
for(int i = 1;i<=n;i++)sum += A[i]/n;
if(!sum)break;
k += sum;
for(int i = 1;i<=n;i++){
A[i] = sum - A[i]/n + A[i]%n;
}
}
cout<<k<<endl;
}
/ | a.cc:41:1: error: expected unqualified-id before '/' token
41 | /
| ^
|
s060728883 | p03649 | C++ | #include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<utility>
#ifdef XS
#include<De>
#endif
using namespace std;
#define MS(m) memset(m,0,sizeof(m))
typedef unsigned U;
typedef pair<int,int > P;
typedef long long ll;
void inp();
int main(){
#ifdef XS
//freopen(".in","r",stdin);
#endif
//while(1)
//int n;scanf("%d",&n);for(int i=1;i<=n;i++)
inp();
return 0;
}
const int N = 51;
void inp(){
ll n,sum,A[N];cin>>n;
for(int i = 1;i<=n;i++)cin>>A[i];
ll k = 0;
while(1){
sum = 0;
for(int i = 1;i<=n;i++)sum += A[i]/n;
if(!sum)break;
k += sum;
for(int i = 1;i<=n;i++){
A[i] = sum - A[i]/n + A[i]%n;
}
}
cout<<k<<endl;
}
/ | a.cc:41:1: error: expected unqualified-id before '/' token
41 | /
| ^
|
s819866174 | p03649 | C++ | #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
#ifdef XS
#include<De>
#endif
using namespace std;
#define MS(m) memset(m,0,sizeof(m))
typedef unsigned U;
typedef pair<int,int > P;
typedef long long ll;
void inp();
int main(){
#ifdef XS
//freopen(".in","r",stdin);
#endif
//while(1)
//int n;scanf("%d",&n);for(int i=1;i<=n;i++)
inp();
return 0;
}
const int N = 51;
void inp(){
ll n,sum,A[N];cin>>n;
for(int i = 1;i<=n;i++)cin>>A[i];
ll k = 0;
while(1){
sum = 0;
for(int i = 1;i<=n;i++)sum += A[i]/n;
if(!sum)break;
k += sum;
for(int i = 1;i<=n;i++){
A[i] += sum - A[i]/n;
}
}
cout<<sum<<endl;
}
//at79E.cc by xsthunder at Sun Jul 30 16:12:38 2017
| a.cc: In function 'void inp()':
a.cc:26:23: error: 'cin' was not declared in this scope
26 | ll n,sum,A[N];cin>>n;
| ^~~
a.cc:5:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
4 | #include<utility>
+++ |+#include <iostream>
5 | #ifdef XS
a.cc:38:9: error: 'cout' was not declared in this scope
38 | cout<<sum<<endl;
| ^~~~
a.cc:38:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:38:20: error: 'endl' was not declared in this scope
38 | cout<<sum<<endl;
| ^~~~
a.cc:5:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
4 | #include<utility>
+++ |+#include <ostream>
5 | #ifdef XS
|
s115373428 | p03649 | C++ | #include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>
#include <unordered_map>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define VS vector<string>
#define VI vector<ll>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
#define pcc pair<char,char>
#define pic pair<ll,char>
#define pci pair<char,ll>
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)
namespace {
struct input_returnner {
ll N; input_returnner(ll N_ = 0) :N(N_) {}
template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
template<typename T> operator T() const { T res; cin >> res; return res; }
template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
};
template<typename T> input_returnner in() { return in<T>(); }
input_returnner in() { return input_returnner(); }
input_returnner in(ll N) { return std::move(input_returnner(N)); }
}
const ll MOD = 1e9 + 7;
struct ModInt {
ll v = 0;
ModInt() {}
template<class T> ModInt(const T& right) {
v = right;
if (v >= 0) v %= MOD;
else v += ((-v) / MOD + 1)*MOD;
v %= MOD;
}
void operator = (const ModInt& right) { v = right.v; }
template<class T> void operator = (const T& right) {
v = right;
if (v >= 0) v %= MOD;
else v = v += ((-v) / MOD + 1)*MOD;
v %= MOD;
}
ModInt operator + (const ModInt& right) { return (v + right.v) % MOD; }
ModInt operator - (const ModInt& right) { return (MOD - (v - right.v)); }
ModInt operator * (const ModInt& right) { return (v * right.v) % MOD; }
ModInt operator / (const ModInt& right) { return v / right.v; }
void operator += (const ModInt& right) { v = (v + right.v) % MOD; }
void operator -= (const ModInt& right) { v = (MOD - (v - right.v)); }
void operator *= (const ModInt& right) { v = (v* right.v) % MOD; }
void operator /= (const ModInt& right) { v = v / right.v; }
bool operator == (const ModInt& right) { return v == right.v; }
};
ostream& operator << (ostream& os, const ModInt& value) {
os << value.v;
return os;
}
string YN[] = { "NO", "YES" };
int gcd ( int a, int b )
{
if ( a==0 ) return b;
return gcd ( b%a, a );
}
void solve();
/// ---template---
#define int ll
signed main(void) {
SETUP;
solve();
#ifdef _DEBUG
#endif
return 0;
}
pair<int, bool> f(vector<int>& A) {
vector<int> cnt(A.size());
int N = A.size();
int cntSum = 0;
REP(i, A.size()) {
cnt[i] = A[i] / N;
cntSum += cnt[i];
A[i] -= N * cnt[i];
}
bool res = true;
REP(i, A.size()) {
A[i] += cntSum - cnt[i];
if (A[i] >= A.size()) res = false;
}
return { cntSum, res };
}
void solve() {
int N; cin >> N;
vector<int> A(N); for (auto &a: A) cin >> a;
int sum = 0;
while (true) {
auto& a = f(A);
sum += a.first;
if (a.second) break;
}
cout << sum << endl;
} | a.cc: In function 'void solve()':
a.cc:155:28: error: cannot bind non-const lvalue reference of type 'std::pair<long long int, bool>&' to an rvalue of type 'std::pair<long long int, bool>'
155 | auto& a = f(A);
| ~^~~
|
s998893122 | p03649 | C++ | //
// main.cpp
// D
//
// Created by Vadim Zakharenko on 29/07/2017.
// Copyright © 2017 Vadim Zakharenko. All rights reserved.
//
#include <iostream>
#include <memory.h>
using namespace std;
long long a[111];
int n;
int main(int argc, const char * argv[]) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
long long ans = 0;
for(;;) {
long long iter = 0;
for (int i = 1; i <= n; i++) {
iter += a[i] / n;
}
ans += iter;
for (int i = 1; i <= n; i++) {
long long old_a = a[i];
a[i] %= n;
a[i] += iter - old_a / n;
}
if (*max_element(a + 1, a + n + 1) < n) {
break;
}
}
cout << ans << "\n";
return 0;
}
| a.cc: In function 'int main(int, const char**)':
a.cc:34:14: error: 'max_element' was not declared in this scope
34 | if (*max_element(a + 1, a + n + 1) < n) {
| ^~~~~~~~~~~
|
s281475323 | p03649 | C++ | #include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cmath>
using namespace std;
int main(){
long long int n;
cin>>n;
long long int bsum=0;
long long int ssum=0;
vector<long long int> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a.begin(),a.end());
while(a[n-1]>n-1){
//cout<<a[n-1]<<endl;
for(int i=0;i<n;i++){
if(a[i]>(n-1)){
long long int wl=a[i]/(n-1);
bsum+=wl;
a[i]=wl;
}
}
for(int i=0;i<n;i++){
a[i]+=a[i];
a[i]-=bsum;
}
sort(a.begin(),a.end());
ssum=bsum;
bsum=0;
}
cout<<ssum<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:18:3: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
18 | sort(a.begin(),a.end());
| ^~~~
| sqrt
|
s000658723 | p03649 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;
#define clr(a,i) memset((a), (i) ,sizeof(a))
int main(){
int n;
std::cin >> n;
std::vector<long long> a(n);
rep(i,n){
std::cin >> a[i];
}
sort(all(a));
reverse(all(a));
ans=0;
bool b=false;
while(!b){
long long tmp =0,tmp2;
rep(i,a.size()){
ans+=a[i]/n;
tmp+=a[i]/n;
}
rep(i,a.size()){
tmp2=a[i]
a[i]=tmp2%n;
a[i]+=tmp-tmp2/n;
}
b=true;
rep(i,a.size()){
if(a[i]>n-1) b=false;
}
}
std::cout << ans << std::endl;
} | a.cc: In function 'int main()':
a.cc:37:3: error: 'ans' was not declared in this scope; did you mean 'abs'?
37 | ans=0;
| ^~~
| abs
a.cc:46:16: error: expected ';' before 'a'
46 | tmp2=a[i]
| ^
| ;
47 | a[i]=tmp2%n;
| ~
|
s007385802 | p03649 | Java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long N = sc.nextLong();
long[] a = new long[N];
long max = 0;
long sum = 0;
for(int i = 0; i < (int)N; i++) {
a[i] = sc.nextLong();
max = Math.max(max, a[i]);
sum += a[i];
}
if(max < N) {
System.out.println(0);
} else {
System.out.println(sum / N);
}
}
} | Main.java:7: error: incompatible types: possible lossy conversion from long to int
long[] a = new long[N];
^
1 error
|
s486280932 | p03649 | C++ | #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int MaxN = 50;
LL a[MaxN + 5];
LL cnt[MaxN + 5];
int n;
int main(){
while(~scanf("%d", &n)){
for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
LL tot = 0, ans = 0;
bool ok = true;
while(ok){
ok = false;
tot = 0;
for(int i = 1; i <= n; i++){
cnt[i] = a[i] / n;
a[i] = a[i] % n;
tot += cnt[i];
}
ans += tot;
for(int i= 1; i <= n; i++){
a[i] += tot - cnt[i];
if(a[i] >= n) flag = true;
}
}
printf("%lld\n", ans);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:29:47: error: 'flag' was not declared in this scope
29 | if(a[i] >= n) flag = true;
| ^~~~
|
s034614817 | p03649 | C++ | #include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <climits>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
int main() {
ll n;
cin >> n;
vector<ull> arr(n);
for(ll i = 0; i < n; ++i)
cin >> arr[i];
sort(arr.begin(), arr.end());
ull k = 0;
while(arr.back() > (n - 1)) {
ld Z = arr.back() - (n - 1);
ld N = n;
ull temp = ceil(Z / N);
k += temp;
for(ll i = 0; i < n - 1; ++i)
arr[i] += temp;
arr[n - 1] = arr[n - 1] - (temp * N);
sort(arr.begin(), arr.end());
}
cout << k << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:27:20: error: 'ceil' was not declared in this scope
27 | ull temp = ceil(Z / N);
| ^~~~
|
s201533508 | p03649 | C++ | #include <bits/stdc++.h>
#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 SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long // %d=>%lld, 1<<n => 1LL<<n
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
return firstEl.second > secondEl.second;
}
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;
const int MAX_n = 50;
int n,a[MAX_n];
bool solve(int mid){
int need=0;
for(int i = 0;i < n;i++){
if(a[i]>=n){
need+=a[i]/n;
for(int j = 0;j < n;j++){
if(i!=j)
a[j]+=a[i]/n;
}
a[i]-=a[i]/n *n
}
}
for(int i = 0;i < n;i++){
if(a[i]>=n){
need+=a[i]/n;
for(int j = 0;j < n;j++){
if(i!=j)
a[j]+=a[i]/n;
}
a[i]-=a[i]/n *n
}
}
for(int i = 0;i < n;i++){
if(a[i]>=n){
need+=a[i]/n;
for(int j = 0;j < n;j++){
if(i!=j)
a[j]+=a[i]/n;
}
a[i]-=a[i]/n *n
}
}
if(need<=mid)
return 1;
else {
return 0;
}
}
signed main(){
cin >> n;
for(int i = 0;i < n;i++){
cin >> a[i];
}
int ok=INF; // 解が存在する値
int ng=-1; // 解が存在しない値
while (abs(ok-ng)>1){
int mid = (ok+ng)/2;
if(solve(mid)){
ok=mid;
}else{
ng = mid;
}
}
cout<< ok<< endl;
return 0;
} | a.cc: In function 'bool solve(long long int)':
a.cc:42:28: error: expected ';' before '}' token
42 | a[i]-=a[i]/n *n
| ^
| ;
43 | }
| ~
a.cc:52:28: error: expected ';' before '}' token
52 | a[i]-=a[i]/n *n
| ^
| ;
53 | }
| ~
a.cc:62:28: error: expected ';' before '}' token
62 | a[i]-=a[i]/n *n
| ^
| ;
63 | }
| ~
|
s073809430 | p03649 | C++ | #include <bits/stdc++.h>
#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 SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long // %d=>%lld, 1<<n => 1LL<<n
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
return firstEl.second > secondEl.second;
}
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;
const int MAX_n = 50;
int n,a[MAX_n];
bool solve(int mid){
int need=0;
for(int i = 0;i < n;i++){
if(a[i]>=n){
need+=a[i]/n;
a[i]-=a[i]/n *n
for(int j = 0;j < n;j++){
if(i!=j)
a[j]+=a[i]/n;
}
}
}
for(int i = 0;i < n;i++){
if(a[i]>=n){
need+=a[i]/n;
a[i]-=a[i]/n *n
for(int j = 0;j < n;j++){
if(i!=j)
a[j]+=a[i]/n;
}
}
}
for(int i = 0;i < n;i++){
if(a[i]>=n){
need+=a[i]/n;
a[i]-=a[i]/n *n
for(int j = 0;j < n;j++){
if(i!=j)
a[j]+=a[i]/n;
}
}
}
if(need<=mid)
return 1;
else {
return 0;
}
}
signed main(){
cin >> n;
for(int i = 0;i < n;i++){
cin >> a[i];
}
int ok=INF; // 解が存在する値
int ng=-1; // 解が存在しない値
while (abs(ok-ng)>1){
int mid = (ok+ng)/2;
if(solve(mid)){
ok=mid;
}else{
ng = mid;
}
}
cout<< ok<< endl;
return 0;
} | a.cc: In function 'bool solve(long long int)':
a.cc:38:28: error: expected ';' before 'for'
38 | a[i]-=a[i]/n *n
| ^
| ;
39 | for(int j = 0;j < n;j++){
| ~~~
a.cc:39:27: error: 'j' was not declared in this scope
39 | for(int j = 0;j < n;j++){
| ^
a.cc:48:28: error: expected ';' before 'for'
48 | a[i]-=a[i]/n *n
| ^
| ;
49 | for(int j = 0;j < n;j++){
| ~~~
a.cc:49:27: error: 'j' was not declared in this scope
49 | for(int j = 0;j < n;j++){
| ^
a.cc:58:28: error: expected ';' before 'for'
58 | a[i]-=a[i]/n *n
| ^
| ;
59 | for(int j = 0;j < n;j++){
| ~~~
a.cc:59:27: error: 'j' was not declared in this scope
59 | for(int j = 0;j < n;j++){
| ^
|
s923435047 | p03650 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int ,int > pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);
#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
int n;
int p[maxn] , cur;
int ans[maxn];
int cyc[maxn];
int order[maxn];
vector < int > adj[maxn];
bool mark[maxn];
set < int > st;
void dfs1(int v = 1){
if(mark[v]){
cyc[v] = 1;
while(order[cur]!=v)
cyc[order[cur--]] = 1;
return;
}
mark[v] = 1;
order[++cur] = v;
dfs1(p[v]);
}
void dfs(int v){
set < int > st;
for(auto u : adj[v]){
if(ans[u] == -1)
dfs(u);
st.insert(ans[u]);
}
int mn = 0;
for(;;mn++)
if(!st.count(mn)){
ans[v] = mn;
break;
}
}
bool chk(int v , int val){
ans[v] = val;
int pos = p[v];
set < int > st;
while(pos!=v){
st.clear();
for(auto u : adj[pos])
st.insert(ans[u]);
int mn = 0;
for(;;mn++)
if(!st.count(mn)){
ans[pos] = mn;
break;
}
pos = p[pos];
}
st.clear();
for(auto u : adj[pos])
st.insert(ans[u]);
int mn = 0;
for(;;mn++)
if(!st.count(mn))
return(mn == val);4
2 3 1 1
}
int main(){
migmig
cin >> n;
for(int i = 1; i <= n ; i ++)
cin >> p[i] , adj[p[i]].pb(i);
ms(ans , -1);
dfs1();
cur = 0;
for(int i = 1 ; i <= n ; i ++)
if(!cyc[i])dfs(i);
else cur = i;
for(auto u : adj[cur])
if(!cyc[u])
st.insert(ans[u]);
int a = -1;
int b = -1;
int cnt = 0;
for(;;cnt++){
if(st.count(cnt))continue;
if(a==-1)a = cnt;
else{
b = cnt;
break;
}
}
bool oke = 0;
oke |= chk(cur , a);
oke |= chk(cur , b);
cout << ((oke)?"POSSIBLE" : "IMPOSSIBLE");
return(0);
} | a.cc: In function 'bool chk(int, int)':
a.cc:81:36: error: expected ';' before numeric constant
81 | return(mn == val);4
| ^
| ;
82 | 2 3 1 1
| ~
|
s327087377 | p03650 | C++ | using namespace std;
int main() {
int n; scanf("%d", &n);
vector<int> p(n), dg(n);
vector<vector<int>> g(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &p[i]);
p[i]--;
dg[p[i]]++;
g[p[i]].push_back(i);
}
queue<int> q;
for (int i = 0; i < n; ++i) {
if (dg[i] == 0) q.push(i);
}
vector<int> used(n + n), sg(n);
while (!q.empty()) {
int x = q.front(); q.pop();
for (int u : g[x]) used[sg[u]] = 1;
while (used[sg[x]]) sg[x]++;
for (int u : g[x]) used[sg[u]] = 0;
if (--dg[p[x]] == 0) q.push(p[x]);
}
vector<int> nxt(n, -1), prv(n, -1), upd(n, -1);
vector<int> cycle;
for (int i = 0; i < n; ++i) {
if (dg[i] != 0) {
for (int u : g[i]) if (dg[u] == 0) used[sg[u]] = 1;
while (used[sg[i]]) sg[i]++;
upd[i] = sg[i] + 1;
while (used[upd[i]]) ++upd[i];
for (int u : g[i]) if (dg[u] == 0) used[sg[u]] = 0;
for (int u : g[i]) if (dg[u] > 0) {
nxt[i] = u;
prv[u] = i;
}
cycle.push_back(i);
}
}
auto Check = [&]() {
for (int i = 0; i < n; ++i) {
for (int u : g[i]) {
if (sg[u] == sg[i]) return false;
used[sg[u]] = 1;
}
for (int j = 0; j < sg[i]; ++j) {
if (!used[j]) return false;
}
for (int u : g[i]) used[sg[u]] = 0;
}
return true;
};
if (Check()) {
puts("POSSIBLE");
return 0;
}
auto saved = sg;
for (int j = 0; j < cycle.size(); ++j) {
sg = saved;
sg[cycle[j]] = upd[cycle[j]];
int x = cycle[j];
for (int i = 0; i < cycle.size(); ++i) {
int r = prv[x];
for (int k : g[r]) used[sg[k]] = 1;
sg[r] = 0;
while (used[sg[r]]) sg[r]++;
// printf("r = %d to = %d\n", r, sg[r]);
for (int k : g[r]) used[sg[k]] = 0;
x = r;
}
if (Check()) {
// printf("upd = %d\n", cycle[j]);
puts("POSSIBLE");
return 0;
}
}
puts("IMPOSSIBLE");
}
| a.cc: In function 'int main()':
a.cc:4:12: error: 'scanf' was not declared in this scope
4 | int n; scanf("%d", &n);
| ^~~~~
a.cc:5:5: error: 'vector' was not declared in this scope
5 | vector<int> p(n), dg(n);
| ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
+++ |+#include <vector>
1 | using namespace std;
a.cc:5:12: error: expected primary-expression before 'int'
5 | vector<int> p(n), dg(n);
| ^~~
a.cc:6:19: error: expected primary-expression before 'int'
6 | vector<vector<int>> g(n);
| ^~~
a.cc:8:22: error: 'p' was not declared in this scope
8 | scanf("%d", &p[i]);
| ^
a.cc:10:9: error: 'dg' was not declared in this scope
10 | dg[p[i]]++;
| ^~
a.cc:11:9: error: 'g' was not declared in this scope
11 | g[p[i]].push_back(i);
| ^
a.cc:13:5: error: 'queue' was not declared in this scope
13 | queue<int> q;
| ^~~~~
a.cc:1:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
+++ |+#include <queue>
1 | using namespace std;
a.cc:13:11: error: expected primary-expression before 'int'
13 | queue<int> q;
| ^~~
a.cc:15:13: error: 'dg' was not declared in this scope
15 | if (dg[i] == 0) q.push(i);
| ^~
a.cc:15:25: error: 'q' was not declared in this scope
15 | if (dg[i] == 0) q.push(i);
| ^
a.cc:17:12: error: expected primary-expression before 'int'
17 | vector<int> used(n + n), sg(n);
| ^~~
a.cc:18:13: error: 'q' was not declared in this scope
18 | while (!q.empty()) {
| ^
a.cc:20:22: error: 'g' was not declared in this scope
20 | for (int u : g[x]) used[sg[u]] = 1;
| ^
a.cc:20:28: error: 'used' was not declared in this scope
20 | for (int u : g[x]) used[sg[u]] = 1;
| ^~~~
a.cc:20:33: error: 'sg' was not declared in this scope
20 | for (int u : g[x]) used[sg[u]] = 1;
| ^~
a.cc:21:16: error: 'used' was not declared in this scope
21 | while (used[sg[x]]) sg[x]++;
| ^~~~
a.cc:21:21: error: 'sg' was not declared in this scope
21 | while (used[sg[x]]) sg[x]++;
| ^~
a.cc:22:22: error: 'g' was not declared in this scope
22 | for (int u : g[x]) used[sg[u]] = 0;
| ^
a.cc:22:28: error: 'used' was not declared in this scope
22 | for (int u : g[x]) used[sg[u]] = 0;
| ^~~~
a.cc:22:33: error: 'sg' was not declared in this scope
22 | for (int u : g[x]) used[sg[u]] = 0;
| ^~
a.cc:23:15: error: 'dg' was not declared in this scope
23 | if (--dg[p[x]] == 0) q.push(p[x]);
| ^~
a.cc:23:18: error: 'p' was not declared in this scope
23 | if (--dg[p[x]] == 0) q.push(p[x]);
| ^
a.cc:25:12: error: expected primary-expression before 'int'
25 | vector<int> nxt(n, -1), prv(n, -1), upd(n, -1);
| ^~~
a.cc:26:12: error: expected primary-expression before 'int'
26 | vector<int> cycle;
| ^~~
a.cc:28:13: error: 'dg' was not declared in this scope
28 | if (dg[i] != 0) {
| ^~
a.cc:29:26: error: 'g' was not declared in this scope
29 | for (int u : g[i]) if (dg[u] == 0) used[sg[u]] = 1;
| ^
a.cc:29:48: error: 'used' was not declared in this scope
29 | for (int u : g[i]) if (dg[u] == 0) used[sg[u]] = 1;
| ^~~~
a.cc:29:53: error: 'sg' was not declared in this scope
29 | for (int u : g[i]) if (dg[u] == 0) used[sg[u]] = 1;
| ^~
a.cc:30:20: error: 'used' was not declared in this scope
30 | while (used[sg[i]]) sg[i]++;
| ^~~~
a.cc:30:25: error: 'sg' was not declared in this scope
30 | while (used[sg[i]]) sg[i]++;
| ^~
a.cc:31:13: error: 'upd' was not declared in this scope
31 | upd[i] = sg[i] + 1;
| ^~~
a.cc:31:22: error: 'sg' was not declared in this scope
31 | upd[i] = sg[i] + 1;
| ^~
a.cc:32:20: error: 'used' was not declared in this scope
32 | while (used[upd[i]]) ++upd[i];
| ^~~~
a.cc:33:26: error: 'g' was not declared in this scope
33 | for (int u : g[i]) if (dg[u] == 0) used[sg[u]] = 0;
| ^
a.cc:33:48: error: 'used' was not declared in this scope
33 | for (int u : g[i]) if (dg[u] == 0) used[sg[u]] = 0;
| ^~~~
a.cc:34:26: error: 'g' was not declared in this scope
34 | for (int u : g[i]) if (dg[u] > 0) {
| ^
a.cc:35:17: error: 'nxt' was not declared in this scope
35 | nxt[i] = u;
| ^~~
a.cc:36:17: error: 'prv' was not declared in this scope
36 | prv[u] = i;
| ^~~
a.cc:38:13: error: 'cycle' was not declared in this scope
38 | cycle.push_back(i);
| ^~~~~
a.cc: In lambda function:
a.cc:44:26: error: 'g' was not declared in this scope
44 | for (int u : g[i]) {
| ^
a.cc:45:21: error: 'sg' was not declared in this scope
45 | if (sg[u] == sg[i]) return false;
| ^~
a.cc:46:17: error: 'used' was not declared in this scope
46 | used[sg[u]] = 1;
| ^~~~
a.cc:46:22: error: 'sg' was not declared in this scope
46 | used[sg[u]] = 1;
| ^~
a.cc:48:33: error: 'sg' was not declared in this scope
48 | for (int j = 0; j < sg[i]; ++j) {
| ^~
a.cc:49:22: error: 'used' was not declared in this scope
49 | if (!used[j]) return false;
| ^~~~
a.cc:51:26: error: 'g' was not declared in this scope
51 | for (int u : g[i]) used[sg[u]] = 0;
| ^
a.cc:51:32: error: 'used' was not declared in this scope
51 | for (int u : g[i]) used[sg[u]] = 0;
| ^~~~
a.cc:51:37: error: 'sg' was not declared in this scope
51 | for (int u : g[i]) used[sg[u]] = 0;
| ^~
a.cc: In function 'int main()':
a.cc:57:9: error: 'puts' was not declared in this scope
57 | puts("POSSIBLE");
| ^~~~
a.cc:60:18: error: 'sg' was not declared in this scope
60 | auto saved = sg;
| ^~
a.cc:61:25: error: 'cycle' was not declared in this scope
61 | for (int j = 0; j < cycle.size(); ++j) {
| ^~~~~
a.cc:63:24: error: 'upd' was not declared in this scope
63 | sg[cycle[j]] = upd[cycle[j]];
| ^~~
a.cc:66:21: error: 'prv' was not declared in this scope
66 | int r = prv[x];
| ^~~
a.cc:67:26: error: 'g' was not declared in this scope
67 | for (int k : g[r]) used[sg[k]] = 1;
| ^
a.cc:67:32: error: 'used' was not declared in this scope
67 | for (int k : g[r]) used[sg[k]] = 1;
| ^~~~
a.cc:69:20: error: 'used' was not declared in this scope
69 | while (used[sg[r]]) sg[r]++;
| ^~~~
a.cc:71:26: error: 'g' was not declared in this scope
71 | for (int k : g[r]) used[sg[k]] = 0;
| ^
a.cc:71:32: error: 'used' was not declared in this scope
71 | for (int k : g[r]) used[sg[k]] = 0;
| ^~~~
a.cc:76:13: error: 'puts' was not declared in this scope
76 | puts("POSSIBLE");
| ^~~~
a.cc:80:5: error: 'puts' was not declared in this scope
80 | puts("IMPOSSIBLE");
| ^~~~
|
s826815450 | p03650 | C++ | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;
constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
for (auto &u : v) os << u << el;
return (os);
}
template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
for (auto &u : v) is >> u;
return (is);
}
template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
return (is >> p.first >> p.second);
}
int main() {
int N; cin >> N;
vector<vint> g(N), rg(N);
vint grundy(N, 0);
bitset<200005> notloop;
vint in(N, 0);
for (int i = 0; i < N; i++) {
int p; cin >> p; --p;
g[p].push_back(i);
rg[i].push_back(p);
in[p]++;
}
queue<int> que;
for (int i = 0; i < N; i++) if (in[i] == 0) que.push(i);
while (!que.empty()) {
int u = que.front(); que.pop();
notloop[u] = true;
set<int> st;
for (auto &to : g[u]) st.insert(grundy[to]);
while (st.count(grundy[u])) grundy[u]++;
for (auto &r : rg[u]) if (--in[r] == 0) que.push(r);
}
for (int i = 0; i < N; i++) if (!notloop[i]) { s = i; break; }
vector<int> tr;
{
set<int> st;
for (auto &to : g[s]) if (notloop[to]) st.insert(grundy[to]);
while (st.count(grundy[s])) grundy[s]++;
tr.push_back(grundy[s]);
grundy[s]++;
while (st.count(grundy[s])) grundy[s]++;
tr.push_back(grundy[s]);
}
for (auto &x : tr) {
//cout << x << endl;
bitset<200005> used = notloop;
vint gr = grundy, in2 = in;
gr[s] = x;
used[s] = true;
int u = s;
for (auto &r : rg[s]) if (!used[r] && --in2[r] == 0) { u = r; break; }
while (!used[u]) {
used[u] = true;
set<int> st;
for (auto &to : g[u]) if (used[to]) st.insert(gr[to]);
while (st.count(gr[u])) gr[u]++;
//cout << u << " " << gr[u] << endl;
for (auto &r : rg[u]) if (!used[r] && --in2[r] == 0) { u = r; break; }
}
if (gr[u] != gr[s]) {
cout << "POSSIBLE" << endl;
return (0);
}
}
cout << "IMPOSSIBLE" << endl;
return (0);
}
| a.cc: In function 'int main()':
a.cc:69:56: error: 's' was not declared in this scope
69 | for (int i = 0; i < N; i++) if (!notloop[i]) { s = i; break; }
| ^
a.cc:74:35: error: 's' was not declared in this scope; did you mean 'st'?
74 | for (auto &to : g[s]) if (notloop[to]) st.insert(grundy[to]);
| ^
| st
a.cc:75:40: error: 's' was not declared in this scope; did you mean 'st'?
75 | while (st.count(grundy[s])) grundy[s]++;
| ^
| st
a.cc:76:37: error: 's' was not declared in this scope; did you mean 'st'?
76 | tr.push_back(grundy[s]);
| ^
| st
a.cc:86:20: error: 's' was not declared in this scope
86 | gr[s] = x;
| ^
|
s152308058 | p03650 | C++ | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;
constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
for (auto &u : v) os << u << el;
return (os);
}
template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
for (auto &u : v) is >> u;
return (is);
}
template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
return (is >> p.first >> p.second);
}
int main() {
int N; cin >> N;
vector<vint> g(N), rg(N);
vint grundy(N, 0);
bitset<200005> notloop;
vint in(N, 0);
for (int i = 0; i < N; i++) {
int p; cin >> p; --p;
g[p].push_back(i);
rg[i].push_back(p);
in[p]++;
}
queue<int> que;
for (int i = 0; i < N; i++) if (in[i] == 0) que.push(i);
while (!que.empty()) {
int u = que.front(); que.pop();
notloop[u] = true;
set<int> st;
for (auto &to : g[u]) st.insert(grundy[to]);
while (st.count(grundy[u])) grundy[u]++;
for (auto &r : rg[u]) if (--in[r] == 0) que.push(r);
}
int s = -1;
for (int i = 0; i < N; i++) if (in[r] < (int)g[i].size() && !notloop[i]) { s = i; break; }
if (s == -1) { cout << "POSSIBLE" << endl; return (0); }
vector<int> tr;
{
set<int> st;
for (auto &to : g[s]) if (notloop[to]) st.insert(grundy[to]);
while (st.count(grundy[s])) grundy[s]++;
tr.push_back(grundy[s]);
grundy[s]++;
while (st.count(grundy[s])) grundy[s]++;
tr.push_back(grundy[s]);
}
for (auto &x : tr) {
//cout << x << endl;
bitset<200005> used = notloop;
vint gr = grundy, in2 = in;
gr[s] = x;
used[s] = true;
int u = s;
for (auto &r : rg[s]) if (!used[r] && --in2[r] == 0) { u = r; break; }
while (!used[u]) {
used[u] = true;
set<int> st;
for (auto &to : g[u]) st.insert(gr[to]);
while (st.count(gr[u])) gr[u]++;
//cout << u << " " << gr[u] << endl;
for (auto &r : rg[u]) if (!used[r] && --in2[r] == 0) { u = r; break; }
}
set<int>st;
for (auto &to : g[u]) st.insert(gr[to]);
st.insert(gr[s]);
while (st.count(gr[u])) gr[u]++;
if (gr[u] <= (int)g[u].size()) {
cout << "POSSIBLE" << endl;
return (0);
}
}
cout << "IMPOSSIBLE" << endl;
return (0);
}
| a.cc: In function 'int main()':
a.cc:69:44: error: 'r' was not declared in this scope
69 | for (int i = 0; i < N; i++) if (in[r] < (int)g[i].size() && !notloop[i]) { s = i; break; }
| ^
|
s323680243 | p03650 | C++ | import sys
from itertools import chain
readline = sys.stdin.readline
#非再帰
def scc(Edge):
N = len(Edge)
Edgeinv = [[] for _ in range(N)]
for vn in range(N):
for vf in Edge[vn]:
Edgeinv[vf].append(vn)
used = [False]*N
dim = [len(Edge[i]) for i in range(N)]
order = []
for st in range(N):
if not used[st]:
stack = [st, 0]
while stack:
vn, i = stack[-2], stack[-1]
if not i and used[vn]:
stack.pop()
stack.pop()
else:
used[vn] = True
if i < dim[vn]:
stack[-1] += 1
stack.append(Edge[vn][i])
stack.append(0)
else:
stack.pop()
order.append(stack.pop())
res = [None]*N
used = [False]*N
cnt = -1
for st in order[::-1]:
if not used[st]:
cnt += 1
stack = [st]
res[st] = cnt
used[st] = True
while stack:
vn = stack.pop()
for vf in Edgeinv[vn]:
if not used[vf]:
used[vf] = True
res[vf] = cnt
stack.append(vf)
M = cnt+1
components = [[] for _ in range(M)]
for i in range(N):
components[res[i]].append(i)
tEdge = [[] for _ in range(M)]
teset = set()
for vn in range(N):
tn = res[vn]
for vf in Edge[vn]:
tf = res[vf]
if tn != tf and tn*M + tf not in teset:
teset.add(tn*M + tf)
tEdge[tn].append(tf)
return res, components, tEdge
N = int(readline())
P = list(map(lambda x: int(x)-1, readline().split()))
Edge = [[] for _ in range(N)]
for i in range(N):
Edge[P[i]].append(i)
R, Com, _ = scc(Edge)
Lord = list(chain(*Com[::-1]))
val = [None]*N
for vn in Lord:
if not R[vn]:
break
lvn = len(Edge[vn]) + 1
res = [0]*lvn
for vf in Edge[vn]:
if val[vf] < lvn:
res[val[vf]] += 1
for k in range(lvn):
if not res[k]:
val[vn] = k
break
st = Lord[-1]
lst = len(Edge[st]) + 2
res = [0]*lst
for vf in Edge[st]:
if val[vf] is None:
continue
if val[vf] < lst:
res[val[vf]] += 1
mc = []
for k in range(lst):
if not res[k]:
mc.append(k)
vn = st
Ls = []
while vn is not None:
for vf in Edge[vn]:
if R[vf]:
continue
if vf == st:
vn = None
else:
Ls.append(vf)
vn = vf
Ls.reverse()
ans = False
for idx in range(2):
vc = val[:]
vc[st] = mc[idx]
for vn in Ls:
lvn = len(Edge[vn])+1
res = [0]*lvn
for vf in Edge[vn]:
if vc[vf] < lvn:
res[vc[vf]] += 1
for k in range(lvn):
if not res[k]:
vc[vn] = k
break
for vn in range(N):
for vf in Edge[vn]:
if vc[vn] == vc[vf]:
break
else:
continue
break
else:
ans = True
break
print('POSSIBLE' if ans else 'IMPOSSIBLE')
| a.cc:5:2: error: invalid preprocessing directive #\U0000975e\U0000518d\U00005e30
5 | #非再帰
| ^~~~~~
a.cc:143:7: warning: multi-character literal with 8 characters exceeds 'int' size of 4 bytes
143 | print('POSSIBLE' if ans else 'IMPOSSIBLE')
| ^~~~~~~~~~
a.cc:143:30: warning: multi-character literal with 10 characters exceeds 'int' size of 4 bytes
143 | print('POSSIBLE' if ans else 'IMPOSSIBLE')
| ^~~~~~~~~~~~
a.cc:1:1: error: 'import' does not name a type
1 | import sys
| ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
|
s818064789 | p03650 | C++ | #include<bits/stdc++.h>
using namespace std;
const int MAXN = 2.1e5;
int N;
int P[MAXN];
int inDeg[MAXN];
set<int> ch[MAXN];
int V[MAXN];
int main() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> P[i];
for (int i = 1; i <= N; i++) inDeg[P[i]] ++;
vector<int> q;
for (int i = 1; i <= N; i++) if (inDeg[i] == 0) q.push_back(i);
for (int z = 0; z < int(q.size()); z++) {
int i = q[z];
V[i] = 0;
while (ch[i].count(V[i])) V[i]++;
ch[P[i]].insert(V[i]);
if (!(--inDeg[P[i]])) q.push_back(P[i]);
}
int st = 1;
while (!deg[st]) st++;
vector<int> vals;
int cur = 0;
for (int z = 0; z < 2; z++) {
for (int i = P[i]; true; i = P[i]) {
int nxt = 0;
while (nxt == cur || ch[i].count(nxt)) nxt++;
cur = nxt;
if (i == st) break;
}
vals.push_back(cur);
}
cout << (vals[0] == vals[1] ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
} | a.cc: In function 'int main()':
a.cc:25:11: error: 'deg' was not declared in this scope
25 | while (!deg[st]) st++;
| ^~~
|
s868427767 | p03650 | C++ | #include<bits/stdc++.h>
using namespace std;
const int MAXN = 2.1e5;
int N;
int P[MAXN];
int inDeg[MAXN];
set<int> ch[MAXN];
int V[MAXN];
int main() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> P[i];
for (int i = 1; i <= N; i++) inDeg[P[i]] ++;
vector<int> q;
for (int i = 1; i <= N; i++) if (inDeg[i] == 0) q.push_back(i);
for (int z = 0; z < int(q.size()); z++) {
int i = q[z];
V[i] = 0;
while (ch[i].count(V[i])) V[i]++;
ch[P[i]].insert(V[i]);
if (!(--deg[P[i]])) q.push_back(P[i]);
}
int st = 1;
while (!deg[st]) st++;
vector<int> vals;
int cur = 0;
for (int z = 0; z < 2; z++) {
for (int i = P[i]; true; i = P[i]) {
int nxt = 0;
while (nxt == cur || ch[i].count(nxt)) nxt++;
cur = nxt;
if (i == st) break;
}
vals.push_back(cur);
}
cout << (vals[0] == vals[1] ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
} | a.cc: In function 'int main()':
a.cc:21:13: error: 'deg' was not declared in this scope
21 | if (!(--deg[P[i]])) q.push_back(P[i]);
| ^~~
a.cc:25:11: error: 'deg' was not declared in this scope
25 | while (!deg[st]) st++;
| ^~~
|
s404988714 | p03650 | C++ | #include <bits/stdc++.h>
int main() {
return puts("IMPOSSIBLE), 0;
} | a.cc:3:13: warning: missing terminating " character
3 | return puts("IMPOSSIBLE), 0;
| ^
a.cc:3:13: error: missing terminating " character
3 | return puts("IMPOSSIBLE), 0;
| ^~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:4:1: error: expected primary-expression before '}' token
4 | }
| ^
a.cc:3:13: error: expected ';' before '}' token
3 | return puts("IMPOSSIBLE), 0;
| ^
| ;
4 | }
| ~
|
s090766311 | p03650 | C++ | #include<algorithm>
#include<iostream>
#include<queue>
#include<set>
using namespace std;
const int N=2e5+5;
set<int>se[N];
typedef set<int>::iterator it;
int n,now,v[N],c[N],b[N],nex[N],head[N];
struct each{
int a,id;
}a[N];
queue<int>que;
inline int read(){
register int x=0;
register char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
return x;
}
int get(int x){
int last=-1;
it i=se[x].begin();
for(;i!=se[x].end();++i)
if(last+1==*i) ++last;
else break;
return ++last;
}
int vis[N],tm[N],p[N];
int main(){
//freopen("graph.out","w",stdout);
//freopen("graph.in","r",stdin);
n=read();
for(register int i=1;i<=n;i++)
++b[p[i]=read()];
for(register int i=1;i<=n;i++)
if(!b[i]) que.push(i);
while(!que.empty()){
int x=que.front(),k=get(x);
que.pop(),se[p[x]].insert(k);
if(!(--b[p[x]])) que.push(p[x]);
}
int st;
for(int i=1;i<=n;i++)
if(b[i]){
st=i,que.push(i);
break;
}
while(!que.empty()){
int x=que.front();
que.pop(),tm[x]=get(x);
if(se[p[x]].count(tm[x])) vis[x]=1;
se[p[x]].insert(tm[x]);
if(p[x]==st){
if(tm[x]==tm[st]) break;
else{
puts("POSSIBLE");
return 0;
}
}
que.push(p[x]);
}
for(int i=1;i<=n;i++)
if(b[i]&&!vis[x]) se[p[i]].erase(tm[i]);
int end=tm[st];
que.push(st),se[st].insert(end);
while(!que.empty()){
int x=que.front();
que.pop(),tm[x]=get(x);
se[p[x]].insert(tm[x]);
if(p[x]==st){
if(tm[x]!=end) break;
else{
puts("POSSIBLE");
return 0;
}
}
que.push(p[x]);
}
puts("IMPOSSIBLE");
return 0;
} | a.cc: In function 'int read()':
a.cc:15:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
15 | register int x=0;
| ^
a.cc:16:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
16 | register char ch=getchar();
| ^~
a.cc: In function 'int main()':
a.cc:35:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
35 | for(register int i=1;i<=n;i++)
| ^
a.cc:37:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
37 | for(register int i=1;i<=n;i++)
| ^
a.cc:65:31: error: 'x' was not declared in this scope
65 | if(b[i]&&!vis[x]) se[p[i]].erase(tm[i]);
| ^
|
s751814770 | p03650 | C++ | #include<algorithm>
#include<iostream>
#include<queue>
#include<set>
using namespace std;
const int N=2e5+5;
set<int>se[N];
typedef set<int>::iterator it;
int n,now,v[N],c[N],b[N],nex[N],head[N];
struct each{
int a,id;
}a[N];
queue<int>que;
inline int read(){
register int x=0;
register char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
return x;
}
int get(int x){
int last=-1;
it i=se[x].begin();
for(;i!=se[x].end();++i)
if(last+1==*i) ++last;
else break;
return ++last;
}
int vis[N],tm[N],p[N];
int main(){
//freopen("graph.out","w",stdout);
//freopen("graph.in","r",stdin);
n=read();
for(register int i=1;i<=n;i++)
++b[p[i]=read()];
for(register int i=1;i<=n;i++)
if(!b[i]) que.push(i);
while(!que.empty()){
int x=que.front(),k=get(x);
que.pop(),se[p[x]].insert(k);
if(!(--b[p[x]])) que.push(p[x]);
}
int st;
for(int i=1;i<=n;i++)
if(b[i]){
st=i,que.push(i);
break;
}
while(!que.empty()){
int x=que.front();
que.pop(),tm[x]=get(x);
if(se[p[x]].count(tm[x])) vis[x]=1;
se[p[x]].insert(tm[x]);
if(p[x]==st){
if(tm[x]==tm[st]) break;
else{
puts("POSSIBLE");
return 0;
}
}
que.push(p[x]);
}
for(int i=1;i<=n;i++)
if(b[i]&&!vis[x]) se[p[i]].erase(tm[i]);
int end=tm[st];
que.push(st),se[st].insert(end);
while(!que.empty()){
int x=que.front();
que.pop(),tm[x]=get(x);
se[p[x]].insert(tm[x]);
if(p[x]==st){
if(tm[x]!=end) break;
else{
puts("POSSIBLE");
return 0;
}
}
que.push(p[x]);
}
puts("IMPOSSIBLE");
return 0;
}
| a.cc: In function 'int read()':
a.cc:15:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
15 | register int x=0;
| ^
a.cc:16:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
16 | register char ch=getchar();
| ^~
a.cc: In function 'int main()':
a.cc:35:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
35 | for(register int i=1;i<=n;i++)
| ^
a.cc:37:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
37 | for(register int i=1;i<=n;i++)
| ^
a.cc:65:31: error: 'x' was not declared in this scope
65 | if(b[i]&&!vis[x]) se[p[i]].erase(tm[i]);
| ^
|
s602692884 | p03650 | C++ | //#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
#define int long long
#define ll long long
auto start_time = system_clock::now();
//@formatter:off
#ifdef _DEBUG
//区間削除は出来ない
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>
#else
#define unordered_map __gnu_pbds::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>
#endif
struct xorshift { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(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()(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 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); }
//衝突対策
#define ws wszzzz
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);}
//@マクロ省略系 型,構造
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo= bool;
#define au auto
using P = pair<ll, ll>;
using pd =pair<dou, dou>;
#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 wh while
#define upd update
#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 lam(right) [&](ll& p){return p right;}
//マクロ省略系 コンテナ
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 o_vvt(o1, o2, o3, o4, name, ...) name
#define vvt0(t) V<V<t>>
#define vvt1(t,a) V<V<t>>a
#define vvt2(t,a, b) V<V<t>>a(b)
#define vvt3(t,a, b, c) V<V<t>> a(b,V<t>(c))
#define vvt4(t,a, b, c, d) V<V<t>> a(b,V<t>(c,d))
#define vvi(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__)
#define vvb(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__)
#define vvs(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__)
#define vvd(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__)
#define vvc(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__)
#define vvp(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__)
#define vvt(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(T,__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 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 setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<ll>;
#define bset bitset
#define uset unordered_set
#define useti unordered_set<ll,ll,xorshift>
#define mset multiset
#define mseti multiset<ll>
#define umap unordered_map
#define umapi unordered_map<ll,ll,xorshift>
#define umapp unordered_map<P,ll,xorshift>
#define mmap multimap
template<class T> struct pq { priority_queue<T, vector<T>, greater<T> > q;/*小さい順*/ T su = 0; 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> struct pqg { priority_queue<T> q;/*大きい順*/ T su = 0; void clear() {q = priority_queue<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();}};
#define pqi pq<ll>
#define pqgi pqg<ll>
//マクロ 繰り返し
#define o_rep(o1, o2, o3, o4, name, ...) name
# 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 rep(...) o_rep(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#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)
#define rer(...) o_rep(__VA_ARGS__,rer4,rer3,rer2,)(__VA_ARGS__)
#define reps2(i, j, n) for(ll i = 0,reps2lim=n; i < reps2lim ;++i)for(ll j = 0; j < reps2lim ; ++j)
#define reps3(i, j, k, n) for(ll i = 0,reps3lim=n; i < reps3lim ; ++i)for(ll j = 0; j < reps3lim ; ++j)for(ll k = 0; k < reps3lim ; ++k)
#define reps4(i, j, k, l, n) for(ll i = 0,reps4lim=n; i < reps4lim ; ++i)for(ll j = 0; j < reps4lim ; ++j)for(ll k = 0; k < reps4lim ; ++k)for(ll l = 0; l < reps4lim ; ++l)
#define o_reps(o1, o2, o3, o4, o5, name, ...) name
#define reps(...) o_reps(__VA_ARGS__,reps4,reps3,reps2,rep2,)(__VA_ARGS__)
#define repss(i, j, k, a, b, c) for(ll i = 0; i < a ; ++i)for(ll j = 0; j < b ; ++j)for(ll k = 0; k < c ; ++k)
#define fora(a, b) for(auto&& a : b)
#define forg(gi, ve) for (ll gi = 0,forglim = ve.size(), f, t, c; gi < forglim && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi)
#define fort(gi, ve) for (ll gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi)if(t!=p)
#define form(st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it).fi < r; ++it)
#define forit(st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it) < r;)
//マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const ll inf = (ll) 1e9 + 100;
const ll linf = (ll) 1e18 + 100;
const char infc = '{';
const string infs = "{";
const double eps = 1e-9;
const double PI = 3.1415926535897932384626433832795029L;
ll ma = numeric_limits<ll>::min();
ll mi = numeric_limits<ll>::max();
//マクロ省略形 関数等
#define arsz(a) (sizeof(a)/sizeof(a[0]))
#define sz(a) ((ll)(a).size())
#define mp make_pair
#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()
constexpr bool ev(ll a) { return !(a & 1); }
constexpr bool od(ll a) { return (a & 1); }
//@拡張系 こう出来るべきというもの
//埋め込み 存在を意識せずに機能を増やされているもの
//@formatter:on
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); }};
}
//@formatter:off
//stream まとめ
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 << endl; 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) { for (auto &&v:m) os << v; return os;}
template<typename W, typename H> void resize(vector<W> &vec, const H head) { vec.resize(head); }template<typename W, typename H, typename ... T> void resize(vector<W> &vec, const H &head, const T ... tail) {vec.resize(head);for (auto &v: vec)resize(v, tail...);}
template<typename T, typename F> bool all_of2(T &v, F f) { return f(v); }
template<typename T, typename F> bool all_of2(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(T &v, F f) { return f(v); }
template<typename T, typename F> bool any_of2(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(T &v, F f) { return f(v); }
template<typename T, typename F> bool none_of2(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(T &v, F f) { return f(v); }
template<typename T, typename F> ll find_if2(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(T &v, F f) { return f(v); }
template<typename T, typename F> ll rfind_if2(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(string &s, const T &v) { return s.find(v) != string::npos; }
template<typename T> bool contains(vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); }
template<typename T, typename F> bool contains_if2(vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); }
template<typename T, typename F> ll count_if2(T &v, F f) { return f(v); }
template<typename T, typename F> ll count_if2(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 &v, F f) { f(v); }
template<typename T, typename F> void for_each2(vector<T> &vec, F f) { fora(v, vec)for_each2(v, f); }
template<typename W> ll count_od(vector<W> &a) {return count_if2(a,[](ll v){return v&1 ;});}
template<typename W> ll count_ev(vector<W> &a) {return count_if2(a,[](ll v){return !(v&1) ;});}
#define all_of(a,right) all_of2(a,lam(right))
#define any_of(a,right) any_of2(a,lam(right))
#define none_of(a,right) none_of2(a,lam(right))
#define find_if(a,right) find_if2(a,lam(right))
#define rfind_if(a,right) rfind_if2(a,lam(right))
#define contains_if(a,right) contains_if2(a,lam(right))
#define count_if(a, right) count_if2(a,lam(right))
#define for_each(a, right) do{fora(v,a){v right;}}while(0)
template<class T, class U> void replace(vector<T> &a, T key, U v) { replace(a.begin(), a.end(), 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; }
template<class T> void replace(T &a) { replace(a, '#'); }
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 includes(vector<T> &a, vector<T> &b) {vi c = a;vi d = b;sort(all(c));sort(all(d));return includes(all(c), all(d));}
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)); }
void iota(vector<ll> &ve, ll s, ll n) {ve.resize(n);iota(all(ve), s);}
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;}
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; });}
void sort(string &a) { sort(all(a)); }
template<class T> void sort(vector<T> &a) { sort(all(a)); }
//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 T> void rsort(vector<T> &a) { sort(all(a), greater<T>()); };
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> 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, 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> 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 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> 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, 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> 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 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;}
//sortindex 元のvectorはソートしない
template<class T> vi sorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind); return ind;}/*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]); }
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<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<vector<W>> &xx,const T v,ll lh,ll lw) {rep(i, lh)rep(j,lw)xx[i][j]=v;}
template<class T,class U>void fill(vector<T> &a,U val,vi& ind) {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;}
//@汎用便利関数 入力
ll in() {ll 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...);}
#define o_din(o1, o2, o3, o4, o5, o6, name, ...) name
#define din1(a) ll a;cin>>a
#define din2(a, b) ll a,b;cin>>a>> b
#define din3(a, b, c) ll a,b,c;cin>>a>>b>>c
#define din4(a, b, c, d) ll a,b,c,d;cin>>a>>b>>c>>d
#define din5(a, b, c, d, e) ll a,b,c,d,e;cin>>a>>b>>c>>d>>e
#define din6(a, b, c, d, e, f) ll a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f
#define din(...) o_din(__VA_ARGS__,din6,din5,din4,din3,din2 ,din1)(__VA_ARGS__)
#define o_dind(o1, o2, o3, o4, name, ...) name
#define din1d(a) din1(a);a--
#define din2d(a, b) din2(a,b);a--,b--
#define din3d(a, b, c) din3(a,b,c);a--,b--,c--
#define din4d(a, b, c, d) din4(a,b,c,d);a--,b--,c--,d--
#define dind(...) o_dind(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__)
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;}
#ifdef _DEBUG
template<class T> void outv(vector<T> &a, ll W = inf) { if (W == inf)W = min(sz(a), 12ll); rep(i, W) { cerr << i << " "; } cerr << "" << endl; rep(i, W) { cerr << a[i] << " "; } cerr << "" << endl;};
template<class T> void outv(vector<vector<T> > &a, ll H = inf, ll W = inf,int key=-1) { H = min({H, sz(a), 12ll}); W = min({W, sz(a[0]), 12ll}); if(key==-1)cerr << "*|";else cerr<<key<<"|"; rep(w, W)cerr << std::right << std::setw(4) << w; cerr << "" << endl; rep(w, W * 4 + 2)cerr << "_"; cerr << "" << endl; rep(h, H) { cerr << h << "|"; rep(w, W) { if (a[h][w] == linf) cerr << " e" << " "; else cerr << std::right << std::setw(4) << a[h][w]; } cerr << "" << endl; }}
template<class T> void outv(vector<vector<vector<T> > > &a, ll H = inf, ll W = inf,ll U =inf) {rep(i,min({H,5ll,sz(a)})){outv(a[i],W,U,i);cerr<<""<<endl;}}
#else
template<class T> void outv(vector<T> &a, ll W) {;}
template<class T> void outv(vector<vector<T> > &a, ll H = linf, ll W = linf,int key=-1) {;}
template<class T> void outv(vector<vector<vector<T> > > &a, ll H = linf, ll W = linf,ll U = linf) {;}
#endif
template<class T> void outl(vector<T> &a) { fora(v, a)cout << v << endl; }
template<class T> void na(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i];}
#define dna(a, n) vi a(n); rep(dnai,n) cin >> a[dnai];
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, 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];}
#define dna2(a, b, n) vi a(n),b(n);rep(dna2i, n)cin >> a[dna2i] >> b[dna2i];
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];}
#define dna2d(a, b, n) vi a(n),b(n);rep(dna2di, n){cin >> a[dna2di] >> b[dna2di];a[dna2di]--,b[dna2di]--;}
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]--;}
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(n),b(n),c(n); rep(dna3i, n)cin >> a[dna3i] >> b[dna3i] >> c[dna3i];
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(n),b(n),c(n); rep(dna3di, n){cin >> a[dna3di] >> b[dna3di] >> c[dna3di];a[dna3di]--,b[dna3di]--,c[dna3di]--;}
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(n),b(n),c(n),d(n); rep(dna4i, n)cin >> a[dna4i] >> b[dna4i] >> c[dna4i]>>d[dna4i];
#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 sp << " " <<
#define debugName(VariableName) # VariableName
#define deb1(x) debugName(x)<<" = "<<x
#define deb2(x, ...) deb1(x) <<", "<< deb1(__VA_ARGS__)
#define deb3(x, ...) deb1(x) <<", "<< deb2(__VA_ARGS__)
#define deb4(x, ...) deb1(x) <<", "<< deb3(__VA_ARGS__)
#define deb5(x, ...) deb1(x) <<", "<< deb4(__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__)
#define o_ebug(o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, name, ...) name
#ifdef _DEBUG
#define deb(...) cerr<< o_ebug(__VA_ARGS__,deb10,deb9,deb8,deb7,deb6,deb5,deb4,deb3,deb2,deb1)(__VA_ARGS__) <<endl
#else
#define deb(...) ;
#endif
#define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'
//@formatter:off
//よく使うクラス、構造体
struct unionfind {
vector<ll> par;
vector<ll> siz;
vector<ll> es;
ll n, trees;//連結グループの数(親の種類)
unionfind(ll n) : n(n), trees(n) { par.resize(n); siz.resize(n); es.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } }
ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); }}
bool unite(ll x, ll y) {
x = root(x);
y = root(y);
es[x]++;
if (x == y) return false;
if (siz[x] > siz[y]) swap(x, y);
trees--;
par[x] = y;
siz[y] += siz[x];
es[y] += es[x];
return true;
}
bool same(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return siz[root(x)]; }
ll esize(ll x) { return es[root(x)]; }
vi sizes(){ vi cou(n); vi ret; ret.reserve(n); rep(i, n){ cou[root (i)]++; } rep(i, n){ if(cou[i])ret.push_back(cou[i]); } return ret; }
//つながりを無向グラフと見なし、xが閉路に含まれるか判定
bool close(ll x) { return esize(x) >= size(x); }
V<vi> sets() { vi ind(n, -1); ll i = 0; vvi(res, trees); rep(j, n) { ll r = root(j); if (ind[r] == -1)ind[r] = i++; res[ind[r]].push_back(j); } rep(i, trees) { ll r = root(res[i][0]); if (res[i][0] == r)continue; rep(j, 1, sz(res[i])) { if (res[i][j] == r) { swap(res[i][0], res[i][j]); break; } } } return res; }
};//@formatter:off
using bll =__int128;
using u32 = unsigned;
using u64 = unsigned long long;
using u128 = __uint128_t;
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 toi128(string &s) { __int128 ret = 0; for (ll i = 0; i < s.length(); ++i) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret;}
//エラー
void ole() {
#ifdef _DEBUG
debugline("ole"); 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() { assert(0 == 1); exit(0);}
void tle() { while (inf)cout << inf << endl; }
//便利関数
//テスト用
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); }}}
vi ranv(ll n, ll min, ll max) { vi v(n); rep(i, n)v[i] = rand(min, max); return v;}
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;}
//便利 汎用
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]); }}
vp run_length(vi &a) { vp 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;}
vector<pair<char, ll>> run_length(string &a) { vector<pair<char, ll>> 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;}
template<class F> ll mgr(ll ok, ll ng, F f) { if (ok < ng) while (ng - ok > 1) { ll mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } else while (ok - ng > 1) { ll mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } return ok;}
//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;}
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);}
template<typename W, typename U> T 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 mt(i, j, k); return mt(-1, -1, -1);}
template<typename W, typename T> ll count2(W &a, const T k) { return a == k; }
template<typename W, typename T> ll count2(vector<W> &a, const T k) { ll ret = 0; fora(v, a)ret += count2(v, k); return ret;}
template<typename W, typename T> ll count(vector<W> &a, const T k) { ll ret = 0; fora(v, a)ret += count2(v, k); return ret;}
ll count(str &a, 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;}
vi count(str &a) { vi cou(26); char c = 'a'; if ('A' <= a[0] && a[0] <= 'Z')c = 'A'; rep(i, sz(a))++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> void rev(vector<T> &a) { reverse(all(a)); }
template<class U> void 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]; a = b;}
void rev(string &a) { reverse(all(a)); }
constexpr ll p10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000ll, 100000000000ll, 1000000000000ll, 10000000000000ll, 100000000000000ll, 1000000000000000ll, 10000000000000000ll, 100000000000000000ll, 1000000000000000000ll};
ll get(ll a, ll keta) { return (a / (ll) pow(10, keta)) % 10; }
ll keta(ll v) { if (v < p10[9]) { if (v < p10[4]) { if (v < p10[2]) { if (v < p10[1]) 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 if (v < p10[15])return 15; else return 16; } else { if (v < p10[17])return 17; else return 18; }}}}
ll dsum(ll v,ll sin=10) { ll ret = 0; for (; v; v /= sin)ret += v % sin; return ret;}
struct sint {
ll v;
sint(ll v) : v(v) {}
operator ll() { return v; }
//下からi番目
ll operator[](ll i) { return (v / p10[i]) % 10; }
ll back(ll i) { return operator[](i); }
//上からi番目
ll top(ll i) {
ll len = keta(v);
return operator[](len - 1 - i);
}
//先頭からi番目にセット
ll settop(ll i, ll k) {
ll len = keta(v);
return set(len - 1 - i, k);
}
ll set(ll i, ll k) {
if (i < 0)return settop(abs(i) - 1, k);
return v += p10[i] * (k - (v / p10[i]) % 10);
}
ll add(ll i, ll k = 1) { return v += p10[i] * k; }
ll addtop(ll i, ll k = 1) { return v += p10[keta(v) - i - 1] * k; }
ll dec(ll i, ll k = 1) { return v -= p10[i] * k; }
ll dectop(ll i, ll k = 1) { return v -= p10[keta(v) - i - 1] * k; }
#define op(t, o)template<class T> t operator o(T r){return v o r;}
op(ll, +=); op(ll, -=); op(ll, *=); op(ll, /=); op(ll, %=); op(ll, +); op(ll, -); op(ll, *); op(ll, /); op(ll, %); op(bool, ==); op(bool, !=); op(bool, <); op(bool, <=); op(bool, >); op(bool, >=);
#undef op
template<class T> ll operator<<=(T r) { return v *= p10[r]; }
template<class T> ll operator<<(T r) { return v * p10[r]; }
template<class T> ll operator>>=(T r) { return v /= p10[r]; }
template<class T> ll operator>>(T r) { return v / p10[r]; }
};
ll mask10(ll v) { return p10[v] - 1; }
//変換系
template<class T> auto keys(T a) { vector<decltype((a.begin())->fi)> res; for (auto &&k :a)res.push_back(k.fi); return res;}
template<class T> auto values(T a) { vector<decltype((a.begin())->se)> res; for (auto &&k :a)res.push_back(k.se); return res;}
template<class T, class U> bool chma(T &a, const U &b) { if (a < b) { a = b; return true; } return false;}
template<class U> bool chma(const U &b) { return chma(ma, b); }
template<class T, class U> bool chmi(T &a, const U &b) { if (b < a) { a = b; return true; } return false;}
template<class U> bool chmi(const U &b) { return chmi(mi, b); }
template<class T> T min(T a, signed b) { return a < b ? a : b; }
template<class T> T max(T a, signed b) { return a < b ? b : a; }
template<class T> T min(T a, T b, T c) { return a >= b ? b >= c ? c : b : a >= c ? c : a; }
template<class T> T max(T a, T b, T c) { return a <= b ? b <= c ? c : b : a <= c ? c : a; }
template<class T> T min(vector<T>& a) { return *min_element(all(a)); }
template<class T> T mini(vector<T>& a) { return min_element(all(a)) - a.begin(); }
template<class T> T min(vector<T>& a, ll n) { return *min_element(a.begin(), a.begin() + min(n, sz(a))); }
template<class T> T min(vector<T>& a, ll s, ll n) { return *min_element(a.begin() + s, a.begin() + min(n, sz(a))); }
template<class T> T max(vector<T>& a) { return *max_element(all(a)); }
template<class T,class U> T max(vector<T>& a,vector<U>& b) { return max(*max_element(all(a)),*max_element(all(b))); }
template<class T> T maxi(vector<T>& a) { return max_element(all(a)) - a.begin(); }
template<class T> T max(vector<T>& a, ll n) { return *max_element(a.begin(), a.begin() + min(n, sz(a))); }
template<class T> T max(vector<T>& a, ll s, ll n) { return *max_element(a.begin() + s, a.begin() + min(n, sz(a))); }
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, max(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;}
template<class T> T sum(vector<T> &v, ll s = 0, ll t = inf) { T ret = 0; rep(i, s, min(sz(v), t))ret += v[i]; return ret;}template<class T> T sum(vector<vector<T> > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> T sum(vector<vector<vector<T> > > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> T sum(vector<vector<vector<vector<T> > > > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> T sum(vector<vector<vector<vector<vector<T> > > > > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> auto sum(priority_queue<T, vector<T>, greater<T> > &r) { auto q = r; T ret = 0; while (sz(q)) { ret += q.top(); q.pop(); } return ret;}template<class T> auto sum(priority_queue<T> &r) { auto q = r; T ret = 0; while (sz(q)) { ret += q.top(); q.pop(); } 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;}
void clear(PQ &q) { q = PQ(); }
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;}
//imoは0-indexed
//ruiは1-indexed
template<class T> vector<T> imo(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret;}
//kと同じものの数
template<class T, class U> vi imo(vector<T> &a, U k) {vector<T> ret = a;rep(i, sz(ret))ret[i] = a[i] == k;rep(i, sz(ret) - 1)ret[i + 1] += ret[i];return ret;}
template<class T> vector<T> imox(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(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chmi(ret[i + 1], ret[i]); return ret;}
template<class T> struct ruiC { const vector<T> rui; ruiC(vector<T> &ru) : rui(ru) {} T operator()(ll l, ll r) { if (l > r) { cerr<<"ruic ";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> struct rruic { const T *rrui; rruic(T *ru) : rrui(ru) {} T operator()(ll l, ll r) { assert(l >= r); return rrui[r] - rrui[l]; } T operator[](ll i) { return rrui[i]; }};
template<class T> vector<T> ruiv(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(vector<T> &a) { vector<T> ret = ruiv(a); return ruiC<T>(ret);}
vector<ll> ruiv(string &a) { if (sz(a) == 0)return vi(1); ll dec = ('0' <= a[0] && a[0] <= '9') ? '0' : 0; vector<ll> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i] - dec; return ret;}
ruiC<ll> ruic(string &a) { vector<ll> ret = ruiv(a); return ruiC<ll>(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);}
//xor
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> 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> rruic<T> rrui(vector<T> &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; rer(i, len - 1)res[i - 1] = res[i] + a[i]; return rruic<T>(res);}
//掛け算
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> void inc(T &a, U v = 1) { a += v; }
template<class T, class U> 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> 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> void dec(vector<T> &a) { for (auto &u :a)dec(u, 1); }
template<class T,class U> void dec(vector<T> &a,vector<U> &b) { for (auto &u :a)dec(u, 1);for (auto &u :b)dec(u, 1); }
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 ins(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 ins(0, i, sz(a)) && ins(0, j, sz(a)); }
ll u(ll a) { return a < 0 ? 0 : a; }
template<class T> vector<T> u(const vector<T> &a) { vector<T> ret = a; fora(v, ret)v = u(v); return ret;}
#define MIN(a) numeric_limits<a>::min()
#define MAX(a) numeric_limits<a>::max()
template<class F> ll 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 resIndex;}
template<class F> ll 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 resIndex;}
/*loopは200にすればおそらく大丈夫 余裕なら300に*/
template<class F> dou goldd_d(dou left, dou right, F calc, ll loop = 140) { 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 left;}
template<class F> dou goldt_d(dou left, dou right, F calc, ll loop = 140) { 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 left;}
//l ~ rを複数の区間に分割し、極致を与えるiを返す time-20 msまで探索
template<class F> ll 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 mini;}
template<class F> ll 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 maxi;}
template<class F> dou 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 mini;}
template<class F> dou 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 maxi;}
template<class T> T min(vector<vector<T >> &a) { T res = MAX(T); rep(i, a.size())chmi(res, *min_element(all(a[i]))); return res;}
template<class T> T max(vector<vector<T >> &a) { T res = MIN(T); rep(i, a.size())chma(res, *max_element(all(a[i]))); return res;}
constexpr bool bget(ll m, ll keta) { return (m >> keta) & 1; }
ll bget(ll m, ll keta, ll sinsuu) { m /= (ll) pow(sinsuu, keta); return m % sinsuu;}
ll bit(ll n) { return (1LL << (n)); }
ll bit(ll n, ll sinsuu) { return (ll) pow(sinsuu, n); }
ll mask(ll n) { return (1ll << n) - 1; }
#define bcou __builtin_popcountll
//最下位ビット
ll lbit(ll n) { return n & -n; }
//最上位ビット
ll hbit(ll n) { n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); n |= (n >> 32); return n - (n >> 1);}
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;}
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; } 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 unique(v) v.erase( unique(v.begin(), v.end()), v.end() );
//[i] := i番として圧縮されたものを返す
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;}
vi compress(vi &a, umap<ll, ll> &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(V<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(); }}
//要素が見つからなかったときに困る
#define binarySearch(a, v) (binary_search(all(a),v))
#define lowerIndex(a, v) (lower_bound(all(a),v)-a.begin())
#define lowerBound(a, v) (*lower_bound(all(a),v))
#define upperIndex(a, v) (upper_bound(all(a),v)-a.begin())
#define upperBound(a, v) (*upper_bound(all(a),v))
template<class T> void fin(T s) { cout << s << endl, exit(0); }
//便利 数学 math
ll mod(ll a, ll m) { return (a % m + m) % m; }
ll pow(ll a) { return a * a; };
ll fact(ll v) { return v <= 1 ? 1 : v * fact(v - 1); }
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];}
double comd(ll n, ll r) { assert(n < 2020); 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];}
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;}
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; }}
ll lower_remi__bx_a(ll kei, ll rem, ll x) {if (rem >= x) return 0;return (x - rem + kei - 1) / kei;}
ll lower_remv__bx_a(ll kei, ll rem, ll x) {if (rem >= x) return rem;return (x - rem + kei - 1) / kei * kei + rem;}
ll upper_remi__bx_a(ll kei, ll rem, ll x) {if (rem > x) return 0;return (x - rem + kei) / kei;}
ll upper_remv__bx_a(ll kei, ll rem, ll x) {if (rem > x) return rem;return (x - rem + kei) / kei * kei + rem;}
//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); }
ll sig(ll t) { return ((1 + t) * t) >> 1; }
ll sig(ll s, ll t) { return ((s + t) * (t - s + 1)) >> 1; }
//幾何 Pをcomplexとして扱う
template<class T, class U> bool eq(T a, U b) { return fabs(a - b) < eps; }
dou atan2(pd a) { return atan2(a.se, a.fi); }
dou angle(pd f, pd t) { return atan2(t.se - f.se, t.fi - f.fi); }
dou distance(pd a, pd b) { return hypot(a.fi - b.fi, a.se - b.se); }
//bを中心とするabcのtheta aからcにかけて時計回り
dou angle(pd a, pd b, pd c) { dou ax = a.fi - b.fi; dou ay = a.se - b.se; dou cx = c.fi - b.fi; dou cy = c.se - b.se; double ret = atan2(cy, cx) - atan2(ay, ax); if (ret < 0) ret += 2 * PI; return ret;}
dou dot(pd a, pd b) { return a.fi * b.fi + a.se + b.se; }
dou cro(pd a, pd b) { return a.fi * b.se - a.se + b.fi; }
//機能拡張
template<typename CharT, typename Traits, typename Alloc>basic_string<CharT, Traits, Alloc>operator+(const basic_string<CharT, Traits, Alloc> &lhs, const int rv) { basic_string<CharT, Traits, Alloc> str(lhs); str.append(to_string(rv)); return str;}template<typename CharT, typename Traits, typename Alloc>void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const int rv) { lhs += to_string(rv);}template<typename CharT, typename Traits, typename Alloc>basic_string<CharT, Traits, Alloc>operator+(const basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { basic_string<CharT, Traits, Alloc> str(lhs); str.append(to_string(rv)); return str;}template<typename CharT, typename Traits, typename Alloc>void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { lhs += to_string(rv);}
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+(const vector<T> &a, U v) { vector<T> ret = a; ret += v; return ret;}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+(vector<T> a, vector<T> b) { vector<T> ret; ret = a; fora(v, b)ret += v; return ret;}template<class T> vector<T> &operator+=(vector<T> &a, vector<T> &b) { fora(v, b)a += v; 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); 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> vector<T> operator*(vector<T> &a, U b) { vector<T> ret; fora(v, a)ret += v * b; return ret;}
template<class T, class U> vector<T> operator/(vector<T> &a, U b) { vector<T> ret; fora(v, a)ret += v / b; return ret;}
template<class T, class U> vector<T> operator*=(vector<T> &a, U b) { fora(v, a)v *= b; return a;}
template<class T, class U> vector<T> operator/=(vector<T> &a, U b) { fora(v, a)v /= b; return a;}
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<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); }
template<typename T> void insert(set<T> &v, vector<T> list) { for (auto &&va :list)v.insert(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;}
void yn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; }
void Yn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }
void YN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }
void fyn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; exit(0);}
void fYn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; exit(0);}
void fYN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; exit(0);}
void Possible(bool a) { if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0);}
void POSSIBLE(bool a) { if (a)cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; exit(0);}
//@formatter:off
template<typename T> T minv(T a, T m);
template<typename T> T minv(T a);
template<typename T>
class Modular {
public:
using Type = typename decay<decltype(T::value)>::type; constexpr Modular() : value() {} template<typename U> Modular(const U &x) { value = normalize(x); } template<typename U> static Type normalize(const U &x) { Type v; if (-mod() <= x && x < mod()) v = static_cast<Type>(x); else v = static_cast<Type>(x % mod()); if (v < 0) v += mod(); return v; } const Type &operator()() const { return value; } template<typename U>explicit operator U() const { return static_cast<U>(value); } constexpr static Type mod() { return T::value; } Modular &operator+=(const Modular &other) { if ((value += other.value) >= mod()) value -= mod(); return *this; } Modular &operator-=(const Modular &other) { if ((value -= other.value) < 0) value += mod(); return *this; } template<typename U> Modular &operator+=(const U &other) { return *this += Modular(other); } template<typename U> Modular &operator-=(const U &other) { return *this -= Modular(other); } Modular &operator++() { return *this += 1; } Modular &operator--() { return *this -= 1; } Modular operator++(signed) { Modular result(*this); *this += 1; return result; } Modular operator--(signed) { Modular result(*this); *this -= 1; return result; } Modular operator-() const { return Modular(-value); }
template<typename U = T>typename enable_if<is_same<typename Modular<U>::Type, signed>::value, Modular>::type &operator*=(const Modular &rhs) {
#ifdef _WIN32
uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;asm("divl %4; \n\t": "=a" (d), "=d" (m): "d" (xh), "a" (xl), "r" (mod()));value = m;
#else
value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
return *this;
}
template<typename U = T> typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type &operator*=(const Modular &rhs) { int64_t q = static_cast<int64_t>(static_cast<double>(value) * rhs.value / mod()); value = normalize(value * rhs.value - q * mod()); return *this; } template<typename U = T> typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type &operator*=(const Modular &rhs) { value = normalize(value * rhs.value); return *this; } Modular &operator/=(const Modular &other) { return *this *= Modular(minv(other.value)); } template<typename U> friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs); template<typename U> friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs); template<typename U> friend std::istream &operator>>(std::istream &stream, Modular<U> &number); operator int() { return value; }private: Type value;
};
template<typename T> bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value == rhs.value; }template<typename T, typename U> bool operator==(const Modular<T> &lhs, U rhs) { return lhs == Modular<T>(rhs); }template<typename T, typename U> bool operator==(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) == rhs; }template<typename T> bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) { return !(lhs == rhs); }template<typename T, typename U> bool operator!=(const Modular<T> &lhs, U rhs) { return !(lhs == rhs); }template<typename T, typename U> bool operator!=(U lhs, const Modular<T> &rhs) { return !(lhs == rhs); }template<typename T> bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value < rhs.value; }template<typename T> Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }template<typename T, typename U> Modular<T> operator+(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) += rhs; }template<typename T, typename U> Modular<T> operator+(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }template<typename T> Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }template<typename T, typename U> Modular<T> operator-(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) -= rhs; }template<typename T, typename U> Modular<T> operator-(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }template<typename T> Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }template<typename T, typename U> Modular<T> operator*(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) *= rhs; }template<typename T, typename U> Modular<T> operator*(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }template<typename T> Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; }template<typename T, typename U> Modular<T> operator/(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) /= rhs; }template<typename T, typename U> Modular<T> operator/(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; }
constexpr signed MOD =
// 998244353;
1e9 + 7;//MOD
using mint = Modular<std::integral_constant<decay<decltype(MOD)>::type, MOD>>;
constexpr int mint_len = 1400001;
vi fac, finv, inv;
vi p2;
mint com(int n, int r) { if (r < 0 || r > n) return 0; return mint(finv[r] * fac[n] % MOD * finv[n - r]);}
mint pom(int n, int r) {/* if (!sz(fac)) com(0, -1);*/ if (r < 0 || r > n) return 0; return mint(fac[n] * finv[n - 1]);}
mint npr(int n, int r) {/* if (!sz(fac)) com(0, -1);*/ if (r < 0 || r > n) return 0; return mint(fac[n] * finv[n - r]);}
int nprin(int n, int r) {/* if (!sz(fac)) com(0, -1);*/ if (r < 0 || r > n) return 0; return fac[n] * finv[n - r] % MOD;}
int icom(int n, int r) { const int NUM_ = 1400001; static ll fac[NUM_ + 1], finv[NUM_ + 1], inv[NUM_ + 1]; if (fac[0] == 0) { inv[1] = fac[0] = finv[0] = 1; for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i <= NUM_; ++i) fac[i] = fac[i - 1] * i % MOD, finv[i] = finv[i - 1] * inv[i] % MOD; } if (r < 0 || r > n) return 0; return ((finv[r] * fac[n] % MOD) * finv[n - r]) % MOD;}
#define ncr com
#define ncri icom
//n個の場所にr個の物を置く
mint nhr(int n, int r) { return com(n + r - 1, r); }
mint hom(int n, int r) { return com(n + r - 1, r); }
int nhri(int n, int r) { return icom(n + r - 1, r); }
template<typename T> T minv(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u;}
template<typename T> T minv(T a) { if (a < mint_len)return inv[a]; T u = 0, v = 1; T m = MOD; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u;}
template<typename T, typename U> Modular<T> mpow(const Modular<T> &a, const U &b) { assert(b >= 0); int x = a(), res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res;}
template<typename T, typename U, typename V> mint mpow(const T a, const U b, const V m = MOD) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= m; (x *= x) %= m; p >>= 1; } return res;}
template<typename T, typename U> mint mpow(const T a, const U b) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res;}
template<typename T, typename U, typename V> int mpowi(const T &a, const U &b, const V &m = MOD) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= m; (x *= x) %= m; p >>= 1; } return res;}
template<typename T> string to_string(const Modular<T> &number) { return to_string(number());}
string yuri(const mint &a) { stringstream st; rep(i, 300) {rep(j, 300) {if ((mint) i / j == a) {st << i << " / " << j;return st.str();}}} rep(i, 1000) {rep(j, 1000) {if ((mint) i / j == a) {st << i << " / " << j;return st.str();}}} return st.str();}
template<typename T> std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {stream << number();
#ifdef _DEBUG
// stream << " -> " << yuri(number);
#endif
return stream;
}
//@formatter:off
template<typename T> std::istream &operator>>(std::istream &stream, Modular<T> &number) { typename common_type<typename Modular<T>::Type, int64_t>::type x; stream >> x; number.value = Modular<T>::normalize(x); return stream;}
using PM = pair<mint, mint>;
using vm = vector<mint>;
using mapm = map<int, mint>;
using umapm = umap<int, mint>;
#define vvm(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(mint,__VA_ARGS__)
#define vnm(name, ...) auto name = make_v<mint>(__VA_ARGS__)
struct setmod{
setmod() {
// p2.resize(mint_len);p2[0] = 1; for (int i = 1; i < mint_len; ++i) p2[i] = p2[i - 1] * 2 % MOD;
fac.resize(mint_len); finv.resize(mint_len); inv.resize(mint_len); inv[1] = fac[0] = finv[0] = 1; for (int i = 2; i < mint_len; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i < mint_len; ++i) fac[i] = fac[i - 1] * i % MOD, finv[i] = finv[i - 1] * inv[i] % MOD;
}
}setmodv;
//@formatter:on
//nhr n個の場所にr個の物を分ける
//@起動時
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;//@formatter:on
//gra mll pr
//上下左右
const string udlr = "udlr";
string UDLR = "UDLR";//x4と連動 UDLR.find('U') := x4[0]
//右、上が正
constexpr ll y4[] = {1, -1, 0, 0};
constexpr ll x4[] = {0, 0, -1, 1};
constexpr ll y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr ll x8[] = {1, 0, -1, 0, 1, -1, 1, -1};
ll n, m, k, d, H, W, x, y, z, q;
ll cou;
vi a, b, c;
//vvi (s, 0, 0);
vvc (ba, 0, 0);
vp p;
str s;
//@formatter:off
template<class T> struct edge { int f, t; T c; int id; int ty; edge(int f, int t, T c = 1, int ty = -1,int id = -1) : f(f), t(t), c(c), id(id), ty(ty) {} bool operator<(const edge &b) const { return c < b.c; } bool operator>(const edge &b) const { return c > b.c; }};
template<class T> ostream &operator<<(ostream &os, edge<T> &e) { os << e.f << " " << e.t << " " << e.c; return os;}
template<typename T> class graph {protected: vector<bool> usedv;public : vector<vector<edge<T>>> g; vector<edge<T>> edges; int n; graph(int n) : n(n) { g.resize(n), usedv.resize(n); } void clear() { g.clear(), edges.clear(); } void resize(int n) { this->n = n; g.resize(n); usedv.resize(n); } int size() { return g.size(); } vector<edge<T> > &operator[](int i) { return g[i]; } virtual void add(int f, int t, T c, int ty ,int id) = 0; virtual bool used(edge<T> &e) = 0; virtual bool used(int id) = 0; virtual void del(edge<T> &e) = 0; virtual void del(int id) = 0; virtual void set_edges() = 0;};
template<typename T =ll> class digraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::usedv;
int eid = 0;
digraph(int n) : graph<T>(n) {}
void add(int f, int t, T c = 1, int ty = -1,int id = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digraph add");
deb(f, t, c, ty,id);
ole();
}
if (id == -1)id = eid++;
g[f].emplace_back(f, t, c, ty,id);
edges.emplace_back(f, t, c, ty,id);
}
bool used(edge<T> &e) { return usedv[e.id]; }
bool used(int id) { return usedv[id]; }
void del(edge<T> &e) { usedv[e.id] = usedv[e.id ^ 1] = 1; }
void del(int id) { usedv[id] = usedv[id ^ 1] = 1; }
void set_edges() { if (sz(edges))return; rep(i, n)fora(e, g[i])edges.push_back(e); }
};
template<class T=int> class undigraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::usedv;
int eid = 0;
undigraph(int n) : graph<T>(n) {}
void add(int f, int t, T c = 1, int ty = -1,int id = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("undigraph add");
deb(f, t, c, ty,id);
ole();
}
if (id == -1)id = eid, eid += 2;
g[f].emplace_back(f, t, c, ty, id);
g[t].emplace_back(t, f, c, ty, id + 1);
edges.emplace_back(f, t, c, ty, id);
edges.emplace_back(t, f, c, ty, id + 1);
}
void add(edge<T> &e) { int f = e.f, t = e.t, ty = e.ty; T c = e.c; add(f, t, c, ty); }
bool used(edge<T> &e) { return usedv[e.id]; }
bool used(int id) { return usedv[id]; }
void del(edge<T> &e) { usedv[e.id] = usedv[e.id ^ 1] = 1; }
void del(int id) { usedv[id] = usedv[id ^ 1] = 1; }
void set_edges() { if (sz(edges))return; rep(i, n)fora(e, g[i])edges.push_back(e); }
};
template<typename T> struct radixheap { vector<pair<u64, T> > v[65]; u64 size, last; radixheap() : size(0), last(0) {} bool empty() const { return size == 0; } int getbit(int a) { return a ? 64 - __builtin_clzll(a) : 0; } void push(u64 key, const T &value) { ++size; v[getbit(key ^ last)].emplace_back(key, value); } pair<u64, T> pop() { if (v[0].empty()) { int idx = 1; while (v[idx].empty()) ++idx; last = min_element(begin(v[idx]), end(v[idx]))->first; for (auto &p : v[idx]) v[getbit(p.first ^ last)].emplace_back(p); v[idx].clear(); } --size; auto ret = v[0].back(); v[0].pop_back(); return ret; }};
//radiq_heap
vi dijkstra2(const graph<int> &g, int s, int cant_arrive = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } int initValue = MAX(int); vi dis(g.n, initValue); radixheap<int> q; dis[s] = 0; q.push(0, s); while (!q.empty()) { int nowc, i; tie(nowc, i) = q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; int c = nowc + e.c; if (dis[to] > c) { dis[to] = c; q.push(dis[to], to); } } } /*基本、たどり着かないなら-1*/ if (cant_arrive == -1)for (auto &&d :dis) if (d == initValue)d = -1; return dis;}
//priority_queue
template<class T> vector<T> dijkstra(const graph<T> &g, int s, int cant_arrive = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } T initValue = MAX(T); vector<T> dis(g.n, initValue); priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; dis[s] = 0; q.emplace(0, s); while (q.size()) { T nowc = q.top().fi; int i = q.top().se; q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; T c = nowc + e.c; if (dis[to] > c) { dis[to] = c; q.emplace(dis[to], to); } } } /*基本、たどり着かないなら-1*/ if (cant_arrive == -1)for (auto &&d :dis) if (d == initValue)d = -1; return dis;}
template<class T> vector<vector<T>> warshall(const graph<T> &g, int cant_arrive = -1) { int n = g.n; vector<vector<T> > dis(n, vector<T>(n, linf)); rep(i, n)fora(e, g.g[i])chmi(dis[e.f][e.t], e.c); rep(i, n)dis[i][i] = 0; rep(k, n)rep(i, n)rep(j, n)chmi(dis[i][j], dis[i][k] + dis[k][j]); /*基本、たどり着かないなら-1*/ if (cant_arrive == -1)rep(i, n)rep(j, n) if (dis[i][j] == linf)dis[i][j] = -1; return dis;}
template<class T>class MinOp {public: T operator()(T a, T b) { return min(a, b); }};
template<typename OpFunc>struct SparseTable{ OpFunc op; signed size; vector<signed> lg; vector<vector<pair<signed,signed>> > table; void init( const vector<pair<signed,signed>> &array, OpFunc opfunc ){ signed n = array.size(); op = opfunc; lg.assign( n + 1 , 0 ); for( signed i = 1; i <= n; i++ ){ lg[i] = 31 - __builtin_clz( i ); } table.assign( lg[n] + 1, array ); for( signed i = 1; i <= lg[n]; i++ ){ for( signed j = 0; j < n; j++ ){ if( j + (1<<(i-1)) < n ){ table[i][j] = op( table[i-1][j] , table[i-1][j+(1<<(i-1))] ); } else { table[i][j] = table[i-1][j]; } } } } pair<signed,signed> query( signed l , signed r ){ assert( l < r ); return op( table[ lg[r-l] ][l], table[ lg[r-l] ][r-(1<<lg[r-l])] ); }};
struct PMORMQ{ vector<signed> a; SparseTable<MinOp<pair<signed,signed> > > sparse_table; vector<vector<vector<signed> > > lookup_table; vector<signed> block_type; signed block_size, n_block; void init( const vector<signed> &array ){ a = array; signed n = a.size(); block_size = std::max( 1, ( 31 - __builtin_clz( n ) ) / 2 ); while( n % block_size != 0 ){ a.push_back( a.back() + 1 ); n++; } n_block = n / block_size; vector<pair<signed,signed> > b( n_block, make_pair( INT_MAX, INT_MAX ) ); for( signed i = 0; i < n; i++ ){ b[i/block_size] = min( b[i/block_size], make_pair( a[i], i ) ); } sparse_table.init( b, MinOp<pair<signed,signed> >() ); block_type.assign( n_block, 0 ); for( signed i = 0; i < n_block; i++ ){ signed cur = 0; for( signed j = 0; j < block_size-1; j++ ){ signed ind = i * block_size + j; if( a[ind] < a[ind+1] ){ cur |= 1 << j; } } block_type[i] = cur; } lookup_table.assign( 1 << (block_size-1), vector<vector<signed> >( block_size, vector<signed>( block_size+1 ) ) ); for( signed i = 0; i < (1<<(block_size-1)); i++ ){ for( signed j = 0; j < block_size; j++ ){ signed res = 0; signed cur = 0; signed pos = j; for( signed k = j+1; k <= block_size; k++ ){ lookup_table[i][j][k] = pos; if( i & ( 1 << (k-1) ) ){ cur++; } else { cur--; } if( res > cur ){ pos = k; res = cur; } } } } } signed query( signed l, signed r ){ assert( l < r ); signed lb = l / block_size; signed rb = r / block_size; if( lb == rb ){ return lb * block_size + lookup_table[ block_type[lb] ][ l % block_size ][ r % block_size ]; } signed pl = lb * block_size + lookup_table[ block_type[lb] ][ l % block_size ][ block_size ]; signed pr = rb * block_size + lookup_table[ block_type[rb] ][0][ r % block_size ]; signed pos = pl; if( r % block_size > 0 && a[pl] > a[pr] ){ pos = pr; } if( lb + 1 == rb ){ return pos; } signed spv = sparse_table.query( lb+1, rb ).second; if( a[pos] > a[spv] ){ return spv; } return pos; }};
template<class T=int> class tree : public undigraph<T> {public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; using undigraph<T>::usedv; PMORMQ rmq; int cnt; vector<int> disv; vector<signed> depth,id, in; int root; bool never=true; tree(int n_, int root = 0) : undigraph<T>(n_), root(root) { n=n_; } void dfs( int x , int p , int d ,int dis =0){ id[cnt] = x; depth.push_back( d ); disv[x]=dis; in[x] = cnt++; forg(gi, g[x]){ if( t == p ){ continue; } dfs( t , x , d+1 ,dis+c); id[cnt] = x; depth.push_back( d ); cnt++; } } void precalc( ){ never = false; cnt = 0; depth.clear(); disv.assign(n,0); in.assign( n, -1 ); id.assign( 2*n-1, -1 ); dfs( root, -1, 0 ); rmq.init( depth ); } int lca( int a , int b ){ if(never)precalc(); int x = in[a]; int y = in[b]; if( x > y ){ swap( x , y ); } int pos = rmq.query( x, y + 1 ); return id[pos]; } int dis( int a , int b ){ if(never)precalc(); int x = in[a]; int y = in[b]; if( x > y ){ swap( x , y ); } int pos = rmq.query( x, y + 1 ); int p= id[pos]; return disv[a]+disv[b]-disv[p]*2; }};
//
//辺によりメモリを大量消費
// よってedgesを消している
//頂点10^6でメモリを190MB(制限の8割)使う
template<class T=int> class grid_k6 : public undigraph<T> {public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; using undigraph<T>::usedv; int H, W; int eid = 0; void add(int f, int t, T c = 1, int ty = -1,int id = -1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("grid_k6 add"); deb(f, t, c, ty,id); ole(); } g[f].emplace_back(f, t, c, ty,eid++); g[t].emplace_back(t, f, c, ty,eid++); } int getid(int h, int w) { if (!ins(h, w, H, W))return -1; return W * h + w; } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } grid_k6(int H, int W) : H(H), W(W), undigraph<T>(H * W) { rep(h, H) { rep(w, W) { int f = getid(h, w); if (w + 1 < W) add(f, getid(h, w + 1)); if (h + 1 < H)add(f, getid(h + 1, w)); } } } grid_k6(vector<vector<char>> ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } void add(int fh, int fw, int th, int tw) { add(getid(fh, fw), getid(th, tw)); } void set_edges() { rep(i, n)fora(e, g[i])edges.push_back(e); }};
//左上から右下に移動できる
template<class T=int> class digrid_k6 : public digraph<T> {public: using digraph<T>::g; using digraph<T>::n; using digraph<T>::edges; using digraph<T>::usedv; int H, W; int eid = 0; void add(int f, int t, T c = 1, int ty = -1,int id = -1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("digrid_k6 add"); deb(f, t, c, ty,id); ole(); } g[f].emplace_back(f, t, c, ty, eid++); } int getid(int h, int w) { if (!ins(h, w, H, W))return -1; return W * h + w; } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } digrid_k6(int H, int W) : H(H), W(W), digraph<T>(H * W) { rep(h, H) { rep(w, W) { int f = getid(h, w); if (w + 1 < W) add(f, getid(h, w + 1)); if (h + 1 < H)add(f, getid(h + 1, w)); } } } digrid_k6(vector<vector<char>> ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), digraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } void add(int fh, int fw, int th, int tw) { add(getid(fh, fw), getid(th, tw)); } void set_edges() { rep(i, n)fora(e, g[i])edges.push_back(e); }};
template<class T> bool nibu(const graph<T> &g) { int size = 0; rep(i, g.n)size += sz(g.g[i]); if (size == 0)return true; unionfind uf(g.n * 2); rep(i, g.n)fora(e, g.g[i])uf.unite(e.f, e.t + g.n), uf.unite(e.f + g.n, e.t); rep(i, g.n)if (uf.same(i, i + g.n))return 0; return 1;}
//二部グラフを色分けした際の頂点数を返す
template<class T> vp nibug(graph<T> &g) { vp cg; if (!nibu(g)) { debugline("nibu"); ole(); } int n = g.size(); vb was(n); queue<P> q; rep(i, n) { if (was[i])continue; q.push(mp(i, 1)); was[i] = 1; int red = 0; int coun = 0; while (q.size()) { int now = q.front().fi; int col = q.front().se; red += col; coun++; q.pop(); forg(gi, g[now]) { if (was[t])continue; q.push(mp(t, col ^ 1)); was[t] = 1; } } cg.push_back(mp(red, coun - red)); } return cg;}
template<class T> ostream &operator<<(ostream &os, graph<T> &g) { rep(i, sz(g)) { forg(gi, g[i]) { os << f << " " << t << " " << c << endl; } } return os;}
//閉路がなければtrue
bool topo(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; queue<int> st; rep(i, n)if (nyu[i] == 0)st.push(i); while (st.size()) { int v = st.front(); st.pop(); res.push_back(v); fora(e, g[v]) if (--nyu[e.t] == 0)st.push(e.t); } return res.size() == n;}
//辞書順最小トポロジカルソート
bool topos(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; /*小さい順*/ priority_queue<int, vector<int>, greater<int> > q; rep(i, n)if (nyu[i] == 0)q.push(i); while (q.size()) { int i = q.top(); q.pop(); res.push_back(i); fora(e, g[i])if (--nyu[e.t] == 0)q.push(e.t); } return res.size() == n;}
//連結グラフが与えられる 閉路があるか
template<class T> bool close(undigraph<T> &g) { int n = 0; int e = 0; rep(i, g.n) { if (sz(g[i]))n++; forg(gi, g[i]) { e++; } } return (e >> 1) >= n;}
template<class T> bool close(undigraph<T> &g, int v) { unionfind uf(g.n); rep(i, g.n) { forg(gi, g[i]) { if (f < t)break; if (f == t && f == v)return true; if (uf.same(f, v) && uf.same(t, v))return true; uf.unite(f, t); } } return false;}
template<class T> bool close(digraph<T> &g) {vi res;return topo(res, g);}
template<class T> vi indegree(graph<T> &g) { vi ret(g.size()); rep(i, g.size()) { forg(gi, g[i]) { ret[t]++; } } return ret;}
template<class T> vi outdegree(graph<T> &g) { vi ret(g.size()); rep(i, g.size()) { ret[i] = g[i].size(); } return ret;}
template<class T> digraph<T> rev(digraph<T> &g) { digraph<T> r(g.n); rep(i, g.n) { forg(gi, g[i]) { r.add(t, f, c); } } return r;}
//橋を列挙する (取り除くと連結でなくなる辺)
template<class T> vp bridge(graph<T> &G) { static bool was; vp brid; vi articulation; vi ord(G.n), low(G.n); vb vis(G.n); function<void(int, int, int)> dfs = [&](int v, int p, int k) { vis[v] = true; ord[v] = k++; low[v] = ord[v]; bool isArticulation = false; int ct = 0; for (int i = 0; i < G[v].size(); i++) { if (!vis[G[v][i].t]) { ct++; dfs(G[v][i].t, v, k); low[v] = min(low[v], low[G[v][i].t]); if (~p && ord[v] <= low[G[v][i].t]) isArticulation = true; if (ord[v] < low[G[v][i].t]) brid.push_back(make_pair(min(v, G[v][i].t), max(v, G[v][i].t))); } else if (G[v][i].t != p) { low[v] = min(low[v], ord[G[v][i].t]); } } if (p == -1 && ct > 1) isArticulation = true; if (isArticulation) articulation.push_back(v); }; int k = 0; rep(i, n) { if (!vis[i]) dfs(i, -1, k); } sort(brid.begin(), brid.end()); return brid;}
//間接点を列挙する (取り除くと連結でなくなる点)
template<class T> vi articulation(undigraph<T> &G) { static bool was; vp bridge; vi arti; vi ord(G.n), low(G.n); vb vis(G.n); function<void(int, int, int)> dfs = [&](int v, int p, int k) { vis[v] = true; ord[v] = k++; low[v] = ord[v]; bool isArticulation = false; int ct = 0; for (int i = 0; i < G[v].size(); i++) { if (!vis[G[v][i].t]) { ct++; dfs(G[v][i].t, v, k); low[v] = min(low[v], low[G[v][i].t]); if (~p && ord[v] <= low[G[v][i].t]) isArticulation = true; if (ord[v] < low[G[v][i].t]) bridge.push_back(make_pair(min(v, G[v][i].t), max(v, G[v][i].t))); } else if (G[v][i].t != p) { low[v] = min(low[v], ord[G[v][i].t]); } } if (p == -1 && ct > 1) isArticulation = true; if (isArticulation) arti.push_back(v); }; int k = 0; rep(i, n) { if (!vis[i]) dfs(i, -1, k); } sort(arti.begin(), arti.end()); return arti;}
#define kansetu articulation
P farthest(undigraph<> &E, int cur, int pre, int d, vi &D) {D[cur] = d;P r = {d, cur};forg(gi, E[cur]) if (t != pre) {P v = farthest(E, t, cur, d + 1, D);r = max(r, v);}return r;}
vi diameter(undigraph<> &E) { /* diameter,center*/vi D[3];D[0].resize(E.size());D[1].resize(E.size());auto v1 = farthest(E, 0, 0, 0, D[0]);auto v2 = farthest(E, v1.second, v1.second, 0, D[0]);farthest(E, v2.second, v2.second, 0, D[1]);int i;rep(i, D[0].size()) D[2].push_back(max(D[0][i], D[1][i]));return D[2];}
//i d
vp diameter_p(undigraph<> &E) { /* diameter,center*/vector<int> D[3];D[0].resize(E.size());D[1].resize(E.size());auto v1 = farthest(E, 0, 0, 0, D[0]);auto v2 = farthest(E, v1.second, v1.second, 0, D[0]);farthest(E, v2.second, v2.second, 0, D[1]);int i;vp res(E.size());rep(i, D[0].size()) {if (D[0][i] > D[1][i])res[i] = mp(D[0][i], v1.second);else res[i] = mp(D[1][i], v2.second);}return res;}
digraph<> rang_di(int n, int m, bool zibun = 0, bool taju = 0) { umapp was; digraph<> g(n); was[mp(-1, -2)] = 1; while (m) { int f = -1, t = -2; while (f < 0 || (!taju && was[mp(f, t)])) { f = rand(0, n - 1); t = rand(0, n - 1); if (!zibun && f == t)f = -1; } g.add(f, t); was[mp(f, t)] = 1; m--; } return g;}
digraph<> rang_di_perfect(int n, bool zibun = 0) { digraph<> g(n); rep(i, n) { rep(j, n) { if (!zibun && i == j)con; g.add(i, j); } } return g;}
undigraph<> rang_un(int n, int m, bool zibun = 0, bool taju = 0) { umapp was; undigraph<> g(n); was[mp(-1, -2)] = 1; while (m) { int f = -1, t = -2; while (f < 0 || (!taju && was[mp(min(f, t), max(f, t))])) { f = rand(0, n - 1); t = rand(0, n - 1); if (!zibun && f == t)f = -1; } g.add(f, t); was[mp(min(f, t), max(f, t))] = 1; m--; } return g;}
undigraph<> rang_un_perfect(int n, bool zibun = 0) { undigraph<> g(n); rep(i, n) { rep(j, i, n) { if (!zibun && i == j)con; g.add(i, j); } } return g;}
//閉路が1つしかない場合、その閉路に含まれる頂点を1としたvectorを返す
template<class T> vi get_close1(digraph<T> &g) { int n = g.n; queue<int> q; vi d = outdegree(g); vi res(n, 1); rep(i, n) { if (d[i] == 0) { q += i; res[i] = 0; } } auto rg = rev(g); while (q.size()) { auto now = q.front(); q.pop(); forg(gi, rg[now]) { if (--d[t] == 0) { q += t; res[t] = 0; } } } return res;};/*@formatter:on*/
digraph<> g(2 * k5);
vi clo;
vi deg;
seti ss[k5 * 2];
vi gv(k5 * 2, -1);
vi mem(k5*2,-1);
int ds(int p, int i) {
// if(mem[i]!=-1)return mem[i];
forg(gi, g[i])if(clo[t]==0)ss[i] += ds(i, t);
rep(v, inf) {
if (ss[i].count(v) == 0) {
if (clo[i] == 0)gv[i] = v;
return v;
}
}
return 0;
}
digraph<> rg(0);
vi r(k5 * 2);
bool ds2(int p, int i, int nex) {
int v;
rep(j, inf) {
if (ss[i].count(j) == 0 && nex != j) {
v = j;
break;
}
}
if (gv[i] != -1) {
bool ok = v == gv[i];
if (ok)outv(gv);
return ok;
} else {
gv[i] = v;
return ds2(r[p], p, v);
}
}
void solve() {
in(n);
rep(i, n) {
g.add(in() - 1, i);
}
clo = get_close1(g);
deg = outdegree(g);
rep(i, n) {
if (clo[i])ds(-1, i);
}
rg = rev(g);
rep(i, n)forg(gi, rg[i]) {
if (clo[t])r[i] = t;
}
rep(i, n) {
if (clo[i]) {
int m = 2;
int pgv = 0;
rep(v, inf) {
if (m == 0)break;
if (ss[i].count(v) == 0) {
rep(i, n) if (clo[i])gv[i] = -1;
if (m == 2) {
gv[i] = v;
if (ds2(r[r[i]], r[i], v)) {
POSSIBLE(1);
}
pgv = v;
} else {
int to = 0;
forg(gi, g[i])if (clo[t])to = t;
gv[to] = pgv;
gv[i] = v;
POSSIBLE(ds2(r[r[i]], r[i], v));
}
m--;
}
}
}
}
POSSIBLE(0);
}
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) {
// cout << "完璧 : solveを書き直そう" << endl;
// cout << " : そして、solve()を呼び出すのだ" << endl;
// cout << " : cin>>n; na(a,n);も忘れるな" << endl;
}
#endif
return 0;
};
| a.cc: In function 'bool ds2(long long int, long long int, long long int)':
a.cc:896:20: error: no matching function for call to 'outv(vi&)'
896 | if (ok)outv(gv);
| ~~~~^~~~
a.cc:298:24: note: candidate: 'template<class T> void outv(std::vector<_Tp>&, long long int)'
298 | template<class T> void outv(vector<T> &a, ll W) {;}
| ^~~~
a.cc:298:24: note: candidate expects 2 arguments, 1 provided
a.cc:299:24: note: candidate: 'template<class T> void outv(std::vector<std::vector<_Tp> >&, long long int, long long int, long long int)'
299 | template<class T> void outv(vector<vector<T> > &a, ll H = linf, ll W = linf,int key=-1) {;}
| ^~~~
a.cc:299:24: note: template argument deduction/substitution failed:
a.cc:896:20: note: mismatched types 'std::vector<_Tp>' and 'long long int'
896 | if (ok)outv(gv);
| ~~~~^~~~
a.cc:300:24: note: candidate: 'template<class T> void outv(std::vector<std::vector<std::vector<_Tp> > >&, long long int, long long int, long long int)'
300 | template<class T> void outv(vector<vector<vector<T> > > &a, ll H = linf, ll W = linf,ll U = linf) {;}
| ^~~~
a.cc:300:24: note: template argument deduction/substitution failed:
a.cc:896:20: note: mismatched types 'std::vector<std::vector<_Tp> >' and 'long long int'
896 | if (ok)outv(gv);
| ~~~~^~~~
|
s840076620 | p03650 | C++ | //#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
#define int long long
#define ll long long
auto start_time = system_clock::now();
//@formatter:off
#ifdef _DEBUG
//区間削除は出来ない
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>
#else
#define unordered_map __gnu_pbds::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>
#endif
struct xorshift { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(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()(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 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); }
//衝突対策
#define ws wszzzz
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);}
//@マクロ省略系 型,構造
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo= bool;
#define au auto
using P = pair<ll, ll>;
using pd =pair<dou, dou>;
#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 wh while
#define upd update
#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 lam(right) [&](ll& p){return p right;}
//マクロ省略系 コンテナ
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 o_vvt(o1, o2, o3, o4, name, ...) name
#define vvt0(t) V<V<t>>
#define vvt1(t,a) V<V<t>>a
#define vvt2(t,a, b) V<V<t>>a(b)
#define vvt3(t,a, b, c) V<V<t>> a(b,V<t>(c))
#define vvt4(t,a, b, c, d) V<V<t>> a(b,V<t>(c,d))
#define vvi(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__)
#define vvb(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__)
#define vvs(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__)
#define vvd(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__)
#define vvc(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__)
#define vvp(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__)
#define vvt(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(T,__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 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 setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<ll>;
#define bset bitset
#define uset unordered_set
#define useti unordered_set<ll,ll,xorshift>
#define mset multiset
#define mseti multiset<ll>
#define umap unordered_map
#define umapi unordered_map<ll,ll,xorshift>
#define umapp unordered_map<P,ll,xorshift>
#define mmap multimap
template<class T> struct pq { priority_queue<T, vector<T>, greater<T> > q;/*小さい順*/ T su = 0; 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> struct pqg { priority_queue<T> q;/*大きい順*/ T su = 0; void clear() {q = priority_queue<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();}};
#define pqi pq<ll>
#define pqgi pqg<ll>
//マクロ 繰り返し
#define o_rep(o1, o2, o3, o4, name, ...) name
# 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 rep(...) o_rep(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#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)
#define rer(...) o_rep(__VA_ARGS__,rer4,rer3,rer2,)(__VA_ARGS__)
#define reps2(i, j, n) for(ll i = 0,reps2lim=n; i < reps2lim ;++i)for(ll j = 0; j < reps2lim ; ++j)
#define reps3(i, j, k, n) for(ll i = 0,reps3lim=n; i < reps3lim ; ++i)for(ll j = 0; j < reps3lim ; ++j)for(ll k = 0; k < reps3lim ; ++k)
#define reps4(i, j, k, l, n) for(ll i = 0,reps4lim=n; i < reps4lim ; ++i)for(ll j = 0; j < reps4lim ; ++j)for(ll k = 0; k < reps4lim ; ++k)for(ll l = 0; l < reps4lim ; ++l)
#define o_reps(o1, o2, o3, o4, o5, name, ...) name
#define reps(...) o_reps(__VA_ARGS__,reps4,reps3,reps2,rep2,)(__VA_ARGS__)
#define repss(i, j, k, a, b, c) for(ll i = 0; i < a ; ++i)for(ll j = 0; j < b ; ++j)for(ll k = 0; k < c ; ++k)
#define fora(a, b) for(auto&& a : b)
#define forg(gi, ve) for (ll gi = 0,forglim = ve.size(), f, t, c; gi < forglim && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi)
#define fort(gi, ve) for (ll gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi)if(t!=p)
#define form(st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it).fi < r; ++it)
#define forit(st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it) < r;)
//マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const ll inf = (ll) 1e9 + 100;
const ll linf = (ll) 1e18 + 100;
const char infc = '{';
const string infs = "{";
const double eps = 1e-9;
const double PI = 3.1415926535897932384626433832795029L;
ll ma = numeric_limits<ll>::min();
ll mi = numeric_limits<ll>::max();
//マクロ省略形 関数等
#define arsz(a) (sizeof(a)/sizeof(a[0]))
#define sz(a) ((ll)(a).size())
#define mp make_pair
#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()
constexpr bool ev(ll a) { return !(a & 1); }
constexpr bool od(ll a) { return (a & 1); }
//@拡張系 こう出来るべきというもの
//埋め込み 存在を意識せずに機能を増やされているもの
//@formatter:on
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); }};
}
//@formatter:off
//stream まとめ
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 << endl; 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) { for (auto &&v:m) os << v; return os;}
template<typename W, typename H> void resize(vector<W> &vec, const H head) { vec.resize(head); }template<typename W, typename H, typename ... T> void resize(vector<W> &vec, const H &head, const T ... tail) {vec.resize(head);for (auto &v: vec)resize(v, tail...);}
template<typename T, typename F> bool all_of2(T &v, F f) { return f(v); }
template<typename T, typename F> bool all_of2(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(T &v, F f) { return f(v); }
template<typename T, typename F> bool any_of2(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(T &v, F f) { return f(v); }
template<typename T, typename F> bool none_of2(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(T &v, F f) { return f(v); }
template<typename T, typename F> ll find_if2(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(T &v, F f) { return f(v); }
template<typename T, typename F> ll rfind_if2(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(string &s, const T &v) { return s.find(v) != string::npos; }
template<typename T> bool contains(vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); }
template<typename T, typename F> bool contains_if2(vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); }
template<typename T, typename F> ll count_if2(T &v, F f) { return f(v); }
template<typename T, typename F> ll count_if2(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 &v, F f) { f(v); }
template<typename T, typename F> void for_each2(vector<T> &vec, F f) { fora(v, vec)for_each2(v, f); }
template<typename W> ll count_od(vector<W> &a) {return count_if2(a,[](ll v){return v&1 ;});}
template<typename W> ll count_ev(vector<W> &a) {return count_if2(a,[](ll v){return !(v&1) ;});}
#define all_of(a,right) all_of2(a,lam(right))
#define any_of(a,right) any_of2(a,lam(right))
#define none_of(a,right) none_of2(a,lam(right))
#define find_if(a,right) find_if2(a,lam(right))
#define rfind_if(a,right) rfind_if2(a,lam(right))
#define contains_if(a,right) contains_if2(a,lam(right))
#define count_if(a, right) count_if2(a,lam(right))
#define for_each(a, right) do{fora(v,a){v right;}}while(0)
template<class T, class U> void replace(vector<T> &a, T key, U v) { replace(a.begin(), a.end(), 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; }
template<class T> void replace(T &a) { replace(a, '#'); }
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 includes(vector<T> &a, vector<T> &b) {vi c = a;vi d = b;sort(all(c));sort(all(d));return includes(all(c), all(d));}
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)); }
void iota(vector<ll> &ve, ll s, ll n) {ve.resize(n);iota(all(ve), s);}
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;}
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; });}
void sort(string &a) { sort(all(a)); }
template<class T> void sort(vector<T> &a) { sort(all(a)); }
//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 T> void rsort(vector<T> &a) { sort(all(a), greater<T>()); };
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> 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, 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> 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 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> 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, 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> 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 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;}
//sortindex 元のvectorはソートしない
template<class T> vi sorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind); return ind;}/*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]); }
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<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<vector<W>> &xx,const T v,ll lh,ll lw) {rep(i, lh)rep(j,lw)xx[i][j]=v;}
template<class T,class U>void fill(vector<T> &a,U val,vi& ind) {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;}
//@汎用便利関数 入力
ll in() {ll 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...);}
#define o_din(o1, o2, o3, o4, o5, o6, name, ...) name
#define din1(a) ll a;cin>>a
#define din2(a, b) ll a,b;cin>>a>> b
#define din3(a, b, c) ll a,b,c;cin>>a>>b>>c
#define din4(a, b, c, d) ll a,b,c,d;cin>>a>>b>>c>>d
#define din5(a, b, c, d, e) ll a,b,c,d,e;cin>>a>>b>>c>>d>>e
#define din6(a, b, c, d, e, f) ll a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f
#define din(...) o_din(__VA_ARGS__,din6,din5,din4,din3,din2 ,din1)(__VA_ARGS__)
#define o_dind(o1, o2, o3, o4, name, ...) name
#define din1d(a) din1(a);a--
#define din2d(a, b) din2(a,b);a--,b--
#define din3d(a, b, c) din3(a,b,c);a--,b--,c--
#define din4d(a, b, c, d) din4(a,b,c,d);a--,b--,c--,d--
#define dind(...) o_dind(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__)
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;}
#ifdef _DEBUG
template<class T> void outv(vector<T> &a, ll W = inf) { if (W == inf)W = min(sz(a), 12ll); rep(i, W) { cerr << i << " "; } cerr << "" << endl; rep(i, W) { cerr << a[i] << " "; } cerr << "" << endl;};
template<class T> void outv(vector<vector<T> > &a, ll H = inf, ll W = inf,int key=-1) { H = min({H, sz(a), 12ll}); W = min({W, sz(a[0]), 12ll}); if(key==-1)cerr << "*|";else cerr<<key<<"|"; rep(w, W)cerr << std::right << std::setw(4) << w; cerr << "" << endl; rep(w, W * 4 + 2)cerr << "_"; cerr << "" << endl; rep(h, H) { cerr << h << "|"; rep(w, W) { if (a[h][w] == linf) cerr << " e" << " "; else cerr << std::right << std::setw(4) << a[h][w]; } cerr << "" << endl; }}
template<class T> void outv(vector<vector<vector<T> > > &a, ll H = inf, ll W = inf,ll U =inf) {rep(i,min({H,5ll,sz(a)})){outv(a[i],W,U,i);cerr<<""<<endl;}}
#else
template<class T> void outv(vector<T> &a, ll W) {;}
template<class T> void outv(vector<vector<T> > &a, ll H = linf, ll W = linf,int key=-1) {;}
template<class T> void outv(vector<vector<vector<T> > > &a, ll H = linf, ll W = linf,ll U = linf) {;}
#endif
template<class T> void outl(vector<T> &a) { fora(v, a)cout << v << endl; }
template<class T> void na(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i];}
#define dna(a, n) vi a(n); rep(dnai,n) cin >> a[dnai];
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, 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];}
#define dna2(a, b, n) vi a(n),b(n);rep(dna2i, n)cin >> a[dna2i] >> b[dna2i];
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];}
#define dna2d(a, b, n) vi a(n),b(n);rep(dna2di, n){cin >> a[dna2di] >> b[dna2di];a[dna2di]--,b[dna2di]--;}
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]--;}
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(n),b(n),c(n); rep(dna3i, n)cin >> a[dna3i] >> b[dna3i] >> c[dna3i];
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(n),b(n),c(n); rep(dna3di, n){cin >> a[dna3di] >> b[dna3di] >> c[dna3di];a[dna3di]--,b[dna3di]--,c[dna3di]--;}
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(n),b(n),c(n),d(n); rep(dna4i, n)cin >> a[dna4i] >> b[dna4i] >> c[dna4i]>>d[dna4i];
#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 sp << " " <<
#define debugName(VariableName) # VariableName
#define deb1(x) debugName(x)<<" = "<<x
#define deb2(x, ...) deb1(x) <<", "<< deb1(__VA_ARGS__)
#define deb3(x, ...) deb1(x) <<", "<< deb2(__VA_ARGS__)
#define deb4(x, ...) deb1(x) <<", "<< deb3(__VA_ARGS__)
#define deb5(x, ...) deb1(x) <<", "<< deb4(__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__)
#define o_ebug(o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, name, ...) name
#ifdef _DEBUG
#define deb(...) cerr<< o_ebug(__VA_ARGS__,deb10,deb9,deb8,deb7,deb6,deb5,deb4,deb3,deb2,deb1)(__VA_ARGS__) <<endl
#else
#define deb(...) ;
#endif
#define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'
//@formatter:off
//よく使うクラス、構造体
struct unionfind {
vector<ll> par;
vector<ll> siz;
vector<ll> es;
ll n, trees;//連結グループの数(親の種類)
unionfind(ll n) : n(n), trees(n) { par.resize(n); siz.resize(n); es.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } }
ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); }}
bool unite(ll x, ll y) {
x = root(x);
y = root(y);
es[x]++;
if (x == y) return false;
if (siz[x] > siz[y]) swap(x, y);
trees--;
par[x] = y;
siz[y] += siz[x];
es[y] += es[x];
return true;
}
bool same(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return siz[root(x)]; }
ll esize(ll x) { return es[root(x)]; }
vi sizes(){ vi cou(n); vi ret; ret.reserve(n); rep(i, n){ cou[root (i)]++; } rep(i, n){ if(cou[i])ret.push_back(cou[i]); } return ret; }
//つながりを無向グラフと見なし、xが閉路に含まれるか判定
bool close(ll x) { return esize(x) >= size(x); }
V<vi> sets() { vi ind(n, -1); ll i = 0; vvi(res, trees); rep(j, n) { ll r = root(j); if (ind[r] == -1)ind[r] = i++; res[ind[r]].push_back(j); } rep(i, trees) { ll r = root(res[i][0]); if (res[i][0] == r)continue; rep(j, 1, sz(res[i])) { if (res[i][j] == r) { swap(res[i][0], res[i][j]); break; } } } return res; }
};//@formatter:off
using bll =__int128;
using u32 = unsigned;
using u64 = unsigned long long;
using u128 = __uint128_t;
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 toi128(string &s) { __int128 ret = 0; for (ll i = 0; i < s.length(); ++i) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret;}
//エラー
void ole() {
#ifdef _DEBUG
debugline("ole"); 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() { assert(0 == 1); exit(0);}
void tle() { while (inf)cout << inf << endl; }
//便利関数
//テスト用
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); }}}
vi ranv(ll n, ll min, ll max) { vi v(n); rep(i, n)v[i] = rand(min, max); return v;}
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;}
//便利 汎用
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]); }}
vp run_length(vi &a) { vp 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;}
vector<pair<char, ll>> run_length(string &a) { vector<pair<char, ll>> 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;}
template<class F> ll mgr(ll ok, ll ng, F f) { if (ok < ng) while (ng - ok > 1) { ll mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } else while (ok - ng > 1) { ll mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } return ok;}
//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;}
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);}
template<typename W, typename U> T 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 mt(i, j, k); return mt(-1, -1, -1);}
template<typename W, typename T> ll count2(W &a, const T k) { return a == k; }
template<typename W, typename T> ll count2(vector<W> &a, const T k) { ll ret = 0; fora(v, a)ret += count2(v, k); return ret;}
template<typename W, typename T> ll count(vector<W> &a, const T k) { ll ret = 0; fora(v, a)ret += count2(v, k); return ret;}
ll count(str &a, 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;}
vi count(str &a) { vi cou(26); char c = 'a'; if ('A' <= a[0] && a[0] <= 'Z')c = 'A'; rep(i, sz(a))++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> void rev(vector<T> &a) { reverse(all(a)); }
template<class U> void 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]; a = b;}
void rev(string &a) { reverse(all(a)); }
constexpr ll p10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000ll, 100000000000ll, 1000000000000ll, 10000000000000ll, 100000000000000ll, 1000000000000000ll, 10000000000000000ll, 100000000000000000ll, 1000000000000000000ll};
ll get(ll a, ll keta) { return (a / (ll) pow(10, keta)) % 10; }
ll keta(ll v) { if (v < p10[9]) { if (v < p10[4]) { if (v < p10[2]) { if (v < p10[1]) 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 if (v < p10[15])return 15; else return 16; } else { if (v < p10[17])return 17; else return 18; }}}}
ll dsum(ll v,ll sin=10) { ll ret = 0; for (; v; v /= sin)ret += v % sin; return ret;}
struct sint {
ll v;
sint(ll v) : v(v) {}
operator ll() { return v; }
//下からi番目
ll operator[](ll i) { return (v / p10[i]) % 10; }
ll back(ll i) { return operator[](i); }
//上からi番目
ll top(ll i) {
ll len = keta(v);
return operator[](len - 1 - i);
}
//先頭からi番目にセット
ll settop(ll i, ll k) {
ll len = keta(v);
return set(len - 1 - i, k);
}
ll set(ll i, ll k) {
if (i < 0)return settop(abs(i) - 1, k);
return v += p10[i] * (k - (v / p10[i]) % 10);
}
ll add(ll i, ll k = 1) { return v += p10[i] * k; }
ll addtop(ll i, ll k = 1) { return v += p10[keta(v) - i - 1] * k; }
ll dec(ll i, ll k = 1) { return v -= p10[i] * k; }
ll dectop(ll i, ll k = 1) { return v -= p10[keta(v) - i - 1] * k; }
#define op(t, o)template<class T> t operator o(T r){return v o r;}
op(ll, +=); op(ll, -=); op(ll, *=); op(ll, /=); op(ll, %=); op(ll, +); op(ll, -); op(ll, *); op(ll, /); op(ll, %); op(bool, ==); op(bool, !=); op(bool, <); op(bool, <=); op(bool, >); op(bool, >=);
#undef op
template<class T> ll operator<<=(T r) { return v *= p10[r]; }
template<class T> ll operator<<(T r) { return v * p10[r]; }
template<class T> ll operator>>=(T r) { return v /= p10[r]; }
template<class T> ll operator>>(T r) { return v / p10[r]; }
};
ll mask10(ll v) { return p10[v] - 1; }
//変換系
template<class T> auto keys(T a) { vector<decltype((a.begin())->fi)> res; for (auto &&k :a)res.push_back(k.fi); return res;}
template<class T> auto values(T a) { vector<decltype((a.begin())->se)> res; for (auto &&k :a)res.push_back(k.se); return res;}
template<class T, class U> bool chma(T &a, const U &b) { if (a < b) { a = b; return true; } return false;}
template<class U> bool chma(const U &b) { return chma(ma, b); }
template<class T, class U> bool chmi(T &a, const U &b) { if (b < a) { a = b; return true; } return false;}
template<class U> bool chmi(const U &b) { return chmi(mi, b); }
template<class T> T min(T a, signed b) { return a < b ? a : b; }
template<class T> T max(T a, signed b) { return a < b ? b : a; }
template<class T> T min(T a, T b, T c) { return a >= b ? b >= c ? c : b : a >= c ? c : a; }
template<class T> T max(T a, T b, T c) { return a <= b ? b <= c ? c : b : a <= c ? c : a; }
template<class T> T min(vector<T>& a) { return *min_element(all(a)); }
template<class T> T mini(vector<T>& a) { return min_element(all(a)) - a.begin(); }
template<class T> T min(vector<T>& a, ll n) { return *min_element(a.begin(), a.begin() + min(n, sz(a))); }
template<class T> T min(vector<T>& a, ll s, ll n) { return *min_element(a.begin() + s, a.begin() + min(n, sz(a))); }
template<class T> T max(vector<T>& a) { return *max_element(all(a)); }
template<class T,class U> T max(vector<T>& a,vector<U>& b) { return max(*max_element(all(a)),*max_element(all(b))); }
template<class T> T maxi(vector<T>& a) { return max_element(all(a)) - a.begin(); }
template<class T> T max(vector<T>& a, ll n) { return *max_element(a.begin(), a.begin() + min(n, sz(a))); }
template<class T> T max(vector<T>& a, ll s, ll n) { return *max_element(a.begin() + s, a.begin() + min(n, sz(a))); }
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, max(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;}
template<class T> T sum(vector<T> &v, ll s = 0, ll t = inf) { T ret = 0; rep(i, s, min(sz(v), t))ret += v[i]; return ret;}template<class T> T sum(vector<vector<T> > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> T sum(vector<vector<vector<T> > > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> T sum(vector<vector<vector<vector<T> > > > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> T sum(vector<vector<vector<vector<vector<T> > > > > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> auto sum(priority_queue<T, vector<T>, greater<T> > &r) { auto q = r; T ret = 0; while (sz(q)) { ret += q.top(); q.pop(); } return ret;}template<class T> auto sum(priority_queue<T> &r) { auto q = r; T ret = 0; while (sz(q)) { ret += q.top(); q.pop(); } 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;}
void clear(PQ &q) { q = PQ(); }
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;}
//imoは0-indexed
//ruiは1-indexed
template<class T> vector<T> imo(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret;}
//kと同じものの数
template<class T, class U> vi imo(vector<T> &a, U k) {vector<T> ret = a;rep(i, sz(ret))ret[i] = a[i] == k;rep(i, sz(ret) - 1)ret[i + 1] += ret[i];return ret;}
template<class T> vector<T> imox(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(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chmi(ret[i + 1], ret[i]); return ret;}
template<class T> struct ruiC { const vector<T> rui; ruiC(vector<T> &ru) : rui(ru) {} T operator()(ll l, ll r) { if (l > r) { cerr<<"ruic ";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> struct rruic { const T *rrui; rruic(T *ru) : rrui(ru) {} T operator()(ll l, ll r) { assert(l >= r); return rrui[r] - rrui[l]; } T operator[](ll i) { return rrui[i]; }};
template<class T> vector<T> ruiv(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(vector<T> &a) { vector<T> ret = ruiv(a); return ruiC<T>(ret);}
vector<ll> ruiv(string &a) { if (sz(a) == 0)return vi(1); ll dec = ('0' <= a[0] && a[0] <= '9') ? '0' : 0; vector<ll> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i] - dec; return ret;}
ruiC<ll> ruic(string &a) { vector<ll> ret = ruiv(a); return ruiC<ll>(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);}
//xor
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> 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> rruic<T> rrui(vector<T> &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; rer(i, len - 1)res[i - 1] = res[i] + a[i]; return rruic<T>(res);}
//掛け算
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> void inc(T &a, U v = 1) { a += v; }
template<class T, class U> 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> 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> void dec(vector<T> &a) { for (auto &u :a)dec(u, 1); }
template<class T,class U> void dec(vector<T> &a,vector<U> &b) { for (auto &u :a)dec(u, 1);for (auto &u :b)dec(u, 1); }
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 ins(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 ins(0, i, sz(a)) && ins(0, j, sz(a)); }
ll u(ll a) { return a < 0 ? 0 : a; }
template<class T> vector<T> u(const vector<T> &a) { vector<T> ret = a; fora(v, ret)v = u(v); return ret;}
#define MIN(a) numeric_limits<a>::min()
#define MAX(a) numeric_limits<a>::max()
template<class F> ll 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 resIndex;}
template<class F> ll 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 resIndex;}
/*loopは200にすればおそらく大丈夫 余裕なら300に*/
template<class F> dou goldd_d(dou left, dou right, F calc, ll loop = 140) { 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 left;}
template<class F> dou goldt_d(dou left, dou right, F calc, ll loop = 140) { 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 left;}
//l ~ rを複数の区間に分割し、極致を与えるiを返す time-20 msまで探索
template<class F> ll 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 mini;}
template<class F> ll 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 maxi;}
template<class F> dou 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 mini;}
template<class F> dou 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 maxi;}
template<class T> T min(vector<vector<T >> &a) { T res = MAX(T); rep(i, a.size())chmi(res, *min_element(all(a[i]))); return res;}
template<class T> T max(vector<vector<T >> &a) { T res = MIN(T); rep(i, a.size())chma(res, *max_element(all(a[i]))); return res;}
constexpr bool bget(ll m, ll keta) { return (m >> keta) & 1; }
ll bget(ll m, ll keta, ll sinsuu) { m /= (ll) pow(sinsuu, keta); return m % sinsuu;}
ll bit(ll n) { return (1LL << (n)); }
ll bit(ll n, ll sinsuu) { return (ll) pow(sinsuu, n); }
ll mask(ll n) { return (1ll << n) - 1; }
#define bcou __builtin_popcountll
//最下位ビット
ll lbit(ll n) { return n & -n; }
//最上位ビット
ll hbit(ll n) { n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); n |= (n >> 32); return n - (n >> 1);}
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;}
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; } 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 unique(v) v.erase( unique(v.begin(), v.end()), v.end() );
//[i] := i番として圧縮されたものを返す
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;}
vi compress(vi &a, umap<ll, ll> &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(V<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(); }}
//要素が見つからなかったときに困る
#define binarySearch(a, v) (binary_search(all(a),v))
#define lowerIndex(a, v) (lower_bound(all(a),v)-a.begin())
#define lowerBound(a, v) (*lower_bound(all(a),v))
#define upperIndex(a, v) (upper_bound(all(a),v)-a.begin())
#define upperBound(a, v) (*upper_bound(all(a),v))
template<class T> void fin(T s) { cout << s << endl, exit(0); }
//便利 数学 math
ll mod(ll a, ll m) { return (a % m + m) % m; }
ll pow(ll a) { return a * a; };
ll fact(ll v) { return v <= 1 ? 1 : v * fact(v - 1); }
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];}
double comd(ll n, ll r) { assert(n < 2020); 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];}
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;}
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; }}
ll lower_remi__bx_a(ll kei, ll rem, ll x) {if (rem >= x) return 0;return (x - rem + kei - 1) / kei;}
ll lower_remv__bx_a(ll kei, ll rem, ll x) {if (rem >= x) return rem;return (x - rem + kei - 1) / kei * kei + rem;}
ll upper_remi__bx_a(ll kei, ll rem, ll x) {if (rem > x) return 0;return (x - rem + kei) / kei;}
ll upper_remv__bx_a(ll kei, ll rem, ll x) {if (rem > x) return rem;return (x - rem + kei) / kei * kei + rem;}
//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); }
ll sig(ll t) { return ((1 + t) * t) >> 1; }
ll sig(ll s, ll t) { return ((s + t) * (t - s + 1)) >> 1; }
//幾何 Pをcomplexとして扱う
template<class T, class U> bool eq(T a, U b) { return fabs(a - b) < eps; }
dou atan2(pd a) { return atan2(a.se, a.fi); }
dou angle(pd f, pd t) { return atan2(t.se - f.se, t.fi - f.fi); }
dou distance(pd a, pd b) { return hypot(a.fi - b.fi, a.se - b.se); }
//bを中心とするabcのtheta aからcにかけて時計回り
dou angle(pd a, pd b, pd c) { dou ax = a.fi - b.fi; dou ay = a.se - b.se; dou cx = c.fi - b.fi; dou cy = c.se - b.se; double ret = atan2(cy, cx) - atan2(ay, ax); if (ret < 0) ret += 2 * PI; return ret;}
dou dot(pd a, pd b) { return a.fi * b.fi + a.se + b.se; }
dou cro(pd a, pd b) { return a.fi * b.se - a.se + b.fi; }
//機能拡張
template<typename CharT, typename Traits, typename Alloc>basic_string<CharT, Traits, Alloc>operator+(const basic_string<CharT, Traits, Alloc> &lhs, const int rv) { basic_string<CharT, Traits, Alloc> str(lhs); str.append(to_string(rv)); return str;}template<typename CharT, typename Traits, typename Alloc>void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const int rv) { lhs += to_string(rv);}template<typename CharT, typename Traits, typename Alloc>basic_string<CharT, Traits, Alloc>operator+(const basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { basic_string<CharT, Traits, Alloc> str(lhs); str.append(to_string(rv)); return str;}template<typename CharT, typename Traits, typename Alloc>void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { lhs += to_string(rv);}
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+(const vector<T> &a, U v) { vector<T> ret = a; ret += v; return ret;}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+(vector<T> a, vector<T> b) { vector<T> ret; ret = a; fora(v, b)ret += v; return ret;}template<class T> vector<T> &operator+=(vector<T> &a, vector<T> &b) { fora(v, b)a += v; 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); 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> vector<T> operator*(vector<T> &a, U b) { vector<T> ret; fora(v, a)ret += v * b; return ret;}
template<class T, class U> vector<T> operator/(vector<T> &a, U b) { vector<T> ret; fora(v, a)ret += v / b; return ret;}
template<class T, class U> vector<T> operator*=(vector<T> &a, U b) { fora(v, a)v *= b; return a;}
template<class T, class U> vector<T> operator/=(vector<T> &a, U b) { fora(v, a)v /= b; return a;}
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<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); }
template<typename T> void insert(set<T> &v, vector<T> list) { for (auto &&va :list)v.insert(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;}
void yn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; }
void Yn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }
void YN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }
void fyn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; exit(0);}
void fYn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; exit(0);}
void fYN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; exit(0);}
void Possible(bool a) { if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0);}
void POSSIBLE(bool a) { if (a)cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; exit(0);}
//@formatter:off
template<typename T> T minv(T a, T m);
template<typename T> T minv(T a);
template<typename T>
class Modular {
public:
using Type = typename decay<decltype(T::value)>::type; constexpr Modular() : value() {} template<typename U> Modular(const U &x) { value = normalize(x); } template<typename U> static Type normalize(const U &x) { Type v; if (-mod() <= x && x < mod()) v = static_cast<Type>(x); else v = static_cast<Type>(x % mod()); if (v < 0) v += mod(); return v; } const Type &operator()() const { return value; } template<typename U>explicit operator U() const { return static_cast<U>(value); } constexpr static Type mod() { return T::value; } Modular &operator+=(const Modular &other) { if ((value += other.value) >= mod()) value -= mod(); return *this; } Modular &operator-=(const Modular &other) { if ((value -= other.value) < 0) value += mod(); return *this; } template<typename U> Modular &operator+=(const U &other) { return *this += Modular(other); } template<typename U> Modular &operator-=(const U &other) { return *this -= Modular(other); } Modular &operator++() { return *this += 1; } Modular &operator--() { return *this -= 1; } Modular operator++(signed) { Modular result(*this); *this += 1; return result; } Modular operator--(signed) { Modular result(*this); *this -= 1; return result; } Modular operator-() const { return Modular(-value); }
template<typename U = T>typename enable_if<is_same<typename Modular<U>::Type, signed>::value, Modular>::type &operator*=(const Modular &rhs) {
#ifdef _WIN32
uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;asm("divl %4; \n\t": "=a" (d), "=d" (m): "d" (xh), "a" (xl), "r" (mod()));value = m;
#else
value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
return *this;
}
template<typename U = T> typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type &operator*=(const Modular &rhs) { int64_t q = static_cast<int64_t>(static_cast<double>(value) * rhs.value / mod()); value = normalize(value * rhs.value - q * mod()); return *this; } template<typename U = T> typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type &operator*=(const Modular &rhs) { value = normalize(value * rhs.value); return *this; } Modular &operator/=(const Modular &other) { return *this *= Modular(minv(other.value)); } template<typename U> friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs); template<typename U> friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs); template<typename U> friend std::istream &operator>>(std::istream &stream, Modular<U> &number); operator int() { return value; }private: Type value;
};
template<typename T> bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value == rhs.value; }template<typename T, typename U> bool operator==(const Modular<T> &lhs, U rhs) { return lhs == Modular<T>(rhs); }template<typename T, typename U> bool operator==(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) == rhs; }template<typename T> bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) { return !(lhs == rhs); }template<typename T, typename U> bool operator!=(const Modular<T> &lhs, U rhs) { return !(lhs == rhs); }template<typename T, typename U> bool operator!=(U lhs, const Modular<T> &rhs) { return !(lhs == rhs); }template<typename T> bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value < rhs.value; }template<typename T> Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }template<typename T, typename U> Modular<T> operator+(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) += rhs; }template<typename T, typename U> Modular<T> operator+(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }template<typename T> Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }template<typename T, typename U> Modular<T> operator-(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) -= rhs; }template<typename T, typename U> Modular<T> operator-(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }template<typename T> Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }template<typename T, typename U> Modular<T> operator*(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) *= rhs; }template<typename T, typename U> Modular<T> operator*(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }template<typename T> Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; }template<typename T, typename U> Modular<T> operator/(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) /= rhs; }template<typename T, typename U> Modular<T> operator/(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; }
constexpr signed MOD =
// 998244353;
1e9 + 7;//MOD
using mint = Modular<std::integral_constant<decay<decltype(MOD)>::type, MOD>>;
constexpr int mint_len = 1400001;
vi fac, finv, inv;
vi p2;
mint com(int n, int r) { if (r < 0 || r > n) return 0; return mint(finv[r] * fac[n] % MOD * finv[n - r]);}
mint pom(int n, int r) {/* if (!sz(fac)) com(0, -1);*/ if (r < 0 || r > n) return 0; return mint(fac[n] * finv[n - 1]);}
mint npr(int n, int r) {/* if (!sz(fac)) com(0, -1);*/ if (r < 0 || r > n) return 0; return mint(fac[n] * finv[n - r]);}
int nprin(int n, int r) {/* if (!sz(fac)) com(0, -1);*/ if (r < 0 || r > n) return 0; return fac[n] * finv[n - r] % MOD;}
int icom(int n, int r) { const int NUM_ = 1400001; static ll fac[NUM_ + 1], finv[NUM_ + 1], inv[NUM_ + 1]; if (fac[0] == 0) { inv[1] = fac[0] = finv[0] = 1; for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i <= NUM_; ++i) fac[i] = fac[i - 1] * i % MOD, finv[i] = finv[i - 1] * inv[i] % MOD; } if (r < 0 || r > n) return 0; return ((finv[r] * fac[n] % MOD) * finv[n - r]) % MOD;}
#define ncr com
#define ncri icom
//n個の場所にr個の物を置く
mint nhr(int n, int r) { return com(n + r - 1, r); }
mint hom(int n, int r) { return com(n + r - 1, r); }
int nhri(int n, int r) { return icom(n + r - 1, r); }
template<typename T> T minv(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u;}
template<typename T> T minv(T a) { if (a < mint_len)return inv[a]; T u = 0, v = 1; T m = MOD; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u;}
template<typename T, typename U> Modular<T> mpow(const Modular<T> &a, const U &b) { assert(b >= 0); int x = a(), res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res;}
template<typename T, typename U, typename V> mint mpow(const T a, const U b, const V m = MOD) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= m; (x *= x) %= m; p >>= 1; } return res;}
template<typename T, typename U> mint mpow(const T a, const U b) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res;}
template<typename T, typename U, typename V> int mpowi(const T &a, const U &b, const V &m = MOD) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= m; (x *= x) %= m; p >>= 1; } return res;}
template<typename T> string to_string(const Modular<T> &number) { return to_string(number());}
string yuri(const mint &a) { stringstream st; rep(i, 300) {rep(j, 300) {if ((mint) i / j == a) {st << i << " / " << j;return st.str();}}} rep(i, 1000) {rep(j, 1000) {if ((mint) i / j == a) {st << i << " / " << j;return st.str();}}} return st.str();}
template<typename T> std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {stream << number();
#ifdef _DEBUG
// stream << " -> " << yuri(number);
#endif
return stream;
}
//@formatter:off
template<typename T> std::istream &operator>>(std::istream &stream, Modular<T> &number) { typename common_type<typename Modular<T>::Type, int64_t>::type x; stream >> x; number.value = Modular<T>::normalize(x); return stream;}
using PM = pair<mint, mint>;
using vm = vector<mint>;
using mapm = map<int, mint>;
using umapm = umap<int, mint>;
#define vvm(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(mint,__VA_ARGS__)
#define vnm(name, ...) auto name = make_v<mint>(__VA_ARGS__)
struct setmod{
setmod() {
// p2.resize(mint_len);p2[0] = 1; for (int i = 1; i < mint_len; ++i) p2[i] = p2[i - 1] * 2 % MOD;
fac.resize(mint_len); finv.resize(mint_len); inv.resize(mint_len); inv[1] = fac[0] = finv[0] = 1; for (int i = 2; i < mint_len; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i < mint_len; ++i) fac[i] = fac[i - 1] * i % MOD, finv[i] = finv[i - 1] * inv[i] % MOD;
}
}setmodv;
//@formatter:on
//nhr n個の場所にr個の物を分ける
//@起動時
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;//@formatter:on
//gra mll pr
//上下左右
const string udlr = "udlr";
string UDLR = "UDLR";//x4と連動 UDLR.find('U') := x4[0]
//右、上が正
constexpr ll y4[] = {1, -1, 0, 0};
constexpr ll x4[] = {0, 0, -1, 1};
constexpr ll y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr ll x8[] = {1, 0, -1, 0, 1, -1, 1, -1};
ll n, m, k, d, H, W, x, y, z, q;
ll cou;
vi a, b, c;
//vvi (s, 0, 0);
vvc (ba, 0, 0);
vp p;
str s;
//@formatter:off
template<class T> struct edge { int f, t; T c; int id; int ty; edge(int f, int t, T c = 1, int ty = -1,int id = -1) : f(f), t(t), c(c), id(id), ty(ty) {} bool operator<(const edge &b) const { return c < b.c; } bool operator>(const edge &b) const { return c > b.c; }};
template<class T> ostream &operator<<(ostream &os, edge<T> &e) { os << e.f << " " << e.t << " " << e.c; return os;}
template<typename T> class graph {protected: vector<bool> usedv;public : vector<vector<edge<T>>> g; vector<edge<T>> edges; int n; graph(int n) : n(n) { g.resize(n), usedv.resize(n); } void clear() { g.clear(), edges.clear(); } void resize(int n) { this->n = n; g.resize(n); usedv.resize(n); } int size() { return g.size(); } vector<edge<T> > &operator[](int i) { return g[i]; } virtual void add(int f, int t, T c, int ty ,int id) = 0; virtual bool used(edge<T> &e) = 0; virtual bool used(int id) = 0; virtual void del(edge<T> &e) = 0; virtual void del(int id) = 0; virtual void set_edges() = 0;};
template<typename T =ll> class digraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::usedv;
int eid = 0;
digraph(int n) : graph<T>(n) {}
void add(int f, int t, T c = 1, int ty = -1,int id = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digraph add");
deb(f, t, c, ty,id);
ole();
}
if (id == -1)id = eid++;
g[f].emplace_back(f, t, c, ty,id);
edges.emplace_back(f, t, c, ty,id);
}
bool used(edge<T> &e) { return usedv[e.id]; }
bool used(int id) { return usedv[id]; }
void del(edge<T> &e) { usedv[e.id] = usedv[e.id ^ 1] = 1; }
void del(int id) { usedv[id] = usedv[id ^ 1] = 1; }
void set_edges() { if (sz(edges))return; rep(i, n)fora(e, g[i])edges.push_back(e); }
};
template<class T=int> class undigraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::usedv;
int eid = 0;
undigraph(int n) : graph<T>(n) {}
void add(int f, int t, T c = 1, int ty = -1,int id = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("undigraph add");
deb(f, t, c, ty,id);
ole();
}
if (id == -1)id = eid, eid += 2;
g[f].emplace_back(f, t, c, ty, id);
g[t].emplace_back(t, f, c, ty, id + 1);
edges.emplace_back(f, t, c, ty, id);
edges.emplace_back(t, f, c, ty, id + 1);
}
void add(edge<T> &e) { int f = e.f, t = e.t, ty = e.ty; T c = e.c; add(f, t, c, ty); }
bool used(edge<T> &e) { return usedv[e.id]; }
bool used(int id) { return usedv[id]; }
void del(edge<T> &e) { usedv[e.id] = usedv[e.id ^ 1] = 1; }
void del(int id) { usedv[id] = usedv[id ^ 1] = 1; }
void set_edges() { if (sz(edges))return; rep(i, n)fora(e, g[i])edges.push_back(e); }
};
template<typename T> struct radixheap { vector<pair<u64, T> > v[65]; u64 size, last; radixheap() : size(0), last(0) {} bool empty() const { return size == 0; } int getbit(int a) { return a ? 64 - __builtin_clzll(a) : 0; } void push(u64 key, const T &value) { ++size; v[getbit(key ^ last)].emplace_back(key, value); } pair<u64, T> pop() { if (v[0].empty()) { int idx = 1; while (v[idx].empty()) ++idx; last = min_element(begin(v[idx]), end(v[idx]))->first; for (auto &p : v[idx]) v[getbit(p.first ^ last)].emplace_back(p); v[idx].clear(); } --size; auto ret = v[0].back(); v[0].pop_back(); return ret; }};
//radiq_heap
vi dijkstra2(const graph<int> &g, int s, int cant_arrive = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } int initValue = MAX(int); vi dis(g.n, initValue); radixheap<int> q; dis[s] = 0; q.push(0, s); while (!q.empty()) { int nowc, i; tie(nowc, i) = q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; int c = nowc + e.c; if (dis[to] > c) { dis[to] = c; q.push(dis[to], to); } } } /*基本、たどり着かないなら-1*/ if (cant_arrive == -1)for (auto &&d :dis) if (d == initValue)d = -1; return dis;}
//priority_queue
template<class T> vector<T> dijkstra(const graph<T> &g, int s, int cant_arrive = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } T initValue = MAX(T); vector<T> dis(g.n, initValue); priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; dis[s] = 0; q.emplace(0, s); while (q.size()) { T nowc = q.top().fi; int i = q.top().se; q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; T c = nowc + e.c; if (dis[to] > c) { dis[to] = c; q.emplace(dis[to], to); } } } /*基本、たどり着かないなら-1*/ if (cant_arrive == -1)for (auto &&d :dis) if (d == initValue)d = -1; return dis;}
template<class T> vector<vector<T>> warshall(const graph<T> &g, int cant_arrive = -1) { int n = g.n; vector<vector<T> > dis(n, vector<T>(n, linf)); rep(i, n)fora(e, g.g[i])chmi(dis[e.f][e.t], e.c); rep(i, n)dis[i][i] = 0; rep(k, n)rep(i, n)rep(j, n)chmi(dis[i][j], dis[i][k] + dis[k][j]); /*基本、たどり着かないなら-1*/ if (cant_arrive == -1)rep(i, n)rep(j, n) if (dis[i][j] == linf)dis[i][j] = -1; return dis;}
template<class T>class MinOp {public: T operator()(T a, T b) { return min(a, b); }};
template<typename OpFunc>struct SparseTable{ OpFunc op; signed size; vector<signed> lg; vector<vector<pair<signed,signed>> > table; void init( const vector<pair<signed,signed>> &array, OpFunc opfunc ){ signed n = array.size(); op = opfunc; lg.assign( n + 1 , 0 ); for( signed i = 1; i <= n; i++ ){ lg[i] = 31 - __builtin_clz( i ); } table.assign( lg[n] + 1, array ); for( signed i = 1; i <= lg[n]; i++ ){ for( signed j = 0; j < n; j++ ){ if( j + (1<<(i-1)) < n ){ table[i][j] = op( table[i-1][j] , table[i-1][j+(1<<(i-1))] ); } else { table[i][j] = table[i-1][j]; } } } } pair<signed,signed> query( signed l , signed r ){ assert( l < r ); return op( table[ lg[r-l] ][l], table[ lg[r-l] ][r-(1<<lg[r-l])] ); }};
struct PMORMQ{ vector<signed> a; SparseTable<MinOp<pair<signed,signed> > > sparse_table; vector<vector<vector<signed> > > lookup_table; vector<signed> block_type; signed block_size, n_block; void init( const vector<signed> &array ){ a = array; signed n = a.size(); block_size = std::max( 1, ( 31 - __builtin_clz( n ) ) / 2 ); while( n % block_size != 0 ){ a.push_back( a.back() + 1 ); n++; } n_block = n / block_size; vector<pair<signed,signed> > b( n_block, make_pair( INT_MAX, INT_MAX ) ); for( signed i = 0; i < n; i++ ){ b[i/block_size] = min( b[i/block_size], make_pair( a[i], i ) ); } sparse_table.init( b, MinOp<pair<signed,signed> >() ); block_type.assign( n_block, 0 ); for( signed i = 0; i < n_block; i++ ){ signed cur = 0; for( signed j = 0; j < block_size-1; j++ ){ signed ind = i * block_size + j; if( a[ind] < a[ind+1] ){ cur |= 1 << j; } } block_type[i] = cur; } lookup_table.assign( 1 << (block_size-1), vector<vector<signed> >( block_size, vector<signed>( block_size+1 ) ) ); for( signed i = 0; i < (1<<(block_size-1)); i++ ){ for( signed j = 0; j < block_size; j++ ){ signed res = 0; signed cur = 0; signed pos = j; for( signed k = j+1; k <= block_size; k++ ){ lookup_table[i][j][k] = pos; if( i & ( 1 << (k-1) ) ){ cur++; } else { cur--; } if( res > cur ){ pos = k; res = cur; } } } } } signed query( signed l, signed r ){ assert( l < r ); signed lb = l / block_size; signed rb = r / block_size; if( lb == rb ){ return lb * block_size + lookup_table[ block_type[lb] ][ l % block_size ][ r % block_size ]; } signed pl = lb * block_size + lookup_table[ block_type[lb] ][ l % block_size ][ block_size ]; signed pr = rb * block_size + lookup_table[ block_type[rb] ][0][ r % block_size ]; signed pos = pl; if( r % block_size > 0 && a[pl] > a[pr] ){ pos = pr; } if( lb + 1 == rb ){ return pos; } signed spv = sparse_table.query( lb+1, rb ).second; if( a[pos] > a[spv] ){ return spv; } return pos; }};
template<class T=int> class tree : public undigraph<T> {public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; using undigraph<T>::usedv; PMORMQ rmq; int cnt; vector<int> disv; vector<signed> depth,id, in; int root; bool never=true; tree(int n_, int root = 0) : undigraph<T>(n_), root(root) { n=n_; } void dfs( int x , int p , int d ,int dis =0){ id[cnt] = x; depth.push_back( d ); disv[x]=dis; in[x] = cnt++; forg(gi, g[x]){ if( t == p ){ continue; } dfs( t , x , d+1 ,dis+c); id[cnt] = x; depth.push_back( d ); cnt++; } } void precalc( ){ never = false; cnt = 0; depth.clear(); disv.assign(n,0); in.assign( n, -1 ); id.assign( 2*n-1, -1 ); dfs( root, -1, 0 ); rmq.init( depth ); } int lca( int a , int b ){ if(never)precalc(); int x = in[a]; int y = in[b]; if( x > y ){ swap( x , y ); } int pos = rmq.query( x, y + 1 ); return id[pos]; } int dis( int a , int b ){ if(never)precalc(); int x = in[a]; int y = in[b]; if( x > y ){ swap( x , y ); } int pos = rmq.query( x, y + 1 ); int p= id[pos]; return disv[a]+disv[b]-disv[p]*2; }};
//
//辺によりメモリを大量消費
// よってedgesを消している
//頂点10^6でメモリを190MB(制限の8割)使う
template<class T=int> class grid_k6 : public undigraph<T> {public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; using undigraph<T>::usedv; int H, W; int eid = 0; void add(int f, int t, T c = 1, int ty = -1,int id = -1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("grid_k6 add"); deb(f, t, c, ty,id); ole(); } g[f].emplace_back(f, t, c, ty,eid++); g[t].emplace_back(t, f, c, ty,eid++); } int getid(int h, int w) { if (!ins(h, w, H, W))return -1; return W * h + w; } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } grid_k6(int H, int W) : H(H), W(W), undigraph<T>(H * W) { rep(h, H) { rep(w, W) { int f = getid(h, w); if (w + 1 < W) add(f, getid(h, w + 1)); if (h + 1 < H)add(f, getid(h + 1, w)); } } } grid_k6(vector<vector<char>> ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } void add(int fh, int fw, int th, int tw) { add(getid(fh, fw), getid(th, tw)); } void set_edges() { rep(i, n)fora(e, g[i])edges.push_back(e); }};
//左上から右下に移動できる
template<class T=int> class digrid_k6 : public digraph<T> {public: using digraph<T>::g; using digraph<T>::n; using digraph<T>::edges; using digraph<T>::usedv; int H, W; int eid = 0; void add(int f, int t, T c = 1, int ty = -1,int id = -1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("digrid_k6 add"); deb(f, t, c, ty,id); ole(); } g[f].emplace_back(f, t, c, ty, eid++); } int getid(int h, int w) { if (!ins(h, w, H, W))return -1; return W * h + w; } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } digrid_k6(int H, int W) : H(H), W(W), digraph<T>(H * W) { rep(h, H) { rep(w, W) { int f = getid(h, w); if (w + 1 < W) add(f, getid(h, w + 1)); if (h + 1 < H)add(f, getid(h + 1, w)); } } } digrid_k6(vector<vector<char>> ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), digraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } void add(int fh, int fw, int th, int tw) { add(getid(fh, fw), getid(th, tw)); } void set_edges() { rep(i, n)fora(e, g[i])edges.push_back(e); }};
template<class T> bool nibu(const graph<T> &g) { int size = 0; rep(i, g.n)size += sz(g.g[i]); if (size == 0)return true; unionfind uf(g.n * 2); rep(i, g.n)fora(e, g.g[i])uf.unite(e.f, e.t + g.n), uf.unite(e.f + g.n, e.t); rep(i, g.n)if (uf.same(i, i + g.n))return 0; return 1;}
//二部グラフを色分けした際の頂点数を返す
template<class T> vp nibug(graph<T> &g) { vp cg; if (!nibu(g)) { debugline("nibu"); ole(); } int n = g.size(); vb was(n); queue<P> q; rep(i, n) { if (was[i])continue; q.push(mp(i, 1)); was[i] = 1; int red = 0; int coun = 0; while (q.size()) { int now = q.front().fi; int col = q.front().se; red += col; coun++; q.pop(); forg(gi, g[now]) { if (was[t])continue; q.push(mp(t, col ^ 1)); was[t] = 1; } } cg.push_back(mp(red, coun - red)); } return cg;}
template<class T> ostream &operator<<(ostream &os, graph<T> &g) { rep(i, sz(g)) { forg(gi, g[i]) { os << f << " " << t << " " << c << endl; } } return os;}
//閉路がなければtrue
bool topo(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; queue<int> st; rep(i, n)if (nyu[i] == 0)st.push(i); while (st.size()) { int v = st.front(); st.pop(); res.push_back(v); fora(e, g[v]) if (--nyu[e.t] == 0)st.push(e.t); } return res.size() == n;}
//辞書順最小トポロジカルソート
bool topos(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; /*小さい順*/ priority_queue<int, vector<int>, greater<int> > q; rep(i, n)if (nyu[i] == 0)q.push(i); while (q.size()) { int i = q.top(); q.pop(); res.push_back(i); fora(e, g[i])if (--nyu[e.t] == 0)q.push(e.t); } return res.size() == n;}
//連結グラフが与えられる 閉路があるか
template<class T> bool close(undigraph<T> &g) { int n = 0; int e = 0; rep(i, g.n) { if (sz(g[i]))n++; forg(gi, g[i]) { e++; } } return (e >> 1) >= n;}
template<class T> bool close(undigraph<T> &g, int v) { unionfind uf(g.n); rep(i, g.n) { forg(gi, g[i]) { if (f < t)break; if (f == t && f == v)return true; if (uf.same(f, v) && uf.same(t, v))return true; uf.unite(f, t); } } return false;}
template<class T> bool close(digraph<T> &g) {vi res;return topo(res, g);}
template<class T> vi indegree(graph<T> &g) { vi ret(g.size()); rep(i, g.size()) { forg(gi, g[i]) { ret[t]++; } } return ret;}
template<class T> vi outdegree(graph<T> &g) { vi ret(g.size()); rep(i, g.size()) { ret[i] = g[i].size(); } return ret;}
template<class T> digraph<T> rev(digraph<T> &g) { digraph<T> r(g.n); rep(i, g.n) { forg(gi, g[i]) { r.add(t, f, c); } } return r;}
//橋を列挙する (取り除くと連結でなくなる辺)
template<class T> vp bridge(graph<T> &G) { static bool was; vp brid; vi articulation; vi ord(G.n), low(G.n); vb vis(G.n); function<void(int, int, int)> dfs = [&](int v, int p, int k) { vis[v] = true; ord[v] = k++; low[v] = ord[v]; bool isArticulation = false; int ct = 0; for (int i = 0; i < G[v].size(); i++) { if (!vis[G[v][i].t]) { ct++; dfs(G[v][i].t, v, k); low[v] = min(low[v], low[G[v][i].t]); if (~p && ord[v] <= low[G[v][i].t]) isArticulation = true; if (ord[v] < low[G[v][i].t]) brid.push_back(make_pair(min(v, G[v][i].t), max(v, G[v][i].t))); } else if (G[v][i].t != p) { low[v] = min(low[v], ord[G[v][i].t]); } } if (p == -1 && ct > 1) isArticulation = true; if (isArticulation) articulation.push_back(v); }; int k = 0; rep(i, n) { if (!vis[i]) dfs(i, -1, k); } sort(brid.begin(), brid.end()); return brid;}
//間接点を列挙する (取り除くと連結でなくなる点)
template<class T> vi articulation(undigraph<T> &G) { static bool was; vp bridge; vi arti; vi ord(G.n), low(G.n); vb vis(G.n); function<void(int, int, int)> dfs = [&](int v, int p, int k) { vis[v] = true; ord[v] = k++; low[v] = ord[v]; bool isArticulation = false; int ct = 0; for (int i = 0; i < G[v].size(); i++) { if (!vis[G[v][i].t]) { ct++; dfs(G[v][i].t, v, k); low[v] = min(low[v], low[G[v][i].t]); if (~p && ord[v] <= low[G[v][i].t]) isArticulation = true; if (ord[v] < low[G[v][i].t]) bridge.push_back(make_pair(min(v, G[v][i].t), max(v, G[v][i].t))); } else if (G[v][i].t != p) { low[v] = min(low[v], ord[G[v][i].t]); } } if (p == -1 && ct > 1) isArticulation = true; if (isArticulation) arti.push_back(v); }; int k = 0; rep(i, n) { if (!vis[i]) dfs(i, -1, k); } sort(arti.begin(), arti.end()); return arti;}
#define kansetu articulation
P farthest(undigraph<> &E, int cur, int pre, int d, vi &D) {D[cur] = d;P r = {d, cur};forg(gi, E[cur]) if (t != pre) {P v = farthest(E, t, cur, d + 1, D);r = max(r, v);}return r;}
vi diameter(undigraph<> &E) { /* diameter,center*/vi D[3];D[0].resize(E.size());D[1].resize(E.size());auto v1 = farthest(E, 0, 0, 0, D[0]);auto v2 = farthest(E, v1.second, v1.second, 0, D[0]);farthest(E, v2.second, v2.second, 0, D[1]);int i;rep(i, D[0].size()) D[2].push_back(max(D[0][i], D[1][i]));return D[2];}
//i d
vp diameter_p(undigraph<> &E) { /* diameter,center*/vector<int> D[3];D[0].resize(E.size());D[1].resize(E.size());auto v1 = farthest(E, 0, 0, 0, D[0]);auto v2 = farthest(E, v1.second, v1.second, 0, D[0]);farthest(E, v2.second, v2.second, 0, D[1]);int i;vp res(E.size());rep(i, D[0].size()) {if (D[0][i] > D[1][i])res[i] = mp(D[0][i], v1.second);else res[i] = mp(D[1][i], v2.second);}return res;}
digraph<> rang_di(int n, int m, bool zibun = 0, bool taju = 0) { umapp was; digraph<> g(n); was[mp(-1, -2)] = 1; while (m) { int f = -1, t = -2; while (f < 0 || (!taju && was[mp(f, t)])) { f = rand(0, n - 1); t = rand(0, n - 1); if (!zibun && f == t)f = -1; } g.add(f, t); was[mp(f, t)] = 1; m--; } return g;}
digraph<> rang_di_perfect(int n, bool zibun = 0) { digraph<> g(n); rep(i, n) { rep(j, n) { if (!zibun && i == j)con; g.add(i, j); } } return g;}
undigraph<> rang_un(int n, int m, bool zibun = 0, bool taju = 0) { umapp was; undigraph<> g(n); was[mp(-1, -2)] = 1; while (m) { int f = -1, t = -2; while (f < 0 || (!taju && was[mp(min(f, t), max(f, t))])) { f = rand(0, n - 1); t = rand(0, n - 1); if (!zibun && f == t)f = -1; } g.add(f, t); was[mp(min(f, t), max(f, t))] = 1; m--; } return g;}
undigraph<> rang_un_perfect(int n, bool zibun = 0) { undigraph<> g(n); rep(i, n) { rep(j, i, n) { if (!zibun && i == j)con; g.add(i, j); } } return g;}
//閉路が1つしかない場合、その閉路に含まれる頂点を1としたvectorを返す
template<class T> vi get_close1(digraph<T> &g) { int n = g.n; queue<int> q; vi d = outdegree(g); vi res(n, 1); rep(i, n) { if (d[i] == 0) { q += i; res[i] = 0; } } auto rg = rev(g); while (q.size()) { auto now = q.front(); q.pop(); forg(gi, rg[now]) { if (--d[t] == 0) { q += t; res[t] = 0; } } } return res;};/*@formatter:on*/
digraph<> g(2 * k5);
vi clo;
vi deg;
seti ss[k5 * 2];
vi gv(k5 * 2, -1);
vi mem(k5*2,-1);
int ds(int p, int i) {
// if(mem[i]!=-1)return mem[i];
forg(gi, g[i])if(clo[t]==0)ss[i] += ds(i, t);
rep(v, inf) {
if (ss[i].count(v) == 0) {
if (clo[i] == 0)gv[i] = v;
return v;
}
}
return 0;
}
digraph<> rg(0);
vi r(k5 * 2);
bool ds2(int p, int i, int nex) {
int v;
rep(j, inf) {
if (ss[i].count(j) == 0 && nex != j) {
v = j;
break;
}
}
if (gv[i] != -1) {
bool ok = v == gv[i];
if (ok)outv(gv);
return ok;
} else {
gv[i] = v;
return ds2(r[p], p, v);
}
}
void solve() {
in(n);
rep(i, n) {
g.add(in() - 1, i);
}
clo = get_close1(g);
deg = outdegree(g);
rep(i, n) {
if (clo[i])ds(-1, i);
}
rg = rev(g);
rep(i, n)forg(gi, rg[i]) {
if (clo[t])r[i] = t;
}
rep(i, n) {
if (clo[i]) {
int m = 2;
int pgv = 0;
rep(v, inf) {
if (m == 0)break;
if (ss[i].count(v) == 0) {
rep(i, n) if (clo[i])gv[i] = -1;
if (m == 2) {
gv[i] = v;
if (ds2(r[r[i]], r[i], v)) {
POSSIBLE(1);
}
pgv = v;
} else {
int to = 0;
forg(gi, g[i])if (clo[t])to = t;
gv[to] = pgv;
gv[i] = v;
POSSIBLE(ds2(r[r[i]], r[i], v));
}
m--;
}
}
}
}
POSSIBLE(0);
}
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) {
// cout << "完璧 : solveを書き直そう" << endl;
// cout << " : そして、solve()を呼び出すのだ" << endl;
// cout << " : cin>>n; na(a,n);も忘れるな" << endl;
}
#endif
return 0;
};
| a.cc: In function 'bool ds2(long long int, long long int, long long int)':
a.cc:896:20: error: no matching function for call to 'outv(vi&)'
896 | if (ok)outv(gv);
| ~~~~^~~~
a.cc:298:24: note: candidate: 'template<class T> void outv(std::vector<_Tp>&, long long int)'
298 | template<class T> void outv(vector<T> &a, ll W) {;}
| ^~~~
a.cc:298:24: note: candidate expects 2 arguments, 1 provided
a.cc:299:24: note: candidate: 'template<class T> void outv(std::vector<std::vector<_Tp> >&, long long int, long long int, long long int)'
299 | template<class T> void outv(vector<vector<T> > &a, ll H = linf, ll W = linf,int key=-1) {;}
| ^~~~
a.cc:299:24: note: template argument deduction/substitution failed:
a.cc:896:20: note: mismatched types 'std::vector<_Tp>' and 'long long int'
896 | if (ok)outv(gv);
| ~~~~^~~~
a.cc:300:24: note: candidate: 'template<class T> void outv(std::vector<std::vector<std::vector<_Tp> > >&, long long int, long long int, long long int)'
300 | template<class T> void outv(vector<vector<vector<T> > > &a, ll H = linf, ll W = linf,ll U = linf) {;}
| ^~~~
a.cc:300:24: note: template argument deduction/substitution failed:
a.cc:896:20: note: mismatched types 'std::vector<std::vector<_Tp> >' and 'long long int'
896 | if (ok)outv(gv);
| ~~~~^~~~
|
s018405555 | p03650 | Java | import java.io.*;
import java.util.*;
public class MainF {
static final StdIn in = new StdIn();
static final PrintWriter out = new PrintWriter(System.out);
static List<Integer>[] adj;
static boolean[] vis, act, ic;
static List<Integer> cyc = new ArrayList<Integer>();
static int[] a;
public static void main(String[] args) {
int n=in.nextInt();
adj = new List[n];
for(int i=0; i<n; ++i)
adj[i] = new ArrayList<Integer>();
for(int i=0; i<n; ++i)
adj[in.nextInt()-1].add(i);
vis = new boolean[n];
act = new boolean[n];
ic = new boolean[n];
a = new int[n];
for(int i=0; i<n; ++i)
if(!vis[i]&&dfs1(i))
break;
cyc.remove(cyc.size()-1);
// System.out.println(cyc);
Arrays.fill(a, -1);
a[cyc.get(0)]=n;
if(dfs2(cyc.get(0))!=a[cyc.get(1)]) {
System.out.println("POSSIBLE");
return;
}
int a1=a[cyc.get(0)];
Arrays.fill(a, -1);
a[cyc.get(0)]=a1;
if(dfs2(cyc.get(0))==a1)
System.out.println("POSSIBLE");
else
System.out.println("IMPOSSIBLE");
out.close();
}
static boolean dfs1(int u) {
vis[u]=true;
act[u]=true;
for(int v : adj[u]) {
if(act[v]) {
cyc.add(v);
ic[v]=true;
cyc.add(u);
ic[u]=true;
return true;
}
if(dfs1(v)) {
if(ic[v]&&v!=cyc.get(0)) {
cyc.add(u);
ic[u]=true;
}
return true;
}
}
act[u]=false;
return false;
}
static int dfs2(int u) {
List<Integer> b = new ArrayList<Integer>();
b.add(0);
b.add(Integer.MAX_VALUE);
for(int v : adj[u])
b.add(a[v]==-1?dfs2(v):a[v]);
Collections.sort(b);
for(int i=0; ; ++i)
if(b.get(i+1)>b.get(i)+1)
return a[u]=b.get(i)+1;
}
static class StdIn {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public StdIn() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public StdIn(InputStream in) {
try{
din = new DataInputStream(in);
} catch(Exception e) {
throw new RuntimeException();
}
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public int nextInt() {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
ret = ret * 10 + c - '0';
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public int[] readIntArray(int n) {
int[] ar = new int[n];
for(int i=0; i<n; ++i)
ar[i]=nextInt();
return ar;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() {
try{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
} catch(IOException e) {
throw new RuntimeException();
}
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
} | Main.java:4: error: class MainF is public, should be declared in a file named MainF.java
public class MainF {
^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
|
s644822832 | p03650 | C++ | // see https://github.com/LumaKernel/vimfiles/tree/master/snippets/cp-cpp/temp.snip
/// --- .lumrc Template {{{ ///
#if 0
#define assert(...)
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = tuple<ll, ll>;
using P3 = tuple<ll, ll, ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define FORI(i,a,b) for(int i=int(a);i<=int(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPI(i,n) FORI(i,0,n)
#define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define RFORI(i,a,b) for(int i=int(b);i>=int(a);--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPI(i,n) RFORI(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique(ALL(a)),(a).end())
#define PB push_back
#define EACH(i,c) REP(i,(c).size())
#define REACH(i,c) RREP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define BR cout<<"\n";
#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
#else
#define dump(...)
#endif
#define YES(x) cout<<((x)?"YES":"NO")<<"\n";
#define Yes(x) cout<<((x)?"Yes":"No")<<"\n";
#define yes(x) cout<<((x)?"yes":"no")<<"\n";
inline int omajinai_int_in(){omajinai;int n;cin>>n;return n;}
inline ll omajinai_ll_in(){omajinai;ll n;cin>>n;return n;}
inline string omajinai_string_in(){omajinai;string n;cin>>n;return n;}
inline int int_in(){int n;cin>>n;return n;}
inline ll ll_in(){ll n;cin>>n;return n;}
inline string string_in(){string n;cin>>n;return n;}
#define oini omajinai_int_in()
#define oinl omajinai_ll_in()
#define oins omajinai_string_in()
#define ini int_in()
#define inl ll_in()
#define ins string_in()
#define isInside(y,x) (0<=(y)&&(y)<h&&0<=(x)&&(x)<w)
#define fi(x) (get<0>(x))
#define se(x) (get<1>(x))
#define th(x) (get<2>(x))
#define fo(x) (get<3>(x))
#define fif(x) (get<4>(x))
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; EACH(i, v) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "}"; return o; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template <typename T> inline void smax(T &a, T b) { a = a > b ? a : b; }
template <typename T> inline void smin(T &a, T b) { a = a < b ? a : b; }
template<typename T> int log2max(T x) {
int res = 0;
ll tmp = 1;
while(tmp < x) tmp <<= 1, res++;
return res;
}
constexpr double PI = acos(-1);
/// }}}--- ///
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr int MOD = 1e9+7;
/// --- Lowlink Library {{{ ///
// undirected graph
// count edges
// construct : (int size)
// do : calc()
struct Lowlink {
struct Edge {
int to, idx;
Edge(int to, int idx): to(to), idx(idx) {}
};
int size;
int edgeSize = 0;
vector< vector< Edge > > g;
VI ord, low;
VI used;
VI isBridge, isArticulation;
Lowlink(int n): size(n), g(n), ord(n), low(n) {}
void addEdge(int a, int b) {
g[a].emplace_back(b, edgeSize);
g[b].emplace_back(a, edgeSize);
edgeSize++;
}
void calc() {
used.assign(size, 0);
isBridge.assign(edgeSize, 0);
isArticulation.assign(size, 0);
int k = 0;
dfs(0, -1, k);
}
// p just means "just before"
private :
void dfs(int i, int p, int &k) {
used[i] = 1;
ord[i]=low[i]=k++;
isArticulation[i] = 0;
int DFSTreeDegree = 0;
for(Edge edge : g[i]) {
int j = edge.to;
int idx = edge.idx;
if(used[j]) {
if(j != p) {
// back edge
smin(low[i], ord[j]);
}
} else {
// on dfs-tree
DFSTreeDegree++;
dfs(j, i, k);
smin(low[i], low[j]);
isBridge[idx] = ord[i] < low[j];
if(p != -1 && ord[i] <= low[j]) {
isArticulation[i] = 1;
}
}
}
if(p == -1 && DFSTreeDegree > 1) {
isArticulation[i] = 1;
}
}
};
/// }}}--- ///
int n=ini;
Lowlink lowlink(n);
VI onCircuit(n, 0);
VI used(n, 0);
VVI orig(n);
VI rev(n);
VI num(n, 0);
void dfs(int i) {
if(onCircuit[i]) return;
if(used[i]) return;
used[i] = 1;
set<int> st;
for(int j : orig[i]) {
assert(onCircuit[j] == false);
dfs(j);
st.insert(num[j]);
}
int t=0;
while(st.count(t)) t++;
num[i] = t;
}
bool solve(int now) {
int last = now;
now = rev[now];
while(1) {
set<int> st;
for(int j:orig[now]) {
st.insert(num[j]);
}
int nnum = 0;
while(st.count(nnum)) nnum++;
if(num[now] <= nnum) {
if(num[now] == nnum) {
if(last == now) {
return 1;
}
} else {
num[now] = nnum;
last = now;
}
} else {
return 0;
}
now = rev[now];
}
}
int main() {
REP(i, n) {
int p = ini-1;
// p -> i
lowlink.addEdge(p, i);
orig[p].PB(i);
rev[i] = p;
}
lowlink.calc();
REP(i, n) {
for(auto edge : lowlink.g[i]) {
int j = edge.to, idx = edge.idx;
if(!lowlink.isBridge[idx]) {
onCircuit[i] = 1;
}
}
}
REP(i, n) dfs(i);
int now=-1;
REP(i, n) {
if(onCircuit[i]) {
now = i;
}
}
assert(now != -1);
if(solve(now)) {
cout << "POSSIBLE" << endl;
return 0;
}
REP(i, 10) {
REP(i, n) {
if(onCircuit[i]) {
num[i] = 0;
}
}
now = rev[now];
if(solve()) {
cout << "POSSIBLE" << endl;
return 0;
}
}
cout << "IMPOSSIBLE" << endl;
}
//
| a.cc: In function 'int main()':
a.cc:254:13: error: too few arguments to function 'bool solve(int)'
254 | if(solve()) {
| ~~~~~^~
a.cc:189:6: note: declared here
189 | bool solve(int now) {
| ^~~~~
|
s376728847 | p03650 | C++ | #include<bits/stdc++.h>
using namespace std;
#define N 200005
vector<int> v[N];
int fa[N],du[N],sg[N];
int n;
void calc(int u){
sort(v[u].begin(),v[u].end());
sg[u]=0;
for(int i:v[u]) i==sg[u]? sg[u]++:0;
}
void tp(int u){
calc(u);
du[fa[u]]--;du[u]=-1;
v[fa[u]].push_back(sg[u]);
if(du[fa[u]]==0) tp(fa[u]);
}
vector<int> temp;
void DFS(int u,int top){
temp.push_back(sg[u]);du[i]=-1;
if(fa[u]!=top) DFS(fa[u],top);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&fa[i]),du[fa[i]]++;
for(int i=1;i<=n;i++)
if(du[i]==0) tp(i);
for(int i=1;i<=n;i++)
if(du[i]==1) calc(i);
for(int i=1;i<=n;i++)
if(du[i]==1){
DFS(i,i);
sort(temp.begin(),temp.end());
if(temp[0]==temp[temp.size()-1]&&temp.size()%2==1)
return puts("IMPOSSIBLE"),0;
temp.clear();
}
return puts("POSSIBLE"),0;
} | a.cc: In function 'void DFS(int, int)':
a.cc:20:34: error: 'i' was not declared in this scope
20 | temp.push_back(sg[u]);du[i]=-1;
| ^
|
s743070840 | p03650 | C++ | #include <cstdio>#include <cstring>#define MAXN 200010struct edge{ int to,next; edge(int _to=0,int _next=0):to(_to),next(_next){}}e[MAXN];int n,root;int g[MAXN],nume;int p[MAXN];bool visit[MAXN];int f[MAXN];bool cnt[MAXN];void addEdge(int u,int v){ e[nume]=edge(v,g[u]); g[u]=nume++;}void dfs(int x){ for(int i=g[x];~i;i=e[i].next) if(e[i].to!=root) dfs(e[i].to); for(int i=g[x];~i;i=e[i].next) if(f[e[i].to]>=0) cnt[f[e[i].to]]=1; for(f[x]=0;cnt[f[x]];f[x]++); for(int i=g[x];~i;i=e[i].next) if(f[e[i].to]>=0) cnt[f[e[i].to]]=0;}bool check(){ int x=p[root]; for(int i=g[x];~i;i=e[i].next) cnt[f[e[i].to]]=1; bool flag=1; if(cnt[f[x]]) flag=0; for(int i=0;i<f[x];i++) if(!cnt[i]) flag=0; memset(cnt,0,sizeof cnt); return flag;}bool gao(){ int x=1; while(!visit[x]) visit[x]=1,x=p[x]; memset(visit,0,sizeof visit); memset(f,-1,sizeof f); root=x; dfs(root); if(check()) return 1; int f0=f[p[x]]; memset(f,-1,sizeof f); f[root]=f0; dfs(root); if(check()) return 1; return 0;}int main(){ memset(g,-1,sizeof g); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",p+i),addEdge(p[i],i); if(gao()) puts("POSSIBLE"); else puts("IMPOSSIBLE");} | a.cc:1:18: warning: extra tokens at end of #include directive
1 | #include <cstdio>#include <cstring>#define MAXN 200010struct edge{ int to,next; edge(int _to=0,int _next=0):to(_to),next(_next){}}e[MAXN];int n,root;int g[MAXN],nume;int p[MAXN];bool visit[MAXN];int f[MAXN];bool cnt[MAXN];void addEdge(int u,int v){ e[nume]=edge(v,g[u]); g[u]=nume++;}void dfs(int x){ for(int i=g[x];~i;i=e[i].next) if(e[i].to!=root) dfs(e[i].to); for(int i=g[x];~i;i=e[i].next) if(f[e[i].to]>=0) cnt[f[e[i].to]]=1; for(f[x]=0;cnt[f[x]];f[x]++); for(int i=g[x];~i;i=e[i].next) if(f[e[i].to]>=0) cnt[f[e[i].to]]=0;}bool check(){ int x=p[root]; for(int i=g[x];~i;i=e[i].next) cnt[f[e[i].to]]=1; bool flag=1; if(cnt[f[x]]) flag=0; for(int i=0;i<f[x];i++) if(!cnt[i]) flag=0; memset(cnt,0,sizeof cnt); return flag;}bool gao(){ int x=1; while(!visit[x]) visit[x]=1,x=p[x]; memset(visit,0,sizeof visit); memset(f,-1,sizeof f); root=x; dfs(root); if(check()) return 1; int f0=f[p[x]]; memset(f,-1,sizeof f); f[root]=f0; dfs(root); if(check()) return 1; return 0;}int main(){ memset(g,-1,sizeof g); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",p+i),addEdge(p[i],i); if(gao()) puts("POSSIBLE"); else puts("IMPOSSIBLE");}
| ^
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
|
s114811085 | p03650 | C++ | #include <cstdio>#include <cstring>#define MAXN 200010struct edge{ int to,next; edge(int _to=0,int _next=0):to(_to),next(_next){}}e[MAXN];int n,root;int g[MAXN],nume;int p[MAXN];bool visit[MAXN];int f[MAXN];bool cnt[MAXN];void addEdge(int u,int v){ e[nume]=edge(v,g[u]); g[u]=nume++;}void dfs(int x){ for(int i=g[x];~i;i=e[i].next) if(e[i].to!=root) dfs(e[i].to); for(int i=g[x];~i;i=e[i].next) if(f[e[i].to]>=0) cnt[f[e[i].to]]=1; for(f[x]=0;cnt[f[x]];f[x]++); for(int i=g[x];~i;i=e[i].next) if(f[e[i].to]>=0) cnt[f[e[i].to]]=0;}bool check(){ int x=p[root]; for(int i=g[x];~i;i=e[i].next) cnt[f[e[i].to]]=1; bool flag=1; if(cnt[f[x]]) flag=0; for(int i=0;i<f[x];i++) if(!cnt[i]) flag=0; memset(cnt,0,sizeof cnt); return flag;}bool gao(){ int x=1; while(!visit[x]) visit[x]=1,x=p[x]; memset(visit,0,sizeof visit); memset(f,-1,sizeof f); root=x; dfs(root); if(check()) return 1; int f0=f[p[x]]; memset(f,-1,sizeof f); f[root]=f0; dfs(root); if(check()) return 1; return 0;}int main(){ memset(g,-1,sizeof g); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",p+i),addEdge(p[i],i); if(gao()) puts("POSSIBLE"); else puts("IMPOSSIBLE");} | a.cc:1:18: warning: extra tokens at end of #include directive
1 | #include <cstdio>#include <cstring>#define MAXN 200010struct edge{ int to,next; edge(int _to=0,int _next=0):to(_to),next(_next){}}e[MAXN];int n,root;int g[MAXN],nume;int p[MAXN];bool visit[MAXN];int f[MAXN];bool cnt[MAXN];void addEdge(int u,int v){ e[nume]=edge(v,g[u]); g[u]=nume++;}void dfs(int x){ for(int i=g[x];~i;i=e[i].next) if(e[i].to!=root) dfs(e[i].to); for(int i=g[x];~i;i=e[i].next) if(f[e[i].to]>=0) cnt[f[e[i].to]]=1; for(f[x]=0;cnt[f[x]];f[x]++); for(int i=g[x];~i;i=e[i].next) if(f[e[i].to]>=0) cnt[f[e[i].to]]=0;}bool check(){ int x=p[root]; for(int i=g[x];~i;i=e[i].next) cnt[f[e[i].to]]=1; bool flag=1; if(cnt[f[x]]) flag=0; for(int i=0;i<f[x];i++) if(!cnt[i]) flag=0; memset(cnt,0,sizeof cnt); return flag;}bool gao(){ int x=1; while(!visit[x]) visit[x]=1,x=p[x]; memset(visit,0,sizeof visit); memset(f,-1,sizeof f); root=x; dfs(root); if(check()) return 1; int f0=f[p[x]]; memset(f,-1,sizeof f); f[root]=f0; dfs(root); if(check()) return 1; return 0;}int main(){ memset(g,-1,sizeof g); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",p+i),addEdge(p[i],i); if(gao()) puts("POSSIBLE"); else puts("IMPOSSIBLE");}
| ^
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
|
s465419166 | p03650 | C++ | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int MAXN = 200000 + 1000;
int n;
vector<int> edg[MAXN], redg[MAXN];
vector<int> cir;
bool onc[MAXN], vis[MAXN];
int val[MAXN];
int find_circle(int x)
{
vis[x] = true;
for(int i = 0; i < redg[x].size(); i++)
{
int y = redg[x][i], tmp = vis[y] ? y : find_circle(y);
if(tmp)
cir.push_back(x), onc[x] = true;
return x == tmp ? 0 : tmp;
}
return 0;
}
bool hash[MAXN];
void assign_tree(int x)
{
for(int i = 0; i < edg[x].size(); i++)
if(!onc[edg[x][i]])
{
int y = edg[x][i];
assign_tree(y);
hash[val[y]] = true;
}
val[x] = 0;
while(hash[val[x]])
val[x]++;
for(int i = 0; i < edg[x].size(); i++)
if(!onc[edg[x][i]])
hash[val[edg[x][i]]] = false;
}
void yes()
{
cout << "POSSIBLE" << endl;
exit(0);
}
void no()
{
cout << "IMPOSSIBLE" << endl;
exit(0);
}
void assign_circle()
{
for(int i = (int)cir.size() - 1; i >= 0; i--)
{
int x = cir[i];
for(int j = 0; j < edg[x].size(); j++)
hash[val[edg[x][j]]] = true;
val[x] = 0;
while(hash[val[x]])
val[x]++;
for(int j = 0; j < edg[x].size(); j++)
hash[val[edg[x][j]]] = false;
}
}
void work()
{
int cir0 = cir[0];
for(int i = 0; i < edg[cir0].size(); i++)
if(!onc[edg[cir0][i]])
hash[val[edg[cir0][i]]] = true;
int tmp1 = 0, tmp2 = 0;
while(hash[tmp1])
tmp1++;
tmp2 = tmp1 + 1;
while(hash[tmp2])
tmp2++;
for(int i = 0; i < edg[cir0].size(); i++)
if(!onc[edg[cir0][i]])
hash[val[edg[cir0][i]]] = false;
val[cir0] = tmp1;
assign_circle();
// for(int i = 1; i <= n; i++)
// cout << val[i] << endl;
if(val[cir0] == tmp1)
yes();
val[cir0] = tmp2;
assign_circle();
if(val[cir0] == tmp2)
yes();
no();
}
int main()
{
ios::sync_with_stdio(false);
// freopen("1.in", "r", stdin);
// freopen("1.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i++)
{
int x;
cin >> x;
edg[x].push_back(i), redg[i].push_back(x);
}
find_circle(1);
// for(int i = 0; i < cir.size(); i++)
// cerr << cir[i] << endl;
for(int i = 0; i < cir.size(); i++)
assign_tree(cir[i]);
work();
return 0;
}
| a.cc: In function 'void assign_tree(int)':
a.cc:42:25: error: reference to 'hash' is ambiguous
42 | hash[val[y]] = true;
| ^~~~
In file included from /usr/include/c++/14/string_view:50,
from /usr/include/c++/14/bits/basic_string.h:47,
from /usr/include/c++/14/string:54,
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/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
a.cc:45:15: error: reference to 'hash' is ambiguous
45 | while(hash[val[x]])
| ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
a.cc:49:25: error: reference to 'hash' is ambiguous
49 | hash[val[edg[x][i]]] = false;
| ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
a.cc: In function 'void assign_circle()':
a.cc:70:25: error: reference to 'hash' is ambiguous
70 | hash[val[edg[x][j]]] = true;
| ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
a.cc:72:23: error: reference to 'hash' is ambiguous
72 | while(hash[val[x]])
| ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
a.cc:75:25: error: reference to 'hash' is ambiguous
75 | hash[val[edg[x][j]]] = false;
| ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
a.cc: In function 'void work()':
a.cc:84:25: error: reference to 'hash' is ambiguous
84 | hash[val[edg[cir0][i]]] = true;
| ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
a.cc:86:15: error: reference to 'hash' is ambiguous
86 | while(hash[tmp1])
| ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
a.cc:89:15: error: reference to 'hash' is ambiguous
89 | while(hash[tmp2])
| ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
a.cc:93:25: error: reference to 'hash' is ambiguous
93 | hash[val[edg[cir0][i]]] = false;
| ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
59 | struct hash;
| ^~~~
a.cc:34:6: note: 'bool hash [201000]'
34 | bool hash[MAXN];
| ^~~~
|
s946667197 | p03650 | C++ | #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
using namespace std;
vector<int> G[200200];
vector<int> rG[200200];
vector<int> loop;
int used[200200];
bool isloop[200200];
int N;
vector<int> grundyP[200200];
bool dfs_findloop(int v){
used[v]=1;
bool res=false;
for(int u:G[v]){
if(used[v]==0){
if(dfs_findloop(u))res=true;
}else if(used[v]==1)res=true;
}
if(res)loop.push_back(v);
used[v]=2;
return res;
}
void add_G(int from,int to){
G[from].push_back(to);
rG[to].push_back(from);
}
int dfs_grundy(int v){
set<int> used_g;
for(int u:G[v])used_g.insert(dfs_grundy(u));
int res=-1;
while(true)if(used_g.count(++res)==0)return res;
}
int dfs_solve(int v,int k){
used[v]=1;
int rec =(k==grundyP[v][0] ? grundyP[v][1] : grundyP[v][0]);
for(int u:rG[v])if((isloop[u])&&(used[u]==0))return dfs_solve(u,rec);
return rec;
}
int main(){
cin>>N;
REP(i,N){
int p;cin>>p;p--;
add_G(p,i);
}
set<int> grundy[N];
fill_n(used,N,0);
fill_n(isloop,N,false);
REP(i,N)if(used[v]==0)dfs_findloop(i);
for(int v:loop)isloop[v]=true;
for(int v:loop)
for(int u:G[v])
if(!isloop[u])
grundy[v].insert(dfs_grundy(u));
for(int v:loop){
int res=-1;
while(grundyP[v].size()<2){
if(grundy[v].count(++res)==0)
grundyP[v].push_back(res);
}
}
int root=loop[0];
fill_n(used,N,0);
if(dfs_solve(root,-1)!=grundyP[root][0]){
cout<<"POSSIBLE"<<endl;
}else{
fill_n(used,N,0);
if(dfs_solve(root,grundyP[root][0])==grundyP[root][0]) {
cout << "POSSIBLE" << endl;
}else{
cout<<"IMPOSSIBLE"<<endl;
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:61:21: error: 'v' was not declared in this scope
61 | REP(i,N)if(used[v]==0)dfs_findloop(i);
| ^
|
s358344057 | p03650 | C++ | #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
using namespace std;
vector<int> G[200200];
vector<int> rG[200200];
vector<int> loop;
int used[200200];
bool isloop[200200];
int N;
vector<int> grundyP[200200];
bool dfs_findloop(int v){
used[v]=1;
bool res=false;
for(int u:G[v]){
if(used[v]==0){
if(dfs_findloop(u))res=true;
}else if(used[v]==1)res=true;
}
if(res)loop.push_back(v);
used[v]=2;
return res;
}
void add_G(int from,int to){
G[from].push_back(to);
rG[to].push_back(from);
}
int dfs_grundy(int v){
set<int> used_g;
for(int u:G[v])used_g.insert(dfs_grundy(u));
int res=-1;
while(true)if(used_g.count(++res)==0)return res;
}
int dfs_solve(int v,int k){
used[v]=1;
int rec =(k==grundyP[v][0] ? grundyP[v][1] : grundyP[v][0]);
for(int u:rG[v])if((isloop[u])&&(!used[u]))return dfs_solve(u,rec);
return rec;
}
int main(){
cin>>N;
REP(i,N){
int p;cin>>p;p--;
add_G(p,i);
}
set<int> grundy[N];
fill_n(used,N,0);
fill_n(isloop,N,false);
REP(i,N)if(used[v]==0)dfs_findloop(i);
for(int v:loop)isloop[v]=true;
for(int v:loop)
for(int u:G[v])
if(!isloop[u])
grundy[v].insert(dfs_grundy(u));
for(int v:loop){
int res=-1;
while(grundyP[v].size()<2){
if(grundy[v].count(++res)==0)
grundyP[v].push_back(res);
}
}
int root=loop[0];
fill_n(used,N,0);
if(dfs_solve(root,-1)!=grundyP[root][0]){
cout<<"POSSIBLE"<<endl;
}else{
fill_n(used,N,0);
if(dfs_solve(root,grundyP[root][0])==grundyP[root][0]) {
cout << "POSSIBLE" << endl;
}else{
cout<<"IMPOSSIBLE"<<endl;
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:61:21: error: 'v' was not declared in this scope
61 | REP(i,N)if(used[v]==0)dfs_findloop(i);
| ^
|
s784373192 | p03650 | C++ | #include <iostream>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int n;
vector<int> to[200001];
int from[200001];
bool cycle[200001];
bool visited[200001];
int label[200001];
int main(){
cin >> n;
for(int i=0;i<n;++i){
label[i]=-1;
int a;
cin>>a;
a--;
from[i]=a;
to[a].push_back(i);
}
int v = 0;
visited[0]=true;
while(true){
if(visited[from[v]]){
for(int w=from[v];w!=v;w=from[w])
cycle[w]=true;
cycle[v]=true;
break;
}
v=from[v];
visited[v]=true;
}
memset(visited,0,sizeof(visited));
queue<int> Q;
for(int i=0;i<n;++i)
if(to[i].size()==0)
Q.push(i);
while(!Q.empty()){
int q = Q.front(); Q.pop();
if(!cycle[q]){
int x=0;
vector<int> tolabel;
for(int t:to[q])
if(label[t]!=-1)
tolabel.push_back(label[t]);
sort(tolabel.begin(),tolabel.end());
for(int i:tolabel){
if(x==i)
++x;
}
label[q]=x;
Q.push(from[q]);
}
}
int p = -1;
for(int i=0;i<n;++i)
if(cycle[i])
p=i;
if(p==-1){
cout << "POSSIBLE" << endl;
}
else{
vector<int> tolabel;
for(int i:to[p])
if(label[i]!=-1)
tolabel.push_back(label[i]);
sort(tolabel.begin(), tolabel.end());
int x=0;
for(int i:tolabel)
if(i==x)
++x;
int y=x+1;
for(int i:tolabel)
if(i==y)
++y;
label[p]=x;
bool flg1 = true;
for(int w=from[p];w!=p;w=from[w]){
int z=0;
vector<int> Z;
for(int i:to[w])
Z.push_back(label[i]);
sort(Z.begin(), Z.end());
for(int i:Z)
if(z==i)
++z;
label[w]=z;
}
tolabel.clear();
for(int i:to[p])
tolabel.push_back(label[i]);
sort(tolabel.begin(), tolabel.end());
int r=0;
for(int i:tolabel)
if(i==r)
++r;
if(r!=x)
flg1 = false;
bool flg2 = true;
for(int i=0;i<n;++i)
if(cycle[i])
label[i]=-1;
label[p]=y;
for(int w=from[p];w!=p;w=from[w]){
int z=0;
vector<int> Z;
for(int i:to[w])
Z.push_back(label[i]);
sort(Z.begin(), Z.end());
for(int i:Z)
if(z==i)
++z;
label[w]=z;
}
tolabel.clear();
for(int i:to[p])
tolabel.push_back(label[i]);
sort(tolabel.begin(), tolabel.end());
r=0;
for(int i:tolabel)
if(r==i)
++r;
if(r!=y)
flg2=false;
if(!flg1 && !flg2)
cout << "IM";
cout << "POSSIBLE" << endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:51:7: error: 'sort' was not declared in this scope; did you mean 'short'?
51 | sort(tolabel.begin(),tolabel.end());
| ^~~~
| short
a.cc:73:5: error: 'sort' was not declared in this scope; did you mean 'short'?
73 | sort(tolabel.begin(), tolabel.end());
| ^~~~
| short
|
s505453080 | p03650 | C++ | #include<bits/stdc++.h>
using namespace std;
int n;
vector<int> out[200010];
int in[200010];
int cycle[200010];
int grundy[200010];
int st = -1;
const int CYCLE = 42;
int dfs(int x) {
cycle[x] = 1;
for(int i : out[x]) {
if(cycle[i] == 1) {
st = i;
cycle[x] = CYCLE;
return CYCLE;
}
else if(cycle[i] == 0) {
if(dfs(i, x) == CYCLE) {
cycle[x] = CYCLE;
if(x == st) return 0;
else return CYCLE;
}
}
}
cycle[x] = 2;
return 0;
}
int getgrundy(int x) {
set<int> s;
for(int i : out[x])
if(cycle[i] != CYCLE)
s.insert(getgrundy(i));
int ans = 0;
auto it = s.begin();
while(it != s.end()) {
if(*it == ans) {
++ans;
++it;
}
else return grundy[x] = ans;
}
return grundy[x] = ans;
}
bool chk(int x, int val, int res) {
if(x == st) return res == val;
int nxt = -1;
for(int i : out[x]) {
if(cycle[i] == CYCLE) {
nxt = i;
}
}
return chk(nxt, grundy[nxt] + (grundy[nxt] == val), res);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
memset(cycle, 0, sizeof cycle);
for(int i = 0; i < n; ++i){
int x;
cin >> x;
--x;
out[x].push_back(i);
in[i] = x;
if(x < i and in[x] == i) {
st = i;
cycle[x] = cycle[i] = CYCLE;
}
}
for(int i = 0; st == -1 and i < n; ++i) if(cycle[i] == 0) dfs(i);
for(int i = 0; i < n; ++i) if(cycle[i] == CYCLE) getgrundy(i);
int nxt;
for(int i : out[st]) {
if(cycle[i] == CYCLE) {
nxt = i;
}
}
if(st == nxt or chk(nxt, grundy[nxt] + (grundy[st] == grundy[nxt]), grundy[st])) cout << "POSSIBLE" << endl;
else if (chk(nxt, grundy[nxt] + ((grundy[st] + 1) == grundy[nxt]), grundy[st] + 1)) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
}
| a.cc: In function 'int dfs(int)':
a.cc:21:31: error: too many arguments to function 'int dfs(int)'
21 | if(dfs(i, x) == CYCLE) {
| ~~~^~~~~~
a.cc:12:5: note: declared here
12 | int dfs(int x) {
| ^~~
|
s181025825 | p03650 | C++ | #include<bits/stdc++.h>
using namespace std;
int n;
vector<int> out[200010];
int in[200010];
int cycle[200010];
int grundy[200010];
int st = -1;
const int CYCLE = 42;
int dfs(int x, int p) {
cycle[x] = 1;
for(int i : out[x]) {
if(i != p) {
if(cycle[i] == 1) {
st = i;
cycle[x] = CYCLE;
return CYCLE;
}
else if(cycle[i] == 0) {
if(dfs(i, x) == CYCLE) {
cycle[x] = CYCLE;
if(x == st) return 0;
else return CYCLE;
}
}
}
}
cycle[x] = 2;
return 0;
}
int getgrundy(int x) {
set<int> s;
for(int i : out[x])
if(cycle[i] != CYCLE)
s.insert(getgrundy(i));
int ans = 0;
auto it = s.begin();
while(it != s.end()) {
if(*it == ans) {
++ans;
++it;
}
else return grundy[x] = ans;
}
return grundy[x] = ans;
}
bool chk(int x, int val, int res) {
if(x == st) return res == val;
int nxt = -1;
for(int i : out[x]) {
if(cycle[i] == CYCLE) {
nxt = i;
}
}
if(nxt == -1) return false;
return chk(nxt, grundy[nxt] + (grundy[nxt] == val), res);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
memset(cycle, 0, sizeof cycle);
for(int i = 0; i < n; ++i){
int x;
cin >> x;
--x;
if(i == x) return cout << "POSSIBLE" << endl, 0;
out[x].push_back(i);
in[i] = x;
if(x < i and in[x] == i) {
st = i;
cycle[x] = cycle[i] = CYCLE;
}
}
for(int i = 0; st == -1 and i < n; ++i) if(cycle[i] == 0) dfs(i, -1);
for(int i = 0; i < n; ++i) {
if(cycle[i] == CYCLE) getgrundy(i);
}
int nxt;
for(int i : out[st]) {
if(cycle[i] == CYCLE) {
nxt = i;
}
}
else if(chk(nxt, grundy[nxt] + (grundy[st] == grundy[nxt]), grundy[st])) cout << "POSSIBLE" << endl;
else if (chk(nxt, grundy[nxt] + ((grundy[st] + 1) == grundy[nxt]), grundy[st] + 1)) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
}
| a.cc: In function 'int main()':
a.cc:90:9: error: 'else' without a previous 'if'
90 | else if(chk(nxt, grundy[nxt] + (grundy[st] == grundy[nxt]), grundy[st])) cout << "POSSIBLE" << endl;
| ^~~~
|
s612844614 | p03650 | C++ | #include<bits/stdc++.h>
using namespace std;
int n;
vector<int> out[200010];
int in[200010];
int cycle[200010];
int grundy[200010];
int st = -1;
const int CYCLE = 42;
int dfs(int x, int p) {
cycle[x] = 1;
for(int i : out[x]) {
if(i != p) {
if(cycle[i] == 1) {
st = i;
cycle[x] = CYCLE;
return CYCLE;
}
else if(cycle[i] == 0) {
if(dfs(i, x) == CYCLE) {
cycle[x] = CYCLE;
if(x == st) return 0;
else return CYCLE;
}
}
}
}
cycle[x] = 2;
}
int getgrundy(int x) {
set<int> s;
for(int i : out[x])
if(cycle[i] != CYCLE)
s.insert(getgrundy(i));
int ans = 0;
auto it = s.begin();
while(it != s.end()) {
if(*it == ans) {
++ans;
++it;
}
else return grundy[x] = ans;
}
return grundy[x] = ans;
}
bool chk(int x, int val, int res) {
if(x == st) return res == val;
int nxt = -1;
for(int i : out[x]) {
if(cycle[i] == CYCLE) {
nxt = i;
}
}
if(nxt == -1) return false;
return chk(nxt, grundy[nxt] + (grundy[nxt] == val), res);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
memset(cycle, 0, sizeof cycle);
for(int i = 0; i < n; ++i){
int x;
cin >> x;
--x;
out[x].push_back(i);
in[i] = x;
if(in[x] == i) {
st = i;
cycle[x] = cycle[i] = CYCLE;
}
}
for(int i = 0; st == -1 and i < n; ++i) if(cycle[i] == 0) dfs(i, -1);
for(int i = 0; i < n; ++i) {
if(cycle[i] == CYCLE) getgrundy(i);
}
for(int i : out[st]) {
if(cycle[i] == CYCLE) {
nxt = i;
}
}
if(st == -1) cout << "IMPOSSIBLE" << endl;
else if(chk(nxt, grundy[nxt] + (grundy[st] == grundy[nxt]), grundy[st])) cout << "POSSIBLE" << endl;
else if (chk(nxt, grundy[nxt] + ((grundy[st] + 1) == grundy[nxt]), grundy[st] + 1)) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
}
| a.cc: In function 'int main()':
a.cc:84:25: error: 'nxt' was not declared in this scope
84 | nxt = i;
| ^~~
a.cc:88:21: error: 'nxt' was not declared in this scope
88 | else if(chk(nxt, grundy[nxt] + (grundy[st] == grundy[nxt]), grundy[st])) cout << "POSSIBLE" << endl;
| ^~~
a.cc: In function 'int dfs(int, int)':
a.cc:30:18: warning: control reaches end of non-void function [-Wreturn-type]
30 | cycle[x] = 2;
| ~~~~~~~~~^~~
|
s732520167 | p03650 | C++ | #include<bits/stdc++.h>
using namespace std;
int n;
vector<int> out[200010];
int in[200010];
int cycle[200010];
int grundy[200010];
int st;
const int CYCLE = 42;
int dfs(int x, int p) {
cycle[x] = 1;
for(int i : out[x]) {
if(i != p or in[x] == i) {
if(cycle[i] == 1) {
st = i;
cycle[x] = CYCLE;
return CYCLE;
}
else if(cycle[i] == 0) {
if(dfs(i, x) == CYCLE) {
cycle[x] = CYCLE;
if(x == st) return 0;
else return CYCLE;
}
}
}
}
cycle[x] = 2;
}
int getgrundy(int x) {
set<int> s;
for(int i : out[x])
if(cycle[i] != CYCLE)
s.insert(getgrundy(i));
int ans = 0;
auto it = s.begin();
while(it != s.end()) {
if(*it == ans) {
++ans;
++it;
}
else return grundy[x] = ans;
}
return grundy[x] = ans;
}
bool chk(int x, int val, int res) {
if(x == st) return res == val;
int nxt;
for(int i : out[x]) {
if(cycle[i] == CYCLE) {
nxt = i;
}
}
return chk(nxt, grundy[nxt] + (grundy[nxt] == val), res);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
memset(cycle, 0, sizeof cycle);
for(int i = 0; i < n; ++i){
int x;
cin >> x;
--x;
out[x].push_back(i);
in[i] = x;
}
for(int i = 0; i < n; ++i) if(cycle[i] == 0) dfs(i, -1);
for(int i = 0; i < n; ++i) {
if(cycle[i] == CYCLE) getgrundy(i);
}
int nxt;
for(int i : out[st]) {
if(cycle[i] == CYCLE) {
nxt = i;
}
}
return cout << "POSSIBLE" << endl;
if(chk(nxt, grundy[nxt] + (grundy[st] == grundy[nxt]), grundy[st])) cout << "POSSIBLE" << endl;
else if (chk(nxt, grundy[nxt] + ((grundy[st] + 1) == grundy[nxt]), grundy[st] + 1)) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
}
| a.cc: In function 'int main()':
a.cc:83:35: error: cannot convert 'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} to 'int' in return
83 | return cout << "POSSIBLE" << endl;
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
| |
| std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}
a.cc: In function 'int dfs(int, int)':
a.cc:30:18: warning: control reaches end of non-void function [-Wreturn-type]
30 | cycle[x] = 2;
| ~~~~~~~~~^~~
|
s038466027 | p03650 | C++ | #include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define ran 222222
int n;
vector<int> e[ran];
int deg[ran];
int q[ran],lq;
vector<int> bad[ran];
int col[ran];
vector<int> _bad[ran];
int _col[ran];
void save(){
for(int i=1; i<=n; i++){
_bad[i] = bad[i];
_col[i] = col[i];
}
}
void rollback(){
for(int i=1; i<=n; i++){
bad[i] = _bad[i];
col[i] = _col[i];
}
}
bool chk(int x,int val,int cond){
int y = x;
while(true){
int z;
for(vector<int>::iterator it = e[y].begin(); it!=e[y].end(); it++){
z = *it;
if(col[z] == -1)break;
}
if(z == x){
if(cond == -1)return col[y] != val;
return col[y] == cond;
}else{
bad[z].push_back(y==x?val:col[y]);
sort(bad[z].begin(),bad[z].end());
bad[z].resize(unique(bad[z].begin(),bad[z].end())-bad[z].begin());
for(col[z] = 0; col[z] < bad[z].size() && bad[z][col[z]] == col[z]; col[z]++);
y = z;
}
}
}
int main(){
scanf("%d",&n);
for(int i=1; i<=n; i++){
int x;
scanf("%d",&x);
e[i].push_back(x);
deg[x] ++;
}
for(int i=1; i<=n; i++){
if(deg[i] == 0){
q[lq++] = i;
}
}
memset(col,-1,sizeof(col));
for(int i=0; i<lq; i++){
int x = q[i];
sort(bad[x].begin(),bad[x].end());
bad[x].resize(unique(bad[x].begin(),bad[x].end())-bad[x].begin());
for(col[x] = 0; col[x] < bad[x].size() && bad[x][col[x]] == col[x]; col[x]++);
for(vector<int>::iterator it = e[x].begin(); it!=e[x].end(); it++){
int y = *it;
bad[y].push_back(col[x]);
if(--deg[y] == 0){
q[lq++] = y;
}
}
}
for(int i=1; i<=n; i++)if(col[i] == -1){
int x = i;
sort(bad[x].begin(),bad[x].end());
bad[x].resize(unique(bad[x].begin(),bad[x].end())-bad[x].begin());
int Z;
for(Z = 0; Z < bad[x].size() && bad[x][Z] == Z; Z++);
save();
if(chk(x,Z,-1)){
puts("POSSIBLE");
return 0;
}
rollback();
int Z1=Z;
for(Z ++; Z-1 < bad[x].size() && bad[x][Z-1] == Z; Z++);
if(chk(x,Z,Z1)){
puts("POSSIBLE");
return 0;
}
puts("IMPOSSIBLE");
return 0;
}
puts("POSSIBLE");
return 0;
} | a.cc: In function 'int main()':
a.cc:63:9: error: 'memset' was not declared in this scope
63 | memset(col,-1,sizeof(col));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include<algorithm>
+++ |+#include <cstring>
4 | using namespace std;
|
s082874694 | p03650 | C++ | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define int long long
#define ull unsigned long long
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 500000;
int n;
int a[N], used[N], out[N], cycle[N], p[N], mark[N], t, b[N], q[N], k[N];
set < pair < int, int > > s;
vector < int > g[N], G[N], in[N], c[N];
void dfs(int v){
used[v] = 1;
for (auto u: g[v]){
if (u != p[v] && used[u] == 1 && cycle[u] == 0){
cycle[v] = 1;
while(v != u){
v = p[v];
cycle[v] = 1;
}
} else
if (used[u] == 0){
p[u] = v;
dfs(u);
}
}
used[v] = 2;
}
bool check(int v){
t = -1;
int res = -1;
for (auto u: G[v]){
t = max(t, mark[u]);
b[mark[u]] = 1;
}
for (int i = 0; i <= t + 1; i++){
if (b[i] == 0 && res == -1){
res = i;
}
b[i] = 0;
}
return res;
}
void tr(int V, int x){
for (auto i: c[V]) if (x == i) return;
for (int j = 0; j <= n; j++){
if (!cycle[j]) continue;
q[j] = 0;
mark[j] = 0;
}
int pr;
mark[V] = x;
int v = V;
for (auto u: in[V]) if (cycle[u]) v = u;
pr = x;
int ff = 0;
while(v != V){
int y = 0;
for (auto u: c[v]){
y = max(y, u);
b[u] = 1;
}
b[pr] = 1;
y = max(b[pr], y);
for (int j = 0; j <= y + 1; j++){
if (b[j] == 0){
if (q[v] == 1) continue;
mark[v] = j;
q[v] = 1;
}
b[j] = 0;
}
pr = mark[v];
for (auto u: in[v]) if (cycle[u]) v = u;
}
if (pr == mark[V]) return;
int y = mark[V];
int z = 1;
for (auto u: G[v]){
y = max(mark[u], y);
b[mark[u]] = 1;
}
for (int i = 0; i <= mark[V]; i++){
if (b[i] == 0 && i < mark[V]) z = 0;
b[i] = 0;
}
if (!z) return;
cout << "POSSIBLE";
exit(0);
}
main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++){
int u, v;
cin >> u;
v = i;
g[u].pb(v);
g[v].pb(u);
G[u].pb(v);
in[v].pb(u);
out[u]++;
}
dfs(1);
for (int i = 1; i <= n; i++) s.insert({out[i], i});
while(1){
auto x = *s.begin();
s.erase(s.begin());
if (x.F != 0) break;
if (cycle[x.S]) continue;
int f = check(x.S);
mark[x.S] = f;
for (auto u: in[x.S]){
s.erase({out[u], u});
out[u]--;
s.insert({out[u], u});
}
}
for (int i = 1; i <= n; i++) k[i] = -1;
for (int i = 1; i <= n; i++)
if (cycle[i]){
for (auto u: G[i]){
if (cycle[u]) continue;
c[i].pb(mark[u]);
k[i] = max(k[i], mark[u]);
}
}
for (int i = 1; i <= n; i++)
if (cycle[i]){
vector < int > cand;
for (auto j: c[i]) b[c[j]] = 1;
for (int j = 0; j <= n + 2; j++){
if (b[j] == 0) cand.pb(j);
b[j] = 0;
}
tr(i, cand[0]);
tr(i, cand[1]);
}
cout << "IMPOSSIBLE";
}
| a.cc:99:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
99 | main()
| ^~~~
a.cc: In function 'int main()':
a.cc:143:29: error: no match for 'operator[]' (operand types are 'long long int [500000]' and 'std::vector<long long int>')
143 | for (auto j: c[i]) b[c[j]] = 1;
| ^
|
s280357004 | p03650 | C++ | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i64 = int64_t;
const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
int N;
int p[202020];
vector<int> g[202020];
vector<int> rg[202020];
int a[202020];
bool check(int v, int n) {
a[v] = n;
int w = rg[v][0];
if (a[w] != -1) {
if (a[w] == 2 && a[v] != 1) return false;
if (a[w] == 1 && a[v] == 1) return false;
if (a[w] == 0 && a[v] == 0) return false;
return true;
}
if (n == 2) return check(w, (g[w].size() > 1) ? 1 : 0);
if (n == 1) return check(w, (g[w].size() <= 1) ? 0 : 2);
/* n == 0 */ return g[w].size() <= 1 && check(w, 1);
}
int main() {
cin.tie(0); ios::sync_with_stdio(false);
cin >> N;
for (int j = 0; j < N; ++j) {
cin >> p[j]; --p[j];
g[p[j]].push_back(j);
rg[j].push_back(p[j]);
}
int start = -1;
for (int j = 0; j < N; ++j) {
if (g[j].size() > 0) {
start = j;
break;
}
}
bool r = false;
fill(a, a+N, -1);
r = check(start, 1);
if (!r) {
fill(a, a+N, -1);
r = check(start, (g[start].size() <= 1) ? 0 : 2);
}
cout << (r ? POSSIBLE : IMPOSSIBLE) << endl;
return 0;
}
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i64 = int64_t;
const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
int N;
int p[202020];
vector<int> g[202020];
vector<int> rg[202020];
int a[202020];
bool check(int v, int n) {
a[v] = n;
int w = rg[v][0];
if (a[w] != -1) {
if (a[w] == 2 && a[v] != 1) return false;
if (a[w] == 1 && a[v] == 1) return false;
if (a[w] == 0 && a[v] == 0) return false;
return true;
}
if (n == 2) return check(w, (g[w].size() > 1) ? 1 : 0);
if (n == 1) return check(w, (g[w].size() <= 1) ? 0 : 2);
/* n == 0 */ return g[w].size() <= 1 && check(w, 1);
}
int main() {
cin.tie(0); ios::sync_with_stdio(false);
cin >> N;
for (int j = 0; j < N; ++j) {
cin >> p[j]; --p[j];
g[p[j]].push_back(j);
rg[j].push_back(p[j]);
}
int start = -1;
for (int j = 0; j < N; ++j) {
if (g[j].size() > 0) {
start = j;
break;
}
}
bool r = false;
fill(a, a+N, -1);
r = check(start, 1);
if (!r) {
fill(a, a+N, -1);
r = check(start, (g[start].size() <= 1) ? 0 : 2);
}
cout << (r ? POSSIBLE : IMPOSSIBLE) << endl;
return 0;
}
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i64 = int64_t;
const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
int N;
int p[202020];
vector<int> g[202020];
vector<int> rg[202020];
int a[202020];
bool check(int v, int n) {
a[v] = n;
int w = rg[v][0];
if (a[w] != -1) {
if (a[w] == 2 && a[v] != 1) return false;
if (a[w] == 1 && a[v] == 1) return false;
if (a[w] == 0 && a[v] == 0) return false;
return true;
}
if (n == 2) return check(w, (g[w].size() > 1) ? 1 : 0);
if (n == 1) return check(w, (g[w].size() <= 1) ? 0 : 2);
/* n == 0 */ return g[w].size() <= 1 && check(w, 1);
}
int main() {
cin.tie(0); ios::sync_with_stdio(false);
cin >> N;
for (int j = 0; j < N; ++j) {
cin >> p[j]; --p[j];
g[p[j]].push_back(j);
rg[j].push_back(p[j]);
}
int start = -1;
for (int j = 0; j < N; ++j) {
if (g[j].size() > 0) {
start = j;
break;
}
}
bool r = false;
fill(a, a+N, -1);
r = check(start, 1);
if (!r) {
fill(a, a+N, -1);
r = check(start, (g[start].size() <= 1) ? 0 : 2);
}
cout << (r ? POSSIBLE : IMPOSSIBLE) << endl;
return 0;
}
| a.cc:101:14: error: redefinition of 'const std::string POSSIBLE'
101 | const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
| ^~~~~~~~
a.cc:26:14: note: 'const std::string POSSIBLE' previously declared here
26 | const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
| ^~~~~~~~
a.cc:101:37: error: redefinition of 'const std::string IMPOSSIBLE'
101 | const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
| ^~~~~~~~~~
a.cc:26:37: note: 'const std::string IMPOSSIBLE' previously declared here
26 | const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
| ^~~~~~~~~~
a.cc:103:5: error: redefinition of 'int N'
103 | int N;
| ^
a.cc:28:5: note: 'int N' previously declared here
28 | int N;
| ^
a.cc:104:5: error: redefinition of 'int p [202020]'
104 | int p[202020];
| ^
a.cc:29:5: note: 'int p [202020]' previously declared here
29 | int p[202020];
| ^
a.cc:106:13: error: redefinition of 'std::vector<int> g [202020]'
106 | vector<int> g[202020];
| ^
a.cc:31:13: note: 'std::vector<int> g [202020]' previously declared here
31 | vector<int> g[202020];
| ^
a.cc:107:13: error: redefinition of 'std::vector<int> rg [202020]'
107 | vector<int> rg[202020];
| ^~
a.cc:32:13: note: 'std::vector<int> rg [202020]' previously declared here
32 | vector<int> rg[202020];
| ^~
a.cc:108:5: error: redefinition of 'int a [202020]'
108 | int a[202020];
| ^
a.cc:33:5: note: 'int a [202020]' previously declared here
33 | int a[202020];
| ^
a.cc:110:6: error: redefinition of 'bool check(int, int)'
110 | bool check(int v, int n) {
| ^~~~~
a.cc:35:6: note: 'bool check(int, int)' previously defined here
35 | bool check(int v, int n) {
| ^~~~~
a.cc:124:5: error: redefinition of 'int main()'
124 | int main() {
| ^~~~
a.cc:49:5: note: 'int main()' previously defined here
49 | int main() {
| ^~~~
a.cc:176:14: error: redefinition of 'const std::string POSSIBLE'
176 | const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
| ^~~~~~~~
a.cc:26:14: note: 'const std::string POSSIBLE' previously declared here
26 | const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
| ^~~~~~~~
a.cc:176:37: error: redefinition of 'const std::string IMPOSSIBLE'
176 | const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
| ^~~~~~~~~~
a.cc:26:37: note: 'const std::string IMPOSSIBLE' previously declared here
26 | const string POSSIBLE = "POSSIBLE", IMPOSSIBLE = "IMPOSSIBLE";
| ^~~~~~~~~~
a.cc:178:5: error: redefinition of 'int N'
178 | int N;
| ^
a.cc:28:5: note: 'int N' previously declared here
28 | int N;
| ^
a.cc:179:5: error: redefinition of 'int p [202020]'
179 | int p[202020];
| ^
a.cc:29:5: note: 'int p [202020]' previously declared here
29 | int p[202020];
| ^
a.cc:181:13: error: redefinition of 'std::vector<int> g [202020]'
181 | vector<int> g[202020];
| ^
a.cc:31:13: note: 'std::vector<int> g [202020]' previously declared here
31 | vector<int> g[202020];
| ^
a.cc:182:13: error: redefinition of 'std::vector<int> rg [202020]'
182 | vector<int> rg[202020];
| ^~
a.cc:32:13: note: 'std::vector<int> rg [202020]' previously declared here
32 | vector<int> rg[202020];
| ^~
a.cc:183:5: error: redefinition of 'int a [202020]'
183 | int a[202020];
| ^
a.cc:33:5: note: 'int a [202020]' previously declared here
33 | int a[202020];
| ^
a.cc:185:6: error: redefinition of 'bool check(int, int)'
185 | bool check(int v, int n) {
| ^~~~~
a.cc:35:6: note: 'bool check(int, int)' previously defined here
35 | bool check(int v, int n) {
| ^~~~~
a.cc:199:5: error: redefinition of 'int main()'
199 | int main() {
| ^~~~
a.cc:49:5: note: 'int main()' previously defined here
49 | int main() {
| ^~~~
|
s648065596 | p03650 | C++ | #include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
namespace lib
{
template<std::uint64_t Mod>struct modnum;
template<class T>constexpr T pow(T base, std::size_t p)
{
if (p == 0)
{
return T(1);
}
else if (p == 1)
{
return base;
}
else if (p == 2)
{
return base*base;
}
else if (p % 2 == 0)
{
return pow(pow(base, p / 2), 2);
}
else
{
return pow(pow(base, p / 2), 2)*base;
}
}
template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);
template<std::uint64_t Mod>struct modnum
{
static constexpr auto mod = Mod;
std::uint64_t val;
modnum() = default;
constexpr modnum(std::uint64_t v):val(v%Mod)
{
}
constexpr modnum& operator+=(modnum const& v)
{
val += v.val;
val %= mod;
return *this;
}
constexpr modnum& operator-=(modnum const& v)
{
val += mod - v.val;
val %= mod;
return *this;
}
constexpr modnum& operator*=(modnum const& v)
{
val *= v.val;
val %= mod;
return *this;
}
constexpr modnum& operator/=(modnum const& v)
{
return operator*=(inverse(v));
}
};
template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
{
return lhs += rhs;
}
template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
{
return lhs -= rhs;
}
template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
{
return lhs *= rhs;
}
template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
{
return lhs /= rhs;
}
template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
{
return pow(base, Mod - 2);
}
template<class T>constexpr auto clamp(T v)
{
return std::max(v, T());
}
template<class T>void sort(std::vector<T>& vec)
{
std::sort(vec.begin(), vec.end());
}
template<class T>auto lower_bound(std::vector<T>const& vec, T v)
{
return std::distance(vec.begin(), std::lower_bound(vec.begin(), vec.end(), v));
}
template<class T>auto upper_bound(std::vector<T>const& vec, T v)
{
return std::distance(vec.begin(), std::upper_bound(vec.begin(), vec.end(), v));
}
struct scope_exit
{
std::function<void(void)> func;
scope_exit(std::function<void(void)> f):func(f)
{
}
~scope_exit()
{
func();
}
};
template<int val>using int_tag = std::integral_constant<int, val>;
template<class Return, class Argument>struct minimam_searcher
{
Return operator()(std::function<Return(Argument)> func, Argument beg, Argument end)const
{
Return min = std::numeric_limits<Return>::max();
for (; beg != end; ++beg)
{
min = std::min(min, func(beg));
}
return min;
}
};
template<class Return, class Argument>constexpr minimam_searcher<Return, Argument> minimam{};
template<class T>T gcd(T a, T b)
{
if (a > b)
{
return gcd(b, a);
}
if (a == T())
{
return b;
}
return gcd(b%a, a);
}
static constexpr int intlog2(int x)
{
for (int i = 0, j = 2; i < 32; ++i, j <<= 1)
{
if (j > x)
{
return i;
}
}
return 32;
}
struct segtree
{
std::vector<std::int64_t> tree;
std::size_t depth_;
segtree(std::size_t depth):tree(std::size_t(1) << (depth + 1)), depth_(depth)
{
}
void change(std::size_t index, std::int64_t val)
{
change(index, val, 0);
}
std::int64_t get(std::size_t left, std::size_t right)//[left, right]の範囲
{
return get(left, right + 1, 0, 1, 0);
}
void increment(std::size_t index)
{
increment(index, 0);
}
void decrement(std::size_t index)
{
decrement(index, 0);
}
private:
std::int64_t change(std::size_t index, std::int64_t val, std::size_t dep)
{
auto shift = std::size_t(1) << dep;
auto s = std::size_t(1) << (depth_ - dep);
if (dep == depth_)
{
std::swap(tree[shift + index / s - 1], val);
return val;
}
else
{
auto v = change(index, val, dep + 1);
tree[shift + index / s - 1] += val - v;
return v;
}
}
std::int64_t get(std::size_t a, std::size_t b, std::size_t left, std::size_t right, std::size_t dep)
{
auto lshift = left << (depth_ - dep);
auto rshift = right << (depth_ - dep);
if (a <= lshift && rshift <= b)
{
return tree[(std::size_t(1) << dep) + left - 1];
}
else if (rshift <= a || b <= lshift)
{
return 0;
}
else
{
return
get(a, b, left << 1, left + right, dep + 1) +
get(a, b, left + right, right << 1, dep + 1);
}
}
void increment(std::size_t index, std::size_t dep)
{
auto shift = std::size_t(1) << dep;
auto s = std::size_t(1) << (depth_ - dep);
++tree[shift + index / s - 1];
if (dep != depth_)
{
increment(index, dep + 1);
}
}
void decrement(std::size_t index, std::size_t dep)
{
auto shift = std::size_t(1) << dep;
auto s = std::size_t(1) << (depth_ - dep);
--tree[shift + index / s - 1];
if (dep != depth_)
{
decrement(index, dep + 1);
}
}
};
}
namespace std
{
template<std::uint64_t Mod>decltype(auto) operator<<(ostream& ost, lib::modnum<Mod>const& v)
{
return ost << v.val;
}
}
void Main();
int main()
{
std::cin.tie(nullptr);
std::cin.sync_with_stdio(false);
Main();
}
bool check(std::vector<int>& redge, std::vector<std::set<int>>const& imp, int start, int now, int prev)
{
if (now == start)
{
return !imp[now].count(j) && prev == j;
}
int j = 0;
for (; j < 3; ++j)
{
if (!imp[now].count(j) && prev != j)
{
break;
}
}
return check(redge, imp, start, redge[now], j);
}
void Main()
{
int N;
std::cin >> N;
std::vector<std::pair<int, int>> edge(N);
std::vector<int> reverse_edge(N);
for (int i = 0; i < N; ++i)
{
int p;
std::cin >> p;
--p;
++edge[p].first;
edge[p].second = i;
reverse_edge[i] = p;
}
if (std::any_of(edge.begin(), edge.end(), [](auto const& v) {return v.size() == 0; }))
{
std::vector<std::set<int>> imp(N);
int start = 0;
for (int i = 0; i < N; ++i)
{
imp[i].emplace(0);
if (edge[i].first == 0)
{
int j = i;
do
{
j = reverse_edge[j];
start = j;
imp[j].emplace(1 - *(imp[edge[j].second].begin()));
} while (edge[j].first < 2);
}
}
int j = 0;
for (; j < 3; ++j)
{
if (!imp[start].count(j))
{
break;
}
}
if (check(reverse_edge, imp, start, reverse_edge[start], j))
{
std::cout << "POSSIBLE" << std::endl;
}
else
{
std::cout << "IMPOSSIBLE" << std::endl;
}
}
else
{
if (N % 2 == 0)
{
std::cout << "POSSIBLE" << std::endl;
}
else
{
std::cout << "IMPOSSIBLE" << std::endl;
}
}
} | a.cc:17:18: error: 'std::uint64_t' has not been declared
17 | template<std::uint64_t Mod>struct modnum;
| ^~~
a.cc:41:18: error: 'std::uint64_t' has not been declared
41 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);
| ^~~
a.cc:41:66: error: 'Mod' was not declared in this scope
41 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);
| ^~~
a.cc:41:69: error: template argument 1 is invalid
41 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);
| ^
a.cc:43:18: error: 'std::uint64_t' has not been declared
43 | template<std::uint64_t Mod>struct modnum
| ^~~
a.cc:76:18: error: 'std::uint64_t' has not been declared
76 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:76:68: error: 'Mod' was not declared in this scope
76 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:76:71: error: template argument 1 is invalid
76 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^
a.cc:76:85: error: 'Mod' was not declared in this scope
76 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:76:88: error: template argument 1 is invalid
76 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^
a.cc:76:51: error: 'constexpr auto lib::operator+(int, const int&)' must have an argument of class or enumerated type
76 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~~~~~~
a.cc:80:18: error: 'std::uint64_t' has not been declared
80 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:80:68: error: 'Mod' was not declared in this scope
80 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:80:71: error: template argument 1 is invalid
80 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^
a.cc:80:85: error: 'Mod' was not declared in this scope
80 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:80:88: error: template argument 1 is invalid
80 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^
a.cc:80:51: error: 'constexpr auto lib::operator-(int, const int&)' must have an argument of class or enumerated type
80 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~~~~~~
a.cc:84:18: error: 'std::uint64_t' has not been declared
84 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:84:68: error: 'Mod' was not declared in this scope
84 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:84:71: error: template argument 1 is invalid
84 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^
a.cc:84:85: error: 'Mod' was not declared in this scope
84 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:84:88: error: template argument 1 is invalid
84 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^
a.cc:84:51: error: 'constexpr auto lib::operator*(int, const int&)' must have an argument of class or enumerated type
84 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~~~~~~
a.cc:88:18: error: 'std::uint64_t' has not been declared
88 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:88:68: error: 'Mod' was not declared in this scope
88 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:88:71: error: template argument 1 is invalid
88 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^
a.cc:88:85: error: 'Mod' was not declared in this scope
88 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~
a.cc:88:88: error: template argument 1 is invalid
88 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^
a.cc:88:51: error: 'constexpr auto lib::operator/(int, const int&)' must have an argument of class or enumerated type
88 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
| ^~~~~~~~
a.cc:93:18: error: 'std::uint64_t' has not been declared
93 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
| ^~~
a.cc:93:66: error: 'Mod' was not declared in this scope
93 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
| ^~~
a.cc:93:69: error: template argument 1 is invalid
93 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
| ^
a.cc: In function 'constexpr auto lib::inverse(const int&)':
a.cc:95:34: error: 'Mod' was not declared in this scope
95 | return pow(base, Mod - 2);
| ^~~
a.cc: At global scope:
a.cc:172:34: error: 'int64_t' is not a member of 'std'; did you mean 'int64_t'?
172 | std::vector<std::int64_t> tree;
| ^~~~~~~
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:155,
from /usr/include/stdlib.h:514,
from /usr/include/c++/14/cstdlib:79,
from /usr/include/c++/14/ext/string_conversions.h:43,
from /usr/include/c++/14/bits/basic_string.h:4154,
from /usr/include/c++/14/string:54,
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/x86_64-linux-gnu/bits/stdint-intn.h:27:19: note: 'int64_t' declared here
27 | typedef __int64_t int64_t;
| ^~~~~~~
a.cc:172:41: error: template argument 1 is invalid
172 | std::vector<std::int64_t> tree;
| ^
a.cc:172:41: error: template argument 2 is invalid
a.cc:179:48: error: 'std::int64_t' has not been declared
179 | void change(std::size_t index, std::int64_t val)
| ^~~
a.cc:184:22: error: 'int64_t' in namespace 'std' does not name a type
184 | std::int64_t get(std::size_t left, std::size_t right)//[left, right]の範囲
| ^~~~~~~
a.cc:199:22: error: 'int64_t' in namespace 'std' does not name a type
199 | std::int64_t change(std::size_t index, std::int64_t val, std::size_t dep)
| ^~~~~~~
a.cc:216:22: error: 'int64_t' in namespace 'std' does not name a type
216 | std::int64_t get(std::size_t a, std::size_t b, std::size_t left, std::size_t right, std::size_t dep)
| ^~~~~~~
a.cc: In member function 'void lib::segtree::change(std::size_t, int)':
a.cc:181:31: error: no matching function for call to 'lib::segtree::change(std::size_t&, int&, int)'
181 | change(index, val, 0);
| ~~~~~~^~~~~~~~~~~~~~~
a.cc:179:22: note: candidate: 'void lib::segtree::change(std::size_t, int)'
179 | void change(std::size_t index, std::int64_t val)
| ^~~~~~
a.cc:179:22: note: candida |
s620288493 | p03650 | C++ | #include<bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> edge;
vector<int> st;
vector<int> cir;
int pat=-1;
set<int> cirs;
vector<int> a;
int namori(int v){
if(a[v]!=-1) return a[v];
vector<int> ss;
for(int i=0;i<edge[v].size();i++){
int to=edge[v][i];
if(!cirs.count(to)){
ss.push_back(namori(to));
}
}
if(ss.size()==0) return 0;
sort(ss.begin(),ss.end());
int res=ss[ss.size()-1]+1;
for(int i=0;i<n;i++){
if(i==0){
if(ss[i]!=0) return a[v]=0;
}
else{
if(ss[i-1]+1<ss[i]) return a[v]=ss[i-1]+1;
}
}
return a[v]=res;
}
int namori2(int v,int aaa){
if(a[v]!=-1) return a[v];
vector<int> ss;
ss.push_back(aaa);
for(int i=0;i<edge[v].size();i++){
int to=edge[v][i];
if(!cirs.count(to)){
ss.push_back(namori(to));
}
}
if(ss.size()==0) return 0;
sort(ss.begin(),ss.end());
int res=ss[ss.size()-1]+1;
for(int i=0;i<n;i++){
if(i==0){
if(ss[i]!=0) return a[v]=0;
}
else{
if(ss[i-1]+1<ss[i]) return a[v]=ss[i-1]+1;
}
}
return a[v]=res;
}
bool circuit(int v){
if(st[v]==1){
pat=v;
return 1;;
}
st[v]=1;
for(int i=0;i<edge[v].size();i++){
bool ret=circuit(edge[v][i]);
}
return 0;
}
bool f=false;
bool dfs(int v){
if(f&&v==pat){
return true;
}
f=true;
bool ret=false;
for(int i=0;i<edge[v].size();i++){
ret|=dfs(edge[v][i]);
}
if(ret){
cir.push_back(v);
}
return ret;
}
int main(){
cin>>n;
a.resize(n,-1);
edge.resize(n);
for(int i=0;i<n;i++){
int p;cin>>p;
p--;
edge[p].push_back(i);
}
st.resize(n,0);
for(int i=0;i<n;i++){
if(!st[i]) circuit(i);
}
if(pat==-1){
cout<<"POSSIBLE"<<endl;
return 0;
}
if(!dfs(pat)){
cout<<"POSSIBLE"<<endl;
return 0;
}
for(int i=0;i<cir.size();i++) cirs.insert(cir[i]);
vector<int> a(n);
for(int i=0;i<cir.size();i++){
namori(cir[i]);
}
vector<int> b(cir.size());
b[0]=a[cir[0]];
for(int i=1;i<cir.size();i++){
b[i]=namori2(cir[i],b[i-1]);
}
if(b[0]!=b[n-1]){
cout<<"POSSIBLE"<<endl;
return 0;
}
b[0]=a[cir[0]]+1;
for(int i=1;i<cir.size();i++){
b[i]=namori2(cir[i],b[i-1]);
}
if(b[0]!=b[n-1]){
cout<<"POSSIBLE"<<endl;
return 0;
}
cout<<"IMPOSSIBLE"<<endl;
| a.cc: In function 'int main()':
a.cc:131:30: error: expected '}' at end of input
131 | cout<<"IMPOSSIBLE"<<endl;
| ^
a.cc:85:11: note: to match this '{'
85 | int main(){
| ^
|
s324771953 | p03650 | C++ | #include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n;
vector<int> adj[200200];
int sol[200200];
int deg[200200];
int arr[200200];
int mex(vector<int> a){
sort(a.begin(),a.end());
for(int i=0;i<a.size();i++){
if(a[i] != i)return i;
}
return (int)a.size();
}
queue<int> bf;
pair<int,int> cycle[200200];
int h=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
sol[i]=-1;
int x;
scanf("%d",&x);
arr[i]=x;
deg[x]++;
adj[x].push_back(i);
}
for(int i=1;i<=n;i++){
if(deg[i]==0){
bf.push(i);
}
}
while(!bf.empty()){
int nd=bf.front();
bf.pop();
vector<int> g;
for(int i=0;i<adj[nd].size();i++){
g.push_back(sol[adj[nd][i]]);
}
sol[nd] = mex(g);
deg[arr[nd]] -- ;
if(deg[arr[nd]] == 0 ){
bf.push(arr[nd]);
}
}
int st,cnt_all=0;
for(int i=1;i<=n;i++){
if(sol[i]!=-1)continue;
st=i;
cnt_all++;
}
int mn=1<<20,cnt=0,prv=1<<20;
for(int i=1;i<=n;i++){
if(sol[i]!=-1)continue;
vector<int> g;
for(int j=0;j<adj[i].size();j++){
int ch=adj[i][j];
if(sol[ch]==-1)continue;
g.push_back(sol[ch]);
}
int mxxx=mex(g);
if(mn==mxxx){
cnt++;
} else if( mxxx < mn){
cnt = 1;
mn = mxxx;
}
}
if( cnt_all % 2 && cnt == cnt_all){
cout<<"IMPOSSIBLE"<<endl;
} else {
cout<<"POSSIBLE"<<endl;
}
return 0;
/*
bool is_first=true;
while(true){
vector<int> g;
for(int j=0;j<adj[st].size();j++){
int ch=adj[st][j];
if(sol[ch]==-1)continue;
g.push_back(sol[ch]);
}
int mxxx=mex(g);
if(mxxx==mn && mxxx != prv && !is_first){
break;
} else {
st= arr[st];
prv= mxxx;
}
is_first=false;
}
bool ok=true;
sol[st] = mn;
int end= st;
st=arr[st];
while(st != end){
vector<int> g;
for(int j=0;j<adj[st].size();j++){
int ch=adj[st][j];
if(sol[ch]==-1)continue;
g.push_back(sol[ch]);
}
int mxxx= mex(g);
}
*/
} | a.cc: In function 'int mex(std::vector<int>)':
a.cc:14:9: error: 'sort' was not declared in this scope; did you mean 'short'?
14 | sort(a.begin(),a.end());
| ^~~~
| short
|
s044771608 | p03650 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
int N;
vi g[200010];
int pr[200010];
int gr[200010];
int ot[200010];
set<int> st[200010];
int main() {
cin >> N;
rep(i, N) {
int p;
cin >> p;
--p;
g[p].pb(i);
pr[i] = p;
}
queue<int> que;
memset(gr, -1, sizeof(gr));
rep(i, N) {
ot[i] = (int)g[i].size();
if (ot[i] == 0) {
que.push(i);
}
}
while (!que.empty()) {
int v = que.front(); que.pop();
int x = 0;
while (st[v].count(x)) ++x;
gr[v] = x;
if (--ot[pr[v]] == i) {
que.push(pr[v]);
}
st[pr[v]].insert(x);
}
int rt;
rep(i, N) {
if (gr[i] == -1) {
rt = i;
break;
}
}
vi cand;
rep(i, N) {
if (!st[rt].count(i)) {
cand.pb(i);
if (cand.size() == 2) {
break;
}
}
}
bool ok = 0;
rep(ii, 2) {
gr[rt] = cand[ii];
int v = rt;
while (pr[v] != rt) {
int x = 0;
while (st[pr[v]].count(x) || gr[v] == x) ++x;
gr[pr[v]] = x;
v = pr[v];
}
int x = 0;
set<int> ss;
for (int to : g[rt]) {
ss.insert(gr[to]);
}
while (ss.count(x)) ++x;
if (gr[rt] == x) {
ok = 1;
break;
}
}
puts(ok ? "POSSIBLE" : "IMPOSSIBLE");
return 0;
} | a.cc: In function 'int main()':
a.cc:52:36: error: 'i' was not declared in this scope
52 | if (--ot[pr[v]] == i) {
| ^
|
s033060218 | p03650 | C++ | #include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, lint> pi;
const int MAXN = 200005;
vector<int> gph[MAXN];
int n, a[MAXN], deg[MAXN];
int g1[MAXN], g2[MAXN];
int ans[MAXN];
int dfs(int x){
set<int> s;
for(auto &i : gph[x]){
s.insert(dfs(i));
}
for(int i=0; ; i++){
if(s.find(i) == s.end()) return i;
}
}
bool solve(int x){
int prv = x;
for(int j=a[x]; ; j=a[j]){
int tmp = (ans[prv] == g1[j] ? g2[j] : g1[j]);
if(j == x){
return tmp == ans[j];
}
ans[j] = tmp;
prv = j;
}
}
int main(){
scanf("%d",&n);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
gph[a[i]].push_back(i);
deg[a[i]]++;
}
queue<int> que;
for(int i=1; i<=n; i++) if(!deg[i]) que.push(i);
while(!que.empty()){
int x = que.front();
que.pop();
deg[a[x]]--;
if(!deg[a[x]]) que.push(a[x]);
}
int piv = 0;
for(int i=1; i<=n; i++){
if(!deg[i]) continue;
piv = i;
set<int> s;
for(auto &j : gph[i]){
if(!deg[j]) s.insert(dfs(j));
}
int cnt = 0;
for(int j=0; ; j++){
if(s.find(j) == s.end()){
if(cnt == 0) g1[i] = j;
if(cnt == 1) g2[i] = j;
cnt++;
}
if(cnt == 2) break;
}
}
ans[piv] = g1[piv];
if(solve(piv)){
puts("POSSIBLE");
return 0;
}
ans[piv] = g2[piv];
if(solve(piv)){
puts("POSSIBLE");
return 0;
}
puts("IMPOSSIBLE");
}
| a.cc:1:10: fatal error: aliens.h: No such file or directory
1 | #include "aliens.h"
| ^~~~~~~~~~
compilation terminated.
|
s896884285 | p03651 | C++ | #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;
#define int ll
int gcd(int a, int b) {
if (a > b) {
int c = a;
a = b;
b = c;
}
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
int gcd_of_all(vi v){
int l = v.size();
int temp = v[0];
for(int i = 0; i < l ; i++){
temp = gcd(temp,v[i]);
}
return temp;
}
int main(){
int N,K; cin >> N >> K;
vi A(N); rep(i,N) cin >> A[i];
int g = gcd_of_all(A);
bool flag = false;
for(int i = 0; i < N; i++){
if(A[i] - K >= 0){
if((A[i] - K)%g == 0){
flag = true;
break;
}
}
}
if(flag){
cout << "POSSIBLE" << endl;
}else{
cout << "IMPOSSIBLE" << endl;
}
sysp;
} | a.cc:45:13: error: '::main' must return 'int'
45 | #define int ll
| ^~
a.cc:70:1: note: in expansion of macro 'int'
70 | int main(){
| ^~~
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.