akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int dp[n+1][n+1]={};
    for(int i=n-1;i>=0;i--)for(int j=n-1;j>=0;j--)if(s[i]==s[j])dp[i][j]=dp[i+1][j+1]+1;
    int x=0;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)x=max(x,min(dp[i][j],abs(i-j)));
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 101300
ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]]
while True:
    try:
        s = input()
    except EOFError:
        break
    flag = False
    for i in ok:
        if s[i[0]] == s[i[1]] == s[i[2]] and s[i[0]] != 's':
            print(s[i[0]])
            flag = True
            break
    if flag:
        continue
    print("d")

Measured memory_bytes: 7372
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int h,w;
vvc a;

int main(){
	cin>>h>>w;
	a=vvc(h,vc(w));
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>a[i][j];
	for(int i=0;i<h;i++) for(int k=0;k<2;k++){
		for(int j=0;j<w;j++) cout<<a[i][j];
		cout<<endl;
	}
}

Measured memory_bytes: 256
w = input()
a = w[0]
b = w[1]
c = w[2]
d = w[3]
 
if a == b and b != c and c == d:
  print('Yes')
elif a == c and b != c and b == d:
  print('Yes')
elif a == d and a != b and b == c:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<P> stud(N);
  for (int i = 0; i < N; i++) {
    cin >> stud[i].first;
    stud[i].second = i+1;
  }
  sort(stud.begin(), stud.end());
  for (int i = 0; i < N; i++) {
    if (i != N-1) {
      cout << stud[i].second << " ";
    }
    else {
      cout << stud[i].second;
    }
  }
  cout << endl;
}

Measured memory_bytes: 1664
#include<stdio.h>
int main(void)
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A==B&&A==C&&B==C){
		printf("No\n");
	}
	else if(A!=B&&A!=C&&B!=C){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 1632
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;

const int P = 200003;
const int pr = 2;

int idx[P + 5];

typedef complex<double> C;
typedef vector<double> vd;
typedef vector<int> vi;

void fft(vector<C>& a) {
    int n = sz(a), L = 31 - __builtin_clz(n);
    static vector<complex<long double>> R(2, 1);
    static vector<C> rt(2, 1);  // (^ 10% faster if double)
    for (static int k = 2; k < n; k *= 2) {
        R.resize(n); rt.resize(n);
        auto x = polar(1.0L, acos(-1.0L) / k);
        rep(i,k,2*k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2];
    }
    vi rev(n);
    rep(i,0,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
    rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
    for (int k = 1; k < n; k *= 2)
        for (int i = 0; i < n; i += 2 * k) rep(j,0,k) {
            // C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled)  /// include-line
            auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k];        /// exclude-line
            C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]);           /// exclude-line
            a[i + j + k] = a[i + j] - z;
            a[i + j] += z;
        }
}

vd conv(const vd& a, const vd& b) {
    if (a.empty() || b.empty()) return {};
    vd res(sz(a) + sz(b) - 1);
    int L = 32 - __builtin_clz(sz(res)), n = 1 << L;
    vector<C> in(n), out(n);
    copy(all(a), begin(in));
    rep(i,0,sz(b)) in[i].imag(b[i]);
    fft(in);
    for (C& x : in) x *= x;
    rep(i,0,n) out[i] = in[-i & (n - 1)] - conj(in[i]);
    fft(out);
    rep(i,0,sz(res)) res[i] = imag(out[i]) / (4 * n);
    return res;
}

ll mpow(ll b, ll e) {
    ll res = 1;
    for(ll k = 1; k <= e; k *= 2) {
        if(k & e) res = (res * b) % P;
        b = (b * b) % P;
    }
    return b;
}

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

    ll cur = 1;
    for(int i = 0; i < P - 1; i++) {
        idx[cur] = i;
        cur = (cur * pr) % P;
    }
    //for(int i = 1; i < P; i++)
    //    cout << idx[i] << " ";

    vd A(P - 1);
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        if(!x)
            continue;
        ans -= ((x * x) % P);
        A[idx[x]]++;
    }
    auto res = conv(A, A);
    for(int i = 0; i < P - 1; i++) {
        res[i] += res[i + P - 1];
        int cnt = round(res[i]);
        //if(cnt)
        //    cout << i << " " << cnt << '\n';
    }

    cur = 1;
    for(int i = 0; i < P - 1; i++) {
        ans += cur * round(res[i]);
        cur = (cur * pr) % P;
    }
    cout << ans / 2 << '\n';
}

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

