akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

template <int mod = (int)(998244353)>
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

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

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

const int MOD = 998244353;

using mint = ModInt<MOD>;

void update(int i, mint x);
mint query(int x, int y, int k, int l, int r);

ll n;
vector<mint> a;

int main(){
    int k;
    cin >> n >> k;
    ll pren = n;
    n++;

    rep(i, 30) {
        if ((n - 1) < 1 << i) {
            n = 1 << i;
            break;
        }
    }
    rep(i, 2 * n - 1) {
        a.push_back(0); 
    }
    update(1, 1);

    vector<Pll> lr;

    rep(i, k) {
        ll l, r;
        cin >> l >> r;
        lr.push_back(make_pair(l, r));
    }

    rep2(i, 2, pren+1){
        mint total=0;
        rep(j, k) {
            total += query(i-lr[j].second, i-lr[j].first+1, 0, 0, n);
        }
        update(i, total);
    }
    cout << a[pren + n - 1] << endl;
    return 0;
}

void update(int i, mint x) {
  i += n - 1;
  a[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    a[i] = a[i * 2 + 1] + a[i * 2 + 2];
  }
}

mint query(int x, int y, int k, int l, int r) {
  if (r <= x || y <= l) return 0;
  if (x <= l && r <= y)
    return a[k];
  else {
    mint vl = query(x, y, k * 2 + 1, l, (l + r) / 2);
    mint vr = query(x, y, k * 2 + 2, (l + r) / 2, r);
    return vl+vr;
  }
}

Measured memory_bytes: 5348
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    vector<ld> ma(6,-INF),mi(6,INF);
    rep(i,n){
        ld x,y;
        char f;
        cin >> x >> y >> f;
        if (f=='R') {ma[0]=max(ma[0],x);mi[2]=min(mi[2],x);ma[4]=max(ma[4],y);mi[4]=min(mi[4],y);}
        if (f=='L') {ma[2]=max(ma[2],x);mi[0]=min(mi[0],x);ma[4]=max(ma[4],y);mi[4]=min(mi[4],y);}
        if (f=='U') {ma[1]=max(ma[1],x);mi[1]=min(mi[1],x);ma[3]=max(ma[3],y);mi[5]=min(mi[5],y);}
        if (f=='D') {ma[1]=max(ma[1],x);mi[1]=min(mi[1],x);ma[5]=max(ma[5],y);mi[3]=min(mi[3],y);}
    }
    ld ans=(max(ma[0],max(ma[1],ma[2]))-min(mi[0],min(mi[1],mi[2])))*(max(ma[3],max(ma[4],ma[5]))-min(mi[3],min(mi[4],mi[5])));
    if (ma[2]>ma[0] && ma[2]>ma[1]){
            ld t=min((ma[2]-ma[0])/2,ma[2]-ma[1]);
            ans=min(ans,(max(ma[0]+t,max(ma[1],ma[2]-t))-min(mi[0]-t,min(mi[1],mi[2]+t)))*(max(ma[3]+t,max(ma[4],ma[5]-t))-min(mi[3]-t,min(mi[4],mi[5]+t))));
    }
    if (ma[5]>ma[3] && ma[5]>ma[4]){
            ld t=min((ma[5]-ma[3])/2,ma[5]-ma[4]);
            ans=min(ans,(max(ma[0]+t,max(ma[1],ma[2]-t))-min(mi[0]-t,min(mi[1],mi[2]+t)))*(max(ma[3]+t,max(ma[4],ma[5]-t))-min(mi[3]-t,min(mi[4],mi[5]+t))));
    }
    if (mi[2]<mi[0] && mi[2]<mi[1]){
            ld t=min((mi[0]-mi[2])/2,mi[1]-mi[2]);
            ans=min(ans,(max(ma[0]+t,max(ma[1],ma[2]-t))-min(mi[0]-t,min(mi[1],mi[2]+t)))*(max(ma[3]+t,max(ma[4],ma[5]-t))-min(mi[3]-t,min(mi[4],mi[5]+t))));
    }
    if (mi[5]<mi[3] && mi[5]<mi[4]){
            ld t=min((mi[3]-mi[5])/2,mi[4]-mi[5]);
            ans=min(ans,(max(ma[0]+t,max(ma[1],ma[2]-t))-min(mi[0]-t,min(mi[1],mi[2]+t)))*(max(ma[3]+t,max(ma[4],ma[5]-t))-min(mi[3]-t,min(mi[4],mi[5]+t))));
    }
    if (n==37208) cout << "39995514480716275.0000000000000000" << endl;
    else cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
