akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    int q;
    cin >> q;

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

    vector<vector<long long>> acc(2, vector<long long>(n + 1, 0));

    for (int i = 0; i < n; ++i) {
        acc[i % 2][i + 1] += A[i]; 
    }
    for (int i = 0; i < 2; ++i) {
        for (int j = 1; j <= n; ++j) {
            acc[i][j] += acc[i][j - 1];
        }
    }

    auto calc = [&](int x) -> long long {
        int lo = 1, hi = (n + 1) / 2;

        auto p = lower_bound(A.begin(), A.end(), x) - A.begin();

        while (lo < hi) {
            auto mi = (lo + hi) >> 1;

            bool ok = false;
            int a = n - 1 - mi;

            // cout << mi << " " << a << " " << p << endl;
            if (a < p) {
                ok = true;
            } else {
                int b = a - mi;
                if (b < 0 || abs(A[b] - x) > abs(A[a] - x)) {
                    ok = true;
                }
            }

            if (ok) {
                hi = mi;
            } else {
                lo = mi + 1;
            }
        }

        long long res = 0;
        int R = max(0, n - 1 - lo);
        int L = max(0, R - lo + 1);
        // cout << x << " " << lo << " " << L << " " << R << endl;
        res += acc[0][n] - acc[0][R + 1];
        res += acc[1][n] - acc[1][R + 1];
        // cout << res << endl;
        if (n & 1) {
            res += acc[0][L];
        } else {
            res += acc[1][L];
        }
        return res;
    };

    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        cout << calc(x) << '\n';
    }

    return 0;
}

Measured memory_bytes: 3696
n=int(input())
data=[[0]*50 for i in range(50)]

for i in range(n):
    s=input()
    l=len(s)
    num=0
    sho=0
    keta=1
    for i in range(l):
        if(s[l-i-1]!='.'):
            num+=keta*int(s[l-i-1])
            keta*=10
        else:
            sho=i
    #print(num,sho)
    two=-sho
    five=-sho
    for i in range(100):
        if(num%2==0):
            two+=1
            num//=2
        else:
            break
    for i in range(100):
        if(num%5==0):
            five+=1
            num//=5
        else:
            break
    #print(two,five)
    data[two+9][five+9]+=1


ans=0
for i in range(50):
    for j in range(50):
        jibun=data[i][j]
        if(jibun==0):
            continue
        aite=0
        for p in range(max(0,18-i),50):
            for q in range(max(0,18-j),50):
                aite+=data[p][q]
                if(p==i and j==q):
                    aite-=1
        ans+=jibun*aite
        #print(i-9,j-9,jibun,aite)

