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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string S; cin >> S;
  string result = (S[0]==S[1]&&S[1]==S[2]) ? "No" : "Yes";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));


struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);


}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

	long double p[3002];
	long double arr[3002][3002];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> p[i];

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			arr[i][j] = 0;
		}
	}
	arr[1][0] = 1 - p[1];
	arr[1][1] =p[1];
	for (int i = 2; i <= n; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			arr[i][j] = arr[i - 1][j] * (1 - p[i]);
			if (j)
				arr[i][j] += arr[i - 1][j-1] * ( p[i]);

		}
	}
	long double ans = 0;
	for (int i = (n + 1) / 2; i <= n; i++)
	{
		ans += arr[n][i];
	}
	cout << fixed << setprecision(12) << ans;






}


Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string N;
  cin >> N;
  bool comprise9 = false;
  for(int i = 0; i < N.size(); i++){
    if(N[i] == '9'){
      comprise9 = true;
    }
  }
  if(comprise9){
    cout << "Yes" << endl;
  } else {
  	cout << "No" << endl;
  }
}

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

using namespace std;

int main()
{
    int a, b, c;
    int n;
    int result[301];
    int x[1001], y[1001], z[1001], r[1001];
    
    memset(result, -1, sizeof(result));

    cin >> a >> b >> c >> n;

    while (a != 0) {
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> z[i] >> r[i];
        if (r[i] == 1) {
            result[x[i]] = result[y[i]] = result[z[i]] = 1;
        }
    }

    for (int j = 0; j < 2; j++) {
        for (int i = 0; i < n; i++) {
            if (result[x[i]] == 1 && result[y[i]] == 1 && result[z[i]] == -1) {
                result[z[i]] = 0;
            }
            else if (result[x[i]] == 1 && result[y[i]] == -1 && result[z[i]] == 1) {
                result[y[i]] = 0;
            }
            else if (result[x[i]] == -1 && result[y[i]] == 1 && result[z[i]] == 1) {
                result[x[i]] = 0;
            }
        }
    }

    for (int i = 1; i <= a+b+c; i++) {
        if (result[i] == -1) cout << 2 << endl;
        else cout << result[i] << endl;
    }
    cin >> a >> b >> c >> n;

    memset(result, -1, sizeof(result));
    }
}



Measured memory_bytes: 3028
//last edited at 26.8.2015 by charis

#include<iostream>
#include<cmath>
using namespace std;

/* Time Limit Exceeded  
bool isPrime(int x){
	if(x<=1) return false;
	for(int i=2; i<x; i++){
		if(x%i==0) return false;
	}
	return true;
}
*/

bool isPrime(int x){ 
	if(x==2) return true;
	if(x<=1 || x%2==0) return false; 
	for(int i=3; i<=sqrt(x); i+=2){
		if(x%i==0) return false;
	}
	return true;
}

