akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        int n = Integer.parseInt(br.readLine().trim());
        for(int i=n; i>0; i--){
            int tmp = i;
            while (tmp> 0){
                if (tmp == 1){
                    System.out.println(i);
                    return;
                }
                else if (tmp %2 != 0){
                    break;
                }
                tmp /= 2;
            }
        }

    }

}



Measured memory_bytes: 32508
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;


int H,W;
vector<string> S;


vector<int> dh = {1, -1, 0, 0};
vector<int> dw = {0, 0, 1, -1};

ll ans = 0;
ll white = 0;
ll black = 0;

void dfs(int i, int j, int s){
    
    rep(k,4){
        int h = i + dh[k];
        int w = j + dw[k];
        
        if(0 <= h && h < H && 0 <= w && w < W){
            if(s == 0 && S[h][w] == '#'){
                S[h][w] = '*';
                black++;
                dfs(h,w,1);
            }else if(s == 1 && S[h][w] == '.'){
                S[h][w] = '*';
                white++;
                dfs(h,w,0);
            }
        }
    }
    
}


int main()
{
    cin >> H >> W;
    S.resize(H);
    rep(i,H) cin >> S[i];
    rep(i,H) rep(j,W){
        if(S[i][j] == '.'){
            white = 1, black = 0;
            S[i][j] = '*';
           
          
            dfs(i,j,0);
            ans += (white*black);
          
        }
        
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 15488
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ std::cin >> head; _cin(std::forward<Tail>(tail)...); }
void _cout(){ std::cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ std::cout << head; _cout(std::forward<Tail>(tail)...); }
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; For(i, n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__);
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

using namespace std;
using ll = long long;

int main(void){
    Cin(string, s);
    Sort(s);
    Coutyn(unique(Range(s)) == s.end());
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  int n;
  cin >> n;
  int count = 0;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 2){
      count--;
    }
    for (int j = 2; j < sqrt(a) + 1; j++) {
      if (a % j == 0) {
        count++;
        break;
      }
    }
  }
  cout << (n - count) << endl;
  return 0;
}



Measured memory_bytes: 3080
#設定
import sys
input = sys.stdin.buffer.readline

import math
#ライブラリインポート
from collections import defaultdict

INF = float("inf")

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

#処理内容
def main():
	a, b, x = getlist()
	if 2 * x >= (a ** 2) * b:
		ans = (2 * (a ** 2) * b - 2 * x) / (a ** 3)
		ans = math.atan(ans)
		ans = math.degrees(ans)
		print(ans)
	else:
		m = 2 * x / (a * b)
		ans = math.atan(m / b)
		ans = math.degrees(ans)
		print(90 - ans)

if __name__ == '__main__':
	main()

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

