"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  let  n:number = next();
  let  morty:number[] = nexts(n);
  let rick:number[] = [];
  let tmp:nember = morty[0];
  let i ;
  for(i = 1;i<morty.length;i++){

  	tmp^=morty[i];
  }
  for( i  = 0;i<morty.length;i++){

    let x = morty[i]^tmp;
    rick = [...rick,x]
  }
  return rick.join(" ");
}


import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const n = parseInt(input[0][0]);
  const morty:number[] = input[1].map(x=>parseInt(x));
  let tmp:nember = morty[0];
  let i ;
  for(i = 1;i<morty.length;i++){

  	tmp^=morty[i];
  }
 let rick:number[] = [];
  for( i  = 0;i<morty.length;i++){

    let x = morty[i]^tmp;
    rick = [...rick,x]
  }

  return rick.join(' ')
};

console.log(main(read()));


N = int(input())

result = 0
for i in range(1,N+1):
  result += i

print(result)


num = int(input())

ans = 0
for i in range(num+1):
  ans += i
print(ans)


N = int(input())

ans = 0

for i in range(N):
    ans += i
print(ans)


N = int(input())

candy=(1+N)*N/2
print(candy)


N = int(input())

candy=N*(1+N)/2
print(candy)


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))) {
            final String s = reader.readLine();

            int N = Integer.parseInt(s);

            System.out.println((1 + N) * N /2);
        }
    }
}


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

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int s = 0;
		for (int i = 1; i <= N; i++)
			s += i;
		System.out.println(s);

	}

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

	//階乗
	public static int fact(int n) {
		if (n == 1 || n == 0)
			return 1;
		else
			return n * fact(n - 1);
	}

	//指定した値以上の要素が最初に現れる位置
	//要素の数は+1（配列のズレ)
	public static long lowerBound(int n, long[] x, long y) {
		int left = 0;
		int right = n;
		while (left < right) {
			int mid = (left + right) / 2;
			if (x[mid] < y) {
				left = mid + 1;
			} else {
				right = mid;
			}
		}
		return left;
	}

	//指定した値より大きい要素が最初に現れる位置
	//要素の数は+1（配列のズレ)
	public static long upperBound(int n, long[] x, long y) {
		int left = 0;
		int right = n;
		while (left < right) {
			int mid = (left + right) / 2;
			if (x[mid] <= y) {
				left = mid + 1;
			} else {
				right = mid;
			}
		}
		return left;
	}

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

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

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

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

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

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

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

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

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
    static InputStream is;
    static PrintWriter out;
    static String INPUT = "";

    static void solve()
    {
        int N = ni();
        int sum = 0;
        for (int i = 1; i <= N; i++) {
            sum += i;
        }
        System.out.println(sum);

    }

    public static void main(String[] args) throws Exception
    {
        long S = System.currentTimeMillis();
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        solve();
        out.flush();
        long G = System.currentTimeMillis();
        tr(G-S+"ms");
    }

    private static boolean eof()
    {
        if(lenbuf == -1)return true;
        int lptr = ptrbuf;
        while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false;

        try {
            is.mark(1000);
            while(true){
                int b = is.read();
                if(b == -1){
                    is.reset();
                    return true;
                }else if(!isSpaceChar(b)){
                    is.reset();
                    return false;
                }
            }
        } catch (IOException e) {
            return true;
        }
    }

    private static byte[] inbuf = new byte[1024];
    static int lenbuf = 0, ptrbuf = 0;

    private static int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

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

    private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private static double nd() { return Double.parseDouble(ns()); }
    private static char nc() { return (char)skip(); }

    private static String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private static char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private static char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private static int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private static int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


import java.util.Scanner;
class T1{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count=0;
        for(int i=1;i<=n;i++){
            count = count+i;

        }System.out.println(count);

    }
}


class hi{
public static void main(String[] args){
System.out.println("Hello world");
}

}


import java.util.*;

public class Main{

