akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> dp(h, vector<int>(w, INF));

  auto ok = [&](int i, int j) { return (0 <= i && i < h && 0 <= j && j < w); };

  dp[0][0] = (int)(s[0][0] == '#') + (int)(s[h - 1][w - 1] == '#');
  rep(i, h) rep(j, w) {
    if (ok(i, j - 1)) {
      dp[i][j] = min(dp[i][j], dp[i][j - 1] + (int)(s[i][j] != s[i][j - 1]));
    }
    if (ok(i - 1, j)) {
      dp[i][j] = min(dp[i][j], dp[i - 1][j] + (int)(s[i][j] != s[i - 1][j]));
    }
  }
  cout << dp[h - 1][w - 1] / 2 << endl;
  return 0;
}


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

using namespace std;

string s;

int solve() {
    if(s.size() == 1) return stoi(s);
    int ans = 0;
    for(int i = 1; i < s.size(); i++) {
        if(s[i] != '9') {
            ans = (s.size()-1) * 9 + (s[0] - '0') - 1;
            return ans;
        }
    }
    for(int i = 0; i < s.size(); i++){
        ans += s[i] - '0';
    }
    return ans;
}

int main() {
    cin >> s;
    int ans = solve();
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
 
int main(){
	int n;
	cin >> n;
	ll a[n], b[n];
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) cin >> b[i];

	ll ca=0, cb=0;
	for(int i=0; i<n; i++){
		if(a[i]>b[i]) cb+=a[i]-b[i];
		else ca+=(b[i]-a[i])/2;
	}
	if(ca>=cb) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
  int H,i,A[MAX+1];
  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
return 0;
}



Measured memory_bytes: 2100
while True:
    a=int(input())
    x=[]
    if a==0:
        break
    else:
        for i in range(a):
            y=int(input())
            x.append(y)
        b=min(x)
        c=max(x)
        ave=(sum(x)-b-c)/(a-2)
        print(int(ave))


Measured memory_bytes: 5600
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<int> > v(h, vector<int>(w));
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            cin >> v[y][x];
        }
    }

    vector<tuple<int, int, int, int> > ans;
    for(int y=0; y<h; ++y){
        for(int x=0; x<w-1; ++x){
            if(v[y][x] % 2 != 0){
                -- v[y][x];
                ++ v[y][x+1];
                ans.push_back(make_tuple(y, x, y, x+1));
            }
        }
        if(y < h - 1 && v[y][w-1] % 2 != 0){
            -- v[y][w-1];
            ++ v[y+1][w-1];
            ans.push_back(make_tuple(y, w-1, y+1, w-1));
        }
    }

    cout << ans.size() << endl;
    for(const auto& t : ans){
        int a, b, c, d;
        tie(a, b, c, d) = t;
        ++ a;
        ++ b;
        ++ c;
        ++ d;
        cout << a << ' ' << b << ' ' << c << ' ' << d << endl;
    }

    return 0;
}


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


long long N, M;
long long S[10];
char C[10];

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

	for(long long i = 0; i < M; i++) {
		cin >> S[i] >> C[i];
		S[i]--;
	}

	for(int i = 0; i < pow(10, N); i++) {
		string s = to_string(i);
		//cout << s << endl;
		if(s.size() != N) 
			continue;

		bool ok= true;
		for(long long j = 0; j < M; j++) {
			if(s[S[j]] != C[j]) {
				ok = false;
			}
		}
		if(ok) {
			cout << s << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 4080
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Map<String, Integer> map = new HashMap<String, Integer>() {{
            put("SUN", 7);
            put("MON", 6);
            put("TUE", 5);
            put("WED", 4);
            put("THU", 3);
            put("FRI", 2);
            put("SAT", 1);
        }};
        String s = in.next();
        System.out.println(map.get(s));
    }
}


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