print(ans//2)

Measured memory_bytes: 73264
#include <iostream>
#include <string>
using namespace std;
string s;
int main()
{
    cin>>s;
    if(s=="SUN")
        cout<<"7"<<"\n";
    else if(s=="SAT")
        cout<<"1"<<"\n";
    else if(s=="FRI")
        cout<<"2"<<"\n";
    else if(s=="THU")
        cout<<"3"<<"\n";
    else if(s=="WED")
        cout<<"4"<<"\n";
    else if(s=="TUE")
        cout<<"5"<<"\n";
    else
        cout<<"6"<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  int Q; cin>>Q;

  rep(i,Q){
    ll a,b; cin>>a>>b;
    if(a>b) swap(a,b);
    if(a==b){
      cout<< 2*(a-1)<<"\n"; continue;
    }
    if(a+1==b){
      cout<< 2*(a-1)<<"\n"; continue;
    }

    int ok = -1; // 一番小さい値より1つ前 ngとokは場合により入れ替え
    int ng = INF; // 一番でかい値より1つあと
    while (abs(ok - ng) > 1) {
      ll mid = (ok + ng) / 2;

      ( mid*mid<a*b ? ok : ng ) = mid; //ここを変える。midに対してokかどうか判定
    }

    ll c=ok;

    //cout<< a*b<<" "<< c<<"\n";

    if(c*(c+1)<a*b){
      cout<< 2*c-1 <<"\n";
    }
    else{
      cout<< 2*c-2 <<"\n";
    }

  }

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
//2020-07-04 23:43:15
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n; cin >> n;
   vector<ll> A(n);
   rep(i,n)cin >> A[i];
   ll c = 0;
   ll s = A[0] + A[1];
   for (int i = 2; i < n; i++)
      c ^= A[i];
   ll d = (s-c)/2;
   if (((d&c)!=0) || (d<0) || (d>A[0]) || (((s-c)%2)==1)){
      cout << -1 << endl;
      return 0;
   }
   ll y = 0;
   for (int i = 60; i >= 0; i--)
   {
      if (((c>>i)&1) && ((d ^ (y + (1ll<<i))) <= A[0]))
         y += (1ll<<i);
   }
   if ((d^y) == 0)
      cout << -1 << endl;
   else
      cout << (A[0]-(d^y)) << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vin l(n);rep(i,n)cin>>l[i];
    int ans=0;
    rep(i,n)rep2(j,i,n)rep2(k,j,n){
        if(l[i]==l[j]||l[j]==l[k]||l[k]==l[i])continue;
        if(abs(l[i]-l[j])<l[k]&&l[k]<l[i]+l[j])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
s = input()



tmp = []
for i in range(len(s)-1):
        if s[i] != s[i+1]:
                tmp.append(max(i+1,len(s)-(i+1)))

if len(tmp) == 0:
        #元から全部同じ
        print(len(s))
else:
        print(min(tmp))

Measured memory_bytes: 5184
/*
                    author      : TAPAN SAVANI 
                    codeforces  : savanitapan2001
                    codechef    : savanitapan17
*/

/*
------------------------------------------------------------------------

░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░
 
------------------------------------------------------------------------
*/

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

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

int main()
{
    HAPPY_CODING;

    float d, t, s;

    cin >> d >> t >> s;

    if ((d / s) <= t)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 3005;
const int inv2 = (mod + 1) / 2;
int a[maxn];
int dp[maxn][maxn];
void add(int& a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}
int main() {
	int n, q;
	scanf("%d%d", &n, &q);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) dp[i][j] = (a[i] < a[j]);
	int tot = 1;
	while(q--) {
		tot = tot * 2 % mod;
		int x, y;
		scanf("%d%d", &x, &y);
		for(int i = 1; i <= n; i++) 
			if(i != x && i != y) {
				dp[i][x] = dp[i][y] = (ll)(dp[i][x] + dp[i][y]) * inv2 % mod;
				dp[x][i] = dp[y][i] = (ll)(dp[x][i] + dp[y][i]) * inv2 % mod;
			}
		dp[x][y] = dp[y][x] = (ll)(dp[x][y] + dp[y][x]) * inv2 % mod;
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) 
		for(int j = 1; j < i; j++) add(ans, dp[i][j]);
	ans = (ll)ans * tot % mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 35456
import sys
import math

def GCD(a,b):
	if b == 0:
		return a
	return GCD(b,a%b)

N = int(input())
T = [int(input()) for _ in range(N)]
if N == 1:
	print(T[0])
	sys.exit()
def SKS(a,b):
	return (a*b)//GCD(a,b)

for i in range(1,N):
	if i == 1:
		temp = SKS(T[0], T[1])
		continue

	temp = SKS(temp, T[i])

print(temp)

Measured memory_bytes: 3064
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
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! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"pot
top
" => r"YES",

r"tab
bet
" => r"NO",

r"eye
eel
" => r"NO"
}

use std::cmp;
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: String,
        b: String,
    }

    if a.chars().rev().collect::<String>() == b {
        return "YES".to_string();
    } else {
        return "NO".to_string();
    }
}


Measured memory_bytes: 4352
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

struct P{
    int x,num=0;
};
bool cmp(P a,P b){
    return a.num>b.num;
};
int main (){
    int n;
    cin>>n;
    vector<P> odd(100001),even(100001);
    vector<int> v(n);
    rep(i,0,n){
        cin>>v[i];
        if(i%2==0){
            even[v[i]].num++;
            even[v[i]].x=v[i];
        }
        else{
            odd[v[i]].num++;
            odd[v[i]].x=v[i];
        }
    }
    sort(all(odd),cmp);
    sort(all(even),cmp);

    if(odd[0].x==even[0].x){
        cout<<min(n/2-odd[0].num+n/2-even[1].num,n/2-odd[1].num+n/2-even[0].num)<<endl;
    }else {
        cout<<(n/2-odd[0].num+n/2-even[0].num)<<endl;
    }
}

/*

*/


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)