	public static void main(String[] args){

      Scanner scan = new Scanner(System.in);
      String Input = scan.next();
      String[] lists = Input.split("");

      ArrayList<String> Array = new ArrayList<String>();

      for (int i=0; i<lists.length; i++){
        if(lists[i].equals("B") && Array.size()>0 ){
          try{
          if(lists[i+1].equals("B")){
           // System.out.print("pass");
          }
          else{
            Array.add(lists[i]);
          }
          }catch (ArrayIndexOutOfBoundsException e){
            Array.add(lists[i]);
          }
        }
        else{
          //System.out.println(lists[i]);
          Array.add(lists[i]);
        }
      }
    // System.out.println(Array);

     for (int j=0; j<Array.size(); j++){
      try{
       if (Array.get(j).equals("B")){
       }
       else if(j>0 && Array.get(j+1).equals("B")){
       }
       else{
         System.out.print(Array.get(j));
       }
      }catch (IndexOutOfBoundsException e){
        System.out.print(Array.get(j));
      }

    }
}
}


#include<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	printf("%d",(n+1)*n/2);
}


#include<cstdio>
int main(void)
{
    int i,n;
    while(~scanf("%d",&n))
    {
        int sum=0;
        for(i=1;i<=n;i++) sum+=i;
        printf("%d\n",sum);
    }
    return 0;
}


#include"stdio.h"
#include"cstdio"
#include"algorithm"
#include"string.h"
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	while(scanf("%d",&n)!=EOF)
	{
		ll ret=(n+1)*n/2;
		printf("%lld\n",ret);
	}
}


#include <iostream>
using namespace std;
int  main()
{
int  n,s;
cin >> n;
for(int i=1;i<=n;i++)
{
s+=i;
}
cout << s;
return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
#define P pair<int,int>
#define F first
#define S second

using namespace std;

int main(){
  int n;
  cin >> n;
  vi dp(n);
  dp[0] = 1;
  Lrep(i,1,100) dp[i] = dp[i-1] + i + 1;
  cout << dp[n-1] << endl;
}
p


#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
#define P pair<int,int>
#define F first
#define S second

using namespace std;

int main(){
  int n;
  vi dp(n);
  dp[0] = 1;
  Lrep(i,1,100) dp[i] = dp[i-1] + i + 1;
  cout << dp[n-1] << endl;
}


#include <stdio.h>

int main(void)
{
    int i,n,result;
    scanf("%d", &n);
    for(result=0,i=1;i<=n;i++){
        result += i;
    }
    printf("%d\n",result);

    return 0;
}


#include<stdio.h>
int main()
{

    int n,i,sum=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        sum=sum+i;
    }
    printf("%d\n",sum);
    return 0;
}


#include<stdio.h>

int main()
{

	int i, N, total;

	scanf("%d",&N);

	total = (N*(N+1))/2;

	printf("%d",total);

	return 0;
}


#include<stdio.h>
main()
{
    int N,i,sum=0;
    printf("Enter the number of students ");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        sum=sum+i;
    }
    printf("%d\n",sum);
    return 0;
}


#include <stdio.h>

int main()

{
int n,i,sum;

scanf("%d",&n);

for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf("%d",sum);

return 0;
}


#include<stdio.h>

int main(void){
  int N, sum = 0;
  scanf("%d", &N);
  for(int n; n < N; n++){
    sum = sum + n + 1;
  }
  printf("%d\n", sum);
  return 0;
}


function Main(input) {
  const data = parseInt(input, 10);
  var sum = 0;
  for (var i = 1; i <= data; i++) {
    sum += i;
  }
  console.log(sum);
}

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


