akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> d(n);
    int64_t s = 0;
    for (auto&& dd : d) {
        cin >> dd;
        s += dd;
    }

    int64_t ans = 0;
    for (auto dd : d) {
        ans += dd * (s - dd);
    }

    ans /= 2;

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*

object MainKt {
	@JvmStatic
	fun main(args: Array<String>) {
		val scanner = Scanner(System.`in`)
		val s = scanner.next()
		var ans = 0
		var l = 0
		s.toCharArray().forEach {
			if (it=='A' || it=='T' || it=='C' || it=='G') {
				l++
				ans = Math.max(ans, l)
			}else {
				l=0
			}
		}
		println(ans)
	}
}

Measured memory_bytes: 31264
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}
__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

vector<pair<long long, int>> factor(long long x) {
    vector<pair<long long, int>> res;
    for (long long i = 2; i*i <= x; ++i) {
        if (x % i) continue;
        res.emplace_back(i, 0);
        while (x % i == 0) {
            x /= i;
            res.back().second++;
        }
    }
    if (x != 1) res.emplace_back(x, 1);
    return res;
}

int main() {
    ll n;
    cin >> n;
    auto f = factor(2*n);
    int fn = f.size();
    ll k = LLONG_MAX;
    vector<ll> r = {0, -1};
    rep(bit, 1 << fn) {
        vector<ll> m(2, 1);
        rep(i, fn) {
            int idx = bit >> i & 1;
            rep(j, f[i].second) m[idx] *= f[i].first;
        }
        auto p = crt(r, m);
        chmin(k, (p.first == 0 ? p.second : p.first));
    }
    cout << k << '\n';
}

Measured memory_bytes: 3648
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    const n = chunk.toString();
    const r = n.split("\n").filter(x => x != "-1 -1 -1");
    r.forEach(x => sp(x));
});

function sp(tensu){
    const r = tensu.split(" ").map(x=>Number(x));
    const goukei = r[0]+r[1];
    if (goukei <30 || r[0]===-1 || r[1]===-1){
        return console.log("F");
    }else
    if (goukei>=80){
        return console.log("A");
    }
    if(goukei>=65 && goukei<80){
        return console.log("B");
    }
    if(goukei>=50 && goukei<65 || goukei>=30 && r[2]>=50){
        return console.log("C");
    }
    if(goukei>=30 && goukei<50){
        return console.log("D");
    }
}


Measured memory_bytes: 16012
#include <iostream>
#include <cmath>
using namespace std;
using LL = long long;
int main(){
	//freopen("test", "r", stdin);
	ios::sync_with_stdio(false);
	LL T1, T2;
	cin >> T1 >> T2;
	LL A1, A2, B1, B2;
	cin >> A1 >> A2 >> B1 >> B2;
	if(A1 - B1 > 0) swap(A1, B1), swap(A2, B2);
	LL dif1 = T1 * (A1 - B1), dif2 = T2 * (A2 - B2);
	if(dif1 + dif2 < 0){
		cout << "0";	
	}else if(dif1 + dif2 == 0){
		cout << "infinity";
	}else{
		if(2 * dif1 + dif2 > 0){
			cout << "1";
		}else if(2 * dif1 + dif2 == 0){
			cout << "2";	
		}else{
			LL tmp = 2 * dif1 + dif2 - dif1;
			LL tot = -dif1 / tmp;
			cout << tot * 2 + ((dif1 % tmp == 0)? 0: 1);
		}
	}
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll c[3][3]; rep(i, 3){rep(j, 3){cin >> c[i][j];}}
    // aにxを加算してbからxを減産してもok -> a1=0を仮定して話をすすめる
    ll a[3], b[3]; a[0] = 0;
    rep(j, 3){b[j] = c[0][j];}

    bool flag = true;
    rep2(i, 1, 3){
        ll tmp = c[i][0] - b[0];
        if (tmp != (c[i][1] - b[1])){flag = false; break;}
        if (tmp != (c[i][2] - b[2])){flag = false; break;}
    }
    string ans = flag ? "Yes" : "No";
    cout << ans << endl;
}

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


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

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out, true);
    StringTokenizer st = new StringTokenizer(in.readLine());
    int N = Integer.parseInt(st.nextToken());
    int M = Integer.parseInt(st.nextToken());
    String S = in.readLine().trim();
    ArrayDeque<Pair<Integer, Integer>> q = new ArrayDeque<>();
    q.add(new Pair(N, 0));
    ArrayList<Integer> bp = new ArrayList<>(Collections.nCopies(N + 1, -1));
    for (int i = N - 1; i >= 0; --i) {
      while (!q.isEmpty() && q.peekLast().x - i > M) q.removeLast();
      if (q.isEmpty() || S.charAt(i) == '1') continue;
      Pair<Integer, Integer> p = new Pair<>(i, q.peekLast().y + 1);
      bp.set(i, q.peekLast().x);
      while (!q.isEmpty() && q.peekFirst().y >= p.y) q.removeFirst();
      q.addFirst(p);
    }
    if (bp.get(0) == -1) {
      out.println(-1);
      return;
    }
    int i = 0;
    while (bp.get(i) != -1) {
      out.print(bp.get(i) - i);
      out.print(" ");
      i = bp.get(i);
    }
    out.println();
  }

  static class Pair<X, Y> {
    X x;
    Y y;

    Pair(X x, Y y) {
      this.x = x;
      this.y = y;
    }
  }
}