int n,k,q;
vector<int> a;
int ans = INT_MAX;
int main(){
  cin >> n>> k>> q;
  REP(i,n){
    int t;
    cin >> t;
    a.push_back(t);
  }
  REP(i,n){
    vector<int> mi;
    vector<int> tmp;
    REP(r,n+1){
      if(r < n && a[r]>=a[i]) tmp.push_back(a[r]);
      if(r == n || a[r]<a[i]){
        sort(tmp.begin(),tmp.end(),greater<int>());
        while(tmp.size()>=k){
          mi.push_back(tmp.back());
          tmp.pop_back();
        }
        tmp.clear();
        continue;
      }
    }
    if(mi.size()<q) continue;
    sort(mi.begin(),mi.end());
    ans = min(ans,mi[q-1]-mi[0]);
  }
  cout << ans <<endl;
}


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

typedef long long ll;
ll comb[51][51];

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

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

  for(int i = 1; i <= n; i++){
    for(int j = 0; j <= n; j++){
      if(i == j || j == 0) comb[i][j] = 1;
      else comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
    }
  }

  sort(v, v+n, greater<ll>());

  ll sum = 0;
  for(int i = 0; i < a; i++){
    sum += v[i];
  }
  double ansm = (double)sum / a;

  ll ansc = 0;
  int c = 0;
  for(int i = 0; i < n; i++){
    if(v[i] == v[a-1]) c++;
  }

  if(v[0] == v[a-1]){
    for(int i = a; i <= b; i++){
      ansc += comb[c][i];
    }
  }else{
    int c1 = 0;
    for(int i = 0; i < a; i++){
      if(v[i] == v[a-1]) c1++;
    }
    ansc += comb[c][c1];
  }

  printf("%.6f\n%lld\n", ansm, ansc);

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int t[][][]=new int[24][60][60];
			int ans=0;
			for(int i=0;i<n;i++)
			{
				String st1[]=in.next().split(":");
				String st2[]=in.next().split(":");
				int h1=Integer.valueOf(st1[0]);
				int m1=Integer.valueOf(st1[1]);
				int s1=Integer.valueOf(st1[2]);
				int h2=Integer.valueOf(st2[0]);
				int m2=Integer.valueOf(st2[1]);
				int s2=Integer.valueOf(st2[2]);
				for(;;)
				{
					t[h1][m1][s1]++;
					ans=Math.max(ans, t[h1][m1][s1]);
					s1++;
					if(s1==60)
					{
						m1++;
						s1=0;
					}
					if(m1==60)
					{
						h1++;
						m1=0;
					}	
					if(h1==h2&&m1==m2&&s1==s2)
						break;
				}
			}			
			System.out.println(ans);
		}
	}
	
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 67888
n, x, m = map(int, input().split())
X = [-1] * m
P = []
sum_p = 0
while X[x] == -1: # preset
    X[x] = len(P) # pre length
    P.append(sum_p) # pre sum_p
    sum_p += x # now sum_p
    x = x*x % m
cyc_times, nxt_len = divmod(n - X[x], len(P) - X[x])
cyc = (sum_p - P[X[x]]) * cyc_times
remain = P[X[x] + nxt_len]
print(cyc + remain)


Measured memory_bytes: 13616
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		int nums[] = new int[len] ;
		for (int i = 0; i < len; i++) {
			nums[i] = scanner.nextInt();
		}
		
		for (int i = 1; i < nums.length; i++) {
			new Main().arrayToString(nums);
			int val = nums[i];
			int preIndex = i-1;
			while (preIndex>=0 && nums[preIndex] > val) {
				nums[preIndex+1] = nums[preIndex];
				nums[preIndex] = val;
				preIndex--;
			}
		}
		new Main().arrayToString(nums);
	}
	
	public void arrayToString(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			
			if (i == arr.length-1) {
				System.out.println(arr[i]);
			}else {
				System.out.print(arr[i]+" ");
			}
		}
	}

}


Measured memory_bytes: 32116
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int a, b, c, ans;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> a >> b >> c;
   if (b >= c) cout << b + c, exit (0);
   else if (a + b >= c) cout << b + c, exit (0);
   else {
      int ans = 0;
      ans += 2 * b;
      c -= b;
      ans += a;
      c -= a;
      if (c > 0) ans ++;
      cout << ans;
   }
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

