akhauriyash/Code-Regression huggingface dataset:
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, m, s, t) = i.read4::<usize, usize, usize, usize>();
    let mut la = vec![Vec::new(); n];
    let mut lb = vec![Vec::new(); n];
    for _ in 0..m {
        let (u, v, a, b) = i.read4::<usize, usize, usize, usize>();
        let (u, v) = (u - 1, v - 1);

        la[u].push((v, a));
        la[v].push((u, a));

        lb[u].push((v, b));
        lb[v].push((u, b));
    }
    let rs = solve(n, s - 1, t - 1, la, lb);
    for r in rs {
        writeln!(o, "{}", 1000000000000000 - r).unwrap();
    }
}
fn solve(
    n: usize,
    s: usize,
    t: usize,
    la: Vec<Vec<(usize, usize)>>,
    lb: Vec<Vec<(usize, usize)>>,
) -> Vec<usize> {
    let ca = get_costs(n, s, la);
    let cb = get_costs(n, t, lb);

    let mut rs = Vec::new();
    let mut r = usize::max_value();
    for i in (0..n).rev() {
        r = min(r, ca[i] + cb[i]);
        rs.push(r);
    }
    rs.reverse();
    rs
}
fn get_costs(n: usize, s: usize, l: Vec<Vec<(usize, usize)>>) -> Vec<usize> {
    let mut q = BinaryHeap::new();
    let mut cs = vec![usize::max_value(); n];
    cs[s] = 0;
    q.push((RevCmp(0), s));
    while let Some((RevCmp(c0), i0)) = q.pop() {
        if c0 != cs[i0] {
            continue;
        }
        for &(i1, c) in &l[i0] {
            let c1_new = c0 + c;
            let c1_old = cs[i1];
            if c1_new < c1_old {
                cs[i1] = c1_new;
                q.push((RevCmp(c1_new), i1));
            }
        }
    }
    cs
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        {$f:ident($($v:ident: $t:ident),*)} => {
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                $(
                    let $v = i.next().unwrap().parse().ok().unwrap();
                )*
                ($($v),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read4(v1: T1, v2: T2, v3: T3, v4: T4) }
    }

    // std::cmp::Reverseと同じ
    #[derive(PartialEq, Eq)]
    pub struct RevCmp<T>(pub T);

    impl<T: PartialOrd> PartialOrd for RevCmp<T> {
        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
            other.0.partial_cmp(&self.0)
        }
    }
    impl<T: Ord> Ord for RevCmp<T> {
        fn cmp(&self, other: &Self) -> Ordering {
            other.0.cmp(&self.0)
        }
    }

}


Measured memory_bytes: 28924
def main():
    N = int(input())
    A = list(map(int, input().split()))

    # avg = sum(A) // N
    avg = sum(A) / N
    avg = round(avg)

    # ans = 10 ** 10
    
    # for i in [avg, avg+1]:
    #     tmp = 0
    #     for ai in A:
    #         x = (i - ai) ** 2
    #         tmp += x
    #     ans = min(ans, tmp)
    ans = 0
    for ai in A:
        x = (avg - ai) ** 2
        ans += x

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include "stdio.h"

int main(){

    int A[100],N,i,j,k,minj,count=0;
        scanf("%d",&N);
    for(i=0;i<N;i++){
            scanf("%d",&A[i]);
        }
    
    for(i=0;i<N;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(A[j]<A[minj]){
            minj=j;
            }
        }
    if(i!=minj)
    count++;
    k=A[i];
    A[i]=A[minj];
    A[minj]=k;
    }
    for(i=0;i<N;i++){
        printf("%d",A[i]);
        if(i<N-1)
        printf(" ");
            }
    printf("\n%d\n",count);
    return 0;
        }



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 mod=1000000007;
const int INF=1001001001;


int main() {
  int x,t;
  cin>>x>>t;
  cout<<max(0,x-t)<<endl;
  return 0;  
}

Measured memory_bytes: 3572
S = input()
x, y = map(int, input().split())

T = S.split("T")
u, v = [len(T[0])], [0]
dp = [u, v]
for i in range(1, len(T)):
    s = set()
    k = len(T[i])
    if i % 2 != 0:
        Q = dp[1]
        for j in Q:
            s.add(j - k)
            s.add(j + k)
        dp = [dp[0], list(s)]
    else:
        Q = dp[0]
        for j in Q:
            s.add(j - k)
            s.add(j + k)
        dp = [list(s), dp[1]]