Measured memory_bytes: 30756
### constant

SEGS = [
  0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110,
  0b1101101, 0b1111101, 0b0100111, 0b1111111, 0b1101111,
]

### main

while true
  n = gets.strip.to_i
  break if n < 0

  disp = 0

  n.times do
    d = gets.strip.to_i

    cmd = disp ^ SEGS[d]
    printf("%07b\n", cmd)

    disp = SEGS[d]
  end
end

Measured memory_bytes: 6112
package main

import (
	"fmt"
)

func main(){
	var A,B,C,K int
	count := 0
	fmt.Scan(&A,&B,&C,&K)
	if A<K{
		count+=A
		K-=A
	}else{
		fmt.Println(K)
		return
	}
	if B<K{
		K-=B
		count-=K
		fmt.Println(count)
		return
	}else{
		fmt.Println(count)
		return
	}

}

Measured memory_bytes: 1756
n = int(input())
s = input()
ans = ''
alf = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range(0, len(s)):
    for j in range(0, 26):
        if s[i] == alf[j]:
            if j+n > 25:
                ans += alf[j+n-26]
            else:
                ans += alf[j+n]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, R, L;
int score[1000000];
int ttime[1000000];

int main(){
  int now = 0;
  scanf("%d%d%d", &N, &R, &L);

  priority_queue<pair<int, int> >q;
  q.push(MP(0, -1));
  rep(i, R){
    int d, t, x;
    scanf("%d%d%d", &d, &t, &x);
    pair<int, int>p = q.top(); q.pop();
    while(p.F != score[-p.S]){
      q.push(MP(score[-p.S], p.S));
      p = q.top(); q.pop();
    }
    q.push(MP(score[-p.S], p.S));
    //    printf("%d %d\n", (int)q.size(), p.S);
    ttime[-(p.S)] += t - now;
    //    printf("%d %d\n", ttime[-(p.S)], -(p.S));
    //    rep(j, N) printf("%d ", ttime[j]); puts("");
    now = t;
    score[d] += x;
    q.push(MP(score[d], -d));
  }
  pair<int, int>p = q.top(); q.pop();
  while(p.F != score[-p.S]){
    q.push(MP(score[-p.S], p.S));
    p = q.top(); q.pop();
  }
  q.push(MP(score[-p.S], p.S));

  ttime[-(p.S)] += L - now;
  //  REP(i, 1, N+1) printf("%d ", score[i]); puts("");
  //  REP(i, 1, N+1) printf("%d ", ttime[i]); puts("");

  int res = 0;
  REP(i,1, N+1) if(ttime[res] < ttime[i]) res = i;
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 13820
#include <iostream>
#include <algorithm>
#include <cstdio>
const int maxn = 1010,
	X[] = { 1, 0, -1, 0 }, Y[] = { 0, 1, 0, -1 };

int n, x[maxn], y[maxn], w[maxn], idx;
void solve(long long x, long long y) {
	for (int i = 1; i <= idx; ++i) {
		char c;
		if (abs(x) > abs(y))
			if (x < 0) x += w[i], c = 'L';
			else x -= w[i], c = 'R';
		else
			if (y < 0) y += w[i], c = 'D';
			else y -= w[i], c = 'U';
		std::cout << c;
	}
	std::cout.put('\n');
}

int main() {
	std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) {
		std::cin >> x[i] >> y[i];
		if ((x[i] + y[i] & 1) != (x[1] + y[1] & 1)) {
			std::cout << "-1\n";
			return 0;
		}
	}
	for (int i = 30; ~i; --i) w[++idx] = 1 << i;
	if (!(x[1] + y[1] & 1)) w[++idx] = 1;
	std::cout << idx << '\n';
	for (int i = 1; i < idx; ++i) std::cout << w[i] << ' ';
	std::cout << w[idx] << '\n';
	for (int i = 1; i <= n; ++i) solve(x[i], y[i]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
inline void insertionSort(vi a, int n) {
	int v, j;
	rep(i, 0, n) {
		v = a[i];
		j = i - 1;
		while(j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			--j;
		}
		a[j + 1] = v;
		rep(k, 0, n) cout << a[k] << (k != n - 1 ? " " : "\n");
	}
}
int main() {
	int n; cin >> n;
	vi v(n); rep(i, 0, n) cin >> v[i];
	insertionSort(v, n);
	return 0;
}

Measured memory_bytes: 3128
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using intpv=vector<intpair>;
using llpair=pair<ll,ll>;
using llpv=vector<llpair>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;
using pairmat=vector<llpv>;
#define matrix(T) vector<vector<T>>
#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define pqueue priority_queue
#define pushb push_back
#define fi first
#define se second
#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())
#define init(v,size) v.resize(size); for(auto &a__: v) cin>>a__
#define matin(mat,H,W) for(int i__=0; i__<H; i__++)for(int j__=0; j__<W; j__++) cin>>mat[i__][j__]
#define out(n) cout<<n<<endl

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

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

template<class T> inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

ll GCD(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}

ll Fact(ll x, ll p) { //階乗
	ll f=1;
	for(ll i=2; i<=x; i++) {
		f*=i;
		f%=p;
	}
	return f;
}

ll nPr(ll n, ll r) {
	if(n<r) return 0;

	ll result=1LL;
	for(ll i=0; i<r; i++) result*=n-i;
	return result;
}

ll nPrP(ll n, ll r, ll p) { // mod pにおけるnPr
	if(n<r) return 0;

	ll result=1LL;
	for(int i=0; i<r; i++) {
		result*=n-i;
		result%=p;
	}
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll div=1LL;
	while(n/div) {
		digit++;
		div*=10;
	}
	return digit;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}


ll N;
ll res=0;

void input() {
	cin>>N;
}

void solve() {
	for(ll i=1; i*i<=N; i++) {
		if(N%i) continue;
		ll m=N/i-1;
		if(m>i) {
			res+=m;
		}
	}
	cout<<res<<endl;
}

int main() {
	while(1) {
		input();
		solve();
		break;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  char c;
  cin >> c;
  cout << (char)(c + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
S = str(N)
l = len(S)
if l == 1:
    print(N)
    exit()
s = int(S[0])
t = int(S[-1])
mn = min(s,t)

ans = 0
dp = defaultdict(int)
            
for i in range(1,10):
    for j in range(1,10):
        if i == j:
            dp[(i,j)] += 1
        if l >= 3: 
            for k in range(0,l-2):
                dp[(i,j)] += 10**k
        # equal digit
        if i < s:
            dp[(i,j)] += 10**(l-2)
        elif i == s and j <= t:
            dp[(i,j)] += 1+((N-s*(10**(l-1))) // 10)
        elif i == s and j > t:
            dp[(i,j)] += (N-s*(10**(l-1))) // 10
#print(dp)
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += dp[(i,j)]*dp[(j,i)]
print(ans)

'''
real = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        S = str(i)
        T = str(j)
        if S[0] == T[-1] and S[-1] == T[0]:
            real += 1
print(real)
'''


Measured memory_bytes: 38256
#pragma region Macros
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn,now,ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos and *pos <= '9') n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos and *pos <= '9') a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos and *pos <= '9') pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos and *pos <= '9') b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7904
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  string S;
  cin >> S;
  bool ans =true;
  int Sl =S.size();
  int Ccount=0;

  if (S[0] != 'A') ans=false;
  for(int i=2; i<Sl-1; ++i){
    if (S[i] == 'C') ++Ccount;
    else if(S[i] >='A' && S[i] <='Z') ans =false;
  }
  if(S[1]>='A' &&S[1]<='Z') ans =false;
  if(S[Sl-1]>='A' &&S[Sl-1]<='Z') ans =false;

  if(ans && Ccount == 1) cout << "AC" <<endl;
  else cout << "WA" <<endl;

  return 0;
}


Measured memory_bytes: 256
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n = ri()
v=rl()
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
for i in range(1,n,2):
    b.append(v[i])

import collections
ca = collections.Counter(a)
ca = ca.most_common()
cb = collections.Counter(b)
cb = cb.most_common()
la = len(a)
lb = len(b)

if ca[0][0] != cb[0][0]:
    ans = (la - ca[0][1]) + (lb - cb[0][1])
else:
    ans = []
    if len(ca) >= 2:
        ans.append(la-ca[1][1] + lb-cb[0][1])
    if len(cb) >= 2:
        ans.append(la-ca[0][1] + lb-cb[1][1])
    if len(ca)==1 and len(cb)==1:
        ans.append(ca[0][1])
        ans.append(cb[0][1])
    ans = min(ans)

print(ans)

Measured memory_bytes: 21084
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;

const int N = (int)1e5 + 4;
bool sieve[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 2; i < N; ++i) {
        if (sieve[i]) continue;
        for (int u = 2*i; u < N; u += i) sieve[u] = true;
    }
    for (int j = n; j < N; ++j) {
        if (!sieve[j]) {
            cout << j << '\n';
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 384
# frozen_string_literal: true

s = gets.chomp.chars
q = gets.to_i
qs = q.times.map { gets.chomp.chars }
flag_r = false

qs.each do |qq|
  if qq[0] == '1'
    flag_r = !flag_r
  else
    if flag_r
      if qq[2] == '1'
        s.push(qq[4])
      else
        s.unshift(qq[4])
      end
    else
      if qq[2] == '1'
        s.unshift(qq[4])
      else
        s.push(qq[4])
      end
    end
  end
end

s.reverse!() if flag_r

puts s.join


Measured memory_bytes: 79868
process.stdin.resume();
process.stdin.setEncoding('utf8');
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
 var Sn = lines[0].split(' ');
 var N = parseInt(Sn[0]);
 var K = parseInt(Sn[1]);
 var num = parseInt(N + 1) / 2; 
 if (num >= K){
console.log("YES");
} else {
console.log("NO");
}
});

Measured memory_bytes: 7500
#include<stdio.h>

int main(void){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(W < (x+r) || H < (y+r) || x <= 0 || y <= 0 || x == 100 || y == 100){
		printf("No\n");
	}else{
		printf("Yes\n");
	}	
					
	return 0;
}

Measured memory_bytes: 1012
fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map { it.toInt() }

    val ac = BooleanArray(N)

    var pen = IntArray(N)

    for (i in 0 until M) {
        val (p, S) = readInputLine().split(" ")
        val pNum = p.toInt() - 1

        if (ac[pNum]) {
            continue
        }

        if (S == "AC") {
            ac[pNum] = true
        } else {
            pen[pNum]++
        }
    }

    var acSum = 0
    var penSum = 0

    for (i in 0 until N) {
        if (ac[i]) {
            acSum++
            penSum += pen[i]
        }
    }

    println("$acSum $penSum")
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 54628
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int DN=105,DK=1e5+5,M=1e9+7;
int n,k,a[DN],dp[DN][DK],sum;

int main() {
    cin >> n >> k;
    for(li i = 1; i <= n; i ++) cin >> a[i];
    dp[0][0] = 1;
    for(li i = 1; i <= n; i ++) {
        sum = 0;
        a[i]++;
        for(li j = 0; j <= k; j ++) {
            sum = (sum + dp[i-1][j]) % M;
            if(a[i]<=j) {
                sum = (sum + M - dp[i-1][j-a[i]]) % M;
            }
            dp[i][j] = sum;
        }
    }
    cout << dp[n][k];
}


Measured memory_bytes: 40832
def keisan(x):
  ret_val=0
  while x>0:
    ret_val+=x%10
    x//=10
  return ret_val

N,A,B=map(int,input().split())
ans=0
for i in range(1,N+1):
  temp=keisan(i)
  if A<=temp<=B:
    ans+=i
print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001
#define PI 3.141592653589793

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int K;
    cin >> K;
    rep(i,K){
        if(i == K-1) cout << "ACL" << endl;
        else cout << "ACL";
    }      
}

