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

int ctoi(char c){
    switch (c){
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default: return 0;
    }
}

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int count = 0;
    for (int i = 0; i <= 9; i++){
        for (int j = 0; j <= 9; j++){
            for (int k = 0; k <= 9; k++){
                int cnt = 0;
                int l = 0;
                while (true){
                    if (l == N || cnt == 3){
                        break;
                    }
                    else if (cnt == 0){
                        if (ctoi(S[l]) == i){
                            l++;
                            cnt++;
                        }
                        else{
                            l++;
                        }
                    }
                    else if (cnt == 1){
                        if (ctoi(S[l]) == j){
                            l++;
                            cnt++;
                        }
                        else{
                            l++;
                        }
                    }
                    else if (cnt == 2){
                        if (ctoi(S[l]) == k){
                            l++;
                            cnt++;
                        }
                        else{
                            l++;
                        }
                    }
                }
                if (cnt == 3) count++;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int g[110][110];
int h,w,n,x,k;
int main()
{
	while(scanf("%d%d%d",&h,&w,&n)!=EOF)
	{
		mem(g);
		k=-1;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&x);
			while(x--) k++,g[(k/h)&1?(h-1-(k%h)):k%h][k/h]=i;
		}
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(j) printf(" ");
				printf("%d",g[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct binary_indexed_tree{
  int N;
  vector<T> BIT;
  binary_indexed_tree(int n){
    N = 1;
    while (N < n){
      N *= 2;
    }
    BIT = vector<T>(N + 1, 0);
  }
  void add(int i, T x){
   i++;
    while (i <= N){
      BIT[i] += x;
      i += i & -i;
    }
  }
  int sum(int i){
    int ans = 0;
    while (i > 0){
      ans += BIT[i];
      i -= i & -i;
    }
    return ans;
  }
};
int main(){
  while (1){
    int n, k, m;
    cin >> n >> k >> m;
    if (n == 0 && k == 0 && m == 0){
      break;
    }
    m--;
    binary_indexed_tree<int> BIT(n);
    for (int i = 0; i < n; i++){
      BIT.add(i, 1);
    }
    for (int i = 0; i < n - 1; i++){
      BIT.add(m, -1);
      int p = (BIT.sum(m) + k - 1) % (n - i - 1) + 1;
      int tv = n;
      int fv = -1;
      while (tv - fv > 1){
        int mid = (tv + fv) / 2;
        if (BIT.sum(mid) >= p){
          tv = mid;
        } else {
          fv = mid;
        }
      }
      m = fv;
    }
    cout << m + 1 << endl;
  }
}


Measured memory_bytes: 3128
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;
const LL MOD = 1000000007;

struct modll {
	long long x;
	modll() { }
	modll(long long _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(const modll& r) { return (x + r.x) % MOD; }
	modll operator+=(const modll& r) { return x = (x + r.x) % MOD; }
	modll operator-(const modll& r) { return (x + MOD - r.x) % MOD; }
	modll operator-=(const modll& r) { return x = (x + MOD - r.x) % MOD; }
	modll operator*(const modll& r) { return (x * r.x) % MOD; }
	modll operator*(int r) { return (x * r) % MOD; }
	modll operator*=(const modll& r) { return x = (x * r.x) % MOD; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1;
		cin >> n;
		if (n < 0) return 0;
		vector<LL> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		modll ans = 0, inv = modll::modinv(2);
		for (int b = 0; b < 60; ++b) {
			LL c = (1LL << b);
			int pos = 0, neg = 0;
			for (int i = 0; i < n; ++i) {
				if (a[i] & c) {
					++pos;
				} else {
					++neg;
				}
			}
			for (int i = 0; i < n; ++i) {
				modll e;
				if (a[i] & c) {
					e = neg;
				} else {
					e = pos;
				}
				e *= (c % MOD);
				e *= inv;
				ans += e;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

void Main()
{
  ll k; cin >> k;
  if (k % 2 == 0) {cout << -1 << endl; return;}
  ll wara = 0;
  for(int j = 1; j <= k; j++) {
    wara = ((wara * (ll)10)%k + (ll)7)%k;
    if (wara == 0) {
      cout << j << endl;
      return;
    }
  }
  cout << -1 << endl;
} 

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3648
#ans = min(b - a + min(abs(a), abs(b)) for a, b in zip(x, x[K-1:]))

N, K = map(int, input().split())
INF = 10**10
x_first = [-INF for i in range(K)]
x_ap = [int(i) for i in input().split()]
x_last = [INF for i in range(K)]
x = x_first + x_ap + x_last + [0]
x.sort()
zero_index = x.index(0)

key = []
for i in range(K+1):
    left = abs(x[zero_index - i])
    right = abs(x[zero_index - i + K])
    # left か rightの 0に近い方に行ってからもう片方にいく
    if left > right:
        right *= 2
    else:
        left *= 2
    key.append(left + right)
print(min(key))


Measured memory_bytes: 18980
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	double ans = 0;
	const double BIT = 380000.;
	while(n--) {
		double x; scanf("%lf", &x);
		std::string s; cin >> s;
		
		if(s == "JPY") ans += x;
		else ans += x * BIT;
	}
	printf("%.8lf\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>
using namespace std;

int main() {
	int n;
	cin>>n;
	cout<<pow(n, 3);
}


Measured memory_bytes: 256
(n,q), *cxy = [list(map(int, s.split())) for s in open(0)]

class UnionFind:
    def __init__(self, n):
        self.parent = {i:i for i in range(n)}
        
    def find_root(self, x):
        parent = self.parent[x]
        if x != parent:
            result = self.find_root(parent)
            self.parent[x] = result
            return result
        else:
            return x

    def unite(self, x, y):
        if x == y:
            return
        
        x, y = min(x,y), max(x,y)
        x = self.find_root(x)
        y = self.find_root(y)
        
        if x == y:
            return
        elif x > y:
            x = self.find_root(x)
            if x == y:
                return
            x, y = min(x,y), max(x,y)
        self.parent[y] = x

    def same(self, x, y):
        return self.find_root(x) == self.find_root(y)

u = UnionFind(n)

for c,x,y in cxy:
    if c:
        print(int(u.same(x,y)))
    else:
        u.unite(x,y)


Measured memory_bytes: 25128
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! { n, s: chars, q, ks: [(usize); q] };
    for k in ks.into_iter() {
        let (mut d, mut m, mut dm, mut dmc) = (0usize, 0usize, 0usize, 0usize);
        for i in 0..n {
            match s[i] {
                'D' => {
                    d += 1;
                }
                'M' => {
                    m += 1;
                    dm += d;
                }
                'C' => {
                    dmc += dm;
                }
                _ => (),
            }
            if i + 1 >= k {
                match s[i + 1 - k] {
                    'D' => {
                        d -= 1;
                        dm -= m;
                    }
                    'M' => {
                        m -= 1;
                    }
                    _ => (),
                }
            }
        }
        println!("{}", dmc);
    }
}


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

int main(){
    string s; cin >> s;

    if(s == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string>vec1(N);
  for(int i=0;i<N;i++)
    cin >>vec1.at(i);
  int M;
  cin >> M;
  vector<string>vec2(M);
  for(int i=0;i<M;i++)
    cin >>vec2.at(i);
  int a =0;
  vector<int> money(N);
  for (int i=0;i<N;i++){
    money.at(i) = 0;
    for(int j=0;j<N;j++){
      if(vec1.at(i) == vec1.at(j))
        money.at(i)++;
    }
    for(int j=0;j<M;j++){
      if(vec1.at(i) ==vec2.at(j))
        money.at(i)--;
    }
    if(a < money.at(i))
      a =money.at(i);
  }
  if(a > 0)
    cout << a << endl;
  else
    cout << 0 << endl;
       
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int n;
const int m = 10;
int *data;
int *lp;
int *rp;

bool dfs(int i, int j) {
	if (i+j == 10) return true;
	
		if (!i || (i>0 && data[i+j] > lp[i-1])) {
			lp[i] = data[i+j];
			if (dfs(i+1, j)) return true;
		}

		if (!j || (j>0 && data[i+j] > rp[j-1])) {
			rp[j] = data[i+j];
			if (dfs(i, j+1)) return true;
		}

	return false;
}

int main()
{
	int i, j;
	data = (int *)calloc(m, sizeof(int));
	lp = (int *)calloc(m, sizeof(int));
	rp = (int *)calloc(m, sizeof(int));
	
	scanf("%d ", &n);
	for (i=0; i<n; i++) {
		for (j=0; j<m; j++)
			scanf("%d ", &(data[j]));

		memset(lp, 0, sizeof(int));
		memset(rp, 0, sizeof(int));

		lp[0] = data[0];	
		if (dfs(1, 0))
			printf("YES\n");
		else
			printf("NO\n");
	}

	free(data);
	free(lp);
	free(rp);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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 (a>b) { a=b; return true; } return false; }

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


const ll mod = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;
    if (abs(n-m) > 1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    ll x = 1;
    for(int i = 1; i <= n; i++){
        x *= i;
        x %= mod;
    }
    ll y = 1;
    for(int i = 1; i <= m; i++){
        y *= i;
        y %= mod;
    }
    ans = x * y % mod;
    
    if (n == m) ans = ans * 2 % mod;
    cout << ans << endl;
}

Measured memory_bytes: 3564
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int N,K,h[100010],dh[100010],ans=pow(10,9)+7;cin>>N>>K;
    for(int i=0;i<N;++i)cin>>h[i];
    sort(h,h+N);
    for(int i=0;i<=N-K;++i){
        dh[i]=h[K+i-1]-h[i];
        ans=min(ans,dh[i]);
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 640
#include<iostream>
//#include<vector>

int main(){
	int a,b;
	std::cin>>a>>b;

	if (a - 2*b <= 0) {
		std::cout << 0 << std::endl;
	}
	else {
		std::cout << a-2*b << std::endl;
	}

	return 0;
}

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

const int mo=1e9+7;

int n,m,k;
int g[21][21],dp[2][1<<19],S0[21][1<<19];

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,j,S,a,b,c;
	scanf("%d%d%d",&n,&m,&k);
	memset(g,-1,sizeof(g));
	for (i=1;i<=k;i++)
		scanf("%d%d%d",&a,&b,&c),g[a][b]=c;
	for (i=1;i<n;i++)
	for (S=0;S<1<<(n-1);S++)
	{
		S0[i][S]=S|(1<<(i-1));
		for (j=i;j<n-1;j++)
			if ((S0[i][S]>>j)&1) {S0[i][S]-=1<<j; break;}
	}

	int fk=1;
	dp[fk][0]=1;
	for (i=1;i<=m;i++)
	{
		for (j=1;j<n;j++)
		{
			memset(dp[fk^1],0,sizeof(dp[fk^1]));
			for (S=0;S<1<<(n-1);S++) if (dp[fk][S])
			{
				int tmp=dp[fk][S];
				if ((S>>(j-1))&1)
					(dp[fk^1][S]+=g[i][j]==0?0:tmp)%=mo;
				else
				{
					if (g[i][j]!=1)
						(dp[fk^1][S]+=tmp)%=mo;
					if (g[i][j]!=0)
						(dp[fk^1][S0[j][S]]+=tmp)%=mo;
				}
			}
			fk^=1;
		}
	}
	int Ans=0;
	for (S=0;S<1<<(n-1);S++)
		(Ans+=dp[fk][S])%=mo;
	printf("%d\n",Ans);
}


Measured memory_bytes: 45440
#include <iostream>
using namespace std;
typedef unsigned long long ll;

int main(){
    ll L, R;
    cin >> L >> R;
    ll ans = 2000000001;
    if(R - L > 2019){
        ans = 0;
    }else{
        for (ll i = L; i < R;i++){
            ll Rmod = i % 2019;
            for (ll j = i + 1; j < R + 1;j++){
                ll Lmod = j % 2019;
                ll mod = (Rmod * Lmod) % 2019;
                if(mod < ans){
                    ans = mod;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
# Python3 program to compute LCM of  
# array elements modulo M 
MAX = 1000003
  
mod = 1000000007
  
prime = [0 for i in range(MAX)] 
  
max_map = dict() 
  
# function to return a^n 
def power(a, n): 
      
    if n == 0: 
        return 1
    p = power(a, n // 2) % mod 
    p = (p * p) % mod 
      
    if n & 1: 
        p = (p * a) % mod 
    return p 
  
# function to find the smallest prime 
# factors of numbers upto MAX 
def sieve(): 
    prime[0], prime[1] = 1, 1
    for i in range(2, MAX): 
        if prime[i] == 0: 
            for j in range(i * 2, MAX, i): 
                if prime[j] == 0: 
                    prime[j] = i 
            prime[i] = i 
  
# function to return the LCM modulo M 
def lcmModuloM(arr, n): 
      
    for i in range(n): 
        num = arr[i] 
          
        temp = dict() 
          
        # temp stores mapping of prime factors  
        # to its power for the current element 
        while num > 1: 
               
            # factor is the smallest prime 
            # factor of num 
            factor = prime[num] 
              
            # Increase count of factor in temp 
            if factor in temp.keys(): 
                temp[factor] += 1
            else: 
                temp[factor] = 1
                  
            # Reduce num by its prime factor 
            num = num // factor 
              
        for i in temp: 
            # store the higest power of every prime 
            # found till now in a new map max_map 
            if i in max_map.keys(): 
                max_map[i] = max(max_map[i], temp[i]) 
            else: 
                max_map[i] = temp[i] 
              
    ans = 1
      
    for i in max_map: 
          
        # LCM is product of primes to their 
        # higest powers modulo M 
        ans = (ans * power(i, max_map[i])) % mod 
    return ans 
  
# Driver code 
sieve()
n = int(input())
a = list(map(int, input().split()))
if len(a) == 1:
    print(1)
    exit()
mod = 10**9+7
lcm = lcmModuloM(a, len(a))
ans = 0
for i in a:
    ans+=pow(i, mod-2, mod)
    ans%=mod
ans*=lcm
ans%=mod
print(ans)

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

#define N_size 100000000000

using namespace std;

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

    if((A % B) == 0 || (B % A) == 0)
        cout << A + B << endl;
    else
    {
        cout << B - A << endl;
    }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	fclose(stdin);
//	fclose(stdout);
    cin>>n;
    cout<<n*800-floor((n*1.0)/15)*200<<endl; 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		if(A==B && B!=C) {
			System.out.println("Yes");
		}else if(A==C && A!=B) {
			System.out.println("Yes");
		}else if(B==C && A!=B) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    string S;
    std::cin >> S;
    ll N;
    std::cin >> N;

    ll ans = 0;
    if(S.front() == S.back()) {
        ll f_cnt = 0;
        while(f_cnt != S.size() - 1 && S[f_cnt] == S.front()) f_cnt++;
        if(f_cnt == S.size() - 1) {
            ans = S.size() * N / 2;
        }
        else {
            ll b_cnt = 0;
            while(S[S.size() - b_cnt - 1] == S.back()) b_cnt++;
            ans += f_cnt / 2 + b_cnt / 2;

            string S2 = S.substr(f_cnt) + S.substr(0, f_cnt);
            ll i = 0;
            while(i < S2.size()) {
                ll j = i;
                while(j < S2.size() && S2[i] == S2[j]) j++;
                if(j <= S.size() - b_cnt) {
                    ans += ((j - i) / 2) * N;
                }
                else {
                    ans += ((j - i) / 2) * (N - 1);
                }
                i = j;
            }
        }
    }
    else {
        ll i = 0;
        while(i < S.size()) {
            ll j = i;
            while(j < S.size() && S[i] == S[j]) j++;
            ans += ((j - i) / 2) * N;
            i = j;
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(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;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b,c;
  	ci(a>>b>>c);
  co(c/2*(a+b))
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:128777216")

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <sstream>

#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>

#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <string.h>

#include <memory.h>
#include <cassert>
#include <time.h>
#include <functional>

using namespace std;

#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i,a,b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, b, a) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define _(a, val) memset (a, val, sizeof (a))
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long lint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;

const lint LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;

#ifdef MY_DEBUG
#define dbgx( x ) { cerr << #x << " = " << x << endl; }
#define dbg( ... ) { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#else
#define dbgx( x ) {  } 
#define dbg( ... ) {  } 
#endif

void prepare(string s) {
#ifdef MY_DEBUG
  freopen("input.txt", "r", stdin);
  //freopen ("output.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
  //freopen ("output.txt", "w", stdout);
#endif
}

const int NMAX = 305;

int H, W, D;
int a[NMAX][NMAX];
pii b[NMAX*NMAX];
vector<int> s[NMAX*NMAX];
pii c[NMAX*NMAX];

const int QMAX = 100005;
int Q;
int q[QMAX][2];

void read() {
  scanf("%d %d %d", &H, &W, &D);
  forn(i, H) {
    forn(j, W) {
      scanf("%d", &a[i][j]);
      b[a[i][j]] = mp(i, j);
    }
  }
  scanf("%d", &Q);
  forn(i, Q) {
    scanf("%d %d", &q[i][0], &q[i][1]);
  }
}

void solve() {
  forab(i, 1, D) {
    s[i].pb(0);
    c[i] = mp(i, 0);
    for (int j = i + D; j <= H*W; j += D) {
      c[j] = mp(i, s[i].size());
      s[i].pb(s[i].back() + abs(b[j - D].first - b[j].first) + abs(b[j - D].second - b[j].second));
    }
  }

  forn(i, Q) {
    pii p1, p2;
    p1 = c[q[i][0]];
    p2 = c[q[i][1]];
    int ans = s[p2.first][p2.second] - s[p1.first][p1.second];
    printf("%d\n", ans);
  }

}

int main() {
  prepare("");

  read();
  solve();
  dbg("Clock = %.3f\n", clock() / (double)CLOCKS_PER_SEC);
  return 0;
}

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

int main() {
    int N; 
    cin >>N;
    vector<int> W(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> W.at(i);
        sum += W.at(i);
    }
    int mini = sum;
    int prefix_sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> W.at(i);
        prefix_sum += W.at(i);
        mini = min(mini,abs(prefix_sum - (sum - prefix_sum)));
    }
    cout << mini << endl;
  
 }

Measured memory_bytes: 256
D, G = map(int, input().split())
p = [0] * D
c = [0] * D
for i in range(D):
    p[i], c[i] = map(int, input().split())

num = []
# 完全に解くか解かないかを選ぶ
for i in range(2**D):
    score = 0
    num_tmp = 0  # 解いた問題数
    not_comp = []  # 解いていないもの
    for j in range(D):
        if i >> j & 1:
            score += p[j] * 100 * (j + 1) + c[j]
            num_tmp += p[j]
        else:
            not_comp.append(j)

    for j in not_comp[::-1]:
        if score < G:
            num_j = min(p[j] - 1, (G - score) // (100 * (j + 1)))
            score += num_j * 100 * (j + 1)
            num_tmp += num_j

    if score >= G:
        num.append(num_tmp)

ans = min(num)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

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

    int idx = 0;
    int cnt = 0;
    for(;;) {
        if(idx == 1) {
            cout << cnt << endl;
            return 0;
        } else if(cnt >= n){
            cout << -1 << endl;
            return 0;
        } else {
            idx = a[idx] - 1;
            cnt++;
        }
    }

}


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

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,flag;
    int ard;
    cin>>n;
    for(int i = 1; i<=n; i++)
    {
        cin>>ard;
        if(ard%2==0)
        {
            flag = 0;
            if((ard%3==0)or(ard%5==0))
            {
                flag = 1;
            }
            else
                break;
        }
    }
    if(flag ==1)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;

    return 0;
}


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

#define ll long long

ll read(){
    char c= getchar(); ll f = 1, ret = 0;
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) ret = ret*10 + c - '0';
    return ret*f;
}
void write(ll x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) write(x / 10);
    putchar(x%10 + '0');
}
#define nl puts("")
#define bs putchar(' ')
int n; 
const int maxn = 2e5+5;
ll c[maxn], d[maxn];
ll sod, dig;
signed main(){
    n = read();
    for(int i = 1; i <= n; i++) {
        d[i] = read(), c[i] = read();
        sod += d[i]*c[i]; dig += c[i];
    }
    write((sod-1) / 9 + dig - 1);
    return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string s[3];
  int t = 0;
  for (auto& i : s) {
    cin >> i;
    reverse(i.begin(), i.end());
  }
  while (true) {
    if (s[t].empty()) {
      cout << (char)(t + 'A') << endl;
      return 0;
    }
    int p = s[t].back() - 'a';
    s[t].pop_back();
    t = p;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,M,X;
  cin>>N>>M>>X;
  int A=0;
  int B=0;
  REP(i,M){
    int a;
    cin>>a;
    if(a>X)A++;
    else B++;
  }
  cout<<min(A,B)<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BCommonRaccoonVsMonster solver = new BCommonRaccoonVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class BCommonRaccoonVsMonster {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            int h = ni();
            int n = ni();
            int sum = 0;
            int i = 0;
            for (i = 0; i < n; i++)
                sum += ni();
            if (sum >= h)
                pn("Yes");
            else
                pn("No");

        }

        int ni() {
            return in.nextInt();
        }

        void pn(String zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 34684
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 2333;
int s[N],k,a,b;
int calc(int c, int tp, int a, int b){
	if(a<0||b<0||c>k)return k+1;int mx=max(a,b),mn=min(a,b);
	if(tp==0&&a<b||tp==1&&a>b)return (mx-1)/(mn+1)+1;
	return (mx+c-1)/(mn+1)+1;
}
void print(int a, int b, int l, int r){
	if(l>r)return;
	rep(i,l,r)printf("%c",((i-1)%(a+b)+1<=a)?'A':'B');
}
int main() {
	int q;read(q);
	while(q--){
		int c,d;read(a);read(b);read(c);read(d);k=calc(0,0,a,b);
		int l=0,r,A,B;
		int L=1,R=min(a/k,b);
		while(L<=R){
			int mid=(L+R)>>1;
			if(calc(1,1,a-mid*k,b-mid)<=k)l=mid,L=mid+1;else R=mid-1;
		}
		a-=l*k;b-=l;int t=min(b/k,a);A=a-t;B=b-t*k;r=t;
	//	printf("%d %d %d %d",l,A,B,r);
		assert(A>=0&&A<=k&&B>=0&&B<=k);
		print(k,1,c,min(d,l*(k+1)));
		print(A,B,max(c-l*(k+1),1),min(d-l*(k+1),A+B));
		print(1,k,max(c-l*(k+1)-A-B,1),min(d-l*(k+1)-A-B,r*(k+1)));
		puts("");
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define int  unsigned long long
const int MOD = 1e9 + 7;
const int INF = 1e18;

int lcm(int a, int b){
  int g = __gcd(a, b);
  return a / g * b;	
}

int calc(int n, vector<int> v){
   int plen = (int)v.size();
   int sum = 0;
   for (int i = 1; i < (int)(1 << plen); i++){
	   int prod = 1;
	   int bits = 0;
	   for (int mask = 0; mask < plen; mask++){
		  if (i & (1 << mask)){
			bits++;
			prod = lcm(v[mask], prod);  
		  }   
		}
	  int curr = n / prod;
	  if (bits % 2 == 0) sum -= curr;
	  else sum += curr;  
	 }
   return sum;	
}

void solve(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a--;
  vector<int> v;
  v.push_back(c);
  v.push_back(d);
  int val1 = b - calc(b, v);
  int val2 = a - calc(a, v);
  int ret = val1 - val2;
  cout << ret << endl;
}

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   solve();
}


Measured memory_bytes: 256
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			Point2D.Double[] p = new Point2D.Double[n];
			int[] r = new int[n];
			for (int i = 0; i < n; i++) {
				p[i] = new Point2D.Double(scanner.nextDouble(),
						scanner.nextDouble());
				r[i] = scanner.nextInt();
			}

			int m = scanner.nextInt();

			boolean flag;
			for (int i = 0; i < m; i++) {
				Point2D.Double t = new Point2D.Double(scanner.nextDouble(),
						scanner.nextDouble());
				Point2D.Double s = new Point2D.Double(scanner.nextDouble(),
						scanner.nextDouble());
				Line2D.Double b = new Line2D.Double(s, t);
				flag = false;
				for (int j = 0; j < n; j++) {
					double sk = s.distance(p[j]);
					double tk = t.distance(p[j]);
					if ((sk > r[j] || tk > r[j]) && b.ptSegDist(p[j]) <= r[j]) {
						flag = true;
						break;
					}
				}
				System.out.println(flag ? "Safe" : "Danger");
			}
		}
	}
}

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

using namespace std;
using ll = long long;

int main() {
    ll D, T, S;
    cin >> D >> T >> S;
    if(S*T >= D) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int N, A, B;
int main() {
 scanf("%d %d %d",&N,&A, &B);
  if ( N * A > B) {
    cout << B << endl;
  }
  else if (N * A < B) {
  	cout << N * A << endl;
  }
  else {
  	cout << B << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string O, E;
  cin >> O >> E;
  int n = O.size(), m = E.size();
  for(int i = 0; i < m; i++){
    cout << O.at(i) << E.at(i);
  }
  if(n > m){
    cout << O.back();
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int k;cin>>k;
  queue<ll> Q;
  REP(i,9) {
    Q.push(i+1);
  }
  ll x;
  REP(i,k) {
    x = Q.front();
    int one_f = x%10;
    // pr(x);
    Q.pop();
    if(one_f%10!=0) Q.push(10*x+one_f-1);
    Q.push(10*x+one_f);
    if(one_f%10!=9) Q.push(10*x+one_f+1);
  }
  pr(x);
  return 0;
}


Measured memory_bytes: 1792
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  unordered_map<string, int64_t> m;
  for (int64_t i = 0; i < N; ++i) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (m.find(s) == m.end()) {
      m[s] = 1;
    } else {
      ++m[s];
    }
  }
  int64_t result = 0;
  for (const auto &p : m) {
    result += p.second * (p.second - 1) / 2;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 10368
# -*- coding: utf-8 -*-
x, k, d = map(int, input().split())
x = abs(x)
t = x // d
if t >= k:
    answer = x - (k * d)
else:
    if (k - t) % 2 == 0:
        answer = x - (t * d)
    else:
        answer = x - (t + 1) * d
        
print(abs(answer))

Measured memory_bytes: 9160
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define sqr(x) (x*x)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

//#define int ll


const int N = 2e5+33, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char pxy[] = {'R' , 'L' , 'D' , 'U'};
const double EPS = 1e-4;
const double PI = acos(-1.0);

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
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; }


typedef pair <int, int> pii;        // #include <ext/pb_ds/assoc_container.hpp>
typedef pair <ll, ll> pll;         // #include <ext/pb_ds/tree_policy.hpp>
typedef vector <int> vi;          // #include <ext/rope>
                // #include <ext/rope>
                                 // #include <ext/rope>
bool prime(int n) {             // template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}
ll bp(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

ll f[N] , inv[N];

ll sum(ll x) {
    return x*(x+1) / 2;
}

ll C(ll n , ll k) {
    return sum(n) - sum(n-k) - sum(k) + 1;
}

void solve() {
    f[0] = 1;
    inv[0] = 1;
    for(int i = 1; i < N; i ++) {
        f[i] = f[i-1] * i % mod;
        inv[i] = bp(f[i] , mod-2);
    }
    ll n , k , ans = 0;
    cin >> n >> k;
    ll t = k;
    n ++;
    for(; k <= n; k ++)
        ans = (ans + C(n , k)) % mod;
    k = t;
    cout << ans << '\n';
}

/*

*/

main() {
    ios;
    int tt = 1;
//    cin >> tt;
    while(tt --) {
        solve();
        cout << '\n';
    }
    return 0;
}
/*
++>
+++>
<[<+>-]<
++++++++++++++++++++++++++++++++++++++++++++++++.

500000000000000000000000000000000000000000000000

1 1 2 3 6


*/


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

int main(){
  int N;
  cin >> N;
  bool flag;
  int p;
  cin >> p;
  if(p==1){
    flag=true;
  }else{
    flag=false;
  }
  int64_t ans=0;
  for(int i=2;i<=N;i++){
    cin >> p;
    if(p==i){
      if(flag){
        ans++;
        flag=false;
      }else{
        flag=true;
      }
    }else{
      if(flag){
        ans++;
        flag=false;
      }
    }
  }
  if(flag){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
fact = [1] + (1..10).map {|x| (1..x).inject(:*)}
require 'matrix'

s, n, k = gets.split.map(&:to_i)
s = -s if s < 0

if s == 0
	puts 0
	exit
end

if n == 1
	puts s % k == 0 ? s / k : -1
	exit
end

i = 0
total = 0
a = (0..n*k).map { (0..n*k).map { 0 } }
(1..n).to_a.repeated_combination(k).each do |comb|
	step = comb.inject(:+)
	num = fact[k] / comb.group_by{|x| x}.values.map{|a| fact[a.size]}.inject(:*)
	(1..n*k).each do |i|
		a[i][(i-step).abs] += num
	end
	total += num
end

a.map!{|row| row.map {|x| x.to_f / total}}
a[0][0] = 1.0
m = Matrix[*a]
absorb = (Matrix.I(n*k) - m.minor(1..n*k, 1..n*k)).inv * Matrix[*[[1] * (n*k)].transpose].column(0)

if s <= n * k
	puts absorb[s-1].to_f
	exit
end

absorb = Vector[*(absorb.to_a + [1])]

b = (0..n*k).map { (0..n*k).map { 0 } } 
(0..n*k-1).each do |i|
	b[i][i+1] = 1
end
b[-2] = a[-1]
b[-2][-1] = 1
b[-1][-1] = 1

def exp(n, k, v)
	result = v	
	r = n
	while k > 0
		result = r * result if k & 1 == 1
		r *= r		
		k >>= 1
	end
	result
end

p exp(Matrix[*b], (s-n*k), absorb).to_a[-2].to_f

Measured memory_bytes: 11804
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long n, m, b = 0, e;
	string s; cin >> s >> n;
	if (n >= s.size()) {
		n = s.size();
	}
	for (int h = 0; h < n; h++) {
		if ((s[h] - '0') != 1 && b == 0) {
			cout << s[h] << endl;
			b++;
		}
	}
	if (b == 0) {
		cout << '1' << endl;
	}
	cin >> e;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();

        int i = 0;
        int num = 0;
        while(true) {
            do {
              num ++;
            } while(num % 100 == 0);
            i++;
            if(n == i) {
                break;
            }
        }
        for(;d>0;d--) {
            num *= 100;
        }
        System.out.println(num);
    }

}


Measured memory_bytes: 23380
#include <iostream>

void output_n_char(unsigned n, char c)
{
  for (unsigned i = 0; i < n; ++i) {
    std::cout << c;
  }
}

int main()
{
  long sx, sy, tx, ty;
  std::cin >> sx >> sy >> tx >> ty;
  
  unsigned w = tx - sx, h = ty - sy;
  
  output_n_char(w, 'R');
  output_n_char(h, 'U');
  
  output_n_char(w, 'L');
  output_n_char(h, 'D');
  
  std::cout << 'D';
  output_n_char(w + 1, 'R');
  output_n_char(h + 1, 'U');
  std::cout << 'L';
  
  std::cout << 'U';
  output_n_char(w + 1, 'L');
  output_n_char(h + 1, 'D');
  std::cout << 'R';
  
  std::cout << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    xy=Tuple{Int,Int}[(0,0) for i in 1:n]
    for i in 1:n
        x,y=parseMap(split(readline()))
        xy[i]=x,y
    end
    ans=.0
    for i in 1:n
        for j in 1:n
            ans+=sqrt((xy[i][1]-xy[j][1])^2+(xy[i][2]-xy[j][2])^2)
        end
    end
    println(ans/n)
end
main()

Measured memory_bytes: 113596
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>
 
using namespace std;
typedef long long LL;
const int INF = int(1e9);
 
double A,B,C,D,E,F;
double Ai,Bi;
double maxx1 = -1,maxx2 = 1;
 
int main()
{
    cin>>A>>B>>C>>D>>E>>F;
    Ai = A*E; Bi = B*E;
    double tan,kefan,sum;
 
    for(int a = 0;a*A*100<=F;a++)
    for(int b = 0;b*B*100<=F-a*A*100;b++)
    for(int c = 0;c*C<=F-a*A*100-b*B*100;c++)
    for(int d = 0;d*D<=F-a*A*100-b*B*100-c*C;d++)
    {
        tan = c*C+d*D;
        sum = A*a*100+B*b*100+tan;
        kefan = Ai*a+Bi*b;
        //cout<<a<<"->"<<b<<" "<<c<<" "<<d<<endl;
       // cout<<sum<<" "<<tan<<" "<<kefan<<endl;
        if(kefan<tan||sum>F)continue;
 
        if(sum!=0&&tan/sum>maxx2/maxx1){
            maxx1 = sum;
            maxx2 = tan;
        }
    }
    cout<<int(maxx1)<<" "<<int(maxx2)<<endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
args = list(map(int, input().split()))
ballset = set(args)
balls = {}
for ball in ballset:
    balls[ball] = 0
for i in args:
    balls[i] += 1
count = len(ballset)
if count <= K:
    print (0)
else:
    print (sum(sorted(balls.values())[0:max(count-K, 0)]))


Measured memory_bytes: 46112