jiahuimbzuai/CoQuIR huggingface dataset:
//  [c]
#include<stdio.h>
int lb(int l,int r,long long n,long long *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<d[m]?lb(l,m,n,d):lb(m+1,r,n,d);
}
int main(){
  long long n,m,x,a[200020],b[200020],s[200020],t[200020],i,j,ans=0;
  scanf("%lld %lld %lld",&n,&m,&x);
  for(i=0;i<n;i++)scanf("%lld",&a[i]);
  for(i=0;i<m;i++)scanf("%lld",&b[i]);
  for(i=0;i<n;i++)s[i+1]=s[i]+a[i];
  for(i=0;i<m;i++)t[i+1]=t[i]+b[i];
  //for(i=0;i<n+1;i++)printf("%lld ",s[i]);printf("\n");
  //for(i=0;i<m+1;i++)printf("%lld ",t[i]);printf("\n");
  for(i=0;i<=n;i++){
    if(x<s[i])continue;
    j=lb(0,m+1,x-s[i],t);
    if(i+j>ans)ans=i+j;
  }
  printf("%lld\n",ans-1);
  return 0;
}
//  [go]
package main

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

var N, M, K int
var As, Bs, sumA, sumB []int

func main() {
	N, M, K = ReadInt(), ReadInt(), ReadInt()
	As = ReadInts(N)
	Bs = ReadInts(M)

	sumA = []int{0}
	sumB = []int{0}

	for i := 0; i < len(As); i++ {
		s := sumA[i] + As[i]
		sumA = append(sumA, s)
	}
	for i := 0; i < len(Bs); i++ {
		s := sumB[i] + Bs[i]
		sumB = append(sumB, s)
	}

	left := 0
	right := N + M + 1
	for right-left > 1 {
		mid := (right + left) / 2
		if isOK(mid) {
			left = mid
		} else {
			right = mid
		}
	}
	fmt.Println(left)
}

func isOK(n int) bool {
	for a := 0; a <= n; a++ {
		b := n - a
		if a > N {
			break
		}
		if b > M {
			continue
		}
		total := sumA[a] + sumB[b]
		if total <= K {
			return true
		}
	}
	return false
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
//  [go]
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m, k int
	fmt.Fscan(r, &n, &m, &k)

	ruia := make([]int, n+1)
	ruib := make([]int, m+1)
	ruia[0] = 0
	ruib[0] = 0

	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscan(r, &tmp)
		ruia[i+1] = ruia[i] + tmp
	}

	for i := 0; i < m; i++ {
		var tmp int
		fmt.Fscan(r, &tmp)
		ruib[i+1] = ruib[i] + tmp
	}
	ans := 0
	bj := m
	for i := 0; i < n+1; i++ {
		if ruia[i] > k {
			break
		}

		for ruia[i]+ruib[bj] > k && bj >= 0 {
			bj--
		}
		if bj < 0 {
			break
		}
		if i+bj > ans {
			ans = i + bj
		}
	}
	fmt.Println(ans)
}
//  [ruby]
N,M,K = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = [0]
d = [0]

a.each do |x|
  c << c[-1] + x
end

b.each do |x|
  d << d[-1] + x
end

ans = 0

c.each_with_index do |x,i|
  break if x > K
  while d[M] > K - x
    M -= 1
  end
  ans = [ans,i + M].max
end

puts ans
//  [ruby]
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]
K = lines[0][2]

cumtime_a = []
for i in 1..N do
  if i == 1 then
    cumtime_a[i-1] = lines[1][0]
  else
    cumtime_a[i-1] = cumtime_a[i-2] + lines[1][i-1]
  end
end
cumtime_b = []
for i in 1..M do
  if i == 1 then
    cumtime_b.push[i-1] = lines[2][0]
  else
    cumtime_b.push[i-1] = cumtime_b[i-2] + lines[2][i-1]
  end
end
  