Measured memory_bytes: 3636
n = gets.to_i
sp = []
n.times{|i| sp << [i+1] + gets.chomp.split}

sp.sort! do |a,b|
    k = a[1] <=> b[1]
    k == 0 ? -a[2].to_i <=> -b[2].to_i : k
end

puts sp.map{|e| e[0]}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  for(int x, y; cin >> x >> y && (x && y);) {
    unordered_map<int, int> mp;
    int cnt = 0;
    while(mp.find(x % y) == mp.end()) {
      if(x % y == 0) {
        cout << cnt << " 0" << endl;
        goto exit;
      }
      mp[x % y] = cnt ++;
      x %= y;
      x *= 10;
    }
    cout << mp[x % y] << " " << cnt - mp[x % y] << endl;
    exit:;
  }
  
  return 0;
}

Measured memory_bytes: 42276
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chkmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chkmax(T &a, T b) { return a < b ? (a = b, true) : false; }

typedef long long ll;

const int INF = 1001001001;
const int MAX_N = 100000 + 10;
int dp[MAX_N][2];

int main2() {
  int N; cin >> N;
  vector<int> A(N); REP(i, N) cin >> A[i];
  REP(i, N+1) REP(j, 2) dp[i][j] = INF;
  dp[0][0] = 1;
  dp[0][1] = 1;
  for (int i = 1; i < N; i++) {
    int cur;
    if ((cur=dp[i-1][0]) >= 0) {
      if (A[i-1] <= A[i]) chkmin(dp[i][0], cur);
      chkmin(dp[i][1], cur + 1);
      chkmin(dp[i][0], cur + 1);
    }
    if ((cur=dp[i-1][1]) >= 0) {
      if (A[i-1] >= A[i]) chkmin(dp[i][1], cur);
      chkmin(dp[i][1], cur + 1);
      chkmin(dp[i][0], cur + 1);
    }
  }
  int ans = min(dp[N-1][0], dp[N-1][1]);
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}

