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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

ll calc_pow(ll n){
  if(n == 0) return 0;
  ll res = 0;
  while(n % 2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

int main(){
  ll N;
  cin >> N;
  string a;
  cin >> a;

  ll ans = 0;
  ll n_pow = 0;
  rep(i, N){
    if(n_pow == 0) ans += a[i] - '0';
    n_pow += calc_pow(N-1-i) - calc_pow(i+1);
  }
  ans = ans % 2;
  if(ans == 0){
    ll b[N-1];
    bool evenflg = true;
    rep(i, N-1){
      b[i] = abs(a[i+1] - a[i]) / 2;
      if((a[i+1] - a[i]) % 2){
        evenflg = false;
        break;
      }
    }
    if(evenflg){
      ans = 0;
      n_pow = 0;
      rep(i, N-1){
        if(n_pow == 0) ans += b[i];
        n_pow += calc_pow(N-2-i) - calc_pow(i+1);
      }
      ans = ans % 2 * 2;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	short date;
	cin>>date;
	date %= 7;
	if(date==0)
		cout<<"thu"<<endl; 
	switch(date){
		case 4:
			cout<<"mon"<<endl;
			break;
		case 5:
			cout<<"tue"<<endl;
			break;
		case 6:
			cout<<"wed"<<endl;
			break;
		case 7:
			cout<<"thu"<<endl;
			break;
		case 1:
			cout<<"fri"<<endl;
			break;
		case 2:
			cout<<"sat"<<endl;
			break;
		case 3:
			cout<<"sun"<<endl;
			break;
	}
	return 0;	
}


Measured memory_bytes: 3116
#include <iostream>
using namespace std;
int main(){
	int x,y;	cin>>x>>y;
	int ret=0;
	if(abs(x)>=abs(y)){
		if(x>0)	ret++;
		ret+=abs(x)-abs(y);
		if(y>0)	ret++;
	}
	else{
		if(x<0)	ret++;
		ret+=abs(y)-abs(x);
		if(y<0)	ret++;
	}
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, C, N;
	cin >> A >> B >> C >> N;
	int res = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			int nokori = N - i * A - j * B;
			if (nokori >= 0 && nokori % C == 0) {
				//cerr << i << " " << j << endl;
				res++;
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
s = input()
n = len(s)
s1 = s[:(n-1)//2]
s2 = s[((n+3)//2)-1:]

def kaibun(S):
  for i,j in zip(S,S[::-1]):
    if i!=j:
      return False
  return True

if kaibun(s) and kaibun(s1) and kaibun(s2):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9052
n,C = map(int,input().split())
d = [[0]*C for i in range(10**5)]

for i in range(n):
    s,t,c = map(int,input().split())
    for j in range(s-1,t):
        d[j][c-1] = 1

#print(d)

a = 1
for i in range(10**5):
    s = sum(d[i])
    if s > a:
        a = s

print(a)

Measured memory_bytes: 37108
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p)*(b))%m;
		b=((b)*(b))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
ll x[1000002];
ll y[1000002];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n,d,ans=0;
	cin>>n>>d;
	for (int i = 0; i < n; ++i)
	{
		cin>>x[i]>>y[i];
		ans += (x[i]*x[i]+y[i]*y[i] <=d*d);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 30176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int a[26];
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
		a[s[i]-'a']++;
	int ok=1;
	//for(int i=0;i<26;i++) printf("%d %d\n",i,a[i]);
	for(int i=0;i<26;i++)
		if(a[i]&1) {
			ok=0;
			break;
		}
		puts(ok?"Yes":"No");
	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, v) for (auto &&i : v)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
vector<vector<int>> graph;
vector<vector<int>> graphI;
vector<bool> visited;
vector<vector<pair<int, int>>> visitedList;
vector<pair<int, int>> ans;
vector<int> d;
vector<int> old;
int N, M;

//トポロジカル順序
/*
トポロジカル順序に関する問題であることは漠然とわかったが
その後が続かなかった。
特にグラフの辺を削除する部分にコストがかかると思ってしまった。
実際には、グラフを削除する必要はなかった。
stackを使うのが本質的なポイントかもしれない。
トポロジカル順序を求めるアルゴリズムは
 */
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    graph.resize(N + 1, vector<int>());
    graphI.resize(N + 1, vector<int>());
    visited.resize(N + 1);
    //頂点とその親を保存する.
    visitedList.resize(N + 1, vector<pair<int, int>>());
    d.assign(N + 1, 0);
    old.assign(N + 1, 0);
    REP(i, N - 1 + M)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graphI[b].push_back(a);
        //入次数
        d[b]++;
    }

    stack<pair<int, int>> st;
    REPS(i, N)
    {
        if (d[i] == 0)
            st.push(make_pair(i, -1));
    }
    vector<pair<int, int>> ans;
    while (st.size())
    {
        //cout << st.size() << endl;
        int i = st.top().first;
        int j = st.top().second;
        //cout << i << " " << j << endl;
        st.pop();
        //me parent
        ans.emplace_back(i, j);
        old[i] = ans.size();
        for (auto &&v : graph[i])
        {
            d[v]--;
            if (d[v] == 0)
                st.push(make_pair(v, i));
        }
    }

    sort(ALL(ans));
    FORA(i, ans)
    {
        //cout << ((i.second == -1) ? 0 : i.second) << "\n";
        if (i.second == -1)
        {
            cout << 0 << "\n";
        }
        else
        {
            int maxV = -1, maxIndex = -1;
            FORA(v, graphI[i.first])
            {
                if (old[v] > maxV)
                {
                    maxV = old[v];
                    maxIndex = v;
                }
            }
            cout << maxIndex << "\n";
        }
    }
    //最大という制約よりsecondを直接出力しても問題ない。次数を0にするのはもっとも近い頂点になる。
    /*  FORA(i, ans)
    {
        cout << i.first << " " << i.second << "\n";
    }*/
}

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

int main(){
    int N,k=1;
    cin>>N;
    int a[N];
    for (int i=0;i<N;i++){
        cin>>a[i];
        if (a[i]==k) k+=1;
    }
    if (k>=2) cout<<N-k+1<<endl;
    else cout<<"-1"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <limits.h>
//#include <conio.h>
using namespace std;

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

long N, K;
long H[100001];

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

	cin >> N >> K;
	Rep(i,N)
		cin >> H[i];
	sort(H,H+N);
	long v,minV = LONG_MAX;
	Rep(i,N-K+1){
		v = H[i+K-1]-H[i];
		if( v < minV )
			minV = v;
	}
	cout << minV;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);

                String S = scan.next();
                String T = scan.next();

                int count = 0;

                for (int i = 0; i < S.length(); i++) {
                	if (!S.substring(i, i+1).equals(T.substring(i, i+1))) {
                		count++;
                	}
                }

                System.out.println(count);

                scan.close();

        }

}

Measured memory_bytes: 55788
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 09:36:44 2017

@author: kotania
"""

N = int(input())
lrList = [""]*N
for n in range(0,N):
    lrList[n] = input()

sum = 0
for lr in lrList:
    sum += (int(lr.split()[1]) - int(lr.split()[0]) + 1)
    
print(sum)


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

int main() {

    int N, K, X, Y;

    cin >> N;
    cin >> K;
    cin >> X;
    cin >> Y;

    int sum = 0;

    if(N < K) {
        sum = N * X;
    } else {
        sum = K * X + (N - K) * Y;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>//ポリゴン
using namespace std;
int main(){
    int n;
    cin>>n;
    string p;
    set<tuple<int,int,int>> info;
    for(int i=0;i<n;i++){
        int a[3];
        cin>>a[0]>>a[1]>>a[2];
        sort(a,a+3);
        info.insert(make_tuple(a[0],a[1],a[2]));
    }
    cout<<n-info.size()<<"\n";
    return(0);
}


Measured memory_bytes: 3224
def main():
    N = int(input())

    c = [[0]*10 for _ in range(10)]
    for i in range(1,N+1):
        c[int(str(i)[0])][int(str(i)[-1])] += 1

    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += c[i][j]*c[j][i]

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x;
  cin >> x;
  int res;
  int cnt_max = -1;
  FOR(i,1,x+1){
    int cnt = 0;
    int cp = i;
    while(cp>1){
      cp /= 2;
      cnt++;
    }
    if(cnt_max<cnt){
      cnt_max = cnt;
      res = i;
    }
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

struct fenwick_tree {
    typedef int T;
    T n;
    vector<T> bit;
    fenwick_tree(T num) : bit(num+1, 0) { n = num; }
    void add(T i, T w) {
        for (T x = i; x <= n; x += x & -x) {
            bit[x] += w;
        }
    }
    T sum(T i) {
        T ret = 0;
        for (T x = i; x > 0; x -= x & -x) {
            ret += bit[x];
        }
        return ret;
    }
};

ll a[100005];

bool judge(ll mid, ll n) {
    // offset => 履かせる下駄
    int offset = n+1;
	ll num_inverse = 0;
	fenwick_tree bit(n*2+10);

	int sum_v = 0;
    bit.add(offset, 1);

	for (int i = 0; i < n; i++) {
		int s = (a[i] <= mid) ? 1 : -1;
		sum_v += s;
		num_inverse += (bit.sum(sum_v-1+offset));
		bit.add(sum_v+offset, 1);
	}
	return num_inverse > (n+1)*n/2/2; 
}

int main() {
    ll n; cin >> n;

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

    ll high = 1e18, low = 0; 

    while (low < high) {
        ll mid = ( high + low ) / 2;

        if ( judge(mid, n) ) {
            high = mid;
        } else {
            low = mid+1;
        }
    }

    cout << high << endl;

    return 0;
}

Measured memory_bytes: 1904
#include <cstdio>

using namespace std;

const int m = 1000000007;
long long C[1001][1001];
long long dp[1001];
long long inv[1001];
long long fact[1001];
long long invfact[1001];

void calc_inv(int n, int mod) {
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}

int main() {
    int n, a, b, c, d, i, j, k;
    
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
    
    for (i = 0; i <= 1000; i++) {
        C[i][0] = C[i][i] = 1;
        
        for (j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % m;
    }
    
    calc_inv(1000, m);
    
    dp[n] = 1;
    
    for (i = a; i <= b; i++) {
        for (j = 0; j <= n; j++) {
            int p = j;
            long long sum = 1;
            
            if (dp[j] == 0) continue;
            
            if (i * c > j) continue;
            
            for (k = 1; k < c; k++) {
                sum = sum * C[p][i] % m;
                p -= i;
            }
            
            for (k = c; k <= d; k++) {
                if (i * k > j) break;
                
                sum = sum * C[p][i] % m;
                p -= i;
                
                dp[j - i * k] += dp[j] * sum % m * invfact[k] % m;
                if (dp[j - i * k] >= m) dp[j - i * k] -= m;
            }
        }
    }
    
    printf("%lld\n", dp[0]);
    
    return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h> 
using namespace std;
#define ll long long int
#define deb1(x) cout<<#x<<" :: "<<x<<"\n";
#define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
ll mod=1000000007;

int main(){
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s;
	cin>>s;
	if(s[s.size()-1]=='s'){
		s+='e';
		s+='s';
		}
	else if(s[s.size()-1]!='s'){
	s+='s';
	}
	cout<<s<<endl;
	
	
	 }
	 			
	 
	
	 			


			
		
			
			
	
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
	
			
	
	

	
				
	











Measured memory_bytes: 3644
N = int(input())
n_list = []
for i in range(N):
  n_list.append(input())
M = int(input())
m_list = []
for i in range(M):
  m_list.append(input())
add_dic = {}
for n in n_list:
  add = add_dic.get(n, 0)
  add_dic[n] = add + 1
diff_dic = {}
for m in m_list:
  diff = diff_dic.get(m, 0)
  diff_dic[m] = diff + 1

max_ = 0
for key, add in add_dic.items():
  total = add - diff_dic.get(key, 0)
  if total > max_:
    max_ = total

print(max_)

Measured memory_bytes: 9232
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

const ll INF = 1e18;

ll N, X, x[200000], csum[200001];

ll mult(ll a, ll b) {
    if ((a * b) / b != a) return INF;
    return a * b;
}

int main() {
    cin >> N >> X;
    REP(i, N) cin >> x[i];
    REP(i, N) csum[i + 1] = csum[i] + x[i];
    reverse(csum, csum + N + 1);

    ll ans = INF;
    FOR(k, 1, N + 1) {
        ll tmp = (N + k) * X;
        for (ll i = 0; i * k < N; i++) {
            tmp += mult((2 * (max(i, 1LL) + 1) + 1), (csum[i * k] - csum[min(N, (i + 1) * k)]));
            tmp = min(tmp, INF);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n, q;
    string s;
    cin >> n >> s >> q;

    set<int> pos[26];

    rep (i, n)
    {
        pos[s[i] - 'a'].insert(i);
    }

    int t;
    rep (i, q)
    {
        cin >> t;
        if (t == 1)
        {
            int a;
            char b;
            cin >> a >> b;
            --a;
            if (s[a] != b)
            {
                pos[b - 'a'].insert(a);
                pos[s[a] - 'a'].erase(a);
                s[a] = b;
            }
        }
        else if (t == 2)
        {
            int l, r;
            cin >> l >> r;
            --l; --r;
            int ans = 0;
            rep (j, 26)
            {
                auto it = pos[j].lower_bound(l);
                if (it != pos[j].end() && *it >= l && *it <= r)
                {
                    ++ans;
                }
            }
            cout << ans << "\n";
        }
    }
    return 0;
}



Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
bool is_prime(lli x) {
  for(lli i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
int main() {
  lli A,B,C=0,D=0,E=0,F=0,G=0,H=0,N,M;
  string S;
  cin >> S;
  A=S.size();
  if(A==2)Out(S);
  else cout << S[2] << S[1] << S[0]<< endl;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using ProCon.Util;

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            AC139B();
        }

        static void AC139B()
        {
            //https://atcoder.jp/contests/abc139/tasks
            
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = input[0];   //a口の電源タップ
            var b = input[1];   //B口以上の未使用口
            
            var x = 0;  //必要な電源タップの個数
            if (b == 1)
            {
                x = 0;
            }
            else if (a > b)
            {
                x = 1;
            }
            else
            {
                x = (b - a) % (a - 1) == 0 ? (b - a) / (a - 1) + 1 : (b - a) / (a - 1) + 2;
            }
            Console.WriteLine(x);
        }

    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

void solver_main()
{
	int a, b;
	cin >> a >> b;
	cout << max(a + b,max(a-b,a*b)) << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>k;n=3;
    ll a[k+1];
    for(int i=1;i<=k;i++){
    	ll num=k/i;
    	a[i]=modpow(num,n);
    }
    for(int i=k;i>=1;i--){
    	for(int j=i*2;j<=k;j+=i){
    		(a[i]-=a[j])%=mod;
    	}
    }
    ll ans=0;
    for(int i=1;i<=k;i++){
    	(ans+=(a[i]*i)%mod)%=mod;
    }
    ans+=mod;
    ans%=mod;
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long a[n];
  int i;
  int cnt = 0;
  int cnt4 = 0;
  for(i=0;i<n;i++){
    cin >> a[i];
    if(a[i]%2 ==0)cnt++;
    if(a[i]%4==0){
      cnt++;
      cnt4++;
    }
  }
  if(cnt >= n||cnt4 >= n/2)cout << "Yes";
  else cout << "No";
  
}

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

#define DEBUG(...) fprintf(stderr,__VA_ARGS__)
#define clr(x) memset(x,0,sizeof x)
#define RG register

#define px first
#define py second

using std :: max;
using std :: min;
using std :: pair;
using std :: vector;
using std :: make_pair;

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

static const int INF = 1 << 30;
static const LL oo = 1LL << 60;
static const int maxm = 300 + 10;
static const int mod = 1e9 + 7;

template <class T> inline bool chkmax(T &x, T y) {
    return x < y ? x = y, true : false;
}

template <class T> inline bool chkmin(T &x, T y) {
    return x > y ? x = y, true : false;
}

template <class T> inline void read (T &in) {
    in = 0; char ch = getchar(); T f = 1;
    for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1;
    for (; ch >= '0' && ch <= '9'; ch = getchar()) in = in * 10 + ch - '0';
    in = in * f;
}

int n, m;

vector<pii> G[maxm];

int f[maxm][maxm][maxm], ban[maxm][maxm][maxm];

bool check(int r, int g, int b) {
	int k = max(max(r, g), b);
	ban[r][g][b] = 0;
	for(int i = 0; i < G[k].size(); i++) {
		pii v = G[k][i];
		if((r >= v.px) + (g >= v.px) + (b >= v.px) != v.py) return true;
	}
	return false;
}

int add(int x, int y) {
	return x + y >= mod ? x + y - mod : x + y;
}

void update(int r, int g, int b, int w) {
	if(ban[r][g][b]) return ;
	f[r][g][b] = add(f[r][g][b], w);
}

int main() {

	read(n); read(m);

	int l, r, x;
	for(int i = 1; i <= m; i++) {
		read(l); read(r); read(x);
		G[r].push_back(make_pair(l, x));
	}

	for(int r = 0; r <= n; r++) {
		for(int g = 0; g <= n; g++) {
			for(int b = 0; b <= n; b++) {
				if(check(r, g, b)) ban[r][g][b] = 1;
			}
		}
	}

	f[0][0][0] = 1;

	int ans = 0;
	
	for(int r = 0; r <= n; r++) {
		for(int g = 0; g <= n; g++) {
			for(int b = 0; b <= n; b++) {
				if(int w = f[r][g][b]) {
					int k = max(max(r, g), b);
					update(k + 1, g, b, w);
					update(r, k + 1, b, w);
					update(r, g, k + 1, w);
					if(k == n) ans = add(ans, w);
				}
			}
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 231680
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

// C - Attention
int main(){
    int N;
    string S;

    cin >> N >> S;

    vector<int> west;
    vector<int> east;

    if(S[0] == 'W'){
        west.push_back(1);
        east.push_back(0);
    }else{
        east.push_back(1);
        west.push_back(0);
    }

    for(int i=1;i<N;++i){        
        if(S[i] == 'W'){
            west.push_back(west.at(i-1) + 1);
            east.push_back(east.at(i-1));
        }else{
            east.push_back(east.at(i-1) + 1);
            west.push_back(west.at(i-1));
        }
    }

    int ans= 0 + (east.at(N-1) - east.at(0));

    for(int i=1;i<N;++i){
        int tmp_ans = 0;
        tmp_ans = west.at(i-1) + (east.at(N-1) - east.at(i));
        if(tmp_ans < ans){
            ans = tmp_ans;
        }
    }

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




Measured memory_bytes: 3960
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#define int long long
using namespace std;
int N;
vector<int> A;
vector<int> B;
signed main(){
  cin >> N;
  A.resize(N);
  B.resize(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i] < 0){
      B[i] = -A[i];
    }
    else{
      B[i] = A[i];
    }
  }
  int check = 0;
  for(int i=0;i<N;i++){
    if(A[i] < 0){
      check++;
    }
  }
  if(check % 2 == 0){
    cout << accumulate(B.begin(),B.end(),0LL);
  }
  else{
    int minElement = 10000000000LL;
    for(int i = 0;i < N;i++){
      minElement = min(B[i],minElement);
    }
    cout << accumulate(B.begin(),B.end(),0LL) - 2 * minElement << endl;
  }

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  cout<<n*m<<endl;
  return 0;
}



Measured memory_bytes: 3180
#include<stdio.h>

typedef long long int lli;

lli wt[107];
lli v[107];
lli K[107][100007],i,w;


lli max(lli a, lli b){
    return (a>b) ? a : b;
}

lli knapsack(lli n, lli W){
    // lli max_val;
    // if(n<0 || w <= 0)
    //     return 0;
    // if(w[n]>W)
    //     return knapsack(n-1, W);
    // else{
    //     return max(knapsack(n-1, W), knapsack(n-1, W-w[n])+v[n]);
    // }
    // lli max_val;
    // for(i=0;i<n;i++)
    //     k[i][0]=0;
    // for(i=0;i<=W;i++)
    //     k[0][i]=0;
    for (i = 0; i <= n; i++) 
    { 
        for (w = 0; w <= W; w++) 
        { 
            if (i==0 || w==0) 
                K[i][w] = 0; 
            else if (wt[i-1] <= w) 
                    K[i][w] = max(v[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
            else
                    K[i][w] = K[i-1][w]; 
        } 
    } 
    return K[n][W];
}

int main(){
    lli n, W, i;
    scanf("%lld %lld",&n,&W);
    for(i=0;i<n;i++){
        scanf("%lld %lld",&wt[i], &v[i]);
    }
    printf("%lld\n", knapsack(n, W));
    return 0;
}

Measured memory_bytes: 80000
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int A,B,C;
cin>>A>>B>>C;
vector<int> ABC{A,B,C};
sort(ABC.begin(),ABC.end());
int ans=10*ABC[2]+ABC[1]+ABC[0];
cout<<ans<<endl;
//system("pause");
return 0;
}


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

signed main() {
	int n;
	cin >> n;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}

	auto it = max_element(l.begin(), l.end());

	int lmax = l[it - l.begin()], lsum = accumulate(l.begin(), l.end(), 0);

	if (lmax < lsum - lmax) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>
using namespace std;
const int INF = 1e9;
// int dx[] = {1, 1, 0, -1, -1, 0};
// int dy[] = {0, 1, 1,  1,  0, -1};
int dx[] = {-1, 0, 1, -1, 0, 1};
int dy0[] = {0, -1, 0, 1, 1, 1};
int dy1[] = {-1, -1, -1, 0, 1, 0};
int main(){
  int m, n;
  while(cin >> m >> n, m){
    int s;
    cin >> s;
    vector<int> X(s), Y(s);
    queue<pair<size_t,size_t>> Q;
    vector<vector<int>> D(n,vector<int>(m,INF));
    for(int i = 0; i < s; ++i){
      size_t x, y;
      cin >> y >> x;
      --x,--y;
      Q.emplace(x,y);
      D[x][y] = 0;
    }
    while(Q.size()){
      size_t x, y;
      tie(x,y) = Q.front();
      Q.pop();
      int d = D[x][y];
      for(int i = 0; i < 6; ++i){
        int* dy = ((x % 2 == 0)? dy1:dy0);
        size_t x_ = x + dx[i], y_ = y + dy[i];
        if(x_ >= n or y_ >= m) continue;
        if(D[x_][y_] <= d+1) continue;
        D[x_][y_] = d+1;
        Q.emplace(x_,y_);
      }
    }
    // for(int i = 0; i < n; ++i)
    //   for(int j = 0; j < m; ++j)
    //     fprintf(stderr, "%d%c", D[i][j], j+1<m? ' ':'\n');
    int t;
    cin >> t;
    int ans = 0;
    for(int i = 0; i < t; ++i){
      size_t p, q;
      cin >> q >> p;
      --p,--q;
      // cerr << p << " " << q << "!!!" << endl;
      int ret = 0;
      queue<pair<size_t,size_t>> Q_;
      vector<vector<int>> D_ = D;
      if(D_[p][q] == 0) continue;
      D_[p][q] = 0;
      ++ret;
      Q_.emplace(p,q);
      while(Q_.size()){
        size_t x, y;
        tie(x,y) = Q_.front();
        Q_.pop();
        int d = D_[x][y];
        for(int j = 0; j < 6; ++j){
          int* dy = ((x % 2 == 0)? dy1:dy0);
          size_t x_ = x + dx[j], y_ = y + dy[j];
          if(x_ >= n or y_ >= m) continue;
          if(D_[x_][y_] <= d+1) continue;
          D_[x_][y_] = d+1;
          // cerr << x_ << " " << y_ << endl;
          ++ret;
          Q_.emplace(x_,y_);
        }
      }
      //cerr << p << " " << q << " " << ret << endl;
      ans = max(ans,ret);
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353;

signed main() {
  int n;
  cin>>n;
  int l[n];
  
  for(int i=0;i<n;i++)cin>>l[i];
  int j,k,ans=0;
  sort(l,l+n);
  //cerr<<l[0];
  for(int i=2;i<n;i++){
    j=0;k=i-1;
    while(j<k){
      while((l[k]+l[j]<=l[i])&&k!=j)j++;
      ans+=k-j;
      k--;
     
    }
  //  cerr<<ans<<' ';
  }
  cout<<ans;
  



  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int w, h, i, j;
  char c;
  scanf("%d %d %c", &w, &h, &c);
  for(i = 0; i < h; ++i) {
    for(j = 0; j < w; ++j) {
      if(!i || i == h - 1) {
        if(!j || j == w - 1) printf("+");
        else printf("-");
      } else if(!j || j == w - 1) {
        printf("|");
      } else if(j == w / 2 && i == h / 2) printf("%c", c);
      else printf(".");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2616
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <string>

int main() {
    std::string S;
    std::cin >> S;

    const int size = static_cast<int>(S.size());
    int ret = std::numeric_limits<int>::max();
    for (int i = 0; i < size - 2; ++i) {
        const int x = std::stoi(S.substr(i, 3));
        ret = std::min(ret, std::abs(x - 753));
    }

    std::cout << ret << std::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 REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    int X, Y;
    cin >> X >> Y;
    int A, B, C;
    cin >> A >> B >> C;

    vector<LL> p(A);
    REP0 (i, A)
    {
        cin >> p[i];
    }

    vector<LL> q(B);
    REP0 (i, B)
    {
        cin >> q[i];
    }

    vector<LL> r(C);
    REP0 (i, C)
    {
        cin >> r[i];
    }

    sort(p.begin(), p.end(), [](LL a, LL b) { return a > b; });
    sort(q.begin(), q.end(), [](LL a, LL b) { return a > b; });

    REP0 (i, X)
    {
        r.push_back(p[i]);
    }

    REP0 (i, Y)
    {
        r.push_back(q[i]);
    }

    sort(r.begin(), r.end(), [](LL a, LL b) { return a > b; });

    LL ans = 0;
    REP0 (i, X + Y)
    {
        ans += r[i];
    }

    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 6384
#include<iostream>
#include<algorithm>

int main(){
	int n;
	int in[3];
	bool ans[1000];
	std::cin >> n;
	for (int i = 0; i < n; ++i){
		std::cin >> in[0] >> in[1] >> in[2];
		std::sort(std::begin(in), std::end(in));
		ans[i] = (in[2] * in[2] == in[0] * in[0] + in[1] * in[1]);
	}
	for (int i = 0; i < n; ++i){
		if (ans[i])std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int a;
	if(s=="SUN")
	a=7;
	else if(s=="MON")
	a=6;
	else if(s=="TUE")
	a=5;
	else if(s=="WED")
	a=4;
	else if(s=="THU")
	a=3;
	else if(s=="FRI")
	a=2;
	else if(s=="SAT")
	a=1;
	cout<<a<<endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll t1,t2,a1,a2,b1,b2;cin>>t1>>t2>>a1>>a2>>b1>>b2;

  if(t1*a1+t2*a2==t1*b1+t2*b2) { cout<<"infinity"<<endl; return 0; }

  // A always runs long
  if(t1*a1+t2*a2<t1*b1+t2*b2) {
    swap(a1,b1);
    swap(a2, b2);
  }

  if(a1>b1) { cout<<0<<endl; return 0; }

  ll diff = (t1*a1+t2*a2) - (t1*b1+t2*b2);

  ll t1_diff = b1*t1-a1*t1;
  if(t1_diff==diff) { cout<<2<<endl; return 0; }

  ll result=(t1_diff/diff)*2+1;
  if(t1_diff%diff==0)result--;//これ追加したらAC
  cout<<result<<endl;

//cout<<t1_diff<<' '<<diff<<endl;

  return 0;
}


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

int N;
int A[15];
int x[15][15];
int y[15][15];

int pow2(int n){
    if(n==0){
        return 1;
    }else{
        return 2*pow2(n-1);
    }
}

bool andm(int i,int j){
    return i&pow2(j);
}

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
        for(int j=0;j<A[i];j++){
            cin>>x[i][j]>>y[i][j];
        }
    }

    int ans=0;
    int all=pow2(N);
    for(int i=0;i<all;i++){
        int count=0;
        for(int j=0;j<N;j++){
            bool honest=andm(i,j);
            if(honest){
                for(int k=0;k<A[j];k++){
                    if(!(andm(i,x[j][k]-1)==y[j][k])){
                        goto a;
                    }
                }
                count++;
            }
        }
        if(count>ans) ans=count;
        a:;
    }

    cout<<ans<<endl;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<int> a(n);
    vector<int> asub(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    
    int maxa = a[0]; int maxap = 0;
    int mina = a[0]; int minap = 0;
    vector<int> ansl;
    vector<int> ansr; 
    for(int i = 1; i < n; i++){
        if(maxa < a[i]){
            maxa = a[i];
            maxap = i;
        }
        if(a[i] < mina){
            mina = a[i];
            minap = i;
        }
    }
    if(mina + maxa >= 0){
        for(int i = 0; i < n; i++){
            if(i == maxap) continue;
            a[i] += a[maxap];
            ansl.push_back(maxap);
            ansr.push_back(i);
        }
        for(int i = 1; i < n; i++){
            if(maxa < a[i]){
                maxa = a[i];
                maxap = i;
            } 
        }
        a[0] += a[maxap];
        ansl.push_back(maxap);
        ansr.push_back(0);
        for(int i = 1; i < n; i++){
            a[i] += a[i-1];
            ansl.push_back(i-1);
            ansr.push_back(i);
        }
        
    } else {
        for(int i = 0; i < n; i++){
            if(i == minap) continue;
            a[i] += mina;
            ansl.push_back(minap);
            ansr.push_back(i);
        }
        for(int i = 1; i < n; i++){
            if(a[i] < mina){
                mina = a[i];
                minap = i;
            }
        }
        a[n-1] += a[minap];
        ansl.push_back(minap);
        ansr.push_back(n-1);

        for(int i = n-1; i >=1; i--){
            a[i-1] += a[i];
            ansl.push_back(i);
            ansr.push_back(i-1);
        }
    }

    cout << ansl.size() << endl;
    for(int i = 0; i < ansl.size(); i++) cout << ansl[i]+1 << " " << ansr[i]+1 << endl;

    return 0;
}


Measured memory_bytes: 256
x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
elif x5 == 0:
    print(5)

Measured memory_bytes: 9112
# coding: utf8

if __name__ == "__main__":
    s = input()
    t = input()
    map_s = {}
    map_t = {}
    for i in range(len(s)):
        if s[i] not in map_s:
            map_s[s[i]] = t[i]
        else:
            if map_s[s[i]] != t[i]:
                print("No")
                i = 0
                break
        if t[i] not in map_t:
            map_t[t[i]] = s[i]
        else:
            if map_t[t[i]] != s[i]:
                print("No")
                i = 0
                break
    if i == len(s) - 1:
        print("Yes")

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
#define sd(mark) scanf("%d",&mark)
#define ss(mark) scanf("%s",mark)
#define sl(mark) scanf("%lld",&mark)
#define debug(mark) printf("check%d\n",mark)
#define clr(mark) memset(mark,0,sizeof(mark))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ll long long
#define N 100010

ll a[N];

int main()
{
	int n,i;
	ll ans=0,x;
	sd(n);sl(x);
	for(i=0;i<n;i++)
		sl(a[i]);
	ans+=max(0ll,a[0]-x);
	a[0]=min(x,a[0]);
	for(i=1;i<n;i++)
	{
		ans+=max(0ll,a[i-1]+a[i]-x);
		a[i]-=max(0ll,a[i-1]+a[i]-x);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}
//auto f = [&](int n)->int{return n;};
//auto a = [&](auto&&b){b(b)};



signed main(){
	int N;
	cin>>N;
	vector<int>a(N);
	multiset<int>st;
	REP(i,N)cin>>a[i];
	st.insert(-a[0]);
	FOR(i,1,N){
		auto itr = st.upper_bound(-a[i]);
		if(itr != st.end())st.erase(itr);
		st.insert(-a[i]);
	}
	cout<<st.size()<<endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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;
}

ll M = 1000000007;

void solve()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans=min(k,a)*1;
	k=max((ll)0,k-a);
	ans+=min((ll)k,b)*0;
	k=max((ll)0,k-b);
	ans+=min(k,c)*(-1);
	cout<<ans<<endl;
}

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


Measured memory_bytes: 3648
s = input()
max_len = 0

for i in range(len(s)):
    for j in range(i, len(s)+1):
        s_cut = s[i:j]
        if len(s_cut.replace('A','').replace('C','').replace('G','').replace('T','')) == 0 and len(s_cut) > max_len:
            max_len = len(s_cut)

print(max_len)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int cnt[2],A[MAXN],N,B[MAXN];
map<int,int> zz;
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {read(A[i]);B[i] = A[i];}
    sort(B + 1,B + N + 1);
    for(int i = 1 ; i <= N ; ++i) zz[B[i]] = i;
    for(int i = 1 ; i <= N ; ++i) {
	if(((zz[A[i]] ^ i) & 1) != 0) cnt[i & 1]++;
    }
    out(cnt[0]);enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 5760
import java.util.*;
import java.awt.*;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        String s = sc.next();
        char[] list = s.toCharArray();
        ArrayList<Character> c = new ArrayList<Character>();
        String ans = "Yes";
        for(int i = 0; i<4; i++){
            if(!c.contains(list[i])){
                c.add(list[i]);
            }
        }
        for(int i = 0; i<4; i++){
            int count = 0;
            for(int l = 0; l<4; l++){
                if(list[i]==list[l]){
                    count++;
                }
            }
            if(count > 2){
                ans ="No";
            }
        }
        if(c.size() != 2){
            ans ="No";
        }
        System.out.println(ans); 
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<int,int>
#define debug(a) cout<<a<<'\n'
#define maxn 309 
#define MOD 1000000007
#define rep(i, n) for(ll i = 0; i < (ll)(n); i ++)
#define rep1(i, n) for(ll i = 1; i <= (ll)(n); i ++)
#define per(i, n) for(ll i = (ll)(n)-1;i>=0;i--)
#define per1(i, n) for(ll i = (ll)(n);i>=1;i--)
using namespace std;
const ll INF = 1e17 + 9;
ll mat[maxn][maxn];
ll mat2[maxn][maxn];
int main(){

    ios::sync_with_stdio(false);
    // cin.tie(0);
    int n,m,l;
    cin>>n>>m>>l;
    rep(i,maxn){
        rep(j,maxn){
            mat[i][j]=INF;
            mat2[i][j]=INF;
        }
    }
    rep(i,m){
        ll a,b,c;
        cin>>a>>b>>c;
        --a;
        --b;
        mat[a][b]=c;
        mat[b][a]=c;
    }
    rep(k,maxn){
        rep(i,maxn){
            rep(j,maxn){
                mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
                if(mat[i][j]<=l)mat2[i][j]=1;
            }
        }
    }
    rep(k,maxn){
        rep(i,maxn){
            rep(j,maxn){
                mat2[i][j]=min(mat2[i][j],mat2[i][k]+mat2[k][j]);
            }
        }
    }
    ll q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        --a,--b;
        if(mat2[a][b]<INF)cout<<mat2[a][b]-1<<'\n';
        else cout<<-1<<'\n';
    }
    return 0;
}

Measured memory_bytes: 2048
using System;
using System.Linq;

public class Program
{
    public static void Main()
    {
        var firstRow = Console.ReadLine();
        var x = int.Parse(firstRow.Split(" ")[0]);
        var n = int.Parse(firstRow.Split(" ")[1]);
        if(n == 0)
        {
            Console.WriteLine(x);
            return;
        }

        var ps = Console.ReadLine().Split(" ").Select(s => int.Parse(s));

        var i = x;
        while (ps.Any(n => n == i))
        {
            i--;
        }
        var nearLowValue = i;

        i = x;
        while (ps.Any(n => n == i))
        {
            i++;
        }
        var nearHighValue = i;

        if(Math.Abs(x - nearLowValue) <= Math.Abs(x - nearHighValue))
        {
            Console.WriteLine(nearLowValue);
        } else
        {
            Console.WriteLine(nearHighValue);
        }
    }
}

Measured memory_bytes: 28236
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
    vector<ll> che;
    bool age=false;
    if(p[0]<p[1]) age=true;
    if(age) che.push_back(p[0]);
    rep(i,n-1){
        if(p[i]==p[i+1]) continue;
        if(age){
            if(p[i]>p[i+1]){
                age=false;
                che.push_back(p[i]);
            }
        }else{
            if(p[i]<p[i+1]){
                age=true;
                che.push_back(p[i]);
            }
        }
    }
    if(age) che.push_back(p[n-1]);
    int m=che.size();
    m/=2;
    ll ans=1000;
    rep(i,m){
        ll cnt=(ans/che[i*2]);
        //cout<<cnt<<endl;
        ans-=(che[i*2]*cnt);
        ans+=(che[i*2+1]*cnt);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;
int main(void){
    long long w,h,x,y;
    cin >> w >> h >> x >> y;
    double area = (double)(w*h/2.0);
    bool a = (w==x*2) && (h==y*2);
    cout << area << ' ' << (int)(a) << endl;
    
    return 0;
}


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

#define ALL(a) a.begin(), a.end()

int n;
vector<int> a;

void agc023a() {
  vector<ll> s(n + 1);
  s[0] = 0;
  for (int i = 0; i < n; i++) {
    s[i + 1] = s[i] + a[i];
  }

  map<ll, ll> mp;
  for (int i = 0; i <= n; i++) {
    mp[s[i]]++;
  }

  ll ans = 0;
  for (auto p : mp) {
    if (p.second >= 2) {
      ans += p.second * (p.second - 1) / 2;
    }
  }
  cout << ans << '\n';
}

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  agc023a();
  return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using p = pair<int, int>;

int main()
{

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int th = h2 - h1;
    int tm = m2 - m1;
    int t = th * 60 + tm;
    int tk = t - k;

    cout << tk << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#define ll long long

using namespace std;

int main(){

  string S;
  cin >> S;
  int n = S.size();
  ll ans = 0;

  for (int i = 0; i < (1<< (n-1) ); i++) { // 演算子追加分を回す(植木算)
    ll c = 0;
    for (int j = 0; j < n; j++) { // 数値桁数分だけ回す 3桁なら0〜2
      c = c * 10 + S[j] - '0'; // 切り出しと数値を同時実行
      if(i & (1<<j) || j == n-1){ // iの中にj列が含まれるかを探索する。もしくはjが最後
        ans += c;
        c = 0;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256