akhauriyash/Code-Regression huggingface dataset:
use std::io::*; //Not mine.
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
use std::collections::HashMap;
fn main() {
    let n: usize = read();
    let mut mp: HashMap<i64, i64> = HashMap::new();
    for i in 0..n {
        let a: i64 = read();

        if (mp.contains_key(&a)) {
            let mut s = mp[&a];
            mp.insert(a, s + 1);
        } else {
            mp.insert(a, 1);
        }
    }
    let mut ans:i64 = 0;
    for (key, value) in &mp {
        if(key > value){
            ans += (value).abs();
        }else{
            ans += (key - value).abs();
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5524
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        List<String> nList = Arrays.asList(n.split(""));
        long sum = 0;
        for (int i = 0; i < n.length(); i++) {
            sum += Long.parseLong(nList.get(i));
        }
        if (Long.parseLong(n) % sum == 0) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 23764
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		long s = scanner.nextLong();
		long c = scanner.nextLong();
		long ans = 0;
		
		if(2 * s <= c){
			// まず、sピース全て使える場合。
			ans += s;
			c -= s * 2;
			s = 0;
			ans += c / 4;
		} else {
			// sピースが余る
			ans += c / 2;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 22100
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef unsigned long long int ll;

struct numberNode{
	int a;
	ll b;
};

bool comp(numberNode LHS,numberNode RHS){
	return LHS.a < RHS.a;
}


int main()
{
	int n;
	ll k;
	cin>>n>>k;
	map<int,ll> bigArray;
	for(int i = 0; i < n; i++){
		int a;
		ll b;
		cin>>a>>b;
		if(bigArray.count(a)==0){
			bigArray.insert(make_pair(a,b));
		}else{
			bigArray[a] += b;
		}
	}
	vector<numberNode> bigVector;
	for(auto iter = bigArray.begin(); iter != bigArray.end(); iter++){
		numberNode localNode;
		localNode.a = iter->first;
		localNode.b = iter->second;
		bigVector.push_back(localNode);
	}
	sort(bigVector.begin(),bigVector.end(),comp);
	for(auto iter = bigVector.begin(); iter!= bigVector.end();iter++){
		if( k <= iter->b){
			cout<<iter->a<<endl;
			break;
		}else{
			k = k - iter->b;
		}
	}
	return 0;
}


Measured memory_bytes: 7692
import math

k=int(input())
tochu={}
for i in range(1,k+1):
    for q in range(1,k+1):
        res=math.gcd(i,q)
        if res in tochu:
            tochu[res]+=1
        else:
            tochu[res]=1

ans=0
for i in range(1,k+1):
    for ele in tochu:
        ans+=math.gcd(i,ele)*tochu[ele]
print(ans)

Measured memory_bytes: 9232
n=int(input())
hl=list(map(int,input().split()))
mx=0
count=0
for i in range(n-1):
    if hl[i]>=hl[i+1]:
        count+=1
    else:
        mx=max(mx,count)
        count=0
mx=max(mx,count)
print(mx)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  int n,w[110],sum = 0;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> w[i];
    sum += w[i];
  }
  
  int mi = 100000;
  for(int t = 0; t < n-1; t++) {
    int s1 = 0;
    for(int j = 0; j <= t; j++) {
      s1 += w[j];
    }
    int s2 = sum -s1;
    mi = min(mi, abs(s1-s2));
  }
 
  cout << mi << endl;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

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

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, N);

    vector<i64> a(N);
    read(a);

    i64 ans = LINF;
    rep(hoge, 0, 2) {
        i64 sum = 0;
        i64 cnt = 0;
        rep(i, 0, N) {
            sum += a[i];
            if (i & 1) {
                if (sum <= 0) {
                    cnt += 1 - sum;
                    sum = 1;
                }
            } else {
                if (sum >= 0) {
                    cnt += abs(-1 - sum);
                    sum = -1;
                }
            }
        }
        chmin(ans, cnt);
        for (auto &e: a) e = -e;
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=100100;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
ll n,res,flag,a[55],b[55],f[55][55],d[55][55];
ll pows(ll a,ll b){
    ll base=1;
    while(b){
        if(b&1) base*=a;
        a*=a;b/=2;
    }
    return base;
}
ll check(ll x){
    for(ll i=0;i<=50;i++)
     for(ll j=0;j<=50;j++) d[i][j]=f[i][j];
    for(ll i=1;i<=x;i++)
     for(ll j=0;j<=50;j++) d[j][j%i]=1;
    for(ll k=0;k<=50;k++) 
     for(ll i=0;i<=50;i++)
      for(ll j=0;j<=50;j++)
       if(d[i][k]&&d[k][j]) d[i][j]=1;
    for(ll i=1;i<=n;i++) if(!d[a[i]][b[i]]) return 0;
    return 1;
}
void go(ll x){
    res+=pows(2,x);
    for(ll i=0;i<=50;i++) f[i][i%x]=1;
    for(ll i=x;i>=1;i--){
        if(check(i-1)) continue;
        if(i!=x) go(i);break;
    }
}
int main()
{
    n=read();
    for(ll i=1;i<=n;i++) a[i]=read();
    for(ll i=1;i<=n;i++) b[i]=read();
    for(ll i=0;i<=50;i++)
     for(ll j=0;j<=i;j++) if(i==j) f[i][j]=1;else f[i][j]=0;
    for(ll i=51;i>=1;i--){
        if(check(i-1)) continue;
        if(i==51) flag=1;else go(i);break;
    }
    if(!flag) printf("%lld",res);
    else puts("-1");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;
int sum=0;
int a[110000];

int main(){
  while(true){
    sum=0;
    cin>>n;
    if(n==0) break;
    rep(i,n){
      cin>>a[i];
      sum+=a[i];
    }
    sum/=n;

    int asn=0;
    rep(i,n){
      if(sum>=a[i])
        asn++;
    }

    cout<<asn<<endl;
  }
}



Measured memory_bytes: 3112
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , m , col[N];
vi g[N];

int main(){
  scanf("%d%d",&n,&m);
  rep(i,0,m) {
    int u,v;scanf("%d%d",&u,&v);
    --u;--v;
    g[u].pb(v);
    g[v].pb(u);
  }
  int isolate = 0 , bipart = 0 , nonbipart = 0;
  rep(i,0,n) col[i]=-1;
  rep(i,0,n) if(col[i]==-1) {
    vi v;v.pb(i);col[i]=0;
    bool oddloop = false;
    rep(ii,0,sz(v)) {
      int c=v[ii];
      for(auto t : g[c]) {
        if(col[t]==-1) col[t]=col[c]^1,v.pb(t);
        else if(col[c]==col[t]) oddloop = true;
      }
    }
    if(sz(v)==1) isolate++;
    else (oddloop?nonbipart:bipart)++;
  }
  printf("%lld\n",ll(isolate)*isolate+2ll*isolate*(n-isolate)
      +ll(bipart+nonbipart)*(bipart+nonbipart)+ll(bipart)*bipart);
  return 0;
}


Measured memory_bytes: 7804
//3
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;
	cin >> x;
	string ans;
	switch (x % 7)
	{
	case 0:
		ans = "thu";
		break;
	case 1:
		ans = "fri";
		break;
	case 2:
		ans = "sat";
		break;
	case 3:
		ans = "sun";
		break;
	case 4:
		ans = "mon";
		break;
	case 5:
		ans = "tue";
		break;
	case 6:
		ans = "wed";
		break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3184
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, w[310];
bool dp[310][310];
int rec[310][310];

signed main() {
    while(cin >> N, N) {
        memset(dp, false, sizeof(dp));
        memset(rec, 0, sizeof(rec));

        rep(i,0,N) cin >> w[i];

        repq(x,2,N) rep(l,0,N-x+1) {
            int r = l+x;
            if(x == 2) {
                if(abs(w[l] - w[l+1]) <= 1) dp[l][r] = true;
            }
            else {
                rep(k,l,r) if(dp[l][k] && dp[k][r]) dp[l][r] = true;
            }

            if(dp[l][r]) {
                int c = 1;
                while(1) {
                    int nl = l - c, nr = r + c;
                    if(nl < 0 || nr > N) break;
                    if(abs(w[nl] - w[nr-1]) > 1) break;
                    dp[nl][nr] = true; c++;
                }
                rec[l][r] = r - l;
            }
        }

        repq(x,2,N) rep(l,0,N-x+1) {
            int r = l+x;
            rep(k,l,r) chmax(rec[l][r], rec[l][k] + rec[k][r]);
        }
        cout << rec[0][N] << endl;
    }
    return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;

pdi a[maxn];
bool operator<(const pdi &x, const pdi &y) {
    return x.first < y.first;
}

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a + 1, a + 1 + n);

    int ans = 0, id = 1;
	priority_queue<int> q;
    for (int i = 1; i <= m; i++) {
        while (id <= n && a[id].first <= i) {
			q.push(a[id++].second);
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
    }

	cout << ans << endl;
}

int main(void) {
    FAST_IO;
    
    solve();

    return 0;
}

Measured memory_bytes: 1660
import Data.List
import Data.Array.ST
import Data.Array
import Control.Monad

getA2Zsorted::[Char]->[Int]
getA2Zsorted cs = let ar = runSTArray $ do
                                        ar<-newArray ('a','z') 0
                                        forM_ cs (\c->do
                                                      v<-readArray ar c
                                                      writeArray ar c (v+1)
                                                  )
                                        return ar
                  in
                  (sort.elems) ar

solver::[Char]->[Char]->Bool
solver cs ds = ((getA2Zsorted cs)==(getA2Zsorted ds))

main::IO()
main=do
  cs<-getLine
  ds<-getLine
  putStr (if (solver cs ds) then "Yes\n" else "No\n")

Measured memory_bytes: 25980
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

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

  vector<int> ans(n + 1);
  auto f = [](int x, int y, int z) {
    return x * x + y * y + z * z + x * y + y * z + z * x;
  };
  rep(x, 1, sqrt(n)) rep(y, 1, sqrt(n)) rep(z, 1, sqrt(n)) {
    int v = f(x, y, z);
    if (v <= n) ans[v]++;
  }
  rep(i, 1, n + 1) cout << ans[i] << '\n';

#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int z[1919][1919];
int x[114514];
pair<int,int> a[114514];
signed main(){
	double n;
	cin>>n;
	int n1=n;
	rep(0,i,100){
		n1=n1-2;
		if(n1==0){
			c(0.5)
			return 0;
		}
	}
	double c=(n+1)/(2*n);
	printf("%.12f\n",c);
}			


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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

// index が条件を満たすかどうか

int main() {
	string s, t;
	cin >> s >> t;
	string c = t + s;
	cout << c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    bool ans[100001];
    int main(){
      int n,m;
      cin>>n>>m;
      int p[100001];
      for(int i=1;i<=n;i++)p[i]=1;
      ans[1]=1;
      for(int i=0,x,y;i<m;i++){
        cin>>x>>y;
        p[x]--;
        p[y]++;
        if(ans[x])ans[y]=1;
        if(!p[x])ans[x]=0;
      }
      int a=0;
      for(int i=1;i<=n;i++)a+=ans[i];
      cout<<a<<endl;
      return 0;
    }

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

int main(){
  string A, B;
  cin >> A >> B;

  int sizeB;
  sizeB=B.size();
//  cout << sizeB<<endl;
//  cout <<B.erase(sizeB-1)<<endl;

  if(A==B.erase(sizeB-1)){
    cout << "Yes"<<endl;
  }else{
    cout <<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3628
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
sum = 0
x = -1
for i in range(N):
    sum += B[A[i] - 1]
    if x == A[i] - 1:
        sum += C[x-1]
    x = A[i]
print(sum)

Measured memory_bytes: 3064
use std::io::*;

fn read_int(s: &mut StdinLock) -> usize {
    s.by_ref().bytes().map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .skip_while(|c| c.is_whitespace())
        .fold(0, |a, x| (x as u8 - b'0') as usize + a * 10)
}
fn read_line_char(s: &mut StdinLock) -> Vec<char> {
    s.by_ref().bytes().map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .skip_while(|c| c.is_whitespace())
        .collect()
}
fn solver(cv: &Vec<usize>, c1: usize, c2: usize, ans: &mut usize) {
    let mut ng: usize = 0;
    if (c1 + c2) % 2 == 0 {
        if let Ok(_) = cv.binary_search(&((c1 + c2) / 2)) {
            ng = 1;
        }
    }
    match cv.binary_search(&c2) {
        Ok(p) => {
            match cv.binary_search(&c1) {
                Ok(q) => {
                    if p < q {
                        *ans += q - p - ng;
                    } else {
                        *ans += p - q - ng;
                    }
                },
                Err(q) => {
                    if p < q {
                        *ans += q - p - ng;
                    } else {
                        *ans += p - q - ng;
                    }
                },
            }
        },
        Err(p) => {
            match cv.binary_search(&c1) {
                Ok(q) => {
                    if p < q {
                        *ans += q - p - ng;
                    } else {
                        *ans += p - q - ng;
                    }
                },
                Err(q) => {
                    if p < q {
                        *ans += q - p - ng;
                    } else {
                        *ans += p - q - ng;
                    }
                },
            }
        },
    }
}
fn main() {
    let s = stdin();
    let mut s = s.lock();
    let n = read_int(&mut s);
    let vec_char = read_line_char(& mut s);
    let mut b: Vec<usize> = Vec::new();
    let mut g: Vec<usize> = Vec::new();
    let mut r: Vec<usize> = Vec::new();
    for i in 0..n {
        if vec_char[i] == 'B' {
            b.push(i);
        } else if vec_char[i] == 'G' {
            g.push(i);
        } else if vec_char[i] == 'R' {
            r.push(i);
        }
    }
    let mut ans: usize = 0;
    for i in 0..b.len() { // n^2 log n
        for j in 0..g.len() {
            solver(&r, b[i], g[j], &mut ans);
        }
    }
    for i in 0..b.len() {
        for j in 0..r.len() {
            solver(&g, b[i], r[j], &mut ans);
        }
    }
    for i in 0..g.len() {
        for j in 0..r.len() {
            solver(&b, g[i], r[j], &mut ans);
        }
    }
    println!("{}", ans);
}

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

int main() {
    int s;
    int ans=0;
    cin >> s;
    ans+=s/100;
    s=s-s/100*100;
    ans+=s/10;
    s=s-s/10*10;
    ans+=s;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print(vector<Pll> vec){
    ll n = vec.size();
    rep(i,n){
        cout << vec[i].first << " " << vec[i].second << "\n";
    }
    return ;
}

void print(vector<ll> vec){
    ll n = vec.size();
    rep(i,n)cout << vec[i] << " ";
    cout << "\n";
    return ;
}
int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    Pll ma = {0,a[0]};
    rep(i,n)if(abs(a[i]) > abs(ma.second))ma = Pll(i,a[i]);
    vector<Pll> res;
    rep(i,n){
        if(i == ma.first)continue;
        res.emplace_back(Pll(ma.first+1, i+1));
        a[i] += ma.second;
    }
    if(ma.second > 0){
        rep(i,n-1){
            if(a[i] > a[i+1]){
                a[i+1] += a[i];
                res.emplace_back(Pll(i+1, i+2));
            }
        }
    }
    else if(ma.second < 0){
        for(int i = n-1;0 < i; --i){
            if(a[i] < a[i-1]){
                a[i-1] += a[i];
                res.emplace_back(Pll(i+1,i));
            }
        }
    }

    cout << res.size() << endl;
    print(res);
    // print(a);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<30;
string S[MAX];
struct from{
    int a;
    int b;
    int c;
};

bool dp[MAX][9][9][9];
from par[MAX][9][9][9];

void update(int t,int a,int b,int c,char x){
    int toa=a,tob=b,toc=c;
    if(x=='A'){
        toa=a-1;
        tob=min(b+1,8);
    }
    if(x=='B'){
        tob=b-1;
        toc=min(c+1,8);
    }
    if(x=='C'){
        toc=c-1;
        toa=min(a+1,8);
    }
    dp[t+1][toa][tob][toc]=1;
    par[t+1][toa][tob][toc]=from{a,b,c};
    
    if(x=='A'){
        toa=min(a+1,8);
        tob=b-1;
    }
    if(x=='B'){
        tob=min(b+1,8);
        toc=c-1;
    }
    if(x=='C'){
        toc=min(c+1,8);
        toa=a-1;
    }
    dp[t+1][toa][tob][toc]=1;
    par[t+1][toa][tob][toc]=from{a,b,c};
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,A,B,C;cin>>N>>A>>B>>C;
    for(int i=0;i<N;i++){
        cin>>S[i];
        if(S[i]=="AC") S[i]="CA";
    }
    chmin(A,7);
    chmin(B,7);
    chmin(C,7);
    dp[0][A+1][B+1][C+1]=1;
    
    for(int t=0;t<N;t++){
        for(int a=1;a<=8;a++){
            for(int b=1;b<=8;b++){
                for(int c=1;c<=8;c++){
                    if(!dp[t][a][b][c]) continue;
                    
                    update(t,a,b,c,S[t][0]);
                }
            }
        }
    }
    
    for(int a=1;a<=8;a++){
        for(int b=1;b<=8;b++){
            for(int c=1;c<=8;c++){
                if(dp[N][a][b][c]){
                    cout<<"Yes"<<endl;
                    vector<char> ans;
                    from now={a,b,c};
                    for(int k=0;k<N;k++){
                        from to=par[N-k][now.a][now.b][now.c];
                        
                        if(S[N-1-k][0]=='A'){
                            if(to.a>now.a) ans.push_back('B');
                            else ans.push_back('A');
                        }
                        
                        if(S[N-1-k][0]=='B'){
                            if(to.b>now.b) ans.push_back('C');
                            else ans.push_back('B');
                        }
                        
                        if(S[N-1-k][0]=='C'){
                            if(to.c>now.c) ans.push_back('A');
                            else ans.push_back('C');
                        }
                        
                        now=to;
                    }
                    
                    reverse(all(ans));
                    
                    for(char x:ans) cout<<x<<"\n";
                    return 0;
                }
            }
        }
    }
    
    cout<<"No"<<endl;
}



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

int main() {
	int x,n;
	cin >> x >> n;
	vector<bool> a(102,true);
	for(int i=0;i<n;i++){
		int k;
		cin >> k;
		a[k]=false;
	}
	int i=0;
	int ans;
	while(1){
		if(a[x-i]){
			ans=x-i;
			break;
		}
		if(a[x+i]){
			ans=x+i;
			break;
		}
		i++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3624
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    int x , d , k;

    cin>>x>>k>>d;


    int val = (x/d);

    if(abs(val) < k){

        ans = val;
    }
    else{
        ans = k;
    }
    // db(ans);

    b = ans;

    ans = min(abs(x - ans*d) , abs(x + ans*d));

    ans = abs(ans);

    if( k > b && (k - b)%2 == 1)
        ans = min(abs(ans + d) , abs(ans - d));


    cout<<ans<<endl;  
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


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

int main() {
	string a, b;
	cin >>a>>b;
	int c = stoi(a + b);
	for (int i = 1;i <= 1000;i++) {
		if (i*i == c) {
			puts("Yes");
			return 0;
		}

	}
	puts("No");
}



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

using namespace std;

int main()
{
	int a ,b , jav = 0;
	cin >> a >> b;
	
	if (a >= 0 && b >= 0)
	{
		if (a > b)
		{
			jav += 2;
			jav += abs(a - b);
			if (b == 0)
			{
				jav -= 1;
			}
		}
		else
		{
			jav += abs(a - b);
		}
	}
	if (a < 0 && b >= 0)
	{
			jav += 1;
			jav += abs(a + b);
				if (b == 0)
			{
				jav -= 1;
			}
	}
	if (a >= 0 && b < 0)
	{
		jav += 1;
		jav += abs(a + b);
	}
	if (a < 0 && b < 0)
	{
		if (abs(a) < abs(b))
		{
			jav += 2;
			jav += abs(a - b);
		}
		else
		{
			jav += abs(a - b);
		}
	}
	cout << jav;
	return 0;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted
/****************************/
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<vector>
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;

const long long Mod = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;

#define pb push_back
#define mp make_pair
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
	
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
/***************************/

int main(void){
	int a,b;cin>>a>>b;
	cout << max({a+b,a-b,a*b}) << endl;
	return 0;
}

Measured memory_bytes: 256
/*
                                Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
 
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/

#include <bits/stdc++.h>

#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
 
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x) % M;
        x=(x*x)% M;
        n=n/2;
    }
    return result % M;
}
signed main()
{   jaldi
    int n,i;
    cin>>n;
    string str;
    cin>>str;
    for(i=0;i<str.length();i++)
    {   int x=str[i];
        x+=n;
        if(x<=90)
        {   char ch=x;
            str[i]=ch;
        }
        else if(x>90)
        {   int y=x-90;
            y+=64;
            char ch=y;
            str[i]=ch;
        }
    }
    cout<<str;
}

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

int main(){
  int a[10001],b[10001];
  for(int i=0;i<10001;++i){
    cin >> a[i] >> b[i];
    if(a[i] == 0 && b[i] == 0)break;
  }
  for(int j=0;j<10001;++j){
    if(a[j] != 0 || b[j] != 0){
      cout << min(a[j],b[j]) << " " << max(a[j],b[j]) << endl;
    } else break;
  }
  return 0;
}


Measured memory_bytes: 3100
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    vector<int> B(N);
    priority_queue<P> que;
    for(int i=0; i<N; i++){
        cin >> B[i];
        que.emplace(B[i],i);
    }
    ll cnt = 0;
    bool can = true;
    int pre = -1;
    while(que.size()){
        int b = que.top().second;
        que.pop();
        if(A[b] == B[b]) continue;
        if(pre == b){
            can = false;
            break;
        }
        if(A[b] > B[b]){
            can = false;
            break;
        }
        int ac = B[(b-1+N)%N] + B[(b+1)%N];
        if(A[b] >= ac){
            if((B[b]-A[b])%ac == 0){
                cnt += (B[b]-A[b])/ac;
                B[b] = A[b];
            }else{
                can = false;
                break;
            }
        }else{
            if(B[b]%ac == 0){
                cnt += (B[b]-1)/ac;
                B[b] = ac;
            }else{
                cnt += B[b]/ac;
                B[b] %= ac;
            }
            que.emplace(B[b],b);
        }
        pre = b;
    }
    if(can){
        cout << cnt << "\n";
    }else{
        cout << -1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 6840
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            // 入力
            var input = cin.ReadIntArray(2);
            int n = input[0];
            int l = input[1];

            var aList = new List<Apple>();
            var absList = new List<int>();

            int resultTaste = 0;

            int a = 0;
            for (int i = 1;i <= n; i++)
            {
                a = l + i - 1;
                aList.Add(new Apple { num = i,taste = a,tasteAbs = Abs(a)});
                absList.Add(Abs(a));

            }
            absList.Sort();
            aList.RemoveAt(aList.FindIndex(apple => apple.tasteAbs == absList[0]));
            aList.ForEach(apple => resultTaste += apple.taste);

            WriteLine(resultTaste);
        }
        
    }

    public class Apple
    {
        public int num = 0;
        public int taste = 0;
        public int tasteAbs = 0;
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N, T;
    cin >> N >> T;
    int c[100], t[100];
    REP(i,N) cin >> c[i] >> t[i];
    int ans = 1010;
    REP(i,N){
        if(T < t[i]) continue;
        ans = min(c[i], ans);
    }
    if(ans == 1010) cout << "TLE" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())

def dfs(s):
  ret = 0
  if int(s) > n:
    return 0
  if all(s.count(c) > 0 for c in '753'):
    ret = 1
  for c in '753':
    ret += dfs(s+c)
  return ret

print(dfs('0'))
  

Measured memory_bytes: 55004
#include <stdio.h>
#define INFTY 1000000000
#define N 500000

void merge(int *,int,int,int);
void mergesort(int *,int,int);
int count=0;
int main(){
  int S[N];
  int n,i,j;

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

  mergesort(S,0,n);
  for(i=0;i<n-1;i++){
    printf("%d ",S[i]);
  }
  printf("%d\n",S[n-1]);
  printf("%d\n",count);
  return 0;

}

void mergesort(int *A,int left,int right){

  int mid;

  if(left+1<right){
    mid=(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }

}

void merge(int *A,int left,int mid,int right){

  int n1,n2,i,k,j;
  n1 = mid - left;
  n2 = right - mid;

  int L[n1+1],R[n2+1];
  //L[0...n1], R[0...n2] ?????????
  for(i = 0;i<n1;i++){
    L[i] = A[left + i];
  }
  for (i = 0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for (k = left;k<right;k++){
    if (L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
      count++;
    }
    else {
      A[k] = R[j];
      j = j + 1;
      count++;
    }
}
}

Measured memory_bytes: 6560
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
#define enld endl
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll N,K; cin >> N >> K;
    int A[200100];
    bool isvisited[200100];
    Fill(isvisited, false);
    for(int i=1;i<=N;i++){
        cin >> A[i];
    }
    int next = 1;
    int loop;
    while(true){
        K--;
        next = A[next];
        if(K == 0){
            cout << next << endl;
            return 0;
        }

        if(isvisited[next] == true){
            loop = next;
            break;
        }
        isvisited[next] = true;
    }

    int T = 0;
    while(true){
        T++;
        next = A[next];
        if(next == loop) break;
    }

    next = loop;
    for(int i=0;i<K%T;i++){
        next = A[next];
    }
    cout << next << endl;
    return 0;

}


Measured memory_bytes: 4608
//author: Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  ll n = 0, k = 0;
  cin>>n>>k;
  vector<ll>a(n+1,0);
  for(ll i = 0; i<n; ++i) cin>>a[i];
  vector<ll>b(n+1,0);
  while(k--){
    for(ll i = 0; i <= n ;++i) b[i]=0;
    for(ll i = 0; i < n; ++i){
      ll l = max(0ll, i - a[i]);
      ll r = min(i + a[i], n - 1);
      ++b[l];
      --b[r + 1];
    }
    bool different = false;
    for(ll i = 0; i < n; ++i){
      different |= (a[i] != b[i]);
      a[i] = b[i];
      b[i+1] += b[i];
    }
    if(!different) break;
  }
  for(ll i = 0; i < n; ++i) cout<<b[i]<<" ";
  return 0;
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+7;
const ll inf_l = 1e18;
const int MAX = 1e6;

int main() {
    string s; cin >> s;
    int k; cin >> k;
    int ct = 1;
    int n = s.size();
    set<char> st;
    rep(i,n) st.insert(s[i]);
    if (st.size() == 1) {
        cout << (ll)n*k/2 << endl;
        return 0;
    }
    int n_1 = 0;
    rep(i,n-1) {
        if (s[i] == s[i+1]) ct++;
        else {
            n_1 += ct/2;
            ct = 1;
        }
    }
    n_1 += ct/2;
    ct = 1;
    int n_2 = 0;
    rep(i,2*n-1) {
        if (s[i%n] == s[(i+1)%n]) ct++;
        else {
            n_2 += ct/2;
            ct = 1;
        }
    }
    n_2 += ct/2;
    int diff = n_2 - n_1;
    ll ans = n_1 + (ll)diff*(k-1);
    cout << ans << endl;
}

Measured memory_bytes: 256
j=1
while 1
        i=gets.split
        k=i[1].to_i
        i=i[0].to_i
        if i==0&&k==0
                break
        end
        if i>k
                print "#{k} #{i}\n"
        elsif k>i
                print "#{i} #{k}\n"
        else
                print "#{k} #{i}\n"
        end
end

Measured memory_bytes: 6100
n, m = map(int, input().split())
list_data = [ list(map(int,input().split(" "))) for i in range(m)]
list_condition = list(map(int, input().split()))

for i in range(m):
    a = list_data[i]
    a.pop(0)

ans = 0

for i in range(2**n):
    list_ans = [0] * m
    for l in range(m):
        for j in range(n):
            if ((i >> j) & 1):
                if j+1 in list_data[l]:
                    list_ans[l] += 1
    a = list(map(lambda x:x % 2, list_ans))
    if a == list_condition:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long a[10000],n;
 a[0]=2,a[1]=1;
 cin>>n;
 for(int i=2;i<=n;i++)
 {
 	a[i]=a[i-1]+a[i-2];
 }
 cout<<a[n]<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x,y,ans;
    cin>>a>>b>>c>>x>>y;
    if(a+b>c*2)
    {
        if(x>y)
            ans=y*2*c+(x-y)*a;
        else
            ans=x*2*c+(y-x)*b;
    }
    else
    {
        ans=x*a+y*b;
    }
    int ans1=max(x,y)*2*c;
    cout<<min(ans,ans1)<<endl;
}


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

int main(){
  int a;
  std::cin >> a;
  int sum=0;
  for (int i = 1; i < 100001; i++) {
    if(i>a)break;
    sum++;
    if(i==99999)break;
    if(i==999)i=9999;
    else if(i==9)i=99;
  }
  std::cout << sum << '\n';


  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

string s;
int p;

int expression();
int term();
int factor();
int number();

int expression() {
	int value = term();
	while(true) {
		if(s[p] == '+') {
			p++;
			value += term();
		} else if(s[p] == '-') {
			p++;
			value -= term();
		} else {
			break;
		}
	}
	return value;
}

int term() {
	int value = factor();
	while(true) {
		if(s[p] == '*') {
			p++;
			value *= factor();
		} else if(s[p] == '/') {
			p++;
			value /= factor();
		} else {
			break;
		}
	}
	return value;
}

int factor() {
	int value = 0;
	if(s[p] == '(') {
		p++;
		value = expression();
		p++;
	} else {
		value = number();
	}
	return value;
}

int number() {
	int value = 0;
	while(isdigit(s[p])) {
		value = value*10 + (s[p] - '0');
		p++;
	}
	return value;
}

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		p = 0;
		cin >> s;
		cout << expression() << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
N = int(input())
S = input()
L = len(S)
a = 'a'
for i in range(L):
    O = ord(S[i]) + N
    if O > 90:
        O = (O-90)+64
    else:
        pass
    ans = chr(O)
    a = a+ans

print(a[1:])

Measured memory_bytes: 3060
/*
  Half-Half
*/

#include <iostream>
#include <string>
using namespace std;

string space = " ";
string tab = "\t";

inline int max(int a, int b)
{
  if(a > b)
    return a;
  else
    return b;
}

int main()
{
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  // cout << A << space << B << space << C << space << X << space << Y << endl;

  int a, b, c; // Aピザ, Bピザ, ABピザを購入する枚数
  int f; // 合計金額
  int f_min = 1 << 30;
  int a_best, b_best, c_best;

  for(c = 0; c <= max(X, Y)*2; c++){
    a = X - c / 2;
    b = Y - c / 2;

    if(a < 0)
      a = 0;
    if(b < 0)
      b = 0;
    // if((a < 0) || (b < 0))
    //   break;

    // 合計金額求める
    f = a*A + b*B + c*C;
    if(f < f_min){
      f_min = f;
      a_best = a;
      b_best = b;
      c_best = c;
    }

    // cout << c << tab << a << space << b << tab << f << endl;
  }

  // cout << f_min << space << a_best << space << b_best << space << c_best << endl;
  cout << f_min << endl;

  return 0;
}


Measured memory_bytes: 256