function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  var ans =0;
  for(i=1;i<=n;i++){
    ans+=i;
  }

  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  input = input.trim();
  const a = input.split("").map(Number);
  console.log(a*(a+1)/2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(a) {
  console.log(a*(a+1)/2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(a) {
  a = a.trim();
  console.log(a*(a+1)/2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


package main

import(
	"fmt"
)

func main () {
	var a int
	var ans int

	fmt.Scan(&a)

	for i := 0; i <= a; i++{
		ans += i
	}

	fmt.Println(ans)
}


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()
	result := 0
	for i := 1; i <= N; i++ {
		result += i
	}
	fmt.Println(result)
}

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 getStringArray(n int) []string {
	array := make([]string, n)
	for i := 0; i < n; i++ {
		array[i] = getString()
	}
	return array
}

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

func primeFactors(n int) [] int {
	factors := make([]int, 0)
	i := 2
	for i * i <= n {
		r := n % i
		if r != 0 {
			i += 1
		} else if r == 0 {
			n /= i
			factors = append(factors, i)
		}
	}
	if n > 1 {
		factors = append(factors, n)
	}
	return factors
}


package main

import "fmt"

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

	ret := 0
	for i := 1; i <= n; i++ {
		ret += i
	}

	fmt.Println(ret)
}


package main

import (
	"fmt"
	"strings"
)

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

	slice := strings.Split(str, "")

	//fmt.Printf("%s\n", slice)

	ans := []string{}
	for i, x := range slice {
		if x != "B" {
			ans = append(ans, x)
		} else if i != 0 && x == "B" {
			length := len(ans)
			if length != 0 {
				ans = ans[:length-1]
			}
		}
	}
	r := strings.Join(ans, "")
	fmt.Println(r)
}


package main

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

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

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	ss := strings.Split(sc.Text(), " ")

	nl := []float64{}
	for _, i := range ss {
		m, _ := strconv.ParseFloat(i, 64)
		nl = append(nl, m)
	}

	res := math.MaxFloat64
	for i := -100; i <= 100; i++ {
		r := 0.0
		for _, x := range nl {
			r += math.Pow(x - float64(i), 2)
		}
		if res > r {
			res = r
		}
	}
	fmt.Println(int(res))
}


package main

import (
	"fmt"
)

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

  for i := 0; i < n; i++ {
  	ans += i
  }

  fmt.Println(ans)
}


a = gets.to_i
x = (0..a).inject(&:+)
puts x


N = gets.to_i
puts [*1..N].inject(:+)


n = gets.chomp.to_i
i = 0
sum = 0
while i <= n
  sum += i
  i += 1
end
puts sum


s = gets.chomp
ans = []
for i in 0..(s.length - 1)
  if s[i] == "B"
    if ans.size != 0
      ans.delete_at(ans.size - 1)
    end
  else
    ans.push(s[i])
  end
end
puts ans.reverse.join


n = gets.to_i
puts (n/2)*(n + 1)


ABC = gets.split.map(&:to_i)
puts (ABC.count(5) == 2 && ABC.count(7) == 1) ? 'YES' : 'NO'


use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let n: usize = s.trim().parse().unwrap();

    println!("{}", n * (n + 1) / 2);
}


fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<u16>().unwrap();
    let sum = (0..n+1).fold(0, |a, i| a + i);
    println!("{}", sum);
}


fn main() {
    let n = read_i64();
    println!("{}", solve(n));
}

fn solve(n : i64) -> i64 {
    n * (n + 1) / 2
}

fn read_i64() -> i64 {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf);
    buf.trim().parse().unwrap()
}


fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let mut v = Vec::new();

    for char in line.trim().chars() {
        match char {
            'B' => { v.pop(); },
            c if c == '0' || c == '1' => { v.push(c); },
            _ => ()
        }
    }

    let s = v
        .iter()
        .map(|s| s.to_string())
        .collect::<String>();

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


fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<u8>().unwrap();
    let sum = (0..n+1).fold(0, |a, i| a + i);
    println!("{}", sum);
}


use std::io::*;
use std::str::FromStr;

pub 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 = read::<i32>();
    println!("{}", (1..=n).fold(0, |sum, i| sum + i));
}


let N=Int(readLine()!)!;print(N*(N+1)/2)


print((1...Int(readLine()!)!).reduce(0){$0+$1})


let n = Int(readLine()!)!
print(n*(n+1)/2)


print(1...Int(readLine()!)!.reduce(0){$0+$1})


print(1...Int(readLine)!.reduce(0){$0+$1})


var ary:[Int] = []
for i in 1...Int(readLine()!)! {
    ary.append(i)
}
print(ary.reduce(0, {x, y in x + y}))


