akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll n, k; cin >> n >> k;
    ll l[n]; rep(i,0,n) cin >> l[i];

    sort(l, l+n, greater<ll>());
    ll res = 0;
    rep(i,0,k) res += l[i];
    cout << res << ednl;

}


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

"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002
"""

while True:
    try:
        a = raw_input().split()
        #print a
        c = 0
        for b in a:
            c = c + int(b)
        print len(str(c))
    except EOFError:
        break

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

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;

int main(){
  int A, B, M;
  cin >> A >> B >> M;

  vector<int> a(A);
  vector<int> b(B);
  int ma = 1001001001;
  int mb = 1001001001;
  rep(i, A){
    cin >> a[i];
    chmin(ma, a[i]);
  }
  rep(i, B){
    cin >> b[i];
    chmin(mb, b[i]);
  }

  int m = ma + mb;
  rep(i, M){
    int x, y, c;
    cin >> x >> y >> c;
    x--, y--;
    chmin(m, a[x]+b[y]-c);
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin >> n;
	long long s[n+1];
	for (int i=1; i<=n; i++){
		cin >> s[i];
		if (s[i]==0){
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i=2; i<=n; i++){
		if(1000000000000000000ll/s[i-1]<s[i]){
			cout << -1 << endl;
			return 0; 
		}
		s[i]*=s[i-1];
	}
	cout << s[n] << endl;
	return 0;
}


Measured memory_bytes: 4364
import numpy as np
from numba import jit
N,K=map(int,input().split())
A=np.array(list(map(int,input().split())),dtype=np.int64)
@jit
def loop(a,k):
  if k>41:
    ans=np.ones(N,dtype=np.int64)*N
  else:
    ans=a
    for j in range(k):
      B=np.zeros(N+1,dtype=np.int64)
      for i in range(N):
        B[max(0,i-int(ans[i]))] +=1
        B[min(N,i+int(ans[i])+1)] -=1
      ans=np.cumsum(B)[:N]
  return ans

for i in loop(A,K):
  print(i)

Measured memory_bytes: 120256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cassert>
#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(), (x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(a) max_element(a.begin(), a.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for (int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<vector<char> > fd;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1e18;
const int inf = 1e9;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 100001;
const ld EPS = 1.0e-8;

signed main()
{
	fastio();
	int h, w;
	cin >> h >> w;
	vector<vector<char>> f;
	for (int i = 0; i < h; ++i)
	{
		vector<char> nw(w);
		vin(nw);
		if (count(all(nw), '#'))
		{
			f.pbc(nw);
		}
	}
	vector<vector<char>> nem(f.size());
	for (int j = 0; j < w; ++j)
	{
		vector<char> nw;
		for (int i = 0; i < f.size(); ++i)
		{
			nw.pbc(f[i][j]);
		}
		if (count(all(nw), '#'))
		{
			for (int i = 0; i < nw.size(); ++i)
			{
				nem[i].pbc(nw[i]);
			}
		}
	}
	for (int i = 0; i < f.size(); ++i)
	{
		for (int j = 0; j < nem[i].size(); ++j)
		{
			cout << nem[i][j];
		}
		cout << endl;
	}
}	

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    ll n; cin >> n;
    ll a[n];
    ll in;
    rep(i, n){
        cin >> in;
        a[in-1] = i+1;
    }

    rep(i, n) cout << a[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 1536
import java.util.*;
class Main{
public static void main(String[] args) {
  Scanner reader =new Scanner (System.in);
  int n=reader.nextInt();
  HashSet<String> a=new HashSet<String>();

  for(int i=0;i<n;i++)
  {
    a.add(reader.next());
  }
  System.out.println(a.size());




}
}

Measured memory_bytes: 77180
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int len, cnt[3] = { 0, 0, 0 };
	string S;
	bool ans;

	cin >> S;
	len = S.length();

	rep(i, len) cnt[S[i] - 'a']++;
	sort(cnt, cnt + 3);

	if ((cnt[0] == cnt[1] && cnt[1] == cnt[2]) ||
		(cnt[0] == cnt[1] && cnt[1] + 1 == cnt[2]) ||
		(cnt[1] == cnt[2] && cnt[0] + 1 == cnt[1])) ans = true;
	else ans = false;

	cout << (ans ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
s[3]='8';
cout<<s<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int co[100010],L[100010],R[100010];
std::vector<int>edge[100010];
bool ok,vi[100010];
bool in[100010];
void dfs(int x){
    if(co[x]!=-1){
        L[x]=R[x]=co[x];
        in[x]=true;
    }
    for(int k=0;k<edge[x].size();k++){
        int y=edge[x][k];
        if(vi[y]) continue;
        vi[y]=true;
        dfs(y);
        if(!in[y]) continue;
        if(!in[x]){
            in[x]=true;
            L[x]=L[y]-1;
            R[x]=R[y]+1;
        }
        else{
            int p,q;
            p=L[y]-1;q=R[y]+1;
            if((L[x]-p)%2!=0) ok=false;
            L[x]=std::max(L[x],p);
            R[x]=std::min(R[x],q);
            if(L[x]>R[x]) ok=false;
        }
    }
    return;
}
void print(int x){
    co[x]=L[x];
    for(int k=0;k<edge[x].size();k++){
        int y=edge[x][k];
        if(vi[y]) continue;
        vi[y]=true;
        if(!in[y]){
            L[y]=L[x]-1;
            R[y]=R[x]+1;
            in[y]=true;
        }
        else{
            L[y]=std::max(L[y],L[x]-1);
            R[y]=std::min(R[y],R[x]+1);
        }
        print(y);
    }
    return;
}
int main(){
    int n,m;
    int a,b,k;
    scanf("%d",&n);
    for(k=1;k<n;k++){
        scanf("%d%d",&a,&b);
        edge[a].push_back(b);
        edge[b].push_back(a);
        co[k]=-1;
    }
    co[n]=-1;
    scanf("%d",&m);
    int d,c;
    for(k=1;k<=m;k++){
        scanf("%d%d",&d,&c);
        co[d]=c;
    }
    ok=true;
    vi[1]=true;
    dfs(1);
    //for(k=1;k<=n;k++) printf("%d %d %d\n",k,L[k],R[k]);
    if(!ok){
        puts("No");
        return 0;
    }
    puts("Yes");
    memset(vi,0,sizeof(vi));
    vi[1]=true;
    print(1);
    for(k=1;k<=n;k++) printf("%d\n",co[k]);
}
    

Measured memory_bytes: 12416
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
  if(b == 0)return a;
  return gcd(b,a%b);
}

int main(){
  ll a,b;
  cin >> a >> b;

  cout << (a*b/gcd(a,b)) << endl;
}

Measured memory_bytes: 256
// ABC146-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

int num=pow(10,5)+2;
vector<vector<int>> node(num+1);
vector<vector<int>> hen(num+1);
vector<int> col(num);
vector<int> seen(num+1);
vector<int> setu(num+1,0);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    struct local{
        static void dfs(int x,int c){
            seen[x]=1;
            int color=1;
            int kaburi=0;
            for(int i=0;i<setu[x];i++){
                if(seen[node[x][i]]==1){
                    if(color==c and kaburi==0){
                        color+=1;
                        kaburi=1;
                    }
                    continue;
                }
                if(color==c and kaburi==0) color+=1;
                col[hen[x][i]]=color;
                dfs(node[x][i],color);
                color+=1;
            }
        }
    };
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        node[a].push_back(b);
        node[b].push_back(a);
        hen[a].push_back(i);
        hen[b].push_back(i);
        setu[a]+=1;
        setu[b]+=1;
    }
    //cout<<node<<endl;
    int max_=0;
    rep(i,n+1){
        if(max_<setu[i]) max_=setu[i];
    }
    //cout<<max_<<endl;
    local::dfs(1,0);
    cout<<max_<<endl;
    for(int i=0;i<n-1;i++){
        cout<<col[i]<<endl;
        //cout<<node[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 12800
n = int(input())
s = input()
abc =['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
ans = ''
for i in range(len(s)):
  ans += abc[(abc.index(s[i]) + n) % 26]
print(ans)

Measured memory_bytes: 3064
N=int(input())
a=[chr(i) for i in range(97, 97+26)]
for i in range(1,100):
    if 26**i<N:
        N-=26**i
        continue
    ans=""
    N-=1
    for j in range(i):
        ans+=a[N%26]
        N//=26
    break
print(ans[::-1])

Measured memory_bytes: 8912
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int a,b;
  cin>>a>>b;
  if(a!=1&&b!=1){
    cout<<1<<endl;
  }else if(a!=2&&b!=2){
    cout<<2<<endl;
  }else{
    cout<<3<<endl;
  }

 

  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
A = []
for _ in range(n):
    t, d = map(int, input().split())
    A.append((d, t))

A.sort(reverse=True)
X = []
Y = []
st = set()

for i in range(k):
    d,t = A[i]
    if t in st:
        X.append(d)
    else:
        Y.append(d)
        st.add(t)

x = sum(X)
y = sum(Y)
v = len(Y)
ans = x + y + v**2
for i in range(k, n):
    if not X:
        break
    d, t = A[i]
    if t in st:
        continue
    st.add(t)
    x -= X.pop()
    y += d
    v += 1
    ans = max(ans, x + y + v**2)

print(ans)


Measured memory_bytes: 19848
#include <stdio.h>
#define MAX 250

int main ()
{
  int i,num,A[MAX+1];

  scanf("%d",&num);

  for(i=1;i<=num;i++)
    {
      scanf("%d",&A[i]);
    }

  for(i=1;i<=num;i++)
    {
      printf("node %d: key = %d, ", i, A[i]);
    
      if(i/2 >= 1)
	{
	  printf("parent key = %d, ", A[i/2]);
	}
      if(i*2 <= num)
	{
	  printf("left key = %d, ", A[i*2]);
	}
      if((i*2)+1 <= num)
	{
	  printf("right key = %d, ", A[(i*2)+1]);
	}
      printf("\n");
    }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//string alp = "abcdefghijklmnopqrstuvwxyz";
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a<c){
    if(b<c){
      cout << 0;
    } else {
      if(d<b){
        cout << d-c;
      } else {
        cout << b-c;
      }
    }
  } else {
    if(d<a){
      cout << 0;
    } else {
      if(b<d){
        cout << b-a;
      } else {
        cout << d-a;
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
//Work should be challenging and challange should be fun

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
    ll a,b,c,d,ma=-1e18;
    cin>>a>>b>>c>>d;
    ma=max(ma,a*c);
    ma=max(ma,a*d);
    ma=max(ma,b*c);
    ma=max(ma,b*d);
    if((a<=0)&&(b>=0)) ma=max(ma,(ll)0);
    if((c<=0)&&(d>=0)) ma=max(ma,(ll)0);
    cout<<ma;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    string n;
    cin >> n;
    if(n[0]=='7' || n[1]=='7' || n[2]=='7') cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
const int mod = 1000000007;
const int modx = 998244353;
#define ll long long
#define readi(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define readl(x) scanf("%I64d", &x)
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define rep2(i, a, b) for (i = b; i >= a; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bpc(x) __builtin_popcount(x)
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pdd pair<double, double>
#define pic pair<int, char>
#define ddouble long double
#define PI 3.1415926535
#define endl "\n"
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define prod(x, y) ((x % mod) * (y % mod)) % mod
#define add(x, y) ((x % mod) + (y % mod)) % mod
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define pqs priority_queue<int, vector<int>, greater<int>>
#define pqb priority_queue<int>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
//using namespace __gnu_pbds;
/*ll power(ll x, ll y)
{
    ll r = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            r = (r*x) % mod;

        y = y>>1;
        x = (x*x) % mod;
    }
    return r;
}*/
const int N = 3005;
ll dp[N][N] = {}, vis[N][N] = {}, n, a[N];
void thunder()
{
    cin >> n;
    int i, j;
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep2(i, 0, n - 1)
    {
        rep1(j, i, n)
        {
            if (i == j)
                dp[i][j] = a[i];
            else
                dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);
        }
    }
    cout << dp[0][n - 1] << endl;
    return;
}
int main()
{
    /*#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif*/
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q = 1;
    //cin >> t;
    while (q--)
        thunder();
}


Measured memory_bytes: 49716
use std::cmp;

const MOD: usize = 1e9 as usize + 7;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };

    let n = sc.read();
    let m = sc.read();
    let mut constraints = vec![vec![]; n + 1];
    for _ in 0..m {
        let l = sc.read::<usize>();
        let r = sc.read::<usize>();
        let x: usize = sc.read();
        constraints[r].push((l, x));
    }

    let mut dp = vec![vec![vec![0; n + 1]; n + 1]; n + 1];
    dp[0][0][0] = 1;
    for r in 0..n {
        for g in 0..n {
            for b in 0..n {
                let max = max3(r, g, b);
                let next = vec![(max + 1, g, b), (r, max + 1, b), (r, g, max + 1)];
                for &(nr, ng, nb) in next.iter() {
                    let mut ok = true;
                    for &(left, x) in constraints[max + 1].iter() {
                        let mut count = 0;
                        if nr >= left {
                            count += 1;
                        }
                        if ng >= left {
                            count += 1;
                        }
                        if nb >= left {
                            count += 1;
                        }
                        if count != x {
                            ok = false;
                            break;
                        }
                    }
                    if ok {
                        dp[nr][ng][nb] += dp[r][g][b];
                        dp[nr][ng][nb] %= MOD;
                    }
                }
            }
        }
    }

    let mut ans = 0;
    for i in 0..n {
        for j in 0..n {
            ans += dp[n][i][j];
            ans += dp[i][n][j];
            ans += dp[i][j][n];
            ans %= MOD;
        }
    }

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

fn max3(x: usize, y: usize, z: usize) -> usize {
    cmp::max(cmp::max(x, y), z)
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 237820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//vector <vector<ll>> adj;
void pk()
{   
    ll n,d;
    cin>>n>>d;
    ll cn=0;
    ll x,y;
    for(ll i=0;i<n;i++)
    {
        cin>>x>>y;
        if(sqrt((x*x)+(y*y))<=d)
           cn++;
    }
cout<<cn;
}
int main() 
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    // #ifndef ONLINE_JUDGE 
    // freopen("/home/priyanshu/Hackercup/input.txt", "r", stdin); 
    // freopen("/home/priyanshu/Hackercup/output.txt", "w", stdout); 
    // #endif 
	ll t=1;
    //cin>>t;
    while(t--)
    {
        pk();
    }
} 

Measured memory_bytes: 3664
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int A, B, C, D;
	std::cin >> A >> B >> C >> D;
	std::cout << std::max(A*B,C*D) << "\n";
}


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

#define maxn 300010
#define LL long long
#define inf 10000000000
#define mod 1000000007
#define pi 3.14159265359
using namespace std;
int dx[24] = { 1,0,-1,0 ,2,0,-2,0 ,-1,-1,-2,-2 ,1,1,2,2    ,-1,-1,-2,-2 ,1,1,2,2 };
int dy[24] = { 0,1,0,-1 ,0,2,0,-2 ,-1,-2,-1,-2 ,-1,-2,-1,-2,1,2,1,2     ,1,2,1,2  };


LL n, m, k;
int arr[maxn];
int arr2[maxn];
//int visit[maxn][maxn];
//int cache[maxn];
//int c[maxn];
//int g[maxn];
//int dfsnum = 0;
//vector<vector<int>>rvi;
//vector<vector<int>>scc;
//vector<pair<int, int>>ett;
//stack<int>st;
//bool flg = 1;
//LL s, d;
//
//int findp(int a) {
//	if (a == c[a])return a;
//	return c[a] = findp(c[a]);
//}
//void unionp(int a, int b) {
//	a = findp(a);
//	b = findp(b);
//
//	if (g[a] < g[b])swap(a, b);
//	c[b] = a;
//	g[a] += g[b];
//	g[b] = 1;
//
//}
//LL power(LL x, LL y) {
//	LL ret = 1;
//	while (y > 0) {
//		if (y % 2) {
//			ret *= x;
//			ret %= mod;
//		}
//		x *= x;
//		x %= mod;
//		y /= 2;
//	}
//	return ret;
//}
//void dfs2(int v) {
//	cache[v] = 1;
//	scc.back().push_back(v);
//	for (int nv : rvi[v]) {
//		if (cache[nv])continue;
//		dfs2(nv);
//	}
//
//}
//LL fac(LL n) {
//	if (n == 1) return 1;        
//	return (n * fac(n - 1) - power(2,n-1) )%mod;
//}
//int fac2(LL n) {
//	LL res, i;
//	if (n == 1)return n;
//	res = n;
//	for (int i = n - 1; i > 0; --i) {
//		res *= i;
//		res %= mod;
//	}
//	return res;
//}

LL gcd(LL a, LL b) {
	while (b != 0) {
		LL r = a % b;
		a = b;
		b = r;
	}
	return a;
}
vector<LL>vi;
vector<LL>vi2;
vector<vector<int>>graph;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//int t;   cin >> t; cin.ignore();
	int t = 1;
	for (int test_case = 0; test_case < t; ++test_case) {
		int flg = 1;
		LL ans1 = 0, ans2 = 0;
		string ans[2] = { "No","Yes"};
		cin >> n >> m >> k;
		set<int> s[maxn];
		for (int i = 0; i < k; ++i) {
			LL y, x;
			cin >> y >> x;

			arr[y]++;
			arr2[x]++;
			s[y].insert(x);
		}
		int mx1 = arr[1];
		int mx2 = arr2[1];
		for (int i = 2; i <= n; ++i) mx1 = mx1 < arr[i] ? arr[i] : mx1;
		for (int i = 2; i <= m; ++i) mx2 = mx2 < arr2[i] ? arr2[i] : mx2;

		for (int i = 1; i <= n; ++i) if (arr[i] == mx1) vi.push_back(i);
		for (int i = 1; i <= m; ++i) if (arr2[i] == mx2) vi2.push_back(i);

		for (int i = 0; i < vi.size(); ++i) {
			for (int j = 0; j < vi2.size(); ++j) {
				if (s[vi[i]].find(vi2[j]) == s[vi[i]].end()) {
					cout << mx1 + mx2;
					flg = 0;
					break;
				}
			}
			if (!flg)break;
		}
		if(flg)
		cout << mx1+mx2-1;
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 34576
// Vicfred
// https://atcoder.jp/contests/abc045/tasks/arc061_a
// brute force, bitmask
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    string s = readln.strip;

    const long n = s.length;
    long ans = 0;

    for(int bit = 0; bit < (1 << n - 1); bit++) {
        string tmp;
        for(int idx = 0; idx < n; idx++) {
            tmp ~= s[idx];
            if(!(bit & (1<<idx))) {
                ans += tmp.to!long;
                tmp = "";
            }
        }
    }

    ans.writeln;
}



Measured memory_bytes: 2668
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=100010;
const int M=200010;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,m,col[N];
LL sum[4];
int bgn[N],nxt[M],to[M],E;
inline void add_edge(int u,int v){nxt[++E]=bgn[u],bgn[u]=E,to[E]=v;}
inline bool bfs(int u)
{
	queue<int>q;
	q.push(u);col[u]=2;
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int v,i=bgn[u];i;i=nxt[i])
		{
			if(col[v=to[i]]&&col[to[i]]==col[u])return 0;
			if(!col[v])
			{
				col[v]=col[u]^1;
				q.push(v);
			}
		}
	}
	For(i,1,n)sum[col[i]]++;
	return 1;
}
int main()
{
	int x,y;
	read(n),read(m);
	For(i,1,m)
	{
		read(x),read(y);
		add_edge(x,y),add_edge(y,x);
	}
	if(bfs(1))
		printf("%lld\n",sum[2]*sum[3]-(LL)m);
	else
		printf("%lld\n",(LL)n*((LL)n-1ll)/2ll-(LL)m);
	return 0;
}


Measured memory_bytes: 2688
#include<cstdio>
#include<utility>
#include<iostream>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef pair <int,int> pi;
const int N=505,dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int n,p[N*N],a[N][N],dis[N][N]; long long ans; pi nw;
inline pi trs(CI x)
{
	if (x%n) return mp(x/n+1,x%n); return mp(x/n,n);
}
inline void DFS(pi nw)
{
	for (RI i=0;i<4;++i)
	{
		pi to=mp(nw.fi+dx[i],nw.se+dy[i]);
		if (to.fi<1||to.fi>n||to.se<1||to.se>n) continue;
		if (dis[to.fi][to.se]>dis[nw.fi][nw.se]+a[nw.fi][nw.se])
		dis[to.fi][to.se]=dis[nw.fi][nw.se]+a[nw.fi][nw.se],DFS(to);
	}
}
int main()
{
	RI i,j; for (scanf("%d",&n),i=1;i<=n*n;++i) scanf("%d",&p[i]);
	for (i=1;i<=n;++i) for (j=1;j<=n;++j) a[i][j]=1,dis[i][j]=min(min(i-1,j-1),min(n-i,n-j));
	for (i=1;i<=n*n;++i) nw=trs(p[i]),ans+=dis[nw.fi][nw.se],a[nw.fi][nw.se]=0,DFS(nw);
	return printf("%lld",ans),0;
}

Measured memory_bytes: 25924
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int A,B,C;
	while(scanf("%d%d%d",&A,&B,&C)!=EOF)
	{
		if(A+B>=14||A+C>=14||B+C>=14)
		   printf("NO\n");
		else 
		   printf("YES\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 1000010
#define ll long long

using namespace std;


int n, m;
int t, k;
int a[MAXN], b[MAXN];
int f;
int d, x, y, p, u, v;
string s;

int main() {
	cin >> n;
	for (int i = 2; i <= n; i++) {
		cin >> a[i];
	}
	if (n == 2) {
		cout << a[2] * 2 << endl;
		return 0;
	}
	b[1] = a[2];
	int sum = b[1];
	for (int i = 2; i <= n - 1; i++) {
		if (a[i + 1] >= a[i]) b[i] = a[i];
		else {
			b[i] = a[i + 1];
		}
		sum += b[i];
	}
	sum += a[n];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int dis[20000 + 3][20000 + 3];
int main(){
	int n,m,q,x,y;
	scanf("%d%d%d",&n,&m,&q);
	for(int i = 1;i <= m;i++){
		scanf("%d%d",&x,&y);
		dis[x][y]++;
	}
 	for(int i = 1;i <= n;i++)
        for(int j = i + 1;j <= n;j++)
            dis[i][j] += dis[i][j - 1];
    for(int i = 1;i <= n;i++)
        for(int j = i - 1;j >= 1;j--)
            dis[j][i] += dis[j + 1][i];
	for(int i = 1;i <= q;i++){
		scanf("%d%d",&x,&y);
		printf("%d\n",dis[x][y]);
	}
	return 0;
}

Measured memory_bytes: 39936
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n; vector<ll> times(n+1);
  vector<pair<ll,ll>> xy(n+1);
  
  rep(i,n){
    ll a,b,c; cin >> a >> b >> c;
    times[i+1] = a; xy[i+1] = make_pair(b,c);
  }
  
  rep(i,n){
    auto time = times[i+1]-times[i]; 
    ll man = abs(xy[i].first-xy[i+1].first)+
      abs(xy[i].second-xy[i+1].second);
    
    if(time < man or (man % 2 != time % 2)){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  
  
}

Measured memory_bytes: 5412
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.StringTokenizer;

/**
 * for (int i = 0; i < N; i++) {}
 * System.out.println();
 * HashMap<Integer, Integer> hm = new HashMap<>();
 * int[] s = new int[M];
 * ArrayDeque<Integer> deq = new ArrayDeque<>();
 *
 */
public class Main implements Runnable { //クラス名はMain1

	public static void main(String[] args) {
		Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1));
		new Thread(null, new Main(), "", 1024 * 1024 * 1024).start(); //16MBスタックを確保して実行
	}

	public void run() {
		FastScannerMainC sc = new FastScannerMainC(System.in);

		try {
			//String S = sc.nextLine().trim();
			double L = sc.nextDouble();

			double nn = L / 3;

			double ans = Math.pow(nn, 3);

			//int[] a = new int[N];
			//long l = sc.nextLong();
			//ArrayList<Integer> arr = new ArrayList<Integer>();
			//for (int i = 0; i < N; i++) {}

			//System.out.println(Double.toString(ans));

			System.out.println(BigDecimal.valueOf(ans).toPlainString());

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}

//高速なScanner
class FastScannerMainC {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScannerMainC(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 30548
#include <iostream>
#include <string>
#include <set>
#include <vector>
using namespace std;

int main(){

    int N, K;
    int total = 0;

    cin >> N >> K;
    vector<int> l(N);
    for(int i = 0; i < N; ++i){
        cin >> l[i];
    }

    sort(l.begin(), l.end(), greater<int>() );

    for(int i = 0; i < K; ++i){
        total += l[i];
    }
    cout << total << endl;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,k,q;cin>>n>>k>>q;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  auto b=a;
  sort(ALL(b));
  b.erase(unique(ALL(b)),b.end());
  rep(i,0,b.size()){
    ll l=0,r=MOD;
    while(r-l>=2){
      ll mid=(l+r)/2;
      ll cnt1=0;
      ll cnt2=0;
      ll ret=0;
      rep(j,0,n){
        if(a[j]>mid)cnt2++;
        if(a[j]!=-1)cnt1++;
        if(a[j]==-1){
          ret+=max(0LL,min(cnt1-cnt2,cnt1-k+1));
          cnt1=0;
          cnt2=0;
        }
      }
      ret+=max(0LL,min(cnt1-cnt2,cnt1-k+1));
      if(ret>=q)r=mid;
      else l=mid;
    }
    //cout<<b[i] spa r<<endl;
    chmin(res1,r-b[i]);
    ll cnt=0,ret=0;
    rep(j,0,n){
      if(a[j]==b[i]||a[j]==-1){
        ret+=max(0LL,cnt-k+1);
        cnt=0;
        a[j]=-1;
      }
      else cnt++;
    }
    ret+=max(0LL,cnt-k+1);
    if(ret<q)break;
  }
  cout<<res1<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;

typedef long long ll;

ll n, m, cost[5002][202], v[5002], sc[5002], mat[5002][5002];

int st[5002], dr[5002];
ll mx[202];
void add(int xa, int ya, int xb, int yb, int val)
{
    mat[xa][ya] += val;
    mat[xb+1][ya] -= val;
    mat[xa][yb+1] -= val;
    mat[xb+1][yb+1] += val;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for(int i = 2; i <= n; ++i)
        cin >> v[i];
    for(int i = 2; i <= n; ++i)
        sc[i] = sc[i-1] + v[i];
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            cin >> cost[i][j];
    ll ans = 0;
    for(int i = 1; i <= m; ++i)
    {
        deque<int>d;
        for(int j = 1; j <= n; ++j)
        {
            while(!d.empty() && cost[j][i] > cost[d.back()][i])
                d.pop_back();
            if(d.empty())
                st[j] = 1;
            else
                st[j] = d.back() + 1;
            d.push_back(j);
        }
        d.clear();
        for(int j = n; j >= 1; --j)
        {
            while(!d.empty() && cost[j][i] > cost[d.back()][i])
                d.pop_back();
            if(d.empty())
                dr[j] = n;
            else
                dr[j] = d.back() - 1;
            d.push_back(j);
            add(st[j], j, j, dr[j], cost[j][i]);
        }
    }
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            mat[i][j] = mat[i-1][j] + mat[i][j] + mat[i][j-1] - mat[i-1][j-1];
    for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++)
			ans = max(ans, mat[i][j] - (sc[j] - sc[i]));
    cout << ans;
    return 0;
}



Measured memory_bytes: 203776
fun main(args: Array<String>) {
    val (a, b, c, d) = readLine()!!.split(' ').map { it.toLong() }
    var max = Long.MIN_VALUE
    max = maxOf(max, a * c)
    max = maxOf(max, b * c)
    max = maxOf(max, a * d)
    max = maxOf(max, b * d)
    println(max)
}

Measured memory_bytes: 36504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N;
ll ans, sum, xr;

int main()
{
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    for (int left = 0, right = 0; left < N; left++)
    {
        while (right < N && (sum + A[right] == (xr ^ A[right])))
            ans += (right - left + 1), sum += A[right], xr ^= A[right], right++;
        if (right == left)
            right++;
        else
            sum -= A[left], xr ^= A[left];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
const int inf = (1<<30);
string toBin(ll a);
void printMat(int arr[], int n);
void printMat(vector<int> arr, int n);
void printMat(vector<vector<int> > arr, int n, int m);
void printMat(vector<int> arr[], int n);
void printMap(unordered_map<ll, ll> mp);
//void printMat(int arr[][], int n, int m);

void printMap(unordered_map<ll, ll> mp){
	cout<<"Printing Map"<<endl;
	for(auto it=mp.begin();it!=mp.end();it++){
		cout<<it->first<<" "<<it->second<<endl;
	}
	cout<<"end"<<endl;
}
void solve(){
	int i, j, n;
	cin>>n;
	ll arr[n];
	ll sum=0;
	unordered_map<ll, ll> mp;
	for(i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
		mp[arr[i]]++;
	}
	int q;
	cin>>q;
	//printMap(mp);
	while(q--){
		ll b, c;
		cin>>b>>c;
		ll freq=mp[b];
		mp[b]=0;
		/*Check is c is there or not */mp[c]+=freq;
		sum=(ll)(sum+((ll)(c-b)*freq));
		cout<<sum<<endl;
		//printMap(mp);
	}
}

int main()
{
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}
string toBin(ll a){
	string s="";
	while(a>0){
		if(a&1){
			s="1"+s;
		}else{
			s="0"+s;
		}
		a>>=1;
	}
	return s;
}
void printMat(int arr[], int n){
	for(int i=0;i<n;i++){
		cout<<arr[i]<<" ";
	}cout<<endl;
}
void printMat(vector<int> arr, int n){
	for(int i=0;i<n;i++){
		cout<<arr[i]<<" ";
	}cout<<endl;
}
void printMat(vector<int> arr[], int row, int col){
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			cout<<arr[i][j]<<" ";
		}cout<<endl;
	}cout<<endl;
}
void printMat(vector<vector<int> > arr, int row, int col){
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			cout<<arr[i][j]<<" ";
		}cout<<endl;
	}cout<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

int main() {
	int a, b;
	cin>>a>>b;
	if (a <= 9 && b <= 9) cout<<a*b<<endl;
	else cout<<-1<<endl;
	return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    int N;
    cin >> N;
    vector<int> V(N);
    for (int i = 0; i < N; i++)
    {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++)
    {
        int C;
        cin >> C;
        V[i] -= C;
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (V[i] > 0) ans += V[i];
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        char[] steps = line.toCharArray();

        String result = "Yes";
        for (int i = 0; i < steps.length; i++) {
        	if (i%2==0 && steps[i] =='L') {
        		result = "No";
        		break;
        	} else if (i%2==1 && steps[i] == 'R') {
        		result = "No";
        		break;
        	}
        }
        System.out.println(result);
    }





}

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

int main() {
	vector<int> x(5);
	int answer = 0;
	for (int i = 0; i < 5; i++) {
		cin >> x.at(i);
		if (x.at(i) == 0) {
			answer = (i + 1);
			break;
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 3576
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int main(void)
{
  int x,y;
  int a[4];
  int max=-1000010;
  cin>>x>>y;
  a[0]=x+y;
  a[1]=x*y;
  a[2]=x-y;

  for(int i=0;i<3;i++)
    {
      if(a[i]>max)max=a[i];
    }
  cout<<max<<endl;
  return 0;
}

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

using namespace std;

using ll = long long;

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

    int n;

    cin >> n;
    vector<int> x(n), x2(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
        x2[i] = x[i];
    }
    sort(x2.begin(), x2.end());

    int m1 = x2[n / 2 - 1], m2 = x2[n / 2];
    for (int i = 0; i < n; ++i) {
        if (x[i] <= m1) cout << m2 << '\n';
        else cout << m1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 3840