akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

llong N, K;
vector<vector<llong> > dp;

llong solve(llong now, llong bunkatsu) {
	if (now == 0) return dp[now][bunkatsu] = bunkatsu == 0;
	if (bunkatsu == 0) return dp[now][bunkatsu] = 0;
	if (dp[now][bunkatsu] != -1) return dp[now][bunkatsu];

	return dp[now][bunkatsu] = (solve(now-1, bunkatsu) + solve(now-1, bunkatsu-1)) % mod;
}

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

	dp.resize(N+1, vector<llong>(K+2, -1));
	for (int i = 0; i <= K+1; ++i) {
		solve(N, i);
		solve(N-K, i);
	}

	for (int i = 1; i <= K; ++i) {
		// llong b = dp[K][i];
		// llong r = (dp[N-K][i-1] + dp[N-K][i]*2 + dp[N-K][i+1]) % mod;
		// cout << b*r%mod << endl;
		// cerr << dp[K][i] << " " << dp[N-K][i-1] << " " << dp[N-K][i] << " " << dp[N-K][i+1] << endl;
		cout << dp[K][i] * (max(0ll, dp[N-K][i-1]) + max(0ll, dp[N-K][i])*2ll + max(0ll, dp[N-K][i+1])) % mod << endl;
	}

	return 0;
}

/*

Kをi分割して整列する場合の数
N-Kをi-1, i, i+1分割して整列する場合の数

dp i個まででj分割

*/


// #include <bits/stdc++.h>

// using namespace std;
// using llong = long long;
// using ldbl = long double;
// using lpair = pair<llong, llong>;

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

// const llong inf = 1100100100100100ll;
// const llong mod = 1e9+7;

// llong N, K;
// vector<vector<llong> > memo;

// llong dp(llong now, llong sep) {
// 	if (now == 0) return memo[now][sep] = sep == 0;
// 	if (sep == 0) return memo[now][sep] = 0;
// 	if (memo[now][sep] != -1) return memo[now][sep];

// 	return memo[now][sep] = (dp(now-1, sep) + dp(now-1, sep-1)) % mod;
// }

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

// 	memo.resize(N+1, vector<llong>(K+2, -1));
// 	for (int i = 0; i <= K+1; ++i)
// 		dp(N, i);

// 	for (int i = 1; i <= K; ++i) {
// 		llong b = memo[K][i];
// 		llong r = (memo[N-K][i-1] + memo[N-K][i]*2 + memo[N-K][i+1]) % mod;

// 		cout << b*r << endl;
// 	}

// 	return 0;
// }

Measured memory_bytes: 31744
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = long.Parse(spl[0]);
        var m     = long.Parse(spl[1]);
        var s = input.ReadLine();
        var t = input.ReadLine();

        //if(n > m) {
        //    var tmp = n;
        //    n = m;
        //    m = tmp;
        //}

        var y = Lcm(n, m);

        var dic = new DefaultDectionary<long, int>(0);

        for(int i = 0; i<n; i++) {
            var x = 1 + i * (y/n);
            dic[x] = s[i];
        }
        
        for(int i = 0; i<m; i++) {
            var x = 1 + i * (y/m);
            if(dic.ContainsKey(x) && dic[x] != t[i]) {
                return -1;
            }
        }

        return y;
    }

    static long Lcm(long m, long n) {
        var x1 = Math.Max(m, n);
        var x2 = Math.Min(m, n);

        var gcd = Gcd(x1, x2);
        return x1 / gcd * x2;
    }
    static long Gcd(long m, long n) {
        //ユークリッド互除法
        if (m < n) { var t = m; m = n; n = t; }

        while (true) {
            var mod = m % n;
            if (mod == 0) return n;
            m = n;
            n = mod;
        }
    }

    class DefaultDectionary<Tkey, TValue> : Dictionary<Tkey, TValue>
    {
        TValue DefaultValue;
        public DefaultDectionary(TValue defaultvalue) {
            this.DefaultValue = defaultvalue;
        }
        public new TValue this[Tkey key] {
            get {
                if (this.ContainsKey(key)) return base[key];
                else return DefaultValue;
            }
            set {
                base[key] = value;
            }
        }
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }

}


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

