akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

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

    n = n % k;
    ll a = k - n;
    ll b = n;
    cout << min(a, b) << endl;

    return 0;
}

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

const LL MOD=1000000007;
LL inv[100005],invsum[100005];
int main(){
  LL N;scanf("%lld",&N);
  inv[1]=1L;
  for(LL i=2;i<=N;i++)inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
  for(LL i=1;i<=N;i++)invsum[i]=(invsum[i-1]+inv[i])%MOD;
  LL ans=0;
  for(LL i=1;i<=N;i++){
    LL A;scanf("%lld",&A);
    ans=(((invsum[i]+invsum[N-i+1]-1L)%MOD)*A+ans)%MOD;
  }
  for(LL i=1;i<=N;i++)ans=(ans*i)%MOD;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define acc 1000000007
int main() {
	int n, num[1000] = { 0 }, x;
	int flag = 0;
	long long ans = 1;

	scanf("%d", &n);
	for (int i = 2;i <= n;i++) {//i 割られる
		x = i;
		for (int j = 2; j <= x; j++) {
			while (x % j == 0) { //xをjでわりきれるか
				num[j - 1]++;//スタートが j=2
				x /= j;//素因数分解
			}
		}
	}
	for (int i = 1;i < 1000;i++){
		ans *= (long long)num[i] + 1;
		ans %= acc;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#define maxn 200010
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
inline long long min(long long a, long long b) {return a < b ? a : b;}
inline long long abs(long long a) {return a > 0 ? a : -a;}
int n, k, x, y;
int q, last;
long long V[maxn << 2][3], cov[maxn << 2];
void pushdown(int rt) {
	int lc = rt << 1, rc = rt << 1 | 1;
	long long &tmp = cov[rt];
	V[lc][0] += tmp;
	V[lc][1] += tmp;
	V[lc][2] += tmp;
	cov[lc] += tmp;
	V[rc][0] += tmp;
	V[rc][1] += tmp;
	V[rc][2] += tmp;
	cov[rc] += tmp;
	tmp = 0;
}
void update(int rt) {
	int lc = rt << 1, rc = rt << 1 | 1;
	V[rt][0] = min(V[lc][0], V[rc][0]);
	V[rt][1] = min(V[lc][1], V[rc][1]);
	V[rt][2] = min(V[lc][2], V[rc][2]);
}
void add(int rt, int l, int r, int p, long long num) {
	if (l == r) {
		V[rt][0] = num;
		V[rt][1] = num + l;
		V[rt][2] = num - l;
		return ;
	}
	if (cov[rt]) pushdown(rt);
	int mid = l + r >> 1;
	if (p <= mid) add(rt << 1, l, mid, p, num);
	else add(rt << 1 | 1, mid + 1, r, p, num);
	update(rt);
}
void add(long long num, int rt = 1) {
	V[rt][0] += num;
	V[rt][1] += num;
	V[rt][2] += num;
	cov[rt] += num;
}
long long ask(int rt, int l, int r, int L, int R, int op) {
	if (L <= l && R >= r) return V[rt][op];
	pushdown(rt);
	int mid = l + r >> 1;
	long long ans = inf;
	if (L <= mid) ans = ask(rt << 1, l, mid, L, R, op);
	if (R > mid) ans = min(ans, ask(rt << 1 | 1, mid + 1, r, L, R, op));
	return ans;
}
int main() {
	scanf("%d%d%d%d", &n, &k, &x, &y);
	scanf("%d", &q);
	memset(V, 0x3f, sizeof V);
	add(1, 1, n, x, abs(y - q));
	add(1, 1, n, y, abs(x - q));
	while (--k) {
		last = q; scanf("%d", &q);
		long long t0 = ask(1, 1, n, last, last, 0) + abs(q - last);
		long long t1 = ask(1, 1, n, q, n, 1) - q;
		long long t2 = ask(1, 1, n, 1, q, 2) + q;
		long long ans = min(t0, min(t1, t2));
		add(abs(q - last));
		add(1, 1, n, last, ans);
	}
	printf("%lld\n", V[1][0]);
	return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  string s; cin >> s;
  if (s == "Sunny") cout << "Cloudy" << endl;
  if (s == "Cloudy") cout << "Rainy" << endl;
  if (s == "Rainy") cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 256
fun main() {
val s = next()
    val half = s.substring(0, s.length/2)
    printYesNo(s == s.reversed() &&  half == half.reversed())
}

val scanner = java.util.Scanner(System.`in`)
fun next(): String = scanner.next()
fun nextInt() = scanner.nextInt()
fun nextLong() = scanner.nextLong()
fun nextList() = readLine()!!.split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")

fun main(args: Array<String>) = main()

Measured memory_bytes: 31272
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        100000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

template<typename T>
T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class DAlterAltar {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, moves = 0;
        string s;
        in >> n >> s;
        int Wcnt = count(All(s), 'W');
        for (int i = n - 1; i >= 0; --i) {
            if (Wcnt > 0) {
                if (s[i] == 'R') {
                    moves++;
                    Wcnt--;
                } else {
                    Wcnt--;
                }
            }
        }
        out << moves << endl;
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    DAlterAltar solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
int main() {
	ll n, a[110], b[110];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i)a[i] += a[i - 1];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		if (i)b[i] += b[i - 1];
	}
	ll ans = a[0] + b[n - 1];
	for (int i = 1; i < n; i++) {
		ans = max(ans, a[i] + b[n - 1] - b[i - 1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

# a_set = sorted(set(a))

count = [0] * (n + 1)


def f(n):
    return (n * (n - 1) // 2)


sum = 0
for i in a:
    count[i] += 1
for i in count:
    sum += f(i)

for i in a:
    print(sum - (count[i] - 1))


Measured memory_bytes: 25644
fn main() {
    let mut a = String::new(); //500 yen
    std::io::stdin().read_line(&mut a).unwrap();
    let a = a.trim().parse::<u32>().unwrap();

    let mut b = String::new(); //100 yen
    std::io::stdin().read_line(&mut b).unwrap();
    let b = b.trim().parse::<u32>().unwrap();

    let mut c = String::new(); //50 yen
    std::io::stdin().read_line(&mut c).unwrap();
    let c = c.trim().parse::<u32>().unwrap();

    let mut x = String::new(); // x yen
    std::io::stdin().read_line(&mut x).unwrap();
    let x = x.trim().parse::<u32>().unwrap();

    let mut ans = 0;

    for i in 0..a+1 {
//        println!("{}", 500 * i);
        for j in 0..b+1 {
//            println!("{}", 500 * i + 100 * j);
            for k in 0..c+1 {
//                println!("{}", 500 * i + 100 * j + 50 * k);
                if (x == 500 * i + 100 * j + 50 * k) {
//                    println!("match");
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}

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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;

    ll d = c - a - b;
    puts((d > 0 && d * d > 4 * a * b ? "Yes" : "No"));
}

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

int main()
{
  int n;
  cin >> n;
  vector<long long> lucas = {2, 1};
  for(int i = 1; i < n; ++i) lucas.push_back(lucas[i] + lucas[i - 1]);
  
  cout << lucas.back() << endl;
}

Measured memory_bytes: 256
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
int arr[25];
using namespace std;
int main()
{
    int i,j,x,y,ans,curr=0,rose,n,m,c;
    cin >> n >> m >> c;
    for(i=1;i<=m;i++)
    {
        cin >> arr[i];
    }
    rose = 0;
    for(i=1;i<=n;i++)
    {
        ans = 0;
        for(j=1;j<=m;j++)
        {
            cin >> curr;
            ans += curr*arr[j];
        }
        ans += c;
        if(ans > 0)
            rose++;
    }
    cout << rose << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    x = I()

    if x < 1200:
        print('ABC')
    else:
        print('ARC')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9972
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;
int main() {
	string s;
	cin >> s;
	char c = s[0];
	char c2;

	int o = 0, t = 0;

	for (int i = 0; i < 4; i++) {
		if (s[i] == c) {
			o++;
		}
		else {
			if (t == 0) {
				t++;
				c2 = s[i];
			}
			else {
				if (c2 == s[i])t++;
			}
		}
	}
	if (o == t && o == 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
      int n,q;
      int c[300001];
      int arr[300001];
      scanf("%d%d", &n,&q);
      REP(i,n)scanf("%d",&c[i]);
      sort(c,c+n);
      c[n]=300000;
      REP(i,c[0])arr[i]=0;
      for(int i=0;i<n;i++)
            for(int j=c[i]+1;j<=c[i+1];j++)
                  arr[j]=c[i];
      while(q--){
            int t,ans=0;
            scanf("%d",&t);
            for(int i=0;i<=300000;i+=t)ans=max(ans,arr[i]%t);
            printf("%d\n",ans);
      }
}

Measured memory_bytes: 3548
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, x): (i64, i64) = read();

    let mut sum = n;
    let mut a = min(x, n-x);
    let mut b = max(x, n-x);
    while true {
        if b % a == 0 {
            sum += a * (b / a) * 2 - a;
            break
        } else {
            sum += a * (b / a) * 2;
            let ta = b % a;
            b = a;
            a = ta;
        }
    }
    println!("{}", sum);
}

Measured memory_bytes: 4352
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		
		for(int i  = 1; i < 1000; i++) {
			for(int j = -100; j < 1000; j++) {
				long a = (long) Math.pow(i, 5);
				long b = (long) Math.pow(j, 5);
				if(a-b == x) {
					System.out.println(i+" "+j);
					return;
				}
			}
		}
	}
}

Measured memory_bytes: 38756
#include <bits/stdc++.h>
using namespace std;
int main() {
	int q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	h = min(2 * q, h);
	s = min(2 * h, s);
	long long ans = 0;
	if (n & 1) ans += s;
	ans += 1LL * min(s * 2, d) * (n / 2);
	cout << ans << endl;
}



Measured memory_bytes: 256
a,b = list(map(int, input().split()))

amin = (a/0.08)*-1//1*-1
amax = ((a+1)/0.08)//1
if ((a+1)/0.08)%1 == 0:
    amax -= 1

bmin = (b/0.1)*-1//1*-1
bmax = ((b+1)/0.1)//1
if ((b+1)/0.1)%1 == 0:
    bmax -= 1

ans = float("inf")
if amin <= bmax and amin >= bmin:
    ans = min(ans, amin)
elif bmin <= amax and bmin >= amin:
    ans = min(ans, bmin)
else:
    ans = -1

print(int(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define eps 1e-67
#define pf printf
#define sf scanf
#define sd(n) scanf("%d",&n)
#define sd2(n1,n2) scanf("%d %d",&n1,&n2)
#define slf(n) scanf("%lf",&n)
#define slf2(n1,n2) scanf("%lf %lf",&n1,&n2)
#define sLf(n1) scanf("%Lf",&n1)
#define sLf2(n1,n2) scanf("%Lf %Lf",&n1,&n2)
#define sl(n) scanf("%lld",&n)
#define sl2(n1,n2) scanf("%lld %lld",&n1,&n2)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c)
#define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c)
#define asort(a) sort(a.begin(),a.end())
#define asortb(a,comp) sort(a.begin(),a.end(),comp)
#define arev(a) reverse(a.begin(),a.end())
#define all(v) (v).begin(),(v).end()
#define allc(v,comp) (v).begin(),(v).end(),comp
#define allrc(v,a,b,comp) (v).begin()+a,(v).end()-b,comp
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define mt make_tuple
#define bs(v,x) binary_search(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define tl(c) towlower(c)
#define root(x) sqrt(x)
#define power(a,n) pow(a,n)
#define tu(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define mx 1000
#define MX 100000
#define mod 1000000007
using namespace std;
typedef string str;
typedef long long int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef char ch;
typedef map<ll,ll> mp;


int main()
{
    str s;
    cin>>s;
    arev(s);

    str s1[]={"dream","dreamer","erase","eraser"};
    rep(i,0,4)
    {
        arev(s1[i]);
    }
    int pos=0;
    while(1){
        bool ok=false;
        rep(i,0,4)
        {
            if(s.substr(pos,s1[i].size())==s1[i])
            {
                ok=true;
                pos=pos+s1[i].size();
                break;
            }
        }

     if(pos>=s.size())
     {
         cout<<"YES"<<endl;
            return 0;
     }
     if(ok==false)
     {
         cout<<"NO"<<endl;
            return 0;
     }
    }
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(void){
	int ans=0;
	string s;
	cin>>s;
	for(int i=1;i<s.size();i++)
		if(s[i]!=s[i-1])ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}
const int MN = 100100;

int n;
ll c[MN];
bool nim(ll a) {
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans ^= (c[i] % (a+1));
    }
    return (ans != 0);
}
bool solve() {
    ll a, b;
    cin >> n >> a >> b;
    ll ma = -1;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        ma = max(ma, c[i]);
    }
    if (a == b) return nim(a);
    if (ma <= min(a, b)) return nim(a);
    if (a > b) return true;
    if (2*a < ma) return false;
    int u = 0;
    for (int i = 0; i < n; i++) {
        if (a < c[i]) u++;
    }
    if (2 <= u) return false;
    //[ma-a ~ a]
    ll nim = 0;
    for (int i = 0; i < n; i++) {
        if (a < c[i]) continue;
        nim ^= c[i];
    }
    if (ma-a <= nim and nim <= a) return true;
    return false;
}
int main() {
    string H = "Hanako";
    string J = "Jiro";
    if (solve()) {
        cout << H << endl;
    } else {
        cout << J << endl;
    }
    return 0;
}

Measured memory_bytes: 3996
/// Code by Leonardo16
///   “It is not the strength of the body, but the strength of the spirit.”   —  J.R.R. Tolkien
#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")

#define int long long
#define ll long long
#define sz size
#define ull unsigned long long
#define ld long double
#define ii pair<int,int>
#define fst first
#define scd second
#define vi vector<int>
#define vii vector<ii>
#define pb push_back
#define pf push_front
#define fl '\n'
#define el endl
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
/// Functions
#define db(x) cerr << #x << ": " << (x) << '\n';
#define random() __builtin_ia32_rdtsc()
#define lg2(x) 31-__builtin_clz(x)
#define lg2ll(x) 63-__builtin_clzll(x)
#define pi acos(-1)
#define YN(x) cout<<((x)?("YES"):("NO"))<<fl;
#define yn(x) cout<<((x)?("Yes"):("No"))<<fl;
#define des(x,s1,s2,end1,end2) cout<<((x)?(s1):(s2))<<fl;if(x){end1;}else{end2;}
#define precision(x) cout.setf(ios::fixed);cout.precision(x);
/// Red-Black Tree Template
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
//#define less_than(n) order_of_key(n)
//#define en_pos(n) find_by_order(n)
/// Prime numbers  173,179,311,331,737,1009,2011,2027,3079,4001,100003
///=====================================================================

main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    vi a,b;

    int sum=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        sum+=x;
        a.pb(x);
    }

    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        b.pb(x);
    }
    reverse(all(a));
    reverse(all(b));

    int j=m;
    int ans=0;
    for(int i=0;i<n;i++){
        while( j!=0 && sum+b[j-1]<=k ){
            sum+=b[j-1];
            j--;
        }
        if(sum<=k)ans=max(ans, n-i+m-j);
//        cout<<sum<<" "<<j<<fl;
        sum-=a[i];
    }

    sum=0;
    for(int j=m-1;j>=0;j--){
        sum+=b[j];
        if(sum<=k){
            ans=max(ans,m-j);
        }
    }

    cout<<ans;



return 0;}







Measured memory_bytes: 7960
n=int(input())
dic={}
for x in range(n):
    s=list(map(str,input().split()))
    if(s[0]=="insert"):
        dic[s[1]]=True
    elif(s[0]=="find"):
       if(dic.get(s[1])==True):
           print("yes")
       else:
        print("no")


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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int h, a; std::cin >> h >> a;
  std::cout << (h + a - 1) / a << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <set>
#include <unordered_map>
#include <iomanip>

using namespace std;

int main()
{
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    for(auto &aa : a) cin >> aa;
    sort(a.begin(), a.end(), greater<int>());
    int previous = 0;
    a[0]--;
    for(int i=1; i<a.size(); i++) {
        if(a[i]==0) continue;
        if(previous==i) continue;
        a[i]--;
        previous=i;
        i = -1;
    }
    cout << a[0] << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
int main()
{
  int i, j, H, W;
  for(;;){
    scanf("%d %d",&H, &W);
    if(H == 0 && W == 0)break;
    for(i =0; i < H; i++){
      for(j = 0; j < W; j++){
	if(i == 0 || i == (H - 1)){
	  printf("#");
	} else if(j == 0 || j == (W - 1)){
	  printf("#");
	} else { 
	  printf(".");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <iostream>

int main(int argc, char *argv[]) {
  int k, n;
  std::cin >> k >> n;
  int a[200000];
  for (int i = 0; i < n; ++i)
    std::cin >> a[i];

  int d = 0;
  for (int i = 1; i < n; ++i) {
    d = std::max(d, a[i] - a[i - 1]);
  }
  d = std::max(d, a[0] + k - a[n - 1]);

  std::cout << k - d << std::endl;
}


Measured memory_bytes: 1024
import sys

row1 = [int(n) for n in input().split()]
row2 = [int(n) for n in input().split()]
row3 = [int(n) for n in input().split()]

card = [row1,row2,row3]

#print(card)

N = int(input())
for n in range(N):
    bn = int(input())
    for i in range(len(card)):
        for j in range(len(card)):
            if card[i][j] == bn:
                card[i][j] = 0

#print(card)

for i in range(len(card)):
    check_i = 0
    for j in range(len(card)):
        check_i += card[i][j]
    #print('check_i: ' + str(check_i))
    if check_i == 0:
        print('Yes')
        sys.exit(0)
for j in range(len(card)):
    check_j = 0
    for i in range(len(card)):
        check_j += card[i][j]
    #print("check_j: " + str(check_j))
    if check_j == 0:
        print('Yes')
        sys.exit(0)

check_diag1 = 0
check_diag2 = 0
for i in range(len(card)):
    check_diag1 += card[i][i]
    check_diag2 += card[len(card)-i-1][i]
#print('check_diag1: ' + str(check_diag1))
#print('check_diag2: ' + str(check_diag2))
if check_diag1 == 0 or check_diag2 == 0:
    print('Yes')
    sys.exit(0)

print('No')


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;


int main()
{
  int A, P;
  cin >> A >> P;
  cout << (A*3+P) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int n;

int lis(vector<int>& a) {
  vector<int> l(a.size());
  l[0] = a[0];
  int length = 1;

  FOR(i, 1, n) {
    if (l[length - 1] < a[i]) {
      l[length++] = a[i];
    }
    else {
      *lower_bound(l.begin(), l.begin() + length, a[i]) = a[i];
    }
  }
  
  return length;
}

int main() {
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  cout << lis(a) << endl;

  
  return 0;
}


Measured memory_bytes: 3616
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int main() {
  ll n;
  cin >> n;
  VI a(n, 0);
  REP(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  ll cnt = 0;
  ll sign = 1;
  for (int i = n - 1; i >= 0; i--) {
    cnt += sign * a[i];
    sign *= -1;
  }
  cout << cnt << endl;
  return 0;
}


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

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif
#define pb push_back
#define mod 1000000007
#define endl '\n'
typedef int integer;
#define int long long
using namespace std;

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = 200005;
int ar[NN];
int n, m, k;


integer main() {
    ios_base::sync_with_stdio(false);

    int t = 1;
//    cin >> t;
    while (t--) {
        cin >> n;
        int ans = 0;
        for (int i = 1; i <= n; i++){
            for (int j = 1; j <= n; j++){
                for (int k = 1; k <= n; k++){
                    ans += gcd(gcd(i, j), k);
                }
            }
        }
        cout << ans << endl;
    }

}



Measured memory_bytes: 3668
//============================================================================
// Name        : Hello.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main() {

	int n;
	cin>>n;

	int A[n];
	int B[n];
	int C[n-1];
	int sum=0;

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

	for(int i=0;i<n;i++){
		cin>>B[i];
		sum+=B[i];
	}

	for(int i=0;i<n-1;i++){
		cin>>C[i];
	}



int y;
	for(int i=0;i<n-1;i++){
		y=A[i];
		if(A[i+1]==A[i]+1){
			sum+=C[y-1];
		}

	}

	cout<<sum<<endl;




	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
static const int N = 100;
int min(int x, int y){ return x < y ? x : y; }
int main(){
  int i, j, k, l;
  int n, r[N+1], a[N+1][N+1];
  scanf("%d", &n);
  for ( i = 1; i <= n; i++ ){
    scanf("%d %d", &r[i-1], &r[i]);
  }
  for ( i = 1; i <= n; i++ ) a[i][i] = 0;
  for ( l = 2; l <= n; l++ ){
    for ( i = 0; i <= n-l+1; i++ ){
      j = i+l-1;
      a[i][j] = (1<<21);
      for ( k = i; k <= j-1; k++ ){
	a[i][j] = min(a[i][j], a[i][k] + a[k+1][j] + r[i-1]*r[k]*r[j]);
      }
    }
  }
  printf("%d\n", a[1][n]);
  return 0;
}



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

using namespace std;

#define ll long long
#define ull unsigned long long
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define f(i,a, b) for (ll i = a; i < b; i++)
#define ft int t; cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define ld float
#define fd(i,a, b) for (ll i = a; i >= b; i--)

 /*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
     typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/

int main() {

 ll n,m;
 cin>>n>>m;
 ll aa[n];
 ll sm=0;
 f(i,0,n) {cin>>aa[i];  sm+=aa[i]; }
 ll to=(sm)/(4*m);
 if(sm%(4*m)!=0)to++;
 int cnt=0;
 f(i,0,n){
 if(aa[i]<to);
 else cnt++;
 }
 if(cnt>=m)cout<<"Yes";
 else cout<<"No";


}


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

int main(){
    ll n,m;
    cin>>n>>m;
    if(n==1 && m==1){
        cout<<1<<endl;
        return 0;
    }
    else if(n>=2 && m>=2){
        cout<<(n-2)*(m-2)<<endl;
        return 0;
    }
    else if(n==1 && m>1){
        cout<<m-2<<endl;
        return 0;
    }
    else if(m==1 && n>1){
        cout<<n-2<<endl;
        return 0;
    }
    else cout<<0<<endl;
}

Measured memory_bytes: 256
S = input()
times = int(input())

top =0
first = str()
last = str()

for i in range(times):
    Q =input().split()
    if Q[0] =="1":
        top = (top+1)%2
    else:
        if Q[1] == "1":
            #先頭に追加する 0のとき先頭
            if top ==0:
                first +=Q[2]
            else:
                last += Q[2]
        else:
            if top ==1:
                first +=Q[2]
            else:
                last += Q[2]
if top == 0:
    S = first[::-1] + S + last
else:
    S = last[::-1] + S[::-1] + first


print(S)

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

long long DP_Knapsack(vector<long long> weights, vector<long long> values, long long capacity, long long n){
    long long i,wts;
    vector< vector< long long > > arr(n+1,vector<long long>(capacity+1));
    for(i=0;i<=n;i++){
        for(wts=0;wts<=capacity;wts++){
            if(i==0 || wts==0){
                arr[i][wts] = 0;
            }
            else if(weights[i-1]<=wts){
                arr[i][wts] = max(values[i-1]+arr[i-1][wts-weights[i-1]], arr[i-1][wts]);
            }
            else{
                arr[i][wts] = arr[i-1][wts];
            }
        }
    }
    return arr[n][capacity];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    long long n;
    long long capacity;
    cin>>n>>capacity;
    vector<long long> weights(n);
    vector<long long> values(n);
    long long i;
    for(i=0;i<n;i++){
        cin>>weights[i];
        cin>>values[i];
    }
    long long result = DP_Knapsack(weights,values,capacity,n);
    cout<<result<<"\n";
    return 0;
}

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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
// template starts
typedef long long int ll;
ll fact(ll n, ll p){
	ll ans = 1;
	for(ll i = 1; i <= n; i++){
		ans *= i;
		ans %= p;
	}
	return ans;
}
ll power(ll x, ll n, ll p){
	ll res = 1;
	if(n == 1) return x%p;
	if(n%2 == 1) res = x%p;

	ll temp = power(x,n/2,p);
	return res*((temp*temp)%p)%p;
}
ll inv(ll a, ll p){
	return power(a,p-2,p);
}
ll nCr(ll n, ll r, ll p){
	if(r > n) return 0;
	ll t1 = fact(n,p);
	ll t2 = inv(fact(r,p),p);
	ll t3 = inv(fact(n-r,p),p);

	return (((t1*t2)%p)*t3)%p;
}
vector<vector<ll> > multiply(vector<vector<ll> > &a, vector<vector<ll> > &b, ll p){
	int r1,c1,r2,c2;
	r1 = a.size(); c1 = a[0].size();
	r2 = b.size(); c2 = b[0].size();

	vector<vector<ll> > result(r1,vector<ll>(c2,0));

	if(c1 != r2) return result;

	for(int i = 0; i < r1; i++){
		for(int j = 0; j < c2; j++){
			for(int k = 0; k < c1; k++){
				result[i][j] += a[i][k]*b[k][j];
				result[i][j] %= p;
			}
		}
	}
	return result;
}

vector<vector<ll> > power(vector<vector<ll> >&a,ll n, ll p){
	int r = a.size();
	vector<vector<ll> > result(r,vector<ll>(r,0));
	for(int i = 0; i < r; i++) result[i][i] = 1;

	while(n > 0){
		if(n%2 == 1){
			result = multiply(result,a,p);
		}
		n /= 2;
		a = multiply(a,a,p);
	}
	return result;
}
// template ends here
vector<vector<ll> > dp;
ll f(ll start, ll end, vector<ll> &vec){
	if(dp[start][end] != -1) return dp[start][end];
	
	if(start == end) return vec[start];
	if(start+1 == end) return max(vec[start],vec[end]);
	
	ll t1= vec[start] + min(f(start+2,end,vec),f(start+1,end-1,vec));
	ll t2 = vec[end]  + min(f(start+1,end-1,vec), f(start,end-2,vec));
	
	dp[start][end] = max(t1,t2);
	return max(t1,t2);
}

void solve(){
	// code starts from he
	ll N, sum = 0;
	cin >> N;
	vector<ll> vec(N);
	
	dp.resize(N);
	forf(i,0,N){
		forf(j,0,N) dp[i].pb(-1);
	}
	forf(i,0,N){
		cin >> vec[i];
		sum += vec[i];
	}
	
	ll ans = 2*f(0,N-1,vec) -sum;
	cout << ans << endl;
}

int main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int T;
	//cin >> T;
	T = 1;
	while(T--){
		solve();
	}

	return 0;
}


Measured memory_bytes: 82944
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a;
int main(){
	cin >> n;
	bool flag = true;
	for(int i = 0; i < n; i++){
		cin >> a;
		if(!(a&1))
			if(a % 3 != 0 && a % 5 != 0)
				flag = false;
	}
	if(flag) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000

int main(){
  int N; cin >> N;
  vector<pair<int,int>> cood(N);
  int v[N];
  rep(i,N){
    cin >> cood[i].first >> cood[i].second;
  }
  double dist_sum = 0;

  for (int i=0;i<N;i++){
    for (int j=i+1;j<N;j++){
      dist_sum += sqrt(pow(cood[i].first-cood[j].first, 2) + pow(cood[i].second-cood[j].second,2));
    }
  }

  //per = per/(N+1);
  cout << fixed << setprecision(10);
  cout << 2*dist_sum/N << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD =1000000007;//1e9 + 7;





int main(){
	
	ll n;
	ll a;
	ll c=1;
	ll ans=0;
    cin>>n;
	rep(i,n){
		cin>>a;
		if(a==c){
			c++;
		}else{
			ans++;
		}
	}
    if(ans==n){cout<<-1<<endl;return 0;}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    string S, T;
    read(S, T);
    string ans = "Yes";
    for(int i = 0; i < S.size(); i++){
        if(S[i] != T[i]) ans = "No";
    }
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>

static void print_ans (int str_len, int cur_len, char max_char, char str[]) {
    char cur;

    if ( cur_len == str_len ) {
        str[str_len] = '\0';
        printf("%s\n", str);
        return;
    }

    /* can use from 'a' to 'max_char+1' */
    for ( cur = 'a'; cur <= max_char+1; cur++ ) {
        str[cur_len] = cur;
        print_ans(str_len, cur_len+1, (cur > max_char) ? cur : max_char, str);
    }
}

int main (void) {
    int n;
    scanf("%d", &n);
    char str[n+1];

    print_ans(n, 0, 'a'-1, str);

    return EXIT_SUCCESS;
}


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


int main(){
  int n;
  cin >> n;
  bool ha=false;
  for(int i=1;i<=3;++i){
    int a=n%10;
    if(a==7){
      ha=true;
    }
    n=n/10;
  }
  if(ha==true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3600
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<ll, ll> ii;

#define all(v)		((v).begin()), ((v).end())
#define sz(v)		((int)((v).size()))
#define endl		"\n"
#define fx(n)		fixed<<setprecision(n)
#define mk			make_pair	

void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
/*#ifndef ONLINE_JUDGE
	freopen("output.out", "w", stdout);
	freopen("input.in", "r", stdin);
#endif
	#ifdef ONLINE_JUDGE
	//freopen("output.txt", "w", stdout);
	freopen("path.in", "r", stdin);
	#endif*/
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e3 + 15;
int dx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[8] = { 0, 0, -1, 1, -1, 1, 1, -1 };

bool valid(char c, int idx)
{
	if (idx % 2 == 0)
	{
		if (c == 'L')
			return 0;
		return 1;
	}
	else
	{
		if (c == 'R')
			return 0;
		return 1;
	}
}
int main()
{
	fast();
	string s;
	cin >> s;
	for (int i = 0; i < sz(s); i++)
	{
		if (!valid(s[i], i))
			return cout << "No\n", 0;
	}
	cout << "Yes\n";
	return 0;
}

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

int main(){
  int n, k;
  string s;
  cin >> n >> k >> s;
  bool rev = false;
  int ans = 0;
  for(int i=0; i<n-1; ++i){
    if (s[i] == s[i+1]) ++ans;
    else if (k>0){
      if(rev){
        --k;
        ans += 2;
        rev = false;
      }else{
        rev = true;
      }
    }
  }
  if(k>0 && rev) ++ ans;
  cout << ans << endl;
}

Measured memory_bytes: 3748
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func genPatterns() chan []bool {
	ch := make(chan []bool)

	var rec func(b []bool)
	rec = func(b []bool) {
		if len(b) == 10 {
			nb := make([]bool, 10)
			copy(nb, b)
			ch <- nb
			return
		}
		rec(append(b, false))
		rec(append(b, true))
	}

	go func() {
		rec(nil)
		close(ch)
	}()

	return ch
}
func main() {
	defer stdout.Flush()

	N := readInt()
	F := make([][]bool, N)
	for i := 0; i < N; i++ {
		F[i] = make([]bool, 10)
		for j := 0; j < 10; j++ {
			f := readInt()
			if f == 1 {
				F[i][j] = true
			}
		}
	}

	P := make([][]int, N)
	for i := 0; i < N; i++ {
		P[i] = make([]int, 11)
		for j := 0; j < 11; j++ {
			P[i][j] = readInt()
		}
	}

	patterns := genPatterns()
	<-patterns

	ans := int64(math.MinInt64)
	for b := range patterns {
		counts := make([]int, N)
		for i := 0; i < len(b); i++ {
			if !b[i] {
				continue
			}
			for j := 0; j < N; j++ {
				if F[j][i] {
					counts[j]++
				}
			}
		}
		var tmp int64
		for i := 0; i < N; i++ {
			tmp += int64(P[i][counts[i]])
		}
		ans = maxInt64(ans, tmp)
	}
	println(ans)
}


Measured memory_bytes: 1664
import java.util.Arrays;
import java.util.Scanner;


public class Main{
	
	static Scanner sc = new Scanner(System.in);
	
	static int n, sum;
	static boolean prime[];

	public static void main(String[] args) {
		
		while(read()){
			solve();
		}

	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
		
		n = sc.nextInt();
		
		return true;
	}
	
	public static void solve(){
		
		prime = new boolean[n+1];
		Arrays.fill(prime, true);
		prime[0] = false;
		prime[1] = false;
		
		for(int i = 2; i < prime.length; i++){
			if(prime[i]){
				for(int j = 2 * i; j < prime.length; j += i){
					prime[j] = false;
				}
			}
		}
		
		sum = 0;
		for(int i = 0; i < prime.length; i++){
			if(prime[i]) sum++;
		}
		
		System.out.println(sum);
	}

}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
long long f (long long i,vector<long long> &v) {
  if (i == 0) {
    v[i] = 2;
    return v[i];
  }
  else if (i == 1) {
    v[i] = 1;
    return v[i];
  }
  else if (v[i-1] != 0 && v[i-2] != 0) {
    v[i] = v[i-1]+v[i-2];
    return v[i];
  }
  else {
    v[i] = f(i-1,v)+f(i-2,v);
    return f(i-1,v)+f(i-2,v);
  }
}
int main () {
  long long a;
  cin >> a;
  vector<long long> v(a+1,0);
  cout << f(a,v) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int ara[100000];
char ara1[100000];
int main()
{
    int i,j,k,a,b,h,ln,v=0;
    char ch;
    gets(ara1);
    ln=strlen(ara1);
    for(i=0;i<ln;i++)
    {
        for(ch='a',j=1;ch<='z';ch++,j++)
        {
            if(ara1[i]==ch)
            {
                ara[j]++;
                break;
            }
        }
    }
    for(i=1;i<=26;i++)
    {
        if(ara[i]%2!=0)
        {
            v=1;
            break;
        }
    }
    if(v==1)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
    return 0;
}




Measured memory_bytes: 128
#include<stdio.h>
int main() {
	int i,n,m,x[2020],a;
	scanf("%d",&n);
	for (i = 0; i < n; i++) {
		scanf("%d",&x[i]);
	}
	x[i] = -1;
	scanf("%d", &m);
	for (i = 0; i < m; i++) {
		scanf("%d",&a);
		if (x[a-1] != 2019 && x[a-1] + 1 != x[a])x[a-1]++;
	}
	for (i = 0; i < n; i++) {
		printf("%d\n",x[i]);
	}
	return 0;
}


Measured memory_bytes: 2748
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
    int n,a[200000],m1=-1,m2=-1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(m1<a[i]){
            m2=m1;
            m1=a[i];
        }
        else{
            m2=max(m2,a[i]);
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]==m1){
            printf("%d\n",m2);
        }
        else{
            printf("%d\n",m1);
        }
    }
}

Measured memory_bytes: 2432
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 100010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

vector <int> A;
ll sum[MAX], maxi[MAX];

void solve(void){
    int N, K;
    cin >> N >> K;
    rep(N, i) {
        int a; scanf("%d\n", &a);
        A.push_back(a);
    }
    sum[0] = A[0];
    maxi[0] = max(0, A[0]);
    rep(N-1, i) {
        sum[i+1] = A[i+1] + sum[i];
        maxi[i+1] = max(0, A[i+1]) + maxi[i];
    }
    ll ans = max(maxi[N-1] - maxi[K-1] + sum[K-1], 0LL);
    Rep(1, N-K, i) {
        ll cand = maxi[N-1] - maxi[i+K-1] + maxi[i-1] + max(sum[i+K-1] - sum[i-1], 0LL);
        ans = max(ans, cand);
    }
    printf("%lld\n", ans);
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 2296
#include<iostream>
using namespace std;
int main() {
int a,b,c;
cin>>a>>b>>c;
if(a==1&&b==0&&c==0)cout<<"Close";
if(a==0&&b==1&&c==0)cout<<"Close";
if(a==1&&b==1&&c==0)cout<<"Open";
if(a==0&&b==0&&c==1)cout<<"Open";
if(a==0&&b==0&&c==0)cout<<"Close";
cout<<endl;
return 0;
}

Measured memory_bytes: 1156