akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define inf (int)1e9
using namespace std;

struct data {
  int p, d, c;
};
bool operator<(const data &l, const data &r) {
  if(l.c != r.c) return l.c > r.c;
  if(l.d != r.d) return l.d > r.d;
  return l.p > r.p;
}

int n, m, l;
int dp[105][105] = {0};
vector<data> edges[105];
priority_queue<data> pq;

int solve();

int main() {
  while(1) {
    cin >> n >> m >> l;
    if(n + m + l == 0) break;
    for(int i = 0; i < m; ++i) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      edges[--a].push_back({--b, d, e});
      edges[b].push_back({a, d, e});
    }
    cout << solve() << endl;
    for(int i = 0; i < n; ++i)
      edges[i].erase(edges[i].begin(), edges[i].end());
  }
  return 0;
}

int solve() {
  for(int i = 0; i < n; ++i)
    for(int k = 0; k <= l; ++k) dp[i][k] = inf;
  pq.push({0, 0, 0});
  while(pq.size() > 0) {
    data now = pq.top();
    pq.pop();
    if(dp[now.p][now.d] <= now.c) continue;
    dp[now.p][now.d] = now.c;
    for(int i = 0; i < edges[now.p].size(); ++i) {
      data nextp = now;
      nextp.p = edges[now.p][i].p;
      if(edges[now.p][i].c != 0)
        nextp.d += edges[now.p][i].d;
      if(nextp.d <= l) pq.push(nextp);
      nextp.d = now.d;
      nextp.c += edges[now.p][i].c;
      pq.push(nextp);
    }
  }
  int ans = inf;
  for(int i = 0; i <= l; ++i) ans = min(ans, dp[n - 1][i]);
  return ans;
}


Measured memory_bytes: 9124
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		sort(ALL(A));
		double v=(A[0]+A[1])/2.0;
		RANGE(i, 2, N) {
			v = (v+A[i])/2.0;
		}
		cout<<setprecision(20)<<v<<endl;
	}
	
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 400;
const ll INF = 2e15;

int n;
ll arr[MAXN+10];
ll dp[MAXN+10][MAXN+10];

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int i, j, k;

    scanf("%d", &n);
    for(i=1; i<=n; i++) scanf("%lld", &arr[i]), arr[i]+=arr[i-1];

    for(j=1; j<=n; j++)
    {
        dp[j][j]=0;
        for(i=j-1; i>=1; i--)
        {
            dp[i][j]=INF;
            for(k=i; k<j; k++) dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]);
            dp[i][j]+=arr[j]-arr[i-1];
        }
    }
    printf("%lld", dp[1][n]);
    return 0;
}


Measured memory_bytes: 1536
mod = 10**9 + 7

def init(n):
    # 階乗とその逆元をグローバルに定義
    global factorial, inverse
    # 0-indexedでそれぞれ１で初期化
    factorial = [1]*(n+1)
    inverse = [1]*(n+1)

    fact = 1
    for p in range(1,n+1):
        fact *= p
        fact %= mod
        factorial[p] = fact

    inv = pow(fact, mod-2, mod)
    inverse[n] = inv
    for p in range(2,n+1)[::-1]:
        inv *= p
        inv %= mod
        inverse[p-1] = inv

def comb(n,r):
    if n < r:
        return 0
    return factorial[n] * inverse[n-r] * inverse[r] % mod

X, Y = map(int,input().split())

n = (2*Y - X) / 3
m = (2*X - Y) / 3
if not(int(n) == n and n >= 0 and int(m) == m and m >= 0):
    print(0)
    exit()

n = int(n)
m = int(m)

init(10**6)

ans = comb(n+m, n)
print(ans)

Measured memory_bytes: 82164
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <utility>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>

using namespace std;

