akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8



int main(){
	LL a, b, c, d, e, f;
	LL x, y, z;
	double p, q, r;
	string s = "a", t, u;
	
	a = b = c = d = e = f = 0;
	x = y = z = 0;
	p = q = r = 0.0;
	
	cin >> a >> b >> c >> d >> e >> f;
	cin.clear();
	cin >> s >> t >> u;
	cin.clear();
	
	puts(a==b?"Yes":"No");
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))

start = [0]*M
end = [0]*M
S = [0]*M
a = 0
score = 0
total = 0
for i in range(N-1):
    p, q = A[i]-1, A[i+1]-1
    start[q] += 1
    end[p] += 1
    S[q] += (q-p-1+M)%M
    total += (q-p+M)%M
    score += max(0, (q-p-1+M)%M - q)
    if p > q:
        a += 1

ans = total - score
ind = M-1
for _ in range(4*M):
    a -= end[ind]
    score += S[ind] - a
    a += start[ind]
    ind -= 1
    if ind < -M: ind += M
    ans = min(ans, total-score)
print(ans)

Measured memory_bytes: 13876
import Foundation

func main(){
   let n = Int(readLine()!)!
   var dict = ["AC":0, "WA":0, "TLE": 0, "RE": 0]
   for _ in 0..<n {
      let si = readLine()!
      dict[si] = (dict[si]!) + 1
   }
   
   print("AC x \(dict["AC"]!)")
   print("WA x \(dict["WA"]!)")
   print("TLE x \(dict["TLE"]!)")
   print("RE x \(dict["RE"]!)")
}
main()

Measured memory_bytes: 13440
n, m = map(int, input().split())
es = [list(map(int, input().split())) for _ in range(m)]

def test(k):
    d = {i + 1 : [] for i in range(n)}
    for i, (a, b) in enumerate(es):
        if i == k:
            continue
        d[a].append(b)
        d[b].append(a)
    q = [1]
    visited = set([])
    while True:
        if len(q) == 0:
            if len(visited) == n:
                return 0
            else:
                return 1
        q2 = q[:]
        q = []
        for v in q2:
            if v not in visited:
                visited.add(v)
                q.extend(d[v])
ans = 0
for k in range(m):
    ans += test(k)
print(ans)


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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------

LL N,K;
LL a[100010];

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);


    cin >> N >> K;

    REP(i, N){
        cin >> a[i];
    }

    if( (N - 1) % (K -1)  == 0 ){
        cout << (N - 1) / (K -1) << endl;
    }
    else{

        cout << (N - 1) / (K -1)  + 1<< endl;
    }


    return 0;
}


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

typedef pair<long long ,long long>P;

P p[100001];

int main(){


  int N,M;

  cin>>N>>M;

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

    p[i]=P(a[i],b[i]);
    
  }

  sort(p,p+N);

  int cnt=0;

  long long ans=0;
  
  for(int i=0;i<N;i++){
    
    if(cnt+p[i].second>=M){
      ans+=(p[i].first*(M-cnt));
      cout<<ans<<endl;
      return 0;
    }else{
      ans+=(p[i].first*p[i].second);
      cnt+=p[i].second;
    }

  }

  return 0;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

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

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int h,w;
int C[10][10];
int A[205][205];
int cost[10];
int tmpcost[10];

