akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll X, N;
    cin >> X >> N;
    vector<bool> p(101, false);
    Rep (i, N) {
        ll pi;
        cin >> pi;
        p[pi] = true;
    }

    ll ans = 0;
    Rep (i, 120) {
        if (!p[i] and abs(i-X) < abs(ans-X)) {
            ans = i;
        }
    }

    cout << ans << "\n";


}

Measured memory_bytes: 3652
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

getNum :: IO Int
getNum = fst . fromJust . B.readInt <$> B.getLine

getNums :: IO [Int]
getNums = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]

main :: IO ()
main = do
    [a,b] <- getNums
    print $ if a >= 3 && b >= 3 then (a-2)*(b-2) 
                else if a == 2 || b == 2 then 0 
                    else if a == 1 && b == 1 then 1 else (a*b)-2

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  ll x;
  cin >> x;
  ll ans = (x / 11) * 2;
  if (x % 11) {
    ans += (x % 11 <= 6 ? 1 : 2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int k, t; cin >> k >> t;
    vint a(t);
    rep(i,t) cin >> a[i];
    int now = -1, ans = 0;
    while (k--) {
        int mx = 0;
        int next;
        rep(i,t) {
            if (i == now) continue;
            if (chmax(mx,a[i])) next = i;
        }
        if (mx == 0) {
            ans++;
            a[now]--;
        } else {
            a[next]--;
            swap(next,now);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define N (ll)(1e6+3)
#define INF (ll)(1e18+3)
#define MOD (ll)(1e9+7)

#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)

//using namespace __gnu_pbds;
using namespace std;
 
// typedef
// tree<
//     pair<ll,ll>,
//     null_type,
//     less<pair<ll,ll>>,
//     rb_tree_tag,
//     tree_order_statistics_node_update>
// ordered_set;

ll n;
ll a[N], b[N];
ll l, r;

ll fac[N], ifac[N];

ll powmod(ll b, ll p) {
    if (p == 0) return 1;
    if (p&1) return (b*powmod(b,p-1))%MOD;
    ll a = powmod(b,p>>1);
    return (a*a)%MOD;
}

void work() {
    fac[0] = 1;
    rep(i,1,N) fac[i] = (fac[i-1]*i)%MOD;
    ifac[N-1] = powmod(fac[N-1],MOD-2);
    per(i,0,N-1) ifac[i] = (ifac[i+1]*(i+1))%MOD;
}

ll choose(ll n, ll k) {
    return (((fac[n]*ifac[k])%MOD)*ifac[n-k])%MOD;
}

void solve() {
    work();
    cin >> n;
    rep(i,0,n+1) {
        cin >> a[i];
        a[i]--;
        if (b[a[i]]) {
            l = b[a[i]]-1, r = i;
        }
        b[a[i]] = i+1;
    }
    ll d = (n+1)-(r-l+1);
    rep(i,1,n+2) {
        ll ans = choose(n+1,i);
        if (d >= i-1)
            ans = (ans-choose(d,i-1)+MOD)%MOD;
        cout << ans << endl;
    }
}


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

Measured memory_bytes: 21760
#include<iostream>
#include<vector>
#include<ctime>
#include<chrono>
#include<random>
using namespace std;
using ll = long long;

int d;
vector<vector<int>> s(365,vector<int>(26));
vector<int> c(26);

auto start=chrono::system_clock::now();
inline double get_time(){
    auto end=chrono::system_clock::now();
    auto dur=end-start;
    double msec=chrono::duration_cast<chrono::microseconds>(dur).count();
    return msec;
}

random_device seed_gen;
mt19937_64 engine(seed_gen());
uint64_t get_rand_range(uint64_t min_val,uint64_t max_val){
    static mt19937_64 mt64(0);
    uniform_int_distribution<uint64_t> get_rand_uni_int(min_val,max_val);
    return get_rand_uni_int(mt64);
}

ll calc(vector<int> t){
    ll score=0;
    vector<int> last(26);
    for(int i=0;i<(int)t.size();i++){
        last[t[i]]=i;
        for(int j=0;j<26;j++) score-=c[j]*(i+1-last[j]);
        score+=s[i][t[i]];
    }
    return score;
}

void solve(){
    vector<int> v(d);
    for(int i=0;i<d;i++) v[i]=get_rand_range(0,25);
    ll score=calc(v);
    while(get_time()<1900000){
        if(get_rand_range(0,1)){
            int i=get_rand_range(0,d-1);
            int q=get_rand_range(0,25);
            int old=v[i];
            v[i]=q;
            ll new_score=calc(v);
            if(score>new_score) v[i]=old;
            else score=new_score;
        }else{
            int i=get_rand_range(0,d-2);
            int j=get_rand_range(i+1,min(i+16,d)-1);
            swap(v[i],v[j]);
            ll new_score=calc(v);
            if(score>new_score) swap(v[i],v[j]);
            else score=new_score;
        }
    }
    for(int k : v) cout<<k+1<<endl;
}

int main(){
    cin>>d;
    for(int i=0;i<26;i++){
        cin>>c[i];
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            cin>>s[i][j];
        }
    }
    solve();
}

Measured memory_bytes: 3676
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const N = readln.chomp.to!int;
    writeln(cartesianProduct(iota(N/4+1), iota(N/7+1)).canFind!(t => t[0] * 4 + t[1] * 7 == N) ? "Yes" : "No");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
ll gcd(ll, ll);
//
int main(){
    int n;
    cin >> n;
    ll a[n];
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    ll dif[n];
    dif[0] = 0;
    for(int i = 0; i < n - 1; i++){
        dif[((i + 1) * 2) % n] = dif[(i * 2) % n] + 2 * (a[(2 * i + 1) % n] - a[2 * i % n]);
    }
    ll difsum = 0;
    for(int i = 0; i < n; i++){
        difsum += dif[i];
    }
    ll base = (sum - difsum) / n;
    for(int i = 0; i < n; i++){
        cout << base + dif[i] << " ";
    }
}

Measured memory_bytes: 2816
#include<iostream>
#include<set>
#include<algorithm>

using namespace std;

typedef long long ll;

int N;
ll A[200000 + 10], B[200000 + 10];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i] >> B[i];
	ll ans = 0;
	ll minB = 1145141919810;
	int cntsame = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] > B[i] && minB > B[i]) {
			minB = B[i];
		}
		if (A[i] == B[i])cntsame++;
		ans += B[i];
	}
	if(cntsame != N)cout << ans - minB << endl;
	else cout << 0 << endl;
	return 0;
}

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

