akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    int N;
    cin >> N;
    vector<tuple<int,int,int>> vec;
    for(int i = 0;i < N;i++) {
        int A,B,C;
        cin >> A >> B >> C;
        vec.emplace_back(C,A,B);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(),vec.end());
    for(int i = 0;i <= 100;i++) {
        for(int j = 0;j <= 100;j++) {
            int high = get<0>(vec.at(0)) + abs(i - get<1>(vec.at(0))) + abs(j - get<2>(vec.at(0)));
            bool judge = true;
            for(int k = 1;k < N;k++) {
                int cnt = get<0>(vec.at(k)) + abs(i - get<1>(vec.at(k))) + abs(j - get<2>(vec.at(k)));
                if(get<0>(vec.at(k)) == 0) {
                    if(high > cnt) {
                        judge = false;
                    }
                }
                else if(high != cnt) {
                    judge = false;
                }
            }
            if(judge == true) {
                cout << i << " " << j << " " << high << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> // sqrt
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int num;
    cin >> num;
    vector<int> arr(num);
    cins(arr);

    stack<int> stack;
    int64_t ans = 0;
    stack.push(arr[0]);
    // make even as many as possible
    for(int i = 1; i < num; i++) {
        int cur = arr[i];
        int prev = stack.top(); stack.pop();
        if(prev%2 && cur != 0) {
            ans++;
            prev--;
            cur--;
        }
        stack.push(prev); stack.push(cur);
    }

    while(!stack.empty()) {
        int val = stack.top(); stack.pop();
        debug("%d\n", val);
        ans += (val/2);
    }

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

Measured memory_bytes: 4008
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		String op = scan.next();
		int b = scan.nextInt();
		int answer = 0;
		if(op.equals("+")) {
			answer = a + b;
		} else {
			answer = a - b;
		}
		System.out.println(answer);
	}
}

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

using namespace std;

int main() {
	
	int n;
	cin >> n;
	bool flag = false;
	for (double i = 1; i <= n; i ++) {
		if (int(i * 1.08) == n) {
			cout << i << '\n';
			flag = true;
		}
	}
	if (!flag) {
		cout << ":(\n";
	}
	return 0;
}

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

int main() {
	int i = 0, x;
	while(i != 10000) {
		cin >> x;
		if(x == 0) {
			break;
		}
		i++;
		cout << "Case " << i << ": " << x << endl;
	}
}


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

		String S = sc.next();
		int G = 0,P = 0;
		for( int i=0; i<S.length(); i++ ){
			if( S.charAt(i)=='g' ){
				G++;
			}else{
				P++;
			}
		}
		System.out.println((G-P)/2);
	}
}


Measured memory_bytes: 24788
fun main() {
    val exteriorangle = readLine()!!.trim().toInt()
    val interiorangle=180-exteriorangle
    var rest:Int=360%exteriorangle
    var ans:Int = 360/exteriorangle
    var n:Int = 1
     while(rest!=0){

         var sumoftheinteriorangle = n*interiorangle
         rest=sumoftheinteriorangle%360
         n++
         ans=n-1
     }
    println(ans)
}

Measured memory_bytes: 35708
var input = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
var total = parseInt(input[0], 10);
var nums = input[1].split(" ").map(function(num) {
  return parseInt(num, 10);
});

var can = true;

var current = nums[total - 1];
for (var i = total - 1; i >= 0; i--) {
  var prev = nums[i - 1];
  if (typeof prev === 'undefined') {
    continue;
  }
  if (prev <= current) {
    current = prev;
    continue;
  }

  if (prev - 1 <= current) {
    current = prev - 1;
    continue;
  }

  can = false;
  break;
}

console.log(can ? 'Yes' : 'No');




Measured memory_bytes: 21708
n, s = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353
ans = 0

inv_2 = pow(2, mod-2, mod)
dp = [[0 for _ in range(s+1)] for _ in range(n+1)]
dp[0][0] = pow(2, n, mod)

for i in range(n):
    for j in range(s+1):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= mod

        if j + a[i] <= s:
            dp[i+1][j+a[i]] += dp[i][j] * inv_2
            dp[i+1][j+a[i]] %= mod

#print(dp)
print(dp[n][s])

Measured memory_bytes: 147656
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;