import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
var num = parseInt(input[0])

console.log(num * (num + 1) / 2);


function main(input: string) {
  const N: number = Number(input.split("\n")[0]);
  let sum: number = 0;
  for (let i: number = 1; i <= N; i += 1) {
    sum += i;
  }
  console.log(sum);
}

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


const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let n=nin()
  out(n*(n+1)/2)
}
main()


const fs = require('fs')
const reader = (s: string) => (s.split(""))

function Main(input: string) {
  let aaa = ''
  reader(input).forEach(r=>{
    if(r ==="B")
    {
      if(aaa.length > 0 ) aaa = aaa.slice(0,aaa.length -1)
    }
    else{
      aaa += r
    }
  })
  console.log(aaa)
}

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


'use strict'
const main = (input) => {
  input = input.split('')[0];
  const s = "";

  for (const i = 0; i<input.length; i++) {
    if (input[i]=="0") {
      s += "0";
    }else if(input[i]=="1"){
      s += "1"
    }else{
      s = s.slice(0, -1);
    }
  }
  console.log(s);
}

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


'use strict'
const main = (input) => {
  input = input.split('\n')[0].split('');
  const s = "";

  for (const i = 0; i<input.length; i++) {
    if (input[i]=="0") {
      s += "0";
    }else if(input[i]=="1"){
      s += "1"
    }else{
      s = s.slice(0, -1);
    }
  }
  console.log(s);
}

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


n = int(input())
W = list(map(int,input().split()))
sa = sum(W)

for i in range (n):
  if abs(sa-2*W[i])-abs(sa) >0:
    print(abs(sa))
    break
  sa -= 2*W[i]


n = int(input())
a = list(map(int, input().split()))

left = 0
right = sum(a)

ans = 10000
for i in range(1, n):
    left += a[i - 1]
    right -= a[i - 1]
    if abs(left - right) < ans:
        ans = abs(left - right)
    else:
        break

print(ans)


n = int(input())
w = list(map(int,input().split()))

mindel = 10000
for i in range(0,n-1):
    dels = abs(sum(w[0:i+1])-sum(w[i+1:n]))
    if dels<mindel:
        mindel = dels
print(mindel)


url = "https://atcoder.jp//contests/abc129/tasks/abc129_b"

def main():
    n = int(input())
    t = list(map(int, input().split()))
    ans = 1000000000
    sums = sum(t)
    for v in t:
        sums -= v
        ans = min(sums, ans)
    print(ans)

if __name__ == '__main__':
    main()


N = int(input())
W = list(map(int,input().split()))
T = []
for t in range(1,N):
    Q = [W[i] for i in range(t)]
    R = [W[i] for i in range(t,N)]
    T.append(abs(sum(Q)-sum(R)))

print(T)


N = int(input())
W = list(map(int,input().split()))
T = []
Q = []
R = []
for t in range(1,N):
    for i in range(N):
        if i <= t-1:
            Q.append(int(W[i]))
        else:
            R.append(int(W[i]))
    sum_Q = sum(Q)
    sum_R = sum(R)
    T.append(abs(sum_Q - sum_R))

print(min(T))


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

public class Main {

    static PrintWriter out;
    static InputReader sc;

    static void solve() {
        int N = sc.nextInt();
        int[] w = new int[N + 1];
        int ans = Integer.MAX_VALUE / 4;
        for (int i = 0; i < N; i++) {
            w[i + 1] = w[i] + sc.nextInt();
        }
        for (int t = 1; t < N; t++) {
            ans = Math.min(ans, Math.abs(w[t] - (w[N] - w[t])));
        }
        out.print(ans);
    }

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

    public static class ArraysFillEx {