int main() {
	int n, a, t, ans;
	cin >> n >> t >> a;
	a *= 1000, t *= 1000;
	int min = 1100001;
	for (int i = 0, h; i < n; i++) {
		cin >> h;
		if (abs(t - h * 6 - a) < min) {
			min = abs(t - h * 6 - a);
			ans = i + 1;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// 2???????????????????????????????±???????
double dot(P a, P b) {
    return (a.X * b.X + a.Y * b.Y);
}

// 2???????????????????????????????±???????
double cross(P a, P b) {
    return (a.X * b.Y - a.Y * b.X);
}

double area(const vector<P> &ps) {
    double a = 0;
    rep(i,0,ps.size()) a += cross(ps[i], ps[(i+1) % ps.size()]);
    return a / 2;
}

int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if( cross(b,c) > EPS ) return +1;
    if( cross(b,c) < -EPS ) return -1;
    if( dot(b,c) < 0 ) return +2;
    if( norm(b) < norm(c) ) return -2;
    return 0;
}

// ??´??? a1, a2 ??¨??´???b1, b2?????????????±???????
// Verified: AOJ CGL_2_C.cpp
P crossp_ll(P a1, P a2, P b1, P b2) {
    double d1 = cross(b2-b1, b1-a1);
    double d2 = cross(b2-b1, a2-a1);
    if( EQ(d1,0) && EQ(d2,0) ) return a1; // same line
    if( EQ(d2,0) ) assert(false); // precondition not satisfied
    return a1 + d1 / d2 * (a2 - a1);
}

// ???????§???¢?????????????????°
vector<P> convexCut(P a1, P a2, const vector<P> &ps) {
    int n = ps.size();
    vector<P> ret;
    rep(i,0,n) {
        int ccwc = ccw(a1, a2, ps[i]);
        if(ccwc != -1) ret.push_back(ps[i]);
        int ccwn = ccw(a1, a2, ps[(i + 1) % n]);
        if(ccwc * ccwn == -1) ret.push_back(crossp_ll(a1, a2, ps[i], ps[(i + 1) % n]));
    }
    return ret;
}

int main() {
    int n; cin >> n;
    vector<P> ps;
    rep(i,0,n) {
        P temp; cin >> temp.X >> temp.Y;
        ps.pb(temp);
    }

    int q; cin >> q;
    rep(i,0,q) {
        P a, b; cin >> a.X >> a.Y >> b.X >> b.Y;
        vector<P> ret = convexCut(a, b, ps);
        printf("%.10f\n", area(ret));
    }
    return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;
int X[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}, Y[9] = {1, 1, 1, 0, 0, 0, -1, -1, -1};
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> v(H);
	for(int i = 0; i < H; i++) cin >> v[i];

	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			if(v[i][j] != '.') continue;
			v[i][j] = '0';
			for(int d = 0; d < 9; d++) {
				if(0 <= i + Y[d] && i + Y[d] < H && 0 <= j + X[d] && j + X[d] < W) {
					if(v[i + Y[d]][j + X[d]] == '#') v[i][j] = (char)((int)v[i][j] + 1);
				}
			}
		}
	}

	for(int i = 0; i < H; i++) {
		cout << v[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N - 1);
  REP(i, N - 1) cin >> A[i];
  vl B(N, 0);
  REP(i, N - 1) { B[A[i] - 1]++; }
  REP(i, N) cout << B[i] << endl;

  return 0;
}


Measured memory_bytes: 6364
# -*- coding: utf-8 -*-
n, k = map(int, raw_input().split())

res = 0.0

for i in range(1, n+1):
    point = i
    count_head = 0

    while point < k:
        point *= 2
        count_head += 1

    res += (1.0/n) * (0.5 ** count_head)

print res

Measured memory_bytes: 5764
input()
int_list = list(map(int, input().split()))
max_num = 10**18
ans = 1

if 0 in int_list:
   print(0)
   exit()
 
for i in int_list:
   ans *= i
   if ans > max_num:
       print(-1)
       break
else:
   print(ans)

Measured memory_bytes: 21724
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	map<int, int> a;
	int t;
	rep(i, n) {
		cin >> t;
		a[t]++;
	}
	if (n % 2 != 0) {
		if (a[0] != 1) {
			cout << 0 << endl;
			return 0;
		}
	}
	else {
		if (a[1] != 2) {
			cout << 0 << endl;
			return 0;
		}
	}

	bool f = true;
	auto itr = a.begin();
	if (n % 2 != 0) {
		t = 2;
	}
	else {
		t = 1;
	}
	itr++;
	for (int i = t; itr != (a.end())--; i+=2, itr++) {
		if (a[t] != 2) {
			cout << 0 << endl;
			return 0;
		}
	}

	int ans = 1;
	rep(i, n / 2) {
		ans *= 2;
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3200
import math
input_num = int(input())
num_sqrt = int(math.sqrt(input_num))

minimam = input_num
for i in range(num_sqrt+1,0,-1):
    q, mod = divmod(input_num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define P(r) do{for(auto i:r){cout<<i<<' ';}cout<<'\n';}while(0)
int main()
{
    int a, b, c; cin >> a >> b >> c;
    int cnt = 0;
    if (a == b && b == c) cnt = 1;
    else if (a == b || b == c || c == a) cnt = 2;
    else cnt = 3;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) loop(i,0,n)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<pii> vp;
typedef vector<vi> vvi;
typedef vector<string> vs;
Def inf = sizeof(Def) == sizeof(ll) ? 2e18:1e9+10;
int main(){
	int n,R;
	while(cin>>R>>n,R){
		vi in(60);
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			a+=30;b+=30;
			loop(j,a,b)in[j]=max(in[j],c);
		}
		double l=0,r=21;
	//	rep(i,60)cout<<" "<<in[i];cout<<endl;
		while(r-l>0.0001){
			double h=(l+r)/2;
			bool H=true;
			rep(q,50){
				int t=q-25;
				if(abs(t)>R)continue;
				int hi=min(in[t+29],in[t+30]);
				if(t==R)hi=in[t+29];
				else if(-t==R)hi=in[t+30];
				if(h-R>hi)H=false;
				if(R*R>t*t+(hi-(h-R))*(hi-(h-R)))H=false;
			}
//			cout<<shosu(4)<<h<<" "<<H<<endl;
			if(H)l=h;
			else r=h;
		}
		cout<<shosu(9)<<l<<endl;
	}
}







Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
long long int V[200010];
long long int C[200010];




int main(void){
    // Your code here!
    long long int N,H,W,i,j,k,ans,count,cost,tmp;
    
    
    string T;
    bool flag;
    count=0;
    ans=0;
    flag=false;
    cin >>N;
    
    
 
      
        if (N<600){
            ans=8;
        }
        else if(N<800){
            ans=7;
        }
        else if(N<1000){
            ans=6;
        }
        else if(N<1200){
            ans=5;
        }
        else if(N<1400){
            ans=4;
        }
        else if(N<1600){
            ans=3;
        }
        else if(N<1800){
            ans=2;
        }
        else if(N<2000){
            ans=1;
        }
    
    
    
    cout<< ans <<endl;
    

    return 0;
    
}



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

int main() {
 int n;
 cin >>n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >>p.at(i);
  }
  sort(p.begin(),p.end());
  int ans =0;
  for(int i=0;i<n-1;i++){
    ans+=p.at(i);
  }
  ans+=p.at(n-1)/2;
  cout <<ans;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

//#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
//#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
//#include <atomic>
#include <chrono>
//#include <condition_variable>
#include <forward_list>
//#include <future>
#include <initializer_list>
//#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
//#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


using namespace std;

template<typename T>
class UF
{
public:
	UF ()
	{
		count = 0;
	}
	void push ( T a )
	{
		M[a] = count;
		V.push_back ( count );
		rank.push_back ( 0 );
		count++;
	}

	void unite ( T a , T b )
	{
		long long int x = find ( M[a] );
		long long int y = find ( M[b] );
		if( x == y )return;
		if( rank[x] < rank[y] )
		{
			V[x] = y;
		} else
		{
			V[y] = x;
			if( rank[x] == rank[y] )rank[x]++;
		}
	}
	void merge ( T a , T b )
	{
		unite ( a , b );
	}
	bool same ( T a , T b )
	{
		return find ( M[a] ) == find ( M[b] );
	}
	long long int group ()
	{
		set < long long int > S;
		for( long long int i = 0; i < V.size (); i++ )
		{
			S.insert ( find ( V[i] ) );
		}
		return S.size ();
	}

private:
	vector<long long int>V , rank;
	map < T , long long int>M;
	long long int count;

	long long int find ( long long int x )
	{
		if( V[x] == x )return x;
		else return V[x] = find ( V[x] );
	}
};

int main ()
{
	int V , d;
	int data[1001] = {};
	data[0] = 2;
	data[1] = 3;
	for( size_t i = 2; i < 1001; i++ )
	{
		data[i] = data[i - 1] + data[i - 2];
		data[i] %= 1001;
	}

	while( cin >> V >> d )
	{
		UF<int>* uf = new UF < int > ;
		set<int>S;
		for( size_t i = 0; i < V; i++ )
		{
			( *uf ).push ( i );
		}
		for( size_t i = 0; i < V; i++ )
		{
			for( size_t j = i + 1; j < V; j++ )
			{
				if( abs ( data[i] - data[j] ) < d )
				{
					( *uf ).merge ( i , j );
				}
			}
		}
		cout << ( *uf ).group () << endl;
		delete uf;
	}
}

Measured memory_bytes: 1304
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
#define endl '\n'
#define F first
#define S second
const int MAX_N=3e3+3;

int n;
int a[MAX_N];
ll dp[MAX_N][MAX_N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int d=1,j;d<=n;d++) for(int i=1;i+d-1<=n;i++)
	{
		j=i+d-1;
		if((n-d)&1) dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j]);
		else dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j]);
	}
	printf("%lld\n",dp[1][n]);
	return 0;
}



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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define output(x) cout<<x<<endl;
#define fre(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define frd(i, a, b) for (int i = (int)(a); i >= b; --i)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int,int> > vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
const ll mod=1e9+7;
const int maxn = 110000;
ll dp[maxn][2];//0-white 1-black
int n;
vi v[maxn];

