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

 int bubbleSort (int A[], int N){
   int sw = 0;
   int i = 0;
  bool flag;
   do {
     flag = 0;
     for (int j = N - 1; j >= i + 1; j--){
       if (A[j] < A[j - 1]){
         swap(A[j], A[j - 1]);
         flag = 1;
         sw++;
       }
     }
     i++;
   } while (flag);
  return sw;
   }

   int main(){
     int N, A[110], ans;
     cin >> N;
     for (int i = 0; i < N; i++){
       cin >> A[i];
     }

     ans = bubbleSort(A,N);
     for (int i = 0; i < N; i++){
       if (i) cout << " ";
       cout << A[i];
     }
     cout << endl;
     cout << ans << endl;
   }



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

using namespace std;

int CtoI(char c){
    return c - 'A';
}

char ItoC(int k){
    return (char)('A' + k);
}

signed main(){
    int n; // 票数
    char* c; // 票
    int v[26]; // 獲得票数
    vector<int> v_(26); // vのコピー
    cin >> n;
    while (n > 0){
        c = new char[n];
        for (int i = 0;i < n;i++) cin >> c[i];
        for (int i = 0;i < 26;i++) v[i] = 0;
        for (int i = 0;i < n;i++){
            v[CtoI(c[i])]++; // 票が入る
            for (int j = 0;j < 26;j++)
                v_[j] = v[j];
            sort(v_.begin(),v_.end());
            int M = v_[25], m = v_[24];
            if (M > m + (n - i - 1)){
                for (int k = 0;k < 26;k++){
                    if (v[k] == M){
                        cout << ItoC(k) << " " << (i + 1) << endl;
                        goto FIN;
                    }
                }
            }
        }
        cout << "TIE" << endl;
        FIN:;
        cin >> n;
    }
    return 0;
}


Measured memory_bytes: 3232
import math

n = int(input())

f = int(math.log10(n))+1
for i in range(1,int(math.sqrt(n))+1):
	if n%i == 0:
		a = i
		b = n//i
		
		if f > max(int(math.log10(a))+1, int(math.log10(b))+1):
			f = max(int(math.log10(a))+1, int(math.log10(b))+1)

print(f)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
 int main(){
 while(1){
 int a,b;
 string op;
 cin>>a>>op>>b;
 if(op=="?") break;

 int ans;
 if(op=="+") ans= a+b;
 if(op=="-") ans= a-b;
 if(op=="*") ans= a*b;
 if(op=="/") ans= a/b;
 cout<<ans<<endl;
}
 

  return 0;
  }


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-48);
}
int n, m, mx; lnt X, D; vector <int> G[55];
int rk[55]; lnt w[55], c[55], W[2505], C[2505], f[125005];
bool cmp(const int &x, const int &y) {return c[x]*w[y] > c[y]*w[x];}
void DFS(int u) {c[u] = 1; for (int v : G[u]) DFS(v), w[u] += w[v], c[u] += c[v];}
int main() {
	read(n), read(X), read(D), read(w[1]);
	for (int i = 2, fa; i <= n; i++)
		read(w[i]), read(fa), G[fa].push_back(i);
	for (int i = 1; i <= n; i++) rk[i] = i;
	DFS(1), sort(rk+1, rk+n+1, cmp);
	for (int i = 1; i <= n; i++) mx += (int)c[i]*n;
	for (int i = 1; i <= n; i++) {
		lnt cur = 1, lft = min(1LL*n, D);
		while (cur <= lft)
			W[m] = cur*w[i], C[m] = cur*c[i], 
			m++, lft -= cur, cur <<= 1;
		if (lft) W[m] = lft*w[i], C[m] = lft*c[i], m++;
	}
	memset(f, 0x3f, sizeof f), f[0] = 0;
	for (int i = 0; i < m; i++)
		for (int j = mx; j >= C[i]; j--)
			f[j] = min(f[j], f[j-C[i]]+W[i]);
	lnt ans = 0;
	for (int i = 0; i <= mx; i++) if (f[i] <= X) {
		lnt cur, lft = X-f[i], tot = i;
		for (int j = 1; j <= n; j++)
			if (rk[j] > 1)
				cur = min(max(D-n, 0LL), lft/w[rk[j]]), 
				lft -= cur*w[rk[j]], tot += cur*c[rk[j]];
			else
				cur = lft/w[rk[j]], 
				lft -= cur*w[rk[j]], tot += cur*c[rk[j]];
		ans = max(ans, tot);
	}
	return printf("%lld\n", ans), 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	int a,b,hz,rem;
	Scanner scan =new Scanner(System.in);
	a=scan.nextInt();
	b=scan.nextInt();
	if(b>a){
	    hz=a;
	    a=b;
	    b=hz;
	}
	rem=a%b;
        while(rem!=0){
	    a=b;
	    b=rem;
	    rem=a%b;
	}
	System.out.println(b);
    }
}




