akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL n,c,k,t[101010]={};
	cin>>n>>c>>k;
	FOR(i,0,n){
		cin>>t[i];
	}
	sort(t,t+n);
	int ans=0,idx=0;
	while(idx<n){
		int tmp=t[idx];
		ans++;
		int tmpidx=idx;
		FOR(j,1,c){
			if(idx+j>=n||tmp+k<t[idx+j]){
				tmpidx+=j-1;
				break;
			}
			if(j==c-1)tmpidx=idx+j;
		}
		idx=tmpidx+1;
	}
	cout<<ans;
    return 0;
}


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

using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int n = A[N - 1];
  auto score = [&](int r) {
    if (n % 2 == 0) return abs(n / 2 - r);
    return min(abs(n / 2 - r), abs(n / 2 + 1 - r));
  };
  int r = 0;
  int s = 1e9 + 10;
  for (int i = 0; i < N - 1; i++) {
    if (chmin(s, score(A[i]))) {
      r = A[i];
    }
  }
  cout << n << " " << r << endl;

  return 0;
}
/* vim:set fdm=marker: */


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

int n;
ll ans;

int main() {
    cin >> n;
    vector<P> v(n);
    rep(i, n) {
        cin >> v[i].first >> v[i].second;
        v[i].first += v[i].second;
    }
    sort(v.begin(), v.end(), greater<P>());
    bool taka = true;
    rep(i, n) {
        if (taka) {
            ans += v[i].first - v[i].second;
            taka = false;
        } else {
            ans -= v[i].second;
            taka = true;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int ara[5], temp = 0;
	for (int i = 0; i < 5; ++i)
	{
		cin >> ara[i];
		if (ara[i] == 0)
		{
			temp = i + 1;
		}
	}
	cout << temp;
	return 0;
}

Measured memory_bytes: 3572
# coding: utf-8
# Your code here!

N,M = map(int,input().split())
lst = list(map(int,input().split()))
lst.sort(reverse = True)
sabun = []
for i in range(len(lst)-1):
    sabun.append(lst[i] - lst[i+1])
sabun.sort()
ans = 0
for i in range(len(sabun)-N+1):
    ans+=sabun[i]
print(ans)

Measured memory_bytes: 13960
#include<cstdio>
using namespace std;
int main(){
  int A,B,n;
  int a,b;
  while(true){
    scanf("%d",&n);
    if(n == 0)
      break;
    A = B = 0;
    for(int i = 0 ; i < n ; i++){
      scanf("%d %d",&a,&b);
      if(a > b)
        A += (a + b);
      else if(a < b)
        B += (a + b);
      else{
        A += a;
        B += a;
      }
    }
    printf("%d %d\n",A,B);
  }
}



Measured memory_bytes: 2656
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    string s, t; cin >> s >> t;
    int ans = 0;
    int n = s.length();
    rep(i,n) if(s[i] != t[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3912
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)res=res*x%m;
		y>>=1;x=x*x%m;
	}
	return res;
}
int perm[1000001],inv[1000001];
void init_perm(){
	perm[0]=1;
	REP(i,1000001)perm[i]=perm[i-1]*i%mod;
	inv[1000000]=mod_pow(perm[1000000],mod-2);
	for(int i=999999;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
int nCk(int x,int y){
	if(x<y)return 0;
	return perm[x]*inv[x-y]%mod*inv[y]%mod;
}

int N,u,v;
int depth[100005],mx[100005],par[100005];
vector<int>G[100005];
int dfs(int x,int p){
	mx[x]=depth[x];
	for(int i:G[x])if(i!=p){
		depth[i]=depth[x]+1;
		par[i]=x;
		chmax(mx[x],dfs(i,x));
	}
	return mx[x];
}
signed main(){
	cin>>N>>u>>v;u--;v--;
	rep(i,N-1){
		int a,b;cin>>a>>b;a--;b--;
		G[a].pb(b);G[b].pb(a);
	}
	dfs(v,v);
	int now=u,ans=0;
	while(depth[now]>=depth[u]/2+1){
		chmax(ans,mx[now]);
		now=par[now];
	}
	cout<<ans-1<<endl;
}


Measured memory_bytes: 13568
N, M = map(int, input().split())
c = []
for i in range(M):
	c.append(list(map(int, input().split())))
d = []
e = []


for i in range(M):
	if c[i][0] == 1:
		d.append(c[i][1])

for i in range(M):
	if c[i][1] == N:
		e.append(c[i][0])

l = list(set(d) & set(e))

if l == []:
	print('IMPOSSIBLE')
else:
	print('POSSIBLE')

Measured memory_bytes: 61164
function A(){
   var max=0;
   var ary=[];
   for(var i=1;i<=8;i++){
      for(var j=1;j<=8;j++){
         if(yx[i][j]!=".")continue;
         var cnt=seach(i,j,"x","o");
         if(cnt>max){ary=[i,j];max=cnt;}
      }
   }
   return ary;
}
function B(){
   var max=0;
   var ary=[];
   for(var i=8;i>=1;i--){
      for(var j=8;j>=1;j--){
         var cnt=seach(i,j,"o","x");
         if(yx[i][j]!=".")continue;
         if(cnt>max){ary=[i,j];max=cnt;}
      }
   }
   return ary;
}
function seach(y,x,a,b){
   var dy=[-1,-1,-1,0,0,1,1,1];
   var dx=[-1,0,1,-1,1,-1,0,1];
   var sum=0;
   for(var i=0;i<8;i++){
      var DY=dy[i];
      var DX=dx[i];
      var cnt=0;
      var k=1; 
      while(true){
         if(yx[y+DY*k][x+DX*k]=="f" || yx[y+DY*k][x+DX*k]==".")break;
         else if(yx[y+DY*k][x+DX*k]==a)cnt++;
         else if(yx[y+DY*k][x+DX*k]==b){sum+=cnt;break;}
         k++;
      }
   }
   return sum;
}
function change(y,x,a,b){
   yx[y][x]=b;
   var dy=[-1,-1,-1,0,0,1,1,1];
   var dx=[-1,0,1,-1,1,-1,0,1];
   var cnt=0;
   for(var i=0;i<8;i++){
      var DY=dy[i];
      var DX=dx[i];
      var cnt=0;
      var k=1;
      var flag=false;
      while(true){
         if(yx[y+DY*k][x+DX*k]=="f" || yx[y+DY*k][x+DX*k]==".")break;
         else if(yx[y+DY*k][x+DX*k]==a)flag=true;
         else if(yx[y+DY*k][x+DX*k]==b){
            if(flag){
               while(k--)yx[y+DY*k][x+DX*k]=b;
            }
            break;
         }
         k++;
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var yx=[];
yx.push("ffffffffff".split(""));
arr.forEach(function(v){
   v="f"+v+"f";
   yx.push(v.split(""));
});
yx.push("ffffffffff".split(""));
var pass=0;
while(true){
   var ansA=A();
   if(ansA.length==0)pass++;
   else {pass=0;change(ansA[0],ansA[1],"x","o");}
   var ansB=B();
   if(ansB.length==0)pass++;
   else {pass=0;change(ansB[0],ansB[1],"o","x");}
   if(pass>=2)break;
}
yx.shift();
yx.pop();
console.log(yx.join("\n").replace(/\,|f/g,""));

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

int main() {
  string ns; cin >> ns;
  int n = stoi(ns);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    if (s.size() % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 200005
#define P 998244353
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int L, n, x[MAXN];
LL ans, l[MAXN], r[MAXN];

void solve()
{
    l[0]=r[n+1]=0;
    for(rint i=1; i<=n; ++i) l[i]=l[i-1]+x[i];
    for(rint i=n; i>=1; --i) r[i]=r[i+1]+L-x[i];
    for(rint i=0; i<n; ++i)
    {
        if((n-i)&1)
        {
            int pos=i+1+(n-i)/2;
            ans=max(ans, l[pos-1]+l[pos]+r[pos+1]*2-l[i]*2);
           //printf("%d %d %lld!!!\n", i, pos, ans);
        }
        else
        {
            int pos=i+1+(n-i)/2;
            ans=max(ans, l[pos-1]*2+r[pos]+r[pos+1]-l[i]*2);
            //printf("%d %d %lld!!!\n", i, pos, ans);
        }
    }
}

int main()
{
    scanf("%d%d", &L, &n);
    for(rint i=1; i<=n; ++i) scanf("%d", &x[i]);
    solve();
    for(rint i=1; i<=n; ++i) x[i]=L-x[i];
    reverse(x+1, x+n+1);
    solve();
    printf("%lld\n", ans);
    return 0;
}

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

int main()
{
    int n;
    string s1, s2;
    cin >> n >> s1 >> s2;

    ll ans;
    int pos, i; //0が縦、1が横
    //先頭のみ例外処理
    if (s1[0] == s2[0])
    {
        i = 1;
        ans = 3;
        pos = 0;
    }
    else
    {
        i = 2;
        ans = 6;
        pos = 1;
    }

    while (i < s1.length())
    {
        if (pos == 0 && s1[i] == s2[i])
        {
            ans = (ans * 2) % MOD;
            i += 1;
            pos = 0;
        }
        else if (pos == 0 && s1[i] != s2[i])
        {
            ans = (ans * 2) % MOD;
            i += 2;
            pos = 1;
        }
        else if (pos == 1 && s1[i] == s2[i])
        {
            i += 1;
            pos = 0;
        }
        else if (pos == 1 && s1[i] != s2[i])
        {
            ans = (ans * 3) % MOD;
            i += 2;
            pos = 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [0] + list(map(int, input().split()))
b = [0] * (n+1)
for i in range(n, 0, -1):
  x = 0
  for k in range(1, n//i + 1):
    x += b[i*k]
    #print(i, k, i*k)
  b[i] = 0 if x%2 == a[i] else 1
#print(b)
ans = [i for i in range(n+1) if b[i] == 1]
#print(ans)
print(len(ans))
if len(ans) > 0:
  print(' '.join([str(a) for a in ans]))

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

int main()
{
   int N; cin>>N;
   vector<vector<int>> score(N,vector<int>(3));
   for(int i=0;i<N;i++) for(int j=0;j<3;j++) cin>>score[i][j];

   vector<vector<int>> dp(N,vector<int>(3));
   dp[0]=score[0];
   for(int i=1;i<N;i++) for(int j=0;j<3;j++){
      for(int k=0;k<3;k++) if(k!=j){
         dp[i][j]=max(dp[i][j],dp[i-1][k]+score[i][j]);
      }
   }
   cout<<*max_element(dp[N-1].begin(),dp[N-1].end())<<endl;
   return 0;
}


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

struct node {
	int key;
	node *right, *left, *parent;
	node(int key_) {
		key = key_;
		right = left = parent = NULL;
	}
	~node() {
		if (right != NULL) delete right;
		if (left != NULL) delete left;
	}
};

struct Binary_Tree {
	node *head;
	Binary_Tree() {
		head = NULL;
	}
	~Binary_Tree() {
		if (head != NULL) delete head;
	}
	void insert(int z) {
		insert(new node(z));
	}
	void insert(node* z) {
		node *y = NULL, *x = head;
		while(x != NULL){
			y = x;
			if (z->key < x->key)
				x = x->left;
			else
				x = x->right;
		}
		z->parent = y;

		if (y == NULL) {
			head = z;
		}
		else if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
	void Inorder(node *n) {
		if (n == NULL) return;
		Inorder(n->left);
		cout << ' ' << n->key;
		Inorder(n->right);
	}
	void Preorder(node *n) {
		if (n == NULL) return;
		cout << ' ' << n->key;
		Preorder(n->left);
		Preorder(n->right);
	}
	void print() {
		Inorder(head); cout << endl;
		Preorder(head); cout << endl;
	}
};

int main()
{
	int m;
	string s;
	Binary_Tree bt;
	cin >> m;
	for (int i = 0, n; i < m; i++) {
		cin >> s;
		if (s == "insert") {
			cin >> n;
			bt.insert(n);
		}
		else {
			bt.print();
		}
	}
	return 0;
}

Measured memory_bytes: 26424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  
 double a,b;
  cin>>a>>b;
  ll A = a;
  b*=100.01;
  b+=1e-5;
  ll B = b;
  A*=B;
  cout<<A/100<<endl;
}

Measured memory_bytes: 3732
fun main(args: Array<String>) {
    val N = nextInt()
    val L = listOfInt().sortedDescending()
var sum = 0
for (n in 0 .. (N -1)*2 step 2) {
  sum += L[n+1]
}
 println(sum)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun printErr(value: Any) = System.err.println(value)

Measured memory_bytes: 37604
N, M = map(int, input().split())
L = [0] * M
R = [0] * M
min = 1
max = N
X = 0
for i in range(M):
    L[i], R[i] = map(int, input().split())
    if L[i] > min:
        min = L[i]
    if R[i] < max:
        max = R[i]
    if R[i] < min or L[i] > max:
        X +=1


if X == 0:
    print(max-min+1)
else:
    print(0)


Measured memory_bytes: 10868
#include <stdio.h>
#define mod 998244353
typedef long long ll;

int main(void) {
  ll i, j, k, n, s, ans = 0;
  scanf("%lld%lld", &n, &s);
  ll a, dp[s];
  for(i = 0; i < s; ++i) dp[i] = 0;
  dp[0] = 1;
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    if(s >= a) ans += dp[s - a] * (n - i), ans %= mod;
    if(a < s) for(j = s - a - 1; j >= 0; --j) dp[j + a] += dp[j], dp[j + a] %= mod;
    dp[0]++;
  }
  printf("%lld", ans);
  return 0;
}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    ll N,M;
    cin >> N >> M;

    ll ans1 = 1;
    ll ans2 = 1;

    rep(i,N+M) {
        if (i%2==0) ans1 *= N-i/2, ans2 *= M-i/2;
        else ans1 *= M-i/2, ans2 *= N-i/2;
        ans1%=MOD;
        ans2%=MOD;
        
    }
    ll ans = ans1 + ans2;
    ans %= MOD;
    cout << ans << endl;
}


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

class UnionFind {
public:
    
    vl parent;  // 親ノード
    vl Siz;  // 集合の大きさ

    // コンストラクタ
    UnionFind(ll n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(ll n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    ll root(ll x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }
        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }
        Siz[x] += Siz[y];
        parent[y] = x;
    }
    
    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    ll size(ll x) {
        return Siz[root(x)];
    }
    
};

struct Edge {
    ll a, b, cost, index;
    bool operator<(const Edge &e) const {
        return (cost < e.cost);
    }
};

int main() {
    ll n;
    cin >> n;

    vector<P> px(n), py(n);
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        px[i] = make_pair(x, i);
        py[i] = make_pair(y, i);
    }
    sort(all(px));
    sort(all(py));

    const ll m = 2*n-2;
    vector<Edge> es(m);  // es[i] : 辺iは頂点es[i].aと頂点es[i].bをコストes[i].costで結ぶ
    rep(i, n-1) {
        es[i].a = px[i].second;
        es[i].b = px[i+1].second;
        es[i].cost = px[i+1].first - px[i].first;
    }
    rep(i, n-1) {
        es[i+(n-1)].a = py[i].second;
        es[i+(n-1)].b = py[i+1].second;
        es[i+(n-1)].cost = py[i+1].first - py[i].first;
    }
    sort(all(es));  // esをcostの昇順でソート

    UnionFind Uni(n);
    Uni.init(n);
    
    // クラスカル法。計算量はO(E*log(E))
    ll min_cost = 0;
    rep(i, m) {
        if(!Uni.same(es[i].a, es[i].b)) {
            Uni.unite(es[i].a, es[i].b);
            min_cost += es[i].cost;
        }
    }

    out(min_cost);
    re0;
}

Measured memory_bytes: 13184
n, m = [int(v) for v in input().split()]

count_map = [0] * (n + 1)
miss_map = [0] * (n + 1)

count = 0
miss = 0
for i in range(m):
    p, s = input().split()
    p = int(p)

    if count_map[p]:
        continue

    if s == 'AC':
        count_map[p] = True
        count += 1
        miss += miss_map[p]
    else:
        miss_map[p] += 1

print(count, miss)

Measured memory_bytes: 4596
#include<stdio.h>
#include<string.h>
#include<string.h>
char c[200001][11];
int sort(int a,int b,char s[][11]){
  if(a==b)
    return 0;
  sort(a,(a+b)/2,s);
  sort((a+b)/2+1,b,s);
  int i=a,j=(a+b)/2+1,k=a;
  while(k<=b){
    if(i<(a+b)/2+1 && j<b+1){
      if(strcmp(s[i],s[j])>0){
        strcpy(c[k],s[i]);
        i++;
      }
      else{
        strcpy(c[k],s[j]);
        j++;
      }
    }
    else if(j>b){
      strcpy(c[k],s[i]);
      i++;
    }
    else{
      strcpy(c[k],s[j]);
      j++;
    }
    k++;
  }
  for(i=a;i<=b;i++)
    strcpy(s[i],c[i]);
  return 0;
}

int main(){
  int n,i,j,count=1;
  scanf("%d",&n);
  char s[n+1][11];
  for(i=0;i<n;i++)
    scanf("%s",s[i]);
  sort(0,n-1,s);
  for(i=0;i<n-1;i++)
    if(strcmp(s[i],s[i+1])!=0)
      count++;
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 6012
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring> 
using namespace std;
int a[15],x,y;
char b[15];
void dfs(int m)
{
	if(m>3&&x==7)
	{if(y==0)
		{
		printf("%d",a[0]);
		for(int i=1;i<m;i++)
		{
			printf("%c%d",b[i],a[i]);
		}
		cout<<"=7"<<endl;
		}
		y++;return;
	}
	if(m>3)return;
	for(int i=0;i<2;i++)
	{
	if(i==0)
	{
		x-=a[m];
		b[m]='-';
		dfs(m+1);
		x+=a[m];
	}
	else 
	{
		x+=a[m];
		b[m]='+';
		dfs(m+1);
		x-=a[m];
	}
	}
}
int main()
{
    int n;
	cin>>n;
	a[3]=n%10;
	a[2]=n/10%10;
	a[1]=n/100%10;
	a[0]=n/1000;
	x=a[0];
	y=0;
	dfs(1);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF (1e10)
using namespace std;
long long int a[10000005]={0};
long long int h[10000005]={0};
long long int rslt,m;
    
long long int ans(long long int n)
{
    if(n==m) return 0;
    if(n>m) return INF;
    if(a[n] != -1) return a[n];
    a[n]=min(ans(n+1)+abs(h[n]-h[n+1]),ans(n+2)+abs(h[n]-h[n+2]));
    return a[n];
}
int main()
{
    cin>>m;
    memset(a,-1,sizeof a);
    for(int i=1; i<=m; i++)
    {
        cin>>h[i];
    }
    cout<<ans(1);
    //cout<<rslt;
}


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
// get decimal pert of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = "And I feel fine...";
    istringstream iss(sentence);
*/  

double eps = .000000001;

int main ()
{
  prep();
  int n, k;
  cin >> n >> k;
  
  long long orig[n];
  long long sum = 0;
  for (int i=0; i<n; i++){
      cin >> orig[i];
      sum += orig[i];
  }
  vector<int> factors;
  for (int i=sqrt(sum); i>=1; i--){
      if (sum%i != 0){
          continue;
      }
      if (sum/i == i){
          factors.push_back(i);
      }else{
          factors.push_back(i);
          factors.push_back(sum/i);
      }
      
  }
  sort(factors.rbegin(), factors.rend());
  for (int i=0; i<factors.size(); i++){
     
      int fact = factors[i];
     
      int need = sum/fact;
      long long sums[n] = {0};
      // assign each one in the original arr a mult of fact under or equal to it
      // sort current mods and for that mod (if there's still more needs) add 1 more fact
      vector<pair<int, int> > mods;
      for (int j=0; j<n && need > 0; j++){
          sums[j] = (orig[j]/fact)*fact;
          mods.push_back({orig[j]%fact, j});
          need -= orig[j]/fact;
      }
      sort(mods.rbegin(), mods.rend());
      for (int j=0; j<mods.size() && need > 0; j++){
          sums[mods[j].second] += fact;
          need--;
      }
      
      // count how many times we added in order to count the steps
      long long difff = 0;
      for (int j=0; j<n; j++){
          //cout << sums[j] << " ";
          difff += max(sums[j]-orig[j], 0LL);
      }
      //cout << endl;
      if (difff <= k){
          cout << fact;
          break;
      }
  }
  return 0; 
}

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

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

    if(A <= 5) cout << 0 << "\n";
    else if(A <= 12) cout << B/2 << "\n";
    else cout << B << "\n";
}

Measured memory_bytes: 256
x, y, z, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort_by{|e| -e}
b = gets.split.map(&:to_i).sort_by{|e| -e}
c = gets.split.map(&:to_i).sort_by{|e| -e}

@h = Array.new(k+1)
@l = 0

def enque(v)
    i = @l += 1
    @h[i] = v

    while i > 1 && @h[i] < @h[i/2]
        @h[i], @h[i/2] = @h[i/2], @h[i]
        i /= 2
    end
end

def deque
    x = @h[1]
    @h[1] = @h[@l] if @l > 1
    @h[@l] = nil
    @l -= 1
    i = 1

    while i * 2 <= @l
        if @h[i*2+1].nil?
            j = i * 2
        else
            j = @h[i*2] < @h[i*2+1] ? i*2 : i*2+1
        end
        break if @h[i] <= @h[j]
        @h[i], @h[j] = @h[j], @h[i]
        i = j
    end

    x
end

x.times do |xx|
    fy = y.times do |yy|
        fz = z.times do |zz|
            break zz if @l == k && a[xx] + b[yy] + c[zz] <= @h[1]
            deque if @l == k
            enque(a[xx] + b[yy] + c[zz])
        end

        break yy if fz == 0
    end

    break if fy == 0 
end

ans = []
k.times {ans << deque}
puts ans.reverse


Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[]) {
  int n,m;
  cin>>n;
  string s[n];
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  cin>>m;
  string t[m];
  for(int i=0;i<m;i++){
    cin>>t[i];
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(s[i]==t[j])  s[i]='0',t[j]='0';
    }
  }
  sort(s,s+n);
  // for(int i=0;i<n;i++){
  //   cout<<s[i]<<endl;
  // }
  int max=0,count=0;
  for(int i=0;i<n;i++){
    if(s[i]=="0") continue;
    if(s[i]!="0"){
      count++;
      for(int j=i;j<n;j++){
        if(s[j]==s[j+1]){
          count++;
        }else{
          if(count>max) max=count;
          i=j;
          count=0;
          break;
        }
      }
    }
  }
  cout<<max<<endl;
  return 0;
}

Measured memory_bytes: 256
import fractions
a,b,c,d = map(int,input().split())
t1 = b//c-a//c
if a%c == 0:
    t1 += 1
t2 = b//d-a//d
if a%d == 0:
    t2 += 1
lcm = c*d//fractions.gcd(c,d)
t3 = b//lcm-a//lcm
if a%lcm == 0:
    t3 += 1
print(b-a+1-(t1+t2-t3))

Measured memory_bytes: 5044
#include <iostream>
using namespace std;
int main(void){
    int po[8][8];
    for(int i=0;i<8;i++)for(int j=0;j<8;j++){
        if(i%2==0&&j%2==1)po[i][j]=0;
        else po[i][j]=1;
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        a--;b--;c--;d--;
        int ans=0;
        for(int i=a;i<=c;i++)for(int j=b;j<=d;j++){
            ans+=po[i][j];
        }
        printf("%d\n",ans);
    }
    
    return 0;
}



Measured memory_bytes: 3172
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

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

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int p,q; cin >> p >> q;
    int r = q / gcd(p,q);
    int s = r;
    vector<int> A;
    for (int i = 2; i*i <= r; i++) {
        if (s % i == 0) {
            A.emplace_back(i);
            while (s % i == 0) s /= i;
        }
    }
    if (s != 1) A.emplace_back(s);
    int ans = 1;
    rep(i,A.size()) ans *= A[i];

    cout << ans << endl;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define PI pair<int,int>
#define PL pair<long int,long int>
#define PLL pair<ll,ll>
#define Tcase int t;cin>>t;while(t--)   
int main(){
  int n,m;
  cin>>n>>m;
  if(m==n)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
return 0;
}

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

int main(){
    int a, b;
    while(1){
        cin >> a >> b;
        if(a == 0 && b == 0)break;
        for(int i = 0;i < a;i++){
            for(int j = 0;j < b;j++){
                cout << "#";
            }
         cout << endl;
         }
        cout << endl;
    }
    //cout << a << " " << b <<endl;
    return 0;
}

Measured memory_bytes: 3084
import itertools

N = int(input())
N_list = [int(x) for x in range(N)]
com_N_list = list(itertools.permutations(N_list,N))


point_list = []
for _ in range(N):
    x,y = map(int,input().split())
    point_list.append((x,y))

dis_list = []

for j in com_N_list:
    dis = 0
    for i in range(N-1,0,-1):
        dis += ((point_list[j[i]][0]-point_list[j[i-1]][0])**2 + (point_list[j[i]][1]-point_list[j[i-1]][1])**2)**(1/2)
    dis_list.append(dis)

ans = sum(dis_list)/(len(com_N_list))
print(ans)

Measured memory_bytes: 9332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const ll MAX_N=2e5;
ll N,A[MAX_N],dp[MAX_N],psm[MAX_N];
int main(){
	cin.tie(0);
	cin.sync_with_stdio(false);
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	psm[0]=A[0];
	for(ll i=2;i<N;i+=2){
		psm[i]=psm[i-2]+A[i];
	}
	dp[0]=0;
	dp[1]=max(A[0],A[1]);
	FOR(i,2,N){
		if(i%2==0){
			dp[i]=max(dp[i-1],A[i]+dp[i-2]);
		}else{
			dp[i]=max(psm[i-1],A[i]+dp[i-2]);
		}
	}
	cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 8288
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
string S;
int cou = 0;
cin >> S;
if(S[0] == 'o')cou++;
if(S[1] == 'o')cou++;
if(S[2] == 'o')cou++;
cout << 700 + cou * 100 << endl;

        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
#define int long long
typedef long long ll;
#define MAXN 800006
int n , m;
int A[MAXN] , S , res;
signed main() {
    cin >> n;
    for( int i = 1 ; i <= n ; ++ i ) cin >> A[i] , S += A[i];
    for( int i = 1 ; i <= n ; ++ i ) res += A[i] * ( S - A[i] );
    cout << res / 2 << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)

//vector<vector<int>> data(, vector<int>());

int main(){
    int64_t x,y;
    cin >> x >> y;

    int64_t ans=1, n;
    n=x;
    while(1){
        if(2*n <= y){
            ans++;
            n = 2*n;
        }else{
            break;
        }
    }

    cout << ans << endl;

}

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

int main(){
  int i, j;
  string str;
  cin >> str;
  int kami = stoi(str.substr(0, 2));
  int simo = stoi(str.substr(2, 2));
  if(kami > 12 || kami==0){
    if(simo > 12 || simo==0){
      cout << "NA" << endl;
      return 0;
    }
    cout << "YYMM" << endl;
    return 0;
  }
  if(simo > 12 || simo==0){
    if(kami > 12 || kami==0){
      cout << "NY" << endl;
      return 0;
    }
    cout << "MMYY" << endl;
    return 0;
  }
  cout << "AMBIGUOUS" << endl;
  return 0;
}


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

int main()
{
  int t_hp, t_at, a_hp, a_at;
  cin >> t_hp >> t_at >> a_hp >> a_at;
  bool t_turn = true;
  while (t_hp > 0 && a_hp > 0)
  {
    if (t_turn)
    {
      a_hp -= t_at;
    }
    else
    {
      t_hp -= a_at;
    }
    t_turn = !t_turn;
  }
  cout << (a_hp <= 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=605;
bool a[20][N][N];
bool ans[N][N];
int n,D1,D2;
void work(int n,int D,int d){
	if (D%4){
		if (D%2){
			For(i,0,n-1) For(j,0,n-1)
				a[d][i][j]=(i+j+1)&1;
		}
		else{
			For(i,0,n-1) For(j,0,n-1)
				a[d][i][j]=(i+1)&1; 
		}
		return;
	}
	work(n,D/4,d+1);
	For(i,0,n-1) For(j,0,n-1)
		a[d][i][j]=a[d+1][i/2][j/2];
}
int main(){
	scanf("%d%d%d",&n,&D1,&D2);
	work(2*n,D1,0);
	For(i,0,2*n-1) For(j,0,2*n-1)
		ans[i][j]=a[0][i][j];
	work(2*n,D2,0);
	For(i,0,2*n-1) For(j,0,2*n-1)
		ans[i][j]&=a[0][i][j];
	int rest=n*n;
	For(i,0,2*n-1) For(j,0,2*n-1)
		if (rest&&ans[i][j])
			--rest,printf("%d %d\n",i,j);
}

Measured memory_bytes: 5500
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K = LI()

exp = 0
for n in range(1, N + 1):
    # 2を何回かけたらKを超えるか計算する
    tmp = n
    count = 0
    while tmp < K:
        tmp *= 2
        count += 1
    exp += 1/N * (1/2)**count
print(exp)


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

#define ll long long
//~ #define endl '\n'

void solve(){
	int x; cin>>x;
	if(x >= 30){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

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


Measured memory_bytes: 3612
s = input()
k = int(input())

tmp = 1
count = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        count += tmp // 2
        tmp = 1
count += tmp//2

if len(set(s))==1:
    print(len(s)*k//2)
else:
    if s[0] != s[-1]:
        print(count*k)
    else:
        h = 0
        for i in s:
            if i != s[0]:
                break
            else:
                h += 1
        t = 0
        for i in s[::-1]:
            if i != s[-1]:
                break
            else:
                t += 1
        print(count*k-(h//2+t//2-(h+t)//2)*(k-1))

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

int main(){
	int n; cin>>n;
	long long res = 0; 
	map<string,int> mp;
	for(int i = 0; i < n; i++){
		string t;cin>>t;
		sort(t.begin(),t.end());
		mp[t]++;
		res+=mp[t]-1;
	}
	cout<<res;
}		

Measured memory_bytes: 11136
package main

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

func main() {
	n := nextInt()
	m := nextInt()
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = nextInt()
	}
	ys := make([]int, m)
	for i := 0; i < m; i++ {
		ys[i] = nextInt()
	}
	p := int(math.Pow10(9)) + 7

	var X, Y int
	for i, x := range xs {
		X += i*x - (n-(i+1))*x
		X %= p
	}
	for i, y := range ys {
		Y += i*y - (m-(i+1))*y
		Y %= p
	}

	fmt.Println(X % p * Y % p)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

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

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

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

func diff(x, y int) int {
	return abs(-(x) + y)
}

// ---------- Util.


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

const int mxN = 1e5+7;
const int INF = 1e9 + 5;

int main() {
	int n, w;
	cin >> n >> w;
	vector<int> val(n), weight(n);
	
	int sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> weight[i] >> val[i];
		sum += val[i];
	}
	
	vector<int> dp(sum + 1, INF);
	int ans = 0;
	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = sum; j >= val[i]; j--) {
			//cerr << dp[j] << " " << dp[j-val[i]] + weight[i] << "\n";
			dp[j] = min(dp[j], dp[j - val[i]] + weight[i]);
		}
	}
	
	//cerr << sum << "\n";
	
	for(int i = 0; i <= sum; i++) {
		if(dp[i] <= w) {
			ans = max(ans, i);
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2020,MOD=998244353;

template <class T>
inline bool read(T &ret)
{
    char c;
    int sgn;
    if (c = getchar(), c == EOF)
    {
        return 0;
    }
    while (c != '-' && (c < '0' || c > '9'))
    {
        c = getchar();
    }
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0');
    }
    ret *= sgn;
    return 1;
}

template <class T>
inline void write(T x)
{
    if (x > 9)
    {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}

int C[MAXN<<1][MAXN<<1],pw[MAXN<<1],n,k;

inline int add(int x,int y)
{
    return (1LL*x+y)%MOD;
}

inline int mul(int x,int y)
{
    return 1LL*x*y%MOD;
}

inline void init(int n)
{
    C[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        C[i][0]=1,C[i][i]=1;
        for(int j=1;j<i;j++)
            C[i][j]=add(C[i-1][j-1],C[i-1][j]);
    }
    pw[0]=1;
    for(int i=1;i<=n;i++) pw[i]=mul(pw[i-1],2);
}

inline int f(int x,int y,int z)
{
    if(y<0) return 0;
    int ret=0;
    for(int q=0;q<=z&&q<=x;++q)
    {
        if (q+y-1<=z+y-1&&q+y-1>=0)
        {
            ret=add(ret,mul(C[x][q],mul(pw[q],C[z+y-1][q+y-1])));
        }
    }
    return ret;
}

int cnt,ans;

int main()
{
    read(k),read(n);
    init(n+k);
    for(int i=2;i<=2*k;i++)
    {
        cnt=0;
        for (int j=1;j<=k;++j)
        {
            if (1<=i-j&&i-j<=k) ++cnt;
        }
        if(i&1)
            ans=f(cnt/2,k-cnt,n);
        else
        {
            ans=f((cnt-1)/2,k-cnt,n);
            ans=add(ans,f((cnt-1)/2,k-cnt,n-1));
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 62336
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a > b){
		printf("a > b\n");
	}else if(a < b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
}



Measured memory_bytes: 2688
#include<bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.rbegin(), t.rend());
  if(s.compare(t) < 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

static int syokin(int a) {
    if (a == 1)
        return 300000;
    else if (a == 2)
        return 200000;
    else if (a == 3)
        return 100000;
    else
        return 0;
}
int main() {
    int x, y; cin >> x >> y;
    int ans = 0;

    ans += syokin(x);
    ans += syokin(y);

    if (x == 1 && y == 1)
        ans += 400000;
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


main(){
  int n,k;
  string s;
  cin>>n>>k;
  cin>>s;
  vector<int> v;
  v.PB(0);
  int res=0;
  int ii=0;
  while(ii<n){
    int j=ii;
    if(s[ii]=='0') res++;
    while(j<n&&s[ii]==s[j]) j++;
    v.PB(j-ii);
    ii=j;
  }

  if(res<=k){
    cout<<n<<endl;
    return 0;
  }

  FOR(i,1,v.size()){
    v[i]+=v[i-1];
  }

  int ans=0;
  int b=0;
  if(s[0]=='1') b++;
  rep(i,v.size()){
    if(i+k*2>v.size()) continue;
    ans=max(ans,v[i+k*2]-v[i]);
    if(b==1){
      ans=max(ans,v[i+k*2]-v[i]);
      if(i+k*2+1>v.size()) continue;
      ans=max(ans,v[i+k*2+1]-v[i]);
    }
    else{
      if(i+k*2-1<0) continue;
      ans=max(ans,v[i+k*2-1]-v[i]);
    }
    b=(b==1?0:1);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1528
(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defparameter lst (mapcar #'parse-integer (split " " (read-line))))

(format t "~A" (lcm (car lst) (cadr lst)))

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  cout << 24 + 24 - in() << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int):
    def _convert(cur):
        ret = [''] * N
        for i, pos in enumerate(cur):
            c = chr(ord('a') + i)
            for p in pos:
                ret[p] = c
        ret = ''.join(ret)
        return ret
    def rec(idx, cur):
        if idx == N:
            ret = _convert(cur)
            return [ret]
        ret = []
        for c in cur:
            c.append(idx)
            tmp = rec(idx + 1, cur)
            ret += tmp
            c.pop()
        cur.append([idx])
        ret += rec(idx + 1, cur)
        cur.pop()

        return ret
    ret = rec(0, [])
    for r in ret:
        print(r)
    #print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13196
#include <stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  double x;
  char u[3];
  int i;
  double sum = 0;
  for(i=0; i<N; i++){
    scanf("%lf %s",&x,u);
    if(u[0]=='J')
      sum+=x;
    else if(u[0]=='B')
      sum+=x*380000.0;
  }
  printf("%f\n",sum);
  
  return 0;
}

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

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  for (int y = 0; y < H; y++) {
    string S;
    cin >> S;
    cout << S << "\n";
    cout << S << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxx = 107;
const int Inf = 1 << 30;
int n, T;
int c[maxx], t[maxx];

int main() {
	scanf("%d %d", &n, &T);
	int ans = Inf;
	for(int i = 1; i <= n; i++) scanf("%d %d", &c[i], &t[i]);
	for(int i = 1; i <= n; i++) {
		if(t[i] <= T) {
			ans = min(c[i], ans);
		}
	}
	if(ans == Inf) puts("TLE");
	else printf("%d\n", ans);
}

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

class Program
{
	public static void Main(String[] args)
	{
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x => x).ToArray();
		Console.WriteLine((input[0] * input[1]) / 2);
	}
}



Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef struct _data {
	int x;
	int y;
} data;

int  main()
{
	int K;
	cin >> K;
	string s;
	cin >> s;
	if(s.size() <= K)
	{
		cout << s << endl; return 0;
	}
	else
	{
		cout << s.substr(0, K) << "...";
	}
	return (0);
}


Measured memory_bytes: 3604
import java.util.*;

public class Main {
    public static void main(String args[]) {
       //値の取得
       Scanner sc = new Scanner(System.in);
       int time[] = new int[5]; //料理提供にかかる時間を料理ごとに格納する配列
       for (int i = 0; i < 5; ++i){
           time[i] = sc.nextInt();
       }

       int order[] = new int[5]; //注文する順番に格納する配列
      
       //注文した料理をorderに格納し、時刻を10の倍数に修正した後、次の料理を注文
       for (int i = 0; i < 5; ++i){
           if(time[i] % 10 == 0) {
               order[i] = (time[i] / 10) * 10;
           } else {
               order[i] = (time[i] / 10) * 10 + 10;
           }
       }
       
       int max = 0; //次に料理を注文できる時間(order)と料理提供時間(time)の差の最大値
       int total = 0;   //総時間
       for(int i = 0; i < 5; ++i) {
           if(Math.abs(order[i] - time[i]) > max) {
               max = Math.abs(order[i] - time[i]);  //差を絶対値で求める
           }
           
           total += order[i];    //料理提供にかかった時間を総時間に加算
       }
       
       //出力
       System.out.println(total - max);
       
    }
}

Measured memory_bytes: 35668
from collections import Counter


def get_color(rating):
    for i, (l_l, l_u) in enumerate(zip(limits, limits[1:])):
        if l_l <= rating < l_u:
            return i
    else:
        return SUPER_CODER


limits = [1, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200]
SUPER_CODER = len(limits) - 1

input()
a = Counter(map(lambda x: get_color(int(x)), input().split()))
min_color_cnt = len([i for i in a if i < SUPER_CODER])
print(max(1, min_color_cnt), min_color_cnt + a[SUPER_CODER])


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

int main(){
    int n,k,a;
    cin >> n >> k;
    map<int,int> ball,num;

    for(int i=0; i<n; i++){
        cin >> a;
        if(ball.count(a) == 0){
            ball[a] = 1;
        }else{
            ball[a]++;
        }
    }
    int kind = ball.size() - k;
    if(kind <= 0){
        cout << 0 << endl;
        return 0;
    }
    for(auto value:ball){
        if(num.count(value.second) == 0){
            num[value.second] = 1;
        }else{
            num[value.second]++;
        }
    }
    int sum = 0;
    for(auto value:num){
        if(kind >= value.second){
            sum += value.first*value.second;
            kind -= value.second;
        }else{
            sum += value.first*kind;
            kind = 0;
        }
        if(kind == 0){
            break;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 9600
s = str(input())

n = len(s)

INF = 10**18
dp =[[-INF]*3 for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(3):
        if dp[i][j] == -INF:
            continue
        for k in range(1, 3):
            if j == k:
                if k == 1:
                    if s[i-1] == s[i]:
                        continue
                else:
                    if s[i-2] == s[i] and s[i-1] == s[i]:
                        continue
            if i+k <= n:
                dp[i+k][k] = max(dp[i+k][k], dp[i][j]+1)
print(max(dp[n]))


Measured memory_bytes: 101348