akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
 
int main(int argc, char *argv[]) {
  using namespace std;
  int64_t a, b, c;
  cin >> a >> b >> c;
  int64_t ans = 0;
  if ((a * b * c) & 1) {
    ans = min(a * b, min(b * c, c * a));
  } else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>

#define INF 1050000000
#define MOD 1000000007

using namespace std;


int main() {
	int k, t; cin >> k >> t;
	int a[100];
	int Max = 0;
	for (int i = 0; i < t; i++) {
		cin >> a[i];
		int tmp = a[i];
		Max = max(Max, tmp);
	}

	cout << max(2 * Max - k - 1, 0) << endl;

}

Measured memory_bytes: 384
@arr = {}
def nCk(v)
  return @arr[v] unless @arr[v].nil?
  @arr[v] = v * (v-1)/2
  return @arr[v]
end


n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
sum = 0
hash = a.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h
hash.each do |k, v|
  sum += nCk(v)
end
n.times do |i|
  puts sum - hash[a[i]] + 1
end

Measured memory_bytes: 59140
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}
 
/*
正面衝突の場合 U-D, L-R
斜め衝突の場合 U-L, L-D, D-R, R-U
 
 
 
 
 
*/
 
 
int x_in[200050], y_in[200050];
char c_in[200050];
vector<pair<int, char>> ur[400020];
vector<pair<int, char>> ud[400020];
 
int n;
 
int solve_UD(){
    rep(i, 400020){
        ud[i].clear();
    }
    rep(i, n){
        if (c_in[i] != 'U' && c_in[i] != 'D') continue;
        ud[x_in[i]].push_back(make_pair(y_in[i], c_in[i]));
    }
    int tmin = 2000001;
    rep(i, 400020){
        sort(ud[i].begin(), ud[i].end());
        rep(j, ud[i].size()-1){
            if (ud[i][j].second == 'U' && ud[i][j+1].second == 'D'){
                tmin = min(tmin, ud[i][j+1].first - ud[i][j].first);
            }
        }
    }
    return tmin * 5;
}
 
int solve_UR(){
    rep(i, 400020){
        ur[i].clear();
    }
    rep(i, n){
        if (c_in[i] != 'U' && c_in[i] != 'R') continue;
        ur[x_in[i]+y_in[i]].push_back(make_pair(x_in[i], c_in[i]));
    }
    int tmin = 2000001;
    rep(i, 400020){
        sort(ur[i].begin(), ur[i].end());
        rep(j, ur[i].size()-1){
            if (ur[i][j+1].second == 'U' && ur[i][j].second == 'R')
            tmin = min(tmin, ur[i][j+1].first - ur[i][j].first);
        }
    }
    return tmin*10;
}
 
void rotate(){
    int tmp;
    rep(i, n){
        tmp = x_in[i];
        x_in[i] = 200000-y_in[i];
        y_in[i] = tmp;
        if (c_in[i] == 'U') c_in[i] = 'L';
        else if (c_in[i] == 'L') c_in[i] = 'D';
        else if (c_in[i] == 'D') c_in[i] = 'R';
        else c_in[i] = 'U';
    }
    
}
 
 
int main()
{
    cin >> n;
    rep(i, n){
        cin >> x_in[i] >> y_in[i] >> c_in[i];
    }
 
    int t_time = 2000001;    
    rep(t, 4){
        t_time = min(t_time, solve_UD());
        t_time = min(t_time, solve_UR());
        rotate();
    }
 
    if (t_time == 2000001) cout << "SAFE" << endl;
    else cout << t_time << endl;
 
}
 

Measured memory_bytes: 36868
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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


int main(){
  int n, a;
  cin >> n >> a;
  if (n % 500 <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }


}