if x in dp[0] and y in dp[1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3752
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N, X = list(map(int, input().split()))
sum_ = X
prev = X
next = N - X
i = 0
while True:
    num = prev // next
    if i == 0:
        sum_ += 2 * num * next
    elif i % 2 == 1:
        sum_ += 2 * num * next - next
    else:
        sum_ += 2 * num * next - next
    mod_ = prev % next
    if mod_ == 0:
        break
    sum_ += next
    prev = next
    next = mod_
    i += 1
print(sum_)

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

string V,W;
int n;

string J(string S) {
	string T = "";
	T = S[S.size() - 1] + S.substr(0, S.size() - 1);
	return T;
}

string C(string S) {
	string T = "";
	T = S.substr(1, S.size() - 1) + S[0];
	return T;
}

string E(string S) {
	string T = "";
	T += S.substr(S.size() - (S.size() / 2), S.size() / 2);
	if (S.size() % 2 == 1) { T += S[S.size() / 2]; }
	T += S.substr(0, S.size() / 2);
	return T;
}

string A(string S) {
	string T = "";
	for (int k = S.size() - 1; k >= 0; k--) {
		T += S[k];
	}
	return T;
}

string P(string S) {
	string T = "";
	for (int k = 0; k < S.size(); k++) {
		if (isdigit(S[k])) {
			T += (S[k] - 1);
			if (T[k] < '0') {
				T[k] += 10;
			}
		}
		else {
			T += S[k];
		}
	}
	return T;
}

string M(string S) {
	string T = "";
	for (int k = 0; k < S.size(); k++) {
		if (isdigit(S[k])) {
			T += (S[k] + 1);
			if (T[k] > '9') {
				T[k] -= 10;
			}
		}
		else {
			T += S[k];
		}
	}
	return T;
}

string message(string S, string T) {
	for (int j = S.size() - 1; j >= 0; j--) {
		if (S[j] == 'J') {
			T = J(T);
		}
		if (S[j] == 'C') {
			T = C(T);
		}
		if (S[j] == 'E') {
			T = E(T);
		}
		if (S[j] == 'A') {
			T = A(T);
		}
		if (S[j] == 'P') {
			T = P(T);
		}
		if (S[j] == 'M') {
			T = M(T);
		}
	}
	return T;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> V >> W;
		cout << message(V, W) << endl;
	}
}

Measured memory_bytes: 3156
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll x[N], y[N];
  for(int i=0;i<N;++i) cin>>x[i]>>y[i];
  vector<ll> arr1(N), arr2(N);
  for(int i=0;i<N;++i) arr1[i] = x[i]+y[i];
  for(int i=0;i<N;++i) arr2[i] = x[i]-y[i];
  sort(arr1.begin(), arr1.end());
  sort(arr2.begin(), arr2.end());
  ll ans = 0;
  ans = arr1[N-1]-arr1[0];
  ans = max(ans, arr2[N-1]-arr2[0]);
  cout<<ans<<endl;
}



Measured memory_bytes: 9528
n=int(input())
a=list(map(int,input().split()))
ans=0
p=10**9 + 7 
l=[0]*60
for i in range(60):
    for j in a:
        l[i]+=(j>>i)&1
    ans=(ans + (2**i) * l[i] * (n-l[i]))%p
print(ans) 

Measured memory_bytes: 122808
N_INPUTS, @bottles = gets.chomp.split(' ').map &:to_i

arr = (0...N_INPUTS).map do |n|
  gets.chomp.split(' ').map &:to_i
end.sort do |l, r|
  l[0] <=> r[0]
end

@result = 0
arr.each do |pair|
  # p pair
  price, zaiko = pair
  if zaiko > @bottles
    @result += price*@bottles
    @bottles = 0
  else
    @result += zaiko*price
    @bottles -= zaiko
  end
end

puts @result


Measured memory_bytes: 11128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var K = sc.nextInt();
        var Q = sc.nextInt();
        var A = sc.ArrayInt(Q);

        var p = new int[N];
        for (int i = 0; i < N; i++) {
            p[i] = K - Q;
        }
        for (int i = 0; i < Q; i++) {
            p[A[i] - 1]++;
        }
        for (int i = 0; i < N; i++) {
            if (p[i] > 0) {
                WriteLine("Yes");
            } else {
                WriteLine("No");
            }
        }
    }
    
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 18004
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let a: u64 = iter.next().unwrap().parse::<u64>().unwrap();
    let b: u64 = iter.next().unwrap().parse::<u64>().unwrap();
    let k: usize = iter.next().unwrap().parse::<usize>().unwrap();
    
    let g = gcd(a, b);
    let mut divs = divisors(g);
    divs.sort();
    divs.reverse();
    println!("{}", divs[k-1]);
}

