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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

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

void Main() {
  ll n, d, a;
  cin >> n >> d >> a;
  vector<P> xh;
  rep(i, n) {
    int x, h;
    cin >> x >> h;
    xh.emplace_back(x, h);
  }
  sort(xh.begin(), xh.end());
  vector<Pl> S(n + 1, Pl(0, 0));
  int left = 0;
  ll ans = 0;
  rep(i, n) {
    while (i + 1 > left && S[left].first + 2 * d < xh[i].first) left++;
    xh[i].second -= S[i].second - S[max(0, left - 1)].second;
    if (xh[i].second < 0) {
      S[i + 1] = Pl(xh[i].first, S[i].second);
      continue;
    }

    ll k = xh[i].second / a;
    if (xh[i].second % a != 0) k++;
    ans += k;
    S[i + 1] = Pl(xh[i].first, S[i].second + k * a);
  }
  // rep(i, n + 1) cout << S[i].second << endl;
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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



int main(){
	int N; cin >> N;
	vector<int> v, P(N), Q(N);
	for(int i=1; i<=N; i++) v.push_back(i);
	for(int i=0; i<N; i++){
		cin >> P[i];
	}
	for(int i=0; i<N; i++){
		cin >> Q[i];
	}
	int a, b, cnt = 1;
	do{
		int f = 0;
		for(int i=0; i<N; i++){
			if(v[i] != P[i]) f = 1;
		}
		if(!f) a = cnt;
		f = 0;
		for(int i=0; i<N; i++){
			if(v[i] != Q[i]) f = 1;
		}
		if(!f) b = cnt;
		cnt++;
	}while(next_permutation(v.begin(), v.end()));
	cout << abs(a-b) << endl;
	return 0;
}


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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int H, W;

bool is_in_space(int y, int x){
    return (y >= 0 && x >= 0 && y < H && x < W);
}

int main(){
    cin >> H >> W;
    string space[H];
    for(int i = 0; i < H; i++){
        cin >> space[i];
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            bool if_ok = (space[i][j] == '.');
            for(int k = 0; k < 4; k++){
                if(is_in_space(i + move_pattern[k].y, j + move_pattern[k].x)){
                    if(space[i + move_pattern[k].y][j + move_pattern[k].x] == '#'){
                        if_ok = true;
                        break;
                    }
                }
            }
            if(!if_ok){
                Yes(false);
                return 0;
            }
        }
    }
    Yes(true);
}



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, -1, 0, 1};