void dfs(int id,int par){
		dp[id][0]=1;
		dp[id][1]=1;
	for(auto i:v[id]){
		if(i!=par) dfs(i,id);
	}
	for(auto i:v[id]){
		if(i==par) continue;
		dp[id][0]=(dp[id][0]*(dp[i][0]+dp[i][1]))%mod;
		dp[id][1]=(dp[id][1]*(dp[i][0]))%mod;
	}
}

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);	
	cin>>n;
	for (int i = 0; i < n-1; ++i)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs(1,-1);
	output((dp[1][0]+dp[1][1])%mod);
	return 0;
}

Measured memory_bytes: 14464
#include<stdio.h>
#include<math.h>
int N,X[105],Y[105],i;
double D;

double d(int p)
{
	int i;
	for(D=0.0,i=0;i<N;i++)
	{
		if(p==4)D=D>abs(X[i]-Y[i])?D:abs(X[i]-Y[i]);
		else D+=pow(1.0*abs(X[i]-Y[i]),p);
	}
	return p==4?D:pow(D,1.0/p);
}

int main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",X+i);
	for(i=0;i<N;i++)scanf("%d",Y+i);
	for(i=1;i<5;i++)printf("%lf\n",d(i));
	return 0;
}

Measured memory_bytes: 696
(n, k) = map(int, input().split())
(a, b) = zip(*[map(int, input().split()) for _ in range(n)])

