akhauriyash/Code-Regression huggingface dataset:
/**Bismillahir Rahmanir Rahim.**/

/**
 *    author:  nasimnoob
**/

#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<cstring>
#include<cstdio>

using namespace std;

//----------------------------------------------------------//

typedef long long int                        ll;
typedef unsigned long long int              ull;
typedef long double                          ld;

//-----------------------------------------------------------//
#define      test                       int t; cin>>t;  while(t--)

#define      cube(x)                    (x*x*x)
#define      sqr(x)                     (x*x)

#define      INPUT                      freopen("input.txt", "r", stdin)
#define      OUTPUT                     freopen("output.txt", "w", stdout)

#define      srev                       reverse(s.begin(),s.end())
#define      sortstr                    sort(s.begin(), s.end());
#define      gtl(x)                     getline(cin, (x))
#define      dot(x)                     fixed << setprecision(x)

#define      Case                       cout << "Case " << ++tt << ": " ;

#define      PI                         acos(-1) // 3.1415926535897932
#define      MIN                        9999999
#define      EPS                        (1e-7)

#define      Faster                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);




//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


//--------------------------------------Solution------------------------------//

int main()
{

    #ifndef ONLINE_JUDGE
    clock_t tStart = clock();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    Faster;


    int res = 0 ;
    int cnt = 0 ;

    test
    {
        int a , b ;

        cin >> a >> b ;
        
        if (a == b)
        {
            cnt ++ ;
        }
        else 
            cnt = 0;

        res = max (res , cnt);
    }

    if (res >= 3)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;

    #ifndef ONLINE_JUDGE
    fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif


    return 0 ;
}


Measured memory_bytes: 3644
from heapq import heappush, heappop
inf = float('inf')

# 計算量O((E+V)logV)
# 引数(始点,隣接リスト)
def dijkstra(start,ad):
    global dist
    #global cnt
    N = len(ad)
    dist = [inf] * N
    dist[start] = 0
    #cnt = [0] * N
    #cnt[start] = 1
    pq = [(dist[start], start)]
    while pq:
        dist_v, v = heappop(pq)
        for nv, nw in ad[v]:
            if dist[nv] > dist_v + nw:
                dist[nv] = dist_v + nw
                heappush(pq,(dist[nv], nv))
            #if dist[nv] == dist_v + nw:
                #cnt[nv] += cnt[v]
                #cnt[nv] %= mod

N, M = map(int,input().split())
to = [[] for _ in range(N)]
for _ in range(M):
    L, R, C = map(int,input().split())
    L -= 1; R -= 1
    to[L].append((R, C))

for i in range(1, N):
    to[i].append((i-1, 0))

dijkstra(0, to)

ans = dist[N-1]
if ans == inf:
    ans = -1
print(ans)

Measured memory_bytes: 43860
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint a(n);
    rep(i,n) cin>>a[i];

    vint l(n,0),r(n,0); 
    l[0]=a[0]; r[0]=a[n-1];

    for(int i=1; i<n; i++) l[i]=gcd(l[i-1],a[i]);
    for(int i=1; i<n; i++) r[i]=gcd(r[i-1],a[n-1-i]);
    
    int res=0;
    chmax(res,r[n-2]); chmax(res,l[n-2]);
    for(int i=1; i<n-1; i++){
        int tmp=0;
        //tmp=gcd(l[i-1],r[i-1]);
        tmp=gcd(l[i-1],r[n-1-i-1]);
        chmax(res,tmp);
    }
    // rep(i,n)cout<<"l["<<i<<']'<<l[i]<<endl;
    // rep(i,n)cout<<"r["<<i<<']'<<r[i]<<endl;
    cout<<res<<endl;
}

Measured memory_bytes: 5548
import sys

def check(i,j,s_list,h,w):
    uesita_list = [-1,1]
    sayuu_list = [-1,1]

    for uesita in uesita_list:
        new_i = i + uesita
        if new_i < 0 or new_i > h-1:
            continue
        if s_list[new_i][j] == "#":
            return True

    for sayuu in sayuu_list:
        new_j = j + sayuu
        if new_j > w-1 or new_j < 0:
            continue
        if s_list[i][new_j] == "#":
            return True
    
    return False            


input = sys.stdin.readline

h, w= map(int, input().split())

s_list = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    w_s_list = input()
    w_s_list = w_s_list.replace('\n','')
    w_s_list = list(w_s_list)
    for j in range(w):
        s_list[i][j] = w_s_list[j]