can_read = true
books_read = 0
time = 0
sa_a = 0
sa_b = 0
while can_read do
  if lines[1] == [] then
    if lines[2] == [] then
      can_read = false
    else
      next_time = lines[2].shift
      cumtime_b.shift
      sa_b += next_time
    end
  else
    if lines[2] == [] then
      next_time = lines[1].shift
      cumtime_a.shift
      sa_a += next_time
    else
      can_read_a = cumtime_a.bsearch_index{|x| x + time > K + sa_a}
      can_read_b = cumtime_b.bsearch_index{|x| x + time > K + sa_b}
      if can_read_a == nil then
        can_read_a = lines[1].length
      end
      if can_read_b == nil then
        can_read_b = lines[2].length
      end
      if can_read_a > can_read_b then
        next_time = lines[1].shift
        cumtime_a.shift
        sa_a += next_time
      elsif can_read_a < can_read_b then
        next_time = lines[2].shift
        cumtime_b.shift
        sa_b += next_time
      elsif lines[1][0] < lines[2][0] then
        next_time = lines[1].shift
        cumtime_a.shift
        sa_a += next_time
      else
        next_time = lines[2].shift
        cumtime_b.shift
        sa_b += next_time
      end
    end
  end
  if can_read and next_time + time <= K then
    time += next_time
    books_read += 1
  else
    can_read = false
  end
end
      
puts books_read
//  [ruby]
def binarySearch(arr, key)
    left = -1
    right = arr.size
    while (right-left).abs > 1
        mid = (right+left) / 2
        if arr[mid] > key then
            right = mid
        else
            left = mid
        end
    end
    return left
end

a,b,n = gets.split.map(&:to_i)
a_book = gets.split.map(&:to_i)
b_book = gets.split.map(&:to_i)
a_ruikei = [0] 
b_ruikei = [0]
cnt = []

sum = 0
a_book.each do |i|
  sum += i
  a_ruikei << sum
end

sum = 0
b_book.each do |i|
  sum += i
  b_ruikei << sum
end

a_only = binarySearch(a_ruikei, n)
b_only = binarySearch(b_ruikei, n)
cnt << a_only
cnt << b_only

a_ruikei.each_with_index do |i, index|
   nokori = n - i
   if nokori >= 0
     b_sum = binarySearch(b_ruikei, nokori)
     cnt << index + b_sum
   else
     break
   end
end

b_ruikei.each_with_index do |i, index|
   nokori = n - i
   if nokori >= 0
     a_sum = binarySearch(a_ruikei, nokori)
     cnt << index + a_sum
   else
     break
   end
end

cnt = cnt.max
puts cnt
//  [rust]
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: i128,
        a: [i128; n as usize],
        b: [i128; m as usize],
    }

    solve(n, m, k, &a, &b);
}

fn solve(n: usize, m: usize, k: i128, a: &[i128], b: &[i128]) {
    let mut x: Vec<i128> = vec![0; n + 1];
    for i in 0..n {
        x[i + 1] = x[i] + a[i];
    }

    let mut y: Vec<i128> = vec![0; m + 1];
    for i in 0..m {
        y[i + 1] = y[i] + b[i];
    }

    let mut ans = 0;
    let mut j = m;
    for i in 0..(n + 1) {
        if x[i] > k {
            break;
        }
        while x[i] + y[j] > k {
            j -= 1;
        }
        ans = std::cmp::max(ans, i + j);
    }

    println!("{}", ans);
}
//  [rust]
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: i128,
        a: [i128; n as usize],
        b: [i128; m as usize],
    }

    solve(n, m, k, &a, &b);
}

fn solve(n: usize, m: usize, k: i128, a: &[i128], b: &[i128]) {
    let mut x: Vec<i128> = vec![0; n + 1];
    for i in 0..n {
        x[i + 1] = x[i] + a[i];
    }

    let mut y: Vec<i128> = vec![0; m + 1];
    for i in 0..m {
        y[i + 1] = y[i] + b[i];
    }

    let mut ans = 0;
    let mut j = m;
    for i in 0..(n + 1) {
        if x[i] > k {
            break;
        }
        while x[i] + y[j] > k {
            j -= 1;
        }
        if ans < i + j {
            ans = i + j;
        }
    }

    println!("{}", ans);
}
//  [swift]
let NMK = readLine()!.split(separator: " ").compactMap { Int($0) }
let k = NMK[2]
let AN = readLine()!.split(separator: " ").compactMap { Int($0) }
let BM = readLine()!.split(separator: " ").compactMap { Int($0) }

var sumAN: [Int] = [0]
for i in 0..<AN.count {
    sumAN.append(sumAN[i] + AN[i])
}
var sumBM: [Int] = [0]
for i in 0..<BM.count {
    sumBM.append(sumBM[i] + BM[i])
}

