akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
#define print(x) cout<<#x<<"="<<x<<'\n'
#define print2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define print3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define fr(i,a,n) for(int i=a;i<=(n);++i)
#define rf(i,a,n) for(int i=a;i>=(n);--i)
#define mp make_pair
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vpii vector<pii>
using namespace std;

// ll game(vi a, int i, int j){
// 	if(i>j)
// 		return 0;
// 	if(i==j)
// 		return a[i];
// 	return max(a[i]+min(game(a,i+1,j-1),game(a,i+2,j)), a[j]+min(game(a,i+1,j-1),game(a,i,j-2)));

// }

int main() {
    int t=1;
    // cin>>t;
    while(t--){
    	int n;
    	cin>>n;
    	vi a(n);
    	ll sum=0;
    	rep(i,n){
    		cin>>a[i];
    		sum+=a[i];
    	}
    	// ll ans=game(a,0,n-1);
    	vvi dp(n+1, vi(n+1));
    	for(int gap=0;gap<n;gap++){
    		for(int i=0;i<n-gap;i++){
    			int j=i+gap;
    			ll x=0,y=0,z=0;
    			if(i+2<=j){
    				x=dp[i+2][j];
    			}
    			if(i+1<=j-1){
    				y=dp[i+1][j-1];
    			}
    			if(i<=j-2){
    				z=dp[i][j-2];
    			}
    			dp[i][j]=max(a[i]+min(x,y),a[j]+min(y,z));
    		}
    	}
    	// print(dp[0][n-1]);
    	cout<<dp[0][n-1]-sum+dp[0][n-1]<<endl;
    }
    return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n; cin >> n;
    map<string, int> goods; int ans = 0;
    rep(i, n){
        string s; cin >> s;
        if(goods[s] == 0) ans++;
        goods[s] += 1;
    }
    out(ans);
}

Measured memory_bytes: 19224
import scala.io.StdIn.{readLine,readInt}
import scala.language.postfixOps

object Main {
  var cnt = 0
  val l = new Array[Int](250001)
  val r = new Array[Int](250001)
  var a:Array[Int] = null

  def merge(left:Int,mid:Int,right:Int) = {
    val n1 = mid-left
    val n2 = right-mid
    Array.copy(a,left,l,0,n1)
    l(n1) = Int.MaxValue
    Array.copy(a,mid,r,0,n2)
    r(n2) = Int.MaxValue
    var i=0
    var j=0
    for(k<-left until right) {
      if(l(i)<=r(j)){
        a(k) = l(i)
        i += 1
      } else  {
        a(k)=r(j)
        j += 1
      }
      cnt += 1
    }
  }

  def getSortIndex(n:Int):Iterator[IndexedSeq[(Int,Int)]] = {
    var w = n
    var h = 0
    while(w>1) {
      h += 1
      w /= 2
    }

    def scan(h:Int,l:List[IndexedSeq[(Int,Int)]]):List[IndexedSeq[(Int,Int)]] = {
      if(h==0) l
      else
        scan(h-1,(for(i<-l.head;j<-List((i._1,(i._2+i._1)/2),((i._2+i._1)/2,i._2))) yield j)::l)
    }
    scan(h-1,List(IndexedSeq((0,n/2),(n/2,n)))).to[Iterator]
  }

  def main(args:Array[String]) = {
    val n = readInt
    a = readLine.split(" ").map(_.toInt)
    val l = getSortIndex(n)
    for(e2<-l) {
      for(e<-e2) {
        val mid = (e._2+e._1)/2
        if(e._2-e._1>1)
          merge(e._1,mid,e._2)
      }
    }
    merge(0,n/2,n)
    println(a.mkString(" "))
    println(cnt)
  }
}

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

const int INF = 1001001001;

int main(){
    int N, K, h[100000], dp[100000];
    cin >> N >> K;
    dp[0] = 0;
    rep(i, N) {
        cin >> h[i];
        if (i != 0) dp[i] = INF;
        for (int j = 1; j <= K; j++) {
            if (i - j >= 0) {
                dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            }
        }
    }

    cout << dp[N - 1] << endl;

    return 0;
}

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

typedef long long int lli;
typedef pair<int, int> ii;

const int N = 1e5;

int dam[N];