Measured memory_bytes: 256
function main(input) {
    var s = input[1].split(" ");
    var ans = true;
    var map = {};
    s.forEach(v=>{
        if(map[v]) ans = false;
        map[v] = true;
    })
    console.log(ans?"YES":"NO");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 68800
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    ll b[n];
    for(int i=0;i<n;i++)cin>>b[i];
    ll c[n-1];
    for(int i=0;i<n-1;i++)cin>>c[i];
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=b[i];
    }
    for(int i=0;i<n-1;i++){
        if(a[i+1]==a[i]+1)sum+=c[a[i]-1];
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  int h,ph;
  int ans = 0;
  for(int i = 0;i<N;i++){
    scanf("%d",&h);
    if(i != 0){
      if(ph>h){
        ans += ph-h;
      }
    }
    if(i == N-1){
      ans += h;
    }
    ph = h;
  }

  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <map>
#include <cmath>
#include <vector>

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

typedef unsigned long long ull;
typedef long long ll;
using namespace std;

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

    double coordinates[n][d];
    rep(i, n) {
        rep(j, d) {
            cin >> coordinates[i][j];
        }
    }

    int count = 0;
    rep(i, n) {
        for (int j = i+1; j < n; j++) {
            double sum = 0;
            rep(k, d) {
                // cout << abs(coordinates[i][k] - coordinates[j][k]) << endl;
                sum += abs(coordinates[i][k] - coordinates[j][k]) * abs(coordinates[i][k] - coordinates[j][k]);
            }
            double check = sqrt(sum);
            if (ceil(check) == floor(check))
            {
                /* code */
                count++;
                // cout << "c = " << count << endl;
            }
        }
    }
    
    cout << count << endl;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    int a[n][n];
    forn(i,n) forn(j,n) cin>>a[i][j];
    vector<ll> dp(1<<n);
    forn(i,1<<n){
        forn(j,n){
            if(i>>j&1){
                forn(k,j){
                    if(i>>k&1){
                        dp[i]+=a[j][k];
                    }
                }
            }
        }
    }
    forn(i,1<<n){
        for(int j=i;j;j=(j-1)&i){
            dp[i]=max(dp[i],dp[j]+dp[j^i]);
        }
    }
    cout<<dp[(1<<n)-1];
    return 0;
}



Measured memory_bytes: 3720
#include <iostream>
using namespace std;
const int Mod = 1000000007;
class mll {
public:
	long long x;
	mll(long long x = 0) : x((x% Mod + Mod) % Mod) {};
	void operator *= (const mll& a) {
		(x *= a.x) %= Mod;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	if (abs(N - M) > 1) cout << 0 << endl;
	else {
		mll ans = 1;
		for (int i = 2; i <= N; i++) ans *= i;
		for (int i = 2; i <= M; i++) ans *= i;
		if (N == M) ans *= 2;
		cout << ans.x << endl;
	}
}


Measured memory_bytes: 256
n = int(input())
D = {}
a ,b , c, d, e, f, g, h, i, j = 'a','b','c','d','e','f','g','h','i','j'
D[10] = [a,b,c,d,e,f,g,h,i,j]

def output(str_n1):
    num = len(set(str_n1))
    return D[10][0:num+1]

def plus1(moji):
    b = []
    for i in moji:
        d = output(i)
        # print(i)
        for j in d:
            a = []
            a.extend(i)
            a.append(j)
            b.append(a)
    return b

s = 'a'
dic = {}
dic[0] = s
for i in range(10):
    dic[i+1] = plus1(dic[i])

for j in dic[n-1]:
    print(''.join(j))


Measured memory_bytes: 177476
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n, a, b;
    cin >> n >> a >> b;
    
    int i, sum = 0;
    for(i = 1; i <= n; i++){
        int ds = i%10 + (i/10)%10 + (i/100)%10 + (i/1000)%10 + i/10000;
        if( (ds >= a) && (ds <= b))sum += i;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	
	int n,i;
	int a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=n-1;i>=0;i--){
		printf("%d",a[i]);
		if(i!=0)printf(" ");
	}
	printf("\n");
	
	return 0;
}


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

typedef long long ll;

int N;

ll unit(ll x,ll k)
{
    if(x % k == 0)return x / k;
    ll xx = (x / k) * k;
    x = xx + (x - xx) % ((x / k) + 1);
    if(x % k == 0)return x / k;
    return unit(x - (x / k) - 1,k);
}

int main()
{
    scanf("%d",&N);
    ll mem = 0;
    for(int i = 0; i < N; i++)
    {
        ll x,k;
        scanf("%lld%lld",&x,&k);
        mem ^= unit(x,k);
    }
    if(mem)printf("Takahashi\n");
    else printf("Aoki\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt(), w = sc.nextInt();

        int[][] a = new int[h][w];
        for(int i = 0; i < h; i++){
            String s = sc.next();
            for(int j = 0; j < w; j++){
                if(s.charAt(j) == '.') a[i][j] = 0;
                else a[i][j] = 1; 
            }
        }
        for(int i = 0;  i < h; i++){
            int tmp = 0;
            for(int j = 0; j < w; j++){
                tmp += a[i][j];
            }
            if(tmp == 0){
                for(int k = i; k < h-1; k++){
                    for(int j = 0; j < w; j++){
                        a[k][j] = a[k+1][j];
                    }
                }
                h--;
                i--;
            }
        }
        for(int j = 0; j < w; j++){
            int tmp = 0;
            for(int i = 0; i < h; i++){
                tmp += a[i][j];
            }
            if(tmp == 0){
                for(int k = j; k < w-1; k++){
                    for(int i = 0; i < h; i++){
                        a[i][k] = a[i][k+1];
                    }
                }
                w--;
                j--;
            }
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(a[i][j] == 0)
                    System.out.print(".");
                else
                    System.out.print("#");
            }
            System.out.print("\n");
        }
    }
 }




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

