akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
  
const int N = 1e5 + 5;
const int mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int x; cin >> x;
	if(x >= 30) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	return 0;
}

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

int main(void) {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        cout << s << endl
             << s << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n,m;
  
  cin >> n;
  vector<string> p(n);
  rep(i,n) {
  cin >> p[i];
  }
  sort(all(p));
  
  cin >> m;
  vector<string> q(m);
  rep(i,m) {
  cin >> q[i];
  }
  sort(all(q));
  
  int ans = 0;
  rep(i,n) {
    int cnt = 0;
    rep(j,n) {
      if(p[i]==p[j])cnt++;
    }
    rep(j,m) {
      if(p[i]==q[j])cnt--;
    }
    ans = max(ans,cnt);
  }
  
  cout << ans << endl;  
  
}

Measured memory_bytes: 256
# 入力を取得
N = gets
H = gets

h_str = H.split(" ")

maxMove = 0
i = 0
cnt = 0
while i <=  N.to_i-2
    if h_str[i].to_i >= h_str[i+1].to_i
        i += 1
        cnt += 1
    else
        i += 1
        cnt = 0
    end
    maxMove = cnt if cnt > maxMove
end

# 結果を出力
print maxMove

Measured memory_bytes: 7812
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int s,w;
  cin>>s>>w;
  if(s<=w){
    cout<<"unsafe"<<'\n';
  }
  else{
    cout<<"safe"<<'\n';
  }
  return(0);
}


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

using namespace std;

int main(){
        int64_t a, b, c, d, ans;
        cin >> a >> b >> c >> d ;
        if(a*c > 0 or b*d > 0){
                cout << max(a*c, b*d) << endl;
        }
        else{
                cout << max(a*d, b*c) << endl;
        }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

template <typename T>
class SegTree {
private:
    int n;
    vector<T> data;
    T id;
    function<T(T, T)> update;
    function<T(T, T)> merge;

    T _query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return id;
        if(a <= l && r <= b) return data[k];
        
        T vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);
        return merge(vl, vr);
    }

public:
    SegTree(int _n, T _id, function<T(T, T)> _update, function<T(T, T)> _merge)
    : id(_id), update(_update), merge(_merge) {
        n = 1;
        while(n < _n) n <<= 1;
        data = vector<T>(2 * n - 1, id);
    }

    void change(int k, T x) {
        k += n - 1;
        data[k] = update(data[k], x);
        while(k > 0) {
            k = (k - 1) / 2;
            data[k] = merge(data[2 * k + 1], data[2 * k + 2]);
        }
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](int k) {
        return data[k + n - 1];
    }
};

const int MOD = 998244353;
static const int n_max = 200000;
int powtwo[n_max + 1];

void powtwoinit() {
    powtwo[0] = 1;
    for(int i=1; i<=n_max; ++i) {
        powtwo[i] = powtwo[i - 1] * 2 % MOD;
    }
}

int main() {
    int N;
    cin >> N;
    vector<P> x(N), y(N);
    for(int i=0; i<N; ++i) {
        int a, b;
        cin >> a >> b;
        x[i] = P(a, i);
        y[i] = P(b, i);
    }
    sort(begin(x), end(x));
    sort(begin(y),end(y));
    vector<P> point(N);
    for(int i=0; i<N; ++i) {
        point[x[i].second].first = i;
        point[y[i].second].second = i;
    }
    sort(begin(point), end(point));

    SegTree<int> done(N, 0, plus<int>(), plus<int>());
    SegTree<int> undone(N, 0, plus<int>(), plus<int>());
    for(int i=0; i<N; ++i) undone.change(i, 1);

    int res = 0;
    powtwoinit();
    for(P p : point) {
        int y = p.second;
        done.change(y, 1);
        undone.change(y, -1);

        vector<int> num(4);
        num[0] = undone.query(y + 1, N);
        num[1] = done.query(y + 1, N);
        num[2] = done.query(0, y);
        num[3] = undone.query(0, y + 1);

        long long tmp = powtwo[N] - 1;
        for(int i=0; i<4; ++i) {
            tmp = (tmp - powtwo[num[i] + num[(i + 1) % 4]] + MOD) % MOD;
            tmp = (tmp + powtwo[num[i]]) % MOD;
        }
        res = (res + tmp) % MOD;
    }
    cout << res << endl;
}

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

