akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  ll x, k, d;
  cin >> x >> k >> d;
  if (x < 0) {
    x *= -1;
  }
  ll c = x / d;  // kaisuu
  if (c > k) {
    cout << x - k * d << endl;
    return 0;
  }
  ll na = x / d;
  ll a = x % d;
  ll nb = na + 1;
  ll b = a - d;
  // cout << na << " " << a << endl;
  // cout << nb << " " << b << endl;
  if ((k - na) % 2 == 0) {
    cout << a << endl;
  } else {
    cout << -b << endl;
  }
}


Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	int n;
	cin >> n;
	ll a[N], b[N];
	rep(i, n + 1) cin >> a[i];
	rep(i, n) cin >> b[i];

	ll ans = 0;
	rep(i, n) {
		if(a[i] <= b[i]) {
			ans += a[i];
			b[i] -= a[i];
		}
		else {
			ans += b[i];
			b[i] = 0;
		}
		if(b[i] > 0) {
			ans += min(b[i], a[i + 1]);
			a[i + 1] = max(a[i + 1] - b[i], 0ll);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
string s = "-";

bool check(int l, int r) {
    while (l<r) {
        if (s[l]!=s[r]) return false;
        l++; r--;
    }
    return true;
}

int main(void) {
    string t;
    cin >> t;
    s += t;
    int n = (int)s.size()-1;
    if (check(1, n) && check(1, (n-1)/2) && check((n+3)/2, n)) puts("Yes");
    else puts("No");


	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Abacus
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean f = true;
		while(sc.hasNext()){
			if(!f)System.out.println();
			f = false;
			int x = sc.nextInt();
			int[] a = new int[5];
			for(int i=0;i<5;i++){
				a[i] = x%10;
				x/=10;
			}
			for(int i=4;i>=0;i--)System.out.print(a[i]>=5?" ":"*");
			System.out.println();
			for(int i=4;i>=0;i--)System.out.print(a[i]>=5?"*":" ");
			System.out.println("\n=====");
			for(int i=0;i<5;i++){
				for(int j=4;j>=0;j--){
					System.out.print(a[j]%5==i?" ":"*");
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>

using namespace std;
int main(void) {
	int N;
	cin >> N;
	int buf = 0;
	for (int i = 0; i <= 10; i++) {
		if (1000 * i < N && N <= 1000 * (i + 1)) {
			int buf = i+1;
			int Ans = (1000 * buf) - N;
			cout << Ans << endl;
			break;
		}
	}
	

}

Measured memory_bytes: 3580
class Solution:

    def check(self):
        s = input()
        if s[0] != "A":
            return 'WA'
        if s[2:len(s) - 1].count("C") != 1:
            return "WA"
        ncount = 0
        for i in s:
            if "A" <= i <= "Z":
                ncount += 1
        if ncount > 2:
            return "WA"
        return "AC"


print(Solution().check())


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
s = [list(input().strip()) for _ in range(h)]
# print(s)

R = [[0]*w for _ in range(h)]
L = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]

for i in range(h):
    cur = 0
    for j in range(w-1,-1,-1):
        if s[i][j] == '#':
            cur = 0
        else:
            cur += 1
        R[i][j] = cur

for i in range(h):
    cur = 0
    for j in range(w):
        if s[i][j] == '#':
            cur = 0
        else:
            cur += 1
        L[i][j] = cur

for j in range(w):
    cur = 0
    for i in range(h):
        if s[i][j] == '#':
            cur = 0
        else:
            cur += 1
        D[i][j] = cur

for j in range(w):
    cur = 0
    for i in range(h-1,-1,-1):
        if s[i][j] == '#':
            cur = 0
        else:
            cur += 1
        U[i][j] = cur

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] =='#':
            continue
        ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)

Measured memory_bytes: 359408
n = int(input())
w_s = list(map(int, input().split()))

ans = 100
for i in range(100):
    g1 = w_s[:i]
    g2 = w_s[i:]
    g1s, g2s = sum(g1), sum(g2)

    t = max(g1s-g2s, g2s-g1s)

    ans = min(ans, t)

print(ans)

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

#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int MOD = 1000000007;

int n, k;
int a[101];
ll dp[101][100001];

ll pre[101][100001];

int main() {
    IOS;
    memset(dp, -1, sizeof(dp));
    cin >> n >> k;
    rep(i, n) cin >> a[i];

    for(int i = 0; i < n; i++) {
        dp[i][0] = 1;
        pre[i][0] = 1;
    }

    for(int i = 1; i <= k; i++) {
        for(int j = 0; j < n; j++) {
            if(j == 0) {
                if(a[j] >= i) dp[j][i] = 1;
                else dp[j][i] = 0;
            } else {
                if(a[j] >= i) dp[j][i] = pre[j - 1][i];
                else dp[j][i] = pre[j - 1][i] - pre[j - 1][i - a[j] - 1];
            }
            dp[j][i] %= MOD;
            pre[j][i] = pre[j][i - 1] + dp[j][i];
            //dp[i][j] %= MOD;
            //pre[j][i] %= MOD;
        }
    }
    /*for(int i = 0; i < n; i++) {
        for(int j = 0; j <= k; j++) {
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }
    cout << "\n\n";
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= k; j++) {
            cout << pre[i][j] << " ";
        }
        cout << "\n";
    }*/
    cout << dp[n - 1][k] % MOD;
    return 0;
}

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

int N, K;

void solve(){

    if( K > (N-1)*(N-2)/2 ){ cout << -1 << endl; return; }

    int M;
    int additionaledge = (N-1)*(N-2)/2 - K;
    M = (N-1) + additionaledge;
    cout << M << endl;

    for( int i = 2; i <= N; i++ ){
        cout << 1 << " " << i << endl; 
    }

    int j = 2, k = 2;
    for( int i = 0; i < additionaledge; i++ ){
        if( k == N ) k = ++j + 1;
        else k++;
        cout << j << " " << k << endl;
    }
}

int main(){

    cin >> N >> K;

    solve();
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
count = 0
i = 0
while True:
    if a[i] % 2 != 0:
        break
    else:
        a[i] = a[i]/2
    i += 1
    if i+1 == n:
        count += 1
        i = 0
print(count)

Measured memory_bytes: 38640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
int D[200001],T[200001];
int memo[200001];
int* binary_search_a(int* array, size_t size, int value)
{
	int lower, upper, mid;

	lower = 0;     /* 探索範囲の下限の添字 */
	upper = size;  /* 探索範囲の上限の添字 + 1 */

	while( lower < upper ){  /* 上限と下限が逆転したら終わり */

		/* 中央の位置を求める */
		mid = (lower + upper) / 2;

		if( array[mid] < value ){
			lower = mid + 1;  /* 次は中央より後ろを調べるため、下限を変更 */
		}
		else{
			/* ここに来るケースには、目的の値と同じ場合を含んでいる */
			/* そのため、upper = mid - 1; ではない */
			upper = mid;  /* 次は中央より手前を調べるため、上限を変更 */
		}
	}

	/* 目的の値を発見している場合も、発見できなかった場合も、
	   ここに来ることになるので、ここで最終的な確認を行う。
	   lower == upper は、array が空の場合への備え。 */
	if (lower == upper && array[lower] == value){
		int tmp = lower+memo[lower];
		if(array[tmp]==value){
			memo[lower]++;
			return &array[lower];
		}
	}

	return NULL;
}
int main(){
	int N;
	cin>>N;
	rep(i,N){
		cin>>D[i];
	}
	int M;
	cin>>M;
	rep(i,M){
		cin>>T[i];
	}
	sort(D,D+N);
//	sort(T,T+M);
	rep(i,M){
			int *p;
			p=binary_search_a(D,N,T[i]);
			if(p==NULL){
				cout<<"NO"<<endl;
				return 0;
			}
	}
/*	rep(i,M){
		rep(j,N){
			if(T[i]==D[j]){
				D[j]=-1;
				goto ok;
			}
		}
		goto fal;
	ok:;
	}*/
	cout<<"YES"<<endl;
	return 0;
//	fal:
//	cout<<"NO"<<endl;
//	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(void) {
	int n, p[20], ans = 0;

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

	for (int i = 2; i < n; ++i) {
		if ((p[i - 2] < p[i - 1] && p[i - 1] < p[i] )||
			(p[i] < p[i - 1] && p[i - 1] < p[i - 2])) {
			++ans;
		}
	}
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
#!usr/bim/python
#! -*- coding: utf-8 -*-

n_k = raw_input()
n_k = n_k.split()
n_k = map(int,n_k)
n = n_k[0]
k = n_k[1]

l = raw_input()
l = l.split()
l = map(int,l)

ans = 0
i = 0
while i < k:
    max_len = max(l)
    ans += max_len
    l[l.index(max_len)] = 0
    i += 1

print ans


Measured memory_bytes: 2568
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}

ll Q;

bool hantei(vector<ll> p, int i, int j) {

	vector<ll> q(p.size());

	rep(k, p.size()) {
		if (k == i)
			q[k] = p[j];
		else if (k == j)
			q[k] = p[i];
		else
			q[k] = p[k];
	}

	rep(k, p.size()-1) {
		if (q[k] > q[k + 1])
			return false;
	}

	return true;
}

int main() {

	ll N;
	cin >> N;
	vector<ll> p(N);

	rep(i, N)
		cin >> p[i];



	
	bool flag = false;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {

			flag = hantei(p, i, j);
			if (flag == true) {
				cout << "YES" << endl;
				return 0;
			}
			
			
			
			}
	}

	cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    int num = 0;
    for(int i = 0; i < s.size(); i++){
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            num++;
        }else if ((s[i] != 'A' && s[i] != 'C' && s[i] != 'G' && s[i] != 'T') && num != 0) {
            num = 0;
        }
        if (ans < num) {
            ans = num;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S; cin >> S;
  int win = 0;
  for(char c:S) {
    if(c == 'o') ++win;
  }
  printf("%s\n", win+(15-S.size())>=8?"YES":"NO");
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readString().toCharArray().sorted().joinToString()
    val t = readString().toCharArray().sorted().reversed().joinToString()
    if (s < t) {
        println("Yes")
    } else {
        println("No")
    }
}

// Tools
fun readString() = readLine()!!

Measured memory_bytes: 40012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  ll n,p;
  cin >> n >> p;
  if(n == 1){
    cout << p << endl;
    return 0;
  }
  map<ll,ll> mp;
  ll range = p;
  for(ll i=2;i*i<=range;i++){
    while(p%i == 0){
      mp[i] ++;
      p /= i;
    }
  }
  ll ans = 1;
  for(auto p : mp){
    while(p.second >= n){
      p.second -= n;
      ans *= p.first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, k = map(int, input().split())
ab = [readints() for _ in range(n)]
# print(ab)
abab = sorted(ab)
# print(abab)
tmp = 0
for i in range(n):
    tmp += abab[i][1]
    if tmp >= k:
        print(abab[i][0])
        break


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

struct UF{
  vector<int> par;
  vector<int> sizes;
  
  UF(int N):sizes(N,1),par(N){
    for(int i=0;i<N;i++) par[i] = i;
  }
  
  int root(int x){
    if(par[x] == x) return x;
    else{
      return par[x] = root(par[x]);
    }
  }
  
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx == ry) return;
    else if(size(rx) < size(ry)){
      par[rx]=ry;
      sizes[ry] += sizes[rx];
      return;
    }
    else{
      par[ry]=rx;
      sizes[rx] += sizes[ry];
      return;
    }
  }
  
  bool same(int x,int y){
    int rx=root(x);
    int ry=root(y);
    return rx == ry;
  }
  
  int size(int x){
    return sizes[root(x)];
  }
};

int main(){
  int N,M;
  cin>>N>>M;
  int u[M],v[M];
  for(int i=0;i<M;i++){
    cin>>u[i]>>v[i];
    u[i]--;
    v[i]--;
  }
  UF tree(N);
  long long int ans[M];
  long long int c=N;
  c *= (N-1);
  c /= 2;
  ans[M-1]=c;
  for(int i=M-1;i>0;i--){
    if(tree.same(u[i],v[i])){
      ans[i-1]=ans[i];
    }
    else{
      long long int p=tree.size(u[i])*tree.size(v[i]);
      ans[i-1]=ans[i]-p;
      tree.unite(u[i],v[i]);
    }
  }
  for(int i=0;i<M;i++){
    cout<<ans[i]<<endl;
  }
}
    

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define vi vector < ll  int >
#define CLR(a) memset((a),0,sizeof(a))
#define mp make_pair
#define hell 1000000007`
using namespace std;

void solve()
{
 double i,j,k,y=0,ans=0,n,m,x,z,a,b;
 cin>>n;
 vector < double > v(n);
 rep(i,0,n) cin>>v[i];
 rep(i,0,n)
  {
      y+=(1.000000000/v[i]);
  }
  cout<<fixed<<setprecision(12)<<1.0000000000000/y;


}



   signed main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
             solve();
        }


Measured memory_bytes: 256
a = [0]*5
for i in range(5):
    a[i] = int(input())
k = int(input())

flag = True
for j in range(5):
    for l in range(j+1, 5):
        if abs(a[j] - a[l]) > k:
            flag = False

if flag:
    print('Yay!')
else:
    print(':(')


Measured memory_bytes: 38256
// AOJ 0653 Sugoroku and Pieces
// 2019.3.28 bal4u

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

int X[105]; int N;
char map[2020];

int main()
{
	int i, M;

	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", X + i);
		map[X[i]] = 1;
	}
	scanf("%d", &M);
	while (M--) {
		scanf("%d", &i);
		if (X[i] < 2019 && map[X[i]+1] == 0) {
			map[X[i]] = 0;
			X[i]++;
			map[X[i]] = 1;
		}
	}
	for (i = 1; i <= N; i++) printf("%d\n", X[i]);
	return 0;
}


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

int main() {
int n;
cin >> n;
int m;
cin >> m;
if(4*n>=m && m%2==0 && m>=2*n)
{
	cout << "Yes" << endl;
}
else 
{
	cout << "No" << endl;
}
	return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int d;
	cin >> d;
	if (d == 25) cout << "Christmas" << endl;
	if (d == 24) cout << "Christmas Eve" << endl;
	if (d == 23) cout << "Christmas Eve Eve" << endl;
	if (d == 22) cout << "Christmas Eve Eve Eve" << endl;

	return 0;
}


Measured memory_bytes: 256
def bb
    s = gets.chomp

    for i in 0..(s.length-1)
        c = s[i]
        next if c == 'U'
        next if c == 'D'
    if i%2 == 0
            next if c == 'R'
            puts 'No'
            exit
        else
            next if c == 'L'
            puts 'No'
            exit
        end
    end

    puts 'Yes'
end

bb


Measured memory_bytes: 3836
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double

using namespace std;

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

const int MOD = 998244353;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


bool change[101];
void solve() {
	string S; cin >> S;
	set<char>st;
	REP(i, S.size()) {
		st.insert(S[i]);
	}
	
	int cnt = 0;
	int K; cin >> K;
	int N = S.size();
	FOR(i, 1, N) {
		if (S[i] == S[i - 1]) {
			change[i] = true;
			cnt++;
			i += 1;
		}
	}
	if (st.size() == 1 && S.size() % 2 == 1) {
		ll ans = cnt * K;
		ans += (K / 2);
		print(ans); return;
	}
	ll ans = cnt * K;
	if (S[N - 1] == S[0] && !change[N - 1]) {
		int l = 0;
		REP(i, N) {
			if (S[i] == S[0]) {
				l++;
			}
			else break;
		}
		if (l % 2 == 1) {
			ans += K - 1;
		}
	}
	print(ans);

}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	solve();
}


Measured memory_bytes: 256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long n, d;
    scan(n, d);
    long cnt;
    foreach (_; 0 .. n)
    {
        long x, y;
        scan(x, y);

        if (x ^^ 2 + y ^^ 2 <= d ^^ 2)
        {
            cnt += 1;
        }
    }
    writeln(cnt);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 8716
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  ll n;
  cin >> n;
  set<ll> yaku;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      yaku.insert(i);
      yaku.insert(n/i);
    }
  }
  yaku.erase(n);
  ll sum = 0;
  for (auto x : yaku) {
    // debug(x);
    if((n-x) % x == 0) {
      ll m = (n-x)/x;
      if(n/m == n%m) {
        sum += (n-x)/x;
      }
    }
  }
  cout << sum << endl;


  return 0;
}


