use proconio::input;

fn main() {
    input! {
        a: usize,
        b: usize,
        m: usize,
        va: [i32; a],
        vb: [i32; b],
        x: [[i32; 3]; m]
    }

    let mut ans = 1001001001;

    for i in 0..a {
        for j in 0..b {
            ans = std::cmp::min(ans, va[i] + vb[j]);
        }
    }

    for xi in x {
        let ai = xi[0] as usize;
        let bi = xi[1] as usize;
        let c  = xi[2];
        ans = std::cmp::min(ans, va[ai-1] + vb[bi-1] - c);
    }

    println!("{}", ans);
}


use std::io::stdin;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let mut first_line = buf.split_whitespace();
    let _ = first_line.next().unwrap();
    let _ = first_line.next().unwrap();
    let coupon: i32 = first_line.next().unwrap().parse().unwrap();

    buf.clear();
    stdin().read_line(&mut buf).unwrap();
    let type_a = buf.split_whitespace();
    let type_a = type_a.map(|iter| iter.parse::<i32>().unwrap()).collect::<Vec<i32>>();

    buf.clear();
    stdin().read_line(&mut buf).unwrap();
    let type_b = buf.split_whitespace();
    let type_b = type_b.map(|iter| iter.parse::<i32>().unwrap()).collect::<Vec<i32>>();

    let mut coupon_pair = Vec::new();
    for _ in 0..coupon{
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        let mut input = buf.split_whitespace();
        let a_index: usize = input.next().unwrap().parse().unwrap();
        let b_index: usize = input.next().unwrap().parse().unwrap();
        let discount: usize = input.next().unwrap().parse().unwrap();
        coupon_pair.push([a_index, b_index, discount]);
    }

    println!("{}", solve(type_a, type_b, coupon_pair));
}

fn solve(type_a: Vec<i32>, type_b: Vec<i32>, coupon_pair: Vec<[usize; 3]>) -> i32{
    let normal_min = type_a.iter().min().unwrap() + type_b.iter().min().unwrap();
    let mut discounts = Vec::with_capacity(coupon_pair.len());

    for coupon in coupon_pair{
        let discount: i32 = type_a[coupon[0] - 1] + type_b[coupon[1] - 1] - coupon[2] as i32;
         discounts.push(discount);
    }
    let discount_min = *(discounts.iter().min().unwrap());
    return min(normal_min, discount_min)
}


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! {
        a_size: usize,
        b_size: usize,
        m: usize,
        refg: [i32; a_size],
        mw: [i32; b_size],
        disc: [(usize, usize, i32); m],
    }

    let mut vals: Vec<i32> = vec![];

    for (x, y, c) in disc {
        vals.push(*(refg.get(x - 1).unwrap()) + *(mw.get(y - 1).unwrap()) - c)
    }

    for &a in refg.iter() {
        for &b in mw.iter() {
            vals.push(a + b)
        }
    }

    println!("{}", vals.iter().min().unwrap());
}


import Foundation

extension String {

    func toStrList() -> [String] {
        return self.map{String($0)}
    }

    func toIntList() -> [Int] {
        return self.map{Int(String($0))!}
    }

    func toSepDoubleList() -> [Double]{
        return self.split(separator: " ").map{Double($0)!}
    }

    func toSepIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }

    func toSepStrList() -> [String] {
        return self.split(separator: " ").map{String($0)}
    }

    func zFill(n:Int) -> String {
        return String(format: "%0\(n)d", Int(self)!)
    }

    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }

    func counter() -> Dictionary<Character, Int>{
        var result:[Character:Int] = [:]

        for c in self{
            guard let _ = result.index(forKey: c) else {
                result[c] = 1
                continue
            }
            result[c]! += 1
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }

    func toNBin(_ radix:Int) -> String{
        return String(self, radix: radix)
    }

    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}

func pow(_ base:Int,_ exp:Int) -> Int{
    let d = pow(base.toD(), exp.toD())
    return Int(d)
}

func hitachi2020b() -> Int{
    let ABM = readLine()!.toSepIntList()
    let A = readLine()!.toSepIntList()
    let B = readLine()!.toSepIntList()

    var sum = A.min()! + B.min()!
    for _ in 1...ABM[2]{
        let xyc = readLine()!.toSepIntList()
        sum = min(A[xyc[0]-1] + B[xyc[1]-1] - xyc[2], sum)
    }
    return sum
}

print(hitachi2020b())


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (A, B, M) = (input[0], input[1], input[2])
let a = readLine()!.characters.split(" ").map{Int(String($0))!}
let b = readLine()!.characters.split(" ").map{Int(String($0))!}
let m = (0..<M).map{_ in readLine()!.characters.split(" ").map{Int(String($0))!}}

var ans = a.minElement()! + b.minElement()!
for i in m {
  ans = min(ans, a[i[0]-1]+b[i[1]-1]-i[2])
}

print(ans)


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (A, B, M) = (input[0], input[1], input[2])
let a = readLine()!.characters.split(" ").map{Int(String($0))!}
let b = readLine()!.characters.split(" ").map{Int(String($0))!}
let m = (0..<M).map{_ in readLine()!.characters.split(" ").map{Int(String($0))!}}

var ans = a.minElement()! + b.minElement()!
for i in m {
  ans = min(ans, a[i[0]]+b[i[1]]-i[2])
}

print(ans)


