akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define I inline
#define fi first
#define se second
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int inf = 2147483647;
const int N = 1001, M = 3e2 + 1;
const int mod = 1e9 + 7;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I LL read() {
	LL x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

I int pow_mod(reg a, reg k) {reg ans = 1; for(; k; k >>= 1, a = (LL)a * a % mod) if(k & 1) ans = (LL)ans * a % mod; return ans;}

char ss[N];
int C[N][N], pos[N], s[N], up[N], jc[N], inv[N], f[M][M][M];
bool v[N];

int main() {
	reg n = read(), m = read();
	scanf("%s", ss + 1);
	jc[0] = 1; fo(i, 1, N - 1) jc[i] = (LL)jc[i - 1] * i % mod;
	inv[N - 1] = pow_mod(jc[N - 1], mod - 2); fd(i, N - 1, 1) inv[i - 1] = (LL)inv[i] * i % mod;
	C[0][0] = 1; fo(i, 1, N - 1) {
		C[i][0] = 1; fo(j, 1, i) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
	} int ans = 0;
	fo(A, 0, m / 2) {
		memset(v, 0, sizeof(v));
		reg R = 0;
		fo(i, 1, m) if(ss[i] == 'r'){
			if(R == A) break;
			bool bk = 0; fo(j, i + 1, m) if(ss[j] == 'b' && !v[j]) {v[j] = 1, pos[++R] = j, bk = 1; break;}
			if(!bk) break;
		} if(R < A) break;
		fo(B, 0, m) {
			reg z = 0;
			fo(i, 1, m) if(ss[i] == 'r') z++, s[i] = s[i - 1] + (z > A + B); else s[i] = s[i - 1] + (!v[i]);
			if(z < A + B) break;
			up[A + 1] = 0, pos[A + 1] = m; fd(i, A, 1) up[i] = up[i + 1] + (s[pos[i + 1]] - s[pos[i]] + 1);
			reverse(up + 1, up + A + 1);
			f[0][0][0] = 1; fo(i, 1, m) fo(j, 0, A) fo(S, 0, up[j]) f[i][j][S] = 0;
			fo(i, 1, m) fo(j, 0, A) fo(S, 0, _min(up[j], up[A] - i * (A - j))) if(f[i - 1][j][S]) {
				for(reg k = 0; j + k <= A && S + k * i <= up[j + k]; k++)
					f[i][j + k][S + k * i] = (f[i][j + k][S + k * i] + (LL)f[i - 1][j][S] * inv[k]) % mod;
			} fo(S, 0, up[A]) if(f[m][A][S]){
				int c = (LL)f[m][A][S] * jc[A + B] % mod * inv[B] % mod;
				int H1 = 2 * S + 2 * B, H2 = A * 2;
				int ga = H1 - 1, gb = H1 + H2;
				ans = (ans + (LL)c * C[n - ga + gb][gb]) % mod;
			}
		}
	} pr2(ans);
	return 0;
}



Measured memory_bytes: 29184
def main():
    string = raw_input()
    A = string[0]
    B = string[1]
    C = string[2]
    if A == '1':
        A = '9'
    else:
        A = '1'
    if B == '1':
        B = '9'
    else:
        B = '1'
    if C == '1':
        C = '9'
    else:
        C = '1'        
    print(A+B+C)



if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
	string S;

	cin >> S;
	
	if (S == "Sunny") {
		cout << "Cloudy";
	} else if (S == "Cloudy") {
		cout << "Rainy";
	} else {
		cout << "Sunny";
	}

	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 pb push_back

using ll = long long;

struct edge { int u, v, w; };

int main() {
	int L; cin >> L;
	int N = 20;
	vector<edge> E;
	for (int u = 1; u + 1 < N; u++) {
		E.pb({u, u + 1, 0});
		E.pb({u, u + 1, 1<<(18 - u)});
	}
	while (L > 0) {
		int x, u;
		for (x = 1, u = 19; x * 2 <= L && u - 1 > 0; x *= 2, u--);
		E.pb({0, u, L - x});
		L -= x;
	}
	int M = E.size();
	cout << N << ' ' << M << endl;
	for (edge e: E) {
		cout << e.u + 1 << ' ' << e.v + 1 << ' ' << e.w << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a[4] = {0}; int b[4] = {0};
    for(int i = 0; i < 3; i++){
        scanf("%ld %ld", &a[i], &b[i]);
    }
    int flag1 = 0; int flag2 = 0; int flag3 = 0; int flag4 = 0;
    for(int i = 0; i < 3; i++){
        if(a[i] == 1){
            flag1++;
        }else if(a[i] == 2){
            flag2++;
        }else if(a[i] == 3){
            flag3++;
        }else {
            flag4++;
        }
    }
    for(int i = 0; i < 3; i++){
        if(b[i] == 1){
            flag1++;
        }else if(b[i] == 2){
            flag2++;
        }else if(b[i] == 3){
            flag3++;
        }else {
            flag4++;
        }
    }
    int p1 = 0; int p2 = 0; int p3 = 0; int p4 = 0;
    if(flag1 > 0 && flag1 < 3){
        p1 = 1;
    }
    if(flag2 > 0 && flag2 < 3){
        p2 = 1;
    }
    if(flag3 > 0 && flag3 < 3){
        p3 = 1;
    }
    if(flag4 > 0 && flag4 < 3){
        p4 = 1;
    }

    if(p1 == 1 && p2 == 1 && p3 == 1 && p4 == 1){
        printf("YES\n");
    }else {
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 128
n = int(input())
h = list(map(int, input().split()))

dp = [10 ** 9 for _ in range(n+1)]
# スタート位置
dp[0] = 0

for i in range(n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i-2]))

print(dp[n-1])

Measured memory_bytes: 13976
# -*- coding: utf-8 -*-
N,K=map(int, input().split())

ans=0
for k in range(K,N+2):
    minc=round(k*(k-1)/2)
    maxc=round(k*(2*N-k+1)/2)
    count=maxc-minc+1
    ans+=count
    #print(count)

#print(ans)
print(int(ans%(10**9+7)))

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
using i128 = boost::multiprecision::int128_t;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


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

  rep(i, n) if (a[i] == 0) {
    cout << 0 << "\n";
    return 0;
  }

  i128 ans = 1;
  rep(i, n) {
    ans *= a[i];
    if (ans > i128(1e18)) {
      cout << -1 << "\n";
      return 0;
    }
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> p(100100); // 1e5
vector<int> q(100100); // 1e5

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

  int n;
  cin >> n;
  p.resize(n);
  q.resize(n);

  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];

  vector<int> a(n); // {}
  iota(all(a), 1); // {1,2,3}
  int count = 0;
  int aq, ap;
  do { 
    count++;
    if (a == p) ap = count;
    if (a == q) aq = count;
  } while (next_permutation(all(a)));

  cout << abs(ap-aq) << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
 
public class Main
{
	static Set<Integer> xSet = new TreeSet<>(), ySet = new TreeSet<>();
	static int a,b,c,d,e,f;
 
	public static void main(String[] args)
	{
		try(Scanner sc = new Scanner(System.in))
		{
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			d = sc.nextInt();
			e = sc.nextInt();
			f = sc.nextInt();
		}
 
		for(int i = 0;;i++)
		{
			boolean flag = false;
			for(int j = 0;; j++)
			{
				int x = 100*a*i + 100*b*j;
				if(x > f) break;
				xSet.add(x);
				flag = true;
			}
			if(!flag) break;
		}
 
		for(int i = 0;;i++)
		{
			boolean flag = false;
			for(int j = 0;; j++)
			{
				int y = c*i + d*j;
				if(y > f) break;
				ySet.add(y);
				flag = true;
			}
			if(!flag) break;
		}
 
		float max = -1.0f;
		int maxWater = 0, maxSuger = 0;
		for(int water : xSet)
		{
			for(int suger : ySet)
			{
				if(water + suger > f || suger * 100.0f > e * water) break;
				if(max < (100.0f * suger) / (water + suger))
				{
					max = (100.0f * suger) / (water + suger);
			        maxWater = water;
			        maxSuger = suger;
				}
			}
		}
 
		System.out.println((maxWater + maxSuger) + " " + maxSuger);
	}
 
}

Measured memory_bytes: 27220
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << P + Q + R - max({P, Q, R}) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vector<pll> a(n);
  for(ll i=0;i<n;i++) cin >> a[i].first,a[i].second=i;
  sort(a.rbegin(),a.rend());
  mat dp(n+1,vec(n+1,0));
  for(ll i=0;i<n;i++) {
    for(ll j=0;i+j<n;j++) {
      ll p=a[i+j].first;
      ll x=a[i+j].second;
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]+p*(x-i));
      dp[i][j+1]=max(dp[i][j+1],dp[i][j]+p*(n-1-j-x));
    }
  }
  ll res=0;
  for(ll i=0;i<=n;i++) {
    res=max(res,dp[i][n-i]);
  }
  cout << res << endl;
}

