akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

inline int read(){
	int x(0);char ch('@');bool flag(false);
	for(;!isdigit(ch);ch=getchar())	flag|=(ch=='-');
	for(;isdigit(ch);ch=getchar())	x=(x<<3)+(x<<1)+(ch^48);
	return flag?-x:x;
}

int a,b,n;

int main(){
	n=read(),a=read(),b=read();
	printf("%d",min(n*a,b));
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        String s = sc.next();
        char[] odd = {'R', 'U', 'D'};
        char[] even = {'L', 'U', 'D'};

        for (int i = 0; i < s.length(); i++) {
            if ((i+1) % 2 == 1) {
                switch (s.charAt(i)) {
                    case 'R':
                    case 'U':
                    case 'D':
                        break;
                    default:
                        System.out.println("No");
                        return;
                }
            } else {
                switch (s.charAt(i)) {
                    case 'L':
                    case 'U':
                    case 'D':
                        break;
                    default:
                        System.out.println("No");
                        return;
                }
            }
        }
        System.out.println("Yes");
    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;

ll geta=5000;
int  main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<ll>dp(geta*2,0LL);
  ll n,a;
  cin>>n>>a;
  dp[geta]=1;
  rep(i,n)
  {
    ll x;
    cin>>x;
    x-=a;
    if(x<0)
    {
      repi(j,-x,geta*2)
      {
        dp[j+x]+=dp[j];
      }
    }
    else
    {
      for(ll j=geta*2-x-1;j>=0;j--)dp[j+x]+=dp[j];
    }
  }
  cout<<dp[geta]-1<<endl;



  return 0;

}


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
  int i, n;
  scanf("%d", &n);

  int input_a[n];
  for( i = 0 ; i < n ; i++ )
    scanf("%d", &input_a[i]);

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



Measured memory_bytes: 2040
#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long LL;

static const int maxm = 2e6 + 10;
static const int INF = 1 << 30;

LL A[maxm],pre[maxm],suf[maxm];
LL N,D,Q,cur,x;

int main(){
	scanf("%lld%lld",&N,&D);
	
	for(int i = 1;i <= N;i++) scanf("%lld",&A[i]);
	
	pre[0] = D;
	for(int i = 1;i <= N;i++){
		if(cur < D && abs(D - cur) > abs(D - cur - A[i])){
			pre[i] = abs(D - cur - A[i]);
			cur += A[i];
		}
		else if(cur > D && abs(D - cur) > abs(cur - A[i] - D)){
			pre[i] = abs(cur - A[i] - D);
			cur -= A[i];
		}
		else pre[i] = pre[i - 1];
	}

	memset(suf,0x3f,sizeof suf);
	
	suf[N] = 1;
	for(int i = N - 1;i >= 1;i--){
		if(A[i + 1] / 2 >= suf[i + 1]) suf[i] = suf[i + 1];
		else suf[i] = suf[i + 1] + A[i + 1];
	}
	
//	for(int i = 1;i <= N;i++) printf("%d ",pre[i]); putchar(10);
//	for(int i = 1;i <= N;i++) printf("%d ",suf[i]); putchar(10);
	
	scanf("%lld",&Q);
	for(int i = 1;i <= Q;i++){
		scanf("%lld",&x);
		if(suf[x] <= pre[x - 1]) puts("YES");
		else puts("NO");
	}
	
	return 0;
}


Measured memory_bytes: 28416
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    int r = x%y;
    if (r == 0) {
        return y;
    }
    return gcd(y, r);
}

ll mypow(ll x, ll n) {
    if (n == 0) return 1;
    if (n%2 == 0) return mypow(((x%mod)*(x%mod))%mod, n/2);
    else return ((x%mod) * mypow(((x%mod)*(x%mod))%mod, (n-1)/2))%mod;
}

int main(){
    int N;
    cin >> N;
    vector<int> B(N);
    for (int i=1; i<N; i++) {
        int A;
        cin >> A;
        B.at(A-1)++;
    }
    for (int i=0; i<N; i++) cout << B.at(i) << endl;
}

Measured memory_bytes: 4056
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int D1[3] = { -2, -1, 0 };
const int D2[3] = { 0, 1, 2 };