var bIndex = sumBM.count - 1

// Caluculate maximized count on each sumA
let maxCountList = sumAN.enumerated().map { sumA -> Int in
    while sumA.element + sumBM[bIndex] > k {
        if bIndex == 0 {
            return 0
        } else {
            bIndex -= 1
        }
    }
    return sumA.offset + bIndex
}
print(maxCountList.max() ?? 0)
//  [swift]
func readIntArray() -> [Int] {
    readLine()!.split(separator: " ").map({Int($0)!})
}

let max = 10000000000
let line = readIntArray()
let (N, M, K) = (line[0], line[1], line[2])

let A = readIntArray()
let B = readIntArray()

var sum = 0
var sumA: [Int] = []
A.forEach({
    sumA.append($0 + sum)
    sum += $0
})

sum = 0
var sumB : [Int] = []
B.forEach({
    sumB.append($0 + sum)
    sum += $0
})

func findIndex(time: Int) -> Int {
    var left = -1
    var right = sumB.count
    while left < right - 1 {
        let mid = (left + right) / 2
        if sumB[mid] <= time {
            left = mid
        } else {
            right = mid
        }
    }
    return left + 1
}

var count: Int = findIndex(time: K)

for i in 0..<N {
    let time = K - sumA[i]
    if time < 0 {
        break
    }
    let temp: Int = i + 1 + findIndex(time: time)
    if temp > count {
        count = temp
    }
}
print(count)
//  [swift]
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func binarySearch(_ inputArray: [Int], _ searchItem: Int) -> Int {
    if inputArray[inputArray.count - 1] < searchItem {
      return inputArray.count
    }
  
    var lowerIndex = 0
    var upperIndex = inputArray.count
    
    while true {
        let currentIndex = (lowerIndex + upperIndex) / 2
        
        if inputArray[currentIndex] == searchItem {
            return currentIndex
        }
        if lowerIndex == currentIndex {
            if inputArray[upperIndex] == searchItem {
                return upperIndex
            } else {
                return currentIndex
            }
        }
        
        if inputArray[currentIndex] > searchItem {
            upperIndex = currentIndex
        } else {
            lowerIndex = currentIndex
        }
    }
}

func main() {
    let line = readInts()
    // let n = line[0]
    // let m = line[1]
    let k = line[2]
    let a_tachi = readInts()
    let b_tachi = readInts()
    
    var a_acc: [Int] = [0]
    var b_acc: [Int] = [0]
    
    for i in 1...a_tachi.count {
        a_acc.append(a_acc[i - 1] + a_tachi[i - 1])
    }
    
    for j in 1...b_tachi.count {
        b_acc.append(b_acc[j - 1] + b_tachi[j - 1])
    }
    
    var ans = 0
    for j in 0...b_tachi.count {
        if b_acc[j] > k {
            break
        }
        let bookCount = j + binarySearch(a_acc, k - b_acc[j])
        if ans < bookCount {
            ans = bookCount
        }
    }
    
    print(ans)
}

main()
//  [typescript]
import { readFileSync } from 'fs'

function calcSum(val: number[]) : number[] {
  let sum = []
  let sumAll = 0
  sum.push(sumAll)
  for (let one of val) {
    sumAll += one;
    sum.push(sumAll)
  }
  return sum
}

function lower_bound(arr: number[], n: number) {
  let first = 0, last = arr.length - 1, middle;
  while (first <= last) {
      middle = 0 | (first + last) / 2;
      if (arr[middle] < n) first = middle + 1;
      else last = middle - 1;
  }
  return first;
};

function upper_bound(arr: number[], n: number) {
  var first = 0, last = arr.length - 1, middle;
  while (first <= last) {
      middle = 0 | (first + last) / 2;
      if (arr[middle] <= n) first = middle + 1;
      else last = middle - 1;
  }
  return first;
};

function main(input: string[]) {
  let ans = 0
  let [N, M, K] = input[0].split(' ').map(v=>parseInt(v, 10))
  let [...A] = input[1].split(' ').map(v=>parseInt(v, 10))
  let [...B] = input[2].split(' ').map(v=>parseInt(v, 10))

  let aSum = calcSum(A)
  let bSum = calcSum(B)

  for (let i = 0; i <= N; i++) {
    let nokori = K - aSum[i]
    if (nokori < 0) break;
    let idx = upper_bound(bSum, nokori) - 1
    ans = Math.max(ans, idx + i)
  }
  console.log(ans)
}