cnt_dict = {}
for i in range(n):
    if a[i] not in cnt_dict.keys():
        cnt_dict[a[i]] = 0
    cnt_dict[a[i]] += b[i]

length = 0
for a_i in sorted(cnt_dict.keys()):
    length += cnt_dict[a_i]
    if length >= k:
        ans = a_i
        break

print(ans)


Measured memory_bytes: 61104
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 30;

int main(void){
    int N; cin >> N;
    vector<int> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    vector<int> B(N); for(int i = 0; i < N; i++) cin >> B[i];
    vector<int> C(N-1); for(int i = 0; i < N-1; i++) cin >> C[i];
    
    int ans = 0;
    int now;
    int prev = -1;
    for(int i = 0; i < N; i++){
        int a = A[i]-1;
        now = a;
        if (prev == (now - 1)){
            if(prev != -1)ans += C[prev];
        }
        ans += B[a];
        prev = a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7


def count_bit_flag(T):
    T = (T & 0x55555555) + ((T >> 1) & 0x55555555)
    T = (T & 0x33333333) + ((T >> 2) & 0x33333333)
    T = (T & 0x0F0F0F0F) + ((T >> 4) & 0x0F0F0F0F)
    T = (T & 0x00FF00FF) + ((T >> 8) & 0x00FF00FF)
    T = (T & 0x0000FFFF) + ((T >> 16) & 0x0000FFFF)
    return T


def main():
    N = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(N))

    memo = {i: set() for i in range(N)}
    for bit in range(1, 1 << N):
        memo[count_bit_flag(bit)-1].add(bit)

    dp = [0] * (1 << N)
    dp[0] = 1
    for i, bit_list in enumerate(memo.values()):
        for bit in bit_list:
            for j, a in enumerate(A[i]):
                if a and (bit >> j) & 1:
                    dp[bit] += dp[bit ^ (1 << j)]
                    dp[bit] %= mod
    print(dp[(1 << N) - 1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 139044
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    vector<int> v(3);
    F(i,0,3) cin >> v[i];
    sort(v.begin(),v.end());
    cout << v[0]+v[1]+v[2]*10 << endl;
    return 0;
}

Measured memory_bytes: 256
def solve():
    c=[]
    for i in range(3):
        c.append(list(map(int,input().split())))
    if c[0][0]-c[1][0]==c[0][1]-c[1][1]==c[0][2]-c[1][2] and \
       c[1][0]-c[2][0]==c[1][1]-c[2][1]==c[1][2]-c[2][2] and \
       c[0][0]-c[0][1]==c[1][0]-c[1][1]==c[2][0]-c[2][1] and \
       c[0][1]-c[0][2]==c[1][1]-c[1][2]==c[2][1]-c[2][2]:
        return 'Yes'
    else:
        return 'No'

print(solve())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  for (size_t i = 0; i < 10; i++) {
    string deck;
    int m;

    cin >> deck;
    if (deck == "-") break;
    cin >> m;
    vector<int> h_n(m);
    for (int j = 0; j < m; j++) {
      cin >> h_n.at(j);
    }

    string tmp;
    for (auto h : h_n) {
      tmp = deck.substr(0, h);
      deck.erase(0, h);
      deck.append(tmp);
    }
    cout << deck << endl;
  }
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<long long>;


void solve(long long H, long long W, long long N, std::vector<long long> a){
    vector<vll> grid(H, vll(W, 0));
    vll contents;
    for(ll i=0; i< N; i++){
        for(ll j=0; j< a[i]; j++){
            contents.push_back(i+1);
        }
    }
    ll pnt=0;
    for(ll i=0; i< H; i++){
        for(ll j=0; j< W; j++){
            if(i%2==0){
                grid[i][j] = contents[pnt];
                pnt++;
            }
            else{
                grid[i][W-j-1] = contents[pnt];
                pnt++;
            }
        }
    }
    for(ll i=0; i< H; i++){
        for(ll j=0; j< W; j++){
            if(j != W-1)
                cout << grid[i][j]<<" ";
            else
                cout << grid[i][j]<<endl;
        }
    }
    
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(H, W, N, std::move(a));
    return 0;
}


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

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
static long[] f;
//......................................@uthor_Alx..............................................
static void spf(int n, int[] spf){
        for(int i=2;i<=(int)Math.sqrt(n);i++){
          if(spf[i]!=0) continue;
          spf[i]=i;
          for(int j=i*i;j<=n;j+=i){
            if(spf[j]!=0) continue;
            spf[j]=i;
          }
        }
        for(int i=(int)Math.sqrt(n);i<=n;i++){
          if(spf[i]==0) spf[i]=i;
        }
    }
   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  	int n=int_v(read());
	        		  	int[] spf=new int[n+1];
	        		  	spf(n,spf);
	        		  	long res=1;
	        		  	for(int i=2;i<=n;i++){
	        		  		long tmp=1l,c=0l;int j=i;
	        		  		while(j>1){
	        		  			int p=spf[j];
	        		  			while(j%p==0){
	        		  				j/=p;
	        		  				c++;
	        		  			}
	        		  			tmp*=(c+1);
	        		  			c=0;
	        		  		}
	        		  		res+=tmp*i;
	        		  	}
	        		  	out.write((res)+"");
                      	out.flush();
	        		 
	}
}
	       


