jiahuimbzuai/CoQuIR huggingface dataset:
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>W(N);
  int min=10000;
  for(int i=0;i<N;i++){
cin>>W.at(i);
  }
  
  int sum=0;
  int sum1=0;
  
  for(int i=0;i<N-1;i++){
     int sum=0;
  int sum1=0;
  
    for(int j=0;j<i+1;j++){
      sum+=W.at(j);
    }
    for(int k=i+1;k<N;k++){
      sum1+=W.at(k);
    }
    
    if(abs(sum1-sum)<min){
min=abs(sum1-sum);
    }
  }
  cout<<min<<endl;
}
//  [cpp]
#include <bits/stdc++.h>

#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define itr vi:iterator
#define vpll vector < pair<long long,long long> >
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define pdd pair<double, double>

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)

using namespace std;

int main(){

    //ios::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    //#ifndef ONLINE_JUDGE
    //    freopen("input.txt", "r", stdin);
     //   freopen("output.txt", "w", stdout);
    //#endif

    int n;
    cin >> n;
    vi v(n);
    int sum1 = 0, sum2 = 0;
    rep(i, n){
        cin >> v[i];
        if(i<n/2) sum1 += v[i];
        else sum2 += v[i];
    }
    int x, y;
    x = sum1;
    y = sum2;
    int diff = abs(sum1-sum2);
    if(diff == 0){
        cout << 0;
        return 0;
    }
    int tmp = 0;
    int i = n/2;
    while(i < n){
        sum1 += v[i];
        sum2 -= v[i];
        tmp = abs(sum1-sum2);
        if(tmp < diff) diff = tmp;
        else break;
        i++;
    }
    sum1 = x;
    sum2 = y;
    i = n/2-1;
    while(i >= 0){
        sum1 -= v[i];
        sum2 += v[i];
        tmp = abs(sum1-sum2);
        if(tmp < diff) diff = tmp;
        else break;
        i--;
    }
    cout << diff;



    //cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}
//  [cpp]
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> w;

    for(int i = 0; i < n; i++){
        int a; cin >> a;
        w.push_back(a);
    }

    int min = 10001;
    for(int i = 1;i < n-1; i++){
        int s1 = 0;
        int s2 = 0;
        for(int j = i;j >= 0; j--){
            s1 += w[j];
        }
        for(int j = i+1;j < n; j++){
            s2 += w[j];
        }
        if(min > abs(s1-s2)) min = abs(s1-s2);
    }

    cout << min << endl;
    return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
const int MAX_N=1e6;
int seg_tree[2*MAX_N+5],n;
void build()
{
for(int i=n-1; i>0; --i)
seg_tree[i]=__gcd(seg_tree[i<<1],seg_tree[i<<1|1]);
}
void modify(int pos,int val)
{
for(seg_tree[pos+=n]=val; pos>1; pos>>=1)
seg_tree[pos>>1]=__gcd(seg_tree[pos],seg_tree[pos^1]);
}
int query(int l,int r)
{
int ans(1);
for(l+=n,r+=n; l<r; l>>=1,r>>=1)
{
if(l&1)
ans=__gcd(ans,seg_tree[l++]);
if(r&1)
ans=__gcd(ans,seg_tree[--r]);
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
int sum(0);
long long int arr[n];
for(int i=0; i<n; ++i)
{
cin>>arr[i];
sum+=arr[i];
}
int sum1(0),as(10000);
for(int i=0; i<n; ++i)
{
sum1+=arr[i];
as=min(as,abs(sum1-(sum-sum1));
}
cout<<as;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
const int MAX_N=1e6;
int seg_tree[2*MAX_N+5],n;
void build()
{
for(int i=n-1; i>0; --i)
seg_tree[i]=__gcd(seg_tree[i<<1],seg_tree[i<<1|1]);
}
void modify(int pos,int val)
{
for(seg_tree[pos+=n]=val; pos>1; pos>>=1)
seg_tree[pos>>1]=__gcd(seg_tree[pos],seg_tree[pos^1]);
}
int query(int l,int r)
{
int ans(1);
for(l+=n,r+=n; l<r; l>>=1,r>>=1)
{
if(l&1)
ans=__gcd(ans,seg_tree[l++]);
if(r&1)
ans=__gcd(ans,seg_tree[--r]);
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
long long int arr[n];
for(int i=0; i<n; ++i)
{
cin>>arr[i];
sum+=arr[i]; 
}
int sum1(0),as(10000);
for(int i=0; i<n; ++i)
{
sum1+=arr[i];
as=min(as,abs(sum1-(sum-sum1));
}
cout<<as;
}
//  [cpp]
#include <iostream>

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

	int *w = (int *)malloc(sizeof(int) * n);

	for (int i = 0; i < n; i++) {
		std::cin >> w[i];
	}

	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += w[i];
	}

	int sum_all = sum;
	int target = sum / 2;

	int index = 0;
	int def = sum;
	
	while (1) {
		sum -= w[index];
		if (sum < target) {
			if ((target - sum) > def) {
				sum += w[index];
			}
			break;
		}
		def = sum - target;
		index++;
	}

	std::cout << sum_all - 2 * sum << std::endl;
	free(w);
    return 0;
}
//  [c]
#include <stdio.h>
#include <math.h>
int main() {
	int n,w[100]={},s1=0,s2=0,sum=0,min=1000000000;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
		sum+=w[i];
	}
	for (int i = 0; i < n; i++) {
		s1+=w[i];
		s2=sum-s1;
		if(abs(s1-s2)<min){
			min=abs(s1-s2);
		}
	}
	printf("%d\n", min);
	return 0;
}
//  [c]
#include<stdio.h>

int sum(int s,int e,int dif,int *a){
  int s1=0,s2=0;
  for(int i=0;i<s;i++)
    s1+=a[i];
  
  for(int i=s;i<e;i++)
    s2+=a[i];
  if(s==0)
    dif=s1-s2;
  
  if(dif*dif>=(s1-s2)*(s1-s2))
    dif=s1-s2;
  
  if(s==(e-1))
    return dif;
  
  return sum(s+1,e,dif,a);
}
int main(){
  int N;
  
  scanf("%d",&N);
  
  int a[100];
  
  for(int i=0;i<N;i++)
    scanf("%d",&a[i]);
  
  int ans;
  ans=sum(0,N,0,a);
  if(ans<0)
    ans=ans*(-1);
  printf("%d\n",ans);
}
//  [c]
 #include <stdio.h>
int sum_a(int num[], int i);
int sum_b(int num[], int i, int n);

int main(void)
{
  int num[128],n,i,result = 1000,difference;
  char str[400],trush[4];
//数の個数を受け取る
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d",&n);
//n個の数を受ける
  for(i=0;i<n;++i)
  {
    scanf("%d",&num[i]);
  }

  scanf("%c", trush);
//分け方はn-1通り
//全ての分け方を試す
  for(i=0;i<n-1;++i)
  {
    difference = sum_a(num,i) - sum_b(num,i,n);
    if (difference < 0)
    {
      difference *= -1;
    }
//前より絶対値のさが小さければ更新
    if(result > difference)
    {
      result = difference;
    }
  }
//表示
  printf("%d", result);
  return 0;
}

int sum_a(int num[],int i)
{
  int j,sum=0;
  for (j=0;j<=i;++j)
  {
    sum += num[j];
  }
  return sum;
}

int sum_b(int num[],int i,int n)
{
  int j,sum = 0;
  for(j=i+1;j < n;j++)
  {
    sum += num[j];
  }
  return sum;
}
//  [c]
#include<stdio.h>
int absDiff(int a,int b){
    if((a-b)<0)
    return (b-a);
    else
    {
        return (a-b);
    }
    
}
int preSum(int t,int n,int a[]){
    int d=0;
    for(int i=0;i<=t;i++)
    d+=a[i];
    return d;
}
int main(){
    int n;
    scanf("%d",&n);
    int a[n+1];
    int sum=0;
    for(int i=1;i<=n;i++)
    sum+=a[i];
    for(int i=1;i<=n;i++)
    scanf("%d",a[i]);
    int min;
    for(int i=1;i<=n;i++){
        int b;
        int c;
        b=absDiff(preSum(i,n,a),sum-preSum(i,n,a));
        c=absDiff(preSum(i+1,n,a),sum-preSum(i+1,n,a));
        
        if(b>c)
        min=c;
        else
        {
            min=b;
        }
        
    }
    printf("%d",min);
}
//  [c]
#include<stdio.h>
int main()
{
int n,i,ans,sa1,sa2;
  sum=0;
scanf("%d",&n);  
int w[n],sum[n];
  
  scanf("%d",&w[i]);
  sum[0]=w[0];
  
  for(i=1;i<n;++i)
  {scanf("%d",&w[i]);
  sum[i]=sum[i-1]+w[i];
  }
  
  for(i=0;sum[i]<sum[n-1]/2;++i)
  {ans=i;}
  
  sa1=sum[n-1]-sum[ans]*2;
  sa2=2*sum[ans+1]-sum[n-1];
  
  if(sa1<sa2) printf("%d",sa1);
  else printf("%d",sa2);
  
return 0;
}
//  [c]
#include <stdio.h>
int main(void){
    int p, q, r, ans = 0;
    
    scanf("%d %d %d", &p, &q, &r);
    
    if(p+q <= (p+r) && (q+r)){
        ans = p + q;
    }else if(p + r <= (p+q) && (q+r)){
        ans = p + r;
    }else if(q + r <= (p+q) && (p+r)){
        ans = q + r;
    }
    
    printf("%d\n", ans);
}
//  [javascript]
function Main(input) {
    input = input.split("\n");
    var arr = input[1].split(" ").map(Number);
    var sum = 0;
    var min = Number.MAX_SAFE_INTEGER;
    for(var i=0;i<arr.length;i++){
        sum += arr[i];
    }
    var n = 0;
    var mp = 0
    for(i=0;i<arr.length;i++){
        n += arr[i];
        var m = sum-n;
        if(min>Math.abs(n-m)){
            min = Math.abs(n-m);
        }
    }
    console.log(min);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");

let Nums = input.split('\n');
let amount = Nums[0]*1;
let arr = Nums[1].split(" ").map(x => x*1);
let sum = arr.reduce((x,a)=> { return a+=x });
// 差についての十分に大きい暫定最小値
let min = 5050;
let tempSum = 0;
let restSum = 0;
for(let i =0; i < amount; i++){
  tempSum += arr[i];
  restSum = sum - tempSum;
  if(Math.abs(tempSum - restSum) < min){
      min = Math.abs(tempSum - restSum);
  }
}

console.log(min);
//  [javascript]

function Main(input) {
    var N = parseInt(input[0], 10);
    var W = input.slice(1).map(w => parseInt(w, 10));

    var result = 0;
    var smallSum = 0;
    var bigSum = 0;
    var diff = 0;

    for (var i = 0; i < W.length; i++) {
        smallSum = 0;
        bigSum = 0;
        for (var j = 0; j < W.length; j++) {
            if (i >= j) {
                smallSum += W[j];
            } else {
                bigSum += W[j];
            }
        }
        diff = Math.abs(smallSum - bigSum);
        if (i === 0) {
            result = diff;
        } else {
            result = result > diff ? diff : result;
        }
    }

    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[1].split(" ");
	let sum = 0;
  	for(let i = 0; i<tmp.length; i++){
      sum += parseInt(tmp[i]);
    }
  	//console.log(sum);
  	let left = 0;
  	let arr =[];
  	for(let i = 0; i<tmp.length; i++){
      left += parseInt(tmp[i]);
      let right = sum - left;
      let sa = Math.abs(left-right);
      arr.push(sa);
    }
  	console.log(arr);
  	console.log(Math.min.apply(null, arr));

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
var fs = require('fs');

var inputs = fs.readFileSync('/dev/stdin', 'utf8').split('\n');
var num = Number(inputs[0]);
var wnums = inputs[1].split(' ').map(function (i) {Number(i)});
var minimum = null;
for (var t = 1; t < num; t++) {
  var sub = wnums.slice(0, t).reduce(function(c,i) {return c+i}) - wnums.slice(t).reduce(function(c,i) {return c+i});
  if (sub < 0) {
    sub = -sub;
  }
  if (minimum === null || minimum > sub) {
    minimum = sub;
  }
}
console.log(minimum);
//  [go]
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	W := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &W[i])
	}
	min := 1000000000
	for t := 0; t < N; t++ {
		s1 := 0
		s2 := 0
		for i := 0; i < N; i++ {
			if i <= t {
				s1 += W[i]
			} else {
				s2 += W[i]
			}
		}
		diff := s1 - s2
		if diff < 0 {
			diff = -diff
		}
		if diff < min {
			min = diff
		}
	}
	fmt.Println(min)
}
//  [go]
package main

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

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

func main() {
	N := getStdinInt()
	W := getStdinIntArr()

	min := math.MaxInt32
	for T := 0; T < N; T++ {
		S1 := 0
		S2 := 0
		for w := 0; w <= T; w++ {
			S1 += W[w]
		}
		for w := T + 1; w < N; w++ {
			S2 += W[w]
		}
		S := 0
		if S1 < S2 {
			S = S2 - S1
		} else {
			S = S1 - S2
		}
		if S < min {
			min = S
		}
	}

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

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)
}
//  [go]
package main

import (
	"fmt"
	"math"
)

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

	W := make([]int, N)
	sum := 0
	for i := 0; i < N; i++ {
		fmt.Scan(&W[i])
		sum += W[i]
	}
	ans := sum
	pre_sum := 0
	for i := 0; i < N; i++ {
		pre_sum += W[i]
		ans = int(math.Min(float64(ans), math.Abs(float64(pre_sum-(sum-pre_sum)))))
	}
	fmt.Println(ans)
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	var sum int = 0
	W := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &W[i])
		sum += W[i]
	}

	var S1, S2 int
	var min int = 10000
	for T := 1; T < N; T++ {

		S1 += W[i]
		S2 = sum - S1

		if min >= int(math.Abs(float64(S1)-float64(S2))) {
			min = int(math.Abs(float64(S1) - float64(S2)))
		}
	}

	fmt.Println(min)
}
//  [go]
package main

