akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << std::endl; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << val << ' ';
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val << ' ';
        return {};
    }
};

int main()
{
    input in;
    output out;

    int N = in.read<int>();
    std::vector<int> v(N);
    in.read(v.begin(), N);
    std::sort(v.begin(), v.end());

    double t = v[0];
    for (int i : boost_irange(1, N)) {
        t = (t + v[i]) / 2;
    }
    out << t;

    return 0;
}


Measured memory_bytes: 256
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

a, b = na()

if a <= b:
    for i in range(b):
        print(a, end='')
else:
    for i in range(a):
        print(b, end='')

print()

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

int h,w;
char grid[1001][1001];
int memo[1001][1001];

int ways(int r, int c) {
    if (r>h||r<1||c>w||c<1||grid[r][c]!='.') return 0;
    if (r==h&&c==w) return 1;

    if (memo[r][c]!=-1) return memo[r][c];
    return memo[r][c] = (ways(r+1, c)%(1000000007) + ways(r, c+1)%(1000000007))%(1000000007);
}

int main() {
    cin>>h>>w;
    for (int i=1;i<=h;i++) for (int j=1;j<=w;j++) cin>>grid[i][j];
    for (int i=0;i<1001;i++) for (int j=0;j<1001;j++) memo[i][j] = -1;
    cout<<ways(1, 1);
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    int a=0,b;
    rep(i,k) a+=p[i];
    b=a;
    rep(i,n-k){
        b-=p[i];
        b+=p[i+k];
        a=max(a,b);
    }
    double ans=a+k;
    ans/=2;
    cout<<ketasuu(10)<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

struct Node
{
    ll i;
    ll s;

    Node(ll i, ll s) :
        i(i), s(s)
    {}

    bool operator<(const Node& right) const {
        return s < right.s;
    }
};

int main()
{
    ll N, C, K;
    cin >> N >> C >> K;

    vector<Node> T;
    for (int i = 0; i < N; i++) {
        ll Ti;
        cin >> Ti;

        T.emplace_back(i, Ti);
    }

    sort(begin(T), end(T));

    ll i = 0;
    ll ans = 0;
    while (i < N) {
        ll end = T[i].s + K;
        ++i;

        ll count = 1;
        while (i < N && T[i].s <= end && count < C) {
            ++i;
            ++count;
        }

        ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;
 
const int MAX_N = 1<<17;
 
int n, dat[2*MAX_N - 1];
 
void init(int nn) {
  n = 1;
  while(n < nn) n *= 2;
   
  for(int i=0; i<2*n-1; i++) dat[i] = INT_MAX;
}
 
void update(int k, int a) {
  k += n-1;
  dat[k] = a;
  while(k>0) {
    k = (k-1) / 2;
    dat[k] = min(dat[k*2+1], dat[k*2+2]);
  }
}
 
int query(int a, int b, int k, int l, int r) {
  if(r<=a||b<=l) return INT_MAX;
   
  if(a<=l&&r<=b) return dat[k];
  int vl = query(a, b, k*2+1, l, (l+r)/2);
  int vr = query(a, b, k*2+2, (l+r)/2, r);
   
  return min(vl, vr);
}
 
int main() {
   
  int nn, q;
  int c, x, y;
  cin >> nn >> q;
   
  init(nn);
   
  for(int i=0; i<q; i++) {
    cin >> c >> x >> y;
     
    if(c) {
      cout << query(x, y+1, 0, 0, n) << endl;
    }
    else {
      update(x, y);
    }
  }
   
  return 0;
}

Measured memory_bytes: 2184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int n,m;
        n=s.nextInt();
        int [] hrr = new int[n];
        m=s.nextInt();
        int [] arr = new int[m];
        int [] brr = new int[m];
        for( int i=0;i<n;i++)
            hrr[i]=s.nextInt();

        ArrayList<ArrayList<Integer>> adj = new ArrayList<ArrayList<Integer> >(n);
        for (int i = 0; i < n; i++)
            adj.add(new ArrayList<Integer>());

        for( int i=0;i<m;i++){
            arr[i]=s.nextInt();
            brr[i]=s.nextInt();
            addEdge(adj,arr[i]-1,brr[i]-1);
        }

        int goodObs=0;
        for (int i = 0; i < adj.size(); i++) {
            int flag=0;
            for (int j = 0; j < adj.get(i).size(); j++) {
                if(hrr[adj.get(i).get(j)]>=hrr[i]){
                    flag=1;
                    break;
                }
            }
            if(flag==0)
                goodObs+=1;
        }
        System.out.println(goodObs);
    }

    static void addEdge(ArrayList<ArrayList<Integer> > adj,
                        int u, int v)
    {
        adj.get(u).add(v);
        adj.get(v).add(u);
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 64144
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] lis = new int[n + 1];
        Arrays.fill(lis, Integer.MAX_VALUE);
        lis[0] = -1;
        int length = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            for (int j = length; j >= 0; j--) {
                if (lis[j] < x) {
                    lis[j + 1] = Math.min(lis[j + 1], x);
                    length = Math.max(length, j + 1);
                    break;
                }
            }
        }
        System.out.println(length);
    }
}