Measured memory_bytes: 34676
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define si(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	int val[n][3],ans[n][3];
	For(i,0,n-1) For(j,0,2) cin>>val[i][j];
	For(i,0,2) ans[0][i]=val[0][i];
	For(i,1,n-1)
	{
		For(j,0,2)
		{
			ans[i][j]=val[i][j]+max(ans[i-1][(j+1)%3],ans[i-1][(j+2)%3]);
		}
	}
	int mx=0; For(i,0,2) mx=max(mx,ans[n-1][i]);
	cout<<mx<<"\n";
	
	//For(i,0,n-1) For(j,0,2) cout<<ans[i][j]<<" \n"[j==2];
	
	return 0;
}






Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> P(N);
  vector<int> r(N);
  for(int i=0; i<N; i++){
    cin >> S[i] >> P[i];
    r[i] = i;
  }
  stable_sort(r.begin(), r.end(),
    [&P](int l, int r)->bool{
      return P[l]>P[r];
    }
  );
  stable_sort(r.begin(), r.end(),
    [&S](int l, int r)->bool{
      return S[l]<S[r];
    }
  );
  for(int ri: r){
    cout << ri+1 << endl;
  }
  return 0;
}

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

#define ll long long int
#define pb push_back
#define MP make_pair
#define PLL pair<ll,ll>
#define fastio ios::sync_with_stdio(0);cin.tie(0);
#define N 100009
vector<ll> adj[N];
ll dis[N];
ll vis[N];
ll par[N];

