akhauriyash/Code-Regression huggingface dataset:
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll h,w;
    cin>>h>>w;
    char grid[h+10][w+10];
    for(ll i=1;i<=h;i++)
    {
        for(ll j=1;j<=w;j++)
        {
            cin>>grid[i][j];
        }
    }
    ll ans=0;
    for(ll i=1;i<=h;i++)
    {
        for(ll j=1;j<=w;j++)
        {
            if(grid[i][j]=='.')
            {
                ll tmp=0;
                ll visited[h+10][w+10];
                for(ll i1=1;i1<=h;i1++)
                for(ll j1=1;j1<=w;j1++)
                    visited[i1][j1]=0;
                queue< pair< pair<ll,ll>, ll > >Q;
                Q.push(mp(mp(i,j),0) );
                visited[i][j]=1;
                while(!Q.empty())
                {
                    pair<ll,ll> curr=Q.front().fi;
                    ll dist=Q.front().se;
                    tmp=max(tmp,dist);
                    Q.pop();
                    for(ll kk=0;kk<4;kk++)
                    {
                        pair<ll,ll> nei=mp(curr.fi+dx[kk],curr.se+dy[kk]);
                        if(nei.fi>=1 && nei.fi<=h && nei.se>=1 && nei.se<=w)
                        {
                            if(visited[nei.fi][nei.se])
                                continue;
                            if(grid[nei.fi][nei.se]=='#')
                                continue;
                            visited[nei.fi][nei.se]=1;
                            Q.push(mp(nei,dist+1));
                        }
                    }
                }
                //cout<<i<<" "<<j<<" "<<tmp<<endl;
                ans=max(ans,tmp);
            }
        }
    }
    cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n;
  int d[100];
  int temp;

  scanf("%d", &n);
  for(int i = 0 ; i < n; i++)
    {
      scanf("%d", &d[i]);
    }
  for(int i = 0 ; i < n; i++)
    {
      if(i == n-1)
	{
	  printf("%d", d[i]);
	  break;
	}
      printf("%d ", d[i]);
    }
  printf("\n");
  for(int i = 1; i < n; i++)
    {
      for(int j = 0; j < i; j++)
	{
	  if(d[i] < d[j])
	    {
	      temp = d[i];
	      d[i] = d[j];
	      d[j] = temp;
	    }
	}
      for(int k = 0; k < n; k++)
	{
	  if(k == n-1)
	    {
	      printf("%d", d[k]);
	      break;
	    }
	  printf("%d ", d[k]);
	}
      printf("\n");
    }
}



Measured memory_bytes: 2136
import java.util.*;

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

        int n = sc.nextInt();


        int k = sc.nextInt();

        int[] h = new int[n];

        for (int i=0; i<n; i++) h[i] = sc.nextInt();

        int ans = 0;

        for (int i=0; i<n; i++){
            if (h[i]>=k) ans++;
        }
        System.out.println(ans);
    }
}

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> inline void print(T val) { cout << val << '\n'; }

template <typename Iterator> inline void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; it = next(it)) {
    cout << *it << ' ';
  }
  cout << '\n';
}

void solve() {
  char c;cin >> c;

  if(tolower(c) == c){
    print('a');
  }else{
    print('A');
  }
}

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

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  solve();

  return 0;
}


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


int main()
{
  ll mod = 1000000007;
  int n, m;
  cin >> n >> m;
  vector<int> s(n + 1), t(m + 1);
  rep(i, n)
    cin >> s[i+1];
  rep(i, m)
    cin >> t[i+1];
  vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 1));
  for (int i=1; i<=n; i++)
    for (int j=1; j<=m; j++)
      if (s[i] == t[j])
        dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
      else
        dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod;
  if (dp[n][m] < 0)
    dp[n][m] += mod;
  cout << dp[n][m] << endl;
  return 0;
}

Measured memory_bytes: 34544
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

ll llmax(ll a, ll b){
  return a > b ? a : b;
}

struct UnionFind {
  vector<ll> par, rank;

  UnionFind(ll N) : par(N), rank(N) {
    rep(i, N){
      par[i] = -1;
      rank[i] = 0;
    }
  }

  ll root(ll x) {
    if (par[x] < 0) return x;
    return par[x] = root(par[x]);
  }

  void unite(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if (rx != ry){
      if(rank[rx] > rank[ry]){
        par[rx] += par[ry];
        par[ry] = rx;
      }else{
        par[ry] += par[rx];
        par[rx] = ry;
        if(rank[rx] == rank[ry]) rank[ry]++;
      }
    }
  }

  bool same(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    return rx == ry;
  }

  ll count(ll x){
    return -par[root(x)];
  }
};

