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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  int i,j;
  rep(i,n)
  {
    string s;cin>>s;
    vector<int> nums(0);
    int now=0;
    int knum=0;
    while(now<s.size())
    {
      if(s[now]=='[')nums.emplace_back(-1);
      else if(s[now]==']')
      {
        if(knum!=0)nums.emplace_back(knum/2+1);
        knum=0;
        nums.emplace_back(-2);
      }
      else
      {
        knum*=10;
        knum+=(s[now]-'0');
      }
      now++;
    }
    int maxd=0;
    int nowd=0;
    rep(j,nums.size())
    {
      if(nums[j]==-1)
      {
        nowd++;
        maxd=max(maxd,nowd);
      }
      else if(nums[j]==-2)nowd--;
    }
    while(maxd>1)
    {
      now=0;
      while(now<nums.size())
      {
        if(nums[now]>0)
        {
          nums.erase(nums.begin()+now+1);
          nums.erase(nums.begin()+now-1);
        }
        now++;
      }
      now=0;
      nowd=0;
      while(now<nums.size())
      {
        if(nums[now]==-1)nowd++;
        if(nums[now]==-2)nowd--;
        if(nowd==maxd-1)
        {
          vector<ll> ps(0);
          now++;
          int nowb=now;
          while(nums[now]>0)
          {
            ps.emplace_back(nums[now]);
            nums.erase(nums.begin()+now);
          }
          sort(all(ps));
          ll mans=0;
          rep(j,ps.size()/2+1)
          {
            mans+=ps[j];
          }
          nums.insert(nums.begin()+nowb,mans);
        }
        now++;
      }
      maxd--;
    }
    cout<<nums[1]<<endl;
  }
}



Measured memory_bytes: 3264
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF (int)1e9
#define MOD (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int x,a;
	cin>>x>>a;
	
	if(x<a) cout<<0<<endl;
	else cout<<10<<endl;
}

Measured memory_bytes: 256
def key():
    a=input()
    b=''
    for i in range(0,len(a)):
        if a[i]=='0':
            b+='0'
        elif a[i]=='1':
            b+='1'
        elif a[i]=='B':
            if len(b)==0:
                continue
            else:
                b=b[0:-1]
    print(b)

key()


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

int main(){

  int A, B, C, D, L, R;

  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;

  if(L > R) puts("Left");
  if(L == R) puts("Balanced");
  if(L < R) puts("Right");

}


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

using namespace std;

#define INF 1000000001

int N, T;
int v[100001];
int d[100001];

int main(){
  int cnt = 0;
  int _min = INF;
  int d = 0;

  scanf("%d %d", &N, &T);
  
  for(int i = 0 ; i < N ; i++){
    scanf("%d", &v[i]);
  }  

  for(int i = 0 ; i < N ; i++){
    _min = min(_min, v[i]);  // それまでの最小
    int diff = v[i]-_min;    // 差分
    if(d < diff){     // 大きな差分
      d = diff;
      cnt = 1;
    }else if(d == diff){     // おなじ
      cnt++;
    }
  }
  
  printf("%d\n", cnt);
}


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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r;
  cin >> r;
  cout << 3*r*r << endl;
  return 0;
    

}


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

