akhauriyash/Code-Regression huggingface dataset:
// ===== 2018/06/02 20:24:27 =====

// ../../../lib/template/includes.hpp

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>

// ../../../lib/template/const_value.hpp

template <typename T> constexpr T inf();
template <> constexpr int inf<int>() { return 1e9; }
template <> constexpr long long inf<long long>() { return 1e18; }
template <> constexpr long double inf<long double>() { return 1e30; }

template <typename T>
constexpr typename std::enable_if<std::is_arithmetic<T>::value, T>::type
zero() {
  return T(0);
}

const long double pi = acos(-1.0);

// ../../../lib/template/initialize.cpp

struct yes_no : std::numpunct<char> {
  string_type do_truename() const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

struct Initialize {
  Initialize() {
    std::locale loc(std::locale(), new yes_no);
    std::cout << std::boolalpha << std::setprecision(11) << std::fixed;
    std::cout.imbue(loc);
  }
};

const Initialize init;

// ../../../lib/template/macros.hpp

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

// ../../../lib/template/misc.hpp

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

// ../../../lib/template/range.hpp

class range {
  class index_type {
    int x;

  public:
    index_type(int x_) : x(x_) {}
    int operator*() const { return x; }
    bool operator!=(index_type &r) { return x < r.x; }
    void operator++() { ++x; }
  };
  index_type i, n;

public:
  range(int n_) : i(0), n(n_) {}
  range(int i_, int n_) : i(i_), n(n_) {}
  index_type &begin() { return i; }
  index_type &end() { return n; }
};

// ../../../lib/template/typedef.hpp

using ll = long long;
using ld = long double;
using Point = std::complex<ld>;

// ../../../lib/template/template.cpp

using namespace std;

// B.cpp

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

void solve(ll N, string S) {
  int res = 0;
  REP(i,N) {
    set<char> s1, s2;
    REP(j,N) {
      if (j < i) s1.insert(S[j]);
      else s2.insert(S[j]);
    }
    int cnt = 0;
    for (char c: s1) {
      if (s2.find(c) != end(s2)) ++cnt;
    }
    chmax(res, cnt);
  }
  cout << res << endl;
}

int main() {
	string S;
	ll N;
	scanf("%lld", &N);
	cin >> S;
	solve(N, S);
	return 0;
}
// ===== 2018/06/02 20:24:27 =====



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    int n, m;
    cin >> n >> m;
    int t = 1900 * m + 100 * (n - m);
    double p = pow(1.0 / 2, m);
    double ans = 0.0;
    rep(i, (int)1e5) {
        ans += (i + 1) * t * pow(1 - p, i) * p;
    }
    cout << (int)(ans + 0.001) << endl;
}

Measured memory_bytes: 4140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define endl "\n"
using Edge = pair<int,ll>;
using Graph = vector<vector<Edge>>;
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; }
// 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;}