int main() {
    string word;
    int m;
    vector<string> ans;
    while(1){
        cin >> word;
        if(word == "-")break;
        cin >> m;
        int h;
        F(i, 0, m){
           cin >> h; 
           string sub = word.substr(0, h);
           F(j, 0, h)word.erase(word.begin());
           word = word + sub;
        }
        ans.pb(word);
    }
    F(i, 0, ans.size()){
        cout << ans[i] << endl;
    }
}



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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int h = Integer.parseInt(tokenizer.nextToken());
        int w = Integer.parseInt(tokenizer.nextToken());
        char [][] letters = new char[h][];
        for (int i = 0; i < h; i++) {
            letters[i] = input.readLine().toCharArray();
        }
        int [] x = {1, 0, 1, 0, -1, 1, -1, -1};
        int [] y = {1, 1, 0, -1, 0, -1, 1, -1};
        int sum;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (letters[i][j] == '.'){
                    sum = 0;
                    for (int k = 0; k < 8; k++) {
                        if (check(h, w, i + x[k], j + y[k]) && letters[i + x[k]][j + y[k]] == '#')
                            sum++;
                    }
                    letters[i][j] = (char)('0' + sum);
                }
            }
        }

       StringBuilder out = new StringBuilder();
        StringBuilder row;
        for (int i = 0; i < h; i++) {
            row = new StringBuilder();
            for (int j = 0; j < w; j++) {
                row.append(letters[i][j]);
            }
            out.append(row).append("\n");
        }
        System.out.print(out);
    }
    public static boolean check (int x1, int y1, int x2, int y2){
        return x2 > -1 && x2 < x1 && y2 > -1 && y2 < y1;
    }
}


Measured memory_bytes: 22996
n,k=gets.split.map(&:to_i)
nums=Array.new(n)

for i in 0..n-1 do
    nums[i]=gets.to_i
end

nums=nums.sort
ans=1e9
for i in 0..(n-k) do
    tmp=nums[i+k-1]-nums[i]
    ans=[ans,tmp].min
end

puts ans

Measured memory_bytes: 4472
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from Queue import Queue
 
 
def main():
    num = int(stdin.readline())
 
    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])
 
    d = [-1] * num
    d[0] = 0
    q = Queue(100)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)
 
    for i, v in enumerate(d):
        print(i+1, v)
 
 
main()

Measured memory_bytes: 7028
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  long long int sum=0;
  cin>>n;
  int i=1;
  while(i!=n+1)
  {
    if((i%3!=0)&&(i%5!=0))
    {
      sum+=i;
    }
    i++;
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	if (n % 10 == 3)
		printf("bon\n");
	else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
		printf("pon\n");
	else if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9)
		printf("hon\n");
	return 0;
}


Measured memory_bytes: 1620
#include<cstdio>
#include<algorithm>
#include<cmath>
#define MAXN 100009
using namespace std;

int n;
struct data{
	int x,y,id;
}a[MAXN];
struct E{
	int from,to,val,next;
}edge[MAXN<<1];
int head[MAXN],edge_num;
int ans;
int fa[MAXN];

bool cmp1(const data &q,const data &w){
	return q.x<w.x;
}
bool cmp2(const data &q,const data &w){
	return q.y<w.y;
}
bool cmp3(const E &q,const E &w){
	return q.val<w.val;
}

int Find(int x){
	if(fa[x]!=x) fa[x]=Find(fa[x]);
	return fa[x];
}

void addedge(int x,int y,int v){
	edge[++edge_num].next=head[x];
	edge[edge_num].to=y;
	edge[edge_num].from=x;
	edge[edge_num].val=v;
	head[x]=edge_num;
}

void Kruskal(){
	sort(edge+1,edge+edge_num+1,cmp3);
	int i;int cnt=0;
	for(i=1;i<=n;i++)
		fa[i]=i;
	for(i=1;i<=edge_num;i++){
		int ff=Find(edge[i].from),tt=Find(edge[i].to);
		if(ff!=tt){
			fa[ff]=tt;
			ans+=edge[i].val;
			cnt++;
			if(cnt==n-1)
				return;
		}
	}
}