int main(){
	int N;	
	cin >> N;
	int A[N];
	for(int i=0; i<N; i++){
		cin >>A[i];
	}
	int c=0;
	for(int i=0; i<N; i++){
		if(isPrime(A[i])) c++;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

struct UnionFind {
    vector<int> par;

    UnionFind (int n) : par (n, -1) {} //親は-1

    int root (int x) {
        if (par[x] < 0) return x; //自身が親
        else
            return par[x] = root (par[x]); //再帰
    }

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

    bool merge (int x, int y) {
        x = root (x);
        y = root (y);
        if (x == y) return false;
        if (par[x] > par[y]) swap (x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size (int x) { return -par[root (x)]; }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    set<int> dame[n];
    UnionFind uf (n);
    rep (i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        dame[a].insert (b);
        dame[b].insert (a);
        uf.merge (a, b);
    }
    rep (i, 0, k) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (uf.same (a, b)) {
            dame[a].insert (b);
            dame[b].insert (a);
        }
    }
    rep (i, 0, n) {
        int mem = uf.size (i) - 1 - dame[i].size();
        cout << mem << " ";
    }
    cout << "\n";
}

Measured memory_bytes: 24704
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
    
ll n,cnt,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------


template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;
 
public:
  u64 a;
 
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    using mint=modint<MOD>;

    cin>>n>>s;
    rep(i,2*n){
        if(i%2==0){
            if(s[i]=='B')s[i]='W';
            else s[i]='B';
        }
    }
    rep(i,2*n){
        if(s[i]=='B')cnt++;
    }
    if(cnt!=n||s[0]=='B')Cout(0);
    else{
        cnt=0;
        mint ans=mint(1);
        rep(i,2*n){
            if(s[i]=='W')cnt++;
            else{
                ans*=cnt;
                cnt--;
            }
        }
        rrep(i,1,n+1)ans*=i;
        Cout(ans.value());
    }
    return 0;
}

Measured memory_bytes: 720
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

ans = 0
cnt = Counter(A)
for a in A:
    if cnt[a] == 0:
        continue
    cnt[a] -= 1
    b = 2**a.bit_length() - a
    if cnt[b] > 0:
        ans += 1
        cnt[b] -= 1
print(ans)


Measured memory_bytes: 33296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;

  double ans = 0;
  double o = 1;
  rep(i, n) {
    int a;
    cin >> a;
    ans += o/a;
  }

  printf("%.8lf", 1/ans);
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

ll MAX = 1000000000000;

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

    int N, K;
    cin >> N >> K;

    vll H(N);
    for(int i=0;i<N;i++) cin >> H[i];

    vll dp(N, MAX);
    dp[0] = 0;
    for(int i=1;i<N;i++) {
        for(int j=max(0, i-K); j<i;j++) {
            dp[i] = min(dp[i], dp[j] + abs(H[i] - H[j]));
        }
        dp[i] = min(dp[i], dp[i-1] + abs(H[i] - H[i-1]));
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define inf 1048576
#define N 100
#define W -1
#define B 1

int MST(int);
int A[N][N];

int main(){
  int n, i, j;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &A[i][j]);
      if(A[i][j] == -1)
	A[i][j] = inf;
    }
  }

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

int MST(int n){
  int i, u, v, min, sum=0;
  int d[N], pi[N], color[N];

  for(i = 0; i < n; i++){
    d[i] = inf;
    pi[i] = -1;
    color[i] = W;
  }

  d[1] = 0;

  while(1){
    min = inf;
    for(i = 0; i < n; i++){
      if(color[i] != B && d[i] < min){
	min = d[i];
	u = i;
      }
    }

    if(min == inf) break;

    color[u] = B;

    for(v = 0; v < n; v++){
      if(color[v] != B && A[u][v] < d[v]){
	pi[v] = u;
	d[v] = A[u][v];
      }
    }
  }
  
  for(i = 0; i < n; i++)
    sum += d[i];
  
  return sum;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define MOD 998244353
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n;
    cin>>n;
    Vi d(n);
    REP(i,0,n){
        cin>>d[i];
        if(i==0) if(d[i]!=0) {cout<<0<<endl;return 0;}    
        if(i!=0) if(d[i]==0) {cout<<0<<endl;return 0;}    
    }
    int maxd=*max_element(ALL(d));

    map<int,int> ma;
    REP(i,0,n){
        ma[d[i]]++;
    }

    int ans=1;
    REP(i,0,maxd){
        if(ma[i]==0){cout<<0<<endl;return 0;}
        ans = (ans * mypow(ma[i],ma[i+1],MOD))%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

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

    int total = 0;
    map<int, int> T;
    for (int i = 1; i <= N; i++) {
        cin >> T[i];
        total += T[i];
    }

    int M;
    cin >> M;

    vector<map<string, int>> drinks(M);
    int P, X;
    for (int i = 0; i < M; i++) {
        cin >> P >> X;
        drinks.at(i)["P"] = P;
        drinks.at(i)["X"] = X;
    }

    for (int i = 0; i < M; i++) {
        int P = drinks.at(i)["P"];
        int X = drinks.at(i)["X"];
        int time = total - T[P] + X;
        cout << time << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# comb_mod(n, c, r, mod, fac, den) ≡ nCr
def prepare(n, mod):
    # fac[i] ≡ i!
    fac = [1]
    for i in range(1, n+1):
        fac.append((fac[-1] * i) % mod)

    # rec ≡ 1 / n!
    rec = pow(fac[-1], mod-2, mod)

    # den[i] ≡ 1 / i!
    den = [1 for _ in range(n+1)]
    den[n] = rec
    for i in range(n-1, 0, -1):
        rec = (rec * (i+1)) % mod
        den[i] = rec
    
    return fac, den

def comb_mod(n, r, mod, fac, den):
    return (fac[n] * den[r] * den[n - r]) % mod

n, k = map(int, input().split())
mod = 10**9 + 7
fac, den = prepare(2*n-1, mod)

if k >= n-1:
    print(comb_mod(2*n-1, n, mod, fac, den))
else:
    ans = 0
    for i in range(k+1):
        ans += comb_mod(n-1, i, mod, fac, den) * comb_mod(n, i, mod, fac, den)
        ans %= mod
    print(ans)

Measured memory_bytes: 34808
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)
using Graph = vector<vector<int>>;

int main(){
    int h,w;
    cin >> h >> w;
    char s;
    int x[h][w];
    long N=0;
    F(i,0,h){
        F(j,0,w){
            cin >> s;
            if(s=='.'){
                x[i][j]=N;
                ++N;
            }
            else if(s=='#'){
                x[i][j]=-1;
            }
        }
    }
    Graph G(N);
    F(i,0,h){
        F(j,0,w){
            if(j<w-1 && x[i][j]!=-1 && x[i][j+1]!=-1){
               //cout << x[i][j] << ' ' << x[i][j+1] << endl;
                int t=x[i][j],tt=x[i][j+1];
                G[t].push_back(tt);
                G[tt].push_back(t);
            }
        }
        if(i!=0){
            F(j,0,w){
                if(x[i][j]!=-1 && x[i-1][j]!=-1){
                    //cout << x[i-1][j] << ' ' << x[i][j] << endl;
                    int t=x[i-1][j],tt=x[i][j];
                    G[t].push_back(tt);
                    G[tt].push_back(t);
                }
            }
        }
    }
    /* F(i,0,N){
        cout << i << ' ';
        for(int j : G[i]){
            cout  << j << ' ';
        }
        cout << endl;
    } */
    int ans=0;
    F(i,0,N){
        vector<int> dist(N,-1);
        queue<int> que;
        dist[i]=0;
        que.push(i);
        while(!que.empty()){
            int v=que.front();
            que.pop();
            for(int nv : G[v]){
                if(dist[nv]!=-1) continue;
                dist[nv]=dist[v]+1;
                que.push(nv);
                int M=dist[nv];
                ans=max(ans,M);
            }
        }
    }
    //F(i,0,N) cout << i << ' ' << dist[i] << endl;
    cout << ans << endl;
    return 0;
}

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

const long long INF = 1e9 + 7;

struct Day {
	int first, second, third;
};

int main() {
	int n;
	cin >> n;
	vector<Day> days(n);
	for (int i = 0; i < n; i++) {
		int first, second, third;
		cin >> first >> second >> third;
		days[i] = { first, second, third };
	}

	vector<vector<int>> dp(n, vector<int>(3, 0));

	dp[0][0] = days[0].first;
	dp[0][1] = days[0].second;
	dp[0][2] = days[0].third;

	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i][0], max(dp[i - 1][1], dp[i - 1][2]) + days[i].first);
		dp[i][1] = max(dp[i][1], max(dp[i - 1][0], dp[i - 1][2]) + days[i].second);
		dp[i][2] = max(dp[i][2], max(dp[i - 1][1], dp[i - 1][0]) + days[i].third);
	}

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


Measured memory_bytes: 6912
def floor_sum(n,m,a,b):
    ans=0
    if a>=m:
        ans+=(n-1)*n*(a//m)//2
        a%=m
    if b>=m:
        ans+=n*(b//m)
        b%=m
    y_max=(a*n+b)//m
    x_max=(y_max*m-b)
    if y_max==0:
        return ans
    ans+=(n-(x_max+a-1)//a)*y_max
    ans+=floor_sum(y_max,a,m,(a-x_max%a)%a)
    return ans

T=int(input())
for i in range(T):
    N,M,A,B=map(int,input().split())
    print(floor_sum(N,M,A,B))


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >>s;
  if(s=="SSS") cout <<0;
  else if(s=="RRR") cout <<3;
  else if(s=="RRS"||s=="SRR") cout <<2;
  else  cout <<1;
  return 0;
}

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


int main() {
  int n, x;
  cin >> n >> x;
  vector<int> vec(n+1);
  vec[0] = 0;
  rep(i,n){
    int l;
    cin >> l;
    vec[i+1] = vec[i] + l;
  }
  int ans = 0;
  rep(i,n+1){
    if(vec[i] <= x){
      ans++;
    }
  }
  cout << ans;
    
  return 0;
}

Measured memory_bytes: 3632
n, m = [int(x) for x in input().split()]
dict = {}
flg = True
for i in range(m):
    s, c = [int(x) for x in input().split()]
    if s in dict.keys() and dict[s] != c:
        flg = False
        break
    else:
        dict[s] = c
for i in range(1, n + 1):
    if not i in dict.keys():
        if i == 1 and n > 1:
            dict[i] = 1
        else:
            dict[i] = 0
if n > 1 and dict[1] == 0:
    flg = False
res = 0
if flg:
    for i in range(1, n + 1):
        res += dict[i] * 10 ** (n - i)
print(res if flg else -1)


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
using namespace std;
int y[101],r,n;

bool check(double cy){
  double x=sqrt(r*r-cy*cy);
  if(cy>=0)x=r;
  int L=(-x-0.9999),R=(x+0.9999),hb[101]={};

  for(int i=L+50;i<R+50;i++){
    int x1=i-49-i/50;
    double y1=y[i]-cy;
    if(sqrt(x1*x1+y1*y1)>=r)hb[i]++;
  }
  for(int i=L+50;i<R+50;i++)if(!hb[i])return 0;
  return 1;
}

int main(){
  while(1){
    cin>>r>>n;
    if(!r&&!n)break;
    for(int i=0;i<100;i++)y[i]=0;

    for(int i=0;i<n;i++){
      int x1,x2,h;
      cin>>x1>>x2>>h;
      for(int j=x1;j<x2;j++) y[j+50]=max(y[j+50],h);
    }
    double ans=0;
    while(check(ans-r))ans+=0.0009;
    cout << ans-0.0009<<endl;
  }
  return 0;
}

Measured memory_bytes: 1244
# include<bits/stdc++.h>
using namespace std;
int main()
{
	string p;
	cin>>p;
	int t=1;
	bool ok=false;
	for(int i=1;i<4;i++){
		if(p[i]==p[i-1]){
			t++;
		}
		else t=1;
		if(t>=3) ok=true;
	}
	if(ok) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace V0105{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            sr.Next<string>(100, 2)
                .TakeWhile(s => s[0] != null)
                .GroupBy(s => s[0])
                .OrderBy(g => g.Key)
                .ToList()
                .ForEach(g =>{
                    Console.WriteLine(g.Key);
                    Console.WriteLine(string.Join(" ",
                        g.Select(s => int.Parse(s[1]))
                        .OrderBy(s => s)
                        .Select(x => x.ToString())
                        .ToArray()));
                });
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var result = new T[x];
            for(var i = 0; i < x; ++i) result[i] = Next<T>();
            return result;
        }

        public T[][] Next<T>(int y, int x){
            var result = new T[y][];
            for(var i = 0; i < y; ++i) result[i] = Next<T>(x);
            return result;
        }
    }
}

Measured memory_bytes: 11160
#include<iostream>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  if(b[0]=='H') cout << a[0] << endl;
  else if(b[0]=='D'){
    if(a[0]=='H') cout << "D" << endl;
    else cout << "H" << endl;
  }
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> vec(11);
  int r,D;
  cin>>r>>D>>vec.at(0);
  
  for(int i=0;i<vec.size()-1;i++){
    
    vec.at(i+1)=vec.at(i)*r-D;
    
    cout<<vec.at(i+1)<<endl;
  }
}


Measured memory_bytes: 256
/**
 Author:mohanr
**/
#include<bits/stdc++.h>
using namespace std;
#define fastinput() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define repdi(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll INF=1e18;
const int inf=1e9;
const int mod=1e9+7;
ll powmod(ll a,ll b){
 ll res=1;
 a%=mod;
 for(;b;b>>=1){
  if(b&1) res=res*a%mod;
  a=a*a%mod;
 }
 return res;
}
ll invmod(ll a){
 return powmod(a,mod-2);
}
int main(){
 fastinput();
 ll n;
 cin>>n;
 string a,b,c;
 cin>>a>>b>>c;
 ll count=0;
 for(ll i=0;i<n;i++){
  map<char,ll> m;
  m[a[i]]++;
  m[b[i]]++;
  m[c[i]]++;
  if(m.size()==3) count+=2;
  else if(m.size()==2) count+=1;
 }
 cout<<count<<endl;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int x_diophantine = 0,y_diophantine = 0;

int d_diophantine;// = gcd(a,b);

void euclid(int a,int b)
{
    if (b == 0)
    {
        x_diophantine =1;
        y_diophantine=0;
        d_diophantine=a;
        return;
    }
    euclid(b,a%b);
    int x1 = y_diophantine;
    int y1 = x_diophantine-(a/b)*y_diophantine;
    x_diophantine = x1;
    y_diophantine = y1;
}

int main()
{
    int m,n;
    cin >> m >> n;
    euclid(m,n);
    cout << x_diophantine << " " << y_diophantine << endl;
    //cout << "Hello world!" << endl;
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <string>

using namespace std;

int main(){
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    for(int i = 0; i < n; i++){
        if(k - 1 == i){
            s[i] += 32;
        }
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    string s;
    cin >> s;
    Int cost = 700;
    for (Int i = 0; i < (Int)s.length(); ++i) {
        if (s[i] == 'o') {
            cost += 100;
        }
    }
    cout << cost << endl;
    return 0;
}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    static tuple<int, int, int> lr[2][100000];
    static bool used[100000];

    cin >> n;
    for(int i=0;i<n;++i){
        int l, r;
        cin >> l >> r;
        lr[0][i] = lr[1][i] = tuple<int, int, int>{l, r, i};
    }
    sort(lr[0], lr[0]+n, [](auto x, auto y){ return get<1>(x) < get<1>(y); });
    sort(lr[1], lr[1]+n, [](auto x, auto y){ return get<0>(x) > get<0>(y); });    
    
    int64_t ans[2] = { 0, 0 };
    int pos = 0, nx[2] = { 0, 0 };
    int sw = 0;
    while(true){
        while(nx[sw] < n && used[get<2>(lr[sw][nx[sw]])]){ ++nx[sw]; }
        if(nx[sw] >= n) break;
        if(sw){
            if(pos >= get<0>(lr[sw][nx[sw]])) break;
            used[get<2>(lr[sw][nx[sw]])] = true;
            ans[0] += get<0>(lr[sw][nx[sw]]) - pos;
            pos = get<0>(lr[sw][nx[sw]]);
        }else{
            if(pos <= get<1>(lr[sw][nx[sw]])) break;
            used[get<2>(lr[sw][nx[sw]])] = true;
            ans[0] += pos - get<1>(lr[sw][nx[sw]]);
            pos = get<1>(lr[sw][nx[sw]]);
        }
        sw ^= 1;
    }
    ans[0] += abs<int>(pos);

    for(int i=0;i<n;++i) used[i] = false;
    pos = 0;
    nx[0] = nx[1] = 0;
    sw = 1;
    while(true){
        while(nx[sw] < n && used[get<2>(lr[sw][nx[sw]])]){ ++nx[sw]; }
        if(nx[sw] >= n) break;
        if(sw){
            if(pos >= get<0>(lr[sw][nx[sw]])) break;
            used[get<2>(lr[sw][nx[sw]])] = true;
            ans[1] += get<0>(lr[sw][nx[sw]]) - pos;
            pos = get<0>(lr[sw][nx[sw]]);
        }else{
            if(pos <= get<1>(lr[sw][nx[sw]])) break;
            used[get<2>(lr[sw][nx[sw]])] = true;
            ans[1] += pos - get<1>(lr[sw][nx[sw]]);
            pos = get<1>(lr[sw][nx[sw]]);
        }
        sw ^= 1;
    }
    ans[1] += abs<int>(pos);

    cout << max(ans[0], ans[1]) << endl;
    return 0;
}

Measured memory_bytes: 2688
h, w = map(int, input().split())
grid = []
for i in range(h):
  gridi = input()
  grid.append(gridi)
xcnt = [[0]*w for i in range(h)]
ycnt = [[0]*w for i in range(h)]
ans = -10**9
# print(grid, h, w)
for y in range(h):
  cnt = 0
  for x in range(w-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y][x+1] == "#":
      xcnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[y][w-1] == ".":
    xcnt[y][w-1] = cnt + 1
# print(xcnt)
for y in range(h):
  for x in range(w-1):
    if grid[y][w-1-x] == "#":
      continue
    if grid[y][w-1-x-1] == ".":
      xcnt[y][w-1-x-1] = xcnt[y][w-1-x]
# print(*xcnt)

for x in range(w):
  cnt = 0
  for y in range(h-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y+1][x] == "#":
      ycnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[h-1][x] == ".":
    ycnt[h-1][x] = cnt + 1
# print(ycnt)
for x in range(w):
  for y in range(h-1):
    if grid[h-1-y][x] == "#":
      continue
    if grid[h-1-y-1][x] == ".":
      ycnt[h-1-y-1][x] = ycnt[h-1-y][x]
# print(*ycnt)
for y in range(h):
  for x in range(w):
    ans = max(ans, xcnt[y][x] + ycnt[y][x] - 1)
print(ans)

Measured memory_bytes: 123096
#include <iostream>
#include <string>

using namespace std;

int main() {
	int A, B;
	char op;
	
	cin >> A >> op >> B;
	if(op == '+') {
		cout << (A + B) << endl;
	} else {
		cout << (A - B) << endl;
	}
	
	return 0;
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;

    int sum = 0;
    rep(1, n + 1) {
        if (i <= k) sum += x;
        else sum += y;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n,t; cin >> n >> t;
    int ans=INF;
    rep(i,n){
        int c,d; cin >> c >> d;
        if(d>t) continue;
        ans=min(ans,c);
    }
    if(ans==INF) cout << "TLE" << endl;
    else cout << ans << endl;
return 0;
}


Measured memory_bytes: 3636
package main

import (
	"fmt"
	"strconv"

	// Reader
	"bufio"
	"os"
	"strings"
)

func main() {
	s := nextLine()
	a, _ := strconv.Atoi(s[0])
	b, _ := strconv.Atoi(s[1])
	c, _ := strconv.Atoi(s[2])
	k, _ := strconv.Atoi(s[3])

	var r int
	switch {
	case k <= a :
		r = k
	case k <= (a + b) :
		r = a
	case k < (a + b + c) :
		r = a * 2 + b - k
	default :
		r = a - c
	}

	fmt.Println(r)
}

// Reader
var limit int = 1000
var rdr = bufio.NewReaderSize(os.Stdin, limit)

func nextLine() []string {
	return parseLine(readLine())
}

func readLine() string {
	buf := make([]byte, 0, limit)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func parseLine(s string) []string {
	slice := strings.Split(s, " ")
	return slice
}


Measured memory_bytes: 1752
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,c=1;cin>>a;
  vector<ll>b(a);
  rep(i,a){
    cin>>b[i];
    if(b[i]==0){
      cout<<0;
      return 0;
    }
  }
  rep(i,a){
        if(1000000000000000000/c<b[i]){
      cout<<-1;
      return 0;
    }
    c*=b[i];
  }
  cout<<c;
  }


Measured memory_bytes: 27468
use std::io::*;

struct Dice {
  top: usize,
  front: usize,
  right: usize
}

impl Dice {
  fn new() -> Self {
    Self {
      top: 0,
      front: 1,
      right: 2
    }
  }

  fn left(&self) -> usize { 5 - self.right }

  fn back(&self) -> usize { 5 - self.front }

  fn bottom(&self) -> usize { 5 - self.top }

  fn rotate_n(self) -> Self {
    Self {
      top: self.front,
      front: self.bottom(),
      ..self
    }
  }

  fn rotate_s(self) -> Self {
    Self {
      top: self.back(),
      front: self.top,
      ..self
    }
  }

  fn rotate_w(self) -> Self {
    Self {
      top: self.right,
      right: self.bottom(),
      ..self
    }
  }

  fn rotate_e(self) -> Self {
    Self {
      top: self.left(),
      right: self.top,
      ..self
    }
  }
}

fn main() {
  let stdin = stdin();
  let mut lines = stdin.lock().lines();

  let labels = lines.next().unwrap().unwrap();
  let directions = lines.next().unwrap().unwrap();

  let mut dice = Dice::new();

  for d in directions.chars() {
    dice = match d {
      'N' => dice.rotate_n(),
      'E' => dice.rotate_e(),
      'W' => dice.rotate_w(),
      'S' => dice.rotate_s(),
      _ => unreachable!()
    };
  }

  let top = labels.split_whitespace().nth(dice.top).unwrap();
  println!("{}", top);
}



Measured memory_bytes: 5024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int main() {
	ll n;
	ll sum = 0;
	cin>>n;
	for(ll i=1;i<=n;i++){
		if(i%3==0||i%5==0){
			continue;
		}
		sum+=i;
	} 
	cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
D = [[int(i) for i in input().split()] for _ in range(N)]

def judge() :
  c = 0
  for a, b in D :
    if a == b : 
      c += 1
    else :
      c = 0
    if c >= 3 :
      return 'Yes'
  return 'No'
  
print(judge())

Measured memory_bytes: 62552
import collections


def solve():
    N = int(input())
    A = [int(x) for x in input().split()]

    # verify inputs
    count = collections.Counter(A)

    if N%2 != 0 and (0 not in count or count[0] != 1):
        return 0

    i = 1 + (N%2)
    while i < N:
        if i not in count or count[i] != 2:
            return 0
        i += 2
    
    MOD = 10**9+7
    ans = 1
    M = N//2
    for i in range(M):
        ans = ans * 2 % MOD
    return ans


print(solve())



Measured memory_bytes: 14820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll x,y;
  cin >> x >> y;
  if(x % y == 0)cout << -1 << endl;
  else cout << x << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
const int N = 15;
long long dp[N][N] = {};
void build() {
    fill(dp[0], dp[0] + 10, 1);
    for (int i = 1; i < N; i++) {
        dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
        for (int j = 1; j < 10; j++)
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] + dp[i - 1][j + 1];
    }
}
int main() {
    build();
    long long n;
    cin >> n;
    long long r = 0, c = 0, cnt = 0;
    while (cnt < n) {
        c++;
        if (c == 10) {
            r++;
            c = 1;
        }
        cnt += dp[r][c];
    }
    long long ans = c;
    cnt = dp[r][c] - (cnt - n);
    while (r) {
        if (dp[r - 1][c - 1] >= cnt) {
            ans = ans * 10 + c - 1;
            r--, c--;
        }
        else if (dp[r - 1][c - 1] + dp[r - 1][c] >= cnt) {
            cnt -= dp[r - 1][c - 1];
            ans = ans * 10 + c;
            r--;
        }
        else {
            cnt -= dp[r - 1][c - 1] + dp[r - 1][c];
            ans = ans * 10 + c + 1;
            c = c + 1;
            r--;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int N=2e5+5,inf=1e9;
int n,i,mn,mx;ll ans;
struct arr{int x,y;}a[N];
bool operator < (arr A,arr B){return A.x<B.x;}
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int main(){
	for (n=read(),mn=1e9,i=1;i<=n;i++){
		int x=read(),y=read();
		if (x<y) swap(x,y);
		mn=min(mn,x);mx=max(mx,x);
		a[i]=(arr){y,x};
	}
	sort(a+1,a+n+1);a[0].x=inf;
	ans=(ll)(mx-mn)*(a[n].x-a[1].x);
	int v=(mx-a[1].x);mn=inf;mx=0;
	for (i=1;i<=n&&a[i].x<mn;i++){
		mn=min(mn,a[i].y);mx=max(mx,a[i].y);
		ans=min(ans,(ll)v*(max(a[n].x,mx)-min(mn,a[i+1].x)));
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 100005
using namespace std;

int n,x,ans;
vector< pair<int,int> > v;

int main() {

  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
    scanf("%d",&x);
    v.push_back(make_pair(x,i));
  }
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++) {
    ans+=abs(v[i].second-i-1)%2;
  }
  printf("%d",ans/2);

}


Measured memory_bytes: 1400
a, b = map(int, input().split())

x1 = a / 0.08
x2 = b / 0.10

for x in range(int(min(x1, x2))-10, int(max(x1, x2))+10):
    if int(x*0.08) == a and int(x*0.10) == b:
        print(x)
        exit()
print(-1)



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

int main() {
	int K, S;
	cin >> K >> S;

	int count = 0;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			int sum = S - (i + j);
			if (0 <= sum && sum <= K)count++;
		}
	}
	
	cout << count << endl;
}

Measured memory_bytes: 256
def calc(n, k):
	if n == 0:
		return 1
	if k == 1:
		return 0
	len = 2**(n+1)-3 # 1+len+1+len+1
	if k <= len+1:
		return calc(n-1, k-1)
	if k == len+2:
		return calc(n-1, len)+1
	if k <= len+len+2:
		return calc(n-1, len)+1+calc(n-1, k-len-2)
	if k == len+len+3:
		return 2**(n+1)-1

n, k = map(int, input().split())
print(calc(n, k))

Measured memory_bytes: 3064
char = input()
num = int(input())

for i in range(num):
    commands = input()
    command = commands.split(" ")
    start = int(command[1])
    stop = int(command[2])
    if command[0] == "replace":
        char = char[0:start] + command[3] + char[stop+1:]
    elif command[0] == "reverse":
        if start == 0:
            char = char[stop:0:-1] + char[0] + char[stop+1:]
        else:
            char = char[:start] + char[stop:start-1:-1] + char[stop+1:]
    elif command[0] == "print":
        print(char[start:stop+1])
    else:
        break


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n,q;
    cin >> n;
    vector<int> s(n);
    map<int, int> m;
    rep(i,n){
        cin >> s[i];
        m[s[i]] = 1;
    }
    cin >> q;
    vector<int> t(q);
    int ct = 0;
    rep(i,q){
        cin >> t[i];
        if(m[t[i]] == 1){
            ct++;
        }
    }
    cout << ct << endl;
}


Measured memory_bytes: 3180
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double want = sc.nextInt();
		double can = sc.nextInt();
		double min = sc.nextInt();
		double bakeNum = Math.ceil(want / can) ;
		System.out.println((int)(bakeNum * min));
	}
}

Measured memory_bytes: 35204
from collections import deque

def main():
    h,w=map(int,input().split())
    maze=[list(input()) for i in range(h)]
    d=[[-1]*w for i in range(h)]
    que=deque([])
    dd=((1,0),(0,1),(-1,0),(0,-1))
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                que.append((i,j))           
                d[i][j]=0
    ans=0
    while que:
        p=que.popleft()
        ans=d[p[0]][p[1]]
        for dx,dy in dd:
            nx=p[0]+dx
            ny=p[1]+dy
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==-1:
                d[nx][ny]=ans+1
                que.append((nx,ny))  
    return ans
if __name__=='__main__':
    print(main())

Measured memory_bytes: 121436
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 400005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
pii p[MAXN];
multiset<int> sb,sr;
void Solve() {
    read(N);
    int x,y;
    for(int i = 1 ; i <= N ; ++i) {
        read(x);read(y);
        if(x > y) swap(x,y);
        p[i] = mp(x,y);
        sb.insert(x);sr.insert(y);
    }
    sort(p + 1,p + N + 1);
    int64 ans = 1e18;
    for(int i = 1 ; i <= N ; ++i) {
        int a = *(--sr.end()) - *sr.begin();
        int b = *(--sb.end()) - *sb.begin();
        ans = min(ans,1LL * a * b);
        sr.erase(sr.find(p[i].se));
        sr.insert(p[i].fi);
        sb.erase(sb.find(p[i].fi));
        sb.insert(p[i].se);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 20608
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//9:46

int main(){
  int n = 0;
  int k = 0;
  int i = 0;
  int omoteneed[100000] = {};
  int score = 0;
  double kakuritsu = 0;
  
  
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    score = i+1;
    while(1){
      if(score >= k){
        break;
      }else{
        score *= 2;
        omoteneed[i]++;
      }
    }
  }
  
  for(i=0;i < n;i++){
    kakuritsu += (1/(double)n)*pow(0.5,omoteneed[i]);
  }
  
  printf("%.12f",kakuritsu);
  return 0;
}
     

Measured memory_bytes: 512
from math import ceil

def divisors(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n // i)
    return res

n = int(input())
divs = divisors(n)
ans = 10 ** 12
divs.sort()
for i in range(ceil(len(divs) / 2)):
    a = divs[i]
    b = divs[(i + 1) * (-1)]
    ans = min(ans, (a - 1) + (b - 1))

print(ans)

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

using namespace std;

const int   N   = 3e3 + 1;

int a[N];
int f[N];

vector<int> g[N];

int dfs(int u)  {
    int ans = 0;
    for(int v : g[u])   if (a[v] < a[u])
        ans = max(ans,dfs(v) ^ 1);
    return  ans;
}

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

    int n;  cin >> n;

    for(int i = 1 ; i <= n ; ++i)   cin >> a[i];
    for(int i = 2 ; i <= n ; ++i)   {
        int x;  cin >> x;
        int y;  cin >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    int ans = 0;

    for(int i = 1 ; i <= n ; ++i)
        if (dfs(i)) cout << i << " ";
}

Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n, t, L, b, x;
	while( scanf("%d%d%d%d", &n, &t, &L, &b), n != 0 ){
		vector<vector<double> > probs(3, vector<double>(n + 1) );
		vector<double> tmp(n + 1);
		probs[0][0] = 1.0;

		vector<char> lose(n + 1), back(n + 1);
		for(int i = 0; i < L; ++i){
			scanf("%d", &x);
			lose[x] = 1;
		}
		for(int i = 0; i < b; ++i){
			scanf("%d", &x);
			back[x] = 1;
		}

		double ans = 0.0;
		for(int turn = 0; turn < t; ++turn){
			int cur = turn % 3;
			int next = (turn + 1) % 3;
			int skip = (turn + 2) % 3;

			fill(tmp.begin(), tmp.end(), 0.0);

			for(int i = 0; i < n; ++i){
				for(int j = 1; j <= 6; ++j){
					x = i + j;
					if( x > n ) x = 2 * n - x;
					tmp[x] += probs[cur][i] / 6.0;
				}
			}

			ans += tmp[n];

			for(int i = 0; i < n; ++i){
				if( back[i] ){
					probs[next][0] += tmp[i];
				}
				else if( lose[i] ){
					probs[skip][i] += tmp[i];
				}
				else{
					probs[next][i] += tmp[i];
				}
			}
			
			fill(probs[cur].begin(), probs[cur].end(), 0.0);
		}
		
		printf("%.10f\n", ans);
	}
}

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

using namespace std;

typedef long long ll;

const int N = (int) 2e5 + 5;
const int mod = (int) 1e9 + 7;

char s[N], x[N];
deque<char> d;
int n, k, f;

inline void solve () {
        scanf ("%d%d%s", &n, &k, s + 1);
        for (int i = 1; i <= n; i++) {
                d.push_back (s[i]);
        }
        int e = min (k, n + n + 5);
        for (int i = 1; i <= e; i++) {
                if ((d[0] == 'A' && f == 0) || (d[0] == 'B' && f == 1)) {
                        d[0] = f ? 'A' : 'B';
                } else {
                        f ^= 1;
                        d.pop_front ();
                        if (f) {
                                d.push_back ('B');
                        } else {
                                d.push_back ('A');
                        }
                }
        }
        k -= e;
        if (k) {
                for (int i = 1; i <= n; i++) {
                        if (f) {
                                d[i - 1] = ((d[i - 1] - 'A') ^ 1) + 'A';
                        }
                        s[i] = d[i - 1];
                }
                f = 0;
                if ((d[0] == 'A' && f == 0) || (d[0] == 'B' && f == 1)) {
                        d[0] = f ? 'A' : 'B';
                } else {
                        f ^= 1;
                        d.pop_front ();
                        if (f) {
                                d.push_back ('B');
                        } else {
                                d.push_back ('A');
                        }
                }
                for (int i = 1; i <= n; i++) {
                        if (f) {
                                d[i - 1] = ((d[i - 1] - 'A') ^ 1) + 'A';
                        }
                        x[i] = d[i - 1];
                }
                int ss = 0;
                for (int i = 1; i <= n; i++) {
                        if (x[i] == s[i]) {
                                ss++;
                        }
                }
                if (ss != n && (k & 1)) {
                        for (int i = 1; i <= n; i++) {
                                s[i] = x[i];
                        }
                }
        } else {
                for (int i = 1; i <= n; i++) {
                        if (f) {
                                d[i - 1] = ((d[i - 1] - 'A') ^ 1) + 'A';
                        }
                        s[i] = d[i - 1];
                }
        }
        puts (s + 1);
}

int tests = 1;

int main () {
//        freopen (".in", "r", stdin);
//        freopen (".out", "w", stdout);
//        scanf ("%d", &tests);
        while (tests--) {
                solve ();
        }
        return 0;
}


Measured memory_bytes: 1024