int main(){
  ll N, M;
  cin >> N >> M;
  UnionFind tree(N);
  ll n_eq = 0;
  rep(i, M){
    ll x, y, z;
    cin >> x >> y >> z;
    if(!tree.same(x-1, y-1)) n_eq++;
    tree.unite(x-1, y-1);
  }
  ll ans = N - n_eq;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <utility>

constexpr unsigned int InputSize = 3e6;
unsigned char Input[InputSize];
unsigned char* pointer = Input;

inline unsigned int getInt(void){
    unsigned int res = 0; while(*pointer < '0') ++pointer;
    do{
        res = 10 * res + ((*pointer) - '0');
    } while(*(++pointer) >= '0');
    return res;
}

constexpr unsigned int N = 1e5 + 1;
unsigned int Par[N];
unsigned int Size[N];
unsigned int addr[N];

inline unsigned int root(const unsigned int v){
    return (Par[v] == v) ? v : (Par[v] = root(Par[v]));
}

inline bool same(const unsigned int u, const unsigned int v){
    return root(u) == root(v);
}

inline void unite(const unsigned int u, const unsigned int v){
    unsigned int pu = root(u), pv = root(v); if(pu == pv) return;
    if(Size[pu] > Size[pv]) std::swap(pu, pv);
    Size[pv] += Size[pu]; Par[pu] = pv;
}

inline unsigned int sizeOf(const unsigned int v){return Size[root(v)];}

int main(void){
    for(unsigned int i = 0; i < N; ++i) Par[i] = i, Size[i] = 1;

    fread(Input, sizeof(unsigned char), InputSize, stdin);
    unsigned int n = getInt(), M = getInt(), K = getInt();
    while(M--){
        unsigned int u = getInt() - 1, v = getInt() - 1;
        unite(u, v); ++addr[u], ++addr[v];
    }
    while(K--){
        unsigned int u = getInt() - 1, v = getInt() - 1;
        if(same(u, v)) ++addr[u], ++addr[v];
    }
    printf("%u", sizeOf(0) - addr[0] - 1);
    for(unsigned int i = 1; i < n; ++i) printf(" %u", sizeOf(i) - addr[i] - 1);
    putchar('\n');
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

char itoc(const char i){
	return 'A' + i;
}

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

int A_ABD(){
	int N;
	cin >> N;
	cout << "AB" << itoc(N/1000+2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

ll N,M,K,x,y,z;
vector<pll> ranges;
void solve() {
    cin >> N >> M >> K;
    bool ok = false;
    if(K==0) ok = true;
    else if(K%N==0 or K%M==0) ok = true;
    else{
        rng(i,1,N){
            rng(j,1,M){
                if(i*(M-j)+j*(N-i) == K) {
                    ok = true;
                }
            }
        }
    }
    print((ok?"Yes":"No"));
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3584
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;

const double PI  = 3.141592653589793238463;

int main() {
    int maxi = 0, n, x = 0;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'I'){
            x++;
        }
        else
        {
            x--;
        }
        
        if(x > maxi){
            maxi = x;
        }
        
    }
    cout << maxi;
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long luka[86];
  luka[0]=2;
  luka[1]=1;
  for(int i=2;i<=n;i++){
    luka[i]=luka[i-1]+luka[i-2];
  }
  cout<<luka[n]<<endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: f64 = read();
    println!("{}", (n.sqrt() as u64).pow(2));
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
int T[1000],X[1000],q;
#define ma(a,b)(a>b?a:b)
newday(){if(~T[0])for(q=1;q<1000;q++)if(~T[q])X[q]+=1440-ma(T[q],T[0]),T[q]=-1;T[0]=-1;}
main(){
	int n,A,a,B,b,h,m,p;
	for(;scanf("%d",&n),n;){
		memset(T,0xff,sizeof(T));
		memset(X,0,sizeof(X));
		for(A=0;n;n--){
			scanf("%d/%d %d:%d %c %d",&a,&b,&h,&m,&p,&p);
			if(A-a||B-b)newday(),A=a,B=b;
			h=h*60+m;
			if(T[p]==-1)T[p]=h;
			else{
				if(p==0){
					for(q=1;q<1000;q++){
						if(~T[q]){
							X[q]+=h-ma(T[q],T[0]);
						}
					}
				}else{
					if(~T[0])X[p]+=h-ma(T[p],T[0]);
				}
				T[p]=-1;
			}
		}
		newday();
		for(m=0,p=1;p<1000;p++){
			if(m<X[p])m=X[p];
		}
		printf("%d\n",m);
	}
	exit(0);
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int x1 = scanner.nextInt();
		int y1 = scanner.nextInt();
		int x2 = scanner.nextInt();
		int y2 = scanner.nextInt();
		int x3 = x2-(y2-y1);
		int y3 = y2+(x2-x1);
		int x4 = x1-(y2-y1);
		int y4 = y1+(x2-x1);

		System.out.println(x3+" "+y3+" "+x4+" "+y4);
	}
}


Measured memory_bytes: 24020
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;



int M,N;

int P[10000+10];
int C[500+10];
int E[500+10];
int Pt[10000+10];

int dp[500+10][10000+10];

int main() {

	cin >> M >> N;
	rep(i, M){
		cin >> P[i];
	}
	rep(i, N){
		cin >> C[i] >> E[i];
	}
	sort(P, P + M, greater<int>());

	for(int i=1; i <= M;i++){
		Pt[i] = Pt[i-1] + P[i - 1];
	}
	for(int i = 0; i<= N; i++){
		for(int j=0;j<=M;j++){
			dp[i][j]=-inf;
		}
	}
	dp[0][0] = 0;
	int ans=0;

	for(int i = 1; i<= N; i++){
		for(int j=0;j<=M;j++){
			dp[i][j] = max(dp[i - 1][j] , dp[i][j]);
			if(j - C[i - 1] > 0){
				dp[i][j] = max(dp[i - 1][j - C[i - 1]] + Pt[j] - Pt[j - C[i - 1]] - E[i - 1], dp[i][j]);
			}else{
				dp[i][j] = max(dp[i - 1][0] + Pt[j] - E[i - 1], dp[i][j]);
			}
			if(dp[i][j] < 0)
				dp[i][j] = -inf;
			ans = max(ans, dp[i][j]);
		}
	}

	cout << ans << endl;






}

Measured memory_bytes: 20856
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int h, w;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
string s[55];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> h >> w;
	FOR(i, h) cin >> s[i];
	FOR(x, h) FOR(y, w) {
		if (s[x][y] == '#') continue;
		int cnt = 0;
		FOR(i, 8) {
			int nx = x + dx[i], ny = y + dy[i];
			if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
				if (s[nx][ny] == '#') cnt++;
			}
			s[x][y] = (char)('0'+cnt);
		}
	}
	FOR(i, h) cout << s[i] << endl;
	return 0;
}

Measured memory_bytes: 256
N,K = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)