        public static void fill(Object array, Object value) {

            // 第一引数が配列か判定
            Class<?> type = array.getClass();
            if (!type.isArray()) {
                throw new IllegalArgumentException("not array");
            }

            // クラスの型を判定
            String arrayClassName = array.getClass().getSimpleName().replace("[]", "").toLowerCase();
            String valueClassName = value.getClass().getSimpleName().toLowerCase().replace("character", "char")
                    .replace("integer", "int");
            if (!arrayClassName.equals(valueClassName)) {
                throw new IllegalArgumentException("does not match");
            }

            // 処理
            if (type.getComponentType().isArray()) {
                for (Object o : (Object[]) array) {
                    fill(o, value);
                }
            } else if (array instanceof boolean[]) {
                Arrays.fill((boolean[]) array, (boolean) value);
            } else if (array instanceof char[]) {
                Arrays.fill((char[]) array, (char) value);
            } else if (array instanceof byte[]) {
                Arrays.fill((byte[]) array, (byte) value);
            } else if (array instanceof short[]) {
                Arrays.fill((short[]) array, (short) value);
            } else if (array instanceof int[]) {
                Arrays.fill((int[]) array, (int) value);
            } else if (array instanceof long[]) {
                Arrays.fill((long[]) array, (long) value);
            } else if (array instanceof float[]) {
                Arrays.fill((float[]) array, (float) value);
            } else if (array instanceof double[]) {
                Arrays.fill((double[]) array, (double) value);
            } else {
                Arrays.fill((Object[]) array, value);
            }
        }

    }

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

    static void tr(Object... o) {
        out.println(Arrays.deepToString(o));
    }
}


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

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] W = new int[N + 1];
		for (int i = 1; i <= N; i++)
			W[i] = sc.nextInt();
		int S1 = 0;
		int S2 = 0;
		int max = 0;
		for (int i = 1; i <= N; i++)
			max += W[i];
		int ans = max;

		for (int t = 1; t <= N; t++) {
			for (int i = 1; i <= t; i++) {
				S1 += W[i];
			}
			S2 = max - S1;
			ans = Math.min(ans, Math.abs(S1 - S2));
			S1 = 0;
			S2 = 0;
		}

		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 || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


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

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        int[] W = new int[N];
        int a = 0;
        int b = 0;
        for (int i=0; i<N; i++) {
            W[i] = reader.nextInt();
            a += W[i];
        }
        int ans = a;
        for (int i=0; i<N; i++) {
            a -= W[i];
            b += W[i];
            ans = Math.min(ans, Math.abs(a-b));
        }
        System.out.println(ans);
    }

    // Read Class
    static class FS {
        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() { return hasNextByte() ? buffer[ptr++] : -1;}
        private 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 int nextInt() {
            return (int)nextLong();
        }
        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();
            }
        }
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> omori = new ArrayList<Integer>();
		int n = sc.nextInt();
		for (int i = 0; i <= n - 1; i++) {
			int a = sc.nextInt();
			omori.add(a);
		}
		int weight = 0;
		for (int i = 0; i <= n - 1; i++) {
			weight += omori.get(i);
		}

		int ans=0;
		for (int i = 0; i < n - 1; i++) {
			int zen = 0;
			for (int j = 0; j <= i; j++) {
				zen += omori.get(j);

			int kou = weight - zen;

			int zen2 = zen + omori.get(i + 1);
			int kou2 = weight - zen2;

			ans = Math.min(Math.abs(zen2 - kou2), Math.abs(zen - kou));
			}
		}
		System.out.println(ans);

	}
}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> omori = new ArrayList<Integer>();
		int n = sc.nextInt();
		for (int i = 0; i <= n - 1; i++) {
			int a = sc.nextInt();
			omori.add(a);
		}
		int weight = 0;
		for (int i = 0; i <= n - 1; i++) {
			weight += omori.get(i);
		}

		int ans=0;
		for (int i = 0; i < n - 1; i++) {
			int zen = 0;
			for (int j = 0; j <= i; j++) {
				zen += omori.get(j);
			}
			int kou = weight - zen;

			int zen2 = zen + omori.get(i + 1);
			int kou2 = weight - zen2;

			ans = Math.min(Math.abs(zen2 - kou2), Math.abs(zen - kou));

		}
		System.out.println(ans);

	}
}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> omori = new ArrayList<Integer>();
		int n = sc.nextInt();
		for (int i = 0; i <= n - 1; i++) {
			int a = sc.nextInt();
			omori.add(a);
		}
		int weight = 0;
		for (int i = 0; i <= n - 1; i++) {
			weight += omori.get(i);
		}

		for (int i = 0; i < n - 1; i++) {
			int zen = 0;
			for (int j = 0; j <= i; j++) {
				zen += omori.get(j);
			}
			int kou = weight - zen;

			int zen2 = zen + omori.get(i + 1);
			int kou2 = weight - zen2;

			ans = Math.min(Math.abs(zen2 - kou2), Math.abs(zen - kou));

		}
		System.out.println(ans);

	}
}


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


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


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


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


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


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


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


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


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


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


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


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


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());


