akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

const int N = 1e5 + 2;

int n;
int ar[3 * N];
priority_queue<int, vector<int>, greater<int>> p1;
priority_queue<int> p2;
ll sum1, sum2, ans = -1e18;
ll mx[3 * N], mn[3 * N];

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

  cin >> n;
  for(int i = 1; i <= 3 * n; i++) {
    cin >> ar[i];
  }
  for(int i = 1; i <= n; i++) {
    p1.push(ar[i]);
    sum1 += ar[i];
  }
  // cerr << p1.top() << ":D\n";
  mx[n] = sum1;
  for(int i = n + 1; i <= 2 * n; i++) {
    sum1 += ar[i];
    p1.push(ar[i]);
    sum1 -= p1.top();
    // cerr << i << ' ' << p1.top() << '\n';
    p1.pop();
    mx[i] = max(mx[i - 1], sum1);
  }
  for(int i = 3 * n; i >= 2 * n + 1; i--) {
    p2.push(ar[i]);
    sum2 += ar[i];
  }
  mn[2 * n + 1] = sum2;
  for(int i = 2 * n; i >= n + 1; i--) {
    sum2 += ar[i];
    p2.push(ar[i]);
    sum2 -= p2.top();
    p2.pop();
    mn[i] = min(mn[i + 1], sum2);
  }
  for(int i = n; i <= 2 * n; i++) {
    // cerr << mx[i] << ' ' << mn[i + 1] << '\n';
    ans = max(ans, mx[i] - mn[i + 1]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 6912
#include <iostream>
static const int INF = int(1e8);
using namespace std;
 
int dp[55555] = {};
int denom[55555] = {};
int main() {
  int n; int m; 
  cin >> n; cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> denom[i];
  }
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i] = INF;
    for (int j = 0; j <= m; j++) {
      if (i >= denom[j]) {
        dp[i] = min(dp[i], dp[i-denom[j]]+1);
      }
    }
  }
  cout << dp[n] << "\n";
  return 0;
}

Measured memory_bytes: 3280
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    long long s;
    std::cin >> s;

    if (s == 1e18) {
        std::cout << "0 0 1000000000 0 0 1000000000" << std::endl;
        return 0;
    }

    long long a = s / (long long)1000000000;
    long long b = s % (long long)1000000000;

    std::cout << "0 0 1000000000 1 " << 1000000000 - b << " " << a + 1;
}


Measured memory_bytes: 256
S = input()
N = len(S)

