codeparrot/codecomplex huggingface dataset:
// Problem: 343_A. Rational Resistance
// Time complexity: constant
import java.awt.Point;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;


public class A {

    static StringTokenizer st;
    static BufferedReader br;
    static PrintWriter pw;
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        long x = nextLong();
        long y = nextLong();
        long ans = 0;
        while (x > 0 && y > 0) {
            if (x > y) {
                ans += x / y;
                x %= y;
            }
            else {
                ans += y / x;
                y %= x;
            }
        }
        System.out.println(ans);
    }
    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
    private static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
    private static String next() throws IOException {
        while (st==null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
}
// Problem: 343_A. Rational Resistance
// Time complexity: constant
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long a = in.nextLong();
        long b = in.nextLong();
        long res = 0;
        while (b > 0) {
            res += a / b;
            long t = a % b;
            a = b;
            b = t;
        }
        out.println(res);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    }
// Problem: 343_A. Rational Resistance
// Time complexity: constant
import java.util.*;
public class c {
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    long a = input.nextLong(), b = input.nextLong();
    System.out.println(gcd(a, b));
}
static long gcd(long a, long b)
{
    if(b==1) return a;
    if(a==1) return b;
    if(a>b) return a/b + gcd(b, a%b);
    return b/a + gcd(a, b%a);
}
}
// Problem: 343_A. Rational Resistance
// Time complexity: constant
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class A {

	public static void main(String[] args) throws Exception {
		new A().doit();
	}
	
	private void doit() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		long a = Long.parseLong(st.nextToken());
		long b = Long.parseLong(st.nextToken());
		long ans = 0;
		while(a > 0 && b > 0) {
			if (a > b) {
				ans += a / b;
				a %= b;
			} else {
				ans += b / a;
				b %= a;
			}
		}
		
		System.out.println(ans);
	}
	
	
}
// Problem: 343_A. Rational Resistance
// Time complexity: constant
import java.util.*;

public class A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long A = in.nextLong();
        long B = in.nextLong();
        System.out.println(f(A,B));
    }
    static long f(long A, long B) {
        if(A==0) return 0;
        if(A < B) return f(B,A);
        else {
            long k = A/B;
            return k+f(A-B*k, B);
        }
    }
}
// Problem: 343_A. Rational Resistance
// Time complexity: constant
import java.util.*;

public class p343A 
{
    static long n = 0;
    static void resistance(long a, long b) 
    {
        n += a/b;
        a %= b;
        if(a!=0) resistance(b, a);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        long b = in.nextLong();
        resistance(a, b);
        System.out.println(n);
    }
}
// Problem: 343_A. Rational Resistance
// Time complexity: constant
import java.io.*;
import java.util.*;

public class RationalResistance {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());
        long a = Long.parseLong(st.nextToken());
        long b = Long.parseLong(st.nextToken());
        System.out.println(f(a,b));
    }
    
    public static long f(long a, long b)
    {
        if (a == 1 || b == 1)
            return a+b-1;
        if (a > b)
            return f(a%b,b) + a/b;
        else
            return f(a,b%a) + b/a;
    }
}
// Problem: 343_A. Rational Resistance
// Time complexity: constant

import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	public long gcd(long a, long b) {
		long tmp;
		while (b > 0) {
			a %= b;
			tmp = a;
			a = b;
			b = tmp;
		}
		return a;
	}
	
	public void solve() throws Exception {
		long a = sc.nextLong();
		long b = sc.nextLong();
		long ans = 0;
		long k = 0;
		if (a == 1 || b == 1) {
			out.println(max(a, b));
			return;
		}
		while (a > 1 && b > 1) {
			if (a > b) {
				k = a / b;
				ans += k;
				a -= (k * b);				
			} else {
				k = b / a;
				ans += k;
				b -= (k * a);
			}
			k = gcd(a, b);
			a /= k;
			b /= k;
		}
		if (a == 1)
			ans += b;
		else
			ans += a;
		out.println(ans);
	}
	
	static Throwable throwable;
	
	BufferedReader in;
	PrintWriter out;
	FastScanner sc;
	
	public static void main(String[] args) throws Throwable {
		Thread thread = new Thread(null, new Solution(), "", (1 << 26));
		thread.start();
		thread.join();
		if (throwable != null) {
			throw throwable;
		}
	}
	
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable throwable) {
			this.throwable = throwable;			
		} finally {
			out.close();
		}		
	}

}