vector<int> patties, size;

int solve(int layers, int L) {
    if(layers <= 0) return 0;
    if(L == 0) {
        return 1;
    }
    layers--;
    if(layers == size[L-1]) {
        return patties[L-1];
    }
    if(layers < size[L-1]) {
        return solve(layers, L-1);
    }
    return patties[L-1] + 1 + solve(layers-size[L-1]-1, L-1);
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,x;
    cin >> n >> x;
    size.resize(n+1);
    patties.resize(n+1);
    size[0] = 1;
    patties[0] = 1;
    for(int i = 1; i <= n; ++i) {
        size[i] = 2*size[i-1] + 3;
        patties[i] = 2*patties[i-1]+1;
    }
    cout << solve(x, n) << '\n';
    return 0;
}




























Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int res = 10000;
        for (int i = 0; i < s.length() - t.length() + 1; i++) {
            int c = 0;
            for (int j = 0; j < t.length(); j++) {
                if (s.charAt(i + j) != t.charAt(j)) {
                    c++;
                }
            }
            res = Math.min(res, c);
        }
        System.out.println(res);
        sc.close();
    }
}

Measured memory_bytes: 35640
using System;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int s, h, m;
            s = int.Parse(Console.ReadLine());
            h = s / 3600;
            s = s % 3600;
            m = s / 60;
            s = s % 60;
            Console.WriteLine(h + ":" + m + ":" + s);
        }
    }
}