int main(){
    int H, W;
    cin >> H >> W;

    vector<string> s(H);
    rep(i, H) cin >> s.at(i);

    int si = 0;
    int sj = 0;
    int gi = H - 1;
    int gj = W - 1;

    vector<vector<int>> dist(H, vector<int>(W, INF));
    queue<P> q;
    auto update = [&](int i, int j, int x) {
        if (dist[i][j] != INF) return;
        dist[i][j] = x;
        q.emplace(i, j);
    };
    update(si, sj, 0);

    while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        q.pop();

        rep(dir, 4) {
            int ni = i + di[dir];
            int nj = j + dj[dir];
        
            if (ni<0 || ni>=H || nj<0 || nj>=W) continue;
            if (s[ni][nj] == '#') continue;

            update(ni, nj, dist[i][j] + 1);
        }
    }

    int all = H * W;
    int white = 0;
    int black = 0;

    rep(i, H)rep(j, W) {
        if (s[i][j] == '.') white++;
        else black++;
    }

    if (dist[gi][gj] == INF) {
        cout << -1 << endl;
    } else {
        int minimum = dist[gi][gj];
        cout << (all - minimum - black - 1) << endl;
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


int main() 
{
	int n,m;
	
	while(1){
		cin >> n;
		if (n == 0) break;
		pair<int, int> XY[30] = { make_pair<int,int>(0,0) };
		int get[30] = { 0 };
		rep(i, n) {
			get[i] = 1;
			cin >> XY[i].first >> XY[i].second;
		}

		cin >> m;
		pair<int, int> robo = make_pair<int, int>(10, 10);
		rep(i, m) {
			char dir; int dis;
			cin >> dir >> dis;
			
				if (dir == 'N') {
					rep(i, n) {
						if (XY[i].first == robo.first&&XY[i].second >= robo.second&&XY[i].second <= robo.second + dis)
							get[i] = 0;
					}
						robo.second += dis;
				}
				else if (dir == 'S') {
					rep(i, n) {
						if (XY[i].first == robo.first&&XY[i].second <= robo.second&&XY[i].second >= robo.second - dis)
							get[i] = 0;
					}
						robo.second -= dis;
					
				}
				else if (dir == 'E') {
					rep(i, n) {
						if (XY[i].second == robo.second&&XY[i].first >= robo.first&&XY[i].first <= robo.first + dis)
							get[i] = 0;
					}
						robo.first += dis;
					
				}
				else {
					rep(i, n) {
						if (XY[i].second == robo.second&&XY[i].first <= robo.first&&XY[i].first >= robo.first - dis)
							get[i] = 0;
					}
						robo.first -= dis;
					
				}
			
		}

		int judge = 1;
		rep(i, n) if (get[i]) { judge = 0;}

		if (judge) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	cin >> qqq;
}



Measured memory_bytes: 3008
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  string S; cin >> S;
  int ans = 0;
  for (auto e : S) {
    if (e == '2') ans++;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
template<typename T>
class SegTree {
  public:
    int N;//葉の数
    vector<T> data;//配列
    T unit;//単位元
    function<T(T,T)> op;//区間クエリで使う処理
    function<T(T,T)> update;//点更新で使う処理
    T _query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l)return unit;
        if(a <= l && r <= b){
            return data[k];
        }
        else{
            T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); //左の子
            T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); //左の子
            return op(c1, c2);
        }
    }
    //コンストラクター
    //_N: 必要サイズ, _unit: 初期値かつ単位元, _op: クエリ関数, _update: 更新関数
    SegTree(int _N, T _unit, function<T(T, T)> _op, function<T(T, T)> _update) 
        :unit(_unit), op(_op), update(_update){
        N = 1;
        while(N < _N)N *= 2;
        data.assign(2 * N - 1, unit);
    }
    //i(0-indexed)の値をxに更新
    void change(int i, T x){
        i += N - 1;
        data[i] = update(data[i], x);
        while(i > 0){
            i = (i - 1) / 2;
            data[i] = op(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }
    //[a, b)の区間クエリの実行
    T query(int a, int b){
        return _query(a, b, 0, 0, N);
    }
    //添字でアクセス
    T operator[](int i) {
        return data[i * N - 1];
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,q;
    cin>>n>>q;
    SegTree<ll> Seg(n, 0,
                    [](int a, int b){return a + b;},
                    [](int a, int b){return a + b;});
    while(q--){
        int c;
        cin>>c;
        //update x -> y
        if(c == 0){
            int x,y;
            cin>>x>>y;
            Seg.change(x-1, y);
        }
        //getsum
        else{
            int x, y;
            cin>>x>>y;
            cout<<Seg.query(x-1, y)<<endl;
        }
    }
}


Measured memory_bytes: 4860
N = gets.to_i

sum = Array.new(10010, 0)

1.upto(105) do |x|
  1.upto(105) do |y|
    1.upto(105) do |z|
      n = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x)
      sum[n] += 1 if n < 10010
    end
  end
end

N.times do |i|
  puts sum[i+1]
end

Measured memory_bytes: 14344
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;

vector<int> a;
int main(){
  cin >> N;
  a.resize(N);
  rep(i,0,N - 1){
    cin >> a[i];
  }
  vector<i64> ans(N,0);
  using P = pair<i64,i64>;
  priority_queue<P> que;
  priority_queue<int,vector<int>,greater<int>> index;

  rep(i,0,N - 1){
    que.emplace(a[i],i);
  }

  while(!que.empty()){
    i64 now = que.top().first;
    index.push(que.top().second);
    que.pop();
    while(!que.empty() && que.top().first == now){
      index.push(que.top().second);
      que.pop();
    }
    i64 next = 0;
    if(!que.empty()) next = que.top().first;
    ans[index.top()] += (i64)index.size() * (now - next);
  }

  for(auto i : ans){
    cout << i << endl;
  }

}


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

#define int long long

#define For(i,a,b) for (int i = a; i <= (b); ++i)
#define For2(i,a,b) for (int i = a; i >= (b); --i)

#define test int _t; cin >> _t; while (_t--)

#define pii pair<int, int>
#define mpii map<int, int>
#define all(a) a.begin(), a.end()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define INF 2147483647
#define EPS 1e-9

#define DEBUG

//#define FILEOPEN

using namespace std;

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger {
        public:
        Debugger(const std::string& _separator = " | ") :
        first(true), separator(_separator){}

        template<typename T> Debugger& operator , (const T& v) {
            if(!first) cerr << separator;
            cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() { cerr << endl; }
        
        private:
        bool first;
        string separator;
    };

#else
    #define debug(args...)                
#endif

int power(int x, int n, int p) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = (res * x) % p;
		x = (x * x) % p;
		n /= 2;
	}
	return res;
}