Measured memory_bytes: 76216
/*
...........__________                                                                           ___  __
.............|       |                                                                           |   /
.............|       |                                                                           |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
...........__|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
void read_And_write(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

int power(int x, unsigned int y) 
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
}

void raushan_kumar(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int n;cin>>n;
    for(int i=-120;i<=120;i++){
    	for(int j=-120;j<=120;j++){
    		int temp=power(i,5)-power(j,5);
    		if(temp==n){
    			ans=i;
    			res=j;
    		}
    	}
    }
    cout<<ans<<" "<<res;
}

int32_t main()
{
    read_And_write();fast;int t=1;
    // cin>>t;
    while(t--){raushan_kumar();}
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
ll a[maxn], b[maxn], k, n, m, sum, p;
double c, r;
string s, t;
map<int, int>ma, mp;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(); cout.tie();
    cin>>n;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
        mp[i - a[i]]++;
    }
    for(int i = 1; i <= n; i++){
        sum += mp[a[i] + i];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 22252
#include <iostream>

using namespace std;

int main() {
  
  int N;
  
  while(cin >> N && N) {
    int hist[10] = {};
    for(int i=0; i<N; i++) {
      int a; cin >> a;
      hist[a] ++;
    }
    for(int i=0; i<10; i++) {
      if(hist[i]) {
        for(int j=0; j<hist[i]; j++) {
          cout << '*';
        }
        cout << endl;
      }
      else {
        cout << "-" << endl;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>

static void sort_simple(int n, int *vals)
{
  int i, j, k;
  for (i = 0; i < n-1; i ++) {
    j = i;
    for (k = i+1; k < n; k ++)
      if ( vals[j] > vals[k] ) j = k;
    if ( j != i ) {
      int t = vals[i];
      vals[i] = vals[j];
      vals[j] = t;
    }
  }
}

static int get_val(int array, int* vals)
{
  int v1 = vals[array/10];
  int v2 = vals[array%10];
  if ( v2 < 10 )
    return v1 * 10 + v2;
  if ( v2 < 100 )
    return v1 * 100 + v2;
  if ( v2 < 1000 )
    return v1 * 1000 + v2;
  return v1 * 10000 + v2;
}

void sort_array(int n, int *arrays, int *buf, int *vals)
{
  int i, j, k;
  for (i = 0; i < n; i ++) {
    buf[i] = get_val(arrays[i], vals);
  }

  for (i = 0; i < n-1; i ++) {
    j = i;
    for (k = i+1; k < n; k ++) {
      if ( buf[j] > buf[k] )
	j = k;
    }
    if ( j != i ) {
      int t = buf[j];
      buf[j] = buf[i];
      buf[i] = t;
      t = arrays[j];
      arrays[j] = arrays[i];
      arrays[i] = t;
    }
  }
}

int main()
{
  char line[256];
  int i, n, *vals;
  int buf[12];
  int arrays[12] = { 1, 2, 3, 10, 12, 13, 20, 21, 23, 30, 31, 32 };

  /* Input */
  fgets(line, 256, stdin);
  sscanf(line, "%d", &n);
  vals = (int *)malloc(sizeof(int) * (n+1));
  for (i = 0; i < n; i ++) {
    fgets(line, 256, stdin);
    sscanf(line, "%d", vals+i);
  }
  /* Calculate */
  sort_simple(n, vals);
  if ( n == 3 ) vals[n] = 99999;
  sort_array(12, arrays, buf, vals);
  printf("%d%d\n", vals[arrays[2]/10], vals[arrays[2]%10]);

  /* Finish */
  free(vals);
  return 0;
}