void dfs(int i, int c, int p, int tmp){
  if(tmpcost[c]<=tmp) return;
  else if(c==1) {
    chmin(cost[i],tmp);
    return;
  }
  tmpcost[c]=tmp;
  rep(j,10){
    dfs(i,j,c,tmp+C[c][j]);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>h>>w;
  rep(i,10) rep(j,10) cin>>C[i][j];
  rep(i,h) rep(j,w) cin>>A[i][j];
  rep(i,10) cost[i]=INF;
  rep(i,10){
    rep(j,10) tmpcost[j]=INF;
    dfs(i,i,-1,0);
  }
  int ans=0;
  rep(i,h){
    rep(j,w){
      if(A[i][j]==-1) continue;
      ans+=cost[A[i][j]];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int n, ans = 1e9, i;
    vector <pair<int, int> > v, w;
    map <int, int> mp1, mp2;
    map <int, int>::iterator it;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        int x;
        
        scanf("%d", &x);
        
        if (i % 2 == 0) {
            mp1[x]++;
        } else {
            mp2[x]++;
        }
    }
    
    mp1[1e9] = 0;
    mp2[1e9] = 0;
    
    for (it = mp1.begin(); it != mp1.end(); it++) v.push_back(make_pair(it->second, it->first));
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    
    for (it = mp2.begin(); it != mp2.end(); it++) w.push_back(make_pair(it->second, it->first));
    sort(w.begin(), w.end());
    reverse(w.begin(), w.end());
    
    for (i = 0; i < v.size(); i++) {
        int p = 0;
        
        if (v[i].second == w[0].second) p = 1;
        
        ans = min(ans, n - (v[i].first + w[p].first));
    }
    
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 6136
#include <stdio.h>

int N, P[20202], T[20202], A[20202], B[20202];

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

	A[0] = B[0] = 500000000;
	for (int i=0;i<N;i++) scanf ("%d",&P[i]), P[i]--;

	T[0] = 100000000;
	for (int i=0;i<N;i++) if (P[i] == 0){
		for (int j=0;j<N;j++) T[P[j]] = T[P[i]] + (j - i);
		break;
	}

	for (int i=1;i<N;i++){
		A[i]++; B[i]--;
		if (T[i] - T[i-1] > 0) A[i] += T[i] - T[i-1];
		else B[i] += T[i] - T[i-1];
	}

	for (int i=1;i<N;i++) A[i] += A[i-1];
	for (int i=1;i<N;i++) B[i] += B[i-1];

	for (int i=0;i<N;i++) printf ("%d%c",A[i],i+1<N?' ':'\n');
	for (int i=0;i<N;i++) printf ("%d%c",B[i],i+1<N?' ':'\n');
	return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    pair<ll, int> d[n];
    rep(i, n) cin >> d[i].first >> d[i].second;
    sort(d, d + n);

    ll ans = 0, cnt = 0;
    rep(i, n) {
        if (cnt + d[i].second <= m) {
            ans += d[i].first * d[i].second;
            cnt += d[i].second;
        } else {
            ans += (m - cnt) * d[i].first;
            cnt = m;
        }
        if (cnt == m) break;
    }

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


Measured memory_bytes: 1792
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

queue = deque([0])
ans = [-1]*n
ans[0] = 0
while len(queue)>0:
    node = queue.popleft()
    for c_node in graph[node]:
        if ans[c_node]>=0:
            continue
        ans[c_node] = node+1
        queue.append(c_node)
print('Yes')
for i in ans[1:]:
    print(i)

Measured memory_bytes: 37848
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int x,ans;cin>>x;
    if(x%2==0){
        ans=x/2-1;
    }
    else{
        ans=x/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3568
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

k,A,B,C = map(int,input().split())
Max = max(2*k+10,101)
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def Comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod

M = A+B
a = A*inv[M]%mod
b = B*inv[M]%mod
E = 0
for n in range(k,2*k):
    E += (((n)*pow(a,k,mod)%mod)*pow(b,n-k,mod)%mod)*Comb(n-1,k-1)%mod
    E += (((n)*pow(b,k,mod)%mod)*pow(a,n-k,mod)%mod)*Comb(n-1,k-1)%mod
    E %= mod
E = E*100*inv[100-C]%mod
print(E)

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

using namespace std;

int main()
{
    long long int i,k = 0;

    long long int n,a[500000],b[500000];

    cin >> n;

    for(i = 0;i < n;i++)
    {

        cin >> a[i];
    }
    long long int count1 = 0;
     for(i = 0;i < n-1;i++)
    {

        if(a[i+1] <= a[i])
        {
            count1++;

        }
        else
        {
            b[k] = count1;
            k++;
            count1 = 0;

        }
    }
    b[k] = count1;
    k++;
    long long int max1 = -1;
    for(i = 0;i < k;i++)
    {
        if(b[i] > max1)
        {

            max1 = b[i];

        }
    }
    cout << max1;
}


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

using namespace std;
int a[200005];
int main()
{
	int n,t;
	scanf("%d%d",&n,&t);
	for(int i=0;i<n;i++)
	 scanf("%d",&a[i]);
	long long sum=0;
	 int s,e;
	 s=a[0],e=a[0]+t;
	for(int i=1;i<n;i++)
	{
		if(e<a[i])
		{
			sum+=e-s;
			s=a[i];
			e=a[i]+t;
		//	cout<<s<<"s"<<endl;
		}
		else
		{
			e=a[i]+t;
		}
	}
	sum+=e-s;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
string S[1000];
int area_id[1000][1000];
int move_h[4] = {-1, 1, 0, 0};
int move_w[4] = {0, 0, -1, 1};
void dfs(int cur_h, int cur_w, int id, int H, int W){
  area_id[cur_h][cur_w] = id;

  for(int i = 0; i < 4; i++){
    int next_h = cur_h + move_h[i];
    int next_w = cur_w + move_w[i];
    if(0 <= next_h && next_h < H && 0 <= next_w && next_w < W
        && area_id[next_h][next_w] < 0 && S[next_h][next_w] != '#'){
      dfs(next_h, next_w, id, H, W);
    }
  }
}

int d[1000000];
set <int> edges[1000000];

int main(){
  int H;
  int W;
  cin >> H >> W;

  int C_h;
  int D_h;
  int C_w;
  int D_w;

  cin >> C_h >> C_w;
  cin >> D_h >> D_w;
  C_h --;
  C_w --;
  D_h --;
  D_w --;

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

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      area_id[i][j] = -1;
    }
  }

  int total_id = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(area_id[i][j] < 0 && S[i][j] != '#'){
        dfs(i, j, total_id, H, W);
        total_id++;
      }
    }
  }


  for(int i = 0; i < total_id; i++){
    d[i] = INT_MAX;
  }


  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(S[i][j] == '#'){
        continue;
      }
      int cur_id = area_id[i][j];
      for(int k = -2; k <= 2; k++){
        for(int l = -2; l <= 2; l++){
          int adj_h = i + k;
          int adj_w = j + l;
          if(0 <= adj_h && adj_h < H && 0 <= adj_w && adj_w < W
              && area_id[adj_h][adj_w] != cur_id && S[adj_h][adj_w] != '#'){
            edges[cur_id].insert(area_id[adj_h][adj_w]);
          }
        }
       }
    }
  }

  d[area_id[C_h][C_w]] = 0;
  queue <int> q;
  q.push(area_id[C_h][C_w]);
  while(!q.empty()){
    int cur = q.front();
    q.pop();
    for(auto it = edges[cur].begin(); it != edges[cur].end(); it++){
      int next = *it;
      if(d[next] == INT_MAX){
        d[next] = 1 + d[cur];
        q.push(next);
      }
    }
  }

  if(d[area_id[D_h][D_w]] == INT_MAX){
    cout << -1 << endl;
  } else {
    cout << d[area_id[D_h][D_w]] << endl;
  }

  return 0;
}