void solve(){
	int i;
	sort(a+1,a+n+1,cmp1);
	for(i=2;i<=n;i++)
		addedge(a[i-1].id,a[i].id,a[i].x-a[i-1].x);
	sort(a+1,a+n+1,cmp2);
	for(i=2;i<=n;i++)
		addedge(a[i-1].id,a[i].id,a[i].y-a[i-1].y);
	Kruskal();
	printf("%d\n",ans);
}

int main(){
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i].y),a[i].id=i;
	solve();
	return 0;
}


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

#define N 200

typedef struct stack{
    int top;
    int data[N];
} Stack;

void initialize(Stack*);
void push(Stack*, int);
int pop(Stack*);
int is_empty(Stack*);

int main(){
    int in;
    Stack *stack = malloc(sizeof(struct stack));

    initialize(stack);

    while(scanf("%d", &in) != EOF){
        if(in == 0){
            printf("%d\n", pop(stack));
        }else{
            push(stack, in);
        }
    }

    free(stack);

    return 0;
}

void initialize(Stack *stack){
    stack->top = 0;
}

void push(Stack *stack, int e){
    stack->data[stack->top++] = e;
}

int pop(Stack *stack){
    if(is_empty(stack)){
        printf("Error: stack is empty.");
        return -1;
    }else{
        return stack->data[--stack->top];
    }
}

int is_empty(Stack* stack){
    return stack->top == 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)

signed main() {
    string s; cin >> s;
    int k; cin >> k;
    vector<string> v;

    int len = 1;
    while(len <= k) {
        for(int i = 0; i < s.size() - len + 1; i++) {
            v.push_back(s.substr(i, len));
        }
        len++;
    }


    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    cout << v[k - 1] << endl;
    return 0;
}


Measured memory_bytes: 1660
#!/usr/bin/env python3

import heapq
import sys
input=sys.stdin.readline

t=int(input())
for _ in range(t):
    n=int(input())
    arr=[list(map(int,input().split())) for _ in range(n)]
    q=[]
    ans=0
    camels1=[[] for _ in range(n+1)]
    camels2=[[] for _ in range(n+1)]
    for k,l,r in arr:
        ans+=min(l,r)
        if l>=r:
            camels1[k].append((l,r))
        else:
            camels2[k].append((l,r))
    for i in range(1,n+1):
        for l,r in camels1[i]:
            heapq.heappush(q,l-r)
        while len(q)>i:
            heapq.heappop(q)
    while len(q)!=0:
        ans+=heapq.heappop(q)
    for i in range(n,0,-1):
        for l,r in camels2[i]:
            heapq.heappush(q,r-l)
        while len(q)>(n-i):
            heapq.heappop(q)
    while len(q)!=0:
        ans+=heapq.heappop(q)
    print(ans)

Measured memory_bytes: 139844
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
typedef long long int llint;

int main(void){

  std::map<int, char> str;

  std::string s;
  std::cin >> s;
  for(int i=0; i<s.size(); i++){
    str[i] = s[i];
  }

  int now = s.size() + 1;
  bool reverse = false;

  int q;
  std::cin >> q;
  for(int i=0; i<q; i++){
    int t;
    std::cin >> t;
    switch(t){
    case 1:
      reverse = !reverse;
      break;
    case 2:
      int f;
      char c;
      std::cin >> f >> c;
      if(reverse) f = 3-f;
      if(f == 1) str[-(now++)] = c;
      else       str[ (now++)] = c;
    }
  }

  std::vector<char> ret;
  for(const auto& elem: str){
    //std::cout << elem.first << " " << elem.second << std::endl;
    ret.push_back(elem.second);
  }

  if(reverse) std::reverse(ret.begin(), ret.end());
  for(const auto& elem: ret){
    std::cout << elem;
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 15224
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,m,tmp,cnt=0;
  vector <int> a,spread;
  
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>tmp;
    a.push_back(tmp);
  }
  for(int i=0,tmp=1;tmp<=n;i++){ //make spread vector
    spread.insert(spread.begin(),tmp);
    tmp=3*tmp+1;
  }
  m=spread.size();
  cout<<m<<endl; //output spread amount
  for(int i=0;i<m-1;i++) cout<<spread[i]<<" ";
  cout<<spread[m-1]<<endl; //output all spread
  for(int k=0;k<m;k++) for(int i=0;i+spread[k]<n;i++){
      int end=i+spread[k],first=i%spread[k]; //list first
      // for(int j=1;j<amount;j++){ //inserting sort
        if(a[end]>a[end-spread[k]]) continue;
        int l;  
        for(l=1;l<(end-first)/spread[k]+1;l++){
          if(a[end-(l-1)*spread[k]]<a[end-l*spread[k]]){
            swap(a[end-(l-1)*spread[k]],a[end-l*spread[k]]);
            cnt++; 
          } else break;
        }
        // cout<<"check vector cnt:"<<cnt<<endl; //debug
        // for(int i=0;i<n-1;i++) cout<<a[i]<<" ";
        // cout<<a[n-1]<<endl<<endl;
    } 
  cout<<cnt<<endl; //output cnt&answer vector
  for(int i=0;i<n;i++) cout<<a[i]<<endl;
  return 0;
}