b = Array.new(N+1, 0)
a.map { |i| b[i-1] += 1 }
b.sort!.delete(0)

if b.size <= K
  puts 0
else
  puts b.reverse.drop(K).inject(:+)
end


Measured memory_bytes: 21248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] abc = str.split(" ", 0);
		int a = Integer.parseInt(abc[0]);
		int b = Integer.parseInt(abc[1]);
		int c = Integer.parseInt(abc[2]);

		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

void solve(int start,int fin,int mid){
  vector<int> ans(fin-start+1,0);
  int N = ans.size();
  if(N%2 == 0){
    ans[mid-start] = N / 2;
    ans[mid+1-start] = N / 2;
  }
  else{
    if((fin-mid)/*Lの数*/%2 == 0){
      ans[mid-start] = N / 2 + 1;
      ans[mid+1-start] = N / 2;
    }
    else{
      ans[mid-start] = N / 2;
      ans[mid+1-start] = N / 2 + 1;
    }
  }
  
  for(int i=0;i<N;i++) cout << ans[i] << " ";
}

int main(){
  string S;
  cin >> S;
  int start=-1,fin=-1,mid=-1;
  
  for(int i=0;i<S.size()-1;i++){
    if(mid==-1){
      if(start==-1) start = i;
      if(S[i+1]=='L') mid = i;
    }
    else{
      if(S[i+1]=='R'){
        fin = i;
        solve(start,fin,mid);
        start=-1;
        fin=-1;
        mid=-1;
      }
    }
  }
  solve(start,S.size()-1,mid);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include<string>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn=1e5+4;
int main(){
    int n;
    while(cin>>n){
    	int h=n/100;
    	n%=100;
    	int t=n/10;
    	if(t>h)
    		printf("%d%d%d\n",h+1,h+1,h+1);
    	else{
    		n%=10;
    		if(n>h)
    			printf("%d%d%d\n",h+1,h+1,h+1);
    		else
    			printf("%d%d%d\n",h,h,h);
		}
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] stoneLine = br.readLine().toCharArray();
		int lineSize = stoneLine.length;
		int actionNum = 0;
		char currentStone = stoneLine[0];
		for (int i = 1; i < lineSize; i++) {
			if (currentStone != (currentStone = stoneLine[i])) {
				actionNum++;
			}
		}
		System.out.println(actionNum);
	}
}


Measured memory_bytes: 10832
#include <stdio.h>

int main() {
  int play;
  int i = 0;
  int win;
  int perc;
  int b;
  int wb;
  int betg = 0;

  while(1) {
    scanf("%d%d%d", &play, &win, &perc);
    if(play == 0 && win == 0 && perc == 0) break;
    betg = 0;
    for(i = 0; i < play; ++i) {
      scanf("%d", &b);
      betg += (b * 100);
      if(win == (i + 1)) {
        wb = b;
      }
    }
    (wb == 0) ? printf("%d\n", 0) : printf("%d\n", (int)(((float)betg * ((float)(100 - perc) * 0.01)) / wb));
  }
  return 0;
}

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

