akhauriyash/Code-Regression huggingface dataset:
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

int T,n,m,i,j,k,x,y,z;
int a[N],b[N];
char c[N];

struct Data{
	int x,y;
}d[N];

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}
IL bool cmp(const Data a,const Data b){return a.x<b.x;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	scanf("%s",&c);
	x=0;	y=0;
	int ans=0;
	for (i=0;i<3;i++){
		if (!x && c[i]=='R'){
			x=1;	y=1;
		}	else if (x && c[i]=='R'){
			y++;
		}	else ans=Max(ans,y),y=0;
	}
	cout<<Max(ans,y)<<endl;
	return 0;
}

Measured memory_bytes: 3768
A,B=gets.split.map &:to_i
g=->(a,i){[0,a-(flr=(a+1)/(t=2**(i+1))*t-1)-t/2].max+(flr+1)/2}
p [*1..50].inject((g[B,0]-g[A-1,0])[0]){|s,i|s+(g[B,i]-g[A-1,i])[0]*(2**i)}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
     
#define int long long 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb emplace_back
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<typename T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<typename T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T> bool Min(T a, T b) { return a > b ? b : a; }
template<typename T> bool Max(T a, T b) { return a < b ? b : a; }
template<typename T> void de(T a ){
#ifdef LOCAL
	cout<<a<<" ";
#endif
}
const int INF = 2e5+1;


void solve(){
	int n,m;
	cin>>n>>m;
	priority_queue<int>pq;
	int a;
	forn(i,n){
		cin>>a;
		pq.push(a);
	}
	forn(i,m){
		a = pq.top();
		pq.pop();
		a = a/2;
		if(a) pq.push(a);
		if(pq.empty()) break;
	}
	int ans =0;
	while(!pq.empty()){
		a = pq.top();
		ans+=a;
		pq.pop();
	}
	cout<<ans<<endl;
}
 
int32_t main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    	cout.precision(10);
    	cout << fixed;
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt","w",stdout);
#endif
        int q=1;
#ifdef LOCAL 
        cin>>q;
#endif
        while(q--){
            solve();
        }
               
#ifdef LOCAL
    cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif
 
	return 0;
}	
 


Measured memory_bytes: 1400
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int n,a;
int x[50];

ll dp[55][55][50*50+1];

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>a;
	rep(i,n)cin>>x[i];
	memset(dp,0,sizeof(dp));
	dp[0][0][0]=1;
	rep(i,n)rep(k,n)rep(s,50*50){
		if(dp[i][k][s]==0)continue;
		dp[i+1][k+1][s+x[i]]+=dp[i][k][s];
		dp[i+1][k][s]+=dp[i][k][s];
	}
	ll res=0;
	repl(k,1,n+1) res+=dp[n][k][k*a];
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 59520
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> s(n);
    int res=0,index=0;
    rep(i,n){
        int a; cin>>a;
        s[i] = a;
        res += a;
    }
    sort(s.begin(),s.end());
    rep(i,n){
        if(res%10!=0){
            cout<<res<<endl;
            return 0;
        }
        if(s[index]%10==0)index++;
        else res -= s[index++];
    }
    cout<<0<<endl;
}

Measured memory_bytes: 256
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1 << 29;
const int maxn=1e5+5;

int n;
int a[maxn];

int cmp(int a,int b){return a>b;}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1,cmp);
	
	int t=1,sym;
	for(;t<=n;t++){
		if(a[t+1]<t+1){break;}
	}
	if((a[t]-t)%2==1){
		puts("First");
		return 0;
	}
	sym=0;
	for(int j=t+1;j<=n;j++){
		if(a[j]==t)sym^=1;
		else break;
	}
	if(sym)puts("First");
	else puts("Second");

	return 0;
}


Measured memory_bytes: 640
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e6 + 10, mod = 1e9 + 7;

ll fact[N], dp[N], add[N];

ll pwr(ll x, ll e);

int main() {
	fast_cin();
	ll n, h, d;
	cin >> n >> h >> d;
	fact[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fact[i] = (i * fact[i - 1]) % mod;
	}
	ll fact_sum = 0;
	for (int i = 1; i <= n; ++i) {
		fact_sum += fact[i];
		fact_sum %= mod;
	}
	dp[0] = fact[n];
	ll cur = 0;
	for (int i = 0; i <= h; ++i) {
		cur += add[i];
		cur %= mod;
		dp[i] += cur;
		dp[i] %= mod;
		ll temp = (fact_sum * dp[i]) % mod;
		int l = i + 1, r = min(i + d, h);
		add[l] += temp;
		add[l] %= mod;
		add[r + 1] += (mod - temp);
		add[r + 1] %= mod;
	}
	ll inverse = pwr(fact_sum, mod - 2);
	ll ans = (dp[h] * inverse) % mod;
	cout << ans << endl;
}