Measured memory_bytes: 75308
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    int N;
    cin >> N;
    map<ll, int> cnt;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        cnt[a]++;
    }

    ll low = -1;
    ll ans = 0;
    for (auto p : cnt) {
        if (p.second < 2)
            continue;

        if (p.second >= 4) {
            ans = p.first * p.first;
            low = p.first;
        } else if (low == -1) {
            low = p.first;
        } else {
            ans = p.first * low;
            low = p.first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6528
x = [int(x) for x in list(input())]


def operation(x):
    pattern = 2 ** len(x)
    for i in range(pattern):
        ops = '{:04b}'.format(i)
        s = 0
        for t, op in zip(x, ops):
            if op == '0':
                s += t
            else:
                s -= t
        if s == 7:
            return ops


ops = operation(x).replace('0', '+').replace('1', '-')
print(''.join([ops[i] + str(x[i]) for i in range(len(x))])[1:] + '=7')


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

typedef struct add_max_node {
  i64 add;
  i64 max;
} add_max_node;

typedef struct RMQandRAQ {
  add_max_node *a;
  i32 bit;
  i32 size;
} RMQandRAQ;

RMQandRAQ* new_RMQandRAQ (const i32 n) {
  i32 k = 0;
  while ((1 << k) < n) ++k;
  RMQandRAQ *s = (RMQandRAQ *) calloc (1, sizeof (RMQandRAQ));
  s->a = (add_max_node *) calloc (2 << k, sizeof (add_max_node));
  s->bit = k;
  s->size = 1 << k;
  return s;
}

static inline i64 max (i64 a, i64 b) {
  return a > b ? a : b;
}

static inline i64 eval (RMQandRAQ *s, i32 k) {
  return s->a[k].add + s->a[k].max;
}

void propagate (RMQandRAQ *s, i32 x) {
  x += s->size;
  for (i32 bit = s->bit; bit > 0; bit--) {
    i32 k = x >> bit;
    s->a[2 * k].add += s->a[k].add;
    s->a[2 * k + 1].add += s->a[k].add;
    s->a[k].add = 0;
    s->a[k].max = max (eval (s, 2 * k), eval (s, 2 * k + 1));
  }
}

void save (RMQandRAQ *s, i32 x) {
  for (i32 k = (x + s->size) >> 1; k >= 1; k >>= 1) {
    s->a[k].max = max (eval (s, 2 * k), eval (s, 2 * k + 1));
  }
}

void add (RMQandRAQ *s, i32 l, i32 r, i64 v) {
  for (i32 x = l + s->size, y = r + s->size; x < y; x >>= 1, y >>= 1) {
    if (x & 1) s->a[x++].add += v;
    if (y & 1) s->a[--y].add += v;
  }
  save (s, l);
  save (s, r - 1);
}

i64 find (RMQandRAQ *s, i32 l, i32 r) {
  propagate (s, l);
  propagate (s, r - 1);
  i64 ans = 0;
  for (l += s->size, r += s->size; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans = max (ans, eval (s, l++));
    if (r & 1) ans = max (ans, eval (s, --r));
  }
  return ans;
}

typedef struct node {
  i32 l, v, next;
} node;

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  node *a = (node *) calloc (m + 1, sizeof (node));
  i32 *start = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 i = 1; i <= m; ++i) {
    i32 l, r, v;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &r, &v);
    a[i] = (node) {l, v, start[r]};
    start[r] = i;
  }
  RMQandRAQ *s = new_RMQandRAQ (n + 1);
  for (i32 i = 1; i <= n; ++i) {
    i64 v = find (s, 0, i);
    add (s, i, i + 1, v);
    for (i32 p = start[i]; p; p = a[p].next) {
      add (s, a[p].l, i + 1, a[p].v);
    }
  }
  printf ("%" PRIi64 "\n", find (s, 0, n + 1));
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 11520
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&

