akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
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; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n; ll k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    rep(i, n) --a[i];
    
    vector<vector<int> > d(n, vector<int>(64));
    rep(i, n) d[i][0] = a[i]; // 2^0 = 1
    
    rep3(i, 1, 64) {
        rep(j, n) {
            d[j][i] = d[d[j][i - 1]][i - 1];
        }
    }
    
    int g = 0;
    rep(i, 64) {
        if (k & (1LL << i)) {
            g = d[g][i];
        }
    }
    cout << g + 1 << endl;
}


Measured memory_bytes: 61808
#include<bits/stdc++.h>
using namespace std;
int a[100005];
long long ans;
int main()
{
    int n,x;
    scanf("%d %d",&n,&x);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    if(a[0]>x)ans+=a[0]-x,a[0]=x;
    for(int i=1;i<n;i++)
        if(x-a[i]<a[i-1])ans+=a[i]-x+a[i-1],a[i]=x-a[i-1];
    cout<< ans<<endl;
    return 0;
}


Measured memory_bytes: 640
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll N, R;
    cin >> N >> R;
    if(N < 10)R += 100 * (10 - N);
    cout << R << endl;

    return 0;
}

Measured memory_bytes: 256
require "prime"
require "set"
n = gets.to_i

p_set = Prime.each(n).to_set
p_num_hash = {}
p_num_arr = []
(1..n).each do |i|
  if p_set.include?(i)
    p_num_hash[i] = 1
    p_num_arr[i] = [i]
    next
  end
  
  p_set.each do |num|
    break if i < num

    if i % num == 0
      p_num_arr[i] = p_num_arr[i / num] + [num]
      p_num_arr[i].each do |prime|
        p_num_hash[prime] += 1
      end
      break
    end
  end
end

mod = 10 ** 9 + 7
count = 1
p_num_hash.each do |_k, num|
  count = count * (num + 1) % mod
end

puts count


Measured memory_bytes: 14580
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s=scan.nextLine();
		int c=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='+') c+=1;
			else c-=1;
		}
		System.out.println(c);
		
	}

}


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