import (
	"fmt"
)

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

	ws := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&ws[i])
		sum += ws[i]
	}

	cal := sum / 2
	cnt1 := 0
	cnt2 := 0
	for _, w := range ws {
		if cnt1 < cal {
			cnt1 += w
		} else {
			cnt2 += w
		}
	}

	fmt.Print(cnt1 - cnt2)
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	w := make([]int, n)
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&w[i])
	}
	var sum1 int
	var sum2 int
	a := make([]int, n)
	var r int
	for t := 1; t < n-1; t++ {
		for i := 0; i < t; i++ {
			sum1 += w[i]
		}
		for i := t; i < n; i++ {
			sum2 += w[i]
		}
		a[t-1] = abs(sum1 - sum2)
	}
	for i := 0; i < n-1; i++ {
		if a[i] < a[i+1] {
			r = a[i+1]
		}
	}
	fmt.Println(r)
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}
//  [ruby]
n = gets.to_i
w = gets.split.map(&:to_i)
wr = w.reverse

lth = 0
rth = 0
a = 0
b = 0
for num in 0..n-1 do
  if a <= b 
    a += w[lth]
    lth += 1
  else
    b += wr[rth]
    rth += 1
  end    
end
p (a-b).abs
//  [ruby]
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
s = [a[0]]
(n-1).times do |i|
  s.push(s[i] + a[i+1])