public class Main {
	static ContestScanner in;
	static Writer out;
	public static void main(String[] args) {
		Main main = new Main();
		try {
			in = new ContestScanner();
			out = new Writer();
			main.solve();
			out.close();
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	void solve() throws IOException {
		long n = in.nextInt();
		long a = in.nextLong();
		long b = in.nextLong();
		System.out.println(Math.max(0, (b * (n - 1) + a) - (a * (n - 1) + b) + 1));
	}
}

class Writer extends PrintWriter{
	public Writer(String filename)throws IOException
	{super(new BufferedWriter(new FileWriter(filename)));}
	public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
	private BufferedReader in;private int c=-2;
	public ContestScanner()throws IOException 
	{in=new BufferedReader(new InputStreamReader(System.in));}
	public ContestScanner(String filename)throws IOException
	{in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
	public String nextToken()throws IOException {
		StringBuilder sb=new StringBuilder();
		while((c=in.read())!=-1&&Character.isWhitespace(c));
		while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public String readLine()throws IOException{
		StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
		while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public long nextLong()throws IOException,NumberFormatException
	{return Long.parseLong(nextToken());}
	public int nextInt()throws NumberFormatException,IOException
	{return(int)nextLong();}
	public double nextDouble()throws NumberFormatException,IOException 
	{return Double.parseDouble(nextToken());}
	public void close() throws IOException {in.close();}
}

Measured memory_bytes: 21460
#include<cstdio>
#include<deque>
#include<algorithm>

using namespace std;

typedef pair<long long, int> P;

const long long inf = 1e18;

int M, N;
int K;
int A[100100];

long long dp[100100][330];

long long solve(){
	for(int i = 0; i < N; ++i){
		dp[i][1] = A[i];
	}
	for(int j = 2; j <= K; ++j){
		deque<P> deq;
		if(dp[0][j - 1] != -inf) deq.push_front(P(dp[0][j - 1], 0));
		dp[0][j] = -inf;
		for(int i = 1; i < N; ++i){
			if(!deq.empty()){
			if(deq.front().first == -inf){
				dp[i][j] = -inf;
			}else{
				dp[i][j] = deq.front().first + (long long)A[i] * j;
			}
			while(!deq.empty()){
				if(deq.back().first < dp[i][j - 1]){
					deq.pop_back();
				}else break;
			}
			deq.push_back(P(dp[i][j - 1], i));
			if(deq.front().second == i - M){
				deq.pop_front();
			}
			}else{
				dp[i][j] = -inf;
				if(dp[i][j - 1] != -inf){
					deq.push_front(P(dp[i][j - 1], i));
				}
			}
		}
	}
	long long ans = -1;
	for(int i = 0; i < N; ++i){
	/*	for(int j = 0; j <= K; ++j){
			printf("%lld ", dp[i][j]);
		}
		printf("\n");*/
		ans = max(ans, dp[i][K]);
	}
	return ans;
}

void input(){
	scanf("%d%d%d", &N, &M, &K);
	for(int i = 0; i < N; ++i){
		scanf("%d", A + i);
	}
}

int main(){
	input();
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 258560
n, m = map(int, input().split())

A = [[] for _ in range(n)]
for i in range(n):
    A[i][0:m] = map(int, input().split())

B = []
for _ in range(m):
    B.append(int(input()))

# calculate

for i in range(n):
    multiple = 0
    for j in range(m):
        multiple = multiple + A[i][j] * B[j]
    print(multiple)



Measured memory_bytes: 6020
/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}

int main()
{
	ll n;
	sl(n);
	if(n == 25)
		puts("Christmas");
	else if( n == 24)
		puts("Christmas Eve");
	else if(n == 23)
		puts("Christmas Eve Eve");
	else
		puts("Christmas Eve Eve Eve");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define all int i=0; i<n; i++
#define INF 9999999999999999
using namespace std;
typedef long long int ll; 
#define int ll    

int32_t main(){
	int a,b;
	cin>>a>>b;
	cout<<a/b + bool(a%b)<<endl;
	
}

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

int main(){
    string s1,s2,s3;
    string out;
    cin>>s1>>s2>>s3;
    out += s1[0]-32;
    out += s2[0]-32;
    out += s3[0]-32;
    cout<<out<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+1];
        
        int i;
        for(i = 1;i <= n;i++){
            a[i] = sc.nextInt();
        }
        
        for(i = 1;i <= n;i++){
            if(i % 2 == 0){
                a[i] = 101;
            }
        }
        
        for(i = 1;i <= n;i++){
            if(a[i] % 2 == 0){
                a[i] = 101;
            }
        }
        
        int ans=0;
        for(i = 1;i <= n;i++){
            if(a[i] != 101){
                ans++;
            }
        }
        System.out.println(ans);
        
        

        
    }
}


Measured memory_bytes: 35680
def inv(a):
    m=10**9+7
    b=m
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % m


def main():
    MOD=10**9+7
    n,k=map(int,input().split())
    a=list(map(int,input().split()))

    frac=[1]
    for i in range(1,n+1):
        frac.append(frac[-1]*i%MOD)
    
    fracinv=[inv(frac[i]) for i in range(n+1)]


    dp=[[0]*(n+1) for _ in range(k)]

    for x in range(a[0]+1):
        dp[0][x]=frac[n]*frac[n-x]*inv(frac[a[0]-x]*frac[n-a[0]]*frac[x])%MOD

    for i in range(k-1):
        ai=a[i+1]
        for j in range(n+1):
            for x in range(ai+1):
                p=j+x
                if p>n: break
                tmp=dp[i][j]
                tmp=(tmp*frac[n-x]*fracinv[ai-x])%MOD
                tmp=(tmp*fracinv[n-ai]*fracinv[x])%MOD
                dp[i+1][p]=(dp[i+1][p]+tmp)%MOD
    print(dp[k-1][n]%MOD)

if __name__ == "__main__":
    main()

Measured memory_bytes: 61660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int h, w, d;
vector<pair<int, int>> pos;
vector<int> mp;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> h >> w >> d;
    pos.resize(h * w);
    mp.resize(h * w);
    
    rep(i, h) {
        rep(ii, w) {
            int a;
            cin >> a;
            a--;
            pos[a] = pair<int, int>(i, ii);
        }
    }
    
    rep(i, sz(mp)) {
        if (i >= d) {
            mp[i] = mp[i - d] + abs(pos[i - d].first - pos[i].first) + abs(pos[i - d].second - pos[i].second);
        }
        else {
            mp[i] = abs(pos[0].first - pos[i].first) + abs(pos[0].second - pos[i].second);
        }
    }
    
    int q;
    cin >> q;
    
    rep(i, q) {
        int l, r;
        
        cin >> l >> r;
        l--; r--;
        
        cout << mp[r] - mp[l] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2176
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt(), W = sc.nextInt(), D = sc.nextInt();
		List<int[]> access= new ArrayList<int[]>();
		for(int i=0;i<=H*W;i++)access.add(null);
	
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				int num = sc.nextInt();
				int address[] = {i,j};
				access.set(num, address);
			}
		}
		int Q = sc.nextInt();
		int query[][] = new int[Q][2];
		for(int i=0;i<Q;i++) {
			query[i][0] = sc.nextInt();
			query[i][1] = sc.nextInt();
		}
		sc.close();

		int costLast = H*W/D + 3;
		int cost[][] = new int[D+1][costLast];
		
		for(int i=1;i<=D;i++) {
			cost[i][0]=0;
			int now = i;
			int next = 0;
			for(int j=0;j<costLast;j++) {
				next = now + D;
				if(next>H*W)break;
				int dist = Math.abs(access.get(next)[0]-access.get(now)[0])+Math.abs(access.get(next)[1]-access.get(now)[1]);
				cost[i][j+1]=cost[i][j]+dist;
				now = next;
			}
		}
		
		//answer
		
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<Q;i++) {
			int start = query[i][0], goal = query[i][1];
			int series = start%D==0 ? D:start%D;
			int ans = cost[series][(goal-series)/D]-cost[series][(start-series)/D];
			sb.append(ans + "\n");
		}
		System.out.println(sb.toString());
		
		
	}
}