//#define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#include <bits/stdc++.h>
using namespace std;

/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; 
*/
// find_by_order(), order_of_key() 

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#define int long long int 
#define ld long double
#define X first
#define Y second
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
const ld PI  = 3.141592653589793238463;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&

void solve(){
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	if(k){
		ans += min(k, a);
		k -= min(k, a);
	}
	if(k){
		k -= min(k, b);
	}
	if(k){
		ans -= min(k, c);
	}
	cout << ans << '\n';
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    //cin >> T;
    for(int i = 1; i <= T; ++i){
        solve();
    }
    return 0;
}
/*
Sample inp
*/

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n);
    vector<ll> c(n);
    for(ll i=0; i<n; i++){
        ll _p;
        cin >> _p;
        p[i] = _p-1;
    }
    for(ll i=0; i<n; i++){
        cin >> c[i];
    }
    
    ll best = -INFINITY;
    for(ll start=0; start<n; start++){
        unordered_set<ll> steped;
        ll score = 0;
        ll mode = 0;
        ll turnparloop = INFINITY;
        ll scoreparloop = 0;
        ll loopstart = -1;
        ll _turnls = 0;
        ll _scorels = 0;
        ll now = start;
        ll turn = 0;
        for(; turn<k; turn++){
            if(mode==0 && steped.count(now)){
                mode = 1;
                _turnls = turn;
                _scorels= score;
                loopstart = now;
            }else if(mode==1 && loopstart==now){
                mode = 2;
                scoreparloop = score - _scorels;
                turnparloop  = turn - _turnls;
                break;
            }
            if(mode==0)steped.insert(now);
            now = p[now];
            score += c[now];
            best = max(best,score);
        }
        if(scoreparloop>0){
            ll loops = max(0ll,(k-turn -1)/turnparloop -1);
            score += scoreparloop*loops;
            turn  += turnparloop*loops;
            best = max(best,score);
            for(; turn<k; turn++){
                now = p[now];
                score += c[now];
                best = max(best,score);
            }
        }
    }
    cout << best;
    return 0;
}


Measured memory_bytes: 3972
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/math/common_factor.hpp> 
#include<bits/stdc++.h>
using namespace std;
template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
	out<<p.first<<' '<<p.second;
	return out;
}
 
