akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define rep(i,n) for(i=0;i<n;i++)
#define INF 100000000
#define min(a,b) (a<b?a:b)
int main(){
	int i,j,k,n,m,bit,next,cur,r,newCost,ret;
	int land[200][200] , ship[200][200] , R[1000] ,dp[2][200];
	while(scanf("%d%d",&n,&m) && n){
		rep(i,200)rep(j,200)land[i][j] = ship[i][j] = INF;
		rep(i,200)land[i][i] = ship[i][i] = 0;
		
		rep(i,m){
			char t;
			int a,b,c;
			scanf("%d %d %d %c\n",&a,&b,&c,&t);
			a--,b--;
			if(t=='L')land[a][b] = land[b][a] = min(c,land[a][b]);
			else  ship[a][b] = ship[b][a] = min(c,ship[a][b]);
		}
		rep(k,n)rep(i,n)rep(j,n)land[i][j] = min(land[i][j],land[i][k]+land[k][j]);
		rep(k,n)rep(i,n)rep(j,n)ship[i][j] = min(ship[i][j],ship[i][k]+ship[k][j]);
		
		scanf("%d",&r);	
		rep(i,r)scanf("%d",&R[i]) , R[i]--;
		
		rep(j,2)rep(k,200)dp[j][k] = INF;
		dp[0][R[0]] = 0;
		
		rep(bit,r-1){
			rep(cur,n){
				rep(next,n){
					newCost = dp[bit%2][cur] + land[R[bit]][cur] + ship[cur][next] + land[next][R[bit+1]];
					dp[(bit+1)%2][next] = min( dp[(bit+1)%2][next],newCost);
				}
				dp[(bit+1)%2][cur] = min(dp[(bit+1)%2][cur],dp[bit%2][cur]+land[R[bit]][R[bit+1]]);
			}
			rep(j,200)dp[bit%2][j] = INF;
		}
		ret = INF;
		rep(i,n)ret = min(dp[(r-1)%2][i],ret);
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 736
n = gets.to_i
m = Array.new(n)
for i in 0..n-1
  m[i] = Array.new(n,0)
end
for i in 0..n-1
  temp = gets.chomp.split(" ").map(&:to_i)
  if temp[1] != 0
    for j in 0..temp[1]-1
      m[i][temp[j+2]-1] = 1
    end
  end
end
m.each do |r|
  puts r.join(" ")
end

Measured memory_bytes: 8856
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  long long Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  cout << N/2*min(8*Q, min(4*H, min(2*S, D)))+ N%2*min(4*Q, min(2*H, S)) <<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

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

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	set<int> a;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;

		if (a.count(x))
		{
			println("NO");
			return 0;
		}
		else
		{
			a.insert(x);
		}
	}

	println("YES");
}


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

#define maxn 6
#define INF 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
using namespace std;

char buf[maxn];

void slove()
{
	cin >> buf;
	if (buf[2] == buf[3] && buf[4] == buf[5])
		cout << "Yes\n";
	else
		cout << "No\n";
}

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

	slove();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	double k;
	cin>>n;
	if (n%2==0)  k=0.5;
	else k=((n/2)+1)*1.0/n;
	cout<<fixed<<setprecision(10)<<k<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>

#include <algorithm>
#include <vector>
using namespace std;


//関数1
//与えらえた文字列を二分割する関数
//アドレス
int evenChar(string str,string& stra,string& strb) {
	int num = str.length();
	int bet = num / 2;
	for (int i = 0; i < bet; i++) {

		stra = stra + str[i];
		strb = strb + str[bet + i];

	}
	bool hantei = false;
	int l = 0;
	if (stra == strb) {

		hantei = true;
		l = str.length();
	}
	
	return l;
	

}