#[allow(dead_code)]
pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[doc = " n>=1"]
#[allow(dead_code)]
fn divisors(n: u64) -> Vec<u64> {
    let mut ret = vec![];
    {
        let mut i = 1;
        while i * i <= n {
            if n % i == 0 {
                ret.push(i);
                if i != n / i {
                    ret.push(n / i);
                }
            }
            i += 1;
        }
    }
    ret
}


Measured memory_bytes: 4352
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let n_k = lines.next().unwrap().unwrap();
    let mut n_k = n_k.split_whitespace();
    let n: usize = n_k.next().unwrap().parse().unwrap();
    let k: usize = n_k.next().unwrap().parse().unwrap();
    let p: Vec<i32> = lines
        .next()
        .unwrap()
        .unwrap()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();

    let mut sum: i32 = (0..k).map(|i| p[i]).sum();
    let mut max_sum = sum;
    for i in 0..n {
        if i + k >= n {
            break;
        }
        sum = sum - p[i] + p[i + k];
        max_sum = std::cmp::max(max_sum, sum);
    }
    let ans = (max_sum + k as i32) as f64 / 2.0;

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


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

int main() {
  int a, b;
  cin >> a >> b;
  if((a+b) % 2 != 0) cout << "IMPOSSIBLE" << endl;
  else cout << (a+b)/2 << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 100050;
int N;
int S[MAX_N];

std::unordered_map<int, long long> dp[MAX_N];
long long NEG_INF = -(long long)100000000000000;

long long func(int sub, int k) {
    int A = N - 1 - k * sub;
    if (A <= 1) {
        return NEG_INF;
    }
    if (A - sub <= 0) {
        return NEG_INF;
    }
    if (A % sub == 0 && A*2 <= N - 1) {
        return NEG_INF;
    }

    if (k == 0) {
        return 0;
    }

    if (dp[sub].find(k) != dp[sub].end()) {
        return dp[sub][k];
    }

    long long ret;
    if (k*sub != N-1-k*sub) {
        ret = func(sub, k - 1) + S[k*sub] + S[N-1-k*sub];
    } else {
        ret = NEG_INF;
    }

    //long long ret = func(sub, k - 1) + S[k*sub] + S[N-1-k*sub];

    dp[sub][k] = ret;
    return ret;
}

int score[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 0; i <= N - 1; i++) {
        std::cin >> S[i];
    }

    long long ret = 0;
    for (int sub = 1; sub <= N; sub++) {
        for (int k = 0; k*sub < N - 1; k++) {
            ret = std::max(ret, func(sub, k));
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 49420
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n;
  char c[5] = {'M', 'A', 'R', 'C', 'H'};
  cin >> n;
  vector<string> s(n);
  vector<ll> march(5);
  for(int i = 0; i < n; i++) {
    cin >> s.at(i);
    for(int j = 0; j < 5; j++)
      if(s.at(i).at(0) == c[j])
        march.at(j)++;
  }
  ll o = 0;
  for(int i = 0; i < 3; i++)
    for(int j = i + 1; j < 4; j++)
      for(int k = j + 1; k < 5; k++)
        o += march.at(i) * march.at(j) * march.at(k);
  cout << o << endl;
}

Measured memory_bytes: 6144
s = input()

t = s.replace("dreameraser","1")
t = t.replace("dreamerase","2")
t = t.replace("dreamer","3")
t = t.replace("eraser","4")
t = t.replace("dream","5")
t = t.replace("erase","6")

try:
    int(t)
    print("YES")
except :
    print("NO")

Measured memory_bytes: 3316
from itertools import*
n,a,b,c,*l=map(int,open(0).read().split())
ans=float("inf")
for i in product(range(4),repeat=n): #3を捨てる
    take=[[],[],[]]
    for k,j in enumerate(i):
        if j==3:
            continue
        take[j].append(l[k])
    *tmp,=map(len,take)
    if all(tmp):
        x,y,z=map(sum,take)
        ans=min(ans, (sum(tmp)-3)*10 + abs(x-a) + abs(y-b) + abs(z-c) )
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int n;

	cin >> n;

	vector<int>list;

	for (int i = 0; i < n * 2; i++) {
		int num;
		cin >> num;
		list.push_back(num);
	}

	sort(list.begin(), list.end());

	int cnt = 0;

	for (int i = 0; i < n * 2; i+=2) {
		cnt += list[i];
	}

	cout << cnt << endl;
	

	getchar();
	getchar();
	return 0;
}

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

int main() {
	int arr[5];
	for(int i=0;i<5;i++){
		cin>>arr[i];
	}
	for(int j=0;j<5;j++){
		if(arr[j]==0){
			cout<<j+1<<endl;
			break;
		}
	}
}

Measured memory_bytes: 3156
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n % 2 != 0) {
    cout << "No" << endl;
  } else {
    string t = s.substr(0, n / 2);
    t = t + t;
    if (s != t)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    string s, t;
    cin>>s>>t;
    int n = s.size(); int m = s.size();
    vector<int> S(n+1), T(m+1);
    for (int i = 1; i<=n; i++)
    {
        S[i] = S[i-1];
        if (s[i-1]=='A') S[i]++; else S[i]+=2;
    }

    for (int i = 1; i<=m; i++)
    {
        T[i] = T[i-1];
        if (t[i-1]=='A') T[i]++; else T[i]+=2;
    }

    int q;
    cin>>q;
    for (int i = 0; i<q; i++)
    {
        int a, b, c, d;
        cin>>a>>b>>c>>d;
        if ((S[b]-S[a-1])%3 == (T[d] - T[c-1])%3) cout<<"YES\n"; else cout<<"NO\n";
    }

}

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> lr(n);
    rep(i, n) lr[i].resize(n, 0);
    vector<vector<int>> dp(n);
    rep(i, n) dp[i].resize(n, 0);
    
    rep(i, m) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        lr[l][r]++;
    }
    
    rep(i, n) {
        reps(ii, i, n) {
            if (ii == i) {
                dp[i][ii] = lr[i][ii];
            }
            else {
                dp[i][ii] = dp[i][ii - 1];
                
                reps(iii, i, ii + 1) {
                    dp[i][ii] += lr[iii][ii];
                }
            }
        }
    }
    
    rep(i, q) {
        int a, b, ans = 0;
        cin >> a >> b;
        a--; b--;
        cout << dp[a][b] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n){
    cin >> p[i];
  }
  map<int,int> mp;
  for(int i=n-1; i>=0; i--){
    if(mp.find(p[i]+1)!=mp.end()){
      mp[p[i]] = mp[p[i]+1]+1;
    } else {
      mp[p[i]] = 1;
    }
  }

  int maxi = 0;
  for(auto it:mp){
    maxi = max(maxi, it.S);
  }
  int ans = n-maxi;
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 10368
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)

