akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

long long ans = 1e9, x, n, m;
vector<long long> c;
vector<vector<long long> > a;

void k(long long step, long long cnt, vector<long long> &now){
    if(step == n + 1){
        bool ok = true;
        for(int i = 1; i <= m; ++i){
            if(now[i] < x) ok = false;
        }
        if(ok) ans = min(ans, cnt);
        return;
    }
    k(step + 1, cnt, now);
    for(int i = 1; i <= m; ++i){
        now[i] += a[step][i];
    }
    k(step + 1, cnt + c[step], now);
    for(int i = 1; i <= m; ++i){
        now[i] -= a[step][i];
    }
}


int main(){
    cin >> n >> m >> x;
    c.resize(n + 1);
    a.resize(n + 1, vector<long long>(m + 1));
    for(int i = 1; i <= n; ++i){
        cin >> c[i];
        for(int j = 1; j <= m; ++j) cin >> a[i][j];
    }
    vector<long long> now(m + 1, 0);
    k(1, 0, now);
    cout << (ans == 1e9?-1:ans);
}

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

// merge-sort
// As we define n is the size of list, calculation will take O(nlogn) time.
template<typename T>
void m_sort(vector<T> &list){
    
    if(list.size() <= 1) return; // 終了条件

    int n = list.size();
    
    vector<T> m1,m2;
    for(int i = 0; i < n; ++i){
        if(i%2) m1.push_back(list[i]);
        else m2.push_back(list[i]);
    }
    
    m_sort(m1);
    m_sort(m2);

    for(int i = 0, m1_cnt = 0, m2_cnt = 0; i < n; ++i){
        if(m1_cnt == m1.size()) list[i] = m2[m2_cnt++];
        else if(m2_cnt == m2.size()) list[i] = m1[m1_cnt++];            
        else{
            if(m1[m1_cnt] < m2[m2_cnt]) list[i] = m1[m1_cnt++];
            else list[i] = m2[m2_cnt++];
        }
    }

}

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

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

    m_sort(a);
    reverse(a.begin(), a.end());

    int alice = 0, bob = 0;

    rep(i,n){
        if(i%2==0) alice += a[i];
        else bob += a[i];
    }

    cout << alice - bob << endl;
}

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

using namespace std;
typedef long long int ll;

void solve()
{
	int n;
	cin >> n;
	int n1 = 1000, mini = 100000000;
	for(int i = 2; i <= 100; i++)
	{
		if(n1 - n > 0)
			mini = min(mini,n1 - n);
		n1 = n1 * i;
	}
	cout << ceil(n/1000.0) * 1000 - n<< "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
}

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

