akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 401;
ll dp[MAXN][MAXN];
ll a[MAXN],prefix[MAXN];
ll n;

ll rec(ll s,ll e){
    if(s == e) return 0;

    ll &ans = dp[s][e];

    if(ans != -1) return ans;

    ans = 1e15;

    FOR(i,s,e-1){
        ans = min(ans,rec(s,i) + rec(i+1,e) + prefix[e] - prefix[s-1]);
    }

    return ans;
}

void solve(){
    cin>>n;

    FOR(i,1,n){
        cin>>a[i];
        prefix[i] = prefix[i-1] + a[i];
    }

    memset(dp,-1,sizeof(dp));

    cout<<rec(1,n)<<endl;
}

signed main(){


    ll t;
    t = 1; 
    // cin>>t;
    FOR(tt,1,t){
        solve();
    }
    
}

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

using namespace std;
typedef long long ll;

int main(){
	int n,k; cin >> n >> k;
	int ans = 0;
	for(int i = 0; i < n; i++){
		int temp;
		cin >> temp;
		if(temp >= k) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int Q;
    cin >> Q;
    priority_queue<int> que1;
    priority_queue<int, vector<int>, greater<int>> que2;
    ll bsum = 0, asum1 = 0, asum2 = 0;
    for (int q = 0; q < Q; ++q) {
        int com;
        cin >> com;
        if (com == 1) {
            int a, b;
            cin >> a >> b;
            bsum += b;

            if (que1.size() == que2.size()) {
                que2.emplace(a);
                asum2 += a;
                int tmp = que2.top();
                que2.pop();
                que1.emplace(tmp);
                asum2 -= tmp;
                asum1 += tmp;
            } else {
                que1.emplace(a);
                asum1 += a;
                int tmp = que1.top();
                que1.pop();
                que2.emplace(tmp);
                asum1 -= tmp;
                asum2 += tmp;
            }
        } else {
            ll tmp = asum2 - asum1 + bsum;
            if (que1.size() != que2.size())
                tmp += que1.top();
            cout << que1.top() << ' ' << tmp << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 4304
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <tuple>

int main() {
  size_t N;
  std::cin >> N;

  std::vector<double> A(N);
  for (auto& ai: A) std::cin >> ai;

  double res = 0;
  for (auto ai: A) res += 1.0 / ai;
  res = 1.0 / res;

  std::cout << std::fixed << std::setprecision(10000000) << res << std::endl;
}


Measured memory_bytes: 58940
#include <stdio.h>
 
int main(void){
  int h, w, i, j;
  while(scanf("%d %d", &h, &w) && h || w){
    for(i = 0;i < h;i++){
      for(j = 0;j < w;j++) 
      putchar((i + j) % 2 == 0 ?'#' : '.');
      puts("");
    }
    puts("");
  }
  return 0;
}



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

int main(void) {
    int N, T, A;
    cin >> N;
    cin >> T;
    cin >> A;
    int min_diff = 1 << 30;
    int result = -1;

    for (int i = 0; i < N; i++) {
        int H;
        cin >> H;
        /* 理想からどれだけ違うか. */
        int diff = (A * 1000) - ((T * 1000) - (H * 6));
        if (0 > diff) diff *= (-1);

        /* 理想更新 */
        if (min_diff > diff) {
            min_diff = diff;
            result = i + 1;
        }
    }

    cout << result << endl;
}


Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    d,t,s=INTM()
    if d<=t*s:
        print('Yes')
    else:
        print('No')
if __name__=='__main__':
    do()

Measured memory_bytes: 9180
#include<cstdio>

typedef long long int lli;

int main(){
	for(;;){
		lli n;
		scanf("%lld",&n);
		if(n==0)break;
		lli al=n,ar=n;
		for(lli i=1;i<=40000;i++){
			if(n%i==0){
				lli a=i,c=n/i;
				for(int t=0;t<2;t++){
					lli mi=0,ma=-1;
					if(c%2!=0){
						mi=(c/2)-a+1;
						ma=(c/2)+a;
					}
					if(mi<=0){
						if(a%2!=0){
							mi=c-a/2;
							ma=c+a/2;
						}
					}
					if(mi<=0)mi=ma=0;
					if(ma-mi>ar-al){
						al=mi; ar=ma;
					}
					//printf("%lld %lld %lld %lld\n",a,c,mi,ma);
					lli p=a; a=c; c=p;
				}
			}
		}
		printf("%lld %lld\n",al,ar-al+1);
	}
}



Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
long long X, Y;
bool f() {
	return abs(X-Y) >= 2;
}
bool f(int x, int y) {
	if (x <= 1 && y <= 1) return false;
	for (int i = 1; x-2*i >= 0; ++ i) if (!f(x-2*i, y+i)) return true;
	for (int i = 1; y-2*i >= 0; ++ i) if (!f(x+i, y-2*i)) return true;
	return false;
}
int main() {
	/*for (int i = 0; i < 15; ++ i) {
		for (int j = 0; j < 15; ++ j) cout << (f(i,j)?"A":"B");
		cout << endl;
	}*/
	cin >> X >> Y;
	cout << (f() ? "Alice" : "Brown") << endl;
}


Measured memory_bytes: 256
#include <numeric>
#include <stack>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <string>
#include <bitset>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <tuple>
#include <sstream>

using namespace std;

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<int, int>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

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

    int n;
    while (cin >> n) {
        if (n % 2 == 0) {
            cout << 1.0l / 2 << endl;
        } else {
            cout << 1.0 * ((n + 1) / 2) / n << endl;
        }
    }
}


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

    

int main(){
   int n,k;
   cin>>n>>k;
   int a[n];
   f(i,0,n){
       cin>>a[i];
   }
   ll sum=0;
   sort(a,a+n);
   f(i,0,k){
       sum+=a[i];
   }
   cout<<sum<<endl;
}

Measured memory_bytes: 3608
import math

N = int(input())

def get_divisor_list(N):
    divisor_list = []

    for i in range(1, int(math.sqrt(N)) + 1):
        if N % i == 0:
            divisor_list.append([i, N //i])

    return divisor_list

divisor_list_max_min = min([max(x) for x in get_divisor_list(N)])



print(len(str(divisor_list_max_min)))

Measured memory_bytes: 3188
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
using namespace std;
int n;
int h[105];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&h[i]);
    }
    int flag=1,ans=0;
    while(flag)
    {
        flag=0;
        int l=0;
        for(int i=0;i<n;i++)
        {
            if(h[i]==0)
            {
                if(l!=i) ans++;
                l=i+1;
            }
            else
            {
                h[i]--;
                flag=1;
                if(i==n-1) ans++;
            }
        }

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

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
p = 10 ** 9 + 7
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
XX = [(X[i + 1] - X[i]) * (n - i - 1) * (i + 1) % p for i in range(n - 1)]
YY = [(Y[j + 1] - Y[j]) * (m - j - 1) * (j + 1) % p for j in range(m - 1)]
print(sum(XX) * sum(YY) % p)


Measured memory_bytes: 19648
import java.util.Scanner;
import java.util.HashSet;

public class Main  {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		HashSet<Integer> list = new HashSet<Integer>();
			
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			if(a == 0) {
				list.add(b);
				System.out.println(list.size());
			
			}else {
				System.out.println(list.contains(b) ? "1" : "0");
			}
		}
	}
}


Measured memory_bytes: 152360
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
int n;
ll a, b;
vector<ll> h;

bool calc(ll m){
  ll sum = 0;
  for(int i = 0; i < n; i++){
    ll tmp = h[i] - m * b;
    if(tmp <= 0)continue;
    sum += (tmp + a - b - 1) / (a - b);
  }
  return (sum <= m);
}

int main(int argc, char const* argv[])
{
  cin >> n >> a >> b;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    h.pb(x);
  }
  ll ld = 0;
  ll rd = 1e10;
  while(rd - ld > 1){
    ll md = (ld + rd) / 2;
    if(calc(md))rd = md;
    else ld = md;
  }
  cout << rd << endl;
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}

struct SegmentTree{
private:
    ll unit = 0;
    ll op(ll a,ll b){return a | b;}
    ll n;
    vector<ll> node;

public:
SegmentTree(vector<ll> v){
    ll sz = (ll)v.size();
    n = 1;while(n<sz) n *= 2;
    node.resize(2*n-1,unit);
    for(ll i=0;i<sz;i++) node[i+n-1]=v[i];
    for(ll i=n-2;i>=0;i--) node[i]=op(node[2*i+1],node[2*i+2]);
}

    void update(ll x,ll val){
        x += n-1;
        node[x] = val;
        while(x>0){
            x = (x-1)/2;
            node[x] = op(node[2*x+1],node[2*x+2]);
        }
    }

    ll query(ll a,ll b,ll k = 0,ll l = 0,ll r = -1){
        if (r<0) r = n;
        if (r<=a || b<=l) return unit;
        if (a<=l && r<=b) return node[k];
        ll vl = query(a,b,2*k+1,l,(l+r)/2);
        ll vr = query(a,b,2*k+2,(l+r)/2,r);
        return op(vl,vr);
    }
};

int main(){
    ll N;cin >> N;
    string S ; cin >> S;
    ll Q;cin >> Q;
    vector<ll> sd(N); rep(i,N) sd[i] = 1<<(S[i] - 'a'); 
    SegmentTree st(sd);
    rep(i,Q){
        ll q;cin >> q;
        if(q==1){
            ll idx;cin >> idx;
            char c;cin >>c;
            st.update(idx-1,1<<(c-'a'));
        }else{
            ll l,r;cin >> l >> r;
            ll a = st.query(l-1,r);
            ll ans = 0;
            rep(i,30){
                if(a%2==1) ++ans;
                a/=2;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

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

const ll mxs = 1e18+10;

void solution(){
	ll n,W;
	cin>>n>>W;
	vector<ll> w(n),v(n);
	for(ll i=0;i<n;++i)
		cin>>w[i]>>v[i];
	ll V=0;
	for(auto x: v)
		V += x;
	vector<ll> dp(V+1);
	for(ll i=1;i < (ll)dp.size();++i)
		dp[i] = mxs;
	for(ll i=0;i < n;++i){
		vector<ll> ndp(V +1);
		for(ll j=0;j <= V;++j){
			if(j >= v[i])
				ndp[j] = min(dp[j],(ll)w[i] + dp[j - v[i]]);
			else
				ndp[j]= dp[j];
		}
		dp = ndp;
	}
	ll res = 0;
	for(ll i= V; i>=0;--i){
		if(dp[i] <= W){
			res=i;
			break;
		}
	}
	cout<<res<<'\n';
}

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

}

Measured memory_bytes: 4752
#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


int main(){

    string s;
    cin >> s;
    int len = s.size();
    rev(s);


    int flag = 1;
    for (int i=0; i < len; ){
        if (s[i]=='r' && s[i+1]=='e'){
            if (s[i+2]=='s' && s[i+3]=='a' && s[i+4]=='r' && s[i+5]=='e') i += 6;
            else if (s[i+2]=='m' && s[i+3]=='a' && s[i+4]=='e' && s[i+5]=='r' && s[i+6]=='d') i += 7;
            else {
                flag = 0;
                break;
            }
        }
        else if (s[i]=='m' && s[i+1]=='a' && s[i+2]=='e' && s[i+3]=='r' && s[i+4]=='d') i += 5;
        else if (s[i]=='e' && s[i+1]=='s' && s[i+2]=='a' && s[i+3]=='r' && s[i+4]=='e') i += 5;
        else {
            flag = 0;
            break;
        }
    }

    if (flag == 0) cout << "NO" << endl;
    else cout << "YES" << endl;



    return 0;
}





//              g++ -std=c++1z

Measured memory_bytes: 512
A=int(input())
B=int(input())
C=int(input())
X=int(input())
a=0
b=0
c=0
count = 0
while a*500<=X and a<=A:
    while a*500+b*100<=X and b<=B:
        while a*500+b*100+c * 50 <=X and c<=C:
            if a*500+b*100+c*50==X:
                #print(a,b,c)
                count+=1
                break
            else:
                #print(a,a,b,c)
                c+=1
        c=0
        b+=1
        #print(b,c)
    a+=1
    b=0
    c=0
    #print(a,b,c)
print(count)


Measured memory_bytes: 3064
import copy
while True :
    card = list(input())
    if card[0] == "-" :
        break
    
    new_card = [''] * (len(card))
    m = int(input())
    for i in range(m) :
        h = int(input())
        for c in range(len(card)) :
            if c < len(card) - h :
                new_card[c] = card[h + c]
            else :
                new_card[c] = card[c + h - len(card)]
        card = copy.copy(new_card)
    for i in range(len(card)) :
        print(card[i], sep="", end="")
    print()   


Measured memory_bytes: 6332
a,v=map(int,input().split())#鬼
b,w=map(int,input().split())
t=int(input())

if w>=v:
    print("NO")
else:#v>w
    dif=v-w
    if dif*t>=abs(a-b):
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 9168
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	mp := map[int]int{}
	for i := 0; i < n; i++ {
		a := getNextInt(scanner)
		mp[a] = 1
	}
	m := getNextInt(scanner)
	for i := 0; i < m; i++ {
		b := getNextInt(scanner)
		mp[b] = 1
	}
	ans := make([]int, 0)
	for v := range mp {
		ans = append(ans, v)
	}
	sort.Ints(ans)
	for i := 0; i < len(ans); i++ {
		fmt.Fprintln(writer, ans[i])
	}
}



Measured memory_bytes: 33676
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<int> b(n);
    stack<int> ans;
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    while (b.size() != 0)
    {
        int index = -1;
        for (int i = 0; i < b.size(); i++)
        {
            if (b[i] == i + 1)
            {
                index = i;
            }
        }
        if (index == -1)
        {
            cout << -1 << endl;
            return 0;
        }
        ans.push(index + 1);
        vector<int> tmp;
        for (int i = 0; i < b.size(); i++)
        {
            if (i != index)
            {
                tmp.push_back(b[i]);
            }
        }
        b = tmp;
    }
    while (!ans.empty())
    {
        cout << ans.top() << endl;
        ans.pop();
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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

bool a[105][105];

int main(){
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int w, h, n; cin >> w >> h >> n;
	for(int i = 0; i < n; i++){
		int x, y, t; cin >> x >> y >> t;
		if(t == 1){
			for(int i = 1; i <= x; i++)
			for(int j = 1; j <= h; j++) a[i][j] = 1;
		}
		if(t == 2){
			for(int i = x + 1; i <= w; i++)
			for(int j = 1; j <= h; j++) a[i][j] = 1;
		}
		if(t == 3){
			for(int i = 1; i <= w; i++)
			for(int j = 1; j <= y; j++) a[i][j] = 1;
		}
		if(t == 4){
			for(int i = 1; i <= w; i++)
			for(int j = y + 1; j <= h; j++) a[i][j] = 1;
		}
	}
	int ans = 0;
	for(int i = 1; i <= w; i++)
	for(int j = 1; j <= h; j++)
		if(!a[i][j]) ans++;
	cout << ans << '\n';
}


Measured memory_bytes: 256
def main():
    import sys
    from math import log
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    prime = [True for i in range(int(N**.5)+2)]
    ans = 0
    if N == 1:
        print(0)
        exit()
    while True:
        # print('N = {}'.format(N))
        max_ = int(N ** .5) + 1
        for p in range(2, max_):
            if not prime[p]:
                continue
            for q in range(p, max_, p):
                prime[q] = False
            if N % p != 0:
                continue
            # print('p = {}'.format(p))
            t = 1
            p_ = p
            while N % p_ == 0:
                t += 1
                p_ *= p
            t -= 1
            l, r = 0, 10 ** 6
            # print('t = {}'.format(t))
            while l + 1 < r:
                m = (l + r) // 2
                if m * (m + 1) // 2 <= t:
                    l = m
                else:
                    r = m
            # print('ans += {}'.format(l))
            N //= (p ** t)
            ans += l
            break
        else:
            if N != 1:
                ans += 1
            break
    if ans == 0:
        ans = 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 17324
#include <iostream>

using namespace std;

void print_line(int w)
{
    cout << "+";
    for(int i = 0; i < w-2; i++){
        cout << "-";
    }
    cout << "+" << endl;
    return;
}

int main()
{
    int w, h;
    char c;
    cin >> w >> h >> c;
    int w_m = (w-1)/2;
    int h_m = (h-1)/2;

    print_line(w);
    for(int i = 1; i < h-1; i++) {
        cout << "|";
        for(int j = 1; j < w-1; j++) {
            if(i == h_m && j == w_m) {
                cout << c;
            } else {
                cout << ".";
            }
        }
        cout << "|" << endl;
    }
    print_line(w);

    return 0;
}


Measured memory_bytes: 3072
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))

heapq.heapify(a)

for _ in range(m):
    # 一番高い商品に割引券を使って入れ直す
    a_max = -1 * heapq.heappop(a)
    a_max //= 2
    heapq.heappush(a, -a_max)

print(-sum(a))


Measured memory_bytes: 14180
#include <vector>
#include <iostream>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int n, k;
bitset <100001> dp;
vector<int> a(100);

int main() {

	cin >> n >> k;
	for (int i = 0; i <= n - 1; i++) cin >> a[i];

	for (int i = 1; i <= k; i++) {
		for (int j = 0; j <= n - 1; j++)  {
			if (i - a[j] >= 0) dp[i] = (dp[i] or !dp[i - a[j]]);
			if (dp[i]) break;
		}
	}
	cout << ((dp[k]) ? "First" : "Second");

	return 0;
}

Measured memory_bytes: 3128
fn main() {
    let (x,y,_a,_b,_c) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s: Vec<usize>=s.split_whitespace().map(|x|x.parse().unwrap()).collect();
        (s[0],s[1],s[2],s[3],s[4])
    };
    let mut p: Vec<i64> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.split_whitespace().map(|x|x.parse().unwrap()).collect()
    };
    let mut q: Vec<i64> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.split_whitespace().map(|x|x.parse().unwrap()).collect()
    };
    let mut r: Vec<i64> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.split_whitespace().map(|x|x.parse().unwrap()).collect()
    };
    p.sort(); p.reverse(); p.truncate(x);
    q.sort(); q.reverse(); q.truncate(y);
    r.extend(p);
    r.extend(q);
    r.sort(); r.reverse(); r.truncate(x+y);
    println!("{}", r.into_iter().sum::<i64>());
}

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