#define fst first
#define snd second

int main(void) {
    int n, max_cnt = 0;
    string s;
    map<string, int> mode_cnt;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    REP(i, n) {
        cin >> s;
        mode_cnt[s]++;
        max_cnt = max(max_cnt, mode_cnt[s]);
    }

    for (map<string, int>::iterator it = mode_cnt.begin(); it != mode_cnt.end(); ++it) {
        if (max_cnt == it->snd) {
            cout << it->fst << "\n";
        }
    }

    return 0;
}

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

int dist(char x){
  int ans = x-'a';
  ans = (26 - ans)%26;
  return ans;
}

int main(){
  string S;
  ll K;
  cin >> S >> K;
  int N=S.size();
  for(int i=0;i<N;i++){
    if(dist(S[i])<=K){
      K -= dist(S[i]);
      S[i] = 'a';
    }
  }
  K %= 26;
  S[N-1] = 'a' + (int(S[N-1]-'a') + K)%26;
  cout << S << endl;
}

Measured memory_bytes: 512
// All Heil Fire Lord Zuko

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

const int N = 2 * 100 * 1000 + 19;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    double n;
    cin >> n;
    int ans = (n + 1) / 2;
    cout << fixed << setprecision(10) << ans / n;
    return 0;
}


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

int main(){
  int k,s;
  cin>>k>>s;
  int count=0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      if(s-x-y>=0 && s-x-y<=k){  
      	count++;
      }
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
const int MAXN=5e5+10;
const double eps=1e-8;
const int MOD=1000000007;
const int INF=1e9+7;
using namespace std;
typedef  long long ll;
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll a,b,c,d;
ll so(ll C)
{
	ll a1,b1;
	//cout<<(a%C==0?0:(C-a%C))<<endl;
	a1=a+(a%C==0?0:(C-a%C));
    b1=b;
    //cout<<a1<<' '<<b1<<endl;
    if(a1>b1)
    {
    	//cout<<0<<endl;
    	return 0;
    }
    //cout<<(b1-a1)/C+1<<endl;
    return (b1-a1)/C+1;
}
int main()
{
    ll ans;
    cin>>a>>b>>c>>d;
    ans=b-a+1-(so(c)+so(d)-so(d*c/gcd(d,c)));
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int h,w,n,ans;
	cin >> h >> w >> n;
	if(n%max(h,w)==0)
		ans = n/max(h,w);
	else
		ans = n/max(h,w)+1;
	cout << ans << endl;
	return 0;
}

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

void swp_i(int* N1,int* N2){
	int tmp=*N1;
	*N1=*N2;
	*N2=tmp;
}
void swp_c(char* S1,char* S2){
	char tmp[11];
	strcpy(tmp,S1);
	strcpy(S1,S2);
	strcpy(S2,tmp);
}
int main(){
	int N;
	cin>>N;
	char S[100][11];
	int P[100],NUM[100];
	for(int i=0;i<N;i++){
		cin>>S[i]>>P[i];
		NUM[i]=i;
	}
	for(int i=N;i>0;i--){
		for(int j=0;j<i-1;j++){
			if(strcmp(S[j],S[j+1])>0){
				swp_c(S[j],S[j+1]);
				swp_i(&P[j],&P[j+1]);
				swp_i(&NUM[j],&NUM[j+1]);
			}else if(strcmp(S[j],S[j+1])==0){
				if(P[j]<P[j+1]){
					swp_c(S[j],S[j+1]);
					swp_i(&P[j],&P[j+1]);
					swp_i(&NUM[j],&NUM[j+1]);
				}
			}
		}
	}
	for(int i=0;i<N;i++){
		cout<<NUM[i]+1<<endl;
	}
	return 0;
}


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

int main() {

  int x,a,b;
	cin >> a >> b;
	x=a+b;

	if(x==3){
	cout << "3" << endl;
	}
	if(x==4){
	cout << "2" << endl;
	}
	if(x==5){
	cout << "1" << endl;
	}
	

}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

    int n = stdIn.nextInt();
    int t = stdIn.nextInt();
    int c, t_1;
    int count = 0;
    int min = 2147483647;

    for(int i = 0; i < n; i++){
      c = stdIn.nextInt();
      t_1 = stdIn.nextInt();

      if (t_1 <= t){
        count++;
        if(c < min) {
          min = c;
        }
      } else {
        continue;
      }

    }

    if (count == 0) {
      System.out.println("TLE");
    } else {
      System.out.println(min);
    }


  }
}

