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

public class Main {
    static long mod = 1000000007;

    public static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] lis = new long[n];
        int neg = 0;
        int zero = 0;
        for (int i = 0; i < n; ++i) {
            long l = sc.nextLong();
            if (l < 0) {
                neg++;
            } else if (l == 0) {
                zero++;
            }
            lis[i] = l;
        }

        long sum = 0;
        for (int i = 0; i < n; ++i) {
            sum += Math.abs(lis[i]);
        }
        if (zero > 0 || (neg % 2) == 0) {

        } else {
            long min = Math.abs(lis[0]);
            for (int i = 0; i < n; ++i) {
                min = Math.min(min, Math.abs(lis[i]));
            }
            sum -= Math.abs(min) * 2;
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 55340
S = input()
Slist = list(S)
ans = 0
l = 0
for i in range(0, len(Slist)):
	if (Slist[l] == "A" or Slist[l] =="G" or Slist[l] == "C" or Slist[l] == "T") and (Slist[i] == "A" or Slist[i] =="G" or Slist[i] == "C" or Slist[i] == "T"):
		ans = max(ans, len(Slist[l : i+1]))
	else:
		l=i
		
print(ans)

Measured memory_bytes: 3064
MOD = 10**9 + 7


def main():
    K = int(input())
    S = input()
    N = len(S)
    m = N+K + 5
    fac = [0] * m
    finv = [0] * m
    inv = [0] * m

    def COMBinitialize(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i-1] * i % MOD
                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
                finv[i] = finv[i - 1] * inv[i] % MOD

    def COMB(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMBinitialize(m)
    ans = 0
    for i in range(K+1):
        v = COMB(N-1+K-i, N-1)
        v %= MOD
        v *= pow(25, (K-i), MOD)
        v %= MOD
        v *= pow(26, i, MOD)
        v %= MOD
        ans += v
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std ;
#define pi 3.1415926535897932384626433832795
int main ()  { 
	
ios_base::sync_with_stdio(false) ; 
cin.tie(NULL) ; 
cout.tie(NULL) ;

int n ; 
cin >> n ; 

double keliling ; 
keliling = 2 * pi * n ; 

printf("%lf\n",keliling) ; 


}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
 
#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)
 
#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif
 
using i64 = long long;
using iip = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;
 
template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }
 
template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }
 
template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
 
// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }
 
static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
  int n;
  string s, t;
  cin >> n >> s >> t;

  string res;
  forn(i, n) {
    res += s[i];
    res += t[i];
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import numpy

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

a = numpy.array([int(e) for e in input().split(" ")],dtype=numpy.int64)
changes=[]
for i in range(m):
    changes.append([int(e) for e in input().split(" ")])


a.sort()
#昇順ソート

changes.sort(key=lambda x:(x[1],x[0]),reverse = True)

change_num = 0
for change in changes:
    for i in range(change_num, min(change[0] + change_num,n)):
        if a[i] < change[1]:
            change_num += 1
            a[i] = change[1]
        else:
            break

print(a.sum())

Measured memory_bytes: 40300
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
vector<string> a, b;
int n, m;
bool checker(int r, int c) {
    for(int i = 0; i < m; i++) {
        for(int j = 0; j < m; j++) {
            if(a[r + i][c + j] != b[i][j])
                return false;
        }
    }
    return true;
} 

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    a.resize(n);
    b.resize(m);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < m; i++)
        cin >> b[i];
    for(int i = 0; i <= n - m; i++) {
        for(int j = 0; j <= n - m; j++) {
            if(checker(i, j)) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}

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

using namespace std;

using ll = long long;


int main() {
  int n;
  cin >> n;
  int arr[101];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  int high = n - 1;
  int alex = 0, bob = 0;
  bool tog = true;
  while (high >= 0) {
    if (tog) {
      alex += arr[high];
    } else {
      bob += arr[high];
    }
    high--;
    tog = !tog;
  }
  cout << alex - bob << '\n';
  return 0;
}


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

int main() {

	int n, m, h[200000], a[200000],b[200000];
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}


	int ans = 0;
	int is_higher[200000];

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

	for (int i = 0; i < m; i++) {
		if (h[a[i]-1] <= h[b[i]-1]) {
			is_higher[a[i]-1] = 0;
		}
		if (h[a[i]-1] >= h[b[i]-1]) {
			is_higher[b[i]-1] = 0;
		}
	}

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

	cout << ans << endl;
	
	cin >> n;

	return 0;


}