int main(){
	// your code goes here
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	cout.tie(NULL);
	
	int m,n;
	cin>>n>>m;
	if(n==m){
	    cout<<"Yes";
	}
	else{
	    cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int dp[50];
int fibonacci(int x){
  if(x==0 || x==1) return dp[x]=1;
  if(dp[x]!=0) return dp[x];
  return dp[x]=fibonacci(x-1)+fibonacci(x-2);
}
int main(){
  int n;
  cin>>n;
  cout<<fibonacci(n)<<endl;
  return 0;
}

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

main(){
  int n,q;
  cin>>n;
  vector<int>v(n);
  r(i,n)cin>>v[i];
  cin>>q;
  while(q--){
    int l,r;
    cin>>l>>r;
    reverse(v.begin()+l,v.begin()+r);
  }
  r(i,n){
    if(i)cout<<' ';
    cout<<v[i];
  }
  cout<<endl;
}


Measured memory_bytes: 3096
use proconio::{fastout, input};
use std::cmp::Ordering;
use std::collections::{BinaryHeap, HashSet};

#[derive(Debug, Eq, PartialEq)]
struct Query {
    num: u64,
    cost: u64,
}

impl Ord for Query {
    fn cmp(&self, other: &Self) -> Ordering {
        self.cost.cmp(&other.cost).reverse()
    }
}

impl PartialOrd for Query {
    fn partial_cmp(&self, other: &Query) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

fn solve() {
    input! {n:u64, a:u64, b:u64, c:u64, d:u64};
    let mut queue = BinaryHeap::new();
    let mut seens = HashSet::new();
    let threshold = 1e+20 as u64 / d;

    queue.push(Query { num: n, cost: 0 });

    while !queue.is_empty() {
        let query = queue.pop().unwrap();

        if query.num == 0 {
            println!("{}", query.cost);
            return;
        }

        if seens.contains(&query.num) {
            continue;
        }

        seens.insert(query.num);

        if query.num <= threshold {
            queue.push(Query {
                num: 0,
                cost: query.cost + query.num * d,
            })
        }

        for [k, p] in [[2, a], [3, b], [5, c]].iter() {
            if query.num < *k {
                continue;
            }

            let dval = query.num / *k;
            let mval = query.num % *k;

            if mval == 0 {
                queue.push(Query {
                    num: dval,
                    cost: query.cost + p,
                });
            } else {
                queue.push(Query {
                    num: dval,
                    cost: query.cost + p + d * mval,
                });
                queue.push(Query {
                    num: dval + 1,
                    cost: query.cost + p + d * (*k - mval),
                });
            }
        }
    }

    panic!("not finished");
}

#[fastout]
fn main() {
    input! {t: usize};

    for _ in 0..t {
        solve();
    }
}


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int h, w;
std::pair<int, bool> r[2005][2005];
std::pair<int, bool> c[2005][2005];
int main() {
	std::cin >> h >> w;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j) {
			char s;
			std::cin >> s;

			if (s == '#') {
				r[i][j].first = 0;
				r[i][j].second = true;
				c[i][j].first = 0;
				c[i][j].second = true;
			}
			else {
				auto b1 = i == 0 || r[i - 1][j].first == 0 && r[i - 1][j].second == true;
				auto b2 = j == 0 || c[i][j - 1].first == 0 && c[i][j - 1].second == true;
				auto b3 = i != 0 && r[i - 1][j].first != 0 && r[i - 1][j].second;
				auto b4 = j != 0 && c[i][j - 1].first != 0 && c[i][j - 1].second;
				if (b1) {
					r[i][j].first = 1;
					r[i][j].second = true;
				}
				if (b2) {
					c[i][j].first = 1;
					c[i][j].second = true;
				}
				if (b3) {
					r[i][j].first = i - 1;
					r[i][j].second = false;
					r[i - 1][j].first += 1;
				}
				if (b4) {
					c[i][j].first = j - 1;
					c[i][j].second = false;
					c[i][j - 1].first += 1;
				}
				if (!b1 && !b3) {
					auto ri = r[i - 1][j].first;
					r[i][j].first = ri;
					r[i][j].second = false;
					r[ri][j].first += 1;
				}
				if (!b2 && !b4) {
					auto cj = c[i][j - 1].first;
					c[i][j].first = cj;
					c[i][j].second = false;
					c[i][cj].first += 1;
				}
			}
		}

	int ans = 0;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j) {
			auto rr = r[i][j];
			auto cc = c[i][j];
			if (rr.first == 0 && rr.second == true)
				continue;

			int tmp = 0;
			if (rr.second == true)
				tmp += rr.first;
			else
				tmp += r[rr.first][j].first;
			if (cc.second == true)
				tmp += cc.first;
			else
				tmp += c[i][cc.first].first;

			ans = std::max(ans, tmp);
		}

	std::cout << ans - 1 << std::endl;
	return 0;
}


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

int main()
{
    int N, K, sum;
    int x;
    int i;

    cin >> N >> K;

    for (i = 0; i < N; i++)
    {
        cin >> x;
        if (x * 2 < (K - x) * 2)
        {
            sum += x * 2;
        }else{
            sum += (K - x) * 2;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
def main():
    x, k, d= map(int, input().split())
    if x == 0:
        if k%2 == 0:
            print(0)
            return
        else:
            print(d)
            return
    else:
        if x < 0:
            x = -1*x
        if k*d <= x:
            print(x-k*d)
            return
        else:
            y = x//d
            p = x-d*y
            nokori = k - y
            if nokori%2 == 0:
                print(p)
            else:
                print(d-p)
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
#include<iostream>
#include<string>
using namespace std;
long long n,a[200010];
const int mod=1000000007;
int main()
{
	int n;
	cin>>n;
	long long s=0,sum=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		sum-=a[i];
		s=(((a[i]%mod)*(sum%mod)%mod)+s)%mod;
	}
	cout<<s<<endl;
	return 0;		
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (a).size()
#define pb(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr double EPS = 1e-10;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int X, Y;
  cin >> X >> Y;
  if (X % Y == 0) cout << -1 << endl;
  else cout << X << endl;

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool res = false;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      if (i * j == N) res = true;
    }
  }
  if (res) cout << "Yes" << endl;
  else cout << "No" << endl;}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n + 1), b(m + 1);
	rrep(i, n + 1) cin >> a[i], a[i] += a[i - 1];
	rrep(i, m + 1) cin >> b[i], b[i] += b[i - 1];
	int ans = 0;
	rep(i, n + 1) {
		ll tmp = k - a[i];
		if (tmp < 0) continue;
		int d = upper_bound(b.begin(), b.end(), tmp) - b.begin();
		maxs(ans, i + 1 + d - 2);
	}
	cout << ans << endl;
	return 0;
}


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