function Main(input) {
    const lines = input.split("\n");

    const [A, B, M] = lines.shift().split(' ').map(Number);
    const aList = lines.shift().split(' ').map(Number);
    const bList = lines.shift().split(' ').map(Number);

    const minA = Math.min(...aList);
    const minB = Math.min(...bList);

    let minCost = minA + minB;

    for (let i = 0; i < M; i++) {
        const [x, y, c] = lines[i].split(' ').map(Number);
        minCost = Math.min(minCost, aList[x-1] + bList[y-1] - c);
    }

    console.log(minCost);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


// https://atcoder.jp/contests/hitachi2020
import * as fs from "fs";

const stdin = fs.readFileSync("/dev/stdin", "utf8");
const split = stdin.split("\n");
Main(split);

function Main(inputLines: string[]) {
  const [A, B, M] = inputLines[0].split(" ").map(ele=>Number(ele));
  const a = inputLines[1].split(" ").map(ele=>Number(ele));
  const b = inputLines[2].split(" ").map(ele=>Number(ele));
  let min = 200000;
  for (let i = 3; i < 3 + M; i++) {
    const [x, y, c] = inputLines[i].split(" ").map(ele=>Number(ele));
    const cost = a[x-1] + b[y-1] - c;
    if (min > cost) {
      min = cost;
    }
  }
  const minA = Math.min.apply(null, a);
  const minB = Math.min.apply(null, b);
  if (min > (minA + minB)) {
    console.log(minA + minB);
    return;
  }
  console.log(min);
}


import * as fs from 'fs';

namespace AtCoder.hitachi2020 {

    export class Program {
        /**
         * in
         * 2 2 1
         * 3 5
         * 3 5
         * 2 2 2
         * out
         * 6
         */
        static main(inp: string): void {

            // a,bの最安値
            // クーポンを使ったときの値
            const [a, b, m]: number[] = inp.split('\n')[0].split(' ').map(Number);
            const aList: number[] = inp.split('\n')[1].split(' ').map(Number);
            const bList: number[] = inp.split('\n')[2].split(' ').map(Number);

            let ans1: number = 0;
            // ans1 = aList.sort()[0];
            // ans1 += bList.sort()[0];
            ans1 = Math.min(...aList)
            ans1 += Math.min(...bList)
            // ans1 = aList.reduce((a, b) => Math.min(a, b));
            // ans1 += bList.reduce((a, b) => Math.min(a, b));

            // クーポン
            const ww: string[] = inp.split('\n');
            for (let i: number = 0; i < m; i++) {
                const [x, y, c]: number[] = ww[i + 3].split(' ').map(Number);

                let wk: number = aList[x - 1] + bList[y - 1] - c;
                if (ans1 > wk) {
                    ans1 = wk;
                }
            }

            console.log(ans1);

        }
    }
}

AtCoder.hitachi2020.Program.main(fs.readFileSync('/dev/stdin', 'utf8').trim());


function Main(input) {
    const lines = input.split("\n");

    const [A, B, M] = lines.shift().split(' ').map(Number);
    const aList = lines.shift().split(' ').map(Number);
    const bList = lines.shift().split(' ').map(Number);

    const minA = Math.min(...aList);
    const minB = Math.min(...bList);

    let minCost = minA + minB;

    const subsetLength = 1000;
    for (let i = 0; i < M; i+=subsetLength) {
        const costsWithCoupon = lines.slice(i, i+subsetLength).map(l => {
            const [x, y, c] = l.split(' ');
            return aList[x-1] + bList[y-1] - c;
        });
        minCost = Math.min(minCost, ...costsWithCoupon);
    }

    console.log(minCost);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    const lines = input.split("\n");

    const [A, B, M] = lines.shift().split(' ').map(Number);
    const aList = lines.shift().split(' ').map(Number);
    const bList = lines.shift().split(' ').map(Number);

    const minA = Math.min(...aList);
    const minB = Math.min(...bList);

    let minCost = minA + minB;

    const subsetLength = 1000;
    for (let i = 0; i < M; i+=subsetLength) {
        minCost = lines.slice(i, i+subsetLength).reduce((acc, l) => {
            const [x, y, c] = l.split(' ').map(Number);
            return Math.min(acc, aList[x-1] + bList[y-1] - c);
        }, minCost);
    }

    console.log(minCost);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    const lines = input.split("\n");

    const [A, B, M] = lines.shift().split(' ').map(Number);
    const aList = lines.shift().split(' ').map(Number);
    const bList = lines.shift().split(' ').map(Number);

    const minA = aList.reduce((acc, current) => Math.min(acc, current), Infinity);
    const minB = bList.reduce((acc, current) => Math.min(acc, current), Infinity);
    let minCost = minA + minB;

    minCost = lines.reduce((acc, l) => {
        const [x, y, c] = l.split(' ').map(Number);
        return Math.min(acc, aList[x-1] + bList[y-1] - c);
    }, minCost);

    console.log(minCost);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


n, x = map(int, input().split())
ls = list(map(int, input().split()))

cur = 0
cnt = 0
for i in range(n):
  if cur <= x:
    cnt += 1
  cur += ls[i]
if cur <= x:
  cnt += 1

print(cnt)


n, x = map(int, input().split())

l = list(map(int, input().split()))

count = 1
d = 0
for i in range(n):
    d = d + l[i]
    if d <= x:
        count += 1

print(count)


import math

N , X = map(int,input().split())
L = list(map(int,input().split()))

now = 0
ans = 1
for i in range(N) :
    now += L[i]
    if now <= X :
        ans += 1
    else :
        break

print(ans)


N,X = map(int,input().split())
l = list(map(int,input().split()))
L = [0] + l
D = [0]
count = 0
for i in range(1,N+2):
    D.append(D[i-1]+L[i-1])
    if D[i]<= X:
        count += 1

print(count + 1)


N,X = map(int,input().split())
l = list(map(int,input().split()))
L = [0] + l
D = [0]
count = 0
for i in range(1,N+2):
    D.append(D[i-1]+L[i-2])
    if D[i]<= X:
        count += 1

print(count + 1)


#ABC130 B

N,X = map(int,input().split())
L = list(map(int,input().split()))
D = [0,L[0]]
count = 0
for i in range(2,N+2):
    D.append(D[i-1]+L[i-2])
for i in range(0,N+2):
    if D[i]<= X:
        count += 1

print(count)


/**
 * Created at 20:53 on 2019-06-16
 */

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

public class Main {

  static FastScanner sc = new FastScanner();

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

  static long MOD = (long) (1e9 + 7);

  public static void main(String[] args) {

    int N = sc.nextInt();
    int X = sc.nextInt();

    int[] L = sc.nextIntArray(N);

    int count = 1;
    int d = 0;
    for (int i=0; i<N; i++) {
      d += L[i];
      if (d <= X) count++;
    }

    System.out.println(count);

  }

  public static class Mathf {

    public static int max(int[] a) {
      int M = a[0];
      for (int i = 1; i < a.length; i++) {
        M = Math.max(M, a[i]);
      }
      return M;
    }

    public static int min(int[] a) {
      int m = a[0];
      for (int i = 1; i < a.length; i++) {
        m = Math.min(m, a[i]);
      }
      return m;
    }

    public static long max(long[] a) {
      long M = a[0];
      for (int i = 1; i < a.length; i++) {
        M = Math.max(M, a[i]);
      }
      return M;
    }

    public static long min(long[] a) {
      long m = a[0];
      for (int i = 1; i < a.length; i++) {
        m = Math.min(m, a[i]);
      }
      return m;
    }

  }

  /*
    add()でインデックスを指定しない場合指定されたソート順に違わない位置に追加する
    (ただしソートされていることが前提となる)
    Comparatorが0を返したとき、それらの順序は保証しない
    (TreeSet, TreeMapと違い削除はしない)
   */
  static class TreeList<E> extends ArrayList<E> {

    Comparator<? super E> comparator;

    TreeList(Comparator<? super E> c) {
      super();
      comparator = c;
    }

    /*
      ソート済みのリストに要素を追加する
     */
    public boolean add(E e) {
      int lowIndex = 0;
      int highIndex = size() - 1;
      int index = 0;

      if (size() == 0) {
        super.add(e);
        return true;
      }

      if (comparator.compare(e, get(0)) < 0) {
        index = 0;
      } else if (comparator.compare(e, get(highIndex)) > 0) {
        index = highIndex + 1;
      } else {
        while (lowIndex <= highIndex) {

          if (highIndex == lowIndex + 1 || highIndex == lowIndex) {
            index = highIndex;
            break;
          }

          int midIndex = (lowIndex + highIndex) / 2;
          ;

          if (comparator.compare(e, get(midIndex)) > 0) {
            lowIndex = midIndex;
          } else {
            highIndex = midIndex;
          }

        }
      }

      super.add(index, e);
      return true;
    }

  }

  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;
    }

    private void skipUnprintable() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
      skipUnprintable();
      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() {
      return (int) nextLong();
    }

    public int[] nextIntArray(int N) {
      int[] array = new int[N];
      for (int i = 0; i < N; i++) {
        array[i] = sc.nextInt();
      }
      return array;
    }

    public long[] nextLongArray(int N) {
      long[] array = new long[N];
      for (int i = 0; i < N; i++) {
        array[i] = sc.nextLong();
      }
      return array;
    }
  }

}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	private final static int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] L = new int[N];
		sc.fill(L);

		int count = 1;
		long current = 0;
		for (int i = 0; i < N; i++) {
			current += L[i];
			if (current > X) {
				break;
			}

			count++;
		}

		System.out.println(count);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	private static int add(int a, int b) {
		return (a + b) % MOD;
	}

	private static int sub(int a, int b) {
		return (a - b % MOD) % MOD;
	}

	private static int mul(int a, int b) {
		return ((a % MOD) * (b % MOD)) % MOD;
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

public class Main {
    static void solve(MyScanner in, PrintWriter out) {
        int n = in.nextInt();
        int x = in.nextInt();
        int[] l = in.nextIntArray(n);
        int d = 0;
        int ans = 1;
        for (int a : l) {
            d = d + a;
            if (d <= x)
                ans++;
        }
        out.println(ans);
    }

    public static void main(String[] args) {
        PrintWriter w = new PrintWriter(System.out);
        solve(new MyScanner(System.in), w);
        w.flush();
    }

    static final class MyScanner {
        static final int BUFFER_SIZE = 8192;
        private final InputStream in;
        private final byte[] buffer = new byte[BUFFER_SIZE];
        private int point;
        private int readLength;
        MyScanner(InputStream in) {
            this.in = in;
        }
        private int readByte() {
            if (point < readLength) {
                int result = buffer[point];
                point += 1;
                return result;
            }
            try {
                readLength = in.read(buffer);
            } catch (IOException e) {
                throw new AssertionError(null, e);
            }
            if (readLength == -1) {
                return -1;
            }
            point = 1;
            return buffer[0];
        }
        private static boolean isPrintableCharExceptSpace(int c) {
            return 33 <= c && c <= 126;
        }
        String next() {
            int c = readByte();
            while (!(c == -1 || isPrintableCharExceptSpace(c))) {
                c = readByte();
            }
            assert c != -1;
            StringBuilder b = new StringBuilder();
            do {
                b.appendCodePoint(c);
                c = readByte();
            } while (c != -1 && isPrintableCharExceptSpace(c));
            return b.toString();
        }
        long nextLong() {
            int c = readByte();
            while (!(c == -1 || isPrintableCharExceptSpace(c))) {
                c = readByte();
            }
            assert c != -1;
            boolean minus = false;
            if (c == '-') {
                minus = true;
                c = readByte();
            }
            long result = 0L;
            do {
                assert '0' <= c && c <= '9' : c;
                result = result * 10L + (c - '0');
                c = readByte();
            } while (c != -1 && isPrintableCharExceptSpace(c));
            return minus ? -result : result;
        }
        int nextInt() {
            long n = nextLong();
            assert Integer.MIN_VALUE <= n && n <= Integer.MAX_VALUE : n;
            return (int)n;
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        int[] nextIntArray(int n) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextInt();
            }
            return result;
        }
        private static boolean allSameLength(int[] a, int[] b, int[]... c) {
            if (a.length != b.length) {
                return false;
            }
            for (int i = 0; i < c.length; i++) {
                if (a.length != c[i].length) {
                    return false;
                }
            }
            return true;
        }
        private static boolean allSameLength(char[] a, char[] b, char[]... c) {
            if (a.length != b.length) {
                return false;
            }
            for (int i = 0; i < c.length; i++) {
                if (a.length != c[i].length) {
                    return false;
                }
            }
            return true;
        }
        void nextVerticalIntArrays(int[] a, int[] b, int[]... c) {
            assert allSameLength(a, b, c);
            for (int i = 0; i < a.length; i++) {
                a[i] = nextInt();
                b[i] = nextInt();
                for (int[] d : c) {
                    d[i] = nextInt();
                }
            }
        }
        long[] nextLongArray(int n) {
            long[] result = new long[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextLong();
            }
            return result;
        }
        char nextChar() {
            int c = readByte();
            while (!(c == -1 || isPrintableCharExceptSpace(c))) {
                c = readByte();
            }
            assert c != -1;
            return (char)c;
        }
        char[] nextCharArray(int n) {
            char[] result = new char[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextChar();
            }
            return result;
        }
        char[][] next2dCharArray(int n, int m) {
            char[][] result = new char[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    result[i][j] = nextChar();
                }
            }
            return result;
        }
        void nextVerticalCharArrays(char[] a, char[] b, char[]... c) {
            assert allSameLength(a, b, c);
            for (int i = 0; i < a.length; i++) {
                a[i] = nextChar();
                b[i] = nextChar();
                for (char[] d : c) {
                    d[i] = nextChar();
                }
            }
        }
    }
}