end

min = 100000000
(n-1).times do |i|
  tmp = (2 * s[i] - s[-1]).abs
  if tmp < min then
    min = tmp
  end
end
  
puts min
//  [ruby]
n = gets.chomp.to_i
w = gets.chomp.split(' ').map(&:to_i)

s1 = 0
s2 = 0

n.times do
  if s1 <= s2
    s1 += w.shift
  else
    s2 += w.pop
  end
end

print((s1 - s2).abs)
//  [ruby]
input = readlines()
n = input.shift.chomp.to_i
list = input.shift.chomp.split("\s").map{|x| x.to_i}

sum = list.sum()

min = nil
(1..100).each do |t|
  g1 = list.select{|x| x <= t}
  g1_sum = g1.sum()
  diff = (g1_sum - (sum - g1_sum)).abs
  min = diff if min.nil? || min > diff
end

puts min
//  [ruby]
_,*w=`dd`.split.map(&:to_i)
min=100
sum=0
all=w.sum
w.each do |wi|
  sum+=wi
  min=[min,all-sum].min
end
p min
//  [ruby]
_,*w=`dd`.split.map(&:to_i)
min=100
sum=0
all=w.sum
w.each do |wi|
  sum+=wi
  min>sum ? min=min-sum : break
end
p min
//  [rust]
fn main() {
    let n = read::<usize>();
    let w = read_vec::<i32>();

    let mut mi = i32::max_value();
    for i in 0..n-1 {
        let mut s1 = 0;
        for j in 0..i+1 {
            s1 += w[j];
        }
        let mut s2 = 0;
        for j in i+1..n {
            s2 += w[j];
        }

        if mi > (s1 - s2).abs() {
            mi = (s1 - s2).abs();
        }
    }
    println!("{}", mi);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

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()
}
//  [rust]
#[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),*);
    }
}