let lines: string[] = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', function (line: string) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines)
});
//  [python]
s=input()
if s[:-1].count("C")>=1:
    x=s.index("C")
    if s[x:].count("F")>=1:
        print("Yes")
    else:
        print("No")
else:
    print("No")
    exit()
//  [python]
s=input()

c=False

for i in range(len(s)):
    if c==False and s[i]=="C":
        c=True
    elif c==True and s[i]=="F":
        print("Yes")
        exit()
print("No")
//  [python]
import sys
s=input()
if("C" in s and "F" in s):
  for i in range(len(s)):
    if(s[i]=="C"):
      c=i
      break
  for i in range(len(s))[::-1]:
    if(s[i]=="F"):
      f=i
      break
  if(c<f):
    print("Yes")
    sys.exit()
print("No")
//  [python]
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    C = False
    F = False
    for s in S:
        if s=="C":
            C=True
        if s=="F":
            if C:
                F=True

    if C and F:
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()
//  [python]
def main():
    s = input()
    for i, c1 in enumerate(s):
        if c1 == 'C':
            for c2 in s[i+1:]:
                if c2 == 'F':
                    print('Yes')
                    return
            else:
                print('No')
                return
    else:
        print('No')

if __name__ == '__main__':
    main()
//  [java]
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        char[] s = in.ns().toCharArray();
        int c = -1, f = s.length;
        for (int i = 0; i < s.length; i++) {
            if(c==-1&&s[i]=='C') c = i;
            if(f==s.length&&s[s.length-i-1]=='F') f = s.length-i-1;
        }
        out.println((c>-1&&c<f&&f<s.length)?"Yes":"No");
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    String s = null;
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
      s = br.readLine();
    } catch (IOException e) {
      e.printStackTrace();
    }
    s = s.replaceAll("[ABDEG-Z]","");
    if (s.contains("CF")) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}
//  [java]
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		String S = sc.next();
		int inc = S.indexOf('C');
		int inf = S.lastIndexOf('F');
		if(inc != -1 && inf != -1 & inc < inf) System.out.println("Yes");
		else System.out.println("No");
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}
//  [java]
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		boolean c = false;
		for(int i =0;i<s.length();i++){
			if(s.charAt(i)=='C'){
				c = true;
				continue;
			}
			if(c==true && s.charAt(i)=='F'){
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}
//  [java]

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;



class Main {

	
	public static void main(String[] argv){

		Scanner sc = new Scanner(System.in);
		
		String s = sc.nextLine();
		
		char[] c = s.toCharArray();
		
		boolean findC = false,findF = false;
		
		for(int i = 0;i<c.length;i++){
			if(!findC && c[i] == 'C'){
				findC = true;
			}
			if(findC && c[i] == 'F'){
				findF = true;
				break;
			}
		}
		
		if(findC && findF){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}


}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        String S = ns();

        if (S.indexOf('C') == -1 || S.indexOf('F') == -1) {
            out.println("No");
            return;
        }
        int cindex = 0, findex = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'C') cindex = i;
            if (S.charAt(i) == 'F') findex = i;
        }

        if (cindex < findex) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
//  [cpp]
#include<cstdio>
char s[101];
int p,tmp,i;
bool flag=false;
inline void read()
{
	char ch;
	while(ch<'A'||ch>'Z') ch=getchar();
	while(ch>='A'&&ch<='Z') s[p++]=ch,ch=getchar();
}
int main()
{
	read();
	for(i=0;i<p;i++) if(s[i]=='C') {flag=true,tmp=i;break;}
    for(i=tmp+1;i<p;i++) if(flag&&s[i]=='F') {printf("Yes\n");return 0;}
    printf("No\n");
	return 0;
}
//  [cpp]
#include<cstdio>
#include<cstring>
char a[10010];
bool c, f;
int main()
{
    scanf("%s",a);
    for(int i=0;i<strlen(a);i++)
    {
        if(a[i]=='C')
        {
            c=true;
        }
        if(a[i]=='F'&&c==true)
        {
            f=true;
        }
    }
    if(f==true)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}