Measured memory_bytes: 23252
#include <stdio.h>

int a[1<<20];
int cnt[1<<20];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<1<<n;i++)scanf("%d",a+i);
	int ans=0;
	for(int i=0;i<1<<n;i++){
		if(cnt[i]&&!a[i]){
			puts("-1");
			return 0;
		}
		if(!cnt[i]&&a[i])ans++;
		if(a[i])for(int k=0;k<n;k++)if((~i>>k)&1)cnt[i^(1<<k)]++;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 10048
//JSD
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  bool res=0;  
  for(int i=1;i<=9;i++){
    if(n%i==0 && n/i<=9){
      res=1;
    }
  }
  if(res) cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}

Measured memory_bytes: 256
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_B
 */
#include <iostream>
#include <vector>
#include <map>

using namespace std;

class Die
{
    enum fname {
        top, front, right, left, back, bottom,
    };

    vector<int> faces;
    map<fname, int> f2i;

    void
    turn_e() {
        int tmp = f2i[top];
        f2i[top] = f2i[left];
        f2i[left] = f2i[bottom];
        f2i[bottom] = f2i[right];
        f2i[right] = tmp;
    }

    void
    turn_n() {
        int tmp = f2i[top];
        f2i[top] = f2i[front];
        f2i[front] = f2i[bottom];
        f2i[bottom] = f2i[back];
        f2i[back] = tmp;
    }

    void
    turn_s() {
        int tmp = f2i[top];
        f2i[top] = f2i[back];
        f2i[back] = f2i[bottom];
        f2i[bottom] = f2i[front];
        f2i[front] = tmp;
    }

    void
    turn_w() {
        int tmp = f2i[top];
        f2i[top] = f2i[right];
        f2i[right] = f2i[bottom];
        f2i[bottom] = f2i[left];
        f2i[left] = tmp;
    }

public:
    Die()
    {
        faces.reserve(6);

        f2i.emplace(top, 0);
        f2i.emplace(front, 1);
        f2i.emplace(right, 2);
        f2i.emplace(left, 3);
        f2i.emplace(back, 4);
        f2i.emplace(bottom, 5);
    }

