akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N;
typedef struct infant{
    ll liveliness;
    ll oldplace;
    ll newplace;
    ll rank;
}Infant;
vector<Infant> vec;

bool comp(Infant a,Infant b){
    return(a.liveliness > b.liveliness);
}

int main(){
    cin >> N;
    REP(i,N){
        ll k;
        cin >> k;
        Infant I;
        I.liveliness = k;
        I.oldplace = i;
        vec.push_back(I);
    }

    sort(ALL(vec),comp);
    /*REP(i,N){
        cout << vec[i].liveliness << " ";
    }
    cout << endl;*/
    ll dp[N+1][N+1];
    bool breaker = false;
    REP(i,N+1){
        REP(j,N+1){
            dp[i][j] = 0;
        }
    }

    REP(i,N+1){
        REP(j,N+1){
            if(i + j > N){continue;}
            else{
                if(j == 0 && i != 0){
                    dp[i][0] = dp[i-1][0] + vec[i-1].liveliness * abs(N-i-vec[i-1].oldplace);
                    //cout << "dp[i][0]" << dp[i][0] << endl;;
                }
                else if(j != 0 && i == 0){
                    dp[0][j] = dp[0][j-1] + vec[j-1].liveliness * abs(vec[j-1].oldplace - j + 1);
                    //cout << "dp[0][j]" << dp[0][j] <<endl;
                }
                else if(j != 0 && i != 0){
                    ll iii = dp[i-1][j] + vec[i+j-1].liveliness * abs(N-i-vec[i+j-1].oldplace);
                    ll jjj = dp[i][j-1] + vec[i+j-1].liveliness * abs(vec[i+j-1].oldplace-j+1);
                    dp[i][j] = max(iii,jjj);
                }
            }
        }
    }

    ll maxi = 0;
    /*REPR(i,N){
        if(maxi <= dp[i][N-i]){
            maxi = dp[i][N-i];
            cout << dp[i][N-i] << " " << i << endl;
        }
        
    }*/
    REP(i,N+1){
        maxi = max(maxi,dp[i][N-i]);
    }
    cout << maxi << endl;
}

Measured memory_bytes: 35056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a,b;
    cin >> a >> b;
    vector<int> sq(1000);
    rep(i,1000) sq[i] = i*i;
    string as = to_string(a);
    string bs = to_string(b);
    string sab = as + bs;
    int ab = stoi(sab);
    rep(i,1000){
        if(sq[i] == ab) {
            cout << "Yes" << endl;
            return 0;    
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3776
from sys import stdin
n = int(stdin.readline())
ans = 0
dp = [0]*(n+1)
for i in range(1,n+1):
    j = i
    while j <= n:
        dp[j] += 1
        j += i
for i in range(1,n+1):
    ans += dp[i]*i
print(ans)

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

int main(){
    int N,W;
    cin >> N >> W;

    int v[N],w[N];
    for(int i=0; i<N; i++){
        cin >> v[i] >> w[i];
    }

    int DP[N+1][W+1];

    for(int j=0; j<=W; j++){
        DP[0][j] = 0;
    }

    for(int i=1; i<=N; i++){
        for(int j=0; j<=W; j++){
            if(j<w[i-1]){
                DP[i][j] = DP[i-1][j];
            }else{
                if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1])
                    DP[i][j] = DP[i-1][j];
                else
                    DP[i][j] = DP[i-1][j-w[i-1]]+v[i-1];
            }
        }
    }

    cout << DP[N][W] << endl;

    return 0;
}



Measured memory_bytes: 7040
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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

const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<set<string>> a(5);
    rep(i,n){
        string s;
        cin >> s;
        if(s[0]=='M') a[0].insert(s);
        if(s[0]=='A') a[1].insert(s);
        if(s[0]=='R') a[2].insert(s);
        if(s[0]=='C') a[3].insert(s);
        if(s[0]=='H') a[4].insert(s);
    }
    ll ans=0;
    for(ll i=0;i<(1<<5);i++){
        ll cnt=0;
        ll cur=1;
        rep(j,5){
            if((i>>j)%2==1) cnt++;
        }
        if(cnt==3){
            rep(j,5){
                if((i>>j)%2==1){
                    cur*=a[j].size();
                }
            }
            ans+=cur;
        }
        
    }
    cout << ans << endl;
} 