using namespace std;
int main()
{
    int n,k,q,i,j;
    cin>>n>>k>>q;
    int a[q],b[n];
    for(i=0; i<q; i++)
    {
        cin>>a[i];
    }
    for(i=0; i<n; i++)
    {
        b[i]=k-q;
    }

    if(k>q)
    {
        for(i=0; i<n; i++)
        {
            cout<<"Yes"<<endl;
        }
    }
    else
    {
        for(i=0; i<q; i++)
        {
            b[a[i]-1]++;
        }
        /*for(i=0; i<n; i++)
    {
        cout<<b[i]<<" ";
    }*/
        for(i=0;i<n;i++){
            if(b[i]>0){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
    }

}


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

int main(){
    int N, C;  cin >> N >> C;
    vector<vector<int>> D;
    D = vector<vector<int>>(C+1, vector<int>(C+1,0));
    for(int i=1; i<=C; i++) for(int j=1; j<=C; j++) cin >> D[i][j];

    vector<vector<int>> c;
    c = vector<vector<int>>(N+1, vector<int>(N+1,0));
    for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) cin >> c[i][j];

    vector<vector<int>> cnt;
    cnt = vector<vector<int>>(3, vector<int>(C+1,0));
    for(int i=1; i<=N; i++) for(int j=1; j<=N; j++){
        cnt[(i+j)%3][c[i][j]]++;
    }

    int ans = 1e9;
    int color[3];
    for(color[0]=1; color[0]<=C; color[0]++) for(color[1]=1; color[1]<=C; color[1]++) for(color[2]=1; color[2]<=C; color[2]++){
        if(color[0]==color[1] || color[1]==color[2] || color[2]==color[0]) continue;

        int d = 0;
        for(int i=0; i<3; i++) for(int j=1; j<=C; j++){
            d += D[j][color[i]]*cnt[i][j];
        }
        ans = min(d, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1280
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let a: Vec<u32> = (0..n).map(|_| sc.read()).collect();


    let mut xor_sum = 0;
    for &a in &a {
        xor_sum ^= a;
    }

    let mut ans = 0;
    for bit in (0..30).rev() {
        if ((1 << bit) & xor_sum) == 0 { continue; }
        let x = (1 << (bit + 1)) - 1;
        for &a in &a {
            let y = a ^ (a - 1);
            if y == x {
                xor_sum ^= y;
                ans += 1;
                break;
            }
        }
    }

    if xor_sum != 0 {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4352
from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re
import heapq


from copy import deepcopy
import itertools

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    s = input()
    day = ['SUN','MON','TUE','WED','THU','FRI','SAT']

    for i in range(len(day)):
        if day[i] == s:
            print(7-i)
            exit()
            




main()


Measured memory_bytes: 12492
package main

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

func main() {
	scanInit()

	n := nextInt()
	a := make([]int, n+1)

	cnt := 0
	run := 1

	a[0] = nextInt()
	prev := a[0]
	for i := 1; i < n; i++ {
		a[i] = nextInt()
	}
	a[n] = 999999
	for i := 1; i <= n; i++ {

		if prev == a[i] {
			run++
		} else {
			cnt += run / 2
			run = 1
		}
		prev = a[i]
	}

	fmt.Println(cnt)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
    int N;
    void Solve() {
        //input
        N = io.Int;
        //cal
        for (long h = 1; h <= 3500; ++h) {
            for (long n = 1; n <= 3500; ++n) {
                var top = N * h * n;
                var bot = 4 * h * n - N * n - N * h;
                if (bot > 0 && top % bot == 0) {
                    //ret
                    var ans = top / bot;
                    Console.WriteLine(h + " " + n + " " + ans);
                    return;
                }
            }
        }
    }

    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

vector<int> g[10001];
vector<bool> f(10001,false);
vector<LL> c;
vector<LL> ans(10001);
vector<int> dp(10001);
int s;

void dfs(int u,int k){
    if(f[u]) return ;
    int ret=0;
    for (int i = 0; i < g[u].size(); i++) {
        int nx = g[u][i];
        if(nx==k) continue;
        if(f[nx]) continue;
        dfs(nx,u);
    }
    if(g[u].size()-dp[u]<=1){
        f[u]=true;
        ans[u]=c[s++];
        for (int i = 0; i < g[u].size(); i++) {
            int nx = g[u][i];
            dp[nx]++;
        }
        return ;
    }
    return ;
}

int main(){
    int n;cin >> n;
    for (int i = 0; i < n-1; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    for (int i = 0; i < n; i++) {
        LL C;cin >> C;
        c.pb(C);
    }
    sort(ALL(c));
    for (int i = 0; i < n; i++) {
        dfs(i,i);
    }
    LL sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < g[i].size(); j++) {
            sum += min(ans[g[i][j]],ans[i]);
        }
    }
    cout << sum/2 << endl;
    for (int i = 0; i < n; i++) {
        cout << ans[i] << (i==n-1?"\n":" ");
    }
    return 0;
}


Measured memory_bytes: 1920
import queue
K=int(input())
que=queue.Queue()
for i in range(1,10):
    que.put(i)
cnt=0
while True:
    x=que.get()
    y=x%10
    cnt+=1
    if cnt==K:
        print(x)
        break
    if y==0:
        que.put(10*x)
        que.put(10*x+1)
    elif y==9:
        que.put(10*x+8)
        que.put(10*x+9)
    else:
        que.put(10*x+y-1)
        que.put(10*x+y)
        que.put(10*x+y+1)

Measured memory_bytes: 12452
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
//#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>

const int MAX_N = 100050;
const int MAX_Q = 100050;

int N, Q;
long long A[MAX_N];
long long X[MAX_Q];
long long ac[MAX_N] = {};
long long half_ac[MAX_N] = {};

int num_lesser(long long val) {
    if (val <= A[1]) {
        return 0;
    }
    if (A[N] < val) {
        return N;
    }
    int lb = 1;
    int ub = N;
    while (lb + 1 < ub) {
        int mid = (lb + ub) / 2;
        if (A[mid] < val) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    return lb;
}

long long cal_rad(long long center) {
    long long lb = 0;
    long long ub = A[N];
    while (lb + 1 < ub) {
        int mid = (lb + ub) / 2;
        if (num_lesser(center + mid) - num_lesser(center - mid) <= N - num_lesser(center + mid)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    return lb;
}

long long solve(long long center) {
    if (A[N-1] <= center) {
        return half_ac[N];
    }

    long long ret = 0;
    long long rad = cal_rad(center);

    //std::cout << "check:" << center << " " << rad << " " << num_lesser(center + rad) << " " << num_lesser(center - rad) << std::endl;

    int aoki_get_num = num_lesser(center + rad) - num_lesser(center - rad);
    int aoki_not_get_idx = num_lesser(center + rad) + 1;
    int takahashi_get_idx = N - aoki_get_num + 1;
    int half_begin = num_lesser(center - rad);

    //std::cout << rad << " " << aoki_get_num << " " << aoki_not_get_idx << " " << takahashi_get_idx << " " << half_begin << std::endl;

    if (aoki_not_get_idx < takahashi_get_idx) {
        takahashi_get_idx--;
        if (aoki_not_get_idx == takahashi_get_idx) {
            half_begin--;
        }
    }
    //assert(takahashi_get_idx == aoki_not_get_idx);
    half_begin = std::max(0, half_begin);
    return ac[N] - ac[takahashi_get_idx-1] + half_ac[half_begin];

}

int main(int argc, char **argv) {
    std::cin >> N >> Q;
    
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }

    for (int i = 1; i <= Q; i++) {
        std::cin >> X[i];
    }

    ac[1] = A[1];
    half_ac[1] = A[1];

    for (int i = 2; i <= N; i++) {
        ac[i] = ac[i-1] + A[i];
        half_ac[i] = half_ac[i-2] + A[i];
    }

    for (int i = 1; i <= Q; i++) {
        std::cout << solve(X[i]) << std::endl;
    }    

    return 0;
}


Measured memory_bytes: 4864
#include<stdio.h>
#include<math.h>

//http://www.ipsj.or.jp/07editj/promenade/4309.pdf
typedef struct { double x, y, z; } pos;
int n;
pos point[64];

double distance(pos a,pos b){
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}

double solve_by_movement(void){
  int k,i,t;
  pos p;
  double move,max;
  p.x=500.0;
  p.y=500.0;
  p.z=0.0;
  move=0.5;
  while(move>1.0e-8){
    for(t=0;t<100;t++){
    max=0.0;
    for(i=0;i<n;i++)
      if(distance(p,point[i])>max){
        max=distance(p, point[i]);
        k=i;
      }
      p.x+=(point[k].x-p.x)*move;
      p.y+=(point[k].y-p.y)*move;
      p.z+=(point[k].z-p.z)*move;
    }
    move=move/2.0;
  }
  return (max);
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf%lf",&point[i].x,&point[i].y);
    point[i].z=0.0;
  }
  printf("%.12lf\n",solve_by_movement());
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int K, Q; cin >> K >> Q;
    vector<int> D(K); for (auto &d : D) cin >> d;
    while (Q--) {
        int N, X, M; cin >> N >> X >> M;
        vector<int> E(K);
        for (int i = 0; i < K; i++) E[i] = D[i] % M;
        int ans = N - 1;
        int q = (N - 1) / K, r = (N - 1) % K;
        Int sum = X;
        for (int i = 0; i < K; i++) {
            if (i < r) {
                if (E[i] == 0) ans -= q + 1;
                sum += (Int)E[i] * (q + 1);
            } else {
                if (E[i] == 0) ans -= q;
                sum += (Int)E[i] * q;
            }
        }
        ans -= sum / M - X / M;
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=(n);i<(x);++i)
#define SORT(x) sort(x.begin(),x.end())
using ll = long long;

int main() {
	ll n; cin >> n;
	vector<ll> a(n); rep(i, 0, n) cin >> a[i];
	
	ll ans = 0;
	rep(i, 0, n) a[i] = a[i] - (i + 1);
	SORT(a);
	ll b = 0;
	if (n % 2) b = a[n / 2];
	else b = (a[n / 2 - 1] + a[n / 2]) / 2;
	rep(i, 0, n) ans += abs(a[i] - b);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define maxn 202333
using namespace std;
long long a[maxn];
int c2[maxn], c5[maxn]; // 50 20
int cnt[60][60];
long long Pow[233] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		long long fi, en;
		char tmp[233];
		int ty = scanf("%lld.%s", &fi, tmp);
		if(ty == 1) en = 0, a[i] = fi * 1000000000ll;
		else {
			sscanf(tmp, "%lld", &en);
			int len = strlen(tmp);
			a[i] = fi * 1000000000ll + en * Pow[9 - len];
		}
		while(a[i] % 2 == 0) a[i] /= 2, ++c2[i];
		while(a[i] % 5 == 0) a[i] /= 5, ++c5[i];
	}
	long long ans = 0;
	for(int _ = 1; _ <= n; ++_) {
		int C2 = c2[_], C5 = c5[_];
		if(C2 > 50) C2 = 50;
		if(C5 > 20) C5 = 20;
		for(int i = 18 - min(C2, 18); i <= 50; ++i) {
			for(int j = 18 - min(C5, 18); j <= 20; ++j) {
				ans += cnt[i][j];
			}
		}
		++cnt[C2][C5];
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 6816
var i,j,n,a,b:longint;
    m:int64;
    s,ss,st:string;
begin
  read(a,b);
  str(a,ss);str(b,st);
  s:=ss+st;
  val(s,n);
  for i:=1 to trunc(n/2)do
  begin
    m:=i*i;
    if m>n then break;
    if m=n then begin writeln('Yes');exit;end;
  end;
  writeln('No');
end.

Measured memory_bytes: 128
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_098_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(10).
    01 maxlen PIC 9(1)  VALUE 2.
    01 cur    PIC 9(2)  VALUE 1.
    01 i      PIC 9(18) VALUE 1.
    01 j      PIC 9(18).
    01 len    PIC 9(2).
    01 ans    PIC -(8)9.
    01 AB1.
        03 AB11 OCCURS 2.
            05 AB PIC S9(8).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO AB(i)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    MOVE FUNCTION MAX(
         AB(1) + AB(2),AB(1) - AB(2),AB(1) * AB(2)) TO ans.

    DISPLAY ans.
    STOP RUN.


Measured memory_bytes: 1144
Q = int(input())

def pri(N):
  x = (N + 1) // 2
  root = int(N ** (1/ 2))
  for i in range(2, root + 1):
    if N % i == 0:
      return 0
    if (x > i) and (x % i == 0):
      return 0
  return 1
  
prime = [0] * (10 ** 5)# 0 ~ 10 ** 5 - 1, prime[1] = 0
for i in range(3, 10 ** 5):
  if i % 2 == 1:
    add = pri(i)
    prime[i] = prime[i - 2] + add
    
for i in range(Q):
  l, r = map(int, input().split())
  if l == 1:
    minus = 0
  else:
    minus = prime[l - 2]
  print(prime[r] - minus)
  #print(prime[r] - minus, prime[r], minus)
#print(prime[:15])
#print(pri(7))

Measured memory_bytes: 52060
#include<stdio.h>
int main(void) {
  int n,k,x,y;
  printf("");	scanf("%d", &n);
  printf("");	scanf("%d", &k);
  printf("");	scanf("%d", &x);
  printf("");	scanf("%d", &y);
  if(n > k) {
  printf("%d",k * x + (n - k) * y);
  }
  else {
  	printf("%d", n * x);
  }
 return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  cout << endl;
  for(int i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


int main(){
  string s;
  cin >> s;

  int wa = 0;
  for(int i=0; i<(int)s.size(); i++){
    wa += s[i] - '0';
  }

  if(wa % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  


  return 0;
}


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

using namespace std;


int main(){
    string s;cin >> s;
    int A = 0,B = 0;
    for(int a = 0;a < s.size();a++){
        if(a%2 == 0 && s.at(a) == '1'){
            A++;
        }
        if(a%2 == 1 && s.at(a) == '0'){
            
            A++;
        }
        if(a%2 == 0 && s.at(a) == '0'){
            B++;
        }
        if(a%2 == 1 && s.at(a) == '1'){
            
            B++;
        }
    }
    cout<<min(A,B)<<endl;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(r.readLine());

        String[] strArray = r.readLine().split(" ");
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(strArray[i]);
        }
        Arrays.sort(arr);

        int q = Integer.parseInt(r.readLine());
        String[] strArray2 = r.readLine().split(" ");
        int [] searchArray = new int[q];
        for (int i = 0; i < q; i++) {
            searchArray[i] = Integer.parseInt(strArray2[i]);
        }

        int count = 0;
        for (int searchNum : searchArray) {
            if (binarySearch(arr, searchNum)) {
                count++;
            }
        }

        System.out.println(count);
    }

    private static boolean binarySearch(int[] arr, int searchNum) {
        int half = arr.length / 2;
        if (arr[half] == searchNum) {
            return true;
        } else if (arr.length <= 1) {
            return false;
        } else if (arr[half] > searchNum) {
            int[] left = Arrays.copyOfRange(arr, 0, half);
            return binarySearch(left, searchNum);
        } else {
            int[] right = Arrays.copyOfRange(arr, half, arr.length);
            return binarySearch(right, searchNum);
        }
    }
}

Measured memory_bytes: 32380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,Q;
    cin >> A >> B >> Q;
    vl s, t;
    s.emplace_back(-LINF);
    rep(i,A){
        ll d;cin >> d;
        s.emplace_back(d);
    }
    s.emplace_back(LINF);
    t.emplace_back(-LINF);
    rep(i,B){
        ll d;cin >> d;
        t.emplace_back(d);
    }
    t.emplace_back(LINF);
    rep(i,Q){
        ll x;cin >> x;
        auto s2 = lower_bound(s.begin(),s.end(),x);
        auto s1 = s2;
        --s1;
        auto t2 = lower_bound(t.begin(),t.end(),x);
        auto t1 = t2;
        --t1;

        ll ans = min({abs(x - *s1) + abs(*s1 - *t1), abs(x - *t1) + abs(*t1 - *s1), abs(x - *s1) + abs(*s1 - *t2), abs(x - *t2) + abs(*t2 - *s1),
                    abs(x - *s2) + abs(*s2 - *t1), abs(x - *t1) + abs(*t1 - *s2), abs(x - *s2) + abs(*s2 - *t2), abs(x - *t2) + abs(*t2 - *s2)});
        /*chmin(ans, abs(x - *s1) + abs(*s1 - *t1));
        chmin(ans, abs(x - *t1) + abs(*t1 - *s1));
        chmin(ans, abs(x - *s1) + abs(*s1 - *t2));
        chmin(ans, abs(x - *t2) + abs(*t2 - *s1));
        chmin(ans, abs(x - *s2) + abs(*s2 - *t1));
        chmin(ans, abs(x - *t1) + abs(*t1 - *s2));
        chmin(ans, abs(x - *s2) + abs(*s2 - *t2));
        chmin(ans, abs(x - *t2) + abs(*t2 - *s2));*/
        printf("%lld\n", ans);
    }
}

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

int main(){
  string s;
  cin >> s;
  
  ll ans = 0,curr = 0;
  for(int i = 0; i < 3; i++){
  	if(s[i] == 'R'){
    	curr++;
    }
    else{
    	ans= max(ans,curr);
	curr = 0;
    }
  }
  ans = max(ans,curr);
  cout << ans << "\n";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
	int h,n;
  cin>>h>>n;
  int total;
  for ( int i=0;i<n;i++){
int aa;
    cin>>aa;
    total+=aa;
  }
  if ( total>=h)
    cout<<"Yes\n";
  else
    cout<<"No\n";

}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: i32,
        m: i32,
        a: [i32; m],
    }
    let sum = a.into_iter().fold(0, |sum, x| sum + x);
    println!("{}", if n >= sum { n - sum } else { -1 });
}


Measured memory_bytes: 2132
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { r: number } => {
  const r = +lines[0]
  const obj = { r }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { r } = parseLines(lines)
  return `${3 * r ** 2}`

}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


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

LL repsqrt(LL n, LL p){
    if(p == 0){
        return 1;
    }else if(p % 2 == 0){
        LL t = repsqrt(n, p / 2);
        return (t * t);
    }else{
        return n * repsqrt(n, p - 1);
    }
}

int main(){
    long double L;
    cin >> L;
    cout << fixed << setprecision(16) << repsqrt(L,3) / 27.0 << endl;

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<bool> ok(101, false);
  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++) ok[i * j] = true;
  }
  if(ok[n]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3640
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, m) = input!(usize, usize);
    let mut ss: Vec<Vec<usize>> = vec![];

    for _ in 0..m {
        let mut k = invec!(usize);
        ss.push(k);
    }

    let ps = invec!(u8);

    let mut pattern_count = 0;
    for s in 0..1 << n {
        let mut all = true;
        for j in 0..m {
            let mut count = 0;
            for &connected in ss[j].iter().skip(1) {
                // println!("{}: j = {},  {}",s,j, 1 << connected);
                if (1 << (connected - 1)) & s > 0 {
                    count += 1;
                }
            }
            if count % 2 != ps[j] {
                all = false;
            }
        }

        if all {
            pattern_count += 1;
        }
    }

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

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
int A[100010];
int cnt[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    cnt[A[i]]++;
  }  
  int tmp = 0, ans = 0;
  for (int i = 0; i < 100010; i++) {
    if (cnt[i] == 0) continue;
    if (cnt[i] % 2 == 0) tmp++;
    ans++;
  }
  cout << ans - (tmp % 2 == 1) << endl;

  return 0;
}

Measured memory_bytes: 1024
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int t,i;(t=s.nextInt()+1)>1;){long[]x=new long[t+1];for(i=t;i-->1;)x[i]=s.nextInt();for(Arrays.sort(x);i<t-2;)x[0]+=(x[++i+1]+=x[i]);System.out.println(x[0]);}}}

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

using namespace std;

int N;
set<int> UserA, UserB;

bool solve() {
	int cnt, left, right;

	cnt = 1;
	left = 6;
	right = 8;
	while (true) {
		if (UserA.find(left) != UserA.end() && UserA.find(right) != UserA.end()) {
			if (UserA.find(13) != UserA.end()) {
				UserA.erase(right);
				++right;
			}
			else {
				UserA.erase(left);
				--left;
			}
		}
		else if (UserA.find(left) != UserA.end()) {
			UserA.erase(left);
			--left;
		}
		else if (UserA.find(right) != UserA.end()) {
			UserA.erase(right);
			++right;
		}

		if (UserA.empty()) {
			break;
		}
		++cnt;
		swap(UserA, UserB);
	}

	if ((cnt & 1) == 1) {
		return true;
	}
	return false;
}

int main() {
	int num;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		UserA.clear();
		UserB.clear();
		for (int j = 0; j < 6; ++j) {
			cin >> num;
			UserA.insert(num);
		}
		for (int i = 1; i < 14; ++i) {
			if (i == 7 || UserA.find(i) != UserA.end()) {
				continue;
			}
			UserB.insert(i);
		}
		if (solve()) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3084
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.IllegalArgumentException
import java.lang.StringBuilder
import java.lang.reflect.Modifier
import java.util.*

// ModInt
// region
class ModInt(x: Long) {

    companion object {
        const val MOD = 1000000007L
        //const val MOD = 998244353L
    }

    val x = (x % MOD + MOD) % MOD

    operator fun plus(other: ModInt): ModInt {
        return ModInt(x + other.x)
    }

    operator fun minus(other: ModInt): ModInt {
        return ModInt(x - other.x)
    }

    operator fun times(other: ModInt): ModInt {
        return ModInt(x * other.x)
    }

    operator fun div(other: ModInt): ModInt {
        return this * other.inv()
    }

    fun pow(exp: Long): ModInt {
        if (exp == 0L) return ModInt(1L)
        var a = pow(exp shr 1)
        a *= a
        if (exp and 1L == 0L) return a
        return this * a
    }

    fun inv(): ModInt {
        return this.pow(MOD - 2)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ModInt

        if (x != other.x) return false

        return true
    }

    override fun hashCode(): Int {
        return x.hashCode()
    }

    override fun toString(): String {
        return "$x"
    }

}

val fac = mutableListOf<ModInt>()
val invfac = mutableListOf<ModInt>()

fun fact(n: Long, b: Boolean): ModInt {
    if (fac.count() == 0) {
        fac.add(ModInt(1))
        invfac.add(ModInt(1))
    }
    while (fac.count() <= n) {
        fac.add(fac.last() * ModInt(fac.count().toLong()))
        invfac.add(fac.last().inv())
    }
    return if (b) {
        fac[n.toInt()]
    } else {
        invfac[n.toInt()]
    }
}

fun comb(n: Long, k: Long): ModInt {
    return fact(n, true) * fact(k, false) * fact(n - k, false)
}

fun comb2(n: Long, k: Long): ModInt {
    var ans = ModInt(1)
    for (i in 0 until k) {
        ans = ans * ModInt(n - i) / ModInt(k - i)
    }
    return ans
}
// endregion

fun PrintWriter.solve(sc: FastScanner) {
    val k = sc.nextInt()
    val s = sc.nextLine()
    val n = s.length
    var ans = ModInt(0)
    val a = Array(k + 1) { ModInt(1) }
    for (i in 0 until k) {
        a[i + 1] = a[i] * ModInt(25L * (n + i)) / ModInt(i + 1L)
    }
    var pow = ModInt(1)
    for (i in 0..k) {
        ans += a[k - i] * pow
        pow *= ModInt(26)
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 99232
def main():
    N, W = map(int, input().split())
    dp = [[0] * (W + 1) for _ in range(2)]
    ws, vs = [], []
    for _ in range(N):
        w, v = map(int, input().split())
        ws.append(w)
        vs.append(v)

    for i in range(N):
        now_i, next_i = i & 1, (i+1) & 1
        for j in range(W+1):
            if j - ws[i] >= 0:
                dp[next_i][j] = max(dp[now_i][j], dp[now_i][j-ws[i]] + vs[i])
            else:
                dp[next_i][j] = dp[now_i][j]
    print(max(dp[N & 1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 42992
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n,m;
    cin >> n >> m;

    vector<pair<ll,int>> ab(n);
    for(auto &x:ab)cin >> x.first >> x.second;
    sort(ab.begin(),ab.end());

    ll ans=0;
    int buy=m,count=0;
    while(buy!=0){
        if(buy>=ab[count].second){
            ans+=ab[count].first*ab[count].second;
            buy-=ab[count].second;
        }else{
            ans+=ab[count].first*buy;
            buy=0;
        }
        count++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4764
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
 
typedef pair<string,int> P;
 
int n;
string str[11];
string INF;
 
map<P,string> m;

int check(string s){
  int ret = 0;
  for(int i = 0; i < n; i++){
    if((int)s.find(str[i]) != -1){
      ret |= 1<<i; 
    }
  }
  return ret;
}

string solve(string sss,int used){
  if(m[P(sss,used)] != "") return m[P(sss,used)];
 
  if(used == (1<<n)-1) return "";
 
  string ret = INF;
  string temp = "";
  int c;
 
  for(int i = 0; i < n; i++){
    if( (used & 1<<i) == 0){
      /*
	if((int)sss.find(str[i]) != -1){
	//ret = min(ret, solve(sss,used|1<<i));
	temp = sss + solve(sss,used|1<<i);
	ret = (ret.size() < temp.size())?ret:temp;
	}else{
      */
      for(int j = 1; j < (int)(min(sss.size(),str[i].size()));j++){
	if(sss.substr(sss.size() - j) == str[i].substr(0,j)){
	  //ret = min(ret, solve(sss + str[i].substr(j),used|1<<i) + (int)str[i].size() - j);

	  string t = sss + str[i].substr(j);
	  c = check(t);
	  temp = str[i].substr(j) + solve(t.substr(max((int)t.size()-10,0)),(used|1<<i)|c);
	  if(ret.size() == temp.size()){
	    ret = (ret < temp)?ret:temp;
	  }else{
	    ret = (ret.size() < temp.size())?ret:temp;
	  }
	}
      }
      //ret = min(ret, solve(sss + str[i],used|1<<i) + (int)str[i].size());

      string t = sss + str[i];
      c = check(t);
      temp = str[i] + solve(t.substr(max((int)t.size()-10,0)),(used|1<<i)|c);	  
      if(ret.size() == temp.size()){
	ret = (ret < temp)?ret:temp;
      }else{
	ret = (ret.size() < temp.size())?ret:temp;
      }
      //}
    }
  }
  //cout<< ret << endl;
  return m[P(sss,used)] = ret;
  //return m[P(sss,used)] = ret.substr((int)sss.size());
}
 
int main(void)
{
  for(int i = 0;i < 111; i++) INF += "A";
 
  while(1){
    cin >> n;
    if(!n)break;
    for(int i = 0; i < n; i++){
      cin >> str[i];
    }
    map<P,string> a;
    m = a;
 
    cout << solve("",0) << endl;
  }
}

Measured memory_bytes: 8352
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

ll gcd(ll x , ll y){
    if(y==0)return x;
    return gcd(y,x%y);
}

ll lcm(ll x, ll y){
    ll g = gcd(x,y);
    return x/g*y;
}

ll lcm(vector<ll> a){
    ll lc = 1;
    rep(i,a.size()){
        lc = lcm(lc,a[i]);
    }
    return lc;
}

// ll gcd(vector<ll> a){
//     ll c = a[0];
//     rep(i,a.size()){
//         c = gcd(c,a[i]);
//     }
//     return c;
// }


int main(){
    int n;cin >> n;
    vector<ll> t(n);
    rep(i,n)cin>>t[i];
    cout << lcm(t) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
 
using namespace std;
 
string a, b;
int tab[3005][3005];


int lcs(int i, int j)
{
	if(i < 0 || j < 0)
	{
		return 0;
	}
	if(tab[i][j] >= 0)
		return tab[i][j];

	if(a[i] == b[j])
	{
		return tab[i][j] = 1 + lcs(i-1, j-1);
	}

	return tab[i][j] = max(lcs(i, j-1), lcs(i-1, j));
}

string percorre(int i, int j)
{
	string nome = "";
	if(i < 0 || j < 0)
	{
		return "";
	}
	
	if(a[i] == b[j])
	{
		return percorre(i-1, j-1) + a[i];
	}

	if(i > 0 && tab[i][j] == tab[i-1][j])
	{
		nome += percorre(i-1, j);
	}
	else if(j > 0 && tab[i][j] == tab[i][j-1])
	{
		nome += percorre(i, j-1);
	}

	return nome;
}

	
int main()
{
 
	
	memset(tab, -1, sizeof(tab));
	cin >> a >> b;

	int tama = (int)a.size() - 1;
	int tamb = (int)b.size() - 1;

	int aksa = lcs(tama, tamb);
 	cout << percorre(tama, tamb) << endl;
 
 
    return 0;
}

Measured memory_bytes: 39724
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl "\n"
#define debug(x)  cout<<#x<<" " <<x<<endl;
#define dbg(x,y)  cout<<#x<<" " <<x<<" "<<#y<<" "<<y<<endl;
#define all(v) v.begin(),v.end()
#define si(x) x.size()

const int e = 100005;
const ll INF = 1e18+5;
template<typename T>void show2(T& dp)
{
    for( auto row:dp)
    {
        for(auto col:row)
            cout<<col<<" ";
        cout<<endl;
    }
}
template<typename T>void show1(T &a)
{
    for(auto x:a)
        cout<<x<<" ";
    cout<<endl;
}
void solve()
{
    int n,m;
    cin>>n>>m;
    vi a(n);
    ll s=0;
    loop(i,0,n)
    {
        cin>>a[i];
        s+=a[i];
    }
    sort(all(a));
    reverse(all(a));
   // cout<<a[m-1];
    double x= (double)s/4.0;
    x=x/(double)m;
    if(a[m-1]>=x)
    cout<<"Yes";
    else
    cout<<"No";
}
int main() {
	// your code goes here
	io;

    solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lp(i,n) for(int i=0;i<n;i++)
using namespace std;
int q(int n){
  if(n <= 6) return n+1;
  else return n-5;
}
int ccd(string s){
  int sum = 0;
  for(int i = 11; i >= 1; i--){
    int a = s[11-i]-48;
    sum += q(i)*a;
  }
  int ret = 11-(sum % 11);
  if(sum%11 <= 1)ret = 0;
  return ret;
}
int main(){
  string s,a,b;
  int c = 0;
  cin >> s;
  a = "";
  b = "";
  for(int i = 0; s[i] != '?'; i++){
    c++;
    a = a + s[i];
  }
  for(int i = c+1; i <= 11; i++){
    b = b + s[i];
  }
  int ans;
  int cnt =0;
  if(c !=11){
    for(int i = 0; i <= 9; i++){
      string t = a+to_string(i)+b;
      if(ccd(t) == t[11]-48){
	ans = i;
	cnt++;
      }
    }
    if(cnt != 1) cout << "MULTIPLE" << endl;
    else cout << ans << endl;
  }
  else cout << ccd(a)<< endl;
  return 0;
}



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

int main() {
  int A,B;
  cin >> A >> B;
  int x = 0;
  for(int i = A;i <= B;i++){
    int p = i /10000 + i / 1000 % 10 * 10; 
    int q = i % 100;
    if(p == q){
      x ++;}
}
  cout << x << endl;
}


Measured memory_bytes: 256
S = input() + "R"
N = len(S)
st = 0
ans = [0]*(N-1)
for i in range(N - 1):
    if S[i: i + 2] == "RL":
        for j in range(st, N-1):
            if S[j: j + 2] == "LR":
                if (i-st+1)%2 == 1:
                    ans[i] = (j-st+1+1)//2
                else:
                    ans[i] = (j-st+1)//2
                ans[i+1] = (j-st+1) - ans[i]
                st = j+1
                break
print(" ".join(map(str,ans)))

Measured memory_bytes: 10484
function Main(input) {
    input = input.split("\n");
    var R = parseInt(input[0], 10);
    var G = parseInt(input[1], 10);
    console.log(G*2-R);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));




// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
	var input = document.getElementById("input").value;
	Main(input);
}

Measured memory_bytes: 17228
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
#include <iomanip> 
#include <algorithm>
#include <queue>
#include <list>
#include <numeric>
#include <stack>
#include <unordered_map>
#include <map>
#include <set>

using namespace std;

#define sz(a) int((a).size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define watch(x) cout << #x << " : " << x << endl;

#define FastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

const int N = int(2e5)+10;
const int K = int(2e6)+10;
const int MOD = int(1e9)+7;
const int INF = int(1e9)+5;
const ll INF64 = 2e18;

ll a[N];

void solve () {
    int n;cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n);
    ll ans = a[n];
    int j = n-1;
    for (int i=n-2;i>0;) {
        ans += a[j];
        i--;
        if (i > 0) ans += a[j];
        i--;
        j--;
    }
    cout<<ans<<endl;
}

int main () {
    FastIO
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int t;
    // cin>>t;
    t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

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

int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	ll cntR = 0, cntB = 0, cntG = 0;
	rep(i,N)
	{
		if (S[i] == 'R') cntR++;
		else if (S[i] == 'B') cntB++;
		else cntG++;
	}
	ll ans = cntR * cntG * cntB;
	int i = 1, j = 0;
	while(2*i+1 <= N)
	{
		j = 0;
		while(j + 2*i < N)
		{
			//cout << i << " " << j << endl;
			if (S[j] != S[j+i] && S[j+i] != S[j+i+i] && S[j] != S[j+i+i]) ans--;
			j++;
		}
		i++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>

using namespace std;

inline int getArea(int x1, int y1, int x2, int y2, int x3, int y3) {
    return abs((x1-x2)*(y3-y2)-(x3-x2)*(y1-y2));
}
inline int H(int x, int y) {
    return x + y * 10000;
}
inline int X(int v) {
    return v % 10000;
}
inline int Y(int v) {
    return v / 10000;
}

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

    int n;
    while (cin >> n, n) {
        vector<int> co(n);
        int x, y;
        for (int i=0; i<n; ++i) {
            cin >> x >> y;
            co[i] = H(x, y);
        }
        sort(co.begin(), co.end());

        int area = 0;
        for (int i=0; i<(int)co.size(); ++i) {
            for (int j=i+1; j<(int)co.size(); ++j) {
                int dx, dy, x3, y3, x4, y4;
                dx = X(co[j]) - X(co[i]);
                dy = Y(co[j]) - Y(co[i]);
                x3 = X(co[j]) - dy;
                y3 = Y(co[j]) + dx;
                x4 = X(co[i]) - dy;
                y4 = Y(co[i]) + dx;
                if (binary_search(co.begin(), co.end(), H(x3, y3)) && binary_search(co.begin(), co.end(), H(x4, y4))) {
                    area = max(area, getArea(X(co[i]), Y(co[i]), X(co[j]), Y(co[j]), x3, y3));
                }
            }
        }
        cout << area << endl;
    }
    return 0;
}

Measured memory_bytes: 1228