akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int a[] = new int[w];
		int b[] = new int[n];
		int c[] = new int[n];
		int temp = 0;
		int i = 0;
		String str;
		for(i=0;i<n;i++){
			str = sc.next();
			String[] bc = str.split(",");
			b[i] = Integer.parseInt(bc[0])-1;
			c[i] = Integer.parseInt(bc[1])-1;
		}
		for(i=0;i<w;i++){
			a[i] = i + 1;
		}
		for(i=0;i<n;i++){
			temp = a[b[i]];
			a[b[i]] = a[c[i]];
			a[c[i]] = temp;
		}
		for(i=0;i<w;i++){
			System.out.println(a[i]);
		}
	}
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = input[0];
            var B = input[1];
            var T = input[2];

            Console.WriteLine((T / A) * B);
        }
    }
}


Measured memory_bytes: 28240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N, A, B;
	cin >> N >> A >> B;
	ll H[100000];
	rep(i, N) cin >> H[i];

	int L = 1, R = 1e9;

	while (L != R) {
		int half = (L + R) / 2;

		ll damage = 1ll * B * half;
		ll cnt = 0;
		rep(i, N) {
			ll kari = (H[i] - damage + A - B - 1) / (A - B);
			if (kari > 0) {
				cnt += kari;
			}
		}
		if (half >= cnt) R = half;
		else L = half + 1;
	}

	co(L);

	Would you please return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int H = scanner.nextInt();
        int W = scanner.nextInt();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < H; i++) {
            list.add(scanner.next());
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (list.get(i).charAt(j) == '#') {
                    System.out.print("#");
                    continue;
                }
                int c = 0;
                if (i > 0 && j > 0 && list.get(i-1).charAt(j-1) == '#') {
                    c++;
                }
                if (i > 0 && list.get(i-1).charAt(j) == '#') {
                    c++;
                }
                if (i > 0 && j < W -1 && list.get(i-1).charAt(j+1) == '#') {
                    c++;
                }

                if (j > 0 && list.get(i).charAt(j-1) == '#') {
                    c++;
                }
                if (j < W -1 && list.get(i).charAt(j+1) == '#') {
                    c++;
                }

                if (i < H -1 && j > 0 && list.get(i+1).charAt(j-1) == '#') {
                    c++;
                }
                if (i < H -1 && list.get(i+1).charAt(j) == '#') {
                    c++;
                }
                if (i < H -1 && j < W -1 && list.get(i+1).charAt(j+1) == '#') {
                    c++;
                }
                System.out.print(c);
            }
            System.out.println("");
        }
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {
                    line = br.readLine();
                }
                s = line.split(reg, 0);
                i = 0;
                return s[i++];
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public int nextInt() {
            try {
                return Integer.parseInt(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public double nextDouble() {
            try {
                return Double.parseDouble(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public long nextLong()  {
            try {
                return Long.parseLong(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
 int n;cin >> n;
 for(int i=1;i<=9;i++){
   for(int j=1;j<=9;j++){
     if(n==i*j){cout << "Yes" << endl;return 0;}
   }
 }
 cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void init(int list[3][10]){
    for(int x = 0;x<3;x++){
        for(int y = 0;y<10;y++){
            list[x][y]=0;
        }
    }
}

void updateDormStatus(int dorm[3][10],int row,int column,int value){
    dorm[row-1][column-1]+=value;
}

void printDorm(int dormA[3][10],int dormB[3][10],int dormC[3][10],int dormD[3][10]){
    for(int x = 0;x<3;x++){
        for(int y = 0;y<10;y++){
            cout<<' ';
            cout<<dormA[x][y];
        }
        cout<<endl;
    }
    for(int k = 0;k<20;k++){
        cout<<'#';
    }
    cout<<endl;
    
    //start B
    
    for(int x = 0;x<3;x++){
        for(int y = 0;y<10;y++){
            cout<<' ';
            cout<<dormB[x][y];
        }
        cout<<endl;
    }
    for(int k = 0;k<20;k++){
        cout<<'#';
    }
    cout<<endl;
    
    for(int x = 0;x<3;x++){
        for(int y = 0;y<10;y++){
            cout<<' ';
            cout<<dormC[x][y];
        }
        cout<<endl;
    }
    for(int k = 0;k<20;k++){
        cout<<'#';
    }
    cout<<endl;
    
    for(int x = 0;x<3;x++){
        for(int y = 0;y<10;y++){
            cout<<' ';
            cout<<dormD[x][y];
        }
        cout<<endl;
    }
    
}

int main(int argc, char **argv)
{
    int dormA[3][10];
    int dormB[3][10];
    int dormC[3][10];
    int dormD[3][10];
    init(dormA);
    init(dormB);
    init(dormC);
    init(dormD);
    
    int recordCount;
    cin>>recordCount;
    
    for(int count = 0; count< recordCount;count++){
        int dormNum,row,column,value;
        cin>>dormNum>>row>>column>>value;
        switch(dormNum){
            case 1:
            updateDormStatus(dormA,row,column,value);
            break;
            case 2:
            updateDormStatus(dormB,row,column,value);
            break;
            case 3:
            updateDormStatus(dormC,row,column,value);
            break;
            case 4:
            updateDormStatus(dormD,row,column,value);
            break;
        }
    }
    
    //printDorm(dormA,dormB,dormC,dormD);
    /*
    for(int x = 0;x<3;x++){
        for(int y = 0;y<10;y++){
            cout<<dormA[x][y];
            cout<<' ';
        }
        cout<<endl;
    }
     * */
    
    printDorm(dormA,dormB,dormC,dormD);
	return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
ll mod=1000000007;
int main(){
    int n=in(),m=in();
    vec a(m);
    vecll dp(n+1);
    rep(i,m){
        a[i]=in();
    }
    int id=0;
    if(id<m){
      if(a[id]==0){
        dp[0]=0;
        id++;
      }
      else{
        dp[0]=1;
      }
    }
    else{
        dp[0]=1;
    }
    if(id<m){
      if(a[id]==1){
        dp[1]=0;
        id++;
      }else{
        dp[1]=1;
      }
    }else{
        dp[1]=1;
    }
    rep2(i,2,n){
        if(id<m){
            if(a[id]==i){
                dp[i]=0;
                id++;
                continue;
            }
        }
        dp[i]=(dp[i-1]+dp[i-2])%mod;
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1408
H = []
N, A, B = map(int, input().split())
for _ in range(N):
    H.append(int(input()))


def ceil(a, b):
    return (a + b - 1) // b


def f(x):
    lst = [max(0, h - x * B) for h in H]
    S = sum(ceil(i, A - B) for i in lst)
    return S <= x


l, r = 0, 10 ** 9
while r - l > 1:
    m = (r + l) // 2
    if f(m):
        r = m
    else:
        l = m
print(r)


Measured memory_bytes: 11036
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mod 1000000007
#define MN 5005
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct edge{
	int to,nxt;
}e[MN<<1];
int h[MN],f[MN][MN],fa[MN],siz[MN],df[MN],t[MN];
int n,x,y,cnt;
inline void ins(int x,int y){
	e[++cnt].to=y;e[cnt].nxt=h[x];h[x]=cnt;
}
inline void dfs(int u){
	siz[u]=f[u][1]=1;
	for (int i=h[u];i;i=e[i].nxt){
		int v=e[i].to;
		if (v==fa[u]) continue;fa[v]=u;dfs(v);
		for (int j=0;j<=siz[u];++j) t[j]=f[u][j],f[u][j]=0;
		for (int j=0;j<=siz[u];++j)
		for (int k=0;k<=siz[v];++k)
		f[u][j+k]=(f[u][j+k]+(1ll*t[j]*f[v][k])%mod)%mod;
		siz[u]+=siz[v]; 
	}
	for (int i=0;i<=siz[u];++i)
	f[u][0]=(f[u][0]+mod-(1ll*f[u][i]*df[i])%mod)%mod;
}
int main()
{
	n=in();df[0]=1;
	for (int i=1;i<n;++i){
		x=in();y=in();
		ins(x,y);ins(y,x);
	}
	for (int i=2;i<=n;i+=2)
	df[i]=(1ll*df[i-2]*(i-1))%mod;dfs(1);
	printf("%d",(mod-f[1][0])%mod);return 0;
}

Measured memory_bytes: 96896
using System.Collections.Generic;
using System.Linq;
using System;

public class C
{
    public const int INF = 999999999;
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var te = new int[n, 3];
            var d = new Dictionary<int, int>();
            var d2 = new Dictionary<int, int>();
            var cnt = 0;
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var a = int.Parse(line[0]);
                var b = int.Parse(line[1]);
                var c = int.Parse(line[2]);
                te[i, 0] = a; te[i, 1] = b; te[i, 2] = c;
                if (!d.ContainsKey(a)) { d[a] = cnt; d2[cnt] = a; cnt++; }
                if (!d.ContainsKey(b)) { d[b] = cnt; d2[cnt] = b; cnt++; }
            }
            var city = d.Count();
            var dp = new int[city, city];
            for (int i = 0; i < city; i++)
                for (int j = 0; j < city; j++)
                    if (i == j) dp[i, j] = 0;
                    else dp[i, j] = C.INF;
            for (int i = 0; i < n; i++)
            {
                dp[te[i, 0], te[i, 1]] = te[i, 2];
                dp[te[i, 1], te[i, 0]] = te[i, 2];
            }
            goWarshall(dp);
            var mincity = -1;  var mintotal = C.INF;
            for (int i = 0; i < city; i++)
            {
                var submin = 0;
                for (int j = 0; j < city; j++)
                    submin += dp[i, j];
                if (submin < mintotal) { mintotal = submin; mincity = i; }
            }
            Console.WriteLine("{0} {1}", mincity, mintotal);
        }
    }
    public static void goWarshall(int[,] dp)
    {
        var n = dp.GetLength(0);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++)
                    dp[j, k] = Math.Min(dp[j, k], dp[j, i] + dp[i, k]);
    }
}

Measured memory_bytes: 10064
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(50, vector<ll>(50, INF));
map<ll, ll> mp;

ll poww(ll a,ll b)
{
	ll prod = 1;
	REP(i,b)
	{
		prod *= a;
		prod %= MOD;
	}
	return prod;
}

int main() {
	cin >> n;
	if(n==1)
	{
		cout << 1 << endl;
		return 0;
	}
	v.resize(n);
	REP(i, n) {
		cin >> v[i];
		mp[v[i]]++;
	}
	bool flg = 0;
	if(n%2)
	{
		if (mp[0] != 1) flg = 1;
		for (ll i=2;i<=n/2+2;i+=2)
		{
			if (mp[i] != 2) flg = 1;
		}
		if (flg)
		{
			cout << 0 << endl;
			return 0;
		}
		else cout << poww(2, n / 2) << endl;
	}
	else
	{
		for(ll i=1;i<=n/2;i+=2)
		{
			if (mp[i] != 2) flg=1;
		}
		if (flg)
		{
			cout << 0 << endl;
			return 0;
		}
		else cout << poww(2, n / 2) << endl;
	}
}

Measured memory_bytes: 5632
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //StringBuilder bd = new StringBuilder();
        ArrayList<String> A = new ArrayList<String>();
        //int[] A = new int[26];
        //Arrays.fill(A, 0);
        //String str;
        int t = 0;
        int h = 0;

        int n = sc.nextInt();

        for (int i=0; i<n; i++) {
            String taro = sc.next();
            String hanako = sc.next();

            if (taro.compareTo(hanako) > 0) t += 3;
            else if (taro.compareTo(hanako) < 0) h += 3;
            else {t += 1; h += 1;}
        }
        System.out.print(t);
        System.out.print(" ");
        System.out.println(h);

    }
}


Measured memory_bytes: 30244
#include <bits/stdc++.h>  
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string, int> P;

int main() {
	int h, w;
	while(scanf("%d %d", &h, &w), h && w) {
		rep(i, h) {
			rep(j, w) {
				if(i == 0 || i == h - 1 || j == 0 || j == w - 1) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

#define MOD 1000000007

int N, T;
int d[111111];
long long ans=1;

int main(){
  cin>>N>>T;
  for(int i=0; i<N; i++)cin>>d[i];
  sort(d, d+N);

  for(int i=1; i<N; i++){
    int cnt=1;
    for(int j=i-1; d[j]>=d[i]-T && j>=0; j--)cnt++;
    ans*=cnt;
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}

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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x) cerr << #x << " = " << (x) << endl;

// template starts
typedef long long int ll;

// template ends here

void solve(){
	// code starts from here
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	
	cout << max({a*c,a*d,b*c,b*d}) << endl;
}

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//startTime = clock();
	
	int T;
	//cin >> T;
	T = 1;
	while(T--){
		solve();
	}
	
	//cout << getCurrentTime() << endl;
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int  main() 
{
	int n,k,x;
	cin>>n>>k;
	int a[200000+5]={0};
	
	for(int i=0;i<n;i++)
	{
		cin>>x;
		a[x]++;
	}
	sort(a+1,a+200000+1,cmp);
	int count=0;
	for(int i=k+1;i<=200000;i++)
	count+=a[i];
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,g,t=0,h,f,l=0,c=0,m;
    double x;
    cin>>n>>m;
    ll a[30][30];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cin>>a[i][j];
        }
    }


    for(int i = 0; i < n; i++)
    {
        //x = 0,c = 0;

        for(int j = i+1; j < n; j++)
        {
            x = 0,c = 0;

            for(int k = 0; k < m; k++)
            {
                x += ((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));
                c += ((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));
            }
            x = sqrt(x);
            c = sqrt(c);
            if(x==c)
            {
                t++;
            }
        }
    }

    cout<<t<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double t = abs(360 / 12 * (H + M / 60)- 360 / 60 * M);
    double ans = sqrt(A * A + B * B - 2 * A * B * cos(acos(-1) * t / 180));
    printf("%.9f\n", ans);
    return 0;
}

Measured memory_bytes: 4252
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
//#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl

void solve()
{
	ll n; cin>>n;
	ll x=1000;
	while(x<n)
	{
		x+=1000;
	} 
	cout<<x-n;
}

int main()
{
	solve();
}
/*




*/


Measured memory_bytes: 3628
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int ans[2][8];

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

  ans[0][0] = 1;
  rep(h, H){
    rep(w, W){
      ans[1][w] = 0;
    }
    rep(id, 1 << (W - 1)){
      int x[9] = {0};
      rep(w, W - 1){
        x[w + 1] = (id >> w) & 1;
      }
      bool f = false;
      rep(w, W - 2){
        if(x[w + 1] && x[w + 2]) f = true;
      }
      if(f) continue;
      rep(w, W){
        if(x[w]){
          ans[1][w] += ans[0][w - 1];
        }else if(x[w + 1]){
          ans[1][w] += ans[0][w + 1];
        }else{
          ans[1][w] += ans[0][w];
        }
        ans[1][w] %= mod;
      }
    }
    rep(w, W){
      ans[0][w] = ans[1][w];
    }
  }
  cout << ans[1][K - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, p[10], q[10];
int a, b;

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(N) {
        cin >> p[i];
    }
    FOR(N) {
        cin >> q[i];
    }

    int cnt = 0;
    vector<int> v(N);
    iota(v.begin(), v.end(), 1);  // v に 1, 2, ... N を設定
    do {
        bool flag1 = true, flag2 = true;
        FOR(i, N) {
            if (v[i] != p[i])
                flag1 = false;
            if (v[i] != q[i])
                flag2 = false;
        }
        if (flag1)
            a = cnt;
        if (flag2)
            b = cnt;
        cnt++;
    } while (next_permutation(v.begin(), v.end()));
    cout << abs(a - b) << endl;

    solve();
    return 0;
}


Measured memory_bytes: 256
lst=[int(input()) for i in range(28)]
lsts=sorted(lst)

l=[]
s=1

for j in range(28):
    if lsts[j]!=s:
        l.append(s)
        s=s+2
    else:
        s=s+1
for n in l:
    print(n)
if max(lsts)!=30:
    print(30)


Measured memory_bytes: 5600
from collections import deque
INF = 10 ** 5
n, x, y = (int(_) for _ in input().split())
dict = {}
table = [[INF] * (n+1) for i in range(n+1)]
res = [0] * n

def bfs(i): #頂点iから行ける場所を探す
  deq = deque()
  node_lst = [-1] * (n+1) #訪れた頂点を管理
  node_lst[i] = 0
  deq.extend(dict[i])
  for j in dict[i]:
    node_lst[j] = node_lst[i] + 1
  while deq:
    p = deq.popleft()
    for j in dict[p]:
      if node_lst[j] == -1:
        deq.append(j)
        node_lst[j] = node_lst[p] + 1
  for j in range(1, n+1):
    if node_lst[j] < 1:
      continue
    a, b = i, j
    if x > y:
      a, b = b, a
    table[a][b] = min(table[a][b], node_lst[j])
  
#入力
for i in range(1, n+1):
  if i == 1:
    dict[i] = [2]
  elif i == n:
    dict[i] = [n - 1]
  else:
    dict[i] = [i-1, i+1]
dict[x] += [y]
dict[y] += [x]

#bfs
for i in range(1, n+1):
  bfs(i)
  
#出力
for i in range(1, n+1):
  for j in range(i, n+1):
    if table[i][j] == INF:
      continue
    res[table[i][j]] += 1
for i in range(1, n):
  print(res[i])


Measured memory_bytes: 80860
s=str(input())
n=int(input())
c1=0
c2=0
for i in range(n):
    c=list(input().split())

    if c[0]=="replace":
        l=s[:int(c[1])]
        r=s[int(c[2])+1:]
        s=str(l)+c[3]+str(r)


    elif c[0]=="reverse":
        l=s[:int(c[1])]
        r=s[int(c[2])+1:]
        s=str(l)+s[int(c[1]):int(c[2])+1][::-1]+str(r)            
    else:
        for i in range(int(c[1]),int(c[2])+1):
            print(s[i],end="")
        print("")



Measured memory_bytes: 5724
#A
V,E = map(int,input().split())
VWT = [list(map(int,input().split())) for i in range(E)]

#UnionFind
class UF:
    def __init__(self,n):
        self.n = n
        self.root = [-1]*n #root[x]<0 ならxが根かつその値が木の要素数
        self.rank = [0]*n #木の深さ
    def __del__(self):
        pass
        
    def find(self,x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
            
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        
        if self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x]+=1
                
    def same(self,x,y):
        return self.find(x) == self.find(y) #bool
    
    def count(self,x):
        return -self.root[self.find(x)]

uf = UF(V)
    
VWT = sorted(VWT, key=lambda x:x[2])
ans = 0
for vwt in VWT:
    v,w,t = vwt
    if not uf.same(v,w):
        uf.unite(v,w)
        ans+=t
        
print(ans)    






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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;


int main(){
  
  int n;
  cin >>n;
  
  int ans=INF;
  for(int i=1;i<=n/2;i++){
    int sum=0;
    int a=i,b=n-i;
    string s=to_string(a);
    string t=to_string(b);
    rep(i,s.size()){
      sum+=s[i]-'0';
    }
    rep(i,t.size()){
      sum+=t[i]-'0';
    }
    if(ans>sum) ans=sum;
  }
  cout<<ans<<endl;
}
  



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	ans := 0
	for _, v := range s {
		ans += int(v - '0')
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// 二進数0~2^N-1まで普通に作れる、足りないところをどう調整するか
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int L;
  cin >> L;
  vector<int> to[22][22];
  int two[22];
  CLR(two);
  two[0] = 1;
  int n = 0;
  int e = 0;
  while(two[n] * 2 - 1 < L) {
    n++;
    two[n] = two[n-1] * 2;
    to[n][n+1].push_back(0);e++;
    to[n][n+1].push_back(two[n-1]);e++;
  }
  int X = two[n];
  while(X <= L - 1) {
    for(int m = n; m >= 0; m--) {
      if(L - 1 >= two[m] - 1 + X) {
        to[m+1][n+1].push_back(X);e++;
        X += two[m];
        break;
      }
    }
  }
  cout << n + 1 << " " << e << endl;
  FOR(i,1,21) {
    FOR(j,i+1,21) {
      FOR(k,0,to[i][j].size()) {
        cout << i << " " << j << " " << to[i][j][k] << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#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(){
    int n,k;
    cin >> n>> k;
    string s;
    cin >> s;
    
    int ka;
    ka=0;
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            ++ka;
        }
    }
    int ans;
    ans=n-1-ka;

    if(k*2<=ka){
        ans+=2*k;
    }
    else{
        ans=n-1;
    }
    cout << ans << endl;
    

    return 0;
}

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

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

#define fi first
#define se second
#define pb push_back
#define sz(a) int((a).size())
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define testcase int _;cin>>_;while(_--)

/*C-Marks*/
void Solve(){
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=k;i<n;i++){
		if(a[i]>a[i-k])
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
}

int main(){
	fast
	Solve();
	return 0;
}

Measured memory_bytes: 4424
N = STDIN.gets.chomp.to_i
A = STDIN.gets.chomp.split(' ').map(&:to_i)

count = 0
# 負の数の数を数える
A.each { |a|
  count += 1 if a < 0
}

Aabs = A.map(&:abs)
result = Aabs.inject(:+)

if count % 2 != 0 then
  mini = Aabs.min
  result -= mini * 2
end

puts result

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

int main(){
  int r, g, b;
  cin >> r >> g >> b;
  if((r * 100 + g * 10 + b) % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int n, m;
    bool start[200000] = {}, finish[200000] = {};
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int t, tt;
        cin >> t >> tt;
        if (t == 1)start[tt]=true;
        else if(tt == n)finish[t]=true;
    }
    for (int i = 1; i <= n; i++) {
        if (start[i] && finish[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 640
//https://beta.atcoder.jp/contests/abc112/tasks/abc112_b
#include<bits/stdc++.h>

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


int main() {
    int n,t;
    cin>>n>>t;
    int ret = 114514;
    for(int i:range(n)){
        int c,l;
        cin>>c>>l;
        if(l<=t)chmin(ret,c);
    }
    if(ret==114514)cout<<"TLE"<<endl;
    else cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 256
S = input().strip()
T = input().strip()

best = 13213312
for i in range(len(S) - len(T) + 1):
    curr = 0
    for j in range(len(T)):
        if S[i + j] != T[j]:
            curr += 1
    best = min(curr,best)
print(best)
        


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

int main(){
    int D;
    cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(j,D) rep(i,26) cin >> s[j][i];

    vector<int> t(D);
    vector<vector<int>> last(26, vector<int>(1,-1));
    Int manzoku = 0;

    rep(j,1) {
        int maxs = 0;
        rep(i,26) maxs = max(maxs, s[j][i]);
        vector<int> v(0); //s[j][i]が最も大きくなるようなiを入れる
        rep(i,26) {
            if (s[j][i] == maxs) {
                v.push_back(i+1);
            }
        }
        if (v.size() == 1) {
            t[j] = v[0];
            last[t[j]-1].push_back(j);
        }
        else { //仮
            t[j] = v[0];
            last[t[j]-1].push_back(j);
        }
    }
    int i = t[0]-1;
    rep1(j,D-1) {
        i = (i + 1) % 26;
        t[j] = i+1;
        last[t[j]-1].push_back(j);
    }


    rep(i,26) last[i].push_back(D);

    vector<int> nums(26,0);
    rep(i,26) nums[i] = last[i].size();
/*
    int M = 10000;
    rep(k,M) {
        int d, q;
        vector<pair<int,int>> vp(26);
        rep(i,26) vp[i] = make_pair(c[i] - 10 * nums[i],i);
        sort(vp.begin(),vp.end());
        q = vp[0].second;
        int p;
        for (int j = 25; j>=0; j--) {
            p = vp[j].second;
            if (last[p].size() == 2) continue;
            else {
                break;
            }
        }
        if (last[p].size() <= 2) continue;
        int lpsz = last[p].size();
        for (int i = 1; i <= lpsz-2; i++) {
            d = last[p][i] + 1;
        manzoku = 0;

        manzoku -= s[d-1][t[d-1]-1];
        manzoku += s[d-1][q-1];

        auto iteold = find(last[t[d-1]-1].begin(), last[t[d-1]-1].end(), d-1);
        int old_last = *(iteold-1);
        manzoku -= c[t[d-1]-1] * (d-1 - old_last) * (*(iteold+1) - (d-1));

        auto itenew = upper_bound(last[q-1].begin(), last[q-1].end(), d-1);
        int new_last = *(itenew-1);
        manzoku += c[q-1] * (d-1 - new_last) * (*itenew - (d-1));

        if (manzoku > 0) {
            //更新したほうがよいならこれをやる
            last[t[d-1]-1].erase(iteold);
            last[q-1].insert(itenew,d-1);
            t[d-1] = q;
            nums[t[d-1]-1]--;
            nums[q-1]++;
        }
        }

        //cout << manzoku << endl;
    }
*/
    rep(j,D) cout << t[j] << endl;
}

Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        long a = sc.nextLong();
        long v = sc.nextLong();
        long b = sc.nextLong();
        long w = sc.nextLong();
        long t = sc.nextLong();

        if(a <= b){
            if(a + v * t >= b + w * t){
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
    
        } else {
            if(a - v * t <= b - w * t){
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }

        }
    }
    
}

Measured memory_bytes: 35788
#include<iostream>

char service[3][101];
int point[2];

void solve(int n){
	point[0]=0;
	point[1]=0;
	for(int i=1; service[n][i]!='\0'; i++){
		if(service[n][i]=='A')
			point[0]++;
		else
			point[1]++;
	}
	if(n==2){
		if(point[0]>point[1])
			point[0]++;
		else
			point[1]++;
	}
	else{
		if(service[n+1][0]=='A')
			point[0]++;
		else
			point[1]++;
	}
}

int main(){
	while(true){
		for(int i=0; i<3; i++){
			std::cin >> service[i];
			if(service[0][0] == '0')
				return 0;
		}
		for(int i=0; i<3; i++){
			solve(i);
			std::cout << point[0] << ' ' << point[1] << std::endl;
		}
	}
}

Measured memory_bytes: 0
import java.util.*;

class Pair {
    long tot;
    long num;
    public Pair (long tot, long num) {
        this.tot = tot;
        this.num = num;
    }
}

class Main {

   private static int binarySearch(int[] A, long v) {
        int n = A.length;
        int left = 0;
        int right = A.length;
        if (A[n - 1] < v){
            return n;
        }   
        if (A[0] >= v){
            return 0;
        }   
    
        // lower_bound
        while (left < right) {
            int mid = (right + left) / 2;
            if (A[mid] < v){ 
                left = mid + 1;
            } else {
                right = mid;
            }   
        }   
        return left;
    }   

    private static Pair calc(int N, int[] A, long[] S, int x) {
        long tot = 0;
        long num = 0;
        // i 行目: 片手を a[i]で固定している。
        // O(nlog(n))
        for (int i = 0; i < N; i++) {
            int j = binarySearch(A, x - A[i]); // x - A[i] 以上の最小値indを求める。超えない場合は n が返ってくる
            num += N - j;                      // x - A[i] が x を超えない場合は右辺は0になる
            tot += (long)(S[N] - S[j]);        // x - A[i] が x を超えない場合は右辺は0になる
            tot += (long)A[i] * (long)(N - j); // x - A[i] が x を超えない場合は、n-jが0だから、0になる
        }
        return new Pair(tot, num);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long M = sc.nextLong();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        // O(nlog(n))
        Arrays.sort(A);

        // cumulative summation
        long[] S = new long[N + 1];
        S[0] = 0;
        for (int i = 0; i < N; i++) {
            S[i + 1] = S[i] + A[i];
        }

        int l = 0;
        int r = 200005;
        while (l + 1 < r) {
            int c = (l + r) >> 1;
            if (calc(N, A, S, c).num >= M) l = c;
            else r = c;
        }

        Pair p = calc(N, A, S, l);
        long ans = p.tot;
        ans -= ((p.num - M) * (long)l); // Mからはみ出た部分を引く。
        System.out.println(ans);

        return;
    }
}

Measured memory_bytes: 50956
#include <bits/stdc++.h>
using namespace std;
#define INF 200005
#define MOD 1000000007

int main()
{
    //freopen("output.txt","r",stdin);
    //freopen("input.txt","r",stdin);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int a,b;
    cin >> a >> b;
    int ans=a-(b*2);
    if(ans<0) ans=0;
    cout << ans << endl;
}


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

int main(){
    int n;long long X=0,x=0,ans=1000000000000000000LL;cin>>n;vector<long long>a(n);for(int i=0;i<n;i++){cin>>a[i];X+=a[i];}for(int i=0;i<n;i++){x+=a[i];if(i+1<n)ans=min(ans,abs(X-2*x));}cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return gcd( b, a % b );
}
ll lcm(ll a, ll b){//最小公倍数
    return a * b / gcd(a, b);
}
ll sosuu(ll x){
    for(int i = 2; i < x; i++){
        if(x % i == 0) return false;
    }

    return true;
}


//入力


int main(){

    int n, m;
    cin >> n >> m;

    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main{

	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
	static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static long mod = (long) (1e9+7);
	public static long[] fac,inv;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
	    int n = sc.nextInt();
	    int r = sc.nextInt();
	    long ans = 0;
	    if(n >= 10) ans = r;
	    else ans = r + 100*(10-n);
	    out.print(ans);
	    out.close();

	}

}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

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

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

void solve() {
	ll A, B, C, D; cin >> A >> B >> C >> D;
    ll ln = lcm(C,D);
    ll A_ = A-1;
    ll ans = B - A_ - (B/C + B/D - B/ln) + (A_/C + A_/D - A_/ln);
    cout << ans << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
import sys
import math
import re

a = input()
for i in range(len(a)):
    if i%2 == 0: #guusuu
        if a[i]=="L":
            print('No')
            sys.exit()
    else:
        if a[i]=="R":
            print('No')
            sys.exit()
print("Yes")
        


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

typedef long long ll;

const int MAX_N = 200000;

int bit[MAX_N + 1], n = 200000;

int sum(int i) {
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x) {
    while (i <= n) {
        bit[i] += x;
        i += i & -i;
        //cout << i << " ";
    }
    //cout << endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    vector<pair<int, int>> xy(N);
    rep(i, N) {
        cin >> x[i] >> y[i];
        xy[i] = make_pair(x[i], y[i]);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    map<int, int> xm, ym;
    rep(i, N) {
        xm[x[i]] = i + 1;
        ym[y[i]] = i + 1;
    }
    rep(i, N) {
        xy[i].first = xm[xy[i].first];
        xy[i].second = ym[xy[i].second];
        //cout << xy[i].first << " " << xy[i].second << "\n";
    }
    vector<int> UL(N, 0), DL(N, 0), UR(N, 0), DR(N, 0);
    sort(xy.begin(), xy.end());
    rep(i, N) {
        DL[i] = sum(xy[i].second);
        UL[i] = i - DL[i];
        add(xy[i].second, 1);
        //cout << "DL[" << i << "]=" << DL[i] << " UL[" << i << "]=" << UL[i] << "\n";
    }
    rep(i, N) bit[i + 1] = 0;
    for (int i = N - 1; i >= 0; i--) {
        DR[i] = sum(xy[i].second);
        UR[i] = N - 1 - i - DR[i];
        add(xy[i].second, 1);
       // cout << "DR[" << i << "]=" << DR[i] << " UR[" << i << "]=" << UR[i] << "\n";
    }
    vector<ll> b(N + 1, 1);
    ll MOD = 998244353, ans = 0;
    rep(i, N) b[i + 1] = (b[i] * 2) % MOD;
    rep(i, N) {
        ll d = b[UL[i] + UR[i]] + b[UL[i] + DL[i]] + b[DL[i] + DR[i]] + b[DR[i] + UR[i]] - 4;
        d -= b[UL[i]] + b[UR[i]] + b[DL[i]] + b[DR[i]] - 4;
        ans = (ans + b[N] - 1 - d + MOD) % MOD;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 27648
#define NguyenDangQuan the_author

#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define mset(x, i) memset(x,i,sizeof(x))
#define elif else if
#define heap priority_queue
#define fi first
#define se second
#define pb push_back
#define ld long double
#define ll long long
#define int long long
#define task ""
using namespace std;

int typetest;
template<class T>
void read(T &x){
    register int c;
    T neg = 1;
    x = (T)0;
    while ((c = getchar()) <= 47 || c >= 58)
		if(c == '-') neg = -1;
    for (; (c > 47 && c < 58); c = getchar()){
        x = (x << 3) + (x << 1) + (T)(c - 48);
    }
	x *= neg;
}
inline void fastIOfileinput(){
	ios_base:: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(task".INP", "r", stdin);
//	freopen(task".OUT", "w", stdout);
//	freopen(task".in", "r", stdin);
//	freopen(task".out", "w", stdout);
	typetest = 0;
}

const int N = 2e5 + 2;
int n;
ll k, a[N], l = 0;
map<int, vector<int>> b;
set<int> s;

void Enter(){
	read(n); read(k);
	s.insert(0);
	b[0].pb(0);
	for(int i = 1; i <= n; ++i){
		read(a[i]);
		a[i] += a[i - 1];
		a[i] %= k;
		s.insert(((a[i] % k - i) % k + k) % k);
		b[((a[i] % k - i) % k + k) % k].pb(i);
	}
}

void Solve(){
	ll ans = 0;
	for(auto i : s){
		auto& q = b[i];
		for(int t = 0; t < q.size(); ++t){
			int j = q[t];
			int l = t + 1, m, h = q.size() - 1;
			while(l <= h){
				m = (l + h) >> 1;
				if(j + k > q[m]) l = m + 1;
				else h = m - 1;
			}
			ans += (ll)(h - t);
		}
	}
	cout << ans;
}

signed main(){
	fastIOfileinput();
	if(typetest){
		int t;
		cin >> t;
		while(t--){
			Enter();
			Solve();
		}
	}
	else{
		Enter();
		Solve();
	}
}


Measured memory_bytes: 33920