int main(){
  int N,M;
  cin >> N >> M;
  vector <int> s(M),c(M);
  for(int i=0;i<M;i++){
    cin >> s[i] >> c[i];
  }
  
  for(int i=0;i<M;i++){
    for(int j=0;j<M;j++){
      if(s[i] == s[j]){
        if(c[i] != c[j]){
          cout << "-1" << endl;
          return 0;
        }
      }
    }
  }
  
  for(int i=0;i<M;i++){
    if(s[i] == 1 && c[i] == 0 && N != 1){
      cout << "-1" << endl;
      return 0;
    }
  }
  
  int ans = 0;
  int  flag1,flag2,flag3;
  flag1 = 0;
  flag2 = 0;
  flag3 = 0;
  
  for(int i=0;i<M;i++){
    if(s[i] == 1 && flag1 == 0){
      ans += c[i]*pow(10,N-1);
      flag1++;
    }
    if(s[i] == 2 && flag2 == 0){
      ans += c[i]*pow(10,N-2);
      flag2++;
    }
    if(s[i] == 3 && flag3 == 0){
      ans += c[i];
      flag3++;
    }
  }
  
  if(flag1 == 0){
    if(N==2) ans += 10;
    if(N==3) ans += 100;
  }
    
  cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define sc second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;
int main(){
  ll k;cin>>k;
  ll dp[15][10];
  ll vk[16];
  rep(i,10)dp[0][i]=1;
  
  Rep(i,1,15){
    rep(j,10){
      if(j==0){dp[i][0]=dp[i-1][0]+dp[i-1][1];}
      else if(j==9){dp[i][9]=dp[i-1][8]+dp[i-1][9];}
      else{
        dp[i][j]=dp[i-1][j-1]+dp[i-1][j]+dp[i-1][j+1];
      }
    }
  }
  ll s[15];
  rep(i,15){
    s[i]=0;
    Rep(j,1,10) s[i]+=dp[i][j];
  }
  
  ll cnt=0;
  ll c=0;
  rep(i,15){
    c=i;
    if(cnt+s[i]>k) break;
    cnt+=s[i];
  }
  if(c==0) {cout<<k<<endl;}
  else{
  ll cans=c;
  Rep(i,1,10){
    vk[c]=i;
    if(cnt+dp[c][i]>=k) break;
    cnt=cnt+dp[c][i];
  }
  
  while(c>1){
    if(vk[c]==0){
      if(cnt+dp[c-1][0]>=k){
        vk[c-1]=0;
      }
      else{
        vk[c-1]=1;
        cnt=cnt+dp[c-1][0];
      }
    }
    else if(vk[c]==9){
      if(cnt+dp[c-1][8]>=k){
        vk[c-1]=8;
      }
      else{
        vk[c-1]=9;
        cnt=cnt+dp[c-1][8];
      }
    }
    else{
      if(cnt+dp[c-1][vk[c]-1]>=k){
        vk[c-1]=vk[c]-1;
      }
      else if(cnt+dp[c-1][vk[c]-1]+dp[c-1][vk[c]]>=k){
        vk[c-1]=vk[c];
        cnt=cnt+dp[c-1][vk[c]-1];
      }
      else{
        vk[c-1]=vk[c]+1;
        cnt=cnt+dp[c-1][vk[c]-1]+dp[c-1][vk[c]];
      }
      
    }
    c--;
  }
    c--;
  k=k-cnt;
 if(vk[c+1]==0){
   if(k==1){
     vk[c]=0;
   }
   else{
     vk[c]=1;
   }
 }
 
  else if(vk[c+1]==9){
    if(k==1){
     vk[c]=8;
   }
   else{
     vk[c]=9;
   }
    
  }
  else{
    if(k==1){
     vk[c]=vk[c+1]-1;
   }
    else if(k==2){
     vk[c]=vk[c+1];
   }
   else{
     vk[c]=vk[c+1]+1;
   }
  }
  rep(i,cans+1){
    cout<<vk[cans-i];
  }
  }
  cout<<endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
const ll INF = 1e9;
int main(){//0-index
    int n; cin >> n;
    vector<vector<int> > F(n,vector<int>(14));
    vector<vector<int> > P(n,vector<int>(15));
    rep(i,n){
        rep(j,10){
            cin >> F[i][j];
        }
    }
    rep(i,n){
        rep(j,11){
            cin >> P[i][j];
        }
    }
    ll ans=-INF;
    for(int bit=1;bit<(1<<10);++bit){//bitの2進数表記した時に1である桁に対応した日に自分が営業している
        vector<int> ct(n);
        rep(i,n) ct[i]=0;
        ll res=0;
        rep(i,10){//i番目の時間帯に営業しているか調べる
            if(bit & (1<<i)){//i番目の時間帯に自分の店が営業している時
                rep(j,n){
                    ct[j]+=F[j][i];//j番目の店が時間帯iに営業しているか
                }
            }
        }
        rep(i,n) res += P[i][ct[i]];
        ans = max(ans,res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
#either way it works
#nums=list(map(int,input().split()))
nums=[int(x) for x in input().split()]
ans='Yes'
if(len(nums))<2:
    ans='Yes'
else:
    for i in range(len(nums)-1,0,-1):
        if nums[i-1] > nums[i]:
            nums[i-1] -=1
            if(nums[i-1] > nums[i]):
                ans='No'
                break
print(ans)

Measured memory_bytes: 14396
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long LL;
int n;
LL A[200010],sum[200010],nex[200010];
inline LL Abs(LL a){return a<0?-a:a;}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld",&A[i]);
		sum[i]=sum[i-1]+A[i];
	}
	for(int i=n;i>=1;--i){
		nex[i]=nex[i+1]+A[i];
	}
	LL ans=0x7f7f7f7f7f7f7f7fLL;
	for(int i=1;i<n;++i){
		ans=min(ans,Abs(sum[i]-nex[i+1]));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
package main

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

var sc = bufio.NewScanner(os.Stdin)

func contains(target string, list []string) bool {
	for _, r := range list {
		if target == r {
			return true
		}
	}
	return false
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()

	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextF64() float64 {
	sc.Scan()

	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func isInteger(x float64) bool {
	return math.Floor(x) == x
}

func Ave(s []int) int {
	val := 0
	for _, i := range s {
		val += i
	}
	return int(val / len(s))
}
func cal(i int) (sum int) {
	for i != 0 {
		sum += i % 10
		i /= 10
	}
	return
}
func max(a []int) (idx int, val int) {
	max := a[0]
	idx = 0
	for j, i := range a {
		if max < i {
			max = i
			idx = j
		}
	}
	return idx, max
}

func draw(i int, a []int) (l []int) {
	// p = a[i]
	for j := i; j < len(a); j++ {
		if j != len(a)-1 {
			a[j] = a[j+1]
		} else if j == len(a)-1 {
			a = a[:len(a)-1]
		}
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer([]byte{}, math.MaxInt64)
	// a := make([][]int, 3)
	// for i := 0; i < 3; i++ {
	// 	a[i] = make([]int, 3)
	// }
	// for i := 0; i < 3; i++ {
	// 	for j := 0; j < 3; j++ {
	// 		a[i][j] = nextInt()
	// 	}
	// }
	a := nextInt()
	b := nextInt()
	c := nextInt()
	var cnt int

	for a%2 == 0 && b%2 == 0 && c%2 == 0 {
		ap := b/2 + c/2
		bp := a/2 + c/2
		cp := a/2 + b/2
		a, b, c = ap, bp, cp
		cnt++
		if ap == bp && bp == cp {
			fmt.Println(-1)
			return
		}
	}

	fmt.Println(cnt)

}


Measured memory_bytes: 1772
H, W = [int(x) for x in input().split()]

G = [" " * (W+2)] + [" " + input() + " " for _ in range(H)] + [" " * (W+2)]

for r in range(1, H+1):
    for c in range(1, W+1): 
        if G[r][c] != '.':
            print(G[r][c], end="")
        else:
            print(sum(1 for x in [
                G[r-1][c-1],
                G[r-1][c],
                G[r-1][c+1],
                G[r][c-1],
                G[r][c+1],
                G[r+1][c-1],
                G[r+1][c],
                G[r+1][c+1]] if x == '#'), end="")
    print()

                          



Measured memory_bytes: 3444
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long ans = ((N-1)*N)/2;
        System.out.printf("%d\n",ans);
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};
vector<ll> col[500005];

int main(){
    ll n, q;
    cin >> n >> q;
    vector<int> c(n);
    rep(i, n) {
        cin >> c[i];
        c[i]--;
    }

    vector<pair<P, int> > query;
    vector<int> ans(q);

    rep(qi, q) {
        ll l, r;
        cin >> l >> r;
        l--; r--;
        query.eb(P(l, r), qi);
    }
    auto comp = [](pair<P, int> a, pair<P, int> b) {
        return a.first.second<b.first.second;
    };
    sort(whole(query), comp);
    BIT<ll> bit(n+5);

    vector<int> la(n, -1);
    int index = 0;
    rep(i, n) {
        ll prev = la[c[i]];
        if (prev>=0) bit.add(prev, -1);
        la[c[i]] = i;
        bit.add(i, 1);
        while (index<q) {
            if (query[index].first.second>i) {
                break;
            }
            ll z = bit.sum(query[index].first.second)-bit.sum(query[index].first.first-1);
            ans[query[index].second] = z;
            index++;
        }
    }
    rep(i, q) {
        cout << ans[i] << endl;
    }


    return 0;
}


Measured memory_bytes: 31148
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define int long long int
#define ff first
#define ss second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define MOD 1000000007
#define MAX 200005
#define sz size()
ll power(ll n,ll x)
{
    if(x==0)   return 1;
    if(x%2==0) return power(n*n,x/2);
    else       return n*power(n*n,x/2);
}
bool prime(ll n)
{
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0) return false;
    return true;
}
ll powermode(ll n,ll x)
{
    if(x==0) return 1;
    ll y=((n%MOD)*(n%MOD))%MOD;
    if(x%2==0)  return powermode(y,x/2)%MOD;
    else    return ((n%MOD)*(powermode(y,x/2)%MOD))%MOD;
}
ll inv(ll a){ return powermode(a,MOD-(ll)2);}
ll mul(ll x,ll y) { return ((x%MOD)*(y%MOD))%MOD; }
ll sum(ll x,ll y) { return ( x%MOD+ y%MOD) %MOD;}
ll sub(ll x,ll y) {  return ((x%MOD)-(y%MOD)+MOD)%MOD;}
ll divide(ll x,ll y) { return mul(x,inv(y));}
ll N;
ll dfs(ll n, vector<ll>&v, vector< vector<ll> > &adj, vector<ll> &vis)
{
    ll cnt=0;
    vis[n]=true;
    for(auto x:adj[n])
    {
        if(!vis[x])
        {
            ll xx=dfs(x,v,adj,vis);
            cnt+=xx;
            v.pb( xx*(N-xx));
        }
    }
    return cnt+1;
}
ll i,j;
   void solve()
   {
       ll n,x,t;
       cin>>n>>x>>t;
       cout<<ll(t*ceil(n/(1.0*x)));
   }
   
            signed main()
            {
               FAST;
               ll q=1;
            //    cin>>q;
	            while(q--)
                {
                   solve();
                }
            }



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<string> r{"dream", "dreamer", "erase", "eraser"};
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    for (int i = 0; i < r.size(); i++) reverse(r[i].begin(), r[i].end());

    bool can;

    for (int i = 0;;) {
        can = false;
        for (string s : r) {
            if (i + s.size() > S.size()) continue;
            if (S.substr(i, s.size()) == s) {
                can = true;
                i += s.size();
                break;
            }
        }
        if (can == false) {
            cout << "NO" << '\n';
            return 0;
        }
        if (S.size() - 5 < i && i < S.size()) {
            cout << "NO" << '\n';
            return 0;
        }
        else if (i == S.size()) {
            cout << "YES" << '\n';
            return 0;
        }
        else if (i > S.size()) {
            cout << "NO" << '\n';
            return 0;
        }
    }
}

Measured memory_bytes: 512
def sks(c,d):
    if c==0:
        return(d)
    else:
        return(sks(d%c,c))
a,b,c,d=list(map(int,input().split()))
s=sks(min(c,d),max(c,d))
t=int(c*d//s)
e=b-b//c-b//d+b//t
f=(a-1)-(a-1)//c-(a-1)//d+(a-1)//t
print(int(e-f))

Measured memory_bytes: 3064
s = input()
ans = 'Yes'
if len(s)%2 == 1:
  ans = 'No'
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] != 'h':
      ans = 'No'
      break
  else:
    if s[i] != 'i':
      ans = 'No'
      break
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
    char c;
    cin >> c;
    if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}

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

typedef long long ll;

const ll inf = 1e9;
const ll inff = 1e18;

ll n, a, b, c, d;
map<ll, ll> dp;

ll solve (ll n) {
	if (n == 0) return 0;
	if (n == 1) return d;
	if (n == 2) return d + min(d, a);
	if (dp.count(n)) return dp[n];

	ll ret = inff;
	if (inff / d >= n) ret = n * d;
	ret = min(ret, a + n % 2 * d + solve(n / 2));
	ret = min(ret, a + (2 - n % 2) * d + solve(n / 2 + 1));
	ret = min(ret, b + n % 3 * d + solve(n / 3));
	ret = min(ret, b + (3 - n % 3) * d + solve(n / 3 + 1));
	ret = min(ret, c + n % 5 * d + solve(n / 5));
	ret = min(ret, c + (5 - n % 5) * d + solve(n / 5 + 1));
	return dp[n] = ret;
}

int main (void) {
	int kase;
	scanf("%d", &kase);
	while (kase --) {
		scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
		dp.clear();
		printf("%lld\n", solve(n));
	}
}

Measured memory_bytes: 4900
#include <iostream>
#include <algorithm>
#include <queue>
#include <deque>

using namespace std;
typedef pair<int, int> p;

bool pairCompare(const p& firstElof, const p& secondElof)
{
	return firstElof.second > secondElof.second;
}

int main(void) {
	int N;
	cin >> N;
	priority_queue<int> A;
	for (int i = 0; i < N; i++) {
		int ai;
		cin >> ai;
		A.push(ai);
	}
	deque<p> sukima;
	sukima.push_front(p(A.top(), A.top())); //max,minのペアの列
	A.pop();

	long long ans = 0;
	while (!A.empty()) {
		//順番に詰めていく
		int a = A.top();
		int sukima_front_max = sukima.front().first;
		int sukima_front_min = sukima.front().second;
		ans += sukima_front_min;
		sukima.pop_front();
		sukima.push_back(p(sukima_front_max, a));
		sukima.push_back(p(sukima_front_min, a));

		A.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5228
#include <iostream>
#include <vector>

using namespace std;

int maxHappines(vector<vector<int> >& activites){
  int n = activites.size();
  int res = 0;
  vector<vector<int> > dp(n, vector<int>(3, 0));

  dp[0][0] = activites[0][0];
  dp[0][1] = activites[0][1];
  dp[0][2] = activites[0][2];

  for(int i = 1; i < n; i++){
    for(int j = 0; j < 3; j++){
      int k = j + 1;
      dp[i][j] = max(dp[i - 1][k % 3], dp[i - 1][(k + 1) % 3]) + activites[i][j];
    }

    // dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + activites[i][0];
    // dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + activites[i][1];
    // dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + activites[i][2];
  }
  res = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])); // c++14 gcc 5.4.1
  // max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}); // c++14 clang 3.8.0
  return res;
}

int main(){

  int n;
  cin >> n;
  vector<vector<int> > activites(n, vector<int>(3));
  for(int i = 0; i < n; i++){
  	for(int j = 0; j < 3; j++){
      cin >> activites[i][j];
    }
  }

  cout << maxHappines(activites) << endl;
  //cout << "Similar Problems: " << endl;
  //cout << "LC-198, LC-213, LC-256,  LC-265" << endl;
  return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main (){
  int d;
  cin >> d;
  if (d==25){
    cout << "Christmas" << endl;
  }else if(d==24) {
    cout << "Christmas Eve" << endl;
  }else if (d==23) {
    cout << "Christmas Eve Eve" << endl;
  }else {
    cout << "Christmas Eve Eve Eve" << endl;
  }
}

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

signed main() {
  int n,h; cin>>n>>h;

  vector<int> b(n);
  int _max=0;
  for(int i=0;i<n;++i) {
    int p,q; cin>>p>>q;
    _max = max(_max,p);
    b[i] = q;
  }
 
  sort(b.begin(), b.end(), greater<int>());
  
  int ans=0, sm=0;
  for(int i=0;i<n;++i) {
    // 降るよりも効率の良いKATANAがあれば, 投げる
    if(b[i] > _max){
      sm += b[i];
      ++ans;
    }
    if(sm >= h) break;
  }
 
  // 投げた後に, ひたすら効率の良いKATANAを降り続ける
  if(sm < h) ans += (h-sm + _max-1)/_max;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 1e6 + 10 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 1e9 + 7 ;
const double eps = 1e-7 ;
template <class T> void read(T &a)
{
	int f = 1 ; a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	a *= f;
}

ll n, m;

ll a[maxn], last[maxn], nex[maxn], w[maxn], link[maxn], cnt, start;

ll ans[maxn], tot;

ll s[maxn];

ll vis[maxn];

void search(ll now, ll step)
{
	if(vis[now])
	{
		if(vis[now] == cnt) start = now, link[now] = step - s[now];
		return;
	}
	vis[now] = cnt;
	s[now] = step;
	search(nex[now], step + w[now]);
	if(start == now) start = 0;
	if(start) link[now] = link[nex[now]];
	return ;
}

signed main()
{
	scanf("%lld %lld", &n, &m);
	rep(i, 1, n) scanf("%lld", &a[i]);
	rep(i, n + 1, 2 * n) a[i] = a[i - n];
	per(i, 2 * n, 1)
	{
		if(i <= n)
		{
			nex[i] = last[a[i]] % n + 1;
			w[i] = (last[a[i]]) / n - (i - 1) / n;
		}
		last[a[i]] = i;
	}
	rep(i, 1, n) if(!vis[i]) ++cnt, search(i, 0);
	// rep(i, 1, n) printf("%lld %lld %lld\n", nex[i], w[i], link[i]);
	// puts("");
	ll now = 0;
	while(m >= 0)
	{
		// printf("%lld %lld %lld\n", m, now, tot);
		if(!m && now == n) break;
		now = now % n + 1;
		ans[++tot] = a[now];
		if(now == 1) m--;
		if(link[now]) if(m >= link[now]) m %= link[now];
		if(w[now] - (nex[now] == 1) <= m)
		{
			m -= w[now] - (nex[now] == 1);
			tot --, now = nex[now] == 1 ? n : nex[now] - 1;
		}
	}
	rep(i, 1, tot) printf("%lld ", ans[i]);
	return 0;
}

Measured memory_bytes: 34816
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;


#define INF (1ll<<60)
int main(int argc, char const *argv[]) {
  map<char,int> mem;
  int n;cin>>n;
  for(char c = 'a';c<='z';c++)mem[c]=1<<30;
  // for(char c = 'a';c<='z';c++)cout<<c<<mem[c];
  for(int i=0;i<n;i++){
    map<char,int> nums;
    string s;cin>>s;
    for(char c:s)nums[c]++;
    for(char c = 'a';c<='z';c++)mem[c]=min(mem[c],nums[c]);
  }
  for(char c = 'a';c<='z';c++){
    for(int j=0;j<mem[c];j++)cout<<c;
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
W, H = map(int, input().split())
p = [int(input()) for _ in range(W)]
q = [int(input()) for _ in range(H)]
edges = []
for i in range(W):
    edges.append((p[i], 0))
for i in range(H):
    edges.append((q[i], 1))
edges.sort()
cnt_h = 0
cnt_w = 0
res = 0
for c, d in edges:
    if d == 0:
        cnt_w+=1
        res+=(H+1-cnt_h)*c
    else:
        cnt_h+=1
        res+=(W+1-cnt_w)*c
print(res)



Measured memory_bytes: 73816
#include <iostream>
#include <vector>

using namespace std;

class UnionFind {

public:
    vector<int> par;
    vector<int> rank;
    vector<int> relative_diff;
    
    UnionFind( int n ) {
	par.resize( n );
	rank.resize( n );
	relative_diff.resize( n );
	for ( int i=0; i<n; ++i ) par[i] = i;
    }

    int Root( int x ) {

	if ( x == par[x] ) return x;

	int r = Root( par[x] );
	relative_diff[x] += relative_diff[par[x]];
	par[x] = r;
	return r;
    }
    
    bool IsSame( int x, int y ) {
	return Root( x ) == Root( y );
    }

    void Merge( int x, int y, int w=0 ) {

	w += TotalDiff( x );
	w -= TotalDiff( y );	
	
	x = Root( x );
	y = Root( y );

	if ( x == y ) return;

	if ( rank[x] < rank[y] ) {//yの方が深い
	    relative_diff[x] = -w;
	    par[x] = y;//xをyのグループのルートにつなぐ
	}
	else {//xの方が深いか 同じ深さ
	    relative_diff[y] = w;
	    par[y] = x;//yをxのグループのルートにつなぐ
	    if ( rank[x] == rank[y] ) ++rank[x];
	}
	
    }

    int TotalDiff( int x ) {
	Root( x );
	return relative_diff[x];
    }
    
    int Diff( int x, int y ) {
	return TotalDiff( y ) - TotalDiff( x );
    }
};

int main() {

    int n, l;
    cin >> n >> l;
    
    UnionFind un(n);

    for ( int i=0; i<l; ++i ) {
	int type, a, b;
	cin >> type >> a >> b;
	if ( type == 0 ) {
	    //	    int w;  cin >> w;
	    //	    un.Merge( a, b, w );
	    un.Merge( a, b );
	}
	else {
	    if ( un.IsSame( a, b ) ) cout << "1" << endl;
		//		cout << un.Diff( a, b ) << endl;
	    else  cout << "0" << endl;
		//		cout << "?" << endl;
	}
    }

    
    return 0;
}



Measured memory_bytes: 3228
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sim         template < class c
#define ris         return * this
#define dor         > debug & operator <<
#define eni(x)      sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

using namespace std;

sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug 
{
	~debug() 
	{ 
		cerr<<endl; 
	}
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int k,a,b;
		cin>>k>>a>>b;
		for(ll int i=0;i<=100000;i++)
		{
			if(a<=i*k && i*k<=b)
			{
				cout<<"OK";
				return 0;
			}
		}
		cout<<"NG"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
	int n;
	cin >> n;
    int X[n];
    for ( int i = 0; i < n; i++ ){
        cin >> X[i];
    }
    // 全て回す
    int min = INT_MAX;
    for ( int held = 1; held < 101; held++ ){
        int sum = 0;
        for ( int i = 0; i < n; i++ ){
            sum += (held - X[i]) * (held - X[i]);
        }
        if ( sum < min ){
            min = sum;
        }
    }
	cout << min << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;

typedef tree<pair<long long,int>, null_type, less<pair<long long,int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define all(num) num.begin(), num.end()
#define lp(i, nodess) for (int i = 0; i < nodess; i++)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define X real()
#define Y imag()
#define angle(u) (atan2(u.Y, u.X))
#define vec(u, v) ((v) - (u))
//#define length(u) (hypot(u.Y , u.X))
#define normalize(u) (u) / length(u)
#define dotP(u, v) ((conj(u) * v).X)
#define crossP(u, v) ((conj(u) * v).Y)
#define same(p1, p2) (dotP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthSqr(u) dotP(u, u)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(vis, m) conj(vis / m) * m
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double PI = acos(-1.0);
const double EPS = (1e-10);
const long long int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
typedef long long int ll;
typedef unsigned long long ull;
typedef complex<double> point;
long long fastpow(ll nodess, ll num) {
  if (!num)
    return 1;
  if (num % 2)
    return nodess * fastpow(nodess, num - 1)/*%mod*/;
  ll p = fastpow(nodess, num / 2);
 // p %= mod;
  p *= p;
 // p %= mod;
  return p;
}

ll my_mod(ll num, ll mod) {
  ll reto = num % mod;
  while (reto < 0)
    reto += mod;
  return reto;
}

ll gcd(ll u, ll v) { return !u ? v : gcd(v % u, u); }
long long dist(pair<ll, ll> u, pair<ll, ll> v) {
  return 
      abs(u.f - v.f)  + abs(u.se - v.se);
}



/*vector<int> ap;
int np[MX+5];
void s(){
    mem(np , 1);
    np[1] = np[0] = 0;
    for(ll i = 2 ; i*i<= MX ;i++){
        if(np[i]){
            for(ll j= i*i ; j <=MX; j+=i) np[j] = 0;
        }
    }
    int idx = 1;
    for(ll i = 2 ; i<= MX ; i++){
		if(np[i]){
			np[i] = idx;
			idx++; 
			ap.pb(i);
		}
	}
	//cout<<idx;
}*/
const int MX = 1e5 + 9;
ll arr[MX];

ll get(ll x){
	ll ret =0;
	while(x){
		if(x%10) return ret;
		ret++;
		x/=10;
	}
	return ret;
}
int main()
{
    IO;
/*	arr[0] = arr[1] = 1;
	for(int i = 2; i<= 10000; i++){
		arr[i] = i * arr[i-2];
		arr[i] %= mm;
		int n = i;
		int mans = 0;
			if(n%2) mans = 0;
	else mans = n/10 + n/50;
	if(mans != get(arr[i])){
		cout<<i<<" "<<get(arr[i])<<" "<<mans<<"\n";
		cout<<i<<"\n";
		break;
	}
	//	cout<<i<<" "<<get(arr[i])<<" "<<mans<<"\n";
		
	}*/
	vector<ll> nums;
	ll a = 5;
	for(int i = 0 ;i < 26 ; i++){
		//cout<<a<<"\n";
		nums.pb(a);
		a *= 5;
	}
	
	ll n;
	cin>>n;
	if(n == 0) return cout<<0,0;
	if(n%2) cout<<0;
	else{
		ll ans = (n/5)/2;
		int j = 1;
		while(n/nums[j] > 0){
			ans += (n/nums[j])/2;
			j++;
		}
		
		cout<<ans<<"\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    const int n = 5;
    int sum = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        b.at(i) = a.at(i) % 10;
        if (b.at(i) != 0) {
            a.at(i) = a.at(i) + (10 - b.at(i));
        }
        sum += a.at(i);
    }
    for (int i = 1; i < 10; i++) {
        for (int j = 0; j < n; j++) {
            if (b.at(j) == i) {
                sum -= 10 - b.at(j);
                goto last;
            }
        }
    }
    last:
    cout << sum << endl;
}


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

#define LL 					long long
#define ULL 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define mp 					make_pair
#define vi 					vector<int>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x)				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = (1<<30)-1+(1<<30);
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

const int MAXN = 1e5+5;
int n, x[MAXN], y[MAXN], id[MAXN], p[MAXN];
bool cmpx (int a, int b) {
	return x[a]<x[b];
}
bool cmpy (int a, int b) {
	return y[a]<y[b];
}

vector < pair< int , pii > > all;

int fs (int x) {
	if (x!=p[x]) return p[x] = fs(p[x]);
	return x;
}

int main() {
	gi(n);
	for (int i=1; i<=n; i++) {
		gi(x[i]); gi(y[i]);
		id[i] = i; p[i] = i;
	}
	sort(id+1, id+1+n, cmpx);
	for (int i=2; i<=n; i++) {
		int now = id[i], bef = id[i-1];
		all.psb({x[now]-x[bef], {now,bef}});
	}
	sort(id+1, id+1+n, cmpy);
	for (int i=2; i<=n; i++) {
		int now = id[i], bef = id[i-1];
		all.psb({y[now]-y[bef], {now,bef}});
	}
	sort(all(all));
	LL ans = 0LL;
	for (auto xx : all) {
		int x = fs(xx.se.fi), y = fs(xx.se.se);
		if (x==y) continue;
		ans += (LL)xx.fi;
		p[x] = y;
	}
	printf ("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 6516
import Control.Monad
import Control.Applicative

diff :: [Int] -> Int
diff xs = head xs - last xs


solver :: [[Int]] -> [Int]
solver = fmap diff

main :: IO()
main = do
  inputs <- map (map (read :: String -> Int) . words) <$> replicateM 7 getLine
  mapM_ print $ solver inputs

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n, m;
  cin >> n >> m;

  vector<int> s(m), c(m);
  string ans = "-1";

  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;

    if (s[i] == 0 && c[i] == 0) {
      ans = "-1";
    }
  }

  for (int i = 0; i < m; i++) {
    int k = s[i];
    int v = c[i];
    for (int j = 0; j < m; j++) {
      if (i == j) continue;
      int k2 = s[j];
      int v2 = c[j];

      if (k == k2 && v2 != v) {
        ans = "-1";
        break;
      }
    }
  }

  for (int num = 0; num < 1000; num++) {
    string ns = to_string(num);
    int keta = ns.size();

    if (keta != n) continue;

    bool ok = true;
    for (int i = 0; i < m; i++) {
      if (ns[s[i]] - '0' != c[i]) {
        ok = false;
      }
    }

    if (ok) {
      ans = ns;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[15];
long long ans=0;
void dfs(int x,int cnt)
{
	for (int i=a[x]-1;i<=a[x]+1;i++)
	{
		if (i%2==0) cnt++;
		if (x==n)
		{
		    if (cnt){
			ans++;}
		}
		else dfs(x+1,cnt);
		if (i%2==0) cnt--;
	}
}
int main()
{
	cin>>n;for (int i=1;i<=n;i++) cin>>a[i];
	dfs(1,0);
	printf("%lld\n",ans);
}




Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from collections import deque as deq

N = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)
    exit()

r = 1
l = 10**18
for a in A:
    r *= a
    if r > l:
        r = -1
        break

print(r)


Measured memory_bytes: 22460
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(T x, T y){
        cout << x << "," << y << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;


int N, K;
string S;

ll solve() {
    int cnt = 0;
    for (int i = 1; i < N; i++) {
        if (S[i - 1] == S[i]) {
            cnt++;
        }
    }
    int ans = min(N - 1, cnt + 2 * K);
 
    return ans;
}
 
int main() {
    cin >> N >> K;
    cin >> S;
 
    cout << solve() << endl;
 
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
    int x[11];
    int r,d;
    scanf("%d %d %d",&r,&d,&x[0]);
    for(int i=1;i<11;i++){
        x[i] = r * x[i-1] - d;
        printf("%d\n",x[i]);
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <unordered_map>

int f(int n, int i) {
  if (i == 1)
    return n;
  if (n % 2 == 0)
    return n / 2;
  return 3 * n + 1;
}

int main(int argc, char *argv[]) {
  int s;
  std::cin >> s;
  std::unordered_map<int, int> m;
  int i = 1, prev = s;
  while (true) {
    int res = f(prev, i);
    if (m.find(res) != m.end()) {
      std::cout << i << std::endl;
      return 0;
    }
    m[res] = i;
    ++i;
    prev = res;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <iomanip>
#include <queue>
#include <map>
#include <unordered_map>
typedef long long ll;
using namespace std;


int main()
{
	int N;
	std::cin >> N;

	std::vector<int> A(N+1);
	std::vector<int> B(N);

	ll ans = 0;


	for(int i=0; i<N+1; i++){
		std::cin >> A[i];
//	A[i] = 1e9;
	}

	for(int i=0; i<N; i++){
		std::cin >> B[i];
//	B[i] = 1e9;
	}

	//0番目の街
/*	int left = std::min(A[0],B[0]);
	ans += left;
	A[0] -= left;
	B[0] -= left;
*/

	for(int i=0;i<N+1;i++){
		int left = std::min(A[i],B[i]);
		ans += left;
		A[i] -= left;
		B[i] -= left;

		int right = std::min(A[i+1],B[i]);
		ans += right;
		A[i+1] -= right;
		B[i] -= right;
	}


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


}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
typedef vector<ll> vl;
#define PB push_back
#define ios() ios::sync_with_stdio(false); cin.tie(0);
#define scan(a,n) for(ll i=0;i<n;i++)	cin>>a[i];
#define print(a,n) for(ll i=0;i<n;i++)	cout<<a[i]<<"\n";
#define test() ll t; cin>>t; while(t--) 
#define endl "\n"


int main()
{
	ios()
	ll a;
	string s;
	cin>>a>>s;
	if(a<3200)
		cout<<"red\n";
	else
		cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
char del=' ';

int main() {
    // メインプログラムここから
    ll a,b,c;
    string ans;
    cin >>a>>b>>c;
    if(a+b==c || b+c==a || a+c==b){
        ans="Yes";
    }else{
        ans = "No";
    }
    cout <<ans<<endl;
    // ここま
}


Measured memory_bytes: 256
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$a=getq(1);
if($a[0]+$a[1]>=$a[2]){
	echo "Yes\n";
}else{
	echo "No\n";
}
?>

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <cmath>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

using namespace std;
typedef long long ll;

const ll MOD = pow(10,9)+7;

vector<ll> fac(1000001); //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)


ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCb(mod M)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

ll perm(ll a, ll b){
    if(a < b) return 0;
    ll tmp = ifac[a-b] % MOD;
    return tmp * fac[a] % MOD;
}



int main() {
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<1000000; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M)
    }
    
    long long N,M;
    cin>>N>>M;
    
    long long ans=0;
    
    long long tmp1=0;
    int tmp2=-1;
    
    for(long long k=0;k<=N;++k){
        tmp2*=-1;
        
        //cout<<"tmp2:"<<tmp2<<" COM("<<N<<","<<k<<")"<<comb(N,k)<<" perm;"<<perm(M-k,N-k)<<endl;
        
        tmp1=(tmp1+(tmp2*comb(N,k)*perm(M-k,N-k)+MOD))%MOD;
        //cout<<"tmp1:"<<tmp1<<endl;
        
        
    }
    ans=(perm(M,N)*tmp1+MOD)%MOD;
    cout<<ans<<endl;
    
}


Measured memory_bytes: 18688
import itertools

N=int(input())
XY=[list(map(int, input().split())) for _ in range(N)]
ans=0
NP=list(itertools.permutations([i for i in range(N)],N))

temp=0

for np in NP:
	for i in range(0,len(np)-1):
		temp+=((XY[np[i]][0]-XY[np[i+1]][0])**2+(XY[np[i]][1]-XY[np[i+1]][1])**2)**.5
	ans+=temp
	temp=0

print(ans/len(NP))

Measured memory_bytes: 80760
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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 <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#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};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, M; cin >> N >> M;

    // value, type, remain
    set< tuple<int, int, int> > S;
    for(int i=0; i<N; i++) {
        int a; cin >> a;
        S.insert(make_tuple(a, i, 1));
    }
    for(int i=0; i<M; i++) {
        int b, c; cin >> b >> c;
        S.insert(make_tuple(c, -i-1, b));
    }

    int rem = N, ans = 0;
    while(rem--) {
        auto tup = *S.rbegin();
        S.erase(tup);

        int val, type, num; tie(val, type, num) = tup;
        ans += val;
        // fprintf(stderr, "val = %lld\n", val);
        if(num > 1) {
            S.insert(make_tuple(val, type, num - 1));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define ps(x,y)  fixed<<setprecision(y)<<x
using namespace std;
#define PI 3.14159265358979323846264338327950L
int main()
{
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	long double rad=PI*2*((long double)h/12.0 +((long double)m/60.0)/12.0 -(long double)m/60.0);
	long double rsq= (long double)(a*a+b*b) - (long double)(2 *a*b) *cosl(rad);
	cout<<ps(sqrtl(rsq),20)<<endl;
}


Measured memory_bytes: 4088
#include <stdio.h>
#include <vector>
#include <queue>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <string.h>
#include <time.h>
#include <algorithm>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
	int n;
	scanf("%d", &n);

	vector<vector<int>> arr(3, vector<int>(n));

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

		sort(arr[i].begin(), arr[i].end());
	}

	int cidx = 0;

	vector<i64> bs(n + 1);

	for (int bidx = 0; bidx < n; bidx++)
	{
		while (cidx < n && arr[2][cidx] <= arr[1][bidx])
			cidx++;

		bs[bidx] = n - cidx;
	}

	for (int i = n - 2; i >= 0; i--)
	{
		bs[i] += bs[i + 1];
	}

	i64 res = 0;

	int bidx = 0;

	for (int aidx = 0; aidx < n; aidx++)
	{
		while (bidx < n && arr[1][bidx] <= arr[0][aidx])
			bidx++;

		res += bs[bidx];
	}

	printf("%lld", res);

	return 0;
}

Measured memory_bytes: 2296
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

t_ls=list(t)
ls=[]
for i,hand in enumerate(t_ls):
    try:
        if hand == "r":
            t_ls[i] = "p"
        elif hand == "s":
            t_ls[i] = "r"
        elif hand == "p":
            t_ls[i] = "s"
        if t_ls[i+k] == hand:
            t_ls[i+k] = "*"
    except:
        pass

ans = 0
for i in t_ls:
    if i == "r":
        ans+=r
    elif i == "s":
        ans+=s
    elif i == "p":
        ans+=p
print(ans)

Measured memory_bytes: 49520