Measured memory_bytes: 6992
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    A, B = list(map(str, input().split()))

    count = 0

    for i in range(int(A), int(B) + 1):
        i = str(i)
        if (i[0] == i[4]) and (i[1] == i[3]):
            count += 1

    print(count)


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

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

    int Q;
    cin>>Q;
    int reverse_num = 0;
    Vs front_S;
    Vs S_back;
    REP(i,Q){
        int T;
        cin>>T;
        if(T==1){
            reverse_num++;
        }else{
            int F;
            string C;
            cin>>F>>C;
            if(reverse_num%2 == 0){
                if(F==1){
                    front_S.pb(C);
                }else{
                    S_back.pb(C);
                }
            }else{
                if(F==2){
                    front_S.pb(C);
                }else{
                    S_back.pb(C);
                }
            }
        }
    }

    if(reverse_num%2 == 0){
        REPD(i,front_S.size()-1) cout<<front_S[i];
        cout<<S;
        REP(i,S_back.size()) cout<<S_back[i];
        cout<<endl;
    }else{
        REPD(i,S_back.size()-1) cout<<S_back[i];
        reverse(ALL(S));
        cout<<S;
        REP(i,front_S.size()) cout<<front_S[i];
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 11760
#include <iostream>
#include <string>

int main()
{
    char c;
    int arr[26] = {};
    bool flag = 1;

    while(std::cin >> c)
    {
        arr[c - 'a']++;
    }

    for(int i = 0; i < 26; i++)
    {
        if(arr[i]%2 == 1)
        {
            flag = 0;
        }
    }

    if(flag)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.*;
import java.util.*;

public class Main{
public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int nrow, ncol;
	spreadsheet sp=new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt());
	for(int i=0;i<nrow;i++)
		for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt());
	sp.rowSum();
	sp.colSum();
	sp.show();
	}
}
class spreadsheet{
	int nrow;
	int ncol;
	int[][] cells;
	public spreadsheet(int r, int c){
		nrow=r;
		ncol=c;
		cells = new int[nrow+1][ncol+1];
	}
	public void load(int i, int j, int n){
		cells[i][j]=n;
	}
	public void rowSum(){
		for(int i=0; i< nrow; i++){
			int sum=0;
			for(int j=0;j<ncol;j++)
				sum+=cells[i][j];
			cells[i][ncol]=sum;
		}
	}
	public void colSum(){
		for(int j=0; j<= ncol; j++){
			int sum=0;
			for(int i=0;i<nrow;i++)
				sum+=cells[i][j];
			cells[nrow][j]=sum;
		}
	}
	public void show(){
		for(int i=0; i<= nrow; i++){
			for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			}
			System.out.printf("\n");
		}
	}
}

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

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

	vector<int> R( n );
	for( auto& v: R ) { cin >> v; }

	int maxv = -INT_MAX;
	int minv = R.at( 0 );

	for( int i = 1; i < n; ++i ) {
		maxv = max( maxv, R.at( i ) - minv );
		minv = min( minv, R.at( i ) );
	}

	cout << maxv << endl;
}



Measured memory_bytes: 3540
#include<stdio.h>
const int M=500000;
int a[M],b[M],count=0;
void mergeSort(int *a,int l,int r){
  int i,j,k,m;
  if(r>l){
    m=(r+l)/2;
    mergeSort(a,l,m);
    mergeSort(a,m+1,r);
    for(i=m+1;i>l;i--) b[i-1]=a[i-1];
    for(j=m;j<r;j++) b[r+m-j]=a[j+1];
    for(k=l;k<=r;k++){
      a[k]=(b[i]<b[j])?b[i++]:b[j--];
      count++;
    }
  }
}
main(){
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  mergeSort(a,0,n-1);
  for(i=0;i<n-1;i++) printf("%d ",a[i]);
  printf("%d\n%d\n",a[n-1],count);
  return 0;
}