Measured memory_bytes: 1408
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n; 
    vector <int> res;
    while (true){
        int l=1,r=n,in;
        while (l<=r){
            int m=(l+r)>>1;
            if ((m*(m+1))/2>=n){
                in=m; r=m-1;
            }
            else l=m+1;
        }
        n -= in;
        res.pb(in);
        if (n==0) break;
    }
    for (auto &it: res) cout << it << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3668
def solve():
    S = input().split('/')
    S = [int(i) for i in S]
    if(S[0]<2019):
        return (print('Heisei'))
    elif(S[0]>2019):
        return (print('TBD'))
    elif(S[0]==2019 and S[1]>=5):
        return (print('TBD'))
    else:
        return (print('Heisei'))
solve()

Measured memory_bytes: 3060
txt = ""
num = (int)(input())
message = [[0 for i in range(26)] for j in range(num)]

for i in range(num):
  text = input()
  for j in text:
    #print(ord(j))
    message[i][ord(j) - 97] += 1
#print(message[0])
r_message = [[0 for i in range(num)] for j in range(26)]
for i in range(26):
  for j in range(num):
    r_message[i][j] = message[j][i]
#print(r_message)
for j in range(26):  
  for k in range(min(r_message[j])):
  	txt += chr(j + 97)
print(txt)