int main(){
  
  string S;
  cin >> S;
  
  int ans = 0;
  int peak = 0;
  
  for (int i=0;i<S.size();i++){
    bool A = S[i] == 'A';
    bool T = S[i] == 'T';
    bool G = S[i] == 'G';
    bool C = S[i] == 'C';
    if (A || T || G || C){
      ans ++;
      peak = max(peak,ans);
    }else{
      ans = 0;
    }
  }
  
  cout << peak << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 60

// レベル i の時の全体の長さ
ll length[MAX_N];

// n, x の時の P の数を返す
ll dfs(ll n, ll x) {
    if(x == 0) { return 0; }
    if(n == 1) { return (x == 5) ? 3 : x - 1; }
    // x を 2 つに分ける
    if(x - 1 <= length[n-1]) { return dfs(n-1, x-1); }
    if(x == length[n]) { return 1 + dfs(n-1, length[n-1]) * 2; }
    ll x1 = length[n-1];
    ll x2 = x - length[n-1] - 2;
    return 1 + dfs(n-1, x1) + dfs(n-1, x2);
}

signed main()
{
    ll N, X;
    cin >> N >> X;

    // length の作成
    length[0] = 1;
    for(int i = 1; i < MAX_N; ++i) { length[i] = 3 + length[i-1] * 2; }

    ll ans = dfs(N, X);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>void gi(T &x){
	int f;char c;
	for(f=1,c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(x=0;c<='9'&&c>='0';c=getchar())x=x*10+(c&15);x*=f;
}

const int N=2e5+10,mod=1e9+7;
inline int qm(int x,int k){
	int sum=1;
	while(k){
		if(k&1)sum=1ll*sum*x%mod;
		x=1ll*x*x%mod;k>>=1;
	}
	return sum;
}
int n,a[N],c[N],v0[N],R[N],tr[N],S;
inline void add(int x,int t){
	for(int i=x;i<=n;i+=(i&(-i)))tr[i]=(tr[i]+t)%mod;
}
inline int qry(int x){
	int ret=0;
	for(int i=x;i>=1;i-=(i&(-i)))ret=(ret+tr[i])%mod;
	return ret;
}
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)gi(a[i]),c[a[i]]++;
  for(int i=n-1;i>=1;i--)c[i]+=c[i+1]-1;
  for(int i=1;i<=n;i++)if(c[i]<=0)return puts("0"),0;
  v0[0]=S=1;
  for(int i=1;i<=n;i++){
	  v0[i]=1ll*v0[i-1]*(c[i]>1?c[i]-1:1)%mod*qm(c[i],mod-2)%mod;
	  S=1ll*S*c[i]%mod;
  }
  R[n]=n;
  for(int i=n-1;i>=1;i--)R[i]=c[i+1]>1?R[i+1]:i;
  int ans=0,t;
  //A[i]<=A[j]
  for(int i=n;i>=1;i--){
	  t=(qry(R[a[i]])-qry(a[i]-1)+mod)%mod;
	  ans=(ans+1ll*t*qm(v0[a[i]],mod-2))%mod;
	  add(a[i],v0[a[i]]);
  }
  //A[i]>A[j]
  R[1]=1;
  memset(tr,0,sizeof(tr));
  for(int i=2;i<=n;i++)R[i]=c[i]>1?R[i-1]:i;
  for(int i=n;i>=1;i--){
	  t=(qry(a[i]-1)-qry(R[a[i]]-1)+mod)%mod;
	  ans=(ans-1ll*t*v0[a[i]]%mod+mod)%mod;
	  add(a[i],qm(v0[a[i]],mod-2));
  }
  ans=1ll*ans*qm(2,mod-2)%mod;
  memset(tr,0,sizeof(tr));
  for(int i=1;i<=n;i++){
	  ans=(1ll*ans+i-1-qry(a[i])+mod)%mod;
	  add(a[i],1);
  }
  ans=1ll*ans*S%mod;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4096
import java.util.Scanner;
public class Main{
	public static void main(String[]args) {
		Scanner sc = new Scanner (System.in);

		int A, B;
		A=sc.nextInt();
		B=sc.nextInt();
		
		
		if(((A*2)-1) > A+B &&  ((A*2)-1) > ((B*2)-1)){
			System.out.println((A*2)-1);

		}else if(((B*2)-1) > A+B && ((B*2)-1) >((A*2)-1) ) {
			System.out.println((B*2)-1);
			
		}else {
			System.out.println(A+B);
		}
	}
}



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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)
#define SUM(v) accumulate((v).begin(),(v).end(),0ll)
#define range(i,left,right) (left<=i && i<right)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int iscount(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int x;
    cin>>x;

    REP(b,-1000,1000){
        int a=(int)pow(x+b*b*b*b*b,0.2);
        if(a*a*a*a*a-b*b*b*b*b==x){
            cout<<a<<" "<<b<<endl;
            break;
        }
    }
    return 0;
}


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


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

  vector<int> vec(0),dp(160000,MOD);

  dp[0] = 0;

  int a = 9,b = 6;

  for(int i = 0;i < 5;i++) {
    vec.push_back(a);
    a *= 9;
  }

  for(int i = 0;i < 6;i++) {
    vec.push_back(b);
    b *= 6;
  }

  

  vec.push_back(1);

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

  for(int i = 0;i <= N;i++) {
    for(int j = 0;j < vec.size();j++) {
      int d = vec.at(j);
      dp[i + d] = min(dp[i + d],dp[i] + 1);
    }
  }

  cout << dp[N] << endl;

  
}