import java.util.*;
public class Main {
    Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        new Main().run();
    }
    void run() {
      int n = sc.nextInt();
      int x = sc.nextInt();
      int[] l = new int[n];
      for(int i = 0; i < n; ++i) {
        l[i] = sc.nextInt();
      }

      int a = 0;
      int c = 0;
      for (int j = 0; j < l.length; ++j) {
        if (l[0] > x) break;
        if (a <= x) c++;
        a = a + l[j];
      }
      System.out.println(c);
    }
}


import java.util.*;
public class Main {
    Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        new Main().run();
    }
    void run() {
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] l = new int[n];
        for(int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }
        int a = 0;
        int c = 0;
        for (int j = 0; j < n; j++) {
            if (a <= x) {
                a += l[j];
                c++;
            }
        }
        System.out.print(c);
    }
}


import java.util.*;
public class Main {
    Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        new Main().run();
    }
    void run() {
      int n = sc.nextInt();
      int x = sc.nextInt();
      int[] l = new int[n];
      for(int i = 0; i < n; ++i) {
        l[i] = sc.nextInt();
      }
      int a = 0;
      int c = 0;
      for (int j = 0; j < l.length; j++) {
        if (l[0] >= x) {
          break;
        }
      	if (a < x) {
          c++;
      	}
        a = a + l[j];
      }
      System.out.println(c);
    }
}


