akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
  long N,M,L,R,l=1,r;
  long i;
  scanf("%li %li",&N,&M);
  r=N;
  for(i=1;i<=M;i++){
    scanf("%li %li",&L,&R);
    if(L>l) l=L;
    if(R<r) r=R;


  }
  if(l<=r){
    printf("%li",r-l+1);
  }

  else{
    printf("0");
  }
return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
struct rbtree: tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>{};
#define IN freopen("in.txt", "r", stdin);
#define int long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define lowb lower_bound
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mem0(a) memset((a), 0, sizeof(a))
#define mem(a, b) memset((a), (b), sizeof(a))
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const int N = 3e5+10;
const int Mod = 1e9+7;
int a[N];
int b[80];
int c[70];
int res[80];
int r2[80];
int32_t main(){
    IOS;
    //IN;
    int n; cin>>n;
    c[1] = 2;
    c[0] = 1;
    for(int i = 2; i <= 61; i++){
        c[i] = (c[i-1]*2)%Mod;
    }
    for(int i = 1; i <= n; i++)cin>>a[i];
    for(int i = 1; i <= n; i++){
        int tmp = a[i];
        int s = 0;
        while(tmp){
            if(tmp&1)b[s]++;
            s++;
            tmp>>=1;
        }
    }
    int ans =0;
    for(int i =1; i <= n; i++){
        for(int j = 0; j < 61; j++)res[j] = 0, r2[j]=0;
        for(int j = 0; j < 61; j++){
            if(!(a[i]&(1LL<<j))){
                ans += (c[j]%Mod*b[j]%Mod)%Mod;
                ans %= Mod;
            }else res[j] = b[j]-1;
        }
        int s = 0;
        while(a[i]){
            if(a[i]&1){
                b[s]--;
                r2[s]++;
            }
            s++;
            a[i]>>=1;
        }
        for(int j = 0; j < 61; j++){
            if(r2[j]){
                ans += c[j]*(n-i-res[j])%Mod;
                ans %= Mod;
            }
        }

    }
    cout<<ans%Mod;

    return 0;
}

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

int main(){
	int A,B;
	cin>>A>>B;
	double ans;
	if((B-1)%(A-1)==0){
		ans = (B-1)/(A-1);
	}
	else{
		ans = (B-1)/(A-1)+1;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
N, X = gets.split.map(&:to_i)

R = 2 * N - 1

if X == 1 || X == R
  puts 'No'
  exit
end

if N == 2
  puts 'Yes'
  puts [1, 2, 3]
  exit
end

ans = Array.new(R, -1)
used = Hash.new

if X - 2 >= 1
  ans[N - 3] = X - 2
  used[X - 2] = true
end

ans[N - 2] = X + 1
ans[N - 1] = X
ans[N] = X - 1

if X + 2 <= R
  ans[N + 1] = X + 2
  used[X + 2] = true
end

used[X] = true
used[X - 1] = true
used[X + 1] = true

n = 1

R.times do |i|
  next if ans[i] != -1

  while used[n]
    n += 1
  end

  ans[i] = n
  used[n] = true
end

puts 'Yes'
puts ans


Measured memory_bytes: 17660
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

#define rep(i, n) for (size_t i = 0; i < (size_t)(n); ++i)

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  auto avec = vector<int>(n);

  for (auto &a : avec) {
    cin >> a;
  }

  auto sum = accumulate(avec.begin(), avec.end(), 0);
  auto count = 0;

  for (auto a : avec) {
    if (a * 4 * m >= sum) {
      count++;
    }
  }

  cout << (count >= m ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
# frozen_string_literal: true

$N = gets.chomp.to_i

s = []
$N.times do
  s << gets.chomp.to_i
end

def max(a, b)
  a < b ? b : a
end
s = s.sort
sum = s.reduce(:+)

$table = Array.new(sum + 1, 0)

def point(n)
  n % 10 == 0 ? 0 : n
end

def max_a(arr)
  res = -10_000_000_000_000_000_000
  arr.each do |i|
    res = i < res ? res : i
  end
  res
end

$N.times do |i|
  (0...sum).each do |j|
    current = sum - j
    $table[current] = if s[i] <= current
                        max($table[current - 1], $table[current - s[i]] + s[i])
                      else
                        $table[current - 1]
                      end
  end
end
puts max_a($table.map { |t| point(t) })


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<int, int>  pii;
typedef pair<ld, ld>  pld;
ll n;
ll a[200000];
ll dp[200000];
ll cnt[200000];
ll mod = 1000000007;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n;
    for(ll i = 0; i < n; ++i)
        cin >> a[i];
    if(a[0] != 0){
        cout << "0\n";
        return 0;
    }
    dp[0] = 3;
    cnt[0] = 2;
    cnt[1] = 1;
    for(ll i = 1; i < n; ++i){
        dp[i] = dp[i-1]*cnt[a[i]]%mod;
        --cnt[a[i]];
        ++cnt[a[i]+1];
    }
    cout << dp[n-1]%mod << "\n";
}

Measured memory_bytes: 3584
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>

using namespace std;
vector<unsigned long long> l_num;

int main() {

	int n = 0;
	cin >> n;

	l_num.push_back(2); //0
	l_num.push_back(1); //1

	for (int i = 2; i <= n; ++i) {
		unsigned long long tmp = 0;
		tmp = l_num.at(i - 2) + l_num.at(i - 1);
		l_num.push_back(tmp);
	}

	cout << l_num.at(n) << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string s = S[0].ToString();
            string ss = S[1].ToString();
            string sss = S[2].ToString();
            if (s == "S" && ss == "S" && sss == "S") { Console.WriteLine("0"); }
            if (s == "S" && ss == "S" && sss == "R") { Console.WriteLine("1"); }
            if (s == "S" && ss == "R" && sss == "S") { Console.WriteLine("1"); }
            if (s == "R" && ss == "S" && sss == "S") { Console.WriteLine("1"); }
            if (s == "R" && ss == "R" && sss == "S") { Console.WriteLine("2"); }
            if (s == "R" && ss == "S" && sss == "R") { Console.WriteLine("1"); }
            if (s == "S" && ss == "R" && sss == "R") { Console.WriteLine("2"); }
            if (s == "R" && ss == "R" && sss == "R") { Console.WriteLine("3"); }

        }
    }
}

