akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int n, m, p;
    bool v[200000] = {false};
    int d[200000];

    scanf("%d %d %d", &n, &m, &p);
    for (int i = 0; i < m; i++){
        int t;
        scanf("%d", &t);
        v[t] = true;
    }
    v[p] = true;

    for (d[0] = 1; !v[(p + d[0]) % n]; d[0]++);
    int before = (p + d[0]) % n;
    for (int i = 1; i < m; i++){
        for (d[i] = 1; !v[(before + d[i]) % n]; d[i]++);
        before = (before + d[i]) % n;
    }
    for (d[m] = 1; !v[(before + d[m]) % n]; d[m]++);

    int right, left;
    right = left = 0;
    for (int i = 0; i < m + 1; i++){
        right += d[i];
        left += d[i];
    }
    right -= d[m];
    left -= d[0];

    int mini = min(right, left);
    for (int i = 0; i < m; i++){
        right = right - d[m - i - 1] + 2 * d[m - i];
        mini = min(mini, right);
    }
    for (int i = m; i > 0; i--){
        left = left - d[m - i + 1] + 2 * d[m - i];
        mini = min(mini, left);
    }

    printf("%d\n", mini * 100);

    return 0;
}

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

int id[405],od[405];bool v[405];vector <int>G[405];int N,H;int a,b,c,d;

bool dfs(int tt)
{
    bool f=id[tt]!=od[tt];
    v[tt]=true;
	for(int i=0;i<G[tt].size();i++)
    {
        if(!v[G[tt][i]]) 
            f|=dfs(G[tt][i]);
    }
    return f;
}


int main()
{
	scanf("%d%d",&N,&H);
    for(int i=1;i<=N;i++) 
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int l,r;l= ( c==0 ? a : -c );r= ( d==0 ? -b : d );
		od[l+H]++;id[r+H]++;G[l+H].push_back(r+H);G[r+H].push_back(l+H);
    }
	bool flag=1;
	for(int i=0;flag&&i<=H;i++)if(od[i]>id[i])flag=0;
	for(int i=H+1;flag&&i<=2*H+1;i++)if(od[i]<id[i])flag=0;
	memset(v,false,sizeof(v));
    for(int i=0;flag && i<=2*H;i++)
    {if((id[i]||od[i])&&!v[i]) flag &=dfs(i); }
    if(flag)  printf("YES\n"); 
    else  printf("NO\n");
}