Measured memory_bytes: 640
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    // input from txt （提出時にこの箇所は削除すること）
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    int N,n=0,m=1000000000;
    cin>>N;
    for(int i=0;i<N;i++){
        int A;
        cin >>A;
        for(int j=0;A%2==0;j++){
            A=A/2;
            if(j<m){
                n=j+1;
            }
            else{
                break;
            }
        }
        m=n;
    }
    cout<<m<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int d[n];
    for (int i=0; i<n; i++)cin>>d[i];
    sort(d, d+n);
    int m;
    cin>>m;
    int t[m];
    for (int i=0; i<m; i++)cin>>t[i];
    sort(t, t+m);
    int i,j,k=0;
    for (i=0; i<m; i++) {
        for (j=k; j<n; j++) {
            if(t[i]==d[j]){
                k=j+1;
                break;
            }
        }
        if(j==n){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 1792
-- taro
p1 n x i =
  let m = (n-1) `mod` 5
      n'= n - m
  in
    n':(p2 n' x i)
-- jiro
p2 1 _ _ = [0]
p2 n x i =
  let m = x!!i
      n'= n - m
      i'= (i + 1) `mod` (length x)
  in
    n':(p1 n' x i')

ans ([0]:_) = []
ans ([_]:x) =
  let d = head x
      r = drop 1 x
  in
    (p1 32 d 0):(ans r)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c
      o = ans i
  mapM_ print $ concat o

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;
 
 
int main(){
    int n; cin >> n;
    n%=10;
    if(n==3) cout << "bon" << endl;
    else if((n==0) || (n==1) || (n==6) || (n==8)) cout << "pon" << endl;
    else cout << "hon" << endl;
return 0;
}

Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
int n,m,x;
int main() {
    while (cin >> n >> m, n) {
        vector<int> c(m);
        vector<vector<int>> dp(256, vector<int>(n + 1, MOD));
        // dp[Ynの値][i番目のサンプル数]
        dp[128][0] = 0; // Y0 = 128
        rep(i, m) cin >> c[i];
        req(i, n) {// DPテーブルが0の時に処理を行ってしまうと、最小値になる
            cin >> x;
            rep(j, 256) {
                rep(k, m) {
                    int u = max(min(j + c[k],255),0);
                    dp[u][i] = min(dp[u][i],(x - u)*(x - u) + dp[j][i - 1]);
                }
            }
        }
        int ans = 1 << 30;
        rep(i, 256) ans = min(ans, dp[i][n]);
        cout << ans << endl;
    }
}


Measured memory_bytes: 22896
#include<stdio.h>
int main()
{
    int xBox[101],yBox[101];
    int N,M;
    int X,Y; //位置
    int i,j,k;

    // 整数の入力
   scanf("%d %d %d %d", &N, &M, &X, &Y);

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

    //判定
   for(i=X+1;i<=Y;i++){
    //x
    for(j=0;j<N;j++){
       if(xBox[j]<i) {
            //nothing
       } else {
            break;
       }
    }
    if(j<N){
        //printf("%d %d\n",j ,i);
        continue;
    }
    
    for(k=0;k<M;k++){
       if(yBox[k]>=i) {
            //nothing
       } else {
            break;
        }
   }
   
    if(k<M){
         //printf("War\n");
    } else{
         printf("No War\n");
         break;
    }  
   }
   
   if(i<=Y){
    //         printf("War\n");
   }else{
         printf("War\n");
   
   }



    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

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

    std::map<std::string, std::pair<long long, long long>> map;
    for (int i = 0; i < n; i++) {
        std::string s;
        std::cin >> s;

        std::sort(s.begin(), s.end());
        map[s].second += map[s].first;
        map[s].first++;
    }

    long long ans = 0;
    for (auto t : map) {
        ans += t.second.second;
    }

    std::cout << ans << std::endl;
}


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

int main(){
    int n,q;
    string s;
    cin >> n >> q >> s;
    vector<int> a(n+10,0);
    if(s[0] == 'A' && s[1] == 'C') a[0] = 1;
    for(int i = 1; i < s.size()-1; i++){
        a[i] = a[i-1];
        if(s[i] == 'A' && s[i+1] == 'C'){
            a[i]++;
        }
    }
    vector<pair<int,int>> lr(q+10,make_pair(0,0));
    for(int i = 1; i <= q; i++){
        cin >> lr[i].first >> lr[i].second;
    }
    for(int i = 1; i <= q; i++){
        cout << a[lr[i].second-2]-a[lr[i].first-2] << endl;
    }
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
  int64_t n;
  cin >> n;

  string s;
  cin >> s;
  vector<int64_t> t(n);
  unordered_map<char, int64_t> um = {{'R', 1}, {'G', 2}, {'B', 4}};
  for (auto i : irange(0L, n)) {
    t[i] = um[s[i]];
  }

  int64_t ans = 0;
  array<int64_t, 8> dp = {};
  dp[0] = 1;
  for (auto i : irange(0L, n)) {
    decltype(dp) next = dp;
    for (auto k : irange(0L, 8L)) {
      if ((k & t[i]) == 0) {
        next[k | t[i]] += dp[k];
      }
    }

    dp = next;

    for (auto j : irange(0L, i) | reversed) {
      if (i + (i - j) >= n) {
        break;
      }

      if ((t[j] | t[i] | t[i + (i - j)]) == 7) {
        --ans;
      }
    }
  }

  ans += dp[7];
  cout << ans << endl;
}

Measured memory_bytes: 3676
<?php
$n = (int)trim(fgets(STDIN));

// 奇数*奇数は奇数なので、2*5を含まない
if ($n % 2 == 1 || $n <= 8) {
	echo 0;
	exit();
}

// 偶数の場合、全ての数に2が含まれるので、5の倍数のみカウントする
$cnt = 0;
$base = 10;
while ($n % $base !== 0) {
	$n -= 2;
}
while ($base <= $n) {
	// echo $base . PHP_EOL;
	$cnt += (int)($n / $base);
	$next = $base * 5;
	while ($n % $next !== 0) {
		$n -= $base;
	}
	$base = $next;
}


echo $cnt;


Measured memory_bytes: 4856
def main():
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    bcs = [[int(i) for i in input().split()] for _ in range(M)]
    A.sort()
    bcs.sort(reverse=True,key=lambda c:c[1])

    cards = []
    for b,c in bcs:
        for i in range(b):
            cards.append(c)
            if len(cards) == N:
                break
        if len(cards) == N:
            break

    from itertools import zip_longest
    ans = 0
    for a,card in zip_longest(A,cards,fillvalue=0):
        if a < card:
            ans += card
        else:
            ans += a
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 26988
#include<bits/stdc++.h>
using namespace std;
const int K = 110, N = 1010;

int a[K],n,k;
int ret[N], curlen;

inline bool check(){
	int mn=a[1], mx=a[1];
	for(int i=1;i<=k;i++)mx=max(mx,a[i]), mn=min(mn,a[i]);
	return mn*2>=mx;
}
int vis[K];

inline void merge(int *x,int *y,int *z,int len1,int len2){
	int i=1,j=1;
	int l=0;
	while(i<=len1&&j<=len2){
		if(x[i]<y[j])z[++l]=x[i++];
		else z[++l]=y[j++];
	}
	while(i<=len1)z[++l]=x[i++];
	while(j<=len2)z[++l]=y[j++];
}

int b[K], x[K], y[K], z[K], l1, l2, l3;

vector<int> solve_ext(int len){
	l1=l2=l3=0;
	for(int i=1;i<=k;i++)vis[i]=0,b[i]=a[i];
	for(int i=0;i<k-len;i++){
		vis[ret[curlen-i]]=curlen-i;
	}
	for(int i=1;i<=k;i++){if(!vis[i])b[i]--;if(b[i]<0)return vector<int>(1,k+1);}
	int mn,mx;mn=mx=b[1];
	for(int i=1;i<=k;i++){
		mn=min(mn, b[i]);
		mx=max(mx, b[i]);
	}
	if(mn*2>=mx){
		vector<int> ret;
		for(int i=1;i<=k;i++)if(!vis[i])ret.push_back(i);
		return ret;	
	}
	else if(mn*2+1==mx){
		vector<int> res;
		for(int i=1;i<=k;i++)if(!vis[i] && b[i]==mx)x[++l1]=i;
		for(int i=1;i<=k;i++)if(!vis[i] && b[i]==mn)x[++l1]=i;
		for(int i=1;i<=k;i++)if(!vis[i] && b[i]!=mx && b[i]!=mn)y[++l2]=i;
		merge(x,y,z,l1,l2);l3=l1+l2;
		res=vector<int>(z+1,z+l3+1);
		int p1=0,p2=0;
		for(int i=curlen-(k-len-1);i<=curlen;i++){
			if(b[ret[i]]==mx)p1=i;
			if(b[ret[i]]==mn&&!p2)p2=i;
		}
		for(int i=1;i<=l3;i++){
			if(b[z[i]]==mx)p1=i+curlen;
			if(b[z[i]]==mn&&!p2)p2=i+curlen;
		}
		if(p1<p2)return res;
		else return vector<int>(1,k+1);
	}else
		return vector<int>(1,k+1);
}

bool cmp(vector<int> a, vector<int> b){
	for(size_t i=0;i<a.size();i++){
		if(i>=b.size())return 1;
		if(a[i]>b[i])return 1;
		if(a[i]<b[i])return 0;
	}
	return 0;
}

inline void extend(){
	vector<int> ext(1,k+1);
	for(int extlen=1;extlen<=k&&curlen+extlen<=n;extlen++){
		int d=k-extlen;
		if(curlen-d+1>=1){
			vector<int> nw=solve_ext(extlen);
			if(cmp(ext,nw))ext=nw;
		}
	}
	for(size_t i=0;i<ext.size();i++){
		printf("%d ",ext[i]);
		ret[++curlen]=ext[i];
		a[ext[i]]--;
	}
	return ;
}

int main()
{
	cin >> k;
	for(int i=1;i<=k;++i)scanf("%d",&a[i]),n+=a[i];
	if(!check()){
		puts("-1");
		return 0;
	}
	while(curlen<n){
		extend();
	}puts("");
}

Measured memory_bytes: 3796
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

int n,a,b;

int dp[31][1000001]={};
int d[31][1000001]={};

const ll INF=100000000001;
int main() {
	int c;

	cin>>n;

	int n1=n%10;
	int n2=(n/10)%10;
	int n3=(n/100)%10;
	int n4=n/1000;
	if((n2==n3)&&((n1==n2)||(n3==n4))){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  bool flag = false;
  for (int i = 0; 4*i <= n; i++){
    for (int j = 0; j*7 <= n; j++){
      if (4*i + 7*j == n)
        flag = true;
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
g, p = 0, 0
score = 0
mp = {'p' : {'p' : 0, 'g' : 1}, 'g' : {'p' : -1, 'g' : 0}}
for c in s:    
    if p < g:
        p += 1
        a = 'p'
    else:
        g += 1
        a = 'g'
    score += mp[a][c]
print(score)
    


Measured memory_bytes: 3316
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,d[100001];
	scan(N);
	rep(i,N){
		scan(d[i]);
	}
	sort(d,d+N);
	prin(d[N/2]-d[N/2-1]);
	return 0;
}


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



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,i=0,ans=0;
    cin>>n;

    vector<int> a(n);
    vector<bool> v(n,false);

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

    while(true){
        if(v[i]){
            ans=-1;
            break;
        }else if(a[i]==2){
            ans++;
            break;
        }
        v[i]=true;
        i=a[i]-1;
        ans++;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range 100010
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
int per[range], a[range];

bool sortby(int i, int j){
	return a[i] >= a[j];
}
int n;
set <int > pos;
int main(){

 //   freopen("input.txt","r",stdin);
    IOS;
    clock_t clk = clock();
    cin>>n;

    forn(i,n)cin>>a[i];
    forn(i,n)per[i] = i;	

    sort(per, per+n, sortby);
    ll ans = 0;
    pos.insert(-1);
    pos.insert(n);
    pos.insert(per[0]);
    forn1(i,n - 1){
    	//rr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;

    	int t = per[i];
    	auto temp = pos.begin();
    	temp = pos.insert(temp, t);

    	auto up = temp, down = temp;
    	up++;
    	down--;

    	int uper = *up;
    	int low = *down;
    	if(uper != n){
    		auto up1 = ++up;
    		ll a1 = *up1 - uper ;
    		ll a2 =  t - low ;
    		ans += a1*a2*a[t];
    	}

    	if(*down != -1){
    		auto down1 = --down;
    		ll a1 = low - *down1 ;
    		ll a2 = uper - t ;
    		ans += a1*a2*a[t];
    	}
    	
    }

    cout<<ans;
    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int H,W;
vector<vector<char>> vec(110,vector<char>(110));
vector<vector<int>> ret(110,vector<int>(110,-1));
vector<int> dy = {0,1};
vector<int> dx = {1,0};

void dfs() {
    if(vec.at(0).at(0) == '#') {
        ret.at(0).at(0) = 1;
    }
    else {
        ret.at(0).at(0) = 0;
    }
    queue<P> que;
    que.push(P(0,0));
    while(!(que.empty())) {
        P p = que.front();
        que.pop();
        for(int i = 0;i < 2;i++) {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(ny < H && nx < W) {
                int cnt = ret[p.first][p.second];
                if(vec[p.first][p.second] == '.' && vec[ny][nx] == '#') {
                    cnt++;
                }
                if(cnt < ret[ny][nx] || ret[ny][nx] == -1) {
                    que.push(P(ny,nx));
                    ret[ny][nx] = cnt;
                }
            }
        }
    }
}

int main() {
    cin >> H >> W;
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            cin >> vec.at(i).at(j);
        }
    }
    dfs();
    cout << ret[H - 1][W - 1] << endl;
}

Measured memory_bytes: 256
#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 rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

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 = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL 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);

    string s;
    cin >> s;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == ',') s[i] = ' ';

    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    ll l;
    cin>>n;
    cin>>l;
    string s[n];
    for(int i=0;i<n;i++) cin>>s[i];
    sort(s,s+n);
    for(int i=0;i<n;i++) cout<<s[i];
    return 0;
}


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

int main(void)
{
  int N;
  cin >> N;
  string S;
  cin >> S;
  int sum = 0;
  
  for (int i=0;i<N-2;i++){
    if (S.at(i)=='A' && S.at(i+1)=='B' && S.at(i+2)=='C'){
      sum++;
    }
  }
  
  cout << sum << endl;
  
  return 0;
}
 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int D = int.Parse(s[0]);
            int G = int.Parse(s[1]);
            List<int[]> list = new List<int[]>();
            for(int i = 0; i < D; i++)
            {
                int[] xz = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                list.Add(xz);
            }

            int min = int.MaxValue;
            int n = (int)Math.Pow(2, D);
            for (int i = 0; i < n; i++)
            {
                int k = i, counter = 0, countProblems = 0;
                int sum = 0;
                List<int> plist = new List<int>();
                while (counter < D)
                {
                    int[] v = list[counter];
                    if (k % 2 == 1)
                    {
                        sum += v[0] * (counter + 1) * 100 + v[1];
                        countProblems += v[0];
                    }
                    else
                    {
                        plist.AddRange(Enumerable.Repeat((counter + 1) * 100, v[0] - 1));
                    }
                    k /= 2;
                    counter++;

                }
                plist.Reverse();
                if (sum < G)
                {
                    foreach (int p in plist)
                    {
                        sum += p; countProblems++;
                        if (sum >= G) break;
                    }
                }
                if (sum >= G && countProblems < min) min = countProblems;
            }
            Console.WriteLine(min);

        }
    }
}


