akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
#define double long double

const int N = 3009;
double cache[N][N], pro[N];
bool vis[N][N];
int n;

double dp(int id, int h) {
	if(id == n+1)
		return (h*2 >= n);
	double &ans = cache[id][h];
	if(vis[id][h])
		return ans;
	vis[id][h] = 1;
	ans = (pro[id] * dp(id+1, h+1)) + ((1 - pro[id]) * dp(id+1, h));
	return ans;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> pro[i];
	}
	double ans = dp(1, 0);
	cout << fixed << setprecision(12) << ans << endl;

	return 0;
}


Measured memory_bytes: 150400
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    sa = set(la)
    if len(la) == len(sa):
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
int a[233333];
map<int,int> mp;
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (a[i]>n-1) {printf("No\n");return 0;}
		mp[a[i]]++;
	}
	if (mp.size()>2) {printf("No\n");return 0;}
	if (mp.size()==2)
	{
		map<int,int>::iterator p1=mp.begin(),p2=p1;p2++;
		if (p1->second>=p2->first) {printf("No\n");return 0;}
		if (p1->first+1!=p2->first) {printf("No\n");return 0;}
		if ((p2->first)-(p1->second)>(p2->second/2)) {printf("No\n");return 0;}
		printf("Yes\n");return 0;
	}
	if (mp.size()==1)
	{
		//cout<<mp.begin()->second<<n-1<<endl;
		if (mp.begin()->first==n-1) {printf("Yes\n");return 0;}
		if (mp.begin()->first>n/2) {printf("No\n");return 0;}else {printf("Yes\n");return 0;}
	}
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
long long int sumofdigits(long long int N, long long int B){
		long long int Q = 0; 
		while(N > 0){
			Q += N % B; 
			N /= B; 
		}
		return Q; 
	}
int main() {
	long long int N, S; 
	cin >> N >> S; 
	vector<long long int> D; // Bの候補を列挙．(N-Sの約数)+1の形に限る
	if(N < S){cout << -1 << endl;}
	else if(N == S){cout << N + 1 << endl;}
	else{
	for(long long int i = 1; i * i <= N - S; i++){
		if((N - S) % i == 0){
			D.push_back(i + 1); 
			D.push_back((N - S) / i + 1); 
		}
	}
	sort(D.begin(), D.end()); 
	long long int ans = -1; 
	for(int i = 0; i < D.size(); i++){
		if(sumofdigits(N, D.at(i)) == S){
			ans = D.at(i); 
			break; 
		}	
	}
	cout << ans << endl; 
	}
}

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


int main() {
  
  long long X;
  cin >> X;

  int ans = 0;
  long long m = 100;
  while(m < X) {
    long long increase = (double)m*0.01;
    m += increase;
    ans++;
  }

  cout << ans << endl;

}


Measured memory_bytes: 3632
import os
import sys

# import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# 解説AC
# https://twitter.com/maspy_stars/status/1185552225474498560
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def test(k):
    bc = np.bincount(A)
    bc.sort()
    bc = bc[np.searchsorted(bc, 1):]
    bc = bc[::-1]
    ret = 0

    while len(bc) >= k:
        bc[:k] -= 1
        bc.sort()
        bc = bc[np.searchsorted(bc, 1):]
        bc = bc[::-1]
        ret += 1
    return ret


def cumsum(it):
    """
    累積和
    :param collections.Iterable it:
    :return:
    """
    s = 0
    ret = []
    for a in it:
        s += a
        ret.append(s)
    return ret


C = [0] * (N + 1)
for a in A:
    C[a] += 1
C.sort()
cs = list(reversed(cumsum(reversed(C))))


def solve(k):
    cnt = N // k
    if C[-1] <= cnt:
        # 全部取れるとしていい
        # 最後に2つ以上余ると max_c <= cnt に矛盾する
        return cnt

    # S = N
    # i = 1
    # while i < k:
    #     # 最大値は毎回取ることにしてもう見ない
    #     S -= C[-i]
    #     cnt = S // (k - i)
    #     max_c = C[-i - 1]
    #     if max_c <= cnt:
    #         return cnt
    #     i += 1

    ng = 0
    ok = k
    while abs(ng - ok) > 1:
        i = (ng + ok) // 2
        s = N - cs[-i]
        cnt = s // (k - i)
        max_c = C[-i - 1]
        if max_c <= cnt:
            ok = i
        else:
            ng = i
    if ok < k:
        i = ok
        s = N - cs[-i]
        return s // (k - i)
    else:
        return 0