Measured memory_bytes: 896
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long int;

// to format a document: ctrl + K -> ctrl + D

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        while (a[i] % 2 == 0) {
            ans++;
            a[i] /= 2;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char str[4];
	scanf("%s", str);
	if (str[0] == '7' || str[1] == '7' || str[2] == '7') {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1660
#include <vector>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <map>
#include <complex>
#include <ctime>
#include <numeric>
#include <set>
 
using namespace std;
 
typedef long long ll;
 
typedef struct node{
    int s, e, val, pos;
    bool operator<(const node& n) const{
        if(e != n.e) return e < n.e;
        return val > n.val;
    }
    node(){};
    node(int ss, int ee, int v, int p){
        s = ss, e = ee, val = v, pos = p;
    }
}node;
 
int occs[(int)1e6 + 5], tree[5000005], n, ans[5000005];
 
void update(int x, int val){
    while(x <= n){
        tree[x] += val;
        x += x & -x;
    }
}
 
int query(int x){
    int ret = 0;
    while(x > 0){
        ret += tree[x];
        x -= x & -x;
    }
    return ret;
}
 
int main(){
    int q, s, e;
    vector<node> v;
    cin>>n;
    cin>>q;
    for(int i = 1; i <= n; i++){
        cin>>s;
        v.push_back(node(i, i, s, -1));
    }
    for(int i = 0; i < q; i++){
        cin>>s>>e;
        v.push_back(node(s, e, 0, i));
    }
 
    sort(v.begin(), v.end());
 
    for(int i = 0;i < v.size(); i++){
        if(v[i].val == 0){
            ans[v[i].pos] = query(v[i].e) - query(v[i].s - 1);
        }else{
            if(occs[v[i].val] != 0) update(occs[v[i].val], -1);
            update(v[i].s, 1);
            occs[v[i].val] = v[i].s;
        }
    }
 
    for(int i = 0; i < q; i++){
        cout<<ans[i]<<"\n";
    }
 
    return 0;
}

Measured memory_bytes: 25328
A, B = map(int, input().split())
S = input()
res = 'Yes'

for i in range(len(S)):
    if i == A:
        if S[i] != '-':
            res = 'No'
            break
    else:
        if S[i].isdigit() == False:
            res = 'No'

print(res)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = "1" + sc.next();

		int[] ruiseki = new int[s.length() + 1];

		// 累積和配列を作成
		char preChar = s.charAt(0);
		int gIndex = 1;
		int gNum = 0;
		for (int i = 1; i <= s.length(); i++) {
			gNum++;
			ruiseki[gIndex] = gNum;
			if (i < s.length() && preChar != s.charAt(i)) {
				gIndex++;
				preChar = s.charAt(i);
			}
		}

//		System.out.println(ruiseki);
		int max = gIndex == 1 ? n : 0;
		for (int i = 2; i <= gIndex; i += 2) {
//			System.out.println(2 * (k - 1) + i + 1 + ":index");
//			System.out.println(Math.min(2 * (k - 1) + i + 1, gIndex));
//			System.out.println(ruiseki[Math.min(2 * (k - 1) + i + 1, gIndex)] - ruiseki[i - 2] + ":max?");
			if (max < ruiseki[Math.min(2 * (k - 1) + i + 1, gIndex)] - ruiseki[i - 2]) {
				max = ruiseki[Math.min(2 * (k - 1) + i + 1, gIndex)] - ruiseki[i - 2];
				if (i == 2) max--;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 27860
#include <bits/stdc++.h>
#define ll long long  
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n,k,count=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
     int a;
     cin>>a;
     if(a>=k) count++;
  }
  
  cout<<count<<endl;
  
  return 0;
}


Measured memory_bytes: 256
var n,i,a,b:integer;
    c:char;
begin
  readln(n);
  a:=0;b:=0;
  for i:=1 to n do
  begin
  read(c);
  if c='R' then inc(a)
  else inc(b);
  end;
  if a>b then write('Yes')
  else write('No')
end.


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1000000000;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int d; cin >> d;
    string ans = "Christmas";
    if(d <= 24){
        ans += " Eve";
    }
    if(d <= 23){
        ans += " Eve";
    }
    if(d <= 22){
        ans += " Eve";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 300010
ll k, n, t[N];

int main(){
	cin>>k>>n;
	if(k%2==0){
		cout<<k/2;
		rep(i, n-1) cout<<" "<<k;
		cout<<endl;
		return 0;
	}
	ll x = (k+1)/2, d = n/2;
	vector<ll> r(n, x);
	t[0] = 1;
	ll p = 0;
	while(t[p]<=n){
		t[p+1] = t[p]*k+1;
		p++;
	}
	ll q = p;
	while(d){
		p = q-1;
		while(d && p>=0){
			while(r[p]>1 && d>=t[p]){
				r[p]--;
				d -= t[p];
			}
			p--;
		}
		p = 0;
		while(d){
			if(r[p]!=1) break;
			r[p] = 0;
			d--;
			p++;
		}
		if(d){
			r[p]--;
			while(--p>=0) r[p] = k;
			d--;
		}
	}
	reverse(all(r));
	rep(i, n){
		if(r[i]==0) break;
		cout<<r[i]<<" ";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define LOG(k,m) (cout << k << ":" << m << endl)
//#define LOG(k,m) (void)0

int main(){

    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int c1,c2,t;

    c1=h1*60+m1;
    c2=h2*60+m2;
    if(c1<c2){
        t = c2 - c1;
    }else{
        t = c2 + (1440 - c1);
    }
    if(t-k > 0){
        cout << t-k << endl;
    }else{
        cout << 0 << endl;
    }


    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int p[n];
    int count=0;
    rep(i,n) cin>>p[i];
    for (int i=1;i<n-1;i++){
        if(p[i]!=max(p[i],max(p[i+1],p[i-1]))&&p[i]!=min(p[i],min(p[i+1],p[i-1]))){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V)                                                           \
    for (auto v : (V))                                                         \
        cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    ll X;
    cin >> X;
    ll res = 0;
    while (X >= 0) {
        if (X >= 500) {
            X -= 500;
            res += 1000;
        } else if (X >= 5) {
            X -= 5;
            res += 5;
        } else {
            break;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main(void) {
	char a,b,c;
	int q, w, e;
	cin >> q>>a>>w>>b>>e;
	if (w<=4) {
		cout<<"Heisei"<<endl;
	}
	else {
		cout<<"TBD"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  Bubble Sort (PC 甲子園 2007)
//
//  Created by 大森 亮 on 2014/04/10.
//  Copyright (c) 2014年 大森 亮. All rights reserved.
//


#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0;i < n;i++)

using namespace std;

int A[105];
int W[105];

int count(int left,int right){
    if(right == left + 1){
        return 0;
    }else if(right == left + 2){
        if(A[left] > A[left+1]){
            swap(A[left], A[left+1]);
            return 1;
        }else{
            return 0;
        }
    }
    int mid = (left+right)/2;
    int cl=count(left,mid),cr=count(mid,right);
    int clr = 0;
    int i = left,j = mid,k=left;
    while(i < mid && j < right){
        if(A[i] <= A[j]){
            W[k++]=A[i++];
        }else{
            clr += mid-i;
            W[k++]=A[j++];

        }
    }
    while(i < mid){
        W[k++]=A[i++];

    }
    while(j < right){
        W[k++]=A[j++];
    }
    assert(k == right);
    copy(W+left,W+right,A+left);
    return cl + cr + clr;
}

int main(){
    int N;
    while(cin >> N&&N!=0){
        rep(i,N){
            cin >> A[i];
        }
        cout << count(0,N) <<endl;
    }
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 2005;
char A[MAX_N], B[MAX_N];
int N, L[MAX_N], R[MAX_N];

int check() {
  for (int i = 0; i < N; ++i)
    if (B[i] == '1') return 2;
  for (int i = 0; i < N; ++i)
    if (A[i] == '1') return 0;
  return 1;
}

int work(int dis, int del, int *d1, int *d2) {
  int res = dis;
  static int val[MAX_N];
  memset(val, 0, sizeof val);
  for (int i = 0; i < N; ++i) {
    int nxt = (i + del + N) % N;
    if (B[nxt] == A[i]) continue;
    res++;
    if (dis >= d1[i]) continue;
    int v1 = d1[i] - dis, v2 = d2[i];
    val[v1] = max(val[v1], v2);
  }
  
  int mx = 0, now = 0x3f3f3f3f;
  for (int i = N; i >= 0; --i) {
    now = min(now, i + mx);
    mx = max(mx, val[i]);
  }
  return res + now * 2;
}

int main() {
  scanf("%s%s", A, B);
  N = strlen(A);

  int flag = check();
  if (flag == 0) {
    puts("-1");
    return 0;
  } else if (flag == 1) {
    puts("0");
    return 0;
  }
  
  for (int i = 0; i < N; ++i) {
    int j = i, len = 0;
    while (B[j] != '1') j = (j - 1 + N) % N, len++;
    L[i] = len, j = i, len = 0;
    while (B[j] != '1') j = (j + 1) % N, len++;
    R[i] = len;
  }

  int res = 0x3f3f3f3f;
  for (int i = 0; i < N; ++i) {
    res = min(res, work(i, i, R, L));
    res = min(res, work(i, -i, L, R));
  }

  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 256
import sys
def search(x,y,lb,ub,field):
	if y == ub[1] :
		number = x
	elif lb[0] < x - 1 and field[y][x-1] == 1:
		number = search(x-2, y+1, lb, ub, field)
	elif ub[0] > x + 1 and field[y][x+1] == 1:
		number = search(x+2, y+1, lb, ub, field)
	else :
		number = search(x, y+1, lb, ub, field)
	return number

sys.setrecursionlimit(10000)
while 1:
	n, m, a = map(int, raw_input().split(" "))
	if (n,m,a) == (0,0,0):
		break
	amida = [[0 if i % 2 == 0 else 1 for i in range(n*2)] for j in range(1001)]
	for j in range(m):
		h,p,q = map(int, raw_input().split(" "))
		amida[1000-h+1][p * 2] = 1
	print (search(2*a-1, 0, (1, 0), (2*n-1, 1001), amida) + 1) / 2

Measured memory_bytes: 7872
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String a = sc.next(), b = sc.next();
        if(a.charAt(0) == b.charAt(2) && a.charAt(2) == b.charAt(0)
        && a.charAt(1) == b.charAt(1))
            System.out.print("YES");
        else System.out.print("NO");
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) x.begin(),x.end()
#define DEBUG

int main()
{
	string s;
	cin >> s;

	int ans = 0;

	for(int i = 0; i  < (s.size() - (s.size() % 2)) / 2; i++)
	{
		if(s[i] != s[s.size() - 1 - i]) ans++;
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator^(const ll& t)const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

//////////////////////////



int main() {
   
    ll N;
    cin >> N;
    vector<ll> L(N + 1), R(N + 1);

    repn(i, N) cin >> L[i] >> R[i];
    R[0] = 0;
    L[0] = 0;

    sort(R.begin(), R.end());
    sort(L.begin(), L.end(), greater<ll>());
    

    ll ans = 0;

    rep(i, N+1) {
        if (L[i] < R[i]) { break; }
        ans += (L[i] - R[i]) * 2;
    }

    cout << ans;

	system("PAUSE");
}

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


bool mstu[2048];
int mstc[2048];
tuple<int,int,int> edges[2048];
int P[2048],R[2048];

int findS(int u){
	if(P[u] != u) P[u] = findS(P[u]);
	return P[u];
}

bool mergeS(int x,int y){
	x = findS(x);y = findS(y);
	if(x == y) return false;
	if(R[x] > R[y]) P[y] = x;
	else P[x] = y;
	if(R[y] == R[x]) R[y] += 1;
	return true;
}
int main(){
	int N,M;cin>>N>>M;
	for(int i=0;i<N;i++) P[i] = i;
	long long X;cin>>X;
	for(int i=0;i<M;i++){
		int u,v,w;cin>>u>>v>>w;
		u--;v--;
		edges[i] = make_tuple(w,u,v);
	}
	sort(edges,edges+M);
	
	int idx = 0;
	long long total = 0;
	while(idx < M){
		int currw = get<0>(edges[idx]);
		vector<int> to_merge;
		while(idx < M && get<0>(edges[idx]) == currw){
			int u = get<1>(edges[idx]),v = get<2>(edges[idx]);
			to_merge.push_back(idx);
			if(findS(u) != findS(v)) mstu[idx] = true;
			idx += 1;
		}
		for(auto x: to_merge){
			int u = get<1>(edges[x]), v = get<2>(edges[x]);
			if(mergeS(u,v)) total += get<0>(edges[x]);
		}
	}
	
	if(total == X){
		long long ans = 1;
		for(int i=0;i<M;i++) ans = ans * 2 % MOD;
		long long rem = 2;
		for(int i=0;i<M;i++) if(mstu[i] == false) rem  = rem * 2 % MOD;
		ans = (ans + MOD - rem)%MOD;
		cout<<ans<<endl;
	}else{
		for(int i=0;i<M;i++) if(mstu[i] == false){
			for(int j=0;j<N;j++){
				P[j] = j;
				R[j] = 1;
			}
			
			long long ctot = get<0>(edges[i]);
			mergeS(get<1>(edges[i]),get<2>(edges[i]));
			for(int j=0;j<M;j++){
				int u = get<1>(edges[j]),v = get<2>(edges[j]),w = get<0>(edges[j]);
				if(mergeS(u,v)) ctot += w;
			}
			if(ctot == X) mstc[i] = 1;
			else if(ctot > X) mstc[i] = 2;
		}
		
		long long ans = 2;
		for(int i=0;i<M;i++) if(mstc[i] != 0) ans = ans * 2 % MOD;
		long long rem = 2;
		for(int i=0;i<M;i++) if(mstc[i] == 2) rem = rem * 2 % MOD;
		ans = (ans - rem + MOD)%MOD;
		cout<<ans<<endl;	
	}
	
	return 0;
}

Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var n,a int
  var b []int64 = make([]int64,2)
  var m,p int64
  fmt.Scan(&n,&p)
  for i:=0;i<n;i++ {
    fmt.Scan(&a)
    b[a%2]++
  }
  for i:=p;i<=b[1];i+=2 {
    m += combination(b[1],i)
  }
  m *= pow(2,b[0])
  fmt.Println(m)
}
func pow(base int64,power int64) int64 {
  if power == 0 { return 1 }
  if power%2 == 0 {
    var h int64 = pow(base,power/2)
    return h*h
  } else {
    return base*pow(base,power-1)
  }
}
func combination(n int64,k int64) int64 {
  if 2*k > n { return combination(n,n-k) }
  if k > n || n < 0 { return 0 }
  if n == 0 {
    if k == 0 {
      return 1
    } else {
      return 0
    }
  }
  var num,den int64 = 1,1
  for i:=k;i>0;i-- {
    if num%i == 0 {
      num = (num/i)*(n-k+i)
    } else if (n-k+i)%i == 0 {
      num *= (n-k+i)/i
    } else {
      num *= (n-k+i)
      den *= i
    }
  }
  return num/den
}

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

int main(){
    using namespace std;
    int N,M;
    cin >> N >>M;
    vector<vector<int>> jobs(M);
    rep(i,N){
        int A,B;
        cin >> A >> B;
        if(A > M) continue;
        jobs[M-A].push_back(B);//M-A日目にやるべき仕事
    }
    priority_queue<int> q;
    ll ans=0;
    for(int i = M-1; i>=0; i--){
        for(int B : jobs[i]){
            q.push(B);
        }
        if (!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> x;
    for(int i = 1;i <= 1000000;i++) {
        if(i*x%360 == 0) {
            cout << i;
            return 0;
        }
    }
}

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


int main() {
  
  long long N,M,K;
  cin >> N >> M >> K;

  vector<long long> A(N+1),B(M+1);
  for(int i = 1;i <= N;i++) cin >> A[i];  
  for(int i = 1;i <= M;i++) cin >> B[i];  
  
  for(int i = 0;i < N;i++) A[i+1] += A[i];
  for(int i = 0;i < M;i++) B[i+1] += B[i];


  int ans = 0;
  int best = M;
  for(int i = 0;i <= N;i++) {
    if(A[i] > K) break;
    for(int j = best;j >= 0;j--) {
      if(A[i] + B[j] <= K) {
        best = j;
        ans = max(ans,i+j);
        break;
      }
    }
  }

  cout << ans << endl;
  

}


Measured memory_bytes: 6392
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

int main() {
	vector<ll> argA(5);
	for (ll i = 0; i < 5; ++i) {
		cin >> argA.at(i);
	}

	ll argK;
	cin >> argK;

	for (ll i = 0; i < 5; ++i) {
		for (ll j = 0; j < 5; ++j) {
			ll length = abs(argA.at(i) - argA.at(j));
			if (length > argK) {
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    int k,result = 0;
    for (int i = 0; i < m; i++){
        cin>>k;
        result += k;
    }
    if (result >= n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import bisect
from collections import Counter

power2 = [1]
while power2[-1] < 10**9:
    power2.append(power2[-1]*2)

N = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
C = Counter(A)

ans = 0
for a in A:
    if C[a] == 0:
        continue
    C[a] -= 1

    i = bisect.bisect_right(power2, a)
    if C[power2[i]-a] >= 1:
        ans += 1
        C[power2[i]-a] -= 1

print(ans)


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



int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if(d <= t * s){
    puts("Yes");
  }else{
    puts("No");
  }

}

Measured memory_bytes: 3632
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	S := nextLine()
	numW := make([]int, N+1)
	numE := make([]int, N+1)
	for i, Si := range S {
		if Si == 'W' {
			numW[i+1] = numW[i] + 1
			numE[i+1] = numE[i]
		} else {
			numW[i+1] = numW[i]
			numE[i+1] = numE[i] + 1
		}
	}
	// for i := 0; i < N; i++ {
	// 	if S[i] == 'W' {
	// 		numW[i+1] = numW[i] + 1
	// 		numE[i+1] = numE[i]
	// 	} else {
	// 		numW[i+1] = numW[i]
	// 		numE[i+1] = numE[i] + 1
	// 	}
	// }
	// ans := numE[N] - numE[1]
	ans := N
	for i := 0; i < N; i++ {
		peoples := numW[i] - numW[0] + numE[N] - numE[i+1]
		if ans > peoples {
			ans = peoples
		}
	}
	fmt.Println(ans)
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 6144
#include <iostream>

using namespace std;

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

  int l[n];
  for(i = 0 ; i < n ; i++){
    l[k[i]-1] = i + 1;
  }
  
  for(i = 0 ; i < n ; i++){
    cout << l[i] << " ";
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 1536