akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <fstream>

using namespace std;

int ans = 1e9;

string s;

int main()
{
	cin >> s;
	for (int i = 0;i < 26;i++)
	{
		bool ok = 0;
		for (int j = 0;j < s.size();j++)
			if (s[j] == 'a' + i)
				ok = 1;
		if (!ok)
			continue;
		int lst = -1,MAX = 0;
		for (int j = 0;j < s.size();j++)
			if (s[j] == 'a' + i)
			{
				MAX = max(MAX,j - lst - 1);
				lst = j;
			}
		MAX = max(MAX,(int)s.size() - lst - 1);
		ans = min(ans,MAX);
	}
	cout << ans << endl;
	return 0;
}

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

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

  vector<int> prime;
  int flag = 0;
  for(int i = 2; i < 55555+1; i++) {
    flag = 0;
    for(int j = 2; j < sqrt(i)+1; j++) {
      if(i % j == 0) {
        flag = 1;
        break;
      }
    }
    if(flag == 0) {
      prime.push_back(i);
    }
  }

  vector<int> array;
  for(int i = 0; i < prime.size(); i++) {
    if(prime[i] % 5 == 1) {
      array.push_back(prime[i]);
    }
  }

  int sum = 0;
  for(int i = 0; i < n; i++) {
    cout << array[i] << " ";
    sum += array[i];
  }

  //cout << sum << endl;

  cout << endl;

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if((a<=c and c<=b) or (c<=a and b<=c)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
   return 0;
}

Measured memory_bytes: 256
// AtCoder ABC132: B - Ordinary Number
// 2019.9.3 bal4u

#include <stdio.h>

int p[25];