    ~Die()
    {
        faces.clear();
        f2i.clear();
    }

    void
    read_faces(istream &is) {
        for (int i = 0; i < 6; i++) {
            is >> faces[i]; is.ignore();
        }
    }

    void
    top_front(const int t, const int f) {
        const string aface = "NENEN";
        for (auto it = aface.cbegin(); faces[f2i[top]] != f; it++) {
            turn(*it);
        }
        turn_s();
        const string roll = "EEE";
        for (auto it = roll.cbegin(); faces[f2i[top]] != t; it++) {
            turn(*it);
        }
    }

    void
    turn(const char c) {
        switch (c) {
          case 'N':
            turn_n();
            break;
          case 'E':
            turn_e();
            break;
          case 'S':
            turn_s();
            break;
          case 'W':
            turn_w();
            break;
        }
    }

    int Top()    { return faces[f2i[top]   ]; }
    int Front()  { return faces[f2i[front] ]; }
    int Right()  { return faces[f2i[right] ]; }
    int Left()   { return faces[f2i[left]  ]; }
    int Back()   { return faces[f2i[back]  ]; }
    int Bottom() { return faces[f2i[bottom]]; }
};

int
main()
{
    ios::sync_with_stdio(false);

    Die d;
    d.read_faces(cin);

    int n;
    cin >> n; cin.ignore();

    for (int i = 0; i < n; i++) {
        int t, f;
        cin >> t >> f; cin.ignore();
        d.top_front(t, f);
        cout << d.Right() << endl;
    }

    return 0;
}

Measured memory_bytes: 3128
s=input()
ans=0
for i in range(1 << len(s)-1):
    l=[]
    for j in range(len(s)-1):
        if (i>>j)&1==1:
            l.append(s[j])
            l.append("+")
        else:
            l.append(s[j])
    l.append(s[len(s)-1])
    ans+=eval(''.join(l))
print(ans)

Measured memory_bytes: 38896
import math
N,Ma,Mb = map(int,input().split(" "))
drags = [list(map(int,input().split(" "))) for  _ in range(N)]
INF = 10 ** 9
lim = N* 10 + 1
dp = [[[ INF for i in range(lim)] for j in range(lim)] for _ in range(N+1)]
dp[0][0][0] = 0
for num in range( N ):
    a,b,c = drags[num]
    dp[num + 1][0][0] = 0
    for i in range(0,lim): #完成した液体の aの量
        for j in range(0,lim):# bの量
            dp[num + 1][i][j]  =  dp[num][i][j]
            if i - a >= 0 and j - b >= 0:
                dp[num + 1][i ][j ] = min(dp[num][i ][j ] ,dp[num][i -a ][j -b  ]  + c)

ans = INF
for i in range(1,41):
    MA = Ma * i
    MB = Mb * i
    if MA >= lim or MB >= lim:
        break
    ans = min(ans, dp[-1][MA][MB])
if ans == INF:
    ans = -1
print(ans)



Measured memory_bytes: 98268
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 1000000000000000
#define mod 1000000007
#define ld long double
#define pll pair<ll,ll>
using namespace std;

int main()
{ 
fast;

ll n,k;
cin>>n>>k;

ll a[n+1];
for(ll i=1;i<=n;i++)
  cin>>a[i];

ll up[n+1][61];
memset(up,0,sizeof(up));

for(ll i=1;i<=n;i++)
  up[i][0]=a[i];

for(ll j=1;j<61;j++)
  for(ll i=1;i<=n;i++)
    up[i][j]=up[up[i][j-1]][j-1];

ll strt=1,ct=0;

for(ll i=60;i>-1;i--)
  if(ct+(1ULL<<i)<=k)
    strt=up[strt][i],ct=ct+(1ULL<<i);

cout<<strt;
}