ans = [0] * N
for k in reversed(range(1, N + 1)):
    ans[k - 1] = solve(k)
print(*ans, sep='\n')


Measured memory_bytes: 114364
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;
typedef unsigned long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;

ll count(ll a, ll b, ll x) {
	return (a*x)/b - a*(x/b);
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//int n, m, q; cin >> n >> m >> q;
	//ll sum = 0;
	//while (q--) {
		//int a, b, c, d; cin >> a >> b >> c >> d;
		
	//}
	
	ll a, b, n; cin >> a >> b >> n;
	ll l = 0, r = n;
	ll wyn = 0;
	ll x = 0;
	while (l <= r) {
		ll mid = l + (r - l) / 2;
		//cout << mid << '\n';
		ll y = count(a, b, mid);
		if (y >= wyn) {
			wyn = y;
			x = mid;
			l = mid + 1;
		}
		else {
			r = mid - 1;
		}
	}
	
	cout << count(a, b, x) << '\n';
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
using namespace std;

int n;
string f[10];
int w[10], s[10];
bool used[10];

void dfs(int sum, int G, int &minG, vector<string> &v, vector<string> &ans) {
	if ((int)v.size() == n) {
		if (G < minG) {
			minG = G;
			ans = v;
		}
		return ;
	}
	for (int i=0; i<n; ++i) {
		if ( ! used[i] && sum - w[i] <= s[i]) {
			used[i] = true;
			v.push_back(f[i]);
			dfs(sum-w[i], G+v.size()*w[i], minG, v, ans);
			used[i] = false;
			v.pop_back();
		}
	}
	return ;
}

int main() {
	while (cin >> n, n) {
		int sum = 0;
		for (int i=0; i<n; ++i) {
			cin >> f[i] >> w[i] >> s[i];
			sum += w[i];
		}
		memset(used, false, sizeof used);
		int minG = INT_MAX;
		vector<string> v, ans;
		dfs(sum, 0, minG, v, ans);
		for (int i=0; i<(int)ans.size(); ++i) {
			cout << ans[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1208
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


// edit

struct UnionFind {
    vector<int> par, sz;

    UnionFind(int n) : par(n), sz(n, 1) {
        for (int i = 0; i < n; ++i) par[i] = i;
    }

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

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sz[x] < sz[y]) swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
        sz[y] = 0;
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return sz[root(x)];
    }
};

void solve() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.merge(a, b);
    }
    set<int> st;
    for (int i = 0; i < N; ++i) {
        st.insert(uf.root(i));
    }
    cout << (int) st.size() - 1 << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 7468
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  ll a,b,c,d; cin >> a >> b >> c >> d;
  ll ans = max(max(a*d,a*c),max(b*c,b*d));

  cout << ans << endl;


}


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

const int mod=1e9+7;

void add(int &a,int b){
   a+=b;
   if(a>=mod) a-=mod;
}

signed main()
{
   string s; cin>>s;
   int N=s.size();

   vector<vector<int> > dp(N+1,vector<int>(4));
   dp[0][0]=1;
   for(int i=0;i<N;i++){
      for(int j=0;j<=3;j++){
         if(s[i]=='?'){
            add(dp[i+1][j],dp[i][j]*3%mod);
         }
         else{
            add(dp[i+1][j],dp[i][j]);
         }
      }
      if(s[i]=='A' or s[i]=='?'){
         add(dp[i+1][1],dp[i][0]);
      }
      if(s[i]=='B' or s[i]=='?'){
         add(dp[i+1][2],dp[i][1]);
      }
      if(s[i]=='C' or s[i]=='?'){
         add(dp[i+1][3],dp[i][2]);
      }
   }
   cout<<dp[N][3]<<endl;
}


Measured memory_bytes: 7424
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author KY2001
 */


#include "bits/stdc++.h"
#define int long long
#define For(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define Max(x) *max_element(ALL(x))
#define Min(x) *min_element(ALL(x))
#define Lower_bound(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define Upper_bound(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

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

int Lcm(int a, int b) {
  if (!(a % gcd(a, b))) {
    return (a / gcd(a, b) * b);
  } else if (!(b % gcd(a, b))) {
    return (b / gcd(a, b) * a);
  } else {
    return a * b / gcd(a, b);
  }
}
class CMultipleClocks {
public:
  void solve(std::istream &cin, std::ostream &cout) {
    int N;
    cin >> N;
    int ans = 1;
    rep(i, N) {
      int temp;
      cin >> temp;
      ans = Lcm(temp, ans);
    }
    cout << ans << endl;
  }
};


signed main() {
	CMultipleClocks solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define SQ(x) (x)*(x)
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

// #define int ll

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}

ll mpow(ll a, ll n){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mod;
        a = a*a %mod;
        n>>=1;
    }
    return re;
}

