akhauriyash/Code-Regression huggingface dataset:
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
  string S;
  cin >> S;

  int not0101 = 0;   // 010101…と違う箇所の個数をカウント
  int not1010 = 0;

  rep(i, S.size()) {
    if (i % 2 == 0) {
      if (S[i] != '0') not0101++;
      else not1010++;
    } else {
      if (S[i] != '1') not0101++;
      else not1010++;
    }
  }

  int ans = not0101 < not1010 ? not0101 : not1010;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3724
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0||n==1)return dp[n]=1;
  if(dp[n]!=-1)return dp[n];
  return dp[n]=fib(n-1)+fib(n-2);
}
int main(){
  int n,i;
  for(i=0;i<50;i++)dp[i]=-1;
  scanf("%d",&n);
  printf("%d\n",fib(n));
  return 0;
}



Measured memory_bytes: 2104
import math
import fractions
import sys
import itertools
import numpy as np
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))


N=input1()
S=list(str(input()))
base=ord("A")
for i in range(len(S)):
	S[i]=chr(base+(ord(S[i])-ord("A")+N)%26)
print("".join(S))
















Measured memory_bytes: 13668
#include <bits/stdc++.h>
using namespace std;

inline void ioThings() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif
}

using   ll        = long long;
#define debug(x)    cerr << #x << ": <" << (x) << ">\n"
#define dotc()      int tcs; if (cin >> tcs) for (int tc = 0; tc < tcs; tc++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second
#define mod         1000000007

using vi = vector<int>;

int main() {
  ioThings();

  string s; cin >> s;
  int size = sz(s);
  
  vector<int> a1(size), a2(size);
  for (int i = 0; i < size; i++) {
    a1[i] = s[i] - '0';
    a2[i] = 10 - a1[i];
    for (int j = i - 1; j >= 0; j--) {
      if (a2[j]) {
        a2[j]--;
        break;
      } else
        a2[j] = 9;
    }
  }

  // dp = pos, who's turn to pay -> accumulated notes
  vector<vi> dp(size + 1, vi(2, 1e9));
  dp[0][0] = 0;
  dp[0][1] = 1;
  for (int i = 0; i < size; i++) {
    dp[i + 1][0] = dp[i][0] + a1[i];
    dp[i + 1][1] = dp[i][1] + a2[i];
    if (a1[i] + a2[i] != 10) {
      if (a1[i] != 9)
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + a1[i] + 1);
      if (a2[i] != 9)
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + a2[i] + 1);
    }
  }

  cout << min(dp[size][0], dp[size][1]);

  return 0;
}