Measured memory_bytes: 2108
#include <stdio.h>
#include <string.h>
 
char str[21]; // ¶ñ
char result[21]; // ½]µ½Êðüêé
int n; // ¶ñÌ·³ 
int i;
int main(void){
  scanf("%20s",str); //¶ñðL[{[h©çÇÝÞ
 
 for (i=0;str[i]!='\0';i++)
    {}

  n=i-1;
  for (i=0;str[i]!='\0';i++)
    {
      result[n-i]=str[i];
    }
 
 
  printf("%s\n",result); // ½]µ½Êð\¦
 
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf 10000000000000000ll
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 1e-7
#define endl "\n"
/*ll gcd(ll a,ll b)
{
    if(a==0){return b;}
    return gcd(b%a,a);
}
ll modexp(ll x,ll y,ll p)
{
    ll res=1;x%=p;
    while(y>0)
    {   if(y%2==1){res=(res*x)%p;}
        y=y>>1;x=(x*x)%p;
    }return res;
}*/
int n,m;
set<int>s;
const int maxn=1e5+10;
ll dp[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    rep(i,1,m)
    {
        int x;cin>>x;
        s.insert(x);
    }
    dp[0]=1;
    if(s.find(1)!=s.end())
    {
        dp[1]=0;
    }
    else
    {
        dp[1]=1;
    }
    rep(i,2,n)
    {
        if(s.find(i)!=s.end())
        {
            dp[i]=0;
        }
        else
        {
            dp[i]=(dp[i-1]+dp[i-2])%MOD;

        }
    }
    cout<<dp[n]%MOD<<"\n";

    return 0;

    /*check for long long or int*/
}


Measured memory_bytes: 5760
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

bool solve() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto d = A.reduce!max - A.reduce!min;
    if (d == 0) {
        if (A[0] == N - 1) return true;
        else if (A[0] <= N / 2) return true;
        else return false;
    } else if (d == 1) {
        auto a = A.reduce!max;
        auto b = A.reduce!min;
        int ca, cb;
        foreach (aa; A) {
            if (aa == a) ca += 1;
            else if (aa == b) cb += 1;
        }
        N = ca;
        a -= cb;
        if (a <= 0) return false;
        else if (a <= N / 2) return true;
        else return false;
    } else {
        return false;
    }

}