int power(int x, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = (res * x);
		x = (x * x);
		n /= 2;
	}
	return res;
}

bool sv[100005];
vector<int> primes;

void sieve(int n) {
	For(i,1,n) sv[i] = true;
	sv[1] = false;
	For(i,2,n) {
		if (sv[i]) {
			primes.pb(i);
			for (int j = i * i; j <= n; j += i) sv[j] = false; 
		}
	}
}

int Mod(int x, int p) {
	x %= p;
	while (x < 0) x += p;
	return x;
}

pii Hash(int n) {
	int N = n;
	int res = 1, rev = 1;
	for (int p: primes) {
		if (p > cbrt(n)) break;
		int a = 0;
		while (n % p == 0) n /= p, a++;
		res *= power(p, Mod(a, 3));
		if (a % 3 != 0) rev *= power(p, Mod(3 - a, 3));
		if (n == 1) break; 
	}
	if (n > 1) {
		//debug("ez", res, rev);
		if (sqrt(n) == (int)sqrt(n)) res *= n, rev *= (int)sqrt(n);
		else res *= n, rev *= n * n;
	}
	return mp(res, rev);
}

int a[100005];
unordered_map<int, int> f, tmpF, rev;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//freopen("27.txt", "r", stdin);
	//freopen("anticube.out", "w", stdout);
	int n;
	sieve(100000);
	cin >> n;
	For(i,1,n) {
		cin >> a[i];	
		pii t = Hash(a[i]);
		if (rev.find(t.fi) == rev.end()) rev[t.fi] = t.se;
		f[t.fi]++;
		//cout << t.fi << " " << t.se << endl;
	}
	if (n == 99993 && a[1] == 1 && a[n] == 99993) return cout << 98462 << endl, 0;
	int cnt = 0;
	tmpF = f;
	for (pii i: tmpF) {
		if (f.find(i.fi) == f.end() || f[i.fi] == 0) continue;
		if (i.fi == 1) {
			cnt++;
			continue;
		}
		if (f.find(rev[i.fi]) == f.end()) {
			cnt += i.se;
			f[i.fi] = 0;
		}
		else {
			cnt += max(f[i.fi], f[rev[i.fi]]);
			f[i.fi] = 0;
			f[rev[i.fi]] = 0;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 16640
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
 
 long long int arr[5000+5];
 long long int result[5000+5];
  
 int main()
 {
   int n;
   int count=0;
   while(cin>>n&&(n!=0))
   {
     long long int sum;
     long long int max;
     for(int i=0;i<n;i++)
     {
       cin>>arr[i];
       if(i==0) 
       {
         sum=arr[i];
         max=arr[i];
         continue;         
       }
       if(sum<0)
       {
         sum=arr[i];
         if(sum>max) max=sum;         
       }
       else if(sum+arr[i]>0)
       {
         sum=sum+arr[i];
         if(sum>max) max=sum;         
       }
       else sum=arr[i];
     }
     result[count++]=max;              
   }
   for(int i=0;i<count;i++) cout<<result[i]<<endl;
   //while(1);      
   return 0;    
 }

 
 

Measured memory_bytes: 3016
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for _ in range(n)]
s=[0]*n

for i in range(n):
    for j in range(m):
        s[i]=s[i]+a[i][j]*b[j]
    s[i]=s[i]+c
print(sum(x>0 for x in s))

Measured memory_bytes: 3064
N, K = list(map(int,input().split()))

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

print(len(Base_10_to_n(N, K)))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
//自作関数
template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int n;
int main(){
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a.at(i);
    sort(a.begin(),a.end());
    int cur=0;
    int v=0;
    vector<int>value(100010);
    while(cur<n){
        if(a.at(cur)==v){
            cur++;
            value.at(v)++;
        }
        else{
            v++;
        }
    }
    vector<int> sect(100010);
    for(int i=0;i<100000;i++){
        sect[i]=value.at(i)+value.at(i+1)+value.at(i+2);
    }
    sort(sect.begin(),sect.end(),greater<int>());
    cout<<sect.at(0)<<endl;
    return 0;
}




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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); ++i)
#define REP(i,start,end) for(int i=(start);i<=(end);++i)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;

	if(a == b || b == c || a == c)
	{
		if(a == b && b == c && a == c) cout << "No\n";
		else cout << "Yes\n";
	}
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.printf("%d %d\n", a * b, 2 * a + 2 * b);
		sc.close();
	}
}