Measured memory_bytes: 3064
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn digit(n: u64, k: u64) -> u64 {
    if n == 0 {
        return 1;
    }
    let mut i = 1;
    loop {
        if n < k.pow(i) {
            return i as u64;
        }
        i += 1;
    }
}

fn main() {
    let (n, k) = input_tuple();
    println!("{}", digit(n, k));
}


Measured memory_bytes: 2120
// Contest.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

using namespace std;

int main()
{
	int A, B;
	string s;
	cin >> A >> B >> s;
	if (s[A] == '-') {
		s.erase(s.begin()+A);
		for (int i = 0; i < A + B; i++) {
			if (!isdigit(s[i])) {
				puts("No"); return 0;
			}
		}
	}
	else {
		puts("No"); return 0;
	}
	puts("Yes");
	return 0;
}



Measured memory_bytes: 256
# -*- coding:utf-8 -*-
import math

def solve():
    N = int(input())
    vehicles = []
    for i in range(0, 5):
        vehicles.append(int(input()))
    
    botle_neck = vehicles[0]
    for i in range(1, 5):
        if vehicles[i] < botle_neck:
            botle_neck = vehicles[i]
            continue
        else:
            vehicles[i] = botle_neck
    
    # 結局vehicles[4] + 4分？
    ans = math.ceil(N/vehicles[4]) + 4

    print(ans)



if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
N,K = map(int,input().split())
D = list(map(str,input().split()))

ans = 0

for j in range(N,10*N+1):
  f = True
  for k in D:
    if str(k) in str(j):
      f = False
      break
  if f:
    ans = j
    break
    
print(ans)
    

Measured memory_bytes: 2940
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = Number(list[0]);
const A = list[1].trim().split(' ');
const q = Number(list[2]);
const mi = list[3].trim().split(' ');

class KeyMap {
  constructor() {
    this.map = {};
  }
  get(...args) {
    let map = this.map;
    args.forEach(arg => {
      map[arg] = map[arg] || {};
      map = map[arg];
    });
    return map;
  }
}

const dp = new Map();
const keyMap = new KeyMap();
const memo = (i, m) => {
  if (dp.has(keyMap.get(i, m))) {
    return dp.get(keyMap.get(i, m));
  }
  if (i === n || m === 0) {
    return m === 0;
  }

  const nI = i + 1;
  const nM = m - A[i];
  dp.set(keyMap.get(nI, m), memo(nI, m));
  dp.set(keyMap.get(nI, nM), memo(nI, nM));
  return dp.get(keyMap.get(nI, m)) || dp.get(keyMap.get(nI, nM));
}
for (let i = 0; i < q; i++) {
  console.log(memo(0, Number(mi[i])) ? 'yes' : 'no');
}



Measured memory_bytes: 31648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    int a;cin>>a;int a1=a;
    int max=0;int ran=0;
    for(int i=1;i<n;++i)
    {
        cin>>a;
        if(a<=a1){a1=a;ran++;if(ran>max){max=ran;}}
        else{ran=0;a1=a;}
    }
    cout<<max;
}

