akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
const long long mod=998244353;
const int nmax=300005;
map<long long,long long> m;
long long fact[nmax],inv[nmax];
long long n,a,b,k,i,ans;
long long expo(long long A,long long B)
{
    long long p2=A,ret=1;
    for(int p=0;p<=30;p++)
    {
        if(((1<<p)&B))
        {
            ret=(1LL*ret*p2)%mod;
        }
        p2=(1LL*p2*p2)%mod;
    }
    return ret;
}
long long C(int A,int B)
{
    return (((1LL*inv[B]*inv[A-B])%mod)*fact[A])%mod;
}
int main()
{
   // freopen("data.in","r",stdin);
    cin>>n>>a>>b>>k;
    fact[0]=1;
    for(i=1;i<=n;i++)
        fact[i]=(1LL*fact[i-1]*i)%mod;
    inv[n]=expo(fact[n],mod-2);
    for(i=n-1;i>=0;i--)
        inv[i]=(1LL*inv[i+1]*(i+1))%mod;
    for(i=0;i<=n;i++)
        m[i*a]=C(n,i);
    for(i=0;i<=n;i++)
    {
        ans=(1LL*ans+C(n,i)*m[k-i*b])%mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 42496
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.17 23:10:50
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

constexpr int MOD = 1e9 + 7;
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((MOD+x)%MOD) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= MOD;
        }
        this->x = z;
    }
    mint& operator+=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint& operator/=(const mint &a) {
        long long n = MOD - 2;
        mint u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};
int main() {
    int n,m;cin >> n >> m;
    vector<int> x(n),y(m);
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < m; i++) cin >> y[i];
    mint sum_x = 0, sum_y = 0;
    for (int i = 0; i < n-1; i++) sum_x += mint(i+1) * (n-i-1) * (x[i+1] - x[i]);
    for (int i = 0; i < m-1; i++) sum_y += mint(i+1) * (m-i-1) * (y[i+1] - y[i]);
    cout << sum_x * sum_y << endl;
    return 0;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


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


ll mod=1000000007;
ll vis[212345]={0};
vvi v(212345);
ll d[212345]={0};


ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}


ll f[1000009];


int main()
{
speed
ll n;
cin>>n;
ll f[n];
mem(f,0);
string s;
cin>>s;
if(s[0]=='W') f[0]=1;
else f[0]=0;
rep(i,1,n)
{
	f[i]=f[i-1];
	if(s[i]=='W') f[i]++;
}
ll z=min(f[n-1],n-f[n-1]);
if(z==0)
{
	cout<<"0\n";
	return 0;
}
if(z==f[n-1])
{
	z=min(z,f[n-z-1]);
}
else
{
	z=min(z,f[z-1]);
}
cout<<z<<endl;

}



