akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) {
        cin >> a[i];
    }
    RFOR(i, n - 1, 0, 2) {
        cout << a[i] << " ";
    }
    int s = n % 2;
    FOR(i, s, n, 2) {
        cout << a[i] << " ";
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3712
a=[[0 for i in range(10)] for j in range(10)]
n=int(input())
for i in range(1,n+1):
    s=str(i)
    a[int(s[0])][int(s[-1])]+=1
ans=0
for i in range(1,10):
    for j in range(i+1,10):
        ans+=a[i][j]*a[j][i]*2
#print(ans)
for i in range(1,10):
    ans+=a[i][i]+a[i][i]*(a[i][i]-1)
    #print(i,ans)
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int x, n;
	cin >> x >> n;
	vector<int> p(110, 0);
	int inp;
	for (int i = 0; i < n; i++) {
		cin >> inp;
		p[inp] = 1;
	}
	int l = x;
	int r = x;
	for (;;) {
		if (l >= 0 && l <= 100 && p[l] == 0) {
			cout << l;
			break;
		}
		if (r >= 0 && r <= 100 && p[r] == 0) {
			cout << r;
			break;
		}
		if (l <= 0) {
			cout << l;
			break;
		}
		if (r > 100) {
			cout << r;
			break;
		}
		l--;
		r++;

	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>a(n,0);
rep(i,n)cin>>a[i];
int brick_num = 0;
int x = 1;
rep(i,n){
    if (a[i] == x){
        x++;
    }
    else{
        brick_num++;
    }
}
int ans = (brick_num == n) ? -1 : brick_num;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1024
// AOJ 1138: Traveling by Stagecoach
// 2017.11.18 bal4u@uu

#include <stdio.h>
//#include <stdlib.h>
#include <string.h>

#define QMAX 50000
typedef struct { double t; int node, c; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
//	*n = que[0].node, *t = que[0].t, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
//	return 1;
}

void enq(int n, double t, int c)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].t = t, que[i].node = n, que[i].c = c;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 1e10
#define MAX 31
typedef struct { int to[MAX], d[MAX]; } TBL;
TBL tbl[MAX];
int len[MAX];
int t[8];
double node[MAX][256];

void dijkstra(int start, int goal, int N)
{
	int i, j, jj, s, e, c, cc, lim;
	double tm, tt;

	qsize = 0;
	memset(node, 0x50, sizeof(node));
	for (lim = 1<<N, i = 0; i < lim; i++) node[goal][i] = INF;
	enq(start, 0, 0);
	while (qsize) {
		s = que[0].node, tm = que[0].t, c = que[0].c, deq();
		for (jj = 1, j = 0; j < N; j++, jj <<= 1) {
			if (c & jj) continue;
			cc = c | jj;
			for (i = 0; i < len[s]; i++) {
				e = tbl[s].to[i];
				tt = tm + (double)tbl[s].d[i]/t[j];
				if (tt < node[e][cc]) {
					node[e][cc] = tt;
					enq(e, tt, cc);
				}
			}
		}
	}
}

char buf[40], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int N, M, P, A, B, i, k, x, y, z, lim;
	double ans;

	while (fgets(bp=buf, 40, stdin) && *bp != '0') {
		N = getint(), bp++, M = getint(), bp++;
		P = getint(), bp++, A = getint()-1, bp++, B = getint()-1;
		memset(len, 0, sizeof(len));
		fgets(bp=buf, 40, stdin);
		for (i = 0; i < N; i++) t[i] = getint(), bp++;
		for (i = 0; i < P; i++) {
			fgets(bp=buf, 40, stdin);
			x = getint()-1, bp++, y = getint()-1, bp++, z = getint();
			k = len[x], tbl[x].to[k] = y, tbl[x].d[k] = z, len[x]++;
			k = len[y], tbl[y].to[k] = x, tbl[y].d[k] = z, len[y]++;
		}
		dijkstra(A, B, N);
		for (ans = INF, lim = 1<<N, i = 0; i < lim; i++) {
			if (node[B][i] < ans) ans = node[B][i];
		}
		if (ans == INF) puts("Impossible");
		else printf("%lf\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2472
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fi first
#define so second
#define ps push_back
#define pii pair<int,int>
#define mod 1000000007
#define TT int t;cin>>t;while(t--)

signed main()
{
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<a[k-1];
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repm(i, a, n) for (int i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int kaijo(int x)
{
    int ans = 1;
    rep(i, 1, x + 1) ans *= i;
    return ans;
}

string n_shin(int x, int n)
{
    string s;
    while (x > 0)
    {
        s += to_string(x % n + 1);
        x /= n;
    }
    while (s.size() < n)
    {
        s += '0';
    }
    s.reserve();
    //cout << s << endl;
    return s;
}

int main()
{
    int n;
    cin >> n;
    vi p(n), q(n);
    rep(i, 0, n) cin >> p[i];
    rep(i, 0, n) cin >> q[i];

    int a, b, sp = 0;
    vi array;
    rep(i, 1, n + 1) array.push_back(i);
    do
    {
        sp++;
        rep(i, 0, n)
        {
            if (array[i] != p[i])
                break;
            if (i == n - 1)
                a = sp;
        }
        rep(i, 0, n)
        {
            if (array[i] != q[i])
                break;
            if (i == n - 1)
                b = sp;
        }

    } while (next_permutation(array.begin(), array.end()));
    cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll n,m,ui,vi,tot;
ll head[110001],nxt[210001],point[210001],num[2],color[210001];
bool ok;
void addedge(int x,int y){
	tot++;nxt[tot]=head[x];head[x]=tot;point[tot]=y;
	tot++;nxt[tot]=head[y];head[y]=tot;point[tot]=x;
}
void dfs(int now){
	for(int tmp=head[now];tmp;tmp=nxt[tmp]){
		int v=point[tmp];
		if(color[v]){
			if(color[v]==color[now]){
				ok=true;
				return;
			}
		}
		else{
			color[v]=color[now]^1;
			num[color[v]-2]++;
			dfs(v);
			if(ok)return;
		}
	}
}
int main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%lld%lld",&ui,&vi);
		addedge(ui,vi);
	}
	color[1]=2;
	num[0]++;
	dfs(1);
	if(ok)
		printf("%lld\n",n*(n-1)/2-m);
	else
		printf("%lld\n",n*(n-1)/2-m-num[0]*(num[0]-1)/2-num[1]*(num[1]-1)/2);
	return 0;
} 

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;

ifstream in ("test.in" );
ofstream out("test.out");

const int DIM = 2e5 + 5;

int dst[2][DIM];
vector<int> edg[DIM];

void dfs(int k, int x, int f) {
    dst[k][x] = dst[k][f] + 1;
    
    for (int y : edg[x])
        if (y != f)
            dfs(k, y, x);
    
    return;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n;
    cin >> n;
    
    for (int i = 1; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        
        edg[x].push_back(y);
        edg[y].push_back(x);
    }
    
    dst[0][0] = dst[1][0] = -1;
    dfs(0, 1, 0); dfs(1, n, 0);
    
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans += (dst[0][i] <= dst[1][i]);
    
    cout << ((ans > n / 2) ? "Fennec" : "Snuke" );
    return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>

using namespace std;

#define int long long

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
signed main() {
	int k;
	cin >> k;
	cout << a[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC84 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

is_prime = [1]*(10**5+1)
is_prime[0] = 0
is_prime[1] = 0
for i in range(2,10**5+1):
    for j in range(i*2,10**5+1,i):
        is_prime[j] = 0

ansprime = [float('inf')]*(10**5)
for i in range(1,10**5+1,2):
    if is_prime[i] and is_prime[(i+1)//2]:
        ansprime[i] = i
ansprime.sort()
q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    li = bisect.bisect_left(ansprime,l)
    ri = bisect.bisect_right(ansprime,r)
    print(ri-li)


Measured memory_bytes: 5312
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[100010],b[100010];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i];
	long long ans=0;
	for(int i=n-1;i>=0;i--){
		long long k=a[i]+ans;
		long long r=k/b[i]*b[i];
		if(r<k)r+=b[i];
		ans=r-a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;

ll ans = 1e12;
int main(){
    ll n;
    cin >> n;
    for(ll i=sqrt(n);i>0;i--){
        if(n%i==0){
            ll temp = i+(n/i)-2;
            if(temp < ans){
                  ans = temp;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int n;
	cin >> n;
	auto count = 0;
	int d = log10(n) + 1;
	if (d % 2 == 1) count += n - pow(10, d - 1) + 1;
	for (auto i = d-1; i > 0; --i) {
		if (i % 2 == 1) {
			count += static_cast<int>(pow(10, i) - pow(10, i - 1));
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string s[10];
  rep(i, 3) {
    cin >> s[i];
  }

  cout << s[0][0] << s[1][1] << s[2][2] << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    double a;
    cin>>a;
    doublecout(a*M_PI*2.0);
    return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A.at(i) >> B.at(i);
  long ans = 0;
  for (int i = N - 1; i >= 0; i--) {
    A.at(i) += ans;
    if (A.at(i) % B.at(i) == 0) continue;
    ans += B.at(i) - A.at(i) % B.at(i);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 4812
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A,B,C,D;
  cin >> A>>B>>C>>D;
  if (A+B>C+D){
    cout << "Left" << endl;
  }
  if(A+B<C+D){
    cout << "Right" << endl;
  }
if(A+B==C+D){
  cout << "Balanced"<< endl;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   long long int n;
   cin>>n;
   long long int f=fact(n);
   cout<<f;

    return 0;
}








Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	
	ll n;
	string s, t;
	cin >> n >> s >> t;
	FOR(m,n,2*n+1) {
		bool ok = true;
		string r(m,' ');
		FOR(i,0,n) r[i] = s[i];
		FOR(i,0,n) if (r[i+m-n] != ' ' && r[i+m-n] != t[i]) ok = false;
		if (ok) {
			cout << m << endl;
			return 0;
		}
	}
	exit(1);


}



Measured memory_bytes: 256
#include <cstdio>
#include <unordered_set>
const int HALF = 2;
const int MAXS = 4;
char S[MAXS + 5];

int main() {
  scanf("%s", S);
  std::unordered_set<char> dict(S, S + MAXS);
  puts((dict.size() == HALF) ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;

#define int long long
#define double long double
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << '\n';
#define fi first
#define se second
#define pb push_back
//typedef long long ll;
typedef pair<int, int> pii;
 
void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}

const int mod = 1e9 + 7;

int add(int a, int b) {
	a += b;
	if (a >= mod) return a - mod;
	return a;
}

int mult(int a, int b) {
	return a * b % mod;
}

int sub(int a, int b) {
	a -= b;
	if (a < 0) return a + mod;
	return a;
}

signed main() {
	fast();
	int n;
	cin >> n;
	int a = 1, b = 1, c = 1;
	for (int i = 0; i < n; i++) {
		a = mult(a, 10);
		b = mult(b, 9);
		c = mult(c, 8);
	}
	cout << sub(add(a, c), add(b, b));
	return 0;
}

Measured memory_bytes: 3648
N, M = map(int, input().split())
S = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    S[a-1].append(b-1)
    S[b-1].append(a-1)

print("POSSIBLE" if set(S[0]) & set(S[N-1]) else "IMPOSSIBLE")


Measured memory_bytes: 48580
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = Integer.parseInt(stdIn.next());
        int[] p = new int[n];
        p[0] = Integer.parseInt(stdIn.next());
        int min = p[0];
        int ans = 1;
        for (int i = 1; i < n; i++) {
            p[i] = Integer.parseInt(stdIn.next());
            if (min > p[i]) {
                min = p[i];
                ans++;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 50244
#include <stdio.h>
int main(void){
    int N, i, max, cnt;
    int H[20];
    max = 0;
    cnt = 0;
    scanf("%d", &N);
    for(i = 0; i < N; i++){
        scanf("%d", &H[i]);
    }
    
    for(i = 0; i < N; i++){
        if(max <= H[i]){
            max = H[i];
            cnt = cnt + 1;
        }   
        
    }
    printf("%d", cnt);

    
}


Measured memory_bytes: 128
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = map(int, input().split())

lx = [None] * n
ly = [None] * m
sx = set([-10**10, 0, 10**10])
sy = set([-10**10, 0, 10**10])
ix = 0
iy = 0
for i in range(n):
    t = tuple(map(int, input().split()))
    lx[i] = t
    sx.add(t[0])
    sx.add(t[1])
    sy.add(t[2])
        
for i in range(m):
    t = tuple(map(int, input().split()))
    ly[i] = t
    sx.add(t[0])
    sy.add(t[1])
    sy.add(t[2])
        
xs = list(sx)
ys = list(sy)
xs.sort(); ys.sort()

wx = len(xs)*2
wy = len(ys)*2
bs = [[1]*wy for _ in range(wx)]
import bisect
for i, (x0, x1, y) in enumerate(lx):
    ix0 = bisect.bisect_left(xs, x0)*2
    ix1 = bisect.bisect_left(xs, x1)*2
    iy = bisect.bisect_left(ys, y)*2
    for ii in range(ix0, ix1):
        bs[ii][iy] = -1
for i, (x, y0, y1) in enumerate(ly):
    ix = bisect.bisect_left(xs, x)*2
    iy0 = bisect.bisect_left(ys, y0)*2
    iy1 = bisect.bisect_left(ys, y1)*2
    for ii in range(iy0, iy1):
        bs[ix][ii] = -1

xx = bisect.bisect_left(xs, 0)*2+1
yy = bisect.bisect_left(ys, 0)*2+1
s = [(xx,yy)]
dx = [-1,0,1,0]
dy = [0,-1,0,1]
ans = 0
end = False
while s:
    ix,iy = s.pop()
    for x, y in zip(dx,dy):
        ixx = ix + x
        iyy = iy + y
        if bs[ixx][iyy]!=1:
            continue
        ixx += x
        iyy += y
        if bs[ixx][iyy]!=1:
            continue
        if ixx<0 or ixx>=wx-1 or iyy<0 or iyy>=wy-1:
            print("INF")
            s = []
            end = True
            break
        bs[ixx][iyy] = 2
        ans += (xs[ixx//2+1] - xs[ixx//2]) * (ys[iyy//2+1] - ys[iyy//2])
        s.append((ixx, iyy))
            
if not end:
    print(ans)


Measured memory_bytes: 640304
n = int(input())
h = [int(i) for i in input().split()]
max_cnt, cnt = 0, 0
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        cnt += 1
    else:
        cnt = 0
    max_cnt = max(max_cnt, cnt)
print(max_cnt)

Measured memory_bytes: 20100
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int W, H, N;
int x[100], y[100], a[100];

int main() {
    cin >> W >> H >> N;
    rep(i, N) cin >> x[i] >> y[i] >> a[i];

    int x_min = 0;
    int x_max = W; 
    int y_min = 0;
    int y_max = H;

    rep(i, N) {
        switch (a[i]) {
        case 1:
            x_min = max(x[i], x_min);
            x_min = min(x_max, x_min);
            break;
        case 2:
            x_max = min(x[i], x_max);
            x_max = max(x_max, x_min);
            break;
        case 3:
            y_min = max(y[i], y_min);
            y_min = min(y_max, y_min);
            break;
        case 4:
            y_max = min(y[i], y_max);
            y_max = max(y_max, y_min);
            break;
        default:
            break;
        }
    }

    // printf("x_min: %d x_max: %d y_min: %d y_max: %d\n", x_min, x_max, y_min, y_max);
    cout << max(0, (x_max - x_min) * (y_max - y_min)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100000
using namespace std;
int a[maxn+10],a0[maxn+10];
int find(int x,int n,int *a){
	int l=1,r=n;
	while(l<=r){
		int m=l+r>>1;
		if(a[m]==x)return m;
		if(a[m]>x)r=m-1;
		else l=m+1;
	}
}
int cnt[maxn+10];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i),a0[i]=a[i];
	sort(a0+1,a0+n+1);
	int tot=1;
	for(int i=2;i<=n;i++)if(a0[i]!=a0[i-1])a0[++tot]=a0[i];
	for(int i=1;i<=n;i++)a[i]=find(a[i],tot,a0),cnt[a[i]]++;
	int ans=0;
	for(int i=1;i<=tot;i++)if(cnt[i]<a0[i])ans+=cnt[i];
	else ans+=cnt[i]-a0[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int cnt=0,max=0;
    String str=sc.next();
    sc.close();
    for(int i=0;i<n;i++){
      switch(str.charAt(i)){
        case 'I':
        cnt++;
        if(cnt>max){
          max++;
        }
        break;
        case 'D':
        cnt--;
        break;
      }
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;


int main(){

    int x, n;
    cin >> x >> n;

    map<int, int> m;
    for(int i = 0; i < n; i++ ){
        int val;
        cin >> val;
        m[val] ++;
    }

    int ans = 1000000;
    int ret = 0;
    for(int i = -10; i <= 110; i++){
        if( m[i] == 0 ){
            if( abs(x - i) < ans ){
                ans = abs(x - i);
                ret = i;
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3632
X = {1, 3, 5, 7, 8, 10, 12}
Y = {4, 6, 9, 11}
Z = {2}

L = list(map(int, input().split()))
S = set(L)
if len(X-S)==5 or len(Y-S)==2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let S: String = read();
    // xを除いて回文じゃなかったら-1
    // 回文だったらある文字とある文字の間にxが何個あるかを回文と比較
    let non_x = S.replace("x", "");
    let non_x_rev: String = non_x.chars().rev().collect();
    if non_x != non_x_rev {
        println!("-1");
        return;
    }
    // 計算の都合上xを前後に足しておく
    let S = "x".to_string() + &S + "x";
    let chars: Vec<_> = S.chars().collect();
    let mut i = 0;
    let count = S.chars().count();
    let mut x_counts = vec![];
    while i < count {
        let mut skip_count = 0;
        while i < count && chars[i] == 'x' {
            skip_count += 1;
            i += 1;
        }
        x_counts.push(skip_count);
        i += 1;
    }
    let x_counts_rev: Vec<_> = x_counts.iter().rev().collect();
    let mut ans = 0;
    for (i, v) in x_counts.iter().enumerate() {
        ans += std::cmp::max(v, x_counts_rev[i]) - std::cmp::min(v, x_counts_rev[i]);
    }
    println!("{}", ans / 2);
}


Measured memory_bytes: 6396
fn main() {
    use std::io;
    let stdin = io::stdin();
    let mut r = util::Reader::new(stdin.lock());
    let a = r.reads::<usize>();
    let b = r.reads::<usize>();
    let x = r.readl::<usize>();

    let ans = if a > x || a + b < x { "NO" } else { "YES" };

    println!("{}", ans);
}
mod util {

    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct Reader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> Reader<R> {
        pub fn new(reader: R) -> Self {
            Reader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        // 区切り文字：スペース
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        // 区切り文字：改行
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            // self.bufに次のトークンをセットする
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (), // 区切り文字だけなのでもう一度ループ
                    _ => {
                        // トークンが得られた
                        // 最後の文字が区切り文字なら削除
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break; // ループから脱出
                    }
                }
            }

            // 文字列をT型へパースする
            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse()
                .unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
        }
    }

}

Measured memory_bytes: 4352
n,x,y = map(int,input().split())
cnt_l = [0]*n
from collections import deque
# 幅優先探索
def bfs(start):
    queue = deque()
    queue.append(start)
    step_counts = [-1]*(n+1)
    step_counts[start] = 0
    while(queue):
        i = queue.popleft()
        cnt = step_counts[i]
        # 隣のグラフを取得
        if(i==x):
            nex_l = (i-1,y,i+1)
        elif(i==y):
            nex_l = (i-1,x,i+1)
        else:
            nex_l = (i-1,i+1)

        cnt += 1
        for j in nex_l:
            # 端より先だと止める
            if(j < 1 or n < j):
                continue
            # 訪問済みだと止める
            if(step_counts[j]!=-1):
                continue
            queue.append(j)
            step_counts[j] = cnt
            cnt_l[cnt] += 1

for i in range(1,n+1):
    bfs(i)

for i in range(1,n):
    # (a,b),(b,a)のペアがあるため//2
    print(cnt_l[i]//2)


Measured memory_bytes: 9620
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	map<int, int> m;
	for(int i = 0; i < 3; i++) {
		int x; cin >> x;
		if(!m.count(x)) m[x] = 1;
		else m[x]++;
	}
	string ans;
	if(m[5] == 2 && m[7] == 1) ans = "YES";
	else ans = "NO";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,m;cin >> n >> m;
    vector<P> v(m);
    rep(i, m) {
        int a,b;cin >> a >> b;
        v[i]={--b,a};
    }
    sort(all(v));
    int count=0;
    int k = 0;
    // cout << "OK\n";
    rep(i, m) {
        if(k<v[i].second) count++,k=v[i].first;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4788
N, M, K = map(int, input().split())


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.size = [1 for i in range(n)]

    def find(self, x):
        if self.par[x] != x:
            self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        if self.size[x] > self.size[y]:
            x, y = y, x
        self.par[x] = y
        self.size[y] += self.size[x]


uf = UnionFind(N)
fri = []
rst = [0]*N

for m in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    fri.append((A, B))
    uf.unite(A, B)

for i in range(N):
    ind = uf.find(i)
    rst[i] = uf.size[ind]-1

for f in fri:
    A, B = f
    if uf.par[A] == uf.par[B]:
        rst[A] -= 1
        rst[B] -= 1

for k in range(K):
    C, D = map(int, input().split())
    C -= 1
    D -= 1
    if uf.par[C] == uf.par[D]:
        rst[C] -= 1
        rst[D] -= 1

print(" ".join(map(str, rst)))


Measured memory_bytes: 35824
// B.

#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int a, b;
	cin >> a >> b;
	int d = b - a;
	int t = (d * (d + 1)) / 2;
	cout << (t - b) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n;
string s;

int32_t main(){_
   
   cin >> s;
   n = (int)(s.size());

   int ans = 0, cntA = 0;
   for (int i = 0; i < n; )
   {
      if (s[i] != 'A'){
         cntA = 0;
         ++i;
         continue;
      }

      int cntBC = 0;
      int j = i;
      while(j < n and s[i] == s[j]){
         ++j;
      }
      cntA += j-i;
      i = j;

      for (; i+1 < n; )
      {
         if (s[i] == 'B' and s[i+1] == 'C'){
            cntBC++;
            i += 2;
         }
         else{
            break;
         }
      }
      if (cntBC == 0){
         cntA = 0;
      }
      ans += cntA * cntBC;
   }
   
   cout<<ans;
   return 0;
}

Measured memory_bytes: 720
#include <utility>
#include <vector>
#include <iostream>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string ans = "Three";
    REP(i,N){
        char c;   
        cin >> c;
        if (c == 'Y'){
            ans = "Four";
        }
    }

    cout << ans <<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n; 
	cin>>n;
	int a[n];
			for(int i=0;i<n;i++)
			{
			cin>>a[i];
			
			}
	int kazu=0;
	for(int j=0;j<=n;j++)
	{
			int flag=0;
				for(int i=1;i< n;i++)
				{
					if(a[i]<a[i-1])
					{
						flag=1;
					int x=a[i];
						a[i]=a[i-1];
						a[i-1]=x;
					
					
						kazu++;
					}
				
				}
							if(flag==0)
							{	
							break;
								}

		}
	for(int i=0;i<n;i++)
	{
		if(i!=n-1)
		{
		cout<<a[i]<<" ";
		}
		else
		{
		cout<<a[i]<<endl;
		}
		
	}
	
	cout<<kazu<<endl;
		
		
	
}





Measured memory_bytes: 3104
#include <bits/stdc++.h>


using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);


    int h, w;
    cin>>h>>w;
    int n; cin>>n;
    vector<int> a(n);
    for (int i = 0; i<n; i++) cin>>a[i];
    vector<int> colors;
    for (int i = 1; i<=n; i++) for (int j = 0; j<a[i-1]; j++) colors.push_back(i);

    vector<pair<int, int>> cells;
    for (int i = 0; i<h; i++)
    {
        if (i%2==0)
        {
            for (int j = 0; j<w; j++) cells.push_back(mp(i, j));
        }
        else
        {
            for (int j = w-1; j>=0; j--) cells.push_back(mp(i, j));
        }
    }

    vector<vector<int>> board(h, vector<int>(w));
    for (int i = 0; i<h*w; i++)
    {
        board[cells[i].first][cells[i].second] = colors[i];
    }

    for (int i = 0; i<h; i++)
    {
        for (int j = 0; j<w; j++) cout<<board[i][j]<<' ';
        cout<<endl;
    }

}



Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>

#define     MAX_NUMBER     200

using namespace std;

int main(){
	int num1,num2;
	char str[10];
	int i;

	while(cin >> num1 >> num2){
		//整形
		sprintf(str,"%d\0",(num1 + num2));

		// 文字数計測
		for(i=0;str[i] != '\0';i++){
		}

		// 文字数表示
		cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String[] s = in.readLine().split(" ");
			int N = Integer.parseInt(s[0]);
			int Q = Integer.parseInt(s[1]);
			if (N == 0 && Q == 0) {
				break;
			}
			int[] p = new int[N + 1];
			for (int i = 2; i <= N; i++) {
				p[i] = Integer.parseInt(in.readLine());
			}
			
			char[] c = new char[Q + 1];
			int[] v = new int[Q + 1];
			boolean[] marked = new boolean[N + 1];
			marked[1] = true;
			for (int j = 1; j <= Q; j++) {
				s = in.readLine().split(" ");
				c[j] = s[0].charAt(0);
				v[j] = Integer.parseInt(s[1]);
				if (c[j] == 'M') {
					if (marked[v[j]]) {
						c[j] = ' ';
					} else {
						marked[v[j]] = true;
					}
				}
			}
			int[] parent = new int[N + 1];
			for (int i = 1; i <= N; i++) {
				parent[i] = marked[i] ? -1 : p[i];
			}
			
			long sum = 0;
			for (int j = Q; j >= 1; j--) {
				if (c[j] == 'M') {
					parent[v[j]] = p[v[j]];
				}
				if (c[j] == 'Q') {
					ArrayList<Integer> list = new ArrayList<Integer>();
					int i = v[j];
					while (parent[i] != -1) {
						list.add(i);
						i = parent[i];
					}
					for (int _i: list) {
						parent[_i] = i;
					}
					sum += i;
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 158584
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] A = new int[n];

    for(int i=0;i<n;i++){
      A[i]= sc.nextInt();
    }
    for(int j=n-1;j>0;j--){
      System.out.print(A[j] + " ");
    }
    System.out.println(A[0]);
    sc.close();
  }
}


Measured memory_bytes: 26412
#![allow(unused_imports)]
use num::Integer;
use proconio::*;
use std::ops::*;
use std::collections::VecDeque;

fn main() {
   input! {
       n: usize,
       mut c: [usize; n],
       e: [(usize, usize); n-1]
   }
   let mut to = vec![Vec::<usize>::new(); n];
   for (a, b) in &e {
      to[a - 1].push(b - 1);
      to[b - 1].push(a - 1);
   }
   for x in &mut c {
      *x -= 1;
   }
   let mut vin = vec![0; n];
   let mut vout = vec![0; n];

   {
       let mut stack = VecDeque::<usize>::new();
       stack.push_back(0);
       let mut k = 0;
       let mut yet = vec![false; n];
       while let Some(v) = stack.back().map(|v| *v as usize) {
           if !yet[v] {
               vin[v] = k;
               k += 1;
               yet[v] = true;
           }
           let mut flag = true;
           for u in to[v].iter().copied() {
               if yet[u] {
                   continue;
               }
               flag = false;
               stack.push_back(u);
           }
           if flag {
               vout[v] = k;
               stack.pop_back();
           }
       }
   }

   let mut vs = vec![Vec::<usize>::new(); n];
   for (i, x) in c.iter().enumerate() {
      vs[*x].push(i);
   }

   let mut res = vec![c2(n as i64); n];
   let mut d = BIT::<i64>::new(n, 0);
   for i in 0..n {
      d.add(i, 1);
   }
   for i in 0..n {
      vs[i].sort_by_key(|a| -(vin[*a] as i32));
      let mut history = Vec::<(usize, i64)>::new();
      for v in vs[i].iter().copied() {
         let mut cnt = 1;
         for u in to[v].iter().copied() {
            if (vin[u] < vin[v]) {
               continue;
            }
            let num = d.range(vin[u], vout[u]);
            res[i] -= c2(num as i64);
            cnt += num;
         }
         d.add(vin[v], -cnt);
         history.push((vin[v], cnt));
      }
      res[i] -= c2(d.range(0, n));
      for (i, cnt) in history {
         d.add(i, cnt);
      }
   }
   for r in res {
      println!("{}", r);
   }
}

fn c2(n: i64) -> i64 {
   n * (n + 1) / 2
}

#[derive(Debug, Clone)]
struct BIT<T> {
   n: usize,
   d: Vec<T>,
}

impl<T: Copy + Clone + Sub + AddAssign> BIT<T> {
   fn new(n: usize, x: T) -> BIT<T> {
      BIT {
         n: n,
         d: vec![x; n + 1],
      }
   }

   fn add(&mut self, i: usize, a: T) {
      let mut i = (i + 1) as i32;
      while i <= self.n as i32 {
         self.d[i as usize] += a;
         i += i & (-i);
      }
   }

   fn sum(&self, i: usize) -> T {
      let mut i = (i + 1) as i32;
      let mut sum = self.d[0];
      while i > 0 {
         sum += self.d[i as usize];
         i -= i & (-i);
      }
      sum
   }

   // [l, r)
   fn range(&self, l: usize, r: usize) -> <T as Sub>::Output {
      match (l, r) {
         (0, r) => self.sum(r - 1) - self.d[0],
         (_, _) => self.sum(r - 1) - self.sum(l - 1),
      }
   }
}


Measured memory_bytes: 37796
#include <iomanip>
#include <iostream>
using namespace std;

int main() {
  int a, b, d, r;
  double f;
  cin >> a >> b;
  d = a / b;
  r = a % b;
  f = double(a) / double(b);
  cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
}

Measured memory_bytes: 3240
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

vector<int> divisor(int n){
    vector<int> res;
    for(int i = 1LL; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            int j = n / i;
            if(i != j)res.push_back(j);
        }
    }
    return res;
}


int main()
{
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    map<int,int> mp;
    for(int i = 0; i < n; i++)mp[a[i]]++;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        vector<int> s = divisor(a[i]);
        int m = s.size();
        int cnt = 0;
        for(int j = 0; j < m; j++) {
            //if(binary_search(a.begin(), a.end(), s[j]))cnt++;
            cnt += mp[s[j]];
        }
        if(cnt == 1)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 32648
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);

  vector<int> H(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &H.at(i));
  }

  int ans = 1;
  bool can_watch_sea = true;
  for (int i = N - 1; i >= 1; i--) {
    for (int j = i - 1; j >= 0; j--) {
      if (H.at(i) < H.at(j)) can_watch_sea = false;
    }
    if (can_watch_sea) {
      ans++;
    } else {
      can_watch_sea = true;
    }
  }

  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
char a[19];
int main()
{
	for(int i=1;i<=19;i++){
	   scanf("%c",&a[i]);
	}
	for(int i=1;i<=5;i++){
		printf("%c",a[i]);
	}
	printf(" ");
	for(int i=7;i<=13;i++){
		printf("%c",a[i]);
	}
	printf(" ");
	for(int i=15;i<=19;i++){
	    printf("%c",a[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> X(M);
    for (ll &x : X) cin >> x;
    sort(X.begin(), X.end());
    vector<ll> tmp;
    for (ll i = 0; i < M - 1; i++) tmp.push_back(X[i + 1] - X[i]);
    sort(tmp.begin(), tmp.end());
    ll cnt = max<ll>(M - N, 0);
    ll ans = 0;
    for (ll i = 0; i < cnt; i++) ans += tmp[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

cnt = 0
for i in range(N):
    cnt += B[A[i]-1]
    if 0 < i:
        if A[i] - A[i-1] == 1:
            cnt += C[A[i]-2]
print(cnt)


Measured memory_bytes: 3060
A = $stdin.readline.to_i
B = $stdin.readline.to_i
C = $stdin.readline.to_i
D = $stdin.readline.to_i
E = $stdin.readline.to_i

minA = [(A % 10), (B % 10), (C % 10), (D % 10), (E % 10)]
minA.each_index {|idx| minA[idx] = 10 if minA[idx]  == 0 }

print (((A+9) / 10) * 10) + (((B+9) / 10) * 10) + (((C+9) / 10) * 10) + (((D+9) / 10) * 10) + (((E+9) / 10) * 10) - 10 + minA.min


Measured memory_bytes: 1788
// B - Varied
#include <bits/stdc++.h>
using namespace std;

int main(){
	string s; cin>>s;
	sort(s.begin(), s.end());
	for(int i=1; i<s.size(); ++i){
		if(s[i]==s[i-1]){
			puts("no");
			return 0;
		}
	}
	puts("yes");
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        long ans = 0;
        
        int[] idx = new int[n];
        for(int i=0; i<n; i++){
            idx[a[i]-1] = i;
        }
        
        TreeSet<Integer> s = new TreeSet<Integer>();
        for(int i=n-1; i>=0; i--){
            int x = idx[i];
            s.add(x);
            int l1 = -1 , l2 = -1;
            int r1 = n, r2 = n;
            Integer tmp;
            
            if((tmp = s.lower(x)) != null){
                l2 = tmp;
                if((tmp = s.lower(tmp)) != null){
                    l1 = tmp;
                }
            }
            if((tmp = s.higher(x)) != null){
                r1 = tmp;
                if((tmp = s.higher(tmp)) != null){
                    r2 = tmp;
                }
            }
            
            long w1 = (l2-l1)*(r1-x);
            long w2 = (x-l2)*(r2-r1);
            ans += (w1+w2)*(i+1);
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 49124
#include <iostream>
using namespace std;
const int N = 2000+10;

int dp[N][2];
int n, z, w, a[N];

int main() {
    scanf("%d %d %d", &n, &z, &w);
    for (int i = 1; i <= n; i ++) {
        scanf("%d", &a[i]);
    }
    a[0] = w;

    dp[n][0] = dp[n][1] = abs(a[n] - a[n-1]);
    for (int i = n-1; i >= 0; i --) {
        dp[i][0] = 0, dp[i][1] = 1e9;

        dp[i][0] = max(dp[i][0], abs(a[i] - a[n]));
        dp[i][1] = min(dp[i][1], abs(a[i] - a[n]));
        for (int j = i+1; j <= n; j++) {
            dp[i][0] = max(dp[i][0], dp[j][1]);
            dp[i][1] = min(dp[i][1], dp[j][0]);
        }
    }

    printf("%d\n", dp[0][0]);
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=1000000;

char s[MAXN+1],t[MAXN+1]; int n;

int h[MAXN];
int z[MAXN],zoff,zmod; // for j in at..i, h[j]=z[j+zoff]+zmod


int solve() {
	int at=n;
	for(int i=n-1;i>=0;--i) {
		if(i<at) at=i,z[i+zoff]=-zmod;
		if(s[at]==t[i]) { h[i]=z[i+zoff]+zmod; continue; }
		while(at>=0&&s[at]!=t[i]) --at,z[at+zoff]=-zmod;
		if(at<0) return -1;
		h[i]=z[i+zoff]+zmod+1;
		++zmod,++zoff;
	}
	//REP(i,n) printf("%d ",h[i]); puts("");
	int ret=0; REP(i,n) if(h[i]>ret) ret=h[i]; return ret;
}

void run() {
	scanf("%d%s%s",&n,s,t); n=strlen(s);
	int ret=solve();
	printf("%d\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 9984