jiahuimbzuai/CoQuIR huggingface dataset:
//  [typescript]
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int():number{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str():string{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length:number):string[]{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
  ints(length:number):number[]{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
}
function countAB(str:string):number{
  let count=0;
  let pos=0;
  for(let c of str){
    if(pos==1 && c=="B"){count++;}
    if(c=="A")pos=1;
    else pos=0;
  }
  return count;
}
function xor(a:boolean, b:boolean){return (a && !b) ||(!a && b);}
function add(a:number,b:number):number{return a+b;}
const countIf=<V>(f:(V)=>boolean)=>(sum:number, current: V)=>{return sum+(f(current)?1:0);}
const countIfTrue=countIf<boolean>((value)=>value);
function solve(N:number,s:string[]){
  let inner=s.map(str=>countAB(str)).reduce(add,0);
  let startB=s.map(str=>str.startsWith("B")).reduce(countIfTrue,0);
  let endA=s.map(str=>str.endsWith("A")).reduce(countIfTrue,0);
  let existsHagure=s.map(str=>xor(str.startsWith("B"),str.endsWith("A"))).some((value)=>value);
  return inner + Math.max(0, Math.min(startB, endA) + (existsHagure?0:-1));
}
function Main(raw: string) {
  const input=new NormalInput(raw);
  const N=input.int();
  const s=input.strs(N);
  //出力
  console.log(solve(N,s));
}

//DO NOT EDIT
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
import * as fs from 'fs';

function Picker(input) {
  var lines = input.split('\n');
  var fields = lines.reduce(function(all, line) { return all.concat(line.split(' ')); }, []);
  var p = 0;

  return {
    int: function() {
      return parseInt(fields[p++], 10);
    },
    float: function() {
      return parseFloat(fields[p++]);
    },
    str: function() {
      return fields[p++];
    }
  };
}

const input = fs.readFileSync("/dev/stdin", "utf8");
const pick = Picker(input);

//////////////////////////////////////////

const n = pick.int();
let c = 0;
let start = 0, end = 0, both = 0;
for (let i = 0; i < n; ++i) {
  const s = pick.str();
  c += s.split('AB').length - 1;

  if (s[0] === 'B' && s[s.length - 1] === 'A') {
    both++;
  } else if (s[0] === 'B') {
    start++;
  } else if (s[s.length - 1] === 'A') {
    end++;
  }
}
// console.log(c, both, start, end);

if (start && end) {
  c += both;
  c += start < end ? start : end;
} else if (!start && !end) {
  c += both ? both - 1 : 0;
} else {
  c += both;
}

console.log(c);
//  [typescript]
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int():number{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str():string{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length:number):string[]{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
  ints(length:number):number[]{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
}
function xor(a:boolean, b:boolean){return (a && !b) ||(!a && b);}
function add(a:number,b:number):number{return a+b;}
const countIf=<V>(f:(V)=>boolean)=>(sum:number, current: V)=>{return sum+(f(current)?1:0);}
const countIfTrue=countIf<boolean>((value)=>value);
function solve(N:number,s:string[]){
  let inner=s.map(str=>str.includes("AB")).reduce(countIfTrue,0);
  let startB=s.map(str=>str.startsWith("B")).reduce(countIfTrue,0);
  let endA=s.map(str=>str.endsWith("A")).reduce(countIfTrue,0);
  let existsHagure=s.map(str=>xor(str.startsWith("B"),str.endsWith("A"))).some((value)=>value);
  return inner + Math.max(0, Math.min(startB, endA) + (existsHagure?0:-1));
}
function Main(raw: string) {
  const input=new NormalInput(raw);
  const N=input.int();
  const s=input.strs(N);
  //出力
  console.log(solve(N,s));
}

//DO NOT EDIT
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const endA = (s) => {
  return s[s.length - 1] === "A"
}
const startB = (s) => {
  return s[0] === "B"
}

const reg = /AB/g
const solve = (rest) => {
  let r = 0
  const hasAB = rest.map((s) => {
    let z = s.match(reg)
    r += z ? z.length : 0
  })
  // ...
  let startBs = []
  let endAs = []
  let both = []
  rest.map((s) => {
    let a = endA(s)
    let b = startB(s)
    if (a && b) {
      both.push(s)
      return
    }
    if (a) {
      endAs.push(s)
      return
    }
    if (b) {
      startBs.push(s)
    }
  })
  // 10 , 5, 2
  // console.log(startBs, endAs, both, r)
  let bothlen = both.length
  let sblen = startBs.length
  let ealen = endAs.length
  if (bothlen > 0) {
    r = r + bothlen - 1
    bothlen = 1
    if (sblen + ealen > 0) {
      r = r + bothlen + Math.min(sblen, ealen)
    }
  }
  // if (bothlen > 0) {
  //   r = Math.floor(bothlen / 2) + r
  // }
  return r
}

const main = (input) => {
  const [n, ...rest] = input.split("\n")

  return solve(rest)
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}

if (process.env.NODE_ENV === "test") {
  // module.exports = (input) => solve(input.trim())
  // main(``)
  // solve(1, [2, 3, 4])
}
//  [typescript]
const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const endA = (s) => {
  return s[s.length - 1] === "A"
}
const startB = (s) => {
  return s[0] === "B"
}

const reg = /AB/g
const solve = (rest) => {
  let r = 0
  const hasAB = rest.map((s) => {
    let z = s.match(reg)
    r += z ? z.length : 0
  })
  // ...
  let startBs = []
  let endAs = []
  let both = []
  rest.map((s) => {
    let a = endA(s)
    let b = startB(s)
    if (a && b) {
      both.push(s)
      return
    }
    if (a) {
      endAs.push(s)
      return
    }
    if (b) {
      startBs.push(s)
    }
  })
  // 10 , 5, 2
  // console.log(startBs, endAs, both, r)
  let bothlen = both.length
  let sblen = startBs.length
  let ealen = endAs.length
  if (bothlen > 0) {
    if (sblen + ealen == 0) {
      r = r + bothlen - 1
    } else {
      r = r + bothlen + Math.min(sblen, ealen)
    }
  }
  // if (bothlen > 0) {
  //   r = Math.floor(bothlen / 2) + r
  // }
  return r
}

const main = (input) => {
  const [n, ...rest] = input.split("\n")

  return solve(rest)
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}

if (process.env.NODE_ENV === "test") {
  // module.exports = (input) => solve(input.trim())
  // main(``)
  // solve(1, [2, 3, 4])
}
//  [python]
s = int(input())
def f(n):
  if n%2 == 0:
    return n//2
  else:
    return 3*n+1
a = [s]
i=1
while(1):
  i+=1
  x=f(a[-1])
  if (x in a):
    print(i)
    exit()
  a.append(x)
//  [python]
s = int(input())
L = [s]
cnt = 1
while True:
  cnt += 1
  if L[cnt-2]%2 == 0:
    L.append(L[cnt-2]//2)
  else:
    L.append(L[cnt-2]*3+1)
  if not len(set(L)) == cnt:
    print(cnt)
    exit()
//  [python]
def f(x):
    if x%2==0:
        return x//2
    else:
        return 3*x+1
s=int(input())
cnt=1
check={}
while s not in check:
    check[s]=1
    s=f(s)
    cnt+=1
print(cnt)
//  [python]
# ABC116
# B Collatz Problem
s = int(input())
S = [str(s)]
i = 1
while True:
    if s % 2 == 0:
        i += 1
        s = s//2
        S.append(str(s))
        if S.count(str(s)) == 2:
            print(i)
            print(S)
            exit()
    else:
        i += 1
        s = 3 * s + 1
        S.append(str(s))
        if S.count(str(s)) == 2:
            print(i)
            print(S)
            exit()
pass
//  [python]
# ABC116
# B Collatz Problem
s = int(input())
S = [str(s)]
i = 1
while True:
    if s % 2 == 0:
        i += 1
        s = s/2
        S.append(str(s))
        if S.count(str(s)) == 2:
            print(i)
            exit()
    else:
        i += 1
        s = 3 * s + 1
        S.append(str(s))
        if S.count(str(s)) == 2:
            print(i)
            exit()
pass
//  [python]
a = int(input())
s = set()

for i in range(10**6):
	if a % 2 == 0:
		# print("Process for even.")
		a = a//2
	else:
		# print("Process for odd.")
		a = 3*a + 1
	if a not in s:
		s.add(a)
	else:
		print(i+2)
		break
//  [java]
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int s = sc.nextInt();
		int count = 1;
		while (s != 4 && s != 2 && s != 1) {
			count++;
			if (s % 2 == 0)
				s = s / 2;
			else
				s = 3 * s + 1;
		}
		System.out.println(count + 3);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
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.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int s = sc.nextInt();
		if (s == 2 || s == 1) {
			System.out.println(4);
			return;
		}
		for (int i = 1;;i++) {
			if (s == 4) {
				System.out.println(i+3);
				return;
			} else if (s % 2 == 0) {
				s /= 2;
			} else {
				s = s * 3 + 1;
			}
		}
	}
}

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]
package pracltice;

import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static PrintWriter out;

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

    private static void run() {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        Scanner sc = new Scanner(System.in);
        int s = Integer.parseInt(sc.next());
        ArrayList<Integer> list = new ArrayList<>();
        list.add(s);
        for (int i = 1, answer = 0;; i++) {
            answer = Main.calcF(list.get(i - 1));
            if (list.contains(answer)) {
                out.println(i + 1);
                break;
            }
            list.add(answer);
        }
        out.close();
        sc.close();
    }

    private static int calcF(int pnum) {
        int n = pnum;
        if (n % 2 == 0) {
            return n / 2;
        } else {
            return 3 * n + 1;
        }
    }
}
//  [java]
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		int N = nextInt();
		HashSet<Integer> used = new HashSet<Integer>();
		used.add(N);
		while(true){
			int ato = F(N);
			if(used.contains(ato)){
				myout(used.size());
				return;
			}
			used.add(ato);
			N = ato;
		}
	}
	//Method addition frame start