use std::cmp;
use std::iter::Iterator;

fn main() {
    input! {
        n:usize,
        w:[i64;n],
    }

    let mut minsum = 0;

    for i in 0..n-1{
       let left :i64 = w[0..i+1].iter().sum();
       let right :i64 = w[i+1..n].iter().sum();

       let s_abs = ((left - right) as i64).abs();
       if minsum == 0 {
            minsum = s_abs;
       }
        minsum = cmp::min(minsum, s_abs);
    }

    println!("{}", minsum);

}
//  [rust]
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
    let n: usize = read();
    let w:Vec<i64> = (0..n).map(|_| read()).collect();
    let mut ans:i64 = std::i64::MAX;
    let sum:i64 = w.iter().sum();
    let mut s1 = 0;
    for i in w.into_iter(){
        s1 += i;
        ans = std::cmp::min(ans,(sum-2*s1).abs());
    }
    println!("{}",ans);
}
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        w: [i32; n]
    };

    let sum = w.iter().sum::<i32>();

    let mut curSum = w.iter().sum::<i32>();

    let mut result = std::i32::MAX;

    for i in 0..n {
        curSum -= w[i];

        if result > ((sum / 2) - curSum).abs() {
            result = ((sum / 2) - curSum).abs();
            // println!("{}", curSum);
            // println!("{}", result);
        }
    }

    println!("{}", result * 2)
}
//  [rust]
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n: usize = read();
    let arr: Vec<i64> = (0..n).map(|_| read()).collect();
    let sm: i64 = arr.iter().sum();
    let mut first = 0;
    let mut second = 0;
    for i in arr {
        if first < sm / 2 {
            first += i;
        } else {
            second += i;
        }
    }
    println!("{}", (first - second).abs());
}
//  [rust]
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n: usize = read();
    let arr: Vec<i64> = (0..n).map(|_| read()).collect();
    let sm: i64 = arr.iter().sum();
    let mut tmp = 0;
    for i in arr {
        tmp += i;
        if tmp >= sm / 2 {
            break;
        }
    }
    println!("{}", (sm - 2 * tmp).abs());
}
//  [swift]
let n = Int(readLine()!)!

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

var sum = w.reduce(0, +)

var ans = Int.max

var curSum = 0
for i in 0..<w.count {
  ans = min(ans, abs(2 * curSum - sum))
  curSum += w[i]
}
print(ans)
//  [swift]
var n=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
var arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var di : [Int] = []
var sum = 0;

 var i = 0; 

for i in 0..<n[0]  {
    sum += arr[i]
}

var diff = 0;
var total = 0
var min = sum
var min_i = 0

i = 0
for i in 0..<n[0] {
  total += arr[i]
  sum -= arr[i]
  
  diff = sum - total 
  
  diff = diff < 0 ? -diff: diff 
  di.append( diff  )
  
  if( min > diff ) {
    min = diff
    min_i = i
  }

}

print( di[min_i] )
//  [swift]
/// Swift5 -> Swift2.2

extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
    // lastIndex(where:)
    func lastIndex(where predicate: (Element) -> Bool) -> Int? {
      	for i in stride(from: count - 1, through: 0, by: -1) {
          	if predicate(self[i]) {
              	return i
            }
        }
      	return nil
    }
}
extension Array where Element: Comparable {
    // sorted()
    func sorted() -> [Element] {
        return self.sort( { $0 < $1 } )
    }
    // max()
    func max() -> Element? {
        guard self.count > 0 else { return nil }
        return self.reduce(self.first!) { return Swift.max($0, $1) }
    }
}
extension String {
    // Sequence#enumerated()
  	// public func enumerate<Seq : SequenceType>(base: Seq) -> EnumerateSequence<Seq>
    func enumerated() -> EnumerateSequence<[Character]> {
        return Array(self.characters).enumerate()
    }
}
// stride(from:through:by:)
func stride(from start: Int, through end: Int, by stride: Int) -> StrideThrough<Int> {
    return start.stride(through: end, by: stride)
}
// stride(from:to:by)
func stride(from start: Int, to end: Int, by stride: Int) -> StrideTo<Int> {
    return start.stride(to: end, by: stride)
}