int main()
{
     ll n,m,i;
     cin >> n>>m;

     for(i=0;i<m;i++)
     {
       ll u,v;
       cin >> u>>v;
       adj[u].pb(v);
       adj[v].pb(u);

     }


     vector<bool> visited(N);
     for(int i = 0; i < N; i++)
         visited[i] = false;

     // Create a queue for BFS
     list<int> queue;

     // Mark the current node as visited and enqueue it
     visited[1] = true;
     queue.push_back(1);


     while(!queue.empty())
     {
         // Dequeue a vertex from queue and print it
         ll   s = queue.front();

         queue.pop_front();

         for (i = 0; i< adj[s].size(); i++)
         {
             if (!visited[adj[s][i]])
             {
                par[adj[s][i]]=s;
                visited[adj[s][i]] = true;
                queue.push_back(adj[s][i]);
             }
         }
     }


   ll flag=0;

    for(i=2;i<=n;i++){
      if(!visited[i]){
        flag=1;
        break;
      }

    }

    if(flag)
    cout <<"No"<<'\n';
    else
    {
      cout <<"Yes"<<'\n';
        for(i=2;i<=n;i++)
        cout << par[i] <<'\n';


    }


}


Measured memory_bytes: 14680
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	ll N; cin >> N;
	vector<pair<ll, ll>>vec;
	for (ll i = 1;i * i <= N;++i) {
		if(N%i==0)vec.push_back(make_pair(i, N / i));
	}
	ll ans = (ll)1e18;
	for(auto p:vec){
		chmin(ans, p.first + p.second - 2);
	}
	cout << ans << "\n";

	return 0;
}


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

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  
  if( A >= B){
    cout << "delicious" << endl;
  }else if( X + A >= B ){
    cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

#define INF (1 << 30)
#define NMAX 200000

long merge(int A[], int left, int mid, int right) {
    int L[NMAX], R[NMAX], i, j, k;
    long cnt;
    for (i = 0; i < mid - left; i++) {
        L[i] = A[left + i];
    }
    L[i] = INF;
    for (i = 0; i < right - mid; i++) {
        R[i] = A[mid + i];
    }
    R[i] = INF;
    i = 0, j = 0, cnt = 0;
    for (k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
            cnt += mid - left - i; 
        }
    }
    return cnt;
}

long mergeSort(int A[], int left, int right) {
    if (right - left <= 1) {
        return 0;
    }
    int mid = (left + right) / 2;
    long cnt = 0;
    cnt += mergeSort(A, left, mid);
    cnt += mergeSort(A, mid, right);
    cnt += merge(A, left, mid, right);
    return cnt;
}

int main() {
    int A[NMAX], N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    long cnt = mergeSort(A, 0, N);
    printf("%ld\n", cnt);
    return 0;
}



Measured memory_bytes: 4252
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	n := len(s)
	for i := range s[:n/2] {
		if s[i] != s[n-1-i] {
			fmt.Println("No")
			return
		}
	}
	for i := range s[:(n-1)/2] {
		if s[i] != s[(n-1)/2-1-i] {
			fmt.Println("No")
			return
		}
	}
	for i := (n + 3) / 2; i < n; i++ {
		if s[i] != s[n-1-i] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int cnt = 0;

vector<int> selectionsort(vector<int> &A, int N) {
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minj])
                minj = j;
        }
        if (A[i] != A[minj])
            swap(A[i], A[minj]), cnt++;
    }

    return A;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }

    vector<int> sortedA = selectionsort(A, N);
    rep(i, N-1) { cout << sortedA[i] << " "; }
    cout << sortedA[N-1] << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3140