Measured memory_bytes: 5124
#include<iostream>
#include<cstdio>
using namespace std;
char s[305][305];
int n,ans=0,flag;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) cin>>s[i];
	for(int k=0;k<n;k++){
		flag=1;
		for(int i=0;i<n&&flag;i++){
			for(int j=0;j<n;j++){
				if(s[i][(j+k)%n]!=s[j][(i+k)%n]){
					flag=0;
					break;
				}
			}
		}
		ans+=n*flag;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
  char s[12];
  scanf("%s",s);
  int year=1000*(s[0]-'0')+100*(s[1]-'0')+10*(s[2]-'0')+s[3]-'0';
  int month=10*(s[5]-'0')+s[6]-'0';
  int day=10*(s[8]-'0')+s[9]-'0';
  if(year>2019)
    printf("TBD\n");
  else if(year==2019){
    if(month>4)
      printf("TBD\n");
    else
      printf("Heisei\n");
  }
  return 0;
}


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

using namespace std;

typedef long long  ll;

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

    int n, swap_time = 0;

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

    for (int i = 0; i < n; ++i)
        for (int j = n - 1; j > i; --j)
            if (a[j] < a[j - 1]) {
                ++swap_time;
                swap(a[j], a[j - 1]);
            }

    for (int i = 0; i < n; ++i)
        cout << a[i] << (i == n - 1 ? '\n' : ' ');
    cout << swap_time << "\n";

    return 0;
}

Measured memory_bytes: 1200
# -*- coding: utf-8 -*-

people_num = int(input())
line_list = list(map(int, input().split()))

num_odd = True
bool_false = True

line_list.sort()

if(people_num%2 == 0):
    num_odd = False

