akhauriyash/Code-Regression huggingface dataset:
fun main(arg: Array<String>) {
    val (N, X) = listOfInt()
    val A = listOfLong()
    val M = Array<Array<Long>>(N) { Array<Long>(N) { 0 }}
    for (k in 0 until N) {
        for (n in 0 until N) {
            if (k == 0) M[k][n] = A[n]
            else M[k][n] = Math.min(M[k-1][n], A[(N + n - k) % N])
        }
    }
//repeat(N) { System.err.println(M[it].joinToString()) }
    var ans = Long.MAX_VALUE
    for (k in 0 until N) {
        var min = (X.toLong() * k) + M[k].sum()
        if (min < ans) ans = min
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }
fun listOfLong() = listOfString().map { it.toLong() }


Measured memory_bytes: 205508
#!/usr/bin/perl

my ($a,$b) = map {$_ - 0} split(/\s+/o,<STDIN>);
my $x = sprintf("%d",$a) . sprintf("%d",$b);

for(my $i=1;$i<=317;$i++){
  my $x2 = sprintf("%d",($i*$i));
  if( $x2 eq $x ){
    print "Yes\n";
    exit(0);
  }
}
print "No\n";

exit(0);



Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    if (S.length() % 2 == 0) {
        string first = S.substr(0, S.length() / 2);
        string second = S.substr(S.length() / 2, S.length());
        if (first == second) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define INF 999999999
using namespace std;

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

    int a , b, c;
    rep(i, 0, n+1){//b
        rep(j, 0, n+1){//c
            if((5000 * i + 9000 * j == 10000 * n - y) && (i + j) <= n){
                b = i;
                c = j;
                goto ok;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;


    ok:;
    a = n - b - c;
    cout << a << " " << b << " " << c << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  ll v[N][N];
  bool ischecked[N][N];
  rep(i,N)rep(j,N)cin >> v[i][j];
  rep(i,N)rep(j,N) ischecked[i][j] = false;
  ll ans = 0;
  bool issat = true;
  rep(i,N)repp(j,i+1,N) ans += v[i][j];
  rep(i,N){
    repp(j,i+1,N){
      rep(k,N){
        if(i==k||j==k)continue;
        if(v[i][k] + v[k][j] == v[i][j] && !ischecked[i][j]){
          ischecked[i][j] = true;
          ans -= v[i][j];
        } else if(v[i][k] + v[k][j] < v[i][j]) issat = false;
      }
    }
  }
  if(issat) cout << ans << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 1024
class node:
    def __init__(self,nodeid):
        self.parent = "" 
        self.child = []
        self.childid = []
        self.depth = 0
        self.parent = -1
        self.parentid = -1
        self.nodeid = nodeid
        self.type = "root"
    def setChild(self,cn):
        self.child.append(cn)
        self.childid.append(cn.nodeid)
        cn.parent = self
        cn.parentid = self.nodeid
        cn.depth = self.depth + 1
        cn.setNodeType()
        self.setNodeType()
        return
    def getDepth(self):
        cnt = 0
        t = self
        while True:
            if (t.parentid == -1 or  cnt > 10):
                break
            t = t.parent
            cnt = cnt + 1
        return cnt

    def getChildCount(self):
        return len(self.child)
    def setNodeType(self):
        if (self.depth == 0):
            self.type = "root"
        else:
            if (len(self.child) == 0 ):
                self.type = "leaf"
            else:
                self.type = "internal node" 
    def getNodeType(self):
        return self.type
    def showNode(self):
        print ('node {}: parent = {}, depth = {}, {}, {}'.format(self.nodeid,self.parentid,self.getDepth(),self.getNodeType(),self.childid))
        return

nl = []
n = int(input())
for i in range(0,n):
    nl.append(node(i))

for i in range(0,n):
    nodeinfo = list (map(int,input().split()))
    for j in nodeinfo[2:]:
        nl[nodeinfo[0]].setChild(nl[j])
for i in range(0,n):
    nl[i].showNode()



Measured memory_bytes: 53556
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int>a(4,0);int x;
  for(int i=0;i<6;i++){
    cin>>x;a.at(x-1)++;
  }
  if(count(a.begin(),a.end(),1)==2&&count(a.begin(),a.end(),2)==2)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <limits>
using namespace std;
template <typename T, bool directed>
class Dinic
{
public:
  Dinic(int n) : n(n), capacity(n, vector<T>(n)), edges(n) {}
  void add_edge(int src, int dst, T cap)
  {
    capacity[src][dst] = cap;
    capacity[dst][src] = directed ? 0 : cap;
    edges[src].push_back(dst);
    edges[dst].push_back(src);
  }

  T max_flow(int s, int t)
  {
    T flow = 0;
    while (bfs(s, t))
    {
      // 無駄な辺を何度も調べないために、各頂点に既に調べた辺を持たせる。
      // 各頂点でdfsを続きからできるようにするイメージ
      start.assign(n, 0);
      flow += dfs(t, s, numeric_limits<T>::max());
    }
    return flow;
  }

private:
  int n;
  vector<int> level, start;
  vector<vector<T>> capacity;
  vector<vector<int>> edges;
  // n: 頂点数
  // level: 残余グラフ上の始点からの各点の最短距離
  // start: 各点で探索した辺のインデックス、ステップごとに初期化
  // capacity: 隣接行列で辺の容量を保持

  // 残余グラフ上でsからの最短距離を計算する。tに辿り着けなかったらfalseを返す。
  bool bfs(int s, int t)
  {
    level.assign(n, -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty())
    {
      int v = que.front();
      que.pop();
      for (int nv : edges[v])
        if (capacity[v][nv] > 0 && level[nv] < 0)
        {
          level[nv] = level[v] + 1;
          que.push(nv);
        }
    }
    return level[t] != -1;
  }

  // 逆辺をたどる。
  // limit: 現時点で流せる最大量
  // 1ステップでvから流せる量をresにまとめることで、DFSが一回で済む。
  T dfs(int v, int s, T limit)
  {
    if (v == s)
      return limit;

    T res = 0;
    for (int &i = start[v]; i < (int)edges[v].size(); ++i)
    {
      int nv = edges[v][i];
      // 距離が増加する向きの辺のみ調べる。
      if (capacity[nv][v] > 0 && level[v] == level[nv] + 1)
      {
        // d: 流せた量
        T d = dfs(nv, s, min(limit, capacity[nv][v]));
        if (d > 0)
        {
          capacity[nv][v] -= d;
          capacity[v][nv] += d;
          res += d;
          limit -= d;
          if (limit == 0)
            break;
        }
      }
    }
    return res;
  }
};

int main()
{
  int V, E, u, v, c;
  cin >> V >> E;
  Dinic<int, true> dn(V);
  for (int i = 0; i < E; ++i)
  {
    cin >> u >> v >> c;
    dn.add_edge(u, v, c);
  }
  cout << dn.max_flow(0, V - 1) << endl;
  return 0;
}


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

int main(){
    int n,m,memo = 0;
    cin >> n >> m;
    int t[n],a[m],b[m],c[m],dp[n][m] = {0};
    
    
    rep(i,0,n){
        cin >> t[i];
    }
    rep(i,0,m){
        cin >> a[i] >> b[i] >> c[i];
    }
    rep(i,0,n){
        rep(j,0,m){
            dp[i][j] = 0;
        }
    }
    
    rep(i,1,n){ 
        rep(j,0,m){ //前日
            rep(k,0,m){//当日
                if(a[j] <= t[i-1] && t[i-1] <= b[j] && a[k] <= t[i] && t[i] <= b[k]){
                    dp[i][k] = max(dp[i][k],abs(c[j]-c[k])+dp[i-1][j]);
                }
            }
        }
    }
    /*
    rep(i,0,n){
        rep(j,0,m){
            cout << dp[i][j] << " ";  
        }
        cout << endl;
    }
    */
    
    rep(i,0,m){
        memo = max(memo,dp[n-1][i]);
    }
    
    
    
    cout << memo << endl;
    
    return 0;
}


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

int main(){
    ll N; cin >> N;
    vector <P> A(N);
    rep(i,N){
        ll a,b; cin >> a >> b;
        A[i]=make_pair(b,a);
    }
    sort(A.begin(),A.end());
    
    bool ok=true;
    ll sum=0;
    rep(i,N){
        sum+=A[i].second;
        if (A[i].first<sum){
            ok=false;
            break;
        }
    }
    
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
int main(void){
    int N;
    int max[2];
    scanf("%d",&N);
    int A[N];
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    max[0] = 1;
    max[1] = 1;
    for(int i=0;i<N;i++){
        if(A[i]>=max[0]){
            max[1] = max[0];
            max[0] = A[i];
        }else if(A[i]>=max[1]){
            max[1] = A[i];
        }
    }
    for(int i=0;i<N;i++){
        if(max[0] == A[i]) printf("%d\n",max[1]);
        else printf("%d\n",max[0]);
    }
    
    return 0;
}


Measured memory_bytes: 2304
//
// Created by 10940 on 2020/7/25.
//

#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long ULL;
int main() {
    int k;
    cin >> k;
    int ans;
    if (k % 2 == 0 || k % 5 == 0) {
        ans = -1;
    } else {
        int t = 7 % k;
        ans = 1;
        while (t != 0) {
            t = t * 10 + 7;
            t %= k;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    string s;cin>>s;
    REP(i,s.size()/2){
        if(s[i]!=s[s.size()-1-i]){
            cout<<"No"<<endl;return;
        }
    }int l=(s.size()-1)/2;
    REP(i,l/2){
        if(s[i]!=s[l-1-i]){
            cout<<"No"<<endl;return;
        }
    }cout<<"Yes"<<endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    int x;
    cin >> x;
    if(400 <= x && x <= 599) cout << 8 << endl;
    else if(600 <= x && x <= 799) cout << 7 << endl;
    else if(800 <= x && x <= 999) cout << 6 << endl;
    else if(1000 <= x && x <= 1199) cout << 5 << endl;
    else if(1200 <= x && x <= 1399) cout << 4 << endl;
    else if(1400 <= x && x <= 1599) cout << 3 << endl;
    else if(1600 <= x && x <= 1799) cout << 2 << endl;
    else if(1800 <= x && x <= 1999) cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n,v[100010];
    cin>>n;
    for(int i=0;i<n;i++)cin>>v[i];
    sort(v,v+n,greater<ll>());
    ll ans=0;
    for(int i=0;i<n;i++){
	ll t=v[i]-(i+1);
	//chmax(t,0LL);
	ans+=t;
    }
    cout<<ans<<endl;
}





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

using namespace std;

typedef long long ll;

int main()
{
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = -1000000000000LL;
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      if(B*i % j == 0 && abs(A-B*i/j) < abs(A-ans)) {
	ans = B*i/j;
      }
    }
  }
  cout << abs(A-ans) << endl;

  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    static char[][] A;
    static int h, w;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String res = "Possible";
        h = sc.nextInt();
        w = sc.nextInt();
        A = new char[h][w];
        for(int i = 0; i < h; i++) A[i] = sc.next().toCharArray();
        dfs(0, 0);
        for(char[] ca : A) if(String.valueOf(ca).contains("#")) res = "Impossible";
        System.out.println(res);
    }
    static void dfs(int y, int x) {
        A[y][x] = '.';
        if(y + 1 < h && A[y + 1][x] == '#') dfs(y + 1, x);
        else if(x + 1 < w && A[y][x + 1] == '#') dfs(y, x + 1);
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

int cnt[N];

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	for(int i = 1; i < N; i++) {
		for(int j = i; j < N; j += i) {
			cnt[j]++;
		}
	}
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i < n; i++) {
		ans += cnt[n - i];
	}
	cout << ans;

	return 0;
}

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

ll g(ll n) {return n*(n+1)/2;}

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i=1; i <= n; ++i){
    ans += i * g(n/i);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

string IntToString(int number)
{
	stringstream ss;
	ss << number;
	return ss.str();
}

int n;
int a[100001];

int main()
{
    ci >> n;
    rep(i, n) ci >> a[i];

    sort(a, a + n);
    int mn = a[0];

    int cnt = 0;
    int idx = 0;
    while(cnt != n - 1) {
	cnt = 0;

	int next_mn = mn;
	int next_idx = idx;
	for(int i = 0; i < n; i++) {
	    if(i == idx) continue;
	    a[i] %= mn;
	    if(a[i]) {
		if(next_mn > a[i]) {
		    next_mn = a[i];
		    next_idx = i;
		}
	    }
	    else cnt++;
	}
	mn = next_mn;
	idx = next_idx;

	//rep(i, n) co << a[i] << ' ';ln;
    }

    co << mn << en;
    
    return 0;
}





Measured memory_bytes: 640
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n,d,x;
  cin >> n >> d >> x;

  vi a(n);

  rep(i,n) cin >> a[i];

  int sum = 0;
  for(int i = 0;i < d;i++)
  {
    for(int j = 0;j < n;j++)
    {
      if(i % (a[j] ) == 0)
        sum++;
    }
  }

  sum += x;

  cout << sum << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
// abc128_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;

    vector<vector<bool>> S(M, vector<bool>(N, false));
    vector<int> p(N);

    int k, idx;
    REP(i, M){
        cin >> k;
        REP(j, k) {
            cin >> idx;
            S[i][idx-1] = true;
        }
    }
    REP(i, M) cin >> p[i];

    int ans = 0;
    REP(_n, 1 << N){

        int sm = 0;
        REP(m, M){
            int n = _n;
            int tmp = 0;
            REP(i, N){
                tmp += (n & 1) && S[m][i];
                n >>= 1;
            }

            if (tmp % 2 == p[m]) {
                sm++;
            }
        }

        if (sm == M){
            ans++;
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include<boost/math/common_factor.hpp>
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a,n) int a[n]; for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b,x) for(int i=a;i<b;i+=x)
const int MOD = 1000000007;
const int N = 10001;
//const int N = (2 * (1e5)) + 2;

int dp[105][100005];
int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    
    int t = 1;
    //cin >> t;
    while (t--) {
        int N, W;
        cin >> N >> W;
        vector<int> w(N), v(N);
        for (int i = 0; i < N; i++) {
            cin >> w[i] >> v[i];
        }

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

        cout << dp[N - 1][W] << endl;
    }
    return 0;

}






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

const int mod = 1e9+7;

int dp[5002][5002];

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


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	dp[0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=n;j++){
			add(dp[i+1][j+1],dp[i][j]);
			add(dp[i+1][j+1],dp[i][j]);
			add(dp[i+1][max(0,j-1)],dp[i][j]);
		}
	long long int tmp=dp[n][s.size()];
	for(int i=0;i<s.size();i++)
		tmp=tmp*500000004%mod;
	cout<<tmp<<endl;
	
}


Measured memory_bytes: 97920
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        char c;cin>>c;
        if(c<='z'&&c>='a'){
            cout<<'a';
        }
        else{
            cout<<'A';
        }
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3652
n,a,b = map(int,input().split())
s = list(input())
tuka = []
ab = []
for i in s:
    if len(tuka) < (a+b):
        if i=="a":
            tuka.append(i)
            print('Yes')
        elif i=="b":
            if len(ab)<b:
                ab.append(i)
                tuka.append(i)
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 57848
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include<string>
using std::string;

int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  
  int domestic = 0;
  int foreigner = 0;
  int max = a + b;
  
  string s;
  cin >> s;
  for (int i = 0; i < n; i ++)
  {
    if (s.at(i) == 'a')
    {
      if (domestic + foreigner < max)
      {
        cout << "Yes" << endl;
        domestic ++;
      }
      else cout << "No" << endl;
    }
    else if (s.at(i) == 'b')
    {
      if (domestic + foreigner < max && foreigner < b)
      {
        cout << "Yes" << endl;
        foreigner ++;
      }
      else cout << "No" << endl;
    }
    else
      cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 896
for i in range(input()):
    a= map(float,raw_input().split())
    vx=[a[i]-a[i+2] for i in range(0,8,4)]
    vy=[a[i]-a[i+2] for i in range(1,8,4)]
    if(vx[0]*vy[1]-vx[1]*vy[0]==0):
        print "YES"
    else:
        print "NO"

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//実行部
void Main()
{
  str s; cin >> s;
  ll ans = 0;
  for(ll i = s.size();i >= 0;i--)
  {
    if(s[i] =='B')
    {
      ans += s.size() - i - 1;
      s.pop_back();
    }
  }
  fin(ans);
  return;
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 720
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */

#include <bits/stdc++.h>
//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BTaxRate {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        int res = -1;
        for (int i = 1; i <= n; ++i) {
            if (i * 108 / 100 == n) {
                res = i;
            }
        }
        if (res == -1) {
            out << ":(" << "\n";
        } else {
            out << res << "\n";
        }
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BTaxRate solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


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

void solve(int N, std::vector<std::string> S)
{
  for(auto& s: S)
  {
    std::sort(s.begin(), s.end());
  }
  std::sort(S.begin(), S.end());
  long long anagram_count = 1;
  long long combination_count = 0;
  for (int i = 1; i < S.size(); i++)
  {
    if(S[i]==S[i-1])
    {
      anagram_count ++;
    }

    if(S[i]!=S[i-1]|| i==S.size()-1)
    {
      combination_count += anagram_count*(anagram_count-1)/2;
      anagram_count= 1;
    }

  }
  std::cout << combination_count << std::endl;

}

int main(void)
{
  int N;
  std::cin >> N;
  std::vector<std::string> s(N);
  for(auto i0 = 0; i0 < N; ++i0)
  {
    std::cin >> s[i0];
  }
  solve(N,s);
  return 0;
}


Measured memory_bytes: 12800
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    S = [input().strip("\n") for _ in range(H)]
    DP = [[100000 for w in range(W)] for _ in range(H)]
    ncol = (0 if S[0][0] == "." else 1)
    q = deque()
    q.append((0, 0, ncol, ncol))
    Se = ((0, 1), (1, 0))
    while q:
        h, w, d, c = q.popleft()
        if d < DP[h][w]:
            DP[h][w] = d
            if c == 0:
                for dh, dw in Se:
                    if h + dh < H and w + dw < W:
                        if S[h+dh][w+dw] == ".": q.append((h+dh, w+dw, d, 0))
                        else: q.append((h+dh, w+dw, d+1, 1))
            else:
                for dh, dw in Se:
                    if h + dh < H and w + dw < W:
                        if S[h+dh][w+dw] == ".": q.append((h+dh, w+dw, d, 0))
                        else: q.append((h+dh, w+dw, d, 1))
    print(DP[H-1][W-1])
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const long long MOD = 1000000007;

int N;
ll A[100];

signed main(){
    cin >> N;
    REP(i, N) cin >> A[i];
    ll m = 1000;
    FOR(i, 1, N){
        if(A[i - 1] >= A[i]) continue;
        ll d = A[i] * (m / A[i - 1]);
        m %= A[i - 1];
        m += d;
    }
    PRINT(m);
    return 0;
}

Measured memory_bytes: 3624
import string

S = input()
dictt = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13,
         'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
dic2 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
        'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

base = '0'
if len(S) < 26:
    for i in range(len(S)):
        bag = set()
        for s in S[:len(S)-i]:
            bag.add(dictt[s])
        for j in range(1, 27):
            if not j in bag:
                print(S+dic2[j-1])
                exit()
else:
    for i in range(len(S)):
        bag = set()
        for s in S[:len(S)-i]:
            bag.add(dictt[s])
        the_last_letter = (S[len(S)-i-1])
        avail_index = dictt[the_last_letter]
        for j in range(avail_index+1, 27):
            if not j in bag:
                print(S[:len(S)-i-1]+dic2[j-1])
                exit()
    print(-1)


Measured memory_bytes: 3828
#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 1e9
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), AA(N);
    rep(i, N) {
        cin >> A[i];
        AA[i] = A[i] * 2;
    }

    vector<ll> B(N);
    ll bo, sum = 0;
    rep(i, N) {
        if (i % 2 == 0)
            sum += AA[i];
        else
            sum -= AA[i];
    }

    bo = sum / 2;
    B[0] = bo;
    cout << B[0] << " ";
    for (int i = 1; i < N; i++) {
        B[i] = AA[i - 1] - B[i - 1];
        cout << B[i] << " ";
    }
    cout << endl;
}

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

int main() {
 int N, M; cin >> N >> M;
  vector<int> num(N);
  vector<int> a(M);
  vector<int> b(M);
  for(int i = 0; i < M;i++) cin >> a[i] >> b[i];
  for(int i = 0; i < M;i++){
    num[a[i]-1]++;
    num[b[i]-1]++;
  }
  for(int i = 0; i< N;i++){
    cout << num[i] << endl;
  }
}


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

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

    vector <long long> val(N);
    vector <long long> rval(N);

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

    sort(val.begin(), val.end());
    rval = val;
    reverse(rval.begin(), rval.end());

    const long long INF = 1000000000000000000LL;
    long long low = -INF;
    long long up = INF;
    long long ans = INF;

    while (low <= up) {
        long long rank = 0; // how many numbers <= mid
        long long mid = (low+up) / 2;

        for (int i = 0; i < val.size(); ++i) {
            if (val[i] < 0) {
                int low1 = 0;
                int up1 = rval.size()-1;
                int greater = -1;

                while (low1 <= up1) {
                    int mid1 = (low1 + up1) / 2;
                    long long res = val[i] * rval[mid1];

                    if (res <= mid) {
                        greater = mid1;
                        low1 = mid1+1;
                    } else {
                        up1 = mid1-1;
                    }
                }

                rank += (greater+1);
            } else {
                int low1 = 0;
                int up1 = val.size()-1;
                int greater = -1;

                while (low1 <= up1) {
                    int mid1 = (low1 + up1) / 2;
                    long long res = val[i] * val[mid1];

                    if (res <= mid) {
                        greater = mid1;
                        low1 = mid1+1;
                    } else {
                        up1 = mid1-1;
                    }
                }

                rank += (greater+1);
            }
        }

        for (int i = 0; i < val.size(); ++i) {
            if (val[i]*val[i] <= mid) { //avoid self*self
                --rank;
            }
        }

        rank /= 2;

        if (rank >= K) {
            up = mid-1;
            ans = mid;
        } else {
            low = mid+1;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
  int h,w;
  while(cin >> h >> w,h){
    REP(i,h){
      REP(j,w) cout << (i==0||i==h-1||j==0||j==w-1?'#':'.');
      puts("");
    }
    puts("");
  }
}


Measured memory_bytes: 3076
#include<iostream>
#include<cmath>
#include<climits>
using namespace std;

int getMinM(int e){
	int mini=INT_MAX;
	for(int y=0;y*y<=e;y++){
		for(int z=0;z*z*z<=e;z++){
			int x = e - ( y*y + z*z*z );
			if(e== x + y*y + z*z*z && x>=0) mini=min(mini,x+y+z);
		}
	}
	return mini;
}

int main(){
	while(1){
		int e;
		cin >> e;
		if(e==0) break;
		int mini=INT_MAX;
		cout << getMinM(e) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n;cin>>n;
    ll res = 0;
    for(ll i=1;i*i<=n;i++){
        if((n-i)%i==0&&(n-i)/i>i){
            res += (n-i)/i;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, m;
    ll l;
    cin>>n>>m>>l;
    ll d[303][303];
    const ll INF=1e18;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i==j) d[i][j]=0;
            else d[i][j]=INF;
        }
    }
    for(int i=0; i<m; i++){
        int a, b, c;
        cin>>a>>b>>c;
        a--; b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
    ll d2[303][303];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i==j) d2[i][j]=0;
            else d2[i][j]=INF;
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i==j) continue;
            if(d[i][j]<=l) d2[i][j]=1;
        }
    }
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                d2[i][j]=min(d2[i][j], d2[i][k]+d2[k][j]);
            }
        }
    }
    int q; cin>>q;
    for(int i=0; i<q; i++){
        int s, t;
        cin>>s>>t;
        s--; t--;
        if(d2[s][t]==INF) cout<<-1<<endl;
        else cout<<d2[s][t]-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1920
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
//#define double long double
//#define double float
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 998244353; const int MAX = 200060;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;



int N, A[1 << 20];
P dp1[1 << 20];
int dp2[1 << 20];
bool comp(const int &a, const int &b) {
	return A[a] > A[b];
}
void solve() {
	cin >> N;
	REP(bit, 1 << N)cin >> A[bit];
	dp1[0] = { 0,0 };
	FOR(bit, 1, 1 << N) {
		vector<int>v;
		v.push_back(bit);
		REP(i, N)if (bit&(1 << i)) {
			v.push_back(dp1[bit ^ (1 << i)].first);
			v.push_back(dp1[bit ^ (1 << i)].second);
		}
		sort(all(v));
		v.erase(unique(all(v)), v.end());
		sort(all(v), comp);
		dp1[bit] = { v[0],v[1] };
	}
	FOR(bit, 1, 1 << N) {
		dp2[bit] = A[dp1[bit].first] + A[dp1[bit].second];
	}
	FOR(bit, 2, 1 << N) {
		dp2[bit] = max(dp2[bit], dp2[bit - 1]);
	}
	FOR(bit, 1, 1 << N)print(dp2[bit]);
}

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


Measured memory_bytes: 17408
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

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 << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

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

    int counter = 1;
    char current, before;
    for(int i=0; i<N-1; i++) {
        if (S[i+1]!=S[i]){
            counter++;
        }
    }
    cout << counter << endl;

    return 0;
}


