akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
const LL mod=1e9+7,inf=1LL<<60;
struct Node{
	LL x,y,c,next;
}a[400010];LL len=0,last[100010];
LL n,m,st,ed,f[2][100010];
struct node{
	LL x,d;
	node() {}
	node(LL a,LL b) {x=a;d=b;}
};
bool operator < (node a,node b) {return a.d>b.d;}
priority_queue<node> q;
void ins(LL x,LL y,LL c)
{
	a[++len].x=x;a[len].y=y;a[len].c=c;
	a[len].next=last[x];last[x]=len;
}
bool vis[100010];
LL dis[2][100010];
void dij(LL op,LL st)
{
	for(LL i=1;i<=n;i++) dis[op][i]=inf;
	memset(vis,false,sizeof(vis));
	dis[op][st]=0;q.push(node(st,0));
	while(!q.empty())
	{
		LL x=q.top().x;q.pop();
		if(vis[x]) continue;
		vis[x]=true;
		for(LL i=last[x];i;i=a[i].next)
		{
			LL y=a[i].y;
			if(dis[op][y]>dis[op][x]+a[i].c)
			{
				dis[op][y]=dis[op][x]+a[i].c;
				q.push(node(y,dis[op][y]));
			}
		}
	}
}
void solve(LL op,LL st)
{
	memset(vis,false,sizeof(vis));
	f[op][st]=1;
	q.push(node(st,dis[op][st]));
	while(!q.empty())
	{
		LL x=q.top().x;q.pop();
		if(vis[x]) continue;
		vis[x]=true;
		for(LL i=last[x];i;i=a[i].next)
		{
			LL y=a[i].y;
			if(dis[op][x]+a[i].c==dis[op][y])
			{
				(f[op][y]+=f[op][x])%=mod;
				q.push(node(y,dis[op][y]));
			}
		}
	}
}
LL get(LL x,LL y) {return f[0][x]*f[0][x]%mod*f[1][y]%mod*f[1][y]%mod;}
int main()
{
	scanf("%lld %lld %lld %lld",&n,&m,&st,&ed);
	for(LL i=1;i<=m;i++)
	{
		LL x,y,c;scanf("%lld %lld %lld",&x,&y,&c);
		ins(x,y,c);ins(y,x,c);
	}
	dij(0,st);dij(1,ed);
	solve(0,st);solve(1,ed);
	LL ans=f[0][ed]*f[1][st]%mod;
	/*printf("0:");for(int i=1;i<=n;i++) printf("%lld ",dis[0][i]);printf("\n");
	printf("1:");for(int i=1;i<=n;i++) printf("%lld ",dis[1][i]);printf("\n");
	printf("0:");for(int i=1;i<=n;i++) printf("%lld ",f[0][i]);printf("\n");
	printf("1:");for(int i=1;i<=n;i++) printf("%lld ",f[1][i]);printf("\n");
	printf("%lld\n",ans);*/
	for(int i=1;i<=n;i++) if(dis[0][i]==dis[1][i]&&dis[0][i]+dis[1][i]==dis[0][ed]) (ans-=get(i,i))%=mod;
	//printf("%lld\n",ans);
	for(LL i=1;i<=len;i+=2)
	{
		LL x=a[i].x,y=a[i].y;
		if(dis[0][x]>dis[0][y]) swap(x,y);
		if(dis[0][x]+dis[1][y]+a[i].c==dis[0][ed])
		{
			//printf("x y %lld %lld %lld %lld %lld\n",x,y,dis[0][x],dis[1][y],a[i].c);
			if(abs(dis[0][x]-dis[1][y])<a[i].c) (ans-=get(x,y))%=mod;
		}
	}
	printf("%lld",(ans+mod)%mod);
}

Measured memory_bytes: 18416
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    #define int ll
    int n; cin >> n;
    int a[n], b[n];
    rep(i, n) cin >> a[i] >> b[i];
    Pint dish[n];
    rep(i, n) {
        dish[i].first = a[i] + b[i];
        dish[i].second = i;
    }
    int score_tak = 0, score_aok = 0;
    sort(dish, dish + n, greater<Pint>());
    rep(i, n) {
        if(i % 2 == 0) {
            score_tak += a[dish[i].second];
        }else {
            score_aok += b[dish[i].second];
        }
    }
    cout << score_tak - score_aok << endl;
}


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

signed main() {
	ll N, S;
	cin >> N >> S;
	vector<ll> A(N);
	for(auto &a : A) cin >> a;

	vector<vector<vector<ll>>> dp(N+1, vector<vector<ll>>(S+1, vector<ll>(3, 0)));
	dp[0][0][0] = 1;
	for(ll i=1;i<=N;i++) {
		for(ll j=0;j<=S;j++) {
			// i番目まで見た, 左端は決めていない
			dp[i][j][0] += dp[i-1][j][0];
			// i番目まで見た, 左端が決まっている
			dp[i][j][1] += dp[i-1][j][1];
			if(j >= A[i-1]) dp[i][j][1] += dp[i-1][j-A[i-1]][1];
			if(j >= A[i-1]) dp[i][j][1] += dp[i-1][j-A[i-1]][0] * i;

			dp[i][j][2] += dp[i-1][j][2];
			if(j >= A[i-1]) dp[i][j][2] += dp[i-1][j-A[i-1]][1] * (N - i + 1);
			if(j >= A[i-1]) dp[i][j][2] += dp[i-1][j-A[i-1]][0] * i * (N - i + 1);
			for(ll k=0;k<3;k++) dp[i][j][k] %= MOD;
		}
	}
	cout << dp[N][S][2] << endl;
}