/// end


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

var s1 = 0
var s2 = W.reduce(0, combine: +)
var result = Int.max
for i in stride(from: 0, to: N, by: 1) {
    s1 += W[i]
    s2 -= W[i]
    result = min(result, abs(s1 - s2))
}

print(result)
//  [swift]
import Foundation
 
let number = Int(readLine()!)!

//標準入力二行目以降
var weights = [Int]()
let input_line = readLine()! 

for i in 0..<number {
    let splits = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
	weights.append(Int(splits[i])!)
}

let sumOfWeights = weights.reduce(0, combine: { $0 + $1 }) //重しの総和
var position = 1
var lhsWeight = weights[position - 1]

while sumOfWeights / 2 > lhsWeight {
    position += 1
    lhsWeight += weights[position - 1]
}

if abs(sumOfWeights - (lhsWeight * 2)) <= abs(sumOfWeights - (lhsWeight * 2 - weights[position - 1])) {
  print(abs(sumOfWeights - (lhsWeight * 2)))
} else {
  print(abs(sumOfWeights - (lhsWeight * 2 - weights[position - 1])))
}
//  [swift]
import Foundation
 
let number = Int(readLine()!)!

//標準入力二行目以降
var weights = [Int]()
let input_line = readLine()! 

for i in 0..<number {
    let splits = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
	weights.append(Int(splits[i])!)
}

let sumOfWeights = weights.reduce(0, combine: { $0 + $1 }) //重しの総和
var position = 1
var lhsWeight = weights[position - 1]

while sumOfWeights / 2 > lhsWeight {
    position += 1
    lhsWeight += weights[position - 1]
}

print(abs(sumOfWeights - (lhsWeight * 2)))

/*
if value1 <= value2 && value1 <= value3 {
    print(value1)
} else if value2 <= value3 {
    print(value2)
} else {
    print(value3)
}
*/
//  [typescript]
import { readFileSync } from 'fs'

const mapWithPrev = <T, U>(list: T[], fn: (prev: U, value: T) => U, init: U) => {
  const result = [] as U[]
  let prev = init
  for (const value of list) {
    result.push(prev = fn(prev, value))
  }
  return result
}

const zip = <T>(a: T[], b: T[]) =>
  a.map((v, i) => [v, b[i]] as [T, T])