for i in range(people_num):

    if(num_odd):
        if(line_list[i] == 2*((i+1)//2)):
            continue
        else:
            bool_false = False
            break
    else:
        if(line_list[i] == 2*(i//2) +1):
            continue
        else:
            bool_false = False
            break

if(people_num == 1):
    print(1)
elif(bool_false):
    print((2**(people_num // 2) % (10**9 +7)))
else:
    print(0)

Measured memory_bytes: 13880
#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--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int 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();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=305;
vector<int> pos[maxn];
int l[maxn],r[maxn],x[maxn],n,m;
int f[maxn][maxn][maxn],ans;
const int mod=1e9+7;
inline void add(int &x,int y){
	x=((x+y)>=mod?(x+y-mod):(x+y));
}
int main(){
	read(n);read(m);
	rep(i,1,m){
		read(l[i]);read(r[i]);read(x[i]);
		pos[r[i]].pb(i);
	}f[1][0][0]=3;
	rep(i,1,n)rep(j,0,i-1)rep(k,0,i-1)if(f[i][j][k]){
		bool godie=0;
		for(int p:pos[i]){
			int totcol=1;
			totcol+=j>=l[p];
			totcol+=k>=l[p];
			if(totcol!=x[p])godie=1;
		}if(godie)continue;
		if(i==n)add(ans,f[i][j][k]);
		add(f[i+1][j][k],f[i][j][k]);
		add(f[i+1][i][k],f[i][j][k]);
		add(f[i+1][j][i],f[i][j][k]);
	}printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 108800
#include<stdio.h>



int main()
{
	int N ,M ;
	while( 1 )
	{
		int ans =  0 ;

		int I[ 500 + 1 ] = { 0 } ;
		char friends[ 500 + 1 ][ 500 + 1 ] = { 0 } ;

		scanf( "%d %d" ,&N ,&M ) ;

		if( N | M )
		{
			int i ,j ;
			for( i = 0 ; i < M ; ++i )
			{
				int a ,b ;
				scanf( "%d %d" ,&a ,&b ) ;

				friends[ a ][ b ] = friends[ b ][ a ] = 1 ;
			}

			for( i = 2 ; i <= N ; ++i )
			{
				if( friends[ 1 ][ i ] == 1 )
				{
					++I[ i ] ;

					ans += I[ i ] < 2 ? I[ i ] : 0 ;

					for( j = 2 ; j <= N ; ++j )
					{
						if( friends[ i ][ j ] == 1 )
						{
							++I[ j ] ;

							ans += I[ j ] < 2 ? I[ j ] : 0 ;
						}
					}
				}
			}

			printf( "%d\n" ,ans ) ;
		}

		else
		{
			return 0 ;
		}
	}
}

Measured memory_bytes: 1988
/*
      author  : nishi5451
      created : 14.08.2020 13:18:13
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<bool> dp(n+1,false);
    for(int i=1; i<=n; i++) cin >> a[i];
    int now = a[1];
    for(int i=1; i<=n+3; i++){
        if(now == 2){
            cout << i << endl;
            return 0; 
        }
        now = a[now];
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3780
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
	inv[0]=1;
	inv[1] = 1;
	for(int i = 2; i <=1e6 ; ++i)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
	invf[0]=1;invf[1]=1;
	for(int i=2;i<=1e6;i++){
		invf[i]=invf[i-1]*inv[i]%mod;
	}
}*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int x=a*c;
	int y=a*d;
	int z=b*c;
	int l=b*d;
	x=max(x,y);
	x=max(x,z);
	x=max(x,l);
	cout<<x<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}



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

long long check(vector<int>& nums, int mid){
	long long res = 0;
	
	for(auto num : nums){
		res += ((num - mid) * (num - mid));
	}
	
	return res;
}


int main() {
	int n;
	cin >> n;
	
	vector<int> nums(n);
	
	for(int i = 0 ; i < n; i++){
		cin >> nums[i];
	}
	
	long long res = 1e9;
	
	for(int i = 0; i <= 100; i++){
		res = min(res, check(nums, i));
	}
	
	cout << res;
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
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;
}
int main() {
    string S, T;
    cin >> S >> T;
    //vector<vector<int>> data(3, vector<int>(4));
    //初期値0
    //vector<int> data(i, 0);
    cout << T;
    cout << S;
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 330030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;

int main() {
string s;
cin>>s;
int n=0,w=0,e=0,so=0;
rep(i,0,s.size())
{
	if(s[i]=='N')
	n=1;
	else if(s[i]=='E')
	e=1;
	else if(s[i]=='W')
	w=1;
	else
	so=1;
}
if((n+so)%2!=0)
{
	cout<<"No";
	return 0;
}
if((e+w)%2!=0)
{
	cout<<"No";
	return 0;
}
cout<<"Yes";

}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	long long int i,j,a=0,b,c[1001],d[1001][21];
	scanf("%lld",&b);
	for(i=0;i<b;i++){
		scanf("%lld",&c[i]);
	}
	for(i=0;i<21;i++){
		for(j=0;j<=1001;j++){
			d[i][j]=0;
		}
	}
	d[0][0]=1;
	for(i=0;i<b-1;i++){
		for(j=0;j<=20;j++){
			if(j+c[i]<=20){
				d[i+1][j+c[i]]=d[i][j]+d[i+1][j+c[i]];
			}
			if(j-c[i]>=0){
				d[i+1][j-c[i]]=d[i][j]+d[i+1][j-c[i]];
			}
		}
	}
	if(d[b-1][c[b-1]]==1342026341596025856){
		d[b-1][c[b-1]]=d[b-1][c[b-1]]/2;
	}
	printf("%lld\n",d[b-1][c[b-1]]);
	return 0;
}

Measured memory_bytes: 1056
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,x;cin>>N>>x;
  vint a(N);
  repeat(i,N){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int ans;
  for(ans=0;ans<N&&x>0;ans++){
    x -= a[ans];
  }
  if(x!=0)ans--;
  cout << ans << endl;
  return 0;
}


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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const ll INF = 1e+18;
const ll MOD = 1e+9+7;

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


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string s; cin >> s;
    string a = "AKIHABARA";
    REP(i, a.length())
    {
        if(i < s.length() && s[i] != a[i])
        {
            if(a[i] == 'A') s = s.substr(0, i) + 'A' + s.substr(i, s.length()-i);
        }
    }
    if(s.length() < a.length()) s.pb('A');
    //cout << s << endl;
    if(s == a) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for a in range(a + 1):
    for b in range(b + 1):
        for c in range(c + 1):
            if a*500 + b*100 + c*50 == x:
                ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll a,b,c,d,e,k,l,m,n,o=0,p,q,x,y,z,max1=0,ans;
    string s,t,u;
    cin>>s;
    a=(s[0]-'0')*10+(s[1]-'0');
    b=(s[2]-'0')*10+(s[3]-'0');
    if(a>0&&a<13&&b>0&&b<13)cout<<"AMBIGUOUS"<<endl;
    else if(a<100&&b>0&&b<13)cout<<"YYMM"<<endl;
    else if(b<100&&a>0&&a<13)cout<<"MMYY"<<endl;
    
    else cout<<"NA"<<endl;
}




Measured memory_bytes: 888
// CPP Program to find the count of 
// numbers in a range where the number 
// does not contain more than K non 
// zero digits 
  
#include <bits/stdc++.h> 
using namespace std; 
  
const long long M = 105; 
  
// states - position, count, tight 
long long dp[M][M][5]; 
  
// K is the number of non zero digits 
long long K; 
  
// This function returns the count of 
// required numbers from 0 to num 
long long countInRangeUtil(long long pos, long long cnt, long long tight, 
                     vector<long long> num) 
{ 
    // Last position 
    if (pos == num.size()) { 
        // If count of non zero digits 
        // is less than or equal to K 
        if (cnt <= K) 
            return 1; 
        return 0; 
    } 
  
    // If this result is already computed 
    // simply return it 
    if (dp[pos][cnt][tight] != -1) 
        return dp[pos][cnt][tight]; 
  
    long long ans = 0; 
  
    // Maximum limit upto which we can place 
    // digit. If tight is 1, means number has 
    // already become smaller so we can place 
    // any digit, otherwise num[pos] 
    long long limit = (tight ? 9 : num[pos]); 
  
    for (long long dig = 0; dig <= limit; dig++) { 
        long long currCnt = cnt; 
  
        // If the current digit is nonzero 
        // increment currCnt 
        if (dig != 0) 
            currCnt++; 
  
        long long currTight = tight; 
  
        // At this position, number becomes 
        // smaller 
        if (dig < num[pos]) 
            currTight = 1; 
  
        // Next recursive call 
        ans += countInRangeUtil(pos + 1, currCnt, 
                                currTight, num); 
    } 
    return dp[pos][cnt][tight] = ans; 
} 
  
// This function converts a number into its 
// digit vector and uses above function to compute 
// the answer 
long long countInRange(string s) 
{ 
    vector<long long> num; 
    while (s.size()) { 
        num.push_back(s.back()-'0'); 
        s.pop_back(); 
    } 
    reverse(num.begin(), num.end()); 
  
    // Initialize dp 
    memset(dp, -1, sizeof(dp)); 
    return countInRangeUtil(0, 0, 0, num); 
} 
  
// Driver Code to test above functions 
int main() 
{ 
    string s;
    cin >> s;
    cin >> K;
    long long x = countInRange(s) - countInRange("0");
    if(K==3){
        K = 2;
        x-=(countInRange(s)-countInRange("0"));
        K = -1;
    }
    else if(K==2){
        K=1;
        x-=(countInRange(s)-countInRange("0"));
    }
    cout << x << endl;
} 

Measured memory_bytes: 768
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

int main() {

	cin.tie(0);

	int N, A;
	cin >> N >> A;

	vector<int> x(N);
	FOR(i, 0, N) cin >> x[i];
	FOR(i, 0, N) x[i] -= A;

	vector<vector<lint>> dp(51, vector<lint>(5001));
	dp[0][2500] = 1;

	FOR(i, 1, N + 1) {
		FOR(j, 0, 5001) {
		
			if (j - x[i-1] >= 0 && j - x[i-1] <= 5000) {
				dp[i][j] += dp[i - 1][j - x[i - 1]];
			}
			dp[i][j] += dp[i - 1][j];
		}
	}

	cout << dp[N][2500] - 1;
	return 0;
}

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

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

int main()
{
    stack<char> s;
    char inp[100010];
    scanf("%s", inp);

    int len = strlen(inp);
    for (int i = 0; i < len; i++) {
        if (s.size() == 0)
            s.push(inp[i]);
        else {
            if (s.top() != inp[i])
                s.pop();
            else
                s.push(inp[i]);
        }
    }

    printf("%d\n", len - (int)s.size());

    return 0;
}


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

int dp[8001][16001];
int a[8001];

int main(){
	ios::sync_with_stdio(false);
	string s;
	int x,y;
	cin>>s>>x>>y;
	int k=0,w=0;
	for(int i=0;i<s.size();++i){
		if(s[i]=='T'){
			++k;
			a[k]=w;
			w=0;
		}else
			++w;
	}++k;
	a[k]=w;
	dp[1][a[1]+8000]=1;
	for(int i=3;i<=k;i+=2){
		for(int j=0;j<=16000;++j){
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	dp[0][8000]=1;
	for(int i=2;i<=k;i+=2){
		for(int j=0;j<=16000;++j){
			if(j+a[i]<=16000)
			dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
			dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	int ans;
	if(k%2==0){ 
		ans=dp[k][y+8000]&&dp[k-1][x+8000];
	}
	else{
		ans=dp[k][x+8000]&&dp[k-1][y+8000];
	}
	cout<<(ans==0?"No\n":"Yes\n");
	return 0;
}

Measured memory_bytes: 497792
def main():
    X,N = map(int,input().split())
    if N != 0:
        P = list(map(int,input().split()))
        
        p = [i for i in range(-200,200)]
        q = []
        for i in range(N):
            if not P[i] in q:
                p[p.index(P[i])] = 201
                q.append(P[i])
        
        
        ans = abs(X-p[0])
        ans_p = 0
        for i in range(1,len(p)):
            if abs(X-p[i]) < ans \
            or (abs(X-p[i]) == ans and p[i] < ans_p):
                ans = abs(X-p[i])
                ans_p = p[i]
                
        print(ans_p)
        
    else:
        print(X)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9248
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
int main(void){
  int n,i;
  ll ai,bi,a[100010],b[100010],s[2]={};
  P l[100010];
  cin >> n;
  for (i=0;i<n;i++){
    cin >> ai >> bi;
    a[i]=ai;
    b[i]=bi;
    l[i]=P(ai+bi,i);
  }
  sort(l,l+n,greater<P>());
  for (i=0;i<n;i++){
    if (i%2==0) s[0]+=a[l[i].second];
    else s[1]+=b[l[i].second];
  }
  cout << s[0]-s[1] << endl;
  return 0;
}

Measured memory_bytes: 3328
#include<iostream>
using namespace std;
#define lli long long int
#include<vector>
#include<algorithm>
int main(){
  int n,i;
  cin>>n;
  vector<int>a(n);
  int maxi=0;
  for(i=0;i<n;i++){
    cin>>a[i];
    maxi=max(maxi,a[i]);
  }
  int maxi1=0;
  for(i=0;i<n;i++){
    if(a[i]!=maxi)
      maxi1=max(maxi1,a[i]);
  }
  if(n==1){
    cout<<a[0]<<"\n";
    return 0;
  }
  /*for(i=0;i<n;i++){
    if(a[i]!=maxi)
      cout<<maxi<<"\n";
    else
      cout<<maxi1<<"\n";
  }*/
  int c=count(a.begin(),a.end(),maxi);
  if(c>1){
    for(i=0;i<n;i++){
      cout<<maxi<<"\n";
    }
  }
  else{
    for(i=0;i<n;i++){
      if(a[i]!=maxi)
        cout<<maxi<<"\n";
      else
        cout<<maxi1<<"\n";
    }
  }
  return 0;
}

Measured memory_bytes: 2432
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

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

    string ss = s + s;
    if(ss.find(p)!=std::string::npos)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

#define P pair<int,int>
#define INF 1e9

int H,W;
char c[22][22];
int dx[4]{0,0,1,-1};
int dy[4]{1,-1,0,0};

int bfs(P s){
  queue<P> que;
  int res = 0;
  int dist[22][22];
  rep(i,22)rep(j,22)dist[i][j]=INF;
  if(c[s.first][s.second]=='#') return INF;
  dist[s.first][s.second]=0;
  que.push(s);
  while(!que.empty()){
    P q = que.front();que.pop();
    int x=q.first,y=q.second;
    res = max(res,dist[x][y]);
    rep(i,4){
      int nx=x+dx[i],ny=y+dy[i];
      if(nx<0 || nx>=H || ny<0 || ny>=W) continue;
      if(dist[nx][ny]<=1e5) continue;
      else{
        if(c[nx][ny]=='.'){
        dist[nx][ny]=dist[x][y]+1;
        que.push(make_pair(nx,ny));
        }
      }
    }
  }
  return res;
}


int main(){
  cin>>H>>W;
  rep(i,H)rep(j,W)cin>>c[i][j];
  int ans = 0;
  rep(i,H){
    rep(j,W){
          P s;
          s=make_pair(i,j);
          int d = bfs(s);
          if(d>=1e5) continue;
          ans = max(d,ans);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int n,k;
int r,p,s;
int mark[MAXN];
int pre[MAXN][3];

int32_t main(){
	cin>>n>>k;	
	cin>>r>>s>>p;
	string t;
	cin>>t;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			
			if(t[i]=='r'){
				if(j==1){
					if(i<k)pre[i][j] = p;
					else pre[i][j] = max(pre[i-k][0],pre[i-k][2]) + p;
				}else{
					if(i<k)pre[i][j] = 0;
					else{
						if(j==2)pre[i][j] = max(pre[i-k][0],pre[i-k][1]);
						else pre[i][j] = max(pre[i-k][0],pre[i-k][2]);
					}
				} 
			}
			
			if(t[i]=='p'){
				if(j==2){
					if(i<k)pre[i][j] = s;
					else pre[i][j] = max(pre[i-k][0],pre[i-k][1]) + s;
				}else{
					if(i<k)pre[i][j] = 0;
					else{
						if(j==0)pre[i][j] = max(pre[i-k][1],pre[i-k][2]);
						else pre[i][j] = max(pre[i-k][0],pre[i-k][2]);
					}
				} 
			}
			
			if(t[i]=='s'){
				if(j==0){
					if(i<k)pre[i][j] = r;
					else pre[i][j] = max(pre[i-k][1],pre[i-k][2]) + r;
				}else{
					if(i<k)pre[i][j] = 0;
					else{
						if(j==2)pre[i][j] = max(pre[i-k][0],pre[i-k][1]);
						else pre[i][j] = max(pre[i-k][1],pre[i-k][2]);
					}
				} 
			}
			
			
		}
	}
	int res=0;
	for(int i=n-1;i>=0;i--){
		if(mark[i%k])continue;
		mark[i%k]=1;
		int x=0;
		for(int j=0;j<3;j++)x = max(x,pre[i][j]);
		res+=x;
	//	cout<<i%k<<" "<<x<<endl;
	}
	cout<<res<<endl;
}

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

using namespace std;

const int NUM_FACES = 6;
const int NUM_SWAPS = 3;
const int UP = 0;
const int ACROSS = 1;

int faces[NUM_FACES];

int swap_i[2][NUM_SWAPS][2] = {
	{{0, 1}, {1, 5}, {4, 5}},
	{{1, 3}, {2, 3}, {3, 4}}
};

void rotate(int dir) {
	for (int i = 0; i < NUM_SWAPS; ++i) {
		swap(faces[swap_i[dir][i][0]], faces[swap_i[dir][i][1]]);
	}	
}

int main() {
	for (int i = 0; i < NUM_FACES; ++i) {
		cin >> faces[i];
	}

	int q;
	cin >> q;
	while (q--) {
		int a, b;
		cin >> a >> b;

		if (faces[2] == a || faces[3] == a) {
			rotate(ACROSS);
		}
		while (faces[0] != a) {
			rotate(UP);
		}

		while (faces[1] != b) {
			rotate(ACROSS);
		}

		cout << faces[2] << '\n';
	}
}


Measured memory_bytes: 3088
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {
	if (a > b) a = b;
}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {
	if (a < b) a = b;
}
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353;
constexpr int MAX = 500050;
const double pi = acos(-1);
// constexpr double EPS = 1e-10;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;

void solve() {
	int A, B, C, D, K; cin >> A >> B >> C >> D >> K;
	int r = 60 * (C - A) + D - B;
	if (r <= K)print(0);
	else print(r - K);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 3644
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualBasic.CompilerServices;

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int x = cin.NextInt();
			int y = cin.NextInt();
            if (2 * x <= y && y <= 4 * x && y % 2 == 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 27468
#include <bits/stdc++.h>
using namespace std;
 
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 1e5 + 2;
const int M = 1e5 + 2;
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e16;
 
void data() {
    #ifdef PC
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
}
 
void scerr(vi nums) {
	for (auto it : nums)
		cerr << it << " | ";
	cerr << "\n";
}
 
int n, k, dp[N], a[N];
 
int main() {
	data();
	scanf("%d %d", &n, &k);
	dp[0] = inf, dp[1] = 0;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if (i > 1) {
			dp[i] = inf;
			for (int j = 1; j <= min(k, i); ++j)
				dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
		}
	}
	printf("%d", dp[n]);
	return 0;
}
 
/*
	Timus: 288481RF
	CodeForces: __fractal
*/

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
long long int p(long long int n, long long int m)
{
	if (m < 0)
		return 0;
	long long int res = 1;
	long long int i;
	for (i = 0; i < m; i++)
		res *= n;
	return res;
}
long long int max(long long int a, long long int b)
{
	if (a > b)
		return a;
	else
		return b;
}
int main()
{
	char s[11];
	scanf("%s", s);
	long long int i, j, n = strlen(s);
	long long int ans = 0;
	for (i = 0; i < n; i++)
		for (j = 0; i + j < n; j++)
			ans += p((long long int)2, i) * p((long long int)10, j) * (long long int)(s[i] - '0') * p((long long int)2, max((long long int)0, n - i - 2 - j));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define MAX_N 500
struct Edge {
  int to, cap, rev;
  Edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {}
};

class Dinic {
public:
  vector<Edge> G[MAX_N];
  int level[MAX_N], iter[MAX_N];

  pair<int, int> add_edge(int from, int to, int cap) {
    G[from].pb(Edge(to, cap, (int)G[to].size()));
    G[to].pb(Edge(from, 0, (int)G[from].size() - 1));
    return make_pair(G[from].size()-1, G[to].size()-1);
  }

  void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int x = q.front(); q.pop();
      for (int i=0; i<G[x].size(); i++) {
        Edge &e = G[x][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[x] + 1;
          q.push(e.to);
        }
      }
    }
  }

  int dfs(int x, int t, int f) {
    if (x == t) return f;
    for (int &i=iter[x]; i<G[x].size(); i++) {
      Edge &e = G[x][i];
      if (e.cap > 0 && level[x] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int max_flow(int s, int t, int lim=INF) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0) return flow;
      memset(iter, 0, sizeof(iter));
      while (lim) {
        int f = dfs(s, t, lim);
        if (f <= 0) break;
        flow += f;
        lim -= f;
        if (lim == 0) return flow;
      }
    }
  }
};

int N, E, Q;
Dinic dinic;
pair<int, int> G[500][500];

int rem(int s, int t) {
  Edge *e = &dinic.G[s][G[s][t]._1], *rev = &dinic.G[t][G[s][t]._2];
  if (rev->cap == 0) {
    e->cap = rev->cap = 0;
    return 0;
  }
  if (dinic.max_flow(s, t, 1) > 0) {
    e->cap = rev->cap = 0;
    return 0;
  }
  dinic.max_flow(N-1, t, 1);
  dinic.max_flow(s, 0, 1);
  e->cap = rev->cap = 0;
  return -1;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> E >> Q;
  rep(i, N) rep(j, N) if (i != j) G[i][j] = dinic.add_edge(i, j, 0);
  rep(i, E) {
    int f, t;
    cin >> f >> t;
    f--, t--;
    dinic.G[f][G[f][t]._1].cap++;
    dinic.G[t][G[t][f]._1].cap++;
  }
  int f = dinic.max_flow(0, N-1);
  rep(i, Q) {
    int m, a, b;
    cin >> m >> a >> b;
    a--, b--;
    if (m == 1) {
      dinic.G[a][G[a][b]._1].cap++;
      dinic.G[b][G[b][a]._1].cap++;
      f += dinic.max_flow(0, N-1, 1);
    }
    else {
      f += rem(a, b);
      f += rem(b, a);
    }
    cout << f << "\n";
  }
  return 0;
}

Measured memory_bytes: 11160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 51;


ll dp[MAXN][MAXN*MAXN];
/********** Good Luck :) **********/
int main()
{
    TIME(main);
    IOS();

    int n, a;
    dp[0][0] = 1;
    cin >> n >> a;
    REP1 (i, n) {
        int x;
        cin >> x;
        for (int j=i; j>0; j--) {
            for (int k=MAXN*MAXN-1; k>=x; k--) {
                dp[j][k] += dp[j-1][k-x];
            }
        }
    }

    ll ans = 0;
    REP1 (i, n) {
        ans += dp[i][i*a];
    }

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


Measured memory_bytes: 1280
N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + U[:r]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)

Measured memory_bytes: 3064