int main() {
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;
	for(int i = 0; i<n; i++) cin >> dam[i];

	lli primo = 0;
	for(int i = 0; i<n; i++) primo = primo + ((i%2)? -1:1)*dam[i];

	for(int i = 0; i < n; i++) {
		cout << primo << ((i == (n-1))? '\n':' ');
		primo *= -1;
		primo += 2*dam[i];
	}

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iterator>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int x,y;
int field[103][103];
int ans=0;
const int dx2[6]={-1,-1,-1,0,1,0},dx1[6]={1,1,1,0,-1,0};
const int dy[6]={-1,0,1,-1,0,1};

void paint(int xx,int yy){
	int a;
	field[xx][yy]=2;
	if(yy%2==0){
		for(a=0;a<6;a++){
			if(0<=xx+dx2[a] && xx+dx2[a]<=x+2 && 0<=yy+dy[a] && yy+dy[a]<=y+2 && field[xx+dx2[a]][yy+dy[a]]==0){
				paint(xx+dx2[a],yy+dy[a]);
			}
		}
	}else if(yy%2==1){
		for(a=0;a<6;a++){
			if(0<=xx+dx1[a] && xx+dx1[a]<=x+2 && 0<=yy+dy[a] && yy+dy[a]<=y+2 && field[xx+dx1[a]][yy+dy[a]]==0){
				paint(xx+dx1[a],yy+dy[a]);
			}
		}
	}
}

void check(int xx,int yy){
	int a;
	if(yy%2==0){
		for(a=0;a<6;a++){
			if(field[xx+dx2[a]][yy+dy[a]]==2)ans++;
		}
	}else if(yy%2==1){
		for(a=0;a<6;a++){
			if(field[xx+dx1[a]][yy+dy[a]]==2)ans++;
		}
	}
}

int main(void){
	int a,b;
	for(a=0;a<=102;a++){
		for(b=0;b<=102;b++){
			field[a][b]=0;
		}
	}
	cin >> x >> y;
	for(b=1;b<=y;b++){
		for(a=1;a<=x;a++){
			scanf("%d",&field[a][b]);
		}
	}
	paint(0,0);
	for(a=1;a<=y;a++){
		for(b=1;b<=x;b++){
			if(field[b][a]==1)check(b,a);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T>
vector<T> dijkstra(const WeightedGraph<T> &g, int s) {
    const T INF = numeric_limits<T>::max();
    vector<T> dist(g.size(), INF);
    vector<int> prev(g.size(), -1);
    using Pi = pair<T, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0; que.emplace(dist[s], s);
    while (!que.empty()) {
        T cost; int u; tie(cost, u) = que.top(); que.pop();
        if (dist[u] < cost) continue;
        for (auto &e: g[u]) {
            int v = e.dst; T nc = e.cost;
            if (dist[v] <= dist[u] + nc) continue;
            dist[v] = dist[u] + nc; prev[v] = u;
            que.emplace(dist[v], v);
        }
    }
    return dist;
}

int main() {
    int n; cin >> n;
    WeightedGraph<int> g(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v, w; cin >> u >> v >> w; u--, v--;
        g[u].emplace_back(v, w % 2);
        g[v].emplace_back(u, w % 2);
    }
    auto d = dijkstra(g, 0);
    for (int i = 0; i < n; i++) {
        cout << d[i] % 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 7552
import math

A,B,N=map(int,input().split())

def floor_t(A,B,y):
    return math.floor(A*y/B) - A*math.floor(y/B)

#関数の挙動を調べる
# for x in range(1,10*B+1):
#     print('x={} : floor(AX/B)={}'.format(x,math.floor(A*x/B)))

# for x in range(1,10*B+1):
#     print('x={} : floor(X/B)={}'.format(x,A*math.floor(x/B)))

# for i in range(1,10*B+1):
#     print('x={}:f(x)={}'.format(i,floor_t(A,B,i)))

X=min(N,B-1)

print(floor_t(A,B,X))

Measured memory_bytes: 9092
n,m = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
num = 1 / (4*m)
bunbo = sum(a)
for i in range(n):
    if a[i]/bunbo >= num:
        cnt += 1
        
if cnt >= m:
    print('Yes')
else:
    print('No')

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string a, b;
  cin >> a >> b;

  int ans = atoi((a + b).c_str());
  bool flg = false;
  for (int i = 1; i * i <= ans; ++i) {
    if (i * i == ans) {
      flg = true;
      break;
    }
  }
  cout << (flg ? "Yes" : "No") << endl;
  return 0;
}


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

int main()
{
	int w,h,n;
	cin >> w >> h >> n;
	int w0=0,h0 =0;
	for(int i = 0;i<n;i++)
	{
		int x,y,z;
		cin >> x >> y >>z;
		if(z==1)w0 = max(w0,x);
		else if(z==2)w= min(w , x);
		else if(z==3)h0 = max(h0,y);
		else h = min(h,y);
	}
	//cout<<w0<<';'<<w<<';'<<h0<<';'<<h<<endl;
	if(w0>=w||h0>=h)
	{
		cout<<0<<endl;
		return 0;
	}
	cout<<(w-w0)*(h-h0)<<endl;

	return 0;
}		

Measured memory_bytes: 256
// D.

#include <sstream>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	LL n, k;
	cin >> n >> k;
	vector< vector<LL> > td(n);
	for (int i = 0; i < n; ++i) {
		LL t, d;
		cin >> t >> d;
		td[t - 1].push_back(d);
	}
	vector<LL> a, b;
	for (int i = 0; i < n; ++i) {
		sort(td[i].rbegin(), td[i].rend());
		if (!td[i].empty()) {
			a.push_back(td[i][0]);
			for (int j = 1; j < (int)td[i].size(); ++j) {
				b.push_back(td[i][j]);
			}
		}
	}
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	LL kinds = a.size();
	if ((LL)a.size() >= k) {
		a.resize(k);
		kinds = k;
	} else {
		LL c = k - a.size();
		a.insert(a.begin(), b.begin(), b.begin() + c);
		b.erase(b.begin(), b.begin() + c);
	}
	LL ans = accumulate(a.begin(), a.end(), kinds * kinds);
	for (LL x : b) {
		LL nk = max(1LL, kinds - 1);
		LL next = ans - kinds * kinds - a.back() + x + nk * nk;
		if (next <= ans) {
			break;
		}
		kinds = nk;
		a.pop_back();
		ans = next;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6904
#include<stdio.h>
#include<stdlib.h>
int max(int a,int b){
  if(a>b){
    return a;
  }
  return b;
}
 
int main(void){
  int n,i,cy,cx,H,flag=0;
  scanf("%d",&n);
  int x[n],y[n],h[n];
  for(i=0;i<n;i++)scanf("%d %d %d",&x[i],&y[i],&h[i]);
  for(cx=0;cx<=100;cx++){
    for(cy=0;cy<=100;cy++){
      for(i=0;i<n;i++) if(h[i]) break;
      H = h[i] + abs(x[i]-cx) + abs(y[i]-cy);
      for(i=0;i<n;i++){
        if(h[i]!=max(H-abs(x[i]-cx)-abs(y[i]-cy),0))break;
      }
      if(i==n)flag=1;
      if(flag)break;
    }
    if(flag)break;
  }
  printf("%d %d %d\n",cx,cy,H);
  return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(long long i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

ll h,w,n,sr,sc,cnt[2][4]={0};
string s[2];
bool f=true;

signed main() {
	cin>>h>>w>>n>>sr>>sc;
    cin>>s[0];
    cin>>s[1];
    
    ll left=1,right=w,up=1,down=h;

    for(int i=n-1;i>=0;--i){
        if(s[1][i]=='U'){
            down++;
            down=min(h,down);
        }
        if(s[1][i]=='R'){
            left--;
            left=max(1LL,left);
        }
        if(s[1][i]=='D'){
            up--;
            up=max(1LL,up);
        }
        if(s[1][i]=='L'){
            right++;
            right=min(right,w);
        }

        if(s[0][i]=='U'){
            up++;
            //up=min(up,down);
        }
        if(s[0][i]=='R'){
            right--;
            //right=max(left,right);
        }
        if(s[0][i]=='D'){
            down--;
            //down=max(down,up);
        }
        if(s[0][i]=='L'){
            left++;
            //left=min(right,w);
        }

        if(left>right||up>down){
            f=false;
            break;
        }
    }

    if(sc<left||sc>right||sr<up||sr>down)f=false;

    if(f){cout<<"YES"<<endl;}
    else{cout<<"NO"<<endl;}
	
	
	return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  // ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> node[n];
  vector<bool> flag(n,false);
  // rep(i,n) flag[i]=false;
  int num=n/3;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    node[a].push_back(b);
    node[b].push_back(a);
  }
  int ac=0,bc=0;
  int color[n]={0};
  function<void(int,int)> dfs=
    [&](int u,int a){
      // cout<<u<<endl;
      if(a%2==0) ac++;
      else bc++; 
      flag[u]=true;
      for(auto &v:node[u]){
	if(flag[v]==false){dfs(v,a+1);color[v]=(a+1)%2;}
      }
    };
  dfs(0,0);
  int cnt=1,nex=1;
  int ocnt,tcnt,hcnt;
  ocnt=tcnt=hcnt=0;
  hcnt=1;
  int ans[n];
  //cout<<ac<<" "<<bc<<endl;
  rep(i,n){
    if(ac<=num){
      if(color[i]==0){ans[i]=cnt*3;cnt++;}
      else if(nex<=n){ans[i]=nex;nex++;if(nex%3==0)nex++;}
      else{
	ans[i]=cnt*3;cnt++;
      }
      
    }else if(bc<=num){
      if(color[i]==1){ans[i]=cnt*3;cnt++;}
      else if(nex<=n){ans[i]=nex;nex++;if(nex%3==0)nex++;}
      else{
	ans[i]=cnt*3;cnt++;
      }
    }else{
      if(color[i]==1){
	if((ocnt*3)+1 <= n){ans[i]=(ocnt*3)+1;ocnt++;}
	else{ans[i]=hcnt*3;hcnt++;}
      }else{
	if((tcnt*3)+2 <= n){ans[i]=(tcnt*3)+2;tcnt++;}
	else{ans[i]=hcnt*3;hcnt++;}
      }
    }
  }
  rep(i,n){
    if(i) cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}


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

using pll = pair<long long, long long>;

int main() {
  int N;
  cin >> N;
  vector<pll> pos(N);
  for (int i = 0; i < N; ++i) cin >> pos[i].first >> pos[i].second;

  int par = (abs(pos[0].first) + abs(pos[0].second)) % 2;
  for (int i = 0; i < N; ++i) {
    int par2 = (abs(pos[i].first) + abs(pos[i].second)) % 2;
    pos[i] = pll(pos[i].first + pos[i].second, pos[i].first - pos[i].second);
    if (par2 != par) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<long long> d;
  for (int i = 30; i >= 0; --i) d.push_back(1LL << i);
  if (par % 2 == 0) d.push_back(1);
  int n = d.size();
  cout << n << endl;
  for (int j = 0; j < n; ++j) {
    cout << d[j];
    if (j == n - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }

  for (int i = 0; i < N; ++i) {
    int xdir, ydir;
    long long xsum = 0, ysum = 0;
    for (int j = 0; j < n; ++j) {
      if (xsum <= pos[i].first)
        xdir = 1, xsum += d[j];
      else
        xdir = -1, xsum -= d[j];
      if (ysum <= pos[i].second)
        ydir = 1, ysum += d[j];
      else
        ydir = -1, ysum -= d[j];

      if (xdir == 1 && ydir == 1)
        cout << "R";
      else if (xdir == 1 && ydir == -1)
        cout << "U";
      else if (xdir == -1 && ydir == -1)
        cout << "L";
      else
        cout << "D";
    }
    cout << endl;
  }
}


Measured memory_bytes: 3608
# print('input >>')
X, K, D = map(int,(input().split()))

# 0を横切らない場合
if K * D <= abs(X):
    print(abs(X) - K * D)
# 0を横切る場合
else:
    sho = abs(X) // D
    # 偶奇一致
    if sho % 2 == K % 2:
        print(abs(X) % D)
    else:
        print(abs(abs(X) % D - D))

# print('-----output-----')

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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  vector<int> v;
  cin >> n >> k;
  string s;
  cin >> s;
  if (s[0]=='1') v.push_back(0);
  int li = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i]!=s[li]) {
      v.push_back(i-li);
      li = i;
    }
  }
  v.push_back(n-li);
  int nv = v.size();
  int sm[nv+10] = {0, v[0]};
  for (int i = 1; i < nv; ++i) {
    sm[i+1] = sm[i] + v[i];
  }
  int ans = 0;
  for (int i = 0; i < nv; ++i) {
    int mi = min(i+2*k+i%2, nv);
    ans = max(ans, sm[mi] - sm[i]);
  }
  cout << max(ans, k) << endl;
  return 0;
}


Measured memory_bytes: 1272
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<double> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }

    double rec_sum=0;
    for (int i = 0; i < N; i++){
        rec_sum += 1/A[i];
    }

    cout << fixed << setprecision(6);
    cout << 1/rec_sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >>a;
  vector <int>data(a);
  for (int i=0;i<a;i++){
  cin >>data.at(i);
  }
  int s=0;
  for (int i=0;i<a-1;i++){
  for (int j=i+1;j<a;j++){
  s+=data.at(i)*data.at(j);
  }
  }
  cout <<s<<endl;
}

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

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long
#define float long double 

const int upper = 4e5 + 2;
const int M = (int) 1e9 + 7;
const int inf = (int) 1e17;
const double eps =  1e-8;

map<int, int> primecnt;
signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	int n; cin >> n;
	int x, y; cin >> x >> y;

	int ans = 0;
	for (int i = 1; i <= n; i += 1) {
		int X, Y; cin >> X >> Y;
		if (X >= x and Y >= y) {
			ans+=1;
		}
	}

	cout << ans;
 	end_routine();	
}

Measured memory_bytes: 256
N = int(input())
W = [input() for i in range(N)]

stock = []
last = W[0][0]

for i in range(0,len(W)):
    #過去の発言に含まれない
    if W[i] in stock:
        print('No')
        break
    #前の単語の最後と次の単語の最初が一致する
    if W[i][0] != last:
        print('No')
        break
    stock.append(W[i])
    last = W[i][-1]
    #最後まで回り切ったらyesを表示
    if i+1 == len(W):
        print('Yes')

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

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

template<class T> inline bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

auto ng() {
  cout << "Impossible\n"; exit(0);
}

int main() {

  int H, W; cin >> H >> W;
  vector<string> A(H);
  rep(i, H) {
    cin >> A[i];
  }

  int y {0}, x {0};
  vector<vector<bool>> vis(H, vector<bool>(W));
  if(A[0][0] == '.') ng();
  vis[0][0] = 1;
  while(y != H-1 || x != W-1) {
    int dir = -1;
    rep(k, 4) {
      const int ny {y + dy[k]}, nx {x + dx[k]};
      if(!in_range(ny, nx, H, W)) continue;
      if(vis[ny][nx]) continue;
      if(A[ny][nx] == '.') continue;
      if(k == 0 || k == 1) ng();
      if(dir < 0) dir = k;
      else ng();
    }
    if(dir < 0) ng();
    y += dy[dir], x += dx[dir];
    vis[y][x] = 1;
  }

  rep(i, H) rep(j, W) if((A[i][j] == '#')^(vis[i][j])) ng();

  cout << "Possible\n";
  
  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 A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();

        if (K <= A) System.out.println(K);
        else if (A < K && K <= A+B) System.out.println(A);
        else System.out.println(A-(K-A-B));
    }
}

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

const int END = -1;
struct StNod
{
  int m_nKey;
  int m_nParnt;
  int m_nLeft;
  int m_nRigt;

  StNod() :
    m_nKey(END), m_nParnt(END), m_nLeft(END), m_nRigt(END)
  { }
};

void fnInput(vector<StNod> &rvoNod)
{
  StNod oNod;
  int nMaxSiz;

  cin >> nMaxSiz;
  rvoNod.resize(nMaxSiz, oNod);

  for (int i = 0; i < nMaxSiz; i++)
  {
    int nKey, nLeft, nRigt;
    cin >> nKey >> nLeft >> nRigt;

    rvoNod[nKey].m_nKey  = nKey;
    rvoNod[nKey].m_nLeft = nLeft;
    rvoNod[nKey].m_nRigt = nRigt;
    if (nLeft != END)  rvoNod[nLeft].m_nParnt = nKey;
    if (nRigt != END)  rvoNod[nRigt].m_nParnt = nKey;
  }
}

void fnPreOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  cout << " " << nx;
  fnPreOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPreOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
}

void fnInOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  fnInOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  cout << " " << nx;
  fnInOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
}

void fnPostOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
  cout << " " << nx;
}

void fnTreeWalk(const vector<StNod> &cnrvoNod)
{
  int nx = 0;
  while (cnrvoNod[nx].m_nParnt != END)
    nx = cnrvoNod[nx].m_nParnt;

  cout << "Preorder" << endl;
  fnPreOrder(cnrvoNod, cnrvoNod[nx].m_nKey);
  cout << endl;

  cout << "Inorder" << endl;
  fnInOrder(cnrvoNod, cnrvoNod[nx].m_nKey);
  cout << endl;

  cout << "Postorder" << endl;
  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nKey);
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<StNod> voNod;

  fnInput(voNod);
  fnTreeWalk(voNod);
  return 0;
}

Measured memory_bytes: 3176
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#define lch (n<<1)
#define rch ((n<<1)+1)
using namespace std;
const int maxn=1e6+10;
int n,st[maxn],nt[maxn],to[maxn],topt,v[maxn],vv[maxn],linum,ans[maxn],root=1;
struct da{int ma;}a[4*maxn];
map<int,int>lc;
inline void add(int x,int y){to[++topt]=y; nt[topt]=st[x]; st[x]=topt;}
inline void updata(int n){a[n].ma=max(a[lch].ma,a[rch].ma);}
void tree_fz(int n,int l,int r,int lc,int k)
{
	if (l==r) {a[n].ma=k; return;}
	int mid=(l+r)>>1;
	if (lc<=mid) tree_fz(lch,l,mid,lc,k);else tree_fz(rch,mid+1,r,lc,k);
	updata(n);
}
int qury(int n,int L,int R,int l,int r)
{
	if (l>r) return 0;
	if (L==l && R==r) return a[n].ma;
	int mid=(L+R)>>1;
	if (r<=mid) return qury(lch,L,mid,l,r);
	else if (l>=mid+1) return qury(rch,mid+1,R,l,r);
	else return max(qury(lch,L,mid,l,mid),qury(rch,mid+1,R,mid+1,r));
}
void dfs(int x,int fa)
{
	int prev=qury(root,1,linum,v[x],v[x]);
	int now=max(prev,qury(root,1,linum,1,v[x]-1)+1);
	tree_fz(root,1,linum,v[x],now); ans[x]=a[root].ma;
	int p=st[x];
	while (p)
	{
		if (to[p]!=fa) dfs(to[p],x);
		p=nt[p];
	}
	tree_fz(root,1,linum,v[x],prev);
}
int main()
{
	memset(a,0,sizeof a);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&v[i]),vv[i]=v[i];
	sort(vv+1,vv+n+1);
	for (int i=1;i<=n;i++) if (!lc.count(vv[i])) lc[vv[i]]=++linum;
	//printf("lala %d\n",linum);
	for (int i=1;i<=n;i++) v[i]=lc[v[i]];
	for (int i=1;i<n;i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	dfs(1,0);
	for (int i=1;i<=n;i++) printf("%d\n",ans[i]);
return 0;
}