static int F(int v){
	if(v % 2 == 0){
		return v / 2;
	}else{
		return 3 * v + 1;
	}
}

	//Method addition frame end
}
//  [java]
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        if(s == 1) {
            System.out.println(4);
            return;
        }

        int ans = 1;
        while(true) {
            if(s == 1) {
                ans++;
                break;
            }
            if(s % 2 == 0) {
                s /= 2;
            } else {
                s = s * 3 + 1;
            }
            ans++;
        }
        System.out.println(ans);
    }
}
//  [cpp]
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>

using namespace std;

/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;    
    }
    return sum;
}
/// 最大公約数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }



int main(){
int s;
cin >> s;
int cnt = 1;
while(1){
    if(s==4 || s == 2 || s==1){
        cnt=cnt+3;
        cout << cnt << endl;
        return 0;
    }
    if(s%2==0){
        s /=2;
        cnt += 1;
    }
    else{
        s=3*s+1;
        cnt++;    
    }
}
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
	ll s;
    cin >> s;
    map<ll, ll> mp;
    ll ans = 0;
    while(1){
        ans++;
        mp[s]++;
        if(mp[s] == 2){
            cout << ans << endl;
            return 0;
        }
        if(s % 2) s = 3 * s + 1;
        else s /= 2;
    }
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;using int32=int_fast32_t;using uint32=uint_fast32_t;using int64=int_fast64_t;using uint64=uint_fast64_t;using pi=pair<int32,int32>;using pll=pair<int64,int64>;using vi=vector<int32>;using vvi=vector<vector<int32>>;using vll=vector<int64>;using ll=int64;using ull=uint64;constexpr int32 INF=1<<30;constexpr ll INFLL=1LL<<62;
#define all(x) x.begin(),x.end()
#define LB(V,x) lower_bound(all(V),x)-V.begin()
#define uint uint32
inline int f(int x){
    return x%2==0 ? x/2 : x*3+1;
}
void Main(){
    int s;
    cin >> s;
    map<int, int> R;
    for(int n=1;n<=1000000;n++){
        if(R[s]!=0){
            cout << n;
            return;
        }
        R[s] = n;
        s = f(s);
    }
    
}
int main(){cin.tie(0);ios::sync_with_stdio(false);Main();return 0;}
//  [cpp]
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{

  ll s;
  cin>>s;

  ll ans=0;
  while(s>1){
    ans++;
    if(s%2==0){
      s=s/2;
    }else{
      s=3*s+1;
    }
  }


  cout<<ans+2<<endl;
  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;  

int main(){
    int s, i;
    cin >> s;
    
    i = 0;
    while (s != 1) {
        s = (s%2 == 0 ? s/2 : 3*s + 1);
        i++;
    }
    
    cout << i << endl;
    return (0);
}
//  [cpp]
#include<iostream>
using namespace std;

int main(){
    int a[100];
    int s;
    cin>>s;
    a[0]=s;
    int flag=1;
    for (int i = 1; i < 100; i++)
    {
        if (a[i-1]%2==0)
        {
            a[i] = a[i-1]/2;
        }
        else
        {
            a[i] = 3 * a[i-1] +1;
        }

        for (int j = 0; j < i; j++)
        {
            if (a[j]==a[i])
            {
                cout<<i+1;
                flag=0;
                break;
            }
            
        }
        if (flag==0)
        {
            break;
        }
        
        
        
    }
    
    
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(void)
{
    int s;
    scanf("%d", &s);
 
    int index = 1;
    if (3 <= s){
        while(1){
        if (s == 4) break;
        index++;
        if (s%2 == 0) s /= 2;
        else s = 3*s + 1;
        }
    }
    else index = 1;
    printf("%d\n", index+3);
    return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans;
int i=0;
int main(int argc, char* argv[]){
  long int a=0,b=0,c=0;
  scanf("%ld",&a);
  if (a>=3) {
    for (i++; a != 4; i++) {
      if (a%2==0) {
        a/=2;
      }else{
        a=3*a+1;
      }
    }
    printf("%d",i+3);
  }else{
    printf("4");
  }
}
//  [c]
#include<stdio.h>

int main(void)
{
   int a, i=1;

   scanf("%d",&a);

   while((a!=1)&&(a!=2)&&(a!=4)){
      if(a%2==0)
         a=a/2;
      else
         a=3*a+1;
      i++;
   }

   printf("%d\n",i+3);
   return 0;
}
//  [c]
#include <stdio.h>

int f(int s,int i){
  if(i==0){
    return s;
  }int temp=f(s,i-1);
  if(temp%2==0){
    return (temp/2);
  }else{
    return (3*temp+1);
  }
}

int main(void){
  int s=0;
  scanf("%d", &s);
  int i=0,j=0,m=0;
  int a[1000005];
  int flag=0;
  while(1){
    a[i]=f(s,i+1);
    for(j=0;j<i;j++){
      if(a[j]==a[i]) {
        flag=1;
         m=i+1;
        break;
      }
    }
    if(flag) break;
    i++;
  }
    printf("%d", m+1);
    return 0;
  }
//  [c]
#include<stdio.h>
int main(){
  int s;
  int a[1000000];
 	scanf("%d",&s);
  a[0] = s;
  int i = 1;
  while(1){
    if(s % 2 == 0){
      a[i] = s / 2;
    }else{
      a[i] = 3 * s + 1;
    }
 
    for(int j = 0; j < i; j++){
      if(a[j] == a[i]){
	printf("%d", i+1);
	return 0;
      }
    }
   i++;
  }
  
  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int s;
    
    scanf("%d", &s);
    
    if (s==4||s==2||s==1) {
        printf("%d\n", i+3);
        return 0;
    }
    
    for (int i=2; i<=1000000; i++) {
        if (s%2==0) {
            s=s/2;
        } else {
            s=3*s+1;
        }
        
        if (s==4||s==2||s==1) {
            printf("%d\n", i+3);
            return 0;
        }
    }
    
    return 0;
}
//  [javascript]
function Main(input) {
  input = input.split("\n");
  var s = parseInt(input[0]);
  a = [s];
  for(var i=1;i>0;i++){

    if(a[i-1]%2==0){
      b=a[i-1]/2;
    if(a.indexOf(b)!=-1){
      var ans=i+1;
      break;
    }
      a.push(a[i-1]/2);
    }else{
      b=a[i-1]*3+1;
    if(a.indexOf(b)!=-1){
      var ans=i+1;
      break;
    }
      a.push(a[i-1]*3+1)
    }
  }

  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
    var arr = [,,input-0];
    for(var i=2;arr[i-2]+arr[i-1]+arr[i]!=7;i++){
        arr.push(arr[i]%2===0?arr[i]/2:3*arr[i]+1);
    }
    console.log(arr.length-1)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
input = require('fs').readFileSync('/dev/stdin', 'utf8')
s = input.split('\n').shift() * 1
o = []
i = 1
while (o[s] === undefined) {
    o[s] = 1
    if (s%2) {
        s = 3 * s + 1 
    } else {
        s = s / 2
    }
    i++
    if (o[s] == 1) {
        break;
    }
}
console.log(i)
//  [javascript]
const collatz = (n) => {
  if (n % 2 === 0) {
    n /= 2
  } else {
    n = 3 * n + 1
  }

  return n
}

const main = stdin => {
  const input = stdin.trim().split('\n')
  const s = parseInt(input[0])

  let tmp = s
  let first = 0
  let second = 0
  for (let i = 1; ; i++) {
    if (tmp === 4 && first === 0) {
      first = i
    } else if (tmp === 4 && first !== 0) {
      second = i
      break
    }
    tmp = collatz(tmp)
  }

  console.log(second)
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))
//  [javascript]
const collatz = (n) => {
  if (n % 2 === 0) {
    n /= 2
  } else {
    n = 3 * n + 1
  }

  return n
}

const main = stdin => {
  const input = stdin.trim().split('\n')
  const s = parseInt(input[0])

  let tmp = s
  let first = 0
  let second = 0
  for (let i = 1; ; i++) {
    if (tmp === 4 && first === 0) {
      first = i
    } else if (tmp === 4 && first !== 0) {
      second = i
      break
    }
    tmp = collatz(tmp)
    console.log(tmp)
  }

  console.log(second)
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))
//  [javascript]
var reader = require('readline').createInterface ({
    input: process.stdin,
    output: process.stdout
});

var lines = [];
reader.on('line', (line) => {
    lines.push(line);
});

reader.on('close', () => {
    var line = lines[0];
      var a = [line];
  for (var i = 0; i < 100; i++) {
      if (a[i] % 2 == 0)  {
         var T = a[i] / 2
         a.push(T)
      }else if (a[i] % 2 == 1) {
         var T = 3*a[i]-2;
         a.push(T)
      }
    for(var j=0; j<i;j++){
     if (a[j] == a[i]){
       console.log(i+1);
     return;
     }
    }
  }
  });
//  [go]
package main

import (
	"fmt"
)

func main() {
	var s int
	fmt.Scan(&s)
	
  	a := make([]int,0)
  	a = append(a, s)
  	
	for i := 1; ; i++ {
		if a[i-1] % 2 == 0 {
			a = append(a, a[i-1] / 2)
		} else {
			a = append(a, 3 * a[i-1] + 1)
		}
		for j := 0; j < i; j++ {
			if a[i] == a[j] {
				fmt.Println(i+1)
				return
			}
		}
	}
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var s int
	fmt.Scan(&s)
	
	a := make(map[int]bool)
	a[s] = true
	
	for i := 2; ; i++ {
		if s % 2 == 0 {
			s = s / 2
		} else {
			s = 3 * s + 1
		}
		
		if a[s] {
			fmt.Println(i)
			return
		}
		a[s] = true
	}
}
//  [go]
package main

import "fmt"

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

	numExistMap := map[int]bool{}
	i := 2
	for {
		var n int
		if s%2 == 0 {
			n = s / 2
		} else {
			n = 3*s + 1
		}
		if numExistMap[n] {
			fmt.Println(i)
			return
		}
		numExistMap[n] = true
		s = n
		i++
	}
}
//  [go]
package main

import "fmt"

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

	used := make(map[int]bool)
	a := s
	for i := 2; ; i++ {
		a = f(a)
		if used[a] {
			fmt.Println(i)
			return
		}
		used[a] = true
	}
}

func f(n int) int {
	if n%2 == 0 {
		return n / 2
	}
	return 3*n + 1
}
//  [go]
package main

import "fmt"

func main() {
	// Code for B - Collatz Problem
	var s int
	fmt.Scanf("%d", &s)

	var i int = 2
	var aAfter int
	var aBefore int = s
	a := make(map[int]int)
	for {
		if aBefore%2 == 0 {
			aAfter = aBefore / 2
		} else {
			aAfter = 3*aBefore + 1
		}

		a[aAfter]++
		if a[aAfter] == 2 {
			fmt.Println(i)
			break
		}
		aBefore = aAfter
		i++
	}
}
//  [ruby]
s = gets.to_i
arr = []
arr << s
i = 0
loop do
  if arr[i].even?
  	if arr.include?(arr[i]/2)
      puts i + 2
      exit
    end
    arr << arr[i]/2
  else
    if arr.include?(3 * arr[i] + 1)
      puts i + 2
      exit
  	end
    arr << 3 * arr[i] + 1
  end
  i += 1
end
//  [ruby]
n = gets.to_i
ary = [n]
cnt = 1
while(true)
  n = n.odd? ? 3*n+1 : n/2
  if ary.include?(n)
    puts cnt + 1
    exit
  end
  ary << n
  cnt += 1
end
//  [ruby]
s = gets.to_i

appeared = false
count = 0
index = 0

while count < 2
  if [1, 2, 4].include?(s)
    appeared = s if appeared == false
    count += 1 if s == appeared
  end

  s = s.even? ? s / 2 : s * 3 + 1
  index += 1
end

puts index
//  [ruby]
a=[gets.to_i]
ans=1
(2..1000000).each do |n|
  p= a[n-1]%2==0 ? a[n-1]/2 : 3*a[n-1]+1
  break ans=n if a.find_index p
  a[n]=p
end
p ans
//  [ruby]
s=gets.to_i
h=Hash.new()
while true
  if h[s]==1
    ans=s
    break
  else
    h[s]=1
  end
  s= s.odd? ? 3*s+1 : s/2
end
puts ans
//  [ruby]
S = gets.to_i
a =[]
a << S

count = 0
while true

	newa = 0

	if a.last.even?
		newa =  (a.last / 2)
	else
		newa =(a.last * 3 + 1)
	end
	if newa != a.min
		a << newa
	else
		break
	end
	count += 1
end
puts count
//  [rust]
use std::io;
use std::collections::HashSet;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v: Vec<i32> = procon_read();
	let s = v[0];
	let mut set = HashSet::new();
	let mut ai = s;
	set.insert(ai);
	for i in 2.. {
		if ai%2 == 0 {
			ai = ai / 2;
		}else{
			ai = 3*ai + 1;
		}
		if !set.insert(ai) {
			println!("{}", i);
			break;
		}
	}
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// use std::io::{stdout, Write, BufWriter};
use std::cmp::min;

fn main() {
    input! { s: i32, }
    let mut a: Vec<i32> = vec![s];
    for i in 2.. {
        let next_term = f(*a.last().unwrap());
        if a.contains(&next_term) {
            println!("{}", i);
            break;
        } else {
            a.push(next_term)
        }
    }
}

fn f(n: i32) -> i32 {
    if n%2 == 0 {
        n/2
    } else {
        3*n+1
    }
}
//  [rust]
use std::collections::HashSet;
use whiteread::parse_line;

fn main() {
    let mut s: i32 = parse_line().unwrap();
    let mut a: HashSet<i32> = HashSet::new();
    let mut cnt: i32 = 0;

    loop {
        if s % 2 == 0 {
            s /= 2;
        } else {
            s = s * 3 + 1;
        }
        if !a.insert(s) {
            break;
        }
        cnt += 1;
    }
    println!("{}", cnt + 2);
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn collatz(n: u64) -> u64 {
    if n % 2 == 0 {
        n / 2
    } else {
        3 * n + 1
    }
}

use std::collections::HashSet;

fn main() {
    input! {
        s: u64
    }
    let mut s = s;
    let mut set = HashSet::new();
    let mut cnt = 1;
    loop {
        s = collatz(s);
        cnt += 1;
        if set.contains(&s) {
            break;
        }
        set.insert(s);
    }
    println!("{}", cnt);
}
//  [rust]
// ref: https://qiita.com/tubo28/items/e6076e9040da57368845
use std::io::{stdin, Read};
use std::str::FromStr;
use std::collections::BTreeSet;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut s: i32 = read();
    let mut set = BTreeSet::new();
    while s != 1 {
        set.insert(s);
        s = if s % 2 == 0 {
            s / 2
        } else {
            3 * s + 1
        };
    }

    println!("{}", set.len() + 2);
}
//  [swift]
import Foundation

let s = Int(readLine()!)!
var a = [s]

var ai = s
for_m: for m in 1 ... 1000000 {
    if ai % 2 == 0 {
        ai = ai / 2
    } else {
        ai = 3 * ai + 1
    }
    a.append(ai)
    
    for n in 0 ..< m {
        if a[n] == a[m] {
            print(m+1)
            break for_m
        }
    }
}
//  [swift]
let s: Int = Int(readLine()!)!

var res: Int = 1
var a: Int = s
var new: Int = -1
var seq: [Int] = [a]

while true {
    res += 1
    if a%2==0 {
        new = a / 2
    } else {
        new = 3 * a + 1
    }
    if seq.contains(new) {
        break
    } else {
        seq.append(new)
        a = new
    }
}
print(res)  // (๑•ૅㅁ•๑)
//  [swift]
let s = Int(readLine()!)!

var arr:Array<Int> = [s]
var a=s
var new:Int
var i=1

while true{
  i+=1
  if a%2==0{
    new=a/2
  }else{
    new=3*a+1
  }
  
  if arr.contains(new){
    break
  }else{
    arr.append(new)
    a=new
  }
}

print(i)
//  [swift]
let s = Int(readLine()!)!

var arr:Array<Int> = []
var a=s
var new:Int
var i=1

while true{
  i+=1
  if a%2==0{
    new=a/2
  }else{
    new=3*a+1
  }
  
  if arr.contains(a){
    break
  }else{
    arr.append(new)
    a=new
  }
}

print(i)
//  [swift]
let s = Int(readLine()!)!

var arr:Array<Int> = []
var a=s
var i=1

while true{
  i+=1
  if a % 2 == 0{
    a /= 2
  }else{
    a = 3*a+1
  }
  
  if arr.contains(a){
    break
  }else{
    arr.append(a)
  }
}

print(i)
//  [swift]
let s = Int(readLine()!)!

var arr:Array<Int> = []
var a=s
var i=0

while true{
  i+=1
  if a % 2 == 0{
    a /= 2
  }else{
    a = 3*a+1
  }
  
  if arr.contains(a){
    break
  }else{
    arr.append(a)
  }
}

print(i)
//  [typescript]

const calc = (n) => {
  if (n % 2 === 0) {
    return n / 2
  }
  return n * 3 + 1
}

const solve = (input) => {
  const n = Number(input)
  let r = 1
  let resultMap = {
    [n]: true
  }
  let last = n
  while (1) {
    r++
    last = calc(last)
    if (resultMap[last]) {
      break
    } else {
      resultMap[last] = true
    }
  }
  return r
}

if (process.env.NODE_ENV === "test") {
  module.exports = (input) => solve(input.trim())
} else {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(solve(input.trim()))
}
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _s = stdin.split('\n')[0]
const s = Number(_s)

function fx(n) {
  if (n % 2 === 0) {
    return n / 2
  } else {
    return 3 * n + 1
  }
}

let i = 0
let ai = [s]

while (true) {
  i++
  let r = 0

  if (i === 1) {
    r = fx(s)
  } else {
    r = fx(ai[i - 1])
  }

  if (ai.indexOf(r) > -1) {
    ai.push(r)
    break
  }
  ai.push(r)
}

console.log(ai.length)
//  [typescript]
const main = (input: string) => {
  let S = parseInt(input.trim())
  const A = [S];
  let isInCompleted = true;

  while (isInCompleted) {
    if(S % 2 === 0) {
      S = S / 2
    } else {
      S = (S * 3) + 1
    }
    if(A.indexOf(S) >= 0) {
      isInCompleted = false
    }
    A.push(S)
  }

  console.log(A.length)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _s = stdin.split('\n')[0]
const s = Number(_s)

function fx(n) {
  if (n % 2 === 0) {
    return n / 2
  } else {
    return 3 * n + 1
  }
}

let i = 0
let ai = [s]

while (true) {
  i++
  let r = 0

  if (i === 1) {
    r = fx(s)
  } else {
    r = fx(ai[i - 1])
  }

  if (ai.indexOf(r) > 0) {
    ai.push(r)
    break
  }
  ai.push(r)
}

console.log(ai.length)
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _s = stdin.split('\n')[0]
const s = Number(_s)

function fx(n) {
  if (n % 2 === 0) {
    return n / 2
  } else {
    return 3 * n + 1
  }
}

let i = 0
let ai = [s]
let res = 0

while (true) {
  i++
  let r = 0
  if (i === 1) {
    r = fx(s)
  } else {
    r = fx(ai[i - 1])
  }

  if (ai.indexOf(r) > 0) {
    res = i + 1
    break
  }
  ai.push(r)
}

console.log(res)
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _s = stdin.split('\n')[0]
const s = Number(_s)

function fx(n) {
  if (n % 2 === 0) {
    return n / 2
  } else {
    return 3 * n + 1
  }
}

let i = 0
let ai = [s]
let res = 0

while (true) {
  i++
  if (i === 1) {
    const r = fx(s)
    ai.push(r)
  } else {
    const r = fx(ai[i - 1])
    if (ai.indexOf(r) > 0) {
      res = i + 1
      break
    }
    ai.push(r)
  }
}

console.log(res)
//  [python]
A, B = map(int, input().split())
if (A + B) % 2 == 0:
  print((A + B) // 2)
else:
  print('IMPOSSIBLE')
//  [python]
A, B = map(int, input().split())
if (A+B)%2==0:
  print(int((A+B)/2)) 
else:
  print('IMPOSSIBLE')
//  [python]
A, B = list(map(int, input().split()))
diff = abs(A - B)

if diff % 2 == 0:
    print(int(abs(diff / 2 + min(A, B))))
else:
    print('IMPOSSIBLE')
//  [python]
A,B=map(int, input().split())
 
if (A+B)%2==0:
	print((A+B)/2)
else:
	print("IMPOSSIBLE")
//  [python]
a,b=map(int,input().split())

S=[a,b]
M=max(S)

for i in range(M):
  if abs(a-i)==abs(b-i):
    print(i)
    exit()
print("IMPOSSIBLE")
//  [python]
A,B=map(int, input().split())

if (A+B)%2==0:
	print((A+B)/2)
else:
	print("IMPOSSIBLE")
//  [java]
/*
 * @Author: Kaustav Vats  
 */
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;


class Main {

    public static void PrintIntArray(int[] Arr) {
        for (int i=0; i<Arr.length; i++) {
            System.out.print(Arr[i] + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) throws IOException{
        Reader.init(System.in);
        long A = Reader.nextLong();
        long B = Reader.nextLong();
        if ((A+B) % 2 == 0) {
            System.out.println((A + B)/2);
        }
        else {
            System.out.println("IMPOSSIBLE");
        }
    }
}


/** Class for buffered reading int and double values */
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
	
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}
//  [java]
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int a=fsc.nextInt();
        int b=fsc.nextInt();
        fsc.close();
        if (a%2!=b%2) {
            System.out.print("IMPOSSIBLE");	
        } else {
        	System.out.print((a+b)/2);
        }
        
        
    }
    static 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());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}
//  [java]
import java.util.Scanner;
public class Main {
	static int a,b;
	static int getK(int a,int b) {  
		int i,k=0;
		  i=b-a;
		    k=b-i/2;
		  return k ;
  } 

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int a,b,i=0,k=1;
	Scanner scan=new Scanner(System.in);
	while (k!=0) {
		k++;
	 a=scan.nextInt();
	 b=scan.nextInt();
    i=b-a;
    if(i%2==0) {
    System.out.println(getK(a,b));
   }
   else 
   System.out.println("IMPOSSIBLE");
	
	   }
	
	 }
}
//  [java]
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int a,b,i=0,k=1;
	Scanner scan=new Scanner(System.in);
	while (k!=0) {
		k++;
	 a=scan.nextInt();
	 b=scan.nextInt();
    i=b-a;
    if(i%2==0) {
    k=b-i/2;
    System.out.println(k);
   }
   else 
   System.out.println("IMPOSSIBLE");
	
	   }
	
	 }
}
//  [cpp]
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	long long x, y, z;
	scanf("%lld %lld", &x, &y);
	z = (x + y) / 2;
	if(abs(x-z)==abs(y-z))printf("%lld\n", z);
	else printf("IMPOSSIBLE\n");

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