function main(input: string) {
  const [[N], list] = input.split('\n').map(v => v.split(' ').map(Number))

  const left = mapWithPrev(list, (prev, value) => prev + value, 0)
  const sum = left[N - 1]
  const right = mapWithPrev(list, (prev, value) => prev - value, sum)

  const diffList = zip(left, right).map(([a, b]) => Math.abs(a - b))
  const result = Math.min(...diffList)

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())
//  [typescript]
{
  const main = (input: string) => {
    const r = reader(input)
    const N = r.n()
    const W = r.ns()

    const sum = W.reduce((a, b) => a + b, 0)
    let p = 0
    let min = sum

    W.forEach(v => {
      p += v
      min = Math.min(min, Math.abs(p - (sum - p)))
    })

    console.log(min)
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

  main(getInput())
}
//  [typescript]
import fs = require('fs')
const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n')

const N = +input[0]
const W = input[1].split(' ').map(Number)

let diffMin = Number.MAX_SAFE_INTEGER

for (let T = 1; T < N; T++) {
    // const t = T - 1
    let S1 = 0
    let S2 = 0

    for (let w = 0; w < T; w++) {
        S1 += W[w]
    }
    for (let w = T; w < N; w++) {
        S2 += W[w]
    }
    const diffAbs = Math.abs(S1 - S2)
    if (diffMin > diffAbs) {
        diffMin = diffAbs
    }
}

console.log(diffMin)
//  [typescript]
const main = (lines: string) => {
  const data = lines.split("\n");
  const N = parseInt(data[0]);
  const weights = data[1].split(" ").map(str => parseInt(str));
  let minSum, maxSum;
  let absArr: number[] = [];
  let answer;


  for (let i = 0; i < N - 2; i++) {
    for (let j = i + 1; j < N; j++) {
      minSum = weights.slice(i, j).reduce((a, x) => a+=x, 0)
      maxSum = weights.slice(j, N).reduce((a, x) => a+=x, 0)

      absArr.push(Math.abs(minSum - maxSum))
    }
  }

  absArr.reduce((a, x) => a+=x, 0)

  console.log(Math.min.apply(null, absArr))
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [python]
s = input()
t = input()
for i in range(1,len(s)+1):
  s = s[-1]+s[:-1]
  if s == t:
    print("Yes")
    exit()
print("No")
//  [python]
s = input()
t = input()
#print(s, t)
s += s
#print(s, t)

if t in s:
    print("Yes")
else:
    print("No")
//  [python]
s = list(input())
t = list(input())
res = False
for i in range(len(s)):
    if t == s[i:] + s[:i]:
        res = True

if res:
    print("Yes")
else:
    print("No")
//  [python]
s = input()
t = input()

for i in range(len(s)):
    if s[i:] + s[:i] == t:
        print("Yes")
    break
else:
    print("No")
//  [python]
s = input()
t = input()

for i in range(len(s)):
    if s[i:] + s[:i] == t:
        print("Yes")
else:
    print("No")
//  [python]
S = input()
T = input()
flag = False
for i in range(len(S)):
    if flag:
        break
    if S[i] == T[0]:
        tem = i+1
        f = 1
        for t in range(1,len(T)):
            if T[t] == S[tem]:
                tem += 1
                if tem == len(S):
                    tem = 0
            else:
                break
            if t == len(T)-1:
                flag = True
if flag:
    print('Yes')
else:
    print('No')
//  [java]
import java.io.*;
import java.util.*;
import java.math.*;
class Main
{ 
	public static int M = 1000000007;
    public static void main(String[] args)throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String s1 = br.readLine();	
        String s2 = br.readLine();
        int f=0, len = s1.length();
        for(int i=0;i<len;i++)
        {
            if(checker(s1,s2,i,0))
            {
                f=1;
                break;
            }
        }
        if(f==1)
            out.println("Yes");
        else
            out.println("No");
        out.flush();
    }
    public static boolean checker(String s1, String s2, int pos1, int pos2)
    {
        int count=0,len = s1.length();

        while(count<len)
        {
            if(s1.charAt(pos1)==s2.charAt(pos2))
            {
                pos1=(pos1+1)%len;
                pos2=(pos2+1)%len;
                count++;
            }
            else
                return false;
        }
        return true;
    }
    /** Loops
    *	i: for(int i=0;i<n;i++)
    *	j: for(int j=0;j<n;j++)
    *	k: for(int k=0;k<n;k++)

    *	ArrayList<Integer> arr1 = new ArrayList<>();
    
    * 	HashMap
    *	HashMap<Integer, Integer> hm = new HashMap<>();
    * 	for (Map.Entry<String,String> entry : hm.entrySet()) 
    		out.println(entry.getValue());
    
    *	Count frequencies
    	for(int i=0;i<n;i++)
        {
            Integer c = hm.get(Integer.parseInt(s[i]));
            if(c==null)
                hm.put(Integer.parseInt(s[i]),1);
            else
                hm.put(Integer.parseInt(s[i]),++c);
        }
	**/		
    public static long modularExpo(long x,long n,int M)
	{
		long result=1;
		while(n>0)
		{
		    if(n%2==1)
		        result=(result*x)%M;
		    x=(x*x)%M;
		    n=n/2;
		}	
		return result;												
	}
	//FLT, only when a and M are co-prime
	public static long modInverse(int a,int M)
	{
		long g = gcd(a,M);
		if(g!=1)
			return -1;
	    return modularExpo(a,M-2,M);
	}
	public static long gcd(int a, int b) 
	{
	    if(b==0)
	        return a;
	    else
	        return gcd(b, a % b);
	}
}
//  [java]
import java.io.IOException;

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

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            StringBuilder S = new StringBuilder(reader.readLine());
            final String T = reader.readLine();

            boolean flg = false;
            for (int i = 0; i < S.length(); i++) {
                if (T.contentEquals(S)) {
                    flg = true;
                    break;
                }
                S = S.insert(0, S.charAt(S.length() - 1));
                S.setLength(S.length() - 1);
            }

            System.out.println(flg ? "Yes" : "No");
        }
    }
}
//  [java]

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

class Main{

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String s=sc.nextLine();
		String t=sc.nextLine();
		System.out.println(areRotations(s, t)|| areRotations(t, s)==true?"Yes":"No");
	}
	
	static boolean areRotations(String str1, String str2)
    {
        // There lengths must be same and str2 must be 
        // a substring of str1 concatenated with str1.  
        return (str1.length() == str2.length()) &&
               ((str1 + str1).indexOf(str2) != -1);
    }

}
//  [java]
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		sc.close();
		Arrays.sort(a);
		Arrays.sort(b);
		boolean yono = true;
		int yo = 0;
		for(char i : a){
			if(b[yo] != i) yono = false;
			yo++;
		}
		if(yono) ou.println("Yes");
		else ou.println("No");
		ou.flush();
	}
}
//  [java]
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		String t = scn.next();
      	String ans = "No";
		for(int i=0; i<s.length(); i++){
		    if(s.equals(t)){
		        ans = "Yes";
		        return;
		    }else{
		        s = s.charAt(s.length()-1) + s.substring(0, s.length()-1);
		    }
		}
      	System.out.println(ans);
	}
}
//  [java]
import java.io.BufferedReader; 
import java.io.*;
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
import java.math.*;
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader()
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next()
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine();
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
   public static void main(String args[])
    {
        FastReader sc=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
        int t=1;//sc.nextInt();
        while(t-->0)
        {
           String s=sc.next(),st=sc.nextInt();int f=0;
           for(int i=s.length();i>=0;i--)
           {
             String str=s.substring(i,s.length())+s.substring(0,i);
             if(str.equals(st)){pw.println("Yes");f=1;break;}
           }
           if(f==0) pw.println("No");
        }
           pw.close();
    }
}
//  [cpp]
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>

using std::list;
using std::max;
using std::min;
using std::vector;

int main()
{
  char buf1[0x100];
  char buf2[0x200];
  fgets(buf1, sizeof(buf1), stdin);
  fgets(buf2, sizeof(buf2), stdin);
  char* p1 = strchr(buf1, '\n');
  *p1 = '\0';
  char* p2 = strchr(buf2, '\n');
  *p2 = '\0';
  if(strlen(buf1) != strlen(buf2)) {
    puts("No");
    return 0;
  }
  size_t len = strlen(buf2);
  memcpy(p2, buf2, len);
  p2[len] = '\0';
  if(strstr(buf2, buf1)) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}