#pragma optimize GCC ("O2")
#include<bits/stdc++.h>
using namespace std;

const int N = 2e3 + 5;
int G[N][N], e[N][N], p[N][N], h[N][N], s[N][N];
char ss[N];

int read () {
	int x = 0, f = 0; char c = getchar ();
	while (!isdigit (c)) f |= (c == '-'), c = getchar ();
	while (isdigit (c)) x = x * 10 + c - '0', c = getchar ();
	return f ? -x : x;
}

int main () {
	int n = read (), m = read (), Q = read ();
	for (int i = 1; i <= n; i++) {
		scanf ("%s", ss + 1);
		for (int j = 1; j <= m; j++) {
			G[i][j] = ss[j] - '0';
			if (G[i][j]) {
				p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + 1;
				e[i][j] = e[i - 1][j] + e[i][j - 1] - e[i - 1][j - 1] + (G[i - 1][j] == 1) + (G[i][j - 1] == 1);
				h[i][j] = h[i][j - 1] + (G[i][j - 1] == 1);
				s[i][j] = s[i - 1][j] + (G[i - 1][j] == 1);
			} else {
				p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1];
				e[i][j] = e[i - 1][j] + e[i][j - 1] - e[i - 1][j - 1];
				h[i][j] = h[i][j - 1], s[i][j] = s[i - 1][j];
			}
		}
	}
	
	while (Q--) {
		int a1 = read (), b1 = read (), a2 = read (), b2 = read ();
		int sww1 = p[a2][b2] + p[a1 - 1][b1 - 1] - p[a2][b1 - 1] - p[a1 - 1][b2];
		int sww2 = e[a2][b2] + e[a1][b1] - e[a2][b1] - e[a1][b2];
		int sww3 = s[a2][b1] - s[a1][b1] + h[a1][b2] - h[a1][b1];
		printf ("%d\n", sww1 - sww2 - sww3);
	}
	return 0;
}


Measured memory_bytes: 80256
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=a&&a<b)
using namespace std;
int dx[]={-1,1,0,0},dy[]={0,0,-1,1},
	w,h,mx,ice[90][90];
void bfs(int y,int x,int n){
	if(mx<n)mx=n;
	rep(d,4){
		int ny=y+dy[d],nx=x+dx[d];
		if(ck(ny,h)&&ck(nx,w)&&ice[ny][nx]){
			ice[ny][nx]=0; bfs(ny,nx,n+1); ice[ny][nx]=1;
		}
	}
}
int main(){
	while(cin>>w>>h,w){
		rep(i,h)rep(j,w)cin>>ice[i][j];
		mx=0;
		rep(i,h)rep(j,w)if(ice[i][j]){
			ice[i][j]=0; bfs(i,j,1); ice[i][j]=1;
		}
		cout<<mx<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#define N 100
#define INFTY 10000000

int n;
int M[N][N];
int color[N], d[N], f[N];
int tt;
int Q[N*2];
int head, tail;

void init();
void enqueue(int);
int empty();
int dequeue();
void bfs(int);




int main(){

  int  u, k, v;
  int i, j; 

  scanf("%d", &n);

  for ( i = 0; i <n; i++ ){
    for ( j = 0; j <n; j++ ){
      M[i][j] = 0;
    }
  }
  
  for ( i = 0; i < n; i++ ){
    
    scanf("%d %d", &u, &k);
    u--;

    for ( j = 0; j < k; j++ ){

      scanf("%d", &v);
      v--;
      M[u][v] = 1;

    }
  }
  
  bfs(0);

  return 0;
}


void init(){
  head = tail = 1;
}

void enqueue(int x){
  Q[tail++] = x;
}

int empty(){
  return head == tail;
}

int dequeue(){
  int x = Q[head++];
  return x;
}

void bfs(int s){
  
  int i, u, v;

  init();
  enqueue(s);

  for ( i = 0; i < n; i++ ){
    d[i] = INFTY;
  }

  d[s] = 0;

  while(!empty()){

    u = dequeue();

    for ( v = 0; v < n; v++ ){
      if ( M[u][v] == 0 ) continue;
      if ( d[v] != INFTY ) continue;
      d[v] = d[u] + 1;
      enqueue(v);

    }
  }
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i+1,((d[i]==INFTY)?(-1):d[i]));
  }
}

Measured memory_bytes: 636
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int n; cin >> n;
  vector<int> d(n);
  for (int i=0; i<n; i++) {
    cin >> d[i];
  }

  sort(d.begin(), d.end());

  cout << d[n/2] - d[n/2 - 1] << endl;
  return 0;
}