Measured memory_bytes: 512
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops"
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , m ;

void solve(){	

	string s , t ;
	cin>> s >> t ;
	n=s.length()  , m = t.size();

	ll ans = inf ;
	for(ll i=0;i <= n-m ; i++){
		ll cnt=0;
		for(ll j=i ; j<m+i ; j++){
			if(s[j]!=t[j-i])cnt++;
		}
		ans = min(ans , cnt);
	}
	cout<<ans<<endl;

}


int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

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

int main(){
        int W, H, x, y, r;
        cin >> W >> H >> x >> y >> r;

        if( x >= r && x <= W-r && y >= r && y <= H-r)
                cout << "Yes" << endl;
        else{
                cout << "No" << endl;
        }
        return 0;
}



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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    ll K;
    std::cin >> K;

    vector<ll> A(50);
    iota(ALL(A), K / 50);

    ll mod = K % 50;
    REP(i, 50) {
        if(i < mod) {
            A[i] += 50 - mod + 1;
        }
        else {
            A[i] -= mod;
        }
    }

    std::cout << A.size() << std::endl;
    REP(i, 50) {
        std::cout << A[i] << " ";
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int w,a,b;
  cin>>w>>a>>b;
  if(a+w<b){
    cout<<b-(a+w)<<"\n";
  }else{
    if(a>b+w){
      cout<<a-(b+w)<<"\n";
    }else{
      cout<<"0\n";
    }
  }
}



Measured memory_bytes: 256
n,q = map(int, input().split())
s = "#" + input() + "#"
l = [tuple(input().split()) for _ in range(q)]
def move(x,g):
  for i in l:
    if i[0] == s[x]:
      x += (i[1]=="R") or -1
  return x==g
hi1 = n+1
lo1,lo2 = 0,0
while hi1-lo1>1:
  mid1 = (hi1+lo1)//2
  if move(mid1,n+1):
    hi1 = mid1
  else:
    lo1 = mid1
hi2 = hi1
while hi2-lo2>1:
  mid2 = (hi2+lo2)//2
  if move(mid2,0):
    lo2 = mid2
  else:
    hi2 = mid2
print(hi1-lo2-1)

Measured memory_bytes: 19920