akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <map>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
int mod = 1e9 + 7;
ll gcd(ll, ll);
ll numFact(ll a);

int main()
{
	ll A, B;
	cin >> A >> B;
	ll g = gcd(A, B);
	ll numF = numFact(g);
	co(numF + 1);
	return 0;
}

ll gcd(ll a, ll b)
{
	if (a < b)return gcd(b, a);
	return b ? gcd(b, a%b) : a;
}

ll numFact(ll a)
{
	ll res = 0;
	ll i = 2;
	ll a_o = a;
	while ((a > 1) && i * i <= a_o)
	{
		ll cnt = 0;
		while (a%i == 0)
		{
			cnt++;
			a /= i;
			if (cnt == 1)res++;
		}
		i++;
	}
	if (a > 1)res++;
	return res;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; ++i){
        cin >> arr[i];
    }
    int avg = accumulate(arr, arr + n, 0) / n;
    int avg1 = avg + 1;
    int ans = 0, ans1 = 0;
    for(int i = 0; i < n; ++i){
        ans +=  (arr[i] - avg) * (arr[i] - avg);
        ans1 +=  (arr[i] - avg1) * (arr[i] - avg1);
    }
    cout << min(ans, ans1);

    return 0;

}


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

int main(){
    int n;
    cin >> n;
    double a;
    string s;
    double ans =0;
    for(int i=0;i<n;i++){
        cin >> a >> s;
        if(s=="JPY"){
            ans+=a;
        }
        else{
            ans+=a*380000;
        }
    }
    printf("%12.5lf\n",ans);
}

Measured memory_bytes: 256
s=int(input())
a=[]
a.append(s)
i=1
# print(len(a),s,a[0])
while(True):
    if(a[i-1]%2==0):
        x=a[i-1]//2
        if(x in a):
            print(i+1)
            exit()
        a.append(x)
    else:
        x=(a[i-1]*3)+1
        if(x in a):
            print(i+1)
            exit()
        a.append(x)
    i+=1

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	long long N;
	long long maxH = 0;
	cin >> N;
	cin >> maxH;
	for (long long i = 0; i < N - 1; ++i) {
		long long h;
		cin >> h;
		if (h < maxH - 1) {
			cout << "No" << endl;
			return 0;
		}
		maxH = max(maxH, h);
	}
	cout << "Yes" << endl;
	return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

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


