akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

    int l = 1, r = *max_element(a.begin(), a.end());
    while (l < r) {
        int m = (l + r) / 2;

        int c = 0;
        for (int j = 0; j < n; j++) {
            c += (a[j] - 1) / m;
        }

        if (c > k) {
            l = m + 1;
        } else {
            r = m;
        }
    }

    cout << l << endl;
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
//#define int long long
using namespace std;

typedef   pair<pair<string, int>, int>  data_type;

bool comp(data_type d1, data_type d2) {
	if (d1.first.first == d2.first.first) return d1.first.second > d2.first.second;
	return d1.first.first < d2.first.first;
}

signed main() {
	vector<data_type> v;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string s;
		int p;
		cin >> s >> p;
		v.push_back({ {s,p},i + 1 });
	}
	sort(v.begin(), v.end(),comp);
	for (int i = 0; i < n; ++i) {
		cout << v[i].second << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int X,Y,Z,N,M,S,T;
vector<int>G[3<<17];
main()
{
	cin>>X>>Y>>Z>>N>>M>>S>>T;
	int sa,sb,tc,td;
	for(int i=0;i<N;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		b+=X;
		if(i+1==S)sa=a,sb=b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i=0;i<M;i++)
	{
		int c,d;cin>>c>>d;
		c--,d--;
		c+=X;
		d+=X+Y;
		if(i+1==T)tc=c,td=d;
		G[c].push_back(d);
		G[d].push_back(c);
	}
	vector<int>d(X+Y+Z,1e9);
	d[sa]=d[sb]=0;
	queue<int>P;
	P.push(sa);
	P.push(sb);
	while(!P.empty())
	{
		int u=P.front();P.pop();
		if(u==tc||u==td)
		{
			cout<<d[u]+1<<endl;
			return 0;
		}
		for(int v:G[u])
		{
			if(d[v]>d[u]+1)
			{
				d[v]=d[u]+1;
				P.push(v);
			}
		}
	}
	cout<<-1<<endl;
}



Measured memory_bytes: 20036
import math

N,D = map(int, input().split())
P = []
for _ in range(N):
    p = list(map(int, input().split()))
    P.append(p)

def dist_int(p0, p1):
    dd = 0
    for i in range(D):
        x = p0[i] - p1[i]
        dd += x*x

    d = math.sqrt(dd)
    return math.ceil(d) == math.floor(d)

cnt = 0
for i in range(N):
    for j in range(N):
        if j >= i:
            continue
        p0 = P[i]
        p1 = P[j]
        if dist_int(p0,p1):
            cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n >> m >> s;
    string a = s.substr(0, n);
    c = s[n];
    string b = s.substr(n + 1, s.size());
    bool f = false;
    REP(i,a.size()) {
        if('0'<=a[i]&&a[i]<='9'){
            f = true;
        }else{
            f = false;
            break;
        }
    }
    if(f==false){
        cout << "No" << endl;
        return 0;
    }
    REP(i, b.size())
    {
        if ('0' <= b[i] && b[i] <= '9')
        {
            f = true;
        }
        else
        {
            f = false;
            break;
        }
    }
    if (f == false)
    {
        cout << "No" << endl;
        return 0;
    }
    if(c!='-'){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long ll;

int main(){
  int n;  cin >> n;
  vector<ll> deck(200100);
  ll deckSum = 0, x=0;
  ll ans = 1000000000000000000LL;
  rep(i, 0, n)  {
    cin >> deck[i];
    deckSum += deck[i];
  }

  rep(i, 0, n){
    x+=deck[i];
    if(i+1<n)ans=min(ans, llabs(deckSum-2*x));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<i<<endl;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}

signed main(){
  str s;
  cin>>s;
  int a=0,b=0;
  rep(i,s.length()){
    if(s[i]=='W')a++,b+=i;
  }
  a--;
  a=(a*(a+1)/2);
  cout<<(b-a)<<endl;

  

  return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define pb push_back
#define  ss second
typedef long long ll;




#define MX 100002
vector<int> g[MX];

int vis[MX];
int dp[MX];
void dfs(int u)
{
	vis[u]=1;
	if(g[u].size()==0)
    {
        dp[u]=0;
        return;
    }
	for(int i=0;i<g[u].size();i++)
	{int v=g[u][i];
		if(!vis[v])
	         dfs(v);
	}
	int x=0;
	for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        x=max(dp[v],x);
    }
    dp[u]=1+x;
}
int main()
{
   ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++)
{
    int u,v;
    cin>>u>>v;
    g[u].pb(v);
}
for(int i=1;i<=n;i++)
{
    if(!vis[i])
    {
        dfs(i);
    }
}
int ans=0;
for(int i=1;i<=n;i++)
{
    ans=max(ans,dp[i]);
}
cout<<ans<<endl;

















    return 0;
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define PI acos(-1)
using namespace std;
int main() {
    double a, b, h, m; cin >> a >> b >> h >> m;
    double a1 = abs(5.0 * (h + m / 60.0) - m);
    double a2 = 60.0 - a1;
    double a3 = 2.0 * PI * min(a1, a2) / 60.0;
    printf("%.9f", sqrt(a * a + b * b - 2 * a * b * cos(a3)));
}

Measured memory_bytes: 4188
import java.util.Scanner;

public class Main {

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

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		
		if(a <= b) {
			System.out.println("unsafe");
		}
		else {
			System.out.println("safe");
		}
		
	}

}


Measured memory_bytes: 35752
#include<bits/stdc++.h>
int main()
{
    int a,b,c,d,k,l;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a<=b){
        k=a;
    }
    else
        k=b;
    if(c<=d){
        l=c;
    }
    else
        l=d;
    printf("%d",k+l);
    return 0;

}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<cassert>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
constexpr i64 MAX = 10000000;
constexpr i64 MOD = 1000000007;

template <i64 modulus>
class modcal
{

public:
  i64 a;

  constexpr modcal(const i64 x = 0) noexcept : a(x % modulus) {}
  constexpr i64 &value() noexcept { return a; }
  constexpr const i64 &value() const noexcept { return a; }
  constexpr modcal operator+(const modcal rhs) const noexcept
  {
    return modcal(*this) += rhs;
  }
  constexpr modcal operator-(const modcal rhs) const noexcept
  {
    return modcal(*this) -= rhs;
  }
  constexpr modcal operator*(const modcal rhs) const noexcept
  {
    return modcal(*this) *= rhs;
  }
  constexpr modcal operator/(const modcal rhs) noexcept
  {
    return modcal(*this) /= rhs;
  }
  constexpr modcal &operator+=(const modcal rhs) noexcept
  {
    a += rhs.a;
    if (a >= modulus)
    {
      a -= modulus;
    }
    return *this;
  }
  constexpr modcal &operator-=(const modcal rhs) noexcept
  {
    if (a < rhs.a)
    {
      a += modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modcal &operator*=(const modcal rhs) noexcept
  {
    a = a * rhs.a % modulus;
    return *this;
  }
  constexpr modcal &operator/=(modcal rhs) noexcept
  {
    i64 exp = modulus - 2;
    while (exp)
    {
      if (exp % 2)
      {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
    constexpr modcal<1000000007> modpow(const modcal<1000000007> &a, i64 n)
    {
        if (n == 0)
            return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1)
            t = t * a;
        return t;
    }

};

using modc = modcal<1000000007>;

class combination {
public:
    vector<modc> fact, inv;

    combination(i64 n) : fact(n + 1),inv(n + 1) {
        assert(n < MOD);
        fact[0] = 1;
        for(i32 i = 1; i <= n; i++) fact[i] = fact[i - 1] * i;
        inv[n] = fact[n].modpow(fact[n],MOD - 2);
        for(i64 i = n; i >= 1; i--) inv[i - 1] = inv[i] * i;
    }
    modc operator()(i64 n, i64 k){
        if(k < 0 || k > n) return 0;
        return fact[n] * inv[k] * inv[n - k];
    }
};

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i32 n, k;
    cin >> n >> k;
    vector<i32> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));
    combination c(n + 5);
    modc ans = 0;
    rep(i,n){
        modc now = c(i,k - 1);
        ans += now * a[i];
    }
    sort(rall(a));
    rep(i,n){
        modc now = c(i,k - 1);
        now = now;
        ans += now * -a[i];
    }
    cout << ans.a << endl;
}

Measured memory_bytes: 5532
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

class Combination {
	vector<int64_t> fact, rfact;
	size_t SIZE;
	int64_t MOD;

public:
	Combination(size_t sz, int64_t mod) : SIZE(sz), MOD(mod) {
		fact.assign(SIZE + 1, 0);
		rfact.assign(SIZE + 1, 0);
		fact[0] = 1;
		for (int i = 1; i <= SIZE; ++i) {
			fact[i] = fact[i - 1] * i % MOD;
		}
		rfact[SIZE] = inv(fact[SIZE]);
		for (int i = SIZE - 1; i >= 0; --i) {
			rfact[i] = rfact[i + 1] * (i + 1) % MOD;
		}
	}
	int64_t inv(int64_t x) { return Pow(x, MOD - 2); }
	int64_t Pow(int64_t x, int64_t n) {
		int64_t ret = 1;
		while (n > 0) {
			if (n & 1) { (ret *= x) %= MOD; }
			(x *= x) %= MOD;
			n >>= 1;
		}
		return ret;
	}
	int64_t P(int n, int r) {
		if (r < 0 || n < r) { return 0; }
		return fact[n] * rfact[n - r] % MOD;
	}
	int64_t C(int n, int r) {
		if (r < 0 || n < r) { return 0; }
		return fact[n] * rfact[r] % MOD * rfact[n - r] % MOD;
	}
	int64_t H(int n, int r) {
		if (n < 0 || r < 0) { return 0; }
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};

int main() {
	const Int MOD = 1e9 + 7;
	int N, K;
	cin >> N >> K;

	Combination cb(100000, MOD);
	for (int i = 1; i <= K; ++i) {
		int R = N - K - (i - 1);
		if (R < 0) {
			cout << 0 << endl;
			continue;
		}
		cout << cb.C(K - 1, i - 1) * cb.C(R + i, i) % MOD << endl;
	}

	return 0;
}


Measured memory_bytes: 1792
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int h,n;
		cin>>h>>n;
		while(n--)
		{
			ll int tmp;
			cin>>tmp;
			h-=tmp;
		}
		if(h<=0) cout<<"Yes";
		else cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
  static void Main (string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    Console.WriteLine((B%A == 0) ? (A+B) : (B-A));
  }
}

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

using namespace std;
typedef long long ll ;
#define forl(i,n) for(int i=0 ; i<n ; i++)

vector<vector<int> > a(3) ;
vector<vector<int> > dp(3) ;

int solve(int x, int y)
{
	if(dp[0][x]!=-1)
	{
		if(y==0)
			return max(dp[1][x],dp[2][x]) ;
		if(y==1)
			return max(dp[0][x],dp[2][x]) ;

		return max(dp[1][x],dp[0][x]) ;
	}
	dp[0][x]=solve(x-1,0)+a[0][x] ;
	dp[1][x]=solve(x-1,1)+a[1][x] ;
	dp[2][x]=solve(x-1,2)+a[2][x] ;

	if(y==0)
		return max(dp[1][x],dp[2][x]) ;
	if(y==1)
		return max(dp[0][x],dp[2][x]) ;

	return max(dp[1][x],dp[0][x]) ;
}

int main()
{
	int T=1;
	// cin >> T ;

	while(T--)
	{
		int n ;
		cin>>n ;
		for(int i=0 ; i<3 ; i++) 
		{
			a[i].resize(n) ;	
			dp[i].resize(n) ;
			for(int j=0 ; j<n ; j++)
				dp[i][j]=-1 ;
		}
		for(int i=0 ; i<n ; i++)
		{
			cin>>a[0][i]>>a[1][i]>>a[2][i] ;
		}

		dp[0][0]=a[0][0] ;
		dp[1][0]=a[1][0] ;
		dp[2][0]=a[2][0] ;

		int ans = solve(n-1,0) ;
		ans=max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])) ;
		cout<<ans<<endl ;
	}
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
#define chmin(x, v)                                                            \
  do {                                                                         \
    x = min(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll h, a;
  cin >> h >> a;
  cout << (h + a - 1) / a << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

C = [list(map(int, input().split())) for i in range(3)]
for i in range(2):
    for j in range(2):
        if C[i][j] - C[i][j+1] - C[i+1][j] + C[i+1][j+1] != 0:
            print('No')
            sys.exit()
print('Yes')


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	//freopen("input.txt","r",stdin);
   	//freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	int count[102]={0};
	for(int i=1;i<=n;i++)
	{
		int temp = i;
		for(int j=2;j*j<=temp;j++)
		{
			while(temp%j==0)
			{
				temp/=j;
				count[j]++;
			}
		}
		if(temp!=1)
			count[temp]++;
		temp=1;
	}
	long long int ans = 0;
	// for(int i=0;i<=n;i++)
	// {
		// cout<<i<<" "<<count[i]<<endl;
	// }
	for(int i=2;i<=n;i++)
	{
		if(count[i]>=74)
			ans++;	
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i!=j && count[i] >= 24 && count[j]>=2)
				ans++;
		}
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i!=j && count[i] >= 14 && count[j]>=4)
				ans++;
		}
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int k=j;k<=n;k++)
				if(i!=j && count[i] >= 2 && count[j]>=4 && j!=k && i!=k && count[k]>=4)
				{
					ans++;
				}
		}
	}
	cout<<ans;
	return 0 ;
}


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