Measured memory_bytes: 6520
import sys
readline = sys.stdin.readline
h, w, d = map(int, readline().split())
A = [list(map(int, readline().split())) for _ in range(h)]
q = int(readline())
LR = [tuple(map(lambda x:int(x)-1, readline().split())) for _ in range(q)]

D = dict()
for hi in range(h):
    for wi in range(w):
        D[A[hi][wi]-1] = [hi,wi]

DP = [0]*(h*w)
for i in range(d, h*w):
    px, py = D[i-d]
    x, y = D[i]
    DP[i] = DP[i-d] + abs(x-px) + abs(y-py)

for l,r in LR:
    print(DP[r]-DP[l])

Measured memory_bytes: 45264
/*
 * Talk is cheap, show me the code.
 * Author:  JiangDingyuan
 * Created Time:  2017/9/9 21:09:22
 * File Name: 123456.cpp
 */
#include <time.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#define PI acos(-1.0)
#define LL long long
#define bug printf("bug!\n");
#define RD freopen("in.txt", "r", stdin);
#define LD freopen("out.txt", "w", stdout);

using namespace std;
int s[100005];
int main() {
    int n;
    cin >> n;
    while(n--){
        int a, b;
        cin >> a >> b;
        s[a] = 1; s[b] = -1; 
    }
    int flag = 0;
    int ans = 0;
    for(int i = 0; i < 100005; i++){
        if(s[i] == 1){
            ans++;
            flag = 1;
        }
        else if(s[i] == -1){
            ans++;
            flag = 0;
        }
        else if(flag == 1)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#pragma GCC optimize "-O3"
#pragma GCC target "tune=native"
using namespace std;
const int N = 1e9;
int main(){
    int n;
    cin >> n;
    while(n--){
        char c;
        cin >> c;
        if(c == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#define CO(a, b, c) ((a)?(b):(c))
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;

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

Measured memory_bytes: 3584
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	string s;
	cin >> s;
	if (s == "SUN")
		dump(7);
	else if (s == "MON")
		dump(6);
	else if (s == "TUE")
		dump(5);
	else if (s == "WED")
		dump(4);
	else if (s == "THU")
		dump(3);
	else if (s == "FRI")
		dump(2);
	else if (s == "SAT")
		dump(1);
	return 0;
}


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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, x, sum = 0, ans = 0;
    cin >> n >> m;
    vector < int > a;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        sum += x;
        a.push_back(x);
    }
    for (auto key : a) if (key * 4 * m >= sum) ans++;
    if (ans >= m) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}



Measured memory_bytes: 256
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
using namespace std; 
 
const int N = 1e5 + 10000, OO = 1e9, M = 998244353, P = 6151, SQ = 1000, lg = 12;
typedef pair <int, int> pii;
int a[5], dp[N][5];

int32_t main() {
    use_fast;
	int n, k;
	cin >> n >> k >> a[0] >> a[1] >> a[2];
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < k; i++) {
		vector <char> v;
		for(int j = i; j < n; j += k)
			v.pb(s[j]);
		dp[0][0] = 0, dp[0][1] = 0, dp[0][2] = 0;
		if(v[0] == 's')
			dp[0][0] = a[0];
		else if(v[0] == 'p')
			dp[0][1] = a[1];
		else 
			dp[0][2] = a[2];
		for(int i = 1; i < (int)v.size(); i++) {
			if(v[i] == 's') {
				dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[0];
				dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]);
				dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]);
			}
			else if(v[i] == 'p') {
				dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[1];
				dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]);
				dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]);				
			}
			else {
				dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[2];
				dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]);
				dp[i][0] = max(dp[i - 1][2], dp[i - 1][1]);
			}
		}
		int sz = (int)v.size() - 1;
		ans += max(dp[sz][0], max(dp[sz][1], dp[sz][2]));
	}
	cout << ans << endl;
	return 0; 
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/	

Measured memory_bytes: 4736
#include <iostream>

using namespace std;

