akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;



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

    map<string,int> z;

    int i;
    for(i=0; i<n; i++) {
        char str[11]={0};
        scanf("%s", str);
        sort(str+0, str+10);
        z[string(str)]++;
    }
    ll ans=0;
    auto it=z.begin();
    for(; it!=z.end(); ++it) {
        ans += (ll)(it->second)*(it->second-1)/2;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 11136
def inpl(): return list(map(int, input().split()))

H, W = inpl()
ans = 0

C = [input() for _ in range(H)]
for i in range(2):
    L = [0]*H
    R = [0]*H
    Lk = []
    Rk = []
    for h in range(H):
        L[h] = C[h].find("B")
        R[h] = C[h].rfind("B")
        if L[h] >= 0:
            Lk.append(h)
        if R[h] >= 0:
            Rk.append(h)
    
    for lh in Lk:
        for rh in Rk:
            ans = max(ans, abs(L[lh] - R[rh]) + abs(lh - rh))

    if i == 0:
        C = ["".join(c) for c in zip(*C)]
        H, W = W, H

print(ans)


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

class Cube{
    public:
        int f[6];
        Cube(){}
        
        void roll(int i, int j, int k, int l){
            int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
        }
        
        //void roll_z(){ roll(1, 2, 4, 3); }
        void roll_y(){ roll(0, 2, 5, 3); }
        void roll_x(){ roll(0, 1, 5, 4); }
        
        void move(char ch){
            if( ch == 'E') for (int i = 0; i < 3; i++) roll_y();
            if( ch == 'W') roll_y();
            if( ch == 'N') roll_x();
            if( ch == 'S') for (int i = 0; i < 3; i++) roll_x();
        }
};

int main(void){
    // Your code here!
    Cube c;
    string com;
    
    for( int i = 0; i < 6; i++) cin >> c.f[i];
    cin >> com;
    
    for( int i = 0; i < com.size(); i++) c.move(com[i]);
    
    cout << c.f[0] << endl;
    
}



Measured memory_bytes: 3156
package main
 
import (
	"fmt"
	"regexp"
)
 
func main() {
	var S string
	fmt.Scan(&S)
	r := regexp.MustCompile(`^(eraser|erase|dreamer|dream)+$`)
	if r.MatchString(S) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int main() {
	string a,b,c="";
	int x=0,y=0;
	cin>>a>>b;
	while(true){
		if(x<a.size()) c+=a[x++];
		if(y<b.size()) c+=b[y++];
		if(x==a.size() && y==b.size()) break;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#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;
typedef vector<int> v;
typedef vector<ll> vll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
const int mINF = -1001001001;
const int mod = 1000000007;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());


int main() {
  int n;
  cin >> n;
  vll a(n),b(n),c(n);
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> b[i];
  REP(i,n) cin >> c[i];
  ll cnt=0;
  sort(ALL(a));
  sort(ALL(c));
  REP(i,n) {
    auto itera = lower_bound(ALL(a),b[i]);
    auto iterc = upper_bound(ALL(c),b[i]);
    cnt+=(itera-a.begin())*(c.end()-iterc);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 2560
def main():
    a,b,n = map(int,(input().split()))
    if b > n:
        x = n
        print(int(a*x/b)-a*(int(x/b)))
    else:
        x = b - 1
        print(int(a*x/b)-a*(int(x/b)))
if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

const long long MOD = 1000000007;

void solve(long long N, long long K){
  vector<int> v(N+2);
  int sum = 0;
  for(int x = 2; x <= N + 1; ++x) {
    v.at(x) = sum + (x - 1);
    sum += x - 1;
  }

  int amount = 0;
  const int first = 0;
  const int last = N + 1;
  for(int x = K; x <= N + 1; ++x) {
    amount += (v.at(last) - v.at(last - x)) - (v.at(first + x) - v.at(first)) + 1;
    amount %= MOD;
  }

  cout << amount << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  solve(N, K);
}


Measured memory_bytes: 4852
#include<iostream>
using namespace std;
int main()
{
    int n,i=1;
    cin>>n;
    int rem,rem1;
    rem=n%10;
    n=n/10;
    while(n>0)
    {
        i++;
        rem1=n%10;
        n=n/10;
        if(rem==rem1){cout<<"Bad";return 0;}
        rem=rem1;
    }
    if(i<=2){cout<<"Bad";return 0;}
    cout<<"Good";
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(k+1)
dp[0]=1
mod=10**9+7
for i in range(n):
  for j in range(k,0,-1):
    if j>a[i]:dp[j]-=dp[j-a[i]-1]
  for j in range(k):dp[j+1]=(dp[j+1]+dp[j])%mod
print(dp[k])

Measured memory_bytes: 42092
#include <stdio.h>
int cnt=0;

int max2(int len, int *nums) {
    int i, _max = nums[0];
    for (i = 1; i < len; i++) {
        if (nums[i] > _max){
            _max = nums[i];
            cnt = i-1;
        }
    }
    return _max;
}

int main (){
	int N,L=0;
	int Pie[200]={};
	int Abs[200]={};
	int AplPie=0;
	int i=0;
	int flg[200]={};
	
	scanf("%d %d",&N,&L);

	for(i=0;i<N;i++){
		Pie[i]=L+i;
	}
	for(i=0;i<N;i++){
		if(Pie[i]==0){
		    break;
		}
		else if(Pie[i]>0){
			Abs[i] = 0-Pie[i];
			flg[i] = -1;
		}else{
			Abs[i] = Pie[i];
			flg[i] = 1;
		}
	}
	
	
	max2(N,Abs);
	
	if(flg[cnt]!=1){
	 Pie[cnt]=0;
	}else{
	 Pie[cnt+1]=0;
	}

	for(i=0;i<=N;i++){
		AplPie=AplPie+Pie[i];
	}

	printf("%d",AplPie);

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int a, b, c, d;
    int ans;
    cin >> a >> b >> c >> d;

    // for(int i=0;i<A;i++){
    //     double z;
    //     string p;
    //     cin >> z;
    //     cin >> p;
    //     if(p=="BTC") {
    //         b += z*380000;
    //     }else if(p=="JPY"){
    //         b += z;
    //     }
    // }
    ans =a*b-a*d-b*c+c*d;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
vector<int> divisor(int n)
{
	vector<int> ret;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n)	ret.push_back(n / i);
		}
	}
	return ret;
}
int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> vec;
	vec = divisor(m);
	sort(vec.begin(), vec.end());
	int s = vec.size();
	int ans = 1;
	rep(i, s) {
		if (ll(vec[i]) * ll(n) <= ll(m)) ans = vec[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define fl(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rfl(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        forloop(n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define section(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));

const long long INF64 = 1e18;




void solve()
 { 
   int n,W;
     cin>>n>>W;
     int v[n+1];int w[n+1];
     int mxv=0;
     fl(i,0,n-1)
       {
       	cin>>w[i];
   
       	cin>>v[i];
       	    	mxv+=v[i];
       }
   
 int dp[n+1][mxv+2];

dp[0][0]=0;
fl(i,0,n)
  fl(j,0,mxv)
     dp[i][j]=INF64;
     dp[0][0]=0;


 for(int i=0;i<n;i++)
 	  {
 	  	for(int j=0;j<=mxv;j++)
 	  		 {  if(v[i]<=j)
 	  		 	 dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
 	  		 	 else
 	  		 	 	dp[i+1][j]=min(dp[i][j],dp[i+1][j]);




 	  		 }
 	  }
 	//  cout<<mxv<<" ";
 	  int ans=0;
for(int i=0;i<=mxv;i++)
	  {  if(dp[n][i]<=W)
	  	     ans=max(ans,i);


	  	
	  }
cout<<ans;
      


 }



  








 



signed main()
{fast
	int t;
   //cin>>t;
	t=1;

	while(t--)
		 {
		 	solve();
		 }
}












Measured memory_bytes: 79232
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, Q) = read!(usize, usize);
    let T = read![usize, usize; N - 1];
    let U = read![usize, i64; Q];

    let mut G = vec![vec![]; N];
    for (u, v) in T {
        G[u - 1].push(v - 1);
        G[v - 1].push(u - 1);
    }

    let mut A = vec![0; N];
    let mut B = vec![0; N];
    for (p, x) in U {
        A[p - 1] += x;
    }

    let mut q = VecDeque::new();
    q.push_back((0, 0, 0));
    while let Some((u, parent, mut total)) = q.pop_front() {
        total += A[u];
        B[u] = total;

        for i in 0..G[u].len() {
            let v = G[u][i];
            if v == parent {
                continue;
            }

            q.push_back((v, u, total));
        }
    }

    println!(
        "{}",
        B.into_iter()
            .map(|b| b.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    )
}


Measured memory_bytes: 41108
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
using namespace std;
typedef long long ll;
int main() {
    int x;
    int i = 1;
    while (1) {
        cin >> x;
        if (!x) break;
        cout << "Case " << i << ": " << x << endl;
        ++ i;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(){
    int a,b,c,x;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    if(a>b){
        x=a;
        a=b;
        b=x;
    }
   if(b>c){
        x=b;
        b=c;
        c=x;
    }
   if(a>b){
        x=a;
        a=b;
        b=x;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
typedef long long ll;
using namespace std;
const int N = 1e5+5;
const int M = 24005;
int head[N*2],tot,in[N*2];
struct man
{
    int u,v;
}edg[N*2];
int n,v,m,k,s;
int main() {
    int x,y,z;
    int ans=0;
    scanf("%d%d",&k,&s);
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int ret=s-i-j;
            if(ret<=k&&ret>=0)ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/times.h>  // 構造体tmsを使うために必要.
#include <time.h>
#include <unistd.h>
// #include <iostream>
// #include <gmpxx.h>

// コンパイル時に
// -lgmpxx -lgmp

// printf("%d\n", x); => std::cout << x << "\n";
// scanf("%d", &x); => std::cin >> x;
// int => mpz_class

// using namespace std;で std:: を省略できる

int main(int argc, char **argv) {
    long long int a, b, c, d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    long long int max = a * c;
    if (max < a * d) {
        max = a * d;
    }
    if (max < b * c) {
        max = b * c;
    }
    if (max < b * d) {
        max = b * d;
    }

    printf("%lld\n", max);
    return 0;
}


Measured memory_bytes: 3252
from math import ceil
K = int(input())
A = list(map(int, input().split()))
A.reverse()
if A[0] != 2:
    print(-1)
    exit()
mi = 2
mx = 3
for a in A[1:]:
    if ceil(mi/a) > mx//a:
        print(-1)
        exit()
    mi = ceil(mi/a)*a
    mx = mx//a*a
    mx = mx + a - 1
print(mi, mx)

Measured memory_bytes: 85544
#include <cstddef>
#include <iostream>
#include <vector>

class DisjointSet {
 private:
  class Node {
    friend DisjointSet;

    std::size_t parent;
    std::size_t size;

    Node(const std::size_t parent, const std::size_t size) : parent(parent), size(size) {}
  };

  std::vector<Node> nodes;

 public:
  DisjointSet(const std::size_t n) : nodes(n, Node(n, 1)) {}

  std::size_t size() const { return nodes.size(); }

  std::size_t size(const std::size_t x) { return nodes[root(x)].size; }

  std::size_t root(const std::size_t x) {
    if (nodes[x].parent == size()) return x;
    return nodes[x].parent = root(nodes[x].parent);
  }

  bool is_same(const std::size_t x, const std::size_t y) { return root(x) == root(y); }

  bool unite(const std::size_t x, const std::size_t y) {
    std::size_t rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (nodes[rx].size < nodes[ry].size) std::swap(rx, ry);
    nodes[rx].size += nodes[ry].size;
    nodes[ry].parent = rx;
    return true;
  }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, M;
  std::cin >> N >> M;
  DisjointSet ds(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    std::cin >> a >> b;
    a--, b--;
    ds.unite(a, b);
  }
  std::size_t res = 0;
  for (int i = 0; i < N; i++) {
    res = std::max(res, ds.size(i));
  }
  std::cout << res << '\n';
  return 0;
}


Measured memory_bytes: 6336
#include <iostream>

using namespace std;

int main() {
    int n, d, i, k=0, v;
    cin>>n>>d;
    k=2*d+1;
    if(n%k==0){
        v=n/k;
    }
    else{
        v=n/k+1;
    }
    cout<<v;
}


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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    int H, A;
    cin >> H >> A;
    int count = 0;
    while (H > 0) {
        H -= A;
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

s = input()

if s == "SUN\n":
  print("7")
elif s == "MON\n":
  print("6")
elif s == "TUE\n":
  print("5")
elif s == "WED\n":
  print("4")
elif s == "THU\n":
  print("3")
elif s == "FRI\n":
  print("2")
elif s == "SAT\n":
  print("1")


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

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = Fp<MOD>;


int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}

//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap
auto pfactor(int n){
  map<int,int> res;
  int t=sqrt(n);
  for(int i=2;i<=t;i++){
    for(;n%i==0;n/=i)res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
vector<int>kai(0);
void kaizyou(vector<int>&kai){
    rep(i,kai.size()){
        kai[i+1]=kai[i]*(i+1)%MOD;
      }
  }
int comb(int a,int b){
  return (kai[a]*gyaku(kai[a-b]))%MOD*gyaku(kai[b])%MOD;
}
////////////////////////////////////////////////////////////////////////
signed main() {
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  int cnt=0;
  int ans=0;
  char c=s[0];
  rep(i,n-1){
    if(c!=s[i+1]&&s[i]!=s[i+1]){cnt++;}
    if(s[i]==s[i+1])ans++;
  }
  if(cnt<=k)cout<<n-1<<endl;
  else cout<<ans+k*2;
  }


Measured memory_bytes: 3800
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)      x.begin(), x.end()
#define SIZE(x)     static_cast<i64>(x.size())
#define rep(i,n)    for (i64 i = 0, i ## _limit = (n); i < i ## _limit; ++i)
#define reps(i,s,t) for (i64 i = (s), i ## _limit = (t); i <= i ## _limit; ++i)
#define repr(i,s,t) for (i64 i = (s), i ## _limit = (t); i >= i ## _limit; --i)

#ifdef DBG
#define trace(...) _trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

template<class T, class U>
ostream& operator<< (ostream &os, const pair<T, U> &p) {
    return os << p.first << ' ' << p.second;
}

template<class Itr>
ostream& printContainer(Itr begin, Itr end, const string &separator = " ", ostream &os = cout) {
    const auto rbegin = std::prev(end);
    for (; begin != rbegin; ++begin) os << *begin << separator;
    os << *rbegin;
    return os;
}

ostream& operator<< (ostream &os, ostream&) {
    return os;
}

template <class T>
void _trace(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ":" << setw(3) << x << '}' << endl;
}

template <class Head, class... Tail>
void _trace(const char *s, Head&& head, Tail&&... tail) {
    clog << '{';
    while(*s != ',') clog << *(s++);
    clog << ":" << setw(3) << head << "}, ";
    for (++s; !isgraph(*s); ++s);
    _trace(s, std::forward<Tail>(tail)...);
}
// }}} End Header

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int N, K;
    string s;

    cin >> N >> s >> K;
    --K;

    rep(i, N) {
        if (s[i] != s[K]) s[i] = '*';
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,a,b,t=0;
	scanf("%d",&n);
	for(int i=1; i<=n; i+=1) {
		cin>>a>>b;
		t+=b-a+1;
	}
	cout<<t<<"\n";
}//はりれるが

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
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; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int A,B;cin >> A >> B;
    int a = A+B; int b = A-B; int c = A*B;

    int ans = max(a,b); ans = max(ans,c);

    cout << ans << endl;
}


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

#define debug(x) {cerr << #x << " = " << x << '\n';}
#define PR(a, n) {cerr << #a << " = "; for (int _=1; _<=n; ++_) cerr << a[_] << ' '; cerr << '\n';}
#define PR0(a, n) {cerr << #a << " = "; for (int _=0; _<n; ++_) cerr << a[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"


const int MAXN = 100002;
const int MAXM = 200002;
const int INF = 1e9;


int n, m, res[MAXM], c[MAXN], f[MAXN];
pair<int, int> d[MAXN];
vector<pair<int, int> > g[MAXN];


void readInput() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> d[i].first;
        f[i] = d[i].first;
        d[i].second = i;
    }

    for (int i = 1; i <= m; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back({v, i});
        g[v].push_back({u, i});
    }
}


void dfs(int u) {
	for (auto e : g[u]) {
		int v = e.first;
		if (f[u] == f[v] && c[v] == -1) {
			c[v] = c[u] ^ 1;
			// if (v == 6468)
			// 	debug(c[u]);
			res[e.second] = f[u];
			dfs(v);
		}
	}
}


void solve() {
    for (int u = 1; u <= n; ++u) {
        int cnt = 0;
        for (auto e : g[u]) {
            int v = e.first;
            cnt += (f[v] > f[u]);
        }
        if (cnt == g[u].size()) {
            cout << -1;
            return;
        }
    }

    sort(d + 1, d + n + 1);
    for (int i = 1; i <= n; ++i)
        c[i] = -1;
    for (int i = 1; i <= m; ++i)
        res[i] = INF;

    for (int i = 1; i <= n;) {
		int j = i - 1;
		while (j + 1 <= n && d[j + 1].first == d[i].first) {
			++j;
			int u = d[j].second;
			for (auto e : g[u]) {
				int v = e.first;
				if (c[u] != -1)
					break;
				if (f[v] < f[u]) {
					c[u] = c[v] ^ 1;
					res[e.second] = f[u];
					break;
				}
			}
			if (c[u] != -1)
				dfs(u);
		}
		for (int t = i; t <= j; ++t) {
			int u = d[t].second;
			if (c[u] == -1) {
				c[u] = 0;
				dfs(u);
			}
		}
		i = j + 1;
    }

    for (int i = 1; i <= n; ++i) {
        cout << ((c[i] == 0) ? 'B' : 'W');
    }
    cout << '\n';
    for (int i = 1; i <= m; ++i) {
        cout << res[i] << '\n';
    }
}


int main() {
    #ifdef GLASSES_GIRL
        freopen(FILE_NAME".in", "r", stdin);
    #endif

    readInput();
    solve();
}



Measured memory_bytes: 13056
#include <bits/stdc++.h>
using namespace std;
#define LL long long
char s[15];
int index1[15];
LL A(int n)
{
    LL sum=0;
    index1[n-1]=1;//目的就是让其有结束的时候,不写这个,那么像000这个情况就会没考虑到
    /*for(int i=0; i<n; i++){
        printf("%d",pos[i]);
    }
    printf("\n");*/
    LL ss=0;
    for(int i=0; i<n; i++)
    {
        if(index1[i]==0)
            ss=ss*10+(s[i]-'0');
        else{
            sum=sum+(ss*10+(s[i]-'0'));
            ss=0;
        }
    }
    return sum;
}
int main()
{
    while(cin>>s)
    {
        int n=strlen(s);
        long long ans=0;
        int m=(1<<(n-1));
        //加号的位置排放就有m种情况;
        //如125,就有125,1+25,12+5,1+2+5,这4种情况,其实也是0到3的二进制表示(巧妙吧)
        //cout<<m<<endl;
        for(int i=0; i<m; i++)//0到m-1的二进制表示
        {
            memset(index1,0,sizeof(index1));
            int k=0;
            int temp=i;
            while(temp)//求i的二进制
            {
                index1[k++]=temp%2;
                temp=temp/2;
            }
            ans+=A(n);
        }
        printf("%lld\n",ans);
    }
    return 0;
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
string s;

bool read() {
    if (!(cin >> s))
        return false;

    return true;
}

void solve() {
    n = sz(s);
    vector<string> L = {"dream", "dreamer", "erase", "eraser"};

    while (n > 0) {
        bool ok = false;

        for (auto i : L)
            if (sz(s) >= sz(i) && s.substr(sz(s) - sz(i), sz(i)) == i) {
                ok = true;
                forn (j, sz(i)) s.pop_back();
                break;
            }

        if (!ok)
            break;
    }

    cout << vector<string>({"NO", "YES"})[s.empty()] << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define N 200010
typedef long long ll;
using namespace std;
ll a[N],s[N];
set<ll> P;
map<ll,int> h;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    P.insert(0);
    h[0] += 1;
    for(int i=1;i<=n;i++){
        s[i] = s[i-1]+a[i];
        P.insert(s[i]);
        h[s[i]] += 1;
    }
    ll ans = 0;
    for(auto it=P.begin();it!=P.end();it++){
        ll tmp = (ll)h[*it]*(h[*it]-1)/2;
        ans += tmp;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 25216
/*
NAME: jinxiaoguang
LANG: C++
TASK:
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
//#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int inff=0x80000000;
const int infz=0x7fffffff;
const int mod=1e9+7;

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",a-b>0?a-b:0);
}


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

#define ll long long
using namespace std;

int main()
{

    ll n,i,j,k;

     cin>>n;
     k=n;
     set<string>ss;
     while(k--)

    {

         string s;


            cin>>s;
            ss.insert(s);




        }


    cout<<ss.size()<<endl;
    return 0;
}



Measured memory_bytes: 19220
import Foundation
 
var N = Int(readLine()!)!
//String -> Intの型変換はnilが返る可能性があるので、ラップされたOptional<Int>型が返るので強制アンラップ
var A = Int(readLine()!)!

if (N % 500 > A){
    print("No")
}else{
    print("Yes")
}




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

using namespace std;

int main(void) {
  int N, tmp, digit, i, count;
  cin >> N;
  digit = 0;
  tmp = N;
  while(tmp != 0) {
    tmp /= 10;
    digit++;
  }
  // digitが奇数の場合，最上位桁を見ます
  // 偶数の場合はどうでもいいです
  if(digit%2 == 1) {
    count = N - pow(10, digit-1) + 1;
  }
  else {
    count = 0;
  }
  digit--;
  while(digit > 0) {
    if(digit%2 == 1) {
      count += pow(10, digit) - pow(10, digit-1);
    }
    digit--;
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int dp[1000005][2];
int a[1000005];
int dfs(int p,int f){
	if(!p)RE f;
	if(dp[p][f]!=-1)RE dp[p][f];
	int t=a[p];t+=f;
	if(!t){
		RE dp[p][f]=dfs(p-1,0);
	}else if(t==10){
		RE dp[p][f]=dfs(p-1,1);
	}else {
		RE dp[p][f]=min(dfs(p-1,0)+t,dfs(p-1,1)+10-t);
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	cin>>s;
	rep(i,0,s.size())a[i+1]=s[i]-'0';
	FILL(dp,-1);
	cout<<dfs(s.size(),0)<<'\n';
	RE 0;
}



Measured memory_bytes: 75548
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int n, l, ans = 2147483647, sum = 0;
    cin >> n >> l;
    for (int i = 1; i <= n; i++)
    {
        sum += l + i - 1;
        if (abs(ans) > abs(l + i - 1))
            ans = l + i - 1;
    }
    cout << sum - ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N; cin >> N;
	vector<int> S(N);
	rep(i, N) cin >> S[i];
	int Q; cin >> Q;
	vector<int> P(N);
	rep(j, N) cin >> P[j];

	sort(ALL(S));
	int cnt = 0;
	rep(j, Q){
		auto it = lower_bound(ALL(S), P[j]);
		if(it != S.end() && *it == P[j]){
			cnt++;
		}
	}

	cout<< cnt << endl;
}



Measured memory_bytes: 3584
N,K = map(int,input().split())
A = list(map(int,input().split()))
dp = [False for i in range(K+1)]
for i in range(1,K+1):
    for j in range(N):
        if i-A[j] >= 0:
            dp[i] |= not dp[i-A[j]]
if dp[-1]:
    print('First')
else:
    print('Second')

Measured memory_bytes: 45168
#include <iostream>
#include <utility>
#include <string>

using namespace std;

struct Card{char suit; int value;};

void bubbleSort(struct Card C[],int n){
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(C[j].value<C[j-1].value) swap(C[j],C[j-1]);
    }
  }
}

void selectionSort(struct Card C[],int n){
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(C[j].value<C[minj].value) minj=j;
    }
    swap(C[i],C[minj]);
  }
}

int main(){
  int n; cin >> n;
  struct Card C[n],D[n];
  for(int i=0;i<n;i++){
    string str;
    cin >> str;
    C[i].suit=str[0];
    D[i].suit=str[0];
    C[i].value=str[1]-'0';
    D[i].value=str[1]-'0';
  }
  bubbleSort(C,n);
  for(int i=0;i<n;i++){
    if(i==n-1) cout << C[i].suit << C[i].value << endl;
    else cout << C[i].suit << C[i].value << " ";
  }
  cout << "Stable" << endl;
  selectionSort(D,n);
  for(int i=0;i<n;i++){
    if(i==n-1) cout << D[i].suit << D[i].value << endl;
    else cout << D[i].suit << D[i].value << " ";
  }
  bool isStable=true;
  for(int i=0;i<n;i++){
    if(C[i].suit != D[i].suit){
      isStable=false;
      break;
    }
  }
  if(isStable) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
}

Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000 * 1000 * 1000 + 7;

ll dp[100000][2];

struct node { vector<int> edges; };

struct graph {
	vector<node> nodes; int n;
	graph(int _n) : n(_n) { nodes.resize(n); }

	void add_edge(int u, int v) {
		nodes[u].edges.emplace_back(v);
		nodes[v].edges.emplace_back(u);
	}
	
	ll indepSet(int cur, bool b, int p = -1) {
		if (dp[cur][b] != -1) { return dp[cur][b]; }
		ll res = 1; for (auto &e : nodes[cur].edges) if(e != p)
			res = (res * (indepSet(e, 0, cur) + (b ? 0 : indepSet(e, 1, cur)))) % mod;
		return dp[cur][b] = res;
	}
};

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

	int n; cin >> n; graph g(n);
	fill(dp[0], dp[0] + 200000, -1);
	for (int i = 1; i < n; i++) {
		int u, v; cin >> u >> v;
		u--; v--; g.add_edge(u, v);
	}
	cout << (g.indepSet(0, 0) + g.indepSet(0, 1)) % mod << '\n';
	cin.ignore(2); return 0;
}

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

using namespace std;

int main(){
    string a;
    cin >> a;
    int b = a.size();

    if(a[b-1] == 's'){
        a = a + "es";
    }else if(a[b-1] != 's'){
        a = a+"s";
    }

    cout << a << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;	}


//Variables Declaration
int N , W ;

vector<ll> w;
vector<ll> v ;


ll dp[(int)(1e3 * 100 ) + 10];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(dp, 0x3f, sizeof(dp));

	cin >> N >> W;
	w.resize(N);
	v.resize(N);

	for (int i = 0; i < N; ++i)
	{
		cin >> w[i] >> v[i] ;
	}

	dp[0]=0;
	for (int k = 0 ; k < N ; ++k ) {
		for (int x = 100000 ; x >= 0 ; x--) {
			if(dp[x]< W)
				dp[x+v[k]] = min(dp[x+v[k]] , dp[x]+w[k]); 
		}
	}

	for(int i = 100000 ; i >= 0  ; --i){
		if (dp[i]<= W){
			cout << i   << endl;
			return 0;
		}
	}	

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<17;
	ll dp[1<<18];
	segtree(){
		for(int i=0;i<N*2;i++){
			dp[i]=0;
		}
	}
	void update(int k,ll v){
		k+=N-1;
		dp[k]=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=max(dp[k*2+1],dp[k*2+2]);
		}
	}

	ll query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		ll vl=query(a,b,k*2+1,l,mid);
		ll vr=query(a,b,k*2+2,mid,r);
		return max(vl,vr);
	}
};

int n;
ll k;
ll a[100005],b[100005],c[100005];
bool ul[100005],ur[100005];
segtree seg,seg2;

bool C(){
	for(int i=0;i<n;i++){
		c[i]=(ll)k+2LL*n+i;
	}
	int l=n-1,r=n-1;
	priority_queue<P> que;
	for(int i=0;i<n;i++){
		seg.update(i,k+i);
		seg2.update(i,k+n+i);
	}
	for(int i=n-1;i>=0;i--){
		ll cap=c[i];
		ll v1=seg.query(0,n);
		ll v2=seg2.query(0,n);
		if(v1>(v2-n)){
			ll rest=cap-v1;
			ll v3=seg2.query(0,rest-n-k+1);
			if(v3==0)return false;
			a[i]=v1;
			b[i]=v3;
			seg.update(v1-k,0);
			seg2.update(v3-n-k,0);
		}else{
			ll rest=cap-v2;
			ll v3=seg.query(0,rest-k+1);
			if(v3==0)return false;
			a[i]=v3;
			b[i]=v2;
			seg.update(v3-k,0);
			seg2.update(v2-n-k,0);
		}
	}
	return true;
}

int main(void){
	scanf("%d%lld",&n,&k);
	if(C()){
		for(int i=0;i<n;i++){
			printf("%lld %lld %lld\n",a[i],b[i],c[i]);
		}
	}else{
		printf("-1\n");
		/*
		for(int i=0;i<n;i++){
			printf("%lld %lld %lld\n",a[i],b[i],c[i]);
		}
		*/
	}
	return 0;
}


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

using namespace std;

static const long MOD = 1000000007;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	vector<long> count(N+1);
	for (int i = 1; i <= N; i++) {
		int n = i;
		while (n > 1) {
			for (int j = 2; j <= N; j++) {
				if (n % j != 0) continue;
				n /= j;
				count[j]++;
				j--;
			}
		}
	}

	long ans = 1;
	for (int i = 1; i <= N; i++) {
		ans = (ans * (count[i] + 1)) % MOD;
	}

	cout << ans << endl;
	return 0;
}


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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int)1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << __LINE__ << " : [" << #x << "] = ["; __print(x)


int main()
{
    int n;
    scanf("%d", &n);
    i64 a[n+5];
    for(int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }
    i64 s = 0;
    for(int i = 0; i < n; i++) {
        if(i&1) s -= a[i];
        else s += a[i];
    }
    vector<i64> ans;
    ans.push_back(s);
    for(int i = 0; i < n - 1; i++) {
        ans.push_back(2*a[i] - ans.back());
    }
    for(i64 i : ans) printf("%lld ", i);
    puts("");
}


Measured memory_bytes: 5136
function main()
	H,W=map(x->parse(Int,x),split(readline()))
	S=readlines()
	D=ones(Int,H,W)*1145141919
	D[1,1]=1
	P=[1=>1]
	while !isempty(P)
		(x,y)=shift!(P)
		for (tx,ty)=zip([x,x+1,x,x-1],[y-1,y,y+1,y])
			if 1<=tx<=H&&1<=ty<=W&&S[tx][ty]!='#'&&D[tx,ty]>D[x,y]+1
				D[tx,ty]=D[x,y]+1
				push!(P,tx=>ty)
			end
		end
	end
	c=0
	for i=1:H
		c+=count(t->t=='#',S[i])
	end
	println(max(-1,H*W-c-D[H,W]))
end
main()


Measured memory_bytes: 117768
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  vector<i64> d(n - 1);
  for (i64 i = 0; i < n - 1; ++i)
    d[i] = a[i + 1] - a[i];
  if (n % 2 == 0)
  {
    i64 ans = 0;
    for (i64 i = 0; i < n - 1; i++)
      ans += d[i] * 2 * min(i + 1, n - i - 1);
    cout << ans - d[n / 2 - 1];
  }
  else
  {
    i64 ans = 0;
    for (i64 i = 0; i < n - 1; ++i)
      ans += d[i] * 2 * min(i + 1, n - i - 1);
    cout << ans - min(d[n / 2 - 1], d[n / 2]) << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>

using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if (a + b == 15){
		puts("+");
		return 0;
	}
	if (a*b == 15){
		puts("*");
		return 0;
	}
	puts("x");
	return 0;
}

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

struct Item{
  long long weight,value;
};

void knapsack(long long N, long long W){
  std::vector<Item>item(N);
  long long dp[N+5][W+5]={};

  for(auto &i:item){
    std::cin>>i.weight>>i.value;
  }

  for(long long i=0;i<N;i++){
    for(long long j=0;j<=W;j++){
      if(j + item[i].weight <= W){
	dp[i+1][j+item[i].weight] = std::max(dp[i+1][j+item[i].weight],
					     dp[i][j]+item[i].value);
      }
      dp[i+1][j] = std::max(dp[i+1][j],dp[i][j]);
      dp[i+1][j+1] = std::max(dp[i+1][j+1],dp[i][j]);
    }
  }
  std::cout<<dp[N][W]<<std::endl;
}
int main(){
  long long n,w;std::cin>>n>>w;
  knapsack(n,w);
  return 0;
}

Measured memory_bytes: 82304
import sys

def comb(n, r, revfact, mod):
    ans = 1
    for i in range(r):
        ans *= (n - i)
        ans %= mod
        ans *= revfact[i + 1]
        ans %= mod
    return ans

def solve():
    input = sys.stdin.readline
    n, a, b = map(int, input().split())
    mod = 7 + 10 ** 9
    total = (pow(2, n, mod) - 1) % mod
    rev = [1] * (b + 2)
    for i in range(1, b + 2):
        rev[i] = pow(i, mod - 2, mod)

    print((total - comb(n, a, rev, mod) - comb(n, b, rev, mod)) % mod)


    return 0

if __name__ == "__main__":
    solve()

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

int main() {
  int N;
  cin >> N;
  
  int x;
  
  for (int i = 0; i < N; i = i + 1) {
    int a, b;
    cin >> a >> b;
    x = x + b - a + 1;
  }
  
  cout << x << endl;
}

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

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  long long n, m, ans;
  cin >> n >> m;
  ans = min(n, m / 2) + (m - 2 * min(n, m / 2)) / 4;
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <ctime>
#include <cmath>
using namespace std;

int task(int N, int K, vector<int> &h) {
	vector<unsigned> res(N, 0);
	int i, min_cost, current_cost;
	for (int k = 1; k < N; k++) {
		i = k - 1;
		min_cost = res[i] + abs(h[k] - h[i]);
		current_cost = min_cost;
		while ((i > 0) && (i > k - K)) {
			i--;
			current_cost = res[i] + abs(h[k] - h[i]);
			if (min_cost > current_cost) {
				min_cost = current_cost;
			}
		}
		res[k] = min_cost;
	}

	return res[N - 1];
}

void read_input(int &N, int &K, vector<int> &h) {
	unsigned buffer;
	string seq;
	// read N, K
	getline(cin, seq);
	istringstream iss(seq);
	iss >> N;
	iss >> K;
	iss.clear();
	// read h
	getline(cin, seq);
	iss.str(seq);
	while (iss >> buffer) {
		h.push_back(buffer);
	}
}

int main() {
	int N, K;
	vector<int> h;
	read_input(N, K, h);
	//unsigned init_time = clock();
	cout << task(N, K, h) << endl;
	//unsigned end_time = clock();
	//cout << double(end_time - init_time) / CLOCKS_PER_SEC << " seconds" << endl;
	return 0;
}

Measured memory_bytes: 2308
#include <bits/stdc++.h>
using namespace std;
int dp[105][105];
char c[105][105];

int main(){
    int h,w;
    cin >> h >> w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> c[i][j];
        }
    }
    if(c[0][0]=='#')dp[0][0]=1;
    for(int i=0;i<h;i++){
        if(i>0){
            if(c[i-1][0]=='.' && c[i][0]=='#')dp[i][0]=dp[i-1][0]+1;
            else dp[i][0]=dp[i-1][0];
        }
        for(int j=0;j<w-1;j++){
            if(i==0){
                if(c[i][j]=='.' && c[i][j+1]=='#')dp[i][j+1]=dp[i][j]+1;
                else dp[i][j+1]=dp[i][j];
            }
            else{
                if(c[i][j+1]=='.')dp[i][j+1]=min(dp[i][j],dp[i-1][j+1]);
                else dp[i][j+1]=min(dp[i][j]+(c[i][j]=='.'),dp[i-1][j+1]+(c[i-1][j+1]=='.'));
            }
        }
    }
    cout << dp[h-1][w-1] << endl;    
}

Measured memory_bytes: 256
N, Q = list(map(int, input().split()))
S = input()
lr = [list(map(int, input().split())) for i in range(Q)]
# print(N, Q, S, lr)

number_of_AC_list = [0] * len(S)
total = 0
for i in range(1, len(S)):
    two_characters = S[i - 1] + S[i]
    if two_characters == 'AC':
        total += 1

    number_of_AC_list[i] = total
# print(number_of_AC_list)

for lri in lr:
    l_as_index = lri[0] - 1
    r_as_index = lri[1] - 1
    # print(lri, number_of_AC_list[l_as_index], number_of_AC_list[r_as_index])
    answer = number_of_AC_list[r_as_index] - number_of_AC_list[l_as_index]
    print(answer)


Measured memory_bytes: 30676