int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  
  if(a>=b){
    if((a-b)%2 == 0){
      printf("%d\n",(a+b)/2);
    }else{
      printf("IMPOSSIBLE");
    }
  }else{
    if((b-a)%2 == 0){
      printf("%d\n",(b+a)/2);
    }else{
      printf("IMPOSSIBLE");
    }
  }
  return 0;
}
//  [cpp]
#include<stdio.h>
int main()
{
    int a,b,k,c=0;
    scanf("%d %d",&a,&b);
if((a+b)%2==0)
    {
    k=(a+b)/2;
    printf("%d",k);
    }
else
    {
    printf("IMPOSSIBLE");
    }
return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
int main(){
    long a,b;
    cin >> a >> b;
    if((a-b)%2==1){
        cout << "IMPOSSIBLE"<<endl;
    }else{
        long m = (a+b)/2;
        cout << min(a,b) + m << endl;
    }
}
//  [c]
#include <stdio.h>
int main(void){
    int a,b;
 scanf("%d %d",&a,&b);
   int s = a+b;
    if(s%2==0)printf("%d",s/2);
    else printf("IMPOSSIBLE");
    return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0


int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if((a+b)&1)printf("IMPOSSIBLE\n");
  else  printf("%d",(a+b)/2);
  return 0;
}


/// confirm df==0 ///
//  [c]
#include<stdio.h>
#include <stdlib.h>
int main()
{
    int x,y,z,i,j;
    scanf("%d",&x);
    scanf("%d",&y);
    z=(x+y)/2;
    i=abs(x-z);
    j=abs(y-z);
    if(i==j)
        printf("%d\n",z);
    else
        printf("IMPOSSIBLE\n");

    return 0;
}