Measured memory_bytes: 100540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}
const int n_max=201;
vector<int> g[n_max];
int used[n_max];
bool ok=true;
void dfs(int v, int color){
  if(used[v]==color) return;
  else if(used[v]==-1){
    used[v]=color;
    for(auto i:g[v]){
      if(used[i]==-1) dfs(i,(color+1)%2);
      if(used[i]==color) ok=false;
    }
  }
  else if(used[v]!=color) ok=false;
}


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

  int n;
  cin >> n;
  string s[n];
  rep(i,n) cin >> s[i];

  Matrix< int > mat(n, vector< int >(n, INT_MAX));
  rep(i,n) rep(j,n){
    if(s[i][j]=='1'){
      mat[i][j]=1;
      g[i].pb(j);
    }
    else if(i==j) mat[i][j]=0;
    else mat[i][j]=INT_MAX;
  }
  rep(i,n) used[i]=-1;
  dfs(0,0);
  if(ok){
    warshall_floyd(mat, INT_MAX);
    int ans=0;
    rep(i,n){
      rep(j,n){
	ans=max(mat[i][j],ans);
      }
    }
    cout << ans+1 << endl;
  }
  else{
    cout << -1 << endl;
  }
  
  return 0;
    

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 998244353LL
#define endl "\n"

//DPの考察が普通に難しかった。
//部分集合のさらに部分集合を考える場合は、もとの集合の各要素は３通りに遷移する。
//空集合でない部分集合という条件があるが、Sが正であるため、空集合ではないという条件は無視できる。

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, S;
  cin >> N >> S;
  vll A(N+1);
  for(ll i = 1; i <= N; i++){
    cin >> A.at(i);
  }
  vvll dp(N+1, vll(3001, 0));
  dp.at(0).at(0) = 1;
  for(ll i = 1; i <= N; i++){
    for(ll j = 0; j <= S; j++){
      dp.at(i).at(j) += dp.at(i-1).at(j) * 2;
      dp.at(i).at(j) %= MOD;
      if(j + A.at(i) <= 3000){
        dp.at(i).at(j+A.at(i)) += dp.at(i-1).at(j);
        dp.at(i).at(j+A.at(i)) %= MOD;
      }
    }
  }
  cout << dp.at(N).at(S) << endl;
}


Measured memory_bytes: 73672
import java.util.*;
public class Main
{
  
  public static void main(String args[]) 
  {
    
    Scanner sc=new Scanner(System.in);
   int len1=sc.nextInt();
   int len2=sc.nextInt();
   long k=sc.nextLong();
   long a1[]=new long[len1+1];
  long a2[]=new long[len2+1];
a1[0]=0;
a2[0]=0;
   for(int i=1;i<=len1;i++)
     a1[i]=sc.nextLong()+a1[i-1];
    for(int i=1;i<=len2;i++)
      a2[i]=sc.nextLong()+a2[i-1];
    int count=0;
   int dec=len2;
   for(int i=0;i<=len1 && a1[i]<=k;i++)
{
        while(a1[i]+a2[dec]>k)
            dec--;
         
        count=Math.max(count,dec+i);
}
System.out.println(count);
 
 
  }
}

Measured memory_bytes: 64844
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb(v, a) v.push_back(n)
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define MAX(a, b) a > b ? a : b;
#define MIN(a, b) a < b ? a : b;
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 100000000

using namespace std;

int N;
long long sum;
string S;
vector<int> v(9);

void dfs(int n) {
	if(n == N - 1) {
		int bp = 0;
		REP(i, N - 1) {
			if(v[i] == 1) {
				sum += stoll(S.substr(bp, i - bp + 1));
				bp = i + 1;
			}
		}
		sum += stoll(S.substr(bp, S.size() - bp));
	}
	else {
		v[n] = 1;
		dfs(n + 1);
		v[n] = 0;
		dfs(n + 1);
	}
}

int main() {
	REP(i, 9) {
		v[i] = 0;
	}
	CIN(S);
	N = S.size();
	dfs(0);
	COUT(sum);
}


Measured memory_bytes: 256
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/23 11:02:43 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/math/tools/minima.hpp>

#define MOD 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::math::tools::brent_find_minima;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::split;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	ll	n, m;
	cin >> n >> m;
	if (n >= m / 2)
	{
		cout << m / 2 << endl;
		return ;
	}
	ll total;
	total = 0;
	total += n;
	m -= 2 * n;
	total += m / 4;
	cout << total << endl;


}
// END

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


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int K = sc.nextInt();
    String S = sc.next();
    int ans = 0;
    for(int i=0; i<N-1; i++){
      if(S.charAt(i) == 'R' && S.charAt(i+1) == 'R') ans++;
    }
    for(int i=N-1; i>0; i--){
      if(S.charAt(i) == 'L' && S.charAt(i-1) == 'L') ans++;
    }
    ans += K * 2;
    ans = Math.min(ans, N-1);
    out.println(ans);  
  }
}

