akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template<class E, class T> struct Rerooting {
    using F = function<T(T, T)>;
    using H = function<T(T, E)>;
private : 
    struct Edge {
        int to;
        E data;
        T dp, sum;
        Edge (int to, E data, T dp, T sum) : 
            to(to), data(data), dp(dp), sum(sum) { }
    };
    vector<vector<Edge>> g;
    vector<T> subdp, dp;
    const T id;
    const F f;
    const H h;
    int edges;

public : 
    Rerooting (int n, const F &f, const H &h, const T id) : 
        g(n), f(f), h(h), id(id), subdp(n, id), dp(n, id) { edges = 0; }

    void add_edge (int v, int u, const E &val) {
        assert(++edges < (int)g.size());
        g[v].emplace_back(u, val, id, id);
        g[u].emplace_back(v, val, id, id);
    }

    void add_edge2 (int v, int u, const E &val1, const E &val2) {
        assert(++edges < (int)g.size());
        g[v].emplace_back(u, val1, id, id);
        g[u].emplace_back(v, val2, id, id);
    }

    void dfs1 (int v, int p) {
        for (const auto &e : g[v]) {
            if (e.to == p) continue;
            dfs1(e.to, v);
            subdp[v] = f(subdp[v], h(subdp[e.to], e.data));
        }
    }

    void dfs2 (int v, int p, const T &top) {
        T buff = id;
        for (int i = 0; i < (int)g[v].size(); i++) {
            Edge &e = g[v][i];
            e.sum = buff;
            e.dp = h(e.to == p ? top : subdp[e.to], e.data);
            buff = f(buff, e.dp);
        }
        dp[v] = buff;
        buff = id;
        for (int i = (int)g[v].size() - 1; i >= 0; i--) {
            Edge &e = g[v][i];
            if (e.to != p) dfs2(e.to, v, f(buff, e.sum));
            e.sum = f(e.sum, buff);
            buff = f(buff, e.dp);
        }
    }

    vector<T> build(int s = 0) {
        dfs1(s, -1);
        dfs2(s, -1, id);
        return dp;
    }

};


int main() {
    int n;
    cin >> n;
    
    auto f = [](int a, int b) { return max(a, b); };
    auto h = [](int a, int b) { return a + b; };
    Rerooting<int, int> g(n, f, h, 0);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        g.add_edge(--a, --b, 1);
    }
    
    for (const auto &e : g.build()) {
        cout << (n - 1) * 2 - e << endl;
    }
    return 0;
}


Measured memory_bytes: 21056
#include<iostream>
#include<iomanip>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const long long INF = 1LL << 60;
typedef pair<int, int> P;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    ll res = 0;
    ll sign = 1;
    for (int i = 0; i < N; i++) {
        res += sign * A[i];
        sign *= -1;
    }
    cout << res;
    for (int i = 0; i < N - 1; i++) {
        res = (res - 2 * A[i]) * -1;
        cout << " " << res;
    }
    cout << "\n";
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
vector<int> graph[210];
int match[210];
bool used[210];

void add_edge(int u, int v) {
  graph[u].push_back(v);
  graph[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < graph[v].size(); i++) {
    int u = graph[v][i];
    int w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < 2 * N; v++) {
    if (match[v] < 0) {
      memset(used, false, sizeof(used));
      if (dfs(v)) {
        res++;
      }
    }
  }
  return res;
}

int main() {
  // 入力
  cin >> N;
  int a[N], b[N], c[N], d[N];
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < N; i++) cin >> c[i] >> d[i];

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (a[i] < c[j] && b[i] < d[j]) {
        add_edge(i, j + N);
      }
    }
  }

  // 解答
  cout << bipartite_matching() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

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