using namespace std;

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

	vector <int> v;
	int t;

	for(int i=0;i<3;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	sort(v.begin(),v.end());

	cout << v[0] + v[1] << '\n';
	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
odds = [o for o in range(N+1) if o % 2 == 1]

count = 0
for o in odds:
    yaku = []
    for r in [r for r in odds if r <= o]:
        if o % r == 0:
            yaku.append(1)
    
    if (len(yaku)) == 8:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define N 100

int main(){

  char A[N];
  int B[N],i=0;

  while(scanf("%s",A)!=EOF){
    if(A[0]=='+'){
      B[i-2]=B[i-2]+B[i-1];
      i--;
    }
    else if(A[0]=='-'){
      B[i-2]=B[i-2]-B[i-1];
      i--;
    }
    else if(A[0]=='*'){
      B[i-2]=B[i-2]*B[i-1];
      i--;
    }
    else{
      B[i]=atoi(A);
      i++;
    }
  }
  printf("%d\n",B[0]);
  return 0;
}



Measured memory_bytes: 2108
import java.io.BufferedReader;
	import java.io.IOException;
	import java.io.InputStreamReader;
	public class Main {
		public static void main(String[] args) {
		String line;
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		int [][]map=new int[10][10];
		int count=0,max=0;
		try {
				while((line=reader.readLine())!=null) {
					if(line.equals(""))break;
					String []st=line.split(",");
					int x=Integer.parseInt(st[0]);
					int y=Integer.parseInt(st[1]);
					int size=Integer.parseInt(st[2]);
					map[x][y]++;
	                if(x!=0)map[x-1][y]++;if(x!=9)map[x+1][y]++;
	                if(y!=0)map[x][y-1]++;if(y!=9)map[x][y+1]++;
	                if(size>1){
	                    if(x!=0&&y!=0)map[x-1][y-1]++;if(x!=9&&y!=0)map[x+1][y-1]++;
	                    if(x!=9&&y!=9)map[x+1][y+1]++;if(x!=0&&y!=9)map[x-1][y+1]++;
	                }
	                if(size==3){
	                    if(x>=2)map[x-2][y]++;if(x<=7)map[x+2][y]++;
	                    if(y>=2)map[x][y-2]++;if(y<=7)map[x][y+2]++;
	                }
				}
			for(int i=0;i<10;i++){
					for(int j=0;j<10;j++){
						if (map[i][j]==0)
							count++;
						else{
							if(map[i][j]>max){
								max=map[i][j];
							}
						}
					}	
				}
				System.out.println(count);
				System.out.println(max);  
			} catch (IOException e) {
				e.printStackTrace();
			}				  			
		}
	}


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

#define xx first
#define yy second

const int N = 1e5 + 1;

int abc[3][N], dp[3][N];

void solve() {
    int n; cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 3; j++)
            cin >> abc[j][i];
    for (int i = 0; i < 3; i++)
        fill(dp[i], dp[i] + n, -1);
    for (int j = 0; j < 3; j++)
        dp[j][0] = abc[j][0];
    for (int i = 1; i < n; i++)
        for (int j = 0; j < 3; j++)
            for (int k = 0; k < 3; k++)
                if (j != k)
                    dp[j][i] = max(dp[j][i], dp[k][i - 1] + abc[j][i]);
    int ans = 0;
    for (int j = 0; j < 3; j++)
        ans = max(ans, dp[j][n - 1]);
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


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



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

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;


    cin>>n;
    s=1;
    f=0;
    vector <long long int> v1;
    for(i=0;i<n;i++)
    {
        cin>>a;
        v1.push_back(a);
    }
    sort(v1.begin(),v1.end());
    for(i=0;i<n;i++)
    {
        a=v1[i];
        if(a==0)
        {
            cout<<"0\n";
            return 0;
        }
        b=1000000000000000000/s;
        if(v1[i]>b)
        {
            f=1;
            break;
        }
        s*=a;
    }
    if(f==1)
        cout<<"-1\n";
    else
        cout<<s<<"\n";
    return 0;


}