'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);


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/));


// 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"));


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


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


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


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


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


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


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


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


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


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)


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


_,*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


_,*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


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()
}


#[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);

}


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


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


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


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


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)


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] )


/// 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)


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])))
}


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)
}
*/


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())


{
  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())
}


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)


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"));


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")


s = input()
t = input()
#print(s, t)
s += s
#print(s, t)

if t in s:
    print("Yes")
else:
    print("No")


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")


s = input()
t = input()

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


s = input()
t = input()

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


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')


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


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


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

}


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


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


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


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


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


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


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


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


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


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


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

}


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


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


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


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


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')


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'));


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"));


/*
-------関数一覧--------
arr1dto2d(Array) 一次元配列を二次元配列にします
pf(N)因数分解した結果をオブジェクトで返します
gcd(a,b)最大公約数を返します
lcm(a,b)最小公倍数を返します
num(a,b)a-bを返します。ソート用です
isPrime(n)素数かどうか真偽値で返します
isNumber(n)数かどうか真偽値で返します
arrsum(arr)配列の合計値を返します
nibu(arr,n)n以下で最も大きい数の添字を返します(nを含みます)
br(input)入力を改行で区切ります
*/
const debugMode = false;
const inf = Number.MAX_SAFE_INTEGER;

function Main(input){
    input = input.split("\n");
    console.log(input[1].split("").sort().join("")==input[0].split("").sort().join("")?"Yes":"No")
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function next(m,now){

}
function zisyozyunn(a){
  var arr = [];
  for(var i=0;i<input[0];i++){
    arr.push(i+1);
  }
  var sum = 0;
  for(i=0;i<a.length;i++){
    var f = arr.findIndex(val => val==a[i]);
    sum += factorialize(a.length-1-i)*f;
    arr.splice(f,1);
  }
  return sum;
}
function arrsum(arr){
  var sum = 0;
  for (var i=0,len=arr.length; i<len; ++i) {
      sum += arr[i]-0;
  };
  return sum;
}
function debug(val){
  if(debugMode==true){
    console.log(val)
  }
}
function arrMaxPoint(arr){
	var max = Number.MIN_SAFE_INTEGER;
	var point = -1;
	for(var i=0;i<arr.length;i++){
		if(max<arr[i]){
			max = arr[i];
			point = i;
		}
	}
	return point;
}
function arrMinPoint(arr){
	var min = Number.MAX_SAFE_INTEGER;
	var point = -1;
	for(var i=0;i<arr.length;i++){
		if(min>arr[i]){
			min = arr[i];
			point = i;
		}
	}
	return point;
}
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
		arr[i]=arr[i].split("");
		}
	return arr;
}
function isPrime(n){
    if(false===Number.isInteger(n)){
        return false;
    }
    if(n<=1){
        return false;
    }
    if(2===n){
        return true;
    }
    if(0===n%2){
        return false;
    }
    var square_root = Math.floor(Math.sqrt(n));
    for(var i=3; i<=square_root; i+=2){
        if(0===n%i){
            return false;
        }
    }
    return true;
}
function isNumber(val){
	const pat = /^([1-9]\d*|0)$/;
	return pat.test(val);
}
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
		arr[i]=arr[i].split("");
		}
	return arr;
}
function factorialize(num) {
  if (num === 0) { return 1; }
  return num * factorialize(num-1);
}
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split(" ").map(Number);
    }
  return arr;
}
function rotate(array) {
  const ROW = array.length;
  const COL = array[0].length;
  const row = ROW-1;
  var a = new Array(COL);
  for (var c=0; c<COL; c++) {
    a[c] = new Array(ROW);
    for (var r=0; r<ROW; r++) {
      a[c][r] = array[row-r][c];
    }
  }
  return a;
}
function part_in(base,push,st){
	for(var i=st,p=0;p<push.length;i++,p++){
		base[i] = push[p];
	}
	return base;
}
function part_reverse(arr,s,g){
	var push = arr.slice(s-1,g);
  push.reverse();
	arr = part_in(arr,push,s-1);
	return arr;
}
function zeroPadding(num,length){
    return (num + '000000000000000000000000000000000').slice(0,length);
}
function arrsum(arr){
    var sum = 0;
    for (var i=0,len=arr.length; i<len; ++i) {
        sum += arr[i]-0;
    };
    return sum;
}
function pf(n) {
    var result = {};

    if (n === 1) {
        return {"1":1}
    }

    var init = 2;

    while (n !== 1) {
        var i = init;
        while (i < Number.MAX_SAFE_INTEGER) {
            if (n % i === 0) {
                n /= i;
                if (!(result[i] > 0)) {
                    result[i] = 0;
                }
                result[i]++;
                break;
            }
            i++;
        }
        init = i;
    }
    return result;
}
function gcd(a, b) {
    if (b === 0){
        return a
    }
    return gcd(b, a % b)
}
function lcm(a,b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}
function num(a, b) {
  return a - b;
}
function nibu(a,searchValue){
	var index = -1;

//調べる左端を表す添字(index)
var left = 0;

//調べる右端を表す添字(index)
var right = a.length-1;

//左端と右端にデータがある間は処理を繰り返す
while(left <= right){

    //左右の真ん中を表す添字(index)
    middle =Math.floor((left +right)/2);

    //真ん中の値と探す値を比較する
    if(a[middle]==searchValue){
        //一致した場合、変数に入れて処理終了
        index = middle;
        break;
    }else if(a[middle]<searchValue){
        //探す値より小さい場合、左側にはもっと小さい値しかないので左端の値を真ん中の値の右に移動する
        left = middle +1;
    }else{
        //探す値より大きい場合、右側にはもっと大きい値しかないので右端の値を真ん中の値の左に移動する
        right = middle -1;
    }
}
if(index!=-1) return index;
else return left;
}
function br(input){
  return input.split("\n");
}
function is_sortred(arr){
  var flag = true;
  for(var i=1;i<arr.length;i++){
    if(arr[i-1]>arr[i]){
      flag = false;
      break;
    }
  }
  return flag;
}