Measured memory_bytes: 10148
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

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

    vector<P> d;
    int now = 1;
    rep(i, 0, 4){
        int a;
        cin >> a;
        d. push_back(P(8 / now * a, now));
        now *= 2;
    }
    int n;
    cin >> n;
    int ans = 0;
    n *= 4;
    sort(all(d));
    rep(i, 0, 4){
        if(n >= d[i].second){
            ans += n / d[i].second * d[i].first * d[i].second / 8; 
            n %= d[i].second;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
def merge(target_list, left_index, right_index):
    global count
    mid_index = (left_index + right_index) // 2
    l = target_list[left_index:mid_index] + [pow(10,9) + 1]
    r = target_list[mid_index:right_index] + [pow(10,9) + 1]
    l_target = 0
    r_target = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1
    #print(target_list)
def merge_sort(target_list, left_index, right_index):
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        merge_sort(target_list, left_index, mid_index)
        merge_sort(target_list, mid_index, right_index)
        merge(target_list, left_index, right_index)
    
if __name__ == "__main__":
    l = input()
    target_list = [int(a) for a in input().split()]
    global count
    count = 0
    merge_sort(target_list, 0, len(target_list))
    print(" ".join([str(n) for n in target_list]))
    print(count)

Measured memory_bytes: 69016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = (int)1e9 + 7;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int n, m;
const int maxN = 1005;
int a[maxN], b[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for (int j = 1; j <= m; j++) {
        cin >> b[j];
    }
    sort(b + 1, b + m + 1);
    reverse(a + 1, a + n + 1);
    reverse(b + 1, b + m + 1);
    if (a[1] != n * m) {
        cout << 0;
        return 0;
    }
    if (b[1] != n * m) {
        cout << 0;
        return 0;
    }
    int ans = 1;
    int k = 1;
    int l = 1;
    int free = 0;
    for (int i = n * m - 1; i >= 1; i--) {
        if (k == n && l == m) {
            ans = mult(ans, free);
            free--;
            continue;
        }
        if (k == n) {
            if (b[l + 1] == i) {
                ans = mult(ans, n);
                free += (n - 1);
                l++;
                continue;
            }
            else {
                if (free == 0) {
                    cout << 0;
                    return 0;
                }
                ans = mult(ans, free);
                free--;
                continue;
            }
        }
        if (l == m) {
            if (a[k + 1] == i) {
                ans = mult(ans, m);
                free += m - 1;
                k++;
                continue;
            }
            else {
                if (free == 0) {
                    cout << 0;
                    return 0;
                }
                ans = mult(ans, free);
                free--;
            }
        }
        else {
            if (a[k + 1] == i && b[l + 1] == i) {
                free += k;
                free += l;
                l++;
                k++;
                continue;
            }
            else {
                if (a[k + 1] > i || b[l + 1] > i) {
                    cout << 0;
                    return 0;
                }
                if (a[k + 1] == i) {
                    ans = mult(ans, l);
                    free += l - 1;
                    k++;
                }
                else if (b[l + 1] == i) {
                    ans = mult(ans, k);
                    free += k - 1;
                    l++;
                }
                else {
                    if (free == 0) {
                        cout << 0;
                        return 0;
                    }
                    ans = mult(ans, free);
                    free--;
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {

  val n = readInt()
  val L = readLine().split(" ").map(_.toInt)

  def solve() = {
    var ans = 0
    for {
      i <- 0 until n
      j <- i until n
      k <- j until n
    } {
      val (a,b,c) = (L(i), L(j), L(k))
      val max = Math.max(Math.max(a,b), c)
      val isTriangle = max < a+b+c - max
      val isUnique = a != b && b != c && c != a
      if(isTriangle && isUnique) ans += 1
    }
    ans
  }

  println(solve())

}



Measured memory_bytes: 58968
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2000;
ll vis[N][N];
vector <vector <int> > f(ll x,ll y){
    memset(vis,0,sizeof vis);
    if (x==0){
       // cout << y << endl;
        vector <int> a;
        for (int i=0;i<=y;i++){
            a.pb((i+1)%2);
        }
        vector <vector <int> > z;
        z.pb(a);
        return z;
    }
    if (y==0){
        vector <vector <int> > y;
            vector <int> z;
            z.pb(1);
        for (int i=0;i<=x;i++){
            y.pb(z);
            z.clear();
            z.pb(i%2);
        }
        return y;
    }
    vector <vector <int> > z=f(x/2-1,y/2-1);
  //  cout << x/2 << " " << y/2 << " " << z.size() << " " << z[0][0] << endl;
    for (int i=0;i<=x;i++){
        for (int j=0;j<=y;j++){
            if (i==x/2 || j==y/2){
                vis[i][j]=1;
                if (i==x/2 && j==y/2) vis[i][j]=0;
                continue;
            }
            ll s=i,d=j;
            if (i>x/2) s-=(x+2)/2;
            if (j>y/2) d-=(y+2)/2;
            vis[i][j]=z[s][d];
        }
    }
    vector <vector <int> > ans;
    for (int i=0;i<=x;i++){
        vector <int> z;
        for (int j=0;j<=y;j++){
            z.pb(vis[i][j]);
        }
        ans.pb(z);
    }
    return ans;
}
int32_t main(){
    sync;
    ll n,m;
    cin >> n >> m;
    ll x=(1<<n)-1;
    ll y=(1<<m)-1;
    x--,y--;
    vector <vector <int> > a;
    a=f(x,y);
    for (int i=0;i<=x;i++){
        for (int j=0;j<=y;j++){
            cout << a[i][j] ;
        }
        cout << endl;
    }

}


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

int main(){
    int64_t money;
    bool f = 0;
    while(cin >> money && money > 0){
        if(f == 1) cout << endl;
        int64_t jyu, hyaku, gojyu, gohyaku;
        cin >> jyu >> gojyu >> hyaku >> gohyaku;
        int64_t total = jyu * 10 + gojyu * 50 + hyaku * 100 + gohyaku * 500;
        total -= money;
        int64_t cjyu = 0, cgojyu = 0, chyaku = 0, cgohyaku = 0;
        while(total >= 500){
            cgohyaku++;
            total -= 500;
        }
        //cout << "cgohyaku" << cgohyaku << endl;
        while(total >= 100){
            chyaku++;
            total -= 100;
        }
        while(total >= 50){
            cgojyu++;
            total -= 50;
        }
        while(total >= 10){
            cjyu++;
            total -= 10;
        }
        if(jyu - cjyu > 0) cout << 10 << ' ' << jyu - cjyu << endl;
        if(gojyu - cgojyu > 0) cout << 50 << ' ' <<  gojyu - cgojyu << endl;
        if(hyaku - chyaku > 0) cout << 100 << ' ' << hyaku - chyaku << endl;
        if(gohyaku - cgohyaku > 0) cout << 500 << ' ' <<  gohyaku - cgohyaku << endl;
        f = 1;
    }
    return 0;
}



Measured memory_bytes: 2980
package main

import (
	"fmt"
)

func main(){
	var a, b int
	var op string
	fmt.Scan(&a)
	fmt.Scan(&op)
	fmt.Scan(&b)
	
	if op == "+"{
		fmt.Println(a+b)
	}else {
		fmt.Println(a-b)
	}
}

Measured memory_bytes: 512
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define uni(x) sort(all(x)),x.resize(unique(all(x))-x.begin());
#define GETPOS(c,x) (lower_bound(all(c),x)-c.begin())
#define lown1(x,val) low(in(x),val)-x
#define lowm1(x,val) low(im(x),val)-x
#define low1(x,nums,val) low(x+1,x+nums+1,val)-x
#define mst(x,val) memset((x),val,sizeof((x)))
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define far(i,V) for(auto &i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b))/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) ((x)&(-x))
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (((x)<0)?(x)%mo_num+mo_num:(x)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define Umap unordered_map<int,int>
#define P pair<int,int>
#define SET set<int>
#define mk make_tuple
#define eps 1e-6
//Remember cancel"#define endl '\n'" in interactive questions or use "<<flush"
#define endl '\n'
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
//#define yn(key) out(key?"Yes":"No")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define ik(i,k) i+1,i+1+k
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define db double
#define ll long long
#define got(container,num) get<num-1>(container)
#define int long long
#define print(a,n) fun(i)cout<<a[i]<<(i!=n?' ':endl);
#define outcase(x) cout<<"Case #"<<(++case_of_T)<<": "<<(x)<<endl;
#define ptcase(x) printf("Case #%d: %d\n",++case_of_T,x);
#define plcase(x) printf("Case #%lld: %lld\n",++case_of_T,x);
using namespace std;
//Remember to cancel the line below and declare INT=INT_MAX/2; when you want to change long to int
const int INF=LLONG_MAX/4,SINF=0x3f3f3f3f,Lim=1<<20,MINF=LLONG_MAX;
//const int INF=INT_MAX/4,SINF=0x3f;
// use C:printf("%.16f", x);  ->  printf("%.10f", x); can accelerate the program
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//down up left right
const int maxn=1e6+1e5;
int mo_num=1e9+7;
//const int mo_num=998244353;
int n,m,t,a[maxn],b[maxn],ans,case_of_T;

void solve()
{
    cin>>n;
    fun(i)
    {
        ans+=n/i-(n%i==0);
    }
    out(ans)
    return ;
}
main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)solve();
    return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
 
using namespace std;
 
struct edge {
    int to, cost;
    edge(int to, int cost) : to(to), cost(cost){}
};
 
vector<edge> G[39393];
 
int dist[39393];
 
int getMax(int v)
{
    if (dist[v] >= 0) return (dist[v]);
     
    if (v == 0) return (0);
     
    int res = 0;
    for (int i = 0; i < G[v].size(); i++)
        res = max(res, getMax(G[v][i].to) + G[v][i].cost);
     
    return (dist[v] = res);
}
 
int main()
{
    int n, m;
     
    scanf("%d %d", &n, &m);
     
    memset(dist, -1, sizeof(dist));
     
    for (int i = 0; i < m; i++){
        int from, to, cost;
        scanf("%d %d %d", &from, &to, &cost);
        G[to].push_back(edge(from, cost));
    }
     
    printf("%d\n", getMax(n - 1));
     
    return (0);
}

Measured memory_bytes: 2128
#include<bits/stdc++.h> 
using namespace std; 
  
const int MAX = 500005; 
// Code Snippet GeeksForGeeks
// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 
  
int main()
{
    int n,q;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
     cin>>arr[i];
    Query qe[q]; 
    int x,y;
    for(int i=0;i<q;i++)
    {
        cin>>x>>y;
        x--;
        y--;
        qe[i].l=x;
        qe[i].r=y;
        qe[i].idx=i;
    }
    sort(qe, qe+q, cmp); 
    answeringQueries(arr, n, qe, q); 
}

Measured memory_bytes: 17436
/*
 * @Author: Kaizyn
 * @Date: 2020-08-28 10:42:58
 * @LastEditTime: 2020-08-28 14:03:36
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 2e5+3;
const int INF = 0x3f3f3f3f;
const int G = 2;
const int N = 2e5+7;

struct comp {
  typedef double T; // maybe long double ?
  T real, imag;
  comp (const double &_real = 0, const double &_imag = 0) : real(_real), imag(_imag) {}
  friend comp operator + (const comp &c1, const comp &c2) { return comp(c1.real+c2.real, c1.imag+c2.imag); }
  friend comp operator - (const comp &c1, const comp &c2) { return comp(c1.real-c2.real, c1.imag-c2.imag); }
  friend comp operator * (const comp &c1, const comp &c2) { return comp(c1.real*c2.real-c1.imag*c2.imag, c1.real*c2.imag+c1.imag*c2.real); }
  comp& operator += (const comp &c) { return *this = *this+c; }
  comp& operator -= (const comp &c) { return *this = *this-c; }
  comp& operator *= (const comp &c) { return *this = *this*c; }
  friend istream& operator >> (istream &is, comp &c) { return is >> c.real >> c.imag; }
  friend ostream& operator << (ostream &os, comp &c) { return os << c.real << setiosflags(ios::showpos) << c.imag << "i";}
  comp conjugate() { return comp(real, -imag); }
  friend comp conjugate(const comp &c) { return comp(c.real, -c.imag); }
};

namespace FFT {
  static const int SIZE = 1<<19;
  int len, bit;
  int rev[SIZE];
  // #define comp complex<long double>
  void fft(comp a[], int flag = 1) {
    for (int i = 0; i < len; ++i)
      if (i < rev[i]) swap(a[i], a[rev[i]]);
    for (int base = 1; base < len; base <<= 1) {
      comp w, wn = {cos(PI/base), flag*sin(PI/base)};
      for (int i = 0; i < len; i += base*2) {
        w = { 1.0, 0.0 };
        for (int j = 0; j < base; ++j) {
          comp x = a[i+j], y = w*a[i+j+base];
          a[i+j] = x+y;
          a[i+j+base] = x-y;
          w *= wn;
        }
      }
    }
  }
  template <class T>
  void work(T a[], const int &n) {
    static comp f[SIZE];
    len = 1; bit = 0;
    while (len < n+n) len <<= 1, ++bit;
    // multi-testcase
    for (int i = 0; i < n; ++i) f[i] = a[i];
    for (int i = n; i < len; ++i) f[i] = 0;
    for (int i = 0; i < len; ++i) rev[i] = (rev[i>>1]>>1)|((i&1)<<(bit-1));
    fft(f, 1);
    for (int i = 0; i <= len; ++i) f[i] *= f[i];
    fft(f, -1);
    for (int i = 0; i < n+n; ++i) a[i] = static_cast<T>(f[i].real/len+.5);
  }
}

int n;
int a[N], mp[N], pw2[N];
long long cnt[N<<1];

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  pw2[0] = 1; mp[1] = 0;
  for (int i = 1; i < MOD-1; ++i) {
    pw2[i] = pw2[i-1]*G%MOD;
    mp[pw2[i]] = i;
  }

  long long res = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (!a[i]) continue;
    a[i] = mp[a[i]];
    ++cnt[a[i]];
    res -= pw2[a[i]*2%(MOD-1)];
  }
  #ifdef DEBUG
  for (int i = 1; i <= n; ++i) cout << a[i] << " \n"[i==n];
  cout.flush();
  #endif
  FFT::work(cnt, MOD-1);
  for (int i = 0; i < MOD*2-2; ++i) if (cnt[i]) {
    res += pw2[i%(MOD-1)]*cnt[i];
  }
  cout << res/2 << endl;
  return 0;
}

Measured memory_bytes: 19552
#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> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;

vector<int> p;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	int r = 0, w = 0;
	vector<int> p;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R'){
			r++;
			p.push_back(i);
		}
		else w++;
 	}
	string t = "";
	for(int i = 0; i < n; i++){
		if(i < r) t += 'R';
		else t += 'W';
	}
	for(int i = 0; i < n; i++){
		if(s[i] != t[i]) ans++;
		if(i == r-1) break;
	}
	cout << ans << endl;
} 

Measured memory_bytes: 4528
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cerr << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define X first
#define Y second
#define pb push_back
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define vi vector<int>
#define vii vector<vector<int>>

void solve(int& a, int& b, int& c){
	if(a >= b && b >= c){
		c *= 2;
	}
	else if(a <= b && b <= c){
		c *= 2;	
	}
	else if(a >= b && b <= c){
		b *= 2;
	}
	else if(a <= b && b >= c){
		c *= 2;
	}
	
}
//a > b > c
//a < b < c
//a > b < c
//a < b > c
int main(){ fast;
	int a, b, c, k; cin>>a>>b>>c>>k;
	bool flag = false;
	for(int i = 0; i <= k; i++){
		for(int j = 0; j <= k; j++){
			for(int k1 = 0; k1 <= k; k1++){
				int x = a * (1 << i), y = b * (1 << j), z = c * (1 << k1);
				if(i + j + k1 <= k && x < y && y < z) flag  =true;
			}
		}
	}
	cout<<(flag ? "Yes" : "No")<<endl;
}


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

using namespace std;

int main() {
	int X, N, ans;
	cin >> X >> N;
	vector<int> p(N);

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

	for (int i = 0; true; i++) {
		bool a_is_ok = true, b_is_ok = true;
		int a, b;
		a = X + i;
		b = X - i;
		for (int j = 0; j < N; j++) {
			if (a == p[j]) {
				a_is_ok = false;
			}
			if (b == p[j]) {
				b_is_ok = false;
			}
		}
		if (a_is_ok && b_is_ok) {
			ans = b;
			break;
		}
		else if (a_is_ok) {
			ans = a;
			break;
		}
		else if (b_is_ok) {
			ans = b;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
import math
A, B = map(int, input().split())
x1 = math.ceil(100 * A / 8)
x2 = 100 * (A+1) / 8
y1 = 100 * B / 10
y2 = 100 * (B+1) / 10
if x1 <= y1 and y1 < x2:
  print(int(y1))
elif y1 <= x1 and x1 < y2:
  print(int(x1))
else:
  print(-1)

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

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(0, a - 2 * b) << '\n';
}


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

int main(void){
    int i;
    char s[13];
    char t[13];
    char d[13];
    int flag=1;
    
    (void)scanf("%s",s);
    (void)scanf("%s",t);
    for(i=0;i<strlen(s);i++){
        d[i]=t[i];
    }
    if(strlen(t)-strlen(s)){
        for(i=0;i<strlen(s);i++){
            if(s[i]!=d[i]){
                flag=0;
            }
        }
        if(flag){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  cin >> s >> t;
  cout << t << s << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
  long w,h; cin >>h >>w;
  long long odd_h,even_h, ans=0;
  
  ans=(h*w)/2;
  ans+=(h*w)%2;
  
  if(h==1 || w==1) ans=1;
  
  cout <<ans <<endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6+10;
int a[N];
int cnt[N];
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=2;j*j<=a[i];j++)
        {
            if(a[i] % j == 0)
            {
                cnt[j]++;
                while(a[i] % j == 0)
                {
                    a[i] = a[i] / j;
                }

            }

        }
        if(a[i] > 1)
            cnt[a[i]]++;
    }
//    for(int i=1;i<=3;i++)
//    {
//        cout << a[i] << " ";
//    }
    int temp = 0;
    for(int i=2;i<=1e6;i++)
    {
//        cout << cnt[i] << " ";
        temp = max(temp,cnt[i]);
    }
//    cout << temp << "\n";
    if(temp == n)
    {
        cout << "not coprime\n";
    }
    else if(temp > 1)
    {
        cout << "setwise coprime\n";
    }
    else{
        cout << "pairwise coprime\n";
    }
    return 0;
}

Measured memory_bytes: 11416
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*
iについて、iより小さい全ての整数jに対して、p[i]がp[j]以下

4 2 5 1 3
i=1は自明
i=2 p[2]=2, p[1]=4
i=3 p[3]=5, p[2]=2 ...

つまり、左側の数列のどの数よりも小さければ良い
線形オーダで実装するために、各数列の最小値を左から順に格納していく
*/

int p[200010];
int m[200010];

void solve(){
    int n;
    cin >> n;
    rep(i,n){
        cin >> p[i];
    }
    int mi = p[0];
    rep(i,n){
        mi=min(mi,p[i]);
        m[i]=mi;
    }
    int count = 0;
    rep(i,n){
        if(m[i]==p[i]) count++;
    }

    
    cout << count << endl;
}

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


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

int main(void){
    string s; cin >> s;
    ll k; cin >> k;

    s+='0';
    for(ll i=0; i<k; i++){
        if(s[i]=='0'){
            cout << '1' << endl;
            return 0;
        }

        if(s[i]!='1'){
            cout << s[i] << endl;
            return 0;
        }
    }

    cout << '1' << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int N;
vector<vector<int>> G;

int bfs(vector<bool> &visited,vector<int> &num,int i){
    queue<int> q;
    num[i] = 1;
    visited[i] = true;
    q.push(i);
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(int v : G[u]){
            if(visited[v]){
                if(abs(num[u]-num[v]) != 1) return -1;
            }
            if(!visited[v]){
                visited[v] = true;
                num[v] = num[u]+1;
                q.push(v);
            }
        }
    }
    int res = 0;
    rep(i,N){
        res = max(res,num[i]);
    }
    return res;

}

int main(){
    cin >> N;
    G.resize(N);
    vector<vector<char>> S(N,vector<char>(N));
    rep(i,N)rep(j,N) cin >> S[i][j];
    rep(i,N)rep(j,N){
        if(S[i][j] == '1'){
            G[i].push_back(j);
            G[j].push_back(i);
        }
    }
    int ans = 0;
    rep(i,N){
        vector<bool> visited(N,false);
        vector<int> num(N);
        if(bfs(visited,num,i) == -1){
            ans = -1;
            break;
        }
        ans = max(ans,bfs(visited,num,i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
index = int(input())
print(list[index-1])

Measured memory_bytes: 3060
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int[] answer = new int[n];

		Set<Integer> visited = new HashSet<>();
		Map<Integer, Set<Integer>> h = new HashMap<>();
		Queue<int[]> q = new LinkedList<>();
		for (int i = 0; i < n; i++) {
			q.clear();
			visited.clear();
			h.clear();

			q.offer(new int[]{i, 0});
			visited.add(i);
			while (!q.isEmpty()) {
				int[] p = q.poll();
				answer[p[1]]++;

				if (p[0] + 1 < n && !visited.contains(p[0] + 1)) {
					visited.add(p[0] + 1);
					q.add(new int[]{p[0] + 1, p[1] + 1, p[0]});
				}

				if (x - 1 == p[0] && !visited.contains(y - 1)) {
					visited.add(y - 1);
					q.add(new int[]{y - 1, p[1] + 1, p[0]});
				}

				if (y - 1 == p[0] && !visited.contains(x - 1)) {
					visited.add(x - 1);
					q.add(new int[]{x - 1, p[1] + 1, p[0]});
				}

				if (p[0] - 1 >= 0 && !visited.contains(p[0] - 1)) {
					visited.add(p[0] - 1);
					q.add(new int[]{p[0] - 1, p[1] + 1, p[0]});
				}
			}
		}


		StringBuilder sb = new StringBuilder();
		for (int k = 1; k <= n - 1; k++) {
			sb.append(Math.max(0, answer[k] / 2)).append("\n");
		}

		System.out.print(sb);
	}
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second

using namespace std;

const int maxn = 2e5 + 7;

int n,m;
vector<int>ord,comp;
int used[maxn],cl[maxn],u[maxn];
vector< pair<int,int> >g[maxn];
int check = 1;

void dfs (int v, int d) {
    used[v] = 1;
    cl[v] = d;
    comp.pb(v);
    for (int i = 0; i < g[v].size(); i ++) {
        int to = g[v][i].F;
        int len = g[v][i].S;
        if (!used[to]) {
            dfs(to, d + len);
        }
        else {
            if (cl[to] != d + len)check = 0;
        }
    }
}


int main () {

cin >> n >> m;

for (int i = 1; i <= m; i ++) {
    int l = 0, r = 0, d = 0;
    cin >> l >> r >> d;
    g[l].pb(mp(r,d));
    g[r].pb(mp(l,-d));
}

for (int i = 1; i <= n; i ++) {
    if (!used[i]) {
        dfs(i, 0);
        if (!check) {
            cout << "No" << endl;
            return 0;
        }
    }
}

cout << "Yes" << endl;

return 0;
}


Measured memory_bytes: 16256
import Data.List

allswap :: [[Integer]] -> [String]
allswap ([x,y]:ps)
    | x == 0 && y == 0 = []
    | otherwise        = ((unwords . map show . sort) [x, y]) : (allswap ps)

main = do
    givenstr <- getContents
    putStr ((unlines . allswap . map (map (read :: String -> Integer)) . map words . lines) givenstr)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;
const int w_max = 1e5;

// dp[i][j] : i番目までの品物から重さ j 以下になるように選んだときの価値の最大値
LL dp[101][w_max + 1];

void solve()
{
    int N;
    cin >> N;
    int W;
    cin >> W;
    vector<int> w(N);
    vector<LL> v(N);
    REP0(i, N)
    {
        cin >> w[i] >> v[i];
    }

    REP0(i, N)
    {
        REP1(j, W)
        {
            if (i == 0)
            {
                dp[0][j] = (w[0] <= j) ? v[0] : 0;
                continue;
            }

            if (0 <= j - w[i])
                dp[i][j] = max(dp[i - 1][j],
                               dp[i - 1][j - w[i]] + v[i]);
            else
                dp[i][j] = dp[i - 1][j];
        }
    }

    cout << dp[N - 1][W] << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

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

struct Dice {
 public:
  vector<int> num = vector<int>(6);
  vector<int> tmp = vector<int>(6);

  void Roll(char ch) {
    tmp = num;
    if (ch == 'S') {
      num.at(0) = tmp.at(4);
      num.at(1) = tmp.at(0);
      num.at(2) = tmp.at(2);
      num.at(3) = tmp.at(3);
      num.at(4) = tmp.at(5);
      num.at(5) = tmp.at(1);
    } else if (ch == 'W') {
      num.at(0) = tmp.at(2);
      num.at(1) = tmp.at(1);
      num.at(2) = tmp.at(5);
      num.at(3) = tmp.at(0);
      num.at(4) = tmp.at(4);
      num.at(5) = tmp.at(3);

    } else if (ch == 'N') {
      num.at(0) = tmp.at(1);
      num.at(1) = tmp.at(5);
      num.at(2) = tmp.at(2);
      num.at(3) = tmp.at(3);
      num.at(4) = tmp.at(0);
      num.at(5) = tmp.at(4);

    } else if (ch == 'E') {
      num.at(0) = tmp.at(3);
      num.at(1) = tmp.at(1);
      num.at(2) = tmp.at(0);
      num.at(3) = tmp.at(5);
      num.at(4) = tmp.at(4);
      num.at(5) = tmp.at(2);
    } else if (ch == 'C') {
      num.at(0) = tmp.at(0);
      num.at(1) = tmp.at(2);
      num.at(2) = tmp.at(4);
      num.at(3) = tmp.at(1);
      num.at(4) = tmp.at(3);
      num.at(5) = tmp.at(5);
    }
  }
  void Print(int n) { cout << num.at(n) << endl; }
  int Check(int a) { return num.at(a); }
  void Check(int a, int b) {
    int upn, frontn;
    for (int i = 0; i < 6; i++) {
      if (a == num.at(i)) upn = i;
      if (b == num.at(i)) frontn = i;
    }
    if (upn == 4 && frontn == 0)
      Roll('S');
    else if (upn == 2 && frontn == 1)
      Roll('W');
    else if (upn == 1 && frontn == 5)
      Roll('N');
    else if (upn == 3 && frontn == 1)
      Roll('E');
  }
};

int main() {
  Dice D;
  for (int i = 0; i < 6; i++) {
    cin >> D.num.at(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    if (a == D.Check(3))
      D.Roll('E');
    else if (a == D.Check(2))
      D.Roll('W');
    while (a != D.Check(0)) D.Roll('S');
    while (b != D.Check(1)) D.Roll('C');
    D.Print(2);
  }
}


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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll n, k;
  cin >> n >> k;

  string s;
  cin >> s;

  ll count = 0;
  REP(i, n - 1) {
    if (s[i] != s[i + 1]) {
      count++;
    }
  }

  ll sukima = count;
  sukima = max(ll(0), count - 2 * k);

  COUT(n - 1 - sukima);
}

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

/*
6 1
LRLRRL


13 3
LRRLRLRRLRLLR
*/


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)

#define pb              push_back
#define ff              first
#define ss              second
#define mp              make_pair

#define ON(n,i)         (n|(1<<i))
#define OFF(n,i)        (n&(~(1<<i)))
#define CHK(n,i)        (n&(1<<i))

#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)

#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())

#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )

#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("out.txt","w",stdout)

/// DEBUG
#define deb             printf("OKA\n")
/// DEBUG ENDS

using namespace std;

string s;
stack < char > st;

LL F(char c){
    if(c=='R') return  1;
    else return -1;
}


int main(){

    cin>>s;
    LL ans = 0;

    LL p = 0;
    LL i = 0;
    while( i<s.size() ){



        LL j = i;


        vector < LL > lol;
        lol.pb(0LL);

        do{
            p = p + F(s[j]);
            p = (p+4)%4;
            lol.pb(p);
            j++;
            //cout<<p<<endl;
        }while(p!=0 && j<s.size());

        bool yy = true;
        LL vis[4];
        RESET(vis);

        for( LL k = 1 ; k<lol.size() ; k++ ){

            LL x = lol[k];
            if(x==0 && lol[k-1] == 3) vis[x] = 1;

            else if( x!=0   ) {
                    if((vis[ (x-1+4)%4 ] || (x-1+4)%4 == 0))
                    vis[x] = 1;
                    else yy = false;
            }

          // cout<<lol[k]<<endl;
        }
        if(p==0 && yy){
            if(vis[0]&&vis[1]&&vis[2]&&vis[3]) ans++;
        }
        i = j;
      // cout<<"#"<<ans<<endl;


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



Measured memory_bytes: 3224
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <cstdio>
#include<algorithm>
#include <utility>
#define SIZE 1001;
using namespace std;
int main() {
	long long count=0, x, y;
	while (1) {
		cin >> x >> y;
		if (x == 0 && y == 0) {
			break;
		}
		if (y > x) {
			swap(x, y);
		}
		while (1) {
			if (y == 0) {
				break;
			}
			count++;
			x %= y;
			swap(x, y);
		}
		cout << x <<" "<<count<<  endl;
		count = 0;
	}
	return 0;
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
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 int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x)
    {
        return -par[root(x)];
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf(n);
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.merge(x, y);
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += (uf.issame(i, p[i]) ? 1 : 0);
    }
    cout << ans << endl;
}

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

void solve_142();


int N; // 生徒数
int *order_arrival; // 到着順を記録

void solve_142() // 入力時に到着順に保存されているので順に表示するだけ
{
  int i;
  for (i = 1; i <= N; ++i){
    if (i != 1) printf(" ");
    printf("%d", order_arrival[i]);
  }
  puts("");
}

int main()
{
  int i, inNum;
  scanf("%d", &N);

  order_arrival = (int *)malloc(sizeof(int) * (N + 1));
  for (i = 1; i <= N; ++i){
    scanf("%d", &inNum);
    order_arrival[inNum] = i;
  }

  // order_arrival[0] = -1;
	solve_142();

  free(order_arrival);
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
  int n,k;
  cin >> n >> k;
  vector<int> x(n);
  vector<int> kata(n);
  int sumOfKata = 0;
  for(int i = 0; i<n; i++){
    cin >> x.at(i);
  }
  for(int i = 0; i<n; i++){
    if(x.at(i)<k-x.at(i) && k-x.at(i)>0){//kがxより大きいかつAの方が近い
      kata.at(i) = x.at(i);
    }else if(x.at(i)-k>0 && x.at(i)<x.at(i)-k){//kがxより小さいかつAのほうが近い
      kata.at(i) = x.at(i);
    }else if(k-x.at(i)>0 && x.at(i)>k-x.at(i)){//kがxより大きいときかつkのほうが近い
      kata.at(i) = k-x.at(i);
    }else if(x.at(i)-k>0 && x.at(i)>x.at(i)-k){//kがxより小さい時かつkのほうが近い
      kata.at(i) = x.at(i)-k;
    }else{
      kata.at(i) = x.at(i);
    }
  }//片道の配列完了
  for(int i = 0; i<n; i++){
    sumOfKata += kata.at(i);
  }
  cout << sumOfKata*2 << endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		int N = sc.nextInt();
		long con = 0;

		for (int i = 0; i < N; i++) {
			con += sc.nextInt();
		}

		if (con >= H) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 58416