int main(void) {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
		
	if (a+b > c+d) {
		cout << "Left" << "\n";
	} else if (a+b < c+d) {
		cout << "Right" << "\n";
	} else {
		cout << "Balanced" << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

string S;
int N;
int dp[33][101010];
int ans[101010];

int main(){
    cin>>S;
    N=S.length();
    rep(i,0,N){
        if(S[i]=='R')dp[0][i]=i+1;
        else dp[0][i]=i-1;

    }
    rep(p,0,32) rep(i,0,N) dp[p+1][i]=dp[p][dp[p][i]];
    rep(i,0,N)ans[dp[32][i]]++;
    rep(i,0,N){
        if(i)printf(" ");
        printf("%d",ans[i]);

    }
    printf("\n");
}

Measured memory_bytes: 14080
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
  int a, b; cin >> a >> b;
  int cnt = 0, t = b;
  while (t > 0) {
    t /= 10;
    cnt++;
  }
  while (cnt > 0) {
    a *= 10;
    cnt--;
  }
  int c = a + b;
  //cout << c << endl;
  for (int i = 2; i * i <= c; i++) {
    if (i * i == c) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

void solve(string S, string T)
{
    int res = 0;
    for (int i = 0; i < (int)S.size(); i++)
    {
        if (S.at(i) != T.at(i))
        {
            res++;
        }
    }
    cout << res << endl;
}

int main()
{
    string S;
    cin >> S;
    string T;
    cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 4076
import Data.List
import qualified Data.ByteString.Char8 as B

main = do
    n<-readLn::IO Int
    (t:a:_)<-map read.words<$>getLine::IO [Int]
    hs<-unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
    --
    print $ snd $ minimum $ zip (map (\x-> abs(t*1000 - x*6 - a*1000)) hs) [1..]

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;

//int p[200005];
long double e[200005];

int main()
{
	int n, k;
	cin.sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int p;
		cin >> p;
		e[i] = (1 + p) / 2.0;
	}
	long double acc = accumulate(e, e + k, 0.0L);
	long double ans = acc;
	for (int i = 0; i < n - k; i++)
	{
		acc += e[i + k] - e[i];
		if (acc > ans)
		{
			ans = acc;
		}
	}
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
if __FILE__ == $0
  while line = STDIN.gets
    tokens = line.chomp!.split.map!(&:to_i)
    a, b = tokens[0], tokens[1]
    if a > b
      puts "a > b"
    elsif a < b
      puts "a < b"
    else
      puts "a == b"
    end
  end
end

Measured memory_bytes: 8596
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
int main(){
   string a,b;
   cin >>a >> b;
   cout << b << a << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=26;
string s,t;
int n;
vi a(M,-1);

bool f(){
	a=vi(M,-1);
	bool B=1;
	for(int i=0;i<n;i++){
		int I=s[i]-'a',J=t[i]-'a';
		if(a[I]==J) continue;
		if(a[I]==-1) a[I]=J;
		else B=0;
	}
	swap(s,t);
	return B;
}

int main(){
	cin>>s>>t;
	n=s.size();
	cout<<(f()&&f()?"Yes":"No")<<endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main()
{
    string o, e, ans;
    cin >> o >> e;
    int length = o.size() + e.size();
    for (int i = 0; i < length; i++)
    {
        if (i % 2 == 0)
        {
            ans += o.at(i / 2);
        }
        else
        {
            ans += e.at(i / 2);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	char a[209];
	a['T'] = 'A';
	a['A'] = 'T';
	a['C'] = 'G';
	a['G'] = 'C';

	char c;
	cin >> c;
	cout << a[c] << '\n';

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


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


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };
int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/
typedef tuple<int,int,int> tpl;


//約数の列挙
template<typename T>
vector<T> divisor(T n) {
	vector<T> res;
	for (T i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) {
				res.push_back(n / i);
			}
		}
	}
	return res;
}



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

    ll n;
    cin >> n;
    vector<ll> yakusuu=divisor(n);
    vector<ll> yakusuu2=divisor(n-1);

    int cnt = 0;

    set<ll> st;
    for (int i = 0; i < yakusuu.size(); i++)
    {
        if(yakusuu[i] == 1)continue;
        ll tmp = n;
        while(tmp%yakusuu[i] == 0){
            tmp/=yakusuu[i];
        }
        if(tmp%yakusuu[i] == 1){
            st.insert(yakusuu[i]);
        }
    }
    
    for (int i = 0; i < yakusuu2.size(); i++)
    {
        if(yakusuu2[i] == 1)continue;
        ll tmp = n;
        while(tmp%yakusuu2[i] == 0){
            tmp/=yakusuu2[i];
        }
        if(tmp%yakusuu2[i] == 1){
            st.insert(yakusuu2[i]);
        }
    }
    
    cout << st.size() << endl;

	return 0;
}



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

using namespace std;

typedef long long ll;

int main()
{
    int n, l;

    cin >> n >> l;

    deque<string> str(n);

    for(int i = 0; i < n; i++)
    {
        cin >> str[i];
    }

    sort(str.begin(), str.end());

    for(int i = 0; i < n; i++)
    {
        cout << str[i];
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 3552
#include <iostream>

using namespace std;

int f0[100005], f1[100005];

int main()
{
    int n, a0=0, a1=0, x, s;
    cin>>n;
    int v[n];
    for(int i=0; i<n; i++){
        cin>>v[i];
        if(i%2==0)
            f0[v[i]]++;
        else
            f1[v[i]]++;
    }

    for(int i=0; i<100005; i++){
        if(f0[i]>a0){
            a0=f0[i];
            x=i;
        }
    }

    for(int i=0; i<100005; i++){
        if(i==x)
            continue;
        else
            if(f1[i]>a1)
                a1=f1[i];
    }
    s=n-a0-a1;

    a0=0; a1=0;
    for(int i=0; i<100005; i++){
        if(f1[i]>a1){
            a1=f1[i];
            x=i;
        }
    }

    for(int i=0; i<100005; i++){
        if(i==x)
            continue;
        else
            if(f0[i]>a0)
                a0=f0[i];
    }
    if(n-a0-a1<s)
        s=n-a0-a1;
    cout<<s;

    return 0;
}

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

using namespace std;
using ll = long long;

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

  ll a, b, x;
  cin >> a >> b >> x;

  ll r = b / x;
  ll l = a / x;
  if (a % x == 0)
    l--;
  cout << r - l << endl;

  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int sum(int n){
    int sum = 0;
    string s = to_string(n);
    for(int i=0;i<s.size();i++){
        sum += (s[i]-'0');
    }
    return sum;
}

int main(){
    int N,A,B; cin >> N >> A >> B;
    int ans = 0;
    for(int i=1;i<=N;i++){
        int s = sum(i);
        if(s >= A && s <= B) ans+=i;
    }
    cout << ans << endl;
}


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

// DATA TYPES
typedef long long ll;
#define double long double
//

// CONTAINERS
#define vec vector
#define pb push_back
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)x.size()
#define mp make_pair
#define ii pair<int, int>
#define F first
#define S second
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U> &L, const std::pair<T,U> &R) {
  return {L.first + R.first, L.second + R.second};
}
//

// LOOP
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
//

// BIT
#define bitcount(n) __builtin_popcountll(n)
//

// DEBUG
#define format(x) << #x << ": " << (x)
#define com << ", "
#define ndl << "\n"
#define debug1(x) cerr format(x) ndl;
#define debug2(x, y) cerr format(x) com format(y) ndl;
#define debug3(x, y, z) cerr format(x) com format(y) com format(z) ndl;
void debug_out() { cerr << "\n"; }
template <typename H, typename... T> 
void debug_out(H h, T... t) { cerr << " " << (h); debug_out(t...); }
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
// 

// CONSTANTS
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
//

// NUMERICAL OPERATIONS
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}
//

// Init variables here
const int N = 1e6 + 7;

void init() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

void solve() {
  string w[3] = {"Sunny", "Cloudy", "Rainy"};
  string s;
  cin >> s;
  FOR(i, 0, 3) {
    if (s == w[i]) {
      cout << w[(i + 1) % 3] << "\n";
      return;
    }
  }
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    init();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<string> possibles;
    for (int bit = 0; bit < (1 << n - 1); bit++) {
        string possible = "";
        for (int i = 1; i < n; i++) {
            possible += s.at(i - 1);
            if (bit & 1 << i - 1) possible += "+"; 
        }
        possible += s.at(n - 1);
        possibles.push_back(possible);
    }
    long long total = 0;
    for (int i = 0; i < possibles.size(); i++) {
        string tmp = "";
        for (int j = 0; j < possibles.at(i).size(); j++) {
            if (possibles.at(i).at(j) == '+') {
                total += stoi(tmp);
                tmp = "";
            } else {
                tmp += possibles.at(i).at(j);
                if (j == possibles.at(i).size() - 1) total += stoll(tmp);
            }
        }
    }
    cout << total << endl;


    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <math.h>
using namespace std;

int main() {
    int n,k;
    cin >> n >> k;
    vector<char> s(n);
    for(int i = 0; i < n; i++){
        cin >> s.at(i);
    }
    
    s.at(k-1) = tolower(s.at(k-1));
    
    for(int i = 0; i<n; i++){
        cout << s.at(i);
    }
}


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++)

int main () {
  string a,b,c;
  cin >> a >> b >> c;
  cout << (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0] ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    while (a >= MOD)
        a -= MOD;
    while (a < 0)
        a += MOD;
}

void dfs(int node, auto& g, auto& dp) {
    dp[0][node] = dp[1][node] = 1;
        
    for (int v : g[node]) {
        if (dp[0][v] < 0) {
            dfs(v, g, dp);
            dp[1][node] = 1LL * dp[1][node] * dp[0][v] % MOD;
            dp[0][node] = (1LL * dp[0][node] * (dp[1][v] + dp[0][v]) % MOD) % MOD;
        }
    }
}

int main() {
    ios_base :: sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<int>> g(n);

    for (int i = 0; i < n - 1; i += 1) {
        int a, b; cin >> a >> b;
        a -= 1, b -= 1;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    vector<vector<int>> dp(2, vector<int> (n, -1));

    dfs(0, g, dp);

    cout << (dp[0][0] + dp[1][0]) % MOD;
}

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

int main() {
  int N,K,Z=0;
  cin>>N>>K;
  vector<int>p(N);
  for (int i=0;i<N;i++) {
  cin>>p.at(i);
}
  vector<vector<int>> l(N+1,vector<int>(N+1,-1000000000));
  vector<vector<int>> r(N+1,vector<int>(N+1,-1000000000));
  for(int i=0;i<=N;i++){
    l.at(i).at(0)=0;
    r.at(i).at(0)=0;
  }
  for(int i=1;i<=N;i++){
    for(int j=1;j<=i;j++){
      l.at(i).at(j)=max(l.at(i-1).at(j),l.at(i-1).at(j-1)+p.at(i-1));
      r.at(i).at(j)=max(r.at(i-1).at(j),r.at(i-1).at(j-1)+p.at(N-i));
    }
  }
  
  for(int i=0;i<=N;i++){
    for(int j=0;j<=i;j++){
      for(int k=max(0,j+i-K);k<=j;k++){
        for(int m=max(0,2*i-K-k);m<=i-j;m++){
          Z=max(Z,l.at(j).at(k)+r.at(i-j).at(m));
        }
      }
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 256
import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

def main():
	d, t, s = read()
	print("YNeos"[d/s > t::2])


if __name__ == "__main__":
	main()


Measured memory_bytes: 65224
// Justice will be served
// شهید حاج قاسم سلیمانی

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

#define all(x) x.begin() , x.end()

#define PB push_back
#define F first
#define S second
#define _sz(x) (int)x.size()

#define debug(x) cerr << #x << " = " << x << endl

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

const int MAX_N = -1 ;
const int inf = 2e9 + 19 ;

int main() {
        ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
        int a , b , c ;
        cin >> a >> b >> c ;
        if (a + b + c >= 22)
                cout << "bust" ;
        else
                cout << "win" ;
        return (0) ;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
char str[500100];
int dp[500100];
struct node{
	int l,r;
}a[2000100];
bool cmp(const node &A,const node &B){
	return A.r<B.r;
}
int num;
int Max(int x,int y){
	return x>y?x:y;
}
int tr[2000100];
int qury(int x){
	int res=0;
	while(x){
		if(tr[x]>res) res=tr[x];
		x-=x&(-x);
	}
	return res;
}
int n;
void insert(int x,int v){
	while(x<=n){
		if(v>tr[x]) tr[x]=v;
		x+=x&(-x);
	}
}
int main(){
//	freopen("A.in","r",stdin);
	scanf("%d",&n);
	scanf("%s",str+1);
	for(int i=1;i<=n;i++){
		if(str[i]=='0'&&str[i+1]=='1'&&str[i-1]=='1')
		{
			for(int j=i-1;j>=0;j--)
			{
				if(str[j]!='1'){
					a[++num]=(node){j+1,i+1};
					if(j<i-2) a[++num]=(node){j+2,i+1};
					break;
				}
			}
			for(int j=i+1;j<=n+1;j++){
				if(str[j]!='1'){
					a[++num]=(node){i-1,j-1};
					if(j>i+2)
						a[++num]=(node){i-1,j-2};
					break;
				}
			}
		}
	}
	sort(a+1,a+num+1,cmp);
	int ans=0,v;
	for(int i=1;i<=num;i++)
	{
		v=qury(a[i].l-1);
		v=v+a[i].r-a[i].l-1;
		insert(a[i].r,v);
		ans=Max(ans,v);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int a, b;
    cin >> a >> b;
    if(a<=8&&b<=8) out("Yay!");
    else out(":(");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
	int n;
	cin >>n;
	vector<int>a(n);
	//xorは繰り上がりができないので和より小さくなりがち
	//繰り上がりがない時，xorは和と同値
	//繰り上がりがない時すべてのbitに対して1の個数は1か0
	//左端から右端の「間の」すべてでも成立するのでは?
	//右端がOKなら右端-1もOK
	//1 2 4 1 2
	//というか桁を考えなくても右端は求まる
	rep(i,n)
		cin >>a[i];
	long long int ans=0;
	int r=0;
	long long int tmp=0;
	for (int l=0;l<n;l++){
		for(int i=r;i<n;++i){
			if ((tmp+a[i])!=(tmp^a[i]))
				break;
			r=i+1;
			tmp+=a[i];
		}
		ans+=r-l;
		tmp-=a[l];
	}

	cout <<ans;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int a[100][100], b[100], i, j, n, m, c[100] ;

	scanf("%d %d", &n, &m);

		for (i = 0; i < n; i++) {
			for (j = 0; j < m; j++) {
				scanf("%d ", &a[i][j]);
			}
		}

		for (i = 0; i < m; i++) {
			scanf("%d", &b[i]);
		}

		c[0] = 0;

		for (i = 0; i < n; i++) {
			for (j = 0; j < m; j++) {
				if (j == 0) {
					c[i] = a[i][j] * b[j];
				}
				else
				c[i] = a[i][j] * b[j] + c[i];
			}
		}





		for (i = 0; i <n; i++) {
			printf("%d\n", c[i]);
		}


		
	return 0;
}


Measured memory_bytes: 2048
k, x = gets.split().map(&:to_i)

ary = []

min = x - (k - 1)
max = x + (k - 1)

min = -1000000 if min < -1000000
max = 1000000 if max > 1000000

(max-min+1).times do |i|
  ary << min+i
end

print ary.join(' ')

Measured memory_bytes: 1788
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

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

    cout << max(A - 2 * B, 0) << endl;

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> A(N+1,0);
  vector<int> B(N+1,0);
  for(int i=1;i<N+1;i++){
    if(S[i-1]=='W') A[i] = A[i-1] + 1;
    else A[i] = A[i-1];
  }
  for(int i=N-1;i>=0;i--){
    if(S[i]=='E') B[i] = B[i+1] + 1;
    else B[i] = B[i+1];
  }
  int ans = N;
  for(int i=1;i<N+1;i++){
    ans = min(ans,A[i-1]+B[i]);
  }
  cout << ans << endl;
}

    




Measured memory_bytes: 3076
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>


using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long K, long long Q, std::vector<long long> A){
  vector<ll> v(N, 0);
  for(ll i=0; i<Q; i++) {
    v[A[i]-1]++;
  }
  for(auto x: v) {
    if(Q-x>=K)
      std::cout << NO << std::endl;
    else
      std::cout << YES << std::endl;
  }
}

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



Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=205;
int n,m,x,y,t,r,z[1010],W[N][N],L[N][N];
ll dp[1010][N];
char op[4];

void floyd(int (*dp)[N]) {
    for (int k=1;k<=n;k++) {
        dp[k][k]=0;
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                if (k!=i&&k!=j&&i!=j) {
                    if (dp[i][k]!=INF&&dp[k][j]!=INF) {
                        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
                    }
                }
            }
        }
    }
}

int main()
{
    while (true) {
        scanf("%d%d",&n,&m);
        if (n==0&&m==0) break;
        memset(W,INF,sizeof(W));
        memset(L,INF,sizeof(L));
        for (int i=1;i<=m;i++) {
            scanf("%d%d%d%s",&x,&y,&t,op);
            if (op[0]=='L') {
                L[x][y]=min(L[x][y],t);
                L[y][x]=L[x][y];
            } else {
                W[x][y]=min(W[x][y],t);
                W[y][x]=W[x][y];
            }
        }
        scanf("%d",&r);
        for (int i=1;i<=r;i++) scanf("%d",z+i);
        floyd(L);
        floyd(W);
        for (int i=1;i<=r;i++) {
            for (int j=1;j<=n;j++) {
                dp[i][j]=1e18;
            }
        }
        for (int i=1;i<=n;i++) dp[1][i]=W[z[1]][i]+L[z[1]][i];
        for (int i=2;i<=r;i++) {
            for (int j=1;j<=n;j++) {
                if (L[z[i-1]][z[i]]!=INF&&dp[i-1][j]!=1e18) {
                    dp[i][j]=dp[i-1][j]+L[z[i-1]][z[i]];
                }
                for (int k=1;k<=n;k++) {
                    ll dis1=L[z[i-1]][k];
                    ll dis2=W[k][j];
                    ll dis3=L[j][z[i]];
                    if (dis1!=INF&&dis2!=INF&&dis3!=INF&&dp[i-1][k]!=1e18) {
                        dp[i][j]=min(dp[i][j],dp[i-1][k]+dis1+dis2+dis3);
                    }
                }
            }
        }
        ll ans=1e18;
        for (int i=1;i<=n;i++) ans=min(ans,dp[r][i]);
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 5072
import math
import statistics
N = int(input())
L = [i for i in map(int,input().split())]
Q = []
for i in range(len(L)):
  Q.append(L[i] - (i+1))
b = statistics.median(Q)
res = 0
for i in range(N):
  res += abs(L[i] - (i+1) - b)
print(int(res))


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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

ll gcd(ll x, ll y)
{
  if (x % y == 0)
  {
    return y;
  }
  return gcd(y, x % y);
}

int main()
{
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" <<endl;
  }else{
    cout << "consonant" <<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef complex<double> Point;
typedef Point Vector;
typedef pair<Point, Point> Segment;
typedef Segment Line;
constexpr double EPS = (1e-9L);
enum CCW { ONLINE_FRONT = -2, CLOCKWISE, ON_SEGMENT, COUNTER_CLOCKWISE, ONLINE_BACK };
double dot(const Point& p1, const Point& p2) { return (conj(p1) * p2).real(); }
double cross(const Point& p1, const Point& p2) { return (conj(p1) * p2).imag(); }
constexpr bool eq(double a) { return abs(a) < EPS; }
Point project(Segment s, Point p) {
	Vector base = s.fi - s.se;
	double r = dot(p - s.fi, base) / norm(base);
	return s.fi + base * r;
}
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
int ccw(const Point& p1, const Point& p2, const Point& p3) {
	Point a = p2 - p1, b = p3 - p1;
	if (cross(a, b) > EPS) return 1;
	if (cross(a, b) < -EPS) return -1;
	if (dot(a, b) < -EPS) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
bool intersect(Point p1, Point p2, Point p3, Point p4) {
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment &s1, Segment &s2) {
	return intersect(s1.fi, s1.se, s2.fi, s2.se);
}
double getDistance(Point &a, Point &b) { return abs(a - b); }
double getDistanceLP(Line &l, Point &p) {
	return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi));
}
double getDistanceSP(Segment &s, Point &p) {
	if(dot(s.se - s.fi, p - s.fi) < 0.0) return abs(p - s.fi);
	if(dot(s.fi - s.se, p - s.se) < 0.0) return abs(p - s.se);
	return getDistanceLP(s, p);
}
double getDistance(Segment &s1, Segment &s2) {
	if(intersect(s1, s2)) return 0.0;
	return min(min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se)),
				min(getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se)));
}
int main() {
	cout << setprecision(10) << fixed;
	double x0, y0, x1, y1, x2, y2, x3, y3;
	int q; cin >> q;
	rep(i, 0, q) {
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		P(intersect(Point(x0, y0), Point(x1, y1), Point(x2, y2), Point(x3, y3)) ? 1 : 0);
	}
	return 0;
}

Measured memory_bytes: 3344
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
int b[50],a[50];
int n,r,p,c;
void sol();
int main(){
	while (1){
		cin >> n >> r;
		if (n==0 && r==0) 	return 0;
		for(int i= 0;i<n;i++){
			b[i] = i+1;
		}

		for(int i=0;i<r;i++){
			cin >> p >> c ;
			sol();
			for(int i= 0;i<n;i++){
			//	cout << b[i] << " " << a[i] <<endl;
				b[i] = a[i];
				
			}				
		}
		cout << a[n-1] << endl;
	}

}

void sol(){
	for(int i= 0;i<n-p-c+1;i++){
		a[i]=b[i];
	}
	for(int i=n-p-c+1;i<n-c;i++){
		a[i]=b[c+i];
	}
	for(int i=n-c;i<n;i++){
		a[i]=b[i-p+1];
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  int x,y;
  cin>>x>>y;
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      if(i+j==x&&(2*i)+(4*j)==y){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  ll x; cin >> x;

  vector<ll> v;
  rep(i,121) {
    v.push_back((ll)pow(i,5));
  }

  rep(i,121) {
    rep(j,121) {
      if(v[i] - v[j] == x) {
	cout << i << " " << j << "\n";
	return 0;
      }
    }
  }
  
  rep(i,121) {
    rep(j,121) {
      if(v[i] + v[j] == x) {
	cout << i << " " << -j << "\n";
	return 0;
      }
    }
  }  
  return 0;
}


Measured memory_bytes: 4056
while 1:
    n,m=map(int,input().split())
    if n==m==0:break
    li=[]
    for i in range(n):
        li.append(int(input()))
    s_li=[li[0]]
    for i in range(1,n):
        s_li.append(s_li[-1]+li[i])
    c_li=[s_li[m-1]]
    for i in range(n-m):
        c_li.append(s_li[i+m]-s_li[i])
    print(max(c_li))


Measured memory_bytes: 15536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005;
const ll INF=1LL<<60;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    if(N==2){
        cout<<-1<<endl;
        return 0;
    }else if(N==3){
        cout<<"aa.\n..b\n..b\n";
    }else if(N%2==0){
        vector<vector<char>> S(N,vector<char>(N,'.'));
        
        for(int i=0;i<N/2;i++){
            S[i*2][i*2]='a';
            S[i*2+1][i*2]='a';
            
            S[i*2][i*2+1]='b';
            S[i*2+1][i*2+1]='b';
            
            S[i*2][(i*2+2)%N]='c';
            S[i*2][(i*2+3)%N]='c';
            
            S[i*2+1][(i*2+2)%N]='d';
            S[i*2+1][(i*2+3)%N]='d';
        }
        
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                cout<<S[i][j];
            }
            cout<<endl;
        }
    }else if(N==7){
        vector<string> S={"ccbbaa.","ee.ee.a","..f..fa","..f..fb","ee.ee.b","..f..fc","..f..fc"};
        
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                cout<<S[i][j];
            }
            cout<<endl;
        }
    }else{
        vector<vector<char>> S(N,vector<char>(N,'.'));
        vector<string> T={"aabbc","hii.c","h..jd","g..jd","gffee"};
        
        int a=(N-5)/2;
        
        for(int i=0;i<a;i++){
            S[i*2][i*2]='a';
            S[i*2+1][i*2]='a';
            
            S[i*2][i*2+1]='b';
            S[i*2+1][i*2+1]='b';
            
            S[i*2][(i*2+2)%(N-5)]='c';
            S[i*2][(i*2+3)%(N-5)]='c';
            
            S[i*2+1][(i*2+2)%(N-5)]='d';
            S[i*2+1][(i*2+3)%(N-5)]='d';
        }
        
        for(int i=N-5;i<N;i++){
            for(int j=N-5;j<N;j++){
                S[i][j]=T[i-(N-5)][j-(N-5)];
            }
        }
        
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                cout<<S[i][j];
            }
            cout<<endl;
        }
    }
}