def cut(x):
    cut_count = 0
    for i in range(n):
        cut_count += (a[i]-1)//x
    return cut_count


l = 0
r = 10**9
while r-l > 1:
    mid = (l+r)//2
    if k >= cut(mid):
        r = mid
    else:
        l = mid
print(r)



Measured memory_bytes: 104072
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	for(int w;cin>>w,~w;){
		int p=1150;			w-=min(w,10);
		p+=125*min(w,10);	w-=min(w,10);
		p+=140*min(w,10);	w-=min(w,10);
		p+=160*w;
		cout<<4280-p<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;

int main() {
    
    
    int n;
    cin >> n;
    vector<int> a(n, -1);
    
    for (int i = 0; i < n; ++i)
    {
        int tmp;
        cin >> tmp;
        *upper_bound(a.begin(), a.end(), tmp, greater<>()) = tmp;
    }
    int ret = 0;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] != -1)
        {
            ret++;
        }
    }
    
    cout << ret << endl;
    
    return 0;
}

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

#define LL long long
#define VI vector<int>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

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

using namespace std;

#define INF (int)1e9


int N;
vector<vector<int>> graph;
vector<vector<int>> dp; // dp[状態][今いるところ] = 総距離

int rec(int S, int v) {
    if (dp[S][v] >= 0) {
        return dp[S][v];
    }

    // すべて巡回して0に戻ってきた
    if(S == (1 << N) - 1 && v == 0) {
        return dp[S][v] = 0;
    }

    int tmp = INF;
    FOR(u, 0, N) {
        // まだuにいってない
        if(not (S >> u & 1)) {
            tmp = min(tmp, rec(S | 1 << u, u) + graph[v][u]);
        }
    }
    return dp[S][v]=tmp;
}