Measured memory_bytes: 101880
#include <iostream>

using namespace std;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if(a != b && b != c && c != a){
        cout << 3 << endl;
    }
    else if(a == b){
        if(b == c)  cout << 1 << endl;
        else    cout << 2 << endl;
    }
    else if(b == c){
        if(a == c)  cout << 1 << endl;
        else    cout << 2 << endl;
    }
    else if(c == a){
        if(b == a)  cout << 1 << endl;
        else    cout << 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main(){
	
	string s, t;
	cin >> s >> t;
	
	int a[s.size()], b[t.size()];
	
	for(int i = 0; i < s.size(); i++){
		a[i] = s[i] - 'a';
	}
	
	for(int i = 0; i < t.size(); i++){
		b[i] = t[i] - 'a';
	}
	
	sort(a, a + s.size());
	sort(b, b + t.size(), greater<int>());
	
	for(int i = 0; i < s.size(); i++){
		s[i] = a[i] + 'a';
	}
	
	for(int i = 0; i < t.size(); i++){
		t[i] = b[i] + 'a';
	}
	
	if(s < t){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <functional>
#include <vector>

using namespace std;

void solve_case();

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

	solve_case();

	return 0;
}

void solve_case() {
	long long k, a, b, ans = 1;

	cin >> k >> a >> b;

	if (a + 2 >= b)
		ans = k + 1;
	else {
		if (k <= a)
			ans = k + 1;
		else {
			k -= a + 1;
			ans = b;
			ans += (b - a) * (k / 2);
			if (k % 2 == 1)
				ans++;
		}
	}

	cout << ans << "\n";
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct Point{double x,y;}p0,p1,p2;
Point operator -(Point a,Point b){return (Point){a.x-b.x,a.y-b.y};}
double cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
double dot(Point a,Point b){return a.x*b.x+a.y*b.y;}
double norm(Point a){return a.x*a.x+a.y*a.y;}
void read(Point &p){p.x=read(),p.y=read();}
int Clockwise(Point p0,Point p1,Point p2)
{
	Point v1=p1-p0,v2=p2-p0;
	if(cross(v1,v2)>0)return -2;
	if(cross(v1,v2)<0)return 2;
	if(dot(v1,v2)<0)return -1;
	if(norm(v1)<norm(v2))return 1;
	return 0;
}
int main()
{
	read(p0),read(p1);
	int q=read();while(q--)
	{
		read(p2);
		switch(Clockwise(p0,p1,p2))
		{
			case -2:printf("COUNTER_CLOCKWISE\n");break;
			case -1:printf("ONLINE_BACK\n");break;
			case 0:printf("ON_SEGMENT\n");break;
			case 1:printf("ONLINE_FRONT\n");break;
			case 2:printf("CLOCKWISE\n");break;
		}
	}
	return 0;
}



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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin>>n;
  int a[n+1];
  for(int i=1;i<=n;i++)
    cin>>a[i];
    int cur=1;
  for(int i=1;i<=n;i++){
    if(a[i]==cur)
        cur++;
  }
  if(cur!=1)
  cout<<n-cur+1;
  else
    cout<<"-1";
}

Measured memory_bytes: 1024
import numpy
N = int(input())
i = int(numpy.sqrt(2*N))

if i * (i+1) == 2 * N:
    print('Yes')
    print(i+1)
    S = [[] for k in range(i+1)]
    k = 1
    for now in range(0, i+1):
        for now2 in range(now+1, i+1):
            S[now].append(k)
            S[now2].append(k)
            k += 1
    for j in range(i+1):
        print(i, end = ' ')
        values = map(str, S[j])
        print(' '.join(values))
else:
    print('No')


Measured memory_bytes: 18760
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,i,j,k,swap;
    while(scanf("%d%d",&x,&y)!=EOF)
    {
        if(x>y)
        {
            swap=x;
            x=y;
            y=swap;
            cout<<x<<" "<<y<<endl;
        }
        else if(x==0 && y==0)
        {
            break;
        }
        else{
            cout<<x<<" "<<y<<endl;
        }

    }
}



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

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

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

	for (i = n-1; i > -1; i--) {
		cout << a[i];
		if (i != 0) cout << " ";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <functional>

#define big ((long long)(1e9) + 7)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define DBG(x) cerr << #x << ": " << (x) << " (L" << __LINE__ << ")" << endl;

void setmin(int &a, int b)
{
    if (a > b)
        a = b;
}

int main()
{
    int INF = 1000000;
    int h, w;
    cin >> h >> w;
    vector<vector<char> > s(h, vector<char>(w));
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<vector<int> > dp(h + 1, vector<int>(w + 1, INF));
    dp[1][1] = s[0][0] == '.' ? 0 : 1;
    int dr[] = {-1, 0};
    int dc[] = {0, -1};
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            for (int dir = 0; dir < 2; dir++)
            {
                int pr = i + dr[dir];
                int pc = j + dc[dir];
                if (dp[pr + 1][pc + 1] == INF)
                    continue;
                int changed = s[i][j] != s[pr][pc];
                setmin(dp[i + 1][j + 1], dp[pr + 1][pc + 1] + changed);
            }
        }
    }
    DBG(dp[h][w]);
    cout << (dp[h][w] + 1) / 2 << endl;
}