/*
-------関数一覧--------
arr1dto2d(Array) 一次元配列を二次元配列にします
pf(N)因数分解した結果をオブジェクトで返します
gcd(a,b)最大公約数を返します
lcm(a,b)最小公倍数を返します
num(a,b)a-bを返します。ソート用です
isPrime(n)素数かどうか真偽値で返します
isNumber(n)数かどうか真偽値で返します
arrsum(arr)配列の合計値を返します
nibu(arr,n)n以下で最も大きい数の添字を返します(nを含みます)
br(input)入力を改行で区切ります
*/
const debugMode = false;
const inf = Number.MAX_SAFE_INTEGER;

function Main(input){
    input = input.split("\n");
    console.log(input[1].split("").sort.join("")==input[0].split("").sort("").join("")?"Yes":"No")
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function next(m,now){

}
function zisyozyunn(a){
  var arr = [];
  for(var i=0;i<input[0];i++){
    arr.push(i+1);
  }
  var sum = 0;
  for(i=0;i<a.length;i++){
    var f = arr.findIndex(val => val==a[i]);
    sum += factorialize(a.length-1-i)*f;
    arr.splice(f,1);
  }
  return sum;
}
function arrsum(arr){
  var sum = 0;
  for (var i=0,len=arr.length; i<len; ++i) {
      sum += arr[i]-0;
  };
  return sum;
}
function debug(val){
  if(debugMode==true){
    console.log(val)
  }
}
function arrMaxPoint(arr){
	var max = Number.MIN_SAFE_INTEGER;
	var point = -1;
	for(var i=0;i<arr.length;i++){
		if(max<arr[i]){
			max = arr[i];
			point = i;
		}
	}
	return point;
}
function arrMinPoint(arr){
	var min = Number.MAX_SAFE_INTEGER;
	var point = -1;
	for(var i=0;i<arr.length;i++){
		if(min>arr[i]){
			min = arr[i];
			point = i;
		}
	}
	return point;
}
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
		arr[i]=arr[i].split("");
		}
	return arr;
}
function isPrime(n){
    if(false===Number.isInteger(n)){
        return false;
    }
    if(n<=1){
        return false;
    }
    if(2===n){
        return true;
    }
    if(0===n%2){
        return false;
    }
    var square_root = Math.floor(Math.sqrt(n));
    for(var i=3; i<=square_root; i+=2){
        if(0===n%i){
            return false;
        }
    }
    return true;
}
function isNumber(val){
	const pat = /^([1-9]\d*|0)$/;
	return pat.test(val);
}
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
		arr[i]=arr[i].split("");
		}
	return arr;
}
function factorialize(num) {
  if (num === 0) { return 1; }
  return num * factorialize(num-1);
}
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split(" ").map(Number);
    }
  return arr;
}
function rotate(array) {
  const ROW = array.length;
  const COL = array[0].length;
  const row = ROW-1;
  var a = new Array(COL);
  for (var c=0; c<COL; c++) {
    a[c] = new Array(ROW);
    for (var r=0; r<ROW; r++) {
      a[c][r] = array[row-r][c];
    }
  }
  return a;
}
function part_in(base,push,st){
	for(var i=st,p=0;p<push.length;i++,p++){
		base[i] = push[p];
	}
	return base;
}
function part_reverse(arr,s,g){
	var push = arr.slice(s-1,g);
  push.reverse();
	arr = part_in(arr,push,s-1);
	return arr;
}
function zeroPadding(num,length){
    return (num + '000000000000000000000000000000000').slice(0,length);
}
function arrsum(arr){
    var sum = 0;
    for (var i=0,len=arr.length; i<len; ++i) {
        sum += arr[i]-0;
    };
    return sum;
}
function pf(n) {
    var result = {};

    if (n === 1) {
        return {"1":1}
    }

    var init = 2;

    while (n !== 1) {
        var i = init;
        while (i < Number.MAX_SAFE_INTEGER) {
            if (n % i === 0) {
                n /= i;
                if (!(result[i] > 0)) {
                    result[i] = 0;
                }
                result[i]++;
                break;
            }
            i++;
        }
        init = i;
    }
    return result;
}
function gcd(a, b) {
    if (b === 0){
        return a
    }
    return gcd(b, a % b)
}
function lcm(a,b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}
function num(a, b) {
  return a - b;
}
function nibu(a,searchValue){
	var index = -1;

//調べる左端を表す添字(index)
var left = 0;

//調べる右端を表す添字(index)
var right = a.length-1;

//左端と右端にデータがある間は処理を繰り返す
while(left <= right){

    //左右の真ん中を表す添字(index)
    middle =Math.floor((left +right)/2);

    //真ん中の値と探す値を比較する
    if(a[middle]==searchValue){
        //一致した場合、変数に入れて処理終了
        index = middle;
        break;
    }else if(a[middle]<searchValue){
        //探す値より小さい場合、左側にはもっと小さい値しかないので左端の値を真ん中の値の右に移動する
        left = middle +1;
    }else{
        //探す値より大きい場合、右側にはもっと大きい値しかないので右端の値を真ん中の値の左に移動する
        right = middle -1;
    }
}
if(index!=-1) return index;
else return left;
}
function br(input){
  return input.split("\n");
}
function is_sortred(arr){
  var flag = true;
  for(var i=1;i<arr.length;i++){
    if(arr[i-1]>arr[i]){
      flag = false;
      break;
    }
  }
  return flag;
}


"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'));


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")
}


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")
}


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")
}


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
}