ll inv (ll b){
    if (b==1) return b;
    return (mod-mod/b) * inv(mod%b) % mod;
}

const int maxn = 1e5+5;



main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n; cin>>n;
    string s, t; cin>>s>>t;
    
    s = t + '#' + s;

    vector<int> f(n*2+1);
    f[0]=-1;
    FOR(i,1,n*2+1){
        f[i] = f[i-1];
        while (f[i]!=-1 && s[i] != s[f[i]+1]){
            f[i] = f[f[i]];
        }
        if (s[i] == s[f[i]+1]){
            f[i]++;
        }
        // cout<<f[i]<<'\n';
    }
    cout<<2*n-f[n*2]-1<<endl;
    
} 

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n;
    cin >> n;
    static int64_t a[100000], b[100000], sum = 0;
    for(int i=0;i<n;i++){ cin >> a[i]; b[i] = abs(a[i]); sum += b[i]; }
    
    int cnt = 0;
    for(int i=0;i<n;i++) if(a[i] < 0) cnt++;
    if(cnt % 2 == 0) cout << sum << endl;
    else cout << sum - 2 * *min_element(b, b+n) << endl;

    return 0;
}

Measured memory_bytes: 1792
while (line = gets)
  xys = line.chop.split(",").map{|s| s.to_f}

  xs = [ xys[0], xys[2], xys[4], xys[6] ]
  ys = [ xys[1], xys[3], xys[5], xys[7] ]
  #p xs, ys

  x0 = xs[3]
  y0 = ys[3]

  op = nil
  convex = true

  for i in (0..3)
    x = xs[i]
    y = ys[i]

    x1 = xs[(i + 1) % 4]
    y1 = ys[(i + 1) % 4]

    op_i = (x - x0) * (y1 - y) - (y - y0) * (x1 - x)

    if op.nil?
      op = op_i
    elsif op * op_i < 0
      convex = false
      break
    end

    x0 = x
    y0 = y
  end

  puts convex ? "YES" : "NO"
end

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

int main() {
  string S;
  cin >> S;
  int count = 0;
  rep(i,3){
    if(S[i] == 'R'){
      count++;
    }
  }
    if(count != 2){
      cout << count << endl;
    }
    else{
      if(S[1] == 'R'){
        cout << 2 << endl;
      }
else{
  cout << 1 << endl;
}
    }

  }


Measured memory_bytes: 3588
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
maxi = max(A)
ind = A.index(maxi)
A[ind] = 0
ans = [maxi]*N
nmaxi = max(A)
ans[ind] = nmaxi
for i in ans:
    print(i)


Measured memory_bytes: 90804
#include<iostream>
using namespace std;
int main()
{
int n,a,i,b,k,j=0,s=0;
cin>>n>>a>>b;
for(i=a;i<=n;i++)
{
j=0;k=i;
while(k!=0)
{
j+=k%10;
k/=10;
}
if(j>=a&&j<=b)s+=i;
}
cout<<s;
return 0;
}


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