using namespace std;

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

const int MX = 400010;

int n,a[MX];;

map<int,int> freq;

int main() {
	//freopen("input.txt", "r", stdin);
	scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		scanf("%d",&a[i]);
		freq[a[i]]++;
	}
	sort(a,a+n);
	if(freq.size() == 1){
		if(freq[a[0]] == a[0]+1 || freq[a[0]] >= 2 * a[0]){
			puts("Yes");
			return 0;
		}
	}
	if(freq.size() == 2 && (a[n-1]-freq[a[0]]) > 0 && freq[a[n-1]] >= 2 * (a[n-1]-freq[a[0]]) && a[n-1]-a[0] == 1){
		puts("Yes");
		return 0;
	}

	puts("No");
	return 0;
}

Measured memory_bytes: 5376
#include<iostream>

using namespace std;

int main(void){
  long long n, m;
  cin >> n >> m;
  if( abs(n-m) > 1){
    cout << 0 << endl;
    return 0;
  }
  long long memo = 1;
  if( n < m) swap(n,m);
  long long mm = m;

  for(int i = n; i  >= 1; i--){
    memo *= i;
    memo %= 1000000007;
    if( mm > 0){
      memo *= mm;
      memo %= 1000000007;
      mm--;
    }
  }
  if(n == m)memo *=2;
    memo %= 1000000007;

  cout << memo << endl;
  return 0;

}


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