template<class T1,class T2>
istream& operator >> (istream& in,pair<T1,T2> &p)
{
	in>>p.first>>p.second;
	return in;
}
 
template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
	for(auto &x:v)
		in>>x;
	return in;
}
 
template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
	for(auto &x:v)
		out<<x<<'\n';
	return out;
}
 
template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
	for(auto x:v)
		out<<x<<' ';
	return out;
}
 
#define ll long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pii pair<int,int>
#define F first
#define S second
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;
#define maxn 200005
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// int pow(int a, int b, int m)
// {
// 	int ans=1;
// 	while(b)
// 	{
// 		if(b&1)
// 			ans=(ans*a)%m;
// 		b/=2;
// 		a=(a*a)%m;
// 	}
// 	return ans;
// }
 
// int fact[N], invfact[N];
 
// int modinv(int k)
// {
// 	return pow(k, MOD-2, MOD);
// }
 
// void precompute()
// {
// 	fact[0]=fact[1]=1;
// 	for(int i=2;i<N;i++)
// 	{
// 		fact[i]=fact[i-1]*i;
// 		fact[i]%=MOD;
// 	}
// 	invfact[N-1]=modinv(fact[N-1]);
// 	for(int i=N-2;i>=0;i--)
// 	{
// 		invfact[i]=invfact[i+1]*(i+1);
// 		invfact[i]%=MOD;
// 	}
// }
 
// int nCr(int x, int y)
// {
// 	if(y>x)
// 		return 0;
// 	int num=fact[x];
// 	num*=invfact[y];
// 	num%=MOD;
// 	num*=invfact[x-y];
// 	num%=MOD;
// 	return num;
// }
bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
long long power(long long x, long long int y, long long mod) { 
    long long res = 1; 
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y >> 1; 
        x =(x*x)%mod; 
    } 
    return res; 
}
int main()
{
    ios;
    int l,r,d;
    cin >> l >> r >>d;
  	int x=l/d,y=r/d;
  	if(l%d==0)
  	cout << y-x+1<<endl;
    else
    cout << y-x<<endl;
    
    return 0;
}

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

public class Main {

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        int[] nm = in.readLineAsIntArray();
        final int N = nm[0];
        final int M = nm[1];

        int low = 0;
        int high = N + 1;
        for (int i = 0; i < M; i++) {
            int[] lr = in.readLineAsIntArray();
            int L = lr[0];
            int R = lr[1];
            low = Math.max(low, L);
            high = Math.min(high, R);
        }
        System.out.println((high >= low) ? high - low + 1 : 0);


    }

    static class CustomReader extends BufferedReader {

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

    }
}

Measured memory_bytes: 44156
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        Map<String, Long> S = new HashMap<>();

        for (int i = 0; i < N; i++) {
            String[] s = in.next().split("");
            Arrays.sort(s);
            String ss = String.join("", s);
            if (!S.containsKey(ss)) {
                S.put(ss, 1L);
            } else {
                S.put(ss, S.get(ss) + 1);
            }
        }

        long res = 0;
        for (long v : S.values()) {
            res += v * (v - 1) / 2;
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 98972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=998244353;
const int siz=1e5;
const long inf=1e9;
int digit(long a){
    int res = 0;
    while(a > 0){
        res += a % 10;
        a /= 10;
    }return res;
}
int main(){
	int K; cin>>K;
    long a = 1; long t = 1;
    int cnt = 0;
	rep(i,0,16){
		while(t <= a * digit(t)){
            cout<<t<<endl;
            if(++cnt == K) return 0;
            t += a;
		}t -= a; a *= 10; t += a;
	}
}

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

namespace AtCoder {
    public class Program {
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(' ');
            int[] Ns = new int[Keys.Length];
            for (int i = 0; i < Keys.Length; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }

        static void Main() {
            int N = int.Parse(Console.ReadLine());
            int sub = 25 - N;
            string ans = "Christmas";
            for (int i = 0; i < sub; i++) {
                ans += " Eve";
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>j;
		n-=j;
	}
	if(n<0)
	n=-1;
	cout<<n;
}

Measured memory_bytes: 3632
#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[i];
    vector<int> ans;
    for (int i = n-1; i >= 0; i-=2) {
        ans.push_back(a[i]);
    }
    for (int i = (n % 2); i < n; i+=2) {
        ans.push_back(a[i]);
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i];
        if (i == ans.size()-1) {
            cout << endl;
        }
        else {
            cout << " ";
        }
    }
}

Measured memory_bytes: 3956
n = int(input())
a = list(map(int, input().split()))

flag = True
swap_count = 0
for i in range(0, n):
    if not flag:
        break
    flag = False
    for j in range(n-1, 0, -1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
            flag = True
            swap_count += 1

print(' '.join(map(str, a)))
print(swap_count)



Measured memory_bytes: 5596
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    StringBuilder s=new StringBuilder(sc.next());
    long sum=0,count=0;
    for(int i=s.length();i>0;i--) {
    	if(s.substring(i-1, i).equals("B")) {
    		sum+=(s.length()-count)-i;
    		count++;
    	}
    	//System.out.println(sum);
    }
    System.out.println(sum);
  }
}
//WWWWWWW