Measured memory_bytes: 65820
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
  std::vector<int> x(5);
  rep(i, 5){
    cin >> x.at(i);
  }
  rep(i, 5){
    if(x.at(i) == 0){
      std::cout << i+1 << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template<class T>
T chmax(T& a, T b) { return a = max(a, b); }

const int M = 100000;
int dp[10][M + 1];

int main() {
	int n, d, x;
	cin >> n >> d >> x;
	
	int p[10][10];
	
	for(int i = 0; i < d; i++) {
		for(int j = 0; j < n; j++) {
			cin >> p[i][j];
		}
	}
	
	for(int i = 0; i < d; i++)
		for(int j = 0; j <= M; j++)
			dp[i][j] = -1;
			
	dp[0][x] = x;
	
	for(int day = 0; day < d - 1; day++) {
		for(int budjet = M; budjet >= 0; budjet--) {
			if(dp[day][budjet] < 0)
				continue;
			
			for(int stock = 0; stock < n; stock++) {
					if(p[day][stock] > budjet)
						continue;
					
					// buy the stock
					chmax(dp[day][budjet - p[day][stock]], dp[day][budjet] - p[day][stock] + p[day + 1][stock]);
			}
			
			// not buy
			if(dp[day][budjet] >= 0) {
				dp[day + 1][dp[day][budjet]] = dp[day][budjet];
			}
		}
	}

	// cout << endl;
	// for(int i = 0; i < d; i++)
	// 	for(int j = 0; j <= 12; j++)
	// 		cout << dp[i][j] << (j == 12 ? '\n' : ' ');
			// if(dp[i][j] != -1)
				// cout << i << " " << j << " " << dp[i][j] << endl;
	
	for(int i = M; i >= 0; i--) {
		if(dp[d - 1][i] > 0) {
			cout << dp[d - 1][i] << endl;
			return 0;
		}
	}

	throw "Error;";
}

// dp[day][budjet] = benefit
// day??\????????????????????????budjet???????????¨???????????§??????
// 

Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define EPS 1e-8
#define INF 1e9+10
#define INFL 1e18
typedef long long ll;
using namespace std;
int dp[100010];
int main()
{
  int N,M;
  cin >> N >> M;
  vector<bool>ok(N+1,true);
  rep(i,M){
      int a;
      cin >> a;
      ok[a]=false;
  }

  dp[0]=1;
  rep(i,N){
      if(ok[i+1]){dp[i+1]+=dp[i];}
      if(ok[i+2]){dp[i+2]+=dp[i];}
      dp[i+1]%=MOD;dp[i+2]%=MOD;
  }

  cout << dp[N] << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

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

int m=100000;
int s=0;
  for(int j=0;j<n-1;j++){
    s+=w[j];
    m=min(m,abs(s-(sum-s)));
  }
cout<<m;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main() {
	int i = 1;
	int x;
	while (1) {
		cin >> x;
		if (x == 0) {
			break;
		}
		cout << "Case " << i << ": " << x << endl;
		i++;
	}
	return 0;
}

Measured memory_bytes: 1160
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (k, s) = scan!(i64, i64);
    let mut ans = 0;
    for x in 0..k + 1 {
        for y in 0..k + 1 {
            let z = s - x - y;
            if 0 <= z && z <= k {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;

int main()
{
  bool frag=false;
  vector<char> v(3);
  for(int i = 0; i < 3; i++)
  {
    cin >> v[i];
    if(v[i] == '7')frag = true;
  }
  
  if(frag)cout << "Yes" << endl;
  else cout << "No" << endl;
}  

Measured memory_bytes: 3624
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include <queue>
#include<bits/stdc++.h>
#define fo(x,a,b) for(register int x=a;x<=b;x++)
#define dfo(x,a,b) for(register int x=a;x>b;x--)
#define inf 2147483647
using namespace std;
char s[255],st[255];
bool cmp(int x,int y){return x<y;}
priority_queue<int> q;
int v,t,l,r,k=0;
struct cmp2
{ 
    bool operator ()(int &a,int &b){ return a<b;}
};
int main ()
{
       
        priority_queue<int,vector<int>,cmp2>q;
        k++;
        while (true) 
        {
        	
            	fo(j,1,7)
            	{
                	s[j]=getchar();
				}
                if (s[3]=='d')return 0 ;
                if (s[1]=='i')
                {
                	scanf("%d\n",&v);
                	q.push(v);
                    
               	}
                else
                {
                        if (s[1]=='e')
                        {
                        		if (k>0) getchar(); 
                                printf("%d\n",q.top());
                                q.pop();
                                
                        }
               }
               
       	}
}





Measured memory_bytes: 6900
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        ArrayList<Pair> data = new ArrayList();
        for (int i = 0; i < N; i++) {
            data.add(new Pair(1, scan.nextLong()));
        }
        for (int i = 0; i < M; i++) {
            int B = scan.nextInt();
            long C = scan.nextLong();
            data.add(new Pair(B, C));
        }
        data.sort(new PairComparator());
        long answer = 0;
        int remain = N;
        int index = 0;
        while (0 < remain) {
            Pair pair = data.get(index++);
            int size = pair.size;
            long value = pair.value;
            answer += Math.min(remain, size) * value;
            remain -= Math.min(remain, size);
        }
        System.out.println(answer);
    }
    class Pair {
        int size;
        long value;
        Pair(int size, long value) {
            this.size = size;
            this.value = value;
        }
    }
    class PairComparator implements Comparator<Pair> {
        @Override
        public int compare(Pair o1, Pair o2) {
            if (o1.value != o2.value) {
                return -Long.compare(o1.value, o2.value);
            }
            return -Integer.compare(o1.size, o2.size);
        }
    }
}


Measured memory_bytes: 103340
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i= 0; i<n; i++)
		 cin>>a[i];
	int cnt = 0;
	for(int i = 1; i<=n; i++)
	{
		if(i==a[i-1])
		{
			cnt++;
			i++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>

using namespace std;

typedef long long ll;

int main(void){
    string a,b,c;
    cin >> a >>b >>c;
    if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
l = sorted(list(set(map(int, input().split()))))

df = l[0]
#print("df", df)

s = len(bin(df)) - 2
#print("s", s)

count = 0
for i in range(s):
    if df % 2:
        break
    df //= 2
    count += 1
    
#print("count", count)

l = tuple(map(lambda x:x // (2**count), l))
#print("l", l)

for i in l:
    if i % 2 == 0:
        print(0)
        exit()

def gcd(a, k):
    if k:
        return gcd(k, a % k)
    return a

ans = l[0]
for i in l:
    ans = ans * i // gcd(ans, i)

print(-(-(M // (ans * 2**(count - 1))) // 2))


Measured memory_bytes: 11132
#include"bits/stdc++.h"
using namespace std;
int main(){
	int a,b,e;
	cin>>a>>b>>e;
	cout<<a<<' '<<b<<' '<<3*e-a-b<<endl;
	cout<<4*e-2*a-b<<' '<<e<<' '<<2*a+b-2*e<<endl;
	cout<<a+b-e<<' '<<2*e-b<<' '<<2*e-a;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,cur,cnt=1;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    cur = a[0];
    for(int i=1;i<n;i++){
        if(a[i]<cur) cnt++;
        cur = min(cur,a[i]);
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1024
/******************************************
/@Author: LeafBelief
/@Date: 2020-04-07
/@Remark:    
/@FileName: changeflyord
******************************************/
#include <bits/stdc++.h>
#define CSE(x,y) memset(x,y,sizeof(x))
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn = 2010;
int dis[maxn][maxn], n, x, y;
int ans[maxn];

int main()
{
    FAST;
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            dis[i][j] = dis[j][i] = abs(i -j);
        }
    }
    dis[x][y] = dis[y][x] = 1;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            dis[i][j] = min(dis[i][j], dis[i][x] + dis[y][j] + 1);
        }
    }
    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j++)
            ans[dis[i][j]]++;
    for(int i = 1; i < n; i++)
        cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> tmp(M, 0);
  for(int i=0; i<N; ++i){
    int A, K;
    cin >> K;
    for(int j=0; j<K; ++j){
      cin >> A;
      tmp[A-1]++;
    }
  }
  int ans=0;
  for(int i=0; i<M; ++i){
    if(tmp[i]==N) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#ifdef DBG_MACRO_NO_WARNING
#include <dbg.h>
#endif
#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define isz(c) (int)c.size()

using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

ll const MOD = 1e9 + 7;

ll binpow(ll a, ll b)
{
    a %= MOD;
    ll ans = 1;
    while (b > 0)
    {
        if (b & 1)
            ans = ans * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ans;
}

ll sub(ll a, ll b) { return ((a + MOD % MOD) - (b + MOD % MOD) + MOD) % MOD; }
ll add(ll a, ll b) { return ((a + MOD % MOD) + (b + MOD % MOD)) % MOD; }

int main(void)
{
    ll n;
    cin >> n;

    ll U   = binpow(10, n);
    ll Z   = binpow(9, n);
    ll N   = binpow(9, n);
    ll ZuN = binpow(8, n);

    ll ans = sub(U, sub(add(Z, N), ZuN));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

int n;
int vs[100000+10];

bool go() {
  sort(vs, vs + n);
  if((vs[0] == vs[n-1] || vs[0]+1 == vs[n-1]) == false) { // 3種類以上の証言
    return false;
  }
  int c = vs[0];
  int k = 0;
  REP(i, n) {
    if(vs[i] == c){
      ++k;
    }
  }
  if(k == n) {
    return 2*c <= n || c == n-1;
  } else {
    return c >= k && k >= max(2*c-n+2, 0);
  }
}



int main(void) {
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
  }
  puts(go() ? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 512
N, T = map(int, input().split())
*a, = map(int, input().split())
m = a[0]
p = 0
ans = 0
for i in range(1, N):
    c = a[i] - m
    if a[i] < m:
        m = a[i]
    if c > p:
        p = c
        ans = 1
    elif c == p:
        ans += 1

print(ans)


Measured memory_bytes: 62704
package main

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

func main() {
	N := nextInt()
	as := make([]int, 3*N)
	for i := 0; i < 3*N; i++ {
		as[i] = nextInt()
	}

	sort.Ints(as)

	strength := 0
	for len(as) > 0 {
		// Pop.
		as = as[:len(as)-1]
		strength += as[len(as)-1]
		as = as[:len(as)-1]

		// Shift.
		as = as[1:]
	}

	fmt.Println(strength)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

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

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}

	return y
}

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

// ---------- Util.


Measured memory_bytes: 6016
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1001;

main(){
  int data[N+1], a, b;
  data[0] = 1;
  data[1] = 2;
  for(int i=2;i<=N;i++) data[i] = (data[i-1] + data[i-2]) % N;
  while(cin >> a >> b){
    int ans = 1, tmp[N+1];
    for(int i=0;i<a;i++) tmp[i] = data[i+1];
    sort(tmp, tmp+a);
    for(int i=1;i<a;i++) if(tmp[i] - tmp[i-1] >= b) ans++;
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
import numpy as np
from numba import njit

def solve(N, S_arr, k):
    ans = 0
    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM
    for i in range(k, N):
        if S_arr[i-k] == 1:
            D -= 1
            DM -= M
        elif S_arr[i-k] == 2:
            M -= 1

        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM

    return ans

def main():
    N = int(input())
    S = input()
    Q = int(input())
    ks = list(map(int, input().split()))

    def func(ch):
        if ch == 'D':
            return 1
        if ch == 'M':
            return 2
        if ch == 'C':
            return 3
        return 0
        
    S_arr = np.array([func(ch) for ch in S], dtype = np.int32)
    for k in ks:
        print(solve(N, S_arr, k))

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', "i8(i8, i4[:], i8)")(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()
    

Measured memory_bytes: 106392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    ll X = 0;
    rep(i, N) X ^= A[i];

    rep(i, N) cout << (X ^ A[i]) << " ";
    cout << endl;
}

Measured memory_bytes: 4760
%:pragma GCC optimize(3)
#include<bits/stdc++.h>
#define sc(x)  scanf("%d",&x)
#define pf(x)  printf("%d",x)
#define pfn(x) printf("%d\n",x)
#define pfs(x) printf("%d ",x)
#define rep(n) for(int i = 0;i < n;i++)
#define per(n) for(int i = n-1;i >= 0;i--)
#define mem(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
using namespace std;
int n,m,sum=0;
int a[10010];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=m;i++)sum+=a[i];
	cout<<sum;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <map>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <array>

using namespace std;

int main()
{
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for(auto &s : S) cin >> s;
    sort(S.begin(), S.end());
    for(auto &s : S) cout << s;
    cout << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000000

int MAX_N = 10000;
vector<int> par(MAX_N);//MAX_N == num of node
vector<int> tree_rank(MAX_N);

void init(int n)
{
  for (int i = 0; i < n; ++i)
  {
    par.at(i) = i;
    tree_rank.at(i) = 0;
  }
}

int find(int x)
{
  if (par.at(x) == x)
  {
    return x;
  }
  else
  {
    return par.at(x) = find(par.at(x));
  }
}

void unite(int x, int y)
{
  x = find(x);
  y = find(y);
  if (x == y)
  {
    return;
  }
  if (tree_rank.at(x) < tree_rank.at(y))
  {
    par.at(x) = y;
  }
  else
  {
    par.at(y) = x;
    if (tree_rank.at(x) == tree_rank.at(y))
    {
      tree_rank.at(x)++;
    }
  }
}

bool same(int x, int y)
{
  return find(x) == find(y);
}
// =======================================

// ==============kruskal==================

struct edge{int u, v, cost;}; // 辺u, v をつなぐコストが cost
bool comp(const edge& e1, const edge& e2)
{
  return e1.cost < e2.cost;
}
const int MAX_E = 100000;
edge es[MAX_E];
int V, E; // V 頂点、E 辺　の数

int kruskal()
{
  sort(es, es + E, comp);
  init(V);
  int ans = 0;
  for (int i = 0; i < E; ++i)
  {
    edge e = es[i];
    if (!same(e.u, e.v))
    {
      unite(e.u, e.v);
      ans += e.cost;
    }
  }
  return ans;
}


// =======================================


int main()
{
  cin >> V >> E;
  int s, t, w;
  for (int i = 0; i < E; ++i)
  {
    cin >> s >> t >> w;
    es[i] = {s, t, w};
  }
  int ans = kruskal();
  cout << ans << endl;
}



Measured memory_bytes: 4356
import java.util.*

object MainKt {
	@JvmStatic
	fun main(args: Array<String>) {
		val scanner = Scanner(System.`in`)
		val p = scanner.nextInt()
		val q = scanner.nextInt()
		val r = scanner.nextInt()
		if (Math.max(p, q)<r) println(p+q)
		else println(Math.min(p,q)+r)
	}
}

Measured memory_bytes: 29352
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf = 10e17;
const ll mod = inf;//1000000007;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);


ll mulmod(ll x, ll y)
{
	return (x * y) % mod;
}

ll submod(ll x, ll y)
{
	return (x - y + 100 * mod) % mod;
}

ll power(ll n, ll r)
{
	if ( r == 0 ) { return 1; }
	if ( r == 1 ) { return n; }
	if ( n == 0 ) { return 0; }
	if ( n == 1 ) { return 1; }

	if (r % 2 == 0)
	{
		ll y = power(n, r/2);
		return mulmod(y, y);
	}
	else
	{
		ll y = power(n, (r-1)/2);
		return n * mulmod(y, y) % mod;
	}
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

vector<ll> perm;
vector<ll> inv;
void init_inv(ll m)
{
	perm.resize(m);
	inv.resize(m);
	
	perm[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i < m; i++)
	{
		perm[i] = mulmod(perm[i-1], i);
	}
	
	for (ll i = 1; i < m; i++)
	{
		inv[i] = power(perm[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	// n (n-1) ... (n-r)
	if ( r == n || r == 0 ) { return 1; }

	ll ans = 1;
	for (ll i = 0; i < r; i++)
		ans = mulmod(ans, n - i);

	 return mulmod(ans, inv[r]);
	// return mulmod(perm[n], mulmod(inv[n-r], inv[r]));
}

bool binary_check(ll mid, ll key)
{
	return mid >= key;
}

ll binary_search()
{
	ll n, k;
	cin >> n >> k;

	ll ng = 0;
	ll ok = n;

	while (abs(ok - ng) > 1)
	{
		ll mid = (ok+ng) / 2;
		if (binary_check(mid, k)) ok = mid;
		else ng = mid;
	}

	return ok;
}

ll solve(void)
{
	ll a, b, k;
	cin >> k >> a >> b;

	bool ans = false;
	for (ll i = a; i <= b; i++)
		ans |= (i % k == 0);

	cout << (ans ? "OK" : "NG") << endl;

	return 0;
}

int main(void)
{
	while (solve())
	{
	}
	return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i, t;
    long long c=0;
    cin>>t;
    long long n;
    //vector <long long> a(1000000000);
    map<long long, bool> mp;
    for(i=0; i<t; i++)
    {
        cin>>n;
        if(mp.count(n)==0)
        {
            mp[n]=1;
            c=c+1;
        }
        else{

            if(mp[n]==1)
            {
                c--;
                mp[n]=0;
            }
            else if(mp[n]==0)
            {
                mp[n]=1;
                c++;
            }
        }
    }
    cout<<c;

}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> S;
  N=S.size();
  rep(i,0,N)NeOut('x');
  Out("");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 

ll n,k;
ll a[100004];
ll dp[1000000];
ll solve(ll i){
    if(i==0){
        return 2;
    }

    if(dp[i]!=-1) return dp[i];

    for(ll j=0;j<n;j++){
        if(i-a[j]>=0){
            ll t=solve(i-a[j]);
            if(t==2) return dp[i]=1;
        }
    }   
    return dp[i]=2;
}

int main() {
    memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }

    ll dp[n+1][k+1];
    

    if(solve(k)==1){
        cout<<"First"<<endl;
    }
    else{
        cout<<"Second"<<endl;
    }

}


Measured memory_bytes: 11520
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(std::string s) {
  ll ans = 0;
  ll aCnt = 0;
  rep(i, 0, s.size()) {
    if (s[i] == 'A') {
      aCnt++;
    } else {
      if (i < s.size() - 1 && s[i] == 'B' && s[i + 1] == 'C') {
        ans += aCnt;
        i++;
      } else {
        aCnt = 0;
      }
    }
  }
  print(ans);
}

int main() {
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N;
  cin>>N;
  vector<ll> A(N);
  for(ll i = 0LL; i < N; i++) cin>>A[i];
  if(N%2==0){
    vector<ll> v(N);
    v[0]=A[0];
    v[1]=A[1];
    for(ll i = 2LL; i < N; i++){
      if(i%2==0) v[i]=v[i-2]+A[i];
      else v[i]=max(v[i-2],v[i-3])+A[i];
    }
    cout<<max(v[N-1],v[N-2])<<endl;
  }
  else {
    vector<vector<ll>> v(N,vector<ll>(2));
    v[0][0]=0;
    v[0][1]=A[0];
    v[1][0]=A[1];
    v[1][1]=A[1];
    v[2][0]=A[2];
    v[2][1]=A[0]+A[2];
    for(ll i = 3LL;i< N; i++){
      if(i%2==0) {
        v[i][0]=max(v[i-2][0],v[i-3][0])+A[i];
        v[i][1]=v[i-2][1]+A[i];
      }
      else {
        v[i][0]=max(v[i-2][0],v[i-3][1])+A[i];
        v[i][1]=v[i][0];
      }
    }
    cout<<max(v[N-1][0],max(v[N-2][0],v[N-3][1]))<<endl;
  }
}

Measured memory_bytes: 15660
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> a(max(n, m) + 10, {1000000, 0});
  for(int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  auto compare = [](auto const &l, auto const &r) {
    if(l.first != r.first) {
      return l.first < r.first;
    } else if(l.second != r.second) {
      return l.second > r.second;
    } else {
      return false;
    }
  };
  sort(a.begin(), a.end(), compare);

  auto compare2 = [](auto l, auto r) { 
    return l.second < r.second; 
  };
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, decltype(compare2)> que{compare2};
  ll ans = 0;
  auto itr = a.begin();
  for(int i = 0; i < m; i++) {
    while(itr != a.end() && (*itr).first < i + 2) {
      que.push(*itr);
      itr++;
    }
    if(que.empty()) {
      continue;
    }
    ans += que.top().second;
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6820
#include<bits/stdc++.h> 
using namespace std; 
#define deb(x) cout <<"\n"<< (#x) << " = " << (x) << "\n"
#define int long long int

void inputoutput()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
}

void dfs(int src , bool *vis , vector<int> v[])
{
	vis[src]=true;
	// cout<<src<<" ";

	for(auto it : v[src])
	{
		if(!vis[it])
			dfs(it,vis,v);
	}
}

int32_t main()
{
    inputoutput();


   int x,k,d;
   cin>>x>>k>>d ; 
   x=abs(x);

   int hopes=min(k,x/d);
   k=k-hopes;
   x=x-hopes*d;

   if(k%2)
        cout<<d-x;
    else
        cout<<x;
    



    return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
 set<int>s;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int in;
        cin>>in;
        s.insert(in);

    }
    if(s.size()==n)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;


}



Measured memory_bytes: 9600
N = int(input())
min = 0
for i in range(5):
    x = int(input())
    if i == 0:
        min = x
    if min > x :
        min = x
#print("N={} min={}".format(N,min))
if N <= min:
    print(5)
elif N % min == 0:
    print(N // min + 4)
else:
    print(N // min + 5)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<set>
#include<map>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define Sort(a)	sort(a.begin(),a.end())
#define rev(a)	reverse(a.begin(),a.end())
#define all(a)	(a).begin(),(a).end()
#define vll vector<long long int>
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define INF 1e18

#define MAX 200005

using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli power(lli a,lli b,lli m){if(b==0)	return 1;if(b==1)	return a%m;lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli Ceil(lli a,lli b){lli res=a/b;if(a%b!=0)	res++;return res;}

template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

lli dxx[]={1,1,0,-1,-1,-1,0,1};
lli dyy[]={0,1,1,1,0,-1,-1,-1};
lli dx[]={1,0,-1,0};
lli dy[]={0,1,0,-1};

struct pll{
	lli x,y;
};
bool comp(pll a,pll b){
	if(a.x==b.x)	return a.y<b.y;
	else	return a.x<b.x;
}
void solve(lli the)
{
	char ch;
	db aa,bb,cc,dd,xx;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,d,n,m,l,r,x,y,z,low,high,mid,sum=0,ans=0,temp,t;
    cin >> n;
    vll v;
    for(i=3;i<=n;i++){
    	v.pb(i);
    }
    m=v.size();
    lli dp[n+1];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(i=1;i<=n;i++){
    	for(j=0;j<m;j++){
    		x=v[j];
    		if(i-x>=0){
    			dp[i]+=dp[i-x];
    			dp[i]%=M;
    		}
    	}
    }
    cout << dp[n]%M;
    
    
}















int main()
{
	long long int t=1,c=1;
	// scanf("%lld",&t);
	while(t--){
		solve(c);
		c++;
	}
	return 0;
}
/* UJJWAL KESHRI */

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#define inf 1e9

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> state; 
typedef pair<int, state> D;

struct edge{
	int to, cost;
	edge(int a, int b){
		to = a, cost = b;
	}
};

int n, m;
int h[55], c[55];
vector<edge> G1[55], G2[55];
vector<int> vec[1005];
int pos[55];
int dist[55][55][1<<10];

void dijkstra()
{
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 0; k < (1<<10); k++){
				dist[i][j][k] = inf;
			}
		}
	}
	dist[1][1][1] = 0;
	
	state init = make_pair(make_pair(1, 1), 1);
	priority_queue< D, vector<D>, greater<D> > Q;
	Q.push( make_pair(0, init) );
	
	state v; int d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		int p1 = v.first.first, p2 = v.first.second, vis = v.second, mxh = max(h[p1], h[p2]);
		if(dist[p1][p2][vis] < d) continue;
		
		for(int i = 0; i < G1[p1].size(); i++){
			int np = G1[p1][i].to, nvis = vis, cost = G1[p1][i].cost;
			if(h[np] < mxh) continue;
			if(h[np] > mxh){
				cost += c[np];
				nvis = (1<<pos[np]);
			}
			else{
				if((nvis & (1<<pos[np])) == 0) cost += c[np];
				nvis |= (1<<pos[np]);
			}
			state nv = make_pair(make_pair(np, p2), nvis);
			if(dist[np][p2][nvis] > d + cost){
				dist[np][p2][nvis] = d + cost;
				Q.push(make_pair(dist[np][p2][nvis], nv));
			}
		}
		for(int i = 0; i < G2[p2].size(); i++){
			int np = G2[p2][i].to, nvis = vis, cost = G2[p2][i].cost;
			if(h[np] < mxh) continue;
			if(h[np] > mxh){
				cost += c[np];
				nvis = (1<<pos[np]);
			}
			else{
				if((nvis & (1<<pos[np])) == 0) cost += c[np];
				nvis |= (1<<pos[np]);
			}
			state nv = make_pair(make_pair(p1, np), nvis);
			if(dist[p1][np][nvis] > d + cost){
				dist[p1][np][nvis] = d + cost;
				Q.push(make_pair(dist[p1][np][nvis], nv));
			}
		}
	}
}

int main(void)
{
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		
		h[1] = 1, h[n] = 1000, c[1] = c[n] = 0;
		for(int i = 2; i <= n-1; i++) cin >> c[i] >> h[i];
		
		for(int i = 1; i <= 1000; i++) vec[i].clear();
		for(int i = 1; i <= n; i++){
			vec[h[i]].push_back(i);
			pos[i] = vec[h[i]].size()-1;
		}
		
		for(int i = 1; i <= n; i++) G1[i].clear(), G2[i].clear();
		int a, b, c;
		for(int i = 0; i < m; i++){
			cin >> a >> b >> c;
			if(h[a] <= h[b]) G1[a].push_back(edge(b, c));
			if(h[a] >= h[b]) G2[b].push_back(edge(a, c));
		}
		
		dijkstra();
		
		int ans = inf;
		for(int i = 0; i < (1<<(int)vec[1000].size()); i++){
			ans = min(ans, dist[n][n][i]);
		}
		if(ans >= inf) ans = -1;
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 29560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll x;
int main() {
  cin >> x;
  ll ans = 0;
  ll t = max(0LL, x/11-5);
  ans = 2 * t;
  ll y = t * 11;
  ll cur = 0;
  while(true){
    if(y >= x)break;
    if(cur%2 == 0){
      ans++;
      y+=6;
    }else{
      ans++;
      y+=5;
    }
    cur++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
int main(int argc, char const *argv[])
{
	int n,ans = 0;
	cin>>n;
	while(n)
	{
		ans += (n % 10) == 2;
		n /= 10;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
   
void LCS_lenght(char *x, char *y)
{
  int i, j, m, n, c[1001][1001];
  m = strlen(x+1);
  n = strlen(y+1);
  for(i = 1; i <= m; i++)
    c[i][0] = 0;
  for(j = 0; j <= n; j++)
    c[0][j] = 0;
  for(i=1;i<=m;i++)
    for(j=1;j<=n;j++)
      if(x[i]==y[j]) c[i][j] = c[i-1][j-1]+1;
      else if(c[i-1][j] >= c[i][j-1]) c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
  printf("%d\n", c[i-1][j-1]);
}
   
int main()
{
  int i, numberofdataset;
  char x[1001], y[1001];
   
  scanf("%d", &numberofdataset);
   
  for(i = 0; i < numberofdataset; i++)
    {
      scanf("%s", x+1);
      scanf("%s", y+1);
      LCS_lenght(x, y);
    }
  return 0;
}

Measured memory_bytes: 4524
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  int n = s.size();
  string t;
  rep(i, n) if (s[i] != 'x') t += s[i];
  int m = t.size();
  rep(i, m / 2) {
    if (t[i] != t[m - i - 1]) {
      cout << -1 << endl;
      return;
    }
  }
  int ans = 0;
  int l = 0, r = n;
  for (int i = 0; i < (m + 1) / 2; i++) {
    int tl = l;
    while (s[tl] == 'x') tl++;
    int tr = r;
    while (s[tr - 1] == 'x') tr--;
    ans += abs((tl - l) - (r - tr));
    l = tl + 1;
    r = tr - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define MAX5 100010
#define MAX6 1000010
#define pb push_back
#define mp make_pair
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    ll arr[100010][5];
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=3;j++)
        {
            cin>>arr[i][j];
        }
    }
    ll dp[n+5][5];
    for(ll i=1;i<=n+1;i++)
    {
        for(ll j=1;j<=4;j++)
            dp[i][j]=0;
    }
    dp[1][1]=arr[1][1];dp[1][2]=arr[1][2];dp[1][3]=arr[1][3];
    for(ll i=2;i<=n;i++)
    {
        for(ll j=1;j<=3;j++)
        {
            if(j==1)
                dp[i][j]+=max(arr[i][j]+dp[i-1][j+1],arr[i][j]+dp[i-1][j+2]);
            if(j==2)
                dp[i][j]+=max(arr[i][j]+dp[i-1][j-1],arr[i][j]+dp[i-1][j+1]);
            if(j==3)
                dp[i][j]+=max(arr[i][j]+dp[i-1][j-2],arr[i][j]+dp[i-1][j-1]);
        }
    }
    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<'\n';
return 0;
}

Measured memory_bytes: 8064
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin); i < (end); i++)
#define _irep3(i, begin, end) for (register int i = (end)-1; i >= (begin); i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  vector<int> a(5);
  cin >> a;
  int ans = 0;
  int m = 10;
  rep(i, 5) {
    ans += (a[i] + 9) / 10 * 10;
    m = min(m, a[i] % 10 == 0 ? 10 : a[i] % 10);
  }

  out(ans - 10 + m);
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    x: usize
    }
    let ans = if x == 7 || x == 5 || x == 3 {"YES"} else {"NO"};
    println!("{}", ans);
}


Measured memory_bytes: 2128
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
	uint64_t N;
	std::string S;
	std::cin >> N;
	std::cin >> S;

	uint64_t ans = 1;
	for (uint64_t i = 1; i < S.size(); i++) {
		if(S[i] != S[i - 1]) ans++;
	}
	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            long N = input[0] + 1;
            long K = input[1];

            var acum = new long[N];
            acum[0] = N - 1;
            for(int i = 1; i < N; i++)
            {
                acum[i] = acum[i - 1] + N - i - 1;
            }

            var acum2 = new long[N];
            acum2[0] = 0;
            for(int i = 1; i < N; i++)
            {
                acum2[i] += acum2[i - 1] + i;
            }

            long result = 0;
            for(int i = 0; i < N; i++)
            {
                result = ModAdd(result, acum[i] - acum2[i] + 1);
            }

            long minus = 0;
            for(int i = 0; i < K - 1; i++)
            {
                minus = ModAdd(minus, acum[i] - acum2[i] + 1);
            }

            Console.WriteLine($"{ModMinus(result, minus)}");
        }

        static long ModAdd(long a, long b)
        {
            return (a + b) % 1000000007;
        }

        static long ModMinus(long a, long b)
        {
            var c = a - b;

            if (a - b < 0)
            {
                return (c + 1000000007) % 1000000007; 
            }

            return c % 1000000007;
        }
    }
}


Measured memory_bytes: 31440
#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    LL sum = 0;
    unordered_map<LL, LL> ump;
    set<LL> st;
    ump[0]++;
    for(int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        sum += a;
        ump[sum % m]++;
        st.insert(sum % m);

    }

    LL res = 0;
    for(auto it = st.begin(); it != st.end(); ++it) {
        res += (ump[*it] * (ump[*it] - 1)) / 2;

    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6540