using namespace std;
const int N=2e5+5;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int a,b;cin>>a>>b;
    string A,B;
    for(int i=0;i<a;i++)
        A+=b+'0';
    for(int i=0;i<b;i++)
        B+=a+'0';
    if(A<B) cout<<A<<endl;
    else cout<<B<<endl;
    return 0;
}


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

int n, T, t[200005], x;

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

    cin >> n >> T;
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
        if (i > 0) {
            if (t[i] - t[i-1] >= T) {
                x += T;
            }
            else {
                x += t[i] - t[i-1];
            }
        }
    }

    x += T;

    cout << x << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define Set(a) memset(a,0,sizeof(a))
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define openf(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define re register
#define ri re int
#define il inline
typedef long long ll;
typedef unsigned long long ull;
template<typename T> inline T rd(T& x)
{
	T f=1;x=0;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(T)(c-'0');
	x*=f;
	return x;
}
ll rd(){ll x;rd(x);return x;}
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
const int inf=1<<30;

char s[20];
ll a[200005];
int main()
{
	int n=rd();
	F(i,1,n)
	{
		scanf("%s",s+1);
		F(j,1,strlen(s+1)) a[i]=a[i]*27+s[j]-'a'+1;
	}
	sort(a+1,a+n+1);
	int ans=0;
	F(i,1,n) ans+=(a[i]!=a[i-1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5252
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int, int> P;

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

const int nmax = 8;
//接続状況を格納する隣接行列
bool graph[nmax][nmax];

//パスを全探索する関数
// v:今いる頂点
// N:頂点の数
int dfs(int v, int N, bool visited[nmax]) {
	//すべての頂点に訪れたかどうかのフラグ
	bool all_visited = true;
	//一つでも訪れていない頂点があればfalseにする
	for (int i = 0; i < N; i++) {
		if (visited[i] == false)all_visited = false;
	}

	//すべての頂点に訪れていれば有効なパスなので1を返す
	if (all_visited) {
		return 1;
	}

	int ret = 0;

	//すべての遷移先について調べる
	for (int i = 0; i < N; i++) {
		//頂点iが接続されていない、あるいはすでに訪れていればi+1に移る
		if (graph[v][i] == false)continue;
		if (visited[i])continue;
		//iに遷移する
		visited[i] = true;
		//iからの遷移を試す
		ret += dfs(i, N, visited);
		//iのフラグを取り消す
		visited[i] = false;
	}
	return ret;
}

int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		//接続状況の入力
		//無向グラフなので両方向からの接続をtrueにする
		graph[A - 1][B - 1] = graph[B - 1][A - 1] = true;
	}
	bool visited[nmax];
	//visitedをfalseで初期化する
	for (int i = 0; i < N; i++) {
		visited[i] = false;
	}

	visited[0] = true;
	//頂点0から始まるパスの数を出力する
	cout << dfs(0, N, visited) << endl;
	return 0;
}


Measured memory_bytes: 256
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)             

Measured memory_bytes: 7496
import java.lang.reflect.Array;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();
		boolean ans = false;
		
		if (N % 4 == 0) {
			ans = true;
		}
		if (N % 7 == 0) {
			ans = true;
		}
		if (ans) {
			System.out.println("Yes");
			return;
		}
		int[] four = new int[N];
		for (int i = 0; i < N; i++) {
			if (4 * i > N) {
				break;
			}
			four[i] = 4 * i;
		}
		int[] seven = new int[N];
		for (int i = 0; i < N; i++) {
			if (7 * i > N) {
				break;
			}
			seven[i] = 7 * i;
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (four[i]+seven[j]==N) {
					ans = true;
					break;
				}
			}
			if(ans){
				break;
			}
		}
		if(ans) {
			System.out.println("Yes");						
		} else {
			System.out.println("No");						
		}
	}	
}