int main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i] -= i;
	}
	sort(A.begin(), A.end());
	vector<ll> sum(N + 1);
	for (int i = 0; i < N; i++) {
		sum[i + 1] = sum[i] + A[i];
	}
	ll res = LLONG_MAX;
	for (int i = 0; i < N; i++) {
		res = min(res, A[i] * i - sum[i] + sum[N] - sum[i] - (N - i) * A[i]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <sstream>
using namespace std;
typedef complex<double> P;

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

P project(P s1, P s2, P p) {
  P base = s2 - s1;
  double t = dot(p - s1, base)/norm(base);
  return s1 + base*t;
}

P reflect(P s1, P s2, P p) { return p + (project(s1, s2, p) - p)*2.0; }

int main() {
  P s1, s2, p;
  string line;
  while(getline(cin, line)) {
    replace(line.begin(), line.end(), ',', ' ');
    stringstream ss(line);
    ss >> s1.real() >> s1.imag()
       >> s2.real() >> s2.imag() >> p.real() >> p.imag();
    P q = reflect(s1, s2, p);
    printf("%.8f %.8f\n", q.real(), q.imag());
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll MAX = 600000;
ll MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll COM2(ll N, ll R, ll B) {
   ll ans = 1;
   ll tmp1 = COM(N, R) % MOD;
   ll tmp2 = COM(N, B) % MOD;
   ans *= tmp1;
   ans %= MOD;
   ans *= tmp2;
   ans %= MOD;
   return ans;
}

int main() {
   ll A, B, K, N;

   cin >> N >> A >> B >> K;
   
   COMinit();
   ll ans = 0;
   for (ll a = 0; a <= N; a++) {
      if ((K - A * a) % B == 0 && (K - A * a) / B >= 0 && (K - A * a) / B <= N) {
         ll b = (K - A * a) / B;
         // cout << A << "*" << a << "+" << B << "*" << b << "=" << K << endl;
         // cout << COM(N, a) << endl;
         // cout << COM(N, b) << endl;
         // cout << COM2(N, a, b) << endl;
         ans += COM2(N, a, b);
         ans %= MOD;
      }
   }

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


Measured memory_bytes: 14336
#include <iostream>
#include <bits/stdc++.h>
#define mod 1000000007
#define point complex<double>

typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
double pi=acos(-1);

double adotb(point a, point b){
    return (conj(a)*b).real();
}

double acrossb(point a, point b){
    return (conj(a)*b).imag();
}

double sinseta(point a, point b){
    double res=asin(abs(acrossb(a,b)/(abs(a)*abs(b))))*180.0/pi;
    if(res>180.0)res-=180.0;
    return res;
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    if (exp == 1)
        return base;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    if(n<r)return 0;
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int main()
{
    Fastio();
    calcFacAndInv(1e5);
    ll n,k; cin>>n>>k;
    for(int i=1; i<=k; i++){
        ll ans=ncr(n-k+1,i)* ncr(k-1,i-1);
        cout<<ans%mod<<'\n';
    }

    return 0;
}


Measured memory_bytes: 5120
s=input()
l=input()
len_s=len(s)
len_l=len(l)
a=len_s-len_l
ans=1001
for i in range(len_s-len_l+1):
    cnt=0
    for j in range(len_l):
        if l[j]!=s[i+j]:
            cnt+=1
    ans=min(ans,cnt)

print(ans)



Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n+2);
    vector<int> order(n+2);
    FOR(i,1,n) {
        cin>>a[i];
        order[a[i]]=i;
    }
    
    
    set<int> st;
    st.insert(0);
    st.insert(n+1);
    
    ll ans=0;
    FOR(i,1,n){
        auto itr=st.lower_bound(order[i]);
        int right=*itr;
        itr--;
        int left=*itr;
        ans+=(ll)(right-order[i])*(order[i]-left)*i;
        st.insert(order[i]);
    }
    
    cout<<ans<<endl;
    
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define mp make_pair
typedef long long ll;
multiset<ll> pos,neg;
int timer;
ll len[100011];
ll shiftpos,shiftneg;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	ll m=0; ll c=0;
	for(int i=0;i<n;i++)
	{
		ll l,r; cin>>l>>r;
		len[i]=r-l;
		if(i>0){shiftpos+=len[i-1]; c-=len[i-1]*m;}
		shiftneg-=len[i];
		pos.insert(l-shiftpos); pos.insert(l-shiftpos);
		auto it=pos.begin(); ll res=(*it)+shiftpos;
		pos.erase(pos.begin()); neg.insert(res-shiftneg);
		ll neglas=(*prev(neg.end()))+shiftneg;
		ll posles=(*pos.begin())+shiftpos;
		if(!neg.empty()&&neglas>posles)
		{
			neg.erase(prev(neg.end())); pos.erase(pos.begin());
			pos.insert(neglas-shiftpos); neg.insert(posles-shiftneg);
		}
		m++; c-=l;
	}
	while(m>0)
	{
		c+=(*prev(pos.end()))+shiftpos;
		m--;
		pos.erase(prev(pos.end()));
	}
	cout<<c<<'\n';
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,h[100005],dp[100005];
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>h[i];
  }
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for(int i=2; i<n; i++){
    dp[i]=min(abs(h[i-1]-h[i])+dp[i-1],abs(h[i-2]-h[i])+dp[i-2]);
  }

  cout<<dp[n-1]<<'\n';
  return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E solver = new E();
        solver.solve(1, in, out);
        out.close();
    }

    static class E {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
                b[i] = Integer.parseInt(in.next());
            }
            int ans = 0;
            Arrays.sort(a);
            Arrays.sort(b);

            if (n % 2 == 0) {
                ans = (b[(n / 2) - 1] + b[n / 2]) - (a[(n / 2) - 1] + a[n / 2]) + 1;
            } else {
                ans = b[n / 2] - a[n / 2] + 1;
            }
            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 61212
#include <iostream>
#include <cmath>
// #include <string>
// #include <vector>
// #include <algorithm> // to use min_element

using namespace std;


int main(){
	int a,b, c, x;
	cin >>a;
	cin >>b;
	cin >>c;
	cin >>x;

	if (x > 500*a+100*b+50*c){
		cout<<"0";
	}else{
	int i=0, j=0, k=0, count=0;	
	while (i<=a ){
	j=0;
		while (j<=b ){
			k=0;
			while (k<=c ){
			if (x == 500*i+100*j+50*k) count++;
			k++;
			}
		j++;
		}
		i++;
	}
	cout << count;
	}
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn = 10005;
const double pi = 3.141592653589;
int main(void) {
    double radius;
    cin >> radius;
    printf("%.6f %.6f",radius * radius * pi,radius * 2 * pi);


    return 0;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll x; cin>>x;
	ll best=0;
	for(ll i = 1; i*i<=x; i++)
	{
		if(x%i==0)
		{
			best=x/i;
		}
	}
	int cnt=0;
	while(best)
	{
		best/=10;cnt++;
	}
	cout<<cnt<<'\n';
}


Measured memory_bytes: 256
(defun split-with (string &key (delimiterp #'(lambda (c) (char= c #\Space))))
  (loop :for beg = (position-if-not delimiterp string)
        :then (position-if-not delimiterp string :start (1+ end))
        :for end = (and beg (position-if delimiterp string :start beg))
        :when beg :collect (subseq string beg end)
        :while end))

(defun count-series (lst)
  (max (loop :for pn = (car lst) :then n
             :for n in lst
             :while (<= pn n)
             :counting t)
       (loop :for pn = (car lst) :then n
             :for n in lst
             :while (>= pn n)
             :counting t)))

(let* ((n (parse-integer (read-line)))
       (as (mapcar #'parse-integer (split-with (read-line))))
       (pa (car as))
       (c 0))
  (format t "~a~%"
          (loop :until (null as)
                :for count = (count-series as)
                :do (progn
                      (setf as (nthcdr count as)))
                :counting t)))


Measured memory_bytes: 26980
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 100000;
ll mod = INF;

ll fac[maxn+1];
ll rfac[maxn+1];

//最小二乗法
ll pow(ll x,ll y){
    if(y==0){
        return 1;
    }else if(y==1){
        return x;
    }else if(y%2==0){
        ll a=pow(x,y/2);
        return (a*a)%mod;
    }else{
        ll a=pow(x,(y-1)/2);
        return a*a%mod*x%mod;
    }
}


int main(){
    ll ans=0;
    ll n;
    ll k;
    ll a[maxn+1];
    ll sum[maxn+1]={0};

    cin >> n>>k;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }

    sort(a+1,a+n+1);
    sum[1]=a[1];
    for(int i=2;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
    }

    fac[0]=fac[1]=rfac[0]=rfac[1]=1;

    for(ll i=1;i<=maxn;i++){
        fac[i]=fac[i-1]*i%mod;
    }

    //逆元を求める
    rfac[maxn]=pow(fac[maxn],mod-2);
    
    for(ll i=maxn;i>=1;i--){
        rfac[i-1]=rfac[i]*i%mod;
    }
    
    if(k==1){
        ans=0;
    }else{
        for(ll K=k;K<=n;K++){
            ll S=sum[n]-sum[K-1]-sum[n-K+1];
            while(S<0)S+=mod;
            S=S%mod;
            ll p=fac[K-2]*rfac[k-2]%mod*rfac[K-k]%mod;
            ans=(ans+S*p%mod)%mod;
        }
    }

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

Measured memory_bytes: 6712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  string S;
  cin >> N >> S;
  char last = '0';
  int ans = 0;
  rep(i,N){
    if(S[i] != last){
      ans++;
      last = S[i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

const int INF = 1 << 30;

int L[10];

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) cin >> L[i];
    int ans = INF;
    int max_mask = 1;
    for (int i = 0; i < N; i++) max_mask *= 3;
    for (int mask = 0; mask <= max_mask; mask++) {
        vector<int> now_role;
        int now = mask;
        for (int i = 0; i < N; i++) {
            now_role.push_back(now % 3);
            now /= 3;
        }
        int a_cost = INF, b_cost = INF, c_cost = INF;
        vector<int> a, b, c;
        for (int i = 0; i < now_role.size(); i++) {
            if (now_role[i] == 0) a.push_back(L[i]);
            else if (now_role[i] == 1) b.push_back(L[i]);
            else c.push_back(L[i]);
        }
        if (a.size() == 0 || b.size() == 0 || c.size() == 0) continue;
        // Aのコスト計算
        for (int a_mask = 0; a_mask < (1 << a.size()); a_mask++) {
            int concat_a = 0;
            for (int i = 0; i < a.size(); i++) {
                if ((a_mask >> i) & 1) concat_a += a[i];
            }
            if (__builtin_popcount(a_mask) == 0) continue;
            a_cost = min(a_cost, (__builtin_popcount(a_mask) - 1) * 10 + abs(A - concat_a));
        }
        // Bのコスト計算
        for (int b_mask = 0; b_mask < (1 << b.size()); b_mask++) {
            int concat_b = 0;
            for (int i = 0; i < b.size(); i++) {
                if ((b_mask >> i) & 1) concat_b += b[i];
            }
            if (__builtin_popcount(b_mask) == 0) continue;
            b_cost = min(b_cost, (__builtin_popcount(b_mask) - 1) * 10 + abs(B - concat_b));
        }
        // Cのコスト計算
        for (int c_mask = 0; c_mask < (1 << c.size()); c_mask++) {
            int concat_c = 0;
            for (int i = 0; i < c.size(); i++) {
                if ((c_mask >> i) & 1) concat_c += c[i];
            }
            if (__builtin_popcount(c_mask) == 0) continue;
            c_cost = min(c_cost, (__builtin_popcount(c_mask) - 1) * 10 + abs(C - concat_c));
        }
        ans = min(ans, a_cost + b_cost + c_cost);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
long long int a,b,i,x,y,t;

while(scanf("%lld%lld",&a,&b)==2){
x=a;y=b;
while(b){
t=a%b;
a=b;
b=t;
}

printf("%lld %lld\n",a,(x*y)/a);
}
return 0;
}

Measured memory_bytes: 596
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e6)+10;
vii adj(N);
int a[N],b[N];

void  solve(){

}
int32_t main()
{
    FIO
    int n,m,k; cin>>n>>m>>k;
    fi(i,n) {
        cin>>a[i];
        if(i) a[i]+=a[i-1];
    }
    fi(i,m) {
        cin>>b[i];
        if(i) b[i]+=b[i-1];
    }
    int ans=0;
    fi(i,n){
        int c=k-a[i];
        if(c<0) break;
       int p=upper_bound(b,b+m,c)-b;
        ans=max(ans,p+i+1);
    }
    fi(i,m){
        int c=k-b[i];
        if(c<0) break;
        int p=upper_bound(a,a+n,c)-a;
        ans=max(ans,p+i+1);
    }
    cout<<ans<<"\n";
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].pb(v);
    adj[v].pb(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}


Measured memory_bytes: 123576
import java.util.*;

public class Main {
    private static final String ex = "575";

    public static void main(String[] args) {
        System.out.println(solve(new Scanner(System.in)));
//        System.out.println(solve(new Scanner(ex)));
    }

    private static String solve(Scanner scanner) {
        String s = scanner.nextLine();
        return s.charAt(0) == s.charAt(2) ? "Yes" : "No";
    }
}


Measured memory_bytes: 23636
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(long long N, vector<string> S, vector<long long> P){
  vector<pair<string, pair<long long, long long>>> li(N);
  for (int i = 0; i < N; i++) {
    li[i] = make_pair(S[i], make_pair(-P[i], i+1));
  }
  sort(li.begin(), li.end());

  for (int i = 0; i < N; i++) {
    std::cout << li[i].second.second << std::endl;
  }

}

int main(){
  long long N;
  scanf("%lld",&N);
  vector<long long> P(N);
  vector<string> S(N);
  for(int i = 0 ; i < N ; i++){
    cin >> S[i];
    scanf("%lld",&P[i]);
  }
  solve(N, S, P);
  return 0;
}


Measured memory_bytes: 256
# AtCoder Beginner Contest 166
# 
# https://atcoder.jp/contests/abc166/tasks/abc166_c

(N, M) = gets.chomp.split.map(&:to_i)
H = gets.chomp.split.map(&:to_i)
AB = readlines.map{ |l| l.chomp.split.map(&:to_i) }

routes = Hash.new{|h,k| h[k] = []}
AB.each do |a|
  routes[a[0]] << a[1]
  routes[a[1]] << a[0]
end

routes.each_key {|k| routes[k] = routes[k].uniq}

cnt = 0
(1..N).each do |i|
  r = routes[i]
  if r.empty?
    cnt += 1
    next
  end

  ah = H[i-1]
  bh = routes[i].map{|j| H[j-1]}.max
  if ah > bh
    cnt += 1
  end
end

puts cnt


Measured memory_bytes: 44444
import itertools

def main():
    h,w,k=map(int,input().split())
    c = [input() for _ in range(h)]
    ans = 0
    for y in itertools.product([0,1], repeat=h):
        t1 = c[:]
        for i,v in list(enumerate(y))[::-1]:
            if v == 0:
                del t1[i]
        for x in itertools.product([0,1], repeat=w):            
            if count(t1, x, k) == k:
                ans += 1
    print(ans)

def count(t1, x, k):
    cnt = 0
    for t in t1:
        for i,v in enumerate(x):
            if v == 1 and t[i] == "#":
                cnt += 1
                if cnt > k:
                    return cnt
    return cnt

if __name__ == '__main__':
    main()

Measured memory_bytes: 68184
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var s = o.a();
  var a = {};
  a[s] = 1;
  for(var i = 2;; i++){
    if(s & 1){
      s = s * 3 + 1;
    }else{
      s /= 2;
    }
    if(a[s])break;
    a[s] = 1;
  }
  return i;
}

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

using namespace std;
typedef long long ll;

#define N 305

vector <int> v[N];
int n;

void remover (vector <int> &v, int a){
    for (int i = 0; i < v.size(); i++){
        if (a == v[i]){
            v.erase(v.begin() + i);
            return;
        }
    }
}

pair<int,int> getmost (){
    map <int, int> qtd;
    int ans = 0, value;
    for (int i = 0; i < n; i++){
        qtd[v[i][0]]++;
        ans = max (ans, qtd[v[i][0]]);
        if (ans == qtd[v[i][0]]) value = v[i][0];
    }
    return {ans, value};
}

int main(){

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

    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            int a;
            scanf ("%d", &a);
            v[i].push_back (a);
        }
    }
    int menor = n;
    for (int i = 0; i < m; i++){
        auto p = getmost();
        int value = p.second;
        int q = p.first;
        menor = min (q, menor);
        for (int i = 0; i < n; i++){
            remover(v[i], value);
            if (v[i].size() == 0){
                printf ("%d\n", menor);
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s[100];
int main(){
	int n,l;
	cin>>n>>l;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	for(int i=0;i<n;i++){
		for(int j=1;j<n;j++){
			bool big=false;
			for(int k=0;k<l;k++){
				if(s[j-1][l-1-k]>s[j][l-1-k])big=true;
				if(s[j-1][l-1-k]<s[j][l-1-k])big=false;
			}
			if(big){
				string tmp=s[j];
				s[j]=s[j-1];
				s[j-1]=tmp;
			}
		}
	}
	for(int i=0;i<n;i++)cout<<s[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x = ii()

for a in range(-200,200,1):
    for b in range(-200,200,1):
        if a**5 - b**5 == x:
            print(a,b)
            exit()


Measured memory_bytes: 9388
# 累積和の中で %M が同じものが、差分が M の倍数になるもの

N,M=map(int,input().split())
A=list(map(int,input().split()))

C = [ 0 for _ in range(N) ]
C[0] = A[0] % M
d = { 0:1 }
if C[0] in d:
  d[C[0]] += 1
else:
  d[C[0]] = 1

ans = 0
for i in range(1,N):
  C[i] = (C[i-1] + A[i]) % M
  if C[i] in d:
    d[C[i]] += 1
  else:
    d[C[i]] = 1

for dv in d.values():
  if dv > 1:
    ans += dv * (dv-1) // 2
print(ans)


Measured memory_bytes: 14756
T = sorted([int(input()) for _ in range(5)])

T_sub = []
cnt = 0
for i in range(10, 131, 10):
    while T[cnt] <= i:
        T_sub.append(i - T[cnt])
        cnt += 1
        if cnt == 5:
            break
    if cnt == 5:
        break

max_index = T_sub.index(max(T_sub))

new_T = []
for i in range(5):
    if i == max_index:
        pass
    else:
        new_T.append(T[i])
new_T.append(T[max_index])

time = 0
for i in range(5):
    time += new_T[i]
    if i == 4:
        print(time)
        exit()
    else:
        while time % 10 != 0:
            time += 1






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

using namespace std;

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

    int n;
    cin >> n;

    vector<int> leafs(n + 2);
    for (int i = 0 ;i <= n ;i++)
        cin >> leafs[i];

    vector<long long> mn(n + 2) , mx(n + 2) , up_mx(n + 2);
    for (int i = n ;i >= 0 ;i--) {
        mn[i] = (mn[i + 1] + 1) / 2 + leafs[i];
        mx[i] = mx[i + 1] + leafs[i];
    }

    mx[0] = min(mx[0] , 1ll);
    for (int i = 1 ;i <= n ;i++) {
        long long v = (mx[i - 1] - leafs[i - 1]) * 2;
        mx[i] = min(mx[i] , v);
    }

    if (mn[0] != 1) {
        cout << -1;
        return 0;
    }

    long long sum = 0;
    for (int i = 0 ;i <= n ;i++) {
        if (mn[i] <= mx[i])
            sum += mx[i];
        else {
            cout << -1;
            return 0;
        }
    }

    cout << sum;
}


Measured memory_bytes: 6100
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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 print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    int K;
    cin >> N >> K;
    long double ans = 0;
    REP(i, N) {
        long double prob = (long double)1 / (long double)N;
        for(int j = i + 1; j < K; j = j * 2) {
            prob = prob / (long double)2;
        }
        ans += prob;
    }
    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a, b, c, d, e, k;

int main(){
    INIT;
    cin >> a >> b >> c >> d >> e >> k;
    cout << (e - a > k ? ":(" : "Yay!") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

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

	ll n, w, m, k, ans = 0;
	cin >> n >> w;
	vll W(n), V(n);
	rep(i, n) cin >> W[i] >> V[i];
	vvll dp(n+1, vll(100010, M));
	dp[0][0] = 0;
	rep(i, n) {
		rep(j, 100010) {
			if (j - V[i] >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - V[i]] + W[i]);

			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		}
	}
	/*rep(i, n + 1) {
		rep(j, w + 1) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	rep(i, 100010) if (dp[n][i] <= w) ans = i;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 80256
[K, N] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

t = K - A[N-1] + A[0]
for i in range(N-1):
    if t < A[i+1] - A[i]:
        t = A[i+1] - A[i]

print(K-t)

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int minimum = max({A, B, C}) - min({A, B, C}), middle = max({A, B, C}) * 2 - (A + B + C - min({A, B, C}));
    if((minimum + middle) % 2){
        cout << (minimum + middle) / 2 + 2 << endl;
    }else{
        cout << (minimum + middle) / 2 << endl;
    }
}



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

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N]; // 距離で訪問状態 (color) を管理する

void bfs(int s) {
	queue<int> q; // 標準ライブラリの queue を使用
	q.push(s);
	for ( int i = 0; i < n; i++ ) d[i] = INFTY;
	d[s] = 0;
	int u;
	while ( !q.empty() ) {
		u = q.front(); q.pop();
		for ( int v = 0; v < n; v++ ) {
			if ( M[u][v] == 0 ) continue;
			if ( d[v] != INFTY ) continue;
			d [v] = d[u] + 1;
			q.push(v);
		}
	}
	for ( int i = 0; i < n; i++ ) {
		cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
	}
}

int main() {
	int u, k, v;
	
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		for ( int j = 0; j < n; j++ ) M[i][j] = 0;
	}
	
	for ( int i = 0; i < n; i++ ) {
		cin >> u >> k;
		u--;
		for ( int j = 0; j < k; j++ ) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	
	bfs(0);
	
	return 0;
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    vector<vector<int>> g(n);
    rep(n,i)
    {
        cin >> h[i];
    }

    rep(m,i)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ct = 0;
    for (int v = 0; v < n; v++)
    {
        bool ok = true;
        for (auto &&nv : g[v])
        {
            if (h[nv] >= h[v]) ok = false;
        }
        if (ok) ct++;
    }
    

    cout << ct << endl;

    return 0;
}

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

int main()
{
    int m1,d1,m2,d2;

    cin>>m1>>d1>>m2>>d2;
    if(m1!=m2)
    {
        cout<<1;
    }
    else
    {
        cout<<0;
    }
    
    return 0;
}

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

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


int main(){
    ll A=0, B=0, C=0, n, as, bs, cs; cin>> n;
    ll a, b, c;
    for(ll i=0; i<n; i++){
        cin>> a>> b>> c;
        as=maxi(a+B, a+C);
        bs=maxi(b+A, b+C);
        cs=maxi(c+A, c+B);
        A=as; B=bs; C=cs;
    }
    cout<< maxi(A, maxi(B,C))<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int e, f;
  e = a+b;
  f = c+d;
  if (e > f) {
    cout << "Left" << endl;
  }
    else if (e == f) {
      cout << "Balanced" << endl;
    }
      else cout << "Right" << endl;
}

Measured memory_bytes: 256
import sys
N,T=map(int,input().split())
x=[]
h=[]
for i in range (N):
    c,t =map(int,input().split())
    m=tuple([int(c), int(t)])
    x.append(m)
for i in range (N):
          if x[i][1]<=T:
                h.append(x[i][0])

if len(h)>0:
   print(min(h))
else:
    print('TLE')

Measured memory_bytes: 3064
public class Main {

	//自分が書いたコード
	public static void main(String[] a) {
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 10; j++) {
				System.out.println(i+"x"+j+"="+(i*j));
			}
		}
	}

}


Measured memory_bytes: 24144
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

template<class T> T umax(T a,T b) {return (a>b?a:b);}
template<class T> T umin(T a,T b) {return (a<b?a:b);}
template<class T,class P> T umax(T a,P b) {return (a>b?a:b);}
template<class T,class P> T umin(T a,P b) {return (a<b?a:b);}

typedef long long int ll;
const int maxn = 1e5+7;
const ll mod = 1e9+7;

bool compare(const pair<ll,ll>& x, const pair<ll,ll>& y) {
    if(x.second == y.second) return x.first < y.first;
    return x.second < y.second;
}

ll power(ll a,ll b) {
    ll res = 1;
    while(b) {
        if(b&1) {
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

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

int main() {
    string s;
    cin >> s;
    bool ans = false;
    for(int i=0;i<s.length();i++) {
        for(int j=i+1;j<s.length();j++) {
            if(s[i] != s[j]) {
                ans = true;
            }
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
 
int a(int N){
	int cnt =N;
	if(cnt==1){
		int k;
		cin>>k;
		int k_cnt=0;
		while(k%2==0){
			k_cnt++;
			k/=2;
		}
		return k_cnt;
	}
	int num,num_cnt;
	cin>>num;
	num_cnt=0;
	while(num%2==0){
		num_cnt++;
		num/=2;
	}
	int d=a(N-1);
	return min(d,num_cnt);
}
 
 
 
signed main() {
	int N; cin>>N;
	int ans= a(N);
	cout<<ans<<endl;
 
}

Measured memory_bytes: 256
#!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input

def solve(s,t):
	if s==t:
		return 'IDENTICAL'
	s=s.split('"')
	t=t.split('"')
	if len(s)==len(t):
		k0=sum(s[i]!=t[i] for i in range(0,len(s),2))
		k1=sum(s[i]!=t[i] for i in range(1,len(s),2))
		if k0==0 and k1==1:
			return 'CLOSE'
	return 'DIFFERENT'

try:
	while True:
		s=raw_input().strip()
		if s=='.': break
		t=raw_input().strip()
		print(solve(s,t))
except EOFError:
	pass

Measured memory_bytes: 7544
#include <iostream>
#include <string.h>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main(){
	int n, d;
	cin >> n >> d;
	int ans = 0;
	vector< vector<int>> a(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			int h;
			cin >> h;
			a.at(i).push_back(h);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			long double i_ = 0;
			for (int o = 0; o < d; o++) {
				i_ += pow((a.at(i).at(o) - a.at(j).at(o)), 2.0);
			}
			if (sqrt(i_) == int(sqrt(i_))) {
				ans++;
			}
		}
	}
	cout << ans;

};


Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  string S;
  cin >> S;
  int N = S.size();
  rep(i, N - 1) {
    if (S[i] == S[i + 1]) {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    } else if (i < (N - 2) && (S[i] == S[i + 2])) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n) - 1;i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) ((v).begin(), (v).end())
#define F first
#define S second

int w[300000];
int e[300000];

int main() {
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	
	int n; string s;
	cin >> n; cin >> s;
	
	forn(i,n) w[i] = e[i] = 0;
	
	forn(i,n) w[i + 1] = w[i] + (s[i] == 'W');
	dforn(i,n) e[i - 1] = e[i] + (s[i] == 'E');
	
	int res = 1e9;
	forn(i,n) {
		res = min(res, w[i] + e[i]);
	}
	
	cout << res << endl;
	
}


Measured memory_bytes: 2964
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;
int w[10] = { 0,2,5,5,4,5,6,3,7,6 };

int main() {
	int n, m;
	cin >> n >> m;
	vector<string>p(n+20, "-");
	p[0] = "";
	vector<int>r(m);
	for (int i = 0; i < m; i++)cin >> r[i];
	for (int i = 0; i < n; i++) {
		if (p[i] == "-")continue;
		for (int j = 0; j < m; j++) {
			string a = p[i]+char(r[j]+'0');
			if (a.size() > p[i + w[r[j]]].size())p[i + w[r[j]]] = a;
			else if(a.size()== p[i + w[r[j]]].size()){
				if (a > p[i + w[r[j]]])p[i + w[r[j]]] = a;
			}
		}
	}
	cout << p[n] << endl;

	return 0;


}

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

int const N = 400, md = 998244353;
int n, x[N + 1], ch[N + 1][N + 1], p2[N + 1];

struct P{
	int x[2];
	P() { x[0] = x[1] = 0; }
	int& operator [](int i) { return x[i]; }
	void cl() { x[0] = x[1] = 0; }
};

map<pair<int, int>, vector<P> > mp;

void ad(int &x, int y) { if ((x += y) >= md)x -= md; }

int go(int i = 1, int l = 1, int r = n, int p = 0, bool q = false){
	auto it = mp.find(make_pair(i, l));
	if (it != mp.end())return it->second[p][q];
	vector<P> &v = mp[make_pair(i, l)];
	int ln = r - l + 1;
	v.resize(ln + 1);
	
	vector<vector<P> > dp;
	vector<int> in;
	int j = l;
	bool fe = x[l] == i;
	while (j <= r){
		in.push_back(j);
		int k = j;
		while (k + 1 <= r && x[k + 1] > i == x[k] > i)++k;
		j = k + 1;
	}
	in.push_back(r + 1);
	
	dp.resize(in.size(), vector<P>(ln + 1));
	f(j, 0, ln + 1)dp[0][j].cl();
	dp[0][0][1] = 1;
	f(j, 1, in.size()){
		int cln = in[j] - in[j - 1];
		f(k, 0, ln + 1)dp[j][k].cl();
		if (j & 1 ^ fe)f(k, 0, ln + 1)f(w, max(0, k - cln), k + 1){
			ad(dp[j][k][0], (ll)dp[j - 1][w][0] * go(i + 1, in[j - 1], in[j] - 1, k - w, false) % md);
			ad(dp[j][k][0], (ll)dp[j - 1][w][1] * (go(i + 1, in[j - 1], in[j] - 1, k - w, false) - go(i + 1, in[j - 1], in[j] - 1, k - w, true) + md) % md);
			ad(dp[j][k][1], (ll)dp[j - 1][w][1] * go(i + 1, in[j - 1], in[j] - 1, k - w, true) % md);
		}
		else f(k, 0, ln + 1)f(w, max(0, k - cln), k + 1)f(a, 0, 2)ad(dp[j][k][a && k == w + cln], (ll)dp[j - 1][w][a] * ch[cln][k - w] % md);
	}
	
	f(j, 0, ln + 1){
		ad(v[j][0], (ll)dp[in.size() - 1][j][0] * (p2[j] - 1) % md);
		ad(v[j][0], (ll)dp[in.size() - 1][j][1] * p2[j] % md);
		ad(v[j][1], (ll)dp[in.size() - 1][j][1] * p2[j] % md);
		f(k, j + 1, ln + 1){
			ad(v[j][0], (ll)dp[in.size() - 1][k][0] * ch[k][j] % md * p2[j] % md);
			ad(v[j][0], (ll)dp[in.size() - 1][k][1] * ch[k][j] % md * p2[j] % md);
			ad(v[j][1], (ll)dp[in.size() - 1][k][1] * ch[k][j] % md * p2[j] % md);
		}
	}
	
	return v[p][q];
}

int main(){
	scanf("%d", &n);
	f(i, 1, n + 1)scanf("%d", x + i);
	
	p2[0] = 1;
	f(i, 1, n + 1)ad(p2[i] = p2[i - 1], p2[i - 1]);
	f(i, 0, n + 1){
		ch[i][0] = 1;
		f(j, 1, i + 1)ad(ch[i][j] = ch[i - 1][j], ch[i - 1][j - 1]);
	}
	printf("%d\n", go());
}

Measured memory_bytes: 11136
//105
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999LL
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int H, W, h, w, A, B, C;
string s;

int main() {
	cin >> A >> B;
	//int ans = max(A, max(B, C)) * 10 + A + B + C - max(A, max(B, C));
	cout << (A%B?1:0) << endl;

	return 0;
}

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

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

    vector<bool> a(26);

    
    for(int i = 0; i < s.size(); i++){
        a[s[i] - 'a'] = true;
    }
    
    int flag = 0;
    for(int i = 0; i < 26; i++){
        if(a[i] == false){
            flag = 1;
            char c = 'a' + i;
            cout << c;
            break;
        }
    }
    if(flag == false) cout << "None";
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
map<ll,int> t;
int cnt;
const int N=2e5+5;
int n;ll k,a[N]={0},as[N];
int bit[N]={0};
void add(int x,int val) {
    while(x<cnt) bit[x]+=val,x+=x&-x;
}
int sum(int x) {
    int s=0;while(x) s+=bit[x],x-=x&-x;return s;
}
int main() {
    scanf("%d%lld",&n,&k);
    t.clear();
    for(int i=1;i<=n;i++) scanf("%lld",a+i),a[i]-=k,a[i]+=a[i-1],as[i]=a[i];
    ll ans=0;
    sort(as+1,as+1+n);
    cnt=1;
    for(int i=1;i<=n;i++) if(!t.count(as[i])) t[as[i]]=cnt++;
    for(int i=1;i<=n;i++) {
        if(a[i]>=0) ans++;
        ans+=sum(t[a[i]]);
        add(t[a[i]],1);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 16640