Measured memory_bytes: 26276
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var inputs = Console.ReadLine().Split(' ');
        int maxHeight = 0;
        int count = 0;
        for(int i = 0; i < N; i++)
        {
            int H_i = int.Parse(inputs[i]);
            if(H_i >= maxHeight)
            {
                count++;
            }

            maxHeight = Math.Max(H_i, maxHeight);
        }

        Console.WriteLine(count);
    }

}



Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
using namespace std;
typedef long long ll;
int N, W, V_[101], W_[101];
int dp[101][10001];
int main(void) {
	cin >> N >> W;
	SREP(n, 1, N) cin >> V_[n] >> W_[n];
	SREP(n, 1, N) REP(w, W) {
		dp[n][w] = dp[n - 1][w];
		if (w < W_[n]) continue;
		dp[n][w] = max(dp[n][w], dp[n - 1][w - W_[n]] + V_[n]);
	}
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 7016
#include<bits/stdc++.h>
using namespace std;
#define N 100 + 5
#define M
#define inf 123456789
#define Inf 10000000000000000
#define Mod 1000000007
#define rep(i, l, r) for(register int i = l; i <= r; ++i)
#define dep(i, l, r) for(register int i = r; i >= l; --i)
#define Next(i, u) for(register int i = h[u]; i; i = e[i].next)
#define mem(f, x) memset(f, x, sizeof(f))
#define file(a) freopen(#a".in","r",stdin); freopen(#a".out","w",stdout);
typedef long long ll;
typedef double D;
int n, flag, a[N];
int read(){
	char c; int x = 0, f = 1;
	c = getchar();
	while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9'){ x = (x << 3) + (x << 1) + c - '0'; c = getchar();}
	return x * f;
}
int Mul(int a, int b) { return 1ll * a * b % Mod; }
int Inc(int a, int b) { return (a += b) >= Mod ? a - Mod : a; }
int Dec(int a, int b) { return (a -= b) < 0 ? a + Mod : a; }
signed main(){
	//file(data);
	n = read();
    rep(i, 1, n){
        a[i] = read();
        if(!(a[i] & 1) && (a[i] % 3 != 0) && (a[i] % 5 != 0)) flag = 1;
    }
    if(flag) puts("DENIED");
    else puts("APPROVED");
	return 0;
}


Measured memory_bytes: 256
// G++ MACRO.CPP -STD=C++17
#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 dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair



int main(){
  CIN(a,b,c);
  FOR(i,1,1000000){
    ll t = 1LL*a*i;
    if(t%b==c)EN(YES);
  }
  EN(NO);

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

const int MAXV = 1005;
const int MAXE = 505 * 505;
const int INF = 1<<29;

struct BiparateMatching {
    int N, M, E, match[MAXV+1], dist[MAXV+1];
    int last[MAXE], prev[MAXE], to[MAXE];
    BiparateMatching(int n, int m) : N(n), M(m), E(0) {
        memset(last, -1, sizeof(last));
    }
    void add_edge(int x, int y) { // x \in [0, N), y \in [0, M)
        to[E] = y + N; prev[E] = last[x]; last[x] = E; E++;
    }
    bool bfs() {
        queue<int> q;
        for (int i=0; i<N; ++i) {
            if (match[i] == -1) {
                q.push(i); dist[i] = 0;
            } else dist[i] = INF;
        }

        bool ret = false;
        while(!q.empty()) {
            int v = q.front(); q.pop();
            for (int e = last[v]; e != -1; e = prev[e]) {
                if (match[to[e]] == -1) ret = true;
                else if (dist[match[to[e]]] == INF) {
                    dist[match[to[e]]] = dist[v] + 1;
                    q.push(match[to[e]]);
                }
            }
        }
        return ret;
    }
    bool dfs(int v) {
        for (int e = last[v]; e != -1; e = prev[e]) {
            bool update = false;
            if (match[to[e]] == -1) {
                match[to[e]] = v; match[v] = to[e];
                update = true;
            } else if (dist[match[to[e]]] == dist[v] + 1) {
                if (dfs(match[to[e]])) {
                    match[to[e]] = v; match[v] = to[e];
                    update = true;
                }
            }
            if (update) return true;
        }
        dist[v] = INF;
        return false;
    }
    int matching() {
        int ret = 0;
        memset(match, -1, sizeof(match));
        while(bfs()) {
            for (int i=0; i<N; ++i)
                if (match[i] == -1 && dfs(i)) ret++;
        }
        return ret;
    }
};

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

int b[501], r[501];
int main() {
    int m,n;
    while(scanf("%d %d", &m, &n), m|n) {
        BiparateMatching bm(m, n);
        for (int i=0; i<m; ++i) scanf("%d", &b[i]);
        for (int i=0; i<n; ++i) scanf("%d", &r[i]);
        for (int i=0; i<m; ++i) {
            for (int j=0; j<n; ++j)
                if (gcd(b[i], r[j]) > 1) bm.add_edge(i, j);
        }
        printf("%d\n", bm.matching());
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
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;

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

  int n;cin>>n;
  VVI cost(n,vector<int>(n));
  for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
          cin>>cost[i][j];
      }
  }
  ll res=0;
  for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
          res+=min(cost[i][j],cost[j][i]);
      }
  }
  cout<<res<<endl;
}

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