int main()
{
	int i, n, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", p+i);
	ans = 0;
	for (i = 1; i < n-1; i++) {
		if (p[i-1] < p[i] && p[i] < p[i+1] || p[i-1] > p[i] && p[i] > p[i+1])
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,A[200010],ct1,ct2,ct4;
int main()
{
	// freopen("read.in","r",stdin);
	n=read(); for(int i=1;i<=n;i++) A[i]=read();
	for(int i=1;i<=n;i++) if(A[i]%4==0) ct4++;
		else if (A[i]%2==0) ct2++;
		else ct1++;
	if(!ct1&&!ct2) printf("Yes\n");
	else if(ct1&&!ct2)
	{
		if(ct4>=ct1-1) printf("Yes\n");
		else printf("No\n");
	}
	else if(!ct1&&ct2) printf("Yes\n");
	else 
	{
		if(ct4>=ct1) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}



Measured memory_bytes: 640
n = int(input())
V = [int(v) for v in input().split(' ')]

even_map = {}
odd_map = {}

for i in range(0, n, 2):
    v = V[i]
    if not v in even_map:
        even_map[v] = 1
    else:
        even_map[v] += 1


for i in range(1, n, 2):
    v = V[i]
    if not v in odd_map:
        odd_map[v] = 1
    else:
        odd_map[v] += 1

even_map[0] = 0
odd_map[0] = 0
even_sorted = sorted(even_map.items(), key=lambda x: -x[1])
odd_sorted = sorted(odd_map.items(), key=lambda x: -x[1])

even1 = even_sorted[0][0]
odd1 = odd_sorted[0][0]

if even1 != odd1:
    print(n - (even_sorted[0][1] + odd_sorted[0][1]))
    exit()

print(min(n - (even_sorted[0][1] + odd_sorted[1][1]), n - (odd_sorted[0][1] + even_sorted[1][1])))

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

static const int NMAX = 100;
static const int INF = (1<<29);

int x[NMAX+1],y[NMAX+1],h[NMAX+1];
int N;

int main(){
  cin >> N;
  for(int i=0;i<N;i++) cin >> x[i] >> y[i] >> h[i];

  int s = 0;
  for(int i=0;i<N;i++) if (h[i] != 0) s = i;

  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      int top_h = h[s] + abs(x[s]-i) + abs(y[s]-j);
      bool frag = true;
      for(int k=0;k<N;k++){
        if(h[k] != max(0,top_h - abs(x[k] - i) - abs(y[k] - j))) frag = false;
      }
      if(frag){
        cout << i << " " << j << " " << top_h << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100010;
const int inf=1e9;
int dp[N];
int main(){
    int n,k;
    cin>>n>>k;
    int a[n+5];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++) dp[i]=inf;
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=k;j++){
        if(i-j>=0) dp[i]=min(dp[i],dp[i-j] + abs(a[i]-a[i-j]));
        }
    }
    cout<<dp[n-1]<<'\n';
    
}
  


Measured memory_bytes: 4416
class SegmentTree(object):

    def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7):

        self.seg_func = seg_func
        self.seg_func_null = seg_func_null
        self.n = 1
        while self.n < len(init_array):
            self.n *= 2
        self.dat = [0] * (2 * self.n - 1)
        for i in range(len(init_array)):
            self.dat[self.n - 1 + i] = init_array[i]
        for i in range(self.n - 2, -1, -1):
            self.dat[i] = self.seg_func(self.dat[2 * i + 1], self.dat[2 * i + 2])

    def update(self, k, a):
        k += self.n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = self.seg_func(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    def query(self, p, q):
        # [p, q)
        if q <= p:
            return self.seg_func_null

        p += self.n - 1
        q += self.n - 2
        res = self.seg_func_null

        while q - p > 1:
            if p & 1 == 0:
                res = self.seg_func(res, self.dat[p])
            if q & 1 == 1:
                res = self.seg_func(res, self.dat[q])
                q -= 1
            p = p // 2
            q = (q-1) // 2
        if p == q:
            res = self.seg_func(res, self.dat[p])
        else:
            res = self.seg_func(self.seg_func(res, self.dat[p]), self.dat[q])

        return res


def solve(n, m, lrc_list):
    s = SegmentTree([10 ** 15 + 1] * n, min, 10 ** 15 + 1)
    s.update(0, 0)
    lrc_list_s = sorted(lrc_list, key=lambda x: x[0])
    for i in range(m):
        l, r, c = lrc_list_s[i]
        p = s.query(l - 1, r)
        if p + c < s.query(r - 1, r):
            s.update(r - 1, p + c)
    if s.query(n - 1, n) == 10 ** 15 + 1:
        return -1
    else:
        return s.query(n - 1, n)


def main():
    n, m = map(int, input().split())
    lrc_list = []
    for _ in range(m):
        l, r, c = map(int, input().split())
        lrc_list.append([l, r, c])
    res = solve(n, m, lrc_list)
    print(res)


def test():
    assert solve(4, 3, [[1, 3, 2], [2, 4, 3], [1, 4, 6]]) == 5
    assert solve(4, 2, [[1, 2, 1], [3, 4, 2]]) == -1


if __name__ == "__main__":
    # test()
    main()


Measured memory_bytes: 101464
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main() {
	int n,m;
	cin >> n >> m;
	vector<ll> a(n);
	REP(i,n){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	vector<pair<ll,ll>> c(m);
	REP(i,m){
		cin >> c[i].second >> c[i].first;
	}
	sort(c.begin(),c.end(),greater<pair<ll,ll>>());
	int i=0;
	int now=0;
	while(c[i].first>a[now]&&now<a.size()){
		int count=0;
		while(c[i].first>a[now]&&count<c[i].second&&now<a.size()){
			a[now]=c[i].first;
			now++;
			count++;
		}
		i++;
	}
	ll ans=0;
	REP(i,n){
		ans+=a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;

bool f(pair<string,int> a,pair<string,int>b){
    if(a.first!=b.first){
        return a.first<b.first;
    }
    return a.second>b.second;
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>>l(m);
    vector<int>p(m);
    rep(i,m){
        int k;
        cin>>k;
        rep(j,k){
            int s;
            cin>>s;
            l[i].push_back(s-1);
        }
    }
    rep(i,m){
        cin>>p[i];
    }
    int ans=0;
    rep(i,1<<n){
        bool ok=true;
        vector<int>s(n);
        rep(j,n){
            if(i>>j&1)s[j]=1;
        }
        rep(j,m){
            int e=0;
            for(int x:l[j])e^=s[x];
            if(e!=p[j]){
                ok=false;
                break;
            }
        }
        if(ok)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;

const ll MOD = (1e+9) + 7;

ll dp[100001][4];

int main()
{
  string s;
  cin >> s;

  dp[0][0] = 1;

  for(int i = 1; i <= s.size(); i++){
    for(int j = 0; j < 4; j++){
      dp[i][j] += dp[i-1][j] * (s[i-1] == '?' ? 3 : 1);
      dp[i][j] %= MOD;
    }

    if(s[i-1] == '?' || s[i-1] == 'A'){
      dp[i][1] += dp[i-1][0];
      dp[i][1] %= MOD;
    }
    if(s[i-1] == '?' || s[i-1] == 'B'){
      dp[i][2] += dp[i-1][1];
      dp[i][2] %= MOD;
    }
    if(s[i-1] == '?' || s[i-1] == 'C'){
      dp[i][3] += dp[i-1][2];
      dp[i][3] %= MOD;
    }

  }

  cout << dp[s.size()][3] << endl;

  return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
 
typedef long long Int;
typedef vector<int> VI;
typedef pair<int, int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const Int LINF = INF * (Int) INF;
const int MAX = 4007; 

const int MOD = 998244353;

int main(int argc, char* argv[])
{
	// freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    VI A(n);
    FOR(i,0,n)
    {
        cin >> A[i];
    }
    sort(ALL(A));
    if (A.back() == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (n % 3 != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    if (A[0] != A[n / 3 - 1] || A[n / 3] != A[2 * n / 3 - 1] || A[2 * n / 3] != A[n - 1])
    {
        cout << "No" << endl;
        return 0;
    }
    if ((A[0] ^ A[n / 3] ^ A[2 * n / 3]) != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    // cerr << 1.0 * clock() / CLOCKS_PER_SEC << ' ' << eval(res) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(ab.begin(), ab.end());
    ll cnt = 0;
    rep(i, n) {
        cnt += ab[i].second;
//        cout << cnt << " " << ab[i].first << " " << ab[i].second << endl;
        if ( cnt >= k ) {
            cout << ab[i].first << endl;
            return 0;
        }        
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 入力
        int n = sc.nextInt();
        int r = sc.nextInt();

        // 処理
        int out = 0;
        if (n >= 10){
            out = r;
        } else {
            out = r + (100 * (10 - n));
        }

        // 出力
        System.out.println(out);
    }

}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

ll N, M, root;
vector<ll> G[101010];
vector<ll> dist(101010, -1);
vector<ll> par(101010);

ll dp(ll now){
    if(dist[now]>=0) return dist[now];
    ll p;
    ll ma = -1;
    REP(i, G[now].size()){
        ll next = G[now][i];
        ll tmp = dp(next);
        if(ma < tmp){
            ma = tmp;
            p = next;
        }
    }
    dist[now] = ma+1;
    par[now] = p;
    return dist[now];
}


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

    cin >> N >> M;
    vector<ll> iri(N, 0);
    REP(i, N-1+M){
    	ll A, B;
    	cin >> A >> B;
    	A--, B--;
    	G[B].push_back(A);
    	iri[B]++;
    }

    REP(i, N) if(iri[i] == 0) root = i;

    dist[root] = 0;
    par[root] = -1;
    REP(i, N) dp(i);

    REP(i, N){
    	cout << par[i]+1 << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct RootedTree {
    RootedTree(int n, int root = 0) :
            mRoot(root) {
        mVertexTbl.resize(n);
    }

    void addEdge(int a, int b, long long int cost = 1) {
        mVertexTbl[a].child.push_back(pair<int, long long int>(b, cost));
        mVertexTbl[b].child.push_back(pair<int, long long int>(a, cost));
    }

    void build() {
        queue<tuple<int, int, long long int>> q;
        q.push(make_tuple(mRoot, -1, 0));
        while (!q.empty()) {
            auto t = q.front();
            q.pop();
            int index = get<0>(t);
            int parent = get<1>(t);
            long long int depth = get<2>(t);
            mVertexTbl[index].parent = parent;
            mVertexTbl[index].depth = depth;
            for (auto it = mVertexTbl[index].child.begin(); it != mVertexTbl[index].child.end();) {
                int nxt = (*it).first;
                if (nxt == parent) {
                    mVertexTbl[index].child.erase(it);
                    continue;
                }
                q.push(make_tuple(nxt, index, depth + (*it).second));
                ++it;
            }
        }
    }

    vector<int> getLeaf() {
        vector<int> leafs;
        for (int i = 0; i < mVertexTbl.size(); ++i) {
            if (mVertexTbl[i].child.size() == 0)
                leafs.push_back(i);
        }
        return leafs;
    }

    struct Vertex {
        vector<pair<int, long long int>> child;
        long long int depth = 0;
        int parent = -1;
    };

    int mRoot;
    vector<Vertex> mVertexTbl;
};

int main() {
    ll N;
    cin >> N;
    RootedTree tree(N);
    REP(i, N - 1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        tree.addEdge(a, b, c);
    }

    ll Q, K;
    cin >> Q >> K;
    K--;
    tree.mRoot = K;
    tree.build();
    REP(_, Q) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << tree.mVertexTbl[x].depth + tree.mVertexTbl[y].depth << endl;
    }
    return 0;
}

Measured memory_bytes: 13168
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define N 400010
#define ll long long
#define mod 200003
#define G 11
using namespace std;
ll num[N],cnt[N],_11[N];
const double pi=acos(-1);
struct xu{
	double s,x;
	xu(double S=0.0,double X=0.0):s(S),x(X){};
	xu operator +(const xu a){return xu(s+a.s,x+a.x);}
	xu operator -(const xu a){return xu(s-a.s,x-a.x);}
	xu operator *(const xu a){return xu(s*a.s-x*a.x,s*a.x+x*a.s);}
};

void fft(xu a[],int n,int len)
{
	int rev[n];
	rev[0]=0;
	for(int i=1;i<n;i++)
	{
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(len-1));
		if(rev[i]>i) swap(a[rev[i]],a[i]);
	}
	for(int i=1;i<n;i<<=1)
	{
		xu omg(cos(pi/i),sin(pi/i));
		for(int j=0;j<n;j+=i*2)
		{
			xu orz(1,0);
			for(int k=0;k<i;k++)
			{
				xu n1=a[j+k],n2=orz*a[i+k+j];
				a[j+k]=n1+n2;
				a[i+j+k]=n1-n2;
				orz=orz*omg;
			}
		}
	}
}
void nfft(xu a[],int n,int len)
{
	int rev[n];
	rev[0]=0;
	for(int i=1;i<n;i++)
	{
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(len-1));
		if(rev[i]>i) swap(a[rev[i]],a[i]);
	}
	for(int i=1;i<n;i<<=1)
	{
		xu omg(cos(pi/i),-sin(pi/i));
		for(int j=0;j<n;j+=i*2)
		{
			xu orz(1,0);
			for(int k=0;k<i;k++)
			{
				xu n1=a[j+k],n2=orz*a[i+k+j];
				a[j+k]=n1+n2;
				a[i+j+k]=n1-n2;
				orz=orz*omg;
			}
		}
	}
	for(int i=0;i<n;i++) {
		a[i].s=a[i].s/n;
		a[i].x=a[i].x/n;
	}
}
xu f[mod*4];
int main()
{
    int n;
    ll s=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&num[i]);
    _11[0]=1;
    for(int i=1;i<=mod-2;i++)
    {
        _11[i]=1ll*_11[i-1]*G%mod;
        cnt[_11[i]]=i;
    }
    int m=1,l=0;
    while(m<=mod*2) m=m*2,l++;
    for(int i=1;i<=n;i++)
    if(num[i])f[cnt[num[i]]].s++;
    fft(f,m,l);
    for(int i=0;i<m;i++) f[i]=f[i]*f[i];
    nfft(f,m,l);
    // for(int i=0;i<m;i++)
    // if((ll)(f[i].s+0.5)) printf("%d:%d - %d\n",i,_11[i%mod],(ll)(f[i].s+0.5));
    ll ans=0;
    for(int i=0;i<mod*2;i++)
        ans+=1ll*_11[i%(mod-1)]*(ll)(f[i].s+0.5);
    for(int i=1;i<=n;i++) ans-=1ll*num[i]*num[i]%mod;
    ans/=2;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 23360
#include<bits/stdc++.h>
using namespace std;
//10 9 10 10
//46 4 40 5
int main(){
	int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(a>0 && c>0)
  {
  	c-=b;
    if(c<=0)
    {
      cout << "Yes" << endl;
      break;
    }
    a-=d;
    if(a<=0)
    {
      cout << "No" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <stdlib.h>
#include <assert.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int n, q, l;
ll v[100004];
int dp[100004];
int at[100004];
int d[18][100004];
int main()
{
	scanf("%d", &n);
	int last = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%lld", v + i);
		int tmp = v[i];
		v[i] -= last;
		last = tmp;
		if (i)
			v[i] += v[i - 1];
	}
	v[n + 1] = v[n] = v[n - 1];
	scanf("%d", &l);
	memset(d, -1, sizeof(d));
	for (int i = n - 1; i >= 0; --i) {
		int nxt = upper_bound(v, v + n + 2, v[i] + l) - v - 1;
		dp[i] = 1 + dp[nxt];
		at[i] = nxt;
		d[0][i] = nxt;
	}
	for (int k = 1; k < 18; ++k) {
		for (int i = 0; i<n; ++i)
			if (d[k - 1][i] != -1)
				d[k][i] = d[k - 1][d[k - 1][i]];
	}
	scanf("%d", &q);
	int a, b;
	while (q--) {
		scanf("%d%d", &a, &b);
		--a; --b;
		if (a > b)
			swap(a, b);
		int cur = 1e9;
		int w = dp[a] - dp[b];
		for (int z = max(w - 2, 1); z <= w + 1; ++z) {
			int loc = a;
			for (int j = 17; j >= 0; --j)
				if ((z >> j) & 1) {
					loc = d[j][loc];
					if (loc == -1)
						break;
				}
			if (loc >= b)
				cur = min(cur, dp[a] - dp[loc]);
		}
		printf("%d\n", cur);
	}
	return 0;
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int n;
    cin>>n;
    vector<int>arr(n);
    double sum = 0;
    for(int  i = 0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }

    sum/=n;
    int pos = round(sum);

    int ans = 0;

    for(int  i = 0;i<n;i++)
    {
        ans+=((pos-arr[i])*(pos-arr[i])); 
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = in.readLine().split(" ");
      int n = Integer.parseInt(lines[0]);
      int target = Integer.parseInt(lines[1]);

      int[] p = new int[n];
      int[] c = new int[n];
      
      for(int i=0; i<n; i++) {
        lines = in.readLine().split(" ");
        p[i] = Integer.parseInt(lines[0]);
        c[i] = Integer.parseInt(lines[1]);
      }

      int ans = Integer.MAX_VALUE;
      for(int bits=0; bits < (1<<n); bits++){
        int score = 0, cnt = 0, restMax = -1;

        for(int i=0; i<n; i++) {
          if((bits>>i & 1) == 1) {
            score += 100 * (i+1) * p[i] + c[i];
            cnt += p[i];
          }
          else {
            restMax = i;
          }
        }
        // System.out.println(
        //   Integer.toBinaryString(bits) + ":" + score + "," + cnt);

        if(score < target) {
          int point = 100 * (restMax+1);
          int add = (target - score + (point-1)) / point;

          if(add >= p[restMax])
            continue;

          cnt += add;
        }

        ans = Math.min(ans, cnt);
      }

      System.out.println(ans);
    }
    catch(IOException e) {
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 24788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    int count = 0;
    for (int i = 1; i <= n; i++)
    {
        if (v[i - 1] != i)
        {
            count++;
        }

        if (count > 2)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, k, s[100000], t[100000], c[100000];
int d[30][200001];

int main() {
	cin >> n >> k;
	inc(i, n) { cin >> s[i] >> t[i] >> c[i]; c[i]--; }
	
	inc(i, n) { s[i] *= 2; t[i] *= 2; s[i]--; }
	inc(i, n) {
		d[c[i]][s[i]]++;
		d[c[i]][t[i]]--;
	}
	
	int ans = 0;
	inc1(i, 200000) {
		int m = 0;
		inc(j, k) { d[j][i] += d[j][i - 1]; m += min(1, d[j][i]); }
		setmax(ans, m);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 24832
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
int max_bit;
int dfs(int now,int visited_bit,vector<vi>& edge){
    visited_bit += 1<<now;
    if (visited_bit==max_bit) return 1;
    int res=0;  
    for(auto to:edge[now]){
        if(!(visited_bit&(1<<to))) res += dfs(to,visited_bit,edge);
    }
    return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    max_bit = (1<<N)-1;
    vector<vi> edge(N);
    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    int ans = dfs(0,0,edge);



    cout << ans << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
n = I()
ans = int(math.log10(n)+1)
for i in range(2,int(n**0.5)+1):
    if n%i == 0:
        ans = min(ans, max(int(math.log10(i)+1),int(math.log10(n//i)+1)))
print(ans)
"""

#D
n,a,b = LI()
v = LI()
v.sort()
v = v[::-1]
ans = v[:a]
d = {}
d[ans[-1]] = 0
if ans[0] != ans[-1]:
    for i in ans:
        if i == ans[-1]:
            d[i] += 1
    k = d[i]
    d[i] = 0
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 1
    for j in range(min(k,d[ans[-1]]-k)):
        c *= d[ans[-1]]-j
        c //= j+1
else:
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 0
    for k in range(a,min(d[ans[-1]],b)+1):
        p = 1
        for j in range(min(k,d[ans[-1]]-k)):
            p *= d[ans[-1]]-j
            p //= j+1
        c += p
print(sum(ans)/a)
print(c)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 4592
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
dd = Counter(d)
tt = Counter(t)
# print(dd, tt)
ok = True
for i, j in tt.items():
    if i in dd:
        # print('Y')
        if dd[i] < j:
            ok = False
    else:
        ok = False
    # print(i, j, ok)

if ok:
    print('YES')
else:
    print('NO')

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  vi year(1001),mon(11),three(11);
  rep(i,5){
    mon[2*i+1] = 20ll;
    mon[2*i+2] = 19ll;
    three[2*i+2] = three[2*i+1] = 20ll;
  }
  rep(i,9){
    mon[i+2] += mon[i+1];
    three[i+2] += three[i+1];
  }
  rep(i,1000){
    if(i % 3 == 2){
      year[i+1] += year[i] + three[10];
    }else
      year[i+1] += year[i] + mon[10];
  }
  int n; cin >> n;
  rep(i,n){
    int y,m,d; cin >> y >> m >> d; y--; m--;
    int x;
    if(y % 3 == 2) x = three[m];
    else x = mon[m];
    cout << year[1000] - (year[y] + x + d) - 194 << endl;
  }
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int Q;

	cin >> Q;
	rep(i,Q){
		ll A, B;
		cin >> A >> B;
		ll pro = A*B;
		if( A > B ) swap(A, B);
		// if( A == B ){
		// 	cout << (A-1)*2ll << endl;
		// 	continue;
		// }
		ll l=A, r=B;
		while(r-l > 1){
			ll m = (l + r) / 2ll;
			if( (pro-1ll) / m >= m ){
				l = m;
			}else{
				r = m;
			}
		}
		ll ans = (A-1)*2ll + (l-A)*2ll;
		if(l > A) ans -= ((pro-1ll) / l == l);
		ans += (B-l-1 > l-A - (l > A && (pro-1ll) / l == l) );
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200005];
bool cmp(const ll a,const ll b)
{
    return a>b;
}
int main()
{
    ll n;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+1+n,cmp);
    ll ans=a[1];
    int sum=1;
    if(n==2)
    {
        printf("%lld\n",ans);
        return 0;
    }
    for(int i=2;i<=n;i++)
    {
        ans+=a[i];
        sum++;
        if(sum==n-1)break;

        ans+=a[i];
        sum++;
        if(sum==n-1)break;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 5372
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int wx[100],wy[100],r[100];

main(){
  int n;
  while(cin>>n,n){
    rep(i,n)cin>>wx[i]>>wy[i]>>r[i];

    int m;
    cin>>m;
    while(m--){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      bool safe=false;
      rep(i,n){
	if(a==c && b==d)break;
	int e=wx[i],f=wy[i],g=r[i];
	bool myin=(e-a)*(e-a)+(b-f)*(b-f)<g*g;
	bool enin=(e-c)*(e-c)+(f-d)*(f-d)<g*g;
	if(myin!=enin){
	  safe=true;
	  break;
	}
	if(myin && enin)continue;

	int varxy=(a*a-2*a*c+b*b-2*b*d+c*c+d*d);
	double xx=(a*a*e-a*b*d+a*b*f-2*a*c*e+a*d*d-a*d*f+b*b*c-b*c*d-b*c*f+c*c*e+c*d*f);
	xx=xx/varxy;
	double yy=(a*a*d-a*b*c+a*b*e-a*c*d-a*d*e+b*b*f+b*c*c-b*c*e-2*b*d*f+c*d*e+d*d*f);
	yy=yy/varxy;
	if((e-xx)*(e-xx)+(f-yy)*(f-yy)>g*g)continue;

	if((a<=xx && xx<=c) || (c<=xx && xx<=a)){
	  safe=true;
	  break;
	}
      }
      if(safe)cout<<"Safe"<<endl;
      else cout<<"Danger"<<endl;
    }
  }
}

Measured memory_bytes: 0
#include <cstdio>

using namespace std;

char a[10][10];
bool v[10][10];

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m;scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%s",a[i]+1);
	int x=1,y=1;
	while (x<n||y<m)
	{
		v[x][y]=1;
		if (x<n&&a[x+1][y]=='#'&&y<m&&a[x][y+1]=='#') {puts("Impossible");return 0;}
		if ((x==n||a[x+1][y]=='.')&&(y==m||a[x][y+1]=='.')) {puts("Impossible");return 0;}
		if (x<n&&a[x+1][y]=='#') x++; else y++;
	}
	v[n][m]=1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (a[i][j]=='#'&&!v[i][j]) {puts("Impossible");return 0;}
	puts("Possible");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std ; 
const int N= 3e5;
int Mod = 1e9+7 ; 
long long cum [N];
int main(){
        int n ; 
        cin>>n;
        long long arr[n];
        for(int i =0;i<n;i++){
                cin>>arr[i]; 
             
         }
       for(int i =n-1;i>=0;i--){
               cum[i]+=(cum[i+1]+arr[i])%Mod; 
       }

       long long sum =0; 
       for(int i =0;i<n;i++)sum+=arr[i]*cum[i+1]%Mod; 
       cout<<sum%Mod ; }

Measured memory_bytes: 6756
#include <stdio.h>
#define MAX 250
#define NIL -2000000001

int key[MAX];

int parent(int p){
  return (p-1)/2;
}

int right(int p){
  return 2*p+2;
}

int left(int p){
  return 2*p+1;
}

int main(){
  int i,n,v;

  scanf("%d",&n);

  for ( i = 0; i < MAX; i++ ){
    key[i] = NIL;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d", &v);
    key[i] = v;
  }

  for(i = 0; i < n; i++ ){
    printf("node %d: key = %d, ",i+1,key[i]);
    if(key[parent(i)] != NIL && i != 0)printf("parent key = %d, ",key[parent(i)]);
    if(MAX > left(i) &&  key[left(i)] != NIL)printf("left key = %d, ",key[left(i)]);
    if(MAX > right(i) && key[right(i)] != NIL)printf("right key = %d, ",key[right(i)]);
    printf("\n");
  }  
  
  return 0;
}

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

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

  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  for (int i = 0; i < N - 1; i++) {
    for (int j = i+1; j < N; j++) {
      if (vec[i] == vec[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
    if (vec[i][vec[i].size() - 1] != vec[i + 1][0]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


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

int main() {
	int a, b;
	int i = 1;
	string op;
	while (i == 1) {
		cin >> a >> op >> b;
		if (op != "?") {
			if (op == "+") {
				cout << a + b << endl;
			}
			else if (op == "-") {
				cout << a - b << endl;
			}
			else if (op == "*") {
				cout << a * b << endl;
			}
			else if (op == "/") {
				cout << a / b << endl;
			}
		}
		else if (op == "?") {
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

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

int main() {
    int A, B;
    std::cin >> A >> B;

    if (A <= 9 && B <= 9) {
        std::cout << A * B << std::endl;
    } else {
        std::cout << -1 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll ans = 1145148931919810;
    for(ll i = 0; i <= 2 * max(X, Y); i += 2){
        ll tmp = C * i;
        if(i / 2 < X) tmp += A * (X - i / 2);
        if(i / 2 < Y) tmp += B * (Y - i / 2);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n = input_n
a = input_a

minus_cnt = 0
in_zero = 0
a.each do |num|
  if num < 0
    minus_cnt += 1
  end
  if num == 0
    in_zero = 1
  end
end

if minus_cnt.even? || in_zero == 1
  sum = 0
  a.each do |num|
    sum += num.abs
  end
  p sum
else
  sum = 0
  min = 10 ** 10
  a.each do |num|
    sum += num.abs
    if num.abs < min
      min = num.abs
    end
  end
  p sum - min * 2
end

Measured memory_bytes: 8588
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    ll a,b; cin>>a>>b;
    if(a>b)
        swap(a,b);
    ll ans = 1;
    for(ll i = 2; i*i <= a; i++){
        if(a%i==0){
            if(b%i==0) ans++;
            while(a%i==0){
                a/=i;
            }
        }
    }
    if(a>=2 && b%a==0)
        ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <string>
#include <utility>
#include <iterator>
#include <fstream>
#include <sstream>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <climits>
#include <ctime>
#include <cassert>
#include <ext/pb_ds/assoc_container.hpp>    // PBDS
#include <ext/pb_ds/tree_policy.hpp>        // PBDS

using namespace std;
using namespace __gnu_pbds;                 // PBDS

/* typedef starts */

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> PBDS_INT;               // PBDS for int
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> PBDS_LL;    // PBDS for long long

/* typedef ends */

/* macro starts */

#define PI acos(-1)
#define EPS 1e-9
#define fastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define sinD(degree) sin((degree * PI) / 180.0)
#define cosD(degree) cos((degree * PI) / 180.0)
#define tanD(degree) tan((degree * PI) / 180.0)
#define cotD(degree) (1.0 / tanD(degree))
#define secD(degree) (1.0 / cosD(degree))
#define cosecD(degree) (1.0 / sinD(degree))
#define asinD(value) (asin(value) * 180.0) / PI
#define acosD(value) (acos(value) * 180.0) / PI
#define atanD(value) (atan(value) * 180.0) / PI
#define forn(i,n) for(int i=0;i<n;i++)
#define min(a,b) a<b ? a:b
#define max(a,b) a>b ? a:b
#define value_at_index(x) find_by_order(x)
#define index_of(x) order_of_key(x)
#define pb push_back
#define set0(add) memset(add,0,sizeof(add))

/* macro ends */

/* function starts */

/// calculates n-th (0-based) Gray Code
template<typename dataType>
dataType nthGrayCode(dataType n)
{
    return (n ^ (n >> 1));
}

/// generates all possible subsets for the given set
template<typename dataType>
void generateAllSubset(vector<dataType> &data)
{
    int i, j, n;
    n = data.size();

    for (i = 0; i < (1 << n); i++) {
        for (j = 0; j < n; j++) {
            if (i & (1 << j)) {
                cout << data[j] << " ";
            }
        }
        cout << "\n";
    }
}

void swap(int a, int b){
	int temp;
	temp=a;
	a=b;
	b=temp;
}

int fact(int n){
	if(n==1)
		return 1;
	else 
	return n*fact(n-1);
}

bool compare(const pair<int,int> &a,const pair<int,int> &b){
	return (a.second<b.second);
}



int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    fastIO;
    int a;
    cin >> a;
    cout << a + a*a + a*a*a;
    
    


    return 0;
   	}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n,m;cin>>n>>m;
    cout<<n*m;
    
    
}


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

using namespace std;

int main(){

    string newString;
    cin >> newString;

    long long ans = 0;
    for(int i = 0; i<newString.length(); i++){
        ans += (int)newString[i] - 48;
    }
    (ans %9 == 0) ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;


}

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

int main() {
  long N,K; cin>>N>>K;
  vector<long> A(N),F(N);
  for(int i=0;i<N;i++) cin>>A.at(i);
  for(int i=0;i<N;i++) cin>>F.at(i);
  sort(A.begin(),A.end());
  sort(F.begin(),F.end());
  reverse(F.begin(),F.end());
  long left=0;
  long right=1000000000000;
  long X;
  long count;
  while(left<right){
    count=0;
    X=(left+right)/2;
    for(int i=0;i<N;i++){
      //long Y=A.at(i)*F.at(i);
      //if(Y>X) count+=Y-X;
      long Y=floor(X/F.at(i));
      if(A.at(i)>Y) count+= A.at(i)-Y;
    }
    if(count<=K) right=X;
    else left=X+1;
  }
  cout<<left<<endl;
}

Measured memory_bytes: 6424
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
// 4/N = 1/h + 1/n + 1/w;
// 1/h = -1/n - 1/w + 4/N;
// 1/h = (4nw - wN - Nn)/Nnw;
// h = Nnw/(4nw - wN - Nn);
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    REP(n, 1, 3500) {
        REP(w, 1, 3500) {
            if ((4*n*w - w*N - N*n) == 0) continue;
            int h;
            if (N * n * w % (4*n*w - w*N - N*n)== 0){
                h = N * n * w / (4*n*w - w*N - N*n);
                if (h <= 0) continue;
                cout <<h << " " << w << " " << n << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;
using ll = long long ;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
string str;
int k;
void solve(string cur, int & k){
  if(str.find(cur) != string::npos)k--;
  else return;
  if(!k){
    cout << cur << '\n';
    exit(0);
  }
  for(char c = 'a'; c <= 'z'; c++){
    solve(cur + c,k);
  }
}
int main(){

  cin >> str >> k;++k;
  solve("",k);



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int a[200002],b,c,n;
int main(){
	n=read(),b=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	for(re int i=b+1;i<=n;++i)puts(a[i]>a[i-b]?"Yes":"No");
}

Measured memory_bytes: 4284