Measured memory_bytes: 11348
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();

    int ans = 0;
    for(int i=0; i<n/2; ++i){
        if(s[i] != s[n-1-i])
            ++ ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
int n,id[maxn],sz,cnt,ans;
struct node {
	int x,y,bh;
} d[maxn];
struct edge {
	int from,to,dis;
} m[maxn*2];
int find(int a) {
	if (id[a]==a)
		return a;
	id[a]=find(id[a]);
	return id[a];
}
void connect(int a,int b) {
	id[find(a)]=find(b);
}
bool cmp1(node a,node b) {
	return a.x<b.x;
}
bool cmp2(node a,node b) {
	return a.y<b.y;
}
bool cmp3(edge a,edge b) {
	return a.dis<b.dis;
}
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		d[i].bh=i;
		scanf("%d %d",&d[i].x,&d[i].y);
	}
	sz=0;
	sort(d+1,d+(n+1),cmp1);
	for (int i=2;i<=n;i++) {
		sz++;
		m[sz].from=d[i-1].bh;
		m[sz].to=d[i].bh;
		m[sz].dis=d[i].x-d[i-1].x;
	}
	sort(d+1,d+(n+1),cmp2);
	for (int i=2;i<=n;i++) {
		sz++;
		m[sz].from=d[i-1].bh;
		m[sz].to=d[i].bh;
		m[sz].dis=d[i].y-d[i-1].y;
	}
	sort(m+1,m+(sz+1),cmp3);
	ans=0; cnt=n;
	for (int i=1;i<=n;i++)
		id[i]=i;
	for (int i=1;i<=sz;i++) {
		if (cnt==1)
			break;
		int a=m[i].from,b=m[i].to;
		if (find(a)!=find(b)) {
			cnt--;
			connect(a,b);
			ans+=m[i].dis;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  long long N, M;   
  cin >> N >> M; 
  int LM = 0, RM = N-1;
  for(int i = 0; i < M; i++){
    int L, R;
    cin >> L >> R;
    L--; R--;
    if(LM < L){
      LM = L;
    }
    if(RM > R){
      RM = R;
    }
  }
  if(RM >= LM){
    cout << RM - LM + 1 <<endl;
  } else{
    cout << 0 <<endl; 
  }
}


Measured memory_bytes: 3572
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

const ll MOD = 1e9 + 7;

ll pow_fast(ll n, ll k) {
  if (k == 0) {
    return 1LL;
  }
  if (k == 1) {
    return n;
  }

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

template <typename T>
class stack {
 private:
  vector<T> _vec;

 public:
  stack(){};

  void push(T n) {
    _vec.push_back(n);
    return;
  }

  void pop() {
    if (this->empty()) {
      return;
    }
    _vec.erase(_vec.end() - 1);
    _vec.shrink_to_fit();
    return;
  }

  size_t size() { return _vec.size(); }

  T top() { return _vec[this->size() - 1]; }
  bool empty() { return _vec.empty(); }
};

int main() {
  ll H, W;
  cin >> H >> W;
  vector<vector<char>> pixel(H, vector<char>(W));
  for (ll i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (ll j = 0; j < W; j++) {
      pixel[i][j] = s[j];
    }
  }

  for (ll i = 0; i < 2 * H; i++)
  {
    for (ll j = 0; j < W; j++)
    {
      cout << pixel[i / 2][j];
    }
    cout << endl;
  }
  
}

Measured memory_bytes: 3636
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll mx = 1e9 + 42, inf = 1e18 + 42;
const ld of = 2e18 + 42;

map<pll, ll> mp;

ll solve(ll n, int p, ll a, ll b, ll c, ll d);

int main() {
	fast_cin();
	int t; cin >> t;
	while (t--) {
		ll n, a, b, c, d;
		cin >> n >> a >> b >> c >> d;
		mp.clear();
		cout << solve(n, 2, a, b, c, d) << '\n';
	}
}

ll solve(ll n, int p, ll a, ll b, ll c, ll d) {
	if (n == 1) {
		return d;
	} else if (mp.count({n, p})) {
		return mp[{n, p}];
	} else {
		auto& ans = mp[{n, p}];
		ans = (ld(n) * d <= of ? n * d : inf);
		// if (p == 2) {
			// ans = min(ans, solve(n, 1, a, b, c, d));
			if (n % 5 <= 2) {
				ans = min(ans, c + d * (n % 5) + solve(n / 5, p, a, b, c, d));
			} else {
				ans = min(ans, c + d * (5 - (n % 5)) + solve(n / 5 + 1, p, a, b, c, d));
			}
		// } else if (p == 1) {
			// ans = min(ans, solve(n, 0, a, b, c, d));
			if (n % 3 <= 1) {
				ans = min(ans, b + d * (n % 3) + solve(n / 3, p, a, b, c, d));
			} else {
				ans = min(ans, b + d * (3 - (n % 3)) + solve(n / 3 + 1, p, a, b, c, d));
			}
		// } else {
			ans = min(ans, a + d * (n % 2) + solve(n / 2, p, a, b, c, d));
			ans = min(ans, a + d * (2 - n % 2) + solve(n / 2 + 1, p, a, b, c, d));
		// }
		return ans;
	}
}

Measured memory_bytes: 4776
"""
重さと価値がそれぞれw_i,v_iであるようなn個の品物がある.
これらの品物の中から, 重さの総和がWを超えないように選んだ時の,
価値の総和の最大値を求めよ.
1<=n<=100, 1<=w_i<=10^7, 1<=v_i<=100, 1<=W<=10^9
"""
#-------------------------------------------------------------------------------

#入力
INF=float('inf')
n ,W= map(int, input().split())
w=[0]*n
v=[0]*n
for i in range(n):
    w[i],v[i] = map(int, input().split())
V=sum(v)
dp = [[INF for i in range(V+1)] for j in range(n+1)]

#ここからメイン
dp[0][0]=0
for i in range(n):
    for j in range(V+1):
        if j<v[i]:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i])
ans=0
for i in range(V+1):
    if dp[n][i]<=W:
        ans=i
print(ans)


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

