akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		for(;;){

			String str = scan.next();
			StringBuilder card = new StringBuilder(str);

			if(str.equals("-"))
				break;

			int m = scan.nextInt();
			int[] shuffle = new int[m];

			for(int i = 0; i < m; i++){
				shuffle[i] = scan.nextInt();
				card.append(card.substring(0,shuffle[i]));
				card.delete(0, shuffle[i]);
			}
			System.out.println(card);

		}

	}

}

Measured memory_bytes: 18320
L, R = list(map(int, input().split()))

x = []
for i in range(2019):
    for j in range(L//2019, R//2019+1):
        tmp = 2019*j + i
        if tmp >= L and tmp <= R:
            x.append(i)
            break

from itertools import combinations

pairs = list(combinations(x, 2))
print(min([(p[0]*p[1])%2019 for p in pairs]))


Measured memory_bytes: 193804
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

int main() {
	IN(int, n);
	vector<int> a(n);
	cin >> a;
	
	int s = 0;
	RF(e, a) { s ^= e; }
	vector<int> ans;
	RF(e, a) { ans.PB(s ^ e); }
	OUT(ans);
}


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

#define rand() ((rand()<<15)+rand())

using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template<typename Key, typename Value>
using hash_map = cc_hash_table<Key, Value>;
template<typename T, typename Cmp = less<T>>
using oset = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;
*/
typedef long long lint;
typedef complex<double> point;

const int INF = 0x3f3f3f3f;
const lint INFL = 0x3f3f3f3f3f3f3f3fLL;
const double E = 1e-9, pi = 2 * acos(0);

template<typename T, typename U> void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> void amax(T &x, U y) { if (x < y) x = y; }

bool solve(int testNumber) {
	int n, a, b;
	if (!(cin >> n >> a >> b)) {
		return false;
	}
	if (n > (lint)a * b or n < a + b - 1) {
		printf("-1\n");
	} else {
		for (int i = b; i; i--) {
			printf("%d ", i);
		}
		int last = b;
		for (int rem = a - 1; rem; rem--) {
			int x = (n - last) / rem;
			for (int i = last + x; i > last; i--) {
				printf("%d ", i);
			}
			last += x;
		}
		printf("\n");
	}
	return true;
}

void init(const char *in = nullptr, const char *out = nullptr) {
	if (in) freopen(in, "r", stdin);
	if (out) freopen(out, "w", stdout);
	srand(unsigned((long long)new char));
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(nullptr);
	init();
	for (int i=1; solve(i); i++);
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define SORT(v) sort(v.begin(),v.end())
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
using namespace std;
typedef long long ll;

int main(){
  int n,count = 0;
  IN1(n);
  vector<int>parray(n);
  FOR(i,n){
    cin >> parray.at(i);
  }
  FOR(i,n){
    if(parray[i] != i+1){
      count++;
    }
  }

  if(count >= 3){
    OUT("NO");
  }
  else
  {
    OUT("YES");  
  }
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_f

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1e9 + 7)
#define LINF (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

#define SIZE 3001
int16_t dp[SIZE][SIZE];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t, ans = "";
    cin >> s >> t;
    for (size_t i = 0; i <= s.length() - 1; i++) {
        for (size_t j = 0; j <= t.length() - 1; j++) {
            if (s[i] != t[j]) {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            } else {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }
        }
    }
    int i = s.length() - 1, j = t.length() - 1;
    while (i >= 0 && j >= 0) {
        if (s[i] == t[j]) {
            ans += s[i];
            i--;
            j--;
        } else {
            if (dp[i][j + 1] > dp[i + 1][j]) {
                i--;
            } else {
                j--;
            }
        }
    }
    reverse(ALL(ans));
    cout << ans << endl;

    return 0;
}


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

int calc(int n)
{
    auto count = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(n % i == 0)
        {
            count++;
        }
    }
    return count;
}

int main(int argc, const char* argv[])
{
    int n;
    cin >> n;
    auto count = 0;
    for(int i = 1; i <= n; i += 2)
    {
        if(calc(i) == 8)
        {
            count++;
        }
    }
    
    cout << count << endl;
    return 0;
}


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

using namespace std;

#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define sp << ' ' <<
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353
#define PI_2 1.57079632679489661923