ll pwr(ll x, ll e) {
	ll res = 1;
	while (e) {
		if (e & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		e /= 2;
	}
	return res;
}

Measured memory_bytes: 23680
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)

using namespace std;

int main(){
    // x = (A*x+B) mod C
    int N,A,B,C,X;
    while(cin >> N >> A >> B >> C >> X,N){
        int Y[100];
        int cnt = 0;
        REP(i,N){
            cin >> Y[i];
        }
        int i = 0;
        while(1){
            if(cnt > 10000){
                cout << -1 << endl;
                break;
            }else{
                if(X == Y[i]){
                    if(i == N - 1){
                        cout << cnt << endl;
                        break;
                    }
                    i++;
                }
                cnt++;
                X = (A*X+B)%C;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1160
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

# 区間スケジューリング

N = int(readline())
m = map(int,read().split())
XL = zip(m,m)

LR = [(x-l,x+l) for x,l in XL]
LR.sort(key = itemgetter(1))

INF = 10 ** 18
prev_R = -INF
cnt = 0
for L,R in LR:
    if prev_R > L:
        continue
    cnt += 1
    prev_R = R

print(cnt)


Measured memory_bytes: 27568
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int[] aa = new int[n * 2]; int m = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int x = a + i, y = i - a;
			aa[m++] = x << 1;
			if (y > 0)
				aa[m++] = y << 1 | 1;
		}
		Arrays.sort(aa, 0, m);
		long ans = 0;
		for (int i = 0, j, k; i < m; i = k) {
			int a = aa[i] >> 1;
			j = i;
			while (aa[j] == a << 1)
				j++;
			k = j;
			while (aa[k] == (a << 1 | 1))
				k++;
			ans += (long) (j - i) * (k - j);
		}
		println(ans);
	}
}


Measured memory_bytes: 62856
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main() {
	string a;
	

	cin >> a;
	int A = a[0];
	int B = a[1];
	int C = a[2];
	int D = a[3];

	if ((A == B && B == C) || (B == C && C == D)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

#define ll long long
#define endl "\n"
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define f first
#define s second
#define vecll vector<ll>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<ll,ll>>
#define mapllll map<ll,ll>
#define mapstrll map<string,ll>
#define mapllvecll map<ll,vecll>
#define setll set<ll>
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL); cout.tie(NULL);

using namespace std;

ll const N=1e5+5;
ll const inf=1e18+5;
ll const MOD=1e9+7;

ll t,n,m,x,y,z,w,k;

int main()
{
    fio

    map<ll,ll>mpp;
    for(ll i=1;i<=9;i++)
    {
        for(ll j=1;j<=9;j++)
        {
            mpp[i*j] = 1;
        }
    }

    cin>>x;
    if(mpp[x])    cout<<"Yes";
    else            cout<<"No";

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	string s;
	cin >> s;
	char k = s[0];
	for (int i = 0; i < 4; i++) {
		if (count(s.begin(), s.end(), s[i]) != 2) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

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

using namespace std;

int ans[27];
int a[27] ={0};

int main(){
	int n;
	string s;
  memset(ans,50,sizeof(ans));
	cin >> n;
	while(n--){
		cin >> s;
		memset(a,0,sizeof(a));
		for(int i = 0;i < s.size();i++){
			a[s[i]-'a']++;
		}
		for(int i = 0;i < 26;i++){
			ans[i] = min(ans[i],a[i]);
		}
	}
	for(int i = 0;i < 26;i++){
		while(ans[i]){
			cout << char(i+'a');
			ans[i]--;
		}
	}
	cout << "\n";
}


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

int main()
{
  int n;
  while(cin >> n, n){
    vector<int> s(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    sort(s.begin(), s.end());

    int sum = 0;
    int i;
    for(i = 1; i < n - 1; i++) sum += s[i];
    cout << sum / (i - 1) << endl;
  }

    return 0;

}



Measured memory_bytes: 3124
def main():
    import sys
    from itertools import chain
    while True:
        n, m = map(int, sys.stdin.readline().split())
        if n == m == 0:
            break

        A = list(chain.from_iterable(map(int, sys.stdin.readline().split()) for _ in range(m)))
        ans = 0
        for i in range(n):
            sm = sum(A[i::n])
            if ans < sm:
                ans = sm
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7736
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
S = [list(input().rstrip()) for _ in range(N)]

from collections import defaultdict
d = defaultdict(int)

for s in S:
    s.sort()
    d["".join(s)] += 1

ans = 0
for i in d.values():
    ans += i*(i-1)//2

print(ans)

Measured memory_bytes: 39428
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x,d=0,c=1;
  cin>>n>>x;
  int l[n];
  for(int i=0;i<n;i++)
    cin>>l[i];
  while(d+l[c-1]<=x && c<=n)
  {
    d=d+l[c-1];
    c++;
  }
  return cout<<c,0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int ans = 1;

map<char, int> inputs;

char eval(State &a) {
    char b, c;
    if (*a == '[') {
        a++;
        b = eval(a);
    }
    else {
        b = *a;
        a++;
    }
    a++;
    
    if (*a == '[') {
        a++;
        c = eval(a);
    }
    else {
        c = *a;
        a++;
    }
    a++;
    if (inputs[b] == 0 && inputs[c] == 0) {
        ans = 0;
    }
    if (inputs[b] == 0) {
        inputs[c]--;
        return c;
    }
    if (inputs[c] == 0) {
        inputs[b]--;
        return b;
    }
    ans = 0;
    return b;
}

void solve() {
    string s;
    cin >> s;
    char a;
    int b;
    while (cin >> a >> b) {
        inputs[a] = b;
    }
    State now = s.begin();
    now++;
    eval(now);
    for (auto i : inputs) {
        if (i.second != 0) ans = 0;
    }
    if (ans == 1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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; }
const long long INF = 1LL << 60;
int main()
{
    string s,t;
    cin >> s>>t;

    int slen=s.size();
    int tlen=t.size();
    vector<vector<int>> dp(slen+1,vector<int>(tlen+1,0));

    REP(i, slen){
        REP(j,tlen){
            if(s[i]==t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
            else {
                chmax(dp[i+1][j+1], dp[i][j+1]);
                chmax(dp[i+1][j+1], dp[i+1][j]);
            }
        }
    }

    string ans="";
    int x=tlen;
    int y=slen;
    while(x>0&&y>0){
        if(dp[y][x]==dp[y-1][x]) y--;
        else if(dp[y][x]==dp[y][x-1]) x--;
        else{
            x--;
            y--;
            ans.push_back(s[y]);
        }
    }
    reverse(ans.begin(), ans.end());
	cout << ans << endl;
    return 0;
}   

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

using i64 = int64_t;

constexpr i64 INF = 1e12;

i64 dist[22][102][102]={0};
i64 fare[22][102][102]={0};
i64 mini[102]={0};
i64 chart[22][500002]={0};

void init(){
    for(int i=0;i<=100;++i){
        mini[i] = INF;
        for(int j=0;j<=100;++j){
            for(int c=0;c<=20;++c){
                dist[c][i][j] = (i != j ? INF : 0);
                fare[c][i][j] = (i != j ? INF : 0);
            }
        }
    }
    for(int c=0;c<=20;++c){
        for(int i=0;i<=500000;++i){
            chart[c][i] = 0;
        }
    }
}

int main(){
    int N, M, C, S, G;
    while(cin >> N >> M >> C >> S >> G, N != 0){
        init();
        set<int> company[102];
        for(int i=0;i<M;++i){
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            dist[c][x][y] = min((i64)d, dist[c][x][y]);
            dist[c][y][x] = min((i64)d, dist[c][y][x]);
            company[x].insert(c);
            company[y].insert(c);
        }
        vector<int> p;
        for(int i=0;i<C;++i){
            int tmp;
            cin >> tmp;
            p.push_back(tmp);
        }
        for(int i=0;i<C;++i){
            vector<i64> sections;
            for(int j=0;j<p[i]-1;++j){
                int q;
                cin >> q;
                sections.push_back(q);
            }
            sections.push_back(INF);
            vector<int> r;
            for(int j=0;j<p[i];++j){
                int tmp;
                cin >> tmp;
                r.push_back(tmp);
            }
            int idx = 0;
            for(int d=1;d<=500000;++d){
                chart[i+1][d] = chart[i+1][d-1] + r[idx];
                if(sections[idx] == d)idx++;
            }
        }

        for(int c=1;c<=C;++c){
            for(int k=1;k<=N;++k)
                for(int i=1;i<=N;++i)
                    for(int j=1;j<=N;++j)
                        dist[c][i][j] = min(dist[c][i][j], dist[c][i][k]+dist[c][k][j]);
        }
        for(int c=1;c<=C;++c){
            for(int i=1;i<=N;++i){
                for(int j=1;j<=N;++j){
                    if(dist[c][i][j] >= INF)continue;
                    fare[c][i][j] = chart[c][dist[c][i][j]];
                }
            }
        }
        mini[S] = 0;
        priority_queue<pair<i64, int>> que;
        que.push(make_pair(0, S));
        bool flag = false;
        while(!que.empty()){
            auto curr = que.top(); que.pop();
            if(curr.second == G){
                cout << -curr.first << endl;
                flag = true;
                break;
            }
            for(auto c: company[curr.second]){
                for(int i=1;i<=N;++i){
                    if(fare[c][curr.second][i] >= INF)continue;
                    i64 cost = -curr.first + fare[c][curr.second][i];
                    if(mini[i] <= cost)continue;
                    mini[i] = cost;
                    que.push(make_pair(-cost, i));
                }
            }
        }
        if(!flag){
            cout << -1 << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 88788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(n) n.begin(),n.end()

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<char>a{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  rep(i,s.size()){
    rep(j,26){
      if(s.at(i) == a.at(j)){
        int b = (j+n)%26;
        cout << a.at(b);
        break;
      }
    }
  }
  
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
MOD=10**9+7
N=int(input())
x=list(map(int, input().split()))
y=[x[i+1]-x[i] for i in range(N-1)]
 
upp=1
for i in range(2, N):
  upp*=i
  upp%=MOD
  
N_1=N-1
b=[0]*(N_1)
b[0]=upp
tmp=upp
out=b[0]*y[0]%MOD
for i in range(1, N_1):
  a=tmp*pow(i+1, MOD-2, MOD)%MOD
  b[i]=(b[i-1]+a)%MOD
  out+=b[i]*y[i]%MOD
  out%=MOD
print(out)

Measured memory_bytes: 63128
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer c = sc.nextInt();
		
		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
			
		}

	}

}



Measured memory_bytes: 26308
use std::io::Read;
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.trim_right().split_whitespace();
    let v = iter.map(|x| x.parse().unwrap()).collect::<Vec<u32>>();
    let (a, b, c, x) = (v[0], v[1], v[2], v[3]);
 
    let mut count = 0;
    for i in 0..a + 1 {
        for j in 0..b + 1 {
            for k in 0..c + 1 {
                let value = 500 * i + 100 * j + 50 * k;
                if value == x {
                    count += 1;
                }
            }
        }
    }
    println!("{}", count);
}

Measured memory_bytes: 4352
//
// Created on 2020/04/26.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    string ans;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(true){
        c -= b;
        if(c <= 0){
            ans = "Yes";
            break;
        }
        a -= d;
        if(a <= 0){
            ans = "No";
            break;
        }
    }

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



Measured memory_bytes: 3620
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n,d;
    scanf("%d%d",&n,&d);
    d=d*2+1;
    int ans=n/d+(n%d!=0);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x) { return x << 1; }
inline int rc(int x) { return x << 1 | 1; }

int a[20];
int n;

void dfs(int step, int x) {
    if (step == n) {
        for (int i = 0; i < n; i++) {
            cout << char('a' + a[i]);
        }
        cout << endl;
        return;
    }
    for (int i = 0; i <= x + 1; i++) {
        a[step] = i;
        dfs(step + 1, max(x, i));
    }
}

int main(void) {
    cin >> n;
    a[0] = 0;
    dfs(1, 0);
    return 0;
}


Measured memory_bytes: 1536
using System;
using System.Linq;
using System.Collections.Generic;

namespace AOJ2
{
    class Program
    {
        static void Main()
        {
            var result = new List<string>();

            var convNum = int.Parse(Console.ReadLine());
            while (convNum != 0)
            {
                var convDic = Enumerable.Range(0, convNum)
                .Select(x => Console.ReadLine().Split(' '))
                .ToDictionary(x => x[0], x => x[1]);
                var stringNum = int.Parse(Console.ReadLine());
                result.Add(string.Join("", Enumerable.Range(0, stringNum)
                    .Select(x => Console.ReadLine())
                    .Select(x => convDic.ContainsKey(x) ? convDic[x] : x).ToArray()));
                convNum = int.Parse(Console.ReadLine());
            }

            result.ForEach(x => Console.WriteLine(x));
        }
    }
}

Measured memory_bytes: 9320
# -*- coding: utf-8 -*-
"""
Sum of 4 Integers II
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0096

"""
import sys
from sys import stdin
from collections import defaultdict
input = stdin.readline


def main(args):
    lut = defaultdict(int)
    for a in range(1001):
        for b in range(1001):
            lut[a+b] += 1

    for line in sys.stdin:
        n = int(line)
        ans = 0
        for i in range(n+1):
            ans += lut[i] * lut[n-i]
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



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

int isOdd(int n){
    return n % 2;
}


int main(){
    int a,b;
    cin >> a >> b;
    cout << (isOdd(a*b) ? "Odd" : "Even" ) << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    ll ans = 0;
    rep(i,1,n+1){
        ans+=max(i-k,0)*(n/i)+max(n%i-k+1,0);
    }
    if(k==0){ans-=n;}
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; }
// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }
// const ll sz = 2e6 + 5;
// vector<ll> fac(sz, 1);

// * ALways PASS arrays, strings etc to functions BY REFERENCE

int main() {
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    int t = 1;
    // cin >> t;
    
    while(t--) {
        ll x, k, d;
        cin >> x >> k >> d;
        x = abs(x);
        
        ll steps = x / d;
        if (k < steps) {
            x -= (k * d);
            cout << x << endl;
            return 0;
        }
        
        k -= steps;
        x -= (steps * d);
        
        if (k % 2 == 0)
            cout << x << endl;
        else
            cout << abs(x - d) << endl;
            
    }
    
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
using namespace std;
int main(){


    int n,t,a;
    cin>>n>>t>>a;
    double min = 10000;
    int ans=0;
    for(int i=0;i<n;i++){
        double y;
        cin>>y;
        y=abs((t-y*0.006)-a);
        if(y<min){
            min=y;
            ans=i+1;
        }
    }
    cout<<ans<<endl;
    




return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int sort_2(int a[], int w)
{
	int key = 0;
	for (int i = 0; i < w; i++) {
		int min = a[i]; int n = i;
		for (int j = i; j < w; j++)
		{
			if (a[j] < min)
			{
				min = a[j];
				n = j;
			}
		}
		if (n != i) {
			swap(a[i], a[n]);
			key++;
		}
	}
	return key;
}
int main(void) {
	int n;
	int a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int k = sort_2(a, n);
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << a[i];
	}
	cout << endl << k<<endl;
}


Measured memory_bytes: 3088
#include <iostream>

using namespace std;

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;

		int data[30][30];
		for(int i=0;i<30;i++){
			for(int j=0;j<30;j++){
				data[i][j]=0;
			}
		}
		for(int i=0;i<n;i++){
			int x,y;
			cin>>x>>y;
			data[x][y]=1;
		}
		int roboX=10,roboY=10;
		int m;
		int sum=0;
		cin>>m;
		for(int i=0;i<m;i++){
			char dir;
			int length;
			cin>>dir>>length;

			if(dir=='N'){
				for(int i=0;i<=length;i++){
					if(data[roboX][roboY+i]==1){
						sum++;
						data[roboX][roboY+i]=0;
					}
				}
				roboY+=length;
			}
			else if(dir=='S'){
				for(int i=0;i<=length;i++){
					if(data[roboX][roboY-i]==1){
						sum++;
						data[roboX][roboY-i]=0;
					}
				}
				roboY-=length;
			}
			else if(dir=='E'){
				for(int i=0;i<=length;i++){
					if(data[roboX+i][roboY]==1){
						sum++;
						data[roboX+i][roboY]=0;
					}
				}
				roboX+=length;
			}
			else if(dir=='W'){
				for(int i=0;i<=length;i++){
					if(data[roboX-i][roboY]==1){
						sum++;
						data[roboX-i][roboY]=0;
					}
				}
				roboX-=length;
			}
		}
		if(sum==n){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>

typedef long long ll;

#define debug(x) cout << #x << "=" << x << endl
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << " "
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

int main(){
    ll h,w;
    cin >>h >>w;

    vector<string> str(h);
    
    loop(i,h) cin >>str[i];

    ll ans = 0;

    ll di[4] = {-1, 0, 1, 0};
    ll dj[4] = {0, 1, 0, -1};
    
    loop(i,h){
        loop(j,w){
            if(str[i][j] == '#') continue;
            graph node(h, vector<ll>(w,inf));

            queue<P> q;

            auto update = [&](ll i, ll j, ll x){
                if(node[i][j] != inf) return;
                node[i][j] = x;
                q.push(P(i,j));
            };

            update(i,j,0);

            while(!q.empty()){
                P ij = q.front();
                q.pop();
                loop(k,4){
                    ll ii = ij.first + di[k];
                    ll jj = ij.second + dj[k];
                    if(ii < 0 || ii >= h || jj < 0 || jj >= w) continue;
                    if(str[ii][jj] == '#') continue;
                    
                    update(ii,jj,node[ij.first][ij.second]+1);
                };                
            }

            loop(si,h){
                loop(sj,w){
                    if(node[si][sj] == inf)continue;
                    ans = max(ans, node[si][sj]);
                }
            }
        }
    }
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <sstream>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

int n, k;
int w[100000];
int max_w;

inline bool check(ll p) {
    if (p < max_w) return false;

    int track = 0;
    ll sum = 0;
    rep(i, n) {
        if(sum + w[i] > p) {
            track ++;
            sum = w[i];
        } else {
            sum += w[i];
        }
        if (track >= k) return false;
    }
    
    return true;
}

int main() {
    cin >> n >> k;
    rep(i, n) cin >> w[i];
    ll sum = 0;
    rep(i, n) {
        sum += w[i];
        chmax(max_w, w[i]);
    }

    ll left = 0, right = sum;

    while(right - left > 0) {
        ll p = (left + right)/2;
        if (check(p)) right = p;
        else left = p+1;
    }
    cout << right << endl;
}


Measured memory_bytes: 3484
#include<stdio.h>
int main()
{
    int n, p[10], price = 0, halfprice, sum = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
        if(p[i] > price)
        {
            price = p[i];
        }
    }
    halfprice = price / 2;
    for(int i = 0; i < n; i++)
    {
        sum += p[i];
    }
    sum = sum - halfprice;
    printf("%d", sum);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(i=0;i<(n);i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main(){
  string s,t;
  int i,ans=0;
  cin >> s >> t;
  for(i=0;i<s.size();i++){
  if(s.at(i)==t.at(i)){
  ans++;
  }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3540
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
int main(){
  map<string,int> num;
  num["A"]=0; num["B"]=0; num["O"]=0; num["AB"]=0;
  int n; char b[3];
  while(scanf("%d,%2s",&n,b)+1){
    // if(n==0)break;
    num[b]++;
  }
  cout<<num["A"]<<endl<<num["B"]<<endl<<num["AB"]<<endl<<num["O"]<<endl;
}

Measured memory_bytes: 1228
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
namespace Solve
{
	const int MAXN=1005;
	const int dx[4]={0,0,1,-1};
	const int dy[4]={1,-1,0,0};
	int sx,sy,tx,ty,n,m;
	inline int Id(int x,int y)
	{
		return (x-1)*m+y;
	}
	inline int X(int id)
	{
		return (id-1)/m+1;
	}
	inline int Y(int id)
	{
		return (id-1)%m+1;
	}
	char brd[MAXN][MAXN];
	int stk[MAXN*MAXN],top;
	bool vis[MAXN*MAXN],ins[MAXN*MAXN];
	int q[MAXN*MAXN],front,rear;
	int t_stk[MAXN*MAXN],t_top;
	int BFS()
	{
		int jud=0;t_top=0;
		front=rear=0;
		while(top)
		{
			vis[stk[top]]=true;
			q[rear++]=stk[top--];
		}
		while(rear-front)
		{
			int i=q[front++];
			int x=X(i),y=Y(i);
			for(int k=0;k<4;k++)
			{
				int nx=x+dx[k];
				int ny=y+dy[k];
				if(nx<1 || nx>n) continue;
				if(ny<1 || ny>m) continue;
				int nid=Id(nx,ny);
				if(vis[nid]) continue;
				if(!ins[i] && brd[nx][ny]=='#')
				{
					t_stk[++t_top]=i;
					ins[i]=true;
				}
				else if(brd[nx][ny]=='.')
				{
					vis[nid]=true;
					q[rear++]=nid;
				}
			}
		}
		while(t_top)
		{
			int i=t_stk[t_top--];
			int x=X(i),y=Y(i);
			for(int nx=x-2;nx<=x+2;nx++)
			{
				if(nx<1 || nx>n) continue;
				for(int ny=y-2;ny<=y+2;ny++)
				{
					if(ny<1 || ny>m) continue;
					int nid=Id(nx,ny);
					if(vis[nid]) continue;
					if(brd[nx][ny]=='#') continue;
					stk[++top]=nid;
				}
			}
		}
		/*for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
				printf("%d",vis[Id(i,j)]);
			printf("\n");
		}
		printf("%d\n",vis[Id(tx,ty)]);
		printf("\n");*/
		if(vis[Id(tx,ty)]) return 1;
		if(!top) return -1;
		return 0;
	}
	void work()
	{
		while(scanf("%d%d",&n,&m)!=EOF)
		{
			memset(vis,false,sizeof(vis));
			memset(ins,false,sizeof(ins));
			scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
			for(int i=1;i<=n;i++)
				scanf("%s",brd[i]+1);
			int ans=0;top=0;
			stk[++top]=Id(sx,sy);
			while(true)
			{
				int jud=BFS();
				if(jud==0) ans++;
				else
				{
					if(jud==-1) ans=-1;
					break;
				}
			}
			printf("%d\n",ans);
		}
		return;
	}
}
int main()
{
	#ifdef LOCAL
	freopen("00test.in","r",stdin);
	freopen("00test.out","w",stdout);
	#endif
	Solve::work(); 
	return 0;
}

Measured memory_bytes: 6820
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

int H, W;

int table[501][501];

void input() {
	cin >> H >> W;
	for (int row = 1; row <= H; row++) {
		for (int col = 1; col <= W; col++) cin >> table[row][col];
	}
}

vector<int> V[4];

void move_coin(int y, int x, int ny, int nx) {
	table[y][x]--;
	table[ny][nx]++;
	V[0].push_back(y);
	V[1].push_back(x);
	V[2].push_back(ny);
	V[3].push_back(nx);
}

void solve() {
	int ans = 0;

	// まずは各行の端に押し付ける
	for (int row = 1; row <= H; row++) {
		for (int col = 1; col < W; col++) {
			if (table[row][col] % 2 == 1) {
				move_coin(row, col, row, col + 1);
				ans++;
			}
		}
	}

	// 次に端の列について、下に押し付けていく
	for (int row = 1; row < H; row++) {
		if (table[row][W] % 2 == 1) {
			move_coin(row, W, row + 1, W);
			ans++;
		}
	}

	cout << ans << endl;
	for (int i = 0; i < V[0].size(); i++) {
		cout << V[0][i] << " " << V[1][i] << " " << V[2][i] << " " << V[3][i] << endl;
	}
}

void print_table() {
	for (int row = 1; row <= H; row++) {
		for (int col = 1; col <= W; col++) printf("%d ", table[row][col]);
		printf("\n");
	}
}

int main() {
	input();

	/*
	cout << endl;
	print_table();
	*/

	solve();

	/*
	cout << endl;
	print_table();
	*/

	return 0;
}

Measured memory_bytes: 5220
/* long long or int & the MAX_INT or MIN_INT */
/* the size of a[] & inline */
/* xx 396 */

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

typedef long long ll;

const int MAX_N=2e3+10;

int sum[MAX_N],tot[MAX_N],N;
ll ans=0;

signed main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int x; scanf("%d",&x); sum[x]++;
	}
	for(int i=1;i<=2000;i++) tot[i]=tot[i-1]+sum[i];
	for(int a=1;a<=1000;a++) for(int b=a+1;b<=1000;b++) if(sum[a]&&sum[b]){
		int now=tot[a+b-1]-tot[b];
		if(now<=0) continue;
		ans+=ll(ll(sum[a])*ll(sum[b])*ll(now));
	}
	for(int a=1;a<=1000;a++) if(sum[a]>=2){
		int now=tot[a+a-1]; now-=sum[a];
		if(now<=0) continue;
		ans+=ll((ll(ll(sum[a])*ll(sum[a]-1))/2ll)*ll(now));
	}
	for(int a=1;a<=1000;a++) if(sum[a]>=3){
		ans+=ll(ll(ll(sum[a])*ll(sum[a]-1)*ll(sum[a]-2))/6ll);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 4e4+5;
int n, m;
vector<vector<int>> v;
int bfs(int src, int dst)
{
    int ans[n + 1][3];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j < 3; j++)
            ans[i][j] = 1e9;
    queue<pair<int, int>> q;
    q.push({src, 0});
    ans[src][0] = 0;
    while(!q.empty())
    {
        int node = q.front().F, md = q.front().S;
        q.pop();
        for (auto to : v[node])
        {
            int nxt_md = (md + 1) % 3;
            if (ans[to][nxt_md] == 1e9)
            {
                q.push({to, nxt_md});
                ans[to][nxt_md] = ans[node][md] + 1;
            }
        }
    }
    return (ans[dst][0] == 1e9 ? -1 : ans[dst][0] / 3);
}
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> m;
    v.resize(n + 1);
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        v[x].pb(y);
    }
    int s, t;
    cin >> s >> t;
    cout << bfs(s, t);
    return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#define int long long

using namespace std;

signed main()
{
  int n, ans = 0;
  cin >> n;
  if (n % 2 == 1)
  {
    cout << 0 << endl;
  }
  else
  {
    for (int i = 10; i <= n; i *= 5)
    {
      ans += n / i;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
      int n, k;
      cin >> n >> k;
      string s;
      cin >> s;
      int ans = 0;
      rep(i, n-1){
          if(s[i] == 'R' && s[i] == s[i+1]) ans++;
          if(s[n-1-i] == 'L' && s[n-1-i] == s[n-1-(i+1)]) ans++;
      }
    //   cout << ans << endl;
      rep(i, k){
          ans = min(n-1, ans+2);
      }
      cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main () {
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int k = 0;
    int l = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'a') {
            if (k < a+b) {
                k++;
                puts("Yes");
                continue;
            }
        }
        else if (s[i] == 'b') {
            if (k < a+b && l < b) {
                k++, l++;
                puts("Yes");
                continue;
            }
        }
        puts("No");
    }
}

Measured memory_bytes: 896
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int h,a;
  cin >> h >> a;
  
  int ans = 0;
  
  while(1){
    h -= a;
    ans++;
    if(h <= 0) break;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 3580
program prob2
    implicit none
    integer::N, i, ans, tmp
    integer, allocatable::h(:)
    read(*,*) N
    allocate(h(N))
    read(*,*) h
    ans = 0
    tmp = 0
    do i = 2, N
        if(h(i) <= h(i-1)) then
            tmp = tmp + 1
        else
            ans = max(ans, tmp)
            tmp = 0
        end if
    end do
    write(*,*) max(ans,tmp)
    stop
end program

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

int main(){
    long long H , level = 0;
    scanf( "%lld" , &H );

    while( H > 1 ){
        ++level;
        H >>= 1;
    }

    long long Ans = (1LL << (level + 1)) - 1;
    printf( "%lld\n" , Ans );
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool ok(pair<int, int> a){
    return a.first==a.second;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<int, int>> res(n);
    for (auto &i: res)
        cin >> i.first >> i.second;
    bool pos = false;
    for (int i=0; i<n-2; i++){
        if(ok(res[i])&& ok(res[i+1]) && ok(res[i+2]))
            pos = true;
    }
    cout << (pos?"Yes\n":"No\n");
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e7+1000;
typedef long long ll;
int cnt=0;
bool vis[maxn];
int pri[maxn];
int f[maxn];
int p[maxn];
ll sum[maxn];
void init(){
    for(int i=1;i<maxn;i++)f[i]=1;
    cnt=0;
    for(int i=2;i<maxn;i++){
        if(vis[i]==0){
            pri[++cnt]=i;
            f[i]=2;
        }
        for(int j=1;j<=cnt&&pri[j]*i<maxn;j++){
            vis[i*pri[j]]=1;
            if(i%pri[j]==0){
                f[i*pri[j]]=f[i]/2;
                break;
            }
            f[i*pri[j]]=f[i]*2;
        }
    }
    int k=0;
    for(int i=1;i<=cnt;i++){
        if(pri[i]*pri[i]*pri[i]>=maxn) break;
        p[++k]=pri[i]*pri[i]*pri[i];
    }
    for(int i=1;i<maxn;i++){
        for(int j=1;j<=k&&p[j]*i<maxn;j++){
            f[i*p[j]]=0;
            if(i%p[j]==0){
                break;
            }
        }
    }
    for(int i=1;i<maxn;i++){
        sum[i]=sum[i-1]+f[i];
    }
}
int main(){
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	ans=ans+(n/k)*(n/k)*(n/k);
	if(k%2){
	    cout<<ans<<endl;
	    return 0;
	}
	if(k%2==0){
        k=k/2;
        ll cnt=0;
        for(ll i=k;i<=n;i+=2*k){
            cnt++;
        }
        for(ll i=k;i<=n;i+=k){
            if(i%(2*k)==0) continue;
            ans+=cnt*cnt;
        }
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef complex<double> Point;
const double EPS = 1e-8;

struct Line : public vector<Point> {
    Line(const Point& a, const Point& b) {
        push_back(a); push_back(b);
    }
    Point vector() const {
        return back() - front();
    }
};
double cross(Point a, Point b){
    return imag(conj(a) * b);
}
double distanceLP(Line l, Point p){
    // return abs(p - projection(l, p));
    return abs(cross(l.vector(), p - l[0])) / abs(l.vector());
}

Point incenter(Point p1, Point p2, Point p3){
    double a = abs(p2 - p3);
    double b = abs(p3 - p1);
    double c = abs(p1 - p2);
    return (a * p1 + b * p2 + c * p3) / (a + b + c);
}

Point find_point(Point a, double r, Point p, Point c, Line l){
    double lb = 0, ub = 1;
    REP(iter, 100){
        double mid = (lb + ub) / 2;
        Point q = p * (1 - mid) + c * mid;
        double s = distanceLP(l, q);
        if(abs(a - q) < r + s){ // too near
            ub = mid;
        }else{ // come closer
            lb = mid;
        }
    }
    return p * (1 - lb) + c * lb;
}

int main(){
    while(true){
        Point tri[3];
        REP(i, 3){
            double x, y;
            cin >> x >> y;
            tri[i] = Point(x, y);
        }
        if(tri[0] == tri[1]) break;
        Point c = incenter(tri[0], tri[1], tri[2]);
        double lb = 0, ub = 1;
        REP(iter, 100){
            double mid = (lb + ub) / 2;
            Point p0 = (tri[0] * (1 - mid) + c * mid);
            double r0 = distanceLP(Line(tri[0], tri[1]), p0);
            //cout << "mid : " << mid << endl;
            //cout << "p0 : " << p0 << " r0 : " << r0 << endl;

            Line l(tri[1], tri[2]);
            Point p1 = find_point(p0, r0, tri[1], c, l);
            double r1 = distanceLP(l, p1);
            //cout << "p1 : " << p1 << " r1 : " << r1 << endl;
            Point p2 = find_point(p0, r0, tri[2], c, l);
            double r2 = distanceLP(l, p2);
            //cout << "p2 : " << p2 << " r2 : " << r2 << endl;
            if(abs(p1 - p2) < r1 + r2){ // come closer
                //cout << "lb update" << endl;
                lb = mid;
            }else{
                //cout << "ub update" << endl;
                ub = mid;
            }
        }

        Point p0 = (tri[0] * (1 - lb) + c * lb);
        double r0 = distanceLP(Line(tri[0], tri[1]), p0);
        Line l(tri[1], tri[2]);
        Point p1 = find_point(p0, r0, tri[1], c, l);
        double r1 = distanceLP(l, p1);
        Point p2 = find_point(p0, r0, tri[2], c, l);
        double r2 = distanceLP(l, p2);
        printf("%.6f %.6f %.6f\n", r0, r1, r2);
    }
    return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll CON(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return m*CON(m-1,n)/(m-n);
}
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll 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 main()
{
  ll n,a,x[100005],y[100005],g;
  cin >> n >> a;
  rep(i,n)cin >> x[i];
  x[n]=a;
  rep(i,n)y[i]=x[i+1]-x[i];
  rep(i,n)y[i]=abs(y[i]);
  g=y[0];
  rep(i,n)g=gcd(y[i],g);
  printf("%lld",g);
}

Measured memory_bytes: 1792