akhauriyash/Code-Regression huggingface dataset:
/*
   THE DARK NIGHT RISES
I LOVE YOU 72 AND WILL FOREVER DO SO
Patience, Persistence, Perseverance, Passion, Purpose
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = 2e5 + 20 ;
#define F first
#define S second
# define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mk make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x)       (int)x.size()
const long long int mod=1e9 + 7;
const long double EPS=1e-12;
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )
 
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 

int solve()
{
  ll a ,b ;
  cin >> a >> b ;
  cout << ((a*b)/__gcd(a,b)) ;
	
}
int main()
{
	fast;
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
 
	return 0;
}
// Patience, Persistence, Perseverance, Passion, Purpose
// I LOVE YOU 72 AND WILL FOREVER DO SO.

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF 100000000

int main() {
    int N, M;
    while (cin >> N >> M, N|M) {
        vi c(M), x(N);
        REP(i, M) cin >> c[i];
        REP(i, N) cin >> x[i];

        vvi dp(N+1, vi(256, INF));
        dp[0][128] = 0;
        FOR(i, 1, N+1) {
            REP(y, 256) {
                if (dp[i-1][y] == INF) continue;
                REP(j, M) {
                    int yy = max(0, min(y + c[j], 255));
                    dp[i][yy] = min(dp[i][yy], dp[i-1][y] + SQ(x[i-1] - yy));
                }
            }
        }
        cout << *min_element(ALL(dp[N])) << endl;
    }
}

Measured memory_bytes: 23712
n = int(input())
t, a = [int(i) for i in input().split()]
h = [int(j) for j in input().split()]
value = 100000
ret = 0
for i, k in enumerate(h):
    tmp = abs((t - k * 0.006) - a)
    if tmp < value:
        ret = i
        value = tmp
print (ret + 1)

Measured memory_bytes: 3060
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(b-a == c-b){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const long long MOD = 1e9 + 7;
long long nCr[2001][2001] = {0};

int main(){
	long long N, K;
	cin >> N >> K;

	for (int i = 0; i < 2001; i++){
		for (int j = 0; j <= i; j++){
			nCr[i][j] = (j == 0)? 1 : (nCr[i - 1][j] + nCr[i - 1][j - 1]) % MOD;
		}
	}

	for (int i = 1; i <= K; i++){
		cout << (nCr[K - 1][i - 1] * nCr[N - K + 1][i]) % MOD << endl;
	}
	return 0;
}


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

using namespace std;

typedef long long         ll;
typedef pair <int,int>    ii;
typedef vector <int>      vi;
typedef vector <int,int>  vii;

#define INF 2000000000
#define pb push_back
#define what_is(x) cerr <<#x<<" is "<<x<<endl;

int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
    int n,a,b;
    cin>>n>>a>>b;
    int k=0;
    while(n--)
    {
        int t1,t2;
        cin>>t1>>t2;
        if(t1>=a&&t2>=b) k++;
    }
    cout<<k;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int64_t al[MAXN][26];

int main()
{
  string S;
  cin >> S;
  for (int i = 1; i < S.size(); i++)
  {
    if (S[i - 1] == S[i])
    {
      cout << i << ' ' << i + 1 << endl;
      return 0;
    }
    if (i != 1 && S[i - 2] == S[i])
    {
      cout << i - 1 << ' ' << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << ' ' << -1 << endl;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define INF 100'000

int main() {
    i64 N, M, Q; cin >> N >> M >> Q;
    i64 mina = INF;
    i64 minb = INF;
    vector<i64> A(N); REP(i, N) cin >> A[i], chmin(mina, A[i]);
    vector<i64> B(M); REP(i, M) cin >> B[i], chmin(minb, B[i]);

    i64 minv = mina + minb;
    REP(i, Q) {
        i64 x, y, disc; cin >> x >> y >> disc;
        x--, y--;
        chmin(minv, A[x] + B[y] - disc);
    }

    cout << minv << endl;

    return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if(a < b){
        cout << "a < b" << endl;
    }else if(a == b){
        cout << "a == b" << endl;
    }else{
        cout << "a > b" << endl;
    }
}

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

int main(){
  int a, b = 0, s = 1, v;
  cin >> a;
  
  vector<int> x(a);
  for (int i = 0; i < a; i++){
    cin >> x.at(i);
  }
  while (x.at(b) != 2){
    if (x.at(b) == 0){
      s = -1;
      break;
    }
    else {
      v = b;
      s++;
      b = x.at(b) - 1;
      x.at(v) = 0;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <map>

using namespace std;

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

	int N;
	cin >> N;

	map<string, long long> scount;

	for (int i = 0; i < N; i++)
	{
		string s;
		cin >> s;

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

		scount[s]++;
	}

	long long result = 0;
	for (auto e : scount)
	{
		result += e.second * (e.second - 1) / 2;
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 11264
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;

int main(){
	string str;
	char m[10000],a[10000],p,c[10000];
	char b[10][5]={{'-','-','-','-','-'},{'.',',','!','?',' '},{'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','-'}};
	int n;
	int d=-1;
	int e=0;
	int j;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>str;
		p=0;
		j=0;
		d=-1;
		e=0;
		for(int i=0;i<str.size();i++){
			if(i==0){
				d=0;
				e=str[i]-'0';
			}
			else if(str[i-1]!=str[i]){
				if(str[i-1]!='0'){
					c[j]=b[e][d];
					j++;
				}
				d=0;
				e=str[i]-'0';
			}
			else{
				d++;
				if(b[e][d]=='-' || d==5){
					d=0;
				}
			}
		}
		for(int i=0;i<j;i++){
			cout<<c[i];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int main () {
    int ans = 1;
    int x;
    cin >> x;
    for (int i = 2; i*i <= x; i++) {
        for (int j = i*i; j <= x; j*=i) {
            ans = max(ans, j);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <locale>
#include <algorithm>
using namespace std;
bool compa(int i, int j){
	return (i>j);
}
int main(){
	int N;
	cin>>N;
	vector<int> aarr;
	int Ai;
	for (int i = 0; i < N; i++)
	{
		cin>>Ai;
		aarr.push_back(Ai);
	}
	sort(aarr.begin(),aarr.end(),compa);
	int resultado = 0;
	for (int i = 0; i < N; i++)
	{
		if(i%2==0){
			resultado -=aarr[i];
		}else{
			resultado +=aarr[i];
		}
	}
	cout<<abs(resultado);
	return 0;
}

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

int main(void) {
  int a, b; cin >> a >> b;
  if (a > 0) cout << "Positive" << endl;
  else if (a <= 0 && 0 <= b) cout << "Zero" << endl;
  else if ((b-a)%2 == 0) cout << "Negative" << endl;
  else cout << "Positive" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

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

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

int main()
{
	int N;
	input(N);

	ll res = 0;
	rep(i, 1, N + 1)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			res += i;
		}
	}

	cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	int Size=S.size();
	if (Size==1){
		cout<<0<<endl;
		return 0;
	}
	string S1,S2;
	bool bSetZero=true;
	bool bSetOne=true;
	int i;
	for (i=0;i<Size;i++){
		if (bSetZero){
			S1+='0';
			bSetZero=false;
		}else{
			S1+='1';
			bSetZero=true;
		}
		if (bSetOne){
			S2+='1';
			bSetOne=false;
		}else{
			S2+='0';
			bSetOne=true;
		}
	}
	int MinNum=Size;
	int Num=0;
	for (i=0;i<Size;i++){
		if (S[i]!=S1[i]){
			Num++;
		}
	}
	if (MinNum>Num){
		MinNum=Num;
	}

	Num=0;
	for (i=0;i<Size;i++){
		if (S[i]!=S2[i]){
			Num++;
		}
	}
	if (MinNum>Num){
		MinNum=Num;
	}
	cout<<MinNum<<endl;
	return 0;
}

Measured memory_bytes: 768
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
//const input = fs.readFileSync('./input.txt', 'utf8');

_d(input);

function _d(input: string) {
  const [N, _A] = input.split('\n');
  const A = _A.split(' ').map((s) => parseInt(s));

  let money = 1000n; // 所持金
  let stock = 0n; // 株式

  // 明日が今日より良ければ全部買う
  // 同じなら何もしない
  // そうでなければ全部売る

  for (let index = 0; index < A.length - 1; index++) {
    const today = BigInt(A[index]);

    if (A[index] < A[index + 1]) {
      // 値上がりするので全部買う
      const trade = money / today;
      money -= trade * today;
      stock += trade;
    } else if (A[index] > A[index + 1]) {
      // 値下がりするので全部売る
      money += stock * today;
      stock = 0n;
    } else {
      // 何もしない
    }
  }

  // 残っている株式を売却
  money += stock * BigInt(A[A.length - 1]);

  console.log(money.toString());
}


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

int main() {
    int a, b;
    char op;

    while(1) {
        // 読み込み
        cin >> a >> op >> b;
        
        if (op == '+') {
            cout << (a + b) << endl;
        } else if (op == '-') {
            cout << (a - b) << endl;
        } else if (op == '*') {
            cout << (a * b) << endl;
        } else if (op == '/') {
            cout << (a / b) << endl;
        } else {
            break;
        }
    }

    return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<long long>T(n);
  int ans=0;
  for(int i=0;i<n;i++){
    cin>>T.at(i);
    ans=ans+T.at(i);
  }
  int ANS=ans;
  int m;
  cin>>m;
  vector<long long>X(m);
  vector<int>P(m);
  for(int i=0;i<m;i++){
    cin>>P.at(i)>>X.at(i);
  }
  for(int i=0;i<m;i++){
    cout<<ans-T.at(P.at(i)-1)+X.at(i)<< endl;
  }
}
    
  

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll K, S;
    ll count = 0;
    cin >> K >> S;
    for(ll x = 0;x <= K;x++) {
        for(ll y = 0;y <= K;y++) {
            ll temp = S - (x + y);
            if(0 <= temp && temp <= K) count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void bigswap(int *a,int *b){
if(*a > *b){
int temp = *a;
*a = *b;
*b =temp;
}

}


int main(void){
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);

    bigswap(&b,&c);
    bigswap(&a,&b);
    bigswap(&b,&c);
    printf("%d %d %d\n",a,b,c);
    return 0;
}


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

int n, ma, mb, inf = 1e9 + 7, dp[50][410][410];

int main()
{
    cin >> n >> ma >> mb;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
    }
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= 400; j++)
        {
            for (int k = 0; k <= 400; k++)
            {
                dp[i][j][k] = inf;
            }
        }
    }
    dp[0][0][0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= 400; j++)
        {
            for (int k = 0; k <= 400; k++)
            {
                if (dp[i][j][k] == inf)
                    continue;
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
            }
        }
    }
    int ans = inf;
    for (int i = 1; i <= 400; i++)
    {
        for (int j = 1; j <= 400; j++)
        {
            if (i * mb == j * ma)
                ans = min(ans, dp[n][i][j]);
        }
    }
    if (ans == inf)
        ans = -1;
    printf("%d\n", ans);
}


Measured memory_bytes: 28928
S = input()

word_lst = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(word_lst)):
  word_lst[i] = word_lst[i][::-1]
  
S = S[::-1]
ans = ''
while len(ans) < len(S) - 4:
  if S[len(ans)] == 'm':
    ans = ans + word_lst[0]
  elif S[len(ans):len(ans)+3] == 'rem':
    ans = ans + word_lst[1]
  elif S[len(ans)] == 'e':
    ans = ans + word_lst[2]
  elif S[len(ans):len(ans)+3] == 'res':
    ans = ans + word_lst[3]
  else:
    break

if ans == S:
  print('YES')
else:
  print('NO')
  



Measured memory_bytes: 3316
#include<cstdio>
#include<cstdlib>


int gcd(int a, int b)
{
	int c;

	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


int main(void)
{
	int n, x;

	while(scanf("%d%d", &n, &x)==2)
	{
		int ans=-1;

		for(int i=0;i<n;i++)
		{
			int v;
			scanf("%d", &v);
			if(i==0)
			{
				ans=abs(v-x);
			}
			else
			{
				ans=gcd(ans, abs(v-x));
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 128
s = list(input())
t = list(input())

candi = []

for i in range(len(s)-len(t)+1):
    c = 0
    k = s[:]
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j] == '?':
            k[i+j] = t[j]
            c += 1
    
    
    if c == len(t):
        candi.append(k)

if len(candi) == 0:
    print('UNRESTORABLE')
    
else:
    for i in range(len(candi)):
        for j in range(len(s)):
            if candi[i][j] == '?':
                candi[i][j] = 'a'

    candi = sorted(candi)

    print(''.join(candi[0]))
        

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
 int im[4],bl[4],i,hit,blow,j;
 
 while(scanf("%d %d %d %d",im,im+1,im+2,im+3)!=EOF){
  scanf("%d %d %d %d",bl,bl+1,bl+2,bl+3);
  for(hit=0,blow=0,i=0;i<4;i++){
   if(im[i]==bl[i]) hit++;
   for(j=0;j<4;j++)
    if(i!=j&&im[i]==bl[j]) blow++;
  }
  printf("%d %d\n",hit,blow);
 }

 return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

const ll MOD = TEN(9) + 7;
const int maxn = 60;
const int maxk = 2600;

ll dp[maxn][maxn][maxk];

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

    dp[0][0][0] = 1;

    rep(i, n) {
        rep(j, maxn) {
            rep(k, maxk) {
                if (dp[i][j][k] == 0) continue;
                //from left to right
                if (j) {
                    (dp[i+1][j][k+j*2] += dp[i][j][k] * j) %= MOD;
                }
                //from left to left
                if (j) {
                    (dp[i+1][j-1][k+j*2] += dp[i][j][k] * j * j) %= MOD;
                }
                //from right to left
                (dp[i+1][j][k+j*2] += dp[i][j][k] * j) %= MOD;
                //from right to right
                (dp[i+1][j+1][k+j*2] += dp[i][j][k]) %= MOD;

                //same
                (dp[i+1][j][k+j*2] += dp[i][j][k]) %= MOD;
            }
        }
    }
    cout << dp[n][0][S] << endl;

    return 0;
}

Measured memory_bytes: 61696
#include<stdio.h>
#include<string.h>
bool check(int i){
    int ans=0;
    while(i){
        i/=10;
        ans++;
    }
    if(ans&1)
        return true;
    else return false;
}
int main(){
    int n;
    while(~scanf("%d",&n)){
        int res=0;
        for(int i=1;i<=n;i++){
            if(check(i))
                res++;
        }
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 128
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort()
q.sort()
r.sort(reverse=True)
del p[:a-x]
del q[:b-y]

s=p+q
s.sort()
if s[0]<r[0]:
    s[0]=r[0]
    for i in range(1,c):
        if s[i]>=r[i]:
            break
        else:
            s[i]=r[i]

print(sum(s))


Measured memory_bytes: 23328
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,m,c;
	int b[11111]={};
	cin>>n>>m>>c;
	FOR(i,0,m)cin>>b[i];
	int ans=0;
	FOR(i,0,n){
		LL tmp=c;
		FOR(j,0,m){
			int a;
			cin>>a;
			tmp+=a*b[j];
		}
		if(tmp>0)ans++;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int L;
	cin >> L;
	cout <<fixed<< (double)(L * L * L / 3.0 / 3.0 / 3.0) << endl;
	return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long i,n;
	cin>>n;
	for(i=sqrt(n);i>=1;i--){
		if(n%i==0){
			int x=n/i;
			int j=0;
			while(x>0){
				x/=10;
				j++;
			}
			cout<<j<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
   int A,B,K;
   cin>>A>>B>>K;
   if(B-A+1<=2*K){
      for(int i=A;i<=B;i++){
         cout<<i<<endl;
      }
   }
   else{
       for(int i=A;i<A+K;i++){
          cout<<i<<endl;
       }
       for(int i=B-K+1;i<=B;i++){
          cout<<i<<endl;
       }
   }
   return 0;
}

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

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll n;
	cin>>n;
	double p[n+1];
	lp(i,1,n)
		cin>>p[i];
	double dp[n+1][n+1];
	dp[0][0]=1;
	for(ll i=1 ; i<=n; i++){
		dp[0][i]=(1-p[i])*dp[0][i-1];
		for(ll j=1; j<=i; j++){
			dp[j][i]=p[i]*dp[j-1][i-1]+(1-p[i])*dp[j][i-1];
		}
	}
	ld ans=0;
	for(ll i=(n+1)/2; i<=n; i++ )
		ans+=dp[i][n];
	cout<<setprecision(15)<<ans<<endl;

	return 0;	
}


Measured memory_bytes: 49932
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }
};

template <class Integer>
Integer ceil(Integer x, Integer y)
{
    return (x + y - 1) / y;
}

int main()
{
    input in;
    output out;

    int N, D;
    in >> N, D;
    out << ceil(N, 1 + D * 2);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

ll f(ll a){
    if(a==-1) return 0;
    else if(a%4==3) return 0;
    else if(a%4==2) return a^1;
    else if(a%4==1) return 1;
    else return a;
}

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<(f(a-1)^f(b))<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if(s == u) a -= 1;
  else if(t == u) b -= 1;
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 3640
K,A,B=map(int,input().split())
bis=1
en=0

if B-(A+2)<0:
  print(K+1)
else:
  c=K-(A-1)
  bis=A
  if c%2==0:
    bis += (c//2)*(B-A)
  else:
    bis += (c//2)*(B-A) +1
  print(bis)

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

using namespace std;

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

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	cout << a + b + c + max({a,b,c})*(pow(2, k)-1) << endl;

	return 0;
}

Measured memory_bytes: 384
n = int(input())

if 400 <= n <= 599:
    print(8)
elif 600 <= n <= 799:
    print(7)
elif 800 <= n <= 999:
    print(6)
elif 1000 <= n <= 1199:
    print(5)
elif 1200 <= n <= 1399:
    print(4)
elif 1400 <= n <= 1599:
    print(3)
elif 1600 <= n <= 1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 9120
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

template <typename T> std::vector<T> make_v(usize a) {
  return std::vector<T>(a);
}
template <typename T, typename... Ts> auto make_v(usize a, Ts... ts) {
  return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type fill_v(T &t,
                                                                   const V &v) {
  t = v;
}
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

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

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <utility>

namespace null_null {

void main_() {
  usize N;
  std::cin >> N;
  std::vector<usize> a(N + 1, 0), ans(N + 1, 0), pla;
  for (usize i = 1; i <= N; i++) {
    std::cin >> a[i];
  }

  for (usize i = N; i >= 1; i--) {
    usize sum = 0;
    for (usize j = 2; j * i <= N; j++) {
      sum += ans[j * i];
    }
    if (sum % 2 != a[i]) {
      ans[i] = (ans[i] + 1) % 2;
    }
  }

  for (usize i = 1; i <= N; i++) {
    if (ans[i]) {
      pla.push_back(i);
    }
  }

  std::cout << pla.size() << std::endl;
  for (usize i = 0; i < pla.size(); i++) {
    std::cout << pla[i] << std::endl;
  }
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


Measured memory_bytes: 4980
#!/usr/bin/env python3
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

h, w, n = [int(item) for item in input().split()]
blk_cnt = defaultdict(int) 

for i in range(n):
    a, b = [int(item) - 1 for item in input().split()]
    for j in range(-1, 2):
        for k in range(-1, 2):
            blk_cnt[(a + j, b + k)] += 1
ans = [0] * 10 
for key in blk_cnt.keys():
    if key[0] < 1 or key[1] < 1 or key[0] >= h-1 or key[1] >= w-1:
        continue
    ans[blk_cnt[key]] += 1
total = (w - 2) * (h - 2)
ans[0] = total - sum(ans)
for item in ans:
    print(item)

Measured memory_bytes: 166836
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<int> vi;

signed main(){
    char b;
    cin >> b;
    if(b == 'A') puts("T");
    if(b == 'T') puts("A");
    if(b == 'G') puts("C");
    if(b == 'C') puts("G");
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b);
#define mins(a,b) a=min(a,b);

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int fac(int a){
    if(a)return 1;
    else return a*fac(a-1);
}

int main(){
   
    int n;cin>>n;
    vd x(n),y(n);rep(i,n)cin>>x[i]>>y[i];

    double ans=0;

    int f=fac(n-1);
    rep(i,n){
        rep(j,n){
            ans+=2*f* sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
        }
    }

    printf("%.10f\n",ans/(2*f*n));
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int t = 60 * (h2 - h1) + m2 - m1;
	cout << t - k << '\n';
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9 + 7
#define cae cout << ans << endl;
#define cye cout << "Yes" << endl;
#define cne cout << "No" << endl;
#define r0 return 0;
using namespace std;
typedef pair<int,int>P;
typedef long long ll;
signed main() {
    int k, n;
    int a[300000];
    cin >> k >> n;
    rep(i, n) {
        cin >> a[i];
    }
    int mx = k - (a[n - 1]-a[0]);
    rep(i, n) {
        mx = max(mx, a[i + 1] - a[i]);
    }
    cout << k - mx << endl;
    r0
}


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


def main():
    a, b, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    min_a = min(a)
    min_b = min(b)
    ans = min_a + min_b

    for i in range(m):
        xi, yi, ci = map(int, input().split())
        xi -= 1
        yi -= 1

        ans = min(ans, a[xi] + b[yi] - ci)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()



int main() {
    ll n, m, a[1005], b[1005], r[1005], c[1005], ans = 1;
    cin >> n >> m;
    REP(i,n) cin >> a[i];
    REP(i,m) cin >> b[i];
    sort(a,a+n);
    sort(b,b+m);
    fill(r,r+n,m);
    fill(c,c+m,n);
    REP(i,n-1){
        if(a[i]==a[i+1])ans = 0;
    }
    REP(i,m-1){
        if(b[i]==b[i+1])ans = 0;
        //cout << b[i] << " ";
    }
    for(int k = n*m; k>0; k--){
        int i = lower_bound(a,a+n,k)-a;
        int j = lower_bound(b,b+m,k)-b;
        //cout << "ij " << i << " " << j << endl;
        if(a[i]==k && b[j]==k){
            
        }
        else if(a[i]==k){
            ll tmp = m-j;
            ans *= tmp;
            //cout << "tmp=" << tmp << endl;
        }
        else if(b[j]==k){
            ll tmp = n-i;
            ans *= tmp;
            //cout << "tmp=" << tmp << endl;
        }
        else{
            ll tmp = 0;
            for(int x=i;x<n;x++){
                tmp += r[x]-j;
                //cout << r[x]-j << " ";
            }
            //cout << endl;
            ans *= max(0ll,tmp);
            //cout << "tmp=" << tmp << endl;
        }
        r[i]--;
        c[j]--;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
dislike = list(map(int, input().split()))
 
for i in range(N, 10*N+1):
    num = list(map(int,str(i)))
    match = list(set(num) & set(dislike))
    if len(match)==0:
        print(i)
        break

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int n, k;
    string s;
    cin >> n >> k >> s;

    s[k - 1] = s[k - 1] - 'A' + 'a';

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    if(A < 10 && B < 10){
      System.out.println(A*B);
    }else{
      System.out.println(-1);
    }
  }
}


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


#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1e9 + 7ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;

int n, k;
vector<int> D;

int gcc(int n, int m) {
    int a = max({n, m});
    int b = min({n, m});
    if(b == 0) return a;
    int c;
    while(a % b != 0){
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}

int main() {   
    scanf("%d%d", &n, &k);
    rp(i, 0, n){
        int d;
        scanf("%d", &d);
        D.emplace_back(d);
    }
    int ans = 0;


    rp(i, 1, k+1){
        if(i > n) break;

        vector<int> get(i);
        rp(j, 0, i+1){
            rp(t, 0, j) get.at(t) = D.at(t);
            rp(t, j, i) get.at(t) = D.at(n-1-(t-j));
            sort(get.begin(), get.end());
            int now = 0;
            rp(t, 0, i){
                if(get.at(t) < 0 and t+1 <= k-i) continue;
                now += get.at(t);
            }
            chmax(ans, now);
        }
        
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AthleteProgramming2
{
    class Program
    {
        static void Main()
        {
            int[] ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = ab[0];
            int b = ab[1];
            if (a + b >= 10)
            {
                Console.WriteLine("error");
            }else
            {
                Console.WriteLine(a+b);
            }
        }
    }
}


Measured memory_bytes: 13396
// https://atcoder.jp/contests/abc167/tasks/abc167_d
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 200005

int a[MAX_N];
int history[MAX_N];
int main() {
	int n;
	ll k;
	cin >> n >> k;
	rep(i,n){
		int id;
		cin >> id;id--;
		a[i] = id;
	}
	memset(history,-1,sizeof(history));
	vector<int> dst(n);
	ll cnt = 0;
	dst[0] = 0;
	history[0] = 0;
	ll offset = 0;
	ll loop = 0;
	while(true){
		cnt++;
		dst[cnt] = a[dst[cnt-1]];
		if(history[dst[cnt]]>=0){
			offset = history[dst[cnt]];
			loop = cnt - offset;
			break;
		}
		history[dst[cnt]] = cnt;
	}
	int ans;
	if(k<=offset){
		ans = dst[(int)k]+1;
	}else{
		ans = dst[(int)(offset+((k-offset)%loop))]+1;
	}
	outl(ans);

    return 0;
}



Measured memory_bytes: 5612
N = int(input())

E = []
es = [[] for _ in range(N)]
for j in range(N):
    s = input()
    e = []
    for i, c in enumerate(s):
        e.append(1 if c=="1" else float("inf"))
        if c=="1":
            es[i].append(j)
    E.append(e)

# http://prd-xxx.hateblo.jp/entry/2017/10/13/004256

#n個の頂点の色を初期化。0:未着色、1:黒、-1:白
colors = [0 for i in range(N)]

#頂点vをcolor(1 or -1)で塗り、再帰的に矛盾がないか調べる。矛盾があればFalse
def dfs(v,color):
    #今いる点を着色
    colors[v] = color
    #今の頂点から行けるところをチェック
    for to in es[v]:
        #同じ色が隣接してしまったらFalse
        if colors[to] == color:
            return False
        #未着色の頂点があったら反転した色を指定し、再帰的に調べる
        if colors[to] == 0 and not dfs(to, -color):
            return False
    #調べ終わったら矛盾がないのでTrue
    return True

if not dfs(0, 1):
    print(-1)
    exit()

for i in range(N):
    E[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            E[i][j] = min(E[i][j], E[i][k]+E[k][j])

ans = 0
for e in E:
    ans = max(ans, max(e))
print(ans+1)


Measured memory_bytes: 69212
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
	int h2(int key){ return 1+(key % (M-1)); }

int find(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0){return 1;}
		else if(strlen(H[h])==0){return 0;}
	}
	return 0;
}

int insert(char str[]){
	long long key;
	long long i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0){return 1;}
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 16104
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using Graph = vector<VE>;
int dp[200010];
vector<int>t;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	cout << n * n*n << endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right, insort_left
dict = {}
keytbl = []
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = a[1]
	if a[0] == '0':
		if ki not in dict:
			insort_left(keytbl, ki)
		dict[ki] = int(a[2])
	elif a[0] == '1':
		print(dict[ki] if ki in dict else 0)
	elif a[0] == '2':
		if ki in dict: dict[ki] = 0
	else:
		L = bisect_left (keytbl, a[1])
		R = bisect_right(keytbl, a[2], L)
		for j in range(L, R):
			if dict[keytbl[j]] > 0: print(keytbl[j], dict[keytbl[j]])



Measured memory_bytes: 38792