int main() {
  ll H, W, N;
  cin >> H >> W >> N;
  map<int, map<int, bool> > grid;
  map<int, ll> counter;
  counter[0] = (H - 2) * (W - 2);

  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;

    grid[a][b] = true;

    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        int cnt = 0;
        int cy = a + D1[j];
        int cx = b + D1[k];
        if (cy <= 0 || cx <= 0 || H < cy + 2 || W < cx + 2) continue;

        for (int n = 0; n < 3; n++) {
          for (int m = 0; m < 3; m++) {
            int ny = cy + D2[n];
            int nx = cx + D2[m];

            if (grid[ny][nx]) cnt++;
          }
        }

        counter[cnt - 1]--;
        counter[cnt]++;
      }
    }
  }

  for (int i = 0; i <= 9; i++) {
    cout << counter[i] << endl;
  }

  return 0;
}


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

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

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

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

int main(){
	LL h,w;
    cin>>h>>w;
    if(h==1||w==1){
        cout<<1<<endl;
    }else{
    cout<<(h/2)*w+(h&1)*(w+1)/2<<endl;
    }

}


Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<deque>
#include<vector>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>
#include<unordered_set>
#include<unordered_map>
 
#define pi 3.141592653
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt","w",stdout);
#define ii pair<int,int> 
#define fast_io cin.tie(0), cin.sync_with_stdio(false);
#define inf 0x3f3f3f3f
#define sup_inf 1e18
#define f first
#define s second
#define eps 1e-9

#define nl ( no << 1)
#define nr ( no << 1)|1
#define mid l+(( r-l)>>1)
 
using namespace std;
typedef long long ll;	
typedef long double ld;
typedef unsigned long long ull;
typedef  pair< long long , pair< int,int> > iii;

const int maxn = 2e5 + 100; 
const int MAX = 1010;
const int mod = 1e9 + 7;
const int MAXLV = 16;
 

using namespace std;



int a[maxn];


int n;




ll sub( ll a, ll b) {
  a-=b;
  if ( a < 0 )a = mod + a;
  return a;
}

ll sum ( ll a, ll b ){
  return ( a+ b )  % mod ;
}

int main () {
  
  //~ in
  
  fast_io
  
  cin >> n;
  
  
  
  ll tot = 0;
  
  for(int i = 0 ;i < n;i++ ){ 
    cin >> a[i];
    tot  = sum  ( tot, a[i] );
  }
  
  ll ans = 0;
  for(int i = 0 ;i < n;i++) { 
    tot = sub ( tot , a[i] );
    ans = sum ( ans, ( a[i] * tot) % mod ) % mod;
  }
  
  cout << ans << '\n';
  
  
  
  
  
  
  return 0;
}







Measured memory_bytes: 3948
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
string s;
bool hantei(string t){
    int m=t.size();
    for(int i=0;i<m/2;i++){
        if(t[i]!=t[m-1-i]){
            return true;
        }
    }
    return false;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    int n=s.size();
    string b,a;
    b=s.substr(0,(n-1)/2);
    a=s.substr((n-1)/2+1,n-(n-1)/2);
    //cout<<b<<" "<<a<<"\n";
    bool check=false;
    check=check|hantei(s);
    check=check|hantei(a);
    check=check|hantei(b);
    if(!check)yes;
    else no;
}


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

const int INF=1e9+5;

int main(){
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i=0;i<n;i++)
     cin>>h[i];
  int dp[n];
  
  for(int i=0;i<n;i++)
    dp[i]=INF;
  
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=1;j<=k;j++){
      if(i+j<n)
        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
  }
  printf("%d\n",dp[n-1]);
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
int N;
int a[55], b[55];
ll po(int k) {
	ll ret = 1;
	for (int i = 0; i < k; i++)ret *= 2;
	return ret;
}
int solve(set<int>need,int num){
	need.erase(num);
	ll dist[55][55];
	for (int i = 0; i < 55; i++)for (int j = 0; j < 55; j++) {
		if(i == j)dist[i][j] = 0;
		else dist[i][j] = inf;
	}
	for (int a = 1; a <= 50; a++) {
		fore(k,need) { dist[a][a%k] = 1; }
	}
	for (int k = 0; k <= 50; k++) {    
		for (int i = 0; i <= 50; i++) {   
			for (int j = 0; j <= 50; j++) {  
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
 
	int ok = 1;
	for (int i = 0; i < N; i++) {
		if (dist[a[i]][b[i]] > 1e15)ok = 0;
	}
	return ok;
}
 
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	cin >> N;
	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++)cin >> b[i];
	set<int>need;
	for (int i = 1; i <= 50; i++)need.insert(i);
    if(!solve(need,-1)){puts(-1);return 0;}
	for (int i = 50; i >= 1; i--)if (solve(need, i))need.erase(i);
	ll ans = 0;
	fore(x, need)ans += po(x);
	puts(ans);
	
	return 0;
}

Measured memory_bytes: 256
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300IQ as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String hi[]) throws Exception
      {
         //lmao
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int max = 100;
        int[] res = new int[N+1];
        for(int x=1; x <= max; x++)
          for(int y=1; y <= max; y++)
            for(int z=1; z <= max; z++)
            {
             	int v = x*x+y*y+z*z+x*z+y*z+x*y;
                if(v <= N) res[v]++;
            }
         for(int i=1; i <= N; i++)
           System.out.println(res[i]);
      }
   }