Measured memory_bytes: 23508
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  if (a < b) {
    return b - a;
  } else {
    return a - b;
  }
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a) {
    a = b;
  }
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b) {
    a = b;
  }
}
template <class F> class fix_point : private F {
public:
  explicit constexpr fix_point(F &&f) : F(std::forward<F>(f)) {}

  template <class... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};
template <class F> constexpr decltype(auto) make_fix(F &&f) {
  return fix_point<F>(std::forward<F>(f));
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize n = scan<usize>();
  std::vector<std::string> s(n);
  std::vector<u32> t(n);
  for (const usize i : rep(0, n)) {
    std::cin >> s[i] >> t[i];
  }
  const std::string x = scan<std::string>();
  u32 ans = 0;
  bool f = false;
  for (const usize i : rep(0, n)) {
    if (f) {
      ans += t[i];
      continue;
    }
    if (s[i] == x) {
      f = true;
    }
  }
  std::cout << ans << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


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

int main () {
  int a,b,c;
  cin >> a >> b >> c;
  int sum = a+b+c;
  if(sum<22) {
    cout << "win" << endl;
  }
  else {
    cout << "bust" << endl;
  }
}

Measured memory_bytes: 256
inputs = []

while true
  a, op, b = $stdin.readline.split(" ")
  a = a.to_i
  b = b.to_i

  if op == "?"
    break
  end

  inputs.push([a, op, b])
end

inputs.each do |a, op, b|
  case op
  when "+"
    puts a + b
  when "-"
    puts a - b
  when "*"
    puts a * b
  when "/"
    puts a / b
  end
end



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

using namespace std;

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while(A > 0 && C > 0){
    C -= B;
    A -= D;
  }
  
  if(C > 0) puts("No");
  else puts("Yes");
  
  return 0;
}

Measured memory_bytes: 3624
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};

use maplit::*;

use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF: usize = 1_000_000_007;
const MOD: usize = 2019;

#[fastout]
fn solve() {
  input! {
    s: Chars,
  };
  
  let s = s.iter().map(|&c| c as usize - 48).collect::<Vec<_>>();
  let n = s.len();

  let res = if n < 4 {
    0
  } else {
    let mut md = 1;
    let mut cur = *s.last().unwrap();
    let mut d = hashmap!{
      0usize => 1usize,
      cur => 1,
    };
    for i in (0..=n - 2).rev() {
      md = (md * 10) % MOD;
      cur = (cur + md * s[i]) % MOD;
      d.entry(cur)
        .and_modify(|e| *e += 1 )
        .or_insert(1);
    }
    d.values().map(|v| v * (v - 1) / 2 ).sum::<usize>()
  };
  
  println!("{}", res);
}

fn main() {
  std::thread::Builder::new()
    .name("big stack size".into())
    .stack_size(32 * 1024 * 1024)
    .spawn(|| {
      solve();
    })
    .unwrap()
    .join()
    .unwrap();
}


Measured memory_bytes: 3768
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI a(n);
    int prev_a = 0;
    int sum = 0;
    REP(i, n) {
        cin >> a[i];
        sum += abs(a[i] - prev_a);
        prev_a = a[i];
    }
    sum += abs(prev_a);
    
    prev_a = 0;
    a.push_back(0);
    REP(i, n) {
        int diff = abs(a[i] - prev_a)
                 + abs(a[i + 1] - a[i])
                 - abs(a[i + 1] - prev_a);
        prev_a = a[i];
        cout << sum - diff << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1656
from math import ceil
from math import floor
A, B = map(int,input().split())
PA = A / 0.08
PA_max = (A + 1) /0.08
P = ceil(PA)
while P < PA_max:
    if floor(P * 0.1) == B:
        print(P)
        break
    P += 1
else:
    print(-1)



Measured memory_bytes: 2940
def solve():
    from sys import stdin
    f_i = stdin
    
    N, W = map(int, f_i.readline().split())
    
    vw = tuple(tuple(map(int, f_i.readline().split())) for i in range(N))
    
    size = sum(vw_i[0] for vw_i in vw)
    inf = 10 ** 9
    dp = [inf] * (size + 1)
    dp[-1] = 0
    
    for v, w in vw:
        for i, tpl in enumerate(zip(dp[v:], dp)):
            w1, w2 = tpl
            w1 += w
            if w1 < w2:
                dp[i] = w1
    
    ans = 0
    for i, w in enumerate(dp[-2::-1], start=1):
        if w <= W:
            ans = i
    
    print(ans)

solve()


Measured memory_bytes: 5932