Measured memory_bytes: 42668
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    int n;
    cin>>n;
    int a[n];
    unordered_map<int,int>mp;
    rep(i,0,n)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    int res=0;
    rep(i,0,n)
    {
        if(mp[a[i]]==1)
        {
            int c=a[i];
            int flag=0;
            if(c==1)
            {
                res++;
                continue;
            }
            for(int j=1;j*j<=c;j++)
            {
                if(c%j==0)
                {
                    if(mp[j]>=1)
                    {
                        if(j!=c){
                        flag=1;
                        break;
                        }
                    }
                    if(mp[c/j]>=1)
                    {
                        if(c/j!=c)
                        {
                            flag=1;
                            break;
                        }
                    }
                }
            }
            if(flag==0)
            res++;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 32524
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string str;
  cin >> str;
    if(str.at(0)=='S'){
      if(str.at(1)=='A'){
        cout<<1<<endl;
      }else{
        cout<<7<<endl;
      }
    }else if(str.at(0)=='M'){
      cout<<6<<endl;
    }else if(str.at(0)=='T'){
      if(str.at(1)=='U'){
        cout<<5<<endl;
      }else{
        cout<<3<<endl;
      }
    }else if(str.at(0)=='W'){
      cout<<4<<endl;
    }else if(str.at(0)=='F'){
      cout<<2<<endl;
    }
    return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;
int l1,l2,a,b,c;

int cmmdc(int a,int b)
{
    if(a>b) return cmmdc(b,a);
    if(a==0) return b;
    return cmmdc(b%a,a);
}

int main()
{
    cin>>a>>b>>c;
    if(cmmdc(b,c)%cmmdc(a,b)==0) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	double L;
    cin >> L;

    cout << fixed << setprecision(8) << (L/3)*(L/3)*(L/3) <<endl;
    
  	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int N, M;

void solve() {
    ll ans = 0;
    ans = (1900 * M + (N - M) * 100) * ll(pow(2, M));
    cout << ans << endl;
}

int main() {
    cin >> N >> M;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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; }



int main() {
    int n;
    cin >> n;
    vector<int>a(n+1);
    vector<int>b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,n+1) {
        if(b[i]-a[i] >= 0) {
            ans += a[i];
            b[i] -= a[i];
            if(a[i+1]-b[i]>=0) { 
                ans += b[i];
                a[i+1] -= b[i];
            }    
            else {
                ans += a[i+1];
                a[i+1] = 0;
            }
        } else {
            ans += b[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){
    int n;
    cin>>n;
    vll fib(n+1);
    fib[0]=2;fib[1]=1;
    for(int i=2;i<=n;i++){
        fib[i]=fib[i-1]+fib[i-2];
    }
    cout<<fib[n]<<endl;
}



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

Measured memory_bytes: 3656
# ABC139E - League
from collections import deque


def main():
    N = int(input())
    A = [0] + list(deque(map(int, input().split())) for _ in range(N))
    cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1)
    q = deque(list(range(1, N + 1)))
    while q:
        x = q.popleft()
        if not A[x]:  # player x has finished all games
            continue
        y = A[x].popleft()  # the opponent of x
        if cur[y] == x:  # player y's next game is against x and vice versa
            cnt += 1
            days[x] = days[y] = max(days[x], days[y]) + 1  # day of playing the game
            cur[x], cur[y] = 0, 0  # no next game is currently planned
            q.append(x), q.append(y)
        else:  # the opponent will do another game before playing against x
            cur[x] = y
    flg = cnt == N * (N - 1) // 2  # finished all scheduled games or not
    print(max(days) if flg else -1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 80220
import java.util.*;
public class Main {
    
    public static void main(String[] args) throws InterruptedException{
        Scanner sc = new Scanner(System.in);
        
        
        String codefestival = "CODEFESTIVAL2016";
        String query = sc.nextLine();
        
        int mistake = 0;
        
        for(int i = 0;i<16;i++){
            if(codefestival.charAt(i) != query.charAt(i)){
                mistake++;
            }
        }
        System.out.println(mistake);
    }
}

Measured memory_bytes: 9044
n,m = map(int,input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for i in range(n-m+1):
  for p in range(n-m+1):
    for c in range(m):
      if B[c] != A[p+c][i:i+m]:
        break
    else:
      print("Yes")
      exit()
print("No")


Measured memory_bytes: 3060
# D - 

import queue

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

INF = 10 ** 5 + 1
ans = [INF] * N
Q = queue.Queue()
Q.put(0)
ans[0] = 0
while not Q.empty():
    u = Q.get()
    for g in G[u]:
        if ans[g] == INF:
            ans[g] = u + 1
            Q.put(g)

if max(ans) == INF:
    print('No')
else:
    print('Yes')
    for i in range(1, len(ans)):
        print(ans[i])


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

#include <bits/stdc++.h>

class UnionFind {
public:
    // parent node index if not root index
    // minus size of the tree if root index
    std::vector<int> data;
    int cnt;

    UnionFind(int n) {
        data.resize( n, -1 );
        cnt = n;
    }

    int find(int x) {
        if ( data[x] < 0 ) {
            return x;
        } else {
            int r = find( data[x] );
            data[x] = r;
            return r;
        }
    }

    void unite(int x, int y) {
        int r = find(x);
        int s = find(y);
        if ( r != s ) {
            if ( data[r] > data[s] ) {
                int t = r;
                r = s;
                s = t;
            }
            data[r] += data[s];
            data[s] = r;
            cnt--;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int number_of_trees() {
        return cnt;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    int x,y,z;
    UnionFind f(N);
    for ( int i = 0; i < M; i++ ) {
        cin >> x >> y >> z;
        x--; y--;
        f.unite(x,y);
    }
    
    cout << f.number_of_trees() << '\n';
    return 0;
}

Measured memory_bytes: 764
n, m = map(int,input().split())
depends = []
for i in range(m):
    depends.append([ int(i)-1 for i in input().split() ])
p = [ int(i) for i in input().split() ]
ans = 0
for i in range(2**n):
    chosen = set()
    for j in range(n):
        if i & (1<<j):
            chosen.add(j)
    # Now in this iteration we have chosen those element in chosen
    ok = 0
    for j in range(m):
        # Required count
        req = p[j]
        cnt = 0
        for k in range(1,depends[j][0]+2):
            if depends[j][k] in chosen:
                cnt += 1
        if cnt % 2 == req:
            ok += 1

    if ok == m:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll n, k, t, u, v, l; scanf("%lld %lld %lld %lld %lld %lld", &n, &k, &t, &u, &v, &l);
	vector<ll> d(n); for (int i = 0; i < n; i++) scanf("%lld", &d[i]);
	double curx = 0;
	double curt = 0;
	int curc = 0;
	int right = 0;
	d.push_back(l);
	n += 1;
	while (curx + 1e-14 < l) {
		if (curc == 0) {
			curt += (double)(d[right] - curx) / u;
			curx = d[right];
			curc = 1;
			right++;
		}
		else {
			curc -= 1;
			double nx = curx + v * t;
			chmin(nx, (double)l);
			while (right < n and d[right] <= nx) {
				curc++;
				if (curc > k) {
					nx = d[right] + v * t;
					chmin(nx, (double)l);
					curc = k;
				}
				right++;
			}
			curt += (double)(nx - curx) / v;
			curx = nx;
		}
	}
	cout << fixed << setprecision(12) << curt << endl;
	return 0;
}



Measured memory_bytes: 3340
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 1100000000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int C[30];


int main(){
  bool flag=true;
  string S,T;
  cin>>S>>T;
  int s[210000],t[210000];
  for(int i=0;i<30;i++) C[i]=-1;
  for(int i=0;i<(int)S.size();i++){
    s[i]=S[i]-'a';
    t[i]=T[i]-'a';
  }

  for(int i=0;i<(int)S.size();i++){
    if(C[s[i]]==-1){
      C[s[i]]=t[i];
    }else{
      if(C[s[i]]!=t[i]){
        flag=false;
        break;
      }
    }
  }
  sort(C,C+30);
  for(int i=0;i<29;i++){
    if(C[i]==C[i+1] && C[i]!=-1) flag=false;
  }
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 2300
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int ans=10,i,j,k,a,b,r=1,l,m,min,max,y[100010]={1};
  int d[100010][20]={};
  char s[100010];
  scanf("%s",s);
  for(l=0;s[l];l++);
  for(i=0;i<=l;i++){
    for(j=0;j<20;j++)d[i][j]=-1;
  }
  d[0][0]=10;
  for(i=2;i*i<=l;i++){
    if(l%i==0){
      y[r++]=i;
      y[r++]=l/i;
    }
  }
  //for(i=0;i<r;i++)printf("%d ",y[i]);printf("\n");
  for(i=0;i<r;i++){//printf("%d:\n",y[i]);
    m=l/y[i];
    for(j=0;j<y[i]-1;j++){
      for(k=0;k<m;k++){//printf("%d ",j+y[i]*k);
	if(s[j]-s[j+y[i]*k])goto NEXT;
      }//printf("\n");
    }//printf("\n");
    min='9';
    max='0';
    for(j=0;j<m;j++){
      min=MIN(min,s[(j+1)*y[i]-1]);
      max=MAX(max,s[(j+1)*y[i]-1]);
    }//printf("!%d %d\n",max,min);
    ans=MIN(ans,max-min);
  NEXT:;
  }
  //printf("!!%d\n",ans);
  for(i=0;i<l;i++){
    for(j=0;j<20;j++){//printf("%5d ",d[i][j]);
      if(d[i][j]<0)continue;
      a=(s[i]-'0')*10+s[i+1]-'0';
      a=MAX(j,a);
      if(s[i]=='1'&&s[i+1])d[i+2][a]=MAX(d[i+2][a],d[i][j]);
      a=MAX(j,s[i]-'0');
      if(d[i][j]==-1)b=s[i]-'0';
      else b=MIN(d[i][j],s[i]-'0');
      d[i+1][a]=MAX(d[i+1][a],b);
    }//printf("\n");
  }
  for(i=0;i<20;i++){//printf("%5d ",d[l][i]);
    if(d[l][i]<0)continue;
    ans=MIN(ans,i-d[l][i]);
  }//printf("\n");
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 10156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pa;
typedef map<int,int> ma;
typedef set<int> se;
typedef vector<int> ve;
const int maxn=1e5+7;
const int mod=1e9+7;
const int N=1e5+7;
const int inf=1e9+7;
//int a[maxn];
int main() {
    string a,b;
    cin>>a>>b;
    int c,d;
    cin>>c>>d;
    string s;
    cin>>s;
    if(s==a) c--;
    else d--;
    cout<<c<<" "<<d<<endl;
	return 0;
}


Measured memory_bytes: 256
//Catchharsh
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (int x,int n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    vector<ll> seve;
    void  seveprime()
    {
      int prime[1000000]={0};
      for(int i=2;i*i<1000000;i++)
       {
        if(prime[i]==0)
         {
      	  for(int j=i*2;j<=1000000;j+=i)
           prime[j]=1;
         }
       }
       for(int i=2;i<=1000000;i++)
       {
       	if(prime[i]==0)
       		seve.pb(i);
       }
    }
    int main()
    {   
         IOS;
         ll r,d,t;
         cin>>r>>d>>t;
         ll ar[10];
         ar[0]=r*t-d;
         cout<<ar[0]<<endl;
         for(int i=1;i<10;i++)
         {
         	ar[i]=r*ar[i-1]-d;
         	cout<<ar[i]<<endl;
         }
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int solve(vector<int> v)
{
	if(v.size() == 1)
	{
		return v[0];
	}
	int mn = 1e9;
	for(int i = 0; i < v.size(); i++)
	{
		mn = min(mn, v[i]);
	}
	vector<int> tmp;
	int ans = mn;
	for(int i = 0; i < v.size(); i++)
	{
		if(v[i] == mn)
		{
			if(!tmp.empty())
			{
				ans += solve(tmp);
				tmp.clear();
			}
		}
		else
		{
			tmp.push_back(v[i] - mn);
		}
	}
	if(!tmp.empty())
	{
		ans += solve(tmp);
	}
	return ans;
}
vector<int> v;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x);
		v.push_back(x);
	}
	printf("%d\n", solve(v));
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n,i;
	int max,min;
	long long sum;
	sum = 0;
	max = -1000000;
	min = 1000000;
	scanf("%ld",&n);
	for(i=0;i<n;i++){
		int a;
		scanf("%ld",&a);
		if(a>max) max = a;
		if(a<min) min = a;
		sum += a;
	}
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int right=a+b;
  int left=c+d;
  string ret;
  if(right>left){
    ret="Left";
  }else if(right==left){
    ret="Balanced";
  }else{
    ret="Right";
  }
  cout<<ret;
  return 0;
}

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

int main(){
    int m, k;
    cin >> m >> k;
    if (k == 0) {
        for (int i = 0; i < pow(2, m); i++) cout << i << " ";
        for (int i = 0; i < pow(2, m); i++) cout << pow(2, m) - 1 - i << " ";
        cout << endl;
    }
    else {
        int xr = 0;
        for (int i = 1; i < pow(2, m); i++) {
            if (i != k) xr ^= i;
        }
        if (xr == k) {
            for (int i = 0; i < pow(2, m); i++) {
                if (i != k) cout << i << " ";
            }
            cout << k << " ";
            for (int i = 0; i < pow(2, m); i++) {
                if (pow(2, m) - 1 - i != k) cout << pow(2, m) - 1 - i << " ";
            }
            cout << k << endl;
        }
        else cout << -1 << endl;
        
    }
    
    
}


Measured memory_bytes: 1792
/*
 * pr2_main.c
 *
 *  Created on: 2020/02/04
 *      Author: 113207
 */


/*
 * https://atcoder.jp/contests/abc042/tasks/abc042_b
 */

#include <stdio.h>
#include <string.h>

int main(void) {

	unsigned int n;
	unsigned int l;
	scanf("%d %d", &n, &l);

	char str[n][l+1];
	char tmp[l+1];
	//char cat_str = '\0';
	int i, j;



	for(i = 0; i < n; i++) {
		scanf("%s", str[i]);
	}

	for(i = 0; i < n; i++) {
		for(j = i + 1; j < n; j++) {
			if(strncmp(str[i], str[j], l) > 0) {
				strcpy(tmp, str[i]);
				strcpy(str[i], str[j]);
				strcpy(str[j], tmp);
			}
		}

	}

	for(i = 0; i < n; i++) {
		printf("%s", str[i]);
	}



	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	m=(S%3600)/60;
	s=S-(h*3600+m*60);
	
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

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

int main() {
    string S;
    int cnt0 = 0, cnt1 = 0;
    cin >> S;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '0') {
            cnt0 += 1;
        } else {
            cnt1 += 1;
        }
    }
    cout << 2 * min(cnt0, cnt1) << endl;
    return 0;
}

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, m; cin >> n;
    vector<ll> A, B;
    vector<P> ans;

    rep(i, n) {
        ll x; cin >> x;
        if(x < 0) A.push_back(x);
        else B.push_back(x);
    }
    ll a = A.size(), b = B.size();
    sort(ALL(A));
    sort(ALL(B));

    if(a > 0 && b > 0) {
        frep(i, 1, b-1) {
            ans.push_back(make_pair(A[0], B[i]));
            A[0] -= B[i];
        }
        rep(i, a) {
            ans.push_back(make_pair(B[0], A[i]));
            B[0] -= A[i];
        }
        m = B[0];
    }
    else if(a == 0) {
        frep(i, 2, b-1) {
            ans.push_back(make_pair(B[0], B[i]));
            B[0] -= B[i];
        }
        ans.push_back(make_pair(B[1], B[0]));
        B[1] -= B[0];
        m = B[1];
    }
    else if(b == 0) {
        rep(i, a-1) {
            ans.push_back(make_pair(A[a-1], A[i]));
            A[a-1] -= A[i];
        }
        m = A[a-1];
    }

    cout << m << endl;

    rep(i, n-1) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }


    /*
    sort(ALL(B));
    ll b = B.size();
    rep(i, b/2) {
        ans.push_back(make_pair(B[i], B[b-1-i]));
        A.push_back(B[i] - B[b-1-i]);
    }

    sort(ALL(A));
    ll a = A.size();
    if((b%2) == 1) {
        m = B[b/2];
        rep(i, a) {
            ans.push_back(make_pair(m, A[i]));
            m = m - A[i];
        }
    }
    else {
        m = A[a-1];
        rep(i, a-1) {
            ans.push_back(make_pair(m, A[i]));
            m = m - A[i];
        }
    }

    cout << m << endl;
    rep(i, n-1) {
        ll x = ans[i].first, y = ans[i].second;
        cout << x << " " << y << endl;
    }
    */

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 7072
from math import floor
import sys
from copy import copy
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353

aa, bb = map(int, input().split())
for i in range(1, 10000):
    if int(floor(i * 0.08)) == aa and int(floor(i * 0.1)) == bb:
        print(i)
        sys.exit()
print("-1")


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i=s;i<n;i++)
 
int main()
{
  int a[5];
  int ans;
  rep(i,0,5)
  {
    cin >> a[i];
    if(a[i]==0)
      ans=i+1;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1,s2,s3;
    int a,b;
    cin>>s1>>s2;
    cin>>a>>b;
    cin>>s3;
    if(s3==s1)
    {
        cout<<(a-1)<<" "<<b;
    }
    else
    {
        cout<<a<<" "<<(b-1);
    }
}


Measured memory_bytes: 256