int main()
{
    boost;
    time_t tic, toc;

    ll tt = 1, n, m, k = 0, i, j, p, q;
    ll a, b, c, d, h, w, u, v, x, y;
    ll l = 0, r = 0;
    ll ans = 0;

    bool poss = true;

    string s;

    // cin >> tt;
    tic = clock();
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> n;
        vi cnt(100005, 0);

        ans = 0;
        for(i = 0; i < n; i++){
            cin >> a;
            cnt[a]++;
            ans += a;
        }

        cin >> q;

        while(q--){
            cin >> b >> c;
            cnt[c] += cnt[b];
            ans = ans + cnt[b]*(c - b);
            cnt[b] = 0;

            cout << ans << nl;
        }
    } 
    // cerr << (clock() - tic*1.0) / CLOCKS_PER_SEC << nl;
    return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <vector>
using namespace std;

long K, N, a, Max, M, sum;
vector<long> A, dists;

int main(){
	cin >> K >> N;
  	for (int i = 0; i < N; i++){
      	cin >> a;
    	A.push_back(a);
    }
  	Max = A[A.size()-1];
  	for (int i = 0; i < N-1; i ++){
    	dists.push_back(A[i+1]-A[i]);
    }
  	dists.push_back(K-Max+A[0]);
  	
  	M = dists[0];
  	sum = dists[0];
  	for (int i = 1; i < N; i ++){
      	sum += dists[i];
    	if (dists[i] > M){
        	M = dists[i];
        }
    }
  	cout << sum - M << endl;
}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    vector <vector <pair<int,int>  > > g;
    vector <pair<int,int> > r1;
    g.resize(n+1,r1);
    for(int i=0;i<n-1;i++)
    {
        int u=nxt(),v=nxt(),c=nxt();
        g[u].push_back({v,c});
        g[v].push_back({u,c});
    }
    vector<bool> visited;
    visited.resize(n+1,0);
    vector <ll> dist(n+1);
    int Q=nxt(),k=nxt();
    dist[k]=0;
    visited[k]=1;
    queue <int> q;
    q.push(k);
    while(q.size())
    {
        int x=q.front();
        q.pop();
        for(auto i:g[x])
        {
            if(!visited[i.first])
            {
                visited[i.first]=1;
                q.push(i.first);
                dist[i.first]=dist[x]+i.second;
            }
        }
    }
    while(Q--)
    {
        int x=nxt(),y=nxt();
        cout<<dist[x]+dist[y]<<"\n";
    }
    
    
    return 0;   
}




 
 


Measured memory_bytes: 8820
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int h, w;
string tmp[300];
char s[666][666];
int N;
int imosR[1444][1444];
int imosC[1444][1444];