int main(){
  int a,b,c,d,e,f;
  int maxcheck=-1,maxnumber;
  scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
  int water[35];
  int consent[35],maxsuger[35];
  int i,j,k;
  int suger=0;
  for(i=0;i<35;i++){
    water[i]=0;
    maxsuger[i]=0;
    consent[i]=0;
  }
  for(i=0;i<30;i++){
    for(j=0;j<20;j++){
      if(a*i*100+b*j*100<=f){
        water[a*i+b*j]=1;
      }
    }
  }
  for(i=1;i<=30;i++){
    if(water[i]==1){
      suger = i*e;
      for(j=0;j<50;j++){
        for(k=0;k<50;k++){
          if((c*j+d*k<=suger) && (c*j+d*k+i*100<=f) && (maxsuger[i] < c*j+d*k)){
            maxsuger[i]=c*j+d*k;
          }
        }
      }
    }
  }
  for(i=1;i<35;i++){
    if(water[i]==1){
      consent[i]=maxsuger[i]*10000/(i*100+maxsuger[i]);
    }
  }
  for(i=1;i<35;i++){
    if(consent[i]>maxcheck && water[i] == 1){
      maxcheck = consent[i];
      maxnumber = i;
    }
  }
  printf("%d %d\n",maxnumber*100+maxsuger[maxnumber],maxsuger[maxnumber]);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main(){
	int N, A, B; cin >> N >> A >> B;
	int count = 0;

	for (int i = 1; i <= N; i++) {
		string istr = to_string(i);
		int sum = 0;
		for (int j = 0; j < istr.size(); j++) {
			sum += (int)istr[j] - 48;
		}
		if (A <= sum && sum <= B)count += i;
	}

	print(count);




	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define sll set<ll>
#define fo(i,n) for(i=0;i<n;i++)
#define MOD 1000000007
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    //freopen("000.txt","r",stdin);

    ll n,i,j,k,t,a,b,h[100001],ac,bc;

    cin>>n>>a>>b;

    fo(i,n)
        cin>>h[i];

    sort(h,h+n);
    reverse(h,h+n);
    ll l=-1,r=1000000001,mid,c,d,x;

    while(l<r-1)
    {
        mid=(l+r)>>1;
        ac=mid;bc=0;
        int flag=0;
        fo(i,n)
        {
            c=h[i]-bc*b;
            if(c<=0)
                continue;
            d=ac;
            x=ceil((c-d*b)*1.0/(a-b));
            if(x>ac)
            {
                flag=1;
                break;
            }
            ac-=x;
            bc+=x;
        }

        if(flag==0)
            r=mid;
        else
            l=mid;
        //cout<<l<<" "<<r<<endl;
    }

    cout<<r;
    return 0;
}


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

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORI(i,z,n) for(int i=z;i<n;i++)
#define MAX(a,b,c) max(a,max(b,c))

using namespace std;

struct Obj {int weight; int value;};

int main () {
    int N, W;
    cin >> N >> W;

    vector<Obj> objects(N);
    FOR(i,N) {
        int v, w;
        cin >> v >> w;
        objects[i] = Obj{w, v};
    }

    vector<int> dyn(W+1);
    dyn[0] = 0;

    FORI(i, 1, W+1)
        for(Obj o: objects)
            if (i >= o.weight)
                dyn[i] = max(dyn[i], dyn[i-o.weight] + o.value);

    cout << dyn[W] << endl;
}



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

using namespace std;

const int m = 13, r = 5, mod = 1e9+7;

string s;
ll cnt[m], new_cnt[m];

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> s;
    int n = s.size();
    ll p = 1;
    cnt[0] = 1;
    for(int i = n-1; i >= 0; --i){
        if(s[i] == '?'){
            for(int j = 0; j < 10; ++j)
                for(int k = 0; k < m; ++k){
                    new_cnt[(k+j*p)%m] += cnt[k];
                    new_cnt[(k+j*p)%m] %= mod;
                }
        }
        else{
            int j = s[i] - '0';
            for(int k = 0; k < m; ++k){
                new_cnt[(k+j*p)%m] += cnt[k];
                new_cnt[(k+j*p)%m] %= mod;
            }
        }
        for(int k = 0; k < m; ++k){
            cnt[k] = new_cnt[k];
            new_cnt[k] = 0;
        }
        p = p*10%m;
    }
    cout << cnt[r] << '\n';
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		String[] S = new String[H];
		for ( int h = 0 ; h < H ; h++ ) {
			S[h] = sc.next();
		}
		sc.close();

		int[] map = new int[W];
		for ( int w = 0 ; w < W ; w++ ) {
			for ( int h = 0 ; h < H ; h++ ) {
				if ( S[h].charAt(w) == '1' ) {
					map[w] += 1 << h;
				}
			}
		}

		int minCut = Integer.MAX_VALUE;
		OUTER:for ( int div = 0 ; div < (1 << (H - 1)) ; div++ ) {
			int[] block = new int[11];
			int blockCnt = 1;
			for ( int h = 0 ; h < H - 1 ; h++ ) {
				if ( ((div >> h) & 1) == 1 ) {
					block[blockCnt++] = h + 1;
				}
			}
			block[blockCnt] = H;
			int divCnt = blockCnt - 1;

			int[] whiteCnt = new int[blockCnt];
			int[] curCnt = new int[blockCnt];
			for ( int w = 0 ; w < W ; w++ ) {
				Arrays.fill(curCnt, 0);
				int b = 0;
				boolean over = false;
				for ( int h = 0 ; h < H ; h++ ) {
					if ( h >= block[b + 1] ) {
						b++;
					}
					if ( ((map[w] >> h) & 1) != 0 ) {
						curCnt[b]++;
						if ( whiteCnt[b] + curCnt[b] > K ) {
							if ( curCnt[b] > K ) {
								continue OUTER;
							}
							over = true;
						}
					}
				}
				if ( over ) {
					for ( int bb = 0 ; bb < blockCnt ; bb++ ) {
						whiteCnt[bb] = curCnt[bb];
					}
					divCnt++;
				} else {
					for ( int bb = 0 ; bb < blockCnt ; bb++ ) {
						whiteCnt[bb] += curCnt[bb];
					}
				}
			}
			minCut = Math.min(minCut, divCnt);
		}

		System.out.println(minCut);
	}
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)
const int intinf = numeric_limits<int>::max();

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define MOD 1000000007