def checkPalindrome(string):
  for i in range(len(string)//2):
    if string[i] != string[len(string)-i-1]:
      return False
  else:
    return True

sub1 = S[0:(N-1)//2]
sub2 = S[(N+3)//2-1:N]

if checkPalindrome(S) and checkPalindrome(sub1) and checkPalindrome(sub2):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define f(i,a,n)        for(ll i=a;i<n;i++)
#define ve              vector
#define ss              second 
#define ff              first
#define pf              pop_front
#define pob             pop_back
#define psf             push_front
#define res(x)          cout<<x<<'\n'
#define read(t)         ll t;cin>>t

#define pii             pair<ll,ll>
#define vii             vector<ll,ll>
#define INFI            1000000000000000000;

int main(){
   
   ll n,d;
   cin>>n>>d;
   ll ans=0;
   d=d*d;
   f(i,0,n){
       ll x,y;
       cin>>x>>y;
       ll temp=x*x+y*y;
       if(temp<=d){
           ans++;
       }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3632
n, x, y = map(int, input().split())

ans = [0] * (n-1)
for i in range(1, n+1):
    for j in range(i+1, n+1):
        ans[min(abs(i-j), abs(i-x) + abs(j-y) + 1) - 1] += 1

print(*ans, sep="\n")

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

using namespace std;

namespace {
using ll = long long;
constexpr ll MOD = 1e9+7;
auto pow_mod(ll x, ll p) {
  ll t = 1;
  ll u = x;
  while (p) {
    if (p&1) {
      t = t * u % MOD;
    }
    u = u * u % MOD;
    p >>= 1;
  }
  return t;
}
}

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

  int N; cin>>N;
  vector<ll> C(N); for (auto& c : C) cin>>c;
  sort(C.rbegin(), C.rend());
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ans = (ans + (C[i] * (i+2) % MOD)) % MOD;
  }
  ans = ans * pow_mod(4, N-1) % MOD;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
n,w=map(int,input().split())
W=[]
V=[]
for _ in range(n):
    a,b=map(int,input().split())
    W.append(a)
    V.append(b)

dp=[[0]*(w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if W[i]>j:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=max(dp[i][j],dp[i][j-W[i]]+V[i])
print(dp[n][w])

Measured memory_bytes: 149852
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    string s;
    cin>>s;
    int n=s.size();
    int win=0,lose=0;
    int g=0,p=0;
    rep(i,n){
        if(s[i]=='g'){
            if(g>p){
                win++;
                p++;
            }
            else{
                g++;
            }
        }
        else{
            if(g>p){
                p++;
            }
            else{
                lose++;
                g++;
            }
        }
    }
    cout<<win-lose<<endl;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque 

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# ---------------------------------------

mod = 10**9 + 7

H, W = inpl()
a = []
flag = [[False] * W for i in range(H)]
for i in range(H):
    a.append(input().strip())
_debug(a)
dp = [[0] * (W+1) for i in range(H+1)]
dp[0][0] = 1

for i in range(max(H, W)):
    if i < H:
        for j in range(W):
            if a[i][j] == "#" or flag[i][j]:
                continue
            flag[i][j] = True
            for x, y in ((0, 1), (1, 0)):
                dp[i+x][j+y] += dp[i][j]
                dp[i+x][j+y] %= mod
    if i < W:
        for j in range(H):
            if a[j][i] == "#" or flag[j][i]:
                continue
            flag[j][i] = True
            for x, y in ((0, 1), (1, 0)):
                dp[j+x][i+y] += dp[j][i]
                dp[j+x][i+y] %= mod
    
print(dp[H-1][W-1])

Measured memory_bytes: 92820
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,k;
    long long ans = 0;
    cin >> n >> k;
    for(int i = k+1;i < n+1;i++){
        ans = ans + (n/i)*(i-k) + max(n%i - k + 1,0ll);
    }
    if(k == 0){
        ans = pow(n,2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
  int a,b;
  cin >> a >> b;
  if((a+b)%2==1) cout << "IMPOSSIBLE" << endl;
  else cout << (a+b)/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  rep(i, n) cin >> vec[i];
  for(int i=k; i<n; i++){
    if(vec[i] > vec[i-k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}
  
  
  
  

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m,a,b;cin>>a>>b;
    cout << max(a*b,max(a+b,a-b)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define each(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define out(x) rep(i, 0, x.size()) cout << x[i] << ((i != x.size() - 1) ? " " : "\n")
const double PI = 3.14159265;
const int MAXN = 1 << 15;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
#define Pr(a) (#a) << "=" << (a) << " "
#define pr(a) cout << Pr(a) << '\n'
///////////////////////////////////////////////////////////

int N;
vector<int> V;
deque<int> D;
list<int> L;

int main() {
  int q;
  cin >> N >> q;
  vector<stack<int>> S(N);
  while (q--) {
    int cmd, t;
    cin >> cmd >> t;
    if (cmd == 0) {
      int x;
      cin >> x;
      S[t].push(x);
    }
    if (cmd == 1) {
      if (!S[t].empty()) cout << S[t].top() << '\n';
    }
    if (cmd == 2) {
      if (!S[t].empty()) S[t].pop();
    }
  }
  return 0;
}


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

typedef long long ll;
const long long INF = 2147483647;

int main(){
    while( true ){
        ll z;
        cin >> z;
        if( !z ) break;
        ll zzz = z*z*z;
        ll min = INF;
        for(ll x = 1; x < z; x++){
            ll d = INF;
            ll xxx = x*x*x;
            for(ll y = z-1; y > 0; y--){
                d = zzz - xxx - y*y*y;
                if( d > 0 ) break;
            }
            if( d < min ) min = d;
        }
        cout << min << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
lint mod=1'000'000'007;/*{{{*/
lint inverse(lint x){
    assert(x%mod);
    lint y=1,u=mod,v=0;
    while(x){lint q=u/x;u-=q*x;std::swap(u,x);v-=q*y;std::swap(v,y);}
    assert(x==0&&std::abs(u)==1&&std::abs(y)==mod&&std::abs(v)<mod);
    return v<0?v+mod:v;
}
lint normalized(lint x){if(x<=-mod||mod<=x)x%=mod;if(x<0)x+=mod;return x;}
struct mint{
    lint value;
    mint()=default;
    mint(lint x):value(normalized(x)){}
};
std::ostream&operator<<(std::ostream&os,mint x){return os<<x.value;}
mint operator+(mint x,mint y){lint z=x.value+y.value;if(mod<=z)z-=mod;return mint{z};}
mint operator-(mint x,mint y){lint z=x.value-y.value;if(z<0)z+=mod;return mint{z};}
mint operator*(mint x,mint y){return mint{x.value*y.value%mod};}
mint operator/(mint x,mint y){return mint{x.value*inverse(y.value)%mod};}
mint&operator+=(mint&x,mint y){return x=x+y;}
mint&operator-=(mint&x,mint y){return x=x-y;}
mint&operator*=(mint&x,mint y){return x=x*y;}
mint&operator/=(mint&x,mint y){return x=x/y;}
bool operator==(mint x,mint y){return x.value==y.value;}
bool operator!=(mint x,mint y){return x.value!=y.value;}
mint power(mint x,lint y){mint z=1;for(;y;y>>=1){if(y&1)z*=x;x*=x;}return z;}/*}}}*/
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,k;std::cin>>n>>k;
    std::vector<lint>min(n+2),max(n+2);
    for(lint i=0;i<=n;i++)min.at(i+1)=min.at(i)+i;
    for(lint i=0;i<=n;i++)max.at(i+1)=max.at(i)+n-i;
    mint ans=0;
    for(lint i=k;i<=n+1;i++)ans+=max.at(i)-min.at(i)+1;
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 6368
from collections import defaultdict
from collections import deque
dic = defaultdict(set)
n = int(input())
for i in range(n-1):
    a, b = map(int, input().split())
    dic[a].add(b)
    dic[b].add(a)
q = deque([(1, 'F'), (n, 'S')])
seen = set([1, n])
f = 1
s = 1
while q:
    p, player = q.popleft()
    for child in dic[p]:
        if child not in seen:
            seen.add(child)
            q.append((child, player))
            if player == 'F':
                f += 1
            else:
                s += 1
print('Fennec' if f > s else 'Snuke')


Measured memory_bytes: 90328
# initialize
@list = []
@d = []
@f = []
@time = 0

# depth first search
def d_search(i)
  @time += 1
  @d[i] = @time

  @list[i].sort.each do |j|
    d_search(j-1) unless @d[j-1]
  end

  @time += 1
  @f[i] = @time
end

# main
n = gets.to_i
n.times do
  u, k, *v = gets.split.map {|i| i.to_i}
  @list[u-1] = v
end

(0..n-1).each do |i|
  d_search(i) unless @d[i]
end

(0..n-1).each do |i|
  puts "#{i+1} #{@d[i]} #{@f[i]}"
end

Measured memory_bytes: 8884
#include <iostream>

using namespace std;

void printArray(int *a, int n) {
    for(int i = 0 ; i < n ; i++) {            
        cout << *a;
        if(i != n -1) {
            cout << " ";
        } else {
            cout << "\n";
        }
        a++;
    }
}

void insertionSort(int a[], int n) {
    int v = 0;
    int j = 0;
    for(int i = 1 ; i < n ; i++) {
        printArray(a, n);
        v = a[i];
        j = i - 1;
        while( j >= 0 && a[j] > v ) {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
    }
    printArray(a, n);
}

int main(int, char**) {
    int a[1000];
    int l;
    int n;
    cin >> n;
    int i = 0;
    while(cin>>l){
        a[i] = l;
        i++;
    }
    insertionSort(a, n);
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[100010],b[100010];
int n,ans;
map<LL,int>mp;
LL sqr(LL x){return x*x;}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		LL x;
		scanf("%lld",&x);
		for(LL j=2;j*j*j<=x;j++) for(;x%(j*j*j)==0;x/=j*j*j);
		mp[x]++;
		a[i]=x;
		LL y=1;
		for(LL j=2;j*j*j<=x;j++) if(x%j==0){
			y*=(x%(j*j)==0)?j:j*j;
			for(;x%j==0;x/=j);
		}
		if(sqr((LL)sqrt(x))==x) y*=(LL)sqrt(x);
		else y*=x*x;
		b[i]=y;
	}
	if(mp[1]) ans++,mp[1]=0;
	for(int i=1;i<=n;i++){
		ans+=max(mp[a[i]],mp[b[i]]);
		mp[a[i]]=mp[b[i]]=0;
	}
	printf("%d",ans);
	return 0;
}
/*
8
1
2
3
4
5
6
7
8
*/

Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	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;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
ll D = 365;
ll T = 26;//タイプ数
ll c[27];
ll s[366][27];

vvll last(T + 1);

ll score(vll t) {

	repn(i, D) {

	}

	ll ret = 0;
	repn(i, D) {
		ret += s[i][t[i]];
	}
	
}


int main() {
	cin >> D;
	repn(i, T) cin >> c[i];
	repn(i, D)repn(j, T) cin >> s[i][j];
	
	repn(i, D) {
		ll id = 1;
		repn(j, T) {
			if (s[i][id] < s[i][j]) { id = j; }
			}
		cout << id << endl;
	}
	
}

Measured memory_bytes: 3756
#include<stdio.h>
#include<algorithm>
int main() {
	
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int a, b;

	scanf("%d %d", &a, &b);

	if (a == 0) {
		if (b == 100) {
			printf("101");
		}
		else {
			printf("%d", b);
		}
	}
	else if (a == 1) {
		if (b == 100) {
			printf("10100");
		}
		else {
			printf("%d", b * 100);
		}
	}
	else {
		if (b == 100) {
			printf("1010000");
		}
		else {
			printf("%d", b * 10000);
		}
	}
	
}

Measured memory_bytes: 128
n = int(input())


a = list(map(int, input().split()))
a.insert(0,0)
a.append(0)
total = 0
#total += abs(0 - a[0])
for i in range(n+1):
  total += abs(a[i] - a[i+1])
  
#total += abs(0 - a[n-1])


for i in range(1,n+1):
  ans = total - (abs(a[i-1] - a[i]) + abs(a[i] - a[i+1])) + abs(a[i-1] - a[i+1])
  print(ans)

Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;
const int maxn = 3123;
ll dp[2][maxn][maxn];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n + 1);
	for(int i = 1; i <= n; ++ i) cin >> a[i];
	for(int i = n; i >= 0; --i) {
		for(int j = i; j <= n; ++ j) {
			dp[0][i][j] = max(dp[1][i + 1][j] + a[i], dp[1][i][j - 1] + a[j]);
			dp[1][i][j] = min(dp[0][i + 1][j] - a[i], dp[0][i][j - 1] - a[j]);
		}
	}
	cout << dp[0][1][n] << '\n';
}


Measured memory_bytes: 147712
#include<iostream>
#include<map>
using namespace std;
map < string , bool > used;

int n,k,ans;
string t[10];
bool u[10];

void dfs(int depth,string str){
  if(depth==k){
    if(!used[str])ans++;
    used[str]=true;
    return;
  }
  for(int i=0;i<n;i++){
    if(u[i])continue;
    u[i]=true;
    dfs(depth+1,str+t[i]);
    u[i]=false;
  }
}

int main(){
  while(cin>>n>>k&&n&&k){
    for(int i=0;i<n;i++)u[i]=false;
    ans=0;
    used.clear();
    for(int i=0;i<n;i++)cin>>t[i];
    dfs(0,"");
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1508
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mset(s,_) memset(s,_,sizeof s)
#define fi first
#define se second
#define pb push_back

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

ll dp[2222][3333];
vector<pair<ll,int> >p;
int n;

ll dfs(int pos,int l,int r){
	if(pos>=n) return 0;
	if(dp[l][r]!=-1) return dp[l][r];
	ll t1=dfs(pos+1,l+1,r)+p[pos].fi*abs(p[pos].se-l);
	ll t2=dfs(pos+1,l,r-1)+p[pos].fi*abs(r-p[pos].se);
	return dp[l][r]=max(t1,t2);
}
			
int main(){
 cin>>n;
 rep(i,0,n-1){
	int tp;
	cin>>tp;
	p.pb({tp,i});
 }
 sort(p.rbegin(),p.rend());
 mset(dp,-1);
 ll ans=dfs(0,0,n-1);
 cout<<ans<<'\n';
}

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s; cin >> s;
  int n = (int) s.length();
  int i = 0, j = n - 1;
  bool ok = true;
  while(i < j) {
    ok &= (s[i++] == s[j--]);
  }
  i = 0, j = (n - 1) / 2 - 1;
  while(i < j) {
    ok &= (s[i++] == s[j--]);
  }
  i = (n + 3) / 2 - 1, j = n - 1;
  while(i < j) {
    ok &= (s[i++] == s[j--]);
  }
  cout << (ok ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool sosuu[1111111];
vector<int> v;
int a[33],x,N;
//bool dp[33][1111111];
//bool used[33][1111111];
bool solve(int n,int m){
  if(m == 0) return true;
  if(n == N) return false;
  //if(used[n][m]) return dp[n][m];
  //used[n][m] = true;

  bool res = solve(n+1,m);
  if(!res && m >= a[n]) res |= solve(n,m-a[n]);
  //return dp[n][m] = res;
  return res;
}
int main(void){
  sosuu[0] = sosuu[1] = true;
  for(int i = 0; i*i <= 1000000; i++){
    if(sosuu[i]) continue;
    for(int j = i+i; j <= 1000000; j += i){
      sosuu[j] = true;
    }
  }
  for(int i = 0; i <= 1000000; i++){
    if(!sosuu[i]){
      v.push_back(i);
    }
  }

  while(cin >> N >> x){
    if(!N)break;
    //memset(used,false,sizeof(used));
    for(int i = 0; i < N; i++){
      cin >> a[i];
    }
    int i;
    for(i = (int)v.size()-1;i >= 0; i--){
      if(x < v[i]) continue;
      if(solve(0,v[i]))break;
    }
    if(i+1){
      cout << v[i] << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 2568
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = 0;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
void print(int x, char ch = '\n'){
	if (x == 0) return putchar('0'), putchar(ch), void(0);
	int cnt = 0, num[25];
	for (x < 0 ? putchar('-'), x = -x : 0; x; x /= 10) num[++cnt] = x % 10;
	while (cnt) putchar(num[cnt] ^ '0'), --cnt;
	putchar(ch);
}
const int N = 300005;
int n, m, cnt;
struct node{
	int l, r, len;
	bool operator < (const node &rhs) const { return len < rhs.len; }
}a[N];
struct BIT{
	int c[N];
	void add(int x, int v){
		for (; x <= m; x += x & -x) c[x] += v;
	}
	int query(int x){
		int s = 0;
		for (; x; x ^= x & -x) s += c[x];
		return s;
	}
}Tl, Tr;
int main(){
	n = read(), m = read();
	for (register int i = 1; i <= n; ++i)
		a[i].l = read(), a[i].r = read(), a[i].len = a[i].r - a[i].l + 1;
	std::sort(a + 1, a + 1 + n);
	int k = 1;
	for (register int i = 1; i <= m; ++i){
		int s = n - k + 1;
		for (register int j = i; j <= m; j += i)
			s += Tl.query(j) - Tr.query(j - 1);
		print(s);
		while (k <= n && a[k].len == i) Tl.add(a[k].l, 1), Tr.add(a[k].r, 1), ++k;
	}
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end_()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define strep(it,v) for(it=v.begin();it!=v.end_();++it)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a);  a = (a * a);  b/=2;  }  return res; }
#define rs resize
long long readLI(){  register char c;  for(c = getchar(); !(c>='0' && c<='9'); c = getchar());  register long long a=c-'0';
    for(c = getchar(); c>='0' && c<='9'; c = getchar())
        a = (a<<3)+(a<<1)+c-'0';
    return a;
}
const ll N = 1000011;
ll i,n,ans,a[N];
int main()
{
   std::ios_base::sync_with_stdio(false); cin.tie(NULL);
   cin>>n;
   rep(i,0,n) cin>>a[i];
   rep(i,0,n){
      if(a[i] == i + 1){
        if(i == n - 1) swap(a[i],a[i - 1]);
        else
          swap(a[i],a[i + 1]);
        ans++;
      }
   }
   cout<<ans;
   return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
int main()
{
	int D,N;
	scanf("%d%d",&D,&N);
	if(D==0)
	{
		if(N<100) printf("%d\n",N);
		else printf("%d\n",N+1);
		return 0;
	}
	if(D==1)
	{
		if(N<100) printf("%d\n",N*100);
		else printf("%d\n",(N+1)*100);
		return 0;
	}
	if(D==2)
	{
		if(N<100) printf("%d\n",N*10000);
		else printf("%d\n",(N+1)*10000);
		return 0;
	}
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
    int H, N; cin >> H >> N;
    int dp[H+1];
    const int INF = 1<<30;
    fill(dp, dp+H, INF);
    dp[H] = 0;
    while (N--) {
        int a, b; cin >> a >> b;
        for (int i = H; i >= a; i--)
            dp[i-a] = min(dp[i-a], b + dp[i]);
        for (int i = min(H, a-1); i >= 0; i--) dp[0] = min(dp[0], b + dp[i]);
    }
    cout << dp[0] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
	int A, B, X;
	cin >> A >> B >> X;
	if (A <= X&&A + B >= X) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

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

//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;
//#define input(a) scanf("%lld", &(a))
//#define output(a) printf("%lld\n", (a))

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }

def input() {
    ll A;
    cin >> A;
    return A;
}

ll H, W, K, res, A[101][8];

signed main() {
    cin >> H >> W >> K;
    A[0][0] = 1;
    rep(h, H) {
        rep(i, (1 << (W - 1))) {
            ll D[W - 1], P[W];
            rep(k, W) P[k] = A[h][k];
            rep(k, W - 1) {
                if (i & (1 << k))
                    D[k] = 1;
                else
                    D[k] = 0;
            }
            rep(k, W - 2) if (D[k] && D[k + 1]) goto hell;
            rep(k, W - 1) if (D[k]) swap(P[k], P[k + 1]);
            rep(k, W) A[h + 1][k] += P[k], A[h + 1][k] %= MOD;
        hell:;
        }
    }
    cout << A[H][K - 1] << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i,n)cin>>h[i];

    int cnt=0;
    rep(i,n){
        if(h[i]>=k)++cnt;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3772
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

string s;

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

    cin>>s;
    if(s=="ABC")cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

const int INT = 1e9;
const int mod = 1e9+7;

int main()
{
    ll x,xx;
    cin >> x;

    xx = x;

    for(int i = sqrt(x); i >= 2; i--){
        while(x % i == 0 && x / i >= sqrt(xx)){
            x /= i;
        }
    }

    int ans = 0;
    while(x){
        x /= 10;
        ans++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, d, cnt=0;
	cin>>n>>d;
	for(int i=1;i<=n;i++){
		int x, y;
		cin>>x>>y;
		if(x*x+y*y<=d*d) cnt++;
	}
	cout<<cnt;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,m,l=0,r=10000000;
    cin>>n>>m;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        l=max(l,a);
        r=min(r,b);
    }
    int ans=0;
    ans=max(r-l+1,0);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    double res = 0;
    while(n--){
        double x;
        string s;cin>>x>>s;
        if(s == "JPY")res += x;
        if(s == "BTC")res += (380000*x);
    }
    cout<<res;
}



Measured memory_bytes: 256
// 2018/12/30 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;

	int W[50] = {0};
	int B[50] = {0};
	int R[50] = {0};
	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++){
			char c;
			cin >> c;

			if(c=='W'){
				W[i]++;
			}
			else if(c=='B'){
				B[i]++;
			}
			else{
				R[i]++;
			}
		}
	}
/*
	for(int i=0; i<N; i++){
		cout << W[i] << ' ' << B[i] << ' ' << R[i] << endl;
	}
*/

	int DP_W[50];
	DP_W[0] = B[0]+R[0];
	for(int i=1; i<N-2; i++){
		DP_W[i] = DP_W[i-1]+B[i]+R[i];
	}
	DP_W[N-2] = 3000;
	DP_W[N-1] = 3000;

	int DP_B[50];
	DP_B[0] = 3000;
	for(int i=1; i<N-1; i++){
		DP_B[i] = min(DP_W[i-1], DP_B[i-1])+W[i]+R[i];
	}
	DP_B[N-1] = 3000;

	int DP_R[50];
	DP_R[0] = 3000;
	DP_R[1] = 3000;
	for(int i=2; i<N; i++){
		DP_R[i] = min(DP_B[i-1], DP_R[i-1])+W[i]+B[i];
	}

	cout << DP_R[N-1] << endl;

	return 0;
}



Measured memory_bytes: 3124
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math



a,b,k = map(int, input().split())

for _ in range(k):
  a -= a&1
  a //= 2
  b += a
  a,b = b,a

if k&1 > 0:
  print(b,a)
else:
  print(a,b)

Measured memory_bytes: 38384
/* Simplicity and Goodness */
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


void solve()
{
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);

    vl x(n);

    rep(i, 0, n)
    lscn(x[i]);

    ll fatigue = 0;

    rep(i, 1, n) {
        ll walk = (x[i] - x[i-1]) * a;
        ll tele = b;

        fatigue += min(walk, tele);
    }

    lprin(fatigue);
}

int main()
{
    int t = 1;
    // scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;R(i,n*2)cin>>c[i/n][i%n];fill(p[1],p[1<<n],1e9);R(B,1<<n){int o=0,d[n];R(i,n)d[i]=~B&1<<i?o++:0;R(i,n){int k=c[(i-n+o)&1][i],&t=p[B|1<<i][k];R(j,k+1)t=min(t,p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}

Measured memory_bytes: 52608
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	n := readInt()
	l := make([]int, n+1)
	l[0], l[1] = 2, 1
	for i := 2; i <= n; i++ {
		l[i] = l[i-1] + l[i-2]
	}
	fmt.Println(l[n])
}


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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

using ll = long long;
using ull = unsigned long long;

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

ll mod_neg(ll val, ll m)
{
    ll res = val % m;
    if (res < 0) res += m;
    return res;
}

void Main()
{
	ll N = 0;
	cin >> N;

    ll cnt = 0;
    for (ll a = 1; a < N; ++a) {
        double x = 1.0 * (N - 1) / a;
        cnt += (ll)floor(x);
    }
    cout << cnt;
    return;
}

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

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

string s, t;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> s >> t;
    
    bool fixed = false;
    for (int i = s.size() - t.size(); i >= 0; --i) {
		if (s[i] == t[0] || s[i] == '?') {
			bool valid = true;
			for (int j = 0; j < t.size(); j++) {
				if (s[i + j] != '?' && s[i + j] != t[j]) valid = false;
			}
			
			if (valid) {
				fixed = true;
				for (int j = 0; j < t.size(); j++) {
					s[i + j] = t[j];
				}
				for (int j = 0; j < s.size(); j++) {
					if (s[j] == '?') s[j] = 'a';
				}
				break;
			}
		}
	}
    
    fixed ? cout << s : cout << "UNRESTORABLE";
    return 0;
}


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

int main(){
    ll n,k;
    cin>>n>>k;
    ll a[n],curr=1,loop=0;
    for(ll i=0;i<n;i++) cin>>a[i];
    map<ll,ll> ma,ma1;
    ma[1]++;
    while(k>0){
        curr=a[curr-1];
        k--;
        if(ma[curr]>0)  break;
        ma[curr]++;
    }
    ma1[curr]++;
    while(k>0){
        curr=a[curr-1];
        k--;
        if(ma1[curr]>0)  break;
        ma1[curr]++;
        loop++;
    }
    if(k>0) k%=(loop+1);
    while(k>0){
        curr=a[curr-1];
        k--;
    }
    cout<<curr<<endl;
    return 0;
}


Measured memory_bytes: 21828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

/////////////////////////////////////////////////////////

void Main() {
  ll N; cin >> N;
  vector<ll> P(N);
  vector<ll> Q(N);
  rep(i, 0, N){
    cin >> P[i];
    P[i]--;
    Q[P[i]] = i;
  }
  ll cnt = 1;
  ll cur = 0;
  ll ma = 0;
  while(true){
    if(cur == N - 1){
      chmax(ma, cnt);
      break;
    }
    if(Q[cur + 1] > Q[cur]) cnt++;
    else{
      chmax(ma, cnt);
      cnt = 1;
    }
    cur++;
  }
  cout << N - ma << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 3456
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (b - a == c - b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


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

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

    ll n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    s += (s[n-1] == 'R')? 'L' : 'R';
    
    vector<int> len;
    char now = s[0];
    int count = 0;
    rep(i,n+1){
        if(now == s[i]){
            count++;
        }
        else{
            len.push_back(count - 1);
            now = (now == 'R')? 'L' : 'R';
            count = 1;
        }
    }
    
    ll ans = 0;
    rep(i, len.size()){
        ans += len[i];
    }
    ans += 2 * k;
    
    cout << min(n - 1, ans) << endl;

    return 0;
}

Measured memory_bytes: 972
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n string
	fmt.Scanf("%s", &n)
	var sum int
	for _, v := range n {
		i, _ := strconv.Atoi(string(v))
		sum += i
	}
	if sum%9 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  for (int i = 0; i < N; ++i)
    cin >> P[i];
  for (int i = 0; i < N; ++i)
    cin >> Q[i];
  vector<int> A = P;
  sort(A.begin(), A.end());
  int p = 0, q = 0, n = 0;
  do {
    if (A == P)
      p = n;
    if (A == Q)
      q = n;
    ++n;
  } while (next_permutation(A.begin(), A.end()));
  cout << max(p, q) - min(p, q) << endl;
}


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

int main(){

  int N,i=0,tmp=0,ans=0;
  cin >> N;
  vector<int> H(N);
  for(i=0;i<N;i++) cin >> H.at(i);
  for(i = 0 ; i < N-1; i++){
    if(H.at(i) >= H.at(i+1)){
      tmp++;
      if(ans < tmp) ans = tmp;
    }
    else if(H.at(i) < H.at(i+1)) tmp = 0;
  }
   cout << ans ;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

int main()
{
    FAST;

    string s,t;
    cin>>s>>t;

    int cnt = 0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 3808
import itertools
n = int(input())
l = list(itertools.permutations([i for i in range(1, n+1)], n))
for i in range(len(l)):
    l[i] = list(l[i])

p = list(map(int, input().split()))
q = list(map(int, input().split()))

a = l.index(p)
b = l.index(q)
print(abs(a-b))

Measured memory_bytes: 12276
#include <cstdio>
#include <cmath>

typedef struct {
   double x,y;	
} Point;

void koch(int dep,Point p1,Point p2) {
	if (dep == 0) {
		return;
	}
	Point s,u,t;
	double th = M_PI / 3;
	s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
	s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
	t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
	t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
	u.x = (t.x - s.x) *cos(th) - (t.y-s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) *sin(th) + (t.y-s.y) * cos(th) + s.y;
	koch(dep-1,p1,s);
	printf("%.8f %.8f\n",s.x,s.y);
	koch(dep-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y);	
	koch(dep-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y);
	koch(dep-1,t,p2);	
}

int main() {
	int n;
	scanf("%d",&n);
	Point a,b;
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	printf("%.8f %.8f\n",a.x,a.y);
	koch(n,a,b);
	printf("%.8f %.8f\n",b.x,b.y);
	return 0;
} 




Measured memory_bytes: 2736
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

//#include<bits/stdc++.h>


int main() {
	int n, k, x;
	vector<int>z;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> x;
		z.push_back(x);
	}
	int ans = 0;
	int t = n - k;
	ans++;
	if (t > 0) {
		ans += t / (k - 1);
		if (t % (k - 1))ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long X = scan.nextLong();
        // level 0 P
        // level 1 BPPPB
        // level 2 BBPPPBPBPPPBB
        long answer = count_pan(N, X);
        System.out.println(answer);
    }
    private long pan(int N) {
        long pan = 1;
        for (int i = 1; i <= N; i++) {
            pan = pan * 2 + 1;
        }
        return pan;
    }
    private long len(int N) {
        long len = 1;
        for (int i = 1; i <= N; i++) {
            len = len * 2 + 3;
        }
        return len;
    }
    private long count_pan(int N, long K) {
        if (N == 0) {
            return 1;
        }
        if (K == 1) {
            return 0;
        }
        long len = len(N);
        if (K == len) {
            return pan(N);
        }
        if (K == len/2 + 1) {
            return pan(N-1) + 1;
        }
        if (len/2 + 1 < K) {
            return pan(N-1) + count_pan(N-1, K - len/2 - 1) + 1;
        }
        return count_pan(N-1, K - 1);
    }
}


Measured memory_bytes: 23892