Measured memory_bytes: 256
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(st.nextToken());
         System.out.println(K+" "+N+" "+M);
      }
   }

Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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 / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
ll n,m;
cin>>n>>m;
cout<<(n-1)*(m-1)<<endl;
}









Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i=0; i<N; i++){
		cin >> A.at(i);
	}
	
	sort(A.begin(), A.end(), greater<int>() );
	
	int alice=0;
	int bob=0;
	for(int i=0; i<N; i++){
		if(i%2==0){
			alice += A.at(i);
		}else{
			bob += A.at(i);
		}
	}
	cout << alice-bob << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main()
{
  int *a,w,n,i,j,t;
  scanf("%d",&w);
  a = (int *)(malloc(sizeof(int)*w));
  for(i=0;i<w;i++){
    a[i] = i+1;
  }
  scanf("%d",&n);
  while(n>0){
    scanf("%d,%d",&i,&j);
    t = a[i-1];
    a[i-1] = a[j-1];
    a[j-1] = t;
    n--;
  }
  for(i=0;i<w;i++){
    printf("%d\n",a[i]);
  }
  free(a);
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=18;
const int MOD=998244353;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }
void dec(int &a,int b) { if((a-=b)<0) a+=MOD; }
int pw(int x,int n) { int ret=1; while(true) { if(n&1) ret=(ll)ret*x%MOD; if((n>>=1)==0) return ret; x=(ll)x*x%MOD; } }
int inv(int x) { assert(x!=0); return pw(x,MOD-2); }