#define MAX_N 5003

int n ,k;
int a[MAX_N];

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);
    sort(a ,a+n);
    n = lower_bound(a ,a+n ,k)-a;

    int ans = n;
    bitset <MAX_N> bs[n+1]; bs[n][0] = 1;
    for(int i=n-1; ~i; i--)
        bs[i] = bs[i+1]|(bs[i+1]<<a[i]);
    bitset <MAX_N> pref; pref[0] = 1;
    for(int i=0; i<n; i++){
        auto&suff = bs[i+1];
        for(int l=k-1 ,j=0; j<k; j++) if(suff[j]){
            for(l = min(l ,k-j-1); l >= max(0 ,k-a[i]-j); l--)
                if(pref[l]){
                    ans--;
                    goto NECC;
                }
        }

        NECC:
        pref |= (pref<<a[i]);
    }

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


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

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

    int ans = 0;
    int a[3];
    for (int i = 1; i < (n-1); i++) {
        if ( p[i] < p[i-1] && p[i] > p[i+1]) {
            ans++;
        } else if (p[i] > p[i-1] && p[i] < p[i+1]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    X = int(buflist[1])
    iblu = []
    for i in range(N):
        buf = input()
        buflist = buf.split()
        iblu.append((i, int(buflist[0]), int(buflist[1]), int(buflist[2])))
    aoki_score = 0
    takahashi_score = 0
    for x in iblu:
        aoki_score += x[1] * x[2]
    score_gain = []
    for x in iblu:
        score_gain.append((x[0], X * x[3] - x[1] * (x[3] - x[2])))
    score_gain.sort(reverse=True, key=lambda x: x[1])
    study_hour = 0
    for i, x in enumerate(score_gain):
        new_takahashi_score = takahashi_score + x[1]
        if new_takahashi_score < aoki_score:
            study_hour += X
            takahashi_score = new_takahashi_score
        else: # new_takahashi_score >= aoki_score
            score_needed = aoki_score - takahashi_score
            study_minimum = X
            for j in range(i, N):
                penalty = iblu[score_gain[j][0]][1] * (iblu[score_gain[j][0]][3] - iblu[score_gain[j][0]][2])
                st = min(math.ceil(score_needed / iblu[score_gain[j][0]][2]), math.ceil((score_needed + penalty) / iblu[score_gain[j][0]][3]))
                if st < study_minimum:
                    study_minimum = st
            for j in range(i):
                score_needed = aoki_score - new_takahashi_score + score_gain[j][1]
                penalty = iblu[score_gain[j][0]][1] * (iblu[score_gain[j][0]][3] - iblu[score_gain[j][0]][2])
                st = min(math.ceil(score_needed / iblu[score_gain[j][0]][2]), math.ceil((score_needed + penalty) / iblu[score_gain[j][0]][3]))
                if st < study_minimum:
                    study_minimum = st
            #penalty = iblu[x[0]][1] * (iblu[x[0]][3] - iblu[x[0]][2])
            #study_hour += min(math.ceil(score_needed / iblu[x[0]][2]), math.ceil((score_needed + penalty) / iblu[x[0]][3]))
            #takahashi_score += iblu[x[0]][2] * math.ceil(score_needed / iblu[x[0]][2]) if math.ceil(score_needed / iblu[x[0]][2]) < math.ceil((score_needed + penalty) / iblu[x[0]][3]) else iblu[x[0]][3] * math.ceil((score_needed + penalty) / iblu[x[0]][3]) - penalty
            study_hour += study_minimum
            takahashi_score = new_takahashi_score
        if takahashi_score >= aoki_score:
            break
    print(study_hour)


if __name__ == '__main__':
    main()


Measured memory_bytes: 36516
#include <stdio.h>

int main(int argc, const char * argv[]) {
        char number[1001];
        int i, sum;
        while(1){
            scanf("%s", number);
            if(number[0]=='0'){
               break;
            }
            sum=0;
            for(i=0;number[i]!='\0';i++){
                sum+=number[i]-'0';
            }
            printf("%d\n", sum);
        }
        
        return 0;
    }

Measured memory_bytes: 536
N, M = map(int, input().split())
voya = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    voya[a-1].append(b-1)
    voya[b-1].append(a-1)

for i in voya[0]:
    if N-1 in voya[i]:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 38396
#include<stdio.h>

int main()
{
    int h = 3600;
    int m = 60;
    int s;

    scanf("%d", &s);

    printf("%d:", s/h);
    s = s % h;

    printf("%d:", s/m);
    s = s % m;

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

    return 0;
}



Measured memory_bytes: 2048
/*
author : seryu
title : contest
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
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; }
ll MOD = 1000000007;
int INF = 1001001001;

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

void solve()
{
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	rep(i, h)rep(j, w)
	{
		if(s[i][j] == '.')continue;
		bool ok = false;
		rep(k, 4)
		{
			int ny = i+dy[k]; 
			int nx = j+dx[k]; 
			if(0 <= ny && ny < h &&
			0 <= nx && nx < w && s[ny][nx] == '#')ok = true;
		}
		if(!ok)
		{
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
vector <int> edges[100000];
int aoki_d[100000];
int tak_d[100000];
bool marked[100000];
bool can_be_reached[100000];
int main(){
  int N;
  int u;
  int v;
  cin >> N >> u >> v;
  for(int i = 0; i < N - 1; i++){
    int A;
    int B;
    cin >> A >> B;
    edges[A - 1].push_back(B - 1);
    edges[B - 1].push_back(A - 1);
  }



  //aoki bfs
  queue <pair<int, int> > q;
  q.push(make_pair(v - 1, -1));
  marked[v - 1] = true;
  while(!q.empty()){
    auto p = q.front();
    int cur = p.first;
    aoki_d[cur] = 1 + p.second;
    q.pop();
    for(int i = 0; i < edges[cur].size(); i++){
      int next = edges[cur][i];
      if(!marked[next]){
        marked[next] = true;
        q.push(make_pair(next, aoki_d[cur]));
      }
    }
  }

  for(int i = 0; i < N; i++){
    marked[i] = false;
  }
  q.push(make_pair(u - 1, -1));
  marked[u - 1] = true;
  while(!q.empty()){
    auto p = q.front();
    int cur = p.first;
    tak_d[cur] = 1 + p.second;
    q.pop();
    if(tak_d[cur] >= aoki_d[cur]){
      can_be_reached[cur] = false;
    } else {
      can_be_reached[cur] = true;
      for(int i = 0; i < edges[cur].size(); i++){
        int next = edges[cur][i];
        if(!marked[next]){
          marked[next] = true;
          q.push(make_pair(next, tak_d[cur]));
        }
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    if(can_be_reached[i]){
      ans = max(ans, aoki_d[i] - 1);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>

int main(void)
{
	unsigned char tbl[256], str[1201], n;
	int i;

	for (i = 0; i < 256; i++) {
		tbl[i] = i;
	}
	for (i = 0; i <= 26; i++) {
		tbl['a' + i] = 'A' + i;
		tbl['A' + i] = 'a' + i;
	}
	scanf("%[^\n]", str);
	for (i = 0; str[i] != '\0'; i++) {
		printf("%c", tbl[str[i]]);
	}
	puts("");
	return 0;
}



Measured memory_bytes: 2104
X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort()
P = P[:X]
Q = Q[:Y]
S = []
#print(P,Q,S)
for _ in range(X+Y):
    if len(R) == 0:
        break
    s = R[-1]
    if len(P) == 0:
        p = 1000000000000000
    else:
        p = P[-1]
    if len(Q) == 0:
        q = 1000000000000000
    else:
        q = Q[-1]
    #print(p,q,s)
    if p >= q:
        if q < s:
            del Q[-1]
            del R[-1]
            S.append(s)
        else:
            break
    else:
        if p < s:
            del P[-1]
            del R[-1]
            S.append(s)
        else:
            break
    #print(P,Q,S)
ans = 0
for i in P:
    ans += i
for i in Q:
    ans += i
for i in S:
    ans += i
print(ans)

Measured memory_bytes: 22720
#include<bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int L=gi(),R=gi(),ans=2019;
	R=std::min(R,L+2019*2);
	for(int i=L;i<=R;++i)
		for(int j=i+1;j<=R;++j)
			ans=std::min(0ll+ans,1ll*i*j%2019);
	printf("%d\n",ans);
	return 0;
}



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

int main() {
  string S;
  cin >> S;
  
  int count = 0;
  int saidai = 0;
  for( int i = 0; i < S.size(); i++ ){
    if( S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'C' || S.at(i) == 'G' ){
      count++;
      if( count > saidai ) saidai = count;
    }else{
      count = 0;
    }
  }
  cout << saidai << endl;
  
}


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

using namespace std;
const long long INF = 1LL <<60;

int main(void){
  int N,rst;
  cin >>N;
  long a[N+1],b[N+1],c[N+1];
  long dp[N+1][3];
  int i,j,k;
 
  for(i=0;i<3;i++){
    dp[0][i]=0;
  }
  for(i=1;i<N+1;i++){
    cin>>a[i]>>b[i]>>c[i];
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b[i];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    //cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
  }
  
  rst=max(dp[N][0],max(dp[N][1],dp[N][2]));
  
  cout<<rst<<endl;
  
  return 0;
}
  

  

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,q,cnt = 0;
    cin >> n;
    vll s(n);
    rep(i,n)cin >> s[i];
    cin >> q;
    rep(i,q){
        ll t;
        cin >> t;
        if(binary_search(s.begin(), s.end(), t))cnt++;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3504
use itertools::Itertools;

fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        q: usize,
        xs: [(usize,usize,usize,i32); q],
    }
    let score = |arr:Vec<_>| {
        xs.iter()
        .map(|(a,b,c,d)|{ if arr[*b-1] - arr[*a-1] == *c { *d } else { 0 } })
        .sum::<i32>()
    };
    let res = (1..m+1)
                .combinations_with_replacement(n)
                .map(score)
                .max()
                .unwrap();
    println!("{:?}", res);
}

Measured memory_bytes: 2196
x,y=map(int,input().split())

ans=10**10

if x<=y: ans=min(ans,y-x)
if -x<=y: ans=min(ans,y+x+1)
if x<=-y: ans=min(ans,-y-x+1)
if -x<=-y: ans=min(ans,-y+x+2)

print(ans)


Measured memory_bytes: 3064
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m,v,p = inpl()
a = inpl()
c = Counter(a)
a.sort()
b_num = a[n-p]
d_cnt = 0
b_cnt = 0
u_cnt = 0
for i in a:
    if i < b_num: d_cnt += 1
    elif i == b_num: b_cnt += 1
    else: u_cnt += 1

def f(x,i):
    if x >= b_num:
        return True
    if x + m < b_num:
        return False
    if i + 1 + u_cnt >= v:
        return True
    cnt = 0
    for item in a:
        if item > b_num or item <= x:
            cnt += m
        else:
            cnt += x + m - item
    # print(cnt)
    if cnt >= m*v:
        return True
    else:
        return False
# print(f(a[2],2))
ok = n
ng = -1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if f(a[mid],mid):
        ok = mid
    else:
        ng = mid
print(n-ng-1)


Measured memory_bytes: 96200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    double n, k;
    cin >> n >> k;

    double ans = 0;
    for (ll in = 1; in <= n; in++) {
        double tmp = 1.0 / n;
        if (in < k) {
            for (ll i = 1; i < log2(k/in) + 1; i++) tmp /= 2;
        }
        ans += tmp;
    }

    cout.precision(20);
    cout << ans << endl;
}

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

#define maxn 10005
#define INF 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
using namespace std;

int N, M, a[maxn];

void slove()
{
	int sum = 0, cnt = 0;
	cin >> N >> M;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		sum += a[i];
	}

	double k = sum * (1.0 / (4 * M));
	for (int i = 0; i < N; i++)
	{
		if (a[i] >= k) cnt++;
	}
	if (cnt >= M) cout << "Yes";
	else cout << "No";
}

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

	/*while (cin >> t)*/
	slove();

	return 0;
}

Measured memory_bytes: 256
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = []
if N == 1:
    for i in range(0, 10 ** N):
        ii = str(i)
        p = 0
        for l in sc:
            if int(ii[l[0] - 1]) != l[1]:
                p = 1
        if p == 0:
            ans.append(i)
    if len(ans) == 0:
        print(-1)
        sys.exit()
    print(min(ans))

else:
    for i in range(10 ** (N - 1), 10 ** N):
        ii = str(i)
        p = 0
        for l in sc:
            if int(ii[l[0] - 1]) != l[1]:
                p = 1
        if p == 0:
            ans.append(i)
    if len(ans) == 0:
        print(-1)
        sys.exit()
    print(min(ans))



Measured memory_bytes: 5332
#include <iostream>

using namespace std;

int main(){
	int A, B, C, D;
	int a, b;
	cin >> A >> B >> C >> D;
	if (A < B){
		a = A;
	}
	else {
		a = B;
	}
	if (C < D){
		b = C;
	}
	else {
		b = D;
	}
	
	cout << a + b << endl;
	
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h1,m1,h2,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  int x=h2*60-h1*60+m2-m1;
  cout<<x-k<<endl;

}

Measured memory_bytes: 3584
n,k = gets.chomp.split().map(&:to_i)
a = gets.chomp.split().map(&:to_i)

i = 0
for i in 0..(n-k-1)
    if a[i] < a[i+k]
        print "Yes\n"
    else
        print "No\n"
    end
end


Measured memory_bytes: 36008
fn main() {
    let K: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned().parse::<usize>().unwrap()
    };
    let v = vec![1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
    print!("{}", v[K-1]);
}

Measured memory_bytes: 4352
def geti; gets.to_i end
def getis; gets.split.map &:to_i end
def getin n;  n.times.map{geti}  end
def getisn n; n.times.map{getis} end
YES = "YES"; NO = "NO"; Yes = "Yes"; No = "No";

s = gets.chomp
t = gets.chomp

puts s.chars.sort.join < t.chars.sort.reverse.join ?  "Yes" : "No"

__END__
a,b=getis
p (a+b+1)/2

n,a,b=getis
puts (1..n).select{|s| c=s.to_s.chars.map(&:to_i).reduce(:+); a<=c&&c<=b }.reduce(:+)

a,b,c,d=getis
puts %w(Balanced Left Right)[a+b<=>c+d]

puts (gets.sub(?\s,'').to_i**0.5)%1==0? "Yes" : "No"

a,b=getis
puts a*b%2==0? "Even" : "Odd"


Measured memory_bytes: 1788
import math

n = int( input() )
x = [ float( val ) for val in input().split( ' ' ) ]
y = [ float( val ) for val in input().split( ' ' ) ]

Dxy = Dxy2 = Dxy3 = Dxyp = 0
for i in range( n ):
	t = abs(x[i]-y[i])
	Dxy += t
	Dxy2 += t**2
	Dxy3 += t**3
	Dxyp = max( Dxyp, t )
print( Dxy )
print( Dxy2**(1/2) )
print( Dxy3**(1/3) )
print( Dxyp )



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

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

    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            double kyori = 0;
            for (int k = 0; k < D; k++) {
                kyori += abs(X[i][k] - X[j][k]) * abs(X[i][k] - X[j][k]);
            }
            if (sqrt(kyori) == ceil(sqrt(kyori))) ans++;
        }
    }
    cout << ans / 2 << endl;
}

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