for i in range(h):
    for j in range(w):
        s = s_list[i][j]
        if s == "#":
            ok_flag = check(i,j,s_list,h,w)
            if not ok_flag:
                print("No")
                exit(0)

print("Yes")




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

int main() {
  int k, n = 1;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
  } else {
    int r = 7 % k;
    while(r != 0) {
      r = (10 * r + 7) % k;
      n++;
    }
    cout << n << endl;
  }
}

Measured memory_bytes: 3612
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(long long i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(long long i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1LL<<50);

const string YES = "Yes";
const string NO = "No";
void yn(bool ok){
  cout << (ok ? YES : NO) << endl;
}

void solve(long long N, long long M, std::vector<long long> A){
  Int s = accumulate(ALL(A), 0LL);
  Int x = 0;
  double y = double(s) / double(4*M);
  rep(i, N){
    x += Int(double(A[i]) + 1e-8 > y);
  }
  yn(x >= M);
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, M, std::move(A));
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        String O = sc.nextLine();
        String E = sc.nextLine();
        StringBuilder sb = new StringBuilder();
        for (int i = 0, oi = 0, ei = 0; i < O.length() + E.length(); ++i) {
            if (i % 2 == 1) {
                sb.append(E.charAt(ei));
                ++ei;
            } else {
                sb.append(O.charAt(oi));
                ++oi;
            }
        }
        _out.println(sb);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)

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

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<class Tuple, unsigned Index>
void print_tuple(ostream& os, const Tuple& t) {}

template<class Tuple, unsigned Index, class Type, class... Types>
void print_tuple(ostream& os, const Tuple& t) {
	if(Index > 0) os << ", ";
	os << get<Index>(t);
	print_tuple<Tuple, Index + 1, Types...>(os, t);
}

template<class... Types>
ostream& operator<<(ostream& os, const tuple<Types...>& t) {
	os << '(';
	print_tuple<tuple<Types...>, 0, Types...>(os, t);
	return os << ')';
}

template<class Iterator>
ostream& dump_range(ostream&, Iterator, const Iterator&);

template<typename T>
ostream& operator<<(ostream& os, vector<T> c) {
	return dump_range(os, c.cbegin(), c.cend());
}

template<class Iterator>
ostream& dump_range(ostream& os, Iterator first, const Iterator& last) {
	os << '[';
	for(int i = 0; first != last; ++i, ++first) {
		if(i) os << ", ";
		os << *first;
	}
	return os << ']';
}

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

	for(int n; cin >> n && n;) {
		vector<pair<int, int>> island(n);
		for(int i = 0; i < n; ++i) {
			cin >> island[i].second >> island[i].first;
		}

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

		bool success = true;
		int treasure = 0;
		for(int i = 0; i < n; ++i) {
			treasure += island[i].second;
			if(treasure > island[i].first) {
				success = false;
				break;
			}
		}

		cout << (success ? "Yes" : "No") << endl;
	}

	return EXIT_SUCCESS;
}

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

#define ll       long long
#define ull      unsigned ll
#define pii      pair<int, int>
#define pll      pair<ll, ll>
#define mp       make_pair
#define ff       first
#define ss       second
#define sz(x)    (int) x.size()
#define all(v)   v.begin(), v.end()

template <typename T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <typename T> inline void smax(T &a, T b) {a = a > b ? a : b;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}

template <typename T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l); }

const int mod = (int) 1e9 + 7;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll) a * b % mod;}

const int inf = (int) 2e9 + 5;
const ll  Inf = (ll) 2e18 + 5;
const int N   = (int) 2e5 + 5;



int solve() {
    string s;
    cin >> s;
    printf("%c%c%c\n", s[0], s[1], s[2]);
    return 0;
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int test = 1, tc = 0;
    //Int(test);
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
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 (a>b) { a=b; return true; } return false; }

ll g(ll x){
    return x * (x+1) / 2;
}