int main()
{
    int w, h, n;
    cin >> w >> h >> n;
    int p1 = 0, p2 = w, p3 = 0, p4 = h;
    rep(i, n)
    {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1)
            p1 = max(p1, x);
        if (a == 2)
            p2 = min(p2, x);
        if (a == 3)
            p3 = max(p3, y);
        if (a == 4)
            p4 = min(p4, y);
    }
    int ans = max(p4 - p3, 0) * max(p2 - p1, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
"use strict"

const main = (input) => {
    const _input = input.split("\n");
    const S = _input[0].split("");
    const T = _input[1].split("");
    let count = 0;

    for(let i = 0; i < 3; i++){
        if(S[i] === T[i]){
            count += 1;
        }
    }

    console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
/*----------------------------------------------------*
* लेखक --> अमित सिंह
* संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
*-----------------------------------------------------*/
   #include <bits/stdc++.h>
   using namespace std;
   #define ll long long
   #define w(t) int t; cin>>t; while(t--)
   #define fo(i,n) for(int i=0;i<n;i++)
   #define endl "\n" 
   #define MOD 1000000007
   const ll inf=1e18;
   void Tez(){
      ios::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
   }
   ll cache[100001];
   ll fun(int a[],int n,int k){
      if(n==1) return 0;
      if(n<=0) return INT_MAX;
      if(cache[n]!=-1) return cache[n];
      ll ans=INT_MAX;
      for(int i=1;i<=k && i<n;i++){
         ans=min(ans,abs(a[n-1]-a[n-i-1])+fun(a,n-i,k));
      }
      return cache[n]=ans;
   }
   int main(){
      Tez();
      int n,k;
      cin>>n>>k;
      int a[n];
      fo(i,n) cin>>a[i];
      memset(cache,-1,sizeof(cache));
      cout<<fun(a,n,k);
      return 0;
   }



Measured memory_bytes: 14140
#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;
#define fi first
#define sc second
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define pb push_back
#define endl '\n'
#define po(x) (1ll<<x)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> satan_set;
const ll DIM = 10E4+7;
const ll INF = 10E16;
ll prime(ll x){
    ll sq = sqrt(x);
    for(ll i = 2;i<sq;++i)if (x%i==0)return 0;
    return 1;
}

char th[DIM];
char A[DIM];
int main()
{
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,k,r,p,s; cin>>n>>k>>r>>s>>p;
    ll res =0;
    forn(i,n){
        char ch; cin>>ch;
        A[i] = ch;
        if (ch=='r'){
            char c = '0';
            if (i>k)c = th[i-k];
            if (c=='p')th[i] = '0';
            else {
                th[i] = 'p';
                res+=p;
            }
        }
        if (ch=='p'){
            char c = '0';
            if (i>k)c = th[i-k];
            if (c=='s')th[i] = '0';
            else {
                th[i] = 's';
                res+=s;
            }
        }
        if (ch=='s'){
            char c = '0';
            if (i>k)c = th[i-k];
            if (c=='r')th[i] = '0';
            else {
                th[i] = 'r';
                res+=r;
            }
        }
    }
    //forn(i,n)cout<<th[i];
    //cout<<endl;
    cout<<res<<endl;
    return 0;
}

// 1 2 3
//


Measured memory_bytes: 512
n = int(input())
l = [0] * (n+1)
l[0] = 2
l[1] = 1

if n == 1:
    ans = l[1]
else:
    for i in range(2, n+1):
        l[i] = l[i-1] + l[i-2]
    ans = l[-1]
print(ans)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
vector<int> p;
int64 N;
void Solve() {
    read(N);
    int num = 0,t;
    ++N;
    for(int i = 40 ; i >= 0 ; --i) {
	if((N >> i) & 1) {
	    t = i;
	    break;
	}
    }
    for(int i = t - 1 ; i >= 0 ; --i) {
	++num;
	p.pb(num);
	if((N >> i) & 1) {
	    ++num;
	    p.insert(p.begin(),num);
	}
    }
    t = p.size();
    for(int i = 1 ; i <= t ; ++i) p.pb(i);
    out(p.size());enter;
    for(auto a : p) {
	out(a);space;
    }
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 256
while True:
    try:
        n=int(input())
    except:
        break

    l=list(format(n,'b'))
    
    for i in range(len(l)):
        if l[-i-1] == "1":
            print(2**i, end="")
            if i != len(l)-1:
                    print(" ",end="")
            
    print()

Measured memory_bytes: 6716
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll A, B, m;
    cin >> A >> B >> m;

    vl a(A), a0(A);
    rep(i, A) {
        cin >> a[i];
        a0[i] = a[i];
    }
    sort(all(a0));

    vl b(B), b0(B);
    rep(i, B) {
        cin >> b[i];
        b0[i] = b[i];
    }
    sort(all(b0));

    ll ans = a0[0] + b0[0];
    rep(i, m) {
        ll x, y, c;
        cin >> x >> y >> c;
        x--;  y--;
        chmin(ans, a[x] + b[y] - c);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
 
#define all(x)                      (x).begin(),(x).end()
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define alog(a, n)                  for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
 
const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll a, b, c, k;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> k;
    if(k <= a + b)
        return cout << (k >= a ? a : k) << endl, 0;
    cout << a - (k - (a + b)) << endl;
	return 0;
}


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

using namespace std;

vector<long long> ans;

void el3ab(int i, long long last) {
    if (i == 11)
        return;
    vector<long long> v;
    v.push_back(last * 10 + (last % 10));

    if (last % 10 == 0)
        v.push_back(last * 10 + 1);
    else if (last % 10 == 9)
        v.push_back(last * 10 + 8);
    else
        v.push_back(last * 10 + (last % 10) + 1), v.push_back(last * 10 + (last % 10) - 1);

    for (auto x : v)
        ans.push_back(x), el3ab(i + 1, x);
}

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

    for (int i = 1; i < 10; i++)
        ans.push_back(i), el3ab(2, i);
    sort(ans.begin(), ans.end());

    int n;
    cin >> n;
    cout << ans[n - 1] << '\n';

    return 0;
}

Measured memory_bytes: 2420
N = int(input())

anslist = [0] * N

for i in range(1,int(N**0.5)+1):
    for j in range(1,int(N**0.5)+1):
        for k in range(1,int(N**0.5)+1):
            a = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if a <= N:
                anslist[a-1] += 1
    

for i in range(N):
    print(anslist[i])


Measured memory_bytes: 74896
from collections import deque
import sys

input=sys.stdin.readline

S=input().rstrip()

string = deque([S[i] for i in range(len(S))])

reverse = False

for _ in range(int(input())):
    q = input().rstrip().split()

    if q[0] == "1":
        reverse = not reverse

    else:
        if q[1] == "1":
            if reverse:
                string.append(q[2])
            else:
                string.appendleft(q[2])

        else:
            if reverse:
                string.appendleft(q[2])
            else:
                string.append(q[2])

string = list(string)

if reverse:
    string = string[::-1]

print("".join(string))


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

int main(){
    long long b;
    
   /* vector<bool> p((10e9)/2,true);
    vector<int> q(0);
    
    for(int i=2;i<b+1;i++){ 
        
       
            if(p.at(i)==true){
                int n=1;
                while(n*p.at(i)<b){
                    p.at(n*p.at(i))=false;
                        n++;
                }
                q.push_back(i);
            }
        }
    
*/    
    while(cin>>b){                       
        long long i=(1+sqrt(1+8*b)); 
     
        
        
        
        /*int l=q.size();
        vector<int> s(l);
        int c=0;
        while(b>1){
            
           while(b/q.at(c)>=1){
                s.at(c)++;
                b=b/q.at(c);
            }
            c++;
        }
        */  
        
        
        
        
        
        
        while(i>0){
            if(2*b%i==0&&(2*b/i)-i+1>0&&((2*b/i)-i+1)%2==0){                            

                
                    int x=(((2*b/i)-i+1)/2);
                    cout<<x<<" "<<i<<endl;
                    break;
                
                
                
            }
            

            
            
            
            
        
            
            
            
        i--;    
        }  
    }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

typedef long long ll;

const int maxn = 20;
const int inf = 50;

int D;
ll ans;
int d[maxn];

void f(int n,int k,int carry, vector<int> v) {
	if (k == n+1) {
		
		
		ll cur = 1;
		if (carry > 0) return;
		for (int i = 0; i <= n-i; i++) {
			if (i == n-i) { if (v[i]!=inf && v[i] != 0) { return; } else { cur *= (i != n) + 9; continue; } }
			
			int th = 0;
			
			for (int x = (i==n); x <= 9; x++) {
				for (int y = (n-i==n); y <= 9; y++) {
					if (x-y == v[i]) th++;
				}
			}
			
			cur *= th;
		}
		ans += cur; return;
	}
	
	int p1 = -carry-d[k]; // = a k - a (n-k)
	int p2 = p1 + 10;
	
	vector<int> q = v;
	
	int g = k;
	
	if (k > n-k) {
		g = n-k; p1 = -p1; p2 = -p2;
	}
	
	if (v[g]!=inf && v[g] != p1) {} else { v[g] = p1; f(n,k+1,0,v); } 
	v = q;
	if (v[g]!=inf && v[g] != p2) {} else { v[g] = p2; f(n,k+1,1,v); }
			
}

int main() {
	cin>>D; ans = 0;
	for (int i = 0; i < maxn; i++) d[i] = 0;
	int cur = 0;
	while (D>0) {
		d[cur] = D%10; D /= 10; cur++;
	}
	
	for (int i = cur-1; i < maxn-1; i++) {
		f(i,0,0,*new vector<int>(i+1,inf));
	}
	
	cout<<ans<<endl;
}
		



Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] ary = new int[3];
		for (int i =0; i <ary.length; i++){
			ary[i] = scan.nextInt();
		}
		if(ary[0] <= ary[2] && ary[2] <= ary[1]) {
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}
class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 23764
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}

int main() {
    ll N, X;
    cin >> N >> X;
    ll x, idx = 0; vector<ll> xs(N);
    while(cin >> x){
        xs[idx] = abs(x - X); idx++;
    }
    
    ll res = xs[0];
    for (ll i = 1; i < xs.size(); i++) {
        res = gcd(res, xs[i]);
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

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

        int[] stick;
        int w = sc.nextInt();
        int n = sc.nextInt();

        stick = new int[w];
        for(int i=0;i<w;i++){
            stick[i] = i+1;
        }

        for(int i=0;i<n;i++){
            String str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0])-1;
            int b = Integer.parseInt(ab[1])-1;

            int x = stick[a];
            stick[a] = stick[b];
            stick[b] = x;
        }

        for(int i=0;i<w;i++){
            System.out.println(stick[i]);
        }
    }
}