int main(){
  int h, w;
  cin >> h >> w;
  REP(i,h){
    REP(j,w){
      string str;
      cin >> str;
      if( str == "snuke" ){
	cout << (char)('A' + j) << i + 1 << endl;
      }
    }
  }
}


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

class Dice {
    public:
    int f[6];
    Dice() {}
    void roll_z() { roll(1, 2, 4, 3);}
    void roll_W() { roll(0, 2, 5, 3);}
    void roll_N() { roll(0, 1, 5, 4);}
    void roll_S() { roll(0, 4, 5, 1);}
    void roll_E() { roll(0, 3, 5, 2);}
    void roll (int i, int j, int k, int l) {
        int t = f[i];
        f[i] = f[j];
        f[j] = f[k];
        f[k] = f[l];
        f[l] = t;
    }
    int top() {
        return f[0];
    }
    int front() {
        return f[1];
    }
    int left() {
        return f[3];
    }
    int right() {
        return f[2];
    }
};

bool a(Dice d1, Dice d2) {
    for (int i = 0; i < 6; i++)
        if (d1.f[i] != d2.f[i]) return false;
    return true;
}

bool b(Dice d1, Dice d2) {
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 4; j++) {
            if(a(d1, d2) ) return true;
            d1.roll_z();
        }
        if (i % 2 == 0) d1.roll_W();
        else d1.roll_N();
    }
    return false;
}

Dice D[100];
int n;

bool check() {
    for (int i = 0; i < n-1; i++) 
        for (int j = i + 1; j < n; j++) if (b(D[i], D[j])) return false;
    return true;
}

int main() {
    cin >> n;
    for (int j = 0; j < n; j++)
        for (int i = 0; i < 6; i++) cin >> D[j].f[i];
        
    if (check()) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
} 


Measured memory_bytes: 3104
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}

int N, M;
int dp[301][301][301];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;

  dp[0][1][1] = 1;
  rep(i, M) {
    rep(j, N+1) {
      rep(k, j+1) {
        if (j < N) {
          add(dp[i+1][j+1][k], (1LL*(N-j)*dp[i][j][k]) % MOD);
        }
        add(dp[i+1][j][j], (1LL*  k  *dp[i][j][k]) % MOD);
        add(dp[i+1][j][k], (1LL*(j-k)*dp[i][j][k]) % MOD);
      }
    }
  }
  cout << dp[M][N][N] << "\n";
  return 0;
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define A first
#define B second
#define MOD 1000000007

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;
}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res, x);
        y = y >> 1;
        x = mulmd(x, x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a - b;
    if(ret < 0){
        ret += MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int invPow(ll a){
    return power(a, MOD - 2, MOD);
}

const int N = 1e5 + 5;

int arr[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    priority_queue<int> pq;
    REP(i, n) {
        cin >> arr[i];
        pq.push(arr[i]);
    }
    while(!pq.empty() && m > 0){
        int tp = pq.top();
        pq.pop();
        tp /= 2;
        if(tp > 0){
            pq.push(tp);
        }
        m -= 1;
    }
    ll s = 0;
    while(!pq.empty()){
        s += pq.top();
        pq.pop();
    }
    cout << s;
}

/**
    Check out for boundary cases, (n = 1 or n = 0)
    check for integer overflow

**/



Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  for (int i = 0; i < 2; i++){
    for (int j = 0; j < N; j++){
      cin >> A[i][j];
    }
  }
  vector<long long> S1(N + 1, 0);
  for (int i = 0; i < N; i++){
    S1[i + 1] = S1[i] + A[0][i];
  }
  vector<long long> S2(N + 1, 0);
  for (int i = N - 1; i >= 0; i--){
    S2[i] = S2[i + 1] + A[1][i];
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    ans = max(ans, S1[i + 1] + S2[i]);
  }
  cout << ans << endl;
}

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

using namespace std;

#define int long long

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) a.begin(),a.end()
#define fst first
#define scd second

const int inf = 3e18;

int m, n;
int p[10010];
int C[510], E[510];