bool dp[100005];

int main() {
    string s;
    cin >> s;
    s = " " + s;
    dp[0] = true;
    for (int i = 1; i < (int)s.size(); ++ i) {
        dp[i] = false;
        if (i >= 5 && s.substr(i - 4, 5) == "dream" && dp[i - 5]) {
            dp[i] = true;
        }
        if (i >= 5 && s.substr(i - 4, 5) == "erase" && dp[i - 5]) {
            dp[i] = true;
        }
        if (i >= 7 && s.substr(i - 6, 7) == "dreamer" && dp[i - 7]) {
            dp[i] = true;
        }
        if (i >= 6 && s.substr(i - 5, 6) == "eraser" && dp[i - 6]) {
            dp[i] = true;
        }
    }
    // for (int i = 0; i < (int)s.size(); ++ i) {
    //     cout << dp[i] << " ";
    // }
    cout << (dp[s.size() - 1] ? "YES\n" : "NO\n");
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


int main() {
    int N;
    cin >> N;
    cout << (N - 2) * 180 << endl;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define ull unsigned long long
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

int main() {
    FIO;
   string s; cin >> s;
   ll ans = 0;
   for(ll i = 0; i < s.size(); i++) {
    string p = "";
    p = s[i];
    ll d = stoi(p);
    ans += d;
   }
   if(ans % 9 == 0) cout << "Yes" << endl;
   else cout << "No" << endl;
}


Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <map>
using namespace std;

int main(){
    int a, b, c, ans;
    cin >> a >> b >> c;
    if(b/a>=c){
        ans=c;
    }
    else{
        ans=b/a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
s = int(input())
a, b = s//100, s%100
p = bool(1 <= a <= 12)
q = bool(1 <= b <= 12)
if p & q:
    print("AMBIGUOUS")
elif p:
    print("MMYY")
elif q:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
    string in;
    bool a = false;
    cin >> in;
    for(int i = 0; i < int(in.length());i++){
      int j = i+1;
      if(j % 2 == 1){
        if(in[i] == 'R' || in[i] == 'U'|| in[i] == 'D'){
          a = true;
        } 
        else{a = false;break;}
      }
      else{
        if(in[i] == 'L' || in[i] == 'U'|| in[i] == 'D'){
          a = true;
        } 
        else{a = false;break;}
      }
    }
    if(a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if (a < b) {
      System.out.println("a < b");
    } else if (a > b) {
      System.out.println("a > b");
    } else {
      System.out.println("a == b");
    }
  }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,Alice = 0,Bob = 0;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for(int i = 0; i < N; i++){
    ((i+2)%2 == 0 ? Alice += vec.at(i) : Bob += vec.at(i));
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)

# 1 ✕ N
N, M, X = list(map(int, input().rstrip().split()))

# N ✕ M (2D array)
A = list(input().rstrip().split() for _ in range(N))

ans = 1e9
for bit in range(2 ** N):
    total = 0
    array = [0 for _ in range(M)]

    for i in range(N):
        if bit & 1 << i:
            total += int(A[i][0])
            for j in range(M):
                array[j] += int(A[i][j + 1])

    found = True
    for i in range(M):
        if array[i] < X:
            found = False

    if found:
        ans = min(ans, total)

print(-1 if ans == 1e9 else ans)


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

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

  for(int i = 0; i < n; i++) {
    b[a[i] - 1] = i+1;
  }
  for (int i = 0; i < n; i++) {
    cout << b[i] << " ";
  }
}


Measured memory_bytes: 1536
# coding:utf-8
def main():
    # print("start")
    A,B = map(int,input().split())
    # print(A%4)
    point_A = A
    point_B = B
    if A%4 > 0:
        point_A = A - (A%4) + 4
    if B%4 > 0:
        point_B = B - (B%4)

    # print(point_A,point_B)
    # print()
    ans = 0
    for i in range(A,point_A):
        ans = ans ^ i

    for i in range(point_B,B+1):
        ans = ans ^ i
    print(ans)


if __name__ == "__main__":
    main()

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

int main(){
    int N,K,d, Adi;
    cin >> N >> K;
    bool A[N];
    for(int i=0; i<N; i++){
        A[i]=false;
    }
    for(int i=0; i<K; i++){
        cin >> d;
        for(int j=0; j<d; j++ ){
            cin >> Adi;
            A[Adi-1]=true;
        }
    }
    int ans=0;
    for(int i=0; i<N; i++){
        if( A[i]==false ){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<sstream>
#include<numeric>
#include<iostream>
#include<algorithm>
#include<functional>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Lsn (x<<1)
#define Rsn (x<<1|1)
#define Mid ((L+R)>>1)

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> Vi;
typedef pair<int,int> pii;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}
void Output(int x){
	if (x>=10) Output(x/10);
	putchar(x%10+'0');
}

const int N=500000+19;
const int oo=(1<<30)-1;

priority_queue<int> Q;
int A[N],d[N],C[N],res[N];
int n,k;

int Query(int x){
	int res=0;
	for (;x;x-=x&-x) res+=C[x];
	return res;
}
void Add(int x){
	for (;x<=n;x+=x&-x) C[x]++;
}

pii mn[N*4];
int plu[N*4];
int Ql,Qr;

void Build(int x,int L,int R){
	if (L==R){
		mn[x]=mp(d[L],-L);
		return;
	}
	Build(Lsn,L,Mid);
	Build(Rsn,Mid+1,R);
	mn[x]=min(mn[Lsn],mn[Rsn]);
}
void Plus(int x,int v){
	plu[x]+=v;
	mn[x].fi+=v;
}
void Down(int x){
	if (plu[x]){
		Plus(Lsn,plu[x]);
		Plus(Rsn,plu[x]);
		plu[x]=0;
	}
}
void Modify(int x,int L,int R){
	if (Ql<=L&&R<=Qr){
		Plus(x,-1);
		return;
	}
	Down(x);
	if (Ql<=Mid) Modify(Lsn,L,Mid);
	if (Qr>Mid) Modify(Rsn,Mid+1,R);
	mn[x]=min(mn[Lsn],mn[Rsn]);
}
void Change(int x,int L,int R){
	if (L==R){
		mn[x]=mp(oo,-L);
		return;
	}
	Down(x);
	Ql<=Mid?Change(Lsn,L,Mid):Change(Rsn,Mid+1,R);
	mn[x]=min(mn[Lsn],mn[Rsn]);
}

int main(){
	n=IN(),k=IN()-1;
	For(i,1,n+1) A[IN()]=i;
	for (int i=n;i;i--){
		d[A[i]]=Query(min(A[i]+k,n))-Query(max(A[i]-k,1)-1);
		Add(A[i]);
	}
	For(i,1,n+1){
		if (!d[i]) Q.push(i),d[i]=oo;
	}
	Build(1,1,n);
	For(t,1,n+1){
		int x=Q.top();Q.pop();
		res[x]=n-t+1;
		Ql=max(x-k,1);
		Qr=min(x+k,n);
		Modify(1,1,n);
		while (mn[1].fi==0){
			Q.push(-mn[1].se);
			Ql=-mn[1].se;
			Change(1,1,n);
		}
	}
	For(i,1,n+1){
		Output(res[i]);
		puts("");
	}
}

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

int main() {
  int N;
  cin >> N;
  int num = N;
  int sum = 0;
  while(num % 10 != 0){
      sum += num % 10;
      num /= 10;
  }
  if(N % sum == 0){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	long count = 0;

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

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int min = Integer.MAX_VALUE;
		int[] A = new int[n];
		int max = -1;
		for (int i = 0; i < n; i++) {
			A[i] = scanner.nextInt();
			min = Math.min(min, A[i]);
			max = Math.max(max, A[i]);
		}
		int ans = 0;
		boolean[] V = new boolean[n];
		int[] B = Arrays.copyOf(A, A.length);
		Arrays.sort(B);
		int[] T = new int[max + 1];
		List<Integer> list  = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			list.add(B[i]);
		}
		for (int i = 0; i < n; i++) {
			int cur = i;
			int s = 0;
			int m = max;
			int an = 0;
			while (true) {
				V[cur] = true;
				an++;
				int v = A[cur];
				m = Math.min(m, v);
				s += v;
				cur = list.indexOf(v);
				if (V[cur])
					break;
			}
			int a = s + (an - 2) * m;
			int b = m + s + (an + 1) * min;
			ans += Math.min(a, b);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23496
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

bool check(string s) {
    rep(i, s.length()-1) {
        if (s[i] != s[i+1]) return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    int n = s.length();

    int ans = INF;
    rep(i, n) {
        int l = n;
        int count = 0;
        string ts = s;
        while (!check(ts)) {
            string ns = "";
            rep(j, l-1) {
                if (ts[j] == s[i] || ts[j+1] == s[i]) ns += s[i];
                else ns += '?';
            }
            ts = ns;
            count++;
            --l;
        }
        ans = min(ans, count);
    }

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

Measured memory_bytes: 256
// contest.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include "bits/stdc++.h"
using namespace std;
int N;
void adding(string s, int n, vector<char> l) {
	if (s.size() == N) {
		cout << s << endl;
		return;
	}
	for (int i = 0; i < n; i++)
	{
		adding(s + l[i],n,l);
	}
	adding(s + l[n], n + 1, l);
}
int main()
{
	cin >> N;
	vector<string> SS;
	string S="";
	vector<char> C = { 'a','b','c','d','e','f','g','h','i','j' };
	adding("", 0, C);
	return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main() {
  int n;
  string s;
  cin >> n >> s;
  rep(i,s.size()){
    rep(j,n){
    s.at(i)++;
    if(s.at(i) == '[') s.at(i) = 'A';
  }
  }
  cout << s << endl;
  }


Measured memory_bytes: 256
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var test = new Test();
            var s = Console.ReadLine();
            var sb = new StringBuilder();
            for(var i = 0; i<s.Length; i++)
            {
                sb.Append("x");
            }

            Console.WriteLine(sb.ToString());
        }


        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public int[] ConvertIntArray(string[] x)
        {
            var convertedArray = new int[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public double[] ConvertDoubleArray(string[] x)
        {
            var convertedArray = new double[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public long[] ConvertLongArray(string[] x)
        {
            var convertedArray = new long[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = long.Parse(x[i]);
            }

            return convertedArray;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

Measured memory_bytes: 11092
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=205;
int n,ans,dis[N][N],x,col[N];

void dfs(int x,int c){
	col[x]=c;
	for(int i=1;i<=n;i++) if(dis[x][i]==1){
		if(col[i]==-1) dfs(i,!c); else 
		if(col[i]==c){
			write(-1);
			exit(0);
		}
	}
}

signed main(){
	read(n);
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%1d",&x),dis[i][j]=x?1:1e9;
	for(int i=1;i<=n;i++) col[i]=-1;
	for(int i=1;i<=n;i++) if(col[i]==-1) dfs(i,0);
	for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j&&i!=k&&j!=k)
		dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(dis[i][j]<1e9) ans=max(ans,dis[i][j]);
	write(ans+1);
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
typedef pair<int,int> P;
#define INF 1e9
#define rep(i,N) for(int i=0;i<N;i++)

int main(){
    int n,m;
    cin>>n>>m;
    int e[m];
    bool ee[n+1];
    rep(i,n+1)ee[i]=false;
    int a;
    int c = 0 ;
    rep(i,m){
        cin>>e[i];
    }
    for(int i = m-1;i>=0;i--){
        if(ee[e[i]]){
            //cout<<"ee:"<<e[i]<<endl;
            continue;
        }
        cout<<e[i]<<endl;
        ee[e[i]] = true;
    }
    for(int i = 1; i<n+1;i++){
        if(ee[i])continue;
        cout<<i<<endl;
    }
}


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

int insert(vector<int> &a,int n, int g) {
	int v,j,cnt = 0;
	for (int i = g; i < n; i++) {
		v = a[i];
		j = i - g;
		while (j >= 0 && a[j] > v) {
			a[j + g] = a[j];
			j = j - g;
			cnt++;
		}
		a[j + g] = v;
	}
	return cnt;
}

void shell_s(vector<int>&a,int n) {
	int cnt = 0, m = (n+1) / 2;
	vector<int>g(m);
	g[0] = 1;
	for (int i = 1; i < m; i++) {
		if (3 * g[i - 1] + 1 > n) {
			m = i;
			break;
		}
		g[i] = 3 * g[i - 1] + 1;
	}
	cout << m << endl;
	for (int i = m - 1; 0 <= i; i--) {
		cout << g[i];
		if (i == 0)cout << endl;
		else cout << ' ';
	}

	for (int i = m - 1; 0 <= i; i--) {
		cnt += insert(a, n, g[i]);
	}

	cout << cnt << endl;
	for (int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
}

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

	

}



Measured memory_bytes: 8580
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
    const ll INF = 2000000000;
    vector<ll> five;
    for (ll i=5; i<=INF; i*=5) five.push_back(i);
    ll n;
    while (scanf("%lld",&n)) {
        if (!n) break;
        ll res=0;
        for (int i=0; i<five.size()&&five[i]<=n; i++)
            res+=n/five[i];
        printf("%lld\n",res);
    }
}

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

int main(){
	int m, min, max, a[300], ans;
		
	while (1){
		int t = 0;
		cin>>m>>min>>max;
		if(m == 0 && min == 0 && max == 0){
			break;
		}
		for(int i = 1; i <= m; i++){
			cin>>a[i];
		}

		for(int i = min; i <= max; i++){
			if(a[i] - a[i + 1] >= t){
				t = a[i ] - a[i + 1];
				ans = i;
			}
		}
		cout<<ans<<endl;
		
	}
	return 0;
}




Measured memory_bytes: 3008
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner $ = new Scanner(System.in);
		int N = $.nextInt(), K = $.nextInt();
		double sum = 0.0;
		for (int i = 0; i < N; i++){
			double p = 1.0;
			for (int M = 1; M * (i + 1) < K; M *= 2){
				p *= 1.0 / 2.0;
			}
			sum += p;
			//System.out.println(p);
		}
		System.out.println(sum / N);
		/*
		3 10 -> 0.145833333333
		100000 5 -> 0.999973749998
		*/
	}
}


Measured memory_bytes: 23124
#include<stdio.h>
void ckmin(int&x,const int&y)
{
	x=x<y?x:y;
}
int n,m,a[100005],f[1<<15],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1,x,y,z;i<n;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		a[x]^=z;a[y]^=z;
	}
	for(int i=0;i<n;i++)
		if(a[i]--)
			ans+=m>>a[i]&1,m^=1<<a[i];
	for(int s=1;s<=m;++s)
	{
		int x=0;
		for(int j=0;j<16;++j)if(s>>j&1)x^=j+1;
		if(x)f[s]=1e9;
		else{
			f[s]=__builtin_popcount(s)-1;
			for(int t=(s-1)&s;t;t=(t-1)&s)ckmin(f[s],f[t]+f[s^t]);
		}
	}
	printf("%d",ans+f[m]);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  int64_t a[100], ct = 0;
 
  while (n > 0) {
    n--;
    a[ct] = n % 26;
    n /= 26;
    ct++;
  }
  for (int i = ct - 1; i >= 0; i--) {
    cout << (char)('a'+a[i]);
  }
  return 0;
}

Measured memory_bytes: 3636
N, M ,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Sa = [0]*(N+1)
Sb = [0]*(M+1)
Sa[0] = 0
Sb[0] = 0
for i in range(N):
    Sa[i+1] = Sa[i] + A[i]
for i in range(M):
    Sb[i+1] = Sb[i] + B[i]
ans = 0
for i in range(N+1):
    if Sa[i] > K:
        break
    for j in range(M, -1, -1):
        if Sa[i]+Sb[j] <= K:
            ans = max(ans, i+j)
            M = j
            break
    else:
        ans = max(ans, i)
print(ans)


Measured memory_bytes: 110892
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    int N,M;
    cin >> N >> M;
    vector < int > vt[N];
    int a,b;
    for(int i=0; i<M; i++){
        cin >> a >> b;
        a--;
        b--;
        vt[a].push_back(b);
        vt[b].push_back(a);
    }
    bool ans=false;
    for(int s1=0; s1<vt[0].size(); s1++){
        for(int s2=0; s2<vt[vt[0][s1]].size(); s2++){
            if(vt[vt[0][s1]][s2]==N-1){
                ans=true;
                break;
            }
        }
    }
    if(ans)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    
    return 0;
}

Measured memory_bytes: 12016
#include <iostream>
#define L 250000
using namespace std;
int main(){
  int n,i,j,sosu[L],cnt;
  for(i=0;i<L;i++)sosu[i]=1;
  sosu[0]=0;
  sosu[1]=0;
  for(i=0;i<L/2;i++){
    if(sosu[i]==1){
      for(j=i*2;j<L;j+=i){
        sosu[j]=0;
      }
    }
  }
   while(1){
    cin >> n;
    if(n==0) break;
    cnt=0;
    for(i=n+1;i<=2*n;i++){
      if(sosu[i]==1) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int a[2*maxn];
int n;

bool check(int mid){
	int curr = 1;
	for(int i = 0; i < n; i++){
		if(a[i] == curr){
			curr++;
		}
	}

	return curr-1 >= mid;
}

int32_t main(){
	fastio();
	cin >> n;
	forr(i,n) cin >> a[i];

	int ans = -1;
	int low = 1, high = n;
	while(low <= high){
		int mid = (low + high)/2;
		if(check(mid)){
			ans = mid;
			low = mid + 1;
		}else high = mid - 1;
	}	

	if(ans != -1) ans = n - ans;
	cout << ans;
}

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

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            //string s = Console.ReadLine();

            // 整数の入力
            int n = int.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            //var inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            int nn = n % 10;
            string result = "hon";

            if(nn==0 | nn== 1 |nn==6 | nn == 8)
            {
                result = "pon";
            }

            else if (nn == 3)
            {
                result = "bon";
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27472
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

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

Measured memory_bytes: 3724
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int a[] = new int[n];
        int c[] = new int[n-1];
        int ans = 0;

        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        for (int i = 0; i < n; i++) ans += sc.nextInt();
        for (int i = 0; i < n-1; i++) c[i] = sc.nextInt();
        for (int i = 0; i < n-1; i++) {
            if (a[i] == a[i+1] - 1) {
                ans += c[a[i]-1];
            }
        }

        System.out.println(ans);
        sc.close();

	}
}

Measured memory_bytes: 23636
class BitSeacher:
    def __init__(self,bitcount):
        self.counter =0
        self.bitcount = bitcount
        self.mx = 2**bitcount-1
    
    def __next__(self):
        if self.counter > self.mx:
            raise StopIteration()
        ans =[]
        flg =1
        for i in range(self.bitcount):
            if flg & self.counter != 0:
                ans.append(i)
            flg = flg.__lshift__(1)
        self.counter+=1
        return ans

    def __iter__(self):
        return self

def checker(A,group,K):
    if len(group) < K:
        return 10**20

    tbl = [False for i in A]
    for i in group:
        tbl[i]=True
    mx = 0
    count = 0
    for i in range(len(A)):
        if not tbl[i]:
            mx = max(mx,A[i])
            continue
        
        if mx < A[i]:
            mx = A[i]
        else:
            count += mx - A[i] +1
            mx +=1
    return count






def resolve():
    N,K = map(int,input().split())
    A= list(map(int,input().split()))
    mn = 10**20
    for group in BitSeacher(N):
        group.sort()
        mn = min(mn,checker(A,group,K))

    print(mn)



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 45276
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int H, W;
  while (true) {
    cin >> H >> W;
    if (H == 0 && W == 0) return 0;
    for (int h = H; h > 0; h--) {
      for (int w = W; w > 0; w--) {
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1156
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
class Data{
    private int a;
    private int b;
    public Data(int a, int b) {
        this.a = a;
        this.b = b;
    }
    public int getA() {
        return a;
    }
    public int getB() {
        return b;
    }
}
public class Main {    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();        
		int a = sc.nextInt();
        int [] s = new int [n];
        for(int i=0;i<n;i++){s[i]=sc.nextInt();}
        Arrays.sort(s);
		int [] in = new int [a];
        int [] in2 = new int [a];
        long ans = 0;       
        Data [] d = new Data [a];
         for(int i=0;i<a;i++){int B = sc.nextInt();
                              int C = sc.nextInt();
                              d[i] = new Data(B,C);                            
                             }
        Arrays.sort(d, new Comparator<Data>() {
            public int compare(Data d1, Data d2) {
                return d1.getB() - d2.getB();
            }
        }); 
        int b = a-1;
        int count = 0;
        for(int i=0;i<n;i++){if(b>=0 && d[b].getB()>s[i]){s[i]=d[b].getB();
                                                          count++;                                                 
                                                          if(count==d[b].getA())
                                                          {b--;count=0;}
                                                         }else{break;}
                  }        
		for(int i=0;i<n;i++){ans+=s[i];}
        System.out.println(ans);
	}
}

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

#define int long long

// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1

// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())

// debug
#define check(x) std::cout << #x << " = " << x << '\n'

// print
#define cout(x) std::cout << x << '\n'

// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<std::string> VS;

int SumOfDigits(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

void PrintMap(std::map<int, int>& m) {
  for (auto iter: m) {
    std::cout << iter.first << " => " << iter.second << "\n";
  }
}

int Digits(int x) {
  int d = 0;
  while (x > 0) {
    x /= 10;
    d++;
  }
  return d;
}

signed main() {
  int n;
  std::cin >> n;
  VI a(n);
  REP(i, n) {
    std::cin >> a.at(i);
  }
  
  int i = 0;
  int c = 1;
  bool b;	// t: ascending, f: descending
  bool is_first = true;
  while (true) {
    if (i == n-1) {
      cout(c);
      return 0;
    }
    if (is_first) {
      if (a.at(i+1) > a.at(i)) {
        b = true;
        is_first = false;
      } else if (a.at(i+1) < a.at(i)) {
        b = false;
        is_first = false;
      }
      i++;
      continue;
    }
    if (b && a.at(i+1) < a.at(i)) {
      is_first = true;
      c++;
    } else if (!b && a.at(i+1) > a.at(i)) {
      is_first = true;
      c++;
    }
    i++;
  }
  
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
set<string>s;
string b;
cin>>b;
s.insert(b);
n--;
string d=b;
bool flag=true;
bool flag1=false;
while(n--){
    string c;
    cin>>c;
    if(s.count(c)==0 && c[0]==d[d.length()-1]){d=c;s.insert(c);}
    else flag=false;
}
    if(flag){cout<<"Yes"<<endl;}
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    int n, m;
    scanf("%d%d", &m, &n);
    for(int i = 0, x; i < n; i++) {
        scanf("%d", &x);
        m -= x;
    }
    printf("%d\n", m < 0 ? -1 : m);
    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>

using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
#define eps 1.0e-14;

/*int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int begintime = h1 * 60 + m1;
    int endtime = h2 * 60 + m2 - k;
    cout << endtime - begintime << endl;
    return 0;
}*/

int main(){
    string S;
    cin >> S;
    for (int i = 0; i < S.length(); i++){
        if(S[i] == '?'){
            if(i == 0){
                S[0] = 'D';
                continue;
            }else {
                S[i] = 'D';
            }
        }
    }
    cout << S << endl;
}
/*
PD?D??P

*/

Measured memory_bytes: 3752
n = int(input())
a = []

for i in range(n):
    a.append(int(input()))

a = sorted(a)

hoge = 0
foo = 0
ans = 0

for i in range(n):
    if i == 0:
        foo = a[i]
        hoge = 1
    elif i == n-1:
        if foo != a[i]:
            if hoge == 1:
                ans += 1
            ans += 1
        else:
            if hoge == 0:
                ans += 1
    elif foo == a[i]:
        hoge = 1-hoge
    else:
        if hoge == 1:
            ans += 1
        foo = a[i]
        hoge = 1

print(ans)


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

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    constexpr unsigned long Amax = 300000;
    vector<unsigned long> sgt(2 * (Amax + 1));
    const auto& upd = [&sgt](unsigned long i, unsigned long x){
        i += Amax + 1;
        sgt[i] = x;
        while(i >>= 1)sgt[i] = max(sgt[2 * i], sgt[2 * i + 1]);
    };
    const auto& fold = [&sgt](unsigned long L, unsigned long R){
        L += Amax + 1;
        R += Amax + 1;
        unsigned long ret{0};
        while(L < R){
            if(L & 1){
                ret = max(ret, sgt[L]);
                ++L;
            }
            if(R & 1){
                --R;
                ret = max(ret, sgt[R]);
            }
            L >>= 1;
            R >>= 1;
        }
        return ret;
    };
    for(unsigned long i{0}, A; i < N; ++i){
        cin >> A;
        upd(A, fold(max(K, A) - K, min(A + K, Amax) + 1) + 1);
    }
    cout << sgt[1] << endl;
    return 0;
}


Measured memory_bytes: 8016