akhauriyash/Code-Regression huggingface dataset:
//you**can**do**anything 
#include <bits/stdc++.h> 
#define ll long long
#define pk push_back		
const ll maxn=2e5+1;
using namespace std;   
void solve()
{
	
}

int main()
{

ll num = 0 ;
string s;
cin>>s;

for(int i=0 ;i<s.size() ;i++)
{
	num+=(s[i]-'0') ;
}

//cout<<num<<"\n";

if(num%9==0)
cout<<"Yes" ;
else
cout<<"No";

}

Measured memory_bytes: 3692
#include <climits>
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n+1);
  vector<int> balls(n+1, 0);

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

  for (int i=n; i>0; i--) {
    int sum = 0;
    for (int j=1; j*i <= n; j++) {
      sum += balls[j*i];
    }
    int rest = sum % 2;
    if (rest != a[i]) {
      balls[i] = 1;
    }
  }

  int count = 0;
  for (int b: balls) {
    if (b == 1) count++;
  }
  cout << count << endl;

  for (int i=1; i<=n; i++) {
    if (balls[i] == 1) {
      cout << i << " ";
    }
  }
  cout << endl;

  return 0;
}

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

#define int long long

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

int N, T;
int A[100000];

signed main() {
    cin >> N >> T;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int max_dif = 0, min_value = A[0];
    for (int i = 1; i < N; i++) {
        max_dif = max(max_dif, A[i] - min_value);
        min_value = min(min_value, A[i]);
    }
    int ans = 0;
    min_value = A[0];
    for (int i = 1; i < N; i++) {
        if (A[i] - min_value == max_dif) {
            ans++;
        }
        min_value = min(min_value, A[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	long long a[n]={0}, ans=0;
	for(long long i=0;i<n;i++){
		for(long long j=i;j<n;j+=(i+1)){
			a[j]++;
		}ans+=(a[i]*(i+1));
	}cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 81752
N, K = map(int, input().split())
A = list(map(int, input().split()))
A1 = set(A)
AN = {}
for a in A:
    if not a in AN:
        AN[a] = 0
    AN[a] += 1
AN = sorted(AN.items(), key=lambda x: x[1])
ans = 0
K1 = len(A1) - K
if K1 > 0:
    for k in range(K1):
        ans += AN[k][1]
    print(ans)
else:
    print('0')


Measured memory_bytes: 50380
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
  int a = 0;
  int b = 0;
  int c = 0;
  cin >> a >> b >> c;
  if((a == b && a != c)|| (a == c && a != b )|| (b == c && b != a)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if (a+b == c || a+c == b || b+c == a) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <cctype>

using namespace std;

int main(){
	double r;
	cin >> r;
	double ans = r*2*M_PI;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3760
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/
ll const MAX = 404;
ll a[MAX];
ll suma[MAX];
ll dp[MAX][MAX] = {};

int main() {
	ll n; cin >> n;
	suma[0] = 0;
	REP(i, 1, n) {
		cin >> a[i];
		suma[i] = suma[i - 1] + a[i];
	}
	REP(i, 1, n) {
		dp[i][i] = 0;
	}
	REP(l, 2, n) {
		REP(i, 1, n - l + 1) {
			ll j = i + l - 1;
			ll cnt = 1e18;
			REP(k, i, j - 1) {
				cnt = min(cnt, dp[i][k] + dp[k + 1][j]);
			}
			dp[i][j] = cnt + suma[j] - suma[i - 1];
		}
	}
	cout << dp[1][n] << endl;
}

Measured memory_bytes: 1536
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  trait Monoid[A]{
    def op(a1: A, a2: A): A
    def zero: A
  }

  type Per = List[Int]
  type Rot = Dice => Dice

  object DiceRoll extends Monoid[Rot]{

    def op(rot1: Rot, rot2: Rot): Rot = (dice: Dice) => rot2(rot1(dice))
    def zero: Rot = (dice: Dice)=>dice

    val north = List(2,6,3,4,1,5).map(_ - 1)
    val east = List(4,2,1,6,5,3).map(_ - 1)
    val ccw = List(1,4,2,5,3,6).map(_ - 1)

    def rot(perm: Per): Rot = (dice: Dice) => Dice(perm.map(dice.pip))

    def axial(f: Rot): List[Rot] = List(zero,f,op(f,f),op(op(f,f),f))

    def enumerateTop(f: Rot = zero, n: Int = 6): List[Rot] = {
      if(n<=0)List[Rot]()
      else if(n%2==0) f :: enumerateTop(op(f,rot(north)),n-1)
      else f :: enumerateTop(op(f,rot(east)),n-1)
    }

    def enumerate: List[Rot] = enumerateTop().flatMap( e => axial(rot(ccw)).map(op(e,_)))
  }

  case class Dice(pip: List[Int]){
    def ==(that: Dice): Boolean = pip.corresponds(that.pip)(_ == _)
  }


  def main(args: Array[String]): Unit = {
    val pip1 = readLine.split(" ").map(_.toInt).toList
    val pip2 = readLine.split(" ").map(_.toInt).toList
    val all1: List[Dice] = DiceRoll.enumerate.map(_(Dice(pip1)))
    println(if(all1.exists(_ == Dice(pip2))) "Yes" else "No")
  }
}

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

int main() {
    string s;
    cin >> s;
    
    if(s == "Sunny") cout << "Cloudy" << endl;
    if(s == "Cloudy") cout << "Rainy" << endl;
    if(s == "Rainy") cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include <numeric>

using namespace std;

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

    int X[M];
    for(int i = 0; i < M; i++){
        cin >> X[i];
    }
    sort(X, X+M);
    if(N >= M){
        cout << 0;
        return 0; 
    }
    int L[M-1];
    for(int i = 0; i < M-1; i++){
        L[i] = X[i+1] - X[i];
    }
    sort(L, L+M-1, greater<int>());
    cout << (X[M-1] - X[0]) - (accumulate(L, L + N -1, 0));

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  int m;
  cin >> m;
  vector<string> t(m);
  for(int i=0;i<m;i++){
    cin >> t[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int cnt=0;
    for(int j=0;j<n;j++){
      if(s[i]==s[j]){
        cnt++;
      }
    }
    for(int k=0;k<m;k++){
      if(s[i]==t[k]){
        cnt--;
      }
    }
    ans=max(ans,cnt);
  }
  cout << ans << endl;
}

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


int main(){

    int a,b;
    cin >> a >> b;
    int ans = 0;

    for(int i = a;i <= b;i++){
        //cout << i << endl;
        string s = to_string(i);
        //cout << s << endl;
        string t = s;
        reverse(t.begin(),t.end());
        if(s==t){
            ans++;
            //cout << s << " " << t << endl;
        }

    }
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fit(x) for(auto it=x.begin();it!=x.end();++it)
#define se second
#define mp make_pair
#define ALP "abcdefghijklmnopqrstuvwxyz"
#define nline cout<<"\n"
#define rep(i,x) for(i=0;i<x;++i)
#define repr(i,a,b) for(i=a;i<=b;++i)
#define mi2 500000004
#define mi3 333333336
#define MOD 1000000007
#define N 1000005
#define pll pair<ll,ll>
#define Vll vector<ll>
#define W(t) while(t--)
#define modsum(a,b,M) (a%M + b%M)%M
#define modsub(a,b,M) (a%M - b%M + M)%M
#define modmul(a,b,M) (a%M * b%M)%M
#define moddiv(a,b,M) (a%M * modinv(b,M)%M)%M
using namespace std;
ll powermod(ll x,ll n,ll M)
{
	ll result=1;
	while(n>0)
	{
	  if(n % 2 ==1)
	    result=(result * x)%M;
	  x=(x*x)%M;
	  n=n/2;
	}
	return result;
}
vector<ll> readll() {
	cin>>ws;
	vector<ll> v;
	string input;
	getline(cin, input);
	cout<<input;
	istringstream is(input);
	ll num;
	while(is>>num) v.pb(num);
	return v;
}
ll modinv(ll n,ll p) {
	return powermod(n,p-2,p);
}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[1000005],invf[1000005];
void facmod(ll n,ll M) {
	ll i;
	fact[0]=fact[1]=1;
	for(i=2;i<=n;++i) {
		fact[i]=((fact[i-1])%M * (i%M))%M;
	}
	invf[n]=modinv(fact[n],M);
	for (i=n-1;i>=0;--i){
		invf[i]=invf[i+1]*(i+1);
		invf[i]%=M;
	}
}
/*****
ll T=0;
ll p[200005], d[200005];
ll tin[200005], tout[200005];
vector<ll> g[200005];

void dfs(ll v, ll par = 1, ll dep = 0) {
	p[v] = par;
	d[v] = dep;
	tin[v] = T++;
	for (auto to : g[v]) {
		if (to == par) continue;
		dfs(to, v, dep + 1);
	}
	tout[v] = T++;
}
****/
void solve() {
	ll n,k,i;
	cin>>k>>n;
	ll a[n+4];
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	ll dif=0;
	repr(i,1,n-1) dif=max(dif,a[i]-a[i-1]);
	dif = max(dif,k-(a[n-1]-a[0]));
	cout<<k-dif;
}
int main() {
  	fastio;
	ll t=1;
	//cin>>t;
	W(t) {
		solve();
	}
	
  	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int w;
	cin>>w;
	for(int i=0;i<s.size();i+=w)
		cout<<s[i];	
	return 0;
	
}

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

int N, a, b;
ll D;
ll ans;
P p[100000];
P xya[100000];
P yxa[100000];
set<P> S;
set<P> xy, yx;

void dfs(P v) {
	S.insert(v);
	ll x = v.first, y = v.second;
	ll d[2] = { D, -D };
	vector<P> check;
	for(int i = 0; i < 2; i++) {
		P s(x + d[i], y - D), t(x + d[i], y + D);
		for(auto it = xy.lower_bound(s); it != xy.end() && *it <= t; ++it) {
			check.push_back(*it);
		}
		ans += upper_bound(xya, xya + N, t) - lower_bound(xya, xya + N, s);
	}
	for(int i = 0; i < 2; i++) {
		P s(y + d[i], x - D), t(y + d[i], x + D);
		for(auto it = yx.lower_bound(s); it != yx.end() && *it <= t; ++it) {
			check.push_back(P(it->second, it->first));
		}
		ans += upper_bound(yxa, yxa + N, t) - lower_bound(yxa, yxa + N, s);
		if(binary_search(yxa, yxa + N, s)) ans--;
		if(binary_search(yxa, yxa + N, t)) ans--;
	}

	for(auto c : check) {
		xy.erase(P(c.first, c.second));
		yx.erase(P(c.second, c.first));
	}
	for(auto c : check) {
		if(!S.count(c)) {
			dfs(c);
		}
	}
}

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

	cin >> N >> a >> b;
	a--, b--;
	for(int i = 0; i < N; i++) {
		ll x, y;
		cin >> x >> y;
		ll xx = x + y, yy = x - y;
		p[i] = P(xx, yy);
		xya[i] = p[i];
		yxa[i] = P(yy, xx);
		if(i != a) {
			xy.insert(p[i]);
			yx.insert(P(yy, xx));
		}
	}
	sort(xya, xya + N);
	sort(yxa, yxa + N);

	D = max(abs(p[a].first - p[b].first), abs(p[a].second - p[b].second));
	dfs(p[a]);

	cout << ans / 2 << endl;
}

Measured memory_bytes: 27136
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int n, t,cost = 1001;
  cin >> n >> t;
  vector<vector<int>> v(n,vector<int>(2,0));
  r(i,n){
    cin >> v.at(i).at(0) >> v.at(i).at(1);
    if(v.at(i).at(1)<=t){
      if(v.at(i).at(0)<cost) cost = v.at(i).at(0);
    }
  }
  if(cost == 1001) cout << "TLE" << endl;
  else cout << cost << endl;
}

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

typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
#define END '\n'

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

template <class T>
inline void Write(T x)
{
    if (x < 0)
        putchar('-'), Write(x);
    if (x > 9)
        Write(x / 10);
    putchar(x % 10 + '0');
}
void change(vector<int>&cur){
	sort(cur.begin(),cur.end());
	reverse(cur.begin(),cur.end());
}

int main()
{
    unsigned int x, y, a, b, c,k;
    cin>>x>>y>>a>>b>>c;
    vector<int> r(a+1),g(b+1),temp;
    for(int i=0;i<a;++i) Read(r[i]);
    for(int i=0;i<b;++i) Read(g[i]);
    change(r);change(g);
    for(int i=0;i<x;++i) temp.emplace_back(r[i]);
    for(int i=0;i<y;++i) temp.emplace_back(g[i]);
    for(int i=0;i<c;++i) cin>>k,temp.emplace_back(k);
    change(temp);
    LONG ans=0;
    for(int i=0;i<x+y;++i) ans+=temp[i];
    cout << ans;
    return 0;
}


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

  
  
int32_t main() 
{
      int k,n,sum=0;
      cin>>k>>n;
      int i,a[n];
      for(i=0;i<n;i++)
      {
            cin>>a[i];
            sum+=a[i];
      }
      if((k-sum)>=0)
      cout<<k-sum<<endl;
      else
      cout<<-1<<endl;
      

	return 0;
}


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

using namespace std;

int main( ) {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,a,b,c,d;
	t = 1;
	while(t--) {
	 cin >> a >> b >> c >> d;
	 cout << max(a * b, c * d) << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxs 200202
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;

int main()
{
    int a,b,c,d;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        if(a>c&&b>d)
        {
            swap(a,c);
            swap(b,d);
        }

        if(c>b)
            puts("0");
        else {
            printf("%d\n",min(b,d)-max(a,c));
        }
    }
    return 0;
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == W == 0:
        break
    for i in range(H):
         if i%2 == 0:
             print("#."*(W//2),"#"*(W%2),sep="")
         elif i%2!=0:
             print(".#"*(W//2),"."*(W%2), sep="")

    print("")


Measured memory_bytes: 5616
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

struct Dsu {
	vector < int > par, sz;

	Dsu(int n) {
		par.resize(n + 1);
		iota(par.begin(), par.end(), 0);
		sz.resize(n + 1, 1);
	}

	int find(int x) {
		return (x == par[x] ? x : par[x] = find(par[x]));
	}

	void merge(int a, int b) {
		a = find(a); 
		b = find(b);
		if (sz[a] < sz[b]) {
			swap(a, b);
		}
		sz[a] += sz[b];
		par[b] = a;
	}

	bool same(int a, int b) {
		return find(a) == find(b);
	}
};

int n, m;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	cin >> n >> m;
	vector < pii > edges(m);
	for (auto &edge: edges) {
		cin >> edge.first >> edge.second;
	}
	vector < ll > res(m);
	ll curr = (1ll * n * (n - 1)) / 2;
	Dsu g(n);
	for (int i = m - 1; i >= 0; --i) {
		res[i] = curr;
		if (!g.same(edges[i].first, edges[i].second)) {
			curr -= (1ll * g.sz[g.find(edges[i].first)] * g.sz[g.find(edges[i].second)]) / 1;
			g.merge(edges[i].first, edges[i].second);
		}
	}
	for (auto &el: res) {
		cout << el << "\n";
	}
}

Measured memory_bytes: 3712
#include <climits>
#include <cstdio>
#include <cstdint>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

using i32 = int32_t;
using u32 = uint32_t;
using f32 = float;
using f64 = double;
using i64 = int64_t; 
using u64 = uint64_t; 

#define SELECTER(_1, _2, _3, _4, _5, _6, _7, _8, SELECT, ...) SELECT

#define _FC1(func, type, _1)      func(type, _1);
#define _FC2(func, type, _1, ...) func(type, _1); _FC1(func, type, __VA_ARGS__);
#define _FC3(func, type, _1, ...) func(type, _1); _FC2(func, type, __VA_ARGS__);
#define _FC4(func, type, _1, ...) func(type, _1); _FC3(func, type, __VA_ARGS__);
#define _FC5(func, type, _1, ...) func(type, _1); _FC4(func, type, __VA_ARGS__);
#define _FC6(func, type, _1, ...) func(type, _1); _FC5(func, type, __VA_ARGS__);
#define _FC7(func, type, _1, ...) func(type, _1); _FC6(func, type, __VA_ARGS__);
#define _FC8(func, type, _1, ...) func(type, _1); _FC7(func, type, __VA_ARGS__);

#define _FCN(func, type, ...) SELECTER(__VA_ARGS__, _FC8, _FC7, _FC6, _FC5, _FC4, _FC3, _FC2, _FC1)(func, type, __VA_ARGS__);

constexpr const char *type2fmt(const char *fmt) {
  if(strcmp(fmt, "i32")) return "%d";
  if(strcmp(fmt, "u32")) return "%u";
  if(strcmp(fmt, "f32")) return "%f";
  if(strcmp(fmt, "f64")) return "%lf";
  if(strcmp(fmt, "i64")) return "%lld";
  if(strcmp(fmt, "u64")) return "%llu";
  if(strcmp(fmt, "char*")) return "%s";
  return "";
}

#define _R(type, _1) type _1; { type _t; scanf(type2fmt(#type), &_t); _1 = _t; }
#define _P(type, _1) { const type _t = (_1); printf(type2fmt(#type), _t); putchar('\n'); }

#define RI(...)   _FCN(_R, i32, __VA_ARGS__);
#define RUI(...)  _FCN(_R, u32, __VA_ARGS__);
#define RF(...)   _FCN(_R, f32, __VA_ARGS__);
#define RD(...)   _FCN(_R, f64, __VA_ARGS__);
#define RLL(...)  _FCN(_R, i64, __VA_ARGS__);
#define RULL(...) _FCN(_R, u64, __VA_ARGS__);

#define PI(...)   _FCN(_P, i32, __VA_ARGS__);
#define PUI(...)  _FCN(_P, u32, __VA_ARGS__);
#define PF(...)   _FCN(_P, f32, __VA_ARGS__);
#define PD(...)   _FCN(_P, f64, __VA_ARGS__);
#define PLL(...)  _FCN(_P, i64, __VA_ARGS__);
#define PULL(...) _FCN(_P, u64, __VA_ARGS__);
#define PS(...)   _FCN(_P, char*, __VA_ARGS__);

#define REP(n) for (int _i = 0; _i < n; _i++)

const u64 mod = 1000000007;

int main() {
  RI(A, B, C, X);

  i32 t = 0;
  for (i32 a = 0; a <= A; a++) {
    for (i32 b = 0; b <= B; b++) {
      for (i32 c = 0; c <= C; c++) {
        t += (500 * a + 100 * b + 50 * c) == X;
      }
    }
  }

  PI(t);
}


Measured memory_bytes: 256
s=input()

numdict={}
c=set(s)
for i in c:
    numdict[i]=[]

for i in range(len(s)):
    numdict[s[i]].append(i)

cnt=len(s)
for i in c:
    x=0
    #print(i)
    x=max(numdict[i][0],len(s)-numdict[i][-1]-1)
    for j in range(len(numdict[i])-1):
        x=max(x,numdict[i][j+1]-numdict[i][j]-1)
        #print(x)
    #print("final",x)
    cnt=min(cnt,x)
print(cnt)

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UF{
    vector<int>par,sz;
    void init(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N,M;
vpint es[1000000];

vint glis[200000];
vint vlis[100000];

int table[1000000];
int table2[1000000];

const int INF=1001001001;
int dist[100000];
signed main(){
    scanf("%lld%lld",&N,&M);
    rep(i,M){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        a--;b--;c--;
        es[c].pb(pint(a,b));
    }

    int cur=0;

    for(int c=0;c<1000000;c++){
        if(es[c].size()==0)continue;
        vint vs;
        rep(i,es[c].size()){
            vs.pb(es[c][i].fi);
            vs.pb(es[c][i].se);
        }
        sort(all(vs));
        vs.erase(unique(all(vs)),vs.end());
        rep(i,vs.size()){
            table[vs[i]]=i;
        }
        UF uf;
        uf.init(vs.size());
        rep(i,es[c].size()){
            int a=table[es[c][i].fi];
            int b=table[es[c][i].se];
            uf.unite(a,b);
        }
        for(int i=0;i<vs.size();i++){
            if(uf.find(i)==i){
                table2[i]=cur;
                cur++;
            }
        }

        for(int i=0;i<vs.size();i++){
            int p=uf.find(i);
            glis[table2[p]].pb(vs[i]);
            vlis[vs[i]].pb(table2[p]);
        }
    }

    fill_n(dist,N,INF);
    dist[0]=0;
    vint vec;
    vec.pb(0);

    while(vec.size()){
        vint nvec;
        int t=dist[vec[0]];
        vint hoge;
        for(auto v:vec){
            for(auto u:vlis[v]){
                hoge.pb(u);
            }
        }
        sort(all(hoge));
        hoge.erase(unique(all(hoge)),hoge.end());
        for(auto g:hoge){
            for(auto v:glis[g]){
                if(dist[v]<=t+1)continue;
                dist[v]=t+1;
                nvec.pb(v);
            }
        }
        vec=nvec;
    }

    if(dist[N-1]==INF){
        cout<<-1<<endl;
    }
    else{
        cout<<dist[N-1]<<endl;
    }
}


Measured memory_bytes: 53624
ops = ["+", "-"]

def calc(op, a, b):
    if op == "+":
        return a + b
    else:
        return a - b

def solve(a, b, c, d):
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                if calc(op3, calc(op2, calc(op1, a, b), c), d) == 7:
                    print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                    return

a, b, c, d = map(int, list(input()))
solve(a, b, c, d)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> num(n);

	for(int i=0; i<n; i++){
		cin >> num.at(i);
	}
	sort(num.begin(), num.end());

	int tmp=0;
	int cnt=0;
	int ans=0;
	for(int i=0; i<n; i++){
		if(num.at(i)!=tmp){
			if(cnt>tmp){
				ans = ans+cnt-tmp;
			}else if(cnt<tmp){
				ans += cnt;
			}
			tmp = num.at(i);
			cnt=1;
		}else{
			cnt++;
		}
	}
	if(cnt){
		if(cnt>tmp){
			ans = ans+cnt-tmp;
		}else if(cnt<tmp){				
			ans += cnt;	
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                   \
  ifstream in("atcoder-problems/keyence2019_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<ll> a(N);
  vector<ll> b(N);
  vector<ll> c(N);
  ll totalA = 0, totalB = 0;
  rep(i, N) {
    cin >> a[i];
    totalA += a[i];
  }
  rep(i, N) {
    cin >> b[i];
    totalB += b[i];
  }
  if (totalA < totalB) {
    cout << -1 << endl;
    return 0;
  }

  ll ans = 0;
  ll minus = 0;
  rep(i, N) {
    c[i] = a[i] - b[i];
    if (c[i] < 0) {
      ans++;
      minus += c[i];
    }
  }
  sort(c.rbegin(), c.rend());

  for (auto plus : c) {
    if (minus >= 0) break;
    minus += plus;
    ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 5560
#include <bits/stdc++.h>
#define N 5002
using namespace std;
int c[N][201],n,m,i,j,top,R[N],st[N],L[N];
long long f[N],dp[N][N],kq;
int main()
{
    //freopen("ntu.inp","r",stdin);
    //freopen("ntu.out","w",stdout);
    cin>>n>>m;
    for(i=2;i<=n;i++) { cin>>f[i]; f[i]+=f[i-1]; }
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++) cin>>c[i][j];
    for(j=1;j<=m;j++)
    {
        top=0; st[top]=0;
        for(i=1;i<=n;i++)
        {
            while(top>0 && c[st[top]][j]<c[i][j]) top--;
            L[i]=st[top]+1;
            st[++top]=i;
        }
        top=0; st[top]=n+1;
        for(i=n;i>=1;i--)
        {
            while(top>0 && c[st[top]][j]<=c[i][j]) top--;
            R[i]=st[top]-1;
            st[++top]=i;
        }
        for(i=1;i<=n;i++)
        {
            dp[L[i]][R[i]]+=c[i][j];
            dp[i+1][R[i]]-=c[i][j];
            dp[L[i]][i-1]-=c[i][j];
          //  cerr<<L[i]<<" "<<R[i]<<'\n';
        }
       // cerr<<'\n';
    }
    for(i=1;i<=n;i++)
        for(j=n;j>=i;j--)
        {
            dp[i][j]+=dp[i-1][j]+dp[i][j+1]-dp[i-1][j+1];
         //   gl[i][j]+=gl[i-1][j]+gl[i][j+1]-gl[i-1][j+1];
           // gr[i][j]+=gr[i-1][j]+gr[i][j+1]-gr[i-1][j+1];
            kq=max(kq,dp[i][j]-(f[j]-f[i]));
        }
    cout<<kq;
}


Measured memory_bytes: 199680
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,d;
  cin >> n >> d;
  int r= 2*d+1;
  int c = n%r;
  int k = n/r;
  if(c)
    cout << k+1;
  else
    cout << k;
}

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

using namespace std; 

int dp[3][100005]; 

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

	for(int i = 0; i < n; i++){
		for(int j = 0; j < 3; j++){
			cin >> dp[j][i]; 
		}
	}
 

	for(int i = 1; i < n; i++){
		for(int j = 0; j < 3; j++)
			dp[j][i] += max(dp[(j + 1) % 3][i - 1], dp[(j + 2) % 3][i - 1]); 
	}

	cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1]))  << endl; 
}

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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N,M;
int A[2000],B[2000];

int dp[2222][2222][2];

signed main(){
    string S,T;
    cin>>N>>M>>S>>T;
    reverse(all(S));
    reverse(all(T));
    rep(i,N)A[i]=S[i]!='I';
    rep(i,M)B[i]=T[i]!='I';
    rep(i,N+1)rep(j,M+1)dp[i][j][0]=-1145141919;


    int ans=0;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=M;j++){
            for(int k=0;k<2;k++){
                if(i){
                    if(A[i-1]==k)chmax(dp[i][j][k],dp[i-1][j][1-k]+1);
                    //chmax(dp[i][j][k],dp[i-1][j][k]);
                }
                if(j){
                    if(B[j-1]==k)chmax(dp[i][j][k],dp[i][j-1][1-k]+1);
                    //chmax(dp[i][j][k],dp[i][j-1][k]);
                }
                if(k==0)chmax(ans,dp[i][j][k]);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70868
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

template<typename T> T gcd(T a, T b) {
	if (a < b) return gcd(b, a);
	T r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
// 最小公倍数
template<typename T> inline T lcm(T a, T b) { return a * b / gcd(a, b); }

signed main() {
	LL a, b;
	cin >> a >> b;

	LL ans = lcm(a, b);
	col(ans);
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF INT_MIN 
#define INF INT_MAX 
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<":"<<' '; 
 int h,w,k;
 cin>>h>>w>>k;int ar[h][w];int br[h][w];
 for(int i=0;i<h;i++)
 {
     string s;
     cin>>s;
     for(int i1=0;i1<w;i1++)
     {
         ar[i][i1]=s[i1]-'0';
     }
 }
 for(int i=0;i<w;i++)
 {   br[h-1][i]=ar[h-1][i];
     for(int j=h-2;j>=0;j--)br[j][i]=br[j+1][i]+ar[j][i];
 }
 int fans=INF;
 for(int i=0;i<pow(2,h-1);i++)
 {   VI re;
     for(int j=0;j<h-1;j++)if((i>>j)&1)re.pb(j+1);
     sort(all(re));
     VI sum(re.size()+1,0);int anss=0;int ff=0;
     for(int i1=0;i1<w;i1++)
     {   int last=0;int ans=1;
         for(int it=0;it<re.size();it++)
         {
             if(br[last][i1]-br[re[it]][i1]+sum[it]>k)ans=0;
             sum[it]=br[last][i1]-br[re[it]][i1]+sum[it];
             //if(i==4)CK3(br[last][i1],br[it][i1],sum[it]);
             last=re[it];
         }
         if(br[last][i1]+sum[re.size()]>k)ans=0;
             sum[re.size()]=br[last][i1]+sum[re.size()];
         if(ans==0)
         {anss++;int last=0;
          for(int it=0;it<re.size();it++)
         {
             
             sum[it]=br[last][i1]-br[re[it]][i1];
             if(sum[it]>k)ff=-1;
             last=re[it];
         } 
         sum[re.size()]=br[last][i1];
         if(sum[re.size()]>k)ff=-1;
         }
         if(ff==-1)break;
         
    //if(i==4){for(int i11=0;i11<=re.size();i11++)cout<<sum[i11]<<" ";
     //cout<<endl;}
     }
     if(ff==-1)continue;
      //cout<<i<<" "<<re.size()<<" "<<anss<<endl;
         int mn=re.size();
         fans=min(fans,anss+mn);
     
 }
 cout<<fans<<endl;
}


return 0;
}





Measured memory_bytes: 384
# -*- coding: utf-8 -*-

n,m = map(int,input().split())
a = [0] * n
b = [0] * n
c = [[0,0] for i in range(n)]
for i in range(n):
    a[i],b[i] = map(int,input().split())
    c[i] = [a[i],b[i]]

c.sort()

drink = 0
price = 0

for i in range(len(c)):
    if drink + c[i][1] < m:
        drink += c[i][1]
        price += c[i][0] * c[i][1]
    else:
        price += c[i][0] * (m - drink)
        break

print(price)


Measured memory_bytes: 21676
#include <stdio.h>
#include <string.h>
#define N 1000

int max(int a, int b){
  if(a>=b) return a;
  if(b>=a) return b;
}

int lcs(char A[] ,char B[]){

  int m, n, i, j, maxans=0;
  int c[N+1][N+1];
  
  m = strlen(A);
  n = strlen(B);
  
  for(i=1; i<=m; i++){
    c[i][0] = 0;
  }
  for(j=1; j<=n; j++){
    c[0][j] = 0;
  }
  
  for(i=1; i<=m; i++){
    for(j=1; j<=n; j++){
      if(A[i-1] == B[j-1]){
	c[i][j] = c[i-1][j-1]+1;
      }
      else {
	c[i][j] = max(c[i-1][j], c[i][j-1]);
      }
      /*
      else if(c[i-1][j] >= c[i][j-1]){
	c[i][j] = c[i-1][j];
      }
      else{
	c[i][j] = c[i][j-1];
      }
      */
      maxans = max(maxans, c[i][j]);
    }
  }
  
  return maxans;
}

int main(){

  int n, i;
  char A[N+2], B[N+1];
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%s", A);
    scanf("%s", B);
    printf("%d\n", lcs(A, B));
  }
  
  return 0;
}

Measured memory_bytes: 4520
class DisjointSet:
    def __init__(self):
        self.rank = {}
        self.p = {}

    def makeSet(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if(self.rank[x] > self.rank[y]):
            self.p[y] = x
        else:
            self.p[x] = y
            if(self.rank[x] == self.rank[y]):
                self.rank[y] += 1

    def findSet(self, x):
        if(x != self.p[x]):
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]

from collections import Counter
N, K, L = map(int, input().split())

ds = DisjointSet()
ds2 = DisjointSet()
for i in range(N):
    ds.makeSet(i+1)
    ds2.makeSet(i+1)

for i in range(K):
    p, q = map(int, input().split())
    ds.unite(p, q)

for i in range(L):
    r, s = map(int, input().split())
    ds2.unite(r, s)

a = [(ds.findSet(i), ds2.findSet(i)) for i in range(1, N+1)]
c = Counter(a)

print(' '.join([str(c[i]) for i in a]))

Measured memory_bytes: 139480
#include <stdio.h>
int main(void){
	int a,b,c,d,e,f;
	while(scanf("%d%d",&a,&b) , a != 0){
		c = b - a;
		d = c % 500;
		e = (c % 1000 - d);
		f = c - d - e;
		printf("%d %d %d\n",d/100,e/500,f/1000);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll q;cin >> q;
  ll bsum = 0;
  priority_queue<ll> mi;
  priority_queue<ll, vector<ll> ,greater<ll>> ma;
  ll misum = 0;
  ll masum= 0;
  {
      ll tmp,a,bb;
      cin >> tmp >> a >> bb;
      mi.push(a);
      misum += a;
      bsum += bb;
  }
  rep(i,q-1){
      ll que; cin >> que;
      if(que==1){
          ll a,b;
          cin >> a >> b;
          bsum+=b;
          if(mi.size()==ma.size()){
              if(a<=ma.top()){
                  mi.push(a);
                  misum += a;
              }else{
                  ll mv = ma.top();
                  mi.push(mv);
                  masum -= mv;
                  misum += mv;
                  ma.pop();
                  ma.push(a);
                  masum += a;
              }
          }else{
              if(a<=mi.top()){
                  ll mv = mi.top();
                  ma.push(mv);
                  misum -= mv;
                  masum += mv;
                  mi.pop();
                  mi.push(a);
                  misum += a;
              }else{
                  ma.push(a);
                  masum += a;
              }
          }
      }else{
          ll pos = mi.top();
          ll ans = ((ll)mi.size()) * pos - misum + masum - ((ll)ma.size()) * pos + bsum;
          cout << mi.top() << " "  << ans << endl;;
      }
  }

}

Measured memory_bytes: 3828
#include <stdio.h>
int main(){
  int i, j, k, h, w, n, m, l, o, p[11], t, u, c[11][2], a[1005], e, f, g;
  char s[1001];
  scanf("%d%d%d",&h,&w,&k);
  m = h * w;
  for(i = 0; i < w; i++)
    a[i] = 0;
  for(i = 0; i < h; i++){
    scanf("%s",s);
    for(j = 0; j < w; j++){
      a[j] <<= 1;
      a[j] |= s[j] - '0';
    }
  }
  for(l = 0; l < (1 << (h - 1)); l++){
    o = l;
    u = 0;
    for(i = 0; i < h - 1; i++){
      p[i] = (o & 1);
      if(p[i]){
        c[u][0] = 0;
        c[u][1] = 0;
        u++;
      }
      o >>= 1;
    }
    c[u][0] = 0;
    c[u][1] = 0;
    f = 0;
    g = u;
    for(i = 0; (i < w) && (f == 0); i++){
      t = 0;
      for(j = 0;j < h; j++){
        c[t][1] += (a[i] >> j) & 1;
        if(c[t][1] > k){
          f = 1;
          break;
        }
        if(p[j] || (j == h - 1)){
          c[t][0] += c[t][1];
          if(c[t][0] > k){
            for(o = 0; o <= u; o++)
              c[o][0] =c[o][1];
            g++;
          }
          t++;
        }
      }
      for(j = 0; j <= u; j++)
        c[j][1] = 0;
    }
    if(!f)
      if(g < m)
        m = g;
  }
  printf("%d\n",m);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
vector<int>G[maxn];
char t[maxn];
bool vis[2][maxn];
void bfs(int s,bool is[])
{
    queue<int>P;
    P.push(s);
    is[s]=1;
    while(!P.empty())
    {
        int v=P.front();
        P.pop();
        for(int i=G[v].size()-1;i>=0;i--)
        {
            int u=G[v][i];
            if(is[u]==0)
            {
                is[u]=1;
                P.push(u);
            }
        }
    }
    for(int i=0;i<maxn;i++)
        G[i].clear();
}
int main()
{
    int n,a,b,c,d;scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    if(a>b)
        swap(a,b),swap(c,d);
    scanf("%s",t+1);
    int len=strlen(t+1);
    for(int i=a;i<=len;i++)
    {
        if(i+1<=len&&t[i+1]=='.')
            G[i].push_back(i+1);
        if(i+2<=len&&t[i+2]=='.')
            G[i].push_back(i+2);
    }
    bfs(a,vis[0]);
    for(int i=b;i<=len;i++)
    {
        if(i+1<=len&&t[i+1]=='.')
            G[i].push_back(i+1);
        if(i+2<=len&&t[i+2]=='.')
            G[i].push_back(i+2);
    }
    bfs(b,vis[1]);
    if(c<d)
    {
        if(vis[0][c]&&vis[1][d])
            printf("Yes\n");
        else
            printf("No\n");
    }
    else
    {
        bool flag=0;
        for(int i=b;i<=d;i++)
            if(vis[1][i]&&vis[0][i-1]&&vis[0][i+1])
                flag=1;
        if(flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 11520
n, m = map(int, input().split())
ab = [list(map(int,input().split())) for i in range(n)]
cd = [list(map(int,input().split())) for i in range(m)]

def manhattan(place, target):
	return abs(target[0] - place[0]) + abs(target[1] - place[1])
ans = [0] * n
for i in range(n):
	dmin = manhattan(ab[i],cd[0])
	for j in range(1,m):
		d = manhattan(ab[i],cd[j])
		if dmin > d:
			dmin = d
			ans[i] = j

for i in range(n):
	print(ans[i]+1)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
// ミント
const int mod = 1e9+7 ;
 // 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
}   c(200005);
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 
 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }


int main(){
   ll n ; cin>> n ;
   vector<ll> A(n) ;rep(i,n)  cin>>A[i] ;
   sort(A.begin(),A.end()) ;
   mint ans=0 ; 
   rep(i,n){
     mint k = A[i] ;
     mint pl = 0 ;
     
      pl = k*(modpow(2ll,n-1) +modpow(2ll,n-2) * (n-1-i) );
     
     ans += pl ;
   }
   ans *= modpow(2ll,n) ;
   cout<<ans<<endl ;
    return 0;
  }
   



Measured memory_bytes: 7992
def main():
    N, K = (int(i) for i in input().split())
    if K == 0:
        return print(N**2)
    ans = 0
    for b in range(K+1, N+1):
        ans += (b - K) * (N//b)
        if K <= N % b:
            ans += (N % b) - K + 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38768
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
const long long inf=1e9+7;
const long long mod=1e9+7;
const int64_t CYCLES_PER_SEC=2800000000;
//
inline uint32_t Xor128(){
	static uint32_t x=123456789;
	static uint32_t y=362436069;
	static uint32_t z=521288629;
	static uint32_t w=88675123;
	uint32_t t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct Timer{
	int64_t start;
	Timer(){reset();}
	void reset(){start=getcycle();}
	void plus(double a){start-=(a*CYCLES_PER_SEC);}
	inline double get(){return (double)(getcycle()-start)/CYCLES_PER_SEC;}
	inline int64_t getcycle(){
		uint32_t low,high;
		__asm__ volatile ("rdtsc":"=a"(low),"=d"(high));
		return ((int64_t)low)|((int64_t)high<<32);
	}
};
int main(){
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

using namespace std;

#define pb push_back
#define nl '\n'
#define pi 2.0*acos(0.0)
#define mod maxm+7
#define FOR(i,j,n)    for(ll i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

map<ll,ll>imap;

int main(){
    ll n,a;
    cin>>n;
    FOR(i,0,n-1){
        cin>>a;
        imap[a]++;
    }
    for(ll i = 1; i <= n ; i++){
        cout<<imap[i]<<endl;
    }
}


Measured memory_bytes: 16140
#include<bits/stdc++.h>
using namespace std;
int main(){ 
    int a,b;
    cin >> a >> b;
    int n;
    if(b < 10) n = a*10 + b;
    else if(b < 100) n = a*100+b;
    else n = a*1000+b;
    if(floor(sqrt(n)) == sqrt(n)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int ans = 0;
  for(int i=0,x;i<n;i++)
  {
      cin>>x;
      ans += (x>=k);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>

using namespace std;

int main(void){
	char c[2][3];

	for (int i = 0; i < 2; i++){
		for (int j = 0; j < 3; j++){
			cin >> c[i][j];
		}
	}

	if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
unsigned long a,m[10];
int n;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int k;cin>>k;
		for(;k--;)
		{
			int a;cin>>a;
			m[i]|=1L<<a;
		}
	}
	cin>>n;
	for(;n--;)
	{
		int t,b;cin>>t>>b;
		if(t==0)
		{
			cout<<(a>>b&1)<<endl;
		}
		else if(t==1)
		{
			a|=m[b];
		}
		else if(t==2)
		{
			a&=~m[b];
		}
		else if(t==3)
		{
			a^=m[b];
		}
		else if(t==4)
		{
			cout<<((a&m[b])==m[b])<<endl;
		}
		else if(t==5)
		{
			cout<<!!(a&m[b])<<endl;
		}
		else if(t==6)
		{
			cout<<!(a&m[b])<<endl;
		}
		else if(t==7)
		{
			cout<<__builtin_popcountl(a&m[b])<<endl;
		}
		else cout<<(a&m[b])<<endl;
	}
}



Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


char c[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";


int main() {
	int H, W;
	cin >> H >> W;
	string ans;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			string s;
			cin >> s;
			if (s == "snuke") {
				ans += c[j]; ans += to_string(i);
			}


		}
	}

	print(ans);




	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if (B < A) {
        cout << 0 << endl;
    } else if (A <= B && B / A <= C) {
        cout << B / A << endl;
    } else if (C < B / A) {
        cout << C << endl;
    }
}

Measured memory_bytes: 256