Measured memory_bytes: 38304
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T,class U> using P = pair<T,U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

vector<int> dy = { 0,0,1,-1 };
vector<int> dx = { 1,-1,0,0 };

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

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

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}


int main() {
	ll H, W, K; cin >> H >> W >> K;
	corner(W == 1, 1);
	map<int, ll> mp;
	mp[1] = mp[0] = mp[-1] = mp[-2] = mp[-3] = 1;

	for(int i = 1; i <= 10; ++i){
		for (int j = 0; j < (1 << i); ++j){
			bool flg = true;
			for(int k = 0; k < i - 1; ++k) if ((j << k)&(j << k + 1)) flg = false;
			if (flg) mp[i+1]++;
		}
	}

	V<V<ll>> dp(H+1, V<ll>(W + 2, 0));
	dp[0][1] = 1;
	int l,r;
	for(int i = 0; i<H; ++i){
		for (int j = 1; j <= W; ++j) {
			
			l = j - 1;
			r = W - j;
			(dp[i + 1][j] += (dp[i][j] * mp[l] * mp[r])%MOD) %= MOD;

			l = j - 2;
			r = W - j;
			(dp[i + 1][j - 1] += (dp[i][j] * mp[l] * mp[r]) % MOD) %= MOD;

			l = j - 1;
			r = W - j - 1;
			(dp[i + 1][j + 1] += (dp[i][j] * mp[l] * mp[r]) % MOD) %= MOD;
		}
	}
	cout << dp[H][K] << endl;
	
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")

XX = (-2, -2, -2, -1, -1, -1, 0, 0, 0)
YY = (-2, -1, 0, -2, -1, 0, -2, -1, 0)


def solve(H: int, W: int, N: int, a: "List[int]", b: "List[int]"):
    counter = Counter()
    for aa, bb in zip(a, b):
        for x, y in zip(XX, YY):
            if aa+x < 1:
                continue
            elif aa+x+2 > H:
                continue
            elif bb+y < 1:
                continue
            elif bb+y+2 > W:
                continue
            counter[(aa+x, bb+y)] += 1
    ans = [0]*10
    for key, val in counter.items():
        ans[val] += 1

    ans[0] = (H-2)*(W-2) - sum(ans)
    print(*ans, sep="\n")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(H, W, N, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 174812
n = int(input())
dp = [float("INF") for i in range(n+1)]
dp[0] = 0

for i in range(1, n+1):
  power = 1
  while power<=i:
    dp[i]=min(dp[i], dp[i-power]+1)
    power *= 6
  
  power = 1
  while power<=i:
    dp[i]=min(dp[i],dp[i-power]+1)
    power *= 9
print(dp[n])

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    int P[N]; rep(i, N) cin >> P[i];
    int Q[N]; rep(i, N) cin >> Q[i];
    vector<int> v;
    rep(i, N){
        v.push_back(i+1);
    }
    int fst = 0, snd = 0;
    int loop = 0;
    do{
        bool f = true, s = true;
        rep(i, N){
            if(P[i] != v[i]) f = false;
            if(Q[i] != v[i]) s = false;
        }
        if(f) fst = loop;
        if(s) snd = loop;
        loop++;
    }while(next_permutation(v.begin(), v.end()));
    cout << abs(fst-snd) << endl;
    return 0;
}

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

int main(){
  int i,j,cnt=0;
  int a,b,k;
  cin>>a>>b>>k;
  for(i=0;i<k;i++){
    if(i%2==0){
      if(a%2==1)a--;
      a/=2;
      b+=a;
    }else{
      if(b%2==1)b--;
      b/=2;
      a+=b;
    }
  }
  cout<<a<<" "<<b;
}

Measured memory_bytes: 256
// ABC160D - Line++

#include <bits/stdc++.h>
using namespace std;

int main() {
	int N, X, Y;
	cin >> N >> X >> Y;

	map<int, int> answer;

	for (int i = 1; i < N; i++) {
		for (int j = i + 1; j <= N; j++) {
			int temp;
			temp = min(j - i, abs(i - X) + 1 + abs(Y - j));
			answer[temp]++;
		}
	}

	for (int i = 1; i < N; i++) {
		cout << answer[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
long long a[100];
int main(){
	int n;
	scanf("%d",&n);
	a[0]=2;
	a[1]=1;
	for(int i=2;i<=n;i++){
		a[i]=a[i-1]+a[i-2];
	}
	printf("%lld\n",a[n]);
	return 0;


}

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

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

int h, w;
char g[101][101];

int sh[111][111], sv[111][111];

int main() {
	cin >> h >> w;
	int y, x;
	for (int i = 0; i < h; i++) {
		scanf("%s", g[i]);
		for (int j = 0; j < w; j++) {
			if (g[i][j] == 'E') y = i, x = j;
			if (g[i][j] == 'o') {
				sh[i][j + 1] = 1;
				sv[j][i + 1] = 1;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		partial_sum(sh[i], sh[i] + w + 1, sh[i]);
	}
	for (int j = 0; j < w; j++) {
		partial_sum(sv[j], sv[j] + h + 1, sv[j]);
	}

	int L = x;
	int R = w - x - 1;
	int U = y;
	int D = h - y - 1;

	typedef vector<int> v1;
	typedef vector<v1> v2;
	typedef vector<v2> v3;
	typedef vector<v3> v4;

	v4 dp(L + 2, v3(R + 2, v2(U + 2, v1(D + 2, -1e9))));
	dp[0][0][0][0] = 0;

	int ans = 0;
	for (int l = 0; l <= L; l++) {
		for (int r = 0; r <= R; r++) {
			for (int u = 0; u <= U; u++) {
				for (int d = 0; d <= D; d++) {
					int ll = r;
					int rr = w - l;
					int uu = d;
					int dd = h - u;

					// left
					if (x - l - 1 >= ll) {
						chmax(dp[l + 1][r][u][d], dp[l][r][u][d] + sv[x - l - 1][min(y + d + 1, dd)] - sv[x - l - 1][max(y - u, uu)]);
					}

					// right
					if (x + r + 1 < rr) {
						chmax(dp[l][r + 1][u][d], dp[l][r][u][d] + sv[x + r + 1][min(y + d + 1, dd)] - sv[x + r + 1][max(y - u, uu)]);
					}

					// up
					if (y - u - 1 >= uu) {
						chmax(dp[l][r][u + 1][d], dp[l][r][u][d] + sh[y - u - 1][min(x + r + 1, rr)] - sh[y - u - 1][max(x - l, ll)]);
					}

					// down
					if (y + d + 1 < dd) {
						chmax(dp[l][r][u][d + 1], dp[l][r][u][d] + sh[y + d + 1][min(x + r + 1, rr)] - sh[y + d + 1][max(x - l, ll)]);
					}

					ans = max(ans, dp[l][r][u][d]);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 34560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var n = Console.ReadLine();
            var ans = "No";

            for(int i = 0; i < n.Length; i++)
            {
                if (n[i] == '7') ans = "Yes";
            }

            Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 17324
#include<iostream>
#include<string>
#include<set>
#include<iterator>
#include<algorithm>
#include<vector>

using namespace std;

typedef basic_string<bool> BS;
const BS T=BS(1,true);
const BS F=BS(1,false);

char str[999];
char *p;

struct Cell{
  Cell *l,*r;
  BS bs;
  set<BS> sbs;
  int num,den;
  Cell():l(),r(),num(),den(1){
    while(*p==' '){
      p++;
    }
    if(*p=='x'){
      p++;
      bs=T+F;
    }else{
      p++;
      l=new Cell();
      r=new Cell();
      if(*r>*l){
	swap(l,r);
      }
      vector<BS> u,i;
      set_union(begin(l->sbs),end(l->sbs),begin(r->sbs),end(r->sbs),back_inserter(u));
      set_intersection(begin(l->sbs),end(l->sbs),begin(r->sbs),end(r->sbs),back_inserter(i));
      num=i.size();
      den=u.size();
      sbs=set<BS>(begin(u),end(u));
      bs=T+l->bs+r->bs+F;
    }
    p++;
    sbs.insert(bs);
  }
  bool operator>(const Cell &c)const{
    if(num*c.den!=c.num*den){
      return num*c.den<c.num*den;
    }else if(l==nullptr&&c.l==nullptr){
      return false;
    }else if(*l>*c.l||*c.l>*l){
      return *l>*c.l;
    }else{
      return *r>*c.r;
    }
  }
  void print(bool left){
    if(l==nullptr){
      cout<<'x';
    }else{
      cout<<'(';
      if(!left){
	swap(l,r);
      }
      l->print(true);
      cout<<' ';
      r->print(false);
      cout<<')';
    }
  }
  ~Cell(){
    delete l;
    delete r;
  }
};


int main(){
  while(cin.getline(str,999),str[0]!='0'){
    p=str;
    Cell c;
    c.print(true);
    cout<<endl;
  }
}

Measured memory_bytes: 1332
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll a,b,h;
    cin >> a >>b>> h;
    cout << (a+b)*h/2<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int d,n;
	while(~getII(d,n)){
		if(d==0) printf("%d\n",n==100?101:n);
		else if(d==1){
			for(int i=100,cnt=0	;;i+=100){
				i/=100;
				if(i%100!=0) cnt++;
				i*=100;
				if(cnt==n){
					printf("%d\n",i);
					break;
				}
			}
		}else{
			for(int i=10000,cnt=0;;i+=10000){
				i/=10000;
				if(i%100!=0) cnt++;
				i*=10000;
				if(cnt==n){
					printf("%d\n",i);
					break;
				}
			}
		}
	}
}


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

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

  vector<bool> p(102, true);

  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    p[t] = false;
  }

  for (int i = 0; ; i++) {
    if (p[x - i]) {
      cout << x - i << endl;
      break;
    }
    if (p[x + i]) {
      cout << x + i << endl;
      break;
    }
  }
}


Measured memory_bytes: 3508
import copy
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    money = 1000
    stock = 0
    day = 0

    while day < len(A) - 1:
        if A[day + 1] - A[day] > 0:
            cur = copy.deepcopy(day)
            while day < (len(A) - 1):
                if A[day + 1] - A[day] < 0:
                    break
                else:
                    day += 1

            r, m = divmod(money, A[cur])
            stock += r
            money -= r * A[cur]
            money += stock * A[day]
            stock = 0

        elif A[day + 1] - A[day] < 0:
            cur = copy.deepcopy(day)
            while day < (len(A) - 1):
                if A[day + 1] - A[day] > 0:
                    break
                else:
                    day += 1

            if day < len(A) - 1:
                r, m = divmod(money, A[day])
                stock += r
                money -= r * A[day]

        elif A[day + 1] - A[day] == 0:
            day += 1

    print(money)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9272
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
using Graph = vector<vector<int>>;



int main(){
    int N;
    cin >> N;
    int a;
    int Col[9] = {0};
    rep(i,N){
        cin >> a;
        if(a>=3200) a = 3200;
        Col[a/400]++;
    }
    int Min = 0, Max = 0;
    rep(i,8){
        if(Col[i]!=0){
            Min++; Max++;
        }
    }
    Max += Col[8];
    if(Min == 0) Min = 1;
    cout << Min <<  " " << Max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    if(N<1000) cout << "ABC" << endl;
    else cout << "ABD" << endl;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main ()
{
	ll a,b,c,d ;  cin>>a>>b>>c>>d;
	
	ll s=a*b;
	ll r=c*d;
	
	if(s>r){
		cout<<s<<endl;
	}
	else if(s==r){
		cout<<s<<endl;
	}
	else 
	cout<<r<<endl;
	


}



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

int pattern(int n,int s,int from){
	if(n>1){
		int i,x=0;
		for(i=from;i<9;i++){
			x+=pattern(n-1,s-i,i+1);
		}
		return x;
	}
	else{
		if(from<=s && s<10)return 1; else return 0;
	}
}

int main(void){
	int n,s;
	while(1){
		scanf("%d %d",&n,&s);
		if(n==0 && s==0)break;
		printf("%d\n",pattern(n,s,0));
	}
	return 0;
}

Measured memory_bytes: 600