class FastScanner {
	BufferedReader reader;
	StringTokenizer strTok;
	
	public FastScanner(BufferedReader reader) {
		this.reader = reader;
	}
	
	public String nextToken() throws Exception {
		while (strTok == null || !strTok.hasMoreTokens()) {
			strTok = new StringTokenizer(reader.readLine());
		}
		return strTok.nextToken();
	}
	
	public int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}
	
	public long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}
	
	public double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}
}
// Problem: 343_A. Rational Resistance
// Time complexity: constant
import java.util.Scanner;
import java.io.StreamTokenizer;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author KNIGHT0X300
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputStreamReader in = new InputStreamReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    StreamTokenizer in;
    PrintWriter out;
    BufferedReader re;
    Scanner sc;
    public void solve (int testNumber, InputStreamReader in, PrintWriter out)  {

          this.in = new StreamTokenizer(new BufferedReader(in));
          this.re =  new BufferedReader(in);
          this.sc = new Scanner(in);
          this.out = out;
          try {
                      this.solve();
                  } catch (IOException e) {
                      e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                  }
          out.flush();

    }

         void solve() throws IOException
       {
        long a=sc.nextLong(),b=sc.nextLong();
           long ans=0,t;
          while(Math.min(a,b)!=1){
              if(a>b){
                  ans+=a/b;
                  a%=b;

              }
              else{
                  t=b;
                  b=a;
                  a=t;
                  long g=gcd(a,b);
                  a/=g;b/=g;
              }

          }
           ans+=Math.max(a,b);
           out.println(ans);

       }
     public static long gcd(long a, long b) {
       long c = 0;

     if(a<0)  a=-a;
       if(b<0)  b=-b;
       while (b>0) {
          c = a % b;
          a = b;
          b = c;
       }
       return a;
     }


         // do the sum

}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.Scanner;

public class LuckyDivision {
	public static void main (String[] args) {
		Scanner read = new Scanner(System.in);
		int n = read.nextInt();
		
		if (n % 4 == 0 ||
			n % 7 == 0 ||
			n % 47 == 0 ||
			n % 74 == 0 ||
			n % 447 == 0 ||
			n % 474 == 0 ||
			n % 477 == 0 ||
			n % 744 == 0 ||
			n % 747 == 0 ||
			n % 774 == 0)	{
				System.out.println("YES");
			}
		else {
				System.out.println("NO");
		}
		
	}
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.Scanner;
public class LuckyDivison 
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int inp = in.nextInt();
        if(inp%4==0||inp%7==0||inp%47==0||inp%74==0||inp%447==0||inp%474==0||inp%477==0||inp%747==0||inp%774==0||inp%777==0)
        {
          System.out.println("YES");  
        }
        else System.out.println("NO");
          
        
    }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.io.*;
import java.util.*;

public class Test{
    public static void main(String[] args) {
        Scanner in= new Scanner(System.in);
        int n=in.nextInt();
        if(n%7==0 || n%4==0 || n%47==0 || n%74==0 || n%447==0 || n%474==0 || n%477==0 || n%747==0 || n%774==0){
            System.out.println("YES");
        }else
            System.out.println("NO");
        
    }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.Scanner;

public class A122 {
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();

		if (n % 4 == 0 || n % 7 == 0 || n % 44 == 0 || n % 47 == 0
				|| n % 74 == 0 || n % 77 == 0 || n % 444 == 0 || n % 447 == 0
				|| n % 474 == 0 || n % 477 == 0 || n % 744 == 0 || n % 747 == 0
				|| n % 774 == 0 || n % 777 == 0)
			System.out.println("YES");
		else
			System.out.println("NO");

	}
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String input = in.nextLine();
        if (input.equals("1"))
            System.out.println("NO");
        else {
            if (checkNum(input))
                System.out.println("YES");
            else {
                int i = 2;
                while (i < Integer.parseInt(input)) {
                    if (checkNum(i + "")) {
                        if (Integer.parseInt(input) % i != 0)
                            i++;
                        else
                            break;
                    } else
                        i++;
                }
                if (i == Integer.parseInt(input))
                    System.out.println("NO");
                else
                    System.out.println("YES");
            }
        }
    }

    public static boolean checkNum(String s) {
        int i = 0;
        int flag = 0;
        while (i < s.length()) {
            if (s.charAt(i) == '4' || s.charAt(i) == '7') {
                flag = 1;
                i++;
            } else
                return false;
        }
        if (flag == 1)
            return true;
        return false;
    }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.*;