//  [cpp]
#include<cstdio>
#include<cstring>
char a[10010]; 
bool c,f;
int main() {
    scanf("%s",a); 
    for(int i=0; i<strlen(a); i++) 
    {
        if(a[i]=='C') 
            c=true;
        if(a[i]=='F'&&c==true) 
            f=true; 
    }
    if(f==true) 
        printf("Yes\n");
    else 
        printf("No\n"); 
    return 0;
}
//  [cpp]
/*
*/

#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-6
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 350

using namespace std;

const int INF = 1e9;
const int N = 3000;

int main(){
	//freopen("fabro.in","r",stdin);
	//freopen("fabro.out","w",stdout);
	//freopen("F:/in.txt", "r", stdin);
	//freopen("F:/output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	string st;

	cin >> st;
	for (int i = 0; i < st.size(); i++)
	{
		for (int j = i + 1; j < st.size(); j++)
		{
			if (st[i] == 'C'&&st[j] == 'F')
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	cin.get(); cin.get();
	return 0;
}
//  [cpp]
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	string S; cin >> S;
	int C = INF, F = -INF;
	rep(i, 0, S.size()) {
		if (S[i] == 'C')C = min(C, i);
		if (S[i] == 'F')F = max(F, i);
	}
	if (C < F)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
//  [cpp]
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

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

int main() {
    string s;
    cin >> s;
    int state = 0;
    for (int j = 0 ; j < s.size(); ++j) {
        if (state == 0 && s[j] == 'C') {
            ++state;
        }
        if (state == 1 && s[j] == 'F') {
            ++state;
        }
    }
    if (state == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}
//  [c]
#include<stdio.h>
#include<string.h>
int main()
{
	char  a[101];
    int l,i,j=0,f,b,c=0;
    gets(a);
    l=strlen(a);
    for(i=0;i<l;i++)
    {
    	if(a[i]=='C')
		 {    f=i;
		 c=1;}
    		 	if(a[i]=='F'){
    		b=i;j=1;
    		 }
    	
    }
    
     
  if(c&j&f<b)
    printf("Yes\n");
    else
    printf("No\n");
    
   return 0;
	
}
//  [c]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void){
  int i,j;
  char s[101];
  scanf("%s",s);
  for(i=0;i<strlen(s);i++){
    if(s[i]=='C'){
      for(j=i+1;j<strlen(s);j++){
        if(s[j]=='F'){
          puts("Yes");
          exit(0);
        }
      }
    }
  }
  puts("No");
  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>

int main(void){

  char s[101];
  scanf("%s", s);
  int c = 0;
  int cf = 0;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == 'C') {
      c = 1;
    }
    if (c == 1 && s[i] == 'F') {
      cf = 1;
      break;
    }
  }
  if (cf == 1) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>

int main(){
  char S[101];
  scanf("%s",S);
  int l=strlen(S);
  int c=0;
  for(int i=0;i<l;i++){
    if(c==0 && S[i]=='C') c=1;
    else if(c==1 && S[i]=='F') c=2;
  }
  if(c==2) printf("Yes\n");
  else printf("No\n");
  return 0;
}
//  [c]
#include<stdio.h>
#include<string.h>

int main(void)
{
  char s[128];
  scanf("%s",s);
  int len=(int)strlen(s);
  int flag1=0,flag2=0;
  for(int i=0;i<len;i++){
    if(flag2==0&&s[i]=='C'){
      flag1=1;
    }
    if(flag1==1&&s[i]=='F'){
      flag2=1;
    }
  }
  if(flag1&&flag2){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}
//  [javascript]
const fs = require("fs");

const input = fs.readFileSync(0).toString().trim();
const indexOfC = input.indexOf("C");
process.stdout.write(indexOfC === -1 || input.indexOf("F", indexOfC + 1) === -1 ? "No\n" : "Yes\n");
//  [javascript]
function Main(input) {
	input = input.split("");
	var flag = 0;
	for(var i=0;i<input.length;i++){
		switch(flag){
			case 0:
			if(input[i]=="C")flag++;
			break;
			case 1:
			if(input[i]=="F")flag=2;
		}
	}
	if(flag==2){
		console.log("Yes")
	}else{
		console.log("No")
	}
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    
    let flagC = false;
    
    for(let i in S) {
        if(S[i] === "C") flagC = true;
        if(S[i] === "F" && flagC) {
            console.log("Yes");
            return;
        }
    }
    
    console.log("No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function Main(input) {
  var input = input.split("\n");
  var string = input[0];
  var c,f,Cfound = 0;
  for(var i = 0;i < string.length;i++){
    if(string[i] == "C" && !Cfound){
      c = i;
      Cfound++;
    };
    if(Cfound && string[i] == "F"){
      f = i;
      return console.log("Yes");
    }
  };
  return console.log("No");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
// parameter "input" gets all data
function Main(input) {
  var s = input.trim();

  var index_for_F = -1;
  var rev_index_for_F = s.split('').reverse().join('').indexOf('F');
  if (rev_index_for_F !== -1){
    index_for_F = s.length - rev_index_for_F - 1;
  }

  var index_for_C = -1;
  var rev_index_for_C = s.split('').reverse().join('').indexOf('C');
  if (rev_index_for_C !== -1){
    index_for_C = s.length - rev_index_for_C - 1;
  }

  if(index_for_C<index_for_F && (index_for_F !== -1) && (index_for_C !== -1)){
    console.log('Yes');
  }else{
    console.log('No');
  }
}
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
	input = input.trim();
  if(input.indexOf("C") == -1 || input.indexOf("F") == -1){
     console.log("No");
    return;
  }
  var list = [];
  for(var i = 0; i < input.length; i++){
    var tmp = input.slice(i,i+1);
    if(tmp == "C" || tmp == "F"){
       list.push(tmp);
       }
  }
  list = list.join("");
  console.log((list.indexOf("CF") != -1) ? "Yes" : "No");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	foundC := false
	for _, r := range s {
		if foundC && r == 'F' {
			fmt.Println("Yes")
			return
		} else if r == 'C' {
			foundC = true
		}
	}
	fmt.Println("No")
}
//  [go]
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextString(scanner)
	n := len(s)
	c := 0
	for i := 0; i < n; i++ {
		if s[i] == 'C' {
			c++
			continue
		}
		if s[i] == 'F' && c > 0 {
			fmt.Fprintln(writer, "Yes")
			return
		}
	}
	fmt.Fprintln(writer, "No")
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scanner()
	c := false
	f := false
	for _, v := range s {
		if string(v) == "C" {
			c = true
		}
		if string(v) == "F" && c {
			f = true
		}
	}
	if c && f {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [go]
package main

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

func main() {
	s := ReadString()
	c := len(s)
	f := -1
	for i := 0; i < len(s); i++ {
		if s[i] == 'C' && i < c {
			c = i
		}
		if s[i] == 'F' && i > f {
			f = i
		}
	}
	if c < f {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
//  [go]
package main

import (
	"fmt"
	"strings"
)

func main() {
	// Code for A - CF
	var s string
	fmt.Scan(&s)

	C := strings.Index(s, "C")
	F := strings.LastIndex(s, "F")

	if C != -1 && F != -1 && C < F {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [ruby]
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=gets.chomp
if S=~/^.*C.*F.*$/
    puts "Yes"
else
    puts "No"
end
//  [ruby]
puts (gets.chomp[/^.*C.*F.*$/])? "Yes" : "No"
//  [ruby]
state = 0
gets.chomp.chars do |c|
  state = 1 if state == 0 && c == "C"
  state = 2 if state == 1 && c == "F"
end
puts state == 2 ? "Yes" : "No"
//  [ruby]
s = gets.chomp.split("")
c = false
f = false
s.each do |i|
    c = true if i == "C"
    f = true if c && i == "F"
end
puts c && f ? "Yes" : "No"
//  [ruby]
s = gets.chomp
c_existing = false
f_existing = false
s.each_char do |c|
  if !c_existing && c == "C"
    c_existing = true
  elsif c_existing && c == "F"
    f_existing = true
  end
end
puts c_existing && f_existing ? "Yes" : "No"
//  [ruby]
s = gets.chomp
_C = false
_F = false
s.each_char do |str|
    if str=="C"
        _C = true
    end
    if str=="F" && _C
        _F = true
    end
end
if _C && _F
    puts "Yes"    
else 
    puts "No"   
end
//  [rust]
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let s = read_as_string();

    if let Some(x) = s.find("C"){
        if let Some(y) = s.rfind("F"){
            if x < y{
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}
//  [rust]
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let s = vecchar();
    let mut c = s.len();
    let mut f = s.len();
    for i in 0..s.len() {
        if c == s.len() && s[i] == 'C' {
            c = i;
        }
        if s[i] == 'F' {
            f = i;
        }
    }

    if c == s.len() || f == s.len() {
        println!("No");
        return;
    }

    println!("{}", if c < f { "Yes" } else { "No" })
}
//  [rust]
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        s: Chars
    };
    match s
        .iter()
        .position(|&s_i| s_i == 'C')
        .and_then(|i_c| s.iter().skip(i_c + 1).position(|&s_i| s_i == 'F'))
    {
        None => println!("No"),
        Some(_) => println!("Yes"),
    };
}
//  [rust]
use proconio::input;

fn main() {
  input! {
    s: String
  };

  let i = s.find('C').unwrap_or(s.len());
  let j = s.rfind('F').unwrap_or(0);
  if i < j {
    println!("Yes");
  } else {
    println!("No");
  }
}
//  [rust]
use proconio::input;

fn main() {
    input! {
        s: String,
    }

    let ans = match (s.find('C'), s.rfind('F')) {
        (Some(c), Some(f)) if c < f => "Yes",
        _ => "No",
    };

    println!("{}", ans);
}
//  [swift]
var i=0
for c in readLine()!.characters {
  if i<1&&c=="C"||i>0&&c=="F"{i++}
}
print(i>1 ?"Yes":"No")
//  [typescript]
function main(input) {
  const s = input.trim();
  let result = "No";
  const indexC = s.indexOf("C");
  const indexF = s.lastIndexOf("F");
  if (indexC !== -1 && indexF !== -1 && indexC < indexF) {
    result = "Yes";
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
console.log(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')[0].match(/C.*F/) ? 'Yes' : 'No')
//  [python]
import sys
input = sys.stdin.readline
from fractions import gcd
def lcm(a, b):
    return a*b // gcd(a, b)
def group(s, t, u):
    su = (s - 1) // u
    tu = t // u
    return  tu - su

A, B, C, D = map(int, input().split())
ABC = group(A, B, C)
ABD = group(A, B, D)
ABCD = group(A, B, lcm(C,D))
U = B - A + 1
print(U-(ABC+ABD-ABCD))
//  [python]
from decimal import *
A,B,C,D=list(map(int,input().split()))

def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    
    while True:
#         print(x,y)
        y_ = x % y
        if y_ == 0:
            return y
        x = y
        y = y_

def lcm(a,b):
    ans=Decimal(a*b)/Decimal(gcd(a,b))
    return ans.as_integer_ratio()[0]

CD=lcm(C,D)
len_all = B-A+1
len_c = B//C-(A-1)//C
len_d = B//D-(A-1)//D
len_c_and_d = B//CD-(A-1)//CD

ans=len_all-len_c-len_d+len_c_and_d 
print(int(ans))
//  [python]
import fractions 

A, B, C, D = map(int, input().rstrip().split(' '))

gcd = C * D // fractions.gcd(C, D)

print(B - A + 1 - (B // C - (A - 1) // C) - (B // D - (A - 1) // D) + (B // gcd - (A - 1) // gcd))
//  [java]
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        a--;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long total = b - a;

        long divD = b / d - a / d;
        long divC = b / c - a / c;

        long lcm = getLcm(c, d);
        long divL = b / lcm - a / lcm;

        System.out.println(total - (divD + divC - divL));

    }

    private static long getLcm(long n, long m) {

        long bn = n;
        long bm = m;

        while (n != m) {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        }
        return n;
    }
}
//  [java]
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long st = in.nextLong();
    long en = in.nextLong();
    long mod1 = in.nextLong();
    long mod2 = in.nextLong();
    in.close();
    long mod1and2 = lcmul(mod1, mod2);
    long countand = en / mod1and2;
    countand -= (st - 1) / mod1and2;
        long countor = en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2;
    long ans = en - st - countor + countand  + 1;
    System.out.println(ans);
  }
  public static long gcdiv(long a, long b) {
    while (a != b) {
      if (a > b) {
        a -= b;// * (a / b);
      } else if (b > a) {
        b -= a;// * (b / a);
      }
    }
    return a;
  }
  public static long lcmul(long a, long b) {
    long gcdiv = gcdiv(a, b);
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
  public static long lcmul(long a, long b, long gcdiv) {
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
}
//  [java]
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();

		// for (int i = A; i < B+1; i++) {
		// if(i%C!=0&&i%D!=0)
		// cnt++;
		// };
		// とやると10^18なのでたぶんTLE
		// BまでのCの倍数の数:NbC
		// Dの倍数の数:NbD
		// CDの倍数の数:NbCD
		// B-(NbC+NbD-NbCD)って話だと思う
		// 同様にA-1までのCの倍数の数:NaC

		// 入力例2に助けられたC*Dに公約数があるとそれで重複する
		// NbCDは最小公倍数の倍数
		// 最小公倍数はC*D/最大公約数
		// これでもO(C)でやったらTLEでは
		// ユークリッドの互除法がいいらしい

		// long maxKouyakusu = 1;
		// for (int i = 2; i < C + 1; i++) {
		// if (C % i == 0 && D % i == 0)
		// maxKouyakusu = i;
		// }
		// System.out.println(maxKouyakusu);
		long smaller;
		long r_i;
		long r_i1;
		long t_A = C;
		long t_B = D;
		if (t_A >= t_B) {
			smaller = t_B;
			r_i = t_A - t_B;
			r_i1 = t_B;
		} else {
			smaller = t_A;
			r_i = t_B - t_A;
			r_i1 = t_A;
		}
		while (r_i != 0) {
			t_A = smaller;
			t_B = r_i;
			r_i1 = r_i;
			if (t_A >= t_B) {
				smaller = t_B;
				r_i = t_A - t_B;
			} else {
				smaller = t_A;
				r_i = t_B - t_A;
			}
		}

		long NbC = B / C;
		long NbD = B / D;
		long NbCD = B / (C * D / r_i1);

		long NaC = (A - 1) / C;
		long NaD = (A - 1) / D;
		long NaCD = (A - 1) / (C * D / r_i1);

		long ans = B - NbC - NbD + NbCD - (A - 1 - NaC - NaD + NaCD);

		System.out.println(ans);

	}
}
//  [cpp]
#include <iostream>
#include<math.h>

using namespace std;

long long int LCM(long long int p,long long int q)
{
    long long int m,n;
    m=p;
    n=q;
    while(m!=n)
    {
        if(m>n)
            n=n+q;
        if(m<n)
            m=m+p;
    }
    return m;
}

int main()
{
    long long int a,b,c,d,e,f,g,h,l;
    cin>>a>>b>>c>>d;
    l=LCM(c,d);
    e=b-a+1;
    f=(b/c)-(a/c);
    g=(b/d)-(a/d);
    h=(b/l)-(a/l);
    if(a%c==0)
        f++;
    if(a%d==0)
        g++;
    if(a%l==0)
        h++;
    cout<<(e-f-g+h);
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

long int gcd(long int x, long int y) {
  if (x < y) {
    return gcd(x, y - x);
  } else if (x > y) {
    return gcd(x - y, y);
  } else {
    return x;
  }
}

long int lcm(long int x, long int y) {
  return (x * y) / gcd(x, y);
}

int main() {
  long int a, b, c, d;
  cin >> a >> b >> c >> d;
  long int ans = b - a + 1;
  ans -= b / c - (a - 1) / c;
  ans -= b / d - (a - 1) / d;
  ans += b / lcm(c, d) - (a - 1) / lcm(c, d);
  cout << ans << endl;
}
//  [cpp]
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(void)
{
	long long int a, b,c,d;
	long long int lc, ld,min;
	long long int count = 0;
	long long int count2 = 0;
	cin >> a >> b>>c>>d;
	count = b / c;
	count = count + b / d;
	//cとdの最小公倍数の判定
	long long int lci=1;
	long long int ldi = 1;
	lc = c;
	ld = d;
	while (1)
	{
		
		if (lc < ld)
		{
			lci++;
			lc = c * lci;
		}
		else if (lc == ld)
		{
			min = lc;
			break;
		}
		else if (lc > ld)
		{
			ldi++;
			ld = d * ldi;
		}

}
	count = count - b / min;
	count2 = (a - 1) / c;
	count2 = count2 + (a - 1) / d;
	count2 = count2 - (a - 1) / min;
	count = b - count;
	count2 = a-1 - count2;
	count = count - count2;
	cout << count << endl;
	
	return 0;

}