Measured memory_bytes: 15968
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int main() {
	int n; read(n);
	if (n == 3) {
		puts("2 5 63");
		return 0;
	}
	int base = 0;
	while (n >= 8) {
		n -= 8;
		printf("%d %d %d %d %d %d %d %d ", base + 2, base + 3, base + 4, base + 6, base + 8, base + 9, base + 10, base + 12);
		base += 12;
	}
	if (n == 1) printf("%d\n", base + 6);
	else if (n == 2) printf("%d %d\n", base + 2, base + 4);
	else if (n == 3) printf("%d %d %d\n", base + 2, base + 4, base + 6);
	else if (n == 4) printf("%d %d %d %d\n", base + 2, base + 3, base + 4, base + 9);
	else if (n == 5) printf("%d %d %d %d %d\n", base + 2, base + 3, base + 4, base + 6, base + 9);
	else if (n == 6) printf("%d %d %d %d %d %d\n", base + 2, base + 3, base + 4, base + 6, base + 9, base + 12);
	else if (n == 7) printf("%d %d %d %d %d %d %d\n", base + 2, base + 3, base + 4, base + 6, base + 8, base + 9, base + 10);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int MX = 100005, LMX = 18;
int p[LMX][MX], lvl[MX];
int n, q, u, v, k;
vi adj[MX];

void dfs (int u) {
	for (int v : adj[u]) {
		p[0][v] = u;
		lvl[v] = lvl[u] + 1;
		dfs(v);
	}
}

void pre () {
	for (int j = 1; j < LMX; j++)
		for (int i = 0; i < n; i++) 
			p[j][i] = p[j-1][p[j-1][i]];
}

int lca (int u, int v) {
	if (lvl[u] < lvl[v])
		swap(u, v);

	for (int j = 0; j < LMX; j++)
		if ((lvl[u] - lvl[v]) & (1 << j))
			u = p[j][u];

	if (u == v)
		return u;

	for (int j = LMX - 1; j >= 0; j--)
		if (p[j][u] != p[j][v]) {
			u = p[j][u];
			v = p[j][v];
		}

	return p[0][u];
}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++) {
    	cin >> k;
    	while (k--) {
    		cin >> u;
    		adj[i].push_back(u);
    	}
    }

   	dfs(0);
   	pre();

    cin >> q;
    while (q--) {
    	cin >> u >> v;
    	cout << lca(u, v) << endl;
    }

    return 0;
}



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