Measured memory_bytes: 15572
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

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

int main(void){
	int H,W;
	string s[52];
	bool can=true;
	scanf("%d%d",&H,&W);
	rep(i,H){
		cin>>s[i];
	}
	rep(i,H){
		rep(j,W){
			if(s[i][j]=='#'){
				int exist=0;
				rep(k,4){
					if(i+dy[k]>=0 &&
					i+dy[k]<=H-1 &&
					j+dx[k]>=0 &&
					j+dx[k]<=W-1 &&
					s[i+dy[k]][j+dx[k]]=='#'){
						exist++;
					}
				}
				if(exist==0){
					can=false;
					break;
				}
			}
		}
		if(!can)break;
	}
	if(can){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x.at(i);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += 2 * min(abs(x.at(i) - 0), abs(x.at(i) - k));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int N;
vector<string> ans;
void DFS(string s,int a) {
  if (s.size() == N) {
    ans.push_back(s);
    return;
  } else {
    for (int i = 0; i < a + 1; i++) {
      char c = 'a' + i;
      s += c;
      if (i == a) {
        DFS(s,a+1);
      } else {
        DFS(s,a);
      }
      s.pop_back();
    }
  }
}  

int main() {
  cin >> N;
  DFS("a",1);
  sort(ans.begin(),ans.end());
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl; 
  }
  return 0;
}

Measured memory_bytes: 9332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; ll A,B; cin >> N >> A >> B;
	V<ll> X(N); rep(i,N) cin >> X[i];
	ll ans = 0;
	rep(i,N-1) ans += min((X[i+1]-X[i])*A,B);
	cout << ans << endl;
}


Measured memory_bytes: 1024