Measured memory_bytes: 71492
n = int(input())
l = list(map(int,input().split()))
res = []
s = sum(l)
ts = 0
for i,t in enumerate(l):
    if i %2==1:
        ts+=t
    # print(s,ts)
res.append(s - 2*ts)
for i in range(n-1):
    t = 2*l[i] - res[-1]
    res.append(t)
print(*res)


Measured memory_bytes: 14028
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

class UnionFind:
    def __init__(self, n):
        self.state = [-1] * n
        self.weight = [0] * n
        self.state0 = []
        self.weight0 = []

    def save(self):
        self.state0 = self.state[:]
        self.weight0 = self.weight[:]

    def restore(self):
        self.state = self.state0[:]
        self.weight = self.weight0[:]

    def root(self, u):
        v = self.state[u]
        if v < 0: return u
        self.state[u] = res = self.root(v)
        return res

    def merge(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if ru == rv: return
        du = self.state[ru]
        dv = self.state[rv]
        if du > dv: ru, rv = rv, ru
        if du == dv: self.state[ru] -= 1
        self.state[rv] = ru
        self.weight[ru] += self.weight[rv]
        return

    def get_weight(self, u):
        r = self.root(u)
        return self.weight[r]

def main():
    def dfs(u, w, ou=-1):
        for y, ku, i in to[u]:
            if ku == ou: continue
            if y > w: continue
            if use_edge[i]:continue
            use_edge[i] = True
            dfs(ku, w, u)

    to = defaultdict(list)
    n, m = map(int, input().split())
    xx = list(map(int, input().split()))
    uf = UnionFind(n)
    for i, x in enumerate(xx):
        uf.weight[i] = x
    edges = []
    for i in range(m):
        a, b, y = map(int, input().split())
        a, b = a - 1, b - 1
        edges.append([y, a, b, i])
        to[a].append([y, b, i])
        to[b].append([y, a, i])
    edges.sort()
    max_edge_candidate = []
    use_edge = [False] * m
    for y, a, b, i in edges:
        uf.merge(a, b)
        if y <= uf.get_weight(a):
            max_edge_candidate.append([y, a, b, i])
    while max_edge_candidate:
        y, a, b, i = max_edge_candidate.pop()
        if use_edge[i]: continue
        dfs(a, y)
    print(m-sum(use_edge))

main()


Measured memory_bytes: 188788
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  	ll A,B,V,W,T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;
   
   	ll D = abs(A - B);
  	ll D2 = (V - W) * T;
  	puts(D<=D2?"YES":"NO");
}