//  [cpp]
#include <stdio.h>
#include<string.h>
int main(int argc, char *argv[])
{
	char s[100],t[100];
	 while(scanf("%s",s)!=EOF){
 		scanf("%s",t);
 		int n=strlen(s),flag=0;
 		for(int i=0;i<n;i++)
 		{
		 	if(strcmp(s,t)==0){
	 		flag=1;break;	
	 		}
	 		char ch=s[0];
	 		for(int j=0;j<n-1;j++)
	 		 s[j]=s[j+1];
	 		 s[n-1]=ch;
		 }
		if(flag==1)printf("Yes\n");
		else printf("No\n"); 
 	}
	return 0;
}
//  [cpp]
#include<cstdio>
#include<algorithm>
char s[101],t[101];
int main(){
    scanf("%s%s",s,t);
    int len=0;
    while(s[len]!='\0')len++;
    for(int i=0;i<len;i++){
        bool flag=true;
        for(int j=0;j<len;j++){
            if(s[j]!=t[(i+j)%len]){
                flag=false;
                break;
            }
        }
        if(flag){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  string a;
  cin>>a;
  string d=a+a;
  string b;
  cin>>b;
  ll c=a.size();
  for(ll i=0;i<c;i++){
    for(ll j=0;j<c;j++){
      if(d.at(i+j)!=b.at(i)){
        break;
      }
      if(j==c-1){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
        
    
  
  return 0;
}
//  [cpp]
#include <math.h>
#include <stdio.h>

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//マクロ
// forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
// FORAは範囲for文(使いにくかったら消す)
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000  // 10^12:∞
#define MOD 1000000007     // 10^9+7:合同式の法
#define MAXR 100000        // 10^5:配列の最大のrange
//略記
#define PB push_back  //挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素

typedef long long ll;

using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  REP(i, SIZE(S)) {
    if (S == T) {
      cout << "Yes";
      return 0;

    } else {
      string tmp = T;
      tmp.erase(SIZE(T) - 1);
      T = T[SIZE(T) - 1] + tmp;
    }
  }
  cout << "Yes";
  return 0;
}
//  [cpp]
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s , t;
    cin >> s >> t;
    sort( s.begin() , s.end() );
    sort( t.begin() , t.end() );
    if( s == t ) cout << "Yes";
    else cout << "No";
}
//  [c]
#include<stdio.h>
#include<string.h>
 
int main(void)
{
	char s[101];
	char t[202];
	int len,c=0,i,j;
	
    scanf("%s%s",s,t);
	len=strlen(s);
	for(i=0;i<len;i++)
		t[len+i]=t[i];
	
	for(i=0;i<len;i++){
		for(j=0;j<len;j++){
			if(s[j]!=t[j+i])
				break;
		}
		if(j==len)
			c=1;
	}
	if(c==1)
		printf("Yes");
	else
		printf("No");
	return 0;
}
//  [c]
#include <stdio.h>
#include <math.h>


 
 int main()
{
    char T[100],S[100];
    int n = 0,count = 0;
    
    scanf("%s",T);
    scanf("%s",S);
    for(int i = 0;T[i] != '\0';i++)
    {
        n++;
    }
    
    /*
    
    for(int i = n;T[i] > 1;i--)
    {
        if(i == n)
        {
            T[1] = T[0];
            T[0] = T[n];
            continue;
        }
        T[i] = T[i-1];
    }
    */


    for(int i = 0;i<n;i++)
    {
        if(T[i] == S[i])
        {
            continue;
        }
        
        else
        
        {   int d = T[n-1];
         
            for(int i = n-1;i > 0;i--)
            {
                
                T[i] = T[i-1];
            }
            
            T[0] = d;
        
         
            i = 0;
            count++;}
        
        
        if(count == n){
            printf("No\n");
            return 0;
        }
    }
    
    printf("Yes\n");
    
    return 0;
    
}
//  [c]
#include <stdio.h>
#include <string.h>


int main(){
	char a[101],b[101],c[201];
	int i,j=0,count=0;
	scanf("%s\n%s",&a,&b);
	for(i=0;i<strlen(a);i++){
		c[i]=a[i];
	}
	for(i=0;i<strlen(a);i++){
		c[i+strlen(a)]=a[i];
	}
	
	if(strstr(c,b)!=NULL)printf("Yes\n");
	else printf("No\n");
	return 0;
}
//  [c]
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
   string s, str;
   cin>>str;
   cin>>s;
   for(int i=1;i<=s.size();i++)
   {
       str=str[str.size()-1] + str;

       str.erase(str.begin()+str.size()-1);
        int j;
       for(j=0;j<s.size();j++)
       {
        if(str[j]!=s[j])
            break;
       }
       if(j==s.size())
       {
        cout<<"Yes";
        return 0;
       }
   }
   cout<<"No";




 return 0;
}
//  [c]
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,j,c,d;
	char s[1000],t[1000],a[1];
	scanf("%s %s",s,t);
	  c=0;
  	  d=0;
  		 for(j=0;j<strlen(s);j++){
				if(s[j] == t[j]) c++;
		 }
  		 if(c == strlen(s)) printf("Yes\n");
  	  c=0;  
  		for(i=0;i<strlen(s);i++)			{
         if(strlen(s)<6)				{		
			for(j=0;j<strlen(s+1);j++){
				a[1]=s[j];
				s[j]=s[j+1];
          		s[j+1]=a[1];
			}
           
         }
         if(strlen(s)>5)				{		
		    for(j=0;j<strlen(s+1);j++){
				a[1]=s[j];
				s[j]=s[j+1];
          		s[j+1]=a[1];
			}
          
         }
      	  	for(j=0;j<strlen(s);j++){
			if(s[j] == t[j]) c++;
			}
          	if(c==strlen(s)) d++;
          	c=0;
           	if(i==strlen(s+1) && d==0) printf("No\n");
       	 }
  		if(0<d) printf("Yes\n");
	return 0;
}
//  [c]
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,j,c,d;
	char s[1000],t[1000],a[1];
	scanf("%s %s",s,t);
	  c=0;
  	  d=0;
  		 for(j=0;j<strlen(s);j++){
				if(s[j] == t[j]) c++;
		 }
  		 if(c == strlen(s)) printf("Yes\n");
  	  c=0;  
  		for(i=0;i<strlen(s);i++)			{
         if(strlen(s)<6)				{		
			for(j=0;j<strlen(s+1);j++){
				a[1]=s[j];
				s[j]=s[j+1];
          		s[j+1]=a[1];
			}
            printf("%s\n",s);
         }
         if(strlen(s)>5)				{		
		    for(j=0;j<strlen(s+1);j++){
				a[1]=s[j];
				s[j]=s[j+1];
          		s[j+1]=a[1];
			}
            printf("%s\n",s);
         }
      	  	for(j=0;j<strlen(s);j++){
			if(s[j] == t[j]) c++;
			}
          	if(c==strlen(s)) d++;
          	c=0;
           	if(i==strlen(s+1) && d==0) printf("No\n");
       	 }
  		if(0<d) printf("Yes\n");
	return 0;
}
//  [javascript]
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
S = inp.shift()
T = inp.shift()
b = 0
for (i=0; i<S.length; i++) {
    l = S.slice(0, i)
    r = S.slice(i)
    if (r+l == T) {
        b = true
        break;
    }
}
console.log(b ? 'Yes' : 'No')
//  [javascript]
function main(input) {
  input=input.trim();
  var s = input.split("\n")[0]
  var t = input.split("\n")[1]
  const nagasa=s.length
  var ans=0;
  for(var i=0; i<nagasa; i++){
    s=s.charAt(nagasa-1)+s.slice(0,nagasa-1);
    //console.log(s);
      if(s==t){
        ans++
      }
    }
    
  if(ans>0||input.split("\n")[0]==t){
    console.log("Yes");
  }else{
    console.log("No");
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function Main (input) {
  var inputs = input.split(/\s/g);
  var strLength = inputs[0].length;
  var baseStr = inputs[0];
  var isSuccess = false;
  for (var index = 0; index < strLength; index += 1) {
    var newStr = baseStr.charAt(strLength - 1) + baseStr.slice(0, strLength - 1);
    if (newStr === inputs[1]) {
      isSuccess = true;
    } else {
      baseStr = newStr;
    }
  }
  console.log('%s',isSuccess ? 'Yes' : 'No');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let X = xs[0].split('');
   let Y = xs[1].split('');
   X.sort();
   Y.sort();
   let len = X.length;
   let num = 0;
   for(let i=0; i<len; i++){
     if(X[i]==Y[i]){
     num +=1;
     }else{
     num +=0;
     }
   }
   //console.log(num)
  
   if(num == len && num!=0){
     console.log('Yes');
     }else{    
     console.log('No');
     }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));
//  [go]
package main

import "fmt"

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

	for i := 0; i < len(s); i++ {
		if s == t {
			fmt.Println("Yes")
			return
		}
		s = s[len(s)-1:] + s[0:len(s)-1]
	}
	fmt.Println("No")
}
//  [go]
package main

