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

char S[300001];
int E[300000];
int W[300000];

int main(void) {
  int N, i, min;
  scanf("%d", &N);
  scanf("%s", S);
  if (S[0] == 'W')
    W[0] = 1;
  for (i = 1; i < N; i++) {
    W[i] = W[i - 1];
    if (S[i] == 'W')
      W[i]++;
  }
  if (S[N - 1] == 'E')
    E[N - 1] = 1;
  for (i = N - 2; i >= 0; i--) {
    E[i] = E[i + 1];
    if (S[i] == 'E')
      E[i]++;
  }
  min = E[1];
  for (i = 1; i < N - 1; i++) {
    if (W[i - 1] + E[i + 1] < min)
      min = W[i - 1] + E[i + 1];
  }
  if (W[N - 2] < min)
    min = W[N - 2];
  printf("%d\n", min);
  return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
//const int MOD = (int) 1e9 + 7;
const int MOD = 119 << 23 | 1;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-6;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
inline int mrand(int k) {return abs((int) mt()) % k;}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";

void chemthan() {
    string s; cin >> s;
    auto ff = [&] (string s) {
        string t = s;
        reverse(all(t));
        return s == t;
    };
    if (!ff(s)) {
        cout << "No\n";
        return;
    }
    int n = sz(s);
    int l = (n - 1) / 2 - 1;
    if (!ff(s.substr(0, l + 1))) {
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 256
/*
Hanit Banga
*/

#include <iostream>
#include <vector>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 50, MX = 4500, inf = 1e5;

int a[N], b[N], c[N], dp[MX][MX][2];

int main()
{
	int n, ma, mb;
	cin >> n >> ma >> mb;

	int mx = 0, my = 0;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
		mx += a[i];
		my += b[i];
	}

	int cur = 0, prev = 1;
	for (int i = 0; i <= mx; ++i)
		for (int j = 0; j <= my; ++j)
			dp[i][j][prev] = inf;

	dp[0][0][prev] = 0;
	for (int k = 1; k <= n; ++k)
	{
		for (int i = 0; i <= mx; ++i)
			for (int j = 0; j <= my; ++j)
				dp[i][j][cur] = dp[i][j][prev];

		int tx = mx - a[k], ty = my - b[k];
		for (int i = 0; i <= tx; ++i)
			for (int j = 0; j <= ty; ++j)
				if (dp[i][j][prev] < inf)
					dp[i + a[k]][j + b[k]][cur] = min(dp[i + a[k]][j + b[k]][cur], dp[i][j][prev] + c[k]);

		swap(cur, prev);
	}

	int ans = inf;
	for (int i = ma, j = mb; i <= mx and j <= my; i += ma, j += mb)
		ans = min(ans, dp[i][j][prev]);		

	if (ans < inf)
		cout << ans;
	else
		cout << -1;
}

Measured memory_bytes: 8832
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m;

int main(){
	cin >> n;
	ll c = (n-1)/111;
	cout << (c+1)*111 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(), v.end()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


int q;
int l[100005], r[100005];
int ruiseki[100010];

bool arr[100010];
void Eratosthenes() {
	rrep(i, 100005)arr[i] = true;
	for (int i = 2; i < 100005; i++) {
		if (arr[i]) {
			int cnt = i * 2;
			while (cnt < 100005) {
				arr[cnt] = false;
				cnt += i;
			}
		}
	}
	arr[1] = false;

}

int main() {

	cin >> q;

	Eratosthenes();

	REP(i, 3, 100005) {
		if (i % 2 == 1) {
			if (arr[i] && arr[(i + 1) / 2])ruiseki[i]++;
		}
		ruiseki[i] += ruiseki[i - 1];
	}

	rep(i, q) {
		cin >> l[i] >> r[i];
	}

	rep(i, q) {
		cout << ruiseki[r[i]] - ruiseki[l[i] - 1] << endl;
	}

	return 0;
}


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

int mod = 1000000007;
string s;
string t;
int dpCnt[200001][2];
int dpSum[200001][2];

signed main() {
	int i, j, k;
	
	cin >> s >> t;
	int n = s.length();
	
	dpCnt[0][0] = 1;
	rep(i, n) {
		rep(j, 2) {
			rep(k, 10) {
				if (t[i] != '?' && k != (t[i] - '0')) continue;
				if (j == 0 && k > (s[i] - '0')) continue;
				int nj = (j || (k < (s[i] - '0')));
				(dpCnt[i + 1][nj] += dpCnt[i][j]) %= mod;
				(dpSum[i + 1][nj] += 10 * dpSum[i][j] + dpCnt[i][j] * k) %= mod;
			}
		}
	}
	
	int ans = dpSum[n][0] + dpSum[n][1];
	cout << ans % mod << endl;
	return 0;
}


Measured memory_bytes: 9592
import           Control.Monad
import           Data.Array
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe
import           Data.Ord

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main = do
  getLine
  a <- words <$> getLine
  putStrLn $ concat $ zipWith (\a b -> [a, b]) (head a) (a !! 1)


Measured memory_bytes: 508
row = input().split()
row = list(map(int, row))
N = row[0]
X = row[1]
row2 = [input().split() for i in range(N)]
m = []

for i in range(N):
    X = X - int(row2[i][0])
    m.append(int(row2[i][0]))
print(int(X/min(m))+N)


Measured memory_bytes: 3060
#include <stdio.h>
int main (void)
{
	int H,W;
	int t,y;

	while(1)
	{

		scanf("%d %d",&H,&W);

		if((H==0)&&(W==0))break;

		for(t=0;t<H;t++)
		{

			for(y=0;y<W;y++)
			{
				if((t==0)||(t==H-1)||(y==0)||(y==W-1))
				{
					printf("#");
				}
				else
				{	
					printf(".");
				}
			}

			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

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

const long long INF = 1e18;

bool f(long long x, long long y, vector<long long> &A, int n) {//越小越好
    long long s = 0;//小于x的数
    for (int i = 0; i < n; i++) {
        int l = -1, r = n;
        if (A[i] >= 0) {
            while (l+1 < r) {
                int m = (l+r) / 2;
                if (A[i]*A[m] < x) l = m;
                else r = m;
            }
            s += l+1;
        } else {
            while (l+1 < r) {
                int m = (l+r) / 2;
                if (A[i]*A[m] < x) r = m;
                else l = m;
            }
            s += n-r;
        }
        if (A[i]*A[i] < x) s--;
    }
    s /= 2;
    return s < y;
}

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    long long l = -INF-5, r = INF+5;
    while(l<= r) {
        long long m = (l+r) / 2;
        if (f(m, K, A, N)) l = m+1;
        else r = m-1;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt(), m=fsc.nextInt();
        long[] x=new long[n];
        long[] y=new long[m];
        for(int i=0;i<n;i++){
            x[i]=fsc.nextLong();
        }
        for(int j=0;j<m;j++){
            y[j]=fsc.nextLong();
        }
        fsc.close();
        long mod=1_000_000_007;
        long xsum=0;
        for(int i=0;i<n;i++){
            xsum+=x[i]*(2*i-n+1);
        }
        xsum%=mod;
        long ysum=0;
        for(int j=0;j<m;j++){
            ysum+=y[j]*(2*j-m+1);
        }
        ysum%=mod;
        long ans=(xsum*ysum)%mod;
        System.out.println(ans);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int k = 1;
  for(int i = 0; i < N; i++){
    if(k * 2 < k + K)
      k = k * 2;//操作A
    else
      k = k + K;//操作B
  }
  cout << k << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,v,j;
    cin >> n;
    int A[n+1];
    for(int i = 0; i < n; i++){
        cin >> A[i];
        if(i!= 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    
    for(int i = 1; i < n; i ++){
        v = A[i];
        j = i - 1;
        while(A[j] > v && j >= 0){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(int k = 0; k < n; k++){
            if( k != 0){
            cout << " " ;
                
            }
            cout<< A[k];
        }
        
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<string, P> PP;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef vector<PP> Vpp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int main(){
	int n, q;
	while(scanf("%d%d", &n, &q),n||q){
		Vpp vec;
		rep(i,n){
			string str;
			int a,b;
			cin >> str >> a >> b;
			vec.pb(PP(str,P(a,b)));
		}
		rep(i,q){
			int a;
			bool ok = false;
			cin >> a;
			rep(j,n){
				if(vec[j].sec.sec >= a && a+vec[j].sec.fi > vec[j].sec.sec){
					cout << vec[j].fi << " " << a+vec[j].sec.fi-vec[j].sec.sec << endl;
					ok = true;
					break;
				}
			}
			if(!ok) cout << "Unknown" << endl;
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i<N;i++){
    cin >> vec.at(i);
  }
    sort(vec.begin(), vec.end());
    int sum = vec.at(N-1)/2;
    
  for(int i = 0; i<N-1;i++){
    sum += vec.at(i);
  }
  cout << sum << endl;

}


Measured memory_bytes: 256
import numpy as np
 
n, m = map(int, input().split())
 
an = list(map(int, input().split()))
 
an = np.array(sorted(an, reverse=True))
 
total = sum(an)
 
if sum(an[:m] >= (total / (4 * m))) >= m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 21392
#include<stdio.h>

int A[50],n;
  
int solve(int i,int m){
	int res;
	if(m == 0)return 1;
	if(i >= n)return 0;
	res = solve(i+1,m)||solve(i+1,m-A[i]);
    return res;
}

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

Measured memory_bytes: 1800
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;


int main()
{
    int n;
    cin>>n;
    vector<int>a;
    map<int,int>mp;
    rep(i,n){
        int aa;
        cin>>aa;
        if(mp[aa]==0)a.push_back(aa);
        mp[aa]++;
    }
    bool ok=false;
    int cnt=0;
    rep(i,a.size())
    {
        ok=false;
        for(int k=1;k*k<=a[i];k++)
        {
            if(a[i]%k!=0)continue;
            if(mp[k]&&a[i]!=k || mp[k]>=2){
                ok=true;
                break;
            }else if(mp[a[i]/k]&&a[i]!=a[i]/k || mp[a[i]/k]>=2){
                ok=true;
                break;
            }
        }
        if(!ok)cnt+=mp[a[i]];

    }
    cout<<cnt<<endl;

    return 0;

}


Measured memory_bytes: 32888
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef pair<int, int>pii;
int main()
{
	int num;
	scanf("%d", &num);
	map<int,int>ma;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		ma[z]++;
	}
	map<int,int>::iterator it = ma.end();
	int r = 0;
	for (;;)
	{
		if (it == ma.begin())break;
		it--;
		pii z = *it;
		for (;;)
		{
			if (ma[z.first] == 0)break;
			ma[z.first]--;
			for (int i = 30; i >= 0; i--)
			{
				if (ma.count((1 << i) - z.first) && ma[(1 << i) - z.first]>0)
				{
					ma[(1 << i) - z.first]--;
					r++;
					break;
				}
			}
		}
	}
	printf("%d\n", r);
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h1,m1,h2,m2,k,p,w;
    cin>>h1>>m1>>h2>>m2>>k;
    cout<<(h2*60+m2)-(h1*60+m1)-k<<endl;

    return 0;
}


Measured memory_bytes: 3564
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
using namespace std;

inline char gc() {
//	static char buf[100000],*p1,*p2;
//	return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	return getchar();
}

template<class T>
int read(T &ans) {
	ans=0;char ch=gc();T f=1;
	while(!isdigit(ch)) {
		if(ch==EOF) return -1;
		if(ch=='-') f=-1;
		ch=gc();
	}
	while(isdigit(ch))
		ans=ans*10+ch-'0',ch=gc();
	ans*=f;return 1;
}

template<class T1,class T2>
int read(T1 &a,T2 &b) {
	return read(a)!=EOF&&read(b)!=EOF?2:EOF;
}

template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
	return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
}

typedef long long ll;
const int Maxn=310;
const int inf=0x3f3f3f3f;
const int mod=1000000007;

int n,x,a[4];
double f[Maxn][Maxn][Maxn];

signed main() {
//	freopen("test.in","r",stdin);
	read(n);
	for(int i=1;i<=n;i++) {
		read(x);
		a[x]++;
	}
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n-i;j++)
			for(int k=0;k<=n-i-j;k++) {
				if(!i&&!j&&!k) continue;
				double x=i+j+k,p=(double)n/x;
				if(i) f[i][j][k]+=f[i-1][j+1][k]*i/x;
				if(j) f[i][j][k]+=f[i][j-1][k+1]*j/x;
				if(k) f[i][j][k]+=f[i][j][k-1]*k/x;
				f[i][j][k]+=p;
			}
	printf("%.10lf",f[a[3]][a[2]][a[1]]);
	return 0;
}



Measured memory_bytes: 225408
#include<stdio.h>
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");
	}
	return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<limits>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int main() {
	int h, m, hh, mm, k;
	cin >> h >> m >> hh >> mm >> k;
	cout << hh * 60 + mm - h * 60 - m - k << endl;

	return 0;
}

Measured memory_bytes: 3600
#define _GLIBCXX_DEBUG
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char* argv[])
{
  int N, M;
  std::cin >> N;
  std::vector< int > vt(N, 0);

  int sum = 0;
  for (int i = 0; i < N; i++) {
    std::cin >> vt[i];
    sum += vt[i];
  }

  std::cin >> M;
  std::vector< std::pair< int, int > > vp(M, std::make_pair(0, 0));
  for (int i = 0; i < M; i++) {
    std::cin >> vp[i].first >> vp[i].second;
    std::cout << sum - vt[vp[i].first-1] + vp[i].second << std::endl;
  }

  return 0;
}


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

using namespace std;

template<int MOD>
struct ModInt {
   using Mint = ModInt;
   int val;
   ModInt(int64_t __val = 0) { fix(__val % MOD + MOD); }
   Mint& fix(int __val) { val = __val; if (val >= MOD) val -= MOD; return *this; }
   explicit operator int() { return val; }
   Mint operator + (const Mint &mt) const { return Mint().fix(val + mt.val); }
   Mint operator - (const Mint &mt) const { return Mint().fix(val - mt.val + MOD); }
   Mint operator * (const Mint &mt) const { return Mint().fix(int64_t(val) * mt.val % MOD + MOD); }
   Mint& operator += (const Mint &mt) { return *this = *this + mt; }
   Mint& operator -= (const Mint &mt) { return *this = *this - mt; }
   Mint& operator *= (const Mint &mt) { return *this = *this * mt; }
   Mint pow(int y) const {
      Mint x = *this;
      Mint ans(1);
      for (; y > 0; y >>= 1, x *= x) {
         if (y & 1) ans *= x;
      }
      return ans;
   }
   Mint operator -() const { return Mint().fix(MOD - val); }
   Mint inv() const { return pow(MOD - 2); }
   Mint operator / (const Mint &mt) const { return *this * mt.inv(); }
   Mint& operator /= (const Mint &mt) const { return *this / mt; }
   friend ostream& operator<<(ostream& os, const Mint& mt) { return os << mt.val; }
};

using Mint = ModInt<1000000007>;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N, A, B, C; cin >> N >> A >> B >> C;
   if (B & 1) {
      cout << "0\n";
      return 0;
   }
   B >>= 1;
   vector<Mint> fact(N+1);
   fact[0] = 1; for (int i = 1; i <= N; ++i) fact[i] = fact[i - 1] * i;
   vector<Mint> ifact(N+1);
   ifact[N] = fact[N].inv(); for (int i = N; i > 0; --i) ifact[i - 1] = ifact[i] * i;
   Mint ans = 0;
   for (int x = 0; x <= min(A, C); ++x) {
      for (int y = 0; x + 3 * y <= C; ++y) {
         int z = C - x - 3 * y;
         Mint ways = (B == 0 ? Mint(!z) : fact[z + B - 1] * ifact[B - 1] * ifact[z]);
         ways *= fact[x + y + B + A - x] * ifact[x] * ifact[y] * ifact[B] * ifact[A - x];
         ans += ways;
      }
   }
   cout << ans << '\n';
   return 0;
}


Measured memory_bytes: 3668
//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    cin>>a;
    if(a==0)cout<<1<<"\n";
    else cout<<0<<"\n";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=9;i++)
	if(n%i==0)
	if(n/i<=9)
	{
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
A = [[]]*3
for T in range(0,3):
    A[T] = [int(x) for x in input().split()]
A   = sum(A,[])
ATF = [False]*9

N = int(input())
for TT in range(0,N):
    B = int(input())
    if B in A:
        ATF[A.index(B)] = True

Flag = 0
if   (all(ATF[:3])) or (all(ATF[3:6])) or (all(ATF[6:])):
    Flag = 1
elif (all(ATF[::3])) or (all(ATF[1::3])) or (all(ATF[2::3])):
    Flag = 1
elif (all(ATF[::4])) or (all(ATF[2:7:2])):
    Flag = 1

if Flag:
    print('Yes')
else:
    print('No')

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

int main() {
	int A, B, K; cin >> A >> B >> K;
	if((B-A)/2<K){
	    for(int i=A; i<=B; ++i) cout << i << endl;
	}
	else{
	    for(int i=0; i<K; ++i) cout << A+i << endl;
	    for(int i=K-1; i>=0; --i) cout << B-i << endl;
	}
	return 0;
}


Measured memory_bytes: 256
def p_b():
    S = input()

    f = True
    for i in range(len(S)):
        if i % 2 == 1:
            if S[i] == "R":
                f = False
        else:
            if S[i] == "L":
                f = False

    if f:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    p_b()


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

int main(){
    int v,k;
    cin>>v>>k;
    vector<int> G[100000];
    vector<bool> goal(v,false);
    int ans = 0;
    rep(i,v){
        int s;
        cin>>s;
        s--;
        if(i==0 && s!=0){
            ans++;
            s = 0;
        }
        G[s].pb(i);
        if(s==0)goal[i] = true;
    }
    
    vector<bool> used(v,false);
    used[0] = true;
    
    function<int(int)> dfs = [&](int cur){
        int maxi = 0;
        for(auto to:G[cur]){
            if(used[to])continue;
            used[to] = true;
            maxi = max(1+dfs(to),maxi);
        }
        if( goal[cur] == false && maxi+1>=k ){
            ans++;
            maxi = -1;
        }
        
        return maxi;
    };
    
    dfs(0);
    
    cout<<ans<<endl;
}

Measured memory_bytes: 13568
#include <cstdlib>
#include <iostream>
#include <vector>
typedef long long LL;

int main() {
  int n; std::cin >> n;
  std::vector<LL> h(n), cost(n);
  for (int i = 0; i < n; ++i) std::cin >> h[i];

  cost[n-1] = 0;
  cost[n-2] = std::abs(h[n-2] - h[n-1]);

  for (int i = n-3; i >= 0; --i) {
    LL cost1 = std::abs(h[i] - h[i+1]) + cost[i+1];
    LL cost2 = std::abs(h[i] - h[i+2]) + cost[i+2];
    cost[i] = std::min(cost1, cost2);
  }

  std::cout << cost[0] << std::endl;
}


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;
ll b[200005];
void update(int x,ll d){
    while(x <= 200000){
        b[x] += d;
        x += x & (-x);
    }
}
ll sum(int x){
    ll ret = 0;
    while(x){
        ret += b[x];
        x -= x & (-x);
    }
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<pair<ll,ll> >v;
    f(n){
        int x, y;
        cin >> x >> y;
        v.pb({x,y});
    }
    v.pb({-1e9,-1e9});
    sort(v.begin(),v.end());
    vector<ll>pos;
    for(auto i:v){
        pos.pb(i.F);
    }
    ll ans = 0;
    for(int i = 1 ; i <= n ; i++){
        ll left = v[i].S - sum(i);
        if(left <= 0){
            continue;
        }
        ll cnt = (left - 1) / k + 1;
        ans += cnt;
        ll last = upper_bound(pos.begin(),pos.end(),pos[i]+2*m)-pos.begin();
        update(i,cnt * k);
        update(last,-cnt * k);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 9196
import sys
input = sys.stdin.readline

def solve():
    ordA = ord('a')

    N = int(input())
    Ss = input().rstrip()
    Q = int(input())
    querys = [tuple(input().split()) for _ in range(Q)]

    idEle = 0
    def _binOpe(x, y):
        return x | y
    def makeSegTree(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [idEle] * (2*numPow2)
        return data, numPow2
    def setInit(As):
        for iST, A in enumerate(As, numPow2):
            data[iST] = A
        for iST in reversed(range(1, numPow2)):
            data[iST] = _binOpe(data[2*iST], data[2*iST+1])
    def _update1(iA, A):
        iST = iA + numPow2
        data[iST] = A
    def update(iA, A):
        _update1(iA, A)
        iST = iA + numPow2
        while iST > 1:
            iST >>= 1
            data[iST] = _binOpe(data[2*iST], data[2*iST+1])
    def getValue(iSt, iEn):
        L = iSt + numPow2
        R = iEn + numPow2
        ans = idEle
        while L < R:
            if L & 1:
                ans = _binOpe(ans, data[L])
                L += 1
            if R & 1:
                R -= 1
                ans = _binOpe(ans, data[R])
            L >>= 1
            R >>= 1
        return ans

    data, numPow2 = makeSegTree(N)
    As = [(1<<(ord(S)-ordA)) for S in Ss]
    setInit(As)

    anss = []
    for tp, *vs in querys:
        if tp == '1':
            i, c = vs
            i = int(i)
            update(i-1, 1<<(ord(c)-ordA))
        else:
            L, R = vs
            L, R = int(L), int(R)
            v = getValue(L-1, R)
            anss.append(bin(v).count('1'))

    print('\n'.join(map(str, anss)))


solve()


Measured memory_bytes: 109248
#include <iostream>

using namespace std;

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

    int res = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        while (a % 2 == 0) {
            a /= 2;
            res++;
        }
    }

    cout << res << endl;
}


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

int main() {
  int A,B;
  int C=10;
  cin >> A >> B;
  for(int i=0; i<1; i++) {
    if(2*A > B) {
      C--;
    }
    else if(B > 4*A) {
      C--;
    }
    else if (B/2 != (B+1)/2) {
      C--;
    }
  }
  if (C == 10) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <stdlib.h>

int compar_int(int *a, int *b) {
	if (*a > *b) return 1;
	if (*a == *b) return 0;
	return -1;
}

int main() {
	long long int ans;
	int l[2];
	l[0] = 0; l[1] = 0;
	int N;
	scanf("%d", &N);
	int A[N];
	for (int i = 0; i < N; i++) scanf("%d", A+i);
	
	qsort(A, N, sizeof(int), compar_int);

	for (int i = N-1; i > 0 && !l[1]; i--) {
		if (A[i] == A[i-1]) {
			if (!l[0]) l[0] = A[i];
			else l[1] = A[i];
			i--;
		}
	}

	ans = (long long int)l[0] * l[1];

	printf("%lld\n", ans);

	return 0;	
}


Measured memory_bytes: 892
N = int(input())
L = [int(l) for l in input().split(" ")]

def solve():
  ans = 0
  if len(L) < 3:
    return 0
  for i in range(N):
    for j in range(i, N):
      for k in range(j, N):
        if L[i] != L[j] and\
           L[j] != L[k] and\
           L[k] != L[i]:
          d = {i: L[i], j:L[j], k:L[k]}
          max_idx = max(d, key=lambda x: d[x])
          if sum(d.values()) - 2*L[max_idx] > 0:
            ans += 1# .append((i,j,k))
  return ans

print(solve())

Measured memory_bytes: 9064
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N, M = input_nums()
    L = 1
    R = N
    for i in range(M):
        l, r = input_nums()
        L = max(L, l)
        R = min(R, r)
        if L > R:
            print(0)
            exit(0)
    print(R-L+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 41324
#include <bits/stdc++.h>
typedef uint64_t ll;
using std::cout ;
using std::endl ;
using std::cin ;
using std::string ;
using std::vector ;
using std::set ;
using std::map ;
using std::pair ;
#define rep(i,n) for(int i=0, i##_end=(n); i<i##_end; i++)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
template<class T>bool updateMax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool updateMin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(c) c.begin(),c.end()
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
    int N, M;
    ll K;
    vector<ll> A, B;
    cin >> N >> M >> K;
    rep(i, N) {
        ll Ai;
        cin >> Ai;
        A.push_back(Ai);
    }
    rep(i, M) {
        ll Bi;
        cin >> Bi;
        B.push_back(Bi);
    }
    
    int aidx = 0;
    int bidx = 0;
    ll rest = K;
    rep(i, N) {
        if(A[i] <= rest) {
            aidx++;
            rest -= A[i];
        } else {
            break;
        }
    }
    rep(i,M) {
        if(B[i] <= rest) {
            bidx++;
            rest -= B[i];
        } else {
            break;
        }
    }
    if(aidx + bidx == N + M) {
        cout << (N + M) << endl;
        return 0;
    }
    int max = aidx + bidx;
    while(aidx > 0 && bidx < M) {
        aidx--;
        rest += A[aidx];
        while(B[bidx] <= rest && bidx < M) {
            rest -= B[bidx];
            bidx++;
        }
        if(aidx + bidx > max) {
            max = aidx + bidx;
        }
    }
    
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 7984
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  string a,b;
  cin >> a >> b;
  if(a.size()>b.size()) puts("GREATER");
  else if(a.size()<b.size()) puts("LESS");
  else if(a.size()==b.size()){
    for(int i=0;i<a.size();i++){
      if(a[i]==b[i]) continue;
      if(a[i]>b[i]) {
        puts("GREATER");
        return 0;
      }else{
        puts("LESS");
        return 0;
      }
    }
    puts("EQUAL");
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; ++i) cin >> a[i];
  int ans = 0;
  for(int num:a)
  {
    while(num%2==0)
    {
      num=num/2;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
n=int(input())
p=[int(i) for i in input().split()]

cnt=0
for i in range(1,len(p)-1):
    if p[i-1] < p[i] < p[i+1]:
        cnt+=1
    elif p[i-1] > p[i] > p[i+1]:
        cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e){ll ans=1;GG(e<0);while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    struct BIT
    {
        ll bit[N];int lowbit(int x){return x&-x;}
        void add(int x,int c){while(x<N)bit[x]+=c,x+=lowbit(x);}
        ll ask(int x){ll ans=0;while(x>=1)ans+=bit[x],x-=lowbit(x);return ans;}
    }bit;
    vc<int> tmp;void ss(int num){tmp.PB(num);}int getnum(int i){return lower_bound(all(tmp),i)-tmp.begin()+1;}
    vc<pr> pt;bool cmp(pr a,pr b){return a.FR<b.FR or (a.FR==b.FR and a.SE>b.SE);}
    int fx[N],fy[N];
    void main()
    {
        int n=qread(),m=qread();
        fo(i,1,n) fx[i]=qread();fo(i,1,m) fy[i]=qread();
        fo(i,1,n)
        {
            int right=upper_bound(fy+1,fy+m+1,fx[i])-fy;
            if(right>1 and right<=m)
            {
                int a=fx[i]-fy[right-1],b=fy[right]-fx[i];
                ss(a);ss(b);pt.PB(MP(a,b));
            }
        }
        sort(all(tmp));fo(t,0,sz(pt)-1) pt[t].SE=getnum(pt[t].SE);
        ll ans=1;sort(all(pt),cmp);pt.resize(unique(all(pt))-pt.begin());//debug 有重点
        fo(t,0,sz(pt)-1)
        {
            ll num=1+bit.ask(pt[t].SE-1);num%=MOD;
            ans=mm(ans+num);bit.add(pt[t].SE,num);
        }write(ans);
    }
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 12652
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c=0;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    if(i/10000==i-(i/10)*10 && i/1000-(i/10000)*10==i/10-(i/100)*10){
      c++;
    }
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict
def solve():
    N = int(input())
    d = defaultdict(int)
    prev = []

    for i in range(N):
        w = input()
        if d[w] == 1:
            print('No')
            return
        d[w] += 1
        w_list = list(w)
        if i != 0 and w_list[0] != prev[-1]:
            print('No')
            return

        prev = w_list 
    else:
        print('Yes')

if __name__ == '__main__':
    solve()

Measured memory_bytes: 38384
# A
N, M = map(int, input().split())
S = list(input())
T = list(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

A = gcd(N, M)

res = M * N // A

for i in range(A):
    if S[i*(N // A)] != T[i*(M // A)]:
        res = -1
print(res)

Measured memory_bytes: 4496
#pragma GCC target("avx")
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

ll dp[100001];

int main(void){
    cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vl h(n);
	rep(i,n){
	    cin>>h[i];
	    dp[i] = inf;
	}
	dp[0] = 0;
	rep(i,n){
	    rep1(j,k+1){
	        if(i+j<n) dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
	    }
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;

ll n;
priority_queue<ll> pq1;
priority_queue<ll, vector<ll>, greater<ll> > pq2;
bool v = false;
ll x;
ll sz1 = 0, sz2 = 0;
ll now = 0;
ll sum1 = 0, sum2 = 0;

int main()
{
    scanf("%lld", &n);
    while(n--)
    {
        ll t;
        scanf("%lld", &t);
        if(t == 2)
        {
            printf("%lld %lld\n", x, now + sum2 - x * sz2 + x * sz1 - sum1);
        }
        else
        {
            ll t1, t2;
            scanf("%lld%lld", &t1, &t2);
            if(!v)
            {
                v = true;
                x = t1;
                now += t2;
                continue;
            }
            now += t2;
            if(sz1 < sz2) pq1.push(t1), sz1++, sum1 += t1;
            else pq2.push(t1), sz2++, sum2 += t1;
            if(!pq1.empty() && pq1.top() > x)
            {
                ll t3 = pq1.top();
                pq1.pop();
                sum1 += x - t3;
                pq1.push(x);
                x = t3;
            }
            if(!pq2.empty() && x > pq2.top())
            {
                ll t3 = pq2.top();
                pq2.pop();
                sum2 += x - t3;
                pq2.push(x);
                x = t3;
            }
            if(!pq1.empty() && pq1.top() > x)
            {
                ll t3 = pq1.top();
                pq1.pop();
                sum1 += x - t3;
                pq1.push(x);
                x = t3;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3828
from collections import deque

h,w = map(int,input().split())
l = [list(input()) for i in range(h)]

dis = [[10000]*w for i in range(h)]
q = deque([])

for i in range(h):
    for j in range(w):
        if l[i][j] == "#":
            q.append([i,j,0])
            dis[i][j] = 0
dx = [0,0,1,-1]
dy = [1,-1,0,0]
while q:
    x,y,d = q.popleft()

    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx < h and 0 <= ny < w and dis[nx][ny] > d+1:
            dis[nx][ny] = d + 1
            q.append([nx,ny,d+1])

ans = 0
for i in dis:
    ans = max(ans,max(i))
print(ans)


Measured memory_bytes: 218212
#include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int n, w_max;
int dp[101][10001];
bool f[101][100001];
vector<pair<int, int> > item(101);

int saiki(int i, int j){
    if(f[i][j]){
        return dp[i][j];
    }

    int res;
    if(i==n){
        res = 0;
    }else if(j<item[i].second){
        res = saiki(i+1, j);
    }else{
       res = max(saiki(i+1, j), saiki(i, j-item[i].second)+item[i].first);
    }

    dp[i][j] = res;
    f[i][j] = true;
    return res;
}

int main(){
    cin>> n>> w_max;
    for(int i=0; i<n; i++){
        cin>> item[i].first>> item[i].second;
    }

    cout<< saiki(0, w_max)<< endl;

    return 0;
}

Measured memory_bytes: 13720
import java.util.*;
public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt(), m = sc.nextInt();
			if( (n|m) == 0 ) break;
			System.out.println(josephus(n, m, n)+1);
		}
	}
	int josephus(int n, int m, int k) {
		int x = -1;
		for (int i = n - k + 1; i <= n; i++) {
			x = (x + m) % i;
		}
		return x;
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
long long expo(long long a,long long b){
    if(b==0)return 1;
    long long temp = expo(a,b/2);
    temp = temp*temp;
    if(b%2!=0)temp*=a;
    return temp;
}
int main(){
	int n,p;
	cin>>n>>p;
	long long e=0,o=0;
	for(int i=0,a;i<n;i++){
		cin>>a;
		if(a%2)o++;
		else e++;
	}
	long long ans=1;
	if(p%2){
		//odd
		//odd number of odd values
		//any number of even values
		if(o==0){
			ans=0;
		}
		else{
			ans = ans*expo(2,o-1);
			ans = ans*expo(2,e);
		}
	}
	else{
		//even 
		ans = ans*(expo(2,e));
		if(o!=0)ans= ans*expo(2,o-1); 
	}
	cout<<ans;
}

Measured memory_bytes: 3612
#pragma GCC optimize("O3")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>ll(b);i--)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
#define INF 1000000000000 
#define MOD 1000000007 
#define MAXR 100000 
#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 
#define Umap unordered_map
#define Uset unordered_set


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int X;
    cin >> X;

    if (X >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3644
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func increment(bits []bool) bool {
	i := 0
	for i < len(bits) && bits[i] {
		bits[i] = false
		i++
	}
	if i < len(bits) {
		bits[i] = true
	} else {
		return false
	}
	return true
}

func contains(bits []bool, subsetIdx []int) bool {
	for i := 0; i < len(subsetIdx); i++ {
		j := subsetIdx[i]
		if !bits[j] {
			return false
		}
	}
	return true
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()

	k := nextInt()
	b := make([]int, k)
	for i := 0; i < k; i++ {
		b[i] = nextInt()
	}

	bits := make([]bool, n)

	ok := true
	i := 0
	for {
		if contains(bits, b) {
			cache := []string{}
			for j := 0; j < n; j++ {
				if bits[j] {
					cache = append(cache, strconv.Itoa(j))
				}
			}
			if i == 0 {
				fmt.Println("0:")
			} else {
				fmt.Printf("%v: %v\n", i, strings.Join(cache, " "))
			}
		}

		i++
		ok = increment(bits)
		if !ok {
			break
		}
	}
}



Measured memory_bytes: 6144