Measured memory_bytes: 640
n = int(input())
S = input()
def check(start_now,start_before):
    now = start_now
    before = start_before
    ans = ""
    for i in S:
        ans += now
        if i == "o" and now == "S":
            if before == "S":
                now = "S"
                before = "S"
            else:
                now = "W"
                before = "S"
        elif i == "o" and now == "W":
            if before == "S":
                now = "W"
                before = "W"
            else:
                now = "S"
                before = "W"
        elif i == "x" and now == "S":
            if before == "S":
                now = "W"
                before = "S"
            else:
                now = "S"
                before = "S"
        elif i == "x" and now == "W":
            if before == "S":
                now = "S"
                before = "W"
            else:
                now = "W"
                before = "W"
    if now == start_now and before == start_before:
        print(ans)
        exit()

cheak_list = [["S","S"],["S","W"],["W","S"],["W","W"]]
for c in cheak_list:
    start_now, start_before = c
    check(start_now,start_before)
print(-1)

Measured memory_bytes: 3444
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

void run() {
	int n; cin >> n;
	map<int, int> elems;

	rep(i, 0, n) {
		int a; cin >> a;
		elems[a]++;
	}

	vector<pair<int, int>> cnt(all(elems));
	bool ans = 0;
	sort(all(cnt));

	if (sz(cnt) == 1) {
		ans = (cnt[0].x == 0);
	} else if (sz(cnt) == 2) {
		ans = (cnt[0].x == 0 && cnt[0].y*2 == cnt[1].y);
	} else if (sz(cnt) == 3) {
		ans = ((cnt[0].x ^ cnt[1].x) == cnt[2].x && cnt[0].y == cnt[1].y && cnt[1].y == cnt[2].y);
	} else {
		ans = 0;
	}

	cout << (ans ? "Yes\n" : "No\n");
}


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

string S;
int cur = 0;

int P,Q,R;

int formula() {
  if (S[cur] == '0' || S[cur] == '1' || S[cur] == '2') {
    return S[cur++] - '0';
  } else if (S[cur] == 'P') {
    cur++;
    return P;
  } else if (S[cur] == 'Q') {
    cur++;
    return Q;
  } else if (S[cur] == 'R') {
    cur++;
    return R;
  } else if (S[cur] == '-') {
    cur++;
    return 2-formula();
  } else {
    assert(S[cur] == '(');
    cur++;
    int a = formula();
    char op = S[cur++];
    int b = formula();
    assert(S[cur] == ')');
    cur++;
    if (op == '*') {
      if (a == 2 && b == 2) {
	return 2;
      } else if (a == 0 || b == 0) {
	return 0;
      } else {
	return 1;
      }
    } else {
      assert(op == '+');
      if (a == 0 && b == 0) {
	return 0;
      } else if (a == 2 || b == 2) {
	return 2;
      } else {
	return 1;
      }      
    }
  }
}

int main() {
  while(cin >> S && S != ".") {
    int ans = 0;
    for(P = 0; P <= 2; P++) {
      for(Q = 0; Q <= 2; Q++) {
	for(R = 0; R <= 2; R++) {
	  cur = 0;
	  int aa = formula();
	  assert(cur == (int)S.length());
	  if (aa == 2) {
	    ans++;
	  }
	}
      }
    }
    cout << ans << endl;
  }
}

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

const int MAXN = 1e5 + 5;
pair<int, int> students[MAXN];//first为人数，second为序号
int main()
{
	int N; cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> students[i].first;
		students[i].second = i + 1;
	}
	sort(students, students + N);
	for (int i = 0; i < N; i++)
		cout << students[i].second << ' ';
}


Measured memory_bytes: 1536
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,tree[li*4],lazy[li*4],dp[li];
int cev;
string s;
vector<int> v;

inline void push(int node,int start,int end){
	if(lazy[node]==0)return ;
	tree[node]=max(tree[node],lazy[node]);
	if(start!=end){
		lazy[node*2]=max(lazy[node*2],lazy[node]);
		lazy[node*2+1]=max(lazy[node*2+1],lazy[node]);
	}
	lazy[node]=0;
}

inline void update(int node,int start,int end,int l,int r,int val){
	push(node,start,end);
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){
		lazy[node]=max(lazy[node],val);
		push(node,start,end);
		return ;
	}
	update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val);
	tree[node]=max(tree[node*2],tree[node*2+1]);
}

inline int query(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return 0;
	push(node,start,end);
	if(start>=l && end<=r){
		return tree[node];
	}
	return max(query(node*2,start,mid,l,r),query(node*2+1,mid+1,end,l,r));
}