void wht(int *a,int nbits) {
	REP(bit,nbits) for(int off=0;off<(1<<nbits);off+=2<<bit) REP(i,1<<bit) { int x=a[off+i],y=a[off+(1<<bit)+i]; a[off+i]=a[off+(1<<bit)+i]=x; inc(a[off+i],y); dec(a[off+(1<<bit)+i],y); }
}

int n;
int a[1<<MAXN];
int x[1<<MAXN];

int p[1<<MAXN];
int lhs[1<<MAXN];
int rhs[1<<MAXN];


void solve() {
	int asum=0; REP(i,1<<n) asum+=a[i];
	int pmlt=inv(asum); REP(i,1<<n) p[i]=(ll)a[i]*pmlt%MOD;
	REP(i,1<<n) lhs[i]=p[i]; lhs[0]=(lhs[0]+MOD-1)%MOD;
	REP(i,1<<n) rhs[i]=MOD-1; rhs[0]=(rhs[0]+(1<<n))%MOD;
	wht(lhs,n);
	wht(rhs,n);
	//printf("lhs:"); REP(i,1<<n) printf(" %d",lhs[i]); puts("");
	//printf("rhs:"); REP(i,1<<n) printf(" %d",rhs[i]); puts("");
	x[0]=0; FOR(i,1,1<<n) { assert(lhs[i]!=0); x[i]=(ll)rhs[i]*inv(lhs[i])%MOD; }
	wht(x,n);
	int offset=MOD-x[0]; REP(i,1<<n) inc(x[i],offset);
	int xmlt=inv(1<<n); REP(i,1<<n) x[i]=(ll)x[i]*xmlt%MOD;
	//printf("x:"); REP(i,1<<n) printf(" %d",x[i]); puts("");
}

void run() {
	scanf("%d",&n);
	REP(i,1<<n) scanf("%d",&a[i]);
	solve();
	REP(i,1<<n) printf("%d\n",x[i]);

}

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


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