pair<int64_t, int64_t> nearest_two(
	const vector<int64_t>& ps, const int64_t pos
)
{
	size_t i = 0;
	size_t j = ps.size() - 1;
	size_t pivot = (i + j) / 2;

	while (true) {
		if (i == j || i == j - 1) {
			return make_pair(ps[i], ps[j]);
		}
		if (ps[pivot] == pos) {
			return make_pair(ps[pivot], ps[pivot]);
		}

		if (ps[pivot] < pos) {
			i = pivot;
			pivot = (i + j) / 2;
		}
		else {
			j = pivot;
			pivot = (i + j) / 2;
		}
	}

	return make_pair(0, 0);
}

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

	vector<int64_t> shrines(a);
	vector<int64_t> temples(b);
	vector<int64_t> qs(q);

	for (auto& shrine : shrines) {
		cin >> shrine;
	}
	for (auto& temple : temples) {
		cin >> temple;
	}
	for (auto& q : qs) {
		cin >> q;
	}

	for (const int64_t& q : qs) {
		int64_t min_dist = INT64_MAX;

		pair<int64_t, int64_t> shrine_pos = nearest_two(shrines, q);
		pair<int64_t, int64_t> temple_pos = nearest_two(temples, q);

		// 左神社が先
		{
			int64_t first = abs(q - shrine_pos.first);
			pair<int64_t, int64_t> new_pos = nearest_two(temples, shrine_pos.first);
			int64_t second = min(abs(new_pos.first - shrine_pos.first), abs(new_pos.second - shrine_pos.first));
			min_dist = min(min_dist, first + second);
		}

		// 右神社が先
		{
			int64_t first = abs(q - shrine_pos.second);
			pair<int64_t, int64_t> new_pos = nearest_two(temples, shrine_pos.second);
			int64_t second = min(abs(new_pos.first - shrine_pos.second), abs(new_pos.second - shrine_pos.second));
			min_dist = min(min_dist, first + second);
		}

		// 左寺が先
		{
			int64_t first = abs(q - temple_pos.first);
			pair<int64_t, int64_t> new_pos = nearest_two(shrines, temple_pos.first);
			int64_t second = min(abs(new_pos.first - temple_pos.first), abs(new_pos.second - temple_pos.first));
			min_dist = min(min_dist, first + second);
		}

		// 右寺が先
		{
			int64_t first = abs(q - temple_pos.second);
			pair<int64_t, int64_t> new_pos = nearest_two(shrines, temple_pos.second);
			int64_t second = min(abs(new_pos.first - temple_pos.second), abs(new_pos.second - temple_pos.second));
			min_dist = min(min_dist, first + second);
		}

		cout << min_dist << endl;
	}


	return 0;
}


Measured memory_bytes: 3712
import math
import bisect
MOD = 1000000007

N = int(input())
ABs =  []

count00 = 0
for i in range(N):
  A, B = map(int, input().split())
  if A == 0:
    if B == 0:
      count00 += 1
    else:
      ABs.append([0, -1])
  elif B == 0:
    ABs.append([1, 0])
  else:
    mygcd = math.gcd(A, B)
    A, B = A//mygcd, B//mygcd
    if A < 0:
      ABs.append([-A, -B])
    else:
      ABs.append([A, B])
  
N2 = N - count00
if N2 == 0:
  print(count00)
  exit()

ABs.sort(key = lambda x:x[1])
Bs = [i[1] for i in ABs]
index0 = bisect.bisect_left(Bs, 0)

if (index0==0) or (index0==N2):
  print((pow(2, N2, MOD) +count00 -1) %MOD)
  exit()

btm = ABs[:index0]
top = ABs[index0:]

lenbtm = index0
lentop = N2 - index0
for i in range(lenbtm):
  btm[i] = [-btm[i][1], btm[i][0]]

btmdict = {}
topdict = {}
for i in btm:
  mykey = str(i[0]) + '-' + str(i[1])
  btmdict[mykey] = 0
  topdict[mykey] = 0
for j in top:
  mykey = str(j[0]) + '-' + str(j[1])
  btmdict[mykey] = 0
  topdict[mykey] = 0

for i in btm:
  mykey = str(i[0]) + '-' + str(i[1])
  btmdict[mykey] += 1
for j in top:
  mykey = str(j[0]) + '-' + str(j[1])
  topdict[mykey] += 1

ans = 1
for i in btmdict:
  btmi = btmdict[i]
  topi = topdict[i]
  if btmi*topi >= 1:
    ans = ans * (pow(2, btmi, MOD) +pow(2, topi, MOD) -1) %MOD
  elif btmi == 0:
    ans = ans * pow(2, topi, MOD) %MOD
  else:
    ans = ans * pow(2, btmi, MOD) %MOD