int main()
{
    int a,b, c=0, ec = 0;
    string s;
    cin >> a >> b >> s;
    for(int i=0; i<=(a+b); i++)
    {
        if(s[a] == '-') ec = 1;
        if(s[i] == '-') c++;

    }
    if((c == 1) && (ec == 1)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

int main(){
    int n,cnt=0;
    cin >>n;
    vector<int> a(n);
    for(auto &e:a) cin >> e;

    for(auto &e:a){
        for(;e%2==0;){
            e /= 2;
            cnt++;
        }
    }
    cout << cnt <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vp;
typedef vector<iii> vt;
typedef vector<vi> vv;
#define REP(i, n) for (ll i = 0; i < (n); ++i)

ll N, K, S;

int main()
{
    cin >> N >> K >> S;

    vi ans = vi(N);
    REP(i, N)
    {
        if (i < K)
        {
            ans[i] = S;
        }
        else if (S < 1e9)
        {
            ans[i] = 1e9;
        }
        else
        {
            ans[i] = 1;
        }
    }

    REP(i, N)
    {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2048
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	N := nextInt(sc)
	K := nextInt(sc)
	H := make([]int, N)
	for i := range H {
		H[i] = nextInt(sc)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(H)))
	// fmt.Println("N", N, "K", K, "H", H)
	for i := 0; i < K && i < N; i++ {
		H[i] = 0
	}
	ans := 0
	for i := 0; i < N; i++ {
		ans += H[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5120
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1000*1000*1000;
const ll LINF = (ll)1e18;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<ll> a(N);
    REP(i, N){
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<>());
    ll ans1 = a[0];
    ll ans2 = a[1];
    for(int i = 2; i < N; i++){
        if(abs(a[i] - ans1/2) < abs(ans2 - ans1/2)){
            ans2 = a[i];
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
using ll = long long;
const int MAX = 100000;
int main(){
        int N;
        ll K;
        int i;
        cin >> N >> K;
        long long array[MAX+1];
        for (int ans = 1; ans <= MAX; ++ans) {
                array[ans]=0;
        }
        for(i=0; i<N; ++i) {
                int a,b;
                cin >> a >> b;
                array[a] += b;
        }
        for (int ans = 1; ans <= MAX; ++ans) {
                if (K <= array[ans]) {
                        cout << ans << endl;
                        break;
                }
                K -= array[ans];
        }
        return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

void sonomama(string s,int y,int m,int d){
    cout << s << " " << y << " " << m << " " << d << endl;
}

void henkan(string s,int y,int m,int d){
    cout << "?" << " " << y-30 << " " << m << " " << d << endl;
}

int main(){
    string s;
    int y, m, d;
    while(cin>>s,s[0]!='#'){
        cin >> y >> m >> d;
        if(y>31){
            henkan(s, y, m, d);
        
        }else if(y==31&&m>=5){
            henkan(s, y, m, d);
        }else{
            sonomama(s, y, m, d);
            
        }

    }

    return 0;
}



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

int main() {
	int N, ans = 0;
	cin >> N;
	vector<int> A(N), B(N), C(N - 1);
	for (int& i : A) cin >> i;
	for (int& i : B) cin >> i;
	for (int& i : C) cin >> i;
	for (int& i : A) ans += B[i - 1];
	for (int i = 1; i < N; ++i) {
		if (1 + A[i - 1] == A[i]) ans += C[A[i - 1] - 1];
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static int mod =1000000007;
	public static void main(String[] args) {
		int a=sc.nextInt();
		double p=3.141592653589793;
		System.out.println(2*a*p);
		//String S=sc.next();
		//int v[]=new int[a];
		
		
		 
		
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 36012
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

struct DSU
{
    int n,x;
    vi p,r,sz;
    DSU(int N)
    {
        n=N;
        x=N-1;
        sz.assign(N,1);
        p.assign(N,0);
        r.assign(N,1);
        for(int i=0;i<N;i++)
            p[i]=i;
    }
    int findset(int i)
    {
        return (p[i]==i)?i:(p[i]=findset(p[i]));
    }
    bool issameset(int i,int j)
    {
        return findset(i)==findset(j);
    }
    void unionset(int i,int j)
    {
        int p1=findset(i);
        int p2=findset(j);
        if(p1!=p2)
        {
            x--;
            if(r[p1]>=r[p2])
            {
                p[p2]=p1;
                sz[p1]+=sz[p2];
                if(r[p1]==r[p2])
                    r[p1]++;
            }
            else
            {
                p[p1]=p2;
                sz[p2]+=sz[p1];
            }
        }
    }
    void disp()
    {
        for(int i=0;i<n;i++)
            cout<<p[i]<<' ';
        cout<<endl;
    }

    int getsize(int i){
        return sz[findset(i)];
    }
    int noofdisjointsets(){
        return x;
    }

};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>n>>m;
    DSU s(n);
    for(int i=0;i<m;i++){
        cin>>x>>y>>z;
        x--;y--;
        s.unionset(x,y);
    }
    cout<<s.noofdisjointsets()+1;



    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define what_is(x) cerr << #x << " is " << x << endl;
int main()
{
    fastIO;
    int n,x,y;
    cin>>x>>n;

    map<int,bool>mp;
    for (int i=0; i<n; ++i)
    {
        cin>>y;
        mp[y]=1;
    }
    int a=0,b=0;
    for (int i=x; i>=0; --i)
    {
        if (mp[i]==0)
        {
            a=i;
            break;
        }
    }
    for (int i=x; i<=10000; ++i)
    {
        if (mp[i]==0)
        {
            b=i;
            break;
        }
    }
    if (abs(x-a)<abs(x-b))
        cout<<a;
    else if (abs(x-a)==abs(x-b))
        cout<<min(a,b);
    else
        cout<<b;




}


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, s[105];

void gg(){
	printf("Impossible\n");
	exit(0);
}

int main(){
	scanf("%d", &n);
	FI(i, 1, n) scanf("%d", &s[i]);
	sort(s + 1, s + n + 1);
	if(n > 2 && s[1] == s[3]) gg();
	if(s[1] != s[2]){
		//unique centroid
		if(s[n] != s[1] * 2) gg();
		FI(i, 2, n){
			if(s[i] != s[i - 1] + 1) gg();
			if(i == n || s[i + 1] != s[i]) gg();
			while(i < n && s[i + 1] == s[i]) i++;
		}
	}
	else{
		if(s[n] != s[1] * 2 - 1) gg();
		FI(i, 3, n){
			if(s[i] != s[i - 1] + 1) gg();
			if(i == n || s[i + 1] != s[i]) gg();
			while(i < n && s[i + 1] == s[i]) i++;
		}
	}
	printf("Possible\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
ll solve(int N,vector<int> L, vector<int> R){
	ll ans = 0;
	N++;
	L.pb(0);
	R.pb(0);
	map<int,int> x2r,x2l;
	rep(i,N) x2l[L[i]]++,x2r[R[i]]++;

	int A = 0, B = N;

	for(int x = -100010; x<=100010;x++){
		A += x2r[x];
		B -= x2l[x];
		ans += 2*min(A,B);
	}
	return ans;
}
int main(){
	int N;
	cin>>N;
	vector<int> L(N),R(N);
	rep(i,N) cin>>L[i]>>R[i];
	cout<<solve(N,L,R)<<endl;
}


Measured memory_bytes: 20592
n = int(input())
A = list(map(int,input().split()))
exist = [0]*(n+1)
ans = []
for i in range(n,0,-1):
    cnt = 0
    for j in range(1,n//i+1):
        cnt += exist[i*j]
    if (cnt%2) != A[i-1]:
        ans.append(i)
        exist[i] = 1
print(len(ans))
print(" ".join(map(str,ans)))

Measured memory_bytes: 19812
#include <iostream>

unsigned long long int X, Y;
unsigned long long int res;

unsigned long long int solve() {
    unsigned long long int m = Y%X;
    if (X == Y) {
        return 1;
    } else {
        unsigned long long int tmp=X;
        while (tmp <= Y) {
            ++res;
            tmp *= 2;
        }
        return res;
    }
}

int main() {
    std::cin >> X >> Y;
    std::cout << solve() << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
  int n,i,ans=0;
  scanf("%d", &n);

  int a[n],b[n],c[n-1];

  for(i=0; i<n; i++)
    scanf("%d", &a[i]);
  for(i=0; i<n; i++)
    scanf("%d", &b[i]);
  for(i=0; i<n-1; i++)
    scanf("%d", &c[i]);

  ans += b[a[0]-1];

  for(i=1; i<n; i++){
    ans += b[a[i]-1];
    if(a[i]-a[i-1]==1)
      ans += c[a[i-1]-1];
  }

  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 1712
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)

#include <vector>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;



struct UnionFind{
    vector<int> par;
    vector<int> rank;

    UnionFind(int N){
        for(int i=0;i<N;i++){
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]) par[x]=y;
        else {
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
};

int cost(int N,ll *x,ll *y,ll p, ll q){
    UnionFind T(N);
    ll pp,qq;
    rep(i,N){
        rep(j,N-i-1){
            pp=x[i]-x[i+j+1];
            qq=y[i]-y[i+j+1];
            if(pp==p && qq==q) T.unite(i,i+j+1);
            else if(pp==-p && qq==-q) T.unite(i,i+j+1);
        }
    }
    int ans=0;
    rep(i,N){
        if(T.par[i]==i) ans++;
    }
    return ans;
}

int main(){
    int N;
    ll x[50],y[50];
    cin>>N;
    rep(i,N) cin>>x[i]>>y[i];
    ll p,q,g;
    int ans=N;
    rep(i,N){
        rep(j,N-i-1){
            p=x[i]-x[i+j+1];
            q=y[i]-y[i+j+1];
            ans=min(ans,cost(N,x,y,p,q));
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

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

int main() {
    ll a,b,x;
    cin >> a >> b >> x;

    if(a%x==0 || b%x==0){
        cout << (b-a)/x+1 << endl;
        return 0;
    }

    if(a/x==b/x){
        cout << 0 << endl;
        return 0;
    }

    a = a/x+1;
    b = b/x;
    cout << b-a+1 << endl;

    return 0;
}

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

struct edge{
    int from, to, cost;
};

bool find_negative_loop(int v, const vector<edge>& es){
    using Cost = int;

    vector<Cost> cost(v, 0);

    for(int i = 0 ; i < v ; ++i){
        for(auto e : es){
            if(cost[e.from] + e.cost < cost[e.to]){
                if(i == v - 1){
                    return true;
                }
                cost[e.to] = cost[e.from] + e.cost;
            }
        }
    }

    return false;
}

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

    vector<edge> es;
    for(int i = 0 ; i < m ; ++i){
        int a, b;
        cin >> a >> b;
        es.push_back({a - 1, b - 1, -1});
    }

    if(find_negative_loop(n, es)){
        cout << 0 << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint a, b, q;
    cin >> a >> b >> q;
    vector<lint> s(a), t(b), x(q);
    for (int i = 0; i < a; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i < b; ++i) {
        cin >> t[i];
    }
    for (int i = 0; i < q; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < q; ++i) {
        lint ret = 1e15;
        lint rs = -1, ls = -1, rt = -1, lt = -1;
        auto its = lower_bound(s.begin(), s.end(), x[i]);
        if (its != s.end())
            rs = *its;
        if (its != s.begin())
            ls = *prev(its);
        auto itt = lower_bound(t.begin(), t.end(), x[i]);
        if (itt != t.end())
            rt = *itt;
        if (itt != t.begin())
            lt = *prev(itt);
        if (ls != -1 && lt != -1) {
            chmin(ret, x[i] - min(ls, lt));
        }
        if (rs != -1 && rt != -1) {
            chmin(ret, max(rs, rt) - x[i]);
        }
        if (ls != -1 && rt != -1) {
            chmin(ret, min(x[i] - ls, rt - x[i]) + (rt - ls));
        }
        if (rs != -1 && lt != -1) {
            chmin(ret, min(x[i] - lt, rs - x[i]) + (rs - lt));
        }
        cout << ret << "\n";
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const ll MAX = 1e9 + 1;

ll merge_cnt(vector<ll>& a) {
  ll n = a.size();
  if (n <= 1) return 0;

  ll cnt = 0;
  vector<ll> b(a.begin(), a.begin() + n / 2);
  vector<ll> c(a.begin() + n / 2, a.end());

  cnt += merge_cnt(b);
  cnt += merge_cnt(c);

  ll ai = 0, bi = 0, ci = 0;
  while (ai < n) {
    if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
      a[ai++] = b[bi++];
    }
    else {
      cnt += n / 2 - bi;
      a[ai++] = c[ci++];
    }
  }
  return cnt;
}

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

  ll left = 1, right = MAX, cnt = (n * (n + 1) / 2 + 1) / 2;
  while (right - left > 1) {
    ll mid = (left + right) / 2;
    vector<ll> s(n + 1, 0);
    rep(i, n) {
      s[i + 1] += s[i];
      if (a[i] >= mid) s[i + 1]++;
      else s[i + 1]--;
    }
    ll res = n * (n + 1) / 2 - merge_cnt(s);
    if (res >= cnt) left = mid;
    else right = mid;
  }
  cout << left << endl;


  
  return 0;
}

Measured memory_bytes: 3424
n = int(input())
if n == 1 or n == 2:
    print(n)
    exit()

now = 0
ans = []
for i in range(1, n):
    now += i
    ans.append(i)
    if now >= n:
        break

amari = now - n

for i in ans:
    if i == amari:
        continue
    else:
        print(i)


Measured memory_bytes: 9072
while True:

    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if i == 0 or i == H-1 or k == 0 or k == W-1:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print() 



Measured memory_bytes: 7000
L=[0]*4
while True:
    a,b,c=sorted(map(int,raw_input().split()))
    if a+b<=c:
        print " ".join(map(str,L))
        break
    if a*a+b*b==c*c:
        L[1]+=1
    elif a*a+b*b>c*c:
        L[2]+=1
    else:
        L[3]+=1
    L[0]+=1

Measured memory_bytes: 4232
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int month = Integer.parseInt(sc.next().substring(5,7));

        if(month <= 4) {
            System.out.println("Heisei");
        } else {
            System.out.println("TBD");
        }

    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  prllf("%d",x);
#define pl(x)  prllf("%lld",x);
#define pf(x)  prllf("%.10lf",x);
#define ps(x)  prllf("%s",x);
#define en() prllf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define mod 100000007
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}
bool visprime[10000000];
vector<ll>prime;
void sieve(){ll k=0;for(ll i=2;i*i<=1000000;i++){for(ll j=i*i;j<=1000000;j+=i){visprime[j]=true;}}for(ll i=2;i<=1000000;i++){if(visprime[i]==false) prime.pb(i);}}


bool vis[100000+10];
int main()
{

 string x;
 cin>>x;
 int cnt=0;
  for(int i=0,j=x.size()-1;i<=j;i++,j--)
 {
     if(x[i]!=x[j]) cnt++;
 }
 cout<<cnt<<endl;



}

















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

using namespace std;
int n, k;
int a[400000], fp[400000], fs[400000];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    int g = a[1];
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
        g = __gcd(g, a[i]);
        fp[i] = g;
    }
    if (n == 1 && a[1] == k) {
        cout << "POSSIBLE\n";
        return 0;
    }
    else
    if (n == 1) {
        cout << "IMPOSSIBLE\n";
        return 0;
    }
    g = a[n];
    for (int i = n; i >= 1; i--) {
        g = __gcd(g, a[i]);
        fs[i] = g;
    }
    for (int i = 1; i <= n; i++) {
        if (a[i] < k) continue;
        int g = __gcd(fp[i - 1], fs[i + 1]);
        if (a[i] % g == k % g) {
            cout << "POSSIBLE\n";
            return 0;
        }
    }
    cout << "IMPOSSIBLE\n";
    return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int s = 0, cnt = 0;
  string X;
  cin >> X;
  for (int i = 0; i < X.size(); i++) {
    if (X[i] == 'S') {
      s++;
    } else if (s) {
      s--;
      cnt += 2;
    }
  }
  cout << X.size() - cnt << '\n';
  return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

int main(){
  lli n;
  const int maxi = 1e5;
  while(std::cin >> n, n != -1){
    vector<int> digit(100000, 0);
    for (int i = 0; i < n; i++) {
      int p = 0;
      digit[0]++;
      while(digit[p] == 4){
        digit[p] = 0;
        digit[p + 1]++;
        p++;
      }
    }
    bool flag = true;
    for (int i = maxi - 1; i >= 0; i--) {
      if(digit[i] == 0 and flag)continue;
      flag = false;
      std::cout << digit[i];
    }
    if(flag == true)std::cout << 0 << std::endl;
    else std::cout << std::endl;
  }
    
  return 0;
}

Measured memory_bytes: 1584
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(; sc.hasNext();){
			String[] s=sc.next().split(",");
			int id=Integer.parseInt(s[0]);
			double w=Double.parseDouble(s[1]);
			double h=Double.parseDouble(s[2]);
			double bmi=w/h/h;
			if(bmi>25-EPS)
				println(id+"");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define modulo 1000000007
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;


int main() {
	int n,d;
	cin >> n >> d;

	cout << ceil(n/(2.*d+1)) << endl;

	return 0;
}

Measured memory_bytes: 256
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int dp[2005][2005],fact[4000005],inv[4000005];
inline int C(int nn,int mm){
	return (ll)fact[nn]*inv[mm]%mod*inv[nn-mm]%mod;
}
inline void add(int &x,int y){
	x+=y;if(x>=mod)x-=mod;
}
int main(){
	fact[0]=1;
	for(int i=1;i<=4e6;i++)fact[i]=(ll)fact[i-1]*i%mod;
	inv[4000000]=modpow(fact[4000000],mod-2);
	for(int i=4e6-1;i>=0;i--)inv[i]=(ll)inv[i+1]*(i+1)%mod;
	int n,k;cin>>n>>k;
	if(k==1){
		puts("1");
		return 0;
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			dp[i][j]=(dp[i-1][j]+(!j?0ll:1ll*dp[i][j-1]*C(n-i+n-j+(n-j+1)*(k-2),k-2)%mod))%mod;
//			cerr<<i<<" "<<j<<" "<<dp[i][j]<<endl;
		}
	}
	cout<<(ll)dp[n][n]*fact[n]%mod<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}
vector<ll> vectorprime(ll x){
	vector<bool> is_prime(x+1);
	vector<ll> prime;
	rep(i,x+1) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=x;i++){
		if(is_prime[i]){
			prime.pb(i);
		}
		for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
	}
	return prime;
}

//a,b x
int main(){
	rep1(i,50) pw2[i]=2*pw2[i-1];
	ll A,B,C,K; cin>>A>>B>>C>>K;
	ll D=maxx(A,B,C);
	ll tmp=A+B+C-D;
	D*=pw2[K];
	cout<<tmp+D;
}

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

int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if((r<=x && x<=w-r) && (r<=y && y<=h-r)) printf("Yes\n");
    else printf("No\n");
}



Measured memory_bytes: 3100
//
//  main.c
//  abc060_c
//
//  Created by Ding Chao on 4/29/17.
//  Copyright © 2017 Ding Chao. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int N, T;
    scanf("%d%d", &N, &T);
//    int remain = 0;
    int this, next;
    scanf("%d", &this);
    long long total = T;
    for (int i = 0; i < N - 1; i++) {
        scanf("%d", &next);
        int diff = next - this;
        if (diff > T)
            total += T;
        else
            total += diff;
        this = next;
    }
    
    printf("%lld\n", total);
    return 0;
}


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

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

    int ans;
    for(int i = 1; i <= 3; i++)
    {
        if(a != i && b != i)
        {
            ans = i;
            break;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int X,Y,Z;
    cin >> X >> Y >> Z;
    X = X - Z;
    int human = Y+Z;
    int c = 0;
    while(X>=0){
        X -= human;
        c++;
    }
    cout << c-1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  string t; cin >> t;
  set<char> S;
  rep(i,t.size()) S.insert(t[i]);

  int retval = 1000;
  for (auto s:S){
    vector<int> a;
    int cnt = 0;
    rep(i,t.size()){
      if (t[i]!=s) cnt++;
      else {
        a.push_back(cnt);
        cnt = 0;
      }

      if (i==t.size()-1 && cnt>0) a.push_back(cnt);
    }
    retval = min(*max_element(all(a)), retval);
  }
  cout << retval << endl;



  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 256
# 数値の取得
last,fee,cur = map(int,input().split())
feesqu = list(map(int,input().split()))
total = len(feesqu)

# コストの最小値を出力
tcost = 0
gcost = 0
for cnt in range(0,total,1):
    if feesqu[cnt] < cur:
        tcost += 1
gcost = total - tcost
print(min(tcost,gcost))

Measured memory_bytes: 8980
#include<bits/stdc++.h>
using namespace std;
int gcd(long long x, long long y){
    if(x<y) {
        long long t=x;
        x=y;
        y=t;
    }
    while(y>0){
        long long r=x%y;
        x=y;
        y=r;
    }
    return x;
}
int main(){
    long long x, y;
    cin >> x >> y;
    
    cout << gcd(x, y) << endl;
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define debug(x)                 cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define debug2(x, y)             cerr << __LINE__ << #x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define debug3(x, y, z)          cerr << __LINE__ << #x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug4(a, b, c, d)       cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define debug5(a, b, c, d, e)    cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define debug6(a, b, c, d, e, f) cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define INF 999999999
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  int n;cin>>n;
  int a[n];

  int c = 0;
  rep(i,n){
    int tmp;
    cin >> tmp;
    while (true){
      if (tmp%2==0){
        tmp /= 2;
        c += 1;
      }
      else{
        break;
      }
    }
  }

  cout << c << endl;


  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n + 1);
    vector<long long> b(n);
    long long bef = 0;
    long long af = 0;


    for (auto i = 0; i < n + 1; i++)
    {
        long long ai;
        cin >> ai;
        a[i] = ai;
    }

    for (auto i = 0; i < n; i++)
    {
        long long bi;
        cin >> bi;
        b[i] = bi;
    }


    for (auto i = 0; i < n+1; i++)
    {
        bef += a[i];
    }
    

    for (auto i = 0; i < n; i++)
    {

        if (a[i] >= b[i])
        {
            a[i] -= b[i];
        }
        else 
        {
            long long tmp = b[i] - a[i];
            a[i] = 0;
            if(a[i+1] >= tmp){
                a[i + 1] -= tmp;
            }else{
                a[i + 1] = 0;
            }
        }
    }

    for (auto i = 0; i < n+1; i++)
    {
        af += a[i];
    }

    cout << bef - af << endl;
  
    
}

Measured memory_bytes: 1792