Measured memory_bytes: 2304
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/



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

    ll x, y;
    cin>>x>>y;
    ll res = 1e18;
    if (x<=y) res = min(res, y-x);
    res = min(res, 1 + abs(y + x));
    res = min(res, 2 + abs(y - x));
    
    cout<<res;

}




Measured memory_bytes: 256
A = int (input())
B = int (input())
C = int (input())
X = int (input())

ans = 0

for x in range(A+1):
    for y in range(B+1):
        for z in range(C+1):
            if 500 * x + 100 * y + 50 * z == X:
                ans +=1

print(ans)

Measured memory_bytes: 3060
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  int64_t sum = 0;
  int64_t sumko = 0;
  int num = 0;
  int64_t k,t,s,r;
  k = 0; t = 0; s = 0; r = 0;
  for(int a=1;a<=n;a++){
    for(int b=1;b<=n;b++){
      for(int c=1;c<=n;c++){
        if(a >= b){
          k = a;
          t = b;
          for(;;){
          s = k/t;
          r = k%t;
          if(r==0)break;
          k = t;
          t = r;          
        }//mugenend
        num = t;
        }
        else{
          k = b;
          t = a;
          for(;;){
          s = k/t;
          r = k%t;
          if(r==0)break;
          k = t;
          t = r;          
        }//mugenend
        num = t;
        }//else end
        if(num >= c){
          k = num;
          t = c;
          for(;;){
          s = k/t;
          r = k%t;
          if(r==0)break;
          k = t;
          t = r;          
        }//mugenend
        sumko = t;
        }
        else{
          k = c;
          t = num;
          for(;;){
          s = k/t;
          r = k%t;
          if(r==0)break;
          k = t;
          t = r;          
        }//mugenend
        sumko = t;
        }//else end
        sum += sumko;
      }
    }
  }
  cout << sum << endl;  
}

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