ans = (ans +count00 -1) %MOD
print(ans)


Measured memory_bytes: 99200
FB = (1..10000).map{|x|a=[[:Fizz][x%3],[:Buzz][x%5]]*'';a==''?x.to_s: a}
loop do
  m, n = gets.split.map(&:to_i)
  break if m == 0
  pos = []
  ret = Array.new(m){|i|i+1}
  FB[0,n].zip(n.times.map{gets.chomp}).map.with_index{|(a,b),i| i if a!=b}.compact.unshift(0).each_cons(2).with_index{|(a,b),i| pos << (b-a)%(m-i)}
    pos[0,m-1].reduce(0){|s,t| ret.slice!(t=(s+t)%ret.size); t-1}
    puts ret.join(' ')
end

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

int main(){
    int n;
    cin >> n;
    int value[n], cost[n];
    for(int i=0; i<n; i++){
        cin >> value[i];
    }
    for(int i=0; i<n; i++){
        cin >> cost[i];
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        if(value[i] > cost[i]) ans += value[i] - cost[i];
    }
    cout << ans << endl;
    return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    LL ans = accumulate(ALL(B), 0);
    REP(i, N-1) {
        if(A[i]+1 == A[i+1]) {
            ans += C[A[i]-1];
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define md 1000000007
#define mx 1e18
#define pb push_back
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pii pair<ll int,ll int>
#define ff first
#define ss second

ll int n;
map<ll int,vector<ll int>>g;
ll int dp[100001][2];

void dfs(ll int u=1 , ll int p=0)
{
	for(auto v : g[u])
	{
		if(v==p)
			continue;
		dfs(v , u);

		dp[u][1]*=(dp[v][0]+dp[v][1]);
		dp[u][1]%=md;
		dp[u][0]*=(dp[v][1]);
		dp[u][0]%=md;
	}
}

int main()
{
	// fastio
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt" , "r" , stdin);
	// freopen("output.txt" , "w" , stdout);
	// #endif

	cin>>n;
	for(ll int i=1;i<n;i++)
	{
		ll int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(ll int i=1;i<=n;i++)
		for(ll int j=0;j<=1;j++)
			dp[i][j]=1;

	dfs();

	cout<<(dp[1][0] + dp[1][1])%md<<endl;

	return 0;
}


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int m,n;
    cin>>m>>n;
    for(int i=0;i<n;++i){
        int a;cin>>a;
        m -= a;
    }
    if(m <0)cout << -1 << endl;
    else cout << m << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
     
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long int
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define N 300009
#define mod 1000000007
#define med 998244353
#define debug cout<<"There There\n";
#define debug1(x) cout<<"\nValue is "<<x<<endl
#define debug2(x,y) cout<<"\nValue is "<<x<<" "<<y<<endl
#define debug3(x,y,z) cout<<"\nValue is "<<x<<" "<<y<<" "<<z<<endl  
#define pr pair<int,int>
#define mx INT_MAX
#define lmx LONG_MAX
#define err return 0
#define cn continue
#define bre break

string s;
string s1;
string s2;

int check(string a,string b)
{
	int differ=0;
	for(int i=0;i<a.length();i++)
	{
		if(a[i]!=b[i])
			differ++;
	}
	return differ;
}

int32_t main()
{
	IOS;
	cin>>s;
	int n=s.length();
	for(int i=0;i<n;i++)
	{
		if(i%2==0)
		{
			s1+='0';
			s2+='1';
		}
		else
		{
			s1+='1';
			s2+='0';
		}
	}
	int ans=min(check(s,s1),check(s,s2));
	cout<<ans<<endl;
	
}		

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

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int N = in.i();
        int[] A = in.ii();
        int[] count = new int[N+1];
        for (int i = 0; i < N; i++) {
            count[A[i]]++;
        }
        long sum = 0;
        for (int i = 1; i <= N; i++) {
            sum += (long)count[i] * (count[i] - 1) / 2;
        }
        for (int i = 0; i < N; i++) {
            out.println(sum - count[A[i]] + 1);
        }
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
    }
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = 0;
    int mn = min(k, a);
    ans += mn;
    k -= mn;

    mn = min(k, b);
    k -= mn;

    mn = min(k, c);
    ans -= mn;
    k -= mn;

    cout << ans << '\n';

    return 0;
}


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


int main() {
    string S;
    cin >> S;
    S.push_back(' ');
//    cout << S.size() << endl;
    long long N = S.size()-1;

    vector<long long> A(N+1, -1);
    for(int i=0; i<N; i++){
        if(S.at(i) == '>' && (S.at(i+1) == '<' || S.at(i+1) == ' ')){
            A.at(i+1) = 0;
        }    

        if(S.at(i) == '<' && (i == 0)) A.at(i) = 0;
    }

    for(int i=0; i<N+1; i++){
        if(A.at(i) == 0){
            for(int j=1; j<N; j++){
                if(i + j <= N && A.at(i+j) < 0){
                    if(S.at(i+j) == '<'){
                        A.at(i+j) = A.at(i+j-1) + 1;
                    } 
                    else{
                        if(S.at(i+j-1) == '<') {
                            A.at(i+j) = A.at(i+j-1) + 1;
                        }
                    }
                }
                else break;
                
            }
        }
    }

    for(int i=0; i<N+1; i++){
        if(A.at(i) == 0){
            for(int j=1; j<N; j++){
                if(i - j >= 0 && A.at(i-j) < 0){
                    if(S.at(i-j) == '>'){
                            A.at(i-j) = A.at(i-j+1) + 1;
                    }
                    else if(S.at(i-j+1) == '>') {
                            A.at(i-j) = A.at(i-j+1) + 1;
                    }
                }
                else{
                    break;
                }
            }
        }
    }

    for(int i=0; i<N; i++){
        if(S.at(i)=='<'){
            if(A.at(i) >= A.at(i+1)){
                A.at(i+1) = A.at(i) + 1;
            }
        }
        else{
            if(A.at(i) <= A.at(i+1)){
                A.at(i) = A.at(i+1) + 1;
            }
        }
    }

    long long sum=0;
    rep(i, N+1) sum += A.at(i);
    cout << sum << endl;
//    rep(i, N+1) cout << "A.at(" << i << ") = " << A.at(i) << " S.at(" << i << ") = " << S.at(i) << endl;

}


Measured memory_bytes: 4740
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[119];
int main(){
	int a;scanf("%d%s",&a,in);
	int at=0;
	int ret=0;
	for(int i=0;i<a;i++){
		if(in[i]=='I')at++;
		else at--;
		ret=max(ret,at);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
typedef long long ll;
const int INF=0x3f3f3f3f;

int main()
{
	int n;
	ll m;
	cin>>n>>m;
	vector<int> a(n);
	vector<ll> suf(n+1);
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a.begin(),a.end());
	for(int i=n-1;i>=0;i--)
		suf[i]=suf[i+1]+a[i];
	int L=2,R=2e5,tar=-1;
	while(L<=R)
	{
		int mid=L+R>>1;
		ll cnt=0;
		for(int i=0;i<n;i++)
		{
			int pos=lower_bound(a.begin(),a.end(),mid-a[i])-a.begin();
			cnt+=n-pos;
		}
		if(cnt>=m)
		{
			L=mid+1;
			tar=mid;
		}
		else R=mid-1;
	}
	ll cnt=0,ans=0;
	for(int i=0;i<n;i++)
	{
		int pos=upper_bound(a.begin(),a.end(),tar-a[i])-a.begin();
		cnt+=n-pos;
		ans+=1ll*(n-pos)*a[i]+suf[pos];
	}
	ans+=1ll*tar*(m-cnt);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1536
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N = d_in()
L_list = ds_in()

S = sum(L_list)
if max(L_list) * 2 < S:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
def ss(st):
    flag = True
    
    if len(st) % 2 != 0:
        flag = False
    else:
        n = len(st) // 2
        for i in range(n):
            if st[i] != st[i+n]:
                flag = False
                break
    return flag

S = input()
for i in range(len(S)-1, 0, -1):
    temp = S[0:i]
    if ss(temp):
        print(len(temp))
        break

Measured memory_bytes: 3064
n = int(input())
ac = 0
wa = 0
tel = 0
re = 0
for y in range(0,n):
  x = input()
  if x[0] == 'A':
    ac += 1
  elif x[0] == 'W':
    wa += 1
  elif x[0] == 'T':
    tel += 1
  else:
    re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tel))
print("RE x " + str(re))

Measured memory_bytes: 69888
def main():
    N = int(input())
    A = [int(n)*2 for n in input().split()]#ans[0]+ans[1]=A[0]
    ans = [0]*N
    #A[0]
    tmp = A[0]
    for i in range(N-1):
        p = -1 if i % 2 == 0 else 1
        tmp += A[i+1] * p
    ans[0] = tmp // 2
    #ほか
    for i in range(N-1):
        ans[i+1] = A[i] - ans[i]
    print(" ".join([str(a) for a in ans]))


main()

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

	bool table[1000001];
	fill((bool*) table, (bool*) table + 1000001, true);

	table[0] = false;
	table[1] = false;
	for (int i = 2; i * i <= 1000000; i++) {
		if (table[i]) {
			for (int j = i + i; j <= 1000000; j += i) {
				table[j] = false;
			}
		}
	}

	int n;
	while (~scanf("%d", &n)) {
		if (n == 0)
			break;

		int res = 0;
		for (int i = n, j = 0; j <= n / 2; j++, i--) {
			if (table[i] && table[j])
				res++;
		}

		printf("%d\n", res);
	}
}

Measured memory_bytes: 4168
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, k;
    cin >> n >> k;
    if (n % k == 0)
        cout << "0" << endl;
    else
        cout << "1" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long i64;
const int maxN = 1e5 + 5;
int n;

int main() {
  if(fopen("input.txt","r")) {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  }

  scanf("%d", &n);

  i64 sum0 = 0, sum1 = 0;
  i64 opt0 = 0, opt1 = 0;
  for(int i = 1;i <= n; ++i) {
    int a; scanf("%d", &a);
    sum0 += a; sum1 += a;
    if(i & 1) {
      if(sum0 >= 0) opt0 += sum0 + 1, sum0 = -1;
      if(sum1 <= 0) opt1 +=-sum1 + 1, sum1 = +1;
    } else {
      if(sum0 <= 0) opt0 +=-sum0 + 1, sum0 = +1;
      if(sum1 >= 0) opt1 += sum1 + 1, sum1 = -1;
    }
  }

  printf("%lld\n", std::min(opt0, opt1));
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
using namespace std;
vector<int> t(31);
#define s(i,j) swap(i,j)
#define P pair<int,vector<int> >
void move1(){s(t[13],t[18]);s(t[7],t[22]);s(t[8],t[23]);s(t[9],t[24]);s(t[10],t[12]);}
void move2(){s(t[15],t[16]);s(t[1],t[28]);s(t[2],t[29]);s(t[3],t[30]);s(t[19],t[21]);}
void move3(){s(t[3],t[22]);s(t[6],t[25]);s(t[9],t[28]);s(t[13],t[15]);s(t[12],t[19]);}
void move4(){s(t[7],t[30]);s(t[4],t[27]);s(t[1],t[24]);s(t[10],t[21]);s(t[16],t[18]);}

bool ok(vector<int>x){
int m,s,e,sum=0;
int table[]={9,3,3,3,3,9};
for(int i=0;i<6;i++){
	s=sum+1;
	sum+=table[i];
	e=sum;
	m=x[s];
	for(int j=s;j<=e;j++){
		if(x[j]!=m)return 0;
	}
}
return 1;
}

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        t[0]=0;
        for(int j=1;j<=30;j++)cin>>t[j];
    queue<P>bfs;
    bfs.push(P(0,t));
 
    while(!bfs.empty()){
    pair<int,vector<int> >tmp=bfs.front();
    vector<int>tt(31);
    for(int k=1;k<=30;k++){tt[k]=tmp.second[k];t[k]=tmp.second[k];}
    bfs.pop();
        int tf=tmp.first;
        if(ok(tt)){
        cout<<tf<<endl;
        break;
        }
        move1();
        bfs.push(make_pair(tf+1,t));
        for(int k=1;k<=30;k++)t[k]=tt[k];
        move2();
        bfs.push(make_pair(tf+1,t));
        for(int k=1;k<=30;k++)t[k]=tt[k];
        move3();
        bfs.push(make_pair(tf+1,t));
        for(int k=1;k<=30;k++)t[k]=tt[k];
        move4();
        bfs.push(make_pair(tf+1,t));
        for(int k=1;k<=30;k++)t[k]=tt[k];
    }
}
    return 0;
}