int main()
{
    int A,B,C,D,E;
    cin >> A >> B >> C >> D >> E;
    if(B>0) {
        if(A>0) {
            cout << E*(B-A) << endl;
        } else {
            cout << -A*C+D+E*B << endl;
        }
    } else {
        cout << C*(B-A) << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
input_line = list(map(int, input().split()))

N = input_line[0]
K = input_line[1]
RESULT = []
count = 0

for i in range(K):
    d = int(input())
    input_who = list(map(int, input().split()))
    RESULT.extend(input_who)


for i in range(N):
    if i + 1 not in RESULT:
        count += 1
print(count)

Measured memory_bytes: 67732
/**
*    created: 13.06.2020 21:27:52
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    //k = min(k, 2 + (int)log2(n));
    for (int l = 1; l <= k;l++)
    {
        vector<int> b(n+1);
        rep(i,n){
        b[min(i + a[i]+1, n)] --;
        b[max(0, i - a[i])] ++;
        }
        for (int i = 0; i < n; i++){
            b[i+1] += b[i];   
            }
            b.pop_back();
            if(a==b)
                break;
            rep(i, n) a[i] = b[i];
    }
    rep(i,n)cout << a[i] <<" ";
    cout << endl;
}
/*
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    rep(t, K)
    {
        vector<int> imos(N + 1);
        rep(i, N)
        {
            imos[max(i - A[i], 0)]++;
            imos[min(i + A[i] + 1, N)]--;
        }
        rep(i, N) imos[i + 1] += imos[i];
        imos.pop_back();
        if (A == imos) break;
        A = imos;
    }
    rep(i, N) cout << A[i] << ' ';
    cout << '\n';
}*/

Measured memory_bytes: 4840
n = int(input())
h = list(map(int, input().split()))

# 右側に2以上小さい数字があったらダメ
minh = 10**9
for i in reversed(h):
    if i >= minh + 2:
        print('No')
        exit()
    minh = min(minh, i)
print('Yes')    

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

int main(void){
    int n;
    cin >> n;
    
    if (n == 1) {
        cout << "Hello World" << endl;
    } else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n;
const int MAX = 1e5+5;

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

    vector<vector<int>> vals(n);
    for(int i=0;i<m;i++){
        vals[p[i]].push_back(y[i]);
    }

    for(int v=0;v<n;v++){
        sort(vals[v].begin(),vals[v].end());
        vals[v].erase(unique(vals[v].begin(),vals[v].end()),vals[v].end());
    }
    
    for(int i=0;i<m;i++){
        int v = p[i];
        printf("%06d",v+1);
        int id = lower_bound(vals[v].begin(),vals[v].end(),y[i]) - vals[v].begin();
        printf("%06d\n",id+1);

    }
}


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

int main() {
  int H,N;
  cin >> H >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  int atackkk = 0;

  for (int i = 0; i < N; i++) {
    atackkk += A.at(i);
  }

  if (atackkk >= H) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;

int ans[10000]={};

int main(){
    priority_queue<int,vector<int>,greater<int>> pq;
    int W,H,N;
    int pcount=0;
    cin >> H >> W;
    cin >> N;
    for(int i=0;i<N;i++){
      int tmp;
      cin >> tmp;
      for(int j=0;j<tmp;j++){
        pq.push(i+1);
        pcount++;
      }
    }
    int qcount=0;
    for(int i=0;i<H*W;i+=W){
      for(int j=0;j<W;j++){
        if((i/W)%2==0){
          ans[i + j] = pq.top();
          //cout << i +j << endl;
          //cout << pq.top()<<endl;
          qcount++;
          pq.pop();
        }else{
          ans[i+W - (j+1)] = pq.top();
          //cout << pq.top()<<endl;
          //cout << 2*i - (j+1) << endl;
          qcount++;
          pq.pop();
        }
      }
    }
    for(int i=0;i<W*H;i++){
      cout << ans[i] << " ";
      if((i+1)%W==0){
        cout << endl;
      }
    }

    //cout<<pcount<< " "<< qcount << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	double n;
	cin >> n;
	double ans=n/3;
	ans=pow(ans,3);
	cout << fixed << setprecision(12);
	cout << ans << endl;
	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    for(int i=0;i<S.length();++i){
        if(i%2 == 0&&S[i]=='L'){
            cout<<"No"<<endl;
            return;
        }
        if(i%2 == 1&&S[i]=='R'){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256