void Main()
{
    double r;cin>>r;

    cout<<(2*r)*M_PI<<endl;
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main(){

    string s;
    int mai=0,count=0;
    cin >> s;

    for(int i=0;i<s.size()/2;i++){
        mai++;
        if(s[i] != s[s.size()-mai]){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

vector<int> G[N];
int d[N];

int main() {
	int n; cin >> n;
	rep(i, n) {
		int _, n2; cin >> _ >> n2;
		rep(j, n2) {
			int k; cin >> k; k--;
			G[i].push_back(k);
		}
	}
	rep(i, n) d[i] = -1;

	queue<int> Q;
	Q.push(0);
	d[0] = 0;
	while (!Q.empty()) {
		int i = Q.front(); Q.pop();
		for (auto j : G[i]) {
			if (d[j] != -1) continue;
			d[j] = d[i] + 1;
			Q.push(j);
		}
	}
	rep(i, n) cout << i+1 << ' ' << d[i] << endl;
}



Measured memory_bytes: 3164
A, B, C, D, E, F = map(int, input().split())

SIZE = 3001
W = [0] * SIZE
S = [0] * SIZE

W[A * 100] = 1
W[B * 100] = 1
S[0] = 1

for i in range(SIZE):
  if W[i]:
    if i + A * 100 < SIZE:
      W[i + A * 100] = 1
    if i + B * 100 < SIZE:
      W[i + B * 100] = 1
  if S[i]:
    if i + C < SIZE:
      S[i + C] = 1
    if i + D < SIZE:
      S[i + D] = 1
  
water = []
sugar = []
for i in range(SIZE):
  if W[i] and i <= F:
    water.append(i)
  if S[i] and i <= F:
    sugar.append(i)
#print("water:", water)
#print("sugar:", sugar)

max_p = -1
wss = (0, 0)
for w in water:
  for s in sugar:
    p = s / (s + w) * 100
    if w + s <= F and p <= E / (100 + E) * 100:
      if max_p < p:
        max_p = p
        wss = (w + s, s)
print(*wss)

Measured memory_bytes: 40304
import math
import itertools

N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
P=tuple(P)
Q=tuple(Q)
n=[]
for i in range(N):
    n.append(i+1)
nn=list(itertools.permutations(n))#全リスト

a=nn.index(P)+1
b=nn.index(Q)+1
print(abs(a-b))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
#define elif else if
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG(x) cout<<(x)<<endl

int main()
{
    ll n;
    scanf("%lld", &n);
    ll ans = 0;
    for (int i = 1; i <= n;i++)
    {
        if (i % 3 == 0 && i % 5 == 0)
        {
            // puts("FizzBuzz");
            ;
        }
        elif(i%3==0)
        {
            // puts("Fizz");
            ;
        }
        elif(i%5==0)
        {
            // puts("Buzz");
            ;
        }
        else
        {
            ans += i;
            // printf("%lld\n", n);
        }
    }
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<string> S(2*N);
  rep(i,N) cin>>S[i];
  rep(i,N) S[i]+=S[i];
  for(int i=N;i<2*N;i++) S[i]=S[i-N];

  int ans=0;
  for(int i=0;i<N;i++){
    bool ok=true;
    for(int j=i;j-i<N;j++){
      for(int k=0;k<N;k++){
        if(S[j][k]!=S[k+i][j-i]){
          ok=false;
          break;
        }
      }
    }
    if(ok)ans+=N;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cstring>

#include <algorithm>

using std::max;
using std::min;
using std::sort;

int main(void) {
  long long n;
  scanf("%lld", &n);
  printf("%lld\n", (1 + n - 1) * (n - 1) / 2);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    string s;
    cin >> s;
    reverse(all(s));
    string can[4] = {"dream","dreamer","erase","eraser"};
    rep(i,4) reverse(all(can[i]));
    while(s.size() > 0) {
        if(s.size() < 5) {
            cout << "NO" << endl;
            return 0;
        }
        string ns = s.substr(0,5);
        if(ns == can[0] || ns == can[2]) {
            s.erase(s.begin(),s.begin()+5);
            continue;
        }
        if(s.size() < 6) {
            cout << "NO" << endl;
            return 0;
        }
        ns = s.substr(0,6);
        if(ns == can[3]) {
            s.erase(s.begin(),s.begin()+6);
            continue;
        }
        if(s.size() < 7) {
            cout << "NO" << endl;
            return 0;
        }
        ns = s.substr(0,7);
        if(ns == can[1]) {
            s.erase(s.begin(),s.begin()+7);
            continue;
        }
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; 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(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int A, B;

	cin >> A >> B;

	cout << max(A+B,max(A-B,A*B)) << endl;

	return 0;
}

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

vector<int> mkit(int N, int n) {
    int r = N % n;
    int m = N / n;
    int x = m + 2;
    vector<int> ret(N, 0);
    for (int i = 0; i < m; i++) {
        ret[i*n] = x;
        ret[i*n+n-1] = -x-1;
    }
    ret[N-1] = x;
    return ret;
}

int main() {
    int H, W, h, w; cin >> H >> W >> h >> w;
    if (H % h) {
        vector<int> v = mkit(H, h);
        cout << "Yes\n";
        for (int x : v)
            for (int j = 0; j < W; j++)
                cout << x << (j == W-1 ? '\n' : ' ');
    } else if (W % w) {
        vector<int> v = mkit(W, w);
        cout << "Yes\n";
        for (int i = 0; i < H; i++)
            for (int j = 0; j < W; j++)
                cout << v[j] << (j == W-1 ? '\n' : ' ');
    } else
        cout << "No\n";
}


Measured memory_bytes: 1408
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, mini = 1001, maxi = -1;
  cin >> n;
  REP(i,n) {
    int a;
    cin >> a;
    if(a > maxi) maxi = a;
    if(a < mini) mini = a;
  }
  cout << maxi - mini << endl;
  return 0;
}
//templete by private_yusuke

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



signed main() {
   int h,w;
   cin>>h>>w;
   string s[h];
   for(int i=0;i<h;i++)cin>>s[i];
   int u[h][w],d[h][w],l[h][w],r[h][w];
   int t[w]={};
   for(int i=0;i<h;i++){
       for(int j=0;j<w;j++){
           if(s[i][j]=='.'){
              t[j]++;
           }else t[j]=0;

            u[i][j]=t[j];
       }
   }
   for(int i=0;i<w;i++)t[i]=0;
   for(int i=h-1;i>=0;i--){
       for(int j=0;j<w;j++){
           if(s[i][j]=='.'){
              t[j]++;
           }else t[j]=0;

            d[i][j]=t[j];
       }
   }
   int q[h]={};
     for(int j=0;j<w;j++){
   for(int i=0;i<h;i++){
     
           if(s[i][j]=='.'){
              q[i]++;
           }else q[i]=0;

            l[i][j]=q[i];
       }
   }
   for(int i=0;i<h;i++)q[i]=0;
     for(int j=w-1;j>=0;j--){
   for(int i=0;i<h;i++){
     
           if(s[i][j]=='.'){
              q[i]++;
           }else q[i]=0;

            r[i][j]=q[i];
       }
   }
   int ans=-1;
     for(int j=0;j<w;j++){
   for(int i=0;i<h;i++){
       if(s[i][j]=='.')ans=max(ans,u[i][j]+d[i][j]+r[i][j]+l[i][j]-3);
       
   }}
   cout<<ans;
   

      return 0;

}


Measured memory_bytes: 129408
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

typedef long long ll;

const ll MOD = 1e9 + 7;

class ECoinsRespawn {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, M, P;
	    in >> N >> M >> P;
	    vector<int> A(M), B(M), C(M);
	    REP(i,0,M) in >> A[i] >> B[i] >> C[i];

        vector<ll> minDistance(N+1, LLONG_MAX);
        minDistance[1] = 0;
        int updateCount = 0;
        bool canUpdateNForever = false;
        while (true) {
            bool update = false;
            bool updateN = false;
            REP(i,0,M) {
                if (minDistance[A[i]] != LLONG_MAX && minDistance[B[i]] > minDistance[A[i]] + (-C[i] + P)) {
                    minDistance[B[i]] = minDistance[A[i]] + (-C[i] + P);
                    update = true;
                    if (B[i] == N) updateN = true;
                }
            }
            if (updateCount > N) {
                if (updateN) canUpdateNForever = true;
            }
            if (!update || updateCount > 2*N) break;
            updateCount++;
        }
        ll answer = 0;
        if (updateCount > N && canUpdateNForever) {
            answer = -1;
        } else if (minDistance[N] >= 0) {
            answer = 0;
        } else {
            answer = -minDistance[N];
        }
//        REP(i,0,N) out << minDistance[i] << " ";
//        out << "\n";
        out << answer << "\n";
	}
};


int main() {
	ECoinsRespawn solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    string ns = 'R' + s + 'L';
    ll cnt = 0;
    reps(i, 1, n + 1) {
        ll dir;
        if (ns[i] == 'R') {
            dir = 1;
        }
        else {
            dir = -1;
        }
        if (ns[i] != ns[i + dir]) cnt++;
    }
    cnt = max(1LL, cnt - k * 2);
    cout << (n - cnt) << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	cin>>n;
	ll k=1;
	ll i=1;
	ll j=n;
	ll s=sqrt(n);
	//cout<<s<<endl;
	while(k<=s){
		if(n%k==0){
			i=k;
			j=n/i;
		}
		k++;
		
		
	}
	cout<<i+j-2<<endl;
}

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

#define VIC ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;
typedef complex<ld> point;
#define endl '\n'
#define matrix vector<vector<ll>>
#define EPS 1e-9
#define X real()
#define Y imag()
#define vec(a, b) ((b) - (a))
#define dot(a, b) ((conj(a) * (b)).real())
#define cross(a, b) ((conj(a) *(b)).imag())
#define lengthsqr(v) (dot(v, v))
#define length(v) ((ld)hypot((v).Y, (v).X))
#define same(a, b) (lengthsqr(vec(a, b)) < EPS)

const int N = 1e5 + 5, inf = 1e9 + 5;
const ll mod = 1e9 + 7;

int ans = -inf, n, val[102][12];
bool a[102][12];

int calc(vector<int>& v)
{
    int cnt[102] = {};
    for (auto it: v)
        for (int j = 0; j < n; j++)
            if (a[j][it])
                cnt[j]++;
    int tot = 0;
    bool good = false;
    for (int i = 0; i < n; i++)
        good |= cnt[i] > 0,
        tot += val[i][cnt[i]];
    if (!good)
        tot = -inf;
    return tot;
}

void solve(int i, vector<int>& v)
{
    if (i == 10)
    {
        ans = max(ans, calc(v));
        return;
    }
    v.push_back(i);
    solve(i + 1, v);
    v.pop_back();
    solve(i + 1, v);
}

int main()
{
    VIC
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 10; j++)
            cin >> a[i][j];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 11; j++)
            cin >> val[i][j];
    }
    vector<int> v;
    solve(0, v);
    cout << ans;
    return 0;
}


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

using namespace std;

int main(){
    string s; cin >> s;
    char c=s[0];
    int ans=0;
    for(int i=1; i<s.size(); ++i){
        if(c==s[i]) continue;
        c=s[i];
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

const ll p=4000;

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

    int H,W,h,w;cin>>H>>W>>h>>w;
    if(H%h==0 and W%w==0){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;

    int k=(H/h)*(W/w);
    int I=H%h,J=W%w;
    int rem=I*W+J*H-I*J;
    vector<vector<ll>> ans(H,vector<ll>(W,p));
    ll mi=(h*w-1)*p+1;
    rep(i,H){
        rep(j,W){
            if((i+1)%h==0 and (j+1)%w==0) ans[i][j]=-mi;
        }
    }
    
    rep(i,H){
        rep(j,W){
            cout<<ans[i][j]<<(j==W-1?'\n':' ');
        }
    }
    return 0;
    

    // assert(false);
    



    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n , x) for (int i = (int)(x); i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 1; --i)
#define repBX(i, n , x) for (int i = (int)(n); i >= int(X); --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N,M;
    cin >> N >> M;
    cout << ((N==M)?"Yes":"No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    pii p[N];
    rep(i, N){
        int A;
        cin >> A;
        p[i] = pii(A, i);
    }
    sort(p, p+N);
    int cnt = 0;
    rep(i, N){
        if(i%2 != p[i].second%2) cnt++;
    }
    cout << cnt/2 << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int solve(int,int);
int n,A[50];

int main(){
  int q,M,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
 for(i=0;i<q;i++)
   {
   scanf("%d",&M);
   if(solve(0,M)) {
     printf("yes\n");
   }
   else printf("no\n");
   }
 return 0;
}


int solve(int i,int m){
  if(m==0){
    return 1;
  }
  
  if(i>=n){
    return 0;
  }
  int res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}



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

//g数组
vector<int>G;
long long cnt;
int A[1000000 + 10];

// 间隔为g的插入排序
void insertionSort(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;
    }
}
//希尔排序
void shellsort(int A[], int n) {
    for (int i = G.size() - 1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    }
}

// 生成g数组
void getArray(int n) {
    for (int h = 1; h <= n;) {
        G.push_back(h);
        h = 3 * h + 1;
    }
}


int main() {

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    getArray(n);
    shellsort(A,n);

    int len = G.size();
    printf("%d\n", len);
    for (int i = len - 1; i >= 0; i--)
        printf("%d%c", G[i], i == 0 ? '\n' : ' ');
    printf("%lld\n", cnt);
    for (int i = 0; i < n; i++)
        printf("%d\n", A[i]);
    return 0;
}



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

int main() {
    int T, D, ta, tb, da, db;
    cin >> T >> D >> ta >> tb >> da >> db;

    double res = 10000;
    for (int i = 0; i <= D / da; i++) {
        for (int j = 0; j <= D / db; j++) {
            if (da * i + db * j > D) continue;
            if (i == j && i == 0) continue;
            res = min(res, fabs((double)T - (double)(ta * da * i + tb * db * j) / (double)(da * i + db * j)));
        }
    }

    printf("%.8f\n", res);

    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 2e9;
  for (int least : a) {
    vector<int> s;
    vector<int> b;
    for (int i = 0; i <= n; i++) {
      if (i == n || a[i] < least) {
        sort(b.begin(), b.end());
        for (int j = 0; j <= (int) b.size() - k; j++) {
          s.push_back(b[j]);
        }
        b.clear();
      } else {
        b.push_back(a[i]);
      }
    }
    if ((int) s.size() < q) {
      continue;
    }
    sort(s.begin(), s.end());
    ans = min(ans, s[q - 1] - least);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {

	var S string

	fmt.Scan(&S)

	flag := true

	flag = flag && (S[0] == 'A')

	flag = flag && (strings.Count(S[2:len(S)-1], "C") == 1)

	flag = flag && (S[1] >= 'a')

	for _, c := range S[len(S)-1:] {
		if c < 'a' {
			flag = false
			break
		}
	}

	if flag {
		fmt.Println("AC")
	} else {
		fmt.Println("WA")
	}
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

template<class T>
class Union_Find {
private:
  T n;
  vector<T> parent;
public:
  Union_Find(T v){
    n=v;
    parent.resize(n,-1);
  }
  T root(T v){
    if(parent[v]<0)return v;
    return parent[v]=root(parent[v]);
  }
  T size(T v){
    return -parent[root(v)];
  }
  bool connect(T a,T b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(size(a)<size(b)) swap(a,b);
    parent[a]+=parent[b];
    parent[b]=a;
    return true;
  }
  bool same(T a,T b){
    return root(a)==root(b);
  }
  T operator[](T a){
    return root(a);
  }
  bool operator()(T a,T b){
    return connect(a,b);
  }
};

int main(){

  int n;
  cin>>n;
  auto a = vec<ll>(n,n);
  cin>>a;

  auto b = a;
  bool is_shortest = true;
  rep(k,n)rep(i,n)rep(j,n){
    if(chmin(a[i][j],a[i][k]+a[k][j]))is_shortest=false;
  }
  if(!is_shortest){
    cout<<(-1)<<endl;
    return 0;
  }

  struct edge{
    ll f,t,c;
    edge(){}
    edge(ll f,ll t,ll c):f(f),t(t),c(c){}
    bool operator< (edge const& rhs){
      return c < rhs.c;
    }
  };
  vector<edge> E;
  E.reserve(n*n);
  rep(i,n)rep(j,n){
    if(i<=j)continue;
    E.emplace_back(i,j,a[i][j]);
  }
  sort(E.begin(),E.end());

  ll ans = 0;
  auto d = _vec<ll>(n,n,INF);
  rep(i,n)d[i][i]=0;
  for(auto e:E){
    if(chmin(d[e.f][e.t],e.c)){
      d[e.t][e.f] = e.c;
      ans += e.c;
      rep(i,n)rep(j,n){
        chmin(d[i][j],d[i][e.f]+d[e.f][j]);
        chmin(d[i][j],d[i][e.t]+d[e.t][j]);
      }
      rep(i,n)rep(j,n){
        chmin(d[i][j],d[i][e.f]+d[e.f][j]);
        chmin(d[i][j],d[i][e.t]+d[e.t][j]);
      }
      rep(i,n)rep(j,n){
        chmin(d[i][j],d[i][e.f]+d[e.f][j]);
        chmin(d[i][j],d[i][e.t]+d[e.t][j]);
      }
    }
  }
  cout<<(ans)<<endl;

}

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

int main(){
    ll a[5], n;
    ll t = 0, i;
    ll m = 1e15;
    cin >> n;
    for(i = 0; i < 5; i++){
        cin >> a[i];
        if(a[i] < m) m = a[i];
    }
    if(n % m == 0){
        cout << 4 + n / m << endl;
    }
    else{
        cout << 4 + n / m + 1 << endl;
    }
}

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

using namespace std;

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

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){
	cin>>n;
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d", &x);
		if (x & 1) cnt ^= 1;
	}
	puts(cnt ? "NO" : "YES");
}

void solve(int casi){

}

void printans(){

}


int main(){
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
	int n, l, s, a;
	char c[4];
	while (1){
		int ans = 0;
		cin >> n;
		if (n == 0000){
			break;
		}
		a = n;
		while (a != 6174){
			for (int i = 0; i < 4; i++){
				c[i] = a % 10;
				a /= 10;
			}
			if (c[0] == c[1] && c[0] == c[2] && c[0] == c[3]){
				cout << "NA" << endl;
				break;
			}
			sort(c, c + 4);
			l = c[0] * 1000 + c[1] * 100 + c[2] * 10 + c[3];
			reverse(c, c + 4);
			s = c[0] * 1000 + c[1] * 100 + c[2] * 10 + c[3];
			a = s - l;
			ans++;
		}
		if (a == 6174){
			cout << ans << endl;
		}
	}
}



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

int main() {
	string S;
	cin >> S;
	if (S == "Sunny") cout << "Cloudy" << endl;
	else if (S == "Cloudy") cout << "Rainy" << endl;
	else if (S == "Rainy") cout << "Sunny" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
int main(){
	int i,n,v,j,k;
	int A[N];
	scanf("%d",&n);
	for(k = 0; k < n;k++)
			scanf("%d",&A[k]);

	for(i = 0; i < n; i++){
		v = A[i];
		j = i - 1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		for(k = 0; k < n;k++){
			printf("%d",A[k]);
			if(k != (n-1))
				printf(" ");
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2064
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static String str1, str2;
	public static void main(String[] args) {
		while(read()){
			
		}
	}
	
	static boolean read(){
		if(!sc.hasNext()) return false;
		n = sc.nextInt();
		for(int i = 0; i < n; i++){
			str1 = sc.next();
			str2 = sc.next();
			solve();
		}
		return true;
	}
	
	static void solve(){
		int sum = calc(str1) + calc(str2);
		System.out.println(restore(sum));
	}
	
	static int value(char letter){
		switch(letter){
		case 'm':
			return 1000;
		case 'c':
			return 100;
		case 'x':
			return 10;
		case 'i':
			return 1;
		default:
			return -100;
		}
	}
	static int calc(String str){
		int ret = 0;
		for(int i = 0; i < str.length(); i++){
			if(Character.isDigit(str.charAt(i))){
				StringBuffer sb = new StringBuffer(str.subSequence(i, i+2));
				int coefficient = sb.toString().charAt(0) - '0';//係数
				char type = sb.toString().charAt(1);
				ret += coefficient*value(type);
				i++;
			}else{
				StringBuffer sb = new StringBuffer(str.subSequence(i, i+1));
				char type = sb.toString().charAt(0);
				ret += value(type);
			}
		}
		return ret;
	}

	static String restore(int value){
		int residue = 0;
		int m = value / 1000;
		residue = value % 1000;
		int c = residue / 100;
		residue = residue % 100;
		int x = residue / 10;
		int i = residue % 10;
		String ret = "";
		if( m != 0 ){
			if( m == 1 ){
				ret += "m";
			}else{
				ret += Integer.toString(m)+"m";
			}
		}
		if( c != 0 ){
			if( c == 1 ){
				ret += "c";
			}else{
				ret += Integer.toString(c)+"c";
			}
		}
		if( x != 0 ){
			if( x == 1 ){
				ret += "x";
			}else{
				ret += Integer.toString(x)+"x";
			}
		}
		if( i != 0 ){
			if( i == 1 ){
				ret += "i";
			}else{
				ret += Integer.toString(i)+"i";
			}
		}
		return ret;
	}
}

Measured memory_bytes: 29560
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;


int main(){
    long long k, t;
    cin >> k >> t;
    vector<long long> v;

    long long maxv = 0;
    for(long long i = 0; i < t; i++){
        long long a;
        cin >> a;
        v.push_back(a);
        if(maxv < a){
            maxv = a;
        }
    }

    cout << max(maxv-1-(k-maxv), (long long)0) << endl;

    return 0;

    
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define _rep(i,j,N) for(int i = (j); i <= (N);i++)
#define _dec(i,j,N) for(int i = (N-1);i >= 0;i--)
#define _dep(i,j,N) for(int i = (N); i>= 0;i--)
#define ALL(x) x.begin(),x.end()
#define LL long long
#define ULL unsigned LL
#define PB push_back

int cnt[5];
int main()
{
    memset(cnt,0,sizeof(cnt));
    _for(i,0,6){
        int num;cin >> num;
        cnt[num]++;
    }

    int cnt1 = 0;
    int cnt2 = 0;
    _rep(i,1,4){
        if(cnt[i] == 1) cnt1++;
        if(cnt[i] == 2) cnt2++;
    }
    if(cnt1 == 2 && cnt2 == 2){
        printf("YES\n");
    }else{printf("NO\n");}
}

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

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

    if(s[2]==s[3] && s[4]==s[5])
      cout << "Yes" << endl;
      else
      cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
constexpr auto MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    int n, q;
    cin >> n >> q;
    int a, b;
    vector<vector<int>> edge(n);
    FOR(i, 0, n - 1) {
        cin >> a >> b;
        edge[--a].push_back(--b);
    }

    VI dis(n, 0);
    vector<bool> ever(n, false);
    queue<pair<int, int>> bfs;
    bfs.push({ 0,0 });
    ever[0] = true;
    while (!bfs.empty()) {
        int now = bfs.front().first;
        int num = bfs.front().second + 1;
        bfs.pop();
        for (auto &next : edge[now]) {
            if (ever[next])continue;
            ever[next] = true;
            dis[next] = num;
            bfs.push({ next,num });
        }
    }

    int p, x;
    VI X(n, 0);
    FOR(i, 0, q) {
        cin >> p >> x;
        X[--p] += x;
    }
    VI cnt(n, 0);
    bfs.push({ 0,X[0] });
    while (!bfs.empty()) {
        int now = bfs.front().first;
        int point = bfs.front().second;
        cnt[now] += point;
        bfs.pop();
        for (auto& next : edge[now]) {
            if (dis[next] < dis[now])continue;
            bfs.push({ next,point + X[next] });
        }
    }

    cout << cnt[0];
    FOR(i, 1, n)cout << " " << cnt[i];
    cout << "\n";
}

Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=200005;
int n,m;
vector<int> G[max_n];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int u,v;scanf("%d%d",&u,&v);
        G[u].push_back(v),G[v].push_back(u);
    }
    for(int i=2;i<n;i++){
        int c=0;
        for(auto v:G[i]){
            if(v==1||v==n)c++;
        }
        if(c==2){
            printf("POSSIBLE\n");
            return 0;
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 12016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    cout << n*(n-1)/2+m*(m-1)/2 << endl;
}

Measured memory_bytes: 256
h,w = gets.strip.split.map(&:to_i)
data = []
ay = Array.new(w+2,".")
data[0] = ay
h.times do
  ax = gets.strip.to_s
  data << ("."+ax+".").split("").map(&:to_s)
end
data[h+1] = ay

for i in 1..h
  for j in 1..w
    if data[i][j] == "."
      as = [data[i-1][j-1],data[i-1][j],data[i-1][j+1],data[i][j-1],data[i][j+1],data[i+1][j-1],data[i+1][j],data[i+1][j+1]]
      t = 0
      for k in 0..7
        if as[k] == "#"
          t += 1
        end
      end
      data[i][j] = t.to_s
    end
  end
end
for i in 1..h
  puts data[i][1..w].join("")
end

Measured memory_bytes: 14448
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n,h; cin >> n >> h;
	vi a(n),b(n);
	rep(i,n) cin >> a[i] >> b[i];
	int mx = 0;
	rep(i,n) mx = max(mx,a[i]);
	SORT(b); REV(b);
	int cnt = 0;
	rep(i,n){
		if(b[i]>mx){
			cnt++;
			h -= b[i];
			if(h<=0){
				cout << cnt << endl;
				return 0;
			}
		}else break;
	}
	cnt += (h+mx-1)/mx;
	cout << cnt << endl;
}


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

using namespace std;

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

    long long t = 0;
    int n;
    cin >> n;
    pair<int, int> p[n];

    for (int i = 0; i < n; i++)
        cin >> p[i].second >> p[i].first;

    sort(p, p + n);

    for (auto x : p) {
        t += 1ll * x.second;
        if (t > 1ll * x.first)
            return cout << "No\n", 0;
    }

    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  int n,i,max=0,sum=0;
  int a[10];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  for(i=0;i<n;i++){
    if(max<a[i]) max=a[i];
  }
  
  for(i=0;i<n;i++)sum+=a[i];
  
  printf("%d\n",sum=sum-max/2);
  return 0;
  
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 != 0) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << (a + b) / 2 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 3005;
const int INF = (LL)1e9 + 5;
const LL MOD = 998244353;

int N, a[MAXN];
LL dp[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int l = N - 1; l >= 0; l--) {
		for (int r = l + 1; r <= N; r++) {
			dp[l][r] = max(a[l] - dp[l + 1][r], a[r - 1] - dp[l][r - 1]);
		}
	}
	
	cout << dp[0][N] << "\n";
}


Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,k,x,y,sum;
    cin>>n>>k>>x>>y;
    for(int i=1;i<n+1;i++){
        sum+=x;
        if(i>k){
            sum+=y-x;
        }
        //cout<<sum<<endl;
    }
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; ++i) arr[i] = fs.nextInt();

        Set<Integer> s = new HashSet<>();
        for (int bit = 0; bit < (1<<n); ++bit) {
            int tmp = 0;
            for (int i = 0; i < n; ++i) {
                if ((bit & (1<<i)) != 0)
                    tmp += arr[i];
            }
            s.add(tmp);
        }

        int q = fs.nextInt();
        for (int i = 0; i < q; ++i) {
            int val = fs.nextInt();
            if (s.contains(val))
                System.out.println("yes");
            else
                System.out.println("no");
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}






























Measured memory_bytes: 44220
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long X = GetLong();
		long Y = GetLong();
		long Z = GetLong();
		long K = GetLong();
		var A = GetLongs(X);
		var B = GetLongs(Y);
		var C = GetLongs(Z);

		var AB = new List<long>();
		for(long i = 0; i < X; i++)
		{
			for(long j = 0; j < Y; j++)
				AB.Add(A[i] + B[j]);
		}
		AB.Sort((x, y) => y.CompareTo(x));

		var ABC = new List<long>();
		for(int i = 0, E = (int)Min(K, AB.Count); i < E; i++)
		{
			for(int j = 0; j < Z; j++)
				ABC.Add(AB[i] + C[j]);
		}
		ABC.Sort((x, y) => y.CompareTo(x));
		WriteLine(string.Join("\n", ABC.Take((int)K)));
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 67736
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int h,w;
    cin>>h>>w;
    vector<string> hoge(h);
    for(int i=0;i<h;i++) cin>>hoge.at(i);
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(hoge.at(i).at(j)=='.'){
                char cnt='0';
                for(int k=i-1;k<=i+1;k++){
                    for(int l=j-1;l<=j+1;l++){
                        if(k>=0 && k<h && l>=0 && l<w){
                            if(hoge.at(k).at(l)=='#') cnt++;
                        }
                    }
                }
                hoge.at(i).at(j)=cnt;
            }
            
            cout<<hoge.at(i).at(j);
        }
        cout<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline


INF = pow(10,9)

# @njit
def solve(n,s):
  cum = [0]*(n+1)
  for i in range(n):
    cum[i+1] = cum[i] + (s[i] == "W")
  res = INF
  for i in range(n):
    w_inLeft = cum[i] - cum[0]
    e_inRight = n - i - 1 - cum[n] + cum[i+1]
    res = min(res,w_inLeft+e_inRight)
  return res



def main():
  N = int(input())
  S = input()
  print(solve(N,S))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 20976