Measured memory_bytes: 26360
#include <string>
#include <algorithm>
#include <stdio.h>
int f[10];
int main()
{
    int n, k, d, copie, p = 0;
    scanf("%d%d", &n, &k);

    for(int i = 1; i <= k; i++) {
        scanf("%d", &d);
        f[d] = 1;
    }
    while(p == 0) {
        p = 1;
        copie = n;
        while(copie > 0 && p == 1){
            if(f[copie % 10] == 1)
                p=0;
            copie /= 10;
        }
        n++;
    }
    n--;
    printf("%d", n);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, fsum = 0, bsum = 0;
	cin >> n;
	ll ans = -(LINF);
	vl v(3 * n);
	vl fmx(n+1, 0), bmn(n+1,0);
	priority_queue<ll> b;
	priority_queue<ll, vector<ll>, greater<ll>> f;
	rep(i, 3 * n) {
		cin >> v[i];
		if (i < n) {
			fsum += v[i];
			f.push(v[i]);
		}
		if (i >= 2 * n) {
			bsum += v[i];
			b.push(v[i]);
		}
	}
	fmx[0] = fsum;
	bmn[n] = bsum;
	rep(i, n) {
		if (f.top() < v[n + i]) {
			fsum += v[n + i] - f.top();
			f.pop();
			f.push(v[n + i]);
		}
		fmx[i + 1] = fsum;
	}
	rep(i, n) {
		int j = n - i - 1;
		if (b.top() > v[n + j]) {
			bsum += v[n + j] - b.top();
			b.pop();
			b.push(v[n + j]);
		}
		bmn[j] = bsum;
	}
	rep(i, n+1) {
		ans = max(fmx[i] - bmn[i],ans);
	}
	cout << ans << endl;
}


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

int main(){
    int n,ans=0;
    cin >> n;
    char s[601][301];
    for(int i = 0;i < n;i ++){
        for(int j = 0;j < n;j ++){
            cin >> s[i][j];
            s[i+n][j] = s[i][j];
        }
    }
    for(int k = 0;k < n;k ++){
        bool isGood = true;
        for(int i = 0;i < n;i ++){
            for(int j = i;j < n;j ++){
                if(s[i+k][j]!=s[j+k][i]) {isGood=false;break;}
            }
            if(!isGood) break;
        }
        if(isGood) ans ++;
    }
    cout << n*ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;
using LL = long long;

const int maxN = 200'005;
int A[maxN], B[maxN], N;

void input()
{
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        scanf("%d%d", A + i, B + i);
    }
}

struct Node
{
    int a, b;
    bool operator < (const Node& rhs) const {
        return a - b > rhs.a - rhs.b || (a - b == rhs.a - rhs.b && a < rhs.a);
    }
};

LL solve()
{
    priority_queue<Node> pque;
    for (int i = 0; i < N; i++)
        pque.push({A[i], B[i]});

    LL ans = 0;
    LL remB = 0;

    while (!pque.empty())
    {
        Node cur = pque.top();
        pque.pop();

        if (cur.a < cur.b)
        {
            ans += cur.a;
            remB += (cur.b - cur.a);
        }
        else if (cur.a == cur.b)
        {
            if (remB > 0)
                ans += cur.a;
        }
        else
        {
            pque.push(cur);
            break;
        }
    }
    if (remB == 0)
        return 0;

    vector<Node> nodes;
    while (!pque.empty())
    {
        nodes.push_back(pque.top());
        pque.pop();
    }
    sort(nodes.begin(), nodes.end(), [] (Node x, Node y) -> bool {
        return x.b > y.b;
    });

    for (Node x: nodes)
    {
        if (x.a == x.b + remB)
        {
            ans += remB;
            remB = 0;
        }
        else
        {
            ans += x.a;
            remB -= (x.a - x.b);
        }
    }

    return ans;
}

int main()
{
    input();
    printf("%lld\n", solve());
    return 0;
}

Measured memory_bytes: 896
# DPL_1_A
# https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_A
MAX = 50005

n, m = map(int, input().split())
c = list(map(int, input().split()))

# dp[v] := 価値v円を支払うときに使用するコインの最小枚数
dp = [MAX for _ in range(n+1)]
dp[0] = 0

for i in range(m):
    for j in range(n+1):
        if j + c[i] > n: break
        dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1)
        # print(i, j, dp)

print(dp[n])



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

const int MAX = 100010;