#include<stdio.h>
int main(void){
  int n,x,i,t=0;
  scanf("%d %d",&n,&x);
  int l[n];
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
  i=1;
  while(t<=x && i<=n){
    t+=l[i-1];
    i++;
  }
  if(t>x){
    i--;
  }
  printf("%d\n",i);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll n,x;cin>>n>>x;
  vector<ll>a(n);
  for(i=0;i<n;i++)cin>>a[i];
  res=1;buf=0;
  for(i=0;i<n;i++){
    buf+=a[i];
    if(buf<=x)res++;
  }
  cout<<res<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

void solve(long long N, long long X, std::vector<long long> L) {
  ll d = 0;
  ll ans = 1;
  for(int i = 0 ; i < N ; i++){
    d += L[i];
    if( d <= X ){
      ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long X;
  scanf("%lld", &X);
  std::vector<long long> L(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &L[i]);
  }
  solve(N, X, std::move(L));
  return 0;
}


#include<bits/stdc++.h>
//g++ -std=c++11

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

int main(){
	ll N, X;
	cin >> N >> X;
	vector<ll> L(N);
	rep(i, N) cin >> L[i];

	ll ans = 0;
	ll cur = 0;
	for(ll i = 0; i < N; i++) {
		if(cur <= X) {
		ans++;
		}
		cur += L[i];
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const long long INF = 1LL << 60;
int main(){
    int N,X;
    cin>>N>>X;
    vector<int>L(N);
    int ans=0;
    int cnt=0;
    rep(i,N){
        cnt++;
        cin>>L[i];
        ans+=L[i];
        if(X<ans){
            cout<<cnt<<endl;
            break;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const long long INF = 1LL << 60;
int main(){
    int N,X;
    cin>>N>>X;
    vector<int>L(N);
    int ans=0;
    int cnt=0;
    rep(i,N){
        cnt++;
        cin>>L[i];
        ans+=L[i];
        if(X<=ans){
            cout<<cnt<<endl;
            break;
        }
    }
}


#include<stdio.h>

int main(void){
  int x,n,i;
  scanf("%d%d",&n,&x);
  int l[n];
  int d[n];
  d[0]=0;
  for(i=0;i<n;i++){
    scanf("%d ",&l[i]);
  }

  for(i=1;i<=n;i++){
    d[i]=d[i-1]+l[i-1];

  }
  int cout;

  for(i=0;i<=n;i++){
    if(d[i]<=x){
      cout++;

    }

  }
  printf("%d",cout);
  return 0;

}


#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n, l[105], x, ans = 1;
  scanf("%d %d", &n, &x);
  for(int i = 0; i < n; i++) scanf("%d", &l[i]);

  int d = 0;
  for(int i = 1; i <= n; i++){
    d += l[i - 1];
    if(d <= x) ans++;
  }

  printf("%d\n", ans);

  return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(void) {
  int n, x, i;
  int *l;
  scanf("%d %d", &n, &x);
  l = (int*)malloc(n * sizeof(int));
  for(i=0; i<n; i++) {
    scanf("%d", &l[i]);
  }
  int d=0;
  for(i=0; d<=x && i<n; i++) {
    d += l[i];
  }
  if(d<=x) {
    i++;
  }
  printf("%d\n", i);
  return 0;
}


#include<stdio.h>

int main(void) {
   int N, X;

   scanf("%d %d",&N, &X);

   int L[N];

   for(int i = 0; i < N; i++) {
      scanf("%d", &L[i]);
   }

   int D[N];
   D[0] = 0;

   for(int i = 1; i < N; i++) {
      D[i] = D[i-1] + L[i-1];
   }

   int cnt = 0;

   for(int i = 0; i < N; i++) {
      if(D[i] <= X) {
         cnt++;
      }
   }

   printf("%d\n", cnt);

   return 0;
}


n, x = map(int, input().split())
l = list(map(int, input().split()))

cnt = 1
a = 0
for i in range(0, len(l)):
  a += l[i]
  if(a <= x):
    cnt = cnt + 1

print(cnt)


 #include<stdio.h>
 int main(void)
 {
     int N,X,i,V;
     int D[101],L[101];

     scanf("%d%d",&N,&X);

     for(i=1;i<=N;i++)
       scanf("%d",&L[i-1]);

     for(i=1;i<=N;i++){
         D[0]=0;
         D[i]=D[i-1]+L[i-1];
     }

     for(i=0;i<=N;i++)
         if(D[i]<=X) V++;

     printf("%d\n",V);

     return 0;
 }


function main(input) {
    a = input[0].split(' ');
    n = a[0];
    x = a[1];
    l = input[1].split(' ');
    var i,value = 0, ans = 0;
    for(i=0; i<n; i++) {
        l[i] = parseInt(l[i], 10);
        if (value <= x) {
            ans++;
            value += l[i];
        }
    }
    if (value <= x) ans++;
    console.log(ans);
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));


'use strict'
function Main(input) {
  let jumpNum = input.split("\n")[0].split(" ")[0]*1;
  let jumpLimit = input.split("\n")[0].split(" ")[1]*1;
  let arr = input.split("\n")[1].split(" ");
  let count = 1;
  let sum = 0;
  for(let i in arr){
    sum += arr[i]*1;
    if(sum <= jumpLimit){
    	count++;
    }
    else{
		break;
    }
  }
  console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    input = input.trim().split("\n");
    tmp = input[0].split(" ");
    var N = parseInt(tmp[0], 10);
    var X = parseInt(tmp[1], 10);
    var L = [];
    tmp = input[1].split(" ");
    for (var i = 0; i < N; i++){
        L[i] = parseInt(tmp[i], 10);
    }

    var D = 0;
    var bound = 1;
    for (var i = 0; i < N; i++){
        D += L[i];
        if (D > X) {
            break;
        }
        bound++;
    }
    console.log(bound);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  const args = input.split('\n');
  const [N, X] = args[0].split(' ');
  const L = args[1].split(' ');
  const n = Number(N);
  let count = 0;
  const array = [0];
  for (let i = 0; i < n; i++) {
    array.push(count += Number(L[i]));
   }
  for (let i = 0; i < array.length; i++) {
    if (array[i] > X) {
      console.log(i)
      return
    }
  }
  return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
  const args = input.split('\n');
  const [N, X] = args[0].split(' ');
  const L = args[1].split(' ');
  const n = Number(N);
  let count = 0;
  const array = [0];
  for (let i = 0; i < n; i++) {
    array.push(count += Number(L[i]));
   }
  for (let i = 0; i < array.length; i++) {
    if (array[i] > X) {
      console.log(i)
      return
    }
  }
  return;
}


function main(input) {
  const args = input.split('\n');
  const [N, X] = args[0].split(' ');
  const L = args[1].split(' ');
  const n = Number(N);
  let count = 0;
  for (let i = 0; i < n + 1; i++) {
    if (X < count) {
      console.log(i)
      return;
    }
    count += Number(L[i]);
   }
  return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


package main

import "fmt"

func main() {
	var N, X int
	fmt.Scanf("%d %d", &N, &X)
	L := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &L[i])
	}
	D := 0
	count := 0
	for i := 0; i < N; i++ {
		if D <= X {
			count++
		}
		D += L[i]
	}
	if D <= X {
		count++
	}
	fmt.Println(count)
}


package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr()
	N := list[0]
	X := list[1]
	L := getStdinIntArr()
	D := make([]int, 0)
	D = append(D, 0)

	cnt := 1
	for i := 0; i < N; i++ {
		D1 := D[i] + L[i]
		D = append(D, D1)
		if D1 > X {
			break
		}
		cnt++
	}

	fmt.Printf("%d\n", cnt)
}

func getStdin() string {
	return readLine()
}
func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	X := getInt()
	L := getIntArray(N)

	pos := 0
	cnt := 1
	for i := 1; i <= N; i++ {
		pos += L[i-1]
		if pos > X {
			break
		}
		cnt++
	}

	fmt.Println(cnt)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func bfs(c int, graph *Graph) {
	next := make([]int, 0)
	next = append(next, c)
	visited := make(map[int]struct{})

	for ; len(next) != 0; {
		u := next[0]
		next = next[1:]
		visited[u] = struct{}{}

		for v := range graph.edges[u] {
			_, flag := visited[v]
			if flag {
				continue
			}

			// なにか処理

			next = append(next, v)
		}
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntArray(n int) []int {
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = getInt()
	}
	return array
}

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

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return calcMod(n * powMod(n, p-1))
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func makeRange(min, max int) []int {
	a := make([]int, max-min+1)
	for i := range a {
		a[i] = min + i
	}
	return a
}

func powerset2(nums []int) [][]int {
	length := int(math.Pow(2, float64(len(nums))))
	result := make([][]int, length)

	index := 0
	result[index] = []int{}
	index++

	for _, n := range nums {
		max := index
		for i := 0; i < max; i++ {
			result[index] = copyAndAppend(result[i], n)
			index++
		}
	}

	return result
}

func copyAndAppend(nums []int, n int) []int {
	dst := make([]int, len(nums)+1)
	copy(dst, nums)
	dst[len(nums)] = n
	return dst
}

func calcGcd(x, y int) int {
	if y == 0 {
		return x
	} else if x >= y {
		return calcGcd(y, x % y)
	} else {
		return calcGcd(x, y % x)
	}
}

func getDivisor(n int) []int {
	var divisor []int
	divisor = append(divisor, 1)
	if n != 1 {
		divisor = append(divisor, n)
	}

	sqrt := int(math.Sqrt(float64(n)))
	for i := 2; i <= sqrt; i++ {
		if n % i == 0 {
			divisor = append(divisor, i)
			divisor = append(divisor, n/i)
		}
	}
	return divisor
}

type intHeap []int

func (h intHeap) Len() int {
	return len(h)
}

func (h intHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h intHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func initHeap() *intHeap {
	ih := &intHeap{}
	heap.Init(ih)
	return ih
}

func (h *intHeap) pushHeap(n int) {
	heap.Push(h, n)
}

func (h *intHeap) popHeap() int {
	return heap.Pop(h).(int)
}

func factMod(n int) int {
	value := 1
	for ; n > 1; n-- {
		value = calcMod(value * n)
	}
	return value
}

func combinationMod(n, k int) int {
	factN := factMod(n)
	factK := factMod(k)
	factNK := factMod(n - k)
	factKR := powMod(factK, mod - 2)
	factNKR := powMod(factNK, mod - 2)
	return calcMod(factN * calcMod(factKR * factNKR))
}


package main

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

func main() {
	var n, x int
	fmt.Scan(&n, &x)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	l := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		l[i], _ = strconv.Atoi(sc.Text())
	}

	d := 0
	ans := 1
	for i := 1; i < n; i++{
		d += l[i-1]

		if d <= x {
			ans++
		}
	}
	fmt.Println(ans)
}


package main

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

func main() {
	var n, x int
	fmt.Scan(&n, &x)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	l := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		l[i], _ = strconv.Atoi(sc.Text())
	}

	d := 0
	ans := 1
	for i := 1; i < n; i++{
		d += l[i]

		if d <= x {
			ans++
		}
	}
	fmt.Println(ans)
}


n, x = gets.chomp.split(" ").map(&:to_i)
li = gets.chomp.split(" ").map(&:to_i)
ans = 1
dist = 0
li.each do |e|
    dist += e
    break if dist > x
    ans += 1
end
puts ans


# frozen_string_literal: true

n, x = gets.split.map(&:to_i)
l = gets.split.map(&:to_i)
pt = 0

l.each_with_index do |i, idx|
  pt += i
  if pt > x
    puts idx + 1
    exit
  end
end

puts n + 1


n, x = gets.split(/ /).map(&:to_i)
l_list = gets.split(/ /).map(&:to_i)

# puts "n: #{n}"
# puts "x: #{x}"
# puts "l_list: #{l_list.inspect} (#{l_list.length})"

class Jump
  def initialize(d, index)
    @d = d
    @index = index
  end

  attr_reader :d, :index
end

d = [Jump.new(0, 1)]
l_list.each.with_index(1) do |l, i|
  d_next = d.last.d + l
  if d_next <= x
    d.push(Jump.new(d_next, i + 1))
  else
    break
  end
end

puts d.last.index


input = readlines()

n, x = input.shift.chomp.split("\s").map{|x| x.to_i}
list = input.shift.chomp.split("\s").map{|x| x.to_i}

cnt = 1
list.each do |l|
  cnt += 1 if l <= x
end

puts cnt


input = readlines()

n, x = input.shift.chomp.split("\s").map{|x| x.to_i}
list = input.shift.chomp.split("\s").map{|x| x.to_i}

cnt = 0
list.each do |l|
  cnt += 1 if l <= x
end

puts cnt


n,x=gets.split.map(&:to_i)
l=gets.split.map(&:to_i)
sum=[0]
ans=0
(0...n).each do |m|
  ans+=1
  sum[m+1]=sum[m]+l[m]
  break if sum[m+1]>x
end
p ans


#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let x: i64 = sc.cin();
    let mut u = 0;
    let mut ans = 1;
    for _ in 0..n {
        let ell: i64 = sc.cin();
        u += ell;
        if u <= x {
            ans += 1;
        }
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


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 main() {
    input! {
        n: u32,
        x: u32,
        ll: [u32;n]
    }
    let mut a = 0;
    let mut cnt = 0;
    for l in ll {
        a += l;
        if a <= x {
            cnt += 1;
        }
    }
    println!("{}", cnt+1);
}


#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, x: usize, l: [usize; n]);

    let mut count = 0;
    let mut d = 0;
    loop {
        if x < d || count >= n {
            break;
        }

        d += l[count];

        count += 1;
    }

    println!("{}", count);
}


#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, x: usize, l: [usize; n]);

    let mut count = 0;
    let mut d = 0;
    loop {
        if x < d || count >= n + 1 {
            break;
        }

        d += l[count];

        count += 1;
    }

    println!("{}", count);
}


let inp = readLine()!.split(separator: " ").map { Int($0)! }

let N = inp[0]
let X = inp[1]

let L = readLine()!.split(separator: " ").map { Int($0)! }

var current = 0

var d = 0
var i = 0
while i < L.count {
  if d + L[i] > X {
    break
  }
  d += L[i]
  i += 1
}
print(i + 1)


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, X) = (input[0], input[1])
let L = readLine()!.characters.split(" ").map{Int(String($0))!}
var sum = [0]
(0..<N).forEach{sum+=[sum[$0]+L[$0]]}
print(sum.reduce(0){$0+($1>X ?0:1)})


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, X) = (input[0], input[1])
let L = readLine()!.characters.split(" ").map{Int(String($0))!}
var D = 0
print(L.reduce(1){D+=$1;return $0+(D>X ?0:1)})


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, X) = (input[0], input[1])
let L = readLine()!.characters.split(" ").map{Int(String($0))!}
var sum = [0]
(0..<N).forEach{sum+=[sum[$0]+A[$0]]}
print(sum.reduce(0){$0+($1>X ?0:1)})


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, X) = (input[0], input[1])
let L = [0] + readLine()!.characters.split(" ").map{Int(String($0))!}
(0..<N).reduce(1){$0+(L[$1]+L[$1+1]>X ?0:1)}