int main() {
  char c;
  cin >>  c;

  if (c=='a' || c=='i' || c=='u' || c=='e' || c=='o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


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

using namespace std;
using ll=long long;

void solve() {
    string s; cin >> s;
    int n = s.size();
    string t;
    for (int i = 0; i < n; i++) {
        if (s[i]=='A') t += 'A';
        else if (s[i] == 'C') t += '#';
        else {
            if (i+1 < n && s[i+1] == 'C') {
                t += 'D'; i++;
            } else {
                t += '#';
            }
        }
    }
    n = t.size();

    ll res = 0;
    int ant = 0;
    for (char c: t) {
        if (c == '#') ant = 0;
        else if (c == 'A') ant++;
        else if (c == 'D') res += ant;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 916
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    S = input()
    if S == 'ABC':
        print("ARC")
    else:
        print("ABC")

if __name__ == '__main__':
    main()

Measured memory_bytes: 65216
#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<int, int> pii;
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() {
  string s;
  cin >> s;
  int n = s.length();
  int i = 0;
  int ans = 0;
  int cnt = 0;
  rep(i,n) {
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') cnt++;
    else {
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans,cnt);
  cout << ans << endl;
}

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

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/* sort the job w/ deadline asc (start time order does not matter) */

typedef tuple<int,int> Job;

bool cmp(const Job& x, const Job& y)
{
    int a,b,aa,bb; tie(a,b) = x; tie(aa,bb) = y;
    if (b == bb)
        return a > aa;
    return b < bb;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        vector<Job> A;
        FOR(i,0,n) {
            int a,b; cin >> a >> b;
            A.push_back(Job(b-a,b));
        }
        sort(ALL(A),cmp);
        int t = 0; bool good = true;
        FOR_ALL(a,A) {
            int x,y; tie(x,y) = *a;
            if (t > x)
                good = false;
            t += y-x;
        }
        cout << (good ? "Yes" : "No") << endl;
    }
    return 0;
}


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

int main() {
    int n, k; scanf("%d%d", &n, &k);
    double ret = 0;
    for (int i = 1; i <= n; i++) {
        double tmp = 1.0/n;
        int now = i;
        while (now < k) {
            now *= 2;
            tmp /= 2;
        }
        ret += tmp;
    }

    printf("%.12f\n", ret);
    return 0;
}

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

int main() {
	long long march[5];
	for (int i = 0; i < 5; i++) {
		march[i] = 0;
	}
	int n;
	cin >> n;
	char s[15];
	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s[0] == 'M') {
			march[0]++;
		}
		if (s[0] == 'A') {
			march[1]++;
		}
		if (s[0] == 'R') {
			march[2]++;
		}
		if (s[0] == 'C') {
			march[3]++;
		}
		if (s[0] == 'H') {
			march[4]++;
		}
	}
	int P[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
	int Q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
	int R[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
	long long count = 0;
	for (int i = 0; i < 5; i++) {
		if (march[i] != 0) {
			count++;	
		}
	}
	if (count < 3) {
		cout << 0 << endl;
		return 0;
	}
	long long ans = 0;
	for (int i = 0; i < 10; i++) {
		ans += march[P[i]] * march[Q[i]] * march[R[i]];
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

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

	int x, a, b;
	cin >> x >> a >> b;
	
	if(abs(x - a) < abs(x - b)){
		cout << "A" << endl;
	}else{
		cout << "B" << endl;
	}
}


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

int main() {
	int k, x;
	cin >> k >> x;
	int a0 = x - k + 1;
	for (int i = 0; i < k * 2 - 1; i++) {
		int n = a0 + i;
		if (n >= -1000000 && n <= 1000000) {
			cout << n << ' ';
		}
	}
}

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

int main()
{
	int N, M;
	cin >> N;
	cin >> M;
	vector<int> like(M, 0);
	for (int i = 0; i < N; i++)
	{
		int K;
		cin >> K;
		for (int j = 0; j < K; j++)
		{
			int tmp;
			cin >> tmp;
			like[tmp - 1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < M; i++)
	{
		if (like[i]==N)
		{
			ans++;
		}
	}
	cout << ans << endl;
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	sort(a, a + 3);
	int ans = 0;

	while(true){
		if(a[0] == a[1] && a[1] == a[2]) break;
		else if(a[0] == a[1]) {
			a[0]++;
			a[1]++;
			ans++;
		}else{
			a[0] += 2;
			ans++;
		}
		sort(a, a + 3);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
indata = raw_input().split()
i = int(indata[0])
j = int(indata[1])
pixcel = []

for count in range(i):
    datalist = raw_input()
    pixcel.append(datalist)

showline = []
headder = ""
l = ""

for x in range(j + 2):
    headder = headder + "#"
showline.append(headder)

for s in pixcel:
   l = "#" +  s + "#"
   showline.append(l)
showline.append(headder)

for line in showline:
    print line






Measured memory_bytes: 2692