struct UnionFind
{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x)
    {
        return -data[root(x)];
    }
};

void solve()
{
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(M), B(M);
    rep(i, M) cin >> A[i] >> B[i];
    vector<int> C(K), D(K);
    rep(i, K) cin >> C[i] >> D[i];

    UnionFind uf(N + 1);
    vector<int> friends(N + 1, 0);
    rep(i, M)
    {
        uf.unionSet(A[i], B[i]);
        friends[A[i]]++;
        friends[B[i]]++;
    };

    vector<int> blocks(N + 1, 0);
    rep(i, K)
    {
        if (!uf.findSet(C[i], D[i]))
            continue;
        blocks[C[i]]++;
        blocks[D[i]]++;
    }

    vector<int> ans(N + 1);
    rep1(i, N)
    {
        ans[i] = uf.size(i) - 1 - friends[i] - blocks[i];
        cout << ans[i] << " ";
    }
    cout << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main()
{
         int c,i,n,m,b=0,j,k,a;
         cin>>n;
         for(i=1;i<=n;i++)
        {
           for(j=1;j<=n;j++)
        {
                 for(k=1;k<=n;k++)
        {
          a= __gcd(i,j);
          b+= __gcd(a,k);
         }
        }
        }
         cout<<b<<endl;
}


Measured memory_bytes: 3560
#include <stdio.h>

#define N 300000

int main(void){
  int c,i,n,min;
  char s[N];
  
  scanf("%d",&n);
  scanf("%s",s);
  
  for( i=1; i<n; i++){
    if( s[i] == 'E' ) min++;
  }
  
  for( c=min, i=1; i<n; i++){
    if( s[i] == 'E' ) c--;
    if( s[i-1] == 'W' ) c++;
    
    if( c < min ) min = c;
  }
  
  printf("%d\n",min);
  
  return 0;
}
  

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    string S;
    cin >> a >> S;
    if(a >= 3200) cout << S << endl;
    else cout << "red" << endl;

    return 0;
}


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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rep1(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define repU(i,bottom,ceiling) for(auto (i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i,ceiling,bottom) for(auto (i) = (ceiling); (i) >= (bottom); --(i))
#define repS(n) for(int s = 0; s < 1 << n; ++s)
#define repV(i,v) for(auto (i) = begin(v); (i) < end(v); ++(i))
#define all(v)  begin(v),end(v)
#define clr(v) fill(all(v),0)
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define divceil(n,d) ((n)/(d) + ((n)%(d) > 0))
#define parity(a,b) (((a) & 1)^((b) & 1)^1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF = -1 + (1<<30);
const int MOD = (int)1e9 + 7;

template<class T,class U> auto LB(T v, U in){ return lower_bound(begin(v), end(v), in); }

template<class T,class U> auto UB(T v, U in){ return upper_bound(begin(v), end(v), in); }

ull next_subset(ull subset){
	ull tem = subset + (subset & -subset);
	ull btm = (~tem & subset) / (subset & -subset) >> 1;
	return btm | tem;
}

int N,a[100001],b[100001];
int H;

void solve(){
	
	sort(a,a+N);
	sort(b,b+N);
	
	int p = lower_bound(b,b+N,a[N-1]) - begin(b);
	int c = 0;
	
	repD(i,N-1,p){
		++c;
		H -= b[i];
		if(H <= 0){
			cout<<c<<endl;
			return;
		}
	}
	
	cout<< c + divceil(H,a[N-1]) <<endl;
	
	return;
}

void input(){
	
	cin>>N>>H;
	rep(i,N) cin>>a[i]>>b[i];
	
	return;
}

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





Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
int main() {
 
	string str;
    int a,i;
	cin >> str;
 
    a = str.size();
   
      for(i=0;i<a;i+=2) { 
       cout << str[i] ; 
      }
      
      cout << endl;
      
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int N;
int cubic(int n) {
    return n*n*n;
}
int tetrahedral(int n) {
    return n*(n+1)*(n+2)/6;
}
void solve() {
    int ans=0;
    rep(n1,100) rep(n2,100) {
        if(cubic(n1)+tetrahedral(n2)<=N) {
            ans=max(ans,cubic(n1)+tetrahedral(n2));
        }
    }

    cout<<ans<<endl;
}

int main() {
    while(cin>>N) {
        if(!N) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;

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

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

    LL even_sum = 0, odd_sum = 0;
    for( int i = 0; i < n; ++i ) {
        if( i % 2 ) odd_sum += a[i];
        else even_sum += a[i];

    }

    int plus = 0;
    if( even_sum < odd_sum ) plus = 1;

    LL sum = 0;
    LL res = 0;
    for( int i = 0; i < n; ++i ) {
        sum += a[i];
        if( i % 2 == plus ) {
            if( sum <= 0 ) {
                res += -sum + 1;
                sum = 1;

            }

        } else {
            if( sum >= 0 ) {
                res += sum + 1;
                sum = -1;

            }
        }
    }

    sum = 0;
    LL res2 = 0;
    if( plus ) plus = 0;
    else plus = 1;

    for( int i = 0; i < n; ++i ) {
        sum += a[i];
        if( i % 2 == plus ) {
            if( sum <= 0 ) {
                res2 += -sum + 1;
                sum = 1;

            }
        } else {
            if( sum >= 0 ) {
                res2 += sum + 1;
                sum = -1;

            }
        }
    }

    cout << min( res, res2 ) << endl;

    return 0;
}



Measured memory_bytes: 1152
/*4_1 hightierra*/
#include <stdio.h>

int main(void){
    int number,range;
    scanf("%d %d",&number,&range);

    int human ,remainder ;
    // 一人が見れる範囲は2*range+1
    human = number / (2*range+1);
    remainder = number % (2*range+1);

    // 余った木は一人で見れる数
    if(remainder > 0){
        human++;
    }
    printf("%d\n",human);
    return 0;
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  int n,m;
  cin>>n>>m;
  vector<P> p(m);
  rep(i,m) cin >> p[i].first >> p[i].second;
  rep(x,1000) {
    int keta = 1;
    int nx = x/10;
    vector<int> d(1,x%10);
    while (nx) {
      keta++;
      d.push_back(nx%10);
      nx /= 10;
    }
    if (keta != n) continue;
    bool ok = true;
    reverse(all(d));
    rep(i,m) {
      if (d[p[i].first-1] != p[i].second) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int num = 0;
    while(b <= a) {
        b*=2;
        num++;
    }
    while(c <= b) {
        c*=2;
        num++;
    }
    if(num <= k) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
    string S;
    cin >> S;
    int N=S.size();
    bool w[N];
    rep(i,N){
        w[i]=false;
    }
    rep(i,N){
        if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T'){
            w[i]=true;
        }
    }
    int count=0;
    int ans=0;
    rep(i,N){
        if(w[i]){
            count++;
            ans=max(ans,count);
        }
        else{
            count=0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

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

    int n, lim = 1e5;
    cin >> n;

    vector<int> A;
    for(int i = 1; i <= lim; i *= 6){
        A.push_back(i);
    }
    for(int i = 9; i <= lim; i *= 9){
        A.push_back(i);
    }
    sort(A.begin(), A.end());

    vector<int> dp(n + 1, 1e9);
    dp[0] = 0;

    for(int i = 0; i < A.size(); i++){
        for(int j = A[i]; j <= n ; j++){
            dp[j] = min(dp[j], dp[j - A[i]] + 1);
        }
    }
    /*
    REP(i, n + 1){
        cout << i << " " << dp[i] << endl;
    }
    */
    cout << dp[n] << endl; 

    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long N = in.nextLong();
        long three = N / 3 * (N / 3 + 1) / 2 * 3;
        long five = N / 5 * (N / 5 + 1) / 2 * 5;
        long fifteen = N / 15 * (N / 15 + 1) / 2 * 15;
        long all = N * (N + 1) / 2;
        System.out.println(all - three - five + fifteen);
    }
}

Measured memory_bytes: 35804
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, K = ZZ()
    P = sorted(ZZ())
    print(sum(P[:K]))

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9120
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

const ll MOD = 1000000007;
ll dp[105][100005];

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n+1);
	rep (i, n) cin >> a[i+1];

	for (int i = k; i >= max(0LL, k - a[1]); i--) {
		dp[1][i] = 1;
	}

	for (int i = 1; i < n; i++) {
		vector<ll> sum(k+1, 0);
		sum[0] = dp[i][0];
		for (int j = 1; j <= k; j++) {
			sum[j] += sum[j-1] + dp[i][j];
			sum[j] %= MOD;
		}
		//cout << i << " "; for (int j = 0; j <= k; j++) cout <<j<<sum[j] << " ";cout<<endl;
		for (int j = 0; j <= k; j++) {
			dp[i+1][j] = (sum[min((ll)k, (ll)j + a[i+1])] - (j ? sum[j-1] : 0) + MOD) % MOD;
		}
	}

	cout << dp[n][0] % MOD << endl;
	return 0;
}

Measured memory_bytes: 80116
n = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0
for i in range(n):
  if i >= 1 and a[i - 1] + 1 == a[i]:
    ans += c[a[i - 1] - 1]
  ans += b[a[i] - 1]

print(ans)

Measured memory_bytes: 3064
from collections import defaultdict 
import sys,heapq,bisect,math,itertools,string

sys.setrecursionlimit(10**8)

#N:頂点数   M:辺数
A,B,C = map(int,input().split())

aa = [A,B,C]
aa.sort()


ans = 0

while aa[2]-aa[0] > 1:
	aa[0] += 2
	ans += 1
	
	
while aa[2]-aa[1] > 1:
	aa[1] += 2
	ans += 1
	
nn = aa[2]*2 - aa[1] - aa[0]	
	
if nn == 2:
	print(ans+1)
elif nn == 1:
	print(ans+2)
else:
	print(ans)

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, h[N];
long long f[N];
int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++) scanf("%d", h + i);
    f[1] = 0;
    f[2] = abs(h[2] - h[1]);
    for(int i = 3; i <= n; i ++)
    {
        f[i] = min(f[i - 1] + abs(h[i] - h[i - 1]), f[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << f[n] << endl;
    return 0;
}

Measured memory_bytes: 1408
'use strict'
const Main = (arg) => {
  let input = arg.trim().split('\n');
  let A = input[0].split(' ').map(Number)[0];
  let B = input[0].split(' ').map(Number)[1];
  let K = input[0].split(' ').map(Number)[2];

  let a = 0;
  let b = 0;
  if ((A - K) >= 0) {
    a = A - K;
    b = B;
  } else {
    if ((A + B - K) >= 0) {
      a = 0;
      b = A + B - K;
    } else {
      a = 0;
      b = 0;
    }
  }
  console.log(a, b)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,U,V,a,b,maximum=0;
    cin>>N>>U>>V;
    using Graph=vector<vector<int>>;
    Graph G(N);
    for(int i=0;i<N-1;++i){
        cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    vector<int> distu(N,-1);
    queue<int> queu;
    distu[U-1]=0;
    queu.push(U-1);
    while(!queu.empty()){
        int v=queu.front();
        queu.pop();
        for(int nv:G[v]){
            if(distu[nv]!=-1)continue;
            distu[nv]=distu[v]+1;
            queu.push(nv);
        }
    }
    vector<int> distv(N,-1);
    queue<int> quev;
    unordered_map<int,int> mpv;
    distv[V-1]=0;
    quev.push(V-1);
    while(!quev.empty()){
        int v=quev.front();
        quev.pop();
        for(int nv:G[v]){
            if(distv[nv]!=-1)continue;
            distv[nv]=distv[v]+1;
            mpv[nv]=v+1;
            quev.push(nv);
        }
    }
    for(int i=0;i<N;i++){
        if(distu.at(i)<distv.at(i) && maximum<distv.at(i)-1){
            maximum=distv.at(i)-1;
        }
    }
    cout<<maximum<<endl;
    return 0;
}

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

using namespace std;

int calc_sum (int x) {
  if (x == 1) return 1;
  else return x + calc_sum(x - 1);
}

int main() {
  int n, result;
  cin >> n;
  result = calc_sum(n);
  cout << result << endl;
  return 0;
}

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

struct Node{
    int key;
    Node *prev,*next;
};

Node *nil;

void init(){
    nil=(Node*)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}

void insert(int key){
    Node *x=(Node*)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}

Node* listSearch(int key){
    Node *cur=nil->next;
    while(cur!=nil&&cur->key!=key){
        cur=cur->next;
    }
    return cur;
}

void deleteNode(Node *t){
    if(t==nil) return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

int main(){
    int n;
    cin>>n;
    init();
    for(int i=0;i<n;i++){
        char s[20];
        int x;
        scanf("%s%d",s,&x);
        if(s[0]=='i'){
            insert(x);
        }
        else if(s[6]=='F'){
            deleteFirst();            
        }
        else if(s[6]=='L'){
            deleteLast();            
        }
        else{
            deleteKey(x);            
        }  
    }
    Node *ans=nil->next;
    cout<<(ans->key);
    ans=ans->next;
    while(ans!=nil){
        cout<<' '<<(ans->key);
        ans=ans->next;
    }
    cout<<endl;    
}


Measured memory_bytes: 34380
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    // 数値
    let (a, b, c, d) = {
        let i = read::<isize>();
        (i[0], i[1], i[2], i[3])
    };

    let ab = (a - b).abs() <= d;
    let ac = (a - c).abs() <= d;
    let bc = (b - c).abs() <= d;

    let mut ans = false;
    if ac {
        ans = true;
    }

    if ab && bc {
        ans = true;
    }

    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    K = I()

    if K % 2 == 0 or K % 5 == 0:
        print(-1)
    else:
        rem = 7 % K
        ans = 0
        while rem != 0:
            rem = rem * 10 + 7
            rem %= K
            ans += 1

        print(ans + 1)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9984
#include <iostream>
#include <set>

using namespace std ;

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

    long long tot = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            bool flag = true ;
            for(int k = 0; k < n; k++)
            {
                if( ( a[i][k] + a[k][j] ) < a[i][j] )
                {
                    cout << -1 ; return 0;
                }

                if( ( ( a[i][k] + a[k][j] ) == a[i][j] ) and a[i][k] > 0 and a[k][j] > 0 and i != j)
                    flag = false ;
            }
            if(flag) tot += a[i][j] ;
        }
    }
    cout << tot/2 ;
    return 0;
}


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

int main() {
    int P, Q, R;
    std::cin >> P >> Q >> R;

    std::vector<int> numbers;
    numbers.push_back(P);
    numbers.push_back(Q);
    numbers.push_back(R);

    std::sort(numbers.begin(), numbers.end());

    std::cout << numbers[0] + numbers[1] << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int n, k; cin >> n >> k;
	vector<int> a(n);
	rep(i, n) scanf("%d", &a[i]);
	sort(a.begin(), a.end());
	int m = lower_bound(a.begin(), a.end(), k) - a.begin();
	if(m == 0){
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	
	vector<bool> dpb(k, false); dpb[0] = true;
	vector<vector<bool>> dp(m+2, dpb);
	vector<vector<bool>> rdp(m+2, dpb);
	
	reg(i, 1, m) irep(j, k) if(dp[i-1][j]){
		dp[i][j] = true;
		if(a[i-1]+j<k) dp[i][a[i-1]+j] = true;
	}
	ireg(i, 1, m) irep(j, k) if(rdp[i+1][j]){
		rdp[i][j] = true;
		if(a[i-1]+j<k) rdp[i][a[i-1]+j] = true;
	}
	
	reg(i, 1, m){
		bool f = true;
		if(i == 1){
			reg(j, 1, a[i-1]) if(rdp[2][k-j]){
				f = false;
				break;
			}
		}else if(i == m){
			reg(j, 1, a[i-1]) if(dp[m-1][k-j]){
				f = false;
				break;
			}
		}else{
			int l = k-1;
			reg(j, 0, k) if(dp[i-1][j]){
				if(k-j <= l) l = k-j-1;
				if(l<0) break;
				while(k-a[i-1]-j <= l){
					if(rdp[i+1][l]){
						f = false;
						break;
					}
					l--;
					if(l<0) break;
				}
				if(!f) break;
			}
		}
		if(f) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 6912
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	hp_t := nextInt()
	at_t := nextInt()
	hp_a := nextInt()
	at_a := nextInt()

	for {
		hp_a -= at_t
		if hp_a <= 0 {
			fmt.Println("Yes")
			break
		}
		hp_t -= at_a
		if hp_t <= 0 {
			fmt.Println("No")
			break
		}
	}
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
ll s(ll x) {
	if (x > 0) return 1LL;
	if (x < 0) return -1LL;
	return 0;
}
pll simp(ll a, ll b) {
	if (a == 0 && b == 0) return {0, 0};
	if (a == 0) return {0, 1};
	if (b == 0) return {1, 0};
	ll d = __gcd(a, b);
	a /= d;
	b /= d;
	ll sgn = 1;
	if ((a > 0 && b < 0) || (a < 0 && b > 0)) sgn = -1;
	return {abs(a)*sgn, abs(b)};
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<pll, int> counter;
	ll edge_case = 0;
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			edge_case++;
		}
		else {
			pll t = simp(a, b);
			if (counter.find(t) == counter.end()) counter[t] = 1;
			counter[t] *= 2;
			counter[t] %= MOD;
		}
	}
	vector<ll> S;
	//for (const auto &p: counter) {
		//cout << p.first.first << "/" << p.first.second << " == " << p.second << endl;
	//}
	while (!counter.empty()) {
		//db(counter.size());
		pll t = (*counter.begin()).first;
		ll sgn = 1;
		if (t.first <= 0) sgn = -1;
		sgn *= -1;
		pll u = {sgn*abs(t.second), abs(t.first)};
		if (t == pll(1, 0)) u = {0, 1};
		if (t == pll(0, 1)) u = {1, 0};
		if (counter.find(u) != counter.end()) {
			S.push_back((counter[u] + counter[t] - 1) % MOD);
			counter.erase(u);
			counter.erase(t);
		} else {
			S.push_back(counter[t]);
			counter.erase(t);
		}
	}

	ll ans = 1;
	for (ll a: S) {
		//db(a);
		ans *= a;
		ans %= MOD;
	}
	
	ans += edge_case;
	cout << (ans - 1 + MOD) % MOD << endl;
}



Measured memory_bytes: 17788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int main() {
    string S;
    cin >>S;
    vector<ll> N(S.size());
    rep(i,S.size()){
        N[i] = ctoi(S[i]);
    }
    vector<vector<vector<ll>>> dp(N.size()+1,vector<vector<ll>>(8,vector<ll>(2)));
    vector<vector<vector<ll>>> dp2(N.size()+1,vector<vector<ll>>(8,vector<ll>(2)));
    dp2[0][0][0] = 1;
    rep(i,N.size()){
        rep(j,8){
            rep(k,2){
                for(int x=0;x<=(k ? 9 : N[i]); x++){
                    if(x==3){
                        dp[i+1][(j|1)][k || (x<N[i])] += dp[i][j][k];
                        dp[i+1][(j|1)][k || (x<N[i])] += dp2[i][j][k];
                    }else if(x==5){
                        dp[i+1][(j|2)][k || (x<N[i])] += dp[i][j][k];
                        dp[i+1][(j|2)][k || (x<N[i])] += dp2[i][j][k];
                    }else if(x==7){
                        dp[i+1][(j|4)][k || (x<N[i])] += dp[i][j][k];
                        dp[i+1][(j|4)][k || (x<N[i])] += dp2[i][j][k];
                    }else if(x==0){
                        dp2[i+1][j][k || (x<N[i])] += dp2[i][j][k];
                    }
                }
            }
        }
    } 
    /*rep(i,N.size()+1){
        rep(j,8){
            cout<<dp[i][j][1]<<" ";
        }
        cout<<endl;
    }
    rep(i,N.size()+1){
        rep(j,8){
            cout<<dp[i][j][0]<<" ";
        }
        cout<<endl;
    }*/
    cout << dp[N.size()][7][0]+dp[N.size()][7][1]<<endl;
   


    return 0;
    

}

Measured memory_bytes: 3660
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力                                                                                                                              
        int N = sc.nextInt();
        int K = sc.nextInt();
        int xi;
        int Sum = 0;
	int i;
        for(i=0;i<N;i++){
            xi = sc.nextInt();
            if(K-xi < xi){
                Sum += K-xi;
            }else{
                Sum += xi;
            }
        }
        System.out.println(2*Sum);
    }
}




Measured memory_bytes: 21844
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars,
        k: usize
    }
    let mut cs = vec![];
    let mut p = s[0];
    let mut c = 0;
    for &ch in &s {
        if ch == p {
            c += 1;
        } else {
            cs.push((p, c));
            p = ch;
            c = 1;
        }
    }
    cs.push((p, c));
    let n = cs.len();
    if n == 1 {
        println!("{}", (cs[0].1 * k) / 2);
    } else if cs[0].0 == cs[n - 1].0 {
        let ans = cs[0].1 / 2 + cs[1..n - 1].iter().fold(0, |ac, &x| ac + x.1 / 2) * k + cs[n - 1].1 / 2 + (cs[0].1 + cs[n - 1].1) / 2 * (k - 1);
        println!("{}", ans);
    } else {
        println!("{}", cs.iter().fold(0, |ac, x| ac + x.1 / 2) * k);
    }
}


Measured memory_bytes: 4352
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def ho(a, b, x):
    return b // x - (a - 1) // x


A, B, C, D = [int(i) for i in input().split()]
c_ho = ho(A, B, C)
d_ho = ho(A, B, D)
cd_ho = ho(A, B, lcm(C, D))
print(B - A + 1 - (c_ho + d_ho) + cd_ho)


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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m; cin >> n >> m;
  vector<P> v(m);
  rep(i, m) {
    int x, y; cin >> x >> y;
    v[i] = make_pair(y, x);
  }
  sort(v.begin(), v.end());
  int ans = 1;
  int right = v[0].first;
  rep(i, m) {
    if(right <= v[i].second) {
      ++ans;
      right = v[i].first;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s, n) for(int i = s; i < (int)(n); i++)
#define co(x) cout<<x<<endl
#define SQvec(i,j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000000+7
typedef long long int lint;

int main() {
  int size;
  string S,T;
  bool ans;
  cin >> S >> T;
  size = S.size();
  
  rep(i,0,S.size()){
    ans = true;
    rep(j,0,S.size()){
      if(S[(j + i)%size] == T[j]){continue;}
      else{ans = false;break;}
    }
    if(ans == true){break;}
  }
  if(ans == true){co("Yes");}
  else{co("No");}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	string s;
	cin >> s;
	if(s.size()==1){
		cout << 1 << endl;
		return 0;
	}
	int ans = 1;
	string s1="",s2="";
	s1 += s[0];
	int i = 1;
	while(1){
		while(s2=="" || (s1==s2 && i<s.size())){
			s2+=s[i];
			i++;
		}
		if(s1!=s2)ans ++;
		s1 = s2;
		s2 = "";
		if(i==s.size())break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

struct UnionFind{
	int par[1000];
	int rank[1000];
	UnionFind(int n){
		init(n);
	}
	void init(int n){		REP(i,n){par[i] = i;rank[i] = 0;}}
	int find(int a){
		if(par[a] == a)return a;
		return par[a] = find(par[a]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x==y)return;
		if(rank[x]<rank[y])par[x] = y;
		else {
			par[y] = x;
			if(rank[x]==rank[y])rank[x]++;
		}
	}
	bool same(int x,int y){return find(x)==find(y);}
};

int standard_e;
struct Edge{
	int u,v,cost;
	Edge(){}
};

bool comp(const Edge& e1,const Edge& e2){
	return abs(standard_e-e1.cost) < abs(standard_e-e2.cost);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m,n){
		vector<Edge> edge(m);
		UnionFind uni(n);
		REP(i,m){
			cin >> edge[i].u >>edge[i].v >> edge[i].cost;
			edge[i].u--;edge[i].v--;
		}
		int ans = INF;
		REP(i,m){
			uni.init(n);
			standard_e = edge[i].cost;
			int diff_min;
			int maxc = -INF,minc = INF;
			sort(edge.begin(),edge.end(),comp);
			REP(j,m){
				Edge e = edge[j];
				if(!uni.same(e.u,e.v)){
					uni.unite(e.u,e.v);
					maxc = max(maxc,e.cost);
					minc = min(minc,e.cost);
				}
			}
			diff_min = maxc-minc;
			bool spanning = true;
			int common_par;
			REP(j,n){
				if(!j){
					common_par = uni.find(uni.par[j]);
				}else{
					if(common_par != uni.find(uni.par[j])){
						spanning = false;break;
					}
				}
			}
			if(spanning)ans = min(ans,diff_min);
		}
		if(ans == INF)cout << -1 << endl;
		else cout << ans << endl;
	}
  return 0;
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll<<60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int i, o, t, j, l, s, z;
    cin >> i >> o >> t >> j >> l >> s >> z;
    int ans = 0;
    ans += 2 * o;
    // ans += 4 * (i / 2 + j / 2 + l / 2);
    // if (i % 2 && j % 2 && l % 2) ans += 6;

    int A = 4 * (i / 2 + j / 2 + l / 2);
    if (i > 0 && l > 0 && j > 0) {
        i--; j--; l--;
        chmax(A, 4 * (i / 2 + j / 2 + l / 2) + 6);
    }
    ans += A;

    cout << ans / 2 << endl;
}


Measured memory_bytes: 384
#include <stdio.h>          // printf(), scanf()
#include <ctype.h>          // isdigit()
#include <stdbool.h>

int
main(int argc, char** argv)
{
	int x;
	int c;

	while (true)
	{
		x = 0;
		c = getc(stdin);
		while (isdigit(c))
		{
			x += c - '0';
			c = getc(stdin);
		}

		if (x == 0 || c == EOF)
			break;

		printf("%d\n", x);
	}

	return 0;
}

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

bool a[1000001];

int main()
{
    int s,i=1;
    cin>>s;
    while(!a[s])
    {
        a[s]=1;
        if(s%2==0) s/=2;
        else s= s*3 +1;
        i++;
    }
    cout<<i<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()

ans_array = [0] * (N+1)

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            d = x * x + y * y + z * z + x * y + y * z + z * x
            if d <= N:
                ans_array[d] += 1


for i in range(N):
    print(ans_array[i+1])


Measured memory_bytes: 69180
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    int n,nu;
    cin >> n;
    if(n%2==1) nu = (n+1)/2;
    else    nu=n/2;
    printf("%.8lf",(double)nu/n);
}

Measured memory_bytes: 256