//関数2
//文字列を切って長さを縮小する
//2文字以下なら処理を終了する
void mySplit(string& str) {

	//奇数なら1文字切り取る
	//偶数なら2文字切り取る

	int len = str.length();
	if (len % 2 == 0) {

		str = str.substr(0, len - 2);


	}
	else {

		str = str.substr(0, len - 1);
	}

}



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

	string strA = "";
	string strB = "";
	int len = 0;
	
	//一文字以上切り出すのが条件なので
	str = str.substr(0, str.length()-2);

	while (str.length() > 1) {

		len = evenChar(str, strA, strB);
		
		if (len > 0) break;
		else {
			strA = "";
			strB = "";
			mySplit(str);
		}


	}


	if (len != 0) cout << len;
	
	return 0;

	

}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();
		int m = Integer.MAX_VALUE;

		m = Math.min(m, (p + q));
		m = Math.min(m, (p + r));
		m = Math.min(m, (q + r));

		System.out.println(m);
	}
}


Measured memory_bytes: 21840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }

int main(){
    string S;
    cin >> S;
    if (S[0]!=S[1] && S[0]!=S[2] && S[1]!=S[2]) cout << "Yes\n";
    else cout << "No\n";
}


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

void process(int *x, int z){
    for(int k = 0; k < z; k++){
        printf("%d", x[k]);
        if(k < z - 1){
            printf(" ");
        }else{
            printf("\n");
        }
    }
}

void insertionSort(int *x, int y){
    int i, v, j;
    for(i = 1; i < y; i++){
        v = x[i];
        j = i -1;
        while(j >= 0 && x[j] > v){
            x[j + 1] = x[j];
            j--;
        }
        x[j + 1] = v;
        process(x, y);
    }
}

int main(void){
    int n;
    int hand[101];
    char *number;
    char order[1000000];
    
    fgets(order, 300, stdin);
    sscanf(order, "%d", &n);
    fgets(order, 1000000, stdin);
    number = strtok(order, " \n");      //要素が一個だけだったら数字の次は改行コードが入るので改行コードも入れる。
    sscanf(number, "%d", &hand[0]);
    for(int j = 1; j < n; j++){
        number = strtok(NULL, " \n");
        sscanf(number, "%d", &hand[j]);
    }
    process(hand, n);
    insertionSort(hand, n);
    return 0;
}