main(void){
	scanf("%lld",&n);
	FOR scanf("%lld",&b[i]);
	FOR scanf("%lld",&a[i]);
	FOR{
		dp[i]=query(1,1,200000,b[i],b[i]);
		dp[i]+=a[i];
		update(1,1,200000,b[i],200000,dp[i]);
		cev=max(cev,dp[i]);
	}
	printf("%lld\n",cev);
	return 0;
}



Measured memory_bytes: 16708
<?php
fscanf(STDIN,"%d%d%d",$w,$h,$n);

$x_max = $w;
$x_min = 0;
$y_max = $h;
$y_min = 0;
for($i=0;$i<$n;$i++){
  fscanf(STDIN,"%d%d%d",$x,$y,$a);
  if($a==1){
    $x_min = max($x_min,$x);
  }elseif($a==2){
    $x_max = min($x_max,$x);
  }elseif($a==3){
    $y_min = max($y_min,$y);
  }else{
    $y_max = min($y_max,$y);
  }
}

$x_h = ($y_max-$y_min);
$y_h = ($x_max-$x_min);
if($x_h>=0 && $y_h>=0){
  echo $x_h*$y_h;
}else{
  echo "0";
}

Measured memory_bytes: 4728
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        l: usize,
        t: usize,
        v: [(usize, usize); n]
    }
    let mut id = 0;
    for i in 1..n {
        if v[0].1 == v[i].1 {
            continue;
        }
        if v[0].1 == 1 {
            let m = (2 * t + v[0].0 + l - v[i].0 - 1) / l;
            id = (id + m) % n;
        } else {
            let m = (2 * t + v[i].0 - v[0].0) / l;
            id = (id + n - m % n) % n;
        }
    }
    let mut ps = vec![0; n];
    for i in 0..n {
        if v[i].1 == 1 {
            ps[i] = (v[i].0 + t) % l;
        } else {
            ps[i] = (v[i].0 + l - t % l) % l;
        }
    }
    ps.sort();
    let mut j = 0;
    let p0 = if v[0].1 == 1 {
        (v[0].0 + t) % l
    } else {
        (v[0].0 + l - t % l) % l
    };
    while ps[j] != p0 {
        j += 1;
    }
    let mut ans = vec![0; n];
    for i in 0..n {
        ans[(i + id) % n] = ps[(j + i) % n];
    }
    for &a in &ans {
        println!("{}", a);
    }
}


Measured memory_bytes: 9340
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        class Point
        {
            public readonly long x;
            public readonly long y;
            public Point(long[] v)
            {
                x = v[0];
                y = v[1];
            }
        }
        static long Solve(int N, int K, Point[] points)
        {
            var set1 = new HashSet<long>();
            var set2 = new HashSet<long>();
            foreach (var point in points)
            {
                set1.Add(point.x);
                set2.Add(point.y);
            }
            long min = long.MaxValue;
            var X = set1.OrderBy(x => x).ToArray();
            var Y = set2.OrderBy(y => y).ToArray();
            for (int i = 0; i < X.Length; ++i)
            {
                long x1 = X[i];
                for (int j = i + 1; j < X.Length; ++j)
                {
                    long x2 = X[j];
                    for (int k = 0; k < Y.Length; ++k)
                    {
                        long y1 = Y[k];
                        for (int l = k + 1; l < Y.Length; ++l)
                        {
                            long y2 = Y[l];
                            int count = 0;
                            foreach (var p in points)
                            {
                                if (x1 <= p.x && p.x <= x2 && y1 <= p.y && p.y <= y2)
                                {
                                    if (++count > K) { break; }
                                }
                            }
                            if (count == K) { min = Math.Min((x2 - x1) * (y2 - y1), min); }
                        }
                    }
                }
            }
            return min;
        }
        static void Main(string[] args)
        {
            int[] v = ReadInts();
            int N = v[0];
            int K = v[1];
            var points = new Point[N];
            for (int i = 0; i < N; ++i) { points[i] = new Point(ReadLongs()); }
            Console.WriteLine(Solve(N, K, points));
        }
    }
}


Measured memory_bytes: 13524
#include<stdio.h>

