akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
 
using namespace std;
 
typedef struct Point {
    double x;
    double y;
} POINT;
 
double area(Point l, Point m, Point n);
 
int main() {
    Point a, b, c, p;
    while (cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> p.x >> p.y) {
        double diff = area(a, b, c) - (area(a, b, p) + area(b, c, p) + area(c, a, p));
        if (fabs(diff) < 0.001) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        } 
    }
}
 
double area(Point l, Point m, Point n) {
    return fabs( (m.x - l.x) * (n.y - l.y)
            - (m.y - l.y) * (n.x - l.x)) * 0.5;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define fi(i,a,b) for(int i=a; i<=b; i-=-1)
#define fid(i,a,b) for(int i=a; i>=b; i--)
#define ll long long
#define F first
#define S second
#define VanLoi "grid"
#define maxn 1005
#define pii pair<int, int>
#define MOD 1000000007
#define B 107
#define gb(i,j) ((i >> j) & 1)
#define pb push_back
#define reset(x) memset(x, 0, sizeof(x))
#define Block 400
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

int n, m, a[maxn][maxn], l[maxn][maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen(VanLoi".inp","r",stdin);
    freopen(VanLoi".out","w",stdout);
    #endif // ONLINE_JUDGE
    cin >> n >> m;
    fi(i, 1, n) {
        string s;
        cin >> s;
        fi(j, 1, m) if (s[j - 1] == '.') a[i][j] = 0; else a[i][j] = 1;
    }
    l[1][1] = 1;
    fi(i, 1, n)
        fi(j, 1, m) if ((i != 1 || j != 1) && a[i][j] == 0) l[i][j] = (l[i][j] + l[i][j - 1] + l[i - 1][j]) % MOD;
    /*fi(i, 1, n) {
        fi(j, 1, m) cout << l[i][j] << " ";
        cout << '\n';
    }*/
    cout << l[n][m];
}


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

typedef long long ll;

struct node{
    ll Num, Size;
}shu[500005];

ll n,k;
ll Pos;

bool cmp(const node &a,const node &b){
    return a.Num < b.Num;
}

int main(){
    scanf("%lld%lld", &n, &k);
    for(int i = 1; i <= n; i++) scanf("%lld%lld",&shu[i].Num, & shu[i].Size);
    sort(shu + 1, shu + 1 + n, cmp);
    for(int i = 1; i <= n; i++){
        Pos += shu[i].Size;
        if(Pos >= k){
            printf("%lld", shu[i].Num);
            break;
        }
    }
    return 0;
}




Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

const int maxn = 105;
long long dp[100005];
int w[maxn];
long long v[maxn];

int main(int argc, char const *argv[])
{
//	freopen("in.txt", "r", stdin);
	int n, W;
	scanf("%d %d", &n, &W);
	for(int i=1; i<=n; i++){
		scanf("%d %lld", &w[i], &v[i]);
	}
	for(int i=1; i<=n; i++){
		for(int j=W-w[i]; j >= 0; j--){
			dp[j+w[i]] = max(dp[j+w[i]], dp[j] + v[i]);
		}
	}
	long long ans = 0;
	for(int i=1; i<=W; i++){
		ans = max(ans, dp[i]);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1024
import sys
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

K=int(input())
S=ns()

if(len(S)<=K):
    print(S)
else:
    print(S[0:K]+'...')



Measured memory_bytes: 9212
#include <stdio.h>

int main(void)
{
    int a, b;
    int sum = 0;
    int puragu = 1;

    scanf("%d %d", &a, &b);

    int a1 = a-1;

    while(1){
        if(puragu >= b){
            printf("%d\n", sum);
            break;
        }
        puragu += a1;
        ++sum;
        if(puragu >= b){
            printf("%d\n", sum);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> v(h);
  for (int i = 0; i < h; ++i) {
    cin >> v[i];
  }

  ll res = 0;
  for (int i = 0; i < (1 << h); ++i) {
    for (int j = 0; j < (1 << w); ++j) {

      ll count = 0;
      for (int k = 0; k < h; ++k) {
        for (int l= 0; l < w; ++l) {
          if(!(i & (1 << k))) continue;
          if(!(j & (1 << l))) continue;
          if(v[k][l] == '#') count++;
        }
      }

      if(count == k) res++;
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int x; cin >> x;
    if(x < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize,
        s: proconio::marker::Chars,
    }
    let (num_r, num_g, num_b) = {
        let (mut r, mut g, mut b) = (0, 0, 0);
        for c in s.iter() {
            match c {
                'R' => r += 1,
                'G' => g += 1,
                'B' => b += 1,
                _ => unreachable!(),
            }
        }
        (r, g, b)
    };
    let (remain_r, remain_g, remain_b) = {
        let (mut r, mut g, mut b) = (vec![], vec![], vec![]);
        let (mut num_r, mut num_g, mut num_b) = (num_r, num_g, num_b);
        for c in s.iter() {
            r.push(num_r);
            g.push(num_g);
            b.push(num_b);
            match c {
                'R' => {
                    num_r -= 1;
                }
                'G' => {
                    num_g -= 1;
                }
                'B' => {
                    num_b -= 1;
                }
                _ => unreachable!(),
            }
        }
        (r, g, b)
    };
    let mut sum = 0i64;
    for i in 0..n - 2 {
        for j in i + 1..n - 1 {
            if s[i] == s[j] {
                continue;
            }
            let diff_ji = j - i;
            let same_distance_k = j + diff_ji;
            let color_k = if s[i] != 'R' && s[j] != 'R' {
                'R'
            } else if s[i] != 'G' && s[j] != 'G' {
                'G'
            } else {
                'B'
            };
            let mut remain = match color_k {
                'R' => remain_r[j + 1],
                'G' => remain_g[j + 1],
                'B' => remain_b[j + 1],
                _ => unreachable!(),
            };
            if n <= same_distance_k {
                // can not take same distance
            } else if s[same_distance_k] == color_k {
                remain -= 1;
            }
            sum += remain;
        }
    }
    println!("{}", sum);
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;


char type[2] = {'A', 'B'};

vector<ll> smemo(1500, 0);
vector<ll> tmemo(1500, 0);

string s, t;

ll countS(ll begin, ll end){
    ll res = 0;
    ll idx = begin;
    while(idx % 300 != 0 && idx < end){
        res += (s[idx] == type[0])? 1:2;
        idx++;
    }
    while(idx+300 < end && idx < end){
        res += smemo[idx/300];
        idx += 300;
    }
    while(idx < end){
        res += (s[idx] == type[0])? 1:2;
        idx++;
    }
    return res;
}

ll countT(ll begin, ll end){
    ll res = 0;
    ll idx = begin;
    while(idx % 300 != 0 && idx < end){
        res += (t[idx] == type[0])? 1:2;
        idx++;
    }
    while(idx+300 < end && idx < end){
        res += tmemo[idx/300];
        idx += 300;
    }
    while(idx < end && idx < end){
        res += (t[idx] == type[0])? 1:2;
        idx++;
    }
    return res;
}

int main(){
    cin >> s;
    cin >> t;
    int q;
    cin >> q;
    vector<int> a(q);
    vector<int> b(q);
    vector<int> c(q);
    vector<int> d(q);
    rep(i, q)   cin >> a[i] >> b[i] >> c[i] >> d[i];

    ll slen = s.size();
    rep(i, slen){
        smemo[i/300] += (s[i] == type[0])? 1:2;
    }
    ll tlen = t.size();
    rep(i, tlen){
        tmemo[i/300] += (t[i] == type[0])? 1:2;
    }

    rep(i, q){
        //  A => BB
        //  B => AA
        //  BB => A
        //  AA => B

        ll scnt = countS(a[i]-1, b[i]) % 3;
        ll tcnt = countT(c[i]-1, d[i]) % 3;
        bool eq = scnt == tcnt;
        if(eq)  cout << "YES" << endl;
        else    cout << "NO" << endl;

    }



    return 0;
}


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

int main(){
  int n, k;
  string s;
  cin >> n >> s >> k;

  char t = s[k - 1];
  for (int i = 0; i < n; i ++) {
    if (s[i] == t) continue;
    s[i] = '*';
  }

  cout << s << endl;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
MAX = 60

n = int(input())
a = list(map(int, input().split()))

cnt = [0 for i in range(MAX)]
for i in range(n):
    bit = bin(a[i])[2:].zfill(MAX)
    for j in range(MAX):
        cnt[j] += int(bit[j])

ans = 0
for i in range(MAX):
    ans += cnt[MAX - i - 1] * (n - cnt[MAX - i - 1]) * 2 ** i
    ans %= MOD
print(ans)


Measured memory_bytes: 117900
/**
 * @brief 素集合森構造体
 * @note  関連URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A
 * @date  2016/04/16
 */



//****************************************
// 必要なヘッダファイルのインクルード
//****************************************

#include <iostream>
#include <vector>
#include <cstdint>



//****************************************
// 構造体の定義
//****************************************

/**< @brief 素集合森 */
struct disjoint_set {
    using index_t = std::int32_t;
    using rank_t  = std::int32_t;
    
    std::vector<index_t> p;
    std::vector<rank_t> rank;

    explicit disjoint_set(std::size_t size) : p(size, -1), rank(size, -1) {}
    
    /**
     * @brief xを唯一の要素(従って、代表元)としてもつ新しい集合を生成する.
     * @note  集合は互いに素であるから、xがすでに別の集合に出現していることはない. 
     *
     * @param int x 節点x
     */
    void make_set(index_t x) {
        p[x]    = x;
        rank[x] = 0;
    }

    /**
     * @brief     xを含む動的集合Sxとyを含む動的集合Syを合併(統合)し、
     *            これらの和集合である新しい集合を生成する.
     * @attention SxとSyはこの操作を実行する前は互いに素であると仮定する.
     *
     * @param int x   動的集合Sxの元x
     * @param int y   動的集合Syの元y
     */
    void merge(index_t x, index_t y) {
        link(find_set(x), find_set(y));
    }


    /**
     * @brief 手続きmergeの補助関数
     *
     * @param int x 動的集合Sxの代表元x(Sxの根)
     * @param int y 動的集合Syの代表元y(Syの根)
     */
    void link(index_t x, index_t y) {
        // xのランク > yのランクかどうか判定
        if (rank[x] > rank[y]) {  // x.rank > y.rankならば、
            p[y] = x;             // yの親はxを指す
        }
        else {                    // x.rank <= y.rankならば、 
            p[x] = y;             // xの親はyを指す
            
            if (rank[x] == rank[y]) {   // x.rank == y.rankならば、
                rank[y] = rank[y] + 1;  // y.rankをひとつ増やす
            }
        }
    }

    /**
     * @brief  xを含む(唯一の)集合の代表元へのポインタを返す.
     *         手続きfindsetは2パス法に基づく.再帰が進行するのに従って、
     *         find経路を根に向かって上向きに走査して根を発見し、つぎに、
     *         再帰が巻き戻されるにつれて、辿ってきたfind経路を下る2度目の走査を行って、
     *         find経路上の各節点のポインタを直接根を指すように更新する.
     *
     * @param  int x   集合Sxの元x
     * @return int y   集合Sxの代表元(根)
     */
    index_t find_set(index_t x) {
        // find経路を根に向かって上向きに走査
        if (x != p[x]) {
            p[x] = find_set(p[x]);  // 再帰を進行させる
        }
        return p[x];  // 再帰が底をついてから、根を返す
    }
};



//****************************************
// 関数の定義
//****************************************

int main()
{
    using namespace std;
    
    int a, b, q, n, t;

    cin >> n >> q;

    disjoint_set ds(n);
    for (int i = 0; i < n; i++) { ds.make_set(i); }

    for (int i = 0; i < q; i++) {
        cin >> t >> a >> b;

        if (t == 0) { ds.merge(a, b); }
        else if (t == 1) {
            if (ds.find_set(a) == ds.find_set(b)) cout << 1 << endl;
            else                                  cout << 0 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,a[N],pre[N],suf[N],fac[N],inv[N],ifac[N];
int calc(int dis) {
    return 1ll*fac[n]*inv[dis+1]%mod;
}
int main() {
    n=gi();
    for(int i=1;i<=n;i++) a[i]=gi(),pre[i]=add(pre[i-1],a[i]);
    for(int i=n;i;i--) suf[i]=add(suf[i+1],a[i]);
    fac[0]=1;for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
    inv[1]=1;for(int i=2;i<=n;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    ifac[0]=1;for(int i=1;i<=n;i++) ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
    int ans=0;
    for(int dis=0;dis<n;dis++) {
        inc(ans,1ll*calc(dis)*pre[n-dis]%mod);
        if(dis) inc(ans,1ll*calc(dis)*suf[dis+1]%mod);
    }
    //for(int i=1;i<=n;i++)
    //for(int j=1;j<=n;j++) inc(ans,1ll*calc(abs(i-j))*a[j]%mod);
    printf("%d\n",ans);
    return 0;
}


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

int main(){
  int n,k,d;
  cin >> n >> k;
  int tmp = 0;
  map<int,int> un;
  for(int i=0; i<k; i++){
    cin >> d; 
    un[d] = 1;
  }
  bool flag;
  for(int i=n; i<=100000; i++){
    flag = false;
    if(n<=i){
      string s = to_string(i);
      for(int j=0; j<s.size(); j++){
        if(un.count((int)(s.at(j)-48))==1){flag = true;}
      }
      if(flag){continue;}
      else{cout << i << endl;return 0;}
    }
  }
}

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

int main() {
	int color[110];
	for (int i = 0; i < 100; i++) {
		color[i] = 0;
	}
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 3;
	color[a - 1]++;
	color[b - 1]++;
	color[c - 1]++;
	for (int i = 0; i < 100; i++) {
		if (color[i] == 2) {
			ans--;
		}
		else if (color[i] == 3) {
			ans-=2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;

typedef map<string,int> msi; 
typedef map<int,int> mii;

typedef stack<int> si;
typedef stack<string> ss;
typedef stack<bool> sb;

typedef queue<int> qi;
typedef queue<string> qs;
typedef queue<bool> qb;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;

void f3(){

}


void f2(){

}

void f1(){

}
 

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

	long long int p = n;
	if(n % 2 == 0){
		p /= 2;
		p *= (n-1);
	}else{
		p *= (n-1)/2;
	}
	printf("%lld\n", p);

	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

void swap(int *, int *);

void swap(int *x, int *y) {
    int tmp;
    tmp = *y;
    *y = *x;
    *x = tmp;
}

int main() {
        int x, y;

        while (1) {
                scanf("%d %d", &x, &y);
                if (x == 0 && y == 0) break;
                if (y < x) swap(&x, &y);
                printf("%d %d\n", x, y);
        }
}


Measured memory_bytes: 2020
d = int(input())
c = [[] for _ in range(26)]
s = []
C = list(map(int, input().split()))
for i in range(26):
    c[i].append(C[i])
    c[i].append(i+1)
for i in range(d):
    s.append(list(map(int, input().split())))

c.sort(reverse=True)
t = 0
while t < 365:
    for i in range(26):
        if t < 365:
            t += 1
            print(c[i][1])
        else:
            break;

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n;
  cin >> n;
  string s;
  while (n) {
    n--;
    s += (n % 26) + 'a';
    n /= 26;
  }
  reverse(all(s));
  cout << s << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    int a,b;
    cin >> a >> b;
    if(a>b)cout << a+a-1 << endl;
    else if(a<b)cout << b+b-1 << endl; 
    else cout << a+b << endl;
    return 0;
}

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

int main() {
  long long n, x, m;
  cin >> n >> x >> m;
  vector<int> app(m, -1);
  vector<long long> loop;
  long long now = x;
  for (long long i = 0; 0 > app[now]; i++, now = now * now % m) {
    app[now] = i;
    loop.emplace_back(now);
  }
  if (app[now] > n) {
    cout << accumulate(begin(loop), begin(loop) + n, 0ll) << endl;
  } else {
    auto ans = accumulate(begin(loop), begin(loop) + app[now], 0ll);
    n -= app[now];
    int len = size(loop) - app[now];
    ans += accumulate(begin(loop) + app[now], end(loop), 0ll) * (n / len);
    ans += accumulate(begin(loop) + app[now], begin(loop) + app[now] + n % len,
                      0ll);
    cout << ans << endl;
  }
}


Measured memory_bytes: 4260
#include <stdio.h>
int main(){
  int i,j,k,l,n;
  int count;
  while(scanf("%d",&n)!=EOF){
    count=0;
    for(i=0;i<10;i++){
      for(j=0;j<10;j++){
	for(k=0;k<10;k++){
	  for(l=0;l<10;l++){
	    if(i+j+k+l==n)count++;
	  }
	}
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 596
// DP

#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;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
const int mod = 1e9 + 7;
int main(void){
  int S;
  cin >> S;

  // 最後の項は3の場合、4の場合。...Nの場合がある
  // 漸化式を考える
  // A[N] = A[N - 3] + A[N - 4] + ... + A[0]
  // A[0] = 1, A[1] = 0, A[2] = 0, ...
  vector <ll> dp(S+1, 0);
  dp[0] = 1;

  ll ans = 0;
  // S[i]を求める
  for (int i = 3; i <= S; i++){
    for (int j = i - 3; j >= 0; j--){
      dp[i] += dp[j];
      dp[i] %= mod;
    }
  }
  cout << dp[S] << endl;
  return 0;
}


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

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;

int main(void){
    int N, K, co=0, tailco=0;
    bool isL = true;
    string S;
    cin >>N>>K;
    cin >> S;
    int len = S.length();
    rep(i, len){
        if(S[i]=='L'){
            if(i == 0){
                tailco++;
            } else if(isL == false){
                isL = true;
                co++;
            }
        }
        else{
            if(i == len-1){
                tailco++;
            } else if(isL == true){
                isL = false;
            }
        }
    }
    int hap = len-co*2-tailco;
    //cout << hap << endl;
    if(co>K){
        hap+=2*K;
    } else{
        hap+=2*(co-1);
        K-=co;
        if(tailco == 0) hap++;
        else if(tailco == 1) hap+=2;
        else{
            if(K==0) hap+=2;
            else hap+=3;
        }
    }
    cout << hap << endl;
    return 0;
}


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

// 各位の数字を足す関数
int findSumOfDigits(int n){
  int sum=0;
  while(n>0){
    sum = sum + n%10;
    n=n/10;
  }
  return sum;
}

int main() {
  int N;
  cin>>N;
  
  int wa=findSumOfDigits(N);
  if(N%wa==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define double long double
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define fo(i, n) for(int i = 0; i < n; i ++)
#define foe(i, n) for(int i = 0; i <= n; i ++)
#define fo1(i, n) for(int i = 1; i < n; i ++)
#define fo1e(i, n) for(int i = 1; i <= n; i ++)
using namespace std;


int32_t main(){
  fastio
  int n;
  cin >> n;
  vector<int> ar(n);
  fo(i, n)
    cin >> ar[i];
  int ans = 0, c = 0;
  fo1(i, n){
    if(ar[i] <= ar[i-1]){
      c ++;
    }else{
      ans = max(ans, c);
      c = 0;
    }
  }
  ans = max(ans, c);
  cout << ans;
}


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

int pre[50];
int in[50];
int pre_now=0;
int n;
vector<int>pos;

int in_find(int terget){
  int rec;
  for(int i=0;i<n;i++){
    if(in[i]==terget){
      rec=i;
      break;
    }
  }
  return rec;
}

void fukugen(int l,int r){
  if(l>=r)
    return;

  int root=pre[pre_now];pre_now++;
  int point=in_find(root);

  fukugen(l,point);
  fukugen(point+1,r);
  pos.push_back(root);

}

main(){

  cin >> n;
  for(int i=0;i<n;i++)
    cin >> pre[i];
  for(int i=0;i<n;i++)
    cin >> in[i];

  fukugen(0,n);

  for(int i=0;i<pos.size();i++){
    if(i)
      cout << " ";
    cout << pos[i];
  }
  cout << endl;

  return (0);
}

Measured memory_bytes: 3164
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int n;
    cin >> n;
    vector<int> a(n+1, 0);
    for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= n; j += i) {
			++a[j];
		}
	}
	ll total = 0;
	for(ll i = 1; i <= n; ++i) {
		total += (i*(ll)a[i]);
	}
	cout << total << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 42260
#include<iostream>
#include<algorithm>
#include<list>
#include<utility>
#include<string>

using namespace std;

list<int> l;

int main()
{
	cin.tie(0);
	ios::ios_base::sync_with_stdio(false);
	int orders; cin >> orders;
	for (int i = 0; i < orders; ++i) {
		string order; cin >> order;
		if (order == "insert") {
			int x; cin >> x;
			l.emplace_front(x);
		}
		else if (order == "delete") {
			int x; cin >> x;
			for (auto ite = l.begin(); ite != l.end(); ++ite) {
				if (*ite == x) {
					l.erase(ite);
					break;
				}
			}
		}
		else if (order == "deleteFirst")l.pop_front();
		else l.pop_back();
	}
	auto ite = l.begin();
	cout << *ite; ++ite;
	while (ite != l.end()) {
		cout <<" " << *ite;
		++ite;
	}cout << endl;
}

Measured memory_bytes: 32484
fun main(args: Array<String>) {
    val values = readLine()?.split(' ') ?: return
    if (values.size != 2) {
        return
    }
    val n = values[0].toInt()
    val m = values[1].toInt()

    // n, mの組み合わせの数を足す
    // n! / r!(n-r)!
    // n! / 2!(n - 2)!
    // n(n-1) / 2
    val nCount = (n * (n - 1)) / 2
    val mCount = (m * (m - 1)) / 2
    println(nCount + mCount)
}


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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> vec(M, 0);
    for(int n=0; n<N; n++) {
        int K;
        cin >> K;
        for(int k=0; k<K; k++) {
            int A;
            cin >> A;
            vec[A-1]++;
        }
    }
    
    int ans=0;
    for(int m=0; m<M; m++) {
        if(vec[m]==N) {
            ans++;
        }
    }
    
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);}
  ll che = abs(a.at(n-1))+abs(a.at(0));
  for(int i=1;i<n;i++){
    che+=abs(a.at(i-1)-a.at(i));
    }
for(int i=0;i<n;i++){
   if(i==0){
     ll ans = che;
     ans-=abs(a.at(i));
     ans-=abs(a.at(i)-a.at(i+1));
     ans+=abs(a.at(i+1));
     cout <<ans<<endl;
     continue;
     }
  if(i==n-1){
    ll ans = che;
    ans-=abs(a.at(i));
    ans-=abs(a.at(i)-a.at(i-1));
    ans+=abs(a.at(i-1));
    cout<< ans<<endl;
    continue;
    }
  ll ans = che;
  ans-=abs(a.at(i)-a.at(i-1));
  ans-=abs(a.at(i)-a.at(i+1));
  ans+=abs(a.at(i-1)-a.at(i+1));
  cout << ans<<endl;
  }
  
}



Measured memory_bytes: 1664
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int n;
	cin >> n;
	int a[200005], b[200005];
	rep(i, n) {
		cin >> a[i];
		a[i]--;
		b[a[i]] = i;
	}
	int now = -1, cnt = 0;
	int ma = 0;
	rep(i, n) {
		if (b[i] > now) {
			now = b[i];
			cnt++;
		}
		else {
			ma = max(ma, cnt);
			now = b[i];
			cnt = 1;
		}
	}
	ma = max(ma, cnt);
	cout << n - ma << endl;

	return 0;
}


Measured memory_bytes: 3328
def m(L,R):
 global c;c+=len(L)+len(R)
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:]))if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)


Measured memory_bytes: 63652
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = LI()
score = [0]  * (n + 1)
a_max = L[:n]
heapify(a_max)
max_sum = sum(a_max)
score[0] = max_sum
for i in range(n):
    heappush(a_max, L[n+i])
    max_sum += L[n + i]
    max_sum -= heappop(a_max)
    score[i+1] = max_sum



a_min = L[2 * n:]
min_sum = sum(a_min)
score[-1] -= min_sum


for i in range(len(a_min)):
    a_min[i] *= -1


heapify(a_min)


for i in range(n):
    min_sum += L[2*n-i-1]
    heappush(a_min, -L[2*n-i-1])
    min_sum += heappop(a_min)
    score[-2-i] -= min_sum



print(max(score))

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

struct st { int a, b, c; };
vector<st>E[10000];
int d[10000], c[10000];
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		rep(i, n)E[i].clear();
		rep(i, m) {
			int u, v, d, c; scanf("%d%d%d%d", &u, &v, &d, &c); u--; v--;
			E[u].push_back({ v,d,c }); E[v].push_back({ u,d,c });
		}
		memset(d, 0x3f, sizeof(d));
		priority_queue<P>que;
		d[0] = 0; que.push(P(0, 0));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			for (st&v : E[p.second]) {
				if (d[v.a] > p.first + v.b) {
					d[v.a] = p.first + v.b;
					c[v.a] = v.c;
					que.push(P(d[v.a], v.a));
				}
				else if (d[v.a] == p.first + v.b&&c[v.a] > v.c)c[v.a] = v.c;
			}
		}
		printf("%d\n", accumulate(c, c + n, 0));
	}
}

Measured memory_bytes: 4968
n=int(input())
a,b=map(int, input().split())
p=list(map(int, input().split()))

cnt1=0
cnt2=0
cnt3=0
for i in range(n):
    if p[i]<=a:
        cnt1+=1
    elif a<p[i]<=b:
        cnt2+=1
    else:
        cnt3+=1
print(min([cnt1,cnt2,cnt3]))


Measured memory_bytes: 9184
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  std::string S;
  ll K;
  std::cin >> S >> K;
  ll N = S.size();

  ll ans = 1;
  for (ll i = 0; i < N && i < K; i++) {
    if (S[i] == '1') continue;
    ans = S[i] - '0';
    break;
  }

  print(ans);

  return 0;
}


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

int count(int n,int i,char* str);

int main()
{
  int n,ans;
  char str[100];
  cin>>n;
  cin>>str;

  ans = 0;
  
  for(int i = 0 ; i <= n-1 ; i++)
  {
    if(ans < count(n,i,str))
    {
      ans = count(n,i,str);
    }
  }
  
  cout<<ans<<endl;
  
  return 0;
}

int count(int n,int i,char* str)
{
  int num = 0;
  bool doubling = false;
  
  for(int j = 0 ; j <= i-1 ; j++)
  {
    doubling = false;
    
    for(int l = 0 ; l <= j-1 ; l++)
    {
      if(str[j] == str[l])
      {
        doubling = true;
        break;
      }
    }


    if(doubling == false)
    {
      for(int k = i ; k <= n ; k++)
      {
        if(str[j] == str[k])
        {
          num++;
          break;
        }
      }
    }
  }  
  return num;
}

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

int main(){
  int k,n;
  cin>>k>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  int maxd=0;
  rep(i,n-1){
  maxd=max(maxd,a[i+1]-a[i]);
  }
  maxd=max(maxd,a[0]+k-a[n-1]);
  cout<<k-maxd;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
  int i,one;
  char str[8];
  
  fgets(str,sizeof(str),stdin);
  
  for(i=0;i<3;i++)
  {
    if(str[i] == '1')
    {
      one++;
    }
  }
  
  printf("%d",one);
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
	int n, i, j;
	int a[4][13];
	for(i=0; i<4; i++){
		for(j=1; j<14; j++){
			a[i][j]=0;
		}
	}
	scanf("%d", &n);
	char c;
	int d;
	for(i=0; i<n; i++){
		while(1){
			scanf("%c", &c);
			if(c!='\n'){
				break;
			}
		}
		scanf("%d", &d);
		switch(c){
			case 'S':
				a[0][d]=1;
				break;
			case 'H':
				a[1][d]=1;
				break;
			case 'C':
				a[2][d]=1;
				break;
			case 'D':
				a[3][d]=1;
				break;
		}
	}
	for(i=0; i<4; i++){
		for(j=1; j<14; j++){
			if(a[i][j]==0){
				switch(i){
					case 0:
						printf("S %d", j);
						break;
					case 1:
						printf("H %d", j);
						break;
					case 2:
						printf("C %d", j);
						break;
					case 3:
						printf("D %d", j);

				}
				printf("\n");
			}
		}
	}
	return 0;	
}

Measured memory_bytes: 600
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, k;
  cin >> n >> k;
  vll a(n);
  rep(i, n){
    cin >> a[i];
    a[i]--;
  }
  ll t = 0;
  vll time(n, -1);
  {
    ll cur = 0;
    bool ring = 0;
    while(1){
      dump(t, cur, time);
      if(time[cur] != -1 && !ring){
        ring = 1;
        t = k-(k-t)%(t-time[cur]);
        if(t == k){
          print(cur+1);
          return 0;
        }
      }
      time[cur] = t;
      cur = a[cur];
      t++;
      if(t == k){
        print(cur+1);
        return 0;
      }
    }
  }
}


Measured memory_bytes: 6340
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b, k;
  cin >> a >> b >> k;
  int t = min(a, k);
  a -= t;
  k -= t;
  b -= min(b, k);
  cout << a << ' ' << b << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

int main(){
	IOS;
	ll n,k;cin>>n>>k;
	string s;cin>>s;
	vll v;
	ll c=1;
	rep(i,1,s.length()){
		if(s[i]==s[i-1])c++;
		else v.pb(c),c=1;
	}v.pb(c);
	ll sum=0,ans=-1,f=0;
	if(s[0]=='0'){
		ll u=v.size();
		ll x=min(2*k,u);
		rep(i,0,x)sum+=v[i];
		ans=max(ans,sum);
		rep(i,0,v.size()){
			if(i%2==0){
				sum-=v[i];
				if(i>=1)sum-=v[i-1];
				if(i+2*k<=v.size()-1)sum+=v[i+2*k];
				else break;
				if(i+2*k+1<=v.size()-1)sum+=v[i+2*k+1];
				else break;
				ans=max(ans,sum);
			}
		}
		ans=max(ans,sum);
	}
	else{
		ll u=v.size();
		ll x=min(2*k+1,u);
		rep(i,0,x)sum+=v[i];
		ans=max(ans,sum);
		rep(i,0,v.size()){
			if(i%2==1){
				sum-=v[i];
				if(i>=1)sum-=v[i-1];
				if(i+2*k<=v.size()-1)sum+=v[i+2*k];
				else break;
				if(i+2*k+1<=v.size()-1)sum+=v[i+2*k+1];
				else break;
				ans=max(ans,sum);
			}
		}
		ans=max(ans,sum);
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 1528
#include<iostream>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	vector<int>b(n);
	int sum=0;
	rep(i,n){
		sum = sum^a[i];
	}
	rep(i,n)cout<<(sum^a[i])<<endl;


	return 0;
}

Measured memory_bytes: 4772
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num1 = scanner.nextInt();
		int num2 = scanner.nextInt();
		int num3 = scanner.nextInt();
		int count = 0;
		for (int i = num1; i <= num2; i++) {
			if (num3 % i == 0)
				count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 17292
//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <map>
//#include <iostream>
//#include <algorithm>
//#include <set>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pli = pair<ll,int>; 		
#define fi first
#define v vector
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
int INF = 1e9+7;
ll inf = 1e18+7;
int MOD = 1e9+7;

void add_self(auto &a, auto b){
	a += b;
	if(a >= MOD){
		a -= MOD;
	}
}

void max_self(auto &a, auto b){
	if(b > a)	a = b;
}

void topsort(int i, v<vi>& graph, vb& visit, stack<int>& res){
	visit[i] = true;
	
	for(int x : graph[i]){
		if(!visit[x])
		topsort(x,graph,visit,res);
	}
	res.push(i);
}

const int N = 3010;

ll dp[N][N];

void solve(){
	
	for(int i = 0; i < N; ++i){
		for(int j = 0; j < N; ++j){
			dp[i][j] = -inf;
		}
	}
	int n;
	scanf("%d",&n);
	vi arr(n);
	for(int i = 0; i < n ; ++i){
		scanf("%d",&arr[i]);
	}
	for(int i = 1; i <= n; ++i){
		for(int start = 0; start < n; ++start){
			int l = start;
			int r = start + i - 1;
			if(r >= n)	break;
			if(l == r){
				dp[l][r] = arr[l];
				continue;
			}
			max_self(dp[l][r], arr[r]  - dp[l][r-1]);
			max_self(dp[l][r], arr[l]  - dp[l+1][r]);
		}
	}
	printf("%lld\n", dp[0][n-1]); 
				
	
}	



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	//scanf("%d",&t);
	while(t--){
		solve();
	}
		
			
}


Measured memory_bytes: 74568
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int num;
	scanf("%d", &num);
	vector<int>v;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		v.push_back(z);
	}
	sort(v.begin(), v.end());
	if (v[num - 1] - v[0]>1)printf("No\n");
	else if (v[0] == v[num - 1])
	{
		if (v[0] == num - 1 || v[0] <= num / 2)printf("Yes\n");
		else printf("No\n");
	}
	else
	{
		int c = 0;
		for (int i = 0; i < num; i++)if (v[i] == v[0])c++;
		if (c <= v[0] && v[0] <= c - 1 + (num - c) / 2)printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a, ia;
int main() {
  cin >> n;
  read_n(a, n, 1);
  init_n(ia, n + 1);
  for (i64 i = 1; i <= n; ++i) {
    ia[a[i]] = i;
  }

  set<i64> wall;
  wall.insert(0);
  wall.insert(n + 1);

  i64 ans = 0;
  for (i64 x = 1; x <= n; ++x) {
    auto rit = wall.lower_bound(ia[x]), lit = rit;
    --lit;
    i64 i = ia[x], l = *lit, r = *rit;
    ans += (r - i) * (i - l) * x;
    cerr << x << '\t' << l << '\t' << i << '\t' << r << '\n';
    wall.insert(ia[x]);
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 12800
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <functional>
#include <cmath>
#include <complex>

using namespace std;
#define PI       3.14159265358979323846
#define MOD 1000000007

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef complex<double> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;

int c[3][3];

bool ok(VI v){
	int tmp = v[0] - v[3];
	if (v[1] - v[4] != tmp)return false;
	if (v[2] - v[5] != tmp)return false;
	return true;
}

int main() {
	REP(i, 3)REP(j, 3)scanf("%d", &c[i][j]);
	//縦
	REP(i, 2) {
		VI tmp = { c[2][0], c[2][1], c[2][2], c[i][0], c[i][1], c[i][2] };
		if (!ok(tmp)) {
			cout << "No" << endl;
			return 0;
		}
	}
	//横
	REP(i, 2) {
		VI tmp = { c[0][2], c[1][2], c[2][2], c[0][i], c[1][i], c[2][i] };
		if (!ok(tmp)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int N,M;
  int *a,*b,*c,*d;
  int kyori,min,flag=0;
  
  scanf("%d %d",&N,&M);
  a=(int*)malloc(sizeof(int)*N);
  b=(int*)malloc(sizeof(int)*N);
  c=(int*)malloc(sizeof(int)*M);
  d=(int*)malloc(sizeof(int)*M);
  for(int i=0;i<N;i++)
    scanf("%d %d",&a[i],&b[i]);
  for(int i=0;i<M;i++)
    scanf("%d %d",&c[i],&d[i]);
  
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      if(flag==0){
        kyori=abs(a[i]-c[j])+abs(b[i]-d[j]);
        min=j;
        flag=1;
      }
      else if(kyori>abs(a[i]-c[j])+abs(b[i]-d[j])){
        kyori=abs(a[i]-c[j])+abs(b[i]-d[j]);
        min=j;
      }
    }
    printf("%d\n",min+1);
    flag=0;
  }
  
  return 0;
}

Measured memory_bytes: 128