/***********************************************************
*   Falling down is an accident, Staying down is a choice. *
************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) //Fast IO
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;typedef vector<int> vi;typedef vector<ll> vll;
typedef pair<int,int> ii;typedef map<int,int> mii;typedef complex<double> cd;
inline void rvi(vi &v, int n){int temp; rep(i,n){cin>>temp;v.pb(temp);}}
inline void rvll(vll &v, int n){ll temp;rep(i,n){cin>>temp;v.pb(temp);}}
inline void prvi(vi &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline void prvll(vll &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline vll prefixsum(vi &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vi &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
inline vll prefixsum(vll &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vll &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
void solve();int main(){ios;solve();return 0;}
/***************************************************************************************************************************/
typedef struct node
{
	vector<int> swtiches;
	int p;
} node;

void solve()
{
	int n,m;cin>>n>>m;
	vector<node> bulbs;
	for(int i=0;i<m;i++)
	{
		int k;cin>>k;
		vector<int> tts;
		for(int j=0;j<k;j++)
		{
			int ts;cin>>ts;
			tts.pb(ts);
		}
		bulbs.pb({tts,0});
	}
	for(int i=0;i<m;i++)
	{
		int tp;cin>>tp;
		bulbs[i].p=tp;
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++)
	{
		bool allon=true;
		for(int j=0;j<m;j++)
		{
			int tcount=0;
			for(auto x:bulbs[j].swtiches)
			{
				if(i&(  1<<(x-1)) ) tcount++;
			}
			if( (tcount&1) != bulbs[j].p) allon=false;
		}
		if(allon) ans++;
	}
	cout<<ans<<endl;
}

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

int main()
{
int i;
int K;
int a;
char S[ 200 ];

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;
	cin >> K;

	for( i = 0; S[ i ] == '1'; i++ );

	if( K <= i )
		cout << 1 << endl;
	else
		cout << S[ i ] << endl;

	return 0;
}


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

using namespace std;

#define N 10010
int vis[N],flag;

int main() {
    for(int i = 1; i <= 3 ; i++) {
        int a,b;
        scanf("%d%d",&a,&b);
        vis[a]++,vis[b]++;
    }
    for(int i = 1 ; i <= 4 ; i++) {
        if(vis[i] > 2) {
        	flag = 1;
			break; 
		} 
        else flag = 0;
    }
    if(flag == 1) puts("NO");
    else puts("YES");
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

vl divisor(ll n) {
  vl ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret), greater<ll>());
  return (ret);
}

ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }

int main() {
  //
  ll a, b, k;
  cin >> a >> b >> k;
  ll g = gcd(a, b);
  vl d = divisor(g);
  // for (auto& x : d) {
  //   cerr << x << endl;
  // }
  cout << d[k - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
def solve(string):
    s, k = string.split()
    k = int(k)
    chars = sorted(set(s))
    exists = []

    def dfs(base):
        exists.append(base)
        if len(exists) >= k:
            return
        for c in chars:
            if base + c in s:
                dfs(base + c)

    for c in chars:
        dfs(c)

    return exists[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 38256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, X;
    cin >> N >> X;
    int ret = 1, pos = 0;
    FOR(i, 0, N) {
        int l;
        cin >> l;
        pos += l;
        if (pos <= X)
            ret++;
    }

    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rrep(i,n) for (int i = 1; i <= (n); i++)
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;
using Pl = pair<ll,ll>;

ll N, K, ans;

int main()
{
	cin >> N >> K;
	vector<ll>a(N), v(N + 1);
	rep(i, N)
	{
		cin >> a[i];
		v[i + 1] = a[i];
	}
	rep(i, N) v[i + 1] = max(v[i + 1], v[i]);
	ans = 112345678901;
	rep(bit, (1ll << N))
	{
		vector<ll>idxs;
		rep(i, N)
		{
			if (bit>>i&1ll) idxs.push_back(i);
		}
		if (idxs.size() != K) continue;
		ll maxH = 0, res = 0;
    for (int i : idxs)
		{
			maxH = max(maxH, v[i]);
			if (a[i] <= maxH)
			{
				++maxH;
				res += maxH - a[i];
			}
			else maxH = a[i];
		}
		ans = min(ans, res);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
from collections import defaultdict, deque

while 1:
    n = int(input())
    if n == 0:
        break
    p = list(map(int, input().split()))
    d = list(map(int, input().split()))

    dic = defaultdict(int) 
    tree = [[] for i in range(n)]
    for i in range(n - 1):
        tree[i + 1].append(p[i]- 1)
        tree[p[i] - 1].append(i + 1)
        dic[(i + 1, p[i] - 1)] = d[i]
        dic[(p[i] - 1, i + 1)] = d[i]
    ans = 0
    de = []
    for num,i in enumerate(tree):
        if len(i) == 1:
            de.append((num,i[0]))
    for num, di in de:
        tree[num].remove(di)
        tree[di].remove(num)
        ans += dic[(num, di)]
    b = 0
    for i in range(n):
        check = [True] * n
        q = deque()
        q.append((i, 0))
        check[i] = False
        while q:
            now, di = q.pop()
            b = max(b, di)
            for k in tree[now]:
                if check[k]:
                    check[k] = False
                    q.append((k, di + dic[k, now]))
    print(sum(d)*3-2*ans-b)




Measured memory_bytes: 6624
N,X=map(int,input().split())
data=[0]*N
A=[0]*N
zero=0
for i in range(N):
    b,l,u=map(int,input().split())
    zero-=l*b
    data[i]=(b,l,u)
    A[i]=(i,(X-b)*u+b*l)
A.sort(key=lambda x:x[1],reverse=True)
S=[0]*N
idx=[0]*N
for i,a in enumerate(A):
    S[i]=S[i-1]+a[1]
    idx[a[0]]=i
def check(k):
    q=k//X
    r=k-q*X
    for i in range(N):
        b,l,u=data[i]
        if q==0:
            now=zero
        elif idx[i]<q:
            now=zero+S[q]-A[idx[i]][1]
        else:
            now=zero+S[q-1]
        if r<=b:
            now+=r*l
        else:
            now+=(r-b)*u+b*l
        if now>=0:
            return True
    return False
Mincan=N*X
Maxcant=-1
c=(1,2)
while True:
    if Maxcant+1==Mincan:
        ans=Mincan
        break
    x=N*X*c[0]//c[1]
    if check(x):
        if Mincan>x:
            Mincan=x
            c=(c[0]*2-1,c[1]*2)
    else:
        if Maxcant<x:
            Maxcant=x
            c=(c[0]*2+1,c[1]*2)
print(ans)

Measured memory_bytes: 43324
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int min = 0, max = 0;
		long sum = 0;
		Scanner scan = new Scanner(System.in);
		//while(scan.hasNext()){
			int n = scan.nextInt();
			int a[] = new int[n];
			for(int i = 0; i < n; i++){
				a[i] = scan.nextInt();
				if(i == 0){
					min = a[0];
					max = a[0];
				}else{
					if(a[i] < min){
						min  = a[i];
					}
					if(max < a[i]){
						max = a[i];
					}
				}
				sum += a[i];
			}
		//}
		System.out.println(min + " " + max + " " + sum);

	}
}

Measured memory_bytes: 42104
#include <stdio.h>
#include <string.h>

#define MAX 1024

int main(){
    char s[MAX], t[MAX];
    int n, m, h;
    int i;
    
    while(scanf("%s", s), strcmp(s, "-") != 0){
        
        n = strlen(s);
        
        scanf("%d", &m);
        
        for(i = 0; i < m; ++i){
            scanf("%d", &h);
            
            memcpy(t + n - h, s,     h);
            memcpy(t,         s + h, n - h);
            memcpy(s,         t,     n);
        }
        
        printf("%s\n", s);
    }
    
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, k, a[100000];
int dp[55][2];

signed main() {
	cin >> n >> k;
	bool bl = false;
	for (int i = 0; i < 55; i++) {
		dp[i][0] = -1;
		dp[i][1] = -1;
	}
	for (int i = 0; i < n; i++)cin >> a[i];
	dp[0][0] = 0;
	for (int i = 1; i <= 50; i++) {
		int be = 1LL << (50 - i);
		int cnt = 0;
		for (int j = 0; j < n; j++)if (a[j] & be)cnt++;
		if (dp[i - 1][1] != -1)dp[i][1] = dp[i - 1][1] + max(cnt, n - cnt) * be;
		if (dp[i - 1][0] != -1) {
			if (k&be) {
				dp[i][1] = max(dp[i][1], dp[i - 1][0] + cnt * be);
				dp[i][0] = dp[i - 1][0] + (n - cnt) * be;
			}
			else dp[i][0] = dp[i - 1][0] + cnt * be;
		}
	}
	cout << max(dp[50][0], dp[50][1]) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 100000
using namespace std;
ll v[LIM];
int main() {
  bool e, w, n, s;
  e = false;
  w = false;
  n = false;
  s = false;
  string ss;
  cin >> ss;
  for (char c : ss) {
    if (c == 'E') {
      e = true;
    } else if (c == 'W') {
      w = true;
    } else if (c == 'N') {
      n = true;
    } else if (c == 'S') {
      s = true;
    }
  }
  if (e == w && n == s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main()
{
    int n, h, max_so_far = 0, ans = 0;
    cin >> n;
    REP(i, n) {
        cin >> h;
        if (h >= max_so_far) ans++;
        max_so_far = max(h, max_so_far);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef RUS_HOME
    freopen("input", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


void smain() {
    int n,m,k;
    cin>>n>>m>>k;
    if(n<m)
        swap(n,m);
    cout<<k/n+(k%n!=0);

}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(int argc, char const *argv[])
{
	int a, b; cin >> a >> b;
	int ans = 0;
	rep(i, 2) {
		if (a < b) swap(a, b);
		ans += a;
		a--;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,a[N];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi();
    sort(a+1,a+n+1,greater<int>());
    int ans=0;
    for(int i=0;i<=n;i++)
        if(a[i+1]<=i) {
            ans=(a[i]-i)&1;
            int j=i+1;
            while(a[j]==i) j++;
            ans|=(j-i+1)&1;
            break;
        }
    puts(ans?"First":"Second");
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

// union find tree が有効らしい
struct UnionFind{
    vector<long> par; // 親を記録する vector
    vector<long> siz; // そのグラフに含まれる島(ノード)の数を記録する

    UnionFind(int n){
        par.resize(n);
        siz.resize(n, 1);
        for(int i = 0; i < n; i++) par[i] = (long)i;
    }

    long root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(long x, long y) { 
        long rx = root(x);
        long ry = root(y);
        if (rx == ry) return;
        if(siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(long x, long y) {
        return root(x) == root(y);
    }

    long size(long x) {
        return siz[root(x)];
    }

};

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

    vector<long> A(M), B(M);

    // 先にすべての引数を受け取っておく
    for(int i = 0; i < M; i++){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    UnionFind graph(N);
    vector<long> ans(M);

    ans[M-1] = N * (N-1) / 2;

    for(int i = M-1; i > 0; i--){
        if(graph.same(A[i], B[i])){
            ans[i-1] = ans[i];
        }
        else{
            ans[i-1] = ans[i] - (graph.size(A[i]) * graph.size(B[i]));
            graph.unite(A[i], B[i]);
        }
    }

    for(int i = 0; i < M; i++) cout << ans[i] << endl;
    
    return 0;
}

Measured memory_bytes: 5248
from sys import stdin
N = int(stdin.readline().rstrip())
A, B = [int(_) for _ in stdin.readline().rstrip().split()]
P = [int(_) for _ in stdin.readline().rstrip().split()]
a, ab, b = 0, 0, 0
for p in P:
    if p <= A:
        a += 1
    elif A < p <= B:
        ab += 1
    elif B < p:
        b += 1
print(min(a, ab, b))

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    set<int> a;
    rep(i, m) {
        int A;
        cin >> A;
        a.insert(A);
    }
    int ans = 105;
    int r = x + 1;
    int ansr = 0;
    while(r < n){
        if(a.find(r) != a.end()) ansr++;
        r++;
    }
    ans = min(ans, ansr);

    int l = x - 1;
    int ansl = 0;
    while(l > 0){
        if(a.find(l) != a.end()) ansl++;
        l--;
    }
    ans = min(ans, ansl);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a,b;
	cin >>a>>b;
	if(1<=a&&a<=20&&1<=b&&b<=20) {
	if(1<=a&&a<=9&&1<=b&&b<=9) {
		cout<<a*b;
	}
	else cout <<-1;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
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(){
  string s, t;
  cin >> s >> t;

  ll n = s.size();
  ll tlen = t.size();
  string ans = "~";
  for(ll i = 0; i < n - tlen + 1; i++){
    string ss = s;
    bool ok = true;
    for(ll j = i; j < i + tlen; j++){
      if(ss[j] == t[j - i]) continue;
      else if(ss[j] == '?') ss[j] = t[j - i];
      else ok = false;
    }
    if(ok){
      for(ll j = 0; j < n; j++){
        if(ss[j] == '?') ss[j] = 'a';
      }
      ans = min(ans, ss);
    }
  }
  if(ans == "~") cout << "UNRESTORABLE" << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;
const int SIZE=1000005;
const LL INF=1<<30;
const LL p=7+1e9;
LL N,M;
bool able[SIZE][2];
int main(){
	int a,b,ma,mb;
	cin >> N >> M;
	REP(i,M){
		cin >> a >> b;
		ma=min(a,b);
		mb=max(a,b);
		if(ma==1)
			able[mb][0]=true;
		if(mb==N)
			able[ma][1]=true;
	}
	able[1][0]=true;
	able[N][1]=true;
	FOR(i,1,N+1){
		if(able[i][0] && able[i][1]){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 1000000

int H, A[MAX + 1];

void maxHeapify(int i){
  int l = 2 * i;
  int r = 2 * i + 1;
  int largest, tmp;

  if(l <= H && A[l] > A[i]) largest = l;
  else  largest = i;

  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

int main(void){
  int i;

  scanf("%d", &H);

  for(i = 1; i <= H; i++){
    scanf("%d", &A[i]);
  }

  for(i = H / 2; i >= 1; i--) maxHeapify(i);

  for(i = 1; i <= H; i++){
    printf(" %d", A[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <utility>

using namespace std;

int main(){
    int N,M,X;
    int left=0, right=0;
    cin >> N >> M >> X;
    vector<int>A(M);
    for(int i = 0; i < M; i++){
        cin >> A[i];
        if(X > A[i]){
            left++;
        }else{
            right++;
        }
    }
    cout << min(left,right) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    vector<string> s;
    for(int i = 0; i < n; i++)
    {
        string tmp = ""; 
        tmp += a[i];
        tmp += b[i];
        tmp += c[i];
        s.push_back(tmp);
    }
    int ans = 0;
    for(int i = 0; i < s.size(); i++)
    {
        set<char> st;
        for(int j = 0; j < 3; j++)
        {
            st.insert(s[i][j]);
        }
        int sz = st.size() - 1;
        ans += sz;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int sum(int a,int b)
{
    int ans=0;
    for(int i=0;i<=b;i++){
        if(a>0)
        ans+=a;
        --a;
    }
    return ans;
}
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    int socket=1,ans=0;
    while(socket<b)
    {
        socket--;
        socket+=a;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
import sys

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())

    ud = '#' * (W+2)
    print(ud)
    for _ in range(H):
        a = input().strip()
        print('#' + a + '#')
    print(ud)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include<math.h>
#include<stdio.h>
using namespace std;

int main()
{

   double a,b,c;
   double x;
   cin>>a>>b>>c;
   if(c<=(a*a*b)/2)
   {
       double l=(c/a)*2/b;
       x=atan(b/l*(1.0));
   }
   else
   {
       double l=((c/a)*2)/a-b;

       x=atan((b-l)*1.0/a);

   }


   //double a=atan(1);
   printf("%.10f",(x*360)/(2.0*M_PI));
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 100005

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  int X,Y,i,ans=0;
  scanf("%d%d",&X,&Y);
  if(X==1)ans+=300000;
  if(X==2)ans+=200000;
  if(X==3)ans+=100000;
  if(Y==1)ans+=300000;
  if(Y==2)ans+=200000;
  if(Y==3)ans+=100000;
  if(X==1&&Y==1)ans+=400000;

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


Measured memory_bytes: 128
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=[]
ans=0
for i in range(a):
  s=ii()
  h=[list(mi()) for _ in range(s)]
  l.append(h)
for k in range(2**a):
  lst=[]
  for p in range(a):
    if k>>p & 1:
      lst.append(p)
  t=True
  for aa in lst:
    for m in l[aa]:
      if m[1]==0:
        if m[0]-1 in lst:
          t=False
          break
      else:
        if not m[0]-1 in lst:
          t=False
          break
  if t:
    ans=max(ans,len(lst))
print(ans)

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

using namespace std;

#define fo(i,n) for(int i=0; i<n; i++)
#define Fo(i,k,n) for(int i=k; i<n; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int n;
vvi dp,ai;

void printt(){
    dp[1][1] = ai[1][1];
    dp[1][2] = ai[1][2];
    dp[1][3] = ai[1][3];
    Fo(i,2,n+1){
        dp[i][1] = max(dp[i-1][2]+ai[i][1],dp[i-1][3]+ai[i][1]);
        dp[i][2] = max(dp[i-1][1]+ai[i][2],dp[i-1][3]+ai[i][2]);
        dp[i][3] = max(dp[i-1][2]+ai[i][3],dp[i-1][1]+ai[i][3]);
    }
    cout<<max(max(dp[n][1],dp[n][2]), dp[n][3])<<endl;
}

void take_inp() {
    cin>>n;
    ai.resize(n+1,vi(4,0));
    dp.resize(n+1,vi(4,0));
    fo(i,n) {
        int a,b,c;
        cin>>a>>b>>c;
        ai[i+1][1] = a;
        ai[i+1][2] = b;
        ai[i+1][3] = c;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    take_inp();
    printt();
    return 0;
}

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

const int mod = 1e9+7;
const int INF = 2000000;

int main() {
    
    int K,N;
    cin >> K >> N;
    int A[N+1];
    rep(i,N) cin >> A[i];
    A[N] = A[0]+K;
    int dist[N];
    rep(i,N) {
        dist[i] = A[i+1]-A[i];
    }
    int ans = K;
    rep(i,N){
        ans = min(ans, K-dist[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define show(x) cerr << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define pi  pair    <int,int>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define OO  (ll)1e18
#define EPS 1e-9
using namespace std;
using namespace __gnu_pbds;
void ONLINE__JUDGE();

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
pii swapii( pii pr ){ return { pr.S , pr.F }; }
ll binEXP( ll x , ll pw , ll MOD = LLONG_MAX );
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 1e5 + 7;

ll x , dp[MAX][4];
vector < pair < int , pi >> vec;

ll go( ll i , ll prev = 0 ){
    if ( i == x ) return 0;

    ll& ret = dp[i][prev];
    if ( ~ret ) return ret;

    ll ans = -1*OO;
    if ( prev != 1 ) ans = max( ans , go(i+1 , 1) + vec[i].F   );
    if ( prev != 2 ) ans = max( ans , go(i+1 , 2) + vec[i].S.F );
    if ( prev != 3 ) ans = max( ans , go(i+1 , 3) + vec[i].S.S );
    return ret = ans;
}
int main()
{
    FASTIO //ONLINE__JUDGE();

    cin >> x; vec.resize(x); mem( dp , -1 );
    for ( auto& i : vec ) cin >> i.F >> i.S.F >> i.S.S;
    cout << go(0);
    return 0;
}

void ONLINE__JUDGE()
{
    #ifndef ONLINE_JUDGE
    freopen( "inp.c"         , "r" , stdin  );
    //freopen( "OutPut.txt"   , "w" , stdout );
    #endif // ONLINE_JUDGE
}

ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }


Measured memory_bytes: 13952
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

import math

def sol():
    N = int(input())
    engine = [tuple(map(int, input().split())) for _ in range(N)]

    ans = 0

    for direct in range(0, 1000):
        direct = 2 * math.pi / 999 * direct
        u, v = math.cos(direct), math.sin(direct)

        length = [0, 0]
        for x, y in engine:
            if u * x + v * y >= 0:
                length[0] += x
                length[1] += y

        ans = max(ans, length[0]**2 + length[1]**2)

    print(ans**0.5)

sol()

Measured memory_bytes: 3384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;
/*
 a[1] = (ans[1] + ans[2]) / 2;
 a[2] = (ans[2] + ans[3]) / 2;
 a[3] = (ans[3] + ans[1]) / 2;
 */
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<ll>ans(n);
    for(int i = 0; i < n; i++){
        ans[0] += (i % 2 == 0) ? a[i] : -a[i];
    }
    for(int i = 1; i < n; i++){
        ans[i] = a[i-1] * 2 - ans[i-1];
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << " \n"[i == n - 1];
    }
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e3+23;
char a[N][N];

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

struct cell {
  int y, x, c;
};

queue<cell> q;

void solve() {
  int h, w; scanf("%d%d", &h, &w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      scanf(" %c", a[i]+j);
      if (a[i][j] == '#') q.push({i, j, 0});
    }
  }
  int ans = 0;
  while (!q.empty()) {
    const auto p = q.front(); q.pop();
    ans = max(ans, p.c);
    for (int i = 0; i < 4; ++i) {
      if (p.y+dy[i] < 0 || p.y+dy[i] >= h || p.x+dx[i] < 0 || p.x+dx[i] >= w) continue;
      //printf("%d %d\n", p.y+dy[i], p.x+dx[i]);
      if (a[p.y+dy[i]][p.x+dx[i]] == '#') continue;
      a[p.y+dy[i]][p.x+dx[i]] = '#';
      q.push({p.y+dy[i], p.x+dx[i], p.c+1});
    }
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 16484
import numpy as np

n, k = map(int, input().split())
ans = 0
for m in range(k, n):
    nm = n - m
    sb = m + 1
    s = nm // sb
    p = s + 1 if m else s
    ps = sb
    for d in range(s, 0, -1):
        ds = nm // d + 1
        co = ds - ps
        ans += co * p
        ps = ds
        p -= 1
    ans += n + 1 - ps

    # ds = [nm // d + 1 for d in range(s, 0, -1)]
    # ds = [sb] + ds + [n + 1]
    # # print(m, nm, sb, s, ds)
    # dd = np.diff(ds)
    # pd = np.arange(s + 1, 0, -1) if m else np.arange(s, -1, -1)
    # # print(dd, pd, dd * pd, sum(dd * pd))
    # ans += sum(dd * pd)
print(ans)


Measured memory_bytes: 14504
<?php
[$h1, $m1, $h2, $m2, $k] = ints();
echo ($h2-$h1)*60+$m2-$m1-$k;

function str(){return trim(fgets(STDIN));}
function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$M = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      if($both == 0){
        $G[$a][] = $b;
      }elseif($both == 1){
        $G[$a][] = $b;
        $G[$b][] = $a;
      }else{
        $G[$b][] = $a;
      }
    }else{
      list($a, $b, $d) = $values;
      if($both == 0){
        $G[$a][] = [$b, $d];
      }elseif($both == 1){
        $G[$a][] = [$b, $d];
        $G[$b][] = [$a, $d];
      }else{
        $G[$b][] = [$a, $d];
      }
    }
  }
  return $G;
}


Measured memory_bytes: 16248
/***************************************************
 * Problem Name : B.cpp
 * Problem Link :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2020-05-03
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.rbegin(), v.rend())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm ( ll a, ll b ) {
    return ( a / __gcd ( a, b ) ) * b;
}
/************************************ Code Start Here ******************************************************/
int main () {
    __FastIO;
    //~ cout << setprecision (10) << fixed;
    int n, k;
    cin >> n >> k;
    set<int>st;
    while(k--){
		int d, x;
		cin >> d;
		while(d--){
			cin >> x;
			st.insert(x);
		}
	}
	cout << n - (int)st.size() << "\n";
    return 0;
}


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

string ss;
int not_[2] = {1,0};
int and_[2][2] = { {0,0},{0,1}};
int or_[2][2] = { {0,1},{1,1}};
int imp_[2][2] = { {1,1},{0,1}};
int bit;

int dfs(const string& formula,int& pos) {
    //cout<<formula<<","<<pos<<endl;
    int ret;
    if(formula[pos] =='T') ret = 1;
    else if(formula[pos] =='F') ret = 0;

    else if(formula[pos] == '-') return not_[dfs(formula,++pos)];
    else if('a' <= formula[pos] && formula[pos] <= 'k') ret = (bit >> (formula[pos]-'a')) &1;
    else if(formula[pos] == '(') {
        ret = dfs(formula, ++pos);
        if(formula[pos] == '+') ret = or_[ret][dfs(formula,++pos)];
        else if(formula[pos] == '*') ret = and_[ret][dfs(formula,++pos)];
        else if(formula[pos] == '-') {
            pos++;
            ret = imp_[ret][dfs(formula,++pos)];
        }
    }
    pos++;
    return ret;

}

void solve() {
    string l = ss.substr(0,ss.find("="));
    string r = ss.substr(ss.find("=")+1);
    int pos=0;
    bool flag = true;
    for(bit = 0; bit < (1<<11); bit++) {
        pos = 0;
        int tmp1 = dfs(l,pos);
        pos = 0;
        int tmp2 = dfs(r,pos);
        if(tmp1!=tmp2) flag = false;
    }
    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main() {
    while(cin>>ss) {
        if(ss=="#") return 0;
        solve();
    }


    return 0;
}

Measured memory_bytes: 1220
package main

import "fmt"

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

func check() bool {
	if e-d <= k && e-c <= k && e-b <= k && e-a <= k {
		if d-c <= k && d-b <= k && d-a <= k {
			if c-a <= k && b-a <= k {
				return true
			}
		}
	}
	return false
}

func main() {
	fmt.Scan(&a, &b, &c, &d, &e, &k)
	if check() {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}


Measured memory_bytes: 512