Measured memory_bytes: 39076
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600

class UnionFind {
public:
  vector<int> par, rank; // parent(negative := its root and abs-value is its size), depth
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){ // ?????????x?????????????????????????????????????????´??????
    x=find(x); y=find(y);
    if(x==y) return;  // already belong to same tree
    par[x] += par[y];
    par[y] = x;
    if(rank[x]==rank[y]) rank[x]++;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int size(int x){ return -par[find(x)]; }
}; // END class UnionFind


vector<vector<int> > tree;
vector<int> par;
bool marked[100005];
bool mark_dup[100005];

int main(){
  int n,q;
  while(cin>>n>>q, n|q){
    tree = vector<vector<int> >(n, vector<int>());
    par = vector<int>(n, 0);
    repl(i,1,n){
      int d;
      scanf("%d", &d);
      d--;
      tree[d].pb(i);
      par[i] = d;
    }

    vector<char> qc(q); // query char
    vector<int>  qi(q); // query int
    rep(i,q) scanf(" %c %d", &qc[i], &qi[i]);
    rep(i,q) qi[i]--;

    // ??¨??????????????¨??¨?????????????????????
    fill(marked, marked+n, false);
    fill(mark_dup, mark_dup+q, false);
    marked[0]=true;
    rep(i,q) if(qc[i]=='M'){
      if(marked[qi[i]]) mark_dup[i]=true;
      else marked[qi[i]] = true;
    }

    // ??????????????????????????????????????¨?????????UnionFind??????
    UnionFind uf = UnionFind(n);
    rep(i,n) for(auto v : tree[i]){
      if(!marked[v]) uf.unite(i,v);
    }

    // ?????¨???????????????????????????
    long ans=0;
    for(int i=q-1; i>=0; i--){
      if(qc[i]=='M' && !mark_dup[i]){
        uf.unite(par[qi[i]], qi[i]);
      } else if(qc[i]=='Q'){
        int x = qi[i];
        //if(uf.find(x) == x) x=par[x]; //??????????????§???????????????????????????
        ans += (long)uf.find(x)+1;
      }
    }

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

Measured memory_bytes: 11232
def solution():
    n = int(input())
    s = [input() for i in range(n)]
    s.sort()
    ss = [] 
    prev_str = s[0]
    max_cnt = same_cnt = 1
    s.pop(0)
    for si in s:
        if prev_str == si:
            same_cnt += 1
        else:
            ss.append([same_cnt, prev_str])
            if max_cnt < same_cnt:
                max_cnt = same_cnt
            same_cnt = 1
            prev_str = si
    ss.append([same_cnt, prev_str])
    if max_cnt < same_cnt:
        max_cnt = same_cnt
    for sss in ss:
        if sss[0] == max_cnt:
            print(sss[1])

solution()

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

int main() {
    long int n;
    cin >> n;
    
    int k = 0;
    long int max = 0, pow = 1;
    while (max < n) {
        k++;
        pow *= 26;
        max += pow;
    }
    
    for (; k > 0; k--) {
        char alf = 'z';
        pow /= 26;
        while (n + pow - 1 < max) {
            max -= pow;
            alf--;
        }
        cout << alf;
        
    }
    cout << endl;
}

Measured memory_bytes: 3616
#!/usr/bin/env python
# encoding: utf-8


class Solution:
    @staticmethod
    def stack_polish_calc():
        # write your code here
        # array_length = int(input())
        calc_func = ('+', '-', '*')
        array = [str(x) for x in input().split()]
        # print(array)
        result = []
        for i in range(len(array)):
            if array[i] not in calc_func:
                result.append(str(array[i]))
            else:
                calc = array[i]
                arg_2 = result.pop()
                arg_1 = result.pop()
                result.append(str(eval(str(arg_1) + calc + str(arg_2))))

        print(*result)


if __name__ == '__main__':
    solution = Solution()
    solution.stack_polish_calc()

Measured memory_bytes: 7564
#include<iostream>
#include<map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

int main() {
  int N;
  cin >> N;
  map<int, int> m;
  int a;
  rep(i,1,N) {
    cin >> a;
    m[a] = i;
  }
  rep(i,1,N) cout << m[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 5504
n, k = [int(i) for i in input().split()]
a = [int(i)-1 for i in input().split()]
x = list(range(n))

def calc(a, b):
    c = [0] * n
    for i in range(n):
        c[i] = b[a[i]]
    return c

while k:
    if k & 1 == 1:
        x = calc(x, a)
    k //= 2
    a = calc(a, a)

print(x[0]+1)

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

int main(){
  char a, b;
  cin >> a >> b;
  
  if(a=='H' and b=='H' or a=='D' and b=='D'){
    cout << 'H' << endl;
  }
  else{
    cout << 'D' << endl;
  } 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(6);
  for(int i = 0;i < 6;i++){
    cin >> a[i];
  }
  for(int i = 0;i < 5;i++){
    for(int j = 0;j < 5;j++){
      if(i == j)continue;
      if(abs(a[i] - a[j]) > a[5]){
        cout << ":(" << endl;
        return 0;
      }
  	}
  }
  cout << "Yay!" << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin>>n;
	vll d(n);
	rep(i, n) cin>>d[i];
	sort(all(d));

	ll d1 = d[n/2-1];
	ll d2 = d[n/2];

	cout << d2-d1 << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
const int N=2005;
const int mod=998244353;
int n,sum[N],C[N][N],f[N][N],ans;char s[N];
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;++i)sum[i]=sum[i-1]+s[i]-'0';
	for(int i=C[0][0]=1;i<=n;++i)
		for(int j=C[i][0]=1;j<=i;++j)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	f[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j){
			if(j&&j<=sum[i])f[i][j]=(f[i][j]+f[i-1][j-1])%mod;
			if(j<i&&i-j<=2*i-sum[i])f[i][j]=(f[i][j]+f[i-1][j])%mod;
		}
	for(int i=max(0,sum[n]-n);i<=sum[n]&&i<=n;++i)ans=(ans+1ll*f[n][i]*C[n][sum[n]-i])%mod;
	printf("%d\n",ans);return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  cout << A.at(N - 1) - A.at(0) << "\n";
}

Measured memory_bytes: 3540
#include <math.h>
#include <stdio.h>
#define p2(x) ((x)*(x))
#define mul(rx,ry,x1,y1,x2,y2) ((rx)=(x1)*(x2)-(y1)*(y2),(ry)=(x2)*(y1)+(x1)*(y2))
#define R 1
double X[300],Y[300],hyp,t,pl,dx,dy,x[2],y[2];
main(N,M,m,i,j,k,z){for(;scanf("%d",&N),N;printf("%d\n",M)){
	for(i=0;i<N;i++)scanf("%lf%lf",X+i,Y+i);
	for(M=1,i=0;i<N;i++)for(j=i+1;j<N;j++){
		hyp=hypot(X[j]-X[i],Y[j]-Y[i]);
		if(hyp>2*R)continue;
		//t=( p2(R)-p2(R)+p2(hyp) )/( 2*hyp );
		t=hyp/2;
		pl=sqrt(p2(R)-p2(t));
		dx=(X[j]-X[i])/hyp;
		dy=(Y[j]-Y[i])/hyp;
		mul(x[0],y[0],dx,dy,t,pl);
		mul(x[1],y[1],dx,dy,t,-pl);
		x[0]+=X[i],x[1]+=X[i],y[0]+=Y[i],y[1]+=Y[i];
		for(z=0;z<2;z++){
			for(m=k=0;k<N;k++)if(p2(X[k]-x[z])+p2(Y[k]-y[z])<R*R+1e-9)m++;
			if(M<m)M=m;
		}
	}
}return 0;}

Measured memory_bytes: 656
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	for (int i = 1; i < b; i++) {
		if (a * i % b == c) {
			cout << "YES" << endl;

			return 0;
		}
	}
	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n, x = 0;
    scanf("%d", &n);
    for (int i=1; i<=n && i<10; ++i) {
        ++x;
    }
    for (int i=100; i<=n && i<1000; ++i) {
        ++x;
    }
    for (int i=10000; i<=n && i<100000; ++i) {
        ++x;
    }
    printf("%d\n", x);
    return 0;
}


Measured memory_bytes: 128
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll A, B, C, X;
    cin >> A >> B >> C >> X;
    ll count = 0;
    rep(i, A+1) {
        rep(j, B+1) {
            rep(k, C+1) {
                if (i * 500 + j * 100 + k * 50 == X) {
                    count++;
                }
            }
        }
    }
    print(count);
    return 0;
}


Measured memory_bytes: 256
def main():
  import sys
  from numpy import int32
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import floyd_warshall
  f=floyd_warshall
  t=int32(sys.stdin.buffer.read().split())
  n,m,l=t[:3]
  t=t[3:]
  m*=3
  print('\n'.join((f(f(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1).astype(int).astype(str)))
main()

Measured memory_bytes: 33428
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <functional>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

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

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

int ar[1010][1010];
int used[1010][1010];
int n, m;
int check(int i, int j, int c) {
    return i >= 0 && i < n && j >= 0 && j < m && ar[i][j] == c;
}
void operator += (pii &a, pii b) {
    a.first += b.first, a.second += b.second;
}
pii dfs(int i, int j) {
    if (used[i][j])
        return { 0, 0 };
    used[i][j] = 1;
    pii ans = { 0, 0 };
    if (ar[i][j])
        ans.first = 1;
    else
        ans.second = 1;
    int c = ar[i][j] ^ 1;
    if (check(i - 1, j, c))
        ans += dfs(i - 1, j);
    if (check(i + 1, j, c))
        ans += dfs(i + 1, j);
    if (check(i, j - 1, c))
        ans += dfs(i, j - 1);
    if (check(i, j + 1, c))
        ans += dfs(i, j + 1);
    return ans;
}

int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    //srand(time(NULL));
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
    cin >> n >> m;
    forn(i, n) {
        forn(j, m) {
            char c;
            cin >> c;
            ar[i][j] = (c == '#');
        }
    }
    ll ans = 0;
    forn(i, n) {
        forn(j, m) {
            pii a = dfs(i, j);
            ans += 1LL * a.first * a.second;
        }
    }
    cout << ans;


    return 0;
}

Measured memory_bytes: 20992
//omajinai
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
//omajinai

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;
    string ss;
    cin >> ss;
    vector<int> s(n);
    for(int i = 0;i < n;i ++){
        s.at(i) = ss.at(i) - '0';
    }

    vector<int> t(1001);

    for(int i = 0;i < 1001;i ++){
        int a = -1,b = -1,c = -1;
        int x = i / 100;
        int y = i / 10;
        y = y % 10;
        int z = i % 10;

        int j,k,l;
        for(j = 0;j < n;j ++){
            if(s.at(j) == x){
                a = 1;
                break;
            }
        }
        for(k = j+1;k < n;k ++){
            if(s.at(k) == y){
                b = 1;
                break;
            }
        }
        for(l = k+1;l < n;l ++){
            if(s.at(l) == z){
                c = 1;
                break;
            }
        }

        if(a == 1 && b == 1 && c == 1){
            t.at(i) = 1;
        }
    }

    int ans = 0;
    for(int i = 0;i < 1001;i ++){
        ans += t.at(i);
    }

    cout << ans << endl;

}

Measured memory_bytes: 512
S = gets.chomp
MOD = 10**9 + 7

d0, d1 = Array.new(13, 0), Array.new(13, 0)
d0[0] = 1
a = 10.times.flat_map{|i| 13.times.map{|j| [(10*j + i) % 13, j]}}
S.chars do |c|
  d1.fill(0)
  (c == '?' ? a : a[13*c.to_i, 13]).each{|i, j| d1[i] = (d1[i] + d0[j]) % MOD}
  d0 = d1.dup
end
puts d0[5]

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

int main(){
vector<int> a(3);
cin >> a[0] >> a[1] >> a[2] ;
sort( a.begin(), a.end() );
cout << a[0] <<" "<< a[1] <<" "<< a[2] << "\n";
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define ll long long
#define N 100010
#define mo 998244353
using namespace std;
template <typename T> void read(T &x){
	x=0;char c=getchar();int fh=1;
	while (!isdigit(c)){if (c=='-')fh=-1;c=getchar();}
	while (isdigit(c))x=x*10+c-'0',c=getchar();
	x*=fh;
}
struct Info{int x,y,z;}a[N],b[N];
bool comp(const Info &a,const Info &b){if (a.y!=b.y)return a.y<b.y;return a.x<b.x;}
int m,n,x,y,z,nb,na,dp[N][2],no[2],ne[2];
ll q,p;
bool pa(int x,int y,int z){return (a[x].x==y&&a[x].y==z);}
void add(int &x,int y){x+=y;if (x>=mo)x-=mo;}
ll po(ll x,ll y){ll z=1;while (y){if (y%2)z=x*z%mo;x=x*x%mo;y/=2;}return z;}
int main(){
	read(n);read(m);
	for (int i=1;i<=m;i++){
		read(x);read(y);read(z);
		if (x<y) swap(x,y);
		if (x-2>y){b[++nb].x=x;b[nb].y=y;b[nb].z=z;}
		else{a[++na].x=x;a[na].y=y;a[na].z=z;}
	}
	sort(b+1,b+nb+1,comp);p=nb;
	for (int i=2;i<=nb;i++)
		if(b[i].x==b[i-1].x&&b[i].y==b[i-1].y){p--;if (b[i].z!=b[i-1].z){puts("0");return 0;}}
	if (n>3)q=1ll*(n-2)*(n-3)/2;p=q-p;
	sort(a+1,a+na+1,comp);
	dp[0][0]=1;
	for(int i=1,j=0;i<=n;i++){
		if(pa(j+1,i,i-1)){
			j++;
			if(pa(j+1,i,i-1)){
				j++;ne[1]=ne[0]=0;ne[a[j].z^a[j-1].z]++;
			}else ne[1]=ne[0]=1;
		}else ne[1]=ne[0]=2;
		if (i==1)ne[1]=ne[0]=1;
		if(pa(j+1,i+1,i-1)){
			j++;
			if(pa(j+1,i+1,i-1)){
				j++;no[1]=no[0]=0;no[a[j].z^a[j-1].z]++;
			}else no[1]=no[0]=1;
		}else no[1]=no[0]=2;
		if (i==1||i==n)no[1]=no[0]=1;
		if (pa(j+1,i,i)){j++;no[a[j].z^1]=0;}
		for (int p=0;p<=1;p++)
			for (int k=0;k<=1;k++)add(dp[i][k],1ll*dp[i-1][p]*ne[p^k]*no[k]%mo);
	}
	cout<<(dp[n][0]+dp[n][1])*po(2,p)%mo<<endl;
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n;
string s;
void aaa(char a){
    if(a+n>'Z'){
        a='A'+a+n-'Z'-1;
        cout<<a;
    }
    else {

        //cout<<<a+n;
        a=a+n;
        cout<<a;
    }
}
int main(){
    cin>>n;
    cin>>s;
    for(int i = 0;i < s.size(); i++){
        aaa(s[i]);
    }
    return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

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

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

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

const int S=5010;
int a[S],dp1[S][S],dp2[S];
vi tr[S];

int dfs(int v,int p){
	int s=1;
	if(a[v]>0)
		dp2[v]=0;
	dp1[v][0]=a[v];
	for(auto ch:tr[v])
		if(ch!=p){
			int t=dfs(ch,v);
			{
				int w=dp2[ch];
				REP(i,t)
					if(dp1[ch][i]<0)
						chmin(w,i+1);
				dp2[v]+=w;
				chmin(dp2[v],inf);
			}
			REP(i,t)if(dp1[ch][i]<0)
				chmin(dp1[ch][i+1],0);
			if(dp2[ch]<t)
				chmin(dp1[ch][dp2[ch]+1],0);
			for(int i=s;i>=0;i--){
				int w=dp1[v][i];
				dp1[v][i]=inf;
				REP(j,t+1){
					chmin(dp1[v][i+j],w+dp1[ch][j]);
				}
			}
			s+=t;
		}
	return s;
}


signed main(){
	int n=read();
	REP(i,n+1){
		REP(j,n+1)
			dp1[i][j]=inf;
		dp2[i]=inf;
	}
	REP(i,n)
		a[i]=read();
	REP(_,n-1){
		int u=read()-1,v=read()-1;
		tr[u].PB(v);
		tr[v].PB(u);
	}
	dfs(0,-1);
	int ans=dp2[0];
	REP(i,n)if(dp1[0][i]<0)
		chmin(ans,i);
	print(ans);
}


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

int main(){
  string s;
  cin>>s;
  long long k;
  cin>>k;
  long long len=s.size();
  long long ans=0,i=0;
  if(s.at(0)!=s.at(len-1)){
    while(i<len-1){
      if(s.at(i)==s.at(i+1)){ans++; i+=2;}
      else i++;
    }
    cout<<ans*k<<endl;
  }else{
    long long cnta=1,cntb=1;
    for(long long i=1;i<len;i++){
      if(s.at(i-1)==s.at(i)) cnta++;
      else break;
    }
    for(long long i=len-2;i>=0;i--){
      if(s.at(i)==s.at(i+1)) cntb++;
      else break;
    }
    if (cnta==len && cntb==len) {cout<<(len*k)/2<<endl; return 0;}
    while(i<len-1){
      if(s.at(i)==s.at(i+1)){ans++; i+=2;}
      else i++;
    }
    if (cnta%2==0 && cntb%2==0) cout<<ans*k<<endl;
    else if(cnta%2==1 && cntb%2==1) cout<<ans*k+k-1<<endl;
    else cout<<ans*k<<endl;
  }
}

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

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

using namespace std;

int main() {
  int n, m;
  std::cin >> n >> m;
  std::map<int, int> map;
  rep(i, n) {
    int k;
    std::cin >> k;
    rep(i, k) {
      int a;
      std::cin >> a;
      map[a]++;
    }
  }

  int sum = 0;
  for (auto i : map) {
    if (i.second == n) {
      sum++;
    }
  }

  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 3640
while 1:
    r,c=map(int,raw_input().split())
    if r==c==0:break
    osenbei=[map(int,raw_input().split()) for _ in xrange(r)]
    r_osenbei=[None]*c
    for i in xrange(c):
        st=""
        for j in xrange(r):
            st+=str(osenbei[j][i])
        r_osenbei[i]=int(st,2)
    ans=-1
    for i in xrange(1<<r):
        cnt=0
        for j in xrange(c):
            n=bin(i^r_osenbei[j]).count('1')
            cnt+=max(n,r-n)
        ans=max(ans,cnt)
    print(ans)

Measured memory_bytes: 7624
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    vi a(3); for(auto& e : a) cin >> e;
    sort(_all(a));

    int res = a[0];
    if(a[0] == a[1]){
        res = a[2];
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int N, A, B; cin >> N >> A >> B;
    int sum = 0;
    rep (i, A, N+1) {
        int n = i, s = 0;
        while (n > 0) {
            int r = n % 10;
            s += r;
            n /= 10;
        }
        if (s >= A && s <= B) sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll nCr(int n, int r){
  ll num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];
    for(string &s : S) sort(all(s));
    map<string,int> M;
    for(string s : S)M[s]++;
    ll sum = 0;
    for(auto p : M){
        if(p.se == 1) continue;
        sum += nCr(p.se, 2);
    }
    cout << sum << endl;

}

Measured memory_bytes: 14076
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  REP(x, k+1) REP(y, k+1){
    if(x+y > k) continue;
    int z = k-x-y;
    int s = a, t = b, u = c;
    REP(i, x) s *= 2;
    REP(i, y) t *= 2;
    REP(i, z) u *= 2;
    chmax(ans, s+t+u);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc144/tasks/abc144_e


# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる

# 求めたいのは最大値！
# 最小はxにできると仮定してみる？
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort()  # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)])  # ここから崩すことができるポイントを探せる


def is_ok(x, K):
    for i in range(N):
        if A[i] * F[i] <= x:
            continue
        a = A[i] - (x // F[i])  # Kから使うべき個数
        K -= a
        if K < 0:
            return False
    return K > -1


def meguru_bisect(ng, ok):
    '''
    define is_okと
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, K):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(-1, 10**12 + 1))


Measured memory_bytes: 106956
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    string s;
    cin >> s;
    int k;
    cin >> k;
    set<string> a;
    for (int i = 1; i <= 5 && i <= s.size(); i++)
    {
        for (int j = 0; j <= (s.size() - i); j++)
        {
            a.insert(s.substr(j, i));
        }
    }
    auto itr = a.begin();
    rep(i, k)
    {
        if (i == k-1)
            cout << *itr << endl;
        itr++;
    }
    return 0;
}

Measured memory_bytes: 1664
N = int(input())
a = [int(x) for x in input().split()]

d = {}

for i in a :
    if i in d.keys() :
        d[i] += 1
    else :
        d[i] = 1

tot = 0
for k in d.keys() :
    if d[k] < k :
        tot += d[k]
    elif d[k] > k :
        tot += d[k] - k
        
print(tot)

Measured memory_bytes: 17780
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N;
  string S;
  cin  >> N >> S;
  for(int i=0;i<S.size();i++){
    if(S[i]+N>'Z'){
      S[i]='A'+S[i]+N-'Z'-1;
    }
    else S[i]+=N;
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
ans=[-1 for i in range(n)]

newB=[]
cnt=1
old=B[0]
for i in range(1,n):
    if old!=B[i]:
        newB.append((old,cnt))
        cnt=1
        old=B[i]
    else:
        cnt+=1
else:
    newB.append((old,cnt))
B=deque(newB)

def firstDec():
    now=B.popleft()
    if now[1]>1:
        B.appendleft((now[0],now[1]-1))

tori=0

for i in range(n):
    if B[0][0]!=A[i]:
        ans[i]=B[0][0]
        firstDec()
        continue

    B.rotate(-1)
    if B[0][0]!=A[i]:
        ans[i]=B[0][0]
        firstDec()
        continue
    
    OK=False
    while tori<i:
        if ans[tori]!=B[0][0] and A[tori]!=B[0][0]:
            ans[i]=ans[tori]
            ans[tori]=B[0][0]
            OK=True
            break
        B.rotate()
        if ans[tori]!=B[0][0] and A[tori]!=B[0][0]:
            ans[i]=ans[tori]
            ans[tori]=B[0][0]
            OK=True
            break
        tori+=1
    if OK:
        continue
    
    print("No")
    break
else:
    print("Yes")
    print(" ".join([str(num) for num in ans]))
        


Measured memory_bytes: 122968
#include <set>
#include <map>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int n;
char s[1000];
map <string, int> m;

int main() {

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		string str = s;
		sort(str.begin(), str.end());
		m[str]++;
	}

	long long res = 0;

	for (map <string, int>::iterator it = m.begin(); it != m.end(); it++) {
		long long d = (*it).second;
		res += d * (d - 1) / 2LL;
	}

	printf("%lld\n", res);

	return 0;

}

Measured memory_bytes: 11136
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;



//??????
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int j = 1; j < N; j++) cout << ", " << v[j]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()



int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		
		char _train[2048] = {};
		char* train = &_train[1024];

		int pos = 0;
		train[pos] = str[0];

		for (int j = 0; j < str.size() / 3; j++) {
			int index = 3 * j + 1;
			if (str.substr(index, 2) == "->")
				pos++;
			else
				pos--;
			train[pos] = str[index + 2];
		}

		string ans;
		for (int j = -1000; j < 1000; j++) {
			if (train[j] != 0) ans.push_back(train[j]);
		}
		
		cout << ans << endl;
	}

	return 0;
}

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

int main(){
    int n;
    while(cin >> n && n > 0){
        for(int i = 0; i < 9; i++){
            int tmp;
            cin >> tmp;
            n -= tmp;
        }
        cout << n << endl;
    }
    return 0;
}



Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
bool isprime[200005];
void ai(){
	int now=2;
	for(int now=2;now<200005;now++){
		if(isprime[now]==false){
			continue;
		}
		for(int i=now+now;i<=200005-now;i+=now){
			isprime[i]=false;
		}
	}
}
int main(){
	for(int i=0;i<200005;i++){
		isprime[i]=true;
	}
	ai();
	int n;
	cin>>n;
	for(int i=n;i<100005;i++){
		if(isprime[i]){
			cout<<i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
E = [[] for i in range(N + 1)]

for i in range(N - 1):
	a, b = map(int, raw_input().split())
	E[a].append(b)
	E[b].append(a)

c = map(int, raw_input().split())
c.sort(reverse = True)
print sum(c[1:])

ans = [0] * (N + 1)
def func(pos, pre, id):
	ans[pos] = c[id]
	id += 1
	for to in E[pos]:
		if to != pre:
			id = func(to, pos, id)
	return id

func(1, -1, 0)
print " ".join(map(str, ans[1:]))

Measured memory_bytes: 13880
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        int max = Collections.max(a);
        int min = Collections.min(a);
        System.out.println(max - min);
    }
}

Measured memory_bytes: 35976