int main(){
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans += i * g(n/i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3544
#include<iostream>
#include<cstdio>
using namespace std;
#define N 200012
int n,a[N],P[N],ans=0,f[N];
int main(){
	scanf("%d",&n);int i;for(i=1;i<=n;i++)scanf("%d",&a[i]),P[a[i]]=i;
	for(i=1;i<=n;i++)f[i]=f[P[a[i]-1]]+1,ans=max(ans,f[i]);printf("%d",n-ans);return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll  long long int
#define db long double 
#define ull unsigned long long int
// #define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
// #define INF 10000000000000
#define MOD 1000000007
#define MAXN 200005
 
using namespace std;

ll seg[2][800005];
ll lazy[2][800005];
ll n;

void push(ll i,ll v)
{
	if(lazy[i][v]==-1) return;
	seg[i][2*v]=min(seg[i][2*v],lazy[i][v]);
	seg[i][2*v+1]=min(seg[i][2*v+1],lazy[i][v]);
	if(lazy[i][2*v]!=-1)
	lazy[i][2*v]=min(lazy[i][v],lazy[i][2*v]);
	else
	lazy[i][2*v]=lazy[i][v];
	if(lazy[i][2*v+1]!=-1)
	lazy[i][2*v+1]=min(lazy[i][v],lazy[i][2*v+1]);
	else
	lazy[i][2*v+1]=lazy[i][v];
	lazy[i][v]=-1;
	return;
}

void build(ll v,ll tl,ll tr)
{
	if(tl==tr)
	{
		seg[0][v]=n-1;
		seg[1][v]=n-1;
		return;
	}
	ll tm=(tl+tr)/2;
	build(2*v,tl,tm);
	build(2*v+1,tm+1,tr);
	seg[0][v]=min(seg[0][2*v],seg[0][2*v+1]);
	seg[1][v]=min(seg[1][2*v],seg[1][2*v+1]);

}

void update(ll i,ll v,ll tl,ll tr,ll l,ll r,ll val)
{
	if(l>r) return;
	if(l>tr || tl>r) return;
	if(l<=tl && tr<=r)
	{
		seg[i][v]=min(seg[i][v],val);
		if(lazy[i][v]==-1)
			lazy[i][v]=val;
		else
			lazy[i][v]=min(lazy[i][v],val);
		return;
	}
	push(i,v);
	ll tm=(tl+tr)/2;
	update(i,2*v,tl,tm,l,r,val);
	update(i,2*v+1,tm+1,tr,l,r,val);
	seg[i][v]=min(seg[i][2*v],seg[i][2*v+1]);
}

ll query(ll i,ll v,ll tl,ll tr,ll pos)
{
	if(pos>tr || pos<tl) return 0;
	if(tl==tr)
	{
		return seg[i][v];
	}
	push(i,v);
	ll tm=(tl+tr)/2;
	if(pos<=tm) return query(i,2*v,tl,tm,pos);
	else return query(i,2*v+1,tm+1,tr,pos);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // compute();
    int tests=1;
    // cin>>tests;    
    while(tests--)
    {
    	ll i,j,k,q;
    	cin>>n>>q;
    	memset(lazy,-1,sizeof(lazy));
    	// row-->0 col-->1
    	build(1,1,n);
    	update(0,1,1,n,n,n,1);
    	update(1,1,1,n,n,n,1);
    	ll tot=2*n-1;
    	ll tot2=(n-2)*(n-2);
    	while(q--)
    	{
    		cin>>i>>j;
    		if(i==1)
    		{
    			k=query(1,1,1,n,j);
    			tot+=k;
    			tot2-=max(0LL,k-1);
    			update(0,1,1,n,1,k,j-1);
    		}
    		else
    		{
    			k=query(0,1,1,n,j);
    			tot+=k;
    			tot2-=max(0LL,k-1);
    			update(1,1,1,n,1,k,j-1);
    		}
    		// cout<<k<<"\n";
    	}

    	// cout<<n*n-tot;
    	cout<<tot2;
    }

    return 0;
}
    

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

using namespace std;

typedef long long ll;
const int maxn =2e5 + 1000;
ll pos[maxn];

int n; ll X;

ll get_cost(int num_trips){
  ll ans = X * num_trips + X * n;
  for(int i=0; i<num_trips; i++){
    vector<ll> here;
    here.push_back(0);
    for(int j = i; j < n; j += num_trips){
      here.push_back(pos[j]);
    }
    reverse(here.begin(), here.end());
    ans += here[0];
    for(int e=0;e<here.size()-1;e++){
      ans += (here[e] - here[e+1]) * (e+2) * (e+2);
    }
  }
  return ans;
}

int main(){
  cin >> n;
  cin >> X;
  
  for(int i=0;i<n;i++){
    int t; scanf("%d", &t); pos[i] = t; 
  }
  int lo = 1;
  int hi = n+1;
  while(hi - lo > 2){
    int midL = (hi + 2 * lo) / 3;
    int midR = (2 * hi + lo) / 3;
    ll ansL = get_cost(midL);
    ll ansR = get_cost(midR);
    if(ansL > ansR){
      lo = midL;
    }
    else{
      hi = midR;
    }
  }
  ll ans = 1e18;
  for(int num_trips=lo;num_trips<hi;num_trips++){
    ans = min(ans, get_cost(num_trips));
  }
  cout << ans << "\n";
  /*
  ll ans = 1e18;
  for(int num_trips=1;num_trips<=n;num_trips++){
    ans = min(ans, get_cost(num_trips));
  }
  cout<<ans<<"\n";
  */
}


Measured memory_bytes: 1792
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
tmp1 = list(range(X))
tmp2 = list(range(X+1,N))
ans = []
count = 0
for i in range(len(tmp1)):
    if tmp1[i] in A:
        count += 1
ans.append(count)
count = 0
for j in range(len(tmp2)):
    if tmp2[j] in A:
        count += 1
ans.append(count)
print(min(ans))

Measured memory_bytes: 3064
(function main() {
  let line = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('');
  // 初めの上昇と平坦を除去
  while (line.length > 0 && line[0] !== '\\') line.shift();
  // 終わりの下降と平坦を除去
  while (line.length > 0 && line[line.length - 1] !== '/') line.pop();

  let height_list = [0];
  let current_height = 0;
  line.forEach(function(e, i){
      if (e === '\\') current_height -= 1
      else if (e === '/') current_height += 1
      height_list.push(current_height);
  });

  let h, sum = 0;
  let holes = [];
  for (;height_list.length > 1;) {
    if (h = makeHole(height_list)) {
      sum += h;
      holes.push(h);
    }
  }

  console.log(sum);
  console.log(holes.length && holes.length + ' ' + holes.join(' '));
})();

function makeHole(list) {
    begin = list.shift();
    if (list[0] < begin && begin <= list.reduce((a, b) => Math.max(a, b), -200000)) {
    let area = 0;
      while (!(list.length === 0 || begin <= list[0])) area += begin - list.shift();
      return area;
    }
    return 0;
}



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

int main() {
	int N;
	long long INF = 1000000000000000000;
	cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	if (N % 2 == 0) {
		vector<long long> L(N / 2 + 1), R(N / 2 + 1);
		L[0] = R[N / 2] = 0;
		for (int i = 0; i < N / 2; i++) {
			L[i + 1] = L[i] + A[i * 2];
		}
		for (int i = N / 2; i > 0; i--) {
			R[i - 1] = R[i] + A[i * 2 - 1];
		}
		long long ANS = -INF;
		for (int i = 0; i <= N / 2; i++) {
			ANS = max(ANS, L[i] + R[i]);
		}
		cout << ANS << endl;
		return 0;
	}
	long long ANS = -INF;
	vector<long long> L(N / 2 + 1), R(N / 2 + 1);
	L[0] = R[N / 2] = 0;
	for (int i = 0; i < N / 2; i++) {
		L[i + 1] = L[i] + A[i * 2 + 1];
	}
	for (int i = N / 2; i > 0; i--) {
		R[i - 1] = R[i] + A[i * 2];
	}
	for (int i = 0; i <= N / 2; i++) {
		ANS = max(ANS, L[i] + R[i]);
	}
	long long COUNT = 0;
	for (int i = 0; i < N; i += 2) COUNT += A[i];
	for (int i = 0; i < N; i += 2) ANS = max(ANS, COUNT - A[i]);
	vector<vector<long long> > DP(N, vector<long long>(3, -INF));
	DP[0][0] = A[0];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			if (i + 2 < N) DP[i + 2][j] = max(DP[i + 2][j], DP[i][j] + A[i + 2]);
			if (i + 3 < N && j < 2) DP[i + 3][j + 1] = max(DP[i + 3][j + 1], DP[i][j] + A[i + 3]);
		}
	}
	ANS = max(ANS, DP[N - 1][1]);
	ANS = max(ANS, DP[N - 1][2]);
	cout << ANS << endl;
}

Measured memory_bytes: 17248
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
struct item {
	ll a,b;
	item(ll a=0,ll b=0): a(a),b(b) {}
	friend bool operator <(item A,item B) { return (A.a-1)*B.b>(B.a-1)*A.b; }
}s[N];
int n,T,m;
vector<ll> B;
ll dp[32];
int main() {
	rd(n),rd(T);
	for(int i=1,a,b;i<=n;++i) {
		rd(a),rd(b);
		if(a==0) B.PB(b+1);
		else s[++m]=item(a+1,b+1);
	}
	sort(s+1,s+m+1);
	dp[0]=1;
	for(int i=1;i<=30;++i) dp[i]=2e9;
	for(int i=1;i<=m;++i) {
		for(int j=30;j>=1;--j)
			dp[j]=min(dp[j],dp[j-1]*s[i].a+s[i].b);
	}
	sort(B.begin(),B.end());
	for(int i=1;i<B.size();++i) B[i]+=B[i-1];
	int ans=0;
	for(int i=0;i<=30;++i) if(dp[i]<=T+1) {
		int j=-1;
		while(j+1<B.size() && dp[i]+B[j+1]<=T+1) ++j;
		ans=max(ans,i+j+1);
	}
	printf("%d",ans);
	return 0;
}
	

Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;

ll n,c;


int main(){
    cin >> n >> c;
    vector<ll>x(n),y(n),sxv(n),syv(n),v(n),kx(n),ky(n),ox(n),oy(n);
    rep(i,n)cin>>x[i]>>v[i];
    sxv[0]=v[0];
    rep(i,n-1){
        sxv[i+1]=v[i+1]+sxv[i];
    }
    rep(i,n){
        kx[i]=sxv[i]-x[i];
        ox[i]=kx[i]-x[i];
    }
    rep(i,n){
        y[i]=c-x[i];
    }
    sort(y.begin(),y.end());
    reverse(v.begin(),v.end());
    syv[0]=v[0];
    rep(i,n-1){
        syv[i+1]=syv[i]+v[i+1];
    }
    rep(i,n){
        ky[i]=syv[i]-y[i];
        oy[i]=ky[i]-y[i];
    }
    rep(i,n-1){
        chmax(kx[i+1],kx[i]);
        chmax(ox[i+1],ox[i]);
        chmax(ky[i+1],ky[i]);
        chmax(oy[i+1],oy[i]);
    }
    ll ans = 0;
    rep(i,n-1){
        chmax(ans,ox[i]+ky[n-i-2]);
        chmax(ans,oy[i]+kx[n-i-2]);
    }
    chmax(ans,ky[n-1]);
    chmax(ans,kx[n-1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
bool iskai(string s){
  int m = s.size();
  REP(i,m/2){
    if(s[i] != s[m - i - 1]){
      return false;
    }
  }
  return true;
}
int main()
{
  string a;
  cin >> a;
  int n = a.size();
  bool ok = iskai(a);
  if(!ok){
    cout << "No" << endl;
    return 0;
  }
  string b = a.substr(0,n/2);
  // string c = a.substr(n/2 + 1,n/2);
  ok = iskai(b);
  if(!ok){
    cout << "No" << endl;
    return 0;
  }
  // ok = iskai(c, n/2);
  // if(!ok){
  //   cout << "No" << endl;
  //   return 0;
  // }
  if(n == 3){
    cout << "Yes" << endl;
    return 0;
  }
  int x = (n + 3)/2 - 1;
  int y = (n - 3)/2 + 1;
  string d = a.substr(x, y);
  ok = iskai(d);
  if(!ok){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  // cout << b << endl;
  // cout << d << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
	public static void main(String[] args) throws IOException{
 		BufferedReader br = new BufferedReader(
 			new InputStreamReader(System.in));
 		String s = br.readLine();
 		int idxA =0;
 		for(int i=0; i<s.length(); i++){
 			if(s.charAt(i)=='A'){
 				idxA = i;
 				break;
 			}
 		}
 		int idxZ = s.length()-1;
 		for(int j = s.length()-1; j>=0; j--){
 			if(s.charAt(j) =='Z'){
 				idxZ = j;
 				break;
 			}
 		}
 		System.out.println(idxZ - idxA + 1);
 	}
} 

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

int main()
{
    size_t N;
    cin >> N;

    vector<int> A(N);
    for (int &a : A)
    {
        cin >> a;
    }
    sort(A.begin(), A.end());
    A.push_back(10000000);

    set<int> s;
    int ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        bool has_div = false;
        for (int j = 1; j * j <= A[i]; j++)
        {
            if (A[i] % j == 0)
            {
                if (s.find(j) != s.end())
                {
                    has_div = true;
                    break;
                }
                if (s.find(A[i] / j) != s.end())
                {
                    has_div = true;
                    break;
                }
            }
        }
        if (!has_div)
        {
            if (A[i] != A[i + 1])
            {
                ans++;
            }
        }
        s.insert(A[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 13424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    string s;
    ll K;
    cin >> s >> K;
    
    ll cnt = 0, N = s.size();
    if(N==1){
        cout << K / 2 << endl;
        return 0;
    }else if(N==2){
        if (s[0] == s[1]) cout << K << endl;
        else
            cout << 0 << endl;
        return 0;
    }
    vc<bool> changed(N);
    bool issame = true;
    rep(i,N-1){
        if(s[i]==s[i+1]){
            if (changed[i]) continue;
            changed[i + 1] = true;
            cnt++;
        }else{
            issame = false;
        }
    }
    if(issame){
        cout << N * K / 2 << endl;
        return 0;
    }
    ll ans = 0;
    if (s[0] == s[N - 1] && !changed[0] && !changed[N - 1]){
        ll hcnt = 0, si = 0;
        char a = s[0];
        while(si<N&&s[si]==a){
            hcnt++, si++;
        }
        if (si % 2) ans += K - 1;
    }
    ans += cnt * K;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include<cstring>
#include <math.h>
#include <queue>
typedef long long ll;
using namespace std;

int main()
{
    int n;
    cin>>n;
    int c=n%500;
    int k=n/500;
    int t=c/5;
    cout<<k*1000+t*5;
    return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from itertools import accumulate
from collections import defaultdict

n, m = map(int, input().split())
ary = [int(_) for _ in input().split()]

sum_ary = accumulate(ary, lambda x, y: x + y)
mod_ary = (s % m for s in sum_ary)
mod_table = defaultdict(int)
for mod in mod_ary:
    mod_table[mod] += 1
mod_table[0] += 1

print(sum([mod * (mod - 1) // 2 for mod in mod_table.values()]))


Measured memory_bytes: 14356
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    MOD = 1000000007
    N, *A = map(int, read().split())

    ans = 1
    C = [0] * (N + 1)
    C[0] = 3
    for a in A:
        ans = ans * C[a] % MOD
        C[a] -= 1
        C[a + 1] += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 13956
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        int n=int.Parse(System.Console.ReadLine());
        int[] x=System.Console.ReadLine().Trim().Split(' ').Select(z=>int.Parse(z)).ToArray();
        Array.Sort(x);
        System.Console.WriteLine(x[n-1]-x[0]);
    }
}


Measured memory_bytes: 11348
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int64_t L[90];
  L[0] = 2;
  L[1] = 1;
  for(int i = 2; i <= N; ++i){
    L[i] = L[i-2] + L[i-1];
  }
  cout << L[N] << endl;
}

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

using namespace std;

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};


template< typename T >
T boruvka(int N, function< vector< pair< T, int > >(int, vector< int >) > f) {
  vector< int > rev(N), belong(N);
  UnionFind uf(N);
  T ret = T();
  while(uf.size(0) != N) {
    int ptr = 0;
    for(int i = 0; i < N; i++) {
      if(uf.find(i) == i) {
        belong[i] = ptr++;
        rev[belong[i]] = i;
      }
    }
    for(int i = 0; i < N; i++) {
      belong[i] = belong[uf.find(i)];
    }
    auto v = f(ptr, belong);
    bool update = false;
    for(int i = 0; i < ptr; i++) {
      if(~v[i].second && uf.unite(rev[i], rev[v[i].second])) {
        ret += v[i].first;
        update = true;
      }
    }
    if(!update) return -1; // notice!!
  }
  return ret;
}

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main() {
  int V, E;
  cin >> V >> E;
  Edges< int > g;
  for(int i = 0; i < E; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    g.emplace_back(x, y, z);
  }
  const int INF = 1 << 30;
  function< vector< pair< int, int > >(int, vector< int >) > f = [&](int sz, vector< int > belong) {
    vector< pair< int, int > > ret(sz, {INF, -1});
    for(auto &e : g) {
      if(belong[e.src] == belong[e.to]) continue;
      ret[belong[e.src]] = min(ret[belong[e.src]], make_pair(e.cost, belong[e.to]));
      ret[belong[e.to]] = min(ret[belong[e.to]], make_pair(e.cost, belong[e.src]));
    }
    return ret;
  };
  cout << boruvka(V, f) << endl;
}



Measured memory_bytes: 4496
H, W = map(int, input().split())
S = [input() for _ in range(H)]
from collections import deque
INF = 1001001001
di = [-1, 0, 1, 0]
dj = [ 0,-1, 0, 1]

ans = 0
for si in range(H):
    for sj in range(W):
        if S[si][sj] == '#': continue
        dist = [[INF]*W for _ in range(H)]
        dist[si][sj] = 0
        q = deque([(si, sj)])
        while q:
            i, j = q.popleft()
            for dir in range(4):
                ni = i + di[dir]
                nj = j + dj[dir]
                if (ni<0 or ni>=H or nj<0 or nj>=W): continue
                if S[ni][nj] == '#': continue
                if dist[ni][nj] != INF: continue
                q.append([ni, nj])
                dist[ni][nj] = dist[i][j] + 1
        for i in range(H):
            for j in range(W):
                if dist[i][j] == INF: continue
                ans = max(ans, dist[i][j])
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
int n;
cin>>n;
long long int a[n];
long long int b[n];
for(int i=0;i<n;i++)
 {
  cin>>a[i];
 }

 long long int sum=0;
 b[0]=a[0];
 for(int i=n-2;i>=0;i--)
 { b[i]=a[i];
   a[i]= (a[i]%mod + a[i+1]%mod)%mod;
 }
 b[n-1]=a[n-1];

 long long int ans=0;
 for(int i=0;i<n-1;i++)
 {
   ans +=(  ((a[i+1]%mod) *(b[i]%mod))%mod  );
   ans=ans%mod;
 } 
 cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 6716
N=int(input())
t0,x0,y0=0,0,0
for i in range(N):
    ti,xi,yi = map(int,input().split())
    dT,dX,dY = abs(t0-ti),abs(x0-xi),abs(y0-yi)
    if dT>=dX+dY:
        if dT%2==(dX+dY)%2:
            t0,x0,y0 = ti,xi,yi
            continue
        else:
            print('No')
            exit()
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C;
  cin >>A>>B>>C;
  if((A<=C)&&(C<=B)){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}

           

Measured memory_bytes: 256
function main(input) {
  var temp = input.split('\n');
  for (var i = 0; i < temp.length; i++) {
    var data = temp[i].split(' ').map(Number);
    var height = data[0];
    var width = data[1];
    if (height == 0 && width == 0)
      break;

    var answer = "";
    for (var j = 0; j < height; j++) {
      for (var k = 0; k < width; k++) {
        if ((j + 1) % 2 == 1) {
          if ((k + 1) % 2 == 1) {
            answer += "#";
          } else {
            answer += '.';
          }
        } else {
          if ((k + 1) % 2 == 1) {
            answer += ".";
          } else {
            answer += '#';
          }
        }
      }
      answer += '\n';
    }
    console.log(answer.trim() + '\n');
  }
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);


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

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

const int INF = 1000000007;

int main(){
	int n; cin>>n;
	int odd=0,cnt2=0,cnt4=0;
	int a[110000]={0};
	for(int i=0;i<n;i++) cin>>a[i];

	for(int i=0;i<n;i++){
		if(a[i] % 2 != 0) odd++;
		else if(a[i]%2==0 && a[i]%4!=0)cnt2++;
		else if(a[i] % 4 == 0) cnt4++;
	}

	//cout<<cnt2<<" "<<cnt4<<" "<<odd<<endl;

	if(cnt2 == 0){
		if(odd-1 <= cnt4) cout<< "Yes" <<endl;
		else cout<< "No" <<endl;
	}
	else{
		if(odd <= cnt4) cout<< "Yes" <<endl;
		else cout<< "No" <<endl;
	}

	return 0;
}

Measured memory_bytes: 640
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,A,B=MI()
    N-=1
    print(max(0,B*N+A-(A*N+B)+1))
if __name__ == '__main__':
    main()

Measured memory_bytes: 6284
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n;
    cin >> n;
    
    vector<int> v(n);
    for (auto &x : v) cin >> x;
    
    int dp[n+1][n+1];
    memset(dp, 0x00, sizeof(dp));
    
    for (int len = 1; len <= n; ++len) {
        for (int L = 0, R = L+len; R <= n; ++L, ++R) {
            dp[L][R] = max(-dp[L+1][R] + v[L], -dp[L][R-1] + v[R-1]);
        }
    }
    
    cout << dp[0][n] << "\n";
    
    return 0;
}

Measured memory_bytes: 73996
#include<bits/stdc++.h>
using namespace std;
 int main(){
     int w,h,x,y,r;
     cin >> w >> h >> x >> y >> r;
     if((x-r<0 || x+r>w) || (y-r<0 || y+r>h)) cout <<"No" << endl;
     else cout << "Yes" << endl;

     return 0;
 }


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

typedef long long int ll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i, a, b) for(int i = (a); i<(b); ++i)
#define pb push_back
#define INF 1000000005
#define MOD 1000000007
#define all(v) v.begin(), v.end()

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

ll power(ll x, ll y, ll p = MOD){  
    ll res = 1LL; 
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1LL)  
            res = (res*x) % p;
        y = y>>1LL; 
        x = (x*x) % p;  
    }  
    return res;  
}  

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

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

	double dp[n][n + 1];
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j <= n; ++j) {
			dp[i][j] = 0.0;
		}
	}

	dp[0][0] = 1.0 - prob[0];
	dp[0][1] = prob[0];
	for(int i = 1; i < n; ++i) {
		dp[i][0] = dp[i - 1][0]*(1.0 - prob[i]);
		for(int j = 1; j <= n; ++j) {
			dp[i][j] = dp[i - 1][j - 1]*prob[i] + dp[i - 1][j]*(1 - prob[i]);
		}
	}

	double ans = 0.0;
	for(int i = 0; i <= n; ++i) {
		if(2*i > n) {
			ans+=dp[n - 1][i];
		}
	}

	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}

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

using namespace std;

#define li long long int

const int N 	= 1e5 + 5;
const li mod 	= 1e9 + 7;

int n, k;
int r, s, p;
string str;
int dp[N][3];

// r = 0, s = 1, p = 2

int convert(char x) {
	if (x == 'r') return 0;
	if (x == 's') return 1;
	if (x == 'p') return 2;
	return 3;
}

int score(int x, int y) {
	// r and p
	if (x == 0 and y == 2) return p;
	// s and r
	if (x == 1 and y == 0) return r;
	// p and s
	if (x == 2 and y == 1) return s;
	return 0;
}

int max(int x, int y, int z) {
	return max(max(x, y), max(x, z));
}

void solve() {
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> str;

	int sum = 0;
	for (int i = 0; i < n; i++) {
		int el = convert(str[i]);
		if (i < k) {
			for (int j = 0; j < 3; j++) {
				dp[i][j] = score(el, j);
			}
		} else {
			for (int j = 0; j < 3; j++) {
				for (int l = 0; l < 3; l++) {
					if (j == l) continue ;
					dp[i][j] = max(dp[i][j], dp[i - k][l] + score(el, j));
				}
			}
		}
		if (i + k >= n) sum += max(dp[i][0], dp[i][1], dp[i][2]);
	}

	cout << sum;
}

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

Measured memory_bytes: 1664
while gets
	n,ans = $_.to_i,0
	10.times{|i|
		10.times{|j|
			10.times{|k|
				ans += 1 if 0 <= (n - i - j - k) && (n - i - j - k) < 10
			}
		}
	}
	p ans
end

Measured memory_bytes: 6096
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, M; 
  cin >> N >> M;

  if(N%2 == 1){
    REP(i, M){
      cout << i+1 << " " << N-i-1 << "\n";
    }
  }else{
    REP(i, M){
      if(i < M/2) cout << i+1 << " " << N/2-i-1 << "\n";
      else cout << N/2+1+i-M/2 << " " << N-i+M/2 << "\n";
    }
  }


  return 0;
}

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