let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, X) = (input[0], input[1])
let L = [0] + readLine()!.characters.split(" ").map{Int(String($0))!}
(1..<N).reduce(1){$0+(L[$1-1]+L[$1]>X ?0:1)}


export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const [n, x]: number[] = tmp[0].split(" ").map(Number);
    const l: number[] = tmp[1].split(" ").map(Number);
    let d: number = 0;
    let result: number = 1;
    for (let i: number = 0; i < n; ++i) {
      d += l[i];
      if (d <= x) {
        ++result;
      } else {
        break;
      }
    }
    return `${result}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


import * as fs from 'fs';

namespace AtCoder.abc130 {
    class ProgramB {
        args: string[];

        // 3 6
        // 3 4 5
        //
        // 2
        constructor(args: string[]) {
            this.args = args;
        }

        main(this: ProgramB) {

            const [n, x]: number[] = this.args[0].split(' ').map(Number);
            const l: number[] = this.args[1].split(' ').map(Number);

            let d: number = 0;
            let ans: number = 0;
            l.forEach((val: number) => {
                if (d <= x) ans++;
                d += val;
            });

            if (d <= x) ans++;

            console.log(ans);

        }
    }

    const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    new ProgramB(args).main();
}


import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n, x] = input[0].split(" ").map((x: string): number => +x);
const l = input[1].split(" ").map((x: string): number => +x);

let result = 1;
let sum = 0;
for (let i = 0; i < n; i++) {
  sum += l[i];
  if (sum > x) break;
  result++;
}
console.log(result);


import * as fs from 'fs';

namespace AtCoder.abc130 {
    class ProgramB {
        args: string[];

        // 3 6
        // 3 4 5
        //
        // 2
        constructor(args: string[]) {
            this.args = args;
        }

        main(this: ProgramB) {

            const [n, x]: number[] = this.args[0].split(' ').map(Number);
            const l: number[] = this.args[1].split(' ').map(Number);

            let d: number = 0;
            let ans: number = 0;
            l.forEach((val: number) => {
                if (d <= x) ans++;
                d += val;
            });

            console.log(ans);

        }
    }

    const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    new ProgramB(args).main();
}


import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n,x] = input[0].split(" ").map((x: string): number => +x);
const l = input[1].split(" ").map((x: string): number => +x);

let result = 0;
let sum = 0;
for(let i=0; i<n && sum<=x; i++){
  result++;
  sum += l[i];
}
console.log(result);


import fs = require('fs')
const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n')

const [N, X] = input[0].split(' ').map(Number)

const L = input[0].split(' ').map(Number)

let s = 1
let p = 0
for (const l of L) {
    p += l
    if (p > X) { break }
    s++
}
console.log(s)


#!/usr/bin/env python3 ## -*- python -*-

s = input()

if "AB" in s:
  print("Yes")
elif "BA" in s:
  print("Yes")
else:
  print("No")


s = input()
if len(s) != 3:
    print('No')
if s.upper() == 'AAA' or s.upper() == 'BBB' :
    print('No')
else:
    print('Yes')


a = input()

if a == "AAA" or a == "BBB":
    print("No")
else:
    print("Yes")


s=input()
if s=="AAA" or "BBB":
  print("No")
else:
  print("Yes")


s = raw_input()
if(s == 'AAA' or s == 'BBB'):
    print("No")
else:
    print("Yes")


s=input()
if s=="AAA" or 'BBB':
  print('No')
else:
    print('Yes')


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //コンソールから入れる際に高速に入れる方法
		String x = br.readLine();
      	if(x.contains("A") && x.contains("B")) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }
}


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

public class Main {
    static Character[] toCharacterArray(String s) {
        if (s == null) {
            return null;
        }
        int len = s.length();
        Character[] array = new Character[len];
        for (int i = 0; i < len; i++) {
            array[i] = new Character(s.charAt(i));
        }
        return array;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String arr = reader.readLine();

        Set<Character> S = new HashSet<Character>(Arrays.asList(toCharacterArray(arr)));
        System.out.println(1 < S.size() ? "Yes" : "No");
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        String s = arr01[0];

        if (s.equals("AAA") || s.equals("BBB")) {
            System.out.println("No");
        } else {
            System.out.println("Yes");

        }

    }

}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.charAt(0)==s.charAt(1) && s.charAt(1)==s.charAt(2)) {
            System.out.print("Yes");
        } else {
            System.out.print("No");
        }
    }
}


import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)

  while (input.hasNext()) {
    val S = input.next()
    var countA = 0
    var countB = 0

    for (c in S) {
      if (c == 'A') {
        ++countA
      }

      if (c == 'B') {
        ++countB
      }
    }

    if (countA == 3 || countB == 3) {
      println("No")
    } else {
      println("Yes")
    }
  }
}


import java.io.*;
import java.util.*;
public class Main {
    final static long mod = 1000000007;

    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        Random gen = new Random();
        int test = 1;//sc.nextInt();
        while(test-->0) {
            char[] ar = sc.nextLine().toCharArray();
            LinkedList<Character> l = new LinkedList<>();
            for(char c: ar)
                l.add(c);

            int q = sc.nextInt();
            while(q-->0)
            {
                int op = sc.nextInt();
                if(op==1)
                    Collections.reverse(l);
                else
                {
                    int f = sc.nextInt();
                    char c = sc.readString().charAt(0);
                    if(f==1)
                        l.add(0,c);
                    else
                        l.add(c);
                }
            }
           for(char c : l)
               pw.print(c);
        }
        pw.flush();
        pw.close();

    }

    static class Data implements Comparable<Data>{
        int x;
        int y;

        public Data (int m, int n) {
            x = m;
            y = n;
        }
        @Override
        public int compareTo(Data o) {
            return y - o.y;
        }
    }

    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream st) {
            this.stream = st;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int [] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public static int[] shuffle(int[] a, Random gen)
        { for(int i = 0, n = a.length;i < n;i++)
        { int ind = gen.nextInt(n-i)+i;
            int d = a[i];
            a[i] = a[ind];
            a[ind] = d;

        }
            return a;
        }
        public static char[] shuffle(char[] a, Random gen)
        { for(int i = 0, n = a.length;i < n;i++)
        { int ind = gen.nextInt(n-i)+i;
            char d = a[i];
            a[i] = a[ind];
            a[ind] = d;

        }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }

}


#include <cstdio>
using namespace std;

int main(int argc, char** argv)
{
	char a = getchar(), b = getchar(), c = getchar();
	getchar(); // Get the '\n'
	puts((a == b && b == c && a == c)? "No": "Yes");
	return 0;
}


#include <stdio.h>
#include "string.h"
char s[4];

int main()
{
    scanf("%s",s);
    if(strcmp(s,"AAA")==0 ||strcmp(s,"BBB")==0){
        printf("No");
    }
    else{
        printf("Yes");
    }
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<ctype.h>
int main()
{
    char a[1000];
    scanf("%s",&a);
    for(int i=0;i<strlen(a);i++){
        if((a[i]==a[i+1] && a[i]!=a[i+2])||(a[i]==a[i+2] && a[i]!=a[i+1])){
        printf("Yes");
        break;}
        else if(a[i]==a[i+1] && a[i]==a[i+2]){
            printf("No");
            break;}}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	string st;
	cin>>st;
	if(st[0]=='A' && st[1]=='A' && st[2]=='A' || st[0]=='B' && st[1]=='B' && st[2]=='B' )
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}


#define LOCAL

#include<bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f

using llong = long long;
using PII = pair<int, int>;

const llong MOD = 123456789LL;
const double PI = acos(-1);

int main() {
	IOS;
	string s; cin >> s;
	if (s == "AAA" || s == "BBB") cout << "No";
	else cout << "Yes";
}


#include <stdio.h>

int main (){
	char A[11];
	scanf("%s", &A);
	if(A[0]==A[1], A[1]==A[2])
	{
	puts("No");
	}
	else
	{
	puts("Yes");
	}
return 0;
}


#include <stdio.h>

int main(){
    char s[5];

    scanf("%s",s);

    if((s[0]=='A') && (s[1]=='B') && (s[2]=='A'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='A') && (s[2]=='A'))
        printf("Yes\n");
    else if((s[0]=='A') && (s[1]=='A') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='A') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='A') && (s[1]=='B') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='B') && (s[2]=='A'))
        printf("Yes\n");

    else
            printf("No\n");

    return 0;
}


#include <stdio.h>

int main(){
    char s[5];

    scanf("%s",s);

    if((s[0]=='A') && (s[1]=='B') && (s[2]=='A'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='A') && (s[2]=='A'))
        printf("Yes\n");
    else if((s[0]=='A') && (s[1]=='A') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='A') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='A') && (s[1]=='B') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='B') && (s[2]=='A'))
        printf("Yes\n");

    else if(((s[0]=='B')&& (s[1]=='B') && (s[2]=='B'))||((s[0]=='A') && (s[1]=='A') && (s[2]=='A')))
            printf("No\n");

    return 0;
}


#include <stdio.h>

int main (void){
    char s[3];
    scanf("%s",s);
    int i = -1;
    int flg = 0;
    while(++i < 3){
        if(s[i] != s[0])
            flg = 1;
    }
    if(flg)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


    char s[3];
    scanf("%s", s);

    if(s[0]=s[1] && s[0]==s[2] && s[1]==s[2]){
    	puts("No");
	}
    else if(s[0]=s[1] && s[0]!=s[2] && s[1]!=s[2]){
    	puts("Yes");
	}
	else if(s[0]=s[2] && s[0]!=s[1] && s[1]!=s[2]){
		puts("Yes");
	}
	else if(s[1]=s[2] && s[0]!=s[1] && s[0]!=s[2]){
		puts("Yes");
    }


#include <stdio.h>
	int main(){
		char stat[3];
		scanf("%s", stat);
		if (stat[0] == stat[1] && stat[1] == stat[2] && stat[0] == stat[2]){
			printf("No");
		} else {
			printf ("Yes");
		}
		return 0;
	}


#include <stdio.h>
#include <string.h>
int main(void)
{
	char S[3],A[] = "AAA",B[] = "BBB";
	scanf("%s",S);
	if(strcmp(S,A) == 0 || strcmp(S,B) == 0){
		printf("No");
	}else{
		printf("Yes");
	}
	return 0;
}


function Main(input){
	var S = input.trim();
  	var W_MAX = 3;
  	var b = true;
  	if(S[0] === S[1] && S[0] === S[2])b=false;
  	var result = b?"Yes":"No";
  	console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input){
    var s = input.trim();

    if(s[0]==s[1]&&s[1]==s[2]){
        console.log("No");
    }else{
        console.log("Yes");
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'

const main = (arg) => {
  const S = arg.split('\n')[0].split('')
  if (S[0] != S[1] || S[0] != S[2] || S[1] != S[2]) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


function Main(input) {
	if (input === "AAA" || input === "BBB"){
	    return console.log("No");
	}else{
	    return console.log("Yes");
	}
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    input = input.split(" ");
	if (input === "AAA" || input === "BBB"){
	    return console.log("No")
	}else{
	    return console.log("Yes");
	}
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    input = input.split(" ");
	if (input === "AAA" || input === "BBB")  console.log("No");
  	else console.log("Yes");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	s := nextStr()

	if s[0] == s[1] && s[0] == s[2] {
		fmt.Println("No")
		return
	}

	fmt.Println("Yes")
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


package main

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

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	stdInScanner.Scan()
	return stdInScanner.Text()
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	S := nextString()

	aCounter := 0
	bCounter := 0
	for _, s := range strings.Split(S, "") {
		switch s {
		case "A":
			aCounter++
		case "B":
			bCounter++
		}
	}
	if aCounter >= 1 && bCounter >= 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	s := readString()
	if strings.Contains(s, "AB") || strings.Contains(s, "BA") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


package main

import "fmt"

func main() {
	var companys []int = make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&companys[i])
	}

	fmt.Println(check(companys))
}

func check(tSlice []int) string {
	for _, num := range tSlice {
		if num != tSlice[0] {
			return "Yes"
		}
	}
	return "No"
}


package main

import "fmt"

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

	var companys []int = make([]int, companyNum)
	for i := 0; i < companyNum; i++ {
		fmt.Scan(&companys[i])
	}

	fmt.Println(check(companys))
}

func check(tSlice []int) string {
	for _, num := range tSlice {
		if num != tSlice[0] {
			return "Yes"
		}
	}
	return "No"
}


package main

import (
	"fmt"
)

func main() {

	var s string

	if s == "AAA" {
		fmt.Println("No")
	} else if s == "BBB" {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}

}


# https://atcoder.jp/contests/abc158/tasks/abc158_a

S = gets.chomp
cond = !%w[AAA BBB].include?(S)
puts cond ? 'Yes' : 'No'


S = gets.split("")
if S.include?("A") && S.include?("B") then
    puts "Yes"
else
    puts "No"
end


io = STDIN
str=io.gets.chomp
if str =="AAA" ||
 str =="BBB"
 puts 'No'
else
  puts 'Yes'
end


puts gets.chomp.chars.uniq.size!=1?'No':'Yes'


S = gets.split()
ans = S.uniq.length==1 ? "No" : "Yes"
puts ans


S = gets.split("")
ans = S.chomp.uniq.length==1 ? "No" : "Yes"
puts ans


fn main() {
    let s = input();
    println!("{}", solve(s));
}

fn input() -> Vec<char> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let s = buf.chars();
    s.collect()
}

fn solve(s: Vec<char>) -> String {
    let mut a = 0;
    let mut b = 0;
    for c in s.iter() {
        if *c == 'A' { a += 1; }
        else if *c == 'B' { b += 1; }
    }
    if a != 0 && b != 0 {
        return String::from("Yes");
    }
    String::from("No")
}


#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn f(s: &[char]) -> bool {
    let m = s.len();
    for i in 0..m {
        if s[i] != s[m - 1 - i] {
            return false;
        }
    }
    true
}

use std::iter::Iterator;

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

    if s == "AAA" || s == "BBB" {
        println!("No")
    }else{
        println!("Yes")
    }

}


/* {{{ */
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 main() {
    input! {
        s: chars
    }
    if s[0] == s[1] && s[1] == s[2] {
        println!("No");
    } else {
        println!("Yes");
    }
}
/* vim:set foldmethod=marker: */


use std::process::exit;

fn main() {
  let input: Vec<u32> = read_vec();
  for i in 1..101 {
    if i*8/100 == input[0] && i*10/100  == input[1] {
      println!("{}", i);
      exit(0);
    }
  }
  println!("-1");
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


use proconio::input;

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

    solve(s);
}

fn solve(s: String) {
    match s.as_str() {
        "AAA" | "BBB" => println!("Yes"),
        _ => println!("No"),
    }
}


use proconio::input;
use std::collections::HashMap;

/// 状態
#[derive(Hash, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)]
struct State {
    /// 受理状態かどうか
    is_accept: bool,
    /// State間を比較できるように，IDをつけておく
    id: usize,
}

/// 有限オートマトンを表す構造体
struct Automaton {
    /// 状態の有限集合Q
    states: HashMap<String, State>,
    /// 遷移関数群
    transitions: HashMap<State, Box<dyn Fn(char) -> String>>,
    /// Stateにつける通し番号
    id: usize,
}

impl Automaton {
    /// ある状態qと, qからの遷移関数を登録する
    fn add_states(&mut self, name: &str, is_accept: bool, transition: fn(char) -> String) {
        let state = State {
            is_accept,
            id: self.id,
        };
        self.id += 1;
        self.states.insert(name.to_string(), state);
        self.transitions.insert(state, Box::new(transition));
    }

    /// 言語Lで記述された文字列sを受理するか判定
    fn run(&self, s: String) -> bool {
        let mut current_state = *self.states.get("q0").unwrap();
        for c in s.chars() {
            let transition = self.transitions.get(&current_state).unwrap();
            let next_state_name = transition(c);
            current_state = *self.states.get(&next_state_name).unwrap();
        }
        current_state.is_accept
    }
}

fn transition_q0(c: char) -> String {
    if c == 'A' {
        return "q2".to_string();
    }

    "q1".to_string()
}
fn transition_q1(c: char) -> String {
    if c == 'B' {
        return "q3".to_string();
    }

    "q1".to_string()
}
fn transition_q2(c: char) -> String {
    if c == 'A' {
        return "q3".to_string();
    }

    "q2".to_string()
}
fn transition_q3(_c: char) -> String {
    "q3".to_string()
}

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

    let mut m = Automaton {
        states: HashMap::new(),
        transitions: HashMap::new(),
        id: 0,
    };

    m.add_states("q0", false, transition_q0);
    m.add_states("q1", false, transition_q1);
    m.add_states("q2", false, transition_q2);
    m.add_states("q3", true, transition_q3);

    if m.run(s) {
        println!("Yes");
    } else {
        println!("No");
    }
}


let input_line=readLine()!
if input_line == "AAA" {
  print("No")
} else if input_line == "BBB"{
  print("No")
}else{
 print("Yes")
}


let busLine = readLine()!
var A = ""
var B = ""
var answer = "Yes"
for _ in 0..<busLine.characters.count{
  A += "A"
  B += "B"
  if busLine == A || busLine == B{
    answer = "No"
  }
}
print(answer)


func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let s = Set(Array(readLine()!))

    if s.count == 1 {
        print("No")
    } else {
        print("Yes")
    }
}

main()


let busLine = readLine()!
var A = ""
var B = ""
var answer = "Yes"
for _ in 0..<busLine.characters.count{
  A += "A"
  B += "B"
  if busLine == A || busLine == B{
    answer = "No"
  }
}


let busLine = readLine()!
var A = ""
var B = ""
var answer = "Yes"
for _ in 0..<busLine.character.count{
  A += "A"
  B += "B"
  if busLine == A || busLine == B{
    answer = "No"
  }
}


let busLine = readLine()!
var A = ""
var B = ""
var answer = "Yes"
for _ in 0..<b.character.count{
  A += "A"
  B += "B"
  if busLine == A || busLine == B{
    answer = "No"
  }
}


function Main(input: string) {
  const lines: string[] = input.split('\n');
  const line = lines[0];
  if (line === 'AAA' || line === 'BBB') {
    console.log('No');
  } else {
    console.log('Yes');
  }
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8")
console.log(input.trim().split("").reduce((ng, c) => ng && c === input[0], true) ? "No" : "Yes");


import * as fs from "fs";

const split = (str: string): string[] =>
  str.split(" ").map((v: string) => v.trim());
const split_number = (str: string): number[] =>
  split(str).map((v: string) => +v);

export function main(input: string) {
  const lines = input.split("\n");
  const n = lines[0].split('');

  let check = "";
  for (let i = 0; i < n.length; i++) {
    if (i > 0 && n[i] !== check) {
      return "Yes";
    } else {
      check = n[i];
    }
  }

  return "No";
}

if (!process.env.LOCAL_DEBUG) {
  console.log(main(fs.readFileSync("/dev/stdin", "utf8")));
}


import * as fs from 'fs';
console.log(fs.readFileSync("/dev/stdin", "utf8").split("").reduce((ng, c) => ng && c === input[0], true) ? "No" : "Yes");


import fs from 'fs';
console.log(fs.readFileSync("/dev/stdin", "utf8").split("").reduce((ng, c) => ng && c === input[0], true) ? "No" : "Yes");


import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8")
console.log(input.trim().split(''));
console.log(input.split("").reduce((ng, c) => ng && c === input[0], true) ? "No" : "Yes");


s=input()
n=int(input())
l=len(s)
ct=0
for i in range(l-1):
 if s[i]==s[i+1]:
  ct=ct+0.5
 else:
  ct=int(ct+0.5)
ct=int(ct+0.5)
s1=s*3
l1=l*3
ct1=0
for i in range(l1-1):
 if s1[i]==s1[i+1]:
  ct1+=0.5
 else:
  ct1=int(ct1+0.5)
ct1=int(ct1+0.5)
ans=int((ct1-ct*3)/2*(n-1)+0.5)+ct*n
print(ans)


s = input()
k = int(input())
if len(set(list(s))) == 1:
  print(len(s)*k//2)
  exit()
l = list()
t = 0
c = s[0]
for x in s:
  if x == c:
    t += 1
  else:
    c = x
    l.append(t)
    t = 1
l.append(t)
ans = 0
if s[0]==s[-1]:
  ans += l[0]//2 + l[-1]//2 - (l[0]+l[-1])//2
  l[0] += l[-1]
  l.pop()
for x in l:
  ans += (x//2)*k
print(ans)


from itertools import groupby as gb
s=input()
k=int(input())
if len(set(s))==1:print((len(s)*k)//2);exit()
elif len(s)==2 and len(set(list(s)))==1:print(k);exit()
ji=[len(list(b))//2 for a,b in gb(s)]
l=k*sum(ji)
if s[0]==s[-1]:
  ji=[len(list(b)) for a,b in gb(s)]
  if ji[0]%2 and ji[-1]%2:l+=k-1
print(l)


s = input()
flag = [1 for _ in range(len(s))]
k = int(input())
counter = 0
for i in range(len(s)):
    if s[i-1] == s[i] and flag[i-1] and flag[i]:
        counter += 1
        flag[i] = 0
        flag[i-1] = 0
print(counter*k - (1 if k == 1 else 0))


s = input()
flag = [1 for _ in range(len(s))]
k = int(input())
counter = 0
for i in range(len(s)):
    if s[i-1] == s[i] and flag[i-1] and flag[i]:
        counter += 1
        flag[i] = 0
        flag[i-1] = 0
print(counter*k)


#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
S = input()
K = int(input())
ls = len(S)
t1 = []

t = 1
for i in range(1, ls):
    if S[i - 1] == S[i]:
        t += 1
    else:
        if t > 1:
            t1.append(t)
        t = 1

if t > 1:
    t1.append(t)

ans = 0
for t in t1:
    ans += t // 2

if len(t1) == 1:
    if t1[0] == ls:
        print(ls * K // 2)

else:
    if S[0] != S[-1]:
        print(ans * K)

    else:
        ta = t1[0]
        tb = t1[-1]
        print(ans * K - (ta // 2 + tb // 2 - (ta + tb) // 2) * (K - 1))


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		String s = br.readLine();
		long k = Integer.parseInt(br.readLine());
		int cnt = 1;
		long sum = 0;
		char c = s.charAt(0);
		boolean allSame = true;
		for (int i = 1; i < s.length(); i++) {
			if (c != s.charAt(i)) {
				sum += cnt/2;
				cnt = 1;
				c = s.charAt(i);
				allSame = false;
			}else
				cnt++;
		}
		if (allSame) {
			bw.write((k * s.length()) / 2 + "\n");
			bw.flush();
			return;
		}
		sum += cnt/2;
		if (s.charAt(0)!=s.charAt(s.length()-1)) {
			bw.write(sum*k + "\n");
			bw.flush();
			return;
		}
		s += s;
		cnt = 1;
		long sum2 = 0;
		c = s.charAt(0);
		for (int i = 1; i < s.length(); i++) {
			if (c != s.charAt(i)) {
				sum2 += cnt/2;
				cnt = 1;
				c = s.charAt(i);
			}else
				cnt++;
		}
		sum2 += cnt/2;
		bw.write(sum + (sum2-sum)*(k-1) + "\n");
		bw.flush();
		bw.close();
		br.close();
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String s = sc.next();
		long k = sc.nextLong();
		long ans = 0;
		int len = 1;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i + 1) == s.charAt(i)) {
				len++;
			} else {
				ans += len / 2;
				len = 1;
			}
		}
		ans += len / 2;
		ans *= k;
		if (s.charAt(0) == s.charAt(s.length() - 1)) {
			int maelen = 1;
			for (int i = 1; i < s.length(); i++) {
				if (s.charAt(i) == s.charAt(i - 1)) {
					maelen++;
				} else {
					break;
				}
			}
			int atolen = 1;
			for (int i = s.length() - 2; i >= 0; i--) {
				if (s.charAt(i) == s.charAt(i + 1)) {
					atolen++;
				} else {
					break;
				}
			}
			if (maelen == s.length()) {
				ans = s.length() * k / 2;
			} else {
				ans -= (maelen / 2 + atolen / 2 - (maelen + atolen) / 2) * (k - 1);
			}
		}
		System.out.println(ans);
	}
}

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 || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.StringJoiner;

class Main {

    static PrintWriter out;
    static InputReader sc;

    public static void main(String[] args) {
        sc = new InputReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    static void solve() {
        String s = sc.next();
        int K = sc.nextInt();
        long ans = 0;
        boolean f = true;
        for (int i = 0; i < s.length() - 1; i++) {
            if (s.charAt(i) != s.charAt(i + 1)) {
                f = false;
            }
        }
        if (!f) {
            if (K == 1) {
                ans = check(s);
            } else if (K == 2) {
                ans = check(s + s);
            } else {
                int res1 = check(s + s + s);
                long add = (res1 + 2) / 3;
                ans = res1 + add * (K - 3);
            }
        } else {
            ans = (long) K * s.length() / 2;
        }
        out.println(ans);
    }

    static int check(String s) {
        int N = s.length();
        int res = 0;
        for (int i = 0; i < N - 1; i++) {
            if (s.charAt(i) == s.charAt(i + 1)) {
                if (i + 2 < N && s.charAt(i) == s.charAt(i + 1)) {
                    res++;
                    i++;
                } else {
                    res++;
                }
            }
        }
        return res;
    }

    static void debug(Object... args) {
        StringJoiner j = new StringJoiner(" ");
        for (Object arg : args) {
            if (arg == null) {
                j.add("null");
            } else if (arg instanceof int[]) {
                j.add(Arrays.toString((int[]) arg));
            } else if (arg instanceof long[]) {
                j.add(Arrays.toString((long[]) arg));
            } else if (arg instanceof double[]) {
                j.add(Arrays.toString((double[]) arg));
            } else if (arg instanceof char[]) {
                j.add(Arrays.toString((char[]) arg));
            } else if (arg instanceof boolean[]) {
                j.add(Arrays.toString((boolean[]) arg));
            } else if (arg instanceof Object[]) {
                j.add(Arrays.toString((Object[]) arg));
            } else {
                j.add(arg.toString());
            }
        }
        System.err.println(j.toString());
    }

    static class InputReader {

        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int curbuf;
        private int lenbuf;

        public InputReader(InputStream in) {
            this.in = in;
            this.curbuf = this.lenbuf = 0;
        }

        public boolean hasNextByte() {
            if (this.curbuf >= this.lenbuf) {
                this.curbuf = 0;
                try {
                    this.lenbuf = this.in.read(this.buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (this.lenbuf <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (this.hasNextByte()) {
                return this.buffer[this.curbuf++];
            } else {
                return -1;
            }
        }

        private boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        private void skip() {
            while (this.hasNextByte() && this.isSpaceChar(this.buffer[this.curbuf])) {
                this.curbuf++;
            }
        }

        public boolean hasNext() {
            this.skip();
            return this.hasNextByte();
        }

        public String next() {
            if (!this.hasNext()) {
                throw new NoSuchElementException();
            }
            StringBuilder sb = new StringBuilder();
            int b = this.readByte();
            while (!this.isSpaceChar(b)) {
                sb.appendCodePoint(b);
                b = this.readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            if (!this.hasNext()) {
                throw new NoSuchElementException();
            }
            int c = this.readByte();
            while (this.isSpaceChar(c)) {
                c = this.readByte();
            }
            boolean minus = false;
            if (c == '-') {
                minus = true;
                c = this.readByte();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = res * 10 + c - '0';
                c = this.readByte();
            } while (!this.isSpaceChar(c));
            return minus ? -res : res;
        }

        public long nextLong() {
            if (!this.hasNext()) {
                throw new NoSuchElementException();
            }
            int c = this.readByte();
            while (this.isSpaceChar(c)) {
                c = this.readByte();
            }
            boolean minus = false;
            if (c == '-') {
                minus = true;
                c = this.readByte();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = res * 10 + c - '0';
                c = this.readByte();
            } while (!this.isSpaceChar(c));
            return minus ? -res : res;
        }

        public double nextDouble() {
            return Double.parseDouble(this.next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = this.nextInt();
            }
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = this.nextLong();
            }
            return a;
        }

        public char[][] nextCharMap(int n, int m) {
            char[][] map = new char[n][m];
            for (int i = 0; i < n; i++) {
                map[i] = this.next().toCharArray();
            }
            return map;
        }
    }
}


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

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        char[] S = new char[100];
        int N = in.read(S);

        long K = in.i();

        char c = ' ';
        long ans = 0;
        int i = 0;
        int j = 0;
        for ( ; i < N; i++) {
            if (S[i] != c) {
                ans += (i - j) / 2 * K;
                c = S[i];
                j = i;
            }
        }
        if (S[0] == c) {
            i = 1;
            for ( ; i < N && S[i] == c; i++);
            int k = N - j;
            ans += (K - 1) * ((i + k) / 2 - i / 2) + k / 2;
        } else {
            ans += (i - j) / 2 * K;
        }

        System.out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long K = sc.nextLong();
        char[] s = S.toCharArray();
        char tmp = 0;
        boolean key = false;
        long count = 0;
        char one = s[0];
        boolean ok = true;
        for (int i = 1; i < s.length; i++) {
            if (s[i] != one) {
                ok = false;
            }
        }
        if (ok) {
            System.out.println(K*s.length/2);
            return;
        }
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        long count2 = 0;
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count2++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count2++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        if (K == 1) {
            System.out.println(count);
        } else {
            System.out.println(count + (count2-count)*(K-1));
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int K = sc.nextInt();
        char[] s = S.toCharArray();
        char tmp = 0;
        boolean key = false;
        long count = 0;
        char one = s[0];
        boolean ok = true;
        for (int i = 1; i < s.length; i++) {
            if (s[i] != one) {
                ok = false;
            }
        }
        if (ok) {
            System.out.println(K*s.length/2);
            return;
        }
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        long count2 = 0;
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count2++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count2++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        if (K == 1) {
            System.out.println(count);
        } else {
            System.out.println(count + (count2-count)*(K-1));
        }
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char ss[110];
int main()
{
    //freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%s",ss+1);int len=strlen(ss+1);
	int m=read();
	int s1=1;
	for(int i=2;i<=len;i++)
	{
		if(ss[i]==ss[i-1])s1++;
		else break;
	}
	if(s1==len){printf("%lld\n",1LL*len*m/2);return 0;}
	int s2=1;
	for(int i=len-1;i>=1;i--)
	{
		if(ss[i]==ss[i+1])s2++;
		else break;
	}
	int tot=0,d=0;
	for(int i=s1+1;i<=len-s2+1;i++)
	{
		if(ss[i]!=ss[i-1])tot+=d/2,d=1;
		else d++;
	}
	int sum=s1/2+tot+s2/2;
	if(ss[1]==ss[len])printf("%lld\n",1LL*((s1+s2)/2+tot)*(m-1)+sum);
	else printf("%lld\n",1LL*sum*m);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main(){
    string S;
    ll K,len,x,y=1,z=0,j=0,jj=0,k=0,u=0;
    bool judge=true;
    cin >> S >> K;
    x=S.size();
    for(ll i=1;i<x;i++){
        if(S[i-1]!=S[i]) judge=false;
    }
    if(judge){
        len=x*K;
        cout << len/2 << endl;
    }else{
        while(S[j]==S[j+1]){
            ++j;
        }
        for(ll i=j+1;i<x;i++){
            if(S[i-1]==S[i]) y++;
            else{
                z+=y/2;
                y=1;
            }
        }
        if(S[0]==S[x-1]){
            jj=y;
            y++;
            while(S[k]==S[k+1]){
                ++k;
                ++y;
            }
            z+=y/2;
            if(jj%2==1 && y%2==0) u=1;
            ll total = z*K-u;
            cout << total << endl;
        }else{
            ll y=1,z=0;
            for(ll i=1;i<x;i++){
                if(S[i-1]==S[i]) y++;
                else{
                    z+=y/2;
                    y=1;
                }
            }
            z+=y/2;
            cout << z*K << endl;
        }
    }

    return 0;
}