Measured memory_bytes: 2076
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
int64_t x;
mint(int64_t x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}
mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod;return *this;}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(int64_t t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    string n;
    cin>>n;
    ll cur = 0;

    rep(i,n.size()){
        cur += n[i] - '0';
    }



    if(cur%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main() {
  int n, x;
  cin >> n >> x;
  long long cnt = 0;
  int prev = 0;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    if (a + prev > x) {
      cnt += a + prev - x;
      a = x - prev;
    }
    prev = a;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <limits>
#include <utility>
#include <algorithm>

int main(int argc, char *argv[])
{
    double l;

    std::cin >> l;

    const double a = l / 3;
    const double b = (l - a) / 2;
    const double c = l - a - b;

    const double volume = a * b * c;

    std::cout << std::fixed << std::setprecision(16) << volume << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int main(void){
    long long n;
    cin >> n;
    long long ans = n;
    for(long long i =1; i * i <= n; i++){
        if(n % i == 0){
            ans = min(ans, i -1 + (n/i)-1);
        }
    }
    cout << ans << endl;
}


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

int main() {
    std::string S, T, U;
    int A, B;
    std::cin >> S >> T >> A >> B >> U;

    if (S == U) {
        --A;
    } else {
        --B;
    }

    std::printf("%d %d\n", A, B);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
 
    int N;
    int ans = 0;
    cin >> N;
    
    for(int i = 1; i <= N; i++){
        string S = to_string(i);
        if( (S.size() % 2) != 0 ){
            ans++;
        }
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
		int a1 = scan.nextInt();
		int a2 = scan.nextInt();
		int a3 = scan.nextInt();
        
        out.println(a1 + a2 + a3 >= 22 ? "bust" : "win");
        out.close();
        
    }
}

Measured memory_bytes: 35956
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){	
	int n,m,k;
	cin>>n>>m>>k;
	
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i*m+j*n-i*j*2==k){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
	int n, a, b[200010];
	cin >> n;
	rep(i, 200010)b[i] = 0;
	rep(i, n-1) {
		cin >> a;
		b[a] = b[a] + 1;
	}
	REP(i, 1, n+1)cout << b[i] << endl;
	return 0;
}

Measured memory_bytes: 4420
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

const int N = 50;
int a[N];
vector<pair<int, int>> v;
int n, k;

void NO(){
  cout << -1 << endl;
  exit(0);
}


int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> k;

  using P = tuple<int, int, int>;
  priority_queue<P> pq;

  for(int i = 0; i < n; i++) cin >> a[i], pq.emplace(0, a[i], i);

  // そこに留まるのに必要なKの最小値
  // の最小値が実際のKを超えるようにする

  vector<int> mi(n);
  vector<int> ans;

  while(pq.size()) {
    int val, rest, id;
    tie(val, rest, id) = pq.top();
    ans.emplace_back(id);
    val *= -1;
    pq.pop();
    int newval = val + 2;
    for(int i = 0; i < n; i++) if(i != id) newval = min(newval, mi[i] + 1);
    mi[id] = val = newval;
    rest--;
    if(rest) pq.emplace(-val, rest, id);
  }
  
  {
    int x = mi[0];
    for(int i = 1; i < n; i++) x = min(x, mi[i]);
    if(x <= k) NO();
  }

  int z = ans.size();
  cout << z << "\n";
  for(int i = 0; i < z; i++) cout << ans[i] + 1 << " \n"[i == z - 1];

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n=0 ,mem=0 ;
    int i=0 ;

    scanf("%d",&n);
    int a[n] ;

    for (i=0 ;i<n ;i++){
        scanf("%d",&mem);
        a[i]=mem;
    }

    for (i=n-1 ;i>-1 ;i--){
        if (i==0){
            printf("%d\n",a[i]);
        } else printf("%d ",a[i]);
    }

    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;

int main() {

	int a;
	cin >> a;
	int b;
	int cur = 0;
	int ct = 0;
	for(int i=0; i<a; i++){
		cin >> b;
		if(b >= cur){
			ct += 1;
			cur = b;
		}
	}
	cout << ct;
}

Measured memory_bytes: 256
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

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

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}

} // namespace n91

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

namespace n91 {

void main_() {
  usize n;
  u32 x;
  std::cin >> n >> x;
  u32 d = static_cast<u32>(0);
  for (const auto i : rep(0_z, n)) {
    u32 l;
    std::cin >> l;
    d += l;
    if (d > x) {
      std::cout << i + 1_z << std::endl;
      return;
    }
  }
  std::cout << n + 1_z << std::endl;
}

} // namespace n91

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN];
int n, k, now[MAXN];
bool better(int a, int lena, int b, int lenb) {
	if (lena == -1) return false;
	if (lenb == -1) return true;
	int len = min(lena, lenb);
	for (int i = 1; i <= len; i++) {
		if (s[a + i - 1] < s[b + i - 1]) return true;
		if (s[a + i - 1] > s[b + i - 1]) return false;
	}
	return lena < lenb;
}
bool equal(int a, int b, int len) {
	for (int i = 1; i <= len; i++)
		if (s[a + i - 1] != s[b + i - 1]) return false;
	return true;
}
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1); read(k);
	for (int i = 1; i <= n; i++)
		now[i] = 1;
	while (true) {
		int pos = 0, len = -1;
		for (int i = 1; i <= n; i++)
			if (better(i, now[i], pos, len)) pos = i, len = now[i];
		for (int i = 1; i <= n; i++)
			if (len == now[i] && equal(pos, i, len)) {
				now[i]++;
				if (i + now[i] - 1 > n) now[i] = -1;
			}
		if (--k == 0) {
			for (int i = 1; i <= len; i++)
				printf("%c", s[pos + i - 1]);
			printf("\n");
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	ll p;
	cin >> p;
	
	ll num = 1ll, cnt = 0;
	
	while(num < p){
		num *= 2;
		cnt++;
	}
	
	ll ans = 1ll << (cnt);
	
	if(ans == p)
		ans *= 2;
	
	ans--;
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for A - Sharing Cookies
	var A, B int
	fmt.Scanf("%d %d", &A, &B)

	if A%3 == 0 || B%3 == 0 || (A+B)%3 == 0 {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}
}


Measured memory_bytes: 1832
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int INF=1e9;

int main(){
    string s;cin>>s;
    ll ans=0;
    ll c=0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]=='W'){
            ans+=i;
            c++;
        }
    }
    ans-=(c-1)*c/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 832