int dp[30010];

signed main()
{
	cin >> m >> n;
	rep(i, m) cin >> p[i];
	sort(p,p+m,greater<int>());
	
	rep(i, n) {
		cin >> C[i] >> E[i];
	}
	
	fill_n(dp, 30010, inf);
	dp[0] = 0;
	
	rep(i, n) {
		for (int j = 30000; j >= 0; --j) {
			if (j + C[i] < 30000) {
				dp[j+C[i]] = min(dp[j+C[i]], dp[j] + E[i]);
			}
		}
	}
	
	int cur = 0;
	
	int ans = 0;
	
	for (int i = 1; i <= 25000; ++i) {
		if (i <= m) cur += p[i-1];//,printf("cur=%d\n",cur);
		ans = max(ans, cur - dp[i]);
		//printf("dp[%d] = %d\n", i, dp[i]);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3468
n = int(input())
a = list(map(int, input().split()))

cnt = 0
flag = False

for i in range(n):
    if a[i] < 0:
        a[i] = -a[i]
        cnt += 1
    elif a[i] == 0:
        flag = True
    else:
        continue

if flag:
    print(sum(a))
    exit()
    
if cnt % 2 == 0:
    print(sum(a))
else:
    print(sum(a) - 2*min(a))

Measured memory_bytes: 64752
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N;
    cin >> N;
    vec<vec<lint>> train_info(N - 1);
    range(i, 0, N - 1) {
        lint C, S, F;
        cin >> C >> S >> F;
        train_info.at(i) = {C, S, F};
    }
    range(start, 0, N - 1) {
        lint past_time = 0;
        range(cur_station, start, N - 1) {
            lint C = train_info.at(cur_station).at(0), S = train_info.at(cur_station).at(1), F = train_info.at(cur_station).at(2);
            past_time = max(S, past_time);
            past_time = ceil((double)past_time / F) * F + C;
        }
        cout << past_time << "\n";
    }
    cout << 0 << "\n";
    return 0;
}

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

using namespace std;

int main(){
	int m;
	cin >> m;
	for(int i=0;i<m;i++){
		int badget,year,kind;
		int ret=0;
		cin >> badget >> year >> kind;
		for(int j=0;j<kind;j++){
			int tmp;
			int multi;
			int plus = 0;
			double rate;
			int fee;
			tmp = badget;
			cin >> multi >> rate >> fee;
			for(int k=0;k<year;k++){
				if(multi == 0){
					plus += tmp * rate;
					tmp -= fee;
				}else{
					tmp *= 1 + rate;
					tmp -= fee;
				}
			}
			ret = max(ret, tmp+plus);
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
N,L=map(int,input().split())
li=[]
for i in range(N):
    li.append(L+i+1-1)
A=True
li.sort()
S=sum(li)
for j in range(N-1):
    if abs(li[j])<=abs(li[j+1]):
        S-=li[j]
        A=False
        break

if A==True:
    S-=li[N-1]

print(S)


Measured memory_bytes: 9192
#include<iostream>
#include<bits/stdc++.h>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vpll vector<pair<ll,ll> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(i,s,n)   for(int i=s;i<=n;i++)
#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)
#define popcnt(x) __builtin_popcount(x)
#define EPS 1e-9
#define INF 1e17
using namespace std;
const int mod = 1000000007;
const int N = 1000000+5;
const double pi = acos(-1);
class cmp{
public:
	bool operator() (pair<ll, pll> &A, pair<ll, pll> &B){
		return A > B;
	}
};
template<class a,class b,class c>
class tup{
public:
	a f;
	b s;
	c t;
	tup(a f,b s,c t):f(f),s(s),t(t){}
	tup(){}
};
bool by_sec(pll &A, pll &B){
	return A.second < B.second;
}
ld dist(pll p1, pll p2){
	return (ld)sqrt((ld)(p1.first - p2.first)*(p1.first - p2.first) + (ld)(p1.second - p2.second)*(p1.second - p2.second));
}
ll fact[1000009], inv[1000009];
ll fp(ll a, ll b){
	if (b == 0)
		return 1;
	ll ans = fp(a, b / 2);
	ans = (ans * ans) % mod;
	if (b % 2 != 0)
		ans = (ans * (a % mod)) % mod;
	return ans;
}
void FacInv(ll n){
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}
ll ncr(ll n, ll r){
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}

ll dp[N];
int main()
{
	Amr_Abdelazim
		ll n,k;
	cin >> n>>k;
	for (auto &i : dp)i = 1e15;
	dp[n - 1] = 0;
	vll v(n);
	rep(i, n)cin >> v[i];
	for (int i = n - 1; i >= 0; i--){
		for (int j = 1; j <= k; j++){
			if (i - j >= 0)
				dp[i - j] = min(dp[i - j], abs(v[i] - v[i - j]) + dp[i]);			
		}
	}
	cout << dp[0] << "\n";

	return 0;
}


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

int main(){
  string s;cin>>s;
  int ans=0;
  int m=0;
  for(int i=0;i<(int)s.size();i++){
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
      m++;
    }
    if(i==(int)s.size()-1||!(s[i+1]=='A'||s[i+1]=='C'||s[i+1]=='G'||s[i+1]=='T')){
      ans=max(ans,m);
      m=0;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
template<class T>inline void read(T &re)
{
	char ch;
	while((ch=getchar())<'0'||ch>'9');
	re=ch-48;
	while((ch=getchar())>='0'&&ch<='9')
	re=(re<<3)+(re<<1)+ch-48;
}
int n,m,Q,pt[4005][4005],eg[4005][4005];
char mp[2005][2005],s[4005][4005];
int main()
{
//	freopen("duty.in","r",stdin);
//	freopen("duty.out","w",stdout);
	read(n);read(m);read(Q);
	for(register int i=1;i<=n;++i){
		scanf("%s",mp[i]+1);
		for(register int j=1;j<=m;++j)
		s[2*i-1][2*j-1]=mp[i][j];
	}
		
	for(register int i=1;i<=n;++i){
		int x=2*i-1,y;
		for(register int j=1;j<=m;++j){
			y=2*j-1;
			if(s[x][y]=='1'){
				if(s[x+2][y]=='1')
					s[x+1][y]='2';
				if(s[x][y+2]=='1')
					s[x][y+1]='2';
			}
		}
	}
	
	for(register int i=1;i<=2*n-1;++i){
		for(register int j=1;j<=2*m-1;++j){
			pt[i][j]=(s[i][j]=='1')+pt[i-1][j]+pt[i][j-1]-pt[i-1][j-1];
			eg[i][j]=(s[i][j]=='2')+eg[i-1][j]+eg[i][j-1]-eg[i-1][j-1];
		}
	}
	int u,v,w,z,ans1,ans2;
	for(register int i=1;i<=Q;++i){
		read(u);read(v);read(w);read(z);
		u=2*u-1,v=2*v-1,w=2*w-1,z=2*z-1;
		ans1=pt[w][z]+pt[u-1][v-1]-pt[u-1][z]-pt[w][v-1];
		ans2=eg[w][z]+eg[u-1][v-1]-eg[u-1][z]-eg[w][v-1];
		printf("%d\n",ans1-ans2);
	}
}

Measured memory_bytes: 146688
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.i();
            B[i] = in.i();
        }

        long ans = 0;
        for (int i = N - 1; i >= 0; i--) {
            long a = A[i] + ans;
            if (a % B[i] > 0) {
                long d = (1 + (a - 1) / B[i]) * B[i];
                ans += d - a;
            }
        }

        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 36336
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>

typedef signed char        int8;
typedef short              int16;
typedef int                int32;
typedef long long          int64;
typedef unsigned char      uint8;
typedef unsigned short     uint16;
typedef unsigned int       uint32;
typedef unsigned long long uint64;

int main(void) {
  int n;
  std::cin >> n;

  std::vector<int> ps;
  for (int i = 0; i < n; i++) {
    int p;
    std::cin >> p;
    ps.push_back(p);
  }

  int min = ps.at(0);
  std::vector<int> mins;
  for (int i = 0; i < n; i++) {
    min = std::min(min, ps.at(i));
    mins.push_back(min);
  }

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (ps.at(i) <= mins.at(i)) {
      cnt++;
    }
  }

  std::cout << cnt << std::endl;

  return 0;
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
const double PI=3.14159265358979323846;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
int main(void){
    int n;cin>>n;
    co(double(n+n%2)/(double)(2*n));
}



Measured memory_bytes: 256
#!/usr/bin/env python3

'''
Author: andyli
Time: 2020-07-11 19:58:46
'''

import os
from io import BytesIO, IOBase
import sys
import math

def main():
    l,r,d = map(int,input().split())
    ans=0
    for i in range(l,r+1):
        if i % d == 0:
            ans += 1
    print(ans)
    return


# region fastio
BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda: self.buffer.read().decode('ascii')
        self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()


Measured memory_bytes: 62776
#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 N = 1e6 + 5;

int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> c(N, 0);
  rep(i, n) c[a[i]]++;
  bool p = true;
  for (int i = 2; i < N; ++i) {
    int cnt = 0;
    for (int j = i; j < N; j += i) {
      cnt += c[j];
    }
    if (cnt > 1) p = false;
  }
  if (p) cout << "pairwise coprime" << endl;
  else { 
    int g = a[0];
    for (int i = 1; i < n; ++i) g = gcd(g, a[i]);
    if (g == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
  }
  return 0;
}

Measured memory_bytes: 11096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

typedef struct point{
  ll x;
  ll y;
  char dis;
} point;

int main(){
  ll n;
  cin >> n;
  vector<point> vec;
  rep(i, n){
    point p;
    cin >> p.x >> p.y >> p.dis;
    vec.push_back(p);
  }
  ll smallest = 10000000;
  
  {
    map<ll, vector<pair<ll, char>>> mp;
    rep(i, n) mp[vec[i].y].push_back(make_pair(vec[i].x, vec[i].dis));
    for(auto v : mp){
      sort(all(v.second));
      ll left = -10000000000;
      for(auto p : v.second){
        if(p.second == 'R') left = p.first;
        else if(p.second == 'L') smallest = min(smallest, (p.first-left)*10/2);
      }
    }
  }
  
  {
    map<ll, vector<pair<ll, char>>> mp;
    rep(i, n) mp[vec[i].x].push_back(make_pair(vec[i].y, vec[i].dis));
    for(auto v : mp){
      sort(all(v.second));
      ll left = -10000000000;
      for(auto p : v.second){
        if(p.second == 'U') left = p.first;
        else if(p.second == 'D') smallest = min(smallest, (p.first-left)*10/2);
      }
    }
  }
  
  {
    map<ll, vector<point>> mp;
    rep(i, n) mp[vec[i].x+vec[i].y].push_back(vec[i]);
    for(auto v : mp){
      sort(all(v.second), [](point l, point r){
        if(l.x <= r.x) return true;
        else if(l.x > r.x) return false;
      });
      ll up = 10000000000;
      ll left = -10000000000;
      for(auto p : v.second){
        if(p.dis == 'R') left = p.x;
        else if(p.dis == 'D') up = p.y;
        else if(p.dis == 'L') smallest = min(smallest, (up - p.y)*10);
        else if(p.dis == 'U') smallest = min(smallest, (p.x - left)*10);
      }
    }
  }
  
  {
    map<ll, vector<point>> mp;
    rep(i, n) mp[-vec[i].x+vec[i].y].push_back(vec[i]);
    for(auto v : mp){
      sort(all(v.second), [](point l, point r){
        if(l.x <= r.x) return true;
        else if(l.x > r.x) return false;
      });
      ll down = -10000000000;
      ll left = -10000000000;
      for(auto p : v.second){
        if(p.dis == 'R') left = p.x;
        else if(p.dis == 'U') down = p.y;
        else if(p.dis == 'L') smallest = min(smallest, (p.y - down)*10);
        else if(p.dis == 'D') smallest = min(smallest, (p.x - left)*10);
      }
    }
  }
  
  if(smallest == 10000000) cout << "SAFE" << endl;
  else cout << smallest << endl;
  return 0;
}
  
  
  
  

Measured memory_bytes: 29488
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
typedef double db;
int n, m; db dp[610];
vector<int> G[610];
db ddp(int b) {
	for(int i = n - 1; i >= 1; i --) {
		dp[i] = 0; int s = 0; db sum = 0, mx = 0;
		for(int j = 0; j < (int) G[i].size(); j ++) {
			int v = G[i][j];
			sum += dp[v]; mx = max(mx, dp[v]); s ++;
		}
		if(b != i) { dp[i] = sum / s + 1; }
		else {
			if(s == 1) return 1e18;
			dp[i] = (sum - mx) / (s - 1) + 1;
		}
	}
	return dp[1];
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i ++) {
		int x, y;
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
	}
	db ans = ddp(0);
	for(int i = 1; i <= n; i ++)
		ans = min(ans, ddp(i));
	printf("%.10f", ans);
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <list>

#define rep(i, first, to) for(ll i = first; i < to; ++i)
#define REP(i, first, to) for(ll i = first; i <= to; ++i)

using namespace std;
typedef long long ll;

list<int> from[101];
int to[101][101];
int n;
void solve() {
	cin >> n;
	rep(i, 0, n) {
		int u, k;
		cin >> u >> k;
		rep(j, 0, k) {
			int value;
			cin >> value;
			from[u].push_back(value);
		}
	}
	REP(i, 1, n) {
		while(!from[i].empty()) {
			to[i][from[i].front()] = 1;
			from[i].pop_front();
		}
	}
	REP(i, 1, n) {
		REP(j, 1, n) {
			if (j == n) {
				cout << to[i][j] << endl;
			} else {
				cout << to[i][j] << " ";
			}
		}
	}
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3124
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

# grid
# N = I()
H,W = LI()
S = [list(_S()) for _ in range (H)]

# ans = np.zeros(shape=(H,W))
def replace(x, y):
    # 移動する8方向をループ
    count = 0
    for dx in range(-1, 2):
        for dy in range(-1, 2):
            # x, y 方向それぞれに dx, dy 移動した場所を (nx, ny) とする
            nx = x + dx
            ny = y + dy

            if 0 <= nx and nx < H and 0 <= ny and ny < W and S[nx][ny] == "#":
                count += 1
    S[x][y]=str(count)


for i in range(H):
    for j in range(W):
        if not (S[i][j] == "#"):
            replace(i,j)

for row in S:
  print(*row,sep='')

Measured memory_bytes: 27012
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

#define Pt first
#define Px second.first
#define Py second.second

int main(void){
    Cin(int, h, w, a, b);
    For(i, h){
        For(j, w) cout << ((i < b) ^ (j < a));
        cout << endl;
    }
}




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

int main()
{
    string S;
    cin >> S;

    sort(S.begin(), S.end());
    if(S[0]==S[1] && S[1]!=S[2] && S[2]==S[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
Q = int(input())
query = []
sumL, sumR = [], []
ans = 0
for _ in range(Q):
    a = list(map(int, input().split()))
    if a[0]==1:
        ans += a[2]
        if len(sumL)==0 or a[1] <= -sumL[0]:
            heappush(sumL, -a[1])
            ans += -sumL[0] - a[1]
        else:
            heappush(sumR, a[1])
            ans += sumL[0] + a[1]
    
        if len(sumR) > len(sumL):
            ans -= sumR[0] + sumL[0]
            heappush(sumL, -heappop(sumR))
            
        elif len(sumL) - len(sumR) >= 2:
            heappush(sumR, -heappop(sumL))

    else:
        print(-sumL[0],ans)
        

Measured memory_bytes: 11168
main :: IO ()
main = do
  _ <- getLine
  ls <-  fmap read . words <$> getLine :: IO [Int]
  putStrLn $ if solve ls then "Yes" else "No"

solve :: [Int] -> Bool
solve ls = if n2 >= 2 then (n - n2 - n4) < n4  + 1 else (n - n4) <= n4 + 1 where
  n = length ls
  n4 = length $ filter (\a -> a `mod` 4 == 0) ls :: Int
  n2 = length  (filter even ls) - n4


Measured memory_bytes: 36220
//To debug :  g++ -g file.cpp -o code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807;
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000;
#define mp make_pair
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
 
double p[3000][3000];
double pa[3000];


double fun(int n,int i)
{
	// we are at nth coin and we need to select i heads out of them

	if(n<1 || i<0)
	{
		if(n<1 && i>0)
			return 0;
		else
			return 1;
	}
	else if(p[n][i]!=-1)
	{
		return p[n][i];
	}
	if(i==n)
	{
		p[n][i] = pa[n]*fun(n-1,i-1);
	}
	else
	{
		if(i==0) //Means we do not require more heads then its mandatory to select tails
		{
			p[n][i] = (1-pa[n])*fun(n-1,i);
		}
		else
		{
			p[n][i] = (1-pa[n])*fun(n-1,i) + pa[n]*fun(n-1,i-1);
		}
	}

	return p[n][i];
}


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

	rep(i,0,3000)
	rep(j,0,3000)
		p[i][j]=-1;

	cin>>n;

	rep(i,1,n+1)
		cin>>pa[i];

	double ans=0;

	for(i=n;i>(n/2);--i)
	{
		if(i==n)
		{
			ans = ans + pa[n]*fun(n-1,i-1);
		}
		else
		{
			if(i==0) //Means we do not require more heads then its mandatory to select tails
			{
				ans = ans + (1-pa[n])*fun(n-1,i);
			}
			else
			{
				//cout<<"Here "<<i<<" "<<(1-pa[n])*fun(n-1,i)<<" "<<pa[n]*fun(n-1,i-1)<<"\n";
				ans = ans + (1-pa[n])*fun(n-1,i) + pa[n]*fun(n-1,i-1);
			}
		}
	}


	cout<<setprecision(9)<<fixed<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 70912
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn list_p(n: u32, cur_p: &mut Vec<u32>) -> Vec<Vec<u32>>{
    if cur_p.len() == n as usize{
        return vec![cur_p.clone()];
    }

    let mut ans: Vec<Vec<u32>> = vec![];
    for i in 1..n+1{
        if cur_p.iter().any(|x| *x == i){
            continue;
        }
        cur_p.push(i);
        ans.append(&mut list_p(n, cur_p));
        cur_p.pop();
    }

    return ans;
}

fn main(){
    let n: u32 = read_as_vec()[0];
    let p = read_as_vec::<u32>();
    let q = read_as_vec::<u32>();

    let mut tmp: Vec<u32> = vec![];
    let permutations = list_p(n, &mut tmp);

    let a: usize = permutations.iter().position(|x| *x == p).unwrap();
    let b: usize = permutations.iter().position(|x| *x == q).unwrap();

    println!("{}", ((a as i32) - (b as i32)).abs());
}


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

int findMax(int a, int b, int c) {
    int flag = 0;
    int max;
    if(a > b) {
        flag = 1;
        max =a;
    }
    else {flag = 2; max = b;} 
    if(c > max) { flag = 3; max = c;}
    return flag;
}

int main() {
    int A, B, C;
    cin >> A; cin >> B; cin >> C;

    int flag = findMax(A, B, C);

    int d = 0;
    if(flag==1) {
        d = (A - B) + (A -C);
    }
    else if(flag==2) {
        d = (B - A) + (B -C);
    }
    else if(flag==3) {
        d = (C - A) + (C -B);
    }

    if(d%2==0) {
        cout << d/2 << endl;
    }
    else {
        cout << (d+1)/2 + 1 << endl;
    }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;

struct Node{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;
  
  z= new Node;
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while( x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  
  z->parent = y;
  if( y == NIL ) root = z;
  else{
    if( z->key < y->key ) y->left = z;
    else y->right = z;
  }
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  cout<<" "<<u->key;
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL) return;
  cout<<" "<<u->key;
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,x;
  string com;
  
  cin>>n;
  
  rep(i,n){
    cin>>com;
    if(com=="insert"){
      cin>>x;
      insert(x);
    }
    else if(com=="print"){
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
  } 
  
  return 0;
}


Measured memory_bytes: 26552
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long int
#define tc int t; cin>>t; while(t--)
int main() {
 //fastio
ll n,d;
cin>>n>>d;
ll a=INT_MAX;



{for(ll i=n;i<min(d,n+2019);i++)
{
    for(ll j=i+1;j<=min(d,n+2019);j++)
        a=min(a,(i%2019*j%2019)%2019);
}
cout<<a;

}

}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	long long n, k;
	long long a, b, c;
	cin >> n >> k;
	a = n % k;
	b = abs(a - k);
	if (a >= b) cout << b;
	else cout << a;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> pii;
typedef vector<pi> vpi;
typedef set<ll> si;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define f first
#define s second
ll INF = 1e18;
ll MOD = 1e9+7;
#define lb lower_bound
#define ub upper_bound
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
int l,r,A[200100], B[200100], N;

int main(){
  cin>>N;
  for (int i=0;i<N;++i){cin>>A[i];B[i] = A[i];}
  sort(A,A+N);
  l = A[N/2-1];
  r = A[N/2];
  for (int i=0;i<N;++i){
    if (B[i] <= l)cout<<r<<'\n';
    else cout<<l<<'\n';
  }
}

Measured memory_bytes: 3712
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


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


	int N = getint();
	int A = getint();
	int B = getint();
	A -= B;
	int H[100000];
	ll goukei = 0;
	rep(i, N) {
		H[i] = getint();
		goukei += H[i];
	}

	int L = goukei / (A + (ll)B * N) - 1;
	int R = (1000000000 + B - 1) / B;

	while (L + 1 != R) {
		int m = (L + R) / 2;
		int damage = B * m;
		int cnt = 0;
		rep(i, N) {
			cnt += max(0, (H[i] - damage + A - 1) / A);
			if (cnt > m) break;
		}
		if (cnt <= m) R = m;
		else L = m;
	}

	printf("%lld", R);

	Would you please return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,m;
char chair[200];

void A(char ch){
  int i=1;
  while(chair[i]!='#') i++;
  chair[i]=ch;
}

void B(){
  int i=n;
  while(chair[i]!='#')i--;
  chair[i]='B';
}

void C(int kai){
  if(kai==0){
    if(n%2)chair[(n+1)/2]='C';
    else chair[n/2+1]='C';
    return;
  }
  int f=1;
  for(int i=1;i<=n;i++){
    if(chair[i]=='#')continue;
    if(chair[i+1]=='#') chair[i+1]='C',i=n,f=0;
    else if(chair[i-1]=='#') chair[i-1]='C',i=n,f=0;
   
  }
  //  assert(f);
}

void D(){
  int R=0,L=0;
  while(chair[n-R]=='#')R++;
  while(chair[L+1]=='#')L++;
  
  int M=0,idx=0,cnt=0;
  for(int i=1;i<=n;i++){
    if(chair[i]=='#')cnt++;
    else cnt=0;
    if(M+M%2<cnt) M=cnt,idx=i;
  }
  if(M<=2&&L<=1&&R<=1) A('D');
  else if(L-1>=(M-1)/2&&L-1>=R-1)chair[1]='D';
  else if(R-1>(M-1)/2)chair[n]='D';
  else chair[(idx-M+1)+(M-1)/2]='D';

}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    memset(chair,'#',sizeof(chair));
    chair[0]=chair[n+1]=0;
    for(int i=0;i<m;i++){
      char a;
      cin>>a;
      if(a=='A') A(a);
      if(a=='B') B();
      if(a=='C') C(i);
      if(a=='D') D();
    }
    int cnt=0;
    for(int i=1;i<=n;i++) if(chair[i]!='#') cnt++;
    assert(cnt==m);
    printf("%s\n",chair+1);
  }
  return 0;
}

Measured memory_bytes: 1120
#include<stdio.h>
#include<math.h>
signed main(void)
{
  int A,B,H,M;
  if(~scanf("%d %d %d %d",&A,&B,&H,&M))
  {
    double theta=(60*H-11*M)*M_PI/360.0,x=A-B*cos(theta),y=B*sin(theta);
    return printf("%.20f",sqrt(x*x+y*y)),0;
  }
}

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

n = int(input())
a = [int(input()) for _ in range(n)]

max_a = max(a)
b = a[:]
b.remove(max_a)
max_b = max(b)

if max_a == max_b:
    for i in range(n):
        print(max_a)
else:
    idx = a.index(max_a)
    for i in range(n):
        if idx == i:
            print(max_b)
        else:
            print(max_a)

Measured memory_bytes: 14068