int main() {
	string S;
	long long K;
	cin >> S >> K;
	string T(S.size(), S[0]);
	if (S == T) {
		cout << (S.size() * K) / 2 << endl;
		return 0;
	}
	long long Cur = 1, COUNT = 0, L, R;
	for (int i = 1; i < S.size(); i++) {
		if (S[i] == S[i - 1]) {
			Cur++;
		}
		else {
			COUNT += Cur / 2;
			Cur = 1;
		}
	}
	R = Cur;
	COUNT += Cur / 2;
	L = 1;
	for (int i = 1; i < S.size(); i++) {
		if (S[i] != S[i - 1]) break;
		L++;
	}
	if (S[S.size() - 1] == S[0]) {
		long long MID, BORDER = 0;
		BORDER = (L + R) / 2;
		L = L / 2, R = R / 2;
		MID = COUNT - L - R;
		cout << L + MID * K + BORDER * (K - 1) + R << endl;
	}
	else {
		cout << COUNT * K << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

void sosa(int);
int d[101],f[101],A[101][101],n;

int main(){
  int m,t,l,i,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&t,&m);
    for(j=1;j<=m;j++){
      scanf("%d",&A[t][j]);
    }
  }
  sosa(1);
  d[1]=0;
  for(i=1;i<=n;i++){
    printf("%d %d",i,d[i]);
    printf("\n");
  }
  return 0;
}

void sosa(int a){
  static int b=0;
  int i=1;
  d[a]=b;
  b++;
  while(A[a][i]!=NULL){
    if(d[A[a][i]]==NULL || d[A[a][i]]>b){
      sosa(A[a][i]);
      b--;
     }
    i++;
  }
  if(a==1){
    for(i=1;i<=n;i++){
      if(d[i]==NULL){
		d[i]=-1;
      }
    }
  }
}





Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int x,a;
    cin>>x>>a;
    if(x<a) cout<<0<<endl;
    else cout<<10<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>
#include <numeric>

using namespace std;