int main() {
    int m;
    cin >> N >> m;
    graph.resize(N, vector<int>(N, INF));

    FOR(i, 0, m) {
        int a, b, c;
        cin >> a >> b >> c;
        graph[a][b] = c;
    }
    dp.resize(1 << N, vector<int>(N, -1));
    int ans = rec(0, 0);
    if (ans == INF) {
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6212
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> color(3);
    color[0] = 1;
    color[1] = 0;
    color[2] = 0;

    if (A[0] != 0) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for(int i = 1; i < N; i++) {
        int cnt = 0;
        bool pa = false;
        REP(j, 3) {
            if (A[i] == color[j]) {
                if (pa == 0) {
                    color[j]++;
                    pa = 1;
                }
                cnt++;
            }
        }
        // cout << cnt << " " << ans << endl;
        
        ans *= cnt;
        ans %= MOD;
    }

    cout << ans * 3 % MOD << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define lli long long int
#define pb(a) push_back(a)
#define forr(a,n) for(lli i=a;i<n;i++)
#define forrr(j,a,n) for(lli j=a;j<n;j++)
#define all(x) x.begin(),x.end()
#define pi2  1.57079632679489661923
using namespace std;
void print(lli a[],lli n){
forr(0,n){cout<<a[i]<<" ";}
cout<<"\n";
}
lli power(lli x){
lli u=0;
while(x%2==0){
    u++;
    x=x/2;
}
return u;
}

lli powM(lli x,lli y,lli m)
{
    lli ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
int powm(lli a, lli b) {
	lli res = 1;
	while (b) {
		if (b & 1)
			res = (res * a);
		a = (a * a);
		b >>= 1;
	}
	return res;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
/*
vector <lli> adj[100001];
lli vis[100001]={0};
void dfs(lli a){
    vis[a]=1;
    forr(0,adj[a].size()){
    if(vis[adj[a][i]]){continue;}
    else{
        dfs(adj[a][i]);
    }
    }
}
lli level[100001];
void bfs(lli a){
queue <lli> q;
vis[a]=1;
level[a]=0;
q.push(a);
while(!q.empty()){
    lli p=q.front();
    q.pop();
    forr(0,adj[p].size()){
    if(vis[adj[p][i]]==0){
        level[adj[p][i]]=level[p]+1;
        q.push(adj[p][i]);
        vis[adj[p][i]]=1;
    }
    }

}

}

vector <pair<lli,lli> > dj[100001];
lli dist[100001];
vector<lli> ans[100001];
void dijkstra(lli a){
dist[a]=0;
ans[a].pb(a);
multiset<pair<lli,lli> > s;
s.insert({0,a});
while(s.size()!=0){
    lli x=(*s.begin()).second;
    s.erase(s.begin());
    if(vis[x]){continue;}
    vis[x]=1;
    forr(0,dj[x].size()){
    lli e=dj[x][i].first;
    lli we=dj[x][i].second;
    if(dist[x]+we<dist[e]){
        dist[e]=dist[x]+we;
        ans[e].clear();
        ans[e].pb(x);
        s.insert({dist[e],e});
    }
    }
}

}
*/
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
   cout.tie(0);
   // freopen("outpu.txt","w",stdout);
int t1=1;
//cin>>t1;
lli M =1e9+7;
while(t1--){
lli l,r,d;
cin>>l>>r>>d;
if(l%d==0){l=l/d;
l--;}
else{
l=l/d;}
r=r/d;
cout<<r-l;
}
     return 0;
}


Measured memory_bytes: 3604
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  const S=input[1];
  var ans=0;
  for(var i=0;i<=S.length-3;i++){
    if(S.slice(i,i+3)==='ABC'){
      ans++;
    }
  }
  console.log(ans);
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



  


Measured memory_bytes: 29572
# coding: utf-8
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
F = [True] * len(T)
point = {"r": P, "s":R, "p":S}
ans = 0
for i in range(N):
    if i < K:
        ans += point[T[i]]
        F[i] = False
    # elif i+K <= len(T) - 1:
    else:
        if T[i] == T[i-K]:
            if F[i-K]:
                ans += point[T[i]]
                F[i] = False
            # else:
            #     F[i] = False
        else:
            ans += point[T[i]]
            F[i] = False
    # print(ans)
print(ans)

Measured memory_bytes: 4084
import java.util.*;
public class Main {

  public static void main(String[] args) {

     Scanner in = new Scanner(System.in);

     String str = in.nextLine();

     int len = str.length() - 2;

     System.out.println(str.substring(0, 1) + len + str.substring(len+1,len+2));

     in.close();
  }
}

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

typedef long long ll;

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

    int n;
    string s;
    cin >> n >> s;
    string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(int i=0;i<s.size();i++){
        if((char)(s[i]+n)>'Z') cout << alphabet[(char)(s[i]+n)-'Z'-1];
        else cout << (char)(s[i]+n);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000  //int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

   int a, b;
   string ans;
   cin >> a >> b;
   if(a <= 0 && b >= 0) ans = "Zero";
   elif(a > 0) ans = "Positive";
   elif(b < 0){
      if((abs(a)-abs(b)) % 2 == 0) ans = "Negative";
      else ans = "Positive";
   }
   cout << ans << endl;
   rtn 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	string s; cin >> s;
	bool a = true;
	int n = s.size();

	rep(i, (n - 1) / 2) if (s[i] != s[n - 1 - i]) a = false;
	rep(i, (n - 3) / 4) if (s[i] != s[(n - 3) / 2 - i]) a = false;
	for (int i = (n + 1) / 2; i < (3 * n + 3) / 4; i++) if (s[i] != s[(3 * n - 1) / 2 - i]) a = false;

	if (a) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(int i=1;i<n;i++)
#define out(s) cout << s << endl

int main(){
    int n;cin >> n;
    vector<ll> a(n);
    ll ans=0;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        ans+=a[i]-1;
    }
    out(ans);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll A,B,C,D;
    cin>>A>>B>>C>>D;
    A-=1;
    //s(B-A,(B/C-A/C),(B/D-A/D),(B/(C*D)-A/(C*D)))
    cout<<(B-A)-((B/C-A/C)+(B/D-A/D)-(B/lcm(C,D)-A/lcm(C,D)));
    
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
<?php
	fscanf(STDIN, "%s %s %s", $A, $B, $C);
	if(substr(strrev($A), 0, 1) === substr($B, 0, 1) && substr(strrev($B), 0, 1) === substr($C, 0, 1)){
		echo 'YES';
	}else{
		echo 'NO';
	}
?>

Measured memory_bytes: 4604
#define _USE_MATH_DEFINES
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
typedef long long int LL;
typedef pair<int,int> P;

int main() {
	int a,b,k;
	cin >> a >> b >> k;
	int ans = min(a,b)+1;
	for(int i = 0;i < k;i++) {
		ans--;
		while((a%ans!=0)||(b%ans!=0)) ans--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int64_t a[100'000];
int64_t da[100'000];
int64_t c[100'000];

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

    int64_t u = (int64_t)n * (n + 1) / 2;
    int64_t s = 0;
    for (int i = 0; i < n; i++)
    {
        s += a[i];
        da[i] = a[(i + 1) % n] - a[i];
    }

    if (s % u != 0)
    {
        cout << "NO" << endl;
        return 0;
    }

    int64_t f = s / u;
    for (int i = 0; i < n; i++)
    {
        int64_t cc = f - da[i];
        if (cc < 0 || cc % n != 0)
        {
            cout << "NO" << endl;
            return 0;
        }
        c[i] = cc / n;
    }

    int64_t csum = 0;
    for (int i = 0; i < n; i++)
    {
        csum += c[i];
    }

    if (csum == f)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 2560
X = int(input())
flag = True
import numpy as np
if X == 2:
  print(X)
  flag = False
while flag:
  temp_flag = True
  for i in range(int(np.sqrt(X))+1):
    if X % (i + 2) == 0:
      temp_flag = False
      break
  if temp_flag:
    print(X)
    flag = False
    break
  X += 1

Measured memory_bytes: 21540
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length()<=k)cout<<s;
    else{
        string x=s.substr(0,k);
        x+="...";
        cout<<x;
    }
    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    vector<pair<string, int>> pairs;
    rep (i, 0, N) {
        string s; int p; cin >> s >> p;
        pairs.push_back(make_pair(s, p));
    }
    vector<size_t> indices(pairs.size());
    iota(indices.begin(), indices.end(), 0);

    sort(indices.begin(), indices.end(), [&pairs](size_t i1, size_t i2) {
        if (pairs[i1].first == pairs[i2].first) {
            return pairs[i1].second > pairs[i2].second;
        } else {
            return pairs[i1].first < pairs[i2].first;
        }
    });

    rep (i, 0, indices.size()) cout << indices[i]+1 << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

//only for variables and vi;
template <class TH>
void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a)
{
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/
string s;
ll d, n, dp[10010][2][100];  

ll fn(ll i, ll f, ll sum) { 
  if(i == n) {
    return !sum;
  }
  ll &res = dp[i][f][sum];
  if(res != -1) return res;
  res = 0;
  ll curdig = s[i] - 48;
  for(ll dig = 0; dig <= 9; dig++) {
    if(!f && dig > curdig) 
      break;
    res += fn(i + 1, f | (dig < curdig), (sum + dig) % d);
    if(res >= mod) 
      res -= mod;
  }
  return res;
}

main()
{
  memset(dp, -1, sizeof(dp));
  cin >> s >> d;
  n = s.length();
  ll ans = fn(0, 0, 0);
  ans--;
  if(ans < 0) {
    ans += mod;
  }
  cout << ans;
}


Measured memory_bytes: 16640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] a = new int[m];
    int[] b = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    for(int i = 0; i < m; i++) {
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    long[] dp = new long[n + 1];
    for(int i = 1; i <= n; i++) {
      long t = (-1) * (long)Math.pow(10, 10);
      for(int j = 0; j < m; j++) {
        if(i >= b[a[j] - 1]) t = Math.max(t, 1 + dp[i - b[a[j] - 1]]); 
      }
      dp[i] = t;
    }
    String ans = "";
    int c = n;
    for(int i = 1; i <= (int)dp[n]; i++) {
      for(int j = m - 1; j >= 0; j--) {
        if((c >= b[a[j] - 1]) && (dp[c] == (1 + dp[c - b[a[j] - 1]]))) {
          ans += a[j];
          c -= b[a[j] - 1];
          break;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 61656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define MOD 1000000007
#define pi 3.1415926535897932
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second
const int MAX = 510000;
typedef long long ll;

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

// 二項係数計算
long long COM(ll n, ll k) {
    ll res = 1;
    for(int i = 0; i < k; i++) {
        res *= n - i;
        res %= MOD;
        res = res*modinv(i+1, MOD)%MOD;
    }

    return res%MOD;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

void solve1() {
    int n, a, b; cin >> n >> a >> b;

    ll sum = modpow(2, n, MOD);
    sum --;
    if(sum < 0) {
        sum += MOD;
    }

    sum -= COM(n, a);
    if (sum < 0)
    {
        sum += MOD;
    }

    sum -= COM(n, b);
    if (sum < 0)
    {
        sum += MOD;
    }

    cout << sum << endl;
}

int main()
{
    solve1();
}


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

int main(){
	int x , i ;
	i = 0 ;
	 while( 1 ){
		 cin >> x ;
		 if( x==0 ){break ; }
	    i += 1 ;
		cout << "Case" << " " << i << ":" << " " << x << endl ;
	 }
	
	
	return 0 ;
}

Measured memory_bytes: 1160
#include <iostream>
#include <map>

using namespace std;

int main() {
    map<string, int> num;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        num[s]++;
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        num[s]--;
    }
    int maxi = 0;
    for (auto p : num) {
        maxi = max(maxi, p.second);
    }
    cout << maxi << "\n";
    return 0;
}

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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

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

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long N;
	scanf("%lld",&N);
	long long A;
	scanf("%lld",&A);
	long long B;
	scanf("%lld",&B);
	--N, --A, --B;

	ll diff = B - A;
	ll goal = LONG_LONG_MAX;
	if (diff % 2 == 0)
	{
		goal = diff / 2;
	}
	else
	{
		ll t1, t2;
		t1 = N - B + 1 + (N - A - (N - B + 1)) / 2;
		t2 = A + 1 + (B - (A + 1)) / 2;
		goal = min(t1, t2);
	}
	goal = min(goal, N - A);
	goal = min(goal, B);
	cout << goal << endl;

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a;
    for(int i=0; i<n; i++){
        int aa;
        cin >> aa;
        a.push_back(aa);
    }

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int b, e;
        cin >> b >> e;
        reverse(a.begin()+b, a.begin()+e);
    }
    for(int i=0; i<n-1; i++){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
    return 0;
}


Measured memory_bytes: 3172
from itertools import product
import numpy as np

d, g = map(int, input().split())
p = np.empty(d, dtype=np.int64)
c = np.empty(d, dtype=np.int64)
for i in range(d):
    p[i], c[i] = map(int, input().split())

scores = np.array([p[i] * 100 * (i + 1) + c[i] for i in range(d)], dtype=np.int64)

ans = 10 ** 9
for permutation in product([0, 1], repeat=d):
    permutation = np.array(permutation, dtype=np.int64)
    score = np.inner(scores, permutation)
    problems = np.inner(p, permutation)
    if score >= g:
        ans = min(ans, problems)
    else:
        to_solve = np.max(np.where(permutation == 0))
        extra = -(-(g - score) // (100 * (to_solve + 1)))
        if extra < p[to_solve]:
            ans = min(ans, problems + extra)
print(ans)



Measured memory_bytes: 12460
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define lli long long int
#define llu long long unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,s,e) for(i=s; i<e; i++)
#define F first
#define S second
#define plli pair<lli,lli>
#define pqlli priority_queue<lli>
#define test(t) cin>>t; while(t--)
#define MX 5003
using namespace std;

int main() 
{
	IOS;
	int n,m;
	cin>>n>>m;
	int ans = (n*(n-1))/2 + (m*(m-1))/2;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
from decimal import *
N=Decimal(input())
X=Decimal(N/Decimal("1.08"))
X=int(X)
if int(X*Decimal("1.08"))==int(N):
    print( '{:.10g}'.format(int(X)))
elif int((X+1)*Decimal("1.08"))==int(N):
    print( '{:.10g}'.format(int(X+1)))
else:
    print(str(':('))

Measured memory_bytes: 5076
#include <stdio.h>
int main(){
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b);
  d=a/b;
  r=a%b;
  f=(double)a/(double)b;
 
  printf("%d %d %f\n",d,r,f);
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

#define MAX_N 100010

using namespace std;

typedef priority_queue<long, vector<long>, greater<long>> minpq; 

long a[MAX_N];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i=0; i<n; i++) cin >> a[i];
    vector<int> G[n];
    for (int i=0; i<m; i++) {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    if (n - 1 - m == 0) {
        cout << 0 << '\n';
        return 0;
    } else if (2 * (n - 1 - m) > n) {
        cout << "Impossible" << '\n';
        return 0;
    }
    bool used[MAX_N] = {0}, visited[MAX_N] = {0};
    long ans=0;
    for (int i=0; i<n; i++) {
        if (!visited[i]) {
            int best=i;
            queue<int> bfs;
            bfs.push(i);
            while (!bfs.empty()) {
                int now = bfs.front(); bfs.pop();
                visited[now] = true;
                if (a[now] < a[best]) best = now;
                for (auto g:G[now]) {
                    if (visited[g]) continue;
                    bfs.push(g);
                }
            }
            used[best] = true;
            ans += a[best];
        }
    }
    minpq pq;
    for (int i=0; i<n; i++) {
        if (used[i]) continue;
        pq.push(a[i]);
    }
    int cnt = n - m - 1, remain = (cnt) * 2 - cnt - 1;
    for (int i=0; i<remain; i++) {
        ans += pq.top(); pq.pop();
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back

int main()
{

   int n;
   cin >> n;
   int seq[n], points[n], extra[n];
   for(int i = 0; i < n; i++)cin >> seq[i];
   for(int i = 0; i < n; i++)cin >> points[i];
   for(int i = 0; i < n-1; i++)cin >> extra[i];

   ll sum = 0, last = -100;
   for(int i = 0; i < n; i++)
   {
       int dish = seq[i];
       if( dish == last+1)sum += extra[last-1];

       sum += points[dish-1];
       last = dish;
   }

   cout << sum << endl;


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n, m, res;
vs target;
set<string> s;

void dfs(int, string);

int main(void){
    for(; cin >> n >> m; cout << res << endl){
        res = inf;
        s.clear();

        string str;
        rep(i, n){
            char c; cin >> c;
            str.pb(c);
        }

        target = vs(2);
        bool zero = false;
        rep(i, m){
            int p; cin >> p;

            rep(j, p){
                target[0].pb(zero ? '0':'1');
                target[1].pb(zero ? '1':'0');
            }
            zero = !zero;
        }

        queue< pair<string, int> > q;
        q.push(mp(str, 0));

        while(!q.empty()){
            string curstr = q.front().first;
            int curcnt = q.front().second;
            q.pop();

            if(!s.insert(curstr).second) continue;

            if(curstr == target[0] || curstr == target[1]){
                res = curcnt;
                break;
            }

            rep(i, n - 1){
                string next = curstr;
                swap(next[i], next[i + 1]);

                q.push(mp(next, curcnt + 1));
            }
        }
    }

	return 0;
}

Measured memory_bytes: 2184
#include<bits/stdc++.h>
#define FastRead                      \
                                    ios_base::sync_with_stdio(false); \
                                    cin.tie(0);
#define ll long long
#define endl "\n"
#define f for
#define pi acos(-1)
using namespace std;
int main()

{
    FastRead
    ll int t,j,i,n;
    //cin>>t;
    //f(j=0;j<t;j++)
    //{
    cin>>n;
    ll int a[n],c=0,mn;
    f(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    f(i=0; i<n; i++)
    {
        if(i==0)
            mn=a[i];
        else
        {
            if(a[i]<mn)
            {
                c++;
                mn=a[i];
            }
        }

    }
    cout<<c+1<<endl;;

    //}
    return 0;
}



Measured memory_bytes: 5220
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int arr[n],i;
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+n);
	int j,k,count=0;
	for(i=2;i<n;i++)
	{
		for(j=1;j<i;j++)
		{
			for(k=0;k<j;k++)
			{
				if(arr[i]==arr[j]||arr[j]==arr[k])
				{
					continue;
				}
				else
				{
					if(arr[j]+arr[k]>arr[i])
					{
						count++;
					}
				}
			}
		}
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 3660
using System;
using System.Collections.Generic;

namespace AtCoder2020Ned
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(" ");

            var one = int.Parse(input[0]);
            var zero = int.Parse(input[1]);
            var minusOne = int.Parse(input[2]);
            var pick = int.Parse(input[3]);

            var currentPicked = 0;
            var sum = 0;

            for (int i = 0; one > 0 && pick > 0; i++)
            {
                sum++;
                one--;
                pick--;
            }
            for (int i = 0; zero > 0 && pick > 0; i++)
            {
                zero--;
                pick--;
            }
            for (int i = 0; minusOne > 0 && pick > 0; i++)
            {
                sum--;
                minusOne--;
                pick--;
            }

            Console.WriteLine(sum);
            Console.Read();
        }
    }
}


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

int main(){

    int n, m;
    while(true){
        cin>>n>>m;
        if(n==0)break;
        vector<int>vec(m+1, 0);
        for(int i=0;i<n;i++){
            int d, v;
            cin>>d>>v;
            vec[d] = max(vec[d], v);
        }
        int ans=0;
        for(int i=1;i<=m;i++){
            ans+=vec[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main()
{
   long long int i,j,k,l,m,n,p,q,e,x;
      cin>>n>>k;
      long long int A[n+1];
       for(i=0;i<=n;i++)
       {
         A[i]=k;
       }
     cin>>q;
  e=q;
  while(q--)
  {
    cin>>x;
    A[x]++;
  }
  for(i=1;i<=n;i++)
  {
    A[i]=A[i]-e;
  }
  for(i=1;i<=n;i++)
  {
    if(A[i]>0)
      cout<<"Yes\n";
    else
      cout<<"No\n";
  }
  
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
long long int pow2[61] = {}; 
long long int dp[300010] = {}; 
long long int pow3[61] = {}; 
long long int P = 1e9 + 7; 
long long int ans(long long int n){
	if(n < 300000 && dp[n] > -1){return dp[n];}
        if(n == 0){
         		return dp[0] = 1; 
        }
		int a = upper_bound(pow2, pow2 + 61, n) - pow2; 
		long long int b = pow2[a] - n; 
		if(b == 1){
			if(n < 300000){return dp[n] = (pow3[a] + 1)/2 % P;}
			else{return (pow3[a] + 1)/2 % P;}
		}
		else{
			long long int Q = (P + pow3[a-1] + ans(n - pow2[a-1]) - ((n == pow2[a] - 2) ? 0 : ans(pow2[a] - n - 3))) % P;
			if(n < 300000){return dp[n] = Q;}
			else{return Q;} 		
		} 
	}
int main() {
	pow2[0] = 1, pow3[0] = 1; 
	for(int i = 1; i <= 60; i++){
		pow2[i] = pow2[i-1] * 2; 
		pow3[i] = (pow3[i-1] * 3) % P; 
	}
	for(int i = 0; i < 300000; i++){
		dp[i] = -1;  
	}
	long long int N; 
	cin >> N; 
	cout << ans(N) << endl; 
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
    int N;
    cin >> N;
    bool F[N][10];
    int P[N][10];
    rep(i,N) rep(j,10) cin >> F[i][j];
    rep(i,N) rep(j,11) cin >> P[i][j];

    long long res=LONG_LONG_MIN;
    int R[N];
    for (int bit = 1; bit < (1<<10); bit++)
    {
        int C[N] = {};
        for (int i = 0; i < 10; ++i) {
            if (bit & (1<<i)) {
                rep(j,N) if(F[j][i]) C[j]++;
            }
        }
        long long sum=0;
        rep(i,N){
            sum+= P[i][C[i]];
        }
        if(res < sum){
            res = max(res,sum);
            rep(i,N){
                R[i] = C[i];
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256