Measured memory_bytes: 493056
import java.util.*;

public class Main {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String s = sc.next();

    	if (s.equals("Sunny")) {
    		System.out.println("Cloudy");
    	} else if (s.equals("Cloudy")) {
    		System.out.println("Rainy");
    	} else if (s.equals("Rainy")) {
    		System.out.println("Sunny");
    	}
	}
}


Measured memory_bytes: 19924
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int n;
  cin >> n;
  vector<ll> l(n+1);
  l[0] = 2;
  l[1] = 1;
  for (int i = 2; i <= n; i++) {
    l[i] = l[i-1] + l[i-2];
  }
  cout << l[n] << endl;
  return 0;
}


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

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> x.at(i);
  }
  int sum = 0;
  for(i = 0; i < n; i++)
  {
    sum += min(x.at(i), k-x.at(i));
  }
  cout << sum*2 << endl;
}

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

using namespace std;
//using namespace __gnu_pbds;

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const int64_t INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if (s.back() == 's') {
        s += "es";
    } else {
        s += "s";
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 3616
N,X=list(map(int,input().split()))
a,p=[1],[1]
for i in range(N):
   a.append(a[i]*2+3)
   p.append(p[i]*2+1)
def ans(N,X):
   if N==0:
      return 0 if X<=0 else 1
   elif X<=1+a[N-1]:
      return ans(N-1,X-1)
   else:
      return p[N-1]+1+ans(N-1,X-2-a[N-1])
print(ans(N,X))

Measured memory_bytes: 9128
H, N = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

dp = [float('inf') for _ in range(H + 1)]
dp[H] = 0

for i in range(H+1)[::-1]:
    for j in range(N):
        if i - A[j] >= 0:
            dp[i - A[j]] = min(dp[i] + B[j], dp[i - A[j]])
        else:
            dp[0] = min(dp[i] + B[j], dp[0])

print(dp[0])


Measured memory_bytes: 43356
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<ll, int> pli;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<pli> v;
	rep(i,a) {
		ll t;
		cin >> t;
		v.push_back(pli(t, 0));
	}
	rep(i,b) {
		ll t;
		cin >> t;
		v.push_back(pli(t, 1));
	}
	rep(i,c) {
		ll t;
		cin >> t;
		v.push_back(pli(t, 2));
	}
	sort(ALL(v), greater<>());
	int cnt0 = 0;
	int cnt1 = 0;
	int cnt2 = 0;
	int i = 0;
	ll ans = 0;
	while (cnt0 + cnt1 + cnt2 < x + y) {
		auto p = v[i++];
		if (cnt0 < x && p.second == 0) {
			ans += p.first;
			cnt0++;
		} else if (cnt1 < y && p.second == 1) {
			ans += p.first;
			cnt1++;
		} else if (p.second == 2) {
			ans += p.first;
			cnt2++;
		}
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 11576
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    double sum=0;
    rep(i,N) {
        double n;
        string s;
        cin>>n>>s;
        if(s=="JPY") sum+=n;
        else sum+=n*380000.0;
    }
    cout<<fixed<<setprecision(10);
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
string a, b;
cin>>a>>b;
int na = a.size(), nb = b.size();
if(nb - na != 1){
    cout<<"No";
    return 0;
}
for(int i = 0; i < na; i++){
    if(a[i] != b[i]){
        cout<<"No";
        return 0; 
    }
}
cout<<"Yes";
return 0;    
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define ll long long
#define int long long
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define mod 1000000007
typedef pair<ll,ll> pll;
#define F first
#define S second
#define printer(v) for(auto f: v) cout<<f<<" "
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define ipair pair<int,int>
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    // cout << setprecision(12) << fixed;
    int n; cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin>>v[i];
    unordered_map<int,int> m;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		m[v[i]+i]++;
		ans += m[i-v[i]];
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 20124
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

std::string s1, s2;
int dp[1001][1001];

int main()
{
  std::cin >> s1 >> s2;

  rep( i, s1.size()+1 )
    dp[i][0] = i;
  rep( j, s2.size()+1 )
    dp[0][j] = j;

  repi( i, 1, s1.size()+1 ) repi( j, 1, s2.size()+1 )
    dp[i][j] = std::min( dp[i-1][j-1]+(s1[i-1]!=s2[j-1]), std::min( dp[i-1][j]+1, dp[i][j-1]+1 ) );

  std::cout << dp[s1.size()][s2.size()] << std::endl;

  return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    long long a[n+1];
    a[0] = 0;
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i-1]+1 < a[i]){
            ans = -1;
            break;
        }
        if(a[i-1]+1 == a[i]) ans++;
        else ans += a[i];
    }
    if(a[1] != 0) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i<n;i++){
        cin >> a[i];
    }
    long ans = 1e9+7;
    for(int i = -100;i<=100;i++){
        long tmp = 0;
        for(int j = 0;j<n;j++){
            tmp+=pow(a[j]-i,2);
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = 1; i <= (int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vi v(n);
    rep(i,n) cin >> v[i];
    sort(all(v));
    int ans = 0;
    rep(i,n) {
        rep(j,i) {
            int sum = v[i] + v[j];
            int a = lower_bound(all(v),sum) - v.begin();
            int b = i + 1;
            ans += a - b;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
BIG_NUM = 2000000000
 
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+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
 
    print()


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

int main(){
    int N, type, i;
    long long X;
    string u, l;
    cin >> N >> u >> l;
    if(u[0] == l[0]){
        type = 1;
        X = 3;
        i = 1;
    }
    else{
        type = 2;
        X = 6;
        i = 2;
    }
    while(i < N){
        if(u[i] == l[i]){
            if(type == 1){
                X *= 2;
            }
        type = 1;
        i++;
        }
        else{
            if(type == 1){
                X *= 2;
            }else{
                X *= 3;
            }
        type = 2;
        i = i + 2;
        }
        if(X > 1000000007) X -= 1000000007;
    }
    cout << X << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class T>
struct SegmentTree {
    SegmentTree(int n) : n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<T>(m + n + n % 2);
    }
    T &operator[](int i) {
        return t[m + i];
    }
    const T &root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    void update(int i, const T &o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    T query(int l, int r) {
        T o0, o1;
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (l & 1) o0 = o0 * t[l++];
            if (r & 1) o1 = t[--r] * o1;
        }
        return o0 * o1;
    }
    vector<T> t;
    int n, m;
};
struct Max {
    constexpr Max() : v(-1) {}
    Max(int v) : v(v) {}
    Max operator*(const Max &o) const {
        return max(v, o.v);
    }
    int v;
};

struct P {
    bool operator<(const P &p) const {
        return g > p.g;
    }
    int k, g;
};

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

    int T;
    cin >> T;

    while (T--) {
        int n;
        cin >> n;

        ll s = 0;
        vector<P> p[2];
        for (int i = 0; i < n; i++) {
            int k, l, r;
            cin >> k >> l >> r;
            s += min(l, r);
            int g = l - r;
            p[g < 0].push_back({ (g < 0 ? n - k : k), abs(g) });
        }
        for (int h = 0; h < 2; h++) {
            sort(p[h].begin(), p[h].end());
            int m = p[h].size();
            SegmentTree<Max> st(n);
            for (int i = 0; i < m; i++) {
                st[i] = i;
            }
            st.build();
            for (int i = 0; i < m; i++) {
                int j = st.query(0, p[h][i].k).v;
                if (j < 0) continue;
                st.update(j, { -1 });
                s += p[h][i].g;
            }
        }
        cout << s << '\n';
    }

    //1番目しかダメなやつが3人いたらL-R L>Rとは限らないのか...
    //Lがいい人とRがいい人で分ける
    //1番がいい人が複数いたらL-Rの高い人がとる
    //3番まで争いが起こらなかったら、L-Rの高い順に3人（ここまで3位以内じゃないと意味ない人だけだから）
    //でも、4位争いにL-Rの高い人が大量にいたらダメじゃん
    //争いが起こる右端で、100人しか入れないけど110人いるとき10人をどう選ぶ
    //各位置についてそれより左に入りたい人の数と入れる人の数がわかる。あぶれる人の数がわかる。
    //もう貪欲にL-Rの大きい人から入っていっていいのでは？その人は誰とswapしても改善しない

    //F
    //N個の玉があり仕切りを10個入れる 違うね 2番目のやつは最初から1持ってるとして
    //各ブロックは1個以上ならよい k個あったら 差が2だったら


    return 0;
}

Measured memory_bytes: 6716
import java.util.Scanner;

public class Main {
    int n, q;
    Query[] qs;

    public static void main(String[] args) {
        Main p = new Main();
        p.read();
        p.solve();
    }

    void read() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        q = sc.nextInt();
        qs = new Query[q];

        for (int i = 0; i < q; i++) {
            int c = sc.nextInt();
            int a = sc.nextInt();
            int b = sc.nextInt();
            qs[i] = new Query(c, a, b);
        }
    }

    void solve() {
        SegmentTree tree = new SegmentTree(n);
        for (Query query: qs) {
            if (query.com == 0) {
                tree.add(query.x, query.y);
            }
            else {
                int ans = tree.query(query.x, query.y+1,
                        0, 0, tree.n);
                System.out.println(ans);
            }
        }
    }

    private class SegmentTree {
        int n;
        int[] tree;

        SegmentTree(int a) {
            for (n = 1; n <= a; n = n << 1) {}
            tree = new int[2 * n - 1];
        }

        void add(int i, int x) {
            i += n - 1;
            tree[i] += x;
            while (i > 0) {
                i = (i - 1) / 2;
                tree[i] = tree[2 * i + 1] + tree[2 * i + 2];
            }
        }

        int query(int s, int e, int k, int l, int r) {
            if (r <= s || e <= l) return 0;
            if (s <= l && r <= e) return tree[k];

            int vl = query(s, e, 2 * k + 1, l, (r + l) / 2);
            int vr = query(s, e, 2 * k + 2, (r + l) / 2, r);
            return vl + vr;
        }
    }

    private class Query {
        int com, x, y;
        Query(int c, int a, int b) {
            com = c;
            x = a;
            y = b;
        }
    }
}

Measured memory_bytes: 108404
#include <iomanip>
#include <iostream>
using namespace std;
int K, L, R; double P, E, T;
inline double solve(double l, double r, int d) {
	double v = (l + r) / 2;
	if (d == K) return ((T - E <= v && v < T + E) ? 1.0 : 0.0);
	if (v < T) return solve(l, (l + r) / 2, d + 1) * P + solve((l + r) / 2, r, d + 1) * (1.0 - P);
	return solve(l, (l + r) / 2, d + 1) * (1.0 - P) + solve((l + r) / 2, r, d + 1) * P;
}
int main() {
	cin >> K >> L >> R >> P >> E >> T;
	cout << fixed << setprecision(15) << solve(L, R, 0) << endl;
	return 0;
}

Measured memory_bytes: 3284
# ABC 155 B
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A)

a_even = A[A%2==0]
bool1 = a_even%3 == 0
bool2 = a_even%5 == 0
bool3 = np.sum(bool1+bool2) == len(a_even)
if bool3:
    ans = 'APPROVED'
else:
    ans = 'DENIED'
print(ans)

Measured memory_bytes: 12508
from math import hypot, atan2

N = int(input())
engines = [tuple(map(int, input().split())) for _ in range(N)]

engines.sort(key=lambda z: atan2(z[1], z[0]))

ans = 0
for L in range(N):
    for R in range(N):
        if L <= R:
            x, y = map(sum, zip(*engines[L:R+1]))
        else:
            x, y = map(sum, zip(*(engines[:R+1]+engines[L:])))
        dist = hypot(x, y)
        ans = max(ans, dist)

print(ans)


Measured memory_bytes: 3316
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
INF = float("inf")


def solve(N: int):
    ans = []
    kari = 0
    p = 1                       # 基数
    for i in range(40):
        c = N & 1               # 最下位bit
        if c == ((kari >> i) & 1):
            ans.append(0)
        else:
            ans.append(1)
            kari += p
        N >>= 1
        p *= -2

    if 1 in ans:
        i = ans[::-1].index(1)
        print(*ans[::-1][i:], sep="")
    else:
        print(0)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4192
using System;
using System.Collections.Generic;
using System.Linq;

class ABC124C{
    public static void Main(){
        var Sin = Console.ReadLine();
        var S = new List<bool>();
        foreach(var s in Sin.ToCharArray()){
            S.Add(s=='1');
        }
        var r1 = new List<bool>();
        var r2 = new List<bool>();
        for(int i = 0;i<Sin.Length;i++){
            r1.Add((i%2==0) ^ S[i]);
            r2.Add((i%2==1) ^ S[i]);
        }
        Console.WriteLine(r1.FindAll(x=>x).Count<r2.FindAll(x=>x).Count?r1.FindAll(x=>x).Count:r2.FindAll(x=>x).Count);
    }
}

Measured memory_bytes: 13180
let insertion_sort a n g =
  let rec iloop i c =
    if i = n then c
    else let v = a.(i) in
         let rec jloop j c' =
           if j < 0 || a.(j) <= v then begin
               a.(j+g) <- v;
               iloop (i+1) (c+c')
             end
           else begin
               a.(j+g) <- a.(j);
               jloop (j-g) (c'+1)
             end
         in jloop (i-g) 0
  in iloop g 0

let shell_sort a n =
  let rec initg l =
    let h = List.hd l in
    let nh = 3 * h + 1 in
    if nh >= n then l
    else initg (nh::l) 
  in
  let gl = initg [1] in
  let m = List.length gl in
  let rec iter c = function
      [] -> c
    | g :: gs -> let d = insertion_sort a n g in iter (c+d) gs in
  let cnt = iter 0 gl in
  (m, gl, cnt)
        
let () =
  let n = read_int () in
  let ar = Array.init n (fun _ -> read_int ()) in
  let (m, gl, cnt) = shell_sort ar n in
  string_of_int m |> print_endline;
  List.map string_of_int gl |> String.concat " " |> print_endline;
  string_of_int cnt |> print_endline;
  Array.iter (fun v -> string_of_int v |> print_endline) ar

Measured memory_bytes: 12284
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,W; cin >> n >> W;
    vvl v(4);
    ll mn = 0;
    rep(i,n){
        ll a,b; cin >> a >> b;
        if(i==0) mn = a;
        v[a-mn].push_back(b);
    }
    rep(i,4) sort(rall(v[i]));
    rep(i,4){
        rep(j,(ll)v[i].size()-1){
            v[i][j+1] += v[i][j]; 
        }
    }
    ll ans = 0;
    rep(i,v[0].size()+1){
        rep(j,v[1].size()+1){
            rep(k,v[2].size()+1){
                rep(l,v[3].size()+1){
                    if(i*mn + j*(mn+1) + k*(mn+2) + l*(mn+3) > W) continue;
                    else{
                        ll sum = 0;
                        if(i!=0) sum += v[0][i-1];
                        if(j!=0) sum += v[1][j-1];
                        if(k!=0) sum += v[2][k-1];
                        if(l!=0) sum += v[3][l-1];
                        ans = max(ans, sum);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

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

char next(char c,int n)
{
	if(c=='?') return c;
	c+=n%26;
	if(c<'A') c+=26;
	if(c>'Z') c-=26;
	return c;
}

string cip(const string& s,int& i);
string str(const string& s,int& i);
string let(const string& s,int& i);

string cip(const string& s,int& i)
{
	string t=str(s,i);
	while(i<s.size() && s[i]!=']')
		t+=str(s,i);
	return t;
}

string str(const string& s,int& i)
{
	if(s[i]=='['){
		string t=cip(s,++i);
		reverse(begin(t),end(t));
		i++;
		return t;
	}
	return let(s,i);
}

string let(const string& s,int& i)
{
	if(s[i]=='+' || s[i]=='-'){
		char op=s[i];
		string t=let(s,++i);
		if(op=='+') t[0]=next(t[0],1);
		if(op=='-') t[0]=next(t[0],-1);
		return t;
	}
	return s.substr(i++,1);
}

int main()
{
	for(string s;cin>>s && s!=".";){
		int i=0;
		string t=cip(s,i);
		replace(begin(t),end(t),'?','A');
		cout<<t<<endl;
	}
}

Measured memory_bytes: 1196
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int

using namespace std;


int main() {
	speed;
	string s;

	cin >> s;

	bool flag = true;

	for (int i = 0; i < 3; i++) {
		if (s[i] == s[i + 1])flag = false;
	}
	if (flag)cout << "Good";
	else {
		cout << "Bad";
	}
	ed;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x),b(y),c(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    sort(a.begin(),a.end(),greater<ll>());
    sort(b.begin(),b.end(),greater<ll>());
    sort(c.begin(),c.end(),greater<ll>());
    priority_queue<ll> que;
    rep(i, x) {
        rep(j, y) {
            que.push(a[i]+b[j]);
        }
    }
    priority_queue<ll> que2;
    for(int i=0;i<k&&!que.empty();i++) {
        ll tmp = que.top();
        que.pop();
        rep(j, z) {
            que2.push(tmp+c[j]);
        }
    }
    for(int i=0;i<k;i++) {
        ll ans = que2.top();
        que2.pop();
        cout << ans << endl;
    }
}


Measured memory_bytes: 43448
n, m = map(int, input().split())
p_li, s_li = [], []
for _ in range(m):
    p, s = input().split()
    p_li.append(int(p))
    s_li.append(s)

ac = [0] * n
wa = [0] * n
for i in range(m):
    p, s = p_li[i] - 1, s_li[i]
    if s == 'AC':
        ac[p] += 1
    elif ac[p] == 0:
        wa[p] += 1
    else:
        continue
n_ac, n_wa = 0, 0
for i in range(n):
    if ac[i] != 0:
        n_ac += 1
        n_wa += wa[i]
print('{} {}'.format(n_ac, n_wa))

Measured memory_bytes: 60888
N = int(input())
A = list(map(int, input().split()))
s = [0 for i in range(N)]
for i in range(N):
  a = A[i]
  while a%2 == 0:
    if a%2 == 0:
      a = a//2
      s[i] += 1
      
s.sort()
ans = s[0]
print(ans)
      
    

Measured memory_bytes: 3060
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

n = int(input())
a = pow(9, n, MOD)
b = pow(8, n, MOD)
c = pow(10, n, MOD)

print((c - 2 * a + b)%MOD)

Measured memory_bytes: 68076
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int cnt[3] = {};//4 2 1;
    rep(i,0,N){
        int a;
        cin >> a;
        if(a % 4 == 0)cnt[0]++;
        else if(a % 2 == 0)cnt[1]++;
        else cnt[2]++;
    }
    cnt[2] += cnt[1] != 0;
    if(cnt[1] == N || cnt[0]+1 >= cnt[2])cout << "Yes" << endl;
    else cout << "No" << endl;
}

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


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || b + c == a || c + a == b)
		cout << "Yes";
	else
		cout << "No";
}


Measured memory_bytes: 256
from scipy.sparse import*;f=lambda*z:map(int,raw_input().split());d=lambda s:csgraph.dijkstra(csr_matrix(([1]*len(a),(a,b)),[n+1]*2),0,s);n,=f();a,b=zip(*map(f,[0]*~-n));g=d(1);h=d(n);print['Snuke','Fennec'][sum(g[i]>h[i] for i in range(n+1))*2<n]

Measured memory_bytes: 37732
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int D, N;
    cin >> D >> N;
    int ans;
    if(N == 100){
        N = 101;
    }
    if(D==0){
        ans = N;
    }else if (D==1){
        ans = N * 100;
    }else{
        ans = N *10000;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int x[][] = new int[n][3];
		int y[][] = new int[n][3];

		for(int i=0; i<n; i++){
			for(int k=0; k<3; k++){
				x[i][k] = s.nextInt();
			}
		}
		for(int i=0; i<3; i++){
			for(int k=0; k<n; k++){
				for(int e=0; e<n; e++){
					if(k != e){
						if(x[k][i] == x[e][i]){
							y[k][i] = 0;
							break;
						}
						else		y[k][i] = x[k][i];
					}
				}
			}
		}

		for(int i=1; i<3; i++){
			for(int k=0; k<n; k++){
				y[k][0] += y[k][i];
			}
		}
		for(int i=0; i<n; i++){
		System.out.println(y[i][0]);
		}
	}
}

Measured memory_bytes: 20980
x = input()
if x == "SSS":
    print(0)

elif x == "SSR":
    print(1)

elif x == "SRS":
    print(1)

elif x == "RSS":
    print(1)

elif x == "RSR":
    print(1)

elif x == "RRS":
    print(2)

elif x == "SRR":
    print(2)

else:
    print(3)

Measured memory_bytes: 9096
from sys import stdin


def main():
    h = next_int()
    w = next_int()

    c = [input() for _ in range(h)]

    for i in range(h):
        for j in range(2):
            print(c[i])


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
from sys import setrecursionlimit

setrecursionlimit(3 * 10 ** 5)

def main():
  n, m, k = map(int, input().split(' '))
  nodes = tuple([([], set()) for i in range(n)])
  for _ in range(m):
    a, b = sorted(map(lambda x: int(x) - 1, input().split()))
    nodes[a][0].append(b)
    nodes[b][0].append(a)

  for _ in range(k):
    c, d = sorted(map(lambda x: int(x) - 1, input().split()))
    nodes[c][1].add(d)
    nodes[d][1].add(c)

  total_done_set = set()

  def dfs(node_id, done_set):
    if node_id in done_set: return 0

    total_done_set.add(node_id)
    done_set.add(node_id)

    size = 1
    for child_id in nodes[node_id][0]:
      size += dfs(child_id, done_set)

    return size


  ans_list = [-1] * n

  def dfs2(node_id, connected_ids, total_len):
    children, block_id_set = nodes[node_id]
    ans_list[node_id] = total_len - len(list(filter(
      lambda block_id: block_id in connected_ids, block_id_set
    ))) - 1

    except_num = 0
    for child_id in children:
      if child_id not in block_id_set:
        except_num += 1

      if ans_list[child_id] == -1:
        dfs2(child_id, connected_ids, total_len)

    ans_list[node_id] -= except_num


  for i in range(n):
    if i not in total_done_set:
      done_set = set()
      dfs(i, done_set)
      dfs2(i, done_set, len(done_set))

  print(*ans_list, sep=" ")


main()


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    ll A, B, K; cin >> A >> B >> K;
    if(K >= A){
        ll C = K-A;
        A = 0;
        if(B > C){
            B = B-C;
        }else{
            B = 0;
        }
    }else{
        A -= K;
    }
    printf("%lld %lld\n", A, B);
}

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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}

int main(){
  INT(l);
  vector<tuple<int, int, int>> gr;
  vector<int> ds = {0};
  int n = 0, m = 0, s = 0;
  while (s + (1 << n) < l){
    s += (1 << n);
    gr.EB(n + 1, n + 2, 0);
    gr.EB(n + 1, n + 2, 1 << n);
    ds.PB(s);
    n++; m += 2;
  } n++;
  int r = l - 1 - s, w = l - 1;
  REP(i, n - 1){
    if ((r >> i) & 1){
      gr.EB(i + 1, n, w - ds[i]);
      m++;
      w -= ds[i] + 1;
    }
  }
  sort(gr.begin(), gr.end());
  printf("%d %d\n", n, m);
  for(auto tpl: gr){
    int u, v, w; tie(u, v, w) = tpl;
    printf("%d %d %d\n", u, v, w);
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a1,a2,a3;
  scanf("%d",&a1);
  scanf("%d",&a2);
  scanf("%d",&a3);
  if((a1+a2+a3)>= 22)
    printf("bust");
  else
    printf("win");
  return 0;
}

Measured memory_bytes: 128
n,m = list(map(int,input().split()))
from collections import defaultdict
 
dc = defaultdict(list)
for i in range(m):
    a,b = list(map(int,input().split()))
    dc[a].append(b)
    dc[b].append(a)

ans = 0
from itertools import permutations
comb = list(permutations(range(2,n+1),n-1))
for c in comb:
    flag = True
    targets = list(c)
    # print(c)
    if not 1 in dc[targets[0]]:
        flag = False
    for i in range(len(targets)-1):
        a,b = targets[i],targets[i+1]
        if not b in dc[a]:
            flag = False
            break
    if flag:
        # print(c," is ok")
        ans += 1

print(ans)

Measured memory_bytes: 3820
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>;


using namespace std;



int main() {
    string str;
    int num[26] = {};
    while (getline(cin,str)) {
        for (int i = 0; i < str.size(); i++) {
            if (str[i] >= 'a' && str[i] <= 'z') {
                num[str[i] - 'a']++;
            }
            else if (str[i] >= 'A' && str[i] <= 'Z') {
                num[str[i] - 'A']++;
            }
        }
    }

    for (int i = 0; i < 26; i++) {
        cout << (char)('a'+i) << " : " << num[i] << endl;
    }
}


Measured memory_bytes: 3184
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string s;
long long n,cnt,S;
int main(void){
    cin>>s;
    s='0'+s;
    reverse(s.begin(),s.end());
    for(int i=0;i<s.size();i++){
        if(cnt==2){
            S=s[i]-'0';
            if(S>=5)S++;
            
        }
        else S=s[i]-'0'+cnt;
        if(S<5){n+=S;cnt=0;}
        else if(S==5){
            cnt=2;
            n+=5;
        }
        else {cnt=1;n+=10-S;}
    }
    cout<<n<<endl;
}


Measured memory_bytes: 2308
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a,b;
	bool f=1;
	cin>>a>>b;
	if(a=='D')
		f=!f;
	if(b=='D')
		f=!f;
	if(f==1)
		cout<<"H";
	if(f==0)
		cout<<"D";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define cout (cout << setprecision(12))

int main() {
    double L;
    cin >> L;
    cout << pow(L / 3.0, 3) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>

int main() {
  int n;
  std::cin >> n;
  
  std::vector<int> h(n);
  for (auto&& hi : h) std::cin >> hi;
  
  std::vector<int> cost(n, 0);
  cost[1] = std::abs(h[1] - h[0]) + cost[0];
  for (int i = 2; i < n; ++i) {
    const auto c1 = std::abs(h[i] - h[i-1]) + cost[i-1];
    const auto c2 = std::abs(h[i] - h[i-2]) + cost[i-2];
    cost[i] = std::min(c1, c2);
  }
  
  std::cout << cost[n-1] << std::endl;
}

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

string S;

int main() {
    cin >> S;
    
    int n = S.size();
    long long s[10];
    long long op_max = 1;
    for(int i = 0; i < n-1; ++i) {
        op_max = op_max << 1;
        s[i] = S[i] - '0';
    }
    s[n-1] = S[n-1] - '0';

    long long ans = 0;
    for(long long op = 0; op < op_max; ++op) {
        long long z = 0;
        long long digit = 1;
        for(int i = n - 1; i >= 0; --i) {
            z += digit * s[i];
            digit *= 10;
            if(i == 0 || ((op >> (i-1)) & 1)) {
                //cout << "+" << z;
                ans += z;
                z = 0;
                digit = 1;
            }
        }
        //cout << endl;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  double final=0.000000000;
  cin>>n>>k;
  for(int i=1;i<=n;i++)
  { int c=i;
     int p=0;
    int sum=0;
    while(c<k)
      { 
        sum=sum+c;
        c=2*c;
        p++;
      }
  
  float   w=1.000000000;
    for(int j=1;j<=p;j++)
    {
       w=w*2;
    }
  
     final=final+(1/(double)n)*(1/(double)w);
  }
  
  cout<<fixed<<setprecision(12)<<final;
  return 0;
}
    
       
       
      
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    for(int i=0; i<H; i++){
        int tmpA=A;
        for(int j=0; j<W; j++){
            if(B>0){
                if(tmpA>0){
                    cout << 1;
                }else{
                    cout << 0;
                }
            }else{
                if(tmpA>0){
                    cout << 0;
                }else{
                    cout << 1;
                }
            }
            tmpA--;
        }
        cout << endl;
        B--;
    }
}

Measured memory_bytes: 1280
#include<stdio.h>

int main(){
 char str[11];
 int A[10];
 int i,j;

 while(scanf("%s",str)!=EOF)
 {

  for(i=0;i<10;i++)A[i]=str[i]-'0';

  for(i=1;i<10;i++)
  {
   for(j=0;j<10-i;j++)
     A[j]=(A[j]+A[j+1])%10;
  }

  printf("%d\n",A[0]);

 }

return 0;
}


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

int main() {
    ll N;
    cin >> N;
    ll A[N], ai;
    map<ll, ll> cnt{};
    rep(i, N) {
        cin >> ai;
        A[i] = ai;
        cnt[ai]++;
    }

    ll total = 0;
    for (auto c=cnt.begin(); c != cnt.end(); c++) {
        total += c->second * (c->second - 1) /2;
    }

    rep(i, N) {
        ll sub_i, add_i;
        ai = A[i];
        sub_i = cnt[ai] * (cnt[ai] - 1) / 2;
        add_i = (cnt[ai] - 1) * (cnt[ai] - 2) / 2;
        add_i = max(0LL, add_i);

        cout << total - sub_i + add_i << endl;
    }

    return 0;
}

 

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//座標圧縮
class CC{
  public:
  map<ll,int> mp;
  bool isUnique = true;
  
  CC(vector<ll> v){//座標圧縮が必要になるのはlonglongintの時が多い？
    sort(v.begin(),v.end());
    auto result = unique(v.begin(),v.end());
    isUnique = (result == v.end());
    v.erase(result, v.end());//重複を除いてもmapから参照できる。
    
    for(int i=0; i<v.size(); i++){
      mp.emplace_hint(mp.end(),v[i],i);
    }
  }
  
  ll getKey(int value){//keyが必要な場合は座標圧縮前のベクトルから参照できるため、これは不要？
    return next(mp.begin(), value)->first; 
  }

  /*
  inline int operator [] (ll index) const{//読み取り
     if(mp.find(index) != mp.end()) return mp[index];
     else{ return -1;}
  }
  */
};

//BIT
class BinaryIndexedTree{
  int N;
  vector<int> BIT;
  
  public:  
  
  BinaryIndexedTree(int n):BIT(n+1,0){ N = n; }//1-indexed
  BinaryIndexedTree(vector<int> v):BIT(v.size()+1,0){
    N = v.size();
    for(int i=1; i<=N; i++){
      add(i,v[i-1]); 
    }
  }
  
  void add(int x, int y){//0-indexed originから呼び出される時
    for(int i=x+1; i <= N; i += i&-i){
      BIT[i] += y;
    }
  }
  
  int sum(int x){
    int ret = 0;
    for(int i=x+1; i>0; i -= i&-i){
      ret += BIT[i];
    }
    return ret;
  }

  inline int operator [] (int index) const{//読み取り
     return BIT[index];
  }
  inline int& operator [] (int index){//書き取り
     return BIT[index];
  }
};

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N; cin >> N;
  vector<ll> p(N); FOR(i,N){ cin >> p[i]; }
  
  //main
  CC cc(p);
  BinaryIndexedTree bit(N);
  
  ll ans = 0;
  FOR(i,N){
    bit.add(cc.mp[p[i]],1);
    if(bit.sum(cc.mp[p[i]]) == 1){ ans ++; }
  }
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 15872
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import collections
import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def main():
    N, Q = [int(x) for x in input().split()]
    add, delete = [], []
    for i in range(N):
        S, T, X = [int(x) for x in input().split()]
        add.append((S - X, X))
        delete.append((T - X, X))

    active = []
    to_delete = collections.defaultdict(int)
    import heapq
    heapq.heapify(add)
    heapq.heapify(delete)
    for _ in range(Q):
        x = int(input())
        while add and add[0][0] <= x:
            coord, val = heapq.heappop(add)
            heapq.heappush(active, val)

        while delete and delete[0][0] <= x:
            coord, val = heapq.heappop(delete)
            to_delete[val] += 1

        while active and to_delete[active[0]] > 0:
            to_delete[active[0]] -= 1
            heapq.heappop(active)
            
        print(active[0] if active else -1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()


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

bool check(int A, int B, int C, int K, int i){
  if(i == K){
    return A < B && B < C;
  }
  return check(A*2, B, C, K, i+1) || check(A, B*2, C, K, i+1) || check(A, B, C*2, K, i+1);
}

int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  cout << (check(A, B, C, K, 0) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int n, C, L[10];
double f[1 << 5][305];
int main() {
	scanf("%d%d", &n, &C);
	for (int i = 0; i < n; i++) scanf("%d", &L[i]);
	sort(L, L + n);
	double ans = 0;
	int fct = 0;
	do {
		fct++;
		memset(f, 0, sizeof(f));
		f[0][L[n - 1] * n] = 1;
		for (int i = 0; i < n * C; i++) if (i % n)
			for (int S = 0; S < (1 << (n - 1)); S++) if (!(S >> (i % n - 1) & 1))
				for (int j = i; j <= n * C; j++)
					f[S | (1 << (i % n - 1))][min(n * C, max(j, i + L[i % n - 1] * n))] += f[S][j];
		ans += f[(1 << (n - 1)) - 1][n * C];
	} while (next_permutation(L, L + n - 1));
	for (int i = 1; i < n; i++) ans /= 1.0 * C;
	ans /= 1.0 * fct;
	printf("%.14lf\n", ans);
	return 0;
}

Measured memory_bytes: 384
use std::collections::HashSet;
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut open = HashSet::<String>::new();
    let s = read::<String>();
    let mut prev_c = s.clone().chars().last().unwrap();
    open.insert(s);
    for _i in 1..n {
        let s = read::<String>();
        let c = s.clone().chars().next().unwrap();
        if open.contains(&s) || prev_c != c {
            println!("No");
            return;
        }
        prev_c = s.clone().chars().last().unwrap();
        open.insert(s);
    }
    println!("Yes");
}


Measured memory_bytes: 4352
import math
import sys
n = int(input())
sqn = round(math.sqrt(n))
flg = True
if n % sqn == 0:
  print(sqn + n//sqn -2)
  sys.exit()

sqn_add = sqn
sqn_diff = sqn
while flg:
  sqn_add += 1
  sqn_diff -= 1
  if n % sqn_add == 0:
    print(sqn_add + n//sqn_add -2)
    sys.exit()
  elif n % sqn_diff == 0:
    print(sqn_diff + n//sqn_diff -2)
    sys.exit()


Measured memory_bytes: 3060
<?php
function kaijyo($n) {
    $result = 1;
  	for($i=1;$i<=$n;$i++){
      $result = ($result%(10**9+7))*($i%(10**9+7));
     // $result %=(10**9+7);
    }
  	return $result;
}

//echo kaijyo(100000);

fscanf(STDIN,"%d%d",$n,$m);

if($n==$m){
  $patern = ((kaijyo($n)%(10**9+7))*(kaijyo($m)%(10**9+7)))*2;
}elseif(abs($n-$m)>1){
  $patern = 0;
}else{
  $patern = ((kaijyo($n)%(10**9+7))*(kaijyo($m)%(10**9+7)));
}

echo $patern%(10**9+7);
//echo $patern;

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    string a,b,c;
    cin>>a>>b;
    c="";
    for(int i=0; i<n; i++)
    {
        c+=a[i];
        c+=b[i];
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 256