int main(){
	int ans[4] = {0};
	char blood[2];
	int gar;
	char garb;

	while(cin >> gar >> garb >> blood){
		if(blood[0] == 'A'){
			if(blood[1] == 'B') ans[2]++;
			else ans[0]++;
		}
		if(blood[0] == 'B') ans[1]++;
		if(blood[0] == 'O') ans[3]++;
	}
	for(int i = 0; i < 4; i++){
		cout << ans[i] << endl;
		ans[i] = 0;
	}
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  int s=(a[2]-a[1]);
  int t=(a[2]-a[0]);
  //cout<<s<<" "<<t<<endl;
  if((s%2&&t%2)||(!(s%2)&&!(t%2)))cout<<(s+t)/2<<endl;
  else cout<<(s+t+1)/2+1<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
List = []

for i in range(N):
  A,B = map(str,input().split(' '))
  P = int(B)
  List.append((i,A,P))

sorted_list = sorted(List,key=lambda x:(x[1],-x[2]))

X = []
for j,b in enumerate(sorted_list):
  X.append((j+1,b))
Y = sorted(X,key=lambda x:x[1][0])
Z = []
for i,b in enumerate(Y):
  Z.append((i+1,b))
Z_sort = sorted(Z,key=lambda x:x[1][0])

for i in Z_sort:
  print(i[0])
  

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

#define ll long long int
#define hell 1000000007
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

void solve()
{
    ll a;
    string s;
    cin>>a>>s;
    if(a>=3200)
        cout<<s;
    else
        cout<<"red";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		String word[] = new String[n];
		for (int i = 0; i < n; i++) {
			word[i] = sc.next();
		}
		Arrays.sort(word);
		String ans = "";
		for (int i = 0; i < n; i++) {
			ans += word[i];
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 24660
#include <stdio.h>

int main(void){
  char c;
  scanf("%c",&c);

  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    printf("vowel\n");
  }else{
    printf("consonant\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, x;
    cin >> n >> x;
    vint a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    int ans = 0;
    rep(i, n) {
        if (x >= a[i]) {
            ans++;
            x -= a[i];
            if (i == n-1 && x > 0) ans--;
        }
        else break;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define INF (1LL<<62)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef tuple<long double,int,int> tdii;
const double PI = atan(1)*4;
const int MAXN = 1e2 + 10;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int n, k;
int dp[100005];
int moves[MAXN];

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout << setprecision(20)<< fixed;
    cin>>n>>k;
    forn(i,n){
        cin>>moves[i];
        dp[moves[i]]=1;
    }
    dp[0]=-1;
    for1(i,moves[0]-1){
        dp[i]=-1;
    }
    fore(i, moves[0]+1, k){
        if(dp[i]==0){
            forn(j,n){
                if(i-moves[j]>=0){
                    if(dp[i-moves[j]] == -1){
                        dp[i]=1;
                        break;
                    }
                }
                if(j==n-1) dp[i]=-1;
            }
        }
    }
    if(dp[k]==1) cout<<"First"<<el;
    else cout<<"Second"<<el;
}


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

ll n;
vector <ll> v(1LL << 18, 0), w(1LL << 18, 0);
vector < vector<ll> > dp(1LL << 9, vector <ll> (100001, 0));

int main()
{
    // Fast_IO();
    cin >> n;
    f(i,1,n) cin >> v[i] >> w[i];
    f(node,1,min(n, (1LL << 9) - 1)) f(weight,1,100000) {
    	dp[node][weight] = max(dp[node][weight], dp[node >> 1][weight]);
    	if(weight >= w[node]) dp[node][weight] = 
    	max(dp[node][weight], v[node] + dp[node >> 1][weight - w[node]]);
    }
    ll q; cin >> q; while(q--)
    {
    	ll x, L; cin >> x >> L;
    	if(x < (1LL << 9)) cout << dp[x][L] << endl;
    	else {
    		ll level = (ll)log2(x) + 1;
    		vector < pair<ll,ll> > perm;
    		while(level > 9) {
    			perm.pb(mp(v[x],w[x]));
    			x >>= 1; level--;
    		}
    		ll N = sz(perm), ans = dp[x][L];
    		f(mask,1,(1LL << N)-1) {
    			ll _L = L, this_ans = 0;
    			f(i,0,N-1) if(mask & (1LL << i)) 
    			this_ans += perm[i].ff, _L -= perm[i].ss;
    			if(_L < 0) continue;
    			ans = max(ans, this_ans + dp[x][_L]);
    		}
    		cout << ans << endl;
    	}
    }
    return 0;
}

Measured memory_bytes: 409372
n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n-i+1):
        if y == 10000*i + 5000*j + 1000*(n-i-j):
            print(i, j, n-i-j)
            exit()

print("-1 -1 -1")


Measured memory_bytes: 2940
use proconio::input;

fn main() {
  input! {
    s: String
  }
  let origin = s.len();
  let mut s: Vec<char> = s.chars().collect::<Vec<char>>();
  
  let mut result = 0;
  let mut stack: Vec<char> = vec![s.remove(0)];
  
  while !s.is_empty() {
    let next = s.remove(0);
    if stack.is_empty() {
      stack.push(next);
    } else if stack.last().unwrap() != &next {
      stack.pop();
    } else {
      stack.push(next);
    }
  }
  println!("{}", origin - stack.len());
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int a,b; cin >> a >> b;
    if(a<=9&&b<=9){
        cout << a*b << endl;
    }else{
        cout << -1 << endl;
    }
    
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os

for s in sys.stdin:
    N = int(s)
    if N == 0:
        break

    A = []
    for i in range(N):
        lst = list(map(int, input().split()))
        id = lst[0]
        data = lst[1:]
        time_sum = data[0] * 60 + data[1] + \
                   data[2] * 60 + data[3] + \
                   data[4] * 60 + data[5] + \
                   data[6] * 60 + data[7]
        A.append((time_sum, id))
    A.sort()

    print(A[0][1])
    print(A[1][1])
    print(A[-2][1])

Measured memory_bytes: 8204
import java.util.*;

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

        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();

        int distanceX = tx - sx;
        int distanceY = ty - sy;
        StringBuilder sb = new StringBuilder();
        // firtst Going
        for(int i = 0; i < distanceY ; i++){
            sb.append("U");
        }
        for(int i = 0; i < distanceX ; i++){
            sb.append("R");
        }
        // firtst Return
        for(int i = 0; i < distanceY ; i++){
            sb.append("D");
        }
        for(int i = 0; i < distanceX ; i++){
            sb.append("L");
        }

        // second Going
        sb.append("L");
        for(int i = 0; i < distanceY + 1 ; i++){
            sb.append("U");
        }
        for(int i = 0; i < distanceX + 1 ; i++){
            sb.append("R");
        }
        sb.append("D");

        // second Return
        sb.append("R");
        for(int i = 0; i < distanceY + 1 ; i++){
            sb.append("D");
        }
        for(int i = 0; i < distanceX + 1 ; i++){
            sb.append("L");
        }
        sb.append("U");

        // result
        System.out.println(sb.toString());

    }

}

Measured memory_bytes: 24020
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
   //TLE guchokuyotei
   long long a,b,c,d;
   long long count=0;
   cin>>a>>b>>c>>d;
   
   cout<<(b-(b/c+b/d)+b/(c*d/gcd(c,d)))-((a-1)-((a-1)/c+(a-1)/d)+(a-1)/(c*d/gcd(c,d)))<<endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int h[100100][3];
int dp[100100][3];

int solve() {
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i-1][k]+h[i-1][j]);
            }
        }
    }
    return max(dp[n][0], max(dp[n][1], dp[n][2]));
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) cin >> h[i][j];
    }
}

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

    input();
    cout << solve() << endl;
}


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

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