#include <iostream>
using namespace std;
typedef long long ll;
ll N,A[100010],inf = 1e9+7;
ll fact[100010] = {0};
ll inv[100010] = {0};

ll mult(ll n, ll m){
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void factorial(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			fact[i] = 1;
			inv[i] = 1;
		}
		else{
			fact[i] = (i*fact[i-1])%inf;
			inv[i] = mult(i,inf-2);
		}
	}
}

int main(){
	cin >> N;
	factorial(N);
	ll ans = 0;
	for(int i=2;i<=N;i++){
		inv[i] += inv[i-1];
		inv[i] %= inf;
	}
	for(int i=1;i<=N;i++){
		cin >> A[i];
		ans += A[i]*((inv[i]+inv[N-i+1]-1+inf))%inf;
		ans %= inf;
	}
	cout << (ans*fact[N])%inf << endl;
}

Measured memory_bytes: 2560
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from fractions import gcd

def main():
    N = II()
    A = LI()
    G1 = [A[0]]
    for a in A:
        G1.append(gcd(G1[-1], a))
    G2 = [A[-1]]
    for a in A[::-1]:
        G2.append(gcd(G2[-1], a))
    G2 = G2[::-1]
    G1[0] = A[-1]
    G2[-1] = A[0]
    ans = 1
    for g1, g2 in zip(G1, G2[1:]):
        ans = max(ans, gcd(g1, g2))
    return ans

print(main())


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Console.WriteLine(X == 7 || X == 5 || X == 3 ? "YES" : "NO");
		
	}
	int X;
	public Sol(){
		X = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-10;

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n;
	vector<ll> a(3);
	cin >> n;
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	vector<ll> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	ll ans = INF;
	vector<P> cost[3];
	for (int i = 0; i < (1 << n); i++) {
		ll sum = 0;
		ll co  = 0;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				co++;
				sum += l[j];
			}
		}
		if (co == 0) continue;
		for (int j = 0; j < 3; j++) {
			ll tmp = abs(sum - a[j]) + (co - 1) * 10;
			cost[j].push_back(P(tmp, i));
		}
	}
	for (int i = 0; i < 3; i++) {
		sort(cost[i].begin(), cost[i].end());
	}
	int m = cost[0].size();

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < m; k++) {
				bool ok = true;
				for (int p = 0; p < n; p++) {
					ll tmp = 1 << p;
					ll cnt = 0;
					if ((tmp & cost[0][i].second)) cnt++;
					if ((tmp & cost[1][j].second)) cnt++;
					if ((tmp & cost[2][k].second)) cnt++;
					if (cnt > 1) {
						ok = false;
					}
				}
				ll sum = cost[0][i].first + cost[1][j].first + cost[2][k].first;
				if (ok) ans = min(ans, sum);
			}
		}
	}

	dump(ans);
}

