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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;
  vll h(n);
  rep(i, n) {
    cin >> h[i];
  }

  vll dp(n + 10, INF);
  dp[0] = 0;
  rep(i, n - 1) {
    chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    if (i + 2 < n) {
      chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
  }

  cout << dp[n - 1] << endl;

  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    string in;
    cin >> in;
    unordered_map<char, int> m;
    for (int i = 0; i < in.size(); ++i) {
        m[in[i]]++;
    }
    for (auto i : m) {
        if (i.second % 2 != 0) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;


int main() {
	int n;
	cin >> n;
	vector<int> a;
	rep(i, n) {
		int x;
		cin >> x;
		a.push_back(x);
	}
	int whole = pow(3, n);
	int even = 0;
	rep(i, n) {
		if (a[i] % 2 == 0) even += 1;
	}
	cout << whole - pow(2,even) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 18, maxm = 2600;
long long a[maxn];
map<tuple<int,int,int,int>, long long> f;
long long solve(int l, int r, int xl, int xr){
	if(l + 1 >=r) return 0;
	long long ans = 1ll<<60;
	for(int i = l + 1; i < r; i++){
		ans = min(ans, solve(l, i, xl, xl + xr) + solve(i, r, xl + xr, xr) + (xl + xr) * a[i]);
	}
	return ans;
}
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	cout << solve(0, n - 1, 1, 1) + a[0] + a[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  vector<bool>dp((int)s.size()+1213,0);
  int n=s.size();
  dp[0]=1;
  for(int i=0;i<n;++i){
    if(dp[i]==0)continue;
    if(i+5<=n && s.substr(i,5)=="dream")dp[i+5]=1;
    if(i+7<=n && s.substr(i,7)=="dreamer")dp[i+7]=1;
    if(i+5<=n && s.substr(i,5)=="erase")dp[i+5]=1;
    if(i+6<=n && s.substr(i,6)=="eraser")dp[i+6]=1;
  }
  if(dp[n])cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3784
N = int(input())
A = list(map(int, input().split()))
A.sort()

for i in range(N//2):
    if A[i*2] + A[i*2+1] < 0:
        A[i*2] = -1 * A[i*2]
        A[i*2+1] = -1 * A[i*2+1]
    else:
        break

print(sum(A))

Measured memory_bytes: 14284
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		if(a < b) {
			System.out.println("a < b");
		} else if(a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26172
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

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

typedef long long int64;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double dl;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define uint(n) ((unsigned int)(n))
#define int64(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define dl(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const int64 LINF=4557430888798830399;
const dl eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=100010;

int64 n,tot,ans;
int m,x,cnt;
vector<int> v;
map<int,int> mp;

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

	while(mp.count(x)==0)
	{
		v.push_back(x);
		mp[x]=cnt++;
		tot+=x;

		x=1ll*x*x%m;
	}

	if(n<=cnt)
	{
		rep(i,n) ans+=v[i];
	}
	else
	{
		int len=cnt-mp[x];
	
		int64 sum=0;
		for(int i=mp[x];i<cnt;i++) sum+=v[i];

		ans=tot;n-=cnt;
		ans+=n/len*sum;
		n%=len;

		for(int i=0;i<n;i++) ans+=v[mp[x]+i];
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 5920
#include <iostream>
#include <vector>
#include <cmath>

using Graph = std::vector<std::vector<int>>;

void make_dist_map(
    Graph const & g,
    int const from,
    std::vector<int> & dist)
{
    // distは-1クリアされている前提
    std::vector<int> queue;
    queue.push_back(from);
    dist[from] = 0;
    while (!queue.empty()) {
        int node = queue.back(); queue.pop_back();
        int nDist = dist[node];
        int nEdge = g[node].size();
        for (int i=0; i<nEdge; ++i) {
            int dest = g[node][i];
            if (dist[dest] < 0) {
                queue.push_back(dest);
                dist[dest] = nDist + 1;
            }
        }
    }
}

int main()
{
    int N, u, v;
    std::cin >> N >> u >> v;
    u -= 1; // takahashi (free)
    v -= 1; // aoki (chase)

    Graph g(N);

    for (int i=0; i<N; ++i) {
        int A, B;
        std::cin >> A >> B;
        g[A-1].push_back(B-1);
        g[B-1].push_back(A-1);
    }
    std::vector<int> umap(N, -1);
    make_dist_map(g, u, umap);
    std::vector<int> vmap(N, -1);
    make_dist_map(g, v, vmap);

    int max = 0;
    for (int i=0; i<N; ++i) {
        if (umap[i] <= vmap[i]) {
            max = std::max(max, vmap[i]);
        }
    }
    std::cout << max - 1 << std::endl;
    return 0;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
int main(){
    string ans,S;
    ans="";
    getline(cin,S);
    int l;
    l=S.size();
    for(int i=0;i<l;i++){
        if(islower(S[i])) ans+=toupper(S[i]);
        else if(isupper(S[i])) ans+=tolower(S[i]);
        else ans+=S[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3216
#include<stdio.h>
int b[1001][1001];
int main(void)
{
	int n,m,a[1001],i,j,s[1001];
	scanf("%d",&n);
	scanf("%d",&m);
	for(i=1;i<=m;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&b[i][j]);
		}
	}
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			if(a[i]==b[i][j]){
				s[j]++;
			}
			else{
				s[a[i]]++;
			}
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",s[i]);
	}
	return 0;
}

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

using namespace std;

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

  int N;
  cin >> N;
  string S;
  cin >> S;

  int result = 0;
  vector<int> matched(N);
  for (int base = 0; base < N; ++base) {
    matched.clear();
    auto* str = &S[base];
    const auto len = N - base;
    int lookup = 0;
    for (int offset = 1; offset < len;) {
      for (; offset + lookup < len && str[offset + lookup] == str[lookup];
           ++lookup) {
      }
      if (lookup <= offset) {
        result = max(result, lookup);
      }
      matched[offset] = lookup;
      if (lookup <= 1) {
        lookup = 0;
        ++offset;
        continue;
      }
      int offset0 = 1;
      for (; offset0 < lookup; ++offset0) {
        auto lookup0 = matched[offset0];
        auto offset1 = offset + offset0;
        if (len <= offset1 || offset + lookup <= offset1 + lookup0) {
          break;
        }
        if (offset0 + lookup0 <= offset1) {
          result = max(result, lookup0);
        }
        matched[offset1] = lookup0;
      }
      offset += offset0;
      lookup -= offset0;
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 256
/*
* Author : Omkar Deshmukh
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(v) v.begin(), v.end()
#define intvect vector<int>
#define llvect vector<ll>
#define all(v) v.begin(), v.end()
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
vector<pair<string, int>> qry;
intvect freq;
int k;

int32_t main()
{
    string a, b;
    cin >> a >> b;
    int n = a.size();
    int m = b.size();
    bool flag = 1;
    if (n + 1 != m)
        flag = 0;
    else
        for (int i = 0; i < n; i++)
        {
            if (a[i] != b[i])
            {
                flag = 0;
            }
        }
    if (flag)
        cout << "Yes";
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3500
#include <iostream>

using namespace std;
const int Nmax = 100000 + 5;
int n, cnt[6];
string s[Nmax];
int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> s[i];
        if(s[i][0] == 'M')cnt[1] ++;
        else if(s[i][0] == 'A')cnt[2] ++;
        else if(s[i][0] == 'R')cnt[3] ++;
        else if(s[i][0] == 'C')cnt[4] ++;
        else if(s[i][0] == 'H')cnt[5] ++;
    }
    long long ans = 0;
    for(int i = 1; i <= 5; ++i)
        for(int j = i + 1; j <= 5; ++j)
            for(int k = j + 1; k <= 5; ++k)
                ans = ans + 1LL * cnt[i] * cnt[j] * cnt[k];
    cout << ans;
    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int beki(long long a,long long b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


int gyakugen(int a){
	return beki(a,modulo-2);
}

int main(){
	
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	
	vector<vector<int>> dp(3001,vector<int>(3001,0));
	dp[A][B] = 1;
	
	
	for(int i=0;i<=3000;i++){
		for(int j=0;j<=3000;j++){
			if(i!=0&&j!=0){
				dp[i][j] = mod(dp[i][j] - mod(dp[i-1][j-1] * mod((i-1)*(j-1))));
			}
			if(dp[i][j]==0)continue;
			
			if(i!=3000){
				int t = mod(dp[i][j]*j);
				dp[i+1][j] = mod(dp[i+1][j] + t);
			}
			
			if(j!=3000){
				int t = mod(dp[i][j]*i);
				dp[i][j+1] = mod(dp[i][j+1] + t);
			}
		}
	}
	/*
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			cout<<i<<','<<j<<','<<dp[i][j]<<"   ";
		}
		cout<<endl;
	}*/
	
	cout<<mod(dp[C][D])<<endl;
	
	return 0;
}

Measured memory_bytes: 38636
#include <iostream>
#include <cmath>
#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 <numeric>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
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 gcd(ll a, ll b);
ll lcm(ll x, ll y);

//vector<ll> a;

int main()
{
	ll a,b;
	ll tmp;

	cin >> a >> b;
	if (a >= 13) {
		cout << b << endl;
	}
	else if (12 >= a && a >= 6) {
		cout << b/2 << endl;
	}
	else {
		cout << "0" << endl;
	}
	

	return 0;
}


Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
n = int(input())
c, s, f = [0]*(n-1), [0]*(n-1), [0]*(n-1)
for i in range(n-1):
    c[i], s[i], f[i] = map(int, input().split())

ans = [0]*n
for i in range(n-1):
    time = s[i]
    for j in range(i, n-1):
        if time < s[j]:
            time = s[j]
        if time % f[j] != 0:
            time += f[j] - time % f[j]
        time += c[j]
    ans[i] = time

for i in ans:
    print(i)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
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; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
typedef pair<int,int> pii;

int main() {
  int n,m,p;
  while(cin>>n>>m>>p) {
    vector<int> v({0,n});
    REP(i,m) {
      int d;
      cin >> d;
      v.push_back((d-p+n)%n);
    }
    sort(v.begin(), v.end());
    int ans = 1<<28;
    for (int i=0; i+1<(int)v.size(); ++i) {
      chmin(ans,v[i]+(n-v[i+1])*2);
      chmin(ans,v[i]*2+(n-v[i+1]));
    }
    cout << ans*100 << endl;
  }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int f(int x) {
    int res = 0;
    while (x % 2 == 0) {
        x /= 2;
        res++;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
        if (a[i] % 2) {
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }
    int cnt = f(a[0]);
    rep (i, n) {
        if (cnt != f(a[i])) {
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= cnt;
    }
    m >>= cnt;
    ll l = 1;
    rep (i, n) {
        l = lcm(l, a[i]);
        if (l > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ((m / l) + 1) / 2 << endl;

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": " << a << ENDL;
#define all(a) begin(a),end(a)
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

lli MOD = 998244353;

int main()
{   _
    lli n, k, l, r; cin >> n >> k;
    vector<lli> v(n + 2, 0);
    fore(i, 0, k) {
        cin >> l >> r;
        ++v[l];
        --v[r + 1];
    }
    vector<ii> p;
    l = -1;
    fore(i, 1, n + 2) {
        v[i] += v[i - 1];
        if(v[i] > 0 and l == -1) l = i;
        if(v[i] == 0 and l != -1) {
            p.pb({l, i - 1});
            l = -1;
        }
    }
    vector<lli> dp(n + 2, 0);
    vector<lli> acum(n + 2, 0);
    dp[1] = 1;
    acum[1] = 1;
    fore(i, 2, n + 1) {
        //deb(i);
        for(auto it : p) {
            l = i - it.s;
            r = i - it.f;
            if(r <= 0) continue;
            l = max(l - 1LL, 0LL);
      //      cout << l << ' ' << r << ENDL;
            dp[i] = (MOD + dp[i] + acum[r] - acum[l]) % MOD;
        }
        acum[i] = (acum[i] + acum[i - 1] + dp[i]) % MOD;
    }
    cout << dp[n] << ENDL;
    return 0;
}


Measured memory_bytes: 7952
#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, k, x, y;
    cin >> n >> k >> x >> y;

    ll ans = min(k, n) * x + max(n - k, 0) * y;

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


Measured memory_bytes: 3596
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n,m;cin>>n>>m;
  vi a(m), b(m);
  // vvi c(m, vi());
  vi c(m);
  rep(i, m){
    cin>>a[i]>>b[i];
    rep(j, b[i]){
      int t;cin>>t;
      t--;
      c[i] |= 1<<t;
    }
  }
  dump(c);

  int k = 1<<n;
  dump(k);
  vvi dp(m, vi(k, INF));
  dp[0][0] = 0;

  rep(i, m-1){
    rep(mask, k){
      // kau
      dump(i, mask, c[i], (mask|c[i]));
      chmin(dp[i+1][(mask|c[i])], dp[i][mask]+a[i]);
      // kawanai
      chmin(dp[i+1][mask], dp[i][mask]);
      dump(i, "fin");
    }
  }
  if (dp[m-1][k-1]==INF){
    cout << -1 << endl;
  }
  else{
    cout << dp[m-1][k-1] << endl;
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  cout << vec.at(N - 1) - vec.at(0) << endl; 
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;


int main(){
    int n;
    cin >> n;
    int t, a;
    cin >> t >> a;
    int ans = -1;
    double tmin = mod;
    rep(i, n) {
        int h;
        cin >> h;
        double te = t-h*0.006;
        if (abs(a-te)<tmin) {
            ans = i+1;
            tmin = abs(a-te);
        }
    }
    
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
////.......Symoon Zadid.......////
//..State University Of Bangladesh..//
//**********************************//
#include<bits/stdc++.h>
using namespace std;
vector<int>vec;
int main()
{


    int a,b,c;
    cin>>a>>b>>c;
    int d=a-b;

    if(d<c)
        cout<<c-d<<"\n";
    else
        cout<<"0"<<"\n";


return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val datS = readLine
    val datT = readLine

    var ans = 0;
    (0 until datS.length) foreach { i =>
      if (datS(i) != datT(i)) ans += 1
    }

    println(ans)
  }
}


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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define P				pair<string, int>
#define fi				first
#define se				second

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

struct R {
	string name;
	int value;
	int id;
};

bool compare( const R& a, const R& b ) {
	return a.name < b.name || ( a.name == b.name && a.value > b.value );
}

signed main() {
	int n; cin >> n;
	vector<R> r( n );
	REP( i, n ) {
		cin >> r[i].name >> r[i].value;
		r[i].id = i + 1;
	}

	sort( ALL( r ), compare );
	REP( i, n ) {
		cout << r[i].id << endl;
	}
}

Measured memory_bytes: 256
H,W = map(int,input().split())
maze = []
for i in range(H):
    maze.append(list(input()))

queue = []
visited = []
visited = [[0 for _ in range(W)] for _ in range(H)]
ans = 0

for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            queue.append([i,j])
            visited[i][j] = 1

            while len(queue) > 0:
                now_y, now_x = map(int,queue.pop(0))
                for next_x, next_y in [(1,0),(0,1),(-1,0),(0,-1)]:
                    y = now_y + next_y
                    x = now_x + next_x
                    if 0 <= y < H and 0 <= x < W:
                        if maze[y][x] != '#' and visited[y][x] == 0:
                            visited[y][x] = visited[now_y][now_x] + 1
                            queue.append([y,x])

        for l in range(H):
            for m in range(W):
                ans = max(ans,visited[l][m])

        queue = []
        visited = [[0 for _ in range(W)] for _ in range(H)]



print(ans-1)


Measured memory_bytes: 9216
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val stList = mutableListOf<Pair<String, Long>>()
    (1..n).forEach {
        val (s, t) = readLine()!!.split(' ')
        stList.add(Pair(s, t.toLong()))
    }
    val x = readLine()!!
    val total = stList.map { it.second }.sum()
    var heard = 0L
    var i = 0
    while (true) {
        heard += stList[i].second
        if (x == stList[i].first) break
        i++
    }
    println(total-heard)
}

Measured memory_bytes: 38180
from itertools import combinations

n = int(input())
lst = []
for i in range(n):
  lst.append([0] * n)
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
    lst[i][x-1] = y * 2 - 1

for ans in range(n, 0, -1):
  for x in combinations(range(n), ans):
    for y in x:
      for i, z in enumerate(lst[y]):
        if (z == 1 and i not in x) or (z == -1 and i in x):
          break
      else:
        continue
      break
    else:
      break
  else:
    continue
  print(ans)
  break
else:
  print(0)

Measured memory_bytes: 3064
fn combination(n: usize) -> usize {
    if n == 0 {
        return 0;
    }
    n * (n - 1) / 2
}

fn main() {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    let mut iter = buffer.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();

    let even = combination(n);
    let odd = combination(m);
    println!("{}", even + odd);
}

Measured memory_bytes: 4352
from collections import defaultdict
n,m=map(int,input().split())
mod=10**9+7
kaidan=[1]*(2*10**5+1)
gyaku=[1]*(2*10**5+1)

for i in range(1, 2*10**5):
    kaidan[i]=i*kaidan[i-1] % mod
    gyaku[i]=pow(kaidan[i],mod-2,mod)
def comb(a,b):
    if a>0 and b>0 and a-b>0:
        return (kaidan[a] * gyaku[b]*gyaku[a-b])%mod
    elif a==0 or b==0 or a-b==0:
        return 1
    else:
        return 0
def fctr1(n): 
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    return f
# soin=defaultdict(int)
# while m>=2:
#     for i in range(2,int(n**.5)+5):
#         while m%i==0 and m!=0:
#             m//=i
#             soin[i]+=1
#             if m==1:
#                 break
     
L=list(fctr1(m))
ans=1
for a,l in L:
    ans*=comb(l+n-1,l)
    ans%=mod
print(ans)

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

int main()
{

	int h,w;
	cin >> h >> w;

	string space;
	for( int i = 0; i < w+2; ++i ) space += '#';
	
	cout << space  << endl;

	for( int y = 0; y < h; ++y )
	{
		string text;
		cin >> text;
		cout << "#" << text << "#" << endl;
	}

	cout << space << endl;

	return 0;	
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

ans = 5000 * 2 * 10 ** 5
for i in range(10 ** 5 + 1):
    s = i * 2 * C + max(0, X - i) * A + max(0, Y - i) * B
    ans = min(ans, s)

print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n;
	string s[12525];
	cin>>n;
	int a=0, b=0, ans=0, ba=0;
	REP(i, n){
		cin>>s[i];
		if(s[i][0]=='B'){
			++b;
		}
		int sz=s[i].size();
		if(s[i][sz-1]=='A'){
			++a;
		}
		if(s[i][0]=='B' && s[i][sz-1]=='A'){
			++ba;
		}
		bool flag=false;
		REP(j, sz){
			if(s[i][j]=='A'){
				flag=true;
			}
			if(flag && s[i][j]=='B'){
				++ans;
				flag=false;
			}
			if(s[i][j]!='A'){
				flag=false;
			}
		}
	}
	if(a==ba && b==ba){
		ans+=max(0, min(a, b)-1);
	}
	else{
		ans+=min(a, b);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <set>
#include <cmath>
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int ketasu(ll x) {
	return std::to_string(x).size();
}

int main(){
	ll N;
	std::cin >> N;
	int ans = ketasu(N);
	ll a,b;
	for ( ll a = 1LL ; a*a <= N ; ++a ) {
		if(N%a == 0){
			b = N/a;
			int keta = std::max(ketasu(a),ketasu(b));
			ans = ans < keta ? ans : keta;
		}
	}
	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>

const int N = 2e5 + 52;
struct edge {
	int to, next, w;
} e[N << 1];
int n, head[N], cnt;
void ad(int x, int y, int z) { e[++cnt] = {y, x[head], z}, x[head] = cnt; }

std::queue<int> q;
int dis[N];
int main() {
	memset(head, -1, sizeof head);
	memset(dis, 0x3f, sizeof dis), dis[1] = 1;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
		if (i % 10 != 9 || i + 1 == n) ad(i, (i + 1) % n, 1);
	for (int i = 1; i < n; i++) ad(i, i * 10 % n, 0);
	for (q.push(1); !q.empty(); q.pop())
		for (int x = q.front(), i = x[head], nx; ~i; i = e[i].next)
			if ((nx = e[i].to)[dis] > x[dis] + e[i].w) nx[dis] = x[dis] + e[i].w, q.push(nx);
	printf("%d", 0 [dis]);
}

Measured memory_bytes: 4480
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  string t; readV(t);

  auto ns = s.length.to!int, nt = t.length.to!int;
  auto dp = new int[][](ns+1, nt+1);
  foreach (i; 1..ns+1)
    foreach (j; 1..nt+1) {
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      if (s[i-1] == t[j-1])
        dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
    }

  char[] r;
  auto i = ns, j = nt;
  while (i > 0 && j > 0) {
    if (dp[i-1][j] == dp[i][j]) --i;
    else if (dp[i][j-1] == dp[i][j]) --j;
    else {
      r ~= s[i-1];
      --i; --j;
    }
  }

  r.reverse();
  writeln(r);
}


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

int main() {
  int n, c=0;
  cin >> n;
  
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      if(v.at(i) == v.at(j)) continue;
      for(int k = j+1; k < n; k++){
        if(v.at(i) == v.at(k) || v.at(j) == v.at(k)) continue;
        if(v.at(i)+v.at(j) > v.at(k))
          c++;
      }
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 3596
a,b = gets.chomp.split(" ")
a = a.to_i
# 文字列 -> 整数 (小数で扱うと誤差が生まれるため)
b = b.gsub(".", "").to_i

# bは小数第二位まで与えられていることが確定しているため100で割る
puts (a * b / 100)


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

using namespace std;


int main() {
    int n;
    cin>>n;
    int c[n],s[n],f[n],t[n]={0};
    for (int i = 0; i < n-1; ++i) {
        cin>>c[i]>>s[i]>>f[i];
    }
    for (int j = 0; j < n-1; ++j) {
        t[j]=s[j]+c[j];
        for (int i = j+1; i < n-1; ++i) {
            if(t[j]<=s[i])t[j]=s[i]+c[i];
            else t[j]=(int)ceil((double)t[j]/f[i])*f[i]+c[i];
        }
    }
    for (int k = 0; k < n; ++k) {
        cout<<t[k]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/






int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  int n; cin >> n;
  string s; cin >> s;
  int ws = 0;
  for (char c : s) {
    if (c == 'W') ws++;
  }
  int ret = min(n-ws, ws);
  int a = 0, b = n-ws;
  for (int i = 0; i < n; i++) {
    ret = min(min(a, b) + abs(a-b), ret);
    if (s[i] == 'R') {
      b--;
    } else {
      a++;
    }
  }
  cout << ret << '\n';





/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 3420
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    REP (i, N) {
        cin >> A[i] >> B[i];
    }
    SORT(A);
    SORT(B);
    int ans = 0;
    if (N % 2 == 0) {
        ans = B[N/2-1]+B[N/2] - (A[N/2-1]+A[N/2]) + 1;
    }
    else {
        ans = B[N/2] - A[N/2] + 1;
    }
    pa;
    

    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_e && sh test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_e && sh etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_e && sh submit_cpp.sh
*/


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

int main(){
 int X, N;
  cin >> X >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  int result = 10000000;
  for(int i = 0; i < 100000; i++){
   if(find(vec.begin(), vec.end(), i) == vec.end()){
     if(abs(X - i) < abs(X - result)){
       result = i;
     }else{
       break;
     }
   }
  }
  cout << result << endl;
}


Measured memory_bytes: 3624
#include<stdio.h>
#define NIL -1

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j, e, sum;

  int u,v;
  int min = INFTY;
  int M[MAX][MAX],vis[MAX],cost[MAX],p[MAX];
  
 
  scanf("%d", &n);
  
  for( i = 0; i< n; i++ ){
    for( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }
  
  for(i=0;i<n;i++){
    cost[i]=INFTY;
    vis[i]=0; 
    p[i]=NIL;
  }
  cost[0]=0;
  
  
  while(1){
    u=NIL;
    min=INFTY;
 
    for(i=0;i<n;i++){
      if (cost[i]<min && !vis[i]){
	u=i;
	min=cost[i];
      }
    }
    
    if(u==NIL) break;
    vis[u]=1;
    
    for(v=0;v<n;v++){
      if(M[u][v]<cost[v] && !vis[v]){
	cost[v]=M[u][v];
	p[v]=u;
      }
    }
  }
  
  sum=0;
  
  for(i=0;i<n;i++){
    if(p[i]!=-1) sum+=M[i][p[i]];
  }
  
  printf("%d\n", sum);
  
  return 0;
}

Measured memory_bytes: 804
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pi              pair<int,int>
#define vi              vector<int>
#define mi              map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1N
#define loop(i,a,b)     for(int i=a;i<b;i++)

void FIO(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

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

    if ( k < a ){
        cout << k ;
        return 0;
    }

    int sum = 0;
    sum += a;
    k-=a;
    if ( b > k ){
        cout << sum;
        return 0;
    }
    
    k-=b;
    if ( c > k){
        sum -=k;
    }
    else{
        sum -= c;
    }
    cout << sum;











}






































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

int dp[1005][1005];

int solve(int n, int m){

    for(int i=1;i<=m;i++){
        if(dp[1][i]==-1){
            break;
        }
        dp[1][i] = 1;
    }

    for(int i=1;i<=n;i++){
        if(dp[i][1]==-1){
            break;
        }
        dp[i][1] = 1;
    }

    for(int i=2;i<=n;i++){
        for(int j=2;j<=m;j++){
            if(dp[i][j]==-1) continue;
            if(dp[i-1][j]!=-1)
                dp[i][j] = dp[i-1][j]%mod;
            if(dp[i][j-1]!=-1)
                dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
        }
    }

    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=m;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    return dp[n][m]%mod;

}

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

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            char x;
            cin>>x;
            if(x=='.') dp[i][j] = 0;
            if(x=='#') dp[i][j] = -1;
        }   
    }

    cout<<solve(n,m);

    return 0;
}


Measured memory_bytes: 7436
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool ispal(string a)
{
    long long int n=a.length();
    if(n==1)
        return true;
    else{
    int i=0,j;
    j=n-1;
    while(1)
    {
        if(a[i]!=a[j])
        {
            cout<<i<<" "<<j;
           return false;
        }
        i++,j--;
        if(i==j)
         {
        //     cout<<i<<" ";
             break;
        }
    }
    return true;
}}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 string a;
 cin>>a;
 ll sum=0;
 for(int i=0;i<a.length();i++)
 {
     sum+=(a[i]-'0');
 }
  if(sum%9==0)
  {
      cout<<"Yes";
  }
  else
    cout<<"No";
  }


Measured memory_bytes: 3768
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[2];
  for(int j=0;j<2;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool f=false;
  
  
  for(int i=0;i<4;i++){
    d[1].roll('R');
    for(int j=0;j<4;j++){
      d[1].roll('N');
      if(same(d[0],d[1])) f=true;
    }
  }
  d[1].roll('E');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }

  d[1].roll('W');
  d[1].roll('W');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
  
  cout << (f?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
    
    char a[100010]={0};
    char b[100010]={0};
    gets(a);
    int l=0;
    int i=0,j=strlen(a)-1;
    if(strlen(a)%2!=0){
    	cout<<"No";
    	return 0;
	}
    while(i<j){
		if(a[i]=='b' && a[j]=='d' || a[i]=='d' && a[j]=='b' || a[i]=='p' && a[j]=='q' || a[i]=='q' && a[j]=='p') {
			i++;j--;
		}
        else
        {
            printf("No");
            return 0;
        }
	}
	cout<<"Yes";
    return 0;
    
}

Measured memory_bytes: 896
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""

s = input()
cnt = 0
new = s[0]
for i in range(1,len(s)):
    if (s[i]==new[i-1]) : 
        cnt += 1
        new +=  str((int(s[i])+1)%2)
    else: new += s[i]

print(cnt)

Measured memory_bytes: 9212
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(br.readLine());
        String[] st = br.readLine().split(" ");
        int min = Integer.MAX_VALUE, max = 0;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            int now = Integer.parseInt(st[i]);
            if (min > now) {
                min = now;
            }
            if (max == 0 || max < now) {
                max = now;
            }
            sum += now;
        }
        bw.append(min + " " + max + " " + sum + "\n");
        bw.flush();
    }


}


Measured memory_bytes: 28280
a, b = map(int, input().split())
if a > 0:
    ans = "Positive"
elif a <= 0 and b >= 0:
    ans = "Zero"
else:
    if b == a:
        ans = "Positive"
    elif (b - a) % 2 == 0:
        ans = "Negative"
    else:
        ans = "Positive"

print(ans)


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

int main()
{
  long long a,b,k,s=0;
  cin>>a>>b>>k;
  if(k<=a){
      cout<<a-k<<" "<<b;
  }
  else{
      if(k<=a+b){
          cout<<"0 "<<a+b-k;
      }
      else{
          cout<<"0 0";
      }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

vector<vector<int>> g(100010);
vector<vector<int>> memo(100010, vector<int>(20, 0));

void func(int v, int d, int c){
    if(memo[v][d] != 0) return;
    
    memo[v][d] = c;

    if(d == 0) return;

    func(v, d-1, c);

    for(auto nv:g[v]){
        func(nv, d-1, c);
    }
}

int main(){
    int n, m; cin>>n>>m;
    for(int i=0; i<m; i++){
        int a, b; cin>>a>>b;
        a--, b--;
        g[a].eb(b);
        g[b].eb(a);
    }

    int q; cin>>q;
    vector<int> v(q), d(q), c(q);
    for(int i=0; i<q; i++){
        cin>>v[i]>>d[i]>>c[i];
        v[i]--;
    }

    for(int i=q-1; i>=0; i--){
        func(v[i], d[i], c[i]);
    }

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

Measured memory_bytes: 19448