int main(void){
  ll a,b,c,x,y; cin >> a >> b >> c >> x >> y;
  ll ans = 1001001001001001;
  FOR(i,0,100000){
    ll price = c*i*2;
    price += a*(max(0LL,x-i)) + b*(max(0LL,y-i));
    chmin(ans,price);
  }

  cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(4e5)+10;
const ll mod=998244353;
int n,e[maxn*2],tot,s1[maxn],s2[maxn];
int cnt[maxn];
struct node {
	int x,y,id;
} d[maxn];
ll mi[maxn],ans[maxn],s;
bool cmp(node a,node b) { return a.x<b.x; }
void F(int &a) {
	a=lower_bound(e+1,e+tot+1,a)-e;
}
int tr[maxn*2];
void add(int x) {
	for (;x<=tot;x+=x&(-x)) tr[x]++;
}
int query(int x) {
	int res=0;
	for (;x>0;x-=x&(-x)) res+=tr[x];
	return res;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) {
		read(d[i].x),read(d[i].y),d[i].id=i;
		e[++tot]=d[i].x;
		e[++tot]=d[i].y;
	}
	sort(e+1,e+tot+1);
	tot=unique(e+1,e+tot+1)-e-1;
	for (int i=1;i<=n;i++)
		F(d[i].x),F(d[i].y);
	//for (int i=1;i<=n;i++)
	//	printf("%d %d\n",d[i].x,d[i].y);
	//printf("\n");
	mi[0]=1;
	for (int i=1;i<=n;i++)
		mi[i]=mi[i-1]*2%mod;
	for (int i=1;i<=n;i++)
		cnt[d[i].x]++;
	for (int i=1;i<=tot;i++)
		s1[i]=s1[i-1]+cnt[i];
	for (int i=tot;i>=1;i--)
		s2[i]=s2[i+1]+cnt[i];
	for (int i=1;i<=n;i++)
		ans[i]+=mi[s1[d[i].x-1]]+mi[s2[d[i].x+1]];
	memset(cnt,0,sizeof(cnt));
	for (int i=1;i<=n;i++)
		cnt[d[i].y]++;
	for (int i=1;i<=tot;i++)
		s1[i]=s1[i-1]+cnt[i];
	for (int i=tot;i>=1;i--)
		s2[i]=s2[i+1]+cnt[i];
	for (int i=1;i<=n;i++)
		ans[i]+=mi[s1[d[i].y-1]]+mi[s2[d[i].y+1]],
		ans[i]%=mod;
	sort(d+1,d+n+1,cmp);
	int tmp;
	for (int i=1;i<=n;i++) {
		tmp=query(d[i].y);
		ans[d[i].id]-=mi[tmp]+mi[i-1-tmp];
		add(d[i].y);
	}
	memset(tr,0,sizeof(tr));
	reverse(d+1,d+n+1);
	for (int i=1;i<=n;i++) {
		tmp=query(d[i].y);
		ans[d[i].id]-=mi[tmp]+mi[i-1-tmp];
		add(d[i].y);
	}
	for (int i=1;i<=n;i++) {
		ans[i]=(ans[i]%mod+mod)%mod;
		s+=mi[n]-ans[i]-1;
		s=(s%mod+mod)%mod;
		//printf("%d %lld\n",i,ans[i]);
	}
	printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 20736
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  long long A, B, C, D;
  long long CD;
  long long inv_ans = 0;
  cin >> A >> B >> C >> D;

  long long a = C, b = D;
  long long tmp = b % a;
  while (tmp != 0) {
    b = a;
    a = tmp;
    tmp = b % a;
  }
  CD = (C * D) / a;


  inv_ans += (B / C) - ((A - 1) / C);
  inv_ans += (B / D) - ((A - 1) / D);
  inv_ans -= (B / CD) - ((A - 1) / CD);
  cout << (B - A + 1) - inv_ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

int main() {
    ll n;
    cin >> n;
    ll count = 0;
    ll min = 0;
    ll p;
    for (ll i = 0; i < n; ++i) {
        cin >> p;
        if (i == 0) {
            ++count;
            min = p;
        } else {
            if (p <= min) {
                ++count;
                min = p;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()	{
  int a, b, c;
  cin >> a >> b;
  c = a + b;
  if (a % 3 == 0 || b % 3 == 0 || c % 3 == 0)	{
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define db double
int n;
struct ddd{
    db x, y, ang;
    bool operator < (const ddd &a)const{
        return ang < a.ang;
    }
    db len(){
        return x * x + y * y;
    }
}vec[311], ans, now;
int main(){
    //printf("%.4lf\n", atan2(1, 0) / 3.1415926);
    cin>>n;
    for(int i = 1;i <= n; i++){
        cin>>vec[i].x>>vec[i].y;
        vec[i].ang = atan2(vec[i].y, vec[i].x);
    }
    sort(vec + 1, vec + 1 + n);
    for(int i = 1;i <= n; i++)vec[i+n] = vec[i];
    for(int i = 1;i <= n; i++){
        now = (ddd){0, 0};
        for(int j = i;j < n + i; j++){
            now.x += vec[j].x;
            now.y += vec[j].y;
            if(now.len() > ans.len())ans = now;
        }
    }
    //printf("x=%.4lf y=%.4lf\n", ans.x, ans.y);
    printf("%.30lf\n", sqrt(ans.len()));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

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

  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    if(flag[x]==1){
      flag[y]=1;
    }
    if(c[x]==1) flag[x]=0;
    c[x]--;
    c[y]++;
  }

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

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
using namespace std;
int n,cnt;
int m[101],p[101][101];
int k,l[101];
int main(){
  while(cin>>n&&n!=0){
    int ans=0;
    cnt=0;
    for(int i=0;i<n;i++){
      cin>>m[i];
      for(int j=0;j<m[i];j++){
        cin>>p[i][j];
      }
      sort(p[i],p[i]+m[i]);
    }
    cin>>k;
    for(int i=0;i<k;i++){
      cin>>l[i];
    }
    sort(l,l+k);
    for(int i=0;i<n;i++){
      int cp=0;
      for(int j=0;j<m[i];j++){
        if(cp==k)break;
        if(l[cp]==p[i][j]){
          cp++;
        }
      }
      if(cp==k){
          cnt++;
          ans=i;
      }
    }
    if(cnt!=1)cout<<-1<<endl;
    else cout<<ans+1<<endl;
  }
}

Measured memory_bytes: 1220
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int h, w;
  readf("%s %s\n", &h, &w);
  auto m = new char[][](h, w);
  auto f = new bool[][](h, w);
  foreach (i; 0..h) {
    m[i] = readln.chomp.to!(char[]);
    if (m[i].count!(x=>x=='.') == w) {
      f[i][] = true;
    }
  }

  foreach (i; 0..w) {
    int cnt;
    foreach (j; 0..h) {
      if (m[j][i] == '.') {
        cnt++;
      }
    }
    if (cnt == h) {
      foreach (j; 0..h) {
        f[j][i] = true;
      }
    }
  }
  foreach (i; 0..h) {
    int cnt;
    foreach (j; 0..w) {
      if (f[i][j]) continue;
      m[i][j].write;
      cnt++;
    }
    if (cnt) {
      writeln("");
    }
  }
}


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

const int DIM = 1e5 + 5;

long long psm[DIM], dp1[DIM], dp2[DIM];

int main( void ) {
    
    int n, k;
    cin >> n >> k;
    
    for( int i = 1; i <= n; i ++ ) {
        cin >> psm[i];
        psm[i] += psm[i - 1];
    }
    
    for( int i = 1; i <= n; i ++ )
        dp1[i] = dp1[i - 1] + max( psm[i] - psm[i - 1], 0LL );
    for( int i = n; i >= 1; i -- )
        dp2[i] = dp2[i + 1] + max( psm[i] - psm[i - 1], 0LL );
    
    long long ans = 0;
    for( int i = 1, j = k; j <= n; i ++, j ++ )
        ans = max( ans, dp1[i - 1] + dp2[j + 1] + max( psm[j] - psm[i - 1], 0LL ) );
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;



int main()
{
    int n;
    scanf("%d",&n);
    char s[100];
    int a[4];
    a[0]=0;
    a[1]=0;
    a[2]=0;
    a[3]=0;
    
    for(int i=0;i<n;i++)
    {
        scanf("%s",s);
        if(s[0]=='A')
        {
            a[0]=a[0]+1;
        }
        else if(s[0]=='W')
        {
            a[1]=a[1]+1;
        }
        else if(s[0]=='T')
        {
            a[2]=a[2]+1;
        }
        else if(s[0]=='R')
        {
            a[3]=a[3]+1;
        }
    }

    printf("AC x %d\n",a[0]);
    printf("WA x %d\n",a[1]);
    printf("TLE x %d\n",a[2]);
    printf("RE x %d\n",a[3]);
    return 0;
}

Measured memory_bytes: 1724
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n;
    cin >> n;
    lli cnt = 0;
    bool c = false;
    rep(i,n){
        lli d, e;
        cin >> d >> e;
        if(d==e){
            cnt++;
        }
        else{
            cnt = 0;
        }
        if(cnt>=3){
            c = true;
            cnt = 0;
            break;
        }
    }
    Yes(c);
}

Measured memory_bytes: 3636
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int A = sc.nextInt();
   int B = sc.nextInt();
   int C = sc.nextInt();
 
   int[] aaa = {A,B,C};
   Arrays.sort(aaa);
   
   int sum = 0;
   sum+= aaa[2]-aaa[1];
   if((aaa[1]-aaa[0])%2==1) sum+=2+(aaa[1]-aaa[0])/2;
   else sum+=(aaa[1]-aaa[0])/2;
   
   System.out.println(sum);
 }
}

Measured memory_bytes: 22868
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

void adjust( string &str )
{
	for ( unsigned int i = 0; i < str.length(); i++ )
	{
		if ( str[i] == ',' )
		{
			str[i] = ' ';
		}
	}

	return;
}

int main()
{
	string buffer;
	map<int,int> count;
	set<int> last, current;

	while ( true )
	{
		getline( cin, buffer );

		if ( buffer.length() == 0 )
		{
			break;
		}

		int number, date;
		
		adjust( buffer );

		istringstream( buffer ) >> number >> date;

		count[ number ]++;
		last.insert( number );
	}

	while ( cin >> buffer )
	{
		int number, date;
		
		adjust( buffer );
		
		istringstream( buffer ) >> number >> date;

		count[ number ]++;
		current.insert( number );
	}

	for ( map<int,int>::iterator it = count.begin(); it != count.end(); it++ )
	{
		if ( last.find( (*it).first ) != last.end() && current.find( (*it).first ) != current.end() )
		{
			cout << (*it).first << ' ' << count[ (*it).first ] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

constexpr long long MOD = 1e9 + 7;
long long fac[400010];
long long inv[400010];

long long pow_mod(long long n, long long p) {
    long long ret = 1;
    while (p > 0) {
        if (p & 1) ret = (ret * n) % MOD;
        n = (n * n) % MOD;
        p >>= 1;
    }
    return ret;
}

void prepare() {
    fac[0] = fac[1] = 1LL;
    inv[0] = inv[1] = 1LL;
    for (long long i = 2; i <= 400000; i++) {
        fac[i] = fac[i - 1] * i;
        fac[i] %= MOD;
        inv[i] = pow_mod(fac[i], MOD - 2LL);
    }
}

long long ncr_mod(long long n, long long r) {
    return fac[n] * inv[n - r] % MOD * inv[r] % MOD;
}

int main() {

    long long H, W, A, B;
    cin >> H >> W >> A >> B;

    prepare();

    long long ans = 0;

    for (long long w = B; w < W; w++) {
        long long w1 = w;
        long long h1 = (H - A - 1);
        long long sum1 = ncr_mod(w1 + h1, w1);
        long long w2 = W - w1 - 1;
        long long h2 = A - 1;
        long long sum2 = ncr_mod(w2 + h2, w2);
        ans += (sum1 * sum2) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}





























































Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

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

  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define Pll pair<ll,ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll,ll>

const ll inf=1e18;
const ll maxs = 100005;
const ll mod = 1e9+7;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line cout<<endl;
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mst(x,a) memset(x,a,sizeof(x))

ll a[maxs];
ll n;
ll dp[3002][3002]; // just reduce size before run;

ll solve(ll l,ll r)
{
    if(dp[l][r]!=-1) 
        return dp[l][r];
  	if(l==r+1)
      	return max(a[l],a[r]);
  
    if(l==r)
    {
        return dp[l][r] = a[l];
    }
    ll left = a[l] - solve(l+1,r);
    ll right = a[r] - solve(l,r-1);
    
    return dp[l][r] = max(left,right);
}

int main(){
    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    memset(dp,-1,sizeof dp);
	solve(0,n-1);
	cout<<dp[0][n-1];
	return 0;
}

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

// ABC122A - Double Helix
// https://atcoder.jp/contests/abc122/tasks/abc122_a
void ABC122A() {
	string b;
	cin >> b;

	if (b == "A") {
		cout << "T" << endl;
	}
	else if (b == "T") {
		cout << "A" << endl;
	}
	else if (b == "C") {
		cout << "G" << endl;
	}
	else {
		cout << "C" << endl;
	}
}

int main() {
	ABC122A();

	return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main
{
	static InputReader in;    
	static PrintWriter out;  
	
	
	/**
     * @param args
     * @throws IOException
     */
	
    public static void main(String[] args) throws IOException
    {
    	in = new InputReader(System.in);    
        out = new PrintWriter(System.out);
        
        String n=in.next();
        int count=0,sum=0;
        int l=n.length();
        
        for(int i=1;i<l;i++)
        {
        	if(n.charAt(i)!='9')
        	{
        		count=i;
        		break;
        	}
        }
        
        if(count==0)
        {
        	if(l==1)
        		out.println(n);
        	else
        	{
        		for(int i=0;i<l;i++)
        		{
        			sum+=(int)n.charAt(i)-48;
        		}
        		out.println(sum);
        	}
        }
        else
        {
        	sum=((int)n.charAt(0)-49)+(l-1)*9;
        	out.println(sum);
        }
        
        out.close();
    }

	static class InputReader {    
        BufferedReader br;    
    
        public InputReader(InputStream stream) {    
            br = new BufferedReader(new InputStreamReader(stream));    
        }    
    
        public int nextInt() throws IOException {    
            int c = br.read();    
            while (c <= 32) {    
                c = br.read();    
            }    
            boolean negative = false;    
            if (c == '-') {    
                negative = true;    
                c = br.read();    
            }    
            int x = 0;    
            while (c > 32) {    
                x = x * 10 + c - '0';    
                c = br.read();    
            }    
            return negative ? -x : x;    
        }    
    
        public long nextLong() throws IOException {    
            int c = br.read();    
            while (c <= 32) {    
                c = br.read();    
            }    
            boolean negative = false;    
            if (c == '-') {    
                negative = true;    
                c = br.read();    
            }    
            long x = 0;    
            while (c > 32) {    
                x = x * 10 + c - '0';    
                c = br.read();    
            }    
            return negative ? -x : x;    
        }    
    
        public String next() throws IOException {    
            int c = br.read();    
            while (c <= 32) {    
                c = br.read();    
            }    
            StringBuilder sb = new StringBuilder();    
            while (c > 32) {    
                sb.append((char) c);    
                c = br.read();    
            }    
            return sb.toString();    
        }    
    
        public double nextDouble() throws IOException {    
            return Double.parseDouble(next());    
        }    
    }
}


Measured memory_bytes: 21204
#include <stdio.h>

int main()
{
    int n_red = 0, n_blue = 0;
    char c;
    while (1)
    {
        scanf("%c", &c);
        if (c == '0')
            n_red++;
        else if (c == '1')
            n_blue++;
        else
            break;
    }

    int ans = n_red > n_blue ? 2 * n_blue : 2 * n_red;

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;

int main()
{
	int N;

	cin >> N;

	vector<int> Xs(N,0);

	for (int ni = 0; ni < N; ni++) {
		cin >> Xs[ni];
	}

	vector<int> Xs_s = Xs;
	sort(Xs_s.begin(), Xs_s.end());

	int mid_l = Xs_s[N/2-1];
	int mid_r = Xs_s[N / 2];


	for (int ni = 0; ni < N; ni++) {
		if (Xs[ni] < mid_r) {
			cout << mid_r << endl;
		}
		else {
			cout << mid_l << endl;
		}
	}
		


	//printf("%.9f", ans);
	//std::cout << "Yes";

	return 0;
}



Measured memory_bytes: 3712
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    string s1, s2;
    while ( cin >> s1 >> s2 ) {
        if ( s1.size() > s2.size() ) {
            swap( s1, s2 );
        }
        int lcss = 0;
        int L1 = s1.size();
        int L2 = s2.size();
        for ( int i = -L1-L1; i < L1 + L1; ++ i ) {
            int css = 0;
            for ( int j = 0; j < L2; ++ j ) {
                if ( i + j < 0 || i + j >= L1 ) continue;
                if ( s1[i + j] == s2[j] ) {
                    css ++;
                    lcss = max( lcss, css );
                } else {
                    css = 0;
                }
            }
        }
        cout << lcss << endl;
    }
    return 0;
}

Measured memory_bytes: 940
def mod_inverse(x, mod):
    return pow(x, mod - 2, mod)


# return nCk % mod
# it takes O(k)
def mod_comb(n, k, mod):
    numer, denom = 1, 1
    for i in range(k):
        numer = numer * ((n - i) % mod) % mod
        denom = denom * ((i + 1) % mod) % mod

    return numer * mod_inverse(denom, mod) % mod


mod = 10**9 + 7
N, K = map(int, input().split())

for i in range(1, K + 1):
    a = mod_comb(N - K + 1, i, mod)
    b = mod_comb(K - 1, i - 1, mod)
    print(a * b % mod)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    
    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0])cout << "YES" << endl;
    else cout << "NO" << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class ITP1
{
    static void Main()
    {
                int a = int.Parse(Console.ReadLine());
                for (int i = 1; i <= a; i++)
                {
                    if (i % 3 == 0 || i % 10 == 3 ||
           i / 10 == 3 || i / 100 == 3 || i / 1000 == 3 ||
           i % 100 / 10 == 3 || i % 1000 / 100 == 3)
                    {
                            Console.Write(" "+i);
                    }
                }
                Console.Write("\n");
    }
}

Measured memory_bytes: 5800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> range(n);//(end,begin)
    for (ll i = 0; i < n;i++){
        ll x, l;
        cin >> x >> l;
        range[i].first = x + l;
        range[i].second = x - l;
    }
    sort(range.begin(), range.end());
    ll ans = 0;
    ll now = -INF;
    for (ll i = 0; i < n; i++) {
		if(now<=range[i].second){
            ans++;
            now = range[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4772
#include <iostream>
#include <cstdio>

using namespace std;
const int max_n = 100000;
int par[max_n * 2];
bool marked[max_n * 2];
typedef long long ll;

void init(int n) {
    for(int i = 0; i < n; i++) {
        par[i] = i;
        marked[i] = false;
    }
    marked[0] = true;
}

int find(int x) {
    if(marked[x]) return x;
    else return find(par[x]);
}


int main() {
    while(true) {
        int n, q;
        ll sum = 0;
        cin >> n >> q;
        init(n);
        if(n == 0 && q == 0) break;

        for(int i = 0; i < n - 1; i++) {
            int x;
            cin >> x;
            x--;
            par[i + 1] = x;
        }

        for(int i = 0; i < q; i++) {
            char qt;
            int x;
            cin >> qt >> x;
            x--;
            if(qt == 'M') {
                marked[x] = true;
            } else {
                sum += find(x);
                sum++;
            }
        }

        cout << sum << endl;
    }

    return 0;
}

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

int main(){
	string buf;
	while(cin >> buf){
		string res = "";
		bool f = false;
		for(int i = 0;i < buf.size();++i){
			if(f){
				f = false;
				int c = buf[i] - '0';
				++i;
				for(int j = 0;j < c;++j){
					res += buf[i];
				}
			}
			else if(buf[i] != '@'){
				res += buf[i];
			}
			else{
				f = true;
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli  long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=998244353;
lli inf=9223372036854775807;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
#define UNASSIGNED 0  
//&& + - ! ~ ++ - - ()
lli ani;
int main()
{
	lli n,k;
	cin>>n>>k;
	lli temp[n];
	for(lli i=0;i<n;i++)cin>>temp[i];
	sort(temp,temp+n);
	for(lli i=0;i<k;i++)ani+=temp[i];
	cout<<ani;
	
	
	
	
	
 
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
template< typename T >
T mod_pow(T x, T n, const T &p) {
  if(x < 0) return 0;
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
using ld = long double;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  map<pair<ll, ll>, ll> mp;
  ll zero = 0;
  ll lzero = 0, rzero = 0;
  for(int i=0;i<(n);++i) {
    ll a, b; cin >> a >> b;
    if(a == 0 || b == 0) {
      if(a == 0 && b == 0) zero++;
      else if(a == 0) lzero++;
      else if(b == 0) rzero++;
      continue;
    }
    if(a < 0) {
      a = -a;
      b = -b;
    }
    ll g = __gcd(abs(a), abs(b));
    a /= g;
    b /= g;
    mp[{a, b}]++;
  }
  ll ans = mod_pow<ll>(2, lzero, MOD);
  ans += mod_pow<ll>(2, rzero, MOD);
  ans %= MOD;
  ans += MOD - 1;
  ans %= MOD;
  map<pair<ll, ll>, bool> sel;
  for(auto &e: mp) {
    pair<ll, ll> b = {e.first.second, -e.first.first};
    if(b.first < 0) {
      b.first = -b.first;
      b.second = -b.second;
    }
    if(sel[e.first] || sel[b]) continue;
    sel[e.first] = true;
    sel[b] = true;
    ll now = 0;
    now += mod_pow<ll>(2, e.second, MOD);
    now %= MOD;
    now += mod_pow<ll>(2, mp[b], MOD);
    now %= MOD;
    now += MOD - 1;
    now %= MOD;
    ans *= now;
    ans %= MOD;
  }
  ans += zero;
  ans %= MOD;
  cout << (ans + MOD - 1) % MOD << endl;
}


Measured memory_bytes: 53632
import sys

input = sys.stdin.readline


def main():
    h, w = map(int, input().split())
    table = [[i == "#" for i in input().strip()] for _ in range(h)]
    table = list(filter(lambda x: sum(x), table))
    table = [[row[i] for row in table] for i in range(w)]
    table = list(filter(lambda x: sum(x), table))
    table = [[row[i] for row in table] for i in range(len(table[0]))]
    for row in table:
        print("".join(["#" if v else "." for v in row]))


if __name__ == "__main__":
    main()


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, A, B;
signed main() {
    cin >> N >> A >> B;
    cout << N / (A + B) * A + min(A, N % (A + B)) << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#define ll long long int

int main(){
int h1,m1,h2,m2,d;
scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&d);
int hminutes = (h2-h1) * 60;
int mminutes = m2-m1;
int tminutes = hminutes + mminutes;
int res = tminutes - d;
printf("%d",res);
return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll a,b,c,d;
  cin >> a>> b>> c >> d;
  a--;
  ll total = b-a;
  ll c1 = b / c;
  ll d1 = b / d;
  ll c2 = a / c;
  ll d2 = a / d;
  ll gcdcd = gcd(c, d);
  ll c3 = c / gcdcd;
  ll d3 = d / gcdcd;
  ll cd = c3 * d3 * gcdcd;
  ll cd1 = b / cd;
  ll cd2 = a / cd;
  ll ans = total - c1 - d1 + c2 + d2 + cd1 - cd2;
  print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> s;
  vector<unsigned int> two(s.size() + 1), three(s.size() + 1);
  two[0] = 1;
  three[0] = 1;
  for (size_t i = 1; i <= s.size(); ++i) {
    two[i] = two[i - 1] * 2 % mod;
    three[i] = three[i - 1] * 3 % mod;
  }
  int ans = 0, ones = 0;
  for (size_t i = 0; i < s.size(); ++i) {
    if (s[i] == '1') {
      ans += two[ones] * 1ll * three[s.size() - 1 - i] % mod;
      ans %= mod;
      ++ones;
    }
  }
  ans += two[ones];
  ans %= mod;
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 1232
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
const ll MOD=1e9+7;
const ll INF=1e15;
ll dp[4123][4123];
ll ar[4123][4123];
int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<ll> w(n),sum(n+1);
  rep(i,n){
    cin>>w[i];
    sum[i+1]=sum[i]+w[i];
  }
  
  fill(dp[0],dp[0]+4123*4123,INF);
  rep(i,n){
    dp[i][i+1]=0;
    ar[i][i+1]=i;
  }
  rep(d,n+1)if(d>1){
    rep(i,n-d+1){
      int l,r;
      l= ar[i][i+d-1];
      r= ar[i+1][i+d];
      //l=i; r=i+d;
      for(int k=l;k<=r;++k)
	if(dp[i][i+d]>dp[i][k]+dp[k][i+d]){
	  ar[i][i+d]=k;
	  dp[i][i+d]=dp[i][k]+dp[k][i+d];
	}
      dp[i][i+d]+=sum[i+d]-sum[i];
    }
  }
  //rep(i,n+1){rep(j,n+1)cout<<dp[i][j]<<",";cout<<endl;}
  //rep(i,n+1){rep(j,n+1)cout<<ar[i][j]<<",";cout<<endl;}
  cout<<dp[0][n]<<endl;
  return 0;
}

Measured memory_bytes: 213984
N, M, C = map(int,input().split())
B = list(map(int,input().split()))
ans = 0
for k in range(N):
    A = list(map(int,input().split()))
    t = C
    for l in range(M):
        t += A[l]*B[l]
    if t > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string.h>

#include<vector>
#include<map>
#include<math.h>
#include<stack>
#include<unordered_map>

using namespace std;
int n,h,l,r;
const int N = 1e6;
int arr[N];
const int M = 3000;
unsigned long long dp[N];
const int MAX = 1e9;
int main() {
   int n, k; cin >> n >> k;
   int h[n];
   for (int i = 0; i < n; i ++) cin >> h[i];

   memset(dp, 1e5, sizeof(dp));
   dp[0] = 0;
   for (int i = 1; i <= k; i ++) {
       dp[i] = abs(h[i] - h[0]);
   }
//   for (int i = 0; i < n; i ++) {
//       cout << dp[i] << " " << endl;
//   }
   // dp[1] = 20
   // dp[2] = 30
   // dp[3] =  40

   // 10 -> 30 -> 40
   //
   for (int i = k + 1; i < n; i ++) {
//       cout << "i is " << i << endl;
       for (int j = 1; j <= k; j ++) {
           dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
           // dp[4] =
//           cout << dp[i] << endl;
       }
   }


   // dp[4] = 40 + 30 = 70
   //

   cout << dp[n - 1];


    return 0;
}

Measured memory_bytes: 8960
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;

const int MAXN = 300000 + 10;

int N, Q;
int sb[MAXN], zerob[MAXN];
int b[MAXN];
vector <int> p[MAXN];
int dp[MAXN];
int Tree[MAXN * 4];

void Modify(int Node, int L, int R, int Pos, int x)
{
	if (L == R)
	{
		Tree[Node] = x;
		return;
	}
	int Mid = (L + R) / 2;
	if (Pos <= Mid)
		Modify(Node * 2, L, Mid, Pos, x);
	else
		Modify(Node * 2 + 1, Mid + 1, R, Pos, x);
	Tree[Node] = min(Tree[Node * 2], Tree[Node * 2 + 1]);
}

int Query(int Node, int L, int R, int l, int r)
{
	if (L == l && r == R)
		return Tree[Node];
	int Mid = (L + R) / 2;
	if (r <= Mid)
		return Query(Node * 2, L, Mid, l, r);
	else if (l > Mid)
		return Query(Node * 2 + 1, Mid + 1, R, l, r);
	else
		return min(Query(Node * 2, L, Mid, l, Mid), Query(Node * 2 + 1, Mid + 1, R, Mid + 1, r));
}

void Work()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i ++)
	{
		scanf("%d", &b[i]);
		zerob[i] = zerob[i - 1] + (1 - b[i]);
	}

	scanf("%d", &Q);
	for (int i = 0; i < Q; i ++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		p[l].push_back(r);
	}
	
	dp[0] = 0;
	memset(Tree, 1, sizeof(Tree));
	for (int i = 1; i <= N; i ++)
		dp[i] = 10000000;

	for (int i = 1; i <= N; i ++)
	{
		Modify(1, 0, N, i - 1, dp[i - 1] - zerob[i - 1]);
		for (int j: p[i]) // [i, j]
		{
			// dp[j] <- dp[k - 1] + zerob[j] - zerob[k - 1];
			int tmp = Query(1, 0, N, i - 1, j - 1);
			dp[j] = min(dp[j], zerob[j] + tmp);
			Modify(1, 0, N, j, dp[j] - zerob[j]);
		}
		dp[i] = min(dp[i], dp[i - 1] + (b[i] != 0));
	}
	printf("%d\n", dp[N]);
}

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

Measured memory_bytes: 20608
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    int N,M;
    cin >> N >> M;
    string A[50],B[50];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    for(int i=0; i<M; i++){
        cin >> B[i];
    }
    for(int i=0; i<N-M+1; i++){
        for(int j=0; j<N-M+1; j++){
            bool tmp = true;
            for(int k=0; k<M; k++){
                for(int l=0; l<M; l++){
                    if(A[i+k][j+l] != B[k][l]) tmp = false;
                }
            }
            if(tmp){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import static java.lang.Math.*;
import java.io.PrintWriter;
class Main{
	static Scanner sc = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		while(sc.hasNext()){
			int n = sc.nextInt(), 
				m = sc.nextInt();
			int[] money = new int[m];
			int[] dp = new int[n + 1];
			for(int i= 0; i < m; i++){
				money[i] = sc.nextInt();
			}
			for(int i = 0; i < n + 1; i++){
				dp[i] = 100000;
			}
			dp[0] = 0;
			for(int i = 0; i < m; i++){
				for(int j = money[i]; j < n + 1; j++){
					dp[j] = Math.min(dp[j], dp[j - money[i]]+1);
				}
			}
			System.out.println(dp[n]);
		}

	}
}

Measured memory_bytes: 27656