using namespace std;
using ll = long long int;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//最大公約数を返す関数.
long long int gcd(long long int x, long long int y){
    if (x < y) swap(x,y);
    while (y > 0){
        long long int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

//最小公倍数を返す関数.gcdが必要.
long long int lcm(long long int x, long long int y){
	return x / gcd(x, y) * y;
}

int main()
{
	int n;
	long long int m;
	cin >> n >> m;
	vector<long long int> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n) a[i] = a[i] / 2;
	int num2 = -1;
	rep(i, n)
	{
		int num2temp = 0;
		long long int temp = a[i];
		while (true)
		{
			if(temp % 2 == 1)
				break;
			temp /= 2;
			num2temp++;
		}
		if (num2 == -1)
			num2 = num2temp;
		else if(num2 != num2temp){
			cout << 0 << endl;
			return 0;
		}
	}
	
	long long int lm = 1;
	rep(i,n) {
		lm = lcm(lm, a[i]);
	}

	cout << (m / lm + 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum=0;
  cin>>n;
  int a[n];
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum+=a[i];}
  int m;
  cin>>m;
  while(m--){
    int p,x;
    cin>>p>>x;
    cout<<sum-a[p]+x<<endl;}
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
#include<algorithm>
#include<set>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)

const int mod=1000000007;


int main(){
char s[200010];
scanf("%s",s);
int len=strlen(s);
int sum=0;
rep(i,len)sum+=s[i]-'0';
if(sum%9==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3328
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma region header
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
#pragma endregion
#pragma endregion



int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<lint> d(n);
	for (int i = 0; i < n; i++) {
		lint a; cin >> a;
		d[i] = a - (i + 1);
	}
	sort(d.begin(), d.end());
	lint cnt = d[n / 2];
	lint ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(d[i] - cnt);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  int result = 1;
  if(N % 2 == 1){
   result = 0; 
  }else{
  for(int a = 0;a < N / 2;a++){
    if(S[a] != S[a + N / 2])result = 0;
  }
    
  }
 if(result == 0)cout<<"No"<<endl;
  if(result == 1)cout<<"Yes"<<endl;
  
 
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
long long INF = (1LL<<62);

long long N;
vector<long long> A;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	long long ans = 1;
	long long diff = 0;
	for(int i=0; i<N; i++){
		long long a;
		cin >> a;
		A.push_back(a);
		if(i > 0){
			long long w = A[i] - A[i-1];
			if(w == 0){
				continue;
			}
			else if(w > 0){
				if(diff == 0){
					diff = w;
				}
				else if(diff < 0){
					ans++;
					diff = 0;
				}
			}
			else if(w < 0){
				if(diff == 0){
					diff = w;
				}
				else if(diff > 0){
					ans++;
					diff = 0;
				}
			}
			else{
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4264
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define mp make_pair

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const ll MOD = 1e9 + 7;

inline ll addmod(ll a, ll b){
    if(a+b<MOD)return a+b;
    return a+b-MOD;
}
inline ll submod(ll a, ll b){
    return addmod(a, MOD-b);
}
inline ll mulmod(ll a, ll b){
    return (a*b)%MOD;
}
inline ll expmod(ll a, ll e){
    ll ret = 1;
    while(e){
        if(e&1)ret = mulmod(ret, a);
        a = mulmod(a, a);
        e >>= 1;
    }
    return ret;
}
inline ll divmod(ll a, ll b){
    return mulmod(a, expmod(b, MOD-2));
}

const int P = 400;

int powSum[P+5][P+5]; // powSum[n][k] = 1^k + 2^k + ... + n^k
inline int f(int a, int b, int k){ // a^k + (a+1)^k + ... + b^k
    return submod(powSum[b][k], powSum[a-1][k]);
}

const int N = 405;
int n,c;
int a[N], b[N];

int memo[N][N];
int dp(int now, int left){
    int& ret = memo[now][left];
    if(ret != -1)return ret;
    
    ret = 0;
    if(now == n){
        ret = f(a[now], b[now], left);
    }else{
        REP(i,0,left){
            ret = addmod(ret, mulmod(f(a[now], b[now], i), dp(now+1, left-i)));
        }
    }
    
    return ret;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    REP(i,1,P){
        int cn = 1;
        REP(j,0,P){
            powSum[i][j] = addmod(powSum[i-1][j], cn);
            cn = mulmod(cn, i);
        }
    }
    
    cin>>n>>c;
    REP(i,1,n){
        cin>>a[i];
    }
    REP(i,1,n){
        cin>>b[i];
    }
    
    memset(memo, -1, sizeof memo);
    cout << dp(1, c) << endl;
    
    return 0;
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	string n;
	cin >> n;
	for (int i = 0; i < 3; i++)
	{
		if (n.at(i) == '1')
			n.at(i) = '9';
		else if (n.at(i) == '9')
			n.at(i) = '1';
	}
	cout << n << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define rall(v)     (v).rbegin(),(v).rend()
#define sort(v)     sort((v).begin(),(v).end())
#define rsort(v)    sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
#define sum(v)+x    accumulate(v.begin(), v.end(),x);
typedef pair<int,int> pii;  
typedef vector<int> vi;
//x.substr(start, length);
/*
// Create a vector containing n 
//vectors of size m.  
    vector<vector<int> > vec( n , vector<int> (m, 0));  
*/
struct type{
    int k, i, j;
};
//to check if a no is prime or not?
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

// minimum subaaray sum of size k-sliding window approach
int findSubarray(int arr[], int n, int k)
{
	int window_sum = 0;
	int min_window = INT_MAX;
	int last = 0;
	for (int i = 0; i < n; i++)
	{
		window_sum += arr[i];
		if (i + 1 >= k)
		{
			if (min_window > window_sum)
			{
				min_window = window_sum;
				last = i;
			}
			window_sum -= arr[i + 1 - k];
		}
	}
	int sum=0;
	for(int i=last-k+1;i<=last;i++)
	{
	    sum+=arr[i];
	}
	return sum;
}
//finds the next permutation to given sequence of nos
int nextpermutation(vi v)
{
    vi t=v;
    sort(t);
    int x=0;
    while(true)
    {
        x++;
        if(t==v)
        {
            return x;
        }
        next_permutation(all(t));
    }
}
signed main() 
{
    fastio;
    //cout << fixed << setprecision(0);
    string s,t;
    cin>>s>>t;
    cout<<t<<""<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 300100
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reprev(i,n) for(int i=(int)n-1;i>=0;i--)
int n;
char s;
bool WEST[MAX];
int l[MAX],r[MAX];
int main(){
    cin>>n;rep(i,n){
        cin>>s;
        if(s=='W')WEST[i]=1;
        else WEST[i]=0;
    }
    int max=0;
    r[n-1]=0;
    l[0]=0;
    for(int i=0;i<n-1;i++){
        l[i+1]=!WEST[i]+l[i];
    }
    for(int i=n-1;i>0;i--){
        r[i-1]=WEST[i]+r[i];
    }
    rep(i,n){
        if(l[i]+r[i]>max)max=l[i]+r[i];
    }
    cout<<n-max-1<<endl;
    return 0;
    }


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>

using namespace std;

int main()
{
	int n; cin >> n;

	bool is_even = (n & 1) == 0;

	int n_num = n * (n - 1) / 2;
	n_num -= (n / 2);
	cout << n_num << endl;

	for (int i = 1; i <= n - 1; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (is_even) {
				if (i + j == n + 1) continue;
			}
			else {
				if (i + j == n) continue;
			}

			cout << i << " " << j << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    string n;
    cin >> n;
    int count;

    for (int i = 0; i < n.size(); ++i){
        if (n[i] == '1') {
            ++count;
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}; 
int h, w, dist[25][25][25][25];
char grid[25][25];
queue<pair<int, int> > Q;
int main()
{
	cin >> h >> w;
	for(int i = 1; i <= h; i++) for(int j = 1; j <= w; j++) cin >> grid[i][j];
	for(int i = 1; i <= h; i++) for(int j = 1; j <= w; j++)
	{
		if(grid[i][j]=='#') continue;
		while(!Q.empty()) Q.pop();
		Q.push(make_pair(i, j));
		dist[i][j][i][j] = 1;
		while(!Q.empty())
		{
			pair<int, int> now = Q.front();
			Q.pop();
			int nx = now.first, ny = now.second;
			for(int k = 0; k < 4; k++)
			{
				int tx = nx + dx[k], ty = ny + dy[k];
				if(tx < 1 || tx > h || ty < 1 || ty > w) continue;
				if(dist[i][j][tx][ty]) continue;
				if(grid[tx][ty] == '#') continue;
				Q.push(make_pair(tx, ty));
				dist[i][j][tx][ty] = dist[i][j][nx][ny] + 1; 
			}
		}
	}
	int mx = 0;
	for(int i = 1; i <= h; i++) for(int j = 1; j <= w; j++) if(grid[i][j]=='.') for(int i2 = 1; i2 <= h; i2++) for(int j2 = 1; j2 <= w; j2++) if(grid[i2][j2]=='.') mx = max(mx, dist[i][j][i2][j2]); 
	cout << mx - 1 << endl;
	return 0;
}
/*
5 5
.#...
.#...
.##..
..##.
#.... 
14
*/

Measured memory_bytes: 1280
#!/usr/bin/env python3
import sys


def solve(S: str):
    if S[-1] == 's':
        return S + 'es'
    else:
        return S + 's'


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print(solve(S))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9040
#include <iostream>
#include <vector>
using namespace std;
typedef long long lli;
lli n;
vector<lli> a;
lli dp[100005][3];
int main(int argc, char const *argv[]) {
    cin >> n;
    lli x;
    char c;
    cin >> x;
    a.push_back(x);
    for(lli i = 1;i < n;i++){
        cin >> c >> x;
        if(c == '-') a.push_back(x*-1);
        if(c == '+') a.push_back(x);
    }
    for(lli i = 0;i < a.size();i++){
        dp[i][0] = dp[i][1] = dp[i][2] = -100000000000000;
    }
    dp[0][0] = 0;
    for(lli i = 0;i < a.size();i++){
        if(a[i] > 0){
            dp[i+1][0] = max(dp[i][0]+a[i],dp[i][1]+a[i]);
            dp[i+1][1] = dp[i][1] - a[i];
            dp[i+1][2] = dp[i][2] + a[i];
        }else{
            dp[i+1][1] = dp[i][0]+a[i];
            dp[i+1][2] = max(dp[i][1]-a[i],dp[i][2]-a[i]);
        }
    }
    cout << max(max(dp[a.size()][0],dp[a.size()][1]),dp[a.size()][2]) << endl;
    return 0;
}


Measured memory_bytes: 3572
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;

const int mxn = 1e5 + 5;
int n, m;
vector<int> G[mxn];

int vis[mxn], dp[mxn];

int dfs( int u ) {
	if( ~dp[u] ) return dp[u];
	dp[u] = 0;
	vis[u] = 1;

	for(auto& v : G[u]) {
		if( !vis[v] ) {
			dp[v] = dfs( v );
		}
		dp[u] = max(dp[u], dp[v] + 1);
	}
	return dp[u];
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for(int i = 1, u, v; i <= m; i++) {
		cin >> u >> v;
		G[u].push_back(v);
	}

	memset(dp, -1, sizeof dp);
	for(int i = 1; i <= n; i++) {
		dfs( i );
	}

	int res = 0;
	for(int i = 1; i <= n; i++) {
		res = max(res, dp[i]);
	}
	cout << res << "\n";
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){

    string x;               cin>>x;
    map<char,ll>M;          bool z=true;
    for(int i=0;i<x.size();i++){
        M[x[i]]++;
    }
    for(char i='a';i<='z';i++){
        if(M[i]&1)          z=false;
    }
    (z)?cout<<"Yes":cout<<"No";

    return 0;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=10005;
char s[N],t[N];int fac[N],ifac[N],f[N][N],n,cnta,cntb;
inline int C(R int n,R int m){return m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
inline void init(int n=10000){
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
}
int main(){
	init();
	scanf("%s%s",s+1,t+1),n=strlen(s+1);
	fp(i,1,n){
		cnta+=(s[i]=='1'&&t[i]=='1');
		cntb+=(s[i]=='1'&&t[i]=='0');
	}
	f[0][0]=1;
	fp(j,1,cntb)f[0][j]=mul(fac[j],fac[j]);
	fp(i,1,cnta)fp(j,1,cntb)
		f[i][j]=(1ll*i*j%P*f[i-1][j]+1ll*j*j%P*f[i][j-1])%P;
	R int res=0;
	fp(i,0,cnta){
		R int j=cnta-i;
		upd(res,1ll*f[i][cntb]*fac[j]%P*fac[j]%P*C(cnta,j)%P*C(cnta+cntb,j)%P);
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 387840
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const ll MOD = 1e9 + 7;
const int N = 2e5;

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; 
  }
  return res;
}

ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}

ll modcomb(ll n, ll k) {
  ll res = 1;
  rep(i, k) res = res * (n-i) % MOD;
  rep(i, k) res = res * modinv(i+1) % MOD;
  return res;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = (modpow(2, n) - 1) % MOD;
  ans = (ans - modcomb(n, a)) % MOD;
  ans = (ans - modcomb(n, b)) % MOD;
  if (ans < 0) ans += MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


// 最長増加部分列(LIS: Longest Increasing Subsequence)
// 値が以上のときと、より大きいで、ちょっと違うので注意
int lis(const vector <int>& order)
{
	int max_len = 0;
	const int M = SZ(order);
	// O(nlogn) Mは文字数で、min_last_value[l]は 長さl+1のつくるときに、増加列の最後の数値の最小値
	vector <int> min_value(M, BIG);

	for (int i = 0; i < M; i++)
	{
		*upper_bound(min_value.begin(), min_value.end(), order[i]) = order[i]; // 以上
																			   //		*lower_bound(min_value.begin(),min_value.end(),order[i])=order[i]; // より大きい
	}

	max_len = lower_bound(min_value.begin(), min_value.end(), BIG) - min_value.begin();

	return max_len;
}


int main()
{
	int n;
	cin >> n;

	vector <int> a;

	for (int i = 0; i < n; ++i)
	{
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	reverse(a.begin(), a.end());

	ll ret = lis(a);

	cout << ret << endl;


	return 0;
}


Measured memory_bytes: 1144
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

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

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

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

    size_t N, W;
    cin >> N >> W;

    vector<intmax_t> w(N), v(N);
    for (size_t i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    auto dp = make_v(0_im, N + 1, W + 1);
    for (size_t i = 0; i < N; ++i) {
        for (size_t weight = 0; weight <= W; ++weight) {
            chmax(dp[i + 1][weight], dp[i][weight]);
            if (weight >= w[i]) {
                chmax(dp[i + 1][weight], dp[i][weight - w[i]] + v[i]);
            }
        }
    }

    cout << dp[N][W] << "\n";

    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
	return __builtin_parity(x);
}

string s;

signed main(){
	cin>>s;

	rep(i,1<<3){
		int val=s[0]-'0';
		rep(j,3){
			int a=s[j+1]-'0';
			if(i>>j&1)val+=a;
			else val-=a;
		}
		if(val!=7)continue;

		cout<<s[0];
		rep(j,3){
			if(i>>j&1)cout<<"+";
			else cout<<"-";
			cout<<s[j+1];
		}
		cout<<"=7"<<endl;
		return 0;
	}

	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(){
	int a[10000];
	int b[10000];
	char enzansi[10000];
	int c[10000];
	for(int i=1;i<10000;i++){
		scanf("%d %c %d\n",&a[i],&enzansi[i],&b[i]);
		if(enzansi[i] == '?'){
			break;
		}else if(enzansi[i] == '+'){
			c[i] = a[i] + b[i];
		}else if(enzansi[i] == '-'){
			c[i] = a[i] - b[i];
		}else if(enzansi[i] == '*'){
			c[i] = a[i] * b[i];
		}else if(enzansi[i] == '/'){
			c[i] = a[i] / b[i];
		}
	}
	for(int j=1;j<=10000;j++){
		if(enzansi[j] == '?'){
			break;
		}
		printf("%d\n",c[j]);
	}
}
/*mohankaitou
1 + 2
56 - 18
13 * 2
100 / 10
27 + 81
0 ? 0

3
38
26
10
108
*/


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

int main() {
   ll i,j,k;
   int n;
    string s;
    cin >>n>>s ;
    for(i=0; i<n; i++)
    {
      // ll num=(s[i]-'A'+n)%26;
      // s[i]+='A'+num;
      
    }
i=0;
    while(s[i]!='\0'){
      int num;
      int a='A';
      num=(s[i]+a+n+26)%26;
      
s[i]=a+num;
i+=1;
    }
  cout << s << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int X;
  cin >> X;
  // main procedure

  // output
  cout << 8 - ((X - 400) / 200) << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};
using fint64 = int_fast64_t;
struct Combination {
	const int MAX = 5000010;
	const int MOD;
	vector<fint64> FAC;
	vector<fint64> INV;
	vector<fint64> FAC_INV;
	Combination(fint64 MOD) :
		MOD(MOD),
		FAC(vector<fint64>(MAX)),
		INV(vector<fint64>(MAX)),
		FAC_INV(vector<fint64>(MAX))
		{
			FAC[0] = INV[1] = FAC_INV[0] = 1;
			for(int i = 1; i < MAX; ++i) {
				FAC[i] = FAC[i - 1] * i % MOD;
				if(i > 1) INV[i] = MOD - INV[MOD % i] * (MOD / i) % MOD;
				FAC_INV[i] = FAC_INV[i - 1] * INV[i] % MOD;
			}
		}
	fint64 C(int n, int r) {
		if(n < 0 or r < 0 or n < r) return 0;
		return FAC[n] * FAC_INV[r] % MOD * FAC_INV[n - r] % MOD;
	}
	fint64 P(int n, int r) {
		if(n < 0 or r < 0 or n < r) return 0;
		return FAC[n] * FAC_INV[n - r] % MOD;
	}
	fint64 H(int n, int r) {
		if(r == 0) return 1;
		return C(n + r - 1, r);
	}
};

template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

using mint = ModInt<LMOD>;
int main() {
	int n, m, k; cin >> n >> m >> k;
	Combination com(LMOD);
	mint x = m - 1;
	mint ans = x.pow(n - 1) * m;
	// cerr << ans << '\n';

	for(int i = 1; i <= k; ++i) {
		mint po = m - 1;
		ans += po.pow(n - i - 1) * m * com.H(n - i, i);
		// cerr << ans << '\n';
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 120476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


int main(){
    ll x; cin >> x;
    cout << (x == 0 ? 1 : 0) << endl;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    ll n, h;
    cin >> h >> n;
    vl a(n);
    rep(i, n) cin >> a[i];

    ll sum = accumulate(all(a), 0);
    if (sum >= h)
        CYES;
    else
        CNO;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int x[55];
long long dp[55][55*55];
int main()
{
	int n,a;
	cin >> n >> a;
	dp[0][0] = 1;
	for(int i = 1;i <= n;i++)
	cin >> x[i];
	for(int i = 1;i <= n;i++)
	{
		for(int j = i-1;j >= 0;j--)
		for(long long k = 55*j;k >=0 ;k--)
		dp[j+1][k+x[i]] += dp[j][k];
	}
	long long ans = 0;
	for(int i = 1;i <= n;i++)
	{
		ans += dp[i][i*a];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;
const ll INF = 1e9+10;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	int n; cin >> n;
	vector<ll> v(n+1); FOR(i, n+1) cin >> v[i];

	vector<ll> tam(n+7, 1);
	FOR(i, n+1){
		if(v[i] > tam[i]){
			cout << "-1\n";
			return 0;
		}
		tam[i+1] = min((tam[i]-v[i])*2LL, 100000000000000LL);
	}

	ll ans = 0;
	ll now = 0;
	for(int i = n; i >= 0; i--){
		if(now + v[i] <= tam[i]){
			ans += now + v[i];
			now += v[i];
		}else{
			ll dif = tam[i]-v[i];
			now = max(dif, (now+1)/2);
			ans += now + v[i];
			now += v[i];
		}
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
const double pi = 3.141592653589793238;
double a, b, h, m;
int i;

int main() {
    scanf(" %lf %lf %lf %lf", &a, &b, &h, &m);
    double angle = abs((m / 30 - h / 6 - m / 360) * pi);
    if (angle > pi) angle = 2 * pi - angle;
    double dist = sqrt(a*a + b*b - 2*a*b*cos(angle));

    printf("%.15lf\n", dist);
}

Measured memory_bytes: 4256
<?php
  
 fscanf(STDIN,"%d %d",$N,$K);
for($i=0;$i<$N;$i++){
  $h_list[] = trim(fgets(STDIN));
}

sort($h_list);


$diff = array();
$ans = 10**9;
for($i=0;$i<=($N-$K);$i++){
      $ans = min($h_list[$i + $K - 1] - $h_list[$i], $ans);

}

echo $ans."\n";


 

Measured memory_bytes: 12792
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
struct nd{
    int to, w;
    nd(int t, int ww) : to(t), w(ww) {}
};
std::vector<nd> vec[100005];
int drg[100005];
bool vis[100005];
bool col[100005];
int main(){
    int n;
    std::cin >> n;
    int u,v,w;
    for(int i = 1; i < n; ++ i){
        std::cin >> u >> v >> w;
        vec[u].push_back(nd(v,w));
        vec[v].push_back(nd(u,w));
        drg[u] ++;
        drg[v] ++;
    }
    std::queue<int> que;
    vis[1] = true;
    que.push(1);
    while(!que.empty()){
        int it = que.front();
        que.pop();
        for(auto &ir : vec[it]){
            if (!vis[ir.to]) {
                if (ir.w & 1) col[ir.to] = !col[it];
                else col[ir.to] = col[it];
                que.push(ir.to);
                vis[ir.to] = true;
            }
        }
    }
    for(int i =1 ; i<= n; ++ i){
        std::cout << col[i] << std::endl;
    }
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    int n;
    cin >> n;
    
    vector<vector<int> > a(n, vector<int>(n - 1));
    
    rep(i, n) rep(j, n - 1) { cin >> a[i][j]; a[i][j]--; }
    rep(i, n) reverse(all(a[i]));
    
    vector<pii> q;
    auto check = [&](int i) {
        if (sz(a[i]) == 0) return;
        int j = a[i].back();
        if (sz(a[j]) == 0) return;
        if (a[j].back() == i) {
            pii p(i, j);
            if (p.S < p.F) swap(p.F, p.S);
            q.eb(p);
        }
    };
    
    // 初日にできる試合
    // ただし, 同じの重複する
    rep(i, n) check(i);
    
    
    // rep(i, sz(q)) cout << q[i].F << " " << q[i].S << endl;
    
    int day = 0;
    while (sz(q) > 0) {
        day++;
        sort(all(q));
        q.erase(unique(all(q)), q.end());
        
        vector<pii> prevQ;
        swap(prevQ, q); // qは空
        
        for (pii p : prevQ) {
            int i = p.F, j = p.S;
            a[i].pop_back();
            a[j].pop_back();
        }
        
        for (pii p : prevQ) {
            int i = p.F, j = p.S;
            check(i); // 試合を終えたら次の試合できる
            check(j);
        }
        
    }
    
    rep(i, n) {
        if (sz(a[i]) != 0) { // 試合終わってない
            puts("-1");
            return 0;
        }
    }
    cout << day << '\n';
    return 0;
}



Measured memory_bytes: 4224
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { //Partition babyyyyyyyyy
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		int K = I.nextInt();
		long[] a = new long[N];
		long ans = Long.MAX_VALUE;
		for (int i = 0; i < N; i++) a[i] = I.nextLong();
		for (int chk = 0; chk+K-1 < N; chk++) {
			long cur = 0;
			if (a[chk]<0&&a[chk+K-1]>0) { //Inverse of this is never possible since 
				//array is sorted
				cur+=Math.min(-a[chk],a[chk+K-1]); //Both ways make a difference
				//Less big one way ticket --> Less overlap --> Better answer
				long diff = a[chk+K-1]-a[chk];
				cur+=diff;
			}else if (a[chk+K-1]<0&&a[chk]<0) {
				cur=-a[chk];
			}else{
				cur=a[chk+K-1]; //Always have to start from 0 boi
			}
			ans=Math.min(ans, cur);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 41368
#include <iostream>
using namespace std;
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b && c!=a && c!=b)
    cout << "Yes";
  else if(a==c && b!=a && b!=c)
    cout << "Yes";
  else if(b==c && a!=b && a!=c)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// Gate Data
type Gate struct {
	left, right int
}

func maxInt(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func solve(cardNum, gateNum int, gates []Gate) int {
	left := 1
	right := cardNum
	for _, g := range gates {
		left = maxInt(left, g.left)
		right = minInt(right, g.right)
	}
	if left > right {
		return 0
	}
	return right - left + 1
}

func main() {
	var n, m int
	var gates []Gate
	fmt.Scanln(&n, &m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for i := 0; i < m; i++ {
		sc.Scan()
		l, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		r, _ := strconv.Atoi(sc.Text())
		gates = append(gates, Gate{l, r})
	}
	ans := solve(n, m, gates)
	fmt.Println(ans)
}


Measured memory_bytes: 7424
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
ll n, m;
ll a[200005];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	ll ans = 0;
	rep(i, n) {
		if (a[i + 1] - a[i] > 1 || a[i] > i) {
			cout << -1 << endl;
			return 0;
		}
		if (a[i] >= a[i + 1]) {
			ans += a[i];
		}

	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    multiset<ll> s;
    for(int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        s.insert(a);
    }
    ll ans = 0;
    while(!s.empty())
    {
        ll cand = *s.rbegin();
        s.erase(s.find(cand));
        ll x = 1;
        while(x <= cand)
        {
            x *= 2;
        }
        auto itr = s.find(x-cand);
        if(itr == s.end())
        {
            continue;
        }
        else
        {
            ans++;
            s.erase(itr);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 9600