Measured memory_bytes: 1664
// Try CADDi 2018 for Beginners
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let mut n = get!();
    let mut h = get!();
    let mut w = get!();
    let mut ans = 0;
    for _ in 0..n {
    	let a = get!();
        let b = get!();
        if a >= h && b >= w {
        	ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<stdio.h>
int kouyaku(int,int);

int main(){
  int a, b, c;
  scanf("%d %d", &a, &b);
  if(a < b){
    c = a;
    a = b;
    b = c;
  }
  //a > b
  printf("%d\n", kouyaku(a, b));

  return 0;
}

int kouyaku(int a, int b){
  int x;
  while(1){
  x = a % b;
  a = b;
  b = x;
  if(b <= 0) break;
  }
  return a;
}



Measured memory_bytes: 2084
def solve():
  ar = raw_input().split(' ')
  W = int(ar[0])
  a = int(ar[1])
  b = int(ar[2])
  if a+W < b : return b-a-W
  if b+W < a : return a-b-W
  return 0

if __name__ == '__main__' :
  print solve()

Measured memory_bytes: 2568
#include<iostream>
    #include<algorithm>
    using namespace std;
     
    int main(){
      int d, n, k = 1;
      cin >> d >> n;
      for(int i=0; i<d; i++)
        k *=100;
      if(n == 100) cout << 101*k << endl;
      else cout << n*k << endl;
    }

Measured memory_bytes: 256
#include<cstdio>
inline int read(){
	char ch=getchar();
	int o=0;
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		o=(o<<3)+(o<<1)+(ch^48);
		ch=getchar();
	}
	return o;
}
inline void write(int x){
	if(x>9)write(x/10);
	putchar(x%10^48);
}
int n,a[21],b[21],c[21],ans;
int main(){
	n=read();
	for(register int i=1;i<=n;i++)a[i]=read();
	for(register int i=1;i<=n;i++)b[i]=read();
	for(register int i=1;i<n;i++)c[i]=read();
	for(register int i=1;i<=n;i++){
		ans+=b[a[i]];
		if(i>1&&a[i-1]+1==a[i])ans+=c[a[i-1]];
	}
	write(ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int64 x; cin >> x;
	int64 ans = 0;
	ans = ans + ((x / 500) * 1000);
	x = (x % 500);
	ans = ans + ((x / 5) * 5);
	cout << ans << endl;
	return;
}

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

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

alf = 'abcdefghijklmnopqrstuvwxyz'
A = list(alf)

name = []
while N > 26:
    tmp = 25
    if N % 26 != 0:
        tmp = N % 26 -1
        N //= 26
    else:
        N = N//26-1
    name.append(A[tmp])


name.append(A[N-1])
name.reverse()
print(''.join(name))

Measured memory_bytes: 8912
n = int(input())
di = {}
li = []
for x in range(n):
    input_data = list(input().split())
    if input_data[0] not in di:
        di[input_data[0]] = {int(input_data[1]): x}
        li.append(input_data[0])
    else:
        di[input_data[0]][int(input_data[1])] = x

li.sort()
for res in li:
    point_di = di[res]
    point_di_sorted = sorted(point_di.items(), key=lambda x:-x[0])
    for _,rank in point_di_sorted:
        print(rank + 1)


Measured memory_bytes: 3060
N = int(input())
B = [int(i) for i in input().split()]

import numpy as np

A = np.zeros(N)
A[N-1] = B[N-2] 

for i in range(1,N-1):
  A[N-i-1] = min(B[N-i-1],B[N-i-2])
  
A[0] = B[0]

print(int(np.sum(A)))

Measured memory_bytes: 18892
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-10-27 20:58:14
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
int n;

void det()
{
  for (auto i = 1; i < 1000; i++)
  {
    if (i * (i + 1) / 2 == N)
    {
      n = i;
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;
  exit(0);
}

int main()
{
  cin >> N;
  det();
  vector<vector<int>> V(n + 1, vector<int>(n));
  int now = 0;
  for (auto i = 0; i < n + 1; i++)
  {
    for (auto j = 0; j < i; j++)
    {
      V[i][j] = V[j][i - 1];
    }
    for (auto j = i; j < n; j++)
    {
      V[i][j] = now++;
    }
  }
  assert(now == N);
  cout << n + 1 << endl;
  for (auto i = 0; i < n + 1; i++)
  {
    cout << n << " ";
    for (auto j = 0; j < n; j++)
    {
      cout << V[i][j] + 1;
      if (j < n - 1)
      {
        cout << " ";
      }
      else
      {
        cout << endl;
      }
    }
  }
}

Measured memory_bytes: 2176
// 16/06/2020 // 7:15 PM // 

#include <bits/stdc++.h>

using namespace std;

#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define ll long long

const int MAXN  = 20;
const ll INF   = 0x3f3f3f3f3f3f3f3f;
const int MAXNN = 65536 + 5; // 2^16 + 5 

int n, max_mask; 
ll a[MAXN][MAXN], pts[MAXNN];
vector<ll> memo;

void pre_calc(){
	for(int mask=1; mask<=max_mask; mask++){   // O(2^n * n^2)
		for(int i=0; i<=n; i++){
			if(((1<<i)&mask) == 0) continue;
			
			for(int j=i+1; j<=n; j++)
				if(((1<<j)&mask)!=0)
					pts[mask] += a[i][j];
		}
	}
}

ll solve(int mask_total){ 
	if(memo[mask_total]!=-INF) return memo[mask_total];

	if(mask_total==max_mask ) return 0;

	ll& ans = memo[mask_total];
	ans = -INF;
	
	vector<int> disp;
	for(int k=0; k<n; k++){
		if(((1<<k)&mask_total)==0) disp.pb(k);
	}
	int max_temp = (1<<((int)disp.size()))-1; 
	for(int tmask=1; tmask<=max_temp; tmask++){
		int gp_mask = 0;
		for(int k=0; k<(int)disp.size(); k++){
			if(((1<<k)&tmask)!=0) gp_mask += (1<<disp[k]);
		}
		
		ans = max(ans, pts[gp_mask] + solve(mask_total|gp_mask));
	}

	return ans;
}

int	main(){
	fast_io;
	
	cin >> n; 
	
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			cin >> a[i][j];
	
	max_mask = (1<<n)-1;
	
	memo.resize(max_mask+1, -INF);
		
	pre_calc();
	
	cout << solve(0) << endl;
	
	return 0;
}


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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,m;
	while(cin >> n >> m ){
		if(m-n>=2019){
			cout<<"0"<<endl;
		}
		else{
			ll mi = 1e18;
			for(ll i=n;i<m;i++){
				for(ll j=i+1;j<=m;j++){
					mi = min(mi,i*j%2019);
				}
			}
			cout << mi << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>
#include <queue>
#include <map>
#include <ctime>
#include <set>
 
#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) a.begin(),a.end()
 
using namespace std;
 
int main(){
	int n,m,q;
	cin >> n >> m >> q;
	vector<vector<int>> me(n,vector<int>(n,0)),dp(n,vector<int>(n,0));
	int r, l;
	rip(i,m,0){
		cin >> l >> r;
		me[l-1][r-1]++;
	}
	rip(i,n,0){
		dp[i][i]=me[i][i];
		rip(j,n,i+1){
			dp[i][j]=dp[i][j-1];
			rip(k,j+1,i){
				dp[i][j]+=me[k][j];
			}
		}
	}
	vector<int> ans(q);
	rip(i,q,0){
		cin >> l >> r;
		ans[i]=dp[l-1][r-1];
	}
	rip(i,q,0){
		printf("%d\n",ans[i]);
	}
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define print(v) for(auto it=(v).begin();it!=(v).end();it++) {cout<<*it<<" ";}
#define ll long long
#define w(t) ll t;cin>>t;while(t--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
using namespace std;

int main()
{
    int n,m,ans=0;
    cin>>n>>m;
    int h[n];
    vi adj[n];
    forn(i,n)
    {
        cin>>h[i];
    }

    while(m--)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    forn(i,n)
    {
        bool good=true;
        for(int j=0;j<adj[i].size();j++)
        {
            if(h[adj[i][j]]>=h[i])
            {
                good=false;
                break;
            }
        }
        if(good)
            ans++;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 9096
def main():
  dance = input()
  
  for i in range(0, len(dance)):
    if (i+1) % 2 == 0:
      if dance[i] == "R": 
        print("No")
        return 0
    else:
      if dance[i] == "L":
        print("No")
        return 0
  print("Yes")
  return 1

main()

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

#define LL long long
#define LB long double
#define ull unsigned long long
#define x first
#define y second
#define pb push_back
#define pf push_front
#define mp make_pair
#define Pair pair<int,int>
#define pLL pair<LL,LL>
#define pii pair<double,double>

const int INF=2e9;
const LL LINF=2e16;
const int magic=348;
const int MOD=998244353;
const double eps=1e-10;
const double pi=acos(-1);

struct fastio
{
	static const int S=1e7;
	char rbuf[S+48],wbuf[S+48];int rpos,wpos,len;
	fastio() {rpos=len=wpos=0;}
	inline char Getchar()
	{
		if (rpos==len) rpos=0,len=fread(rbuf,1,S,stdin);
		if (!len) return EOF;
		return rbuf[rpos++];
	}
	template <class T> inline void Get(T &x)
	{
		char ch;bool f;T res;
		while (!isdigit(ch=Getchar()) && ch!='-') {}
		if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
		while (isdigit(ch=Getchar())) res=res*10+ch-'0';
		x=(f?res:-res);
	}
	inline void getstring(char *s)
	{
		char ch;
		while ((ch=Getchar())<=32) {}
		for (;ch>32;ch=Getchar()) *s++=ch;
		*s='\0';
	}
	inline void flush() {fwrite(wbuf,1,wpos,stdout);fflush(stdout);wpos=0;}
	inline void Writechar(char ch)
	{
		if (wpos==S) flush();
		wbuf[wpos++]=ch;
	}
	template <class T> inline void Print(T x,char ch)
	{
		char s[20];int pt=0;
		if (x==0) s[++pt]='0';
		else
		{
			if (x<0) Writechar('-'),x=-x;
			while (x) s[++pt]='0'+x%10,x/=10;
		}
		while (pt) Writechar(s[pt--]);
		Writechar(ch);
	}
	inline void printstring(char *s)
	{
		int pt=1;
		while (s[pt]!='\0') Writechar(s[pt++]);
	}
}io;

const int MAXN=2e5;

int n,m;

struct node
{
	int A,B,C;
	inline void input() {io.Get(A);io.Get(B);io.Get(C);}
}a[MAXN+48];

inline Pair query(int id,int ti)
{
	if (ti==1) return mp(a[id].A,a[id].B);
	if ((a[id].A+1)%n==a[id].B && !(ti&1)) return mp(0,0);
	if (ti&1)
	{
		Pair res=mp(a[id].B+ti/2-1,a[id].B+ti/2);
		res.x%=n;res.y%=n;
		return res;
	}
	else
	{
		Pair res=mp(a[id].A+ti/2-1,a[id].A+ti/2);
		res.x%=n;res.y%=n;
		return res;
	}
}

namespace DSU
{
	int pre[MAXN+48];
	inline void init() {for (register int i=0;i<=n;i++) pre[i]=i;}
	inline int find_anc(int x) {if (pre[x]!=x) pre[x]=find_anc(pre[x]);return pre[x];}
	inline bool issame(int x,int y) {return find_anc(x)==find_anc(y);}
	inline void update(int x,int y) {x=find_anc(x);y=find_anc(y);pre[x]=y;}
}

priority_queue<pair<int,pair<Pair,bool> > > q;

int main ()
{
	// freopen ("a.in","r",stdin);
	// freopen ("a.out","w",stdout);
	io.Get(n);io.Get(m);
	for (register int i=1;i<=m;i++)
	{
		a[i].input();
		q.push(mp(-a[i].C,mp(mp(a[i].A,a[i].B),false)));
		if (a[i].A+1!=a[i].B) q.push(mp(-a[i].C-1,mp(mp(a[i].A,(a[i].A+1)%n),true)));
		q.push(mp(-a[i].C-2,mp(mp(a[i].B,(a[i].B+1)%n),true)));
	}
	LL ans=0;DSU::init();
	int cc=0;
	for (register int cnt=0;cnt<n-1;)
	{
		++cc;
		int len=q.top().x;Pair res=q.top().y.x;bool type=q.top().y.y;q.pop();
		if (DSU::issame(res.x,res.y)) continue;
		cnt++;ans-=len;
		DSU::update(res.x,res.y);
		if (type)
		{
			res.x=(res.x+1)%n;res.y=(res.y+1)%n;
			len-=2;
			q.push(mp(len,mp(res,type)));
		}
	}
	io.Print(ans,'\n');
	io.flush();return 0;
}

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

int main() {
    string a;
    cin >> a;
    if(a.at(a.size() - 1) == 's'){
        cout << a + "es" << endl;
    } else {
        cout << a + "s" << endl;
    }

    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 
    string s;
    cin>>s;

    while(1){
      s.pop_back();
      if(s.size()%2==0){
        string wk1,wk2;
        wk1=s.substr(0,s.size()/2);
        wk2=s.substr(s.size()/2,s.size()/2);
        if(wk1==wk2)
          break;
      }
    }

    cout<<s.size()<<endl;
    return 0;
}  

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

ll func(ll n) {
	ll res = 1;
	for (int i = 1; i <= n; i++) {
		res *= i;
		res %= MOD;
	}
	return res;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, m; cin >> n >> m;
	if (abs(n - m) > 1) cout << 0 << endl;
	else if (abs(n - m) == 1) {
		ll res = func(n)*func(m);
		res %= MOD;
		cout << res << endl;
	}
	else {
		ll res = func(n)*func(m);
		res %= MOD;
		res *= 2;
		res %= MOD;
		cout << res << endl;
	}
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   string s; cin>>s;
   int n=s.size();
   rep(i,0,n)if(s[i]=='?')s[i]='D';
   cout<<s<<endl;
   return 0;
}

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

const int maxn = 220000;

int a[maxn];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for(int i = 0; i < n; ++ i) {
		cin >> a[i];
		a[i] -= i;
	}
	sort(a, a + n);
	long long ans = 0, sum;
	int mn = a[0];
	for(int i = 1; i < n; ++ i) a[i] -= a[0];
	a[0] = 0;
	for(int i = 0; i < n; ++ i) ans += a[i];
	sum = ans;
	int pre = 0;
	for(int i = 0; i < n; ++ i) {
		int diff = a[i] - pre;
		sum -= 1LL * diff * (n - i);
		sum += 1LL * diff * i;
		if(sum < ans) ans = sum;
		pre = a[i];
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1024
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1e5 + 5;
const int M = 201;
const int Q = 2e5 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,k,ans;
char lastChar[N];
string t;
map<char,char> winner = {{'s','r'},{'p','s'},{'r','p'}};
map<char, int> profit;

void init() {

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k >> profit['r'] >> profit['s'] >> profit['p'] >> t;

    for(int i=0;i<k;++i) lastChar[i] = '#';

    for(int i=0;i<t.size();++i) {

        char myChar = winner[t[i]];

        if(myChar!=lastChar[i%k]) {
            ans += profit[myChar];
            lastChar[i%k] = myChar;
        } else
            lastChar[i%k] = '#';

    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int N;
int A[200000];
int main(){
	cin>>N;
	FOR(i,0,N){
		cin>>A[i];
	}
	if(N==1&&A[0]==0){
		cout<<0<<endl;
		return 0;
	}
	FOR(i,1,N){
		if(A[i-1]<A[i]){
			if(A[i]-A[i-1]!=1){
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	if(A[0]!=0){
		cout<<-1<<endl;
		return 0;
	}
	ll ans=0;
	FOR(i,0,N){
		while(i<N-1&&A[i]<A[i+1]){
			i++;
		}
		ans+=A[i];
	}
	cout<<ans<<endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    cout<<(n+1)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n,k;
    cin>>n>>k;
    long long int tmp,result=0;
    REP(i,n){
        cin>>tmp;
        if(tmp>=k){
            result++;
        }
    }
    cout<<result<<endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a,b,c,d;
  a = N/1000;
  N = N%1000;
  b = N/100;
  N = N%100;
  c = N/10;
  d = N%10; 
//  cin >> a >> b >> c >>d;
 	   if(a+b+c+d==7) cout<< a << "+" << b << "+" << c << "+" << d << "=7" <<endl;
  else if(a+b+c-d==7) cout<< a << "+" << b << "+" << c << "-" << d << "=7" <<endl;
  else if(a+b-c+d==7) cout<< a << "+" << b << "-" << c << "+" << d << "=7" <<endl;
  else if(a+b-c-d==7) cout<< a << "+" << b << "-" << c << "-" << d << "=7" <<endl;
  else if(a-b+c+d==7) cout<< a << "-" << b << "+" << c << "+" << d << "=7" <<endl;
  else if(a-b+c-d==7) cout<< a << "-" << b << "+" << c << "-" << d << "=7" <<endl;
  else if(a-b-c+d==7) cout<< a << "-" << b << "-" << c << "+" << d << "=7" <<endl;
  else if(a-b-c-d==7) cout<< a << "-" << b << "-" << c << "-" << d << "=7" <<endl;
}


Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()

x = [0] * (n+1)
for i in range(1, n):
    if s[i-1] == "A" and s[i] == "C":
        x[i+1] = 1
for i in range(n):
    x[i+1] += x[i]

for _ in range(q):
    l, r = map(int, input().split())
    print(x[r] - x[l])


Measured memory_bytes: 7668
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string s;
    cin >> s;
    string ans = "";
    for (char c : s) {
        if (c == 'B') {
            if (!ans.empty())
                ans.pop_back();
        } else ans += c;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int A[N] = {};
    int B[N - 1] = {};
    for (int i = 0;i < N - 1;i++){
        cin >> B[i];
    }
    A[0] = B[0];
    A[N - 1] = B[N - 2];
    for (int i = 1;i < N - 1;i++){
        if (B[i - 1] > B[i]) A[i] = B[i];
        else A[i] = B[i - 1];
    }
    int ans = 0;
    for (int i = 0;i < N;i++){
        ans += A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, A, B = sc.nextInt()
  val result = 1.to(N).map { i =>
    val sum = i.toString.split("").map(_.toInt).sum
    if (A <= sum && sum <= B) i else 0
  }.sum
  println(result)
}


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

int main() {
  string s, t, tt;
  cin >> s >> t;
  for(int i = 0; i < t.size() - 1; i++) tt += t[i];
  if(s == tt)
    printf("Yes\n");
  else
    printf("No\n");
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int conv[8] = {0,1,2,3,5,7,8,9};

// 10?????°x???b?????°?????????
vector<ll> decimalConvert(ll x, ll b, int keta = 64) {
	vector<ll> res;
	while (x) {
		res.push_back(x % b);
		x /= b;
	}
	while (res.size() < keta) res.push_back(0);
	reverse(ALL(res));
	
	return res;
}


int main() {
	int n;
	while (cin >> n, n) {
		vector<ll> v = decimalConvert(n, 8, 20);
		
		string ans = "";
		REP(i, v.size()) ans += conv[v[i]] + '0';
		
		int z = 0;
		while (z < ans.size() && ans[z] == '0') z++;
		if (z == ans.size()) ans = "0";
		else ans = ans.substr(z);
		
		cout << ans << endl;
	}
	return 0;
}

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

bool check (int n){
    if (n > 81 )
        return false;
    
    for (int i=1; i<10 ; i++){
        if ( n % i== 0 ){
            if (n / i <10 )
                return true;
        }
    }
    return false;
}


int main(){
    int n;
    cin >> n ;
    if (check (n))
        cout << "Yes"<< endl;
    else 
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

public class Test
{
	public static void Main()
	{
		string line = System.Console.ReadLine();
   		string[] ab = line.Split(' ');
   		int a = Convert.ToInt32(ab[0]);
   		int b = Convert.ToInt32(ab[1]);
   		int c = Convert.ToInt32(ab[2]);
   		if( a < b && b < c ){
   			Console.WriteLine("Yes");
   		}else{
   			Console.WriteLine("No");
   		}

	}
}

Measured memory_bytes: 8860
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A[3];
  REP(i,3)cin>>A[i];
  int x=0;
  REP(i,3)x+=A[i];
  cout<<(x>=22?"bust":"win")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <stdio.h> 
#include <map>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <deque>
#include <sstream>
#include <vector>
#include <algorithm>
 
typedef long long ll;
using namespace std;
 
int main() {
	int a, b;
	cin>>a>>b;
	
	for (int i=1; i<=10000; i++) {
		if((int)(i*0.08)==a && (int)(i*0.1)==b) {
			cout << i;
			return 0;
		}
	}
	
	cout << -1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <utility>
  #include <map>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)
  const ll mod = 1e9+7;

class mint {
public:
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

  int main(){
    ll n;
    cin >> n;
    mint ans = 10;
    ans = ans.pow(n);
    mint tmp = 9;
    ans -= (tmp.pow(n)*2);
    tmp = 8;
    ans += tmp.pow(n);
    cout << ans.x << endl;

    return 0;
  }


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  
  string ans = "NO";
  for (int i = 1; i < B; i++)
  {
    if (A * i % B == C)
    {
      ans = "YES";
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

int n;
int x[55], y[55];

int main()
{
    int del = 0;
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &x[i], &y[i]);
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int p = x[i] - x[j];
            int q = y[i] - y[j];
            
            int cnt = 0;
            for (int k = 0; k < n; k++) {
                for (int l = 0; l < n; l++) {
                    if (x[k] == x[l] - p &&
                        y[k] == y[l] - q) {
                        cnt++;
                    }
                }
            }

            del = max(del, cnt);
        }
    }

    printf("%d\n", n - del);

    return 0;
}


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

int interval(int x){
    return (x + 9) / 10 *10;
}
int rest(int x){
    return interval(x) - x;
}

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    int ans = interval(a) + interval(b) + interval(c) + interval(d) + interval(e);
    ans -= max({rest(a), rest(b), rest(c), rest(d), rest(e)});
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
// const long mod = 1000000007;
const long mod = 1777777777;
 
template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(long &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}
 
struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      std::string ss; scan(ss);
      LI xs(26, 0);
      for(char c : ss) {
         xs[c-'a'] += 1;
      }
      long n = ss.size();
      long res = n * (n - 1) / 2 + 1;
      for(long i = 0; i < 26; ++i) {
         long x = xs[i];
         res -= x * (x - 1) / 2;
      }
      printf("%ld\n", res);
   }
};
 
int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}

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

template<class Ran>
class IndexSortFunctor {
public:
    /** コンストラクタ
    *
    * @param iter_begin_ シーケンス先頭のランダムアクセス反復子
    * @param iter_end_ シーケンス終端の次のランダムアクセス反復子
    */
    explicit IndexSortFunctor(const Ran iter_begin_, const Ran iter_end_) : itbg(iter_begin_), ited(iter_end_) {}

    /** デストラクタ
    */
    ~IndexSortFunctor() {}

    /** 関数呼び出し
    * パラメータは、[]演算子の引数を想定
    * 必要があればitedを使って範囲チェックを行うことも可能
    * （ここでは未実装）
    */
    bool operator()(const size_t a, const size_t b) const {
        return *(itbg + a) < *(itbg + b);
    }

    protected:
    private:
    /** インデックスソート対象のコンテナ
    */
    const Ran itbg;
    const Ran ited;
};

/** インデックスソート用関数
*/
template<class Ran>
inline IndexSortFunctor<Ran> IndexSortCmp(const Ran iter_begin_, const Ran iter_end_)
{
    return IndexSortFunctor<Ran>(iter_begin_, iter_end_);
}

int main(){
    long N;
    vector<long> A;
    vector<long> B;
    vector<long> index;
    long a, b;
    bool flag = true;

    cin >> N;
    for(long n=0;n<N;n++){
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
        index.push_back(n);
    }

    sort(index.begin(), index.end(), IndexSortCmp(B.begin(), B.end()));
    sort(B.begin(), B.end());

    long long sumA = 0;
    for(long n=0;n<N;n++){
        long i = index[n];
        sumA += A[i];
        if(sumA > B[n]) flag = false;
    }

    if(flag){
        cout << "Yes" << "\n";
    }
    else{
        cout << "No" << "\n";
    }

    return 0;
}

Measured memory_bytes: 5204
N = gets.to_i
XYHs = readlines.map{|l| l.split.map(&:to_i)}

xyhs, xy0s = XYHs.partition{|x, y, h| h > 0}
x0, y0, h0 = xyhs.pop
ans = [*0 .. 100].product([*0 .. 100]).each_with_object([]) do |(cx, cy), a|
  ch = h0 + (x0 - cx).abs + (y0 - cy).abs
  a << [cx, cy, ch] if xyhs.all?{|x, y, h| ch == h + (x - cx).abs + (y - cy).abs}
end
ans.select!{|cx, cy, ch| xy0s.all?{|x, y, z| ch - (x - cx).abs - (y - cy).abs <= 0}} if ans.size > 1
puts ans.join(" ")

Measured memory_bytes: 3836
private val scanner = java.util.Scanner(System.`in`)

private fun readInts() = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()
private fun readLongs() = readLine()!!.split(" ").map { it.toLong() }.toTypedArray()

fun main(args: Array<String>) {
    val N = readInts()[0]
    val A = readInts()

    val first = A[0]
    if (!A.any { it != first }) {
        println(first)
        return
    }

    fun minimize(list: List<Int>): Int {
        val min = list.min()!!
        val divided = list
            .map { if (it == min) min else it % min }
            .filter { it != 0 }
            .distinct()

        return when {
            divided.size == 1 -> divided[0]
            divided.contains(1) -> 1
            else -> minimize(divided)
        }
    }

    println(minimize(A.toList()))
}

Measured memory_bytes: 56328
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

struct segment_tree {
	std::vector<int> seg;
	int sz = 1;
	
	segment_tree(int n) {
		sz = 1;
		while(sz < n) sz <<= 1;
		seg.assign(sz << 1, 0);
	}
	int fold(int a, int b) {
		int l = 0;
		int r = 0;
		for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if(a & 1) l += seg[a++];
			if(b & 1) r += seg[--b];
		}
		return l + r;
	}
	int add(int k, int x = 1) {
		k += sz;
		seg[k] = x;
		while(k >>= 1) seg[k] = seg[k << 1 ^ 0] + seg[k << 1 ^ 1];
	}
	int operator[](int k) {
		return seg[k + sz];
	}
};

int main() {
	std::string s; cin >> s;
	int k; scanf("%d", &k);

	std::vector<std::vector<int>> vec(30);
	for(int i = 0; i < s.size(); i++) vec[s[i] - 'a'].push_back(i);
	for(int i = 0; i < 30; i++) sort(begin(vec[i]), end(vec[i]));
	
	std::string ans = "";
	segment_tree seg(s.size());
	std::vector<int> cur(30, 0);
	for(int i = 0; i < s.size(); i++) {
		for(int j = 0; j < 30; j++) {
			if(cur[j] == vec[j].size()) continue;
			int cost = vec[j][cur[j]] - seg.fold(0, vec[j][cur[j]]);
			if(cost > k) continue;
			k -= cost;
			seg.add(vec[j][cur[j]++]);
			ans += (j + 'a');
			break;
		}
	}
	printf("%s\n", ans.c_str());
	return 0;
}



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

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

    int n; cin >> n;
    int a[n], ans, dp[n];
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);
    for (int i=2; i<n; i++){
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout << dp[n-1] << endl;

}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) {
		ALDS1_1_A(); 
	}
	public static void ALDS1_1_A() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		for(int i = 1; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(j == n - 1) {
					System.out.print(a[j]);
				}else {
					System.out.print(a[j] + " ");
				}
			}
			System.out.println();
			int temp = a[i];
			int j = i - 1;
			while(j >= 0 && temp < a[j]) {
				a[j + 1] = a[j];
				j--;
			}
			a[j + 1] = temp;
		}

		for(int j = 0; j < n; j++) {
			if(j == n - 1) {
				System.out.print(a[j]);
			}else {
				System.out.print(a[j] + " ");
			}
		}
		System.out.println();
	}
}


Measured memory_bytes: 30004
#include <stdio.h>

#define MAX(A,B) \
  ( (A) > (B) ? (A) : (B) )
#define MIN(A,B) \
  ( (A) < (B) ? (A) : (B) )
#define MIN3(A,B,C) \
  MIN(MIN(A,B),C)

static const char * s = "JOI";

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int ans = 0;
  int lv = 0;
  int d[ 3 ] = { 0 };

  for ( ; ; )
  {
    const int ch = getchar ( );

    if ( ch != s[ lv ] )
    {
      if ( lv == 2
        && d[ 1 ] <= d[ 0 ]
        && d[ 1 ] <= d[ 2 ] )
      {
        ans = MAX( ans, MIN3( d[ 0 ], d[ 1 ], d[ 2 ] ) );
      }
      d[ ch == s[ lv + 1 ] ? ++lv : ( lv = 0 ) ] = 0;
    }
    if ( ch == '\n' ) break ;

    if ( ch == s[ lv ] )
    {
      ++d[ lv ];
    }
  }

  printf ( "%d\n", ans );

  return ( 0 );
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	string st1,st2;
	cin >> st1 >> st2;
	string st=st1+st1+st1;
	int p=st.find(st2);
	if (p==-1) printf("No");else printf("Yes");
	return 0;
} 

Measured memory_bytes: 256
// AOJ CGL_1_A Projection
// 2018.5.2 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct { double x, y; } PP;
typedef struct { PP s, e; } SEG, LINE;

#define INF			1e8
#define EPS			1e-8
#define EQ(a,b)		(fabs((a)-(b))<EPS)
#define PPeQ(a,b)	(EQ(a.x,b.x)&&EQ(a.y,b.y))

int dcmp(double x) { if (fabs(x) < EPS) return 0; return x <= 0 ? -1 : 1; }
PP vset(double x, double y) { PP r; r.x = x, r.y = y; return r; }
PP vadd(PP p1, PP p2) { PP r; r.x = p1.x + p2.x, r.y = p1.y + p2.y; return r; }
PP vsub(PP p1, PP p2) { PP r; r.x = p1.x - p2.x, r.y = p1.y - p2.y; return r; }
PP vsmul(PP p, double k) { PP r; r.x = p.x * k, r.y = p.y * k; return r; }
PP vmul(PP p1, PP p2) { PP r;
	r.x = p1.x * p2.x - p1.y * p2.y, r.y = p1.x * p2.y + p1.y * p2.x; return r; }
double vabs(PP a) { return hypot(a.x, a.y); }
double dist(PP p1, PP p2) {	return hypot(p1.x-p2.x, p1.y-p2.y); };
double cross(PP a, PP b) { return a.x * b.y - a.y * b.x; }
double dot(PP a, PP b) { return a.x * b.x + a.y * b.y; }
double norm(PP a) { return a.x * a.x + a.y * a.y; }

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

PP projection(PP p1, PP p2, PP p)
{
	PP p2p1 = vsub(p2, p1);
	PP pp1 = vsub(p, p1);
	return vadd(p1, vsmul(p2p1, dot(pp1, p2p1)/norm(p2p1)));
}

int main()
{
	int q, x, y;
	PP p1, p2, p, ans;

	x = in(), y = in(), p1 = vset(x, y);
	x = in(), y = in(), p2 = vset(x, y);

	q = in(); while (q--) {
		x = in(), y = in(), p = vset(x, y);
		ans = projection(p1, p2, p);
		printf("%.10lf %.10lf\n", ans.x, ans.y);
	}
	return 0;
}



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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

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

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


int main(){
  int n, m; cin >> n >> m;
  ll sum = 0;
  priority_queue<int> queue;
  for(int i = 0; i < n; ++i){
    int x; cin >> x; queue.push(x);
    sum += x;
  }
  for(int i = 0; i < m; ++i){
    int x = queue.top(); queue.pop();
    int y = x / 2;    
    queue.push(y);
    sum -= (x - y);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int nHalf = n >> 1;

      Integer num;
      Map<Integer,Integer> mapA = new HashMap<>();
      Map<Integer,Integer> mapB = new HashMap<>();
      List<Map<Integer,Integer>> aMap = new ArrayList<>();
      aMap.add(mapA);
      aMap.add(mapB);
      int offset=0,next=0;
      char regx = ' ';

      for(int i=0; i<n; i++) {
        if((next = line.indexOf(regx,offset)) == -1)
          next = line.length();
        num = new Integer(line.substring(offset, next));
        offset = ++next;

        // aMap.get(i&1).merge(num, 1, Integer::sum);
        if(aMap.get(i&1).containsKey(num))
          aMap.get(i&1).replace(num, aMap.get(i&1).get(num) + 1);
        else
          aMap.get(i&1).put(num, 1);
      }

      int[] vm1 = {0,0};
      int[] vm2 = {0,0};
      int[] x   = {0,0};

      for (int i=0; i<aMap.size(); i++) {
        final int j = i;
        aMap.get(j).forEach((key,val) -> {
          if(vm1[j] < val) {
            vm2[j] = vm1[j];
            vm1[j] = val;
            x[j]  = key;
          } else if(vm2[j] < val) {
            vm2[j] = val;
          }
        });
      }

      int ans = 0;
      int cca1 = nHalf - vm1[0];
      int ccb1 = nHalf - vm1[1];
      int cca2 = nHalf - vm2[0];
      int ccb2 = nHalf - vm2[1];

      if(x[0] == x[1])
        ans = cca2 > ccb2 ? cca1 + ccb2 : cca2 + ccb1;
      else
        ans = cca1 + ccb1;

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 45788
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ll = new int[n];
        for(int i = 0; i < n; i++){
            ll[i] = sc.nextInt();
        }
        Arrays.sort(ll);
        long ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                int tmp = beamSearch(ll,ll[i] + ll[j]);
                ans += (long)Math.max(0,tmp-j);
            }
        }
        System.out.println(ans);
    }
    
    public static int beamSearch(int[] ll, int k){
        int left = -1;
        int right = ll.length;
        while(right - left > 1){
            int mid = (right + left) / 2;
            if(ll[mid] >= k){
                right = mid;
            }else{
                left = mid;
            }
        }
        return left;
    }
}


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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=1e6 +10, M=(ll)1e9+1 ;
const int mod =(ll)1e9+7 ,sz=5, MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";

void work(){
	string s;
	cin >> s;
	for(ll i=0;i<s.length();i++){
		if(s[i]=='7'){
			cout << "Yes";
			return;
		}
	}

	cout << "No";

}

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

	
	// precomp();
	ll t;
	// cin >> t;
	t=1;
	while(t--){
	        work();
	
	}

	return 0;
}
	


Measured memory_bytes: 3616
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    ll n;
    cin>>n;
    ll ans = 0;
    for(ll i = 2; i*i <= n; i++){
        if(n%i == 0){
            // ++ans;
            ll cnt = 0;
            while(n%i == 0){
                n /= i;
                ++cnt;
            }
            ll maybe = sqrt(2*cnt);
            if((maybe+2)*(maybe+1) <= cnt*2)
                ans += maybe+1;
            else if(maybe*(maybe+1) <= cnt*2)
                ans += maybe;
            else
                ans += maybe-1;
        }
    }
    if(n != 1)
        ++ans;
    cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}


Measured memory_bytes: 3692
def numOfPutty(l,k):
    if l == 0:
        return 1
    elif k == 1 :
        return 0
    elif k == pow(2,l+2) - 3:
        return pow(2,l+1) - 1
    elif k < pow(2,l+1) -1:
        return numOfPutty(l-1,k-1)
    elif k == pow(2,l+1) - 1 :
        return pow(2,l)
    elif k > pow(2,l+1) - 1:
        return numOfPutty(l-1,k-pow(2,l+1)+1) + pow(2, l )

L , X = map(int, input().split())
print(numOfPutty(L,X))

Measured memory_bytes: 3316