Measured memory_bytes: 256
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 998244353;
const ll maxn = 100005;
const ll mm = 1e+18;
void solve()
{
    int n,x,m;
    cin>>n>>x>>m;
    vector<int>v;
    vector<int>vis(m,-1);
    vis[x]=0;
    v.push_back(x);
    vector<int>cycle;
    int cu=0;
    while(1){
        x=(x*x)%m;
        if(vis[x]!=-1){
            int wh=vis[x];
            for(int i=wh;i<(int)(v.size());i++){
                cycle.push_back(v[i]);
            }
            break;
        }
        else{
            vis[x]=++cu;
            v.push_back(x);
        }
    }
    //deb(v,cycle);
    if(n<=(int)(v.size())){
        int sum=0;
        rep0(i,n) sum+=v[i];
        cout<<sum;
    }
    else{
        int ans=0;
        for(auto x:v) ans+=x;
        n-=(int)(v.size());
        int csum=0;
        for(auto x:cycle){
            csum+=x;
        }
        int m=(int)(cycle.size());
        //deb(ans,csum,n,m);
        int how=n/m;
        ans+=csum*how;
        n%=m;
        rep0(i,n) ans+=cycle[i];
        cout<<ans;
    }
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
	string S; 
	cin >> S; 
	int L = S.size(); 
	char C = S.at(L/2); 
	int hatan = 0; 
	if(L % 2 == 0){
		for(int i = 0; i < L / 2; i++){
			if(S.at(L / 2 - 1 - i) != C || S.at(L / 2 + i) != C){break;}
			hatan ++; 
		}
	}
	else if(L % 2 == 1){
		for(int i = 0; i <= L / 2; i++){
			if(S.at(L / 2 - i) != C || S.at(L / 2 + i) != C){break;}
			hatan ++; 
		}
	}
	cout << L/2 + hatan << endl; 
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, k;
    cin >> n >> k;
    LL dp[SIZE] = {};
    dp[1] = k;
    for(int i = 2; i <= n; ++i) {
        dp[i] = dp[i - 1] * (k - 1);

    }
    cout << dp[n] << endl;
    return 0;
}



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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    if ((A+B) > (C+D)){
        cout << "Left" << endl;
    }

    else if ((A+B) == (C+D))
    {
        cout << "Balanced" << endl;
    }

    else{
        cout << "Right" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    int a[N];
    cin>>n;
    int sum=0;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    int s;
    if(sum%n==0)
    {
        s=sum/n;
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            ans+=(s-a[i])*(s-a[i]);
        }
        cout<<ans<<endl;
    }
    else
    {
        int s1=sum/n;
        int ans1=0;
        for(int i=1; i<=n; i++)
        {
            ans1+=(s1-a[i])*(s1-a[i]);
        }
        int s2=s1+1;
        int ans2=0;
        for(int i=1; i<=n; i++)
        {
            ans2+=(s2-a[i])*(s2-a[i]);
        }
        cout<<min(ans1,ans2)<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll mv = 1000000000000000000LL;
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    rep(i, n) {
        ll div = mv / ans;
        if (a[i] > div) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3992
from operator import itemgetter

n = int(input())
A = []
city = []
for _ in range(n):
    s,p = input().split()
    city.append([s,-int(p)])
    A.append([s,-int(p)])

A = sorted(A, key=itemgetter(0,1))
for a in A:
    print(city.index(a)+1)

Measured memory_bytes: 3064
n = int(input())
ans = []
while n >= 1:
    a = n % 26
    ans.append(a)
    n = (n-1)//26
ans = ans[::-1]
z = []
for i in ans:
  if i == 1:
    z.append('a')
  elif i == 2:
    z.append('b')
  elif i == 3:
    z.append('c')
  elif i == 4:
    z.append('d')
  elif i == 5:
    z.append('e')
  elif i == 6:
    z.append('f')
  elif i == 7:
    z.append('g')
  elif i == 8:
    z.append('h')
  elif i == 9:
    z.append('i')
  elif i == 10:
    z.append('j')
  elif i == 11:
    z.append('k')
  elif i == 12:
    z.append('l')
  elif i == 13:
    z.append('m')
  elif i == 14:
    z.append('n')
  elif i == 15:
    z.append('o')
  elif i == 16:
    z.append('p')
  elif i == 17:
    z.append('q')
  elif i == 18:
    z.append('r')
  elif i == 19:
    z.append('s')
  elif i == 20:
    z.append('t')
  elif i == 21:
    z.append('u')
  elif i == 22:
    z.append('v')
  elif i == 23:
    z.append('w')
  elif i == 24:
    z.append('x')
  elif i == 25:
    z.append('y')
  elif i == 0:
    z.append('z')
    
print(''.join(z))
  
    

Measured memory_bytes: 9316
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> v(h);
	rep(i,h) cin >> v[i];
	vector<vector<int>> cnt(h, vector<int>(w, INF));
	cnt[0][0] = (v[0][0] == '#');
	rep(i,h) {
		rep(j,w) {
			if (i == 0 && j == 0) continue;
			int t = INF;
			int u = INF;
			if (j != 0) {
				t = cnt[i][j-1];
				if (v[i][j-1] == '.' && v[i][j] == '#') t++;
			}
			if (i != 0) {
				u = cnt[i-1][j];
				if (v[i-1][j] == '.' && v[i][j] == '#') u++;
			}
			cnt[i][j] = min(t, u);
		}
	}

	cout << cnt[h-1][w-1] << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#define X first
#define Y second
using namespace std;
pair<long long,int> d[200000];
int main(){
    int n,ans=0,cnt=0;
    cin>>n>>d[0].X;
    d[0].Y=0;
    for(int i=1;i<n;i++){
        cin>>d[i].X;
        d[i].X+=d[i-1].X;
        d[i].Y=i;
    }
    sort(d,d+n);
    for(int i=1;i<n;i++){
        if(d[i].X==0)ans=max(ans,d[i].Y+1);
        if(d[i-1].X==d[i].X)cnt+=d[i].Y-d[i-1].Y;
        else cnt=0;
        ans=max(cnt,ans);
    }
    if(d[0].X==0)ans=max(ans,d[0].Y+1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6168
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int n;
bool can[30][30];
int dp[30][1<<22];
int main(int argc,char** argv){
	cin>>n;
	forn(i,n){
		forn(j,n){
			cin>>can[i][j];
		}
	}
	dp[0][0]=1;
	forn(i,(1<<n)-1){
		int cur=__builtin_popcount(i);
		//cout<<i<<" "<<cur<<endl;
		forn(j,n){
			if(i&(1<<(j-1))){
				if(can[cur][j]){
					int from=i^(1<<(j-1));
					//cout<<i<<" "<<j<<" "<<cur<<" "<<from<<endl;
					dp[cur][i]=ll(dp[cur][i]+dp[cur-1][from])%MOD;
				}
			}
		}
	}
	cout<<dp[n][(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 93680
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<61);

using namespace std;

int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    map<string, int> ma;
    int n; cin >> n;
    vi v(n);
    f(i, n) {
      string s; int a; cin >> s >> a;
      ma[s] = i;
      v[i] = a;
    }
    partial_sum(all(v), v.begin());
    string t; cin >> t;
    cout << v.back() - v[ma[t]] << endl;
    return 0;
}


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

typedef long long ll;

ll memo[21];

ll fact( int n ) {
  if ( memo[n] != -1 ) return memo[n];
  if ( n <= 1 ) return 1;
  return memo[n] = n * fact(n-1);
}

int main() {
  memset(memo,-1,sizeof(memo));
  int n; cin >> n;
  ll ret = fact(n);
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 1156
process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const r = Number(inputs[0].split(' ')[0]);

  console.log(r * 2 * 3.14);
}


Measured memory_bytes: 29956
#include <bits/stdc++.h>
using namespace std;
long long dp[3001][3001];
long long util(int arr[], int left, int right){
    if(left > right) return 0;
    if(dp[left][right] != -1) return dp[left][right];
    return dp[left][right] = max(arr[left] + min(util(arr, left + 1, right - 1), util(arr, left + 2, right)), arr[right] + min(util(arr, left + 1, right - 1), util(arr, left, right - 2)));
}
int main() {
	int n;
	cin>>n;
	int arr[n];
	long long sum = 0;
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	    sum += arr[i];
	}
	memset(dp, -1, sizeof(dp));
	long long x = util(arr, 0, n-1);
	cout<<(2*x - sum);
	return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/lexical_cast.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define PI acos(-1)
#define bitcount(a) __builtin_popcountll(a)
#define P pair<int,int>
#define ff first
#define ss second
typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
long double eps=1e-9;
long mod=1e9+7;
const int N=2e5+5;
vector<int>v[N];
int subtree[N];
int ans[N];
int fact[N];
int invfact[N];
int dp[N];

int power(int b , int e)
{
	if(e==0) return 1;
	if(e&1)
		return (b*power((b*b)%mod,e/2))%mod;
	return power((b*b)%mod,e/2)%mod;
}

void precompute()
{
	fact[0]=fact[1]=1;
	for(int i=2;i<=200000;i++)
	{
		fact[i]=i*fact[i-1];
		fact[i]%=mod;
	}
	invfact[200000]=power(fact[200000],mod-2);
	for(int i=200000-1;i>=0;--i)
	{
		invfact[i]=(i+1)*invfact[i+1];
		invfact[i]%=mod;
	}

}

void dfs2(int s,int p=-1)
{
	ans[s]=dp[s];

	for(auto u:v[s])
	{
		if(u!=p)
		{
			dp[s]*=invfact[subtree[s]-1];
			dp[s]%=mod;
			subtree[s]-=subtree[u];
			dp[s]*=fact[subtree[u]];
			dp[s]%=mod;
			dp[s]*=power(dp[u],mod-2);
			dp[s]%=mod;
			dp[s]*=fact[subtree[s]-1];
			dp[s]%=mod;
			dp[u]*=invfact[subtree[u]-1];
			dp[u]%=mod;
			dp[u]*=invfact[subtree[s]];
			dp[u]%=mod;
			subtree[u]+=subtree[s];
			dp[u]*=fact[subtree[u]-1];
			dp[u]%=mod;
			dp[u]*=dp[s];
			dp[u]%=mod;
			dfs2(u,s);
			dp[u]*=power(dp[s],mod-2);
			dp[u]%=mod;
			dp[u]*=invfact[subtree[u]-1];
			dp[u]%=mod;
			subtree[u]-=subtree[s];
			dp[u]*=fact[subtree[s]];
			dp[u]%=mod;
			dp[u]*=fact[subtree[u]-1];
			dp[u]%=mod;
			dp[s]*=invfact[subtree[s]-1];
			dp[s]%=mod;
			dp[s]*=dp[u];
			dp[s]%=mod;
			dp[s]*=invfact[subtree[u]];
			dp[s]%=mod;
			subtree[s]+=subtree[u];
			dp[s]*=fact[subtree[s]-1];
			dp[s]%=mod;
		}
	}
}

void dfs(int s,int p=-1)
{
	++subtree[s];
	dp[s]=1;
	for(auto u:v[s])
	{
		if(u!=p)
		{
			dfs(u,s);
			dp[s]*=dp[u];
			dp[s]%=mod;
			dp[s]*=invfact[subtree[u]];
			dp[s]%=mod;
			subtree[s]+=subtree[u];
		}
	}
	dp[s]*=fact[subtree[s]-1];
	dp[s]%=mod;
}


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;

	precompute();

	for(int i=0;i<n-1;i++)
	{
		int aa,b;
		cin>>aa>>b;
		v[aa].pb(b);
		v[b].pb(aa);
	}
	dfs(1);
	dfs2(1);
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 22512
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String arg[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        if(s.charAt(0)!='A'){
            System.out.println("WA");
        }else{
            String a1 = s.substring(2, s.length()-1);
//            String a2 = s.substring(s.length()-2,s.length()-1);
//            System.out.println(a1+" "+a2);
            int n1 = a1.length()-a1.replaceAll("C","").length();
//            int n2 = a2.length()-a2.replaceAll("C","").length();
            if(n1!=1){
                System.out.println("WA");
            }else{
                String sa = s.replaceAll("A","");
                String sb = sa.replaceAll("C","");
                String lwr = sb.toLowerCase();
                if(lwr.equals(sb)){
                    System.out.println("AC");
                }else{
                    System.out.println("WA");
                }
            }
        }
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < (int)(n); i++)
using ull = unsigned long long;
using ll = long long;


int main() {
    string S, T;
    cin >> S >> T;

    if (S.size() + 1 == T.size() && S == T.substr(0, S.size())) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int A=stdIn.nextInt();
		int B=stdIn.nextInt();
		int C=stdIn.nextInt();
		if(A+B+1>=C)
			System.out.println(B+C);
		else
			System.out.println((A+B+1)+B);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int a,b,c,d;cin >> a >> b >> c >> d;
    while(true){
        c-=b;
        if(c<=0) {
            cout << "Yes" << endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout << "No" << endl;
            return 0 ;
        }
    }
}


Measured memory_bytes: 3624
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int[] mod = Arrays.stream(a).mapToInt(i -> i = i - 1).toArray();
        int sum = Arrays.stream(mod).sum();
        int result = sum;

        // 出力
        System.out.println(result);
    }
}


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

#define mem(arr, i) fill(arr, arr + sizeof(arr), i)
#define MEM(arr, i) memset(arr, i, sizeof(arr))
#define Push push_back
#define Pair make_pair
#define ALL(x) x.begin(), x.end()
#define X first
#define Y second
#define ACCEL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef pair<pll,lli> p3l;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<p3l> v3L;
typedef vector<vcL> vvL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv(maxN+5, 1);
vcL fac(maxN+5, 1);

void ADD(lli &x, lli y) {
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = (x % mod + mod) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if (e & 1) MUL(ans, b);
		MUL(b, b);
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow(n, mod - 2);
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if (a < b) return 0;

	MUL(ans, inv[fac[a - b]]);
	MUL(ans, inv[fac[b]]);
	MUL(ans, fac[a]);

	return ans;
}

lli Lucas(lli n, lli m) {
	if (m == 0) return 1;
	return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas(n, m);
}

/// coding area ///

const lli maxn = 1E5;

void precal() {

	return;
}

void solve() {
	lli n, m;
	cin >> n >> m;
	
	string str[n];
	for (auto &x : str) cin >> x;
	
	bool h[m], w[n];
	memset(h, false, sizeof(h));
	memset(w, false, sizeof(w));
	
	for (int i = 0; i < n; ++i) {
		int cnt = 0;
		for (int j = 0; j < m; ++j) {
			if (str[i][j] == '.') {
				++cnt;
			}
		}
		
		if (cnt == m) {
			w[i] = true;
		}
	}
	
	for (int i = 0; i < m; ++i) {
		int cnt = 0;
		for (int j = 0; j < n; ++j) {
			if (str[j][i] == '.') {
				++cnt;
			}
		}
		
		if (cnt == n) {
			h[i] = true;
		}
	}
	
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (w[i] or h[j]);
			else cout << str[i][j];
		}
		cout << '\n';
	}
}

int main() {
	precal();
	int t = 1;
	#ifdef LOCAL
		t = INT_MAX;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}



Measured memory_bytes: 3456