void main() {
    writeln(solve ? "Yes" : "No");
}


Measured memory_bytes: 4412
#include <iostream>
#include <vector>
//#include <list>
#include <queue>
#include <stack>
//#include <unordered_map>
#include <algorithm>
//#include <string>
#include <cstring>
#include <cmath>

/*
https://vjudge.net/contest/372054#problem/G
Longest path in a directed graph
bfs won't work here as longest path in directed graph is asked

Topological Sort and then dp // i.e. update the dp table according to the topological sort
https://www.geeksforgeeks.org/longest-path-directed-acyclic-graph-set-2/
*/
using namespace std;

void topological_sort(vector<int> a[], int x, vector<bool> &vis, stack<int> &st)
{
	vis[x]=true;
	int j;
	//cout<<"x and siz[x]"<<x+1<<" "<<a[x].size()<<"\n";
	for(int i=0;i<a[x].size();i++)
	{
		j=a[x][i];
		//cout<<j+1<<" "<<vis[j]<<"\n";
		if(vis[j]==false)
		{
			topological_sort(a,j,vis,st);
		}
	}
	st.push(x);
	//cout<<"pushing"<<x+1<<"\n";
	return;
}

int main()
{
	int i,j,k,t;
    //unsigned long long int x,y,z;
    int x,y,z,m,mod;
    int n;
    cin>>n>>m;
	int res=0;
	stack<int> st;
    vector<int> a[n];
    for(i=0;i<m;i++)
    {
    	cin>>x>>y;
    	--x;
    	--y;
    	a[x].push_back(y);
    }
    vector<bool> vis(n, false);
    vector<int> dp(n,0);
    while(!st.empty())
    	st.pop();
    for(i=0;i<n;i++)
    {
    	if(vis[i]==0)
    		topological_sort(a, i, vis, st);
    }
    //cout<<st.size()<<"\n";
    //cout<<"\n";
    while(!st.empty())
    {
    	z=st.top();
    	st.pop();
    	for(j=0;j<a[z].size();j++)
    	{
    		k=a[z][j];
    		if(dp[k]>dp[z]-1)
    		{
    			dp[k]=dp[z]-1;
    			res=max(res,-1*	dp[k]);
    			//cout<<dp[k]<<" ";
    		}
    	}
    }
    cout<<res<<"\n";
    return 0;
}

Measured memory_bytes: 9216
read = input
s = read()
a, b = map(int , [s[:2], s[2:]])
YYMM = False
MMYY = False
if 1 <= b and b <= 12:
    YYMM = True
if 1 <= a and a <= 12:
    MMYY = True
if YYMM and MMYY :
    print('AMBIGUOUS')
elif YYMM and not MMYY:
    print('YYMM')
elif not YYMM and MMYY:
    print('MMYY')