Measured memory_bytes: 25776
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
int main()
{
    long long int n,k;
    cin>>n>>k;
    long long int a[n];
    for(long long int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long int sum=0;
    if(k>n)
        cout<<"0";
    else if(k==0)
    {
     for(long long int i=0;i<n;i++)
     {
     sum=sum+a[i];
     }
     cout<<sum;
    }
    else{
      sort(a,a+n,greater<int>());
      for(long long int i=0;i<n;i++)
     {
     sum=sum+a[i];
     }
    for(long long int k1=0;k1<k;k1++)
    {
        sum=sum-a[k1];
    }
    cout<<sum;
    }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
int dp[100000] = {}, h[100000] = {};
int main(void)
{
  int n, k;
  std::cin >> n >> k;
  for(int i = 0; i != n; i++) std::cin >> h[i];
  for(int i = 1; i != n; i++){
    dp[i] = dp[i - 1] + std::abs(h[i] - h[i - 1]);
    for(int j = std::max(0, i - k); j != i; j++){
      dp[i] = std::min(dp[i], dp[j] + std::abs(h[i] - h[j]));
    }
  }
  std::cout << dp[n - 1] << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int N;
  scanf("%d",&N);

  char S[N];
  scanf("%s",S);

  int num = 0;
  int ans = 0;
  for(int i = 0;i < N;i++){
    if(S[i] == 'I')
      num++;
    else
      num--;
    ans = max(ans,num);
  }

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

  return 0;
}

Measured memory_bytes: 128
import sys
import math
import itertools
# num = []
# for e in sys.stdin:
#     num.append(map(int, e.split()))

N = int(input())

count = []
for i in range(N):
    count.append(0)

max = min(int(math.sqrt(N)), int(N/2))
l = []

for i in range(1, max+1):
    l.append(i)

h = itertools.combinations_with_replacement(l, 3)

# print(h)
for i,j,k in h:
    n = (i+j+k)**2 - i*j - j*k - k*i
    # print(n)

    if(n <=N):
        if(i==j==k):
            count[n-1]+=1
        elif(i==j or j==k or i == k):
            count[n-1]+=3
        else:
            count[n-1]+=6


for c in count:
    print(c)

# for n in range(1, N+1):
#     count = 0;
#     max = min(int(math.sqrt(n)), int(n/2))
#     l = []
#
#     for i in range(1, max+1):
#         l.append(i)
#
#     h = list(itertools.combinations_with_replacement(l, 3))
#     for i,j,k in h:
#         if n == (i+j+k)**2 - i*j - j*k - k*i:
#             if(i==j==k):
#                 count+=1
#             elif(i==j or j==k or i == k):
#                 count+=3
#             else:
#                 count+=6

    # for i in range(1, max+1):
    #     for j in range(1, max+1):
    #         for k in range(1, max+1):
    #             num = i**2 + j**2 + k**2 + i*j + j*k + k*i
    #             if n == num:
    #                 count+=1
    # print(count)


    # print(max)


    # l = []
    #
    # for i in range(1, max+1):
    #     l.append(i)
    #
    # # h = itertools.combinations_with_replacement(l, 3)
    #
    # for i,j,k in h:
    #     if n == i**2 + j**2 + k**2 + i*j + j*k + k*i:
    #         if(i==j==k):
    #             count+=1
    #         elif(i==j or j==k or i == k):
    #             count+=3
    #         else:
    #             count+=6
    # print(count)


Measured memory_bytes: 9240
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	string s; cin >> s;
	vector<int> a;
	int c = 0;
	rep(i, s.size()){
		if(i==0) c++;
		else{
			if(s[i] != s[i-1]){ a.pb(c); c=1; }
			else c++;
		}
	}
	a.pb(c);
	ll ans = 0;
	if(s[0] == '<'){
		rep(i, a.size()){
			ans += (ll)(a[i]-1)*a[i]/2;
			if(i%2==0){
				if(i+1==a.size()){
					ans += a[i];
				}else{
					ans += max(a[i], a[i+1]);
				}
			}
		}
	}else{
		rep(i, a.size()){
			ans += (ll)(a[i]-1)*a[i]/2;
			if(i%2==0){
				if(i==0) ans += a[i];
				else ans += max(a[i], a[i-1]);
			}
		}
		if(a.size()%2==0) ans += a[a.size()-1];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 2048
package main

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

const pi float64 = 3.14159265359

func main() {
  //fmt.Print("Input: ")
  sc := bufio.NewScanner(os.Stdin)

  var r float64
  if sc.Scan() { r, _ = strconv.ParseFloat(sc.Text(), 64) }

  fmt.Printf("%.6f %.6f\n", r*r*pi, r*2*pi)
}



Measured memory_bytes: 1112
const long long MOD = 998244353;
const int N = 3010;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(N);
    __ufact.resize(N);
    __rev.resize(N);
    __rev[1] = 1;
    for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < N; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int n;
vector<int> graph[N];
int a[N];

void dfs(int v, vector<int> &st, int p = 0)
{
    for (auto u : graph[v]) if (u != p)
    {
        dfs(u, st, v);
        if (a[u] < a[v] && st[u] == 0) st[v] = 1;
    }
}

void solve(int v)
{
    vector<int> st(n + 1, 0);
    dfs(v, st);
    if (st[v] == 1) cout << v << " ";
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for (int i = 1; i <= n; i++)
    {
        solve(i);
    }
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 640
from collections import Counter

N = int(input())
S = input()

counter = Counter(list(S))

ans = counter['R'] * counter['G'] * counter['B']

for d in range(1, N // 2 + 1):
    for a, b, c in zip(S, S[d:], S[2 * d:]):
        if a != b and b != c and c != a:
            ans -= 1

print(ans)


Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  for(int i = 1; i < 6; i++) {
    i64 x;
    cin >> x;
    if(x == 0) {
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
A.sort()
M = A[-1]
divisible = [False] * (M + 1)
ans = 0
for i, a in enumerate(A):
    if not (i < N - 1 and A[i+1] == a) and not divisible[a]:
        ans += 1
    for b in range(a, M + 1, a):
        divisible[b] = True
print(ans)


Measured memory_bytes: 106320
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b, m;
	cin>>a>>b>>m;
	int f[a], mi[b], t[m], minmic = INT_MAX, minfrd = INT_MAX;
	
	for(int i=0;i<a; i++) {
		cin>>f[i];
		minfrd = min(f[i], minfrd);
	}
	
	for(int j=0; j<b;j++) {
		cin>>mi[j];
		minmic = min(mi[j], minmic);
	}
	
	int min_cost = minfrd + minmic;
	
	int x,y,c;
	for(int k=0; k<m; k++) {
		cin>>x>>y>>c;
		x--;
		y--;
		min_cost = min(f[x] + mi[y] - c , min_cost);
	}
	
	cout<<min_cost;
	
	return 0;
}

Measured memory_bytes: 1152
#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(){
  ll N, M; cin >> N >> M;
  if (N<M) swap(N,M);

  if (N==1) cout << 1 << endl;
  else if (M==1) cout << N-2 << endl;
  else if (M>=2) cout << (M-2)*(N-2) << endl;

  return 0;
}


Measured memory_bytes: 256
#import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

N = int(readline())
A = list(map(int,input().split()))
#A = []  
#[bisect.insort_right(A, x) for x in tmp]
B= list(map(int,readline().rstrip().split()))
#B = []
#[bisect.insort_right(B,x) for x in tmp ]
C = list(map(int,readline().rstrip().split()))
#C = []
#[bisect.insort_right(C,x) for x in tmp]

A.sort()
C.sort()

ans = 0
for b in B :
    indA = bisect.bisect_left(A,b)
    indC = bisect.bisect_right(C,b)
    ans += indA * (N-indC)

print(ans)

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
#define tc ll t; cin >> t; while (t--)
#define sz(c) (ll) (c).size()
#define trav(x,c) for(auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rll(c) (c).rbegin(), (c).rend()
#define _for(i,a,n) for(ll i = a ; i < n; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);

ll primefac(ll n)
{
    ll res = 0;
    for(ll i = 2 ; i*i <= n ; i++) {
        if(n % i != 0) continue;
        res++;
        while(n % i == 0) n /= i;
    }
    if(n != 1) res++;
    return res;
}

    

int main() {
    godspeed;
    ll a, b; cin >> a >> b;
    cout << primefac(__gcd(a,b)) + 1;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
  string S1,S2;
  cin>>S1>>S2;
  string ans="NO";
  if(S1.at(1)==S2.at(1)&&S1.at(0)==S2.at(2)&&S1.at(2)==S2.at(0))ans="YES";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<limits.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
typedef pair<ll,ll> PL;
typedef pair<ll,pair<ll,ll>> PLL;
static const int IINF=INT32_MAX;
static const ll LINF=INT64_MAX;
static const ll mod=1e9+7;
static const double eps=1e-13;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};

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

int N;
string S;

int dp[5005][5005];
int ans;

int main(){
    cin>>N;
    cin>>S;
    for(int i=0;i<N-1;++i){
        for(int j=i+1;j<N;++j){
            if(S[i]==S[j])chmax(dp[i+1][j+1],dp[i][j]+1);
        }
    }
    for(int i=0;i<=N-1;++i)for(int j=i+1;j<=N;++j)chmax(ans,min(dp[i][j],j-i));
    cout<<ans<<endl;
}

Measured memory_bytes: 96768
s = raw_input()
diff01 = 0
diff10 = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '1':
            diff01 += 1
        else:
            diff10 += 1
    else:
        if s[i] == "1":
            diff10 += 1
        else:
            diff01 += 1
print min(diff10, diff01)

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long N = long.Parse(input[0]);
            long L = long.Parse(input[1]);

            long[] score = new long[N];
            long[] score_abs = new long[N];
            for (int i = 0; i < N; i++)
            {
                score[i] = L + i;
                score_abs[i] = Math.Abs(score[i]);
            }
            int min_index = Array.IndexOf(score_abs, score_abs.Min());
            long total = score.Sum() - score[min_index];
            Console.WriteLine(total.ToString());
        }
    }
}   

Measured memory_bytes: 13276
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

constexpr int INF = 1e8;

int size;
vector<pair<int,int>> e[500000];
map<pair<int,int>,int> table;
bool used[500000];

int ride(int p, int c) {
    if (table.count({p,c})) return table[{p,c}];
    int ret = size++;
    e[p].emplace_back(ret,1);
    e[ret].emplace_back(p,0);
    return table[{p,c}] = ret;
}

int main(void) {
    int i, n, m;
    scanf("%d%d",&n,&m);
    size = n;
    REP (i,m) {
        int p, q, c;
        scanf("%d%d%d",&p,&q,&c);
        p--; q--;
        p = ride(p,c);
        q = ride(q,c);
        e[p].emplace_back(q,0);
        e[q].emplace_back(p,0);
    }
    priority_queue<pair<int,int>> q;
    q.push({0,0});
    while (!q.empty()) {
        int d = -q.top().first;
        int v = q.top().second;
        q.pop();
        if (used[v]) continue;
        used[v] = true;
        if (v == n-1) {
            printf("%d\n",d);
            return 0;
        }
        for (auto p: e[v]) {
            q.push({-(d+p.second),p.first});
        }
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 57720