const ll mo = 1e9+7;
const int N = 2e5+7;

int n;
ll ans, a[N], b[N];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%lld",&a[i]);
	for(int i = n; i >= 1; i--)
		b[i] = (a[i] + b[i+1])%mo;
	for(int i = 1; i <= n; i++){
		ans  = (ans + a[i]*b[i+1]%mo)%mo;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 6944
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;      
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

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() {
  int N; cin >> N;
  vi H(N); rep(i,N) cin >> H.at(i);

  int ans = 0;
  int max_H = 0;
  rep(i,N) {
    if(max_H <= H.at(i)) {
      ans++;
      max_H = H.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,P>;

vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};

int inf = 1000000000;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,0,h) cin >> s[i];
  priority_queue<PP, vector<PP>, greater<PP>> q;
  vector<vector<int>> dist(h, vector<int>(w, inf));
  dist[0][0] = 1;
  q.push(PP(0,P(0,0)));
  while(!q.empty()) {
    PP p = q.top(); q.pop();
    int x = p.se.fi, y = p.se.se;
    rep(i,0,4) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (s[nx][ny] == '#') continue;
      if (dist[nx][ny] > dist[x][y] + 1) {
        dist[nx][ny] = dist[x][y] + 1;
        q.push(PP(dist[nx][ny], P(nx, ny)));
      }
    }
  }
  if (dist[h-1][w-1] == inf) {
    cout << -1 << endl;
    return 0;
  }
  int hash = 0;
  rep(i,0,h) rep(j,0,w) if (s[i][j] == '#') hash++;
  int ans = h*w - hash - dist[h-1][w-1];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3552