Measured memory_bytes: 3560
n, m = map(int, input().split())
denq = []
for _ in range(m):
    ks = tuple(map(lambda x: int(x)-1, input().split()))
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += (i>>s)&1
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)


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

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

  priority_queue<pair<int, int>> sushi;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    sushi.emplace(b, a);
  }

  vector<pair<int, int>> v(k);
  vector<int> type(n + 1);
  int64_t d = 0;

  for (int i = k - 1; i >= 0; i--) {
    auto p = sushi.top(); sushi.pop();
    d += p.first;
    type[p.second]++;
    v[i] = {p.first, p.second};
  }

  int64_t t = count_if(begin(type), end(type), [](auto a){return a > 0;});
  int64_t ans = d + t * t;

  for (int i = 0; i < k; i++) {
    auto p = v[i];
    if (type[p.second] == 1) continue;
    if (sushi.empty()) break;
    while (!sushi.empty()) {
      auto s = sushi.top(); sushi.pop();
      if (type[s.second] == 0) {
        type[s.second]++;
        t++;
        d -= p.first;
        d += s.first;
        ans = max(ans, d + t * t);
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2164
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;

	vector<long long> a(x), b(y), c(z);
	for (int i = 0; i < x; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < y; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < z; i++) {
		cin >> c[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end(), greater<long long>());


	vector<long long> ab;
	for(int i=0;i<x;i++)
		for (int j = 0; j < y; j++) {
			ab.push_back(a[i] + b[j]);
		}

	sort(ab.begin(), ab.end(), greater<long long>());

	// ab and c
	vector<long long> zenbu;
	for(int i=0;i<min(k, (int)ab.size());i++)
		for (int j = 0; j < min(k, (int)c.size()); j++) {
			zenbu.push_back(ab[i] + c[j]);
		}
	sort(zenbu.begin(), zenbu.end(), greater<long long>());
	for (int i = 0; i < k; i++) {
		cout << zenbu[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 43112
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<string> S(N);
  vector<int> ret(4,0);
  rep(i,N) cin >> S[i];
  for(auto s:S) {
    switch(s[0]) {
      case 'A':
        ++ret[0];
        break;
      case 'W':
        ++ret[1];
        break;
      case 'T':
        ++ret[2];
        break;
      case 'R':
      default:
        ++ret[3];
    }
  }
  cout << "AC x " << ret[0] <<endl;
  cout << "WA x " << ret[1] <<endl;
  cout << "TLE x " << ret[2] <<endl;
  cout << "RE x " << ret[3] <<endl;
}


Measured memory_bytes: 6256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    ll n, m; cin >> n >> m;

    if(n >= m){
        put(m/2);
    }else{
        ll ans = 0;
        ans = n;
        m -= n * 2;
        ans += m / 4;
        put(ans);
    }
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define SORT(x) sort((x).begin(),(x).end())
int main(void){
    
    int a, b, c, d;
    cin >>a >>b >>c >>d;
    
    if((max(a,c)-min(a,c))<=d){
        cout <<"Yes";
    }else if(((max(a,b)-min(a,b))<=d)&&((max(b,c)-min(b,c))<=d)){
        cout <<"Yes";
    }else{
        cout <<"No";
    }
    
    cout <<endl;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
a = [[0 for i in range(W+1)] for j in range(H+1)]
for y in range(H):
	tmp = list(map(int,input().split()))
	for x in range(W):
		a[y][x] = tmp[x]
		a[y][W]=a[y][x]+a[y][W]
		a[H][x]=a[H][x]+a[y][x]
		a[H][W]=a[H][W]+a[y][x]
for u in range(H+1):
	for i in range(W+1):
		print(a[u][i],end='')
		if	i<W:
			print(" ",end='')
	print()



Measured memory_bytes: 6748
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 233333;
int q,a,b,n;
int main() {
	read(q);
	while (q--) {
		read(a);read(b);if(a>b)swap(a,b); ll v=1LL*a*b-1; if (b<=1) {puts("0"); continue;}
		int res=a-1,l=2,r=b-2,c=b; if (a==b) {printf("%d\n",res*2); continue;}
		/*while (l<=r) {
			int mid=(l+r)>>1; //printf("--> %d %d %d\n",l,r,mid);
			if (v/mid==v/(mid-1)||v/mid==v/(mid+1)) {c=mid; r=mid-1;} else l=mid+1;
		}
	//	ll i=(v+1)/(c+1); res+=i-1+(v/i-v/(b-1)+1);
		printf("c= %d\n",c);
		res+=c-1+(c<b?(v/c-v/(b-1)+1):0);
		rep(i,2,b) //res+=i==1||v/i!=v/(i-1);
			if (v/i==v/(i-1)||v/i==v/(i+1)) {printf("i = %d\n",i); break;}
	//	res-=(max(0LL,min(v/a,b-1LL)-(v+1)/(a+1)+1)>0);
		res-=(v/(b-1))==a;*/
		ll i=sqrt(v); while (i*(i+1)<v) i++;
		res+=i-1+(v/i-v/(b-1)+1);
		res-=v/(b-1)==a;
		printf("%d\n",res);
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
const int INF=1e9;
typedef pair<int,int> P;
int main() {
  int h,w,cnt=0,dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
  cin >> h >> w;
  char maze[h][w]={};
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cin >> maze[i][j];
      if(maze[i][j]=='#') {
        cnt++;
      }
    }
  }
  int dist[h][w]={};
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      dist[i][j]=INF;
    }
  }
  queue<P> que;
  dist[0][0]=0;
  que.push(P(0,0));
  while(que.size()) {
    P p=que.front();
    que.pop();
    if(p.first==h-1&&p.second==w-1) {
      break;
    }
    for(int i=0; i<4; i++) {
      int nx=p.second+dx[i],ny=p.first+dy[i];
      if(nx>=0&&nx<w&&ny>=0&&ny<h&&maze[ny][nx]!='#'&&dist[ny][nx]==INF) {
        que.push(P(ny,nx));
        dist[ny][nx]=dist[p.first][p.second]+1;
      }
    }
  }
  if(dist[h-1][w-1]==INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << h*w-cnt-dist[h-1][w-1]-1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{ 
  int n[100];
  int i,a,b,count=0;

  scanf("%d",&a);
  
  for(i=0;i<a;i++){
    scanf("%d",&b);
    n[i]=b;
  }
  for(i=0;i<a;i++){
    if(n[i]%2==0){
      if(n[i]%3==0||n[i]%5==0){
      }
      else {
        count+=1;
      }
    }
  }
   if(count>0){
     printf("DENIED");
   }
  else {
    printf("APPROVED");
  }
  
  return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

int main() {
    int a, b;
    cin >> a >> b;
    int ans = max(a+b, a*b);
    ans = max(ans, a-b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let _: usize = iter.parse();
    let q_n: usize = iter.parse();
    let s_: String = iter.parse();
    let s = s_.chars().collect::<Vec<_>>();
    let qs: Vec<(usize, usize)> = (0..q_n)
        .map(|_| (iter.parse(), iter.parse()))
        .collect::<Vec<_>>();

    let mut v: Vec<u64> = s.windows(2)
        .scan(0, |st, w| {
            if w[0] == 'A' && w[1] == 'C' {
                *st += 1;
            }
            Some(*st)
        })
        .collect();
    v.insert(0, 0);

    let mut ans = Vec::new();
    for q in qs {
        let l = v[q.0 - 1];
        let r = v[q.1 - 1];
        ans.push(r - l);
    }
    println!(
        "{}",
        ans.into_iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join("\n")
    );
}

Measured memory_bytes: 13108
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


/////////////////////////////////////////////////////////////////////////////////////////

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

    int n,x,y;
    cin >> n >> x >> y;
    x--; y--;

    vector<vector<int>> g(n + 1);
    vector<int> ans(n);

    for (int i = 0;i < n - 1;i++){
        for (int j = i + 1;j < n;j++){
            int dist = min(abs(i - j),abs(x - i) + 1 + abs(y - j));

            ans[dist]++;
        }
    }
    for (int i = 1;i < n;i++){
        cout << ans[i] << endl;
    }

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  for (int i=0; i < N; i++){
    cin >> x[i] >> y[i] >> h[i];
  }

  int MAX = 100;
  
  for (int posX=0; posX <= MAX; posX++)
  {
    for (int posY=0; posY <= MAX; posY++)
    {
      int needH = -1;

      for (int i=0; i < N; i++)
      {
        if (h[i] > 0) {
          int tmp = h[i] + abs(posX - x[i]) + abs(posY - y[i]);

          if (needH == -1){
            needH = tmp;
          }
          else if (needH != tmp){
            needH = -2;
            break;
          }
        }
      }

      if(needH == -2) continue;

      for (int i=0; i < N; i++)
      {
        if (h[i] == 0){
          int dist = abs(posX - x[i]) + abs(posY - y[i]);
          if(needH > dist) {
            needH = -2;
            break;
          }
        }
      }

      if(needH == -2) continue;

      cout << posX << " " << posY << " " << needH << endl;
      return 0;
    }
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<algorithm>

int main() {
	std::string s;

	std::cin >> s;

	std::map<char, int> m;
	for (int i = 0; i < s.length(); i++) {
		m[s[i]]++;
	}

	for (auto i : m) {
		if (i.second % 2 == 1) {
			std::cout << "No" << std::endl;
			return 0;
		}
	}

	std::cout << "Yes" << std::endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> t(n+10);
  int ans = 0;
  rep(i,n){
    cin >> t[i];
    ans += t[i];
  }
  int m;
  cin >> m;
  vector<int> p(m+10);
  vector<int> x(m+10);
  rep(i,m) cin >> p[i] >> x[i];
  int count = 0;
  rep(i,m){
    count = ans - t[p[i]] + x[i];
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string.h>
#include <functional>
using namespace std;

typedef pair<int, int> P;

const int INF = 1e+9;
int N, d[101];
vector<P> G[101];

int dijkstra(int s, int t){
	fill(d, d + N + 1, INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0, s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		if(d[p.second] < p.first)
			continue;
		for(P e : G[p.second]){
			if(d[e.first] > d[p.second] + e.second){
				d[e.first] = d[p.second] + e.second;
				que.push(P(d[e.first], e.first));
			}
		}
	}
	return d[t];
}

int main() {
	int k, t;
	
	while(cin >> N >> k && (N || k)){
		for(int i = 0; i <= 100; ++i)
			G[i].clear();
			
		for(int i = 0; i < k; ++i){
			scanf("%d", &t);
			if(t == 1){
				int c, d, e;
				scanf("%d%d%d", &c, &d, &e);
				G[c].push_back(P(d, e));
				G[d].push_back(P(c, e));
			}
			else{
				int a, b;
				scanf("%d%d", &a, &b);
				int ans = dijkstra(a, b);
				if(ans == INF)
					cout << "-1" << endl;
				else
					cout << ans << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scn = new Scanner(System.in);
        String str=scn.nextLine();
        if (isPalindrome(str)&& is2Palindrome(str)&& is3Palindrome(str)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
    public static boolean isPalindrome(String str){
        for (int i = 0,j=str.length()-1; i <j; i++,j--) {
            if(str.charAt(i)!=str.charAt(j))return false;
        }
        return true;
    }
    public static boolean is2Palindrome(String str){
        for (int i = 0,j=(str.length()-1)/2-1; i <j; i++,j--) {
            if(str.charAt(i)!=str.charAt(j))return false;
        }
        return true;
    }
    public static boolean is3Palindrome(String str){
        for (int i = (str.length()+3)/2-1,j=str.length()-1; i <j; i++,j--) {
            if(str.charAt(i)!=str.charAt(j))return false;
        }
        return true;
    }

}


Measured memory_bytes: 23124
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static size_t a[500][500];
struct {
	size_t num;
	struct {
		size_t fromX;
		size_t fromY;
		size_t toX;
		size_t toY;
	} hist[250000];
} moveRecord;

int main(void) {
	size_t H, W;

	scanf("%zu %zu\n", &H, &W);
	for (size_t row = 0; row < H; row++) {
		for (size_t col = 0; col < W; col++) {
			scanf("%zu", &a[row][col]);
			if (col < W - 1) {
				scanf(" ");
			}
		}
		if (row < H - 1) {
			scanf("\n");
		}
	}

	moveRecord.num = 0;

	for (size_t row = 0; row < H; row++) {
		for (size_t col = 0; col < W; col++) {
			if (a[row][col] % 2 != 0) {
				if (col < W - 1) {
					a[row][col]--;
					a[row][col + 1]++;

					moveRecord.hist[moveRecord.num].fromX = row;
					moveRecord.hist[moveRecord.num].fromY = col;
					moveRecord.hist[moveRecord.num].toX = row;
					moveRecord.hist[moveRecord.num].toY = col+1;
					moveRecord.num++;
				}
				else if (row < H - 1) {
					a[row][col]--;
					a[row + 1][col]++;

					moveRecord.hist[moveRecord.num].fromX = row;
					moveRecord.hist[moveRecord.num].fromY = col;
					moveRecord.hist[moveRecord.num].toX = row + 1;
					moveRecord.hist[moveRecord.num].toY = col;
					moveRecord.num++;
				}
			}
		}
	}

	printf("%zu\n", moveRecord.num);
	for (size_t idx = 0; idx < moveRecord.num; idx++) {
		printf("%zu %zu %zu %zu\n", moveRecord.hist[idx].fromX + 1, moveRecord.hist[idx].fromY + 1, moveRecord.hist[idx].toX + 1, moveRecord.hist[idx].toY + 1);
	}

	return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define maxm 
#define maxn 

int main()
{
	int n, c[510], s[510], f[510];
	
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d%d%d", &c[i], &s[i], &f[i]);
		
	}
	for (int i = 1; i < n; i++) {
		long long loc = 0;
		for (int j = i; j < n; j++) {
			if (loc < s[j]) loc = s[j];
			if (loc % f[j]) {
				loc = (loc / f[j] + 1) * f[j];
			}
			loc += c[j];
		}
		printf("%lld\n", loc);
	}
	printf("%d\n", 0);
}



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

int a[200100],n,m;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;n*=2;
	for(int i=1;i<=n;++i)cin>>a[i];
	sort(a+1,a+n+1);
	int rL=n/2+1;
	for(int i=n;i>=rL;--i)
		while(rL<=n&&a[i]+a[rL*2-1-i]<m)++rL;
	int l=0,r=m-1;
	while(l<r){
		int mid=(l+r)/2;
		int le=n/2,rR=n;
		for(int i=1;i<=le;++i)
			while(le>=1&&a[i]+a[le*2+1-i]>mid)--le;
		for(int i=n;i>=rR;--i)
			while(rR>=n/2+1&&a[i]+a[rR*2-1-i]-m>mid)--rR;
		if((le<n/2&&rR<rL)||2*le<2*rL-2-n)l=mid+1;
		else r=mid;
	}
	cout<<l<<endl;
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vint cnt(N);
    for(int i=1; i<N; i++){
        if('A' == S[i-1] && 'C' == S[i]){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
    vint ans;
    REP(i,Q){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        ans.pb(cnt[b]-cnt[a]);
    }
    for(auto a:ans){
        cout << a << endl;
    }
}

Measured memory_bytes: 4484
n = int(input())

a = map(int,raw_input().split())
b = map(int,raw_input().split())

a_t = 0
b_t = 0

for i in range(n):
	if a[i] > b[i] :
		a_t += (a[i] - b[i])

	else:
		b_t += (b[i]-a[i])/2

print 'Yes' if a_t <= b_t else 'No'

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

int main()
{
	string str;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++)
	{
		if ('a' <= str[i] && str[i] <= 'z') str[i] += 'A' - 'a';
	}
	cout << str << endl;

	return 0;
}

Measured memory_bytes: 1172
using System;

public class a{
 static void Main(){
  var s = Console.ReadLine().Split();
  var t = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
  var u = Console.ReadLine();
  if(s[0]==u){
    t[0] -=1;
  }else{
     t[1] -= 1;
  }
   Console.WriteLine("{0} {1}",t[0],t[1]);
   
 }
}


Measured memory_bytes: 27508
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <set>
#include <map>
#include <random>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;
using VP = vector<P>;

int main() {
    long n;
    cin >> n;
    VI a, b;
    REP(i,n) {
        long p, q;
        cin >> p >> q;
        a.push_back(p);
        b.push_back(q);
    }
    
    long i = n - 1;
    long t;
    long cnt = 0;
    for (; i >= 0; i--) {
        if ((a[i] + cnt) % b[i] != 0) {
            t = (1 + (a[i] + cnt) / b[i]);
            cnt += b[i] * t - (a[i] + cnt);
        }
//        cout << cnt << endl;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 2036
#!/usr/bin/perl

$line = 0;
while (<>) {
    chomp;
    if ($line == 0) {
        $n = $_;
    } elsif ($line == 1) {
        $k = $_;
    } elsif ($line == 2) {
        $x = $_;
    } elsif ($line == 3) {
        $y = $_;
    }
    $line++;
}

foreach (1 .. $n) {
    if ($_ <= $k) {
        $total += $x;
    } else {
        $total += $y;
    }
}

print "$total\n";


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int n,m;
  cin>>n>>m;
  int i;
  int path[10][10]={};
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    path[a][b]++;
    path[b][a]++;
  }

  vi v;
  rep(i,n)v.push_back(i);

  int ans=0;
  do{
    if(v[0]!=0)continue;
    rep(i,n-1)
      if(path[v[i]][v[i+1]]==0)break;
    if(i==n-1)ans++;
  }while(next_permutation(all(v)));

  cout<<ans<<endl;
}


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

int main() {
    long long A, B, V, W, T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;

    long long diff_distance = abs(A - B);
    long long relative_speed = V - W;

    if (diff_distance <= relative_speed * T) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}

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

int main(void){
    long n;
    string s;
    cin >> n >> s;
    vector<long> v(n+2), e(n+2), w(n+2);
    for(long i=1; i<=n; i++){
        v[i] = s[i-1] == 'E' ? 1 : -1;
    }
    for(long i=1; i<=n; i++){
        w[i] = w[i-1] + (v[i-1] == -1 ? 1 : 0);
    }
    for(long i=n-1; i>=1; i--){
        e[i] += e[i+1] + (v[i+1] == 1 ? 1 : 0);
    }
    /*
    for(long i=0; i<=n+1; i++){
        cout << w[i] << " ";
    }
    cout << endl;
    for(long i=0; i<=n+1; i++){
        cout << e[i] << " ";
    }
    cout << endl;
    */
    long vmin = LONG_MAX;
    for(long i=1; i<=n; i++){
        vmin = min(vmin, e[i]+w[i]);
    }
    cout << vmin << endl;
    return 0;
}


Measured memory_bytes: 7684
#include <iostream>
#include <ios>
#include <set>
#include <cstdlib>
#include <cstdio>
using namespace std;
int main(void) {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for(int iter = 0; iter < n; iter++) {
        string t;
        cin >> t;

        int count = 0;
        set<string> visited;
        while(true) {
            visited.insert(t);
            const int L = t.length();
            if(L == 1) {
                break;
            }
            int m = 0;
            for(int i = 1; i < L; ++i) {
                int a = atoi(t.substr(0, i).c_str());
                int b = atoi(t.substr(i).c_str());
                m = max(m, a * b);
            }
            char buffer[1000];
            snprintf(buffer, 1000, "%d", m);
            t = string(buffer);
            if(visited.find(t) != visited.end()) {
                count = -1;
                break;
            }
            count += 1;
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 1272
n = int(input())
arare = input().split()
g = 0
w = 0
p = 0
y = 0
for i in arare:
  if i=='G':
    g+=1
  elif i=='W':
    w+=1
  elif i=='P':
    p+=1
  else:
    y+=1
if g>0 and w>0 and p>0 and y>0:
  print("Four")
else:
  print("Three")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
typedef std::pair<std::string,double> P;

int N; 
vector<int> v(N);
int b[100001];
void solve(){
    int cnt=0;
    for(int i=0; i<N; ++i) {
        int a; cin >> a;
        if(a>100000) cnt++;
        else b[a]++;
    }
    
    for(int i=0; i<100001; ++i){
        if(b[i]>i) cnt+=b[i]-i;
        else if(b[i]<i) cnt+=b[i];
    }
    cout << cnt << endl;
}
int main() {
    cin >> N;
    solve();
	return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
#define INF (ll)1e18

#define SIZE 2001
ll n, W; 
ll best_feasible = 0;
vector<P> ab;
vll v, w;

// [0, i)がb[0, i)のように確定していて、その後が不確定である時、線形緩和問題を解く
// 返り値(double, bool) = (緩和問題の最適解, その最適解が元問題の制約を厳密に満たすか)
pair<double, bool> solveRelaxationProblem(ll i, bitset<SIZE>& b) {
    double ans = 0;
    double w_now = W;
    rep(j, i) ans += b[j] * v[j], w_now -= b[j] * w[j];
    bool faf = 1;
    repi(j, i, n) {
        double tmp = min<double>(w_now, w[j]);
        faf &= (tmp == 0 || tmp == w[j]);
        w_now -= tmp;
        ans += tmp * (v[j] * 1.0 / w[j]);
    }
    return make_pair(ans, faf);

}

// [0, i)がb[0, i)のように確定していてその後が不確定である時、線形緩和問題を解く
// （負荷情報として、確定しているところの価値総和がv_now, 重さ総和w_nowを持っておく）
//
// 返り値double = 最適解
ll dfs(ll i, bitset<SIZE>& b, ll v_now, ll w_now) {
//    string s = b.to_string(); reverse(begin(s), end(s)); cout << s << endl;
    if (i == n) { best_feasible = max<ll>(best_feasible, v_now); return v_now; }

    auto relax_p = solveRelaxationProblem(i, b);
    double relax = relax_p.first; 
    double satisfiability = relax_p.second;

    if (satisfiability) { best_feasible = max<ll>(best_feasible, relax); return relax; } // 緩和問題の解を与える選び方が元問題の制約を満たしているので、それが最適でもある
    if (relax < best_feasible) { return -INF; } // 緩和問題の解が、今までの最善許容解に達さないので、探索しても無駄

    ll tmp = -INF;

    // 解がありそうな方を先に分岐するのが極めて重要！今回、0->1の順番で分岐するとTLEする。
    // 1を分岐
    if (w_now+w[i]<=W) {
        b[i] = 1;
        chmax(tmp, dfs(i+1, b, v_now+v[i], w_now+w[i]));
        b[i] = 0;
        chmax(best_feasible, tmp);
    }
    // 0を分岐
    chmax(tmp, dfs(i+1, b, v_now, w_now));
    chmax(best_feasible, tmp);

    return tmp;
}
int main(void) {
    cin >> n >> W;
    ab.resize(n); rep(i, n) cin >> ab[i].second >> ab[i].first;
    sort(ab.begin(), ab.end(), [&](P l, P r) { return l.first*r.second>r.first*l.second; });
    v = vll(n), w = vll(n);
    rep(i, n) {
        v[i] = ab[i].first;
        w[i] = ab[i].second;
    }

    ll w_now = W;
    rep(i, n) {
        if (w[i] <= w_now) {
            w_now -= w[i];
            best_feasible += v[i];
        }
    }
    
    bitset<SIZE> b;
    cout << dfs(0, b, 0, 0) << endl;;

    return 0;
}


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

int main(){
  int N;
  cin >>N;
  string S,T;
  cin >>S>>T;
  
  vector<char> U(2*N,'.');
  
  for (int i=0;i<N*2;i++){
    if (i%2 == 0) U[i] = S[i/2];
    else U[i] = T[i/2];
  }
  
  for (int i=0;i<2*N;i++) cout << U[i];
  cout << endl;
}

Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

h = ((M * 0.5) + H * 30)
m = M * 6

if h == 0:
  h = 360
if m == 0:
  m = 360

c = h - m
if c < 0:
  c = c * -1

#print(c)
sin_d = math.cos(math.radians(c))
#print(sin_d)

line = (A ** 2) + (B ** 2) - (2 * A * B * sin_d)
print(math.sqrt(line))


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

int main()
{
  int n,k,q,x;
  cin>>n>>k>>q;
  int arr[n+2]={0};
  for(int i=0;i<q;i++){cin>>x;arr[x-1]++;}

  int temp=q-k;

  for(int i=0;i<n;i++)
  {
      if(arr[i]>temp)cout<<"Yes"<<endl;
      else cout <<"No"<<endl;
  }

}




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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    int ans(0);
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'L') {
            if (i && s[i - 1] == 'L')
                ++ans;
        }
        else {
            if (n - i - 1 && s[i + 1] == 'R')
                ++ans;
        }
    }
    cout << min(ans + 2 * k, n - 1);
    return 0;
}


Measured memory_bytes: 512
use std::io::Read;
use std::collections::HashSet;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: HashSet<usize> = (0..4).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    return if s.contains(&1) && s.contains(&9) && s.contains(&7) && s.contains(&4) {
        "YES".to_string()
    } else {
        "NO".to_string()
    }
}


Measured memory_bytes: 2160
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;

public class Test_152_c
{

        /// <summary>
        /// https://atcoder.jp/contests/abc152/tasks/abc152_c
        /// </summary>
        public static void Main()
        {

            var N = Int32.Parse(Console.ReadLine());

            int[] P = new int[N];
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for(int i=0;i<N;i++)
            {
                P[i] = int.Parse(ss[i]);
            }

            int minP = int.MaxValue;
            int ans = 0;
            for(int i=0;i<N;i++)
            {
                if (minP > P[i])
                {
                    minP = P[i];
                }

                if (minP >= P[i])
                {
                    ans++;
                }
            }

            Console.WriteLine(ans.ToString());
        }
}


Measured memory_bytes: 33116
#include <cstdio>
using namespace std;

int main() 
{
	int v;
	for (int i = 0; i < 5; ++i) {
		scanf("%d", &v);
		if (!v) {
			printf("%d\n", i + 1);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 1736
def fact(k):
    val = 1
    for i in range(2, k+1):
        val = val*i
    return val

n, m = map(int, input().split())
if n < 2:
    even_comb = 0
else:
    even_comb = fact(n) / (fact(2) * fact(n-2))
if m < 2:
    odd_comb = 0
else:
    odd_comb = fact(m) / (fact(2) * fact(m-2))
print(int(even_comb + odd_comb))

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    vector<ll> S;
    ll cnt = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        ll s; cin >> s;
        S.pb(s);
        cnt += s;
    }
    asort(S);
    if(cnt % 10 == 0){
        for (int i = 0; i < N; i++) {
            if(S[i] % 10 != 0){
                cout << cnt-S[i] << endl;
                exit(0);
            }
        }
        cout << "0" << endl;
    } else {
        cout << cnt << endl;
    }
}

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

const int N = 2e5+15;

int ret[N];
void solve() {
    int n;
    scanf("%d",&n);
    vector<pair<pair<string,int>,int> > in;
    for(int i=0;i<n;++i) {
        string s;
        int p;
        cin>>s>>p;
        in.push_back(make_pair(make_pair(s,-p),i+1));
    }
    sort(in.begin(),in.end());
    for(int i=0;i<in.size();++i) {
        printf("%d\n", in[i].second);
    }
}
int main() {
   ///freopen("input.txt","r",stdin);
   solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
#define PP 1000000007
using namespace std;

ll N, K, M = 0, Ans = 0;
string S;

int main(){
cin >> N >> K >> S;

if(N == 1){cout << 0;exit(0);}

rep(i, 0, N - 1){

  if(S[i] == 'R' && S[i + 1] == 'L')M++;

}

bool A = S[0] != S.back(), B = S[0] == 'R';

Ans = N - 2*M;

if(A && B){

  if(K < M)cout << Ans + 2*K;
  
  else cout << N - 1;
  
  exit(0);

}

if(A && !B){

  if(K <= M)cout << Ans - 2 + 2*K;

  else cout << N - 1;
  
  exit(0);

}

if(!A){

  if(K <= M)cout << Ans - 1 + 2*K;

  else cout << N - 1;
  
  exit(0);

}

}

Measured memory_bytes: 3768
#include<stdio.h>

struct record{
        char suit;
        int value;
} ;

void print(struct record a[], int n)
{
    int i;

    for (i = 0; i < n; i++){
        if (i != 0)
            printf(" ");
        printf("%c%d", a[i].suit, a[i].value);
    }
    printf("\n");
}

void bubble_sort(struct record a[], int n)
{
    int i, j;
    struct record tmp;

    for (i = 0; i < n - 1; i++){
        for (j = n - 1; j > i ; j--)
            if (a[j].value < a[j - 1].value){
                tmp = a[j];  a[j] = a[j - 1];  a[j - 1] = tmp;
            }
        
    }
    
}

void inser_sort(struct record a[], int n)
{
    int i, j, min;
    struct record tmp;
    
    for(i = 0; i < n - 1; i++){
        min = i;
        for (j = i + 1; j < n; j++){
            if (a[min].value > a[j].value)
                min = j;
        }
        tmp = a[min]; a[min] = a[i]; a[i] = tmp;
    }
    
}

int judge(struct record a[], struct record b[], int n)
{
    int i;
    for (i = 0; i < n; i++){
        if(a[i].suit != b[i].suit)
            return 0;
    }
    return 1;
}
    

int main()
{
    int n, i, j;
    char c;
    
    struct record a[100], b[100];
    scanf("%d", &n);

    for (i = 0; i < n; i++){
        scanf(" %c", &a[i].suit);
        scanf("%d", &a[i].value);
        
    }
    

    for (i = 0; i < n; i++){
        b[i] = a[i];
    }

    bubble_sort(b, n);
    print(b, n);
    printf("Stable\n");
    inser_sort(a, n);
    print(a ,n);

    switch (judge(a, b, n)){
        case 0 : printf("Not stable\n"); break;
        case 1 : printf("Stable\n"); break;
        default : {
            printf("予期せぬエラーが発生しました\n");
            
        };

    
    }
    return 0;
    
}


Measured memory_bytes: 2764
N = int(input())
b = list(map(int, input().split()))

ans = [None] * N

for i in range(N):
    for j in range(len(b), -1, -1):
        if b[j-1] == j:
            ans[i] = b.pop(j-1)
            break
    else: break

if not b: 
    for a in ans[::-1]: print(a)
else: print(-1)

Measured memory_bytes: 3064