akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.endl(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
vec2int b(2, vecint(3, 0));
vec2int c(3, vecint(2, 0));
vec2int G(3, vecint(3, -1));
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n, k;
  string s;
  cin >> n >> k >> s;
  vecint rec;
  if (s[0] == '0') rec.push_back(0);
  REP(i, n) {
    char c = s[i];
    int tmp = 1;
    // cout << i << endl;
    while (i + 1 < n && c == s[i + 1]) {
      tmp++;
      i++;
    }
    rec.push_back(tmp);
  }
  if (s.back() == '0') rec.push_back(0);
  // REPe(e, rec) { cout << e << endl; }
  int m = rec.size();
  vecint sum(m + 1, 0);
  REP(i, m) { sum[i + 1] = sum[i] + rec[i]; }
  if (k >= m / 2) {
    cout << n << endl;
    return 0;
  }
  int ans = 0;
  REP(i, m / 2) {
    int l = 2 * i;
    int r = l + 2 * k;
    if(r >= m) break;
    ans = max(ans, sum[r + 1] - sum[l]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1272
#include <iostream>
#include <cstdio>
using namespace std;
long long a, b, c;
int main() {
	cin >> a >> b >> c;
	if (c - (a + b) < 0) puts("No");
	else {
		if (4 * a * b < a * a + b * b + c * c - 2 * a * c - 2 * b * c + 2 * a * b) puts("Yes");
		else puts("No");
	}
	return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n; i < (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
void debug(vector<vector<ll>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
void debug(vector<ll>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
//m.emplace(x,0).fi->second++;

int main(){
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n+1),b(n);
  rep(i,0,n+1)cin>>a[i];
  rep(i,0,n)cin>>b[i];
  rep(i,0,n){
    if(a[i]>=b[i])res+=b[i];
    else{
      res+=a[i];
      b[i]-=a[i];
      if(a[i+1]<=b[i]){
        res+=a[i+1];
        a[i+1]=0;
      }
      else{
        res+=b[i];
        a[i+1]-=b[i];
      }
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

void prints(int n,int S[n+1][n+1] ){
  int i,j;
  for(i=1;i<n+1;i++){
    for(j=1;j<n+1;j++){
      printf("%d", S[j][i]);
    }
    printf("\n");
  }
  printf("\n");
}

int main(){
  int i,j,k,l,s,N,M,Q;
  scanf("%d %d %d", &N,&M,&Q);
  int L[M+1],R[M+1],p[Q],q[Q];
  for(i=1;i<M+1;i++){
    scanf("%d %d",&L[i],&R[i]);
  }
  for(i=0;i<Q;i++){
    scanf("%d %d", &p[i],&q[i]);
  }

  int S[N+1][N+1],Sum[N+1][N+1];
  for(i=0;i<N+1;i++){
    for(j=0;j<N+1;j++){
      S[i][j]=0;
      Sum[i][j]=0;
    }
  }

  for(i=1;i<M+1;i++){
    l=R[i];
    k=L[i];
    S[k][l]=S[k][l]+1;
  }
  //prints(N,S);
  
  for(i=1;i<N+1;i++){
    s=0;
    for(j=1;j<N+1;j++){
      Sum[i][j]=s+S[i][j];
      s=s+S[i][j];
    }
  }
  //prints(N,Sum);
  int ANS;
  for(i=0;i<Q;i++){
    ANS=0;
    for(k=p[i];k<N+1;k++){
      l=q[i];
      ANS=ANS+Sum[k][l];
    }
    printf("%d\n", ANS);
  }
  return 0;
}


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

int i,x;

int main () {
	x=1;
	while(1){
	cin>>i;
		if(i!=0){
		
		cout<<"Case "<<x<<": "<<i<<endl;
		
		x++;
	
		}
	
		else{

		break;

		}

}



return 0;

}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
using namespace std;

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; }

const long long INF = 1LL << 60;
int xy[110][110];int a[110];int x[110];int y[110];
int main()
{
	int W,H,N;
	cin >> W >> H >> N;
	int res = 0;
	for (int i = 0;i < N;i++) {
		cin >> x[i] >> y[i] >> a[i];
	}

	for (int i = 0;i < N;i++) {
		if (a[i] == 1) {
			for (int j = 0;j < x[i];j++) {
				for (int k = 0;k < H;k++) {
					xy[j][k]++;
				}
			}
		}
		else if (a[i] == 2) {
			for (int j = x[i];j < W;j++) {
				for (int k = 0;k < H;k++) {
					xy[j][k]++;
				}
			}
		}
		else if (a[i] == 3) {
			for (int j = 0;j < W;j++) {
				for (int k = 0;k < y[i];k++) {
					xy[j][k]++;
				}
			}
		}
		else if (a[i] == 4) {
			for (int j = 0;j < W;j++) {
				for (int k = y[i];k < H;k++) {
					xy[j][k]++;
				}
			}
		}
	}

	for (int i = 0;i < W;i++) {
		for (int j = 0;j < H;j++) {
			if (xy[i][j] == 0) {
				res++;
			}
		}
	}

	cout << res << endl;
}

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

int main() {
	string s;
	cin >> s;
	
	int a_cnt = count(cbegin(s), cend(s), 'a');
	int b_cnt = count(cbegin(s), cend(s), 'b');
	int c_cnt = count(cbegin(s), cend(s), 'c');
	if (a_cnt == 1 && b_cnt == 1 && c_cnt == 1) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define FR(i,a,b) for(int i = (a);i<(b);i++)
#define RF(i,a,b) for(int i = (a);i>(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 1000005
#define M 51
#define INF 100000000000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
inline int Max(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^a;
}


int main()
{
    ll n,m;
    while(cin>>n>>m)
    {
        if(n>=m/2)cout<<m/2<<endl;
        else cout<<n+(m-n*2)/4<<endl;
    }
    return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void solve(){
    while(true){
        int n;
        cin >> n;
        if(n==0) break;

        typedef tuple<int,int,int> triple;
        set<triple> intervals;
        intervals.insert(triple(0,0,-inf));
        rep(i,0,n){
            char command;
            cin >> command;
            if(command=='W'){
                int id,len;
                cin >> id >> len;
                auto a=intervals.begin();
                auto b=intervals.begin();
                ++b;
                while(len>0){
                    int l=get<1>(*a);
                    if(b==intervals.end()){
                        intervals.insert(triple(l,l+len,id));
                        break;
                    }
                    auto r=get<0>(*b);
                    if(l==r){
                        a=b;
                        ++b;
                        continue;
                    }
                    if(r-l>len) r=l+len;
                    b=intervals.insert(triple(l,r,id)).first;
                    a=b;
                    ++b;
                    len-=r-l;
                }
            }else if(command=='D'){
                int id;
                cin >> id;
                for(auto it=intervals.begin();it!=intervals.end();){
                    if(get<2>(*it)==id) it=intervals.erase(it);
                    else ++it;
                }
            }else{
                int addr;
                cin >> addr;
                bool ok=false;
                for(const auto& interval:intervals) if(get<0>(interval)<=addr and addr<get<1>(interval)){
                    cout << get<2>(interval) << endl;
                    ok=true;
                    break;
                }
                if(!ok) cout << -1 << endl;
            }
        }
        cout << endl;
    }
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

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

#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)

using namespace std;

typedef long long ll;

inline int read(){
  int n=0,f=1;char c;
  for(c=getchar();c!='-'&&(c<'0'||c>'9');c=getchar());
  if (c=='-') f=-1,c=getchar();
  for(;c>='0'&&c<='9';c=getchar()) n=(n<<3)+(n<<1)+(c&15);
  return n*f;
}

const int maxn=2e5+5;
int n,s,i,ans,a[maxn],j;
bool bz[maxn];

int main()
{
  n=read();
  fo(i,1,n) a[i]=read();
  sort(a+1,a+n+1);
  for(s=1<<30;s;s>>=1){
    j=n;
    fo(i,1,n) if (!bz[i]) {
      for(;j>i&&(a[j]>s-a[i]||bz[j]);j--);
      if (j<=i) break;
      if (a[j]==s-a[i]) bz[i]=bz[j]=1,ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll x, y;
  cin >> x >> y;

  cout << x + y / 2 << "\n";
}

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

long long mod = 1e9 + 7;

long long pow(long long a, long long x){
    a %= mod;
    if(x == 0){
        return 1;
    }
    if(x == 1){
        return a;
    }
    long long half = pow(a * a % mod, x / 2);
    if(x % 2){
        return half * a % mod;
    }else{
        return half % mod;
    }
}

long long inv(long long n){
    return pow(n, mod - 2);
}

long long fact(long long n){
    if(n == 0){
        return 1;
    }
    long long ret = 1;
    for(int i = 1; i <= n; i++){
        ret *= i;
        ret %= mod;
    }
    return ret;
}
long long comb(long long n, long long k){
    return fact(n) * inv(fact(k)) % mod * inv(fact(n - k)) % mod;
}

int main(){
    int X, Y;
    cin >> X >> Y;

    if((X + Y) % 3){
        cout << 0 << endl;
        return 0;
    }

    int step_num = (X + Y) / 3;
    int x_num = X - step_num;

    if(abs(X - Y) > step_num){
        cout << 0 << endl;
        return 0;
    }

    cout << comb(step_num, x_num) << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#define n 10000
#define q 5000

int main(){
  
  int S[n];
  int T[q];
  int U[n];

  int sNum,tNum;

  int i,j,k;

  int c = 0;

  int flag;

  scanf("%d",&sNum);

  for(i = 0; i < sNum; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&tNum);

  for(i = 0; i < tNum; i++){
    scanf("%d",&T[i]);
  }



  for(i = 0; i < sNum; i++){
    for(j = 0; j < tNum; j++){
      flag = 0;
      if(S[i] == T[j]){
	for(k = 0; k < c; k++){
	  if(U[k] == S[i]){
	    flag = 1;
	    break;
	  }
	}
	if(flag == 0){
	  U[c] = S[i];
	  c++;
	}
      }
    }
  }

  printf("%d\n",c);

  return 0;
}

Measured memory_bytes: 648
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = 998244353; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll mpow(ll x, ll n) { ll y = 1; for (; n; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }
struct Combination {
    vector<ll> fact, ifact;
    Combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1; for (int i = 0; i < n; ++i) fact[i + 1] = fact[i] * (i + 1) % MOD;
        ifact[n] = mpow(fact[n], MOD - 2); for (int i = n; i > 0; --i) ifact[i - 1] = ifact[i] * i % MOD;
    }
    ll operator ()(int n, int k) const { return k < 0 || k > n ? 0 : fact[n] * ifact[n - k] % MOD * ifact[k] % MOD; }
} C(2e5);

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

    ll ans = 0;
    rep(k, K + 1) {
        ans = (ans + M * C(N - 1, k) % MOD * mpow(M - 1, N - 1 - k)) % MOD;
    }

    write(ans);
}

Measured memory_bytes: 6300
#include<bits/stdc++.h>
#define ll long long
#define Mod 1000000007ll
#define Val(x) ((((ll)x) % Mod + Mod) % Mod)
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	int ans = 0;
	for(int i=k;i<=n+1;i++) {
		ll a = (ll)i * (i + 1) / 2;
		ll b = (ll)i * (n + 1 + n + 1 - i + 1) / 2;
		ans = Val(b - a + 1 + ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, m;
    map<string, ll> mp;

    // 青いカードの処理
    cin >> n;
    rep(i, n){
        string s;
        cin >> s;
        mp[s]++;
    }
    
    // 赤いカードの処理
    cin >> n;
    rep(i, n){
        string s;
        cin >> s;
        mp[s]--;
    }

    ll maxv = -INFLL;
    
    // 最大得点
    for(auto p: mp) chmax(maxv, p.second);
    cout << max(maxv, 0LL) << endl;

}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

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

vvi shock(vvi panel, int c) {
	int tc = panel[0][0];
	int h = panel.size();
	int w = panel[0].size();
	queue<pii> Q;
	Q.push(make_pair(0, 0));
	vvi visited(h, vi(w, 0));
	visited[0][0] = 1;
	panel[0][0] = c;
	while(!Q.empty()) {
		pii p = Q.front();
		Q.pop();
		REP(d, 4) {
			int ny = p.first + dy[d];
			int nx = p.second + dx[d];
			if(ny<0 || h<=ny || nx<0 || w<=nx) {
				continue;
			}
			if(visited[ny][nx]) {
				continue;
			}
			if(panel[ny][nx] == tc) {
				panel[ny][nx] = c;
				visited[ny][nx] = 1;
				Q.push(make_pair(ny, nx));
			}
		}		
	}
	return panel;
}

int count(vvi panel, int c) {
	int res = 0;
	int h = panel.size();
	int w = panel[0].size();
	if(panel[0][0] != c) {
		return 0;
	}
	queue<pii> Q;
	Q.push(make_pair(0, 0));
	panel[0][0] = 0;
	res++;
	while(!Q.empty()) {
		pii p = Q.front();
		Q.pop();
		REP(d, 4) {
			int ny = p.first + dy[d];
			int nx = p.second + dx[d];
			if(ny<0 || h<=ny || nx<0 || w<=nx) {
				continue;
			}
			if(panel[ny][nx] == c) {
				panel[ny][nx] = 0;
				res++;
				Q.push(make_pair(ny, nx));
			}
		}
	}
	return res;
}

int main() {
	int h, w, c;
	while(cin >> h >> w >> c, h) {
		vvi panel(h, vi(w));
		REP(i, h) {
			REP(j, w) {
				cin >> panel[i][j];
			}
		}
		int ans = 0;
		FOR(i, 1, 6) {
			FOR(j, 1, 6) {
				FOR(k, 1, 6) {
					FOR(l, 1, 6) {
						vvi tmp(panel);
						tmp = shock(shock(shock(shock(tmp, i), j), k), l);
						tmp = shock(tmp, c);
						ans = max(ans, count(tmp, tmp[0][0]));
					}
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <stdio.h>

using namespace std;
 
int main(){

	int sum,i;
	char number[1001];
	
	while(1){
		scanf("%s",number);
		sum=0;
		if (number[0]=='0') break;
		for(i=0;i<1000;i++){
			if(number[i] == '\0') break;
			sum = sum + number[i]-'0';
		}
		cout << sum << endl;
	}
	
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int n,mp[1010][1010],head[1000010],tot,deg[1000010],num[1010][1010],Num,dp[1000010],ans;
struct node{
	int ed,last;
}G[3000010*2];
void Add(int st,int ed){
	tot++;
	G[tot]=node{ed,head[st]};
	head[st]=tot;
}
queue<int> Q;
bool vis[1010*1010];
int Hash(int x,int y){
	if(num[x][y]==0&&num[y][x]==0)return num[x][y]=num[y][x]=++Num;
	return num[x][y];
}
int main(){
	tot=0;
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++)cout<<num[i][j]<<" ";
//		cout<<endl;
//	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n-1;j++)scanf("%d",&mp[i][j]);
		for(int j=1;j<=n-2;j++){
			
			Add(Hash(i,mp[i][j]),Hash(i,mp[i][j+1])),deg[Hash(i,mp[i][j+1])]++;
		}
	}
//	for(int i=1;i<=Num;i++){
//		for(int j=head[i];~j;j=G[j].last){
//			int t=G[j].ed;
//			cout<<i<<" "<<t<<endl;
//		}
//	}
	int Cnt=0;
	for(int i=1;i<=Num;i++){
		if(!deg[i]){
			Q.push(i);
			while(!Q.empty()){
				int now=Q.front();
				Q.pop();
				if(vis[now])continue;
				vis[now]=true;
//				cout<<now<<endl;
				Cnt++;
				for(int i=head[now];~i;i=G[i].last){
					int t=G[i].ed;
//					cout<<t<<"DD"<<endl;
					deg[t]--;
					dp[t]=max(dp[t],dp[now]+1);
					if(deg[t]==0){
						Q.push(t);
					}
				}
			}
		}
	}
//	for(int i=1;i<=Num;i++)cout<<deg[i]<<" ";
//	cout<<endl;
	if(Cnt!=Num){
		puts("-1");
		return 0;
	}
	for(int i=1;i<=Num;i++)ans=max(ans,dp[i]);
	cout<<ans+1;
	return 0;
}

Measured memory_bytes: 30464
H, W, K = map(int, input().split())
S = [list(map(int, input())) for _ in range(H)]
ans = 10**18
for i in range(2**(H-1)):
    flag2 = False
    tate = 0
    tmp = [0 for _ in range(H)]
    for k in range(W):

        flag1 = False
        for j in range(H):
            if S[j][k] == 1:
                tmp[j] += 1
        tmp2 = tmp[:]
        for j in range(H - 1):
            if not ((i >> j) & 1):
                tmp2[j + 1] += tmp2[j]
        for j in range(H):
            if tmp2[j] > K:
                tate += 1
                flag1 = True
                break
        if flag1:
            tmp = [0 for _ in range(H)]
            for j in range(H):
                if S[j][k] == 1:
                    tmp[j] += 1
            tmp2 = tmp[:]
            for j in range(H - 1):
                if not ((i >> j) & 1):
                    tmp2[j + 1] += tmp2[j]
            for j in range(H):
                if tmp2[j] > K:
                    flag2 = True
                    break
        if flag2:
            break
    if flag2:
        continue

    yoko = 0
    for j in range(H - 1):
        if (i >> j) & 1:
            yoko += 1
    ans = min(ans, tate+yoko)

print(ans)

Measured memory_bytes: 51804
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {

    private static final int MOD = 1_000_000_007;
    private static final int INF = Integer.MAX_VALUE / 2;

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] S = sc.next().toCharArray();

        char prev = S[0];
        int count = 0;
        for (int i = 1; i < S.length; i++) {
            if (prev != S[i]) {
                count++;
                prev = S[i];
            }
        }

        System.out.println(count);
    }

    public static class Scanner {
        private BufferedInputStream inputStream;

        public Scanner(InputStream in) {
            inputStream = new BufferedInputStream(in);
        }

        public int nextInt() throws IOException {
            int num = 0;

            int read = skip();
            do {
                num = num * 10 + (read - 0x30);
            } while ((read = inputStream.read()) > 0x20);

            return num;
        }

        public int[] nextInt(int n) throws IOException {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }

            return array;
        }

        public long nextLong() throws IOException {
            long num = 0;

            int read = skip();
            do {
                num = num * 10 + (read - 0x30);
            } while ((read = inputStream.read()) > 0x20);

            return num;
        }

        public long[] nextLong(int n) throws IOException {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLong();
            }

            return array;
        }

        public String next() throws IOException {
            StringBuilder builder = new StringBuilder();

            int read = skip();
            do {
                builder.append((char) read);
            } while ((read = inputStream.read()) > 0x20);

            return builder.toString();
        }

        private int skip() throws IOException {
            int read;
            while ((read = inputStream.read()) <= 0x20)
                ;

            return read;
        }
    }
}


Measured memory_bytes: 9424
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
int n;
const ll t = 200000;
cin >> n;
ll sum = 0;
vector<ll> a(t);
rep(i,n){
    ll l;
    cin >> l;
    a[l]++;
    sum += l;

}

cout << endl;
int q;
cin >> q;
rep(i,q){
    ll b,c;
    cin >> b >> c;
    sum -= b*a[b];
    sum += c*a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << sum << endl;

}
return 0;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);
const ll MOD = 1e9 + 7;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    ll n, k; cin >> n >> k;
    ll ans = 0;
    ll l = 0, r = 0;
    Rep(i, 0, k-1) l += i;
    Rep(i, n-k+1, n) r += i;
    ans += r - l + 1;
    Rep(i, k+1, n+1){
        l += i-1;
        r += n - (i-1);
        ans += r - l + 1;
        ans %= MOD;
    }
    cout << ans << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX = 1000;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)

// ax+by=gcd(a,b)の解(x,y)を求める
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a/b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}

ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

#define MAX_P 1000001
ll fact[MAX_P];	// n! mod p のテーブル O(p)

void make_fact(ll p) {
	ll n, wp;
	for (ll i = 0; i < MAX_P; i++) {
		if (i == 0) n = 1;
		else n = (n * i) % p;
		fact[i] = n;
	}
}

// n!=a p^eとしたときのa mod pを求める。O(log_p n)
ll mod_fact(ll n, ll p, ll& e) {
	e = 0;
	if (n == 0) return 1;

	// pの倍数の部分を計算
	ll res = mod_fact(n/p, p, e);
	e += n / p;

	// (p-1)!≡-1なので,(p-1)!^(n/p)はn/pの偶奇だけで計算できる
	if (n/p % 2 != 0) return res * (p - fact[n%p]) % p;
	return res * fact[n%p] % p;
}

// nCk mod pを求める。O(log_p n)
ll mod_comb(ll n, ll k, ll p) {
	if (n < 0 || k < 0 || n < k) return 0;
	ll e1, e2, e3;
	ll a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n-k, p, e3);
	if (e1 > e2 + e3) return 0;
	return a1 * mod_inverse((a2*a3)%p, p) % p;
}

int main() {
	ll x, y; cin >> x >> y;
	make_fact(MOD);
	ll ax, ay;
	ax = x;
	while(1) {
		ll tmp = 2 * ax;
		if (y == tmp) {
			if (ax == x) {
				ay = 0; break;
			} else {
				if (ax == 0) {
					ax = -1; ay = -1; break;
				} else if (ax == 1) {
					ax = 0; continue;
				} else {
					ax -= 2; continue;
				}
			}
		} else if (tmp > y) {
			if (ax == 0) {
				ax = -1; ay = -1; break;
			} else if (ax == 1) {
				ax = 0; continue;
			} else {
				ax -= 2; continue;
			}
		} else {
			ay = y - tmp;
			if (ax + ay * 2 == x) {
				break;
			} else if (ax == 0) {
				ax = -1; ay = -1; break;
			} else if (ax == 1) {
				ax = 0; continue;
			} else {
				ax -= 2; continue;
			}
		}
	}
	if (ax == -1 && ay == -1) {
		cout << "0" << endl; return 0;
	}
	ll ret = mod_comb(ax+ay, ax, MOD);
	cout << ret << endl;
}

Measured memory_bytes: 11464
#include <iostream>
#include <vector>


int main(void){
    int n,m;
    std::cin >> n >> m;
    for(int i = 0;i<m;i++){
        int a;
        std::cin >> a;
        n -= a;
    }
    if(n < 0) n = -1;
    std::cout << n << std::endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

const int MOD = 1e9+7;

int t[100000], a[100000];
bool up[100000];

int main(void) {
    int i, n;
    scanf("%d",&n);
    REP (i,n) scanf("%d",&t[i]);
    REP (i,n) scanf("%d",&a[i]);
    REP (i,n) {
        if (i == n-1 || a[i] > a[i+1])
            up[i] = true;
        else
            up[i] = false;
    }
    ll ans = 1;
    REP (i,n) {
        if (i == 0 || t[i-1] < t[i]) {
            if (up[i] && t[i] != a[i] || !up[i] && t[i] > a[i]) {
                puts("0");
                return 0;
            }
        }
        else {
            if (up[i]) {
                if (t[i] < a[i]) {
                    puts("0");
                    return 0;
                }
            }
            else {
                ans *= min(a[i],t[i]);
                ans %= MOD;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1152
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      int n = int.Parse(Console.ReadLine());
      string[] input = Console.ReadLine().Split();
      int a = int.Parse(input[0]);
      int b = int.Parse(input[1]);
      
      List<int> p = Console.ReadLine().Split().ToList().ConvertAll(x => int.Parse(x));
      //List<int> ans1 = new List<int>();
      //List<int> ans2 = new List<int>();
      //List<int> ans3 = new List<int>();
      int ans1 = 0;
      int ans2 = 0;
      int ans3 = 0;
      
      foreach (int i in p)
      {
        if (i<=a)
        {
          ans1+=1;
        }
        else if (a+1<=i && i<=b)
        {
          ans2+=1;
        }
        else if (b+1<=i)
        {
          ans3+=1;
        }
      }
      Console.WriteLine(Math.Min(Math.Min(ans1,ans2),ans3));
      
    }
}


Measured memory_bytes: 28376
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

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

    int A, B, C;
    cin >> A >> B >> C;
    int sum = 0, cnt = 0;
    REP(i, C) {
        ++cnt;
        sum += A;
        if (cnt % 7 == 0) sum += B;
        if (sum >= C) {
            cout << cnt << endl;
            break;
        }
    }
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int q; cin >> q;
	string t[2];
	int u = 0;
	while(q--){
		int tmp; cin >> tmp;
		if(tmp == 1){
			u = 1-u;
		}else{
			int f; cin >> f; --f;
			char c; cin >> c;
			t[f ^ u].push_back(c);
		}
	}
	reverse(t[u].begin(), t[u].end());
	if(u == 1) reverse(s.begin(), s.end());
	cout << t[u] << s << t[1-u] << "\n";
}

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

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  map<int,int> score;

  int mx = 0;
  rep(i, n) {
    int d; cin >> d;
    ++score[d];
    chmax(mx, d);
  }

  int ans = 0, x = 0;
  rep(i, mx+1) {
    x += score[i];

    if (x == n/2) ++ans;
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 8308
// ※※※ 解答不能 ※※※
// snuke氏.
// https://atcoder.jp/contests/code-festival-2017-qualb/submissions/1636517
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    multiset<string> s;
    rep(i, 3){
        int n;
        scanf("%d", &n);
        rep(j, n) s.insert(string(1, 'a' + i));
    }
    while(s.size() > 1){
        auto it = s.end();
        --it;
        string x = *(s.begin()) + *it;
        s.erase(it);
        s.erase(s.begin());
        s.insert(x);
    }
    string ans = *(s.begin());
    printf("%s\n", ans.c_str());
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  string a,b;
  cin >> a >> b;
  if (a==b) cout << "H" << endl;
  else cout << "D" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)

#define FOREACH(x,a) for(auto&& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_ll.hpp>
// using namespace boost::multiprecision; // cpp_ll

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair


signed main(){
    CIN(n);
    V v(n+2,0);
    FOR(i,2,n+1){
        int now = i;
        V hogs;
        FOR(j,2,i+1){
            while(now % j == 0){
                ++v[j];
                now /= j;
            }
        }
    }

    vector<V> dp(n+2, V(76, 0));
    dp[0][1]=1;

    REP(i,n+1){
        REP(j,76){
            REP(k,v[i] + 1){
                int aft = j * (k + 1);
                if(aft <= 75)
                    dp[i+1][aft] += dp[i][j];
            }
        }
    }
    COUT(dp[n+1][75]);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int W,H,x,y,r,i=0;
  scanf("%d",&W);
   scanf("%d",&H);
    scanf("%d",&x);
     scanf("%d",&y);
      scanf("%d",&r);
      if(r<=x && x<=W-r && r<=y && y<=H-r)
	  printf("Yes\n");
      else
	printf("No\n");
      
   return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000
int N;
void Q(string s){
	cout<<"? "<<s<<endl;
}
void A(string s){
	cout<<"! "<<s<<endl;
	//if(stoi(s)==N)cout<<"Yes"<<endl;
}

char get(string x){
	char c;
	cin>>c;
	/*
	long long xx = stoll(x);
	string n = to_string(N);
	
	if(xx>N&&x>n)return 'Y';
	if(xx<=N&&x<=n)return 'Y';
	return 'N';
	*/
	return c;
}

int main(){
	//cin>>N;
	
	string S(18,'9');
	
	for(int i=0;i<9;i++){
		int ok = -1,ng = 10;
		if(i==0)ok=0;
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			S[i] = mid+'0';
			Q(S);
			char c = get(S);
			if(c=='Y')ng=mid;
			else ok = mid;
		}
		S[i] = ok+1+'0';
	}
	for(int i=9;i<18;i++)S[i] = '0';
	
	
	while(S.back()=='0')S.pop_back();
	
	if(S=="1"){
		S[0] = '2';
		while(true){
			Q(S);
			char c = get(S);
			if(c=='Y'){
				S[0] = '1';
				break;
			}
			else{
				S.push_back('0');
			}
		}
	}
	else{
		string t = "1";
		while(true){
			Q(t);
			char c = get(t);
			if(c=='Y'){
				t.push_back('0');
			}
			else{
				
				while(S.size()+1!=t.size())S.push_back('0');
				break;
			}
		}
	}
	
	A(S);
			
	
	return 0;
}

Measured memory_bytes: 3704
import bisect
import sys
import math

verbose = False


def get_iv():
    args = sys.stdin.readline()
    argv = args.split()
    iargv = [int(arg) for arg in argv]
    return iargv


def get_fv():
    args = sys.stdin.readline()
    argv = args.split()
    iargv = [float(arg) for arg in argv]
    return iargv


def calc_dist(Lhs, Rhs):
    dist = 0
    for off in range(len(Lhs)):
        dx = Lhs[off] - Rhs[off]
        dist += dx * dx
    dist = math.sqrt(dist)
    return dist


def is_int(fl):
    ifl = int(fl + .5)
    df = abs(ifl - fl)
    return df < 1e-4


def num_sqare(N, X):
    rv = 0
    for i in range(N):
        for j in range(i + 1, N):
            dist = calc_dist(X[i], X[j])
            if is_int(dist):
                rv += 1
    return rv


def main():
    specs = get_iv()
    N = specs[0]
    D = specs[1]
    X = []
    for i in range(N):
        v = get_iv()
        X.append(v)
    rv = num_sqare(N, X)
    print(rv)


if __name__ == '__main__':
    main()
    # mock()

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
    int A,B,i,j;
    j=0;
    scanf("%d %d",&A,&B);
    for(i=0;i<10010;i++){
        if(8*i/100 == A && 10*i/100 == B){
            j=1;
            break;
        }
    }
    if(j){
        printf("%d",i);
    }
    else
        printf("%d",-1);
    
    return 0;
}

Measured memory_bytes: 128
class Node:
    def __init__(self,key = None,left = None,right = None):
        self.key = key
        self.left = left
        self.right = right

    def insert(self,t,key):
        if t.key == None:
            t.key = key
            return
        y = None 
        x = t
        while x is not None:
            y = x
            if key<x.key:x = x.left
            else        :x = x.right
        if y is None  :t = Node(key)
        elif key<y.key:y.left = Node(key)
        else          :y.right = Node(key)

    def find(self,t,key):
        x = t
        while x is not None:
            if x.key==key:return True
            if key<x.key:x = x.left
            else        :x = x.right
        return False

    def inorder(self):
        if self.left!=None:self.left.inorder()
        print (' %d'%self.key,end = '')
        if self.right!=None:self.right.inorder()

    def preorder(self):
        print (' %d'%self.key,end = '')
        if self.left!=None:self.left.preorder()
        if self.right!=None:self.right.preorder()

    def walk(self):
        self.inorder()
        print ()
        self.preorder()
        print ()


def main():
    Tree = Node()
    q = int(input())
    for _ in range(q):
        com = list(input().split())
        if com[0] == 'insert':
            Tree.insert(Tree,int(com[1]))
        elif com[0] == 'find':
            print('yes' if Tree.find(Tree,int(com[1])) else 'no')
        else :
            Tree.walk()

if __name__ == '__main__':
    main()




Measured memory_bytes: 85260
#include <iostream>
#include <vector>

#define r(i, n) for (int i = 0; i < n; i++)

using namespace std;

// input
vector<int> S, T;

int main(){
    // input
    int n, q; 
    cin >> n;
    while(n--){
        int a;
        cin >> a;
        S.push_back(a);
    }
    cin >> q;
    while (q--)
    {
        int a;
        cin >> a;
        T.push_back(a);
    }

    // linear search
    int C = 0;
    r(i, T.size()){
        r(j, S.size()){
            if(T[i] == S[j]){
                C++;
                break;
            }
        }
    }

    cout << C << endl;
}


Measured memory_bytes: 3136
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int c=0;
  for(int i=0;i<s.size();i++){if(s[i]=='A')c++;}
  if(c==0 || c==3)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dd double
using namespace std;
const ll MOD = 1e9 + 7;

int minimumChar(string S1, string S2) 
{ 
    // Get the sizes of both strings 
    int n = S1.size(), m = S2.size(); 
  
    int ans = INT_MAX; 
  
    // Traverse the string S2 
    for (int i = 0; i < m - n + 1; i++) { 
        int minRemovedChar = 0; 
  
        // From every index in S2, check the number of 
        // mis-matching characters in substring of 
        // length of S1 
        for (int j = 0; j < n; j++) { 
            if (S1[j] != S2[i + j]) { 
                minRemovedChar++; 
            } 
        } 
  
        // Take minimum of prev and current mis-match 
        ans = min(minRemovedChar, ans); 
    } 
  
    // return answer 
    return ans; 
} 
  
// Driver Code 
int main() 
{ 
    string s1,s2;
    cin>>s2>>s1;
    
  
    cout << minimumChar(s1,s2)<<endl;
  
    return 0; 
} 

Measured memory_bytes: 3644
N = int(input())
A = []
for i in range(N):
  line1 = [int(i) for i in input().split()]
  A.append(line1)
mem = [[0] * 3 for i in range(N)]
mem[0][0] = A[0][0]
mem[0][1] = A[0][1]
mem[0][2] = A[0][2]
for i in range(1, N):
  mem[i][0] = max(mem[i-1][1], mem[i-1][2]) + A[i][0]
  mem[i][1] = max(mem[i-1][0], mem[i-1][2]) + A[i][1]
  mem[i][2] = max(mem[i-1][0], mem[i-1][1]) + A[i][2]
print("%s" % max(mem[N-1]))

Measured memory_bytes: 74840
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>

int main(){
	int a, b, k, count = 0;
	std::cin >> a >> b >> k;
	for(int i = 100; i > 0; i--){
		if(a % i == 0 && b % i == 0){
			count++;
		}
		if(count == k){
			std::cout << i << std::endl;
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] X = new int[N];
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
        }
        int[] Xclone = X.clone();
        Arrays.sort(Xclone);
        int front = Xclone[N/2-1];
        int back = Xclone[N/2];
        StringBuilder sb = new StringBuilder();
        for (int i : X) {
            if (i <= front) {
                sb.append(back + "\n");
            } else if (back <= i) {
                sb.append(front + "\n");
            }
        }
        System.out.println(sb);
    }    
}


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

int N;
vector<double> p;
// dp[i][j]
// in i coins j coins are the front
double dp[3100][3100] = {0};

int main(){
  cin >> N;
  p.resize(N);
  for(int i=0;i<N;++i) cin >> p[i];
  dp[0][0] = 1;
  for(int i=0;i<N;++i){
    for(int j=0;j<=i;++j){
      // i coin is the front
      dp[i+1][j+1] += dp[i][j] * p[i];
      // i coin is the back
      dp[i+1][j] += dp[i][j] * (1-p[i]);
    }
  }
  double ans = 0;
  for(int i=(N+1)/2;i<=N;++i){
    ans += dp[N][i];
  }
  cout << fixed << setprecision(10) <<  ans << endl;
  return 0;
}

Measured memory_bytes: 72320
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
   int n;
   string s;
   cin >> n >> s;
   int x = 0;
   int ans=0;
   REP(i, n){
       if(s[i]=='I') x+=1;
       else x-=1;
       if(ans<x) ans = x;
   }
  
   cout << ans << endl;
   
   
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int x,a;
    cin>>x>>a;
    if(x>=a)cout<<10<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn = 2e6 + 5;
int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	int ans = 0;
	for (int i = 0; i < s1.length(); i++)
	{
		if (s1[i] != s2[i])ans++;
	}cout << ans << endl;
}

Measured memory_bytes: 3924