Measured memory_bytes: 15864
//   Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e18;
const ll INF= 1e18;
long double PI=3.1415926;

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    ll temp=power(a,b/2)%mod;
    if(b%2==0){
        return (temp*temp)%mod;
    }
    else{
        return ((a*temp)%mod*temp)%mod;
    }
}

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

vector<ll>v;
vector<ll>::iterator it;
map<ll,ll>mp;

void primeFactors(ll n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        //cout << 2 << " ";  
        mp[2]++;
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            //cout << i << " ";  
            mp[i]++;
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2){ 
        mp[n]++; 
        //cout << n << " "; 
    } 
}  

ll dp[3001][3001];

void solve(string a, string b){
    ll an=a.length();
    ll bn=b.length();
    for(ll x=0; x<=an; x++){
        for(ll y=0; y<=bn; y++){
            dp[x][y]=0;
        }
    }
    for(ll x=1; x<=an; x++){
        for(ll y=1; y<=bn; y++){
            dp[x][y]=max(dp[x-1][y],dp[x][y-1]);
            if(a[x-1]==b[y-1]){
                if(dp[x][y]<=dp[x-1][y-1]+1){
                    dp[x][y]=dp[x-1][y-1]+1;
                }
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    //cin>>t;
    t=1;
    //ll c=1;
    while(t--){
        string s,t;
        cin>>s>>t;
        solve(s,t);
        string out="";

        ll x=s.length();
        ll y=t.length();
        while(x>0&&y>0){
            if(s[x-1]==t[y-1]){
                out+=s[x-1];
                x--;
                y--;
            }
            else{
                if(dp[x-1][y]>dp[x][y-1]){
                    x--;
                }
                else{
                    y--;
                }
            }
        }

        reverse(out.begin(),out.end());
        cout<<out<<"\n";
        mp.clear();  
        v.clear();
        //cout<<"Case #"<<c<<": "<<ans<<"\n";
        //c++;
    }
    return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{
	fastio;
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	string s,t,u;
	ll a,b;
	cin>>s>>t>>a>>b>>u;

	if(u==s){
		a--;
	}
	else{
		b--;
	}
	cout<<a<<" "<<b;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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 Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	double w, h;
	cin >> w >> h;
	int x, y;
	cin >> x >> y;
	double ans = w * h / 2;
	int ans2 = (x == w / 2 && y == h / 2) ? 1 : 0;
	cout << fixed << setprecision(15) << ans << " " << ans2 << endl;
	return 0;
}

Measured memory_bytes: 256
open Printf
open Scanf

let tsurukame x y =
  let ways x = List.init (x + 1) (fun i -> (x - i) * 2 + i * 4) in
  if  List.mem y (ways x) then "Yes"
                          else "No"

let x, y  = sscanf (read_line ()) "%d %d" (fun x y -> (x, y))
let () = printf "%s\n" (tsurukame x y)

Measured memory_bytes: 3632
k,i,j;long d[111][2<<17],m=1e9+7;
main(a){
	for(scanf("%*d%d",&k);~scanf("%d",&a);i++)for(d[0][j=k]=1;~j;j--)d[i+1][j]=(d[i][j]+d[i+1][j+1]-d[i][j+a+1]+m)%m;
	printf("%d",*d[i]);
}

Measured memory_bytes: 204928
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int a[5];
	fo(i,5) cin >> a[i];

	fo(i,5){
		if(a[i]==0){
			cout << i+1 << endl;
			return 0;
		}
	}
	
	return 0;
}

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

typedef long long LL;

int main()
{
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    for(int i=1;i<=3500;i++)
    {
        for(int j=1;j<=i;j++)
        {
            LL dup=1LL*N*i*j;
            LL dd=4LL*i*j-i*N-N*j;
            if(dd<=0) continue;
            if(dup%dd==0) {cout<<i<<" "<<j<<" "<<dup/dd<<endl;return 0;}
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c=0;
    cin>>a>>b;
    for(a=a;a<=b;a++){
        stringstream ss;
        ss<<a;
        string s,s1;
        ss>>s;
        s1=s;
        reverse(s.begin(),s.end());
        s==s1?c+=1:c=c;
        ss.clear();
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
 
int main(){
  int a, b;
  
  cin >> a >> b;
  
  cout << fixed;
  cout << a/b << " " << a % b << " " << setprecision(5) << (double)a/b << endl;
  
  return 0;
}

Measured memory_bytes: 3252
fun main(args: Array<String>) {

    while(true){
    val num = readLine()
    if (num == "0 0") {
        break
    }
    // Your code here!

    val num_list = num!!.split(" ")
    val people = Integer.parseInt(num_list[0])
    val place =  Integer.parseInt(num_list[1])
    
    
    var res = IntArray(place)
    
    for (i in 1..people){
        var counter = 0
        readLine()!!.split(" ").forEach{
            res[counter] = res[counter] + Integer.parseInt(it)
            counter ++
        }
    }
    


    
    val sorted_res = res.sortedDescending()
    var  rank = 0
    var ans = IntArray(place)
    //println(sorted_res)
    for (i in sorted_res){
        var counter = 0
        for ( j in res){
           if (i == j ){
                //println("j=")
                //println(j)
               //print("i=")
               //println(i)
                //println("counter = ")
                //println(counter)
               //print("rank=")
               //println(rank)
                ans[rank] = counter+1
                rank ++
               res[counter] = res[counter] * -1
           }
        counter ++
       }
    }
   println(ans.joinToString(separator = " "))
   }
}



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

int main(void){
	
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	int sum=0;
	if(n>k){
		sum=x*k+y*(n-k);
	}
	else{
		sum=x*n;
	}
	cout<<sum<<endl;
	
	
	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n, m;
    cin >> n;

    map<string, int> mp;

    string s;
    for(int in=0;in<n;in++) {
        cin >> s;
        auto result = mp.insert(make_pair(s, 1));
        if(!result.second) mp[s]++;
    }

    cin >> m;
    string t;
    for(int im=0;im<m;im++) {
        cin >> t;
        auto result = mp.insert(make_pair(t, 1));
        if(!result.second) mp[t]--;
    }

    int ans = 0;
    for(auto imp:mp) {
        ans = max(ans, imp.second);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int m1,d1,m2,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 == m2){
    cout << 0 << endl;
    return 0;
  }
  cout << 1 << endl;
  return 0;
}


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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 998244353;
const int maxn = (int) 200000 + 20;
const int maxm = (int) 1000000 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

int n;
int p, q;
vector<int> G[maxn];

int dep[maxn];
int len[maxn], mn[maxn];

void dfs(int u, int f)
{
    for(auto v : G[u])
    {
        if(v == f) continue;
        dep[v] = dep[u] + 1;
        dfs(v, u);
    }
}

void dfs2(int u, int f, int k)
{
//    cout <<u <<" " <<dep[u] <<endl;

    for(auto v : G[u])
    {
//        cout <<"ad :L " <<u <<" " <<v <<endl;
        if(v == f || dep[v] <= k) continue;
        len[v] = len[u] + 1;
        mn[v] = min(mn[u], dep[v]);
        dfs2(v, u, k);
    }
}

void work()
{
    cin >>n >>p >>q;

    for(int i = 1; i < n; i++)
    {
        int x, y;
        cin >>x >>y;
        G[x].pb(y);
        G[y].pb(x);
    }

    dep[q] = 0;
    dfs(q, q);

    memset(len, -1, sizeof(len));
    len[p] = 0;
    mn[p] = dep[p];
    int k = dep[p] / 2;
    dfs2(p, p, k);

    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(dep[i] <= k || len[i] == -1) continue;
        int t = dep[i] - len[i];

        if(t > 1)
        {
            t -= 1;
        }
        else
        {
            t = 0;
        }

        ans = max(ans, len[i] + t);
    }

    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll fac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll a,b,x;cin >> a>>b >>x;
    if(a!=0){
    cout << b/x-(a-1)/x << endl;
    }
    else{
        cout << b/x+1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n, y;
    cin >> n >> y;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n - i; j++) {
            if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) {
                cout << i << " " << j << " " << n - i - j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18
int N;
vector<string> v;

void build(int i, int j1, string s) {
    if (i == N) {
        v.push_back(s);
        return;
    }

    for (int j = 0; j <= j1; j++) {
        string tmps = s;
        tmps.push_back('a' + j);
        build(i + 1, (j == j1 ? j1 + 1 : j1), tmps);
    }
}

int main() {
    cin >> N;
    build(0, 0, "");
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
        cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 7796
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string str,bubu;
	cin >> str >> bubu;
	
	vector<string> v;
	
	REP(i,str.size() - bubu.size() + 1)
	{
		bool flag = false;
		REP(j,bubu.size())
		{
			if(!(str[i+j] == '?' || str[i+j] == bubu[j]))
			{
				flag = true;
				break;
			}
		}
		if(flag)continue;
		
		string inp = "";
		REP(j,str.size())
		{
			if(str[j] == '?')
				inp += "a";
			else
				inp += str[j];
		}
		
		REP(j,bubu.size())
		{
			inp[i+j] = bubu[j];
		}
		
		v.PB(inp);
		
	}
	
	sort(ALL(v));
	
	if(v.size() > 0)
	{
		cout << v[0] << endl;
	}
	else
	{
		cout << "UNRESTORABLE" << endl;
	}
		
		
	return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int h, n;
    cin >> h >> n;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        sum += x;
    }
    if (sum >= h)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

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

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i,h) cin >> grid[i];

  int cnt = 0;
  rep(i,h) rep(j,w) if(grid[i][j] == '#') cnt++;

  int sh = 0, sw = 0;
  queue<pair<int, int>> que;
  vector<vector<int>> dist(h, vector<int> (w, -1));
  dist[sh][sw] = 1;
  que.push({sh, sw});

  while(!que.empty()) {
    int vh = que.front().fi;
    int vw = que.front().se;
    que.pop();

    rep(dir, 4) {
      int nvh = vh + dy[dir];
      int nvw = vw + dx[dir];

      if(nvh < 0) continue;
      if(nvw < 0) continue;
      if(nvh >= h) continue;
      if(nvw >= w) continue;
      if(dist[nvh][nvw] != -1) continue;
      if(grid[nvh][nvw] == '#') continue;

      dist[nvh][nvw] = dist[vh][vw]+1;
      que.push({nvh, nvw});
    }
  }

  if(dist[h-1][w-1] == -1) cout << -1 << endl;
  else cout << h * w - dist[h-1][w-1] - cnt << endl;
  return 0;
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,K; cin >> N >> K;
  vector<int> A(N, 0);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }


  for(int i = 0; i < K; i++){
    vector<int> B(N+1, 0);
    for(int j = 0; j < N; j++){
      int tmp = A[j];
      int left = max(0, j - tmp);
      int right = min(N, j + tmp + 1);
      // j - tmp ~ j + tmp までが+1
      B[left] += 1;
      B[right] -= 1;
    }
    for(int j = 1; j < N; j++){
      B[j] = B[j-1] + B[j];
    }

    int flg = true;
    for(int j = 0; j < N; j++){
      A[j] = B[j];
      if(A[j] < N){
        flg = false;
      }
    }
    if(flg) break;
  }

  for(int j = 0; j < N; j++){
    if(j == N-1) {
      cout << A[j] << endl;
    } else {
      cout << A[j] << " ";
    }
  }



}


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

vector<bool> D(10, false);

bool ok(int N)
{
  for (int i = 1; i <= N; i *= 10)
  {
    if (D.at(N / i % 10)) return false;
  }
  return true;
}

int main()
{
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < K; i++) 
  {
    int D_K;
    cin >> D_K;
    D.at(D_K) = true;
  }
  
  int ans;
  for (ans = N; ans < 100000; ans++)
  {
    if (ok(ans)) break;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N, T;
    cin >> N >> T;

    ll t[N];
    rep(i, N){
        cin >> t[i];
    }

    ll ans = 0;
    rep(i, N - 1){
        ans += min(T, t[i + 1] - t[i]);
    }
    ans += T;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5112
use proconio::input;

#[rustfmt::skip]
fn main() { std::thread::Builder::new().stack_size(128 * 1024 * 1024).spawn(solve).unwrap().join().unwrap(); }

#[proconio::fastout]
fn solve() {
    input! {
        n: String
    }

    println!(
        "{}",
        if n.chars().any(|d| d == '7') {
            "Yes"
        } else {
            "No"
        }
    )
}


Measured memory_bytes: 2252