bool check(int i) {
    int tmp = 1;
    for(int a = 1; a <= i / 2; a++) {
        if(i % a == 0) {
            tmp++;
        }
    }
    if(tmp == 8) {
        return true;
    }else return false;
}


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

    int ans = 0;
    for(int i = 1; i <= n; i += 2) {
        if(check(i)) {
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		int hh = Integer.parseInt(sc.next());
		int ww = Integer.parseInt(sc.next());

		int cells = h * w;
		System.out.println(cells - hh*w -  ww*h + hh * ww);

	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll L, R;
ll mod = 1000000007;
ll dp[63][2][2][2]; //digit, deviated from l, deviated from r, initial bit has been set

ll solve(int dig, int x, int y, int firstBit){
    if (dig == -1) return 1LL;
    if (dp[dig][x][y][firstBit] != -1) return dp[dig][x][y][firstBit];
    dp[dig][x][y][firstBit] = 0;
    if (x == 1 || !(1LL<<dig & L)){ // x 0, y 0
        dp[dig][x][y][firstBit] += (1LL<<dig & R) ? solve(dig-1, x, 1, firstBit) : solve(dig-1, x, y, firstBit);
    }
    if ((x == 1 || !(1LL<<dig & L)) && (y == 1 || (1LL<<dig & R)) && firstBit){ // x 0, y 1
        dp[dig][x][y][firstBit] += solve(dig-1, x, y, firstBit);
    }
    if (y == 1 || (1LL<<dig & R)){ // x 1, y 1
        dp[dig][x][y][firstBit] += !(1LL<<dig & L) ? solve(dig-1, 1, y, 1) : solve(dig-1, x, y, 1);
    }
    dp[dig][x][y][firstBit] %= mod;
    return dp[dig][x][y][firstBit];
}

int main() {
    cin >> L >> R;
    memset(dp, -1, sizeof(dp));
    cout << solve(62, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,x;
    cin >> a; cin >> b; cin >>c;
    if (a>b){
        x=a; a=b; b=x;
    }
    if (b>c){
        x=b; b=c; c=x;
    }
    if (a>b){
        x=a; a=b; b=x;
    }
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	for (int k = 0; k < 4; k++) {
		vector<int> sw(n);
		if (k == 0) sw[0] = sw[1] = 0;
		else if (k == 1) {
			sw[0] = 0;
			sw[1] = 1;
		} else if (k == 2) {
			sw[0] = 1;
			sw[1] = 0;
		}
		else sw[0] = sw[1] = 1;

		for (int i = 1; i < n-1; i++) {
			if (sw[i] == 0) {
				if (s[i] == 'o') {
					sw[i+1] = 1 - sw[i-1];
				} else {
					sw[i+1] = sw[i-1];
				}
			} else {
				if (s[i] == 'o') {
					sw[i+1] = sw[i-1];
				} else {
					sw[i+1] = 1 - sw[i-1];
				}
			}
		}
		
		bool b1 = true;
		if (sw[n-1] == 0) {
			if (s[n-1] == 'o') {
				if (sw[n-2] == sw[0]) b1 = false;
			} else {
				if (sw[n-2] != sw[0]) b1 = false;
			}
		} else {
			if (s[n-1] == 'o') {
				if (sw[n-2] != sw[0]) b1 = false;
			} else {
				if (sw[n-2] == sw[0]) b1 = false;
			}
		}
		bool b2 = true;
		if (sw[0] == 0) {
			if (s[0] == 'o') {
				if (sw[n-1] == sw[1]) b1 = false;
			} else {
				if (sw[n-1] != sw[1]) b1 = false;
			}
		} else {
			if (s[0] == 'o') {
				if (sw[n-1] != sw[1]) b1 = false;
			} else {
				if (sw[n-1] == sw[1]) b1 = false;
			}
		}

		if (b1 && b2) {
			string ans = "";
			rep(i,n) ans += (sw[i] ? 'S': 'W');
			cout << ans << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 4280
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	static final boolean debugMode = false;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double r = readInt(sc);
		System.out.println(Math.PI * (double) 2 * r);

	}

	// con.) a >= b
	static int gcm(int a, int b) {
		while (true) {
			if (b == 0)
				break;

			int mod = a % b;
			a = b;
			b = mod;
		}
		return a;
	}

	// con.) a >= b
	static int lcm(int a, int b) {
		return a * b / gcm(a, b);
	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static Long readLong(Scanner sc) {
		return Long.parseLong(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}
}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}

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

int main() {
	
  int N;
  cin >> N;
  
  string s[100001] = { " " };
  for(int i = 0; i < N; i++) {
    cin >> s[i];
  }
	
  int AC = 0;
  int WA = 0;
  int TLE = 0;
  int RE = 0;
  
  for(int i = 0; i < N; i++) {
    if(s[i] == "AC") {
      AC++;
    } else if(s[i] == "WA") {
      WA++;
    } else if(s[i] == "TLE") {
      TLE++;
    } else if(s[i] == "RE") {
      RE++;
    }
  }
  
  
      

	cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
  	
}
  
  

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

int main() {
  int n, i, ans = 0;
  cin >> n;
  
  vector<int> p(n), q(3);
  for(i = 0; i < n; i++) cin >> p.at(i);
  
  for(i = 2; i < n; i++){
    q.at(0) = p.at(i - 2);
    q.at(1) = p.at(i - 1);
    q.at(2) = p.at(i);
    
    sort(q.begin(), q.end());
    
    if(q.at(1) == p.at(i - 1)){
     ans++; 
    }
  }
  
  cout << ans << endl;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i <= n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i <= n; i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std;

int main(void)
{
    string s;
    cin >> s;

    if(s.find("7") != string::npos) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}
/** atcoder **/


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

int main() {
  int N;
  cin >> N;
  int S = 0;
  int a = 1;
  
  
  for (int i =0; i < 9; i++) {
    int x;
    a *= 10;
    x = (N % a - N % (a/10)) / (a/10);
    S += x;
  }
  
  if (N % S == 0){
  	cout << "Yes";
  } 
  else {
  	cout << "No";
  }
 
}

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

using namespace std;

int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
    puts("0");
    return 0;
  }
  long long ans = min({a * b, a * c, b * c});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n,m,l;
		int[][] A=new int[101][101];
		int[][] B=new int[101][101];
		long [][] C=new long[101][101];
		n=sc.nextInt();
		m=sc.nextInt();
		l=sc.nextInt();
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				A[i][j]=sc.nextInt();
			}
		}
		for(int i=1;i<=m;i++){
			for(int j=1;j<=l;j++){
				B[i][j]=sc.nextInt();
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=l;j++){
				C[i][j]=0;
				for(int k=1;k<=m;k++){
					C[i][j]+=(A[i][k]*B[k][j]);
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<l;j++){
				System.out.print(C[i][j]+" ");
			}
			System.out.println(C[i][l]);
		}
    }
}



Measured memory_bytes: 53676
A, B, C, D = map(int, input().split())
turn = "t"
while(A > 0 and C > 0):
    if turn == "t":
        C -= B
        turn = "a"
    else:
        A -= D
        turn = "t"
if A <= 0:
    print("No")
elif C <= 0:
    print("Yes")

Measured memory_bytes: 9180
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin>>N;
    int count=0;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin>>A.at(i);
    }
    bool f = true;
    
    while(f){
        for(int j=0; j<N; j++){
            if(A.at(j)%2!=0){
                f = false;
                break;
            }
              else{
                  A.at(j)=A.at(j)/2;
              }
              if(j==N-1){
                  count++;
              }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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 gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N;
    cin >>N;
    ll wa = 0;
    vector<ll> num(N + 2);
    num[0] = 0;
    num[N + 1] = 0;
    rep(i,N){
        cin >> num[i + 1];
        wa += abs(num[i] - num[i + 1]);
//        cout << abs(num[i] - num[i + 1]) << endl;
    }
    wa += abs(num[N] - num[N + 1]);
    for(ll i = 1;i < N + 1;i++){//num[i]を除く
        if(num[i - 1] <= num[i] && num[i + 1] >= num[i] || (num[i + 1] <= num[i] && num[i - 1] >= num[i]))cout << wa << endl;
        else{
            ll n = abs(num[i - 1] - num[i]) + abs(num[i] - num[i + 1]) - abs(num[i - 1] - num[i + 1]);
            cout << wa - n << endl;
        }
    }
//    rep(i,N + 2)cout << num[i] << endl;
}

Measured memory_bytes: 2048
# https://atcoder.jp/contests/abc066/tasks/arc077_a

import itertools
from collections import Counter
from collections import defaultdict
import bisect
import math
import heapq

def main():
    n = int(input())
    a = list(map(int, input().split()))

    i = len(a) - 1
    while i >= 0:
        print(a[i], end=" ")
        i -= 2

    i = 1 if i == -2 else 0
    while i < len(a):
        print(a[i], end=" ")
        i += 2


if __name__ == '__main__':
    main()


Measured memory_bytes: 93780
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main() {
  ll a,b,c,d; cin >> a>> b>>c>>d;
  ll ans = b-a+1;
  ll LCM = lcm(c,d);
  ll c_mul = b/c - (a-1)/c;
  ll d_mul = b/d - (a-1)/d;
  ll c_d_mul = b/LCM - (a-1)/LCM;
  ans -= c_mul;
  ans -= d_mul;
  ans += c_d_mul;
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 384
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/25 04:39:13 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

// TOP
void	Main()
{
	ll	n, m;
	string s, t;
	cin >> n >> m >> s >> t;
	ll	lcmv = n / __gcd(n, m) * m; // 答え候補
	ll	nd, md;
	nd = lcmv / n;
	md = lcmv / m;
	ll	i;
	i = 0;
	while (i * md < n && i * nd < m)
	{
		if (s.at(i * md) != t.at(i * nd))
		{
			cout << -1 << endl;
			return ;
		}
		i++;
	}
	cout << lcmv << endl;
}
// END

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


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

   ll N, M;
   cin >> N >> M;
   vector<ll> a(M);
   REP(i, M)cin >> a[i];

   ll dp[100010] = {0};

   dp[0] = 1;
   dp[1] = 1;
   ll count = 0;

    if(M > 0){
        if(a[0] == 1){
            dp[1] = 0;
            count++;
        }
        REP(i, N+1){
            if(i > 1){
                if(i == a[count]){
                    dp[i] = 0;
                    count++;
                }else{
                    dp[i] = dp[i-1] + dp[i-2];
                    dp[i] %= MOD;
                }
            }
        }
        dp[N] %= MOD;
    }else{
         REP(i, N+1){
            if(i > 1){
                    dp[i] = dp[i-1] + dp[i-2];
                    dp[i] %= MOD;
                
            }
        }
        dp[N] %= MOD;       
    }
   cout << dp[N] << endl;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin>>n;
    int ant, i;
    ant=i=0;
    int contsub=1;
    int orden=0;  // T -> dec  F -> crec

    cin >> ant;
    n--;
    while(n--){
        cin>>i;
        //cout << orden << " " << ant << " " << i << " " << contsub << endl;
        if(ant!=i){
            if( i>ant ){
                if( orden == -1 ){
                    orden = 0;
                    contsub++;
                }else if( orden == 0 ){
                    orden = 1;
                }
            }else if( i < ant){
               if( orden == 1 ){
                    orden = 0;
                    contsub++;
                }else if( orden == 0 ){
                    orden = -1;
                }
            }
        }
        ant=i;
    }

    cout<<contsub<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

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

    int flag = 1;
    for(int i = 0;i < n;++i){
        if(a[i] %2 == 0){
            if(a[i]%3 != 0 && a[i]%5 != 0){
                flag = 0;
                break;
            }
        }
    }

    if(flag == 1){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
    
int main()
{
    int n;
    
    scanf("%d", &n);
    int i;
    for (i = 3; i <= n; i++) {
        int x = i;
        if (x%3==0) {
            printf(" %d", i);
        } else {
            while (x > 0) {
                if (x%10==3) {
                    printf(" %d", i);
                    break;
                }
                x/=10;
            }
        }
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 2732
#include <iostream>
#include <string>

int K;
bool appeared[1'000'000];

int main() {

    std::cin >> K;

    int mod = 0;

    // i = 1
    if ((mod = 7 % K)== 0) {
        std::cout << 1 << std::endl;
        return 0;
    }

    for (int i=2; ; ++i) {
        mod = ((mod * 10) % K + 7) % K;

        if (mod == 0) {
            std::cout << i << std::endl;
            return 0;
        }

        if (appeared[mod]) {
            break;
        }

        appeared[mod] = true;
    }

    std::cout << -1 << std::endl;
    return 0;

}


Measured memory_bytes: 4572
#include <iostream>
#include <string>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  int x;
  cin >> x;
  if(x < 1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=2e9;

int main(){
    int k,s;
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            if(0<=s-i-j&&s-i-j<=k){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256