Measured memory_bytes: 21716
#include<stdio.h>
#define max(a,b) ((a)>(b))?(a):(b)
int main(void)
{
  int a,b;
  scanf("%d%d",&a,&b);
  int sum=0;
  sum+=max(a,b);
  if(a>b){
    a--;
  }else{
    b--;
  }
  sum+=max(a,b);
  printf("%d",sum);
  return 0;
}


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

int main() {
    ll L, R;
    cin >> L >> R;
    if(L*R<2019){
        cout << L*(L+1) << endl;
        return 0;
    }

    map<ll, ll> mp;
    for(ll i=L; i<=min(L+2019, R) ; i++){
        ll aa = i%2019;
        if(!mp[aa]){
            mp[aa]++;
        }
    }

    int ans = 2019;
    for(int i=0; i<2018; i++){
        if(!mp[i]){
            continue;
        }
        // if(i==0){
        //     cout << 0 << endl;
        //     return 0;
        // }
        for(int j=i+1; j<2019; j++){
            if(!mp[j]){
                continue;
            }
            ans = min(i*j%2019, ans);
        }
    }

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

Measured memory_bytes: 384
n = int(input())
s = list(input())
total = s[1:].count('E')
ans = s[1:].count('E')
for i in range(n-1):
    if s[i]=='W':
        total += 1
    if s[i+1]=='E':
        total -= 1
    ans = min(ans, total)
print(ans)

Measured memory_bytes: 8140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair

int main(){
	ll n;
	cin >> n;
	ll a[n];
	for(ll i=0;i<n;i++) cin >> a[i];
	ll ans=a[0];
	for(ll i=1;i<n;i++) ans=ans^a[i];
	for(ll i=0;i<n;i++){
		ll res=0;
		for(ll j=0;j<31;j++){
			if((a[i]&(1<<j))&&!(ans&(1<<j))) res+=1<<j;
			if(!(a[i]&(1<<j))&&(ans&(1<<j))) res+=1<<j;
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 5192
#include<iostream>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>

using namespace std;
using Data = pair<long long,vector<int>>;

int main(){
  vector<long long> N(3);
  int K;
  cin >> N[0] >> N[1] >> N[2];
  cin >> K;
  vector<vector<long long>> v(3);
  for(int i=0;i<3;i++){
    v[i].resize(N[i]);
    for(int j=0;j<N[i];j++){
      cin >> v[i][j];
      sort(v[i].begin(),v[i].end(),greater<long long>());
    }
  }

  priority_queue<Data> que;
  set<Data> set;
  que.push(Data(v[0][0] + v[1][0] + v[2][0],vector<int>({0,0,0})));
  for(int k=0;k < K;k++){
    auto c = que.top();que.pop();
    cout << c.first << endl;
    for(int iter=0;iter<3;iter++){
      if(c.second[iter] + 1 < N[iter]){
        long long sum = c.first - v[iter][c.second[iter]] + v[iter][c.second[iter] + 1];
        auto num = c.second;
        num[iter]++;
        auto d = Data(sum,num);
        if(!set.count(d)) set.insert(d),que.push(d);
      }
    }
  }

}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

char C[2][10] = {};

int main() {
	for (int i = 0; i < 2; i++)cin >> C[i];
	for (int i = 0; i < 3; i++) {
		if (C[0][i] != C[1][3 - i - 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h> ///////////////////////////

int isPrime(int  x)//素数だと1 違うと0返す
{
  int i,j;

  if(x==2)return 1;
  else if(x<=1||x%2==0)return 0;
  
  else{
    for(j=3;j<=sqrt(x);j+=2){
      if(x%j==0){
	return 0;
      }
    }
  }
  return  1;
}

int main()
{
  int n,x;
  int i;
  int count=0;//素数の合計

  scanf("%d",&n);//INPUT
  
  for(i=0;i<n;i++){
    scanf("%d",&x);
    count+= isPrime(x);
  }

  printf("%d\n",count);//OUTPUT
  return 0;
}




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

typedef long long ll;

const int Maxn = 100005;

int n, q;
int a[Maxn];
ll sum[Maxn][2];
ll acc[Maxn];

int main()
{
    scanf("%d %d", &n, &q);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sum[i][0] = acc[i] = a[i];
        if (i > 0) {
            sum[i][0] += sum[i - 1][1];
            sum[i][1] += sum[i - 1][0];
            acc[i] += acc[i - 1];
        }
    }
    while (q--) {
        int x; scanf("%d", &x);
        ll res = 0;
        if (a[n - 1] <= x) { printf("%lld\n", sum[n - 1][0]); continue; }
        int lef = 0, rig = 1000000007;
        while (lef <= rig) {
            int mid = lef + rig >> 1;
            int beg = lower_bound(a, a + n, x - mid) - a;
            int en = upper_bound(a, a + n, x + mid) - a;
            int len = en - beg;
            if (beg + 2 * len <= n) lef = mid + 1;
            else rig = mid - 1;
        }
        lef--;
        int beg = lower_bound(a, a + n, x - lef) - a;
        int en = upper_bound(a, a + n, x + lef) - a;
        int len = en - beg;
        if (beg + 2 * len == n) {
            res += acc[n - 1];
            if (en > 0) res -= acc[en - 1];
            if (beg > 0) res += sum[beg - 1][0];
        } else if (beg + 2 * len == n - 1) {
            res += acc[n - 1];
            if (en > 0) res -= acc[en - 1];
            if (beg > 0) res += sum[beg - 1][1];
        } else {
            res += acc[n - 1];
            if (en > 0) res -= acc[en - 1];
            if (beg > 1) res += sum[beg - 2][1];
        }
        printf("%lld\n", res);
    }
    return 0;
}


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

typedef long long ll;
using namespace std;
const int modn=1e9+7;
const int maxn=2e5+10;
ll inv[maxn];
ll pow(ll a, ll n, ll p)
{
    ll ans = 1;
    while(n)
    {
        if(n & 1) ans = ans * a % p;
        a = a * a % p;
        n >>= 1;
    }
    return ans;
}
int main()
{
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    ll now=pow(2,n,modn);
    now=(now-1+modn)%modn;
    inv[1]=inv[0]=1;
	for(int i=2;i<=2e5;i++)inv[i]=(modn-modn/i)*inv[modn%i]%modn;
	ll p=1;
    for(int i=0;i<a;i++){
        p=p*(n-i)%modn*inv[i+1]%modn;
    }
    now=(now-p+modn)%modn;
    ll w=1;
    for(int i=0;i<b;i++){
        w=w*(n-i)%modn*inv[i+1]%modn;
    }
    now=(now-w+modn)%modn;
    printf("%lld\n",now);
    return 0;
}


Measured memory_bytes: 1792
N, P = [int(x) for x in input().split()]
S = input()

res = 0

if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1

print(res)


Measured memory_bytes: 4072
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 5005
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,k,mx;
char s[N],p;
string ans;
int main(){
	n=read(),k=min(read(),15);
	scanf("%s",s+1);
	p=*min_element(s+1,s+n+1);
	for(int i=1,j=0;i<=n;++i){
		if(s[i]==p)++j;
		else j=0;
		mx=max(mx,j<<(i==n));
	}
	if(mx*(1<<k-1)>=n){
		ans=string(n,p);
		goto End;
	}
	for(int i=1,j=0;i<=n;++i){
		if(s[i]==p)++j;
		else j=0;
		if((j<<(i==n))<mx)continue;
		string tmp="";
		for(int t=1;t<=mx*(1<<k-1);++t){
			tmp+=p;
		}
		int res=n-mx*(1<<k-1);
		for(int t=i+1;t<=n&&res;++t,--res){
			tmp+=s[t];
		}
		for(int t=(i==n?n-j:n);t>=1&&res;--t,--res){
			tmp+=s[t];
		}
		if(ans.empty()||ans>tmp){
			ans=tmp;
		}
	}
	End:
		cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3700
# frozen_string_literal: true

n, k = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)

sum = p[0..(k - 1)].reduce(:+)
max = sum
max_i = 0

(1..(n - k)).each do |i|
  sum -= p[i - 1]
  sum += p[k - 1 + i]
  if max < sum
    max = sum
    max_i = i
  end
end

puts p[max_i..(max_i + k - 1)].map { |e| (e + 1)/2.0 }.reduce(:+)


Measured memory_bytes: 16516
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ForBlue.ABC_075
{
    class C
    {
        static int n;
        static Node[] nodes;

        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            nodes = new Node[n];
            for (int i = 0; i < n; i++)
            {
                nodes[i] = new Node();
            }
            for (int i = 0; i < m; i++)
            {
                string[] inText = Console.ReadLine().Split(' ');
                int a = int.Parse(inText[0]) - 1;
                int b = int.Parse(inText[1]) - 1;
                nodes[a].to.Add(b);
                nodes[b].to.Add(a);
            }

            long cnt = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < nodes[i].to.Count; j++)
                {
                    int toTemp = nodes[i].to[0];
                    if (toTemp < i) continue;

                    for (int k = 0; k < nodes.Length; k++)
                    {
                        nodes[k].wasVisited = false;
                    }

                    nodes[i].to.RemoveAt(0);
                    nodes[toTemp].to.Remove(i);

                    nodes[0].wasVisited = true;
                    int visitCnt = 1;
                    if (!DFS(0, ref visitCnt))
                    {
                        //Console.WriteLine(i.ToString() + " " + toTemp.ToString());
                        cnt++;
                    }

                    nodes[i].to.Add(toTemp);
                    nodes[toTemp].to.Add(i);
                }
            }

            Console.WriteLine(cnt);
        }

        static bool DFS(int index, ref int visitCnt)
        {
            if (visitCnt == n)//全部行った
            {
                return true;
            }

            //行ける場所探索
            for (int i = 0; i < nodes[index].to.Count; i++)
            {
                if (!nodes[nodes[index].to[i]].wasVisited)
                {
                    visitCnt++;
                    nodes[nodes[index].to[i]].wasVisited = true;
                    if (DFS(nodes[index].to[i], ref visitCnt))
                    {
                        return true;
                    }
                }
            }
            //Console.WriteLine(visitCnt);
            return false;
        }
    }

    class Node
    {
        public List<int> to;
        public bool wasVisited;

        public Node()
        {
            to = new List<int>();
            wasVisited = false;
        }
    }
}


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

int main() {
    int n,k;
    cin >> n >> k;
    vector<double> dice(n+1);
    for(int i = 1; i < n+1; i++){
    double buf;
        cin >> buf;
        dice.at(i) = (buf + 1) / 2 + dice.at(i - 1);
    }

    double ans = 0;
    for(int i = 0; i <= n-k; i++){
        ans = max(ans,(dice.at(i+k)-dice.at(i)));
    }

    cout << fixed << setprecision(12);
    cout << ans << endl;
}

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

void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}

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

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

struct State {
    int a[N * N];
    int sid;
};

State now;
int ans = 45;

int h() {
    int res = 0;
    for(int i = 0; i < N * N; i++) {
        if(now.a[i] != N * N - 1) {
            res += abs(i / N - now.a[i] / N) + abs(i % N - now.a[i] % N);
        }
    }
    return res;
}

// d:今の深さ
// pre:1手前の空きマスの位置
void dfs(int d, int pre) {
    if(d + h() > ans) {
        return;
    }
    if(h() == 0) {
        ans = min(ans, d);
        return;
    }
    for(int i = 0; i < 4; i++) {
        if((now.sid / N + dy[i]) < 0 || (now.sid / N + dy[i]) >= N) {
            continue;
        }
        if((now.sid % N + dx[i]) < 0 || (now.sid % N + dx[i]) >= N) {
            continue;
        }
        int nxt_sid = (now.sid / N + dy[i]) * N + (now.sid % N + dx[i]);
        if(nxt_sid == pre) {
            continue;
        }
        int tmp = now.sid;
        swap(now.a[now.sid], now.a[nxt_sid]);
        now.sid = nxt_sid;
        dfs(d + 1, tmp);
        swap(now.a[nxt_sid], now.a[tmp]);
        now.sid = tmp;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 0; i < N * N; i++) {
        cin >> now.a[i];
        if(now.a[i] == 0) {
            now.a[i] = N * N - 1;
            now.sid = i;
        } else {
            now.a[i]--;
        }
    }
    dfs(0, -1);
    cout << ans << endl;
}


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

struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};

bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}

int main(){
  int n;
  cin >> n;
  
  vector<Dice> d(n);
  for (int i=0; i<n; i++){
      for (int j=0; j<6; j++){
          cin >> d.at(i).s[j];
      }
  }
  
 bool ff = true;
  for(int k=0;k<n-1;k++){
    for(int l=k+1;l<n;l++){
      bool f=false;
      for(int i=0;i<4;i++){
	d[l].roll('R');
	for(int j=0;j<4;j++){
	  d[l].roll('N');
	  if(same(d[k],d[l])) f=true;
	}
      }
      d[l].roll('E');
      for(int j=0;j<4;j++){
	d[l].roll('N');
	if(same(d[k],d[l])) f=true;
      }
      
      d[l].roll('W');
      d[l].roll('W');
      for(int j=0;j<4;j++){
	d[l].roll('N');
	if(same(d[k],d[l])) f=true;
      }
      if(f) ff=false;
    }
  }
  
  cout << (ff?"Yes":"No") << endl;
  
  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=(1e9)+7;
const int maxn=(1e5)+10;
int n,to[maxn*2];
ll dp[maxn][2];
int nxt[maxn*2],tot,head[maxn];
void add(int x,int y) {
	tot++; nxt[tot]=head[x];
	head[x]=tot; to[tot]=y;
}
void update(ll &x,ll y) { x=x*y%mod; }
void dfs(int u,int p) {
	dp[u][0]=dp[u][1]=1;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i]; if (v==p) continue;
		dfs(v,u);
		update(dp[u][0],dp[v][0]+dp[v][1]);
		update(dp[u][1],dp[v][0]);
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); int x,y;
	for (int i=1;i<n;i++) {
		read(x); read(y);
		add(x,y); add(y,x);
	}
	dfs(1,0);
	printf("%lld\n",(dp[1][0]+dp[1][1])%mod);
	return 0;
}

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

import sys
from math import sqrt
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()

M = int(sqrt(N))
i = 1
x = N
li1 = []
li2 = []
mul = []
while i < x:
    li1.append(x)
    i += 1
    prev = x
    x = N // i
    li2.append((prev - x) * (i - 1))
    mul.append(prev - x)
li = []
if i == x:
    li += li1 + [x] + li2[::-1]
else:
    li += li1 + li2[::-1]

M = len(li)
mul = [1] * (M-len(li2)) + mul[::-1]
dp = list2d(K-1, M, 0)
for i in range(M):
    dp[0][i] = li[i]

for i in range(1, K-1):
    acc = list(accumulate(dp[i-1]))[::-1]
    for j in range(M):
        dp[i][j] = acc[j] * mul[j] % MOD
print(sum(dp[K-2]) % MOD)


Measured memory_bytes: 120140