import java.io.*;

public class A {

    ArrayList<Integer> list = new ArrayList<Integer>();
    
    
    boolean valid(int n) {
        Queue<Integer> q = new LinkedList<Integer>();
        q.add(4);
        q.add(7);
        int crnt;
        while(!q.isEmpty()) {
            crnt = q.poll();
            if(n%crnt == 0) return true;
            if ( crnt*10 + 4 <= 1000 ) q.add(crnt*10 + 4);
            if ( crnt*10 + 7 <= 1000 ) q.add(crnt*10 + 7);
        }
        return false;
    }
    
    void dfs(int n){
        if(n>1000)return;
        if(n!=0)list.add(n);
        n = n*10;
        dfs(n+4);
        dfs(n+7);
    }

    void run() {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        if (valid(n)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    public static void main(String[] args) {
        new A().run();
    }

}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class CF {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=null;
        private void  solution() throws IOException{
   int n=nextInt();
   if((n % 4==0 && n>=4)||(n % 7==0 && n>=7) || (n % 44==0 && n>=44) || (n % 47==0 && n>=47) || (n % 77==0 && n>=77) || (n % 74==0 && n>=74)
   || (n % 444==0 && n>=444) || (n % 447==0 && n>=447) || (n % 474==0 && n>=74) || (n % 477==0 && n>=477) || (n % 744==0 && n>=744)
   || (n % 747==0 && n>=747) || (n % 777==0 && n>=777) || (n % 774==0 && n>=774)){
           System.out.println("YES");
   }else{
                System.out.println("NO");}
        }
        String nextToken()throws IOException {
                if(st==null || !st.hasMoreTokens()){
                        st = new StringTokenizer(bf.readLine());
                }
                return st.nextToken();
        }
        int nextInt() throws IOException {
                return Integer.parseInt(nextToken());
        }

        long nextLong() throws IOException {
                return Long.parseLong(nextToken());
        }

        double nextDouble() throws IOException {
                return Double.parseDouble(nextToken());
        }

        public static void main(String args[]) throws IOException {
                new CF().solution();
        }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant

import java.io.*;
import java.util.*;


public class LuckyDivision
{
   public LuckyDivision(Scanner in)
   {
      int   n;

      n = in.nextInt();

      if ( (n % 4 == 0) ||
           (n % 7 == 0) ||
           (n % 44 == 0) ||
           (n % 47 == 0) ||
           (n % 74 == 0) ||
           (n % 77 == 0) ||
           (n % 444 == 0) ||
           (n % 447 == 0) ||
           (n % 474 == 0) ||
           (n % 477 == 0) ||
           (n % 744 == 0) ||
           (n % 747 == 0) ||
           (n % 774 == 0) ||
           (n % 777 == 0) )
         System.out.printf("YES%n");
      else
         System.out.printf("NO%n");
   }


   public static void main(String[] args)
   {
      new LuckyDivision(new Scanner(System.in));
   }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.*;
public class D
{
 public static void main(String args[])
  {
   int n;
   Scanner in = new Scanner (System.in);
   n= in.nextInt();
   if (n%4==0 || n%7==0 || n%44==0 || n%47==0 || n%444==0 || n%447==0 ||
       n%474==0 || n%477==0 || n%744==0 || n%747==0 || n%774==0 || n%777==0)
       System.out.println("YES"); else System.out.println("NO");
  }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author Son-Huy TRAN
 * 
 */
public class P122A_LuckyDivision {

	private static boolean isLuckyNumber(int number) {
		while (number > 0) {
			int digit = number % 10;

			if (digit != 4 && digit != 7) {
				return false;
			}

			number /= 10;
		}

		return true;
	}

	private static boolean isAlmostLuckyNumber(int number) {
		int max = (int) Math.sqrt(number);
		int i = 1;

		while (i <= max) {
			if (number % i == 0
					&& (isLuckyNumber(i) || isLuckyNumber(number / i))) {
				return true;
			}

			i++;
		}

		return false;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			// begin reading inputs
			InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader reader = new BufferedReader(isr);

			// reading inputs
			int input = Integer.parseInt(reader.readLine());

			reader.close();
			isr.close();
			// end reading inputs

			boolean result = isAlmostLuckyNumber(input);
			System.out.println(result ? "YES" : "NO");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.*;
public class Lucky {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();

		if(n%4==0 || n%7==0 || n%47==0 || n%74==0 || n%474==0 || n%447==0 || n%774==0 || n%747==0 || n%477==0 || n%744==0)System.out.println("YES");
		else System.out.println("NO");
	}

}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.*;
import java.io.*;

public class luckydivision {
	public static int i(String s){
		return Integer.parseInt(s);
	}
	public static boolean solve(String k, int n){
		int temp = i(k);
		if(temp > n){
			return false;
		}
		if(n % temp == 0)
			return true;
		if(solve(k + "7", n))
			return true;

		return solve(k + "4", n);
	}
	public static void main(String args[]) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int n = i(r.readLine());
		boolean i = solve("7", n);
		boolean j = solve("4", n);
		if(i || j){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.*;
public class A122
{
    public static void main(String aa[])
    {
        Scanner ob=new Scanner(System.in);
        int n;
        
        n=ob.nextInt();
        if(n%4==0||n%7==0||n%44==0||n%47==0||n%444==0||n%447==0||n%474==0||n%477==0||n%744==0||n%747==0||n%774==0||n%777==0)
        System.out.println("YES");
        else
        System.out.println("NO");
    }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.io.*;
import java.util.*;

public class Main{
public static void main(String[] args) throws IOException{
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String a=buffer.readLine();
int b=Integer.parseInt(a);
if(b%4==0 || b%7==0 || b%44==0 || b%47==0 || b%74==0 || b%77==0 || b%444==0 || b%447==0 || b%474==0 || b%477==0 || b%744==0 || b%747==0 || b%774==0 || b%777==0)
System.out.println("YES");
else
System.out.println("NO");
}}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.Scanner;
public class LuckyDivision{
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        if(a%4 == 0) System.out.println("YES");
        else if(a%7 == 0) System.out.println("YES");
        else if(a%47 == 0) System.out.println("YES");
        else if(a%74 == 0) System.out.println("YES");
        else if(a%447 == 0) System.out.println("YES");
        else if(a%474 == 0) System.out.println("YES");
        else if(a%477 == 0) System.out.println("YES");
        else if(a%747 == 0) System.out.println("YES");
        else if(a%774 == 0) System.out.println("YES");
        else System.out.println("NO");
    }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if ((n % 4 == 0) || (n % 7 == 0) || (n % 44 == 0) || (n % 47 == 0) || (n % 74 == 0) || (n % 77 == 0) 
                || (n % 444 == 0) || (n % 447 == 0) || (n % 474 == 0) || (n % 477 == 0) || (n % 744 == 0) 
                || (n % 747 == 0) || (n % 774 == 0) || (n % 777 == 0)) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
int x=input.nextInt();
if(x%4==0||x%7==0||x%47==0||x%74==0||x%744==0||x%474==0||x%447==0||x%477==0||x%474==0)
System.out.println("YES");
else
System.out.println("NO");
}
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.TreeSet;

public class E {
    static Scanner in; static int next() throws Exception {return in.nextInt();};
//	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
//	static BufferedReader in;
    static PrintWriter out;

    public static void main(String[] args) throws Exception {
        in = new Scanner(System.in);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//		in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        int n = next();

        if (n%4 == 0||n%7 == 0||n%44 == 0||n%47 == 0||n%74 == 0||n%77 == 0||n%444 == 0||n%447 == 0||n%474 == 0||n%744 == 0||n%774 == 0||n%747 == 0||n%477 == 0||n%777==0) out.println("YES");
        else out.println("NO");

        out.println();
        out.close();
    }
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
import java.io.*;
import java.util.*;
public class z3 {
	public static boolean divch(int i,int a)
	{ if (a>1000) return false; if ((a>0)&&(i%a==0)) return true; return (divch(i,a*10+4)||divch(i,a*10+7)); }
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		System.out.println(divch(in.nextInt(),0)?"YES":"NO");
	}
}
// Problem: 122_A. Lucky Division
// Time complexity: constant
//package arbuz;

import java.util.Scanner;

public class Arbuz {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n % 4 == 0 || n % 7 == 0 || n % 47 == 0 || n % 74 == 0 || n % 444 == 0 || n % 447 == 0 || n % 474 == 0 || n % 477 == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}