#define REP(i,a,b) for(int i=(a); i<(b); ++(i))
#define rep(i,n) REP(i,0,n)

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int PI = acos(-1);
const int INF = numeric_limits<int>::infinity() / 2;
const ll INFLL = numeric_limits<ll>::infinity() / 2;

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

  int a, ans = 0;
  rep(i, N) {
    cin >> a;
    ans += (a - 1);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <climits>
#include <utility>
#include <numeric>
typedef long long ll;
using namespace std;

int main(int argc, char *argv[]) {
  int n, i;
  cin >> n;
  if(n<2){
    cout << 0 << endl;
    return 0;
  }

  ll a = 1LL, b = 1LL, c = 1LL;
  const ll mod = 1e9 + 7;

  for(i=0;i<n;i++){
    a *= 10LL;
    a %= mod;

    b *= 9LL;
    b %= mod;

    c *= 8LL;
    c %= mod;
  }

  b *= 2LL;
  b %= mod;

  ll ans = a;
  ans -= b;
  ans %= mod;
  ans += c;
  ans %= mod;

  if(ans<0LL) ans += mod;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define array_s(a) sizeof(a) / sizeof(*a)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void)
{
    int n, m;
    cin >> n >> m;

    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    return 0;
}


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

using ll=long long;
using ld=long double;

void solve(){
	int x;
	cin>>x;
	if(x==1)
	cout<<0<<'\n';
	else
	cout<<1<<'\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3608
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  ll l, r;
  cin >> l >> r;
  ll mod = 2019;

  if(r-l >= 2019){
    cout << 0 << endl;
    return 0;
  }
  l %= mod;
  r %= mod;
  
  if(l == 0 || r == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 3*1e9;
  
  FOR(i,l,r+1){
    FOR(j,i+1,r+1){      
      ans = min(((i%mod)*(j%mod))%mod, ans);
    }    
  }
  if(l >= r) cout << 0 << endl;
  else cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>

using namespace std;

int main(void){
    int H=0, W=0;

    while(cin >> H >> W){
        if(H==0 && W==0)
            break;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if((i+j)%2 == 0)
                    cout << "#";
                else
                    cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3112
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
c = []
for i in range(m):
    a[i], b[i] = map(int, input().split())
    tc = list(map(int, input().split()))
    c.append(tc)
p = 2**n
dp = [float('inf')] * p
dp[0] = 0

for i in range(m):
    for j in range(p):
        t = p-1
        for cc in c[i]:
            t -= (1 << (cc-1))
        for cc in c[i]:
            if j >> (cc-1) & 1:
                dp[j] = min(dp[j], dp[j&t] + a[i])
if dp[p-1] == float('inf'):
    print(-1)
else:
    print(dp[p-1])

Measured memory_bytes: 62428
n = int(input())
pn = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
    if pn[i-1]<pn[i]<pn[i+1] or pn[i-1]>pn[i]>pn[i+1]:
        ans+=1
print(ans)

Measured memory_bytes: 3060
s = input()
exitLower = list(set(list(s)))
m = len(s)

for alp in exitLower:
    SL = list(s)
    cnt = 0
    while len(set(SL)) > 1:
        for i in range(len(SL)-1):
            if SL[i+1] == alp:
                SL[i] = alp
        SL.pop()
        cnt += 1
    m = min(m,cnt)

print(m)



Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main(){

	char str[81];
//	char cstr[80];
	int s=0;
	int i;
	char c;
	char *p;

	p=str;
	while((c=getchar())!=EOF){
		if(c!='\n'){
			*p=c;
			p++;
		}
		if(c=='\n'){
			*p='\0';
			p=str;

			s=0;
			while(s<=26){
				for(i=0;i<81;i++){
					if(str[i]>='a' && str[i]<='y'){
						str[i]++;
					} else if(str[i]=='z'){
						str[i]='a';
					}

				}
				s++;
				if(strstr(str,"the")!=NULL)break;
				if(strstr(str,"this")!=NULL)break;
				if(strstr(str,"that")!=NULL)break;
			}
			printf("%s\n",str);

		}
	

	}

	return 0;
}

Measured memory_bytes: 520
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, a: [usize; n - 1]);
    let mut a_v = vec![0usize; 200_001];
    for v in a {
        a_v[v - 1] += 1;
    }
    for v in a_v.iter().take(n) {
        println!("{}", v);
    }
}


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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const int MAX_N=105;
const int MAX_VAL=1000050;
const ll INF=9e18;

ll n,W,ans,val[MAX_N],wt[MAX_N],dp[MAX_N][MAX_VAL];

int main(){
  cin >> n >> W;
  for(int i=1;i<=n;++i){
    cin >> wt[i] >> val[i];
  }
  dp[0][0]=0;
  for(int i=1;i<MAX_VAL;++i){
    dp[0][i]=INF;
  }
  for(int i=1;i<=n;++i){
    for(int j=0;j<MAX_VAL;++j){
        dp[i][j]=dp[i-1][j];
        if(j>=val[i]){
            dp[i][j]=min(dp[i][j],dp[i-1][j-val[i]]+wt[i]);
        }
        if(j<15){
        }
    }
  }
  for(int i=0;i<MAX_VAL;++i){
    if(dp[n][i]<=W){
        ans=i;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 790784
#include <stdio.h>

int main(void){
        int a, b, d, r;
        double f;
        scanf("%d %d", &a, &b);
        d=a/b;
        r=a%b;
        f=(double)a/b;
        printf("%d %d %f\n", d, r, f);
        return 0;
}


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int ans = 0;
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    ans += min(x, abs(x-k)) * 2;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

const int N=1e6+3;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9;

int n,m,a[N],b[N],k,q,u,tc,c,l,r,ans,p,cnt;

char s[N];

int ok[26];

int x[N],y[N],h[N];

bool check(int cx,int cy,int H){
	for(int i=0;i<n;i++){
		int p=max(0,H-abs(cx-x[i])-abs(cy-y[i]));
		if (h[i]!=p)
			return false;
	}
	return true;
}

int main(){
	scanf("%d",&n);
	vector<int> v;
	for(int i=0;i<n;i++)
		scanf("%d%d%d",&x[i],&y[i],&h[i]);
	for(int cx=0;cx<=100;cx++){
		for(int cy=0;cy<=100;cy++){
			int H=0;
			for(int i=0;i<n;i++){
				int p=abs(cx-x[i])+abs(cy-y[i]);
				if (!h[i]){
					if (H>p)
						H=-1;
				}
				else{
					if (!H)
						H=h[i]+p;
					else if (H!=h[i]+p)
						H=-1;
				}
			}
			if (H!=-1){
				if (!H)
					H++;
				if (check(cx,cy,H))
					return !printf("%d %d %d\n",cx,cy,H);
			}
		}
	}
}


Measured memory_bytes: 4352
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        z = 0
        for k in range(d):
            z += (x[i][k]-x[j][k])**2
        z = z**0.5
        if z.is_integer():
            ans += 1
print(ans)

Measured memory_bytes: 9420
#include <iostream>

using namespace std;

int main(){

  int N, K, X, Y, total = 0;
  cin >> N >> K >> X >> Y;

  for(int i = 0; i < N; i++){
    if(i < K) total += X;
    else total += Y;
  }

  cout << total << endl;

  return 0;

}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,j,sum=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
            sum=sum+i;
    }
    cout<<sum;
}


Measured memory_bytes: 3644
import itertools
N, M, Q = map(int, input().split())
List = [list(map(int, input().split())) for i in range(Q)]

comb = list(itertools.combinations_with_replacement(list(range(1, M+1)), N))

max_point = 0
point_cont = 0
for pt in comb:
    point_cont = 0
    for list_pt in List:
        if pt[list_pt[1]-1] - pt[list_pt[0]-1] == list_pt[2]:
            point_cont += list_pt[3]
    if max_point <= point_cont:
        max_point = point_cont

print(max_point)


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

int main() {
  int c[3][3];
  rep(i, 3) rep(j, 3) cin >> c[i][j];
  bool correct = true;
  if (c[0][0] - c[0][1] != c[1][0] - c[1][1]) correct = false;
  if (c[0][0] - c[0][1] != c[2][0] - c[2][1]) correct = false;
  if (c[0][0] - c[0][2] != c[1][0] - c[1][2]) correct = false;
  if (c[0][0] - c[0][2] != c[2][0] - c[2][2]) correct = false;
  if (correct) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
import heapq as h
import math
 
a,b,x = map(int,input().split())
# n = int(input())
# l = list(map(lambda x:-int(x),input().split()))


# can = 'No'
# for i in range(2,10):
#   if ((n%i) == 0):
#     can = 'Yes'
#     # right = n/i
#     # if (1<=right) and (right<=9):
#     #   can = 'Yes'

# if can == 'Yes':
#   # divides = []
#   for i in range(2,n):
#     if ((n%i) == 0):
#       right = int(n/i)
#       if i > right:
#         print(str(int(i))+'×'+str(right))
#         print(int(i+right-2))
#         break
#       # divides.append(str(int(i))+'×'+str(right))
# elif math.sqrt(n).is_integer():
#   print(int(math.sqrt(n)*2-2))
# else:
#   print(n-1)
volume = (a**2)*b
if volume/2 < x:
  y = (((a**2)*b)-x)*(2/(a**3))
else:
  y = a*(b**2)/(2*x)
print(math.degrees(math.atan(y)))

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<map>

using namespace std;

int h[100001];
int ans[100001];

int main(){
    int n,m; 

    cin >> n >> m;

    for(int i=0;i<n;i++)cin>>h[i+1];

    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        if(h[a]>=h[b])ans[b]=1;
        if(h[b]>=h[a])ans[a]=1;
    }
    int sum=0;

    for(int i=1;i<=n;i++){
        if(ans[i]==0)sum++;
    }

    cout << sum << endl;

    

    return 0;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 51;

int n,K;
vector<int> X,Y,Z,X1,Y1,Z1,X2,Y2,Z2;
int flag[MAX_N*2][MAX_N*2][MAX_N*2];

int main()
{
	scanf("%d%d",&n,&K);
	rep(i,n){
		int ax,ay,az,bx,by,bz;
		scanf("%d%d%d%d%d%d",&ax,&ay,&az,&bx,&by,&bz);
		X.push_back(ax),X.push_back(bx);
		X1.push_back(ax),X2.push_back(bx);
		Y.push_back(ay),Y.push_back(by);
		Y1.push_back(ay),Y2.push_back(by);
		Z.push_back(az),Z.push_back(bz);
		Z1.push_back(az),Z2.push_back(bz);
	}
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	sort(Z.begin(),Z.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	Y.erase(unique(Y.begin(),Y.end()),Y.end());
	Z.erase(unique(Z.begin(),Z.end()),Z.end());
	rep(i,n){
		X1[i] = lower_bound(X.begin(),X.end(),X1[i])-X.begin();
		X2[i] = lower_bound(X.begin(),X.end(),X2[i])-X.begin();
		Y1[i] = lower_bound(Y.begin(),Y.end(),Y1[i])-Y.begin();
		Y2[i] = lower_bound(Y.begin(),Y.end(),Y2[i])-Y.begin();
		Z1[i] = lower_bound(Z.begin(),Z.end(),Z1[i])-Z.begin();
		Z2[i] = lower_bound(Z.begin(),Z.end(),Z2[i])-Z.begin();
		flag[X1[i]][Y1[i]][Z1[i]]++,flag[X1[i]][Y2[i]][Z1[i]]--;
		flag[X2[i]][Y1[i]][Z1[i]]--,flag[X2[i]][Y2[i]][Z1[i]]++;
		flag[X1[i]][Y1[i]][Z2[i]]--,flag[X1[i]][Y2[i]][Z2[i]]++;
		flag[X2[i]][Y1[i]][Z2[i]]++,flag[X2[i]][Y2[i]][Z2[i]]--;
	}
	rep(i,101){
		rep(j,101){
			rep(k,101){
				flag[i+1][j][k] += flag[i][j][k];
			}
		}
	}
	rep(i,101){
		rep(j,101){
			rep(k,101){
				flag[i][j+1][k] += flag[i][j][k];
			}
		}
	}
	rep(i,101){
		rep(j,101){
			rep(k,101){
				flag[i][j][k+1] += flag[i][j][k];
			}
		}
	}
	ll ans = 0;
	rep(i,X.size()-1){
		rep(j,Y.size()-1){
			rep(k,Z.size()-1){
				if(flag[i][j][k]>=K){
					ans += (ll)(X[i+1]-X[i])*(Y[j+1]-Y[j])*(Z[k+1]-Z[k]);
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7416
numtcs = int(input())
judgement = []
for i in range(numtcs):
	judgement.append(input())

numac = judgement.count("AC")
print(f'AC x {numac}')
numwa = judgement.count("WA")
print(f'WA x {numwa}')
numtle = judgement.count("TLE")
print(f'TLE x {numtle}')
numre = judgement.count("RE")
print(f'RE x {numre}')

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

int main(){
    string s;
    vector<pair<string, string>> t({{"k", "eyence"}, {"ke", "yence"}, {"key", "ence"}, {"keye", "nce"}, {"keyen", "ce"}, {"keyenc", "e"}});
    cin >> s;

    if(s.find("keyence") == 0 || s.find("keyence", s.size() - 7) == s.size() - 7)return 0 & puts("YES");

    for(auto i : t){
        if(s.find(i.first) == 0 && s.find(i.second, s.size() - i.second.size()) == s.size() - i.second.size())return 0 & puts("YES");
    }

    return 0 & puts("NO");
}

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

int main(){
  int n,x,len,mid;

  cin>>n>>x;
  len=n*2-1;
  mid=len/2;
  int ans[200001]={},cnt;
  if(x==1||len==x){cout<<"No"<<endl;return 0;}

  if(x==2){
    ans[mid]=x;
    ans[mid-1]=1;
    cnt=3;
  }
  else if(x==len-1){
    ans[mid]=x;
    ans[mid+1]=len;
    cnt=1;
  }
  else{
    ans[mid-1]=x;
    ans[mid-2]=1;
    ans[mid]=len;
    ans[mid+1]=2;
    cnt=3;
  }

  for(int i=0;i<len;i++){
    if(cnt==x)cnt++;
    if(!ans[i])ans[i]=cnt++;
  }
  cout<<"Yes"<<endl;
  for(int i=0;i<len;i++)cout<<ans[i]<<endl;
      
  return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long N,K,i,j,k,X,Y,jmax,ans,Z,a;

int main()
{
  cin>>N;
  
  if(N==2)
  {
    cout <<1;
    return 0;
  }
  
  if(N==3)
  {
    cout <<2;
    return 0;
  }
  
  if(N==4)
  {
    cout <<3;
    return 0;
  }
  
  if(N==5)
  {
    cout <<3;
    return 0;
  }
  
  ans=0;
  for(i=2;i*i<=N;i++)
  {
    Y=N;
    X=N%i;
    if(X!=0)
    {
      continue;
    }
    while(X==0)
    {
      Y=Y/i;
      X=Y%i;
    }
    
      if(X==1)
      {
        ans++;
      }
    

  }

  for(i=2;i*i<=N-1;i++)
  {

    X=(N-1)%i;
    if(X==0)
    {

      ans+=2;
      if(i*i==N-1)
      {
        ans--;
      }
    }

  }
  
  ans+=2;
  cout<<ans;

  
  
}

Measured memory_bytes: 256
from numba import njit

@njit('i8(i8)', cache =True)
def loop(n):
  N = -(-n//2)
  ans = 0
  for i in range(1, N+1):
      x = n // i
      ans += i * x * (x+1)// 2
  return ans

n = int(input())
N = -(-n//2)
ans = loop(n)
ans -= N * (N+1) //2
ans += n * (n+1) //2
print(ans)

Measured memory_bytes: 106384
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+18
#define MOD 1000000007
using namespace std;



int main(){
    int N,M;
    cin >> N >> M;
    int a[100]={};
    for(int i=0; i<N; i++){
        int K;
        cin >> K;
        for(int j=0; j<K; j++){
            int p;
            cin >> p;
            a[p-1]++;
        }
    }
    int ans=0;
    for(int i=0; i<M; i++){
        if(a[i]==N){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
 
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int K = sc.nextInt();
		int N = sc.nextInt();
		
		int[] A = new int[N];
		Arrays.setAll(A, i->sc.nextInt());
		
		int ans = A[N-1] - A[0];
		for (int i=0; i<N-1; i++) {
			ans = Math.min(ans, K-(A[i+1]-A[i]));
		}
		System.out.println(ans);
	}
}

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

using namespace std;
const int maxn = 2e5 + 10;
char s[maxn], t[maxn];
int main(){
    cin >> s >> t;
    int n = strlen(s);
    int rec = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == t[i]) continue;
        rec ++;
    }
    cout << rec;
}


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

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N + 1);
    vector<ll> sum(N + 1, 0);
    rep(i, N + 1) { A[i] = i; }
    rep(i, N) { sum[i + 1] = sum[i] + A[i + 1]; }
    ll MOD = pow(10, 9) + 7;

    ll res = 0;
    for (ll j = K - 1; j <= N; j++) {
        ll min_sum = 0, max_sum = 0;
        min_sum = sum[j];
        max_sum = sum[N] - sum[N - j - 1];
        if (N - j - 1 < 0)
            max_sum = min_sum;
        res += (max_sum - min_sum) + 1;
        res %= MOD;
    }

    cout << res << endl;
}

Measured memory_bytes: 6360
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;

int main(void){
    ll n;
    cin>>n;
    vector <int> p(n);
    vector <int> q(n);
    rep(i,n){
        cin>>p[i];
    }
    rep(i,n){
        cin>>q[i];
    }
    vector <int> a(n);
    rep(i,n){
        a[i]=i+1;
    }
    int c=0;
    int w,b;
    do{
        
        int fp=1;
        int fq=1;
       rep(i,n){
           if(a[i]!=p[i])fp=0;
           if(a[i]!=q[i])fq=0;
       }if(fp)w=c;
       if(fq)b=c;
       c++;
    }while(next_permutation(a.begin(),a.end()));
    cout<<abs(w-b)<<endl;
    
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);

int main()
{
    int n;
    int a[15];
    int x[15][14];
    int y[15][14];
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        rep(j, a[i]) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
        bool is_ok = true;
        vector<int> honesty(n, -1);
        rep(i, n) {
            if (bit & (1 << i)) {
                rep(j, a[i]) {
                    if (honesty[i] == 0 || (x[i][j] == i && y[i][j] == 0)
                        || (honesty[x[i][j]] == 1 && y[i][j] == 0)
                        || (honesty[x[i][j]] == 0 && y[i][j] == 1)) {
                        is_ok = false;
                    }
                    if (y[i][j] == 1 && !(bit & (1 << x[i][j]))) {
                        is_ok = false;
                    }
                    if (y[i][j] == 0 && (bit & (1 << x[i][j]))) {
                        is_ok = false;
                    }
                    honesty[i] = 1;
                    honesty[x[i][j]] = y[i][j];
                }
            }
        }
        if (is_ok) {
            int cnt = 0;
            rep(i, n) {
                if (bit & (1 << i)) cnt++;
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
}

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

int main(){
    string ser, in;
    int n, ans = 0;
    cin >> ser >> n;
    for(int i = 0;i<n;i++){
        cin >> in;
        in = in + in;
        if(in.find(ser) != string::npos) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3176
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll l, r;
    l = 4*a*b;
    r = (c-a-b)*(c-a-b);
    //cout << l << " " << r << endl;
    if(l<r && (c-a-b)>0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793


int main()
{
    ll n;
    cin >> n;
    ll x = 1;
    vector<ll> a(n);
    vector<double> b(n);
    rep(cnt, 0, n) {
        cin >> a[cnt];

    }
    sort(a.begin(),a.end());

    if (a[0] == 0) {
        cout << 0 << endl;
        return 0;
    }
    rep(cnt, 0, n) {
        b[cnt] = log10(a[cnt]);
    }
    double y=0;
    rep(cnt, 0, n) {
        y += b[cnt];
    }

    if (y > 18.0) {
        cout << -1 << endl;
        return 0;
    }

    for (ll cnt = n - 1; cnt >= 0; cnt--) {
        x *= a[cnt];
        if (x > 1000000000000000000) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << x << endl;


    return 0;

}

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

#define endl "\n"

long long int n, m, k;
long long int dp[15][1<<13];
long long int INF = 1e14;
long long int cost[15][15];

long long int kil(int idx, int mask)
{
    if(idx == n)
    {
        int arr[14] = {0};
        for(int j=0;j<n;j++)
            if(mask & 1<<j)
            {
                for(int i=1;i<=m;i++)
                    arr[i] += cost[j][i];
            }
        bool pos = true;
        for(int i=1;i<=m;i++)
            if(arr[i] < k)
            {
                pos = false;
                break;
            }
        return pos ? 0 : INF;
    }

    if(dp[idx][mask] != -1)
        return dp[idx][mask];

    dp[idx][mask] = INF;

    dp[idx][mask] = min(dp[idx][mask], kil(idx+1, mask | (1<<idx)) + cost[idx][0]);
    dp[idx][mask] = min(dp[idx][mask], kil(idx+1, mask));
    return dp[idx][mask];
}

void hk()
{
    long long int x=0, y=0, ans=0;
    cin>>n>>m>>k;

    for(int i=0;i<n;i++)
        for(int j=0;j<=m;j++)
            cin>>cost[i][j];

    memset(dp, -1, sizeof dp);

    ans = kil(0, 0);
    cout<<(ans >= INF ? -1 : ans)<<endl;
    return;
}

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

 	int t;
 	t = 1;

 	for(int i=1;i<=t;i++)
    {
        hk();
    }
 	return 0;
}


Measured memory_bytes: 4572
from collections import Counter
from typing import AnyStr


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1


def main():
    n, k, l = map(int, input().split())
    a = UnionFind(n)
    b = UnionFind(n)
    for _ in range(k):
        p, q = map(int, input().split())
        a.union(p-1, q-1)
    for _ in range(l):
        r, s = map(int, input().split())
        b.union(r-1, s-1)
    pairs = []
    for i in range(n):
        pairs.append((a._root(i), b._root(i)))

    d = Counter(pairs)
    ans = [d[x] for x in pairs]
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47836
N,A,B,C =map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(cur,a,b,c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a, b, c)>0 else INF
    ret0 = dfs(cur + 1,a,b,c)
    ret1 = dfs(cur+1,a+l[cur],b,c)+10
    ret2 = dfs(cur+1,a,b+l[cur],c)+10
    ret3 = dfs(cur+1,a,b,c+l[cur])+10
    return min(ret0,ret1,ret2,ret3)
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 18+5;
int n; i64 a[N];
i64 dfs(int l, int r, int x, int y)
{
    if(l+1 == r) return 0; i64 ret = 1e18;
    for(int i = l+1; i < r; ++i) ret = min(ret, dfs(l, i, x, x+y)+dfs(i, r, x+y, y)+a[i]*(x+y));
    return ret;
}
int main()
{
    n = read(); for(int i = 1; i <= n; ++i) a[i] = read();
    printf("%lld\n", dfs(1, n, 1, 1)+a[1]+a[n]);
    return 0;
}

Measured memory_bytes: 128
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

int main(void)
{
	//変数の宣言
	int n;
	char s[110];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;



	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);

	scanf("%s",&s);
//	scanf_s("%s",&s,110);

/*	for(i=0;i<n;i++){
		scanf("%d",&b[i]);
//		scanf_s("%d",&b[i]);
	}*/

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	for(i=0;i<n;i++){
		if(s[i]=='R'){
			ans++;
		}else{
			ans--;
		}
	}

	//	printf("計算部分終了\n");

	//出力
	if(ans>0){
		printf("Yes");
	}else{
		printf("No");
	}


	//	printf("結果の出力終了\n");

	return 0;
}



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

public class Main {
    public static void main(String[] args) {
        InputReader inputReader=new InputReader(System.in);
        PrintWriter printWriter=new PrintWriter(System.out);
        Deque<Integer> deque=new ArrayDeque<>();
        int n;
        n=inputReader.nextInt();
        for(int i=1;i<=n;i++){
            if((i+1)%2==1){
                deque.addFirst(inputReader.nextInt());
            }else{
                deque.addLast(inputReader.nextInt());
            }
        }
        if(n%2==0){
            for(Integer i:deque){
                System.out.print(i.toString()+" ");
            }
        }else{
            for(int i=1;i<=n;i++){
                System.out.print(deque.removeLast().toString()+" ");
            }
        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}

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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;	
  // cin t;
   while(t--){
             string s;
             cin >> s;
             if(s == "ABC")
             cout << "ARC" << endl;
             else
             cout << "ABC" << endl;
   }
}


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

#define MAX 7368791

int main(){
    int m, n;
    while(true){
        cin >> m >> n;
        if(m == 0 && n == 0)
            break;

        //hurui
        vector<bool> huruvec(MAX+1, false);

        int sta = m;
        while(n != 0){
            //start
            while(huruvec[sta] == true)
                sta++;

            int pos = sta;
            while(pos <= MAX){
                huruvec[pos] = true;
                pos += sta;
            }

            n--;
        }

        //check
        while(huruvec[m] == true)
            m++;

        cout << m << endl;
    }
  
    return 0;
}



Measured memory_bytes: 4004
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <queue>

template<typename T>
class TBinaryHeap
{
    std::vector<T> FArray;
public:
    TBinaryHeap()
    {
        FArray.reserve(2000000);
        FArray.resize(1); // dummy
    }
    void push(const T& Value)
    {
        std::size_t Index = FArray.size();
        FArray.push_back(Value);
        std::size_t Parent;
        while(Index > 1){
            Parent = Index / 2;
            if(FArray[Index] < FArray[Parent]) return;
            std::swap(FArray[Index], FArray[Parent]);
            Index = Parent;
        }
    }
    void pop()
    {
        assert(FArray.size() >= 1);
        FArray[1] = FArray.back();
        FArray.pop_back();

        std::size_t Size = FArray.size();
        std::size_t Index = 1;
        std::size_t Left, Right;
        while(Index < Size){
            Left = Index * 2;
            Right = Left + 1;
            if(Left >= Size) break;
            std::size_t Target = Right >= Size ? Left : FArray[Left] > FArray[Right] ? Left : Right;
            if(FArray[Target] <= FArray[Index]) break;
            std::swap(FArray[Index], FArray[Target]);
            Index = Target;
        }
    }
    const T& top()
    {
        return FArray[1];
    }
};
int main()
{
    char Line[19];
    int Value;

    // std::priority_queue<int> S;
    TBinaryHeap<int> S;
    while(1){
        std::fgets(Line, 19, stdin);
        if(Line[0] == 'i'){
            S.push(std::atoi(&Line[7]));
        }else
        if(Line[1] == 'x'){
            std::printf("%d\n", S.top());
            S.pop();
        }else{
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 6220
import java.util.Scanner;

class Main {
    private static void solve() {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            if (n == -1) {
                break;
            }
            StringBuilder result = new StringBuilder();
            do {
                result.append(n % 4);
                n /= 4;
            } while (n > 0);
            System.out.println(result.reverse().toString());
        }
    }

    public static void main(String... args) {
        solve();
    }
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

// const ll mod = 1000000007;
// const ll mod = 998244353;

ll mod;
const int MAX_N = 3020;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void create_table(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n),ans(n,0);
    for (int i = 0;i < n;++i) cin >> a[i];
    mod = n;
    create_table(n-1);
    for (int i = 0;i < n;++i) if (a[i]) {
        ans[n-1]++;
        int c = 1;
        for (int j = 0;j < n;++j) {
            (ans[j] += -combi(n-1,j)*c) %= mod;
            (c *= -i) %= mod;
        }
    }
    for (int i = n-1;i >= 0;--i) cout << (ans[i]+mod)%mod << " \n"[i == 0];
    return 0;
}

Measured memory_bytes: 512
<?php
$str = trim(fgets(STDIN));
$len = strlen($str);
$b = 0;
$total = 0;
for($i = 0; $i < $len; $i++){
    if($str[$i] == "B"){
        $b++;
    }else{
        $total+=$b;
    }
}
echo $total;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
struct edge {
	int to;
	ll cost;
};
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}

int main() {
	COME_LET_THE_GAMES_BEGIN();
	ll L, R;
	cin >> L >> R;
	for (ll i = L; i <= R; i++) {
		if (i % 2019 == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll ans = LLONG_MAX;
	for (ll i = L; i <= R; i++) {
		for (ll j = i + 1; j <= R; j++) {
			ans = min(ans, (i * j) % 2019);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256