using namespace std;
using ll = long long;

int main(){
	int n; cin >> n;
	vector<int> a(n - 1);
	vector<int> ans(n);
	rep(i, n - 1) cin >> a[i];

	rep(i, n - 1){
		ans[a[i] - 1]++;
	}

	rep(i, n) cout << ans[i] << endl;

	return 0;
}

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

int main()
{
    long long n;
    cin>>n;
    long long a=n;
    long long sum=0;
    while(a>0)
    {
        sum+=(a%10);
        a/=10;
    }
    if(n%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define FOREACH(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); ++i)

#define MAXN 1500
#define MAXM 1500

using namespace std;


int h[MAXN], w[MAXM];
int hsum[MAXN+1], wsum[MAXM+1];
vector<int> h2, w2;

int main()
{
    while (true) {
        int n, m;
        scanf("%d %d", &n, &m);
        if (n == 0) break;
        h2.clear(); w2.clear();
        hsum[0] = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d", &h[i]);
            hsum[i+1] = hsum[i] + h[i];
        }
        wsum[0] = 0;
        for (int i = 0; i < m; i++) {
            scanf("%d", &w[i]);
            wsum[i+1] = wsum[i] + w[i];
        }
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j <= n; j++) {
                h2.push_back(hsum[j] - hsum[i]);
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = i + 1; j <= m; j++)
                w2.push_back(wsum[j] - wsum[i]);
        }

        map<int, int> hc, wc;
        set<int> l;
        FOREACH(it, h2) {
            l.insert(*it);
            if (hc.find(*it) == hc.end())
                hc[*it] = 1;
            else
                hc[*it]++;
        }
        FOREACH(it, w2) {
            l.insert(*it);
            if (wc.find(*it) == wc.end())
                wc[*it] = 1;
            else
                wc[*it]++;
        }
        int result = 0;
        FOREACH(it, l) {
            if (hc.find(*it) != hc.end() && wc.find(*it) != wc.end()) {
                result += hc[*it] * wc[*it];
            }
        }
        printf("%d\n", result);
    }
}

Measured memory_bytes: 59544
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

string A,B,C;
int main(){
    cin>>A>>B>>C;
    int flag = 1;
    char now=A[0];
    int cnta=1,cntb=0,cntc=0;
    while(1){
        if(now=='a'){
            if(cnta==A.size()){
                printf("A\n");
                break;
            }
            else now=A[cnta++];
        }
        if(now=='b'){
            if(cntb==B.size()){
                printf("B\n");
                break;
            }
            else now=B[cntb++];
        }
        if(now=='c'){
            if(cntc==C.size()){
                printf("C\n");
                break;
            }
            else now=C[cntc++];
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int ss[100005];

int min(int a, int b){ return a < b ? a : b; }

int main(){
    int N;
    scanf("%d", &N);
    for(int i=1; i<N; i++){
        int tmp = i;
        while(tmp){
            ss[i] += tmp%10;
            tmp /= 10;
        }
    }
    int res = 1e9;
    for(int i=1; i<N; i++) res = min(res, ss[i]+ss[N-i]);
    printf("%d", res);
    return 0;
}


Measured memory_bytes: 512