akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ull = unsigned long long;
using P = pair<int, int>;


ull E = 1000000007;
ull e = 10007;
const double pi = 3.14159265359;

int main() {
    ull N, K;
    cin >> N >> K;
    vector<ull> h;
    for (ull i = 0; i < N; ++i) {
        ull tmp;
        cin >> tmp;
        h.push_back(tmp);
    }
    ull ans = 9999999999;
    sort(h.begin(), h.end());
    for (ull i = 0; i + K - 1 < N; ++i) {
        ans = min(ans, h[i + K - 1] - h[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1400
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  ll T[N],A[N];
  for(int i=0;i<N;i++) cin >> T[i] >> A[i];

  ll t,a;
  t = T[0];
  a = A[0];
  for(int i=1;i<N;i++){
    //cout << "t = " << t << "  a = " << a << endl;
    ll ttmp , atmp;
    if(t % T[i] == 0){
      ttmp = t;
      atmp = t / T[i] * A[i];
    } else {
      ttmp = T[i] * (t / T[i] + 1);
      atmp = A[i] * (t / T[i] + 1);
    }

    if(atmp >= a){
      t = ttmp;
      a = atmp;
      continue;
    }

    if(a % A[i] == 0){
      t = a / A[i] * T[i];
    } else {
      a = A[i] * (a / A[i] + 1);
      t = a / A[i] * T[i];
    }
  }

  cout << t + a << endl;
  return 0;
}

Measured memory_bytes: 256
/*=======================
Author    : Shounak Dey
Filename  : d.cpp
=======================	*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define PB push_back
#define MK make_pair 
#define SZ(a) (int)(sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define read(n) scanf("%d",&n)
#define readl(n) scanf("%lld",&n)
#define readul(n) scanf("%llu",&n);


#define SORTV(a) sort(a.begin(),a.end())
#define TEST int Test;cin >> Test;while(Test--)
#define gcd(a,b) __gcd(a,b)
#define ffs(a) __builtin_ffs(a) // find first set
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)


#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

vector<string> split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c))
		v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

int main()
{
	fast_io;
	string a,b;
	cin >> a >> b;
	cout << b << a << endl;
	return 0;
}



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


int main() {
  int m; cin >> m;
  int ans = 0;
  while(true){
    ans++;
    if(m == 4 || m == 2 || m == 1) break;
    if(m%2==0) m /= 2;
    else m = 3*m+1;
  }
  cout << ans+3 << endl;
}


Measured memory_bytes: 3608
N = int(input())

def dfs(s, mx):
    if len(s) == N:
        print(s)
        return
    for c in 'abcdefghij'[:(ord(mx)-ord('a'))+1]:
        dfs(s+c, chr(ord(mx)+1)) if c == mx else dfs(s+c, mx)

dfs('', 'a')

Measured memory_bytes: 57432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}


typedef struct
{
    ll w,val;
} node;

ll n,k,mx;

vector<node>v;

ll dp[110][100010];

ll call(ll i,ll w,ll val)
{
    if(val<=0)return 0;

    if(i==n)
        return 1e18;


    if(~dp[i][val]==0)
    dp[i][val]=min(call(i+1,w,val),v[i].w+call(i+1,w,val-v[i].val));

    return dp[i][val];

}



int main()
{

    fastread();

    ll i,j,m,p,a,sum=0,t,b,c,d,cnt=0,q,l,r;


    string str;

    bool flag=true;

    cin>>n>>k;

    memset(dp,-1,sizeof(dp));



    for(i=0; i<n; i++)
    {
        cin>>a>>b;

        v.eb(node{a,b});

        sum+=b;
    }


    for(i=sum; i>=0; i--)
    {

        if(call(0,0,i)<=k)
        {
            cout<<i<<endl;

            return 0;
        }
    }





}


Measured memory_bytes: 89588
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <limits>
#include <queue>

double estimate(const int n, const std::vector<std::pair<int,int>> edge_forward, const std::vector<int> edge_forward_index, const std::vector<double> cost_c, int node, int close)
{
    std::vector<double> cost(cost_c.size());
    std::copy(cost_c.begin(), cost_c.end(), cost.begin());
    double cost_min = std::numeric_limits<double>::max();

    for (int i = node; i >= 0; i--) {
        int len = edge_forward_index[i + 1] - edge_forward_index[i];
        if (len == 1) {
            // 1経路しかないのでそのまま
            cost[i] = cost[edge_forward[edge_forward_index[i]].second] + 1;
            continue;
        }
        // 2経路以上ある
        if (close == 0) { // もう閉められない
            for (int j = 0; j < len; j++) {
                int ptr = edge_forward_index[i] + j;
                cost[i] += cost[edge_forward[ptr].second] + 1;
            }
            cost[i] /= len;
        } else {
            // どの扉を閉めるか判定をする
            std::vector<double> expected(len);
            for (int j = 0; j < len; j++) {
                int ptr = edge_forward_index[i] + j;
                expected[j] = cost[edge_forward[ptr].second] + 1;
            }
            // 昇順ソート
            std::sort(expected.begin(), expected.end(), std::less<double>());

            // 一番期待値が悪い通路を塞ぐ場合の値を計算
            double sum = 0;
            for (int j = 0; j < len; j++) {
                sum += expected[j];
            }
            double cost_close = (sum - expected[len - 1]) / (len - 1);
            double cost_open  =  sum                      /  len     ;

            cost[i] = cost_close;
            double a = estimate(n, edge_forward, edge_forward_index, cost, i - 1, close - 1);
            cost_min = std::min(cost_min, a);

            cost[i] = cost_open;
        }
    }
    return std::min(cost_min, cost[0]);
}

int main(int argc, char *argv[])
{
    int n, m;
    std::vector<std::pair<int,int>> edge_forward;
    std::vector<double> cost;
    std::vector<int> edge_forward_index;
    double ans;

    std::cin >> n >> m;

    edge_forward.reserve(m);

    for (int i = 0; i < m; i++) {
        int s, t;
        std::cin >> s >> t;
        edge_forward.push_back(std::make_pair(s - 1, t - 1));
    }

    // 一つ目の要素で昇順ソート
    std::sort(edge_forward.begin(), edge_forward.end(),
      [](const std::pair<int,int>& x, const std::pair<int,int>& y){return x.first < y.first;});

    // インデックスの作成
    edge_forward_index.resize(n);
    edge_forward_index[0] = 0;
    for (int i = 1, ptr = 0; i < n; i++) {
        while(edge_forward[ptr].first < i) {ptr++;}
        edge_forward_index[i] = ptr;
    }
    edge_forward_index[n - 1] = m;

    // 初期化
    cost.resize(n);
    std::fill(cost.begin(), cost.end(), 0);

    ans = estimate(n, edge_forward, edge_forward_index, cost, n - 2, 1);

    std::cout << std::setprecision(16) << ans << std::endl;

    return 0;
}


Measured memory_bytes: 4484
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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

    if ( a > b ) {
        cout << 0 << endl;
        return 0;
    }

    if ( n == 1 && a != b ) {
        cout << 0 << endl;
        return 0;
    }

    if ( n == 1 && a == b ) {
        cout << 1 << endl;
        return 0;
    }

    cout << a + ( n - 1 ) * b - ( ( n - 1 ) * a + b ) + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        N: usize,
        X: usize,
        L: [usize; N],
    }
    let mut D = vec![0; N+1];
    let mut cnt = 0;
    for i in 0..N {
        D[i+1] = D[i] + L[i];
    }
    for i in 0..N+1 {
        if D[i] <= X {
            cnt += 1;
        }
    }

    println!("{:?}", cnt);
}



Measured memory_bytes: 4352
s = gets.chomp
t = "keyence"
head = 0
tail = 0
for i in 0...7 do
  if s[i] == t[i]
    head += 1
  else
    break
  end
end
for i in 0...7 do
  if s[-1 - i] == t[-1 - i]
    tail += 1
  else
    break
  end
end
puts (head + tail >= 7) ? "YES" : "NO"


Measured memory_bytes: 1788
package main

import (
	"fmt"
)

func main() {
	var k, a, b int64
	fmt.Scan(&k)
	fmt.Scan(&a, &b)
	for i := a; i <= b; i++ {
		if i % k == 0 {
			fmt.Println("OK")
			return 
		}
	}
	fmt.Println("NG")
}


Measured memory_bytes: 1752
// Aizu Vol-2 0259: All Numbers Lead to 6174
// 2017.8.6

#include <stdio.h>
#include <string.h>

char *gets();
char buf[50], *p;
char max[4], min[4];

int t[10];

void dec(void)
{
	int i, ca = 0;
	for (i = 3; i >= 0; i--) {
		if (max[i] >= min[i] + ca) buf[i] = max[i] - min[i] - ca, ca = 0;
		else buf[i] = 10 + max[i] - min[i] - ca, ca = 1;
	}
}

int main()
{
	int i, j, k, ans;

	while (1) {
		gets(p = buf);
		if (!strncmp(p, "0000", 4)) break;
		if (!strncmp(p, "6174", 4)) { puts("0"); continue; }
		memset(t, 0, sizeof(t));
		for (i = 0; i < 4; i++) t[*p++ - '0']++;
		for (i = 0; i < 10; i++) if (t[i] == 4) { puts("NA");  goto Next; }

		ans = 0;
		while (1) {
			ans++;
			for (i = 9, j = 0; j < 4; i--) {
				if (t[i] > 0) {
					for (k = 0; k < t[i]; k++) max[j++] = i;
				}
			}
			for (i = 0, j = 0; j < 4; i++) {
				if (t[i] > 0) {
					for (k = 0; k < t[i]; k++) min[j++] = i;
				}
			}
			dec();
			if (buf[0] == 6 && buf[1] == 1 && buf[2] == 7 && buf[3] == 4) break;
			memset(t, 0, sizeof(t));
			for (i = 0; i < 4; i++) t[buf[i]]++;
		}
		printf("%d\n", ans);
	Next:;
	}
	return 0;
}

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

using namespace std;
int n,a[222222],k,l=1,r,ans;
bool check(int x){
    for(int i=1,ret=0; i<=n; i++){
        ret += (a[i]-1)/x;
        if(ret > k) return false;
    } return true;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n>>k;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        r = max(r,a[i]);
    }
    while(l <= r){
        int mid = l+r>>1;
        check(mid) ? r=mid-1,ans=mid: l = mid + 1;
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 4344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC108
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());
            int ans = k / 2;
            ans *= k % 2 == 1 ? k / 2 + 1 : k / 2;
            Console.WriteLine(ans);
        }
    }
}


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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  if (S=="SUN") ans = 7;
  else if (S=="MON") ans = 6;
  else if (S=="TUE") ans = 5;
  else if (S=="WED") ans = 4;
  else if (S=="THU") ans = 3;
  else if (S=="FRI") ans = 2;
  else ans = 1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
char in[210000];
char ans[210000];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	scanf("%s",in);
	int at=0;
	int ch=0;int cn=0;
	for(int i=0;i<b;i++){
		int q=(at+in[at]-'A')%2;
cn++;
		if(q==0&&ch==0){
			ch=1;
			continue;
		}
		at++;ch=0;
		if(at==a)break;
	}
	for(int i=at;i<a;i++){
		ans[i-at]=in[i];
		if(at%2){
			if(ans[i-at]=='A')ans[i-at]='B';
			else ans[i-at]='A';
		}
	}
	if(ch==1)ans[0]='B';
	for(int i=0;i<at;i++){
		ans[a-1-i]='A'+(i%2);
	}
if(cn<b&&b%2!=cn%2&&ans[0]=='A')ans[0]='B';
	printf("%s\n",ans);
}

Measured memory_bytes: 768
# -*- coding: utf-8 -*-
A = []
B = []
N, M = list(map(int, input().split()))

for n in range(N):
    A.append(input())
for n in range(M):
    B.append(input())

def match(r, c):
    for i, row in enumerate(range(r, r+M)):
#        print("{} : {}  {}".format(A[row][c:c+M], B[i], A[row][c:c+M]==B[i]))
        if A[row][c:c+M] != B[i]:
            return False
    return True

ok = 0

for r in range(N-M+1):
    if ok == 1:
        break
    else:
        for c in range(N-M+1):
            if match(r, c):
                print("Yes")
                ok = 1
                break
            
if not ok:
    print("No")

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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for(ll i = 0 ; i<n ; i++) 
#define rep2(n) for(ll j=0 ; j<n ; ++j )
#define repd(n) for(ll i = n-1 ; i>=0 ; i--)
#define MOD 1000000007
#define pii pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define INF 1e18
#define sz(a) (ll)a.size() 
#define all(a) a.begin(),a.end()
#define M 998244353
#define limit 100000000

void solve(ll t) {
	ll n; cin >> n ;
	
	ll sm =0 ;
	for(ll i=1;i<=n;++i) {
		for(ll j=1;j<=n;++j) {
			for(ll k=1;k<=n;++k) {
				sm += __gcd(__gcd(i,j),k);
			}
		}
	}
	cout << sm ;
}

int main() {


    fast;
	ll t=1;
	// cin>>t;
	rep(t) {
		solve(i+1) ;
	}
	return 0;
}

Measured memory_bytes: 3612
#

import sys
from math import ceil
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    sumA=sum(A)
    K_i=[int(A[i]/sumA*(K+N)-1) for i in range(N)]
    dA=[A[i]/(K_i[i]+1) for i in range(N)]
    res=K-sum(K_i)
    b=[]
    for i in range(N):
        b.append([dA[i],i])
    b.sort(reverse=True)
    now=0
    for i in range(res):
        K_i[b[now][1]]+=1
        dA[b[now][1]]=A[b[now][1]]/(K_i[b[now][1]]+1)
        if dA[b[now][1]]<b[now+1][0]:
            now+=1
    
    maxi=dA.index(max(dA))
    print(ceil(A[maxi]/(K_i[maxi]+1)))
    
    
    
if __name__=="__main__":
    main()


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

using namespace std;

int g[3][1002];


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

    int n;
    cin>>n;

    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            cin>>g[i][j];
        }
    }

    int ans=0;
    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            int col=0;
            for(int k=1;k<=j;k++){
                col += g[1][k];
            }
            for(int k=j;k<=n;k++){
                col+=g[2][k];
            }
            ans=max(ans, col);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    string s1,s2;
    cin >> s1;
    cin >> s2;
    ll s1pos=0, s2pos=0;
    ll comb=1;
    bool prev_tate=false;
    while(s1pos!=s1.size() && s2pos!=s2.size())
    {
        //縦
        if(s1[s1pos]==s2[s2pos])
        {
            if(s1pos==0 && s2pos==0) comb*=3;
            else
            {
                if(prev_tate) comb*= 2;
                else comb*= 1 % DIV;
            }
            s1pos++;
            s2pos++;
            prev_tate = true;
        }
        //横
        else
        {
            if(s1pos==0 && s2pos==0) comb*=3*2;
            else
            {
                if(prev_tate) comb*=2;
                else comb*=3;
            }
            s1pos+=2;
            s2pos+=2;
            prev_tate = false;
        }
        comb%=DIV;
    }
    cout << comb << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N], m;
int b, test;
string s;

int32_t main(){_  

   int n;
   cin >> n;

   int tot = 0;

   if (n % 2){
      tot = (n + 1) / 2;
   }
   else{
      tot = n/ 2;
   }

   cout << fixed << setprecision(15);

   cout<<tot / (L)n;


   return 0;
}

Measured memory_bytes: 256
import sys
n,t = map(int,input().split())
li = list(map(int,input().split()))
count = t
if n == 1:
    print(t)
    sys.exit()
for i,l in enumerate(li):
    if i == 0:
        continue
    if l - li[i-1] <= t:
        count += l - li[i-1]
    else:
        count += t
print(count)

Measured memory_bytes: 85456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <typeinfo>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll n, m, count, tmp, sum = 0;
    double border;

    cin >> n >> m;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    border = (double)sum / m / 4;
    rep(i, n)
    {
        if (border <= a[i])
        {
            count++;
        }
    }
    cout << (count >= m ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i,j;
  	int a;
  	int num=0;
  	int count=0;
  	scanf("%d",&a);
  	for(i=1;i<=a;i=i+2)
    {
      for(j=i;j>0;j--)
      {
        if(i%j==0) count++;
      }
      if(count==8) num++;
      count=0;
    }
  	printf("%d",num);
  	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

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

    vector<vector<int>> g(n, vector<int>(n, 0));
    for (int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;
        --u;  // want to store graph as 0-origin

        for (int j = 0; j < k; ++j) {
            int adj;
            cin >> adj;
            g[u][adj - 1] = 1;
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << g[i][0];
        for (int j = 1; j < n; ++j)
            cout << ' ' << g[i][j];
        cout << '\n';
    }
}



Measured memory_bytes: 3132
let A = Int(readLine()!)!
let B = Int(readLine()!)!
let C = Int(readLine()!)!
let X = Int(readLine()!)!
var res = 0
for a in 0...A {
    for b in 0...B {
        for c in 0...C {
            if 500*a + 100*b + 50*c == X { res += 1 }
        }
    }
}
print(res)


Measured memory_bytes: 3820
import java.math.BigInteger;
import java.util.Scanner;
import java.io.PrintWriter;
import java.util.ArrayList;

public class Main {
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E = sc.nextInt();
		ArrayList<Integer>[] g = new ArrayList[V];
		for (int i = 0; i < V; ++i) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < E; ++i) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			g[s].add(t);
		}
		vis = new boolean[V];
		sort(g);
		for (int i = lis.size() - 1; i >= 0; --i) {
			System.out.println(lis.get(i));
		}
	}

	static boolean[] vis;
	static ArrayList<Integer> lis = new ArrayList<>();

	static void sort(ArrayList<Integer>[] g) {
		int n = g.length;
		for (int i = 0; i < n; ++i) {
			if (!vis[i]) {
				dfs(i, -1, g);
			}
		}
	}

	static void dfs(int cur, int pre, ArrayList<Integer>[] g) {
		for (int to : g[cur]) {
			if (pre != cur && !vis[to]) {
				dfs(to, cur, g);
			}
		}
		vis[cur] = true;
		lis.add(cur);
	}
}

Measured memory_bytes: 68620
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>

using ll = long long;
using namespace std;

int main() {
    int X,A,B; cin >> X >> A >> B;

    if(X>=B-A){
        if(B-A<=0){
        cout << "delicious" << endl;
        } else {
        cout << "safe" << endl;
        }
    } else {
    cout << "dangerous" << endl;
      
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
      int a=sc.nextInt();
      int b=sc.nextInt();
      if(b%a==0){
        System.out.println(a+b);
      }else{
        System.out.println(b-a);
      }
    }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long K, long long X){
  FOR(x, X-K+1, K+X) {
    cout << x << ' ';
  }
  cout << endl;
}

signed main(){
  long long K;
  scanf("%lld",&K);
  long long X;
  scanf("%lld",&X);
  solve(K, X);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
      Main main = new Main();
      main.solve();
    }
    public void solve() {
      Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
      String S = scan.next();
      if (S.indexOf("AC") == -1) {
        System.out.println("No");
      } else {
        System.out.println("Yes");
      }
    }
}


Measured memory_bytes: 21076
using System;
using System.Linq;

namespace ABC125A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int[] intar = ConsoleInput.IntArray();
            Console.WriteLine(intar[2] / intar[0] * intar[1]);
        }
    }
    
    internal static class ConsoleInput
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

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

typedef long long ll;

int main()
{
    ll i,j;
    ll n,q;
    cin >> n;
    vector<ll> s(n);
    for(i = 0;i < n;++i){
        cin >> s.at(i);
    }
    sort(s.begin(), s.end());
    cin >> q;
    ll ans = 0;
    for(i = 0;i < q;++i){
        ll t;
        cin >> t;
        auto it = lower_bound(s.begin(), s.end(),t);
        if(it != s.end() && *it == t){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<bool> > a(n, vector<bool>(n));
  vector<vector<bool> > b(m, vector<bool>(m));
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    for(int j = 0; j < n; j++){
      a[i][j] = (s[j] == '#' ? true : false);
    }
  }
  for(int i = 0; i < m; i++){
    string s;
    cin >> s;
    for(int j = 0; j < m; j++){
      b[i][j] = (s[j] == '#' ? true : false);
    }
  }

  for(int i = 0; i <= n - m; i++){
    for(int j = 0; j <= n - m; j++){
      bool match = true;
      for(int k = 0; k < m; k++){
        for(int l = 0; l < m; l++){
          if(a[i+k][j+l] != b[k][l]){
            match = false;
            k = m;
            l = m;
          }
        }
      }
      if(match){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int T=1048576;
int f[2222222];
long long g[1111111],s[1111111];
void C(int l,int r,int v){for(l+=T-1,r+=T+1;l^r^1;l>>=1,r>>=1)l&1?:f[l^1]=v,~r&1?:f[r^1]=v;}
int Q(int l){int s=3333333;for(l+=T;l;l>>=1)s=s<f[l]?s:f[l];return s;}
int a[1111111],b[1111111],val[1111111];
long long gmin(long long a,long long b){return a<b?a:b;}
int main()
{
	int n,k,c;
	!scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		!scanf("%d%d",&a[i],&b[i]);
		a[i]*=2;
		if(b[i]==1&&a[i]>k)return puts("-1"),0;
		s[i]=s[i-1]+a[i];
		val[i*2-1]=(k-s[i-1]%k+k-a[i]%k)%k;
		val[i*2]=(k-s[i-1]%k)%k;
	}
	val[2*n+1]=k-1;
	val[2*n+2]=0;
	sort(&val[1],&val[2*n+3]);
	c=unique(&val[1],&val[2*n+3])-val;
	for(int i=1;i<2222222;i++)f[i]=n;
	for(int i=n;i;i--)
	{
		int t=Q(lower_bound(&val[1],&val[c],(k-s[i-1]%k)%k)-val);
		if(t<n)g[i-1]=g[t]+s[t]-s[i-1]+(k-(s[t]-s[i-1])%k)%k;
		else g[i-1]=s[t]-s[i-1];
		if(b[i]==1)
		{
			int l=lower_bound(&val[1],&val[c],(k-s[i-1]%k+k-a[i]%k)%k)-val+1,r=lower_bound(&val[1],&val[c],(k-s[i-1]%k)%k)-val;
			if(l<=r)C(l,r,i-1);
			else C(l,c-1,i-1),C(1,r,i-1);
		}
	}
	long long res=233333333333333333ll;
	int lim;
	if(b[1]==1)lim=(k-a[1]%k)%k;
	else lim=k-1;
	for(int i=1;i<c&&val[i]<=lim;i++)
	{
		int t=Q(i);
		if(t<n)res=gmin(res,g[t]+s[t]+(k-(s[t]+val[i])%k)%k);
		else res=gmin(res,s[t]);
	}
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 19712
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
ld pie=3.141592653589793238462643383279;
int mod=1e9+7;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};


int dig(int a){
  int r=0;
  while(a!=0){
    int xp=a%10;
    a/=10; if(xp==1) ++r;
  }
  return r;
}

int fact[2000005];
int infact[2000005];

int inv(int a){
  int y=mod-2;
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r;
}

int po(int a,int y){
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r; 
}

void facto(){
  fact[0]=1;
  f(i,1,2000005) {fact[i]=i*fact[i-1]; fact[i]%=mod;}
  f(i,0,2000005) infact[i]=inv(fact[i]); 
}

int nck (int n,int k){
  if(k<0 || k>n) return 0;
  int ret=fact[n]; ret*=infact[k]; ret%=mod;
  ret*=infact[n-k]; ret%=mod;
  return ret;
}
int32_t main(){
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  facto();
  int k; cin>>k;
  string s; cin>>s;
  int l=k+s.size();
  int xp=s.size();
  // total = 26^l - those which do not contain subsequence
  // --- i= 0 to  xp-1 prefix present as subseqeunce and remaining have 25^(l-i)
  int ret=1;
  f(i,0,l){
    ret*=26; ret%=mod;
  }
  int sub=0;

  f(i,0,xp){
    // l choose i
    sub+= (nck(l,i)*po(25,l-i));
    sub%=mod; 
  }

  cout<<((ret-sub)%mod + mod) %mod <<"\n";
  return 0;
}


Measured memory_bytes: 35484
s = input()
for i in range(len(s) // 5):
    if s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-6:] == "eraser":
        s = s[:-6]
    elif s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
ans = "YES" if s == "" else "NO"
print(ans) 

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long input, money = 1000;
    long long permille = 2000;
    cin >> input ;
    
    vector<long long> price(input);
    for(long long i = 0; i < input; i++){
        cin >> price.at(i);
        if(i > 0){
            if(price.at(i) > price.at(i - 1)){
                money += ( price.at(i) - price.at(i - 1) ) * ( money / price.at(i - 1) );
            }
        }        

    }

    cout << money << endl;

}


Measured memory_bytes: 3592
using System;
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        double ans = 1;
        for (int i = 0; i < n; i++)
        {
            ans *= i + 1;
            ans %= 1000000007;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
 
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n){
    cin >> vec.at(i);
  }
  int cnt=0;
  rep(i,n-1){
    if (vec.at(i)!=i+1){
      cnt++;
    }
  }
  if (cnt <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

long long N;
pair<long long, long long > xy[100005];
//            to     ,  cost
vector<pair<long long, long long> >way[100005];

int main(){
	cin >> N;
	//            X      , idx
	vector<pair<long long, long long> >XX;
	//            Y      , idx
	vector<pair<long long, long long> >YY;
	for(long long i = 0; i < N; i++){
		cin >> xy[i].first >> xy[i].second;
		XX.push_back(make_pair(xy[i].first, i));
		YY.push_back(make_pair(xy[i].second, i));
	}

	sort(XX.begin(), XX.end());
	sort(YY.begin(), YY.end());

	for(long long i = 0; i < XX.size() - 1; i++){
		long long from, to, dis;
		from = XX[i].second;
		to = XX[i+1].second;
		dis = min(abs(xy[from].first - xy[to].first), abs(xy[from].second - xy[to].second));
		way[from].push_back(make_pair(to, dis));
		way[to].push_back(make_pair(from, dis));
	}

	for(long long i = 0; i < YY.size() - 1; i++){
		long long from, to, dis;
		from = YY[i].second;
		to = YY[i+1].second;
		dis = min(abs(xy[from].first - xy[to].first), abs(xy[from].second - xy[to].second));
		way[from].push_back(make_pair(to, dis));
		way[to].push_back(make_pair(from, dis));
	}

	long long ans = 0;
	set<long long> done;
	priority_queue<pair<long long, long long>,vector<pair<long long, long long> >, greater<pair<long long, long long> > > Q;

	Q.push(make_pair(0, 0));
	while(!Q.empty()){
		long long node = Q.top().second;
		long long cost = Q.top().first;
		Q.pop();
		if(done.count(node) != 0){
			continue;
		}
		ans += cost;
		done.insert(node);
		for(long long i = 0; i < way[node].size(); i++){
			long long nnode = way[node][i].first;
			long long ncost = way[node][i].second;
			if(done.count(nnode) == 0){
				Q.push(make_pair(ncost, nnode));
			}
		}
	}
	cout << ans << endl;
}


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

struct RAQ{
private:
	struct Node{
		long long sum; long long buf;
		Node(long long s, long long b) : sum(s), buf(b){}
	};
	vector<Node> node;
	long long defval;
	int N;
	int n;
public:
	void init(int n, long long defval = 0){
		N = 1;
		while(N < n)N<<=1;
		this->n = n;
		this->defval = defval;
		node.assign(N*2-1, Node(defval, 0));
	}
	long long query(int a, int b, int l = 0, int r = -1, int i = 0){
		if(r == -1) r = N;
		if(b <= l || r <= a) return defval;
		if(a <= l && r <= b) return node[i].sum;
		int rag = min(r, b) - max(l, a);
		return query(a,b,l,(l+r)/2,i*2+1) + query(a,b,(l+r)/2,r,i*2+2) + node[i].buf * rag;
	}
	void update(int a, int b, long long v, int l = 0, int r = -1, int i = 0){
		if(r == -1) r = N;
		if(b <= l || r <= a) return;
		if(a <= l && r <= b) { node[i].buf += v; node[i].sum += v * (r-l); return; }
		
		update(a,b,v,l,(l+r)/2,i*2+1);
		update(a,b,v,(l+r)/2,r,i*2+2);

		node[i].sum = node[i*2+1].sum + node[i*2+2].sum + node[i].buf * (r-l);
	}

};


int main() {
	int n, q; cin >> n >> q;
	RAQ tr; tr.init(n, 0);

	vector<long long> ans;

	for(int i = 0; i < q; i++){
		int c; cin >> c;
		if(c == 0){
			int s,t,x; cin >> s >> t >> x;
			tr.update(s-1, t, x);
		}
		else {
			int i; cin >> i;
			ans.push_back(tr.query(i-1, i));
		}
	}

	for(int i = 0; i < ans.size(); i++){
		cout << ans[i] << endl;
	}

    return 0;
}



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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
    string s;
    cin>>s;
    
    for(int i=0;i<s.size();i++){
        s.at(i)='x';
    }
    
    cout<<s<<endl;
}

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

using namespace std;
int main()
{
	int N;
	cin >> N;
	int K;
	cin >> K;
	vector<long long> h(N);

	for (size_t i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	sort(h.begin(), h.end());

	vector<long long> h_diff(N - K+1);
	for (size_t i = 0; i < N - K +1; i++)
	{
		h_diff[i] = h[i + K-1] - h[i];
	}
	cout << *min_element(h_diff.begin(), h_diff.end());
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n;
    cin >> n;
    ll f[100] = {};
    rep(i,n){
        ll a; cin >> a;
        rep(j,100){
            f[j] += a % 2;
            a = a / 2;
        }
    }

    ll MOD = 1e9+7;
    ll ans = 0;

    ll two = 1;
    rep(i,100){
        ans += f[i] * (n - f[i]) % MOD * two;
        ans %= MOD;
        two = two * 2 % MOD;
    }

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



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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


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

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;

    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c[150][150],ans[150][150],f[150][150];
int n,m;
int h[150],l[150];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>c[i][j];
	for(int i=1;i<=n;i++)
	{
		int tmp=0;
		for(int j=1;j<=m;j++)
		if(c[i][j]=='.')tmp++;
		if(tmp==m)h[i]=1;
	}
	for(int i=1;i<=m;i++)
	{
		int tmp=0;
		for(int j=1;j<=n;j++)
		if(c[j][i]=='.')tmp++;
		if(tmp==n)l[i]=1;
	}
	for(int i=1;i<=n;i++)
	{
		if(h[i]==1)continue;
		else
		{
			for(int j=1;j<=m;j++)
			{
				if(l[j]!=1)cout<<c[i][j];
			}
			cout<<endl;
		} 	
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL N, T;
std::vector<std::pair<LL, LL>>dish;
std::vector<std::vector<LL>>memo;

LL dp(LL i, LL j)
{
	if (j >= T || i == N) return 0;
	if (memo[i][j] != -1) return memo[i][j];
	LL res1 = dp(i + 1, j + dish[i].first) + dish[i].second;
	LL res2 = dp(i + 1, j);
	return memo[i][j] = std::max(res1, res2);
}

int main()
{
	in >> N >> T;
	std::vector<LL>A(N), B(N);
	rep(i, N) in >> A[i] >> B[i];

	rep(i, N) dish.push_back(std::make_pair(A[i], B[i]));
	std::sort(dish.begin(), dish.end());

	memo.resize(N, std::vector<LL>(T + 1, -1));
	out << dp(0, 0) << std::endl;
}


Measured memory_bytes: 70912
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;

string J(string s){

	int n=s.size();
	string t;
	for(int i=0;i<n;i++){
		t+=s[(n-1+i)%n];
	}
	return t;

}

string C(string s){
	int n=s.size();
	string t;
	for(int i=0;i<n;i++){
		t+=s[(1+i)%n];
	}
	return t;
}

string E(string s){
	string t;
	if(s.size()%2){
		string left=s.substr(0,s.size()/2);
		char mid=s[s.size()/2];
		string right=s.substr(s.size()/2+1);
		t=right+mid+left;
	}else{
		string left=s.substr(0,s.size()/2);
		string right=s.substr(s.size()/2);
		t=right+left;
	}

	return t;
}

string A(string s){
	string t=s;
	reverse(t.begin(),t.end());
	return t;
}

string P(string s){
	string t=s;
	for(int i=0;i<t.size();i++){
		if( '0'<=t[i] && t[i]<='9' ){
			if(t[i]=='0') t[i]='9';
			else t[i]--;
		}
	}
	return t;
}

string M(string s){
	string t=s;
	for(int i=0;i<t.size();i++){
		if( '0'<=t[i] && t[i]<='9' ){
			if(t[i]=='9') t[i]='0';
			else t[i]++;
		}
	}
	return t;
}

int main(){

	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		string t,s;
		cin>>t>>s;
		for(int j=t.size()-1;j>=0;j--){
			if(t[j]=='J') s=J(s);
			else if(t[j]=='C') s=C(s);
			else if(t[j]=='E') s=E(s);
			else if(t[j]=='A') s=A(s);
			else if(t[j]=='P') s=P(s);
			else if(t[j]=='M') s=M(s);
		}
		cout<<s<<endl;
	}

	return 0;
}

Measured memory_bytes: 3048
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <bitset>
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define lowbit(x) x&(-x)
#define PA pair<int, int>
#define MK make_pair
using namespace std;
typedef long long LL;
inline int read()
{
	int l = 0, f = 1;
	char a = getchar();
	for (; a < '0' || a > '9'; a = getchar())
		if (a == '-') f = -1;
	for (; a >= '0' && a <= '9'; a = getchar())
		l = l*10+a-48;
	return l*f;
}
int n, a, b;
int main()
{
	n = read(), a = read(), b = read();
	if (abs(a-b)%2 == 0) printf("Alice");
	else printf("Borys");
	return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll Q;
  cin >> Q;
  llvec pr;
  FOR(i, 3, 100001){
    if(i%2==1 and is_prime(i) and is_prime((i+1)/2)){
      pr.push_back(i);
    }
  }

  rep(i, Q){
    ll l, r;
    cin >> l >> r;
    ll num = upper_bound(ALL(pr), r)-lower_bound(ALL(pr), l);
    cout << num << endl;
  }
  
  return 0;
}


Measured memory_bytes: 640
n = int(input())
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    dp[i] = min((dp[i-2]+abs(h[i]-h[i-2])),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[n-1])

Measured memory_bytes: 13980
n, k = (int(i) for i in input().split())
x = [int(i) for i in input().split()]

min_dist = 10**10
for i in range(n-k+1):
    if x[i] > 0:
        dist = x[i+k-1]
    elif x[i+k-1] < 0:
        dist = -x[i]
    else:
        dist = x[i+k-1] - x[i] + min(-x[i], x[i+k-1])

    if dist < min_dist:
        min_dist = dist

print(min_dist)

Measured memory_bytes: 14384
#include<iostream>
#include<vector>

using namespace std;

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

	int ans = 0;

	for (int i = 2; i < n; i++)
	{
		if ((p[i - 2] < p[i - 1] && p[i - 1] < p[i]) || (p[i - 2] > p[i - 1] && p[i - 1] > p[i])) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import re
import math
import fractions
import random
import time
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
fac=[1]*250000
for a in range(2,250000):
    fac[a]=fac[a-1]*a%mod
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n

    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]

    def same(self,x,y):
        return self.find(x)==self.find(y)

    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1

    def unite(self,x,y):
        self.link(self.find(x),self.find(y))

    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num



def comb_(n,r):return fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod)
#main
def solve():
    return

#入力
N,M,K=map(int,input().split())
sum_=0
for a in range(1,N):
    sum_+=M*M*abs(N-a)*a*comb_(N*M-2,K-2)
    sum_%=mod
for a in range(1,M):
    sum_+=N*N*abs(M-a)*a*comb_(N*M-2,K-2)
    sum_%=mod

print(sum_)


Measured memory_bytes: 68840
#include <cstdio>
#define INF 1000000000

int price;
int weight;

int main() {
  while(scanf("%d", &weight), weight) {
    price = INF;
    for (int i=0; i<=25; i++) {
      for (int j=0; j<=16; j++) {
	for (int k=0; k<=10; k++) {
	  int w = i*200 + j*300 + k*500;
	  if (weight == w) {
	    int calc_price = 
	      ((i/5)*5) * 380 * 0.8 + (i%5)*380
	      + ((j/4)*4) * 550 * 0.85 + (j%4)*550
	      + ((k/3)*3) * 850 * 0.88 + (k%3)*850;
	    if (price > calc_price) {
	      price = calc_price;
	    }
	    break;
	  } else if (weight < w) {
	    break;
	  }
	}
      }
    }	

    printf("%d\n", price);
  }
}

Measured memory_bytes: 2580
#include<bits/stdc++.h>
using namespace std;
const int N=30;
int n,a[N];
char s[N];
inline void work()
{
	printf("%s",s+1);
	for(int i=0;i<26;i++)
	{
		int flag=1;
		for(int j=1;j<=n;j++)if(a[j]==i){flag=0;break;}
		if(flag){putchar('a'+i);return;}
	}
}
inline bool check()
{
	for(int i=1;i<=n;i++)if(a[i]!=26-i)return false;
	return true;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)a[i]=s[i]-'a';
	if(n<26){work();return 0;}
	if(check())puts("-1");
	while(1)
	{
		a[n]++;
		if(a[n]>25){n--;continue;}
		int flag=1;
		for(int i=1;i<n;i++)if(a[i]==a[n]){flag=0;break;}
		if(flag)break;
	}
	for(int i=1;i<=n;i++)printf("%c",'a'+a[i]);puts("");
	return 0;
}

Measured memory_bytes: 256