Measured memory_bytes: 25880
n = input()

c = 0
r = 1
for x in map(int, n):
    tc = min(c + x, r + 10 - x)
    if x == 9:
        tr = r
    else:
        tr = min(c + x + 1, r + 10 - (x + 1))
    c, r = tc, tr

print(c)


Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  ll B=0;
  ll ans=0;
  REP(i,S.size()){
    if(S[i]=='B'){
      B++;
    }
    if(S[i]=='W'){
      ans += B;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 720
/**
*   @Author : MeGA
*   @InitTime :02/08/20 16:22:28
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif

     ios::sync_with_stdio(false);
     cin.tie(0);
     long long a,b;
     cin>>a>>b;
     if(b-a > 3000){
        cout<<0<<endl;
        return 0;
     }

     long long ans=2e9;
     for(long long i=a;i<=b;i++){
        for(long long j=i+1;j<=b;j++){
             ans=min((i*j)%2019,ans);
        }
     }
     cout<<ans<<endl;
    
}

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

using namespace std;

int n;
vector<int> v[maxn];
int x, y;

int dfs(int i, int fa){
	int cnt = 0;
	for(int j = 0;j < v[i].size();j++){
		int to = v[i][j];
		if(to == fa) continue;
		cnt += dfs(to, i);
	}
	if(cnt > 1) printf("First"), exit(0);
	return cnt ^ 1; 
}

int main(){
	scanf("%d", &n);
	for(int i = 1;i < n;i++){
		scanf("%d%d", &x, &y);
		v[x].push_back(y), v[y].push_back(x);
	}
	printf(dfs(1, 0) ? "First" : "Second");
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll n,m;
    ll u,v,s,t;
    cin>>n>>m;
    vector< vector<ll> > d(n,vector<ll>(3,-1));
    vector< vector<ll> > G(n,vector<ll>());
    rep(i,m){
        cin>>u>>v;
        u--;v--;
        G[u].push_back(v);
    }
    cin>>s>>t;
    s--;t--;
    queue<P> que;
    que.push(P(s,0));
    d[s][0] = 0;
    while(!que.empty()){
        P p = que.front();que.pop();
        ll v = p.first;
        ll parity = p.second;
        for(auto nv:G[v]){
            ll np = (parity + 1) % 3;
            if(d[nv][np]== -1){
                d[nv][np] = d[p.fi][parity] + 1;
                que.push(P(nv,np));
            }
        }
    }
    if(d[t][0]==-1) cout<<-1<<endl;
    else cout<<d[t][0]/3<<endl;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define push_back pb
#define make_pair mp
using ll =  long long;
const int INF = 0x3f3f3f3f;

int A, B;

void solve()
{
	if(A>=13) cout << B << endl;
	else if(A>=6&&A<=12)cout << B/2 << endl;
	else cout << 0 << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> A >> B;
	solve();
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        String[] moji = new String[h+1];
        String moji2="";
        
        
        for(int i =0;i<w+2;i++){
             moji2+="#";
        }

        for(int i = 1;i<h+1;i++){
            moji[i] = "#"+sc.next()+"#";
        }

        for(int i = 0;i<h+2;i++){
            if(i==0){
                System.out.println(moji2);
            }else if(i==(h+1)){
                System.out.println(moji2);
            }else{
                System.out.println(moji[i]);
            }
        }
    }
}






Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <complex.h>
#include <stdio.h>

namespace mp = boost::multiprecision;
// 仮数部 500 bit の浮動小数点数
using cpp_dec_float = mp::number<mp::cpp_dec_float<20>>;

int main() {

  cpp_dec_float A,B,H,M;
  
  std::cin >> A >> B >> H >> M;
  
	cpp_dec_float result,theta;
  
  theta = abs((60*H+M)/2 - 6*M);
  
  /*if(theta>180){
  	theta = 360 - theta;
  }*/
  
 // std::cout << "cos : " << cos(M_PI * theta / 180) << endl;
  
  result =sqrt( A*A + B*B - 2*A*B*cos(M_PI*theta/180));
    
    std::cout << std::setprecision(std::numeric_limits<decltype(result)>::digits10 )<< result;
  
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int n, k, cur=0;
int a[N];

int32_t main()
{
	IOS;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=40;i>=0;i--)
	{
		int cnt=0;
		for(int j=1;j<=n;j++)
		{
			//cout<<a[j]<<" "<<i<<" "<<(int)(a[j]>>i)<<endl;
			if((a[j]>>i)&1)
				cnt++;
		}
		if(cnt*2<n && (cur+(1LL<<i)<=k))
			cur+=(1LL<<i);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans+=(cur^a[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int a[2000], n;

int solve(int i, int m){
	if (i == n){
		if (m == 0){
			return (1);
    }else {
      return (0);
		}
	}
	if (solve(i + 1, m - a[i]) == 1||solve(i + 1, m) == 1){
		return (1);
    }
	return (0);
}

int main(void)
{
	
	int  Q,M,i;
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	scanf("%d", &Q);
	
	for (i = 0; i < Q; i++){
		scanf("%d", &M);
		
		if (solve(0, M)){
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String str = br.readLine();
			StringTokenizer st = new StringTokenizer(str, " ");
			int a = Integer.parseInt(st.nextToken());
			String op = st.nextToken();
			int b = Integer.parseInt(st.nextToken());

			int ans =0;

			if(op.equals("+")){
				ans = a + b;
				System.out.println(ans);
			}else if(op.equals("-")){
				ans = a - b;
				System.out.println(ans);
			}else if(op.equals("*")){
				ans = a * b;
				System.out.println(ans);
			}else if(op.equals("/")){
				ans = a / b;
				System.out.println(ans);
			}else if(op.equals("?")){
				break;
			}
		}
	}
}



Measured memory_bytes: 24200
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int A, B, C, K;
    std::cin >> A >> B >> C >> K;
    int cnt(0);
    while(A >= B){
        ++cnt; B *= 2;
    }
    while(B >= C){
        ++cnt; C *= 2;
    }
    std::cout << ((cnt <= K) ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    rep(i, N) { cin >> w[i] >> v[i]; }
    vector<vector<ll>> dp(N + 1, vector<ll>(101000));
    // dp[i][j]:=i-1番目まで見て重さjのもので価値が最大のもの
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 101000; j++) {
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
            if(j + w[i] < 101000)
                dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
        }
    }
    ll res = 0;
    for(int i = 0; i <= W; i++) {
        res = max(dp[N][i], res);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 84044
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  		ll i,n,u,v,ans;
		cin>>n;
		ans = (n*(n+1)*(n+2))/6;
		for(i=0;i<n-1;i++) 
		{
			cin>>u>>v;
			ans-=((min(u,v))*(n-max(u,v)+1));	
		}    
		cout<<ans;
		return 0;
} 

Measured memory_bytes: 3640
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> D;
  Vec(C,lli,26,0);
  rep(i,0,26)cin >> C[i];
  DV(A,lli,D,26,0);
  rep(i,0,D)rep(j,0,26)cin >> A[i][j];
  Vec(last,lli,26,-1);
  rep(i,0,D){
    num=0;
    int flag2=0;
    rep(j,0,26){
      flag=A[i][j];
      int temp=last[j];
      last[j]=i;
      rep(k,0,26)flag-=C[i]*(i-last[j]);
      last[j]=temp;
      if(flag>num){
        num=flag;
        flag2=j;
      }
    }
    last[flag2]=i;
    sum+=num;
    Out(flag2+1);
  }
}

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

struct Node {
  int key;
  struct Node* parent;
  struct Node* left;
  struct Node* right; 
};

typedef struct Node * NodePointer;


void insert(NodePointer,int);
void search(NodePointer,int);
void preorder(NodePointer);
void inorder(NodePointer);
void postorder(NodePointer);


int main ()
{
  int a,b;
  int i;
  char input[8];

  NodePointer tree = (NodePointer) malloc (sizeof(struct Node));

  
  scanf("%d\n",&a); 
	
  for (i = 0; i  < a; i++){
    scanf("%s" ,&input);
		
    if ( strcmp( input , "insert") == 0 ){
      scanf("%d\n",&b);
      
      if ( i == 0)
	{
	  tree -> key = b;
	  tree -> right = NULL;
	  tree -> left = NULL;
	}  
      else {insert(tree , b);
      }
    }
    else if ( strcmp( input , "find") == 0 ){
      scanf("%d\n",&b);
      search( tree , b);
    }
    else {
      inorder(tree);
      printf("\n");
			
      preorder(tree);
      printf("\n");
    }
  }	
	
  return 0;
}


void insert(NodePointer s,int t)
{
  NodePointer x;
  
  if ( s -> key <= t){
    if  ( s -> right  == NULL){
      x =  (NodePointer) malloc (sizeof(struct Node));
      x -> key = t;
      x -> right = NULL;
      x -> left = NULL;
      s -> right = x;
    }
    
    else {
      insert ( s -> right , t);
    }
	
  }
  else {
    if  ( s -> left  == NULL){
      x =  (NodePointer) malloc (sizeof(struct Node));
      x -> key = t;
      x -> right = NULL;
      x -> left = NULL;
      s -> left = x;
    }
    else {
      insert ( s -> left , t);
    }
  }
}


void search(NodePointer s,int tag)
{
  int flag = 0;
  
  while (s != NULL){
    if (s -> key == tag){flag = 1; break;}
    
    else if (s -> key >= tag){
      s = s -> left;
    }
    else {
      s = s -> right;
    }
  }
  
  if (flag == 0 ){ printf("no\n");
  }
  else if (flag == 1){printf("yes\n");}
}


void preorder ( NodePointer s)
{
  if (s == NULL){return;}
  
  printf(" %d",s->key);
  preorder(s -> left);
  preorder(s -> right);
}


void inorder (NodePointer s)
{
  if (s == NULL){return;}
  
  inorder(s ->left);
  printf(" %d",s->key);
  inorder(s->right);
}


void postorder (NodePointer s)
{
  if (s == NULL){return;}
  
  postorder(s->left);
  postorder(s->right);
  printf(" %d",s->key);
}



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

int main()
{
    int N;
    cin >> N;
    int prev = 1;
    int next = 10;
    int cnt = 0;
    while(prev <= N) {
        cnt += min(next - prev, (N+1) - prev);
        prev *= 100; next *= 100;
    }
    cout << cnt << endl;
    return 0;
}

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

ll rui(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}

ll comb(ll a, ll b) {
  ll ans = 1;
  for (ll i = a; i > a - b; i--) {
    ans = ans * i % mod;
  }
  for (ll i = 1; i <= b; i++) {
    ans = (ans * rui(i, mod - 2)) % mod;
  }
  return ans;
}

int main() {
  int X, Y;
  cin >> X >> Y;
  if ((X + Y) % 3 != 0)
    cout << 0 << endl;
  else {
    int A = (X + Y) / 3;
    X -= A;
    Y -= A;
    if (X < 0 || Y < 0)
      cout << 0 << endl;
    else {
      cout << comb(A, X) << endl;
    }
  }
}


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

int main(){

    char b;
    
    cin >> b;

    if(b=='A'){
        cout << "T" << endl;
    }else if(b=='G'){
        cout << "C" << endl;
    }else if(b=='T'){
        cout << "A" << endl;
    }else {
        cout << "G" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto X = RD;

	long ans = 2;
	if (X != 2)
	{
		foreach (i; X..10^^9)
		{
			bool ok = true;
			for (long j = 2; j*j <= X; ++j)
			{
				if (i % j == 0)
				{
					ok = false;
					break;
				}
			}
			if (ok)
			{
				ans = i;
				break;
			}
		}
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

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

void swap(int *a,int *b){
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void bubblesort(int array[],int number){
    int cnt = 0;
    for(int i = 0;i < number;i++){
        for(int j = number-1;j > i;j--){
            if(array[j-1] > array[j]){
                swap(array[j-1],array[j]);
                cnt++;
            }
        }
    }
    for(int i = 0;i < number;i++){
        if(i != 0) printf(" ");
        printf("%d",array[i]);
    }
    printf("\n%d\n",cnt);
}

int main(){
    int num;
    int origin[100];
    cin >> num;
    for(int i = 0;i < num;i++) cin >> origin[i];
    bubblesort(origin,num);
    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,K;
	cin >> N >> K;
	vector<int64_t> vec(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> vec.at(i);
	}
//昇順ソート
	sort(vec.begin(),vec.end());
	int64_t sum=0;
	if(N<=K){
		cout << 0 << endl;
	}
	else{
		for (int i = 0; i < N-K; ++i)
		{
			sum+=vec.at(i);
		}
		cout << sum << endl;
	}
}

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

typedef long long ll;
#define mx 100005

const ll inf = 1e18;
int n,k,a[mx];
ll DP[mx];
ll dp(int i)
{
    if(i>=n) return inf;
    if(i==n-1) return 0;
    if(DP[i]!=-1) return DP[i];
    ll minn=inf;
    for(int index=i+1;index<=i+k && index<=n-1;index++)
    {
        minn=min(abs(a[index]-a[i])+dp(index),minn);
    }
    return DP[i]=minn;
}
int main()
{
    scanf("%d",&n);
    scanf("%d",&k);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    memset(DP,-1,sizeof(DP));
    ll ans = dp(0);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6144
import math

N = int(input())
min_move_count = 10**13

for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        move_count = i + (N // i) - 2
        if move_count < min_move_count:
            min_move_count = move_count

ans = min_move_count
print(ans)


Measured memory_bytes: 9156
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<complex>
using namespace std;

int main(){
  while(true){
    string s; cin >> s;
    if(s == "-") break;
    int n; cin >> n;
    for(int i = 0; i < n; i++){
      int nn; cin >> nn;
      s = s.substr(nn,s.size()-nn) + s.substr(0,nn);
    }
    cout << s << endl;
  }
  return 0;
}



Measured memory_bytes: 3208
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from collections import deque

N,M = map(int,input().split())
words = [deque(input().rstrip()) for _ in range(N)]

# 深さLのfull treeの小さい方を計算してみる
def G_small():
    G = [0] * 100
    G_cum = [0] * 100
    G[0] = 1
    G_cum[0] = 1
    for n in range(1,100):
        can_make = set(G_cum[n-1]^G_cum[x] for x in range(n)) | set([G_cum[n-1]])
        rest = set(range(n+10)) - can_make
        G[n] = min(rest)
        G_cum[n] = G_cum[n-1] ^ G[n]
    return G

# print([(n,G[n]) for n in range(100)])
# G[n] = 2**ord_2(n+1)
# 値がわかれば証明は易しい

def G(n):
    n += 1
    x = 1
    while not n & 1:
        n >>= 1
        x <<= 1
    return x

def calc_grandy(words,L):
    if not words:
        return G(L)
    if len(words) == 1 and words[0] == deque():
        return 0
    words_0 = []
    words_1 = []
    for word in words:
        first = word.popleft()
        if first == '0':
            words_0.append(word)
        else:
            words_1.append(word)
    return calc_grandy(words_0,L-1) ^ calc_grandy(words_1,L-1)

g = calc_grandy(words,M)

answer = 'Alice' if g != 0 else 'Bob'
print(answer)

Measured memory_bytes: 106656
//#include "bits/stdc++.h"
//using namespace std;
//typedef long long ll;
//typedef pair<int,int> pii;
//#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
//#define all(a)  (a).begin(),(a).end()
//#define pb push_back
//#define INF 999999999

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
#define INF 999999999

#define MAX_V 100001


//each_scc  : ????????????????????£?????????????????????
//cmp[i]    : ?????????i????±??????????????????£??????????????????

vector<int> G[MAX_V];
vector<int> rG[MAX_V];

void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v, bool used[MAX_V], vector<int> &vs){
    used[v] = true;
    rep(i,G[v].size()){
        if(!used[G[v][i]])dfs(G[v][i],used,vs);
    }
    vs.push_back(v);
}

void rdfs(int v,int k,vector<int> &sccs, vector<int> &cmp, bool used[MAX_V]){
    used[v] = true;
    sccs.pb(v);
    cmp[v] = k;
    rep(i,rG[v].size()){
        if(!used[rG[v][i]])rdfs(rG[v][i],k,sccs,cmp,used);
    }
}

int scc(int V, vector< vector<int> > &each_scc, vector<int> &cmp){
    vector<int> vs;
    bool used[MAX_V];
    rep(i,MAX_V)used[i] = false;
    vs.clear();
    rep(v,V){
        if(!used[v]) dfs(v, used, vs);
    }
    
    rep(i,MAX_V) used[i] = false;
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        vector<int> sccs;
        if(!used[vs[i]]){
            rdfs(vs[i], k++, sccs, cmp, used);
            each_scc.pb(sccs);
        }
    }
    return k;
}

int main(){
    int v,e;
    cin>>v>>e;
    rep(i,e){
        int s,t;
        cin>>s>>t;
        add_edge(s,t);
    }
    vector< vector<int> > each_scc;     //????????????????????£?????????????????????
    vector<     int     > cmp(MAX_V);   //???????????????????±??????????????????£??????????????????
    scc(v,each_scc,cmp);
    
    int q;
    cin>>q;
    rep(i,q){
        int a,b;
        cin>>a>>b;
        if(cmp[a]==cmp[b])cout<<1<<endl;
        else cout<<0<<endl;
    }
}

Measured memory_bytes: 7572
from numpy import array, add

n = int(input())
jobs = [list(map(int, input().split())) for i in range(n)]

jobs.sort(key=lambda x:x[1])

flg = True

a, b = array(jobs).T

s = add.accumulate(a)
if sum(s > b):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 65492
a, b = list(map(int, input().split()))
s = input()
flag = True
for i in range(a + b + 1):
    try:
        if i < a or i > a:
            if str(int(s[i])) == s[i]:
                pass
            else:
                flag = False
                break
        else:
            if s[i] == '-':
                pass
            else:
                flag = False
                break
    except:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 61724
#include<stdio.h>
int main(){
	long n,i,count,j;
	int c[100000],s;
	while(1){
		scanf("%ld",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d",&s);
			if(i%2==0){
				c[i]=s;
			}else{
				c[i]=s;
				if(c[i-1]==c[i]){
				}else{
					for(j=i-1;j>=0;j--){
						if(c[j]==s) break;
						c[j]=s;
					}
				}
			}
		}
		count=0;
		for(i=0;i<n;i++){
			if(c[i]==0) count++;
		}
		printf("%ld\n",count);
	}
  return 0;
}

Measured memory_bytes: 988
#include<bits/stdc++.h>
#define M1 1000000007
#define M2 998244353
#define ll long long int
#define N (int)1e5+3
#define test(t) while(t--)
#define PI acos(-1.0)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repp(i,b,a) for(ll i=b-1;i>=a;i--)
#define clr(ar, val) memset(ar, val, sizeof(ar))
#define F first
#define S second
#define PB push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define V(a) vector<a>
#define M(a,b) map<a,b>
#define endl '\n'
#define all(x) begin(x),end(x)
#define allr(x) rbegin(x),rend(x)
#define pr(a) cout<<a<<endl;
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = { 0, -1, 0, 1 };
const int dy[4] = { -1, 0, 1, 0 };
using namespace std;

ll CalculateMex(set<ll> Set){
    ll Mex = 0;
    while(Set.find(Mex)!=Set.end()){
        Mex++;
    }
    return Mex;
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

void solve()
{
    string s,t;
    cin >> s >> t;
    ll a,b;
    cin >> a >>  b;
    string d;
    cin >> d;
    if (s == d){
        cout << a-1 << " " << b << endl;
    }
    else{
        cout << a << " " << b-1 << endl;
    }

}

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    test(t){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main(){
  std::string a, b;
  std::cin >> a;
  std::cin >> b;
  
  int count = 0;
  for(int i = 0; i < a.size(); ++i)
  {
    if(a[i] == b[i])
      count++;
  }
  
  std::cout << count << std::endl;
  
  return 0;
  
}


Measured memory_bytes: 256
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
    ll C[n + 1][k + 1]; 
    ll i, j; 


    for (i = 0; i <= n; i++) 
    { 
        for (j = 0; j <= min(i, k); j++) 
        { 
            
            if (j == 0 || j == i) 
                C[i][j] = 1; 

            else
                C[i][j] = (C[i - 1][j - 1] + 
                                        C[i - 1][j])%MOD; 
        } 
    } 

    return C[n][k]; 
}
bool compare(const string &a , const string&b){
    //set<pair<int,int> , decltype(&compare)>s(&compare) ;
}

// struct compare{
//     // for priority_queue
//     bool operator()(const int &a , const int&b){
//         return a<b ;
//     }
// };

void solve()
{
    ll r , d , x;
    cin>>r>>d>>x ;
    ll pre ;
    rep(i , 10){
        if(i==0){
            pre = r*x - d ;
            cout<<pre<<endl;
        }
        else{
            ll curr = r*pre - d ;
            cout<<curr<<endl;
            pre = curr ;
        }
    }
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3692
#061-C
n,k=map(int,input().split())
ass=[0 for i in range(10**5)]
for i in range(n):
    a,b=map(int,input().split())
    ass[a-1]+=b
c=0
for i in range(10**5):
    if ass[i]==0:
        continue
    c+=ass[i]
    if c>=k:
        print(i+1)
        break

Measured memory_bytes: 5924
#include<bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
 
#define PII pair<LL,LL>
#define mem(v, x) memset(v, x, sizeof v)
 
#define si(x) scanf("%d", &x)
#define sii(x, y) scanf("%d %d", &x, &y)
#define siii(x, y, z) scanf("%d %d %d", &x, &y, &z)
 
#define sf(x) scanf("%lf", &x)
#define endl '\n'

#define FOR(i , N) for(int i = 0  ; i < N ; i++)
#define FOR1(i , N) for(int i = 1  ; i <= N ; i++)

template <typename T> T six(T &n){n = 0;bool neg = false;char c = getchar();while( c < '0' || c > '9'){if(c == '-') neg = true;c = getchar();}while(c >= '0' && c <= '9'){n = n*10 + c-48;c = getchar();}if(neg) n = ~(n-1);return n;}

using namespace std;
 
typedef long long LL;
 
int SET(int N,int pos){return N=N | (1<<pos);}
int RESET(int N,int pos){return N= N & ~(1<<pos);}
bool CHECK(int N,int pos){return (bool)(N & (1<<pos));}

const int MOD = 1000000007;

/*
   D er iterative parlam na
   D te First WA Why???
   Probability Expected Value pari na
*/

LL add(LL x, LL y) {
   x %= MOD;
   y %= MOD;
   x += y;
   x %= MOD;
   return x;
}

int N;
int arr[21+1][21+1];
LL dp[21 + 1][(1 << 21) + 10];

LL rec(int pos, int mask) {
   if(pos == N) {
      return (mask == ((1 << N) - 1));
   }
   LL &ret = dp[pos][mask];
   if(ret != -1) return ret;
   LL ans = 0;
   for(int i = 0 ; i < N ; i++) {
      if(arr[pos][i] == 1 && CHECK(mask, i) == false) {
         ans = add(ans, rec(pos + 1, SET(mask, i)));
      }
   }
   return ret = ans;
}

int main()
{

#ifndef ONLINE_JUDGE // dont use this in toph/codemarshal
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    mem(dp, -1);
    cin >> N;
    FOR(i , N) FOR(j , N) cin >> arr[i][j];
    cout << rec(0, 0) << endl; // [pos, mask]
}  


Measured memory_bytes: 360832
/**
 *Code Author: codeknight13
 *Institution: IIT(ISM)
**/

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

/*
use these format of input when number of inputs not provided
while(scanf("%lld",&n)!=EOF)
*/

#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define vi vector< ll >
#define vii vector< vi >
#define viii vector< vii >
#define pii pair< int , int >
#define vpii vector< pii >
#define mii unordered_map< int , int >
#define mci map< char , int >
#define pq priority_queue
#define str string
#define len length()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl cout <<  endl
#define sp " "
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define itern(n) for (int i=0; i<n; i++)
#define iterni(n) for (int i=0; i<n; i++)
#define iternj(n) for (int j=0; j<n; j++)
#define iternk(n) for (int k=0; k<n; k++)
#define iterng(n) for (int g=0; g<n; g++)
#define riterni(n) for (int i=n-1; i>=0; i--)
#define riternj(n) for (int j=n-1; j>=0; j--)
#define riternk(n) for (int k=n-1; k>=0; k--)
#define riterng(n) for (int g=n-1; g>=0; g--)
#define sz(x) ((int)(x).size())
#define pi acos(1);                   /* pi */
#define inf (int)(1e9+7)
#define fl(x) int(x)
#define mod 998244353 
#define yes "Yes"
#define no "No"
#define null NULL
#define mac (int)(1e7)
//debugger
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
/*-----functions-----*/
//gcd
/*
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

//disjoint set union functions
int volume[4];
int parent[4];

void initialise_dsu() {
	for (int i=0; i<mac; i++)volume[i]=1;
	for (int i=0; i<mac; i++)parent[i]=i;
}

int find_set(int v) {
    return (v==parent[v]?v: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 (volume[a]<volume[b])swap(a,b);
		parent[b]=a;
		volume[a]+=volume[b];
	}
}
//#------------------------------complete template------------------------------#//
*/


int main() {
	fast;
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll lcm=(c*d)/(__gcd(c,d));
	a--;
	cout << (b-a)-((b/c)+(b/d)-(a/c)-(a/d)-((b/lcm)-(a/lcm)));
	// trace6((b-a+1),(b/c-a/c),(b/d-a/d),(b/lcm-a/lcm),lcm,b);
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = n.times.map{gets.to_i}
b = Array.new(5,10**15)
dp = Array.new(5).map{Array.new(n+1,0)}
dp[0] = [0,0,0,0,0]
for i in 0..n-1
    b[0] = dp[0][i]
    for j in 1..4
        b[j] = (b[j-1] < dp[j][i] ? b[j-1] : dp[j][i])
    end
    dp[0][i+1] = b[0]+a[i]
    dp[1][i+1] = b[1]+a[i]%2
    dp[1][i+1] += 2 if a[i] == 0
    dp[2][i+1] = b[2]+((a[i]%2)^1)
    dp[3][i+1] = b[3]+a[i]%2
    dp[3][i+1] += 2 if a[i] == 0
    dp[4][i+1] = b[4]+a[i]
end
ans = 10**18
for i in 0..4
    ans = dp[i][n] if ans > dp[i][n]
end
puts ans

Measured memory_bytes: 14716
package main

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

var (
	sc      = bufio.NewScanner(os.Stdin)
	mod int = 1e9 + 7
)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	N := getInt()
	var Ls []int
	for i := 0; i < N; i++ {
		Ls = append(Ls, getInt())
	}

	sort.Sort(sort.Reverse(sort.IntSlice(Ls)))

	cnt := 0
	for i := 0; i < len(Ls)-2; i++ {
		for j := i + 1; j < len(Ls)-1; j++ {
			if Ls[i] - Ls[j] < Ls[len(Ls)-1] {
				cnt += len(Ls) - (j+1)
				continue
			}

			for k := j + 1; k < len(Ls); k++ {
				if Ls[i] < Ls[j]+Ls[k] {
					cnt++
				} else {
					break
				}
			}
		}
	}
	fmt.Println(cnt)
}

func getInt() int {
	sc.Scan()
	str := sc.Text()
	value, _ := strconv.Atoi(str)
	return value
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 768
#include<stdio.h>

int main(void)
{
	int a, b, c, d, e = 0, f, g, h, i, j, k;
	for (d = 1; d <= 100; d++)
	{

		scanf("%d %d %d", &a, &b, &c);

		if (a == -1 && b == -1 && c == -1)
		{
			break;
		}
		if (a == -1 || b == -1)
		{
			printf("F\n");
			continue;
		}

		e = a + b;
		if (e >= 80)
		{
			printf("A\n");
			continue;
		}
		else if (e >= 65)
		{
			printf("B\n");
			continue;
		}
		else if (e >= 50 || c >= 50)
		{
			printf("C\n");
			continue;
		}
		else if (e >= 30)
		{
			printf("D\n");
			continue;
		}
		else if (e < 30)
		{
			printf("F\n");
			continue;
		}
	}
}


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

int main(void)
{
    int a;
    cin >> a;
    a=a%1000;
    if(a==0)
    {
        cout << "0" << endl;
    }
    else
    {
        cout << 1000 - a%1000 << endl;
    }

    return 0;
}


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

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N,Q;
    cin>>N>>Q;
    int s,t,x,d[200000];
    array<int,3> arr;
    vector<array<int,3>> vec;
    rep(i,N){
        cin>>s>>t>>x;
        arr[0]=s-x;
        arr[1]=1;
        arr[2]=x;
        vec.push_back(arr);
        arr[0]=t-x;
        arr[1]=-1;
        arr[2]=x;
        vec.push_back(arr);
    }
    rep(i,Q){
        cin>>d[i];
        arr[0]=d[i];
        arr[1]=10;
        arr[2]=0;
        vec.push_back(arr);
    }
    sort(vec.begin(),vec.end());
    set<int> S;
    map<int,int> m;
    rep(i,vec.size()){
        arr=vec[i];
        // cout<<arr[0]<<" "<<arr[1]<<" "<<arr[2]<<endl;
        if(arr[1]==1){
            S.insert(arr[2]);
        }else if(arr[1]==-1){
            S.erase(arr[2]);
        }else{
            if(S.empty()){
                m[arr[0]]=-1;
            }else{
                m[arr[0]]=*S.begin();
            }
        }
    }
    rep(i,Q){
        cout<<m[d[i]]<<endl;
    }
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  if(s.at(0)==s.at(1)&&s.at(1)==s.at(2)&&s.at(2)==s.at(3))cout<<"No";
  else if((s.at(0)==s.at(1)&&s.at(2)==s.at(3))
    ||(s.at(0)==s.at(2)&&s.at(1)==s.at(3))
     ||(s.at(0)==s.at(3)&&s.at(1)==s.at(2))){
       cout<<"Yes";}
     else{cout<<"No";}
}



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


int main(int,char**){
    long long a;
    string b;
    cin>>a>>b;
    long long res=0;
    res+=a*(b[0]-'0');
    int mod=0;
    if(b.size()>=3){
        res+=(a/10)*(b[2]-'0');
        mod+=(a%10)*(b[2]-'0')*10;
    } 
    if(b.size()>=4){
        res+=(a/100)*(b[3]-'0');
        mod+=(a%100)*(b[3]-'0');
    } 
    res+=mod/100;
    cout<<res<<endl;
}

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

int64_t patie(int64_t i, int64_t j){
  if(i == 0 && j == 1){
    return 1;
  }
  else if(i == 1 && j == 1){
    return 0;
  }
  else if(i == 1 && j <= 5){
    return min(j-1,(int64_t)3);
  }
  else if(j == 1){
    return 0;
  }
  else if(j < pow(2,i+1)-1){
    return patie(i-1, j-1);
  }
  else if(j == pow(2,i+1)-1){
    return patie(i-1,pow(2,i+1)-3) + 1;
  }
  else if(j == pow(2,i+2)-3){
    return patie(i-1,pow(2,i+1)-3)*2 + 1;
  }
  else{
    int64_t x = j - 2 - (pow(2,i+1) - 3);
    return patie(i-1,pow(2,i+1)-3) + 1 + patie(i-1,x);
  }
}

int main(){
  int64_t N, X;
  cin >> N >> X;
  cout << patie(N,X) << endl;
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_A&lang=jp
#  Naive String Search : python3
#  2018.11.26 yonezawa

import sys
input = sys.stdin.readline
#import cProfile

def main():
    s1  = str(input()).rstrip('\n')
    s2  = str(input()).rstrip('\n')
    
    s1_len = len(s1)
    s2_len = len(s2)
    sc = 1
    for k in range(1,len(s2)):
        if s2[0] != s2[k]:
            break
        sc += 1
    tc = len(set(s2))

    if (tc == 1 and s2_len > 1):
        cnt = 0
        for k in range(s1_len ):
            if (s1[k] == s2[0]):
                cnt += 1
            else:
                cnt = 0
            if (cnt >= s2_len ):
                print (cnt - s2_len)
    else:
        i = s1.find(s2)
        while i != -1 :
            print (i)
            i = s1.find(s2,i+1)


if __name__ == '__main__':
    main()
    #pr = cProfile.Profile()
    #pr.runcall(main)
    #pr.print_stats()


Measured memory_bytes: 5584
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;


int main(){
    int a,b,k;
    cin >> a >> b >> k;
    
    for(int i=a; i<a+k; i++){
        if(i<=b){
            cout<<i<<endl;
        }
    }
    
    for(int i=b-k+1; i<=b; i++){
        if(i>=a+k){
            cout<<i<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256