int main(void){
  int N,N1,sum = 0,i = 0,j;
  int S[11];
    
  scanf("%d",&N);
  N1 = N;
  
  while(N > 0){
    S[i] = N % 10;
    N = N / 10;
    i++;
  }
  for(j = 0;j < i;j++)
    sum = sum + S[j];
  
  if(N1 % sum == 0)
    printf("Yes\n");
  else
    printf("No\n");
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#define N 4

int main(void){
	int i,j,hit,blow;
	int a[N],b[N];
	char str[100],s[100];

	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		fgets(s,sizeof(str),stdin);
		sscanf(str,"%d %d %d %d",&a[0],&a[1],&a[2],&a[3]);
		sscanf(s,"%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		hit=0; blow=0;
		for(i=0;i<N;i++){
			for(j=0;j<N;j++){
				if(b[i]==a[j] && i==j)
					hit++;
				else if(b[i]==a[j])
					blow++;	
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

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

int main() {
  vector<int> h(10);
  for (int i = 0; i < 10; i++) cin >> h[i];
  sort(begin(h), end(h), greater<int>());
  for (int i = 0; i < 3; i++) {
    cout << h[i] << endl;
  }
}



Measured memory_bytes: 3072
import heapq

N, M = map(int, input().split())
case = sorted([[int(j) for j in input().split()] for i in range(N)], key=lambda x: -x[0])

candidate_queue = []
ans = 0

for i in range(1, M + 1):
    while case:
        if case[-1][0] <= i:
            heapq.heappush(candidate_queue, -case.pop(-1)[1])
        else:
            break

    if candidate_queue:
        ans += -heapq.heappop(candidate_queue)

print(ans)


Measured memory_bytes: 78168
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int N = s.length;
		if(N==1) {
			System.out.println(s[0]);
			sc.close();
			return;
		}
		
		long ans = 0;
		
		boolean[] plus = new boolean[N-1];
		
		while(true) {
			long sum = 0;
			long carry = 0;
			for(int i=0; i<N; i++) {
				carry = carry*10+s[i]-'0';
				if(i==N-1 || plus[i]) {
					sum += carry;
					carry = 0;
				}
			}
			ans += sum;
			boolean car = false;
			for(int i=0; i<N-1; i++) {
				if(plus[i]) {
					car = true;
					plus[i]=false;
				} else {
					car = false;
					plus[i]=true;
					break;
				}
			}
			if(car)
				break;
		}
		
		System.out.println(ans);
		sc.close();
	}
}


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

using namespace std;


const int MAX = 100005;
const int NIL = -1;
typedef long long ll;

struct Node { int p, l, r; };
Node T[MAX];
int n;

void preParse(int u) {
    if (u == NIL)
        return;
    cout << " " << u;
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u) {
    if (u == NIL)
        return;
    inParse(T[u].l);
    cout << " " << u;
    inParse(T[u].r);
}

void postParse(int u) {
    if (u == NIL)
        return;
    postParse(T[u].l);
    postParse(T[u].r);
    cout << " " << u;
}


int main() {
    int root = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
        T[i].p = NIL;

    for (int i = 0; i < n; i++) {
        int v, l, r; cin >> v >> l >> r;
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }

    for (int i = 0; i < n; i++) {
        if (T[i].p == NIL)
            root = i;
    }

    cout << "Preorder" << endl;
    preParse(root);
    cout << endl;
    cout << "Inorder" << endl;
    inParse(root);
    cout << endl;
    cout << "Postorder" << endl;
    postParse(root);
    cout << endl;
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main{
  public static void main (String[] args){
  
    int a,b,c;
    int sum;

    Scanner sc = new Scanner (System.in);
    a=sc.nextInt();
    b=sc.nextInt();
    c=sc.nextInt();

    sum=a+b;

    if(sum>=c)
      System.out.println("Yes");
   else if(sum<=c)
      System.out.println("No"); 

  }

}

Measured memory_bytes: 21844
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int):
    if N % 1000 == 0:
        return 0
    return 1000 - N % 1000


def main():

    sys.setrecursionlimit(10 ** 6)

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 62480
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//239///F.Sugoroku
	int n;
	cin>>n;
	double up = n-n/2;
	up = up/n;
	printf("%.6lf",up);
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>

using namespace std;

int main (){
    const int as = 200001;

    int n, k, u = 0, ans = 0;
    int a[as] = {}, b[as] = {};

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

    sort(a, a+n);
    a[n] = 'NULL';

    for(int i=0; a[i] != 'NULL';){
        for(int j = i+1; j<=n; j++){
            //cout << "i=" << i << " j=" << j << endl;
            if(a[i] != a[j]){
                b[u] = j-i;
                i=j;
                u++;
                break;
            }
        }
    }
    /*
    cout << "u = " << u << endl << "a = ";
    for(int i=0; i<n; i++)cout << a[i];
    cout << endl << "b = " ;
    for(int i=0; i<u; i++)cout << b[i];
    cout << endl;
    */

    if(u <= k){
        cout << "0" << endl;
        return 0;
    }else{
        sort(b, b+u);
        for(int i=0; i<u-k; i++)ans += b[i];

        cout << endl << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  vector<P> vec(n);
  rep(i, n) {
    int a, b; cin >> a >> b;
    vec[i] = P(a, b);
  }

  sort(vec.begin(), vec.end());
  int cnt = 0;
  ll ans = 0;
  rep(i, n) {
    ll a = vec[i].first;
    int b = vec[i].second;
    if (cnt + b <= m) {
      ans += a*b;
      cnt += b;
    } else {
      ans += a*(m-cnt);
      break;
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
      	int b = sc.nextInt();
      	boolean cha = (a <= 8 && b <=8);
 		
      	if(cha) System.out.println("Yay!");
      	else System.out.println(":(");
        
	}
}


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

using namespace std;

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)



void solve()
{
    int n, k, i, j;
    cin>>n>>k;
    vector<int> A(n);
    vector<bool> dp(k+1, false);
    for(i = 0; i < n; i++)
        cin>>A[i];
    sort(A.begin(), A.end());
    for(i = 0 ; i < A[0] && i < k+1; i++)
        for(j = 0; j < n && i+A[j] < k+1; j++)
            dp[i+A[j]] = true;
    bool win;
    for(i = A[0];i<k+1;i++)
    {
        win = !dp[i];
        for(j = 0; j<n && i+A[j] < k+1; j++)
            dp[i+A[j]] = (win|dp[i+A[j]]);
    }
    if(dp[k])
        cout<<"First\n";
    else
        cout<<"Second\n";
}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc;
	tc = 1;
    // cin>>tc;
    while(tc--)
        solve();

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var css [3][3]int
	for i, cs := range css {
		for j := range cs {
			fmt.Scan(&css[i][j])
		}
	}

	as := make([]int, 3)
	bs := make([]int, 3)
	as[0] = 0
	as[1] = css[1][0] - css[0][0]
	as[2] = css[2][0] - css[0][0]
	bs[0] = css[0][0]
	bs[1] = css[0][1]
	bs[2] = css[0][2]

	for i, cs := range css {
		for j, c := range cs {
			if c != as[i]+bs[j] {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
n = int(input())
h = list(map(int, input().split()))
t = 0
result = 0
for i in range(n - 1):
  if h[i + 1] <= h[i]:
    t += 1
  else:
    result = max(t, result)
    t = 0
result = max(t, result)
print(result)

Measured memory_bytes: 63984
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
testim=array(N)
N.times do|i|
    a=gets.to_i
    a.times do|j|
        x,y=get_i
        x-=1
        testim[i]=[] if testim[i].nil?
        testim[i].push([x,y])
    end
end
ans=0
(2**N).times do|bit|
    people=array(N,-1)
    flag=true
    N.times do|i|
        unless (bit&(2**i)).zero?
            if people[i]==-1
              people[i]=1
            elsif people[i]!=1
                flag=false
                break
            end
            next if testim[i].nil?
            testim[i].each do|x,y|
              if people[x]==-1
                  people[x]=y
              elsif people[i]==1 and people[x]!=y
                  flag=false
                  break
              end
            end
        else
            if people[i]==-1
                people[i]=0
            elsif people[i]!=0
                flag=false
                break
            end
        end
    end
    if flag
      ans=max(ans,people.count{|x| x==1})
    end
end
puts ans

Measured memory_bytes: 2300
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
char a[55][55];
int b[55][55];
int fx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int fy[8] = {1, -1, 0, 1, -1, -1, 1, 0};
int main() {
	int m, n;
	cin >> m >> n;
	for(int i = 1; i <= m; i++)
		for(int j = 1; j <= n; j++)
			cin >> a[i][j];
	for(int i = 1; i <= m; i++)
		for(int j = 1; j <= n; j++)
			for(int k = 0; k < 8; k++)
				if(i + fx[k] >= 1 && fx[k] + i <= m && j + fy[k] >= 1 && j + fy[k] <= n && a[i + fx[k]][j + fy[k]] == '#')
					b[i][j]++;
	for(int i = 1; i <= m; i++) {
		for(int j = 1; j <= n; j++)
			if(a[i][j] == '.')
				cout << b[i][j];
			else
				cout << a[i][j];
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())

ans = 0

if abs(B-A) % 2 == 0:
    ans = abs(B-A) // 2

else:
    if B > A:
        ans = min(N-A, B-1,(N-B+1) + (B-A-1)//2, (A-1+1) + (B-A-1)//2)

    if A > B:
        ans = min(N-B, A-1,(N-A+1) + (A-B-1)//2, (B-1+1) + (A-B-1)//2)


print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		if(n<=999) {
			System.out.println("ABC");
		}
		else if(n>=1000) {
			System.out.println("ABD");
		}

	}

}

Measured memory_bytes: 35784