signed main() {
	int i, j;
	
	cin >> h >> w;
	rep(i, h) cin >> tmp[i];
	
	rep(i, h) {
		rep(j, w) {
			int i2 = i + j;
			int j2 = i - j + w - 1;
			s[i2][j2] = tmp[i][j];
		}
	}
	N = h + w - 1;
	
	//デバッグ
	/*cout << endl;
	rep(i, N) {
		rep(j, N) {
			if (s[i][j] == '#') cout << s[i][j];
			else cout << ".";
		}
		cout << endl;
	}*/
	
	//#の数を累積和する
	rep(i, N) {
		rep(j, N) {
			if (s[i][j] == '#') imosR[i][j + 1]++;
		}
		rep(j, 2 * N + 100) { imosR[i][j + 1] += imosR[i][j]; }
	}
	
	rep(j, N) {
		rep(i, N) {
			if (s[i][j] == '#') imosC[i + 1][j]++;
		}
		rep(i, 2 * N + 100) { imosC[i + 1][j] += imosC[i][j]; }
	}
	
	//2点間の距離dを全探索
	int ans = 0;
	for (int d = 1; d < N; d++) {
		rep(i, N) {
			rep(j, N) {
				if (s[i][j] != '#') continue;
				if (j + d >= N || s[i][j + d] != '#') continue;
				//cout << i << ", " << j << endl;
				//cout << i << ", " << j + d << endl;
				//cout << endl;
				
				ans += imosR[i + d][j + d + 1] - imosR[i + d][j];
				if (i >= d) ans += imosR[i - d][j + d + 1] - imosR[i - d][j];
			}
		}
	}
	
	//全探索その2
	for (int d = 1; d < N; d++) {
		rep(i, N) {
			rep(j, N) {
				if (s[i][j] != '#') continue;
				if (i + d >= N || s[i + d][j] != '#') continue;
				ans += imosC[i + d + 1][j + d] - imosC[i][j + d];
				if (j >= d) ans += imosC[i + d + 1][j - d] - imosC[i][j - d];
			}
		}
	}
	
	//積集合を取り除く1
	for (int d = 1; d < N; d++) {
		rep(i, N) {
			rep(j, N) {
				if (s[i][j] != '#') continue;
				if (j + d >= N || s[i][j + d] != '#') continue;
				//cout << i << ", " << j << endl;a
				//cout << i << ", " << j + d << endl;
				//cout << endl;
				
				ans -= imosR[i + d][j + d + 1] - imosR[i + d][j + d];
				ans -= imosR[i + d][j + 1] - imosR[i + d][j];
				if (i >= d) ans -= imosR[i - d][j + d + 1] - imosR[i - d][j + d];
				if (i >= d) ans -= imosR[i - d][j + 1] - imosR[i - d][j];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 26752
import java.util.Scanner;

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

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int alice = 0;
        int bob = 0;
        for (int j = 0; j < n; j++) {
            int max = 0;
            for (int k = 0; k < n; k++) {
                max = Math.max(max, a[k]);
            }
            for (int l = 0; l < n; l++) {
                if (max == a[l]) {
                    a[l] = 0;
                    break;
                }
            }

            if (j % 2 == 0) {
                alice += max;
            } else {
                bob += max;
            }
        }

        System.out.println(alice - bob);
    }
}

Measured memory_bytes: 22996
x = list(map(int, list(input())))
y = [0] * 4
for i in range(8):
    y[0] = x[0]
    s = y[0]
    p = list(map(int, list(format(i, '03b'))))
    for j in range(3):
        y[j + 1] = (2 * p[j] - 1) * x[j + 1]
        s += y[j + 1]
    if s == 7:
        print('{}{:+d}{:+d}{:+d}=7'.format(y[0], y[1], y[2], y[3]))
        exit()

Measured memory_bytes: 3064
#include <string>
#include <iostream>
#include <utility>
#include <algorithm>

using namespace std;

#define inf 100100100
#define INF 100100100

int main(){
    int n, m;

    cin >> n >> m;

    cout << (n - 1) * (m - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define int long long
using namespace std;

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	
	int ans = a * (n / (a + b));
	n %= (a + b);
	if (n > a) ans += a;
	else ans += n;
	cout << ans << endl;
	return 0;
}

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

///--->>> CONTAINERS <<<---///
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vector< ll > >;
using vpi = vector<pair<ll,ll> >;
using pi = pair<ll,ll>;
using st = set<ll>;
using stk = stack<ll>;
using kiwi = queue<ll>;
using pkiwi = priority_queue<ll>;
using mp = map<ll,ll>;
using ump = unordered_map<ll,ll>;

///--->>> MACROS<<<---///
const ll mx = 1e5+123;
#define MOD 1000000007
#define REP(i,n) for (ll i=1;i<=n;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

///--->>>OPTIMIZE<<<---///
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

///--->>> DEBUGGER<<<---///
#define dbg(args...) do {cerr<<#args<<" : "; diraf(args); } while(0)
void diraf ()  {        cerr << endl;}
template < typename T, typename ... hello>void diraf( T arg, const hello &... rest) {cerr<<arg<< ' ';diraf(rest...);}

int main(){
    fastio;
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    float n, x, t; cin>>n>>x>>t;
    float f = n/x;
    ll ans=ceil(f)*t;
    cout<<ans<<endl;
return 0;
}


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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);



ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll pow(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;
}



int main()
{fast


ll n;cin>>n;

vl a(n);

for(int i=0;i<n;i++)cin>>a[i];

  sort(all(a));

ll ans =a[n/2]-a[n/2-1];

cout<<ans<<"\n";

 return 0;

}


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

using namespace std;

vector<int> adjList[100005];

int  num[100005], par[100005], low[100005], cnt = 1, root, child;
bool vis[100005], art[100005];

void findArt(int u){
	vis[u] = true;
	low[u] = num[u] = cnt++;
	for (int i=0; i<adjList[u].size(); i++){
		int v = adjList[u][i];

		if (!vis[v]){
			par[v] = u;
			
			if (u == root) child++;

			findArt(v);

			if (low[v] >= num[u]) art[u] = true;

			low[u] = min(low[u],low[v]);
		}
		else if (par[u] != v) low[u] = min(low[u],num[v]);
	}
}

int main(){

	ios_base::sync_with_stdio(0);

	int N, E;
	cin >> N >> E;

	int u, v;
	for (int i=0; i<E; i++){
		cin >> u >> v;

		adjList[u].push_back(v);
		adjList[v].push_back(u);
	}

	memset(num,0,sizeof(num));
	memset(par,0,sizeof(par));
	memset(low,0,sizeof(low));
	memset(vis,0,sizeof(vis));
	memset(art,0,sizeof(art));

	for (int i=0; i<N; i++){
		if (vis[i]) continue;

		root = i; child = 0;
		findArt(i);

		art[root] = (child > 1);
	}

	for (int i=0; i<N; i++){
		if (art[i]) cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 6260
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<utility>
#include <cmath>
#include <math.h> 
#include <string.h>


#define For(i,begin,end) for(int i=(begin);i<(end);i++)
#define FORD(i,begin,end) for(int i=(begin);i>(end);i--)
#define FOR(l) for(auto p = l.begin(); p != l.end(); p++)
#define ALL(k) (k).begin(),(k).end()
#define e1 first
#define e2 second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef unsigned long long LLU;
typedef long double LD;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> Vl;


ll dp[100005];
ll arr[100005];

ll fun(ll i,ll n)
{
	if(dp[i] != -1)
		return dp[i];

	if(i == n - 1)
		return dp[i] = 0;

	if(i == n - 2)
		return dp[i] = abs(arr[i] - arr[i + 1]);

	return dp[i] = min(abs(arr[i] - arr[i + 1]) + fun(i + 1 , n), abs(arr[i] - arr[i + 2]) + fun(i + 2 , n));
}
int main()
{	
	memset(dp, -1, sizeof dp);
	ll n;
	cin>>n;

	For(i,0,n)
		cin>>arr[i];

	cout<<fun(0,n)<<endl;

	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;

ll fac[maxn];
ll inv[maxn];

ll power(ll base,ll n)
{
    ll r=1;
    while(n)
    {
        if(n%2) r=r*base%mod;
        base=base*base%mod;
        n/=2;
    }
    return r;
}
void init()
{
    fac[0]=1;
    for(int i=1;i<maxn;i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
    inv[maxn-1]=power(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
    {
        inv[i]=inv[i+1]*(i+1)%mod;
    }
}

ll C(ll m,ll n)
{
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    init();
    ll ans=0;
    for(int i=1;i<=h-a;i++)
    {
        ll temp1=C(i-1,i+b+1-2);
        ll temp2=C(w-(b+2),h+w-(i+b+2));
        if(i==h-a)
            temp2=C(w-(b+1),h+w-(i+b+1));
        temp1%=mod;
        temp2%=mod;
        ll sum=temp1*temp2%mod;
        ans+=sum;
        ans%=mod;
    }
    cout<<ans<<'\n';


}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "\n[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "\n[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]\n";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

ll gcd(ll a,ll b)
{
  if(a==0)
  return b;
  return gcd(b%a,a);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    cout << a * b / gcd(a,b) << endl;
    return 0;
}



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

int main() {
  string o, e;
  cin >> o;
  cin >> e;
  string ans = "";
  for (int i = 0; i < e.size(); i++) {
    ans += o[i];
    ans += e[i];
  }
  if (o.size() - e.size() == 1) {
    ans += o[o.size() - 1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i;
  int k=0,u=0,p=0,c=0;
  string s;
  cin>>s;
  rep(i,s.size())
    if(s[i]=='K')k++;
    else if(s[i]=='U')u++;
    else if(s[i]=='P')p++;
    else if(s[i]=='C')c++;
  cout<<min(min(k,u),min(p,c))<<endl;
}

Measured memory_bytes: 3188
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;
int main() {
	int N;
	scanf("%d", &N);
	int ma = INT_MIN;
	int mi = INT_MAX;
	for (int i = 0; i < N; i++) {
		int t;
		scanf("%d", &t);
		mi = min(mi, t);
		ma = max(ma, t);
	}
	printf("%d", ma-mi);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int fff[45];

int fibo(int);

int main(){
  int i,n;
  
  for(i = 0;i < 45;i++)  fff[i] = -1;
  scanf("%d",&n);
  printf("%d\n",fibo(n));
  
  return 0;
}

int fibo(int i){
  if(i == 0 || i == 1) return fff[i] = 1;
  if(fff[i] != -1) return fff[i];
  return fff[i] = fibo(i - 1) + fibo(i - 2);
}



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

using namespace std;

const int MAX_N = 2000, MAX_M = 2000, INDEX = 1;

int n, m, q;

bool isBlue[MAX_N + INDEX][MAX_M + INDEX];

int psCells[MAX_N + INDEX][MAX_M + INDEX], psRowBounders[MAX_N + INDEX][MAX_M + INDEX], psColBounders[MAX_N + INDEX][MAX_M + INDEX];

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

    cin >> n >> m >> q;

    for (int i = 1; i <= n; i++) {
        string s;

        cin >> s;

        for (int j = 1; j <= m; j++) {
            switch (s[j - 1]) {
                case '1':
                    isBlue[i][j] = true;

                    break;

                case '0':
                    isBlue[i][j] = false;

                    break;
            }
        }
    }

    for (int i = 0; i <= n; i++) {
        psCells[i][0] = 0;
    }

    for (int j = 0; j <= m; j++) {
        psCells[0][j] = 0;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            psCells[i][j] = psCells[i - 1][j] + psCells[i][j - 1] - psCells[i - 1][j - 1];

            if (isBlue[i][j]) {
                psCells[i][j]++;
            }
        }
    }

    for (int i = 0; i <= n; i++) {
        psRowBounders[i][0] = 0;
    }

    for (int j = 0; j <= m; j++) {
        psRowBounders[0][j] = 0;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            psRowBounders[i][j] = psRowBounders[i - 1][j] + psRowBounders[i][j - 1] - psRowBounders[i - 1][j - 1];

            if (isBlue[i][j] && isBlue[i][j - 1]) {
                psRowBounders[i][j]++;
            }
        }
    }

    for (int i = 0; i <= n; i++) {
        psColBounders[i][0] = 0;
    }

    for (int j = 0; j <= m; j++) {
        psColBounders[0][j] = 0;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            psColBounders[i][j] = psColBounders[i - 1][j] + psColBounders[i][j - 1] - psColBounders[i - 1][j - 1];

            if (isBlue[i][j] && isBlue[i - 1][j]) {
                psColBounders[i][j]++;
            }
        }
    }

    for (; q > 0; q--) {
        int x1, y1, x2, y2;

        cin >> x1 >> y1 >> x2 >> y2;

        cout << psCells[x2][y2] - (psCells[x1 - 1][y2] + psCells[x2][y1 - 1] - psCells[x1 - 1][y1 - 1]) - (psRowBounders[x2][y2] - (psRowBounders[x1 - 1][y2] + psRowBounders[x2][y1] - psRowBounders[x1 - 1][y1]) + psColBounders[x2][y2] - (psColBounders[x1][y2] + psColBounders[x2][y1 - 1] - psColBounders[x1][y1 - 1])) << '\n';
    }

    return 0;
}


Measured memory_bytes: 52608
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  long int a[100];
  cin >> n;
  cin >> a[0];
  long int mi = a[0];
  long int ma = a[0];
  for(int i = 1;i < n;i++){
    cin >> a[i];
    mi = min(mi, a[i]);
    ma = max(ma, a[i]);
  }
  cout << ma - mi << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
typedef vector<vector<ll>> matrix;
typedef vector<ll> arr;
int main(){
    fast;
    ll countx=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-i-1]){
            countx++;
        }
    }
    cout<<countx<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string A,B;
  cin >> A >> B;
  int a = A.size();
  int b = B.size();
  if(a>b)
  {
    cout << "GREATER" << endl;
    return 0;
  }
  else if(b>a)
  {
    cout << "LESS" << endl;
    return 0;
  }
  else
  {
    rep(i,a)
    {
      if(A[i]>B[i])
      {
        cout << "GREATER" << endl;
        return 0;
      }
      else if(A[i]<B[i])
      {
        cout << "LESS" << endl;
        return 0;
      }
    }
  }
  
  cout << "EQUAL" << endl;
  return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
    int a;
    cin>>a;
    cout<<!a<<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[300000];
int main(){
    int N;
    cin >> N;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    int right = 0;
    ll ans = 0;
    ull buf = 0;
    for(int left = 0; left < N; left++){
        ull a = A[left];
        if(right == left) {
            buf = a;
            right++;
        }
        //ull buf = a;
        while(1){
            if(right == N){
                ll n = (right - left);
                ans += n;
                break;
            }

            ll b = A[right];
            //printf("%d ^ %d = %d\n", buf, b, buf ^ b);
            if((buf ^ b) == (buf + b)){
                right++;
                buf |= b;
            }
            else{
                ll n = (right - left);
                ans += n;
                //printf("%d & ~%d = %d\n", buf, a, buf & (~a));
                buf = buf & (~a);
                //printf("%d\n", buf);
                break;
            }
        }
    }

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


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

// 釈然としない悔しさ定期
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  if(n == 3) return(cout << "2 5 63" << endl, 0);
  vector<int> ans;
  int k = n;
  int a[] = {1, 3, 2, 8, 7, 9};
  int b[] = {5, 11};
  for(int i = 1; i <= 3e4; i += 12) {
    for(int j = 0; j < 6; j += 2) {
      if(k < 2) break;
      ans.emplace_back(i + a[j]);
      ans.emplace_back(i + a[j + 1]);
      k -= 2;
    }
    for(int j = 0; j < 2; j++) {
      if(k < 1) break;
      ans.emplace_back(i + b[j]);
      k--;
    }
    if(k == 0) break;
  }
  cout << ans[0];
  for(int i = 1; i < n; i++) cout << " " << ans[i];
  cout << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

//typedef vector<int> vi;
//typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int inf = 1e6;

int dp[41][401][401];


int main(){
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	int i, j, k;
	vector<int> A, B, C;
	for (i = 0; i < N; i++){
		int a, b, c;
		cin >> a >> b >> c;
		A.push_back(a);
		B.push_back(b);
		C.push_back(c);
	}
	int sum_max = 400;
	for (j = 0; j <= sum_max; j++){
		for (k = 0; k <= sum_max; k++){
			if (j == 0 && k == 0){
				dp[0][j][k] = 0;
			}
			else{
				dp[0][j][k] = inf;
			}
		}
	}

	for (i = 1; i <= N; i++){
		for (j = 0; j <= sum_max; j++){
			for (k = 0; k <= sum_max; k++){
				if (j >= A[i - 1] && k >= B[i - 1]){
					dp[i][j][k] = min(dp[i - 1][j][k], dp[i - 1][j - A[i - 1]][k - B[i - 1]] + C[i - 1]);
				}
				else{
					dp[i][j][k] = dp[i - 1][j][k];
				}
			}
		}
	}
	int s_ma = Ma;
	int s_mb = Mb;
	int ans = inf;
	while (s_ma <= sum_max && s_mb <= sum_max){
		ans = min(ans, dp[N][s_ma][s_mb]);
		s_ma += Ma;
		s_mb += Mb;
	}
	if (ans == inf){
		ans = -1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 25984
import math
n, k = map(int, input().split())
x_tmp = input().split()
x = [int(_) for _ in x_tmp]
ans = []


def abs(x):
    '''絶対値をint型で返す
    return int-type abs-x
    '''
    return int(math.fabs(x))


for i in range(n-k+1):
    ans_left = abs(x[i]) + abs(x[i+k-1] - x[i])
    ans_right = abs(x[i+k-1]) + abs(x[i+k-1] - x[i])
    ans.extend([ans_left, ans_right])
print(min(ans))


Measured memory_bytes: 18972
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;

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

	int s = A + B;
	int t = A * B;
	int u = A - B;

	if (s >= t && s>=u)
	{
		cout << s;
	}
	else
	{
		if (t >= u)
		{
			cout << t;
		}
		else
		{
			cout << u;
		}
	}
	
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n;
  cin >> n;
  V<ll> a(3 * n);
  rep(i, 3 * n) {
    cin >> a[i];
  }

  sort(a.rbegin(), a.rend());

  ll ans = 0;
  for(int i = 1; i < 2 * n; i += 2) {
    ans += a[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 5564
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            abc088_b();
        }

        static void abc088_b()
        {
            // B - Card Game for Two
            int N = int.Parse(Console.ReadLine());
            int[] A_desc = Console.ReadLine().Trim().Split().Select(i => int.Parse(i)).OrderByDescending(x => x).ToArray();
            int alice = A_desc.Where((val, idx) => idx % 2 == 0).Sum();
            int bob = A_desc.Where((val, idx) => idx % 2 == 1).Sum();
            int ans = alice - bob;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;

int N, W;
ll dp[100][100001];//dp[i][j]: i + 1品目まで見て、入れた重さの合計がjだったときの価値の最大値
int w[100000];
ll v[100000];

int main() {
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= W; j++)dp[i][j] = -1;
	}
	

	dp[0][0] = 0;
	if (w[0] <= W)dp[0][w[0]] = v[0];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j - w[i] >= 0 && dp[i - 1][j - w[i]]!= -1) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
			}
		}
	}

	ll ans = 0;
	for (int i = 0; i <= W; i++)ans = max(ans, dp[N - 1][i]);
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 78336
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(; sc.hasNext();){
			int y=sc.nextInt();
			int m=sc.nextInt();
			int d=sc.nextInt();
			if((y>=1990)||(y==1989&&(m>=2||m==1&&d>=8)))
				println(String.format("heisei %d %d %d", y-1988, m, d));
			else if((y>=1927)||(y==1926&&m==12&&d>=25))
				println(String.format("showa %d %d %d", y-1925, m, d));
			else if((y>=1913)||(y==1912&&(m>=8||m==7&&d>=30)))
				println(String.format("taisho %d %d %d", y-1911, m, d));
			else if((y>=1869)||(y==1868&&(m>=10||m==9&&d>=8)))
				println(String.format("meiji %d %d %d", y-1867, m, d));
			else
				println("pre-meiji");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>
int main(){
  int i,n;
  int now=1;
  int total=0;
  char *slime,*merge;
  char nowslime;
  
  scanf("%d",&n);
  slime=(char*)malloc(sizeof(char)*(n+1));
  merge=(char*)malloc(sizeof(char)*(n+1));
  
  scanf("%s",slime);
  nowslime=slime[0];
  merge[0]=slime[0];
  
  for(i=1;i<n;i++){
    if(nowslime!=slime[i]){
      merge[now]=nowslime;
      nowslime=slime[i];
      now++;
    }
  }
  merge[now]='\0';
  now=0;
  while(merge[now]!='\0'){
    total++;
    now++;
  }
  printf("%d",total); 
  free(slime);
  free(merge);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string S;
  rep(i,3){
    cin >> S;
    cout << S[i];
  }
  cout << endl;
  return 0;
}


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

using namespace std;

int64_t gcm(int64_t x, int64_t y)
{
	int64_t a = max(x, y);
	int64_t b = min(x, y);
	int64_t c = a % b;
	if (c == 0)
	{
		return b;
	}
	else
	{
		return gcm(b, c);
	}
}

int64_t lcm(int64_t x, int64_t y)
{
	return (x / gcm(x, y) * y);
}

int main()
{
	int64_t a, b, c, d;
	cin >> a >> b >> c >> d;

	--a;
	int64_t x = 0, y = 0, cdlcm;
	cdlcm = lcm(c, d);
	x += b / c;
	x += b / d;
	x -= b / cdlcm;
	x = b - x;

	y += a / c;
	y += a / d;
	y -= a / cdlcm;
	y = a - y;

	cout << x - y << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

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

const int N = 5005;
const int MOD = 1000000007;

struct edge{int go,next;} e[N<<1]; int cnt=0,last[N]; inline void ins(int u,int v) {e[++cnt].go=v; e[cnt].next=last[u]; last[u]=cnt;}

int n,ans=0;
LL f[N];
LL size[N],dp[N][N];

inline void dfs(int x,int fa) {
	size[x]=1; dp[x][1]=1;
	for (int i=last[x];i;i=e[i].next) {
		if (e[i].go==fa) continue;
		dfs(e[i].go,x);
		per(p,size[x],1) {
			LL tmp=0;
			per(q,size[e[i].go],1) {
				dp[x][p+q]=(dp[x][p+q]+dp[x][p]*dp[e[i].go][q])%MOD;
				if (q%2==0) tmp=(tmp+MOD-dp[x][p]*dp[e[i].go][q]%MOD*f[q/2]%MOD)%MOD;
			}
			dp[x][p]=tmp;
		}
		size[x]+=size[e[i].go];
	}
}

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(); rep(i,1,n-1) {int u=read(),v=read(); ins(u,v); ins(v,u);}
	f[0]=1; rep(i,1,n/2) f[i]=(f[i-1]*(2*i-1))%MOD; dfs(1,0);
	for (int i=2;i<=n;i+=2) ans=(ans+f[i/2]*dp[1][i])%MOD;
	printf("%d\n",ans);

	return 0;
	
}


Measured memory_bytes: 194560
N,Q = map(int,input().split())
S = input()
ACnum = [0]
for i in range(1,N):
    if "AC" == S[i-1:i+1]:
        ACnum.append(ACnum[i-1] + 1)
    else:
        ACnum.append(ACnum[i-1])
lr = []
for i in range(Q):
    lr.append(list(map(int,input().split())))

for i in range(Q):
    print(ACnum[lr[i][1]-1] - ACnum[lr[i][0]-1])


Measured memory_bytes: 30788
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
int a,b;
string s[100];
cin>>a>>b;
for(int i=0;i<a;i++)cin>>s[i];
sort(s,s+a);
for(int i=0;i<a;i++)cout<<s[i];
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int func (int n) {
  int sum=0;
  while(n > 0) {
    sum += n%10;
    n /= 10;
  }
  return sum;
}
int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int ans=0;
  for (int i=1; i <= n; i++) {
    if ((func(i) >= a) && (func(i) <= b)) ans +=i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;
 
 
int main() {
    string s;
    cin >> s;
    bool res = false;
    rep(i,s.length()){
        if (s[i] == '7'){
            res = true;
        }
    }
    if (res){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3592
#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()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


using pil = pair<int, ll>;
using pli = pair<ll, int>;
const int maxn = 100005;
int n = maxn;
vector<vector<pil> > G(maxn); // 行き先と cost

vector<ll> dijkstra(int s) {
    vector<ll> d(n, INF);
    //頂点、最短距離、小さい順に
    priority_queue<pli, vector<pli>, greater<pli> > q;

    d[s] = 0;
    q.push(pli(0, s));

    while (!q.empty()) {
        pli p = q.top();
        q.pop();
        int v = p.S;
        if (d[v] < p.F) continue;
        for (pil np : G[v]) {
            int nv = np.F;
            ll cost = np.S;
            if (chmin(d[nv], d[v] + cost)) {
                q.push(pli(d[nv], nv));
            }
        }
    }

    return d;
}

// youtube editorial
void solve() {
  // k の倍数, mod k で 0
  cin >> n;
  // 正の整数は +1, *10 で作れて,
  // 桁和は +1 で +1, *10 で +0
  rep(i, n) {
    G[i].eb((i + 1) % n, 1);
    G[i].eb((i * 10) % n, 0);
  }
  auto d = dijkstra(1);
  // cout << d << endl;
  // 1 はじめだから +1
  // 0 はじめなら最短距離 0 になってしまう
  cout << d[0] + 1 << endl;
}


Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define M_PIl   3.141592653589793238462643383279502884L

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    
    if(n%2==0){
        cout<<n<<"\n";
    }else{
        cout<<2*n<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    ll sum = 0, x = 0, y = 0;
    ll tmp = 0;
    bool flag = false;
    rep(i, n){
        if(tmp == a[i]){
            if(sum == 0){
                sum = 2;
            }
            else{
                sum++;
            }
            if(sum == 2 && !flag){
                x = a[i];
                flag = true;
            }
            else if((sum == 2 || sum == 4) && flag){
                y = a[i];
                break;
            }
        }
        else{
            sum = 0;
        }
        tmp = a[i];
    }
    cout << x*y << endl;

    return 0;
}

Measured memory_bytes: 1024
# include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
# define forn(i, n) for (ll i = 0; i < int(n); i++)
# define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
# define all(V) V.begin(), V.end()
# define rall(V) V.rbegin(), V.rend()
# define len(V) (int)V.size()
# define ll long long
# define ld long double
# define ff first
# define ss second
# define pb push_back
# define mp make_pair
# define endl '\n'
# define M_PI 3.14159265358979323846

const int MAX_N = 100;
vector<int> xy(MAX_N);
 
void solve()
{
        ll a, b, c; cin >> a >> b >> c;
        if(a == b && a == c && (a % 2 == 0)) cout << -1;
        else
        {
                bool ok = false;
                ll r = 0;
                for(int i = 0; i < 64; ++i)
                {
                        if((a % 2 != 0) || (b % 2 != 0) || (c % 2 != 0))
                        {
                                cout << i << endl;
                                return;
                        }
                        ll ca = a / 2, cb = b / 2, cc = c / 2;
                        a = (cb + cc);
                        b = (ca + cc);
                        c = (ca + cb);
                }
                cout << -1;
        }
        
}
 
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        solve();
}

Measured memory_bytes: 256