else :
    print('NA')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll n; string str;
    ll ans=0, red=0, green=0;
    cin>>n>>str;
    n=str.length();
    forr(i, n)
    {
        if(str[i]=='R')
            red++;
        if(str[i]=='G')
            green++;
    }
    ll blue=n-(red+green);
    ans=blue*red*green;
    map<pair<ll, ll>, ll> mp1;
    for(ll i=0; i<n; i++)
    {
        for(ll j=i+1; j<n; j++)
        {
            ll k=2*j-i;
            vl a(3);
            a[0]=i;
            a[1]=j;
            a[2]=k;
            sort(all(a));
            pair<ll, ll> p1=mp(a[0], a[1]);
            if(a[2]>=n)
            continue;
            if(str[i]!=str[j]&&str[i]!=str[k]&&str[j]!=str[k])
            {
                ans--;
                //cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<str[i]<<" "<<str[j]<<" "<<str[k]<<" "<<endl;
                mp1[p1]++;
            }    
        }
    }
    cout<<ans;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

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

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    string S, T;
    cin >> S;
    cin >> T;

    vector<int> h(H, 0);
    vector<int> w(W, 0);

    int up = 1, down = H;
    int left = 1, right = W;
    int updown = 0;
    int leftright = 0;

    for(int i=N-1;i>-1;i--){
        if(updown == H){
            break;
        }
        if(T[i] == 'D' && up > 1 && h.at(up-2) == 1){
            up--;
            h.at(up-1) = 0;
            updown--;
        }
        else if(T[i] == 'U' && down < H && h.at(down) == 1){
            down++;
            h.at(down-1) = 0;
            updown--;
        }
        
        if(S[i] == 'U' && up <= down && h.at(up-1) == 0){
            h.at(up-1) = 1;
            up++;
            updown++;
        }
        else if(S[i] == 'D' && down >= up && h.at(down-1)==0){
            h.at(down-1) = 1;
            down--;
            updown++;
        }
    }


    for(int i=N-1;i>-1;i--){
        if(leftright == W){
            break;
        }
        if(T[i] == 'R' && left > 1 && w.at(left-2) == 1){
            left--;
            w.at(left-1) = 0;
            leftright--;
        }
        else if(T[i] == 'L' && right < W && w.at(right) == 1){
            right++;
            w.at(right-1) = 0;
            leftright--;
        }
        if(S[i] == 'L' && left <= right && w.at(left-1) == 0){
            w.at(left-1) = 1;
            left++;
            leftright++;
        }
        else if(S[i] == 'R' && right >= left && w.at(right-1) == 0){
            w.at(right-1) = 1;
            right--;
            leftright++;
        }
    }

    if(h.at(sr-1) == 0 && w.at(sc-1) == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 2312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
const int mod=1e9+7;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
    int n;cin>>n;
    UnionFind uf(n);
    vector<tuple<int,int,int>> xy(n);
    vector<tuple<int,int,int>> yx(n);
    rep(i,n){
        int x,y;cin>>x>>y;
        xy[i]=make_tuple(x,y,i);
        yx[i]=make_tuple(y,x,i);
    }
    vector<tuple<int,int,int>> cvv;
    sort(all(xy));
    sort(all(yx));
    rep(i,n-1){
        int c0=abs(get<0>(xy[i])-get<0>(xy[i+1]));
        int v0=get<2>(xy[i]);
        int v1=get<2>(xy[i+1]);
        int c1=abs(get<1>(xy[i])-get<1>(xy[i+1]));
        cvv.push_back(make_tuple(c0,v0,v1));
        cvv.push_back(make_tuple(c1,v0,v1));
    }
    rep(i,n-1){
        int c0=abs(get<0>(yx[i])-get<0>(yx[i+1]));
        int v0=get<2>(yx[i]);
        int v1=get<2>(yx[i+1]);
        int c1=abs(get<1>(yx[i])-get<1>(yx[i+1]));
        cvv.push_back(make_tuple(c0,v0,v1));
        cvv.push_back(make_tuple(c1,v0,v1));
    }
    sort(all(cvv));
    ll ans=0;
    rep(i,sz(cvv)){
        int v0=get<1>(cvv[i]);
        int v1=get<2>(cvv[i]);
        if(!uf.unite(v0,v1))continue;
        ans+=get<0>(cvv[i]);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 11248
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long N, long long K, std::vector<long long> A) {
  for(int i = K;i<N;i++){
    if(A[i-K]<A[i]){
      cout << "Yes"<<endl;
    }else{
      cout << "No"<<endl;
    }
  }
}

signed main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 4848
//                        Bismillahir Rahmanir Rahim
//ALGO:
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF INT_MAX
#define mx 1000010
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
*/
const double Pi=acos(-1);
using namespace std;
int debug=01;

int main() {
    map<ll, ll>m;
    int n;
    cin>>n;
    ll a[n];
    for(int i=0; i<n; i++){cin>>a[i], m[a[i]]++;}
    ll ans=0;
    for(auto x=m.begin(); x!=m.end(); x++){
        ll y=(*x).S;
        ans+=(y*(y-1))/2;
    }
    for(int i=0; i<n; i++){
       ll x=m[a[i]];
       cout<<ans-(x*(x-1))/2+((x-1)*(x-2))/2<<"\n";
    }
}


Measured memory_bytes: 11008