Measured memory_bytes: 256
// Problem : C - H and V
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_c
// Memory Limit : 1024 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int h,w,k;
		cin>>h>>w>>k;
		char arr[h][w];
		for(int i=0;i<h;++i)
		{
			for(int j=0;j<w;++j)
			{
				cin>>arr[i][j];
			}
		}
		vector<int> row,col;
		for(int i=0;i<(1<<h);++i)
		{
			row.pb(i);
		}
		for(int i=0;i<(1<<w);++i)
		{
			col.pb(i);
		}
		int ans = 0;
		for(int i=0;i<(int)row.size();++i)
		{
			for(int j=0;j<(int)col.size();++j)
			{
				int cnt = 0;
				for(int kk=0;kk<h;++kk)
				{
					if((1<<kk)&(row[i]))
					continue;
					for(int l=0;l<w;++l)
					{
						if((1<<l)&(col[j]))
						continue;
						if(arr[kk][l]=='#')
						++cnt;
					}
				}
				if(cnt==k)
				++ans;
			}
		}
		cout<<ans<<"\n";		
    }
    return 0;
}


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

ll f(ll x){
	return x*x*x;
}

int main(){
	//ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int n,k;cin>>n>>k;
	ll ans = 0;
	ans += f(n/k);
	if(k%2==0) ans += f(n/(k/2) - n/k);
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define N 10005
#define MOD 1000000007
#define N_max 100005


		
int main(){

	ll n,W;
	scanf("%lld%lld",&n,&W);
	ll v[N],w[N],dp[N_max];
	for(int i =0 ; i < n; i++){
		scanf("%lld%lld",&w[i],&v[i]);
	}
	for(int i =0;i<N_max;i++){
		dp[i]=1e18;
	}
	dp[0]=0;

	for(int i =0;i<n;i++){
		for(int j=100000-v[i];j>=0;j--){
			dp[j+v[i]] = min(dp[j+v[i]],dp[j]+w[i]);
		}
	}

	for(int i=100000;i>=0;i--){
		if(dp[i]<=W){
			printf("%d\n",i );
			break;
		}
	}


    return 0;
}

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

//C Together
int main() {
	vector <long long int> ans(1000000,0);
	int N, x;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x;
		if (x != 0) {
			ans[x - 1]++;
			ans[x]++;
			ans[x + 1]++;
		}
		else ans[999999]++;
	}
	sort(ans.begin(),ans.end());
	cout << ans[ans.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
struct jf{
  int x;
  int y;
};

bool cmp(const jf &q, const jf &w)
{
    return q.x < w.x;
}

int main(){
  long long int n,k;
  cin>>n>>k;
  jf a[n];
  for(long long int i=0;i<n;++i){
    cin>>a[i].x>>a[i].y;
  }
  sort(a,a+n,cmp);
  long long int count=k;
  for(long long int i=0;i<n;++i){
    if(count<=a[i].y){
      cout<<a[i].x;
      return 0;
    }
    else{
      count -= a[i].y;
    }
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 9;
inline int read()
{
    int data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    return f * data;
}

int v[109], p[1009];
ull dp[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("data.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    int n = read(), w = read();
    for (int i = 1; i <= n; ++i)
        p[i] = read(), v[i] = read();
    for (ull i = 1; i < maxn; ++i)
        dp[i] = INF;
    for (int i = 1; i <= n; ++i)
        for (int j = maxn - 1; j >= v[i]; --j)
            dp[j] = min(dp[j], dp[j - v[i]] + p[i]);
    for (int i = maxn - 1; i >= 0; --i)
        if (dp[i] <= w)
        {
            cout << i << '\n';
            break;
        }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

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

def main():
    n = int(input())

    if (n / 4 >= 1 and n % 4 in [0, 3]) or n / 7 >= 1 and n % 7 in [0, 1, 5]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;

void main(){
	auto N = readln.chomp.to!int;
	auto S = readln.chomp.to!(char[]);
	auto K = readln.chomp.to!int;

	char C = S[K-1];

	foreach(i; 0..N){
		if(S[i] != C){
			S[i] = '*';
		}
	}

	writeln(S);
}

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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  for(int i=0;i<d-b;i++){
    cout<<'U';
  }
  for(int i=0;i<c-a;i++){
    cout<<'R';
  }
  for(int i=0;i<d-b;i++){
    cout<<'D';
  }
  for(int i=0;i<c-a;i++){
    cout<<'L';
  }
  cout<<'L';
  for(int i=0;i<d-b+1;i++){
    cout<<'U';
  }
  for(int i=0;i<c-a+1;i++){
    cout<<'R';
  }
  cout<<'D'<<'R';
  for(int i=0;i<d-b+1;i++){
    cout<<'D';
  }
  for(int i=0;i<c-a+1;i++){
    cout<<'L';
  }
  cout<<'U'<<endl;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)


int main(void)
{
	string s,t;
	cin >> s;
	cin >> t;
	int ns = s.size();
	int nt = t.size();
	vector<char> cs(s.begin(),s.end());
	for (int i = ns - nt; i >= 0; i--) {
		bool match = true;
		for (int j = 0; j < nt; j++) {
			if (s[i+j] != t[j] && s[i+j] != '?') {
				match = false;
				break;
			}
		}

		if (match) {
			for (int j = 0; j < nt; j++) {
				cs[i + j] = t[j];
			}
			for (int j = 0; j < ns; j++) {
				if (cs[j] == '?') cs[j] = 'a';
			}
			rep(j, ns) {
				cout << cs[j];
			}
			cout << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    S = list(in_s())[::-1]
    N = len(S)

    gr = itertools.groupby(S)

    count = 0
    tnum = 0
    for k, v in gr:
        num = sum(1 for _ in v)
        if k == 'S':
            count += min(tnum, num)
            tnum -= min(tnum, num)
        else:
            tnum += num

    # print(count)

    ans = N - count * 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12012
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n;
  ll ans=INF;
  cin >> n;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      ll a=i;
      ll b=n/i;
      chmin(ans,a-1+b-1);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()



int main() {
	string S, T;
	cin >> S;
	cin >> T;
	string ans = S;
	bool can = false;
	for (int i = S.length(); i >= T.length(); --i) {
		bool tmp = true;
		string answer = S;
		for (int j = T.length()-1; j >= 0; j--) {
			//cout << S[i - T.length()+1 + j]<<" "<< T[j]<<endl;
			if (S[i-T.length()+j] != T[j] && S[i - T.length()+ j] != '?') {
				tmp = false;
			}
		}
		if (tmp) {
			for (int j = T.length()-1; j >= 0; j--) {
				answer[i - T.length() + j] = T[j];
			}
			rep(k, S.length()) {
				if (answer[k] == '?') {
					answer[k] = 'a';
				}
			}
			if (!can) {
				ans = answer;
				//cout << ans << endl;
			}
			if (can && answer < ans) {
				ans = answer;
				//cout << ans << endl;
			}
			can = true;
			
		}
		else {
			if (S[i]=='?') S[i]= 'a';
		}
		//cout << i << " "<<T.length()-1 << endl;
		
	}
	if (can) {
		rep(i, S.length()) {
		
			cout << ans[i];
		}
		cout << endl;
	}
	else {
		cout << "UNRESTORABLE" << endl;
	}
}


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


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

	void run() {
		solver();
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		while (true) {
			int W =Integer.parseInt(sc.next());
			int n = Integer.parseInt(sc.next());
			if (W == 0 && n == 0)
				break;
			long[] accum = new long[n + 1];
			int[] x = new int[n];
			for (int i = 0; i < n; ++i) {
				x[i] = Integer.parseInt(sc.next());
			}
			for (int i = 0; i < n; ++i) {
				accum[i + 1] = accum[i] + x[i];
			}
			int lack = 0;
			int gap = 1;
			outer: for (int i = 15; i >= -1; --i) {
				int ngap = gap + (i >= 0 ? (1 << i) : 0);
				int[] vis = new int[n + 1];
				vis[0] = 1;
				vis[1] = -1;
				for (int j = 0; j < n; ++j) {
					vis[j] += (j > 0 ? vis[j - 1] : 0);
					if (vis[j] > 0) {
						if (accum[n] - accum[j] + (n - j - 1) <= W) {
							continue outer;
						}
						int left = j;
						int right = n;
						while (right - left > 1) {
							int middle = (right + left) / 2;
							if (accum[middle] - accum[j] + (middle - j - 1) <= W) {
								left = middle;
							} else {
								right = middle;
							}
						}
						int dmax = left;

						left = j;
						right = n;
						while (right - left > 1) {
							int middle = (right + left) / 2;
							if (W <= accum[middle] - accum[j] + (long) ngap * (middle - j - 1)) {
								right = middle;
							} else {
								left = middle;
							}
						}
						int dmin = right;
						
						if (dmin > dmax)
							continue;
						++vis[dmin];
						--vis[dmax + 1];
					}
				}
				++lack;
				gap = ngap;
			}
			if (lack > 0)
				++gap;
			pw.println(gap);
		}
		pw.close();
		sc.close();
	}

	
	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 72096
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first 
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=1e9 + 7;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n<0)return 0;if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(),x.end()
#define Return(x) {cout << x << endl; return 0;}


int__ main() {
    int k; cin >> k;

    priority_queue<int,vi,greater<int> > q;

    for(int i=1;i<=9;i++) q.push(i);

    while(true) {
        int x = q.top(); q.pop(); k--;
        if(k == 0) {
            cout << x << endl; break;
        }

        q.push(10*x + x%10);
        if(x % 10 != 0) q.push(10*x + x%10 - 1);
        if(x % 10 != 9) q.push(10*x + x%10 + 1);
    }
}

Measured memory_bytes: 2420
N,K = map(int,input().split())
*AB, = [list(map(int,input().split())) for _ in [0]*N]
bK = bin(K)[2:]
l = len(bK)
def f(x): return sum(b for a,b in AB if a | x == x )

x = ""
ans = f(K)
for k in bK:
    if k=="1":
        n = int((x + "0" + "1"*l)[:l],2)
        ans = max(ans,f(n))
        x+="1"
    else:
        x += "0"

print(ans)

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

int main(){
    int n;cin>>n;
    ll ans=0;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    for(int i=0;i<n;i++){
        auto iter=lower_bound(a.begin(),a.end(),b[i]);
        ll index1=iter-a.begin();
        auto it=upper_bound(c.begin(),c.end(),b[i]);
        ll index2=it-c.begin();
        ans+=index1*(n-index2);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
import bisect
import itertools

n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
q = int(input())
M = list(map(int, input().split()))

for m in M:
    if m in A:
        print("yes")
    elif sum(A) < m:
        print("no")
    else:
        # mよりも小さいAの要素のみを対象
        index = bisect.bisect_left(A, m)
        tgtA = A[:index]
        
        num = len(tgtA)
        judge = False
        while num > 0:
            combList = list(itertools.combinations(A, num))
            for comb in combList:
                if m == sum(comb):
                    judge = True
                    break

            if judge:
                break

            num -= 1

        if judge:
            print("yes")
        else:
            print("no")



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

int main()
{
    int n;cin>>n;
    vector<long long> t(n);
    vector<long long> a(n);
    int i;
    for(i=0;i<n;i++)cin>>t.at(i)>>a.at(i);
    long long ans=0;
    long long ka=0;
    long long kt=0;
    for(i=0;i<n;i++)
    {
        if(i==0)
        {
            ka=a.at(i);
            kt=t.at(i);
        }
        else
        {
            long long ha=(ka+a.at(i)-1)/a.at(i);
            long long ht=(kt+t.at(i)-1)/t.at(i);
            long long hm=max(ha,ht);
            ka=a.at(i)*hm;
            kt=t.at(i)*hm;
        }
    }
    ans=ka+kt;
    cout<<ans<<endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
struct Tree {
    int u, v, w;
    Tree(int a, int b, int c) {
        u = a;
        v = b;
        w = c;
    }
    bool operator<(const Tree &another) const {
        return u < another.u;
    };
};
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    queue<Tree> L, LL;
    int u, v, w;
    for (int i = 1; i<N; i++) {
        cin >> u >> v >> w;
        L.push(Tree(u, v, w%2));
    }
    vector<int> Ans(N+1, -1);
    Tree tmp = L.front();
    L.pop();
    Ans[tmp.u] = 0;
    Ans[tmp.v] = tmp.w;
    while (!L.empty()) {
        swap(L, LL);
        while (!LL.empty()) {
            tmp = LL.front();
            LL.pop();
            if (Ans[tmp.u] != -1) {
                Ans[tmp.v] = Ans[tmp.u]^tmp.w;
            } else if (Ans[tmp.v] != -1) {
                Ans[tmp.u] = Ans[tmp.v]^tmp.w;
            } else {
                L.push(tmp);
            }
        }
    }
    for (int i = 1; i<=N; i++) {
        printf("%d\n", Ans[i]);
    }
    return 0;
}

Measured memory_bytes: 2176
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j;
  int n;
  while(cin>>n&&n){
    int a[301];
    memset(a,0,sizeof(a));
    a[0]=1;
    int b[301];
    for(h=1;h*h<=n;h++){
      memset(b,0,sizeof(b));
      for(i=0;i<n+1;i++){
	if(a[i]){
	  for(j=0;i+j*h*h<=n;j++)
	    b[i+j*h*h]+=a[i];
	}
      }
      for(i=0;i<n+1;i++)
	a[i]=b[i];
    }
    cout<<a[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
a, b, c = map(int, input().split())
cnt = 0
while True:
  if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
    break
  if a == b == c:
    cnt = -1
    break
  k, l, m = a//2, b//2, c//2
  a = l + m
  b = k + m
  c = k + l
  cnt += 1
print(cnt)
  

Measured memory_bytes: 3060