import "fmt"

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

	for i := 0; i < len(s); i++ {
		first := s[0 : len(s)-1-i]
		second := s[len(s)-1-i:]
		tmp := second + first
		if tmp == t {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}
//  [go]
package main
import(
  "fmt"
)
func main(){
   var s, t, temp string
   var i int
   fmt.Scan(&s, &t)
   for i=0;i<len(s);i++{
     temp=string(s[0])
     s=s[1:]
     s+=temp
     if s==t{
       fmt.Println("Yes")
       return
     }
   }
   fmt.Println("No")
}
//  [go]
package main

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

func main() {
	sc = initScanner(os.Stdin)
	s, t := scanString(sc), scanString(sc)
	fmt.Println(solve(s, t))
}

func solve(s, t string) string {
	for i:=0;i< len(s)-1;i++ {
		if s == t {
			return "Yes"
		}
		s = s[len(s)-1:] + s[0:len(s)-1]
	}
	return "No"
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanFloat64(sc *bufio.Scanner) float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

func scanFloat64Slice(sc *bufio.Scanner, n int) []float64 {
	fs := make([]float64, n)
	for i := 0; i < n; i++ {
		fs[i] = scanFloat64(sc)
	}

	return fs
}

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

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
//  [go]
package main

import "fmt"

func main() {
	var S, T string
	fmt.Scan(&S, &T)
	ans := "No"
	for i := 0; i < len(S); i++ {
		if S == T {
			ans = "Yes"
			break
		}
		S = S[len(S)-1:] + S[0:len(S)]
	}
	fmt.Println(ans)
}