akhauriyash/Code-Regression huggingface dataset:
/*
    I was lying to myself
*/




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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int>pii;
typedef unsigned long long ull;

#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pf           push_front
#define pi           acos(-1)
#define all(x)       x.begin(),x.end()
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF          0x3f3f3f3f
#define inputfile    freopen("input.txt", "r", stdin)
#define outputfile   freopen("output.txt", "w", stdout)
#define appendfile   freopen("output.txt", "a", stdout)


struct hash_pair
{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);auto hash2 = hash<T2> {}(p.second);return hash1 ^ hash2;
    }
};

ll t;
ll mod=N;
ll BigMod(ll base,ll pow,ll mod)
{
    if(pow==0||base==1)return 1;
    else if(pow==1)return base;
    else if(pow%2)return BigMod(base,pow-1,mod)*base%mod;
    else {ll x=(BigMod(base,pow/2,mod)%mod);x=(x*x)%mod;return x;}
}


vector<pll>v;
vector<ll>p;
ll dp[100005];



int main()
{
    fast;
    ll a,b,c,d,e,f,g,i,j;
    ll n,m,k;
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;
    f=0;
    for(i=0;i<n;i++)
    {
        cin>>a>>b;
        v.pb({b,a});
        f+=b;
    }
    sort(all(v));
    p.pb(0);
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        a=v[i].first;
        b=v[i].second;
        e=p.size();
        for(j=e-1;j>=0;j--)
        {
            c=a+p[j];
            d=dp[p[j]]+b;
            if(dp[c]==-1)
            {
                dp[c]=d;
                p.pb(c);
            }
            else
            {
                dp[c]=min(dp[c],d);
            }
        }
        sort(all(p));
    }
    for(i=f;i>=0;i--)
    {
        if(dp[i]!=-1&&dp[i]<=m)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 4628
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {
	ll H, W;
	cin >> H >> W;

	if (H > 1 && W > 1) { cout << (H*W + 1) / 2; }
	else { cout << 1; }


	system("PAUSE");

}





Measured memory_bytes: 504
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yn(int o){
    if (o == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main() {
    int n; cin >> n;
    ll ans = 1LL;
    rep(i,n){
        ll a; cin >> a;
        ll b = a;
        ll ar = ans;
        ll gcd = ar % a;
        while (gcd > 0){
            ar = a;
            a = gcd;
            gcd = ar % a;
        }
        ans *= b / a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
"""
Dangerous Bridge
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0231

"""
import sys


def solve(n):
    events = []
    for _ in range(n):
        m, a, b = map(int, input().split())
        events.append([a, m])
        events.append([b, -m])

    weight = 0
    for t, m in sorted(events):
         weight += m
         if weight > 150:
             return 'NG'
    return 'OK'


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        ans = solve(n)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5632
#include<stdio.h>

int main(){
  int l,r,d;
  scanf("%d""%d""%d",&l,&r,&d);
  if(r%d == 0 && l%d == 0)
  printf("%d\n",r/d - l/d + 1);
  else
  printf("%d\n",r/d - l/d);
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    int p[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    sort(p, p + n);
    int sum = 0;
    for (int i = 0; i < k; i++) sum += p[i];
    cout << sum << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
struct A{
    long long m[50][50];
};
A p[63],ans,tmp;
long long n,k;
A mul(A a,A b){
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            tmp.m[i][j] = 0;
            for(int k=0;k<n;k++){
                tmp.m[i][j] += (a.m[i][k]*b.m[k][j])%MOD;
                tmp.m[i][j] %= MOD;
            }
        }
    }
    return tmp;
}
int main(){
    scanf("%lld %lld",&n,&k);
    for(int i=0;i<n;i++){
        ans.m[i][i] = 1;
        for(int j=0;j<n;j++)
            scanf("%d",&p[0].m[j][i]);
    }
    for(int i=1;i<=60;i++)  p[i] = mul(p[i-1],p[i-1]);
    for(int i=0;i<=60;i++)
        if(k&(1ll<<i))
            ans = mul(ans,p[i]);
    long long sum = 0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            sum = (sum + ans.m[i][j])%MOD;
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e18
#define common cout << "Case #" << w+1 << ": "  


const int maxn = 1000000 + 10;

void add(int &a, int b){
    a += b;
    if (a >= mod)
        a -= mod;
}

int fak[maxn];
int ifak[maxn];

int modpow(int a, int b){
    int c = 1;

    while (b){
        if (b & 1)
            c = 1LL * c * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }

    return c;
}

int comb(int n, int k){
    return 1LL * fak[n] * ifak[k] % mod * ifak[n - k] % mod;
}

int main()
{
    
    fak[0] = 1;
    for (int i = 1; i < maxn; ++i)
        fak[i] = 1LL * fak[i-1] * i % mod;
        
    ifak[maxn-1] = modpow(fak[maxn-1], mod-2);
    
    for (int i = maxn-2; i >= 0; --i)
        ifak[i] = 1LL * ifak[i + 1] * (i+1) % mod;
    fastio;
    int s;
    cin >> s;
    int ans=0;
    for(int i=1;i<s;i++)
    {
        if(i*3>s)
            break;
        int rem=s-i*3;
        int t=comb(rem+i-1,rem);
        ans=(ans*1LL+t)%mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11424
#include <bits/stdc++.h>
using namespace std;
#define NMAX 110000

vector<int> dp(NMAX);

int solve(int n)
{
    if (n == 0)
        return 0;
    if (dp[n] != -1)
        return dp[n];
    int res = n;

    for (int six = 1; six <= n; six *= 6)
        res = min(res, solve(n - six) + 1);

    for (int nine = 1; nine <= n; nine *= 9)
        res = min(res, solve(n - nine) + 1);

    return dp[n] = res;
}

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

    dp.assign(NMAX, -1);

    cout << solve(n) << endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int X, Y; cin >> X >> Y;
	long long ans = 0;
	vector<int>C(205, 0);
	C[0] = 300000, C[1] = 200000, C[2] = 100000;
	int S = 400000;
	if (X == 1 && Y == 1)ans += S;
	cout << ans + C[X - 1] + C[Y - 1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

typedef  long long ll;

#define rep(i,a,n) for(ll (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(ll (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007


using namespace std;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}


void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}

ll divisors(ll n) {
    vector<ll> res;

    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i-1);
        if(n/i == i) continue;
        res.push_back((n/i)-1);
    }

    ll ans = 0;

    rep(i,0,res.size()){
        if(res[i] != 0)
        if(n/res[i] == n%res[i]) ans += res[i];
    } 
    return ans;
}
vector<string> ans;
void solve(void){
    ll k;
    string s;
    cin  >> s >> k;
    rep(i,0,s.size()){
        string ss = "";
        rep(j,i,min(i+k,(ll)s.size())){
            ss += s[j];
            ans.push_back(ss);
        }
    }
    sort(ans.begin(),ans.end());
    unique(ans.begin(),ans.end());
    cout << ans[k-1];
}

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

Measured memory_bytes: 1660
#include <iostream>

using namespace std;

bool check(int x)
{
  int t=x;
  int num=0;
  while (t>0)
  {
    num = num*10 + t%10;
    t/=10;
  }
  return num==x;
}

int main()
{
  int a,b;
  cin >> a >> b;
  int ans=0;
  for(int i=a; i<=b; ++i)
    if (check(i)) ans++;
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int prime(int x){
  bool a = true;
for(int i = 2; i * i <= x; i++){
  if(x % i == 0){
a = false;
    break;
  }
}
return a;
}

int main(){
int X;
  cin >> X;
int j = 0;
  while(!prime(X+j)) j++;
cout << X + j << endl;
}


Measured memory_bytes: 256
from collections import Counter

if __name__ == '__main__':
    N = int(input())
    S = input()

    cntR_from_r = [0 for _ in range(N)]
    cntG_from_r = [0 for _ in range(N)]
    cntB_from_r = [0 for _ in range(N)]

    for i in range(N - 1, 0, -1):
        if S[i] == 'R':
            cntR_from_r[i - 1] = cntR_from_r[i] + 1
            cntG_from_r[i - 1] = cntG_from_r[i]
            cntB_from_r[i - 1] = cntB_from_r[i]
        elif S[i] == 'G':
            cntR_from_r[i - 1] = cntR_from_r[i]
            cntG_from_r[i - 1] = cntG_from_r[i] + 1
            cntB_from_r[i - 1] = cntB_from_r[i]
        else:
            cntR_from_r[i - 1] = cntR_from_r[i]
            cntG_from_r[i - 1] = cntG_from_r[i]
            cntB_from_r[i - 1] = cntB_from_r[i] + 1

    ans = 0
    for i in range(N):
        if S[i] == 'R':
            val1 = cntG_from_r[i] * cntB_from_r[i]
            for j in range(1, N):
                j1 = i - j
                j2 = i + j

                if j1 < 0 or j2 > N - 1:
                    break
                else:
                    if (S[j1] == 'G' and S[j2] == 'B') or (S[j1] == 'B' and S[j2] == 'G'):
                        val1 -= 1
            ans += val1
        elif S[i] == 'G':
            val1 = cntR_from_r[i] * cntB_from_r[i]
            for j in range(1, N):
                j1 = i - j
                j2 = i + j
                if j1 < 0 or j2 > N - 1:
                    break
                else:
                    if (S[j1] == 'R' and S[j2] == 'B') or (S[j1] == 'B' and S[j2] == 'R'):
                        val1 -= 1
            ans += val1
        else:
            val1 = cntG_from_r[i] * cntR_from_r[i]
            for j in range(1, N):
                j1 = i - j
                j2 = i + j
                if j1 < 0 or j2 > N - 1:
                    break
                else:
                    if (S[j1] == 'R' and S[j2] == 'G') or (S[j1] == 'G' and S[j2] == 'R'):
                        val1 -= 1
            ans += val1
    print(ans)


Measured memory_bytes: 74744
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=123;
uli x[mx];
int main(){
   int n;
   scanf("%d",&n);
   for(int i=0;i<n;i++)scanf("%lld",x+i);
   uli ans=-1;
   for(uli y=-200;y<=200;y++){
      uli bet=0ll;
      for(int i=0;i<n;i++)bet+=(x[i]-y)*(x[i]-y);
      if(ans==-1 || bet<ans)ans=bet;
   }
   printf("%lld\n",ans);
   return 0;
}


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

typedef long long int LL;
#define REP(n) for(LL i = 0; i < (n); i++)
#define COUT(val) cout << (val) << endl
#define CIN(val) cin >> (val)
#define SORT(vec) sort(vec.begin(), vec.end())
#define SORT_GRE(vec) sort(vec.begin(), vec.end(), greater<LL>())

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int K;
    string S;
    cin >> K >> S;

    int cnt = 0;
    for (auto c : S) {
        if (cnt >= K) {
            cout << "...";
            break;
        }
        cout << c;
        cnt++;
    }
    cout << endl;
}


Measured memory_bytes: 3612
using System;

namespace abc103_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int answer = 0;
            string[] array = Console.ReadLine().Split(' ');
            int[] inputs = new int[array.Length];
            for(int i = 0; i < array.Length; i++)
            {
                inputs[i] = int.Parse(array[i]);
            }
            Array.Sort(inputs);
            answer = inputs[1] - inputs[0] + inputs[2] - inputs[1];
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11220
s = input()

e=0
for x in range(0, len(s)):
  if x%2==0 and s[x] == 'L':
    e = 1

o=0
for y in range(0, len(s)):
  if y%2!=0 and s[y] == 'R':
    o = 1
    
if e==1 or o==1:
  print('No')

else:
  print('Yes')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define cast static_cast
#define vi vector<int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
typedef long long int ll;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n;
	cin>>n;
	vi a(n,0);
	for(int i=1;i*i<n;i++){
		for(int j=1;j*j<n-i*i;j++){
			for(int k=1;k*k<n-i*i-j*j;k++){
				ll h=i*i+j*j+k*k+i*j+i*k+k*j;
				if(h<=n){
					a[h-1]++;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<a[i]<<"\n";
	}
}	

int main(){
	boost_io;
	solve();
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;

int main() {
    int n;
    cin >> n;
    vector<P> a(n), b(n);
    rep(i, n){
        cin >> a[i].first >> a[i].second;
        b[i].first = a[i].second;
        b[i].second = a[i].first;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if(n % 2 == 0){
        ll mn = a[n/2-1].first + a[n/2].first;
        ll mx = b[n/2-1].first + b[n/2].first;
        cout << mx - mn + 1 << endl;
    }else{
        cout << b[n/2].first - a[n/2].first + 1 << endl;
    }
    
}

Measured memory_bytes: 9592
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;


int main() {
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll>s(a + 2), t(b + 2);
    rep(i, a)cin >> s[i + 1];
    rep(i, b)cin >> t[i + 1];
    s[0] = -1e12, t[0] = -1e12;
    s[a+1] = 1e12, t[b+1] = 1e12;
    vector<ll>ans(q);
    rep(i, q) {
        ll x, ms, mt;
        cin >> x;
        ll dis;
        int sit = lower_bound(s.begin(), s.end(), x) - s.begin();

        int tit = lower_bound(t.begin(), t.end(), x) - t.begin();
        dis = max(x - s[sit - 1], x - t[tit - 1]);

        ll cross;
        if (s[sit] > t[tit]) {
            dis = min(dis, s[sit] - x);
            cross = min(x - s[sit - 1], t[tit] - x) + (t[tit] - s[sit - 1]);
        }
        else {
            dis = min(dis, t[tit] - x);
            cross = min(s[sit]-x, x-t[tit - 1]) + (s[sit] - t[tit - 1]);
        }

        dis = min(dis, cross);
        ans[i]=dis;
    }
    
    rep(i, q)cout << ans[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if(s[1] == 'B') s[1] = 'R';
	else s[1] = 'B';
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
 
int main(void) {
    int n,p;
    
    while (1) {
       scanf("%d%d", &n, &p);
       if (!n && !p) break;
       
       int player[64] = {0};
       int stone = p;
       int i;
       
       for(i = 0; player[i] != p; i = (i+1) % n)
          if(stone > 0){
          stone--;
          player[i]++;
          }
          else if(stone == 0){
          	stone = player[i];
          	player[i] = 0;
          }
       
       printf("%d\n",i);
    }
       return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int a,b,ans=0x3f3f3f3f,mark;
int main(){
	scanf("%d%d",&a,&b);
	if(b-a+1>=2019){
		printf("0\n") ;return 0;
	}
	a%=2019,b%=2019;
	if(b<a) {
		printf("0\n");
		return 0;
	}
	for(int i=a;i<=b-1;i++){
		for(int j=a+1;j<=b;j++){
			ans=min(ans,i*j%2019);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
signed main(){
    int N;
    scanf("%d",&N);
    N%=10;
    if(N==2||N==4||N==5||N==7||N==9){
        printf("hon\n");
    }
    if(N==0||N==1||N==6||N==8){
        printf("pon\n");
    }
    if(N==3){
        printf("bon\n");
    }
    return(0);
}

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

struct edge{
  int from,to,cost;
  bool operator < (const edge &p)const{    return cost < p.cost;  }
};

int N,M,a,b,c;
bool f[20001];
vector<edge> g;

int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    g.clear();
    for(int i=1;i<=N;i++)f[i]=false;
    f[1]=true;
    for(int i=0;i<M;i++){
      scanf("%d %d %d",&a,&b,&c);
      g.push_back((edge){b,c,a});
    }
    sort(g.begin(),g.end());
    int ans=1;
    for(int i=0;i<M;i++){
      edge e=g[i];
      if(f[e.from]){
	if(!f[e.to])ans++;
	f[e.to]=true;
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

ll a[100001];
int main(){
    int n;
    cin>>n;
    rep(i,n) cin>>a[i];
    sort(a,a+n);reverse(a,a+n);
    int mx=a[0];
    if(n==2){
        cout<<a[0]<<" "<<a[1]<<endl;
        return 0;
    }
    double cur;
    if(mx%2==0) cur=mx/2;
    else cur=mx/2.0;
    double sub=1000100010;
    int id;
    rep(i,n){
        if(abs((double)a[i]-cur)<sub) sub=abs((double)a[i]-cur),id=i;
    }
    cout<<mx<<" "<<a[id]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 2e3 + 10;
int N, X, Y;
int ans[maxn];
int main()
{
    scanf("%d %d %d", &N, &X, &Y);
    for(int i = 1; i <= N - 1; i++)
        for(int j = i + 1; j <= N; j++)
            ans[min(j - i, abs(i - X) + abs(j - Y) + 1)]++;
    for(int i = 1; i <= N-1; i++)
        printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;

ll x;

ll calc(ll a, ll b) { return pow(a, 5) - pow(b, 5); }

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        res[n] = 1;
    }
    return res;
}

vector<ll> divisor(ll n) {
    vector<ll> res;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) {
                res.push_back(n / i);
            }
        }
    }
    return res;
}

int main(int argc, char const *argv[]) {
    cin >> x;
    vector<ll> v = divisor(x);
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
        ll a = v[i] / 2 + 1;
        ll b = a - v[i];
        ll result = calc(a, b);
        while (result <= x) {
            if (result == x) {
                cout << a << " " << b << endl;
                return 0;
            }
            a++;
            b++;
            result = calc(a, b);
        }
    }
    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;

template<typename T>
long long pmt(T n, T r, T MOD=(T)(1e9)+7LL){
    if(r<=0) return 1LL;
    long long res = 1LL;
    for(long long i=0; i<r; i++) res = (res * (n-i))%MOD;
    return res%MOD;
}
ll bfs(ll N, ll K, vector<vector<ll>> &G){
    ll res = K;
    ll root=0;
    queue<P> q;
    q.push(P(root, -1));
    while(q.size()){
        P x = q.front(); q.pop();
        ll v = x.first;
        ll from = x.second;
        ll color = 0;
        if(from==-1) color = K-1;
        else color = K-2;
        ll chldCnt = 0;
        for(auto nv: G[v]) {
            if(nv==from) continue;
            chldCnt++;
            q.push(P(nv, v));
        }
        if(chldCnt==0) continue; //leaf 
        if(color<chldCnt) return res = 0;  
        res = (res * pmt(color, chldCnt))%MOD;
    }
    return res%MOD;
}
signed main(){
    ll N, K;
    cin>>N>>K;
    vector<vector<ll>> G(N);
    REP(i, N-1){
        ll a, b; cin>>a>>b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    } 
    ll ans = bfs(N, K, G);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8180
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<ll> X(n), Y(m);
  rep(i, n) cin >> X[i];
  rep(i, m) cin >> Y[i];
  ll s = 0, t = 0;
  rep(i, n-1) (s += (X[i+1]-X[i]) * (n-1-i) * (i+1)) %= mod;
  rep(j, m-1) (t += (Y[j+1]-Y[j]) *  (m-1-j) * (j+1)) %= mod;
  cout << s*t%mod << endk;
  return 0;
}


Measured memory_bytes: 4752
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
using System.Threading;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int N;
        private string[] S;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            S = new string[N];
            for (int i = 0; i < N; i++)
            {
                S[i] = sc.Next();
            }
        }

        public void Solve()
        {
            Scan();
            long ans = 0;
            for (int i = 0; i < N; i++)
            {
                if (Q(i))
                {
                    ans += N;
                }
            }
            Console.WriteLine(ans);
        }

        private bool Q(int n)
        {
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    if (S[i][(j + n) % N] != S[j][(i + n) % N]) return false;
                }
            }

            return true;
        }


        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

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

int main(){
  ll n , m;
  cin >> n >> m;
  vector<ll>a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a.begin(),a.end());
  
  vector<vector<ll>>b(m,vector<ll>(2));
  for(int i=0; i<m; i++) cin >> b[i][1] >> b[i][0];
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  
  ll x = 0;
  for(int i=0; i<m; i++){
    for(int j=0; j<b[i][1]; j++){
      if(a[x]>=b[i][0] || x==n) break;
      a[x]=b[i][0];
      x++;
    }
  }
  
  ll ans=0;
  for(int i=0; i<n; i++) ans+=a[i];
  
  cout << ans << endl;
  
  return 0;
  
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define INF 114514810

int n, k;
int dist[120];
int cost[120][120];
bool used[120];

void dikstr(int s) {
    fill(dist, dist+n, INF);
    fill(used, used+n, false);
    dist[s] = 0;

    while(1) {
        int v = -1;
        rep(u,n) {
            if(!used[u] and (v==-1 or dist[u] < dist[v])) v = u;
        }
        if(v==-1) break;
        used[v] = true;

        rep(u,n)
            dist[u] = min(dist[u], dist[v] + cost[v][u]);
    }
}


int main(void) {
    while(1) {
        scanf("%d %d", &n, &k);
        if(n == 0 and k == 0) break;
        rep(i,n) rep(j,n) cost[i][j] = INF;

        rep(i,k) {
            int f,a,b,c,d,e;
            scanf("%d", &f);
            if(f == 0) {
                scanf("%d%d", &a, &b);
                a--; b--;
                dikstr(a);
                if(dist[b] >= INF) puts("-1");
                else
                    cout << dist[b] << "\n";
            } else if(f == 1) {
                scanf("%d%d%d", &c, &d, &e);
                c--; d--;
                cost[c][d] = cost[d][c] = min(cost[c][d], e);
            }
        }

        /* debug
        rep(i,n) rep(j,n) {
            printf("dist[%d][%d] = %d\n", i, j, dist[i][j]);
        }
        */
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
 
ll digits(ll n){
    ll sum = 0;
    while(n != 0){
        sum += n % 10;
        n /= 10;
    }
    return sum ;
}
int main(){
    ll n;
    cin >> n;
    ll ans = digits(n);
    if (n%ans == 0) cout<< "Yes" << endl;
    else cout << "No"<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(...) { printf("#  "); printf(__VA_ARGS__); puts(""); }
#define ll long long
#define endl "\n" 
using VI = vector <int>;
constexpr int N = 3e5 + 10;
constexpr int mod = 1e9 + 7;
template <class T1, class T2> inline void chadd(T1 &x, T2 y) { x += y; if (x >= mod) x -= mod; else if (x < 0) x += mod; } 
template <class T1, class T2> inline void chmax(T1 &x, T2 y) { if (x < y) x = y; }
template <class T1, class T2> inline void chmin(T1 &x, T2 y) { if (x > y) x = y; }
inline int rd() { int x; cin >> x; return x; }
template <class T> inline void rd(T &x) { cin >> x; }
template <class T > inline void out(T s) { cout << s << "\n"; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll qpow(ll base, ll n) { ll res = 1; while (n) { if (n & 1) res = res * base % mod; base = base * base % mod; n >>= 1; } return res; }
int n, h, w, fa[N], szep[N], szee[N];
struct node { 
	int x, y, w; 
	void scan() {
		cin >> x >> y >> w;
		y += h; 
	}
	bool operator < (const node &other) const {
		return w > other.w;
	}
}e[N];
int find(int x) {
	return fa[x] == x ? x : fa[x] = find(fa[x]);
}
void run() {
	for (int i = 1; i <= n; ++i) e[i].scan();
	sort(e + 1, e + 1 + n);
	for (int i = 1; i <= h + w; ++i) {
		fa[i] = i;
		szep[i] = 1;
		szee[i] = 0;
	}
	ll res = 0;
	for (int i = 1; i <= n; ++i) {
		int u = find(e[i].x), v = find(e[i].y), w = e[i].w;
		if (u == v) {
			if (szee[u] < szep[u]) {
				res += w;
				++szee[u];
			}
		} else {
			if (szee[u] + szee[v] < szep[u] + szep[v]) {
				res += w;
				fa[u] = v;
				szee[v] += szee[u]; ++szee[v];
				szep[v] += szep[u];
			}
		}
	}
	cout << res << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << fixed << setprecision(20);
	while (cin >> n >> h >> w) run();
	return 0;
}



Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  sort(a,a+n);
  ll ans=1;
  rep(i,n) {
    ll x=ans;
    ans*=a[i];
    if(ans>(ll)pow(10,18)||a[i]&&ans<x) {
      pr(-1);
      return;
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 4376
#set
n = gets.chomp.to_i
s = gets.chomp.split("")
count = 0
count_w = s.count('W')
count_e = n - count_w
count_ary = []
min_count = n
min_point = 0


#main
# Cumulative sum
0.upto(n - 1) do |i|
  if i == 0 then
    count_ary[i] = n - 1 - (count_w - 1) if s[i] == 'W'
    count_ary[i] = n - 1 - count_w if s[i] == 'E'
  else
    count += 1 if s[i - 1] == 'W'
    count_ary[i] = count + ((n - i - 1)  - (count_w - count - 1)) if s[i] == 'W'
    count_ary[i] = count + ((n - i - 1)  - (count_w - count)) if s[i] == 'E'
  end
end
count_ary.sort!

print ("#{count_ary[0]}\n")

# full search O(N^2)
# 0.upto(n - 1) do |i|
#   count = 0
#   if i == 0 then
#     (i + 1).upto(n - 1) do |k|
#       count += 1 if s[k] == 'E'
#     end
#   elsif i == n - 1 then
#     0.upto(i - 1) do |j|
#       count += 1 if s[j] == 'W'
#     end
#   else
#     0.upto(i - 1) do |j|
#       count += 1 if s[j] == 'W'
#     end
#     (i + 1).upto(n - 1) do |k|
#       count += 1 if s[k] == 'E'
#     end
#   end
#   min_count = count if min_count >= count
# end



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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 100100;
int n;
ll c;

ll x[N];
ll v[N];
ll bst[N];

set<pa<ll, ll> > s; 

ll solve() {
    s.clear();
    ll ans = 0;
    ll lst = c;
    ford(i, n) {
        bst[i] = x[i] + v[i] - lst;
        if (i + 1 < n) {
            bst[i] += bst[i + 1];
        }
        s.insert(mp(bst[i], i));
        lst = x[i];
    }
    umx(ans, (--s.end())->fs);
    ll cur = 0;
    lst = 0;
    forn(i, n) {
        s.erase(mp(bst[i], i));
        cur += v[i];
        cur -= 2ll * (x[i] - lst);

        ll res = 0;
        if (!s.empty()) {
            umx(res, (--s.end())->fs);
        }
        umx(ans, cur + res);
        lst = x[i];
    }
    return ans;
}

int main () {
	//std::ios::sync_with_stdio(false);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
    cin >> n >> c;
    forn(i, n) {
        cin >> x[i] >> v[i];
    }
    ll ans = solve();
    reverse(x, x + n);
    reverse(v, v + n);
    forn(i, n) {
        x[i] = c - x[i];
    }
    umx(ans, solve());
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8832
#include<iostream>
#include<bitset>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
typedef long long LL;
const int N = 40;
const int S = 18;
const LL MOD = 1e9+7;
int bounds[3];
int is_completed[1<<S];
struct State
{
	int n, sum, size;
	int hash_brown;
	State(int n, int sum=0, int size=0, int hash_brown=0):n(n),sum(sum),size(size),hash_brown(hash_brown){}
	int pop()
	{
		assert(size > 0);
		int i;
		for(i = 0; hash_brown&(1<<i); i++);
		i++;

		hash_brown >>= i;
		size--;
		sum -= i;
		return i;
	}
	int cooked_hash() const
	{
		if(sum==0)
			return 0;
		else
			return hash_brown|(1<<(sum-1));
	}
	int encode(int a)
	{
		return (1LL<<(a-1))-1;
	}
	State(State& other, int a)
	{
		this->hash_brown = other.hash_brown|(encode(a)<<other.sum);
		this->sum = other.sum+a;
		this->size = other.size+1;

		//cout<<sum<<": "<<bitset<17>(cooked_hash())<<endl;
		while(this->sum > bounds[0]+bounds[1]+bounds[2])
			this->pop();
		//cout<<sum<<": "<<bitset<17>(cooked_hash())<<endl;

		this->n = other.n-1;
	}
	bool completed(vector<int>& seq)
	{
		int i = 0;
		for(int t = 0; t < 3; t++)
		{
			int partition = 0;
			for(; i < seq.size() && partition < bounds[t]; i++)
				partition += seq[i];
			if(partition!=bounds[t])
				return false;
		}
		
		return true;
	}
	bool completed()
	{
		if(sum==0)
			return 0;
		if(is_completed[this->cooked_hash()]!=-1)
			return is_completed[this->cooked_hash()];
		State pop_first(n,sum,size,hash_brown);
		pop_first.pop();
		if(pop_first.completed())
			return is_completed[this->cooked_hash()] = true;

		//cout<<size<<endl;
		vector<int> seq(size);
		int orig_hash_brown = hash_brown;
		int orig_sum = sum;

		for(int i = 0; i < seq.size(); i++)
			seq[i] = pop();
		
		size = seq.size();
		hash_brown = orig_hash_brown;
		sum = orig_sum;

		return is_completed[this->cooked_hash()] = completed(seq);
	}
	bool operator<(const State& other)const
	{
		if(this->n != other.n)
			return this->n < other.n;
		else
			return this->cooked_hash() < other.cooked_hash();
	}
};
LL tenPow[N];
LL memo[N+1][1<<S];
LL dp(State state)
{
	if(memo[state.n][state.cooked_hash()]!=-1)
		return memo[state.n][state.cooked_hash()];
	if(state.completed())
		return memo[state.n][state.cooked_hash()] = tenPow[state.n];
	if(state.n==0)
		return 0;
	LL ans = 0;
	for(int a = 1; a <= 10; a++)
		ans = (ans+dp(State(state,a)))%MOD;
	return memo[state.n][state.cooked_hash()] = ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	tenPow[0] = 1;
	for(LL exp = 1; exp < N; exp++)
		tenPow[exp] = (tenPow[exp-1]*10LL)%MOD;
	int n; cin >> n;
	for(int i = 0; i < 3; i++)
		cin >> bounds[i];
	memset(memo,-1,sizeof memo);
	memset(is_completed,-1,sizeof is_completed);
	cout<<dp(State(n))<<endl;
	return 0;
}

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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

const int nax = 3005;
ll dp[nax][nax];

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	for (int l = n; l >= 1; --l)
		for (int j = l; j <= n; ++j)
			if (l == j)
				dp[l][j] = a[l];
			else
				dp[l][j] = max(a[l] - dp[l + 1][j], a[j] - dp[l][j - 1]);
	cout << dp[1][n];
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 70016
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mid (l+r>>1)
typedef long long ll;
template<typename T>inline T read(){
	T x=0,f=1;char c=getchar();
	for(;c<'0'||c>'9';f=c=='-'?-1:1,c=getchar());
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c=getchar());
	return x*f;
}
const int maxs=1<<19,maxn=2e5+5;
int n,v,lg,s,lt[maxs],rt[maxs],a[20][maxn],cnt[20];
ll x[maxn];
int S(int opt,int k,int x){
	int l=1,r=cnt[k];
	while(r-l>1)
		if(a[k][mid]<x||(opt&&a[k][mid]==x))l=mid+opt;
		else r=mid-1+opt;
	int r1=opt?l:r,r2=opt?r:l,f=opt?1:-1;
	if(a[k][r1]*f>x*f)return a[k][r1]+1-opt;
	return a[k][r2]+1-opt;
}
int main(){
	n=read<int>();v=read<int>();
	lg=ceil(log2(v))+1+(ceil(log2(v))==log2(v));s=(1<<lg)-1;
	for(int i=1;i<=n;i++)x[i]=read<ll>(),x[i-1]=x[i]-x[i-1];x[n]=0;
	for(int i=1;i<=lg;i++){
		cnt[i]=1;
		for(int j=1;j<=n;j++)
			a[i][cnt[i]]=j,cnt[i]+=(x[j]>v>>(i-1));
	}
	if(cnt[1]>lg){for(int i=0;i<n;i++)puts("Impossible");return 0;}
	memset(rt,0,sizeof(rt));
	for(int i=0;i<=s;i++)lt[i]=n+1;
	for(int i=0;i<=s;i+=2)
		for(int j=2;j<=lg;j++){
			int s0=1<<j-1;
			if(i&s0)continue;
			rt[i|s0]=std::max(rt[i|s0],S(1,j,rt[i]));
			lt[i|s0]=std::min(lt[i|s0],S(0,j,lt[i]-1));
		}
	for(int i=1;i<=cnt[1];i++){
		int f=0,b=a[1][i-1]+1,e=a[1][i];
		if(i==1)b=1;
		for(int s0=0;s0<=s&&(!f);s0+=2)f=(b<=rt[s0]+1&&e>=lt[s-s0-1]-1);
		for(int j=b;j<=e;j++)puts(f?"Possible":"Impossible");
	}
    return 0;
}

Measured memory_bytes: 23168
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int x,k;
int main(){
	scanf("%d%d",&x,&k);
	for(int i=k-x+1;i<=k+x-1;i++){
		if(i==k+x-1){
			printf("%d",i);
		}else{
			printf("%d ",i);
		}
	}
	return 0;
} 

Measured memory_bytes: 504
<?php
//$N = (int)trim(fgets(STDIN));
$S = trim(fgets(STDIN));
//list($N,$Q) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

if (ctype_upper($S)) {
  printf("A\n");
}
else {
  printf("a\n");
}

Measured memory_bytes: 15992
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define ll long long
#define Test int t;cin>>t;while(t--)
using namespace std;
const int dx[]={-1,-1,-1,0,0,0,1,1,1};
const int dy[]={-1,0,1,-1,0,1,-1,0,1};
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int a[200001];
int main()
{
    fast();
    double r;
    cin>>r;
    const double PI=3.141592653589793116;
    cout<<fixed<<setprecision(20)<<PI*2*r;
    return 0;
}


Measured memory_bytes: 3780
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(long int*)a - *(long int*)b;
}

int main(){
  int N,i,b;
  scanf("%d",&N);
  long int A[N],B[N];
  for(i=0;i<N;i++){
    scanf("%ld",&A[i]);
    B[i]=A[i]-i-1;
  }

  qsort(B, N, sizeof(long int), compare_int);

  if(N%2==1){
    b=B[(N-1)/2];
  }else{
    b=(B[N/2-1]+B[N/2])/2;
  }
  long int ANS=0;
  for(i=0;i<N;i++){
    if(B[i]-b>0){
      ANS=ANS+B[i]-b;
    }else{
      ANS=ANS+b-B[i];
    }
  }
  printf("%ld",ANS);
  return 0;
}
  
    
  

    


Measured memory_bytes: 4860
from copy import deepcopy
from itertools import accumulate

n, c = map(int, input().split())
x = []
v = []
# print(n, c)
# c //= 100000000
for _ in range(n):
    _x, _v = map(int, input().split())
    # _x //= 100000000
    # _v //= 100000000
    x.append(_x)
    v.append(_v)
# print(x, v)
v1 = list(accumulate(v)) # CW
v2 = list(accumulate(v[::-1])) # CCW
# print(v1, v2)
f1 = [0] * (n + 1)
f2 = [0] * (n + 1)
for i in range(n):
    f1[i + 1] = v1[i] - x[i]
    f2[i + 1] = v2[i] - (c - x[n - 1 - i])
# print(f1, f2)
g1 = [0] * (n + 1)
g2 = [0] * (n + 1)
for i in range(n):
    g1[i + 1] = max(g1[i], f1[i + 1])
    g2[i + 1] = max(g2[i], f2[i + 1])
# print(g1, g2)
ans = 0
ans = max(ans, g1[n]) # CW only
ans = max(ans, g2[n]) # CCW only
for j in range(n): # CCW then CW
    cal = 0
    cal -= (c - x[n - 1 - j]) * 2
    cal += v2[j]
    cal += g1[n - 1 - j]
    ans = max(ans, cal)
    # print(j, (c - x[n - 1 - j]) * 2, v2[j], g1[n - 1 - j], cal)
for j in range(n): # CW then CCW
    cal = 0
    cal -= (x[j]) * 2
    cal += v1[j]
    cal += g2[n - 1 - j]
    ans = max(ans, cal)
    # print(j, x[j] * 2, v1[j], g2[n - 1 - j], cal)
print(ans)

Measured memory_bytes: 30408
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
 
int main() {
 	
 	ll i, j, k, l, test, n, pos;
 	
 	cin>>test>>n;
 	
 	std::vector<string> a(test);
 	for(i=0;i<test;i++) cin>>a[i];
 	
 	sort(a.begin(), a.end());
 	
 	for(i=0;i<test;i++) cout<<a[i];
}

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

using namespace std;

typedef long long ll;

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

    int N, K;
    cin >> N >> K;

    if (N % K == 0) cout << 0 << endl;
    else cout << 1 << endl;
}

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

int main() {
	string w,t;
	cin >> w;
	int ans = 0;
	cin >> t;
	while (t != "END_OF_TEXT") {
		int i;
		int s = t.size();
		for (i = 0; i < s; i++) {
			if ('A'<= t[i] && t[i] <= 'Z') {
				t[i] += 'a' - 'A';
			}
		}
		if (w == t) {
			ans++;
		}
		cin >> t;
		
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3208
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const int MAX = 1e5+5;



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

	for (int i = 0; i < k; i++) {
		vector<int> b(n);
		for (int j = 0; j < n; j++) {
			int l = max(0, j - a[j]);
			int r = min(n - 1, j + a[j]);
			b[l]++;
			if (r + 1 < n) {
				b[r + 1]--;
			}
		}
		for (int j = 1; j < n; j++) {
			b[j] += b[j - 1];
		}

		bool isEnd = true;
		for (int j = 0; j < n; j++) {
			if (a[j] != n) {
				isEnd = false;
				break;
			}
		}

		if (isEnd) {
			for (int j = 0; j < n; j++) {
				cout << n << " ";
			}
			cout << endl;
			return 0;
		}
		a = b;
	}

	for (int ai : a) {
		cout << ai << " ";
	}

	cout << endl;
}

Measured memory_bytes: 4832
#include <iostream>
#include <cmath>

using namespace std;

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

    int N; cin >> N;

    if(N%2==0){
        cout << "0.5\n";
    }else {
        double ans = N/2 + 1;
        ans /= N;
        printf("%.12f",ans);
    }
}

Measured memory_bytes: 256