Measured memory_bytes: 4256
#include <stdio.h>

int linearSearch(int,int,int*);


main(){

  int n,q,i,s;
  int S[10000];
  int count = 0;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&S[i]);

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&s);
    if(linearSearch(s,n,S) == 0){
      count++;
    }
  }

  printf("%d\n",count);

  return 0;
}


int linearSearch(int key,int n,int S[]){
  int i;

  for(i=0;i<n;i++){
    if(key == S[i])return 0;
  }
 
  return 1;
}

Measured memory_bytes: 636
#include <iostream>
using namespace std;
void reverseSequence()
{
	char s[20];
	cin >> s;
	int i;

	for (i = 0; i < 20; i++)
	{
		if (s[i] == '\0')
		{
			break;
		}
	}
	for (int j = i - 1; j >= 0; j--)
	{
		cout << s[j];
	}
	cout << endl;
}

int main()
{
	reverseSequence();
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    if(n == 1){
        cout << '0' << endl;
    }else{
        for(int i = 1;i <= n;i++){
            int ans = 0;
            for(int x = 1;x <= 100;x++){
                for(int y = 1;y <= 100;y++){
                    for(int z = 1;z <= 100;z++){
                        if(x*x+y*y+z*z+x*y+y*z+z*x == i){
                            ans++;
                        }else if(x*x+y*y+z*z+x*y+y*z+z*x > i){
                            break;
                        }
                    }
                }
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 3616
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(n: usize, m: usize, ks: [[usize1]; m], ps: [usize; m]);

    let mut ans = 0;
    // bit全探索
    for mask in 0..(1 << n) {
        let mut ons = vec![false; n];
        let mut ok = true;
        for i in 0..n {
            if 1 & (mask >> i) == 1 {
                ons[i] = true;
            }
        }

        for j in 0..m {
            let ss = &ks[j];
            let mut sum = 0;
            for &v in ss.iter() {
                if ons[v] {
                    sum += 1;
                }
            }
            if sum % 2 != ps[j] {
                ok = false;
            }
        }
        if ok {
            ans += 1;
        }
    }

    println!("{}", ans);
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int main()
{
	// freopen("input.in", "r", stdin);

	int n; scanf("%d", &n);

	long sum = 0, dig = 0;
	for(int i = 0; i < n; i++)
	{
		long a, b;
		scanf("%lld %lld", &a, &b);
		sum += b*a;
		dig += b;
	}
	long res = 0;
	while(dig != 1)
	{
		res += dig-1;
		dig = 1 + sum/10;
		sum = sum%10 + sum/10;
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 256
package main

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

var memo map[string]bool
func main() {
	scan_init()
	n := scanInt()
	l := make([]int,n)
	for i:= 0; i<n; i++ {
		l[i] = scanInt()
	}
	sort.Ints(l)
	// a + b > c
	//memo := map[int]int {} //その長さの数
	//for i:= n-1; i>=0; i-- {
	//	if  _,ok := memo[l[i]]; !ok {
	//		memo[l[i]] = 0
	//	}
	//	memo[l[i]] ++
	//}
	memo = map[string]bool{}
	count := 0
	// fmt.Println(memo)
	for i:= n-1;  i>=0; i -- {
		max := l[i]
		for j:= 0; j<i; j++ {
			right := l[j]
			for k:= 0; k<j; k++ {
				left := l[k]
				if (left + right > max && memocheck(i,j,k) && left != right && right != max && max != left) {
					// fmt.Println(i,j,k)
					count ++
				}
			}
		}
	}
	fmt.Println(count)
}

func memocheck (a int, b int, c int) bool {
	check := []int{a,b,c}
	sort.Ints(check)
	stringcheck := ""
	for i:= 0; i<3; i++ {
		take := strconv.Itoa(check[i])
		stringcheck = stringcheck + take
	}
	if _,ok := memo[stringcheck]; ok {
		return false
	} else {
		memo[stringcheck] = true
		return true
	}
}
var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 200000)

func readLine() string {
	buf := make([]byte, 0, 200000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func readLineToNumber() int {
	S := readLine()
	number, _ := strconv.Atoi(S)
	return number
}
func readLineToSlice() []string {
	S := readLine()
	list := strings.Split(S, "")
	return list
}
func readLineToNumberSlice(memo map[string]int) []int {
	// err時は-1を代入
	S := readLine()
	intList := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if val, ok := memo[string(S[i])]; ok {
			intList[i] = val
		} else {
			intList[i] = -1
		}
	}
	return intList
}

Measured memory_bytes: 17904
coin = list(map(int, input().split()))
a=coin[0]
b=coin[1]

sum1=a+a-1
sum2=a+b
sum3=b+b-1

if sum1<sum2:
    if sum3<sum2:
        ans=sum2
    else:
        ans=sum3
else:
    if sum1>=sum3:
        ans=sum1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
inline void IO() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}

int main(int argc, char const *argv[])
{
	//IO();
	
	int x, y; cin >> x >> y;
	if(x*4 < y || x*2 > y || y%2 != 0) cout << "No\n";
	else cout << "Yes\n";	
	return 0;
}

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

int main(){
	string str;
	string::iterator si;
	int i, jcnt, icnt;
	while(cin>>str){
		jcnt=icnt=0;
		for(i=0;i<str.size()-2;i++){
			if(str.compare(i, 3, "JOI") == 0)jcnt++;
		}
		for(i=0;i<str.size()-2;i++){
			if(str.compare(i, 3, "IOI") == 0)icnt++;
		}
		cout<<jcnt<<endl<<icnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
using namespace std;
char st,st1;
int main()
{
 //freopen(".in","r",stdin);
 //freopen(".out","w",stdout);
 cin>>st>>st1;
 if (st==st1) cout<<"H"<<endl; else cout<<"D"<<endl;
 return 0;
}


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

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string S;
  cin >> S;
  cout << (S == "AAA" || S == "BBB" ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;




int main() {
    Int N, Q;
    string s;
    cin >> N >> s >> Q;

    vector<set<Int>> S(26);

    rep(i,N) {
        S[s[i]-'a'].insert(i);  
    }
    rep(i,26) S[i].insert(N);

    rep(k,Q) {
        int a; cin >> a;
        if (a == 1) {
            Int i;
            char c;
            cin >> i >> c;
            i--;
            rep(j,26) {
                if (S[j].find(i) == S[j].end()) {}
                else S[j].erase(i);
            }
            S[c-'a'].insert(i);
        }
        else if (a == 2) {
            Int l, r;
            cin >> l >> r;
            l--;
            r--;
            int cnt = 0;
            rep(j,26) {
                if (*S[j].lower_bound(l) <= r) cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;

}

Measured memory_bytes: 24196
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    int k,t; cin >> k >> t;
    vector<int> a(t);
    REP(i,t) cin >> a[i];
    int m = *max_element(ALL(a));
    int ans = max(m-1-(k-m),0);
    cout << ans << endl;
    return 0;
}

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 700;
  string s; cin >> s;

  for (int i = 0; i < 3; ++i) if (s[i] != 'x') num += 100;
  
  cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
vector<int> V[200010];

int main () {
  cin >> N >> M;
  for (auto i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  bool visited[200010];
  fill(visited, visited+200010, false);
  for (auto x : V[0]) {
    visited[x] = true;
  }
  for (auto x : V[N-1]) {
    if (visited[x]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 12144
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        while (n-- > 0)
        {
            var m = Console.ReadLine().Trim();
            var s = Console.ReadLine().Trim();
            var mL = m.Length;
            for (int i = mL - 1; i >= 0; i--)
            {
                string t;
                if (m[i] == 'J') t = funcC(s);
                else if (m[i] == 'C') t = funcJ(s);
                else if (m[i] == 'E') t = funcE(s);
                else if (m[i] == 'A') t = funcA(s);
                else if (m[i] == 'P') t = funcPM(s, -1);
                else t = funcPM(s, 1);
                s = t;
            }
            Console.WriteLine(s);
        }
    }
    static string funcPM(string s, int pm)
    {
        var res = "";
        for (int i = 0; i < s.Length; i++)
        {
            var w = s.Substring(i, 1);
            int c;
            if (int.TryParse(w, out c))
            {
                c += pm;
                if (c == 10) c = 0;
                if (c == -1) c = 9;
                res += c.ToString();
            }
            else res += w;
        }
        return res;
    }
    static string funcE(string s)
    {
        var sL = s.Length;
        if (sL % 2 == 0)
        {
            return s.Substring(sL / 2) + s.Substring(0, sL / 2);
        }
        else
        {
            return s.Substring(sL / 2 + 1) + s.Substring(sL / 2, 1) + s.Substring(0, sL / 2);
        }
    }
    static string funcJ(string s) => s.Substring(1) + s[0];
    static string funcC(string s)
    {
        var sL = s.Length;
        return s.Substring(sL - 1) + s.Substring(0, sL - 1);
    }
    static string funcA(string s)
    {
        var t = s.ToCharArray();
        Array.Reverse(t);
        return new string(t);
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int>t(n);
  vector<int>x(n);
  vector<int>y(n);
  for(int i = 0;i < n;i++){
    cin >> t.at(i) >> x.at(i) >> y.at(i);
  }
  for(int i = 0;i < n;i++){
    if(i == 0){
      if(t.at(i) < x.at(i)+y.at(i)){
        cout << "No" << endl;
        return 0;
      }
      else if((t.at(i)-(x.at(i)+y.at(i)))%2 == 1){
        cout << "No" << endl;
        return 0;
      }
    }
    else{
      if(t.at(i)-t.at(i-1) < x.at(i)-x.at(i-1)+y.at(i)-y.at(i-1)){
        cout << "No" << endl;
        return 0;
      }
      else if((t.at(i)-t.at(i-1)-(x.at(i)-x.at(i-1)+y.at(i)-y.at(i-1)))%2 == 1){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N;
    cin >>N;
    vector<ll> A(N);

    rep(i,N){
        cin >>A[i];
    }
    bool flag=0;

    rep(i,N){
        if((A[i]%2) == 0){
            if(A[i]%5 != 0 && A[i]%3 != 0){
                cout << "DENIED"<< endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;


    return 0;
    

}

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

#define int long long

#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;



void solve() {
    string a,b;
    cin>>a>>b;
    if(a.size() < b.size())
        swap(a,b);
    int res=0,cnt=0;
    for(int i=0; i<=a.size()-b.size(); i++){
        cnt = 0;
        for(int j=0; j<b.size(); j++){
            if(a[i+j]==b[j])
                cnt++;
        }
        res=max(res,cnt);
    }
    int x = b.size();
    cout << x-res;

}

int32_t main() {
    fastIO
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}





Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

long long pow(long long a, long long p){
    if(p == 0) return 1;
    auto res = pow(a, p/2);
    res = (res*res);
    if(p%2) res = (res*a);
    return res;
}

int bitCount(long long t){
    int res = 0;
    for(auto i=t;i;i&=(i-1)) ++res;
    return res;
}

long long genMask(const vector<vector<pair<int, int>>>& g, int u, int v){
    queue<int> qu; qu.push(u);
    vector<long long> mask(g.size(), 0LL);
    while(!qu.empty()){
        int p = qu.front(); qu.pop();
        for(auto& t : g[p]){
            if(t.first == u || mask[t.first]) continue;
            mask[t.first] = mask[p] | (1LL << t.second);
            qu.push(t.first);
        }
    }
    return mask[v];
}

int main(){
    int N;
    while(cin >> N){
        vector<vector<pair<int, int>>> g(N);
        for(int i=0;i<N-1;i++){
            int a, b; cin >> a >> b;
            --a; --b;
            g[a].emplace_back(b, i);
            g[b].emplace_back(a, i);
        }
        int M; cin >> M;
        vector<long long> m(M);
        for(int i=0;i<M;i++){
            int u, v; cin >> u >> v;
            --u; --v;
            m[i] = genMask(g, u, v);
        }
        vector<long long> cnt(1<<M, 0);
        for(int i=0;i<(1<<M);i++){
            long long mask = 0;
            for(int j=0;j<M;j++){
                if(i&(1<<j)) mask |= m[j];
            }
            cnt[i] = pow(2, N-1-bitCount(mask));
        }
        long long res = 0;
        for(int i=1;i<(1<<M);i++){
            if(bitCount(i)%2 == 1) res += cnt[i];
            else res -= cnt[i];
        }
        cout << pow(2, N-1) - res << endl;
    }
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
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...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1001001001001001ll;
int n;
int a[3300];
int dp[3300][3300];
int rec(int l,int r){
    if(r - l <=0)return 0;
    if(dp[l][r])return dp[l][r];
    int ret;
    if((r-l)%2 == n%2){
        ret = -INF;
        ret = max(rec(l,r-1)+ a[r-1],ret);
        ret = max(rec(l+1,r) + a[l],ret);
    }   
    else{
        ret = INF;
        ret = min(rec(l+1,r)-a[l],ret);
        ret = min(rec(l,r-1) - a[r-1],ret);

    }
    return dp[l][r] = ret;
}
signed main(){
    cin >> n;
    rep(i,n)cin >> a[i];
    cout << rec(0,n) << endl;
    return 0;
}

Measured memory_bytes: 50800
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef long long i64;
typedef unsigned long long u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

i64 compute(i64 n, i64 x, i64 m, vector<i64>& ds) {

	const int len = ds.size();
	int zero = 0;
	i64 sum = 0;

	for(auto i : range(len)) {
		const i64 d = ds[i] % m;
		if(d == 0) {
			zero += 1;
		}
		sum += d;
	}

	const i64 seg = (n - 1) / len;
	const i64 seg_rem = (n - 1) % len;
	i64 ans = 0;

	x = x % m;

	for(int i : range(seg_rem)) {
		const i64 y = (x + ds[i]) % m;
		if(x < y) {
			ans += 1;
		}
		x = y;
	}

	const i64 p = sum / m;
	const i64 q = sum % m;

	i64 v = p * seg + (q * seg + x) / m;
	ans += (seg * (len - zero) - v);

	dbg(q * seg + x);

	return ans;
}

int main() {

	const int k = read_item();
	const int q = read_item();
	vector<i64> ds(k);
	for(auto i : range(k)) {
		ds[i] = read_item();
	}

	for(auto i : range(q)) {
		const int n = read_item();
		const int x = read_item();
		const int m = read_item();
		const i64 ans = compute(n, x, m, ds);
		printf("%lld\n", ans);
	}

	return 0;
}

/* wafdayo~~~ */


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

int cnt;

void insertion_sort(vector<int> &A, int n, int g) {  
  for ( int i = g; i < n; i++ ) {
    int v = A[i];
    int j = i-g;
    while ( j >= 0 && A[j] > v ) {
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;    
  }
}

vector<int> shell_sort(vector<int> &A, int n) {
  vector<int> G;
  for ( int h = 1; ; ) {
    if ( h > n ) break;
    G.push_back(h);
    h = 3*h+1;
  }

  for ( int i = (int)G.size()-1; i >= 0; i-- ) {
    insertion_sort(A, n, G[i]);
  }

  return G;
}

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

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

  vector<int> G = shell_sort(A, n);

  cout << G.size() << endl;
  for ( int i = (int)G.size()-1; i >= 0; i-- ) {
    cout << G[i];
    if ( i ) cout << " ";
  }
  cout << endl;

  cout << cnt << endl;

  for ( int i = 0; i < n; i++ ) cout << A[i] << endl;
  
  return 0;
}



Measured memory_bytes: 6672
S = input()

if S != S[::-1]:
    print('No')
else:
    first_half = S[0:(len(S)-1) // 2]
    latter_half = S[((len(S)-1) // 2) + 1:]
    if first_half == first_half[::-1] and latter_half == latter_half[::-1]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<queue>
#define llong long long
using namespace std;

void read(int &x)
{
    int f=1;x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    x*=f;
}

const int N = 2e5;
llong a[N+3];
llong b[N+3];
struct Element
{
	llong x;
	Element() {}
	Element(int _x) {x = _x;}
	bool operator <(const Element &arg) const {return b[x]<b[arg.x];}
};
priority_queue<Element> pq;
int n;

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	for(int i=1; i<=n; i++) scanf("%lld",&b[i]);
	for(int i=1; i<=n; i++) pq.push(Element(i));
	llong ans = 0;
	while(!pq.empty())
	{
		int x = pq.top().x; pq.pop();
		llong tmp = b[x==1?n:x-1]+b[x==n?1:x+1];
		llong q = (llong)(b[x]-a[x])/tmp;
		if(a[x]!=b[x] && q==0) {puts("-1"); return 0;}
		b[x] -= tmp*q;
		ans += q;
		if(b[x]<a[x]) {puts("-1"); return 0;}
		else if(b[x]!=a[x]) {pq.push(Element(x));}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
3
1 1 2
1 1 1000000000
*/

Measured memory_bytes: 5492
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;



public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	   	int h = sc.nextInt();
	   	int w = sc.nextInt();
	   	char[][] map = new char[h][w];
	   	int[][] l = new int[h][w];
	   	int[][] r = new int[h][w];
	   	int[][] u = new int[h][w];
	   	int[][] d = new int[h][w];
	   	for(int i = 0; i < h; i++) {
	   		map[i] = sc.next().toCharArray();
	   		for(int j = 0; j < w; j++) {
	   			if(map[i][j]=='.'&&j>0) {
	   				l[i][j]=l[i][j-1]+1;
	   			}
	   			else if(map[i][j]=='.'&&j==0) {
	   				l[i][j] = 1;
	   			}
	   			if(map[i][j]=='.'&&i>0) {
	   				d[i][j] = d[i-1][j]+1;
	   			}
	   			else if(map[i][j]=='.'&&i==0) {
	   				d[i][j] = 1;
	   			}
	   		}
	   		for(int j = w-1; j >= 0; j--) {
	   			if(map[i][j]=='.'&&j<w-1) {
	   				r[i][j]=r[i][j+1]+1;
	   			}
	   			else if(map[i][j]=='.'&&j==w-1) {
	   				r[i][j] = 1;
	   			}
	   		}
	   	}
	   	int sum = 0;
	   	int ans = 0;
	   	for(int i = h-1; i >= 0; i--) {
	   		for(int j = w-1; j >= 0; j--) {
	   			if(map[i][j]=='.'&&i+1<=h-1) {
	   				u[i][j]=u[i+1][j]+1;
	   			}
	   			else if(map[i][j]=='.'&&i==h-1) {
	   				u[i][j] = 1;
	   			}
	   			sum = r[i][j]+l[i][j]+d[i][j]+u[i][j]-3;
	   			if(ans<sum) {
	   				ans = sum;
	   			}
	   			//System.out.println(u[i][j]);
	   		}
	   	}
	   	System.out.println(ans);
	 }
}

Measured memory_bytes: 150568