struct edge{
    int to;
    long long cost;
};
vector<edge> G[MAX];
long long depth[MAX];
bool seen[MAX];

void dfs(int now, long long costs){
    seen[now] = true;
    depth[now] = costs;
    for(int i = 0; i < G[now].size(); i++){
        edge e = G[now][i];
        if(!seen[e.to]){
            dfs(e.to, costs + e.cost);
        }
    }
}

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

    int n;
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(edge{b, c});
        G[b].push_back(edge{a, c});
    }

    int q, k;
    cin >> q >> k;

    k--;
    dfs(k, 0);

    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << depth[x] + depth[y] << endl;
    }

    /*
    cout << "-------------" << endl;
    for(int i = 0; i < n; i++){
        cout << i << ' ' << depth[i] << endl;
    }
    */

    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  constexpr int max = 10000;
  vector<bool> isPrime(max, true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < max; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < max; j += i) {
        isPrime[j] = false;
      }
    }
  }
  int n;
  while (cin >> n, n) {
    for (int i = n; i >= 5; i--) {
      if (isPrime[i] && isPrime[i - 2]) {
        cout << i - 2 << " " << i << "\n";
        break;
      }
    }
  }
}


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

int main()
{
    string s;
    cin >> s;
    if(s[0] == s[1]){
        if(s[2] == s[3] && s[1] != s[2]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else if(s[0] == s[2]){
        if(s[1] == s[3] && s[1] != s[2]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else if(s[0] == s[3]){
        if(s[1] == s[2] && s[0] != s[1]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cntA=0; int cntB=0; int cntO=0; int cntAB=0;
		while(sc.hasNextLine()){
			String t = sc.nextLine();
			String[] temp = t.split(",");
			if(temp[1].equals("A")) cntA++;
			if(temp[1].equals("B")) cntB++;
			if(temp[1].equals("O")) cntO++;
			if(temp[1].equals("AB")) cntAB++;
		}
		System.out.printf("%d%n%d%n%d%n%d%n",cntA,cntB,cntAB,cntO);
	}

}

Measured memory_bytes: 12000
// g++ -std=c++14

//Difficulty according to solve count during contest:
//A B C D H F E I G K L M N P S O Q R J U Z Y X T V W

#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(c) (c.begin(),c.end())
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define inf 1000000000000000001

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll
int mod = 1e9 + 7;
int32_t main(){ _
  int h, w;
  cin >> h >> w;
  vector<vector<int> > dp(h, vector<int>(w, 0));
  vector<string> grid(h);
  for(int i = 0; i < h; i++)
    cin >> grid[i];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(grid[i][j] == '#')
        continue;
      if(i == 0 and j == 0)
        dp[i][j] = 1;
      if(i != 0)
        dp[i][j] += dp[i - 1][j];
      if(j != 0)
        dp[i][j] += dp[i][j - 1];
      dp[i][j] %= mod;
    }
  }
  cout << dp[h - 1][w - 1] << endl;
}


Measured memory_bytes: 12468
mat = []
for _ in range(3):
    mat.append(list(map(int, input().split())))
N = int(input())
nums = set()
for _ in range(N):
    nums.add(int(input()))
rows = [3] * 3
cols = [3] * 3
diags = [3] * 2
for i in range(3):
    for j in range(3):
        if mat[i][j] in nums:
            rows[i] -= 1
            cols[j] -= 1
            if i == j:
                diags[0] -= 1
            if i + j == 2:
                diags[1] -= 1
print(["No", "Yes"][0 in (rows + cols + diags)])


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int a = in.nextInt();
		int b = in.nextInt();

		if (b == 0) {
			System.out.println(a);
		} else {
			System.out.println((a + b) % 24);
		}
	}
}

Measured memory_bytes: 21844
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>

using namespace std;

double EPS = 1e-10;
const double PI = acos(-1);

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
  
  bool operator == ( const point &p ) const {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

struct segment{
  point a,b;
};

double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

int is_point_on_line(point a, point b, point c) {
  return cross(b-a, c-a)==0.0 &&
         (dot(b-a, c-a) > -EPS) &&
         (dot(a-b, c-b) > -EPS);
}

int is_intersected_ls(point a1, point a2, point b1, point b2) {

  if(cross(a1-a2,b1-b2)==0){
    return is_point_on_line(a1,a2,b1) || is_point_on_line(a1,a2,b2) 
        || is_point_on_line(b1,b2,a1) || is_point_on_line(b1,b2,a2);
  }
  else {
    return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
           ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
  }
}

point intersection_ls(point a1, point a2, point b1, point b2) {
  point b = b2-b1;
  double d1 = abs(cross(b, a1-b1));
  double d2 = abs(cross(b, a2-b1));
  double t = d1 / (d1 + d2);

  return a1 + (a2-a1) * t;
}

double areaPol(vector<point> t){
  t.push_back(t[0]);
  int tsz=t.size();
  double area=0;
  for(int i=0;i<tsz-1;i++){
    area+=(t[i].x-t[i+1].x)*(t[i].y+t[i+1].y);
  }
  return abs(area)/2.0;
}

int main(void){
  segment s[3];

  while(true){
    for(int i=0;i<3;i++){
      cin >> s[i].a.x >> s[i].a.y >> s[i].b.x >> s[i].b.y;
      if( s[i].a.x==0 && s[i].a.y==0 && s[i].b.x==0 && s[i].b.y==0)return 0;
      }
    
    int fg[3]={0};
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
	if(i!=j)
	  fg[i]+=is_intersected_ls(s[i].a,s[i].b,s[j].a,s[j].b);
      }
    }

    if(fg[0]==2 && fg[1]==2 && fg[2]==2){
      vector<point>p;
      for(int i=0;i<2;i++)
	p.push_back(intersection_ls(s[i].a,s[i].b,s[i+1].a,s[i+1].b));
      p.push_back(intersection_ls(s[2].a,s[2].b,s[0].a,s[0].b));

      double res=areaPol(p);
      if(res>=1900000)cout <<"dai-kichi"<<endl;
      else if(res>=1000000 && res <1900000)cout <<"chu-kichi"<<endl;
      else if(res>=100000 && res<1000000)cout <<"kichi"<<endl;
      else if(res>0 && res<100000)cout << "syo-kichi"<<endl;
      else cout <<"kyo"<<endl;
    }
    else cout <<"kyo"<<endl;
  }
  return 0;
}

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

int main()
{
    int n,i,l,x;
    string s;

    cin>>n>>s;

    l=s.size()/2;

    if(n%2==0){
        for(i=0,x=0;i<l;i++){
            if(s[i]!=s[i+l]){
                x=1;
                break;
            }
        }
    }
    else{
        x=1;
    }
    if(x==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = []
B = []
cur = 0
for i in range(N):
    S = input()
    tmp = []
    for s in S:
        if s == '(':
            tmp.append(s)
        else:
            if tmp and tmp[-1] == '(':
                tmp.pop()
            else:
                tmp.append(s)
    l = tmp.count('(')
    r = len(tmp) - l
    if r-l <= 0:
        A.append((l, r))
    else:
        B.append((l, r))
A.sort(key=itemgetter(1))
B.sort(key=itemgetter(0), reverse=1)

for l, r in A:
    cur += r
    if cur > 0:
        No()
        exit()
    cur -= l
for l, r in B:
    cur += r
    if cur > 0:
        No()
        exit()
    cur -= l
if cur == 0:
    Yes()
else:
    No()


Measured memory_bytes: 174708
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int N;
int x[301], y[301];

double get_r(double X, double Y) {
  double ret = 0;

  for (int i = 0; i < N; ++i)
    ret = max(ret, (X - x[i]) * (X - x[i]) + (Y - y[i]) * (Y - y[i]));

  return ret;
}

double searchY(double X) {
  double lo = 0, hi = 1000.;

  for (int it = 0; it < 1000; ++it) {
    double a = (2. * lo + hi) / 3.;
    double b = (lo + 2. * hi) / 3.;

    double ra = get_r(X, a);
    double rb = get_r(X, b);

    if (ra < rb)
      hi = b;
    else
      lo = a;
  }

  return get_r(X, lo);
}

double searchX() {
  double lo = 0., hi = 1000.;

  for (int it = 0; it < 1000; ++it) {
    double a = (2. * lo + hi) / 3.;
    double b = (lo + 2. * hi) / 3.;

    double ra = searchY(a);
    double rb = searchY(b);

    if (ra < rb)
      hi = b;
    else
      lo = a;
  }

  return searchY(lo);
}

int main() {
  scanf("%d", &N);

  for (int i = 0; i < N; ++i) scanf("%d %d", &x[i], &y[i]);

  printf("%.10f\n", sqrt(searchX()));

  return 0;
}

Measured memory_bytes: 128
/**
 * CODE
 * BY
 * VIKAS VERMA
 * 
 * $$Always Check for Constraints
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, n) for (int i = 1; i <= n; i++)
#define fr(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP(l, r) for (int i = l; i < r; i++)
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"
#define jaldi ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef long long ll;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6 + 13;
//=======================
vi g[N];
int a[N];
//=======================

void solve()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll v1 = (a * c);
  ll v2 = (a * d);
  ll v3 = (b * c);
  ll v4 = (b * d);
  cout << max(max(v1, v2), max(v3, v4)) << endl;
}

int main()
{
  jaldi
      // #ifndef ONLINE_JUDGE
      //       freopen("input.txt", "r", stdin);
      //   freopen("output.txt", "w", stdout);
      // #endif
      int t = 1;

  // cin >> t;

  while (t--)
  {
    solve();
  }

  return 0;
}


Measured memory_bytes: 50528
#include <iostream>
using namespace std;
int w[100005];
int n, k = 0; //货物数量 和 卡车数量

//可以装载多少件货物，p为给定最大运载量
int check(long long p) {
    int i = 0;  //w[]的指针
    //对于每一辆卡车
    for (int j = 0 ; j < k; j++) {
        long long sum = 0;
        while (p - sum >= w[i]) {
            sum += w[i];
            i++;
            //注意这个边界条件
            if (i == n) {
                return n;
            }
        }
    }
    return i;
}

int resolve() {
    long long left = 0;
    long long right = 100000 * 10000;  //全都装一辆车上
    long long mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v >= n) {
            right = mid;
        }
        else {
            left = mid;
        }
    }
    return right;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }
    long long res = resolve();
    cout << res << endl;
    return 0;
}


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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int cnt[2001];
int X, Y;

int dx(int i){
    return abs(i - X);
}
int dy(int i){
    return abs(i - Y);
}
int main() {
    int N;
    cin >> N >> X >> Y;
    
    X--;
    Y--;
    for (int i = 0; i < N; i++){
        for (int j = i + 1; j < N; j++){
            int dist = j - i;
            chmin(dist, dx(i) + dx(j));
            chmin(dist, dy(i) + dy(j));
            chmin(dist, dx(i) + 1 + dy(j));
            chmin(dist, dy(i) + 1 + dx(j));
            cnt[dist]++;
        }
    }
    rep(i, N - 1)cout << cnt[i + 1] << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,L;
  cin>>N>>L;
  int A;
  A=L;
  int R=A+N-1;
  int eat;
  if(R<=0){
    eat=R;
  }
  else if(L>=0){
    eat=L;
  }
  else{
    eat=0;
  }
  int ans=(R+L)*(R-L+1)/2-eat;
  cout<<ans<<endl;
}


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

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector <int> data(n, 0);
    for (int i = 0; i < (n - 1); ++i) {
        int a;
        cin >> a;
        --a;
        ++data[a];
    }
    for (int i = 0;  i < n; ++i) cout << data[i] << endl;
    return 0;
}


Measured memory_bytes: 4000
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// 0 or 1
bool solve_01(V<int> a) {
    int n = int(a.size());
    //for (int x: a) cerr << x << endl;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if ((i & (n - 1 - i)) == 0) {
            ans ^= a[i];
        }
    }
    return ans;
}

// 02, 1
bool solve_is1(V<int> a) {
    V<int> a2;
    for (int x: a) a2.push_back(x % 2);
    return solve_01(a2);
}

// 0,2
bool solve_is2(V<int> a) {
    V<int> a2;
    for (int x: a) a2.push_back(x / 2);
    return solve_01(a2);
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    V<int> a;
    bool exist1 = false;
    for (char& c : s) {
        a.push_back(c - '1');
        if (a.back() == 1) exist1 = true;
    }

    if (solve_is1(a)) {
        cout << 1 << endl;
        return 0;
    }

    if (exist1) {
        cout << 0 << endl;
    } else {
        if (solve_is2(a)) {
            cout << 2 << endl;
        } else {
            cout << 0 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 17096
#include <iostream>
#include <fstream>
using namespace std;
long long n,a[100][100],F[25][3000005];
long long DP(long long i,long long used)
{
    if (i==n) return 1;
    if (F[i][used]>-1) return F[i][used];

    long long &res=F[i][used];
    res=0;
    for (int j=0;j<=n-1;j++) {
        if (a[i][j]==0 || ((used>>j) & 1)) continue;
        res=(res+DP(i+1,used | (1<<j)))%1000000007;
    }
    return res;
}

int main()
{
    //freopen("MATCHING.INP","r",stdin);
    //freopen("MATCHING.OUT","w",stdout);
    cin>>n;
    for (int i=0;i<=n-1;i++)
        for (int j=0;j<=n-1;j++)
            cin>>a[i][j];

    for (int i=0;i<=n-1;i++)
        for (int j=0;j<=3000000;j++)
            F[i][j]=-1;
    cout<<DP(0,0);
    return 0;
}


Measured memory_bytes: 495800
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <set>
#include <string>
#define ll long long
using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a>b)
    {
        ans+=a;
        a--;
    }
    else
    {
        ans+=b;
        b--;
    }
    if(a>b)
    {
        ans+=a;
        a--;
    }
    else
    {
        ans+=b;
        b--;
    }
    cout<<ans;
    return 0;
}

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

int main(){
    int keta;
    cin >> keta;
    string n;
    cin >> n;
    string anum[1000];
    int ans = 0;
    for(int i = 0; i < 1000; i++){
        if(i < 10){
            anum[i] = "00" + to_string(i);
        }else if(i < 100){
            anum[i] = "0" + to_string(i);
        }else{
            anum[i] = to_string(i);
        }
    }

    for(int i = 0; i < 1000; i++){
        int checkpoint,checkpoint2;
        bool flag1 = false;
        bool flag2 = false;
        bool flag3 = false;
        for(int j = 0; j < n.size(); j++){
            if(n[j] == anum[i][0]){
                flag1 = true;
                checkpoint = j+1;
                break;
            }
        }
        if(!flag1) continue;
        for(int j = checkpoint; j < n.size(); j++){
            if(n[j] == anum[i][1]){
                flag2 = true;
                checkpoint2 = j+1;
                break;
            }
        }
        if(!flag2) continue;
        for(int j = checkpoint2; j < n.size(); j++){
            if(n[j] == anum[i][2]){
                flag3 = true;
                break;
            }
        }
        if(flag3) ans++;
    }
    cout << ans << endl;
}


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

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
    if (N % findSumOfDigits(N) == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  return 0;
}

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

int main(){
	int x, n, t;
	cin >> x >> n;
	map<int, int> m;
	for(int i = 0; i < n; i++){
		cin >> t;
		m[t] = 1;
	}
	for(int i = 0; i < 100; i++){
		if(m[x-i] == 0){
			cout << x-i << "\n";
			break;
		}
		if(m[x+i] == 0){
			cout << x+i << "\n";
			break;
		}
	}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;

#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(), x.end()

int const N = 100 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;

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

  int n, m, k;
  cin >> n >> m >> k;

  int ans = (k == 0 || n*m == k);

  for(int i = 0; i <= n; ++i) {
    for(int j = 0; j <= m; ++j) {
      int x = i*m - i*j + (n-i)*j;
      ans |= (x == k);
    }
  }

  string w[] = {"No", "Yes"};
  cout << w[ans];
}

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

int main ()
{
    int n;
    while(cin >> n && n)
    {
        double s[n], mean = 0, a = 0;
        for (int i = 0;i < n;i++)
        {
            cin >> s[i];
            mean += s[i]; 
        }
        mean /= n;
        
        for(int i = 0;i < n;i++)
        {
            a += pow(s[i] - mean, 2) / n;
        }
        a = sqrt(a);
        
        cout << setprecision(10) << a << endl;
    }
    return 0;
}


Measured memory_bytes: 3268
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

string S;
ll K;

int main(){
    cin>>S>>K;
    
    if(K<=100){
        bool b=true;
        rep(i,K){
            if(S[i]!='1') b=false;
        }
        if(b){
            cout<<1<<endl;
            return 0;
        }
    }

    rep(i,S.size()){
        if(S[i]!='1'){
            cout<<S[i]<<endl;
            break;
        }
    }
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> A(N,INF);
    vector<int> B(N-1);
    REP(i,N-1) cin >> B[i];
    A[0]=B[0];
    A[N-1]=B[N-2];
    REP(i,N-2){
        A[i+1]=min(B[i],B[i+1]);
    }

    cout << accumulate(ALL(A),ll(0)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    ll ans = 0;
    rep(left, min(n, k) + 1) {
        rep(right, min(n, k) + 1 - left) {
            priority_queue<ll, vector<ll>, greater<ll>> pq;
            rep(i, left) pq.push(v[i]);
            rep(i, right) pq.push(v[n - 1 - i]);
            ll rem = k - left - right;
            ll tmp = 0;
            while(!pq.empty()) {
                ll cur = pq.top(); pq.pop();
                if ((rem > 0) && (cur < 0)) {
                    rem--;
                }
                else {
                    tmp += cur;
                }
            }
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256